@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,240 @@
|
|
|
1
|
+
// One builder attempt: the agent in its sandbox, collection, and the limit retry chain.
|
|
2
|
+
import * as S from "../sandbox.js";
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { existsSync, mkdtempSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { basename, join } from "node:path";
|
|
7
|
+
import { stateDir } from "../config.js";
|
|
8
|
+
import { PROMPT_MAX_CHARS } from "../sessions/launch.js";
|
|
9
|
+
import { cursorLimitFile, cursorLimitUntil, detectLimit, fallbackChain, isBlockingLimit, recordCursorLimit } from "../limits.js";
|
|
10
|
+
import { listModels } from "../models.js";
|
|
11
|
+
import { traceStream } from "../cursor-trace.js";
|
|
12
|
+
import { OUT, SANDBOX, WORK } from "../sandbox.js";
|
|
13
|
+
import { BUILDER_HARNESSES, DEFAULT_MODEL, BASE_REF, SYNC_TIMEOUT_MS, readState, updateState } from "./state.js";
|
|
14
|
+
import { harnessCommand } from "./policy.js";
|
|
15
|
+
import { builderSandboxGone, must, uploadBuilderSandbox, hasInstall, stage } from "./stage.js";
|
|
16
|
+
import { prepareSettlement } from "./settle.js";
|
|
17
|
+
/** The sandbox notes appended to every builder brief. */
|
|
18
|
+
export function briefNotes({ task, branch, workdir }) {
|
|
19
|
+
return [
|
|
20
|
+
"",
|
|
21
|
+
"## Builder sandbox",
|
|
22
|
+
`You run inside an OpenShell sandbox. Your worktree is ${workdir} on branch ${branch}; ${BASE_REF} is the base.`,
|
|
23
|
+
"git, node, npm and oncebitten are on PATH. Commit your work on this branch with git; the host copies your commits back after you exit.",
|
|
24
|
+
`\`temmo task set|progress\` are recorded and applied on the host when you exit; \`temmo task show ${task}\` prints a snapshot. Nothing else of temmo works here.`,
|
|
25
|
+
"Use TMPDIR=$(mktemp -d -p /tmp) for the test suite: /dev/shm is not writable here.",
|
|
26
|
+
`Before marking the task done, run \`oncebitten check --base ${BASE_REF}\` and fix what fires.`,
|
|
27
|
+
`Finish with \`temmo task set ${task} status=done\`, or status=blocked detail=<reason>.`,
|
|
28
|
+
"",
|
|
29
|
+
].join("\n");
|
|
30
|
+
}
|
|
31
|
+
export function cursorLimitPath(model, env) {
|
|
32
|
+
return { state: cursorLimitFile(model, env) };
|
|
33
|
+
}
|
|
34
|
+
export function cursorLimitDetail(harness, model, env) {
|
|
35
|
+
if (harness !== "cursor")
|
|
36
|
+
return undefined;
|
|
37
|
+
const until = cursorLimitUntil(model, env);
|
|
38
|
+
if (until > Date.now())
|
|
39
|
+
return `Cursor ${model} reached its usage limit. Choose another approved model or retry after ${new Date(until).toISOString()}.`;
|
|
40
|
+
}
|
|
41
|
+
/** Retry chain after a Codex usage limit: lib/limits.ts's chain, Codex only as another configured model. */
|
|
42
|
+
export function fallbackAttempts(env, { model = "", available = [], models = {} } = {}) {
|
|
43
|
+
return fallbackChain({ harness: "codex", model, models: leadWithDefaults(models), available, env }).map(({ harness, model: next }) => ({ harness, model: next }));
|
|
44
|
+
}
|
|
45
|
+
// A harness's default model leads its listed models, so a retry does not take the catalogue's first entry.
|
|
46
|
+
function leadWithDefaults(models) {
|
|
47
|
+
return Object.fromEntries(Object.entries(models).map(([harness, list]) => {
|
|
48
|
+
const preferred = DEFAULT_MODEL[harness];
|
|
49
|
+
return [harness, preferred && list.includes(preferred) ? [preferred, ...list.filter((name) => name !== preferred)] : list];
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
/** The first retry target: defaults.json "limitFallback" ("harness:model"), else Cursor DeepSeek. */
|
|
53
|
+
export function limitFallback(env) {
|
|
54
|
+
return fallbackAttempts(env)[0];
|
|
55
|
+
}
|
|
56
|
+
export async function retryLimitedBuilder(state, paths, context) {
|
|
57
|
+
const { openshell, env, log, signal } = context;
|
|
58
|
+
const sandbox = state.sandbox;
|
|
59
|
+
let { fallback } = readState(paths);
|
|
60
|
+
let resuming = fallback?.phase === "running";
|
|
61
|
+
if (typeof fallback === "string")
|
|
62
|
+
throw new Error("builder interrupted during fallback; inspect " + sandbox);
|
|
63
|
+
const models = await listModels(stateDir(env), env, { peers: [], run: async () => "" }).catch(() => ({}));
|
|
64
|
+
const available = BUILDER_HARNESSES.filter((harness) => hasInstall(harness, state, env));
|
|
65
|
+
fallback ??= { remaining: fallbackAttempts(env, { model: state.model, available, models }), detail: "Codex reached its usage limit. No fallback model is available." };
|
|
66
|
+
while (fallback.remaining.length) {
|
|
67
|
+
signal?.throwIfAborted();
|
|
68
|
+
const attempt = { ...state, ...fallback.remaining[0] };
|
|
69
|
+
if (!fallback.phase) {
|
|
70
|
+
const limited = cursorLimitDetail(attempt.harness, attempt.model, env);
|
|
71
|
+
if (limited) {
|
|
72
|
+
fallback = { remaining: fallback.remaining.slice(1), detail: `Codex reached its usage limit. ${limited}` };
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!hasInstall(attempt.harness, state, env)) {
|
|
76
|
+
log(`no ${attempt.harness} install found on the host; trying the next model`);
|
|
77
|
+
fallback = { remaining: fallback.remaining.slice(1), detail: `Codex reached its usage limit. No ${attempt.harness} install was found on the host.` };
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
fallback = { ...fallback, phase: "staging" };
|
|
81
|
+
updateState(paths, { fallback, phase: "staging", workspaceUploaded: false, collected: false });
|
|
82
|
+
}
|
|
83
|
+
if (fallback.phase === "staging") {
|
|
84
|
+
// Replacement is safe once the previous workspace and calls are on the host.
|
|
85
|
+
const gone = await builderSandboxGone(state, { openshell, env });
|
|
86
|
+
if (!gone.ok)
|
|
87
|
+
throw new Error("could not replace builder sandbox: " + gone.detail);
|
|
88
|
+
updateState(paths, { sandboxCreated: false });
|
|
89
|
+
log(`Codex usage limit reached; retrying with ${attempt.harness}:${attempt.model}`);
|
|
90
|
+
const staged = await stage(attempt, paths, { env, log, resume: join(paths.back, basename(state.worktree)) });
|
|
91
|
+
await uploadBuilderSandbox(attempt, paths, staged, context);
|
|
92
|
+
if (existsSync(paths.out))
|
|
93
|
+
await S.uploadAll({ openshell, env, sandbox, local: paths.out, remote: SANDBOX });
|
|
94
|
+
fallback = { ...fallback, staged, phase: "running" };
|
|
95
|
+
updateState(paths, { fallback, phase: "running", workspaceUploaded: true });
|
|
96
|
+
}
|
|
97
|
+
if (fallback.phase === "running") {
|
|
98
|
+
const agent = resuming ? {
|
|
99
|
+
...attempt,
|
|
100
|
+
prompt: builderResumePrompt(attempt.prompt ?? readFileSync(paths.brief, "utf8")),
|
|
101
|
+
} : attempt;
|
|
102
|
+
resuming = false;
|
|
103
|
+
const result = await runSandboxAgent(agent, paths, fallback.staged, context);
|
|
104
|
+
fallback = { ...fallback, phase: "collecting", result };
|
|
105
|
+
updateState(paths, { fallback, phase: "collecting", exitCode: result.exitCode });
|
|
106
|
+
}
|
|
107
|
+
if (fallback.phase === "collecting") {
|
|
108
|
+
await collect(attempt, paths, fallback.staged, context);
|
|
109
|
+
fallback = { ...fallback, phase: "collected" };
|
|
110
|
+
updateState(paths, { fallback, phase: "collected" });
|
|
111
|
+
}
|
|
112
|
+
const { exitCode, usageLimit, limitDetail } = fallback.result;
|
|
113
|
+
const limited = limitDetail ?? (usageLimit ? `${attempt.harness} reached its usage limit.` : undefined);
|
|
114
|
+
if (!limited) {
|
|
115
|
+
await prepareSettlement(attempt, paths, exitCode, context);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
fallback = { remaining: fallback.remaining.slice(1), detail: `Codex reached its usage limit. ${limited}` };
|
|
119
|
+
updateState(paths, { fallback });
|
|
120
|
+
}
|
|
121
|
+
await prepareSettlement(state, paths, readState(paths).exitCode, { env, log, limitDetail: fallback.detail });
|
|
122
|
+
}
|
|
123
|
+
export async function runSandboxAgent(state, paths, staged, { openshell, env, log, onChild, signal }) {
|
|
124
|
+
signal?.throwIfAborted();
|
|
125
|
+
const original = state.prompt ?? readFileSync(paths.brief, "utf8");
|
|
126
|
+
const brief = staged.builderCode ? original + "\nUse temmo-code run_code to batch related sh, read, grep and edit operations. "
|
|
127
|
+
+ "Check command exit codes and return only the findings needed for your next decision." : original;
|
|
128
|
+
const launcher = staged.layout.file ? staged.layout.dir + "/" + basename(staged.layout.tree) : undefined;
|
|
129
|
+
const argv = S.execArgv({
|
|
130
|
+
openshell, sandbox: state.sandbox, workdir: staged.workdir, env: staged.execEnv,
|
|
131
|
+
command: harnessCommand({ ...state, brief, workdir: staged.workdir, launcher, builderCode: staged.builderCode }),
|
|
132
|
+
});
|
|
133
|
+
log("running " + state.harness + " " + state.model + " in sandbox " + state.sandbox);
|
|
134
|
+
const cursor = state.harness === "cursor";
|
|
135
|
+
const codex = state.harness === "codex";
|
|
136
|
+
const stdio = cursor || codex ? ["ignore", "pipe", "pipe"] : ["ignore", "inherit", "inherit"];
|
|
137
|
+
const child = spawn(argv[0], argv.slice(1), { env, stdio });
|
|
138
|
+
onChild?.(child);
|
|
139
|
+
const stop = () => child.kill("SIGTERM");
|
|
140
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
141
|
+
// A Cursor builder's stream-json passes through to the log and becomes its OTLP trace (model, tokens, tool calls).
|
|
142
|
+
const trace = cursor ? traceStream(child.stdout, { env, out: process.stdout, role: "builder", model: state.model }) : null;
|
|
143
|
+
let errorTail = "";
|
|
144
|
+
let cursorLimit;
|
|
145
|
+
let usageLimit = false;
|
|
146
|
+
if (codex) {
|
|
147
|
+
let outputTail = "";
|
|
148
|
+
child.stdout?.setEncoding("utf8").on("data", (chunk) => {
|
|
149
|
+
process.stdout.write(chunk);
|
|
150
|
+
outputTail = (outputTail + chunk).slice(-8192);
|
|
151
|
+
// Codex stdout can contain assistant text alongside explicit errors.
|
|
152
|
+
usageLimit ||= outputTail.split(/\r?\n/).some((line) => /^\s*error:/i.test(line) && isBlockingLimit(detectLimit("codex", line)));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
child.stderr?.setEncoding("utf8").on("data", (chunk) => {
|
|
156
|
+
process.stderr.write(chunk);
|
|
157
|
+
errorTail = (errorTail + chunk).slice(-8192);
|
|
158
|
+
if (cursor) {
|
|
159
|
+
// Cursor reports a limit as an ActionRequiredError line; the shared detector decides which of those lines is one.
|
|
160
|
+
const lines = errorTail.match(/^ActionRequiredError:[^\r\n]*/gim) ?? [];
|
|
161
|
+
cursorLimit = lines.find((line) => isBlockingLimit(detectLimit("cursor", line))) ?? cursorLimit;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Each line is its own text: a rate line and a reset line from different places are not one limit.
|
|
165
|
+
usageLimit ||= errorTail.split(/\r?\n/).some((line) => isBlockingLimit(detectLimit("codex", line)));
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const exitCode = await new Promise((resolve, reject) => {
|
|
169
|
+
child.once("error", reject);
|
|
170
|
+
child.once("close", resolve);
|
|
171
|
+
}).finally(() => {
|
|
172
|
+
signal?.removeEventListener("abort", stop);
|
|
173
|
+
onChild?.(null);
|
|
174
|
+
});
|
|
175
|
+
signal?.throwIfAborted();
|
|
176
|
+
await trace?.finish({ exitStatus: exitCode === 0 ? undefined : "error" });
|
|
177
|
+
if (exitCode !== 0 && cursorLimit)
|
|
178
|
+
await recordCursorLimit(state.model, cursorLimit, { env });
|
|
179
|
+
return { exitCode, usageLimit: exitCode !== 0 && usageLimit,
|
|
180
|
+
limitDetail: exitCode !== 0 && cursorLimit ? cursorLimitDetail(state.harness, state.model, env) : undefined };
|
|
181
|
+
}
|
|
182
|
+
export function builderResumePrompt(prompt) {
|
|
183
|
+
const instruction = "The runner restarted during this assignment. Inspect the existing workspace and continue the task. Preserve any work already completed.";
|
|
184
|
+
return instruction + "\n\n" + prompt.slice(0, PROMPT_MAX_CHARS - instruction.length - 2);
|
|
185
|
+
}
|
|
186
|
+
// Copies a credentials file the harness refreshed inside back to the host, unless the host's changed meanwhile; never logs it.
|
|
187
|
+
async function keepRefreshedAuth(state, staged, { openshell, env, log }) {
|
|
188
|
+
const { layout } = staged;
|
|
189
|
+
if (!layout.auth || !staged.authHash)
|
|
190
|
+
return;
|
|
191
|
+
const remote = `${layout.authDir}/${basename(layout.auth)}`;
|
|
192
|
+
const res = await S.runTool(openshell, S.execArgv({ openshell, sandbox: state.sandbox, command: ["cat", remote] }).slice(1), { env });
|
|
193
|
+
if (res.code !== 0 || !res.stdout.trim())
|
|
194
|
+
return;
|
|
195
|
+
const inside = createHash("sha256").update(res.stdout).digest("hex");
|
|
196
|
+
if (inside === staged.authHash)
|
|
197
|
+
return;
|
|
198
|
+
if (S.fileHash(layout.auth) !== staged.authHash) {
|
|
199
|
+
log(`${state.harness} credentials changed on both sides; kept the host's`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const tmp = `${layout.auth}.builder-${process.pid}`;
|
|
203
|
+
writeFileSync(tmp, res.stdout, { mode: 0o600 });
|
|
204
|
+
renameSync(tmp, layout.auth);
|
|
205
|
+
log(`${state.harness} refreshed its credentials in the sandbox; copied them back to the host`);
|
|
206
|
+
}
|
|
207
|
+
// Downloads the worktree clone and the recorded hook payloads and task calls.
|
|
208
|
+
export async function collect(state, paths, staged, { openshell, env, log }) {
|
|
209
|
+
log(`collecting workspace from sandbox ${state.sandbox}`);
|
|
210
|
+
await keepRefreshedAuth(state, staged, { openshell, env, log });
|
|
211
|
+
await S.runTool(openshell, S.execArgv({ openshell, sandbox: state.sandbox, command: ["rm", "-f", `${staged.workdir}/node_modules`] }).slice(1), { env });
|
|
212
|
+
await downloadWorktree(state, paths, openshell, env);
|
|
213
|
+
updateState(paths, { collected: true });
|
|
214
|
+
rmSync(paths.out, { recursive: true, force: true });
|
|
215
|
+
const got = await S.runTool(openshell, ["sandbox", "download", state.sandbox, OUT, paths.out], { env, timeoutMs: SYNC_TIMEOUT_MS });
|
|
216
|
+
if (got.code !== 0)
|
|
217
|
+
log("no recorded task calls or hook payloads");
|
|
218
|
+
}
|
|
219
|
+
export async function downloadWorktree(state, paths, openshell, env) {
|
|
220
|
+
const name = basename(state.worktree);
|
|
221
|
+
const incoming = mkdtempSync(join(paths.dir, "download-"));
|
|
222
|
+
try {
|
|
223
|
+
await must(openshell, ["sandbox", "download", state.sandbox, `${WORK}/${name}`, join(incoming, name)], env, "sandbox download");
|
|
224
|
+
if (!existsSync(join(incoming, name, ".git")))
|
|
225
|
+
throw new Error("Downloaded workspace is missing its Git repository");
|
|
226
|
+
rmSync(paths.back, { recursive: true, force: true });
|
|
227
|
+
renameSync(incoming, paths.back);
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
rmSync(incoming, { recursive: true, force: true });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
export async function cleanupBuilderSandbox(state, paths, { openshell, env, log }) {
|
|
234
|
+
const final = readState(paths);
|
|
235
|
+
if (final.sandboxCreated && (!final.workspaceUploaded || final.collected)) {
|
|
236
|
+
const gone = await builderSandboxGone(state, { openshell, env });
|
|
237
|
+
log(gone.ok ? `sandbox ${state.sandbox} deleted` : `sandbox delete failed: ${gone.detail}`);
|
|
238
|
+
updateState(paths, { sandboxDeleted: gone.ok, sandboxCreated: !gone.ok });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// Settlement: commit, fast-forward the host branch, oncebitten check, and the task verdict.
|
|
2
|
+
import * as S from "../sandbox.js";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { existsSync, readdirSync, readFileSync, rmSync } from "node:fs";
|
|
5
|
+
import { basename, dirname, join } from "node:path";
|
|
6
|
+
import { clipProgress, openTasks, reviewPacket, STATUSES } from "../tasks.js";
|
|
7
|
+
import { cleanBuilders } from "../builder-clean.js";
|
|
8
|
+
import { loadConfig } from "../config.js";
|
|
9
|
+
import { task } from "../task-cli.js";
|
|
10
|
+
import { WORK } from "../sandbox.js";
|
|
11
|
+
import { BUILDER_HARNESSES, BASE_REF, GIT_TIMEOUT_MS, readState, updateState, oneLine } from "./state.js";
|
|
12
|
+
import { git, findOncebitten } from "./stage.js";
|
|
13
|
+
/** Whether a recorded call may be replayed on the host: only `task set` and `task progress`. */
|
|
14
|
+
export function replayable(argv) {
|
|
15
|
+
return argv[0] === "task" && (argv[1] === "set" || argv[1] === "progress") && argv.length >= 4;
|
|
16
|
+
}
|
|
17
|
+
/** Splits a recorded shim call (NUL-terminated arguments) into argv. */
|
|
18
|
+
export function parseRecordedCall(text) {
|
|
19
|
+
const parts = String(text).split("\0");
|
|
20
|
+
if (parts.at(-1) === "")
|
|
21
|
+
parts.pop();
|
|
22
|
+
return parts;
|
|
23
|
+
}
|
|
24
|
+
// Save the verified verdict before publishing it.
|
|
25
|
+
const HARNESS_NAMES = { cursor: "Cursor", codex: "Codex", claude: "Claude", opencode: "OpenCode" };
|
|
26
|
+
export async function prepareSettlement(state, paths, exitCode, { env, log, limitDetail }) {
|
|
27
|
+
const back = join(paths.back, basename(state.worktree));
|
|
28
|
+
const hostGit = (cwd, args) => git(cwd, args, env);
|
|
29
|
+
const harnessName = HARNESS_NAMES[state.harness];
|
|
30
|
+
const trailer = `Assisted-by: ${harnessName}:${state.model}`;
|
|
31
|
+
if (await S.commitUncommitted({ git: hostGit, repo: back, message: `chore(builder): uncommitted work from ${state.id}`, trailer }))
|
|
32
|
+
log("committed the agent's uncommitted changes on the host");
|
|
33
|
+
const commits = await S.commitsAhead({ git: hostGit, repo: back, base: state.base });
|
|
34
|
+
let landed = false;
|
|
35
|
+
let commit;
|
|
36
|
+
let landError = "";
|
|
37
|
+
if (commits > 0) {
|
|
38
|
+
try {
|
|
39
|
+
commit = (await git(back, ["rev-parse", "HEAD"], env)).trim();
|
|
40
|
+
await git(state.worktree, ["fetch", "--quiet", back, "HEAD"], env);
|
|
41
|
+
await git(state.worktree, ["merge", "--quiet", "--ff-only", "FETCH_HEAD"], env);
|
|
42
|
+
landed = true;
|
|
43
|
+
log(`${commits} commit(s) on ${state.branch}`);
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
landError = `could not fast-forward ${state.branch}; the work is kept in ${back}: ${oneLine(error.message)}`;
|
|
47
|
+
log(landError);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Report sinks do not all offer idempotency keys. An interrupted replay requires operator review.
|
|
51
|
+
if (readState(paths).replayingReports)
|
|
52
|
+
throw new Error("builder interrupted while replaying reports; inspect " + paths.out);
|
|
53
|
+
updateState(paths, { replayingReports: true });
|
|
54
|
+
const captured = await replayCaptures(state, paths, env, log);
|
|
55
|
+
const check = landed ? await oncebittenCheck(state, env) : { code: 0, text: "" };
|
|
56
|
+
const requested = await replayCalls(state, paths, env, log);
|
|
57
|
+
let status = "blocked";
|
|
58
|
+
let detail = limitDetail;
|
|
59
|
+
if (landError)
|
|
60
|
+
detail = landError;
|
|
61
|
+
else if (check.code !== 0) {
|
|
62
|
+
const reason = check.code === 1 ? "fired" : "could not run";
|
|
63
|
+
detail = "oncebitten check --base " + BASE_REF + " " + reason + ": " + (check.text || "exit " + check.code);
|
|
64
|
+
log(detail);
|
|
65
|
+
}
|
|
66
|
+
else if (requested !== "blocked") {
|
|
67
|
+
if (exitCode === 0 && landed)
|
|
68
|
+
status = "review";
|
|
69
|
+
else
|
|
70
|
+
detail ??= `builder ${state.unit} exited ${exitCode} with ${commits} commit(s) and ${requested ? "requested " + requested : "set no status"}`;
|
|
71
|
+
}
|
|
72
|
+
// A finished build waits for the operator's verdict, so the packet rides with the settlement the runner saved above.
|
|
73
|
+
const review = status === "review" ? reviewPacket({
|
|
74
|
+
submission: randomUUID(), commit, base: state.base, branch: state.branch,
|
|
75
|
+
criteria: reviewCriteria(state, paths, env), check, numstat: await reviewNumstat(back, state.base, env),
|
|
76
|
+
}) : undefined;
|
|
77
|
+
const outcome = `builder ${state.unit}: exit ${exitCode}, ${commits} commit(s) on ${state.branch}, ${captured} oncebitten capture(s)`;
|
|
78
|
+
const progress = limitDetail ? `${limitDetail} ${outcome}` : outcome;
|
|
79
|
+
updateState(paths, { settlement: { commits, landed, status, detail, captured, oncebitten: landed ? check.code : null, checkText: check.text, progress, ...(review ? { review } : {}), at: Date.now() } });
|
|
80
|
+
log(`settled as ${status} (agent exit ${exitCode}, requested ${requested || "no status"}, oncebitten ${landed ? "exit " + check.code : "skipped"})`);
|
|
81
|
+
}
|
|
82
|
+
// The criteria a reviewer judges the build against: the task's own detail, else the brief's opening paragraph.
|
|
83
|
+
function reviewCriteria(state, paths, env) {
|
|
84
|
+
let detail = "";
|
|
85
|
+
try {
|
|
86
|
+
detail = openTasks(state.project, env).get(state.task).detail || "";
|
|
87
|
+
}
|
|
88
|
+
catch { /* store unreadable; fall back to the brief */ }
|
|
89
|
+
if (detail.trim())
|
|
90
|
+
return detail;
|
|
91
|
+
try {
|
|
92
|
+
const brief = readFileSync(paths.brief, "utf8").split("\n## Builder sandbox\n")[0].trim();
|
|
93
|
+
return brief.split(/\n{2,}/)[0] || brief;
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Per-file line counts for the packet; a missing range is not worth failing the settlement over.
|
|
100
|
+
async function reviewNumstat(back, base, env) {
|
|
101
|
+
try {
|
|
102
|
+
return await git(back, ["diff", "--numstat", `${base}..HEAD`], env);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export async function publishSettlement(state, paths, env) {
|
|
109
|
+
const { at, progress, detail, ...result } = readState(paths).settlement;
|
|
110
|
+
const tasks = openTasks(state.project, env);
|
|
111
|
+
const entry = { by: state.unit, text: clipProgress(progress || detail).text };
|
|
112
|
+
// The progress entry and verdict are written together. On retry the entry proves publication.
|
|
113
|
+
if (!tasks.get(state.task).progress.some((p) => p.at === at && p.by === entry.by && p.text === entry.text)) {
|
|
114
|
+
// A runner killed while holding this lock can leave it behind until the stale-lock timeout.
|
|
115
|
+
await tasks.update(state.task, { status: result.status, ...(result.review ? { review: result.review } : {}), ...(detail !== undefined ? { detail } : {}), progress: entry }, at, { waitMs: 45_000 });
|
|
116
|
+
}
|
|
117
|
+
if (result.landed)
|
|
118
|
+
rmSync(paths.back, { recursive: true, force: true });
|
|
119
|
+
rmSync(paths.stage, { recursive: true, force: true });
|
|
120
|
+
updateState(paths, { phase: result.error ? "failed" : "finished", ended: Date.now(), ...result });
|
|
121
|
+
await cleanBuilders(env);
|
|
122
|
+
}
|
|
123
|
+
// Feeds every saved hook payload to the host's `oncebitten capture`, with sandbox paths mapped to the host worktree.
|
|
124
|
+
async function replayCaptures(state, paths, env, log) {
|
|
125
|
+
const dir = join(paths.out, "oncebitten");
|
|
126
|
+
if (!existsSync(dir))
|
|
127
|
+
return 0;
|
|
128
|
+
const bin = env.TEMMO_ONCEBITTEN_BIN || findOncebitten(env);
|
|
129
|
+
if (!bin) {
|
|
130
|
+
log("oncebitten is not installed on the host; captures dropped");
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
const workdir = `${WORK}/${basename(state.worktree)}`;
|
|
134
|
+
let count = 0;
|
|
135
|
+
for (const file of readdirSync(dir).sort()) {
|
|
136
|
+
const host = file.replace(/\.json$/, "").split("-").slice(2).join("-") || state.harness;
|
|
137
|
+
const payload = readFileSync(join(dir, file), "utf8").split(workdir).join(state.worktree);
|
|
138
|
+
if (!payload.trim())
|
|
139
|
+
continue;
|
|
140
|
+
const res = await S.runTool(bin, ["capture", "--host", BUILDER_HARNESSES.includes(host) ? host : state.harness], { env, cwd: state.worktree, stdin: payload });
|
|
141
|
+
if (res.code === 0)
|
|
142
|
+
count += 1;
|
|
143
|
+
}
|
|
144
|
+
return count;
|
|
145
|
+
}
|
|
146
|
+
// Own-task status assignments are requests. Replay other fields and progress as usual.
|
|
147
|
+
async function replayCalls(state, paths, env, log) {
|
|
148
|
+
const dir = join(paths.out, "temmo");
|
|
149
|
+
let requested = "";
|
|
150
|
+
if (!existsSync(dir))
|
|
151
|
+
return requested;
|
|
152
|
+
for (const file of readdirSync(dir).sort()) {
|
|
153
|
+
const argv = parseRecordedCall(readFileSync(join(dir, file), "utf8"));
|
|
154
|
+
if (!replayable(argv)) {
|
|
155
|
+
log(`skipped recorded call: ${argv.slice(0, 2).join(" ")}`);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
let status;
|
|
159
|
+
if (argv[1] === "set" && argv[2] === state.task) {
|
|
160
|
+
const fields = argv.slice(3);
|
|
161
|
+
status = fields.findLast(a => a.startsWith("status="))?.slice(7);
|
|
162
|
+
if (status !== undefined && !STATUSES.includes(status)) {
|
|
163
|
+
log(`skipped recorded call with invalid status: ${status}`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
argv.splice(3, fields.length, ...fields.filter(a => !a.startsWith("status=")));
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
if (argv.length > 3)
|
|
170
|
+
await taskCli(argv, env);
|
|
171
|
+
if (status)
|
|
172
|
+
requested = status;
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
log(`recorded call failed: ${error.message}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return requested;
|
|
179
|
+
}
|
|
180
|
+
async function oncebittenCheck(state, env) {
|
|
181
|
+
const bin = env.TEMMO_ONCEBITTEN_BIN || findOncebitten(env);
|
|
182
|
+
if (!bin) {
|
|
183
|
+
const lock = join(state.worktree, ".oncebitten", "rules.lock");
|
|
184
|
+
const local = join(dirname(lock), "rules.local");
|
|
185
|
+
const configured = (existsSync(local) && readdirSync(local).length > 0) || (existsSync(lock) && !/^source\s*=\s*\[\s*\]$/.test(readFileSync(lock, "utf8").trim()));
|
|
186
|
+
return configured ? { code: 2, text: "oncebitten is not installed" } : { code: 0, text: "" };
|
|
187
|
+
}
|
|
188
|
+
const res = await S.runTool(bin, ["check", "--base", state.base], { env, cwd: state.worktree, timeoutMs: GIT_TIMEOUT_MS });
|
|
189
|
+
return { code: res.code, text: oneLine(`${res.stdout} ${res.stderr}`).slice(0, 300) };
|
|
190
|
+
}
|
|
191
|
+
// Runs `temmo task ...` in-process; throws with its stderr on a non-zero exit.
|
|
192
|
+
async function taskCli(argv, env) {
|
|
193
|
+
let errText = "";
|
|
194
|
+
const sink = { write: () => true };
|
|
195
|
+
const code = await task(argv.slice(1), { env, cfg: loadConfig(env), out: sink, err: { write: (s) => { errText += s; return true; } } });
|
|
196
|
+
if (code !== 0)
|
|
197
|
+
throw new Error(oneLine(errText) || `temmo ${argv.join(" ")} exited ${code}`);
|
|
198
|
+
}
|