@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,58 @@
|
|
|
1
|
+
// Finds pattern runs that stopped moving: a live role whose session is gone, or idle with no handoff for too long.
|
|
2
|
+
// The runner fails a role over or settles the run from this; a scheduled tick names the stuck run instead of skipping silently.
|
|
3
|
+
import { autoDefaults } from "./config.js";
|
|
4
|
+
export const OFFLINE_MINUTES = 10;
|
|
5
|
+
export const IDLE_HOURS = 6;
|
|
6
|
+
/** defaults.json `patternOfflineMinutes` and `patternIdleHours`, else 10 minutes and 6 hours. */
|
|
7
|
+
export function stallLimits(env = process.env) {
|
|
8
|
+
const defaults = autoDefaults(env) ?? {};
|
|
9
|
+
const positive = (value, fallback) => (typeof value === "number" && value > 0 ? value : fallback);
|
|
10
|
+
return {
|
|
11
|
+
offlineMs: positive(defaults.patternOfflineMinutes, OFFLINE_MINUTES) * 60_000,
|
|
12
|
+
idleMs: positive(defaults.patternIdleHours, IDLE_HOURS) * 3_600_000,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const addressOf = (run, role, index) => run.instances?.[role]?.[index] || (index === 0 ? run.sessions?.[role] ?? "" : "");
|
|
16
|
+
/** When this instance last received work: its latest incoming handoff, else the run start. */
|
|
17
|
+
function enteredAt(run, role, index) {
|
|
18
|
+
const into = (run.handoffs ?? []).filter((item) => item.to === role && String(item.instance ?? "").split(",").includes(String(index)));
|
|
19
|
+
return Math.max(run.startedAt ?? 0, ...into.map((item) => item.at ?? 0), ...(run.failovers ?? []).filter((item) => item.role === role && item.index === index).map((item) => item.at ?? 0));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The live instances of a running run that stopped. A session whose owned record is missing or ended is dead: it fails over
|
|
23
|
+
* after offlineMs. An idle session (no turn running) with no handoff since is stuck: past idleMs the run is settled. A dead
|
|
24
|
+
* session past idleMs settles the run too, so an old run never launches fresh agents. `owned` maps address to owned record.
|
|
25
|
+
*/
|
|
26
|
+
export function staleRoles(run, owned, { now, offlineMs, idleMs }) {
|
|
27
|
+
if (run?.status !== "running")
|
|
28
|
+
return [];
|
|
29
|
+
const out = [];
|
|
30
|
+
for (const { role, index } of run.live ?? []) {
|
|
31
|
+
const address = addressOf(run, role, index);
|
|
32
|
+
// A call role waits on its child run, whose own roles the reaper checks.
|
|
33
|
+
if (!address || address.startsWith("run:"))
|
|
34
|
+
continue;
|
|
35
|
+
const record = owned.get(address);
|
|
36
|
+
const entered = enteredAt(run, role, index);
|
|
37
|
+
if (!record || record.status === "ended") {
|
|
38
|
+
const since = Math.max(entered, record?.updatedAt ?? 0);
|
|
39
|
+
const age = now - since;
|
|
40
|
+
out.push({ role, index, address, state: "dead", since, action: age >= idleMs ? "fail" : age >= offlineMs ? "failover" : "wait" });
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (record.status !== "idle" || record.run)
|
|
44
|
+
continue;
|
|
45
|
+
const since = Math.max(entered, record.updatedAt ?? 0);
|
|
46
|
+
out.push({ role, index, address, state: "idle", since, action: now - since >= idleMs ? "fail" : "wait" });
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
/** The line a scheduled tick logs when an earlier run of its pattern is unsettled: stuck (with its role and date) or still active. */
|
|
51
|
+
export function unsettledLine(run, owned, limits) {
|
|
52
|
+
const stuck = staleRoles(run, owned, limits).filter((item) => item.action !== "wait");
|
|
53
|
+
if (stuck.length) {
|
|
54
|
+
const first = stuck.sort((a, b) => a.since - b.since)[0];
|
|
55
|
+
return `skipped: run ${run.id} stuck since ${new Date(first.since).toISOString()} (role ${first.role} ${first.state}: ${first.address})`;
|
|
56
|
+
}
|
|
57
|
+
return `skipped: run ${run.id} ${run.status} since ${new Date(run.startedAt ?? limits.now).toISOString()}`;
|
|
58
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// One scheduled tick of a pattern: start a run unless an earlier run of the same pattern and task is unsettled.
|
|
2
|
+
// A skip names the run, and a stuck one says since when, so a stalled schedule never logs a bare success.
|
|
3
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
4
|
+
import { listRuns } from "./pattern-runs.js";
|
|
5
|
+
import { stallLimits, unsettledLine } from "./pattern-stall.js";
|
|
6
|
+
import { isProjectPaused } from "./project-pause.js";
|
|
7
|
+
import { listOwned } from "./sessions/registry.js";
|
|
8
|
+
// Idle role sessions of a finished or failed run are closed before the next run starts, so their sandboxes are released.
|
|
9
|
+
async function closeFinishedRoles(runs, owned, runner) {
|
|
10
|
+
const finished = new Set(runs.filter((run) => run.status === "done" || run.status === "failed").map((run) => run.id));
|
|
11
|
+
for (const session of owned.filter((item) => item.status === "idle" && finished.has(item.patternRun))) {
|
|
12
|
+
const current = await runner.get(session.address);
|
|
13
|
+
if (current.status !== 200 || current.body.status !== "idle")
|
|
14
|
+
continue;
|
|
15
|
+
const closed = await runner.close(session.address);
|
|
16
|
+
if (closed.status !== 200)
|
|
17
|
+
throw Error(`could not close ${session.address} of finished run ${session.patternRun}`);
|
|
18
|
+
let ended = closed.body.status === "ended";
|
|
19
|
+
for (let attempt = 0; !ended && attempt < 40; attempt++) {
|
|
20
|
+
await delay(1000);
|
|
21
|
+
ended = (await runner.get(session.address)).body?.status === "ended";
|
|
22
|
+
}
|
|
23
|
+
if (!ended)
|
|
24
|
+
throw Error(`${session.address} of finished run ${session.patternRun} is still closing`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Runs one tick and returns the line to log. `check` reports the state as JSON and starts nothing. */
|
|
28
|
+
export async function patternTick({ cfg, pattern, task, runner, env = process.env, now = Date.now(), check = false }) {
|
|
29
|
+
const runs = listRuns(cfg).filter((run) => run.pattern === pattern && run.task === task);
|
|
30
|
+
const ownedList = listOwned(cfg);
|
|
31
|
+
const owned = new Map(ownedList.map((record) => [record.address, record]));
|
|
32
|
+
const unsettled = runs.find((run) => run.status === "running" || run.status === "suspended");
|
|
33
|
+
const paused = isProjectPaused(cfg);
|
|
34
|
+
if (check)
|
|
35
|
+
return JSON.stringify({ project: cfg.project, pattern, paused, unsettled: unsettled?.id ?? null, ...(unsettled ? { line: unsettledLine(unsettled, owned, { now, ...stallLimits(env) }) } : {}) });
|
|
36
|
+
if (paused)
|
|
37
|
+
return "skipped: project is paused";
|
|
38
|
+
if (unsettled)
|
|
39
|
+
return unsettledLine(unsettled, owned, { now, ...stallLimits(env) });
|
|
40
|
+
await closeFinishedRoles(runs, ownedList, runner);
|
|
41
|
+
const result = await runner.startPattern({ project: cfg.project, name: pattern, task });
|
|
42
|
+
if (result.status !== 201 || result.body?.status !== "running")
|
|
43
|
+
throw Error(result.body?.detail || result.body?.error || `${pattern} run did not start`);
|
|
44
|
+
return `started: run ${result.body.id}`;
|
|
45
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// One pattern run on the durable log: enter a role, wait for its event, leave through decide.
|
|
2
|
+
// The workflow id is pattern-<run id>. The input is the team snapshot the run started with.
|
|
3
|
+
export function patternWorkflowId(runId) {
|
|
4
|
+
return `pattern-${runId}`;
|
|
5
|
+
}
|
|
6
|
+
export function runIdOfPatternWorkflow(workflowId) {
|
|
7
|
+
const prefix = "pattern-";
|
|
8
|
+
if (!workflowId?.startsWith(prefix))
|
|
9
|
+
throw new Error(`not a pattern workflow: ${workflowId}`);
|
|
10
|
+
return workflowId.slice(prefix.length);
|
|
11
|
+
}
|
|
12
|
+
/** The run launchPatternRun writes. project stays on the workflow input so recovery can find the run file. */
|
|
13
|
+
export function seedPatternRun({ name, task, definition, parent }, runId, now = Date.now) {
|
|
14
|
+
const entry = definition.roles[0];
|
|
15
|
+
const count = entry.count ?? 1;
|
|
16
|
+
return {
|
|
17
|
+
id: runId, openshell: true, runner: true, pattern: name, definition, task, status: "running", active: entry.id,
|
|
18
|
+
live: Array.from({ length: count }, (_, index) => ({ role: entry.id, index })),
|
|
19
|
+
sessions: {}, instances: {}, arrivals: {}, visits: { [entry.id]: Array.from({ length: count }, () => 1) },
|
|
20
|
+
handoffs: [], notes: [], startedAt: typeof now === "function" ? now() : now, ...(parent ? { parent } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Steps are enter, event, and leave. A finished step returns its recorded output.
|
|
25
|
+
* A step left started uses onCut and does not call the harness again.
|
|
26
|
+
* deps.between runs after leave is durable and before the next enter, so a test can stop there.
|
|
27
|
+
*/
|
|
28
|
+
export async function runPatternWorkflow(wf, input, deps) {
|
|
29
|
+
const runId = runIdOfPatternWorkflow(wf.id);
|
|
30
|
+
const entry = await wf.step("enter", async () => {
|
|
31
|
+
const started = await deps.enterEntry(input, runId);
|
|
32
|
+
wf.signal.throwIfAborted();
|
|
33
|
+
return { reply: started.reply ?? started };
|
|
34
|
+
}, { onCut: () => deps.cutEntry(input, runId) });
|
|
35
|
+
deps.reply?.(input.request, { reply: entry.reply });
|
|
36
|
+
let reply = entry.reply;
|
|
37
|
+
while (reply?.status === "running" || reply?.status === "suspended") {
|
|
38
|
+
const message = await wf.recv("advance", { name: "event" });
|
|
39
|
+
const left = await wf.step("leave", async () => {
|
|
40
|
+
const outcome = await deps.leave(runId, message);
|
|
41
|
+
wf.signal.throwIfAborted();
|
|
42
|
+
return outcome;
|
|
43
|
+
}, { onCut: () => deps.cutLeave(runId, message) });
|
|
44
|
+
if (deps.between)
|
|
45
|
+
await deps.between(wf, left);
|
|
46
|
+
if (left.launch) {
|
|
47
|
+
const entered = await wf.step("enter", async () => {
|
|
48
|
+
const next = await deps.enterNext(runId, left);
|
|
49
|
+
if (deps.afterEnter)
|
|
50
|
+
await deps.afterEnter(wf, next);
|
|
51
|
+
wf.signal.throwIfAborted();
|
|
52
|
+
return next;
|
|
53
|
+
}, { onCut: () => deps.cutEnter(runId, left) });
|
|
54
|
+
if (entered.reply?.status === "failed") {
|
|
55
|
+
deps.reply?.(message.request, { reply: entered.reply });
|
|
56
|
+
return entered.reply;
|
|
57
|
+
}
|
|
58
|
+
if (entered.reply)
|
|
59
|
+
left.reply = { ...left.reply, ...entered.reply, handoff: left.reply?.handoff ?? entered.reply.handoff };
|
|
60
|
+
}
|
|
61
|
+
if (left.error)
|
|
62
|
+
deps.reply?.(message.request, { error: left.error });
|
|
63
|
+
else
|
|
64
|
+
deps.reply?.(message.request, { reply: left.reply });
|
|
65
|
+
if (left.reply)
|
|
66
|
+
reply = left.reply;
|
|
67
|
+
}
|
|
68
|
+
return reply;
|
|
69
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// pi extension: maps pi events to scripts/temmo-hook.mjs --host pi; the temmo tools come from pi's built-in MCP.
|
|
2
|
+
// The runner loads it with `pi --mode rpc -e <this file>` (runner/adapters/pi.ts); docs/pi.md maps each hook to its pi event.
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { ACTIVITY_TIMEOUT_MS, HOOK_TIMEOUT_MS, contextText, runHook } from "./opencode-plugin.mjs";
|
|
5
|
+
import { PI_MCP_SERVER, piMcpServer } from "./pi.js";
|
|
6
|
+
import { INSTRUCTIONS } from "./surfaces/instructions.js";
|
|
7
|
+
export const HOST = "pi";
|
|
8
|
+
export const CUSTOM_TYPE = "temmo";
|
|
9
|
+
// Set by the runner adapter: the extension asks before APPROVAL_TOOLS and the adapter answers by the session's mode.
|
|
10
|
+
export const APPROVALS_ENV = "TEMMO_PI_APPROVALS";
|
|
11
|
+
export const APPROVAL_TOOLS = ["bash", "edit", "write"];
|
|
12
|
+
// The confirm dialog title the adapter recognises as a tool approval; its message is JSON {tool, input}.
|
|
13
|
+
export const APPROVAL_TITLE = "temmo:tool_approval";
|
|
14
|
+
const MCP_SCRIPT = fileURLToPath(new URL("../scripts/temmo-mcp.mjs", import.meta.url));
|
|
15
|
+
const textOf = (content) => (Array.isArray(content) ? content.filter((p) => p?.type === "text").map((p) => p.text).join("\n") : typeof content === "string" ? content : "");
|
|
16
|
+
/** The temmo MCP server this extension registers: this app's server under the node running pi. */
|
|
17
|
+
export const hostMcpServer = (node = process.execPath) => piMcpServer({ command: node, script: MCP_SCRIPT, env: { TEMMO_PEER: HOST } });
|
|
18
|
+
/** The extension factory; run and env are injectable for tests. */
|
|
19
|
+
export function createPiExtension({ run = runHook, env = process.env } = {}) {
|
|
20
|
+
return async function aiCollab(pi) {
|
|
21
|
+
let sessionId = "";
|
|
22
|
+
let pending = "";
|
|
23
|
+
let lessons = "";
|
|
24
|
+
const tokens = (ctx) => { const n = ctx?.getContextUsage?.()?.tokens; return Number.isSafeInteger(n) ? { context_tokens: n } : {}; };
|
|
25
|
+
const input = (ctx, event, extra = {}) => ({ hook_event_name: event, session_id: sessionId, cwd: ctx?.cwd || process.cwd(), ...extra });
|
|
26
|
+
const call = (ctx, event, extra, options = {}) => Promise.resolve(run(input(ctx, event, extra), { host: HOST, env, timeoutMs: HOOK_TIMEOUT_MS[event] ?? ACTIVITY_TIMEOUT_MS, ...options })).catch(() => ({}));
|
|
27
|
+
const activity = (ctx, event, extra) => { void Promise.resolve(run(input(ctx, event, extra), { host: HOST, env, activity: true })).catch(() => { }); };
|
|
28
|
+
const remember = (ctx) => { sessionId = ctx?.sessionManager?.getSessionId?.() || sessionId; };
|
|
29
|
+
// The tools come from MCP only; an mcp.json entry of the same name (the OpenShell agent dir's) wins over this one.
|
|
30
|
+
pi.registerMcpServer(PI_MCP_SERVER, hostMcpServer());
|
|
31
|
+
// SessionStart: its context waits for the first prompt, since session_start cannot add a message.
|
|
32
|
+
pi.on("session_start", async (event, ctx) => {
|
|
33
|
+
remember(ctx);
|
|
34
|
+
const out = await call(ctx, "SessionStart", { source: event?.reason === "startup" ? "startup" : "resume" });
|
|
35
|
+
if (typeof out.lessons === "string" && out.lessons.trim())
|
|
36
|
+
lessons = out.lessons.trim();
|
|
37
|
+
pending = [pending, contextText(out)].filter(Boolean).join("\n");
|
|
38
|
+
});
|
|
39
|
+
// UserPromptSubmit, plus the server instructions and the lesson note on the system prompt and any SessionStart or
|
|
40
|
+
// compaction context. A direct MCP server's instructions reach no prompt in pi, so they ride here; a custom-message turn has no prompt.
|
|
41
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
42
|
+
remember(ctx);
|
|
43
|
+
const out = event?.messageType === "custom" ? {} : await call(ctx, "UserPromptSubmit", { prompt: String(event?.prompt ?? "") });
|
|
44
|
+
// UserPromptSubmit may refresh lessons + harness surface (AGENTS.local.md / memory) together.
|
|
45
|
+
if (typeof out.lessons === "string" && out.lessons.trim())
|
|
46
|
+
lessons = out.lessons.trim();
|
|
47
|
+
const text = [pending, contextText(out)].filter(Boolean).join("\n");
|
|
48
|
+
pending = "";
|
|
49
|
+
return {
|
|
50
|
+
systemPrompt: [event?.systemPrompt ?? "", INSTRUCTIONS, lessons].filter(Boolean).join("\n\n"),
|
|
51
|
+
...(text ? { message: { customType: CUSTOM_TYPE, content: text, display: false } } : {}),
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
// PreToolUse: the read gate first, then the runner's approval through pi's confirm dialog.
|
|
55
|
+
pi.on("tool_call", async (event, ctx) => {
|
|
56
|
+
const extra = { tool_name: event.toolName, tool_input: event.input, tool_use_id: event.toolCallId };
|
|
57
|
+
activity(ctx, "PreToolUse", extra);
|
|
58
|
+
const gate = await call(ctx, "PreToolUse", extra, { gate: true, timeoutMs: ACTIVITY_TIMEOUT_MS });
|
|
59
|
+
const decision = gate?.hookSpecificOutput;
|
|
60
|
+
if (decision?.permissionDecision === "deny")
|
|
61
|
+
return { block: true, reason: String(decision.permissionDecisionReason || "direct read refused") };
|
|
62
|
+
if (env[APPROVALS_ENV] !== "1" || !APPROVAL_TOOLS.includes(event.toolName) || !ctx?.hasUI)
|
|
63
|
+
return undefined;
|
|
64
|
+
const ok = await ctx.ui.confirm(APPROVAL_TITLE, JSON.stringify({ tool: event.toolName, input: event.input }));
|
|
65
|
+
return ok ? undefined : { block: true, reason: "The operator denied this tool call." };
|
|
66
|
+
});
|
|
67
|
+
// PostToolUse: delivered messages ride on the tool result.
|
|
68
|
+
pi.on("tool_result", async (event, ctx) => {
|
|
69
|
+
const extra = { tool_name: event.toolName, tool_input: event.input, tool_use_id: event.toolCallId, ...tokens(ctx) };
|
|
70
|
+
if (event.isError)
|
|
71
|
+
return void activity(ctx, "PostToolUseFailure", { ...extra, error: textOf(event.content) });
|
|
72
|
+
const text = contextText(await call(ctx, "PostToolUse", { ...extra, tool_response: textOf(event.content) }));
|
|
73
|
+
return text ? { content: [...(Array.isArray(event.content) ? event.content : []), { type: "text", text }] } : undefined;
|
|
74
|
+
});
|
|
75
|
+
// Stop: a continuation (waiting messages, an AFK answer) starts the next turn as a follow-up; a retry is no stop.
|
|
76
|
+
pi.on("agent_end", async (event, ctx) => {
|
|
77
|
+
if (event?.willRetry)
|
|
78
|
+
return;
|
|
79
|
+
const last = [...(event?.messages ?? [])].reverse().find((m) => m?.role === "assistant");
|
|
80
|
+
const out = await call(ctx, "Stop", { stop_hook_active: false, last_assistant_message: textOf(last?.content), ...tokens(ctx) });
|
|
81
|
+
if (out?.decision === "block" && typeof out.reason === "string" && out.reason)
|
|
82
|
+
pi.sendUserMessage(out.reason, { deliverAs: "followUp" });
|
|
83
|
+
});
|
|
84
|
+
pi.on("session_before_compact", async (_event, ctx) => { activity(ctx, "PreCompact", { trigger: "auto", ...tokens(ctx) }); });
|
|
85
|
+
// After a compaction, Claude's SessionStart source "compact" gives the session pad; it joins the next turn.
|
|
86
|
+
pi.on("session_compact", async (_event, ctx) => {
|
|
87
|
+
remember(ctx);
|
|
88
|
+
const text = contextText(await call(ctx, "SessionStart", { source: "compact" }));
|
|
89
|
+
if (text)
|
|
90
|
+
pi.sendMessage({ customType: CUSTOM_TYPE, content: text, display: false }, { deliverAs: "nextTurn" });
|
|
91
|
+
});
|
|
92
|
+
pi.on("session_shutdown", async (event, ctx) => {
|
|
93
|
+
if (event?.reason === "quit")
|
|
94
|
+
await call(ctx, "SessionEnd", { reason: "quit" });
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export default createPiExtension();
|
package/lib/pi.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// pi facts the adapter, setup, the extension and the OpenShell staging share: the package, the version floor, the MCP entry.
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
export const PI_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
5
|
+
export const PI_MIN_VERSION = [1, 7, 0];
|
|
6
|
+
export const PI_INSTALL = `npm i -g ${PI_PACKAGE}@^1.7`;
|
|
7
|
+
// The MCP server name; pi names its tools mcp__temmo__<tool> (hyphen to underscore).
|
|
8
|
+
export const PI_MCP_SERVER = "temmo";
|
|
9
|
+
const VERSION_MS = 15000;
|
|
10
|
+
const VERSION = /(\d+)\.(\d+)\.(\d+)/;
|
|
11
|
+
// Version checks by binary path and mtime: an upgrade in place changes the mtime.
|
|
12
|
+
const checked = new Map();
|
|
13
|
+
/** "" when `pi --version` output names 1.7 or later, else the refusal with the install command. */
|
|
14
|
+
export function piVersionProblem(output) {
|
|
15
|
+
const match = VERSION.exec(String(output ?? ""));
|
|
16
|
+
if (!match)
|
|
17
|
+
return `pi did not report a version; install pi 1.7 or later: ${PI_INSTALL}`;
|
|
18
|
+
const version = match.slice(1, 4).map(Number);
|
|
19
|
+
const older = PI_MIN_VERSION.findIndex((n, i) => version[i] !== n);
|
|
20
|
+
if (older >= 0 && version[older] < PI_MIN_VERSION[older])
|
|
21
|
+
return `pi ${match[0]} is older than 1.7; install pi 1.7 or later: ${PI_INSTALL}`;
|
|
22
|
+
return "";
|
|
23
|
+
}
|
|
24
|
+
/** The refusal for a missing pi binary. */
|
|
25
|
+
export const piMissing = () => `pi is not installed (no pi on PATH); install pi 1.7 or later: ${PI_INSTALL}`;
|
|
26
|
+
/** "" when the pi at file is 1.7 or later, else the refusal; cached per binary path and mtime. */
|
|
27
|
+
export function checkPi(file, env = process.env) {
|
|
28
|
+
if (!file)
|
|
29
|
+
return Promise.resolve(piMissing());
|
|
30
|
+
let key = file;
|
|
31
|
+
try {
|
|
32
|
+
key = `${file}:${statSync(file).mtimeMs}`;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return Promise.resolve(piMissing());
|
|
36
|
+
}
|
|
37
|
+
let result = checked.get(key);
|
|
38
|
+
if (!result) {
|
|
39
|
+
result = new Promise((resolve) => {
|
|
40
|
+
execFile(file, ["--version"], { env: { ...env, PI_OFFLINE: "1" }, timeout: VERSION_MS, encoding: "utf8" }, (error, stdout, stderr) => {
|
|
41
|
+
if (error && !stdout)
|
|
42
|
+
return resolve(`pi --version failed (${error.message.split("\n")[0]}); install pi 1.7 or later: ${PI_INSTALL}`);
|
|
43
|
+
resolve(piVersionProblem(`${stdout}\n${stderr}`));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
checked.set(key, result);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/** The temmo stdio MCP server entry for pi: declared to the model directly, with no tool_search or codemode step. */
|
|
51
|
+
export function piMcpServer({ command, script, env }) {
|
|
52
|
+
return { command, args: [script, "pi"], ...(env ? { env } : {}), exposure: "direct" };
|
|
53
|
+
}
|
|
54
|
+
/** An mcp.json body holding the temmo server. */
|
|
55
|
+
export function piMcpJson(server) {
|
|
56
|
+
return `${JSON.stringify({ mcpServers: { [PI_MCP_SERVER]: server } }, null, 2)}\n`;
|
|
57
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** A clean plugin copy: only package.json's "files" list, never node_modules, git data, worktrees or build output. */
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
// Claude, Codex and Cursor copy their plugin folder; a checkout with worktrees once made a 42 GB plugin cache.
|
|
5
|
+
export const PLUGIN_COPY_MAX_BYTES = 50 * 1024 * 1024;
|
|
6
|
+
const PLUGIN_ALWAYS = ["package.json", "README.md", "LICENSE"];
|
|
7
|
+
const NEVER = /(^|\/)(node_modules|\.git|\.next[^/]*)(\/|$)/;
|
|
8
|
+
// Harnesses that run the plugin from a copy under ~/.local/share/temmo (lib/setup.ts installPlugin).
|
|
9
|
+
export const COPIED_PLUGINS = ["claude", "codex"];
|
|
10
|
+
/** The commands that make an installed plugin load its refreshed copy; Codex re-adding from a local marketplace reinstalls it. */
|
|
11
|
+
export function pluginUpdateCommands(peer) {
|
|
12
|
+
if (peer === "claude")
|
|
13
|
+
return [["plugin", "marketplace", "update", "temmo"], ["plugin", "update", "temmo@temmo"]];
|
|
14
|
+
if (peer === "codex")
|
|
15
|
+
return [["plugin", "add", "temmo@temmo"]];
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Copies only package.json's "files" list (plus the manifest, README and LICENSE) from root into dest, replacing dest.
|
|
20
|
+
* Entries are paths or "dir/*.ext" globs, as npm pack reads them. Throws, leaving dest untouched, past PLUGIN_COPY_MAX_BYTES.
|
|
21
|
+
*/
|
|
22
|
+
export function packPluginCopy(root, dest) {
|
|
23
|
+
const files = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8")).files ?? [];
|
|
24
|
+
const tmp = `${dest}.tmp-${process.pid}`;
|
|
25
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
26
|
+
let bytes = 0;
|
|
27
|
+
const copy = (rel) => {
|
|
28
|
+
const from = path.join(root, rel);
|
|
29
|
+
if (!fs.existsSync(from))
|
|
30
|
+
return;
|
|
31
|
+
fs.cpSync(from, path.join(tmp, rel), { recursive: true, filter: (src) => !NEVER.test(path.relative(root, src)) });
|
|
32
|
+
};
|
|
33
|
+
try {
|
|
34
|
+
for (const entry of [...PLUGIN_ALWAYS, ...files]) {
|
|
35
|
+
if (!entry.includes("*")) {
|
|
36
|
+
copy(entry);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const dir = path.dirname(entry);
|
|
40
|
+
const re = new RegExp(`^${path.basename(entry).replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, "[^/]*")}$`);
|
|
41
|
+
for (const name of fs.existsSync(path.join(root, dir)) ? fs.readdirSync(path.join(root, dir)) : []) {
|
|
42
|
+
if (re.test(name) && fs.statSync(path.join(root, dir, name)).isFile())
|
|
43
|
+
copy(path.join(dir, name));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const walk = (dir) => { for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
47
|
+
const p = path.join(dir, e.name);
|
|
48
|
+
if (e.isDirectory())
|
|
49
|
+
walk(p);
|
|
50
|
+
else
|
|
51
|
+
bytes += fs.statSync(p).size;
|
|
52
|
+
} };
|
|
53
|
+
walk(tmp);
|
|
54
|
+
if (bytes > PLUGIN_COPY_MAX_BYTES)
|
|
55
|
+
throw new Error(`plugin copy is ${Math.round(bytes / 1048576)} MB, over the ${PLUGIN_COPY_MAX_BYTES / 1048576} MB limit; check package.json "files"`);
|
|
56
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
57
|
+
fs.renameSync(tmp, dest);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
return { dest, bytes };
|
|
64
|
+
}
|
|
65
|
+
/** Re-copies root into each installed <peer>-plugin folder under home, so running harnesses load the deployed code. Returns the peers refreshed. */
|
|
66
|
+
export function refreshPluginCopies(root, home) {
|
|
67
|
+
const refreshed = [];
|
|
68
|
+
for (const peer of COPIED_PLUGINS) {
|
|
69
|
+
const dest = path.join(home, ".local", "share", "temmo", `${peer}-plugin`);
|
|
70
|
+
if (!fs.existsSync(dest))
|
|
71
|
+
continue;
|
|
72
|
+
packPluginCopy(root, dest);
|
|
73
|
+
refreshed.push(peer);
|
|
74
|
+
}
|
|
75
|
+
return refreshed;
|
|
76
|
+
}
|
package/lib/pm-review.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run review: the last thing a scheduled harness tick is told, so every run ends with a short review of
|
|
3
|
+
* itself and the lessons that outlive it land in openmem (a fact about the setup) and MISSION.md (a rule the
|
|
4
|
+
* next run follows). Pure text, appended to the prompt like the mission file; a plain script is left alone.
|
|
5
|
+
*/
|
|
6
|
+
import { RULES_MAX } from "./mission.js";
|
|
7
|
+
import { harnessOfCommand } from "./schedule-session.js";
|
|
8
|
+
// The review is the operator's summary of a run, not a report: three lines at most.
|
|
9
|
+
export const REVIEW_MAX_LINES = 3;
|
|
10
|
+
export const REVIEW_HEADING = "Run review, before you finish";
|
|
11
|
+
/**
|
|
12
|
+
* The review instructions appended to every scheduled harness tick. With a project, the openmem bank is named,
|
|
13
|
+
* because the plugin resolves no bank from inside the prompt.
|
|
14
|
+
*/
|
|
15
|
+
export function reviewBlock({ project = "" } = {}) {
|
|
16
|
+
const bank = project ? `coding-agent::${project}` : "";
|
|
17
|
+
return [
|
|
18
|
+
`${REVIEW_HEADING}:`,
|
|
19
|
+
`- End this run with a short review, in at most ${REVIEW_MAX_LINES} lines: what worked, what did not, and what you would do differently. Post it as the last line of your final post so the operator reads it in the phone chat (\`send_to_all\`; from a shell, \`temmo send all "<review>" --progress\`).`,
|
|
20
|
+
`- Keep what you learned before you stop, and say where it went in the review. A fact about this setup goes to openmem with memory_add${bank ? `, bank "${bank}"` : ""}. A standing rule the next run must follow becomes a line in MISSION.md (\`temmo mission add-rule "<lesson>"\`; write the file first if the project has none). Work this run left open becomes a task.`,
|
|
21
|
+
`- Do not record a lesson twice. At ${RULES_MAX} rules, merge or drop one rather than add another; a rule the file no longer needs is not worth keeping.`,
|
|
22
|
+
].join("\n");
|
|
23
|
+
}
|
|
24
|
+
/** The command with the review appended to its last argument (the prompt, for a harness); a plain script is unchanged. */
|
|
25
|
+
export function withReview(command, { project = "" } = {}) {
|
|
26
|
+
if (!harnessOfCommand(command))
|
|
27
|
+
return command;
|
|
28
|
+
const block = reviewBlock({ project });
|
|
29
|
+
const last = command.length - 1;
|
|
30
|
+
const prompt = command[last].trim() ? `${command[last]}\n\n${block}` : block;
|
|
31
|
+
return [...command.slice(0, last), prompt];
|
|
32
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PM workspace is a separate clone of the schedule cwd's origin, not a linked
|
|
3
|
+
* worktree of the host checkout. A tick refreshes it before the command runs.
|
|
4
|
+
* Creating the directory clones origin and checks out main. An existing clone is
|
|
5
|
+
* never reset: a clean one is fast-forwarded, a dirty one is left as it is.
|
|
6
|
+
* The source repo is only read for its origin URL.
|
|
7
|
+
*/
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { existsSync } from "node:fs";
|
|
10
|
+
function gitEnv(base = process.env) {
|
|
11
|
+
const env = { ...base, GIT_TERMINAL_PROMPT: "0" };
|
|
12
|
+
for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_PREFIX"])
|
|
13
|
+
delete env[key];
|
|
14
|
+
return env;
|
|
15
|
+
}
|
|
16
|
+
function git(run, args, env) {
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
result = run("git", args, { encoding: "utf8", env });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return { status: 1, stdout: "", stderr: error.message };
|
|
23
|
+
}
|
|
24
|
+
if (!result || result.error) {
|
|
25
|
+
return { status: result?.status ?? 1, stdout: result?.stdout || "", stderr: result?.error?.message || result?.stderr || "git failed" };
|
|
26
|
+
}
|
|
27
|
+
return { status: result.status ?? 1, stdout: result.stdout || "", stderr: result.stderr || "" };
|
|
28
|
+
}
|
|
29
|
+
function lastLine(result) {
|
|
30
|
+
return (result.stderr || result.stdout || `exit ${result.status}`).trim().split("\n").pop();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Refresh `dir` from the origin of `source`. Returns {ok, dirty?, cloned?, detail}.
|
|
34
|
+
* Logs the reason when the clone is missing, dirty, or cannot fast-forward.
|
|
35
|
+
* `run` is spawnSync-shaped so tests can watch the argv.
|
|
36
|
+
*/
|
|
37
|
+
export function refreshPmWorkspace(dir, { source, run = spawnSync, log = () => { }, env = process.env } = {}) {
|
|
38
|
+
if (!dir || !source) {
|
|
39
|
+
const detail = "pm workspace: no directory; left it";
|
|
40
|
+
log(detail);
|
|
41
|
+
return { ok: false, detail };
|
|
42
|
+
}
|
|
43
|
+
const childEnv = gitEnv(env);
|
|
44
|
+
if (!existsSync(dir)) {
|
|
45
|
+
const url = git(run, ["-C", source, "remote", "get-url", "origin"], childEnv);
|
|
46
|
+
if (url.status !== 0 || !url.stdout.trim()) {
|
|
47
|
+
const detail = `pm workspace ${dir} is missing and ${source} has no origin URL; left it`;
|
|
48
|
+
log(detail);
|
|
49
|
+
return { ok: false, detail };
|
|
50
|
+
}
|
|
51
|
+
const cloned = git(run, ["clone", "--branch", "main", url.stdout.trim(), dir], childEnv);
|
|
52
|
+
if (cloned.status !== 0) {
|
|
53
|
+
const detail = `pm workspace clone failed: ${lastLine(cloned)}`;
|
|
54
|
+
log(detail);
|
|
55
|
+
return { ok: false, detail };
|
|
56
|
+
}
|
|
57
|
+
const detail = `pm workspace ${dir} cloned from origin`;
|
|
58
|
+
log(detail);
|
|
59
|
+
return { ok: true, cloned: true, detail };
|
|
60
|
+
}
|
|
61
|
+
const status = git(run, ["-C", dir, "status", "--porcelain"], childEnv);
|
|
62
|
+
if (status.status !== 0) {
|
|
63
|
+
const detail = `pm workspace ${dir} is not a git clone; left it`;
|
|
64
|
+
log(detail);
|
|
65
|
+
return { ok: false, detail };
|
|
66
|
+
}
|
|
67
|
+
if (status.stdout.trim()) {
|
|
68
|
+
const detail = `pm workspace ${dir} is dirty; left it`;
|
|
69
|
+
log(detail);
|
|
70
|
+
return { ok: true, dirty: true, detail };
|
|
71
|
+
}
|
|
72
|
+
const fetched = git(run, ["-C", dir, "fetch", "origin"], childEnv);
|
|
73
|
+
if (fetched.status !== 0) {
|
|
74
|
+
const detail = `pm workspace fetch failed: ${lastLine(fetched)}`;
|
|
75
|
+
log(detail);
|
|
76
|
+
return { ok: false, detail };
|
|
77
|
+
}
|
|
78
|
+
const pulled = git(run, ["-C", dir, "pull", "--ff-only"], childEnv);
|
|
79
|
+
if (pulled.status !== 0) {
|
|
80
|
+
const detail = `pm workspace pull skipped: ${lastLine(pulled)}`;
|
|
81
|
+
log(detail);
|
|
82
|
+
return { ok: false, detail };
|
|
83
|
+
}
|
|
84
|
+
const detail = `pm workspace ${dir} pulled`;
|
|
85
|
+
log(detail);
|
|
86
|
+
return { ok: true, detail };
|
|
87
|
+
}
|
package/lib/postgres.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Postgres for the message bus (schema bus) and the DBOS workflow engine. The container is defined in
|
|
3
|
+
* deploy/postgres/compose.yaml and bound to loopback only; the password lives in ~/.config/temmo/pg-password
|
|
4
|
+
* (0600) and the data under ~/.local/state/temmo/postgres, both owned by the user.
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import net from "node:net";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { configDir } from "./config.js";
|
|
12
|
+
const ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
13
|
+
// pg waits forever for a connection by default; a saturated server must fail the caller instead of hanging it.
|
|
14
|
+
export const PG_CONNECT_TIMEOUT_MS = 10_000;
|
|
15
|
+
/** The password file path: TEMMO_PG_PASSWORD_FILE, else <config dir>/pg-password. */
|
|
16
|
+
export function pgPasswordFile(env = process.env) {
|
|
17
|
+
if (env.TEMMO_PG_PASSWORD_FILE)
|
|
18
|
+
return env.TEMMO_PG_PASSWORD_FILE;
|
|
19
|
+
return path.join(configDir(env), "pg-password");
|
|
20
|
+
}
|
|
21
|
+
/** Creates the Postgres password file (0600) if absent; never overwrites. Returns {file, password, created}. */
|
|
22
|
+
export function ensurePgPassword({ env = process.env } = {}) {
|
|
23
|
+
const file = pgPasswordFile(env);
|
|
24
|
+
if (fs.existsSync(file)) {
|
|
25
|
+
if ((fs.statSync(file).mode & 0o777) !== 0o600)
|
|
26
|
+
fs.chmodSync(file, 0o600); // never leave a password world-readable
|
|
27
|
+
return { file, password: fs.readFileSync(file, "utf8").trim(), created: false };
|
|
28
|
+
}
|
|
29
|
+
const bytes = randomBytes(24);
|
|
30
|
+
let password = "";
|
|
31
|
+
for (const b of bytes)
|
|
32
|
+
password += ALPHABET[b % ALPHABET.length];
|
|
33
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
34
|
+
fs.writeFileSync(file, password, { mode: 0o600 });
|
|
35
|
+
fs.chmodSync(file, 0o600);
|
|
36
|
+
return { file, password, created: true };
|
|
37
|
+
}
|
|
38
|
+
/** The DBOS system database URL: loopback, user ai_collab, password from the file, database from
|
|
39
|
+
* TEMMO_PG_DATABASE (default ai_collab; tests use ai_collab_test). */
|
|
40
|
+
export function pgUrl(env = process.env) {
|
|
41
|
+
const { password } = ensurePgPassword({ env });
|
|
42
|
+
const database = env.TEMMO_PG_DATABASE || "ai_collab";
|
|
43
|
+
return `postgres://ai_collab:${password}@${env.TEMMO_PG_HOST || "127.0.0.1"}:${env.TEMMO_PG_PORT || "5432"}/${database}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Creates the TEMMO_PG_DATABASE database when missing, through the "postgres" maintenance database.
|
|
47
|
+
* Idempotent, so parallel test files may all call it. Returns the database name.
|
|
48
|
+
* pg is imported lazily: lib/*.mjs must import only builtins at load time (test/plugin-no-deps).
|
|
49
|
+
*/
|
|
50
|
+
export async function ensureDatabase(env = process.env) {
|
|
51
|
+
const database = env.TEMMO_PG_DATABASE || "ai_collab";
|
|
52
|
+
if (!/^[a-z_][a-z0-9_]*$/.test(database))
|
|
53
|
+
throw new Error(`postgres: invalid database name ${database}`);
|
|
54
|
+
const { password } = ensurePgPassword({ env });
|
|
55
|
+
const { default: pg } = await import("pg");
|
|
56
|
+
const admin = new pg.Pool({ connectionString: `postgres://ai_collab:${password}@${env.TEMMO_PG_HOST || "127.0.0.1"}:${env.TEMMO_PG_PORT || "5432"}/postgres`, connectionTimeoutMillis: PG_CONNECT_TIMEOUT_MS });
|
|
57
|
+
try {
|
|
58
|
+
const { rows } = await admin.query("SELECT 1 FROM pg_database WHERE datname = $1", [database]);
|
|
59
|
+
if (!rows.length) {
|
|
60
|
+
try {
|
|
61
|
+
await admin.query(`CREATE DATABASE ${database}`);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (!/already exists/.test(String(error?.message)))
|
|
65
|
+
throw error;
|
|
66
|
+
} // parallel creators: one wins
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await admin.end();
|
|
71
|
+
}
|
|
72
|
+
return database;
|
|
73
|
+
}
|
|
74
|
+
/** Postgres reachable? Exits non-zero when the container is down or the port is closed.
|
|
75
|
+
* Probes host:port only: a check must never create the password file pgUrl would read. */
|
|
76
|
+
export function pgReachable(env = process.env) {
|
|
77
|
+
const host = env.TEMMO_PG_HOST || "127.0.0.1";
|
|
78
|
+
const port = Number(env.TEMMO_PG_PORT || "5432");
|
|
79
|
+
return new Promise((resolve) => {
|
|
80
|
+
const sock = net.connect({ host, port });
|
|
81
|
+
const done = (ok) => { sock.destroy(); resolve(ok); };
|
|
82
|
+
sock.setTimeout(1500);
|
|
83
|
+
sock.on("connect", () => done(true));
|
|
84
|
+
sock.on("error", () => done(false));
|
|
85
|
+
sock.on("timeout", () => done(false));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* `temmo postgres <up|down|status>`: drives docker compose on deploy/postgres/compose.yaml.
|
|
90
|
+
* run and composeFile are injectable for tests. Returns an exit code.
|
|
91
|
+
*/
|
|
92
|
+
export function postgresCommand(argv = [], { env = process.env, run = defaultRun, composeFile = defaultComposeFile() } = {}) {
|
|
93
|
+
const sub = argv[0] || "status";
|
|
94
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by the runtime subcommand
|
|
95
|
+
const args = { up: ["compose", "-f", composeFile, "up", "-d"], down: ["compose", "-f", composeFile, "down"], status: ["compose", "-f", composeFile, "ps"] }[sub];
|
|
96
|
+
if (!args) {
|
|
97
|
+
process.stderr.write(`postgres: unknown command ${sub}; use up, down or status\n`);
|
|
98
|
+
return 2;
|
|
99
|
+
}
|
|
100
|
+
if (sub === "up")
|
|
101
|
+
ensurePgPassword({ env });
|
|
102
|
+
const r = run("docker", args);
|
|
103
|
+
if (r.stdout)
|
|
104
|
+
process.stdout.write(r.stdout);
|
|
105
|
+
if (r.code !== 0)
|
|
106
|
+
process.stderr.write(r.stderr || `postgres: docker ${sub} failed\n`);
|
|
107
|
+
return r.code;
|
|
108
|
+
}
|
|
109
|
+
function defaultComposeFile() {
|
|
110
|
+
return path.join(path.dirname(new URL(import.meta.url).pathname), "..", "deploy", "postgres", "compose.yaml");
|
|
111
|
+
}
|
|
112
|
+
function defaultRun(cmd, args) {
|
|
113
|
+
const r = spawnSync(cmd, args, { encoding: "utf8" });
|
|
114
|
+
return { code: r.status ?? 1, stdout: r.stdout || "", stderr: r.stderr || String(r.error?.message || "") };
|
|
115
|
+
}
|