Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions docs/architecture/flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ digraph review {
criteria), `branch` (a branch or worktree holding the change), or both.
- `draft`: the session an import belongs to until it is made general (FL5).

The CLI ships a starter pool: the `line`, the `change` line (PR, CI beside
review, merge, deploy: FL4), the `quick-change` line (check, review, ship: landed on the
reviewer's approval with no person asked), the `climb` line (FL10: hill-climbing one goal metric through its environments), and the segments `check`, `eval`, `review`, `judge` (FL9), `decide`, `ship`,
and `prove-implement`, cut from the shipped line's own station files so their
The CLI ships a starter pool: the `line`, the `change` line (labelled Ship: PR, CI beside
review, merge, deploy, FL4), the `climb` line (FL10: hill-climbing one goal metric through its environments), and the segments `check`, `eval`, `review`, `judge` (FL9), `decide`, `ship`
(labelled Land: rebase, then land through the project's own ship command, the way a repository that pushes straight
to its default branch ships), `deploy` and `prove-implement`, cut from the shipped line's own station files so their
prompts stay one copy. The web reads the shipped pool from a generated
snapshot (`packages/web/lib/line/shippedFlows.generated.ts`, regenerated by
`bun packages/cli/scripts/gen-shipped-flows.ts`, checked by
Expand Down Expand Up @@ -429,13 +429,7 @@ branch before it pushes. Every way back to the session returns to PR, so what
merges is exactly the commit CI and the reviewer passed, never the session's
live edits. Each way back has `max_visits=3`; the fourth visit ends the run.

`quick-change` keeps the older shape, built from segments: Check (a slot),
Review, Land (the `ship` segment), Deploy. A failed check, the reviewer's
"changes" and a rebase conflict at Land each go back to the session and then
to Check (`fix_check.md`, `fix_review.md` and `fix_conflict.md` in
`templates/change/`).

In both, the session hears how the run ended (done, or stopped where and why)
The session hears how the run ended (done, or stopped where and why)
in its own turn. A run on a task, a branch or a pull request started from inside a
session has that session as its subject too (`callingSubject` in
`flowCommand.ts` writes it into `change.json`): the session fixes the change by
Expand All @@ -450,8 +444,8 @@ subject, and its first fixable stop ends it with what the stage found.

A check the machine could not run (LP4: the check exits 2, say no test
database could be built) is not a finding about the change. Check routes it to
its own exit, `Not checked here`, marked `machine=true`, and `quick-change`
sends that exit to a stop of its own rather than to Fix check. The runner
its own exit, `Not checked here`, marked `machine=true`, and a flow built on
the segment sends that exit to a stop of its own rather than back to the session. The runner
returns the task to in_review, posts the reason as a note (not a blocker, so
the task's followers are not notified), and the run's owner hears it: its
subject session in the run's end message, else the person whose account ran
Expand Down Expand Up @@ -611,8 +605,8 @@ out, that production may run a backend the default branch lacks.

### Deploy: the run takes the merged commit live

Both change flows end at Deploy: after Merge in `change`, after Land (the `ship`
segment) in `quick-change`. The `deploy` segment is one station
`change` ends at Deploy after Merge, and a flow built on the `ship` segment after
Land. The `deploy` segment is one station
with `parks=true`: while the run stands there it holds no machine slot and no
session. The station runs `cast flow await-deploy --merge $run_dir/merge.json`
in the run's worktree. It starts only from the sha Merge wrote there, else the
Expand Down Expand Up @@ -803,8 +797,8 @@ this change needs done its own way written as generated segments; a flow is
written whole only when nothing in the library has the work's shape.

**Slots.** A backbone marks a node `slot="<what it must do>"`, optionally with
`flow=` for the steps it runs when nothing fills it (`quick-change` leaves its Check
as a slot with the `check` segment as default). A flow that names the backbone
`flow=` for the steps it runs when nothing fills it (say a Check slot with the
`check` segment as default). No shipped flow leaves a slot; a team's backbone can. A flow that names the backbone
by `extends="<slug>"` fills the slot with `subgraph <slot> { ... }`. The parser
(`parser.ts`) reads a fill as an inline segment and expands it exactly as
`flow=` expands a library segment (FL3): its steps take the slot's id as
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture/regret.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ buckets (`through`):
- **line**: it came through a run a role started (`workflow_runs.org_role_id`):
the run's merge commit, or a commit whose session worked under the run.
- **session_flow**: it came through a check flow a person's session ran (a
graph run from the pool: `change`, `quick-change`, `onefix`, `agentwatch`
graph run from the pool: `change`, `onefix`, `agentwatch`
and the like) that no role started.
- **outside**: anything else. No run, a Claude Code workflow run
(`run_kind: "workflow"`, which checks nothing) and the sessions under it,
Expand Down
2 changes: 1 addition & 1 deletion docs/brand/facts.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Each has a page at codecast.sh/features/<slug> (`packages/web/app/(marketing)/fe
| Memory | Search and ask across every past session; `cast blame` traces a line of code to the conversation that wrote it | /features/memory |
| Spawn and fork | Delegate to a new session, branch a conversation, switch agent or model mid-session | /features/agents |
| Triggers | Work that runs later: on a schedule, on a PR comment, on an event | /features/triggers |
| Flows | Every change takes the same path: check, review, decide, land, deploy | /features/flows |
| Flows | Every change takes the same path: pull request, CI and review, merge, deploy; it asks a person only when the change edits CI | /features/flows |
| Decisions | One queue for the calls only a person can make, answerable from the phone | /features/decisions |
| Pull requests | A PR is owned by the session that opened it; review comments and red checks wake it | /features/pull-requests |
| Browser | Agents drive your own Chrome in a background tab | /features/browser |
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/daemonBuildId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
//
// This file is excluded from its own hash, and it imports nothing on purpose:
// the CLI fast path reads it, so it must never pull in a module graph.
export const DAEMON_BUILD_ID = "4a33af1683ad";
export const DAEMON_BUILD_ID = "43ce973d63b5";
44 changes: 40 additions & 4 deletions packages/cli/src/flowCommand.defaultFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ describe("workspaceDefaultFlow (the web's defaultFlowOf over the CLI's pool)", (
expect(pool.find((f) => f.slug === "broken")?.errors.length).toBeGreaterThan(0);
for (const set of [null, "deleted", "triage", "broken"]) expect(workspaceDefaultFlow(pool, set)?.slug).toBe("change");
});

test("Change for a workspace that set Quick, which the library retired", () => {
expect(workspaceDefaultFlow(poolFlows(repo(), null, []), "quick-change")?.slug).toBe("change");
});
});

/** The flow team "dir" publishes to its own pool: in no repo and shipped by no CLI, so only a read of that pool finds it. */
Expand All @@ -71,10 +75,17 @@ const DIR_SHIP = {
nodes: [{ id: "start" }, { id: "review", prompt: "Read the change." }, { id: "exit" }],
};

/** The row a run of quick-change left in its runner's pool before the library retired it. */
const STORED_QUICK = {
_id: "k57quick", slug: "quick-change", name: "quick-change", workspace: "team:dir", by: "Ana", mine: true, origin: null,
source: line("quick-change", "Quick", "task,branch"),
nodes: [{ id: "start" }, { id: "review", prompt: "Read the change." }, { id: "exit" }],
};

/** Run `cast flow <args>` from inside `cwd`, a directory mapped to team "dir" (or, with `mapped` false, to none) while
* the active team is "active". Team "dir"'s pool holds DIR_SHIP and carries `defaultFlow` (or fails with it, an Error);
* team "active"'s carries `activeDefault`. */
async function castFlow(cwd: string, args: string[], defaultFlow: string | null | Error, activeDefault: string | null = null, mapped = true) {
* the active team is "active". Team "dir"'s pool holds DIR_SHIP and `stored`, and carries `defaultFlow` (or fails with
* it, an Error); team "active"'s carries `activeDefault`. */
async function castFlow(cwd: string, args: string[], defaultFlow: string | null | Error, activeDefault: string | null = null, mapped = true, stored: unknown[] = []) {
const out: string[] = [];
const err: string[] = [];
const posted: string[] = [];
Expand All @@ -89,7 +100,7 @@ async function castFlow(cwd: string, args: string[], defaultFlow: string | null
if (!body.team_id) return { flows: [], default_flow: null };
if (body.team_id === "active") return { flows: [], default_flow: activeDefault };
if (defaultFlow instanceof Error) throw defaultFlow;
return { flows: [DIR_SHIP], default_flow: defaultFlow };
return { flows: [DIR_SHIP, ...stored], default_flow: defaultFlow };
}
if (route === "/cli/flow/live/show") return [];
throw new Error(`not asked: ${route}`);
Expand Down Expand Up @@ -181,6 +192,31 @@ describe("cast flow run with no flow named", () => {
expect(r.out).toBe("");
});

test("a workspace whose default is the retired Quick runs Change", async () => {
const r = await castFlow(repo(), ["run", "--branch", "feature", "--dry-run"], "quick-change");
expect(r.err).toContain("running change, the workspace's default");
expect(r.out).toContain("on branch feature");
});

test("naming the retired Quick fails in one line that names Change", async () => {
const r = await castFlow(repo(), ["run", "quick-change", "--branch", "feature", "--dry-run"], null);
expect(r.code).toBe(1);
expect(r.err).toBe("✗ quick-change is no longer in the library: use change (Ship), which asks a person only when the change edits CI");
expect(r.out).toBe("");
});

test("a Quick row a run left in the pool brings it back to no listing, show, run or default", async () => {
const root = repo();
const retired = "✗ quick-change is no longer in the library: use change (Ship), which asks a person only when the change edits CI";
const run = await castFlow(root, ["run", "quick-change", "--branch", "feature", "--dry-run"], null, null, true, [STORED_QUICK]);
expect([run.code, run.err]).toEqual([1, retired]);
const shown = await castFlow(root, ["show", "quick-change"], null, null, true, [STORED_QUICK]);
expect([shown.code, shown.err]).toEqual([1, retired]);
expect((await castFlow(root, ["ls"], null, null, true, [STORED_QUICK])).out).not.toContain("quick-change");
const nameless = await castFlow(root, ["run", "--branch", "feature", "--dry-run"], "quick-change", null, true, [STORED_QUICK]);
expect(nameless.err).toContain("running change, the workspace's default");
});

test("a flow named still runs that flow, and says nothing of the default", async () => {
const r = await castFlow(repo(), ["run", "change", "--branch", "feature", "--dry-run"], "ship-now");
expect(r.err).not.toContain("No flow named");
Expand Down
8 changes: 5 additions & 3 deletions packages/cli/src/flowCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,18 @@ export const FLOW_HELP = `
Choosing a flow:
A library flow that fits the work runs as it stands: it carries what the team has learned.
A library flow that fits as a backbone, with a step this change needs done its own way, is
extended: name it with extends and fill its slots with steps you write. The rest stays the team's.
extended: name it with extends and add the steps you write, or fill its slots when it leaves
some. The rest stays the team's.
A flow written whole fits only when nothing in the library has the shape of the work.

cast flow run the workspace's default flow (cast flow ls marks it),
on this session's own edits; --task, --branch, --pr name another change
cast flow run change a library flow by name, on this session's own edits
cast flow run - <<'EOF' a flow written here, checked before it starts
digraph flaky_fix {
graph [extends="quick-change"]
subgraph check { reproduce -> prove } steps that fill the backbone's check slot
graph [extends="change"]
reproduce [after="pr", prompt="Run the flaky test until it fails"] steps of this change's own,
prove [after="reproduce", script="bun test --rerun-each 20"] ahead of CI and review
}
EOF

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/flowEdit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function parse(file: string, read: ReadFile): WorkflowGraph {

/** The plan for one edit of `flow` in the checkout at `root`. */
export function planFlowEdit(root: string, flow: string, req: FlowEditRequest, read: ReadFile = readDisk): FlowEditPlan {
if (!/^[\w-]+$/.test(flow)) throw new FlowEditError(`"${flow}" is not a flow's name: name one from cast flow ls (change, quick-change, ...)`);
if (!/^[\w-]+$/.test(flow)) throw new FlowEditError(`"${flow}" is not a flow's name: name one from cast flow ls (change, line, ...)`);
const file = repoFlowFile(root, flow);
const dir = path.dirname(file);
const existing = read(file);
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/flowFind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { spawnSync } from "./proc.js";
import { notFoundLine } from "./argChecks.js";
import { retiredFlowLine } from "@codecast/shared/contracts/flowPool";
import { describeFlow, poolFlows, workspaceDefaultFlow, type PoolFlow, type PushedPoolRow } from "./workflow/flowPool.js";
import { BUILTIN_WORKFLOW_TEMPLATES } from "./workflow/templates.js";
import type { Workspace } from "./resolveWorkspace.js";
Expand Down Expand Up @@ -73,7 +74,8 @@ export async function findFlow(slug: string, deps: FlowDeps, pool?: PoolFlow[]):
}
const f = (pool ?? (await readPool(deps, poolWorkspace(deps))).flows).find((p) => p.slug === slug.replace(/\.cast$/, ""));
if (!f) {
console.error(notFoundLine("flow", slug, "cast flow ls"));
const retired = retiredFlowLine(slug.replace(/\.cast$/, ""));
console.error(retired ? `✗ ${retired}` : notFoundLine("flow", slug, "cast flow ls"));
process.exit(1);
}
return { ...f, source: f.file ? fs.readFileSync(f.file, "utf-8") : BUILTIN_WORKFLOW_TEMPLATES[f.slug] };
Expand Down
20 changes: 20 additions & 0 deletions packages/cli/src/flowLibrary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,26 @@ describe("the library", () => {
expect(parseWorkflowFile(variant.file!).nodes.get("investigate")?.prompt).toBe("Read the system finding.");
});

test("a variant that names its base by slug parses beside a base whose stations keep files in a folder of that name", () => {
const base: PushedPoolRow = {
_id: "kchange", slug: "change", name: "change", source: `digraph change {\n graph [kind=line, label="Ship"]\n start [shape=Mdiamond]\n fix [label="Fix", prompt="@change/fix.md"]\n exit [shape=Msquare]\n start -> fix -> exit\n}`,
workspace: "user:u1", mine: true, nodes: [{ id: "fix", prompt: "Fix it." }],
origin: { file: ".codecast/flows/change.cast", files: [{ node: "fix", prompt: ".codecast/flows/change/fix.md" }] },
};
const variant: PushedPoolRow = {
_id: "know", slug: "ship-now", name: "ship_now", source: `digraph ship_now {\n graph [extends="change", kind=line, label="Ship now"]\n fix [label="Fix now"]\n}`,
workspace: "user:u1", mine: true, nodes: [{ id: "fix", prompt: "Fix it." }],
origin: { file: ".codecast/flows/ship-now.cast", files: [] },
};
// The repo has its own change, so the published one is read only as the variant's base.
const repo = mkdtemp();
fs.mkdirSync(path.join(repo, ".codecast", "flows"), { recursive: true });
fs.writeFileSync(path.join(repo, ".codecast", "flows", "change.cast"), base.source!.replace("@change/fix.md", "Fix it."));
const now = poolFlows(repo, null, [variant, base], mkdtemp()).find((f) => f.slug === "ship-now")!;
expect(now.errors).toEqual([]);
expect(parseWorkflowFile(now.file!).nodes.get("fix")).toMatchObject({ label: "Fix now", prompt: "Fix it." });
});

test("the live flow's flow is the spine, its variant sits under it, segments on their own shelf", () => {
const tree = libraryTree(pool(), [live]);
expect(tree.spine.map((n) => [n.flow.slug, n.variants.map((v) => v.flow.slug)])).toEqual([["agentwatch", ["agentwatch-system"]]]);
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22428,6 +22428,12 @@ workflow
// else one of the caller's own pushed workflows by slug (L2).
let resolved = "resolved" in choice ? choice.resolved : resolveWorkflowSource(file);
if (!resolved) {
const { retiredFlowLine } = await import("@codecast/shared/contracts/flowPool");
const retired = retiredFlowLine(file);
if (retired) {
console.error(`✗ ${retired}`);
process.exit(1);
}
const own = (await cliPost("/cli/workflows/list", {}).catch(() => null))?.workflows?.find((w: any) => w.slug === file && w.source);
if (own) resolved = { source: own.source, label: `workflow:${own.slug}` };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// A synthetic team flow for awaitDeploy.personSent.test.ts: the shipped
// quick-change, with Deploy composed to send nothing, because a person sends
// change, with Deploy composed to send nothing, because a person sends
// this team's production deploy.
digraph change {
graph [extends="quick-change", label="Change", description="Check, review, land, then wait for the deploy a person sends"]
graph [extends="change", description="PR, CI and review, merge, then wait for the deploy a person sends"]
deploy [send=""]
}
4 changes: 2 additions & 2 deletions packages/cli/src/workflow/condition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ describe("evalCondition: every condition the shipped workflows use", () => {
["outcome = failure and verify.exit_code != 2", { outcome: "failure", "verify.exit_code": "2" }, false],
["outcome = failure and verify.exit_code = 2", { outcome: "failure", "verify.exit_code": "2" }, true],
["outcome = failure and verify.exit_code = 2", { outcome: "failure", "verify.exit_code": "1" }, false],
// The ship segment inside the change line (flows.md FL3): its stations read under the node's name.
// The ship segment inside a flow (flows.md FL3): its stations read under the node's name.
["outcome = success and ship__rebase.json.landed != true", { outcome: "success", "ship__rebase.json.landed": "false" }, true],
["outcome = success and ship__rebase.json.landed = true", { outcome: "success", "ship__rebase.json.landed": "true" }, true],
["outcome = failure and ship__rebase.exit_code = 1", { outcome: "failure", "ship__rebase.exit_code": "1" }, true],
Expand All @@ -193,7 +193,7 @@ describe("evalCondition: every condition the shipped workflows use", () => {
["outcome = failure and ship__conflict.json.exit = unshipped", { outcome: "failure", "ship__conflict.json.exit": "conflict" }, false],
["outcome = failure and ship__unshipped.json.exit = conflict", { outcome: "failure", "ship__unshipped.json.exit": "unshipped" }, false],
["outcome = failure and ship__unshipped.json.exit = unshipped", { outcome: "failure", "ship__unshipped.json.exit": "unshipped" }, true],
// The check segment imported into change and quick-change: its exits read through each stop node.
// The check segment imported into a flow: its exits read through each stop node.
["outcome = failure and check__verify.exit_code != 2", { outcome: "failure", "check__verify.exit_code": "1" }, true],
["outcome = failure and check__verify.exit_code = 2", { outcome: "failure", "check__verify.exit_code": "2" }, true],
["outcome = failure and check__failed.json.exit != unjudged", { outcome: "failure", "check__failed.json.exit": "failed" }, true],
Expand Down
Loading
Loading