@mmerterden/multi-agent-pipeline 20.21.0 → 20.22.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/CHANGELOG.md +33 -0
- package/docs/adr/0017-change-impact-from-the-graph.md +69 -0
- package/docs/adr/README.md +1 -0
- package/docs/ecosystem.md +6 -5
- package/docs/facts.json +4 -3
- package/install/catalog-history.json +1 -1
- package/install/templates/copilot-instructions.md +1 -0
- package/manifest.json +44 -40
- package/package.json +1 -1
- package/pipeline/commands/multi-agent/review/SKILL.md +2 -1
- package/pipeline/commands/multi-agent/setup/SKILL.md +6 -15
- package/pipeline/multi-agent-refs/_dev-context.md +15 -0
- package/pipeline/multi-agent-refs/analysis/evidence.md +5 -3
- package/pipeline/multi-agent-refs/analysis/locked.md +1 -1
- package/pipeline/multi-agent-refs/cross-cli-contract.md +1 -0
- package/pipeline/multi-agent-refs/features/code-graph.md +27 -0
- package/pipeline/multi-agent-refs/features/product-context.md +238 -0
- package/pipeline/multi-agent-refs/knowledge.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +7 -12
- package/pipeline/multi-agent-refs/phases/phase-2-dev.md +1 -1
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +7 -6
- package/pipeline/multi-agent-refs/platform-parity.md +23 -9
- package/pipeline/multi-agent-refs/setup/token-save-flow.md +24 -0
- package/pipeline/schemas/agent-state.schema.json +31 -0
- package/pipeline/schemas/analysis-spec.schema.json +14 -0
- package/pipeline/schemas/code-graph.schema.json +12 -1
- package/pipeline/schemas/diff-risk.schema.json +2 -1
- package/pipeline/schemas/prefs.schema.json +58 -0
- package/pipeline/scripts/_code-graph.mjs +76 -3
- package/pipeline/scripts/_diff-impact.mjs +312 -0
- package/pipeline/scripts/capture-flush.sh +58 -3
- package/pipeline/scripts/diff-risk-score.mjs +80 -9
- package/pipeline/scripts/graph-affected.mjs +167 -36
- package/pipeline/scripts/graph-query.mjs +16 -4
- package/pipeline/scripts/product-context.mjs +539 -0
- package/pipeline/scripts/smoke-cross-cli-behavior.sh +39 -1
- package/pipeline/scripts/validate-code-graph.mjs +2 -1
- package/pipeline/scripts/validate-diff-risk.mjs +1 -0
- package/pipeline/skills/.skill-manifest.json +3 -3
- package/pipeline/skills/shared/core/multi-agent-review/SKILL.md +5 -1
- package/pipeline/skills/shared/core/multi-agent-setup/SKILL.md +8 -6
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* product-context.mjs - which other repositories a run reads, and what it
|
|
4
|
+
* learned from them.
|
|
5
|
+
*
|
|
6
|
+
* A product is made of several repositories (iOS app, Android app, web client,
|
|
7
|
+
* backend services, a shared resources repo). A run develops in some of them;
|
|
8
|
+
* planning reads all the others, read-only, at their latest integration branch,
|
|
9
|
+
* through the toolkit's repo_* tools. This script owns the deterministic half:
|
|
10
|
+
*
|
|
11
|
+
* refs the reference set: product repos minus the repos this run develops.
|
|
12
|
+
* Symmetric by construction - whichever stack is primary, the rest
|
|
13
|
+
* are references. Exit 2 when nothing is mapped.
|
|
14
|
+
* suggest candidate repos for a product that is not mapped yet, by name core
|
|
15
|
+
* from a repo-cache listing. Never guesses a stack.
|
|
16
|
+
* needs-mapping whether the project has never answered the mapping question.
|
|
17
|
+
* learn write a confirmed product map into the preferences file.
|
|
18
|
+
* decline remember that the project is not part of a product.
|
|
19
|
+
* record normalise a repo_find_keys result into state.productContext and
|
|
20
|
+
* append each finding to the related repo's own knowledge directory,
|
|
21
|
+
* keyed by the sha it was read at.
|
|
22
|
+
* recall findings already recorded for a repo at a given sha.
|
|
23
|
+
*
|
|
24
|
+
* Knowledge lands in $HOME/.claude/knowledge/<repo-name>/product-context.jsonl,
|
|
25
|
+
* the same directory that repo's own runs read, so what an iOS run learns about
|
|
26
|
+
* Android is there for the next Android run, and the other way round. A finding
|
|
27
|
+
* is reused only while the sha matches: a newer commit on the branch makes
|
|
28
|
+
* every older finding invisible rather than wrong.
|
|
29
|
+
*
|
|
30
|
+
* Usage:
|
|
31
|
+
* product-context.mjs refs --project <key> [--developed <remote>]... [--prefs <file>]
|
|
32
|
+
* product-context.mjs suggest --primary <repo-name> --repos <repo-cache.json>
|
|
33
|
+
* product-context.mjs needs-mapping --project <key> [--developed <remote>]... [--prefs <file>] exit 0 ask, 3 already answered
|
|
34
|
+
* product-context.mjs learn --project <key> --product <name> --repos <repos.json> [--prefs <file>]
|
|
35
|
+
* product-context.mjs decline --project <key> [--prefs <file>]
|
|
36
|
+
* product-context.mjs record --in <find-keys.json> [--refs <refs.json>] [--task <id>] [--knowledge <dir>]
|
|
37
|
+
* product-context.mjs recall --remote <url> --sha <sha> --keys <k1,k2> [--knowledge <dir>]
|
|
38
|
+
*
|
|
39
|
+
* Exit codes: 0 ok, 1 bad input, 2 nothing mapped (refs), 3 already answered (needs-mapping).
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { execFileSync } from "node:child_process";
|
|
43
|
+
import {
|
|
44
|
+
appendFileSync,
|
|
45
|
+
chmodSync,
|
|
46
|
+
existsSync,
|
|
47
|
+
mkdirSync,
|
|
48
|
+
readFileSync,
|
|
49
|
+
renameSync,
|
|
50
|
+
statSync,
|
|
51
|
+
writeFileSync,
|
|
52
|
+
} from "node:fs";
|
|
53
|
+
import { homedir } from "node:os";
|
|
54
|
+
import { dirname, join } from "node:path";
|
|
55
|
+
import { fileURLToPath } from "node:url";
|
|
56
|
+
|
|
57
|
+
export const STACKS = ["ios", "android", "web", "backend", "resources"];
|
|
58
|
+
const AUTH_SCHEMES = ["basic", "bearer"];
|
|
59
|
+
const KNOWLEDGE_FILE = "product-context.jsonl";
|
|
60
|
+
|
|
61
|
+
export function canonicalRemote(remote) {
|
|
62
|
+
let host;
|
|
63
|
+
let path = String(remote ?? "").trim();
|
|
64
|
+
const scp = /^[^@/]+@([^:/]+):(.+)$/.exec(path);
|
|
65
|
+
if (scp) {
|
|
66
|
+
host = scp[1];
|
|
67
|
+
path = scp[2];
|
|
68
|
+
} else {
|
|
69
|
+
try {
|
|
70
|
+
const u = new URL(path);
|
|
71
|
+
host = u.hostname;
|
|
72
|
+
path = u.pathname;
|
|
73
|
+
} catch {
|
|
74
|
+
return path.toLowerCase().replace(/\.git\/?$/, "");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const segments = path
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.replace(/\.git\/?$/, "")
|
|
80
|
+
.split("/")
|
|
81
|
+
.filter(Boolean);
|
|
82
|
+
if (segments[0] === "scm") segments.shift();
|
|
83
|
+
return [host.toLowerCase(), ...segments].join("/");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The knowledge directory name for a remote: its repository name as the remote
|
|
88
|
+
* spells it. It can differ from a local checkout's folder name; recall uses the
|
|
89
|
+
* same function, so writer and reader always agree. Never `.` or `..`.
|
|
90
|
+
*/
|
|
91
|
+
export function repoSlug(remote) {
|
|
92
|
+
const parts = canonicalRemote(remote).split("/");
|
|
93
|
+
const slug = parts[parts.length - 1].replace(/[^a-z0-9._-]/g, "_");
|
|
94
|
+
return /^\.*$/.test(slug) ? `_${slug.length}` : slug;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function validRemote(remote) {
|
|
98
|
+
const r = String(remote ?? "");
|
|
99
|
+
if (!r || r.startsWith("-") || /\s/.test(r) || r.includes("::")) return false;
|
|
100
|
+
if (/^https:\/\//i.test(r)) {
|
|
101
|
+
if (/\\|%5c/i.test(r)) return false;
|
|
102
|
+
try {
|
|
103
|
+
const u = new URL(r);
|
|
104
|
+
return !u.username && !u.password;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (/^file:\/\//i.test(r)) return process.env.MCP_TOOLKIT_REPO_ALLOW_FILE === "1";
|
|
110
|
+
return /^ssh:\/\//i.test(r) || /^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+:[^/].*/.test(r);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function reference(repo, source) {
|
|
114
|
+
const out = { stack: repo.stack || "unknown", remote: repo.remote };
|
|
115
|
+
if (repo.branch) out.branch = repo.branch;
|
|
116
|
+
if (repo.credential) out.credential = repo.credential;
|
|
117
|
+
if (repo.authScheme) out.auth_scheme = repo.authScheme;
|
|
118
|
+
if (repo.username) out.username = repo.username;
|
|
119
|
+
if (source) out.source = source;
|
|
120
|
+
const { stack: _stack, source: _source, ...spec } = out;
|
|
121
|
+
out.spec = spec;
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function defaultOriginOf(path) {
|
|
126
|
+
try {
|
|
127
|
+
return (
|
|
128
|
+
execFileSync("git", ["-C", path, "remote", "get-url", "origin"], {
|
|
129
|
+
encoding: "utf8",
|
|
130
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
131
|
+
}).trim() || null
|
|
132
|
+
);
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function productFor(prefs, projectKey, developed) {
|
|
139
|
+
const products = prefs?.global?.products || {};
|
|
140
|
+
const named = prefs?.projects?.[projectKey]?.product;
|
|
141
|
+
if (named && products[named]) return named;
|
|
142
|
+
for (const [name, p] of Object.entries(products)) {
|
|
143
|
+
const remotes = new Set((p.repos || []).map((r) => canonicalRemote(r.remote)));
|
|
144
|
+
if (developed.some((d) => remotes.has(d))) return name;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Product repos minus the developed ones. Without a product, the legacy
|
|
151
|
+
* per-project keys are read so an existing setup keeps a reference set: each
|
|
152
|
+
* counterpartRoots path through its origin remote, each webRepos entry only
|
|
153
|
+
* when it is already a remote URL. Anything that cannot become a remote is
|
|
154
|
+
* returned in unresolved[] rather than dropped.
|
|
155
|
+
*/
|
|
156
|
+
export function referenceSet(
|
|
157
|
+
prefs,
|
|
158
|
+
projectKey,
|
|
159
|
+
developedRemotes = [],
|
|
160
|
+
{ originOf = defaultOriginOf } = {},
|
|
161
|
+
) {
|
|
162
|
+
const developed = developedRemotes.map(canonicalRemote);
|
|
163
|
+
const isDeveloped = (remote) => developed.includes(canonicalRemote(remote));
|
|
164
|
+
const product = productFor(prefs, projectKey, developed);
|
|
165
|
+
if (product) {
|
|
166
|
+
const repos = prefs.global.products[product].repos || [];
|
|
167
|
+
return {
|
|
168
|
+
product,
|
|
169
|
+
references: repos.filter((r) => !isDeveloped(r.remote)).map((r) => reference(r)),
|
|
170
|
+
unresolved: [],
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const project = prefs?.projects?.[projectKey] || {};
|
|
174
|
+
const references = [];
|
|
175
|
+
const unresolved = [];
|
|
176
|
+
for (const path of project.counterpartRoots || []) {
|
|
177
|
+
const remote = originOf(path);
|
|
178
|
+
if (remote && validRemote(remote)) {
|
|
179
|
+
if (!isDeveloped(remote))
|
|
180
|
+
references.push(reference({ stack: "unknown", remote }, "counterpartRoots"));
|
|
181
|
+
} else unresolved.push(`counterpartRoots:${path}`);
|
|
182
|
+
}
|
|
183
|
+
for (const entry of project.webRepos || project.frontendRepos || []) {
|
|
184
|
+
if (validRemote(entry)) {
|
|
185
|
+
if (!isDeveloped(entry))
|
|
186
|
+
references.push(reference({ stack: "web", remote: entry }, "webRepos"));
|
|
187
|
+
} else unresolved.push(`webRepos:${entry}`);
|
|
188
|
+
}
|
|
189
|
+
return { product: null, references, unresolved };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const NON_CORE = new Set([
|
|
193
|
+
"ios",
|
|
194
|
+
"android",
|
|
195
|
+
"web",
|
|
196
|
+
"backend",
|
|
197
|
+
"api",
|
|
198
|
+
"app",
|
|
199
|
+
"apps",
|
|
200
|
+
"mobile",
|
|
201
|
+
"new",
|
|
202
|
+
"next",
|
|
203
|
+
"legacy",
|
|
204
|
+
"v2",
|
|
205
|
+
"v3",
|
|
206
|
+
]);
|
|
207
|
+
|
|
208
|
+
const nameCore = (name) =>
|
|
209
|
+
String(name)
|
|
210
|
+
.toLowerCase()
|
|
211
|
+
.split(/[-_.]+/)
|
|
212
|
+
.filter((t) => t && !NON_CORE.has(t));
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Repos whose name core starts with the primary repo's name core. The core is
|
|
216
|
+
* the name without platform and version words, so `acme-shop-ios-new` and
|
|
217
|
+
* `acme-shop-android` share `acme-shop`, while a repo that merely has Android
|
|
218
|
+
* markers shares nothing. A primary whose name is only such words matches
|
|
219
|
+
* nothing rather than everything.
|
|
220
|
+
*/
|
|
221
|
+
export function suggestCandidates(primaryName, repos) {
|
|
222
|
+
const core = nameCore(primaryName);
|
|
223
|
+
if (!core.length) return [];
|
|
224
|
+
return (repos || [])
|
|
225
|
+
.filter((r) => {
|
|
226
|
+
const name = String(r.name || r.fullName || "")
|
|
227
|
+
.split("/")
|
|
228
|
+
.pop();
|
|
229
|
+
if (name.toLowerCase() === String(primaryName).toLowerCase()) return false;
|
|
230
|
+
const t = nameCore(name);
|
|
231
|
+
return core.every((s, i) => t[i] === s);
|
|
232
|
+
})
|
|
233
|
+
.map((r) => ({
|
|
234
|
+
fullName: r.fullName || r.name,
|
|
235
|
+
remote: r.cloneUrl || r.remote || null,
|
|
236
|
+
provider: r.provider || null,
|
|
237
|
+
stack: "unknown",
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function httpsHost(remote) {
|
|
242
|
+
if (!/^https:\/\//i.test(String(remote))) return null;
|
|
243
|
+
try {
|
|
244
|
+
return new URL(remote).hostname.toLowerCase();
|
|
245
|
+
} catch {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Write a confirmed product. A repository may name a credential only when that
|
|
252
|
+
* key is already bound to the repository's https host in
|
|
253
|
+
* `prefs.global.credentialHosts`, which `/multi-agent:setup` writes with the
|
|
254
|
+
* person present. The product map never creates a binding: the repo list is
|
|
255
|
+
* assembled from picker output and model-written files, and a binding made
|
|
256
|
+
* there would let any text that reached the planner send a token anywhere.
|
|
257
|
+
*/
|
|
258
|
+
const MAX_PRODUCT_REPOS = 20;
|
|
259
|
+
const CREDENTIAL_FIELDS = ["credential", "authScheme", "username"];
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Why a repo entry may not carry its credential, or null when it may: the
|
|
263
|
+
* remote must be https and its host bound to the key in
|
|
264
|
+
* `prefs.global.credentialHosts`, which only setup writes. Checked on every
|
|
265
|
+
* entry a merge produces, so a credential kept from an earlier spelling never
|
|
266
|
+
* lands on a remote it was not bound for.
|
|
267
|
+
*/
|
|
268
|
+
function credentialProblem(prefs, r) {
|
|
269
|
+
if (!r.credential) return null;
|
|
270
|
+
const host = httpsHost(r.remote);
|
|
271
|
+
const hosts = (prefs?.global?.credentialHosts?.[r.credential] || []).map((h) =>
|
|
272
|
+
String(h).toLowerCase(),
|
|
273
|
+
);
|
|
274
|
+
if (host && hosts.includes(host)) return null;
|
|
275
|
+
return `credential ${JSON.stringify(r.credential)} is not bound to ${host || r.remote}; bind it in prefs.global.credentialHosts with /multi-agent:setup hosts first`;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export function learnProduct(prefs, projectKey, productName, repos) {
|
|
279
|
+
if (!productName || !/^[A-Za-z0-9._-]{1,64}$/.test(productName))
|
|
280
|
+
throw new Error("product name must be 1-64 letters, digits, . _ -");
|
|
281
|
+
const clean = (repos || []).map((r) => {
|
|
282
|
+
if (!STACKS.includes(r.stack))
|
|
283
|
+
throw new Error(`stack ${JSON.stringify(r.stack)} is not one of ${STACKS.join(", ")}`);
|
|
284
|
+
if (!validRemote(r.remote))
|
|
285
|
+
throw new Error(
|
|
286
|
+
`remote ${JSON.stringify(r.remote)} must be https://, ssh:// or user@host:path, without credentials (file:// only with MCP_TOOLKIT_REPO_ALLOW_FILE=1)`,
|
|
287
|
+
);
|
|
288
|
+
if (r.authScheme && !AUTH_SCHEMES.includes(r.authScheme))
|
|
289
|
+
throw new Error(`authScheme must be one of ${AUTH_SCHEMES.join(", ")}`);
|
|
290
|
+
const problem = credentialProblem(prefs, r);
|
|
291
|
+
if (problem) throw new Error(problem);
|
|
292
|
+
const out = { stack: r.stack, remote: r.remote };
|
|
293
|
+
for (const k of ["branch", "credential", "authScheme", "username"]) if (r[k]) out[k] = r[k];
|
|
294
|
+
return out;
|
|
295
|
+
});
|
|
296
|
+
if (!clean.length) throw new Error("a product needs at least one repo");
|
|
297
|
+
const next = structuredClone(prefs || {});
|
|
298
|
+
next.global = next.global || {};
|
|
299
|
+
const merged = new Map(
|
|
300
|
+
(next.global.products?.[productName]?.repos || []).map((r) => [canonicalRemote(r.remote), r]),
|
|
301
|
+
);
|
|
302
|
+
for (const r of clean) {
|
|
303
|
+
const key = canonicalRemote(r.remote);
|
|
304
|
+
const entry = { ...(merged.get(key) || {}), ...r };
|
|
305
|
+
if (credentialProblem(prefs, entry)) for (const k of CREDENTIAL_FIELDS) delete entry[k];
|
|
306
|
+
merged.set(key, entry);
|
|
307
|
+
}
|
|
308
|
+
if (merged.size > MAX_PRODUCT_REPOS)
|
|
309
|
+
throw new Error(
|
|
310
|
+
`a product holds at most ${MAX_PRODUCT_REPOS} repos (one repo_find_keys call reads them all); ${productName} would have ${merged.size}`,
|
|
311
|
+
);
|
|
312
|
+
next.global.products = {
|
|
313
|
+
...(next.global.products || {}),
|
|
314
|
+
[productName]: { repos: [...merged.values()] },
|
|
315
|
+
};
|
|
316
|
+
next.projects = next.projects || {};
|
|
317
|
+
next.projects[projectKey] = { ...(next.projects[projectKey] || {}), product: productName };
|
|
318
|
+
return next;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/** A project is asked once: until it names a product or declines, it needs mapping. */
|
|
322
|
+
export function needsMapping(prefs, projectKey, developedRemotes = []) {
|
|
323
|
+
const named = prefs?.projects?.[projectKey]?.product;
|
|
324
|
+
if (named === "") return false;
|
|
325
|
+
if (typeof named === "string" && prefs?.global?.products?.[named]) return false;
|
|
326
|
+
return productFor(prefs, projectKey, developedRemotes.map(canonicalRemote)) === null;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Remember that a project is not part of a product, so the offer is not repeated. */
|
|
330
|
+
export function declineProduct(prefs, projectKey) {
|
|
331
|
+
const next = structuredClone(prefs || {});
|
|
332
|
+
next.projects = next.projects || {};
|
|
333
|
+
next.projects[projectKey] = { ...(next.projects[projectKey] || {}), product: "" };
|
|
334
|
+
return next;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const STATUS = {
|
|
338
|
+
implemented: "implemented",
|
|
339
|
+
not_found_at_sha: "not-yet-implemented",
|
|
340
|
+
diverges: "diverges",
|
|
341
|
+
error: "error",
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
export function recordFindings(
|
|
345
|
+
findKeys,
|
|
346
|
+
{
|
|
347
|
+
taskId = null,
|
|
348
|
+
knowledgeRoot = defaultKnowledgeRoot(),
|
|
349
|
+
now = new Date().toISOString(),
|
|
350
|
+
refs = [],
|
|
351
|
+
} = {},
|
|
352
|
+
) {
|
|
353
|
+
const stackOf = new Map(refs.map((r) => [canonicalRemote(r.remote), r.stack]));
|
|
354
|
+
const productContext = [];
|
|
355
|
+
for (const repo of findKeys?.repos || []) {
|
|
356
|
+
const slug = repoSlug(repo.remote);
|
|
357
|
+
const stack = stackOf.get(canonicalRemote(repo.remote));
|
|
358
|
+
const base = { remote: repo.remote, slug, ...(stack ? { stack } : {}) };
|
|
359
|
+
if (repo.error) {
|
|
360
|
+
productContext.push({ ...base, error: repo.error });
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
const keys = (repo.keys || []).map((k) => ({
|
|
364
|
+
key: k.key,
|
|
365
|
+
status: STATUS[k.status] || "error",
|
|
366
|
+
...(k.note ? { note: String(k.note) } : {}),
|
|
367
|
+
hits: (k.hits || []).map((h) => ({ path: h.path, line: h.line })),
|
|
368
|
+
}));
|
|
369
|
+
productContext.push({
|
|
370
|
+
...base,
|
|
371
|
+
branch: repo.branch,
|
|
372
|
+
sha: repo.sha,
|
|
373
|
+
stale: Boolean(repo.stale),
|
|
374
|
+
keys,
|
|
375
|
+
});
|
|
376
|
+
if (repo.stale || !repo.sha) continue;
|
|
377
|
+
const dir = join(knowledgeRoot, slug);
|
|
378
|
+
mkdirSync(dir, { recursive: true });
|
|
379
|
+
const lines = keys
|
|
380
|
+
.filter((k) => k.status !== "error")
|
|
381
|
+
.map((k) =>
|
|
382
|
+
JSON.stringify({
|
|
383
|
+
remote: canonicalRemote(repo.remote),
|
|
384
|
+
branch: repo.branch,
|
|
385
|
+
sha: repo.sha,
|
|
386
|
+
key: k.key,
|
|
387
|
+
status: k.status === "diverges" ? "implemented" : k.status,
|
|
388
|
+
...(k.note ? { note: k.note } : {}),
|
|
389
|
+
hits: k.hits,
|
|
390
|
+
task: taskId,
|
|
391
|
+
capturedAt: now,
|
|
392
|
+
}),
|
|
393
|
+
);
|
|
394
|
+
if (lines.length) appendFileSync(join(dir, KNOWLEDGE_FILE), `${lines.join("\n")}\n`);
|
|
395
|
+
}
|
|
396
|
+
return { productContext };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function recall({ knowledgeRoot = defaultKnowledgeRoot(), remote, sha, keys = [] }) {
|
|
400
|
+
const file = join(knowledgeRoot, repoSlug(remote), KNOWLEDGE_FILE);
|
|
401
|
+
const want = canonicalRemote(remote);
|
|
402
|
+
const latest = new Map();
|
|
403
|
+
if (existsSync(file)) {
|
|
404
|
+
for (const line of readFileSync(file, "utf8").split("\n")) {
|
|
405
|
+
if (!line) continue;
|
|
406
|
+
let row;
|
|
407
|
+
try {
|
|
408
|
+
row = JSON.parse(line);
|
|
409
|
+
} catch {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (row.remote === want && row.sha === sha && keys.includes(row.key))
|
|
413
|
+
latest.set(row.key, row);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
found: keys.filter((k) => latest.has(k)).map((k) => latest.get(k)),
|
|
418
|
+
missing: keys.filter((k) => !latest.has(k)),
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function defaultKnowledgeRoot() {
|
|
423
|
+
return process.env.MULTI_AGENT_KNOWLEDGE_ROOT || join(homedir(), ".claude", "knowledge");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function defaultPrefsPath() {
|
|
427
|
+
return (
|
|
428
|
+
process.env.MULTI_AGENT_PREFS || join(homedir(), ".claude", "multi-agent-preferences.json")
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function writePrefsAtomic(file, prefs) {
|
|
433
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
434
|
+
const tmp = `${file}.tmp.${process.pid}`;
|
|
435
|
+
const mode = existsSync(file) ? statSync(file).mode & 0o777 : 0o600;
|
|
436
|
+
writeFileSync(tmp, `${JSON.stringify(prefs, null, 2)}\n`, { mode });
|
|
437
|
+
chmodSync(tmp, mode);
|
|
438
|
+
renameSync(tmp, file);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function readJson(file) {
|
|
442
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function parseArgs(argv) {
|
|
446
|
+
const out = { developed: [] };
|
|
447
|
+
for (let i = 0; i < argv.length; i++) {
|
|
448
|
+
const a = argv[i];
|
|
449
|
+
if (!a.startsWith("--")) continue;
|
|
450
|
+
const key = a.slice(2);
|
|
451
|
+
const value = argv[i + 1];
|
|
452
|
+
if (value === undefined || value === "" || value.startsWith("--")) {
|
|
453
|
+
process.stderr.write(`product-context: --${key} needs a value\n`);
|
|
454
|
+
process.exit(1);
|
|
455
|
+
}
|
|
456
|
+
i += 1;
|
|
457
|
+
if (key === "developed") out.developed.push(value);
|
|
458
|
+
else out[key] = value;
|
|
459
|
+
}
|
|
460
|
+
return out;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function fail(message) {
|
|
464
|
+
process.stderr.write(`product-context: ${message}\n`);
|
|
465
|
+
process.exit(1);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
function main() {
|
|
469
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
470
|
+
const args = parseArgs(rest);
|
|
471
|
+
const prefsFile = args.prefs || defaultPrefsPath();
|
|
472
|
+
const loadPrefs = () =>
|
|
473
|
+
existsSync(prefsFile) ? readJson(prefsFile) : { global: {}, projects: {} };
|
|
474
|
+
switch (command) {
|
|
475
|
+
case "refs": {
|
|
476
|
+
if (!args.project) fail("refs needs --project");
|
|
477
|
+
const r = referenceSet(loadPrefs(), args.project, args.developed);
|
|
478
|
+
process.stdout.write(`${JSON.stringify(r)}\n`);
|
|
479
|
+
process.exitCode = r.references.length ? 0 : 2;
|
|
480
|
+
break;
|
|
481
|
+
}
|
|
482
|
+
case "suggest": {
|
|
483
|
+
if (!args.primary || !args.repos) fail("suggest needs --primary and --repos");
|
|
484
|
+
process.stdout.write(
|
|
485
|
+
`${JSON.stringify(suggestCandidates(args.primary, readJson(args.repos)))}\n`,
|
|
486
|
+
);
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
case "learn": {
|
|
490
|
+
if (!args.project || !args.product || !args.repos)
|
|
491
|
+
fail("learn needs --project, --product and --repos");
|
|
492
|
+
let next;
|
|
493
|
+
try {
|
|
494
|
+
next = learnProduct(loadPrefs(), args.project, args.product, readJson(args.repos));
|
|
495
|
+
} catch (e) {
|
|
496
|
+
fail(e.message);
|
|
497
|
+
}
|
|
498
|
+
writePrefsAtomic(prefsFile, next);
|
|
499
|
+
process.stdout.write(
|
|
500
|
+
`${JSON.stringify({ product: args.product, repos: next.global.products[args.product].repos.length })}\n`,
|
|
501
|
+
);
|
|
502
|
+
break;
|
|
503
|
+
}
|
|
504
|
+
case "needs-mapping": {
|
|
505
|
+
if (!args.project) fail("needs-mapping needs --project");
|
|
506
|
+
const needed = needsMapping(loadPrefs(), args.project, args.developed);
|
|
507
|
+
process.stdout.write(`${JSON.stringify({ needsMapping: needed })}\n`);
|
|
508
|
+
process.exitCode = needed ? 0 : 3;
|
|
509
|
+
break;
|
|
510
|
+
}
|
|
511
|
+
case "decline": {
|
|
512
|
+
if (!args.project) fail("decline needs --project");
|
|
513
|
+
writePrefsAtomic(prefsFile, declineProduct(loadPrefs(), args.project));
|
|
514
|
+
process.stdout.write(`${JSON.stringify({ project: args.project, product: "" })}\n`);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
case "record": {
|
|
518
|
+
if (!args.in) fail("record needs --in");
|
|
519
|
+
const r = recordFindings(readJson(args.in), {
|
|
520
|
+
taskId: args.task || null,
|
|
521
|
+
knowledgeRoot: args.knowledge || defaultKnowledgeRoot(),
|
|
522
|
+
refs: args.refs ? readJson(args.refs).references || [] : [],
|
|
523
|
+
});
|
|
524
|
+
process.stdout.write(`${JSON.stringify(r)}\n`);
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
case "recall": {
|
|
528
|
+
if (!args.remote || !args.sha || !args.keys) fail("recall needs --remote, --sha and --keys");
|
|
529
|
+
process.stdout.write(
|
|
530
|
+
`${JSON.stringify(recall({ knowledgeRoot: args.knowledge || defaultKnowledgeRoot(), remote: args.remote, sha: args.sha, keys: args.keys.split(",").filter(Boolean) }))}\n`,
|
|
531
|
+
);
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
default:
|
|
535
|
+
fail("usage: product-context.mjs refs|suggest|needs-mapping|learn|decline|record|recall ...");
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) main();
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
# 3. No personal-data leaks (hardcoded personal keychain keys, etc.)
|
|
11
11
|
# 4. Canonical placeholders present where required (sanity)
|
|
12
12
|
# 5. Canonical project-name vocabulary in user-facing docs
|
|
13
|
+
# 8. Product context installed on Claude Code, Copilot CLI and Codex CLI
|
|
13
14
|
#
|
|
14
15
|
# Must pass before any `sync` run that touches shared commands.
|
|
15
16
|
#
|
|
@@ -34,7 +35,7 @@ if [ -z "${CROSS_CLI_HOME:-}" ] && [ -e "$CHECKOUT/.git" ] && [ -f "$CHECKOUT/in
|
|
|
34
35
|
INSTALL_HOME=$(mktemp -d "${TMPDIR:-/tmp}/cross-cli-home.XXXXXX")
|
|
35
36
|
trap 'rm -rf "$INSTALL_HOME"' EXIT
|
|
36
37
|
if HOME="$INSTALL_HOME" MULTI_AGENT_SKIP_MCP_REGISTER=1 \
|
|
37
|
-
node "$CHECKOUT/install.js" --claude --copilot >"$INSTALL_HOME/install.log" 2>&1; then
|
|
38
|
+
node "$CHECKOUT/install.js" --claude --copilot --codex >"$INSTALL_HOME/install.log" 2>&1; then
|
|
38
39
|
pass "installed this checkout into a temporary home"
|
|
39
40
|
else
|
|
40
41
|
fail "install of this checkout failed: $(tail -3 "$INSTALL_HOME/install.log" | tr '\n' ' ')"
|
|
@@ -276,6 +277,43 @@ else
|
|
|
276
277
|
fail "triage consensus.reviewerCount does not document the 3-reviewer set"
|
|
277
278
|
fi
|
|
278
279
|
|
|
280
|
+
echo ""
|
|
281
|
+
echo "→ 8. Product context reaches every host"
|
|
282
|
+
# Planning reads the product's other repositories through the toolkit's repo_*
|
|
283
|
+
# tools on every host, so the deterministic half (product-context.mjs) and the
|
|
284
|
+
# Phase 1 step that calls it must be installed wherever the pipeline runs.
|
|
285
|
+
# Copilot installs no multi-agent-refs tree by design; it reads the refs from
|
|
286
|
+
# ~/.claude or GitHub, and its own copy of the review skill carries the step.
|
|
287
|
+
for host in .claude .copilot .codex; do
|
|
288
|
+
[ -d "$H/$host" ] || { echo " ↷ SKIP: $host not installed in this home"; continue; }
|
|
289
|
+
if [ -f "$H/$host/scripts/product-context.mjs" ]; then
|
|
290
|
+
pass "$host/scripts/product-context.mjs installed"
|
|
291
|
+
else
|
|
292
|
+
fail "$host/scripts/product-context.mjs missing"
|
|
293
|
+
fi
|
|
294
|
+
done
|
|
295
|
+
for host in .claude .codex; do
|
|
296
|
+
[ -d "$H/$host" ] || continue
|
|
297
|
+
P1="$H/$host/multi-agent-refs/phases/phase-1-plan.md"
|
|
298
|
+
if [ -f "$P1" ] && grep -q "Step 1.6 - Product context" "$P1" && grep -q "product-context.mjs refs" "$P1"; then
|
|
299
|
+
pass "$host Phase 1 carries the product-context step"
|
|
300
|
+
else
|
|
301
|
+
fail "$host Phase 1 lacks the product-context step"
|
|
302
|
+
fi
|
|
303
|
+
done
|
|
304
|
+
if [ -d "$H/.copilot" ]; then
|
|
305
|
+
if grep -q "product-context.mjs refs" "$H/.copilot/skills/multi-agent-review/SKILL.md" 2>/dev/null; then
|
|
306
|
+
pass "Copilot review skill resolves product counterparts"
|
|
307
|
+
else
|
|
308
|
+
fail "Copilot review skill does not resolve product counterparts"
|
|
309
|
+
fi
|
|
310
|
+
fi
|
|
311
|
+
if grep -q '`repo_find_keys`' "$H/.claude/multi-agent-refs/cross-cli-contract.md" 2>/dev/null; then
|
|
312
|
+
pass "cross-cli contract pins the repo_* toolkit minimum"
|
|
313
|
+
else
|
|
314
|
+
fail "cross-cli contract does not name the repo_* tools"
|
|
315
|
+
fi
|
|
316
|
+
|
|
279
317
|
echo ""
|
|
280
318
|
echo "══ cross-cli-behavior smoke: $PASS passed, $FAIL failed ══"
|
|
281
319
|
[ "$FAIL" -eq 0 ]
|
|
@@ -137,7 +137,8 @@ export function validate(obj) {
|
|
|
137
137
|
if (typeof obj !== "object" || obj === null || Array.isArray(obj))
|
|
138
138
|
return ["root must be an object"];
|
|
139
139
|
|
|
140
|
-
if (
|
|
140
|
+
if (!["1.0.0", "1.1.0"].includes(obj.schemaVersion))
|
|
141
|
+
errors.push(`schemaVersion must be "1.0.0" or "1.1.0"`);
|
|
141
142
|
if (!ALLOWED_STACK.has(obj.stack))
|
|
142
143
|
errors.push(`stack must be one of ${[...ALLOWED_STACK].join(",")}`);
|
|
143
144
|
if (typeof obj.root !== "string" || obj.root.length === 0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": "1.0.0",
|
|
3
|
-
"generatedAt": "2026-10-
|
|
3
|
+
"generatedAt": "2026-10-12T21:38:23Z",
|
|
4
4
|
"skillCount": 228,
|
|
5
5
|
"entries": [
|
|
6
6
|
{
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
},
|
|
166
166
|
{
|
|
167
167
|
"path": "shared/core/multi-agent-review/SKILL.md",
|
|
168
|
-
"sha256": "
|
|
168
|
+
"sha256": "1a22618e6d3d9d07b267bd61fc591bb33726e1d7ef8567285401f61bc7be0ad5"
|
|
169
169
|
},
|
|
170
170
|
{
|
|
171
171
|
"path": "shared/core/multi-agent-route-off/SKILL.md",
|
|
@@ -213,7 +213,7 @@
|
|
|
213
213
|
},
|
|
214
214
|
{
|
|
215
215
|
"path": "shared/core/multi-agent-setup/SKILL.md",
|
|
216
|
-
"sha256": "
|
|
216
|
+
"sha256": "79a4afa655df12221a25bc386a32e61c38016d2de660dd618b404ca8bb0b28d3"
|
|
217
217
|
},
|
|
218
218
|
{
|
|
219
219
|
"path": "shared/core/multi-agent-stack/SKILL.md",
|
|
@@ -76,7 +76,11 @@ Skip Phase 0-3 and review a diff only. Input shapes: a PR (`#N`, `repo#N`, GitHu
|
|
|
76
76
|
resolves whose `stack` is the other mobile platform and the diff touches a screen, a
|
|
77
77
|
service, a request model or a localization file, compare the change against that repo
|
|
78
78
|
on four axes: endpoints called, parameters sent, business rules around the call,
|
|
79
|
-
localization keys used.
|
|
79
|
+
localization keys used. When the project belongs to a product
|
|
80
|
+
(`prefs.global.products`), the counterparts are the product's other repositories,
|
|
81
|
+
resolved with `product-context.mjs refs` and compared at their latest integration
|
|
82
|
+
branch through the toolkit's `repo_*` tools, pinned to a sha
|
|
83
|
+
(`features/product-context.md`). Otherwise the counterpart is resolved automatically and in both
|
|
80
84
|
directions (ios ↔ android) from four sources in this order, first hit wins:
|
|
81
85
|
`--with <path|owner/repo>` (a one-off override, remembered like any other resolution),
|
|
82
86
|
then a remembered `prefs.projects[<slug>].counterpartRoots[]`, then the primary
|