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,934 @@
|
|
|
1
|
+
// `exec` and `process` tool definitions — Phase 5a.
|
|
2
|
+
//
|
|
3
|
+
// Two tools, both with target='local'|<resource-name> pattern:
|
|
4
|
+
//
|
|
5
|
+
// - exec : single-shot command. sync (default) or background.
|
|
6
|
+
// - process : interact with running background jobs. action enum:
|
|
7
|
+
// list, poll, log, write, kill.
|
|
8
|
+
//
|
|
9
|
+
// The model is steered (via tool descriptions) toward file_write for
|
|
10
|
+
// remote file writing and file_read for paging through big captured
|
|
11
|
+
// outputs — exec is for COMMANDS, not for moving file contents.
|
|
12
|
+
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
import { logger } from '../../server/logger.ts';
|
|
15
|
+
import type { ToolDefinition } from '../types.ts';
|
|
16
|
+
import { resolveVisibleResourceFresh } from '../resources/visibility.ts';
|
|
17
|
+
import { auditPrivilegedExec, evaluateExecPolicy } from './allowlist.ts';
|
|
18
|
+
import { checkBlacklist } from './blacklist.ts';
|
|
19
|
+
import { releaseRemoteSlot, tryAcquireExecSlot } from './concurrency.ts';
|
|
20
|
+
import {
|
|
21
|
+
clearLivePid,
|
|
22
|
+
clearLiveStdin,
|
|
23
|
+
completeJob,
|
|
24
|
+
failJob,
|
|
25
|
+
getLivePid,
|
|
26
|
+
getLiveStdin,
|
|
27
|
+
listJobsForAgent,
|
|
28
|
+
markJobKilled,
|
|
29
|
+
probeLocalJob,
|
|
30
|
+
readJobLog,
|
|
31
|
+
readMeta,
|
|
32
|
+
type JobMeta,
|
|
33
|
+
} from './job-store.ts';
|
|
34
|
+
import { skillEnvScopeForCommand, skillEnvStripHint } from '../../skills/env-scope.ts';
|
|
35
|
+
import { SOMORA_INTERNAL_ENV_SUMMARY } from './internal-env.ts';
|
|
36
|
+
import { killLocalJob, localExecBackground, localExecSync } from './local.ts';
|
|
37
|
+
import { fitExecOutput } from './fit-output.ts';
|
|
38
|
+
import { saveToolOutput } from '../tool-output.ts';
|
|
39
|
+
import { pinnedWorkdir } from '../../server/session-workdir.ts';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* When a stream was shortened for the result (or capped at capture),
|
|
43
|
+
* keep the captured text on disk and tell the model where. The captured
|
|
44
|
+
* text is the full output up to the 256 KB capture cap.
|
|
45
|
+
*/
|
|
46
|
+
async function saveShortenedStreams(
|
|
47
|
+
agent: string,
|
|
48
|
+
r: { stdout: string; stderr: string; truncated: boolean },
|
|
49
|
+
shortened: boolean,
|
|
50
|
+
): Promise<{ files: { stdout_file?: string; stderr_file?: string }; hint?: string }> {
|
|
51
|
+
if (!shortened && !r.truncated) return { files: {} };
|
|
52
|
+
const files: { stdout_file?: string; stderr_file?: string } = {};
|
|
53
|
+
if (r.stdout.length > 0) {
|
|
54
|
+
const f = await saveToolOutput(agent, 'exec-stdout', r.stdout);
|
|
55
|
+
if (f) files.stdout_file = f;
|
|
56
|
+
}
|
|
57
|
+
if (r.stderr.length > 0) {
|
|
58
|
+
const f = await saveToolOutput(agent, 'exec-stderr', r.stderr);
|
|
59
|
+
if (f) files.stderr_file = f;
|
|
60
|
+
}
|
|
61
|
+
if (!files.stdout_file && !files.stderr_file) return { files };
|
|
62
|
+
const parts: string[] = [];
|
|
63
|
+
if (files.stdout_file) parts.push(`stdout (${r.stdout.length} chars) → ${files.stdout_file}`);
|
|
64
|
+
if (files.stderr_file) parts.push(`stderr (${r.stderr.length} chars) → ${files.stderr_file}`);
|
|
65
|
+
const capNote = r.truncated ? ' (capture stopped at 256 KB per stream)' : '';
|
|
66
|
+
return {
|
|
67
|
+
files,
|
|
68
|
+
hint:
|
|
69
|
+
`Full captured output saved${capNote}: ${parts.join('; ')}. ` +
|
|
70
|
+
`Read a part with file_read offset/limit or search in it with file_search instead of re-running the command.`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
import {
|
|
74
|
+
killRemoteJob,
|
|
75
|
+
pollRemoteJob,
|
|
76
|
+
remoteExecBackground,
|
|
77
|
+
remoteExecSync,
|
|
78
|
+
tailRemoteJobLog,
|
|
79
|
+
} from './remote.ts';
|
|
80
|
+
|
|
81
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
82
|
+
// exec
|
|
83
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
84
|
+
|
|
85
|
+
const ExecInput = z
|
|
86
|
+
.object({
|
|
87
|
+
command: z
|
|
88
|
+
.string()
|
|
89
|
+
.min(1)
|
|
90
|
+
.describe('Shell command to run. Interpreted by the target machine\'s default shell (bash/zsh/dash).'),
|
|
91
|
+
target: z
|
|
92
|
+
.string()
|
|
93
|
+
.min(1)
|
|
94
|
+
.default('local')
|
|
95
|
+
.describe(
|
|
96
|
+
'"local" (default) = the somora server\'s machine. Otherwise a configured ' +
|
|
97
|
+
'resource name from resource_list. Resources must be set up in config.yaml — exec ' +
|
|
98
|
+
'cannot dial ad-hoc SSH targets.',
|
|
99
|
+
),
|
|
100
|
+
cwd: z
|
|
101
|
+
.string()
|
|
102
|
+
.min(1)
|
|
103
|
+
.optional()
|
|
104
|
+
.describe(
|
|
105
|
+
'Working directory on the target machine. Absolute path, "~/..." or relative ' +
|
|
106
|
+
'(both resolved against the target user\'s home). Must be an existing directory — ' +
|
|
107
|
+
'exec fails with a cwd error otherwise.',
|
|
108
|
+
),
|
|
109
|
+
env: z
|
|
110
|
+
.record(z.string(), z.string())
|
|
111
|
+
.optional()
|
|
112
|
+
.describe('Extra environment variables to merge into the command shell. Local target only in v1.'),
|
|
113
|
+
background: z
|
|
114
|
+
.boolean()
|
|
115
|
+
.default(false)
|
|
116
|
+
.describe(
|
|
117
|
+
'true = fire-and-forget. Returns a job_id immediately; output streams to disk; ' +
|
|
118
|
+
'use process tool to poll/kill/read. Only supported on target="local" in v1.',
|
|
119
|
+
),
|
|
120
|
+
timeout_ms: z
|
|
121
|
+
.number()
|
|
122
|
+
.int()
|
|
123
|
+
.min(100)
|
|
124
|
+
.max(3_600_000)
|
|
125
|
+
.default(60_000)
|
|
126
|
+
.describe(
|
|
127
|
+
'Sync only. Kill after this. Default 60s, max 1h. Ignored when background:true. ' +
|
|
128
|
+
'When you intentionally run a long-blocking command, set this above the expected ' +
|
|
129
|
+
'duration — e.g. for `sleep N` use `timeout_ms: (N+5)*1000`. The 60s default exists ' +
|
|
130
|
+
'so a runaway command can\'t lock a tool slot for an hour.',
|
|
131
|
+
),
|
|
132
|
+
pty: z
|
|
133
|
+
.boolean()
|
|
134
|
+
.default(false)
|
|
135
|
+
.describe(
|
|
136
|
+
'Allocate a pseudo-terminal so TUI tools and tools that check isatty() ' +
|
|
137
|
+
'(vim, htop, claude, codex, color/cursor handling, progress bars) work correctly. ' +
|
|
138
|
+
'Works on both target=local (via node-pty) and target=<resource> (via ssh2 native ' +
|
|
139
|
+
'pty allocation). When pty is on, stdout and stderr merge into one stream ' +
|
|
140
|
+
'(= same behavior as a real terminal). Background mode ignores this flag — ' +
|
|
141
|
+
'TUI tools running in the background nobody can see; use tmux for that.',
|
|
142
|
+
),
|
|
143
|
+
description: z
|
|
144
|
+
.string()
|
|
145
|
+
.min(1)
|
|
146
|
+
.max(200)
|
|
147
|
+
.optional()
|
|
148
|
+
.describe('Short human-readable label for this command. Surfaces in process_list and logs.'),
|
|
149
|
+
inherit_agent_env: z
|
|
150
|
+
.boolean()
|
|
151
|
+
.default(false)
|
|
152
|
+
.describe(
|
|
153
|
+
'local target only. When false (default), the shell gets a curated env: somora-internal ' +
|
|
154
|
+
`vars (${SOMORA_INTERNAL_ENV_SUMMARY}) are stripped before spawn, so a \`claude\` / ` +
|
|
155
|
+
'`codex` invocation behaves like in the user\'s normal terminal and a project\'s own ' +
|
|
156
|
+
'tsx/next/dotenv see their own config, not somora\'s. Set true only when you ' +
|
|
157
|
+
'intentionally want somora\'s isolated claude tree and runtime vars visible to the ' +
|
|
158
|
+
'spawned process.',
|
|
159
|
+
),
|
|
160
|
+
})
|
|
161
|
+
.strict();
|
|
162
|
+
|
|
163
|
+
interface ExecSyncResult {
|
|
164
|
+
ok: boolean;
|
|
165
|
+
background: false;
|
|
166
|
+
target: string;
|
|
167
|
+
exit_code: number | null;
|
|
168
|
+
stdout: string;
|
|
169
|
+
stderr: string;
|
|
170
|
+
truncated: boolean;
|
|
171
|
+
ms: number;
|
|
172
|
+
hint?: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
interface ExecBackgroundResult {
|
|
176
|
+
ok: true;
|
|
177
|
+
background: true;
|
|
178
|
+
job_id: string;
|
|
179
|
+
pid: number;
|
|
180
|
+
target: string;
|
|
181
|
+
hint: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface ExecBlockedResult {
|
|
185
|
+
ok: false;
|
|
186
|
+
background: false;
|
|
187
|
+
blocked: true;
|
|
188
|
+
reason: string;
|
|
189
|
+
pattern: string;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface ExecCapDeniedResult {
|
|
193
|
+
ok: false;
|
|
194
|
+
background: true;
|
|
195
|
+
cap_denied: true;
|
|
196
|
+
reason: string;
|
|
197
|
+
per_agent_cap: number;
|
|
198
|
+
global_cap: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type ExecResult =
|
|
202
|
+
| ExecSyncResult
|
|
203
|
+
| ExecBackgroundResult
|
|
204
|
+
| ExecBlockedResult
|
|
205
|
+
| ExecCapDeniedResult;
|
|
206
|
+
|
|
207
|
+
export const exec: ToolDefinition<z.infer<typeof ExecInput>, ExecResult> = {
|
|
208
|
+
name: 'exec',
|
|
209
|
+
toolset: 'exec',
|
|
210
|
+
description:
|
|
211
|
+
'Run a shell command on the somora server (target:"local") or on a configured SSH resource ' +
|
|
212
|
+
'(target:<resource-name> from resource_list). Default: synchronous, returns stdout/stderr/exit. ' +
|
|
213
|
+
'Set background:true for long-running tasks (build, test-suite, dev server) — returns a ' +
|
|
214
|
+
'job_id immediately, output streams to disk, interact via the process tool ' +
|
|
215
|
+
'(list/poll/log/write/kill). Background jobs are fully detached: they keep running across ' +
|
|
216
|
+
'turns and somora/MCP restarts until they finish or you kill them. Note: process write ' +
|
|
217
|
+
'(stdin) only works while the somora process that spawned the job is alive. ' +
|
|
218
|
+
'\n\n' +
|
|
219
|
+
'IMPORTANT — to reach a remote host, ALWAYS use target:<resource-name> (from resource_list). ' +
|
|
220
|
+
'NEVER shell out to raw `ssh user@host …` from target:"local" — that bypasses the resource ' +
|
|
221
|
+
'config, hits hosts without keys, and produces "Permission denied (publickey,password)" errors. ' +
|
|
222
|
+
'If a host you need is not in resource_list, ask the user to add it to config.yaml first. ' +
|
|
223
|
+
'\n\n' +
|
|
224
|
+
'IMPORTANT — non-empty stderr does NOT mean failure. Many tools (ssh, git, build systems) write ' +
|
|
225
|
+
'progress / warnings to stderr while still exiting 0. Treat the call as failed ONLY when ' +
|
|
226
|
+
'`ok:false` OR `exit_code != 0`. Do not retry just because stderr has content — read it for ' +
|
|
227
|
+
'context but trust the exit status. ' +
|
|
228
|
+
'\n\n' +
|
|
229
|
+
'IMPORTANT — for writing FILES on a remote target, ALWAYS use file_write with target:<name>. ' +
|
|
230
|
+
'NEVER use exec with heredoc/echo to push file content over SSH — shell escaping breaks for ' +
|
|
231
|
+
'large or complex content. file_write goes through SFTP, binary-clean, no escape pain. ' +
|
|
232
|
+
'\n\n' +
|
|
233
|
+
'Remote targets have NO assumed binaries beyond POSIX core (sh, ls, cat, cp, mv, find, …). ' +
|
|
234
|
+
'jq, python, node, rg etc. may be missing — probe first with `which <bin>` or `command -v` ' +
|
|
235
|
+
'before relying on them, or pipe a JSON post-processor through stdin on the local side. ' +
|
|
236
|
+
'\n\n' +
|
|
237
|
+
'Output: a sync result carries about 60 000 chars of stdout+stderr. Longer output comes back as ' +
|
|
238
|
+
'the first and last part of each stream with the cut marked in the text and truncated:true — ' +
|
|
239
|
+
'never guess the omitted middle; redirect to a file and file_read it, or narrow the command. ' +
|
|
240
|
+
'Capture cap: 256 KB per stream, also for process_log tail reads. If your command ' +
|
|
241
|
+
'produces more output, write it to a file on the target (e.g. ./out.log) and use file_read ' +
|
|
242
|
+
'with offset/limit to page through. ' +
|
|
243
|
+
'\n\n' +
|
|
244
|
+
'Hard-blocked: rm -rf / and other destructive system ops, sudo/doas, fork bombs, system ' +
|
|
245
|
+
'shutdown, chmod world-writable on /etc /usr /bin /sbin /boot /root /var /opt, reading ' +
|
|
246
|
+
'private SSH keys, curl|sh / wget|sh untrusted-remote-exec patterns. Match → blocked:true ' +
|
|
247
|
+
'in result with reason; the model should adapt the command rather than retry. ' +
|
|
248
|
+
'\n\n' +
|
|
249
|
+
'Per-resource override: a configured SSH resource may have an `allowBlocked` list in ' +
|
|
250
|
+
'config.yaml that whitelists specific commands (e.g. `sudo ~/bin/update.sh`, `systemctl ' +
|
|
251
|
+
'reboot`) despite the global block. Check resource_list — entries with allowBlockedCount>0 ' +
|
|
252
|
+
'have privileged overrides. local target is never overridable.',
|
|
253
|
+
inputSchema: ExecInput,
|
|
254
|
+
jsonSchema: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
properties: {
|
|
257
|
+
command: { type: 'string', description: 'Shell command.' },
|
|
258
|
+
target: { type: 'string', description: '"local" or resource name.', default: 'local' },
|
|
259
|
+
cwd: {
|
|
260
|
+
type: 'string',
|
|
261
|
+
description:
|
|
262
|
+
'Working directory. Absolute, "~/..." or relative-to-target-home; must exist. Default: the folder of the project pinned to this session (when it has a workdir), else the server process cwd.',
|
|
263
|
+
},
|
|
264
|
+
env: { type: 'object', additionalProperties: { type: 'string' } },
|
|
265
|
+
background: { type: 'boolean', default: false },
|
|
266
|
+
timeout_ms: { type: 'integer', minimum: 100, maximum: 3_600_000, default: 60_000 },
|
|
267
|
+
pty: { type: 'boolean', default: false },
|
|
268
|
+
description: { type: 'string', maxLength: 200 },
|
|
269
|
+
inherit_agent_env: {
|
|
270
|
+
type: 'boolean',
|
|
271
|
+
default: false,
|
|
272
|
+
description:
|
|
273
|
+
`local only. Default false: somora-internal env (${SOMORA_INTERNAL_ENV_SUMMARY}) is stripped ` +
|
|
274
|
+
'so a project\'s own tsx/next/dotenv and a nested claude/codex behave like in a normal terminal. ' +
|
|
275
|
+
'true = inherit everything.',
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
required: ['command'],
|
|
279
|
+
additionalProperties: false,
|
|
280
|
+
},
|
|
281
|
+
// Engine-level race: sync exec gets the caller's timeout_ms +2s
|
|
282
|
+
// buffer (OpenClaw pattern). Background returns instantly so the
|
|
283
|
+
// 30s default is plenty.
|
|
284
|
+
defaultTimeoutMs: 30_000,
|
|
285
|
+
timeoutFromInput: (input) =>
|
|
286
|
+
input.background ? undefined : (input.timeout_ms ?? 60_000) + 2_000,
|
|
287
|
+
maxTimeoutMs: 3_600_000 + 2_000,
|
|
288
|
+
async handler(input, ctx): Promise<ExecResult> {
|
|
289
|
+
// Hard-blacklist runs FIRST — never even reach a target if the
|
|
290
|
+
// command is in the deny list.
|
|
291
|
+
const block = checkBlacklist(input.command);
|
|
292
|
+
if (block.matched) {
|
|
293
|
+
// Per-resource allowlist override: if the target is a configured
|
|
294
|
+
// SSH resource, evaluate the command against its `allowBlocked`
|
|
295
|
+
// list segment-by-segment. `local` target NEVER gets an override
|
|
296
|
+
// (the host where somora runs is not a dedicated-agent-workstation)
|
|
297
|
+
// — we pass an empty entry list so evaluateExecPolicy always
|
|
298
|
+
// blocks there. See src/tools/exec/allowlist.ts for the algorithm
|
|
299
|
+
// (each blacklisted sub-command needs its own override; hard-blocks
|
|
300
|
+
// like `rm -rf /etc` and cross-pipe `curl|sh` can't be overridden).
|
|
301
|
+
let entries: ReadonlyArray<string> = [];
|
|
302
|
+
if (input.target !== 'local') {
|
|
303
|
+
const resource = await resolveVisibleResourceFresh(ctx.agent, input.target);
|
|
304
|
+
if (resource && resource.type === 'ssh') {
|
|
305
|
+
entries = resource.allowBlocked;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const policy = evaluateExecPolicy(input.command, entries);
|
|
309
|
+
if (policy.allowed) {
|
|
310
|
+
logger.info({
|
|
311
|
+
msg: 'exec.privileged_allowed',
|
|
312
|
+
agent: ctx.agent,
|
|
313
|
+
target: input.target,
|
|
314
|
+
matched_entries: policy.overrides ?? [],
|
|
315
|
+
blacklist_reason: block.reason,
|
|
316
|
+
command_head: input.command.slice(0, 120),
|
|
317
|
+
});
|
|
318
|
+
// Audit-trail JSONL — fire-and-forget. We deliberately log
|
|
319
|
+
// the AUTH event (matched + about-to-execute), not the
|
|
320
|
+
// completion: the rest of somora's exec logging captures
|
|
321
|
+
// exit codes, and one line per privileged-allow is the
|
|
322
|
+
// simplest after-the-fact review surface.
|
|
323
|
+
void auditPrivilegedExec({
|
|
324
|
+
ts: Date.now(),
|
|
325
|
+
agent: ctx.agent,
|
|
326
|
+
session: ctx.session ?? 'unknown',
|
|
327
|
+
resource: input.target,
|
|
328
|
+
command_head: input.command.slice(0, 200),
|
|
329
|
+
matched_entry: (policy.overrides ?? []).join(', '),
|
|
330
|
+
blacklist_reason: block.reason,
|
|
331
|
+
blacklist_pattern: block.pattern,
|
|
332
|
+
});
|
|
333
|
+
} else {
|
|
334
|
+
logger.warn({
|
|
335
|
+
msg: 'exec.blocked',
|
|
336
|
+
agent: ctx.agent,
|
|
337
|
+
target: input.target,
|
|
338
|
+
reason: policy.reason ?? block.reason,
|
|
339
|
+
pattern: policy.pattern ?? block.pattern,
|
|
340
|
+
command_head: input.command.slice(0, 120),
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
ok: false,
|
|
344
|
+
background: false,
|
|
345
|
+
blocked: true,
|
|
346
|
+
reason: policy.reason ?? block.reason,
|
|
347
|
+
pattern: policy.pattern ?? block.pattern,
|
|
348
|
+
...(policy.segment ? { blocked_segment: policy.segment } : {}),
|
|
349
|
+
...(policy.hint ? { hint: policy.hint } : {}),
|
|
350
|
+
// Surface the resource's allowBlocked entries (if any) so the
|
|
351
|
+
// agent can see why none of them cleared this command instead
|
|
352
|
+
// of having to reverse-engineer the matcher (2026-07-27
|
|
353
|
+
// feedback). Entries match a segment when it equals the entry
|
|
354
|
+
// or starts with `entry + ' '`, and command substitution
|
|
355
|
+
// ($(…)/backticks) always blocks.
|
|
356
|
+
...(entries.length > 0 ? { allow_blocked_entries: [...entries] } : {}),
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (input.background) {
|
|
362
|
+
// Concurrency cap — protects the host from runaway-loop spawn.
|
|
363
|
+
// Counted across both local AND remote BG jobs since the load
|
|
364
|
+
// matters regardless of which machine the work lands on. Slot is
|
|
365
|
+
// released in job-store completion paths.
|
|
366
|
+
//
|
|
367
|
+
// Per-agent count comes from DISK (post-liveness-probe), not
|
|
368
|
+
// only the in-memory counter: detached jobs survive somora/MCP
|
|
369
|
+
// restarts, so a fresh process would otherwise under-count and
|
|
370
|
+
// over-spawn. The probe also clears stale 'running' states so a
|
|
371
|
+
// dead job can never wedge the cap.
|
|
372
|
+
const diskJobs = await listJobsForAgent(ctx.agent);
|
|
373
|
+
const diskRunning = (
|
|
374
|
+
await Promise.all(
|
|
375
|
+
diskJobs
|
|
376
|
+
.filter((j) => j.state === 'running')
|
|
377
|
+
.map((j) => probeLocalJob(ctx.agent, j)),
|
|
378
|
+
)
|
|
379
|
+
).filter((j) => j.state === 'running').length;
|
|
380
|
+
const slot = tryAcquireExecSlot(ctx.agent, diskRunning);
|
|
381
|
+
if (!slot.ok) {
|
|
382
|
+
logger.warn({
|
|
383
|
+
msg: 'exec.background.cap_denied',
|
|
384
|
+
agent: ctx.agent,
|
|
385
|
+
target: input.target,
|
|
386
|
+
per_agent_now: slot.perAgentNow,
|
|
387
|
+
global_now: slot.globalNow,
|
|
388
|
+
reason: slot.reason,
|
|
389
|
+
});
|
|
390
|
+
return {
|
|
391
|
+
ok: false,
|
|
392
|
+
background: true,
|
|
393
|
+
cap_denied: true,
|
|
394
|
+
reason: slot.reason,
|
|
395
|
+
per_agent_cap: slot.perAgentCap,
|
|
396
|
+
global_cap: slot.globalCap,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
try {
|
|
400
|
+
if (input.target === 'local') {
|
|
401
|
+
const bgSkillScope = await skillEnvScopeForCommand(input.command, ctx.config);
|
|
402
|
+
const result = await localExecBackground({
|
|
403
|
+
agent: ctx.agent,
|
|
404
|
+
command: input.command,
|
|
405
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
406
|
+
...(input.env ? { env: input.env } : {}),
|
|
407
|
+
...(input.description ? { description: input.description } : {}),
|
|
408
|
+
releaseSlot: slot.release,
|
|
409
|
+
stripSomoraInternalEnv: !input.inherit_agent_env,
|
|
410
|
+
...(bgSkillScope ? { skillEnvScope: bgSkillScope } : {}),
|
|
411
|
+
});
|
|
412
|
+
return {
|
|
413
|
+
ok: true,
|
|
414
|
+
background: true,
|
|
415
|
+
job_id: result.job_id,
|
|
416
|
+
pid: result.pid,
|
|
417
|
+
target: 'local',
|
|
418
|
+
hint:
|
|
419
|
+
`Job started in the background. Use process({action:"poll", job_id:"${result.job_id}"}) ` +
|
|
420
|
+
`to check status, process({action:"log", job_id:"${result.job_id}"}) for output, ` +
|
|
421
|
+
`process({action:"kill", job_id:"${result.job_id}"}) to terminate.`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
// Remote target — nohup-pattern, slot is released when the
|
|
425
|
+
// job is detected complete via process({action:"poll"}) or
|
|
426
|
+
// explicitly killed. process tool calls completeJob/failJob/
|
|
427
|
+
// markJobKilled which can in turn signal release; for v1 we
|
|
428
|
+
// accept that the slot remains held until either a poll
|
|
429
|
+
// resolves the job or it's killed. The cap protects against
|
|
430
|
+
// floods, not against long-running jobs.
|
|
431
|
+
const remote = await remoteExecBackground({
|
|
432
|
+
agent: ctx.agent,
|
|
433
|
+
target: input.target,
|
|
434
|
+
command: input.command,
|
|
435
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
436
|
+
...(input.description ? { description: input.description } : {}),
|
|
437
|
+
releaseSlot: slot.release,
|
|
438
|
+
});
|
|
439
|
+
return {
|
|
440
|
+
ok: true,
|
|
441
|
+
background: true,
|
|
442
|
+
job_id: remote.job_id,
|
|
443
|
+
pid: remote.remote_pid,
|
|
444
|
+
target: input.target,
|
|
445
|
+
hint:
|
|
446
|
+
`Remote job started on ${input.target} (pid=${remote.remote_pid}). Output streams to ` +
|
|
447
|
+
`${remote.remote_out_file} / ${remote.remote_err_file} on the remote host. Use ` +
|
|
448
|
+
`process({action:"poll", job_id:"${remote.job_id}"}) to check status, ` +
|
|
449
|
+
`process({action:"log", job_id:"${remote.job_id}"}) for tail, ` +
|
|
450
|
+
`process({action:"kill", job_id:"${remote.job_id}"}) to terminate. ` +
|
|
451
|
+
`Note: ${remote.remote_out_file} stays on the remote host even after the job ends — ` +
|
|
452
|
+
`clean up via exec({command:"rm /tmp/somora-exec-${remote.job_id}.*", target:"${input.target}"}) when done.`,
|
|
453
|
+
};
|
|
454
|
+
} catch (err) {
|
|
455
|
+
// Spawn failed — release the slot so the cap doesn't leak.
|
|
456
|
+
slot.release();
|
|
457
|
+
throw err;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ── sync path ──
|
|
462
|
+
if (input.target === 'local') {
|
|
463
|
+
// Skill-scoped env: strip all skill-declared secrets, re-inject
|
|
464
|
+
// only those whose skill's bins this command invokes. Logged when
|
|
465
|
+
// it actually matched — forensics for "why does/doesn't my skill
|
|
466
|
+
// command see its env var".
|
|
467
|
+
const skillScope = await skillEnvScopeForCommand(input.command, ctx.config);
|
|
468
|
+
if (skillScope && skillScope.matchedSkills.length > 0) {
|
|
469
|
+
logger.info({
|
|
470
|
+
msg: 'exec.skill_env_injected',
|
|
471
|
+
agent: ctx.agent,
|
|
472
|
+
skills: skillScope.matchedSkills,
|
|
473
|
+
vars: Object.keys(skillScope.injectEnv),
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
// Default cwd: the folder of the project pinned to this session,
|
|
477
|
+
// when it has one (docs/projects.md `workdir`); else the server's.
|
|
478
|
+
const localCwd = input.cwd ?? (await pinnedWorkdir(ctx.agent, ctx.session)) ?? undefined;
|
|
479
|
+
const r = await localExecSync({
|
|
480
|
+
command: input.command,
|
|
481
|
+
...(localCwd ? { cwd: localCwd } : {}),
|
|
482
|
+
...(input.env ? { env: input.env } : {}),
|
|
483
|
+
timeoutMs: input.timeout_ms ?? 60_000,
|
|
484
|
+
pty: input.pty,
|
|
485
|
+
stripSomoraInternalEnv: !input.inherit_agent_env,
|
|
486
|
+
...(skillScope ? { skillEnvScope: skillScope } : {}),
|
|
487
|
+
...(ctx.signal ? { signal: ctx.signal } : {}),
|
|
488
|
+
});
|
|
489
|
+
// A stripped skill var named in a failed command's output is
|
|
490
|
+
// almost always an indirect bin call — say so, or the agent reads
|
|
491
|
+
// the bin's "set VAR" message as a broken bootstrap.
|
|
492
|
+
const stripHint = skillEnvStripHint(skillScope, r.exit_code, `${r.stdout}\n${r.stderr}`);
|
|
493
|
+
if (stripHint) {
|
|
494
|
+
logger.info({
|
|
495
|
+
msg: 'exec.skill_env_stripped_hint',
|
|
496
|
+
agent: ctx.agent,
|
|
497
|
+
vars: skillScope?.stripVars.filter((v) => !(v in (skillScope?.injectEnv ?? {}))),
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
const fitted = fitExecOutput(r.stdout, r.stderr);
|
|
501
|
+
const saved = await saveShortenedStreams(ctx.agent, r, fitted.shortened);
|
|
502
|
+
const hint = [stripHint, fitted.hint, saved.hint].filter(Boolean).join(' ');
|
|
503
|
+
return {
|
|
504
|
+
ok: r.exit_code === 0,
|
|
505
|
+
background: false,
|
|
506
|
+
target: 'local',
|
|
507
|
+
exit_code: r.exit_code,
|
|
508
|
+
stdout: fitted.stdout,
|
|
509
|
+
stderr: fitted.stderr,
|
|
510
|
+
// One flag for every way the text can be incomplete: the 256 KB
|
|
511
|
+
// capture cap AND the result budget (fit-output.ts).
|
|
512
|
+
truncated: r.truncated || fitted.shortened,
|
|
513
|
+
ms: r.ms,
|
|
514
|
+
...saved.files,
|
|
515
|
+
...(hint ? { hint } : {}),
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Remote sync — env not threaded yet (ssh2 exec doesn't take it
|
|
520
|
+
// as easily as local; would need shell-quoting). Surface a hint
|
|
521
|
+
// if the model tries to set env on remote.
|
|
522
|
+
if (input.env) {
|
|
523
|
+
logger.info({
|
|
524
|
+
msg: 'exec.remote.env_ignored',
|
|
525
|
+
target: input.target,
|
|
526
|
+
keys: Object.keys(input.env),
|
|
527
|
+
hint: 'env-on-remote requires shell-quoted prefix; v1 ignores. Use cwd or cd in command.',
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
const rr = await remoteExecSync({
|
|
531
|
+
agent: ctx.agent,
|
|
532
|
+
target: input.target,
|
|
533
|
+
command: input.command,
|
|
534
|
+
...(input.cwd ? { cwd: input.cwd } : {}),
|
|
535
|
+
timeoutMs: input.timeout_ms ?? 60_000,
|
|
536
|
+
...(input.pty ? { pty: true } : {}),
|
|
537
|
+
});
|
|
538
|
+
const rfitted = fitExecOutput(rr.stdout, rr.stderr);
|
|
539
|
+
const rsaved = await saveShortenedStreams(ctx.agent, rr, rfitted.shortened);
|
|
540
|
+
const rhint = [rfitted.hint, rsaved.hint].filter(Boolean).join(' ');
|
|
541
|
+
return {
|
|
542
|
+
ok: rr.exit_code === 0,
|
|
543
|
+
background: false,
|
|
544
|
+
target: input.target,
|
|
545
|
+
exit_code: rr.exit_code,
|
|
546
|
+
stdout: rfitted.stdout,
|
|
547
|
+
stderr: rfitted.stderr,
|
|
548
|
+
truncated: rr.truncated || rfitted.shortened,
|
|
549
|
+
ms: rr.ms,
|
|
550
|
+
...rsaved.files,
|
|
551
|
+
...(rhint ? { hint: rhint } : {}),
|
|
552
|
+
};
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
557
|
+
// process — action enum for interacting with background exec jobs
|
|
558
|
+
// ─────────────────────────────────────────────────────────────────────
|
|
559
|
+
|
|
560
|
+
const ProcessInput = z
|
|
561
|
+
.object({
|
|
562
|
+
action: z
|
|
563
|
+
.enum(['list', 'poll', 'log', 'write', 'kill'])
|
|
564
|
+
.describe(
|
|
565
|
+
'list (no other fields) | poll (job_id) | log (job_id, tail_lines?) | ' +
|
|
566
|
+
'write (job_id, text) | kill (job_id, signal?)',
|
|
567
|
+
),
|
|
568
|
+
job_id: z
|
|
569
|
+
.string()
|
|
570
|
+
.min(1)
|
|
571
|
+
.optional()
|
|
572
|
+
.describe('Required for poll/log/write/kill. From the job_id returned by exec({background:true}).'),
|
|
573
|
+
text: z
|
|
574
|
+
.string()
|
|
575
|
+
.optional()
|
|
576
|
+
.describe('write only — text to send to the job\'s stdin. Append \\n yourself if needed.'),
|
|
577
|
+
tail_lines: z
|
|
578
|
+
.number()
|
|
579
|
+
.int()
|
|
580
|
+
.min(1)
|
|
581
|
+
.max(2000)
|
|
582
|
+
.default(50)
|
|
583
|
+
.describe('log only — how many lines from the END of stdout/stderr each. Default 50.'),
|
|
584
|
+
signal: z
|
|
585
|
+
.enum(['SIGTERM', 'SIGKILL', 'SIGINT', 'SIGHUP'])
|
|
586
|
+
.default('SIGTERM')
|
|
587
|
+
.describe('kill only — signal to send. Default SIGTERM (graceful).'),
|
|
588
|
+
})
|
|
589
|
+
.strict();
|
|
590
|
+
|
|
591
|
+
interface ProcessListResult {
|
|
592
|
+
action: 'list';
|
|
593
|
+
count: number;
|
|
594
|
+
jobs: Array<{
|
|
595
|
+
job_id: string;
|
|
596
|
+
target: string;
|
|
597
|
+
state: JobMeta['state'];
|
|
598
|
+
started_at: number;
|
|
599
|
+
ended_at?: number;
|
|
600
|
+
exit_code?: number | null;
|
|
601
|
+
description?: string;
|
|
602
|
+
command_head: string;
|
|
603
|
+
ms?: number;
|
|
604
|
+
}>;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
interface ProcessPollResult {
|
|
608
|
+
action: 'poll';
|
|
609
|
+
job_id: string;
|
|
610
|
+
state: JobMeta['state'];
|
|
611
|
+
exit_code: number | null | undefined;
|
|
612
|
+
pid: number | null;
|
|
613
|
+
ms: number;
|
|
614
|
+
error?: string;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
interface ProcessLogResult {
|
|
618
|
+
action: 'log';
|
|
619
|
+
job_id: string;
|
|
620
|
+
stdout_tail: string;
|
|
621
|
+
stderr_tail: string;
|
|
622
|
+
total_stdout_bytes: number;
|
|
623
|
+
total_stderr_bytes: number;
|
|
624
|
+
truncated: boolean;
|
|
625
|
+
hint?: string;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
interface ProcessWriteResult {
|
|
629
|
+
action: 'write';
|
|
630
|
+
job_id: string;
|
|
631
|
+
ok: boolean;
|
|
632
|
+
bytes_written: number;
|
|
633
|
+
error?: string;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
interface ProcessKillResult {
|
|
637
|
+
action: 'kill';
|
|
638
|
+
job_id: string;
|
|
639
|
+
ok: boolean;
|
|
640
|
+
/** null when no signal was sent (job already ended). */
|
|
641
|
+
signal_sent: string | null;
|
|
642
|
+
was_running: boolean;
|
|
643
|
+
note?: string;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
type ProcessResult =
|
|
647
|
+
| ProcessListResult
|
|
648
|
+
| ProcessPollResult
|
|
649
|
+
| ProcessLogResult
|
|
650
|
+
| ProcessWriteResult
|
|
651
|
+
| ProcessKillResult;
|
|
652
|
+
|
|
653
|
+
function tailLines(text: string, n: number): string {
|
|
654
|
+
if (!text) return '';
|
|
655
|
+
const lines = text.split('\n');
|
|
656
|
+
if (lines.length <= n) return text;
|
|
657
|
+
return lines.slice(-n).join('\n');
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
export const processTool: ToolDefinition<z.infer<typeof ProcessInput>, ProcessResult> = {
|
|
661
|
+
name: 'process',
|
|
662
|
+
toolset: 'exec',
|
|
663
|
+
description:
|
|
664
|
+
'Interact with background exec jobs. action="list" shows your agent\'s known jobs (newest ' +
|
|
665
|
+
'first). action="poll" returns the current state of one job. action="log" returns the tail ' +
|
|
666
|
+
'of stdout+stderr. action="write" pipes text into the job\'s stdin (local only). action="kill" ' +
|
|
667
|
+
'sends a signal. Use exec({background:true}) to spawn jobs first; the job_id from that result ' +
|
|
668
|
+
'feeds back into the actions here.',
|
|
669
|
+
inputSchema: ProcessInput,
|
|
670
|
+
jsonSchema: {
|
|
671
|
+
type: 'object',
|
|
672
|
+
properties: {
|
|
673
|
+
action: { type: 'string', enum: ['list', 'poll', 'log', 'write', 'kill'] },
|
|
674
|
+
job_id: { type: 'string' },
|
|
675
|
+
text: { type: 'string' },
|
|
676
|
+
tail_lines: { type: 'integer', minimum: 1, maximum: 2000, default: 50 },
|
|
677
|
+
signal: {
|
|
678
|
+
type: 'string',
|
|
679
|
+
enum: ['SIGTERM', 'SIGKILL', 'SIGINT', 'SIGHUP'],
|
|
680
|
+
default: 'SIGTERM',
|
|
681
|
+
},
|
|
682
|
+
},
|
|
683
|
+
required: ['action'],
|
|
684
|
+
additionalProperties: false,
|
|
685
|
+
},
|
|
686
|
+
async handler(input, ctx): Promise<ProcessResult> {
|
|
687
|
+
if (input.action === 'list') {
|
|
688
|
+
const listed = await listJobsForAgent(ctx.agent);
|
|
689
|
+
// Resolve stale 'running' states for local jobs before rendering
|
|
690
|
+
// — a job spawned by a previous somora/MCP process has no exit
|
|
691
|
+
// listener in THIS process, so meta alone can lie (2026-07-27
|
|
692
|
+
// report). probeLocalJob is a no-op for terminal/remote jobs.
|
|
693
|
+
const jobs = await Promise.all(listed.map((j) => probeLocalJob(ctx.agent, j)));
|
|
694
|
+
return {
|
|
695
|
+
action: 'list',
|
|
696
|
+
count: jobs.length,
|
|
697
|
+
jobs: jobs.map((j) => ({
|
|
698
|
+
job_id: j.job_id,
|
|
699
|
+
target: j.target,
|
|
700
|
+
state: j.state,
|
|
701
|
+
started_at: j.started_at,
|
|
702
|
+
...(j.ended_at !== undefined ? { ended_at: j.ended_at } : {}),
|
|
703
|
+
...(j.exit_code !== undefined ? { exit_code: j.exit_code } : {}),
|
|
704
|
+
...(j.description ? { description: j.description } : {}),
|
|
705
|
+
command_head: j.command.slice(0, 120),
|
|
706
|
+
...(j.ended_at !== undefined ? { ms: j.ended_at - j.started_at } : {}),
|
|
707
|
+
})),
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// poll/log/write/kill all need job_id
|
|
712
|
+
if (!input.job_id) {
|
|
713
|
+
throw new Error(`process: action='${input.action}' requires job_id`);
|
|
714
|
+
}
|
|
715
|
+
const meta = await readMeta(ctx.agent, input.job_id);
|
|
716
|
+
if (!meta) {
|
|
717
|
+
throw new Error(`process: job '${input.job_id}' not found for agent '${ctx.agent}'`);
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
if (input.action === 'poll') {
|
|
721
|
+
// For LOCAL running jobs: probe PID + exit file. The exit
|
|
722
|
+
// listener lives in whichever process spawned the job — after a
|
|
723
|
+
// somora/MCP restart nobody is watching, and trusting meta.state
|
|
724
|
+
// reported 'running' for long-dead PIDs (2026-07-27 report).
|
|
725
|
+
if (meta.target === 'local' && meta.state === 'running') {
|
|
726
|
+
const fresh = await probeLocalJob(ctx.agent, meta);
|
|
727
|
+
return {
|
|
728
|
+
action: 'poll',
|
|
729
|
+
job_id: input.job_id,
|
|
730
|
+
state: fresh.state,
|
|
731
|
+
exit_code: fresh.exit_code,
|
|
732
|
+
pid: fresh.pid,
|
|
733
|
+
ms: (fresh.ended_at ?? Date.now()) - fresh.started_at,
|
|
734
|
+
...(fresh.error ? { error: fresh.error } : {}),
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
// For remote running jobs, do an active probe — kill -0 +
|
|
738
|
+
// exit-file check on the remote host. Updates meta.state to
|
|
739
|
+
// done/failed when the remote process has finished.
|
|
740
|
+
if (meta.target !== 'local' && meta.state === 'running' && meta.pid != null) {
|
|
741
|
+
try {
|
|
742
|
+
const probe = await pollRemoteJob(ctx.agent, meta.target, meta.pid, input.job_id);
|
|
743
|
+
if (!probe.alive) {
|
|
744
|
+
if (probe.exit_code === null) {
|
|
745
|
+
await failJob(ctx.agent, input.job_id, 'remote process gone without exit-file');
|
|
746
|
+
} else {
|
|
747
|
+
await completeJob(ctx.agent, input.job_id, probe.exit_code);
|
|
748
|
+
}
|
|
749
|
+
// Free the concurrency slot — remote jobs have no
|
|
750
|
+
// local close-handler equivalent.
|
|
751
|
+
releaseRemoteSlot(input.job_id);
|
|
752
|
+
// Re-read meta to surface updated state in this same call.
|
|
753
|
+
const fresh = await readMeta(ctx.agent, input.job_id);
|
|
754
|
+
if (fresh) {
|
|
755
|
+
return {
|
|
756
|
+
action: 'poll',
|
|
757
|
+
job_id: input.job_id,
|
|
758
|
+
state: fresh.state,
|
|
759
|
+
exit_code: fresh.exit_code,
|
|
760
|
+
pid: fresh.pid,
|
|
761
|
+
ms: (fresh.ended_at ?? Date.now()) - fresh.started_at,
|
|
762
|
+
...(fresh.error ? { error: fresh.error } : {}),
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
} catch (err) {
|
|
767
|
+
logger.warn({
|
|
768
|
+
msg: 'exec.process.remote_poll_failed',
|
|
769
|
+
job_id: input.job_id,
|
|
770
|
+
target: meta.target,
|
|
771
|
+
err: (err as Error).message,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
return {
|
|
776
|
+
action: 'poll',
|
|
777
|
+
job_id: input.job_id,
|
|
778
|
+
state: meta.state,
|
|
779
|
+
exit_code: meta.exit_code,
|
|
780
|
+
pid: meta.pid,
|
|
781
|
+
ms: (meta.ended_at ?? Date.now()) - meta.started_at,
|
|
782
|
+
...(meta.error ? { error: meta.error } : {}),
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
if (input.action === 'log') {
|
|
787
|
+
const lines = input.tail_lines ?? 50;
|
|
788
|
+
// Remote: tail the files on the remote host via short ssh exec.
|
|
789
|
+
if (meta.target !== 'local') {
|
|
790
|
+
const remote = await tailRemoteJobLog(ctx.agent, meta.target, input.job_id);
|
|
791
|
+
return {
|
|
792
|
+
action: 'log',
|
|
793
|
+
job_id: input.job_id,
|
|
794
|
+
stdout_tail: tailLines(remote.stdout, lines),
|
|
795
|
+
stderr_tail: tailLines(remote.stderr, lines),
|
|
796
|
+
total_stdout_bytes: remote.stdout.length,
|
|
797
|
+
total_stderr_bytes: remote.stderr.length,
|
|
798
|
+
truncated: remote.truncated,
|
|
799
|
+
...(remote.truncated
|
|
800
|
+
? {
|
|
801
|
+
hint:
|
|
802
|
+
`Tail capped at 256 KB per stream. Full logs live on the remote host at ` +
|
|
803
|
+
`/tmp/somora-exec-${input.job_id}.{out,err} on ${meta.target} — ` +
|
|
804
|
+
`use file_read with target:"${meta.target}" + offset/limit to page through.`,
|
|
805
|
+
}
|
|
806
|
+
: {}),
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
// Local
|
|
810
|
+
const log = await readJobLog(ctx.agent, input.job_id);
|
|
811
|
+
if (!log) {
|
|
812
|
+
throw new Error(`process: log not available for job '${input.job_id}'`);
|
|
813
|
+
}
|
|
814
|
+
const stdoutTail = tailLines(log.stdout_tail, lines);
|
|
815
|
+
const stderrTail = tailLines(log.stderr_tail, lines);
|
|
816
|
+
return {
|
|
817
|
+
action: 'log',
|
|
818
|
+
job_id: input.job_id,
|
|
819
|
+
stdout_tail: stdoutTail,
|
|
820
|
+
stderr_tail: stderrTail,
|
|
821
|
+
total_stdout_bytes: log.total_stdout_bytes,
|
|
822
|
+
total_stderr_bytes: log.total_stderr_bytes,
|
|
823
|
+
truncated: log.truncated,
|
|
824
|
+
...(log.truncated
|
|
825
|
+
? {
|
|
826
|
+
hint:
|
|
827
|
+
'Tail capped at 256 KB per stream. Full output is on disk at ' +
|
|
828
|
+
`~/.somora/agents/${ctx.agent}/exec-jobs/${input.job_id}/{stdout,stderr}.log — ` +
|
|
829
|
+
'use file_read with offset/limit to page through.',
|
|
830
|
+
}
|
|
831
|
+
: {}),
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (input.action === 'write') {
|
|
836
|
+
if (input.text === undefined) {
|
|
837
|
+
throw new Error('process: action="write" requires text');
|
|
838
|
+
}
|
|
839
|
+
if (meta.state !== 'running') {
|
|
840
|
+
return {
|
|
841
|
+
action: 'write',
|
|
842
|
+
job_id: input.job_id,
|
|
843
|
+
ok: false,
|
|
844
|
+
bytes_written: 0,
|
|
845
|
+
error: `job is ${meta.state}, not running — can't write to its stdin`,
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
const stdin = getLiveStdin(input.job_id);
|
|
849
|
+
if (!stdin) {
|
|
850
|
+
return {
|
|
851
|
+
action: 'write',
|
|
852
|
+
job_id: input.job_id,
|
|
853
|
+
ok: false,
|
|
854
|
+
bytes_written: 0,
|
|
855
|
+
error:
|
|
856
|
+
'no live stdin handle for this job — likely orphaned across restart, ' +
|
|
857
|
+
'or job is remote (remote stdin not supported in v1)',
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
const buf = Buffer.from(input.text, 'utf8');
|
|
861
|
+
const ok = stdin.write(buf);
|
|
862
|
+
return {
|
|
863
|
+
action: 'write',
|
|
864
|
+
job_id: input.job_id,
|
|
865
|
+
ok,
|
|
866
|
+
bytes_written: buf.length,
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// kill
|
|
871
|
+
if (meta.state !== 'running') {
|
|
872
|
+
// Honest no-op: nothing was signalled. Note for jobs from
|
|
873
|
+
// pre-group-kill somora versions: their workload may have
|
|
874
|
+
// survived a "successful" kill (only the wrapper sh died) —
|
|
875
|
+
// point the agent at a manual path instead of dead-ending.
|
|
876
|
+
return {
|
|
877
|
+
action: 'kill',
|
|
878
|
+
job_id: input.job_id,
|
|
879
|
+
ok: true,
|
|
880
|
+
signal_sent: null,
|
|
881
|
+
was_running: false,
|
|
882
|
+
note:
|
|
883
|
+
`job is already '${meta.state}' — no signal sent. If a stray workload from this job ` +
|
|
884
|
+
`is still alive (jobs killed before 2026-07-21 only stopped the wrapper shell), find and ` +
|
|
885
|
+
`kill it manually via exec (pgrep -f '<command>').`,
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
const sig = (input.signal ?? 'SIGTERM') as NodeJS.Signals;
|
|
889
|
+
|
|
890
|
+
if (meta.target === 'local') {
|
|
891
|
+
const pid = getLivePid(input.job_id) ?? meta.pid;
|
|
892
|
+
if (!pid) {
|
|
893
|
+
throw new Error('process: no pid recorded for job — cannot kill');
|
|
894
|
+
}
|
|
895
|
+
const r = killLocalJob(pid, sig);
|
|
896
|
+
if (r.delivered) {
|
|
897
|
+
await markJobKilled(ctx.agent, input.job_id, sig);
|
|
898
|
+
clearLivePid(input.job_id);
|
|
899
|
+
clearLiveStdin(input.job_id);
|
|
900
|
+
}
|
|
901
|
+
return {
|
|
902
|
+
action: 'kill',
|
|
903
|
+
job_id: input.job_id,
|
|
904
|
+
ok: r.delivered,
|
|
905
|
+
signal_sent: sig,
|
|
906
|
+
was_running: r.delivered,
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Remote kill via short ssh exec. We strip the SIG- prefix that
|
|
911
|
+
// Node uses (`SIGTERM`) since `kill -SIGTERM` is non-portable on
|
|
912
|
+
// some shells; the bare name (`TERM`) works everywhere.
|
|
913
|
+
if (meta.pid == null) {
|
|
914
|
+
throw new Error('process: no pid recorded for remote job — cannot kill');
|
|
915
|
+
}
|
|
916
|
+
const remoteSig = sig.replace(/^SIG/, '');
|
|
917
|
+
const r = await killRemoteJob(ctx.agent, meta.target, meta.pid, remoteSig);
|
|
918
|
+
if (r.delivered) {
|
|
919
|
+
await markJobKilled(ctx.agent, input.job_id, sig);
|
|
920
|
+
releaseRemoteSlot(input.job_id);
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
action: 'kill',
|
|
924
|
+
job_id: input.job_id,
|
|
925
|
+
ok: r.delivered,
|
|
926
|
+
signal_sent: sig,
|
|
927
|
+
was_running: r.delivered,
|
|
928
|
+
};
|
|
929
|
+
},
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
export function execTools(): ToolDefinition[] {
|
|
933
|
+
return [exec, processTool] as ToolDefinition[];
|
|
934
|
+
}
|