@mmerterden/multi-agent-pipeline 23.3.0 → 23.5.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 +73 -0
- package/README.md +27 -8
- package/README.tr.md +28 -9
- package/SECURITY.md +16 -0
- package/docs/adr/0008-installer-modularization-and-secret-leak-defense.md +1 -1
- package/docs/adr/0010-own-code-graph.md +299 -8
- package/docs/architecture.md +3 -3
- package/docs/ecosystem.md +10 -10
- package/docs/engineering.md +4 -4
- package/docs/facts.json +8 -8
- package/docs/features.md +5 -5
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/_platform-filter.mjs +2 -55
- package/install/claude.mjs +28 -2
- package/install/codex.mjs +1 -3
- package/install/copilot.mjs +4 -8
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +236 -167
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +3 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/graph/SKILL.md +57 -24
- package/pipeline/commands/multi-agent/pair/SKILL.md +92 -0
- package/pipeline/commands/multi-agent/prune-prompts/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/search/SKILL.md +7 -1
- package/pipeline/commands/multi-agent/status/SKILL.md +4 -0
- package/pipeline/commands/multi-agent/sync/SKILL.md +3 -3
- package/pipeline/contract/CHANGELOG.md +63 -0
- package/pipeline/contract/README.md +1 -0
- package/pipeline/contract/build.mjs +13 -1
- package/pipeline/contract/fixtures/error-invalid-request.json +1 -1
- package/pipeline/contract/fixtures/error-unauthorized.json +1 -1
- package/pipeline/contract/fixtures/runs-awaiting-question.json +4 -1
- package/pipeline/contract/fixtures/runs-empty.json +1 -1
- package/pipeline/contract/fixtures/runs-failed.json +4 -1
- package/pipeline/contract/fixtures/runs-old-schema.json +3 -0
- package/pipeline/contract/fixtures/runs-pr-opened-redacted.json +4 -1
- package/pipeline/contract/fixtures/runs-pr-opened.json +4 -1
- package/pipeline/contract/fixtures/runs-running.json +4 -1
- package/pipeline/contract/manifest.json +41 -15
- package/pipeline/contract/types/index.d.ts +81 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/stack-detect.sh +1 -1
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +613 -0
- package/pipeline/lib/usage-run-key.mjs +235 -0
- package/pipeline/lib/usage-vocab.mjs +210 -0
- package/pipeline/multi-agent-refs/analysis/intake.md +2 -2
- package/pipeline/multi-agent-refs/analysis/render.md +1 -1
- package/pipeline/multi-agent-refs/channels/generator.md +4 -5
- package/pipeline/multi-agent-refs/cross-cli-contract.md +3 -3
- package/pipeline/multi-agent-refs/design-check/init-inventory.md +11 -1
- package/pipeline/multi-agent-refs/design-check/scope-and-ledger.md +1 -1
- package/pipeline/multi-agent-refs/features/code-graph.md +146 -11
- package/pipeline/multi-agent-refs/features/code-intelligence.md +16 -14
- package/pipeline/multi-agent-refs/features/dev-critic.md +7 -7
- package/pipeline/multi-agent-refs/features/model-fallback.md +6 -4
- package/pipeline/multi-agent-refs/features/remote-control.md +253 -0
- package/pipeline/multi-agent-refs/features/review-delta.md +1 -1
- package/pipeline/multi-agent-refs/features/review-file-set.md +3 -3
- package/pipeline/multi-agent-refs/features/review-multi-repo.md +1 -1
- package/pipeline/multi-agent-refs/features/session-brief.md +42 -0
- package/pipeline/multi-agent-refs/features/skill-conformance.md +3 -3
- package/pipeline/multi-agent-refs/features/usage-reporting.md +255 -27
- package/pipeline/multi-agent-refs/help/en.md +3 -2
- package/pipeline/multi-agent-refs/help/tr.md +3 -2
- package/pipeline/multi-agent-refs/knowledge.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +2 -2
- package/pipeline/multi-agent-refs/phases/operations.md +2 -2
- package/pipeline/multi-agent-refs/phases/phase-0-init.md +13 -12
- package/pipeline/multi-agent-refs/phases/phase-1-plan.md +4 -4
- package/pipeline/multi-agent-refs/phases/phase-3-review.md +2 -0
- package/pipeline/multi-agent-refs/phases/phase-5-report.md +1 -1
- package/pipeline/multi-agent-refs/platform-parity.md +2 -2
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1309 -236
- package/pipeline/office/toolkit.json +1 -1
- package/pipeline/rules/outside-the-pipeline.md +1 -1
- package/pipeline/schemas/activity.schema.json +23 -0
- package/pipeline/schemas/agent-state.schema.json +6 -1
- package/pipeline/schemas/code-graph-calls.schema.json +254 -0
- package/pipeline/schemas/code-graph-docs.schema.json +223 -0
- package/pipeline/schemas/code-graph-infra.schema.json +227 -0
- package/pipeline/schemas/code-graph.schema.json +2 -2
- package/pipeline/schemas/examples/design-check-config.json +27 -0
- package/pipeline/schemas/learning-curve.schema.json +67 -0
- package/pipeline/schemas/mcp-health.schema.json +96 -0
- package/pipeline/schemas/office-jobs.json +69 -2
- package/pipeline/schemas/office-jobs.schema.json +8 -1
- package/pipeline/schemas/phases.json +5 -0
- package/pipeline/schemas/phases.schema.json +8 -0
- package/pipeline/schemas/prefs.schema.json +46 -12
- package/pipeline/schemas/runs-index.schema.json +17 -0
- package/pipeline/schemas/toolkit-path-params.json +78 -8
- package/pipeline/scripts/README.md +1 -0
- package/pipeline/scripts/_code-graph.mjs +184 -103
- package/pipeline/scripts/_contract-core.mjs +1 -1
- package/pipeline/scripts/_contract-routes-office.mjs +33 -0
- package/pipeline/scripts/_diff-impact.mjs +21 -2
- package/pipeline/scripts/_graph-sidecars.mjs +372 -0
- package/pipeline/scripts/_http-post.mjs +103 -115
- package/pipeline/scripts/_safe-read.mjs +57 -0
- package/pipeline/scripts/_skill-practices.mjs +26 -0
- package/pipeline/scripts/_strip-code.mjs +380 -0
- package/pipeline/scripts/activity-snapshot.mjs +13 -1
- package/pipeline/scripts/aggregate-metrics.mjs +3 -5
- package/pipeline/scripts/build-stack-plugins.mjs +1 -47
- package/pipeline/scripts/call-graph/index.mjs +78 -0
- package/pipeline/scripts/call-graph/lang/cpp.mjs +308 -0
- package/pipeline/scripts/call-graph/lang/csharp.mjs +130 -0
- package/pipeline/scripts/call-graph/lang/go.mjs +303 -0
- package/pipeline/scripts/call-graph/lang/java.mjs +370 -0
- package/pipeline/scripts/call-graph/lang/kotlin.mjs +397 -0
- package/pipeline/scripts/call-graph/lang/python.mjs +399 -0
- package/pipeline/scripts/call-graph/lang/rust.mjs +345 -0
- package/pipeline/scripts/call-graph/lang/shared.mjs +230 -0
- package/pipeline/scripts/call-graph/lang/swift.mjs +432 -0
- package/pipeline/scripts/call-graph/lang/typescript.mjs +692 -0
- package/pipeline/scripts/call-graph/lex.mjs +396 -0
- package/pipeline/scripts/call-graph/platform.mjs +86 -0
- package/pipeline/scripts/call-graph/profiles.mjs +89 -0
- package/pipeline/scripts/call-graph/resolve.mjs +1125 -0
- package/pipeline/scripts/call-graph/scan.mjs +267 -0
- package/pipeline/scripts/code-graph-rules/android.json +7 -2
- package/pipeline/scripts/code-graph-rules/cpp.json +99 -0
- package/pipeline/scripts/code-graph-rules/csharp.json +102 -0
- package/pipeline/scripts/code-graph-rules/go.json +2 -1
- package/pipeline/scripts/code-graph-rules/ios.json +3 -1
- package/pipeline/scripts/code-graph-rules/java.json +76 -0
- package/pipeline/scripts/code-graph-rules/node.json +7 -2
- package/pipeline/scripts/code-graph-rules/python.json +6 -2
- package/pipeline/scripts/code-graph-rules/rust.json +105 -0
- package/pipeline/scripts/contract-server.mjs +3 -0
- package/pipeline/scripts/design-check-config.mjs +205 -0
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- package/pipeline/scripts/gen-facts.mjs +1 -2
- package/pipeline/scripts/gen-usage-names.mjs +124 -0
- package/pipeline/scripts/graph-affected.mjs +109 -20
- package/pipeline/scripts/graph-build.mjs +95 -15
- package/pipeline/scripts/graph-export.mjs +272 -0
- package/pipeline/scripts/graph-hint.mjs +15 -2
- package/pipeline/scripts/graph-query.mjs +305 -26
- package/pipeline/scripts/graph-report.mjs +187 -1
- package/pipeline/scripts/health-report.mjs +3 -4
- package/pipeline/scripts/infra/docs.mjs +317 -0
- package/pipeline/scripts/infra/extract.mjs +998 -0
- package/pipeline/scripts/infra/graph.mjs +245 -0
- package/pipeline/scripts/infra/yaml-lite.mjs +311 -0
- package/pipeline/scripts/job-launch.mjs +67 -2
- package/pipeline/scripts/learning-curve.mjs +288 -178
- package/pipeline/scripts/log-metric.sh +10 -1
- package/pipeline/scripts/mcp-health.mjs +309 -0
- package/pipeline/scripts/note-agent-event.mjs +3 -4
- package/pipeline/scripts/note-command-use.mjs +333 -0
- package/pipeline/scripts/note-command-use.sh +126 -0
- package/pipeline/scripts/note-mcp-call.sh +89 -0
- package/pipeline/scripts/note-mcp-failure.mjs +272 -1
- package/pipeline/scripts/note-session.sh +62 -3
- package/pipeline/scripts/note-skill-use.mjs +58 -2
- package/pipeline/scripts/office-build.mjs +115 -1
- package/pipeline/scripts/office-memory.mjs +14 -5
- package/pipeline/scripts/pair.mjs +333 -0
- package/pipeline/scripts/pre-push-check.sh +1 -1
- package/pipeline/scripts/remote/cbor.mjs +128 -0
- package/pipeline/scripts/remote/contract.mjs +98 -0
- package/pipeline/scripts/remote/handler.mjs +330 -0
- package/pipeline/scripts/remote/handles.mjs +57 -0
- package/pipeline/scripts/remote/lifecycle.mjs +186 -0
- package/pipeline/scripts/remote/listener.mjs +204 -0
- package/pipeline/scripts/remote/lockout.mjs +103 -0
- package/pipeline/scripts/remote/nonces.mjs +61 -0
- package/pipeline/scripts/remote/pairing.mjs +519 -0
- package/pipeline/scripts/remote/qr-encode.mjs +459 -0
- package/pipeline/scripts/remote/store.mjs +191 -0
- package/pipeline/scripts/remote/transport.mjs +211 -0
- package/pipeline/scripts/remote/verbs.json +70 -0
- package/pipeline/scripts/remote/verbs.mjs +217 -0
- package/pipeline/scripts/remote/webauthn.mjs +169 -0
- package/pipeline/scripts/remote/wire.mjs +364 -0
- package/pipeline/scripts/remote-listener.mjs +83 -0
- package/pipeline/scripts/route-learn.mjs +4 -4
- package/pipeline/scripts/run-kill.mjs +1 -1
- package/pipeline/scripts/run-write.mjs +13 -2
- package/pipeline/scripts/runs-index.mjs +30 -3
- package/pipeline/scripts/search-logs.sh +9 -0
- package/pipeline/scripts/session-brief.mjs +458 -0
- package/pipeline/scripts/session-brief.sh +130 -0
- package/pipeline/scripts/skill-usage.mjs +16 -5
- package/pipeline/scripts/test-gap-rules/cpp.json +25 -0
- package/pipeline/scripts/test-gap-rules/csharp.json +20 -0
- package/pipeline/scripts/test-gap-rules/java.json +20 -0
- package/pipeline/scripts/test-gap-rules/rust.json +14 -0
- package/pipeline/scripts/token-budget-report.mjs +3 -2
- package/pipeline/scripts/uninstall.mjs +29 -0
- package/pipeline/scripts/usage-access.mjs +16 -31
- package/pipeline/scripts/usage-health.mjs +31 -62
- package/pipeline/scripts/usage-register-beacon.mjs +11 -22
- package/pipeline/scripts/usage-register.mjs +39 -29
- package/pipeline/scripts/usage-report.mjs +579 -178
- package/pipeline/scripts/validate-code-graph.mjs +361 -111
- package/pipeline/scripts/write-state.mjs +39 -0
- package/pipeline/skills/.skill-manifest.json +21 -17
- package/pipeline/skills/.skills-index.json +13 -2
- package/pipeline/skills/shared/README.md +5 -4
- package/pipeline/skills/shared/core/multi-agent-design-check/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-diff-explain/SKILL.md +3 -3
- package/pipeline/skills/shared/core/multi-agent-graph/SKILL.md +55 -21
- package/pipeline/skills/shared/core/multi-agent-pair/SKILL.md +41 -0
- package/pipeline/skills/shared/core/multi-agent-prune-prompts/SKILL.md +1 -1
- package/pipeline/skills/shared/core/multi-agent-sync/SKILL.md +3 -3
- package/pipeline/skills/shared/external/app-store-optimization/SKILL.md +2 -3
- package/pipeline/skills/shared/external/app-store-optimization/references/keyword-research-methodology.md +2 -2
- package/pipeline/skills/shared/external/app-store-optimization/references/product-page-variants.md +2 -2
- package/pipeline/skills/shared/external/app-store-review/SKILL.md +11 -4
- package/pipeline/skills/shared/external/build-settings-audit/SKILL.md +1 -1
- package/pipeline/skills/shared/external/build-time-benchmark/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-fixes/SKILL.md +5 -5
- package/pipeline/skills/shared/external/build-time-optimizer/SKILL.md +6 -6
- package/pipeline/skills/shared/external/free-llm-apis/references/providers.md +1 -0
- package/pipeline/skills/shared/external/ios-coding-standard/references/STANDARD.md +2 -2
- package/pipeline/skills/shared/external/ios-haptics/references/core-haptics.md +1 -1
- package/pipeline/skills/shared/external/localization-reuse-map/references/publish-and-snapshot.md +1 -1
- package/pipeline/skills/shared/external/package-build-audit/SKILL.md +3 -3
- package/pipeline/skills/shared/external/reverse-engineer-own-app/SKILL.md +2 -3
- package/pipeline/skills/shared/external/swift-compile-hotspots/SKILL.md +2 -2
- package/pipeline/skills/shared/external/weatherkit/SKILL.md +5 -6
- package/pipeline/skills/skills-index.md +3 -2
- package/docs/FIGMA_PIPELINE.md +0 -137
- package/pipeline/lib/identifier-scan.mjs +0 -156
- package/pipeline/scripts/_renamed-skills.mjs +0 -164
- package/pipeline/scripts/publish-staged.mjs +0 -324
- package/pipeline/skills/renamed.json +0 -30
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file _strip-code.mjs - blank comments and string literals, keep interpolated code.
|
|
3
|
+
*
|
|
4
|
+
* The code graph reads definitions, identifiers and calls from source with the
|
|
5
|
+
* text that is not code removed. A character scan does it, not a regex pass: a
|
|
6
|
+
* regex cannot tell a `//` inside a string from a comment, which is what makes
|
|
7
|
+
* reference edges noisy. Removed spans become spaces, so offsets and line
|
|
8
|
+
* numbers are preserved.
|
|
9
|
+
*
|
|
10
|
+
* What counts as a comment or a string comes from the stack's rule file
|
|
11
|
+
* (`comments`): line and block markers, quote tokens, and a `dialect` that turns
|
|
12
|
+
* on the literal forms of that language:
|
|
13
|
+
*
|
|
14
|
+
* js template literals, regular-expression literals
|
|
15
|
+
* swift nested block comments, `#"..."#` extended delimiters, `\(expr)`
|
|
16
|
+
* kotlin nested block comments, `"""` raw strings, `${expr}` templates
|
|
17
|
+
* rust nested block comments, `r#"..."#` raw strings, char literals
|
|
18
|
+
* cpp `R"x(...)x"` raw strings, char literals
|
|
19
|
+
* csharp `@"..."` verbatim and `$"..."` interpolated strings
|
|
20
|
+
* python `f"..."` strings with `{expr}` holes
|
|
21
|
+
* go backtick raw strings
|
|
22
|
+
*
|
|
23
|
+
* The code inside an interpolation hole is kept (comments, strings and regular
|
|
24
|
+
* expressions inside it are blanked in turn), because a call written there is a
|
|
25
|
+
* call. Work is linear: every character is visited once, holes nest to a fixed
|
|
26
|
+
* depth, and an unterminated literal ends at the end of the text.
|
|
27
|
+
*
|
|
28
|
+
* @module pipeline/scripts/_strip-code
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const HOLE_DEPTH_MAX = 12;
|
|
32
|
+
const REGEX_LOOKAHEAD = 600;
|
|
33
|
+
// "<" is absent: a "/" after it closes a JSX tag (`</strong>`), and `a < /re/` is not written.
|
|
34
|
+
const REGEX_AFTER_CHARS = new Set([..."=(,:;!&|?{[+-*%>~^"]);
|
|
35
|
+
const REGEX_AFTER_WORDS = new Set([
|
|
36
|
+
"return",
|
|
37
|
+
"typeof",
|
|
38
|
+
"case",
|
|
39
|
+
"in",
|
|
40
|
+
"of",
|
|
41
|
+
"delete",
|
|
42
|
+
"void",
|
|
43
|
+
"yield",
|
|
44
|
+
"await",
|
|
45
|
+
"else",
|
|
46
|
+
"throw",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const isIdentChar = (c) => c !== undefined && /[A-Za-z0-9_$]/.test(c);
|
|
50
|
+
|
|
51
|
+
/** Can a `/` at index i start a regular-expression literal, judging by what precedes it? */
|
|
52
|
+
function regexMayStart(text, i) {
|
|
53
|
+
let k = i - 1;
|
|
54
|
+
while (k >= 0 && (text[k] === " " || text[k] === "\t" || text[k] === "\n" || text[k] === "\r"))
|
|
55
|
+
k--;
|
|
56
|
+
if (k < 0) return true;
|
|
57
|
+
if (REGEX_AFTER_CHARS.has(text[k])) return true;
|
|
58
|
+
if (!/[A-Za-z_$]/.test(text[k])) return false;
|
|
59
|
+
let w = k;
|
|
60
|
+
while (w > 0 && isIdentChar(text[w - 1])) w--;
|
|
61
|
+
return REGEX_AFTER_WORDS.has(text.slice(w, k + 1));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** End (exclusive, flags included) of the regular-expression literal starting at i, or -1. */
|
|
65
|
+
function regexEnd(text, i) {
|
|
66
|
+
const limit = Math.min(text.length, i + REGEX_LOOKAHEAD);
|
|
67
|
+
let j = i + 1;
|
|
68
|
+
let inClass = false;
|
|
69
|
+
while (j < limit) {
|
|
70
|
+
const c = text[j];
|
|
71
|
+
if (c === "\n") return -1;
|
|
72
|
+
if (c === "\\") {
|
|
73
|
+
j += 2;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (inClass) {
|
|
77
|
+
if (c === "]") inClass = false;
|
|
78
|
+
} else if (c === "[") inClass = true;
|
|
79
|
+
else if (c === "/") {
|
|
80
|
+
j++;
|
|
81
|
+
while (j < limit && /[dgimsuyv]/.test(text[j])) j++;
|
|
82
|
+
return j > i + 1 ? j : -1;
|
|
83
|
+
}
|
|
84
|
+
j++;
|
|
85
|
+
}
|
|
86
|
+
return -1;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Number of consecutive `ch` immediately before index i. */
|
|
90
|
+
function runBefore(text, i, ch) {
|
|
91
|
+
let k = 0;
|
|
92
|
+
while (i - k - 1 >= 0 && text[i - k - 1] === ch) k++;
|
|
93
|
+
return k;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* How the literal that opens with `tok` at index i is written in this dialect.
|
|
98
|
+
*
|
|
99
|
+
* @returns {{from: number, body: number, close: (j: number) => number, esc: string|null,
|
|
100
|
+
* multiline: boolean, hole: ((j: number) => {len: number, closer: string}|null)|null,
|
|
101
|
+
* verbatim: boolean, pair?: string}}
|
|
102
|
+
*/
|
|
103
|
+
function literalSpec(text, i, tok, dialect, depth) {
|
|
104
|
+
const single = (close, esc, multiline) => ({
|
|
105
|
+
from: i,
|
|
106
|
+
body: i + tok.length,
|
|
107
|
+
close: (j) => (text.startsWith(close, j) ? close.length : 0),
|
|
108
|
+
esc,
|
|
109
|
+
multiline,
|
|
110
|
+
hole: null,
|
|
111
|
+
verbatim: false,
|
|
112
|
+
});
|
|
113
|
+
const holeAt = (open, closer) => (j) =>
|
|
114
|
+
depth < HOLE_DEPTH_MAX && text.startsWith(open, j) ? { len: open.length, closer } : null;
|
|
115
|
+
|
|
116
|
+
if (dialect === "js") {
|
|
117
|
+
const s = single(tok, "\\", tok === "`");
|
|
118
|
+
if (tok === "`") s.hole = holeAt("${", "}");
|
|
119
|
+
return s;
|
|
120
|
+
}
|
|
121
|
+
if (dialect === "swift") {
|
|
122
|
+
const hashes = runBefore(text, i, "#");
|
|
123
|
+
const tail = "#".repeat(hashes);
|
|
124
|
+
const s = single(tok + tail, null, tok.length === 3);
|
|
125
|
+
s.from = i - hashes;
|
|
126
|
+
s.esc = `\\${tail}`;
|
|
127
|
+
s.hole = holeAt(`\\${tail}(`, ")");
|
|
128
|
+
return s;
|
|
129
|
+
}
|
|
130
|
+
if (dialect === "kotlin") {
|
|
131
|
+
const s = single(tok, tok.length === 3 ? null : "\\", tok.length === 3);
|
|
132
|
+
s.hole = holeAt("${", "}");
|
|
133
|
+
return s;
|
|
134
|
+
}
|
|
135
|
+
if (dialect === "rust" && tok === '"') {
|
|
136
|
+
const hashes = runBefore(text, i, "#");
|
|
137
|
+
const r = text[i - hashes - 1];
|
|
138
|
+
const before = text[i - hashes - 2];
|
|
139
|
+
if (r === "r" && !(isIdentChar(before) && before !== "b" && before !== "c")) {
|
|
140
|
+
const s = single(`"${"#".repeat(hashes)}`, null, true);
|
|
141
|
+
s.from = i - hashes - 1;
|
|
142
|
+
return s;
|
|
143
|
+
}
|
|
144
|
+
return single(tok, "\\", true);
|
|
145
|
+
}
|
|
146
|
+
if (dialect === "cpp" && tok === '"') {
|
|
147
|
+
let before = i - 2;
|
|
148
|
+
while (before >= 0 && before > i - 5 && "Lu8U".includes(text[before])) before--;
|
|
149
|
+
if (text[i - 1] === "R" && !isIdentChar(text[before])) {
|
|
150
|
+
const open = text.indexOf("(", i + 1);
|
|
151
|
+
if (open > 0 && open - i <= 17) {
|
|
152
|
+
const delim = text.slice(i + 1, open);
|
|
153
|
+
if (!/[\s)\\]/.test(delim)) {
|
|
154
|
+
const s = single(`)${delim}"`, null, true);
|
|
155
|
+
s.from = i - 1;
|
|
156
|
+
s.body = open + 1;
|
|
157
|
+
return s;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return single(tok, "\\", false);
|
|
162
|
+
}
|
|
163
|
+
if (dialect === "csharp" && tok === '"') {
|
|
164
|
+
const verbatim = text[i - 1] === "@" || (text[i - 1] === "$" && text[i - 2] === "@");
|
|
165
|
+
const interpolated = text[i - 1] === "$" || (text[i - 1] === "@" && text[i - 2] === "$");
|
|
166
|
+
const s = single(tok, verbatim ? null : "\\", verbatim);
|
|
167
|
+
s.from = i - (verbatim && interpolated ? 2 : verbatim || interpolated ? 1 : 0);
|
|
168
|
+
s.verbatim = verbatim;
|
|
169
|
+
if (verbatim) s.close = (j) => (text[j] === '"' && text[j + 1] !== '"' ? 1 : 0);
|
|
170
|
+
if (interpolated) {
|
|
171
|
+
s.pair = "{{";
|
|
172
|
+
s.hole = (j) => (depth < HOLE_DEPTH_MAX && text[j] === "{" ? { len: 1, closer: "}" } : null);
|
|
173
|
+
}
|
|
174
|
+
return s;
|
|
175
|
+
}
|
|
176
|
+
if (dialect === "python") {
|
|
177
|
+
let p = 0;
|
|
178
|
+
let f = false;
|
|
179
|
+
while (p < 3 && /[A-Za-z]/.test(text[i - p - 1] || "")) {
|
|
180
|
+
if (/[fF]/.test(text[i - p - 1])) f = true;
|
|
181
|
+
p++;
|
|
182
|
+
}
|
|
183
|
+
if (p && isIdentChar(text[i - p - 1])) {
|
|
184
|
+
p = 0;
|
|
185
|
+
f = false;
|
|
186
|
+
}
|
|
187
|
+
const s = single(tok, "\\", tok.length === 3);
|
|
188
|
+
s.from = i - p;
|
|
189
|
+
if (f) {
|
|
190
|
+
s.pair = "{{";
|
|
191
|
+
s.hole = (j) => (depth < HOLE_DEPTH_MAX && text[j] === "{" ? { len: 1, closer: "}" } : null);
|
|
192
|
+
}
|
|
193
|
+
return s;
|
|
194
|
+
}
|
|
195
|
+
if (dialect === "go" && tok === "`") return single(tok, null, true);
|
|
196
|
+
return single(tok, "\\", tok.length > 1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** A character literal such as `'"'` or `'\n'` at i in a dialect whose quotes list omits `'`. */
|
|
200
|
+
function charLiteralEnd(text, i) {
|
|
201
|
+
if (text[i + 1] === "\\") {
|
|
202
|
+
const end = text.indexOf("'", i + 3);
|
|
203
|
+
return end > 0 && end - i <= 12 ? end + 1 : -1;
|
|
204
|
+
}
|
|
205
|
+
const cp = text.codePointAt(i + 1);
|
|
206
|
+
const width = cp > 0xffff ? 2 : 1;
|
|
207
|
+
return text[i + 1 + width] === "'" ? i + width + 2 : -1;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Remove comments and string literals so they cannot produce phantom edges.
|
|
212
|
+
*
|
|
213
|
+
* @param {string} text - source text
|
|
214
|
+
* @param {object} comments - rules.comments: line, block, string, regex, dialect, nested
|
|
215
|
+
* @param {{stringFill?: string}} [options] - stringFill replaces the first character of each
|
|
216
|
+
* string literal, so a scanner that reads call arguments still sees that one was written.
|
|
217
|
+
* @returns {string} same length, comments and literal text blanked, interpolated code kept
|
|
218
|
+
*/
|
|
219
|
+
export function stripCode(text, comments = {}, options = {}) {
|
|
220
|
+
const line = comments.line || [];
|
|
221
|
+
const block = comments.block || [];
|
|
222
|
+
const quotes = comments.string || [];
|
|
223
|
+
const fill = options.stringFill || null;
|
|
224
|
+
const dialect = comments.dialect || (comments.regex === true ? "js" : "");
|
|
225
|
+
const nested = comments.nested === true;
|
|
226
|
+
const regexOn = dialect === "js";
|
|
227
|
+
const charLiterals = dialect === "rust" || dialect === "cpp";
|
|
228
|
+
const out = text.split("");
|
|
229
|
+
const n = text.length;
|
|
230
|
+
|
|
231
|
+
const starts = new Set([
|
|
232
|
+
...line.map((t) => t[0]),
|
|
233
|
+
...block.map(([open]) => open[0]),
|
|
234
|
+
...quotes.map((q) => q[0]),
|
|
235
|
+
...(regexOn ? ["/"] : []),
|
|
236
|
+
...(charLiterals ? ["'"] : []),
|
|
237
|
+
]);
|
|
238
|
+
|
|
239
|
+
const blank = (from, to) => {
|
|
240
|
+
for (let k = Math.max(from, 0); k < to && k < n; k++) {
|
|
241
|
+
if (out[k] !== "\n") out[k] = " ";
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const blockEnd = (i, open, close) => {
|
|
246
|
+
if (!nested) {
|
|
247
|
+
const end = text.indexOf(close, i + open.length);
|
|
248
|
+
return end === -1 ? n : end + close.length;
|
|
249
|
+
}
|
|
250
|
+
let depth = 1;
|
|
251
|
+
let j = i + open.length;
|
|
252
|
+
while (j < n && depth > 0) {
|
|
253
|
+
if (text.startsWith(open, j)) {
|
|
254
|
+
depth++;
|
|
255
|
+
j += open.length;
|
|
256
|
+
} else if (text.startsWith(close, j)) {
|
|
257
|
+
depth--;
|
|
258
|
+
j += close.length;
|
|
259
|
+
} else j++;
|
|
260
|
+
}
|
|
261
|
+
return j;
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
/** Read one literal; blank its text and keep what is inside its holes. */
|
|
265
|
+
const literal = (i, tok, depth) => {
|
|
266
|
+
const spec = literalSpec(text, i, tok, dialect, depth);
|
|
267
|
+
let j = spec.body;
|
|
268
|
+
let segment = spec.from;
|
|
269
|
+
while (j < n) {
|
|
270
|
+
if (spec.pair && text.startsWith(spec.pair, j)) {
|
|
271
|
+
j += spec.pair.length;
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const hole = spec.hole ? spec.hole(j) : null;
|
|
275
|
+
if (hole) {
|
|
276
|
+
blank(segment, j + hole.len);
|
|
277
|
+
const end = scan(j + hole.len, hole.closer, depth + 1);
|
|
278
|
+
segment = end;
|
|
279
|
+
j = end < n ? end + 1 : n;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
if (spec.esc && text.startsWith(spec.esc, j)) {
|
|
283
|
+
j += spec.esc.length + 1;
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (spec.verbatim && text[j] === '"' && text[j + 1] === '"') {
|
|
287
|
+
j += 2;
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
const closing = spec.close(j);
|
|
291
|
+
if (closing) {
|
|
292
|
+
j += closing;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
if (text[j] === "\n" && !spec.multiline) break;
|
|
296
|
+
j++;
|
|
297
|
+
}
|
|
298
|
+
j = Math.min(j, n);
|
|
299
|
+
blank(segment, j);
|
|
300
|
+
if (fill) out[spec.from] = fill;
|
|
301
|
+
return j;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Scan code from i. At a hole (`closer` set) stop at the bracket that closes it
|
|
306
|
+
* and return its index; at the top level run to the end of the text.
|
|
307
|
+
*/
|
|
308
|
+
const scan = (start, closer, depth) => {
|
|
309
|
+
const opener = closer === "}" ? "{" : closer === ")" ? "(" : null;
|
|
310
|
+
let level = 0;
|
|
311
|
+
let i = start;
|
|
312
|
+
while (i < n) {
|
|
313
|
+
const c = text[i];
|
|
314
|
+
if (closer !== null) {
|
|
315
|
+
if (c === opener) level++;
|
|
316
|
+
else if (c === closer) {
|
|
317
|
+
if (level === 0) {
|
|
318
|
+
blank(i, i + 1);
|
|
319
|
+
return i;
|
|
320
|
+
}
|
|
321
|
+
level--;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!starts.has(c)) {
|
|
325
|
+
i++;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const rest = text.slice(i, i + 8);
|
|
329
|
+
|
|
330
|
+
const lineTok = line.find((t) => rest.startsWith(t));
|
|
331
|
+
if (lineTok) {
|
|
332
|
+
let end = text.indexOf("\n", i);
|
|
333
|
+
if (end === -1) end = n;
|
|
334
|
+
blank(i, end);
|
|
335
|
+
i = end;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const blockTok = block.find(([open]) => rest.startsWith(open));
|
|
340
|
+
if (blockTok) {
|
|
341
|
+
const end = blockEnd(i, blockTok[0], blockTok[1]);
|
|
342
|
+
blank(i, end);
|
|
343
|
+
i = end;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
const quoteTok = quotes.find((q) => rest.startsWith(q));
|
|
348
|
+
if (quoteTok) {
|
|
349
|
+
i = literal(i, quoteTok, depth);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (regexOn && c === "/" && regexMayStart(text, i)) {
|
|
354
|
+
const end = regexEnd(text, i);
|
|
355
|
+
if (end > 0) {
|
|
356
|
+
blank(i, end);
|
|
357
|
+
if (fill) out[i] = "0";
|
|
358
|
+
i = end;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (charLiterals && c === "'") {
|
|
364
|
+
const end = charLiteralEnd(text, i);
|
|
365
|
+
if (end > 0) {
|
|
366
|
+
blank(i, end);
|
|
367
|
+
if (fill) out[i] = "0";
|
|
368
|
+
i = end;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
i++;
|
|
374
|
+
}
|
|
375
|
+
return n;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
scan(0, null, 0);
|
|
379
|
+
return out.join("");
|
|
380
|
+
}
|
|
@@ -78,11 +78,13 @@ import { buildIndex } from "./runs-index.mjs";
|
|
|
78
78
|
import { startedJobs } from "./job-launch.mjs";
|
|
79
79
|
import { createUsageCache, priceModels, sessionTranscripts } from "../lib/session-usage.mjs";
|
|
80
80
|
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
81
|
+
import { globalPref } from "../lib/prefs-value.mjs";
|
|
82
|
+
import { budgetConfig } from "./_cost-budget.mjs";
|
|
81
83
|
import { ArgsError, parseArgs as parseArgv } from "../lib/args.mjs";
|
|
82
84
|
|
|
83
85
|
exitOnHelp(import.meta.url);
|
|
84
86
|
|
|
85
|
-
export const CONTRACT_VERSION = "1.
|
|
87
|
+
export const CONTRACT_VERSION = "1.4.0";
|
|
86
88
|
export const RECENT_MS = 10 * 60_000;
|
|
87
89
|
|
|
88
90
|
export const ROLES = JSON.parse(
|
|
@@ -741,6 +743,11 @@ export async function activitySnapshot(opts = {}) {
|
|
|
741
743
|
corridors,
|
|
742
744
|
counts: { rooms: 0, tables: 0, seats: 0, live: 0, waiting: 0 },
|
|
743
745
|
};
|
|
746
|
+
const budget = budgetConfig(
|
|
747
|
+
opts.costBudget !== undefined ? opts.costBudget : globalPref("costBudget", null),
|
|
748
|
+
);
|
|
749
|
+
if (budget.enabled)
|
|
750
|
+
doc.costBudget = { maxUsd: budget.maxUsd, warnPct: budget.warnPct, onExceed: budget.onExceed };
|
|
744
751
|
for (const room of doc.rooms) {
|
|
745
752
|
doc.counts.rooms++;
|
|
746
753
|
for (const t of room.tables) {
|
|
@@ -943,6 +950,8 @@ function renderTable(team, clean, now) {
|
|
|
943
950
|
channels: [],
|
|
944
951
|
waitingFor: asking(seats) ? "terminal" : null,
|
|
945
952
|
waitingForYou: asking(seats),
|
|
953
|
+
waitingSince: null,
|
|
954
|
+
waitingSinceSource: null,
|
|
946
955
|
pendingQuestion: null,
|
|
947
956
|
tokens: team.usage?.tokens ?? null,
|
|
948
957
|
estUsd: team.usage?.estUsd ?? null,
|
|
@@ -998,6 +1007,9 @@ function renderTable(team, clean, now) {
|
|
|
998
1007
|
pr: Number.isInteger(run.prNumber) && run.prNumber > 0 ? { number: run.prNumber } : null,
|
|
999
1008
|
channels: Array.isArray(run.channels) ? run.channels.slice(0, 5) : [],
|
|
1000
1009
|
waitingFor,
|
|
1010
|
+
waitingSince: waitingFor && typeof run.waitingSince === "string" ? run.waitingSince : null,
|
|
1011
|
+
waitingSinceSource:
|
|
1012
|
+
waitingFor && typeof run.waitingSince === "string" ? (run.waitingSinceSource ?? null) : null,
|
|
1001
1013
|
host,
|
|
1002
1014
|
limited: host !== "claude",
|
|
1003
1015
|
sessionId: run.sessionId ?? first?.sessionId ?? null,
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
// node aggregate-metrics.mjs --since=2026-04-01 --json
|
|
23
23
|
// METRICS_FILE=/tmp/test.jsonl node aggregate-metrics.mjs
|
|
24
24
|
|
|
25
|
-
import {
|
|
25
|
+
import { readRotatedLines, rotatedExists } from "../lib/rotated-log.mjs";
|
|
26
26
|
import { homedir } from "node:os";
|
|
27
27
|
import { join } from "node:path";
|
|
28
28
|
|
|
@@ -51,7 +51,7 @@ for (const a of args) {
|
|
|
51
51
|
const METRICS_FILE =
|
|
52
52
|
process.env.METRICS_FILE || join(homedir(), ".claude", "logs", "multi-agent", "metrics.jsonl");
|
|
53
53
|
|
|
54
|
-
if (!
|
|
54
|
+
if (!rotatedExists(METRICS_FILE)) {
|
|
55
55
|
if (opts.json) {
|
|
56
56
|
console.log(
|
|
57
57
|
JSON.stringify({ ok: false, reason: "metrics file not found", path: METRICS_FILE }),
|
|
@@ -63,9 +63,7 @@ if (!existsSync(METRICS_FILE)) {
|
|
|
63
63
|
process.exit(0);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const lines =
|
|
67
|
-
.split("\n")
|
|
68
|
-
.filter((l) => l.trim());
|
|
66
|
+
const lines = readRotatedLines(METRICS_FILE);
|
|
69
67
|
const events = [];
|
|
70
68
|
let parseErrors = 0;
|
|
71
69
|
for (const line of lines) {
|
|
@@ -21,11 +21,6 @@
|
|
|
21
21
|
* A NOTICE file left in a plugin's knowledge/ by an earlier build is removed:
|
|
22
22
|
* the skills are written here and ship without attribution files.
|
|
23
23
|
*
|
|
24
|
-
* A skill renamed in pipeline/skills/renamed.json keeps its old name in the
|
|
25
|
-
* plugin as a one-file alias skill (see _renamed-skills.mjs), written into the
|
|
26
|
-
* plugin that carries the new name and declared in plugin.json beside it, so
|
|
27
|
-
* `/<plugin>:<old>` and references that still name the old skill keep working.
|
|
28
|
-
*
|
|
29
24
|
* Usage:
|
|
30
25
|
* node build-stack-plugins.mjs [--plugins-repo <path>] [--pipeline <path>] [--dry-run]
|
|
31
26
|
* node build-stack-plugins.mjs --check-routing
|
|
@@ -94,13 +89,6 @@ import {
|
|
|
94
89
|
STACK_ONLY,
|
|
95
90
|
STACK_PATTERNS,
|
|
96
91
|
} from "./_stack-routing.mjs";
|
|
97
|
-
import {
|
|
98
|
-
aliasSkillMarkdown,
|
|
99
|
-
aliasesFor,
|
|
100
|
-
isUserInvocableOff,
|
|
101
|
-
loadRenamed,
|
|
102
|
-
renamedProblems,
|
|
103
|
-
} from "./_renamed-skills.mjs";
|
|
104
92
|
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
105
93
|
|
|
106
94
|
exitOnHelp(import.meta.url);
|
|
@@ -155,8 +143,6 @@ if (!existsSync(EXTERNAL)) {
|
|
|
155
143
|
process.exit(args.includes("--check-routing") ? 1 : 0);
|
|
156
144
|
}
|
|
157
145
|
const allSkills = listDirs(EXTERNAL);
|
|
158
|
-
const renamed = loadRenamed(PIPE_ROOT);
|
|
159
|
-
const renameProblems = renamedProblems(renamed, new Set(allSkills), new Set(allSkills));
|
|
160
146
|
|
|
161
147
|
// --- 2. compute desired knowledge set per plugin -------------------------
|
|
162
148
|
const desired = { [COMMON_PLUGIN]: new Set(), [ANALYST_PLUGIN]: new Set() };
|
|
@@ -212,12 +198,6 @@ for (const skill of allSkills) {
|
|
|
212
198
|
if (owners.length > 1) multiRouted.push(`${skill} -> ${owners.join(" + ")}`);
|
|
213
199
|
}
|
|
214
200
|
|
|
215
|
-
if (renameProblems.length) {
|
|
216
|
-
console.error(`renamed.json: ${renameProblems.length} problem(s)`);
|
|
217
|
-
for (const p of renameProblems) console.error(` FAIL ${p}`);
|
|
218
|
-
process.exit(1);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
201
|
if (args.includes("--check-routing")) {
|
|
222
202
|
if (multiRouted.length) {
|
|
223
203
|
console.error(
|
|
@@ -248,17 +228,8 @@ for (const [plugin, want] of Object.entries(desired)) {
|
|
|
248
228
|
continue;
|
|
249
229
|
}
|
|
250
230
|
|
|
251
|
-
const aliases = new Map(
|
|
252
|
-
aliasesFor(renamed, want).map(([oldName, newName]) => [
|
|
253
|
-
oldName,
|
|
254
|
-
aliasSkillMarkdown(oldName, newName, {
|
|
255
|
-
removeIn: renamed.removeIn,
|
|
256
|
-
userInvocable: !isUserInvocableOff(join(EXTERNAL, newName, "SKILL.md")),
|
|
257
|
-
}),
|
|
258
|
-
]),
|
|
259
|
-
);
|
|
260
231
|
const have = new Set(listDirs(kdir));
|
|
261
|
-
const wanted = new Set(
|
|
232
|
+
const wanted = new Set(want);
|
|
262
233
|
const toAdd = [...wanted].filter((s) => !have.has(s)).sort();
|
|
263
234
|
const toRemove = [...have].filter((s) => !wanted.has(s)).sort();
|
|
264
235
|
const setChanged = toAdd.length > 0 || toRemove.length > 0;
|
|
@@ -282,21 +253,6 @@ for (const [plugin, want] of Object.entries(desired)) {
|
|
|
282
253
|
cpSync(from, to, { recursive: true });
|
|
283
254
|
}
|
|
284
255
|
}
|
|
285
|
-
for (const [oldName, text] of aliases) {
|
|
286
|
-
const to = join(kdir, oldName);
|
|
287
|
-
const current = existsSync(to) ? readdirSync(to) : [];
|
|
288
|
-
const same =
|
|
289
|
-
current.length === 1 &&
|
|
290
|
-
current[0] === "SKILL.md" &&
|
|
291
|
-
readFileSync(join(to, "SKILL.md"), "utf8") === text;
|
|
292
|
-
if (same) continue;
|
|
293
|
-
contentChanged = true;
|
|
294
|
-
if (!DRY) {
|
|
295
|
-
rmSync(to, { recursive: true, force: true });
|
|
296
|
-
mkdirSync(to, { recursive: true });
|
|
297
|
-
writeFileSync(join(to, "SKILL.md"), text);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
256
|
if (!DRY) {
|
|
301
257
|
for (const s of toRemove) rmSync(join(kdir, s), { recursive: true, force: true });
|
|
302
258
|
}
|
|
@@ -351,7 +307,6 @@ for (const [plugin, want] of Object.entries(desired)) {
|
|
|
351
307
|
plugin,
|
|
352
308
|
added: toAdd,
|
|
353
309
|
removed: toRemove,
|
|
354
|
-
aliases: [...aliases.keys()].sort(),
|
|
355
310
|
skillCount: newSkills.length,
|
|
356
311
|
version: oldV === newV ? oldV : `${oldV} → ${newV}`,
|
|
357
312
|
bumped: oldV !== newV,
|
|
@@ -371,7 +326,6 @@ for (const r of report) {
|
|
|
371
326
|
console.log(` ${r.plugin}: skills=${r.skillCount} version=${r.version} [${flag}]`);
|
|
372
327
|
if (r.added.length) console.log(` + ${r.added.join(", ")}`);
|
|
373
328
|
if (r.removed.length) console.log(` - ${r.removed.join(", ")}`);
|
|
374
|
-
if (r.aliases.length) console.log(` alias: ${r.aliases.join(", ")}`);
|
|
375
329
|
}
|
|
376
330
|
if (unrouted.length) {
|
|
377
331
|
console.log(` ⚠ unrouted (matched no stack, not common/apple-only) - NOT copied anywhere:`);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file index.mjs - per-file call facts and graph-wide call edges.
|
|
3
|
+
*
|
|
4
|
+
* `analyzeFile` runs once per file during extraction and returns JSON-safe
|
|
5
|
+
* facts: declared types and functions, imports, and for every function the
|
|
6
|
+
* call chains in its body. `addCallEdges` (resolve.mjs) joins those facts across
|
|
7
|
+
* files after every file has been read.
|
|
8
|
+
*
|
|
9
|
+
* @module pipeline/scripts/call-graph
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { BudgetError, refusal, tokenize } from "./lex.mjs";
|
|
13
|
+
import { scanBody } from "./scan.mjs";
|
|
14
|
+
import { profileForPath } from "./profiles.mjs";
|
|
15
|
+
|
|
16
|
+
export { addCallEdges } from "./resolve.mjs";
|
|
17
|
+
export { profileForPath, supportedExtensions } from "./profiles.mjs";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Call facts for one file, or null when the language is not covered or the file
|
|
21
|
+
* must not be analysed (too large, binary, minified, unbalanced, too many tokens).
|
|
22
|
+
*
|
|
23
|
+
* @param {string} raw - source text as read
|
|
24
|
+
* @param {(options: object) => string} strip - strips comments and string bodies; called only for a covered language
|
|
25
|
+
* @param {string} path - repo-relative path
|
|
26
|
+
* @param {{budgetMs?: number}} [options] - budgetMs overrides the per-file time budget
|
|
27
|
+
* @returns {{facts: object|null, skipped: string|null}}
|
|
28
|
+
*/
|
|
29
|
+
export function analyzeFile(raw, strip, path, { budgetMs } = {}) {
|
|
30
|
+
const profile = profileForPath(path);
|
|
31
|
+
if (!profile) return { facts: null, skipped: null };
|
|
32
|
+
const why = refusal(raw);
|
|
33
|
+
if (why) return { facts: null, skipped: why };
|
|
34
|
+
let text = strip({ stringFill: "\u0001" });
|
|
35
|
+
if (profile.prepare) text = profile.prepare(text);
|
|
36
|
+
const tk = tokenize(text, budgetMs);
|
|
37
|
+
if (tk.skipped) return { facts: null, skipped: tk.skipped };
|
|
38
|
+
let parsed;
|
|
39
|
+
let fns;
|
|
40
|
+
let binds;
|
|
41
|
+
let rx;
|
|
42
|
+
const top = [];
|
|
43
|
+
try {
|
|
44
|
+
parsed = profile.parse(tk, path);
|
|
45
|
+
fns = parsed.fns.map((f) => {
|
|
46
|
+
const { body, pr, ...rest } = f;
|
|
47
|
+
const ev = [
|
|
48
|
+
...(pr ? scanBody(tk, pr[0], pr[1], profile) : []),
|
|
49
|
+
...(body ? scanBody(tk, body[0], body[1], profile) : []),
|
|
50
|
+
];
|
|
51
|
+
return { ...rest, ...(ev.length ? { ev } : {}) };
|
|
52
|
+
});
|
|
53
|
+
binds = profile.binds
|
|
54
|
+
? profile.binds(profile.keepStrings ? strip({ keepStrings: true }) : text, path)
|
|
55
|
+
: parsed.binds || [];
|
|
56
|
+
for (const [from, to] of parsed.top || []) top.push(...scanBody(tk, from, to, profile));
|
|
57
|
+
rx = profile.reexports
|
|
58
|
+
? profile.reexports(profile.keepStrings ? strip({ keepStrings: true }) : text)
|
|
59
|
+
: [];
|
|
60
|
+
} catch (e) {
|
|
61
|
+
return { facts: null, skipped: e instanceof BudgetError ? "time-budget" : "parse-error" };
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
facts: {
|
|
65
|
+
lang: profile.id,
|
|
66
|
+
types: parsed.types,
|
|
67
|
+
fns,
|
|
68
|
+
binds,
|
|
69
|
+
...(parsed.gl && Object.keys(parsed.gl).length ? { gl: parsed.gl } : {}),
|
|
70
|
+
...(parsed.mods?.length ? { mods: parsed.mods } : {}),
|
|
71
|
+
...(parsed.vars?.length ? { vars: parsed.vars } : {}),
|
|
72
|
+
...(parsed.def ? { def: parsed.def } : {}),
|
|
73
|
+
...(rx.length ? { rx } : {}),
|
|
74
|
+
...(top.length ? { top } : {}),
|
|
75
|
+
},
|
|
76
|
+
skipped: null,
|
|
77
|
+
};
|
|
78
|
+
}
|