@temmo/cli 0.0.0-stage → 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 +110 -4
- 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,120 @@
|
|
|
1
|
+
// The temmo app inside an OpenShell sandbox: its scripts, the host bus config and the MCP server entry, shared by every staging path.
|
|
2
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { basename, dirname, join } from "node:path";
|
|
5
|
+
import { APP_IN, CODE_MCP, CODEX_SANDBOX_FEATURES, sandboxBus, sandboxDefaults } from "./builder/policy.js";
|
|
6
|
+
import { APP_ROOT } from "./builder/state.js";
|
|
7
|
+
import { piMcpJson, piMcpServer } from "./pi.js";
|
|
8
|
+
import { HOME_IN, hostTokenFile, NTFY_TOKEN_IN, TOOLS, uploadFile, uploadSecret, uploadTree, WORK } from "./sandbox.js";
|
|
9
|
+
/** The app parts a sandbox needs to run the temmo CLI and MCP servers under TOOLS/temmo. */
|
|
10
|
+
export const APP_PARTS = ["package.json", "scripts", "lib", "web/lib", "harness-core"];
|
|
11
|
+
/** The node every sandbox gets from the common toolchain (lib/sandbox-tools.ts). */
|
|
12
|
+
export const NODE_IN = `${TOOLS}/node/bin/node`;
|
|
13
|
+
/** The bus MCP server script inside a sandbox. */
|
|
14
|
+
export const MCP_IN = `${APP_IN}/scripts/temmo-mcp.mjs`;
|
|
15
|
+
/** pi's agent dir in a sandbox home (PI_CODING_AGENT_DIR): mcp.json, models.json, auth.json and its sessions. */
|
|
16
|
+
export const PI_AGENT_IN = `${HOME_IN}/.pi/agent`;
|
|
17
|
+
// The env a sandboxed stdio MCP server needs beside its own: the sandbox config dir and the toolchain's libraries.
|
|
18
|
+
const MCP_ENV = { XDG_CONFIG_HOME: `${HOME_IN}/.config`, LD_LIBRARY_PATH: `${TOOLS}/lib` };
|
|
19
|
+
/** Copies the app parts under tools/temmo of a staging tools tree. */
|
|
20
|
+
export function stageApp(tools, root = APP_ROOT) {
|
|
21
|
+
for (const part of APP_PARTS)
|
|
22
|
+
if (existsSync(join(root, part)))
|
|
23
|
+
cpSync(join(root, part), join(tools, "temmo", part), { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Writes the sandbox home's temmo config: defaults.json with the host bus, and projects.json mapping `root` to the
|
|
27
|
+
* project when one is named. tokenFile is the uploaded in-sandbox path, never the host's.
|
|
28
|
+
*/
|
|
29
|
+
export function stageBusConfig(home, { project, root, token }) {
|
|
30
|
+
const config = join(home, ".config", "temmo");
|
|
31
|
+
mkdirSync(config, { recursive: true });
|
|
32
|
+
const tokenFile = token ? NTFY_TOKEN_IN : undefined;
|
|
33
|
+
writeFileSync(join(config, "defaults.json"), sandboxDefaults({ tokenFile }));
|
|
34
|
+
if (project)
|
|
35
|
+
writeFileSync(join(config, "projects.json"), `${JSON.stringify([{ root, project, ...sandboxBus(tokenFile) }], null, 2)}\n`);
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
/** The stdio temmo MCP server a sandboxed harness runs: staged node and script, the project and peer in its env. */
|
|
39
|
+
export function busMcpServer({ project, peer, host }) {
|
|
40
|
+
return { command: NODE_IN, args: [MCP_IN, ...(host ? [host] : [])], env: { ...(project ? { TEMMO_PROJECT: project } : {}), TEMMO_PEER: peer } };
|
|
41
|
+
}
|
|
42
|
+
/** The bus MCP server as a sandboxed harness starts it: the staged node and script, with the sandbox home's config env. */
|
|
43
|
+
export function sandboxBusMcpServer({ project, peer }) {
|
|
44
|
+
const server = busMcpServer({ project, peer, host: peer });
|
|
45
|
+
return { command: server.command, args: server.args, env: { ...MCP_ENV, ...server.env } };
|
|
46
|
+
}
|
|
47
|
+
/** The code-mode MCP server beside it, run the same way; null when the app has no such script. */
|
|
48
|
+
export function codeMcpServer({ project, peer, host }, root = APP_ROOT) {
|
|
49
|
+
if (!existsSync(join(root, CODE_MCP)))
|
|
50
|
+
return null;
|
|
51
|
+
return { command: NODE_IN, args: [`${APP_IN}/${CODE_MCP}`, ...(host ? [host] : [])], env: { ...(project ? { TEMMO_PROJECT: project } : {}), TEMMO_PEER: peer } };
|
|
52
|
+
}
|
|
53
|
+
/** The `[features]` table a sandboxed Codex's config.toml starts with: CODEX_SANDBOX_FEATURES plus the caller's own. */
|
|
54
|
+
export function codexFeaturesToml(extra = {}) {
|
|
55
|
+
return `[features]\n${Object.entries({ ...CODEX_SANDBOX_FEATURES, ...extra }).map(([k, v]) => `${k} = ${v}`).join("\n")}\n`;
|
|
56
|
+
}
|
|
57
|
+
/** The Codex config.toml a sandbox home gets: no ChatGPT connectors or remote plugins, and the bus and code-mode MCP servers under the staged node. */
|
|
58
|
+
export function codexMcpToml(project) {
|
|
59
|
+
const env = MCP_ENV;
|
|
60
|
+
const servers = { "temmo": busMcpServer({ project, peer: "codex", host: "codex" }), "temmo-code": codeMcpServer({ project, peer: "codex", host: "codex" }) };
|
|
61
|
+
return `${codexFeaturesToml()}\n` + Object.entries(servers).filter(([, s]) => s).map(([name, s]) => {
|
|
62
|
+
const server = s;
|
|
63
|
+
const vars = Object.entries({ ...env, ...server.env }).map(([k, v]) => `${k} = ${JSON.stringify(v)}`).join("\n");
|
|
64
|
+
return `[mcp_servers.${JSON.stringify(name)}]\ncommand = ${JSON.stringify(server.command)}\nargs = ${JSON.stringify(server.args)}\n\n[mcp_servers.${JSON.stringify(name)}.env]\n${vars}\n`;
|
|
65
|
+
}).join("\n");
|
|
66
|
+
}
|
|
67
|
+
/** The mcp.json a sandboxed pi's agent dir gets: the bus server under the staged node, its tools declared directly. */
|
|
68
|
+
export function piSandboxMcpJson(project) {
|
|
69
|
+
const server = busMcpServer({ project, peer: "pi", host: "pi" });
|
|
70
|
+
return piMcpJson(piMcpServer({ command: server.command, script: MCP_IN, env: { ...MCP_ENV, ...server.env } }));
|
|
71
|
+
}
|
|
72
|
+
/** The opencode.json mcp entry a sandboxed OpenCode gets: the bus server under the staged node. */
|
|
73
|
+
export function opencodeSandboxMcpEntry(project) {
|
|
74
|
+
const server = busMcpServer({ project, peer: "opencode", host: "opencode" });
|
|
75
|
+
return { type: "local", command: [server.command, ...server.args], cwd: ".", enabled: true, environment: { ...MCP_ENV, ...server.env } };
|
|
76
|
+
}
|
|
77
|
+
/** Uploads only the app's scripts and libraries under TOOLS/temmo, for a harness that stages its own bus config and token. */
|
|
78
|
+
export async function uploadAppTree({ openshell, env, sandbox }) {
|
|
79
|
+
const dir = mkdtempSync(join(tmpdir(), "temmo-sandbox-app-"));
|
|
80
|
+
try {
|
|
81
|
+
const tools = join(dir, "tools");
|
|
82
|
+
mkdirSync(tools, { recursive: true });
|
|
83
|
+
stageApp(tools);
|
|
84
|
+
await uploadTree({ openshell, env, sandbox, local: join(tools, "temmo"), remote: TOOLS, gitIgnore: false });
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
rmSync(dir, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Uploads the app, the home's bus config and the host's bus token into a runner sandbox, so its MCP servers start and
|
|
92
|
+
* reach the host bus. The token goes as an uploaded file, never through argv or env; Codex also gets its config.toml, pi its mcp.json.
|
|
93
|
+
*/
|
|
94
|
+
export async function uploadApp({ openshell, env, sandbox, project, harness }) {
|
|
95
|
+
const dir = mkdtempSync(join(tmpdir(), "temmo-sandbox-app-"));
|
|
96
|
+
try {
|
|
97
|
+
const tools = join(dir, "tools");
|
|
98
|
+
mkdirSync(tools, { recursive: true });
|
|
99
|
+
stageApp(tools);
|
|
100
|
+
const home = join(dir, "home");
|
|
101
|
+
const token = hostTokenFile(env);
|
|
102
|
+
const config = stageBusConfig(home, { project, root: WORK, token: Boolean(token) });
|
|
103
|
+
// An upload replaces its target, so only temmo's own dirs and files go: the home keeps its login and transcripts.
|
|
104
|
+
await uploadTree({ openshell, env, sandbox, local: join(tools, "temmo"), remote: TOOLS, gitIgnore: false });
|
|
105
|
+
await uploadTree({ openshell, env, sandbox, local: config, remote: `${HOME_IN}/.config`, gitIgnore: false });
|
|
106
|
+
if (harness === "codex") {
|
|
107
|
+
writeFileSync(join(dir, "config.toml"), codexMcpToml(project));
|
|
108
|
+
await uploadFile({ openshell, env, sandbox, local: join(dir, "config.toml"), remoteDir: `${HOME_IN}/.codex` });
|
|
109
|
+
}
|
|
110
|
+
if (harness === "pi") {
|
|
111
|
+
writeFileSync(join(dir, "mcp.json"), piSandboxMcpJson(project));
|
|
112
|
+
await uploadFile({ openshell, env, sandbox, local: join(dir, "mcp.json"), remoteDir: PI_AGENT_IN });
|
|
113
|
+
}
|
|
114
|
+
if (token)
|
|
115
|
+
await uploadSecret({ openshell, env, sandbox, file: token, remoteDir: dirname(NTFY_TOKEN_IN), name: basename(NTFY_TOKEN_IN), tmpPrefix: "temmo-sandbox-token-" });
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
rmSync(dir, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// The claim ledger and the landing the runner's OpenShell session adapters share: one sandbox per harness and project,
|
|
2
|
+
// landed on the host worktree and deleted when its last claim drops. The landing half moved out of runner/adapters/cursor.mjs.
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { existsSync, mkdtempSync, readFileSync, realpathSync, rmSync } from "node:fs";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
import { commitUncommitted, DEPS, destroyOwnedSandboxes, downloadTree, execArgv, OUT, runTool, SYNC_TIMEOUT_MS, TOOLS, uploadFile, uploadTree, whenSandboxReady, WORK, } from "./sandbox.js";
|
|
8
|
+
const GIT_TIMEOUT_MS = 120_000;
|
|
9
|
+
const LOOSE_WORK_COMMIT = "chore(openshell): uncommitted work from a sandboxed session";
|
|
10
|
+
const real = (file) => { try {
|
|
11
|
+
return file ? realpathSync(file) : "";
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return "";
|
|
15
|
+
} };
|
|
16
|
+
// Runs git with a fixed argv; throws with its stderr on a non-zero exit.
|
|
17
|
+
async function git(cwd, args, env) {
|
|
18
|
+
const out = await runTool("git", ["-C", cwd, ...args], { env, timeoutMs: GIT_TIMEOUT_MS });
|
|
19
|
+
if (out.code !== 0)
|
|
20
|
+
throw new Error(`git ${args[0]} failed: ${(out.stderr || "").trim() || `exit ${out.code}`}`);
|
|
21
|
+
return out.stdout;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Uploads a git work tree as a self-contained clone of its checked-out branch, so git works inside the sandbox:
|
|
25
|
+
* a linked worktree's .git is a file pointing into the host repo, which the sandbox does not have (as lib/builder.ts).
|
|
26
|
+
*/
|
|
27
|
+
export async function uploadClone({ openshell, env, sandbox, cwd, remote }) {
|
|
28
|
+
const dir = mkdtempSync(join(tmpdir(), "temmo-sandbox-clone-"));
|
|
29
|
+
const clone = join(dir, basename(cwd));
|
|
30
|
+
try {
|
|
31
|
+
const branch = (await git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"], env)).trim();
|
|
32
|
+
await runTool("git", ["clone", "--quiet", "--no-hardlinks", ...(branch && branch !== "HEAD" ? ["--branch", branch] : []), cwd, clone], { env, timeoutMs: GIT_TIMEOUT_MS })
|
|
33
|
+
.then((out) => { if (out.code !== 0)
|
|
34
|
+
throw new Error(`git clone failed: ${(out.stderr || "").trim()}`); });
|
|
35
|
+
await git(clone, ["remote", "remove", "origin"], env);
|
|
36
|
+
for (const key of ["user.name", "user.email"]) {
|
|
37
|
+
const value = (await runTool("git", ["-C", cwd, "config", key], { env })).stdout.trim();
|
|
38
|
+
if (value)
|
|
39
|
+
await git(clone, ["config", key, value], env);
|
|
40
|
+
}
|
|
41
|
+
const out = await runTool(openshell, ["sandbox", "upload", sandbox, `${clone}/`, `${remote.replace(/\/+$/, "")}/`, "--no-git-ignore"], { env, timeoutMs: SYNC_TIMEOUT_MS });
|
|
42
|
+
if (out.code !== 0)
|
|
43
|
+
throw new Error(`openshell sandbox upload failed: ${(out.stderr || "").trim() || `exit ${out.code}`}`);
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
rmSync(dir, { recursive: true, force: true });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Lands a sandbox clone's work on the host work tree the way builders do: loose changes become one commit, then the
|
|
50
|
+
// host fast-forwards to it. A branch that moved on the host keeps the download and says where it is.
|
|
51
|
+
async function landClone({ openshell, env, sandbox, cwd, log, label, trailer }) {
|
|
52
|
+
const incoming = mkdtempSync(join(tmpdir(), "temmo-sandbox-back-"));
|
|
53
|
+
const back = join(incoming, basename(cwd));
|
|
54
|
+
let keep = false;
|
|
55
|
+
try {
|
|
56
|
+
await downloadTree({ openshell, env, sandbox, remote: `${WORK}/${basename(cwd)}`, local: back });
|
|
57
|
+
if (!existsSync(join(back, ".git")))
|
|
58
|
+
throw new Error("the downloaded workspace has no git repository");
|
|
59
|
+
await commitUncommitted({ git: (repo, args) => git(repo, args, env), repo: back, message: LOOSE_WORK_COMMIT, trailer });
|
|
60
|
+
const ahead = Number((await git(back, ["rev-list", "--count", "HEAD", "--not", (await git(cwd, ["rev-parse", "HEAD"], env)).trim()], env).catch(() => "0")).trim()) || 0;
|
|
61
|
+
if (!ahead)
|
|
62
|
+
return true;
|
|
63
|
+
await git(cwd, ["fetch", "--quiet", back, "HEAD"], env);
|
|
64
|
+
try {
|
|
65
|
+
await git(cwd, ["merge", "--quiet", "--ff-only", "FETCH_HEAD"], env);
|
|
66
|
+
log(`${label}: landed ${ahead} commit(s) from the sandbox on ${cwd}`);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
keep = true;
|
|
70
|
+
log(`${label}: could not fast-forward ${cwd}; the sandbox work is kept in ${back}: ${error.message}`);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
if (!keep)
|
|
77
|
+
rmSync(incoming, { recursive: true, force: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Copies the sandbox worktree back to the host after a run or on close: commits for a git work tree, files otherwise; never throws.
|
|
82
|
+
* label prefixes the log lines and trailer ends the commit of loose work; both default to Cursor's.
|
|
83
|
+
*/
|
|
84
|
+
export async function syncSandboxBack({ openshell, env, sandbox, cwd, log = () => { }, label = "cursor", trailer = "Assisted-by: Cursor:cursor-agent" }) {
|
|
85
|
+
try {
|
|
86
|
+
if (existsSync(join(cwd, ".git")))
|
|
87
|
+
return await landClone({ openshell, env, sandbox, cwd, log, label, trailer });
|
|
88
|
+
await downloadTree({ openshell, env, sandbox, remote: `${WORK}/${basename(cwd)}`, local: cwd });
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
log(`${label}: could not copy edits back from the sandbox: ${error.message}`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/** The claim ledger: which sessions hold each sandbox; the sandbox goes with the last claim. */
|
|
97
|
+
export function createClaimLedger() {
|
|
98
|
+
const claims = new Map();
|
|
99
|
+
return {
|
|
100
|
+
claim(name, id) {
|
|
101
|
+
const set = claims.get(name) ?? new Set();
|
|
102
|
+
set.add(id);
|
|
103
|
+
claims.set(name, set);
|
|
104
|
+
},
|
|
105
|
+
holds: (name, id) => claims.get(name)?.has(id) === true,
|
|
106
|
+
drop(name, id) {
|
|
107
|
+
const set = claims.get(name);
|
|
108
|
+
if (!set?.delete(id))
|
|
109
|
+
return false;
|
|
110
|
+
if (set.size)
|
|
111
|
+
return false;
|
|
112
|
+
claims.delete(name);
|
|
113
|
+
return true;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Whether a restored record holds a session sandbox: openshell, not ended, addressed, and not a builder's (a builder settles its own work in lib/builder/settle.ts). */
|
|
118
|
+
export function claimableRecord(record) {
|
|
119
|
+
const r = record;
|
|
120
|
+
return r?.place === "openshell" && r.status !== "ended" && !!r.address && !r.builder;
|
|
121
|
+
}
|
|
122
|
+
/** `openshell sandbox exec` with no workdir and no env: the probe both adapters run. */
|
|
123
|
+
export function makeExec(openshell, env) {
|
|
124
|
+
return (name, command) => runTool(openshell, execArgv({ openshell, sandbox: name, command }).slice(1), { env });
|
|
125
|
+
}
|
|
126
|
+
/** Uploads the harness binary when `test -x bin` fails, renaming it to the launcher path. */
|
|
127
|
+
export async function ensureSandboxBinary(a) {
|
|
128
|
+
if ((await a.exec(a.sandbox, ["test", "-x", a.bin])).code === 0)
|
|
129
|
+
return;
|
|
130
|
+
// Right after a gateway restart the sandbox exists but refuses uploads until it is ready.
|
|
131
|
+
await whenSandboxReady(() => uploadFile({ openshell: a.openshell, env: a.env, sandbox: a.sandbox, local: a.local, remoteDir: a.remoteDir }), { pollMs: a.pollMs });
|
|
132
|
+
if (basename(a.local) !== basename(a.bin)) {
|
|
133
|
+
const moved = await a.exec(a.sandbox, ["mv", `${a.remoteDir}/${basename(a.local)}`, a.bin]);
|
|
134
|
+
if (moved.code !== 0)
|
|
135
|
+
throw new Error(`could not install ${a.harnessName} in ${a.sandbox}: ${moved.stderr.trim()}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Links the worktree's node_modules into the sandbox clone, uploading it once per package-lock.json content. */
|
|
139
|
+
export async function linkDeps(a) {
|
|
140
|
+
const local = real(join(a.cwd, "node_modules"));
|
|
141
|
+
const lock = join(a.cwd, "package-lock.json");
|
|
142
|
+
if (!local || !existsSync(lock))
|
|
143
|
+
return;
|
|
144
|
+
const remote = `${DEPS}/${createHash("sha256").update(readFileSync(lock)).digest("hex").slice(0, 16)}`;
|
|
145
|
+
if ((await a.exec(a.sandbox, ["test", "-d", `${remote}/${basename(local)}`])).code !== 0) {
|
|
146
|
+
await uploadTree({ openshell: a.openshell, env: a.env, sandbox: a.sandbox, local, remote, gitIgnore: false });
|
|
147
|
+
}
|
|
148
|
+
// The repo's "node_modules/" pattern does not ignore a symlink, so the clone's own exclude file does.
|
|
149
|
+
const linked = await a.exec(a.sandbox, ["sh", "-c", 'ln -sfn "$1" "$2/node_modules" && grep -qx node_modules "$2/.git/info/exclude" 2>/dev/null || { mkdir -p "$2/.git/info" && echo node_modules >> "$2/.git/info/exclude"; }', "sh", `${remote}/${basename(local)}`, a.workdir]);
|
|
150
|
+
if (linked.code !== 0)
|
|
151
|
+
throw new Error(`could not link node_modules in ${a.sandbox}: ${linked.stderr.trim()}`);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Lands the sandbox clone's commits on the host worktree without downloading the clone (a clone with its history runs to
|
|
155
|
+
* gigabytes): one git bundle of what is new since the host HEAD travels alone. Uncommitted work stays in the sandbox.
|
|
156
|
+
* Returns how many commits landed; throws when the host worktree moved on or cannot fast-forward.
|
|
157
|
+
*/
|
|
158
|
+
export async function landCommits(a) {
|
|
159
|
+
const base = (await git(a.cwd, ["rev-parse", "HEAD"], a.env)).trim();
|
|
160
|
+
const repo = `${WORK}/${basename(a.cwd)}`;
|
|
161
|
+
const sandboxGit = `${TOOLS}/bin/git`;
|
|
162
|
+
const counted = await a.exec(a.sandbox, [sandboxGit, "-C", repo, "rev-list", "--count", `${base}..HEAD`]);
|
|
163
|
+
if (counted.code !== 0)
|
|
164
|
+
throw new Error(`the sandbox clone does not have the host's ${base.slice(0, 8)}: ${counted.stderr.trim() || `exit ${counted.code}`}`);
|
|
165
|
+
const ahead = Number(counted.stdout.trim()) || 0;
|
|
166
|
+
if (!ahead)
|
|
167
|
+
return 0;
|
|
168
|
+
const remote = `${OUT}/land`;
|
|
169
|
+
// bundle runs git-pack-objects, which the uploaded git finds through the tool env that exec does not pass.
|
|
170
|
+
const made = await a.exec(a.sandbox, ["sh", "-c", 'export GIT_EXEC_PATH="$5" LD_LIBRARY_PATH="$6"; rm -rf "$1" && mkdir -p "$1" && "$2" -C "$3" bundle create "$1/land.bundle" "$4..HEAD"', "sh", remote, sandboxGit, repo, base, `${TOOLS}/git-core`, `${TOOLS}/lib`]);
|
|
171
|
+
if (made.code !== 0)
|
|
172
|
+
throw new Error(`could not bundle the sandbox commits: ${made.stderr.trim() || `exit ${made.code}`}`);
|
|
173
|
+
const incoming = mkdtempSync(join(tmpdir(), "temmo-sandbox-land-"));
|
|
174
|
+
try {
|
|
175
|
+
await downloadTree({ openshell: a.openshell, env: a.env, sandbox: a.sandbox, remote, local: incoming });
|
|
176
|
+
await git(a.cwd, ["fetch", "--quiet", join(incoming, "land.bundle"), "HEAD"], a.env);
|
|
177
|
+
await git(a.cwd, ["merge", "--quiet", "--ff-only", "FETCH_HEAD"], a.env);
|
|
178
|
+
a.log(`${a.landing.label}: landed ${ahead} commit(s) from the sandbox on ${a.cwd}`);
|
|
179
|
+
return ahead;
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
rmSync(incoming, { recursive: true, force: true });
|
|
183
|
+
await a.exec(a.sandbox, ["rm", "-rf", remote]).catch(() => undefined);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Brings origin into the sandbox clone, which has no remote of its own (the reverse of landCommits): the host worktree
|
|
188
|
+
* fetches origin, bundles the ref down to what the clone already has, and the clone updates its own
|
|
189
|
+
* refs/remotes/origin/<ref>. A marker file in the sandbox remembers the last sha delivered per ref, so the first fetch
|
|
190
|
+
* of a ref ships it whole and later ones carry only the new commits. Returns the sha and the commit count carried.
|
|
191
|
+
*/
|
|
192
|
+
export async function fetchIntoSandbox(a) {
|
|
193
|
+
const ref = a.ref;
|
|
194
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._/-]*$/.test(ref) || ref.includes(".."))
|
|
195
|
+
throw new Error(`invalid ref: ${ref}`);
|
|
196
|
+
await git(a.cwd, ["fetch", "--quiet", "origin", `+refs/heads/${ref}:refs/remotes/origin/${ref}`], a.env);
|
|
197
|
+
const sha = (await git(a.cwd, ["rev-parse", `refs/remotes/origin/${ref}`], a.env)).trim();
|
|
198
|
+
const repo = `${WORK}/${basename(a.cwd)}`;
|
|
199
|
+
const sandboxGit = `${TOOLS}/bin/git`;
|
|
200
|
+
const marker = `${WORK}/.fetched/${ref.replace(/[^A-Za-z0-9._-]/g, "_")}`;
|
|
201
|
+
const have = await a.exec(a.sandbox, ["cat", marker]);
|
|
202
|
+
const since = /^[a-f0-9]{40}$/.test(have.stdout.trim()) ? have.stdout.trim() : "";
|
|
203
|
+
// A shared history lets the bundle carry only what the clone lacks; a force-push or the first fetch ships the ref whole.
|
|
204
|
+
const ancestor = since !== "" && (await runTool("git", ["-C", a.cwd, "merge-base", "--is-ancestor", since, sha], { env: a.env })).code === 0;
|
|
205
|
+
const count = Number((await git(a.cwd, ["rev-list", "--count", ancestor ? `${since}..${sha}` : sha], a.env)).trim()) || 0;
|
|
206
|
+
const dir = mkdtempSync(join(tmpdir(), "temmo-sandbox-fetch-"));
|
|
207
|
+
const bundle = join(dir, "origin.bundle");
|
|
208
|
+
try {
|
|
209
|
+
await git(a.cwd, ["bundle", "create", bundle, ancestor ? `${since}..refs/remotes/origin/${ref}` : `refs/remotes/origin/${ref}`], a.env);
|
|
210
|
+
await uploadFile({ openshell: a.openshell, env: a.env, sandbox: a.sandbox, local: bundle, remoteDir: `${WORK}/.fetch` });
|
|
211
|
+
// fetch runs git-fetch-pack and git-index-pack, which the uploaded git finds through the tool env that exec does not pass.
|
|
212
|
+
const fetched = await a.exec(a.sandbox, ["sh", "-c",
|
|
213
|
+
'export GIT_EXEC_PATH="$4" LD_LIBRARY_PATH="$5"; "$1" -C "$2" fetch --quiet --force "$3" "refs/remotes/origin/$6:refs/remotes/origin/$6" && mkdir -p "$(dirname "$7")" && printf "%s" "$8" > "$7"',
|
|
214
|
+
"sh", sandboxGit, repo, `${WORK}/.fetch/origin.bundle`, `${TOOLS}/git-core`, `${TOOLS}/lib`, ref, marker, sha]);
|
|
215
|
+
if (fetched.code !== 0)
|
|
216
|
+
throw new Error(`could not fetch into the sandbox clone: ${fetched.stderr.trim() || `exit ${fetched.code}`}`);
|
|
217
|
+
a.log(`fetched origin/${ref} ${sha.slice(0, 8)} (${count} commit(s)) into ${a.sandbox}`);
|
|
218
|
+
return { sha, count };
|
|
219
|
+
}
|
|
220
|
+
finally {
|
|
221
|
+
rmSync(dir, { recursive: true, force: true });
|
|
222
|
+
await a.exec(a.sandbox, ["rm", "-f", `${WORK}/.fetch/origin.bundle`]).catch(() => undefined);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Lands the sandbox's work on the host worktree. By default it refuses uncommitted work in the sandbox clone first and
|
|
227
|
+
* copies the clone (land finish, close). With commitsOnly it lands just the commits, whatever is uncommitted (a turn's end), and
|
|
228
|
+
* returns how many landed.
|
|
229
|
+
*/
|
|
230
|
+
export async function syncBackWork(a) {
|
|
231
|
+
if (a.commitsOnly)
|
|
232
|
+
return landCommits(a);
|
|
233
|
+
const status = await a.exec(a.sandbox, [`${TOOLS}/bin/git`, "-C", `${WORK}/${basename(a.cwd)}`, "status", "--porcelain"]);
|
|
234
|
+
if (status.code !== 0)
|
|
235
|
+
throw new Error(`git status in the sandbox failed: ${status.stderr.trim() || `exit ${status.code}`}`);
|
|
236
|
+
if (status.stdout.trim())
|
|
237
|
+
throw new Error("commit your work in the sandbox first");
|
|
238
|
+
if (!(await syncSandboxBack({ openshell: a.openshell, env: a.env, sandbox: a.sandbox, cwd: a.cwd, log: a.log, label: a.landing.label, trailer: a.landing.trailer }))) {
|
|
239
|
+
throw new Error("could not copy the sandbox commits to the host worktree");
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/** Lands the session's work, drops its claim, and with the last claim runs stopBox, forgets the staged work, and deletes the sandbox. */
|
|
243
|
+
export async function releaseClaim(a) {
|
|
244
|
+
if (!a.ledger.holds(a.name, a.id))
|
|
245
|
+
return true;
|
|
246
|
+
let ok = true;
|
|
247
|
+
if (a.cwd)
|
|
248
|
+
ok = await syncSandboxBack({ openshell: a.openshell, env: a.env, sandbox: a.name, cwd: a.cwd, log: a.log, label: a.landing.label, trailer: a.landing.trailer });
|
|
249
|
+
a.forgetWork?.(a.cwd);
|
|
250
|
+
if (!a.ledger.drop(a.name, a.id))
|
|
251
|
+
return ok;
|
|
252
|
+
if (a.stopBox)
|
|
253
|
+
await a.stopBox();
|
|
254
|
+
const out = await destroyOwnedSandboxes({ openshell: a.openshell, env: a.env, project: a.project, kind: "session", owner: a.owner, log: a.log });
|
|
255
|
+
if (!out.ok)
|
|
256
|
+
a.log(`${a.landing.label}: could not delete sandbox ${a.name}: ${out.detail}`);
|
|
257
|
+
return ok && out.ok;
|
|
258
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `temmo sandbox ...`: the operator's terminal mirror of the phone card for sandbox change proposals
|
|
3
|
+
* (docs/sandbox-proposals.md). approve and deny apply on this host: they write the two config files and re-apply
|
|
4
|
+
* to live sandboxes, exactly like the UI server's authenticated route; a proposal applies at most once.
|
|
5
|
+
*/
|
|
6
|
+
import { MANAGED_ENV } from "./agent-guard.js";
|
|
7
|
+
import { onHost } from "./run-terminal.js";
|
|
8
|
+
import { applySandboxChange, announceChangeDecision, denySandboxChange, currentConfig, findProposal, listProposals, proposeSandboxChange, renderDiff, validateChange, waitForChangeResult, } from "./sandbox-proposal.js";
|
|
9
|
+
const USAGE = `usage: temmo sandbox <propose|pending|approve|deny|status> [...]
|
|
10
|
+
propose --reason "<why>" [--add-host <host[:port]>]... [--remove-host <host[:port]>]...
|
|
11
|
+
[--add-tool <name>]... [--remove-tool <name>]...
|
|
12
|
+
post the proposal card to the operator; it changes nothing until approved
|
|
13
|
+
pending list open proposals with the before/after diff of this machine's config
|
|
14
|
+
approve <id> apply an approved proposal: write the config files, re-apply to live sandboxes
|
|
15
|
+
deny <id> [why] close a proposal as denied
|
|
16
|
+
approve and deny need an interactive terminal: an agent session cannot decide
|
|
17
|
+
status <id> [seconds] wait for a proposal's outcome: pending, applied, denied, skipped, failed
|
|
18
|
+
Approving applies to every sandbox: ~/.config/temmo/sandbox-hosts.json and sandbox-tools.json are one shared config.`;
|
|
19
|
+
const HELP_FLAGS = ["--help", "-h"];
|
|
20
|
+
/** Flag pairs and repeated flags: --add-host a --add-host b --reason "x" → {add_host: [a, b], reason: "x"}. */
|
|
21
|
+
function parseFlags(args) {
|
|
22
|
+
const REPEAT = new Set(["add-host", "remove-host", "add-tool", "remove-tool"]);
|
|
23
|
+
const flags = {};
|
|
24
|
+
const positional = [];
|
|
25
|
+
for (let i = 0; i < args.length; i++) {
|
|
26
|
+
const arg = args[i];
|
|
27
|
+
if (!arg.startsWith("--")) {
|
|
28
|
+
positional.push(arg);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const key = arg.slice(2);
|
|
32
|
+
const value = args[++i];
|
|
33
|
+
if (value === undefined || value.startsWith("--"))
|
|
34
|
+
return { flags, positional, bad: `--${key} needs a value` };
|
|
35
|
+
if (REPEAT.has(key)) {
|
|
36
|
+
const prev = flags[key];
|
|
37
|
+
flags[key] = [...(Array.isArray(prev) ? prev : prev ? [prev] : []), value];
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
flags[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return { flags, positional };
|
|
43
|
+
}
|
|
44
|
+
async function propose(cfg, args, { env, out, err }) {
|
|
45
|
+
const { flags, positional, bad } = parseFlags(args);
|
|
46
|
+
if (bad || positional.length) {
|
|
47
|
+
err.write(`temmo: sandbox propose: ${bad || "unexpected argument"}\n${USAGE}\n`);
|
|
48
|
+
return 1;
|
|
49
|
+
}
|
|
50
|
+
const list = (k) => { const v = flags[k]; return v === undefined ? undefined : [].concat(v); };
|
|
51
|
+
try {
|
|
52
|
+
const result = await proposeSandboxChange(cfg, {
|
|
53
|
+
add_hosts: list("add-host"), remove_hosts: list("remove-host"),
|
|
54
|
+
add_tools: list("add-tool"), remove_tools: list("remove-tool"), reason: flags.reason,
|
|
55
|
+
}, { env, harness: "cli" });
|
|
56
|
+
out.write(`proposed ${result.id} (pending the operator's approval)\n${result.diff}\n`);
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
err.write(`temmo: sandbox propose: ${error.message}\n`);
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** The diff an operator should judge: the proposal's change against this machine's live config, not the proposer's copy. */
|
|
65
|
+
function liveDiff(p, env) {
|
|
66
|
+
const c = (p.change ?? {});
|
|
67
|
+
const valid = validateChange({ ...c, reason: "x" });
|
|
68
|
+
if ("error" in valid)
|
|
69
|
+
return p.diff;
|
|
70
|
+
return renderDiff(valid.change, currentConfig(env));
|
|
71
|
+
}
|
|
72
|
+
async function pending(cfg, { env, out, err }) {
|
|
73
|
+
const open = (await listProposals(cfg)).filter((p) => p.status === "pending");
|
|
74
|
+
if (!open.length) {
|
|
75
|
+
out.write("no open sandbox change proposals\n");
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
for (const p of open) {
|
|
79
|
+
out.write(`${p.id} from ${p.sender} ${new Date(p.askedAt).toISOString()}\n reason: ${p.reason}\n${liveDiff(p, env).split("\n").map((l) => ` ${l}`).join("\n")}\n\n`);
|
|
80
|
+
}
|
|
81
|
+
out.write(`approve with: temmo sandbox approve <id>; deny with: temmo sandbox deny <id>\n`);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
async function approve(cfg, args, { env, out, err, deps }) {
|
|
85
|
+
const [id] = args;
|
|
86
|
+
if (!id) {
|
|
87
|
+
err.write("temmo: usage: sandbox approve <id>\n");
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
const found = await findProposal(cfg, id);
|
|
91
|
+
if (!found) {
|
|
92
|
+
err.write(`temmo: sandbox approve: no proposal ${id} on the project channel\n`);
|
|
93
|
+
return 1;
|
|
94
|
+
}
|
|
95
|
+
if (found.status !== "pending") {
|
|
96
|
+
err.write(`temmo: sandbox approve: already ${found.status}${found.why ? `: ${found.why}` : ""}\n`);
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
99
|
+
const result = await applySandboxChange({ stateDir: cfg.stateDir, project: cfg.project, id, change: found.change, by: cfg.peer, env, reapply: deps.reapply });
|
|
100
|
+
if (result.status === "applied") {
|
|
101
|
+
out.write(`applied ${id}: ${result.detail}\n`);
|
|
102
|
+
await announceChangeDecision(cfg, { id, session: found.session || undefined, reason: "allowed", detail: result.detail });
|
|
103
|
+
return 0;
|
|
104
|
+
}
|
|
105
|
+
const why = "why" in result ? result.why : "already decided";
|
|
106
|
+
err.write(`temmo: sandbox approve: ${why}\n`);
|
|
107
|
+
if (result.status === "failed")
|
|
108
|
+
await announceChangeDecision(cfg, { id, reason: "cancelled", detail: why });
|
|
109
|
+
return 1;
|
|
110
|
+
}
|
|
111
|
+
async function deny(cfg, args, { env, out, err }) {
|
|
112
|
+
const [id, ...why] = args;
|
|
113
|
+
if (!id) {
|
|
114
|
+
err.write("temmo: usage: sandbox deny <id> [why]\n");
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
const found = await findProposal(cfg, id);
|
|
118
|
+
if (!found) {
|
|
119
|
+
err.write(`temmo: sandbox deny: no proposal ${id} on the project channel\n`);
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
if (found.status !== "pending") {
|
|
123
|
+
err.write(`temmo: sandbox deny: already ${found.status}\n`);
|
|
124
|
+
return 1;
|
|
125
|
+
}
|
|
126
|
+
const result = denySandboxChange({ stateDir: cfg.stateDir, project: cfg.project, id, by: cfg.peer, why: why.join(" ") });
|
|
127
|
+
if (result.status !== "denied") {
|
|
128
|
+
err.write(`temmo: sandbox deny: ${"why" in result ? result.why : "already decided"}\n`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
out.write(`denied ${id}\n`);
|
|
132
|
+
await announceChangeDecision(cfg, { id, reason: "denied", detail: why.join(" ") || "denied from the terminal" });
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
async function status(cfg, args, { out, err }) {
|
|
136
|
+
const [id, secs] = args;
|
|
137
|
+
if (!id) {
|
|
138
|
+
err.write("temmo: usage: sandbox status <id> [seconds]\n");
|
|
139
|
+
return 1;
|
|
140
|
+
}
|
|
141
|
+
const seconds = secs === undefined ? 25 : Number(secs);
|
|
142
|
+
if (!Number.isFinite(seconds) || seconds < 0 || seconds > 45) {
|
|
143
|
+
err.write("temmo: seconds must be 0 to 45\n");
|
|
144
|
+
return 1;
|
|
145
|
+
}
|
|
146
|
+
const result = await waitForChangeResult(cfg, id, { seconds });
|
|
147
|
+
out.write(`${result.id}\t${result.status}${result.why ? `\t${result.why}` : ""}\n`);
|
|
148
|
+
return result.status === "pending" ? 2 : result.status === "applied" ? 0 : 1;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Whether this process may decide a proposal from the terminal. An agent that has a host shell (a folder
|
|
152
|
+
* place) still carries MANAGED_ENV, and a piped stdin means nobody is typing; either way the decision
|
|
153
|
+
* belongs to the UI or to a human at a keyboard. docs/sandbox-proposals.md.
|
|
154
|
+
*/
|
|
155
|
+
function decideRefused(env, stdin) {
|
|
156
|
+
return env[MANAGED_ENV] === "1" || stdin.isTTY !== true;
|
|
157
|
+
}
|
|
158
|
+
export async function sandboxCli(argv, { env, cfg, out, err, deps = {}, stdin = process.stdin }) {
|
|
159
|
+
const [sub = "help", ...rest] = argv;
|
|
160
|
+
if (sub === "help" || HELP_FLAGS.includes(sub)) {
|
|
161
|
+
out.write(`${USAGE}\n`);
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
if (!cfg.enabled) {
|
|
165
|
+
err.write(`temmo: disabled: ${cfg.reason}\n`);
|
|
166
|
+
return 2;
|
|
167
|
+
}
|
|
168
|
+
if (sub === "propose")
|
|
169
|
+
return propose(cfg, rest, { env, out, err });
|
|
170
|
+
if (sub === "pending")
|
|
171
|
+
return pending(cfg, { env, out, err });
|
|
172
|
+
if (sub === "status")
|
|
173
|
+
return status(cfg, rest, { env, out, err });
|
|
174
|
+
if (!onHost(env)) {
|
|
175
|
+
err.write("temmo: sandbox approve/deny run on the host, not in a sandbox\n");
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
if (decideRefused(env, stdin)) {
|
|
179
|
+
err.write("temmo: sandbox approve/deny: approve from the UI or an interactive terminal\n");
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
if (sub === "approve")
|
|
183
|
+
return approve(cfg, rest, { env, out, err, deps });
|
|
184
|
+
if (sub === "deny")
|
|
185
|
+
return deny(cfg, rest, { env, out, err });
|
|
186
|
+
err.write(`temmo: sandbox: unknown command "${sub}"\n${USAGE}\n`);
|
|
187
|
+
return 1;
|
|
188
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** `temmo sandbox-hosts ...`: list, add or remove personal web hosts for OpenShell sandboxes. */
|
|
2
|
+
import { addSandboxHosts, formatHostSpec, readSandboxHosts, removeSandboxHosts, sandboxHostsPath, } from "./sandbox-hosts.js";
|
|
3
|
+
const USAGE = `usage: temmo sandbox-hosts <list|add|remove> [host[:port]...]
|
|
4
|
+
list print personal sandbox web hosts (from ~/.config/temmo/sandbox-hosts.json)
|
|
5
|
+
add <host[:port]>... append hosts; regenerating sandbox policy never overwrites that file
|
|
6
|
+
remove <host[:port]>...
|
|
7
|
+
drop hosts from the file
|
|
8
|
+
Hosts take effect on the next sandbox create, reuse, or deploy (policy set).`;
|
|
9
|
+
const HELP_FLAGS = ["--help", "-h"];
|
|
10
|
+
export function sandboxHostsCli(argv, { env, out, err }) {
|
|
11
|
+
const [sub = "list", ...rest] = argv;
|
|
12
|
+
if (sub === "help" || HELP_FLAGS.includes(sub) || rest.some((a) => HELP_FLAGS.includes(a))) {
|
|
13
|
+
out.write(`${USAGE}\n`);
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
if (sub === "list") {
|
|
17
|
+
if (rest.length) {
|
|
18
|
+
err.write(`temmo: ${USAGE}\n`);
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
const hosts = readSandboxHosts(env);
|
|
22
|
+
const file = sandboxHostsPath(env);
|
|
23
|
+
if (!hosts.length) {
|
|
24
|
+
out.write(`no personal sandbox hosts in ${file}\n`);
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
out.write(`${hosts.map(formatHostSpec).join("\n")}\n`);
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
if (sub === "add") {
|
|
31
|
+
if (!rest.length) {
|
|
32
|
+
err.write("temmo: usage: sandbox-hosts add <host[:port]>...\n");
|
|
33
|
+
return 1;
|
|
34
|
+
}
|
|
35
|
+
const result = addSandboxHosts(rest, env);
|
|
36
|
+
if ("error" in result) {
|
|
37
|
+
err.write(`temmo: sandbox-hosts: ${result.error}\n`);
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
if (!result.added.length) {
|
|
41
|
+
out.write(`already listed: ${rest.map((s) => s.trim()).join(", ")} (${sandboxHostsPath(env)})\n`);
|
|
42
|
+
return 0;
|
|
43
|
+
}
|
|
44
|
+
out.write(`added ${result.added.map(formatHostSpec).join(", ")} → ${sandboxHostsPath(env)}\n`);
|
|
45
|
+
out.write("takes effect on the next sandbox create, reuse, or deploy\n");
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
if (sub === "remove") {
|
|
49
|
+
if (!rest.length) {
|
|
50
|
+
err.write("temmo: usage: sandbox-hosts remove <host[:port]>...\n");
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
53
|
+
const result = removeSandboxHosts(rest, env);
|
|
54
|
+
if ("error" in result) {
|
|
55
|
+
err.write(`temmo: sandbox-hosts: ${result.error}\n`);
|
|
56
|
+
return 1;
|
|
57
|
+
}
|
|
58
|
+
if (!result.removed.length) {
|
|
59
|
+
out.write(`not listed: ${rest.map((s) => s.trim()).join(", ")}\n`);
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
out.write(`removed ${result.removed.map(formatHostSpec).join(", ")} → ${sandboxHostsPath(env)}\n`);
|
|
63
|
+
out.write("takes effect on the next sandbox create, reuse, or deploy\n");
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
err.write(`temmo: sandbox-hosts: unknown command "${sub}"\n${USAGE}\n`);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|