@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,115 @@
|
|
|
1
|
+
/** Install this plugin tree for Cursor local plugins (same pattern as smarter-compact). */
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { packPluginCopy } from "./plugin-copy.js";
|
|
7
|
+
import { PACKAGE_NAME } from "./names.js";
|
|
8
|
+
export const PLUGIN_NAME = "temmo";
|
|
9
|
+
// Our entries in ~/.cursor/hooks.json are recognised by this path fragment, so reinstalling replaces them.
|
|
10
|
+
// Entries an install from before the rename wrote (plugins/local/ai-collab) count as ours too.
|
|
11
|
+
const OWN_HOOK = /\/plugins\/local\/(?:temmo|ai-collab)\/scripts\/(?:temmo|ai-collab)-hook/;
|
|
12
|
+
// The package files only (lib/plugin-copy.ts); hooks/ is dropped because Cursor would also run the Claude hooks in it.
|
|
13
|
+
function cleanCopy(src, dest) {
|
|
14
|
+
packPluginCopy(src, dest);
|
|
15
|
+
fs.rmSync(path.join(dest, "hooks"), { recursive: true, force: true });
|
|
16
|
+
}
|
|
17
|
+
export function cursorPluginDest(home = os.homedir()) {
|
|
18
|
+
return path.join(home, ".cursor", "plugins", "local", PLUGIN_NAME);
|
|
19
|
+
}
|
|
20
|
+
/** Walk up from the caller's file to the directory holding this package.json. */
|
|
21
|
+
export function packageRoot(importMetaUrl) {
|
|
22
|
+
let dir = path.dirname(fileURLToPath(importMetaUrl));
|
|
23
|
+
for (;;) {
|
|
24
|
+
const pkg = path.join(dir, "package.json");
|
|
25
|
+
if (fs.existsSync(pkg)) {
|
|
26
|
+
try {
|
|
27
|
+
if (JSON.parse(fs.readFileSync(pkg, "utf8")).name === PACKAGE_NAME)
|
|
28
|
+
return dir;
|
|
29
|
+
}
|
|
30
|
+
catch { /* keep walking */ }
|
|
31
|
+
}
|
|
32
|
+
const parent = path.dirname(dir);
|
|
33
|
+
if (parent === dir)
|
|
34
|
+
return null;
|
|
35
|
+
dir = parent;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Links (or with copy, copies) this package into Cursor's local plugins folder, then installs its hooks. */
|
|
39
|
+
export function installCursorPlugin({ home = os.homedir(), importMetaUrl, copy = false } = {}) {
|
|
40
|
+
const src = packageRoot(importMetaUrl);
|
|
41
|
+
if (!src)
|
|
42
|
+
return { ok: false, dest: "", mode: "copy", message: "package root not found" };
|
|
43
|
+
if (!fs.existsSync(path.join(src, ".cursor-plugin", "plugin.json"))) {
|
|
44
|
+
return { ok: false, dest: "", mode: "copy", message: `missing Cursor plugin manifest under ${src}` };
|
|
45
|
+
}
|
|
46
|
+
const dest = cursorPluginDest(home);
|
|
47
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
48
|
+
// The plugin folder an install from before the rename made; Cursor would load both.
|
|
49
|
+
fs.rmSync(path.join(path.dirname(dest), "ai-collab"), { recursive: true, force: true });
|
|
50
|
+
try {
|
|
51
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
catch { /* missing */ }
|
|
54
|
+
const mode = copy ? "copy" : "symlink";
|
|
55
|
+
try {
|
|
56
|
+
if (copy)
|
|
57
|
+
cleanCopy(src, dest);
|
|
58
|
+
else
|
|
59
|
+
fs.symlinkSync(src, dest, "dir");
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
if (!copy && err.code === "EPERM") {
|
|
63
|
+
cleanCopy(src, dest);
|
|
64
|
+
return { ok: true, dest, mode: "copy", message: "symlink failed; copied instead" };
|
|
65
|
+
}
|
|
66
|
+
return { ok: false, dest, mode, message: err.message };
|
|
67
|
+
}
|
|
68
|
+
const hooks = installCursorHooks({ home, src, dest });
|
|
69
|
+
const warning = copy ? "" : "symlinked: Cursor also runs the Claude hooks in hooks/hooks.json; use --copy";
|
|
70
|
+
const message = [hooks.ok ? "" : hooks.message, warning].filter(Boolean).join("; ");
|
|
71
|
+
return { ok: true, dest, mode, ...(message ? { message } : {}) };
|
|
72
|
+
}
|
|
73
|
+
/** Re-copies root over an installed Cursor plugin copy and re-merges its hooks; a symlinked or missing install is left alone. */
|
|
74
|
+
export function refreshCursorPlugin(root, home) {
|
|
75
|
+
const dest = cursorPluginDest(home);
|
|
76
|
+
if (!fs.lstatSync(dest, { throwIfNoEntry: false })?.isDirectory())
|
|
77
|
+
return false;
|
|
78
|
+
cleanCopy(root, dest);
|
|
79
|
+
const hooks = installCursorHooks({ home, src: root, dest });
|
|
80
|
+
if (!hooks.ok)
|
|
81
|
+
throw new Error(hooks.message);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Cursor's CLI runs only some plugin hooks (sessionStart, stop) but every hook in ~/.cursor/hooks.json, so ours go
|
|
86
|
+
* there: hooks/cursor-hooks.json with the plugin root resolved, replacing earlier temmo entries, keeping all others.
|
|
87
|
+
*/
|
|
88
|
+
export function installCursorHooks({ home = os.homedir(), src, dest = cursorPluginDest(home) }) {
|
|
89
|
+
const file = path.join(home, ".cursor", "hooks.json");
|
|
90
|
+
try {
|
|
91
|
+
const ours = JSON.parse(fs.readFileSync(path.join(src, "hooks", "cursor-hooks.json"), "utf8")).hooks;
|
|
92
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- replaced by the parsed hooks.json
|
|
93
|
+
let current = { version: 1, hooks: {} };
|
|
94
|
+
if (fs.existsSync(file))
|
|
95
|
+
current = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
96
|
+
const merged = {};
|
|
97
|
+
for (const [event, list] of Object.entries(current.hooks || {})) {
|
|
98
|
+
const kept = (Array.isArray(list) ? list : []).filter((h) => !OWN_HOOK.test(h?.command || ""));
|
|
99
|
+
if (kept.length)
|
|
100
|
+
merged[event] = kept;
|
|
101
|
+
}
|
|
102
|
+
for (const [event, list] of Object.entries(ours)) {
|
|
103
|
+
const resolved = list.map((h) => ({ ...h, command: h.command.replaceAll("${CURSOR_PLUGIN_ROOT}", dest) }));
|
|
104
|
+
merged[event] = [...(merged[event] || []), ...resolved];
|
|
105
|
+
}
|
|
106
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
107
|
+
const tmp = `${file}.temmo-${process.pid}`;
|
|
108
|
+
fs.writeFileSync(tmp, JSON.stringify({ ...current, version: current.version ?? 1, hooks: merged }, null, 2) + "\n");
|
|
109
|
+
fs.renameSync(tmp, file);
|
|
110
|
+
return { ok: true, file };
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
return { ok: false, file, message: `could not update ${file}: ${err.message}` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Installs the OpenCode 2 plugin (a shim in the global plugins folder), the temmo and temmo-code MCP servers, and the skills path.
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { packageRoot } from "./install-cursor.js";
|
|
7
|
+
export const OPENCODE_PLUGIN_FILE = "temmo.js";
|
|
8
|
+
export const MCP_NAME = "temmo";
|
|
9
|
+
export const CODE_MCP_NAME = "temmo-code";
|
|
10
|
+
// First line of the shim; a plugins/temmo.js without it belongs to someone else and is left alone.
|
|
11
|
+
const SHIM_MARK = "// temmo-managed";
|
|
12
|
+
/** OpenCode's global config folder: $XDG_CONFIG_HOME/opencode, else ~/.config/opencode. */
|
|
13
|
+
export function opencodeConfigDir({ home = os.homedir(), env = {} } = {}) {
|
|
14
|
+
return path.join(env.XDG_CONFIG_HOME || path.join(home, ".config"), "opencode");
|
|
15
|
+
}
|
|
16
|
+
/** The shim OpenCode loads from plugins/: it re-exports lib/opencode-plugin.mjs from this checkout. */
|
|
17
|
+
export function pluginShim(src) {
|
|
18
|
+
const url = pathToFileURL(path.join(src, "lib", "opencode-plugin.mjs")).href;
|
|
19
|
+
return `${SHIM_MARK}: written by scripts/install-opencode.mjs; rerun it to update.\nexport { default } from ${JSON.stringify(url)};\n`;
|
|
20
|
+
}
|
|
21
|
+
/** A local MCP server entry (default: the temmo server); cwd "." resolves to the session's workspace, where projects.json matching starts. */
|
|
22
|
+
export function mcpEntry(src, script = "temmo-mcp.mjs") {
|
|
23
|
+
return { type: "local", command: ["node", path.join(src, "scripts", script), "opencode"], cwd: ".", enabled: true };
|
|
24
|
+
}
|
|
25
|
+
// Writes through a temporary file and a rename, so OpenCode never reads a half-written file.
|
|
26
|
+
function writeAtomic(file, text) {
|
|
27
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
28
|
+
const tmp = `${file}.temmo-${process.pid}`;
|
|
29
|
+
fs.writeFileSync(tmp, text);
|
|
30
|
+
fs.renameSync(tmp, file);
|
|
31
|
+
}
|
|
32
|
+
/** Config with our MCP entry: under mcp.servers (what `opencode mcp add` writes), or flat when the file already lists servers flat. */
|
|
33
|
+
export function mergeMcp(config, entry, name = MCP_NAME) {
|
|
34
|
+
const out = { ...config };
|
|
35
|
+
const mcp = out.mcp && typeof out.mcp === "object" && !Array.isArray(out.mcp) ? { ...out.mcp } : {};
|
|
36
|
+
const flat = !mcp.servers && Object.values(mcp).some((v) => v && typeof v === "object" && ("command" in v || "url" in v));
|
|
37
|
+
if (flat)
|
|
38
|
+
mcp[name] = entry;
|
|
39
|
+
else
|
|
40
|
+
mcp.servers = { ...(mcp.servers && typeof mcp.servers === "object" ? mcp.servers : {}), [name]: entry };
|
|
41
|
+
out.mcp = mcp;
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
// Names an install from before the rename wrote; installing drops them so OpenCode does not run both servers.
|
|
45
|
+
const LEGACY_MCP_NAMES = ["ai-collab", "ai-collab-code"];
|
|
46
|
+
const LEGACY_PLUGIN_FILE = "ai-collab.js";
|
|
47
|
+
const LEGACY_SHIM_MARK = "// ai-collab-managed";
|
|
48
|
+
/** Config without the MCP entries an ai-collab install wrote, under mcp.servers or flat. */
|
|
49
|
+
export function dropLegacyMcp(config) {
|
|
50
|
+
if (!config.mcp || typeof config.mcp !== "object" || Array.isArray(config.mcp))
|
|
51
|
+
return config;
|
|
52
|
+
const mcp = { ...config.mcp };
|
|
53
|
+
if (mcp.servers && typeof mcp.servers === "object") {
|
|
54
|
+
mcp.servers = Object.fromEntries(Object.entries(mcp.servers).filter(([name]) => !LEGACY_MCP_NAMES.includes(name)));
|
|
55
|
+
}
|
|
56
|
+
for (const name of LEGACY_MCP_NAMES)
|
|
57
|
+
delete mcp[name];
|
|
58
|
+
return { ...config, mcp };
|
|
59
|
+
}
|
|
60
|
+
/** Config with a skills path added once; OpenCode's "skills" key lists extra folders to discover skills from. */
|
|
61
|
+
export function mergeSkills(config, dir) {
|
|
62
|
+
const add = (list) => [...list.filter((s) => s !== dir), dir];
|
|
63
|
+
// The object form ({paths, urls}) keeps its other keys; the path goes into paths.
|
|
64
|
+
if (config.skills && typeof config.skills === "object" && !Array.isArray(config.skills)) {
|
|
65
|
+
const paths = Array.isArray(config.skills.paths) ? config.skills.paths : [];
|
|
66
|
+
return { ...config, skills: { ...config.skills, paths: add(paths) } };
|
|
67
|
+
}
|
|
68
|
+
return { ...config, skills: add(Array.isArray(config.skills) ? config.skills : []) };
|
|
69
|
+
}
|
|
70
|
+
/** Writes plugins/temmo.js and opencode.json's mcp and skills entries, keeping other settings; refuses a foreign shim or bad JSON. */
|
|
71
|
+
export function installOpenCode({ home = os.homedir(), env = {}, importMetaUrl, src = importMetaUrl ? packageRoot(importMetaUrl) : null } = {}) {
|
|
72
|
+
if (!src)
|
|
73
|
+
return { ok: false, plugin: "", config: "", message: "package root not found" };
|
|
74
|
+
const dir = opencodeConfigDir({ home, env });
|
|
75
|
+
const plugin = path.join(dir, "plugins", OPENCODE_PLUGIN_FILE);
|
|
76
|
+
const config = path.join(dir, "opencode.json");
|
|
77
|
+
if (fs.existsSync(plugin) && !fs.readFileSync(plugin, "utf8").startsWith(SHIM_MARK)) {
|
|
78
|
+
return { ok: false, plugin, config, message: `${plugin} exists and was not written by temmo` };
|
|
79
|
+
}
|
|
80
|
+
let current = {};
|
|
81
|
+
if (fs.existsSync(config)) {
|
|
82
|
+
try {
|
|
83
|
+
current = JSON.parse(fs.readFileSync(config, "utf8"));
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
return { ok: false, plugin, config, message: `could not parse ${config}: ${err.message}` };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (fs.existsSync(path.join(dir, "opencode.jsonc"))) {
|
|
90
|
+
return { ok: false, plugin, config, message: `${path.join(dir, "opencode.jsonc")} has comments; add the mcp entry by hand (README, OpenCode)` };
|
|
91
|
+
}
|
|
92
|
+
try {
|
|
93
|
+
writeAtomic(plugin, pluginShim(src));
|
|
94
|
+
const legacy = path.join(dir, "plugins", LEGACY_PLUGIN_FILE);
|
|
95
|
+
if (fs.existsSync(legacy) && fs.readFileSync(legacy, "utf8").startsWith(LEGACY_SHIM_MARK))
|
|
96
|
+
fs.rmSync(legacy);
|
|
97
|
+
// Both servers: temmo, and temmo-code (run_code, docs/code-mode.md).
|
|
98
|
+
const servers = mergeMcp(mergeMcp(dropLegacyMcp(current), mcpEntry(src)), mcpEntry(src, "temmo-code-mcp.mjs"), CODE_MCP_NAME);
|
|
99
|
+
writeAtomic(config, JSON.stringify(mergeSkills(servers, path.join(src, "skills")), null, 2) + "\n");
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
return { ok: false, plugin, config, message: err.message };
|
|
103
|
+
}
|
|
104
|
+
return { ok: true, plugin, config };
|
|
105
|
+
}
|
package/lib/job.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
4
|
+
import { constants } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { assertHostAgent, managedShellStartRefusal } from "./agent-guard.js";
|
|
7
|
+
import { isRunning, processStart } from "./process.js";
|
|
8
|
+
import { writeState } from "./state.js";
|
|
9
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
10
|
+
const USAGE = "usage: temmo job run -- <command> [args...]";
|
|
11
|
+
/** Active commands for a local session. Process start times distinguish reused PIDs. */
|
|
12
|
+
export function runningJobs(registry, address, files) {
|
|
13
|
+
const prefix = address + ".job-";
|
|
14
|
+
let count = 0;
|
|
15
|
+
for (const name of files) {
|
|
16
|
+
if (!name.startsWith(prefix) || !/^[a-f0-9-]{36}\.json$/.test(name.slice(prefix.length)))
|
|
17
|
+
continue;
|
|
18
|
+
const file = join(registry, name);
|
|
19
|
+
try {
|
|
20
|
+
const job = JSON.parse(readFileSync(file, "utf8"));
|
|
21
|
+
if (typeof job.start === "string" && isRunning(job))
|
|
22
|
+
count++;
|
|
23
|
+
else
|
|
24
|
+
rmSync(file, { force: true });
|
|
25
|
+
}
|
|
26
|
+
catch { /* Missing or unreadable record. */ }
|
|
27
|
+
}
|
|
28
|
+
return count;
|
|
29
|
+
}
|
|
30
|
+
export async function job(argv, { cfg, env, out, err, registered }) {
|
|
31
|
+
if (argv.length === 0 || ["help", "--help", "-h"].includes(argv[0]) ||
|
|
32
|
+
(argv[0] === "run" && ["--help", "-h"].includes(argv[1]))) {
|
|
33
|
+
out.write(USAGE + "\n");
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const [sub, separator, command, ...args] = argv;
|
|
37
|
+
if (sub !== "run" || separator !== "--" || !command) {
|
|
38
|
+
err.write(USAGE + "\n");
|
|
39
|
+
return 2;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
if (!cfg.enabled)
|
|
43
|
+
throw new Error(cfg.reason);
|
|
44
|
+
const address = `${cfg.peer}#${cfg.session}`;
|
|
45
|
+
if (!cfg.session || !registered(cfg, address)) {
|
|
46
|
+
throw new Error("Set TEMMO_PEER and TEMMO_SESSION to your registered session");
|
|
47
|
+
}
|
|
48
|
+
const managed = managedShellStartRefusal([command, ...args], env);
|
|
49
|
+
if (managed)
|
|
50
|
+
throw new Error(managed);
|
|
51
|
+
assertHostAgent([command, ...args], { env });
|
|
52
|
+
const file = join(cfg.stateDir, cfg.project, "registry", address + ".job-" + randomUUID() + ".json");
|
|
53
|
+
const child = spawn(command, args, { env, stdio: "inherit" });
|
|
54
|
+
const completion = new Promise((resolve, reject) => {
|
|
55
|
+
child.once("error", reject);
|
|
56
|
+
child.once("exit", (code, signal) => resolve(code ?? 128 + (signal ? constants.signals[signal] : 0)));
|
|
57
|
+
});
|
|
58
|
+
const handlers = SIGNALS.map((signal) => [signal, () => child.kill(signal)]);
|
|
59
|
+
for (const [signal, handler] of handlers)
|
|
60
|
+
process.on(signal, handler);
|
|
61
|
+
try {
|
|
62
|
+
const start = child.pid && processStart(child.pid);
|
|
63
|
+
if (start)
|
|
64
|
+
writeState(file, { pid: child.pid, start });
|
|
65
|
+
return await completion;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
child.kill("SIGKILL");
|
|
69
|
+
await completion.catch(() => { });
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
for (const [signal, handler] of handlers)
|
|
74
|
+
process.off(signal, handler);
|
|
75
|
+
rmSync(file, { force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
err.write(`temmo: job: ${error.message}\n`);
|
|
80
|
+
return error.code === "ENOENT" ? 127 : 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
package/lib/land-cli.js
ADDED
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// `temmo land request|finish <branch>` on any agent checkout; `temmo deploy` on the host: main, or any tree with --from.
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { parseArgs } from "node:util";
|
|
5
|
+
import { broadcastTopic, stateDir } from "./config.js";
|
|
6
|
+
import { checkoutBranch, deployLink, dbosVersion, dirty, inFlight, installUnits, pointLink, readLink, resolveSource, unitsInstalled } from "./deploy-tree.js";
|
|
7
|
+
import { AUTO_DEPLOY_TIMEOUT_MS, HOST_CHECKOUT, deployHost, execRun, finishBranch, mergeNode, npmCommand, readLastDeploy, requestLand, restartServices, writeLastDeploy } from "./land.js";
|
|
8
|
+
import { operatorConfigs } from "./mode.js";
|
|
9
|
+
import { installedServices } from "./names.js";
|
|
10
|
+
import { pluginUpdateCommands, refreshPluginCopies } from "./plugin-copy.js";
|
|
11
|
+
import { refreshCursorPlugin } from "./install-cursor.js";
|
|
12
|
+
import { publish } from "./messaging.js";
|
|
13
|
+
import { withLock } from "./state.js";
|
|
14
|
+
import { openTasks } from "./tasks.js";
|
|
15
|
+
import { passJs } from "./surfaces/types.js";
|
|
16
|
+
const LAND_USAGE = `Usage: temmo land request <branch> [--proof <file>] [--title "<text>"] [--description <file>]
|
|
17
|
+
Pushes <branch> (never main) and opens its PR into main, or reuses the open one. Prints the PR URL.
|
|
18
|
+
Without flags the title and body come from the commits. --proof adds the commits and proof to the body;
|
|
19
|
+
--title and --description let the author choose the PR title and body (write them; do not settle for the log).
|
|
20
|
+
Usage: temmo land finish <branch> [--proof <file>] [--title "<text>"] [--description <file>] [--landing pr|packet|branch] [--task <id>]
|
|
21
|
+
The default is a draft PR with the proof in its body when origin is GitHub and gh is signed in, else a
|
|
22
|
+
review packet on the project's task board; never pushes main.
|
|
23
|
+
`;
|
|
24
|
+
const DEPLOY_USAGE = `Usage: temmo deploy [--if-moved] [--force]
|
|
25
|
+
temmo deploy --main [--force]
|
|
26
|
+
temmo deploy --from <worktree-path|branch> [--allow-dirty] [--force]
|
|
27
|
+
temmo deploy --install-units
|
|
28
|
+
Runs on the PM host (Linux, systemd user units). Plain deploy uses ${HOST_CHECKOUT}: refuses a dirty checkout or one
|
|
29
|
+
not on main, pulls --ff-only, and when HEAD moved runs npm ci --include=dev and npm run build. Every deploy then
|
|
30
|
+
points the deploy link at the tree, restarts temmo-ui once, verifies it, publishes one result line to the operator
|
|
31
|
+
channel, and restarts temmo-bus and temmo-runner in a transient unit.
|
|
32
|
+
--if-moved do nothing unless origin/main differs from the last deployed main (the auto-deploy schedule uses it)
|
|
33
|
+
--from deploy a worktree (a path starting with /, ./ or ../) or a branch, checked out detached under
|
|
34
|
+
~/.cache/temmo-deploy/<branch>; plain deploys and --if-moved hold until --main
|
|
35
|
+
--main return the services to ${HOST_CHECKOUT} on main
|
|
36
|
+
--allow-dirty deploy a --from tree with tracked changes
|
|
37
|
+
--force restart despite in-flight runner turns or a DBOS app-version change
|
|
38
|
+
--install-units one-time: write deploy-tree.conf drop-ins so the units run through the deploy link, then daemon-reload
|
|
39
|
+
Prints: deployed <old>..<new> | deployed <ref> <sha> | skipped: <reason> | failed: <reason>
|
|
40
|
+
`;
|
|
41
|
+
const DEPLOY_OPTIONS = {
|
|
42
|
+
from: { type: "string" }, main: { type: "boolean" }, "if-moved": { type: "boolean" }, force: { type: "boolean" },
|
|
43
|
+
"allow-dirty": { type: "boolean" }, "install-units": { type: "boolean" }, help: { type: "boolean" },
|
|
44
|
+
};
|
|
45
|
+
// The UI restarts in-process before its verify; the bus and runner restart last, in a transient unit.
|
|
46
|
+
const SHORT = 12;
|
|
47
|
+
const lastLine = (text = "") => text.trim().split("\n").pop() ?? "";
|
|
48
|
+
const skipped = (reason) => ({ status: "skipped", line: `skipped: ${reason}` });
|
|
49
|
+
const failed = (reason) => ({ status: "failed", line: `failed: ${reason}` });
|
|
50
|
+
// The operator channel: one line per operator config on its broadcast topic.
|
|
51
|
+
async function publishToOperators(line, env) {
|
|
52
|
+
// operatorConfigs keeps only enabled configs.
|
|
53
|
+
const configs = passJs(operatorConfigs(env));
|
|
54
|
+
await Promise.all(configs.map((cfg) => publish(cfg, broadcastTopic(cfg.project), line, { title: "temmo: deploy" })));
|
|
55
|
+
}
|
|
56
|
+
// Reads `land` flags (--proof, --title, --description plus any extra allowed flags); null on an unknown flag or a missing value.
|
|
57
|
+
function landFlags(rest, extra = []) {
|
|
58
|
+
const flags = {};
|
|
59
|
+
for (let i = 0; i < rest.length; i++) {
|
|
60
|
+
const name = rest[i];
|
|
61
|
+
const value = rest[++i];
|
|
62
|
+
if (value === undefined || !["--proof", "--title", "--description", ...extra].includes(name))
|
|
63
|
+
return null;
|
|
64
|
+
flags[name.slice(2)] = value;
|
|
65
|
+
}
|
|
66
|
+
return flags;
|
|
67
|
+
}
|
|
68
|
+
export async function land(args, { out, err, run = execRun, cwd = process.cwd(), env = process.env, cfg = {} }) {
|
|
69
|
+
if (args.length === 0 || args[0] === "help" || args.includes("--help")) {
|
|
70
|
+
out.write(LAND_USAGE);
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
const [action, branch, ...rest] = args;
|
|
74
|
+
if (action === "request") {
|
|
75
|
+
const flags = branch ? landFlags(rest) : null;
|
|
76
|
+
if (!branch || flags === null) {
|
|
77
|
+
err.write(LAND_USAGE);
|
|
78
|
+
return 1;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const proof = flags.proof === undefined ? undefined : readFileSync(flags.proof, "utf8");
|
|
82
|
+
const description = flags.description === undefined ? undefined : readFileSync(flags.description, "utf8");
|
|
83
|
+
const { url } = await requestLand(branch, { run, cwd, ...(proof !== undefined ? { proof } : {}), ...(flags.title ? { title: flags.title } : {}), ...(description !== undefined ? { description } : {}) });
|
|
84
|
+
out.write(`${url}\n`);
|
|
85
|
+
return 0;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
err.write(`temmo: land: ${error.message}\n`);
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const flags = action === "finish" && branch ? landFlags(rest, ["--landing", "--task"]) : null;
|
|
93
|
+
if (!flags) {
|
|
94
|
+
err.write(LAND_USAGE);
|
|
95
|
+
return 1;
|
|
96
|
+
}
|
|
97
|
+
const { proof: proofFile, landing, task, title, description: descriptionFile } = flags;
|
|
98
|
+
if (!proofFile && landing !== "branch") {
|
|
99
|
+
err.write("temmo: land: finish needs --proof <file> unless --landing branch\n");
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
const proof = proofFile ? readFileSync(proofFile, "utf8") : "";
|
|
104
|
+
const description = descriptionFile ? readFileSync(descriptionFile, "utf8") : undefined;
|
|
105
|
+
const by = cfg.peer && cfg.session ? `${cfg.peer}#${cfg.session}` : cfg.peer || "cli";
|
|
106
|
+
// The store opens only when the packet path uses it; without a project that path refuses.
|
|
107
|
+
const noBoard = () => { throw new Error("the packet landing needs a project task board: set TEMMO_PROJECT or pass --landing pr|branch"); };
|
|
108
|
+
const tasks = cfg.project ? openTasks(cfg.project, env) : { add: noBoard, submitReview: noBoard };
|
|
109
|
+
const result = await finishBranch(branch, passJs({ run, cwd, proof, tasks, by, ...(landing ? { landing } : {}), ...(task ? { task } : {}), ...(title ? { title } : {}), ...(description !== undefined ? { description } : {}) }));
|
|
110
|
+
if (result.landing === "pr")
|
|
111
|
+
out.write(`pr: ${result.url}${result.created ? "" : " (existing)"}\n`);
|
|
112
|
+
else if (result.landing === "packet")
|
|
113
|
+
out.write(`packet: task ${result.task}\n`);
|
|
114
|
+
else
|
|
115
|
+
out.write(`branch: pushed ${result.branch}\n`);
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
err.write(`temmo: land: ${error.message}\n`);
|
|
120
|
+
return 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function parseDeploy(args) {
|
|
124
|
+
let flags;
|
|
125
|
+
try {
|
|
126
|
+
const parsed = parseArgs({ args, options: DEPLOY_OPTIONS, strict: true, allowPositionals: true });
|
|
127
|
+
if (parsed.positionals.length && !(parsed.positionals.length === 1 && parsed.positionals[0] === "help"))
|
|
128
|
+
return { flags: null };
|
|
129
|
+
flags = { ...parsed.values, ...(parsed.positionals[0] === "help" ? { help: true } : {}) };
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
return { flags: null, message: error.message };
|
|
133
|
+
}
|
|
134
|
+
const modes = [flags.from !== undefined, Boolean(flags.main), Boolean(flags["install-units"])].filter(Boolean).length;
|
|
135
|
+
if (modes > 1 || (flags["if-moved"] && (flags.from !== undefined || flags.main)))
|
|
136
|
+
return { flags: null };
|
|
137
|
+
if (flags["install-units"] && (flags.force || flags["allow-dirty"] || flags["if-moved"]))
|
|
138
|
+
return { flags: null };
|
|
139
|
+
if (flags["allow-dirty"] && flags.from === undefined)
|
|
140
|
+
return { flags: null };
|
|
141
|
+
return { flags };
|
|
142
|
+
}
|
|
143
|
+
export async function deploy(args, { env = process.env, out, err, run = execRun, hostCheckout = HOST_CHECKOUT, npm, nodePath = process.execPath, publish: send = publishToOperators, cwd = process.cwd(), inflight = inFlight, }) {
|
|
144
|
+
const { flags, message } = parseDeploy(args);
|
|
145
|
+
if (flags?.help) {
|
|
146
|
+
out.write(DEPLOY_USAGE);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
if (!flags) {
|
|
150
|
+
if (message)
|
|
151
|
+
err.write(`temmo: deploy: ${message}\n`);
|
|
152
|
+
err.write(DEPLOY_USAGE);
|
|
153
|
+
return 1;
|
|
154
|
+
}
|
|
155
|
+
if (flags["install-units"]) {
|
|
156
|
+
try {
|
|
157
|
+
const services = installedServices(env);
|
|
158
|
+
for (const path of await installUnits({ env, hostCheckout, run, services }))
|
|
159
|
+
out.write(`wrote ${path}\n`);
|
|
160
|
+
out.write(`run once: systemctl --user restart ${services.join(" ")}\n`);
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
err.write(`temmo: deploy: ${error.message}\n`);
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (flags.from !== undefined && !unitsInstalled(env, installedServices(env))) {
|
|
169
|
+
err.write(`temmo: deploy: the units do not run through ${deployLink(env)}; run temmo deploy --install-units once\n`);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
// One deploy at a time: a second run (the timer while a deploy is slow) reports and leaves.
|
|
173
|
+
// The lock records its owner pid, so a lock left by a crash is taken over; staleMs covers a full deploy.
|
|
174
|
+
const locked = await withLock(join(stateDir(env), "deploy"), async () => {
|
|
175
|
+
try {
|
|
176
|
+
return await deployTree(flags, { env, run, hostCheckout, npm, nodePath, cwd, inflight });
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
return failed(error.message.split("\n")[0]);
|
|
180
|
+
}
|
|
181
|
+
}, { waitMs: 0, staleMs: AUTO_DEPLOY_TIMEOUT_MS });
|
|
182
|
+
if (!locked.locked) {
|
|
183
|
+
out.write("skipped: another deploy is running\n");
|
|
184
|
+
return 0;
|
|
185
|
+
}
|
|
186
|
+
const result = locked.value;
|
|
187
|
+
if (result.status === "unchanged")
|
|
188
|
+
return 0;
|
|
189
|
+
out.write(`${result.line}\n`);
|
|
190
|
+
// A repeated skip (same reason as the last recorded result) stays off the operator channel.
|
|
191
|
+
const last = readLastDeploy(env);
|
|
192
|
+
const repeat = result.status === "skipped" && last?.status === "skipped" && last.line === result.line;
|
|
193
|
+
if (!repeat)
|
|
194
|
+
await send(result.line ?? "", env).catch((error) => err.write(`temmo: deploy: publish failed: ${error.message}\n`));
|
|
195
|
+
// deployed is the main commit last shipped; a skip, a failure or another tree carries it over.
|
|
196
|
+
const shipped = result.status === "deployed" && result.ref === "main" ? result.to : last?.deployed;
|
|
197
|
+
// ref, tree and sha follow the link: set by the deploy that pointed it, else carried over.
|
|
198
|
+
const live = result.tree ? { ref: result.ref, tree: result.tree, sha: result.sha } : { ref: last?.ref, tree: last?.tree, sha: last?.sha };
|
|
199
|
+
writeLastDeploy(env, {
|
|
200
|
+
at: new Date().toISOString(), status: result.status, line: result.line, ...(shipped ? { deployed: shipped } : {}),
|
|
201
|
+
...(live.ref ? live : {}),
|
|
202
|
+
});
|
|
203
|
+
if (result.status === "failed")
|
|
204
|
+
return 1;
|
|
205
|
+
if (result.status !== "deployed")
|
|
206
|
+
return 0;
|
|
207
|
+
// Last: the restart stops the runner, so everything else is recorded first.
|
|
208
|
+
// The UI restarted with the build; the bus and runner restart here, under whichever names are installed.
|
|
209
|
+
const restart = await restartServices({ run, services: installedServices(env, ["bus", "runner"]) });
|
|
210
|
+
if (restart.status !== 0) {
|
|
211
|
+
err.write(`temmo: deploy: restart failed: ${lastLine(restart.stderr) || `exit ${restart.status}`}\n`);
|
|
212
|
+
return 1;
|
|
213
|
+
}
|
|
214
|
+
return 0;
|
|
215
|
+
}
|
|
216
|
+
/** Builds the chosen tree, then points the link at it, restarts the UI once and verifies it. */
|
|
217
|
+
async function deployTree(flags, { env, run, hostCheckout, npm, nodePath, cwd, inflight }) {
|
|
218
|
+
const linked = readLink(env);
|
|
219
|
+
const held = linked !== null && linked !== hostCheckout;
|
|
220
|
+
const last = readLastDeploy(env);
|
|
221
|
+
if (held && flags.from === undefined && !flags.main) {
|
|
222
|
+
if (flags["if-moved"])
|
|
223
|
+
return { status: "unchanged" };
|
|
224
|
+
return skipped(`${last?.ref ?? linked} is deployed; run temmo deploy --main to return`);
|
|
225
|
+
}
|
|
226
|
+
// Read before any checkout: the version the running services use.
|
|
227
|
+
const runningDbos = dbosVersion(held ? linked : hostCheckout);
|
|
228
|
+
const preflight = async (tree) => {
|
|
229
|
+
if (flags.force)
|
|
230
|
+
return null;
|
|
231
|
+
const reasons = [];
|
|
232
|
+
const turns = await inflight(env);
|
|
233
|
+
if (turns.length)
|
|
234
|
+
reasons.push(`${turns.length} runner turn(s) in flight (${turns.join(", ")})`);
|
|
235
|
+
const target = dbosVersion(tree);
|
|
236
|
+
if (runningDbos && target && runningDbos !== target)
|
|
237
|
+
reasons.push(`DBOS app version changes ${runningDbos} -> ${target}`);
|
|
238
|
+
return reasons.length ? `${reasons.join("; ")}; --force restarts anyway` : null;
|
|
239
|
+
};
|
|
240
|
+
let built;
|
|
241
|
+
if (flags.from === undefined) {
|
|
242
|
+
const result = await deployHost(passJs({
|
|
243
|
+
run, hostCheckout, env, ifMoved: Boolean(flags["if-moved"]), nodePath, npm, deployed: last?.deployed,
|
|
244
|
+
build: ["run", "build"], returning: Boolean(flags.main) && held, check: () => preflight(hostCheckout),
|
|
245
|
+
}));
|
|
246
|
+
if (result.status !== "deployed")
|
|
247
|
+
return result;
|
|
248
|
+
built = { ...result, tree: hostCheckout, ref: "main", sha: result.to ?? "" };
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const source = await resolveSource(flags.from, { run, hostCheckout, env, cwd });
|
|
252
|
+
const { tree, ref } = source;
|
|
253
|
+
let sha;
|
|
254
|
+
if (source.kind === "branch")
|
|
255
|
+
sha = await checkoutBranch({ run, hostCheckout, tree, branch: ref });
|
|
256
|
+
else
|
|
257
|
+
sha = (await run("git", ["rev-parse", "HEAD"], { cwd: tree, encoding: "utf8" })).stdout.trim();
|
|
258
|
+
if (!flags["allow-dirty"] && await dirty(run, tree))
|
|
259
|
+
return skipped(`${tree} has local changes; --allow-dirty deploys them`);
|
|
260
|
+
const before = await preflight(tree);
|
|
261
|
+
if (before)
|
|
262
|
+
return skipped(before);
|
|
263
|
+
const [npmFile, ...npmArgs] = npm ?? npmCommand(mergeNode(nodePath, tree, env), env.PATH);
|
|
264
|
+
const npmRun = (argv) => run(npmFile, [...npmArgs, ...argv], { cwd: tree, env, encoding: "utf8" });
|
|
265
|
+
const ci = await npmRun(["ci", "--include=dev"]);
|
|
266
|
+
if (ci.status !== 0)
|
|
267
|
+
return failed(`npm ci --include=dev exited ${ci.status}`);
|
|
268
|
+
const build = await npmRun(["run", "build"]);
|
|
269
|
+
if (build.status !== 0)
|
|
270
|
+
return failed(`UI build exited ${build.status}`);
|
|
271
|
+
built = { status: "deployed", line: `deployed ${ref} ${sha.slice(0, SHORT)}`, tree, ref, sha };
|
|
272
|
+
}
|
|
273
|
+
// Turns may have started during the build.
|
|
274
|
+
const late = await preflight(built.tree);
|
|
275
|
+
if (late)
|
|
276
|
+
return skipped(late);
|
|
277
|
+
pointLink(env, built.tree);
|
|
278
|
+
const restart = await run("systemctl", ["--user", "restart", `${installedServices(env, ["ui"])[0]}.service`], { encoding: "utf8" });
|
|
279
|
+
if (restart.status !== 0)
|
|
280
|
+
return { ...built, ...failed(`UI restart exited ${restart.status}`) };
|
|
281
|
+
const verify = await run(nodePath, [join(built.tree, "deploy", "verify-ui.mjs")], { cwd: built.tree, env, encoding: "utf8" });
|
|
282
|
+
if (verify.status !== 0)
|
|
283
|
+
return { ...built, ...failed(`UI verify exited ${verify.status}`) };
|
|
284
|
+
// Without this, installed plugin copies keep the code from the last temmo setup.
|
|
285
|
+
if (!env.HOME)
|
|
286
|
+
return built;
|
|
287
|
+
try {
|
|
288
|
+
const peers = refreshPluginCopies(built.tree, env.HOME);
|
|
289
|
+
const failures = await updateInstalledPlugins(run, env, peers);
|
|
290
|
+
if (refreshCursorPlugin(built.tree, env.HOME))
|
|
291
|
+
peers.push("cursor");
|
|
292
|
+
const line = [built.line, ...(peers.length ? [`refreshed ${peers.join(", ")} plugin`] : []), ...failures].join("; ");
|
|
293
|
+
return { ...built, line };
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
// The services already run the new tree; a stale plugin copy is reported, not a failed deploy.
|
|
297
|
+
return { ...built, line: `${built.line}; plugin refresh failed: ${error.message}` };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// A fresh copy alone leaves Claude and Codex on the version they installed; they load the update on restart.
|
|
301
|
+
async function updateInstalledPlugins(run, env, peers) {
|
|
302
|
+
const failures = [];
|
|
303
|
+
for (const peer of peers) {
|
|
304
|
+
for (const args of pluginUpdateCommands(peer)) {
|
|
305
|
+
const cmd = `${peer} ${args.join(" ")}`;
|
|
306
|
+
try {
|
|
307
|
+
const r = await run(peer, args, { env, encoding: "utf8" });
|
|
308
|
+
if (r.status === 0)
|
|
309
|
+
continue;
|
|
310
|
+
failures.push(`${cmd} failed: ${(r.stderr || r.stdout || `exit ${r.status}`).trim().split("\n").pop()}`);
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
failures.push(`${cmd} failed: ${error.message}`);
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return failures;
|
|
319
|
+
}
|