@temmo/cli 0.0.0 → 0.19.0
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/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +112 -1
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// Claude and Codex in OpenShell: the host CLI uploaded into a per-project sandbox and run over `openshell sandbox exec`.
|
|
2
|
+
// One sandbox per harness and project, shared by its sessions and deleted when the last one closes; each session's
|
|
3
|
+
// worktree is uploaded as a git clone and landed on the host worktree on close, as Cursor's and OpenCode's are.
|
|
4
|
+
import { spawn as nodeSpawn } from "node:child_process";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { homedir, tmpdir } from "node:os";
|
|
9
|
+
import { basename, dirname, join } from "node:path";
|
|
10
|
+
import { builderPolicy, CLAUDE_DIR, CODEX_DIR } from "../../lib/builder/policy.js";
|
|
11
|
+
import { sharedLibs, toolSources } from "../../lib/builder/stage.js";
|
|
12
|
+
import { ensureSandbox, execArgv, executables, harnessLogins, harnessSandboxName, HOME_IN, refreshSandboxPolicies, sandboxLabels, uploadSecret, uploadTree, whenSandboxReady, WORK, } from "../../lib/sandbox.js";
|
|
13
|
+
import { claimableRecord, createClaimLedger, ensureSandboxBinary, fetchIntoSandbox, linkDeps, makeExec, releaseClaim, syncBackWork, uploadClone } from "../../lib/sandbox-claims.js";
|
|
14
|
+
import { findExecutable } from "../../lib/sessions/scope.js";
|
|
15
|
+
import { MANAGED_ENV } from "../../lib/subagent-guard.js";
|
|
16
|
+
import { TOOL_ENV, uploadToolchain } from "../../lib/sandbox-tools.js";
|
|
17
|
+
import { NODE_IN, uploadApp } from "../../lib/sandbox-app.js";
|
|
18
|
+
export { stageToolchain, TOOL_ENV, uploadToolchain } from "../../lib/sandbox-tools.js";
|
|
19
|
+
export const CLAUDE_IN = `${CLAUDE_DIR}/claude`;
|
|
20
|
+
// The env a sandboxed CLI starts with; the host env never crosses, so no host path or secret reaches argv.
|
|
21
|
+
const BASE_ENV = { HOME: HOME_IN, XDG_CONFIG_HOME: `${HOME_IN}/.config`, TMPDIR: "/tmp" };
|
|
22
|
+
// Documented in code.claude.com/docs/en/env-vars; the policy allows only Claude's API hosts, so other traffic would hang.
|
|
23
|
+
const CLAUDE_QUIET = { CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC: "1", DISABLE_TELEMETRY: "1", DISABLE_ERROR_REPORTING: "1", DISABLE_AUTOUPDATER: "1" };
|
|
24
|
+
// SDK and temmo variables a sandboxed Claude keeps from the env the SDK hands its spawner; secrets never.
|
|
25
|
+
const CLAUDE_PASS = /^(CLAUDE_CODE_|CLAUDE_AGENT_SDK_|TEMMO_(OWNED|PARENT|MANAGED)$)/;
|
|
26
|
+
const SECRET = /TOKEN|SECRET|PASSWORD|KEY|CREDENTIAL/;
|
|
27
|
+
const EXIT_WAIT_MS = 5_000;
|
|
28
|
+
const STDERR_LINE_MAX = 500;
|
|
29
|
+
const selfNote = (address) => `\n\n[temmo] Your address is ${address}; pass session "${address.split("#")[1]}" to temmo tools.`;
|
|
30
|
+
const real = (file) => { try {
|
|
31
|
+
return file ? realpathSync(file) : "";
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return "";
|
|
35
|
+
} };
|
|
36
|
+
/** The first send of a sandboxed session names its address, as a spawned child's brief does: no hook there supplies it. */
|
|
37
|
+
export function withSelfNote(handle, address) {
|
|
38
|
+
let noted = false;
|
|
39
|
+
const label = address.split("#")[1];
|
|
40
|
+
return async (input) => {
|
|
41
|
+
if (noted || String(input.text).includes(`session "${label}"`))
|
|
42
|
+
return handle.send(input);
|
|
43
|
+
const sent = await handle.send({ ...input, text: input.text + selfNote(address) });
|
|
44
|
+
noted = true;
|
|
45
|
+
return sent;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/** The Claude Code binary a sandbox gets: TEMMO_CLAUDE_BIN, else the SDK's bundled Linux binary, else `claude` on PATH. */
|
|
49
|
+
export function claudeInstall(env) {
|
|
50
|
+
const local = env.TEMMO_CLAUDE_BIN || bundledClaude() || real(findExecutable("claude", env.PATH ?? ""));
|
|
51
|
+
if (!local)
|
|
52
|
+
throw new Error("no Claude Code binary to upload into OpenShell; set TEMMO_CLAUDE_BIN");
|
|
53
|
+
return { local, file: true, dir: CLAUDE_DIR, bin: CLAUDE_IN, binaries: [CLAUDE_IN] };
|
|
54
|
+
}
|
|
55
|
+
// The native CLI the Agent SDK ships for this machine (glibc Linux, as the sandbox image is); the same version the SDK speaks.
|
|
56
|
+
function bundledClaude() {
|
|
57
|
+
if (process.platform !== "linux")
|
|
58
|
+
return "";
|
|
59
|
+
try {
|
|
60
|
+
return createRequire(import.meta.url).resolve(`@anthropic-ai/claude-agent-sdk-linux-${process.arch}/claude`);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The Codex install a sandbox gets: TEMMO_CODEX_TREE, else the release tree holding the host `codex` (bin/codex inside), as builders upload it. */
|
|
67
|
+
export function codexInstall(env) {
|
|
68
|
+
const found = real(findExecutable("codex", env.PATH ?? ""));
|
|
69
|
+
const tree = env.TEMMO_CODEX_TREE || (found ? dirname(dirname(found)) : "");
|
|
70
|
+
if (!tree || !existsSync(join(tree, "bin", "codex")))
|
|
71
|
+
throw new Error("no Codex install to upload into OpenShell; set TEMMO_CODEX_TREE to a tree with bin/codex");
|
|
72
|
+
const inTree = `${CODEX_DIR}/${basename(tree)}`;
|
|
73
|
+
return { local: tree, file: false, dir: CODEX_DIR, bin: `${inTree}/bin/codex`, binaries: executables(join(tree, "bin")).map((f) => `${inTree}/bin/${f}`) };
|
|
74
|
+
}
|
|
75
|
+
/** The env a sandboxed Codex app-server runs with: the sandbox home and its CODEX_HOME, the owned marker, and the managed marker for a managed session. */
|
|
76
|
+
export function codexSandboxEnv(managed) {
|
|
77
|
+
return { ...BASE_ENV, CODEX_HOME: `${HOME_IN}/.codex`, TEMMO_OWNED: "codex", ...(managed ? { [MANAGED_ENV]: "1" } : {}) };
|
|
78
|
+
}
|
|
79
|
+
/** The env a sandboxed Claude runs with: the SDK's own variables (no secrets), the sandbox home and the quiet switches. */
|
|
80
|
+
export function claudeSandboxEnv(sdkEnv) {
|
|
81
|
+
const kept = Object.entries(sdkEnv).filter((pair) => typeof pair[1] === "string" && CLAUDE_PASS.test(pair[0]) && !SECRET.test(pair[0]));
|
|
82
|
+
return { ...Object.fromEntries(kept), ...BASE_ENV, ...CLAUDE_QUIET };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The SDK's spawnClaudeCodeProcess for a sandbox: the CLI argv the SDK built, run as `openshell sandbox exec` over stdio.
|
|
86
|
+
* The SDK's cwd is the sandbox workdir. kill() also destroys the pipes, since the exec client may not be what holds them.
|
|
87
|
+
*/
|
|
88
|
+
export function claudeSpawner({ openshell, env, sandbox, workdir, log, spawn = nodeSpawn }) {
|
|
89
|
+
const children = new Set();
|
|
90
|
+
const spawner = (o) => {
|
|
91
|
+
const argv = execArgv({ openshell, sandbox, workdir: o.cwd || workdir, env: { ...claudeSandboxEnv(o.env), ...TOOL_ENV }, command: [CLAUDE_IN, ...o.args] });
|
|
92
|
+
const child = spawn(argv[0], argv.slice(1), { env, stdio: ["pipe", "pipe", "pipe"], shell: false });
|
|
93
|
+
const destroy = () => { for (const stream of [child.stdin, child.stdout, child.stderr])
|
|
94
|
+
if (stream && !stream.destroyed)
|
|
95
|
+
stream.destroy(); };
|
|
96
|
+
const kill = child.kill.bind(child);
|
|
97
|
+
child.kill = (signal) => { const ok = kill(signal); destroy(); return ok; };
|
|
98
|
+
child.stdin?.on("error", () => { });
|
|
99
|
+
child.stderr?.setEncoding("utf8");
|
|
100
|
+
child.stderr?.on("data", (chunk) => { for (const line of chunk.split("\n"))
|
|
101
|
+
if (line.trim())
|
|
102
|
+
log(`claude: ${line.trimEnd().slice(0, STDERR_LINE_MAX)}`); });
|
|
103
|
+
children.add(child);
|
|
104
|
+
child.once("exit", () => children.delete(child));
|
|
105
|
+
o.signal?.addEventListener("abort", () => child.kill("SIGTERM"), { once: true });
|
|
106
|
+
return child;
|
|
107
|
+
};
|
|
108
|
+
// Waits up to EXIT_WAIT_MS for every CLI to exit after the SDK closed its stdin, then kills what is left.
|
|
109
|
+
const stopped = async () => {
|
|
110
|
+
await Promise.all([...children].map((child) => new Promise((resolve) => {
|
|
111
|
+
if (child.exitCode !== null || child.signalCode !== null)
|
|
112
|
+
return resolve();
|
|
113
|
+
const timer = setTimeout(() => { child.kill("SIGKILL"); resolve(); }, EXIT_WAIT_MS);
|
|
114
|
+
child.once("exit", () => { clearTimeout(timer); resolve(); });
|
|
115
|
+
})));
|
|
116
|
+
};
|
|
117
|
+
return { spawner, stopped };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The per-project sandboxes one harness's runner sessions share; `install` names what to upload, `label` and `trailer` mark the landing.
|
|
121
|
+
* `policy` replaces the builder policy for the install; `stage` uploads the harness's own config after the app.
|
|
122
|
+
*/
|
|
123
|
+
export function createCliSandbox({ env = process.env, harness, label, trailer, install, policy: policyFor, stage }) {
|
|
124
|
+
const openshell = env.TEMMO_OPENSHELL_BIN || "openshell";
|
|
125
|
+
const boxes = new Map(); // sandbox name -> its staged state, for this runner's lifetime
|
|
126
|
+
const ledger = createClaimLedger(); // which sessions (and restored records) hold each sandbox
|
|
127
|
+
const landing = { label, trailer };
|
|
128
|
+
const ownerOf = (project) => `${harness}-${project}`;
|
|
129
|
+
const exec = makeExec(openshell, env);
|
|
130
|
+
// Creates or reuses the sandbox under the harness policy, uploads the CLI when missing, and the harness's own login.
|
|
131
|
+
async function startBox(box, home, log) {
|
|
132
|
+
const inst = install(env);
|
|
133
|
+
const dir = mkdtempSync(join(tmpdir(), `temmo-${harness}-policy-`));
|
|
134
|
+
try {
|
|
135
|
+
const policy = join(dir, "policy.yaml");
|
|
136
|
+
const body = policyFor ? policyFor(inst, home) : builderPolicy({ harness, binaries: inst.binaries, ntfyBinaries: [NODE_IN], packages: true });
|
|
137
|
+
writeFileSync(policy, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
|
|
138
|
+
await ensureSandbox({ openshell, env, name: box.name, policy, labels: sandboxLabels({ project: box.project, kind: "session", owner: box.owner }) });
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
rmSync(dir, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
// The CLI is a few hundred MB, so a sandbox that already has it keeps it.
|
|
144
|
+
if (inst.file) {
|
|
145
|
+
await ensureSandboxBinary({ openshell, env, exec, sandbox: box.name, local: inst.local, remoteDir: inst.dir, bin: inst.bin, harnessName: harness });
|
|
146
|
+
}
|
|
147
|
+
else if ((await exec(box.name, ["test", "-e", inst.bin])).code !== 0) {
|
|
148
|
+
await whenSandboxReady(() => uploadTree({ openshell, env, sandbox: box.name, local: inst.local, remote: inst.dir, gitIgnore: false }));
|
|
149
|
+
}
|
|
150
|
+
await uploadToolchain({ openshell, env, sandbox: box.name, label, log });
|
|
151
|
+
// The app and bus config, so the session's temmo MCP servers start under the staged node and reach the host bus.
|
|
152
|
+
await uploadApp({ openshell, env, sandbox: box.name, project: box.project, harness });
|
|
153
|
+
await stage?.(box.name, home, log);
|
|
154
|
+
for (const login of harnessLogins(env, home).filter((l) => l.harness === harness)) {
|
|
155
|
+
await uploadSecret({ openshell, env, sandbox: box.name, file: login.file, remoteDir: login.remoteDir, tmpPrefix: `temmo-${harness}-secret-` })
|
|
156
|
+
.catch((error) => log(`${label}: could not copy the login into ${box.name}: ${error.message.split("\n")[0]}`));
|
|
157
|
+
}
|
|
158
|
+
box.bin = inst.bin;
|
|
159
|
+
box.launch = inst.launch ?? [inst.bin];
|
|
160
|
+
}
|
|
161
|
+
async function boxFor(project, home, log) {
|
|
162
|
+
const name = harnessSandboxName(harness, project);
|
|
163
|
+
const known = boxes.get(name);
|
|
164
|
+
if (known) {
|
|
165
|
+
await known.ready;
|
|
166
|
+
return known;
|
|
167
|
+
}
|
|
168
|
+
const box = { name, project, owner: ownerOf(project), bin: "", launch: [], uploaded: new Set(), ready: Promise.resolve() };
|
|
169
|
+
boxes.set(name, box);
|
|
170
|
+
box.ready = startBox(box, home, log);
|
|
171
|
+
try {
|
|
172
|
+
await box.ready;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (boxes.get(name) === box)
|
|
176
|
+
boxes.delete(name);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
return box;
|
|
180
|
+
}
|
|
181
|
+
// Uploads a session's worktree as a clone under /sandbox/work; a resume keeps the one already there.
|
|
182
|
+
async function stageWork(box, cwd, keepExisting) {
|
|
183
|
+
const workdir = `${WORK}/${basename(cwd)}`;
|
|
184
|
+
if (box.uploaded.has(cwd))
|
|
185
|
+
return workdir;
|
|
186
|
+
const present = keepExisting && (await exec(box.name, ["test", "-d", workdir])).code === 0;
|
|
187
|
+
if (!present) {
|
|
188
|
+
if (existsSync(join(cwd, ".git")))
|
|
189
|
+
await uploadClone({ openshell, env, sandbox: box.name, cwd, remote: WORK });
|
|
190
|
+
else
|
|
191
|
+
await uploadTree({ openshell, env, sandbox: box.name, local: cwd, remote: WORK });
|
|
192
|
+
}
|
|
193
|
+
await linkDeps({ openshell, env, exec, sandbox: box.name, cwd, workdir });
|
|
194
|
+
box.uploaded.add(cwd);
|
|
195
|
+
return workdir;
|
|
196
|
+
}
|
|
197
|
+
// Lands the session's work on its host worktree, drops its claim, and deletes the sandbox with the last claim.
|
|
198
|
+
const releaseClaimFor = (name, id, project, cwd, log) => releaseClaim({
|
|
199
|
+
openshell, env, ledger, name, id, project, owner: ownerOf(project), cwd, log, landing,
|
|
200
|
+
forgetWork: (work) => { boxes.get(name)?.uploaded.delete(work); },
|
|
201
|
+
stopBox: async () => { boxes.delete(name); },
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
openshell,
|
|
205
|
+
/**
|
|
206
|
+
* Claims the project's sandbox for one session, stages it and uploads the worktree. `id` is the session's claim (a
|
|
207
|
+
* resume passes its address, which a restored record already holds); a failed open drops a new claim, a failed resume keeps it.
|
|
208
|
+
*/
|
|
209
|
+
async open({ project, cwd, home = env.HOME || homedir(), log, id = randomUUID(), resume = false }) {
|
|
210
|
+
const name = harnessSandboxName(harness, project);
|
|
211
|
+
ledger.claim(name, id);
|
|
212
|
+
let box;
|
|
213
|
+
try {
|
|
214
|
+
box = await boxFor(project, home, log);
|
|
215
|
+
const workdir = await stageWork(box, cwd, resume);
|
|
216
|
+
const launch = box.launch;
|
|
217
|
+
let closed = false;
|
|
218
|
+
return {
|
|
219
|
+
name, workdir,
|
|
220
|
+
/** Argv that runs the CLI with args in the session's workdir. */
|
|
221
|
+
argv: (args, vars) => execArgv({ openshell, sandbox: name, workdir, env: { ...vars, ...TOOL_ENV }, command: [...launch, ...args] }),
|
|
222
|
+
syncBack: (sessionLog, opts) => syncBackWork({ openshell, env, exec, sandbox: name, cwd, log: sessionLog, landing, ...opts }),
|
|
223
|
+
fetchOrigin: (ref) => fetchIntoSandbox({ openshell, env, exec, sandbox: name, cwd, log, ref }),
|
|
224
|
+
/** Lands the work and releases the claim once. */
|
|
225
|
+
close: async (sessionLog) => {
|
|
226
|
+
if (closed)
|
|
227
|
+
return true;
|
|
228
|
+
closed = true;
|
|
229
|
+
return releaseClaimFor(name, id, project, cwd, sessionLog);
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (!resume)
|
|
235
|
+
await releaseClaimFor(name, id, project, box ? cwd : "", log);
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
/** A runner start replaces the policy on this harness's sandboxes that already exist, so a deploy reaches idle ones too. */
|
|
240
|
+
async reapplyPolicy(projects) {
|
|
241
|
+
const names = projects.map((project) => harnessSandboxName(harness, project));
|
|
242
|
+
if (!names.length)
|
|
243
|
+
return;
|
|
244
|
+
const inst = install(env);
|
|
245
|
+
const dir = mkdtempSync(join(tmpdir(), `temmo-${harness}-policy-`));
|
|
246
|
+
try {
|
|
247
|
+
const policy = join(dir, "policy.yaml");
|
|
248
|
+
const body = policyFor ? policyFor(inst, env.HOME || homedir()) : builderPolicy({ harness, binaries: inst.binaries, ntfyBinaries: [NODE_IN], packages: true });
|
|
249
|
+
writeFileSync(policy, `${JSON.stringify(body, null, 2)}\n`, { mode: 0o600 });
|
|
250
|
+
await refreshSandboxPolicies({ openshell, env, names, policy });
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
rmSync(dir, { recursive: true, force: true });
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
/** A record restored after a runner restart holds its sandbox until it resumes or is released. */
|
|
257
|
+
restore(record) {
|
|
258
|
+
if (!claimableRecord(record))
|
|
259
|
+
return;
|
|
260
|
+
ledger.claim(harnessSandboxName(harness, record.project), record.address);
|
|
261
|
+
},
|
|
262
|
+
/** Ends a restored record that never resumed: lands its work and deletes the sandbox when no other session holds it. */
|
|
263
|
+
release(record) {
|
|
264
|
+
if (!claimableRecord(record))
|
|
265
|
+
return Promise.resolve(true);
|
|
266
|
+
return releaseClaimFor(harnessSandboxName(harness, record.project), record.address, record.project, record.cwd, () => { });
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
/** Claude Code's sandbox host: its binary in /sandbox/claude, its OAuth login, and its commits trailed as Claude's. */
|
|
271
|
+
export function createClaudeSandbox({ env = process.env, install = claudeInstall } = {}) {
|
|
272
|
+
return createCliSandbox({ env, harness: "claude", label: "claude", trailer: "Assisted-by: Claude:claude-code", install });
|
|
273
|
+
}
|
|
274
|
+
/** Codex's sandbox host: its release tree in /sandbox/codex, its login, and its commits trailed as Codex's. */
|
|
275
|
+
export function createCodexSandbox({ env = process.env, install = codexInstall } = {}) {
|
|
276
|
+
return createCliSandbox({ env, harness: "codex", label: "codex", trailer: "Assisted-by: Codex:codex", install });
|
|
277
|
+
}
|