sumo-agents 0.4.0 → 0.5.0
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/AGENTS.md +8 -6
- package/CHANGELOG.md +155 -0
- package/README.md +76 -18
- package/bin/sumo.mjs +13 -2
- package/guides/feature.md +2 -1
- package/guides/memory.md +6 -4
- package/guides/projects.md +1 -1
- package/guides/review.md +1 -1
- package/package.json +5 -4
- package/prompts/dream.md +6 -0
- package/spinner.txt +25 -1
- package/src/apply.mjs +146 -18
- package/src/auth.mjs +32 -5
- package/src/card.mjs +39 -2
- package/src/catalog.mjs +6 -3
- package/src/chat.mjs +197 -86
- package/src/cli.mjs +359 -135
- package/src/cost.mjs +67 -8
- package/src/db.mjs +106 -3
- package/src/dream.mjs +445 -19
- package/src/editor.mjs +3 -2
- package/src/export.mjs +105 -7
- package/src/guard.mjs +57 -11
- package/src/guides.mjs +5 -4
- package/src/herdr.mjs +4 -2
- package/src/hooks.mjs +31 -18
- package/src/jobs.mjs +118 -39
- package/src/jobtools.mjs +6 -4
- package/src/keeper.mjs +77 -0
- package/src/local-server.mjs +9 -16
- package/src/lock.mjs +2 -1
- package/src/logs.mjs +165 -0
- package/src/loop.mjs +121 -44
- package/src/mcp.mjs +72 -16
- package/src/memory.mjs +142 -15
- package/src/model.mjs +41 -21
- package/src/paths.mjs +38 -0
- package/src/prime.mjs +19 -31
- package/src/projects.mjs +76 -12
- package/src/redact.mjs +10 -0
- package/src/render.mjs +2 -1
- package/src/route.mjs +16 -22
- package/src/sandbox.mjs +82 -3
- package/src/scan.mjs +35 -1
- package/src/scribe.mjs +10 -22
- package/src/sessions.mjs +46 -11
- package/src/setup.mjs +423 -78
- package/src/text.mjs +100 -1
- package/src/tools.mjs +258 -21
- package/src/tty.mjs +205 -78
- package/src/ui.mjs +869 -293
- package/src/verify.mjs +17 -1
package/src/chat.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
-
import { appendFileSync,
|
|
4
|
-
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
3
|
+
import { appendFileSync, mkdirSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
4
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
5
5
|
import { createInterface } from 'node:readline/promises';
|
|
6
6
|
import { isAdvisorTool } from './advisor.mjs';
|
|
7
7
|
import { ago } from './card.mjs';
|
|
8
8
|
import { getMeta } from './db.mjs';
|
|
9
|
-
import { runDream } from './dream.mjs';
|
|
10
9
|
import { openWatchTab, runHerdr } from './herdr.mjs';
|
|
11
10
|
import { appendLive, attemptsSettled, endLive, getJob, newJob, parseJobId, reportOf, runFollowed, startLive, tell as tellJob, treeOf } from './jobs.mjs';
|
|
12
11
|
import { handleEvent } from './hooks.mjs';
|
|
13
|
-
import { contextFor, converse, networkOn, paramsFor, runJob, runLines, sandboxOn, sendToApi, stopReason, TAMPER_REFUSED, tampersMarker, textOf, thinkingFor, withMcp, withServers } from './loop.mjs';
|
|
12
|
+
import { COMPACT_INSTRUCTIONS, compactionParams, contextFor, converse, describeFailure, networkOn, paramsFor, QUIET_RETRIES, runJob, runLines, sandboxOn, sendToApi, stopReason, TAMPER_REFUSED, tampersMarker, textOf, thinkingFor, withFallback, withMcp, withServers } from './loop.mjs';
|
|
13
|
+
import { logRun, usageOf } from './model.mjs';
|
|
14
14
|
import { closeMcp, compactInput, gateMcp, isMcpTool, mcpLines, mcpReady, splitMcpName } from './mcp.mjs';
|
|
15
|
+
import { EFFORT_MESSAGE_BETA, effortOnly } from './auth.mjs';
|
|
15
16
|
import { assertOn, MODEL_IDS, MODELS, modelId, usableModels } from './catalog.mjs';
|
|
16
17
|
import { takeLock } from './lock.mjs';
|
|
17
18
|
import { paths, REPO_ROOT } from './paths.mjs';
|
|
@@ -21,14 +22,14 @@ import { getProject, projectAt, scratchDir } from './projects.mjs';
|
|
|
21
22
|
import { redact } from './redact.mjs';
|
|
22
23
|
import { chooseChatRoute, EFFORTS } from './route.mjs';
|
|
23
24
|
import { verifyCommands } from './scan.mjs';
|
|
24
|
-
import {
|
|
25
|
-
import { currentProject, describeSaved, findSaved, loadState, lockFile, recordTurn, saveState, savedSessions, sessionLine, shortId, withoutThinking } from './sessions.mjs';
|
|
25
|
+
import { passLines, runMemoryPass } from './keeper.mjs';
|
|
26
|
+
import { currentProject, describeSaved, findSaved, loadState, lockFile, noteSessionOutside, recordTurn, saveState, savedSessions, sessionLine, shortId, withoutThinking } from './sessions.mjs';
|
|
26
27
|
import { ASK_TOOL, BASH_TOOL, cap, capRedacted, DELEGATE_TOOL, EDITOR_TOOL, INTERRUPTED, nextUndoTurn, runCommand, undoLast } from './tools.mjs';
|
|
27
28
|
import { CONFIG_DEFAULTS } from './setup.mjs';
|
|
28
|
-
import { estimateTokens, head } from './text.mjs';
|
|
29
|
-
import { colourEnabled, createRenderer, header, pathFrom, prompt, renderBlock, safeForTerminal, styles, tilde, toolView, widthOf } from './tty.mjs';
|
|
29
|
+
import { closest, estimateTokens, head } from './text.mjs';
|
|
30
|
+
import { colourEnabled, createRenderer, explained, header, ledger, OUT_AT, pathFrom, prompt, renderBlock, safeForTerminal, styles, TEXT_AT, tilde, toolView, widthOf, wrap } from './tty.mjs';
|
|
30
31
|
import { hasCommit } from './verify.mjs';
|
|
31
|
-
import { sourcesOf, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WEB_TOOLS } from './web.mjs';
|
|
32
|
+
import { isWebTool, sourcesOf, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WEB_TOOLS } from './web.mjs';
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* The conversation the user has with Sumo: the same loop a job runs in, with
|
|
@@ -43,7 +44,9 @@ import { sourcesOf, WEB_FETCH_TOOL, WEB_SEARCH_TOOL, WEB_TOOLS } from './web.mjs
|
|
|
43
44
|
*/
|
|
44
45
|
|
|
45
46
|
/** Models that take operator instructions as `role: "system"` messages mid-conversation; the others get them as text in the user turn. */
|
|
46
|
-
const SYSTEM_MESSAGES = new Set([MODEL_IDS.opus, MODEL_IDS.sonnet, MODEL_IDS.fable]);
|
|
47
|
+
const SYSTEM_MESSAGES = new Set([MODEL_IDS.haiku, MODEL_IDS.opus, MODEL_IDS.sonnet, MODEL_IDS.fable]);
|
|
48
|
+
/** Models whose effort can be changed by a message in the conversation, leaving the cache whole: the same four, with thinking on as it always is here. */
|
|
49
|
+
const EFFORT_MESSAGES = SYSTEM_MESSAGES;
|
|
47
50
|
|
|
48
51
|
// The guide comes with the command, by name, through the prompt hook — the same way it comes when the user's words ask for
|
|
49
52
|
// it: from inside a project the tools cannot reach guides/ by a relative path, and the editor is jailed away from it.
|
|
@@ -51,47 +54,62 @@ const COMMANDS = {
|
|
|
51
54
|
fix: (args) => ({ text: `Fix this: ${args}`, guide: 'fix' }),
|
|
52
55
|
feature: (args) => ({ text: `Build this: ${args}`, guide: 'feature' }),
|
|
53
56
|
review: (args) => ({ text: `Review this: ${args}`, guide: 'review' }),
|
|
54
|
-
dream: () => ({ text: 'Run `sumo dream run` and tell me, in a few lines, what it changed and what it wants me to confirm.' }),
|
|
55
57
|
};
|
|
56
58
|
|
|
59
|
+
/** What each model is for, as `/model`'s menu says it: the kinds of work the router gives it. */
|
|
60
|
+
const MODEL_HINTS = {
|
|
61
|
+
auto: 'the router picks a model and an effort each turn',
|
|
62
|
+
haiku: 'quickest and cheapest: small, mechanical changes',
|
|
63
|
+
sonnet: 'everyday features and fixes',
|
|
64
|
+
opus: 'hard problems: design, a bug with no clear cause',
|
|
65
|
+
fable: 'novel work: new algorithms, deep reviews',
|
|
66
|
+
};
|
|
67
|
+
/** And each effort: how much the model thinks before it acts. */
|
|
68
|
+
const EFFORT_HINTS = { low: 'quickest: one spot', medium: 'a few files', high: 'many parts that work together', xhigh: 'more thought still, slower', max: 'the most thought, the slowest' };
|
|
69
|
+
|
|
57
70
|
/**
|
|
58
|
-
* What the command menu shows, in the order it shows it
|
|
59
|
-
* The
|
|
71
|
+
* What the command menu shows, in the order it shows it, each with what it does for the user — and, for /help, what it
|
|
72
|
+
* takes (`args`). The models `/model` offers are the ones that are on as it is typed, each with what it is for and the one
|
|
73
|
+
* in use marked (`inUse`). The effort a model would keep comes first (`effortNow`), so Enter on the open menu keeps it
|
|
74
|
+
* rather than dropping to the lowest.
|
|
60
75
|
*/
|
|
61
|
-
|
|
76
|
+
function commandList(db, { effortNow = () => null, inUse = () => ({}), saved = () => [], running = () => [] } = {}) {
|
|
62
77
|
const efforts = () => {
|
|
63
|
-
const
|
|
64
|
-
return EFFORTS.includes(
|
|
78
|
+
const kept = effortNow();
|
|
79
|
+
return EFFORTS.includes(kept) ? [kept, ...EFFORTS.filter((e) => e !== kept)] : EFFORTS;
|
|
65
80
|
};
|
|
81
|
+
const marked = (name, hint, current) => ({ name, hint: `${hint}${name === current ? ' (current)' : ''}` });
|
|
66
82
|
const modelChoices = (given) => {
|
|
67
83
|
const usable = usableModels(db);
|
|
68
|
-
|
|
84
|
+
const { model, effort } = inUse();
|
|
85
|
+
if (given.length === 0) return ['auto', ...usable].map((name) => marked(name, MODEL_HINTS[name] ?? '', model));
|
|
86
|
+
return given.length === 1 && usable.includes(given[0]) ? efforts().map((name) => marked(name, EFFORT_HINTS[name] ?? '', model === 'auto' ? null : effort)) : [];
|
|
69
87
|
};
|
|
70
88
|
return [
|
|
71
|
-
{ name: 'fix', hint: 'fix a bug,
|
|
72
|
-
{ name: 'feature', hint: 'build something,
|
|
73
|
-
{ name: 'review', hint: 'have a reviewer
|
|
74
|
-
{ name: '
|
|
75
|
-
{ name: '
|
|
76
|
-
{ name: '
|
|
77
|
-
{ name: '
|
|
78
|
-
{ name: '
|
|
79
|
-
{ name: '
|
|
80
|
-
{ name: '
|
|
81
|
-
{ name: '
|
|
82
|
-
{ name: '
|
|
83
|
-
{ name: '
|
|
84
|
-
{ name: 'thinking', hint: 'the model\'s thinking under the working line: on or off', choices: (given) => (given.length === 0 ? ['on', 'off'] : []) },
|
|
89
|
+
{ name: 'fix', args: '<bug>', hint: 'fix a bug: find the cause, change it, check it' },
|
|
90
|
+
{ name: 'feature', args: '<what>', hint: 'build something new, with its tests' },
|
|
91
|
+
{ name: 'review', args: '<what>', hint: 'have a reviewer look over a change' },
|
|
92
|
+
{ name: 'model', args: '[model] [effort]', hint: 'the model and effort: see them, or change them', choices: modelChoices },
|
|
93
|
+
{ name: 'memory', hint: 'your memory in the browser: confirm, edit, forget' },
|
|
94
|
+
{ name: 'mcp', hint: 'the MCP servers: which are connected, and their tools' },
|
|
95
|
+
{ name: 'resume', args: '[id]', hint: 'pick up a saved session where it stopped', choices: (given) => (given.length === 0 ? saved().map((s) => ({ name: shortId(s.id), hint: s.hint })) : []) },
|
|
96
|
+
{ name: 'copy', args: '[code] [n]', hint: 'copy the last reply, or its code, to the clipboard', choices: (given) => (given.length === 0 ? ['code'] : []) },
|
|
97
|
+
{ name: 'undo', hint: 'put back the files the last turn edited' },
|
|
98
|
+
{ name: 'stop', args: '[job]', hint: 'stop a job working in the background', choices: (given) => (given.length === 0 ? running().map((id) => `j${id}`) : []) },
|
|
99
|
+
{ name: 'context', hint: 'how full the context is, and what it has cost' },
|
|
100
|
+
{ name: 'export', args: '[path]', hint: 'save the conversation as a Markdown file' },
|
|
101
|
+
{ name: 'thinking', args: 'on|off', hint: "show or hide the model's thinking as it works", choices: (given) => (given.length === 0 ? ['on', 'off'] : []) },
|
|
85
102
|
{ name: 'help', hint: 'the commands and the keys' },
|
|
103
|
+
{ name: 'handoff', hint: 'start fresh from a hand-off the model writes' },
|
|
86
104
|
{ name: 'new', hint: 'start a fresh session (/clear does too)' },
|
|
87
|
-
{ name: 'exit', hint: 'leave' },
|
|
105
|
+
{ name: 'exit', hint: 'leave (/quit does too)' },
|
|
88
106
|
];
|
|
89
107
|
}
|
|
90
108
|
|
|
91
109
|
/** A job is run with `delegate`, never from the shell: there it would be an agent in a shell of its own, holding no credential. */
|
|
92
110
|
const JOB_RUN = /(?:^|[\n;&|(`]|\$\()\s*(?:\w+=\S*\s+|nohup\s+|exec\s+)*sumo\s+job\s+(run|new)\b/;
|
|
93
|
-
/**
|
|
94
|
-
const PASS_RUN = /^\s*sumo\s+
|
|
111
|
+
/** The memory pass the model asks for: run here too, since the shell it would start in holds no credential. */
|
|
112
|
+
const PASS_RUN = /^\s*sumo\s+memory\s+run(\s+--tidy)?\s*$/;
|
|
95
113
|
|
|
96
114
|
/**
|
|
97
115
|
* Operator text for the model, placed so the cached prefix is untouched: a
|
|
@@ -150,7 +168,7 @@ export function describeCall(call) {
|
|
|
150
168
|
* The branch a directory's repository is on, read from its HEAD — no process is started for it. A worktree's `.git` is a
|
|
151
169
|
* file that names where its HEAD is. A detached head is the start of its commit; a directory in no repository has none.
|
|
152
170
|
*/
|
|
153
|
-
|
|
171
|
+
function branchOf(dir) {
|
|
154
172
|
for (let at = resolve(dir); ; at = dirname(at)) {
|
|
155
173
|
const git = join(at, '.git');
|
|
156
174
|
try {
|
|
@@ -175,9 +193,9 @@ export const routeOf = ({ model, effort }) => (effort && effort !== 'none' ? `${
|
|
|
175
193
|
|
|
176
194
|
/**
|
|
177
195
|
* What `/model` was given: a model that is on, a model and an effort, or `auto`. The model alone keeps
|
|
178
|
-
* the effort in hand
|
|
196
|
+
* the effort in hand. Anything else is said back, and nothing changes.
|
|
179
197
|
*/
|
|
180
|
-
|
|
198
|
+
function parseRoute(args, current, db) {
|
|
181
199
|
const [model, effort, ...rest] = args.split(/\s+/).filter(Boolean);
|
|
182
200
|
if (model === 'auto') {
|
|
183
201
|
if (effort) throw new UsageError('auto takes no effort — the router picks it each turn');
|
|
@@ -186,10 +204,6 @@ export function parseRoute(args, current, db) {
|
|
|
186
204
|
if (!MODELS.includes(model)) throw new UsageError(`no such model "${model}" — one of: auto, ${usableModels(db).join(', ')}`);
|
|
187
205
|
assertOn(db, model);
|
|
188
206
|
if (rest.length > 0) throw new UsageError(`/model takes a model and an effort, not "${args}"`);
|
|
189
|
-
if (model === 'haiku') {
|
|
190
|
-
if (effort) throw new UsageError('haiku takes no effort setting');
|
|
191
|
-
return { model, effort: 'none' };
|
|
192
|
-
}
|
|
193
207
|
if (effort !== undefined && !EFFORTS.includes(effort)) throw new UsageError(`no such effort "${effort}" — one of: ${EFFORTS.join(', ')}`);
|
|
194
208
|
const kept = current.effort && current.effort !== 'none' ? current.effort : CONFIG_DEFAULTS['chat.effort'];
|
|
195
209
|
return { model, effort: effort ?? kept };
|
|
@@ -202,32 +216,33 @@ export function parseRoute(args, current, db) {
|
|
|
202
216
|
* break a secret apart where the redaction after it would no longer see it whole.
|
|
203
217
|
*/
|
|
204
218
|
export function jobPrinter(write, s, { width = 98, clean = (text) => text, cwd = null } = {}) {
|
|
205
|
-
// Each call as the chat names it —
|
|
219
|
+
// Each call as the chat's ledger names it — run npm test, read src/cart.js — a file from the project the job works in.
|
|
206
220
|
const at = () => (typeof cwd === 'function' ? cwd() : cwd);
|
|
207
221
|
return {
|
|
208
|
-
onStart: (job) => write(
|
|
222
|
+
onStart: (job) => write(`${s.bold(ledger(`j${job.id}`))}${job.agent} · ${routeOf(job)} — ${job.title}\n`),
|
|
209
223
|
onTool: (call) => {
|
|
210
224
|
const view = toolView(call, null, { cwd: at() });
|
|
211
225
|
// One line, and where more was cut away, the ellipsis that says so.
|
|
212
226
|
const [first, ...rest] = clean(view.detail).split('\n');
|
|
213
227
|
const line = first.length > 160 ? `${first.slice(0, 159)}…` : rest.length > 0 && !first.endsWith('…') ? `${first} …` : first;
|
|
214
|
-
write(
|
|
228
|
+
write(`${s.dim(ledger(view.title))}${line}\n`);
|
|
215
229
|
},
|
|
216
|
-
onRetry: (r) => write(
|
|
217
|
-
onCompact: (c) => write(
|
|
230
|
+
onRetry: (r) => write(`${' '.repeat(TEXT_AT)}${s.dim(retryLine(r))}\n`),
|
|
231
|
+
onCompact: (c) => write(`${' '.repeat(TEXT_AT)}${s.dim(compactLine(c))}\n`),
|
|
218
232
|
onResult: (call, result) => {
|
|
219
|
-
// The line that says how it went, as the chat's screen would show it: what a command printed first, a read's size, an
|
|
233
|
+
// The line that says how it went, as the chat's screen would show it: what a command printed first, a read's size, an
|
|
234
|
+
// edit's first change — under the step's words; a failure with its mark, which says so without the colour.
|
|
220
235
|
const first = toolView(call, { content: String(result.content ?? ''), isError: Boolean(result.isError), edit: result.edit }, { cwd: at() }).lines[0]?.text ?? '';
|
|
221
|
-
write(`
|
|
236
|
+
write(`${' '.repeat(OUT_AT - 2)}${result.isError ? `${s.red('✗')} ` : ' '}${s.dim(clean(first).slice(0, 160))}\n`);
|
|
222
237
|
},
|
|
223
238
|
onTurn: (response) => {
|
|
224
239
|
const text = textOf(response.content);
|
|
225
240
|
if (!text) return;
|
|
226
241
|
const drawn = [];
|
|
227
|
-
const reply = createRenderer((t) => drawn.push(t), s, { width });
|
|
242
|
+
const reply = createRenderer((t) => drawn.push(t), s, { width: width - TEXT_AT });
|
|
228
243
|
reply.write(clean(text));
|
|
229
244
|
reply.flush();
|
|
230
|
-
write(`${drawn.join('').split('\n').map((l) => (l ?
|
|
245
|
+
write(`${drawn.join('').split('\n').map((l, i) => (i === 0 ? `${s.bold(ledger('sumo'))}${l}` : l ? `${' '.repeat(TEXT_AT)}${l}` : l)).join('\n')}\n`);
|
|
231
246
|
},
|
|
232
247
|
};
|
|
233
248
|
}
|
|
@@ -245,7 +260,7 @@ const kilo = (n) => (n >= 1000 ? `${(n / 1000).toFixed(n >= 10_000 ? 0 : 1)}k` :
|
|
|
245
260
|
export function contextReport({ contextTokens = 0, rows = [], turns = 0, calls = 0 }) {
|
|
246
261
|
const full = Math.min(1, contextTokens / CONTEXT_FULL);
|
|
247
262
|
const bar = `${'█'.repeat(Math.round(full * 20))}${'░'.repeat(20 - Math.round(full * 20))}`;
|
|
248
|
-
const band = contextTokens >= CONTEXT_FULL ? 'very large — /
|
|
263
|
+
const band = contextTokens >= CONTEXT_FULL ? 'very large — /handoff now, or /new; the memory brings the thread back' : contextTokens >= CONTEXT_LARGE ? 'large — quality drops from here; finish the piece in hand, then /handoff' : 'room to spare';
|
|
249
264
|
const cost = rows.reduce((sum, row) => sum + row.cost, 0);
|
|
250
265
|
const lines = [`**Context** ${kilo(contextTokens)} tokens · \`${bar}\` ${Math.round(full * 100)}% of ${kilo(CONTEXT_FULL)} · ${band}`, '', `**This session** ${turns} turn${turns === 1 ? '' : 's'} · ${calls} tool call${calls === 1 ? '' : 's'} · $${cost.toFixed(2)}`];
|
|
251
266
|
if (rows.length === 0) return [...lines, '', 'No request has been made yet.'].join('\n');
|
|
@@ -253,9 +268,9 @@ export function contextReport({ contextTokens = 0, rows = [], turns = 0, calls =
|
|
|
253
268
|
}
|
|
254
269
|
|
|
255
270
|
/** A session past its budget, in one line: what it has cost, how to start afresh, and how to move the line. */
|
|
256
|
-
|
|
271
|
+
const budgetLine = (cost) => `this session has cost $${cost.toFixed(2)} — /new starts a fresh one; sumo config chat.budget changes when this is said`;
|
|
257
272
|
|
|
258
|
-
/** Where the context is large enough that quality drops, and where it is time for /
|
|
273
|
+
/** Where the context is large enough that quality drops, and where it is time for /handoff: the bands the session is told about. */
|
|
259
274
|
const CONTEXT_LARGE = 60_000;
|
|
260
275
|
const CONTEXT_FULL = 150_000;
|
|
261
276
|
|
|
@@ -307,8 +322,6 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
307
322
|
const named = MODELS.find((name) => MODEL_IDS[name] === model) ?? model;
|
|
308
323
|
if (named !== 'auto' && MODELS.includes(named)) assertOn(db, named, 'sumo config chat.model <name>');
|
|
309
324
|
effort ??= model === 'auto' ? null : configured(db, 'chat.effort');
|
|
310
|
-
// Haiku takes no effort setting, however the chat came to be on it: by flag, by configuration, or by /model.
|
|
311
|
-
if (modelId(model) === MODEL_IDS.haiku) effort = 'none';
|
|
312
325
|
/** On auto, the route the last turn ran on; null otherwise. */
|
|
313
326
|
let routed = null;
|
|
314
327
|
const system = chatSystem();
|
|
@@ -336,6 +349,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
336
349
|
let note = null;
|
|
337
350
|
/** The files the model has viewed or written in this session, as they stood then: an edit to one changed on disk since says so. */
|
|
338
351
|
let seen = new Map();
|
|
352
|
+
/** The files outside the project the user let the editor change for the rest of this session. */
|
|
353
|
+
let opened = new Set();
|
|
339
354
|
/** Whether the screen has said what this session cost: once a session, when it first passes `chat.budget`. */
|
|
340
355
|
let costSaid = false;
|
|
341
356
|
/** The jobs running here, each with what the user has said to it that it has not read yet. */
|
|
@@ -365,13 +380,14 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
365
380
|
const kept = effort ?? configured(db, 'chat.effort');
|
|
366
381
|
return kept && kept !== 'none' ? kept : CONFIG_DEFAULTS['chat.effort'];
|
|
367
382
|
},
|
|
383
|
+
inUse: () => ({ model, effort }),
|
|
368
384
|
saved: () => others().map((s) => ({ id: s.id, hint: describeSaved(s, now()) })),
|
|
369
385
|
running: () => [...stops.keys()],
|
|
370
386
|
});
|
|
371
387
|
|
|
372
388
|
const emit = (text) => out(text);
|
|
373
389
|
/** The conversation as the model in hand can take it: one that takes no operator messages is sent them as text. The history itself is left alone, so a model that does take them still reads it from its cache. */
|
|
374
|
-
const sendAs = (p, options) => send(SYSTEM_MESSAGES.has(p.model) ? p : { ...p, messages: p.messages.map((m) => (m.role === 'system' ? asText(m.content) : m)) }, options);
|
|
390
|
+
const sendAs = (p, options) => send(SYSTEM_MESSAGES.has(p.model) ? p : { ...p, messages: p.messages.filter((m) => !effortOnly(m)).map((m) => (m.role === 'system' ? asText(m.content) : m)) }, options);
|
|
375
391
|
|
|
376
392
|
const busy = (id) => (holder) => `session ${shortId(id)} is open in another terminal (process ${holder})`;
|
|
377
393
|
|
|
@@ -390,6 +406,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
390
406
|
costSaid = false;
|
|
391
407
|
project = null;
|
|
392
408
|
seen = new Map();
|
|
409
|
+
opened = new Set();
|
|
393
410
|
spoken = Boolean(saved);
|
|
394
411
|
transcript = join(paths().logs, 'sessions', `${sessionId}.jsonl`);
|
|
395
412
|
const block = handleEvent(db, 'session-start', { session_id: sessionId, cwd, transcript_path: transcript, source }, now());
|
|
@@ -397,7 +414,6 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
397
414
|
model = saved.model;
|
|
398
415
|
routed = saved.routed ?? null;
|
|
399
416
|
if (!given.effort) effort = saved.effort;
|
|
400
|
-
if (modelId(model) === MODEL_IDS.haiku) effort = 'none';
|
|
401
417
|
}
|
|
402
418
|
params = paramsFor({ model: model === 'auto' ? (routed?.model ?? CONFIG_DEFAULTS['chat.model']) : model, effort: model === 'auto' ? routed?.effort : effort, tools: toolsNow(), system: systemNow(), text: saved ? undefined : block });
|
|
403
419
|
// What jobs reported that this session had not read comes back with it; a fresh session has read nothing, and is owed nothing.
|
|
@@ -445,14 +461,36 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
445
461
|
}
|
|
446
462
|
}
|
|
447
463
|
|
|
448
|
-
/**
|
|
464
|
+
/**
|
|
465
|
+
* The request from here on goes to this model at this effort, thinking as that model does; the conversation so far stays.
|
|
466
|
+
* On the same model, a new effort is said in the conversation — a system message with no content, carrying the effort — so
|
|
467
|
+
* the cached history is not written again, as changing the request's own effort would have it. A model switch writes it
|
|
468
|
+
* again whichever way, so there the request's own effort changes; one said earlier in the conversation would outrank it,
|
|
469
|
+
* so when one was, the new effort is said again too.
|
|
470
|
+
*/
|
|
449
471
|
function apply({ model: m, effort: e }) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
472
|
+
const id = modelId(m);
|
|
473
|
+
const wanted = e && e !== 'none' ? e : null;
|
|
474
|
+
const switched = params.model !== id;
|
|
475
|
+
const spoken = params.messages.some(effortOnly);
|
|
476
|
+
const inForce = params.messages.findLast(effortOnly)?.output_config.effort ?? params.output_config?.effort ?? null;
|
|
477
|
+
if (switched) {
|
|
478
|
+
params.model = id;
|
|
479
|
+
if (wanted) params.output_config = { effort: wanted };
|
|
480
|
+
else delete params.output_config;
|
|
481
|
+
const thinking = thinkingFor(m);
|
|
482
|
+
if (thinking) params.thinking = thinking;
|
|
483
|
+
else delete params.thinking;
|
|
484
|
+
withFallback(params, m);
|
|
485
|
+
}
|
|
486
|
+
if (wanted === inForce && !(switched && spoken)) return;
|
|
487
|
+
if (wanted && EFFORT_MESSAGES.has(id) && params.messages.length > 0 && (!switched || spoken)) {
|
|
488
|
+
params.messages.push({ role: 'system', content: [], output_config: { effort: wanted } });
|
|
489
|
+
if (!params.betas.includes(EFFORT_MESSAGE_BETA)) params.betas = [...params.betas, EFFORT_MESSAGE_BETA];
|
|
490
|
+
} else if (!switched) {
|
|
491
|
+
if (wanted) params.output_config = { effort: wanted };
|
|
492
|
+
else delete params.output_config;
|
|
493
|
+
}
|
|
456
494
|
}
|
|
457
495
|
|
|
458
496
|
/**
|
|
@@ -526,8 +564,8 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
526
564
|
if (gate) return { content: JSON.parse(gate).deny, isError: true };
|
|
527
565
|
const pass = PASS_RUN.exec(command);
|
|
528
566
|
if (pass) {
|
|
529
|
-
activity(
|
|
530
|
-
return { content:
|
|
567
|
+
activity(pass[1] ? 'tidying memory…' : 'running the memory pass…');
|
|
568
|
+
return { content: passLines(await runMemoryPass(db, { tidy: Boolean(pass[1]) }), { asked: Boolean(pass[1]) }).join('\n') };
|
|
531
569
|
}
|
|
532
570
|
const job = JOB_RUN.exec(command);
|
|
533
571
|
if (job) return { content: `jobs are not ${job[1] === 'new' ? 'made' : 'run'} from the shell: use the delegate tool${job[1] === 'run' ? ' (only `job` for one already made)' : ''}`, isError: true };
|
|
@@ -766,10 +804,10 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
766
804
|
return id;
|
|
767
805
|
}
|
|
768
806
|
|
|
769
|
-
/** A turn that ended before the model answered left its operator message at the tail; the API takes one only where the model answers next, so before anything follows it, it becomes text. */
|
|
807
|
+
/** A turn that ended before the model answered left its operator message at the tail; the API takes one only where the model answers next, so before anything follows it, it becomes text. An effort said there may stand anywhere, and stays. */
|
|
770
808
|
function settleTail() {
|
|
771
809
|
const tail = params.messages.at(-1);
|
|
772
|
-
if (tail?.role === 'system') params.messages[params.messages.length - 1] = asText(tail.content);
|
|
810
|
+
if (tail?.role === 'system' && !effortOnly(tail)) params.messages[params.messages.length - 1] = asText(tail.content);
|
|
773
811
|
}
|
|
774
812
|
|
|
775
813
|
/**
|
|
@@ -822,17 +860,24 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
822
860
|
|
|
823
861
|
async function turn(text, said, images, automated = false, guide = null) {
|
|
824
862
|
stopper = new AbortController();
|
|
825
|
-
// Edits nothing has checked: an editor call that
|
|
826
|
-
//
|
|
827
|
-
// left. The shell can edit too (`sed -i`,
|
|
863
|
+
// Edits nothing has checked: an editor call that wrote adds its file — one refused, or whose old_str was not found,
|
|
864
|
+
// changed nothing and adds none; one of the project's declared checks running clears them — any command does when
|
|
865
|
+
// the project declares none. The gate at the end of the turn is told what is left. The shell can edit too (`sed -i`,
|
|
866
|
+
// a redirect); that is not seen.
|
|
828
867
|
const unchecked = new Set();
|
|
829
868
|
const declared = () => verifyCommands(workspace().cwd).map((c) => c.command);
|
|
830
869
|
const noteCall = (call) => {
|
|
831
|
-
if (call.name === EDITOR_TOOL.name && call.input?.command !== 'view' && call.input?.path) unchecked.add(resolve(workspace().cwd, String(call.input.path)));
|
|
832
870
|
if (call.name !== BASH_TOOL.name) return;
|
|
833
871
|
const checks = declared();
|
|
834
872
|
if (checks.length === 0 || checks.some((c) => String(call.input?.command ?? '').includes(c))) unchecked.clear();
|
|
835
873
|
};
|
|
874
|
+
// Only the project's own files are the project's check to judge: a file outside it the user let change is theirs.
|
|
875
|
+
const noteResult = (call, result) => {
|
|
876
|
+
if (call.name !== EDITOR_TOOL.name || call.input?.command === 'view' || !call.input?.path || result?.isError) return;
|
|
877
|
+
const { cwd: root } = workspace();
|
|
878
|
+
const path = resolve(root, String(call.input.path));
|
|
879
|
+
if (path.startsWith(`${root}${sep}`)) unchecked.add(path);
|
|
880
|
+
};
|
|
836
881
|
// The servers connect while the first turn is typed; the first request waits for them, and Esc does not. Their tools
|
|
837
882
|
// join the request then — even when something else, /mcp, already waited for them to connect.
|
|
838
883
|
if (!joined) {
|
|
@@ -886,8 +931,9 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
886
931
|
for (;;) {
|
|
887
932
|
const outcome = await converse(db, params, {
|
|
888
933
|
send: sendAs,
|
|
889
|
-
// A command the sandbox kept from writing is put to the user as an MCP call off the allow list is, for one run outside it
|
|
890
|
-
|
|
934
|
+
// A command the sandbox kept from writing is put to the user as an MCP call off the allow list is, for one run outside it;
|
|
935
|
+
// so is a change to a file outside the project, once or for the session.
|
|
936
|
+
ctx: { ...workspace(), seen, opened, undo: undoFolder, approve },
|
|
891
937
|
ledger,
|
|
892
938
|
beforeTool,
|
|
893
939
|
concurrent: (call) => call.name === DELEGATE_TOOL.name,
|
|
@@ -904,8 +950,13 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
904
950
|
activity(describeCall(call));
|
|
905
951
|
watch({ type: 'tool', call });
|
|
906
952
|
noteCall(call);
|
|
953
|
+
// A page or an MCP server read here: what this conversation says from now on may be what it was told.
|
|
954
|
+
if (isWebTool(call) || isMcpTool(call.name)) noteSessionOutside(db, sessionId, call.name);
|
|
955
|
+
},
|
|
956
|
+
onResult: (call, result) => {
|
|
957
|
+
noteResult(call, result);
|
|
958
|
+
watch({ type: 'result', call, result });
|
|
907
959
|
},
|
|
908
|
-
onResult: (call, result) => watch({ type: 'result', call, result }),
|
|
909
960
|
onTurn: (response, totals) => {
|
|
910
961
|
lastContext = totals.contextTokens;
|
|
911
962
|
logLine(transcript, { type: 'assistant', message: { role: 'assistant', model: response.model ?? params.model, usage: response.usage, content: response.content } });
|
|
@@ -958,6 +1009,38 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
958
1009
|
return `undid the last turn that changed files: ${what} — changes made through bash are not tracked, so they stay`;
|
|
959
1010
|
}
|
|
960
1011
|
|
|
1012
|
+
/**
|
|
1013
|
+
* `/handoff`: the model writes a hand-off of this session — the task, what is done, what was tried, the files and
|
|
1014
|
+
* the next step, by the instructions a job's compaction summarizes under — and a fresh session starts with it as its
|
|
1015
|
+
* first note, so a piece in hand survives the start. The request is this session's last; the session is then kept,
|
|
1016
|
+
* as /new keeps it, and the new one begins. A hand-off that cannot be had leaves this session as it is.
|
|
1017
|
+
*/
|
|
1018
|
+
async function handoff() {
|
|
1019
|
+
if (!spoken) throw new UsageError('nothing to hand off: nothing has been said in this session — /new starts fresh');
|
|
1020
|
+
stopper = new AbortController();
|
|
1021
|
+
settleTail();
|
|
1022
|
+
const row = (model, result, said) => logRun(db, { kind: 'chat', model, result, note: said, now: now(), sessionId });
|
|
1023
|
+
let summary;
|
|
1024
|
+
try {
|
|
1025
|
+
summary = await sendAs(compactionParams(params, COMPACT_INSTRUCTIONS), { signal: stopper.signal, retries: QUIET_RETRIES });
|
|
1026
|
+
} catch (cause) {
|
|
1027
|
+
const why = describeFailure(cause).slice(0, 200);
|
|
1028
|
+
row(params.model, { ok: false, usage: usageOf(params.model, null) }, `hand-off: ${why}`);
|
|
1029
|
+
if (stopper.signal.aborted) throw new UsageError('the hand-off was stopped: this session goes on');
|
|
1030
|
+
throw new UsageError(`no hand-off could be written: ${why} — /new starts fresh; the memory brings the thread back`);
|
|
1031
|
+
}
|
|
1032
|
+
const block = summary.content.find((b) => b.type === 'compaction' && b.content);
|
|
1033
|
+
const by = summary.model ?? params.model;
|
|
1034
|
+
row(by, { ok: Boolean(block), usage: usageOf(by, summary.usage) }, block ? 'hand-off' : 'hand-off: no summary came back');
|
|
1035
|
+
if (!block) throw new UsageError('no hand-off came back from the model — /new starts fresh; the memory brings the thread back');
|
|
1036
|
+
const text = redact(String(block.content)).text.trim();
|
|
1037
|
+
const from = shortId(sessionId);
|
|
1038
|
+
end();
|
|
1039
|
+
const opening = start('handoff');
|
|
1040
|
+
note = `hand-off: the session before this one (${from}) ended with this hand-off, written by the model that worked it. Carry on from where it leaves off: what it says is done is done.\n\n${text}`;
|
|
1041
|
+
return { block: opening, text, from };
|
|
1042
|
+
}
|
|
1043
|
+
|
|
961
1044
|
/** `! <command>`: the user runs it themselves, where the model would be refused; the model sees what it printed. */
|
|
962
1045
|
async function shell(command) {
|
|
963
1046
|
stopper = new AbortController();
|
|
@@ -980,10 +1063,13 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
980
1063
|
const [, name, args = ''] = m;
|
|
981
1064
|
if (name === 'exit' || name === 'quit') return { control: 'quit' };
|
|
982
1065
|
if (name === 'new' || name === 'clear') return { control: 'new' };
|
|
983
|
-
if (name === 'memory' || name === 'undo' || name === 'context') return { control: name };
|
|
1066
|
+
if (name === 'memory' || name === 'undo' || name === 'context' || name === 'handoff') return { control: name };
|
|
984
1067
|
if (name === 'model' || name === 'resume' || name === 'mcp' || name === 'copy' || name === 'help' || name === 'stop' || name === 'export' || name === 'thinking') return { control: name, args: args.trim() };
|
|
985
1068
|
const make = Object.hasOwn(COMMANDS, name) ? COMMANDS[name] : undefined;
|
|
986
|
-
|
|
1069
|
+
if (make) return { ...make(args.trim()), said: args.trim() };
|
|
1070
|
+
// A command mistyped is answered with the one it is closest to, two keys off at most; one close to none, with them all.
|
|
1071
|
+
const close = closest(name, commands.map((c) => c.name));
|
|
1072
|
+
return { error: close ? `no command /${name} — did you mean /${close}?` : `no command /${name} — one of: ${commands.map((c) => `/${c.name}`).join(' ')}` };
|
|
987
1073
|
}
|
|
988
1074
|
|
|
989
1075
|
/** `/mcp`: the servers as `sumo mcp` lists them. They connect once, while the first turn is typed, so an early look waits for them. */
|
|
@@ -1049,6 +1135,7 @@ export function createChat(db, { model, effort, cwd = process.cwd(), send = send
|
|
|
1049
1135
|
return {
|
|
1050
1136
|
start,
|
|
1051
1137
|
say,
|
|
1138
|
+
handoff,
|
|
1052
1139
|
interrupt: () => stopper?.abort(),
|
|
1053
1140
|
/** Said to the chat while it works: read with the model's next request of this turn. */
|
|
1054
1141
|
steer: (text) => void steers.push(text),
|
|
@@ -1117,12 +1204,12 @@ async function screen(db, { model, effort, resume }) {
|
|
|
1117
1204
|
ask: (question) => new Promise((resolve) => events.emit('ask', { ...question, resolve })),
|
|
1118
1205
|
});
|
|
1119
1206
|
try {
|
|
1120
|
-
await runUi({ session, events, resume, notify: configured(db, 'chat.notify') !== 'off', motion: configured(db, 'chat.
|
|
1207
|
+
await runUi({ session, events, resume, notify: configured(db, 'chat.notify') !== 'off', motion: configured(db, 'chat.screen') === 'full', plain: configured(db, 'chat.screen') === 'plain' }).waitUntilExit();
|
|
1121
1208
|
// The way back in, said as the screen closes: the command that picks this session up again, and what it cost.
|
|
1122
1209
|
if (session.spoken) {
|
|
1123
1210
|
const s = styles(colourEnabled());
|
|
1124
1211
|
const cost = session.spent();
|
|
1125
|
-
process.stdout.write(
|
|
1212
|
+
process.stdout.write(farewell({ id: shortId(session.sessionId), cost, columns: process.stdout.columns || 80 }, s));
|
|
1126
1213
|
}
|
|
1127
1214
|
} finally {
|
|
1128
1215
|
// Jobs still at work in the background are stopped with the chat, and let go of what they hold before it closes.
|
|
@@ -1133,12 +1220,21 @@ async function screen(db, { model, effort, resume }) {
|
|
|
1133
1220
|
return 0;
|
|
1134
1221
|
}
|
|
1135
1222
|
|
|
1223
|
+
/**
|
|
1224
|
+
* The way back in, said as the screen closes: the command that picks the session up again, and what it cost — two short
|
|
1225
|
+
* lines, each with its margin, folded to the window under it: a narrow one never has them back at the edge.
|
|
1226
|
+
*/
|
|
1227
|
+
export function farewell({ id, cost, columns }, s) {
|
|
1228
|
+
const said = wrap(`picks this session up again${cost >= 0.005 ? ` · it cost $${cost.toFixed(2)}` : ''}`, Math.max(20, columns - 3));
|
|
1229
|
+
return `\n${s.dim(` sumo chat --resume ${id}`)}\n${said.split('\n').map((row) => s.dim(` ${row}`)).join('\n')}\n\n`;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1136
1232
|
/**
|
|
1137
1233
|
* The terminal. With a keyboard and a screen it is the full-screen chat; piped,
|
|
1138
1234
|
* it is plain lines: a header, the prompt with the model in it, the reply
|
|
1139
1235
|
* rendered as it streams, tool lines dim, errors red, a rule between turns.
|
|
1140
1236
|
*/
|
|
1141
|
-
export async function chat(db, { model, effort, resume = null, send, input = process.stdin, output = process.stdout } = {}) {
|
|
1237
|
+
export async function chat(db, { model, effort, resume = null, send, input = process.stdin, output = process.stdout, errors = process.stderr } = {}) {
|
|
1142
1238
|
if (input.isTTY && output.isTTY) return screen(db, { model, effort, resume });
|
|
1143
1239
|
const rl = createInterface({ input, output });
|
|
1144
1240
|
// Every line is a turn. Lines that arrive while one is being answered wait here for theirs; a question would hear only the next.
|
|
@@ -1148,6 +1244,15 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1148
1244
|
// Piped in is not piped out: what the model or a command prints may reach a terminal, and only colour gets through to it.
|
|
1149
1245
|
// A carriage return redraws a progress bar in place; as plain lines each redraw is a line of its own, not run into the next.
|
|
1150
1246
|
const write = (t) => output.write(safeForTerminal(String(t).replace(/\r(?!\n)/g, '\n')));
|
|
1247
|
+
/** Whether a turn failed: the chat then exits 1, so a script that piped into it can tell. */
|
|
1248
|
+
let failed = false;
|
|
1249
|
+
/** A turn that failed, said where failures go — stderr — in the screen's own words, with what to do and what came back under it. */
|
|
1250
|
+
const failure = (message) => {
|
|
1251
|
+
const { text, detail } = explained(message);
|
|
1252
|
+
const e = styles(colourEnabled(errors));
|
|
1253
|
+
errors.write(`${e.red(safeForTerminal(text))}\n${detail ? `${e.dim(` ${safeForTerminal(detail)}`)}\n` : ''}`);
|
|
1254
|
+
failed = true;
|
|
1255
|
+
};
|
|
1151
1256
|
const reply = createRenderer(write, s, { width });
|
|
1152
1257
|
const session = createChat(db, {
|
|
1153
1258
|
model,
|
|
@@ -1161,7 +1266,7 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1161
1266
|
// Piped, nobody answers a question: one of the model's is not asked, an MCP call not on the allow list is refused, and a server that failed is said.
|
|
1162
1267
|
watch: (e) => {
|
|
1163
1268
|
if (e.type === 'retry' && e.job === undefined) return write(`${s.dim(` › ${retryLine(e)}`)}\n`);
|
|
1164
|
-
if (e.type === 'sources') return write(`\n${e.sources.map((page) => s.dim(`
|
|
1269
|
+
if (e.type === 'sources') return write(`\n${e.sources.map((page) => s.dim(` ${safeForTerminal(`${page.title} — ${page.url}`).replace(/\s+/g, ' ')}`)).join('\n')}\n`);
|
|
1165
1270
|
if (e.type !== 'mcp') return;
|
|
1166
1271
|
if (e.error) write(`${s.red(`mcp: ${e.error}`)}\n`);
|
|
1167
1272
|
for (const server of e.servers.filter((x) => !x.ok)) write(`${s.red(`mcp ${server.name}: ${server.error}`)}\n`);
|
|
@@ -1169,7 +1274,7 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1169
1274
|
});
|
|
1170
1275
|
const rule = () => write(`\n${s.dim('─'.repeat(width))}\n\n`);
|
|
1171
1276
|
/** A line under what the user typed, as a tool's result is drawn: what a command did. */
|
|
1172
|
-
const result = (text) => write(`${s.dim(`
|
|
1277
|
+
const result = (text) => write(`${s.dim(` ${text}`)}\n`);
|
|
1173
1278
|
/** The header, then the memory block of a fresh session or the line that says what a resumed one is. */
|
|
1174
1279
|
const show = (block, after = '') => {
|
|
1175
1280
|
write(`${header({ route: routeLine(session), cwd: process.cwd() }, s)}\n\n`);
|
|
@@ -1205,6 +1310,12 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1205
1310
|
show(session.start('new'));
|
|
1206
1311
|
continue;
|
|
1207
1312
|
}
|
|
1313
|
+
if (control === 'handoff') {
|
|
1314
|
+
const handed = await session.handoff();
|
|
1315
|
+
write(`${s.dim(handed.text)}\n\n`);
|
|
1316
|
+
show(handed.block, `handed off from ${handed.from}: the hand-off rides in with your next message`);
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1208
1319
|
if (control === 'resume') {
|
|
1209
1320
|
if (!args) {
|
|
1210
1321
|
const saved = session.saved();
|
|
@@ -1217,7 +1328,7 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1217
1328
|
continue;
|
|
1218
1329
|
}
|
|
1219
1330
|
if (control === 'model' || control === 'memory' || control === 'mcp' || control === 'undo') {
|
|
1220
|
-
result(control === 'model' ? session.route(args) : control === 'undo' ? session.undo() : control === 'mcp' ? (await session.mcp()).join('\n
|
|
1331
|
+
result(control === 'model' ? session.route(args) : control === 'undo' ? session.undo() : control === 'mcp' ? (await session.mcp()).join('\n ') : await session.memoryPage());
|
|
1221
1332
|
continue;
|
|
1222
1333
|
}
|
|
1223
1334
|
if (control === 'context') {
|
|
@@ -1234,8 +1345,8 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1234
1345
|
write('\n');
|
|
1235
1346
|
const outcome = await session.say(text, said, [], { guide });
|
|
1236
1347
|
reply.flush();
|
|
1237
|
-
if (outcome.stop === 'error')
|
|
1238
|
-
if (stopReason(outcome.stop)) write(`\n${s.dim(stopReason(outcome.stop))}\n`);
|
|
1348
|
+
if (outcome.stop === 'error') failure(outcome.error);
|
|
1349
|
+
if (stopReason(outcome.stop)) write(`\n${s.dim(stopReason(outcome.stop, outcome.stopDetail))}\n`);
|
|
1239
1350
|
rule();
|
|
1240
1351
|
} catch (cause) {
|
|
1241
1352
|
reply.flush();
|
|
@@ -1247,5 +1358,5 @@ export async function chat(db, { model, effort, resume = null, send, input = pro
|
|
|
1247
1358
|
rl.close();
|
|
1248
1359
|
await closeMcp();
|
|
1249
1360
|
}
|
|
1250
|
-
return 0;
|
|
1361
|
+
return failed ? 1 : 0;
|
|
1251
1362
|
}
|