@aragon-agent/cli 0.6.24 → 0.6.25

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 (37) hide show
  1. package/CHANGELOG.md +1835 -1786
  2. package/README.md +2578 -2562
  3. package/dist/agent/controller.d.ts +49 -3
  4. package/dist/agent/controller.js +78 -3
  5. package/dist/agent/conversation-reset.d.ts +91 -0
  6. package/dist/agent/conversation-reset.js +66 -0
  7. package/dist/agent/model-probe-limits.d.ts +39 -0
  8. package/dist/agent/model-probe-limits.js +25 -0
  9. package/dist/agent/model-probe.d.ts +104 -0
  10. package/dist/agent/model-probe.js +391 -0
  11. package/dist/agent/reducer.js +45 -13
  12. package/dist/commands/builtins.js +14 -34
  13. package/dist/commands/clear-command.d.ts +27 -0
  14. package/dist/commands/clear-command.js +107 -0
  15. package/dist/commands/registry.d.ts +20 -1
  16. package/dist/config/model-profiles.d.ts +8 -0
  17. package/dist/config/model-profiles.js +10 -0
  18. package/dist/session/clear-archive.d.ts +51 -0
  19. package/dist/session/clear-archive.js +160 -0
  20. package/dist/todo/types.d.ts +5 -3
  21. package/dist/ui/App.js +39 -7
  22. package/dist/ui/entries/CompactionCard.d.ts +5 -4
  23. package/dist/ui/entries/CompactionCard.js +5 -4
  24. package/dist/ui/overlays/HelpOverlay.js +8 -2
  25. package/dist/ui/overlays/ModelDiscoveryList.d.ts +23 -0
  26. package/dist/ui/overlays/ModelDiscoveryList.js +161 -0
  27. package/dist/ui/overlays/ModelProfileEditor.d.ts +18 -1
  28. package/dist/ui/overlays/ModelProfileEditor.js +117 -68
  29. package/dist/ui/overlays/SettingsScreen.d.ts +8 -0
  30. package/dist/ui/overlays/SettingsScreen.js +34 -2
  31. package/dist/ui/overlays/model-probe-view.d.ts +128 -0
  32. package/dist/ui/overlays/model-probe-view.js +225 -0
  33. package/dist/ui/overlays/model-profile-state.d.ts +9 -1
  34. package/dist/ui/overlays/model-profile-state.js +10 -0
  35. package/dist/ui/overlays/use-model-probe.d.ts +30 -0
  36. package/dist/ui/overlays/use-model-probe.js +109 -0
  37. package/package.json +2 -2
@@ -0,0 +1,225 @@
1
+ /**
2
+ * The probe's VIEW MODEL (model-profile-connection-test §3.2 / §6.3).
3
+ *
4
+ * Pure functions only: the editor's row list, the result sentences, the candidate
5
+ * ordering and the two number formatters. Rendering and input both read
6
+ * `editorRows()`, so "which row am I on" has exactly one definition and inserting a
7
+ * row can no longer shift `apiKey` off index 6 by arithmetic.
8
+ *
9
+ * ASCII ONLY (`ui/` is inside `glyphs.test.ts::inScope`).
10
+ */
11
+ import { PROBE_LIMITS } from '../../agent/model-probe-limits.js';
12
+ import { resolveDraftKey } from '../../agent/model-probe.js';
13
+ import { profileEndpointSummary } from './ModelProfilePicker.js';
14
+ export const EDITOR_FIELDS = ['name', 'provider', 'model', 'contextWindow', 'baseUrl',
15
+ 'credentialMode', 'apiKey'];
16
+ export const EDITOR_LABELS = ['Name', 'Provider', 'Model', 'Context window', 'Base URL',
17
+ 'Credential mode', 'API key'];
18
+ function idleView(hasKey) {
19
+ return { kind: 'idle', reason: hasKey ? 'no_result' : 'no_key' };
20
+ }
21
+ function hasKey(target) {
22
+ return Boolean(target.apiKey && target.apiKey.trim().length > 0);
23
+ }
24
+ /** Whether pressing a probe action can produce anything at all (AC-12 / AC-15). */
25
+ export function canProbe(view) {
26
+ return !(view.kind === 'idle' && (view.reason === 'no_key' || view.reason === 'unavailable'));
27
+ }
28
+ function testView(test, target, probe) {
29
+ if (!probe)
30
+ return { kind: 'idle', reason: 'unavailable' };
31
+ if (test.phase === 'testing') {
32
+ return test.targetId === probe.targetFingerprint(target)
33
+ ? { kind: 'testing' } : idleView(hasKey(target));
34
+ }
35
+ if (test.phase === 'tested') {
36
+ return test.outcome.targetId === probe.targetFingerprint(target)
37
+ ? { kind: 'result', outcome: test.outcome } : idleView(hasKey(target));
38
+ }
39
+ return idleView(hasKey(target));
40
+ }
41
+ function discoveryView(state, target, probe) {
42
+ if (!probe)
43
+ return { kind: 'idle' };
44
+ if (state.phase === 'discovering') {
45
+ return state.connectionId === probe.connectionFingerprint(target) ? { kind: 'discovering' }
46
+ : { kind: 'idle' };
47
+ }
48
+ if (state.phase === 'discovered') {
49
+ return state.outcome.connectionId === probe.connectionFingerprint(target)
50
+ ? { kind: 'discovery', outcome: state.outcome } : { kind: 'idle' };
51
+ }
52
+ return { kind: 'idle' };
53
+ }
54
+ /**
55
+ * Filter both slots down to what the CURRENT target may honestly claim (§4.6).
56
+ *
57
+ * A `OK 812 ms` that describes a model the user has since edited is worse than no
58
+ * result at all, so a fingerprint mismatch degrades to `idle` - no effect, no
59
+ * reset call, no cross-page synchronisation.
60
+ */
61
+ export function visibleProbeViews(test, discovery, target, probe) {
62
+ return { test: testView(test, target, probe), discovery: discoveryView(discovery, target, probe) };
63
+ }
64
+ /** The exact target a draft would use - the resolved key included (§4.2.1). */
65
+ export function editorProbeTarget(editor, apiKeys) {
66
+ return {
67
+ provider: editor.provider,
68
+ model: editor.model,
69
+ baseUrl: editor.baseUrl.trim().length > 0 ? editor.baseUrl.trim() : null,
70
+ apiKey: resolveDraftKey({ credentialMode: editor.credentialMode, draftKey: editor.apiKey,
71
+ existingKey: editor.original.apiKey, sharedKey: apiKeys[editor.provider] }),
72
+ };
73
+ }
74
+ /** `812 ms` / `1.4 s` - one decimal only once a second has passed. */
75
+ export function latencyLabel(ms) {
76
+ const safe = Number.isFinite(ms) && ms >= 0 ? ms : 0;
77
+ return safe < 1000 ? `${Math.round(safe)} ms` : `${(safe / 1000).toFixed(1)} s`;
78
+ }
79
+ /** `128K` / `1M` / `auto` - `auto` when the vendor did not report a window. */
80
+ export function windowLabel(window) {
81
+ if (!window || !Number.isFinite(window))
82
+ return 'auto';
83
+ if (window >= 1_000_000) {
84
+ const millions = window / 1_000_000;
85
+ return `${Number.isInteger(millions) ? millions : millions.toFixed(1)}M`;
86
+ }
87
+ if (window >= 1000)
88
+ return `${Math.round(window / 1000)}K`;
89
+ return String(Math.round(window));
90
+ }
91
+ /**
92
+ * Clean and order a discovered list: one row per id, and the model the draft
93
+ * already names first, so "which one am I on" is answerable without scrolling.
94
+ */
95
+ export function rankCandidates(models, currentModel) {
96
+ const seen = new Set();
97
+ const unique = [];
98
+ for (const model of models) {
99
+ if (model.id.length === 0 || seen.has(model.id))
100
+ continue;
101
+ seen.add(model.id);
102
+ unique.push(model);
103
+ }
104
+ const wanted = currentModel.trim().toLowerCase();
105
+ if (wanted.length === 0)
106
+ return unique;
107
+ const matches = (model) => model.id.toLowerCase() === wanted;
108
+ const prefixed = (model) => model.id.toLowerCase().startsWith(wanted);
109
+ return [...unique.filter(matches), ...unique.filter((model) => !matches(model) && prefixed(model)),
110
+ ...unique.filter((model) => !matches(model) && !prefixed(model))];
111
+ }
112
+ function usagePart(outcome) {
113
+ if (!outcome.usage)
114
+ return '';
115
+ return ` | ${outcome.usage.inputTokens} in / ${outcome.usage.outputTokens} out`;
116
+ }
117
+ function fixLine(outcome) {
118
+ if (outcome.kind === 'auth')
119
+ return 'Fix: edit API key, or set Credential mode to Shared.';
120
+ if (outcome.kind !== 'model_not_found')
121
+ return undefined;
122
+ const reach = outcome.availableModels;
123
+ return `Fix: choose Discover models.${reach === undefined ? ''
124
+ : ` This key can reach ${reach} models.`}`;
125
+ }
126
+ function resultLines(outcome, target) {
127
+ const name = `${target.provider}:${target.model.trim()}`;
128
+ if (outcome.ok) {
129
+ const head = `Last test: ${name} OK in ${latencyLabel(outcome.latencyMs)}${usagePart(outcome)}`;
130
+ const reply = outcome.reply ? `Reply: "${outcome.reply}"` : undefined;
131
+ const reach = outcome.reply || outcome.availableModels === undefined ? undefined
132
+ : `This key can reach ${outcome.availableModels} models.`;
133
+ const second = reply ?? reach;
134
+ return second ? [head, second] : [head];
135
+ }
136
+ const head = `Last test: FAILED - ${outcome.detail ?? 'The connection test failed.'}`;
137
+ const fix = fixLine(outcome);
138
+ return fix ? [head, fix] : [head];
139
+ }
140
+ /** At most TWO rows: the verdict, then what to do about it (§3.1 / D-11). */
141
+ export function probeLines(view, target) {
142
+ if (view.kind === 'result')
143
+ return resultLines(view.outcome, target).slice(0, 2);
144
+ if (view.kind === 'idle') {
145
+ if (view.reason === 'unavailable')
146
+ return ['Connection test is unavailable in this session.'];
147
+ if (view.reason === 'no_key')
148
+ return ['No key yet: set API key, or use Credential mode Shared.'];
149
+ return ['Not tested for this profile yet.'];
150
+ }
151
+ return [];
152
+ }
153
+ /** Colour for the result rows; the status WORDS carry the meaning without colour. */
154
+ export function probeTone(view) {
155
+ if (view.kind !== 'result')
156
+ return 'muted';
157
+ return view.outcome.ok ? 'ok' : 'fail';
158
+ }
159
+ function fieldValue(editor, field) {
160
+ if (field === 'apiKey') {
161
+ if (editor.credentialMode === 'replace') {
162
+ return editor.apiKey ? 'Configured (replacement)' : '(type replacement)';
163
+ }
164
+ return editor.credentialMode === 'keep' ? 'Configured (unchanged)' : 'Shared / environment';
165
+ }
166
+ if (field === 'credentialMode')
167
+ return editor.credentialMode;
168
+ return editor[field] || (field === 'name' ? '(defaults to model)'
169
+ : field === 'contextWindow' ? '(auto)' : field === 'baseUrl'
170
+ ? '(provider default)' : '(required)');
171
+ }
172
+ function actionValue(action, view) {
173
+ if (action === 'retain' || action === 'apply' || action === 'cancel')
174
+ return '';
175
+ if (view.kind === 'idle' && view.reason === 'unavailable')
176
+ return '(unavailable)';
177
+ if (view.kind === 'idle' && view.reason === 'no_key')
178
+ return '(no key)';
179
+ if (action === 'test' && view.kind === 'testing')
180
+ return 'testing...';
181
+ return action === 'test' ? 'Enter or Ctrl+R' : 'Enter or Ctrl+F';
182
+ }
183
+ function actionRow(action, label, view) {
184
+ return { kind: 'action', action, label, value: actionValue(action, view) };
185
+ }
186
+ /** THE single source of the editor's rows - fields, actions, notes AND results. */
187
+ export function editorRows(input) {
188
+ const { editor, retain, probe, target } = input;
189
+ const rows = EDITOR_FIELDS.map((field, at) => ({ kind: 'field', field,
190
+ label: EDITOR_LABELS[at], value: fieldValue(editor, field) }));
191
+ if (retain)
192
+ rows.push(actionRow('retain', 'Retain key for new endpoint', probe));
193
+ rows.push(actionRow('test', 'Test connection', probe), actionRow('discover', 'Discover models', probe), actionRow('apply', 'Apply to settings draft', probe), actionRow('cancel', 'Cancel editing', probe));
194
+ rows.push({ kind: 'note', muted: true,
195
+ label: `Target: ${editor.provider} ${profileEndpointSummary(editor.baseUrl)}` });
196
+ if (input.fastOnly) {
197
+ rows.push({ kind: 'note', muted: true,
198
+ label: 'Window applies when this profile is bound as Main.' });
199
+ }
200
+ const tone = probeTone(probe);
201
+ for (const line of probeLines(probe, target)) {
202
+ rows.push({ kind: 'result', label: line, tone });
203
+ }
204
+ return rows;
205
+ }
206
+ /** Rows the cursor can land on; index arithmetic now derives from the row model. */
207
+ export function isFocusable(row) {
208
+ return row.kind === 'field' || row.kind === 'action';
209
+ }
210
+ /** The focusable rows, in order - the index space `useProfileScroll` follows. */
211
+ export function focusableRows(rows) {
212
+ return rows.filter(isFocusable);
213
+ }
214
+ /** Result rows currently on screen, so the viewport can be widened to include them. */
215
+ export function resultRowCount(rows) {
216
+ return rows.filter((row) => row.kind === 'result').length;
217
+ }
218
+ /** Longest id shown in one list row, inside the 40-column budget. */
219
+ export const LIST_ID_CHARS = 28;
220
+ /** A model's one-line name, bounded by `maxNameChars`. */
221
+ export function clipName(name) {
222
+ const points = [...name];
223
+ return points.length <= PROBE_LIMITS.maxNameChars ? name
224
+ : `${points.slice(0, PROBE_LIMITS.maxNameChars - 3).join('')}...`;
225
+ }
@@ -1,7 +1,7 @@
1
1
  import { type ModelProfile, type ModelProfilesConfig, type ModelRole } from '../../config/model-profiles.js';
2
2
  import type { ModelSettingsDraft } from '../../config/model-profile-store.js';
3
3
  import type { SubagentModelMode } from '../../team/model.js';
4
- export type ProfilePage = 'root' | 'picker' | 'manager' | 'editor' | 'delete-confirm' | 'discard-confirm';
4
+ export type ProfilePage = 'root' | 'picker' | 'manager' | 'editor' | 'models' | 'delete-confirm' | 'discard-confirm';
5
5
  /**
6
6
  * Which role a PROFILE PICKER page is choosing for.
7
7
  *
@@ -60,6 +60,14 @@ export type ModelProfileAction = {
60
60
  type: 'merge-editor';
61
61
  } | {
62
62
  type: 'cancel-editor';
63
+ }
64
+ /**
65
+ * The ONE write path for a discovered model (§6.3 / D-2 / D-3): only `model`
66
+ * changes - never the credential, never the context window, never the draft.
67
+ */
68
+ | {
69
+ type: 'choose-model';
70
+ model: string;
63
71
  } | {
64
72
  type: 'duplicate';
65
73
  id: string;
@@ -168,6 +168,16 @@ export function modelProfileReducer(state, action) {
168
168
  case 'retain-key': return state.editor?.original.apiKey ? { ...state,
169
169
  editor: { ...state.editor, credentialMode: 'keep', apiKey: '' } } : state;
170
170
  case 'merge-editor': return mergeEditor(state);
171
+ case 'choose-model': {
172
+ // Legal ONLY from the list page (§7). `editor-field` would do the same thing,
173
+ // but routing the list page through the generic field action would also let a
174
+ // future `editField` side effect (key reset, endpoint flag) fire on a choice
175
+ // that never touched the endpoint.
176
+ if (!state.editor || state.page !== 'models')
177
+ return state;
178
+ return { ...state, page: 'editor', error: undefined,
179
+ editor: { ...state.editor, model: action.model } };
180
+ }
171
181
  case 'cancel-editor': return { ...state, editor: undefined, page: state.returnPage,
172
182
  error: undefined };
173
183
  case 'duplicate': {
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The probe task hook (model-profile-connection-test §6.2).
3
+ *
4
+ * IT LIVES IN `SettingsScreen`, ONCE, AND NOWHERE ELSE. The editor unmounts whenever
5
+ * the page changes (`SettingsScreen` renders it only for `page === 'editor'`), so a
6
+ * hook inside the editor would abort its own discovery the moment `Discover models`
7
+ * switched to the list page - the feature cancelling itself.
8
+ *
9
+ * TWO SLOTS, ONE IN FLIGHT. A test verdict and a discovered list answer different
10
+ * questions, so they are stored separately: opening the list must not erase a verdict
11
+ * the user still wants to read when they press Esc back (AC-27). Starting either task
12
+ * aborts whatever is running - one request at a time.
13
+ *
14
+ * `test()` AND `discover()` NEVER REJECT. The only callers are Ink input handlers,
15
+ * which have nowhere to await a `catch`; the hook folds every exception into an
16
+ * `unknown` failure so no frame can be left on `testing` forever.
17
+ *
18
+ * ASCII ONLY (`ui/` is inside `glyphs.test.ts::inScope`).
19
+ */
20
+ import type { ModelProbe, ProbeTarget } from '../../agent/model-probe.js';
21
+ import type { ProbeDiscoveryPhase, ProbeTestPhase } from './model-probe-view.js';
22
+ export interface ModelProbeTasks {
23
+ test: ProbeTestPhase;
24
+ discovery: ProbeDiscoveryPhase;
25
+ busy: boolean;
26
+ startTest(target: ProbeTarget): void;
27
+ startDiscovery(target: ProbeTarget): void;
28
+ cancel(): void;
29
+ }
30
+ export declare function useModelProbe(probe?: ModelProbe): ModelProbeTasks;
@@ -0,0 +1,109 @@
1
+ /**
2
+ * The probe task hook (model-profile-connection-test §6.2).
3
+ *
4
+ * IT LIVES IN `SettingsScreen`, ONCE, AND NOWHERE ELSE. The editor unmounts whenever
5
+ * the page changes (`SettingsScreen` renders it only for `page === 'editor'`), so a
6
+ * hook inside the editor would abort its own discovery the moment `Discover models`
7
+ * switched to the list page - the feature cancelling itself.
8
+ *
9
+ * TWO SLOTS, ONE IN FLIGHT. A test verdict and a discovered list answer different
10
+ * questions, so they are stored separately: opening the list must not erase a verdict
11
+ * the user still wants to read when they press Esc back (AC-27). Starting either task
12
+ * aborts whatever is running - one request at a time.
13
+ *
14
+ * `test()` AND `discover()` NEVER REJECT. The only callers are Ink input handlers,
15
+ * which have nowhere to await a `catch`; the hook folds every exception into an
16
+ * `unknown` failure so no frame can be left on `testing` forever.
17
+ *
18
+ * ASCII ONLY (`ui/` is inside `glyphs.test.ts::inScope`).
19
+ */
20
+ import { useCallback, useEffect, useRef, useState } from 'react';
21
+ const TEST_FAILED_DETAIL = 'The connection test could not run.';
22
+ const DISCOVERY_FAILED_DETAIL = 'The model list could not be fetched.';
23
+ function unknownTest(targetId) {
24
+ return { ok: false, targetId, latencyMs: 0, kind: 'unknown', detail: TEST_FAILED_DETAIL };
25
+ }
26
+ function unknownDiscovery(connectionId) {
27
+ return { ok: false, connectionId, kind: 'unknown', detail: DISCOVERY_FAILED_DETAIL,
28
+ models: [], truncated: false, total: 0 };
29
+ }
30
+ /** Run one probe, guaranteeing the promise settles and no rejection escapes. */
31
+ function settle(work, onValue, onFailure) {
32
+ let pending;
33
+ try {
34
+ pending = work();
35
+ }
36
+ catch {
37
+ onFailure();
38
+ return;
39
+ }
40
+ void pending.then(onValue, onFailure);
41
+ }
42
+ export function useModelProbe(probe) {
43
+ const [test, setTest] = useState({ phase: 'idle' });
44
+ const [discovery, setDiscovery] = useState({ phase: 'idle' });
45
+ const controller = useRef(null);
46
+ const inFlight = useRef(null);
47
+ const abortCurrent = useCallback(() => {
48
+ controller.current?.abort();
49
+ controller.current = null;
50
+ inFlight.current = null;
51
+ }, []);
52
+ useEffect(() => abortCurrent, [abortCurrent]);
53
+ const begin = useCallback((kind) => {
54
+ abortCurrent();
55
+ const next = new AbortController();
56
+ controller.current = next;
57
+ inFlight.current = kind;
58
+ return next;
59
+ }, [abortCurrent]);
60
+ /**
61
+ * Land one run's result and drop the in-flight refs with it.
62
+ *
63
+ * Clearing them here is what keeps `cancel()` honest: it is the ONLY caller of
64
+ * `abortCurrent`, and an Escape on a settled slot (a frame where `busy` is stale)
65
+ * must not erase a verdict the user is still reading.
66
+ */
67
+ const finish = useCallback((run, commit) => {
68
+ if (run.signal.aborted)
69
+ return;
70
+ controller.current = null;
71
+ inFlight.current = null;
72
+ commit();
73
+ }, []);
74
+ const startTest = useCallback((target) => {
75
+ if (!probe)
76
+ return;
77
+ const run = begin('test');
78
+ const targetId = probe.targetFingerprint(target);
79
+ setTest({ phase: 'testing', targetId });
80
+ settle(() => probe.test({ ...target, signal: run.signal }), (outcome) => {
81
+ finish(run, () => setTest({ phase: 'tested', outcome }));
82
+ }, () => {
83
+ finish(run, () => setTest({ phase: 'tested', outcome: unknownTest(targetId) }));
84
+ });
85
+ }, [probe, begin, finish]);
86
+ const startDiscovery = useCallback((target) => {
87
+ if (!probe)
88
+ return;
89
+ const run = begin('discovery');
90
+ const connectionId = probe.connectionFingerprint(target);
91
+ setDiscovery({ phase: 'discovering', connectionId });
92
+ settle(() => probe.discover({ ...target, signal: run.signal }), (outcome) => {
93
+ finish(run, () => setDiscovery({ phase: 'discovered', outcome }));
94
+ }, () => {
95
+ finish(run, () => setDiscovery({ phase: 'discovered',
96
+ outcome: unknownDiscovery(connectionId) }));
97
+ });
98
+ }, [probe, begin, finish]);
99
+ const cancel = useCallback(() => {
100
+ const kind = inFlight.current;
101
+ abortCurrent();
102
+ if (kind === 'test')
103
+ setTest({ phase: 'idle' });
104
+ if (kind === 'discovery')
105
+ setDiscovery({ phase: 'idle' });
106
+ }, [abortCurrent]);
107
+ const busy = test.phase === 'testing' || discovery.phase === 'discovering';
108
+ return { test, discovery, busy, startTest, startDiscovery, cancel };
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aragon-agent/cli",
3
- "version": "0.6.24",
3
+ "version": "0.6.25",
4
4
  "description": "AragonAgent CLI — a Claude-Code / Codex-style interactive terminal UI (TUI) on top of the @aragon-agent/core engine. Installable and runnable via npm / npx.",
5
5
  "license": "MIT",
6
6
  "author": "AragonAgent contributors",
@@ -56,7 +56,7 @@
56
56
  "prepublishOnly": "npm run build"
57
57
  },
58
58
  "dependencies": {
59
- "@aragon-agent/core": "^0.2.36",
59
+ "@aragon-agent/core": "^0.2.37",
60
60
  "chalk": "^5.6.2",
61
61
  "cli-highlight": "^2.0.0",
62
62
  "commander": "^12.1.0",