@temmo/cli 0.0.0-stage → 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 +110 -4
- 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,33 @@
|
|
|
1
|
+
// Serves a tool list over MCP stdio with the official SDK; tool definitions pass through unchanged.
|
|
2
|
+
// The plugin runs without node_modules, so the SDK comes from a checked-in bundle (tools/vendor-mcp-sdk.mjs).
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, Server, StdioServerTransport } from "../vendor/mcp-sdk.mjs";
|
|
4
|
+
/** Reads requests from stdin and answers on stdout. A thrown tool error becomes an isError result. */
|
|
5
|
+
export function serveMcp(surface) {
|
|
6
|
+
const server = new Server({ name: surface.name, version: surface.version }, { capabilities: { tools: surface.listChanged ? { listChanged: true } : {} }, instructions: surface.instructions });
|
|
7
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: (await surface.listTools()) }));
|
|
8
|
+
// End of input aborts the calls still running, then waits for their answers: a piped request still gets one.
|
|
9
|
+
const gone = new AbortController();
|
|
10
|
+
const running = new Set();
|
|
11
|
+
server.setRequestHandler(CallToolRequestSchema, async ({ params }, { signal }) => {
|
|
12
|
+
try {
|
|
13
|
+
const call = surface.callTool(params.name, params.arguments ?? {}, AbortSignal.any([signal, gone.signal]));
|
|
14
|
+
running.add(call);
|
|
15
|
+
void call.finally(() => running.delete(call)).catch(() => { });
|
|
16
|
+
const { text, isError } = await call;
|
|
17
|
+
return { ...(isError ? { isError: true } : {}), content: [{ type: "text", text }] };
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return { isError: true, content: [{ type: "text", text: error.message }] };
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const transport = new StdioServerTransport();
|
|
24
|
+
// The SDK transport ignores end of input, so the server closes itself once the answers are written.
|
|
25
|
+
const closed = new Promise((resolve) => process.stdin.once("end", async () => {
|
|
26
|
+
gone.abort();
|
|
27
|
+
await Promise.allSettled([...running]);
|
|
28
|
+
await new Promise((settle) => setImmediate(settle));
|
|
29
|
+
await server.close().finally(resolve);
|
|
30
|
+
}));
|
|
31
|
+
void server.connect(transport);
|
|
32
|
+
return { toolsChanged: () => { void server.sendToolListChanged().catch(() => { }); }, closed };
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// MCP tools for run in terminal (lib/run-terminal.ts); listed only on the host with runInTerminal on.
|
|
2
|
+
import { RUN_ID, REASON_MAX, SCRIPT_MAX_BYTES, TIMEOUT_MAX_S, createRunRequest, onHost, runInTerminalEnabled, waitForRun } from "../run-terminal.js";
|
|
3
|
+
import { IDENTITY, WAIT } from "./schema.js";
|
|
4
|
+
import { passJs } from "./types.js";
|
|
5
|
+
const available = (env) => onHost(env) && runInTerminalEnabled(env);
|
|
6
|
+
export const RUN_TERMINAL_OPS = [
|
|
7
|
+
{
|
|
8
|
+
name: "run_in_terminal",
|
|
9
|
+
description: "Propose a bash script for the operator to run on the host. The operator reads the exact script, its cwd, your reason and its sha256 in the UI and clicks Run or Reject; nothing runs without that click. Returns a request id at once; call run_in_terminal_result with it for the exit code and output. A request runs at most once and expires after 15 minutes.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object", required: ["script", "cwd", "reason", "session"], additionalProperties: false,
|
|
12
|
+
properties: {
|
|
13
|
+
script: { type: "string", minLength: 1, description: `Bash script, at most ${SCRIPT_MAX_BYTES} bytes; tab and newline are the only control characters allowed.` },
|
|
14
|
+
cwd: { type: "string", minLength: 1, description: "Absolute path of an existing directory to run in." },
|
|
15
|
+
reason: { type: "string", minLength: 1, maxLength: REASON_MAX, description: "One line telling the operator why." },
|
|
16
|
+
session: IDENTITY,
|
|
17
|
+
timeout_s: { type: "integer", minimum: 1, maximum: TIMEOUT_MAX_S, default: 300, description: "Seconds before the script's process group is killed." },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
surfaces: ["mcp"],
|
|
21
|
+
needsSession: true,
|
|
22
|
+
available,
|
|
23
|
+
handler: (args, { cfg, env }) => createRunRequest(passJs(cfg), passJs({ script: args.script, cwd: args.cwd, reason: args.reason, timeoutS: args.timeout_s }), env),
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: "run_in_terminal_result",
|
|
27
|
+
description: "Wait for a run_in_terminal request: returns status pending, running, done, lost, rejected, expired or refused, and once done the exit code, stdout and stderr tails (16 KB each) and duration. Returns the current status when the wait ends first.",
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: "object", required: ["id"], additionalProperties: false,
|
|
30
|
+
properties: { id: { type: "string", pattern: RUN_ID.source }, wait_seconds: WAIT },
|
|
31
|
+
},
|
|
32
|
+
surfaces: ["mcp"],
|
|
33
|
+
available,
|
|
34
|
+
handler: (args, { cfg, env, signal }) => {
|
|
35
|
+
if (!available(env))
|
|
36
|
+
throw new Error("run_in_terminal runs only on the host with runInTerminal on");
|
|
37
|
+
return waitForRun(passJs(cfg), passJs(args.id), passJs(args.wait_seconds ?? 25), signal);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// MCP tools for sandbox change proposals (lib/sandbox-proposal.ts); listed everywhere, since the proposal and its
|
|
2
|
+
// outcome travel on the bus: an agent inside an OpenShell sandbox can propose and read the decision without host access.
|
|
3
|
+
import { PROPOSAL_ID, proposeSandboxChange, waitForChangeResult } from "../sandbox-proposal.js";
|
|
4
|
+
import { IDENTITY, WAIT } from "./schema.js";
|
|
5
|
+
import { passJs } from "./types.js";
|
|
6
|
+
const HOSTS = { type: "array", maxItems: 20, items: { type: "string" }, description: "host[:port] entries (egress the personal policy rule adds or drops)." };
|
|
7
|
+
const TOOLS = { type: "array", maxItems: 20, items: { type: "string", pattern: "^[a-z0-9][a-z0-9._+-]{0,63}$" }, description: "Host binaries to copy into every sandbox's tools/bin; each must exist on the host PATH when the operator approves." };
|
|
8
|
+
export const SANDBOX_OPS = [
|
|
9
|
+
{
|
|
10
|
+
name: "propose_sandbox_change",
|
|
11
|
+
description: "Ask the operator to change the shared OpenShell sandbox config: egress hosts (host[:port]) and tools copied into sandboxes. The operator gets an approval card; only their approval (phone UI or temmo sandbox approve) writes ~/.config/temmo/sandbox-hosts.json and sandbox-tools.json and re-applies the change to live sandboxes. Returns a proposal id at once; call sandbox_change_result with it for the outcome. You cannot approve your own proposal.",
|
|
12
|
+
inputSchema: {
|
|
13
|
+
type: "object", required: ["reason", "session"], additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
add_hosts: HOSTS, remove_hosts: HOSTS, add_tools: TOOLS, remove_tools: TOOLS,
|
|
16
|
+
reason: { type: "string", minLength: 1, maxLength: 500, description: "One line telling the operator why this change is needed." },
|
|
17
|
+
session: IDENTITY,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
surfaces: ["mcp"],
|
|
21
|
+
needsSession: true,
|
|
22
|
+
handler: (args, { cfg, env, host }) => proposeSandboxChange(cfg, passJs({
|
|
23
|
+
add_hosts: args.add_hosts, remove_hosts: args.remove_hosts, add_tools: args.add_tools, remove_tools: args.remove_tools, reason: args.reason,
|
|
24
|
+
}), { env, harness: host }),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "sandbox_change_result",
|
|
28
|
+
description: "Wait for the operator's decision on a propose_sandbox_change proposal: status pending, applied, denied, skipped or failed (failed carries why). An applied change is already written and re-applied to live sandboxes; new sandboxes get it at their next create.",
|
|
29
|
+
inputSchema: {
|
|
30
|
+
type: "object", required: ["id"], additionalProperties: false,
|
|
31
|
+
properties: { id: { type: "string", pattern: PROPOSAL_ID.source }, wait_seconds: WAIT },
|
|
32
|
+
},
|
|
33
|
+
surfaces: ["mcp"],
|
|
34
|
+
handler: (args, { cfg, signal }) => waitForChangeResult(cfg, passJs(args.id), passJs({ seconds: args.wait_seconds ?? 25, signal })),
|
|
35
|
+
},
|
|
36
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Input-schema fragments shared by the operation table; JSON Schema is the MCP wire format, so no zod here.
|
|
2
|
+
import { MAX_BODY_CHARS } from "../config.js";
|
|
3
|
+
export const WAIT = { type: "integer", minimum: 0, maximum: 45, default: 25 };
|
|
4
|
+
export const IDENTITY = { type: "string", pattern: "^[a-f0-9]{16}$", description: "Session label from the temmo hook context." };
|
|
5
|
+
export const MESSAGE_ID = { type: "string", pattern: "^[a-zA-Z0-9-]{1,64}$" };
|
|
6
|
+
export const BODY = { type: "string", minLength: 1, maxLength: MAX_BODY_CHARS };
|
|
7
|
+
export const URGENT = { type: "boolean", default: false, description: "Deliver at the recipient's very next hook event (its next tool call or stop), skipping the poll throttle. Nothing interrupts a model mid-generation." };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Task fields as agents see them through the MCP and code surfaces.
|
|
2
|
+
import { ID_MAX, PROGRESS_MAX, STATUSES, TASK_PRIORITIES, clipProgress, openTasks, priorityOf, sortTasks } from "../tasks.js";
|
|
3
|
+
import { IDENTITY } from "./schema.js";
|
|
4
|
+
export const TASK_LIST_SCHEMA = {
|
|
5
|
+
type: "object", required: ["session"], additionalProperties: false,
|
|
6
|
+
properties: {
|
|
7
|
+
status: { type: "string", enum: STATUSES }, query: { type: "string", maxLength: 200 },
|
|
8
|
+
ids: { type: "array", maxItems: 50, items: { type: "string", maxLength: ID_MAX } },
|
|
9
|
+
limit: { type: "integer", minimum: 1, maximum: 200 }, include_done: { type: "boolean" }, session: IDENTITY,
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
export const TASK_UPDATE_SCHEMA = {
|
|
13
|
+
type: "object", required: ["id", "session"], additionalProperties: false,
|
|
14
|
+
properties: {
|
|
15
|
+
id: { type: "string", pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$", maxLength: 40 },
|
|
16
|
+
priority: { type: "string", enum: TASK_PRIORITIES },
|
|
17
|
+
status: { type: "string", enum: STATUSES },
|
|
18
|
+
title: { type: "string", minLength: 1, maxLength: 300 },
|
|
19
|
+
detail: { type: "string", maxLength: 2000 },
|
|
20
|
+
run: { type: "string", pattern: "^[a-z0-9]{6,32}$" },
|
|
21
|
+
owner: { type: "string", pattern: "^[a-z0-9-]{1,24}#[a-f0-9]{16}$" },
|
|
22
|
+
block_on: { type: "string", pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$", maxLength: 40 },
|
|
23
|
+
progress: { type: "string", minLength: 1, maxLength: 4000 },
|
|
24
|
+
ask: { type: "string", minLength: 1, maxLength: 500 },
|
|
25
|
+
options: { type: "array", maxItems: 6, items: { type: "string", minLength: 1, maxLength: 80 } },
|
|
26
|
+
clear_question: { type: "boolean" },
|
|
27
|
+
session: IDENTITY,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
export function taskView(task) {
|
|
31
|
+
return {
|
|
32
|
+
id: task.id, title: task.title, priority: priorityOf(task), status: task.status, ...(task.detail ? { detail: task.detail } : {}),
|
|
33
|
+
...(task.owner ? { owner: task.owner } : {}), ...(task.run ? { run: task.run } : {}), blockers: task.blockers,
|
|
34
|
+
last: task.progress.at(-1) ?? null,
|
|
35
|
+
...(task.question ? { question: task.question } : {}),
|
|
36
|
+
...(task.review ? { review: task.review } : {}),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export const LIST_LIMIT = 30;
|
|
40
|
+
export const ROW_NOTE = 160;
|
|
41
|
+
const openQuestion = (task) => {
|
|
42
|
+
const question = task.question;
|
|
43
|
+
return question && !question.answer ? String(question.text ?? "") : null;
|
|
44
|
+
};
|
|
45
|
+
/** A search over the store: compact rows, done tasks only when asked; ids returns those tasks in full. */
|
|
46
|
+
export function listTasks(all, args) {
|
|
47
|
+
const ids = args.ids ?? [];
|
|
48
|
+
if (ids.length)
|
|
49
|
+
return { tasks: all.filter((task) => ids.includes(task.id)).map(taskView) };
|
|
50
|
+
const words = (args.query ?? "").toLowerCase().split(/\s+/).filter(Boolean);
|
|
51
|
+
const text = (task) => `${task.id} ${task.title} ${task.detail ?? ""}`.toLowerCase();
|
|
52
|
+
const hits = sortTasks(all).filter((task) => (args.status ? task.status === args.status : args.include_done || task.status !== "done"))
|
|
53
|
+
.filter((task) => words.every((word) => text(task).includes(word)));
|
|
54
|
+
const limit = args.limit ?? LIST_LIMIT;
|
|
55
|
+
return {
|
|
56
|
+
tasks: hits.slice(0, limit).map((task) => ({
|
|
57
|
+
id: task.id, title: task.title, priority: priorityOf(task), status: task.status, ...(task.owner ? { owner: task.owner } : {}),
|
|
58
|
+
...(task.run ? { run: task.run } : {}), blockers: task.blockers, last: String(task.progress.at(-1)?.text ?? "").slice(0, ROW_NOTE) || null,
|
|
59
|
+
...(openQuestion(task) ? { asks: openQuestion(task) } : {}), ...(task.review ? { review: true } : {}),
|
|
60
|
+
})),
|
|
61
|
+
total: hits.length,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// One task update: patch fields, block_on, and an optional progress note; the note's clipping comes back as a note.
|
|
65
|
+
export async function updateTask(cfg, args, env) {
|
|
66
|
+
const backend = openTasks(cfg.project, env);
|
|
67
|
+
const patch = {};
|
|
68
|
+
for (const key of ["status", "title", "detail", "run", "owner", "priority"])
|
|
69
|
+
if (args[key] !== undefined)
|
|
70
|
+
patch[key] = args[key];
|
|
71
|
+
if (args.block_on !== undefined)
|
|
72
|
+
patch.block = args.block_on;
|
|
73
|
+
if (args.ask !== undefined && args.clear_question)
|
|
74
|
+
throw new Error("ask and clear_question cannot be combined");
|
|
75
|
+
if (args.options !== undefined && args.ask === undefined)
|
|
76
|
+
throw new Error("options need ask");
|
|
77
|
+
if (args.ask !== undefined)
|
|
78
|
+
patch.ask = { text: args.ask, options: args.options, by: `${cfg.peer}#${cfg.session}` };
|
|
79
|
+
if (args.clear_question)
|
|
80
|
+
patch.ask = null;
|
|
81
|
+
// The changes and the progress note are one store transaction: all of them are validated, or none is written.
|
|
82
|
+
if (args.progress !== undefined)
|
|
83
|
+
patch.progress = { by: `${cfg.peer}#${cfg.session}`, text: args.progress };
|
|
84
|
+
const notes = [];
|
|
85
|
+
if (Object.keys(patch).length)
|
|
86
|
+
await backend.update(args.id, patch, Date.now());
|
|
87
|
+
if (args.progress !== undefined && clipProgress(args.progress).truncated)
|
|
88
|
+
notes.push(`progress clipped to ${PROGRESS_MAX} characters`);
|
|
89
|
+
return { task: taskView(backend.get(args.id)), ...(notes.length ? { notes } : {}) };
|
|
90
|
+
}
|
package/lib/task-cli.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/** `temmo task ...`: list, show, add, set, block, progress, ask, own, remove, render, import. Store: lib/tasks.ts. */
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { onHost } from "./run-terminal.js";
|
|
5
|
+
import { projectRoot } from "./sessions/launch.js";
|
|
6
|
+
import { busTaskCall } from "./task-route.js";
|
|
7
|
+
import { STATUSES, TASK_PRIORITIES, clipProgress, importReport, openTasks, priorityOf, renderFeatureRequests, sortTasks, validateTasks } from "./tasks.js";
|
|
8
|
+
const SET_FIELDS = ["status", "title", "detail", "run", "priority"];
|
|
9
|
+
const USAGE = {
|
|
10
|
+
outcomes: "usage: task outcomes",
|
|
11
|
+
"propose-outcome": 'usage: task propose-outcome <outcome-id> "<task title>" ["<task title>" ...]',
|
|
12
|
+
"report-outcome": 'usage: task report-outcome <outcome-id> pass|fail "<evidence>"',
|
|
13
|
+
list: "usage: task list [status]",
|
|
14
|
+
show: "usage: task show <id>",
|
|
15
|
+
add: "usage: task add \"<title>\" [--priority P0|P1|P2|P3]",
|
|
16
|
+
set: `usage: task set <id> status=<${STATUSES.join("|")}> | title=<text> | detail=<text> | run=<run-id> | priority=<${TASK_PRIORITIES.join("|")}>`,
|
|
17
|
+
block: "usage: task block <id> <blocker-id>",
|
|
18
|
+
progress: "usage: task progress <id> \"<text>\"",
|
|
19
|
+
own: "usage: task own <id> <session-address>",
|
|
20
|
+
ask: "usage: task ask <id> \"<question for the operator>\" [--option <choice>]... | task ask <id> --clear",
|
|
21
|
+
remove: "usage: task remove <id>",
|
|
22
|
+
render: "usage: task render",
|
|
23
|
+
import: "usage: task import <feature-requests.md | tasks.json>",
|
|
24
|
+
};
|
|
25
|
+
const HELP_FLAGS = ["--help", "-h"];
|
|
26
|
+
// Commands a sandboxed session runs through the bus; the rest need the host's store file.
|
|
27
|
+
const BUS_COMMANDS = ["list", "show", "add", "set", "block", "progress", "ask", "own"];
|
|
28
|
+
function localStore(cfg, env, now) {
|
|
29
|
+
const tasks = () => openTasks(cfg.project, env);
|
|
30
|
+
return {
|
|
31
|
+
list: async () => sortTasks(tasks().list()),
|
|
32
|
+
get: async (id) => tasks().get(id),
|
|
33
|
+
add: (fields) => tasks().add(fields, now),
|
|
34
|
+
update: async (id, patch) => { await tasks().update(id, patch, now); },
|
|
35
|
+
progress: async (id, text) => { await tasks().addProgress(id, { by: author(cfg), text }, now); },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// The CLI patch as task_update arguments; the bus stamps the caller's address on progress and questions.
|
|
39
|
+
function updateArgs(patch) {
|
|
40
|
+
const { block, ask, ...rest } = patch;
|
|
41
|
+
const question = ask;
|
|
42
|
+
return {
|
|
43
|
+
...rest, ...(block !== undefined ? { block_on: block } : {}), ...(question === null ? { clear_question: true } : {}),
|
|
44
|
+
...(question ? { ask: question.text, ...(question.options?.length ? { options: question.options } : {}) } : {}),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** The host store through the bus, as the calling session (docs/tasks.md#sandboxed-sessions). */
|
|
48
|
+
function busStore(cfg) {
|
|
49
|
+
if (!cfg.session || !cfg.peer || !cfg.url)
|
|
50
|
+
throw new Error("a sandboxed session reaches the task store through the bus: TEMMO_SESSION and the bus url are required");
|
|
51
|
+
const bus = { url: cfg.url, token: cfg.token, project: cfg.project, peer: cfg.peer };
|
|
52
|
+
const call = (op, args) => busTaskCall(bus, op, { ...args, session: cfg.session });
|
|
53
|
+
return {
|
|
54
|
+
list: async () => (await call("list", { include_done: true, limit: 200 })).tasks,
|
|
55
|
+
get: async (id) => {
|
|
56
|
+
const [found] = (await call("list", { ids: [id] })).tasks;
|
|
57
|
+
if (!found)
|
|
58
|
+
throw new Error(`${id} is not a task`);
|
|
59
|
+
return found;
|
|
60
|
+
},
|
|
61
|
+
add: async (fields) => (await call("add", fields)).task,
|
|
62
|
+
update: async (id, patch) => { await call("update", { id, ...updateArgs(patch) }); },
|
|
63
|
+
progress: async (id, text) => { await call("update", { id, progress: text }); },
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const helpText = () => ["usage: temmo task <command>", ...Object.values(USAGE)].join("\n");
|
|
67
|
+
// The address of the calling session (peer#label), else the peer name, else "cli".
|
|
68
|
+
function author(cfg) {
|
|
69
|
+
if (cfg.session && cfg.peer)
|
|
70
|
+
return `${cfg.peer}#${cfg.session}`;
|
|
71
|
+
return cfg.peer || "cli";
|
|
72
|
+
}
|
|
73
|
+
function line(task) {
|
|
74
|
+
return `${task.id}\t${task.status}\t${priorityOf(task)}\t${task.owner ?? "-"}\t${task.run ?? "-"}\t${task.title}`;
|
|
75
|
+
}
|
|
76
|
+
export async function task([sub, ...rest], { env, cfg, out, err }) {
|
|
77
|
+
const fail = (key) => { err.write(`temmo: ${USAGE[key]}\n`); return 1; };
|
|
78
|
+
// `task --help` and `task <command> --help` print usage instead of treating the flag as an argument.
|
|
79
|
+
if (sub === undefined || sub === "help" || HELP_FLAGS.includes(sub)) {
|
|
80
|
+
out.write(`${helpText()}\n`);
|
|
81
|
+
return 0;
|
|
82
|
+
}
|
|
83
|
+
if (rest.some((a) => HELP_FLAGS.includes(a))) {
|
|
84
|
+
if (!(sub in USAGE)) {
|
|
85
|
+
err.write(`temmo: task: unknown command "${sub}"\n${helpText()}\n`);
|
|
86
|
+
return 1;
|
|
87
|
+
}
|
|
88
|
+
out.write(`temmo: ${USAGE[sub]}\n`);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
if (!cfg.project) {
|
|
92
|
+
err.write("temmo: task: TEMMO_PROJECT is not set and no project matches this folder\n");
|
|
93
|
+
return 2;
|
|
94
|
+
}
|
|
95
|
+
const now = Date.now();
|
|
96
|
+
const sandboxed = !onHost(env);
|
|
97
|
+
if (sandboxed && !BUS_COMMANDS.includes(sub)) {
|
|
98
|
+
err.write(`temmo: task ${sub}: runs on the host only; a sandboxed session has ${BUS_COMMANDS.join(", ")}\n`);
|
|
99
|
+
return 1;
|
|
100
|
+
}
|
|
101
|
+
const project = cfg.project;
|
|
102
|
+
try {
|
|
103
|
+
const store = sandboxed ? busStore({ ...cfg, project }) : localStore({ ...cfg, project }, env, now);
|
|
104
|
+
if (sub === "outcomes") {
|
|
105
|
+
if (rest.length)
|
|
106
|
+
return fail(sub);
|
|
107
|
+
const { outcomes = [] } = openTasks(cfg.project, env).projectBoard();
|
|
108
|
+
out.write(JSON.stringify(outcomes.filter((entry) => entry.state !== "closed"), null, 2) + "\n");
|
|
109
|
+
return 0;
|
|
110
|
+
}
|
|
111
|
+
if (sub === "propose-outcome" || sub === "report-outcome") {
|
|
112
|
+
const [id, verdict, result] = rest;
|
|
113
|
+
const propose = sub === "propose-outcome";
|
|
114
|
+
if (!id || (!propose && (rest.length !== 3 || !["pass", "fail"].includes(verdict))))
|
|
115
|
+
return fail(sub);
|
|
116
|
+
await openTasks(cfg.project, env).outcome(propose ? "propose" : "report", { id, titles: rest.slice(1), passed: verdict === "pass", result, by: author(cfg) });
|
|
117
|
+
out.write(id + " updated\n");
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
if (sub === "list") {
|
|
121
|
+
if (rest.length > 1)
|
|
122
|
+
return fail("list");
|
|
123
|
+
const [status] = rest;
|
|
124
|
+
if (status !== undefined && !STATUSES.includes(status))
|
|
125
|
+
return fail("list");
|
|
126
|
+
for (const t of await store.list())
|
|
127
|
+
if (!status || t.status === status)
|
|
128
|
+
out.write(`${line(t)}\n`);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
if (sub === "show") {
|
|
132
|
+
const [id] = rest;
|
|
133
|
+
if (!id || rest.length > 1)
|
|
134
|
+
return fail("show");
|
|
135
|
+
out.write(`${JSON.stringify(await store.get(id), null, 2)}\n`);
|
|
136
|
+
return 0;
|
|
137
|
+
}
|
|
138
|
+
if (sub === "add") {
|
|
139
|
+
// --priority P1 (or --priority=P1) is not part of the title; anything else is.
|
|
140
|
+
const words = [];
|
|
141
|
+
let priority;
|
|
142
|
+
for (let i = 0; i < rest.length; i++) {
|
|
143
|
+
const a = rest[i];
|
|
144
|
+
if (a === "--priority") {
|
|
145
|
+
priority = rest[++i];
|
|
146
|
+
}
|
|
147
|
+
else if (a.startsWith("--priority=")) {
|
|
148
|
+
priority = a.slice("--priority=".length);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
words.push(a);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const title = words.join(" ").trim();
|
|
155
|
+
if (!title || (rest.includes("--priority") && priority === undefined))
|
|
156
|
+
return fail("add");
|
|
157
|
+
if (priority !== undefined && !TASK_PRIORITIES.includes(priority))
|
|
158
|
+
return fail("add");
|
|
159
|
+
const t = await store.add({ title, ...(priority ? { priority } : {}) });
|
|
160
|
+
out.write(`${t.id}\n`);
|
|
161
|
+
return 0;
|
|
162
|
+
}
|
|
163
|
+
if (sub === "set") {
|
|
164
|
+
const [id, ...assignments] = rest;
|
|
165
|
+
if (!id || assignments.length < 1)
|
|
166
|
+
return fail("set");
|
|
167
|
+
const patch = {};
|
|
168
|
+
for (const a of assignments) {
|
|
169
|
+
const at = a.indexOf("=");
|
|
170
|
+
const key = at > 0 ? a.slice(0, at) : "";
|
|
171
|
+
if (!SET_FIELDS.includes(key))
|
|
172
|
+
return fail("set");
|
|
173
|
+
patch[key] = a.slice(at + 1);
|
|
174
|
+
}
|
|
175
|
+
await store.update(id, patch);
|
|
176
|
+
out.write(`${id} updated\n`);
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
if (sub === "block") {
|
|
180
|
+
const [id, on] = rest;
|
|
181
|
+
if (!id || !on || rest.length > 2)
|
|
182
|
+
return fail("block");
|
|
183
|
+
await store.update(id, { block: on });
|
|
184
|
+
out.write(`${id} blocked on ${on}\n`);
|
|
185
|
+
return 0;
|
|
186
|
+
}
|
|
187
|
+
if (sub === "progress") {
|
|
188
|
+
const [id, ...words] = rest;
|
|
189
|
+
const text = words.join(" ").trim();
|
|
190
|
+
if (!id || !text)
|
|
191
|
+
return fail("progress");
|
|
192
|
+
await store.progress(id, text);
|
|
193
|
+
out.write(`${id} progress recorded${clipProgress(text).truncated ? " (clipped to 500 characters)" : ""}\n`);
|
|
194
|
+
return 0;
|
|
195
|
+
}
|
|
196
|
+
if (sub === "ask") {
|
|
197
|
+
const [id, ...args] = rest;
|
|
198
|
+
if (!id || !args.length)
|
|
199
|
+
return fail("ask");
|
|
200
|
+
if (args.length === 1 && args[0] === "--clear") {
|
|
201
|
+
await store.update(id, { ask: null });
|
|
202
|
+
out.write(`${id} question cleared\n`);
|
|
203
|
+
return 0;
|
|
204
|
+
}
|
|
205
|
+
const words = [];
|
|
206
|
+
const options = [];
|
|
207
|
+
for (let i = 0; i < args.length; i++) {
|
|
208
|
+
if (args[i] === "--option") {
|
|
209
|
+
if (args[i + 1] === undefined)
|
|
210
|
+
return fail("ask");
|
|
211
|
+
options.push(args[++i]);
|
|
212
|
+
}
|
|
213
|
+
else if (args[i].startsWith("--")) {
|
|
214
|
+
return fail("ask");
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
words.push(args[i]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
const text = words.join(" ").trim();
|
|
221
|
+
if (!text)
|
|
222
|
+
return fail("ask");
|
|
223
|
+
await store.update(id, { ask: { text, options, by: author(cfg) } });
|
|
224
|
+
out.write(`${id} waits on the operator\n`);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
if (sub === "own") {
|
|
228
|
+
const [id, address] = rest;
|
|
229
|
+
if (!id || !address || rest.length > 2)
|
|
230
|
+
return fail("own");
|
|
231
|
+
await store.update(id, { owner: address });
|
|
232
|
+
out.write(`${id} owned by ${address}\n`);
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
if (sub === "remove") {
|
|
236
|
+
const [id] = rest;
|
|
237
|
+
if (!id || rest.length > 1)
|
|
238
|
+
return fail("remove");
|
|
239
|
+
await openTasks(cfg.project, env).remove(id);
|
|
240
|
+
out.write(`${id} removed\n`);
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
if (sub === "render") {
|
|
244
|
+
if (rest.length)
|
|
245
|
+
return fail("render");
|
|
246
|
+
const file = join(projectRoot(cfg.project, env), "docs", "feature-requests.md");
|
|
247
|
+
const doc = { v: 1, tasks: openTasks(cfg.project, env).list() };
|
|
248
|
+
const existing = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
249
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
250
|
+
writeFileSync(file, renderFeatureRequests(doc, existing));
|
|
251
|
+
out.write(`rendered ${file}\n`);
|
|
252
|
+
return 0;
|
|
253
|
+
}
|
|
254
|
+
if (sub === "import") {
|
|
255
|
+
const [file] = rest;
|
|
256
|
+
if (!file || rest.length > 1)
|
|
257
|
+
return fail("import");
|
|
258
|
+
const text = readFileSync(file, "utf8");
|
|
259
|
+
// A .json file is a task store (the old .ai-collab/tasks.json included); anything else is the markdown table.
|
|
260
|
+
const { doc, defaulted } = file.endsWith(".json") ? { doc: validateTasks(JSON.parse(text)), defaulted: [] } : importReport(text, now);
|
|
261
|
+
const count = await openTasks(cfg.project, env).replaceAll(doc);
|
|
262
|
+
for (const title of defaulted)
|
|
263
|
+
out.write(`defaulted to done (no status word): ${title}\n`);
|
|
264
|
+
out.write(`imported ${count} tasks\n`);
|
|
265
|
+
return 0;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
err.write(`temmo: task ${sub}: ${error.message}\n`);
|
|
270
|
+
return 1;
|
|
271
|
+
}
|
|
272
|
+
err.write(`${Object.values(USAGE).join("\n")}\n`);
|
|
273
|
+
return 1;
|
|
274
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Task priority and list order, shared by the store, CLI, MCP, render and the board; no node imports, so the web bundle can use it.
|
|
2
|
+
export const TASK_PRIORITIES = ["P0", "P1", "P2", "P3"];
|
|
3
|
+
export const TASK_PRIORITY_DEFAULT = "P2";
|
|
4
|
+
// Within one priority: work in flight first (including builds waiting for review), then queued (open and decided
|
|
5
|
+
// share a rank), then finished.
|
|
6
|
+
export const SORT_STATUSES = ["building", "review", "blocked", "open", "decided", "done"];
|
|
7
|
+
// oxlint-disable-next-line quality/no-known-value-widening -- looked up by a runtime status string
|
|
8
|
+
const STATUS_RANK = { building: 0, review: 0, blocked: 1, open: 2, decided: 2, done: 3 };
|
|
9
|
+
function rank(list, value) {
|
|
10
|
+
const at = list.indexOf(value);
|
|
11
|
+
return at < 0 ? list.length : at;
|
|
12
|
+
}
|
|
13
|
+
/** The task's priority: its own when valid, else P2 (a missing priority means P2). */
|
|
14
|
+
export function priorityOf(task) {
|
|
15
|
+
return TASK_PRIORITIES.includes(task?.priority) ? task?.priority : TASK_PRIORITY_DEFAULT;
|
|
16
|
+
}
|
|
17
|
+
/** Priority alone, P0 first; 0 when the two tasks share one. */
|
|
18
|
+
export function comparePriority(a, b) {
|
|
19
|
+
return rank(TASK_PRIORITIES, priorityOf(a)) - rank(TASK_PRIORITIES, priorityOf(b));
|
|
20
|
+
}
|
|
21
|
+
/** Priority, then status (building/review, blocked, open/decided, done), then most recently updated first. */
|
|
22
|
+
export function compareTasks(a, b) {
|
|
23
|
+
const byPriority = comparePriority(a, b);
|
|
24
|
+
if (byPriority)
|
|
25
|
+
return byPriority;
|
|
26
|
+
const byStatus = (STATUS_RANK[a.status ?? ""] ?? SORT_STATUSES.length) - (STATUS_RANK[b.status ?? ""] ?? SORT_STATUSES.length);
|
|
27
|
+
if (byStatus)
|
|
28
|
+
return byStatus;
|
|
29
|
+
return (b.updated ?? 0) - (a.updated ?? 0);
|
|
30
|
+
}
|
|
31
|
+
/** A sorted copy of the tasks; the input is left alone. */
|
|
32
|
+
export function sortTasks(tasks) {
|
|
33
|
+
return [...tasks].sort(compareTasks);
|
|
34
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { isValidName, loadProjects } from "./config.js";
|
|
2
|
+
import { schemaProblem } from "./code-run.js";
|
|
3
|
+
import { listSessions } from "./sessions/registry.js";
|
|
4
|
+
import { TASK_PRIORITIES, ownedBuilding, openTasks, recordOwnerProgress } from "./tasks.js";
|
|
5
|
+
import { BODY, IDENTITY } from "./surfaces/schema.js";
|
|
6
|
+
import { TASK_LIST_SCHEMA, TASK_UPDATE_SCHEMA, listTasks, taskView, updateTask } from "./surfaces/task-view.js";
|
|
7
|
+
import { passJs } from "./surfaces/types.js";
|
|
8
|
+
const BODY_MAX_BYTES = 256 * 1024;
|
|
9
|
+
const FETCH_TIMEOUT_MS = 30_000;
|
|
10
|
+
const PEER = /^[a-z0-9-]{1,24}$/;
|
|
11
|
+
const ROUTE = /^\/tasks\/(list|update|add|progress)$/;
|
|
12
|
+
const TASK_ADD_SCHEMA = {
|
|
13
|
+
type: "object", required: ["title", "session"], additionalProperties: false,
|
|
14
|
+
properties: { title: { type: "string", minLength: 1, maxLength: 300 }, priority: { type: "string", enum: TASK_PRIORITIES }, session: IDENTITY },
|
|
15
|
+
};
|
|
16
|
+
const TASK_PROGRESS_SCHEMA = {
|
|
17
|
+
type: "object", required: ["text", "session"], additionalProperties: false,
|
|
18
|
+
properties: { text: BODY, session: IDENTITY },
|
|
19
|
+
};
|
|
20
|
+
const SCHEMAS = { list: TASK_LIST_SCHEMA, update: TASK_UPDATE_SCHEMA, add: TASK_ADD_SCHEMA, progress: TASK_PROGRESS_SCHEMA };
|
|
21
|
+
const refuse = (status, message) => Object.assign(new Error(message), { status });
|
|
22
|
+
async function readJson(req) {
|
|
23
|
+
const chunks = [];
|
|
24
|
+
let total = 0;
|
|
25
|
+
for await (const chunk of req) {
|
|
26
|
+
total += chunk.length;
|
|
27
|
+
if (total > BODY_MAX_BYTES)
|
|
28
|
+
throw refuse(413, "body too large");
|
|
29
|
+
chunks.push(chunk);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
33
|
+
if (value && typeof value === "object" && !Array.isArray(value))
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
catch { /* falls through */ }
|
|
37
|
+
throw refuse(400, "bad json");
|
|
38
|
+
}
|
|
39
|
+
/** The caller's config: a project this host serves and a session its registry lists under that peer. */
|
|
40
|
+
function callerOf(host, body, args) {
|
|
41
|
+
const project = typeof body.project === "string" ? body.project : "";
|
|
42
|
+
const peer = typeof body.peer === "string" ? body.peer : "";
|
|
43
|
+
if (!isValidName(project))
|
|
44
|
+
throw refuse(400, "invalid project");
|
|
45
|
+
if (!PEER.test(peer))
|
|
46
|
+
throw refuse(400, "invalid peer");
|
|
47
|
+
const cfg = loadProjects(host.env, { host: "operator" }).find((c) => c.project === project);
|
|
48
|
+
if (!cfg)
|
|
49
|
+
throw refuse(404, `no project ${project} on this host`);
|
|
50
|
+
const address = `${peer}#${args.session}`;
|
|
51
|
+
if (!listSessions(cfg).some((s) => s.id === address))
|
|
52
|
+
throw refuse(403, `session ${address} is not registered in project ${project}`);
|
|
53
|
+
return { ...cfg, project, peer, session: String(args.session) };
|
|
54
|
+
}
|
|
55
|
+
async function run(op, caller, args, env) {
|
|
56
|
+
switch (op) {
|
|
57
|
+
case "list": return listTasks(openTasks(caller.project, env).list(), passJs(args));
|
|
58
|
+
case "update": return updateTask(caller, passJs(args), env);
|
|
59
|
+
case "add": {
|
|
60
|
+
const task = await openTasks(caller.project, env).add({ title: args.title, ...(args.priority ? { priority: String(args.priority) } : {}) });
|
|
61
|
+
return { task: taskView(task) };
|
|
62
|
+
}
|
|
63
|
+
case "progress": {
|
|
64
|
+
const owned = ownedBuilding(caller, env).length;
|
|
65
|
+
return { owned, recorded: owned ? await recordOwnerProgress(caller, String(args.text), env) : 0 };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function reply(res, status, value) {
|
|
70
|
+
res.writeHead(status, { "content-type": "application/json" });
|
|
71
|
+
res.end(JSON.stringify(value));
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
/** Answers POST /tasks/<op>; false when the path is not a task route. A bus without a host answers 404. */
|
|
75
|
+
export async function taskRoute(host, req, res, url) {
|
|
76
|
+
const match = ROUTE.exec(url.pathname);
|
|
77
|
+
if (!match && url.pathname !== "/tasks" && !url.pathname.startsWith("/tasks/"))
|
|
78
|
+
return false;
|
|
79
|
+
if (!match)
|
|
80
|
+
return reply(res, 404, { error: "unknown task route" });
|
|
81
|
+
if (req.method !== "POST")
|
|
82
|
+
return reply(res, 405, { error: "method not allowed" });
|
|
83
|
+
if (!host)
|
|
84
|
+
return reply(res, 404, { error: "this bus serves no task store" });
|
|
85
|
+
const op = match[1];
|
|
86
|
+
let caller;
|
|
87
|
+
let args;
|
|
88
|
+
try {
|
|
89
|
+
const body = await readJson(req);
|
|
90
|
+
args = body.args && typeof body.args === "object" && !Array.isArray(body.args) ? body.args : {};
|
|
91
|
+
const problem = schemaProblem(SCHEMAS[op], args);
|
|
92
|
+
if (problem)
|
|
93
|
+
throw refuse(400, problem);
|
|
94
|
+
caller = callerOf(host, body, args);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return reply(res, error.status || 500, { error: error.status ? error.message : "task request failed" });
|
|
98
|
+
}
|
|
99
|
+
// The store refuses with a message the caller acts on (unknown task, cycle, bad transition), as on the host.
|
|
100
|
+
try {
|
|
101
|
+
return reply(res, 200, await run(op, caller, args, host.env));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return reply(res, 422, { error: error.message });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** One task call through the bus, as the session cfg; throws the bus's refusal text. */
|
|
108
|
+
export async function busTaskCall(cfg, op, args) {
|
|
109
|
+
let res;
|
|
110
|
+
try {
|
|
111
|
+
res = await fetch(`${cfg.url}/tasks/${op}`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: { "content-type": "application/json", ...(cfg.token ? { authorization: `Bearer ${cfg.token}` } : {}) },
|
|
114
|
+
body: JSON.stringify({ project: cfg.project, peer: cfg.peer, args }),
|
|
115
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error(`task store unreachable: the bus at ${cfg.url} did not answer (${error.message})`, { cause: error });
|
|
120
|
+
}
|
|
121
|
+
const body = await res.json().catch(() => null);
|
|
122
|
+
if (!res.ok)
|
|
123
|
+
throw new Error(typeof body?.error === "string" ? body.error : `bus /tasks/${op} answered ${res.status}`);
|
|
124
|
+
return body;
|
|
125
|
+
}
|