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,182 @@
|
|
|
1
|
+
// Where a builder may write.
|
|
2
|
+
//
|
|
3
|
+
// A builder session pinned to a project folder writes there and in its
|
|
4
|
+
// own temp folder — nowhere else. A chat agent is not affected, and a
|
|
5
|
+
// builder without a pinned folder keeps the old rule (the write
|
|
6
|
+
// blacklist alone). The check runs after the path blacklist, in the
|
|
7
|
+
// same place for file_write and file_patch, in-process and in the MCP
|
|
8
|
+
// child (the question goes over loopback HTTP, so both reach the panel).
|
|
9
|
+
//
|
|
10
|
+
// Outside the scope:
|
|
11
|
+
// unattended — refused, the message names the allowed folders.
|
|
12
|
+
// attended — a question in the task panel: allow once, allow this
|
|
13
|
+
// folder for the session, deny. The session-wide grants
|
|
14
|
+
// live on the session meta (`builderWriteAllow`).
|
|
15
|
+
// The shell can still write anywhere; that is what command approvals
|
|
16
|
+
// (stage 3, not built) would gate. Documented as the limit.
|
|
17
|
+
|
|
18
|
+
import { dirname, isAbsolute, normalize, sep } from 'node:path';
|
|
19
|
+
import { homedir } from 'node:os';
|
|
20
|
+
import type { Config } from '../../config/types.ts';
|
|
21
|
+
import { loadPersona } from '../../persona/loader.ts';
|
|
22
|
+
import { readBuilderState } from '../../server/builder-session.ts';
|
|
23
|
+
import { classifyFetchError, loopbackFetch } from '../../server/loopback-fetch.ts';
|
|
24
|
+
import { logger } from '../../server/logger.ts';
|
|
25
|
+
import { pinnedWorkdir } from '../../server/session-workdir.ts';
|
|
26
|
+
import { sessionMetaStore } from '../../storage/sessions.ts';
|
|
27
|
+
|
|
28
|
+
const SOMORA_HOME = process.env.SOMORA_HOME ?? `${homedir()}/.somora`;
|
|
29
|
+
/** How long the panel question waits before the write counts as denied. */
|
|
30
|
+
export const WRITE_SCOPE_QUESTION_TIMEOUT_MS = 5 * 60_000;
|
|
31
|
+
|
|
32
|
+
export function agentTempDir(agent: string): string {
|
|
33
|
+
return normalize(`${SOMORA_HOME}/agents/${agent}/tmp`);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isUnder(path: string, root: string): boolean {
|
|
37
|
+
const r = normalize(root).replace(/[\\/]+$/, '');
|
|
38
|
+
const p = normalize(path);
|
|
39
|
+
return p === r || p.startsWith(r + sep);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The folders a builder pinned to `workdir` may write in. */
|
|
43
|
+
export function writeScopeRoots(agent: string, workdir: string, extra: readonly string[] = []): string[] {
|
|
44
|
+
return [normalize(workdir), agentTempDir(agent), ...extra.map((e) => normalize(e))];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isWithinRoots(absolute: string, roots: readonly string[]): boolean {
|
|
48
|
+
return roots.some((r) => isUnder(absolute, r));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type WriteScopeVerdict =
|
|
52
|
+
| { kind: 'unscoped' } // chat agent, or builder without a pinned folder
|
|
53
|
+
| { kind: 'inside' }
|
|
54
|
+
| { kind: 'refused'; reason: string }
|
|
55
|
+
| { kind: 'ask'; roots: string[] };
|
|
56
|
+
|
|
57
|
+
/** Pure decision from what the session says; no I/O. */
|
|
58
|
+
export function decideWriteScope(args: {
|
|
59
|
+
absolute: string;
|
|
60
|
+
kind: 'chat' | 'builder';
|
|
61
|
+
workdir: string | null;
|
|
62
|
+
mode: 'attended' | 'unattended' | null;
|
|
63
|
+
agent: string;
|
|
64
|
+
sessionGrants: readonly string[];
|
|
65
|
+
}): WriteScopeVerdict {
|
|
66
|
+
if (args.kind !== 'builder' || !args.workdir) return { kind: 'unscoped' };
|
|
67
|
+
const roots = writeScopeRoots(args.agent, args.workdir, args.sessionGrants);
|
|
68
|
+
if (isWithinRoots(args.absolute, roots)) return { kind: 'inside' };
|
|
69
|
+
if (args.mode === 'attended') return { kind: 'ask', roots };
|
|
70
|
+
return {
|
|
71
|
+
kind: 'refused',
|
|
72
|
+
reason:
|
|
73
|
+
`write refused: '${args.absolute}' is outside the project folder. A builder writes only inside ` +
|
|
74
|
+
`${roots[0]} (the pinned project) or ${roots[1]} (its temp folder). Use a path inside the project, ` +
|
|
75
|
+
'or say in your report why the file is needed elsewhere.',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function baseUrl(): string {
|
|
80
|
+
const host = process.env.SOMORA_HOST || '127.0.0.1';
|
|
81
|
+
const port = process.env.SOMORA_PORT || '18737';
|
|
82
|
+
const scheme = process.env.SOMORA_TLS === '1' ? 'https' : 'http';
|
|
83
|
+
return `${scheme}://${host}:${port}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const OPTION_ONCE = 'Allow once';
|
|
87
|
+
const OPTION_SESSION = 'Allow this folder for the session';
|
|
88
|
+
const OPTION_DENY = 'Deny';
|
|
89
|
+
|
|
90
|
+
/** Ask the person in the task panel. Resolves when allowed, throws when
|
|
91
|
+
* denied or unanswered. */
|
|
92
|
+
async function askPerson(agent: string, session: string, absolute: string, roots: string[]): Promise<void> {
|
|
93
|
+
const folder = dirname(absolute);
|
|
94
|
+
let res;
|
|
95
|
+
try {
|
|
96
|
+
res = await loopbackFetch(`${baseUrl()}/agents/${encodeURIComponent(agent)}/sessions/${encodeURIComponent(session)}/ask`, {
|
|
97
|
+
method: 'POST',
|
|
98
|
+
headers: { 'Content-Type': 'application/json' },
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
header: 'Write outside the project',
|
|
101
|
+
question:
|
|
102
|
+
`The builder wants to write ${absolute}, which is outside the project folder (${roots[0]}). ` +
|
|
103
|
+
`Allow it?`,
|
|
104
|
+
options: [
|
|
105
|
+
{ label: OPTION_ONCE, description: 'This file, this time.' },
|
|
106
|
+
{ label: OPTION_SESSION, description: `Any file under ${folder} for the rest of this session.` },
|
|
107
|
+
{ label: OPTION_DENY, description: 'The write is refused; the builder is told to stay inside the project.' },
|
|
108
|
+
],
|
|
109
|
+
multiple: false,
|
|
110
|
+
timeout_ms: WRITE_SCOPE_QUESTION_TIMEOUT_MS,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
} catch (err) {
|
|
114
|
+
const c = classifyFetchError(err);
|
|
115
|
+
throw new Error(`write refused: '${absolute}' is outside the project folder and the person could not be asked [${c.category}]: ${c.message}`);
|
|
116
|
+
}
|
|
117
|
+
const answer = (await res.json().catch(() => ({}))) as { answered?: boolean; answers?: string[]; text?: string; error?: string };
|
|
118
|
+
if (!res.ok) throw new Error(`write refused: '${absolute}' is outside the project folder and the question failed: ${answer.error ?? res.status}`);
|
|
119
|
+
const chosen = answer.answers?.[0] ?? '';
|
|
120
|
+
if (answer.answered && chosen === OPTION_ONCE) {
|
|
121
|
+
logger.info({ msg: 'builder.write_scope_allowed_once', agent, session, path: absolute });
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (answer.answered && chosen === OPTION_SESSION) {
|
|
125
|
+
await sessionMetaStore.update(agent, session, (current) => {
|
|
126
|
+
const prev = Array.isArray((current as Record<string, unknown>).builderWriteAllow)
|
|
127
|
+
? ((current as Record<string, unknown>).builderWriteAllow as string[])
|
|
128
|
+
: [];
|
|
129
|
+
return { ...current, builderWriteAllow: [...new Set([...prev, folder])] } as typeof current;
|
|
130
|
+
});
|
|
131
|
+
logger.info({ msg: 'builder.write_scope_allowed_session', agent, session, folder });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
logger.info({ msg: 'builder.write_scope_denied', agent, session, path: absolute, answered: answer.answered, chosen });
|
|
135
|
+
throw new Error(
|
|
136
|
+
answer.answered
|
|
137
|
+
? `write refused: the person did not allow writing '${absolute}' outside the project folder. Stay inside ${roots[0]}.`
|
|
138
|
+
: `write refused: '${absolute}' is outside the project folder and the person did not answer in time. Stay inside ${roots[0]}.`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The gate file_write and file_patch pass through after the blacklist. */
|
|
143
|
+
export async function enforceWriteScope(args: {
|
|
144
|
+
/** The path as resolved from the call (may not exist yet) — what the message names. */
|
|
145
|
+
absolute: string;
|
|
146
|
+
/** Its realpath (nearest existing ancestor resolved) — a symlink must not lead outside. */
|
|
147
|
+
real?: string;
|
|
148
|
+
agent: string;
|
|
149
|
+
session?: string;
|
|
150
|
+
config: Config;
|
|
151
|
+
}): Promise<void> {
|
|
152
|
+
if (!args.session || !isAbsolute(args.absolute)) return;
|
|
153
|
+
const persona = await loadPersona(args.agent);
|
|
154
|
+
if (!persona || persona.kind !== 'builder') return;
|
|
155
|
+
const workdir = await pinnedWorkdir(args.agent, args.session);
|
|
156
|
+
if (!workdir) return;
|
|
157
|
+
const meta = (await sessionMetaStore.get(args.agent, args.session)) as Record<string, unknown>;
|
|
158
|
+
const state = readBuilderState(meta);
|
|
159
|
+
const grants = Array.isArray(meta.builderWriteAllow) ? (meta.builderWriteAllow as string[]) : [];
|
|
160
|
+
const verdict = decideWriteScope({
|
|
161
|
+
absolute: args.absolute,
|
|
162
|
+
kind: 'builder',
|
|
163
|
+
workdir,
|
|
164
|
+
mode: state?.mode ?? 'unattended',
|
|
165
|
+
agent: args.agent,
|
|
166
|
+
sessionGrants: grants,
|
|
167
|
+
});
|
|
168
|
+
if (verdict.kind === 'unscoped') return;
|
|
169
|
+
if (verdict.kind === 'inside') {
|
|
170
|
+
// Inside by name, but a symlink on the way leads out of the folder.
|
|
171
|
+
if (args.real && !isWithinRoots(args.real, writeScopeRoots(args.agent, workdir, grants))) {
|
|
172
|
+
logger.info({ msg: 'builder.write_scope_refused', agent: args.agent, session: args.session, path: args.absolute, real: args.real, workdir, via: 'symlink' });
|
|
173
|
+
throw new Error(`write refused: '${args.absolute}' resolves to '${args.real}', outside the project folder ${workdir}.`);
|
|
174
|
+
}
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (verdict.kind === 'refused') {
|
|
178
|
+
logger.info({ msg: 'builder.write_scope_refused', agent: args.agent, session: args.session, path: args.absolute, workdir });
|
|
179
|
+
throw new Error(verdict.reason);
|
|
180
|
+
}
|
|
181
|
+
await askPerson(args.agent, args.session, args.absolute, verdict.roots);
|
|
182
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Per-agent tool visibility (design: private/mcp-hub-design.md §4.6).
|
|
2
|
+
// One filter, applied at BOTH tool-list surfaces — the in-process
|
|
3
|
+
// per-turn ToolInvoker (openai-compat) and the MCP child's tools/list
|
|
4
|
+
// (somora and external-server proxy mode) — so every engine sees
|
|
5
|
+
// the identical gated set.
|
|
6
|
+
//
|
|
7
|
+
// Pattern forms (config lives in each agent's agent.yaml `tools:`):
|
|
8
|
+
// web_search exact tool name
|
|
9
|
+
// toolset:exec every tool of a toolset tag
|
|
10
|
+
// mcp__parallel__* trailing-* glob on the name (server wildcard)
|
|
11
|
+
// Semantics: deny beats allow; empty/missing allow = everything not
|
|
12
|
+
// denied; missing section entirely = no restriction.
|
|
13
|
+
|
|
14
|
+
import type { Toolset } from './types.ts';
|
|
15
|
+
|
|
16
|
+
export interface ToolGating {
|
|
17
|
+
deny: string[];
|
|
18
|
+
allow: string[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function matchesToolPattern(pattern: string, name: string, toolset: Toolset | undefined): boolean {
|
|
22
|
+
if (pattern.startsWith('toolset:')) {
|
|
23
|
+
return toolset !== undefined && pattern.slice('toolset:'.length) === toolset;
|
|
24
|
+
}
|
|
25
|
+
if (pattern.endsWith('*')) {
|
|
26
|
+
return name.startsWith(pattern.slice(0, -1));
|
|
27
|
+
}
|
|
28
|
+
return pattern === name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What a Builder agent (agent.yaml `kind: builder`) sees by default: the
|
|
33
|
+
* coding harness set — files, shell, task list, questions, helpers,
|
|
34
|
+
* consulting colleagues, skills, the web page it was pointed at, the
|
|
35
|
+
* project it is pinned to, and read-only memory. Everything else
|
|
36
|
+
* (memory writes, dreaming, sentinel, browser, media, tmux, docs, wiki,
|
|
37
|
+
* external MCP servers) is off unless the agent's own `tools.allow`
|
|
38
|
+
* names it. A short list is the point: a local model that is offered 48
|
|
39
|
+
* tools (~19k tokens of schema per request) stops using any of them
|
|
40
|
+
* well; a coding harness offers ten to twenty.
|
|
41
|
+
*/
|
|
42
|
+
export const BUILDER_TOOL_ALLOW: readonly string[] = [
|
|
43
|
+
'file_read',
|
|
44
|
+
'file_write',
|
|
45
|
+
'file_patch',
|
|
46
|
+
'file_search',
|
|
47
|
+
'file_list',
|
|
48
|
+
'analyze_file',
|
|
49
|
+
'exec',
|
|
50
|
+
'process',
|
|
51
|
+
'todo_write',
|
|
52
|
+
'ask_user',
|
|
53
|
+
'plan_write',
|
|
54
|
+
'spawn_subagent',
|
|
55
|
+
'subagent_result',
|
|
56
|
+
'subagent_cancel',
|
|
57
|
+
'agent_ask',
|
|
58
|
+
'agent_ask_result',
|
|
59
|
+
'skill',
|
|
60
|
+
'skill_list',
|
|
61
|
+
'web_fetch',
|
|
62
|
+
'web_search',
|
|
63
|
+
'project_get',
|
|
64
|
+
'project_list',
|
|
65
|
+
'project_create',
|
|
66
|
+
'project_focus',
|
|
67
|
+
'memory_search',
|
|
68
|
+
'memory_get',
|
|
69
|
+
'time_now',
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
export type AgentKind = 'chat' | 'builder';
|
|
73
|
+
|
|
74
|
+
/** Tools of the `builder` toolset — hidden from chat agents by default. */
|
|
75
|
+
export const BUILDER_ONLY_TOOLS: ReadonlySet<string> = new Set(['todo_write', 'ask_user', 'plan_write']);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The gating a persona's turn actually runs with: the kind's defaults
|
|
79
|
+
* merged with what agent.yaml says. Chat agents: agent.yaml as is.
|
|
80
|
+
* Builders: allow = kind list ∪ agent.yaml allow, deny = agent.yaml
|
|
81
|
+
* deny — so an operator adds a tool by naming it in `allow` and removes
|
|
82
|
+
* one by naming it in `deny`, and the matrix in the web shows the result.
|
|
83
|
+
*/
|
|
84
|
+
export function effectiveToolGating(kind: AgentKind, own: ToolGating | undefined): ToolGating | undefined {
|
|
85
|
+
if (kind !== 'builder') {
|
|
86
|
+
// The builder-only tools (task list, question, plan file) need the
|
|
87
|
+
// task panel and the builder phases; a chat agent never sees them
|
|
88
|
+
// unless its own allow-list names one explicitly.
|
|
89
|
+
const namesBuilderTool = (own?.allow ?? []).some((p) => BUILDER_ONLY_TOOLS.has(p));
|
|
90
|
+
if (namesBuilderTool) return own;
|
|
91
|
+
return { deny: [...(own?.deny ?? []), 'toolset:builder'], allow: own?.allow ?? [] };
|
|
92
|
+
}
|
|
93
|
+
const allow = [...BUILDER_TOOL_ALLOW, ...(own?.allow ?? [])];
|
|
94
|
+
return { deny: own?.deny ?? [], allow: [...new Set(allow)] };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function isToolAllowed(
|
|
98
|
+
name: string,
|
|
99
|
+
toolset: Toolset | undefined,
|
|
100
|
+
gating: ToolGating | undefined,
|
|
101
|
+
): boolean {
|
|
102
|
+
if (!gating) return true;
|
|
103
|
+
if (gating.deny.some((p) => matchesToolPattern(p, name, toolset))) return false;
|
|
104
|
+
if (gating.allow.length === 0) return true;
|
|
105
|
+
return gating.allow.some((p) => matchesToolPattern(p, name, toolset));
|
|
106
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Per-turn image budget.
|
|
2
|
+
//
|
|
3
|
+
// `imageGen.maxImagesPerTurn` is a cost brake, not a rate limit: an
|
|
4
|
+
// agent set to review its own output can re-prompt in a loop, and each
|
|
5
|
+
// round is real money (4-8 cents at grok-imagine rates). The ceiling
|
|
6
|
+
// gives it room to iterate a few times and then makes it come back and
|
|
7
|
+
// ask.
|
|
8
|
+
//
|
|
9
|
+
// Scoped by turnId, which run-turn.ts owns. MCP-served calls
|
|
10
|
+
// (claude-cli / codex-cli) don't carry one; there the per-call `n` is
|
|
11
|
+
// still capped but nothing accumulates. Deriving a pseudo-turn from the
|
|
12
|
+
// session id was the alternative and is worse: the counter would never
|
|
13
|
+
// reset and the agent would be locked out of image generation for the
|
|
14
|
+
// rest of that session.
|
|
15
|
+
|
|
16
|
+
/** Bounded so a long-running server doesn't accumulate one entry per
|
|
17
|
+
* turn forever. Turns are short and the counter is only interesting
|
|
18
|
+
* while one is in flight. */
|
|
19
|
+
const MAX_TRACKED_TURNS = 500;
|
|
20
|
+
|
|
21
|
+
const spent = new Map<string, number>();
|
|
22
|
+
|
|
23
|
+
export function imagesSpentInTurn(turnId: string | undefined): number {
|
|
24
|
+
if (!turnId) return 0;
|
|
25
|
+
return spent.get(turnId) ?? 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function recordImagesInTurn(turnId: string | undefined, count: number): void {
|
|
29
|
+
if (!turnId) return;
|
|
30
|
+
// Re-insert so the key moves to the end — makes the trim below evict
|
|
31
|
+
// the least recently touched turn rather than an active one.
|
|
32
|
+
const next = (spent.get(turnId) ?? 0) + count;
|
|
33
|
+
spent.delete(turnId);
|
|
34
|
+
spent.set(turnId, next);
|
|
35
|
+
if (spent.size > MAX_TRACKED_TURNS) {
|
|
36
|
+
const oldest = spent.keys().next();
|
|
37
|
+
if (!oldest.done) spent.delete(oldest.value);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Test seam. */
|
|
42
|
+
export function resetImageBudget(): void {
|
|
43
|
+
spent.clear();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface BudgetCheck {
|
|
47
|
+
ok: boolean;
|
|
48
|
+
/** How many more images this turn may generate. Infinity when the
|
|
49
|
+
* turn isn't tracked. */
|
|
50
|
+
remaining: number;
|
|
51
|
+
reason?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function checkImageBudget(
|
|
55
|
+
turnId: string | undefined,
|
|
56
|
+
requested: number,
|
|
57
|
+
maxPerTurn: number,
|
|
58
|
+
): BudgetCheck {
|
|
59
|
+
if (requested > maxPerTurn) {
|
|
60
|
+
return {
|
|
61
|
+
ok: false,
|
|
62
|
+
remaining: maxPerTurn,
|
|
63
|
+
reason:
|
|
64
|
+
`n=${requested} exceeds imageGen.maxImagesPerTurn (${maxPerTurn}). ` +
|
|
65
|
+
`Generate at most ${maxPerTurn} images per turn.`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (!turnId) return { ok: true, remaining: Number.POSITIVE_INFINITY };
|
|
69
|
+
|
|
70
|
+
const used = imagesSpentInTurn(turnId);
|
|
71
|
+
const remaining = maxPerTurn - used;
|
|
72
|
+
if (requested > remaining) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
remaining: Math.max(0, remaining),
|
|
76
|
+
reason:
|
|
77
|
+
`this turn has already generated ${used} of ${maxPerTurn} allowed images ` +
|
|
78
|
+
`(imageGen.maxImagesPerTurn). Ask the user before generating more.`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return { ok: true, remaining };
|
|
82
|
+
}
|