@temmo/cli 0.0.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +112 -1
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
// pi adapter: one long-lived `pi --mode rpc` process per session (JSONL on stdin and stdout; docs/pi.md).
|
|
2
|
+
// The temmo tools come from pi's built-in MCP; the hooks from the first-party extension lib/pi-extension.mjs, loaded with -e.
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { readFile } from "node:fs/promises";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { EventType } from "@ag-ui/core";
|
|
8
|
+
import { sessionLabel } from "../../lib/config.js";
|
|
9
|
+
import { piModels } from "../../lib/models.js";
|
|
10
|
+
import { findExecutable } from "../../lib/sessions/scope.js";
|
|
11
|
+
import { childEnv } from "../../lib/sessions/launch.js";
|
|
12
|
+
import { APPROVALS_ENV, APPROVAL_TITLE } from "../../lib/pi-extension.mjs";
|
|
13
|
+
import { checkPi } from "../../lib/pi.js";
|
|
14
|
+
import { createPiSandbox, PI_EXTENSION_IN, piSandboxEnv } from "./pi-sandbox.js";
|
|
15
|
+
import { APPROVAL_REQUESTED, APPROVAL_RESOLVED, PERMISSION_TABLE } from "../contract.js";
|
|
16
|
+
const EXTENSION = fileURLToPath(new URL("../../lib/pi-extension.mjs", import.meta.url));
|
|
17
|
+
const READY_MS = 30000;
|
|
18
|
+
const REQUEST_MS = 30000;
|
|
19
|
+
const COMPACT_MS = 600000;
|
|
20
|
+
const KILL_MS = 3000;
|
|
21
|
+
// Dialog methods wait for an answer; the fire-and-forget ones (notify, setStatus, ...) need none (docs/rpc.md).
|
|
22
|
+
const DIALOGS = new Set(["select", "confirm", "input", "editor"]);
|
|
23
|
+
/** The tools a mode asks the operator about (PERMISSION_TABLE.pi), empty for an unknown mode. */
|
|
24
|
+
export const askFor = (mode) => PERMISSION_TABLE.pi[mode]?.ask ?? [];
|
|
25
|
+
const threadOf = (sessionId) => `pi#${sessionLabel(sessionId)}`;
|
|
26
|
+
const textOf = (content) => (Array.isArray(content) ? content.filter((p) => p?.type === "text").map((p) => p.text).join("\n") : typeof content === "string" ? content : JSON.stringify(content ?? ""));
|
|
27
|
+
const lastAssistant = (messages) => [...(Array.isArray(messages) ? messages : [])].reverse().find((m) => m?.role === "assistant");
|
|
28
|
+
/** Calls onLine for each line of a stream split on LF only: pi's JSONL may carry U+2028 inside strings, which readline splits on. */
|
|
29
|
+
export function jsonLines(stream, onLine) {
|
|
30
|
+
let buffer = "";
|
|
31
|
+
stream.setEncoding("utf8");
|
|
32
|
+
stream.on("data", (chunk) => {
|
|
33
|
+
buffer += chunk;
|
|
34
|
+
for (let nl = buffer.indexOf("\n"); nl >= 0; nl = buffer.indexOf("\n")) {
|
|
35
|
+
const line = buffer.slice(0, nl).replace(/\r$/, "");
|
|
36
|
+
buffer = buffer.slice(nl + 1);
|
|
37
|
+
if (line)
|
|
38
|
+
onLine(line);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/** The pi ImageContent blocks for an input's images (base64 of each file). */
|
|
43
|
+
async function imagesOf(input) {
|
|
44
|
+
return Promise.all((input.images ?? []).map(async (image) => ({ type: "image", data: (await readFile(image.path)).toString("base64"), mimeType: image.mime })));
|
|
45
|
+
}
|
|
46
|
+
/** An adapter that starts `bin` (the pi on PATH by default) for each session; `sandbox` runs place openshell sessions in the project's pi sandbox. */
|
|
47
|
+
export function createPiAdapter({ env = process.env, stateDir = "", bin, sandbox = null } = {}) {
|
|
48
|
+
const sessions = new Set();
|
|
49
|
+
const binary = () => bin || findExecutable("pi", childEnv(env).PATH);
|
|
50
|
+
// Stages the project's pi sandbox for one session; a resume passes the record's address, which holds its claim.
|
|
51
|
+
async function openBox(options, ctx) {
|
|
52
|
+
if (options.place !== "openshell")
|
|
53
|
+
return null;
|
|
54
|
+
if (!sandbox)
|
|
55
|
+
throw new Error("pi has no OpenShell sandbox in this runner");
|
|
56
|
+
return sandbox.open({ project: String(options.project), cwd: options.cwd, home: options.env?.HOME, log: ctx.log, ...(options.boxId ? { id: options.boxId, resume: true } : {}) });
|
|
57
|
+
}
|
|
58
|
+
// Starts pi and waits for get_state, which names the session; resumeFrom is a session file or id.
|
|
59
|
+
async function start(options, ctx, ask) {
|
|
60
|
+
const file = binary();
|
|
61
|
+
const problem = await checkPi(file, options.env);
|
|
62
|
+
if (problem)
|
|
63
|
+
throw new Error(problem);
|
|
64
|
+
const tail = [...(options.model ? ["--model", options.model] : []), ...(options.resumeFrom ? ["--session", options.resumeFrom] : [])];
|
|
65
|
+
const box = await openBox(options, ctx);
|
|
66
|
+
// In OpenShell the staged node runs the uploaded pi with the staged extension; the host env stays out of the box.
|
|
67
|
+
const [command, ...args] = box
|
|
68
|
+
? box.argv(["--mode", "rpc", "-e", PI_EXTENSION_IN, ...tail], piSandboxEnv(options.env, { approvals: APPROVALS_ENV, managed: options.managed === true }))
|
|
69
|
+
: [file, "--mode", "rpc", "-e", EXTENSION, ...tail];
|
|
70
|
+
const child = spawn(command, args, {
|
|
71
|
+
cwd: options.cwd, env: box ? (options.env ?? env) : { ...options.env, TEMMO_OWNED: "pi", [APPROVALS_ENV]: "1" }, stdio: ["pipe", "pipe", "pipe"], shell: false,
|
|
72
|
+
});
|
|
73
|
+
const s = { box, child, ctx, ask, allowed: new Set(), sessionId: "", sessionFile: "", threadId: "", run: null, requests: new Map(), approvals: new Map(), messages: 0, exited: false, stderr: "" };
|
|
74
|
+
sessions.add(s);
|
|
75
|
+
child.stderr.setEncoding("utf8");
|
|
76
|
+
child.stderr.on("data", (chunk) => { s.stderr = (s.stderr + chunk).slice(-2000); });
|
|
77
|
+
child.stdin.on("error", () => { });
|
|
78
|
+
jsonLines(child.stdout, (line) => {
|
|
79
|
+
let frame;
|
|
80
|
+
try {
|
|
81
|
+
frame = JSON.parse(line);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return ctx.log(`pi: unparsed line ${line.slice(0, 200)}`);
|
|
85
|
+
}
|
|
86
|
+
dispatch(s, frame);
|
|
87
|
+
});
|
|
88
|
+
child.on("error", (error) => exited(s, error.message));
|
|
89
|
+
child.on("exit", (code, signal) => exited(s, `pi exited (${signal ?? code})`));
|
|
90
|
+
try {
|
|
91
|
+
const state = await request(s, { type: "get_state" }, READY_MS);
|
|
92
|
+
s.sessionId = String(state?.sessionId ?? "");
|
|
93
|
+
s.sessionFile = String(state?.sessionFile ?? "");
|
|
94
|
+
if (!s.sessionId)
|
|
95
|
+
throw new Error("pi named no session");
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
await stop(s);
|
|
99
|
+
await box?.close(ctx.log);
|
|
100
|
+
throw new Error(`${error.message}${s.stderr ? `: ${s.stderr.trim().slice(-500)}` : ""}`);
|
|
101
|
+
}
|
|
102
|
+
s.threadId = threadOf(s.sessionId);
|
|
103
|
+
return handleFor(s);
|
|
104
|
+
}
|
|
105
|
+
function send(s, frame) {
|
|
106
|
+
if (s.exited)
|
|
107
|
+
throw new Error("pi is not running");
|
|
108
|
+
s.child.stdin.write(JSON.stringify(frame) + "\n");
|
|
109
|
+
}
|
|
110
|
+
// Sends a command and resolves its response data; a failed response rejects with pi's error.
|
|
111
|
+
function request(s, command, timeoutMs = REQUEST_MS) {
|
|
112
|
+
const id = randomUUID();
|
|
113
|
+
return new Promise((resolve, reject) => {
|
|
114
|
+
const timer = setTimeout(() => { s.requests.delete(id); reject(new Error(`pi ${command.type} timed out`)); }, timeoutMs);
|
|
115
|
+
s.requests.set(id, { resolve, reject, timer });
|
|
116
|
+
try {
|
|
117
|
+
send(s, { ...command, id });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
clearTimeout(timer);
|
|
121
|
+
s.requests.delete(id);
|
|
122
|
+
reject(error);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function exited(s, reason) {
|
|
127
|
+
if (s.exited)
|
|
128
|
+
return;
|
|
129
|
+
s.exited = true;
|
|
130
|
+
sessions.delete(s);
|
|
131
|
+
for (const { reject, timer } of s.requests.values()) {
|
|
132
|
+
clearTimeout(timer);
|
|
133
|
+
reject(new Error(reason));
|
|
134
|
+
}
|
|
135
|
+
s.requests.clear();
|
|
136
|
+
for (const id of s.approvals.keys())
|
|
137
|
+
s.ctx.emit({ type: EventType.CUSTOM, name: APPROVAL_RESOLVED, value: { interruptId: id, status: "cancelled", reason: "cancelled" } });
|
|
138
|
+
s.approvals.clear();
|
|
139
|
+
endRun(s, (runId) => ({ type: EventType.RUN_ERROR, message: reason, metadata: { aiCollab: { runId } } }));
|
|
140
|
+
}
|
|
141
|
+
function runStarted(s) {
|
|
142
|
+
const run = s.run;
|
|
143
|
+
if (!run || run.started)
|
|
144
|
+
return;
|
|
145
|
+
run.started = true;
|
|
146
|
+
s.ctx.emit({
|
|
147
|
+
type: EventType.RUN_STARTED, threadId: s.threadId, runId: run.runId,
|
|
148
|
+
input: { threadId: s.threadId, runId: run.runId, tools: [], context: [], messages: [{ id: `${run.runId}:input`, role: "user", content: run.text }] },
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function endRun(s, toEvent) {
|
|
152
|
+
const run = s.run;
|
|
153
|
+
if (!run)
|
|
154
|
+
return;
|
|
155
|
+
s.run = null;
|
|
156
|
+
runStarted({ ...s, run });
|
|
157
|
+
s.ctx.emit(toEvent(run.runId));
|
|
158
|
+
}
|
|
159
|
+
// A tool approval the mode asks about becomes a card; any other is allowed at once.
|
|
160
|
+
function approval(s, frame) {
|
|
161
|
+
let asked = {};
|
|
162
|
+
try {
|
|
163
|
+
asked = JSON.parse(String(frame.message ?? ""));
|
|
164
|
+
}
|
|
165
|
+
catch { /* not ours */ }
|
|
166
|
+
const tool = String(asked?.tool ?? "tool");
|
|
167
|
+
if (!s.ask.includes(tool) || s.allowed.has(tool))
|
|
168
|
+
return send(s, { type: "extension_ui_response", id: frame.id, confirmed: true });
|
|
169
|
+
s.approvals.set(frame.id, { tool });
|
|
170
|
+
s.ctx.emit({
|
|
171
|
+
type: EventType.CUSTOM, name: APPROVAL_REQUESTED,
|
|
172
|
+
value: { interruptId: frame.id, reason: "tool_approval", toolCallName: tool, summary: typeof asked?.input === "object" ? JSON.stringify(asked.input) : String(asked?.input ?? "") },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function answer(s, id, confirmed) {
|
|
176
|
+
s.approvals.delete(id);
|
|
177
|
+
send(s, { type: "extension_ui_response", id, confirmed });
|
|
178
|
+
s.ctx.emit({ type: EventType.CUSTOM, name: APPROVAL_RESOLVED, value: { interruptId: id, status: "resolved", reason: confirmed ? "allowed" : "denied" } });
|
|
179
|
+
}
|
|
180
|
+
function dispatch(s, frame) {
|
|
181
|
+
switch (frame?.type) {
|
|
182
|
+
case "response": {
|
|
183
|
+
const pending = s.requests.get(frame.id);
|
|
184
|
+
if (!pending)
|
|
185
|
+
return;
|
|
186
|
+
s.requests.delete(frame.id);
|
|
187
|
+
clearTimeout(pending.timer);
|
|
188
|
+
return frame.success ? pending.resolve(frame.data) : pending.reject(Object.assign(new Error(String(frame.error || `pi ${frame.command} failed`)), { refused: true }));
|
|
189
|
+
}
|
|
190
|
+
case "extension_ui_request":
|
|
191
|
+
if (frame.method === "confirm" && frame.title === APPROVAL_TITLE)
|
|
192
|
+
return approval(s, frame);
|
|
193
|
+
// No operator sits at this dialog: it is dismissed so pi never waits on it.
|
|
194
|
+
if (DIALOGS.has(frame.method))
|
|
195
|
+
send(s, { type: "extension_ui_response", id: frame.id, cancelled: true });
|
|
196
|
+
return;
|
|
197
|
+
case "agent_start": return runStarted(s);
|
|
198
|
+
case "message_start":
|
|
199
|
+
if (frame.message?.role === "assistant")
|
|
200
|
+
s.messages++;
|
|
201
|
+
return;
|
|
202
|
+
case "message_update": {
|
|
203
|
+
const delta = frame.assistantMessageEvent;
|
|
204
|
+
if (s.run && delta?.type === "text_delta" && delta.delta) {
|
|
205
|
+
runStarted(s);
|
|
206
|
+
s.ctx.emit({ type: EventType.TEXT_MESSAGE_CHUNK, messageId: `${s.run.runId}:${s.messages}`, role: "assistant", delta: String(delta.delta) });
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
case "tool_execution_start":
|
|
211
|
+
if (!s.run)
|
|
212
|
+
return;
|
|
213
|
+
runStarted(s);
|
|
214
|
+
return s.ctx.emit({ type: EventType.TOOL_CALL_CHUNK, toolCallId: String(frame.toolCallId), toolCallName: String(frame.toolName ?? "tool"), delta: JSON.stringify(frame.args ?? {}) });
|
|
215
|
+
case "tool_execution_end":
|
|
216
|
+
if (!s.run)
|
|
217
|
+
return;
|
|
218
|
+
return s.ctx.emit({
|
|
219
|
+
type: EventType.TOOL_CALL_RESULT, toolCallId: String(frame.toolCallId), messageId: `${frame.toolCallId}:result`, role: "tool",
|
|
220
|
+
content: textOf(frame.result?.content), metadata: { aiCollab: { toolCallName: String(frame.toolName ?? "tool"), failed: Boolean(frame.isError) } },
|
|
221
|
+
});
|
|
222
|
+
case "agent_end": {
|
|
223
|
+
// pi retries a transient failure, or recovers an overflow, after this agent_end: the run goes on.
|
|
224
|
+
if (frame.willRetry)
|
|
225
|
+
return;
|
|
226
|
+
const last = lastAssistant(frame.messages);
|
|
227
|
+
if (s.run?.cancelled || last?.stopReason === "aborted")
|
|
228
|
+
return endRun(s, (runId) => ({ type: EventType.RUN_FINISHED, threadId: s.threadId, runId, outcome: { type: "cancelled" } }));
|
|
229
|
+
if (last?.stopReason === "error")
|
|
230
|
+
return endRun(s, (runId) => ({ type: EventType.RUN_ERROR, message: String(last.errorMessage || "pi run failed"), metadata: { aiCollab: { runId } } }));
|
|
231
|
+
return endRun(s, (runId) => ({ type: EventType.RUN_FINISHED, threadId: s.threadId, runId, outcome: { type: "success" } }));
|
|
232
|
+
}
|
|
233
|
+
case "compaction_start":
|
|
234
|
+
return s.ctx.emit({ type: EventType.STEP_STARTED, stepName: "compact", metadata: { aiCollab: { compaction: { trigger: frame.reason, phase: "started" } } } });
|
|
235
|
+
case "compaction_end":
|
|
236
|
+
return s.ctx.emit({ type: EventType.STEP_FINISHED, stepName: "compact", metadata: { aiCollab: { compaction: { phase: frame.aborted || frame.errorMessage ? "failed" : "finished" } } } });
|
|
237
|
+
case "extension_error":
|
|
238
|
+
return s.ctx.log(`pi extension error: ${frame.error ?? JSON.stringify(frame)}`);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async function stop(s) {
|
|
242
|
+
if (s.exited)
|
|
243
|
+
return;
|
|
244
|
+
const gone = new Promise((resolve) => s.child.once("exit", () => resolve()));
|
|
245
|
+
s.child.stdin.end();
|
|
246
|
+
s.child.kill("SIGTERM");
|
|
247
|
+
const timer = setTimeout(() => s.child.kill("SIGKILL"), KILL_MS);
|
|
248
|
+
await gone;
|
|
249
|
+
clearTimeout(timer);
|
|
250
|
+
}
|
|
251
|
+
function handleFor(s) {
|
|
252
|
+
return {
|
|
253
|
+
nativeId: s.sessionId,
|
|
254
|
+
async send(input) {
|
|
255
|
+
if (s.run)
|
|
256
|
+
throw new Error("a run is already running");
|
|
257
|
+
const run = { runId: randomUUID(), text: input.text, started: false, cancelled: false };
|
|
258
|
+
s.run = run;
|
|
259
|
+
try {
|
|
260
|
+
const images = await imagesOf(input);
|
|
261
|
+
const answer = await request(s, { type: "prompt", message: input.text, ...(images.length ? { images } : {}) });
|
|
262
|
+
// A prompt pi handled itself (a command) starts no run, so no agent_end will end it.
|
|
263
|
+
if (answer?.disposition === "handled" && s.run === run)
|
|
264
|
+
endRun(s, (runId) => ({ type: EventType.RUN_FINISHED, threadId: s.threadId, runId, outcome: { type: "success" } }));
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
if (s.run === run)
|
|
268
|
+
s.run = null;
|
|
269
|
+
// pi refused the prompt and ran nothing, or the request timed out after pi may have taken it.
|
|
270
|
+
if (error.refused)
|
|
271
|
+
error.retryable = true;
|
|
272
|
+
else
|
|
273
|
+
error.mayHaveStarted = true;
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
if (s.run === run)
|
|
277
|
+
runStarted(s);
|
|
278
|
+
return { runId: run.runId };
|
|
279
|
+
},
|
|
280
|
+
async steer(input) {
|
|
281
|
+
const images = await imagesOf(input);
|
|
282
|
+
await request(s, { type: "steer", message: input.text, ...(images.length ? { images } : {}) });
|
|
283
|
+
},
|
|
284
|
+
async interrupt() {
|
|
285
|
+
const run = s.run;
|
|
286
|
+
if (!run)
|
|
287
|
+
return;
|
|
288
|
+
run.cancelled = true;
|
|
289
|
+
await request(s, { type: "abort" });
|
|
290
|
+
if (s.run === run)
|
|
291
|
+
endRun(s, (runId) => ({ type: EventType.RUN_FINISHED, threadId: s.threadId, runId, outcome: { type: "cancelled" } }));
|
|
292
|
+
},
|
|
293
|
+
async compact() {
|
|
294
|
+
if (s.run)
|
|
295
|
+
throw new Error("pi: finish the running turn before compacting");
|
|
296
|
+
const data = await request(s, { type: "compact" }, COMPACT_MS);
|
|
297
|
+
return Number.isSafeInteger(data?.tokensBefore) ? { before: data.tokensBefore } : {};
|
|
298
|
+
},
|
|
299
|
+
async respond(interruptId, decision) {
|
|
300
|
+
const entry = s.approvals.get(interruptId);
|
|
301
|
+
if (!entry)
|
|
302
|
+
throw new Error("no open pi approval with that id");
|
|
303
|
+
if (decision.answers)
|
|
304
|
+
throw new Error("pi approvals take allow or deny, not answers");
|
|
305
|
+
if (decision.behavior === "allow" && decision.scope === "session")
|
|
306
|
+
s.allowed.add(entry.tool);
|
|
307
|
+
answer(s, interruptId, decision.behavior === "allow");
|
|
308
|
+
},
|
|
309
|
+
async contextUsage() {
|
|
310
|
+
const usage = (await request(s, { type: "get_session_stats" }))?.contextUsage;
|
|
311
|
+
return Number.isSafeInteger(usage?.tokens) ? { tokens: usage.tokens, ...(Number.isSafeInteger(usage.contextWindow) ? { window: usage.contextWindow } : {}) } : null;
|
|
312
|
+
},
|
|
313
|
+
async setModel(model) {
|
|
314
|
+
const at = model.indexOf("/");
|
|
315
|
+
if (at <= 0 || at === model.length - 1)
|
|
316
|
+
throw new Error("pi models are provider/model");
|
|
317
|
+
await request(s, { type: "set_model", provider: model.slice(0, at), modelId: model.slice(at + 1) });
|
|
318
|
+
},
|
|
319
|
+
async setPermissionMode(mode) {
|
|
320
|
+
if (!PERMISSION_TABLE.pi[mode])
|
|
321
|
+
throw new Error(`pi has no permission mode ${mode}`);
|
|
322
|
+
s.ask = askFor(mode);
|
|
323
|
+
for (const [id, entry] of [...s.approvals])
|
|
324
|
+
if (!s.ask.includes(entry.tool))
|
|
325
|
+
answer(s, id, true);
|
|
326
|
+
},
|
|
327
|
+
resumeData: () => (s.sessionFile ? { sessionFile: s.sessionFile } : {}),
|
|
328
|
+
// A boxed session lands its work on the host worktree and releases the sandbox once pi has exited.
|
|
329
|
+
...(s.box ? { syncBack: (opts) => s.box.syncBack(s.ctx.log, opts), fetchOrigin: (ref) => s.box.fetchOrigin(ref) } : {}),
|
|
330
|
+
close: async () => { await stop(s); await s.box?.close(s.ctx.log); },
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
return {
|
|
334
|
+
harness: "pi",
|
|
335
|
+
capabilities: { steer: true, images: true, resume: "transcript", permissionModes: Object.keys(PERMISSION_TABLE.pi), places: sandbox ? ["folder", "worktree", "openshell"] : ["folder", "worktree"], openshellTeams: false },
|
|
336
|
+
async available() {
|
|
337
|
+
const problem = await checkPi(binary(), env);
|
|
338
|
+
return problem ? { ok: false, detail: problem } : { ok: true };
|
|
339
|
+
},
|
|
340
|
+
open(options, ctx) {
|
|
341
|
+
return start({ cwd: options.cwd, model: options.model, env: options.env, place: options.place, project: options.project, managed: options.managed }, ctx, options.permission?.ask ?? askFor(options.permissionMode));
|
|
342
|
+
},
|
|
343
|
+
resume(record, ctx, childEnvVars) {
|
|
344
|
+
const resumeFrom = typeof record.resume?.sessionFile === "string" && record.resume.sessionFile ? record.resume.sessionFile : record.nativeId;
|
|
345
|
+
return start({ cwd: record.cwd, model: record.model, env: childEnvVars, resumeFrom, place: record.place, project: record.project, managed: record.managed, boxId: record.address }, ctx, askFor(record.permissionMode));
|
|
346
|
+
},
|
|
347
|
+
async listModels(listEnv) {
|
|
348
|
+
return (await piModels(stateDir, listEnv ?? env)).map((id) => ({ id }));
|
|
349
|
+
},
|
|
350
|
+
async listCommands() {
|
|
351
|
+
return [];
|
|
352
|
+
},
|
|
353
|
+
restore: (record) => sandbox?.restore(record),
|
|
354
|
+
reapplyPolicy: (projects) => sandbox?.reapplyPolicy(projects) ?? Promise.resolve(),
|
|
355
|
+
release: (record) => (sandbox ? sandbox.release(record) : Promise.resolve(true)),
|
|
356
|
+
// Sandboxes outlive the runner, so boxed sessions resume after a restart.
|
|
357
|
+
async shutdown() {
|
|
358
|
+
await Promise.allSettled([...sessions].map((s) => stop(s)));
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
export default function piAdapter({ env = process.env, stateDir = "" } = {}) {
|
|
363
|
+
return createPiAdapter({ env, stateDir, sandbox: createPiSandbox({ env }) });
|
|
364
|
+
}
|
package/runner/client.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Client for the runner control socket, for the UI server and the CLI.
|
|
2
|
+
import { runnerRequest } from "../lib/runner-request.js";
|
|
3
|
+
export { CLIENT_TIMEOUT_MS, runnerRequest } from "../lib/runner-request.js";
|
|
4
|
+
const sessionPath = (address) => {
|
|
5
|
+
const [harness, label] = String(address).split("#");
|
|
6
|
+
return `/v1/sessions/${encodeURIComponent(harness)}/${encodeURIComponent(label || "")}`;
|
|
7
|
+
};
|
|
8
|
+
/** Thin wrappers that name each control route. */
|
|
9
|
+
export const runnerClient = (options = {}) => ({
|
|
10
|
+
startPattern: (input) => runnerRequest("POST", "/v1/pattern-runs", input, options),
|
|
11
|
+
advancePattern: (input) => runnerRequest("POST", "/v1/pattern-runs/advance", input, options),
|
|
12
|
+
health: () => runnerRequest("GET", "/v1/health", undefined, options),
|
|
13
|
+
harnesses: () => runnerRequest("GET", "/v1/harnesses", undefined, options),
|
|
14
|
+
models: (harness) => runnerRequest("GET", `/v1/harnesses/${encodeURIComponent(harness)}/models`, undefined, options),
|
|
15
|
+
commands: (harness, project) => runnerRequest("GET", `/v1/harnesses/${encodeURIComponent(harness)}/commands?project=${encodeURIComponent(project)}`, undefined, options),
|
|
16
|
+
sessions: () => runnerRequest("GET", "/v1/sessions", undefined, options),
|
|
17
|
+
deliveries: () => runnerRequest("GET", "/v1/deliveries", undefined, options),
|
|
18
|
+
schedules: () => runnerRequest("GET", "/v1/schedules", undefined, options),
|
|
19
|
+
runSchedule: (name, caller = "client") => runnerRequest("POST", `/v1/schedules/${encodeURIComponent(name)}/run?caller=${encodeURIComponent(caller)}`, {}, options),
|
|
20
|
+
continueBuilder: (input) => runnerRequest("POST", "/v1/builder-continuations", input, options),
|
|
21
|
+
start: (input) => runnerRequest("POST", "/v1/sessions", input, options),
|
|
22
|
+
get: (address) => runnerRequest("GET", sessionPath(address), undefined, options),
|
|
23
|
+
send: (address, text, { steer = false } = {}) => runnerRequest("POST", `${sessionPath(address)}/send`, { text, steer }, options),
|
|
24
|
+
interrupt: (address) => runnerRequest("POST", `${sessionPath(address)}/interrupt`, {}, options),
|
|
25
|
+
compact: (address) => runnerRequest("POST", `${sessionPath(address)}/compact`, {}, options),
|
|
26
|
+
setModel: (address, model) => runnerRequest("POST", `${sessionPath(address)}/model`, { model }, options),
|
|
27
|
+
setMode: (address, mode) => runnerRequest("POST", `${sessionPath(address)}/mode`, { mode }, options),
|
|
28
|
+
approve: (address, id, decision) => runnerRequest("POST", `${sessionPath(address)}/approvals/${encodeURIComponent(id)}`, decision, options),
|
|
29
|
+
context: (address) => runnerRequest("GET", `${sessionPath(address)}/context`, undefined, options),
|
|
30
|
+
close: (address) => runnerRequest("DELETE", sessionPath(address), undefined, options),
|
|
31
|
+
});
|
|
32
|
+
/** True when the runner answers its control socket; the UI dispatcher stands down while it does. */
|
|
33
|
+
export async function runnerUp(options = {}) {
|
|
34
|
+
try {
|
|
35
|
+
return (await runnerClient({ timeoutMs: 1000, ...options }).health()).status === 200;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// Constants and validators of the owned-session contract (docs/owned-sessions-contract.md, runner/types.d.ts).
|
|
2
|
+
import { EventType } from "@ag-ui/core";
|
|
3
|
+
import { EventSchema } from "@ag-ui/core/schemas";
|
|
4
|
+
export const HARNESSES = ["claude", "codex", "cursor", "opencode", "pi"];
|
|
5
|
+
export const PERMISSION_MODES = ["supervised", "accept-edits", "auto", "full-access"];
|
|
6
|
+
export const PLACES = ["folder", "worktree", "openshell"];
|
|
7
|
+
export const EVENT_TYPES = [
|
|
8
|
+
EventType.RUN_STARTED, EventType.TEXT_MESSAGE_CONTENT, EventType.TEXT_MESSAGE_CHUNK, EventType.TOOL_CALL_CHUNK,
|
|
9
|
+
EventType.TOOL_CALL_RESULT, EventType.STEP_STARTED, EventType.STEP_FINISHED, EventType.STATE_DELTA,
|
|
10
|
+
EventType.CUSTOM, EventType.RUN_FINISHED, EventType.RUN_ERROR,
|
|
11
|
+
];
|
|
12
|
+
export const APPROVAL_REQUESTED = "ai-collab.approval-requested";
|
|
13
|
+
export const APPROVAL_RESOLVED = "ai-collab.approval-resolved";
|
|
14
|
+
export const NOTICE = "ai-collab.notice";
|
|
15
|
+
export const ERROR = "ai-collab.error";
|
|
16
|
+
// A harness limit: value is a lib/limits.ts classification. The runner alerts once per session and window.
|
|
17
|
+
export const LIMIT = "ai-collab.limit";
|
|
18
|
+
export const RESOLVE_REASONS = ["allowed", "denied", "answered", "cancelled"];
|
|
19
|
+
export const STATE_PATHS = ["/contextTokens", "/contextWindow", "/model", "/permissionMode"];
|
|
20
|
+
// Codex values follow T3 Code (MIT, Copyright (c) 2026 T3 Tools Inc.), CodexAdapterV2.ts L751-L800 at 5935157.
|
|
21
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime harness or mode name
|
|
22
|
+
export const PERMISSION_TABLE = {
|
|
23
|
+
claude: {
|
|
24
|
+
supervised: { permissionMode: "default" },
|
|
25
|
+
"accept-edits": { permissionMode: "acceptEdits" },
|
|
26
|
+
auto: { permissionMode: "auto" },
|
|
27
|
+
"full-access": { permissionMode: "bypassPermissions" },
|
|
28
|
+
},
|
|
29
|
+
codex: {
|
|
30
|
+
supervised: { approvalPolicy: "untrusted", approvalsReviewer: "user", sandboxPolicy: { type: "readOnly" } },
|
|
31
|
+
"accept-edits": { approvalPolicy: "on-request", approvalsReviewer: "user", sandboxPolicy: { type: "workspaceWrite" } },
|
|
32
|
+
auto: { approvalPolicy: "on-request", approvalsReviewer: "auto_review", sandboxPolicy: { type: "workspaceWrite" } },
|
|
33
|
+
"full-access": {
|
|
34
|
+
approvalPolicy: { granular: { mcp_elicitations: true, request_permissions: false, rules: false, sandbox_approval: false, skill_approval: false } },
|
|
35
|
+
approvalsReviewer: "user", sandboxPolicy: { type: "dangerFullAccess" },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
opencode: {
|
|
39
|
+
supervised: { autoReply: [], reply: "once" },
|
|
40
|
+
"accept-edits": { autoReply: ["edit"], reply: "once" },
|
|
41
|
+
"full-access": { autoReply: ["*"], reply: "once" },
|
|
42
|
+
},
|
|
43
|
+
// pi has no approvals of its own; the temmo extension asks before these tools and the adapter answers the rest.
|
|
44
|
+
pi: {
|
|
45
|
+
supervised: { ask: ["bash", "edit", "write"] },
|
|
46
|
+
"accept-edits": { ask: ["bash"] },
|
|
47
|
+
"full-access": { ask: [] },
|
|
48
|
+
},
|
|
49
|
+
cursor: {
|
|
50
|
+
supervised: { force: false },
|
|
51
|
+
"full-access": { force: true, requiresPlace: "openshell" },
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime harness or mode name
|
|
55
|
+
export const DEFAULT_PERMISSION = { claude: "auto", codex: "auto", cursor: "supervised", opencode: "supervised", pi: "supervised" };
|
|
56
|
+
export const OPENSHELL_PERMISSION = "full-access";
|
|
57
|
+
// The runner mode each Claude --permission-mode value names; dontAsk and plan have no runner mode.
|
|
58
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime harness or mode name
|
|
59
|
+
export const CLAUDE_CLI_MODES = { default: "supervised", acceptEdits: "accept-edits", auto: "auto", bypassPermissions: "full-access" };
|
|
60
|
+
export const APPROVAL_TIMEOUT_MIN = 30;
|
|
61
|
+
const APPROVAL_TIMEOUT_MAX_MIN = 12 * 60;
|
|
62
|
+
/** The mode a session starts in when the caller names none: full-access in OpenShell, else the harness default. */
|
|
63
|
+
export const defaultPermission = (harness, place = "folder") => (place === "openshell" ? OPENSHELL_PERMISSION : DEFAULT_PERMISSION[harness]);
|
|
64
|
+
/** The runner mode for a Claude --permission-mode value, or null when the runner has none for it. */
|
|
65
|
+
export const runnerModeOfClaude = (flag) => (Object.hasOwn(CLAUDE_CLI_MODES, flag) ? CLAUDE_CLI_MODES[flag] : null);
|
|
66
|
+
/** Milliseconds an owned approval waits before the runner denies it: TEMMO_APPROVAL_TIMEOUT_MIN (default 30, at most 12 h, the cache window of an operator-run ntfy server). */
|
|
67
|
+
export function approvalTimeoutMs(env = process.env) {
|
|
68
|
+
const minutes = Number(env.TEMMO_APPROVAL_TIMEOUT_MIN);
|
|
69
|
+
return (Number.isFinite(minutes) && minutes > 0 ? Math.min(minutes, APPROVAL_TIMEOUT_MAX_MIN) : APPROVAL_TIMEOUT_MIN) * 60_000;
|
|
70
|
+
}
|
|
71
|
+
/** The settings a harness gets for a mode, or an error string when the pair is not allowed. */
|
|
72
|
+
export function permissionSettings(harness, mode, place = "folder") {
|
|
73
|
+
const settings = PERMISSION_TABLE[harness]?.[mode];
|
|
74
|
+
if (!settings)
|
|
75
|
+
return { error: `${harness} has no permission mode ${mode}` };
|
|
76
|
+
if (settings.requiresPlace && settings.requiresPlace !== place)
|
|
77
|
+
return { error: `${harness} ${mode} runs only in ${settings.requiresPlace}` };
|
|
78
|
+
return { settings };
|
|
79
|
+
}
|
|
80
|
+
const isText = (value) => typeof value === "string" && value.length > 0;
|
|
81
|
+
/** Null for a supported AG-UI event with the fields the runner uses. */
|
|
82
|
+
export function eventProblem(e) {
|
|
83
|
+
if (!e || typeof e !== "object" || !EVENT_TYPES.includes(e.type))
|
|
84
|
+
return "unknown event type";
|
|
85
|
+
if (!EventSchema.safeParse(e).success)
|
|
86
|
+
return "invalid AG-UI event";
|
|
87
|
+
if (e.subagentRunId !== undefined && !isText(e.subagentRunId))
|
|
88
|
+
return "bad subagent run ID";
|
|
89
|
+
const meta = e.metadata?.aiCollab;
|
|
90
|
+
switch (e.type) {
|
|
91
|
+
case EventType.RUN_STARTED:
|
|
92
|
+
return isText(e.threadId) && isText(e.runId) ? null : "threadId and runId required";
|
|
93
|
+
case EventType.RUN_FINISHED:
|
|
94
|
+
return isText(e.threadId) && isText(e.runId) && [undefined, "success", "cancelled"].includes(e.outcome?.type)
|
|
95
|
+
? null : "invalid run finish";
|
|
96
|
+
case EventType.RUN_ERROR:
|
|
97
|
+
return isText(meta?.runId) && isText(e.message) ? null : "runId and message required";
|
|
98
|
+
case EventType.TEXT_MESSAGE_CONTENT:
|
|
99
|
+
case EventType.TEXT_MESSAGE_CHUNK:
|
|
100
|
+
return isText(e.messageId) && typeof e.delta === "string" ? null : "messageId and delta required";
|
|
101
|
+
case EventType.TOOL_CALL_CHUNK:
|
|
102
|
+
return isText(e.toolCallId) && isText(e.toolCallName) ? null : "toolCallId and toolCallName required";
|
|
103
|
+
case EventType.TOOL_CALL_RESULT:
|
|
104
|
+
return isText(e.toolCallId) && isText(e.messageId) ? null : "toolCallId and messageId required";
|
|
105
|
+
case EventType.STEP_STARTED:
|
|
106
|
+
case EventType.STEP_FINISHED:
|
|
107
|
+
return isText(e.stepName) ? null : "stepName required";
|
|
108
|
+
case EventType.STATE_DELTA:
|
|
109
|
+
return e.delta.length && e.delta.every((op) => ["add", "replace", "remove"].includes(op.op) && STATE_PATHS.includes(op.path))
|
|
110
|
+
? null : "delta must patch known paths";
|
|
111
|
+
case EventType.CUSTOM:
|
|
112
|
+
return customProblem(e);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function customProblem({ name, value }) {
|
|
116
|
+
if (name === NOTICE || name === ERROR)
|
|
117
|
+
return isText(value) ? null : "event text required";
|
|
118
|
+
if (name === LIMIT)
|
|
119
|
+
return isText(value?.harness) ? null : "invalid limit";
|
|
120
|
+
if (name === APPROVAL_REQUESTED) {
|
|
121
|
+
return isText(value?.interruptId) && ["tool_approval", "question"].includes(value.reason) &&
|
|
122
|
+
isText(value.toolCallName) && typeof value.summary === "string" ? null : "invalid approval request";
|
|
123
|
+
}
|
|
124
|
+
if (name === APPROVAL_RESOLVED) {
|
|
125
|
+
return isText(value?.interruptId) && ["resolved", "cancelled"].includes(value.status) && RESOLVE_REASONS.includes(value.reason)
|
|
126
|
+
? null : "invalid approval resolution";
|
|
127
|
+
}
|
|
128
|
+
return "unknown custom event";
|
|
129
|
+
}
|