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
package/src/tools/file/tools.ts
CHANGED
|
@@ -13,13 +13,19 @@
|
|
|
13
13
|
// writable so the agent can self-edit.
|
|
14
14
|
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
+
import { readFileSync } from 'node:fs';
|
|
17
|
+
import { resolve as resolvePath } from 'node:path';
|
|
18
|
+
import { configPath, validateConfigText } from '../../config/loader.ts';
|
|
16
19
|
import type { ContentBlock } from '../../multimodal/blocks.ts';
|
|
17
20
|
import { resolveVisibleResourceFresh } from '../resources/visibility.ts';
|
|
18
21
|
import type { MultimodalToolResult, ToolContext, ToolDefinition } from '../types.ts';
|
|
19
22
|
import { localList, localPatch, localRead, localSearch, localWrite } from './local.ts';
|
|
20
23
|
import { lspAfterWrite, lspTouch } from './lsp-hook.ts';
|
|
21
24
|
import { WRITE_SCOPE_QUESTION_TIMEOUT_MS } from './write-scope.ts';
|
|
22
|
-
import { remoteList, remotePatch,
|
|
25
|
+
import { remoteFetch, remoteList, remotePatch, remoteSearch, remoteTextResult, remoteWrite } from './remote.ts';
|
|
26
|
+
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
27
|
+
import { tmpdir } from 'node:os';
|
|
28
|
+
import { join } from 'node:path';
|
|
23
29
|
|
|
24
30
|
// ─────────────────────────────────────────────────────────────────────
|
|
25
31
|
// Multimodal helpers for file_read polymorph (image, PDF)
|
|
@@ -32,14 +38,17 @@ async function readImageAsContentBlock(
|
|
|
32
38
|
absolutePath: string,
|
|
33
39
|
mimeType: string,
|
|
34
40
|
ctx: ToolContext,
|
|
41
|
+
/** What the model asked for — a remote file is read via a local temp copy. */
|
|
42
|
+
shown: { label: string; remote: boolean } = { label: absolutePath, remote: false },
|
|
35
43
|
): Promise<MultimodalToolResult> {
|
|
36
44
|
if (!ctx.activeModel || !ctx.activeModel.model.capabilities.includes('image')) {
|
|
37
45
|
throw new Error(
|
|
38
|
-
`file_read: '${
|
|
46
|
+
`file_read: '${shown.label}' is ${mimeType} but the active model ` +
|
|
39
47
|
`${ctx.activeModel ? `'${ctx.activeModel.providerName}/${ctx.activeModel.modelId}'` : '(unknown)'} ` +
|
|
40
|
-
`lacks 'image' capability.
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
`lacks 'image' capability. ` +
|
|
49
|
+
(shown.remote
|
|
50
|
+
? 'analyze_file reads files on this machine only: copy the file here first, then analyze_file it, or switch to a vision-capable model.'
|
|
51
|
+
: `Use analyze_file({path:"${absolutePath}"}) to dispatch to the configured vision worker, or switch to a vision-capable model.`),
|
|
43
52
|
);
|
|
44
53
|
}
|
|
45
54
|
const { loadAttachment } = await import('../../multimodal/load.ts');
|
|
@@ -49,6 +58,7 @@ async function readImageAsContentBlock(
|
|
|
49
58
|
// and dump PNG bytes into the model context (2026-09-05 report).
|
|
50
59
|
const att = await loadAttachment(absolutePath, {
|
|
51
60
|
maxImageBytes: ctx.config.attachments?.maxImageBytes,
|
|
61
|
+
maxImageEdge: ctx.config.attachments?.maxImageEdge,
|
|
52
62
|
});
|
|
53
63
|
return {
|
|
54
64
|
_somoraMultimodal: true,
|
|
@@ -71,10 +81,11 @@ async function readImageAsContentBlock(
|
|
|
71
81
|
async function readPdfAsContentBlocks(
|
|
72
82
|
absolutePath: string,
|
|
73
83
|
ctx: ToolContext,
|
|
84
|
+
shown: { label: string; remote: boolean } = { label: absolutePath, remote: false },
|
|
74
85
|
): Promise<MultimodalToolResult> {
|
|
75
86
|
if (!ctx.activeModel || !ctx.activeModel.model.capabilities.includes('image')) {
|
|
76
87
|
throw new Error(
|
|
77
|
-
`file_read: '${
|
|
88
|
+
`file_read: '${shown.label}' is a PDF but the active model ` +
|
|
78
89
|
`${ctx.activeModel ? `'${ctx.activeModel.providerName}/${ctx.activeModel.modelId}'` : '(unknown)'} ` +
|
|
79
90
|
`lacks 'image' capability (PDFs are rendered to PNG-pages and ` +
|
|
80
91
|
`delivered as images). Use analyze_file({path:"${absolutePath}"}) ` +
|
|
@@ -180,12 +191,14 @@ export const fileRead: ToolDefinition<z.infer<typeof ReadInput>> = {
|
|
|
180
191
|
'Use this INSTEAD of running `cat`, `head`, or `tail` via exec — file_read paginates safely, ' +
|
|
181
192
|
'enforces the read-blacklist, and never gets caught by shell quoting. ' +
|
|
182
193
|
'\n\n' +
|
|
183
|
-
'Multimodal behavior (local files
|
|
184
|
-
' - PNG / JPEG / WebP / GIF → returned as image content block
|
|
194
|
+
'Multimodal behavior (local files and remote resources alike):\n' +
|
|
195
|
+
' - PNG / JPEG / WebP / GIF → returned as image content block, scaled down when its ' +
|
|
196
|
+
'longer side exceeds the configured limit (text stays readable). Active model must ' +
|
|
185
197
|
'have `image` capability; if not, you get an error pointing at `analyze_file`.\n' +
|
|
186
198
|
' - PDF → each page rendered to PNG (max 20 pages by default), returned as ' +
|
|
187
199
|
'image-array. Same `image`-capability gate. Token cost: ~1300 tokens per page on ' +
|
|
188
200
|
'Anthropic models.\n' +
|
|
201
|
+
' - Video / audio → error; extract a frame with ffmpeg via exec and read that.\n' +
|
|
189
202
|
' - Unknown binary → error with a hint to inspect with `exec` first.\n\n' +
|
|
190
203
|
'If your model can see images, look yourself — that is more reliable than a ' +
|
|
191
204
|
'second-hand description. `analyze_file` exists for models that cannot, and is only ' +
|
|
@@ -223,8 +236,7 @@ export const fileRead: ToolDefinition<z.infer<typeof ReadInput>> = {
|
|
|
223
236
|
// - pdf → render pages to PNG, return image-array
|
|
224
237
|
// (MultimodalToolResult). Same capability gate.
|
|
225
238
|
// - unknown → clear error explaining the situation
|
|
226
|
-
// Remote reads
|
|
227
|
-
// round-trip + remote PDF rendering; v2 work.
|
|
239
|
+
// Remote reads do the same after downloading (below).
|
|
228
240
|
// Read policy FIRST, outside the try below: the image/PDF branch
|
|
229
241
|
// returns file content without ever reaching localRead (which has
|
|
230
242
|
// its own check), so an image or PDF under a blocked directory
|
|
@@ -247,6 +259,9 @@ export const fileRead: ToolDefinition<z.infer<typeof ReadInput>> = {
|
|
|
247
259
|
if (mime.kind === 'pdf') {
|
|
248
260
|
return await readPdfAsContentBlocks(absolute, ctx);
|
|
249
261
|
}
|
|
262
|
+
if (mime.kind === 'video' || mime.kind === 'audio') {
|
|
263
|
+
throw new Error(mediaRefusal(input.path, mime.mimeType));
|
|
264
|
+
}
|
|
250
265
|
if (mime.kind === 'unknown') {
|
|
251
266
|
throw new Error(
|
|
252
267
|
`file_read: '${input.path}' has no recognized text or known-binary signature ` +
|
|
@@ -275,17 +290,47 @@ export const fileRead: ToolDefinition<z.infer<typeof ReadInput>> = {
|
|
|
275
290
|
limit: input.limit,
|
|
276
291
|
});
|
|
277
292
|
}
|
|
293
|
+
// Remote: download once, then treat it like a local file of the same
|
|
294
|
+
// kind. A picture or PDF used to come back as its bytes decoded as
|
|
295
|
+
// text — hundreds of thousands of characters of noise in the model's
|
|
296
|
+
// context, and a vision model that could not see it (2026-10-06).
|
|
278
297
|
const resource = await resolveSshTarget({ ctx, target: input.target });
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
298
|
+
const { remotePath, buf } = await remoteFetch({ resourceName: input.target, resource, path: input.path });
|
|
299
|
+
const { detectMimeFromBuffer } = await import('../../multimodal/mime.ts');
|
|
300
|
+
const mime = detectMimeFromBuffer(buf);
|
|
301
|
+
const label = `${input.target}:${remotePath}`;
|
|
302
|
+
if (mime.kind === 'image' || mime.kind === 'pdf') {
|
|
303
|
+
const dir = await mkdtemp(join(tmpdir(), 'somora-remote-read-'));
|
|
304
|
+
const local = join(dir, mime.kind === 'pdf' ? 'file.pdf' : `file.${mime.mimeType.split('/')[1]}`);
|
|
305
|
+
try {
|
|
306
|
+
await writeFile(local, buf);
|
|
307
|
+
return mime.kind === 'image'
|
|
308
|
+
? await readImageAsContentBlock(local, mime.mimeType, ctx, { label, remote: true })
|
|
309
|
+
: await readPdfAsContentBlocks(local, ctx, { label, remote: true });
|
|
310
|
+
} finally {
|
|
311
|
+
await rm(dir, { recursive: true, force: true });
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (mime.kind === 'video' || mime.kind === 'audio') throw new Error(mediaRefusal(label, mime.mimeType));
|
|
315
|
+
if (mime.kind === 'unknown') {
|
|
316
|
+
throw new Error(
|
|
317
|
+
`file_read: '${label}' is a binary file (${mime.mimeType}), not text, an image or a PDF. ` +
|
|
318
|
+
`Inspect it on the remote with exec (e.g. \`file ${remotePath}\`).`,
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
return remoteTextResult(remotePath, buf, input.offset, input.limit);
|
|
286
322
|
},
|
|
287
323
|
};
|
|
288
324
|
|
|
325
|
+
/** file_read shows text, images and PDFs; video and audio have no form
|
|
326
|
+
* a model reads from a file_read result. */
|
|
327
|
+
function mediaRefusal(path: string, mimeType: string): string {
|
|
328
|
+
return (
|
|
329
|
+
`file_read: '${path}' is ${mimeType}. file_read shows text, images and PDFs, not video or audio. ` +
|
|
330
|
+
'For a look at a video, extract frames with exec (e.g. `ffmpeg -ss 12 -i in.mov -frames:v 1 frame.jpg`) and file_read the frame.'
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
289
334
|
// ─────────────────────────────────────────────────────────────────────
|
|
290
335
|
// file_write
|
|
291
336
|
// ─────────────────────────────────────────────────────────────────────
|
|
@@ -353,7 +398,7 @@ export const fileWrite: ToolDefinition<z.infer<typeof WriteInput>> = {
|
|
|
353
398
|
});
|
|
354
399
|
// A builder gets the language server's verdict on the file (docs/lsp.md).
|
|
355
400
|
const lsp = await lspAfterWrite(ctx, result.path);
|
|
356
|
-
return
|
|
401
|
+
return { ...result, ...(lsp ?? {}), ...configCheckAfterWrite(result.path) };
|
|
357
402
|
}
|
|
358
403
|
const resource = await resolveSshTarget({ ctx, target: input.target });
|
|
359
404
|
return remoteWrite({
|
|
@@ -366,6 +411,28 @@ export const fileWrite: ToolDefinition<z.infer<typeof WriteInput>> = {
|
|
|
366
411
|
},
|
|
367
412
|
};
|
|
368
413
|
|
|
414
|
+
/** After a local write to ~/.somora/config.yaml: validate it as the
|
|
415
|
+
* server will. The write stands (an edit may take two steps), but the
|
|
416
|
+
* agent learns right away — the server keeps the last valid version
|
|
417
|
+
* until the file validates again. */
|
|
418
|
+
function configCheckAfterWrite(path: string): { config_invalid?: { issues: string[]; note: string } } {
|
|
419
|
+
if (resolvePath(path) !== resolvePath(configPath())) return {};
|
|
420
|
+
let raw: string;
|
|
421
|
+
try {
|
|
422
|
+
raw = readFileSync(path, 'utf8');
|
|
423
|
+
} catch {
|
|
424
|
+
return {};
|
|
425
|
+
}
|
|
426
|
+
const r = validateConfigText(raw);
|
|
427
|
+
if (r.ok) return {};
|
|
428
|
+
return {
|
|
429
|
+
config_invalid: {
|
|
430
|
+
issues: r.issues.map((i) => `${i.path}: ${i.message}`),
|
|
431
|
+
note: 'config.yaml does not validate. somora keeps running on the last valid version until it does; fix the listed problems and check with `somora config check`.',
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
369
436
|
// ─────────────────────────────────────────────────────────────────────
|
|
370
437
|
// file_patch
|
|
371
438
|
// ─────────────────────────────────────────────────────────────────────
|
|
@@ -431,7 +498,7 @@ export const filePatch: ToolDefinition<z.infer<typeof PatchInput>> = {
|
|
|
431
498
|
replaceAll: input.replace_all,
|
|
432
499
|
});
|
|
433
500
|
const lsp = await lspAfterWrite(ctx, result.path);
|
|
434
|
-
return
|
|
501
|
+
return { ...result, ...(lsp ?? {}), ...configCheckAfterWrite(result.path) };
|
|
435
502
|
}
|
|
436
503
|
const resource = await resolveSshTarget({ ctx, target: input.target });
|
|
437
504
|
return remotePatch({
|
package/src/tools/image/tools.ts
CHANGED
|
@@ -484,6 +484,10 @@ interface ModelRow {
|
|
|
484
484
|
max_n?: number;
|
|
485
485
|
capability_source?: string;
|
|
486
486
|
note?: string;
|
|
487
|
+
/** What the endpoint's catalog says about this model, verbatim. */
|
|
488
|
+
endpoint_note?: string;
|
|
489
|
+
/** The catalog's notes on single parameters, verbatim. */
|
|
490
|
+
param_notes?: Record<string, string>;
|
|
487
491
|
}
|
|
488
492
|
|
|
489
493
|
/**
|
|
@@ -577,6 +581,8 @@ export const imageModels: ToolDefinition<ModelsArgs, { models: ModelRow[] }> = {
|
|
|
577
581
|
}
|
|
578
582
|
if (caps.maxReferences !== undefined) row.max_references = caps.maxReferences;
|
|
579
583
|
if (caps.maxN !== undefined) row.max_n = caps.maxN;
|
|
584
|
+
if (caps.endpointNote) row.endpoint_note = caps.endpointNote;
|
|
585
|
+
if (caps.paramNotes) row.param_notes = caps.paramNotes;
|
|
580
586
|
row.capability_source = caps.source;
|
|
581
587
|
} catch (err) {
|
|
582
588
|
// A catalog outage must not make this tool useless — the
|
package/src/tools/registry.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// Tools are registered once at server boot. Registration is idempotent
|
|
11
11
|
// per name (re-register replaces — useful for dev:server hot reload).
|
|
12
12
|
|
|
13
|
+
import { DEFAULT_MAX_IMAGE_EDGE, fitImageForModel } from '../multimodal/model-image.ts';
|
|
13
14
|
import { isLoopHolder } from '../dream/loop-state.ts';
|
|
14
15
|
import { logger } from '../server/logger.ts';
|
|
15
16
|
import { saveToolOutput } from './tool-output.ts';
|
|
@@ -250,6 +251,18 @@ export class ToolRegistry {
|
|
|
250
251
|
// unhelpfully. Per-modality byte caps are enforced upstream by
|
|
251
252
|
// the loader (`src/multimodal/load.ts`).
|
|
252
253
|
if (isMultimodalToolResult(data)) {
|
|
254
|
+
// Every image a tool hands to a model goes out scaled
|
|
255
|
+
// (attachments.maxImageEdge): file_read, image_generate's
|
|
256
|
+
// review, external MCP tools — whatever produced it.
|
|
257
|
+
const maxEdge = ctx.config?.attachments?.maxImageEdge ?? DEFAULT_MAX_IMAGE_EDGE;
|
|
258
|
+
let scaled = 0;
|
|
259
|
+
for (const block of data.contentBlocks) {
|
|
260
|
+
if (block.type !== 'image' || block.source.kind !== 'base64') continue;
|
|
261
|
+
const fitted = await fitImageForModel(Buffer.from(block.source.data, 'base64'), block.source.mediaType, maxEdge);
|
|
262
|
+
if (!fitted.resized) continue;
|
|
263
|
+
block.source = { kind: 'base64', mediaType: fitted.mimeType, data: fitted.bytes.toString('base64') };
|
|
264
|
+
scaled += 1;
|
|
265
|
+
}
|
|
253
266
|
logger.info({
|
|
254
267
|
msg: 'tool.invoked',
|
|
255
268
|
name,
|
|
@@ -257,6 +270,7 @@ export class ToolRegistry {
|
|
|
257
270
|
ms: Date.now() - start,
|
|
258
271
|
multimodal: true,
|
|
259
272
|
blocks: data.contentBlocks.length,
|
|
273
|
+
...(scaled > 0 ? { images_scaled: scaled } : {}),
|
|
260
274
|
});
|
|
261
275
|
return { ok: true, contentBlocks: data.contentBlocks };
|
|
262
276
|
}
|
package/src/types/events.ts
CHANGED
|
@@ -155,7 +155,17 @@ export type NormalizedEvent =
|
|
|
155
155
|
autoPlayRequested?: boolean;
|
|
156
156
|
}
|
|
157
157
|
| { kind: 'assistant_delta'; ts: number; engine: string; text: string }
|
|
158
|
-
| {
|
|
158
|
+
| {
|
|
159
|
+
kind: 'assistant_message';
|
|
160
|
+
ts: number;
|
|
161
|
+
engine: string;
|
|
162
|
+
/** Everything the model wrote this turn, all rounds — what clients show. */
|
|
163
|
+
text: string;
|
|
164
|
+
/** openai-compatible, turns with tool rounds: the text of the last
|
|
165
|
+
* reply only. The earlier rounds' text is on their tool_call
|
|
166
|
+
* events (`lead`); a rebuilt history uses both. */
|
|
167
|
+
final?: string;
|
|
168
|
+
}
|
|
159
169
|
/**
|
|
160
170
|
* The model's reasoning text, separate from the reply. `thinking_delta`
|
|
161
171
|
* is CUMULATIVE for the turn (like assistant_delta) and never persisted;
|
|
@@ -254,7 +264,18 @@ export type NormalizedEvent =
|
|
|
254
264
|
durationSec?: number;
|
|
255
265
|
}>;
|
|
256
266
|
}
|
|
257
|
-
| {
|
|
267
|
+
| {
|
|
268
|
+
kind: 'tool_call';
|
|
269
|
+
ts: number;
|
|
270
|
+
engine: string;
|
|
271
|
+
callId: string;
|
|
272
|
+
tool: string;
|
|
273
|
+
input: unknown;
|
|
274
|
+
/** openai-compatible: the text the model wrote in the same reply as
|
|
275
|
+
* this call (first call of a round only), so a rebuilt history
|
|
276
|
+
* puts it where it was said instead of after all the work. */
|
|
277
|
+
lead?: string;
|
|
278
|
+
}
|
|
258
279
|
| { kind: 'tool_result'; ts: number; engine: string; callId: string; output: unknown; error?: string }
|
|
259
280
|
// Engine-internal metadata that the agent emits as a side-channel to
|
|
260
281
|
// the conversation. The canonical case is codex-cli's `todo_list`
|