@ontrails/trails 1.0.0-beta.2 → 1.0.0-beta.22
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 +647 -0
- package/README.md +26 -0
- package/package.json +28 -7
- package/src/app.ts +86 -2
- package/src/clack.ts +22 -0
- package/src/cli.ts +330 -11
- package/src/completions.ts +240 -0
- package/src/lifecycle-source-io.ts +33 -0
- package/src/load-app-mirror.ts +202 -0
- package/src/local-state-io.ts +153 -0
- package/src/mcp-app.ts +30 -0
- package/src/mcp-options.ts +77 -0
- package/src/mcp.ts +8 -0
- package/src/project-writes.ts +377 -0
- package/src/release/bindings.ts +39 -0
- package/src/release/check.ts +818 -0
- package/src/release/config.ts +63 -0
- package/src/release/contract-facts.ts +425 -0
- package/src/release/index.ts +85 -0
- package/src/release/native-bun-publish.ts +651 -0
- package/src/release/native-bun-registry.ts +350 -0
- package/src/release/packed-artifacts-smoke.ts +236 -0
- package/src/release/smoke.ts +46 -0
- package/src/release/wayfinder-dogfood-smoke.ts +226 -0
- package/src/retired-topo-command.ts +36 -0
- package/src/run-adapter-check.ts +76 -0
- package/src/run-collision.ts +126 -0
- package/src/run-completions-install.ts +179 -0
- package/src/run-example.ts +149 -0
- package/src/run-examples.ts +148 -0
- package/src/run-quiet.ts +75 -0
- package/src/run-release-check.ts +74 -0
- package/src/run-trace.ts +273 -0
- package/src/run-warden.ts +39 -0
- package/src/run-watch.ts +432 -0
- package/src/scaffold-version-sync.ts +183 -0
- package/src/scaffold-versions.generated.ts +12 -0
- package/src/trails/adapter-check.ts +244 -0
- package/src/trails/add-surface.ts +94 -40
- package/src/trails/add-trail.ts +79 -41
- package/src/trails/add-verify.ts +95 -25
- package/src/trails/compile.ts +67 -0
- package/src/trails/completions-complete.ts +165 -0
- package/src/trails/completions.ts +47 -0
- package/src/trails/create-adapter.ts +1084 -0
- package/src/trails/create-scaffold.ts +399 -104
- package/src/trails/create-versions.ts +62 -0
- package/src/trails/create.ts +185 -71
- package/src/trails/deprecate.ts +59 -0
- package/src/trails/dev-clean.ts +82 -0
- package/src/trails/dev-reset.ts +50 -0
- package/src/trails/dev-stats.ts +72 -0
- package/src/trails/dev-support.ts +340 -0
- package/src/trails/doctor.ts +56 -0
- package/src/trails/draft-promote.ts +949 -0
- package/src/trails/guide.ts +74 -68
- package/src/trails/load-app.ts +1143 -15
- package/src/trails/project.ts +17 -3
- package/src/trails/release-check.ts +104 -0
- package/src/trails/release-smoke.ts +48 -0
- package/src/trails/revise.ts +53 -0
- package/src/trails/root-dir.ts +21 -0
- package/src/trails/run-example.ts +491 -0
- package/src/trails/run-examples.ts +145 -0
- package/src/trails/run.ts +410 -0
- package/src/trails/scaffold-json.ts +58 -0
- package/src/trails/survey.ts +881 -226
- package/src/trails/topo-activation.ts +385 -0
- package/src/trails/topo-constants.ts +2 -0
- package/src/trails/topo-history.ts +47 -0
- package/src/trails/topo-output-schemas.ts +248 -0
- package/src/trails/topo-pin.ts +52 -0
- package/src/trails/topo-read-support.ts +313 -0
- package/src/trails/topo-reports.ts +807 -0
- package/src/trails/topo-store-support.ts +174 -0
- package/src/trails/topo-support.ts +220 -0
- package/src/trails/topo-unpin.ts +61 -0
- package/src/trails/topo.ts +106 -0
- package/src/trails/validate.ts +38 -0
- package/src/trails/version-lifecycle-support.ts +945 -0
- package/src/trails/warden-guide.ts +129 -0
- package/src/trails/warden.ts +165 -58
- package/src/versions.ts +31 -0
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/__tests__/examples.test.ts +0 -6
- package/dist/bin/trails.d.ts +0 -3
- package/dist/bin/trails.d.ts.map +0 -1
- package/dist/bin/trails.js +0 -4
- package/dist/bin/trails.js.map +0 -1
- package/dist/src/app.d.ts +0 -2
- package/dist/src/app.d.ts.map +0 -1
- package/dist/src/app.js +0 -11
- package/dist/src/app.js.map +0 -1
- package/dist/src/clack.d.ts +0 -9
- package/dist/src/clack.d.ts.map +0 -1
- package/dist/src/clack.js +0 -62
- package/dist/src/clack.js.map +0 -1
- package/dist/src/cli.d.ts +0 -2
- package/dist/src/cli.d.ts.map +0 -1
- package/dist/src/cli.js +0 -13
- package/dist/src/cli.js.map +0 -1
- package/dist/src/trails/add-surface.d.ts +0 -13
- package/dist/src/trails/add-surface.d.ts.map +0 -1
- package/dist/src/trails/add-surface.js +0 -88
- package/dist/src/trails/add-surface.js.map +0 -1
- package/dist/src/trails/add-trail.d.ts +0 -11
- package/dist/src/trails/add-trail.d.ts.map +0 -1
- package/dist/src/trails/add-trail.js +0 -85
- package/dist/src/trails/add-trail.js.map +0 -1
- package/dist/src/trails/add-verify.d.ts +0 -10
- package/dist/src/trails/add-verify.d.ts.map +0 -1
- package/dist/src/trails/add-verify.js +0 -67
- package/dist/src/trails/add-verify.js.map +0 -1
- package/dist/src/trails/create-scaffold.d.ts +0 -15
- package/dist/src/trails/create-scaffold.d.ts.map +0 -1
- package/dist/src/trails/create-scaffold.js +0 -288
- package/dist/src/trails/create-scaffold.js.map +0 -1
- package/dist/src/trails/create.d.ts +0 -22
- package/dist/src/trails/create.d.ts.map +0 -1
- package/dist/src/trails/create.js +0 -121
- package/dist/src/trails/create.js.map +0 -1
- package/dist/src/trails/guide.d.ts +0 -11
- package/dist/src/trails/guide.d.ts.map +0 -1
- package/dist/src/trails/guide.js +0 -80
- package/dist/src/trails/guide.js.map +0 -1
- package/dist/src/trails/load-app.d.ts +0 -4
- package/dist/src/trails/load-app.d.ts.map +0 -1
- package/dist/src/trails/load-app.js +0 -24
- package/dist/src/trails/load-app.js.map +0 -1
- package/dist/src/trails/project.d.ts +0 -8
- package/dist/src/trails/project.d.ts.map +0 -1
- package/dist/src/trails/project.js +0 -43
- package/dist/src/trails/project.js.map +0 -1
- package/dist/src/trails/survey.d.ts +0 -33
- package/dist/src/trails/survey.d.ts.map +0 -1
- package/dist/src/trails/survey.js +0 -225
- package/dist/src/trails/survey.js.map +0 -1
- package/dist/src/trails/warden.d.ts +0 -19
- package/dist/src/trails/warden.d.ts.map +0 -1
- package/dist/src/trails/warden.js +0 -88
- package/dist/src/trails/warden.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/__tests__/create.test.ts +0 -349
- package/src/__tests__/guide.test.ts +0 -91
- package/src/__tests__/load-app.test.ts +0 -15
- package/src/__tests__/survey.test.ts +0 -161
- package/src/__tests__/warden.test.ts +0 -74
- package/tsconfig.json +0 -9
package/src/trails/survey.ts
CHANGED
|
@@ -1,307 +1,962 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `survey` trail -- Full topo introspection.
|
|
3
3
|
*
|
|
4
|
-
* Lists trails,
|
|
5
|
-
*
|
|
4
|
+
* Lists trails, looks up trails/resources/signals, and diffs against previous
|
|
5
|
+
* versions.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import type {
|
|
8
|
+
import { basename, extname, join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import type { Topo } from '@ontrails/core';
|
|
11
|
+
import {
|
|
12
|
+
deriveSafePath,
|
|
13
|
+
NotFoundError,
|
|
14
|
+
Result,
|
|
15
|
+
trail,
|
|
16
|
+
ValidationError,
|
|
17
|
+
} from '@ontrails/core';
|
|
18
|
+
import type { DiffEntry, DiffResult, TopoGraph } from '@ontrails/topographer';
|
|
11
19
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} from '@ontrails/
|
|
20
|
+
createTopoStore,
|
|
21
|
+
deriveTopoGraphDiff,
|
|
22
|
+
deriveTopoGraph,
|
|
23
|
+
resolveTopoGraphVersionReference,
|
|
24
|
+
TOPO_GRAPH_SCHEMA_VERSION,
|
|
25
|
+
readTopoGraph,
|
|
26
|
+
} from '@ontrails/topographer';
|
|
19
27
|
import { z } from 'zod';
|
|
20
28
|
|
|
21
|
-
import {
|
|
29
|
+
import { writeIsolatedExampleJsonFile } from '../local-state-io.js';
|
|
30
|
+
|
|
31
|
+
import { tryLoadFreshAppLease } from './load-app.js';
|
|
32
|
+
import { resolveTrailRootDir } from './root-dir.js';
|
|
33
|
+
import {
|
|
34
|
+
buildCurrentTopoBrief,
|
|
35
|
+
buildCurrentTopoList,
|
|
36
|
+
buildCurrentTopoMatches,
|
|
37
|
+
buildCurrentTrailDetail,
|
|
38
|
+
buildCurrentResourceDetail,
|
|
39
|
+
buildCurrentSignalDetail,
|
|
40
|
+
readSurfaceLayerNamesFromContext,
|
|
41
|
+
} from './topo-read-support.js';
|
|
42
|
+
import {
|
|
43
|
+
activationOverviewOutput,
|
|
44
|
+
resourceDetailOutput,
|
|
45
|
+
shippedSurfaceInventoryOutput,
|
|
46
|
+
signalDetailOutput,
|
|
47
|
+
trailDetailOutput,
|
|
48
|
+
} from './topo-output-schemas.js';
|
|
49
|
+
import { createIsolatedExampleInput } from './topo-support.js';
|
|
50
|
+
import {
|
|
51
|
+
briefReportSchema,
|
|
52
|
+
deriveShippedSurfaceProjectionInventory,
|
|
53
|
+
} from './topo-reports.js';
|
|
54
|
+
import type { SurfaceLayerNames } from './topo-reports.js';
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
briefReportSchema,
|
|
58
|
+
deriveBriefReport,
|
|
59
|
+
deriveResourceDetail,
|
|
60
|
+
deriveShippedSurfaceProjectionInventory,
|
|
61
|
+
deriveSignalDetail,
|
|
62
|
+
deriveSurveyList,
|
|
63
|
+
deriveTrailDetail,
|
|
64
|
+
} from './topo-reports.js';
|
|
65
|
+
export type {
|
|
66
|
+
BriefReport,
|
|
67
|
+
ShippedSurfaceInventoryReport,
|
|
68
|
+
ShippedSurfaceProjection,
|
|
69
|
+
SignalDetailReport,
|
|
70
|
+
SurfaceLayerNames,
|
|
71
|
+
SurveyListReport,
|
|
72
|
+
TrailDetailReport,
|
|
73
|
+
} from './topo-reports.js';
|
|
22
74
|
|
|
23
75
|
// ---------------------------------------------------------------------------
|
|
24
|
-
//
|
|
76
|
+
// Survey diff helpers
|
|
25
77
|
// ---------------------------------------------------------------------------
|
|
26
78
|
|
|
27
|
-
|
|
28
|
-
readonly
|
|
29
|
-
readonly
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
readonly detours: boolean;
|
|
35
|
-
readonly hikes: boolean;
|
|
36
|
-
readonly events: boolean;
|
|
37
|
-
};
|
|
38
|
-
readonly trails: number;
|
|
39
|
-
readonly hikes: number;
|
|
40
|
-
readonly events: number;
|
|
79
|
+
interface SurveyDiffReport {
|
|
80
|
+
readonly against: string;
|
|
81
|
+
readonly breaking: readonly DiffEntry[];
|
|
82
|
+
readonly hasBreaking: boolean;
|
|
83
|
+
readonly info: readonly DiffEntry[];
|
|
84
|
+
readonly mode: 'diff';
|
|
85
|
+
readonly warnings: readonly DiffEntry[];
|
|
41
86
|
}
|
|
42
87
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
interface DiffInput {
|
|
89
|
+
readonly against?: string | undefined;
|
|
90
|
+
readonly breakingOnly?: boolean | undefined;
|
|
91
|
+
readonly breaks?: boolean | undefined;
|
|
92
|
+
readonly forces?: boolean | undefined;
|
|
93
|
+
readonly module?: string | undefined;
|
|
94
|
+
readonly rootDir?: string | undefined;
|
|
95
|
+
readonly target?: string | undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface ParsedDiffTarget {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
readonly versions?: ReadonlySet<number> | undefined;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const formatDiff = (diff: DiffResult, against: string): SurveyDiffReport => ({
|
|
104
|
+
against,
|
|
105
|
+
breaking: diff.breaking,
|
|
106
|
+
hasBreaking: diff.hasBreaking,
|
|
107
|
+
info: diff.info,
|
|
108
|
+
mode: 'diff',
|
|
109
|
+
warnings: diff.warnings,
|
|
110
|
+
});
|
|
50
111
|
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
): { hasDetours: boolean; hasExamples: boolean; hasOutputSchemas: boolean } => {
|
|
55
|
-
const trails = [...app.trails.values()].map(
|
|
56
|
-
(item) => item as unknown as Record<string, unknown>
|
|
112
|
+
const partitionDiffEntries = (entries: readonly DiffEntry[]): DiffResult => {
|
|
113
|
+
const sorted = [...entries].toSorted((left, right) =>
|
|
114
|
+
left.id.localeCompare(right.id)
|
|
57
115
|
);
|
|
116
|
+
const breaking = sorted.filter((entry) => entry.severity === 'breaking');
|
|
117
|
+
const warnings = sorted.filter((entry) => entry.severity === 'warning');
|
|
118
|
+
const info = sorted.filter((entry) => entry.severity === 'info');
|
|
119
|
+
|
|
58
120
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
121
|
+
breaking,
|
|
122
|
+
entries: sorted,
|
|
123
|
+
hasBreaking: breaking.length > 0,
|
|
124
|
+
info,
|
|
125
|
+
warnings,
|
|
62
126
|
};
|
|
63
127
|
};
|
|
64
128
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
129
|
+
const parseVersionRange = (
|
|
130
|
+
reference: string
|
|
131
|
+
): ReadonlySet<number> | undefined => {
|
|
132
|
+
const match = /^(\d+)\.\.(\d+)$/.exec(reference);
|
|
133
|
+
if (match === null) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
const start = Number(match[1]);
|
|
137
|
+
const end = Number(match[2]);
|
|
138
|
+
if (start < 1 || end < start) {
|
|
139
|
+
throw new ValidationError(
|
|
140
|
+
`Diff version range must use ascending positive versions: ${reference}`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
68
143
|
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
features: {
|
|
73
|
-
detours: hasDetours,
|
|
74
|
-
events: app.events.size > 0,
|
|
75
|
-
examples: hasExamples,
|
|
76
|
-
hikes: app.hikes.size > 0,
|
|
77
|
-
outputSchemas: hasOutputSchemas,
|
|
78
|
-
},
|
|
79
|
-
hikes: app.hikes.size,
|
|
80
|
-
name: app.name,
|
|
81
|
-
trails: app.trails.size,
|
|
82
|
-
version: '0.1.0',
|
|
83
|
-
};
|
|
144
|
+
return new Set(
|
|
145
|
+
Array.from({ length: end - start + 1 }, (_value, index) => start + index)
|
|
146
|
+
);
|
|
84
147
|
};
|
|
85
148
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
149
|
+
const findDiffTargetEntry = (
|
|
150
|
+
previous: TopoGraph,
|
|
151
|
+
current: TopoGraph,
|
|
152
|
+
id: string
|
|
153
|
+
) =>
|
|
154
|
+
current.entries.find((entry) => entry.id === id) ??
|
|
155
|
+
previous.entries.find((entry) => entry.id === id);
|
|
156
|
+
|
|
157
|
+
const parseDiffTarget = (
|
|
158
|
+
previous: TopoGraph,
|
|
159
|
+
current: TopoGraph,
|
|
160
|
+
target: string | undefined
|
|
161
|
+
): Result<ParsedDiffTarget | undefined, Error> => {
|
|
162
|
+
if (target === undefined || target.length === 0) {
|
|
163
|
+
return Result.ok();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const separator = target.lastIndexOf('@');
|
|
167
|
+
const id = separator === -1 ? target : target.slice(0, separator);
|
|
168
|
+
const reference =
|
|
169
|
+
separator === -1 ? undefined : target.slice(separator + 1).trim();
|
|
170
|
+
if (id.length === 0 || reference === '') {
|
|
171
|
+
return Result.err(
|
|
172
|
+
new ValidationError('Diff target must use trail.id or trail.id@version')
|
|
173
|
+
);
|
|
174
|
+
}
|
|
89
175
|
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}): string => {
|
|
94
|
-
if (entry.destructive) {
|
|
95
|
-
return 'destructive';
|
|
176
|
+
const entry = findDiffTargetEntry(previous, current, id);
|
|
177
|
+
if (entry === undefined) {
|
|
178
|
+
return Result.err(new NotFoundError(`Trail not found for diff: ${id}`));
|
|
96
179
|
}
|
|
97
|
-
|
|
98
|
-
|
|
180
|
+
|
|
181
|
+
if (reference === undefined) {
|
|
182
|
+
return Result.ok({ id });
|
|
99
183
|
}
|
|
100
|
-
return '-';
|
|
101
|
-
};
|
|
102
184
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
185
|
+
try {
|
|
186
|
+
const range = parseVersionRange(reference);
|
|
187
|
+
if (range !== undefined) {
|
|
188
|
+
return Result.ok({ id, versions: range });
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return Result.ok({
|
|
192
|
+
id,
|
|
193
|
+
versions: new Set([
|
|
194
|
+
resolveTopoGraphVersionReference(entry, reference).version,
|
|
195
|
+
]),
|
|
196
|
+
});
|
|
197
|
+
} catch (error: unknown) {
|
|
198
|
+
return Result.err(
|
|
199
|
+
error instanceof Error ? error : new Error(String(error))
|
|
108
200
|
);
|
|
109
|
-
|
|
110
|
-
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const detailVersions = (detail: string): readonly number[] => {
|
|
205
|
+
const match = /^(?:Live version|Version) (\d+)\b/.exec(detail);
|
|
206
|
+
if (match !== null) {
|
|
207
|
+
return [Number(match[1])];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const supportMatch = /^Supported versions (?:added|removed): (.+)$/.exec(
|
|
211
|
+
detail
|
|
212
|
+
);
|
|
213
|
+
if (supportMatch === null) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return (supportMatch[1] ?? '')
|
|
218
|
+
.split(',')
|
|
219
|
+
.map((part) => Number(part.trim()))
|
|
220
|
+
.filter((version) => Number.isInteger(version) && version > 0);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
type DiffSeverity = DiffEntry['severity'];
|
|
224
|
+
|
|
225
|
+
const severityRank: Record<DiffSeverity, number> = {
|
|
226
|
+
breaking: 2,
|
|
227
|
+
info: 0,
|
|
228
|
+
warning: 1,
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const higherSeverity = (
|
|
232
|
+
left: DiffSeverity,
|
|
233
|
+
right: DiffSeverity
|
|
234
|
+
): DiffSeverity => (severityRank[right] > severityRank[left] ? right : left);
|
|
235
|
+
|
|
236
|
+
const versionStatus = (detail: string): string | undefined =>
|
|
237
|
+
/^Version \d+ (?:added|removed) \(([^)]+)\)$/.exec(detail)?.[1];
|
|
238
|
+
|
|
239
|
+
const visibleDetailSeverity = (detail: string): DiffSeverity => {
|
|
240
|
+
if (detail.startsWith('Force event ')) {
|
|
241
|
+
return 'warning';
|
|
242
|
+
}
|
|
243
|
+
if (detail.startsWith('Supported versions removed: ')) {
|
|
244
|
+
return 'breaking';
|
|
245
|
+
}
|
|
246
|
+
if (detail.startsWith('Supported versions added: ')) {
|
|
247
|
+
return 'info';
|
|
248
|
+
}
|
|
249
|
+
if (
|
|
250
|
+
/^Live version \d+ (?:added without examples|example coverage removed)$/.test(
|
|
251
|
+
detail
|
|
111
252
|
)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
253
|
+
) {
|
|
254
|
+
return 'warning';
|
|
255
|
+
}
|
|
256
|
+
if (detail.startsWith('Live version ') && detail.includes(' examples: ')) {
|
|
257
|
+
return 'info';
|
|
258
|
+
}
|
|
259
|
+
if (/^Version \d+ status changed: .+ -> archived$/.test(detail)) {
|
|
260
|
+
return 'warning';
|
|
261
|
+
}
|
|
262
|
+
if (detail.startsWith('Version ') && detail.includes(' status changed: ')) {
|
|
263
|
+
return 'info';
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const status = versionStatus(detail);
|
|
267
|
+
if (detail.startsWith('Version ') && detail.includes(' removed (')) {
|
|
268
|
+
return status === 'archived' ? 'warning' : 'breaking';
|
|
269
|
+
}
|
|
270
|
+
if (detail.startsWith('Version ') && detail.includes(' added (')) {
|
|
271
|
+
return status === 'archived' ? 'info' : 'warning';
|
|
272
|
+
}
|
|
273
|
+
if (
|
|
274
|
+
/^Version \d+ (?:kind changed:|Required (?:input|contour) field ".+" added|(?:Input|Output|Contour) field ".+" (?:removed|type changed:|changed from optional to required))/.test(
|
|
275
|
+
detail
|
|
276
|
+
)
|
|
277
|
+
) {
|
|
278
|
+
return 'breaking';
|
|
279
|
+
}
|
|
280
|
+
if (
|
|
281
|
+
/^Version \d+ (?:marker changed:|Optional (?:input|contour) field ".+" added|Output field ".+" added)/.test(
|
|
282
|
+
detail
|
|
283
|
+
)
|
|
284
|
+
) {
|
|
285
|
+
return 'info';
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return 'info';
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const visibleDetailsSeverity = (details: readonly string[]): DiffSeverity => {
|
|
292
|
+
let severity: DiffSeverity = 'info';
|
|
293
|
+
for (const detail of details) {
|
|
294
|
+
severity = higherSeverity(severity, visibleDetailSeverity(detail));
|
|
295
|
+
}
|
|
296
|
+
return severity;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
const detailsChanged = (
|
|
300
|
+
previous: readonly string[],
|
|
301
|
+
next: readonly string[]
|
|
302
|
+
): boolean =>
|
|
303
|
+
previous.length !== next.length ||
|
|
304
|
+
previous.some((detail, index) => detail !== next[index]);
|
|
305
|
+
|
|
306
|
+
const filterDetails = (
|
|
307
|
+
details: readonly string[],
|
|
308
|
+
target: ParsedDiffTarget | undefined,
|
|
309
|
+
forcesOnly: boolean
|
|
310
|
+
): readonly string[] => {
|
|
311
|
+
const visible = forcesOnly
|
|
312
|
+
? details.filter((detail) => detail.startsWith('Force event '))
|
|
313
|
+
: [...details];
|
|
314
|
+
if (target?.versions === undefined || forcesOnly) {
|
|
315
|
+
return visible;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return visible.filter((detail) => {
|
|
319
|
+
const versions = detailVersions(detail);
|
|
320
|
+
return versions.some((version) => target.versions?.has(version));
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
const filterDiff = (
|
|
325
|
+
diff: DiffResult,
|
|
326
|
+
target: ParsedDiffTarget | undefined,
|
|
327
|
+
options: Pick<DiffInput, 'breakingOnly' | 'breaks' | 'forces'>
|
|
328
|
+
): DiffResult => {
|
|
329
|
+
const entries = diff.entries.flatMap((entry): DiffEntry[] => {
|
|
330
|
+
if (target !== undefined && entry.id !== target.id) {
|
|
331
|
+
return [];
|
|
332
|
+
}
|
|
333
|
+
const details = filterDetails(
|
|
334
|
+
entry.details,
|
|
335
|
+
target,
|
|
336
|
+
options.forces === true
|
|
337
|
+
);
|
|
338
|
+
if (details.length === 0) {
|
|
339
|
+
return [];
|
|
340
|
+
}
|
|
341
|
+
return [
|
|
342
|
+
{
|
|
343
|
+
...entry,
|
|
344
|
+
details,
|
|
345
|
+
severity: detailsChanged(entry.details, details)
|
|
346
|
+
? visibleDetailsSeverity(details)
|
|
347
|
+
: entry.severity,
|
|
348
|
+
},
|
|
349
|
+
];
|
|
121
350
|
});
|
|
122
351
|
|
|
123
|
-
|
|
352
|
+
const partitioned = partitionDiffEntries(entries);
|
|
353
|
+
return options.breakingOnly === true || options.breaks === true
|
|
354
|
+
? partitionDiffEntries(partitioned.breaking)
|
|
355
|
+
: partitioned;
|
|
124
356
|
};
|
|
125
357
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
358
|
+
const createDiffExampleInput = (): {
|
|
359
|
+
readonly against: string;
|
|
360
|
+
readonly module: string;
|
|
361
|
+
readonly rootDir: string;
|
|
362
|
+
} => {
|
|
363
|
+
const input = createIsolatedExampleInput('survey-diff');
|
|
364
|
+
writeIsolatedExampleJsonFile(input.rootDir, 'baseline/topo.lock', {
|
|
365
|
+
activationGraph: {
|
|
366
|
+
edgeCount: 0,
|
|
367
|
+
edges: [],
|
|
368
|
+
sourceCount: 0,
|
|
369
|
+
sourceKeys: [],
|
|
370
|
+
trailIds: [],
|
|
371
|
+
},
|
|
372
|
+
activationSources: {},
|
|
373
|
+
entries: [],
|
|
374
|
+
generatedAt: '2026-01-01T00:00:00.000Z',
|
|
375
|
+
topoGraphSchemaVersion: TOPO_GRAPH_SCHEMA_VERSION,
|
|
376
|
+
} satisfies TopoGraph);
|
|
377
|
+
return { ...input, against: 'baseline' };
|
|
378
|
+
};
|
|
137
379
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
380
|
+
const isNotFound = (error: unknown): boolean =>
|
|
381
|
+
typeof error === 'object' &&
|
|
382
|
+
error !== null &&
|
|
383
|
+
(error as NodeJS.ErrnoException).code === 'ENOENT';
|
|
384
|
+
|
|
385
|
+
const readTopoGraphFile = async (
|
|
386
|
+
filePath: string
|
|
387
|
+
): Promise<TopoGraph | null> => {
|
|
388
|
+
try {
|
|
389
|
+
return (await Bun.file(filePath).json()) as TopoGraph;
|
|
390
|
+
} catch (error: unknown) {
|
|
391
|
+
if (isNotFound(error)) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
throw error;
|
|
395
|
+
}
|
|
146
396
|
};
|
|
147
397
|
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
});
|
|
398
|
+
const readStoredTopoGraph = (
|
|
399
|
+
rootDir: string,
|
|
400
|
+
against: string
|
|
401
|
+
): TopoGraph | undefined => {
|
|
402
|
+
try {
|
|
403
|
+
const store = createTopoStore({ rootDir });
|
|
404
|
+
const stored =
|
|
405
|
+
store.exports.get({ pin: against }) ??
|
|
406
|
+
store.exports.get({ snapshotId: against });
|
|
407
|
+
return stored === undefined
|
|
408
|
+
? undefined
|
|
409
|
+
: (JSON.parse(stored.topoGraphJson) as TopoGraph);
|
|
410
|
+
} catch (error: unknown) {
|
|
411
|
+
if (error instanceof NotFoundError) {
|
|
412
|
+
return undefined;
|
|
413
|
+
}
|
|
414
|
+
throw error;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const readPathTopoGraph = async (
|
|
419
|
+
rootDir: string,
|
|
420
|
+
against: string
|
|
421
|
+
): Promise<Result<TopoGraph | null, Error>> => {
|
|
422
|
+
const safePath = deriveSafePath(rootDir, against);
|
|
423
|
+
if (safePath.isErr()) {
|
|
424
|
+
return safePath;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return Result.ok(
|
|
428
|
+
basename(safePath.value) === 'topo.lock' ||
|
|
429
|
+
extname(safePath.value) === '.json'
|
|
430
|
+
? await readTopoGraphFile(safePath.value)
|
|
431
|
+
: await readTopoGraph({ dir: safePath.value })
|
|
432
|
+
);
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
const describeAgainstPathTarget = (against: string): string =>
|
|
436
|
+
basename(against) === 'topo.lock' || extname(against) === '.json'
|
|
437
|
+
? 'workspace-relative TopoGraph file'
|
|
438
|
+
: 'workspace-relative directory containing topo.lock';
|
|
439
|
+
|
|
440
|
+
const topoGraphNotFound = (against: string): NotFoundError =>
|
|
441
|
+
new NotFoundError(
|
|
442
|
+
`No TopoGraph found for: ${against}. Tried ${describeAgainstPathTarget(
|
|
443
|
+
against
|
|
444
|
+
)}, then topo-store pin and snapshot references.`
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
const readAgainstTopoGraph = async (
|
|
448
|
+
rootDir: string,
|
|
449
|
+
against?: string | undefined
|
|
450
|
+
): Promise<Result<{ against: string; map: TopoGraph }, Error>> => {
|
|
451
|
+
if (against === undefined || against === 'saved') {
|
|
452
|
+
const map = await readTopoGraph({ dir: join(rootDir, '.trails') });
|
|
453
|
+
return map === null
|
|
454
|
+
? Result.err(
|
|
455
|
+
new NotFoundError(
|
|
456
|
+
'No saved TopoGraph found. Run `trails compile` first.'
|
|
457
|
+
)
|
|
458
|
+
)
|
|
459
|
+
: Result.ok({ against: 'saved', map });
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// Treat explicit filesystem targets as the most local user intent; stored
|
|
463
|
+
// pins and snapshot ids are fallback references when no path exists.
|
|
464
|
+
const pathMap = await readPathTopoGraph(rootDir, against);
|
|
465
|
+
if (pathMap.isErr()) {
|
|
466
|
+
return pathMap;
|
|
467
|
+
}
|
|
468
|
+
if (pathMap.value !== null) {
|
|
469
|
+
return Result.ok({ against, map: pathMap.value });
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const storedMap = readStoredTopoGraph(rootDir, against);
|
|
473
|
+
if (storedMap !== undefined) {
|
|
474
|
+
return Result.ok({ against, map: storedMap });
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return Result.err(topoGraphNotFound(against));
|
|
478
|
+
};
|
|
154
479
|
|
|
155
480
|
const buildSurveyDiff = async (
|
|
156
481
|
app: Topo,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
'No previous surface map found. Run `trails survey generate` first.'
|
|
165
|
-
)
|
|
166
|
-
);
|
|
482
|
+
rootDir: string,
|
|
483
|
+
input: DiffInput
|
|
484
|
+
): Promise<Result<SurveyDiffReport, Error>> => {
|
|
485
|
+
const currentMap = deriveTopoGraph(app);
|
|
486
|
+
const previous = await readAgainstTopoGraph(rootDir, input.against);
|
|
487
|
+
if (previous.isErr()) {
|
|
488
|
+
return previous;
|
|
167
489
|
}
|
|
168
490
|
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
: formatDiff(diff)
|
|
491
|
+
const target = parseDiffTarget(previous.value.map, currentMap, input.target);
|
|
492
|
+
if (target.isErr()) {
|
|
493
|
+
return target;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
const diff = filterDiff(
|
|
497
|
+
deriveTopoGraphDiff(previous.value.map, currentMap),
|
|
498
|
+
target.value,
|
|
499
|
+
input
|
|
179
500
|
);
|
|
501
|
+
return Result.ok(formatDiff(diff, previous.value.against));
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
const buildSurveyLookup = (
|
|
505
|
+
app: Topo,
|
|
506
|
+
entityId: string,
|
|
507
|
+
rootDir: string,
|
|
508
|
+
surfaceLayerNames?: Partial<SurfaceLayerNames> | undefined
|
|
509
|
+
): Result<object, Error> => {
|
|
510
|
+
const matches = buildCurrentTopoMatches(app, entityId, {
|
|
511
|
+
rootDir,
|
|
512
|
+
surfaceLayerNames,
|
|
513
|
+
});
|
|
514
|
+
return Result.ok({ matches });
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
const buildSurveyTrailDetail = (
|
|
518
|
+
app: Topo,
|
|
519
|
+
id: string,
|
|
520
|
+
rootDir: string,
|
|
521
|
+
surfaceLayerNames?: Partial<SurfaceLayerNames> | undefined
|
|
522
|
+
): Result<object, Error> => {
|
|
523
|
+
const detail = buildCurrentTrailDetail(app, id, {
|
|
524
|
+
rootDir,
|
|
525
|
+
surfaceLayerNames,
|
|
526
|
+
});
|
|
527
|
+
return detail === undefined
|
|
528
|
+
? Result.err(new NotFoundError(`Trail not found: ${id}`))
|
|
529
|
+
: Result.ok(detail);
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
const buildSurveyResourceDetail = (
|
|
533
|
+
app: Topo,
|
|
534
|
+
id: string,
|
|
535
|
+
rootDir: string
|
|
536
|
+
): Result<object, Error> => {
|
|
537
|
+
const detail = buildCurrentResourceDetail(app, id, { rootDir });
|
|
538
|
+
return detail === undefined
|
|
539
|
+
? Result.err(new NotFoundError(`Resource not found: ${id}`))
|
|
540
|
+
: Result.ok(detail);
|
|
180
541
|
};
|
|
181
542
|
|
|
182
|
-
const
|
|
543
|
+
const buildSurveySignalDetail = (
|
|
183
544
|
app: Topo,
|
|
184
|
-
|
|
545
|
+
id: string,
|
|
546
|
+
rootDir: string
|
|
185
547
|
): Result<object, Error> => {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
548
|
+
const detail = buildCurrentSignalDetail(app, id, { rootDir });
|
|
549
|
+
return detail === undefined
|
|
550
|
+
? Result.err(new NotFoundError(`Signal not found: ${id}`))
|
|
551
|
+
: Result.ok(detail);
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
const buildSurveySurfaceInventory = (app: Topo): Result<object, Error> =>
|
|
555
|
+
Result.ok(deriveShippedSurfaceProjectionInventory(app));
|
|
556
|
+
|
|
557
|
+
interface SurveyInput {
|
|
558
|
+
id?: string | undefined;
|
|
559
|
+
module?: string | undefined;
|
|
560
|
+
rootDir?: string | undefined;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
type SurveyMode = 'lookup' | 'overview';
|
|
564
|
+
|
|
565
|
+
type SurveyEnvelope = { readonly mode: SurveyMode } & Record<string, unknown>;
|
|
566
|
+
|
|
567
|
+
/** Determine which survey mode was requested, falling back to 'overview'. */
|
|
568
|
+
const deriveSurveyMode = (input: SurveyInput): SurveyMode =>
|
|
569
|
+
input.id === undefined || input.id === '' ? 'overview' : 'lookup';
|
|
570
|
+
|
|
571
|
+
type SurveyHandler = (
|
|
572
|
+
app: Topo,
|
|
573
|
+
input: SurveyInput,
|
|
574
|
+
rootDir: string,
|
|
575
|
+
surfaceLayerNames?: Partial<SurfaceLayerNames> | undefined
|
|
576
|
+
) => Result<object, Error> | Promise<Result<object, Error>>;
|
|
577
|
+
|
|
578
|
+
/** Handlers keyed by survey mode. */
|
|
579
|
+
const surveyHandlers: Record<SurveyMode, SurveyHandler> = {
|
|
580
|
+
lookup: (app, input, rootDir, surfaceLayerNames) =>
|
|
581
|
+
input.id === undefined || input.id === ''
|
|
582
|
+
? Result.err(new ValidationError('Survey lookup requires an id'))
|
|
583
|
+
: buildSurveyLookup(app, input.id, rootDir, surfaceLayerNames),
|
|
584
|
+
overview: (app, _input, rootDir) =>
|
|
585
|
+
Result.ok(buildCurrentTopoList(app, { rootDir })),
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
const envelopeSurveyValue = (
|
|
589
|
+
mode: SurveyMode,
|
|
590
|
+
value: object
|
|
591
|
+
): SurveyEnvelope => ({ ...value, mode });
|
|
592
|
+
|
|
593
|
+
/** Dispatch to the appropriate survey sub-command based on input flags. */
|
|
594
|
+
const dispatchSurvey = async (
|
|
595
|
+
app: Topo,
|
|
596
|
+
input: SurveyInput,
|
|
597
|
+
rootDir: string,
|
|
598
|
+
surfaceLayerNames?: Partial<SurfaceLayerNames> | undefined
|
|
599
|
+
): Promise<Result<SurveyEnvelope, Error>> => {
|
|
600
|
+
const mode = deriveSurveyMode(input);
|
|
601
|
+
const handler = surveyHandlers[mode];
|
|
602
|
+
const result = await handler(app, input, rootDir, surfaceLayerNames);
|
|
603
|
+
if (result.isErr()) {
|
|
604
|
+
return result;
|
|
605
|
+
}
|
|
606
|
+
return Result.ok(envelopeSurveyValue(mode, result.value));
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const detailInputSchema = z.object({
|
|
610
|
+
id: z.string().describe('Trail, resource, or signal ID'),
|
|
611
|
+
module: z.string().optional().describe('Path to the app module'),
|
|
612
|
+
rootDir: z.string().optional().describe('Workspace root directory'),
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const withFreshSurveyApp = async <T>(
|
|
616
|
+
input: { readonly module?: string | undefined },
|
|
617
|
+
rootDir: string,
|
|
618
|
+
consume: (app: Topo) => Promise<Result<T, Error>> | Result<T, Error>
|
|
619
|
+
): Promise<Result<T, Error>> => {
|
|
620
|
+
const leaseResult = await tryLoadFreshAppLease(input.module, rootDir);
|
|
621
|
+
if (leaseResult.isErr()) {
|
|
622
|
+
return Result.err(leaseResult.error);
|
|
623
|
+
}
|
|
624
|
+
const lease = leaseResult.value;
|
|
625
|
+
try {
|
|
626
|
+
return await consume(lease.app);
|
|
627
|
+
} finally {
|
|
628
|
+
lease.release();
|
|
189
629
|
}
|
|
190
|
-
return Result.ok(formatTrailDetail(item as Trail<unknown, unknown>));
|
|
191
630
|
};
|
|
192
631
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
632
|
+
const withResolvedSurveyApp = async <T>(
|
|
633
|
+
input: {
|
|
634
|
+
readonly module?: string | undefined;
|
|
635
|
+
readonly rootDir?: string | undefined;
|
|
636
|
+
},
|
|
637
|
+
cwd: string | undefined,
|
|
638
|
+
consume: (
|
|
639
|
+
app: Topo,
|
|
640
|
+
rootDir: string
|
|
641
|
+
) => Promise<Result<T, Error>> | Result<T, Error>
|
|
642
|
+
): Promise<Result<T, Error>> => {
|
|
643
|
+
const rootDirResult = resolveTrailRootDir(input.rootDir, cwd);
|
|
644
|
+
if (rootDirResult.isErr()) {
|
|
645
|
+
return Result.err(rootDirResult.error);
|
|
646
|
+
}
|
|
647
|
+
const rootDir = rootDirResult.value;
|
|
648
|
+
return withFreshSurveyApp(input, rootDir, (app) => consume(app, rootDir));
|
|
201
649
|
};
|
|
202
650
|
|
|
651
|
+
const moduleInputSchema = z.object({
|
|
652
|
+
module: z.string().optional().describe('Path to the app module'),
|
|
653
|
+
rootDir: z.string().optional().describe('Workspace root directory'),
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
const diffEntryOutput = z.object({
|
|
657
|
+
change: z.enum(['added', 'removed', 'modified']),
|
|
658
|
+
details: z.array(z.string()).readonly(),
|
|
659
|
+
id: z.string(),
|
|
660
|
+
kind: z.enum(['contour', 'trail', 'signal', 'resource']),
|
|
661
|
+
severity: z.enum(['info', 'warning', 'breaking']),
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
const diffOutput = z.object({
|
|
665
|
+
against: z.string(),
|
|
666
|
+
breaking: z.array(diffEntryOutput),
|
|
667
|
+
hasBreaking: z.boolean(),
|
|
668
|
+
info: z.array(diffEntryOutput),
|
|
669
|
+
mode: z.literal('diff'),
|
|
670
|
+
warnings: z.array(diffEntryOutput),
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
const diffInputSchema = z.object({
|
|
674
|
+
against: z
|
|
675
|
+
.string()
|
|
676
|
+
.min(1)
|
|
677
|
+
.optional()
|
|
678
|
+
.describe(
|
|
679
|
+
'Saved TopoGraph target: "saved", a workspace path (topo.lock, .json file, or directory with topo.lock), then a pin/snapshot id'
|
|
680
|
+
),
|
|
681
|
+
breakingOnly: z
|
|
682
|
+
.boolean()
|
|
683
|
+
.default(false)
|
|
684
|
+
.describe('Legacy alias for --breaks; only show breaking changes'),
|
|
685
|
+
breaks: z.boolean().default(false).describe('Only show breaking changes'),
|
|
686
|
+
forces: z
|
|
687
|
+
.boolean()
|
|
688
|
+
.default(false)
|
|
689
|
+
.describe('Only show graph force audit events'),
|
|
690
|
+
module: z.string().optional().describe('Path to the app module'),
|
|
691
|
+
rootDir: z.string().optional().describe('Workspace root directory'),
|
|
692
|
+
target: z
|
|
693
|
+
.string()
|
|
694
|
+
.min(1)
|
|
695
|
+
.optional()
|
|
696
|
+
.describe('Trail or trail version target, such as user.create@1..2'),
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
const surveyMatchOutput = z.discriminatedUnion('kind', [
|
|
700
|
+
z.object({
|
|
701
|
+
detail: trailDetailOutput,
|
|
702
|
+
kind: z.literal('trail'),
|
|
703
|
+
}),
|
|
704
|
+
z.object({
|
|
705
|
+
detail: resourceDetailOutput,
|
|
706
|
+
kind: z.literal('resource'),
|
|
707
|
+
}),
|
|
708
|
+
z.object({
|
|
709
|
+
detail: signalDetailOutput,
|
|
710
|
+
kind: z.literal('signal'),
|
|
711
|
+
}),
|
|
712
|
+
]);
|
|
713
|
+
|
|
203
714
|
// ---------------------------------------------------------------------------
|
|
204
715
|
// Trail definition
|
|
205
716
|
// ---------------------------------------------------------------------------
|
|
206
717
|
|
|
207
718
|
export const surveyTrail = trail('survey', {
|
|
719
|
+
args: ['id'],
|
|
720
|
+
blaze: async (input, ctx) =>
|
|
721
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
722
|
+
dispatchSurvey(app, input, rootDir, readSurfaceLayerNamesFromContext(ctx))
|
|
723
|
+
),
|
|
208
724
|
description: 'Full topo introspection',
|
|
209
725
|
examples: [
|
|
210
726
|
{
|
|
211
|
-
description: '
|
|
212
|
-
input:
|
|
213
|
-
name: '
|
|
727
|
+
description: 'Show all registered trails, resources, and signals',
|
|
728
|
+
input: createIsolatedExampleInput('survey-overview'),
|
|
729
|
+
name: 'Overview',
|
|
214
730
|
},
|
|
215
731
|
{
|
|
216
|
-
description: '
|
|
217
|
-
input: {
|
|
218
|
-
name: '
|
|
732
|
+
description: 'Find every trail, resource, or signal with a matching ID',
|
|
733
|
+
input: { ...createIsolatedExampleInput('survey-lookup'), id: 'survey' },
|
|
734
|
+
name: 'Lookup by ID',
|
|
219
735
|
},
|
|
220
736
|
],
|
|
221
|
-
implementation: async (input, ctx) => {
|
|
222
|
-
const app = await loadApp(input.module, ctx.cwd ?? '.');
|
|
223
|
-
|
|
224
|
-
if (input.brief) {
|
|
225
|
-
return Result.ok(generateBriefReport(app));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (input.diff) {
|
|
229
|
-
return await buildSurveyDiff(app, input.breakingOnly);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (input.trailId) {
|
|
233
|
-
return buildSurveyDetail(app, input.trailId);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (input.generate) {
|
|
237
|
-
return await buildSurveyGenerate(app);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return Result.ok(formatTrailList(app));
|
|
241
|
-
},
|
|
242
737
|
input: z.object({
|
|
243
|
-
|
|
244
|
-
.boolean()
|
|
245
|
-
.default(false)
|
|
246
|
-
.describe('Only show breaking changes'),
|
|
247
|
-
brief: z.boolean().default(false).describe('Quick capability summary'),
|
|
248
|
-
diff: z.string().optional().describe('Diff against a git ref'),
|
|
249
|
-
generate: z
|
|
250
|
-
.boolean()
|
|
251
|
-
.default(false)
|
|
252
|
-
.describe('Generate surface map and lock file'),
|
|
253
|
-
module: z
|
|
738
|
+
id: z
|
|
254
739
|
.string()
|
|
255
|
-
.
|
|
256
|
-
.describe('
|
|
257
|
-
|
|
740
|
+
.optional()
|
|
741
|
+
.describe('Trail, resource, or signal ID to look up'),
|
|
742
|
+
module: z.string().optional().describe('Path to the app module'),
|
|
743
|
+
rootDir: z.string().optional().describe('Workspace root directory'),
|
|
258
744
|
}),
|
|
259
|
-
|
|
745
|
+
intent: 'read',
|
|
746
|
+
output: z.discriminatedUnion('mode', [
|
|
260
747
|
z.object({
|
|
748
|
+
activation: activationOverviewOutput,
|
|
261
749
|
count: z.number(),
|
|
262
750
|
entries: z.array(
|
|
263
751
|
z.object({
|
|
752
|
+
activatedBy: z.array(z.string()).readonly(),
|
|
753
|
+
activates: z.array(z.string()).readonly(),
|
|
264
754
|
examples: z.number(),
|
|
265
755
|
id: z.string(),
|
|
266
756
|
kind: z.string(),
|
|
267
757
|
safety: z.string(),
|
|
268
758
|
})
|
|
269
759
|
),
|
|
760
|
+
mode: z.literal('overview'),
|
|
761
|
+
resourceCount: z.number(),
|
|
762
|
+
resources: z.array(
|
|
763
|
+
z.object({
|
|
764
|
+
description: z.string().nullable(),
|
|
765
|
+
health: z.enum(['available', 'none']),
|
|
766
|
+
id: z.string(),
|
|
767
|
+
kind: z.literal('resource'),
|
|
768
|
+
lifetime: z.literal('singleton'),
|
|
769
|
+
usedBy: z.array(z.string()),
|
|
770
|
+
})
|
|
771
|
+
),
|
|
772
|
+
signalCount: z.number(),
|
|
773
|
+
signals: z.array(
|
|
774
|
+
z.object({
|
|
775
|
+
consumers: z.array(z.string()).readonly(),
|
|
776
|
+
description: z.string().nullable(),
|
|
777
|
+
examples: z.number(),
|
|
778
|
+
from: z.array(z.string()).readonly(),
|
|
779
|
+
id: z.string(),
|
|
780
|
+
kind: z.literal('signal'),
|
|
781
|
+
payloadSchema: z.boolean(),
|
|
782
|
+
producers: z.array(z.string()).readonly(),
|
|
783
|
+
})
|
|
784
|
+
),
|
|
270
785
|
}),
|
|
271
786
|
z.object({
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
features: z.object({
|
|
275
|
-
detours: z.boolean(),
|
|
276
|
-
events: z.boolean(),
|
|
277
|
-
examples: z.boolean(),
|
|
278
|
-
hikes: z.boolean(),
|
|
279
|
-
outputSchemas: z.boolean(),
|
|
280
|
-
}),
|
|
281
|
-
hikes: z.number(),
|
|
282
|
-
name: z.string(),
|
|
283
|
-
trails: z.number(),
|
|
284
|
-
version: z.string(),
|
|
285
|
-
}),
|
|
286
|
-
z.object({
|
|
287
|
-
breaking: z.array(z.unknown()),
|
|
288
|
-
hasBreaking: z.boolean(),
|
|
289
|
-
info: z.array(z.unknown()),
|
|
290
|
-
warnings: z.array(z.unknown()),
|
|
291
|
-
}),
|
|
292
|
-
z.object({
|
|
293
|
-
description: z.unknown().nullable(),
|
|
294
|
-
detours: z.unknown().nullable(),
|
|
295
|
-
examples: z.array(z.unknown()),
|
|
296
|
-
id: z.string(),
|
|
297
|
-
kind: z.string(),
|
|
298
|
-
safety: z.string(),
|
|
299
|
-
}),
|
|
300
|
-
z.object({
|
|
301
|
-
hash: z.string(),
|
|
302
|
-
lockPath: z.string(),
|
|
303
|
-
mapPath: z.string(),
|
|
787
|
+
matches: z.array(surveyMatchOutput),
|
|
788
|
+
mode: z.literal('lookup'),
|
|
304
789
|
}),
|
|
305
790
|
]),
|
|
306
|
-
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
export const surveyBriefTrail = trail('survey.brief', {
|
|
794
|
+
blaze: async (input, ctx) =>
|
|
795
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
796
|
+
Result.ok(buildCurrentTopoBrief(app, { rootDir }))
|
|
797
|
+
),
|
|
798
|
+
description: 'Summarize topo capabilities',
|
|
799
|
+
examples: [
|
|
800
|
+
{
|
|
801
|
+
description: 'Show counts and feature flags',
|
|
802
|
+
input: createIsolatedExampleInput('survey-brief'),
|
|
803
|
+
name: 'Brief capability report',
|
|
804
|
+
},
|
|
805
|
+
],
|
|
806
|
+
input: moduleInputSchema,
|
|
807
|
+
intent: 'read',
|
|
808
|
+
output: briefReportSchema,
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
export const surveySurfacesTrail = trail('survey.surfaces', {
|
|
812
|
+
blaze: async (input, ctx) =>
|
|
813
|
+
withResolvedSurveyApp(input, ctx.cwd, (app) =>
|
|
814
|
+
buildSurveySurfaceInventory(app)
|
|
815
|
+
),
|
|
816
|
+
description: 'Inventory shipped surface projections',
|
|
817
|
+
examples: [
|
|
818
|
+
{
|
|
819
|
+
description: 'Show CLI, MCP, and HTTP projections for public trails',
|
|
820
|
+
input: createIsolatedExampleInput('survey-surfaces'),
|
|
821
|
+
name: 'Shipped surface inventory',
|
|
822
|
+
},
|
|
823
|
+
],
|
|
824
|
+
input: moduleInputSchema,
|
|
825
|
+
intent: 'read',
|
|
826
|
+
output: shippedSurfaceInventoryOutput,
|
|
827
|
+
});
|
|
828
|
+
|
|
829
|
+
export const surveyDiffTrail = trail('survey.diff', {
|
|
830
|
+
blaze: async (input, ctx) =>
|
|
831
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
832
|
+
buildSurveyDiff(app, rootDir, input)
|
|
833
|
+
),
|
|
834
|
+
description: 'Diff the current topo against a saved TopoGraph',
|
|
835
|
+
examples: [
|
|
836
|
+
{
|
|
837
|
+
description: 'Compare current topo to a saved TopoGraph directory',
|
|
838
|
+
input: createDiffExampleInput(),
|
|
839
|
+
name: 'Diff against baseline',
|
|
840
|
+
},
|
|
841
|
+
{
|
|
842
|
+
description: 'Reject an empty saved map target',
|
|
843
|
+
error: 'ValidationError',
|
|
844
|
+
input: { against: '' },
|
|
845
|
+
name: 'Reject empty diff target',
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
description: 'Reject an empty target before filtering breaking drift',
|
|
849
|
+
error: 'ValidationError',
|
|
850
|
+
input: {
|
|
851
|
+
against: '',
|
|
852
|
+
breakingOnly: true,
|
|
853
|
+
},
|
|
854
|
+
name: 'Reject empty breaking-only target',
|
|
855
|
+
},
|
|
856
|
+
],
|
|
857
|
+
input: diffInputSchema,
|
|
858
|
+
intent: 'read',
|
|
859
|
+
output: diffOutput,
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
export const diffTrail = trail('diff', {
|
|
863
|
+
args: ['target'],
|
|
864
|
+
blaze: async (input, ctx) =>
|
|
865
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
866
|
+
buildSurveyDiff(app, rootDir, input)
|
|
867
|
+
),
|
|
868
|
+
description: 'Diff the current topo against a saved TopoGraph',
|
|
869
|
+
examples: [
|
|
870
|
+
{
|
|
871
|
+
description: 'Compare current topo to a saved TopoGraph directory',
|
|
872
|
+
input: createDiffExampleInput(),
|
|
873
|
+
name: 'Diff against baseline',
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
description: 'Show only breaking contract drift',
|
|
877
|
+
input: { ...createDiffExampleInput(), breaks: true },
|
|
878
|
+
name: 'Breaking changes',
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
description: 'Show graph-only force audit events',
|
|
882
|
+
input: { ...createDiffExampleInput(), forces: true },
|
|
883
|
+
name: 'Force audit events',
|
|
884
|
+
},
|
|
885
|
+
],
|
|
886
|
+
input: diffInputSchema,
|
|
887
|
+
intent: 'read',
|
|
888
|
+
output: diffOutput,
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
export const surveyTrailDetailTrail = trail('survey.trail', {
|
|
892
|
+
args: ['id'],
|
|
893
|
+
blaze: async (input, ctx) =>
|
|
894
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
895
|
+
buildSurveyTrailDetail(
|
|
896
|
+
app,
|
|
897
|
+
input.id,
|
|
898
|
+
rootDir,
|
|
899
|
+
readSurfaceLayerNamesFromContext(ctx)
|
|
900
|
+
)
|
|
901
|
+
),
|
|
902
|
+
description: 'Inspect one trail by ID',
|
|
903
|
+
examples: [
|
|
904
|
+
{
|
|
905
|
+
description: 'Show trail contract detail',
|
|
906
|
+
input: {
|
|
907
|
+
...createIsolatedExampleInput('survey-trail-detail'),
|
|
908
|
+
id: 'survey',
|
|
909
|
+
},
|
|
910
|
+
name: 'Trail detail',
|
|
911
|
+
},
|
|
912
|
+
],
|
|
913
|
+
input: detailInputSchema,
|
|
914
|
+
intent: 'read',
|
|
915
|
+
output: trailDetailOutput,
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
export const surveyResourceTrail = trail('survey.resource', {
|
|
919
|
+
args: ['id'],
|
|
920
|
+
blaze: async (input, ctx) =>
|
|
921
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
922
|
+
buildSurveyResourceDetail(app, input.id, rootDir)
|
|
923
|
+
),
|
|
924
|
+
description: 'Inspect one resource by ID',
|
|
925
|
+
examples: [
|
|
926
|
+
{
|
|
927
|
+
description: 'Show resource usage detail',
|
|
928
|
+
error: 'NotFoundError',
|
|
929
|
+
input: {
|
|
930
|
+
...createIsolatedExampleInput('survey-resource-detail'),
|
|
931
|
+
id: 'db.main',
|
|
932
|
+
},
|
|
933
|
+
name: 'Resource detail',
|
|
934
|
+
},
|
|
935
|
+
],
|
|
936
|
+
input: detailInputSchema,
|
|
937
|
+
intent: 'read',
|
|
938
|
+
output: resourceDetailOutput,
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
export const surveySignalTrail = trail('survey.signal', {
|
|
942
|
+
args: ['id'],
|
|
943
|
+
blaze: async (input, ctx) =>
|
|
944
|
+
withResolvedSurveyApp(input, ctx.cwd, (app, rootDir) =>
|
|
945
|
+
buildSurveySignalDetail(app, input.id, rootDir)
|
|
946
|
+
),
|
|
947
|
+
description: 'Inspect one signal by ID',
|
|
948
|
+
examples: [
|
|
949
|
+
{
|
|
950
|
+
description: 'Show signal producer and consumer detail',
|
|
951
|
+
error: 'NotFoundError',
|
|
952
|
+
input: {
|
|
953
|
+
...createIsolatedExampleInput('survey-signal-detail'),
|
|
954
|
+
id: 'hello.greeted',
|
|
955
|
+
},
|
|
956
|
+
name: 'Signal detail',
|
|
957
|
+
},
|
|
958
|
+
],
|
|
959
|
+
input: detailInputSchema,
|
|
960
|
+
intent: 'read',
|
|
961
|
+
output: signalDetailOutput,
|
|
307
962
|
});
|