@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,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Runs one agent harness command inside a fresh OpenShell sandbox and lands its commits on the host; schedules.json
|
|
3
|
+
// entries with "sandbox": true run through it. Usage: sandbox-run.mjs --name N --cwd DIR [--project P] -- <argv...>
|
|
4
|
+
//
|
|
5
|
+
// Staging follows lib/builder.ts: a clone of cwd's branch, node, git, the temmo CLI and the harness install go
|
|
6
|
+
// in by upload; the bus is reachable at host.openshell.internal:8794; the clone comes back by download, uncommitted work
|
|
7
|
+
// becomes one commit, and new commits land on branch sandbox/<name>-<stamp> in cwd's repository. The sandbox is
|
|
8
|
+
// deleted at the end, also after a timeout (SIGTERM from the schedule).
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { basename, dirname, join } from "node:path";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { agentHarness } from "../lib/agent-guard.js";
|
|
15
|
+
import { listProjects, stateDir } from "../lib/config.js";
|
|
16
|
+
import { builderPolicy, replayable, parseRecordedCall, toolSources } from "../lib/builder.js";
|
|
17
|
+
import { busMcpServer, NODE_IN, stageApp, stageBusConfig } from "../lib/sandbox-app.js";
|
|
18
|
+
import { projectOfFolder } from "../lib/schedule-session.js";
|
|
19
|
+
import { stageToolchain } from "../lib/sandbox-tools.js";
|
|
20
|
+
import { destroyOwnedSandboxes, execArgv, executables, gitIn, HOME_IN, hostTokenFile, labelArgs, landBranch, must, NTFY_TOKEN_IN, OUT, runTool, sandboxCapRefusal, sandboxLabels, SANDBOX, stageAndUpload, TOOLS, UPLOAD_TIMEOUT_MS, WORK } from "../lib/sandbox.js";
|
|
21
|
+
const APP_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
22
|
+
const CLI = join(APP_ROOT, "scripts", "temmo.mjs");
|
|
23
|
+
const APP_IN = `${TOOLS}/temmo`;
|
|
24
|
+
const SANDBOX_PATH = `${TOOLS}/bin:${TOOLS}/node/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`;
|
|
25
|
+
const NAME_PREFIX_MAX = 8;
|
|
26
|
+
// Per harness: where its install goes, the launcher inside it, and where its login lives in the sandbox home.
|
|
27
|
+
const LAYOUTS = {
|
|
28
|
+
cursor: { dir: "/sandbox/agent", launcher: "/cursor-agent", name: "cursor-agent", authDir: `${HOME_IN}/.config/cursor`, tree: (src) => src.cursorTree, auth: (src) => src.cursorAuth },
|
|
29
|
+
codex: { dir: "/sandbox/codex", launcher: "/bin/codex", name: "codex", authDir: `${HOME_IN}/.codex`, tree: (src) => src.codexTree, auth: (src) => src.codexAuth },
|
|
30
|
+
opencode: { dir: "/sandbox/opencode", launcher: "", name: "opencode", file: true, authDir: `${HOME_IN}/.local/share/opencode`, tree: (src) => src.opencodeBin, auth: (src) => src.opencodeAuth },
|
|
31
|
+
claude: { dir: "/sandbox/claude", launcher: "", name: "claude", file: true, authDir: `${HOME_IN}/.claude`, tree: (src) => src.claudeBin, auth: (src) => src.claudeAuth },
|
|
32
|
+
};
|
|
33
|
+
// The CLI marks itself non-dumpable unless this is set; OpenShell then denies its sockets (lib/builder.ts).
|
|
34
|
+
const HARNESS_ENV = { cursor: { CURSOR_AGENT_ALLOW_PROCESS_INSPECTION: "1" } };
|
|
35
|
+
// Inside the sandbox: task writes are recorded for the host, builder commands are refused, the rest is the real CLI.
|
|
36
|
+
const CLI_SHIM = `#!/bin/sh
|
|
37
|
+
case "$1 $2" in
|
|
38
|
+
"task list"|"task show"|"task outcomes") ;;
|
|
39
|
+
task\\ *) d="\${TEMMO_SANDBOX_OUT:-${OUT}}/temmo"; mkdir -p "$d" || exit 1; printf '%s\\0' "$@" > "$d/$(date +%s%N)-$$"
|
|
40
|
+
echo "temmo: recorded; the host applies supported task commands when this run ends"; exit 0 ;;
|
|
41
|
+
builder\\ *) echo "temmo: builder commands work on the host only" >&2; exit 2 ;;
|
|
42
|
+
esac
|
|
43
|
+
exec ${NODE_IN} ${APP_IN}/scripts/temmo.mjs "$@"
|
|
44
|
+
`;
|
|
45
|
+
const git = (cwd, args, env) => gitIn(env)(cwd, args);
|
|
46
|
+
/** The sandbox name for one schedule run: s-<first 8 of the name>-<6 hex>, at most 17 characters. */
|
|
47
|
+
export function runSandboxName(name, at = Date.now()) {
|
|
48
|
+
const hash = createHash("sha256").update(`${name}@${at}`).digest("hex").slice(0, 6);
|
|
49
|
+
return `s-${String(name).slice(0, NAME_PREFIX_MAX).replace(/-+$/, "")}-${hash}`;
|
|
50
|
+
}
|
|
51
|
+
/** The argv to run inside the sandbox: the harness binary replaced by its launcher's name, every other element kept. */
|
|
52
|
+
export function sandboxCommand(argv) {
|
|
53
|
+
const harness = agentHarness(argv);
|
|
54
|
+
if (!harness)
|
|
55
|
+
throw new Error(`a sandboxed schedule runs an agent harness (claude, codex, cursor-agent, opencode), not ${basename(String(argv?.[0] ?? ""))}`);
|
|
56
|
+
// By name: the exec env's PATH starts with /sandbox/tools/bin, where the launcher link lives (as lib/builder.ts runs it).
|
|
57
|
+
return [LAYOUTS[harness].name, ...argv.slice(1)];
|
|
58
|
+
}
|
|
59
|
+
/** Parses `--name N --cwd DIR [--project P] -- argv...`; throws on anything else. */
|
|
60
|
+
export function parseArgs(args) {
|
|
61
|
+
const at = args.indexOf("--");
|
|
62
|
+
if (at < 0 || at === args.length - 1)
|
|
63
|
+
throw new Error("usage: sandbox-run.mjs --name N --cwd DIR [--project P] -- <command...>");
|
|
64
|
+
const flags = {};
|
|
65
|
+
for (let i = 0; i < at; i += 2) {
|
|
66
|
+
if (!["--name", "--cwd", "--project"].includes(args[i]) || i + 1 >= at)
|
|
67
|
+
throw new Error(`unknown option ${args[i]}`);
|
|
68
|
+
flags[args[i].slice(2)] = args[i + 1];
|
|
69
|
+
}
|
|
70
|
+
if (!flags.name || !flags.cwd)
|
|
71
|
+
throw new Error("--name and --cwd are required");
|
|
72
|
+
return { ...flags, command: args.slice(at + 1) };
|
|
73
|
+
}
|
|
74
|
+
/** Builds the host-side staging: the clone, the tools tree, the sandbox home and the policy. */
|
|
75
|
+
export async function stage({ cwd, project, harness, dir, env, log }) {
|
|
76
|
+
const clone = join(dir, basename(cwd));
|
|
77
|
+
const branch = (await git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"], env)).trim();
|
|
78
|
+
await must("git", ["clone", "--quiet", "--no-hardlinks", ...(branch !== "HEAD" ? ["--branch", branch] : []), cwd, clone], { env, timeoutMs: UPLOAD_TIMEOUT_MS, what: "git clone", errorPrefix: "", stdoutFallback: true });
|
|
79
|
+
await git(clone, ["remote", "remove", "origin"], env);
|
|
80
|
+
for (const key of ["user.name", "user.email"]) {
|
|
81
|
+
const value = (await runTool("git", ["-C", cwd, "config", key], { env })).stdout.trim();
|
|
82
|
+
if (value)
|
|
83
|
+
await git(clone, ["config", key, value], env);
|
|
84
|
+
}
|
|
85
|
+
const base = (await git(clone, ["rev-parse", "HEAD"], env)).trim();
|
|
86
|
+
const src = toolSources({ harness, root: cwd }, env);
|
|
87
|
+
const layout = LAYOUTS[harness];
|
|
88
|
+
const tree = layout.tree(src);
|
|
89
|
+
if (!tree)
|
|
90
|
+
throw new Error(`no ${harness} install found on the host`);
|
|
91
|
+
if (!src.node)
|
|
92
|
+
throw new Error("no node found on the host for the temmo CLI");
|
|
93
|
+
const tools = join(dir, "tools");
|
|
94
|
+
mkdirSync(join(tools, "bin"), { recursive: true });
|
|
95
|
+
writeFileSync(join(tools, "bin", "temmo"), CLI_SHIM, { mode: 0o755 });
|
|
96
|
+
// The common toolchain as every sandbox stages it (lib/sandbox-tools.ts).
|
|
97
|
+
const toolchain = await stageToolchain(dir, env, log);
|
|
98
|
+
stageApp(tools);
|
|
99
|
+
const inTree = `${layout.dir}/${basename(tree)}`;
|
|
100
|
+
// Relative, so the link resolves wherever the sandbox root is mounted.
|
|
101
|
+
symlinkSync(`../..${inTree.slice(SANDBOX.length)}${layout.launcher}`, join(tools, "bin", layout.name));
|
|
102
|
+
const workdir = `${WORK}/${basename(cwd)}`;
|
|
103
|
+
const home = join(dir, "home");
|
|
104
|
+
const token = hostTokenFile(env);
|
|
105
|
+
stageBusConfig(home, { project, root: workdir, token: Boolean(token) });
|
|
106
|
+
// The temmo MCP server, so set_identity, send_to_all and ask_question reach the operator over the bus.
|
|
107
|
+
const mcp = busMcpServer({ project, peer: harness });
|
|
108
|
+
if (harness === "cursor") {
|
|
109
|
+
mkdirSync(join(home, ".cursor"), { recursive: true });
|
|
110
|
+
writeFileSync(join(home, ".cursor", "mcp.json"), `${JSON.stringify({ mcpServers: { "temmo": mcp } }, null, 2)}\n`);
|
|
111
|
+
}
|
|
112
|
+
if (harness === "claude")
|
|
113
|
+
writeFileSync(join(home, ".claude.json"), `${JSON.stringify({ mcpServers: { "temmo": { type: "stdio", ...mcp } } }, null, 2)}\n`);
|
|
114
|
+
// A snapshot of the project's tasks, so `temmo task list|show` answer from the host's state as of the start.
|
|
115
|
+
const tasks = join(env.XDG_DATA_HOME || join(env.HOME || "", ".local", "share"), "temmo", "tasks", `${project}.json`);
|
|
116
|
+
if (project && existsSync(tasks)) {
|
|
117
|
+
mkdirSync(join(home, ".local", "share", "temmo", "tasks"), { recursive: true });
|
|
118
|
+
copyFileSync(tasks, join(home, ".local", "share", "temmo", "tasks", basename(tasks)));
|
|
119
|
+
}
|
|
120
|
+
const binaries = layout.file ? [inTree] : executables(harness === "codex" ? join(tree, "bin") : tree).map((f) => `${inTree}${harness === "codex" ? "/bin" : ""}/${f}`);
|
|
121
|
+
const policy = join(dir, "policy.yaml");
|
|
122
|
+
writeFileSync(policy, `${JSON.stringify(builderPolicy({ harness, binaries, ntfyBinaries: [NODE_IN] }), null, 2)}\n`);
|
|
123
|
+
const execEnv = {
|
|
124
|
+
HOME: HOME_IN, XDG_CONFIG_HOME: `${HOME_IN}/.config`, XDG_DATA_HOME: `${HOME_IN}/.local/share`, XDG_STATE_HOME: `${HOME_IN}/.local/state`,
|
|
125
|
+
CODEX_HOME: `${HOME_IN}/.codex`, PATH: SANDBOX_PATH, TMPDIR: "/tmp", TEMMO_SANDBOX_OUT: OUT, ...(project ? { TEMMO_PROJECT: project } : {}),
|
|
126
|
+
...(src.gitCore ? { GIT_EXEC_PATH: `${TOOLS}/git-core` } : {}), ...(toolchain.libs.length ? { LD_LIBRARY_PATH: `${TOOLS}/lib` } : {}),
|
|
127
|
+
...(HARNESS_ENV[harness] ?? {}),
|
|
128
|
+
};
|
|
129
|
+
return { clone, base, branch, tools, home, src, layout, tree, token, workdir, policy, execEnv };
|
|
130
|
+
}
|
|
131
|
+
// The host paths stageAndUpload sends, npm included, so a scheduled run has the common tools (lib/sandbox-tools.ts).
|
|
132
|
+
function uploadPaths(staged) {
|
|
133
|
+
return { clone: staged.clone, tools: staged.tools, home: staged.home, workdir: staged.workdir, node: staged.src.node, gitCore: staged.src.gitCore, npm: staged.src.npm, nodeModules: staged.src.nodeModules, ntfyToken: staged.token };
|
|
134
|
+
}
|
|
135
|
+
// The harness layout stageAndUpload uses: its tree and login as this run resolved them.
|
|
136
|
+
function uploadLayout(staged) {
|
|
137
|
+
const { layout, src } = staged;
|
|
138
|
+
return { dir: layout.dir, file: layout.file, tree: staged.tree, auth: layout.auth(src), authDir: layout.authDir };
|
|
139
|
+
}
|
|
140
|
+
/** Replays supported task calls through the host CLI; others are logged and dropped. */
|
|
141
|
+
export async function replayTasks({ dir, project, env, log, name }) {
|
|
142
|
+
const recorded = join(dir, "out", "temmo");
|
|
143
|
+
if (!existsSync(recorded))
|
|
144
|
+
return 0;
|
|
145
|
+
let count = 0;
|
|
146
|
+
for (const file of readdirSync(recorded).sort()) {
|
|
147
|
+
const argv = parseRecordedCall(readFileSync(join(recorded, file), "utf8"));
|
|
148
|
+
const outcome = name === "pm" && argv[0] === "task" && ["propose-outcome", "report-outcome"].includes(argv[1]);
|
|
149
|
+
if (!outcome && !replayable(argv)) {
|
|
150
|
+
log(`dropped recorded call: ${argv.slice(0, 2).join(" ")}`);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const out = await runTool(process.execPath, [CLI, ...argv], { env: { ...env, TEMMO_PROJECT: project } });
|
|
154
|
+
if (out.code === 0)
|
|
155
|
+
count += 1;
|
|
156
|
+
else
|
|
157
|
+
log(`recorded call failed: ${(out.stderr || "").trim()}`);
|
|
158
|
+
}
|
|
159
|
+
return count;
|
|
160
|
+
}
|
|
161
|
+
/** Runs one command in a fresh sandbox; resolves the harness's exit code. */
|
|
162
|
+
export async function sandboxRun({ name, cwd, project, command }, { env = process.env, log = (line) => process.stderr.write(`sandbox-run ${name}: ${line}\n`), stdout = process.stdout, stderr = process.stderr } = {}) {
|
|
163
|
+
const harness = agentHarness(command);
|
|
164
|
+
const inner = sandboxCommand(command);
|
|
165
|
+
if (!existsSync(join(cwd, ".git")))
|
|
166
|
+
throw new Error(`${cwd} is not a git work tree; a sandboxed run needs one to land its commits`);
|
|
167
|
+
const openshell = env.TEMMO_OPENSHELL_BIN || "openshell";
|
|
168
|
+
const proj = project || projectOfFolder(cwd, listProjects(env));
|
|
169
|
+
// Over the cap a tick is skipped, not failed: the next tick tries again.
|
|
170
|
+
const capped = await sandboxCapRefusal({ openshell, env, log });
|
|
171
|
+
if (capped) {
|
|
172
|
+
log(`skipped: ${capped}; the next tick tries again`);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
mkdirSync(stateDir(env), { recursive: true, mode: 0o700 });
|
|
176
|
+
const dir = mkdtempSync(join(stateDir(env), "sandbox-run-"));
|
|
177
|
+
let keep = false;
|
|
178
|
+
const sandbox = runSandboxName(name);
|
|
179
|
+
let child = null;
|
|
180
|
+
let stopping = false;
|
|
181
|
+
const onTerm = () => { stopping = true; child?.kill("SIGTERM"); };
|
|
182
|
+
process.once("SIGTERM", onTerm);
|
|
183
|
+
process.once("SIGINT", onTerm);
|
|
184
|
+
let created = false;
|
|
185
|
+
try {
|
|
186
|
+
const staged = await stage({ cwd, project: proj, harness, dir: join(dir, "stage"), env, log });
|
|
187
|
+
await must(openshell, ["sandbox", "create", "--name", sandbox, "--no-tty", "--detach", "--policy", staged.policy, ...labelArgs(sandboxLabels({ project: proj, kind: "run", owner: name }))], { env, timeoutMs: UPLOAD_TIMEOUT_MS, what: "sandbox create", errorPrefix: "", stdoutFallback: true });
|
|
188
|
+
created = true;
|
|
189
|
+
log(`sandbox ${sandbox} created`);
|
|
190
|
+
await stageAndUpload({
|
|
191
|
+
openshell, env, sandbox, log, staged: uploadPaths(staged), layout: uploadLayout(staged),
|
|
192
|
+
style: { errorPrefix: "", stdoutFallback: true }, authMissing: `no host ${harness} login found; the harness will ask to log in`, secretTmp: "temmo-sandbox-run-auth-",
|
|
193
|
+
logins: { home: env.HOME, remoteHome: HOME_IN },
|
|
194
|
+
});
|
|
195
|
+
let code = 143;
|
|
196
|
+
if (!stopping) {
|
|
197
|
+
const argv = execArgv({ openshell, sandbox, workdir: staged.workdir, env: staged.execEnv, command: inner });
|
|
198
|
+
log(`running ${harness} in ${staged.workdir}`);
|
|
199
|
+
child = spawn(argv[0], argv.slice(1), { env, stdio: ["ignore", "pipe", "pipe"] });
|
|
200
|
+
child.stdout.on("data", (chunk) => stdout.write(chunk));
|
|
201
|
+
child.stderr.on("data", (chunk) => stderr.write(chunk));
|
|
202
|
+
code = await new Promise((resolve) => { child.once("error", () => resolve(127)); child.once("close", (c) => resolve(c ?? 143)); });
|
|
203
|
+
child = null;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
await landBranch({ openshell, env, sandbox, cwd, name, workdir: staged.workdir, base: staged.base, dir, log });
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
keep = true;
|
|
210
|
+
log(`could not land the work; staging kept in ${dir}: ${error.message}`);
|
|
211
|
+
}
|
|
212
|
+
const got = await runTool(openshell, ["sandbox", "download", sandbox, OUT, join(dir, "out")], { env, timeoutMs: UPLOAD_TIMEOUT_MS });
|
|
213
|
+
if (got.code === 0 && proj)
|
|
214
|
+
log(`${await replayTasks({ dir, project: proj, env, log, name })} recorded task call(s) applied`);
|
|
215
|
+
return code;
|
|
216
|
+
}
|
|
217
|
+
finally {
|
|
218
|
+
process.removeListener("SIGTERM", onTerm);
|
|
219
|
+
process.removeListener("SIGINT", onTerm);
|
|
220
|
+
if (created && keep)
|
|
221
|
+
log(`sandbox ${sandbox} kept so its work is not lost; delete it with: openshell sandbox delete ${sandbox}`);
|
|
222
|
+
else if (created) {
|
|
223
|
+
const gone = await destroyOwnedSandboxes({ openshell, env, project: proj, kind: "run", owner: name, legacyNames: [sandbox] });
|
|
224
|
+
log(gone.ok ? `sandbox ${sandbox} deleted` : `sandbox delete failed: ${gone.detail}`);
|
|
225
|
+
}
|
|
226
|
+
if (!keep)
|
|
227
|
+
rmSync(dir, { recursive: true, force: true });
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {
|
|
231
|
+
try {
|
|
232
|
+
const args = parseArgs(process.argv.slice(2));
|
|
233
|
+
process.exitCode = await sandboxRun(args);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
process.stderr.write(`sandbox-run: ${error.message}\n`);
|
|
237
|
+
process.exitCode = 1;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// Scheduled commands: schedules.json entries become durable scheduled workflows that run one command per tick.
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { isAbsolute, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { configDir, listProjects, stateDir } from "../lib/config.js";
|
|
7
|
+
import { MISSION_FILE, withMission } from "../lib/mission.js";
|
|
8
|
+
import { refreshPmWorkspace } from "../lib/pm-workspace.js";
|
|
9
|
+
import { withReview } from "../lib/pm-review.js";
|
|
10
|
+
import { isProjectPaused, PROJECT_PAUSED } from "../lib/project-pause.js";
|
|
11
|
+
import { harnessOfCommand, projectOfFolder, sessionOfCommand } from "../lib/schedule-session.js";
|
|
12
|
+
import { childEnv } from "../lib/sessions/launch.js";
|
|
13
|
+
import { SYSTEM_PROMPT_ENV } from "../lib/machine-prompt.js";
|
|
14
|
+
import { ROLE_ENV } from "../lib/cursor-trace.js";
|
|
15
|
+
import { scopeLaunch } from "../lib/sessions/scope.js";
|
|
16
|
+
import { agentHarness, hostAgentRefusal } from "../lib/agent-guard.js";
|
|
17
|
+
export const DEFAULT_TIMEOUT_SEC = 900;
|
|
18
|
+
export const TAIL_CHARS = 2000;
|
|
19
|
+
export const KILL_GRACE_MS = 5000;
|
|
20
|
+
export const TICK_STEP = "command";
|
|
21
|
+
const MAX_EVERY_MINUTES = 525_600;
|
|
22
|
+
const NAME = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
23
|
+
const KEYS = ["name", "everyMinutes", "cwd", "command", "timeoutSec", "wakeOnTasks", "sandbox", "workspace"];
|
|
24
|
+
// Runs a "sandbox": true entry's agent command inside a fresh OpenShell sandbox (runner/sandbox-run.mjs).
|
|
25
|
+
export const SANDBOX_RUN = fileURLToPath(new URL("./sandbox-run.mjs", import.meta.url));
|
|
26
|
+
// Host settings for the sandbox helper, which builds its own environment for the harness.
|
|
27
|
+
const SANDBOX_RUN_KEYS = [
|
|
28
|
+
"TEMMO_OPENSHELL_BIN", "TEMMO_STATE_DIR",
|
|
29
|
+
"TEMMO_CURSOR_TREE", "TEMMO_CODEX_TREE", "TEMMO_CLAUDE_BIN", "TEMMO_OPENCODE_BIN",
|
|
30
|
+
"TEMMO_BUILDER_NODE", "TEMMO_BUILDER_NODE_MODULES", "TEMMO_BUILDER_GIT",
|
|
31
|
+
"TEMMO_BUILDER_GIT_CORE", "TEMMO_BUILDER_ONCEBITTEN",
|
|
32
|
+
];
|
|
33
|
+
/** The schedules file: TEMMO_SCHEDULES, else <config dir>/schedules.json. */
|
|
34
|
+
export const schedulesPath = (env = process.env) => env.TEMMO_SCHEDULES || join(configDir(env), "schedules.json");
|
|
35
|
+
function invalid(index, message) {
|
|
36
|
+
throw new Error(`schedules.json entry ${index}: ${message}`);
|
|
37
|
+
}
|
|
38
|
+
// Checks one entry and returns it with everyMs and timeoutMs; throws on the first problem.
|
|
39
|
+
function checkEntry(entry, index) {
|
|
40
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
41
|
+
invalid(index, "not an object");
|
|
42
|
+
if (entry.cron !== undefined)
|
|
43
|
+
invalid(index, "cron schedules are not supported; use everyMinutes");
|
|
44
|
+
const unknown = Object.keys(entry).filter((key) => !KEYS.includes(key));
|
|
45
|
+
if (unknown.length)
|
|
46
|
+
invalid(index, `unknown key ${unknown.join(", ")}`);
|
|
47
|
+
if (typeof entry.name !== "string" || !NAME.test(entry.name))
|
|
48
|
+
invalid(index, "name must be 1-40 lowercase letters, digits or dashes");
|
|
49
|
+
if (!Number.isSafeInteger(entry.everyMinutes) || entry.everyMinutes < 1 || entry.everyMinutes > MAX_EVERY_MINUTES) {
|
|
50
|
+
invalid(index, `everyMinutes must be an integer from 1 to ${MAX_EVERY_MINUTES}`);
|
|
51
|
+
}
|
|
52
|
+
if (typeof entry.cwd !== "string" || !isAbsolute(entry.cwd))
|
|
53
|
+
invalid(index, "cwd must be an absolute path");
|
|
54
|
+
if (!statSync(entry.cwd, { throwIfNoEntry: false })?.isDirectory())
|
|
55
|
+
invalid(index, `cwd ${entry.cwd} is not a directory`);
|
|
56
|
+
if (!Array.isArray(entry.command) || !entry.command.length || !entry.command.every((arg) => typeof arg === "string") || !entry.command[0]) {
|
|
57
|
+
invalid(index, "command must be a non-empty array of strings");
|
|
58
|
+
}
|
|
59
|
+
const timeoutSec = entry.timeoutSec ?? DEFAULT_TIMEOUT_SEC;
|
|
60
|
+
if (!Number.isSafeInteger(timeoutSec) || timeoutSec < 1)
|
|
61
|
+
invalid(index, "timeoutSec must be a positive integer");
|
|
62
|
+
if (timeoutSec >= entry.everyMinutes * 60)
|
|
63
|
+
invalid(index, "timeoutSec must be shorter than everyMinutes");
|
|
64
|
+
// wakeOnTasks names a project whose finished tasks start this schedule early.
|
|
65
|
+
if (entry.wakeOnTasks !== undefined && (typeof entry.wakeOnTasks !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/.test(entry.wakeOnTasks)))
|
|
66
|
+
invalid(index, "wakeOnTasks must be a project name");
|
|
67
|
+
if (entry.sandbox !== undefined && typeof entry.sandbox !== "boolean")
|
|
68
|
+
invalid(index, "sandbox must be true or false");
|
|
69
|
+
if (entry.sandbox && !agentHarness(entry.command))
|
|
70
|
+
invalid(index, "sandbox: true needs a command that runs claude, codex, cursor-agent or opencode");
|
|
71
|
+
// The directory need not exist yet: a pm tick clones it. cwd stays the registered project.
|
|
72
|
+
if (entry.workspace !== undefined && (typeof entry.workspace !== "string" || !isAbsolute(entry.workspace)))
|
|
73
|
+
invalid(index, "workspace must be an absolute path");
|
|
74
|
+
return { name: entry.name, everyMs: entry.everyMinutes * 60_000, cwd: entry.cwd, command: entry.command, timeoutMs: timeoutSec * 1000, ...(entry.wakeOnTasks ? { wakeOnTasks: entry.wakeOnTasks } : {}), ...(entry.sandbox ? { sandbox: true } : {}), ...(entry.workspace ? { workspace: entry.workspace } : {}) };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Reads the schedules file. Returns {entries, errors}: each invalid entry is left out and reported, so one typo
|
|
78
|
+
* does not stop the others. A missing file is no schedules.
|
|
79
|
+
*/
|
|
80
|
+
export function loadSchedules(env = process.env) {
|
|
81
|
+
const file = schedulesPath(env);
|
|
82
|
+
let text;
|
|
83
|
+
try {
|
|
84
|
+
text = readFileSync(file, "utf8");
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (error.code === "ENOENT")
|
|
88
|
+
return { entries: [], errors: [] };
|
|
89
|
+
return { entries: [], errors: [`${file}: ${error.message}`] };
|
|
90
|
+
}
|
|
91
|
+
let list;
|
|
92
|
+
try {
|
|
93
|
+
list = JSON.parse(text);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return { entries: [], errors: [`${file} is not valid JSON: ${error.message}`] };
|
|
97
|
+
}
|
|
98
|
+
if (!Array.isArray(list))
|
|
99
|
+
return { entries: [], errors: [`${file} must hold a JSON array of schedules`] };
|
|
100
|
+
const entries = [];
|
|
101
|
+
const errors = [];
|
|
102
|
+
const names = new Set();
|
|
103
|
+
list.forEach((raw, index) => {
|
|
104
|
+
try {
|
|
105
|
+
const entry = checkEntry(raw, index);
|
|
106
|
+
if (names.has(entry.name))
|
|
107
|
+
invalid(index, `name ${entry.name} appears twice`);
|
|
108
|
+
names.add(entry.name);
|
|
109
|
+
entries.push(entry);
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
errors.push(error.message);
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return { entries, errors };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Runs argv in its own process group (no shell, stdin closed). A timeout or abort sends SIGTERM to the group, then
|
|
119
|
+
* SIGKILL after graceMs. Resolves {ok, exitCode, signal, timedOut, durationMs, tail}; rejects when signal aborts.
|
|
120
|
+
* With `scope`, the command runs in its own transient systemd scope, so a runner restart does not kill an agent it
|
|
121
|
+
* started; the scope execs the command, so the process group and the timeout handling are the same either way.
|
|
122
|
+
*/
|
|
123
|
+
export function runCommand(command, { cwd, env = process.env, timeoutMs, signal, graceMs = KILL_GRACE_MS, scope = null }) {
|
|
124
|
+
const [given, ...givenArgs] = command;
|
|
125
|
+
// A scope outlives this process, so the timeout is also handed to systemd: it cuts the command if the caller dies.
|
|
126
|
+
const launch = scope ? scopeLaunch(command, { ...scope, kind: "schedule", runtimeMaxSec: timeoutMs === undefined ? 0 : timeoutMs / 1000 }) : null;
|
|
127
|
+
const [file, runArgs] = launch ? [launch.file, launch.args] : [given, givenArgs];
|
|
128
|
+
const started = Date.now();
|
|
129
|
+
return new Promise((resolve, reject) => {
|
|
130
|
+
if (signal?.aborted)
|
|
131
|
+
return reject(signal.reason);
|
|
132
|
+
const child = spawn(file, runArgs, { cwd, env, stdio: ["ignore", "pipe", "pipe"], detached: true, windowsHide: true });
|
|
133
|
+
let tail = "";
|
|
134
|
+
let timedOut = false;
|
|
135
|
+
let aborted = false;
|
|
136
|
+
let exit = null;
|
|
137
|
+
let spawnError = null;
|
|
138
|
+
let deadline;
|
|
139
|
+
let escalate;
|
|
140
|
+
let giveUp;
|
|
141
|
+
let closeFallback;
|
|
142
|
+
let settled = false;
|
|
143
|
+
const keep = (chunk) => { tail = (tail + chunk).slice(-TAIL_CHARS); };
|
|
144
|
+
const killGroup = (sig) => {
|
|
145
|
+
const { pid } = child;
|
|
146
|
+
if (pid === undefined)
|
|
147
|
+
return;
|
|
148
|
+
try {
|
|
149
|
+
process.kill(-pid, sig);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
// OpenShell sandboxes refuse group signals with EPERM; signal each member found in /proc instead.
|
|
153
|
+
if (error.code !== "EPERM")
|
|
154
|
+
return;
|
|
155
|
+
let entries;
|
|
156
|
+
try {
|
|
157
|
+
entries = readdirSync("/proc");
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
if (!/^\d+$/.test(entry))
|
|
164
|
+
continue;
|
|
165
|
+
let stat;
|
|
166
|
+
try {
|
|
167
|
+
stat = readFileSync(`/proc/${entry}/stat`, "utf8");
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
continue;
|
|
171
|
+
} // it exited mid-scan
|
|
172
|
+
// The pgid is the third field after comm, and comm may hold spaces and parentheses.
|
|
173
|
+
if (stat.slice(stat.lastIndexOf(")") + 2).split(" ")[2] === String(pid)) {
|
|
174
|
+
try {
|
|
175
|
+
process.kill(Number(entry), sig);
|
|
176
|
+
}
|
|
177
|
+
catch { /* it exited mid-kill */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const finish = () => {
|
|
183
|
+
if (settled)
|
|
184
|
+
return;
|
|
185
|
+
settled = true;
|
|
186
|
+
// A process left running may still hold the pipes: drain them without keeping its output.
|
|
187
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
188
|
+
stream.removeListener("data", keep);
|
|
189
|
+
stream.resume();
|
|
190
|
+
stream.unref?.();
|
|
191
|
+
}
|
|
192
|
+
for (const timer of [deadline, escalate, giveUp, closeFallback])
|
|
193
|
+
clearTimeout(timer);
|
|
194
|
+
signal?.removeEventListener("abort", onAbort);
|
|
195
|
+
if (aborted)
|
|
196
|
+
return reject(signal.reason);
|
|
197
|
+
const durationMs = Date.now() - started;
|
|
198
|
+
if (spawnError)
|
|
199
|
+
return resolve({ ok: false, exitCode: null, signal: null, timedOut: false, durationMs, tail: spawnError.message.slice(-TAIL_CHARS) });
|
|
200
|
+
resolve({ ok: !timedOut && exit?.code === 0, exitCode: exit?.code ?? null, signal: exit?.signal ?? null, timedOut, durationMs, tail });
|
|
201
|
+
};
|
|
202
|
+
const terminate = () => {
|
|
203
|
+
if (escalate)
|
|
204
|
+
return;
|
|
205
|
+
killGroup("SIGTERM");
|
|
206
|
+
escalate = setTimeout(() => {
|
|
207
|
+
killGroup("SIGKILL");
|
|
208
|
+
giveUp = setTimeout(finish, graceMs); // a process that survives SIGKILL is not waited for
|
|
209
|
+
}, graceMs);
|
|
210
|
+
};
|
|
211
|
+
const onAbort = () => { aborted = true; terminate(); };
|
|
212
|
+
child.stdout.on("data", keep);
|
|
213
|
+
child.stderr.on("data", keep);
|
|
214
|
+
child.on("error", (error) => { spawnError = error; finish(); });
|
|
215
|
+
child.on("exit", (code, sig) => {
|
|
216
|
+
exit = { code, signal: sig };
|
|
217
|
+
// Background work the command started (an agent it handed off to) outlives a clean exit; only a timeout or abort kills the group.
|
|
218
|
+
closeFallback = setTimeout(finish, graceMs); // stdio can outlive the exit
|
|
219
|
+
});
|
|
220
|
+
child.on("close", (code, sig) => {
|
|
221
|
+
exit ??= { code, signal: sig };
|
|
222
|
+
finish();
|
|
223
|
+
});
|
|
224
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
225
|
+
deadline = setTimeout(() => { timedOut = true; terminate(); }, timeoutMs);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/** The argv a sandboxed entry's tick runs: the sandbox runner, then the agent command after "--". */
|
|
229
|
+
export function sandboxRunCommand(entry, command, project = "") {
|
|
230
|
+
return [process.execPath, SANDBOX_RUN, "--name", entry.name, "--cwd", entry.cwd, ...(project ? ["--project", project] : []), "--", ...command];
|
|
231
|
+
}
|
|
232
|
+
/** The workflow body for one entry: one checkpointed command step, not re-run after a cut. */
|
|
233
|
+
export function tickFn(entry, { env = process.env, log = () => { }, graceMs, projects, refresh = refreshPmWorkspace } = {}) {
|
|
234
|
+
return async (scheduledTime, actualTime, wf) => {
|
|
235
|
+
// The mission file is read here, every tick, so a PM edit reaches the next tick without touching schedules.json.
|
|
236
|
+
// cwd stays the registered project. A pm workspace is a separate clone: the command and the mission come from it.
|
|
237
|
+
const project = projectOfFolder(entry.cwd, projects ?? listProjects(env));
|
|
238
|
+
let runCwd = entry.cwd;
|
|
239
|
+
let missionFile = "";
|
|
240
|
+
if (entry.name === "pm" && entry.workspace) {
|
|
241
|
+
refresh(entry.workspace, { source: entry.cwd, log, env });
|
|
242
|
+
runCwd = entry.workspace;
|
|
243
|
+
missionFile = join(entry.workspace, MISSION_FILE);
|
|
244
|
+
}
|
|
245
|
+
// The review comes last, after the mission, so it is the closing instruction of every run; a project with no
|
|
246
|
+
// mission file still gets it, and the review says to write the file first.
|
|
247
|
+
const command = [...withMission(entry.command, { project, env, log, ...(missionFile ? { file: missionFile } : {}) })];
|
|
248
|
+
if (entry.name === "pm" && project && harnessOfCommand(command)) {
|
|
249
|
+
command[command.length - 1] += [
|
|
250
|
+
"",
|
|
251
|
+
"Review project outcomes with temmo task outcomes.",
|
|
252
|
+
'For a requested outcome, run temmo task propose-outcome <outcome-id> "<task title>" ["<task title>" ...] with one to three tasks. Wait for operator approval before working on them.',
|
|
253
|
+
'When every linked task is done, run the acceptance check and record evidence with temmo task report-outcome <outcome-id> pass|fail "<evidence>". Leave closure to the operator.',
|
|
254
|
+
].join("\n");
|
|
255
|
+
}
|
|
256
|
+
const reviewedCommand = withReview(command, { project });
|
|
257
|
+
// The command runs in its own scope, so a runner restart does not kill an agent a tick started; it also outlives
|
|
258
|
+
// the tick's own timeout only if the scope cannot be made, where the group kill still applies.
|
|
259
|
+
const result = await wf.step(TICK_STEP, () => {
|
|
260
|
+
if (project && harnessOfCommand(entry.command) && !sessionOfCommand(entry.command) && isProjectPaused({ project, stateDir: stateDir(env) })) {
|
|
261
|
+
return { ok: false, exitCode: null, signal: null, timedOut: false, durationMs: 0, tail: PROJECT_PAUSED };
|
|
262
|
+
}
|
|
263
|
+
const refusal = hostAgentRefusal(reviewedCommand, { sandboxed: Boolean(entry.sandbox), env });
|
|
264
|
+
if (refusal)
|
|
265
|
+
return { ok: false, exitCode: null, signal: null, timedOut: false, durationMs: 0, tail: refusal };
|
|
266
|
+
const run = entry.sandbox ? sandboxRunCommand({ ...entry, cwd: runCwd }, reviewedCommand, project) : reviewedCommand;
|
|
267
|
+
const pass = entry.sandbox ? Object.fromEntries(SANDBOX_RUN_KEYS.filter((key) => env[key]).map((key) => [key, env[key]])) : {};
|
|
268
|
+
return runCommand(run, { cwd: runCwd, env: { ...childEnv(env), ...pass, [SYSTEM_PROMPT_ENV]: "1", [ROLE_ENV]: `schedule:${entry.name}` }, timeoutMs: entry.timeoutMs, signal: wf.signal, graceMs, scope: { env, label: entry.name, description: `Temmo schedule ${entry.name}` } });
|
|
269
|
+
}, {
|
|
270
|
+
onCut: () => ({ ok: false, exitCode: null, signal: null, timedOut: false, durationMs: 0, tail: "", cut: "runner restarted during the run; not re-run" }),
|
|
271
|
+
});
|
|
272
|
+
// A cut tick never ran here: its line must not match the "ok|failed in N ms" the journal analyzer counts.
|
|
273
|
+
if (result.cut)
|
|
274
|
+
log(`${entry.name}: ${result.cut}`);
|
|
275
|
+
else {
|
|
276
|
+
const lines = String(result.tail || "").split("\n").map((l) => l.trim()).filter(Boolean);
|
|
277
|
+
const notStarted = !result.ok && result.exitCode === null && !result.signal && !result.timedOut;
|
|
278
|
+
// A failed command's reason is its first error line, else its last output line.
|
|
279
|
+
const errorLine = lines.find((l) => /^\w*(Error|Exception)\b|\berror:/i.test(l)) ?? lines.at(-1) ?? "";
|
|
280
|
+
const reason = notStarted ? (lines[0] ?? "").slice(0, 160)
|
|
281
|
+
: !result.ok && typeof result.exitCode === "number" ? `exit ${result.exitCode}${errorLine ? `: ${errorLine.slice(0, 160)}` : ""}` : "";
|
|
282
|
+
const how = result.timedOut ? " (timed out)" : result.signal ? ` (${result.signal})` : reason ? ` (${reason})` : "";
|
|
283
|
+
log(`${entry.name}: ${result.ok ? "ok" : "failed"}${how} in ${result.durationMs} ms`);
|
|
284
|
+
}
|
|
285
|
+
return { ...result, scheduledTime: scheduledTime.toISOString(), actualTime: actualTime.toISOString() };
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
/** Registers each entry with the durable log as a scheduled workflow; returns the names. */
|
|
289
|
+
export function registerSchedules(durable, entries, { env = process.env, log = () => { }, projects } = {}) {
|
|
290
|
+
for (const entry of entries) {
|
|
291
|
+
durable.scheduled(entry.name, { everyMs: entry.everyMs, firstStep: TICK_STEP }, tickFn(entry, { env, log, projects }));
|
|
292
|
+
}
|
|
293
|
+
return entries.map((entry) => entry.name);
|
|
294
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Starts a schedule's tick early when a task in a project's store moves to done or blocked, so the PM hands off the next task at once.
|
|
2
|
+
import { readStore, taskStoreFile } from "../lib/tasks.js";
|
|
3
|
+
export const TASK_WAKE_EVERY_MS = 15_000;
|
|
4
|
+
const FINISHED = new Set(["done", "blocked"]);
|
|
5
|
+
/** Polls the task store; calls wake(ids) for tasks newly done or blocked, and retries until wake returns true. Returns stop(). */
|
|
6
|
+
export function watchTaskFinishes({ file, wake, log = () => { }, everyMs = TASK_WAKE_EVERY_MS }) {
|
|
7
|
+
let last = null;
|
|
8
|
+
let pending = [];
|
|
9
|
+
const statuses = () => new Map(readStore(file).tasks.map((task) => [task.id, task.status]));
|
|
10
|
+
const tick = async () => {
|
|
11
|
+
let now;
|
|
12
|
+
try {
|
|
13
|
+
now = statuses();
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
log(`task wake: ${error.message}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (last)
|
|
20
|
+
for (const [id, status] of now)
|
|
21
|
+
if (FINISHED.has(status) && last.get(id) !== status && !pending.includes(id))
|
|
22
|
+
pending.push(id);
|
|
23
|
+
last = now;
|
|
24
|
+
if (!pending.length)
|
|
25
|
+
return;
|
|
26
|
+
let started = false;
|
|
27
|
+
try {
|
|
28
|
+
started = await wake(pending) === true;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
log(`task wake: ${error.message}`);
|
|
32
|
+
}
|
|
33
|
+
if (started)
|
|
34
|
+
pending = [];
|
|
35
|
+
};
|
|
36
|
+
void tick();
|
|
37
|
+
const timer = setInterval(tick, everyMs);
|
|
38
|
+
timer.unref();
|
|
39
|
+
return () => clearInterval(timer);
|
|
40
|
+
}
|
|
41
|
+
/** Watches each schedule entry's wakeOnTasks project and runs that schedule now when one of its tasks finishes. */
|
|
42
|
+
export function startTaskWakes(entries, runner, { env = process.env, log = () => { }, everyMs } = {}) {
|
|
43
|
+
return entries.filter((entry) => entry.wakeOnTasks).map((entry) => watchTaskFinishes({
|
|
44
|
+
file: taskStoreFile(entry.wakeOnTasks, env),
|
|
45
|
+
everyMs,
|
|
46
|
+
log,
|
|
47
|
+
wake: async (ids) => {
|
|
48
|
+
try {
|
|
49
|
+
const result = await runner.runSchedule(entry.name, "task-wake");
|
|
50
|
+
log(`task wake: ${ids.join(", ")} finished; ${entry.name} ${result.status}`);
|
|
51
|
+
return result.status === "started";
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
log(`task wake: ${entry.name} not started: ${error.message}`);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Installs this plugin into ~/.cursor/plugins/local/temmo (symlink; --copy to copy).
|
|
3
|
+
import { installCursorPlugin } from "../lib/install-cursor.js";
|
|
4
|
+
const result = installCursorPlugin({ importMetaUrl: import.meta.url, copy: process.argv.includes("--copy") });
|
|
5
|
+
if (!result.ok) {
|
|
6
|
+
console.error(`temmo: ${result.message}`);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
console.log(`installed (${result.mode}) -> ${result.dest}`);
|
|
10
|
+
if (result.message)
|
|
11
|
+
console.log(result.message);
|