@flyingrobots/graft 0.7.0 → 0.7.1
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 +13 -0
- package/README.md +0 -1
- package/bin/graft.js +26 -26
- package/dist/cli/init-client-config.d.ts.map +1 -1
- package/dist/cli/init-client-config.js +40 -4
- package/dist/cli/init-client-config.js.map +1 -1
- package/dist/cli/init-model.js +2 -2
- package/dist/cli/init-model.js.map +1 -1
- package/dist/cli/json-document.d.ts +1 -0
- package/dist/cli/json-document.d.ts.map +1 -1
- package/dist/cli/json-document.js +3 -0
- package/dist/cli/json-document.js.map +1 -1
- package/dist/hooks/posttooluse-read.js +1 -1
- package/dist/hooks/posttooluse-read.js.map +1 -1
- package/dist/hooks/pretooluse-read.js +1 -1
- package/dist/hooks/pretooluse-read.js.map +1 -1
- package/dist/mcp/daemon-worker-child-pool.d.ts +2 -0
- package/dist/mcp/daemon-worker-child-pool.d.ts.map +1 -1
- package/dist/mcp/daemon-worker-child-pool.js +10 -3
- package/dist/mcp/daemon-worker-child-pool.js.map +1 -1
- package/dist/mcp/daemon-worker-pool.d.ts +1 -1
- package/dist/mcp/daemon-worker-pool.d.ts.map +1 -1
- package/dist/mcp/daemon-worker-pool.js +1 -1
- package/dist/mcp/daemon-worker-pool.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +3 -1
- package/dist/version.js.map +1 -1
- package/docs/SETUP.md +11 -7
- package/package.json +9 -4
- package/src/adapters/canonical-json.ts +0 -56
- package/src/adapters/json-text-decoder.ts +0 -11
- package/src/adapters/node-fs.ts +0 -43
- package/src/adapters/node-git.ts +0 -47
- package/src/adapters/node-paths.ts +0 -35
- package/src/adapters/node-process-runner.ts +0 -27
- package/src/adapters/repo-paths.ts +0 -63
- package/src/adapters/rotating-ndjson-log.ts +0 -66
- package/src/api/index.ts +0 -107
- package/src/api/repo-local-graft.ts +0 -21
- package/src/api/repo-workspace.ts +0 -34
- package/src/api/tool-bridge.ts +0 -22
- package/src/cli/activity-render.ts +0 -112
- package/src/cli/cli-error.ts +0 -192
- package/src/cli/command-parser.ts +0 -484
- package/src/cli/daemon-status-model.ts +0 -238
- package/src/cli/daemon-status-render.ts +0 -102
- package/src/cli/daemon-status.ts +0 -100
- package/src/cli/entrypoint.ts +0 -18
- package/src/cli/git-graft-enhance-model.ts +0 -131
- package/src/cli/git-graft-enhance-render.ts +0 -33
- package/src/cli/git-graft-enhance.ts +0 -54
- package/src/cli/index-cmd.ts +0 -90
- package/src/cli/index-model.ts +0 -75
- package/src/cli/init-bootstrap.ts +0 -47
- package/src/cli/init-client-config.ts +0 -428
- package/src/cli/init-model.ts +0 -284
- package/src/cli/init-render.ts +0 -54
- package/src/cli/init-target-hooks.ts +0 -93
- package/src/cli/init.ts +0 -124
- package/src/cli/json-document.ts +0 -155
- package/src/cli/local-history-dag-model.ts +0 -437
- package/src/cli/local-history-dag-render.ts +0 -133
- package/src/cli/local-history-dag.ts +0 -103
- package/src/cli/main.ts +0 -197
- package/src/cli/migrate-local-history.ts +0 -119
- package/src/cli/peer-command.ts +0 -60
- package/src/contracts/capabilities.ts +0 -540
- package/src/contracts/causal-ontology.ts +0 -627
- package/src/contracts/causal-surface-next-action.ts +0 -18
- package/src/contracts/json-object.ts +0 -18
- package/src/contracts/mcp-runtime.ts +0 -16
- package/src/contracts/output-schema-cli.ts +0 -103
- package/src/contracts/output-schema-fragments.ts +0 -881
- package/src/contracts/output-schema-mcp.ts +0 -501
- package/src/contracts/output-schema-meta.ts +0 -119
- package/src/contracts/output-schemas.ts +0 -1524
- package/src/git/diff.ts +0 -161
- package/src/git/target-git-hook-bootstrap.ts +0 -56
- package/src/guards/stream-boundary.ts +0 -110
- package/src/hooks/posttooluse-read.ts +0 -54
- package/src/hooks/pretooluse-read.ts +0 -52
- package/src/hooks/read-governor.ts +0 -95
- package/src/hooks/read-messages.ts +0 -53
- package/src/hooks/shared.ts +0 -168
- package/src/index.ts +0 -1
- package/src/mcp/burden.ts +0 -132
- package/src/mcp/cache.ts +0 -7
- package/src/mcp/cached-file.ts +0 -1
- package/src/mcp/context.ts +0 -150
- package/src/mcp/control-plane/authz-storage.ts +0 -129
- package/src/mcp/control-plane/session-registry.ts +0 -115
- package/src/mcp/control-plane/status-projection.ts +0 -76
- package/src/mcp/control-plane/types.ts +0 -144
- package/src/mcp/daemon-bootstrap.ts +0 -100
- package/src/mcp/daemon-control-plane.ts +0 -310
- package/src/mcp/daemon-job-scheduler.ts +0 -279
- package/src/mcp/daemon-repos.ts +0 -99
- package/src/mcp/daemon-server.ts +0 -172
- package/src/mcp/daemon-session-host.ts +0 -234
- package/src/mcp/daemon-stdio-bridge.ts +0 -262
- package/src/mcp/daemon-worker-child-pool.ts +0 -213
- package/src/mcp/daemon-worker-inline-pool.ts +0 -46
- package/src/mcp/daemon-worker-pool.ts +0 -7
- package/src/mcp/daemon-worker-process.ts +0 -52
- package/src/mcp/daemon-worker-types.ts +0 -66
- package/src/mcp/metrics.ts +0 -176
- package/src/mcp/monitor-health.ts +0 -83
- package/src/mcp/monitor-persistence.ts +0 -54
- package/src/mcp/monitor-tick-job.ts +0 -153
- package/src/mcp/monitor-types.ts +0 -103
- package/src/mcp/persisted-local-history-graph.ts +0 -592
- package/src/mcp/persisted-local-history-policy.ts +0 -501
- package/src/mcp/persisted-local-history-views.ts +0 -250
- package/src/mcp/persisted-local-history.ts +0 -1621
- package/src/mcp/persistent-monitor-runtime.ts +0 -482
- package/src/mcp/policy.ts +0 -75
- package/src/mcp/receipt.ts +0 -201
- package/src/mcp/repo-concurrency.ts +0 -392
- package/src/mcp/repo-overview/filter.ts +0 -44
- package/src/mcp/repo-overview/types.ts +0 -63
- package/src/mcp/repo-overview/view-projection.ts +0 -90
- package/src/mcp/repo-state-git.ts +0 -247
- package/src/mcp/repo-state-observation.ts +0 -203
- package/src/mcp/repo-state-transition.ts +0 -151
- package/src/mcp/repo-state-types.ts +0 -107
- package/src/mcp/repo-state.ts +0 -146
- package/src/mcp/repo-tool-job.ts +0 -102
- package/src/mcp/repo-tool-worker-context.ts +0 -215
- package/src/mcp/repo-workspace.ts +0 -21
- package/src/mcp/run-capture-config.ts +0 -33
- package/src/mcp/runtime-causal-context.ts +0 -72
- package/src/mcp/runtime-observability.ts +0 -217
- package/src/mcp/runtime-staged-target.ts +0 -161
- package/src/mcp/runtime-workspace-overlay.ts +0 -255
- package/src/mcp/secret-scrub.ts +0 -89
- package/src/mcp/semantic-transition-guidance.ts +0 -60
- package/src/mcp/semantic-transition-summary.ts +0 -130
- package/src/mcp/server-context.ts +0 -236
- package/src/mcp/server-invocation.ts +0 -388
- package/src/mcp/server-tool-access.ts +0 -148
- package/src/mcp/server.ts +0 -270
- package/src/mcp/stdio-server.ts +0 -26
- package/src/mcp/stdio.ts +0 -3
- package/src/mcp/tool-registry.ts +0 -98
- package/src/mcp/tools/activity-view.ts +0 -325
- package/src/mcp/tools/budget.ts +0 -23
- package/src/mcp/tools/causal-attach.ts +0 -67
- package/src/mcp/tools/causal-status.ts +0 -58
- package/src/mcp/tools/changed-since.ts +0 -71
- package/src/mcp/tools/code-find.ts +0 -192
- package/src/mcp/tools/code-refs.ts +0 -470
- package/src/mcp/tools/code-show.ts +0 -289
- package/src/mcp/tools/daemon-monitors.ts +0 -14
- package/src/mcp/tools/daemon-repos.ts +0 -22
- package/src/mcp/tools/daemon-sessions.ts +0 -14
- package/src/mcp/tools/daemon-status.ts +0 -12
- package/src/mcp/tools/diagnostic-models.ts +0 -97
- package/src/mcp/tools/doctor.ts +0 -83
- package/src/mcp/tools/explain.ts +0 -84
- package/src/mcp/tools/export-surface-diff.ts +0 -26
- package/src/mcp/tools/file-outline.ts +0 -67
- package/src/mcp/tools/git-files.ts +0 -73
- package/src/mcp/tools/graft-diff.ts +0 -35
- package/src/mcp/tools/graft-edit.ts +0 -276
- package/src/mcp/tools/knowledge-map.ts +0 -34
- package/src/mcp/tools/map-collector.ts +0 -338
- package/src/mcp/tools/map.ts +0 -185
- package/src/mcp/tools/monitor-nudge.ts +0 -19
- package/src/mcp/tools/monitor-pause.ts +0 -18
- package/src/mcp/tools/monitor-resume.ts +0 -18
- package/src/mcp/tools/monitor-start.ts +0 -20
- package/src/mcp/tools/monitor-stop.ts +0 -18
- package/src/mcp/tools/precision-live.ts +0 -158
- package/src/mcp/tools/precision-match.ts +0 -54
- package/src/mcp/tools/precision-paths.ts +0 -59
- package/src/mcp/tools/precision-query.ts +0 -127
- package/src/mcp/tools/precision-show.ts +0 -86
- package/src/mcp/tools/precision-visibility.ts +0 -44
- package/src/mcp/tools/precision-warp.ts +0 -101
- package/src/mcp/tools/precision.ts +0 -21
- package/src/mcp/tools/read-range.ts +0 -28
- package/src/mcp/tools/refactor-difficulty.ts +0 -42
- package/src/mcp/tools/run-capture.ts +0 -149
- package/src/mcp/tools/safe-read.ts +0 -148
- package/src/mcp/tools/since.ts +0 -53
- package/src/mcp/tools/state.ts +0 -39
- package/src/mcp/tools/stats.ts +0 -24
- package/src/mcp/tools/structural-blame.ts +0 -55
- package/src/mcp/tools/structural-churn.ts +0 -28
- package/src/mcp/tools/structural-log.ts +0 -41
- package/src/mcp/tools/structural-review.ts +0 -63
- package/src/mcp/tools/workspace-authorizations.ts +0 -14
- package/src/mcp/tools/workspace-authorize.ts +0 -20
- package/src/mcp/tools/workspace-bind.ts +0 -25
- package/src/mcp/tools/workspace-rebind.ts +0 -25
- package/src/mcp/tools/workspace-revoke.ts +0 -18
- package/src/mcp/tools/workspace-status.ts +0 -12
- package/src/mcp/warp-pool.ts +0 -36
- package/src/mcp/workspace-read-observation-model.ts +0 -48
- package/src/mcp/workspace-read-observation.ts +0 -103
- package/src/mcp/workspace-router-capability.ts +0 -32
- package/src/mcp/workspace-router-history.ts +0 -233
- package/src/mcp/workspace-router-model.ts +0 -131
- package/src/mcp/workspace-router-resolution.ts +0 -71
- package/src/mcp/workspace-router-runtime.ts +0 -246
- package/src/mcp/workspace-router.ts +0 -688
- package/src/metrics/logger.ts +0 -40
- package/src/metrics/types.ts +0 -40
- package/src/operations/adaptive-projection.ts +0 -54
- package/src/operations/agent-handoff.ts +0 -59
- package/src/operations/cached-file.ts +0 -40
- package/src/operations/capture-range.ts +0 -64
- package/src/operations/conversation-primer.ts +0 -82
- package/src/operations/cross-session-resume.ts +0 -104
- package/src/operations/deterministic-replay.ts +0 -143
- package/src/operations/diff-identity.ts +0 -127
- package/src/operations/export-surface-diff.ts +0 -355
- package/src/operations/file-outline.ts +0 -48
- package/src/operations/footprint-parallelism.ts +0 -98
- package/src/operations/graft-diff.ts +0 -169
- package/src/operations/horizon-of-readability.ts +0 -60
- package/src/operations/import-reference-impact.ts +0 -143
- package/src/operations/knowledge-map.ts +0 -96
- package/src/operations/observation-cache.ts +0 -165
- package/src/operations/projection-safety.ts +0 -111
- package/src/operations/read-range.ts +0 -64
- package/src/operations/repo-workspace.ts +0 -339
- package/src/operations/result-dto.ts +0 -23
- package/src/operations/safe-read.ts +0 -118
- package/src/operations/semantic-drift.ts +0 -70
- package/src/operations/session-filtration.ts +0 -76
- package/src/operations/session-replay.ts +0 -73
- package/src/operations/sludge-detector.ts +0 -356
- package/src/operations/state.ts +0 -66
- package/src/operations/structural-blame.ts +0 -197
- package/src/operations/structural-review.ts +0 -317
- package/src/operations/structured-buffer-compare.ts +0 -429
- package/src/operations/structured-buffer-model.ts +0 -456
- package/src/operations/structured-buffer-query.ts +0 -794
- package/src/operations/structured-buffer.ts +0 -181
- package/src/operations/teaching-hints.ts +0 -52
- package/src/parser/diff.ts +0 -320
- package/src/parser/lang.ts +0 -71
- package/src/parser/markdown.ts +0 -197
- package/src/parser/outline.ts +0 -316
- package/src/parser/runtime.ts +0 -71
- package/src/parser/types.ts +0 -75
- package/src/policy/evaluate.ts +0 -178
- package/src/policy/graftignore.ts +0 -6
- package/src/policy/types.ts +0 -87
- package/src/ports/codec.ts +0 -13
- package/src/ports/filesystem.ts +0 -18
- package/src/ports/git.ts +0 -16
- package/src/ports/guards.ts +0 -68
- package/src/ports/paths.ts +0 -22
- package/src/ports/process-runner.ts +0 -22
- package/src/release/security-gate.ts +0 -102
- package/src/session/tracker.ts +0 -145
- package/src/session/types.ts +0 -23
- package/src/version.ts +0 -3
- package/src/warp/ast-emitter.ts +0 -133
- package/src/warp/ast-import-resolver.ts +0 -333
- package/src/warp/commit-meta.ts +0 -19
- package/src/warp/context.ts +0 -48
- package/src/warp/dead-symbols.ts +0 -174
- package/src/warp/drift-sentinel.ts +0 -101
- package/src/warp/index-head.ts +0 -348
- package/src/warp/observers.ts +0 -101
- package/src/warp/open.ts +0 -67
- package/src/warp/outline-diff-trailer.ts +0 -100
- package/src/warp/plumbing.d.ts +0 -24
- package/src/warp/refactor-difficulty.ts +0 -257
- package/src/warp/references.ts +0 -77
- package/src/warp/stale-docs.ts +0 -210
- package/src/warp/structural-drift-detection.ts +0 -97
- package/src/warp/structural-queries.ts +0 -258
- package/src/warp/symbol-timeline.ts +0 -209
- package/src/warp/traverse-hydrate.ts +0 -61
- package/src/warp/warp-reference-count.ts +0 -47
- package/src/warp/warp-structural-blame.ts +0 -65
- package/src/warp/warp-structural-churn.ts +0 -309
- package/src/warp/warp-structural-log.ts +0 -149
- package/src/warp/writer-id.ts +0 -30
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Identity enrichment for structural diffs.
|
|
3
|
-
*
|
|
4
|
-
* When WARP indexed truth is available, projects canonical symbol
|
|
5
|
-
* identity (`sid:*`) onto DiffEntry objects. Level 1 address truth
|
|
6
|
-
* (name, kind, signature) is preserved — identityId is additive.
|
|
7
|
-
*
|
|
8
|
-
* Symbols without indexed identity keep identityId undefined.
|
|
9
|
-
* This module never fabricates identity from heuristics.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { DiffEntry, OutlineDiff } from "../parser/diff.js";
|
|
13
|
-
import type { GraftDiffResult, FileDiff } from "./graft-diff.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Identity lookup: maps symbol name to identityId for a single file.
|
|
17
|
-
*/
|
|
18
|
-
export type IdentityMap = ReadonlyMap<string, string>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Resolves canonical symbol identities for a file path.
|
|
22
|
-
* Returns an empty map when the file has no indexed symbols.
|
|
23
|
-
*/
|
|
24
|
-
export type IdentityResolver = (filePath: string) => Promise<IdentityMap>;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Enrich a single DiffEntry with identity from the WARP index.
|
|
28
|
-
* Returns a new DiffEntry with identityId when found, or the
|
|
29
|
-
* original entry unchanged when no indexed identity exists.
|
|
30
|
-
*/
|
|
31
|
-
function enrichEntry(
|
|
32
|
-
entry: DiffEntry,
|
|
33
|
-
identities: IdentityMap,
|
|
34
|
-
): DiffEntry {
|
|
35
|
-
const identityId = identities.get(entry.name);
|
|
36
|
-
const enrichedChildDiff = entry.childDiff !== undefined
|
|
37
|
-
? enrichOutlineDiff(entry.childDiff, identities)
|
|
38
|
-
: undefined;
|
|
39
|
-
|
|
40
|
-
// No identity and no child enrichment needed — return original
|
|
41
|
-
if (identityId === undefined && enrichedChildDiff === undefined) {
|
|
42
|
-
return entry;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return new DiffEntry({
|
|
46
|
-
name: entry.name,
|
|
47
|
-
kind: entry.kind,
|
|
48
|
-
...(entry.signature !== undefined ? { signature: entry.signature } : {}),
|
|
49
|
-
...(entry.oldSignature !== undefined ? { oldSignature: entry.oldSignature } : {}),
|
|
50
|
-
...(enrichedChildDiff !== undefined ? { childDiff: enrichedChildDiff } : entry.childDiff !== undefined ? { childDiff: entry.childDiff } : {}),
|
|
51
|
-
...(identityId !== undefined ? { identityId } : {}),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Enrich all entries in an OutlineDiff with WARP identity.
|
|
57
|
-
* Returns undefined if no entries were actually enriched (saves allocation).
|
|
58
|
-
*/
|
|
59
|
-
function enrichOutlineDiff(
|
|
60
|
-
diff: OutlineDiff,
|
|
61
|
-
identities: IdentityMap,
|
|
62
|
-
): OutlineDiff | undefined {
|
|
63
|
-
const enrichedAdded = diff.added.map((e) => enrichEntry(e, identities));
|
|
64
|
-
const enrichedRemoved = diff.removed.map((e) => enrichEntry(e, identities));
|
|
65
|
-
const enrichedChanged = diff.changed.map((e) => enrichEntry(e, identities));
|
|
66
|
-
|
|
67
|
-
const anyEnriched =
|
|
68
|
-
enrichedAdded.some((e, i) => e !== diff.added[i]) ||
|
|
69
|
-
enrichedRemoved.some((e, i) => e !== diff.removed[i]) ||
|
|
70
|
-
enrichedChanged.some((e, i) => e !== diff.changed[i]);
|
|
71
|
-
|
|
72
|
-
if (!anyEnriched) return undefined;
|
|
73
|
-
|
|
74
|
-
return new OutlineDiff({
|
|
75
|
-
added: [...enrichedAdded],
|
|
76
|
-
removed: [...enrichedRemoved],
|
|
77
|
-
changed: [...enrichedChanged],
|
|
78
|
-
continuity: [...diff.continuity],
|
|
79
|
-
unchangedCount: diff.unchangedCount,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Enrich a GraftDiffResult with canonical symbol identities.
|
|
85
|
-
*
|
|
86
|
-
* For each file in the diff, resolves symbol identities through the
|
|
87
|
-
* provided resolver and attaches them to matching DiffEntry objects.
|
|
88
|
-
* Files with no indexed symbols pass through unchanged.
|
|
89
|
-
*
|
|
90
|
-
* This function is safe to call even when the resolver has no data —
|
|
91
|
-
* it gracefully degrades to returning the original result.
|
|
92
|
-
*/
|
|
93
|
-
export async function enrichDiffWithIdentity(
|
|
94
|
-
result: GraftDiffResult,
|
|
95
|
-
resolve: IdentityResolver,
|
|
96
|
-
): Promise<GraftDiffResult> {
|
|
97
|
-
const enrichedFiles: FileDiff[] = [];
|
|
98
|
-
let anyEnriched = false;
|
|
99
|
-
|
|
100
|
-
for (const file of result.files) {
|
|
101
|
-
const identities = await resolve(file.path);
|
|
102
|
-
|
|
103
|
-
if (identities.size === 0) {
|
|
104
|
-
enrichedFiles.push(file);
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const enrichedDiff = enrichOutlineDiff(file.diff, identities);
|
|
109
|
-
if (enrichedDiff === undefined) {
|
|
110
|
-
enrichedFiles.push(file);
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
anyEnriched = true;
|
|
115
|
-
enrichedFiles.push({
|
|
116
|
-
...file,
|
|
117
|
-
diff: enrichedDiff,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!anyEnriched) return result;
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
...result,
|
|
125
|
-
files: enrichedFiles,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Export surface diff — what changed in the public API between two refs?
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
|
|
5
|
-
import type { GitClient } from "../ports/git.js";
|
|
6
|
-
import { getChangedFiles, getFileAtRef } from "../git/diff.js";
|
|
7
|
-
import { detectLang } from "../parser/lang.js";
|
|
8
|
-
import { extractOutline } from "../parser/outline.js";
|
|
9
|
-
import type { OutlineEntry } from "../parser/types.js";
|
|
10
|
-
import { toJsonObject } from "./result-dto.js";
|
|
11
|
-
import type { JsonObject } from "../contracts/json-object.js";
|
|
12
|
-
|
|
13
|
-
// ---- Public types ---------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
export interface ExportChange {
|
|
16
|
-
readonly symbol: string;
|
|
17
|
-
readonly filePath: string;
|
|
18
|
-
readonly kind: string;
|
|
19
|
-
readonly changeType: "added" | "removed" | "signature_changed";
|
|
20
|
-
readonly signature?: string | undefined;
|
|
21
|
-
readonly previousSignature?: string | undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ExportSurfaceDiffResult {
|
|
25
|
-
readonly base: string;
|
|
26
|
-
readonly head: string;
|
|
27
|
-
readonly added: readonly ExportChange[];
|
|
28
|
-
readonly removed: readonly ExportChange[];
|
|
29
|
-
readonly changed: readonly ExportChange[];
|
|
30
|
-
readonly semverImpact: "major" | "minor" | "patch" | "none";
|
|
31
|
-
readonly summary: string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ExportSurfaceDiffOptions {
|
|
35
|
-
readonly cwd: string;
|
|
36
|
-
readonly git: GitClient;
|
|
37
|
-
readonly base?: string | undefined;
|
|
38
|
-
readonly head?: string | undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type SemverImpact = ExportSurfaceDiffResult["semverImpact"];
|
|
42
|
-
|
|
43
|
-
// ---- Internal helpers -----------------------------------------------------
|
|
44
|
-
|
|
45
|
-
function exportKey(entry: OutlineEntry): string {
|
|
46
|
-
return `${entry.kind}:${entry.name}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function extractExportedEntries(
|
|
50
|
-
content: string | null,
|
|
51
|
-
filePath: string,
|
|
52
|
-
): Map<string, OutlineEntry> {
|
|
53
|
-
if (content === null) return new Map();
|
|
54
|
-
const lang = detectLang(filePath);
|
|
55
|
-
if (lang === null) return new Map();
|
|
56
|
-
const outline = extractOutline(content, lang);
|
|
57
|
-
const result = new Map<string, OutlineEntry>();
|
|
58
|
-
for (const entry of outline.entries) {
|
|
59
|
-
if (entry.exported) {
|
|
60
|
-
result.set(exportKey(entry), entry);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
interface ParsedParameter {
|
|
67
|
-
readonly type: string;
|
|
68
|
-
readonly required: boolean;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
interface ParsedSignature {
|
|
72
|
-
readonly parameters: readonly ParsedParameter[];
|
|
73
|
-
readonly returnType: string;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function normalizeSignaturePart(value: string): string {
|
|
77
|
-
return value.replace(/\s+/g, " ").trim();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function findMatchingParen(signature: string, openIndex: number): number {
|
|
81
|
-
let depth = 0;
|
|
82
|
-
for (let index = openIndex; index < signature.length; index += 1) {
|
|
83
|
-
const char = signature[index];
|
|
84
|
-
if (char === "(") {
|
|
85
|
-
depth += 1;
|
|
86
|
-
} else if (char === ")") {
|
|
87
|
-
depth -= 1;
|
|
88
|
-
if (depth === 0) {
|
|
89
|
-
return index;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return -1;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function splitTopLevelCommaList(value: string): string[] {
|
|
97
|
-
const parts: string[] = [];
|
|
98
|
-
let start = 0;
|
|
99
|
-
let angle = 0;
|
|
100
|
-
let brace = 0;
|
|
101
|
-
let bracket = 0;
|
|
102
|
-
let paren = 0;
|
|
103
|
-
|
|
104
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
105
|
-
const char = value[index];
|
|
106
|
-
if (char === "<") angle += 1;
|
|
107
|
-
else if (char === ">" && angle > 0) angle -= 1;
|
|
108
|
-
else if (char === "{") brace += 1;
|
|
109
|
-
else if (char === "}" && brace > 0) brace -= 1;
|
|
110
|
-
else if (char === "[") bracket += 1;
|
|
111
|
-
else if (char === "]" && bracket > 0) bracket -= 1;
|
|
112
|
-
else if (char === "(") paren += 1;
|
|
113
|
-
else if (char === ")" && paren > 0) paren -= 1;
|
|
114
|
-
else if (char === "," && angle === 0 && brace === 0 && bracket === 0 && paren === 0) {
|
|
115
|
-
const part = value.slice(start, index).trim();
|
|
116
|
-
if (part.length > 0) parts.push(part);
|
|
117
|
-
start = index + 1;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const tail = value.slice(start).trim();
|
|
122
|
-
if (tail.length > 0) parts.push(tail);
|
|
123
|
-
return parts;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function findTopLevelColon(value: string): number {
|
|
127
|
-
let angle = 0;
|
|
128
|
-
let brace = 0;
|
|
129
|
-
let bracket = 0;
|
|
130
|
-
let paren = 0;
|
|
131
|
-
|
|
132
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
133
|
-
const char = value[index];
|
|
134
|
-
if (char === "<") angle += 1;
|
|
135
|
-
else if (char === ">" && angle > 0) angle -= 1;
|
|
136
|
-
else if (char === "{") brace += 1;
|
|
137
|
-
else if (char === "}" && brace > 0) brace -= 1;
|
|
138
|
-
else if (char === "[") bracket += 1;
|
|
139
|
-
else if (char === "]" && bracket > 0) bracket -= 1;
|
|
140
|
-
else if (char === "(") paren += 1;
|
|
141
|
-
else if (char === ")" && paren > 0) paren -= 1;
|
|
142
|
-
else if (char === ":" && angle === 0 && brace === 0 && bracket === 0 && paren === 0) {
|
|
143
|
-
return index;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return -1;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function findTopLevelEquals(value: string): number {
|
|
151
|
-
let angle = 0;
|
|
152
|
-
let brace = 0;
|
|
153
|
-
let bracket = 0;
|
|
154
|
-
let paren = 0;
|
|
155
|
-
|
|
156
|
-
for (let index = 0; index < value.length; index += 1) {
|
|
157
|
-
const char = value[index];
|
|
158
|
-
if (char === "<") angle += 1;
|
|
159
|
-
else if (char === ">" && angle > 0) angle -= 1;
|
|
160
|
-
else if (char === "{") brace += 1;
|
|
161
|
-
else if (char === "}" && brace > 0) brace -= 1;
|
|
162
|
-
else if (char === "[") bracket += 1;
|
|
163
|
-
else if (char === "]" && bracket > 0) bracket -= 1;
|
|
164
|
-
else if (char === "(") paren += 1;
|
|
165
|
-
else if (char === ")" && paren > 0) paren -= 1;
|
|
166
|
-
else if (char === "=" && angle === 0 && brace === 0 && bracket === 0 && paren === 0) {
|
|
167
|
-
return index;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return -1;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function parseParameter(rawParameter: string): ParsedParameter {
|
|
175
|
-
const equalsIndex = findTopLevelEquals(rawParameter);
|
|
176
|
-
const declaration = equalsIndex === -1 ? rawParameter : rawParameter.slice(0, equalsIndex);
|
|
177
|
-
const normalized = normalizeSignaturePart(declaration);
|
|
178
|
-
const required = !/^\s*\.\.\./.test(declaration)
|
|
179
|
-
&& !/^[^:=]+?\?\s*:/.test(declaration)
|
|
180
|
-
&& equalsIndex === -1;
|
|
181
|
-
const colonIndex = findTopLevelColon(declaration);
|
|
182
|
-
const type = colonIndex === -1
|
|
183
|
-
? normalized
|
|
184
|
-
: normalizeSignaturePart(declaration.slice(colonIndex + 1));
|
|
185
|
-
return { type, required };
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function parseSignature(signature: string | undefined): ParsedSignature | null {
|
|
189
|
-
if (signature === undefined) {
|
|
190
|
-
return null;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const openIndex = signature.indexOf("(");
|
|
194
|
-
if (openIndex === -1) {
|
|
195
|
-
return null;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const closeIndex = findMatchingParen(signature, openIndex);
|
|
199
|
-
if (closeIndex === -1) {
|
|
200
|
-
return null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
const parameterText = signature.slice(openIndex + 1, closeIndex).trim();
|
|
204
|
-
const parameters = parameterText.length === 0
|
|
205
|
-
? []
|
|
206
|
-
: splitTopLevelCommaList(parameterText).map(parseParameter);
|
|
207
|
-
const trailing = signature.slice(closeIndex + 1).trim();
|
|
208
|
-
const returnType = trailing.startsWith(":")
|
|
209
|
-
? normalizeSignaturePart(trailing.slice(1))
|
|
210
|
-
: "";
|
|
211
|
-
|
|
212
|
-
return { parameters, returnType };
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function classifySignatureImpact(change: ExportChange): SemverImpact {
|
|
216
|
-
const previous = parseSignature(change.previousSignature);
|
|
217
|
-
const next = parseSignature(change.signature);
|
|
218
|
-
if (previous === null || next === null) {
|
|
219
|
-
return "major";
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (previous.returnType !== next.returnType) {
|
|
223
|
-
return "major";
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
for (let index = 0; index < previous.parameters.length; index += 1) {
|
|
227
|
-
const previousParam = previous.parameters[index];
|
|
228
|
-
const nextParam = next.parameters[index];
|
|
229
|
-
if (previousParam === undefined || nextParam === undefined) {
|
|
230
|
-
return "major";
|
|
231
|
-
}
|
|
232
|
-
if (previousParam.type !== nextParam.type) {
|
|
233
|
-
return "major";
|
|
234
|
-
}
|
|
235
|
-
if (!previousParam.required && nextParam.required) {
|
|
236
|
-
return "major";
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const addedParameters = next.parameters.slice(previous.parameters.length);
|
|
241
|
-
if (addedParameters.some((parameter) => parameter.required)) {
|
|
242
|
-
return "major";
|
|
243
|
-
}
|
|
244
|
-
if (addedParameters.length > 0) {
|
|
245
|
-
return "minor";
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return "patch";
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function deriveSemverImpact(
|
|
252
|
-
added: readonly ExportChange[],
|
|
253
|
-
removed: readonly ExportChange[],
|
|
254
|
-
changed: readonly ExportChange[],
|
|
255
|
-
): SemverImpact {
|
|
256
|
-
if (removed.length > 0) return "major";
|
|
257
|
-
if (changed.some((change) => classifySignatureImpact(change) === "major")) return "major";
|
|
258
|
-
if (added.length > 0) return "minor";
|
|
259
|
-
if (changed.some((change) => classifySignatureImpact(change) === "minor")) return "minor";
|
|
260
|
-
if (changed.length > 0) return "patch";
|
|
261
|
-
return "none";
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function buildSummary(
|
|
265
|
-
added: readonly ExportChange[],
|
|
266
|
-
removed: readonly ExportChange[],
|
|
267
|
-
changed: readonly ExportChange[],
|
|
268
|
-
semverImpact: string,
|
|
269
|
-
): string {
|
|
270
|
-
const total = added.length + removed.length + changed.length;
|
|
271
|
-
if (total === 0) return "No exported API changes.";
|
|
272
|
-
const parts: string[] = [];
|
|
273
|
-
if (added.length > 0) parts.push(`+${String(added.length)} added`);
|
|
274
|
-
if (removed.length > 0) parts.push(`-${String(removed.length)} removed`);
|
|
275
|
-
if (changed.length > 0) parts.push(`~${String(changed.length)} changed`);
|
|
276
|
-
return `${parts.join(", ")} exported symbols. Semver impact: ${semverImpact}.`;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// ---- Public API -----------------------------------------------------------
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Compute the export surface diff between two git refs.
|
|
283
|
-
*
|
|
284
|
-
* Extracts outlines at both refs, filters to exported symbols, and
|
|
285
|
-
* classifies additions, removals, and signature changes. Derives
|
|
286
|
-
* the semver impact from the change set.
|
|
287
|
-
*/
|
|
288
|
-
export async function exportSurfaceDiff(
|
|
289
|
-
opts: ExportSurfaceDiffOptions,
|
|
290
|
-
): Promise<ExportSurfaceDiffResult> {
|
|
291
|
-
const { cwd, git } = opts;
|
|
292
|
-
const base = opts.base ?? "HEAD~1";
|
|
293
|
-
const head = opts.head ?? "HEAD";
|
|
294
|
-
|
|
295
|
-
const changedFiles = await getChangedFiles({ cwd, git, base, head });
|
|
296
|
-
|
|
297
|
-
const added: ExportChange[] = [];
|
|
298
|
-
const removed: ExportChange[] = [];
|
|
299
|
-
const changed: ExportChange[] = [];
|
|
300
|
-
|
|
301
|
-
for (const filePath of changedFiles) {
|
|
302
|
-
const baseContent = await getFileAtRef(base, filePath, { cwd, git });
|
|
303
|
-
|
|
304
|
-
const headContent = await getFileAtRef(head, filePath, { cwd, git });
|
|
305
|
-
|
|
306
|
-
const baseExports = extractExportedEntries(baseContent, filePath);
|
|
307
|
-
const headExports = extractExportedEntries(headContent, filePath);
|
|
308
|
-
|
|
309
|
-
// Detect added and changed exports
|
|
310
|
-
for (const [key, headEntry] of headExports) {
|
|
311
|
-
const baseEntry = baseExports.get(key);
|
|
312
|
-
if (baseEntry === undefined) {
|
|
313
|
-
added.push({
|
|
314
|
-
symbol: headEntry.name,
|
|
315
|
-
filePath,
|
|
316
|
-
kind: headEntry.kind,
|
|
317
|
-
changeType: "added",
|
|
318
|
-
signature: headEntry.signature,
|
|
319
|
-
});
|
|
320
|
-
} else if (headEntry.signature !== baseEntry.signature) {
|
|
321
|
-
changed.push({
|
|
322
|
-
symbol: headEntry.name,
|
|
323
|
-
filePath,
|
|
324
|
-
kind: headEntry.kind,
|
|
325
|
-
changeType: "signature_changed",
|
|
326
|
-
signature: headEntry.signature,
|
|
327
|
-
previousSignature: baseEntry.signature,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Detect removed exports
|
|
333
|
-
for (const [key, baseEntry] of baseExports) {
|
|
334
|
-
if (!headExports.has(key)) {
|
|
335
|
-
removed.push({
|
|
336
|
-
symbol: baseEntry.name,
|
|
337
|
-
filePath,
|
|
338
|
-
kind: baseEntry.kind,
|
|
339
|
-
changeType: "removed",
|
|
340
|
-
signature: baseEntry.signature,
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const semverImpact = deriveSemverImpact(added, removed, changed);
|
|
347
|
-
const summary = buildSummary(added, removed, changed, semverImpact);
|
|
348
|
-
|
|
349
|
-
return { base, head, added, removed, changed, semverImpact, summary };
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/** Serialize an ExportSurfaceDiffResult for MCP / CLI output. */
|
|
353
|
-
export function exportSurfaceDiffToJson(result: ExportSurfaceDiffResult): JsonObject {
|
|
354
|
-
return toJsonObject(result);
|
|
355
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { extractOutlineForFile } from "../parser/outline.js";
|
|
2
|
-
import type { OutlineEntry, JumpEntry } from "../parser/types.js";
|
|
3
|
-
import type { FileSystem } from "../ports/filesystem.js";
|
|
4
|
-
|
|
5
|
-
export interface FileOutlineResult {
|
|
6
|
-
path: string;
|
|
7
|
-
outline: OutlineEntry[];
|
|
8
|
-
jumpTable: JumpEntry[];
|
|
9
|
-
partial?: boolean | undefined;
|
|
10
|
-
cacheHit?: boolean | undefined;
|
|
11
|
-
reason?: "UNSUPPORTED_LANGUAGE" | undefined;
|
|
12
|
-
error?: string | undefined;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export async function fileOutline(
|
|
16
|
-
filePath: string,
|
|
17
|
-
opts: { fs: FileSystem },
|
|
18
|
-
): Promise<FileOutlineResult> {
|
|
19
|
-
let content: string;
|
|
20
|
-
try {
|
|
21
|
-
content = await opts.fs.readFile(filePath, "utf-8");
|
|
22
|
-
} catch {
|
|
23
|
-
return {
|
|
24
|
-
path: filePath,
|
|
25
|
-
outline: [],
|
|
26
|
-
jumpTable: [],
|
|
27
|
-
error: "File not found",
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const result = extractOutlineForFile(filePath, content);
|
|
32
|
-
if (result === null) {
|
|
33
|
-
return {
|
|
34
|
-
path: filePath,
|
|
35
|
-
outline: [],
|
|
36
|
-
jumpTable: [],
|
|
37
|
-
reason: "UNSUPPORTED_LANGUAGE",
|
|
38
|
-
error: "Unsupported file type: no parser-backed outline available",
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
path: filePath,
|
|
44
|
-
outline: result.entries,
|
|
45
|
-
jumpTable: result.jumpTable ?? [],
|
|
46
|
-
...(result.partial === true ? { partial: true } : {}),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Footprint Parallelism — discover concurrent-safe tool calls
|
|
3
|
-
// ---------------------------------------------------------------------------
|
|
4
|
-
|
|
5
|
-
/** The structural footprint of a tool call. */
|
|
6
|
-
export interface ToolFootprint {
|
|
7
|
-
readonly tool: string;
|
|
8
|
-
readonly files: readonly string[];
|
|
9
|
-
readonly symbols: readonly string[];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Tools that have no structural footprint (diagnostics, status). */
|
|
13
|
-
const ZERO_FOOTPRINT_TOOLS = new Set([
|
|
14
|
-
"daemon_status",
|
|
15
|
-
"daemon_monitors",
|
|
16
|
-
"causal_status",
|
|
17
|
-
"knowledge_map",
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Compute the structural footprint of a tool call.
|
|
22
|
-
*
|
|
23
|
-
* Files and symbols that the call reads or writes. Two calls with
|
|
24
|
-
* non-overlapping footprints can run concurrently.
|
|
25
|
-
*/
|
|
26
|
-
export function computeFootprint(
|
|
27
|
-
tool: string,
|
|
28
|
-
args: Readonly<Record<string, unknown>>,
|
|
29
|
-
): ToolFootprint {
|
|
30
|
-
if (ZERO_FOOTPRINT_TOOLS.has(tool)) {
|
|
31
|
-
return { tool, files: [], symbols: [] };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const files: string[] = [];
|
|
35
|
-
const symbols: string[] = [];
|
|
36
|
-
|
|
37
|
-
// Extract path from common arg patterns
|
|
38
|
-
const pathArg = args["path"];
|
|
39
|
-
if (typeof pathArg === "string") {
|
|
40
|
-
files.push(pathArg);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Extract symbol from common arg patterns
|
|
44
|
-
const symbolArg = args["symbol"] ?? args["name"];
|
|
45
|
-
if (typeof symbolArg === "string") {
|
|
46
|
-
symbols.push(symbolArg);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return { tool, files, symbols };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Check if two footprints overlap (share files or symbols).
|
|
54
|
-
*/
|
|
55
|
-
function overlaps(a: ToolFootprint, b: ToolFootprint): boolean {
|
|
56
|
-
for (const file of a.files) {
|
|
57
|
-
if (b.files.includes(file)) return true;
|
|
58
|
-
}
|
|
59
|
-
for (const sym of a.symbols) {
|
|
60
|
-
if (b.symbols.includes(sym)) return true;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Partition footprints into parallel groups.
|
|
67
|
-
*
|
|
68
|
-
* Each group contains footprints that can run concurrently (no
|
|
69
|
-
* overlaps within the group). Groups are ordered — group N+1
|
|
70
|
-
* runs after group N.
|
|
71
|
-
*
|
|
72
|
-
* Uses greedy graph coloring: for each footprint, place it in the
|
|
73
|
-
* first group that has no conflicts.
|
|
74
|
-
*/
|
|
75
|
-
export function findParallelGroups(
|
|
76
|
-
footprints: readonly ToolFootprint[],
|
|
77
|
-
): ToolFootprint[][] {
|
|
78
|
-
if (footprints.length === 0) return [];
|
|
79
|
-
|
|
80
|
-
const groups: ToolFootprint[][] = [];
|
|
81
|
-
|
|
82
|
-
for (const fp of footprints) {
|
|
83
|
-
let placed = false;
|
|
84
|
-
for (const group of groups) {
|
|
85
|
-
const conflicts = group.some((existing) => overlaps(existing, fp));
|
|
86
|
-
if (!conflicts) {
|
|
87
|
-
group.push(fp);
|
|
88
|
-
placed = true;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if (!placed) {
|
|
93
|
-
groups.push([fp]);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return groups;
|
|
98
|
-
}
|