@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,178 @@
|
|
|
1
|
+
// Control API: HTTP/1.1 JSON over a 0600 unix socket; routes are listed in docs/owned-sessions-contract.md.
|
|
2
|
+
import http, {} from "node:http";
|
|
3
|
+
import net from "node:net";
|
|
4
|
+
import { chmodSync, mkdirSync, rmSync } from "node:fs";
|
|
5
|
+
import { dirname } from "node:path";
|
|
6
|
+
import { SESSION_LABEL } from "../lib/config.js";
|
|
7
|
+
import { HARNESSES } from "./contract.js";
|
|
8
|
+
export const MAX_REQUEST_BYTES = 64 * 1024;
|
|
9
|
+
const VERSION = 1;
|
|
10
|
+
export { runnerSocket } from "../lib/runner-request.js";
|
|
11
|
+
const fail = (status, message) => { throw Object.assign(new Error(message), { status }); };
|
|
12
|
+
// The caller label a client sends as ?caller=, reduced to 80 safe characters for the log.
|
|
13
|
+
const callerOf = (url) => String(url.searchParams.get("caller") || "").replace(/[^\w.:@/-]/g, "").slice(0, 80) || "unknown";
|
|
14
|
+
async function body(req) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
let size = 0;
|
|
17
|
+
for await (const chunk of req) {
|
|
18
|
+
size += chunk.length;
|
|
19
|
+
if (size > MAX_REQUEST_BYTES)
|
|
20
|
+
fail(413, "Request too large");
|
|
21
|
+
chunks.push(chunk);
|
|
22
|
+
}
|
|
23
|
+
if (!size)
|
|
24
|
+
return {};
|
|
25
|
+
try {
|
|
26
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
27
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
catch { /* falls through */ }
|
|
31
|
+
fail(400, "Expected a JSON object");
|
|
32
|
+
}
|
|
33
|
+
// "/v1/sessions/<harness>/<label>" parts → the session address, or a 400.
|
|
34
|
+
function address(harness, label) {
|
|
35
|
+
if (!HARNESSES.includes(harness) || !SESSION_LABEL.test(label || ""))
|
|
36
|
+
fail(400, "Invalid session address");
|
|
37
|
+
return `${harness}#${label}`;
|
|
38
|
+
}
|
|
39
|
+
/** Dispatches one request to the runner; resolves [status, value]. */
|
|
40
|
+
export async function route(runner, method, url, input) {
|
|
41
|
+
const parts = url.pathname.split("/").filter(Boolean);
|
|
42
|
+
if (parts[0] !== "v1")
|
|
43
|
+
fail(404, "Not found");
|
|
44
|
+
const [, area, a, b, action, id] = parts;
|
|
45
|
+
if (area === "health" && method === "GET")
|
|
46
|
+
return [200, { ok: true, version: VERSION, harnesses: (await runner.harnesses()).map((h) => h.harness) }];
|
|
47
|
+
if (area === "pattern-runs" && method === "POST" && !b) {
|
|
48
|
+
if (!a)
|
|
49
|
+
return [201, await runner.startPattern(input)];
|
|
50
|
+
if (a === "advance")
|
|
51
|
+
return [200, await runner.advancePattern(input)];
|
|
52
|
+
}
|
|
53
|
+
if (area === "schedules") {
|
|
54
|
+
if (!a && method === "GET")
|
|
55
|
+
return [200, await runner.schedules()];
|
|
56
|
+
if (a && b === "runs" && !action) {
|
|
57
|
+
if (method !== "GET")
|
|
58
|
+
fail(405, "Method not allowed");
|
|
59
|
+
return [200, await runner.scheduleRuns(a)];
|
|
60
|
+
}
|
|
61
|
+
if (a && b === "run" && !action) {
|
|
62
|
+
if (method !== "POST")
|
|
63
|
+
fail(405, "Method not allowed");
|
|
64
|
+
return [202, await runner.runSchedule(a, callerOf(url))];
|
|
65
|
+
}
|
|
66
|
+
fail(404, "Not found");
|
|
67
|
+
}
|
|
68
|
+
if (area === "harnesses") {
|
|
69
|
+
if (method !== "GET")
|
|
70
|
+
fail(405, "Method not allowed");
|
|
71
|
+
if (!a)
|
|
72
|
+
return [200, { harnesses: await runner.harnesses() }];
|
|
73
|
+
if (!HARNESSES.includes(a))
|
|
74
|
+
fail(400, "Unknown harness");
|
|
75
|
+
if (b === "models")
|
|
76
|
+
return [200, { models: await runner.models(a) }];
|
|
77
|
+
if (b === "commands")
|
|
78
|
+
return [200, { commands: await runner.commands(a, url.searchParams.get("project") || "") }];
|
|
79
|
+
fail(404, "Not found");
|
|
80
|
+
}
|
|
81
|
+
if (area === "deliveries") {
|
|
82
|
+
if (method !== "GET")
|
|
83
|
+
fail(405, "Method not allowed");
|
|
84
|
+
return [200, await runner.deliveries()];
|
|
85
|
+
}
|
|
86
|
+
if (area === "builder-continuations" && !a && method === "POST")
|
|
87
|
+
return [201, await runner.continueBuilder(input)];
|
|
88
|
+
// A host-side sandbox-change approval asks every harness adapter to re-put its policy on the sandboxes that exist.
|
|
89
|
+
if (area === "sandbox" && a === "reapply-policies" && !b && method === "POST")
|
|
90
|
+
return [200, await runner.reapplyPolicies()];
|
|
91
|
+
if (area !== "sessions")
|
|
92
|
+
fail(404, "Not found");
|
|
93
|
+
if (!a) {
|
|
94
|
+
if (method === "GET")
|
|
95
|
+
return [200, { sessions: runner.list() }];
|
|
96
|
+
if (method === "POST")
|
|
97
|
+
return [201, await runner.start(input)];
|
|
98
|
+
fail(405, "Method not allowed");
|
|
99
|
+
}
|
|
100
|
+
const target = address(a, b);
|
|
101
|
+
if (!action) {
|
|
102
|
+
if (method === "GET")
|
|
103
|
+
return [200, runner.get(target)];
|
|
104
|
+
if (method === "DELETE")
|
|
105
|
+
return [200, await runner.close(target)];
|
|
106
|
+
fail(405, "Method not allowed");
|
|
107
|
+
}
|
|
108
|
+
if (action === "context" && method === "GET")
|
|
109
|
+
return [200, { context: await runner.context(target) }];
|
|
110
|
+
if (method !== "POST")
|
|
111
|
+
fail(405, "Method not allowed");
|
|
112
|
+
if (action === "send")
|
|
113
|
+
return [202, await runner.send(target, { text: input.text, steer: input.steer === true })];
|
|
114
|
+
if (action === "close-child")
|
|
115
|
+
return [200, await runner.closeChild(target, input.parent)];
|
|
116
|
+
if (action === "interrupt")
|
|
117
|
+
return [202, await runner.interrupt(target)];
|
|
118
|
+
// Real in-place compaction through the harness's own trigger (Claude /compact, Codex thread/compact/start, OpenCode
|
|
119
|
+
// session.compact); 409 when the session is mid-turn, "unsupported" when the harness has no outside trigger.
|
|
120
|
+
if (action === "compact")
|
|
121
|
+
return [200, await runner.compact(target)];
|
|
122
|
+
if (action === "model")
|
|
123
|
+
return [200, await runner.setModel(target, input.model)];
|
|
124
|
+
if (action === "mode")
|
|
125
|
+
return [200, await runner.setMode(target, input.mode)];
|
|
126
|
+
if (action === "approvals" && /^[a-f0-9]{12}$/.test(id || ""))
|
|
127
|
+
return [200, await runner.respond(target, id, { decision: input.decision, ...(input.answers ? { answers: input.answers } : {}), ...(input.scope === "session" ? { scope: "session" } : {}) })];
|
|
128
|
+
fail(404, "Not found");
|
|
129
|
+
}
|
|
130
|
+
// Resolves true when something already accepts connections on the socket path.
|
|
131
|
+
function socketLive(path) {
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
const probe = net.connect(path);
|
|
134
|
+
probe.once("connect", () => { probe.destroy(); resolve(true); });
|
|
135
|
+
probe.once("error", () => resolve(false));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/** Listens on the unix socket; refuses to replace a live runner. Resolves {server, path, close}. */
|
|
139
|
+
export async function listenControl(runner, path) {
|
|
140
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
141
|
+
chmodSync(dirname(path), 0o700);
|
|
142
|
+
if (await socketLive(path))
|
|
143
|
+
throw new Error(`another runner listens on ${path}`);
|
|
144
|
+
rmSync(path, { force: true });
|
|
145
|
+
const server = http.createServer(async (req, res) => {
|
|
146
|
+
let status;
|
|
147
|
+
let value;
|
|
148
|
+
try {
|
|
149
|
+
const url = new URL(req.url, "http://runner.invalid");
|
|
150
|
+
[status, value] = await route(runner, req.method, url, ["POST", "PUT"].includes(req.method) ? await body(req) : {});
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
status = Number.isInteger(error.status) ? error.status : 500;
|
|
154
|
+
value = { error: status === 500 ? "Runner error" : error.message };
|
|
155
|
+
}
|
|
156
|
+
res.writeHead(status, { "content-type": "application/json", "cache-control": "no-store" });
|
|
157
|
+
res.end(JSON.stringify(value));
|
|
158
|
+
});
|
|
159
|
+
// The umask makes the socket 0600 from its first moment; the chmod below is the backstop.
|
|
160
|
+
const mask = process.umask(0o177);
|
|
161
|
+
try {
|
|
162
|
+
await new Promise((resolve, reject) => {
|
|
163
|
+
server.once("error", reject);
|
|
164
|
+
server.listen(path, resolve);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
finally {
|
|
168
|
+
process.umask(mask);
|
|
169
|
+
}
|
|
170
|
+
chmodSync(path, 0o600);
|
|
171
|
+
return {
|
|
172
|
+
server, path,
|
|
173
|
+
close: () => new Promise((resolve) => {
|
|
174
|
+
server.closeAllConnections();
|
|
175
|
+
server.close(() => { rmSync(path, { force: true }); resolve(); });
|
|
176
|
+
}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// Delivery workflow: one durable workflow per (session, message). It reserves, pushes, confirms and marks the message,
|
|
2
|
+
// then redelivers an expect-reply message until it is answered. Steps and sleeps are checkpointed in runner.db.
|
|
3
|
+
import { backoffMs, nextAction, REDELIVER_MS } from "../lib/delivery.js";
|
|
4
|
+
export const DELIVERY = "delivery";
|
|
5
|
+
export const READY_POLL_MS = 5000;
|
|
6
|
+
/**
|
|
7
|
+
* Builds the workflow function over deps (injectable; the live set is in runner/runner.ts):
|
|
8
|
+
* now(); scfgOf(project, session); sessionOf(project, address) -> live session or null; probe?(session) -> live-set probe, once per poll;
|
|
9
|
+
* ready(session, probe, project) -> bool; held?(session, scfg) -> bool (a Stop hook holds the session, so the push waits);
|
|
10
|
+
* handOff?(scfg, messages) (writes the messages to the session's hand-off file for that hold, lib/stop.ts; a handed message counts as delivered);
|
|
11
|
+
* handedOff?(scfg, id) -> bool (the hand-off file holds the id: a push cut by a restart after its hand-off);
|
|
12
|
+
* busy?(session, probe) -> bool (still working on an earlier push);
|
|
13
|
+
* reserve(scfg, ids, {owner, allowSeen}) -> {owned, busy}; release(scfg, ids, owner); markDelivered(scfg, ids);
|
|
14
|
+
* snapshot(session) -> JSON; push(session, {text, urgent, ids}) -> {status}; awaitConfirm(id, session, snapshot) -> bool;
|
|
15
|
+
* waitConfirmed(session, ids, snapshot) -> bool after the full confirm window; confirmedSince(session, ids, snapshot) -> bool;
|
|
16
|
+
* acked(project, address, message) -> bool; textFor(scfg, message, attempt) -> string.
|
|
17
|
+
* Optional overrides for tests: backoffMs(failures), redeliverMs, readyPollMs.
|
|
18
|
+
* Input: {project, address, message, redeliver?: {pushes, firstAt}} (redeliver resumes a message the dispatcher delivered).
|
|
19
|
+
* Output: {status} with status delivered, skipped, cut, answered, dropped or expired.
|
|
20
|
+
* The timing and attempt rules come from lib/delivery.ts nextAction.
|
|
21
|
+
*/
|
|
22
|
+
export function deliveryWorkflow(deps) {
|
|
23
|
+
const backoff = deps.backoffMs ?? backoffMs;
|
|
24
|
+
const redeliverMs = deps.redeliverMs ?? REDELIVER_MS;
|
|
25
|
+
const readyPollMs = deps.readyPollMs ?? READY_POLL_MS;
|
|
26
|
+
return async function delivery(wf, input) {
|
|
27
|
+
const { project, address, message, redeliver = null } = input;
|
|
28
|
+
const id = message.id;
|
|
29
|
+
const owner = wf.id;
|
|
30
|
+
const firstAt = await wf.step("start", () => redeliver?.firstAt ?? deps.now());
|
|
31
|
+
// The snapshot of the current push number: its retries are checked against it, so a landed copy is never sent twice.
|
|
32
|
+
let snap;
|
|
33
|
+
// The push number snap was taken for.
|
|
34
|
+
let snapFor = 0;
|
|
35
|
+
// Ms of the last redelivery wake; the next redelivery is due no earlier than this.
|
|
36
|
+
let dueAt = null;
|
|
37
|
+
const stateOf = (attemptNo) => ({ firstAt, pushes: attemptNo - 1, dueAt });
|
|
38
|
+
// nextAction on live facts for session; pollAcks false skips the ack poll.
|
|
39
|
+
async function actionFor(session, state, pollAcks) {
|
|
40
|
+
// One probe per poll, shared by ready and busy.
|
|
41
|
+
const active = session ? (await deps.probe?.(session)) ?? null : null;
|
|
42
|
+
const ready = Boolean(session) && await deps.ready(session, active, project);
|
|
43
|
+
const busy = ready && state.pushes > 0 && Boolean(await deps.busy?.(session, active));
|
|
44
|
+
// Acks matter only to a redelivery; the first push never polls them.
|
|
45
|
+
const acked = state.pushes > 0 && pollAcks && await deps.acked(project, address, message);
|
|
46
|
+
return nextAction(state, deps.now(), { acked, busy, ready });
|
|
47
|
+
}
|
|
48
|
+
// Waits, without a checkpoint, until nextAction allows a push: resolves the live session, or the action that ends the message.
|
|
49
|
+
async function target(state) {
|
|
50
|
+
for (;;) {
|
|
51
|
+
// A replayed attempt skips the probe; a push step that then runs live checks again (resumed in attempt).
|
|
52
|
+
if (wf.replaying) {
|
|
53
|
+
const replayed = deps.sessionOf(project, address);
|
|
54
|
+
if (replayed)
|
|
55
|
+
return replayed;
|
|
56
|
+
}
|
|
57
|
+
const session = deps.sessionOf(project, address);
|
|
58
|
+
const action = await actionFor(session, state, !wf.replaying);
|
|
59
|
+
if (action === "push")
|
|
60
|
+
return session;
|
|
61
|
+
if (action !== "wait")
|
|
62
|
+
return action;
|
|
63
|
+
await wf.pause(readyPollMs);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// One push attempt. Resolves "delivered", "failed" (retry after backoff), "cut" (never sent again), "skipped", "expired", "dropped" or "answered".
|
|
67
|
+
async function attempt(attemptNo, { allowSeen }) {
|
|
68
|
+
// A restart inside this attempt: target() and the answer re-check below skip their live checks.
|
|
69
|
+
const resumed = wf.replaying;
|
|
70
|
+
const session = await target(stateOf(attemptNo));
|
|
71
|
+
if (typeof session === "string")
|
|
72
|
+
return session;
|
|
73
|
+
const scfg = deps.scfgOf(project, session);
|
|
74
|
+
if (snap === undefined) {
|
|
75
|
+
snap = await wf.step("snapshot", () => deps.snapshot(session));
|
|
76
|
+
snapFor = attemptNo;
|
|
77
|
+
}
|
|
78
|
+
if (attemptNo > 1) {
|
|
79
|
+
const fresh = snapFor !== attemptNo;
|
|
80
|
+
// A new push number's recheck takes its snapshot; a retry checks copies since it; an older run's recorded boolean replays as before.
|
|
81
|
+
const r = await wf.step("recheck", async () => fresh ? { snapshot: await deps.snapshot(session) } : deps.confirmedSince(session, [id], snap));
|
|
82
|
+
snapFor = attemptNo;
|
|
83
|
+
if (r === true) {
|
|
84
|
+
await wf.step("mark", () => deps.markDelivered(scfg, [id]));
|
|
85
|
+
return "delivered";
|
|
86
|
+
}
|
|
87
|
+
if (r !== false)
|
|
88
|
+
snap = r.snapshot;
|
|
89
|
+
}
|
|
90
|
+
// A redelivery re-checks the answer before reserving, so an answer seen while waiting never gets a copy.
|
|
91
|
+
if (attemptNo > 1 && !wf.replaying && await deps.acked(project, address, message))
|
|
92
|
+
return "answered";
|
|
93
|
+
const got = await wf.step("reserve", () => deps.reserve(scfg, [id], { owner, allowSeen }));
|
|
94
|
+
if (got.busy)
|
|
95
|
+
return "failed";
|
|
96
|
+
if (!got.owned.length)
|
|
97
|
+
return "skipped";
|
|
98
|
+
const current = deps.reservedMessage ? deps.reservedMessage(scfg, message) : message;
|
|
99
|
+
if (!current)
|
|
100
|
+
return "skipped";
|
|
101
|
+
const text = await Promise.resolve().then(() => deps.textFor(scfg, current, attemptNo));
|
|
102
|
+
// A Stop hook that started since the ready check delivers the message itself; the check runs inside the step so replays match.
|
|
103
|
+
const pushed = await wf.step("push", async () => {
|
|
104
|
+
// A resumed attempt whose push never ran checks now: an answer or busy target during the restart gets no copy.
|
|
105
|
+
if (resumed) {
|
|
106
|
+
const action = await actionFor(session, stateOf(attemptNo), true);
|
|
107
|
+
if (action !== "push")
|
|
108
|
+
return { status: action === "wait" ? "unsent" : action };
|
|
109
|
+
}
|
|
110
|
+
if (!(await deps.held?.(session, scfg)))
|
|
111
|
+
return deps.push(session, { text, urgent: current.urgent === true, ids: [id] });
|
|
112
|
+
// The hold reads the hand-off file every second and the mark step hides the inbox copy; a failed hand-off retries.
|
|
113
|
+
if (!deps.handOff)
|
|
114
|
+
return { status: "held" };
|
|
115
|
+
return Promise.resolve().then(() => deps.handOff(scfg, [current])).then(() => ({ status: "handed" }), () => ({ status: "held" }));
|
|
116
|
+
}, {
|
|
117
|
+
// A restart after the hand-off but before the checkpoint finds the id in the hand-off file.
|
|
118
|
+
onCut: async () => ({ status: deps.handedOff?.(scfg, id) ? "handed" : await deps.waitConfirmed(session, [id], snap) ? "delivered" : "cut" }),
|
|
119
|
+
});
|
|
120
|
+
if (pushed.status === "delivered" || pushed.status === "handed") {
|
|
121
|
+
await wf.step("mark", () => deps.markDelivered(scfg, [id]));
|
|
122
|
+
return "delivered";
|
|
123
|
+
}
|
|
124
|
+
if (["cut", "unsent", "held", "answered", "expired", "dropped"].includes(pushed.status)) {
|
|
125
|
+
await wf.step("release", () => deps.release(scfg, [id], owner));
|
|
126
|
+
return pushed.status === "unsent" || pushed.status === "held" ? "failed" : pushed.status;
|
|
127
|
+
}
|
|
128
|
+
// Unconfirmed: renew the reservation for the watch, then wait for the write to show in the transcript.
|
|
129
|
+
await wf.step("renew", () => deps.reserve(scfg, [id], { owner, allowSeen: true }));
|
|
130
|
+
const c = await wf.step("confirm", () => deps.awaitConfirm(id, session, snap).then((confirmed) => ({ confirmed, cut: false })), {
|
|
131
|
+
onCut: async () => ({ confirmed: await deps.waitConfirmed(session, [id], snap), cut: true }),
|
|
132
|
+
});
|
|
133
|
+
if (c.confirmed) {
|
|
134
|
+
await wf.step("mark", () => deps.markDelivered(scfg, [id]));
|
|
135
|
+
return "delivered";
|
|
136
|
+
}
|
|
137
|
+
if (c.cut) {
|
|
138
|
+
await wf.step("release", () => deps.release(scfg, [id], owner));
|
|
139
|
+
return "cut";
|
|
140
|
+
}
|
|
141
|
+
if (await wf.step("late", () => deps.confirmedSince(session, [id], snap))) {
|
|
142
|
+
await wf.step("mark", () => deps.markDelivered(scfg, [id]));
|
|
143
|
+
return "delivered";
|
|
144
|
+
}
|
|
145
|
+
await wf.step("release", () => deps.release(scfg, [id], owner));
|
|
146
|
+
return "failed";
|
|
147
|
+
}
|
|
148
|
+
// Attempts until delivered, skipped, cut or past the TTL; a failed attempt waits a durable backoff first.
|
|
149
|
+
async function deliver(attemptNo, opts) {
|
|
150
|
+
for (let failures = 0;;) {
|
|
151
|
+
const outcome = await attempt(attemptNo, opts);
|
|
152
|
+
if (outcome !== "failed")
|
|
153
|
+
return outcome;
|
|
154
|
+
failures += 1;
|
|
155
|
+
await wf.sleep(backoff(failures));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let pushes = redeliver?.pushes ?? 0;
|
|
159
|
+
if (!redeliver) {
|
|
160
|
+
const first = await deliver(1, { allowSeen: false });
|
|
161
|
+
if (first !== "delivered")
|
|
162
|
+
return { status: first };
|
|
163
|
+
if (message.expectReply !== true)
|
|
164
|
+
return { status: "delivered", pushes: 1 };
|
|
165
|
+
pushes = 1;
|
|
166
|
+
}
|
|
167
|
+
// Redelivery: after each redeliverMs without an answer, push again, at most MAX_ATTEMPTS pushes in all.
|
|
168
|
+
for (;;) {
|
|
169
|
+
await wf.sleep(redeliverMs);
|
|
170
|
+
// The durable sleep has just run out, so the redelivery is due: dueAt is the wake time.
|
|
171
|
+
dueAt = deps.now();
|
|
172
|
+
const acked = await wf.step("acked", () => deps.acked(project, address, message));
|
|
173
|
+
// Ready and busy are decided on each poll in target(); here only the answer, TTL and attempt cap can end the message.
|
|
174
|
+
const wake = nextAction(stateOf(pushes + 1), deps.now(), { acked, busy: false, ready: true });
|
|
175
|
+
if (wake !== "push")
|
|
176
|
+
return { status: wake, pushes };
|
|
177
|
+
const outcome = await deliver(pushes + 1, { allowSeen: true });
|
|
178
|
+
if (["answered", "expired", "cut", "dropped"].includes(outcome))
|
|
179
|
+
return { status: outcome, pushes };
|
|
180
|
+
if (outcome === "delivered")
|
|
181
|
+
pushes += 1;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Scheduled factory tick: node runner/factory-tick.mjs, run from the project root (schedules.json cwd).
|
|
3
|
+
import { loadConfig } from "../lib/config.js";
|
|
4
|
+
import { factoryTick } from "../lib/factory-tick.js";
|
|
5
|
+
import { runnerClient } from "./client.js";
|
|
6
|
+
const cfg = loadConfig(process.env, { cwd: process.cwd(), host: "operator" });
|
|
7
|
+
if (!cfg.enabled)
|
|
8
|
+
throw Error(`Temmo project registration is unavailable: ${cfg.reason ?? process.cwd()}`);
|
|
9
|
+
for (const line of await factoryTick({ cfg, root: process.cwd(), runner: runnerClient({ timeoutMs: 300_000 }) }))
|
|
10
|
+
console.log(line);
|
package/runner/lock.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Single-instance lock: a pid file beside the workflow log, replaced only when its process is gone.
|
|
2
|
+
import { closeSync, openSync, readFileSync, rmSync, writeSync } from "node:fs";
|
|
3
|
+
const alive = (pid) => {
|
|
4
|
+
if (!Number.isInteger(pid) || pid < 1)
|
|
5
|
+
return false;
|
|
6
|
+
try {
|
|
7
|
+
process.kill(pid, 0);
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
return error.code === "EPERM";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
/** Takes the lock at file; throws while another live runner holds it. Resolves to a release function. */
|
|
15
|
+
export function acquireLock(file) {
|
|
16
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
17
|
+
try {
|
|
18
|
+
const fd = openSync(file, "wx", 0o600);
|
|
19
|
+
writeSync(fd, `${process.pid}\n`);
|
|
20
|
+
closeSync(fd);
|
|
21
|
+
return () => rmSync(file, { force: true });
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error.code !== "EEXIST")
|
|
25
|
+
throw error;
|
|
26
|
+
let pid;
|
|
27
|
+
try {
|
|
28
|
+
pid = Number(readFileSync(file, "utf8").trim());
|
|
29
|
+
}
|
|
30
|
+
catch (readError) {
|
|
31
|
+
if (readError.code === "ENOENT")
|
|
32
|
+
continue; // released between the two calls
|
|
33
|
+
throw readError;
|
|
34
|
+
}
|
|
35
|
+
if (alive(pid))
|
|
36
|
+
throw new Error(`another runner holds ${file} (pid ${pid})`);
|
|
37
|
+
rmSync(file, { force: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`cannot take ${file}`);
|
|
41
|
+
}
|
package/runner/main.mjs
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
11
|
+
// temmo-runner entry: loads projects and adapters, recovers durable sessions, serves the control socket.
|
|
12
|
+
import { existsSync, mkdirSync, realpathSync } from "node:fs";
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { loadProjects, stateDir, autoDefaults, autoDeployEnabled } from "../lib/config.js";
|
|
16
|
+
import { autoDeployEntry } from "../lib/land.js";
|
|
17
|
+
import { HARNESSES } from "./contract.js";
|
|
18
|
+
import { openWorkflows } from "../lib/workflows.js";
|
|
19
|
+
import { pgUrl } from "../lib/postgres.js";
|
|
20
|
+
import { createRunner } from "./runner.js";
|
|
21
|
+
import { listenControl, runnerSocket } from "./control.js";
|
|
22
|
+
import { loadSchedules, registerSchedules } from "./schedules.js";
|
|
23
|
+
import { reflectEnabled, reflectEveryMs, reflectTick, SWEEP_STEP } from "../lib/reflect.js";
|
|
24
|
+
import { startTaskWakes } from "./task-wake.js";
|
|
25
|
+
import { acquireLock } from "./lock.js";
|
|
26
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
27
|
+
/** The durable log path: TEMMO_RUNNER_DB, else <state dir>/runner.db. */
|
|
28
|
+
export const runnerDb = (env = process.env) => env.TEMMO_RUNNER_DB || join(stateDir(env), "runner.db");
|
|
29
|
+
/** Imports runner/adapters/<harness>.ts (.js in the built package, else .mjs) for each name; a missing module is skipped and reported. */
|
|
30
|
+
export async function loadAdapters(names, { dir = join(HERE, "adapters"), env = process.env, log = () => { } } = {}) {
|
|
31
|
+
const adapters = new Map();
|
|
32
|
+
for (const harness of names) {
|
|
33
|
+
if (!HARNESSES.includes(harness)) {
|
|
34
|
+
log(`unknown harness ${harness}`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let factory;
|
|
38
|
+
try {
|
|
39
|
+
const file = [".ts", ".js"].map((ext) => join(dir, harness + ext)).find((path) => existsSync(path)) ?? join(dir, `${harness}.mjs`);
|
|
40
|
+
({ default: factory } = await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code === "ERR_MODULE_NOT_FOUND") {
|
|
44
|
+
log(`no ${harness} adapter yet`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
const adapter = factory({ env, stateDir: stateDir(env) });
|
|
50
|
+
if (adapter?.harness !== harness)
|
|
51
|
+
throw new Error(`adapters/${harness}.mjs returned no ${harness} adapter`);
|
|
52
|
+
adapters.set(harness, adapter);
|
|
53
|
+
}
|
|
54
|
+
return adapters;
|
|
55
|
+
}
|
|
56
|
+
/** Runs the service until SIGTERM or SIGINT. */
|
|
57
|
+
export async function main(env = process.env) {
|
|
58
|
+
const log = (message) => process.stderr.write(`temmo-runner: ${message}\n`);
|
|
59
|
+
// "runner" names only the base config; sessions publish as their harness.
|
|
60
|
+
const projects = loadProjects(env, { host: "runner" });
|
|
61
|
+
if (!projects.length)
|
|
62
|
+
log("no enabled project; serving the control socket only");
|
|
63
|
+
const names = env.TEMMO_RUNNER_HARNESSES === "none" ? [] : String(env.TEMMO_RUNNER_HARNESSES || HARNESSES.join(",")).split(",").map((s) => s.trim()).filter(Boolean);
|
|
64
|
+
const adapters = await loadAdapters(names, { dir: env.TEMMO_RUNNER_ADAPTER_DIR || join(HERE, "adapters"), env, log });
|
|
65
|
+
const db = runnerDb(env);
|
|
66
|
+
mkdirSync(dirname(db), { recursive: true, mode: 0o700 });
|
|
67
|
+
const release = acquireLock(join(dirname(db), "runner.lock"));
|
|
68
|
+
let durable;
|
|
69
|
+
let runner;
|
|
70
|
+
let control;
|
|
71
|
+
try {
|
|
72
|
+
// "dbos" runs the workflows on Postgres (temmo postgres up); the sqlite durable log stays the default.
|
|
73
|
+
const engine = env.TEMMO_WORKFLOW_ENGINE || autoDefaults(env)?.workflowEngine || "sqlite";
|
|
74
|
+
durable = await openWorkflows({ engine, file: db, log, ...(engine === "dbos" ? { pgUrl: pgUrl(env) } : {}) });
|
|
75
|
+
// Registered before boot so PENDING ticks recover with the sessions; invalid entries are reported, not fatal.
|
|
76
|
+
const { entries: configured, errors } = loadSchedules(env);
|
|
77
|
+
// The auto-deploy schedule exists only when autoDeploy is on (TEMMO_AUTO_DEPLOY or defaults.json).
|
|
78
|
+
const entries = autoDeployEnabled(env) ? [...configured, autoDeployEntry()] : configured;
|
|
79
|
+
for (const error of errors)
|
|
80
|
+
log(`schedule skipped: ${error}`);
|
|
81
|
+
const schedules = registerSchedules(durable, entries, { env, log });
|
|
82
|
+
// The Harness² reflector sweeps ended sessions into the lesson library (lib/reflect.ts, docs/harness-improvement.md).
|
|
83
|
+
if (reflectEnabled(env)) {
|
|
84
|
+
durable.scheduled("reflect", { everyMs: reflectEveryMs(env), firstStep: SWEEP_STEP }, reflectTick({ env, log }));
|
|
85
|
+
schedules.push("reflect");
|
|
86
|
+
}
|
|
87
|
+
runner = createRunner({ projects, adapters, durable, env, log, scheduleErrors: errors, scheduleEntries: entries });
|
|
88
|
+
const recovered = await runner.boot();
|
|
89
|
+
// Serve the socket before any tick can start, so a failed bind starts nothing.
|
|
90
|
+
control = await listenControl(runner, runnerSocket(env));
|
|
91
|
+
await durable.startSchedules();
|
|
92
|
+
startTaskWakes(entries, runner, { env, log });
|
|
93
|
+
log(`listening on ${control.path}; adapters ${[...adapters.keys()].join(", ") || "none"}; recovered ${recovered.length} session(s); schedules ${schedules.join(", ") || "none"}`);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
await control?.close();
|
|
97
|
+
if (runner)
|
|
98
|
+
await runner.stop();
|
|
99
|
+
else
|
|
100
|
+
await durable?.close();
|
|
101
|
+
release();
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
let stopping = false;
|
|
105
|
+
const shutdown = async () => {
|
|
106
|
+
if (stopping)
|
|
107
|
+
return;
|
|
108
|
+
stopping = true;
|
|
109
|
+
await control.close();
|
|
110
|
+
await runner.stop();
|
|
111
|
+
release();
|
|
112
|
+
process.exit(0);
|
|
113
|
+
};
|
|
114
|
+
process.on("SIGTERM", shutdown);
|
|
115
|
+
process.on("SIGINT", shutdown);
|
|
116
|
+
}
|
|
117
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)))
|
|
118
|
+
await main();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Scheduled pattern tick: node runner/pattern-tick.mjs <pattern> <task> [--check]. Run from the project root (schedules.json cwd).
|
|
3
|
+
import { loadConfig } from "../lib/config.js";
|
|
4
|
+
import { patternTick } from "../lib/pattern-tick.js";
|
|
5
|
+
import { runnerClient } from "./client.js";
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const check = args.includes("--check");
|
|
8
|
+
const [pattern, task] = args.filter((arg) => arg !== "--check");
|
|
9
|
+
if (!pattern || !task) {
|
|
10
|
+
console.error("usage: pattern-tick.mjs <pattern> <task> [--check]");
|
|
11
|
+
process.exit(2);
|
|
12
|
+
}
|
|
13
|
+
const cfg = loadConfig(process.env, { cwd: process.cwd(), host: "operator" });
|
|
14
|
+
if (!cfg.enabled)
|
|
15
|
+
throw Error(`Temmo project registration is unavailable: ${cfg.reason ?? process.cwd()}`);
|
|
16
|
+
console.log(await patternTick({ cfg, pattern, task, check, runner: runnerClient({ timeoutMs: 300_000 }) }));
|