@krisada-m/ksd-intelligence 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/.antigravity-plugin/plugin.json +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +195 -2
  4. package/agy-skills/erosiano-review/SKILL.md +17 -0
  5. package/dist/adapters/agy/skills.js +252 -0
  6. package/dist/adapters/cli/check-changed.js +3 -0
  7. package/dist/adapters/cli/main.js +1013 -0
  8. package/dist/adapters/cli/policy-bin.js +10 -0
  9. package/dist/adapters/cli/review-verdict.js +3 -0
  10. package/dist/adapters/omp/extension.js +884 -0
  11. package/dist/adapters/omp/skills.js +130 -0
  12. package/dist/adapters/ui/hud.js +389 -0
  13. package/dist/adapters/ui/tree.js +471 -0
  14. package/dist/core/audit/index.js +2 -0
  15. package/dist/core/audit/log.js +505 -0
  16. package/dist/core/audit/summary.js +188 -0
  17. package/dist/core/changes/changes.js +591 -0
  18. package/dist/core/changes/git.js +266 -0
  19. package/dist/core/changes/plan.js +109 -0
  20. package/dist/core/changes/render.js +356 -0
  21. package/dist/core/engine/build.js +178 -0
  22. package/dist/core/engine/child.js +389 -0
  23. package/dist/core/engine/host.js +206 -0
  24. package/dist/core/engine/lock.js +133 -0
  25. package/dist/core/engine/protocol.js +43 -0
  26. package/dist/core/engine/runtime.js +44 -0
  27. package/dist/core/engine/status.js +452 -0
  28. package/dist/core/engine/typescript.js +194 -0
  29. package/dist/core/engine/workspace.js +72 -0
  30. package/dist/core/graph/graph.js +127 -0
  31. package/dist/core/graph/limits.js +16 -0
  32. package/dist/core/impact/query.js +1292 -0
  33. package/dist/core/impact/render.js +590 -0
  34. package/dist/core/impact/session.js +694 -0
  35. package/dist/core/indexing/declarations.js +455 -0
  36. package/dist/core/indexing/differential.js +345 -0
  37. package/dist/core/indexing/doctor.js +120 -0
  38. package/dist/core/indexing/indexer.js +811 -0
  39. package/dist/core/indexing/keys.js +451 -0
  40. package/dist/core/indexing/lexical.js +212 -0
  41. package/dist/core/indexing/packages.js +57 -0
  42. package/dist/core/indexing/program.js +171 -0
  43. package/dist/core/indexing/resolve.js +1004 -0
  44. package/dist/core/indexing/stamp.js +52 -0
  45. package/dist/core/indexing/surface.js +335 -0
  46. package/dist/core/indexing/ui-progress.js +37 -0
  47. package/dist/core/indexing/verify.js +76 -0
  48. package/dist/core/kernel/config.js +383 -0
  49. package/dist/core/kernel/glob.js +105 -0
  50. package/dist/core/kernel/guards.js +4 -0
  51. package/dist/core/kernel/types.js +3 -0
  52. package/dist/core/kernel/verdict.js +142 -0
  53. package/dist/core/knowledge/anchors.js +139 -0
  54. package/dist/core/knowledge/knowledge.js +95 -0
  55. package/dist/core/knowledge/learning.js +102 -0
  56. package/dist/core/knowledge/render.js +76 -0
  57. package/dist/core/knowledge/store.js +109 -0
  58. package/dist/core/knowledge/yaml.js +87 -0
  59. package/dist/core/search/lexical.js +382 -0
  60. package/dist/core/search/render.js +98 -0
  61. package/dist/core/search/segments.js +118 -0
  62. package/dist/core/verify/parse.js +127 -0
  63. package/dist/core/verify/render.js +67 -0
  64. package/dist/core/verify/report.js +40 -0
  65. package/dist/core/verify/revision.js +79 -0
  66. package/dist/core/verify/run.js +117 -0
  67. package/dist/core/verify/store.js +66 -0
  68. package/dist/core/verify/verify.js +173 -0
  69. package/dist/core/workspace/init.js +267 -0
  70. package/dist/core/workspace/probe.js +56 -0
  71. package/dist/core/workspace/scan.js +420 -0
  72. package/dist/engineering/baseline.js +337 -0
  73. package/dist/engineering/change-scope.js +500 -0
  74. package/dist/engineering/check-changed.js +40 -0
  75. package/dist/engineering/config.js +129 -0
  76. package/dist/engineering/dist/policy.d.ts +17 -0
  77. package/dist/engineering/dist/policy.js +150 -0
  78. package/dist/engineering/dist/runtime.d.ts +40 -0
  79. package/dist/engineering/dist/runtime.js +77 -0
  80. package/dist/engineering/dist/sdlc.d.ts +7 -0
  81. package/dist/engineering/dist/sdlc.js +27 -0
  82. package/dist/engineering/eslint-rules/index.js +107 -0
  83. package/dist/engineering/index.d.ts +7 -0
  84. package/dist/engineering/index.js +319 -0
  85. package/dist/engineering/intelligence.js +44 -0
  86. package/dist/engineering/package.json +36 -0
  87. package/dist/engineering/policy.js +2 -0
  88. package/dist/engineering/practice-tool.js +72 -0
  89. package/dist/engineering/practices.js +283 -0
  90. package/dist/engineering/practices.json +2453 -0
  91. package/dist/engineering/review-verdict.js +262 -0
  92. package/dist/engineering/sdlc.js +2 -0
  93. package/dist/index.js +20 -0
  94. package/dist/storage/records.js +245 -0
  95. package/dist/storage/sqlite.js +314 -0
  96. package/dist/workflow/catalog.js +69 -0
  97. package/dist/workflow/classify.js +55 -0
  98. package/dist/workflow/loader.js +140 -0
  99. package/dist/workflow/packs.js +469 -0
  100. package/dist/workflow/registry.js +359 -0
  101. package/dist/workflow/render.js +61 -0
  102. package/dist/workflow/router.js +141 -0
  103. package/dist/workflow/sources.js +229 -0
  104. package/dist/workflow/types.js +44 -0
  105. package/dist/workflow/updates.js +532 -0
  106. package/engineering.lock.json +94 -0
  107. package/package.json +81 -4
  108. package/rules/engineering.md +20 -0
  109. package/scripts/agy-mcp.mjs +27 -0
  110. package/scripts/mcp/engineering.mjs +91 -0
  111. package/scripts/mcp/stdio.mjs +304 -0
  112. package/scripts/mcp/tools.mjs +491 -0
  113. package/skills/ksd-intelligence/SKILL.md +54 -0
  114. package/skills/matt-sdlc/SKILL.md +42 -0
  115. package/skills/osmani-quality/SKILL.md +38 -0
  116. package/skills/poteto-mode/SKILL.md +40 -0
  117. package/skills/pstack-analysis/SKILL.md +36 -0
  118. package/skills.lock.json +71 -0
  119. package/skills.registry.json +181 -0
@@ -0,0 +1,471 @@
1
+ const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
2
+ // Escape before applying ANSI so repository-controlled text cannot alter terminal state.
3
+ function safe(text) {
4
+ return text.replace(/[\u0000-\u001f\u007f-\u009f]/g, (char) => {
5
+ if (char === '\n')
6
+ return '\\n';
7
+ if (char === '\t')
8
+ return '\\t';
9
+ return `\\u{${char.codePointAt(0)?.toString(16).padStart(2, '0')}}`;
10
+ });
11
+ }
12
+ function width(text) {
13
+ let size = 0;
14
+ for (const cluster of graphemes.segment(text)) {
15
+ const code = cluster.segment.codePointAt(0) ?? 0;
16
+ if (/\p{Mark}/u.test(cluster.segment[0] ?? '') || code === 0x200d)
17
+ continue;
18
+ size +=
19
+ code >= 0x1100 &&
20
+ (code <= 0x115f ||
21
+ (code >= 0x2329 && code <= 0x232a) ||
22
+ (code >= 0x2e80 && code <= 0xa4cf) ||
23
+ (code >= 0xac00 && code <= 0xd7a3) ||
24
+ (code >= 0xf900 && code <= 0xfaff) ||
25
+ (code >= 0xfe10 && code <= 0xfe6f) ||
26
+ (code >= 0xff01 && code <= 0xff60) ||
27
+ (code >= 0xffe0 && code <= 0xffe6) ||
28
+ code >= 0x1f000)
29
+ ? 2
30
+ : 1;
31
+ }
32
+ return size;
33
+ }
34
+ function styled(text, role, options) {
35
+ const escaped = safe(text);
36
+ if (!options.color || role === undefined)
37
+ return escaped;
38
+ const code = {
39
+ success: '32',
40
+ warning: '33',
41
+ unknown: '35',
42
+ error: '31',
43
+ critical: '1;31',
44
+ dim: '2',
45
+ tag: '36',
46
+ }[role];
47
+ return `\u001b[${code}m${escaped}\u001b[0m`;
48
+ }
49
+ function symbol(role, options) {
50
+ if (role === 'success')
51
+ return options.ascii ? 'ok' : '✓';
52
+ if (role === 'warning')
53
+ return options.ascii ? '!' : '⚠';
54
+ if (role === 'error' || role === 'critical')
55
+ return options.ascii ? 'x' : '✗';
56
+ return '?';
57
+ }
58
+ function actionRole(verdict) {
59
+ if (verdict.action === 'ask-owner')
60
+ return 'error';
61
+ if (verdict.action === 'run-tests')
62
+ return 'warning';
63
+ if (verdict.action === 'check-gaps' || verdict.level === 'unknown')
64
+ return 'unknown';
65
+ return 'success';
66
+ }
67
+ function headline(target, verdict, completeness, options) {
68
+ const role = actionRole(verdict);
69
+ const levelRole = verdict.level === 'critical' ? 'critical' : role;
70
+ return `${styled(symbol(role, options), role, options)} ${styled(target, undefined, options)} ${styled(verdict.action, role, options)} · ${styled(verdict.level, levelRole, options)} · ${safe(completeness)}`;
71
+ }
72
+ function label(key) {
73
+ return key.includes('#')
74
+ ? key.slice(key.lastIndexOf('#') + 1)
75
+ : key.slice(key.lastIndexOf('/') + 1);
76
+ }
77
+ function fileOf(key) {
78
+ return key.split('#', 1)[0] ?? key;
79
+ }
80
+ function shortLocations(locations) {
81
+ const basenames = new Map();
82
+ const paths = new Set(locations);
83
+ for (const path of paths) {
84
+ const base = path.split('/').at(-1) ?? path;
85
+ basenames.set(base, (basenames.get(base) ?? 0) + 1);
86
+ }
87
+ const result = new Map();
88
+ for (const path of paths) {
89
+ const base = path.split('/').at(-1) ?? path;
90
+ result.set(path, basenames.get(base) === 1 ? base : path);
91
+ }
92
+ return result;
93
+ }
94
+ function nodeRows(nodes) {
95
+ return [...nodes]
96
+ .sort((a, b) => label(a.symbol).localeCompare(label(b.symbol)) ||
97
+ a.span.file.localeCompare(b.span.file) ||
98
+ a.span.startLine - b.span.startLine)
99
+ .map((node) => ({
100
+ text: label(node.symbol),
101
+ location: `${node.span.file}:${node.span.startLine}`,
102
+ tag: node.gapScoped ? 'gap' : node.route ? 'route' : undefined,
103
+ }));
104
+ }
105
+ function section(name, rows) {
106
+ return { text: name, role: 'dim', children: rows };
107
+ }
108
+ function folded(rows, options) {
109
+ if (options.all || rows.length <= 10)
110
+ return rows;
111
+ return [...rows.slice(0, 10), { text: `+ ${rows.length - 10} more (--all)`, role: 'dim' }];
112
+ }
113
+ function wrapWords(text, room) {
114
+ const words = safe(text).split(/ +/);
115
+ const lines = [];
116
+ let current = '';
117
+ for (const word of words) {
118
+ if (current && width(`${current} ${word}`) > room) {
119
+ lines.push(current);
120
+ current = word;
121
+ }
122
+ else {
123
+ current = current ? `${current} ${word}` : word;
124
+ }
125
+ }
126
+ lines.push(current);
127
+ return lines;
128
+ }
129
+ function linesFor(rows, options) {
130
+ const output = [];
131
+ const paths = shortLocations(rows.flatMap(function collect(row) {
132
+ return [row.location ?? '', ...(row.children ?? []).flatMap(collect)]
133
+ .filter(Boolean)
134
+ .map((item) => item.replace(/:\d+$/, ''));
135
+ }));
136
+ const draw = (items, prefix) => {
137
+ items.forEach((row, index) => {
138
+ const last = index === items.length - 1;
139
+ const continuing = options.ascii ? '| ' : '│ ';
140
+ const joint = options.ascii ? '|- ' : '├─ ';
141
+ const end = options.ascii ? '\\- ' : '└─ ';
142
+ const branch = last ? ' ' : continuing;
143
+ const connector = last ? end : joint;
144
+ const location = row.location;
145
+ const path = location?.replace(/:\d+$/, '') ?? '';
146
+ const displayed = location === undefined ? '' : `${paths.get(path) ?? path}${location.slice(path.length)}`;
147
+ const tag = row.tag ? ` ${row.tag}` : '';
148
+ const text = safe(row.text) + tag;
149
+ const displayLocation = safe(displayed);
150
+ const inline = displayed !== '' &&
151
+ options.columns >= 60 &&
152
+ width(prefix + connector + text + ' ' + displayLocation) <= options.columns;
153
+ const wrapped = inline
154
+ ? [safe(row.text)]
155
+ : wrapWords(row.text, Math.max(12, options.columns - width(prefix + connector + tag)));
156
+ output.push(`${prefix}${connector}${styled(wrapped[0] ?? '', row.role, options)}${row.tag ? ` ${styled(row.tag, row.tag === 'gap' ? 'unknown' : 'tag', options)}` : ''}${inline ? ` ${styled(displayed, 'dim', options)}` : ''}`);
157
+ for (const continuation of wrapped.slice(1))
158
+ output.push(`${prefix}${branch}${styled(continuation, row.role, options)}`);
159
+ if (displayed !== '' && !inline)
160
+ output.push(`${prefix}${branch}${styled(displayed, 'dim', options)}`);
161
+ if (row.children?.length)
162
+ draw(folded(row.children, options), prefix + branch);
163
+ });
164
+ };
165
+ draw(rows, '');
166
+ return output;
167
+ }
168
+ function footer(index, scanned, engine) {
169
+ return `${index}${scanned === undefined ? '' : ` · ${scanned} files`}${engine === undefined ? '' : ` · engine ${engine}`}`;
170
+ }
171
+ function renderImpactResult(result, batch, options) {
172
+ const rows = [
173
+ section(`reach ${result.reach.direct} → ${result.reach.total} · ${result.reach.files} files · ${result.reach.packages} pkgs · ${result.reach.routes} routes`, []),
174
+ ];
175
+ if (result.factors.length)
176
+ rows.push(section('risk', folded(result.factors.map((text) => ({ text })), options)));
177
+ if (result.byDepth.some((level) => level.length))
178
+ rows.push(section('callers', result.byDepth.flatMap((nodes, index) => nodes.length ? [section(`depth ${index + 1}`, nodeRows(nodes))] : [])));
179
+ if (result.bridged.length)
180
+ rows.push(section('gaps · heuristic bridges', nodeRows(result.bridged)));
181
+ if (result.tests.length)
182
+ rows.push(section('tests', result.tests.map((path) => ({ text: label(path), location: path, tag: 'test' }))));
183
+ if (result.completeness.reasons.length)
184
+ rows.push(section('gaps', result.completeness.reasons.map((text) => ({ text, role: 'unknown' }))));
185
+ if (result.verdict.requiredActions.length)
186
+ rows.push(section('next', result.verdict.requiredActions.map((text) => ({ text }))));
187
+ const header = headline(label(result.target), result.verdict, result.completeness.status, options);
188
+ if (options.collapsed)
189
+ return [header];
190
+ return [
191
+ header,
192
+ ...linesFor(rows, options),
193
+ styled(footer(`index ${batch.index.state}`, result.scannedFiles, result.engine.version), 'dim', options),
194
+ ];
195
+ }
196
+ function renderImpactAnswer(answer, batch, options) {
197
+ if (answer.kind !== 'result') {
198
+ const role = answer.kind === 'failure' ? 'error' : 'unknown';
199
+ return [
200
+ styled(`${symbol(role, options)} ${answer.input} ${answer.code}: ${answer.message}`, role, options),
201
+ ];
202
+ }
203
+ const value = answer.value;
204
+ if ('target' in value)
205
+ return renderImpactResult(value, batch, options);
206
+ const file = value;
207
+ const result = file.aggregate;
208
+ const heading = result
209
+ ? headline(file.file, result.verdict, result.completeness.status, options)
210
+ : `${symbol('unknown', options)} ${safe(file.file)} · ${file.results.length} exported symbols`;
211
+ if (options.collapsed)
212
+ return [heading];
213
+ const rows = file.results.map((entry) => ({
214
+ text: `${label(entry.target)} ${entry.verdict.action} · ${entry.verdict.level}`,
215
+ location: entry.span ? `${entry.span.file}:${entry.span.startLine}` : undefined,
216
+ }));
217
+ if (file.remainder)
218
+ rows.push({ text: `${file.remainder} other declarations` });
219
+ return [
220
+ heading,
221
+ ...linesFor([
222
+ section('symbols', rows),
223
+ ...(result ? [section(`reach ${result.reach.direct} → ${result.reach.total}`, [])] : []),
224
+ ], options),
225
+ styled(footer(`index ${batch.index.state}`, file.scannedFiles, file.engine?.version), 'dim', options),
226
+ ];
227
+ }
228
+ function outcomeHeader(name, outcome, options) {
229
+ if (outcome.kind === 'result')
230
+ return null;
231
+ const role = outcome.kind === 'failure' ? 'error' : 'unknown';
232
+ return styled(`${symbol(role, options)} ${name} ${outcome.code}: ${outcome.message}`, role, options);
233
+ }
234
+ function renderChanges({ value: outcome, verificationNote }, options) {
235
+ const unavailable = outcomeHeader('changes', outcome, options);
236
+ if (unavailable !== null)
237
+ return [unavailable];
238
+ if (outcome.kind !== 'result')
239
+ return [];
240
+ const result = outcome.value;
241
+ const header = headline('changes', result.verdict, result.impact.completeness.status, options);
242
+ if (options.collapsed)
243
+ return [header];
244
+ const rows = [];
245
+ if (result.nothingChanged)
246
+ rows.push(section('changed', [{ text: 'nothing changed' }]));
247
+ else {
248
+ rows.push(section('changed', result.changedSymbols.map((item) => ({
249
+ text: `${label(item.symbol)} · ${item.change}`,
250
+ location: item.span ? `${item.span.file}:${item.span.startLine}` : fileOf(item.symbol),
251
+ children: item.directCallers?.length
252
+ ? [section('callers', nodeRows(item.directCallers))]
253
+ : undefined,
254
+ }))));
255
+ }
256
+ if (result.changedFiles.length)
257
+ rows.push(section('files', result.changedFiles.map((item) => ({
258
+ text: `${item.status} ${item.indexed ? 'indexed' : 'outside index'}`,
259
+ location: item.path,
260
+ }))));
261
+ if (result.unindexedDetails?.length)
262
+ rows.push(section('gaps', result.unindexedDetails.map((item) => ({
263
+ text: `${item.reason} · ${item.status}`,
264
+ location: item.path,
265
+ role: 'unknown',
266
+ }))));
267
+ else if (result.unindexedChanges.length)
268
+ rows.push(section('gaps', result.unindexedChanges.map((path) => ({
269
+ text: 'outside index',
270
+ location: path,
271
+ role: 'unknown',
272
+ }))));
273
+ if (result.impact.tests.length)
274
+ rows.push(section('tests', result.impact.tests.map((path) => ({ text: label(path), location: path, tag: 'test' }))));
275
+ if (result.impact.completeness.reasons.length)
276
+ rows.push(section('gaps', result.impact.completeness.reasons.map((text) => ({ text, role: 'unknown' }))));
277
+ const changed = result.nothingChanged !== true && result.changedFiles.length > 0;
278
+ if (changed && verificationNote?.line !== undefined) {
279
+ rows.push(section('verification', [{ text: verificationNote.line }]));
280
+ }
281
+ const nextHint = changed ? verificationNote?.nextHint : undefined;
282
+ if (result.verdict.requiredActions.length || nextHint !== undefined) {
283
+ const next = result.verdict.requiredActions.map((text) => ({ text }));
284
+ if (nextHint !== undefined)
285
+ next.push({ text: nextHint.trimStart() });
286
+ rows.push(section('next', next));
287
+ }
288
+ return [
289
+ header,
290
+ ...linesFor(rows, options),
291
+ styled(footer(`index ${result.indexState ?? 'unknown'}`, result.scannedFiles, result.engine.version), 'dim', options),
292
+ ];
293
+ }
294
+ function renderSearch(outcome, options) {
295
+ const unavailable = outcomeHeader('search', outcome, options);
296
+ if (unavailable !== null)
297
+ return [unavailable];
298
+ if (outcome.kind !== 'result')
299
+ return [];
300
+ const value = outcome.value;
301
+ const role = value.indexState === 'stale' ? 'unknown' : 'success';
302
+ const header = `${styled(symbol(role, options), role, options)} search ${safe(value.query)} · ${value.totalMatches} matches · ${value.indexState}`;
303
+ if (options.collapsed)
304
+ return [header];
305
+ const rows = [
306
+ section('matches', value.hits.map((hit) => ({
307
+ text: `${label(hit.symbol)} · ${hit.kind}`,
308
+ location: `${hit.span.file}:${hit.span.startLine}`,
309
+ tag: hit.route ? 'route' : undefined,
310
+ }))),
311
+ ];
312
+ if (!value.hits.length && value.totalMatches === 0)
313
+ rows.push(section('next', [
314
+ {
315
+ text: value.indexState === 'stale' ? 'refresh index and search again' : 'try another query',
316
+ },
317
+ ]));
318
+ if (value.staleReason)
319
+ rows.push(section('gaps', [{ text: value.staleReason, role: 'unknown' }]));
320
+ if (value.totalMatches > value.hits.length)
321
+ rows.push(section('next', [
322
+ {
323
+ text: `${value.totalMatches - value.hits.length} matches outside retrieved limit ${value.limit}; refine query or increase --limit`,
324
+ },
325
+ ]));
326
+ return [
327
+ header,
328
+ ...linesFor(rows, options),
329
+ styled(footer(`index ${value.indexState}`, value.scannedFiles, value.engine.version), 'dim', options),
330
+ ];
331
+ }
332
+ function renderStatus(status, options) {
333
+ const role = status.state === 'ready' ? 'success' : 'warning';
334
+ const header = `${styled(symbol(role, options), role, options)} status ${styled(status.state, role, options)}${status.reason ? ` · ${safe(status.reason)}` : ''}`;
335
+ if (options.collapsed)
336
+ return [header];
337
+ const index = status.index;
338
+ const rows = [
339
+ section('index', index
340
+ ? [
341
+ {
342
+ text: `${index.coverage.indexable} indexable · ${index.coverage.scanned} scanned · ${index.coverage.packages} packages`,
343
+ },
344
+ { text: `${index.graph.declarations} declarations · ${index.graph.edges} edges` },
345
+ section('extraction', ['ok', 'lexical', 'not-in-program', 'parse-error'].map((name) => ({
346
+ text: `${name} ${(index.graph.extraction[name] ?? 0).toLocaleString('en-US')}`,
347
+ }))),
348
+ ...index.tsconfigErrors.map((text) => ({ text, role: 'unknown' })),
349
+ ]
350
+ : [{ text: status.indexError ?? 'none yet', role: 'unknown' }]),
351
+ ...(index
352
+ ? [
353
+ section('unindexed', Object.entries(index.coverage.reasons)
354
+ .sort(([a, aCount], [b, bCount]) => bCount - aCount || a.localeCompare(b))
355
+ .map(([reason, count]) => ({ text: `${reason} ${count.toLocaleString('en-US')}` }))),
356
+ ]
357
+ : []),
358
+ section('runtime', [
359
+ {
360
+ text: `${status.runtime.kind} ${status.runtime.version} · TypeScript ${status.typescript.ok ? status.typescript.runtime.version : status.typescript.reason}`,
361
+ },
362
+ ]),
363
+ section('config', [
364
+ { text: status.config.path ?? 'defaults · run ei init' },
365
+ ...status.config.errors.map((text) => ({ text, role: 'unknown' })),
366
+ ...(status.includeWarnings ?? []).map((text) => ({ text, role: 'warning' })),
367
+ ]),
368
+ section('store', [{ text: index?.path ?? status.cacheDir }]),
369
+ ];
370
+ if (status.failure)
371
+ rows.push(section('gaps', [
372
+ {
373
+ text: `${status.failure.reason}: ${status.failure.problems.join('; ')}`,
374
+ role: 'unknown',
375
+ },
376
+ ]));
377
+ if (status.auditWarning)
378
+ rows.push(section('gaps', [{ text: status.auditWarning, role: 'unknown' }]));
379
+ if (status.fix)
380
+ rows.push(section('next', [{ text: status.fix }]));
381
+ return [
382
+ header,
383
+ ...linesFor(rows, options),
384
+ styled(footer('status', index?.coverage.scanned, index?.meta.engine_version), 'dim', options),
385
+ ];
386
+ }
387
+ function renderAudit(audit, options) {
388
+ const role = audit.corruptLines ? 'warning' : 'success';
389
+ const header = `${styled(symbol(role, options), role, options)} audit · ${audit.totalCalls} calls${audit.since ? ` · since ${safe(audit.since)}` : ''}`;
390
+ if (options.collapsed)
391
+ return [header];
392
+ const counted = (source) => Object.entries(source)
393
+ .sort(([a], [b]) => a.localeCompare(b))
394
+ .map(([name, count]) => ({ text: `${name} ${count}` }));
395
+ const rows = [
396
+ section('tools', counted(audit.callsByTool)),
397
+ section('risk', counted(audit.verdictDistribution)),
398
+ section('gaps', [
399
+ ...(audit.corruptLines
400
+ ? [{ text: `${audit.corruptLines} corrupt lines`, role: 'unknown' }]
401
+ : []),
402
+ ...audit.changedWithoutPriorImpact.map((text) => ({ text, role: 'unknown' })),
403
+ ]),
404
+ ];
405
+ return [
406
+ header,
407
+ ...linesFor(rows, options),
408
+ styled(`${audit.filesRead} audit files read`, 'dim', options),
409
+ ];
410
+ }
411
+ function renderSkills(input, options) {
412
+ const { discovery, registryIssues } = input;
413
+ const issues = [...discovery.issues, ...registryIssues];
414
+ const role = issues.length ? 'warning' : 'success';
415
+ const header = `${styled(symbol(role, options), role, options)} skills ${safe(input.platform)} · ${discovery.skills.length} discovered · ${issues.length} issues`;
416
+ if (options.collapsed)
417
+ return [header];
418
+ const rows = [
419
+ section('skills', discovery.skills.map((skill) => ({
420
+ text: `${skill.name} · ${skill.explicitOnly ? 'opt-in' : 'auto'} · ${skill.sourceLabel}`,
421
+ location: skill.file,
422
+ }))),
423
+ ...(issues.length
424
+ ? [
425
+ section('gaps', issues.map((issue) => ({
426
+ text: `${issue.code}: ${issue.message}`,
427
+ role: 'unknown',
428
+ }))),
429
+ ]
430
+ : []),
431
+ ];
432
+ return [
433
+ header,
434
+ ...linesFor(rows, options),
435
+ styled(`${discovery.autoVisible.length} auto · ${discovery.explicitOnly.length} opt-in`, 'dim', options),
436
+ ];
437
+ }
438
+ export function renderResultView(input, options) {
439
+ if (input.kind === 'impact') {
440
+ const rows = input.value.answers.flatMap((answer, index) => [
441
+ ...(index ? [''] : []),
442
+ ...renderImpactAnswer(answer, input.value, options),
443
+ ]);
444
+ if (!options.collapsed && input.learningsLine !== undefined) {
445
+ rows.push(safe(input.learningsLine));
446
+ }
447
+ return rows;
448
+ }
449
+ if (input.kind === 'changes')
450
+ return renderChanges(input, options);
451
+ if (input.kind === 'search')
452
+ return renderSearch(input.value, options);
453
+ if (input.kind === 'status')
454
+ return renderStatus(input.value, options);
455
+ if (input.kind === 'audit')
456
+ return renderAudit(input.value, options);
457
+ return renderSkills(input, options);
458
+ }
459
+ export function terminalViewOptions(input) {
460
+ if (input.json || input.plain || input.env.NO_COLOR !== undefined || input.env.TERM === 'dumb')
461
+ return undefined;
462
+ if (!input.isTTY && (!input.env.FORCE_COLOR || input.env.FORCE_COLOR === '0'))
463
+ return undefined;
464
+ return {
465
+ columns: input.columns,
466
+ color: input.env.FORCE_COLOR !== '0',
467
+ ascii: input.env.EI_ASCII === '1' ||
468
+ !/utf-?8/i.test(input.env.LC_ALL ?? input.env.LC_CTYPE ?? input.env.LANG ?? 'UTF-8'),
469
+ all: input.all,
470
+ };
471
+ }
@@ -0,0 +1,2 @@
1
+ export { AUDIT_FILE, MAX_AUDIT_BYTES, MAX_QUERY_CHARS, MAX_ROTATIONS, MAX_TASK_CHARS, auditFieldsForChanges, auditFieldsForImpact, auditFieldsForSearch, auditFieldsForWorkflow, clearAuditState, consumeAuditWarning, recordAudit, sanitizeAuditText, stripCodeDetail, } from './log.js';
2
+ export { parseSince, renderAuditSummary, summarizeAudit } from './summary.js';