@temmo/cli 0.0.0-stage → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +110 -4
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// The registered session a scheduled command resumes, so a run can link to that session's timeline.
|
|
2
|
+
import { basename, isAbsolute, relative as relativePath, sep } from "node:path";
|
|
3
|
+
import { sessionLabel } from "./config.js";
|
|
4
|
+
import { harnessOfBinary } from "./harness.js";
|
|
5
|
+
// The flag that names the session to resume, per harness; Codex takes it as `codex exec resume <id>`.
|
|
6
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime harness name
|
|
7
|
+
const RESUME_FLAGS = { cursor: ["--resume", "-r"], claude: ["--resume", "-r"], opencode: ["--session", "-s"] };
|
|
8
|
+
// A harness session id: a UUID or a thread name; never a path or another flag.
|
|
9
|
+
const SESSION_ID = /^[A-Za-z0-9][\w.:@-]{0,255}$/;
|
|
10
|
+
// The value of the first of names the args carry, as `--flag value` or `--flag=value`.
|
|
11
|
+
function valueAfter(args, names) {
|
|
12
|
+
for (let i = 0; i < args.length; i++) {
|
|
13
|
+
const arg = args[i];
|
|
14
|
+
if (typeof arg !== "string")
|
|
15
|
+
continue;
|
|
16
|
+
const joined = names.find((name) => arg.startsWith(name + "="));
|
|
17
|
+
if (joined)
|
|
18
|
+
return arg.slice(joined.length + 1);
|
|
19
|
+
if (names.includes(arg)) {
|
|
20
|
+
const next = args[i + 1];
|
|
21
|
+
if (typeof next === "string" && !next.startsWith("-"))
|
|
22
|
+
return next;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The registered project whose folder holds a path (the deepest match), or "" when none does. A schedule's cwd names
|
|
29
|
+
* the project its session publishes under, so its runs link to that project's timeline.
|
|
30
|
+
*/
|
|
31
|
+
export function projectOfFolder(folder, projects = []) {
|
|
32
|
+
if (typeof folder !== "string" || !folder)
|
|
33
|
+
return "";
|
|
34
|
+
let best = "";
|
|
35
|
+
let bestRoot = "";
|
|
36
|
+
for (const entry of projects) {
|
|
37
|
+
if (typeof entry?.root !== "string" || typeof entry.project !== "string")
|
|
38
|
+
continue;
|
|
39
|
+
const relative = relativePath(entry.root, folder);
|
|
40
|
+
if (relative === ".." || relative.startsWith(".." + sep) || isAbsolute(relative))
|
|
41
|
+
continue;
|
|
42
|
+
if (entry.root.length > bestRoot.length || !best) {
|
|
43
|
+
best = entry.project;
|
|
44
|
+
bestRoot = entry.root;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return best;
|
|
48
|
+
}
|
|
49
|
+
/** The harness a command runs (by its binary's name), or "" for a plain script or a wrapper like `npx`. */
|
|
50
|
+
export function harnessOfCommand(command) {
|
|
51
|
+
return Array.isArray(command) && typeof command[0] === "string" ? harnessOfBinary(basename(command[0])) || "" : "";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The session a scheduled command resumes, as {harness, session}, or null when the command names none (a plain
|
|
55
|
+
* script, a harness with no resume flag, a wrapper binary). The label is the same hash the session's hooks publish.
|
|
56
|
+
*/
|
|
57
|
+
export function sessionOfCommand(command) {
|
|
58
|
+
if (!Array.isArray(command) || !command.length || typeof command[0] !== "string")
|
|
59
|
+
return null;
|
|
60
|
+
const harness = harnessOfCommand(command);
|
|
61
|
+
if (!harness)
|
|
62
|
+
return null;
|
|
63
|
+
const arg = harness === "codex" ? valueAfter(command.slice(1), ["resume"]) : valueAfter(command.slice(1), RESUME_FLAGS[harness]);
|
|
64
|
+
if (!SESSION_ID.test(arg || ""))
|
|
65
|
+
return null;
|
|
66
|
+
const session = sessionLabel(arg);
|
|
67
|
+
return session ? { harness, session } : null;
|
|
68
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// `temmo activity <peer#session>`: one session's recent steps (prompt, text, tool calls and results) from the
|
|
2
|
+
// project's activity topic, so an operator or a parent agent can watch a run without the phone.
|
|
3
|
+
import { parseWireEnvelope } from "./agui.js";
|
|
4
|
+
import { activityTopic } from "./config.js";
|
|
5
|
+
import { pollCached } from "./messaging.js";
|
|
6
|
+
export const ACTIVITY_DEFAULT = 20;
|
|
7
|
+
export const ACTIVITY_MAX = 200;
|
|
8
|
+
const LINE_MAX = 240;
|
|
9
|
+
/** Activity of one session (`peer#label`) since a bus cursor, oldest first, with streamed chunks of one call merged. */
|
|
10
|
+
export async function sessionActivity(cfg, address, { since = "1h", signal } = {}) {
|
|
11
|
+
const [from, session] = address.split("#");
|
|
12
|
+
const lines = [];
|
|
13
|
+
for (const event of await pollCached(cfg, activityTopic(cfg.project), since, signal)) {
|
|
14
|
+
let record;
|
|
15
|
+
try {
|
|
16
|
+
record = parseWireEnvelope(event.message);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (record?.kind !== "activity" || record.from !== from || record.session !== session)
|
|
22
|
+
continue;
|
|
23
|
+
const text = record.type === "tool_call" ? String(record.input ?? "") : contentText(record.output ?? record.input ?? "");
|
|
24
|
+
const last = lines.at(-1);
|
|
25
|
+
// A text or tool call streams as chunks under one id; they read as one step.
|
|
26
|
+
if (last && record.callId && last.callId === record.callId && last.type === record.type && (record.type === "text" || record.type === "tool_call")) {
|
|
27
|
+
last.text += text;
|
|
28
|
+
last.id = event.id;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
lines.push({ id: event.id, ts: String(record.ts ?? new Date(event.time * 1000).toISOString()), type: record.type, ...(record.tool ? { tool: record.tool } : {}), text, ...(record.callId ? { callId: record.callId } : {}) });
|
|
32
|
+
}
|
|
33
|
+
return lines;
|
|
34
|
+
}
|
|
35
|
+
const TEXT_PART = '[{"type":"text","text":"';
|
|
36
|
+
const CLIPPED = /…\[truncated \d+ bytes\]$/;
|
|
37
|
+
// MCP-style results arrive as [{"type":"text","text":...}]; the texts are what a reader wants. The publisher clips
|
|
38
|
+
// long results mid-JSON (ending in CLIPPED), so a clipped first text part is decoded up to the cut.
|
|
39
|
+
function contentText(value) {
|
|
40
|
+
const text = String(value);
|
|
41
|
+
if (!text.startsWith("["))
|
|
42
|
+
return text;
|
|
43
|
+
try {
|
|
44
|
+
const parts = JSON.parse(text);
|
|
45
|
+
if (Array.isArray(parts) && parts.every((p) => p?.type === "text" && typeof p.text === "string"))
|
|
46
|
+
return parts.map((p) => p.text).join("\n");
|
|
47
|
+
}
|
|
48
|
+
catch { /* clipped or not JSON */ }
|
|
49
|
+
const clipped = CLIPPED.exec(text);
|
|
50
|
+
if (!clipped || !text.startsWith(TEXT_PART))
|
|
51
|
+
return text;
|
|
52
|
+
const body = text.slice(TEXT_PART.length, clipped.index);
|
|
53
|
+
for (const cut of [body, body.replace(/\\(u[0-9a-fA-F]{0,3})?$/, "")]) {
|
|
54
|
+
try {
|
|
55
|
+
return `${JSON.parse(`"${cut}"`)}${clipped[0]}`;
|
|
56
|
+
}
|
|
57
|
+
catch { /* a cut escape or a second part: try the next form */ }
|
|
58
|
+
}
|
|
59
|
+
return text;
|
|
60
|
+
}
|
|
61
|
+
/** One line per step: time, kind, tool, and the text on one line, clipped. */
|
|
62
|
+
export function formatActivity(line) {
|
|
63
|
+
const time = line.ts.slice(11, 19);
|
|
64
|
+
const body = line.text.replace(/\s+/g, " ").trim();
|
|
65
|
+
const clipped = body.length > LINE_MAX ? `${body.slice(0, LINE_MAX - 1)}…` : body;
|
|
66
|
+
return [time, line.type.padEnd(11), line.tool ?? "", clipped].filter(Boolean).join(" ");
|
|
67
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Clear and model switch in one model, beside compaction (lib/compaction.ts); both ride the activity row's own field. */
|
|
2
|
+
import { COMPACTION_HISTORY_MAX, compactionFields } from "./compaction.js";
|
|
3
|
+
const count = (value) => (Number.isSafeInteger(value) && value >= 0 ? value : undefined);
|
|
4
|
+
const MODEL_MAX = 128;
|
|
5
|
+
const model = (value) => (typeof value === "string" && value.trim() && value.length <= MODEL_MAX ? value.trim() : undefined);
|
|
6
|
+
/** {tokensBefore?, tokensAfter: 0}: a clear empties the context, so the after count is 0 by definition. */
|
|
7
|
+
export function clearFields({ tokensBefore } = {}) {
|
|
8
|
+
const before = count(tokensBefore);
|
|
9
|
+
return { ...(before === undefined ? {} : { tokensBefore: before }), tokensAfter: 0 };
|
|
10
|
+
}
|
|
11
|
+
/** {from, to} model names, or null when either is missing. */
|
|
12
|
+
export function modelFields({ from, to } = {}) {
|
|
13
|
+
const [a, b] = [model(from), model(to)];
|
|
14
|
+
return a && b ? { from: a, to: b } : null;
|
|
15
|
+
}
|
|
16
|
+
// The run a row belongs to: its agent, and its subagent run when it has one.
|
|
17
|
+
const runOf = (row) => `${row.agent || ""}|${row.subagent?.id || ""}`;
|
|
18
|
+
const fill = (finished, started) => {
|
|
19
|
+
const out = { ...finished };
|
|
20
|
+
if (out.tokensBefore === undefined && started.tokensBefore !== undefined)
|
|
21
|
+
out.tokensBefore = started.tokensBefore;
|
|
22
|
+
if (out.filesDropped === undefined && started.filesDropped !== undefined)
|
|
23
|
+
out.filesDropped = started.filesDropped;
|
|
24
|
+
return out;
|
|
25
|
+
};
|
|
26
|
+
/** Each finished or failed compaction takes the fields of the started one before it in its run; that started row is dropped.
|
|
27
|
+
* Rows without a compaction (clears, model switches, texts) do not break a pair. */
|
|
28
|
+
export function pairCompactions(rows) {
|
|
29
|
+
const open = new Map();
|
|
30
|
+
const consumed = new Set();
|
|
31
|
+
const fixed = new Map();
|
|
32
|
+
rows.forEach((row, i) => {
|
|
33
|
+
const compaction = row.compaction;
|
|
34
|
+
if (!compaction)
|
|
35
|
+
return;
|
|
36
|
+
const run = runOf(row);
|
|
37
|
+
if (compaction.phase === "started") {
|
|
38
|
+
open.set(run, i);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const at = open.get(run);
|
|
42
|
+
if (at === undefined)
|
|
43
|
+
return;
|
|
44
|
+
open.delete(run);
|
|
45
|
+
consumed.add(at);
|
|
46
|
+
fixed.set(i, { ...row, compaction: fill(compaction, rows[at].compaction) });
|
|
47
|
+
});
|
|
48
|
+
return rows.flatMap((row, i) => (consumed.has(i) ? [] : [fixed.get(i) ?? row]));
|
|
49
|
+
}
|
|
50
|
+
/** Per agent, its last {max} session events as {at (ms), kind, ...fields}, oldest first. kind: compaction, clear or model. */
|
|
51
|
+
export function sessionHistory(items, max = COMPACTION_HISTORY_MAX) {
|
|
52
|
+
const perAgent = new Map();
|
|
53
|
+
for (const item of items) {
|
|
54
|
+
const row = rowOf(item);
|
|
55
|
+
if (!row)
|
|
56
|
+
continue;
|
|
57
|
+
const list = perAgent.get(item.agent) || [];
|
|
58
|
+
list.push(row);
|
|
59
|
+
perAgent.set(item.agent, list);
|
|
60
|
+
}
|
|
61
|
+
const byAgent = new Map();
|
|
62
|
+
for (const [agent, rows] of perAgent) {
|
|
63
|
+
const entries = pairCompactions(rows).map(entryOf);
|
|
64
|
+
byAgent.set(agent, entries.slice(-max));
|
|
65
|
+
}
|
|
66
|
+
return byAgent;
|
|
67
|
+
}
|
|
68
|
+
// An activity item as a row with its fields validated; null for items that are not session events.
|
|
69
|
+
function rowOf(item) {
|
|
70
|
+
// A subagent's compaction belongs to its run, not the parent's history.
|
|
71
|
+
if (item.subagent)
|
|
72
|
+
return null;
|
|
73
|
+
const base = { id: item.id, time: item.time, agent: item.agent };
|
|
74
|
+
if (item.type === "compact" && item.compaction) {
|
|
75
|
+
const compaction = compactionFields(item.compaction);
|
|
76
|
+
return compaction ? { ...base, type: "compact", compaction } : null;
|
|
77
|
+
}
|
|
78
|
+
if (item.type === "clear" && item.clear)
|
|
79
|
+
return { ...base, type: "clear", clear: clearFields(item.clear) };
|
|
80
|
+
if (item.type === "model" && item.modelSwitch) {
|
|
81
|
+
const modelSwitch = modelFields(item.modelSwitch);
|
|
82
|
+
return modelSwitch ? { ...base, type: "model", modelSwitch } : null;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
// A history entry: {id, at (ms), kind, ...fields}.
|
|
87
|
+
function entryOf(row) {
|
|
88
|
+
const at = row.time * 1000;
|
|
89
|
+
if (row.type === "compact")
|
|
90
|
+
return { id: row.id, at, kind: "compaction", ...row.compaction };
|
|
91
|
+
if (row.type === "clear")
|
|
92
|
+
return { id: row.id, at, kind: "clear", ...row.clear };
|
|
93
|
+
return { id: row.id, at, kind: "model", ...row.modelSwitch };
|
|
94
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// Control runs and interrupts on a session: wake, compact, interrupt, and the environment a harness child gets.
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { delimiter, dirname, isAbsolute, join } from "node:path";
|
|
5
|
+
import { sessionLabel } from "../config.js";
|
|
6
|
+
import { isOwnEnvKey } from "../names.js";
|
|
7
|
+
import { REQUIRE_RUN_CODE_ENV } from "../code-mode.js";
|
|
8
|
+
import { codexCompact, codexLiveCompact, CLIENT, connect } from "../codex-compact.js";
|
|
9
|
+
import { sendMessage } from "../messaging.js";
|
|
10
|
+
import { isRunning } from "../process.js";
|
|
11
|
+
import { WAKE_ENV, WAKE_PROMPT } from "../mode.js";
|
|
12
|
+
import { opencodeRequest } from "../opencode-api.js";
|
|
13
|
+
import { argv } from "../harness.js";
|
|
14
|
+
import { noSubagentArgs, noSubagentEnv } from "../subagent-guard.js";
|
|
15
|
+
const NATIVE_UUID = /^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i;
|
|
16
|
+
// OpenCode session IDs are "ses_" and 26 base-62 characters (OpenCode 2.2.5 logs and API).
|
|
17
|
+
const OPENCODE_SESSION_ID = /^ses_[A-Za-z0-9]{20,40}$/;
|
|
18
|
+
export const SANDBOX_NAME = /^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,62}$/;
|
|
19
|
+
const pending = new Map();
|
|
20
|
+
// Asked of a running session that temmo cannot compact from outside; delivered urgent, at its next hook.
|
|
21
|
+
export const COMPACT_REQUEST = "[temmo] The operator asked to compact this session's context. Finish or checkpoint your current step, "
|
|
22
|
+
+ "reply to the operator in one line with what is still in progress, then end your turn so the operator can run /compact.";
|
|
23
|
+
/** The binary and argv that act on a session; the Cursor name is cursorBinary on the PATH the wake runs with. */
|
|
24
|
+
export function harnessCommand(action, harness, id, requireRunCode, { path = "", permission, managed = false } = {}) {
|
|
25
|
+
// A managed session (team, pattern, builder, spawn) wakes with native subagents still off.
|
|
26
|
+
if (action === "wake")
|
|
27
|
+
return argv(harness, "wake", { id, prompt: WAKE_PROMPT, requireRunCode, path, permission, ...(managed ? { noSubagents: noSubagentArgs(harness) } : {}) });
|
|
28
|
+
if (action === "compact")
|
|
29
|
+
return argv(harness, "compact", { id });
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** Whether a session ID has the shape its harness uses. */
|
|
33
|
+
export function nativeSessionId(harness, id) {
|
|
34
|
+
return typeof id === "string" && (harness === "opencode" ? OPENCODE_SESSION_ID : NATIVE_UUID).test(id);
|
|
35
|
+
}
|
|
36
|
+
/** The environment for a harness child: this process's without TEMMO_*, with node's and ~/.local/bin on PATH. */
|
|
37
|
+
export function harnessEnv() {
|
|
38
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([key]) => !isOwnEnvKey(key)));
|
|
39
|
+
env.PATH = [dirname(process.execPath), join(homedir(), ".local", "bin"), env.PATH].filter(Boolean).join(delimiter);
|
|
40
|
+
return env;
|
|
41
|
+
}
|
|
42
|
+
/** Runner from TEMMO_WAKE_RUNNER (host | openshell) and TEMMO_OPENSHELL_SANDBOX. */
|
|
43
|
+
export function runnerFromEnv(env = process.env) {
|
|
44
|
+
const kind = env.TEMMO_WAKE_RUNNER || "host";
|
|
45
|
+
if (kind === "host")
|
|
46
|
+
return { kind };
|
|
47
|
+
if (kind === "openshell" && SANDBOX_NAME.test(env.TEMMO_OPENSHELL_SANDBOX || "")) {
|
|
48
|
+
return { kind, sandbox: env.TEMMO_OPENSHELL_SANDBOX };
|
|
49
|
+
}
|
|
50
|
+
return { kind: "invalid" };
|
|
51
|
+
}
|
|
52
|
+
/** The argv as given on the host, or wrapped in `openshell sandbox exec` for the openshell runner. */
|
|
53
|
+
export function placeCommand([file, args], cwd, runner) {
|
|
54
|
+
if (runner.kind !== "openshell")
|
|
55
|
+
return [file, args];
|
|
56
|
+
return ["openshell", ["sandbox", "exec", "--name", runner.sandbox, "--workdir", cwd, "--no-tty", "--no-login-shell", "--", file, ...args]];
|
|
57
|
+
}
|
|
58
|
+
function invoke(file, args, options) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const child = spawn(file, args, { ...options, stdio: "ignore", shell: false });
|
|
61
|
+
child.once("error", reject);
|
|
62
|
+
child.once("close", (code) => resolve(code));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Compact a saved Claude session through the Agent SDK; resolves with its compact_boundary metadata. */
|
|
66
|
+
async function sdkCompact(sessionId, cwd) {
|
|
67
|
+
const { query } = await import("@anthropic-ai/claude-agent-sdk");
|
|
68
|
+
let boundary = null;
|
|
69
|
+
let result = null;
|
|
70
|
+
for await (const m of query({ prompt: "/compact", options: { cwd, resume: sessionId, settingSources: [], allowedTools: [] } })) {
|
|
71
|
+
if (m.type === "system" && m.subtype === "compact_boundary")
|
|
72
|
+
boundary = m.compact_metadata;
|
|
73
|
+
if (m.type === "result")
|
|
74
|
+
result = m.subtype;
|
|
75
|
+
}
|
|
76
|
+
return { boundary, result };
|
|
77
|
+
}
|
|
78
|
+
/** Compacts a running session: Codex through its daemon when idle, else an urgent request to finish the step. */
|
|
79
|
+
async function compactRunning(peer, { cfg, codexLive, runner, env }) {
|
|
80
|
+
const { sessionId, cwd, harness } = peer;
|
|
81
|
+
let note = "";
|
|
82
|
+
if (harness === "codex") {
|
|
83
|
+
try {
|
|
84
|
+
const r = await codexLive(sessionId, { cwd, env, command: placeCommand(["codex", ["app-server", "proxy"]], cwd, runner) });
|
|
85
|
+
if (r.status === "compacted")
|
|
86
|
+
return { status: "succeeded", detail: "Codex compacted the running thread through its app-server daemon." };
|
|
87
|
+
note = r.status === "busy" ? "Codex is mid-turn. " : "This Codex session is not attached to the app-server daemon. ";
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
note = "The Codex app-server daemon did not compact the thread. ";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (!cfg?.enabled)
|
|
94
|
+
return { status: "unsupported", detail: `${note}The session is running. Run /compact in it directly.` };
|
|
95
|
+
const where = harness === "claude" ? " in its terminal or from Remote Control" : harness === "codex" ? " in it, or press Compact again once its turn ends" : " in it";
|
|
96
|
+
try {
|
|
97
|
+
await sendMessage({ ...cfg, peer: "operator", session: "" }, peer.id, COMPACT_REQUEST, { operatorThread: true, system: true, urgent: true });
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return { status: "failed", detail: `${note}The compaction request could not be sent. Run /compact${where}.` };
|
|
101
|
+
}
|
|
102
|
+
return { status: "requested", detail: `${note}Asked the session to finish its step at its next hook. Run /compact${where}.` };
|
|
103
|
+
}
|
|
104
|
+
async function run(action, peer, { execute = invoke, compact = sdkCompact, codex = codexCompact, codexLive = codexLiveCompact, runner = runnerFromEnv(), cfg } = {}) {
|
|
105
|
+
const { sessionId, cwd, harness } = peer;
|
|
106
|
+
if (!nativeSessionId(harness, sessionId) || typeof cwd !== "string" || !isAbsolute(cwd) ||
|
|
107
|
+
!peer.id?.endsWith("#" + sessionLabel(sessionId))) {
|
|
108
|
+
return { status: "unsupported", detail: "Missing a verified native session ID or workspace." };
|
|
109
|
+
}
|
|
110
|
+
const env = harnessEnv();
|
|
111
|
+
const command = harnessCommand(action, harness, sessionId, peer.requireRunCode === true, { path: env.PATH, permission: peer.claudePermission, managed: peer.managed === true });
|
|
112
|
+
const sdk = action === "compact" && harness === "claude";
|
|
113
|
+
const appServer = action === "compact" && harness === "codex";
|
|
114
|
+
const adapter = Boolean(command || sdk || appServer);
|
|
115
|
+
const noAdapter = { status: "unsupported", detail: `No ${action} adapter for ${harness}.` };
|
|
116
|
+
// A running Cursor session still gets the compaction request; an exited one has no adapter.
|
|
117
|
+
if (!adapter && !(action === "compact" && ["claude", "codex", "cursor"].includes(harness)))
|
|
118
|
+
return noAdapter;
|
|
119
|
+
if (runner.kind === "invalid")
|
|
120
|
+
return { status: "failed", detail: "TEMMO_WAKE_RUNNER is misconfigured." };
|
|
121
|
+
if (!Number.isInteger(peer.pid) || typeof peer.pidStart !== "string") {
|
|
122
|
+
return { status: "unsupported", detail: "No recorded harness process, so exit cannot be verified. The message stays queued." };
|
|
123
|
+
}
|
|
124
|
+
// OpenCode compacts through its server whether or not a turn is running.
|
|
125
|
+
const serverCompact = action === "compact" && harness === "opencode";
|
|
126
|
+
if (!serverCompact && isRunning({ pid: peer.pid, start: peer.pidStart })) {
|
|
127
|
+
return action === "wake"
|
|
128
|
+
? { status: "queued", detail: "The session is running. Its next hook delivers the message." }
|
|
129
|
+
: compactRunning(peer, { cfg, codexLive, runner, env });
|
|
130
|
+
}
|
|
131
|
+
if (!adapter)
|
|
132
|
+
return noAdapter;
|
|
133
|
+
if (sdk) {
|
|
134
|
+
try {
|
|
135
|
+
const { boundary, result } = await compact(sessionId, cwd);
|
|
136
|
+
if (!boundary)
|
|
137
|
+
return { status: "failed", detail: `Claude finished (${result ?? "no result"}) without compacting.` };
|
|
138
|
+
return { status: "succeeded", detail: `Compacted ${boundary.pre_tokens} → ${boundary.post_tokens} tokens.` };
|
|
139
|
+
}
|
|
140
|
+
catch {
|
|
141
|
+
return { status: "failed", detail: "Claude Agent SDK compaction failed." };
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (appServer) {
|
|
145
|
+
try {
|
|
146
|
+
await codex(sessionId, { cwd, env, command: placeCommand(["codex", ["app-server"]], cwd, runner) });
|
|
147
|
+
return { status: "succeeded", detail: "Codex compacted the thread." };
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
return { status: "failed", detail: "Codex app-server compaction failed." };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
const [file, args] = placeCommand(command, cwd, runner);
|
|
154
|
+
if (action === "wake" && peer.requireRunCode === true)
|
|
155
|
+
env[REQUIRE_RUN_CODE_ENV] = "1";
|
|
156
|
+
if (action === "wake" && peer.managed === true)
|
|
157
|
+
Object.assign(env, noSubagentEnv(harness, env));
|
|
158
|
+
env[WAKE_ENV] = "1"; // hooks in the resumed run must not read its prompt as the operator returning
|
|
159
|
+
try {
|
|
160
|
+
const code = await execute(file, args, { cwd, env });
|
|
161
|
+
if (code !== 0)
|
|
162
|
+
return { status: "failed", detail: file + " exited " + (code ?? "after a signal") + "." };
|
|
163
|
+
return { status: "succeeded", detail: serverCompact ? "OpenCode compacted the session." : "The harness finished the resumed turn." };
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return { status: "failed", detail: error.code === "ENOENT" ? "Executable or workspace unavailable." : "Harness invocation failed." };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** One control run per session at a time; concurrent retries share the in-flight result. */
|
|
170
|
+
export function controlSession(action, peer, options) {
|
|
171
|
+
if (!peer)
|
|
172
|
+
return Promise.resolve({ status: "unsupported", detail: "Missing local session registration." });
|
|
173
|
+
const key = JSON.stringify([peer.harness, peer.sessionId]);
|
|
174
|
+
const active = pending.get(key);
|
|
175
|
+
if (active?.action === action)
|
|
176
|
+
return active.promise;
|
|
177
|
+
if (active)
|
|
178
|
+
return Promise.resolve({ status: "failed", detail: `A ${active.action} run for this session is in progress. Retry after it finishes.` });
|
|
179
|
+
const promise = run(action, peer, options).finally(() => pending.delete(key));
|
|
180
|
+
pending.set(key, { action, promise });
|
|
181
|
+
return promise;
|
|
182
|
+
}
|
|
183
|
+
/** Interrupts a thread's turn in the app-server daemon; resolves interrupted, not-running or not-loaded. */
|
|
184
|
+
export async function codexLiveInterrupt(threadId, { cwd, env, command = argv("codex", "interrupt", {}), timeoutMs = 15_000 } = {}) {
|
|
185
|
+
const rpc = connect(command, { cwd, env });
|
|
186
|
+
const timer = setTimeout(() => rpc.close(), timeoutMs);
|
|
187
|
+
try {
|
|
188
|
+
await rpc.request("initialize", { clientInfo: CLIENT, capabilities: null });
|
|
189
|
+
rpc.send({ method: "initialized" });
|
|
190
|
+
const loaded = [];
|
|
191
|
+
let cursor = null;
|
|
192
|
+
do {
|
|
193
|
+
const page = await rpc.request("thread/loaded/list", cursor ? { cursor } : {});
|
|
194
|
+
loaded.push(...(Array.isArray(page?.data) ? page.data : []));
|
|
195
|
+
cursor = typeof page?.nextCursor === "string" ? page.nextCursor : null;
|
|
196
|
+
} while (cursor && !loaded.includes(threadId));
|
|
197
|
+
if (!loaded.includes(threadId))
|
|
198
|
+
return { status: "not-loaded" };
|
|
199
|
+
const read = await rpc.request("thread/read", { threadId, includeTurns: true });
|
|
200
|
+
const turn = (read?.thread?.turns ?? []).findLast((t) => t?.status === "inProgress");
|
|
201
|
+
if (!turn?.id)
|
|
202
|
+
return { status: "not-running" };
|
|
203
|
+
await rpc.request("turn/interrupt", { threadId, turnId: turn.id });
|
|
204
|
+
return { status: "interrupted" };
|
|
205
|
+
}
|
|
206
|
+
finally {
|
|
207
|
+
clearTimeout(timer);
|
|
208
|
+
rpc.close();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/** Interrupts a registry session's running turn; resolves {status: succeeded|not-running|unsupported|failed, detail}. */
|
|
212
|
+
export async function interruptSession(peer, { env = harnessEnv(), runner = runnerFromEnv(), codexInterrupt = codexLiveInterrupt, opencode = opencodeRequest } = {}) {
|
|
213
|
+
if (!peer)
|
|
214
|
+
return { status: "unsupported", detail: "Missing local session registration." };
|
|
215
|
+
const { sessionId, cwd, harness } = peer;
|
|
216
|
+
if (!["codex", "opencode"].includes(harness)) {
|
|
217
|
+
return { status: "unsupported", detail: `${harness} has no outside interrupt; press Esc in its terminal.` };
|
|
218
|
+
}
|
|
219
|
+
if (!nativeSessionId(harness, sessionId) || !peer.id?.endsWith("#" + sessionLabel(sessionId))) {
|
|
220
|
+
return { status: "unsupported", detail: "Missing a verified native session ID." };
|
|
221
|
+
}
|
|
222
|
+
if (harness === "opencode") {
|
|
223
|
+
const r = await opencode("POST", `/api/session/${encodeURIComponent(sessionId)}/interrupt`);
|
|
224
|
+
if (!r.ok)
|
|
225
|
+
return r.status === 404 ? { status: "not-running", detail: "OpenCode has no such running session." } : { status: "failed", detail: r.error };
|
|
226
|
+
const interrupted = r.body?.interrupted ?? r.body?.data?.interrupted;
|
|
227
|
+
return interrupted ? { status: "succeeded", detail: "OpenCode interrupted the turn." } : { status: "not-running", detail: "No turn was running." };
|
|
228
|
+
}
|
|
229
|
+
if (typeof cwd !== "string" || !isAbsolute(cwd))
|
|
230
|
+
return { status: "unsupported", detail: "Missing a workspace." };
|
|
231
|
+
if (runner.kind === "invalid")
|
|
232
|
+
return { status: "failed", detail: "TEMMO_WAKE_RUNNER is misconfigured." };
|
|
233
|
+
try {
|
|
234
|
+
const r = await codexInterrupt(sessionId, { cwd, env, command: placeCommand(argv("codex", "interrupt", {}), cwd, runner) });
|
|
235
|
+
if (r.status === "interrupted")
|
|
236
|
+
return { status: "succeeded", detail: "Codex interrupted the turn." };
|
|
237
|
+
if (r.status === "not-running")
|
|
238
|
+
return { status: "not-running", detail: "No turn was running." };
|
|
239
|
+
return { status: "unsupported", detail: "This Codex session is not attached to the app-server daemon." };
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
return { status: "failed", detail: "The Codex app-server daemon did not interrupt the turn." };
|
|
243
|
+
}
|
|
244
|
+
}
|