@mmerterden/multi-agent-pipeline 23.2.0 → 23.4.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 +50 -0
- package/README.md +25 -6
- package/README.tr.md +26 -7
- 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 +6 -6
- package/docs/performance.md +17 -17
- package/install/_dev-only-files.mjs +9 -0
- package/install/claude.mjs +28 -2
- package/install/templates/claude-hooks.json +32 -1
- package/manifest.json +229 -161
- package/package.json +11 -3
- package/pipeline/commands/multi-agent/SKILL.md +1 -1
- package/pipeline/commands/multi-agent/design-check/SKILL.md +2 -2
- package/pipeline/commands/multi-agent/diff-explain/SKILL.md +3 -3
- package/pipeline/commands/multi-agent/fable-status/SKILL.md +1 -1
- 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 +49 -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 +28 -15
- package/pipeline/contract/types/index.d.ts +55 -3
- package/pipeline/lib/detach-self.mjs +95 -0
- package/pipeline/lib/model-rung.sh +1 -1
- package/pipeline/lib/public-mcp-servers.mjs +33 -0
- package/pipeline/lib/rotated-log.mjs +93 -0
- package/pipeline/lib/tls-trust.mjs +29 -0
- package/pipeline/lib/usage-lifecycle.mjs +9 -11
- package/pipeline/lib/usage-names.generated.mjs +614 -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 +4 -4
- 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 +9 -7
- package/pipeline/multi-agent-refs/features/remote-control.md +252 -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 +252 -24
- 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/copilot-pipeline.md +1 -1
- package/pipeline/multi-agent-refs/orchestrator/dispatcher.md +1 -1
- 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 +5 -3
- 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/review/panel.md +1 -1
- package/pipeline/multi-agent-refs/wiki-capture.md +3 -17
- package/pipeline/office/index.html +1207 -233
- 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/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 +84 -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 +21 -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/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 +1 -0
- package/pipeline/scripts/cost-table.json +6 -5
- package/pipeline/scripts/feedback-send.mjs +26 -26
- package/pipeline/scripts/gate-ledger.mjs +2 -1
- 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/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 +317 -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 +188 -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/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 +22 -18
- 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-fable-status/SKILL.md +1 -1
- 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/publish-staged.mjs +0 -324
- package/pipeline/skills/shared/external/ios-coding-standard/scripts/check_structure.py +0 -765
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
* room for matches. --tier=<t> is the same flag; a name
|
|
39
39
|
* outside the three exits 64. Without --tier the output is
|
|
40
40
|
* the walk below, unchanged.
|
|
41
|
+
* --include <kinds> Also rank and walk these node kinds: doc, rationale, infra,
|
|
42
|
+
* env, config. By default a question is answered from code;
|
|
43
|
+
* documentation sections and configuration are reached by
|
|
44
|
+
* name, by --path, or with this flag.
|
|
45
|
+
* --seed <id|name,...> Start the walk at these nodes instead of the ranked seeds
|
|
46
|
+
* (an ambiguous name exits 3 with a request for the node id).
|
|
41
47
|
* --no-log Do not append this query to the query log
|
|
42
48
|
* --json Emit JSON instead of text
|
|
43
49
|
*
|
|
@@ -70,11 +76,20 @@
|
|
|
70
76
|
* with the candidates, never guessed; a name that matches
|
|
71
77
|
* none gets its nearest names.
|
|
72
78
|
*
|
|
79
|
+
* graph-query --callers <fn> | --callees <fn> [--depth N] [--min-confidence C]
|
|
80
|
+
* The functions that call fn, or that fn calls, to depth N
|
|
81
|
+
* (default 3, at most 15). Each row carries how the edge was
|
|
82
|
+
* derived and its confidence, and the weakest confidence on
|
|
83
|
+
* the chain to it. fn is a node id, a name, or Owner.name.
|
|
84
|
+
* --path prints the same confidence per hop and, as its
|
|
85
|
+
* last line, the weakest hop; of two routes of equal length
|
|
86
|
+
* it reports the one whose weakest hop is stronger.
|
|
87
|
+
*
|
|
73
88
|
* Exit codes:
|
|
74
89
|
* 0 - answered (possibly empty, or no path within the depth)
|
|
75
90
|
* 1 - graph missing or unreadable
|
|
76
91
|
* 2 - feedback for a query id the log does not hold
|
|
77
|
-
* 3 - a --path
|
|
92
|
+
* 3 - a --path, --seed, --callers or --callees reference is ambiguous or unknown
|
|
78
93
|
* 64 - usage error
|
|
79
94
|
*
|
|
80
95
|
* @module pipeline/scripts/graph-query
|
|
@@ -89,6 +104,9 @@ import { parseArgs } from "../lib/args.mjs";
|
|
|
89
104
|
import { exitOnHelp } from "../lib/cli-help.mjs";
|
|
90
105
|
import { TIER_NAMES, fitToBudget, tierChars, tierNote } from "../lib/tiered-budget.mjs";
|
|
91
106
|
import { clusters } from "./_graph-analysis.mjs";
|
|
107
|
+
import { attachSidecars, layersOfKinds, notesFor } from "./_graph-sidecars.mjs";
|
|
108
|
+
import { listCandidateFiles } from "./_code-graph.mjs";
|
|
109
|
+
import { addedInputs } from "./infra/graph.mjs";
|
|
92
110
|
|
|
93
111
|
exitOnHelp(import.meta.url);
|
|
94
112
|
|
|
@@ -110,6 +128,19 @@ function headerQuestion(question) {
|
|
|
110
128
|
const cut = question.slice(0, HEADER_QUESTION_MAX).trimEnd();
|
|
111
129
|
return `${cut} [+${question.length - cut.length} chars]`;
|
|
112
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Symbol kinds the call analysis adds. They are reached by name through
|
|
133
|
+
* graph_node, `--path` and the call walks, but they take no part in free-text
|
|
134
|
+
* ranking: a method name is shared by dozens of unrelated types, and ranking
|
|
135
|
+
* them would push the type a task names out of its seed slots.
|
|
136
|
+
*/
|
|
137
|
+
const NON_CODE_KINDS = new Set(["doc", "rationale", "infra", "env", "config"]);
|
|
138
|
+
const NON_CODE_ID = /^(?:doc|rationale|infra|env|config):/;
|
|
139
|
+
const NON_CODE_EDGES = new Set(["mentions", "explains", "reads", "sets", "uses", "builds", "runs"]);
|
|
140
|
+
const CONFIDENCE_RANK = { low: 1, medium: 2, high: 3, certain: 4 };
|
|
141
|
+
const CONFIDENCE_NAMES = ["", "low", "medium", "high", "certain"];
|
|
142
|
+
const DEFAULT_MIN_CONFIDENCE = "medium";
|
|
143
|
+
const NO_KINDS = new Set();
|
|
113
144
|
const MAX_EXPAND = 12;
|
|
114
145
|
const MAX_LIKE = 50;
|
|
115
146
|
const LIKE_DISTANCE = 2;
|
|
@@ -128,7 +159,14 @@ export function loadGraph(path) {
|
|
|
128
159
|
if (!Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
|
|
129
160
|
throw new Error(`graph is malformed: ${path}`);
|
|
130
161
|
}
|
|
131
|
-
|
|
162
|
+
let candidates = null;
|
|
163
|
+
return attachSidecars(graph, path, {
|
|
164
|
+
addedPaths: (name, side) => {
|
|
165
|
+
if (!graph.root || !side.manifest) return [];
|
|
166
|
+
candidates ||= listCandidateFiles(graph.root);
|
|
167
|
+
return addedInputs(name, candidates, side.manifest);
|
|
168
|
+
},
|
|
169
|
+
});
|
|
132
170
|
}
|
|
133
171
|
|
|
134
172
|
/**
|
|
@@ -137,18 +175,32 @@ export function loadGraph(path) {
|
|
|
137
175
|
* Traversal has to cross an edge either way: a task naming a base class must
|
|
138
176
|
* reach its subclasses (incoming) as readily as its own file (outgoing).
|
|
139
177
|
*
|
|
178
|
+
* `calls` edges and the edges of infrastructure, configuration and documentation
|
|
179
|
+
* nodes are left out of the free-text traversal and the tier sections
|
|
180
|
+
* (`calls: false, infra: false`): that traversal is tuned against a graded
|
|
181
|
+
* question set and a method-level edge or a documentation section floods it
|
|
182
|
+
* with neighbours. Path search, `--callers` and `--callees` walk them all.
|
|
183
|
+
*
|
|
140
184
|
* @param {object} graph
|
|
185
|
+
* @param {{calls?: boolean}} [opts]
|
|
141
186
|
* @returns {Map<string, Array<{id: string, kind: string, dir: string}>>}
|
|
142
187
|
*/
|
|
143
|
-
export function adjacency(graph) {
|
|
188
|
+
export function adjacency(graph, { calls = true, infra = true } = {}) {
|
|
144
189
|
const adj = new Map();
|
|
145
|
-
const push = (from, to, kind, dir) => {
|
|
190
|
+
const push = (from, to, kind, dir, conf) => {
|
|
146
191
|
if (!adj.has(from)) adj.set(from, []);
|
|
147
|
-
adj.get(from).push({ id: to, kind, dir });
|
|
192
|
+
adj.get(from).push({ id: to, kind, dir, conf });
|
|
148
193
|
};
|
|
149
194
|
for (const e of graph.edges) {
|
|
150
|
-
|
|
151
|
-
|
|
195
|
+
if (!calls && e.kind === "calls") continue;
|
|
196
|
+
if (
|
|
197
|
+
!infra &&
|
|
198
|
+
(NON_CODE_EDGES.has(e.kind) || NON_CODE_ID.test(e.to) || NON_CODE_ID.test(e.from))
|
|
199
|
+
)
|
|
200
|
+
continue;
|
|
201
|
+
const conf = e.confidence || "certain";
|
|
202
|
+
push(e.from, e.to, e.kind, "out", conf);
|
|
203
|
+
push(e.to, e.from, e.kind, "in", conf);
|
|
152
204
|
}
|
|
153
205
|
return adj;
|
|
154
206
|
}
|
|
@@ -169,8 +221,15 @@ export function adjacency(graph) {
|
|
|
169
221
|
* @param {{expand?: string[], standing?: Map<string, {corroborated: boolean, suppressed: boolean}>}} [opts]
|
|
170
222
|
* @returns {Array<{node: object, score: number}>} descending, zero scores dropped
|
|
171
223
|
*/
|
|
172
|
-
export function rankNodes(
|
|
173
|
-
|
|
224
|
+
export function rankNodes(
|
|
225
|
+
graph,
|
|
226
|
+
question,
|
|
227
|
+
{ expand = [], standing: byNode = null, include = NO_KINDS } = {},
|
|
228
|
+
) {
|
|
229
|
+
const pool = graph.nodes.filter(
|
|
230
|
+
(n) => n.layer !== "calls" && (!NON_CODE_KINDS.has(n.kind) || include.has(n.kind)),
|
|
231
|
+
);
|
|
232
|
+
const docs = pool.map((n) => ({
|
|
174
233
|
name: n.name || "",
|
|
175
234
|
path: n.path || "",
|
|
176
235
|
symbolKind: n.symbolKind || "",
|
|
@@ -185,9 +244,9 @@ export function rankNodes(graph, question, { expand = [], standing: byNode = nul
|
|
|
185
244
|
};
|
|
186
245
|
return scored
|
|
187
246
|
.filter((s) => s.score > 0)
|
|
188
|
-
.map((s) => ({ index: s.index, score: s.score * factor(
|
|
247
|
+
.map((s) => ({ index: s.index, score: s.score * factor(pool[s.index].id) }))
|
|
189
248
|
.sort((a, b) => b.score - a.score || a.index - b.index)
|
|
190
|
-
.map((s) => ({ node:
|
|
249
|
+
.map((s) => ({ node: pool[s.index], score: s.score }));
|
|
191
250
|
}
|
|
192
251
|
|
|
193
252
|
/** Words of an identifier: camelCase, snake_case, kebab-case and digits split. */
|
|
@@ -349,6 +408,9 @@ export function resolveNode(graph, ref) {
|
|
|
349
408
|
const byId = graph.nodes.find((n) => n.id === ref);
|
|
350
409
|
if (byId) return { node: byId };
|
|
351
410
|
let matches = graph.nodes.filter((n) => n.name === ref);
|
|
411
|
+
if (!matches.length && String(ref).includes(".")) {
|
|
412
|
+
matches = graph.nodes.filter((n) => n.owner && `${n.owner}.${n.name}` === ref);
|
|
413
|
+
}
|
|
352
414
|
if (!matches.length) {
|
|
353
415
|
const lower = String(ref).toLowerCase();
|
|
354
416
|
matches = graph.nodes.filter((n) => (n.name || "").toLowerCase() === lower);
|
|
@@ -373,11 +435,14 @@ export function shortestPath(
|
|
|
373
435
|
graph,
|
|
374
436
|
fromId,
|
|
375
437
|
toId,
|
|
376
|
-
{ maxDepth = 8, directed = false, kinds = null } = {},
|
|
438
|
+
{ maxDepth = 8, directed = false, kinds = null, minConfidence = DEFAULT_MIN_CONFIDENCE } = {},
|
|
377
439
|
) {
|
|
440
|
+
const floorRank = CONFIDENCE_RANK[minConfidence] ?? CONFIDENCE_RANK[DEFAULT_MIN_CONFIDENCE];
|
|
378
441
|
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
379
442
|
const adj = adjacency(graph);
|
|
380
443
|
const prev = new Map([[fromId, null]]);
|
|
444
|
+
const weakest = new Map([[fromId, CONFIDENCE_RANK.certain]]);
|
|
445
|
+
const level = new Map([[fromId, 0]]);
|
|
381
446
|
let frontier = [fromId];
|
|
382
447
|
for (let d = 0; d < maxDepth && frontier.length && !prev.has(toId); d++) {
|
|
383
448
|
const next = [];
|
|
@@ -385,8 +450,19 @@ export function shortestPath(
|
|
|
385
450
|
for (const n of adj.get(id) || []) {
|
|
386
451
|
if (directed && n.dir !== "out") continue;
|
|
387
452
|
if (kinds && !kinds.includes(n.kind)) continue;
|
|
388
|
-
if (
|
|
389
|
-
|
|
453
|
+
if ((CONFIDENCE_RANK[n.conf] ?? CONFIDENCE_RANK.certain) < floorRank) continue;
|
|
454
|
+
const rank = Math.min(weakest.get(id), CONFIDENCE_RANK[n.conf] ?? CONFIDENCE_RANK.certain);
|
|
455
|
+
if (prev.has(n.id)) {
|
|
456
|
+
// Among routes of equal length the one whose weakest hop is strongest wins.
|
|
457
|
+
if (level.get(n.id) === d + 1 && rank > weakest.get(n.id)) {
|
|
458
|
+
prev.set(n.id, { from: id, via: `${n.kind}/${n.dir}`, conf: n.conf });
|
|
459
|
+
weakest.set(n.id, rank);
|
|
460
|
+
}
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
prev.set(n.id, { from: id, via: `${n.kind}/${n.dir}`, conf: n.conf });
|
|
464
|
+
weakest.set(n.id, rank);
|
|
465
|
+
level.set(n.id, d + 1);
|
|
390
466
|
// An external module joins every file that imports it, so it ends a
|
|
391
467
|
// path but is never walked through.
|
|
392
468
|
if (byId.get(n.id)?.kind !== "module" || n.id === toId) next.push(n.id);
|
|
@@ -397,9 +473,14 @@ export function shortestPath(
|
|
|
397
473
|
if (!prev.has(toId)) return { path: null };
|
|
398
474
|
const path = [];
|
|
399
475
|
for (let id = toId; id !== null; id = prev.get(id)?.from ?? null) {
|
|
400
|
-
path.unshift({
|
|
476
|
+
path.unshift({
|
|
477
|
+
node: byId.get(id),
|
|
478
|
+
via: prev.get(id)?.via ?? null,
|
|
479
|
+
confidence: prev.get(id)?.conf ?? null,
|
|
480
|
+
});
|
|
401
481
|
}
|
|
402
|
-
|
|
482
|
+
const floor = weakest.get(toId);
|
|
483
|
+
return { path, confidence: CONFIDENCE_NAMES[floor] };
|
|
403
484
|
}
|
|
404
485
|
|
|
405
486
|
function renderNode(node) {
|
|
@@ -434,13 +515,15 @@ export function traverse({
|
|
|
434
515
|
budget,
|
|
435
516
|
depth,
|
|
436
517
|
seedCount,
|
|
518
|
+
seedNodes = null,
|
|
519
|
+
include = NO_KINDS,
|
|
437
520
|
expand = [],
|
|
438
521
|
standing: byNode = null,
|
|
439
522
|
}) {
|
|
440
|
-
const ranked = rankNodes(graph, question, { expand, standing: byNode });
|
|
441
|
-
const seeds = ranked.slice(0, seedCount).map((r) => r.node);
|
|
523
|
+
const ranked = rankNodes(graph, question, { expand, standing: byNode, include });
|
|
524
|
+
const seeds = seedNodes ?? ranked.slice(0, seedCount).map((r) => r.node);
|
|
442
525
|
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
443
|
-
const adj = adjacency(graph);
|
|
526
|
+
const adj = adjacency(graph, { calls: false, infra: include.size > 0 });
|
|
444
527
|
|
|
445
528
|
const seen = new Set(seeds.map((n) => n.id));
|
|
446
529
|
const hits = [];
|
|
@@ -505,7 +588,7 @@ function fileOfNode(graph, node) {
|
|
|
505
588
|
|
|
506
589
|
function neighbourRows(graph, seeds, maxDepth, cap) {
|
|
507
590
|
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
508
|
-
const adj = adjacency(graph);
|
|
591
|
+
const adj = adjacency(graph, { calls: false, infra: false });
|
|
509
592
|
const seen = new Set(seeds.map((n) => n.id));
|
|
510
593
|
const rows = [];
|
|
511
594
|
let frontier = seeds.map((n) => ({ node: n, from: n }));
|
|
@@ -636,6 +719,12 @@ export function tieredGraphQuery({ graph, question, tier, expand = [], standing:
|
|
|
636
719
|
return { tier, maxChars, text, dropped, kept: items.length - dropped.length, seeds };
|
|
637
720
|
}
|
|
638
721
|
|
|
722
|
+
/** Node kinds the free-text query is asked to rank and walk besides code (--include doc,infra,...). */
|
|
723
|
+
function includeKinds(flags) {
|
|
724
|
+
if (typeof flags.include !== "string") return NO_KINDS;
|
|
725
|
+
return new Set(flags.include.split(",").filter((k) => NON_CODE_KINDS.has(k)));
|
|
726
|
+
}
|
|
727
|
+
|
|
639
728
|
function pathMain(flags, positional, graph) {
|
|
640
729
|
if (positional.length !== 2) {
|
|
641
730
|
process.stderr.write(
|
|
@@ -661,24 +750,179 @@ function pathMain(flags, positional, graph) {
|
|
|
661
750
|
}
|
|
662
751
|
const maxDepth = Math.min(Number(flags["max-depth"]) > 0 ? Number(flags["max-depth"]) : 8, 12);
|
|
663
752
|
const kinds = typeof flags.kind === "string" ? flags.kind.split(",") : null;
|
|
664
|
-
const
|
|
753
|
+
const minConfidence = CONFIDENCE_RANK[flags["min-confidence"]]
|
|
754
|
+
? flags["min-confidence"]
|
|
755
|
+
: DEFAULT_MIN_CONFIDENCE;
|
|
756
|
+
const { path, confidence } = shortestPath(graph, ends[0].node.id, ends[1].node.id, {
|
|
665
757
|
maxDepth,
|
|
666
758
|
directed: flags.directed === true,
|
|
667
759
|
kinds,
|
|
760
|
+
minConfidence,
|
|
668
761
|
});
|
|
669
762
|
if (flags.json === true) {
|
|
670
763
|
const hops =
|
|
671
|
-
path?.map((h) => ({
|
|
764
|
+
path?.map((h) => ({
|
|
765
|
+
id: h.node.id,
|
|
766
|
+
line: renderNode(h.node),
|
|
767
|
+
via: h.via,
|
|
768
|
+
confidence: h.confidence,
|
|
769
|
+
})) ?? null;
|
|
672
770
|
process.stdout.write(
|
|
673
|
-
JSON.stringify(
|
|
771
|
+
JSON.stringify(
|
|
772
|
+
{
|
|
773
|
+
from: ends[0].node.id,
|
|
774
|
+
to: ends[1].node.id,
|
|
775
|
+
path: hops,
|
|
776
|
+
confidence: confidence ?? null,
|
|
777
|
+
minConfidence,
|
|
778
|
+
...(notesFor(graph, ["calls"]).length ? { notes: notesFor(graph, ["calls"]) } : {}),
|
|
779
|
+
},
|
|
780
|
+
null,
|
|
781
|
+
2,
|
|
782
|
+
) + "\n",
|
|
674
783
|
);
|
|
675
784
|
return 0;
|
|
676
785
|
}
|
|
786
|
+
const pathNotes = notesFor(graph, ["calls"]);
|
|
677
787
|
if (!path) {
|
|
678
|
-
process.stdout.write(
|
|
788
|
+
process.stdout.write(
|
|
789
|
+
`no path within ${maxDepth} hops (edges below ${minConfidence} confidence skipped)\n`,
|
|
790
|
+
);
|
|
791
|
+
for (const n of pathNotes) process.stdout.write(`note: ${n}\n`);
|
|
679
792
|
return 0;
|
|
680
793
|
}
|
|
681
|
-
path.forEach((h, i) =>
|
|
794
|
+
path.forEach((h, i) =>
|
|
795
|
+
process.stdout.write(
|
|
796
|
+
`${printedLine(i, renderNode(h.node), h.via ? `${h.via}${h.confidence && h.confidence !== "certain" ? ` ${h.confidence}` : ""}` : null)}\n`,
|
|
797
|
+
),
|
|
798
|
+
);
|
|
799
|
+
process.stdout.write(`path confidence: ${confidence} (its weakest hop)\n`);
|
|
800
|
+
if (minConfidence !== "low")
|
|
801
|
+
process.stdout.write(
|
|
802
|
+
`edges below ${minConfidence} confidence are skipped; --min-confidence low adds leads\n`,
|
|
803
|
+
);
|
|
804
|
+
for (const n of pathNotes) process.stdout.write(`note: ${n}\n`);
|
|
805
|
+
return 0;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* Walk the call graph from one function: its callers (`up`) or what it calls
|
|
810
|
+
* (`down`), breadth first, to a depth, with the weakest confidence on the way.
|
|
811
|
+
*
|
|
812
|
+
* @param {object} graph
|
|
813
|
+
* @param {string} startId
|
|
814
|
+
* @param {{direction: "callers"|"callees", depth: number, min: string}} opts
|
|
815
|
+
* @returns {Array<{node: object, dist: number, via: string, confidence: string, weakest: string}>}
|
|
816
|
+
*/
|
|
817
|
+
export function callWalk(graph, startId, { direction, depth, min = "low" }) {
|
|
818
|
+
const byId = new Map(graph.nodes.map((n) => [n.id, n]));
|
|
819
|
+
const next = new Map();
|
|
820
|
+
for (const e of graph.edges) {
|
|
821
|
+
if (e.kind !== "calls") continue;
|
|
822
|
+
const rank = CONFIDENCE_RANK[e.confidence] ?? CONFIDENCE_RANK.certain;
|
|
823
|
+
if (rank < CONFIDENCE_RANK[min]) continue;
|
|
824
|
+
const [a, b] = direction === "callers" ? [e.to, e.from] : [e.from, e.to];
|
|
825
|
+
if (!next.has(a)) next.set(a, []);
|
|
826
|
+
next.get(a).push({ id: b, via: e.via, rank });
|
|
827
|
+
}
|
|
828
|
+
const seen = new Map([[startId, CONFIDENCE_RANK.certain]]);
|
|
829
|
+
const out = [];
|
|
830
|
+
let frontier = [startId];
|
|
831
|
+
for (let d = 1; d <= depth && frontier.length; d++) {
|
|
832
|
+
const layer = [];
|
|
833
|
+
for (const id of frontier) {
|
|
834
|
+
for (const n of next.get(id) || []) {
|
|
835
|
+
const floor = Math.min(seen.get(id), n.rank);
|
|
836
|
+
if (seen.has(n.id)) continue;
|
|
837
|
+
seen.set(n.id, floor);
|
|
838
|
+
const node = byId.get(n.id);
|
|
839
|
+
if (!node) continue;
|
|
840
|
+
out.push({
|
|
841
|
+
node,
|
|
842
|
+
dist: d,
|
|
843
|
+
via: n.via,
|
|
844
|
+
confidence: CONFIDENCE_NAMES[n.rank],
|
|
845
|
+
weakest: CONFIDENCE_NAMES[floor],
|
|
846
|
+
});
|
|
847
|
+
layer.push(n.id);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
frontier = layer;
|
|
851
|
+
}
|
|
852
|
+
return out;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
function callsMain(flags, graph) {
|
|
856
|
+
const direction = typeof flags.callers === "string" ? "callers" : "callees";
|
|
857
|
+
const ref = String(flags.callers ?? flags.callees);
|
|
858
|
+
const found = resolveNode(graph, ref);
|
|
859
|
+
if (!found.node) {
|
|
860
|
+
const doc = found.ambiguous || found.unknown || [];
|
|
861
|
+
if (flags.json === true) {
|
|
862
|
+
process.stdout.write(
|
|
863
|
+
JSON.stringify(
|
|
864
|
+
{
|
|
865
|
+
refused: [
|
|
866
|
+
{
|
|
867
|
+
ref,
|
|
868
|
+
reason: found.ambiguous ? "ambiguous" : "unknown",
|
|
869
|
+
candidates: doc.map((n) => ({ id: n.id, line: renderNode(n) })),
|
|
870
|
+
},
|
|
871
|
+
],
|
|
872
|
+
},
|
|
873
|
+
null,
|
|
874
|
+
2,
|
|
875
|
+
) + "\n",
|
|
876
|
+
);
|
|
877
|
+
} else {
|
|
878
|
+
process.stdout.write(
|
|
879
|
+
`${ref}: ${found.ambiguous ? "ambiguous" : "unknown"}; pass one of these ids:\n`,
|
|
880
|
+
);
|
|
881
|
+
for (const n of doc) process.stdout.write(` ${n.id} ${renderNode(n)}\n`);
|
|
882
|
+
}
|
|
883
|
+
return 3;
|
|
884
|
+
}
|
|
885
|
+
const depth = Math.min(Number(flags.depth) > 0 ? Number(flags.depth) : 3, 15);
|
|
886
|
+
const min = CONFIDENCE_RANK[flags["min-confidence"]]
|
|
887
|
+
? flags["min-confidence"]
|
|
888
|
+
: DEFAULT_MIN_CONFIDENCE;
|
|
889
|
+
const rows = callWalk(graph, found.node.id, { direction, depth, min });
|
|
890
|
+
if (flags.json === true) {
|
|
891
|
+
process.stdout.write(
|
|
892
|
+
JSON.stringify(
|
|
893
|
+
{
|
|
894
|
+
[direction === "callers" ? "callee" : "caller"]: found.node.id,
|
|
895
|
+
depth,
|
|
896
|
+
minConfidence: min,
|
|
897
|
+
...(notesFor(graph, ["calls"]).length ? { notes: notesFor(graph, ["calls"]) } : {}),
|
|
898
|
+
results: rows.map((r) => ({
|
|
899
|
+
id: r.node.id,
|
|
900
|
+
line: renderNode(r.node),
|
|
901
|
+
dist: r.dist,
|
|
902
|
+
via: r.via,
|
|
903
|
+
confidence: r.confidence,
|
|
904
|
+
weakest: r.weakest,
|
|
905
|
+
})),
|
|
906
|
+
},
|
|
907
|
+
null,
|
|
908
|
+
2,
|
|
909
|
+
) + "\n",
|
|
910
|
+
);
|
|
911
|
+
return 0;
|
|
912
|
+
}
|
|
913
|
+
process.stdout.write(`# ${direction} of ${renderNode(found.node)}\n\n`);
|
|
914
|
+
if (!rows.length) process.stdout.write("none\n");
|
|
915
|
+
for (const r of rows) {
|
|
916
|
+
const lead = r.confidence === "low" ? " (lead: unresolved binding)" : "";
|
|
917
|
+
process.stdout.write(
|
|
918
|
+
`${printedLine(r.dist, renderNode(r.node), `${r.via} ${r.confidence}${r.weakest !== r.confidence ? `, chain ${r.weakest}` : ""}${lead}`)}\n`,
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
if (min !== "low")
|
|
922
|
+
process.stdout.write(
|
|
923
|
+
`edges below ${min} confidence are not listed; --min-confidence low adds leads\n`,
|
|
924
|
+
);
|
|
925
|
+
for (const n of notesFor(graph, ["calls"])) process.stdout.write(`note: ${n}\n`);
|
|
682
926
|
return 0;
|
|
683
927
|
}
|
|
684
928
|
|
|
@@ -698,6 +942,16 @@ function main() {
|
|
|
698
942
|
process.exit(pathMain(flags, ends, graph));
|
|
699
943
|
}
|
|
700
944
|
const path = flags.graph && flags.graph !== true ? resolve(flags.graph) : defaultGraphPath();
|
|
945
|
+
if (typeof flags.callers === "string" || typeof flags.callees === "string") {
|
|
946
|
+
let graph;
|
|
947
|
+
try {
|
|
948
|
+
graph = loadGraph(path);
|
|
949
|
+
} catch (e) {
|
|
950
|
+
process.stderr.write(`graph-query: ${e.message}\n`);
|
|
951
|
+
process.exit(1);
|
|
952
|
+
}
|
|
953
|
+
process.exit(callsMain(flags, graph));
|
|
954
|
+
}
|
|
701
955
|
if (positional.length === 1 && positional[0] === "feedback")
|
|
702
956
|
process.exit(feedbackMain(flags, path));
|
|
703
957
|
const question = positional.join(" ").trim();
|
|
@@ -725,20 +979,43 @@ function main() {
|
|
|
725
979
|
const expansion =
|
|
726
980
|
typeof flags.expand === "string" ? expandTerms(vocabulary(graph), flags.expand) : null;
|
|
727
981
|
|
|
982
|
+
let seedNodes = null;
|
|
983
|
+
if (typeof flags.seed === "string") {
|
|
984
|
+
seedNodes = [];
|
|
985
|
+
for (const ref of flags.seed.split(",").filter(Boolean)) {
|
|
986
|
+
const r = resolveNode(graph, ref.trim());
|
|
987
|
+
if (!r.node) {
|
|
988
|
+
process.stderr.write(
|
|
989
|
+
`graph-query: --seed ${ref}: ${r.ambiguous ? "ambiguous, pass a node id" : "no such node"}\n`,
|
|
990
|
+
);
|
|
991
|
+
process.exit(3);
|
|
992
|
+
}
|
|
993
|
+
seedNodes.push(r.node);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
728
997
|
const result = traverse({
|
|
729
998
|
graph,
|
|
730
999
|
question,
|
|
731
1000
|
budget,
|
|
732
1001
|
depth,
|
|
733
1002
|
seedCount,
|
|
1003
|
+
seedNodes,
|
|
1004
|
+
include: includeKinds(flags),
|
|
734
1005
|
expand: expansion?.used ?? [],
|
|
735
1006
|
standing: standingByNode(path),
|
|
736
1007
|
});
|
|
737
1008
|
|
|
738
1009
|
const logId = logQuery(flags, path, question, expansion, result.seeds);
|
|
1010
|
+
const queryNotes = notesFor(graph, layersOfKinds(includeKinds(flags)));
|
|
739
1011
|
|
|
740
1012
|
if (flags.json === true) {
|
|
741
|
-
const doc = {
|
|
1013
|
+
const doc = {
|
|
1014
|
+
question,
|
|
1015
|
+
budget,
|
|
1016
|
+
...result,
|
|
1017
|
+
...(queryNotes.length ? { notes: queryNotes } : {}),
|
|
1018
|
+
};
|
|
742
1019
|
if (expansion) doc.expansion = expansion;
|
|
743
1020
|
if (logId) doc.logId = logId;
|
|
744
1021
|
process.stdout.write(JSON.stringify(doc, null, 2) + "\n");
|
|
@@ -760,6 +1037,7 @@ function main() {
|
|
|
760
1037
|
}
|
|
761
1038
|
if (result.hits.length === 0) {
|
|
762
1039
|
process.stdout.write("no matching nodes\n");
|
|
1040
|
+
for (const n of queryNotes) process.stdout.write(`note: ${n}\n`);
|
|
763
1041
|
return;
|
|
764
1042
|
}
|
|
765
1043
|
for (const hit of result.hits) {
|
|
@@ -773,6 +1051,7 @@ function main() {
|
|
|
773
1051
|
: "") +
|
|
774
1052
|
"\n",
|
|
775
1053
|
);
|
|
1054
|
+
for (const n of queryNotes) process.stdout.write(`note: ${n}\n`);
|
|
776
1055
|
}
|
|
777
1056
|
|
|
778
1057
|
/** Append a free-text query to the log beside the graph; its id, or null when not logged. */
|