@ngockhoale/ukit 3.4.74 → 3.4.76
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/CHANGELOG.md +110 -95
- package/manifests/platform.full.yaml +15 -0
- package/package.json +14 -4
- package/src/cli/commands/markerStore.js +15 -0
- package/src/cli/index.js +7 -0
- package/src/core/markerStoreMigration.js +122 -0
- package/template_project/.claude/hooks/completion-gate.sh +10 -1
- package/template_project/.claude/hooks/handoff-resume.sh +9 -0
- package/template_project/.claude/hooks/owner-stop-gate.mjs +41 -0
- package/template_project/.claude/hooks/skill-router.sh +262 -28
- package/template_project/.claude/settings.json +11 -1
- package/template_project/.claude/ukit/index/publication-intent.mjs +144 -18
- package/template_project/.claude/ukit/index/route-task.mjs +91 -9
- package/template_project/.claude/ukit/runtime/cron-operation-adapter.mjs +11 -4
- package/template_project/.claude/ukit/runtime/execution-ledger.mjs +369 -29
- package/template_project/.claude/ukit/runtime/operation-evidence.mjs +9 -0
- package/template_project/.claude/ukit/runtime/resumable-run.mjs +33 -11
- package/template_project/.claude/ukit/runtime/stop-coordinator.mjs +161 -32
- package/template_project/.omp/hooks/pre/ukit-bridge.js +552 -4
- package/scripts/bug/triage.mjs +0 -76
- package/scripts/dev/worktree-preflight.mjs +0 -166
- package/scripts/docs/render-instructions.mjs +0 -66
- package/scripts/index/build-index.mjs +0 -102
- package/scripts/index/query-index.mjs +0 -128
- package/scripts/index/refresh-index.mjs +0 -195
- package/scripts/install/sync-installed-mirror.mjs +0 -263
- package/scripts/measure-decision-gateway.mjs +0 -306
- package/scripts/probe/codex-capability-probe.mjs +0 -169
- package/scripts/skill/audit-skill.mjs +0 -68
- package/scripts/test/run-handoff-isolated.mjs +0 -178
package/scripts/bug/triage.mjs
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
import { triageBug } from '../../src/bug/triageBug.js';
|
|
5
|
-
|
|
6
|
-
async function main() {
|
|
7
|
-
const args = process.argv.slice(2);
|
|
8
|
-
const { value: rootArg, args: remainingArgs } = extractFlagValue(args, '--root');
|
|
9
|
-
const rootDir = rootArg ? path.resolve(rootArg) : process.cwd();
|
|
10
|
-
|
|
11
|
-
// Everything after `--` is signature text; before it, only positional args
|
|
12
|
-
// are — the --root value was already consumed by extractFlagValue.
|
|
13
|
-
const separatorIndex = remainingArgs.indexOf('--');
|
|
14
|
-
const positional = separatorIndex === -1 ? remainingArgs : remainingArgs.slice(0, separatorIndex);
|
|
15
|
-
const afterSeparator = separatorIndex === -1 ? [] : remainingArgs.slice(separatorIndex + 1);
|
|
16
|
-
const unknown = positional.filter((arg) => arg.startsWith('--'));
|
|
17
|
-
if (unknown.length > 0) {
|
|
18
|
-
throw new Error(`unknown argument: ${unknown[0]}`);
|
|
19
|
-
}
|
|
20
|
-
const signature = [...positional, ...afterSeparator].join(' ').trim();
|
|
21
|
-
|
|
22
|
-
if (!signature) {
|
|
23
|
-
console.error('Usage: yarn bug:triage -- "<error signature>"');
|
|
24
|
-
process.exitCode = 1;
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const result = await triageBug({ rootDir, signature });
|
|
29
|
-
console.log('[bug:triage]');
|
|
30
|
-
console.log(`lane: ${result.lane}`);
|
|
31
|
-
console.log(`confidence: ${result.confidence.toFixed(2)}`);
|
|
32
|
-
console.log(`signature: ${result.signature}`);
|
|
33
|
-
console.log(`suspects: ${result.suspectFiles.join(', ') || 'none'}`);
|
|
34
|
-
console.log(`test: ${result.recommendedTestCommand}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function extractFlagValue(argv, flag) {
|
|
38
|
-
let value = null;
|
|
39
|
-
const nextArgs = [];
|
|
40
|
-
|
|
41
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
42
|
-
const arg = argv[i];
|
|
43
|
-
|
|
44
|
-
if (arg === flag) {
|
|
45
|
-
if (value !== null) {
|
|
46
|
-
nextArgs.push(arg);
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
const maybeValue = argv[i + 1];
|
|
50
|
-
if (!maybeValue || maybeValue.startsWith('--')) {
|
|
51
|
-
throw new Error(`Missing value for ${flag}.`);
|
|
52
|
-
}
|
|
53
|
-
value = maybeValue;
|
|
54
|
-
i += 1;
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (arg.startsWith(`${flag}=`)) {
|
|
59
|
-
if (value === null) {
|
|
60
|
-
value = arg.slice(flag.length + 1);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
nextArgs.push(arg);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return { value, args: nextArgs };
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
await main();
|
|
73
|
-
} catch (error) {
|
|
74
|
-
console.error(error && error.message ? error.message : error);
|
|
75
|
-
process.exit(1);
|
|
76
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// Bootstrap the gitignored UKit runtime in a fresh `git worktree` so targeted tests can run.
|
|
3
|
-
//
|
|
4
|
-
// A new worktree only has tracked files. `.claude/`, `.ukit/`, `CLAUDE.md`, … are generated by
|
|
5
|
-
// `ukit install` and gitignored, so mirror/runtime tests fail there for environment reasons.
|
|
6
|
-
// This reuses `bin/ukit install` (no new generator), idempotently:
|
|
7
|
-
// - already bootstrapped → no-op
|
|
8
|
-
// - missing prerequisites → run `ukit install` once, re-check
|
|
9
|
-
// - not a linked worktree → refuse (the primary checkout's .claude/ is the maintainer runtime)
|
|
10
|
-
// Install can also create template-owned scaffolds missing from the checkout (docs/AI_HANDOFF/PLAN.md, SPEC.md);
|
|
11
|
-
// those are not gitignored, so they are reported as `visibleWrites` + a warning, never hidden or deleted.
|
|
12
|
-
// `ukit install` writes the install flavour of root CLAUDE.md/AGENTS.md, but those files are
|
|
13
|
-
// gitignored *render outputs* of template_project/instructions (docs:render). The preflight
|
|
14
|
-
// re-renders them when they drift — never a tracked render target, which is only reported.
|
|
15
|
-
// It copies nothing from another checkout (no sessions, secrets, handoff state) and does not
|
|
16
|
-
// link node_modules — run `yarn install` in the worktree (a symlinked node_modules is warned:
|
|
17
|
-
// realpath-sensitive hooks resolve it outside the project and misjudge delete targets).
|
|
18
|
-
//
|
|
19
|
-
// Usage: node scripts/dev/worktree-preflight.mjs [--root <dir>] [--check] [--json]
|
|
20
|
-
// Exit: 0 ready · 1 prerequisites missing (--check, or bootstrap failed) · 2 refused
|
|
21
|
-
|
|
22
|
-
import { spawnSync } from 'node:child_process';
|
|
23
|
-
import fs from 'node:fs';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import { fileURLToPath } from 'node:url';
|
|
26
|
-
|
|
27
|
-
// Generated by `ukit install`; each is required by a mirror/runtime test family.
|
|
28
|
-
export const PREREQUISITES = [
|
|
29
|
-
'node_modules',
|
|
30
|
-
'.claude/settings.json',
|
|
31
|
-
'.claude/hooks',
|
|
32
|
-
'.claude/ukit/runtime/execution-ledger.mjs',
|
|
33
|
-
'.ukit/storage/config.json',
|
|
34
|
-
'CLAUDE.md',
|
|
35
|
-
'AGENTS.md',
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
// Explicit bounds so a wedged git/render child can never hang the preflight. Normal runs take
|
|
39
|
-
// milliseconds; these sit far above that yet below `ukit install`'s own 120s budget.
|
|
40
|
-
const GIT_TIMEOUT_MS = 30_000;
|
|
41
|
-
const RENDER_TIMEOUT_MS = 60_000;
|
|
42
|
-
|
|
43
|
-
function git(root, args) {
|
|
44
|
-
const res = spawnSync('git', args, { cwd: root, encoding: 'utf8', timeout: GIT_TIMEOUT_MS });
|
|
45
|
-
return res.status === 0 ? res.stdout.trim() : null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function isLinkedWorktree(root) {
|
|
49
|
-
const gitDir = git(root, ['rev-parse', '--path-format=absolute', '--git-dir']);
|
|
50
|
-
const common = git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']);
|
|
51
|
-
return Boolean(gitDir && common && path.resolve(gitDir) !== path.resolve(common));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function isTracked(root, rel) {
|
|
55
|
-
const res = spawnSync('git', ['ls-files', '--error-unmatch', '--', rel], { cwd: root, stdio: 'ignore', timeout: GIT_TIMEOUT_MS });
|
|
56
|
-
// A timed-out probe proves nothing: treat as tracked so the file is reported, never overwritten.
|
|
57
|
-
return res.status === 0 || Boolean(res.error);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const RENDER_CLI = 'scripts/docs/render-instructions.mjs';
|
|
61
|
-
|
|
62
|
-
// Visible (non-ignored) paths in `git status`. `ukit install` creates template-owned scaffolds that
|
|
63
|
-
// are missing from the checkout (docs/AI_HANDOFF/PLAN.md, SPEC.md — mergeStrategy skip, handoff-clear
|
|
64
|
-
// restores them to template, never deletes them). They are not gitignored, so a HEAD that lost them
|
|
65
|
-
// turns the bootstrap into a visible write. Report it truthfully instead of hiding or deleting it.
|
|
66
|
-
function visibleStatus(root) {
|
|
67
|
-
const res = spawnSync('git', ['status', '--porcelain', '--untracked-files=all'], { cwd: root, encoding: 'utf8', timeout: GIT_TIMEOUT_MS });
|
|
68
|
-
return res.status === 0 ? new Set(res.stdout.split('\n').filter(Boolean)) : null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// → rel paths whose rendered bytes differ from disk (`DRIFT <target>` lines of --check).
|
|
72
|
-
export function renderDrift(root) {
|
|
73
|
-
const res = spawnSync(process.execPath, [path.join(root, RENDER_CLI), '--check'], { cwd: root, encoding: 'utf8', timeout: RENDER_TIMEOUT_MS });
|
|
74
|
-
// A killed check prints nothing, which would read as "no drift" — fail loudly instead.
|
|
75
|
-
if (res.error) throw new Error(`render check did not complete (${res.error.code || res.error.message})`);
|
|
76
|
-
return `${res.stdout || ''}`.split('\n').map((l) => l.match(/^DRIFT (.+)$/)?.[1]).filter(Boolean);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function missingPrerequisites(root) {
|
|
80
|
-
return PREREQUISITES.filter((rel) => !fs.existsSync(path.join(root, rel)));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function preflight({ root, check = false } = {}) {
|
|
84
|
-
const projectRoot = fs.realpathSync(root);
|
|
85
|
-
const result = { root: projectRoot, ok: false, bootstrapped: false, missing: [], rendered: [], visibleWrites: [], warnings: [], home: null, error: null };
|
|
86
|
-
|
|
87
|
-
if (!fs.existsSync(path.join(projectRoot, 'bin/ukit'))) {
|
|
88
|
-
return { ...result, exitCode: 2, error: `not a UKit checkout (no bin/ukit): ${projectRoot}` };
|
|
89
|
-
}
|
|
90
|
-
if (!isLinkedWorktree(projectRoot)) {
|
|
91
|
-
return { ...result, exitCode: 2, error: 'refusing: not a linked worktree (git worktree add …); the primary checkout keeps its own runtime' };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
result.missing = missingPrerequisites(projectRoot);
|
|
95
|
-
if (result.missing.length > 0) {
|
|
96
|
-
if (check) return { ...result, exitCode: 1 };
|
|
97
|
-
if (result.missing.includes('node_modules')) {
|
|
98
|
-
return { ...result, exitCode: 1, error: 'node_modules missing — run `yarn install` in the worktree first (not linked from another checkout)' };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// `ukit install` also writes user-level state (~/.ukit playbooks). Point HOME inside the
|
|
102
|
-
// worktree's ignored .cache/ so a preflight never mutates the real home or leaks from it.
|
|
103
|
-
result.home = path.join(projectRoot, '.cache/worktree-preflight-home');
|
|
104
|
-
fs.mkdirSync(result.home, { recursive: true });
|
|
105
|
-
const visibleBefore = visibleStatus(projectRoot);
|
|
106
|
-
const install = spawnSync(process.execPath, [path.join(projectRoot, 'bin/ukit'), 'install'], {
|
|
107
|
-
cwd: projectRoot,
|
|
108
|
-
encoding: 'utf8',
|
|
109
|
-
env: { ...process.env, HOME: result.home, USERPROFILE: result.home },
|
|
110
|
-
timeout: 120_000,
|
|
111
|
-
});
|
|
112
|
-
result.bootstrapped = true;
|
|
113
|
-
const visibleAfter = visibleStatus(projectRoot);
|
|
114
|
-
if (visibleBefore && visibleAfter) {
|
|
115
|
-
result.visibleWrites = [...visibleAfter].filter((l) => !visibleBefore.has(l)).map((l) => l.slice(3));
|
|
116
|
-
if (result.visibleWrites.length > 0) {
|
|
117
|
-
result.warnings.push(`ukit install created non-ignored file(s) missing from this checkout: ${result.visibleWrites.join(', ')} — template-owned scaffolds; restore/commit them (not deleted)`);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
result.missing = missingPrerequisites(projectRoot);
|
|
121
|
-
if (install.status !== 0 || result.missing.length > 0) {
|
|
122
|
-
const tail = `${install.stdout || ''}${install.stderr || ''}`.trim().split('\n').slice(-5).join('\n');
|
|
123
|
-
return { ...result, exitCode: 1, error: `ukit install did not produce all prerequisites (exit ${install.status})\n${tail}` };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (fs.lstatSync(path.join(projectRoot, 'node_modules')).isSymbolicLink()) {
|
|
128
|
-
result.warnings.push('node_modules is a symlink — realpath-sensitive tests (block-dangerous) fail; run `yarn install` in this worktree for a real copy');
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const drift = renderDrift(projectRoot);
|
|
132
|
-
if (drift.length > 0) {
|
|
133
|
-
if (check) return { ...result, missing: drift.map((t) => `render:${t}`), exitCode: 1 };
|
|
134
|
-
const tracked = drift.filter((t) => isTracked(projectRoot, t));
|
|
135
|
-
if (tracked.length > 0) {
|
|
136
|
-
return { ...result, exitCode: 1, error: `tracked render target(s) drifted, not overwriting: ${tracked.join(', ')} — commit or revert the source edit` };
|
|
137
|
-
}
|
|
138
|
-
const write = spawnSync(process.execPath, [path.join(projectRoot, RENDER_CLI), '--write'], { cwd: projectRoot, encoding: 'utf8', timeout: RENDER_TIMEOUT_MS });
|
|
139
|
-
const still = renderDrift(projectRoot);
|
|
140
|
-
if (write.status !== 0 || still.length > 0) {
|
|
141
|
-
return { ...result, exitCode: 1, error: `docs:render did not clear drift: ${still.join(', ') || (write.stderr || '').trim()}` };
|
|
142
|
-
}
|
|
143
|
-
result.rendered = drift;
|
|
144
|
-
}
|
|
145
|
-
return { ...result, ok: true, exitCode: 0 };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function main(argv) {
|
|
149
|
-
const args = { root: process.cwd(), check: false, json: false };
|
|
150
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
151
|
-
if (argv[i] === '--root') args.root = path.resolve(argv[++i] || '');
|
|
152
|
-
else if (argv[i] === '--check') args.check = true;
|
|
153
|
-
else if (argv[i] === '--json') args.json = true;
|
|
154
|
-
}
|
|
155
|
-
const { exitCode, ...result } = preflight(args);
|
|
156
|
-
if (args.json) {
|
|
157
|
-
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
158
|
-
} else if (result.ok) {
|
|
159
|
-
console.log(`[worktree-preflight] ready${result.bootstrapped ? ' (bootstrapped via ukit install)' : ' (already bootstrapped)'}: ${result.root}`);
|
|
160
|
-
} else {
|
|
161
|
-
console.error(`[worktree-preflight] ${result.error || `missing: ${result.missing.join(', ')}`}`);
|
|
162
|
-
}
|
|
163
|
-
process.exit(exitCode);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main(process.argv.slice(2));
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// DOC-102 renderer CLI (SPEC §8.2).
|
|
3
|
-
// node scripts/docs/render-instructions.mjs --write (default) regenerate all outputs
|
|
4
|
-
// node scripts/docs/render-instructions.mjs --parity check installed root instructions read-only
|
|
5
|
-
// `--parity` takes precedence over `--check`/`--write`; `--parity-root` overrides only the
|
|
6
|
-
// comparison target directory for fixture/testing use, never the source/layout root.
|
|
7
|
-
import path from 'node:path';
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import { fileURLToPath } from 'node:url';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
renderInstructionsFromDisk,
|
|
13
|
-
checkRenderedInstructions,
|
|
14
|
-
} from '../../src/render/instructionRenderer.js';
|
|
15
|
-
|
|
16
|
-
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const USAGE = 'usage: render-instructions.mjs [--write|--check|--parity] [--parity-root <dir>]';
|
|
20
|
-
const args = process.argv.slice(2);
|
|
21
|
-
const parityRootArg = args.indexOf('--parity-root');
|
|
22
|
-
const parityRoot = parityRootArg === -1 ? repoRoot : path.resolve(args[parityRootArg + 1] || '');
|
|
23
|
-
const unknown = args.filter((a, i) => a !== '--write' && a !== '--check' && a !== '--parity'
|
|
24
|
-
&& a !== '--parity-root' && !(parityRootArg !== -1 && i === parityRootArg + 1));
|
|
25
|
-
if (unknown.length > 0 || (parityRootArg !== -1 && !args[parityRootArg + 1])) {
|
|
26
|
-
console.error(`${USAGE}\nunknown flag or missing value: ${unknown[0] || '--parity-root'}`);
|
|
27
|
-
process.exit(2);
|
|
28
|
-
}
|
|
29
|
-
if (parityRootArg !== -1 && !args.includes('--parity')) {
|
|
30
|
-
console.error(`${USAGE}\n--parity-root requires --parity`);
|
|
31
|
-
process.exit(2);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const mode = args.includes('--check') ? 'check' : 'write';
|
|
35
|
-
const parity = args.includes('--parity');
|
|
36
|
-
|
|
37
|
-
try {
|
|
38
|
-
if (parity) {
|
|
39
|
-
const rendered = await renderInstructionsFromDisk({ repoRoot, write: false });
|
|
40
|
-
const targets = [...rendered].filter(([target]) => target === 'CLAUDE.md' || target === 'AGENTS.md');
|
|
41
|
-
const drift = targets.filter(([target, content]) => {
|
|
42
|
-
const file = path.join(parityRoot, target);
|
|
43
|
-
return !fs.existsSync(file) || !fs.readFileSync(file).equals(Buffer.from(content));
|
|
44
|
-
});
|
|
45
|
-
for (const [target] of drift) console.log(`DRIFT ${target}`);
|
|
46
|
-
if (drift.length > 0) process.exit(1);
|
|
47
|
-
console.log(`PARITY OK ${targets.length} files`);
|
|
48
|
-
process.exit(0);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (mode === 'check') {
|
|
52
|
-
const drift = await checkRenderedInstructions({ repoRoot });
|
|
53
|
-
for (const target of drift) {
|
|
54
|
-
console.log(`DRIFT ${target}`);
|
|
55
|
-
}
|
|
56
|
-
process.exit(drift.length > 0 ? 1 : 0);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const rendered = await renderInstructionsFromDisk({ repoRoot, write: true });
|
|
60
|
-
for (const [target, content] of rendered) {
|
|
61
|
-
console.log(`WROTE ${target} (${content.split('\n').length - 1} lines)`);
|
|
62
|
-
}
|
|
63
|
-
} catch (err) {
|
|
64
|
-
console.error(err && err.message ? err.message : err);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
buildCodeIndex,
|
|
7
|
-
buildDerivedIndexArtifacts,
|
|
8
|
-
inspectIndexStaleness,
|
|
9
|
-
mapLimit,
|
|
10
|
-
INDEX_IO_CONCURRENCY,
|
|
11
|
-
} from '../../src/index/buildIndex.js';
|
|
12
|
-
|
|
13
|
-
async function main() {
|
|
14
|
-
const args = process.argv.slice(2);
|
|
15
|
-
const { value: rootArg, args: remainingArgs } = extractFlagValue(args, '--root');
|
|
16
|
-
const unexpected = remainingArgs.filter((arg) => arg.startsWith('--'));
|
|
17
|
-
if (unexpected.length > 0) {
|
|
18
|
-
throw new Error(`unexpected argument: ${unexpected[0]}`);
|
|
19
|
-
}
|
|
20
|
-
const rootDir = rootArg ? path.resolve(rootArg) : process.cwd();
|
|
21
|
-
|
|
22
|
-
// One enumeration serves both the readability check and the build: the
|
|
23
|
-
// snapshot is handed to buildCodeIndex, which reuses it instead of
|
|
24
|
-
// rediscovering the repository.
|
|
25
|
-
const { snapshot } = await inspectIndexStaleness({ rootDir, maxAgeMs: 0 });
|
|
26
|
-
const unreadable = await collectUnreadableFiles(rootDir, snapshot?.files ?? []);
|
|
27
|
-
for (const filePath of unreadable) {
|
|
28
|
-
console.error(`[index:build] skipped unreadable file: ${filePath}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const summary = await buildCodeIndex({ rootDir, discoverySnapshot: snapshot });
|
|
32
|
-
await buildDerivedIndexArtifacts(rootDir);
|
|
33
|
-
|
|
34
|
-
console.log('[index:build] completed');
|
|
35
|
-
console.log(`root: ${rootDir}`);
|
|
36
|
-
console.log(`files: ${summary.fileCount}`);
|
|
37
|
-
console.log(`symbols: ${summary.symbolCount}`);
|
|
38
|
-
console.log(`imports: ${summary.importCount}`);
|
|
39
|
-
console.log(`tests-map: ${summary.testsMapCount}`);
|
|
40
|
-
console.log(`hotspots: ${summary.hotspotCount}`);
|
|
41
|
-
console.log(`parsed: ${summary.parsedCodeFileCount}`);
|
|
42
|
-
console.log(`reused: ${summary.reusedCodeFileCount}`);
|
|
43
|
-
if (unreadable.length > 0) {
|
|
44
|
-
console.log(`skipped-unreadable: ${unreadable.length}`);
|
|
45
|
-
}
|
|
46
|
-
console.log(`indexDir: ${summary.indexDir}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// The parse worker inside buildCodeIndex skips files it cannot read; the CLI
|
|
50
|
-
// surfaces them so a partial index is never silent.
|
|
51
|
-
async function collectUnreadableFiles(rootDir, entries) {
|
|
52
|
-
const unreadable = await mapLimit(entries, INDEX_IO_CONCURRENCY, async (entry) => {
|
|
53
|
-
try {
|
|
54
|
-
await fs.access(entry.absolutePath, fs.constants.R_OK);
|
|
55
|
-
return null;
|
|
56
|
-
} catch {
|
|
57
|
-
return path.relative(rootDir, entry.absolutePath).split(path.sep).join('/');
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return unreadable.filter(Boolean).sort();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function extractFlagValue(argv, flag) {
|
|
64
|
-
let value = null;
|
|
65
|
-
const nextArgs = [];
|
|
66
|
-
|
|
67
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
68
|
-
const arg = argv[i];
|
|
69
|
-
|
|
70
|
-
if (arg === flag) {
|
|
71
|
-
if (value !== null) {
|
|
72
|
-
nextArgs.push(arg);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
const maybeValue = argv[i + 1];
|
|
76
|
-
if (!maybeValue || maybeValue.startsWith('--')) {
|
|
77
|
-
throw new Error(`Missing value for ${flag}.`);
|
|
78
|
-
}
|
|
79
|
-
value = maybeValue;
|
|
80
|
-
i += 1;
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (arg.startsWith(`${flag}=`)) {
|
|
85
|
-
if (value === null) {
|
|
86
|
-
value = arg.slice(flag.length + 1);
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
nextArgs.push(arg);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return { value, args: nextArgs };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
try {
|
|
98
|
-
await main();
|
|
99
|
-
} catch (error) {
|
|
100
|
-
console.error(error && error.message ? error.message : error);
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
queryCodeIndex,
|
|
7
|
-
} from '../../src/index/queryIndex.js';
|
|
8
|
-
import {
|
|
9
|
-
buildCodeIndex,
|
|
10
|
-
buildDerivedIndexArtifacts,
|
|
11
|
-
inspectIndexStaleness,
|
|
12
|
-
isIndexStale,
|
|
13
|
-
mapLimit,
|
|
14
|
-
INDEX_IO_CONCURRENCY,
|
|
15
|
-
DEFAULT_INDEX_CACHE_MAX_AGE_MS,
|
|
16
|
-
} from '../../src/index/buildIndex.js';
|
|
17
|
-
import { parseIndexArgs, QUERY_FLAG_DEFINITIONS } from '../../src/cli/commands/indexArgs.js';
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
const args = process.argv.slice(2);
|
|
21
|
-
const { value: rootArg, args: afterRootArgs } = extractFlagValue(args, '--root');
|
|
22
|
-
const { value: changedArg, args: remainingArgs } = extractFlagValue(afterRootArgs, '--changed');
|
|
23
|
-
const changedFiles = changedArg
|
|
24
|
-
? changedArg.split(',').map((item) => item.trim()).filter(Boolean)
|
|
25
|
-
: [];
|
|
26
|
-
const rootDir = rootArg ? path.resolve(rootArg) : process.cwd();
|
|
27
|
-
|
|
28
|
-
const { tokens, flags } = parseIndexArgs(remainingArgs, QUERY_FLAG_DEFINITIONS);
|
|
29
|
-
const query = tokens.join(' ').trim();
|
|
30
|
-
if (!query) {
|
|
31
|
-
console.error('Usage: yarn index:query -- "<error|symbol|path>" [--limit N] [--changed fileA,fileB]');
|
|
32
|
-
process.exitCode = 1;
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const stale = await isIndexStale({ rootDir, maxAgeMs: DEFAULT_INDEX_CACHE_MAX_AGE_MS });
|
|
37
|
-
if (stale) {
|
|
38
|
-
// One enumeration serves the readability check and the rebuild.
|
|
39
|
-
const { snapshot } = await inspectIndexStaleness({ rootDir, maxAgeMs: 0 });
|
|
40
|
-
const unreadable = await collectUnreadableFiles(rootDir, snapshot?.files ?? []);
|
|
41
|
-
for (const filePath of unreadable) {
|
|
42
|
-
console.error(`[index:query] skipped unreadable file: ${filePath}`);
|
|
43
|
-
}
|
|
44
|
-
await buildCodeIndex({ rootDir, discoverySnapshot: snapshot });
|
|
45
|
-
await buildDerivedIndexArtifacts(rootDir);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const limit = Number.parseInt(flags.get('--limit') ?? '5', 10);
|
|
49
|
-
const results = await queryCodeIndex({
|
|
50
|
-
rootDir,
|
|
51
|
-
query,
|
|
52
|
-
limit: Number.isNaN(limit) ? 5 : limit,
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (changedFiles.length > 0) {
|
|
56
|
-
console.log(`changed-files-hint: ${changedFiles.join(', ')}`);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (results.length === 0) {
|
|
60
|
-
console.log('[index:query] no matches');
|
|
61
|
-
} else {
|
|
62
|
-
console.log(`[index:query] top ${results.length} matches for: ${query}`);
|
|
63
|
-
for (const [idx, item] of results.entries()) {
|
|
64
|
-
console.log(`${idx + 1}. ${item.filePath} (score=${item.score})`);
|
|
65
|
-
if ((item.tests ?? []).length > 0) {
|
|
66
|
-
console.log(` tests: ${item.tests.slice(0, 2).join(', ')}`);
|
|
67
|
-
}
|
|
68
|
-
if ((item.reasons ?? []).length > 0) {
|
|
69
|
-
console.log(` reasons: ${item.reasons.join(', ')}`);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// The parse worker inside buildCodeIndex skips files it cannot read; the CLI
|
|
76
|
-
// surfaces them so a partial index is never silent.
|
|
77
|
-
async function collectUnreadableFiles(rootDir, entries) {
|
|
78
|
-
const unreadable = await mapLimit(entries, INDEX_IO_CONCURRENCY, async (entry) => {
|
|
79
|
-
try {
|
|
80
|
-
await fs.access(entry.absolutePath, fs.constants.R_OK);
|
|
81
|
-
return null;
|
|
82
|
-
} catch {
|
|
83
|
-
return path.relative(rootDir, entry.absolutePath).split(path.sep).join('/');
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
return unreadable.filter(Boolean).sort();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function extractFlagValue(argv, flag) {
|
|
90
|
-
let value = null;
|
|
91
|
-
const nextArgs = [];
|
|
92
|
-
|
|
93
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
94
|
-
const arg = argv[i];
|
|
95
|
-
|
|
96
|
-
if (arg === flag) {
|
|
97
|
-
if (value !== null) {
|
|
98
|
-
nextArgs.push(arg);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const maybeValue = argv[i + 1];
|
|
102
|
-
if (!maybeValue || maybeValue.startsWith('--')) {
|
|
103
|
-
throw new Error(`Missing value for ${flag}.`);
|
|
104
|
-
}
|
|
105
|
-
value = maybeValue;
|
|
106
|
-
i += 1;
|
|
107
|
-
continue;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (arg.startsWith(`${flag}=`)) {
|
|
111
|
-
if (value === null) {
|
|
112
|
-
value = arg.slice(flag.length + 1);
|
|
113
|
-
continue;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
nextArgs.push(arg);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return { value, args: nextArgs };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
await main();
|
|
125
|
-
} catch (error) {
|
|
126
|
-
console.error(error && error.message ? error.message : error);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|