@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,103 @@
|
|
|
1
|
+
/** `temmo mission ...`: read and edit MISSION.md, the PM's mission file in git, read at every scheduled tick. */
|
|
2
|
+
import { MISSION_FILE, editMission, missionPath, readMission, renderMission } from "./mission.js";
|
|
3
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by the runtime subcommand
|
|
4
|
+
const USAGE = {
|
|
5
|
+
show: "usage: mission show",
|
|
6
|
+
check: "usage: mission check",
|
|
7
|
+
"add-goal": 'usage: mission add-goal "<text>"',
|
|
8
|
+
"add-rule": 'usage: mission add-rule "<text>"',
|
|
9
|
+
"done-goal": "usage: mission done-goal <n>",
|
|
10
|
+
"open-goal": "usage: mission open-goal <n>",
|
|
11
|
+
"remove-goal": "usage: mission remove-goal <n>",
|
|
12
|
+
"remove-rule": "usage: mission remove-rule <n>",
|
|
13
|
+
};
|
|
14
|
+
// The 0-based index of a 1-based position in a list, as the argv names it; NaN for anything else.
|
|
15
|
+
function position(arg, length) {
|
|
16
|
+
const n = Number(arg);
|
|
17
|
+
return Number.isInteger(n) && n >= 1 && n <= length ? n - 1 : NaN;
|
|
18
|
+
}
|
|
19
|
+
const HELP_FLAGS = ["--help", "-h"];
|
|
20
|
+
const helpText = () => ["usage: temmo mission <command>", ...Object.values(USAGE)].join("\n");
|
|
21
|
+
export async function mission([sub = "show", ...rest], { env, cfg, out, err }) {
|
|
22
|
+
const fail = (key) => { err.write(`temmo: ${USAGE[key] ?? helpText()}\n`); return 1; };
|
|
23
|
+
// `mission --help` and `mission <command> --help` print usage instead of adding "--help" to a goal.
|
|
24
|
+
if (sub === "help" || HELP_FLAGS.includes(sub)) {
|
|
25
|
+
out.write(`${helpText()}\n`);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
if (rest.some((a) => HELP_FLAGS.includes(a))) {
|
|
29
|
+
if (!(sub in USAGE)) {
|
|
30
|
+
err.write(`temmo: mission: unknown command "${sub}"\n${helpText()}\n`);
|
|
31
|
+
return 1;
|
|
32
|
+
}
|
|
33
|
+
out.write(`temmo: ${USAGE[sub]}\n`);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
if (!cfg.project) {
|
|
37
|
+
err.write("temmo: mission: TEMMO_PROJECT is not set and no project matches this folder\n");
|
|
38
|
+
return 2;
|
|
39
|
+
}
|
|
40
|
+
const file = missionPath(cfg.project, env);
|
|
41
|
+
try {
|
|
42
|
+
if (sub === "show" || sub === "check") {
|
|
43
|
+
if (rest.length)
|
|
44
|
+
return fail(sub);
|
|
45
|
+
const doc = readMission(file);
|
|
46
|
+
if (sub === "check") {
|
|
47
|
+
out.write(doc ? `${file}: ok (${doc.goals.length} goals, ${doc.rules.length} rules)\n` : `no ${MISSION_FILE} at ${file}\n`);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
if (!doc) {
|
|
51
|
+
out.write(`no ${MISSION_FILE} at ${file}\n`);
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
out.write(`${JSON.stringify(doc, null, 2)}\n`);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
if (sub === "add-goal" || sub === "add-rule") {
|
|
58
|
+
const text = rest.join(" ").trim();
|
|
59
|
+
if (!text)
|
|
60
|
+
return fail(sub);
|
|
61
|
+
const key = sub === "add-goal" ? "goals" : "rules";
|
|
62
|
+
const doc = await editMission(cfg.project, (current) => ({
|
|
63
|
+
...current,
|
|
64
|
+
[key]: [...current[key], key === "goals" ? { text, done: false } : text],
|
|
65
|
+
}), { env });
|
|
66
|
+
out.write(renderMission(doc));
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
if (sub === "done-goal" || sub === "open-goal") {
|
|
70
|
+
const [arg, ...extra] = rest;
|
|
71
|
+
if (!arg || extra.length)
|
|
72
|
+
return fail(sub);
|
|
73
|
+
const done = sub === "done-goal";
|
|
74
|
+
const doc = await editMission(cfg.project, (current) => {
|
|
75
|
+
const at = position(arg, current.goals.length);
|
|
76
|
+
if (Number.isNaN(at))
|
|
77
|
+
throw new Error(`there is no goal ${arg}; the file has ${current.goals.length}`);
|
|
78
|
+
return { ...current, goals: current.goals.map((goal, i) => (i === at ? { ...goal, done } : goal)) };
|
|
79
|
+
}, { env });
|
|
80
|
+
out.write(renderMission(doc));
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
if (sub === "remove-goal" || sub === "remove-rule") {
|
|
84
|
+
const [arg, ...extra] = rest;
|
|
85
|
+
if (!arg || extra.length)
|
|
86
|
+
return fail(sub);
|
|
87
|
+
const key = sub === "remove-goal" ? "goals" : "rules";
|
|
88
|
+
const doc = await editMission(cfg.project, (current) => {
|
|
89
|
+
const at = position(arg, current[key].length);
|
|
90
|
+
if (Number.isNaN(at))
|
|
91
|
+
throw new Error(`there is no ${key === "goals" ? "goal" : "rule"} ${arg}; the file has ${current[key].length}`);
|
|
92
|
+
return { ...current, [key]: current[key].filter((_, i) => i !== at) };
|
|
93
|
+
}, { env });
|
|
94
|
+
out.write(renderMission(doc));
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
err.write(`temmo: mission ${sub}: ${error.message}\n`);
|
|
100
|
+
return 1;
|
|
101
|
+
}
|
|
102
|
+
return fail(sub);
|
|
103
|
+
}
|
package/lib/mission.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PM mission file: MISSION.md at the project root, in git, owned and edited by the PM, and read at every tick.
|
|
3
|
+
* The shape is an H1 title, the mission prose, then "## Goals" (a checkbox list) and "## Rules" (a bullet list).
|
|
4
|
+
* A missing file reads as null; an invalid file throws with its line. Writes go through a temp file and a rename.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { harnessOfCommand } from "./schedule-session.js";
|
|
9
|
+
import { projectRoot } from "./sessions/launch.js";
|
|
10
|
+
import { withLock } from "./state.js";
|
|
11
|
+
export const MISSION_FILE = "MISSION.md";
|
|
12
|
+
export const MISSION_VERSION = 1;
|
|
13
|
+
// The whole file is appended to a tick's prompt, so it stays small: a mission, its goals and its rules.
|
|
14
|
+
export const MISSION_MAX_BYTES = 16 * 1024;
|
|
15
|
+
export const TITLE_MAX = 200;
|
|
16
|
+
export const LINE_MAX = 300;
|
|
17
|
+
export const GOALS_MAX = 40;
|
|
18
|
+
export const RULES_MAX = 40;
|
|
19
|
+
const TITLE = /^#\s+(.+?)\s*$/;
|
|
20
|
+
const SECTION = /^##\s+(.+?)\s*$/;
|
|
21
|
+
const GOAL = /^-\s+\[([ xX])\]\s+(.+?)\s*$/;
|
|
22
|
+
const RULE = /^-\s+(.+?)\s*$/;
|
|
23
|
+
// Control characters would put escape codes into an agent's prompt.
|
|
24
|
+
const CONTROL = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
25
|
+
/** The mission file's path for a project: MISSION.md at the registered root. Throws for an unregistered project. */
|
|
26
|
+
export function missionPath(project, env = process.env) {
|
|
27
|
+
return join(projectRoot(project, env), MISSION_FILE);
|
|
28
|
+
}
|
|
29
|
+
function missionError(at, message) {
|
|
30
|
+
return new Error(at ? `mission: line ${at}: ${message}` : `mission: ${message}`);
|
|
31
|
+
}
|
|
32
|
+
function checkText(text, at, what) {
|
|
33
|
+
if (!text.trim())
|
|
34
|
+
throw missionError(at, `${what} is empty`);
|
|
35
|
+
if (text.length > LINE_MAX)
|
|
36
|
+
throw missionError(at, `${what} is over ${LINE_MAX} characters`);
|
|
37
|
+
if (CONTROL.test(text))
|
|
38
|
+
throw missionError(at, `${what} has a control character`);
|
|
39
|
+
}
|
|
40
|
+
/** Checks a parsed mission and returns it; throws on the first problem. */
|
|
41
|
+
export function validateMission(doc) {
|
|
42
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc))
|
|
43
|
+
throw missionError(0, "expected an object");
|
|
44
|
+
const obj = doc;
|
|
45
|
+
checkText(typeof obj.title === "string" ? obj.title : "", 0, "title");
|
|
46
|
+
if (obj.title.length > TITLE_MAX)
|
|
47
|
+
throw missionError(0, `title is over ${TITLE_MAX} characters`);
|
|
48
|
+
if (typeof obj.mission !== "string" || !(obj.mission).trim())
|
|
49
|
+
throw missionError(0, "the mission prose is empty");
|
|
50
|
+
// Sections must exist and be well formed; either may be empty, and the tick points that out.
|
|
51
|
+
if (!Array.isArray(obj.goals))
|
|
52
|
+
throw missionError(0, "goals must be a list");
|
|
53
|
+
if (obj.goals.length > GOALS_MAX)
|
|
54
|
+
throw missionError(0, `at most ${GOALS_MAX} goals`);
|
|
55
|
+
for (const goal of obj.goals) {
|
|
56
|
+
if (!goal || typeof goal !== "object" || typeof goal.text !== "string" || typeof goal.done !== "boolean")
|
|
57
|
+
throw missionError(0, "a goal is {text, done}");
|
|
58
|
+
checkText(goal.text, 0, "a goal");
|
|
59
|
+
}
|
|
60
|
+
if (!Array.isArray(obj.rules))
|
|
61
|
+
throw missionError(0, "rules must be a list");
|
|
62
|
+
if (obj.rules.length > RULES_MAX)
|
|
63
|
+
throw missionError(0, `at most ${RULES_MAX} rules`);
|
|
64
|
+
for (const rule of obj.rules) {
|
|
65
|
+
if (typeof rule !== "string")
|
|
66
|
+
throw missionError(0, "a rule is text");
|
|
67
|
+
checkText(rule, 0, "a rule");
|
|
68
|
+
}
|
|
69
|
+
return { v: MISSION_VERSION, title: obj.title, mission: obj.mission, goals: obj.goals.map(({ text, done }) => ({ text: text, done: done })), rules: [...obj.rules] };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* MISSION.md as {v, title, mission, goals: [{text, done}], rules}. The mission prose runs from the title to
|
|
73
|
+
* "## Goals"; a blank line there separates paragraphs and runs of them collapse to one.
|
|
74
|
+
*/
|
|
75
|
+
export function parseMission(text) {
|
|
76
|
+
if (typeof text !== "string")
|
|
77
|
+
throw missionError(0, "expected text");
|
|
78
|
+
if (text.includes("\r"))
|
|
79
|
+
throw missionError(0, "use LF line endings, not CRLF");
|
|
80
|
+
if (Buffer.byteLength(text) > MISSION_MAX_BYTES)
|
|
81
|
+
throw missionError(0, `the file is over ${MISSION_MAX_BYTES / 1024} KB`);
|
|
82
|
+
let title = "";
|
|
83
|
+
const prose = [];
|
|
84
|
+
const goals = [];
|
|
85
|
+
const rules = [];
|
|
86
|
+
const seen = new Set();
|
|
87
|
+
let section = "mission";
|
|
88
|
+
let paragraph = false;
|
|
89
|
+
text.split("\n").forEach((raw, index) => {
|
|
90
|
+
const at = index + 1;
|
|
91
|
+
const line = raw.replace(/\s+$/, "");
|
|
92
|
+
if (!line.trim()) {
|
|
93
|
+
if (title && section === "mission" && prose.length)
|
|
94
|
+
paragraph = true;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!title) {
|
|
98
|
+
const match = TITLE.exec(line);
|
|
99
|
+
if (!match)
|
|
100
|
+
throw missionError(at, "the first line is \"# <title>\"");
|
|
101
|
+
checkText(match[1], at, "title");
|
|
102
|
+
title = match[1];
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const heading = SECTION.exec(line);
|
|
106
|
+
if (heading) {
|
|
107
|
+
const name = heading[1].toLowerCase();
|
|
108
|
+
if (name === "goals" || name === "rules") {
|
|
109
|
+
if (seen.has(name))
|
|
110
|
+
throw missionError(at, `"## ${heading[1]}" appears twice`);
|
|
111
|
+
if (name === "goals" && seen.has("rules"))
|
|
112
|
+
throw missionError(at, "\"## Goals\" comes before \"## Rules\"");
|
|
113
|
+
seen.add(name);
|
|
114
|
+
section = name;
|
|
115
|
+
paragraph = false;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
throw missionError(at, `unknown section "## ${heading[1]}"; the file has "## Goals" and "## Rules"`);
|
|
119
|
+
}
|
|
120
|
+
if (line.startsWith("#"))
|
|
121
|
+
throw missionError(at, "the only headings are the title, \"## Goals\" and \"## Rules\"");
|
|
122
|
+
if (section === "goals") {
|
|
123
|
+
const match = GOAL.exec(line);
|
|
124
|
+
if (!match)
|
|
125
|
+
throw missionError(at, "a goal is \"- [ ] text\" or \"- [x] text\"");
|
|
126
|
+
checkText(match[2], at, "a goal");
|
|
127
|
+
goals.push({ text: match[2], done: match[1] !== " " });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (section === "rules") {
|
|
131
|
+
const match = RULE.exec(line);
|
|
132
|
+
if (!match)
|
|
133
|
+
throw missionError(at, "a rule is \"- text\"");
|
|
134
|
+
checkText(match[1], at, "a rule");
|
|
135
|
+
rules.push(match[1]);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
checkText(line, at, "the mission line");
|
|
139
|
+
if (paragraph && prose.length)
|
|
140
|
+
prose.push("");
|
|
141
|
+
paragraph = false;
|
|
142
|
+
prose.push(line);
|
|
143
|
+
});
|
|
144
|
+
if (!title)
|
|
145
|
+
throw missionError(0, "the file is empty; it starts with \"# <title>\"");
|
|
146
|
+
for (const name of ["goals", "rules"])
|
|
147
|
+
if (!seen.has(name))
|
|
148
|
+
throw missionError(0, `add a "## ${name[0].toUpperCase()}${name.slice(1)}" section`);
|
|
149
|
+
return validateMission({ title, mission: prose.join("\n"), goals, rules });
|
|
150
|
+
}
|
|
151
|
+
/** The canonical MISSION.md text: one trailing newline, no trailing spaces, goals then rules. */
|
|
152
|
+
export function renderMission(doc) {
|
|
153
|
+
validateMission(doc);
|
|
154
|
+
return [
|
|
155
|
+
`# ${doc.title}`,
|
|
156
|
+
"",
|
|
157
|
+
...doc.mission.split("\n"),
|
|
158
|
+
"",
|
|
159
|
+
"## Goals",
|
|
160
|
+
"",
|
|
161
|
+
...doc.goals.map((goal) => `- [${goal.done ? "x" : " "}] ${goal.text}`),
|
|
162
|
+
"",
|
|
163
|
+
"## Rules",
|
|
164
|
+
"",
|
|
165
|
+
...doc.rules.map((rule) => `- ${rule}`),
|
|
166
|
+
"",
|
|
167
|
+
].join("\n");
|
|
168
|
+
}
|
|
169
|
+
/** The mission file parsed, or null when it does not exist. Throws with the path when it is invalid. */
|
|
170
|
+
export function readMission(file) {
|
|
171
|
+
if (!existsSync(file))
|
|
172
|
+
return null;
|
|
173
|
+
try {
|
|
174
|
+
return parseMission(readFileSync(file, "utf8"));
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
throw new Error(`${file}: ${error.message}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/** Validates, then writes through a temp file and rename so a reader never sees half a mission. */
|
|
181
|
+
export function writeMission(file, doc) {
|
|
182
|
+
validateMission(doc);
|
|
183
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
184
|
+
const tmp = `${file}.${process.pid}.${Date.now()}.tmp`;
|
|
185
|
+
writeFileSync(tmp, renderMission(doc));
|
|
186
|
+
renameSync(tmp, file);
|
|
187
|
+
return doc;
|
|
188
|
+
}
|
|
189
|
+
/** Reads, changes and writes the project's mission file under its lock; `change` gets the document and returns it. */
|
|
190
|
+
export async function editMission(project, change, { env = process.env } = {}) {
|
|
191
|
+
const file = missionPath(project, env);
|
|
192
|
+
const result = await withLock(file, async () => {
|
|
193
|
+
const doc = readMission(file);
|
|
194
|
+
if (!doc)
|
|
195
|
+
throw new Error(`${file}: no mission file; write one first`);
|
|
196
|
+
const next = validateMission(change(doc));
|
|
197
|
+
writeMission(file, next);
|
|
198
|
+
return next;
|
|
199
|
+
});
|
|
200
|
+
if (!result.locked)
|
|
201
|
+
throw new Error("the mission file is busy; retry");
|
|
202
|
+
return result.value;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The command with the mission appended to its last argument, so a scheduled agent reads the current file every
|
|
206
|
+
* tick instead of the operator copying it into the command. Only a harness command is touched: a plain script's
|
|
207
|
+
* argv has its own meaning. A missing or invalid file leaves the command alone.
|
|
208
|
+
*/
|
|
209
|
+
export function withMission(command, { project = "", env = process.env, log = () => { }, file = "" } = {}) {
|
|
210
|
+
if (!project || !harnessOfCommand(command))
|
|
211
|
+
return command;
|
|
212
|
+
// `file` is the PM workspace copy. Without it the registered project root is the file.
|
|
213
|
+
let doc;
|
|
214
|
+
let missionFile = file;
|
|
215
|
+
try {
|
|
216
|
+
missionFile = file || missionPath(project, env);
|
|
217
|
+
doc = readMission(missionFile);
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
log(`mission: ${error.message}; this tick runs without it`);
|
|
221
|
+
return command;
|
|
222
|
+
}
|
|
223
|
+
if (!doc) {
|
|
224
|
+
log(file
|
|
225
|
+
? `mission: no ${MISSION_FILE} at ${missionFile}; this tick runs without it`
|
|
226
|
+
: `mission: no ${MISSION_FILE} for project ${project}; this tick runs without it`);
|
|
227
|
+
return command;
|
|
228
|
+
}
|
|
229
|
+
// An empty section is valid but worth pointing out: the tick is the only reader.
|
|
230
|
+
const gaps = [!doc.goals.length && "no goals yet", !doc.rules.length && "no rules yet"].filter(Boolean);
|
|
231
|
+
const block = [
|
|
232
|
+
`Mission file ${MISSION_FILE}, owned and edited by the PM; keep it current.`,
|
|
233
|
+
...(file ? [`Edit ${missionFile}. The host checkout is not this workspace.`] : []),
|
|
234
|
+
...(gaps.length ? [`(${gaps.join(", ")})`] : []),
|
|
235
|
+
"",
|
|
236
|
+
renderMission(doc),
|
|
237
|
+
].join("\n");
|
|
238
|
+
const last = command.length - 1;
|
|
239
|
+
const prompt = command[last].trim() ? `${command[last]}\n\n${block}` : block;
|
|
240
|
+
return [...command.slice(0, last), prompt];
|
|
241
|
+
}
|
package/lib/mode.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { alertPriority, readAlertLevel } from "./alerts.js";
|
|
2
|
+
/**
|
|
3
|
+
* Operator AFK mode: on (away), off (present, default), quiet (alerts and blocking questions only).
|
|
4
|
+
* The ai-collab.mode event carries the mode, timestamp and optional GitHub login. Latest timestamp wins.
|
|
5
|
+
* Sessions learn the mode from claimInbox (recorded in session state) and from one fetch at SessionStart.
|
|
6
|
+
* A failed fetch is unknown, not off: off is what the topic says when its cached history holds no mode envelope.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { broadcastTopic, isGithubLogin, listProjects, loadConfig } from "./config.js";
|
|
11
|
+
import { pollCached, publish } from "./messaging.js";
|
|
12
|
+
import { readState, statePath, withLock, writeState } from "./state.js";
|
|
13
|
+
import { encodeEnvelope, parseWireEnvelope } from "./agui.js";
|
|
14
|
+
export const MODES = ["on", "off", "quiet"];
|
|
15
|
+
export const DEFAULT_MODE = Object.freeze({ mode: "off", ts: 0 });
|
|
16
|
+
const HISTORY = "12h"; // policy window: a mode older than this no longer describes the operator
|
|
17
|
+
// The mode this machine last read for the project, beside its sessions, so a session with no record of its own knows it.
|
|
18
|
+
const PROJECT_MODE_FILE = "operator-mode.json";
|
|
19
|
+
export { MACHINE_PREFIXES, WAKE_ENV, WAKE_PROMPT, machinePrompt, operatorPrompt } from "./machine-prompt.js";
|
|
20
|
+
/** The mode envelope as {mode, ts}, or null for anything else. */
|
|
21
|
+
export function parseMode(raw) {
|
|
22
|
+
const m = parseWireEnvelope(raw);
|
|
23
|
+
if (m?.kind !== "mode" || m.from !== "operator")
|
|
24
|
+
return null;
|
|
25
|
+
if (!MODES.includes(m.mode) || !Number.isSafeInteger(m.ts) || m.ts < 0)
|
|
26
|
+
return null;
|
|
27
|
+
return { mode: m.mode, ts: m.ts };
|
|
28
|
+
}
|
|
29
|
+
/** Latest mode in a list of bus events (oldest first); a tie goes to the later event. */
|
|
30
|
+
export function latestMode(events, start = null) {
|
|
31
|
+
let best = start;
|
|
32
|
+
for (const ev of events) {
|
|
33
|
+
const m = parseMode(ev.message);
|
|
34
|
+
if (m && (!best || m.ts >= best.ts))
|
|
35
|
+
best = m;
|
|
36
|
+
}
|
|
37
|
+
return best;
|
|
38
|
+
}
|
|
39
|
+
/** Merge a mode into session state in place; returns true when it changed the state. */
|
|
40
|
+
export function recordMode(state, m) {
|
|
41
|
+
if (!m || (state.mode && Number(state.mode.ts) > m.ts))
|
|
42
|
+
return false;
|
|
43
|
+
if (state.mode?.mode === m.mode && state.mode?.ts === m.ts)
|
|
44
|
+
return false;
|
|
45
|
+
state.mode = { mode: m.mode, ts: m.ts };
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
// A recorded mode as {mode, ts}, or null for anything else (missing, half-written, or an unknown mode name).
|
|
49
|
+
function validMode(m) {
|
|
50
|
+
return m && MODES.includes(m.mode) && Number.isFinite(m.ts) ? { mode: m.mode, ts: m.ts } : null;
|
|
51
|
+
}
|
|
52
|
+
/** The newest of the given modes by ts, or null when none of them is one. */
|
|
53
|
+
function newestMode(...modes) {
|
|
54
|
+
let best = null;
|
|
55
|
+
for (const cand of modes) {
|
|
56
|
+
const m = validMode(cand);
|
|
57
|
+
if (m && (!best || m.ts > best.ts))
|
|
58
|
+
best = m;
|
|
59
|
+
}
|
|
60
|
+
return best;
|
|
61
|
+
}
|
|
62
|
+
function projectModeFile(cfg) {
|
|
63
|
+
return path.join(cfg.stateDir, cfg.project, PROJECT_MODE_FILE);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The last mode any session on this machine read for the project, or null when none has.
|
|
67
|
+
* The topic keeps mode envelopes for 12 hours, so a mode set earlier is gone from its cache; this record keeps it.
|
|
68
|
+
*/
|
|
69
|
+
export function projectMode(cfg) {
|
|
70
|
+
try {
|
|
71
|
+
return validMode(JSON.parse(readFileSync(projectModeFile(cfg), "utf8")));
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Records the mode this machine read for the project, for a later session whose own read fails.
|
|
79
|
+
* Any successful read counts, including one that found no envelope (off, read at that moment); a failed read does not.
|
|
80
|
+
*/
|
|
81
|
+
export function saveProjectMode(cfg, m) {
|
|
82
|
+
if (!validMode(m) || !(m.ts > 0))
|
|
83
|
+
return;
|
|
84
|
+
const seen = projectMode(cfg);
|
|
85
|
+
if (seen && seen.ts >= m.ts)
|
|
86
|
+
return;
|
|
87
|
+
try {
|
|
88
|
+
writeState(projectModeFile(cfg), { mode: m.mode, ts: m.ts });
|
|
89
|
+
}
|
|
90
|
+
catch { /* no project record only costs the fallback */ }
|
|
91
|
+
}
|
|
92
|
+
/** The newest mode recorded for this session or for the project, without network; null when neither has one. */
|
|
93
|
+
export function recordedMode(cfg) {
|
|
94
|
+
return newestMode(readState(statePath(cfg)).mode, projectMode(cfg));
|
|
95
|
+
}
|
|
96
|
+
/** Mode recorded locally for this session or peer, without network; a mode nothing recorded reads as the default off. */
|
|
97
|
+
export function storedMode(cfg) {
|
|
98
|
+
return recordedMode(cfg) ?? { ...DEFAULT_MODE };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The current mode, or null when this session cannot tell: the read failed and neither this session nor the project
|
|
102
|
+
* records a mode. Null is not off — only a read of the topic, or the local record of one, may say off.
|
|
103
|
+
*/
|
|
104
|
+
export async function currentModeKnown(cfg, { poll = pollCached } = {}) {
|
|
105
|
+
if (!cfg.enabled)
|
|
106
|
+
return null;
|
|
107
|
+
let read;
|
|
108
|
+
try {
|
|
109
|
+
read = latestMode(await poll(cfg, broadcastTopic(cfg.project), HISTORY));
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// An unreachable topic says nothing about the mode: the last read on this machine stands, and no record is unknown.
|
|
113
|
+
return recordedMode(cfg);
|
|
114
|
+
}
|
|
115
|
+
const file = statePath(cfg);
|
|
116
|
+
const r = await withLock(file, async () => {
|
|
117
|
+
const state = readState(file);
|
|
118
|
+
// A successful read is knowledge: with no envelope in the cached history the mode is off. That record carries
|
|
119
|
+
// ts 0, so any real envelope outranks it, and the mode note announces the default once, as documented.
|
|
120
|
+
if (recordMode(state, read ?? DEFAULT_MODE))
|
|
121
|
+
writeState(file, state);
|
|
122
|
+
return validMode(state.mode) ?? { ...DEFAULT_MODE };
|
|
123
|
+
}).catch(() => ({ locked: false }));
|
|
124
|
+
const mode = (r.locked ? r.value : validMode(read)) ?? { ...DEFAULT_MODE };
|
|
125
|
+
saveProjectMode(cfg, mode);
|
|
126
|
+
return mode;
|
|
127
|
+
}
|
|
128
|
+
/** Fetch the latest mode from the broadcast topic, record it locally, and return it; unknown reads as the default off. */
|
|
129
|
+
export async function currentMode(cfg, opts = {}) {
|
|
130
|
+
return (await currentModeKnown(cfg, opts)) ?? { ...DEFAULT_MODE };
|
|
131
|
+
}
|
|
132
|
+
/** Publish one mode envelope to each config's broadcast topic; by names the UI user. Returns per-project results; never throws. */
|
|
133
|
+
export async function publishMode(cfgs, mode, { now = Date.now(), send = publish, by } = {}) {
|
|
134
|
+
if (!MODES.includes(mode))
|
|
135
|
+
throw new Error(`mode must be one of ${MODES.join(", ")}`);
|
|
136
|
+
if (by !== undefined && !isGithubLogin(by))
|
|
137
|
+
throw new Error("by must be a GitHub login");
|
|
138
|
+
const fields = { from: "operator", mode, ts: now, ...(by ? { by } : {}) };
|
|
139
|
+
return Promise.all(cfgs.map(async (cfg) => {
|
|
140
|
+
try {
|
|
141
|
+
await send(cfg, broadcastTopic(cfg.project), encodeEnvelope("mode", fields, cfg.wire), { title: `temmo: operator AFK mode ${mode}`, priority: alertPriority(readAlertLevel(), "other") });
|
|
142
|
+
return { project: cfg.project, ok: true };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return { project: cfg.project, ok: false, error: error.message };
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
/** Operator configs for every project in projects.json; falls back to the environment's project. */
|
|
150
|
+
export function operatorConfigs(env = process.env) {
|
|
151
|
+
const base = { ...env, TEMMO_PEER: "operator" };
|
|
152
|
+
const seen = new Set();
|
|
153
|
+
const cfgs = [];
|
|
154
|
+
for (const project of listProjects(env)) {
|
|
155
|
+
const cfg = loadConfig(base, { cwd: project.root });
|
|
156
|
+
const key = `${cfg.url} ${cfg.project}`;
|
|
157
|
+
if (cfg.enabled && !seen.has(key)) {
|
|
158
|
+
seen.add(key);
|
|
159
|
+
cfgs.push(cfg);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (!cfgs.length) {
|
|
163
|
+
const cfg = loadConfig(base);
|
|
164
|
+
if (cfg.enabled)
|
|
165
|
+
cfgs.push(cfg);
|
|
166
|
+
}
|
|
167
|
+
return cfgs;
|
|
168
|
+
}
|
|
169
|
+
// Cursor's AskQuestion opens a dialog in the terminal only, and no hook carries it to the phone as Claude's AskUserQuestion is.
|
|
170
|
+
const NATIVE_QUESTION_NOTE = "Cursor's own AskQuestion tool shows only in the terminal and never reaches the phone: ask through ask_question instead.";
|
|
171
|
+
/** One-line rules an agent follows in each mode. */
|
|
172
|
+
export function modeNote(mode, { session = "", afkWaitS = 600 } = {}) {
|
|
173
|
+
const s = session ? `session=${JSON.stringify(session)}` : "your session label";
|
|
174
|
+
const minutes = Math.round(afkWaitS / 60);
|
|
175
|
+
switch (mode) {
|
|
176
|
+
case "on":
|
|
177
|
+
return "[temmo] Operator AFK mode is ON: the operator is away from the terminal. "
|
|
178
|
+
+ `At each milestone, post a one-line progress note with the temmo send_to_all tool (progress=true, ${s}). `
|
|
179
|
+
+ `Ask anything that needs the human with the temmo ask_question tool (${s}); set important=true only when you cannot continue without the answer. `
|
|
180
|
+
+ `${NATIVE_QUESTION_NOTE} `
|
|
181
|
+
+ `To wait for the operator after your turn, call ask_question or the temmo wait_for_operator tool (${s}), then end your turn: the Stop hook waits up to ${minutes} min. `
|
|
182
|
+
+ "Otherwise your turn ends at once. An important question holds until it is answered.";
|
|
183
|
+
case "quiet":
|
|
184
|
+
return "[temmo] Operator AFK mode is QUIET: send no progress messages. "
|
|
185
|
+
+ `Use the temmo ask_question tool (${s}) only for blocking questions, with important=true; the Stop hook holds until they are answered. `
|
|
186
|
+
+ `${NATIVE_QUESTION_NOTE} `
|
|
187
|
+
+ "Context alerts still go out automatically. Still answer operator messages.";
|
|
188
|
+
default:
|
|
189
|
+
return "[temmo] Operator AFK mode is OFF: the operator is at the terminal. Send no progress messages; answer operator messages as instructed.";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The mode note this session has not seen yet (or always, with force), marking it as seen.
|
|
194
|
+
* The default (no envelope seen) counts as already announced. Returns "" when there is nothing new.
|
|
195
|
+
* With no mode recorded for this session it falls back to the project's last known one, and with none at all it says
|
|
196
|
+
* nothing: announcing OFF for an unread mode is what told headless sessions the operator was at the terminal.
|
|
197
|
+
*/
|
|
198
|
+
export async function takeModeNote(cfg, { force = false } = {}) {
|
|
199
|
+
if (!cfg.enabled || !cfg.session)
|
|
200
|
+
return "";
|
|
201
|
+
const file = statePath(cfg);
|
|
202
|
+
const r = await withLock(file, async () => {
|
|
203
|
+
const state = readState(file);
|
|
204
|
+
// A mode this machine never read is unknown, and unknown must not be announced as off.
|
|
205
|
+
const m = newestMode(state.mode, projectMode(cfg));
|
|
206
|
+
if (!m)
|
|
207
|
+
return "";
|
|
208
|
+
if (!force && (state.modeNotedTs ?? 0) === m.ts)
|
|
209
|
+
return "";
|
|
210
|
+
state.modeNotedTs = m.ts;
|
|
211
|
+
writeState(file, state);
|
|
212
|
+
return modeNote(m.mode, { session: cfg.session, afkWaitS: cfg.afkWaitS });
|
|
213
|
+
}).catch(() => ({ locked: false }));
|
|
214
|
+
return r.locked ? r.value : "";
|
|
215
|
+
}
|
package/lib/models.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model allowlists for sessions started from the phone, so only a listed name reaches a harness's argv.
|
|
3
|
+
* claude: aliases and full ids from https://code.claude.com/docs/en/model-config (#model-aliases).
|
|
4
|
+
* codex: visible slugs in $CODEX_HOME/models_cache.json (Codex's own model catalog cache) plus config.toml's model.
|
|
5
|
+
* cursor: `cursor-agent --list-models`, cached in the state dir for a day.
|
|
6
|
+
* opencode: `opencode models` (provider/model per line), cached the same way.
|
|
7
|
+
* pi: `pi --list-models` (a provider and a model column per line), cached the same way.
|
|
8
|
+
*/
|
|
9
|
+
import { execFile } from "node:child_process";
|
|
10
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
import { MODEL_NAME, cursorBinary, modelShape } from "./harness.js";
|
|
14
|
+
import { childEnv } from "./sessions/launch.js";
|
|
15
|
+
import { findExecutable } from "./sessions/scope.js";
|
|
16
|
+
export const CLAUDE_MODELS = [
|
|
17
|
+
"fable", "opus", "sonnet", "haiku", "best", "opusplan", "sonnet[1m]", "opus[1m]",
|
|
18
|
+
"claude-fable-5-2", "claude-fable-5-1", "claude-fable-5", "claude-opus-5-5", "claude-opus-5", "claude-opus-4-8",
|
|
19
|
+
"claude-opus-4-7", "claude-opus-4-6", "claude-opus-4-1", "claude-sonnet-5", "claude-sonnet-4-6", "claude-sonnet-4-5",
|
|
20
|
+
"claude-haiku-5-5", "claude-haiku-4-5",
|
|
21
|
+
];
|
|
22
|
+
const CURSOR_CACHE_MS = 24 * 3600_000;
|
|
23
|
+
const CURSOR_TIMEOUT_MS = 20_000;
|
|
24
|
+
const CURSOR_LINE = /^([a-zA-Z0-9][a-zA-Z0-9._-]{0,79}) - \S/;
|
|
25
|
+
const valid = (list) => [...new Set(list.filter((name) => typeof name === "string" && MODEL_NAME.test(name)))];
|
|
26
|
+
/** Codex models: the catalog cache's listed slugs, plus the model set in config.toml. */
|
|
27
|
+
export function codexModels(env = process.env) {
|
|
28
|
+
const home = env.CODEX_HOME || join(env.HOME || homedir(), ".codex");
|
|
29
|
+
let listed = [];
|
|
30
|
+
try {
|
|
31
|
+
const models = JSON.parse(readFileSync(join(home, "models_cache.json"), "utf8")).models;
|
|
32
|
+
if (Array.isArray(models))
|
|
33
|
+
listed = models.filter((m) => m?.visibility !== "hide").map((m) => m?.slug);
|
|
34
|
+
}
|
|
35
|
+
catch { /* no cache yet */ }
|
|
36
|
+
let configured = "";
|
|
37
|
+
try {
|
|
38
|
+
configured = /^model\s*=\s*"([^"\n]+)"/m.exec(readFileSync(join(home, "config.toml"), "utf8"))?.[1] || "";
|
|
39
|
+
}
|
|
40
|
+
catch { /* no config */ }
|
|
41
|
+
return valid([configured, ...listed]);
|
|
42
|
+
}
|
|
43
|
+
/** Model names from `cursor-agent --list-models` output: lines of "<name> - <label>". */
|
|
44
|
+
export function parseCursorModels(text) {
|
|
45
|
+
return valid(String(text).split("\n").map((line) => CURSOR_LINE.exec(line.trim())?.[1]));
|
|
46
|
+
}
|
|
47
|
+
/** Model names from `opencode models` output: the first word of each line, shaped provider/model. */
|
|
48
|
+
export function parseOpenCodeModels(text) {
|
|
49
|
+
const names = String(text).split("\n").map((line) => line.trim().split(/\s+/)[0]);
|
|
50
|
+
return [...new Set(names.filter((name) => modelShape("opencode", name)))];
|
|
51
|
+
}
|
|
52
|
+
/** Model names from `pi --list-models` output: provider and model columns after the header row, joined provider/model. */
|
|
53
|
+
export function parsePiModels(text) {
|
|
54
|
+
const names = String(text).split("\n").slice(1).map((line) => line.trim().split(/\s+/)).map(([provider, model]) => `${provider}/${model}`);
|
|
55
|
+
return [...new Set(names.filter((name) => modelShape("pi", name)))];
|
|
56
|
+
}
|
|
57
|
+
function runList(file, env, args = ["--list-models"]) {
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
execFile(file, args, { env, timeout: CURSOR_TIMEOUT_MS, maxBuffer: 1 << 20, shell: false }, (error, stdout) => {
|
|
60
|
+
resolve(error ? "" : String(stdout));
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
// A model list from a day-old cache file or a fresh run of the harness's list command; a stale cache when the run fails.
|
|
65
|
+
async function cachedList(stateDir, env, { name, executable, args, parse, check, now, run }) {
|
|
66
|
+
const cache = join(stateDir, `models-${name}.json`);
|
|
67
|
+
let cached = null;
|
|
68
|
+
try {
|
|
69
|
+
const value = JSON.parse(readFileSync(cache, "utf8"));
|
|
70
|
+
if (Array.isArray(value.list) && Number.isFinite(value.at))
|
|
71
|
+
cached = { at: value.at, list: value.list.filter(check) };
|
|
72
|
+
}
|
|
73
|
+
catch { /* none */ }
|
|
74
|
+
if (cached && now - cached.at < CURSOR_CACHE_MS)
|
|
75
|
+
return cached.list;
|
|
76
|
+
const vars = childEnv(env);
|
|
77
|
+
const file = findExecutable(executable, vars.PATH);
|
|
78
|
+
const list = file ? parse(await run(file, vars, args)) : [];
|
|
79
|
+
if (!list.length)
|
|
80
|
+
return cached?.list || [];
|
|
81
|
+
try {
|
|
82
|
+
mkdirSync(dirname(cache), { recursive: true, mode: 0o700 });
|
|
83
|
+
writeFileSync(cache, JSON.stringify({ at: now, list }), { mode: 0o600 });
|
|
84
|
+
}
|
|
85
|
+
catch { /* uncached */ }
|
|
86
|
+
return list;
|
|
87
|
+
}
|
|
88
|
+
/** Cursor models, from a day-old cache or a fresh `<cursor cli> --list-models`; a stale cache when the command fails. */
|
|
89
|
+
export function cursorModels(stateDir, env = process.env, { now = Date.now(), run = runList } = {}) {
|
|
90
|
+
const check = (name) => typeof name === "string" && MODEL_NAME.test(name);
|
|
91
|
+
// A bare name: cachedList resolves it against PATH, and cursorBinary already chose which name that is.
|
|
92
|
+
const executable = cursorBinary(childEnv(env).PATH);
|
|
93
|
+
return cachedList(stateDir, env, { name: "cursor", executable, args: ["--list-models"], parse: parseCursorModels, check, now, run });
|
|
94
|
+
}
|
|
95
|
+
/** OpenCode models, from a day-old cache or a fresh `opencode models` (which uses OpenCode's background server). */
|
|
96
|
+
export function opencodeModels(stateDir, env = process.env, { now = Date.now(), run = runList } = {}) {
|
|
97
|
+
const check = (name) => modelShape("opencode", name);
|
|
98
|
+
return cachedList(stateDir, env, { name: "opencode", executable: "opencode", args: ["models"], parse: parseOpenCodeModels, check, now, run });
|
|
99
|
+
}
|
|
100
|
+
/** pi models, from a day-old cache or a fresh `pi --list-models` (offline, so no provider is called). */
|
|
101
|
+
export function piModels(stateDir, env = process.env, { now = Date.now(), run = runList } = {}) {
|
|
102
|
+
const check = (name) => modelShape("pi", name);
|
|
103
|
+
return cachedList(stateDir, { ...env, PI_OFFLINE: "1" }, { name: "pi", executable: "pi", args: ["--list-models"], parse: parsePiModels, check, now, run });
|
|
104
|
+
}
|
|
105
|
+
/** {claude, codex, cursor, opencode, pi}: the names each harness accepts in a start request; peers skips unlisted CLIs. */
|
|
106
|
+
export async function listModels(stateDir, env = process.env, options = {}) {
|
|
107
|
+
const { peers = [], ...rest } = options;
|
|
108
|
+
const wanted = (h) => !peers.length || peers.includes(h);
|
|
109
|
+
return {
|
|
110
|
+
claude: [...CLAUDE_MODELS], codex: codexModels(env), cursor: wanted("cursor") ? await cursorModels(stateDir, env, rest) : [],
|
|
111
|
+
opencode: wanted("opencode") ? await opencodeModels(stateDir, env, rest) : [],
|
|
112
|
+
pi: wanted("pi") ? await piModels(stateDir, env, rest) : [],
|
|
113
|
+
};
|
|
114
|
+
}
|