@krisada-m/ksd-intelligence 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +167 -2
- package/dist/adapters/agy/skills.js +252 -0
- package/dist/adapters/cli/check-changed.js +3 -0
- package/dist/adapters/cli/main.js +1002 -0
- package/dist/adapters/cli/policy-bin.js +10 -0
- package/dist/adapters/cli/review-verdict.js +3 -0
- package/dist/adapters/omp/extension.js +893 -0
- package/dist/adapters/omp/skills.js +130 -0
- package/dist/adapters/ui/hud.js +318 -0
- package/dist/adapters/ui/tree.js +460 -0
- package/dist/core/audit/index.js +2 -0
- package/dist/core/audit/log.js +505 -0
- package/dist/core/audit/summary.js +188 -0
- package/dist/core/changes/changes.js +591 -0
- package/dist/core/changes/git.js +266 -0
- package/dist/core/changes/plan.js +109 -0
- package/dist/core/changes/render.js +356 -0
- package/dist/core/engine/build.js +178 -0
- package/dist/core/engine/child.js +389 -0
- package/dist/core/engine/host.js +206 -0
- package/dist/core/engine/lock.js +133 -0
- package/dist/core/engine/protocol.js +43 -0
- package/dist/core/engine/runtime.js +44 -0
- package/dist/core/engine/status.js +381 -0
- package/dist/core/engine/typescript.js +194 -0
- package/dist/core/engine/workspace.js +72 -0
- package/dist/core/graph/graph.js +127 -0
- package/dist/core/graph/limits.js +16 -0
- package/dist/core/impact/query.js +1292 -0
- package/dist/core/impact/render.js +590 -0
- package/dist/core/impact/session.js +694 -0
- package/dist/core/indexing/declarations.js +455 -0
- package/dist/core/indexing/differential.js +345 -0
- package/dist/core/indexing/doctor.js +120 -0
- package/dist/core/indexing/indexer.js +792 -0
- package/dist/core/indexing/keys.js +451 -0
- package/dist/core/indexing/lexical.js +212 -0
- package/dist/core/indexing/packages.js +57 -0
- package/dist/core/indexing/program.js +171 -0
- package/dist/core/indexing/resolve.js +1004 -0
- package/dist/core/indexing/stamp.js +52 -0
- package/dist/core/indexing/surface.js +335 -0
- package/dist/core/indexing/ui-progress.js +37 -0
- package/dist/core/indexing/verify.js +76 -0
- package/dist/core/kernel/config.js +383 -0
- package/dist/core/kernel/glob.js +105 -0
- package/dist/core/kernel/guards.js +4 -0
- package/dist/core/kernel/types.js +3 -0
- package/dist/core/kernel/verdict.js +142 -0
- package/dist/core/knowledge/anchors.js +139 -0
- package/dist/core/knowledge/knowledge.js +95 -0
- package/dist/core/knowledge/learning.js +102 -0
- package/dist/core/knowledge/render.js +76 -0
- package/dist/core/knowledge/store.js +109 -0
- package/dist/core/knowledge/yaml.js +87 -0
- package/dist/core/search/lexical.js +382 -0
- package/dist/core/search/render.js +98 -0
- package/dist/core/search/segments.js +118 -0
- package/dist/core/verify/parse.js +127 -0
- package/dist/core/verify/render.js +67 -0
- package/dist/core/verify/report.js +40 -0
- package/dist/core/verify/revision.js +79 -0
- package/dist/core/verify/run.js +117 -0
- package/dist/core/verify/store.js +66 -0
- package/dist/core/verify/verify.js +173 -0
- package/dist/core/workspace/init.js +267 -0
- package/dist/core/workspace/probe.js +56 -0
- package/dist/core/workspace/scan.js +420 -0
- package/dist/index.js +20 -0
- package/dist/policy/change-scope.js +500 -0
- package/dist/policy/check-changed.js +40 -0
- package/dist/policy/config.js +106 -0
- package/dist/policy/dist/policy.d.ts +17 -0
- package/dist/policy/dist/policy.js +147 -0
- package/dist/policy/dist/runtime.d.ts +40 -0
- package/dist/policy/dist/runtime.js +75 -0
- package/dist/policy/dist/sdlc.d.ts +7 -0
- package/dist/policy/dist/sdlc.js +27 -0
- package/dist/policy/eslint-rules/index.js +107 -0
- package/dist/policy/index.d.ts +2 -0
- package/dist/policy/index.js +241 -0
- package/dist/policy/package.json +33 -0
- package/dist/policy/policy.d.ts +2 -0
- package/dist/policy/policy.js +2 -0
- package/dist/policy/review-verdict.js +262 -0
- package/dist/policy/sdlc.js +2 -0
- package/dist/storage/records.js +245 -0
- package/dist/storage/sqlite.js +314 -0
- package/dist/workflow/catalog.js +69 -0
- package/dist/workflow/classify.js +55 -0
- package/dist/workflow/loader.js +140 -0
- package/dist/workflow/packs.js +469 -0
- package/dist/workflow/registry.js +359 -0
- package/dist/workflow/render.js +61 -0
- package/dist/workflow/router.js +141 -0
- package/dist/workflow/sources.js +229 -0
- package/dist/workflow/types.js +44 -0
- package/dist/workflow/updates.js +532 -0
- package/package.json +74 -4
- package/scripts/agy-mcp.mjs +27 -0
- package/scripts/mcp/stdio.mjs +304 -0
- package/scripts/mcp/tools.mjs +451 -0
- package/skills/ksd-intelligence/SKILL.md +54 -0
- package/skills/matt-sdlc/SKILL.md +42 -0
- package/skills/osmani-quality/SKILL.md +38 -0
- package/skills/poteto-mode/SKILL.md +40 -0
- package/skills/pstack-analysis/SKILL.md +36 -0
- package/skills.lock.json +71 -0
- package/skills.registry.json +181 -0
|
@@ -0,0 +1,460 @@
|
|
|
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
|
+
...index.tsconfigErrors.map((text) => ({ text, role: 'unknown' })),
|
|
346
|
+
]
|
|
347
|
+
: [{ text: status.indexError ?? 'none yet', role: 'unknown' }]),
|
|
348
|
+
section('runtime', [
|
|
349
|
+
{
|
|
350
|
+
text: `${status.runtime.kind} ${status.runtime.version} · TypeScript ${status.typescript.ok ? status.typescript.runtime.version : status.typescript.reason}`,
|
|
351
|
+
},
|
|
352
|
+
]),
|
|
353
|
+
section('config', [
|
|
354
|
+
{ text: status.config.path ?? 'defaults · run ei init' },
|
|
355
|
+
...status.config.errors.map((text) => ({ text, role: 'unknown' })),
|
|
356
|
+
]),
|
|
357
|
+
section('store', [{ text: index?.path ?? status.cacheDir }]),
|
|
358
|
+
];
|
|
359
|
+
if (status.failure)
|
|
360
|
+
rows.push(section('gaps', [
|
|
361
|
+
{
|
|
362
|
+
text: `${status.failure.reason}: ${status.failure.problems.join('; ')}`,
|
|
363
|
+
role: 'unknown',
|
|
364
|
+
},
|
|
365
|
+
]));
|
|
366
|
+
if (status.auditWarning)
|
|
367
|
+
rows.push(section('gaps', [{ text: status.auditWarning, role: 'unknown' }]));
|
|
368
|
+
if (status.fix)
|
|
369
|
+
rows.push(section('next', [{ text: status.fix }]));
|
|
370
|
+
return [
|
|
371
|
+
header,
|
|
372
|
+
...linesFor(rows, options),
|
|
373
|
+
styled(footer('status', index?.coverage.scanned, index?.meta.engine_version), 'dim', options),
|
|
374
|
+
];
|
|
375
|
+
}
|
|
376
|
+
function renderAudit(audit, options) {
|
|
377
|
+
const role = audit.corruptLines ? 'warning' : 'success';
|
|
378
|
+
const header = `${styled(symbol(role, options), role, options)} audit · ${audit.totalCalls} calls${audit.since ? ` · since ${safe(audit.since)}` : ''}`;
|
|
379
|
+
if (options.collapsed)
|
|
380
|
+
return [header];
|
|
381
|
+
const counted = (source) => Object.entries(source)
|
|
382
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
383
|
+
.map(([name, count]) => ({ text: `${name} ${count}` }));
|
|
384
|
+
const rows = [
|
|
385
|
+
section('tools', counted(audit.callsByTool)),
|
|
386
|
+
section('risk', counted(audit.verdictDistribution)),
|
|
387
|
+
section('gaps', [
|
|
388
|
+
...(audit.corruptLines
|
|
389
|
+
? [{ text: `${audit.corruptLines} corrupt lines`, role: 'unknown' }]
|
|
390
|
+
: []),
|
|
391
|
+
...audit.changedWithoutPriorImpact.map((text) => ({ text, role: 'unknown' })),
|
|
392
|
+
]),
|
|
393
|
+
];
|
|
394
|
+
return [
|
|
395
|
+
header,
|
|
396
|
+
...linesFor(rows, options),
|
|
397
|
+
styled(`${audit.filesRead} audit files read`, 'dim', options),
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
function renderSkills(input, options) {
|
|
401
|
+
const { discovery, registryIssues } = input;
|
|
402
|
+
const issues = [...discovery.issues, ...registryIssues];
|
|
403
|
+
const role = issues.length ? 'warning' : 'success';
|
|
404
|
+
const header = `${styled(symbol(role, options), role, options)} skills ${safe(input.platform)} · ${discovery.skills.length} discovered · ${issues.length} issues`;
|
|
405
|
+
if (options.collapsed)
|
|
406
|
+
return [header];
|
|
407
|
+
const rows = [
|
|
408
|
+
section('skills', discovery.skills.map((skill) => ({
|
|
409
|
+
text: `${skill.name} · ${skill.explicitOnly ? 'opt-in' : 'auto'} · ${skill.sourceLabel}`,
|
|
410
|
+
location: skill.file,
|
|
411
|
+
}))),
|
|
412
|
+
...(issues.length
|
|
413
|
+
? [
|
|
414
|
+
section('gaps', issues.map((issue) => ({
|
|
415
|
+
text: `${issue.code}: ${issue.message}`,
|
|
416
|
+
role: 'unknown',
|
|
417
|
+
}))),
|
|
418
|
+
]
|
|
419
|
+
: []),
|
|
420
|
+
];
|
|
421
|
+
return [
|
|
422
|
+
header,
|
|
423
|
+
...linesFor(rows, options),
|
|
424
|
+
styled(`${discovery.autoVisible.length} auto · ${discovery.explicitOnly.length} opt-in`, 'dim', options),
|
|
425
|
+
];
|
|
426
|
+
}
|
|
427
|
+
export function renderResultView(input, options) {
|
|
428
|
+
if (input.kind === 'impact') {
|
|
429
|
+
const rows = input.value.answers.flatMap((answer, index) => [
|
|
430
|
+
...(index ? [''] : []),
|
|
431
|
+
...renderImpactAnswer(answer, input.value, options),
|
|
432
|
+
]);
|
|
433
|
+
if (!options.collapsed && input.learningsLine !== undefined) {
|
|
434
|
+
rows.push(safe(input.learningsLine));
|
|
435
|
+
}
|
|
436
|
+
return rows;
|
|
437
|
+
}
|
|
438
|
+
if (input.kind === 'changes')
|
|
439
|
+
return renderChanges(input, options);
|
|
440
|
+
if (input.kind === 'search')
|
|
441
|
+
return renderSearch(input.value, options);
|
|
442
|
+
if (input.kind === 'status')
|
|
443
|
+
return renderStatus(input.value, options);
|
|
444
|
+
if (input.kind === 'audit')
|
|
445
|
+
return renderAudit(input.value, options);
|
|
446
|
+
return renderSkills(input, options);
|
|
447
|
+
}
|
|
448
|
+
export function terminalViewOptions(input) {
|
|
449
|
+
if (input.json || input.plain || input.env.NO_COLOR !== undefined || input.env.TERM === 'dumb')
|
|
450
|
+
return undefined;
|
|
451
|
+
if (!input.isTTY && (!input.env.FORCE_COLOR || input.env.FORCE_COLOR === '0'))
|
|
452
|
+
return undefined;
|
|
453
|
+
return {
|
|
454
|
+
columns: input.columns,
|
|
455
|
+
color: input.env.FORCE_COLOR !== '0',
|
|
456
|
+
ascii: input.env.EI_ASCII === '1' ||
|
|
457
|
+
!/utf-?8/i.test(input.env.LC_ALL ?? input.env.LC_CTYPE ?? input.env.LANG ?? 'UTF-8'),
|
|
458
|
+
all: input.all,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
@@ -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';
|