@aragon-agent/cli 0.6.78 → 0.6.79
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/README.md +89 -21
- package/dist/agent/controller.d.ts +36 -0
- package/dist/agent/controller.js +108 -0
- package/dist/agent/system-prompt.d.ts +10 -0
- package/dist/agent/system-prompt.js +6 -0
- package/dist/app/App.js +108 -27
- package/dist/app/index-console.d.ts +59 -0
- package/dist/app/index-console.js +99 -0
- package/dist/cli.js +80 -4
- package/dist/commands/builtins.js +4 -2
- package/dist/commands/catalog.js +7 -1
- package/dist/commands/index-build.js +10 -1
- package/dist/commands/index-command.d.ts +43 -0
- package/dist/commands/index-command.js +244 -0
- package/dist/commands/index-copy.d.ts +50 -0
- package/dist/commands/index-copy.js +82 -0
- package/dist/commands/kit-command.d.ts +10 -0
- package/dist/commands/kit-command.js +8 -2
- package/dist/commands/kits-command.d.ts +35 -0
- package/dist/commands/kits-command.js +137 -0
- package/dist/commands/registry.d.ts +10 -0
- package/dist/compaction/memory-agent.js +61 -0
- package/dist/config/env.d.ts +30 -0
- package/dist/config/env.js +47 -0
- package/dist/config/launch-notice.d.ts +61 -0
- package/dist/config/launch-notice.js +138 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.js +72 -2
- package/dist/diagnostics/info.d.ts +28 -0
- package/dist/diagnostics/info.js +41 -0
- package/dist/exec/cli-commands.d.ts +24 -0
- package/dist/exec/cli-commands.js +48 -1
- package/dist/exec/index.js +9 -0
- package/dist/exec/options.d.ts +12 -0
- package/dist/host/index-build.d.ts +38 -7
- package/dist/host/index-build.js +74 -20
- package/dist/indexer/commit.d.ts +77 -0
- package/dist/indexer/commit.js +145 -0
- package/dist/indexer/discover.d.ts +50 -0
- package/dist/indexer/discover.js +147 -0
- package/dist/indexer/engine.d.ts +51 -0
- package/dist/indexer/engine.js +477 -0
- package/dist/indexer/errors.d.ts +62 -0
- package/dist/indexer/errors.js +86 -0
- package/dist/indexer/finalize.d.ts +30 -0
- package/dist/indexer/finalize.js +19 -0
- package/dist/indexer/fingerprint.d.ts +41 -0
- package/dist/indexer/fingerprint.js +49 -0
- package/dist/indexer/ignore.d.ts +59 -0
- package/dist/indexer/ignore.js +140 -0
- package/dist/indexer/index.d.ts +21 -0
- package/dist/indexer/index.js +21 -0
- package/dist/indexer/l0.d.ts +55 -0
- package/dist/indexer/l0.js +168 -0
- package/dist/indexer/limits.d.ts +75 -0
- package/dist/indexer/limits.js +106 -0
- package/dist/indexer/link.d.ts +68 -0
- package/dist/indexer/link.js +220 -0
- package/dist/indexer/lock.d.ts +115 -0
- package/dist/indexer/lock.js +270 -0
- package/dist/indexer/parse.d.ts +68 -0
- package/dist/indexer/parse.js +163 -0
- package/dist/indexer/paths.d.ts +99 -0
- package/dist/indexer/paths.js +198 -0
- package/dist/indexer/plan.d.ts +48 -0
- package/dist/indexer/plan.js +80 -0
- package/dist/indexer/rank.d.ts +42 -0
- package/dist/indexer/rank.js +125 -0
- package/dist/indexer/read/cache.d.ts +28 -0
- package/dist/indexer/read/cache.js +54 -0
- package/dist/indexer/read/query.d.ts +48 -0
- package/dist/indexer/read/query.js +361 -0
- package/dist/indexer/scanner/extract.d.ts +36 -0
- package/dist/indexer/scanner/extract.js +134 -0
- package/dist/indexer/scanner/mask.d.ts +44 -0
- package/dist/indexer/scanner/mask.js +198 -0
- package/dist/indexer/scanner/py-extract.d.ts +29 -0
- package/dist/indexer/scanner/py-extract.js +164 -0
- package/dist/indexer/scanner/refs.d.ts +31 -0
- package/dist/indexer/scanner/refs.js +116 -0
- package/dist/indexer/scanner/ts-extract.d.ts +39 -0
- package/dist/indexer/scanner/ts-extract.js +277 -0
- package/dist/indexer/store.d.ts +88 -0
- package/dist/indexer/store.js +309 -0
- package/dist/indexer/tools.d.ts +120 -0
- package/dist/indexer/tools.js +132 -0
- package/dist/indexer/types.d.ts +225 -0
- package/dist/indexer/types.js +44 -0
- package/dist/indexer/wiring.d.ts +45 -0
- package/dist/indexer/wiring.js +42 -0
- package/dist/tools/index.d.ts +16 -2
- package/dist/tools/index.js +23 -0
- package/package.json +3 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/index`: the slash-command family for the deterministic AST index (spec 7.1).
|
|
3
|
+
*
|
|
4
|
+
* THREE ENTRY POINTS, ONE ENGINE. `Ctrl+I` / `Alt+I` (keys), this family, and the
|
|
5
|
+
* host bridge all resolve an `IndexEngine` through `createIndexer`, so the console,
|
|
6
|
+
* the status line and the desktop app cannot disagree about which workspace is
|
|
7
|
+
* indexed or what the settings are.
|
|
8
|
+
*
|
|
9
|
+
* THE GUARD ORDER IS A CONTRACT, the same one `/gov` and `/team` use:
|
|
10
|
+
*
|
|
11
|
+
* status / open / on / off / confirm - questions and switches, answerable in ANY
|
|
12
|
+
* session, including one where a build could
|
|
13
|
+
* not run (that is where users ask why).
|
|
14
|
+
* clean - takes the lock first: deleting a generation
|
|
15
|
+
* another process is writing is the only
|
|
16
|
+
* operation here that can truly corrupt an index.
|
|
17
|
+
* rebuild - STILL ASKS (P1-6). A destructive write does not
|
|
18
|
+
* become safe because the user can type; a user who
|
|
19
|
+
* wants no prompt sets `index.confirmOnBuild=false`,
|
|
20
|
+
* which is visible, reversible and announces itself.
|
|
21
|
+
*
|
|
22
|
+
* THE ROOT IS DISCOVERED, NEVER ASSUMED. Every path below comes from
|
|
23
|
+
* `indexPathsFor(discoverRoot(cwd).root)` - the SAME call `createIndexEngine` makes -
|
|
24
|
+
* because in a monorepo the git root is not the working directory. Reading
|
|
25
|
+
* `<cwd>/.claude-index/ast` while the engine writes `<root>/.claude-index/ast` made
|
|
26
|
+
* `/index clean` report "nothing to clean" and `/index open ast` report "not built"
|
|
27
|
+
* with a complete index on disk.
|
|
28
|
+
*
|
|
29
|
+
* ASCII ONLY: `commands/**` is inside `glyphs.test.ts::inScope`.
|
|
30
|
+
*/
|
|
31
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
32
|
+
import process from 'node:process';
|
|
33
|
+
import { spawn } from 'node:child_process';
|
|
34
|
+
import { getLogger } from '../logging/logger.js';
|
|
35
|
+
import { createIndexer } from '../indexer/wiring.js';
|
|
36
|
+
import { INDEX_DIR_NAME, discoverRoot, displayPath, indexPathsFor } from '../indexer/paths.js';
|
|
37
|
+
import { readLock, shouldTakeOver } from '../indexer/lock.js';
|
|
38
|
+
import { formatStatusLines } from '@aragon-agent/tui/model/index-build/format';
|
|
39
|
+
import { clampIndexConfig } from '@aragon-agent/tui/model/index-build/config';
|
|
40
|
+
import { CLEAN_DONE, INDEX_DISABLED_LINE, INDEX_USAGE, OPEN_AST_HINT, OPEN_PROSE_HINT, cleanConfirmSummary, cleanRefused, confirmLine, enabledLine, openMissingLine, } from './index-copy.js';
|
|
41
|
+
/** Split `args` into a subcommand and the rest, lower-cased for matching only. */
|
|
42
|
+
export function parseIndexArgs(args) {
|
|
43
|
+
const parts = args.trim().split(/\s+/).filter((part) => part !== '');
|
|
44
|
+
return { sub: (parts[0] ?? '').toLowerCase(), rest: parts.slice(1) };
|
|
45
|
+
}
|
|
46
|
+
/** The one definition of "where this workspace's artifacts live" (see the file header). */
|
|
47
|
+
export function indexArtifactPaths(cwd) {
|
|
48
|
+
return indexPathsFor(discoverRoot(cwd).root);
|
|
49
|
+
}
|
|
50
|
+
/** Register `/index` (spec 6.4). */
|
|
51
|
+
export function registerIndexCommand(registry) {
|
|
52
|
+
// THE DESCRIPTION IS A LITERAL HERE, AND THAT IS LOAD-BEARING. `doc-truth.test.ts`
|
|
53
|
+
// extracts command names and descriptions from SOURCE TEXT (`commandNamesInSource`),
|
|
54
|
+
// and it only recognises a literal `description: '...'` - a constant reference is
|
|
55
|
+
// invisible to it, so the command would read as "documented but nonexistent". The
|
|
56
|
+
// literal is therefore not duplication to be "cleaned up": `command-catalog.test.ts`
|
|
57
|
+
// compares this string against the catalog row and the docs, so the three cannot drift.
|
|
58
|
+
registry.register({
|
|
59
|
+
name: 'index',
|
|
60
|
+
description: 'Project index: status | rebuild | clean | open [ast] | on | off | confirm on|off',
|
|
61
|
+
run: (ctx) => {
|
|
62
|
+
runIndexCommand(ctx);
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Dispatch one `/index` invocation. Exported so the tests can call it without a registry. */
|
|
67
|
+
export function runIndexCommand(ctx) {
|
|
68
|
+
const { sub, rest } = parseIndexArgs(ctx.args);
|
|
69
|
+
const config = clampIndexConfig(ctx.controller.getIndexConfig());
|
|
70
|
+
switch (sub) {
|
|
71
|
+
case '':
|
|
72
|
+
// Plain `/index` is the console, exactly like the keystroke: the port reads the
|
|
73
|
+
// current status first, so the panel's first paint is complete.
|
|
74
|
+
openConsole(ctx);
|
|
75
|
+
return;
|
|
76
|
+
case 'status':
|
|
77
|
+
reportStatus(ctx, config.enabled);
|
|
78
|
+
return;
|
|
79
|
+
case 'rebuild':
|
|
80
|
+
if (!config.enabled) {
|
|
81
|
+
ctx.notify('warn', INDEX_DISABLED_LINE);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
// Opens the console in its CONFIRM phase: the same gate the keystroke uses.
|
|
85
|
+
openConsole(ctx);
|
|
86
|
+
return;
|
|
87
|
+
case 'clean':
|
|
88
|
+
// `yes` IS THE SECOND CONFIRMATION, and it has to reach `confirmedClean` or the
|
|
89
|
+
// command tells the user to type a word that does nothing (AC-25).
|
|
90
|
+
if (rest[0]?.toLowerCase() === 'yes')
|
|
91
|
+
confirmedClean(ctx);
|
|
92
|
+
else
|
|
93
|
+
cleanGenerations(ctx);
|
|
94
|
+
return;
|
|
95
|
+
case 'open':
|
|
96
|
+
openTarget(ctx, rest[0]?.toLowerCase() === 'ast' ? 'ast' : 'prose', config.enabled);
|
|
97
|
+
return;
|
|
98
|
+
case 'on':
|
|
99
|
+
case 'off':
|
|
100
|
+
setEnabled(ctx, sub === 'on');
|
|
101
|
+
return;
|
|
102
|
+
case 'confirm':
|
|
103
|
+
setConfirm(ctx, rest[0]);
|
|
104
|
+
return;
|
|
105
|
+
default:
|
|
106
|
+
ctx.notify('warn', INDEX_USAGE);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** Open the console through the App's adapter when it is wired, else bare (tests). */
|
|
110
|
+
function openConsole(ctx) {
|
|
111
|
+
if (ctx.openIndexConsole)
|
|
112
|
+
ctx.openIndexConsole();
|
|
113
|
+
else
|
|
114
|
+
ctx.setOverlay('index');
|
|
115
|
+
}
|
|
116
|
+
/** `/index status`: generation, counts, resolution rate, staleness, artifact path. */
|
|
117
|
+
async function reportStatusAsync(ctx, enabled) {
|
|
118
|
+
if (!enabled) {
|
|
119
|
+
ctx.notify('info', INDEX_DISABLED_LINE);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const indexer = createIndexer({
|
|
124
|
+
cwd: ctx.controller.getCwd(),
|
|
125
|
+
config: ctx.controller.getIndexConfig(),
|
|
126
|
+
log: (event, fields) => getLogger().debug('cli', event, fields),
|
|
127
|
+
});
|
|
128
|
+
const status = await indexer.engine.status();
|
|
129
|
+
const lines = formatStatusLines(status, displayPath(`${INDEX_DIR_NAME}/ast`));
|
|
130
|
+
ctx.notify(status.present ? 'info' : 'warn', lines.join('\n'));
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
134
|
+
ctx.notify('error', `Could not read the index status: ${message}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Sync wrapper: the registry's `run` is synchronous, so the promise is fire-and-forget. */
|
|
138
|
+
function reportStatus(ctx, enabled) {
|
|
139
|
+
void reportStatusAsync(ctx, enabled);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* `/index clean`: refuse while another process holds the lock, then require a second
|
|
143
|
+
* confirmation, then delete every generation and leave the prose files alone.
|
|
144
|
+
*/
|
|
145
|
+
function cleanGenerations(ctx) {
|
|
146
|
+
const paths = indexArtifactPaths(ctx.controller.getCwd());
|
|
147
|
+
// THE TAKEOVER RULE, NOT A BARE READ (spec 5.6 / I-3): a pid that died hours ago still
|
|
148
|
+
// owns the lockfile, and refusing on its behalf would make `/index clean` unusable after
|
|
149
|
+
// exactly the crash the stale sweep exists for. A lock this process holds is not a
|
|
150
|
+
// conflict either - `/index clean` is allowed while our own build is running.
|
|
151
|
+
const holder = readLock(paths);
|
|
152
|
+
if (holder && holder.pid !== process.pid && shouldTakeOver(holder, Date.now()) === 'none') {
|
|
153
|
+
ctx.notify('warn', cleanRefused(holder.pid));
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const generations = countGenerations(paths.generationsDir);
|
|
157
|
+
if (generations === 0 && !existsSync(paths.currentFile)) {
|
|
158
|
+
ctx.notify('info', 'No generated index to clean. /index rebuild creates one.');
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
// Second confirmation: this deletes every generation, which is the one action here
|
|
162
|
+
// that cannot be undone by reading the artifact again. The words come from
|
|
163
|
+
// `index-copy.ts` so this file owns no user-visible sentence of its own.
|
|
164
|
+
ctx.notify('warn', `${cleanConfirmSummary(ctx.controller.getCwd())}\n\n${generations} ${generations === 1 ? 'generation' : 'generations'} on disk. Reply with /index clean yes to confirm.`);
|
|
165
|
+
}
|
|
166
|
+
/** `/index clean yes` deletes; the first pass only asked. */
|
|
167
|
+
function confirmedClean(ctx) {
|
|
168
|
+
const indexer = createIndexer({
|
|
169
|
+
cwd: ctx.controller.getCwd(),
|
|
170
|
+
config: ctx.controller.getIndexConfig(),
|
|
171
|
+
log: (event, fields) => getLogger().debug('cli', event, fields),
|
|
172
|
+
});
|
|
173
|
+
void indexer.engine
|
|
174
|
+
.clean()
|
|
175
|
+
.then(() => ctx.notify('info', CLEAN_DONE))
|
|
176
|
+
.catch((error) => {
|
|
177
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
178
|
+
ctx.notify('error', message);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/** Generations present on disk, for the clean confirmation text. */
|
|
182
|
+
function countGenerations(generationsDir) {
|
|
183
|
+
try {
|
|
184
|
+
return readdirSync(generationsDir).filter((entry) => /^\d+$/.test(entry)).length;
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/** `/index open [ast]`: hand the artifact to the OS default program. */
|
|
191
|
+
function openTarget(ctx, which, enabled) {
|
|
192
|
+
if (!enabled) {
|
|
193
|
+
ctx.notify('warn', INDEX_DISABLED_LINE);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const paths = indexArtifactPaths(ctx.controller.getCwd());
|
|
197
|
+
const target = which === 'ast' ? paths.astDir : paths.proseIndexFile;
|
|
198
|
+
if (!existsSync(target)) {
|
|
199
|
+
ctx.notify('warn', openMissingLine(which));
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
ctx.notify('info', which === 'ast' ? OPEN_AST_HINT : OPEN_PROSE_HINT);
|
|
203
|
+
openWithSystem(target);
|
|
204
|
+
}
|
|
205
|
+
/** Open a path with the platform's default handler, ignoring a failure (the notice already named it). */
|
|
206
|
+
function openWithSystem(target) {
|
|
207
|
+
const command = process.platform === 'win32' ? 'cmd' : process.platform === 'darwin' ? 'open' : 'xdg-open';
|
|
208
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', target] : [target];
|
|
209
|
+
try {
|
|
210
|
+
const child = spawn(command, args, { detached: true, stdio: 'ignore' });
|
|
211
|
+
// `spawn` REPORTS A MISSING OPENER ASYNCHRONOUSLY through an `error` event, so the
|
|
212
|
+
// try/catch below never saw it: on a host without `xdg-open` this threw an uncaught
|
|
213
|
+
// exception inside the running TUI. The notice above already named the path.
|
|
214
|
+
child.on('error', () => undefined);
|
|
215
|
+
child.unref();
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// Synchronous failure (a malformed command): same answer as above.
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** `/index on|off`: the master switch. Off removes the tool and the prompt block. */
|
|
222
|
+
function setEnabled(ctx, enabled) {
|
|
223
|
+
ctx.persistConfig({ index: { ...clampIndexConfig(ctx.controller.getIndexConfig()), enabled } });
|
|
224
|
+
// THE SAME PATCH, ALSO TO THE LIVE SESSION. Without this second half the command reports
|
|
225
|
+
// success and nothing changes until the next launch (the `setTodoConfig` lesson).
|
|
226
|
+
ctx.controller.applyIndexConfig({ enabled });
|
|
227
|
+
ctx.notify('info', enabledLine(enabled));
|
|
228
|
+
}
|
|
229
|
+
/** `/index confirm on|off`: the session's ask-before-writing switch. */
|
|
230
|
+
function setConfirm(ctx, value) {
|
|
231
|
+
// AN AMBIGUOUS VALUE IS REFUSED, NOT READ AS `off`. `/index confirm of` (a typo) used to
|
|
232
|
+
// disable the build gate and print the banner, i.e. a typo silently removed a safety net.
|
|
233
|
+
const normalized = value?.toLowerCase();
|
|
234
|
+
if (normalized !== 'on' && normalized !== 'off') {
|
|
235
|
+
ctx.notify('warn', 'Usage: /index confirm on|off');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const confirmOnBuild = normalized === 'on';
|
|
239
|
+
ctx.persistConfig({
|
|
240
|
+
index: { ...clampIndexConfig(ctx.controller.getIndexConfig()), confirmOnBuild },
|
|
241
|
+
});
|
|
242
|
+
ctx.controller.applyIndexConfig({ confirmOnBuild });
|
|
243
|
+
ctx.notify(confirmOnBuild ? 'info' : 'warn', confirmLine(confirmOnBuild));
|
|
244
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every user-visible sentence the index feature adds, in one ASCII module
|
|
3
|
+
* (spec 6.3 `commands/index-copy.ts`).
|
|
4
|
+
*
|
|
5
|
+
* WHY ONE FILE: `commands/**` is inside the glyph scanner's scope, so an em dash
|
|
6
|
+
* that slips in here is a mojibake bug on a legacy console; and the confirm dialog,
|
|
7
|
+
* the result card, `/index status` and the host bridge must word the same fact the
|
|
8
|
+
* same way. Two copies of a sentence drift exactly like two copies of a name list.
|
|
9
|
+
*
|
|
10
|
+
* ASCII ONLY, EVERY BYTE. Box drawing and check marks come from `pickGlyphs` in the
|
|
11
|
+
* renderer, never from a string here.
|
|
12
|
+
*/
|
|
13
|
+
/** Result of one `/index <sub>` dispatch, as the command layer reports it. */
|
|
14
|
+
export interface IndexCommandReply {
|
|
15
|
+
/** Message kind; the toast colour follows it. */
|
|
16
|
+
readonly level: 'info' | 'warn' | 'error';
|
|
17
|
+
/** Body text, already ASCII and user-ready. */
|
|
18
|
+
readonly text: string;
|
|
19
|
+
}
|
|
20
|
+
/** The confirm dialog for a build that writes a new generation (spec 5.9). */
|
|
21
|
+
export declare function buildConfirmSummary(input: {
|
|
22
|
+
readonly cwd: string;
|
|
23
|
+
readonly hasExistingIndex: boolean;
|
|
24
|
+
readonly includeProse: boolean;
|
|
25
|
+
}): string;
|
|
26
|
+
/** Banner printed on the first build after `index.confirmOnBuild` was turned off (spec 5.9). */
|
|
27
|
+
export declare const CONFIRM_DISABLED_BANNER = "Index confirmation is off: Ctrl+I now builds without asking. Run /index confirm on to restore it.";
|
|
28
|
+
/** Shown when the feature is disabled. */
|
|
29
|
+
export declare const INDEX_DISABLED_LINE = "The project index is off. Run /index on to enable it.";
|
|
30
|
+
/** Shown when another process owns the writer lock. */
|
|
31
|
+
export declare function busyLine(pid: number): string;
|
|
32
|
+
/** `/index clean` needs a second confirmation because it deletes every generation. */
|
|
33
|
+
export declare function cleanConfirmSummary(cwd: string): string;
|
|
34
|
+
/** `/index clean` success. */
|
|
35
|
+
export declare const CLEAN_DONE = "Index generations deleted. The prose index files were kept. /index rebuild to recreate.";
|
|
36
|
+
/** `/index clean` refused because the lock is held. */
|
|
37
|
+
export declare function cleanRefused(pid: number): string;
|
|
38
|
+
/** `index.enabled` toggled. */
|
|
39
|
+
export declare function enabledLine(enabled: boolean): string;
|
|
40
|
+
/** `index.confirmOnBuild` toggled. */
|
|
41
|
+
export declare function confirmLine(confirmOnBuild: boolean): string;
|
|
42
|
+
/** `/index open` targets. */
|
|
43
|
+
export declare const OPEN_PROSE_HINT = "Opening the prose index. Use /index open ast to open the generated artifacts.";
|
|
44
|
+
export declare const OPEN_AST_HINT = "Opening the generated index artifacts.";
|
|
45
|
+
/** Nothing to open yet. */
|
|
46
|
+
export declare function openMissingLine(which: 'prose' | 'ast'): string;
|
|
47
|
+
/** Usage line for an unknown subcommand: lists the legal ones. */
|
|
48
|
+
export declare const INDEX_USAGE = "Usage: /index [status|rebuild|clean|open [ast]|on|off|confirm on|off]. Plain /index opens the index console.";
|
|
49
|
+
/** Sentence appended to the prose-stage skill arguments when the AST stage failed (spec 5.10). */
|
|
50
|
+
export declare function proseAfterFailureArgs(code: string): string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every user-visible sentence the index feature adds, in one ASCII module
|
|
3
|
+
* (spec 6.3 `commands/index-copy.ts`).
|
|
4
|
+
*
|
|
5
|
+
* WHY ONE FILE: `commands/**` is inside the glyph scanner's scope, so an em dash
|
|
6
|
+
* that slips in here is a mojibake bug on a legacy console; and the confirm dialog,
|
|
7
|
+
* the result card, `/index status` and the host bridge must word the same fact the
|
|
8
|
+
* same way. Two copies of a sentence drift exactly like two copies of a name list.
|
|
9
|
+
*
|
|
10
|
+
* ASCII ONLY, EVERY BYTE. Box drawing and check marks come from `pickGlyphs` in the
|
|
11
|
+
* renderer, never from a string here.
|
|
12
|
+
*/
|
|
13
|
+
import { INDEX_DIR_NAME } from '../indexer/paths.js';
|
|
14
|
+
/** The confirm dialog for a build that writes a new generation (spec 5.9). */
|
|
15
|
+
export function buildConfirmSummary(input) {
|
|
16
|
+
const action = input.hasExistingIndex ? 'Rebuild' : 'Build';
|
|
17
|
+
const lines = [
|
|
18
|
+
`${action} the project index for this workspace?`,
|
|
19
|
+
'',
|
|
20
|
+
`Writes, inside ${INDEX_DIR_NAME}\\ast\\ :`,
|
|
21
|
+
'- generations\\<n>\\ (symbols, references, imports, file graph)',
|
|
22
|
+
'- current (moved only after a complete, verified build)',
|
|
23
|
+
];
|
|
24
|
+
if (input.includeProse) {
|
|
25
|
+
lines.push('', 'Then runs the bundled "project-indexer" skill as a normal agent turn:', `- ${INDEX_DIR_NAME}\\index.md and ${INDEX_DIR_NAME}\\config.md`, '- the "## Project Index" and "## Clean Code Guidelines" sections of CLAUDE.md and AGENTS.md');
|
|
26
|
+
}
|
|
27
|
+
lines.push('', 'A failed or cancelled build leaves the previous index untouched.', `Workspace: ${input.cwd}`, `Add "${INDEX_DIR_NAME}/ast/" to .gitignore if you do not want to commit it.`);
|
|
28
|
+
return lines.join('\n');
|
|
29
|
+
}
|
|
30
|
+
/** Banner printed on the first build after `index.confirmOnBuild` was turned off (spec 5.9). */
|
|
31
|
+
export const CONFIRM_DISABLED_BANNER = 'Index confirmation is off: Ctrl+I now builds without asking. Run /index confirm on to restore it.';
|
|
32
|
+
/** Shown when the feature is disabled. */
|
|
33
|
+
export const INDEX_DISABLED_LINE = 'The project index is off. Run /index on to enable it.';
|
|
34
|
+
/** Shown when another process owns the writer lock. */
|
|
35
|
+
export function busyLine(pid) {
|
|
36
|
+
return `Another process is building the index (pid ${pid}). Press Ctrl+I to watch it.`;
|
|
37
|
+
}
|
|
38
|
+
/** `/index clean` needs a second confirmation because it deletes every generation. */
|
|
39
|
+
export function cleanConfirmSummary(cwd) {
|
|
40
|
+
return [
|
|
41
|
+
'Delete every generated index generation for this workspace?',
|
|
42
|
+
'',
|
|
43
|
+
`Removes ${INDEX_DIR_NAME}\\ast\\generations\\ and the current pointer.`,
|
|
44
|
+
`Keeps ${INDEX_DIR_NAME}\\index.md and ${INDEX_DIR_NAME}\\config.md.`,
|
|
45
|
+
'',
|
|
46
|
+
`Workspace: ${cwd}`,
|
|
47
|
+
'This cannot be undone, but a rebuild recreates everything.',
|
|
48
|
+
].join('\n');
|
|
49
|
+
}
|
|
50
|
+
/** `/index clean` success. */
|
|
51
|
+
export const CLEAN_DONE = 'Index generations deleted. The prose index files were kept. /index rebuild to recreate.';
|
|
52
|
+
/** `/index clean` refused because the lock is held. */
|
|
53
|
+
export function cleanRefused(pid) {
|
|
54
|
+
return `Cannot clean while another process is building (pid ${pid}). Wait for it to finish, then run /index clean.`;
|
|
55
|
+
}
|
|
56
|
+
/** `index.enabled` toggled. */
|
|
57
|
+
export function enabledLine(enabled) {
|
|
58
|
+
return enabled
|
|
59
|
+
? 'Project index enabled. Ctrl+I builds it; code_query answers from it.'
|
|
60
|
+
: 'Project index disabled. Ctrl+I, /index and code_query are off until /index on.';
|
|
61
|
+
}
|
|
62
|
+
/** `index.confirmOnBuild` toggled. */
|
|
63
|
+
export function confirmLine(confirmOnBuild) {
|
|
64
|
+
return confirmOnBuild
|
|
65
|
+
? 'Index builds will ask for confirmation again.'
|
|
66
|
+
: CONFIRM_DISABLED_BANNER;
|
|
67
|
+
}
|
|
68
|
+
/** `/index open` targets. */
|
|
69
|
+
export const OPEN_PROSE_HINT = 'Opening the prose index. Use /index open ast to open the generated artifacts.';
|
|
70
|
+
export const OPEN_AST_HINT = 'Opening the generated index artifacts.';
|
|
71
|
+
/** Nothing to open yet. */
|
|
72
|
+
export function openMissingLine(which) {
|
|
73
|
+
return which === 'ast'
|
|
74
|
+
? 'No generated index yet. Run /index rebuild first.'
|
|
75
|
+
: `No ${INDEX_DIR_NAME}/index.md yet. Run /index rebuild (with the prose stage) first.`;
|
|
76
|
+
}
|
|
77
|
+
/** Usage line for an unknown subcommand: lists the legal ones. */
|
|
78
|
+
export const INDEX_USAGE = 'Usage: /index [status|rebuild|clean|open [ast]|on|off|confirm on|off]. Plain /index opens the index console.';
|
|
79
|
+
/** Sentence appended to the prose-stage skill arguments when the AST stage failed (spec 5.10). */
|
|
80
|
+
export function proseAfterFailureArgs(code) {
|
|
81
|
+
return `Note: the AST index build failed (${code}); the prose index below is written without structural counts.`;
|
|
82
|
+
}
|
|
@@ -14,6 +14,16 @@
|
|
|
14
14
|
* promise. Setting a default is a settings action, with a Save the user sees.
|
|
15
15
|
*/
|
|
16
16
|
import type { CommandRegistry, CommandContext } from './registry.js';
|
|
17
|
+
import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
|
|
18
|
+
import { type AgentKit } from '@aragon-agent/tui/model/config/model-kits';
|
|
19
|
+
/**
|
|
20
|
+
* `main a:b / sub same as main / fast off`, shared by every branch below.
|
|
21
|
+
*
|
|
22
|
+
* EXPORTED for the launch notice (launch-model-and-kit-flags 2.5): one kit must
|
|
23
|
+
* not be described two ways depending on whether it arrived from `--kit` or from
|
|
24
|
+
* `Ctrl+K`, and the only way to guarantee that is to render it in one place.
|
|
25
|
+
*/
|
|
26
|
+
export declare function describeKit(config: CliConfig, kit: AgentKit): string;
|
|
17
27
|
/** The command body; `registerKitCommand` is the only registration site. */
|
|
18
28
|
export declare function runKitCommand(ctx: CommandContext): void;
|
|
19
29
|
/** Registered from `builtins.ts` with one line, next to every other subsystem. */
|
|
@@ -15,8 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { kitMatches, findKit, kitSlotConnections } from '@aragon-agent/tui/model/config/model-kits';
|
|
17
17
|
import { kitApplyMessage, kitNoteMessages } from '../agent/kit-apply.js';
|
|
18
|
-
/**
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* `main a:b / sub same as main / fast off`, shared by every branch below.
|
|
20
|
+
*
|
|
21
|
+
* EXPORTED for the launch notice (launch-model-and-kit-flags 2.5): one kit must
|
|
22
|
+
* not be described two ways depending on whether it arrived from `--kit` or from
|
|
23
|
+
* `Ctrl+K`, and the only way to guarantee that is to render it in one place.
|
|
24
|
+
*/
|
|
25
|
+
export function describeKit(config, kit) {
|
|
20
26
|
const connections = kitSlotConnections(config.modelProfiles, kit);
|
|
21
27
|
const main = connections.main
|
|
22
28
|
? `${connections.main.provider}:${connections.main.model}` : 'Profile missing';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aragon kits list | show` - the discoverable half of launch selection
|
|
3
|
+
* (launch-model-and-kit-flags 3.10 / 2.5).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/commands/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* WHY A READ-ONLY PAIR AND NOTHING ELSE (R-3 / P2-1): without a way to list kits,
|
|
8
|
+
* `--kit` would require opening the TUI first, which locks the feature inside the
|
|
9
|
+
* interactive surface. But a `set-default` / `rm` verb here would be a THIRD path
|
|
10
|
+
* that changes configuration, beside Settings and `config set` - and the one thing
|
|
11
|
+
* this feature must never do is let a launch flag become a saved default (D-7).
|
|
12
|
+
* So: two verbs, both read-only, both `--json`-capable for scripts.
|
|
13
|
+
*
|
|
14
|
+
* MATCHING IS `kitMatches()` AND NOTHING ELSE (I-4): the same function `--kit`,
|
|
15
|
+
* `/kit use` and `Ctrl+K` use, so "how a name matches" cannot have a second shape.
|
|
16
|
+
*/
|
|
17
|
+
import type { Command } from 'commander';
|
|
18
|
+
import type { CliFlags } from '../config/load.js';
|
|
19
|
+
import type { CliConfig } from '@aragon-agent/tui/model/config/schema';
|
|
20
|
+
export interface KitsCommandDeps {
|
|
21
|
+
/** stdout, injectable so the tests can read it without capturing the process. */
|
|
22
|
+
out?: (text: string) => void;
|
|
23
|
+
/** stderr, for the exit-2 sentences. */
|
|
24
|
+
err?: (text: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/** `kits list` / `kits show <ref>`; returns the process exit code. */
|
|
27
|
+
export declare function runKitsCommand(argv: string[], config: CliConfig, deps?: KitsCommandDeps): number;
|
|
28
|
+
/**
|
|
29
|
+
* Register the `kits` family.
|
|
30
|
+
*
|
|
31
|
+
* REGISTERED LIKE `gene`: the declaration lives here rather than in `cli.tsx`
|
|
32
|
+
* (which is 60% over the guideline) and this module owns its own options, so
|
|
33
|
+
* `aragon kits --help` stays the complete list of what it accepts.
|
|
34
|
+
*/
|
|
35
|
+
export declare function registerKitsCommand(program: Command, toFlags: (opts: Record<string, unknown>) => CliFlags): void;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `aragon kits list | show` - the discoverable half of launch selection
|
|
3
|
+
* (launch-model-and-kit-flags 3.10 / 2.5).
|
|
4
|
+
*
|
|
5
|
+
* ASCII ONLY - `src/commands/**` is inside `glyphs.test.ts::inScope`.
|
|
6
|
+
*
|
|
7
|
+
* WHY A READ-ONLY PAIR AND NOTHING ELSE (R-3 / P2-1): without a way to list kits,
|
|
8
|
+
* `--kit` would require opening the TUI first, which locks the feature inside the
|
|
9
|
+
* interactive surface. But a `set-default` / `rm` verb here would be a THIRD path
|
|
10
|
+
* that changes configuration, beside Settings and `config set` - and the one thing
|
|
11
|
+
* this feature must never do is let a launch flag become a saved default (D-7).
|
|
12
|
+
* So: two verbs, both read-only, both `--json`-capable for scripts.
|
|
13
|
+
*
|
|
14
|
+
* MATCHING IS `kitMatches()` AND NOTHING ELSE (I-4): the same function `--kit`,
|
|
15
|
+
* `/kit use` and `Ctrl+K` use, so "how a name matches" cannot have a second shape.
|
|
16
|
+
*/
|
|
17
|
+
import process from 'node:process';
|
|
18
|
+
import { loadConfig } from '../config/load.js';
|
|
19
|
+
import { kitMatches, kitSlotConnections } from '@aragon-agent/tui/model/config/model-kits';
|
|
20
|
+
import { resolveActiveKit } from '@aragon-agent/tui/model/config/kit-resolution';
|
|
21
|
+
/** Exit codes, matching `exit-codes.mjs` (0 ok, 2 usage, and nothing on stdout for 2). */
|
|
22
|
+
const EXIT_OK = 0;
|
|
23
|
+
const EXIT_USAGE = 2;
|
|
24
|
+
function connection(provider, model) {
|
|
25
|
+
if (!provider && !model)
|
|
26
|
+
return 'not set';
|
|
27
|
+
if (!provider)
|
|
28
|
+
return model ?? 'not set';
|
|
29
|
+
if (!model)
|
|
30
|
+
return provider;
|
|
31
|
+
return `${provider}:${model}`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Flatten one kit into the five fields both output shapes print.
|
|
35
|
+
*
|
|
36
|
+
* THE SLOTS COME FROM `kitSlotConnections()`, not from a second dereference of
|
|
37
|
+
* `modelProfiles.entries`: that function is what `/kit` and the picker already use
|
|
38
|
+
* for "what does this slot resolve to", and a second lookup would answer the same
|
|
39
|
+
* question with a second implementation.
|
|
40
|
+
*/
|
|
41
|
+
function rowOf(config, kit, activeId, defaultId) {
|
|
42
|
+
const connections = kitSlotConnections(config.modelProfiles, kit);
|
|
43
|
+
const sub = kit.subagent.model === 'main' ? 'same as main'
|
|
44
|
+
: kit.subagent.model === 'fast' ? 'fast tier'
|
|
45
|
+
: connections.subagent.name ? `profile ${connections.subagent.name}` : 'Profile missing';
|
|
46
|
+
return { id: kit.id, name: kit.name, active: kit.id === activeId,
|
|
47
|
+
isDefault: kit.id === defaultId,
|
|
48
|
+
main: connections.main
|
|
49
|
+
? connection(connections.main.provider, connections.main.model) : 'Profile missing',
|
|
50
|
+
// D-8: a null fast profile means this kit TURNS THE TIER OFF.
|
|
51
|
+
fast: kit.fastProfileId === null ? 'off'
|
|
52
|
+
: connections.fast ? connection(connections.fast.provider, connections.fast.model)
|
|
53
|
+
: 'Profile missing',
|
|
54
|
+
subagent: sub };
|
|
55
|
+
}
|
|
56
|
+
function rowsOf(config) {
|
|
57
|
+
const active = resolveActiveKit(config);
|
|
58
|
+
const defaultId = config.modelProfiles?.defaultKitId ?? null;
|
|
59
|
+
return (config.modelProfiles?.kits ?? []).map((kit) => rowOf(config, kit, active.source === 'none' ? null : active.id, defaultId));
|
|
60
|
+
}
|
|
61
|
+
/** Markers, in the order `/kit list` prints them, so two surfaces read alike. */
|
|
62
|
+
function markersOf(row) {
|
|
63
|
+
const markers = [row.active ? 'active' : '', row.isDefault ? 'default' : '']
|
|
64
|
+
.filter(Boolean).join(', ');
|
|
65
|
+
return markers ? ` (${markers})` : '';
|
|
66
|
+
}
|
|
67
|
+
function renderList(rows) {
|
|
68
|
+
if (!rows.length)
|
|
69
|
+
return 'No kits yet. Create one in /settings (Settings > Kit pack).';
|
|
70
|
+
return rows.map((row) => `${row.name}${markersOf(row)}\n`
|
|
71
|
+
+ ` main ${row.main} / sub ${row.subagent} / fast ${row.fast}\n`
|
|
72
|
+
+ ` id ${row.id}`).join('\n');
|
|
73
|
+
}
|
|
74
|
+
function renderShow(row) {
|
|
75
|
+
const markers = row.active ? 'active' : row.isDefault ? 'default' : 'not in use';
|
|
76
|
+
return [`${row.name} (${markers})`, ` id ${row.id}`,
|
|
77
|
+
` main ${row.main}`, ` fast ${row.fast}`,
|
|
78
|
+
` subagent ${row.subagent}`].join('\n');
|
|
79
|
+
}
|
|
80
|
+
/** `kits list` / `kits show <ref>`; returns the process exit code. */
|
|
81
|
+
export function runKitsCommand(argv, config, deps = {}) {
|
|
82
|
+
const out = deps.out ?? ((text) => void process.stdout.write(`${text}\n`));
|
|
83
|
+
const err = deps.err ?? ((text) => void process.stderr.write(`${text}\n`));
|
|
84
|
+
const json = argv.includes('--json');
|
|
85
|
+
const words = argv.filter((arg) => !arg.startsWith('--'));
|
|
86
|
+
const verb = words[0] ?? 'list';
|
|
87
|
+
const rows = rowsOf(config);
|
|
88
|
+
if (verb === 'list') {
|
|
89
|
+
out(json ? JSON.stringify({ kits: rows }, null, 2) : renderList(rows));
|
|
90
|
+
return EXIT_OK;
|
|
91
|
+
}
|
|
92
|
+
if (verb !== 'show') {
|
|
93
|
+
err(`Unknown kits subcommand "${verb}". Use: kits list | kits show <name|#id>.`);
|
|
94
|
+
return EXIT_USAGE;
|
|
95
|
+
}
|
|
96
|
+
const ref = words[1];
|
|
97
|
+
if (!ref) {
|
|
98
|
+
err('kits show needs a kit: aragon kits show <name|#id>.');
|
|
99
|
+
return EXIT_USAGE;
|
|
100
|
+
}
|
|
101
|
+
const matches = kitMatches(config.modelProfiles, ref);
|
|
102
|
+
const only = matches[0];
|
|
103
|
+
if (matches.length === 1 && only) {
|
|
104
|
+
out(json ? JSON.stringify({ kit: rows.find((row) => row.id === only.id) }, null, 2)
|
|
105
|
+
: renderShow(rows.find((row) => row.id === only.id)));
|
|
106
|
+
return EXIT_OK;
|
|
107
|
+
}
|
|
108
|
+
// EXIT 2 WITH AN EMPTY STDOUT, like every other refused reference in 2.4: the
|
|
109
|
+
// `--json` contract promises one object there, so a diagnostic sentence in its
|
|
110
|
+
// place would break every script that reads it.
|
|
111
|
+
if (matches.length === 0) {
|
|
112
|
+
const names = (config.modelProfiles?.kits ?? []).map((kit) => kit.name);
|
|
113
|
+
err(`No kit named "${ref}". Available: ${names.length ? names.join(', ') : 'none'}.`);
|
|
114
|
+
return EXIT_USAGE;
|
|
115
|
+
}
|
|
116
|
+
const ids = matches.map((kit) => `#${kit.id.slice(0, 8)} ${kit.name}`).join(', ');
|
|
117
|
+
err(`Kit reference "${ref}" matches ${matches.length} kits: ${ids}. Use the id prefix.`);
|
|
118
|
+
return EXIT_USAGE;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Register the `kits` family.
|
|
122
|
+
*
|
|
123
|
+
* REGISTERED LIKE `gene`: the declaration lives here rather than in `cli.tsx`
|
|
124
|
+
* (which is 60% over the guideline) and this module owns its own options, so
|
|
125
|
+
* `aragon kits --help` stays the complete list of what it accepts.
|
|
126
|
+
*/
|
|
127
|
+
export function registerKitsCommand(program, toFlags) {
|
|
128
|
+
program
|
|
129
|
+
.command('kits [subcommand] [ref]')
|
|
130
|
+
.description('List the model kits (dev packs) on this machine, or show one')
|
|
131
|
+
.option('--json', 'Machine-readable output')
|
|
132
|
+
.action((subcommand, ref, opts) => {
|
|
133
|
+
const argv = [subcommand ?? 'list', ...(ref ? [ref] : []),
|
|
134
|
+
...(opts.json ? ['--json'] : [])];
|
|
135
|
+
process.exitCode = runKitsCommand(argv, loadConfig(toFlags(program.opts())));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
@@ -25,6 +25,16 @@ export interface CommandContext {
|
|
|
25
25
|
state: ViewState;
|
|
26
26
|
dispatch: (action: ViewAction) => void;
|
|
27
27
|
setOverlay: (overlay: Overlay) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Open the index console the SAME WAY `Ctrl+I` does: read `status()` first, then show
|
|
30
|
+
* the panel, then build when confirmation is off (tui-ctrl-i-ast-index 5.9 / HCI rule 7).
|
|
31
|
+
*
|
|
32
|
+
* WHY A PORT AND NOT `setOverlay('index')`: the overlay alone renders the panel with no
|
|
33
|
+
* status, so the first paint says "No index status available" over a complete index and
|
|
34
|
+
* the confirm step cannot show the current generation. Optional so every existing
|
|
35
|
+
* hand-built context in the tests stays valid.
|
|
36
|
+
*/
|
|
37
|
+
openIndexConsole?: () => void;
|
|
28
38
|
/** Durable transcript message (errors, listings, saved paths). */
|
|
29
39
|
notify: (level: NoticeLevel, text: string) => void;
|
|
30
40
|
/** Ephemeral, auto-dismissing acknowledgement (spec §3.9). */
|