somora 2026.1004.4 → 2026.1007.2
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 +27 -23
- package/config.example.yaml +27 -0
- package/docs/api.md +57 -9
- package/docs/cache-strategy.md +24 -5
- package/docs/compaction.md +45 -0
- package/docs/display.md +14 -6
- package/docs/files.md +54 -12
- package/docs/imagegen.md +10 -1
- package/docs/memory.md +28 -0
- package/docs/mobile.md +29 -1
- package/docs/models.md +44 -4
- package/docs/resources.md +22 -0
- package/docs/setup.md +35 -3
- package/docs/thinking.md +37 -9
- package/docs/web.md +14 -5
- package/package.json +2 -1
- package/src/attachments/store.ts +19 -1
- package/src/browser/session.ts +2 -2
- package/src/cli/auth.ts +22 -0
- package/src/cli/claude-bin.ts +48 -0
- package/src/cli/config.ts +47 -0
- package/src/cli/setup.ts +11 -7
- package/src/cli/somora.ts +6 -1
- package/src/cli/tui/api.ts +44 -2
- package/src/cli/tui/app.tsx +62 -8
- package/src/cli/tui/commands.ts +109 -12
- package/src/cli/tui/header.tsx +20 -0
- package/src/cli/tui/stream.ts +2 -0
- package/src/cli/tui/types.ts +10 -1
- package/src/compaction/summarize.ts +4 -0
- package/src/compaction/template.ts +15 -0
- package/src/compaction/types.ts +3 -0
- package/src/config/loader.ts +75 -10
- package/src/config/types.ts +40 -7
- package/src/engine/a2a.ts +1 -1
- package/src/engine/claude-cli.ts +136 -4
- package/src/engine/codex-cli.ts +74 -0
- package/src/engine/engine-meta-labels.ts +2 -0
- package/src/engine/openai-compatible.ts +142 -29
- package/src/engine/types.ts +7 -0
- package/src/imagegen/generate.ts +30 -5
- package/src/imagegen/types.ts +6 -0
- package/src/media/capabilities.ts +8 -0
- package/src/memory/inject.ts +66 -7
- package/src/multimodal/blocks.ts +14 -0
- package/src/multimodal/load.ts +21 -2
- package/src/multimodal/model-image.ts +127 -0
- package/src/server/index.ts +118 -39
- package/src/server/run-turn.ts +65 -16
- package/src/server/session-compact.ts +138 -0
- package/src/server/thinking-resolve.ts +30 -0
- package/src/ssh/exec.ts +55 -22
- package/src/storage/sessions.ts +40 -15
- package/src/tools/exec/tools.ts +3 -0
- package/src/tools/file/analyze.ts +46 -7
- package/src/tools/file/remote.ts +31 -10
- package/src/tools/file/tools.ts +86 -19
- package/src/tools/image/tools.ts +6 -0
- package/src/tools/registry.ts +14 -0
- package/src/types/events.ts +23 -2
- package/web/dist/assets/{index-Cl1xtY5g.js → index-40x__Izy.js} +96 -96
- package/web/dist/assets/index-40x__Izy.js.map +1 -0
- package/web/dist/assets/index-CZFgQRsq.css +32 -0
- package/web/dist/index.html +2 -2
- package/web-mobile/dist/assets/index-CxILeHfe.js +88 -0
- package/web-mobile/dist/assets/{index-BpsX8_mX.js.map → index-CxILeHfe.js.map} +1 -1
- package/web-mobile/dist/assets/{index-DZXivrMo.css → index-Cyr13VGR.css} +1 -1
- package/web-mobile/dist/index.html +2 -2
- package/web/dist/assets/index-Cl1xtY5g.js.map +0 -1
- package/web/dist/assets/index-D0q6NZer.css +0 -32
- package/web-mobile/dist/assets/index-BpsX8_mX.js +0 -88
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// `somora config check [file]` — validate config.yaml exactly as the
|
|
2
|
+
// server does (YAML, schema, unique aliases) without starting anything.
|
|
3
|
+
// An agent that edits the file runs it before relying on the change.
|
|
4
|
+
import { readFileSync } from 'node:fs';
|
|
5
|
+
import { resolve } from 'node:path';
|
|
6
|
+
import { configPath, validateConfigText } from '../config/loader.ts';
|
|
7
|
+
|
|
8
|
+
function usage(): string {
|
|
9
|
+
return `somora config — the server configuration (~/.somora/config.yaml)
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
somora config check [file] validate the file exactly as the server does;
|
|
13
|
+
exit code 0 = valid, 1 = invalid, 2 = unreadable
|
|
14
|
+
somora config path print the path of the config file
|
|
15
|
+
`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function checkConfigFile(file: string): { code: number; out: string } {
|
|
19
|
+
let raw: string;
|
|
20
|
+
try {
|
|
21
|
+
raw = readFileSync(file, 'utf8');
|
|
22
|
+
} catch (err) {
|
|
23
|
+
return { code: 2, out: `cannot read ${file}: ${(err as Error).message}\n` };
|
|
24
|
+
}
|
|
25
|
+
const r = validateConfigText(raw);
|
|
26
|
+
if (r.ok) return { code: 0, out: `${file}: valid\n` };
|
|
27
|
+
return {
|
|
28
|
+
code: 1,
|
|
29
|
+
out: `${file}: invalid — ${r.issues.length} problem(s)\n${r.issues.map((i) => ` - ${i.path}: ${i.message}`).join('\n')}\n`,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function runConfigCli(args: string[]): Promise<number> {
|
|
34
|
+
const sub = args[0];
|
|
35
|
+
if (sub === 'check') {
|
|
36
|
+
const file = args[1] ? resolve(args[1]) : configPath();
|
|
37
|
+
const r = checkConfigFile(file);
|
|
38
|
+
(r.code === 0 ? process.stdout : process.stderr).write(r.out);
|
|
39
|
+
return r.code;
|
|
40
|
+
}
|
|
41
|
+
if (sub === 'path') {
|
|
42
|
+
process.stdout.write(`${configPath()}\n`);
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
process.stdout.write(usage());
|
|
46
|
+
return sub && sub !== '--help' && sub !== '-h' ? 2 : 0;
|
|
47
|
+
}
|
package/src/cli/setup.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
import { isOperatorError, tailscaleState } from '../setup/tailscale.ts';
|
|
31
31
|
import { SOMORA_VERSION } from '../version.ts';
|
|
32
32
|
import { launchdPlistPath } from './launchd.ts';
|
|
33
|
+
import { bundledClaudeBinary, claudeBinaryForLogin } from './claude-bin.ts';
|
|
33
34
|
import { isUtf8Locale, renderBanner } from './banner.ts';
|
|
34
35
|
|
|
35
36
|
const HOME = homedir();
|
|
@@ -195,11 +196,10 @@ export function addToShellPath(dir: string, home: string = HOME, envPath: string
|
|
|
195
196
|
return changed;
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
// The person's own Claude Code when installed, else the one bundled
|
|
200
|
+
// with somora (see claude-bin.ts). Either can run the login.
|
|
198
201
|
function claudeBinary(): string | null {
|
|
199
|
-
|
|
200
|
-
if (existsSync(local)) return local;
|
|
201
|
-
const r = capture('sh', ['-c', 'command -v claude']);
|
|
202
|
-
return r.code === 0 ? r.stdout.trim() : null;
|
|
202
|
+
return claudeBinaryForLogin()?.path ?? null;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
function claudeLoggedIn(): boolean {
|
|
@@ -225,8 +225,12 @@ async function pickModels(p: Prompter, title: string, models: ModelPreset[], hav
|
|
|
225
225
|
async function setupClaude(ctx: Ctx, config: YamlFile): Promise<void> {
|
|
226
226
|
const { p } = ctx;
|
|
227
227
|
let bin = claudeBinary();
|
|
228
|
+
if (bin && bin === bundledClaudeBinary()) {
|
|
229
|
+
ok('Claude Code comes bundled with somora — nothing to install');
|
|
230
|
+
}
|
|
228
231
|
if (!bin) {
|
|
229
|
-
|
|
232
|
+
// Only when the bundled binary is missing (an incomplete install).
|
|
233
|
+
explain('Claude runs through Anthropic\'s own program, Claude Code. The copy bundled with somora is missing.');
|
|
230
234
|
if (await p.confirm('Install Claude Code now? (official installer from claude.ai, into ~/.local/bin)')) {
|
|
231
235
|
p.handOver('sh', ['-c', 'curl -fsSL https://claude.ai/install.sh | bash']);
|
|
232
236
|
bin = claudeBinary();
|
|
@@ -252,7 +256,7 @@ async function setupClaude(ctx: Ctx, config: YamlFile): Promise<void> {
|
|
|
252
256
|
p.handOver(bin, ['auth', 'login']);
|
|
253
257
|
}
|
|
254
258
|
if (!claudeLoggedIn()) {
|
|
255
|
-
warn(
|
|
259
|
+
warn('no login yet — the models are added anyway; log in later with: somora auth login');
|
|
256
260
|
} else {
|
|
257
261
|
ok('logged in');
|
|
258
262
|
}
|
|
@@ -396,7 +400,7 @@ async function stepModels(ctx: Ctx): Promise<void> {
|
|
|
396
400
|
}
|
|
397
401
|
const engines = new Set(before.map((a) => a.engine));
|
|
398
402
|
const choices: Array<Choice<'claude' | 'codex' | 'own'>> = [
|
|
399
|
-
{ label: 'Claude subscription (Pro / Max)', value: 'claude', hint: claudeLoggedIn() ? 'login found on this machine' :
|
|
403
|
+
{ label: 'Claude subscription (Pro / Max)', value: 'claude', hint: claudeLoggedIn() ? 'login found on this machine' : 'log in with your subscription' },
|
|
400
404
|
{ label: 'ChatGPT subscription (Plus / Pro / Business)', value: 'codex', hint: codexLoggedIn() ? 'login found on this machine' : 'Codex is bundled' },
|
|
401
405
|
{ label: 'My own model server or an API key', value: 'own', hint: 'Ollama, LM Studio, vLLM, OpenRouter, …' },
|
|
402
406
|
];
|
package/src/cli/somora.ts
CHANGED
|
@@ -73,7 +73,7 @@ Usage:
|
|
|
73
73
|
somora tui launch the TUI against the running server
|
|
74
74
|
somora skill <subcommand> list/check/add/update/remove skills
|
|
75
75
|
(run \`somora skill\` for sub-help)
|
|
76
|
-
somora auth status|sync
|
|
76
|
+
somora auth login|status|sync Claude subscription login (bundled Claude Code) / inspect / reconcile
|
|
77
77
|
the two credential stores
|
|
78
78
|
somora codex [args...] run the bundled Codex CLI (e.g. \`somora codex login\`,
|
|
79
79
|
\`somora codex debug models\`); somora mirrors the login
|
|
@@ -83,6 +83,7 @@ Usage:
|
|
|
83
83
|
what is installed, install with npm into ~/.somora/lsp
|
|
84
84
|
somora wiki migrate [step] [id] move a grown wiki onto the folder template (docs/wiki.md):
|
|
85
85
|
guided, or plan|judge|status|approve|dry-run|run|undo
|
|
86
|
+
somora config check [file] validate config.yaml exactly as the server does
|
|
86
87
|
somora telemetry show what the daily update check sends to somora.ai, and when
|
|
87
88
|
somora update [<version>|--edge] install from npm + rebake systemd + restart
|
|
88
89
|
(run \`somora update --help\` for options)
|
|
@@ -720,6 +721,10 @@ async function main(): Promise<number> {
|
|
|
720
721
|
const { runSetupCli } = await import('./setup.ts');
|
|
721
722
|
return await runSetupCli(rest);
|
|
722
723
|
}
|
|
724
|
+
case 'config': {
|
|
725
|
+
const { runConfigCli } = await import('./config.ts');
|
|
726
|
+
return await runConfigCli(rest);
|
|
727
|
+
}
|
|
723
728
|
case 'wiki': {
|
|
724
729
|
const { runWikiCli } = await import('./wiki.ts');
|
|
725
730
|
return await runWikiCli(rest);
|
package/src/cli/tui/api.ts
CHANGED
|
@@ -69,12 +69,41 @@ export class Api {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
async fetchSessions(agent: string): Promise<SessionSummary[]> {
|
|
73
|
-
const
|
|
72
|
+
async fetchSessions(agent: string, opts: { includeArchived?: boolean } = {}): Promise<SessionSummary[]> {
|
|
73
|
+
const query = opts.includeArchived ? '?include_archived=true' : '';
|
|
74
|
+
const res = await loopbackFetch(`${this.base}/agents/${encodeURIComponent(agent)}/sessions${query}`);
|
|
74
75
|
if (!res.ok) return [];
|
|
75
76
|
return (await res.json()) as SessionSummary[];
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
/** Compact the session by hand. Resolves with the server's outcome;
|
|
80
|
+
* a running turn answers 409 with `busy: true`. */
|
|
81
|
+
async compactSession(
|
|
82
|
+
agent: string,
|
|
83
|
+
session: string,
|
|
84
|
+
instructions?: string,
|
|
85
|
+
): Promise<{ status: string; engine?: string; note?: string; tokensBefore?: number; tokensAfter?: number; error?: string; busy?: boolean }> {
|
|
86
|
+
const res = await loopbackFetch(
|
|
87
|
+
`${this.base}/agents/${encodeURIComponent(agent)}/sessions/${encodeURIComponent(session)}/compact`,
|
|
88
|
+
{ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(instructions ? { instructions } : {}) },
|
|
89
|
+
);
|
|
90
|
+
const body = (await res.json().catch(() => ({}))) as Record<string, unknown>;
|
|
91
|
+
if (!res.ok && typeof body.error === 'string') return { status: 'error', error: body.error, ...(body.busy === true ? { busy: true } : {}) };
|
|
92
|
+
return body as { status: string };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Bring an archived session back. Returns the name it is listed
|
|
96
|
+
* under now (a reset archive comes back as `<name>-archive`). */
|
|
97
|
+
async unarchiveSession(agent: string, session: string): Promise<{ session: string; slug: string }> {
|
|
98
|
+
const res = await loopbackFetch(
|
|
99
|
+
`${this.base}/agents/${encodeURIComponent(agent)}/sessions/${encodeURIComponent(session)}/unarchive`,
|
|
100
|
+
{ method: 'POST' },
|
|
101
|
+
);
|
|
102
|
+
const body = (await res.json().catch(() => ({}))) as { session?: string; slug?: string; error?: string };
|
|
103
|
+
if (!res.ok || !body.session) throw new Error(body.error ?? `unarchive failed (HTTP ${res.status})`);
|
|
104
|
+
return { session: body.session, slug: body.slug ?? body.session };
|
|
105
|
+
}
|
|
106
|
+
|
|
78
107
|
async createSession(agent: string, slug: string): Promise<string> {
|
|
79
108
|
const res = await loopbackFetch(`${this.base}/agents/${encodeURIComponent(agent)}/sessions`, {
|
|
80
109
|
method: 'POST',
|
|
@@ -99,6 +128,19 @@ export class Api {
|
|
|
99
128
|
return (await res.json()) as ResetResult;
|
|
100
129
|
}
|
|
101
130
|
|
|
131
|
+
/** The server's view of config.yaml; `invalid` is set while the file
|
|
132
|
+
* does not validate and the last valid version keeps running. */
|
|
133
|
+
async fetchConfigProblem(): Promise<{ since: string; message: string } | null> {
|
|
134
|
+
try {
|
|
135
|
+
const res = await loopbackFetch(`${this.base}/config/status`);
|
|
136
|
+
if (!res.ok) return null;
|
|
137
|
+
const body = (await res.json()) as { invalid?: { since: string; message: string } | null };
|
|
138
|
+
return body.invalid ?? null;
|
|
139
|
+
} catch {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
102
144
|
async fetchModels(): Promise<ModelInfo[]> {
|
|
103
145
|
const res = await loopbackFetch(`${this.base}/models`);
|
|
104
146
|
if (!res.ok) return [];
|
package/src/cli/tui/app.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import { openStream, type StreamHandle } from './stream.ts';
|
|
|
7
7
|
import { openActivityStream } from './activity-stream.ts';
|
|
8
8
|
import { matchCommands, runCommand } from './commands.ts';
|
|
9
9
|
import { Header } from './header.tsx';
|
|
10
|
+
import { resolveEngineMetaLabel, summariseEngineMeta } from '../../engine/engine-meta-labels.ts';
|
|
10
11
|
import { Footer } from './footer.tsx';
|
|
11
12
|
import { Separator } from './separator.tsx';
|
|
12
13
|
import { SlashAutocomplete } from './autocomplete.tsx';
|
|
@@ -88,6 +89,20 @@ export function App({
|
|
|
88
89
|
const [streaming, setStreaming] = useState(false);
|
|
89
90
|
const [connected, setConnected] = useState(false);
|
|
90
91
|
const [stats, setStats] = useState<TurnStats | null>(null);
|
|
92
|
+
// The model the session's next turn uses. `stats.model` is the last
|
|
93
|
+
// turn's; a switch from another client or an agent shows up here at
|
|
94
|
+
// once (session_model event), not only after the next turn.
|
|
95
|
+
const [nextModel, setNextModel] = useState<{ label: string; modelId: string } | null>(null);
|
|
96
|
+
const refreshNextModel = (a: string, s: string): void => {
|
|
97
|
+
apiRef.current
|
|
98
|
+
.fetchSessionModel(a, s)
|
|
99
|
+
.then((info) => {
|
|
100
|
+
if (info) setNextModel({ label: info.alias ?? info.modelId, modelId: info.modelId });
|
|
101
|
+
})
|
|
102
|
+
.catch(() => {
|
|
103
|
+
/* keep the previous value */
|
|
104
|
+
});
|
|
105
|
+
};
|
|
91
106
|
const [input, setInput] = useState('');
|
|
92
107
|
const [busy, setBusy] = useState(false);
|
|
93
108
|
const [agentIcons, setAgentIcons] = useState<Record<string, string>>({});
|
|
@@ -365,6 +380,8 @@ export function App({
|
|
|
365
380
|
let cancelled = false;
|
|
366
381
|
setTurns([]);
|
|
367
382
|
setStats(null);
|
|
383
|
+
setNextModel(null);
|
|
384
|
+
refreshNextModel(agent, session);
|
|
368
385
|
setPendingQueued([]);
|
|
369
386
|
pendingQueuedBufferRef.current.clear();
|
|
370
387
|
setWork(null);
|
|
@@ -525,13 +542,11 @@ export function App({
|
|
|
525
542
|
typeof ev.engine === 'string' &&
|
|
526
543
|
typeof ev.itemType === 'string'
|
|
527
544
|
) {
|
|
528
|
-
//
|
|
529
|
-
//
|
|
530
|
-
//
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
};
|
|
534
|
-
const label = knownLabels[ev.engine]?.[ev.itemType] ?? ev.itemType;
|
|
545
|
+
// The same label and one-liner the server puts on the live
|
|
546
|
+
// event (pure formatting, no server state), so a row reads the
|
|
547
|
+
// same after a reload as it did when it arrived.
|
|
548
|
+
const label = resolveEngineMetaLabel(ev.engine, ev.itemType);
|
|
549
|
+
const summary = summariseEngineMeta(ev.engine, ev.itemType, ev.payload);
|
|
535
550
|
let details: string | undefined;
|
|
536
551
|
try {
|
|
537
552
|
details = JSON.stringify(ev.payload, null, 2);
|
|
@@ -544,6 +559,7 @@ export function App({
|
|
|
544
559
|
engine: ev.engine,
|
|
545
560
|
itemType: ev.itemType,
|
|
546
561
|
label,
|
|
562
|
+
...(summary ? { summary } : {}),
|
|
547
563
|
...(details ? { details } : {}),
|
|
548
564
|
});
|
|
549
565
|
}
|
|
@@ -562,6 +578,38 @@ export function App({
|
|
|
562
578
|
}
|
|
563
579
|
}
|
|
564
580
|
|
|
581
|
+
// A broken config.yaml: say so once per broken version (the server
|
|
582
|
+
// keeps the last valid one, so an edit silently does nothing).
|
|
583
|
+
const configProblemShownRef = useRef<string | null>(null);
|
|
584
|
+
useEffect(() => {
|
|
585
|
+
let alive = true;
|
|
586
|
+
const check = async () => {
|
|
587
|
+
const problem = await apiRef.current.fetchConfigProblem();
|
|
588
|
+
if (!alive) return;
|
|
589
|
+
if (!problem) {
|
|
590
|
+
configProblemShownRef.current = null;
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (configProblemShownRef.current === problem.since) return;
|
|
594
|
+
configProblemShownRef.current = problem.since;
|
|
595
|
+
appendTurn({
|
|
596
|
+
kind: 'system',
|
|
597
|
+
id: nextId(),
|
|
598
|
+
tone: 'error',
|
|
599
|
+
text:
|
|
600
|
+
'config.yaml does not validate — somora keeps running on the last valid version. Fix it (somora config check):\n' +
|
|
601
|
+
problem.message.replace(/^config\.yaml is invalid \([^)]*\):\n/, ''),
|
|
602
|
+
});
|
|
603
|
+
};
|
|
604
|
+
void check();
|
|
605
|
+
const t = setInterval(() => void check(), 60_000);
|
|
606
|
+
return () => {
|
|
607
|
+
alive = false;
|
|
608
|
+
clearInterval(t);
|
|
609
|
+
};
|
|
610
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
611
|
+
}, []);
|
|
612
|
+
|
|
565
613
|
function appendTurn(t: Turn): void {
|
|
566
614
|
setTurns((prev) => [...prev, t]);
|
|
567
615
|
}
|
|
@@ -571,6 +619,9 @@ export function App({
|
|
|
571
619
|
case 'connected':
|
|
572
620
|
setConnected(true);
|
|
573
621
|
return;
|
|
622
|
+
case 'session-model':
|
|
623
|
+
refreshNextModel(agent, session);
|
|
624
|
+
return;
|
|
574
625
|
case 'agent-start':
|
|
575
626
|
refreshWork(agent, session);
|
|
576
627
|
setStreaming(true);
|
|
@@ -717,7 +768,9 @@ export function App({
|
|
|
717
768
|
return;
|
|
718
769
|
}
|
|
719
770
|
case 'engine_meta': {
|
|
720
|
-
|
|
771
|
+
// somora's own notes (model switched, compacted by hand) are for
|
|
772
|
+
// the reader, not engine internals: shown with tools hidden too.
|
|
773
|
+
if (!showToolsRef.current && ev.engine !== 'somora') return;
|
|
721
774
|
let details: string | undefined;
|
|
722
775
|
try {
|
|
723
776
|
details = JSON.stringify(ev.payload, null, 2);
|
|
@@ -1167,6 +1220,7 @@ export function App({
|
|
|
1167
1220
|
project={project}
|
|
1168
1221
|
unreadOtherAgents={unreadOtherAgents}
|
|
1169
1222
|
workCounters={formatWorkCounters(work)}
|
|
1223
|
+
nextModel={nextModel}
|
|
1170
1224
|
/>
|
|
1171
1225
|
<SlashAutocomplete matches={slashMatches} selectedIndex={safeAutocompleteIndex} />
|
|
1172
1226
|
<Box>
|
package/src/cli/tui/commands.ts
CHANGED
|
@@ -48,11 +48,13 @@ export const COMMANDS: readonly CommandMeta[] = [
|
|
|
48
48
|
{ name: '/help', usage: '/help' },
|
|
49
49
|
{ name: '/agents', usage: '/agents' },
|
|
50
50
|
{ name: '/agent', usage: '/agent <name> [session]' },
|
|
51
|
-
{ name: '/sessions', usage: '/sessions' },
|
|
51
|
+
{ name: '/sessions', usage: '/sessions [archived]' },
|
|
52
52
|
{ name: '/session', usage: '/session <slug-or-id>' },
|
|
53
|
+
{ name: '/unarchive', usage: '/unarchive <slug-or-id>' },
|
|
53
54
|
{ name: '/new', usage: '/new <slug>' },
|
|
54
55
|
{ name: '/main', usage: '/main' },
|
|
55
56
|
{ name: '/reset', usage: '/reset [YES]' },
|
|
57
|
+
{ name: '/compact', usage: '/compact [what to keep]' },
|
|
56
58
|
{ name: '/models', usage: '/models' },
|
|
57
59
|
{ name: '/model', usage: '/model [<alias>|default]' },
|
|
58
60
|
{ name: '/show', usage: '/show [memory|tools] [on|off]' },
|
|
@@ -102,12 +104,14 @@ const HELP_TEXT_BASE = `Available commands:
|
|
|
102
104
|
/help — show this help
|
|
103
105
|
/agents — list agents
|
|
104
106
|
/agent <name> [session] — switch agent (defaults to main session)
|
|
105
|
-
/sessions
|
|
107
|
+
/sessions [archived] — list sessions of current agent (archived: the archived ones)
|
|
106
108
|
/session <slug-or-id> — switch to another session of current agent
|
|
109
|
+
/unarchive <slug-or-id> — bring an archived session back and switch to it
|
|
107
110
|
/new <slug> — create new session and switch to it
|
|
108
111
|
/main — back to main session of current agent
|
|
109
112
|
/reset — preview reset of current session
|
|
110
113
|
/reset YES — archive current session, start fresh
|
|
114
|
+
/compact [what to keep] — compact this session now and keep talking (optional focus for the summary)
|
|
111
115
|
/models — list all configured models with aliases
|
|
112
116
|
/model — show current effective model for this session
|
|
113
117
|
/model <alias-or-ref> — override model for this session
|
|
@@ -193,6 +197,15 @@ async function applySamplingPatch(
|
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
|
|
200
|
+
/** `2026-10-06 23:00` in the terminal's own time zone (the server
|
|
201
|
+
* sends UTC). Empty for a missing or unreadable timestamp. */
|
|
202
|
+
function localStamp(iso: string | null | undefined): string {
|
|
203
|
+
const t = iso ? new Date(iso) : null;
|
|
204
|
+
if (!t || Number.isNaN(t.getTime())) return '';
|
|
205
|
+
const p = (n: number) => String(n).padStart(2, '0');
|
|
206
|
+
return `${t.getFullYear()}-${p(t.getMonth() + 1)}-${p(t.getDate())} ${p(t.getHours())}:${p(t.getMinutes())}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
196
209
|
export async function runCommand(
|
|
197
210
|
line: string,
|
|
198
211
|
ctx: CommandContext,
|
|
@@ -255,6 +268,27 @@ export async function runCommand(
|
|
|
255
268
|
}
|
|
256
269
|
|
|
257
270
|
case '/sessions': {
|
|
271
|
+
if (args[0] === 'archived') {
|
|
272
|
+
const archived = (await ctx.api.fetchSessions(ctx.agent, { includeArchived: true }))
|
|
273
|
+
.filter((s) => s.isArchived)
|
|
274
|
+
.sort((a, b) => (b.archivedAt ?? b.lastActivity ?? '').localeCompare(a.archivedAt ?? a.lastActivity ?? ''));
|
|
275
|
+
if (archived.length === 0) {
|
|
276
|
+
out.push({ kind: 'notice', text: `No archived sessions for ${ctx.agent}.`, tone: 'info' });
|
|
277
|
+
return out;
|
|
278
|
+
}
|
|
279
|
+
const lines = [`Archived sessions for ${ctx.agent} (newest first):`];
|
|
280
|
+
for (const s of archived) {
|
|
281
|
+
const stamp = localStamp(s.archivedAt ?? s.lastActivity) || '—';
|
|
282
|
+
lines.push(` ${s.slug.padEnd(24)} ${String(s.messageCount).padStart(3)} msgs archived ${stamp} ${s.id}`);
|
|
283
|
+
}
|
|
284
|
+
lines.push(' /unarchive <slug-or-id> brings one back.');
|
|
285
|
+
out.push({ kind: 'notice', text: lines.join('\n'), tone: 'info' });
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
if (args[0]) {
|
|
289
|
+
out.push({ kind: 'notice', text: 'usage: /sessions [archived]', tone: 'warn' });
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
258
292
|
const sessions = await ctx.api.fetchSessions(ctx.agent);
|
|
259
293
|
const lines = [`Sessions for ${ctx.agent}:`];
|
|
260
294
|
for (const s of sessions) {
|
|
@@ -266,7 +300,7 @@ export async function runCommand(
|
|
|
266
300
|
typeof s.unreadAt === 'string' &&
|
|
267
301
|
(typeof s.seenAt !== 'string' || s.unreadAt > s.seenAt);
|
|
268
302
|
const unreadGlyph = isUnread ? '📬' : ' ';
|
|
269
|
-
const stamp = s.lastActivity
|
|
303
|
+
const stamp = localStamp(s.lastActivity) || 'empty';
|
|
270
304
|
const project = s.projectSlug ? ` 📁 ${s.projectSlug}` : '';
|
|
271
305
|
lines.push(
|
|
272
306
|
` ${marker} ${unreadGlyph} ${s.slug.padEnd(24)} ${String(s.messageCount).padStart(3)} msgs ${stamp}${project}`,
|
|
@@ -283,8 +317,9 @@ export async function runCommand(
|
|
|
283
317
|
return out;
|
|
284
318
|
}
|
|
285
319
|
if (ref !== 'main') {
|
|
286
|
-
const sessions = await ctx.api.fetchSessions(ctx.agent);
|
|
287
|
-
|
|
320
|
+
const sessions = await ctx.api.fetchSessions(ctx.agent, { includeArchived: true });
|
|
321
|
+
const hit = sessions.find((s) => s.id === ref) ?? sessions.find((s) => s.slug === ref && !s.isArchived) ?? sessions.find((s) => s.slug === ref);
|
|
322
|
+
if (!hit) {
|
|
288
323
|
out.push({
|
|
289
324
|
kind: 'notice',
|
|
290
325
|
text: `session '${ref}' not found. /sessions to list, or /new <slug>.`,
|
|
@@ -292,11 +327,71 @@ export async function runCommand(
|
|
|
292
327
|
});
|
|
293
328
|
return out;
|
|
294
329
|
}
|
|
330
|
+
if (hit.isArchived) {
|
|
331
|
+
out.push({
|
|
332
|
+
kind: 'notice',
|
|
333
|
+
text: `session '${ref}' is archived. /unarchive ${hit.id} brings it back.`,
|
|
334
|
+
tone: 'warn',
|
|
335
|
+
});
|
|
336
|
+
return out;
|
|
337
|
+
}
|
|
295
338
|
}
|
|
296
339
|
out.push({ kind: 'switchTo', agent: ctx.agent, session: ref });
|
|
297
340
|
return out;
|
|
298
341
|
}
|
|
299
342
|
|
|
343
|
+
case '/unarchive': {
|
|
344
|
+
const ref = args[0];
|
|
345
|
+
if (!ref) {
|
|
346
|
+
out.push({ kind: 'notice', text: 'usage: /unarchive <slug-or-id> (/sessions archived lists them)', tone: 'warn' });
|
|
347
|
+
return out;
|
|
348
|
+
}
|
|
349
|
+
const archived = (await ctx.api.fetchSessions(ctx.agent, { includeArchived: true })).filter((s) => s.isArchived);
|
|
350
|
+
const byId = archived.find((s) => s.id === ref);
|
|
351
|
+
const matches = byId ? [byId] : archived.filter((s) => s.slug === ref);
|
|
352
|
+
if (matches.length === 0) {
|
|
353
|
+
out.push({ kind: 'notice', text: `no archived session '${ref}'. /sessions archived lists them.`, tone: 'warn' });
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
if (matches.length > 1) {
|
|
357
|
+
// Every /reset of main leaves a `main-archive`: the name alone
|
|
358
|
+
// does not say which one.
|
|
359
|
+
const lines = [`'${ref}' matches ${matches.length} archived sessions. Use the id:`];
|
|
360
|
+
for (const s of matches) {
|
|
361
|
+
const stamp = localStamp(s.archivedAt ?? s.lastActivity) || '—';
|
|
362
|
+
lines.push(` /unarchive ${s.id} ${String(s.messageCount).padStart(3)} msgs archived ${stamp}`);
|
|
363
|
+
}
|
|
364
|
+
out.push({ kind: 'notice', text: lines.join('\n'), tone: 'warn' });
|
|
365
|
+
return out;
|
|
366
|
+
}
|
|
367
|
+
try {
|
|
368
|
+
const restored = await ctx.api.unarchiveSession(ctx.agent, matches[0]!.id);
|
|
369
|
+
out.push({ kind: 'notice', text: `[unarchived] back as '${restored.slug}'. Switching to it.`, tone: 'info' });
|
|
370
|
+
out.push({ kind: 'switchTo', agent: ctx.agent, session: restored.session });
|
|
371
|
+
} catch (err) {
|
|
372
|
+
out.push({ kind: 'notice', text: (err as Error).message, tone: 'error' });
|
|
373
|
+
}
|
|
374
|
+
return out;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
case '/compact': {
|
|
378
|
+
const focus = args.join(' ').trim();
|
|
379
|
+
try {
|
|
380
|
+
const r = await ctx.api.compactSession(ctx.agent, ctx.session, focus || undefined);
|
|
381
|
+
if (r.status === 'error') {
|
|
382
|
+
out.push({ kind: 'notice', text: r.error ?? 'compaction failed', tone: r.busy ? 'warn' : 'error' });
|
|
383
|
+
} else if (r.status === 'compacted') {
|
|
384
|
+
// The chat row (context compacted) arrives over the stream.
|
|
385
|
+
if (r.note) out.push({ kind: 'notice', text: r.note, tone: 'info' });
|
|
386
|
+
} else {
|
|
387
|
+
out.push({ kind: 'notice', text: r.note ?? `nothing compacted (${r.status})`, tone: 'warn' });
|
|
388
|
+
}
|
|
389
|
+
} catch (err) {
|
|
390
|
+
out.push({ kind: 'notice', text: (err as Error).message, tone: 'error' });
|
|
391
|
+
}
|
|
392
|
+
return out;
|
|
393
|
+
}
|
|
394
|
+
|
|
300
395
|
case '/new': {
|
|
301
396
|
const slug = args[0];
|
|
302
397
|
if (!slug) {
|
|
@@ -325,8 +420,8 @@ export async function runCommand(
|
|
|
325
420
|
: '';
|
|
326
421
|
const text =
|
|
327
422
|
`[/reset] would archive the CURRENT session (${ctx.agent}:${ctx.session}) and start fresh.` +
|
|
328
|
-
`\n
|
|
329
|
-
`\n
|
|
423
|
+
`\n The conversation is kept as an archive: /sessions archived` +
|
|
424
|
+
`\n lists it, /unarchive brings it back as <name>-archive.` +
|
|
330
425
|
altHint +
|
|
331
426
|
`\n To commit: /reset YES`;
|
|
332
427
|
out.push({ kind: 'notice', text, tone: 'info' });
|
|
@@ -341,7 +436,7 @@ export async function runCommand(
|
|
|
341
436
|
out.push({
|
|
342
437
|
kind: 'notice',
|
|
343
438
|
text:
|
|
344
|
-
`[reset done] archived as: ${result.archivedId}` +
|
|
439
|
+
`[reset done] archived as: ${result.archivedId} (/unarchive ${result.archivedId} brings it back)` +
|
|
345
440
|
`\n current session is now empty + clean.${dreamLine}`,
|
|
346
441
|
tone: 'info',
|
|
347
442
|
});
|
|
@@ -429,13 +524,15 @@ export async function runCommand(
|
|
|
429
524
|
out.push({ kind: 'notice', text: 'could not fetch thinking state', tone: 'error' });
|
|
430
525
|
return out;
|
|
431
526
|
}
|
|
432
|
-
const eff = info.effective ?? '
|
|
527
|
+
const eff = info.effective ?? 'model decides';
|
|
433
528
|
const sourcePart =
|
|
434
529
|
info.source === 'session-override'
|
|
435
|
-
? ` — session
|
|
530
|
+
? ` — set for this session (agent default: ${info.personaDefault ?? 'none'}, model default: ${info.modelDefault ?? 'none'})`
|
|
436
531
|
: info.source === 'persona-default'
|
|
437
|
-
?
|
|
438
|
-
:
|
|
532
|
+
? " — the agent's default (agent.yaml)"
|
|
533
|
+
: info.source === 'model-default'
|
|
534
|
+
? " — the model's default (config.yaml)"
|
|
535
|
+
: ' — nothing set: nothing is sent and the model decides (reasoning models usually think)';
|
|
439
536
|
const dormantPart = info.effective && !info.modelSupportsReasoning
|
|
440
537
|
? `\n warning: active model has no 'reasoning' capability — setting is dormant`
|
|
441
538
|
: '';
|
package/src/cli/tui/header.tsx
CHANGED
|
@@ -46,6 +46,9 @@ interface Props {
|
|
|
46
46
|
/** Session work counters (`⌛3 ▶1 🤖2`), empty when idle. Text is
|
|
47
47
|
* pre-formatted by work-queue.ts; /queue shows the list. */
|
|
48
48
|
workCounters?: string;
|
|
49
|
+
/** The model the session's next turn uses (alias or id), read from
|
|
50
|
+
* the server and refreshed on every switch. */
|
|
51
|
+
nextModel?: { label: string; modelId: string } | null;
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
// Status line. Sits right above the input, NOT at the top of the terminal —
|
|
@@ -69,6 +72,7 @@ export function Header({
|
|
|
69
72
|
project,
|
|
70
73
|
unreadOtherAgents,
|
|
71
74
|
workCounters,
|
|
75
|
+
nextModel,
|
|
72
76
|
}: Props) {
|
|
73
77
|
const tokenSegment = renderTokenSegment(stats);
|
|
74
78
|
const agentTag = agentIcon ? `${agentIcon} ${agent}` : agent;
|
|
@@ -99,6 +103,16 @@ export function Header({
|
|
|
99
103
|
<>
|
|
100
104
|
<Text color="gray"> · </Text>
|
|
101
105
|
<Text color="magentaBright">{stats.model}</Text>
|
|
106
|
+
{nextModel && !sameModel(stats.model, nextModel.modelId) ? (
|
|
107
|
+
// Switched since the last turn (here or elsewhere): the
|
|
108
|
+
// model shown is the last turn's, the arrow the next one's.
|
|
109
|
+
<Text color="gray"> → {nextModel.label} (next turn)</Text>
|
|
110
|
+
) : null}
|
|
111
|
+
</>
|
|
112
|
+
) : nextModel ? (
|
|
113
|
+
<>
|
|
114
|
+
<Text color="gray"> · </Text>
|
|
115
|
+
<Text color="magentaBright">{nextModel.label}</Text>
|
|
102
116
|
</>
|
|
103
117
|
) : null}
|
|
104
118
|
{tokenSegment ? (
|
|
@@ -277,3 +291,9 @@ function renderTokenSegment(stats: TurnStats | null): ReactElement | null {
|
|
|
277
291
|
</Text>
|
|
278
292
|
);
|
|
279
293
|
}
|
|
294
|
+
|
|
295
|
+
/** The last turn's model (an id, or `provider/id` after a fallback)
|
|
296
|
+
* against the session's next model id. */
|
|
297
|
+
function sameModel(turnModel: string, nextModelId: string): boolean {
|
|
298
|
+
return turnModel === nextModelId || turnModel.endsWith(`/${nextModelId}`);
|
|
299
|
+
}
|
package/src/cli/tui/stream.ts
CHANGED
|
@@ -255,6 +255,8 @@ export function openStream(
|
|
|
255
255
|
...(typeof data.summary === 'string' ? { summary: data.summary } : {}),
|
|
256
256
|
payload: data.payload,
|
|
257
257
|
};
|
|
258
|
+
case 'session_model':
|
|
259
|
+
return { kind: 'session-model' };
|
|
258
260
|
case 'model_fallback':
|
|
259
261
|
if (typeof data.requested !== 'string' || typeof data.actual !== 'string') return null;
|
|
260
262
|
return {
|
package/src/cli/tui/types.ts
CHANGED
|
@@ -37,7 +37,8 @@ export interface SessionThinkingInfo {
|
|
|
37
37
|
effective: ThinkingLevel | null;
|
|
38
38
|
override: ThinkingLevel | null;
|
|
39
39
|
personaDefault: ThinkingLevel | null;
|
|
40
|
-
|
|
40
|
+
modelDefault?: ThinkingLevel | null;
|
|
41
|
+
source: 'session-override' | 'persona-default' | 'model-default' | 'engine-default';
|
|
41
42
|
modelSupportsReasoning: boolean;
|
|
42
43
|
wire?: string | null;
|
|
43
44
|
}
|
|
@@ -79,6 +80,9 @@ export interface SessionSummary {
|
|
|
79
80
|
unreadAt?: string | null;
|
|
80
81
|
/** ISO timestamp of when any client last viewed this session. */
|
|
81
82
|
seenAt?: string | null;
|
|
83
|
+
/** Only in a list fetched with archived sessions included. */
|
|
84
|
+
isArchived?: boolean;
|
|
85
|
+
archivedAt?: string;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
// Project surface — mirror of the server's project frontmatter, kept lean
|
|
@@ -401,6 +405,11 @@ export type StreamEvent =
|
|
|
401
405
|
kind: 'turn-dequeued';
|
|
402
406
|
turnId: string;
|
|
403
407
|
}
|
|
408
|
+
| {
|
|
409
|
+
// The session's model was set or cleared from somewhere (another
|
|
410
|
+
// client, an agent, the API). The client re-reads it.
|
|
411
|
+
kind: 'session-model';
|
|
412
|
+
}
|
|
404
413
|
| {
|
|
405
414
|
// Project focus change broadcast (HTTP-route initiated). MCP-routed
|
|
406
415
|
// agent project_focus tool calls don't reach SSE — clients catch
|
|
@@ -531,6 +531,8 @@ export interface RunCompactionInput {
|
|
|
531
531
|
/** Test seam: run the summary through this instead of the real engine
|
|
532
532
|
* dispatcher, so the cascade can be exercised without a provider. */
|
|
533
533
|
summarize?: (worker: ResolvedModel) => Promise<SummarizeViaResult>;
|
|
534
|
+
/** A compaction asked for by hand (`/compact [focus]`). */
|
|
535
|
+
manual?: { focus?: string };
|
|
534
536
|
}
|
|
535
537
|
|
|
536
538
|
export async function runCompaction(
|
|
@@ -556,6 +558,7 @@ export async function runCompaction(
|
|
|
556
558
|
systemPrompt,
|
|
557
559
|
pairs: range.pairs,
|
|
558
560
|
priorSummary: range.priorSummary,
|
|
561
|
+
...(input.manual?.focus ? { focus: input.manual.focus } : {}),
|
|
559
562
|
});
|
|
560
563
|
|
|
561
564
|
const tokensBefore = estimateTokens(system + user);
|
|
@@ -690,6 +693,7 @@ export async function runCompaction(
|
|
|
690
693
|
summary: summaryResult.text,
|
|
691
694
|
byEngine: worker.provider.engine,
|
|
692
695
|
byModel: `${worker.providerName}/${worker.modelId}`,
|
|
696
|
+
...(input.manual ? { trigger: 'manual' as const } : {}),
|
|
693
697
|
tokensBefore,
|
|
694
698
|
tokensAfter: summaryResult.tokensOut ?? estimateTokens(summaryResult.text),
|
|
695
699
|
};
|