@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
package/package.json
CHANGED
|
@@ -1,6 +1,112 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temmo/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.19.0",
|
|
4
|
+
"description": "Best-effort messaging and status between coding-agent peers over a private local message bus (Postgres-backed, loopback only).",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=24"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"temmo": "scripts/temmo.mjs",
|
|
12
|
+
"ai-collab": "scripts/temmo.mjs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
".claude-plugin",
|
|
16
|
+
".codex-plugin",
|
|
17
|
+
".cursor-plugin",
|
|
18
|
+
".mcp.json",
|
|
19
|
+
"commands",
|
|
20
|
+
"deploy",
|
|
21
|
+
"tools/smoke-ui.mjs",
|
|
22
|
+
"tools/screen-state.mjs",
|
|
23
|
+
"harness-core",
|
|
24
|
+
"hooks",
|
|
25
|
+
"lib",
|
|
26
|
+
"runner",
|
|
27
|
+
"scripts/*.mjs",
|
|
28
|
+
"scripts/temmo",
|
|
29
|
+
"scripts/temmo-hook",
|
|
30
|
+
"scripts/ai-collab",
|
|
31
|
+
"scripts/ai-collab-hook",
|
|
32
|
+
"skills",
|
|
33
|
+
"THIRD_PARTY_NOTICES",
|
|
34
|
+
"web/app",
|
|
35
|
+
"web/components",
|
|
36
|
+
"web/lib",
|
|
37
|
+
"web/public",
|
|
38
|
+
"web/server",
|
|
39
|
+
"web/*.js",
|
|
40
|
+
"web/*.mjs",
|
|
41
|
+
"web/*.json"
|
|
42
|
+
],
|
|
43
|
+
"scripts": {
|
|
44
|
+
"lint": "oxlint .",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.core.json",
|
|
46
|
+
"build:package": "node tools/build-package.mjs",
|
|
47
|
+
"test": "node --test --test-timeout=300000 --test-global-setup=test/helpers/global-setup.mjs",
|
|
48
|
+
"land": "node tools/land.mjs",
|
|
49
|
+
"tlc": "node tools/tlc.mjs",
|
|
50
|
+
"tla-tie": "danger local --base origin/main --text-only --failOnErrors",
|
|
51
|
+
"build": "node deploy/build-ui.mjs",
|
|
52
|
+
"runner": "node runner/main.mjs",
|
|
53
|
+
"ui": "next start web -H 127.0.0.1 -p ${TEMMO_UI_PORT:-8795}",
|
|
54
|
+
"demo": "TEMMO_NEXT_DIST=.next-demo next build web && TEMMO_NEXT_DIST=.next-demo node scripts/demo/record.mjs",
|
|
55
|
+
"vendor:mcp": "node tools/vendor-mcp-sdk.mjs"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@a2ui/react": "^0.15.0",
|
|
59
|
+
"@a2ui/web_core": "^0.15.0",
|
|
60
|
+
"@ag-ui/client": "^1.0.5",
|
|
61
|
+
"@ag-ui/core": "^1.0.5",
|
|
62
|
+
"@anthropic-ai/claude-agent-sdk": "^0.3.330",
|
|
63
|
+
"@assistant-ui/react": "^0.15.38",
|
|
64
|
+
"@assistant-ui/react-markdown": "^0.14.26",
|
|
65
|
+
"@dbos-inc/dbos-sdk": "5.7.0",
|
|
66
|
+
"@pierre/diffs": "^1.6.4",
|
|
67
|
+
"@tailwindcss/postcss": "^4.3.5",
|
|
68
|
+
"@ui-sdk/core": "0.1.0-beta.16",
|
|
69
|
+
"@ui-sdk/react": "0.1.0-beta.16",
|
|
70
|
+
"class-variance-authority": "^0.7.1",
|
|
71
|
+
"clsx": "^2.1.1",
|
|
72
|
+
"lucide-react": "^1.77.0",
|
|
73
|
+
"next": "^16.4.6",
|
|
74
|
+
"next-themes": "^0.4.6",
|
|
75
|
+
"pg": "^8.23.1",
|
|
76
|
+
"radix-ui": "^1.8.1",
|
|
77
|
+
"react": "^19.3.1",
|
|
78
|
+
"react-dom": "^19.3.1",
|
|
79
|
+
"react-markdown": "^10.1.0",
|
|
80
|
+
"remark-breaks": "^4.0.0",
|
|
81
|
+
"remark-gfm": "^4.0.1",
|
|
82
|
+
"shiki": "^4.6.0",
|
|
83
|
+
"sonner": "^2.0.8",
|
|
84
|
+
"tailwind-merge": "^3.7.1",
|
|
85
|
+
"tailwindcss": "^4.3.5",
|
|
86
|
+
"tw-animate-css": "^1.4.0",
|
|
87
|
+
"use-stick-to-bottom": "^1.1.6",
|
|
88
|
+
"web-push": "^4.0.0",
|
|
89
|
+
"zod-v3": "npm:zod@^3.25.76"
|
|
90
|
+
},
|
|
91
|
+
"devDependencies": {
|
|
92
|
+
"@cloudflare/oxlint-config": "^0.2.0",
|
|
93
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
94
|
+
"@types/node": "22.20.5",
|
|
95
|
+
"@types/pg": "^8.23.1",
|
|
96
|
+
"@types/react": "19.3.0",
|
|
97
|
+
"@types/react-dom": "19.3.0",
|
|
98
|
+
"danger": "14.1.0",
|
|
99
|
+
"esbuild": "0.28.2",
|
|
100
|
+
"fast-check": "^4.11.0",
|
|
101
|
+
"gifenc": "^1.0.3",
|
|
102
|
+
"oxlint": "^1.95.0",
|
|
103
|
+
"playwright-core": "1.65.1",
|
|
104
|
+
"sharp": "^0.35.5",
|
|
105
|
+
"tsrs": "^7.1.0-beta.tsrs5",
|
|
106
|
+
"typescript": "6.0.3"
|
|
107
|
+
},
|
|
108
|
+
"repository": {
|
|
109
|
+
"type": "git",
|
|
110
|
+
"url": "git+https://github.com/bcmyguest/temmo.git"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// Claude adapter: one Agent SDK query() per owned session (docs/owned-sessions-contract.md, "Adapter interface").
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { EventType } from "@ag-ui/core";
|
|
5
|
+
import { query as sdkQuery } from "@anthropic-ai/claude-agent-sdk";
|
|
6
|
+
import { sessionLabel } from "../../lib/config.js";
|
|
7
|
+
import { childEnv } from "../../lib/sessions/launch.js";
|
|
8
|
+
import { findExecutable } from "../../lib/sessions/scope.js";
|
|
9
|
+
import { classifyLimit } from "../../lib/limits.js";
|
|
10
|
+
import { claudeCodeModeSettings } from "../../lib/code-mode.js";
|
|
11
|
+
import { CLAUDE_SUBAGENT_TOOLS } from "../../lib/subagent-guard.js";
|
|
12
|
+
import { APPROVAL_REQUESTED, APPROVAL_RESOLVED, LIMIT, PERMISSION_MODES, permissionSettings } from "../contract.js";
|
|
13
|
+
import { busMcpServer, codeMcpServer } from "../../lib/sandbox-app.js";
|
|
14
|
+
import { CLAUDE_LEAN_SETTINGS, CLAUDE_SESSION_TOOL_DENY } from "../../lib/builder/policy.js";
|
|
15
|
+
import { CLAUDE_IN, claudeSpawner, createClaudeSandbox, withSelfNote } from "./cli-sandbox.js";
|
|
16
|
+
// Env marker on the CLI child; hooks stand down by the owned record, this names the harness that spawned the child.
|
|
17
|
+
export const OWNED_ENV = "TEMMO_OWNED";
|
|
18
|
+
const ASK_QUESTION = "AskUserQuestion";
|
|
19
|
+
const HANDSHAKE_MS = 60_000;
|
|
20
|
+
const COMPACT_MS = 5 * 60_000;
|
|
21
|
+
/** A push-based async iterable: the SDK reads user messages from it, and end() closes it. */
|
|
22
|
+
export function inputQueue() {
|
|
23
|
+
const items = [];
|
|
24
|
+
let wake = null;
|
|
25
|
+
let ended = false;
|
|
26
|
+
return {
|
|
27
|
+
push(message) { items.push(message); wake?.(); wake = null; },
|
|
28
|
+
end() { ended = true; wake?.(); wake = null; },
|
|
29
|
+
async *[Symbol.asyncIterator]() {
|
|
30
|
+
for (;;) {
|
|
31
|
+
if (items.length) {
|
|
32
|
+
yield items.shift();
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (ended)
|
|
36
|
+
return;
|
|
37
|
+
await new Promise((resolve) => { wake = resolve; });
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const textOf = (content) => (typeof content === "string" ? content
|
|
43
|
+
: (Array.isArray(content) ? content.filter((b) => b?.type === "text").map((b) => b.text).join("\n") : ""));
|
|
44
|
+
/** A one-line description of a tool call for the approval card. */
|
|
45
|
+
export function summarize(toolName, input) {
|
|
46
|
+
if (typeof input?.command === "string")
|
|
47
|
+
return input.command;
|
|
48
|
+
if (typeof input?.file_path === "string")
|
|
49
|
+
return `${toolName} ${input.file_path}`;
|
|
50
|
+
return `${toolName} ${JSON.stringify(input ?? {}).slice(0, 500)}`;
|
|
51
|
+
}
|
|
52
|
+
/** An SDKUserMessage carrying the input's text and images. */
|
|
53
|
+
async function userMessage(input, priority) {
|
|
54
|
+
const images = await Promise.all((input.images || []).map(async (image) => ({
|
|
55
|
+
type: "image",
|
|
56
|
+
source: { type: "base64", media_type: image.mime, data: (await readFile(image.path)).toString("base64") },
|
|
57
|
+
})));
|
|
58
|
+
const content = images.length ? [...images, { type: "text", text: input.text }] : input.text;
|
|
59
|
+
return { type: "user", message: { role: "user", content }, parent_tool_use_id: null, ...(priority ? { priority } : {}) };
|
|
60
|
+
}
|
|
61
|
+
/** Starts one session's query and message pump; attach() awaits the handshake before the handle is used. */
|
|
62
|
+
function startSession({ query, ctx, nativeId, address, cwd, model, permission, env, resume, codeMode, managed, launch, lean, allowFullAccess }) {
|
|
63
|
+
// An owned record keeps its address across a pad restart, which gives the conversation a new native id; run events
|
|
64
|
+
// under any other threadId are dropped by the runner, leaving the record running with no run.
|
|
65
|
+
const threadId = address ?? `claude#${sessionLabel(nativeId)}`;
|
|
66
|
+
const inputs = inputQueue();
|
|
67
|
+
const pending = new Map();
|
|
68
|
+
const toolNames = new Map();
|
|
69
|
+
// Watchers for an in-flight compact(), fed every message before the run/approval branches.
|
|
70
|
+
const compactWatch = new Set();
|
|
71
|
+
let run = null;
|
|
72
|
+
let closed = false;
|
|
73
|
+
let ended = false;
|
|
74
|
+
const q = query({
|
|
75
|
+
prompt: inputs,
|
|
76
|
+
options: {
|
|
77
|
+
cwd,
|
|
78
|
+
env: { ...env, [OWNED_ENV]: "claude", TEMMO_PARENT: threadId },
|
|
79
|
+
permissionMode: permission.permissionMode,
|
|
80
|
+
// The SDK refuses a later setPermissionMode("bypassPermissions") unless the query opened with this.
|
|
81
|
+
...(allowFullAccess ? { allowDangerouslySkipPermissions: true } : {}),
|
|
82
|
+
canUseTool: (toolName, input, extra) => canUseTool(toolName, input, extra),
|
|
83
|
+
...(model ? { model } : {}),
|
|
84
|
+
// A managed session has no native subagents (temmo spawn_agent replaces them); a boxed one drops the lean deny list too.
|
|
85
|
+
...(managed || lean ? { disallowedTools: [...(managed ? CLAUDE_SUBAGENT_TOOLS : []), ...(lean?.disallowedTools ?? [])] } : {}),
|
|
86
|
+
// Flag settings are the only layer a headless Claude reads code mode from (lib/code-mode.ts); a boxed one adds the lean keys.
|
|
87
|
+
...(typeof codeMode === "boolean" || lean ? { settings: { ...lean?.settings, ...(typeof codeMode === "boolean" ? claudeCodeModeSettings(codeMode) : {}) } } : {}),
|
|
88
|
+
...(resume ? { resume: nativeId } : { sessionId: nativeId }),
|
|
89
|
+
// An OpenShell session's CLI runs in its sandbox through this spawner (createClaudeAdapter's sandbox).
|
|
90
|
+
...(launch ?? {}),
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
// Settles one approval: the SDK gets the decision, and the card gets its resolution event once.
|
|
94
|
+
function settle(interruptId, decision, value) {
|
|
95
|
+
const card = pending.get(interruptId);
|
|
96
|
+
if (!card)
|
|
97
|
+
return;
|
|
98
|
+
pending.delete(interruptId);
|
|
99
|
+
card.signal?.removeEventListener("abort", card.onAbort);
|
|
100
|
+
ctx.emit({ type: EventType.CUSTOM, name: APPROVAL_RESOLVED, value: { interruptId, ...value } });
|
|
101
|
+
card.resolve(decision);
|
|
102
|
+
}
|
|
103
|
+
function cancelPending(status) {
|
|
104
|
+
for (const interruptId of [...pending.keys()]) {
|
|
105
|
+
settle(interruptId, { behavior: "deny", message: "the run was cancelled" }, { status, reason: "cancelled" });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function finishRun({ error }) {
|
|
109
|
+
const finished = run;
|
|
110
|
+
run = null;
|
|
111
|
+
if (!finished)
|
|
112
|
+
return;
|
|
113
|
+
if (error)
|
|
114
|
+
ctx.emit({ type: EventType.RUN_ERROR, message: error, metadata: { aiCollab: { runId: finished.runId } } });
|
|
115
|
+
else
|
|
116
|
+
ctx.emit({ type: EventType.RUN_FINISHED, threadId, runId: finished.runId, outcome: { type: finished.cancelled ? "cancelled" : "success" } });
|
|
117
|
+
}
|
|
118
|
+
function canUseTool(toolName, input, { signal, toolUseID }) {
|
|
119
|
+
const interruptId = randomUUID();
|
|
120
|
+
const question = toolName === ASK_QUESTION;
|
|
121
|
+
ctx.emit({
|
|
122
|
+
type: EventType.CUSTOM, name: APPROVAL_REQUESTED,
|
|
123
|
+
value: {
|
|
124
|
+
interruptId, reason: question ? "question" : "tool_approval", toolCallId: toolUseID, toolCallName: toolName,
|
|
125
|
+
summary: summarize(toolName, input), ...(question ? { questions: input.questions ?? [] } : {}),
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
return new Promise((resolve) => {
|
|
129
|
+
const onAbort = () => cancelPending("cancelled");
|
|
130
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
131
|
+
pending.set(interruptId, { resolve, signal, onAbort, question, input });
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
// The operator's answer to an approval card, by interruptId; an unknown id is ignored.
|
|
135
|
+
function respond(interruptId, decision) {
|
|
136
|
+
const card = pending.get(interruptId);
|
|
137
|
+
if (!card)
|
|
138
|
+
return;
|
|
139
|
+
if (decision.behavior !== "allow") {
|
|
140
|
+
settle(interruptId, { behavior: "deny", message: decision.message || "denied by the operator" }, { status: "resolved", reason: "denied" });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const reason = card.question ? "answered" : "allowed";
|
|
144
|
+
const updatedInput = card.question ? { ...card.input, answers: decision.answers ?? {} } : card.input;
|
|
145
|
+
settle(interruptId, { behavior: "allow", updatedInput }, { status: "resolved", reason });
|
|
146
|
+
}
|
|
147
|
+
function onMessage(msg) {
|
|
148
|
+
// A compaction in flight sees the boundary and status messages before anything else claims them.
|
|
149
|
+
if (compactWatch.size)
|
|
150
|
+
for (const watch of [...compactWatch])
|
|
151
|
+
watch(msg);
|
|
152
|
+
const attribution = msg.parent_tool_use_id ? { subagentRunId: msg.parent_tool_use_id } : {};
|
|
153
|
+
if (msg.type === "assistant") {
|
|
154
|
+
msg.message.content.forEach((block, index) => {
|
|
155
|
+
if (block.type === "text" && block.text) {
|
|
156
|
+
ctx.emit({ type: EventType.TEXT_MESSAGE_CHUNK, messageId: `${msg.uuid}:${index}`, role: "assistant", delta: block.text, ...attribution });
|
|
157
|
+
}
|
|
158
|
+
else if (block.type === "tool_use") {
|
|
159
|
+
toolNames.set(block.id, block.name);
|
|
160
|
+
ctx.emit({ type: EventType.TOOL_CALL_CHUNK, toolCallId: block.id, toolCallName: block.name, delta: JSON.stringify(block.input, null, 2), ...attribution });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
else if (msg.type === "user" && Array.isArray(msg.message?.content)) {
|
|
165
|
+
for (const block of msg.message.content) {
|
|
166
|
+
if (block.type !== "tool_result")
|
|
167
|
+
continue;
|
|
168
|
+
ctx.emit({
|
|
169
|
+
type: EventType.TOOL_CALL_RESULT, toolCallId: block.tool_use_id, messageId: `${block.tool_use_id}:result`, role: "tool",
|
|
170
|
+
content: textOf(block.content),
|
|
171
|
+
metadata: { aiCollab: { toolCallName: toolNames.get(block.tool_use_id) || "tool", failed: block.is_error === true } },
|
|
172
|
+
...attribution,
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (msg.type === "system" && msg.subtype === "compact_boundary") {
|
|
177
|
+
// The SDK reports a compaction once it has finished, so only the finished step is emitted.
|
|
178
|
+
const { trigger, pre_tokens: tokensBefore, post_tokens: tokensAfter } = msg.compact_metadata ?? {};
|
|
179
|
+
ctx.emit({ type: EventType.STEP_FINISHED, stepName: "compact", metadata: { aiCollab: { compaction: { trigger, phase: "finished", tokensBefore, tokensAfter } } } });
|
|
180
|
+
}
|
|
181
|
+
else if (msg.type === "rate_limit_event") {
|
|
182
|
+
// sdk.d.ts:6224; only a rejected window is a limit (lib/limits.ts).
|
|
183
|
+
const limit = classifyLimit("claude", { kind: "rate_limit_event", rate_limit_info: msg.rate_limit_info });
|
|
184
|
+
if (limit)
|
|
185
|
+
ctx.emit({ type: EventType.CUSTOM, name: LIMIT, value: limit, ...attribution });
|
|
186
|
+
}
|
|
187
|
+
else if (msg.type === "result") {
|
|
188
|
+
finishRun(msg.is_error && !run?.cancelled ? { error: msg.errors?.join("; ") || msg.subtype } : {});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// Owns the query's lifetime: a failed or exited process ends the open run with RUN_ERROR.
|
|
192
|
+
void (async () => {
|
|
193
|
+
try {
|
|
194
|
+
for await (const msg of q)
|
|
195
|
+
onMessage(msg);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (!closed)
|
|
199
|
+
ctx.log(`claude query failed: ${error.message}`);
|
|
200
|
+
if (!closed && run)
|
|
201
|
+
finishRun({ error: `claude session failed: ${error.message}` });
|
|
202
|
+
}
|
|
203
|
+
finally {
|
|
204
|
+
ended = true;
|
|
205
|
+
if (!closed) {
|
|
206
|
+
if (run)
|
|
207
|
+
finishRun({ error: "claude process exited during a run" });
|
|
208
|
+
cancelPending("cancelled");
|
|
209
|
+
for (const watch of [...compactWatch])
|
|
210
|
+
watch({ type: "system", subtype: "status", compact_result: "failed", compact_error: "the claude process exited" });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
})();
|
|
214
|
+
const handle = {
|
|
215
|
+
nativeId,
|
|
216
|
+
async send(input) {
|
|
217
|
+
if (closed || ended)
|
|
218
|
+
throw new Error("the claude session has ended");
|
|
219
|
+
if (run)
|
|
220
|
+
throw new Error("claude: a run is already running");
|
|
221
|
+
const runId = randomUUID();
|
|
222
|
+
run = { runId, cancelled: false };
|
|
223
|
+
try {
|
|
224
|
+
const message = await userMessage(input);
|
|
225
|
+
ctx.emit({
|
|
226
|
+
type: EventType.RUN_STARTED, threadId, runId,
|
|
227
|
+
input: { threadId, runId, tools: [], context: [], messages: [{ id: `${runId}:input`, role: "user", content: input.text }] },
|
|
228
|
+
});
|
|
229
|
+
inputs.push(message);
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
run = null;
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
return { runId };
|
|
236
|
+
},
|
|
237
|
+
async steer(input) {
|
|
238
|
+
if (!run)
|
|
239
|
+
throw new Error("claude: no run to steer");
|
|
240
|
+
inputs.push(await userMessage(input, "now"));
|
|
241
|
+
},
|
|
242
|
+
async interrupt() {
|
|
243
|
+
if (!run)
|
|
244
|
+
return;
|
|
245
|
+
run.cancelled = true;
|
|
246
|
+
cancelPending("cancelled");
|
|
247
|
+
await q.interrupt();
|
|
248
|
+
},
|
|
249
|
+
async setModel(model) {
|
|
250
|
+
if (closed || ended)
|
|
251
|
+
throw new Error("the claude session has ended");
|
|
252
|
+
if (run || compactWatch.size)
|
|
253
|
+
throw new Error("claude: wait for the current operation to finish before switching models");
|
|
254
|
+
await q.setModel(model);
|
|
255
|
+
},
|
|
256
|
+
// "/compact" typed into the session: the CLI runs its own compaction on the live conversation.
|
|
257
|
+
// The CLI reports it with a compact_boundary (finished with token counts) and a status message.
|
|
258
|
+
async compact() {
|
|
259
|
+
if (closed || ended)
|
|
260
|
+
throw new Error("the claude session has ended");
|
|
261
|
+
if (run)
|
|
262
|
+
throw new Error("claude: finish the running turn before compacting");
|
|
263
|
+
if (compactWatch.size)
|
|
264
|
+
throw new Error("claude: a compaction is already running");
|
|
265
|
+
const boundary = new Promise((resolve, reject) => {
|
|
266
|
+
const timer = setTimeout(() => { stop(); reject(new Error("compaction timed out")); }, COMPACT_MS);
|
|
267
|
+
function stop() { clearTimeout(timer); compactWatch.delete(watch); }
|
|
268
|
+
const watch = (msg) => {
|
|
269
|
+
if (msg.type === "system" && msg.subtype === "compact_boundary") {
|
|
270
|
+
stop();
|
|
271
|
+
const meta = msg.compact_metadata ?? {};
|
|
272
|
+
return resolve({ before: meta.pre_tokens, after: meta.post_tokens });
|
|
273
|
+
}
|
|
274
|
+
if (msg.type === "system" && msg.subtype === "status" && msg.compact_result === "failed") {
|
|
275
|
+
stop();
|
|
276
|
+
reject(new Error(msg.compact_error || "claude compaction failed"));
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
compactWatch.add(watch);
|
|
280
|
+
});
|
|
281
|
+
boundary.catch(() => { }); // rejected only if the watcher is abandoned
|
|
282
|
+
// A local slash command bypasses the loop, so it carries no run; the answer arrives as local_command_output.
|
|
283
|
+
inputs.push({ type: "user", message: { role: "user", content: "/compact" }, parent_tool_use_id: null });
|
|
284
|
+
return boundary;
|
|
285
|
+
},
|
|
286
|
+
async respond(interruptId, decision) {
|
|
287
|
+
respond(interruptId, decision);
|
|
288
|
+
},
|
|
289
|
+
async setPermissionMode(mode) {
|
|
290
|
+
const { settings, error } = permissionSettings("claude", mode);
|
|
291
|
+
if (error)
|
|
292
|
+
throw new Error(error);
|
|
293
|
+
await q.setPermissionMode(settings.permissionMode);
|
|
294
|
+
ctx.emit({ type: EventType.STATE_DELTA, delta: [{ op: "replace", path: "/permissionMode", value: mode }] });
|
|
295
|
+
},
|
|
296
|
+
async contextUsage() {
|
|
297
|
+
try {
|
|
298
|
+
const usage = await q.getContextUsage();
|
|
299
|
+
return { tokens: usage.totalTokens, window: usage.maxTokens };
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
async close() {
|
|
306
|
+
if (closed)
|
|
307
|
+
return;
|
|
308
|
+
closed = true;
|
|
309
|
+
if (run)
|
|
310
|
+
finishRun({});
|
|
311
|
+
cancelPending("cancelled");
|
|
312
|
+
// An in-flight compact() fails at once instead of waiting for its timeout.
|
|
313
|
+
for (const watch of [...compactWatch])
|
|
314
|
+
watch({ type: "system", subtype: "status", compact_result: "failed", compact_error: "the session closed" });
|
|
315
|
+
inputs.end();
|
|
316
|
+
q.close();
|
|
317
|
+
},
|
|
318
|
+
};
|
|
319
|
+
return { handle, q };
|
|
320
|
+
}
|
|
321
|
+
/** Waits for the CLI handshake within handshakeMs, so a missing, unauthenticated or hung CLI fails at open or resume. */
|
|
322
|
+
async function attach(session, label, handshakeMs) {
|
|
323
|
+
let timer;
|
|
324
|
+
try {
|
|
325
|
+
await Promise.race([
|
|
326
|
+
session.q.initializationResult(),
|
|
327
|
+
new Promise((_, reject) => {
|
|
328
|
+
timer = setTimeout(() => reject(new Error(`no response from the CLI within ${handshakeMs / 1000} s`)), handshakeMs);
|
|
329
|
+
}),
|
|
330
|
+
]);
|
|
331
|
+
}
|
|
332
|
+
catch (error) {
|
|
333
|
+
await session.handle.close();
|
|
334
|
+
throw new Error(`${label} failed to start: ${error.message}`);
|
|
335
|
+
}
|
|
336
|
+
finally {
|
|
337
|
+
clearTimeout(timer);
|
|
338
|
+
}
|
|
339
|
+
return session.handle;
|
|
340
|
+
}
|
|
341
|
+
/** Runs a query with no prompt, reads its initialization result, then closes it. */
|
|
342
|
+
async function probe(query, options, read) {
|
|
343
|
+
const inputs = inputQueue();
|
|
344
|
+
const q = query({ prompt: inputs, options });
|
|
345
|
+
try {
|
|
346
|
+
return read(await q.initializationResult());
|
|
347
|
+
}
|
|
348
|
+
finally {
|
|
349
|
+
inputs.end();
|
|
350
|
+
q.close();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/** A boxed session's MCP servers: the staged temmo pair only, so the repo's .mcp.json (a plugin-root path) never loads there. */
|
|
354
|
+
export function boxedMcpServers(project) {
|
|
355
|
+
const code = codeMcpServer({ project, peer: "claude", host: "claude" });
|
|
356
|
+
return { "temmo": { type: "stdio", ...busMcpServer({ project, peer: "claude", host: "claude" }) }, ...(code ? { "temmo-code": { type: "stdio", ...code } } : {}) };
|
|
357
|
+
}
|
|
358
|
+
/** What every sandboxed Claude session turns off: the builders' lean settings and the tools a sandbox never uses. */
|
|
359
|
+
export function boxedLean() {
|
|
360
|
+
return { settings: CLAUDE_LEAN_SETTINGS, disallowedTools: CLAUDE_SESSION_TOOL_DENY };
|
|
361
|
+
}
|
|
362
|
+
/** The handle with a close that waits for the sandboxed CLI, lands the work and releases the sandbox, and a syncBack for land finish. */
|
|
363
|
+
function boxedHandle(handle, box, stopped, log) {
|
|
364
|
+
let closed = false;
|
|
365
|
+
return {
|
|
366
|
+
...handle,
|
|
367
|
+
send: withSelfNote(handle, `claude#${sessionLabel(handle.nativeId)}`),
|
|
368
|
+
syncBack: (opts) => box.syncBack(log, opts),
|
|
369
|
+
fetchOrigin: (ref) => box.fetchOrigin(ref),
|
|
370
|
+
async close() {
|
|
371
|
+
if (closed)
|
|
372
|
+
return;
|
|
373
|
+
closed = true;
|
|
374
|
+
await handle.close();
|
|
375
|
+
await stopped();
|
|
376
|
+
await box.close(log);
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The Claude adapter with an injected query function (tests pass a fake; the default export uses the SDK).
|
|
382
|
+
* handshakeMs bounds the CLI handshake at open and resume. `sandbox` runs place openshell sessions in the project's
|
|
383
|
+
* Claude sandbox (cli-sandbox.ts); without one the adapter offers no openshell place.
|
|
384
|
+
*/
|
|
385
|
+
export function createClaudeAdapter({ query = sdkQuery, handshakeMs = HANDSHAKE_MS, sandbox = null } = {}) {
|
|
386
|
+
// Stages the sandbox and returns the query options that run the CLI there, with the box and a wait for the CLI's exit.
|
|
387
|
+
async function openBox(project, cwd, vars, ctx, resumeId) {
|
|
388
|
+
if (!sandbox)
|
|
389
|
+
throw new Error("claude has no OpenShell sandbox in this runner");
|
|
390
|
+
const box = await sandbox.open({ project, cwd, home: vars?.HOME, log: ctx.log, ...(resumeId ? { id: resumeId, resume: true } : {}) });
|
|
391
|
+
const { spawner, stopped } = claudeSpawner({ openshell: sandbox.openshell, env: vars ?? process.env, sandbox: box.name, workdir: box.workdir, log: ctx.log });
|
|
392
|
+
// strictMcpConfig: only these servers load, so no plugin or project config with an unset CLAUDE_PLUGIN_ROOT starts.
|
|
393
|
+
const mcp = { mcpServers: boxedMcpServers(project), strictMcpConfig: true };
|
|
394
|
+
return { box, stopped, lean: boxedLean(), launch: { spawnClaudeCodeProcess: spawner, pathToClaudeCodeExecutable: CLAUDE_IN, mcpServersDelivery: "initialize", ...mcp } };
|
|
395
|
+
}
|
|
396
|
+
async function started(session, label, boxed, ctx) {
|
|
397
|
+
if (!boxed)
|
|
398
|
+
return attach(session, label, handshakeMs);
|
|
399
|
+
try {
|
|
400
|
+
return boxedHandle(await attach(session, label, handshakeMs), boxed.box, boxed.stopped, ctx.log);
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
await boxed.stopped();
|
|
404
|
+
await boxed.box.close(ctx.log);
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
harness: "claude",
|
|
410
|
+
capabilities: { steer: true, images: true, resume: "transcript", permissionModes: PERMISSION_MODES, ...(sandbox ? { places: ["folder", "worktree", "openshell"] } : {}) },
|
|
411
|
+
async available(childVars) {
|
|
412
|
+
const path = findExecutable("claude", childEnv(childVars).PATH);
|
|
413
|
+
return path ? { ok: true, detail: path } : { ok: false, detail: "claude is not on PATH" };
|
|
414
|
+
},
|
|
415
|
+
// The session id is chosen here, so the native id is known before the first prompt.
|
|
416
|
+
// options.beforeStart(nativeId) runs before the CLI child starts, so its owned record stands down the child's hooks.
|
|
417
|
+
async open(options, ctx) {
|
|
418
|
+
const nativeId = randomUUID();
|
|
419
|
+
await options.beforeStart?.(nativeId);
|
|
420
|
+
const boxed = options.place === "openshell" ? await openBox(options.project, options.cwd, options.env, ctx, null) : null;
|
|
421
|
+
const session = startSession({
|
|
422
|
+
query, ctx, nativeId, cwd: boxed ? boxed.box.workdir : options.cwd, model: options.model, permission: options.permission, env: options.env, codeMode: options.codeMode, managed: options.managed === true, launch: boxed?.launch, lean: boxed?.lean, allowFullAccess: options.allowFullAccess === true,
|
|
423
|
+
});
|
|
424
|
+
return started(session, "claude session", boxed, ctx);
|
|
425
|
+
},
|
|
426
|
+
async resume(record, ctx, childVars) {
|
|
427
|
+
// A /permission value is the SDK mode for this resume; without one the runner's mode for the record stands.
|
|
428
|
+
const { settings: runnerSettings } = permissionSettings("claude", record.permissionMode, record.place);
|
|
429
|
+
const settings = record.claudePermission ? { permissionMode: record.claudePermission } : runnerSettings;
|
|
430
|
+
// A restored record holds its sandbox claim under its address; the transcript stays in the sandbox's home.
|
|
431
|
+
const boxed = record.place === "openshell" ? await openBox(record.project, record.cwd, childVars, ctx, record.address) : null;
|
|
432
|
+
const session = startSession({
|
|
433
|
+
query, ctx, nativeId: record.nativeId, address: record.address, cwd: boxed ? boxed.box.workdir : record.cwd, model: record.model, permission: settings, env: childVars, resume: true, codeMode: record.codeMode, managed: record.managed === true, launch: boxed?.launch, lean: boxed?.lean, allowFullAccess: record.allowFullAccess === true,
|
|
434
|
+
});
|
|
435
|
+
return started(session, "claude resume", boxed, ctx);
|
|
436
|
+
},
|
|
437
|
+
// A threshold restart's fresh conversation (roadmap stage 3, piece 5): a new native id, so the old transcript is not resumed.
|
|
438
|
+
async restart(record, ctx, childVars) {
|
|
439
|
+
const { settings: runnerSettings } = permissionSettings("claude", record.permissionMode, record.place);
|
|
440
|
+
const settings = record.claudePermission ? { permissionMode: record.claudePermission } : runnerSettings;
|
|
441
|
+
const boxed = record.place === "openshell" ? await openBox(record.project, record.cwd, childVars, ctx, record.address) : null;
|
|
442
|
+
const session = startSession({
|
|
443
|
+
query, ctx, nativeId: randomUUID(), address: record.address, cwd: boxed ? boxed.box.workdir : record.cwd, model: record.model, permission: settings, env: childVars, codeMode: record.codeMode, managed: record.managed === true, launch: boxed?.launch, lean: boxed?.lean, allowFullAccess: record.allowFullAccess === true,
|
|
444
|
+
});
|
|
445
|
+
return started(session, "claude restart", boxed, ctx);
|
|
446
|
+
},
|
|
447
|
+
async listModels(childVars) {
|
|
448
|
+
return probe(query, { env: childEnv(childVars) }, (init) => init.models.map((m) => ({ id: m.value, label: m.displayName })));
|
|
449
|
+
},
|
|
450
|
+
async listCommands(cwd, childVars) {
|
|
451
|
+
return probe(query, { cwd, env: childEnv(childVars) }, (init) => init.commands.map((c) => ({
|
|
452
|
+
name: c.name, ...(c.description ? { description: c.description } : {}), ...(c.argumentHint ? { argumentHint: c.argumentHint } : {}),
|
|
453
|
+
})));
|
|
454
|
+
},
|
|
455
|
+
restore: (record) => sandbox?.restore(record),
|
|
456
|
+
reapplyPolicy: (projects) => sandbox?.reapplyPolicy(projects) ?? Promise.resolve(),
|
|
457
|
+
release: (record) => (sandbox ? sandbox.release(record) : Promise.resolve(true)),
|
|
458
|
+
// Sandboxes outlive the runner, so their sessions resume after a restart.
|
|
459
|
+
async shutdown() { },
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// The env arrives per call from the runner; the runner's env locates openshell and the CLI to upload.
|
|
463
|
+
export default function claudeAdapter({ env = process.env } = {}) {
|
|
464
|
+
return createClaudeAdapter({ sandbox: createClaudeSandbox({ env }) });
|
|
465
|
+
}
|