crewbus 10.0.7 → 10.0.9
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/CHANGELOG.md +21 -0
- package/README.md +41 -8
- package/bin/crewbus.js +259 -27
- package/bin/lib/identity.js +56 -1
- package/bin/lib/mail.js +14 -2
- package/bin/lib/spawn.js +202 -10
- package/bin/lib/store.js +5 -3
- package/bin/lib/web.js +252 -49
- package/bin/lib/workbench.js +188 -0
- package/docs/SPLIT.md +5 -4
- package/docs/VERSION_SKEW.md +1 -1
- package/documentation.html +365 -359
- package/index.html +9 -8
- package/package.json +2 -2
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// bin/lib/workbench.js — Artifacts + lessons: the compound-memory layer.
|
|
2
|
+
// Purpose: make worker output load-bearing for teammates instead of
|
|
3
|
+
// DM-status-only (feed-forward, the Minecraft-paper lever set):
|
|
4
|
+
// artifacts = board objects with depends-on edges; adoption + verification
|
|
5
|
+
// are recorded ON the object, so a later crew can see what was reused and
|
|
6
|
+
// what held up (artifact publish|list|show|adopt|verify).
|
|
7
|
+
// lessons = scoped one-liners auto-injected into later spawn briefs
|
|
8
|
+
// (lesson post|list), so a lesson learned once is paid forward without
|
|
9
|
+
// anyone re-deriving it.
|
|
10
|
+
// Zero-dependency Node 18+ ESM. Side-effect-free at top level. Storage:
|
|
11
|
+
// artifacts/<id>.json {id, from, at, path, summary?, deps[], adoptedBy[], verifiedBy[]}
|
|
12
|
+
// lessons/<id>.json {id, from, scope, text, at}
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { fail, readJson, writeJson, listJson, newId } from "./store.js";
|
|
16
|
+
|
|
17
|
+
// Artifact ids minted via newId("art"): art-<YYMMDD>-<HHMMSS>-<8hex>.
|
|
18
|
+
export const ARTIFACT_ID_RE = /\bart-[0-9]{6}-[0-9]{6}-[0-9a-f]{8}\b/g;
|
|
19
|
+
|
|
20
|
+
export function artifactPath(d, id) {
|
|
21
|
+
return path.join(d.artifacts, `${id}.json`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function readArtifactById(d, id) {
|
|
25
|
+
if (!id) return null;
|
|
26
|
+
try {
|
|
27
|
+
const a = readJson(artifactPath(d, id));
|
|
28
|
+
return a && a.id === id ? a : null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Newest first (board reads answer "what exists lately", not history).
|
|
35
|
+
export function listArtifacts(d, { limit } = {}) {
|
|
36
|
+
const items = listJson(d.artifacts)
|
|
37
|
+
.map((e) => e && e.data)
|
|
38
|
+
.filter((a) => a && a.id && a.path);
|
|
39
|
+
items.sort((a, b) => String(b.at).localeCompare(String(a.at)) || String(b.id).localeCompare(String(a.id)));
|
|
40
|
+
return typeof limit === "number" ? items.slice(0, Math.max(0, limit)) : items;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function cleanArtifactId(raw, flag) {
|
|
44
|
+
const f = flag || "--id";
|
|
45
|
+
if (raw === undefined || raw === null || String(raw).trim() === "") fail(`missing ${f} <artifact-id>`);
|
|
46
|
+
const c = String(raw).trim().toLowerCase();
|
|
47
|
+
if (!/^art-[0-9]{6}-[0-9]{6}-[0-9a-f]{8}$/.test(c)) fail(`invalid ${f} "${raw}" (want an art-<id> from artifact list)`);
|
|
48
|
+
return c;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Lesson scopes: freeform short names like groups; missing reads as
|
|
52
|
+
// "global" so one-off lessons still reach every later brief.
|
|
53
|
+
export function cleanLessonScope(raw, flag) {
|
|
54
|
+
const f = flag || "--scope";
|
|
55
|
+
if (raw === undefined || raw === null || String(raw).trim() === "") return "global";
|
|
56
|
+
const c = String(raw).trim().toLowerCase().replace(/[^a-z0-9_.-]/g, "-").slice(0, 60);
|
|
57
|
+
if (!c) fail(`invalid ${f} "${raw}"`);
|
|
58
|
+
return c;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function parseArtifactDeps(raw) {
|
|
62
|
+
if (raw === undefined || raw === null || String(raw).trim() === "") return [];
|
|
63
|
+
return String(raw).split(",").map((s) => cleanArtifactId(s, "--deps")).filter((x, i, a) => a.indexOf(x) === i);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function publishArtifact(d, { from, ref, summary, deps, at }) {
|
|
67
|
+
const cleanRef = String(ref === undefined || ref === null ? "" : ref).trim();
|
|
68
|
+
if (!cleanRef) fail('missing --path <path-or-url> (where the artifact lives; reference, never inline secrets)');
|
|
69
|
+
const doc = {
|
|
70
|
+
id: newId("art"),
|
|
71
|
+
from,
|
|
72
|
+
at,
|
|
73
|
+
path: cleanRef.slice(0, 500),
|
|
74
|
+
summary: String(summary || "").trim().slice(0, 500) || undefined,
|
|
75
|
+
deps: Array.isArray(deps) ? deps : [],
|
|
76
|
+
adoptedBy: [],
|
|
77
|
+
verifiedBy: [],
|
|
78
|
+
};
|
|
79
|
+
for (const dep of doc.deps) {
|
|
80
|
+
if (!readArtifactById(d, dep)) fail(`dep ${dep} not found on this board (publish the dependency first, or drop it)`);
|
|
81
|
+
}
|
|
82
|
+
writeJson(artifactPath(d, doc.id), doc);
|
|
83
|
+
return doc;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function adoptArtifact(d, { id, from, note, at }) {
|
|
87
|
+
const a = readArtifactById(d, id);
|
|
88
|
+
if (!a) fail(`unknown artifact ${id} (artifact list to see what's on the board)`);
|
|
89
|
+
if (!a.adoptedBy.some((e) => e.by === from)) {
|
|
90
|
+
a.adoptedBy.push({ by: from, at, note: String(note || "").trim().slice(0, 200) || undefined });
|
|
91
|
+
writeJson(artifactPath(d, id), a);
|
|
92
|
+
}
|
|
93
|
+
return a;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function verifyArtifact(d, { id, from, note, at }) {
|
|
97
|
+
const a = readArtifactById(d, id);
|
|
98
|
+
if (!a) fail(`unknown artifact ${id} (artifact list to see what's on the board)`);
|
|
99
|
+
if (!a.verifiedBy.some((e) => e.by === from)) {
|
|
100
|
+
a.verifiedBy.push({ by: from, at, note: String(note || "").trim().slice(0, 200) || undefined });
|
|
101
|
+
writeJson(artifactPath(d, id), a);
|
|
102
|
+
}
|
|
103
|
+
return a;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function postLesson(d, { from, scope, text, at }) {
|
|
107
|
+
const t = String(text === undefined || text === null ? "" : text).trim();
|
|
108
|
+
if (!t) fail('missing --text "..." (one or two sentences: what happened + what to do differently)');
|
|
109
|
+
const doc = { id: newId("les"), from, scope: cleanLessonScope(scope), text: t.slice(0, 800), at };
|
|
110
|
+
writeJson(path.join(d.lessons, `${doc.id}.json`), doc);
|
|
111
|
+
return doc;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Oldest first (a lesson list is a history read, unlike artifacts).
|
|
115
|
+
export function listLessons(d, { scope } = {}) {
|
|
116
|
+
let items = listJson(d.lessons)
|
|
117
|
+
.map((e) => e && e.data)
|
|
118
|
+
.filter((l) => l && l.id && l.text);
|
|
119
|
+
items.sort((a, b) => String(a.at).localeCompare(String(b.at)) || String(a.id).localeCompare(String(b.id)));
|
|
120
|
+
if (scope !== undefined) items = items.filter((l) => l.scope === cleanLessonScope(scope));
|
|
121
|
+
return items;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Brief injection selection: lessons whose scope matches one of this
|
|
125
|
+
// spawn's groups (or global), newest last-N reversed so the freshest
|
|
126
|
+
// lessons land first in the brief. Cap keeps prompts bounded.
|
|
127
|
+
export function selectLessons(d, { scopes = [], limit = 8 } = {}) {
|
|
128
|
+
const scopeSet = new Set(["global", ...(scopes || []).map(String)]);
|
|
129
|
+
const picked = listLessons(d).filter((l) => scopeSet.has(l.scope));
|
|
130
|
+
return picked.slice(-Math.max(0, limit)).reverse();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Pure renderer: the Workbench: block for spawn briefs. Returns bullet
|
|
134
|
+
// lines (no header); caller joins under a header. Empty board -> [].
|
|
135
|
+
export function renderWorkbenchBlock({ lessons, artifacts, me }) {
|
|
136
|
+
const les = (lessons || []).slice(0, 8);
|
|
137
|
+
const arts = (artifacts || []).slice(0, 6);
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const l of les) out.push(`- lesson [${l.scope}] ${l.text} (from ${l.from})`);
|
|
140
|
+
for (const a of arts) {
|
|
141
|
+
const state = [];
|
|
142
|
+
if (a.adoptedBy && a.adoptedBy.length) state.push(`adopted x${a.adoptedBy.length}`);
|
|
143
|
+
if (a.verifiedBy && a.verifiedBy.length) state.push("verified");
|
|
144
|
+
out.push(`- artifact ${a.id} ${a.path}${a.summary ? ` — ${a.summary}` : ""}${state.length ? ` (${state.join(", ")})` : ""}`);
|
|
145
|
+
}
|
|
146
|
+
if (out.length === 0) return out;
|
|
147
|
+
out.push(`(verify before reuse; publish yours: artifact publish --path <p> [--deps <id,id>] / lesson post --scope <s> --text "..."; reuse a piece: artifact adopt|verify --id <id> --from ${String(me || "you")})`);
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Gather metrics (pure given a lookup fn): scan transcript messages for
|
|
152
|
+
// artifact references (the m.artifact field + art- ids in bodies), then
|
|
153
|
+
// score feed-forward: an edge is a message whose sender is NOT the
|
|
154
|
+
// artifact's producer — someone downstream actually consumed upstream
|
|
155
|
+
// output on the board itself.
|
|
156
|
+
export function workbenchMetrics(items, lookup) {
|
|
157
|
+
const seenEdges = new Set();
|
|
158
|
+
const refs = new Map();
|
|
159
|
+
const producers = new Set();
|
|
160
|
+
let feedForward = 0;
|
|
161
|
+
let adopted = 0;
|
|
162
|
+
let verified = 0;
|
|
163
|
+
for (const m of items || []) {
|
|
164
|
+
if (!m) continue;
|
|
165
|
+
const text = `${m.artifact || ""} ${m.body || ""}`;
|
|
166
|
+
const ids = new Set(String(text).match(ARTIFACT_ID_RE) || []);
|
|
167
|
+
for (const id of ids) {
|
|
168
|
+
const a = lookup(id);
|
|
169
|
+
if (!a) continue;
|
|
170
|
+
// Adoption/verification are per-artifact facts; count each artifact
|
|
171
|
+
// once no matter how many transcript messages cite it.
|
|
172
|
+
if (!refs.has(id)) {
|
|
173
|
+
refs.set(id, a);
|
|
174
|
+
producers.add(a.from);
|
|
175
|
+
if (a.adoptedBy && a.adoptedBy.length) adopted++;
|
|
176
|
+
if (a.verifiedBy && a.verifiedBy.length) verified++;
|
|
177
|
+
}
|
|
178
|
+
if (m.from && m.from !== a.from) {
|
|
179
|
+
const key = `${m.id}|${id}`;
|
|
180
|
+
if (!seenEdges.has(key)) {
|
|
181
|
+
seenEdges.add(key);
|
|
182
|
+
feedForward++;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { artifactRefs: refs.size, producers: producers.size, feedForward, adopted, verified };
|
|
188
|
+
}
|
package/docs/SPLIT.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Status: landed. `bin/crewbus.js` is a dispatcher that intentionally
|
|
4
4
|
retains the `cmd*` wrappers, `USAGE`, `main()`, and the opencode
|
|
5
|
-
tool/plugin embeds; domain logic lives in the
|
|
5
|
+
tool/plugin embeds; domain logic lives in the 13 lib modules
|
|
6
6
|
(`bin/lib/` holds channels, export, groups, identity, launch, mail,
|
|
7
|
-
relay, spawn, store, sync, tokenfile, web; import block,
|
|
8
|
-
`bin/crewbus.js` lines 44–
|
|
7
|
+
relay, spawn, store, sync, tokenfile, web, workbench; import block,
|
|
8
|
+
`bin/crewbus.js` lines 44–56). No behavior change is intended, with one deliberate exception recorded in CHANGELOG (parseRecipients full-version canonicalization).
|
|
9
9
|
|
|
10
10
|
## Module map
|
|
11
11
|
|
|
@@ -23,9 +23,10 @@ relay, spawn, store, sync, tokenfile, web; import block,
|
|
|
23
23
|
| `bin/lib/channels.js` | Shared channels + locks: log IO, per-reader cursors, digest/summarize, group mirrors, advisory locks, channel text-merge | `appendChannelPost`, `readChannelPosts`, `tailChannelPosts`, `parseChannelText`, `mergeChannelText`, `mirrorToGroupChannels`, `acquireLockDoc`, `releaseLockDoc` |
|
|
24
24
|
| `bin/lib/web.js` | Dashboard + API: snapshots, HTML render, ack/kill/launch handlers, `cmdWeb`; control-plane additions: `handleApiLaunch`, `POST /api/launch`, `GET /api/harnesses\|routes\|holds\|quotas`, Holds/Quotas/AppRoot sections | `boardSnapshot`, `fleetSnapshot`, `channelsSnapshot`, `resultsSnapshot`, `auditSnapshot`, `renderBoardHtml`, `handleApiAck`, `handleApiKill`, `handleApiLaunch`, `cmdWeb` |
|
|
25
25
|
| `bin/lib/tokenfile.js` | Token-file convention for long runs: save/re-read agent tokens across compaction/restart amnesia (0600 best-effort); standalone, no local imports (cycle-free) | `tokenFilePath`, `saveTokenFile`, `loadTokenFile` |
|
|
26
|
+
| `bin/lib/workbench.js` | Artifacts + lessons (compound-memory layer): artifact objects with deps/adoption/verification edges, scoped lessons, spawn-brief Workbench block, gather metrics; pure helpers, monolith keeps `cmdArtifact`/`cmdLesson` | `publishArtifact`, `adoptArtifact`, `verifyArtifact`, `readArtifactById`, `listArtifacts`, `listLessons`, `postLesson`, `selectLessons`, `renderWorkbenchBlock`, `workbenchMetrics`, `cleanArtifactId`, `cleanLessonScope`, `parseArtifactDeps`, `ARTIFACT_ID_RE` |
|
|
26
27
|
|
|
27
28
|
Full export lists: see the import block at the top of `bin/crewbus.js`
|
|
28
|
-
(lines 44–
|
|
29
|
+
(lines 44–56). Entry-point `cmd*` functions (e.g. `cmdSend`, `cmdSync`,
|
|
29
30
|
`cmdServe`) stay in the monolith; lib modules carry the computation helpers
|
|
30
31
|
those verbs call.
|
|
31
32
|
|
package/docs/VERSION_SKEW.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Version skew (mixed-relay operation)
|
|
2
2
|
|
|
3
|
-
How crewbus versions interoperate. Evidence: `package.json:2` (`10.0.
|
|
3
|
+
How crewbus versions interoperate. Evidence: `package.json:2` (`10.0.9`),
|
|
4
4
|
`CHANGELOG.md` (10.0.0 2026-10-08; 7.0.0 2026-10-05; 6.4.0–6.0.0; 4.1.0/4.0.0 baseline).
|
|
5
5
|
Capabilities: `RELAY_CAPS` + `launch` per `packages/contracts/board-caps.json:6-8`.
|
|
6
6
|
Cell behavior is the NEW side's verified behavior (`bin/lib/sync.js` refs);
|