Public Beta
Not set

Experience

Changes how pages explain things, never what you can do.

More

Experience

Changes how pages explain things, never what you can do.

Sign inGet started

Workflow Automation v0.1.2 · claude-code

Archive SHA-256 85be31abe46644f344964c8b1d4b56f6d7218b34a58fd31ffb075c5e5b587476 · 89.5 KB · built Dec 1, 2026

src/report.js

// Human-readable plan output: the operation list as a text "diff" and as Markdown.
import { ESCAPERS } from "./template.js";

const n = (x) => x.toLocaleString("en-US");

export function summarize(ops) {
  const s = { operations: ops.length, planned: 0, create_folder: 0, create: 0, overwrite: 0, append: 0, move: 0, copy: 0, skip: 0, unchanged: 0, conflicts: 0, bytes_to_write: 0 };
  for (const o of ops) {
    if (o.status === "conflict") s.conflicts++;
    else if (o.status === "skip") s.skip++;
    else if (o.status === "unchanged") s.unchanged++;
    else {
      s.planned++;
      if (o.op === "create_folder") s.create_folder++;
      else if (o.op === "move_file") s.move++;
      else if (o.op === "copy_file") {
        s.copy++;
        s.bytes_to_write += o.bytes ?? 0;
      } else {
        s[o.mode]++;
        s.bytes_to_write += o.bytes ?? 0;
      }
    }
  }
  return s;
}

function verb(o) {
  if (o.status === "conflict") return "CONFLICT";
  if (o.status === "skip") return "skip";
  if (o.status === "unchanged") return "unchanged";
  if (o.op === "create_folder") return "create folder";
  if (o.op === "move_file") return o.case_only ? "rename (case)" : "move";
  if (o.op === "copy_file") return "copy";
  return o.mode;
}

function target(o) {
  return o.from ? `${o.from} -> ${o.path}` : o.path;
}

function detail(o) {
  const bits = [];
  if (o.status === "planned" && o.op === "write_file") {
    if (o.mode === "create") bits.push(`${n(o.bytes)} bytes`);
    else if (o.diff) bits.push(`+${o.diff.added} -${o.diff.removed} lines`);
  }
  if (o.renamed_from) bits.push(`${o.renamed_from} exists, so renamed`);
  return bits.length ? ` (${bits.join("; ")})` : "";
}

export function diffText(ops, { name, workspace, executed }) {
  const lines = [`${executed ? "Applied" : "Plan for"} "${name}" in ${workspace}${executed ? "" : " (nothing has been written)"}:`];
  if (!ops.length) lines.push("  no file operations");
  for (const o of ops) {
    lines.push(`  ${verb(o).padEnd(14)} ${target(o)}${detail(o)}${o.reason && o.status !== "planned" ? `: ${o.reason}` : ""}`);
    if (o.status === "planned" && o.diff && o.op === "write_file") {
      for (const l of o.diff.lines) lines.push(`                   ${l}`);
      if (o.diff.truncated) lines.push("                   …");
    }
  }
  const s = summarize(ops);
  const tail = [`${s.planned} ${executed ? "applied" : "to apply"}`];
  if (s.skip) tail.push(`${s.skip} skipped`);
  if (s.unchanged) tail.push(`${s.unchanged} unchanged`);
  if (s.conflicts) tail.push(`${s.conflicts} conflict${s.conflicts === 1 ? "" : "s"} (resolve them, for example with if_exists, before running)`);
  lines.push(tail.join(", ") + ".");
  return lines.join("\n");
}

export function markdownReport(ops, { name, workspace, executed, warnings, planHash }) {
  const md = ESCAPERS.markdown;
  const s = summarize(ops);
  const out = [`# ${md(name)}: ${executed ? "run report" : "plan"}`, "", `- Workspace: \`${workspace.replace(/`/g, "'")}\``, `- Status: ${executed ? "applied" : s.conflicts ? `not ready (${s.conflicts} conflict${s.conflicts === 1 ? "" : "s"})` : "ready to run (nothing written yet)"}`, `- Plan hash: \`${planHash}\``, ""];
  if (ops.length) {
    out.push("| # | Action | Path | Note |", "| ---: | --- | --- | --- |");
    for (const o of ops) out.push(`| ${o.index} | ${verb(o)} | ${md(target(o))} | ${md((detail(o).replace(/^ \(|\)$/g, "") + (o.reason && o.status !== "planned" ? ` ${o.reason}` : "")).trim()) || " "} |`);
  } else out.push("No file operations.");
  if (warnings.length) out.push("", "## Warnings", "", ...warnings.map((w) => `- ${md(w)}`));
  return out.join("\n") + "\n";
}

Find an agent

Do not include passwords, keys, customer data or other confidential details.
Rule-based matching is free during the public beta (fair use).