@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,420 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { createHash } from 'node:crypto';
3
+ import { createReadStream, existsSync, lstatSync } from 'node:fs';
4
+ import { readdir, readFile } from 'node:fs/promises';
5
+ import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
6
+ import { pipeline } from 'node:stream/promises';
7
+ import { promisify } from 'node:util';
8
+ import { isRecord } from '../kernel/guards.js';
9
+ import { matchAny, matchGlob } from '../kernel/glob.js';
10
+ const run = promisify(execFile);
11
+ /** Boundary check for a module imported by path: the members the scan calls are present. */
12
+ export function isTypescriptApi(value) {
13
+ return (isRecord(value) &&
14
+ typeof value.version === 'string' &&
15
+ isRecord(value.sys) &&
16
+ typeof value.getParsedCommandLineOfConfigFile === 'function' &&
17
+ typeof value.resolveProjectReferencePath === 'function' &&
18
+ typeof value.readConfigFile === 'function');
19
+ }
20
+ // RISK §6 default excludes (D49), two classes. Secrets are reported as `secret`.
21
+ // Always excluded, any kind of file:
22
+ const SECRET_PATTERNS = ['**/.env*', '**/*.pem', '**/*.key'];
23
+ const DEFAULT_EXCLUDES = ['**/node_modules/**', '**/dist/**', '**/.git/**'];
24
+ // Excluded by name only when the file is not code: source that handles credentials is indexed.
25
+ const SECRET_NAME_PATTERNS = ['**/*credentials*', '**/secrets/**'];
26
+ const IS_CODE = {
27
+ ts: true,
28
+ tsx: true,
29
+ js: true,
30
+ jsx: true,
31
+ mjs: true,
32
+ cjs: true,
33
+ 'd.ts': true,
34
+ json: false,
35
+ other: false,
36
+ };
37
+ const KINDS = {
38
+ '.ts': 'ts',
39
+ '.mts': 'ts',
40
+ '.cts': 'ts',
41
+ '.tsx': 'tsx',
42
+ '.js': 'js',
43
+ '.jsx': 'jsx',
44
+ '.mjs': 'mjs',
45
+ '.cjs': 'cjs',
46
+ '.json': 'json',
47
+ };
48
+ const TSCONFIG_NAME = /^(?:tsconfig(?:\..+)?|jsconfig)\.json$/;
49
+ const HASH_CONCURRENCY = 32;
50
+ export function kindOf(path) {
51
+ if (/\.d\.[cm]?ts$/.test(path))
52
+ return 'd.ts';
53
+ return KINDS[extname(path)] ?? 'other';
54
+ }
55
+ export function isCodeKind(kind) {
56
+ return IS_CODE[kind];
57
+ }
58
+ /** Secret and excluded paths are decided by path and kind alone; their content is never read. */
59
+ export function exclusionOf(path, impact) {
60
+ if (SECRET_PATTERNS.some((pattern) => matchGlob(pattern, path)))
61
+ return 'secret';
62
+ if (!IS_CODE[kindOf(path)] && SECRET_NAME_PATTERNS.some((pattern) => matchGlob(pattern, path))) {
63
+ return 'secret';
64
+ }
65
+ if (matchAny([...DEFAULT_EXCLUDES, ...impact.exclude], path))
66
+ return 'excluded';
67
+ return null;
68
+ }
69
+ /**
70
+ * Files whose content must never be read (RISK §6, D57): secrets, default excludes (`node_modules`,
71
+ * `dist`, `.git`), and non-code files in `impact.exclude`. Owner-excluded code files are hashed
72
+ * and scanned lexically for the name cross-check while keeping `reason: 'excluded'`.
73
+ */
74
+ export function neverReadOf(path, kind, impact) {
75
+ if (SECRET_PATTERNS.some((pattern) => matchGlob(pattern, path)))
76
+ return 'secret';
77
+ if (!IS_CODE[kind] && SECRET_NAME_PATTERNS.some((pattern) => matchGlob(pattern, path))) {
78
+ return 'secret';
79
+ }
80
+ if (matchAny(DEFAULT_EXCLUDES, path))
81
+ return 'excluded';
82
+ if (!IS_CODE[kind] && matchAny(impact.exclude, path))
83
+ return 'excluded';
84
+ return null;
85
+ }
86
+ function toPosix(path) {
87
+ return sep === '/' ? path : path.split(sep).join('/');
88
+ }
89
+ // One read is ~35% faster than a stream on source-sized files (oh-my-pi: 1.6 s vs 2.5 s for
90
+ // 210 MB in 10,485 files); large files stream so a big binary never sits in memory whole.
91
+ const STREAM_ABOVE_BYTES = 8 * 2 ** 20;
92
+ export async function hashFile(path, size) {
93
+ const hash = createHash('sha256');
94
+ if (size > STREAM_ABOVE_BYTES)
95
+ await pipeline(createReadStream(path), hash);
96
+ else
97
+ hash.update(await readFile(path));
98
+ return hash.digest('hex');
99
+ }
100
+ export async function mapLimit(items, limit, work) {
101
+ const results = new Array(items.length);
102
+ // Workers share one iterator, so each item is taken exactly once.
103
+ const queue = items.entries();
104
+ const worker = async () => {
105
+ for (const [index, item] of queue)
106
+ results[index] = await work(item);
107
+ };
108
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
109
+ return results;
110
+ }
111
+ // shortcut: gitignore character classes ([abc]) and escapes are matched literally (the shared glob
112
+ // does not support them); only the non-git fallback uses this, git repositories use git itself.
113
+ function parseGitignore(text, base) {
114
+ const rules = [];
115
+ for (const raw of text.split(/\r?\n/)) {
116
+ let line = raw.trimEnd();
117
+ if (line === '' || line.startsWith('#'))
118
+ continue;
119
+ const negate = line.startsWith('!');
120
+ if (negate)
121
+ line = line.slice(1);
122
+ const dirOnly = line.endsWith('/');
123
+ if (dirOnly)
124
+ line = line.slice(0, -1);
125
+ const anchored = line.includes('/');
126
+ if (line.startsWith('/'))
127
+ line = line.slice(1);
128
+ const prefix = base === '' ? '' : `${base}/`;
129
+ rules.push({ glob: anchored ? prefix + line : `${prefix}**/${line}`, negate, dirOnly });
130
+ }
131
+ return rules;
132
+ }
133
+ async function walkVisible(root) {
134
+ const files = [];
135
+ const visit = async (dir, inherited) => {
136
+ const abs = join(root, dir);
137
+ const entries = await readdir(abs, { withFileTypes: true });
138
+ const own = await readFile(join(abs, '.gitignore'), 'utf8').then((text) => parseGitignore(text, dir), () => []);
139
+ const rules = [...inherited, ...own];
140
+ for (const entry of entries) {
141
+ if (entry.name === '.git')
142
+ continue;
143
+ const path = dir === '' ? entry.name : `${dir}/${entry.name}`;
144
+ const isDir = entry.isDirectory();
145
+ let ignored = false;
146
+ for (const rule of rules) {
147
+ if ((!rule.dirOnly || isDir) && matchGlob(rule.glob, path))
148
+ ignored = !rule.negate;
149
+ }
150
+ if (ignored)
151
+ continue;
152
+ if (isDir)
153
+ await visit(path, rules);
154
+ else
155
+ files.push(path);
156
+ }
157
+ };
158
+ await visit('', []);
159
+ return files;
160
+ }
161
+ function hasGitAncestor(root) {
162
+ let dir = resolve(root);
163
+ for (;;) {
164
+ if (existsSync(join(dir, '.git')))
165
+ return true;
166
+ const parent = dirname(dir);
167
+ if (parent === dir)
168
+ return false;
169
+ dir = parent;
170
+ }
171
+ }
172
+ /**
173
+ * The visible set (D25): git's tracked + untracked − ignored when `root` is in a git work tree,
174
+ * else a walk honouring .gitignore. Paths are repo-relative POSIX; the disk check comes later.
175
+ */
176
+ export async function listVisibleFiles(root) {
177
+ const hasGitEnv = Boolean(process.env.GIT_DIR) ||
178
+ Boolean(process.env.GIT_WORK_TREE) ||
179
+ Boolean(process.env.GIT_COMMON_DIR);
180
+ if (!hasGitEnv && !hasGitAncestor(root)) {
181
+ return { paths: await walkVisible(root), listing: 'walk' };
182
+ }
183
+ try {
184
+ const { stdout } = await run('git', ['-C', root, 'ls-files', '--cached', '--others', '--exclude-standard', '-z'], { maxBuffer: 256 * 2 ** 20 });
185
+ // Unmerged entries are listed once per stage.
186
+ return { paths: [...new Set(stdout.split('\0').filter(Boolean))], listing: 'git' };
187
+ }
188
+ catch {
189
+ return { paths: await walkVisible(root), listing: 'walk' };
190
+ }
191
+ }
192
+ /** Disk is the truth: listed paths that are gone, or are directories (submodules), drop out. */
193
+ export async function statVisible(root) {
194
+ const { paths, listing } = await listVisibleFiles(root);
195
+ // Synchronous on purpose: 10,502 lstat calls take ~30 ms in one loop and ~400 ms as promises
196
+ // through the thread pool (oh-my-pi, Node 24). This runs on every query.
197
+ const entries = [];
198
+ for (const path of paths) {
199
+ let stat;
200
+ try {
201
+ stat = lstatSync(join(root, path), { throwIfNoEntry: false });
202
+ }
203
+ catch {
204
+ continue; // unreadable parent directory: not on disk as far as the index can tell
205
+ }
206
+ if (stat === undefined || (!stat.isFile() && !stat.isSymbolicLink()))
207
+ continue;
208
+ entries.push({ path, size: stat.size, mtimeMs: stat.mtimeMs, symlink: stat.isSymbolicLink() });
209
+ }
210
+ entries.sort((a, b) => (a.path < b.path ? -1 : 1)); // listed paths are unique
211
+ return { entries, listing };
212
+ }
213
+ /** Repo-relative paths of configs named by a relative `extends` (string or array). */
214
+ function extendedConfigs(root, configPath, raw) {
215
+ if (!isRecord(raw))
216
+ return [];
217
+ const values = Array.isArray(raw.extends) ? raw.extends : [raw.extends];
218
+ const bases = [];
219
+ for (const value of values) {
220
+ // Package specifiers resolve into node_modules, which is never part of the visible set.
221
+ if (typeof value !== 'string' || !value.startsWith('.'))
222
+ continue;
223
+ const file = join(root, dirname(configPath), value.endsWith('.json') ? value : `${value}.json`);
224
+ bases.push(toPosix(relative(root, file)));
225
+ }
226
+ return bases;
227
+ }
228
+ /** Whether the parsed config or any config it extends declares `include` or `files`. */
229
+ function hasExplicitInputs(ts, parsed) {
230
+ const declares = (raw) => isRecord(raw) && (raw.include !== undefined || raw.files !== undefined);
231
+ if (declares(parsed.raw))
232
+ return true;
233
+ // `include` and `files` are inherited through `extends`; the compiler lists the chain here.
234
+ const configFile = parsed.options.configFile;
235
+ const chain = isRecord(configFile) && Array.isArray(configFile.extendedSourceFiles)
236
+ ? configFile.extendedSourceFiles
237
+ : [];
238
+ return chain.some((file) => typeof file === 'string' && declares(ts.readConfigFile(file, ts.sys.readFile).config));
239
+ }
240
+ /**
241
+ * Every tsconfig the visible set holds, plus configs reached through project references, parsed
242
+ * by TypeScript itself so `extends`, `include`/`exclude`/`files` and `allowJs` mean exactly what
243
+ * they mean to the compiler. A base (a config other configs extend, that no reference names and
244
+ * whose effective inputs are implicit, such as `tsconfig.base.json`) is not a project: its implicit
245
+ * `include` of everything below it would claim files no real project compiles.
246
+ */
247
+ function parseConfigs(root, ts, candidates) {
248
+ const parsedConfigs = [];
249
+ const errors = [];
250
+ const extended = new Set();
251
+ const referenced = new Set();
252
+ const implicitInputs = new Set();
253
+ const seen = new Set();
254
+ const queue = [...candidates];
255
+ const host = { ...ts.sys, onUnRecoverableConfigFileDiagnostic: () => undefined };
256
+ while (queue.length > 0) {
257
+ const path = queue.shift() ?? '';
258
+ if (seen.has(path))
259
+ continue;
260
+ seen.add(path);
261
+ const parsed = ts.getParsedCommandLineOfConfigFile(join(root, path), {}, host);
262
+ if (!parsed) {
263
+ errors.push(`${path}: cannot be read or parsed`);
264
+ continue;
265
+ }
266
+ for (const error of parsed.errors) {
267
+ const text = typeof error.messageText === 'string' ? error.messageText : error.messageText.messageText;
268
+ // TS18003 "No inputs were found" is a fact about the config, not a parse problem.
269
+ if (error.code !== 18003)
270
+ errors.push(`${path}: ${text}`);
271
+ }
272
+ for (const base of extendedConfigs(root, path, parsed.raw))
273
+ extended.add(base);
274
+ if (!hasExplicitInputs(ts, parsed))
275
+ implicitInputs.add(path);
276
+ const files = new Set();
277
+ for (const file of parsed.fileNames) {
278
+ const rel = toPosix(relative(root, file));
279
+ if (!rel.startsWith('..') && !isAbsolute(rel))
280
+ files.add(rel);
281
+ }
282
+ parsedConfigs.push({ path, files });
283
+ for (const reference of parsed.projectReferences ?? []) {
284
+ const rel = toPosix(relative(root, ts.resolveProjectReferencePath(reference)));
285
+ if (rel.startsWith('..') || isAbsolute(rel))
286
+ continue;
287
+ referenced.add(rel);
288
+ queue.push(rel);
289
+ }
290
+ }
291
+ const isBase = (path) => extended.has(path) && !referenced.has(path) && implicitInputs.has(path);
292
+ return {
293
+ configs: parsedConfigs.filter((config) => !isBase(config.path)),
294
+ bases: parsedConfigs.filter((config) => isBase(config.path)).map((config) => config.path),
295
+ errors,
296
+ };
297
+ }
298
+ function depthOf(configPath) {
299
+ const dir = dirname(configPath);
300
+ return dir === '.' ? 0 : dir.split('/').length;
301
+ }
302
+ /** Nearest = deepest config directory; in one directory `tsconfig.json` wins, then name order. */
303
+ function nearer(a, b) {
304
+ if (depthOf(a) !== depthOf(b))
305
+ return depthOf(a) > depthOf(b);
306
+ const aDefault = basename(a) === 'tsconfig.json';
307
+ if (aDefault !== (basename(b) === 'tsconfig.json'))
308
+ return aDefault;
309
+ return a < b;
310
+ }
311
+ function ownerOf(path, configs) {
312
+ let best = null;
313
+ for (const config of configs) {
314
+ if (config.files.has(path) && (best === null || nearer(config.path, best)))
315
+ best = config.path;
316
+ }
317
+ return best;
318
+ }
319
+ function packageOf(path, packageDirs) {
320
+ let dir = dirname(path);
321
+ for (;;) {
322
+ if (packageDirs.has(dir))
323
+ return dir;
324
+ if (dir === '.')
325
+ return null;
326
+ dir = dirname(dir);
327
+ }
328
+ }
329
+ function classify(path, kind, tsconfig, impact) {
330
+ if (!matchAny(impact.include, path))
331
+ return { status: 'unindexed', reason: 'outside-index-scope' };
332
+ if (kind === 'json' || kind === 'other')
333
+ return { status: 'unindexed', reason: 'other-kind' };
334
+ if (tsconfig === null)
335
+ return { status: 'orphan', reason: 'no-tsconfig' };
336
+ return { status: 'indexable', reason: null };
337
+ }
338
+ /**
339
+ * Phase 1 SCAN (DESIGN §6.2.1): census of every visible file with size, mtime, kind, content hash,
340
+ * owning package and owning tsconfig, classified indexable · orphan · unindexed with a reason.
341
+ */
342
+ export async function scan(root, impact, ts,
343
+ /**
344
+ * Stat-level reuse (D22, freshness "stat" only): a file whose size and mtime equal this
345
+ * fingerprint keeps its hash without being read. Rebuilds and `freshness: "hash"` pass nothing.
346
+ */
347
+ fingerprint) {
348
+ const started = performance.now();
349
+ const { entries, listing } = await statVisible(root);
350
+ const packageDirs = new Set(entries
351
+ .filter((entry) => basename(entry.path) === 'package.json')
352
+ .map((entry) => dirname(entry.path)));
353
+ const configCandidates = entries
354
+ .filter((entry) => TSCONFIG_NAME.test(basename(entry.path)))
355
+ .filter((entry) => !entry.symlink && exclusionOf(entry.path, impact) === null)
356
+ .map((entry) => entry.path);
357
+ const { configs, bases, errors } = parseConfigs(root, ts, configCandidates);
358
+ const records = await mapLimit(entries, HASH_CONCURRENCY, async (entry) => {
359
+ const kind = kindOf(entry.path);
360
+ const base = { path: entry.path, size: entry.size, mtimeMs: entry.mtimeMs, kind };
361
+ const pkg = packageOf(entry.path, packageDirs);
362
+ const neverRead = entry.symlink ? 'symlink' : neverReadOf(entry.path, kind, impact);
363
+ if (neverRead !== null) {
364
+ const row = {
365
+ ...base,
366
+ package: pkg,
367
+ hash: null,
368
+ tsconfig: null,
369
+ status: 'unindexed',
370
+ reason: neverRead,
371
+ };
372
+ return row;
373
+ }
374
+ const known = fingerprint?.get(entry.path);
375
+ const hash = known?.hash != null && known.size === entry.size && known.mtimeMs === entry.mtimeMs
376
+ ? known.hash
377
+ : await hashFile(join(root, entry.path), entry.size);
378
+ if (matchAny(impact.exclude, entry.path)) {
379
+ const row = {
380
+ ...base,
381
+ package: pkg,
382
+ hash,
383
+ tsconfig: null,
384
+ status: 'unindexed',
385
+ reason: 'excluded',
386
+ };
387
+ return row;
388
+ }
389
+ const tsconfig = ownerOf(entry.path, configs);
390
+ const row = {
391
+ ...base,
392
+ package: pkg,
393
+ hash,
394
+ tsconfig,
395
+ ...classify(entry.path, kind, tsconfig, impact),
396
+ };
397
+ return row;
398
+ });
399
+ const reasons = {};
400
+ const counts = { indexable: 0, orphan: 0, unindexed: 0 };
401
+ for (const record of records) {
402
+ counts[record.status]++;
403
+ if (record.reason !== null)
404
+ reasons[record.reason] = (reasons[record.reason] ?? 0) + 1;
405
+ }
406
+ return {
407
+ records,
408
+ summary: {
409
+ scanned: records.length,
410
+ ...counts,
411
+ reasons,
412
+ packages: packageDirs.size,
413
+ tsconfigs: configs.map((config) => config.path).sort(),
414
+ tsconfigBases: bases.sort(),
415
+ tsconfigErrors: errors,
416
+ listing,
417
+ ms: Math.round(performance.now() - started),
418
+ },
419
+ };
420
+ }