@mayurdluffy/ccwf 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/lib/index.js +4 -1
- package/lib/installer.js +2 -2
- package/lib/merge.js +7 -2
- package/lib/modules.js +26 -2
- package/lib/stats.js +49 -4
- package/lib/transcripts.js +192 -0
- package/package.json +1 -1
- package/templates/blocks/browser.md +5 -9
- package/templates/blocks/cbm.md +4 -6
- package/templates/blocks/core.md +1 -0
- package/templates/docs/agents/workflow.md +1 -1
- package/templates/skills/agent-browser/SKILL.md +1 -1
- package/templates/skills/orchestrate-workers/ISOLATION.md +24 -0
- package/templates/skills/orchestrate-workers/OPTIONS.md +13 -0
- package/templates/skills/orchestrate-workers/SKILL.md +37 -44
- package/templates/skills/orchestrate-workers/TAB.md +9 -0
- package/templates/skills/orchestrate-workers/context.conf +18 -0
- package/templates/skills/orchestrate-workers/context.js +337 -0
- package/templates/skills/orchestrate-workers/tickets.sh +101 -3
- package/templates/skills/verify-ui/SKILL.md +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ npx @mayurdluffy/ccwf@latest init # tools + user-level skills + project files
|
|
|
26
26
|
| `tracking` | `docs/ROADMAP.md` (session entry point: product, order of work, efforts with their `progress.md`), empty `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/`, `learnings/` + `save-learning` skill + rules; `docs/agents/{domain,issue-tracker,triage-labels}.md` |
|
|
27
27
|
| `browser` | `agent-browser` + `verify-ui` skills, `chrome-devtools` MCP, `.cursor/cli.json`, Claude MCP approval and allowed sites |
|
|
28
28
|
| `guardrails` (only when asked for: `ccwf add guardrails`) | `.agents/guardrails/check.sh` runs your project's checks from `checks.conf` and looks for new secrets. The same script serves workers (a finished one is sent back once if it fails), git commits (`--install-hook`) and CI (`--all`) |
|
|
29
|
-
| `workers` | `orchestrate-workers` skill (a `workers` tab of four panes in the orchestrator's own herdr space, `hc` reference, `workers.conf`). A `reviewer` row in `workers.conf` turns on an independent review of every ticket. `isolation worktree` gives each worker a folder of its own, which is deleted once its work is merged |
|
|
29
|
+
| `workers` | `orchestrate-workers` skill (a `workers` tab of four panes in the orchestrator's own herdr space, `hc` reference, `workers.conf`). A `reviewer` row in `workers.conf` turns on an independent review of every ticket. `isolation worktree` gives each worker a folder of its own, which is deleted once its work is merged. `context.conf` sets the orchestrator's context limits: in Claude Code, and in Codex once you approve its hooks with `/hooks`, a hook warns at 50% of the window and orders a hand-off at 65%, a second hook then refuses `assign.sh` and `review.sh` until the session is reset (`GATE=off` in `context.conf` turns that off), and a third puts `progress.md`'s Resume back after `/clear` or `/compact` |
|
|
30
30
|
|
|
31
31
|
Skills live in `.agents/skills/` (Codex, Cursor); Claude Code gets symlinks in `.claude/skills/`. Files are written only for the agents you select.
|
|
32
32
|
|
|
@@ -45,7 +45,7 @@ A skill that needs project settings asks you the first time it runs and saves th
|
|
|
45
45
|
| `ccwf update` | the only command that re-renders templates from this ccwf version; files you edited are merged, not overwritten (see below) |
|
|
46
46
|
| `ccwf sync` | push skill settings into agent configs and add navigation rules; does not re-render templates |
|
|
47
47
|
| `ccwf doctor` | check tools, skills and files; offer to install what is missing and to run `update` (`--yes` does both). `--check` changes nothing and exits 1 on problems |
|
|
48
|
-
| `ccwf stats` | worker runs in this repo per model and folder mode: done, first try, time, fix rounds, failed checks (`--json`).
|
|
48
|
+
| `ccwf stats` | worker runs in this repo per model and folder mode: done, first try, time, fix rounds, failed checks, and from the Claude Code and Codex session files the context each session started with and reached, the tokens it read and its codebase-memory calls, plus every orchestrator session against its limit (`--json`). Runs are recorded in `.git/ccwf/runs.jsonl`; numbers only, no prompts or code, and nothing leaves your computer |
|
|
49
49
|
| `ccwf eject <skill>` | stop managing a skill you changed |
|
|
50
50
|
| `ccwf status` | installed modules; files, managed blocks, settings and links that differ. `--check` exits 1 when something is missing or broken; your edits do not count |
|
|
51
51
|
|
|
@@ -108,6 +108,8 @@ Then follow `docs/agents/workflow.md` in your repo. Commit `.ccwf.json` and the
|
|
|
108
108
|
|
|
109
109
|
`node scripts/harvest.js <repo> --terms yourproduct` diffs a working repo's skills against `templates/skills/`, flags project-specific lines, and with `--apply` copies the clean ones. Not published to npm.
|
|
110
110
|
|
|
111
|
+
Why the context limits exist and how they were found, measured and tested: [docs/context-engineering.md](docs/context-engineering.md) (the model and the story), [docs/context-engineering-methods.md](docs/context-engineering-methods.md) (how to reproduce it), [docs/audit-context.md](docs/audit-context.md) (the findings). The analysis scripts are in `scripts/context/`.
|
|
112
|
+
|
|
111
113
|
Before and after changing a skill, run its tasks in [evals/](evals/README.md). They use paid agent sessions and never run in CI.
|
|
112
114
|
|
|
113
115
|
## Releasing
|
package/lib/index.js
CHANGED
|
@@ -27,7 +27,7 @@ Usage: ccwf <command> [options]
|
|
|
27
27
|
chrome-mcp serve the project’s Chrome DevTools MCP (--print shows its command)
|
|
28
28
|
doctor check tools, skills and files; offer to fix what is missing
|
|
29
29
|
eject <skill> stop managing a skill you changed
|
|
30
|
-
stats worker runs per model: done, time, fix rounds, failed checks (--json)
|
|
30
|
+
stats worker runs per model: done, time, fix rounds, failed checks; context per session (--json)
|
|
31
31
|
status show installed modules and drifted files
|
|
32
32
|
|
|
33
33
|
Modules: ${ORDER.join(", ")}
|
|
@@ -270,6 +270,9 @@ async function install(cmd, opts, root) {
|
|
|
270
270
|
if (cmd === "update" && prev.ccwf !== pkg.version) console.log(`update: ccwf ${prev.ccwf} -> ${pkg.version}`);
|
|
271
271
|
report(r.ins, opts["dry-run"]);
|
|
272
272
|
if (!opts["dry-run"]) saveManifest(root, { agents, modules, ejected, ...tracked(r.ins) });
|
|
273
|
+
if (r.ins.log.some((l) => l.rel === ".codex/hooks.json" && /created|updated/.test(l.state))) {
|
|
274
|
+
console.log(" next: Codex runs project hooks only after you approve them. Open Codex in this repo and review them with /hooks (they are the context limits: orchestrate-workers/context.js). Until then Codex has no context limit here.");
|
|
275
|
+
}
|
|
273
276
|
if (modules.includes("guardrails") && !prev?.modules?.includes("guardrails")) {
|
|
274
277
|
console.log(" next: check the commands in .agents/guardrails/checks.conf and commit the folder. To run the quick ones before each commit: .agents/guardrails/check.sh --install-hook. In CI: .agents/guardrails/check.sh --all");
|
|
275
278
|
}
|
package/lib/installer.js
CHANGED
|
@@ -324,9 +324,9 @@ class Installer {
|
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
// Deep-merge keys into a JSON file; invalid JSON aborts without touching the file.
|
|
327
|
-
json(rel, patch, union = []) {
|
|
327
|
+
json(rel, patch, union = [], owns = null) {
|
|
328
328
|
const cur = this.read(rel) ?? "";
|
|
329
|
-
const next = mergeJson(cur, patch, rel, union);
|
|
329
|
+
const next = mergeJson(cur, patch, rel, union, owns);
|
|
330
330
|
if (next === cur) return this.note(rel, "unchanged", "json");
|
|
331
331
|
const existed = cur !== "";
|
|
332
332
|
this.write(rel, next);
|
package/lib/merge.js
CHANGED
|
@@ -119,7 +119,9 @@ function setPath(obj, dotted, value) {
|
|
|
119
119
|
|
|
120
120
|
// Merge `patch` into JSON text, keeping every other key. Throws on invalid JSON (never overwrite).
|
|
121
121
|
// `union`: dotted paths whose arrays are merged as a set (existing entries first) instead of replaced.
|
|
122
|
-
|
|
122
|
+
// `owns`: tells an entry this tool wrote earlier. When the patch brings entries of its own, the old ones are replaced, not kept
|
|
123
|
+
// beside them, so a changed hook (a new timeout, a new command) never runs twice.
|
|
124
|
+
function mergeJson(text, patch, label = "JSON file", union = [], owns = null) {
|
|
123
125
|
let data = {};
|
|
124
126
|
if (text.trim() !== "") {
|
|
125
127
|
try {
|
|
@@ -134,7 +136,10 @@ function mergeJson(text, patch, label = "JSON file", union = []) {
|
|
|
134
136
|
const add = getPath(p, path);
|
|
135
137
|
if (!Array.isArray(add)) continue;
|
|
136
138
|
const have = getPath(data, path);
|
|
137
|
-
|
|
139
|
+
// Equal values once, by content: hook entries are objects, which a Set would keep twice.
|
|
140
|
+
const kept = (Array.isArray(have) ? have : []).filter((v) => !(owns && owns(v) && add.some(owns)));
|
|
141
|
+
const all = [...kept, ...add];
|
|
142
|
+
setPath(p, path, [...new Map(all.map((v) => [JSON.stringify(v), v])).values()]);
|
|
138
143
|
}
|
|
139
144
|
const before = JSON.parse(JSON.stringify(data));
|
|
140
145
|
deepMerge(data, p);
|
package/lib/modules.js
CHANGED
|
@@ -31,7 +31,7 @@ function skillFiles(name, params) {
|
|
|
31
31
|
rel,
|
|
32
32
|
content: render(fs.readFileSync(path.join(dir, rel), "utf8"), params),
|
|
33
33
|
mode: st.mode & 0o111 ? 0o755 : undefined,
|
|
34
|
-
seed: rel === "workers.conf", // the user's roster: written once, never merged
|
|
34
|
+
seed: rel === "workers.conf" || rel === "context.conf", // the user's roster and context limits: written once, never merged
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -119,6 +119,27 @@ function checksConf(ins) {
|
|
|
119
119
|
].join("\n") + "\n";
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
// The context guard (orchestrate-workers/context.js): it measures the session after each tool call and each prompt, refuses
|
|
123
|
+
// new work (assign.sh, review.sh) at the hand-off limit, and puts progress.md's "## Resume" back after /clear or /compact.
|
|
124
|
+
// Claude Code reads .claude/settings.json and Codex reads .codex/hooks.json; both take this shape. Cursor has no equivalent, so
|
|
125
|
+
// the skill's wave rule is the only limit it gets.
|
|
126
|
+
// Shell form with the path quoted, which Claude Code's docs allow beside "exec form" (command + args). Exec form needs a Claude
|
|
127
|
+
// Code version this cannot check, and an older one would run bare `node` and do nothing.
|
|
128
|
+
// timeout: the default is 600 seconds and a stalled hook delays every tool call; these only read a file's tail.
|
|
129
|
+
const GUARD = "orchestrate-workers/context.js";
|
|
130
|
+
const guardHooks = (root) => {
|
|
131
|
+
const hook = (arg) => ({ type: "command", command: `node "${root}/.agents/skills/${GUARD}" ${arg}`, timeout: 10 });
|
|
132
|
+
return {
|
|
133
|
+
PostToolUse: [{ hooks: [hook("check")] }],
|
|
134
|
+
UserPromptSubmit: [{ hooks: [hook("check")] }],
|
|
135
|
+
PreToolUse: [{ matcher: "Bash", hooks: [hook("gate")] }],
|
|
136
|
+
SessionStart: [{ matcher: "clear|compact", hooks: [hook("resume")] }],
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const CONTEXT_HOOKS = guardHooks("$CLAUDE_PROJECT_DIR");
|
|
140
|
+
const CODEX_HOOKS = guardHooks("$(git rev-parse --show-toplevel)"); // Codex sets no project variable; the worktree of an isolated worker is its own top level
|
|
141
|
+
const ownsGuard = (entry) => JSON.stringify(entry).includes(GUARD); // an earlier version of these entries: replaced, not kept beside
|
|
142
|
+
|
|
122
143
|
const MODULES = {
|
|
123
144
|
core: {
|
|
124
145
|
desc: "engineering discipline rules, commit skill, workflow + setup guides",
|
|
@@ -176,9 +197,12 @@ const MODULES = {
|
|
|
176
197
|
},
|
|
177
198
|
},
|
|
178
199
|
workers: {
|
|
179
|
-
desc: "orchestrate-workers skill (needs herdr + hc)",
|
|
200
|
+
desc: "orchestrate-workers skill (needs herdr + hc) and its context limits",
|
|
180
201
|
run(ctx) {
|
|
181
202
|
installSkill(ctx, "orchestrate-workers");
|
|
203
|
+
const events = Object.keys(CONTEXT_HOOKS).map((e) => `hooks.${e}`);
|
|
204
|
+
if (ctx.agents.includes("claude")) ctx.ins.json(".claude/settings.json", { hooks: CONTEXT_HOOKS }, events, ownsGuard);
|
|
205
|
+
if (ctx.agents.includes("codex")) ctx.ins.json(".codex/hooks.json", { hooks: CODEX_HOOKS }, events, ownsGuard);
|
|
182
206
|
// ccwf 0.1 named the fourth worker theta; the panes now look up delta.
|
|
183
207
|
ctx.ins.rewrite(
|
|
184
208
|
".agents/skills/orchestrate-workers/workers.conf",
|
package/lib/stats.js
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const { spawnSync } = require("child_process");
|
|
6
|
+
const transcripts = require("./transcripts");
|
|
7
|
+
|
|
8
|
+
// The main folder of the repo: worker folders and linked worktrees count as the repo they belong to.
|
|
9
|
+
function mainRoot(root) {
|
|
10
|
+
const r = spawnSync("git", ["rev-parse", "--git-common-dir"], { cwd: root, encoding: "utf8" });
|
|
11
|
+
if (r.status !== 0) return root;
|
|
12
|
+
const common = path.resolve(root, r.stdout.trim());
|
|
13
|
+
return path.basename(common) === ".git" ? fs.realpathSync(path.dirname(common)) : root;
|
|
14
|
+
}
|
|
6
15
|
|
|
7
16
|
function readEvents(root) {
|
|
8
17
|
const r = spawnSync("git", ["rev-parse", "--git-common-dir"], { cwd: root, encoding: "utf8" });
|
|
@@ -23,13 +32,20 @@ function readEvents(root) {
|
|
|
23
32
|
});
|
|
24
33
|
}
|
|
25
34
|
|
|
35
|
+
// Context numbers of the sessions found for a group of runs. Medians, since one long ticket should not set the picture.
|
|
36
|
+
function contextOf(found) {
|
|
37
|
+
if (!found.length) return null;
|
|
38
|
+
const m = (f) => median(found.map(f));
|
|
39
|
+
return { sessions: found.length, startCtx: m((x) => x.startCtx), peakCtx: m((x) => x.peakCtx), turns: m((x) => x.turns), read: m((x) => x.read), graph: found.reduce((n, x) => n + x.graph, 0) };
|
|
40
|
+
}
|
|
41
|
+
|
|
26
42
|
function median(values) {
|
|
27
43
|
if (!values.length) return null;
|
|
28
44
|
const s = [...values].sort((a, b) => a - b);
|
|
29
45
|
return (s[(s.length - 1) >> 1] + s[s.length >> 1]) / 2;
|
|
30
46
|
}
|
|
31
47
|
|
|
32
|
-
function summarise(events) {
|
|
48
|
+
function summarise(events, sessions = []) {
|
|
33
49
|
const runs = new Map();
|
|
34
50
|
const lastRun = new Map(); // ticket -> the run that worked on it last
|
|
35
51
|
const doneBy = new Map(); // ticket -> the run that had it when it was set to done
|
|
@@ -58,6 +74,7 @@ function summarise(events) {
|
|
|
58
74
|
}
|
|
59
75
|
}
|
|
60
76
|
const done = new Set(doneBy.values());
|
|
77
|
+
const matched = transcripts.matchRuns(events, sessions);
|
|
61
78
|
const groups = new Map();
|
|
62
79
|
for (const r of runs.values()) {
|
|
63
80
|
const folder = r.tree === "worktree" ? "own" : "shared";
|
|
@@ -83,9 +100,11 @@ function summarise(events) {
|
|
|
83
100
|
gates: sum((r) => r.gates),
|
|
84
101
|
conflicts: sum((r) => r.conflicts),
|
|
85
102
|
failedStarts: all.length - ran.length,
|
|
103
|
+
context: contextOf(ran.map((r) => matched.get(r.run)).filter(Boolean)),
|
|
86
104
|
};
|
|
87
105
|
});
|
|
88
|
-
|
|
106
|
+
const orchestrators = sessions.filter((x) => x.kind === "orchestrator").sort((a, b) => a.start - b.start);
|
|
107
|
+
return { workers: workers.sort((a, b) => b.runs - a.runs), reviews: [...reviewers.values()], orchestrators };
|
|
89
108
|
}
|
|
90
109
|
|
|
91
110
|
function table(rows) {
|
|
@@ -93,10 +112,35 @@ function table(rows) {
|
|
|
93
112
|
return rows.map((r) => " " + r.map((c, i) => (i < 4 ? String(c).padEnd(width[i]) : String(c).padStart(width[i]))).join(" ").trimEnd()).join("\n");
|
|
94
113
|
}
|
|
95
114
|
|
|
115
|
+
const kTokens = (n) => (n === null || n === undefined ? "-" : n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : `${Math.round(n / 1000)}k`);
|
|
116
|
+
|
|
117
|
+
// Sessions changed within 30 days, or since the first recorded run if that is older.
|
|
118
|
+
function sessionsFor(root, events) {
|
|
119
|
+
const first = events.length ? Math.min(...events.map((e) => e.t)) * 1000 - 86400000 : Infinity;
|
|
120
|
+
return transcripts.readSessions(mainRoot(root), Math.min(Date.now() - 30 * 86400000, first));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function printContext(s, window) {
|
|
124
|
+
const rows = s.workers.filter((w) => w.context);
|
|
125
|
+
if (rows.length) {
|
|
126
|
+
const head = ["agent", "model", "effort", "folder", "sessions", "start ctx", "peak ctx", "turns", "tokens read", "graph calls"];
|
|
127
|
+
const row = (w) => [w.agent, w.model, w.effort, w.folder, w.context.sessions, kTokens(w.context.startCtx), kTokens(w.context.peakCtx), Math.round(w.context.turns), kTokens(w.context.read), w.context.graph];
|
|
128
|
+
console.log("\nContext per worker session (medians; tokens read = what the model re-read over the whole session; graph calls = codebase-memory tools, total)");
|
|
129
|
+
console.log(table([head, ...rows.map(row)]));
|
|
130
|
+
}
|
|
131
|
+
if (s.orchestrators.length) {
|
|
132
|
+
console.log(`\nOrchestrator sessions (the limit is ${kTokens(window)}; see context.conf)`);
|
|
133
|
+
const head = ["started", "agent", "turns", "start ctx", "peak ctx", "peak % of limit", "tokens read", "graph calls"];
|
|
134
|
+
const row = (o) => [new Date(o.start).toISOString().slice(0, 16).replace("T", " "), o.agent, o.turns, kTokens(o.startCtx), kTokens(o.peakCtx), `${Math.round((100 * o.peakCtx) / window)}%`, kTokens(o.read), o.graph];
|
|
135
|
+
console.log(table([head, ...s.orchestrators.map(row)]));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
96
139
|
function print(root, asJson) {
|
|
97
|
-
const
|
|
140
|
+
const events = readEvents(root);
|
|
141
|
+
const s = summarise(events, sessionsFor(root, events));
|
|
98
142
|
if (asJson) return console.log(JSON.stringify(s, null, 2));
|
|
99
|
-
if (!s.workers.length && !s.reviews.length) return console.log("no worker runs recorded yet (orchestrate-workers writes them to .git/ccwf/runs.jsonl)");
|
|
143
|
+
if (!s.workers.length && !s.reviews.length && !s.orchestrators.length) return console.log("no worker runs recorded yet (orchestrate-workers writes them to .git/ccwf/runs.jsonl)");
|
|
100
144
|
if (s.workers.length) {
|
|
101
145
|
const head = ["agent", "model", "effort", "folder", "runs", "done", "first try", "min to finish", "fix rounds", "checks failed", "prompts", "conflicts", "failed starts"];
|
|
102
146
|
const row = (w) => [w.agent, w.model, w.effort, w.folder, w.runs, w.done, w.firstTry, w.minutesToFinish === null ? "-" : w.minutesToFinish.toFixed(1), w.fixRounds, w.checksFailed, w.gates, w.conflicts, w.failedStarts];
|
|
@@ -104,6 +148,7 @@ function print(root, asJson) {
|
|
|
104
148
|
console.log("\nfirst try: done with no fix round and no failed check. min to finish: median, from the start to the end of the first turn");
|
|
105
149
|
console.log("that passed or gave up, waiting for you included. Tickets differ in size: compare models only over many runs.");
|
|
106
150
|
}
|
|
151
|
+
printContext(s, transcripts.windowOf(mainRoot(root)));
|
|
107
152
|
for (const r of s.reviews) console.log(`\nreviewer ${r.agent} ${r.model}: ${r.reviews} reviews, ${r.withFindings} with findings${r.noVerdict ? `, ${r.noVerdict} without a verdict` : ""}`);
|
|
108
153
|
}
|
|
109
154
|
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// What the agents' own session files say about context: how big a session started, how big it got, and
|
|
3
|
+
// how many tokens it read. Claude Code keeps them in ~/.claude/projects/<folder>/*.jsonl, Codex in
|
|
4
|
+
// ~/.codex/sessions/<y>/<m>/<d>/*.jsonl. Cursor keeps none that can be read. Only numbers leave this
|
|
5
|
+
// file: no prompt, code or output is kept.
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
|
|
10
|
+
// A call, not a search for the tool: Codex writes `tools.mcp__codebase_memory__search_graph(`.
|
|
11
|
+
const GRAPH_CALL = /mcp__codebase[-_]memory__[a-z_]+\s*\(/g;
|
|
12
|
+
const slug = (p) => p.replace(/[^A-Za-z0-9]/g, "-");
|
|
13
|
+
const WORKER_PROMPT = /You are worker ([a-z]+)\./;
|
|
14
|
+
const workerOf = (text) => WORKER_PROMPT.exec(String(text).slice(0, 80));
|
|
15
|
+
const when = (iso) => (Number.isFinite(Date.parse(iso)) ? Date.parse(iso) : null);
|
|
16
|
+
|
|
17
|
+
function lines(file) {
|
|
18
|
+
try {
|
|
19
|
+
return fs.readFileSync(file, "utf8").split("\n");
|
|
20
|
+
} catch {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function tryParse(line) {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(line);
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function claudeText(content) {
|
|
34
|
+
if (typeof content === "string") return content;
|
|
35
|
+
return Array.isArray(content) ? (content.find((c) => c.type === "text") || {}).text || "" : "";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Claude Code: one assistant message is written once per content block, all with the same usage.
|
|
39
|
+
function parseClaude(file) {
|
|
40
|
+
const calls = new Map(); // message id -> usage
|
|
41
|
+
let prompt = null;
|
|
42
|
+
let start = null;
|
|
43
|
+
let orchestrator = false;
|
|
44
|
+
let graph = 0;
|
|
45
|
+
for (const line of lines(file)) {
|
|
46
|
+
if (!line) continue;
|
|
47
|
+
const isAssistant = line.includes('"type":"assistant"');
|
|
48
|
+
if (!isAssistant && (prompt !== null || !line.includes('"type":"user"'))) continue;
|
|
49
|
+
const e = tryParse(line);
|
|
50
|
+
if (!e) continue;
|
|
51
|
+
start = start ?? when(e.timestamp);
|
|
52
|
+
if (e.type === "user") {
|
|
53
|
+
prompt = claudeText(e.message && e.message.content);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const m = e.message || {};
|
|
57
|
+
if (m.usage && m.model !== "<synthetic>") calls.set(m.id || e.uuid, m.usage);
|
|
58
|
+
for (const c of m.content || []) {
|
|
59
|
+
if (c.type !== "tool_use") continue;
|
|
60
|
+
if (c.name === "Bash" && String((c.input || {}).command || "").includes("orchestrate-workers/")) orchestrator = true;
|
|
61
|
+
if (/^mcp__codebase[-_]memory/.test(c.name)) graph++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const usage = [...calls.values()];
|
|
65
|
+
const ctx = usage.map((u) => (u.input_tokens || 0) + (u.cache_read_input_tokens || 0) + (u.cache_creation_input_tokens || 0));
|
|
66
|
+
return finish({ agent: "claude", file, start, prompt: prompt || "", orchestrator, graph, ctx, output: usage.reduce((n, u) => n + (u.output_tokens || 0), 0) });
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Codex: one token_count event per model call; the same totals are sometimes written twice.
|
|
70
|
+
function parseCodex(file, root) {
|
|
71
|
+
let meta = null;
|
|
72
|
+
let prompt = null;
|
|
73
|
+
let orchestrator = false;
|
|
74
|
+
let graph = 0;
|
|
75
|
+
let lastTotal = -1;
|
|
76
|
+
let output = 0;
|
|
77
|
+
const ctx = [];
|
|
78
|
+
for (const line of lines(file)) {
|
|
79
|
+
if (!line) continue;
|
|
80
|
+
if (meta === null) {
|
|
81
|
+
const e = tryParse(line);
|
|
82
|
+
if (!e || e.type !== "session_meta") return null;
|
|
83
|
+
meta = e.payload || {};
|
|
84
|
+
if (!inRepo(meta.cwd || "", root)) return null;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (line.includes('"token_count"')) {
|
|
88
|
+
const p = (tryParse(line) || {}).payload || {};
|
|
89
|
+
const info = p.info;
|
|
90
|
+
if (!info || !info.last_token_usage || info.total_token_usage.total_tokens === lastTotal) continue;
|
|
91
|
+
lastTotal = info.total_token_usage.total_tokens;
|
|
92
|
+
ctx.push(info.last_token_usage.input_tokens || 0);
|
|
93
|
+
output = info.total_token_usage.output_tokens || 0;
|
|
94
|
+
} else if (/"type":"(function_call|custom_tool_call)"/.test(line)) {
|
|
95
|
+
if (line.includes("orchestrate-workers/")) orchestrator = true;
|
|
96
|
+
graph += (line.match(GRAPH_CALL) || []).length;
|
|
97
|
+
} else if (prompt === null && line.includes('"role":"user"')) {
|
|
98
|
+
const p = (tryParse(line) || {}).payload || {};
|
|
99
|
+
const text = (p.content || []).map((c) => c.text || "").join("");
|
|
100
|
+
if (workerOf(text)) prompt = text;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return finish({ agent: "codex", file, start: when(meta && meta.timestamp), prompt: prompt || "", orchestrator, graph, ctx, output });
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function finish(s) {
|
|
107
|
+
if (!s.ctx.length) return null;
|
|
108
|
+
const worker = workerOf(s.prompt);
|
|
109
|
+
return {
|
|
110
|
+
agent: s.agent,
|
|
111
|
+
start: s.start,
|
|
112
|
+
kind: worker ? "worker" : s.orchestrator ? "orchestrator" : "other",
|
|
113
|
+
worker: worker ? worker[1] : null,
|
|
114
|
+
prompt: worker ? s.prompt : "",
|
|
115
|
+
turns: s.ctx.length,
|
|
116
|
+
startCtx: s.ctx[0],
|
|
117
|
+
peakCtx: Math.max(...s.ctx),
|
|
118
|
+
read: s.ctx.reduce((a, b) => a + b, 0),
|
|
119
|
+
output: s.output,
|
|
120
|
+
graph: s.graph,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function inRepo(cwd, root) {
|
|
125
|
+
return cwd === root || cwd.startsWith(root + path.sep) || cwd.startsWith(root + "-workers" + path.sep);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Every Claude and Codex session of this repo (and of its worker folders) changed since `sinceMs`.
|
|
129
|
+
function readSessions(root, sinceMs, env = process.env) {
|
|
130
|
+
const out = [];
|
|
131
|
+
const recent = (f) => {
|
|
132
|
+
try {
|
|
133
|
+
return fs.statSync(f).mtimeMs >= sinceMs;
|
|
134
|
+
} catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const claudeProjects = path.join(env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude"), "projects");
|
|
139
|
+
let dirs = [];
|
|
140
|
+
try {
|
|
141
|
+
dirs = fs.readdirSync(claudeProjects).filter((d) => d === slug(root) || d.startsWith(slug(root) + "-workers-"));
|
|
142
|
+
} catch {}
|
|
143
|
+
for (const d of dirs) {
|
|
144
|
+
for (const f of fs.readdirSync(path.join(claudeProjects, d)).filter((f) => f.endsWith(".jsonl"))) {
|
|
145
|
+
const file = path.join(claudeProjects, d, f);
|
|
146
|
+
if (recent(file)) out.push(parseClaude(file));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const codexRoot = path.join(env.CODEX_HOME || path.join(os.homedir(), ".codex"), "sessions");
|
|
150
|
+
const walk = (dir) => {
|
|
151
|
+
let entries = [];
|
|
152
|
+
try {
|
|
153
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
154
|
+
} catch {}
|
|
155
|
+
for (const e of entries) {
|
|
156
|
+
const p = path.join(dir, e.name);
|
|
157
|
+
if (e.isDirectory()) walk(p);
|
|
158
|
+
else if (e.name.endsWith(".jsonl") && recent(p)) out.push(parseCodex(p, root));
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
walk(codexRoot);
|
|
162
|
+
return out.filter(Boolean);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Gives each recorded run (runlog.sh "start" event) the session that did it: the same agent, started
|
|
166
|
+
// within a few minutes of the run, with that ticket in its prompt. Nothing is guessed: no match, no numbers.
|
|
167
|
+
function matchRuns(events, sessions) {
|
|
168
|
+
const free = sessions.filter((s) => s.kind === "worker");
|
|
169
|
+
const bySession = new Map();
|
|
170
|
+
for (const e of events.filter((x) => x.e === "start" && (x.agent === "claude" || x.agent === "codex"))) {
|
|
171
|
+
let best = null;
|
|
172
|
+
for (const s of free) {
|
|
173
|
+
if (s.agent !== e.agent || s.worker !== e.worker || !s.start || [...bySession.values()].includes(s)) continue;
|
|
174
|
+
if (e.ticket && !s.prompt.includes(e.ticket)) continue;
|
|
175
|
+
const gap = s.start - e.t * 1000;
|
|
176
|
+
if (gap < -30000 || gap > 300000) continue;
|
|
177
|
+
if (!best || Math.abs(gap) < Math.abs(best.start - e.t * 1000)) best = s;
|
|
178
|
+
}
|
|
179
|
+
if (best) bySession.set(e.run, best);
|
|
180
|
+
}
|
|
181
|
+
return bySession;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function windowOf(root) {
|
|
185
|
+
try {
|
|
186
|
+
const m = /^\s*WINDOW\s*=\s*(\d+)/m.exec(fs.readFileSync(path.join(root, ".agents/skills/orchestrate-workers/context.conf"), "utf8"));
|
|
187
|
+
if (m) return Number(m[1]);
|
|
188
|
+
} catch {}
|
|
189
|
+
return 200000;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
module.exports = { readSessions, matchRuns, windowOf, parseClaude, parseCodex, slug };
|
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
## Browser verification (Claude Code, Codex, Cursor)
|
|
2
2
|
|
|
3
|
-
Every feature and every bug fix that can be seen in a browser, whether the change is in the UI or in the API behind it, is checked with the `verify-ui` skill before it is reported done.
|
|
3
|
+
Every feature and every bug fix that can be seen in a browser, whether the change is in the UI or in the API behind it, is checked with the `verify-ui` skill (`.agents/skills/verify-ui`) before it is reported done. Read the accessibility tree, never a screenshot, to check that something exists, loaded or says the right thing; screenshot only for purely visual questions (layout, colors).
|
|
4
4
|
|
|
5
|
-
- **Feature:** write its scenario, run it, then run the whole suite.
|
|
6
|
-
- **
|
|
7
|
-
|
|
8
|
-
- **
|
|
9
|
-
- **Show, debug or act on a page with the user** through the `chrome-devtools` MCP. It opens the system's Chrome in its own window, with a profile kept per project, so logins persist between sessions; the user can watch and take over. Start the dev server first, then `new_page` or `navigate_page` to it. Use `take_snapshot`, `click`, `fill`, console, network and performance tools. The first agent to start on this project holds that profile until it exits; any other agent, and every worker, gets a separate temporary browser without those logins. Only the project's allowed sites load.
|
|
10
|
-
- **Scripted and headless checks** use verify-ui or agent-browser in a dedicated session. Get an ID with `agent-browser session id --scope worktree --prefix task`, then pass `--session <id>` to every command. `open <url>` → `snapshot -i -c` → act on refs → `console` → `close`.
|
|
11
|
-
- **Dev server**: start it as a background process and stop it by its ID; never `pkill`/`killall`.
|
|
12
|
-
- **Allowed sites** come from `ALLOWED_DOMAINS` in `verify-ui.conf` (`example.com` is that host only, `*.example.com` includes its subdomains) and are enforced by `--allowedUrlPattern` for Chrome DevTools MCP and by `AGENT_BROWSER_ALLOWED_DOMAINS` for agent-browser (Claude: `.claude/settings.json`; Codex: `.codex/config.toml`; Cursor: prefix agent-browser commands with it, the `verify-ui` scripts set it themselves). Never visit a site that is not listed; ask the user to add it.
|
|
5
|
+
- **Feature:** write its scenario, run it, then run the whole suite. **Bug:** first reproduce it as a failing scenario, then fix, then keep the scenario as the regression test.
|
|
6
|
+
- **With the user, or to debug live:** the `chrome-devtools` MCP opens the system's Chrome with this project's profile, so logins persist and the user can watch. The first agent to start holds that profile; any other agent, and every worker, gets a temporary browser without those logins. Start the dev server first, then `new_page` or `navigate_page`.
|
|
7
|
+
- **Dev server:** start it as a background process and stop it by its ID; never `pkill`/`killall`.
|
|
8
|
+
- **Allowed sites** are `ALLOWED_DOMAINS` in `.agents/skills/verify-ui/verify-ui.conf` (`example.com` is that host only, `*.example.com` includes its subdomains; the skill asks for it on first use, then run `npx @mayurdluffy/ccwf sync`). Never visit a site that is not listed; ask the user to add it. Cursor: prefix a raw `agent-browser` command with `AGENT_BROWSER_ALLOWED_DOMAINS=<list>`; the verify-ui scripts set it themselves.
|
package/templates/blocks/cbm.md
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
## Codebase navigation (Claude Code, Codex, Cursor)
|
|
2
2
|
|
|
3
|
-
Use the codebase-memory MCP (server `codebase-memory`) before Grep/Read
|
|
3
|
+
Use the codebase-memory MCP (server `codebase-memory`) before Grep/Read, in this order: project docs → graph (`search_graph`, `trace_path`, `get_code_snippet`, `get_architecture`) → Grep/Read only on a graph miss or for non-code files.
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
8
|
-
- Exclusions go in the root `.cbmignore`; the indexer also honors `.gitignore`.
|
|
9
|
-
- Re-index after large changes: `npx @mayurdluffy/cbm-cli re-index` (refreshes the committed `.codebase-memory/graph.db.zst`).
|
|
5
|
+
- Claude Code lists these tools without their definitions: load them with ToolSearch (query `codebase-memory`) before the first search, or they go unused.
|
|
6
|
+
- Exclusions go in the root `.cbmignore`; the indexer also honors `.gitignore`. Re-index after large changes: `npx @mayurdluffy/cbm-cli re-index`.
|
|
7
|
+
- Server setup, the launcher, and why there is one cache and no global server entry: `docs/agents/setup.md`.
|
package/templates/blocks/core.md
CHANGED
|
@@ -7,6 +7,7 @@ Bias toward caution over speed; use judgment on trivial tasks. Lean by default.
|
|
|
7
7
|
- Identify callers, tests, config, exports, and data the change could break.
|
|
8
8
|
- State assumptions. If the request is ambiguous or has several readings, present them and ask; don't pick silently or invent product behavior. Push back when a simpler approach exists.
|
|
9
9
|
- Define how success will be verified. For multi-step work, state a short plan with a verify check per step.
|
|
10
|
+
- Read narrowly: find with `rg -n`, read ranges with `sed -n 'A,Bp'`, never print a whole file over ~200 lines, and pipe commands that can print a lot through `head` or `tail`. Everything you read stays in context for the rest of the session.
|
|
10
11
|
|
|
11
12
|
**Use the first option that fully solves it**
|
|
12
13
|
1. Does it need to exist? Skip speculative features, options, flexibility; state the skipped scope in one line.
|
|
@@ -40,7 +40,7 @@ One coding agent is the **orchestrator**; it does not write feature code. Up to
|
|
|
40
40
|
6. **You check** anything a person should judge (UI, security) and say go.
|
|
41
41
|
7. Commit with the `commit` skill (Conventional Commits, one per ticket), mark tickets done, update `docs/FEATURES.md`, start the next wave.
|
|
42
42
|
|
|
43
|
-
State lives in the ticket `**Status:**` lines and `.scratch/<feature>/progress.md`, so a new session resumes from the files.
|
|
43
|
+
State lives in the ticket `**Status:**` lines and `.scratch/<feature>/progress.md`, so a new session resumes from the files. That is why the orchestrator hands off to a fresh session after every wave and at 65% of its context window (`context.conf`): a long session costs more per turn and answers worse.
|
|
44
44
|
|
|
45
45
|
## Along the way
|
|
46
46
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: agent-browser
|
|
3
|
-
description: Browser automation CLI for AI agents.
|
|
3
|
+
description: Browser automation CLI for AI agents. Open pages, read the accessibility tree, click, fill forms, take screenshots, extract data, test web apps, exploratory QA. Use it when a task needs programmatic web interaction. In this project check your own changes with the verify-ui skill first and use this one by hand to explore. Electron apps, Slack and cloud browsers load with `agent-browser skills get <name>`.
|
|
4
4
|
allowed-tools: Bash(agent-browser:*)
|
|
5
5
|
hidden: true
|
|
6
6
|
---
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# A folder per worker
|
|
2
|
+
|
|
3
|
+
Read this before assigning anything, when `workers.conf` has the row `isolation worktree`. Part of the `orchestrate-workers` skill; the loop in `SKILL.md` still applies, with the changes below.
|
|
4
|
+
|
|
5
|
+
Only when `workers.conf` has the row `isolation worktree`. Change it only while every worker is idle and no worker folder is left. Then each worker gets its own folder, `../<repo>-workers/<name>`: a copy of the main folder as it is at that moment, uncommitted work included. What changes in the loop:
|
|
6
|
+
|
|
7
|
+
- **Assign** as always: `assign.sh` creates the folder first. The worker must be idle (no queueing). In the prompt, write "none" for the other tickets, and add: "Write the scenario file but do not run the browser suite: the dev server shows another folder."
|
|
8
|
+
- **Status** changes stay in the main folder (`tickets.sh set`). The worker's report, its ticked boxes and your `## Review findings` go in the ticket file in the worker's folder; they come over with the merge.
|
|
9
|
+
- **Review** in two parts. In the worker's folder (`cd "$(.agents/skills/orchestrate-workers/worktree.sh path <name>)"`, then back): steps 1, 2, 3 and 5. `git diff HEAD` there is exactly this ticket. When that passes, merge from the main folder, one ticket at a time: `.agents/skills/orchestrate-workers/worktree.sh merge <name>`. Then run the completion checks and step 4 (the browser suite) in the main folder. Only then is the ticket `reviewed`.
|
|
10
|
+
- `CONFLICT`: the main folder is unchanged. Run `worktree.sh update <name>`, tell the worker which files hold conflict markers and which ticket the other side is from, start its watcher, then review and merge again.
|
|
11
|
+
- Exit 4 (`checks: failed`): the tickets do not work together. Send the worker back; its folder now holds the merged state. Merge again after the fix.
|
|
12
|
+
- **Nothing is committed** by the merge. The user's go-ahead and the commits work as before.
|
|
13
|
+
- **Clean-up is automatic.** `end.sh` deletes the folder when its work is merged, and `grid.sh` deletes what a crashed session left. `KEPT` names work that is not merged: merge it, or ask the user before `worktree.sh discard <name>`. Never delete these folders by hand. After a later bug report, assign again: the worker gets a fresh folder.
|
|
14
|
+
|
|
15
|
+
A new folder has no ignored files: no `node_modules`, no `.env`. If the project needs them, write `worktree-setup.sh` beside this file, show it to the user, and commit it executable. It runs in each new folder with `MAIN` (the main folder) and `WORKER` set:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
#!/bin/sh
|
|
19
|
+
set -e
|
|
20
|
+
[ ! -f "$MAIN/.env" ] || cp "$MAIN/.env" .env
|
|
21
|
+
cp -cR "$MAIN/node_modules" . 2>/dev/null || npm ci # -c on a Mac: a copy that takes almost no disk space
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Monorepos have more than one `node_modules`: use the package manager's own install there.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Options
|
|
2
|
+
|
|
3
|
+
Two parts of the `orchestrate-workers` skill that apply only with a particular `workers.conf` setting. Read this file only then.
|
|
4
|
+
|
|
5
|
+
## Effort `auto`
|
|
6
|
+
|
|
7
|
+
When the roster says `auto`, pick per ticket: `medium` normally, `high` for tickets that set a pattern others copy or touch auth, crypto, webhooks or shared behaviour other tickets build on, `low` for mechanical renames. Name the chosen effort in the progress row. Give the riskiest ticket of a wave to the strongest free worker, not just the first.
|
|
8
|
+
|
|
9
|
+
## A `reviewer` row
|
|
10
|
+
|
|
11
|
+
Run `.agents/skills/orchestrate-workers/review.sh <ticket> <files this ticket changed>` (a few minutes, so in the background). It asks a fresh agent that sees only the ticket and the diff. Exit 1: check each finding in the code yourself; send back the real ones and drop the others with one line of why in the ticket. Exit 2 is not a pass: read why and run it again. Run it once per ticket, and again only after a fix that changed the logic.
|
|
12
|
+
|
|
13
|
+
The `review.sh` command and the findings it prints are used in step 5 of Review in `SKILL.md`; record the result as that section says.
|