@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
package/lib/setup.js
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `temmo setup`: writes defaults.json with a bus token, installs the local message bus and every
|
|
3
|
+
* detected harness plugin and the UI user service, then prints phone-access steps. Reruns skip finished steps.
|
|
4
|
+
*/
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import os from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { parseArgs } from "node:util";
|
|
11
|
+
import { productionDistDir } from "./ui-build-output.js";
|
|
12
|
+
import { configDir } from "./config.js";
|
|
13
|
+
import { ensureOperatorToken, operatorTokenFile } from "./operator-token.js";
|
|
14
|
+
import { pgReachable } from "./postgres.js";
|
|
15
|
+
import { inFlight } from "./deploy-tree.js";
|
|
16
|
+
import { legacyUnitsInstalled, migrateDirs, migrateUnits } from "./rename-migration.js";
|
|
17
|
+
import { readJson } from "./store.js";
|
|
18
|
+
import { PLUGIN_COPY_MAX_BYTES, packPluginCopy, pluginUpdateCommands } from "./plugin-copy.js";
|
|
19
|
+
export { PLUGIN_COPY_MAX_BYTES, packPluginCopy };
|
|
20
|
+
import { installCursorPlugin, packageRoot } from "./install-cursor.js";
|
|
21
|
+
import { installOpenCode } from "./install-opencode.js";
|
|
22
|
+
import { piMissing, piVersionProblem } from "./pi.js";
|
|
23
|
+
const BUS_PORT = 8794;
|
|
24
|
+
const UI_PORT = 8795;
|
|
25
|
+
// npx unpacks into a cache that npm may delete; setup moves itself here so plugins and the UI keep a stable path.
|
|
26
|
+
const APP_DIR = [".local", "share", "temmo", "app"];
|
|
27
|
+
// Claude and Codex copy their marketplace folder; a checkout with worktrees once made a 42 GB plugin cache.
|
|
28
|
+
const SHARE_DIR = [".local", "share", "temmo"];
|
|
29
|
+
const SKIP_COPY = new Set(["node_modules", ".git", path.join("web", ".next"), path.join("web", ".next-demo"), path.join("web", ".next-builds"), "site"]);
|
|
30
|
+
const OPTIONS = { port: { type: "string" }, "no-ui": { type: "boolean" }, agent: { type: "string", multiple: true }, force: { type: "boolean" } };
|
|
31
|
+
const HARNESSES = [
|
|
32
|
+
{ peer: "claude", bin: "claude" },
|
|
33
|
+
{ peer: "codex", bin: "codex" },
|
|
34
|
+
// Cursor renamed its CLI to `agent`; the older `cursor-agent` still counts as installed.
|
|
35
|
+
{ peer: "cursor", bin: "agent", fallback: "cursor-agent" },
|
|
36
|
+
{ peer: "opencode", bin: "opencode" },
|
|
37
|
+
{ peer: "pi", bin: "pi" },
|
|
38
|
+
];
|
|
39
|
+
/** Whether one harness's CLI is installed: its binary, or else the fallback name older installs use. */
|
|
40
|
+
function installed(h, env, which) {
|
|
41
|
+
return which(h.bin, env) || (h.fallback ? which(h.fallback, env) : "");
|
|
42
|
+
}
|
|
43
|
+
function defaultRun(cmd, args, opts = {}) {
|
|
44
|
+
const r = spawnSync(cmd, args, { encoding: "utf8", ...opts, env: { ...process.env, ...opts.env } });
|
|
45
|
+
return { code: r.status ?? 1, stdout: r.stdout || "", stderr: r.stderr || String(r.error?.message || "") };
|
|
46
|
+
}
|
|
47
|
+
function defaultWhich(bin, env) {
|
|
48
|
+
for (const dir of String(env.PATH || "").split(path.delimiter)) {
|
|
49
|
+
if (dir && fs.existsSync(path.join(dir, bin)))
|
|
50
|
+
return path.join(dir, bin);
|
|
51
|
+
}
|
|
52
|
+
return "";
|
|
53
|
+
}
|
|
54
|
+
function writePrivate(file, text) {
|
|
55
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
56
|
+
fs.writeFileSync(file, text, { mode: 0o600 });
|
|
57
|
+
fs.chmodSync(file, 0o600);
|
|
58
|
+
}
|
|
59
|
+
// A bus token: tk_ plus 29 lowercase alphanumerics, the shape older ntfy tokens had.
|
|
60
|
+
function busToken() {
|
|
61
|
+
const alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
62
|
+
const bytes = randomBytes(29);
|
|
63
|
+
let out = "";
|
|
64
|
+
for (const b of bytes)
|
|
65
|
+
out += alphabet[b % alphabet.length];
|
|
66
|
+
return `tk_${out}`;
|
|
67
|
+
}
|
|
68
|
+
function busUnit(root, port) {
|
|
69
|
+
// No start limit: a bus that exits while Postgres restarts keeps retrying every RestartSec until Postgres is back.
|
|
70
|
+
return `[Unit]
|
|
71
|
+
Description=Temmo message bus
|
|
72
|
+
StartLimitIntervalSec=0
|
|
73
|
+
|
|
74
|
+
[Service]
|
|
75
|
+
ExecStart=${process.execPath} ${path.join(root, "scripts", "temmo-bus.mjs")}
|
|
76
|
+
Environment=TEMMO_BUS_PORT=${port}
|
|
77
|
+
Restart=on-failure
|
|
78
|
+
RestartSec=2
|
|
79
|
+
UMask=0077
|
|
80
|
+
|
|
81
|
+
[Install]
|
|
82
|
+
WantedBy=default.target
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
// Installs and starts the bus user service; an existing unit is left alone.
|
|
86
|
+
function installBus({ root, home, run, which, env, port }) {
|
|
87
|
+
const unit = path.join(home, ".config", "systemd", "user", "temmo-bus.service");
|
|
88
|
+
if (fs.existsSync(unit))
|
|
89
|
+
return `kept ${unit}`;
|
|
90
|
+
if (!which("systemctl", env))
|
|
91
|
+
return `no systemd: run \`node ${path.join(root, "scripts", "temmo-bus.mjs")}\` in the background`;
|
|
92
|
+
fs.mkdirSync(path.dirname(unit), { recursive: true });
|
|
93
|
+
fs.writeFileSync(unit, busUnit(root, port));
|
|
94
|
+
run("systemctl", ["--user", "daemon-reload"]);
|
|
95
|
+
const r = run("systemctl", ["--user", "enable", "--now", "temmo-bus"]);
|
|
96
|
+
return r.code === 0 ? `running on http://127.0.0.1:${port}` : `systemctl enable failed: ${r.stderr.trim()}`;
|
|
97
|
+
}
|
|
98
|
+
// Codex VS Code loads a plugin's hooks and skills but not its mcpServers, so an interactive Codex
|
|
99
|
+
// gets no bus tools from the plugin alone. config.toml mcp_servers load in every Codex surface, and
|
|
100
|
+
// Codex keys servers by name, so these coexist with the plugin's and the runner's -c declarations.
|
|
101
|
+
const CODEX_FRAGMENT_BEGIN = "# BEGIN TEMMO MANAGED CODEX CONFIG FRAGMENT";
|
|
102
|
+
const CODEX_FRAGMENT_END = "# END TEMMO MANAGED CODEX CONFIG FRAGMENT";
|
|
103
|
+
// The fragment an install from before the rename wrote ([mcp_servers.ai-collab]); replaced by ours.
|
|
104
|
+
const LEGACY_FRAGMENT_BEGIN = "# BEGIN AI-COLLAB MANAGED CODEX CONFIG FRAGMENT";
|
|
105
|
+
const LEGACY_FRAGMENT_END = "# END AI-COLLAB MANAGED CODEX CONFIG FRAGMENT";
|
|
106
|
+
function codexMcpFragment(pluginDir) {
|
|
107
|
+
const script = (name) => JSON.stringify(path.join(pluginDir, "scripts", `${name}-mcp.mjs`));
|
|
108
|
+
return [
|
|
109
|
+
CODEX_FRAGMENT_BEGIN,
|
|
110
|
+
"[mcp_servers.temmo]",
|
|
111
|
+
'command = "node"',
|
|
112
|
+
`args = [${script("temmo")}, "codex"]`,
|
|
113
|
+
"",
|
|
114
|
+
"[mcp_servers.temmo-code]",
|
|
115
|
+
'command = "node"',
|
|
116
|
+
`args = [${script("temmo-code")}, "codex"]`,
|
|
117
|
+
"tool_timeout_sec = 150",
|
|
118
|
+
CODEX_FRAGMENT_END,
|
|
119
|
+
].join("\n");
|
|
120
|
+
}
|
|
121
|
+
/** Write or refresh the managed mcp_servers fragment in a Codex config.toml; says what changed. */
|
|
122
|
+
export function ensureCodexMcpServers(file, pluginDir) {
|
|
123
|
+
const fragment = codexMcpFragment(pluginDir);
|
|
124
|
+
let existing = fs.existsSync(file) ? fs.readFileSync(file, "utf8") : "";
|
|
125
|
+
const oldBegin = existing.indexOf(LEGACY_FRAGMENT_BEGIN);
|
|
126
|
+
const oldEnd = existing.indexOf(LEGACY_FRAGMENT_END);
|
|
127
|
+
let dropped = false;
|
|
128
|
+
if (oldBegin >= 0 && oldEnd > oldBegin) {
|
|
129
|
+
existing = existing.slice(0, oldBegin) + existing.slice(oldEnd + LEGACY_FRAGMENT_END.length).replace(/^\n+/, "");
|
|
130
|
+
dropped = true;
|
|
131
|
+
}
|
|
132
|
+
const begin = existing.indexOf(CODEX_FRAGMENT_BEGIN);
|
|
133
|
+
const end = existing.indexOf(CODEX_FRAGMENT_END);
|
|
134
|
+
let next;
|
|
135
|
+
let action;
|
|
136
|
+
if (begin >= 0 && end > begin) {
|
|
137
|
+
const stop = end + CODEX_FRAGMENT_END.length;
|
|
138
|
+
if (existing.slice(begin, stop) === fragment && !dropped)
|
|
139
|
+
return "kept";
|
|
140
|
+
next = existing.slice(0, begin) + fragment + existing.slice(stop);
|
|
141
|
+
action = "updated";
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const sep = existing.trim() ? (existing.endsWith("\n") ? "\n" : "\n\n") : "";
|
|
145
|
+
next = `${existing}${sep}${fragment}\n`;
|
|
146
|
+
action = dropped ? "updated" : "added";
|
|
147
|
+
}
|
|
148
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
149
|
+
fs.writeFileSync(file, next);
|
|
150
|
+
return action;
|
|
151
|
+
}
|
|
152
|
+
// The Claude plugin and marketplace an install from before the rename added; both plugins would run every hook.
|
|
153
|
+
const LEGACY_CLAUDE_PLUGIN = "ai-collab@ai-collab";
|
|
154
|
+
const LEGACY_MARKETPLACE = "ai-collab";
|
|
155
|
+
/** Whether a harness's plugin record still names the old ai-collab plugin or marketplace (a quoted key). */
|
|
156
|
+
function legacyRecorded(...files) {
|
|
157
|
+
return files.some((file) => { try {
|
|
158
|
+
return fs.readFileSync(file, "utf8").includes(`"${LEGACY_MARKETPLACE}`);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return false;
|
|
162
|
+
} });
|
|
163
|
+
}
|
|
164
|
+
/** Uninstalls the old ai-collab Claude plugin and its marketplace when Claude still records them; says what it did. */
|
|
165
|
+
function removeLegacyClaudePlugin({ home, env, run }) {
|
|
166
|
+
const plugins = path.join(env.CLAUDE_CONFIG_DIR || path.join(home, ".claude"), "plugins");
|
|
167
|
+
if (!legacyRecorded(path.join(plugins, "installed_plugins.json"), path.join(plugins, "known_marketplaces.json")))
|
|
168
|
+
return "";
|
|
169
|
+
const failed = [];
|
|
170
|
+
for (const args of [["plugin", "uninstall", LEGACY_CLAUDE_PLUGIN], ["plugin", "marketplace", "remove", LEGACY_MARKETPLACE]]) {
|
|
171
|
+
const r = run("claude", args);
|
|
172
|
+
if (r.code !== 0 && !/not (found|installed)/i.test(r.stderr + r.stdout))
|
|
173
|
+
failed.push(`claude ${args.join(" ")} failed: ${(r.stderr || r.stdout).trim()}`);
|
|
174
|
+
}
|
|
175
|
+
return failed.length ? failed.join("; ") : "removed the old ai-collab plugin";
|
|
176
|
+
}
|
|
177
|
+
function installPlugin(peer, { root, home, env, run }) {
|
|
178
|
+
const url = new URL("../package.json", import.meta.url).href;
|
|
179
|
+
if (peer === "claude" || peer === "codex") {
|
|
180
|
+
let copy;
|
|
181
|
+
try {
|
|
182
|
+
copy = packPluginCopy(root, path.join(home, ...SHARE_DIR, `${peer}-plugin`)).dest;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
return `plugin copy failed: ${error.message}`;
|
|
186
|
+
}
|
|
187
|
+
root = copy;
|
|
188
|
+
}
|
|
189
|
+
if (peer === "claude") {
|
|
190
|
+
for (const args of [["plugin", "marketplace", "add", root], ["plugin", "install", "temmo@temmo"]]) {
|
|
191
|
+
const r = run("claude", args);
|
|
192
|
+
if (r.code !== 0 && !/already/i.test(r.stderr + r.stdout))
|
|
193
|
+
return `claude ${args.join(" ")} failed: ${(r.stderr || r.stdout).trim()}`;
|
|
194
|
+
}
|
|
195
|
+
// "already installed" leaves the old version recorded; update moves it to the refreshed copy.
|
|
196
|
+
for (const args of pluginUpdateCommands("claude")) {
|
|
197
|
+
const r = run("claude", args);
|
|
198
|
+
if (r.code !== 0)
|
|
199
|
+
return `claude ${args.join(" ")} failed: ${(r.stderr || r.stdout).trim()}`;
|
|
200
|
+
}
|
|
201
|
+
return removeLegacyClaudePlugin({ home, env, run });
|
|
202
|
+
}
|
|
203
|
+
if (peer === "codex") {
|
|
204
|
+
for (const args of [["plugin", "marketplace", "add", root], ["plugin", "add", "temmo@temmo"]]) {
|
|
205
|
+
const r = run("codex", args);
|
|
206
|
+
if (r.code !== 0 && !/already/i.test(r.stderr + r.stdout))
|
|
207
|
+
return `codex ${args.join(" ")} failed: ${(r.stderr || r.stdout).trim()}`;
|
|
208
|
+
}
|
|
209
|
+
let note = "restart Codex and trust the hooks in /hooks";
|
|
210
|
+
if (legacyRecorded(path.join(env.CODEX_HOME || path.join(home, ".codex"), "config.toml")))
|
|
211
|
+
note += "; remove the old ai-collab plugin in Codex's /plugins";
|
|
212
|
+
try {
|
|
213
|
+
const wrote = ensureCodexMcpServers(path.join(home, ".codex", "config.toml"), root);
|
|
214
|
+
if (wrote !== "kept")
|
|
215
|
+
note += `; mcp_servers ${wrote} in config.toml`;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
note += `; config.toml mcp_servers failed: ${error.message}`;
|
|
219
|
+
}
|
|
220
|
+
return note;
|
|
221
|
+
}
|
|
222
|
+
if (peer === "cursor") {
|
|
223
|
+
const r = installCursorPlugin({ home, importMetaUrl: url, copy: true });
|
|
224
|
+
return r.ok ? "restart running Cursor sessions" : `failed: ${r.message}`;
|
|
225
|
+
}
|
|
226
|
+
const r = installOpenCode({ home, env, importMetaUrl: url });
|
|
227
|
+
return r.ok === false ? `failed: ${r.message}` : "restart OpenCode";
|
|
228
|
+
}
|
|
229
|
+
// pi installs nothing: the runner loads lib/pi-extension.mjs with -e and pi's built-in MCP serves the tools (docs/pi.md).
|
|
230
|
+
function piNote(h, { env, run, which }) {
|
|
231
|
+
if (!installed(h, env, which))
|
|
232
|
+
return piMissing();
|
|
233
|
+
const r = run("pi", ["--version"], { env: { PI_OFFLINE: "1" } });
|
|
234
|
+
return piVersionProblem(`${r.stdout}\n${r.stderr}`) || "nothing to install; the runner loads the temmo extension with -e and pi's built-in MCP serves the tools";
|
|
235
|
+
}
|
|
236
|
+
function uiUnit(root) {
|
|
237
|
+
const next = path.join(root, "node_modules", "next", "dist", "bin", "next");
|
|
238
|
+
return `[Unit]
|
|
239
|
+
Description=Temmo UI
|
|
240
|
+
|
|
241
|
+
[Service]
|
|
242
|
+
WorkingDirectory=${root}
|
|
243
|
+
Environment=NODE_ENV=production
|
|
244
|
+
# Environment=TEMMO_UI_ORIGIN=https://<host>.<tailnet>.ts.net
|
|
245
|
+
ExecStart=${process.execPath} ${next} start ${path.join(root, "web")} -H 127.0.0.1 -p ${UI_PORT}
|
|
246
|
+
Restart=on-failure
|
|
247
|
+
RestartSec=2
|
|
248
|
+
UMask=0077
|
|
249
|
+
|
|
250
|
+
[Install]
|
|
251
|
+
WantedBy=default.target
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
// Builds the UI if needed and installs a systemd user unit; an existing unit is left alone.
|
|
255
|
+
function installUi({ root, home, run, which, env }) {
|
|
256
|
+
const unit = path.join(home, ".config", "systemd", "user", "temmo-ui.service");
|
|
257
|
+
if (fs.existsSync(unit))
|
|
258
|
+
return `kept ${unit}`;
|
|
259
|
+
if (!which("systemctl", env))
|
|
260
|
+
return `no systemd: run \`npm run ui\` in ${root}`;
|
|
261
|
+
if (!fs.existsSync(path.join(root, "web", productionDistDir(path.join(root, "web")), "BUILD_ID"))) {
|
|
262
|
+
const r = run(process.execPath, [path.join(root, "deploy", "build-ui.mjs")], { cwd: root });
|
|
263
|
+
if (r.code !== 0)
|
|
264
|
+
return `build failed: ${(r.stderr || r.stdout).trim().split("\n").slice(-3).join(" ")}`;
|
|
265
|
+
}
|
|
266
|
+
fs.mkdirSync(path.dirname(unit), { recursive: true });
|
|
267
|
+
fs.writeFileSync(unit, uiUnit(root));
|
|
268
|
+
run("systemctl", ["--user", "daemon-reload"]);
|
|
269
|
+
const r = run("systemctl", ["--user", "enable", "--now", "temmo-ui"]);
|
|
270
|
+
return r.code === 0 ? `running on http://127.0.0.1:${UI_PORT}` : `systemctl enable failed: ${r.stderr.trim()}`;
|
|
271
|
+
}
|
|
272
|
+
// Copies the package out of the npx cache, installs its dependencies, and reruns setup from the copy.
|
|
273
|
+
function relocate(root, home, argv, { run, say }) {
|
|
274
|
+
const dest = path.join(home, ...APP_DIR);
|
|
275
|
+
say(`install: copying temmo to ${dest}`);
|
|
276
|
+
fs.rmSync(dest, { recursive: true, force: true });
|
|
277
|
+
fs.cpSync(root, dest, { recursive: true, filter: (from) => !SKIP_COPY.has(path.relative(root, from)) });
|
|
278
|
+
// A published package carries no package-lock.json; a git checkout does.
|
|
279
|
+
const verb = fs.existsSync(path.join(dest, "package-lock.json")) ? "ci" : "install";
|
|
280
|
+
const npm = run("npm", [verb, "--omit=dev", "--no-audit", "--no-fund"], { cwd: dest });
|
|
281
|
+
if (npm.code !== 0) {
|
|
282
|
+
say(`install: npm ci failed: ${(npm.stderr || npm.stdout).trim().split("\n").slice(-3).join(" ")}`);
|
|
283
|
+
return 1;
|
|
284
|
+
}
|
|
285
|
+
return run(process.execPath, [path.join(dest, "scripts", "temmo.mjs"), "setup", ...argv], { stdio: "inherit" }).code;
|
|
286
|
+
}
|
|
287
|
+
/** The harnesses to install: --agent names (comma or repeated), else every one on PATH; throws on an unknown name. */
|
|
288
|
+
function chosenHarnesses(agents, env, which) {
|
|
289
|
+
if (!agents?.length)
|
|
290
|
+
return HARNESSES.filter(h => installed(h, env, which));
|
|
291
|
+
const names = agents.flatMap(a => a.split(",")).map(a => a.trim().toLowerCase()).filter(Boolean);
|
|
292
|
+
const unknown = names.filter(n => !HARNESSES.some(h => h.peer === n));
|
|
293
|
+
if (unknown.length)
|
|
294
|
+
throw new Error(`unknown --agent ${unknown.join(", ")}; pick from ${HARNESSES.map(h => h.peer).join(", ")}`);
|
|
295
|
+
return HARNESSES.filter(h => names.includes(h.peer));
|
|
296
|
+
}
|
|
297
|
+
/** Runs setup and returns an exit code; run, which and root are injectable for tests. */
|
|
298
|
+
export async function setup(argv = [], { env = process.env, home = env.HOME || os.homedir(), out = process.stdout, run = defaultRun, which = defaultWhich, root = packageRoot(import.meta.url), turns = inFlight } = {}) {
|
|
299
|
+
const say = (line) => out.write(`${line}\n`);
|
|
300
|
+
let flags;
|
|
301
|
+
try {
|
|
302
|
+
flags = parseArgs({ args: argv, options: OPTIONS, strict: true }).values;
|
|
303
|
+
}
|
|
304
|
+
catch (err) {
|
|
305
|
+
say(`setup: ${err.message}`);
|
|
306
|
+
return 2;
|
|
307
|
+
}
|
|
308
|
+
// The rename stops the old units before it moves their dirs: a running service could recreate an old dir between the
|
|
309
|
+
// move and its symlink and split the state. It runs before the npx relocation, which then lands in the new share dir.
|
|
310
|
+
const homeEnv = { ...env, HOME: home };
|
|
311
|
+
if (legacyUnitsInstalled(homeEnv) && which("systemctl", env)) {
|
|
312
|
+
// Stopping the old runner kills its agents mid-turn, so the rename waits for an idle runner.
|
|
313
|
+
const busy = flags.force ? [] : await turns(homeEnv);
|
|
314
|
+
if (busy.length)
|
|
315
|
+
say(`rename: ${busy.length} runner turn(s) in flight (${busy.join(", ")}); the old units and dirs stay until a rerun when idle, or --force`);
|
|
316
|
+
else
|
|
317
|
+
for (const note of migrateUnits({ env: homeEnv, run, beforeStart: () => migrateDirs(homeEnv) }))
|
|
318
|
+
say(`rename: ${note}`);
|
|
319
|
+
}
|
|
320
|
+
else
|
|
321
|
+
for (const note of migrateDirs(homeEnv))
|
|
322
|
+
say(`rename: ${note}`);
|
|
323
|
+
if (root.split(path.sep).includes("_npx"))
|
|
324
|
+
return relocate(root, home, argv, { run, say });
|
|
325
|
+
let found;
|
|
326
|
+
try {
|
|
327
|
+
found = chosenHarnesses(flags.agent, env, which);
|
|
328
|
+
}
|
|
329
|
+
catch (err) {
|
|
330
|
+
say(`setup: ${err.message}`);
|
|
331
|
+
return 2;
|
|
332
|
+
}
|
|
333
|
+
const defaultsFile = path.join(configDir({ ...env, HOME: home }), "defaults.json");
|
|
334
|
+
let defaults = readJson(defaultsFile);
|
|
335
|
+
if (defaults?.url && defaults?.tokenFile)
|
|
336
|
+
say(`bus: using ${defaults.url} from ${defaultsFile}`);
|
|
337
|
+
else {
|
|
338
|
+
const port = Number(flags.port) || BUS_PORT;
|
|
339
|
+
const token = busToken();
|
|
340
|
+
const tokenFile = path.join(path.dirname(defaultsFile), "bus-token");
|
|
341
|
+
writePrivate(tokenFile, `${token}\n`);
|
|
342
|
+
defaults = { url: `http://127.0.0.1:${port}`, tokenFile, peers: found.map(h => h.peer).join(",") };
|
|
343
|
+
writePrivate(defaultsFile, `${JSON.stringify(defaults, null, 2)}\n`);
|
|
344
|
+
say(`bus: ${installBus({ root, home, run, which, env, port })}; token in ${tokenFile}`);
|
|
345
|
+
if (!(await pgReachable(env)))
|
|
346
|
+
say("bus: stores events in Postgres, which is not running: run `temmo postgres up`, then `systemctl --user restart temmo-bus`");
|
|
347
|
+
}
|
|
348
|
+
// The UI server's own credential; agents never get it (docs/security.md#operator-verified-messages).
|
|
349
|
+
ensureOperatorToken({ ...env, HOME: home });
|
|
350
|
+
say(`operator token: ${operatorTokenFile({ ...env, HOME: home })} (read only by the UI server)`);
|
|
351
|
+
say("projects: every git repo joins under its folder name; add an empty .temmo-off file to keep a repo out");
|
|
352
|
+
if (!found.length)
|
|
353
|
+
say("harnesses: none found on PATH (claude, codex, agent, opencode, pi); pick with --agent claude,cursor");
|
|
354
|
+
for (const h of found) {
|
|
355
|
+
// Claude Code and Codex install through their CLI; Cursor and OpenCode plugins are plain files.
|
|
356
|
+
if ((h.peer === "claude" || h.peer === "codex") && !installed(h, env, which)) {
|
|
357
|
+
say(`${h.peer}: ${h.bin} not found on PATH; install it, then rerun`);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
if (h.peer === "pi") {
|
|
361
|
+
say(`pi: ${piNote(h, { env, run, which })}`);
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
const note = installPlugin(h.peer, { root, home, env, run });
|
|
365
|
+
say(`${h.peer}: ${note.startsWith("failed") || note.includes(" failed") ? note : `installed${note ? `; ${note}` : ""}`}`);
|
|
366
|
+
}
|
|
367
|
+
if (!flags["no-ui"])
|
|
368
|
+
say(`ui: ${installUi({ root, home, run, which, env })}`);
|
|
369
|
+
say(`
|
|
370
|
+
Phone access (setup changes nothing on your network):
|
|
371
|
+
1. Install Tailscale on this machine and your phone, both signed in to one tailnet.
|
|
372
|
+
2. tailscale serve --bg --https=443 http://127.0.0.1:${UI_PORT}
|
|
373
|
+
3. Set TEMMO_UI_ORIGIN to the printed https URL in ~/.config/systemd/user/temmo-ui.service,
|
|
374
|
+
then: systemctl --user restart temmo-ui
|
|
375
|
+
4. Open that URL on your phone and add it to the home screen.`);
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed approvals: the operator allows one exact tool call from the phone, and code (not a model reading text) checks
|
|
3
|
+
* it before the harness runs the call (docs/security.md#signed-approvals).
|
|
4
|
+
*
|
|
5
|
+
* The UI server signs an approval record with an Ed25519 private key only it holds (lib/approval-signer.ts). This
|
|
6
|
+
* module holds no private key: it verifies a record against the trusted public keys and the pending call, and burns
|
|
7
|
+
* its nonce so the record allows that call once. It is harness-agnostic; claudePreToolUse adapts a result to
|
|
8
|
+
* Claude Code's PreToolUse output, and `temmo approval verify` runs the same check from a shell.
|
|
9
|
+
*
|
|
10
|
+
* Token: base64url(JSON claims) "." base64url(Ed25519 signature over the first part).
|
|
11
|
+
*/
|
|
12
|
+
import { createHash, createPublicKey, verify } from "node:crypto";
|
|
13
|
+
import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import { configDir, stateDir } from "./config.js";
|
|
16
|
+
export const APPROVAL_TTL_MS = 10 * 60 * 1000;
|
|
17
|
+
export const APPROVAL_PUBLIC_KEY_FILE = "approval-ed25519.pub";
|
|
18
|
+
// Prefix of the reply body that carries a token: "reply <id> allow signed:<token>".
|
|
19
|
+
export const SIGNED_PREFIX = "signed:";
|
|
20
|
+
const HEX64 = /^[a-f0-9]{64}$/;
|
|
21
|
+
const REQUEST_ID = /^[a-f0-9]{12}$/;
|
|
22
|
+
const SESSION = /^[a-f0-9]{16}$/;
|
|
23
|
+
const NONCE = /^[a-f0-9]{32}$/;
|
|
24
|
+
const LOGIN = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/;
|
|
25
|
+
const TOOL_MAX = 128;
|
|
26
|
+
const TOKEN_MAX = 4096;
|
|
27
|
+
/** JSON with object keys sorted at every depth, so equal inputs hash equally whatever their key order. */
|
|
28
|
+
export function canonicalJson(value) {
|
|
29
|
+
if (Array.isArray(value))
|
|
30
|
+
return `[${value.map(canonicalJson).join(",")}]`;
|
|
31
|
+
if (value && typeof value === "object") {
|
|
32
|
+
return `{${Object.keys(value).sort().map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(",")}}`;
|
|
33
|
+
}
|
|
34
|
+
return JSON.stringify(value ?? null);
|
|
35
|
+
}
|
|
36
|
+
/** sha256 of the tool name and its exact input; any change to the input (command, patch, path) changes the hash. */
|
|
37
|
+
export function approvalInputHash(tool, input) {
|
|
38
|
+
return createHash("sha256").update(`${tool}\n${canonicalJson(input)}`).digest("hex");
|
|
39
|
+
}
|
|
40
|
+
/** Whether claims have the shape and field limits a signer may emit. */
|
|
41
|
+
export function validClaims(c) {
|
|
42
|
+
const x = c;
|
|
43
|
+
return !!x && typeof x === "object" && x.v === 1 && SESSION.test(String(x.session)) && typeof x.tool === "string"
|
|
44
|
+
&& x.tool.length > 0 && x.tool.length <= TOOL_MAX && HEX64.test(String(x.inputHash)) && REQUEST_ID.test(String(x.requestId))
|
|
45
|
+
&& Number.isSafeInteger(x.iat) && Number.isSafeInteger(x.exp) && x.exp > x.iat && x.exp - x.iat <= APPROVAL_TTL_MS
|
|
46
|
+
&& NONCE.test(String(x.nonce)) && (x.by === undefined || LOGIN.test(String(x.by)));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The seam that decides which public keys sign approvals: today, the UI server's key file in the config dir.
|
|
50
|
+
* GitHub login or a well-known trust file replaces this body later; every verifier calls only this.
|
|
51
|
+
*/
|
|
52
|
+
export function trustedApprovalKeys(env = process.env) {
|
|
53
|
+
try {
|
|
54
|
+
return [createPublicKey(readFileSync(path.join(configDir(env), APPROVAL_PUBLIC_KEY_FILE), "utf8"))];
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Checks a token's signature, shape and expiry only, not what it is bound to. */
|
|
61
|
+
export function verifySignature(token, keys, now = Date.now()) {
|
|
62
|
+
if (typeof token !== "string" || !token)
|
|
63
|
+
return { ok: false, reason: "unsigned" };
|
|
64
|
+
if (!keys.length)
|
|
65
|
+
return { ok: false, reason: "no-trusted-key" };
|
|
66
|
+
const parts = token.startsWith(SIGNED_PREFIX) ? token.slice(SIGNED_PREFIX.length).split(".") : token.split(".");
|
|
67
|
+
if (token.length > TOKEN_MAX || parts.length !== 2 || !parts[0] || !parts[1])
|
|
68
|
+
return { ok: false, reason: "malformed" };
|
|
69
|
+
const [data, sig] = parts;
|
|
70
|
+
const signed = keys.some((key) => {
|
|
71
|
+
try {
|
|
72
|
+
return verify(null, Buffer.from(data), key, Buffer.from(sig, "base64url"));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
if (!signed)
|
|
79
|
+
return { ok: false, reason: "bad-signature" };
|
|
80
|
+
let claims;
|
|
81
|
+
try {
|
|
82
|
+
claims = JSON.parse(Buffer.from(data, "base64url").toString("utf8"));
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return { ok: false, reason: "malformed" };
|
|
86
|
+
}
|
|
87
|
+
if (!validClaims(claims))
|
|
88
|
+
return { ok: false, reason: "malformed" };
|
|
89
|
+
if (claims.exp <= now)
|
|
90
|
+
return { ok: false, reason: "expired" };
|
|
91
|
+
return { ok: true, claims };
|
|
92
|
+
}
|
|
93
|
+
/** Verifies a token against one pending call: signature, expiry, session, tool, exact input and (when given) request id. */
|
|
94
|
+
export function verifyApproval(token, call, { keys, now = Date.now() }) {
|
|
95
|
+
const v = verifySignature(token, keys, now);
|
|
96
|
+
if (!v.ok)
|
|
97
|
+
return v;
|
|
98
|
+
const c = v.claims;
|
|
99
|
+
if (c.session !== call.session)
|
|
100
|
+
return { ok: false, reason: "session" };
|
|
101
|
+
if (c.tool !== call.tool)
|
|
102
|
+
return { ok: false, reason: "tool" };
|
|
103
|
+
if (c.inputHash !== approvalInputHash(call.tool, call.input))
|
|
104
|
+
return { ok: false, reason: "input" };
|
|
105
|
+
if (call.requestId !== undefined && c.requestId !== call.requestId)
|
|
106
|
+
return { ok: false, reason: "request" };
|
|
107
|
+
return v;
|
|
108
|
+
}
|
|
109
|
+
/** The approvals directory: pending tokens per session and burnt nonces. */
|
|
110
|
+
export function approvalsDir(env = process.env) {
|
|
111
|
+
return path.join(stateDir(env), "approvals");
|
|
112
|
+
}
|
|
113
|
+
const pendingDir = (dir, session) => path.join(dir, "pending", session);
|
|
114
|
+
const usedFile = (dir, nonce) => path.join(dir, "used", nonce);
|
|
115
|
+
/**
|
|
116
|
+
* Burns a nonce: true for the first caller, false for every later one (an exclusive create, so of two racing hooks only
|
|
117
|
+
* one wins). The marker holds the expiry; sweepUsed drops it once the record could no longer verify anyway.
|
|
118
|
+
*/
|
|
119
|
+
export function burnNonce(dir, claims) {
|
|
120
|
+
mkdirSync(path.join(dir, "used"), { recursive: true, mode: 0o700 });
|
|
121
|
+
try {
|
|
122
|
+
writeFileSync(usedFile(dir, claims.nonce), String(claims.exp), { flag: "wx", mode: 0o600 });
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function sweepUsed(dir, now) {
|
|
130
|
+
let names = [];
|
|
131
|
+
try {
|
|
132
|
+
names = readdirSync(path.join(dir, "used"));
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (const name of names) {
|
|
138
|
+
const file = path.join(dir, "used", name);
|
|
139
|
+
let exp = 0;
|
|
140
|
+
try {
|
|
141
|
+
exp = Number(readFileSync(file, "utf8")) || 0;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (exp <= now)
|
|
147
|
+
rmSync(file, { force: true });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/** Stores a signature-checked token for its session so the pre-call gate can find it; returns the claims or the refusal. */
|
|
151
|
+
export function savePendingApproval(dir, token, keys, now = Date.now()) {
|
|
152
|
+
const v = verifySignature(token, keys, now);
|
|
153
|
+
if (!v.ok)
|
|
154
|
+
return v;
|
|
155
|
+
if (readUsed(dir, v.claims.nonce))
|
|
156
|
+
return { ok: false, reason: "replayed" };
|
|
157
|
+
const target = pendingDir(dir, v.claims.session);
|
|
158
|
+
mkdirSync(target, { recursive: true, mode: 0o700 });
|
|
159
|
+
const tmp = path.join(target, `.${v.claims.nonce}.tmp`);
|
|
160
|
+
writeFileSync(tmp, token, { mode: 0o600 });
|
|
161
|
+
renameSync(tmp, path.join(target, `${v.claims.nonce}.tok`));
|
|
162
|
+
return v;
|
|
163
|
+
}
|
|
164
|
+
function readUsed(dir, nonce) {
|
|
165
|
+
try {
|
|
166
|
+
readFileSync(usedFile(dir, nonce));
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The pre-call gate: finds this session's stored approval that verifies for exactly this call, burns its nonce and
|
|
175
|
+
* returns it. Tokens that no longer verify (expired, forged, burnt) are removed. A refusal names the closest reason.
|
|
176
|
+
*/
|
|
177
|
+
export function takeApproval(dir, call, { keys, now = Date.now() }) {
|
|
178
|
+
if (!SESSION.test(call.session))
|
|
179
|
+
return { ok: false, reason: "session" };
|
|
180
|
+
sweepUsed(dir, now);
|
|
181
|
+
let names = [];
|
|
182
|
+
try {
|
|
183
|
+
names = readdirSync(pendingDir(dir, call.session)).filter((n) => n.endsWith(".tok"));
|
|
184
|
+
}
|
|
185
|
+
catch { /* none stored */ }
|
|
186
|
+
if (!names.length)
|
|
187
|
+
return { ok: false, reason: "unsigned" };
|
|
188
|
+
let refusal = { ok: false, reason: "unsigned" };
|
|
189
|
+
for (const name of names.sort()) {
|
|
190
|
+
const file = path.join(pendingDir(dir, call.session), name);
|
|
191
|
+
let token = "";
|
|
192
|
+
try {
|
|
193
|
+
token = readFileSync(file, "utf8");
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const v = verifyApproval(token, call, { keys, now });
|
|
199
|
+
if (!v.ok) {
|
|
200
|
+
if (["expired", "bad-signature", "malformed", "no-trusted-key"].includes(v.reason))
|
|
201
|
+
rmSync(file, { force: true });
|
|
202
|
+
refusal = v;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
rmSync(file, { force: true });
|
|
206
|
+
if (!burnNonce(dir, v.claims)) {
|
|
207
|
+
refusal = { ok: false, reason: "replayed" };
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
return v;
|
|
211
|
+
}
|
|
212
|
+
return refusal;
|
|
213
|
+
}
|
|
214
|
+
/** Claude Code PreToolUse output: "allow" for a verified approval, {} (no decision, the normal permission flow) otherwise. */
|
|
215
|
+
export function claudePreToolUse(v) {
|
|
216
|
+
if (!v.ok)
|
|
217
|
+
return {};
|
|
218
|
+
const by = v.claims.by ? ` by ${v.claims.by}` : "";
|
|
219
|
+
return {
|
|
220
|
+
hookSpecificOutput: {
|
|
221
|
+
hookEventName: "PreToolUse", permissionDecision: "allow",
|
|
222
|
+
permissionDecisionReason: `temmo signed approval ${v.claims.requestId}${by}: allowed once for this exact input.`,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
}
|