@mmerterden/multi-agent-pipeline 20.20.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 +58 -0
- package/README.md +24 -13
- package/README.tr.md +21 -10
- package/docs/adr/0017-change-impact-from-the-graph.md +69 -0
- package/docs/adr/README.md +1 -0
- package/docs/ecosystem.md +7 -5
- package/docs/facts.json +6 -4
- package/docs/features.md +1 -0
- package/install/catalog-history.json +1 -1
- package/install/templates/copilot-instructions.md +1 -0
- package/manifest.json +71 -64
- package/package.json +1 -1
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/review/SKILL.md +2 -1
- package/pipeline/commands/multi-agent/route-on/SKILL.md +32 -8
- package/pipeline/commands/multi-agent/route-status/SKILL.md +12 -2
- package/pipeline/commands/multi-agent/setup/SKILL.md +8 -16
- package/pipeline/lib/model-dispatch.sh +72 -24
- package/pipeline/lib/outbound-gate.mjs +2 -0
- package/pipeline/lib/route-state.sh +118 -10
- package/pipeline/lib/toolkit-llm.sh +30 -0
- package/pipeline/lib/unattended-profile-check.mjs +23 -2
- package/pipeline/multi-agent-refs/_dev-context.md +15 -0
- package/pipeline/multi-agent-refs/analysis/evidence.md +7 -3
- package/pipeline/multi-agent-refs/analysis/locked.md +1 -1
- package/pipeline/multi-agent-refs/cross-cli-contract.md +9 -3
- package/pipeline/multi-agent-refs/features/code-graph.md +27 -0
- package/pipeline/multi-agent-refs/features/doctor.md +11 -0
- package/pipeline/multi-agent-refs/features/free-models.md +111 -0
- package/pipeline/multi-agent-refs/features/model-fallback.md +21 -15
- package/pipeline/multi-agent-refs/features/product-context.md +238 -0
- package/pipeline/multi-agent-refs/features/unattended-security.md +4 -2
- 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/free-models.md +22 -0
- package/pipeline/multi-agent-refs/setup/token-save-flow.md +24 -0
- package/pipeline/preferences-template.json +1 -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 +68 -1
- package/pipeline/schemas/route-config.schema.json +33 -8
- package/pipeline/schemas/secret-patterns.json +14 -0
- package/pipeline/scripts/_code-graph.mjs +76 -3
- package/pipeline/scripts/_diff-impact.mjs +312 -0
- package/pipeline/scripts/bulk-read.sh +98 -12
- package/pipeline/scripts/capture-flush.sh +58 -3
- package/pipeline/scripts/cost-table.json +9 -1
- package/pipeline/scripts/diff-risk-score.mjs +80 -9
- package/pipeline/scripts/doctor.mjs +100 -0
- package/pipeline/scripts/graph-affected.mjs +167 -36
- package/pipeline/scripts/graph-query.mjs +16 -4
- package/pipeline/scripts/pre-commit-check.sh +1 -1
- package/pipeline/scripts/product-context.mjs +539 -0
- package/pipeline/scripts/smoke-cross-cli-behavior.sh +39 -1
- package/pipeline/scripts/unattended_policy.py +20 -0
- package/pipeline/scripts/validate-code-graph.mjs +2 -1
- package/pipeline/scripts/validate-diff-risk.mjs +1 -0
- package/pipeline/skills/.skill-manifest.json +6 -6
- package/pipeline/skills/shared/core/multi-agent/SKILL.md +2 -0
- package/pipeline/skills/shared/core/multi-agent-review/SKILL.md +5 -1
- package/pipeline/skills/shared/core/multi-agent-route-on/SKILL.md +31 -7
- package/pipeline/skills/shared/core/multi-agent-route-status/SKILL.md +12 -2
- package/pipeline/skills/shared/core/multi-agent-setup/SKILL.md +9 -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 ]
|
|
@@ -2644,6 +2644,24 @@ def _toolkit_path_refusal(name, ti, policy, env, cwd):
|
|
|
2644
2644
|
return None
|
|
2645
2645
|
|
|
2646
2646
|
|
|
2647
|
+
def _free_routing_on(env):
|
|
2648
|
+
"""modelRouting.enabled and modelRouting.free.enabled in the preferences
|
|
2649
|
+
file. The user's own switch, read at call time: off, unreadable or absent
|
|
2650
|
+
all mean off."""
|
|
2651
|
+
env = env if env is not None else os.environ
|
|
2652
|
+
home = env.get("HOME") or os.path.expanduser("~")
|
|
2653
|
+
for path in (env.get("MULTI_AGENT_PREFS"), os.path.join(home, ".claude", "multi-agent-preferences.json")):
|
|
2654
|
+
if not path or not os.path.isfile(path):
|
|
2655
|
+
continue
|
|
2656
|
+
try:
|
|
2657
|
+
with open(path, encoding="utf-8") as fh:
|
|
2658
|
+
routing = (json.load(fh).get("global") or {}).get("modelRouting") or {}
|
|
2659
|
+
except (OSError, ValueError, AttributeError):
|
|
2660
|
+
return False
|
|
2661
|
+
return routing.get("enabled") is True and (routing.get("free") or {}).get("enabled") is True
|
|
2662
|
+
return False
|
|
2663
|
+
|
|
2664
|
+
|
|
2647
2665
|
def check_toolkit(name, ti, policy, env, depth=0, cwd=None):
|
|
2648
2666
|
"""A multi-agent-toolkit tool call, by its short name (web_goto,
|
|
2649
2667
|
ios_open_url, agent_run_steps). agent_run_steps dispatches other toolkit
|
|
@@ -2653,6 +2671,8 @@ def check_toolkit(name, ti, policy, env, depth=0, cwd=None):
|
|
|
2653
2671
|
return f"{name} arguments are not an object the guard can read"
|
|
2654
2672
|
if name.startswith("research_"):
|
|
2655
2673
|
return f"{name} sends the query to an outside service"
|
|
2674
|
+
if name == "llm_delegate" and not _free_routing_on(env):
|
|
2675
|
+
return "llm_delegate sends text to a free-model provider; unattended runs allow it only after route-on --free"
|
|
2656
2676
|
if name == "web_eval":
|
|
2657
2677
|
return "web_eval runs arbitrary JavaScript that can reach any host; refused unattended"
|
|
2658
2678
|
if name == "agent_run_steps":
|
|
@@ -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)
|