@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,130 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join, resolve } from 'node:path';
4
+ import { defaultSkillsDir, discoverSkillsForPlatform, } from '../../workflow/packs.js';
5
+ // Inspects OMP's profile, RULES.md, config, and skill directories read-only without mutating user state.
6
+ export function detectOmpEnvironment(options = {}) {
7
+ const env = options.env ?? process.env;
8
+ const realHome = options.homeDir ?? env.SNAP_REAL_HOME ?? env.HOME ?? homedir();
9
+ const profile = options.profile ?? env.OMP_PROFILE ?? 'default';
10
+ const agentDir = resolve(options.agentDir ??
11
+ env.PI_CODING_AGENT_DIR ??
12
+ env.OMP_AGENT_DIR ??
13
+ (profile !== 'default'
14
+ ? join(realHome, '.omp', 'profiles', profile, 'agent')
15
+ : join(realHome, '.omp', 'agent')));
16
+ const projectDir = options.workspaceRoot ? resolve(options.workspaceRoot, '.omp') : null;
17
+ const projectSkillsDir = projectDir ? join(projectDir, 'skills') : null;
18
+ const userSkillsDir = join(agentDir, 'skills');
19
+ const sharedSkillsDir = resolve(realHome, '.agents', 'skills');
20
+ const pluginSkillsDir = resolve(options.skillsDir ?? defaultSkillsDir());
21
+ const rulesFiles = [];
22
+ if (projectDir) {
23
+ const projectRules = join(projectDir, 'RULES.md');
24
+ rulesFiles.push({ scope: 'project', path: projectRules, exists: existsSync(projectRules) });
25
+ }
26
+ const userRules = join(agentDir, 'RULES.md');
27
+ rulesFiles.push({ scope: 'user', path: userRules, exists: existsSync(userRules) });
28
+ const configFiles = [];
29
+ if (projectDir) {
30
+ const projectSettings = join(projectDir, 'settings.json');
31
+ configFiles.push({
32
+ kind: 'settings.json',
33
+ scope: 'project',
34
+ path: projectSettings,
35
+ exists: existsSync(projectSettings),
36
+ });
37
+ }
38
+ for (const kind of ['config.yml', 'settings.json', 'engineering-proxy.json']) {
39
+ const file = join(agentDir, kind);
40
+ configFiles.push({ kind, scope: 'user', path: file, exists: existsSync(file) });
41
+ }
42
+ return {
43
+ realHome,
44
+ profile,
45
+ agentDir,
46
+ rulesFiles,
47
+ configFiles,
48
+ projectSkillsDir,
49
+ userSkillsDir,
50
+ sharedSkillsDir,
51
+ pluginSkillsDir,
52
+ };
53
+ }
54
+ // Native OMP skill discovery mirroring `@oh-my-pi/pi-coding-agent` precedence:
55
+ // project `.omp/skills` > active profile/user `<agentDir>/skills` > shared `~/.agents/skills` > marketplace plugin `skills/`.
56
+ // Skills with `disable-model-invocation: true` (e.g. `poteto-mode`) remain in `explicitOnly`.
57
+ export async function discoverOmpSkills(options = {}) {
58
+ const environment = detectOmpEnvironment({
59
+ workspaceRoot: options.workspaceRoot,
60
+ profile: options.profile,
61
+ agentDir: options.agentDir,
62
+ skillsDir: options.skillsDir,
63
+ env: options.env,
64
+ homeDir: options.homeDir,
65
+ });
66
+ const roots = [];
67
+ const seenPaths = new Set();
68
+ const addRoot = (root) => {
69
+ const key = resolve(root.path);
70
+ if (seenPaths.has(key))
71
+ return;
72
+ seenPaths.add(key);
73
+ roots.push(root);
74
+ };
75
+ if (environment.projectSkillsDir) {
76
+ addRoot({
77
+ path: environment.projectSkillsDir,
78
+ label: 'omp:project',
79
+ optional: true,
80
+ });
81
+ }
82
+ if (options.userSkillsDir) {
83
+ addRoot({
84
+ path: options.userSkillsDir,
85
+ label: 'omp:user',
86
+ optional: true,
87
+ allowExternalSymlinks: true,
88
+ auditContent: false,
89
+ });
90
+ }
91
+ else if (options.detectHostPaths || options.profile || options.agentDir) {
92
+ addRoot({
93
+ path: environment.userSkillsDir,
94
+ label: environment.profile === 'default' ? 'omp:user' : `omp:profile:${environment.profile}`,
95
+ optional: true,
96
+ allowExternalSymlinks: true,
97
+ auditContent: false,
98
+ });
99
+ }
100
+ if (options.sharedSkillsDir) {
101
+ addRoot({
102
+ path: options.sharedSkillsDir,
103
+ label: 'omp:shared',
104
+ optional: true,
105
+ allowExternalSymlinks: true,
106
+ auditContent: false,
107
+ });
108
+ }
109
+ else if (options.detectHostPaths) {
110
+ addRoot({
111
+ path: environment.sharedSkillsDir,
112
+ label: 'omp:shared',
113
+ optional: true,
114
+ allowExternalSymlinks: true,
115
+ auditContent: false,
116
+ });
117
+ }
118
+ addRoot({
119
+ path: environment.pluginSkillsDir,
120
+ label: 'omp:plugin:ksd-intelligence',
121
+ optional: false,
122
+ auditContent: true,
123
+ });
124
+ const discovery = await discoverSkillsForPlatform({
125
+ platform: 'omp',
126
+ roots,
127
+ requireCatalog: options.requireCatalog ?? true,
128
+ });
129
+ return { ...discovery, environment };
130
+ }
@@ -0,0 +1,389 @@
1
+ const blocks = ['', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█'];
2
+ const sparkBlocks = '⣀⣄⣤⣦⣶⣷⣿';
3
+ const phaseOrder = ['scan', 'program', 'extract', 'resolve', 'verify', 'publish'];
4
+ const phaseRamp = ['34', '36', '35', '95', '33', '94'];
5
+ const minThroughputMs = 2000;
6
+ const minThroughputSamples = 5;
7
+ const reset = '\x1b[0m';
8
+ function safe(text) {
9
+ return text.replace(/[\x00-\x1f\x7f-\x9f]/g, ' ');
10
+ }
11
+ function duration(ms) {
12
+ if (!Number.isFinite(ms) || ms < 0)
13
+ return '?';
14
+ return `${Number((ms / 1000).toFixed(2))}s`;
15
+ }
16
+ function wrap(text, prefix, columns) {
17
+ const lines = [];
18
+ const indent = ' '.repeat(width(prefix));
19
+ let line = prefix;
20
+ let hasWord = false;
21
+ for (const word of safe(text).split(/ +/)) {
22
+ if (hasWord && width(`${line} ${word}`) > columns) {
23
+ lines.push(line);
24
+ line = indent;
25
+ hasWord = false;
26
+ }
27
+ let remaining = word;
28
+ const room = columns - width(line);
29
+ while (width(remaining) > room) {
30
+ const piece = fit(remaining, room);
31
+ lines.push(line + piece);
32
+ remaining = remaining.slice(piece.length);
33
+ line = indent;
34
+ }
35
+ line += `${hasWord ? ' ' : ''}${remaining}`;
36
+ hasWord = true;
37
+ }
38
+ lines.push(line);
39
+ return lines;
40
+ }
41
+ function width(text) {
42
+ let size = 0;
43
+ for (const char of text) {
44
+ const point = char.codePointAt(0) ?? 0;
45
+ if (/\p{Mark}/u.test(char) || point === 0x200d || point === 0xfe0f)
46
+ continue;
47
+ size +=
48
+ point >= 0x1100 &&
49
+ (point <= 0x11ff ||
50
+ (point >= 0x2e80 && point <= 0xa4cf) ||
51
+ (point >= 0xac00 && point <= 0xd7ff) ||
52
+ (point >= 0xf900 && point <= 0xfaff) ||
53
+ (point >= 0xfe10 && point <= 0xfe6f) ||
54
+ (point >= 0xff01 && point <= 0xff60) ||
55
+ (point >= 0xffe0 && point <= 0xffe6) ||
56
+ (point >= 0x1f300 && point <= 0x1faff))
57
+ ? 2
58
+ : 1;
59
+ }
60
+ return size;
61
+ }
62
+ function fit(text, columns) {
63
+ let result = '';
64
+ let used = 0;
65
+ for (const char of safe(text)) {
66
+ const size = width(char);
67
+ if (used + size > columns)
68
+ break;
69
+ result += char;
70
+ used += size;
71
+ }
72
+ return result;
73
+ }
74
+ function colorTier(env) {
75
+ if (env.COLORTERM === 'truecolor' || env.COLORTERM === '24bit')
76
+ return 'truecolor';
77
+ return env.TERM?.includes('256color') ? '256' : '16';
78
+ }
79
+ function bar(fraction, length, tier, ascii) {
80
+ const eighths = Math.max(0, Math.min(length * 8, Math.round(fraction * length * 8)));
81
+ const full = Math.floor(eighths / 8);
82
+ const rest = eighths % 8;
83
+ if (ascii || tier === '16')
84
+ return `${'#'.repeat(full)}${rest ? ':' : ''}${'.'.repeat(length - full - (rest ? 1 : 0))}`;
85
+ const filled = `${'█'.repeat(full)}${blocks[rest] ?? ''}`;
86
+ if (tier === 'none')
87
+ return filled + '·'.repeat(length - full - (rest ? 1 : 0));
88
+ const ramp = tier === 'truecolor'
89
+ ? [
90
+ '\x1b[38;2;67;190;113m',
91
+ '\x1b[38;2;76;154;240m',
92
+ '\x1b[38;2;163;113;228m',
93
+ '\x1b[38;2;237;119;171m',
94
+ ]
95
+ : ['\x1b[38;5;77m', '\x1b[38;5;75m', '\x1b[38;5;141m', '\x1b[38;5;212m'];
96
+ let colored = '';
97
+ for (let index = 0; index < filled.length; index++) {
98
+ colored += `${ramp[Math.min(3, Math.floor((index * 4) / length))]}${filled[index]}`;
99
+ }
100
+ return `${colored}${reset}${'·'.repeat(length - full - (rest ? 1 : 0))}`;
101
+ }
102
+ function spark(samples, ascii) {
103
+ if (!samples.length)
104
+ return ascii ? '.' : '⣀';
105
+ const max = Math.max(1, ...samples);
106
+ return samples
107
+ .map((sample) => {
108
+ const index = Math.min(6, Math.floor((sample * 7) / max));
109
+ return ascii ? '.:-=+*#'[index] : sparkBlocks[index];
110
+ })
111
+ .join('');
112
+ }
113
+ function color(text, code, enabled) {
114
+ return enabled ? `\x1b[${code}m${text}${reset}` : text;
115
+ }
116
+ export function openHud(options) {
117
+ const { stream, env } = options;
118
+ if (!stream.isTTY ||
119
+ options.plain ||
120
+ options.json ||
121
+ 'NO_COLOR' in env ||
122
+ env.TERM === 'dumb' ||
123
+ 'CI' in env ||
124
+ env.EI_NO_ANIMATION === '1')
125
+ return undefined;
126
+ const tier = colorTier(env);
127
+ const ascii = tier === '16' ||
128
+ env.EI_ASCII === '1' ||
129
+ !/utf-?8/i.test(`${env.LC_ALL ?? env.LC_CTYPE ?? env.LANG ?? ''}`);
130
+ const now = options.now ?? Date.now;
131
+ const started = now();
132
+ const phases = new Map();
133
+ const samples = [];
134
+ let current;
135
+ let observedPhase;
136
+ const observations = [];
137
+ let latestRate = 0;
138
+ let drawnAt = -Infinity;
139
+ let lines = 0;
140
+ let timer;
141
+ let closed = false;
142
+ let cursorHidden = false;
143
+ function erase() {
144
+ if (!lines)
145
+ return;
146
+ stream.write(`\x1b[${lines}A`);
147
+ for (let index = 0; index < lines; index++)
148
+ stream.write('\r\x1b[2K\x1b[1B');
149
+ stream.write(`\x1b[${lines}A`);
150
+ lines = 0;
151
+ }
152
+ function draw() {
153
+ if (closed || !current)
154
+ return;
155
+ const columns = Math.max(20, stream.columns || 80);
156
+ const narrow = columns < 60;
157
+ const glyph = ascii ? ['-', '>', '+'] : ['◇', '◈', '◆'];
158
+ const phaseNames = options.command === 'index'
159
+ ? [...new Set([...phaseOrder, ...phases.keys()])]
160
+ : [...phases.keys()];
161
+ const currentIndex = phaseNames.indexOf(current.phase);
162
+ const prefix = `${ascii ? '|' : '▌'}ei ${options.command} `;
163
+ const elapsed = now() - started;
164
+ const suffix = `${current.kind ? ` · ${current.kind}` : ''} ${duration(elapsed)}`;
165
+ const heading = `${prefix}${fit(options.repo, Math.max(0, columns - width(prefix) - width(suffix)))}${suffix}`;
166
+ const body = [heading];
167
+ if (!narrow && (options.previous || (current.kind === 'cold' && current.reason)))
168
+ body.push(` ${options.previous ? `last run ${duration(options.previous.durationMs)}` : ''}${current.kind === 'cold' && current.reason ? ` · why: ${safe(current.reason)}` : ''}`);
169
+ if (!narrow)
170
+ body.push('');
171
+ for (const [index, phase] of phaseNames.entries()) {
172
+ if (narrow && phase !== current.phase)
173
+ continue;
174
+ const event = phases.get(phase);
175
+ let status = 0;
176
+ if (index === currentIndex)
177
+ status = 1;
178
+ if (index < currentIndex && event)
179
+ status = 2;
180
+ const done = event?.done;
181
+ const total = event?.total;
182
+ const known = done !== undefined &&
183
+ total !== undefined &&
184
+ total > 0 &&
185
+ Number.isFinite(done) &&
186
+ Number.isFinite(total);
187
+ let fraction = status === 2 ? 1 : 0;
188
+ if (known)
189
+ fraction = Math.min(1, Math.max(0, done) / total);
190
+ let beam = bar(fraction, narrow ? 10 : 16, tier, ascii);
191
+ if (!known && status === 1) {
192
+ const length = narrow || ascii ? 10 : 16;
193
+ const position = Math.floor(now() / 100) % length;
194
+ const dot = ascii ? '.' : '·';
195
+ beam = `${dot.repeat(position)}${ascii ? '#' : '█'}${dot.repeat(length - position - 1)}`;
196
+ }
197
+ let count = '';
198
+ if (known)
199
+ count = `${Math.max(0, done).toLocaleString('en-US')}/${total.toLocaleString('en-US')}`;
200
+ if (!known && status === 2)
201
+ count = 'ok';
202
+ if (!known && status === 1)
203
+ count = 'building';
204
+ const label = ` ${glyph[status]} ${phase.padEnd(8)} ${beam} ${count}`;
205
+ body.push(label);
206
+ }
207
+ if (!narrow && elapsed >= minThroughputMs && samples.length >= minThroughputSamples)
208
+ body.push('', ` files/s ${spark(samples, ascii)} ${Math.round(latestRate).toLocaleString('en-US')}`);
209
+ if (current.file)
210
+ body.push(` ${ascii ? '>' : '›'} ${safe(current.file)}`);
211
+ erase();
212
+ if (!cursorHidden) {
213
+ stream.write('\x1b[?25l');
214
+ cursorHidden = true;
215
+ }
216
+ for (const line of body)
217
+ stream.write(`\r\x1b[2K${fitAnsi(line, columns)}\n`);
218
+ lines = body.length;
219
+ drawnAt = now();
220
+ timer = setTimeout(draw, 100);
221
+ timer.unref();
222
+ }
223
+ function update(event) {
224
+ if (closed)
225
+ return;
226
+ const time = now();
227
+ if (event.done !== undefined && Number.isFinite(event.done) && event.done >= 0) {
228
+ if (observedPhase !== event.phase ||
229
+ event.done < (observations[observations.length - 1]?.count ?? 0)) {
230
+ observations.length = 0;
231
+ observedPhase = event.phase;
232
+ }
233
+ const baseline = observations[0];
234
+ if (baseline && time > baseline.time && event.done >= baseline.count) {
235
+ latestRate = ((event.done - baseline.count) * 1000) / (time - baseline.time);
236
+ samples.push(latestRate);
237
+ if (samples.length > 24)
238
+ samples.shift();
239
+ }
240
+ observations.push({ count: event.done, time });
241
+ while (observations.length > 2 && time - (observations[1]?.time ?? time) > 2000)
242
+ observations.shift();
243
+ }
244
+ phases.set(event.phase, event);
245
+ current = {
246
+ ...event,
247
+ kind: event.kind ?? current?.kind,
248
+ reason: event.reason ?? current?.reason,
249
+ };
250
+ if (time - drawnAt < 100)
251
+ return;
252
+ clearTimeout(timer);
253
+ timer = undefined;
254
+ draw();
255
+ }
256
+ return {
257
+ get throughput() {
258
+ return samples;
259
+ },
260
+ update,
261
+ close() {
262
+ if (closed)
263
+ return;
264
+ closed = true;
265
+ clearTimeout(timer);
266
+ erase();
267
+ if (cursorHidden)
268
+ stream.write('\x1b[?25h');
269
+ },
270
+ };
271
+ }
272
+ // Width is measured on visible characters, not ANSI colour controls.
273
+ function fitAnsi(line, columns) {
274
+ const parts = line.split(/(\x1b\[[\d;]*m)/g);
275
+ let remaining = columns;
276
+ let result = '';
277
+ for (const part of parts) {
278
+ if (part.startsWith('\x1b[')) {
279
+ result += part;
280
+ continue;
281
+ }
282
+ const clipped = fit(part, remaining);
283
+ result += clipped;
284
+ remaining -= width(clipped);
285
+ if (remaining <= 0)
286
+ break;
287
+ }
288
+ return line.includes('\x1b[') ? `${result}${reset}` : result;
289
+ }
290
+ export function renderHudSummary(input) {
291
+ const ascii = input.ascii ?? false;
292
+ const columns = Math.max(20, input.columns ?? 80);
293
+ const enabled = input.color === true;
294
+ const success = input.outcome !== 'failed';
295
+ let mark = ascii ? 'ok' : '◆';
296
+ if (!success)
297
+ mark = ascii ? 'x' : '✗';
298
+ const name = `${input.command} ${input.outcome}`;
299
+ const diff = input.previous && success && Number.isFinite(input.previous.durationMs)
300
+ ? input.durationMs - input.previous.durationMs
301
+ : undefined;
302
+ let comparison = '';
303
+ if (diff !== undefined) {
304
+ let sign = '+';
305
+ if (diff < 0)
306
+ sign = ascii ? '-' : '−';
307
+ comparison = ` ${sign}${duration(Math.abs(diff))} vs last`;
308
+ }
309
+ const coverage = success ? input.coverage : undefined;
310
+ const scanned = coverage?.scanned.toLocaleString('en-US');
311
+ const codeFiles = coverage?.codeFiles ?? 0;
312
+ const count = scanned === undefined
313
+ ? ''
314
+ : ` · ${scanned} scanned · ${codeFiles.toLocaleString('en-US')} code files`;
315
+ const header = `${mark} ${name}${input.kind ? ` ${input.kind}` : ''}${count} · ${duration(input.durationMs)}${comparison}`;
316
+ const compiler = coverage?.extraction.ok ?? 0;
317
+ const lexical = coverage?.extraction.lexical ?? 0;
318
+ const notInProgram = coverage?.extraction['not-in-program'] ?? 0;
319
+ const errors = coverage?.extraction['parse-error'] ?? 0;
320
+ const indexed = compiler + lexical + notInProgram + errors;
321
+ const fraction = codeFiles > 0 ? indexed / codeFiles : 0;
322
+ const lowCoverage = codeFiles > 0 && fraction < 0.8;
323
+ const highLexical = lexical * 5 > indexed;
324
+ let tone = '32';
325
+ if (lowCoverage || highLexical)
326
+ tone = '33';
327
+ if (!success || (codeFiles > 0 && fraction < 0.3))
328
+ tone = '31';
329
+ const lines = wrap(header, '', columns).map((line) => color(line, tone, enabled));
330
+ if (input.reason)
331
+ lines.push(...wrap(input.reason, ' ', columns));
332
+ if (input.drift)
333
+ lines.push(` drift ${safe(input.drift)}`);
334
+ if (input.activeIndex && !success)
335
+ lines.push(` in use ${safe(input.activeIndex)}`);
336
+ const phases = input.phases?.filter((phase) => Number.isFinite(phase.durationMs) && phase.durationMs >= 0) ??
337
+ [];
338
+ const totalTime = phases.reduce((sum, phase) => sum + phase.durationMs, 0);
339
+ if (success && phases.length) {
340
+ const extra = Math.max(0, Math.min(24, columns - 12) - phases.length);
341
+ let spent = 0;
342
+ let used = 0;
343
+ const segments = phases.map((phase, index) => {
344
+ spent += phase.durationMs;
345
+ const end = totalTime > 0 ? Math.round((spent / totalTime) * extra) : 0;
346
+ let stroke = '━';
347
+ if (ascii)
348
+ stroke = phase.phase === 'publish' ? 'u' : (phase.phase[0] ?? '?');
349
+ const segment = color(stroke.repeat(1 + end - used), phaseRamp[index % phaseRamp.length] ?? '34', enabled);
350
+ used = end;
351
+ return segment;
352
+ });
353
+ lines.push('', ` timeline ${segments.join('')}`, ...wrap(phases
354
+ .map(({ phase, durationMs }) => `${phase} ${durationMs < 1000 ? `${durationMs}ms` : duration(durationMs)}`)
355
+ .join(' · '), ' ', columns));
356
+ }
357
+ const throughput = input.throughput;
358
+ if (success &&
359
+ input.durationMs >= minThroughputMs &&
360
+ throughput &&
361
+ throughput.length >= minThroughputSamples)
362
+ lines.push(` files/s ${spark(throughput, ascii)} ${Math.round(throughput.at(-1) ?? 0).toLocaleString('en-US')}`);
363
+ const outsideScope = coverage?.outsideScope ?? 0;
364
+ if (codeFiles > 0) {
365
+ const barLine = bar(fraction, Math.min(16, columns - 16), 'none', ascii);
366
+ lines.push(color(` coverage ${barLine} ${Math.round(fraction * 100)}%`, tone, enabled));
367
+ lines.push(...wrap(`${indexed.toLocaleString('en-US')} indexed · ${outsideScope.toLocaleString('en-US')} outside scope`, ' ', columns));
368
+ const missing = notInProgram === 0 ? '' : ` · ${notInProgram.toLocaleString('en-US')} not in program`;
369
+ lines.push(...wrap(`${compiler.toLocaleString('en-US')} compiler · ${lexical.toLocaleString('en-US')} lexical only · ${errors.toLocaleString('en-US')} errors${missing}`, ' ', columns));
370
+ }
371
+ const hints = [...(input.includeWarnings ?? [])];
372
+ if (lowCoverage) {
373
+ if (outsideScope > 0) {
374
+ hints.push(`${outsideScope.toLocaleString('en-US')} code files outside scope: ei_impact will be partial; check include in ei.config.json`);
375
+ }
376
+ else {
377
+ hints.push(`${(codeFiles - indexed).toLocaleString('en-US')} code files unindexed: ei_impact will be partial; check ei status`);
378
+ }
379
+ }
380
+ if (highLexical)
381
+ hints.push(`${lexical.toLocaleString('en-US')} files are not in a TypeScript program: ei_impact will be partial; check tsconfig include / allowJs`);
382
+ if (!lowCoverage && !highLexical && input.next)
383
+ hints.push(input.next);
384
+ if (hints.length > 0)
385
+ lines.push('');
386
+ for (const hint of hints)
387
+ lines.push(...wrap(hint, ascii ? ' > ' : ' › ', columns));
388
+ return `${lines.map((line) => fitAnsi(line, columns)).join('\n')}\n`;
389
+ }