somora 2026.930.1
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/LICENSE +21 -0
- package/README.md +364 -0
- package/bin/node-version.d.mts +3 -0
- package/bin/node-version.mjs +45 -0
- package/bin/somora.mjs +77 -0
- package/config.example.yaml +896 -0
- package/docs/agents.md +677 -0
- package/docs/api.md +3194 -0
- package/docs/browser.md +317 -0
- package/docs/builder.md +331 -0
- package/docs/cache-strategy.md +373 -0
- package/docs/compaction.md +253 -0
- package/docs/display.md +154 -0
- package/docs/dream-phases.md +891 -0
- package/docs/files.md +387 -0
- package/docs/imagegen.md +366 -0
- package/docs/images/somora-hero.png +0 -0
- package/docs/images/somora-mobile-2026-05-23.png +0 -0
- package/docs/images/somora-tui-2026-05-23.png +0 -0
- package/docs/images/somora-web-2026-05-23.png +0 -0
- package/docs/index.md +178 -0
- package/docs/lsp.md +93 -0
- package/docs/mcp.md +332 -0
- package/docs/memory.md +407 -0
- package/docs/mobile.md +310 -0
- package/docs/models.md +379 -0
- package/docs/projects.md +425 -0
- package/docs/realtime-voice.md +293 -0
- package/docs/resources.md +230 -0
- package/docs/sampling.md +128 -0
- package/docs/security.md +189 -0
- package/docs/sentinel.md +295 -0
- package/docs/setup.md +1217 -0
- package/docs/skills.md +501 -0
- package/docs/team.md +189 -0
- package/docs/thinking.md +463 -0
- package/docs/tmux.md +399 -0
- package/docs/tools.md +117 -0
- package/docs/videogen.md +191 -0
- package/docs/voice.md +288 -0
- package/docs/web.md +893 -0
- package/docs/wiki.md +583 -0
- package/npm-shrinkwrap.json +5670 -0
- package/package.json +116 -0
- package/src/attachments/store.ts +196 -0
- package/src/browser/change-stream.ts +31 -0
- package/src/browser/display.ts +108 -0
- package/src/browser/policy.ts +121 -0
- package/src/browser/screencast.ts +374 -0
- package/src/browser/service.ts +1337 -0
- package/src/browser/session.ts +15 -0
- package/src/browser/snapshot.ts +40 -0
- package/src/cli/auth.ts +117 -0
- package/src/cli/codex.ts +41 -0
- package/src/cli/lsp.ts +71 -0
- package/src/cli/resolvers/clawhub.ts +400 -0
- package/src/cli/setup.ts +835 -0
- package/src/cli/skill.ts +619 -0
- package/src/cli/somora.ts +548 -0
- package/src/cli/systemd-unit.ts +72 -0
- package/src/cli/team.ts +148 -0
- package/src/cli/tui/activity-stream.ts +121 -0
- package/src/cli/tui/api.ts +479 -0
- package/src/cli/tui/app.tsx +1169 -0
- package/src/cli/tui/autocomplete.tsx +55 -0
- package/src/cli/tui/commands.ts +913 -0
- package/src/cli/tui/dream-glyphs.ts +22 -0
- package/src/cli/tui/footer.tsx +15 -0
- package/src/cli/tui/format.ts +28 -0
- package/src/cli/tui/header.tsx +279 -0
- package/src/cli/tui/index.tsx +120 -0
- package/src/cli/tui/markdown.tsx +63 -0
- package/src/cli/tui/sampling.ts +162 -0
- package/src/cli/tui/separator.tsx +13 -0
- package/src/cli/tui/state.ts +42 -0
- package/src/cli/tui/stream.ts +330 -0
- package/src/cli/tui/thinking-text.ts +54 -0
- package/src/cli/tui/turn-views.tsx +499 -0
- package/src/cli/tui/types.ts +410 -0
- package/src/cli/tui/work-queue.ts +161 -0
- package/src/cli/update-args.ts +55 -0
- package/src/cli/wiki.ts +406 -0
- package/src/compaction/index.ts +28 -0
- package/src/compaction/midturn.ts +210 -0
- package/src/compaction/policy.ts +154 -0
- package/src/compaction/summarize.ts +691 -0
- package/src/compaction/template.ts +90 -0
- package/src/compaction/types.ts +148 -0
- package/src/config/loader.ts +276 -0
- package/src/config/reload.ts +43 -0
- package/src/config/types.ts +2292 -0
- package/src/dream/deep-actions.ts +324 -0
- package/src/dream/deep-dispatcher.ts +237 -0
- package/src/dream/deep-llm.ts +388 -0
- package/src/dream/deep-prompts.ts +106 -0
- package/src/dream/deep-runner.ts +757 -0
- package/src/dream/deep-skip-cache.ts +199 -0
- package/src/dream/deep-worker.ts +229 -0
- package/src/dream/json-salvage.ts +34 -0
- package/src/dream/judge.ts +188 -0
- package/src/dream/loop-state.ts +286 -0
- package/src/dream/lucid-actions.ts +303 -0
- package/src/dream/lucid-batches.ts +94 -0
- package/src/dream/lucid-prompt.ts +82 -0
- package/src/dream/lucid-runner.ts +744 -0
- package/src/dream/lucid-storage.ts +277 -0
- package/src/dream/lucid-structure.ts +102 -0
- package/src/dream/lucid-types.ts +137 -0
- package/src/dream/lucid-worker.ts +224 -0
- package/src/dream/rem-dedup.ts +502 -0
- package/src/dream/rem-extract.ts +782 -0
- package/src/dream/rem-reset-run.ts +67 -0
- package/src/dream/rem-runner.ts +696 -0
- package/src/dream/rem-worker.ts +527 -0
- package/src/dream/review-window.ts +71 -0
- package/src/dream/scheduler-state.ts +129 -0
- package/src/dream/storage.ts +497 -0
- package/src/dream/types.ts +133 -0
- package/src/dream/wiki-context.ts +133 -0
- package/src/engine/a2a.ts +33 -0
- package/src/engine/availability.ts +63 -0
- package/src/engine/claude-cli.ts +969 -0
- package/src/engine/codex-app-server-client.ts +294 -0
- package/src/engine/codex-bin.ts +49 -0
- package/src/engine/codex-cli.ts +1014 -0
- package/src/engine/codex-dynamic-tools.ts +239 -0
- package/src/engine/codex-home.ts +63 -0
- package/src/engine/codex-thread-config.ts +74 -0
- package/src/engine/context-budget.ts +257 -0
- package/src/engine/engine-meta-labels.ts +211 -0
- package/src/engine/grok-cli.ts +941 -0
- package/src/engine/inline-think.ts +59 -0
- package/src/engine/model-availability.ts +105 -0
- package/src/engine/openai-compatible.ts +2464 -0
- package/src/engine/reasoning-retry.ts +83 -0
- package/src/engine/registry.ts +13 -0
- package/src/engine/replay.ts +195 -0
- package/src/engine/sampling.ts +90 -0
- package/src/engine/thinking-params.ts +264 -0
- package/src/engine/types.ts +269 -0
- package/src/engine/user-tag.ts +24 -0
- package/src/imagegen/aspect.ts +128 -0
- package/src/imagegen/generate.ts +642 -0
- package/src/imagegen/references.ts +75 -0
- package/src/imagegen/types.ts +154 -0
- package/src/lsp/client.ts +183 -0
- package/src/lsp/fake-server.helper.mjs +42 -0
- package/src/lsp/format.ts +29 -0
- package/src/lsp/index.ts +21 -0
- package/src/lsp/manager.ts +238 -0
- package/src/lsp/registry.ts +151 -0
- package/src/mcp/config.ts +117 -0
- package/src/mcp/hub/audit.ts +55 -0
- package/src/mcp/hub/bridge.ts +115 -0
- package/src/mcp/hub/catalog.ts +69 -0
- package/src/mcp/hub/credentials.ts +406 -0
- package/src/mcp/hub/env-expand.ts +14 -0
- package/src/mcp/hub/manager.ts +770 -0
- package/src/mcp/hub/normalize.ts +213 -0
- package/src/mcp/server.ts +368 -0
- package/src/mcp/tool-schema.ts +20 -0
- package/src/media/capabilities.ts +392 -0
- package/src/media/records.ts +175 -0
- package/src/media/store.ts +217 -0
- package/src/media/types.ts +69 -0
- package/src/memory/chunking.ts +168 -0
- package/src/memory/embeddings.ts +262 -0
- package/src/memory/index.ts +15 -0
- package/src/memory/inject.ts +197 -0
- package/src/memory/manager.ts +996 -0
- package/src/memory/registry.ts +176 -0
- package/src/memory/rescan.ts +101 -0
- package/src/memory/retrieval.ts +586 -0
- package/src/memory/shared-index.ts +372 -0
- package/src/memory/slug.ts +39 -0
- package/src/memory/storage.ts +385 -0
- package/src/memory/watcher.ts +134 -0
- package/src/multimodal/blocks.ts +101 -0
- package/src/multimodal/dimensions.ts +214 -0
- package/src/multimodal/load.ts +86 -0
- package/src/multimodal/mime.ts +135 -0
- package/src/multimodal/pdf-render.ts +80 -0
- package/src/multimodal/user-content.ts +266 -0
- package/src/persona/files.ts +144 -0
- package/src/persona/loader.ts +598 -0
- package/src/persona/skill-gating-store.ts +59 -0
- package/src/persona/tool-gating-store.ts +113 -0
- package/src/projects/focus.ts +186 -0
- package/src/projects/prompt-block.ts +106 -0
- package/src/projects/scheme.ts +107 -0
- package/src/projects/store.ts +144 -0
- package/src/projects/types.ts +73 -0
- package/src/sentinel/dispatcher.ts +97 -0
- package/src/sentinel/schedule.ts +271 -0
- package/src/sentinel/scheduler.ts +840 -0
- package/src/sentinel/store.ts +259 -0
- package/src/sentinel/types.ts +221 -0
- package/src/server/activity-stream.ts +160 -0
- package/src/server/ask-calls.ts +137 -0
- package/src/server/ask-wait-graph.ts +171 -0
- package/src/server/async-tasks.ts +199 -0
- package/src/server/builder-busy.ts +86 -0
- package/src/server/builder-prompt.ts +204 -0
- package/src/server/builder-questions.ts +117 -0
- package/src/server/builder-session.ts +249 -0
- package/src/server/chat-aborts.ts +83 -0
- package/src/server/claude-config-dir.ts +71 -0
- package/src/server/claude-credential-sync.ts +454 -0
- package/src/server/env-file.ts +100 -0
- package/src/server/env.ts +115 -0
- package/src/server/heal-session.ts +151 -0
- package/src/server/history-page.ts +46 -0
- package/src/server/index.ts +7244 -0
- package/src/server/lockfile.ts +89 -0
- package/src/server/logger.ts +67 -0
- package/src/server/logs.ts +187 -0
- package/src/server/loopback-fetch.ts +130 -0
- package/src/server/openai-client.ts +89 -0
- package/src/server/prompt-assembly.ts +334 -0
- package/src/server/restart-reconcile.ts +139 -0
- package/src/server/run-turn-fallback.ts +275 -0
- package/src/server/run-turn-types.ts +91 -0
- package/src/server/run-turn.ts +1474 -0
- package/src/server/sanitize-assistant-text.ts +112 -0
- package/src/server/session-export.ts +220 -0
- package/src/server/session-queue.ts +376 -0
- package/src/server/session-workdir.ts +49 -0
- package/src/server/sse-h2-safe.ts +61 -0
- package/src/server/sse-liveness.ts +162 -0
- package/src/server/sse-serializer.ts +161 -0
- package/src/server/start-turn.ts +249 -0
- package/src/server/steer-inbox.ts +107 -0
- package/src/server/tls-keeper.ts +153 -0
- package/src/server/tool-format.ts +167 -0
- package/src/server/turn-framing.ts +52 -0
- package/src/server/turn-origin-kind.ts +74 -0
- package/src/server/turn-origin.ts +40 -0
- package/src/server/work-ledger.ts +975 -0
- package/src/server/workspace.ts +114 -0
- package/src/setup/config-edit.ts +201 -0
- package/src/setup/presets.ts +71 -0
- package/src/setup/prompt.ts +163 -0
- package/src/setup/tailscale.ts +44 -0
- package/src/skills/bin-checks.ts +227 -0
- package/src/skills/bootstrap.ts +347 -0
- package/src/skills/env-scope.ts +175 -0
- package/src/skills/gating.ts +71 -0
- package/src/skills/lint.ts +202 -0
- package/src/skills/load.ts +368 -0
- package/src/skills/path-helpers.ts +102 -0
- package/src/skills/registry.ts +178 -0
- package/src/ssh/exec.ts +142 -0
- package/src/ssh/index.ts +12 -0
- package/src/ssh/known-hosts.ts +109 -0
- package/src/ssh/pool.ts +307 -0
- package/src/storage/sessions.ts +602 -0
- package/src/team/render.ts +149 -0
- package/src/team/resolve.ts +122 -0
- package/src/team/store.ts +124 -0
- package/src/team/types.ts +111 -0
- package/src/team/write.ts +95 -0
- package/src/testing/isolated-home.mts +46 -0
- package/src/tmux/attention-watcher.ts +272 -0
- package/src/tmux/attention.ts +336 -0
- package/src/tmux/list.ts +91 -0
- package/src/tmux/origin-store.ts +102 -0
- package/src/tmux/tui-markers.ts +267 -0
- package/src/tools/agents/ask-cancel.ts +94 -0
- package/src/tools/agents/ask-result.ts +235 -0
- package/src/tools/agents/ask.ts +704 -0
- package/src/tools/agents/builder-dispatch.ts +217 -0
- package/src/tools/agents/images.ts +104 -0
- package/src/tools/agents/index.ts +42 -0
- package/src/tools/agents/long-task-timeouts.ts +39 -0
- package/src/tools/agents/session-list.ts +136 -0
- package/src/tools/agents/session-model.ts +106 -0
- package/src/tools/agents/spawn.ts +845 -0
- package/src/tools/agents/status.ts +589 -0
- package/src/tools/browser/index.ts +6 -0
- package/src/tools/browser/ops.ts +145 -0
- package/src/tools/browser/tools.ts +184 -0
- package/src/tools/builder/short-descriptions.ts +80 -0
- package/src/tools/builder/tools.ts +222 -0
- package/src/tools/docs/index.ts +1 -0
- package/src/tools/docs/tools.ts +228 -0
- package/src/tools/dream/index.ts +11 -0
- package/src/tools/dream/tools.ts +1002 -0
- package/src/tools/exec/allowlist.ts +233 -0
- package/src/tools/exec/background-detach.helper.mts +27 -0
- package/src/tools/exec/blacklist.ts +336 -0
- package/src/tools/exec/concurrency.ts +150 -0
- package/src/tools/exec/fit-output.ts +82 -0
- package/src/tools/exec/index.ts +7 -0
- package/src/tools/exec/internal-env.ts +89 -0
- package/src/tools/exec/job-store.ts +403 -0
- package/src/tools/exec/local.ts +649 -0
- package/src/tools/exec/remote.ts +399 -0
- package/src/tools/exec/tools.ts +934 -0
- package/src/tools/file/analyze.ts +378 -0
- package/src/tools/file/index.ts +2 -0
- package/src/tools/file/local.ts +707 -0
- package/src/tools/file/lsp-hook.ts +72 -0
- package/src/tools/file/persona-guard.ts +61 -0
- package/src/tools/file/policy.ts +292 -0
- package/src/tools/file/read-format.ts +129 -0
- package/src/tools/file/remote.ts +680 -0
- package/src/tools/file/replace.ts +507 -0
- package/src/tools/file/search-window.ts +224 -0
- package/src/tools/file/tools.ts +658 -0
- package/src/tools/file/write-scope.ts +182 -0
- package/src/tools/gating.ts +106 -0
- package/src/tools/image/budget.ts +82 -0
- package/src/tools/image/index.ts +7 -0
- package/src/tools/image/tools.ts +601 -0
- package/src/tools/index.ts +99 -0
- package/src/tools/memory/index.ts +12 -0
- package/src/tools/memory/tools.ts +399 -0
- package/src/tools/projects/index.ts +1 -0
- package/src/tools/projects/tools.ts +643 -0
- package/src/tools/registry.ts +427 -0
- package/src/tools/resources/index.ts +8 -0
- package/src/tools/resources/tools.ts +176 -0
- package/src/tools/resources/visibility.ts +60 -0
- package/src/tools/sentinel/index.ts +1 -0
- package/src/tools/sentinel/tools.ts +592 -0
- package/src/tools/skill/index.ts +4 -0
- package/src/tools/skill/tools.ts +285 -0
- package/src/tools/time/index.ts +5 -0
- package/src/tools/time/tools.ts +123 -0
- package/src/tools/tmux/index.ts +1 -0
- package/src/tools/tmux/local.ts +277 -0
- package/src/tools/tmux/remote.ts +168 -0
- package/src/tools/tmux/tools.ts +1064 -0
- package/src/tools/tool-output.ts +97 -0
- package/src/tools/types.ts +227 -0
- package/src/tools/video/index.ts +1 -0
- package/src/tools/video/tools.ts +425 -0
- package/src/tools/web/fetch.ts +337 -0
- package/src/tools/web/index.ts +4 -0
- package/src/tools/web/tools.ts +186 -0
- package/src/tools/wiki/index.ts +1 -0
- package/src/tools/wiki/tools.ts +445 -0
- package/src/tts/cache-gc.ts +128 -0
- package/src/tts/prepare-for-tts.ts +114 -0
- package/src/tts/service.ts +332 -0
- package/src/types/events.ts +695 -0
- package/src/types/turn-origin.ts +53 -0
- package/src/version.ts +21 -0
- package/src/videogen/dialects.ts +222 -0
- package/src/videogen/generate.ts +484 -0
- package/src/videogen/jobs.ts +178 -0
- package/src/videogen/runner.ts +125 -0
- package/src/videogen/wake.ts +119 -0
- package/src/voice/realtime/call.ts +948 -0
- package/src/voice/realtime/consult.ts +293 -0
- package/src/voice/realtime/fake-provider.ts +134 -0
- package/src/voice/realtime/manager.ts +384 -0
- package/src/voice/realtime/openai-provider.ts +471 -0
- package/src/voice/realtime/persona.ts +227 -0
- package/src/voice/realtime/session-match.ts +116 -0
- package/src/voice/realtime/types.ts +182 -0
- package/src/wiki/conflict.ts +113 -0
- package/src/wiki/explorer.ts +578 -0
- package/src/wiki/index-builder.ts +172 -0
- package/src/wiki/language.ts +134 -0
- package/src/wiki/log-builder.ts +150 -0
- package/src/wiki/map.ts +258 -0
- package/src/wiki/migration/analyze.ts +304 -0
- package/src/wiki/migration/execute.ts +689 -0
- package/src/wiki/migration/refine.ts +402 -0
- package/src/wiki/migration/store.ts +100 -0
- package/src/wiki/move-page.ts +57 -0
- package/src/wiki/structure-file.ts +192 -0
- package/src/wiki/taxonomy.ts +140 -0
- package/src/wiki/templates.ts +163 -0
- package/src/wiki/types.ts +133 -0
- package/templates/skills/README.md +24 -0
- package/templates/skills/_templates/api-wrapper/SKILL.md +26 -0
- package/templates/skills/_templates/cli-wrapper/BOOTSTRAP.md +32 -0
- package/templates/skills/_templates/cli-wrapper/SKILL.md +24 -0
- package/templates/skills/_templates/default/SKILL.md +25 -0
- package/templates/skills/builder-handover/SKILL.md +96 -0
- package/templates/skills/builder-handover/assets/ORDER.md +12 -0
- package/templates/skills/skill-author/SKILL.md +110 -0
- package/tsconfig.json +22 -0
- package/web/dist/assets/index-BaVv6pB2.js +631 -0
- package/web/dist/assets/index-BaVv6pB2.js.map +1 -0
- package/web/dist/assets/index-V3FV3Z25.css +32 -0
- package/web/dist/favicon.svg +8 -0
- package/web/dist/index.html +20 -0
- package/web/package.json +36 -0
- package/web/tsconfig.json +25 -0
- package/web-mobile/dist/apple-touch-icon.png +0 -0
- package/web-mobile/dist/assets/index-BqKt7IMx.css +1 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js +88 -0
- package/web-mobile/dist/assets/index-X_vRr6cd.js.map +1 -0
- package/web-mobile/dist/favicon.svg +8 -0
- package/web-mobile/dist/icon-192.png +0 -0
- package/web-mobile/dist/icon-512.png +0 -0
- package/web-mobile/dist/index.html +27 -0
- package/web-mobile/dist/manifest.webmanifest +32 -0
- package/web-mobile/dist/service-worker.js +90 -0
- package/web-mobile/package.json +28 -0
- package/web-mobile/tsconfig.json +25 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// builder_dispatch — hand a build order to a builder agent in one call.
|
|
2
|
+
//
|
|
3
|
+
// What an orchestrator used to assemble by hand (create a session, pin
|
|
4
|
+
// the project, brief, then poll a terminal) is one tool: a fresh session
|
|
5
|
+
// on the builder, the project pinned (its folder becomes the working
|
|
6
|
+
// directory), the session set to unattended + build, and the order sent
|
|
7
|
+
// as an agent_ask with wait:false — so the caller is woken with the
|
|
8
|
+
// builder's report when it lands, exactly like any other agent answer,
|
|
9
|
+
// and reads it with agent_ask_result. Nothing in between: no interim
|
|
10
|
+
// check-ins, no corrections into running work. A correction is a new
|
|
11
|
+
// message into that session (steer or next turn).
|
|
12
|
+
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { classifyFetchError, loopbackFetch } from '../../server/loopback-fetch.ts';
|
|
15
|
+
import { listAgents, loadPersona } from '../../persona/loader.ts';
|
|
16
|
+
import { projectWorkdir } from '../../projects/focus.ts';
|
|
17
|
+
import type { ToolDefinition } from '../types.ts';
|
|
18
|
+
import { agentAsk } from './ask.ts';
|
|
19
|
+
|
|
20
|
+
const Input = z
|
|
21
|
+
.object({
|
|
22
|
+
builder: z
|
|
23
|
+
.string()
|
|
24
|
+
.min(1)
|
|
25
|
+
.optional()
|
|
26
|
+
.describe('Name of the builder agent (kind: builder). Optional when exactly one builder exists; with several, choose by their team description (the result of a missing name lists them).'),
|
|
27
|
+
task: z
|
|
28
|
+
.string()
|
|
29
|
+
.min(1)
|
|
30
|
+
.describe(
|
|
31
|
+
'The complete order: what to build or change, in which repository, what "done" means, where to write the report. ' +
|
|
32
|
+
'The builder sees nothing of your conversation — give it everything.',
|
|
33
|
+
),
|
|
34
|
+
project: z
|
|
35
|
+
.string()
|
|
36
|
+
.min(1)
|
|
37
|
+
.optional()
|
|
38
|
+
.describe('Project slug to pin on the builder session. A project with `workdir` makes that folder the working directory.'),
|
|
39
|
+
plan_path: z.string().min(1).optional().describe('Absolute path of an already written plan file the builder must read first.'),
|
|
40
|
+
done_criteria: z.string().min(1).optional().describe('What "done" means, e.g. "tests green and the CLI prints the new column". Appended to the order.'),
|
|
41
|
+
report_path: z.string().min(1).optional().describe('Absolute path the builder writes its report to at the end (besides answering).'),
|
|
42
|
+
mode: z
|
|
43
|
+
.enum(['attended', 'unattended'])
|
|
44
|
+
.optional()
|
|
45
|
+
.describe('Default unattended: the builder decides open points itself. attended: it may ask the person via ask_user.'),
|
|
46
|
+
phase: z
|
|
47
|
+
.enum(['plan', 'build'])
|
|
48
|
+
.optional()
|
|
49
|
+
.describe('Default build (the order is complete, go). plan: the builder first reads and writes a plan file, then stops with "Plan ready"; the person presses Go in the task panel (or you send the next message) to start the build.'),
|
|
50
|
+
session: z
|
|
51
|
+
.string()
|
|
52
|
+
.min(1)
|
|
53
|
+
.optional()
|
|
54
|
+
.describe('Slug for the new builder session (default: build-<project or ts>-<rand>).'),
|
|
55
|
+
timeout_ms: z.number().int().min(1_000).max(7_200_000).optional().describe('Passed to agent_ask (wait:false — the wake comes when the report lands).'),
|
|
56
|
+
})
|
|
57
|
+
.strict();
|
|
58
|
+
|
|
59
|
+
function baseUrl(): string {
|
|
60
|
+
const host = process.env.SOMORA_HOST || '127.0.0.1';
|
|
61
|
+
const port = process.env.SOMORA_PORT || '18737';
|
|
62
|
+
const scheme = process.env.SOMORA_TLS === '1' ? 'https' : 'http';
|
|
63
|
+
return `${scheme}://${host}:${port}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function call<T>(method: string, path: string, body: unknown): Promise<T> {
|
|
67
|
+
let res;
|
|
68
|
+
try {
|
|
69
|
+
res = await loopbackFetch(`${baseUrl()}${path}`, {
|
|
70
|
+
method,
|
|
71
|
+
headers: { 'Content-Type': 'application/json' },
|
|
72
|
+
body: JSON.stringify(body),
|
|
73
|
+
});
|
|
74
|
+
} catch (err) {
|
|
75
|
+
const c = classifyFetchError(err);
|
|
76
|
+
throw new Error(`builder_dispatch [${c.category}${c.code ? '/' + c.code : ''}]: ${c.message}`);
|
|
77
|
+
}
|
|
78
|
+
const data = (await res.json().catch(() => ({}))) as T & { error?: string };
|
|
79
|
+
if (!res.ok) throw new Error(`builder_dispatch: ${data.error ?? `HTTP ${res.status}`}`);
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function get<T>(path: string): Promise<T> {
|
|
84
|
+
let res;
|
|
85
|
+
try {
|
|
86
|
+
res = await loopbackFetch(`${baseUrl()}${path}`);
|
|
87
|
+
} catch (err) {
|
|
88
|
+
const c = classifyFetchError(err);
|
|
89
|
+
throw new Error(`builder_dispatch [${c.category}${c.code ? '/' + c.code : ''}]: ${c.message}`);
|
|
90
|
+
}
|
|
91
|
+
const data = (await res.json().catch(() => ({}))) as T & { error?: string };
|
|
92
|
+
if (!res.ok) throw new Error(`builder_dispatch: ${data.error ?? `HTTP ${res.status}`}`);
|
|
93
|
+
return data;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The builder to use: the named one, or the only one there is. With
|
|
97
|
+
* several and no name, the error lists them so the caller can choose. */
|
|
98
|
+
export async function resolveBuilderName(named: string | undefined): Promise<string> {
|
|
99
|
+
if (named) return named;
|
|
100
|
+
const builders = (await listAgents()).filter((a) => a.kind === 'builder');
|
|
101
|
+
if (builders.length === 1) return builders[0]!.name;
|
|
102
|
+
if (builders.length === 0) throw new Error('builder_dispatch: no builder agent exists (an agent with kind: builder in its agent.yaml)');
|
|
103
|
+
const list = builders.map((b) => `${b.name}${b.role ? ` (${b.role})` : ''}: ${b.description.split('\n')[0]?.slice(0, 120) ?? ''}`).join('; ');
|
|
104
|
+
throw new Error(`builder_dispatch: several builders exist — name one in \`builder\`, chosen by its team description: ${list}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function composeBuildOrder(input: { task: string; plan_path?: string; done_criteria?: string; report_path?: string; phase?: 'plan' | 'build' }): string {
|
|
108
|
+
const parts: string[] = [];
|
|
109
|
+
if (input.phase === 'plan') {
|
|
110
|
+
parts.push(input.task.trim());
|
|
111
|
+
if (input.done_criteria) parts.push(`Done means: ${input.done_criteria.trim()}`);
|
|
112
|
+
parts.push(
|
|
113
|
+
'Plan first: read the repository and write the plan with plan_write (goal, steps in order, files to touch, how to verify, open risks). ' +
|
|
114
|
+
'Do not change any file yet. When the plan is complete say "Plan ready" and stop; the build starts with Go.' +
|
|
115
|
+
(input.report_path ? ` The report at the end goes to ${input.report_path}.` : ''),
|
|
116
|
+
);
|
|
117
|
+
return parts.join('\n\n');
|
|
118
|
+
}
|
|
119
|
+
if (input.plan_path) parts.push(`Read the plan at ${input.plan_path} first and follow it.`);
|
|
120
|
+
parts.push(input.task.trim());
|
|
121
|
+
if (input.done_criteria) parts.push(`Done means: ${input.done_criteria.trim()}`);
|
|
122
|
+
if (input.report_path) parts.push(`At the end write your report to ${input.report_path} with file_write, and give the same report as your answer.`);
|
|
123
|
+
parts.push('Decide open questions yourself and list every decision in the report. Do not stop for approval.');
|
|
124
|
+
return parts.join('\n\n');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const builderDispatch: ToolDefinition<z.infer<typeof Input>> = {
|
|
128
|
+
name: 'builder_dispatch',
|
|
129
|
+
toolset: 'agents',
|
|
130
|
+
description:
|
|
131
|
+
'Hand a build order to a builder agent (kind: builder) in one call: creates a fresh session on it, pins the ' +
|
|
132
|
+
'project (its folder becomes the working directory), sets the session to unattended + build, and sends the ' +
|
|
133
|
+
'order. Returns at once with a call_id; you are woken with the builder\'s report when it is done (read it with ' +
|
|
134
|
+
'agent_ask_result). Give the COMPLETE order — repository or project, what to build, what done means, where the ' +
|
|
135
|
+
'report goes; the builder sees nothing of this conversation. Do not check in on it or send corrections into ' +
|
|
136
|
+
'running work: wait for the report, then send a new message into that session if something must change. ' +
|
|
137
|
+
'One builder per project folder at a time: a folder another builder is working in is refused (wait for that report). ' +
|
|
138
|
+
'Several builders: choose by their team description; two orders to different folders may run at the same time.',
|
|
139
|
+
inputSchema: Input,
|
|
140
|
+
jsonSchema: {
|
|
141
|
+
type: 'object',
|
|
142
|
+
properties: {
|
|
143
|
+
builder: { type: 'string', description: 'Builder agent name (kind: builder). Optional when exactly one builder exists.' },
|
|
144
|
+
task: { type: 'string', description: 'The complete order — everything the builder needs.' },
|
|
145
|
+
project: { type: 'string', description: 'Project slug to pin (its `workdir` becomes the working directory).' },
|
|
146
|
+
plan_path: { type: 'string', description: 'Absolute path of a plan file to read first.' },
|
|
147
|
+
done_criteria: { type: 'string', description: 'What "done" means.' },
|
|
148
|
+
report_path: { type: 'string', description: 'Absolute path for the written report.' },
|
|
149
|
+
mode: { type: 'string', enum: ['attended', 'unattended'], description: 'Default unattended.' },
|
|
150
|
+
phase: { type: 'string', enum: ['plan', 'build'], description: 'Default build. plan = plan first, then wait for Go.' },
|
|
151
|
+
session: { type: 'string', description: 'Slug for the new builder session.' },
|
|
152
|
+
timeout_ms: { type: 'integer', description: 'Passed to agent_ask.' },
|
|
153
|
+
},
|
|
154
|
+
required: ['task'],
|
|
155
|
+
additionalProperties: false,
|
|
156
|
+
},
|
|
157
|
+
defaultTimeoutMs: 60_000,
|
|
158
|
+
async handler(input, ctx) {
|
|
159
|
+
const builderName = await resolveBuilderName(input.builder);
|
|
160
|
+
const persona = await loadPersona(builderName);
|
|
161
|
+
if (!persona) throw new Error(`builder_dispatch: agent '${builderName}' not found`);
|
|
162
|
+
if (persona.kind !== 'builder') {
|
|
163
|
+
throw new Error(`builder_dispatch: '${builderName}' is a ${persona.kind} agent, not a builder — use agent_ask for it`);
|
|
164
|
+
}
|
|
165
|
+
// One builder per folder: a project whose folder another builder is
|
|
166
|
+
// working in right now is refused before anything is created.
|
|
167
|
+
if (input.project) {
|
|
168
|
+
const folder = await projectWorkdir(input.project);
|
|
169
|
+
if (folder) {
|
|
170
|
+
const q = await get<{ busy: { agent: string; session: string; reason: string } | null }>(`/builders/busy?workdir=${encodeURIComponent(folder)}`);
|
|
171
|
+
if (q.busy) throw new Error(`builder_dispatch: folder busy — ${q.busy.reason}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const rand = Math.random().toString(36).slice(2, 6);
|
|
175
|
+
const slug = (input.session ?? `build-${input.project ?? new Date().toISOString().slice(0, 10)}-${rand}`).replace(/[^A-Za-z0-9_-]/g, '-');
|
|
176
|
+
const b = encodeURIComponent(builderName);
|
|
177
|
+
const created = await call<{ id: string }>('POST', `/agents/${b}/sessions`, { slug });
|
|
178
|
+
const sid = encodeURIComponent(created.id);
|
|
179
|
+
if (input.project) {
|
|
180
|
+
await call('POST', `/agents/${b}/sessions/${sid}/project`, { slug: input.project });
|
|
181
|
+
}
|
|
182
|
+
const phase = input.phase ?? 'build';
|
|
183
|
+
await call('PATCH', `/agents/${b}/sessions/${sid}/builder`, {
|
|
184
|
+
mode: input.mode ?? 'unattended',
|
|
185
|
+
phase,
|
|
186
|
+
...(input.plan_path ? { planPath: input.plan_path } : {}),
|
|
187
|
+
// Go (after a plan phase) wakes this agent with the report.
|
|
188
|
+
orderer: { agent: ctx.agent, ...(ctx.session ? { session: ctx.session } : {}) },
|
|
189
|
+
});
|
|
190
|
+
const order = composeBuildOrder({ ...input, phase });
|
|
191
|
+
const ask = await agentAsk.handler(
|
|
192
|
+
{
|
|
193
|
+
agent: builderName,
|
|
194
|
+
message: order,
|
|
195
|
+
session: created.id,
|
|
196
|
+
wait: false,
|
|
197
|
+
...(input.timeout_ms ? { timeout_ms: input.timeout_ms } : {}),
|
|
198
|
+
} as Parameters<typeof agentAsk.handler>[0],
|
|
199
|
+
ctx,
|
|
200
|
+
);
|
|
201
|
+
return {
|
|
202
|
+
ok: true,
|
|
203
|
+
builder: builderName,
|
|
204
|
+
session: created.id,
|
|
205
|
+
slug,
|
|
206
|
+
...(input.project ? { project: input.project } : {}),
|
|
207
|
+
mode: input.mode ?? 'unattended',
|
|
208
|
+
phase,
|
|
209
|
+
dispatch: ask,
|
|
210
|
+
note:
|
|
211
|
+
phase === 'plan'
|
|
212
|
+
? 'The builder plans in its own session and stops with "Plan ready" — you are woken with the plan ([agent answer]). Then the person presses Go in the task panel, or you send the next message into that session (POST …/builder/go starts the build).'
|
|
213
|
+
: 'The builder works in its own session; you will be woken with its report ([agent answer]). ' +
|
|
214
|
+
'Read it with agent_ask_result(call_id). Corrections go as a new message into that session.',
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Hand a picture to another agent.
|
|
2
|
+
//
|
|
3
|
+
// An agent has file PATHS, not upload hashes: `image_generate` returns
|
|
4
|
+
// a path, the browser's screenshot returns a path, a file listing
|
|
5
|
+
// returns paths. Until 2026-09-11 there was no way to get any of them
|
|
6
|
+
// into another agent's turn — `agent_ask` and `spawn_subagent` carried
|
|
7
|
+
// text only, so an orchestrator handing a graphic to a co-worker could
|
|
8
|
+
// only mention where it lies, and a path is just text to a model that
|
|
9
|
+
// can see. Rene, on whether agents need this: "es könnte schon
|
|
10
|
+
// passieren das ein agent im A2A ein bild einem anderen agenten
|
|
11
|
+
// schickt zum weiterverarbeiten … besonders bei grösseren tasks wo
|
|
12
|
+
// einer der orchestrator war".
|
|
13
|
+
//
|
|
14
|
+
// The bytes travel the same route a browser client uses: POST
|
|
15
|
+
// /attachments (raw body, name in a header), then the returned ref on
|
|
16
|
+
// the send. Going through the server rather than reading the file here
|
|
17
|
+
// is what makes this work from an MCP tool child too, which has no
|
|
18
|
+
// attachment store of its own.
|
|
19
|
+
|
|
20
|
+
import { createReadStream, statSync } from 'node:fs';
|
|
21
|
+
import { basename, isAbsolute } from 'node:path';
|
|
22
|
+
import { Readable } from 'node:stream';
|
|
23
|
+
import { loopbackFetch } from '../../server/loopback-fetch.ts';
|
|
24
|
+
|
|
25
|
+
/** The ref shape POST /attachments returns and the send routes take. */
|
|
26
|
+
export interface AttachmentRef {
|
|
27
|
+
hash: string;
|
|
28
|
+
name: string;
|
|
29
|
+
mime: string;
|
|
30
|
+
kind: string;
|
|
31
|
+
size: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Same cap as a chat turn's attachments — `config.attachments.maxPerTurn`
|
|
35
|
+
* is enforced server-side; this one keeps a bad loop from uploading
|
|
36
|
+
* fifty files before the turn is refused. */
|
|
37
|
+
export const MAX_IMAGES_PER_MESSAGE = 8;
|
|
38
|
+
|
|
39
|
+
export const IMAGES_FIELD_DESCRIPTION =
|
|
40
|
+
'Absolute paths of images (or PDFs) to attach to this message, e.g. a picture you just ' +
|
|
41
|
+
'generated. The target agent SEES them; a target whose model has no vision gets the ' +
|
|
42
|
+
"vision worker's description instead. Use this instead of naming a path in the text — a " +
|
|
43
|
+
'path is just text to a model. Max ' +
|
|
44
|
+
MAX_IMAGES_PER_MESSAGE +
|
|
45
|
+
' per message.';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Upload local files and return their refs, in the given order.
|
|
49
|
+
*
|
|
50
|
+
* Throws with a message the model can act on: a wrong path, a
|
|
51
|
+
* directory, an empty file or a server-side refusal (size caps, unknown
|
|
52
|
+
* type) are all things it can fix by passing a different path.
|
|
53
|
+
*/
|
|
54
|
+
export async function uploadLocalAttachments(
|
|
55
|
+
paths: readonly string[],
|
|
56
|
+
base: string,
|
|
57
|
+
): Promise<AttachmentRef[]> {
|
|
58
|
+
if (paths.length > MAX_IMAGES_PER_MESSAGE) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`${paths.length} images exceed the per-message cap of ${MAX_IMAGES_PER_MESSAGE} — send fewer, or send them in several messages`,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const refs: AttachmentRef[] = [];
|
|
64
|
+
for (const p of paths) {
|
|
65
|
+
if (!isAbsolute(p)) {
|
|
66
|
+
throw new Error(`image path must be absolute: ${p}`);
|
|
67
|
+
}
|
|
68
|
+
let size: number;
|
|
69
|
+
try {
|
|
70
|
+
const st = statSync(p);
|
|
71
|
+
if (st.isDirectory()) throw new Error('is a directory');
|
|
72
|
+
size = st.size;
|
|
73
|
+
} catch (err) {
|
|
74
|
+
throw new Error(`cannot read image ${p}: ${(err as Error).message}`);
|
|
75
|
+
}
|
|
76
|
+
if (size === 0) throw new Error(`image ${p} is empty`);
|
|
77
|
+
const res = await loopbackFetch(`${base}/attachments`, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
headers: {
|
|
80
|
+
// The store sniffs magic bytes anyway — extensions lie — so an
|
|
81
|
+
// honest generic type here beats a guess from the suffix.
|
|
82
|
+
'Content-Type': 'application/octet-stream',
|
|
83
|
+
'X-Somora-Filename': encodeURIComponent(basename(p)),
|
|
84
|
+
},
|
|
85
|
+
// Node's fetch needs duplex for a streamed body; the file never
|
|
86
|
+
// sits in memory as one buffer.
|
|
87
|
+
body: Readable.toWeb(createReadStream(p)) as unknown as BodyInit,
|
|
88
|
+
duplex: 'half',
|
|
89
|
+
} as RequestInit);
|
|
90
|
+
if (!res.ok) {
|
|
91
|
+
const detail = await res.text().catch(() => '');
|
|
92
|
+
let msg = detail.slice(0, 300);
|
|
93
|
+
try {
|
|
94
|
+
const parsed = JSON.parse(detail) as { error?: string };
|
|
95
|
+
if (parsed.error) msg = parsed.error;
|
|
96
|
+
} catch {
|
|
97
|
+
/* not JSON, keep raw */
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`upload of ${p} failed (HTTP ${res.status}): ${msg}`);
|
|
100
|
+
}
|
|
101
|
+
refs.push((await res.json()) as AttachmentRef);
|
|
102
|
+
}
|
|
103
|
+
return refs;
|
|
104
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// A2A tool bundle.
|
|
2
|
+
// Modus 1 (sealed-task delegation, fresh sub-session):
|
|
3
|
+
// spawn_subagent / spawn_subagents / subagent_status /
|
|
4
|
+
// subagent_result / subagent_list — Phase 6b
|
|
5
|
+
// Modus 2 (live messaging into target's existing session):
|
|
6
|
+
// agent_ask — Phase 6c
|
|
7
|
+
// Orientation: session_list — which chat sessions exist, what runs
|
|
8
|
+
|
|
9
|
+
import { agentAsk } from './ask.ts';
|
|
10
|
+
import { agentAskResult } from './ask-result.ts';
|
|
11
|
+
import { agentAskCancel } from './ask-cancel.ts';
|
|
12
|
+
import { sessionList } from './session-list.ts';
|
|
13
|
+
import { sessionModel } from './session-model.ts';
|
|
14
|
+
import { spawnSubagent, spawnSubagents } from './spawn.ts';
|
|
15
|
+
import { subagentCancel, subagentList, subagentResult, subagentStatus } from './status.ts';
|
|
16
|
+
import { builderDispatch } from './builder-dispatch.ts';
|
|
17
|
+
import type { ToolDefinition } from '../types.ts';
|
|
18
|
+
|
|
19
|
+
export { agentAsk } from './ask.ts';
|
|
20
|
+
export { agentAskResult } from './ask-result.ts';
|
|
21
|
+
export { agentAskCancel } from './ask-cancel.ts';
|
|
22
|
+
export { sessionList } from './session-list.ts';
|
|
23
|
+
export { sessionModel } from './session-model.ts';
|
|
24
|
+
export { configureSpawnTools, spawnSubagent, spawnSubagents } from './spawn.ts';
|
|
25
|
+
export { subagentCancel, subagentList, subagentResult, subagentStatus } from './status.ts';
|
|
26
|
+
|
|
27
|
+
export function agentTools(): ToolDefinition[] {
|
|
28
|
+
return [
|
|
29
|
+
spawnSubagent,
|
|
30
|
+
spawnSubagents,
|
|
31
|
+
subagentStatus,
|
|
32
|
+
subagentResult,
|
|
33
|
+
subagentList,
|
|
34
|
+
subagentCancel,
|
|
35
|
+
agentAsk,
|
|
36
|
+
agentAskResult,
|
|
37
|
+
agentAskCancel,
|
|
38
|
+
sessionList,
|
|
39
|
+
sessionModel,
|
|
40
|
+
builderDispatch,
|
|
41
|
+
] as ToolDefinition[];
|
|
42
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Module-level cache of the long-task timeout knobs from
|
|
2
|
+
// config.agentLoop.{longTaskDefaultTimeoutMs,longTaskMaxTimeoutMs}.
|
|
3
|
+
//
|
|
4
|
+
// Why module-level: ToolDefinition.timeoutFromInput / maxTimeoutMs are
|
|
5
|
+
// evaluated by the engine without a ToolContext (the engine doesn't carry
|
|
6
|
+
// config into the per-call timeout resolver — see openai-compatible.ts
|
|
7
|
+
// ~line 427). Plumbing config into that signature would touch every
|
|
8
|
+
// engine adapter; a small module-level cache, populated at server boot
|
|
9
|
+
// the same way configureSpawnTools is, keeps the change local.
|
|
10
|
+
//
|
|
11
|
+
// Fallbacks below match the schema defaults so an MCP child that boots
|
|
12
|
+
// before configure() runs (or in test code that skips boot wiring)
|
|
13
|
+
// still gets sensible numbers instead of NaN.
|
|
14
|
+
|
|
15
|
+
import type { Config } from '../../config/types.ts';
|
|
16
|
+
|
|
17
|
+
const FALLBACK_DEFAULT_MS = 300_000; // 5 min
|
|
18
|
+
const FALLBACK_MAX_MS = 1_800_000; // 30 min
|
|
19
|
+
|
|
20
|
+
let cachedDefault = FALLBACK_DEFAULT_MS;
|
|
21
|
+
let cachedMax = FALLBACK_MAX_MS;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Called once at server boot (and at MCP-child boot) with the loaded
|
|
25
|
+
* config. Subsequent reads via longTaskDefaultMs/longTaskMaxMs return
|
|
26
|
+
* the configured values.
|
|
27
|
+
*/
|
|
28
|
+
export function configureLongTaskTimeouts(config: Config): void {
|
|
29
|
+
cachedDefault = config.agentLoop.longTaskDefaultTimeoutMs;
|
|
30
|
+
cachedMax = config.agentLoop.longTaskMaxTimeoutMs;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function longTaskDefaultMs(): number {
|
|
34
|
+
return cachedDefault;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function longTaskMaxMs(): number {
|
|
38
|
+
return cachedMax;
|
|
39
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// session_list — which chat sessions exist, and is anything running?
|
|
2
|
+
//
|
|
3
|
+
// Agents had no way to see somora's chat sessions — their own or a
|
|
4
|
+
// colleague's. Asked on a call "which sessions do you have open?", one
|
|
5
|
+
// answered with its tmux sessions, then fell back to raw curl against
|
|
6
|
+
// the internal API (report 2026-09-16). It is also what makes
|
|
7
|
+
// agent_ask({session}) and sentinel dispatch usable: you can only name
|
|
8
|
+
// a session you can find.
|
|
9
|
+
//
|
|
10
|
+
// Read-only on purpose. Archiving or opening sessions for someone else
|
|
11
|
+
// is a different decision (who confirms it, who sees it) and not part
|
|
12
|
+
// of this tool.
|
|
13
|
+
//
|
|
14
|
+
// Goes through HTTP because "is a turn running" lives in the main
|
|
15
|
+
// server process; claude-cli/codex-cli run tools in an MCP child that
|
|
16
|
+
// cannot see it.
|
|
17
|
+
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { classifyFetchError, loopbackFetch } from '../../server/loopback-fetch.ts';
|
|
20
|
+
import type { ToolDefinition } from '../types.ts';
|
|
21
|
+
|
|
22
|
+
const Input = z
|
|
23
|
+
.object({
|
|
24
|
+
agent: z.string().min(1).optional().describe('Whose sessions. Default: your own. "*" = every agent.'),
|
|
25
|
+
include_archived: z.boolean().optional().describe('Include archived sessions. Default false.'),
|
|
26
|
+
limit: z.number().int().min(1).max(200).optional().describe('Max rows, most recently active first. Default 30.'),
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
|
|
30
|
+
interface SessionRow {
|
|
31
|
+
agent: string;
|
|
32
|
+
session: string;
|
|
33
|
+
id: string;
|
|
34
|
+
is_main: boolean;
|
|
35
|
+
is_current?: true;
|
|
36
|
+
archived?: true;
|
|
37
|
+
last_activity: string | null;
|
|
38
|
+
messages: number;
|
|
39
|
+
running: boolean;
|
|
40
|
+
queued: number;
|
|
41
|
+
project?: string;
|
|
42
|
+
engine?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface SessionListResult {
|
|
46
|
+
count: number;
|
|
47
|
+
total: number;
|
|
48
|
+
sessions: SessionRow[];
|
|
49
|
+
hint?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const sessionList: ToolDefinition<z.infer<typeof Input>, SessionListResult> = {
|
|
53
|
+
name: 'session_list',
|
|
54
|
+
toolset: 'agents',
|
|
55
|
+
description:
|
|
56
|
+
'List somora CHAT sessions — yours by default, another agent\'s with `agent`, everyone\'s with ' +
|
|
57
|
+
'agent:"*". "Session" here is a somora conversation (what the web Sessions window shows), not a ' +
|
|
58
|
+
'tmux session. Each row: session name (use it as `session` in agent_ask or sentinel dispatch), ' +
|
|
59
|
+
'last activity, message count, the pinned project, and whether a turn is running there right now ' +
|
|
60
|
+
'(`running`) with how many wait behind it (`queued`). Your current session is marked ' +
|
|
61
|
+
'`is_current`. Read-only. Use it for "which sessions do you have?", "is anything still running ' +
|
|
62
|
+
'at <agent>?", and before addressing a session by name.',
|
|
63
|
+
inputSchema: Input,
|
|
64
|
+
jsonSchema: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
properties: {
|
|
67
|
+
agent: { type: 'string', description: 'Whose sessions. Default: your own. "*" = every agent.' },
|
|
68
|
+
include_archived: { type: 'boolean', description: 'Include archived sessions. Default false.' },
|
|
69
|
+
limit: { type: 'integer', minimum: 1, maximum: 200, description: 'Max rows, most recently active first. Default 30.' },
|
|
70
|
+
},
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
},
|
|
73
|
+
defaultTimeoutMs: 15_000,
|
|
74
|
+
async handler(input, ctx): Promise<SessionListResult> {
|
|
75
|
+
const host = process.env.SOMORA_HOST || '127.0.0.1';
|
|
76
|
+
const port = process.env.SOMORA_PORT || '18737';
|
|
77
|
+
const scheme = process.env.SOMORA_TLS === '1' ? 'https' : 'http';
|
|
78
|
+
const url = `${scheme}://${host}:${port}/sessions${input.include_archived ? '?include_archived=true' : ''}`;
|
|
79
|
+
let res;
|
|
80
|
+
try {
|
|
81
|
+
res = await loopbackFetch(url, { method: 'GET' });
|
|
82
|
+
} catch (err) {
|
|
83
|
+
const c = classifyFetchError(err);
|
|
84
|
+
throw new Error(`session_list [${c.category}${c.code ? '/' + c.code : ''}]: ${c.message}`);
|
|
85
|
+
}
|
|
86
|
+
if (!res.ok) throw new Error(`session_list: server returned HTTP ${res.status}`);
|
|
87
|
+
const body = (await res.json()) as { sessions?: Array<Record<string, unknown>> };
|
|
88
|
+
return shapeSessionList(body.sessions ?? [], { ...input, self: ctx.agent, currentSession: ctx.session });
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/** Filter, order and trim the server rows. Exported for tests. */
|
|
93
|
+
export function shapeSessionList(
|
|
94
|
+
rows: Array<Record<string, unknown>>,
|
|
95
|
+
opts: { agent?: string; limit?: number; self: string; currentSession?: string },
|
|
96
|
+
): SessionListResult {
|
|
97
|
+
const who = opts.agent ?? opts.self;
|
|
98
|
+
const mine = rows.filter((r) => who === '*' || r.agent === who);
|
|
99
|
+
const known = new Set(rows.map((r) => String(r.agent)));
|
|
100
|
+
if (who !== '*' && mine.length === 0 && !known.has(who)) {
|
|
101
|
+
return {
|
|
102
|
+
count: 0,
|
|
103
|
+
total: 0,
|
|
104
|
+
sessions: [],
|
|
105
|
+
hint: `No sessions found for '${who}'. Agents with sessions: ${[...known].sort().join(', ') || '(none)'}.`,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
const ts = (r: Record<string, unknown>): number => (typeof r.lastActivity === 'string' ? Date.parse(r.lastActivity) || 0 : 0);
|
|
109
|
+
// Running first — that is usually the question — then most recent.
|
|
110
|
+
mine.sort((a, b) => Number(Boolean(b.busy)) - Number(Boolean(a.busy)) || ts(b) - ts(a));
|
|
111
|
+
const limit = opts.limit ?? 30;
|
|
112
|
+
const sessions = mine.slice(0, limit).map((r): SessionRow => {
|
|
113
|
+
const id = String(r.sessionId);
|
|
114
|
+
const slug = typeof r.slug === 'string' && r.slug.length > 0 ? r.slug : id;
|
|
115
|
+
return {
|
|
116
|
+
agent: String(r.agent),
|
|
117
|
+
session: slug,
|
|
118
|
+
id,
|
|
119
|
+
is_main: r.isMain === true,
|
|
120
|
+
...(r.agent === opts.self && opts.currentSession !== undefined && id === opts.currentSession ? { is_current: true as const } : {}),
|
|
121
|
+
...(r.isArchived === true ? { archived: true as const } : {}),
|
|
122
|
+
last_activity: typeof r.lastActivity === 'string' ? r.lastActivity : null,
|
|
123
|
+
messages: typeof r.messageCount === 'number' ? r.messageCount : 0,
|
|
124
|
+
running: r.busy === true,
|
|
125
|
+
queued: typeof r.queueLength === 'number' ? r.queueLength : 0,
|
|
126
|
+
...(typeof r.projectSlug === 'string' ? { project: r.projectSlug } : {}),
|
|
127
|
+
...(typeof r.engine === 'string' ? { engine: r.engine } : {}),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
count: sessions.length,
|
|
132
|
+
total: mine.length,
|
|
133
|
+
sessions,
|
|
134
|
+
...(mine.length > sessions.length ? { hint: `${mine.length - sessions.length} more not shown — raise limit.` } : {}),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// session_model — switch the model of a session that already exists.
|
|
2
|
+
//
|
|
3
|
+
// Until 2026-09-21 only a person could do that: agent_ask takes `model`
|
|
4
|
+
// for a session it CREATES and refuses it for an existing one ("the
|
|
5
|
+
// model of a running session is the user's call"). Rene lifted that:
|
|
6
|
+
// an orchestrator that sees a colleague's session struggling on a small
|
|
7
|
+
// model should be able to move it. What stays is that it never happens
|
|
8
|
+
// silently — the server writes a row into the affected conversation
|
|
9
|
+
// saying who switched to what, every open client updates its header,
|
|
10
|
+
// and the running turn is not touched (the next turn uses the new
|
|
11
|
+
// model).
|
|
12
|
+
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { classifyFetchError, loopbackFetch } from '../../server/loopback-fetch.ts';
|
|
15
|
+
import type { ToolDefinition } from '../types.ts';
|
|
16
|
+
|
|
17
|
+
const Input = z
|
|
18
|
+
.object({
|
|
19
|
+
model: z.string().min(1).optional().describe('Model alias or provider/id. Omit together with clear:true.'),
|
|
20
|
+
clear: z.boolean().optional().describe('true = remove the override; the persona default applies again.'),
|
|
21
|
+
agent: z.string().min(1).optional().describe('Whose session. Default: you.'),
|
|
22
|
+
session: z.string().min(1).optional().describe('Session slug or id. Default for your own agent: the session you are in. Required for another agent.'),
|
|
23
|
+
})
|
|
24
|
+
.strict();
|
|
25
|
+
|
|
26
|
+
interface SessionModelResult {
|
|
27
|
+
ok: boolean;
|
|
28
|
+
agent: string;
|
|
29
|
+
session: string;
|
|
30
|
+
model: string | null;
|
|
31
|
+
resolved?: string;
|
|
32
|
+
takes_effect: 'next turn';
|
|
33
|
+
note: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const sessionModel: ToolDefinition<z.infer<typeof Input>, SessionModelResult> = {
|
|
37
|
+
name: 'session_model',
|
|
38
|
+
toolset: 'agents',
|
|
39
|
+
description:
|
|
40
|
+
'Switch the model of an EXISTING somora chat session — your own (default: the session you are in) or ' +
|
|
41
|
+
'another agent\'s (name `agent` and `session`; find sessions with session_list). Use it when the user ' +
|
|
42
|
+
'asks for it ("stell hans\' Projekt-Session auf opus"), or when a session clearly needs a stronger or ' +
|
|
43
|
+
'cheaper model for what it is doing. The running turn keeps its model; the NEXT turn uses the new one. ' +
|
|
44
|
+
'The switch is written into that conversation with your name, and every open window updates — so say ' +
|
|
45
|
+
'in your reply what you switched and why. `clear:true` removes the override (back to the persona ' +
|
|
46
|
+
'default). For a session that does not exist yet, use agent_ask with create_session + model instead.',
|
|
47
|
+
inputSchema: Input,
|
|
48
|
+
jsonSchema: {
|
|
49
|
+
type: 'object',
|
|
50
|
+
properties: {
|
|
51
|
+
model: { type: 'string', description: 'Model alias or provider/id. Omit together with clear:true.' },
|
|
52
|
+
clear: { type: 'boolean', description: 'true = remove the override; the persona default applies again.' },
|
|
53
|
+
agent: { type: 'string', description: 'Whose session. Default: you.' },
|
|
54
|
+
session: { type: 'string', description: 'Session slug or id. Default for your own agent: the session you are in. Required for another agent.' },
|
|
55
|
+
},
|
|
56
|
+
additionalProperties: false,
|
|
57
|
+
},
|
|
58
|
+
defaultTimeoutMs: 15_000,
|
|
59
|
+
async handler(input, ctx): Promise<SessionModelResult> {
|
|
60
|
+
if (Boolean(input.model) === Boolean(input.clear)) {
|
|
61
|
+
throw new Error('session_model: pass either `model` or `clear:true`, not both and not neither');
|
|
62
|
+
}
|
|
63
|
+
const target = resolveSessionModelTarget(input, { agent: ctx.agent, session: ctx.session });
|
|
64
|
+
const host = process.env.SOMORA_HOST || '127.0.0.1';
|
|
65
|
+
const port = process.env.SOMORA_PORT || '18737';
|
|
66
|
+
const scheme = process.env.SOMORA_TLS === '1' ? 'https' : 'http';
|
|
67
|
+
const url = `${scheme}://${host}:${port}/agents/${encodeURIComponent(target.agent)}/sessions/${encodeURIComponent(target.session)}/model`;
|
|
68
|
+
const by = { by_agent: ctx.agent, ...(ctx.session ? { by_session: ctx.session } : {}) };
|
|
69
|
+
let res;
|
|
70
|
+
try {
|
|
71
|
+
res = await loopbackFetch(url, {
|
|
72
|
+
method: input.clear ? 'DELETE' : 'PUT',
|
|
73
|
+
headers: { 'Content-Type': 'application/json' },
|
|
74
|
+
body: JSON.stringify(input.clear ? by : { model: input.model, ...by }),
|
|
75
|
+
});
|
|
76
|
+
} catch (err) {
|
|
77
|
+
const c = classifyFetchError(err);
|
|
78
|
+
throw new Error(`session_model [${c.category}${c.code ? '/' + c.code : ''}]: ${c.message}`);
|
|
79
|
+
}
|
|
80
|
+
const data = (await res.json().catch(() => ({}))) as { error?: string; session?: string; resolved?: string };
|
|
81
|
+
if (!res.ok) throw new Error(`session_model: ${data.error ?? `HTTP ${res.status}`}`);
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
agent: target.agent,
|
|
85
|
+
session: data.session ?? target.session,
|
|
86
|
+
model: input.clear ? null : input.model!,
|
|
87
|
+
...(data.resolved ? { resolved: data.resolved } : {}),
|
|
88
|
+
takes_effect: 'next turn',
|
|
89
|
+
note: 'Recorded in that conversation with your name. A turn that is running there right now keeps its model.',
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Which session is meant. Exported for tests. */
|
|
95
|
+
export function resolveSessionModelTarget(
|
|
96
|
+
input: { agent?: string | undefined; session?: string | undefined },
|
|
97
|
+
self: { agent: string; session?: string | undefined },
|
|
98
|
+
): { agent: string; session: string } {
|
|
99
|
+
const agent = input.agent ?? self.agent;
|
|
100
|
+
if (input.session) return { agent, session: input.session };
|
|
101
|
+
if (agent !== self.agent) {
|
|
102
|
+
throw new Error(`session_model: name the session of '${agent}' you mean — session_list({agent:"${agent}"}) shows them`);
|
|
103
|
+
}
|
|
104
|
+
if (!self.session) throw new Error('session_model: not running inside a session — name the session explicitly');
|
|
105
|
+
return { agent, session: self.session };
|
|
106
|
+
}
|