@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.
Files changed (150) hide show
  1. package/CHANGELOG.md +647 -0
  2. package/README.md +26 -0
  3. package/package.json +28 -7
  4. package/src/app.ts +86 -2
  5. package/src/clack.ts +22 -0
  6. package/src/cli.ts +330 -11
  7. package/src/completions.ts +240 -0
  8. package/src/lifecycle-source-io.ts +33 -0
  9. package/src/load-app-mirror.ts +202 -0
  10. package/src/local-state-io.ts +153 -0
  11. package/src/mcp-app.ts +30 -0
  12. package/src/mcp-options.ts +77 -0
  13. package/src/mcp.ts +8 -0
  14. package/src/project-writes.ts +377 -0
  15. package/src/release/bindings.ts +39 -0
  16. package/src/release/check.ts +818 -0
  17. package/src/release/config.ts +63 -0
  18. package/src/release/contract-facts.ts +425 -0
  19. package/src/release/index.ts +85 -0
  20. package/src/release/native-bun-publish.ts +651 -0
  21. package/src/release/native-bun-registry.ts +350 -0
  22. package/src/release/packed-artifacts-smoke.ts +236 -0
  23. package/src/release/smoke.ts +46 -0
  24. package/src/release/wayfinder-dogfood-smoke.ts +226 -0
  25. package/src/retired-topo-command.ts +36 -0
  26. package/src/run-adapter-check.ts +76 -0
  27. package/src/run-collision.ts +126 -0
  28. package/src/run-completions-install.ts +179 -0
  29. package/src/run-example.ts +149 -0
  30. package/src/run-examples.ts +148 -0
  31. package/src/run-quiet.ts +75 -0
  32. package/src/run-release-check.ts +74 -0
  33. package/src/run-trace.ts +273 -0
  34. package/src/run-warden.ts +39 -0
  35. package/src/run-watch.ts +432 -0
  36. package/src/scaffold-version-sync.ts +183 -0
  37. package/src/scaffold-versions.generated.ts +12 -0
  38. package/src/trails/adapter-check.ts +244 -0
  39. package/src/trails/add-surface.ts +94 -40
  40. package/src/trails/add-trail.ts +79 -41
  41. package/src/trails/add-verify.ts +95 -25
  42. package/src/trails/compile.ts +67 -0
  43. package/src/trails/completions-complete.ts +165 -0
  44. package/src/trails/completions.ts +47 -0
  45. package/src/trails/create-adapter.ts +1084 -0
  46. package/src/trails/create-scaffold.ts +399 -104
  47. package/src/trails/create-versions.ts +62 -0
  48. package/src/trails/create.ts +185 -71
  49. package/src/trails/deprecate.ts +59 -0
  50. package/src/trails/dev-clean.ts +82 -0
  51. package/src/trails/dev-reset.ts +50 -0
  52. package/src/trails/dev-stats.ts +72 -0
  53. package/src/trails/dev-support.ts +340 -0
  54. package/src/trails/doctor.ts +56 -0
  55. package/src/trails/draft-promote.ts +949 -0
  56. package/src/trails/guide.ts +74 -68
  57. package/src/trails/load-app.ts +1143 -15
  58. package/src/trails/project.ts +17 -3
  59. package/src/trails/release-check.ts +104 -0
  60. package/src/trails/release-smoke.ts +48 -0
  61. package/src/trails/revise.ts +53 -0
  62. package/src/trails/root-dir.ts +21 -0
  63. package/src/trails/run-example.ts +491 -0
  64. package/src/trails/run-examples.ts +145 -0
  65. package/src/trails/run.ts +410 -0
  66. package/src/trails/scaffold-json.ts +58 -0
  67. package/src/trails/survey.ts +881 -226
  68. package/src/trails/topo-activation.ts +385 -0
  69. package/src/trails/topo-constants.ts +2 -0
  70. package/src/trails/topo-history.ts +47 -0
  71. package/src/trails/topo-output-schemas.ts +248 -0
  72. package/src/trails/topo-pin.ts +52 -0
  73. package/src/trails/topo-read-support.ts +313 -0
  74. package/src/trails/topo-reports.ts +807 -0
  75. package/src/trails/topo-store-support.ts +174 -0
  76. package/src/trails/topo-support.ts +220 -0
  77. package/src/trails/topo-unpin.ts +61 -0
  78. package/src/trails/topo.ts +106 -0
  79. package/src/trails/validate.ts +38 -0
  80. package/src/trails/version-lifecycle-support.ts +945 -0
  81. package/src/trails/warden-guide.ts +129 -0
  82. package/src/trails/warden.ts +165 -58
  83. package/src/versions.ts +31 -0
  84. package/.turbo/turbo-build.log +0 -1
  85. package/.turbo/turbo-lint.log +0 -3
  86. package/.turbo/turbo-typecheck.log +0 -1
  87. package/__tests__/examples.test.ts +0 -6
  88. package/dist/bin/trails.d.ts +0 -3
  89. package/dist/bin/trails.d.ts.map +0 -1
  90. package/dist/bin/trails.js +0 -4
  91. package/dist/bin/trails.js.map +0 -1
  92. package/dist/src/app.d.ts +0 -2
  93. package/dist/src/app.d.ts.map +0 -1
  94. package/dist/src/app.js +0 -11
  95. package/dist/src/app.js.map +0 -1
  96. package/dist/src/clack.d.ts +0 -9
  97. package/dist/src/clack.d.ts.map +0 -1
  98. package/dist/src/clack.js +0 -62
  99. package/dist/src/clack.js.map +0 -1
  100. package/dist/src/cli.d.ts +0 -2
  101. package/dist/src/cli.d.ts.map +0 -1
  102. package/dist/src/cli.js +0 -13
  103. package/dist/src/cli.js.map +0 -1
  104. package/dist/src/trails/add-surface.d.ts +0 -13
  105. package/dist/src/trails/add-surface.d.ts.map +0 -1
  106. package/dist/src/trails/add-surface.js +0 -88
  107. package/dist/src/trails/add-surface.js.map +0 -1
  108. package/dist/src/trails/add-trail.d.ts +0 -11
  109. package/dist/src/trails/add-trail.d.ts.map +0 -1
  110. package/dist/src/trails/add-trail.js +0 -85
  111. package/dist/src/trails/add-trail.js.map +0 -1
  112. package/dist/src/trails/add-verify.d.ts +0 -10
  113. package/dist/src/trails/add-verify.d.ts.map +0 -1
  114. package/dist/src/trails/add-verify.js +0 -67
  115. package/dist/src/trails/add-verify.js.map +0 -1
  116. package/dist/src/trails/create-scaffold.d.ts +0 -15
  117. package/dist/src/trails/create-scaffold.d.ts.map +0 -1
  118. package/dist/src/trails/create-scaffold.js +0 -288
  119. package/dist/src/trails/create-scaffold.js.map +0 -1
  120. package/dist/src/trails/create.d.ts +0 -22
  121. package/dist/src/trails/create.d.ts.map +0 -1
  122. package/dist/src/trails/create.js +0 -121
  123. package/dist/src/trails/create.js.map +0 -1
  124. package/dist/src/trails/guide.d.ts +0 -11
  125. package/dist/src/trails/guide.d.ts.map +0 -1
  126. package/dist/src/trails/guide.js +0 -80
  127. package/dist/src/trails/guide.js.map +0 -1
  128. package/dist/src/trails/load-app.d.ts +0 -4
  129. package/dist/src/trails/load-app.d.ts.map +0 -1
  130. package/dist/src/trails/load-app.js +0 -24
  131. package/dist/src/trails/load-app.js.map +0 -1
  132. package/dist/src/trails/project.d.ts +0 -8
  133. package/dist/src/trails/project.d.ts.map +0 -1
  134. package/dist/src/trails/project.js +0 -43
  135. package/dist/src/trails/project.js.map +0 -1
  136. package/dist/src/trails/survey.d.ts +0 -33
  137. package/dist/src/trails/survey.d.ts.map +0 -1
  138. package/dist/src/trails/survey.js +0 -225
  139. package/dist/src/trails/survey.js.map +0 -1
  140. package/dist/src/trails/warden.d.ts +0 -19
  141. package/dist/src/trails/warden.d.ts.map +0 -1
  142. package/dist/src/trails/warden.js +0 -88
  143. package/dist/src/trails/warden.js.map +0 -1
  144. package/dist/tsconfig.tsbuildinfo +0 -1
  145. package/src/__tests__/create.test.ts +0 -349
  146. package/src/__tests__/guide.test.ts +0 -91
  147. package/src/__tests__/load-app.test.ts +0 -15
  148. package/src/__tests__/survey.test.ts +0 -161
  149. package/src/__tests__/warden.test.ts +0 -74
  150. package/tsconfig.json +0 -9
@@ -1,307 +1,962 @@
1
1
  /**
2
2
  * `survey` trail -- Full topo introspection.
3
3
  *
4
- * Lists trails, shows detail for individual trails, generates surface maps,
5
- * and diffs against previous versions.
4
+ * Lists trails, looks up trails/resources/signals, and diffs against previous
5
+ * versions.
6
6
  */
7
7
 
8
- import type { Topo, Trail } from '@ontrails/core';
9
- import { Result, trail } from '@ontrails/core';
10
- import type { DiffResult } from '@ontrails/schema';
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
- diffSurfaceMaps,
13
- generateSurfaceMap,
14
- hashSurfaceMap,
15
- readSurfaceMap,
16
- writeSurfaceLock,
17
- writeSurfaceMap,
18
- } from '@ontrails/schema';
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 { loadApp } from './load-app.js';
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
- // Brief report (formerly scout)
76
+ // Survey diff helpers
25
77
  // ---------------------------------------------------------------------------
26
78
 
27
- export interface BriefReport {
28
- readonly name: string;
29
- readonly version: string;
30
- readonly contractVersion: string;
31
- readonly features: {
32
- readonly outputSchemas: boolean;
33
- readonly examples: boolean;
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
- /** Check if a trail has a specific feature. */
44
- const trailHas = (raw: Record<string, unknown>, key: string): boolean => {
45
- if (key === 'examples') {
46
- return Array.isArray(raw[key]) && (raw[key] as unknown[]).length > 0;
47
- }
48
- return Boolean(raw[key]);
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
- /** Detect which features are used across trails. */
52
- const detectFeatures = (
53
- app: Topo
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
- hasDetours: trails.some((r) => trailHas(r, 'detours')),
60
- hasExamples: trails.some((r) => trailHas(r, 'examples')),
61
- hasOutputSchemas: trails.some((r) => trailHas(r, 'output')),
121
+ breaking,
122
+ entries: sorted,
123
+ hasBreaking: breaking.length > 0,
124
+ info,
125
+ warnings,
62
126
  };
63
127
  };
64
128
 
65
- /** Generate a compact capability report for the given topo. */
66
- export const generateBriefReport = (app: Topo): BriefReport => {
67
- const { hasDetours, hasExamples, hasOutputSchemas } = detectFeatures(app);
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
- contractVersion: '2026-03',
71
- events: app.events.size,
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
- // Formatting helpers
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 safetyLabel = (entry: {
91
- readOnly?: boolean;
92
- destructive?: boolean;
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
- if (entry.readOnly) {
98
- return 'readOnly';
180
+
181
+ if (reference === undefined) {
182
+ return Result.ok({ id });
99
183
  }
100
- return '-';
101
- };
102
184
 
103
- const formatTrailList = (app: Topo): object => {
104
- const items = app.list();
105
- const entries = items.map((item) => {
106
- const safety = safetyLabel(
107
- item as unknown as { readOnly?: boolean; destructive?: boolean }
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
- const examples = Array.isArray(
110
- (item as unknown as { examples?: unknown[] }).examples
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
- ? (item as unknown as { examples: unknown[] }).examples.length
113
- : 0;
114
-
115
- return {
116
- examples,
117
- id: item.id,
118
- kind: item.kind,
119
- safety,
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
- return { count: items.length, entries };
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
- * Build a human-readable detail view for a single trail.
128
- *
129
- * Overlaps with `trailToEntry` in `@ontrails/schema` which builds the
130
- * surface-map entry. The two serve different audiences (human display vs
131
- * machine-diffable surface map) so they are kept separate.
132
- */
133
- const formatTrailDetail = (item: Trail<unknown, unknown>): object => {
134
- const safety = safetyLabel(
135
- item as unknown as { readOnly?: boolean; destructive?: boolean }
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
- return {
139
- description: item.description ?? null,
140
- detours: item.detours ?? null,
141
- examples: item.examples ?? [],
142
- id: item.id,
143
- kind: item.kind,
144
- safety,
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 formatDiff = (diff: DiffResult): object => ({
149
- breaking: diff.breaking,
150
- hasBreaking: diff.hasBreaking,
151
- info: diff.info,
152
- warnings: diff.warnings,
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
- breakingOnly: boolean
158
- ): Promise<Result<object, Error>> => {
159
- const currentMap = generateSurfaceMap(app);
160
- const previousMap = await readSurfaceMap();
161
- if (!previousMap) {
162
- return Result.err(
163
- new Error(
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 diff = diffSurfaceMaps(previousMap, currentMap);
170
- return Result.ok(
171
- breakingOnly
172
- ? formatDiff({
173
- ...diff,
174
- entries: diff.breaking,
175
- info: [],
176
- warnings: [],
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 buildSurveyDetail = (
543
+ const buildSurveySignalDetail = (
183
544
  app: Topo,
184
- trailId: string
545
+ id: string,
546
+ rootDir: string
185
547
  ): Result<object, Error> => {
186
- const item = app.get(trailId);
187
- if (!item) {
188
- return Result.err(new Error(`Trail not found: ${trailId}`));
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 buildSurveyGenerate = async (
194
- app: Topo
195
- ): Promise<Result<object, Error>> => {
196
- const surfaceMap = generateSurfaceMap(app);
197
- const mapPath = await writeSurfaceMap(surfaceMap);
198
- const hash = hashSurfaceMap(surfaceMap);
199
- const lockPath = await writeSurfaceLock(hash);
200
- return Result.ok({ hash, lockPath, mapPath });
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: 'Lists all registered trails with safety and surface info',
212
- input: {},
213
- name: 'List all trails',
727
+ description: 'Show all registered trails, resources, and signals',
728
+ input: createIsolatedExampleInput('survey-overview'),
729
+ name: 'Overview',
214
730
  },
215
731
  {
216
- description: 'Quick capability summary with counts and feature flags',
217
- input: { brief: true },
218
- name: 'Brief capability report',
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
- breakingOnly: z
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
- .default('./src/app.ts')
256
- .describe('Path to the app module'),
257
- trailId: z.string().optional().describe('Trail ID for detail view'),
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
- output: z.union([
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
- contractVersion: z.string(),
273
- events: z.number(),
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
- readOnly: true,
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
  });