@ngockhoale/ukit 3.4.75 → 3.4.77

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.
@@ -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,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
- }
@@ -1,195 +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
- inspectIndexStaleness,
8
- mapLimit,
9
- INDEX_IO_CONCURRENCY,
10
- DEFAULT_INDEX_CACHE_MAX_AGE_MS,
11
- } from '../../src/index/buildIndex.js';
12
-
13
- async function main() {
14
- const args = process.argv.slice(2);
15
- const { value: rootArg, args: afterRootArgs } = extractFlagValue(args, '--root');
16
- const { value: changedArg, args: remainingArgs } = extractFlagValue(afterRootArgs, '--changed');
17
- const force = remainingArgs.includes('--force');
18
- const unexpected = remainingArgs.filter((arg) => arg !== '--force');
19
- if (unexpected.length > 0) {
20
- throw new Error(`unexpected argument: ${unexpected[0]}`);
21
- }
22
-
23
- const rootDir = rootArg ? path.resolve(rootArg) : process.cwd();
24
- const hintedFiles = changedArg
25
- ? changedArg.split(',').map((item) => item.trim()).filter(Boolean)
26
- : [];
27
-
28
- // Hints that exist but cannot be read would be silently dropped by the parse
29
- // worker; surface them and keep them out of the merge set. ENOENT hints are
30
- // kept — a deleted file is a legitimate removal hint.
31
- const { readable: changedFiles, unreadable: unreadableHints } = await partitionReadableHints(rootDir, hintedFiles);
32
- for (const filePath of unreadableHints) {
33
- console.error(`[index:refresh] skipped unreadable file: ${filePath}`);
34
- }
35
-
36
- const lastRefreshMs = await getLastRefreshTime(rootDir);
37
-
38
- if (changedFiles.length > 0 && !force) {
39
- // Hints carry the change set, so no staleness enumeration is needed:
40
- // buildCodeIndex merges the hinted paths into the existing artifacts and
41
- // falls back to the bounded full discovery path on its own when the hints
42
- // are unsafe or the previous artifacts cannot be merged (TASK-023).
43
- const summary = await buildCodeIndex({ rootDir, changedFiles });
44
-
45
- console.log('[index:refresh] completed');
46
- console.log(`mode: ${summary.mode}`);
47
- if (lastRefreshMs !== null) {
48
- console.log(`lastRefreshBefore: ${new Date(lastRefreshMs).toISOString()}`);
49
- }
50
- console.log(`changed-files-hint: ${changedFiles.join(', ')}`);
51
- console.log(`root: ${rootDir}`);
52
- console.log(`files: ${summary.fileCount}`);
53
- console.log(`parsed: ${summary.parsedCodeFileCount}`);
54
- console.log(`reused: ${summary.reusedCodeFileCount}`);
55
- if (summary.removedFiles.length > 0) {
56
- console.log(`removed: ${summary.removedFiles.length}`);
57
- }
58
- console.log(`indexDir: ${summary.indexDir}`);
59
- return;
60
- }
61
-
62
- // One enumeration serves the staleness check, the readability check, and the
63
- // build: the snapshot is handed to buildCodeIndex, which reuses it.
64
- const staleness = await inspectIndexStaleness({ rootDir, maxAgeMs: DEFAULT_INDEX_CACHE_MAX_AGE_MS });
65
- const stale = force || staleness.stale;
66
-
67
- if (!stale) {
68
- console.log('[index:refresh] skipped (cache fresh)');
69
- if (lastRefreshMs !== null) {
70
- console.log(`lastRefresh: ${new Date(lastRefreshMs).toISOString()}`);
71
- }
72
- if (changedFiles.length > 0) {
73
- console.log(`changed-files-hint: ${changedFiles.join(', ')}`);
74
- }
75
- console.log(`root: ${rootDir}`);
76
- return;
77
- }
78
-
79
- const unreadable = await collectUnreadableFiles(rootDir, staleness.snapshot?.files ?? []);
80
- for (const filePath of unreadable) {
81
- console.error(`[index:refresh] skipped unreadable file: ${filePath}`);
82
- }
83
-
84
- const summary = await buildCodeIndex({
85
- rootDir,
86
- discoverySnapshot: staleness.snapshot,
87
- });
88
-
89
- console.log('[index:refresh] completed');
90
- console.log(`mode: ${summary.mode}`);
91
- if (lastRefreshMs !== null) {
92
- console.log(`lastRefreshBefore: ${new Date(lastRefreshMs).toISOString()}`);
93
- }
94
- if (changedFiles.length > 0) {
95
- console.log(`changed-files-hint: ${changedFiles.join(', ')}`);
96
- }
97
- console.log(`root: ${rootDir}`);
98
- console.log(`files: ${summary.fileCount}`);
99
- console.log(`parsed: ${summary.parsedCodeFileCount}`);
100
- console.log(`reused: ${summary.reusedCodeFileCount}`);
101
- if (unreadable.length > 0) {
102
- console.log(`skipped-unreadable: ${unreadable.length}`);
103
- }
104
- console.log(`indexDir: ${summary.indexDir}`);
105
- }
106
-
107
- // The parse worker inside buildCodeIndex skips files it cannot read; the CLI
108
- // surfaces them so a partial index is never silent.
109
- async function collectUnreadableFiles(rootDir, entries) {
110
- const unreadable = await mapLimit(entries, INDEX_IO_CONCURRENCY, async (entry) => {
111
- try {
112
- await fs.access(entry.absolutePath, fs.constants.R_OK);
113
- return null;
114
- } catch {
115
- return path.relative(rootDir, entry.absolutePath).split(path.sep).join('/');
116
- }
117
- });
118
- return unreadable.filter(Boolean).sort();
119
- }
120
-
121
- async function partitionReadableHints(rootDir, hints) {
122
- const readable = [];
123
- const unreadable = [];
124
- for (const hint of hints) {
125
- try {
126
- await fs.access(path.resolve(rootDir, hint), fs.constants.R_OK);
127
- readable.push(hint);
128
- } catch (error) {
129
- if (error?.code === 'ENOENT') {
130
- readable.push(hint); // deleted file — a legitimate removal hint
131
- } else {
132
- unreadable.push(hint);
133
- }
134
- }
135
- }
136
- return { readable, unreadable };
137
- }
138
-
139
- function extractFlagValue(argv, flag) {
140
- let value = null;
141
- const nextArgs = [];
142
-
143
- for (let i = 0; i < argv.length; i += 1) {
144
- const arg = argv[i];
145
-
146
- if (arg === flag) {
147
- if (value !== null) {
148
- nextArgs.push(arg);
149
- continue;
150
- }
151
- const maybeValue = argv[i + 1];
152
- if (!maybeValue || maybeValue.startsWith('--')) {
153
- throw new Error(`Missing value for ${flag}.`);
154
- }
155
- value = maybeValue;
156
- i += 1;
157
- continue;
158
- }
159
-
160
- if (arg.startsWith(`${flag}=`)) {
161
- if (value === null) {
162
- value = arg.slice(flag.length + 1);
163
- continue;
164
- }
165
- }
166
-
167
- nextArgs.push(arg);
168
- }
169
-
170
- return { value, args: nextArgs };
171
- }
172
-
173
- async function getLastRefreshTime(rootDir) {
174
- const filesPath = path.join(rootDir, '.cache', 'index', 'files.json');
175
-
176
- try {
177
- const raw = await fs.readFile(filesPath, 'utf8');
178
- const artifact = JSON.parse(raw);
179
- const generatedAtRaw = String(artifact?.generatedAt ?? '').trim();
180
- if (!generatedAtRaw) {
181
- return null;
182
- }
183
- const generatedAtMs = Date.parse(generatedAtRaw);
184
- return Number.isNaN(generatedAtMs) ? null : generatedAtMs;
185
- } catch {
186
- return null;
187
- }
188
- }
189
-
190
- try {
191
- await main();
192
- } catch (error) {
193
- console.error(error && error.message ? error.message : error);
194
- process.exit(1);
195
- }