@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,10 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Installs the OpenCode 2 plugin shim and the temmo MCP server into OpenCode's global config.
|
|
3
|
+
import { installOpenCode } from "../lib/install-opencode.js";
|
|
4
|
+
const result = installOpenCode({ importMetaUrl: import.meta.url, env: process.env });
|
|
5
|
+
if (!result.ok) {
|
|
6
|
+
console.error(`temmo: ${result.message}`);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
}
|
|
9
|
+
console.log(`plugin -> ${result.plugin}`);
|
|
10
|
+
console.log(`mcp -> ${result.config}`);
|
package/scripts/temmo
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
3
|
+
// temmo-bus entry: the local message bus.
|
|
4
|
+
// Reads url/token from defaults.json (or TEMMO_BUS_* env), serves Postgres-backed events on loopback,
|
|
5
|
+
// and prunes past retention hourly. Sandboxes reach it through host.openshell.internal.
|
|
6
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { configDir, listProjects, loadProjects, stateDir } from "../lib/config.js";
|
|
11
|
+
import { DEFAULT_RETENTION_MS, openBus, resolveBusStoreKind } from "../lib/bus.js";
|
|
12
|
+
import { hostAgentDirectory } from "../lib/agents-route.js";
|
|
13
|
+
import { openPostgresBusStore } from "../lib/bus-postgres.js";
|
|
14
|
+
import { pgPasswordFile, pgReachable, pgUrl } from "../lib/postgres.js";
|
|
15
|
+
import { listOwned, listSessions } from "../lib/sessions/registry.js";
|
|
16
|
+
import { threadSessionsOf } from "../lib/threads.js";
|
|
17
|
+
import { ensureOperatorToken } from "../lib/operator-token.js";
|
|
18
|
+
function busToken(env) {
|
|
19
|
+
if (env.TEMMO_BUS_TOKEN !== undefined)
|
|
20
|
+
return env.TEMMO_BUS_TOKEN.trim();
|
|
21
|
+
let file = env.TEMMO_BUS_TOKEN_FILE;
|
|
22
|
+
if (!file) {
|
|
23
|
+
try {
|
|
24
|
+
const defaults = JSON.parse(readFileSync(path.join(configDir(env), "defaults.json"), "utf8"));
|
|
25
|
+
if (typeof defaults.tokenFile === "string")
|
|
26
|
+
file = defaults.tokenFile;
|
|
27
|
+
}
|
|
28
|
+
catch { /* no defaults.json */ }
|
|
29
|
+
}
|
|
30
|
+
if (!file)
|
|
31
|
+
return "";
|
|
32
|
+
try {
|
|
33
|
+
return readFileSync(file, "utf8").trim();
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function busDefaults(env) {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(readFileSync(path.join(configDir(env), "defaults.json"), "utf8"));
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function busPort(env) {
|
|
48
|
+
if (env.TEMMO_BUS_PORT)
|
|
49
|
+
return Number(env.TEMMO_BUS_PORT);
|
|
50
|
+
try {
|
|
51
|
+
const defaults = JSON.parse(readFileSync(path.join(configDir(env), "defaults.json"), "utf8"));
|
|
52
|
+
if (typeof defaults.url === "string")
|
|
53
|
+
return new URL(defaults.url).port ? Number(new URL(defaults.url).port) : 8794;
|
|
54
|
+
}
|
|
55
|
+
catch { /* no defaults.json */ }
|
|
56
|
+
return 8794;
|
|
57
|
+
}
|
|
58
|
+
/** The thread backfill (docs/threads.md): every registered project's unassigned sessions get a thread. Idempotent. */
|
|
59
|
+
export async function backfillThreads(threads, env, log) {
|
|
60
|
+
const roots = new Map(listProjects(env).map((entry) => [entry.project, entry.root]));
|
|
61
|
+
for (const cfg of loadProjects(env, { host: "operator" })) {
|
|
62
|
+
const root = roots.get(cfg.project) || "";
|
|
63
|
+
try {
|
|
64
|
+
const sessions = threadSessionsOf({ sessions: listSessions(cfg), owned: listOwned(cfg), root });
|
|
65
|
+
const { assigned, created, retitled } = await threads.sync({ project: cfg.project, root, sessions });
|
|
66
|
+
if (assigned.length)
|
|
67
|
+
log(`threads: ${cfg.project}: ${assigned.length} session(s) assigned, ${created} thread(s) created`);
|
|
68
|
+
if (retitled)
|
|
69
|
+
log(`threads: ${cfg.project}: ${retitled} thread(s) renamed from their lead session`);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
log(`threads: ${cfg.project}: backfill failed: ${error.message}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function main(env = process.env, { err = process.stderr } = {}) {
|
|
77
|
+
const log = (message) => err.write(`temmo-bus: ${message}\n`);
|
|
78
|
+
const token = busToken(env);
|
|
79
|
+
if (!token) {
|
|
80
|
+
log("no token: set tokenFile in defaults.json, or TEMMO_BUS_TOKEN / TEMMO_BUS_TOKEN_FILE");
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
// Only the UI server reads this file; an event it publishes is stamped verified (docs/security.md#operator-verified-messages).
|
|
84
|
+
let operatorToken;
|
|
85
|
+
try {
|
|
86
|
+
operatorToken = ensureOperatorToken(env);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
log(`operator token: ${error.message}`);
|
|
90
|
+
return 1;
|
|
91
|
+
}
|
|
92
|
+
const dataDir = env.TEMMO_BUS_DATA || path.join(stateDir(env), "bus");
|
|
93
|
+
const retentionMs = Number(env.TEMMO_BUS_RETENTION_HOURS ? Number(env.TEMMO_BUS_RETENTION_HOURS) * 3_600_000 : DEFAULT_RETENTION_MS);
|
|
94
|
+
let kind;
|
|
95
|
+
try {
|
|
96
|
+
kind = resolveBusStoreKind(env, busDefaults(env));
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
log(error.message);
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
const pgAt = `${env.TEMMO_PG_HOST || "127.0.0.1"}:${env.TEMMO_PG_PORT || "5432"}`;
|
|
103
|
+
const noPostgres = (why) => log(`${why}; the bus stores events in Postgres: run \`temmo postgres up\`, then restart temmo-bus`);
|
|
104
|
+
// Checked before pgUrl, which would create a fresh password that the running container does not know.
|
|
105
|
+
if (!existsSync(pgPasswordFile(env))) {
|
|
106
|
+
noPostgres(`no Postgres password at ${pgPasswordFile(env)}`);
|
|
107
|
+
return 1;
|
|
108
|
+
}
|
|
109
|
+
if (!(await pgReachable(env))) {
|
|
110
|
+
noPostgres(`no Postgres on ${pgAt}`);
|
|
111
|
+
return 1;
|
|
112
|
+
}
|
|
113
|
+
let store;
|
|
114
|
+
try {
|
|
115
|
+
store = await openPostgresBusStore({ url: pgUrl(env), filesDir: path.join(dataDir, "files"), retentionMs, log });
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
noPostgres(`Postgres on ${pgAt} refused the bus store: ${error.message}`);
|
|
119
|
+
return 1;
|
|
120
|
+
}
|
|
121
|
+
if (store.threads)
|
|
122
|
+
await backfillThreads(store.threads, env, log);
|
|
123
|
+
const bus = openBus({ token, operatorToken, baseUrl: env.TEMMO_BUS_BASE_URL || "", store, directory: hostAgentDirectory(env), tasks: { env } });
|
|
124
|
+
const port = busPort(env);
|
|
125
|
+
const url = await bus.listen(port, "127.0.0.1");
|
|
126
|
+
const prune = async () => { try {
|
|
127
|
+
const { events, files } = await bus.prune();
|
|
128
|
+
if (events || files)
|
|
129
|
+
log(`pruned ${events} event(s), ${files} file(s)`);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
log(`prune failed: ${error.message}`);
|
|
133
|
+
} };
|
|
134
|
+
await prune();
|
|
135
|
+
const timer = setInterval(prune, 3_600_000);
|
|
136
|
+
timer.unref?.();
|
|
137
|
+
log(`listening on ${url}; store ${kind}; data ${dataDir}; retention ${Math.round(retentionMs / 3_600_000)}h`);
|
|
138
|
+
let stopping = false;
|
|
139
|
+
const shutdown = async () => {
|
|
140
|
+
if (stopping)
|
|
141
|
+
return;
|
|
142
|
+
stopping = true;
|
|
143
|
+
await bus.close();
|
|
144
|
+
process.exit(0);
|
|
145
|
+
};
|
|
146
|
+
process.on("SIGTERM", shutdown);
|
|
147
|
+
process.on("SIGINT", shutdown);
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url)))
|
|
151
|
+
process.exitCode = await main();
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
3
|
+
// MCP server "temmo-code": tools that run a JavaScript program in an OpenShell sandbox (lib/code-run.ts).
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { toolClient } from "../lib/tool-api.js";
|
|
7
|
+
import { BOOTSTRAP, RUN_CODE, RUN_READ_CODE, TIMEOUT_DEFAULT_MS, TIMEOUT_MAX_MS, CODE_MAX_CHARS, codeSandbox, programSource, formatRun, hostCaller, prepareSandbox, programArgv, removeCodeSandbox, runCodeTool, runProgram } from "../lib/code-run.js";
|
|
8
|
+
import { serveMcp } from "../lib/surfaces/render-mcp.js";
|
|
9
|
+
const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
10
|
+
const INSTRUCTIONS = "run_code runs one JavaScript program in an OpenShell sandbox with an `ai` client for the temmo tools; "
|
|
11
|
+
+ "use it when a task needs many temmo calls (list, filter, join) and only the answer should come back. Use run_read_code to gather evidence through the read-only ai API.";
|
|
12
|
+
const SESSION = /^[a-f0-9]{16}$/;
|
|
13
|
+
const builder = process.argv[2] === "--builder-local";
|
|
14
|
+
const workdir = process.argv[3];
|
|
15
|
+
if (builder && (!process.env.OPENSHELL_SANDBOX || !workdir?.startsWith("/sandbox/work/"))) {
|
|
16
|
+
throw new Error("Builder run_code requires an OpenShell builder worktree");
|
|
17
|
+
}
|
|
18
|
+
const client = builder ? null : toolClient({ host: process.argv[2] || "" });
|
|
19
|
+
// One run_code call: checks its input, prepares the sandbox, runs the program, and returns the capped result text.
|
|
20
|
+
async function runCode(args, signal, readOnly) {
|
|
21
|
+
const { session, timeout_ms: timeoutMs = TIMEOUT_DEFAULT_MS } = args;
|
|
22
|
+
const code = programSource(args, { cwd: builder ? workdir : process.cwd() });
|
|
23
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > TIMEOUT_MAX_MS)
|
|
24
|
+
throw new Error(`timeout_ms must be 1000-${TIMEOUT_MAX_MS}`);
|
|
25
|
+
if (builder) {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const helper = fileURLToPath(new URL("../lib/builder-code.cjs", import.meta.url));
|
|
28
|
+
const argv = [process.execPath, "--max-old-space-size=256", "-e", BOOTSTRAP, helper];
|
|
29
|
+
const run = await runProgram({ argv, code, env: process.env, cwd: workdir, timeoutMs, signal, builder });
|
|
30
|
+
return { text: formatRun(run), isError: !run.ok };
|
|
31
|
+
}
|
|
32
|
+
if (typeof session !== "string" || !SESSION.test(session))
|
|
33
|
+
throw new Error("Pass the session label supplied by the temmo hook");
|
|
34
|
+
const sandbox = codeSandbox(process.env, { readOnly });
|
|
35
|
+
try {
|
|
36
|
+
await prepareSandbox({ sandbox });
|
|
37
|
+
const argv = await programArgv(sandbox);
|
|
38
|
+
signal.throwIfAborted();
|
|
39
|
+
const run = await runProgram({
|
|
40
|
+
argv, code, env: process.env, timeoutMs, signal, readOnly,
|
|
41
|
+
callTool: hostCaller({ client, session, signal, readOnly }),
|
|
42
|
+
});
|
|
43
|
+
return { text: formatRun(run), isError: !run.ok };
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
if (readOnly)
|
|
47
|
+
await removeCodeSandbox(sandbox);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
serveMcp({
|
|
51
|
+
name: "temmo-code",
|
|
52
|
+
version: VERSION,
|
|
53
|
+
instructions: builder ? "Batch related worktree operations with run_code." : INSTRUCTIONS,
|
|
54
|
+
listTools: () => {
|
|
55
|
+
const tools = client?.listTools();
|
|
56
|
+
return builder ? [runCodeTool([], { builder })] : [runCodeTool(tools), runCodeTool(tools, { readOnly: true })];
|
|
57
|
+
},
|
|
58
|
+
callTool: async (name, args, signal) => {
|
|
59
|
+
if (name !== RUN_CODE && (builder || name !== RUN_READ_CODE))
|
|
60
|
+
throw new Error("Unknown tool");
|
|
61
|
+
return runCode(args, signal, name === RUN_READ_CODE);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
3
|
+
/**
|
|
4
|
+
* Agent hook. Reads one JSON object on stdin and writes exactly one JSON object on stdout.
|
|
5
|
+
* Events: SessionStart (status start + current AFK mode + inbox + the harness's learned lessons), UserPromptSubmit / PostToolUse (inbox, throttled),
|
|
6
|
+
* Stop (deliver waiting messages, AFK wait, important-question hold; see lib/stop.ts), SessionEnd (status stop).
|
|
7
|
+
* Every event also publishes activity (prompts, tool calls and results, assistant text; never thinking) to the
|
|
8
|
+
* project's activity topic unless TEMMO_ACTIVITY=off; that publish runs alongside delivery under a 1.5 s cap.
|
|
9
|
+
* --rewake marks the Claude asyncRewake registration (lib/waiter.ts): it prints no JSON; it exits 2 with the messages on stderr.
|
|
10
|
+
* --activity marks a registration that only publishes activity and returns the neutral output; SessionStart after a compaction adds the session's pad.
|
|
11
|
+
* A Stop hold publishes status "hold"; the hold's message or answer, or the session's next prompt or tool call, publishes "start".
|
|
12
|
+
* InstructionsLoaded (Claude) records the instruction file it loaded in the session's context state (lib/usage.ts).
|
|
13
|
+
* A prompt the operator typed records operatorPromptAt for this session; AFK mode changes only when the operator sets it.
|
|
14
|
+
* --host opencode takes Claude-shaped input from the OpenCode plugin (lib/opencode-plugin.mjs) and answers in Claude's shapes.
|
|
15
|
+
* The lesson note joins SessionStart's additionalContext on claude, codex and cursor, where that is the harness's system
|
|
16
|
+
* channel; opencode and pi get it in a top-level lessons field for their plugin or extension to place on the system prompt.
|
|
17
|
+
* PermissionDenied (Claude auto mode) posts the blocked call to the channel in AFK mode on or quiet (lib/blocked.ts).
|
|
18
|
+
* PermissionRequest (Claude, Codex, OpenCode) and Cursor beforeShellExecution / beforeMCPExecution ask the operator's phone in AFK
|
|
19
|
+
* mode on or quiet (lib/approvals.ts); no answer means no decision, so the harness shows its own prompt.
|
|
20
|
+
* In mode off a Claude or Codex prompt becomes a view-only card; PostToolUse(Failure), Stop, StopFailure, UserPromptSubmit
|
|
21
|
+
* or SessionEnd of that session closes it.
|
|
22
|
+
* Any failure prints {} and exits 0: the session continues unchanged. Transcripts are never read.
|
|
23
|
+
* --read-gate refuses an agent read of the task store or state dir when readsThroughRunCode is on, with the
|
|
24
|
+
* run_code recipe, and otherwise prints {}. Cursor beforeShellExecution and beforeReadFile use it so a
|
|
25
|
+
* non-matching command is not turned into an approval prompt. A human shell never runs this hook.
|
|
26
|
+
* On Claude's Agent/Task tool it adds the spawn_agent hint once per session (lib/family.ts SUBAGENT_TOOL_HINT) and never blocks.
|
|
27
|
+
* Its read gate also shows the Harness² stage file (harness-core/) when a Bash call is about to git commit, git push or land,
|
|
28
|
+
* or when the request_pr tool is called (docs/harness2-v2.md step 1b).
|
|
29
|
+
* Cursor events also feed the run's OTLP trace (lib/cursor-trace.ts); its export waits at most 1.5 s after the output.
|
|
30
|
+
* The Claude --read-gate also allows a call that a stored signed approval is bound to, once (lib/signed-approval.ts);
|
|
31
|
+
* --approval-gate runs only that check and otherwise prints {}.
|
|
32
|
+
* Every message handed to the agent gets a read receipt, published in the background like activity.
|
|
33
|
+
*/
|
|
34
|
+
import fs from "node:fs";
|
|
35
|
+
import module from "node:module";
|
|
36
|
+
import os from "node:os";
|
|
37
|
+
import path from "node:path";
|
|
38
|
+
// Every hook call is a fresh node process: the on-disk compile cache spares it recompiling the TypeScript modules.
|
|
39
|
+
module.enableCompileCache?.();
|
|
40
|
+
// Only the gate's modules load up front; the compile cache must be on before them, so they load dynamically.
|
|
41
|
+
const { loadConfig, ownEnv, sessionLabel } = await import("../lib/config.js");
|
|
42
|
+
const { CLAUDE_SUBAGENT_TOOLS, managedDenial, subagentDenial } = await import("../lib/subagent-guard.js");
|
|
43
|
+
const { hookOutput } = await import("../lib/format.js");
|
|
44
|
+
const { hookReadCall, storeReadDenial } = await import("../lib/store-read.js");
|
|
45
|
+
const HOSTS = new Set(["claude", "codex", "cursor", "opencode", "pi"]);
|
|
46
|
+
// The stage a pre-call event is about to enter: a shell command (commit, push, land) or the request_pr tool.
|
|
47
|
+
// Loaded lazily: an app copy without harness-core/ (an older sandbox upload) skips stage hints instead of failing every hook.
|
|
48
|
+
const harnessCore = () => import("../harness-core/stage.mjs");
|
|
49
|
+
function callStage(key, msg, stageForCommand) {
|
|
50
|
+
const call = hookReadCall(key, msg);
|
|
51
|
+
if (!call)
|
|
52
|
+
return null;
|
|
53
|
+
if (/(^|_)request_pr$/.test(call.name))
|
|
54
|
+
return "pr";
|
|
55
|
+
const command = call.input && typeof call.input === "object" ? call.input.command : undefined;
|
|
56
|
+
return stageForCommand(typeof command === "string" ? command : "");
|
|
57
|
+
}
|
|
58
|
+
// The first call per session and stage is denied with the stage text; the marker file makes every later one pass.
|
|
59
|
+
async function stageDenial(host, key, msg, cwd, session) {
|
|
60
|
+
const { resolveStage, stageForCommand } = await harnessCore();
|
|
61
|
+
const stage = session ? callStage(key, msg, stageForCommand) : null;
|
|
62
|
+
const found = stage ? resolveStage(stage, { cwd, env: process.env }) : null;
|
|
63
|
+
if (!found)
|
|
64
|
+
return null;
|
|
65
|
+
const dir = path.join(os.tmpdir(), "harness-stage-seen");
|
|
66
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
67
|
+
try {
|
|
68
|
+
fs.writeFileSync(path.join(dir, `${host}-${session}-${stage}`), "", { flag: "wx" });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const reason = `[harness] ${stage} stage, shown once per session: read it, then run the same command again (${found.path}):\n${found.text.slice(0, 2000)}`;
|
|
74
|
+
return subagentDenial(host, reason);
|
|
75
|
+
}
|
|
76
|
+
function hostArg(argv) {
|
|
77
|
+
const i = argv.indexOf("--host");
|
|
78
|
+
const h = i >= 0 ? String(argv[i + 1] || "") : "claude";
|
|
79
|
+
return HOSTS.has(h) ? h : "claude";
|
|
80
|
+
}
|
|
81
|
+
function readStdin(limitMs = 2000) {
|
|
82
|
+
return new Promise((resolve) => {
|
|
83
|
+
const chunks = [];
|
|
84
|
+
const timer = setTimeout(() => resolve(Buffer.concat(chunks).toString("utf8")), limitMs);
|
|
85
|
+
process.stdin.on("data", (c) => chunks.push(c));
|
|
86
|
+
process.stdin.on("end", () => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
89
|
+
});
|
|
90
|
+
process.stdin.on("error", () => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
resolve("");
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function emit(value) {
|
|
97
|
+
process.stdout.write(`${JSON.stringify(value)}\n`);
|
|
98
|
+
}
|
|
99
|
+
// Set once a call passes the gate and loads lib/hook.mjs, which handles every other registration.
|
|
100
|
+
let hook = null;
|
|
101
|
+
async function main() {
|
|
102
|
+
const argv = process.argv.slice(2);
|
|
103
|
+
const host = hostArg(argv);
|
|
104
|
+
const activityOnly = argv.includes("--activity");
|
|
105
|
+
const raw = await readStdin();
|
|
106
|
+
let msg;
|
|
107
|
+
try {
|
|
108
|
+
msg = raw.trim() ? JSON.parse(raw) : {};
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return emit({});
|
|
112
|
+
}
|
|
113
|
+
if (!msg || typeof msg !== "object" || Array.isArray(msg))
|
|
114
|
+
return emit({});
|
|
115
|
+
// Cursor also runs Claude Code plugins' hooks; its own registration (--host cursor) handles the event.
|
|
116
|
+
if (host !== "cursor" && typeof msg.cursor_version === "string")
|
|
117
|
+
return emit({});
|
|
118
|
+
// Cursor sends workspace_roots instead of cwd and runs ~/.cursor/hooks.json hooks from the home folder.
|
|
119
|
+
const roots = Array.isArray(msg.workspace_roots) ? msg.workspace_roots.filter((r) => typeof r === "string" && path.isAbsolute(r)) : [];
|
|
120
|
+
const cwd = typeof msg.cwd === "string" && msg.cwd ? msg.cwd : roots[0] || process.cwd();
|
|
121
|
+
msg.cwd = cwd;
|
|
122
|
+
// A child agent inherits its parent's shell environment; ownEnv keeps it from taking the parent's identity.
|
|
123
|
+
const env = ownEnv(process.env, host);
|
|
124
|
+
const sessionId = [msg.session_id, msg.sessionId, msg.conversation_id, msg.conversationId, env.CURSOR_CONVERSATION_ID]
|
|
125
|
+
.find((id) => typeof id === "string" && id.length > 0);
|
|
126
|
+
const session = sessionLabel(sessionId);
|
|
127
|
+
const key = String(msg.hook_event_name || msg.hookEventName || msg.event_name || "")
|
|
128
|
+
.toLowerCase()
|
|
129
|
+
.replace(/[^a-z]/g, "");
|
|
130
|
+
// File reads of the task store and state dir. Checked before config and activity so a missing project still refuses,
|
|
131
|
+
// and so Cursor's shell and read hooks return {} instead of asking. Codex and Claude PreToolUse deny here too.
|
|
132
|
+
const storeRead = storeReadDenial(host, key, msg);
|
|
133
|
+
if (storeRead && (await import("../lib/code-run.js")).readsThroughRunCode(env))
|
|
134
|
+
return emit(storeRead);
|
|
135
|
+
// A managed session's native subagent or shell harness start is refused (lib/subagent-guard.ts); before standsDown, so owned Cursor sessions refuse too.
|
|
136
|
+
// Codex PreToolUse runs --activity only, so its shell gate runs on every Codex hook call.
|
|
137
|
+
if (argv.includes("--read-gate") || host === "codex") {
|
|
138
|
+
const denied = managedDenial(host, key, msg, env, { cwd, host, session });
|
|
139
|
+
if (denied)
|
|
140
|
+
return emit(denied);
|
|
141
|
+
}
|
|
142
|
+
// A signed phone approval allows the one call it is bound to, once (lib/signed-approval.ts); after the denials above.
|
|
143
|
+
const approvalGate = argv.includes("--approval-gate");
|
|
144
|
+
if ((approvalGate || argv.includes("--read-gate")) && host === "claude" && key === "pretooluse" && typeof msg.tool_name === "string" && session) {
|
|
145
|
+
const sa = await import("../lib/signed-approval.js");
|
|
146
|
+
const verdict = sa.takeApproval(sa.approvalsDir(env), { session, tool: msg.tool_name, input: msg.tool_input ?? {} }, { keys: sa.trustedApprovalKeys(env) });
|
|
147
|
+
if (verdict.ok || approvalGate)
|
|
148
|
+
return emit(sa.claudePreToolUse(verdict));
|
|
149
|
+
}
|
|
150
|
+
if (approvalGate)
|
|
151
|
+
return emit({});
|
|
152
|
+
// An operator session's first Claude Agent/Task call gets the spawn_agent hint as context; the call goes ahead.
|
|
153
|
+
if (argv.includes("--read-gate") && host === "claude" && key === "pretooluse" && CLAUDE_SUBAGENT_TOOLS.includes(msg.tool_name)
|
|
154
|
+
&& !(typeof msg.agent_id === "string" && msg.agent_id)) {
|
|
155
|
+
const [{ standsDown }, { subagentToolHint }] = await Promise.all([import("../lib/sessions/registry.js"), import("../lib/family.js")]);
|
|
156
|
+
const cfg = loadConfig(env, { cwd, host, session });
|
|
157
|
+
const hint = cfg.enabled && !standsDown(cfg, { label: session }) ? await subagentToolHint(cfg).catch(() => "") : "";
|
|
158
|
+
return emit(hookOutput(host, "PreToolUse", hint));
|
|
159
|
+
}
|
|
160
|
+
// Harness² stage hint on Codex, Cursor, OpenCode and Pi (step 1d): a deny with a reason is the only pre-call output
|
|
161
|
+
// verified on all of them, so the first commit, push or land per session and stage is refused with the stage text.
|
|
162
|
+
if ((argv.includes("--read-gate") || host === "codex") && host !== "claude" && (key === "pretooluse" || key === "beforeshellexecution")) {
|
|
163
|
+
try {
|
|
164
|
+
const denied = await stageDenial(host, key, msg, cwd, session);
|
|
165
|
+
if (denied)
|
|
166
|
+
return emit(denied);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Stage disclosure never blocks the tool call beyond its one denial; fall through unchanged.
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Harness² ship-time disclosure (docs/harness2-v2.md step 1b): an agent about to commit, push or land
|
|
173
|
+
// gets the stage file for that moment, resolved by the portable core (harness-core/, docs/adr/0001).
|
|
174
|
+
if (argv.includes("--read-gate") && host === "claude" && key === "pretooluse"
|
|
175
|
+
&& (msg.tool_name === "Bash" || /^mcp__plugin_(?:temmo_temmo|ai-collab_ai-collab)__request_pr$/.test(msg.tool_name ?? ""))) {
|
|
176
|
+
try {
|
|
177
|
+
const { resolveStage, stageForCommand } = await harnessCore();
|
|
178
|
+
const stage = msg.tool_name === "Bash" ? stageForCommand(msg.tool_input?.command) : "pr";
|
|
179
|
+
const found = stage ? resolveStage(stage, { cwd, env: process.env }) : null;
|
|
180
|
+
if (found)
|
|
181
|
+
return emit(hookOutput(host, "PreToolUse", `[harness] ${stage} stage (${found.path}):\n${found.text.slice(0, 2000)}`));
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// Stage disclosure never blocks the tool call; fall through unchanged.
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (argv.includes("--read-gate"))
|
|
188
|
+
return emit({});
|
|
189
|
+
hook = await import("../lib/hook.mjs");
|
|
190
|
+
return hook.run({ argv, host, activityOnly, msg, cwd, env, sessionId, session, key, emit });
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
await main();
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
try {
|
|
197
|
+
emit({});
|
|
198
|
+
}
|
|
199
|
+
catch { /* stdout closed */ }
|
|
200
|
+
}
|
|
201
|
+
await hook?.traced();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
3
|
+
// The tool worker scripts/temmo-mcp.mjs runs; it restarts this process when a deploy replaces the plugin copy.
|
|
4
|
+
import { toolClient } from "../lib/tool-api.js";
|
|
5
|
+
import { READ_TOOLS, readsThroughRunCode } from "../lib/code-run.js";
|
|
6
|
+
import { runCodeReadRecipe } from "../lib/store-read.js";
|
|
7
|
+
import { serveToolWorker } from "../lib/surfaces/mcp-reload.js";
|
|
8
|
+
const host = process.argv[2] || "";
|
|
9
|
+
// Tag launches and machine defaults can require reads through run_code.
|
|
10
|
+
const runCodeFirst = readsThroughRunCode();
|
|
11
|
+
const client = toolClient({ host });
|
|
12
|
+
// With reads through run_code, read tools stay listed (hidden, a probe fell back to the CLI) but say where to call them.
|
|
13
|
+
const redirect = (tool) => ({ ...tool, description: `Do not call directly: call run_code (temmo-code server) with ai.${tool.name}(...) and batch your other reads in the same program. ${tool.description}` });
|
|
14
|
+
serveToolWorker({
|
|
15
|
+
listTools: () => client.listTools().map((tool) => (runCodeFirst && READ_TOOLS.includes(tool.name) ? redirect(tool) : tool)),
|
|
16
|
+
callTool: async (name, args, signal) => {
|
|
17
|
+
if (runCodeFirst && READ_TOOLS.includes(name))
|
|
18
|
+
return { isError: true, text: runCodeReadRecipe(name, args) };
|
|
19
|
+
const result = await client.callTool(name, args, { signal });
|
|
20
|
+
return { text: JSON.stringify(result) };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "../lib/names.js"; // first: folds AI_COLLAB_* env into TEMMO_* before other modules read it
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { serveMcp } from "../lib/surfaces/render-mcp.js";
|
|
5
|
+
import { toolWorkers } from "../lib/surfaces/mcp-reload.js";
|
|
6
|
+
import { INSTRUCTIONS } from "../lib/surfaces/instructions.js";
|
|
7
|
+
const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
8
|
+
const host = process.argv[2] || "";
|
|
9
|
+
// The tools run in a worker; a deploy that replaces the plugin copy restarts it and the session gets the new list.
|
|
10
|
+
let mcp;
|
|
11
|
+
const workers = toolWorkers({
|
|
12
|
+
script: new URL("./temmo-mcp-tools.mjs", import.meta.url),
|
|
13
|
+
args: [host],
|
|
14
|
+
watch: new URL("../package.json", import.meta.url),
|
|
15
|
+
onToolsChanged: () => mcp?.toolsChanged(),
|
|
16
|
+
});
|
|
17
|
+
mcp = serveMcp({
|
|
18
|
+
name: "temmo",
|
|
19
|
+
version: VERSION,
|
|
20
|
+
instructions: INSTRUCTIONS,
|
|
21
|
+
listChanged: true,
|
|
22
|
+
listTools: () => workers.listTools(),
|
|
23
|
+
callTool: (name, args, signal) => workers.callTool(name, args, signal),
|
|
24
|
+
});
|
|
25
|
+
// A top-level await would hold module evaluation for the whole session.
|
|
26
|
+
// oxlint-disable-next-line unicorn/prefer-top-level-await
|
|
27
|
+
void mcp.closed.then(() => workers.stop());
|