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,695 @@
|
|
|
1
|
+
// Internal canonical event format. Persisted as JSONL (later in step 1b+).
|
|
2
|
+
// Engine-agnostic — every adapter (anthropic, openai, ...) maps SDK events to this shape.
|
|
3
|
+
import type { TurnOrigin } from './turn-origin.ts';
|
|
4
|
+
|
|
5
|
+
export type NormalizedEvent =
|
|
6
|
+
| {
|
|
7
|
+
kind: 'user_message';
|
|
8
|
+
ts: number;
|
|
9
|
+
engine: string;
|
|
10
|
+
text: string;
|
|
11
|
+
/**
|
|
12
|
+
* Agent-to-agent (A2A) attribution. When set, this user_message
|
|
13
|
+
* was written into THIS session by another somora agent (via
|
|
14
|
+
* `agent_ask` or as a sub-task seed) — NOT by the human user.
|
|
15
|
+
*
|
|
16
|
+
* Semantics:
|
|
17
|
+
* - undefined → human user (default, unchanged behavior)
|
|
18
|
+
* - '<agent>' → another agent wrote this turn into the current
|
|
19
|
+
* agent's session as part of an A2A flow.
|
|
20
|
+
*
|
|
21
|
+
* Storage: persists in JSONL alongside `text`; replays into
|
|
22
|
+
* cross-engine context with a "[Message from agent <name>]"
|
|
23
|
+
* header so other engines learn provenance during catch-up.
|
|
24
|
+
*
|
|
25
|
+
* TUI: rendered with the sender's icon instead of the user icon.
|
|
26
|
+
*/
|
|
27
|
+
from_agent?: string;
|
|
28
|
+
/**
|
|
29
|
+
* A2A: the session the asking agent wrote from (its session id,
|
|
30
|
+
* or 'main'). Set together with from_agent by agent_ask. Lets
|
|
31
|
+
* the receiver address a follow-up to the right session and
|
|
32
|
+
* lets `agent_ask` without an explicit `session` route a reply
|
|
33
|
+
* back there (see src/server/turn-origin.ts).
|
|
34
|
+
*/
|
|
35
|
+
from_session?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Marks a user_message that was synthesized by an internal
|
|
38
|
+
* subsystem rather than typed by a human or sent by a peer
|
|
39
|
+
* agent: a sentinel fire, a tmux or browser wake, a voice
|
|
40
|
+
* consult, or a wake-up about a finished agent_ask (`a2a`),
|
|
41
|
+
* sub-agent (`subagent`) or background job (`job`). Clients
|
|
42
|
+
* render the inbound as a centered system divider instead of a
|
|
43
|
+
* regular user-bubble; `origin` below says the same with detail.
|
|
44
|
+
*
|
|
45
|
+
* Note: from_agent and from_system are mutually exclusive — an
|
|
46
|
+
* inbound is either A2A (from another agent) OR system
|
|
47
|
+
* (synthesized by an internal subsystem) OR neither (human
|
|
48
|
+
* user). The renderer picks the bubble class in that order.
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* `job` means a background job the agent started has finished and
|
|
52
|
+
* brought it back — video renders today. Deliberately not named
|
|
53
|
+
* after the medium: the distinguishing fact is "something you
|
|
54
|
+
* kicked off is done", and video is only the first of those.
|
|
55
|
+
*/
|
|
56
|
+
from_system?: 'sentinel' | 'tmux' | 'subagent' | 'job' | 'browser' | 'voice' | 'a2a';
|
|
57
|
+
/**
|
|
58
|
+
* Where the turn came from, as one value (src/types/turn-origin.ts).
|
|
59
|
+
* Additive since 2026-09-13: from_agent / from_system above stay
|
|
60
|
+
* the fields every older reader uses; a client that knows this
|
|
61
|
+
* one renders glyph, label and subtitle from it instead of
|
|
62
|
+
* parsing the message text. Absent on turns recorded before.
|
|
63
|
+
*/
|
|
64
|
+
origin?: TurnOrigin;
|
|
65
|
+
/**
|
|
66
|
+
* Steering (since 2026-09-23): this message was sent while a turn
|
|
67
|
+
* was running and handed to the model inside that turn, before
|
|
68
|
+
* its next step — it did not start a turn of its own. `steer_id`
|
|
69
|
+
* is the id the client got back from `POST /chat/send` with
|
|
70
|
+
* `steer: true`, so it can pair the record with its bubble.
|
|
71
|
+
*/
|
|
72
|
+
steer?: true;
|
|
73
|
+
steer_id?: string;
|
|
74
|
+
/**
|
|
75
|
+
* Correlation UUID for an `agent_ask` round-trip. Persisted on
|
|
76
|
+
* BOTH sides: on the caller's side as a tool_call → tool_result
|
|
77
|
+
* pair (the call_id is in the tool_call payload), and on the
|
|
78
|
+
* target's side as user_message.agent_ask_call_id alongside
|
|
79
|
+
* from_agent.
|
|
80
|
+
*
|
|
81
|
+
* Powers `agent_ask_result(call_id)`: the live registry
|
|
82
|
+
* (src/server/ask-calls.ts) answers first; after a restart the
|
|
83
|
+
* route re-reads this field from the target's JSONL.
|
|
84
|
+
*/
|
|
85
|
+
agent_ask_call_id?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Memory-recall block (`<memory-context>...</memory-context>`)
|
|
88
|
+
* that was injected at the time THIS turn was sent. Persisted
|
|
89
|
+
* here so history reconstruction at later turns recreates the
|
|
90
|
+
* exact byte sequence we originally sent — required for
|
|
91
|
+
* prefix-cache to match across turns on stateless backends.
|
|
92
|
+
*
|
|
93
|
+
* Without this field, openai-compatible engines have no way to
|
|
94
|
+
* rebuild past user_messages identically (every turn re-queries
|
|
95
|
+
* memory and gets potentially different hits), so any cache
|
|
96
|
+
* breakpoint sitting between the system block and the latest
|
|
97
|
+
* user message gets invalidated turn-after-turn.
|
|
98
|
+
*
|
|
99
|
+
* Engines that don't reconstruct full history (claude-cli /
|
|
100
|
+
* codex-cli with resumed sessions) ignore this field — they
|
|
101
|
+
* inline the memory block into the outgoing user_message text
|
|
102
|
+
* directly, and the underlying provider remembers the prior
|
|
103
|
+
* turns it already saw.
|
|
104
|
+
*
|
|
105
|
+
* TUI rendering should display only `text`, not `ephemeral` —
|
|
106
|
+
* the recall block is internal scaffolding, not user-typed.
|
|
107
|
+
*/
|
|
108
|
+
ephemeral?: string;
|
|
109
|
+
/**
|
|
110
|
+
* User-attached files (Phase Y.B, web upload). Refs only — bytes
|
|
111
|
+
* live at `~/.somora/attachments/<hash>.<ext>` content-
|
|
112
|
+
* addressed. JSONL persists name/mime/size for display +
|
|
113
|
+
* sanity-checks at replay time; the path is derived from the
|
|
114
|
+
* hash on demand.
|
|
115
|
+
*/
|
|
116
|
+
attachments?: Array<{
|
|
117
|
+
hash: string;
|
|
118
|
+
name: string;
|
|
119
|
+
mime: string;
|
|
120
|
+
size: number;
|
|
121
|
+
}>;
|
|
122
|
+
/**
|
|
123
|
+
* Input-channel metadata. Populated when the user message
|
|
124
|
+
* arrived through a non-text channel (currently: STT
|
|
125
|
+
* transcription from the mic button on web/mobile, or the
|
|
126
|
+
* `/voice/turn` audio-in endpoint). Drives the auto-TTS
|
|
127
|
+
* policy in run-turn: only voice-input turns are eligible
|
|
128
|
+
* for assistant_audio generation. Absent ⇒ treat as text
|
|
129
|
+
* (backwards-compatible with pre-voice JSONL).
|
|
130
|
+
*/
|
|
131
|
+
input?: {
|
|
132
|
+
modality?: 'text' | 'voice';
|
|
133
|
+
/** True if the text was produced by an STT pass (not typed). */
|
|
134
|
+
transcribed?: boolean;
|
|
135
|
+
/** Free-form tag for the STT path used, e.g. provider name. */
|
|
136
|
+
sttProvider?: string;
|
|
137
|
+
/**
|
|
138
|
+
* WHICH spoken path this came from. Two different features
|
|
139
|
+
* write `modality: 'voice'` and they must not be read as one
|
|
140
|
+
* (Rene, 2026-09-12): `stt` is the microphone button — one
|
|
141
|
+
* recording becomes one message you can still edit before
|
|
142
|
+
* sending. `realtime` is a live call, where the sentence was
|
|
143
|
+
* spoken into a standing connection and is recorded after the
|
|
144
|
+
* fact.
|
|
145
|
+
*/
|
|
146
|
+
source?: 'stt' | 'realtime';
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Per-turn client request: did the client (web / mobile / voice
|
|
150
|
+
* endpoint) ask somora to also generate spoken audio for the
|
|
151
|
+
* assistant reply? The auto-TTS hook in run-turn only fires
|
|
152
|
+
* when this is true AND `input.modality === 'voice'`. Absent ⇒
|
|
153
|
+
* no audio generated (default-safe).
|
|
154
|
+
*/
|
|
155
|
+
autoPlayRequested?: boolean;
|
|
156
|
+
}
|
|
157
|
+
| { kind: 'assistant_delta'; ts: number; engine: string; text: string }
|
|
158
|
+
| { kind: 'assistant_message'; ts: number; engine: string; text: string }
|
|
159
|
+
/**
|
|
160
|
+
* The model's reasoning text, separate from the reply. `thinking_delta`
|
|
161
|
+
* is CUMULATIVE for the turn (like assistant_delta) and never persisted;
|
|
162
|
+
* `thinking_message` is the final text, persisted to JSONL before the
|
|
163
|
+
* turn's assistant_message. Engines that surface no thinking emit
|
|
164
|
+
* neither. Never replayed to a model and never fed to REM.
|
|
165
|
+
*/
|
|
166
|
+
| { kind: 'thinking_delta'; ts: number; engine: string; text: string }
|
|
167
|
+
| {
|
|
168
|
+
kind: 'thinking_message';
|
|
169
|
+
ts: number;
|
|
170
|
+
engine: string;
|
|
171
|
+
text: string;
|
|
172
|
+
/** Set by the server when the text was cut at thinkingContent.maxChars. */
|
|
173
|
+
truncated?: true;
|
|
174
|
+
}
|
|
175
|
+
| {
|
|
176
|
+
/**
|
|
177
|
+
* Audio artifact attached to an assistant_message. Emitted by
|
|
178
|
+
* the auto-TTS hook in run-turn after the assistant text
|
|
179
|
+
* finalizes and the speech-sanitizer accepts it, or by the
|
|
180
|
+
* `/voice/turn` endpoint as part of its synchronous response.
|
|
181
|
+
*
|
|
182
|
+
* Append-only — never mutates the original assistant_message
|
|
183
|
+
* event. Clients pair by `turnId`: when an assistant_audio
|
|
184
|
+
* with matching turnId arrives, render a Play-button on the
|
|
185
|
+
* corresponding assistant bubble.
|
|
186
|
+
*/
|
|
187
|
+
kind: 'assistant_audio';
|
|
188
|
+
ts: number;
|
|
189
|
+
engine: string;
|
|
190
|
+
turnId: string;
|
|
191
|
+
audio: {
|
|
192
|
+
/** Absolute URL path served by GET /tts/cache/:hash.:ext. */
|
|
193
|
+
url: string;
|
|
194
|
+
/** Concrete MIME (`audio/wav`, `audio/opus`, `audio/mp4`). */
|
|
195
|
+
mime: string;
|
|
196
|
+
/** Approximate duration of the generated audio in ms. */
|
|
197
|
+
durationMs?: number;
|
|
198
|
+
/** sha256(text+voice+model+format) — debug/forensic only. */
|
|
199
|
+
cacheKey: string;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
| {
|
|
203
|
+
/**
|
|
204
|
+
* Media produced during an assistant turn. Emitted after the turn
|
|
205
|
+
* finalizes, once, listing everything the turn's generation tools
|
|
206
|
+
* made while it ran.
|
|
207
|
+
*
|
|
208
|
+
* Deliberately NOT called `assistant_images`: this string is
|
|
209
|
+
* written into session JSONL and stays there for the life of the
|
|
210
|
+
* session. A video endpoint would otherwise need a second,
|
|
211
|
+
* near-identical event kind, and every reader would have to
|
|
212
|
+
* understand both forever. Instead each entry carries its own
|
|
213
|
+
* `type`, and a reader that meets a type it doesn't know skips
|
|
214
|
+
* that entry.
|
|
215
|
+
*
|
|
216
|
+
* Append-only and paired by `turnId`, exactly like
|
|
217
|
+
* assistant_audio — the original assistant_message is never
|
|
218
|
+
* mutated. Clients render the media on the matching bubble.
|
|
219
|
+
*
|
|
220
|
+
* Why the server volunteers these instead of the agent sending
|
|
221
|
+
* them: a person who asked for a picture should get the picture.
|
|
222
|
+
* Leaving it to the agent to remember means the failure mode is
|
|
223
|
+
* "Done!" with nothing to look at.
|
|
224
|
+
*
|
|
225
|
+
* Refs only — bytes stay in the images directory and are served
|
|
226
|
+
* by GET /images/:id/file. JSONL keeps enough to render a
|
|
227
|
+
* placeholder if the file later disappears. Note that `url` is
|
|
228
|
+
* itself part of the persisted payload: that route has to keep
|
|
229
|
+
* resolving even if a later generalisation adds a /media/ path.
|
|
230
|
+
*/
|
|
231
|
+
kind: 'assistant_media';
|
|
232
|
+
ts: number;
|
|
233
|
+
engine: string;
|
|
234
|
+
turnId: string;
|
|
235
|
+
media: Array<{
|
|
236
|
+
/** What this entry is. Adding `video` here — rather than a
|
|
237
|
+
* second event kind — is exactly what this field was for. */
|
|
238
|
+
type: 'image' | 'video';
|
|
239
|
+
id: string;
|
|
240
|
+
prompt: string;
|
|
241
|
+
mime: string;
|
|
242
|
+
filename: string;
|
|
243
|
+
/**
|
|
244
|
+
* Absolute URL path: `/media/<id>/file`.
|
|
245
|
+
*
|
|
246
|
+
* Rows written on 2026-08-27 carry `/images/<id>/file`. That
|
|
247
|
+
* route stays mounted for good — the string is in session files
|
|
248
|
+
* and cannot be rewritten.
|
|
249
|
+
*/
|
|
250
|
+
url: string;
|
|
251
|
+
/** Video: a still, where the provider serves one. */
|
|
252
|
+
thumbUrl?: string;
|
|
253
|
+
/** Video: playing time in seconds. */
|
|
254
|
+
durationSec?: number;
|
|
255
|
+
}>;
|
|
256
|
+
}
|
|
257
|
+
| { kind: 'tool_call'; ts: number; engine: string; callId: string; tool: string; input: unknown }
|
|
258
|
+
| { kind: 'tool_result'; ts: number; engine: string; callId: string; output: unknown; error?: string }
|
|
259
|
+
// Engine-internal metadata that the agent emits as a side-channel to
|
|
260
|
+
// the conversation. The canonical case is codex-cli's `todo_list`
|
|
261
|
+
// item — codex tracks an internal plan/checklist that the model
|
|
262
|
+
// updates mid-turn. We don't drive it ourselves; we observe + persist
|
|
263
|
+
// it so REM-dream/memory can read history later, and so the user can
|
|
264
|
+
// optionally see it when their `show.tools` toggle is on. Opaque
|
|
265
|
+
// payload — different engines / future codex versions can ship
|
|
266
|
+
// arbitrary itemType strings without parser churn.
|
|
267
|
+
| {
|
|
268
|
+
kind: 'engine_meta';
|
|
269
|
+
ts: number;
|
|
270
|
+
engine: string;
|
|
271
|
+
/** Raw item-type label as the engine produced it (e.g. 'todo_list',
|
|
272
|
+
* 'hookPrompt'). Clients map known ones to friendly labels (see
|
|
273
|
+
* src/engine/codex-cli.ts CODEX_META_LABELS) and fall back to the
|
|
274
|
+
* raw string for unknowns. */
|
|
275
|
+
itemType: string;
|
|
276
|
+
/** The original event payload, untouched. Schema depends on
|
|
277
|
+
* engine + itemType — treat as opaque. */
|
|
278
|
+
payload: unknown;
|
|
279
|
+
}
|
|
280
|
+
| { kind: 'turn_start'; ts: number; engine: string; turnId: string }
|
|
281
|
+
/**
|
|
282
|
+
* Engine-internal: steer messages (src/server/steer-inbox.ts) were
|
|
283
|
+
* handed to the model at a step boundary, in this order. run-turn
|
|
284
|
+
* turns each into a persisted `user_message` with `steer: true`; the
|
|
285
|
+
* event itself is never written to the session file.
|
|
286
|
+
*/
|
|
287
|
+
| {
|
|
288
|
+
kind: 'steer_applied';
|
|
289
|
+
ts: number;
|
|
290
|
+
engine: string;
|
|
291
|
+
messages: Array<{
|
|
292
|
+
id: string;
|
|
293
|
+
text: string;
|
|
294
|
+
ts: number;
|
|
295
|
+
origin: TurnOrigin;
|
|
296
|
+
from_agent?: string;
|
|
297
|
+
from_session?: string;
|
|
298
|
+
}>;
|
|
299
|
+
}
|
|
300
|
+
| {
|
|
301
|
+
kind: 'turn_end';
|
|
302
|
+
ts: number;
|
|
303
|
+
engine: string;
|
|
304
|
+
turnId: string;
|
|
305
|
+
/** `<provider>/<modelId>` that actually produced this turn — the
|
|
306
|
+
* fallback's when one took over. Stamped by run-turn when the
|
|
307
|
+
* event is persisted (since 2026-09-21); absent on older turns.
|
|
308
|
+
* Without it a session file could not answer "which model wrote
|
|
309
|
+
* this?" once the session's model had been switched. */
|
|
310
|
+
model?: string;
|
|
311
|
+
usage?: {
|
|
312
|
+
tokens_in: number;
|
|
313
|
+
tokens_out: number;
|
|
314
|
+
/** Tokens served from the provider's prefix-cache (subset of tokens_in). Optional — not all engines surface it. */
|
|
315
|
+
tokens_in_cached?: number;
|
|
316
|
+
/** Reasoning/thinking tokens (subset of tokens_out). Optional — only reasoning-capable models surface it. */
|
|
317
|
+
tokens_out_reasoning?: number;
|
|
318
|
+
/** True when tokens_out_reasoning was estimated from streamed reasoning text (backend reported none). */
|
|
319
|
+
tokens_out_reasoning_estimated?: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Prompt size of the LAST request of this turn — how full the
|
|
322
|
+
* context actually was, not how much was spent getting there.
|
|
323
|
+
*
|
|
324
|
+
* `tokens_in` is a sum across every request a turn makes, which
|
|
325
|
+
* for a tool-using turn is a multiple of the window and cannot
|
|
326
|
+
* be compared against it. Displaying that sum as occupancy is
|
|
327
|
+
* what let a turn read as 58k while the backend was refusing
|
|
328
|
+
* 507k (2026-09-10 report). Engines that can report it do.
|
|
329
|
+
*/
|
|
330
|
+
context_tokens?: number;
|
|
331
|
+
/**
|
|
332
|
+
* The window the ENGINE says this model has, when it says so.
|
|
333
|
+
*
|
|
334
|
+
* For a CLI engine the configured `contextWindow` is somora's
|
|
335
|
+
* own guess at a session cap it does not control: codex reports
|
|
336
|
+
* `modelContextWindow` per thread (258,400 for gpt-6-astra on
|
|
337
|
+
* 2026-09-11, against 272,000 configured by hand), and that
|
|
338
|
+
* number is the one the CLI compacts against. Shown instead of
|
|
339
|
+
* the configured value when present.
|
|
340
|
+
*/
|
|
341
|
+
context_window?: number;
|
|
342
|
+
};
|
|
343
|
+
/** Tool-call rounds the engine ran this turn (engines that count). */
|
|
344
|
+
rounds?: number;
|
|
345
|
+
/** The engine had to force a no-tools finish (round cap, tool
|
|
346
|
+
* budget, scaffold leak) and the model then produced a real
|
|
347
|
+
* answer — a partial result, not a clean one. */
|
|
348
|
+
forced_final?: string;
|
|
349
|
+
/** The final text is a harness marker, not a model answer:
|
|
350
|
+
* the model looped, leaked scaffold, or never answered. Runtime
|
|
351
|
+
* signal — never inferred from model text by consumers. */
|
|
352
|
+
degraded?: { reason: string };
|
|
353
|
+
}
|
|
354
|
+
| {
|
|
355
|
+
kind: 'error';
|
|
356
|
+
ts: number;
|
|
357
|
+
engine: string;
|
|
358
|
+
message: string;
|
|
359
|
+
/**
|
|
360
|
+
* The PROVIDER refused or could not serve this request: quota
|
|
361
|
+
* exhausted, auth rejected, host unreachable, backend 5xx. Set by
|
|
362
|
+
* the engine adapter, which is the only place that knows how its
|
|
363
|
+
* provider dresses a failure — never inferred from model text.
|
|
364
|
+
*
|
|
365
|
+
* Two consumers depend on it. The fallback chain may switch models
|
|
366
|
+
* even when text already arrived, because a quota notice that the
|
|
367
|
+
* provider streamed as an assistant message is not an answer
|
|
368
|
+
* (2026-09-09 report: Claude's monthly-limit text set the
|
|
369
|
+
* first-output guard and the configured backups never ran). And
|
|
370
|
+
* the turn result counts as failed rather than completed.
|
|
371
|
+
*/
|
|
372
|
+
providerError?: boolean;
|
|
373
|
+
}
|
|
374
|
+
// Server-side marker for project focus changes within a session. Fired
|
|
375
|
+
// whenever the user pins a project via slash-command OR an agent
|
|
376
|
+
// autonomously calls project_focus via the Tool surface. Persists in
|
|
377
|
+
// JSONL purely for forensics: lets you reconstruct "from which turn
|
|
378
|
+
// onwards did this session see project context X?" months later
|
|
379
|
+
// without needing to replay session.meta history. The `engine` field
|
|
380
|
+
// is the sentinel `'somora'` here — these aren't engine-emitted.
|
|
381
|
+
| {
|
|
382
|
+
kind: 'project_switched';
|
|
383
|
+
ts: number;
|
|
384
|
+
engine: string;
|
|
385
|
+
from: string | null;
|
|
386
|
+
to: string | null;
|
|
387
|
+
via: 'tool' | 'slash_command';
|
|
388
|
+
}
|
|
389
|
+
// Server-side marker: the persona's primary model failed before
|
|
390
|
+
// producing any content and run-turn-fallback re-ran the turn on the
|
|
391
|
+
// configured `fallback:` model. Persisted right before the fallback
|
|
392
|
+
// engine's events so history can mark the turn that follows; clients
|
|
393
|
+
// show a chip on that assistant bubble + a one-time notice. `engine`
|
|
394
|
+
// is the sentinel 'somora'. Refs are `provider/modelId`.
|
|
395
|
+
| {
|
|
396
|
+
kind: 'model_fallback';
|
|
397
|
+
ts: number;
|
|
398
|
+
engine: string;
|
|
399
|
+
requested: string;
|
|
400
|
+
actual: string;
|
|
401
|
+
/** Primary's failure message, trimmed — what the user sees on hover. */
|
|
402
|
+
reason: string;
|
|
403
|
+
/** Every model that died before producing anything on this turn,
|
|
404
|
+
* in order (the primary first). Present since fallback chains
|
|
405
|
+
* (2026-09-08); one entry when a single `fallback:` took over. */
|
|
406
|
+
hops?: Array<{ model: string; reason: string }>;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export interface ModelFallbackInfo {
|
|
410
|
+
requested: string;
|
|
411
|
+
actual: string;
|
|
412
|
+
reason: string;
|
|
413
|
+
/** Failed attempts in order, primary first. See NormalizedEvent. */
|
|
414
|
+
hops?: Array<{ model: string; reason: string }>;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Wire format over SSE — orbit-compatible. Deltas are cumulative.
|
|
418
|
+
export type SseEvent =
|
|
419
|
+
| { event: 'chat'; data: { state: 'delta' | 'final'; text: string } }
|
|
420
|
+
/** Reasoning text; deltas cumulative like `chat`. `final` precedes the chat final of the same turn. */
|
|
421
|
+
| { event: 'thinking'; data: { state: 'delta' | 'final'; text: string; truncated?: true } }
|
|
422
|
+
| {
|
|
423
|
+
event: 'agent';
|
|
424
|
+
data: {
|
|
425
|
+
phase: 'start' | 'end';
|
|
426
|
+
usage?: {
|
|
427
|
+
tokens_in: number;
|
|
428
|
+
tokens_out: number;
|
|
429
|
+
tokens_in_cached?: number;
|
|
430
|
+
tokens_out_reasoning?: number;
|
|
431
|
+
tokens_out_reasoning_estimated?: boolean;
|
|
432
|
+
/** Prompt size of the turn's last request — occupancy, not spend. */
|
|
433
|
+
context_tokens?: number;
|
|
434
|
+
};
|
|
435
|
+
contextWindow?: number;
|
|
436
|
+
/** The model that ACTUALLY answered (the fallback when one ran). */
|
|
437
|
+
provider?: string;
|
|
438
|
+
model?: string;
|
|
439
|
+
/**
|
|
440
|
+
* Effective thinking depth for this turn. Surfaces what the
|
|
441
|
+
* engine actually applied so clients can show it in the header.
|
|
442
|
+
* 'dormant' = setting present but model lacks 'reasoning' capability.
|
|
443
|
+
*/
|
|
444
|
+
thinking?: { level: 'off' | 'low' | 'medium' | 'high'; active: boolean };
|
|
445
|
+
/** Set on phase:'end' when the turn was answered by the fallback model. */
|
|
446
|
+
fallback?: ModelFallbackInfo;
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
| { event: 'model_fallback'; data: ModelFallbackInfo }
|
|
450
|
+
| {
|
|
451
|
+
// Per-turn auto-inject summary — what the runtime pulled from memory
|
|
452
|
+
// before the engine ran. Lets the CLI / orbit show users which notes
|
|
453
|
+
// were surfaced without them having to grep server logs.
|
|
454
|
+
event: 'memory';
|
|
455
|
+
data: {
|
|
456
|
+
count: number;
|
|
457
|
+
topScore?: number;
|
|
458
|
+
// `<source>/<slug>` references in score order, top first.
|
|
459
|
+
refs: string[];
|
|
460
|
+
// Full inject block text — exactly what was concatenated into
|
|
461
|
+
// the engine's systemPrompt/ephemeralContext for this turn.
|
|
462
|
+
// Always present; clients render only when /verbose memory is on.
|
|
463
|
+
fullText: string;
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
| {
|
|
467
|
+
// Tool lifecycle event. Server pre-formats the renderable bits:
|
|
468
|
+
// call → tool name (stripped of mcp__ prefix) + args summary
|
|
469
|
+
// result → tool name + result summary (omitted entirely if trivial,
|
|
470
|
+
// so clients never see "boring" rows like {ok:true})
|
|
471
|
+
// error → tool name + error string
|
|
472
|
+
// Clients render summary/error directly without inspecting raw payloads.
|
|
473
|
+
event: 'tool';
|
|
474
|
+
data:
|
|
475
|
+
| { phase: 'call'; tool: string; summary: string; details: string }
|
|
476
|
+
| { phase: 'result'; tool: string; summary: string; details: string }
|
|
477
|
+
| { phase: 'error'; tool: string; error: string; details?: string };
|
|
478
|
+
}
|
|
479
|
+
| { event: 'status'; data: { msg: string } }
|
|
480
|
+
| {
|
|
481
|
+
// A2A user-message broadcast. Fired ONLY when an `agent_ask` (or
|
|
482
|
+
// similar A2A tool) writes a user_message with `from_agent` set
|
|
483
|
+
// into a session. Used by the TUI of a human watching that
|
|
484
|
+
// session live so they see the inbound A2A turn appear in real
|
|
485
|
+
// time, rendered with the sender's icon instead of their own.
|
|
486
|
+
//
|
|
487
|
+
// Now ALSO fired for self-typed turns so multi-client setups
|
|
488
|
+
// (TUI tail + web window open at once) see each other's
|
|
489
|
+
// inputs live. Senders dedupe their own optimistic copy by
|
|
490
|
+
// recent-text — TUI does this implicitly via the local echo,
|
|
491
|
+
// web's ChatProvider tracks pending texts in a ref.
|
|
492
|
+
event: 'user_message';
|
|
493
|
+
data: {
|
|
494
|
+
text: string;
|
|
495
|
+
ts?: number;
|
|
496
|
+
/** Server-generated turn id. Echoed back so clients can match
|
|
497
|
+
* this event to an optimistic bubble created from POST
|
|
498
|
+
* /chat/send (whose response carries the same turnId), and to
|
|
499
|
+
* clear any pending `turn_queued` indicator on that bubble. */
|
|
500
|
+
turnId?: string;
|
|
501
|
+
/** Set only when the message came from another agent
|
|
502
|
+
* (A2A). Self-typed user turns omit it. */
|
|
503
|
+
from_agent?: string;
|
|
504
|
+
/** Set only when the inbound was synthesized by an internal
|
|
505
|
+
* subsystem (today: 'sentinel'). Clients render the message
|
|
506
|
+
* as a centered system divider. */
|
|
507
|
+
from_system?: 'sentinel' | 'tmux' | 'subagent' | 'job' | 'browser' | 'voice' | 'a2a';
|
|
508
|
+
/** Same value as on the stored event — see NormalizedEvent. */
|
|
509
|
+
origin?: TurnOrigin;
|
|
510
|
+
agent_ask_call_id?: string;
|
|
511
|
+
/** Steering: this message was handed to the running turn (the
|
|
512
|
+
* `turnId` here) before its next step; `steer_id` pairs it with
|
|
513
|
+
* the `steer_queued` event / the POST /chat/send response. */
|
|
514
|
+
steer?: true;
|
|
515
|
+
steer_id?: string;
|
|
516
|
+
/** How the turn was said, when it was not typed. Mirrors the
|
|
517
|
+
* `input` field on the stored event so the live bubble and the
|
|
518
|
+
* one rebuilt from history render the same way — dictation and
|
|
519
|
+
* a standing call look different, and both differ from text. */
|
|
520
|
+
input?: { modality?: 'text' | 'voice'; source?: 'stt' | 'realtime' };
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
| {
|
|
524
|
+
// User-turn was enqueued behind a still-running turn on the same
|
|
525
|
+
// (agent, session). Fired by POST /chat/send right after pushing
|
|
526
|
+
// the waiter into the session lock's queue. Clients tag their
|
|
527
|
+
// optimistic user-bubble (matched by turnId from the HTTP
|
|
528
|
+
// response) with a "queued" indicator until the matching
|
|
529
|
+
// `user_message` event arrives — at which point the lock has
|
|
530
|
+
// been acquired and the turn is actually running.
|
|
531
|
+
//
|
|
532
|
+
// `ahead` = number of turns this one must wait for, INCLUDING
|
|
533
|
+
// the currently-running one (so ahead=1 means "next in line").
|
|
534
|
+
// Static snapshot at enqueue time: not updated as the queue
|
|
535
|
+
// drains. Clients show "queued" for ahead=1, "queued · N ahead"
|
|
536
|
+
// for ahead>1.
|
|
537
|
+
event: 'turn_queued';
|
|
538
|
+
data: {
|
|
539
|
+
turnId: string;
|
|
540
|
+
ahead: number;
|
|
541
|
+
/** Phase 2: the ledger id and origin kind of the waiter. */
|
|
542
|
+
workId?: string;
|
|
543
|
+
kind?: string;
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* A message was accepted for steering into the running turn `turnId`
|
|
548
|
+
* (POST /chat/send with `steer: true`). It is not in the session file
|
|
549
|
+
* yet: the matching `user_message` with the same `steer_id` follows
|
|
550
|
+
* when the engine hands it to the model. Other windows on the session
|
|
551
|
+
* render a pending bubble from this.
|
|
552
|
+
*/
|
|
553
|
+
| {
|
|
554
|
+
event: 'steer_queued';
|
|
555
|
+
data: { steerId: string; text: string; ts: number; turnId: string; origin: TurnOrigin };
|
|
556
|
+
}
|
|
557
|
+
/** Builder sessions (docs/builder.md): the task list changed. */
|
|
558
|
+
| { event: 'todo_updated'; data: { todos: Array<{ content: string; status: string; priority?: string }>; by?: string } }
|
|
559
|
+
/** Builder: the agent asked the person a question (ask_user); answer via POST …/answer. */
|
|
560
|
+
| {
|
|
561
|
+
event: 'question_asked';
|
|
562
|
+
data: {
|
|
563
|
+
questionId: string;
|
|
564
|
+
question: string;
|
|
565
|
+
header?: string;
|
|
566
|
+
options: Array<{ label: string; description?: string }>;
|
|
567
|
+
multiple: boolean;
|
|
568
|
+
expiresAt: number;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
/** Builder: the open question was answered or withdrawn. */
|
|
572
|
+
| { event: 'question_answered'; data: { questionId: string; answered: boolean } }
|
|
573
|
+
/** Builder: mode / phase / plan path changed. */
|
|
574
|
+
| { event: 'builder_state'; data: { mode: 'attended' | 'unattended'; phase: 'plan' | 'build'; planPath: string | null } }
|
|
575
|
+
| {
|
|
576
|
+
// A queued user turn was taken back before it started
|
|
577
|
+
// (DELETE /chat/queue/:turnId). `turnId` is the same server-
|
|
578
|
+
// issued id the client got from POST /chat/send. Clients drop
|
|
579
|
+
// the optimistic bubble; the initiating client already has the
|
|
580
|
+
// text back in its composer. Followed by fresh `turn_queued`
|
|
581
|
+
// events for the waiters that moved up.
|
|
582
|
+
event: 'turn_dequeued';
|
|
583
|
+
/** `workId` (Phase 2): the work-ledger id — equals `turnId` for a
|
|
584
|
+
* human turn, a call_id or task_id for anything else. */
|
|
585
|
+
data: { turnId: string; workId?: string };
|
|
586
|
+
}
|
|
587
|
+
| {
|
|
588
|
+
// The engine opened a turn: its own turn id (`t-…`, the one
|
|
589
|
+
// that `assistant_media` / `turn_end` carry in the session
|
|
590
|
+
// file). Clients stamp the assistant bubble they are about to
|
|
591
|
+
// build with it, so late-arriving media and errors can be
|
|
592
|
+
// paired to THIS turn instead of "the most recent bubble" —
|
|
593
|
+
// which, when a turn errors without an assistant message, is
|
|
594
|
+
// the previous turn's (2026-08-28 report: pictures landed a
|
|
595
|
+
// few lines up).
|
|
596
|
+
event: 'turn_started';
|
|
597
|
+
data: { turnId: string };
|
|
598
|
+
}
|
|
599
|
+
| {
|
|
600
|
+
// The turn ended with an error instead of (or after) an
|
|
601
|
+
// assistant message. `status` still carries the same text for
|
|
602
|
+
// older clients; this event adds the engine turn id so the
|
|
603
|
+
// failure renders as a block inside the right turn.
|
|
604
|
+
event: 'turn_error';
|
|
605
|
+
data: { turnId?: string; message: string; engine: string };
|
|
606
|
+
}
|
|
607
|
+
| {
|
|
608
|
+
// Audio artifact ready for an assistant message. Sibling to
|
|
609
|
+
// `chat: final` — that event delivers the text, this one
|
|
610
|
+
// delivers a play-able URL for the same turn. Clients pair
|
|
611
|
+
// by `turnId` and render a Play-button on the corresponding
|
|
612
|
+
// assistant bubble.
|
|
613
|
+
event: 'assistant_audio';
|
|
614
|
+
data: {
|
|
615
|
+
turnId: string;
|
|
616
|
+
url: string;
|
|
617
|
+
mime: string;
|
|
618
|
+
durationMs?: number;
|
|
619
|
+
cacheKey: string;
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
| {
|
|
623
|
+
// Media produced during the turn. Same pairing mechanism as
|
|
624
|
+
// assistant_audio: arrives after the reply, clients attach it to
|
|
625
|
+
// the bubble with the matching turnId. Mirrors the persisted
|
|
626
|
+
// `assistant_media` event — see the note there on why entries
|
|
627
|
+
// carry a `type` instead of the kind naming one medium.
|
|
628
|
+
event: 'assistant_media';
|
|
629
|
+
data: {
|
|
630
|
+
turnId: string;
|
|
631
|
+
media: Array<{
|
|
632
|
+
type: 'image' | 'video';
|
|
633
|
+
id: string;
|
|
634
|
+
prompt: string;
|
|
635
|
+
mime: string;
|
|
636
|
+
filename: string;
|
|
637
|
+
url: string;
|
|
638
|
+
thumbUrl?: string;
|
|
639
|
+
durationSec?: number;
|
|
640
|
+
}>;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
| {
|
|
644
|
+
// Engine-internal metadata (codex todo_list / future side-channel
|
|
645
|
+
// items). Persisted in JSONL by run-turn; clients only render when
|
|
646
|
+
// the `show.tools` toggle is on. Label mapping (raw itemType →
|
|
647
|
+
// friendly word) is shared via src/engine/engine-meta-labels.ts so
|
|
648
|
+
// server + clients stay in sync.
|
|
649
|
+
event: 'engine_meta';
|
|
650
|
+
data: {
|
|
651
|
+
engine: string;
|
|
652
|
+
itemType: string;
|
|
653
|
+
/** Pretty label resolved server-side (e.g. todo_list → "plan").
|
|
654
|
+
* Falls back to itemType verbatim for unknown types. */
|
|
655
|
+
label: string;
|
|
656
|
+
/** Optional one-liner summary (e.g. "3 items, 2 completed"). */
|
|
657
|
+
summary?: string;
|
|
658
|
+
/** Opaque structured payload — clients render via known itemType
|
|
659
|
+
* shapes or fall back to compact JSON dump for unknowns. */
|
|
660
|
+
payload: unknown;
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
| {
|
|
664
|
+
// Project focus change. Fired when the user (via /projekt slash-
|
|
665
|
+
// command or web button) pins or clears a project for this
|
|
666
|
+
// session. Clients use this to live-update the project-chip in
|
|
667
|
+
// the chat header without polling.
|
|
668
|
+
//
|
|
669
|
+
// `to: null` means the focus was cleared. Agent-initiated focus
|
|
670
|
+
// changes from MCP-routed tool calls (claude-cli / codex-cli)
|
|
671
|
+
// don't have SSE access from the child process — the client
|
|
672
|
+
// catches up on the next chat:final or by refetching
|
|
673
|
+
// /agents/:agent/sessions/:session/project explicitly.
|
|
674
|
+
event: 'project';
|
|
675
|
+
data: {
|
|
676
|
+
from: string | null;
|
|
677
|
+
to: string | null;
|
|
678
|
+
via: 'tool' | 'slash_command';
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
| {
|
|
682
|
+
// The session's model override was set or cleared (PUT/DELETE
|
|
683
|
+
// …/model). Often done from outside the window that shows the
|
|
684
|
+
// session — an orchestrator agent, another client — so clients
|
|
685
|
+
// re-read the session's model on this instead of showing the old
|
|
686
|
+
// one until reopened. `model: null` = override cleared, the
|
|
687
|
+
// persona default applies again. The running turn keeps the model
|
|
688
|
+
// it started with; the next turn uses the new one.
|
|
689
|
+
event: 'session_model';
|
|
690
|
+
data: {
|
|
691
|
+
model: string | null;
|
|
692
|
+
resolved?: string;
|
|
693
|
+
source: 'session-override' | 'persona-default';
|
|
694
|
+
};
|
|
695
|
+
};
|