@mayurdluffy/ccwf 0.1.0 → 0.2.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 +19 -6
- package/lib/index.js +30 -12
- package/lib/installer.js +160 -20
- package/lib/merge.js +10 -1
- package/lib/merge3.js +81 -0
- package/lib/modules.js +12 -6
- package/package.json +1 -1
- package/templates/docs/agents/setup.md +1 -1
- package/templates/skills/orchestrate-workers/HC.md +2 -2
- package/templates/skills/orchestrate-workers/SKILL.md +10 -10
- package/templates/skills/orchestrate-workers/approve.sh +1 -1
- package/templates/skills/orchestrate-workers/assign.sh +23 -0
- package/templates/skills/orchestrate-workers/end.sh +1 -1
- package/templates/skills/orchestrate-workers/grid.sh +74 -17
- package/templates/skills/orchestrate-workers/pane.sh +2 -2
- package/templates/skills/orchestrate-workers/watch.sh +2 -2
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@mayurdluffy/ccwf)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://github.com/mayurdluffy/ccwf/actions/workflows/ci.yml)
|
|
6
|
-
[](https://github.com/mayurdluffy/ccwf/actions/workflows/publish.yml)
|
|
7
5
|
|
|
8
6
|
One command that sets up the same agent system on any computer and in any repo, for **Claude Code, Codex and Cursor** (only those three; macOS and Linux).
|
|
9
7
|
|
|
@@ -27,7 +25,7 @@ npx @mayurdluffy/ccwf init # tools + user-level skills + project files
|
|
|
27
25
|
| `memory` | `.agent-memory/MEMORY.md` + rules |
|
|
28
26
|
| `tracking` | empty `docs/GLOSSARY.md`, `DECISIONS.md`, `FEATURES.md`, `BACKLOG.md`, `adr/` + rules; `docs/agents/{domain,issue-tracker,triage-labels}.md` |
|
|
29
27
|
| `browser` | `agent-browser` + `verify-ui` skills, `chrome-devtools` MCP, `.cursor/cli.json`, Claude MCP approval and allowed sites |
|
|
30
|
-
| `workers` | `orchestrate-workers` skill (herdr
|
|
28
|
+
| `workers` | `orchestrate-workers` skill (a `workers` tab of four panes in the orchestrator's own herdr space, `hc` reference, `workers.conf`) |
|
|
31
29
|
|
|
32
30
|
Skills live in `.agents/skills/` (Codex, Cursor); Claude Code gets symlinks in `.claude/skills/`. Files are written only for the agents you select.
|
|
33
31
|
|
|
@@ -43,13 +41,27 @@ A skill that needs project settings asks you the first time it runs and saves th
|
|
|
43
41
|
|---|---|
|
|
44
42
|
| `ccwf init` | machine setup + repo setup (`--agents`, `--modules`, `--project-only`, `--machine-only`, `--yes`, `--dry-run`, `--force`, `--dir`) |
|
|
45
43
|
| `ccwf add <module>` | add a module |
|
|
46
|
-
| `ccwf update` | the only command that re-renders templates from this ccwf version; edited
|
|
44
|
+
| `ccwf update` | the only command that re-renders templates from this ccwf version; files you edited are merged, not overwritten (see below) |
|
|
47
45
|
| `ccwf sync` | push skill settings into agent configs and add navigation rules; does not re-render templates |
|
|
48
46
|
| `ccwf doctor` | check tools, skills and files; offer to fix |
|
|
49
47
|
| `ccwf eject <skill>` | stop managing a skill you changed |
|
|
50
48
|
| `ccwf status` | installed modules, drifted files |
|
|
51
49
|
|
|
52
|
-
State is in `.ccwf.json` (choices and a hash of every file ccwf wrote). Commit it.
|
|
50
|
+
State is in `.ccwf.json` (choices and a hash of every file, managed block and seeded doc ccwf wrote). Commit it.
|
|
51
|
+
|
|
52
|
+
## Updating a repo set up with an older ccwf
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx @mayurdluffy/ccwf@latest update
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`update` brings in new skills, scripts, rules and docs and keeps everything you wrote:
|
|
59
|
+
|
|
60
|
+
- **Your own text in `AGENTS.md`** (domain notes, anything outside the `<!-- ccwf:begin/end -->` markers) is never touched. If you edited inside a managed block, your edit is merged with the new block.
|
|
61
|
+
- **Files ccwf owns** (skills, scripts, guides): untouched ones are replaced; ones you edited are merged 3-way against the version ccwf last wrote (kept in `.git/ccwf/base/`, or found in git history after a fresh clone).
|
|
62
|
+
- **Seeded docs** (`docs/GLOSSARY.md`, `DECISIONS.md`, ...): new template lines are merged in; your entries stay. `workers.conf` (your roster) is never re-rendered.
|
|
63
|
+
- Where your edit and the new version change the same lines, the file gets git-style markers (`<<<<<<< current` / `=======` / `>>>>>>> incoming (ccwf X)`) and a warning; `ccwf status` lists files that still have them, and `update` skips them until you resolve them.
|
|
64
|
+
- `--dry-run` shows what would change (`*` merged, `x` conflict); `--force` replaces files ccwf owns instead of merging; `ccwf eject <skill>` stops managing a skill.
|
|
53
65
|
|
|
54
66
|
## What a first run looks like
|
|
55
67
|
|
|
@@ -77,7 +89,8 @@ Then follow `docs/agents/workflow.md` in your repo. Commit `.ccwf.json` and the
|
|
|
77
89
|
| You see | Do |
|
|
78
90
|
|---|---|
|
|
79
91
|
| `skipped: not a terminal; re-run with --yes` | run `ccwf init --yes` from a terminal script, or install by hand from `docs/agents/setup.md` |
|
|
80
|
-
| `warning: <file>:
|
|
92
|
+
| `warning: <file>: your edits and the new version overlap` | resolve the `<<<<<<< current` / `>>>>>>> incoming` markers in that file, then commit |
|
|
93
|
+
| `warning: <file>: merged without the previous ccwf version` | no record of what ccwf wrote last time: your lines and the new lines were combined; read the file once |
|
|
81
94
|
| `... already defined by hand, skipped` | you wrote that config table yourself; ccwf leaves it alone |
|
|
82
95
|
| `next: codebase-memory is not set up here` | run `npx @mayurdluffy/cbm-cli install --agents claude,codex,cursor`, then `ccwf sync` |
|
|
83
96
|
| anything else | `ccwf doctor` checks tools, skills and files and offers to fix them |
|
package/lib/index.js
CHANGED
|
@@ -4,12 +4,13 @@ const os = require("os");
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const readline = require("readline/promises");
|
|
6
6
|
const { Installer, sha } = require("./installer");
|
|
7
|
+
const { hasConflict } = require("./merge3");
|
|
7
8
|
const { MODULES, ORDER, AGENTS, makeParams, sync } = require("./modules");
|
|
8
9
|
const machine = require("./machine");
|
|
9
10
|
const pkg = require("../package.json");
|
|
10
11
|
|
|
11
12
|
const MANIFEST = ".ccwf.json";
|
|
12
|
-
const STATE_MARK = { created: "+", updated: "~", unchanged: "=", skipped: "!" };
|
|
13
|
+
const STATE_MARK = { created: "+", updated: "~", merged: "*", conflict: "x", unchanged: "=", skipped: "!" };
|
|
13
14
|
|
|
14
15
|
const HELP = `ccwf ${pkg.version} — agent setup for Claude Code, Codex and Cursor (macOS, Linux)
|
|
15
16
|
|
|
@@ -17,7 +18,7 @@ Usage: ccwf <command> [options]
|
|
|
17
18
|
|
|
18
19
|
init set up this computer (tools, user-level skills) and the current repo
|
|
19
20
|
add <module> add one module to an initialised repo
|
|
20
|
-
update the only command that re-renders templates from this ccwf version
|
|
21
|
+
update the only command that re-renders templates from this ccwf version; files you edited are merged
|
|
21
22
|
sync push skill settings and add navigation rules; does not re-render templates
|
|
22
23
|
doctor check tools, skills and files; offer to fix what is missing
|
|
23
24
|
eject <skill> stop managing a skill you changed
|
|
@@ -33,7 +34,7 @@ Options:
|
|
|
33
34
|
--machine-only skip the repo
|
|
34
35
|
--yes, -y no prompts (install everything missing)
|
|
35
36
|
--dry-run show what would change, write and install nothing
|
|
36
|
-
--force overwrite only files ccwf owns, never seeded docs
|
|
37
|
+
--force overwrite only files ccwf owns instead of merging, never seeded docs
|
|
37
38
|
--dir PATH target repo (default: current directory)
|
|
38
39
|
-h, --help -v, --version`;
|
|
39
40
|
|
|
@@ -66,6 +67,11 @@ function list(v, all, what) {
|
|
|
66
67
|
return items;
|
|
67
68
|
}
|
|
68
69
|
|
|
70
|
+
// What the manifest records about content ccwf wrote, so update can tell your edits from its own.
|
|
71
|
+
function tracked(src) {
|
|
72
|
+
return { files: { ...src?.files }, blocks: { ...src?.blocks }, seeds: { ...src?.seeds } };
|
|
73
|
+
}
|
|
74
|
+
|
|
69
75
|
function loadManifest(root) {
|
|
70
76
|
try {
|
|
71
77
|
return JSON.parse(fs.readFileSync(path.join(root, MANIFEST), "utf8"));
|
|
@@ -92,7 +98,7 @@ async function confirm(question, def = true) {
|
|
|
92
98
|
|
|
93
99
|
// One line per path: a file touched by several modules reports its strongest state.
|
|
94
100
|
function collapse(log) {
|
|
95
|
-
const rank = { unchanged: 0, skipped: 1, updated: 2,
|
|
101
|
+
const rank = { unchanged: 0, skipped: 1, updated: 2, merged: 3, created: 4, conflict: 5 };
|
|
96
102
|
const by = new Map();
|
|
97
103
|
for (const { rel, state } of log) if (!by.has(rel) || rank[state] > rank[by.get(rel)]) by.set(rel, state);
|
|
98
104
|
return [...by].map(([rel, state]) => ({ rel, state }));
|
|
@@ -102,7 +108,8 @@ function report(ins, dryRun) {
|
|
|
102
108
|
const log = collapse(ins.log);
|
|
103
109
|
for (const { rel, state } of log) if (state !== "unchanged") console.log(` ${STATE_MARK[state]} ${rel}`);
|
|
104
110
|
const n = (s) => log.filter((l) => l.state === s).length;
|
|
105
|
-
|
|
111
|
+
const merged = n("merged") + n("conflict") ? `, ${n("merged")} merged, ${n("conflict")} with conflicts` : "";
|
|
112
|
+
console.log(`${dryRun ? "would change" : "repo"}: ${n("created")} created, ${n("updated")} updated${merged}, ${n("unchanged")} unchanged, ${n("skipped")} skipped`);
|
|
106
113
|
for (const w of ins.warnings) console.log(` warning: ${w}`);
|
|
107
114
|
}
|
|
108
115
|
|
|
@@ -158,8 +165,8 @@ function globalCbmFindings() {
|
|
|
158
165
|
|
|
159
166
|
// ---- project ----
|
|
160
167
|
|
|
161
|
-
function applyProject({ root, agents, modules, ejected,
|
|
162
|
-
const ins = new Installer({ root, dryRun, force,
|
|
168
|
+
function applyProject({ root, agents, modules, ejected, prev, dryRun, force }) {
|
|
169
|
+
const ins = new Installer({ root, dryRun, force, ejected, version: pkg.version, ...tracked(prev) });
|
|
163
170
|
const ctx = { ins, agents, params: makeParams({ agents }) };
|
|
164
171
|
for (const m of ORDER.filter((x) => modules.includes(x))) MODULES[m].run(ctx);
|
|
165
172
|
const synced = sync(ctx, modules);
|
|
@@ -225,10 +232,11 @@ async function install(cmd, opts, root) {
|
|
|
225
232
|
let synced = { cbm: true };
|
|
226
233
|
if (!opts["machine-only"]) {
|
|
227
234
|
if (!fs.existsSync(path.join(root, ".git"))) console.log(" note: not a git repo root; ccwf works anyway, but `commit`/`orchestrate-workers` expect git");
|
|
228
|
-
const r = applyProject({ root, agents, modules, ejected,
|
|
235
|
+
const r = applyProject({ root, agents, modules, ejected, prev, dryRun: opts["dry-run"], force: opts.force });
|
|
229
236
|
synced = r.synced;
|
|
237
|
+
if (cmd === "update" && prev.ccwf !== pkg.version) console.log(`update: ccwf ${prev.ccwf} -> ${pkg.version}`);
|
|
230
238
|
report(r.ins, opts["dry-run"]);
|
|
231
|
-
if (!opts["dry-run"]) saveManifest(root, { agents, modules, ejected,
|
|
239
|
+
if (!opts["dry-run"]) saveManifest(root, { agents, modules, ejected, ...tracked(r.ins) });
|
|
232
240
|
}
|
|
233
241
|
if (!opts["project-only"] && cmd === "init") await machineSetup({ agents, modules, root, opts });
|
|
234
242
|
if (!opts["machine-only"]) projectNextSteps(synced);
|
|
@@ -238,11 +246,11 @@ async function runSync(opts, root) {
|
|
|
238
246
|
const prev = loadManifest(root);
|
|
239
247
|
if (!prev) throw new Error(`no ${MANIFEST} here; run \`ccwf init\` first`);
|
|
240
248
|
// Settings and the navigation block only. Re-rendering templates is update's job.
|
|
241
|
-
const ins = new Installer({ root, dryRun: opts["dry-run"], force: false,
|
|
249
|
+
const ins = new Installer({ root, dryRun: opts["dry-run"], force: false, ejected: prev.ejected || [], version: pkg.version, ...tracked(prev) });
|
|
242
250
|
const agents = prev.agents;
|
|
243
251
|
const synced = sync({ ins, agents, params: makeParams({ agents }) }, prev.modules);
|
|
244
252
|
report(ins, opts["dry-run"]);
|
|
245
|
-
if (!opts["dry-run"]) saveManifest(root, { ...prev,
|
|
253
|
+
if (!opts["dry-run"]) saveManifest(root, { ...prev, ...tracked(ins) }, prev.ccwf);
|
|
246
254
|
console.log(`allowed sites: ${synced.domains}${synced.cbm ? " · codebase-memory rules: on" : ""}`);
|
|
247
255
|
projectNextSteps(synced);
|
|
248
256
|
}
|
|
@@ -278,6 +286,16 @@ function status(root) {
|
|
|
278
286
|
}
|
|
279
287
|
}
|
|
280
288
|
console.log(drift ? `${drift} file(s) differ from what ccwf wrote` : "all ccwf-owned files match");
|
|
289
|
+
const paths = [...new Set([...Object.keys(m.files), ...Object.keys(m.seeds || {}), ...Object.keys(m.blocks || {}).map((k) => k.split("#")[0])])];
|
|
290
|
+
const conflicts = paths.filter((rel) => {
|
|
291
|
+
try {
|
|
292
|
+
return hasConflict(fs.readFileSync(path.join(root, rel), "utf8"));
|
|
293
|
+
} catch {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
for (const rel of conflicts) console.log(` conflict markers: ${rel}`);
|
|
298
|
+
if (conflicts.length) console.log(`${conflicts.length} file(s) still have conflict markers from \`ccwf update\``);
|
|
281
299
|
}
|
|
282
300
|
|
|
283
301
|
async function doctor(opts, root) {
|
|
@@ -288,7 +306,7 @@ async function doctor(opts, root) {
|
|
|
288
306
|
const agents = m?.agents || AGENTS;
|
|
289
307
|
const modules = m?.modules || ORDER;
|
|
290
308
|
await machineSetup({ agents, modules, root: m ? root : null, opts, fixOnly: true });
|
|
291
|
-
if (m) projectNextSteps(applyProject({ root, agents, modules, ejected: m.ejected || [],
|
|
309
|
+
if (m) projectNextSteps(applyProject({ root, agents, modules, ejected: m.ejected || [], prev: m, dryRun: true, force: false }).synced);
|
|
292
310
|
}
|
|
293
311
|
|
|
294
312
|
async function main(argv = process.argv.slice(2)) {
|
package/lib/installer.js
CHANGED
|
@@ -2,22 +2,82 @@
|
|
|
2
2
|
const fs = require("fs");
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const crypto = require("crypto");
|
|
5
|
-
const {
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
const { upsertBlock, getBlock, mergeJson, hasTableOutsideBlock, missingMarker } = require("./merge");
|
|
7
|
+
const { merge3, merge2, hasConflict } = require("./merge3");
|
|
6
8
|
|
|
7
9
|
const sha = (s) => crypto.createHash("sha256").update(s).digest("hex");
|
|
8
10
|
|
|
9
11
|
// Applies file operations under `root`, records what it did, and never clobbers user edits.
|
|
12
|
+
// When the user edited something ccwf wrote and the template changed too, the two are merged:
|
|
13
|
+
// 3-way against the version ccwf last wrote when it can be found, else 2-way with conflict markers.
|
|
10
14
|
class Installer {
|
|
11
|
-
constructor({ root, dryRun = false, force = false, files = {}, ejected = [] }) {
|
|
15
|
+
constructor({ root, dryRun = false, force = false, files = {}, blocks = {}, seeds = {}, ejected = [], version = "new" }) {
|
|
12
16
|
this.root = root;
|
|
13
17
|
this.ejected = ejected; // path prefixes the user took over (ccwf eject)
|
|
14
18
|
this.dryRun = dryRun;
|
|
15
19
|
this.force = force;
|
|
20
|
+
this.version = version; // the ccwf version writing now, for conflict labels
|
|
16
21
|
this.files = { ...files }; // rel -> sha256 of the content ccwf last wrote
|
|
17
|
-
this.
|
|
22
|
+
this.blocks = { ...blocks }; // "rel#id" -> sha256 of the managed block body ccwf last wrote
|
|
23
|
+
this.seeds = { ...seeds }; // rel -> sha256 of the seeded doc ccwf last wrote
|
|
24
|
+
this.log = []; // { rel, state: created|updated|merged|conflict|unchanged|skipped }
|
|
18
25
|
this.warnings = [];
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
git(...args) {
|
|
29
|
+
const r = spawnSync("git", args, { cwd: this.root, encoding: "utf8", maxBuffer: 64 << 20 });
|
|
30
|
+
return r.status === 0 ? r.stdout : null;
|
|
31
|
+
}
|
|
32
|
+
gitDir() {
|
|
33
|
+
if (this._gitDir === undefined) this._gitDir = this.git("rev-parse", "--absolute-git-dir")?.trim() || null;
|
|
34
|
+
return this._gitDir;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Keep a copy of what ccwf wrote, so the next update can merge against it (.git/ccwf/base/<sha>).
|
|
38
|
+
remember(content) {
|
|
39
|
+
const dir = this.gitDir();
|
|
40
|
+
if (this.dryRun || !dir) return;
|
|
41
|
+
const f = path.join(dir, "ccwf", "base", sha(content));
|
|
42
|
+
if (fs.existsSync(f)) return;
|
|
43
|
+
fs.mkdirSync(path.dirname(f), { recursive: true });
|
|
44
|
+
fs.writeFileSync(f, content);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The content ccwf last wrote (hash), from the local copy or else from the file's git history.
|
|
48
|
+
recall(hash, rel, extract = (t) => t) {
|
|
49
|
+
const dir = this.gitDir();
|
|
50
|
+
if (!dir) return null;
|
|
51
|
+
try {
|
|
52
|
+
return fs.readFileSync(path.join(dir, "ccwf", "base", hash), "utf8");
|
|
53
|
+
} catch {}
|
|
54
|
+
const revs = (this.git("log", "--all", "--format=%H", "-n", "200", "--", rel) || "").split("\n").filter(Boolean);
|
|
55
|
+
for (const rev of revs) {
|
|
56
|
+
const text = this.git("show", `${rev}:./${rel}`);
|
|
57
|
+
const part = text === null ? null : extract(text);
|
|
58
|
+
if (part !== null && sha(part) === hash) return part;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Merge the user's `cur` with the new template `incoming`. Returns { text, conflicts } or null (skip).
|
|
64
|
+
// `label` names it in warnings (a file, or file#block); `rel` is the file whose history holds the base.
|
|
65
|
+
merge(label, rel, cur, baseHash, incoming, extract) {
|
|
66
|
+
if (hasConflict(cur)) {
|
|
67
|
+
this.warn(`${label}: still has conflict markers from an earlier update; resolve them, then re-run`);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const base = this.recall(baseHash, rel, extract);
|
|
71
|
+
const r = base !== null ? merge3(cur, base, incoming, this.version) : merge2(cur, incoming, this.version);
|
|
72
|
+
if (!r) {
|
|
73
|
+
this.warn(`${label}: modified locally and could not be merged, left as is (use --force to overwrite)`);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
if (r.conflicts) this.warn(`${label}: your edits and the new version overlap in ${r.conflicts} place(s); resolve the <<<<<<< current / >>>>>>> incoming markers`);
|
|
77
|
+
else if (base === null) this.warn(`${label}: merged without the previous ccwf version (your lines kept, new lines added); check it`);
|
|
78
|
+
return r;
|
|
79
|
+
}
|
|
80
|
+
|
|
21
81
|
abs(rel) {
|
|
22
82
|
return path.join(this.root, rel);
|
|
23
83
|
}
|
|
@@ -41,31 +101,89 @@ class Installer {
|
|
|
41
101
|
if (mode) fs.chmodSync(this.abs(rel), mode);
|
|
42
102
|
}
|
|
43
103
|
|
|
44
|
-
// A file ccwf owns: replaced on update
|
|
104
|
+
// A file ccwf owns: replaced on update while it still matches what ccwf wrote; merged when the user edited it.
|
|
45
105
|
owned(rel, content, mode) {
|
|
46
106
|
if (this.ejected.some((p) => rel === p || rel.startsWith(p + "/"))) return this.note(rel, "unchanged");
|
|
47
107
|
const cur = this.read(rel);
|
|
48
|
-
|
|
108
|
+
const base = this.files[rel];
|
|
109
|
+
const record = () => {
|
|
49
110
|
this.files[rel] = sha(content);
|
|
111
|
+
this.remember(content);
|
|
112
|
+
};
|
|
113
|
+
if (cur === content) {
|
|
114
|
+
record();
|
|
50
115
|
return this.note(rel, "unchanged");
|
|
51
116
|
}
|
|
52
|
-
if (cur
|
|
53
|
-
this.
|
|
117
|
+
if (cur === null || this.force || base === sha(cur)) {
|
|
118
|
+
this.write(rel, content, mode);
|
|
119
|
+
record();
|
|
120
|
+
return this.note(rel, cur === null ? "created" : "updated");
|
|
121
|
+
}
|
|
122
|
+
if (hasConflict(cur)) {
|
|
123
|
+
this.warn(`${rel}: still has conflict markers from an earlier update; resolve them, then re-run`);
|
|
54
124
|
return this.note(rel, "skipped");
|
|
55
125
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
126
|
+
if (!base) {
|
|
127
|
+
this.warn(`${rel}: exists and was not written by ccwf, left as is (use --force to overwrite)`);
|
|
128
|
+
return this.note(rel, "skipped");
|
|
129
|
+
}
|
|
130
|
+
if (base === sha(content)) return this.note(rel, "unchanged"); // your edit stays; nothing new from ccwf
|
|
131
|
+
const r = this.merge(rel, rel, cur, base, content);
|
|
132
|
+
if (!r) return this.note(rel, "skipped");
|
|
133
|
+
if (r.text !== cur) this.write(rel, r.text, mode);
|
|
134
|
+
record();
|
|
135
|
+
this.note(rel, r.conflicts ? "conflict" : r.text === cur ? "unchanged" : "merged");
|
|
59
136
|
}
|
|
60
137
|
|
|
61
|
-
// A file the user will edit: written once
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this.
|
|
65
|
-
|
|
138
|
+
// A file the user will edit: written once. With `merge`, a later template change is merged into it
|
|
139
|
+
// (taken as is while the user has not edited it). --force does not apply.
|
|
140
|
+
seed(rel, content, mode, merge = false) {
|
|
141
|
+
const cur = this.read(rel);
|
|
142
|
+
const record = () => {
|
|
143
|
+
if (!merge) return;
|
|
144
|
+
this.seeds[rel] = sha(content);
|
|
145
|
+
this.remember(content);
|
|
146
|
+
};
|
|
147
|
+
if (cur === null) {
|
|
148
|
+
this.write(rel, content, mode);
|
|
149
|
+
record();
|
|
150
|
+
return this.note(rel, "created");
|
|
151
|
+
}
|
|
152
|
+
const base = this.seeds[rel];
|
|
153
|
+
if (merge && hasConflict(cur)) {
|
|
154
|
+
this.warn(`${rel}: still has conflict markers from an earlier update; resolve them, then re-run`);
|
|
155
|
+
return this.note(rel, "skipped");
|
|
156
|
+
}
|
|
157
|
+
if (!merge || cur === content || !base || base === sha(content)) {
|
|
158
|
+
if (cur === content) record();
|
|
159
|
+
return this.note(rel, "unchanged");
|
|
160
|
+
}
|
|
161
|
+
if (sha(cur) === base) {
|
|
162
|
+
this.write(rel, content, mode);
|
|
163
|
+
record();
|
|
164
|
+
return this.note(rel, "updated");
|
|
165
|
+
}
|
|
166
|
+
const r = this.merge(rel, rel, cur, base, content);
|
|
167
|
+
if (!r) return this.note(rel, "skipped");
|
|
168
|
+
if (r.text !== cur) this.write(rel, r.text, mode);
|
|
169
|
+
record();
|
|
170
|
+
this.note(rel, r.conflicts ? "conflict" : r.text === cur ? "unchanged" : "merged");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// A one-off fix to a file the user owns (a rename ccwf made). `fn` returns the new text or the same text.
|
|
174
|
+
rewrite(rel, fn, why) {
|
|
175
|
+
if (this.ejected.some((p) => rel.startsWith(p + "/"))) return;
|
|
176
|
+
const cur = this.read(rel);
|
|
177
|
+
if (cur === null) return;
|
|
178
|
+
const next = fn(cur);
|
|
179
|
+
if (next === cur) return;
|
|
180
|
+
this.write(rel, next);
|
|
181
|
+
this.warn(`${rel}: ${why}`);
|
|
182
|
+
this.note(rel, "updated");
|
|
66
183
|
}
|
|
67
184
|
|
|
68
|
-
// Managed section inside a shared text file (AGENTS.md, .gitignore, config.toml).
|
|
185
|
+
// Managed section inside a shared text file (AGENTS.md, .gitignore, config.toml). Text outside the
|
|
186
|
+
// markers is never touched; an edit inside them is merged with the new body.
|
|
69
187
|
block(rel, id, body, style = "md") {
|
|
70
188
|
const raw = this.read(rel);
|
|
71
189
|
const cur = raw ?? "";
|
|
@@ -74,10 +192,32 @@ class Installer {
|
|
|
74
192
|
this.warn(`${rel}: managed block ${id} has no ${missing} marker, skipped`);
|
|
75
193
|
return this.note(rel, "skipped");
|
|
76
194
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
195
|
+
const key = `${rel}#${id}`;
|
|
196
|
+
// Bodies are compared and stored with one trailing newline, the way line merges expect them.
|
|
197
|
+
const want = body.trimEnd() + "\n";
|
|
198
|
+
const got = getBlock(cur, id, style);
|
|
199
|
+
const have = got === null ? null : got + "\n";
|
|
200
|
+
const base = this.blocks[key];
|
|
201
|
+
let next = want;
|
|
202
|
+
let state = null;
|
|
203
|
+
if (have !== null && have !== want && !this.force && base && base !== sha(have)) {
|
|
204
|
+
if (base === sha(want)) next = have; // your edit stays; nothing new from ccwf
|
|
205
|
+
else {
|
|
206
|
+
const r = this.merge(`${rel} (block ${id})`, rel, have, base, want, (t) => {
|
|
207
|
+
const b = getBlock(t, id, style);
|
|
208
|
+
return b === null ? null : b + "\n";
|
|
209
|
+
});
|
|
210
|
+
if (!r) return this.note(rel, "skipped");
|
|
211
|
+
next = r.text;
|
|
212
|
+
state = r.conflicts ? "conflict" : "merged";
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
this.blocks[key] = sha(want);
|
|
216
|
+
this.remember(want);
|
|
217
|
+
const text = upsertBlock(cur, id, next, style);
|
|
218
|
+
if (text === cur) return this.note(rel, "unchanged");
|
|
219
|
+
this.write(rel, text);
|
|
220
|
+
this.note(rel, raw === null ? "created" : state || "updated");
|
|
81
221
|
}
|
|
82
222
|
|
|
83
223
|
// Codex TOML: a managed block, unless the user already defines the same table by hand.
|
package/lib/merge.js
CHANGED
|
@@ -32,6 +32,15 @@ function upsertBlock(text, id, body, style = "md") {
|
|
|
32
32
|
return `${text}${sep}${block}\n`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
// The text between the markers of block `id`, or null when the block is not there.
|
|
36
|
+
function getBlock(text, id, style = "md") {
|
|
37
|
+
if (missingMarker(text, id, style)) return null;
|
|
38
|
+
const begin = STYLES[style](id, "begin");
|
|
39
|
+
const end = STYLES[style](id, "end");
|
|
40
|
+
const m = new RegExp(`${escapeRe(begin)}\\n([\\s\\S]*?)\\n?${escapeRe(end)}`).exec(text);
|
|
41
|
+
return m ? m[1] : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
35
44
|
function removeBlock(text, id, style = "md") {
|
|
36
45
|
const begin = STYLES[style](id, "begin");
|
|
37
46
|
const end = STYLES[style](id, "end");
|
|
@@ -89,4 +98,4 @@ function mergeJson(text, patch, label = "JSON file", union = []) {
|
|
|
89
98
|
return JSON.stringify(deepMerge(data, p), null, 2) + "\n";
|
|
90
99
|
}
|
|
91
100
|
|
|
92
|
-
module.exports = { upsertBlock, removeBlock, hasTableOutsideBlock, mergeJson, missingMarker };
|
|
101
|
+
module.exports = { upsertBlock, getBlock, removeBlock, hasTableOutsideBlock, mergeJson, missingMarker };
|
package/lib/merge3.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Line merges for `ccwf update`: keep what the user wrote, bring in what the new template adds.
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const { spawnSync } = require("child_process");
|
|
7
|
+
|
|
8
|
+
const CURRENT = "<<<<<<< current";
|
|
9
|
+
const SPLIT = "=======";
|
|
10
|
+
const incomingLabel = (version) => `incoming (ccwf ${version})`;
|
|
11
|
+
|
|
12
|
+
// True when the text still holds conflict markers from an earlier merge.
|
|
13
|
+
function hasConflict(text) {
|
|
14
|
+
return /^<<<<<<< current$/m.test(text || "");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// 3-way merge with `git merge-file`. Returns { text, conflicts } or null when git cannot run.
|
|
18
|
+
function merge3(current, base, incoming, version) {
|
|
19
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "ccwf-merge-"));
|
|
20
|
+
try {
|
|
21
|
+
const p = (n, s) => (fs.writeFileSync(path.join(dir, n), s), path.join(dir, n));
|
|
22
|
+
const args = ["merge-file", "-p", "-L", "current", "-L", "base", "-L", incomingLabel(version)];
|
|
23
|
+
const r = spawnSync("git", [...args, p("current", current), p("base", base), p("incoming", incoming)], { encoding: "utf8" });
|
|
24
|
+
if (r.error || r.status === null || r.status < 0 || r.status > 127) return null;
|
|
25
|
+
return { text: r.stdout, conflicts: r.status };
|
|
26
|
+
} finally {
|
|
27
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function splitLines(s) {
|
|
32
|
+
if (s === "") return [];
|
|
33
|
+
const lines = s.split("\n");
|
|
34
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
35
|
+
return lines;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Longest common subsequence of two line arrays, as pairs of indexes.
|
|
39
|
+
function lcs(a, b) {
|
|
40
|
+
const n = a.length;
|
|
41
|
+
const m = b.length;
|
|
42
|
+
const dp = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
43
|
+
for (let i = n - 1; i >= 0; i--) for (let j = m - 1; j >= 0; j--) dp[i][j] = a[i] === b[j] ? dp[i + 1][j + 1] + 1 : Math.max(dp[i + 1][j], dp[i][j + 1]);
|
|
44
|
+
const pairs = [];
|
|
45
|
+
for (let i = 0, j = 0; i < n && j < m; ) {
|
|
46
|
+
if (a[i] === b[j]) pairs.push([i++, j++]);
|
|
47
|
+
else if (dp[i + 1][j] >= dp[i][j + 1]) i++;
|
|
48
|
+
else j++;
|
|
49
|
+
}
|
|
50
|
+
return pairs;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 2-way merge when the content ccwf last wrote is unknown. Lines only the user has are kept,
|
|
54
|
+
// lines only the template has are added, and a region both changed gets conflict markers.
|
|
55
|
+
function merge2(current, incoming, version) {
|
|
56
|
+
const a = splitLines(current);
|
|
57
|
+
const b = splitLines(incoming);
|
|
58
|
+
if (a.length * b.length > 4e6) return null;
|
|
59
|
+
const out = [];
|
|
60
|
+
let conflicts = 0;
|
|
61
|
+
let i = 0;
|
|
62
|
+
let j = 0;
|
|
63
|
+
const flush = (ie, je) => {
|
|
64
|
+
const mine = a.slice(i, ie);
|
|
65
|
+
const theirs = b.slice(j, je);
|
|
66
|
+
if (mine.length && theirs.length) {
|
|
67
|
+
out.push(CURRENT, ...mine, SPLIT, ...theirs, `>>>>>>> ${incomingLabel(version)}`);
|
|
68
|
+
conflicts++;
|
|
69
|
+
} else out.push(...mine, ...theirs);
|
|
70
|
+
};
|
|
71
|
+
for (const [ie, je] of lcs(a, b)) {
|
|
72
|
+
flush(ie, je);
|
|
73
|
+
out.push(a[ie]);
|
|
74
|
+
i = ie + 1;
|
|
75
|
+
j = je + 1;
|
|
76
|
+
}
|
|
77
|
+
flush(a.length, b.length);
|
|
78
|
+
return { text: out.length ? out.join("\n") + "\n" : "", conflicts };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = { merge3, merge2, hasConflict };
|
package/lib/modules.js
CHANGED
|
@@ -30,7 +30,7 @@ function skillFiles(name, params) {
|
|
|
30
30
|
rel,
|
|
31
31
|
content: render(fs.readFileSync(path.join(dir, rel), "utf8"), params),
|
|
32
32
|
mode: st.mode & 0o111 ? 0o755 : undefined,
|
|
33
|
-
seed: rel === "workers.conf",
|
|
33
|
+
seed: rel === "workers.conf", // the user's roster: written once, never merged
|
|
34
34
|
};
|
|
35
35
|
});
|
|
36
36
|
}
|
|
@@ -39,7 +39,7 @@ function installSkill(ctx, name) {
|
|
|
39
39
|
const { ins, params, agents } = ctx;
|
|
40
40
|
for (const f of skillFiles(name, params)) {
|
|
41
41
|
const rel = `.agents/skills/${name}/${f.rel}`;
|
|
42
|
-
if (f.seed) ins.seed(rel, f.content, f.mode);
|
|
42
|
+
if (f.seed) ins.seed(rel, f.content, f.mode, false);
|
|
43
43
|
else ins.owned(rel, f.content, f.mode);
|
|
44
44
|
}
|
|
45
45
|
if (agents.includes("claude")) {
|
|
@@ -115,7 +115,7 @@ const MODULES = {
|
|
|
115
115
|
memory: {
|
|
116
116
|
desc: "shared .agent-memory/ for all three agents",
|
|
117
117
|
run(ctx) {
|
|
118
|
-
ctx.ins.seed(".agent-memory/MEMORY.md", tpl("agent-memory", "MEMORY.md"));
|
|
118
|
+
ctx.ins.seed(".agent-memory/MEMORY.md", tpl("agent-memory", "MEMORY.md"), undefined, true);
|
|
119
119
|
ctx.ins.block("AGENTS.md", "memory", blockBody("memory", ctx.params));
|
|
120
120
|
},
|
|
121
121
|
},
|
|
@@ -123,9 +123,9 @@ const MODULES = {
|
|
|
123
123
|
desc: "empty GLOSSARY, DECISIONS, FEATURES, BACKLOG, adr/ + the rules for using them",
|
|
124
124
|
run(ctx) {
|
|
125
125
|
const { ins } = ctx;
|
|
126
|
-
for (const f of ["GLOSSARY", "DECISIONS", "BACKLOG", "FEATURES"]) ins.seed(`docs/${f}.md`, tpl("docs", `${f}.md`));
|
|
126
|
+
for (const f of ["GLOSSARY", "DECISIONS", "BACKLOG", "FEATURES"]) ins.seed(`docs/${f}.md`, tpl("docs", `${f}.md`), undefined, true);
|
|
127
127
|
ins.seed("docs/adr/.gitkeep", "");
|
|
128
|
-
for (const f of ["domain", "issue-tracker", "triage-labels"]) ins.seed(`docs/agents/${f}.md`, tpl("docs", "agents", `${f}.md`));
|
|
128
|
+
for (const f of ["domain", "issue-tracker", "triage-labels"]) ins.seed(`docs/agents/${f}.md`, tpl("docs", "agents", `${f}.md`), undefined, true);
|
|
129
129
|
ins.block("AGENTS.md", "tracking", blockBody("tracking", ctx.params));
|
|
130
130
|
},
|
|
131
131
|
},
|
|
@@ -145,6 +145,12 @@ const MODULES = {
|
|
|
145
145
|
desc: "orchestrate-workers skill (needs herdr + hc)",
|
|
146
146
|
run(ctx) {
|
|
147
147
|
installSkill(ctx, "orchestrate-workers");
|
|
148
|
+
// ccwf 0.1 named the fourth worker theta; the panes now look up delta.
|
|
149
|
+
ctx.ins.rewrite(
|
|
150
|
+
".agents/skills/orchestrate-workers/workers.conf",
|
|
151
|
+
(t) => (/^delta\s/m.test(t) ? t : t.replace(/^theta(\s+)/m, (m, sp) => `delta${sp}`)),
|
|
152
|
+
"renamed worker theta to delta (rebuild the workers tab: grid.sh --rebuild)",
|
|
153
|
+
);
|
|
148
154
|
ctx.ins.block("AGENTS.md", "workers", blockBody("workers", ctx.params));
|
|
149
155
|
},
|
|
150
156
|
},
|
|
@@ -182,7 +188,7 @@ function sync(ctx, modules) {
|
|
|
182
188
|
|
|
183
189
|
const ORDER = Object.keys(MODULES);
|
|
184
190
|
|
|
185
|
-
const WORKER_NAMES = ["alpha", "beta", "gamma", "
|
|
191
|
+
const WORKER_NAMES = ["alpha", "beta", "gamma", "delta"];
|
|
186
192
|
const DEFAULT_MODEL = { claude: "claude-sonnet-5-5", codex: "gpt-5-codex", cursor: "grok-4.7" };
|
|
187
193
|
|
|
188
194
|
function defaultRoster(agents) {
|
package/package.json
CHANGED
|
@@ -44,5 +44,5 @@ Log in once per agent (not scriptable): `claude`, `codex login`, `cursor-agent l
|
|
|
44
44
|
## 5. Keeping it healthy
|
|
45
45
|
|
|
46
46
|
- `npx @mayurdluffy/ccwf doctor` — checks tools, skills and files; offers to fix.
|
|
47
|
-
- `npx @mayurdluffy/ccwf update` — re-render from a newer `ccwf`; files you edited are
|
|
47
|
+
- `npx @mayurdluffy/ccwf update` — re-render from a newer `ccwf`; files you edited are merged with the new version (your text kept, overlaps marked `<<<<<<< current` / `>>>>>>> incoming`). After it, run `.agents/skills/orchestrate-workers/grid.sh --rebuild` once the workers are idle.
|
|
48
48
|
- `npx @mayurdluffy/ccwf eject <skill>` — stop `ccwf` from managing a skill you changed.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# `hc` quick reference
|
|
2
2
|
|
|
3
|
-
Coding agents (Claude Code, Codex, cursor-agent) run in **herdr** terminal tabs. `hc` (herdr-core) lets one agent talk to another's pane from the shell.
|
|
3
|
+
Coding agents (Claude Code, Codex, cursor-agent) run in **herdr** terminal tabs. Each orchestrator owns the `workers` tab in its own herdr space; never act on terminals in another space. `hc` (herdr-core) lets one agent talk to another's pane from the shell.
|
|
4
4
|
|
|
5
|
-
- `hc ls` — list terminals (address like `t2`, agent, cwd, status).
|
|
5
|
+
- `hc ls` — list terminals (address like `t2`, agent, cwd, status). Pane addresses change: for workers use `.git/hc-workers/<name>.t`, which the panes keep current.
|
|
6
6
|
- `hc read <t>` — print a pane's screen and history.
|
|
7
7
|
- `hc send <t> <text>` — paste text and press enter. It prefixes a `<hc from=...>` header, so use it for agent prompts, not shell commands. To type a shell command: `hc keys <t> c o d e x enter`.
|
|
8
8
|
- `hc wait <t>` — block until the agent stops working (never returns for cursor-agent; the skill's `watch.sh` covers that). Also: `hc interrupt`, `hc keys`, `hc put <t> <file>`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: orchestrate-workers
|
|
3
|
-
description: Run a ticket set as an orchestrator, with agent CLIs (Codex, Cursor, Claude; any model and effort) as TDD workers in a 2x2 grid herdr tab named
|
|
3
|
+
description: Run a ticket set as an orchestrator, with agent CLIs (Codex, Cursor, Claude; any model and effort) as TDD workers in a 2x2 grid herdr tab named workers in the orchestrator's own herdr space, then review, stop for the user's check, and commit. Use when the user says "orchestrate", "use workers", "run the tickets with codex/cursor", "continue the loop", or asks to work through `.scratch/<feature>/issues/` in parallel.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# orchestrate-workers
|
|
@@ -13,7 +13,7 @@ All loop state lives in files, never only in your context: the tickets' `Status:
|
|
|
13
13
|
|
|
14
14
|
0. **Confirm the roster first, every session.** Read `workers.conf` (the user's last decision: agent, model and effort per worker). Ask the user once (AskUserQuestion): keep it, or change it? On a change, rewrite the rows and the `decided:` line, and log the question and answer in `docs/DECISIONS.md` if the project has one. Never assign a ticket before this answer.
|
|
15
15
|
1. Read `.scratch/<feature>/progress.md` (table plus its `## Resume` section). Do not re-read the spec; workers read it.
|
|
16
|
-
2.
|
|
16
|
+
2. Run `.agents/skills/orchestrate-workers/grid.sh`: it builds the `workers` tab in your own herdr space, or prints the workers when that tab is already there. If a worker is mid-ticket, restart its watcher (step 4 of the loop) instead of reassigning.
|
|
17
17
|
3. Act on `## Resume` → "Next action".
|
|
18
18
|
|
|
19
19
|
## The loop
|
|
@@ -29,7 +29,7 @@ All loop state lives in files, never only in your context: the tickets' `Status:
|
|
|
29
29
|
- `EXITED` (agent closed, pane idle). If the lines show `[name] ERROR:`, the job never ran: fix what it names (usually the `workers.conf` row) and assign again. Otherwise check the ticket for a report before treating it as finished.
|
|
30
30
|
- `GATE` → approve with `.agents/skills/orchestrate-workers/approve.sh <name>` (it presses the key that agent expects: Claude ignores `y`) only if the command is local and safe (installing a dependency: first check the `package.json` diff for new packages), then start the watcher again. Never answer a product decision; that goes to the user.
|
|
31
31
|
- `TIMEOUT` (50 minutes) → read the printed lines: still working, start the watcher again; stuck or looping, end the session and reassign with a note of what went wrong.
|
|
32
|
-
- `STUCK` or `GONE` → the pane is dead:
|
|
32
|
+
- `STUCK` or `GONE` → the pane is dead: rebuild the tab with `grid.sh --rebuild` (see "The workers tab").
|
|
33
33
|
|
|
34
34
|
Do not use `hc wait` (it never returns for cursor-agent) and do not `hc read` busy workers. Routine-command allowlists: `.cursor/cli.json` (Cursor), `claude-worker-settings.json` in this folder (Claude); Codex runs sandboxed and asks only to leave the sandbox.
|
|
35
35
|
5. **Review each ticket as its worker finishes** (see Review). Send defects back to the same worker session. Other workers keep running. Set the ticket to `in-review` while you do.
|
|
@@ -78,21 +78,21 @@ Update `## Resume` whenever the next action changes: after assigning, after each
|
|
|
78
78
|
|
|
79
79
|
## The workers tab
|
|
80
80
|
|
|
81
|
-
Four workers, by pane: `alpha` top left, `beta` top right, `gamma` bottom left, `
|
|
81
|
+
Four workers, by pane: `alpha` top left, `beta` top right, `gamma` bottom left, `delta` bottom right. Which agent, model and effort each one runs is in `workers.conf`, not here: `pane.sh` reads its row fresh for every ticket, so a roster change applies from each worker's next ticket without rebuilding the tab. Supported agents: `codex`, `cursor`, `claude`, in any mix. A row that cannot start (unknown agent, missing CLI, an agent that quits within 20 seconds on a bad model id or login) leaves `[name] ERROR: ...` above the pane's idle line, and the watcher prints it.
|
|
82
82
|
|
|
83
|
-
The tab is named `
|
|
83
|
+
The tab is named `workers`, lives in your own herdr space (the one holding your terminal) and is always a 2x2 grid. Manage it only with `.agents/skills/orchestrate-workers/grid.sh`: no argument builds it or reports the one already there; `--rebuild` closes your space's `workers` tab and builds a new one, and refuses while any worker is busy. Other spaces have their own orchestrators and `workers` tabs (other repos, other features): never close, reuse, send to or read their tabs, and never call `herdr-app do tab.close` or `space.close` yourself. Each pane runs `pane.sh <name>`: it starts one agent per job file, returns to idle when the agent exits, and reloads itself after every ticket. Each pane writes its terminal address to `.git/hc-workers/<name>.t`: `assign.sh`, `watch.sh`, `approve.sh` and `end.sh` take the worker name directly; for hc use `hc send $(<.git/hc-workers/alpha.t) '...'`. (herdr only names a terminal started with `hc run --name`, and those cannot be placed in a grid, so the grid panes stay unnamed in herdr; the pane shows `[name]` and its title.)
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
After `ccwf update` changes this skill, run `grid.sh --rebuild` once every worker is idle, so the panes run the new scripts (a tab from before the rename to `workers` and `delta` is replaced the same way).
|
|
86
|
+
|
|
87
|
+
**Assign** with `assign.sh` (the pane picks the job up within 2 seconds). Always pass the prompt in a quoted heredoc: inside double quotes the shell runs anything in backticks and silently drops it from the prompt. `assign.sh` writes the job file in one rename, so the pane never reads half of it, and refuses when that worker already has a job waiting.
|
|
86
88
|
|
|
87
89
|
```sh
|
|
88
|
-
|
|
89
|
-
default
|
|
90
|
+
.agents/skills/orchestrate-workers/assign.sh alpha default <<'EOF'
|
|
90
91
|
<prompt>
|
|
91
92
|
EOF
|
|
92
|
-
mv .git/hc-workers/alpha.job.tmp .git/hc-workers/alpha.job # line 1: effort, or "default" = roster
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
Assign only to a pane that shows `idle`;
|
|
95
|
+
The second argument is the effort: `default` (the roster's) or `low | medium | high | xhigh`. Assign only to a pane that shows `idle`; `assign.sh` says `queued` when an agent is still running there, and that job starts by itself when the agent exits.
|
|
96
96
|
|
|
97
97
|
Effort: use the roster's (`default`). Only when the roster says `auto` do you 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.
|
|
98
98
|
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
# Approve the approval prompt a worker is showing, once, with the key its agent expects:
|
|
3
3
|
# Claude shows a numbered menu ("1. Yes") and ignores y; Codex and Cursor take y.
|
|
4
4
|
# Usage: approve.sh <worker-name|terminal>
|
|
5
|
-
t=$1; f=$(git rev-parse --git-dir 2>/dev/null)/hc-workers/$1.t; [[ -s $f ]] && t=$(<$f)
|
|
5
|
+
t=$1; f=$(git rev-parse --absolute-git-dir 2>/dev/null)/hc-workers/$1.t; [[ -s $f ]] && t=$(<$f)
|
|
6
6
|
if hc read "$t" 2>/dev/null | grep -qE '❯ +1\. Yes'; then key=1; else key=y; fi
|
|
7
7
|
hc keys "$t" $key >/dev/null
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env zsh
|
|
2
|
+
# Give a worker its next ticket: reads the prompt from stdin and writes the job file in one rename,
|
|
3
|
+
# so the pane never reads half a file. Pass the prompt with a quoted heredoc (<<'EOF'): inside double
|
|
4
|
+
# quotes the shell would run anything in backticks and drop it from the prompt.
|
|
5
|
+
# Usage: assign.sh <name> [effort] <<'EOF'
|
|
6
|
+
# <prompt>
|
|
7
|
+
# EOF
|
|
8
|
+
# effort: low | medium | high | xhigh, or default (the roster's; also when omitted)
|
|
9
|
+
# Exit 1 without writing when the worker has no pane, already has a job waiting, or the prompt is empty.
|
|
10
|
+
name=$1 effort=${2:-default}
|
|
11
|
+
[[ -n $name ]] || { echo "usage: assign.sh <name> [effort] < prompt"; exit 1; }
|
|
12
|
+
[[ $effort == (default|low|medium|high|xhigh|-) ]] || { echo "unknown effort '$effort'"; exit 1; }
|
|
13
|
+
d=$(git rev-parse --absolute-git-dir)/hc-workers
|
|
14
|
+
[[ -s $d/$name.t ]] || { echo "no pane for '$name' ($d/$name.t): run grid.sh"; exit 1; }
|
|
15
|
+
[[ -e $d/$name.job ]] && { echo "$name already has a job waiting; not replaced"; exit 1; }
|
|
16
|
+
prompt=$(cat)
|
|
17
|
+
[[ -n ${prompt//[[:space:]]/} ]] || { echo "empty prompt: pass it on stdin"; exit 1; }
|
|
18
|
+
{ print -r -- "$effort"; print -r -- "$prompt"; } > $d/$name.job.tmp && mv $d/$name.job.tmp $d/$name.job || exit 1
|
|
19
|
+
if hc read "$(<$d/$name.t)" 2>/dev/null | grep -qE '^\[[a-z]+\] idle: waiting for a ticket'; then
|
|
20
|
+
echo "assigned $name ($effort)"
|
|
21
|
+
else
|
|
22
|
+
echo "queued for $name ($effort): it starts when the running agent exits (end.sh $name to end it now)"
|
|
23
|
+
fi
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# Presses ctrl+c twice with a pause: cursor-agent ignores two presses that arrive together,
|
|
4
4
|
# and Claude forgets the first press after about a second. Tries a short gap first, then a longer one.
|
|
5
5
|
# Usage: end.sh <worker-name|terminal> Exit 0 = idle, 1 = still running (prints the screen end).
|
|
6
|
-
t=$1; f=$(git rev-parse --git-dir 2>/dev/null)/hc-workers/$1.t; [[ -s $f ]] && t=$(<$f)
|
|
6
|
+
t=$1; f=$(git rev-parse --absolute-git-dir 2>/dev/null)/hc-workers/$1.t; [[ -s $f ]] && t=$(<$f)
|
|
7
7
|
idle() { hc read "$t" 2>/dev/null | grep -qE '^\[[a-z]+\] idle: waiting for a ticket'; }
|
|
8
8
|
for i in 1 2 3; do
|
|
9
9
|
idle && { echo "idle $t"; exit 0; }
|
|
@@ -1,24 +1,81 @@
|
|
|
1
1
|
#!/usr/bin/env zsh
|
|
2
|
-
#
|
|
2
|
+
# The "workers" tab: a 2x2 grid in the orchestrator's own herdr space, one worker per pane.
|
|
3
3
|
# alpha | beta
|
|
4
|
-
# gamma |
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
4
|
+
# gamma | delta
|
|
5
|
+
# Usage: grid.sh build the tab; when this space already has one, print its workers and exit 0
|
|
6
|
+
# grid.sh --rebuild close this space's workers tab (only while every worker is idle), then build it
|
|
7
|
+
# Only the space holding this terminal ($HC_TERMINAL_ID) is read or changed. Workers tabs in other
|
|
8
|
+
# spaces (other repos, other orchestrators) are never closed or reused.
|
|
9
|
+
# Each pane records its terminal address in <git-dir>/hc-workers/<name>.t, so watch.sh, approve.sh,
|
|
10
|
+
# end.sh and assign.sh take the worker name.
|
|
8
11
|
root=$(git rev-parse --show-toplevel) || exit 1
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
d=$(git rev-parse --absolute-git-dir)/hc-workers
|
|
13
|
+
P=${0:A:h}/pane.sh
|
|
14
|
+
names=(alpha beta gamma delta)
|
|
15
|
+
[[ -n $HC_TERMINAL_ID ]] || { echo "run this from the orchestrator's own herdr terminal (HC_TERMINAL_ID is not set)"; exit 1; }
|
|
16
|
+
|
|
17
|
+
# Prints: line 1 this space's id; then one line per workers tab in it: "<tab id> <terminal>...".
|
|
18
|
+
# "worker" is the tab name ccwf 0.1 used.
|
|
19
|
+
mine() {
|
|
20
|
+
herdr-app ls | python3 -c '
|
|
21
|
+
import json, sys
|
|
22
|
+
me = sys.argv[1]
|
|
23
|
+
for s in json.load(sys.stdin)["spaces"]:
|
|
24
|
+
if any(x["terminal"] == me for t in s["tabs"] for x in t["terminals"]):
|
|
25
|
+
print(s["id"])
|
|
26
|
+
for t in s["tabs"]:
|
|
27
|
+
if t["name"] in ("workers", "worker"):
|
|
28
|
+
print(t["id"], *[x["terminal"] for x in t["terminals"]])
|
|
29
|
+
sys.exit(0)
|
|
30
|
+
sys.exit(1)' "$HC_TERMINAL_ID"
|
|
31
|
+
}
|
|
32
|
+
idle() { hc read "$1" 2>/dev/null | grep -qE '^\[[a-z]+\] idle: waiting for a ticket'; }
|
|
33
|
+
show() { for n in $names; do print -n "$n=$(cat $d/$n.t 2>/dev/null) "; done; echo; }
|
|
34
|
+
|
|
35
|
+
out=$(mine) || { echo "terminal $HC_TERMINAL_ID is not in any herdr space (herdr-app ls)"; exit 1; }
|
|
36
|
+
lines=("${(@f)out}")
|
|
37
|
+
space=$lines[1]
|
|
38
|
+
tabs=("${(@)lines[2,-1]}") # "<tab id> <terminal>..." per workers tab in this space
|
|
39
|
+
|
|
40
|
+
if [[ $1 == --rebuild ]]; then
|
|
41
|
+
for line in $tabs; do
|
|
42
|
+
w=(${=line})
|
|
43
|
+
for t in ${w[2,-1]}; do
|
|
44
|
+
idle $t || { echo "not rebuilt: terminal $t is busy; end its session first (end.sh)"; exit 1; }
|
|
45
|
+
done
|
|
46
|
+
done
|
|
47
|
+
for line in $tabs; do w=(${=line}); herdr-app do tab.close --id $w[1] >/dev/null || exit 1; done
|
|
48
|
+
tabs=()
|
|
49
|
+
elif [[ -n $1 ]]; then
|
|
50
|
+
echo "usage: grid.sh [--rebuild]"; exit 1
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
if (( $#tabs )); then
|
|
54
|
+
w=(${=tabs[1]}); terms=(${w[2,-1]})
|
|
55
|
+
for n in $names; do
|
|
56
|
+
t=$(cat $d/$n.t 2>/dev/null)
|
|
57
|
+
(( ${terms[(Ie)$t]} )) || { echo "this space's workers tab does not match $d/$n.t (pane gone or owned by another space): grid.sh --rebuild"; exit 1; }
|
|
58
|
+
done
|
|
59
|
+
print -n "workers tab already in this space: "; show; exit 0
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
mkdir -p $d && rm -f $d/${^names}.t
|
|
11
63
|
j() { python3 -c "import json,sys; print(json.load(sys.stdin)['$1'])"; }
|
|
12
64
|
argv() { print -r -- "[\"$P\",\"$1\"]"; }
|
|
13
|
-
t1=$(herdr-app do tab.new --name
|
|
14
|
-
p1=$(herdr-app ls | python3 -c
|
|
15
|
-
import json,sys
|
|
16
|
-
for s in json.load(sys.stdin)[
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
65
|
+
t1=$(herdr-app do tab.new --name workers --space "$space" --folder "$root" --argv "$(argv alpha)" | j terminal) || exit 1
|
|
66
|
+
p1=$(herdr-app ls | python3 -c '
|
|
67
|
+
import json, sys
|
|
68
|
+
for s in json.load(sys.stdin)["spaces"]:
|
|
69
|
+
for t in s["tabs"]:
|
|
70
|
+
for x in t["terminals"]:
|
|
71
|
+
if x["terminal"] == sys.argv[1]: print(x["pane"])' "$t1")
|
|
72
|
+
[[ -n $p1 ]] || { echo "new tab's pane not found"; exit 1; }
|
|
20
73
|
p2=$(herdr-app do pane.split --direction right --pane "$p1" --argv "$(argv beta)" | j pane) || exit 1
|
|
21
74
|
herdr-app do pane.split --direction down --pane "$p1" --argv "$(argv gamma)" >/dev/null || exit 1
|
|
22
|
-
herdr-app do pane.split --direction down --pane "$p2" --argv "$(argv
|
|
23
|
-
|
|
24
|
-
for n in
|
|
75
|
+
herdr-app do pane.split --direction down --pane "$p2" --argv "$(argv delta)" >/dev/null || exit 1
|
|
76
|
+
for i in {1..20}; do
|
|
77
|
+
ok=1; for n in $names; do [[ -s $d/$n.t ]] || ok=0; done
|
|
78
|
+
(( ok )) && break; sleep 0.5
|
|
79
|
+
done
|
|
80
|
+
(( ok )) || { print -n "some panes did not start: "; show; exit 1; }
|
|
81
|
+
show
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env zsh
|
|
2
2
|
# One worker pane. Waits for a job file, runs one agent session on it, and
|
|
3
3
|
# returns to waiting when that agent exits, so every ticket gets a fresh context.
|
|
4
|
-
# Usage: pane.sh <name> name = a row in workers.conf (alpha | beta | gamma |
|
|
4
|
+
# Usage: pane.sh <name> name = a row in workers.conf (alpha | beta | gamma | delta)
|
|
5
5
|
# Agent and model come from workers.conf, read fresh for every ticket.
|
|
6
6
|
# Job file: <git-dir>/hc-workers/<name>.job
|
|
7
7
|
# line 1: effort for this ticket (low | medium | high | xhigh), or "default" for the roster's
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
name=$1
|
|
11
11
|
root=$(git rev-parse --show-toplevel) || exit 1
|
|
12
12
|
here=${0:A:h}
|
|
13
|
-
dir=$
|
|
13
|
+
dir=$(git rev-parse --absolute-git-dir)/hc-workers # also right in a git worktree
|
|
14
14
|
mkdir -p "$dir"
|
|
15
15
|
cd "$root"
|
|
16
16
|
trap : INT
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
# around that prompt (not the whole screen) match this regex.
|
|
8
8
|
# Exit 0 = DONE (turn finished) or EXITED (agent closed, pane idle; shows a pane ERROR line if any),
|
|
9
9
|
# 2 = GATE (needs you), 3 = TIMEOUT, STUCK (job never picked up) or GONE (terminal unreadable).
|
|
10
|
-
t=$1; d=$(git rev-parse --git-dir 2>/dev/null)/hc-workers; [[ -s $d/$1.t ]] && t=$(<$d/$1.t) # worker name -> address
|
|
10
|
+
t=$1; d=$(git rev-parse --absolute-git-dir 2>/dev/null)/hc-workers; [[ -s $d/$1.t ]] && t=$(<$d/$1.t) # worker name -> address
|
|
11
11
|
limit=${2:-3000}; start=$SECONDS; quiet=0; last=""; approved=""
|
|
12
|
-
gate='Run this [A-Za-z ]+\?|Do you want to (proceed|make this edit|create)|Would you like to (run|send|make)|Press enter to confirm|Waiting for approval|\(y/n\)'
|
|
12
|
+
gate='Run this [A-Za-z ]+\?|Write to this file\?|Allow this [A-Za-z ]+\?|Trust this (workspace|folder)|Do you want to (proceed|make this edit|create)|Would you like to (run|send|make)|Press enter to confirm|Waiting for approval|\(y/n\)'
|
|
13
13
|
busy='ctrl\+c to stop|esc to interrupt|Working|Generating|Running'
|
|
14
14
|
|
|
15
15
|
# A job that was just assigned: wait for the pane to pick it up, or the idle screen reads as EXITED.
|