@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
package/lib/questions.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { parseWireEnvelope } from "./agui.js";
|
|
4
|
+
import { fitApprovalEnvelope } from "./approval-card.js";
|
|
5
|
+
import { MESSAGE_MAX_BYTES, SESSION_LABEL, broadcastTopic, isValidName } from "./config.js";
|
|
6
|
+
import { assertWaitSeconds, choiceLabels, matchReply, waitForOperatorReply } from "./operator.js";
|
|
7
|
+
import { pollCached, publish } from "./messaging.js";
|
|
8
|
+
import { VERIFIED_SOURCE, VERIFIED_TAG } from "./format.js";
|
|
9
|
+
import { deepLink } from "./deep-link.js";
|
|
10
|
+
import { alertPriority, readAlertLevel } from "./alerts.js";
|
|
11
|
+
import { sendReceipts } from "./receipts.js";
|
|
12
|
+
import { statePath, withLock, writeState } from "./state.js";
|
|
13
|
+
export { choiceLabels, parseChoice, parsePhoneReply, skippedQuestionId } from "./operator.js";
|
|
14
|
+
const QUESTION_ID = /^[a-f0-9]{12}$/;
|
|
15
|
+
const MAX_QUESTION_BYTES = 2000;
|
|
16
|
+
const OPEN_MAX = 20;
|
|
17
|
+
const CHOICE_MIN = 2;
|
|
18
|
+
const CHOICE_MAX = 6;
|
|
19
|
+
const CHOICE_QUESTION_MAX = 500;
|
|
20
|
+
const LABEL_MAX = 100;
|
|
21
|
+
const DESCRIPTION_MAX = 300;
|
|
22
|
+
// An answer's source: the bus operator token proves the operator sent it; without it any bus client could have.
|
|
23
|
+
const UNVERIFIED_SOURCE = "unverified channel broadcast";
|
|
24
|
+
const QUESTION_TEXT = /^Question from ([^\n]+)\n\n([\s\S]+)\n\nReply in this topic: reply ([a-f0-9]{12}) YOUR ANSWER$/;
|
|
25
|
+
/** An agent's question and its human-readable reply instructions. */
|
|
26
|
+
export function parseQuestionText(raw) {
|
|
27
|
+
const match = typeof raw === "string" && QUESTION_TEXT.exec(raw);
|
|
28
|
+
if (match)
|
|
29
|
+
return { sender: match[1], body: match[2], id: match[3], text: raw };
|
|
30
|
+
const record = parseWireEnvelope(raw);
|
|
31
|
+
if (record?.kind !== "question" || !isValidName(record.from))
|
|
32
|
+
return null;
|
|
33
|
+
const { from, session, id, body } = record;
|
|
34
|
+
if (typeof id !== "string" || !QUESTION_ID.test(id) || typeof body !== "string" || !body.trim())
|
|
35
|
+
return null;
|
|
36
|
+
if (session !== undefined && (typeof session !== "string" || !SESSION_LABEL.test(session)))
|
|
37
|
+
return null;
|
|
38
|
+
const sender = session ? `${from}#${session}` : from;
|
|
39
|
+
return { sender, body, id, text: `Question from ${sender}\n\n${body}\n\nReply in this topic: reply ${id} YOUR ANSWER` };
|
|
40
|
+
}
|
|
41
|
+
// The ask_question options as choices, or null without options; throws on a shape the phone cannot show.
|
|
42
|
+
function validateChoices(question, options, multiSelect) {
|
|
43
|
+
if (options === undefined) {
|
|
44
|
+
if (multiSelect)
|
|
45
|
+
throw new Error("multi_select needs options");
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
if (!Array.isArray(options) || options.length < CHOICE_MIN || options.length > CHOICE_MAX) {
|
|
49
|
+
throw new Error(`Options must be an array of ${CHOICE_MIN} to ${CHOICE_MAX} choices`);
|
|
50
|
+
}
|
|
51
|
+
if (Array.from(question.trim()).length > CHOICE_QUESTION_MAX)
|
|
52
|
+
throw new Error(`A question with options takes ${CHOICE_QUESTION_MAX} characters at most`);
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
return options.map((o) => {
|
|
55
|
+
const label = typeof o?.label === "string" ? o.label.trim() : "";
|
|
56
|
+
if (!label || label.length > LABEL_MAX)
|
|
57
|
+
throw new Error(`Each option needs a label of 1 to ${LABEL_MAX} characters`);
|
|
58
|
+
if (multiSelect && label.includes(","))
|
|
59
|
+
throw new Error("Option labels cannot contain commas when multi_select is true");
|
|
60
|
+
if (seen.has(label.toLowerCase()))
|
|
61
|
+
throw new Error(`Option labels must be unique: ${label}`);
|
|
62
|
+
seen.add(label.toLowerCase());
|
|
63
|
+
if (o.description !== undefined && (typeof o.description !== "string" || o.description.length > DESCRIPTION_MAX)) {
|
|
64
|
+
throw new Error(`An option description takes ${DESCRIPTION_MAX} characters at most`);
|
|
65
|
+
}
|
|
66
|
+
return o.description ? { label, description: o.description.trim() } : { label };
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function questionsFile(cfg) {
|
|
70
|
+
return statePath(cfg).replace(/\.json$/, ".questions.json");
|
|
71
|
+
}
|
|
72
|
+
/** Open questions this session asked: [{id, important, askedAt, questions?}], oldest first; questions are set for choice cards. */
|
|
73
|
+
export function openQuestions(cfg) {
|
|
74
|
+
if (!cfg.session)
|
|
75
|
+
return [];
|
|
76
|
+
try {
|
|
77
|
+
const list = JSON.parse(readFileSync(questionsFile(cfg), "utf8")).open;
|
|
78
|
+
return Array.isArray(list)
|
|
79
|
+
? list.filter((q) => QUESTION_ID.test(q?.id) && Number.isFinite(q.askedAt))
|
|
80
|
+
.map(({ id, important, askedAt, questions }) => ({ id, important: important === true, askedAt, ...(Array.isArray(questions) ? { questions } : {}) }))
|
|
81
|
+
: [];
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function updateQuestions(cfg, change) {
|
|
88
|
+
if (!cfg.session)
|
|
89
|
+
return;
|
|
90
|
+
const file = questionsFile(cfg);
|
|
91
|
+
const locked = await withLock(file, async () => writeState(file, { open: change(openQuestions(cfg)).slice(-OPEN_MAX) }));
|
|
92
|
+
if (!locked.locked)
|
|
93
|
+
throw new Error(`${file} is busy; retry`);
|
|
94
|
+
}
|
|
95
|
+
function waitFile(cfg) {
|
|
96
|
+
return statePath(cfg).replace(/\.json$/, ".wait.json");
|
|
97
|
+
}
|
|
98
|
+
/** Ask the next Stop hook to wait for the operator (AFK mode ON); the Stop clears it when it ends or delivers. */
|
|
99
|
+
export async function requestWait(cfg, now = Date.now(), questionId = null) {
|
|
100
|
+
if (!cfg.session)
|
|
101
|
+
return;
|
|
102
|
+
const file = waitFile(cfg);
|
|
103
|
+
const locked = await withLock(file, async () => writeState(file, { requestedAt: now, questionId }));
|
|
104
|
+
if (!locked.locked)
|
|
105
|
+
throw new Error(`${file} is busy; retry`);
|
|
106
|
+
}
|
|
107
|
+
/** Time of this session's pending wait request, or 0. */
|
|
108
|
+
export function waitRequestedAt(cfg) {
|
|
109
|
+
return Number(readWait(cfg)?.requestedAt) || 0;
|
|
110
|
+
}
|
|
111
|
+
function readWait(cfg) {
|
|
112
|
+
try {
|
|
113
|
+
return JSON.parse(readFileSync(waitFile(cfg), "utf8"));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export async function clearWait(cfg, questionId) {
|
|
120
|
+
if (!cfg.session || !waitRequestedAt(cfg))
|
|
121
|
+
return;
|
|
122
|
+
const file = waitFile(cfg);
|
|
123
|
+
await withLock(file, async () => {
|
|
124
|
+
const pending = readWait(cfg);
|
|
125
|
+
// Older wait records had no question ID.
|
|
126
|
+
if (questionId === undefined || pending?.questionId === undefined || pending.questionId === questionId) {
|
|
127
|
+
rmSync(file, { force: true });
|
|
128
|
+
}
|
|
129
|
+
}).catch(() => { });
|
|
130
|
+
}
|
|
131
|
+
export async function closeQuestion(cfg, id) {
|
|
132
|
+
await updateQuestions(cfg, (open) => open.filter((q) => q.id !== id));
|
|
133
|
+
await clearWait(cfg, id);
|
|
134
|
+
}
|
|
135
|
+
// A reply as the text the agent reads: a choice as its labels joined "; ", a plain answer as typed.
|
|
136
|
+
function answerText(match) {
|
|
137
|
+
return match.labels ? Object.values(match.labels).map((parts) => parts.join(", ")).join("; ") : match.answer;
|
|
138
|
+
}
|
|
139
|
+
/** Replies and skips on the broadcast topic for the given question IDs, since the oldest one was asked. */
|
|
140
|
+
export async function findAnswers(cfg, questions, { poll = pollCached } = {}) {
|
|
141
|
+
if (!questions.length)
|
|
142
|
+
return [];
|
|
143
|
+
const since = String(Math.floor(Math.min(...questions.map((q) => q.askedAt)) / 1000) - 60);
|
|
144
|
+
const found = new Map();
|
|
145
|
+
for (const ev of await poll(cfg, broadcastTopic(cfg.project), since)) {
|
|
146
|
+
for (const q of questions) {
|
|
147
|
+
if (found.has(q.id))
|
|
148
|
+
continue;
|
|
149
|
+
const match = matchReply(ev, { id: q.id, questions: q.questions });
|
|
150
|
+
if (!match)
|
|
151
|
+
continue;
|
|
152
|
+
if (match.skipped) {
|
|
153
|
+
found.set(q.id, { id: q.id, skipped: true });
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const answer = answerText(match);
|
|
157
|
+
if (answer)
|
|
158
|
+
found.set(q.id, { id: q.id, answer, messageId: ev.id, ...(match.verified ? { verified: true } : {}) });
|
|
159
|
+
}
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return [...found.values()];
|
|
164
|
+
}
|
|
165
|
+
// One retry, then the error reaches the caller: a published question nobody recorded is never answered.
|
|
166
|
+
async function recordOrThrow(what, op) {
|
|
167
|
+
try {
|
|
168
|
+
await op();
|
|
169
|
+
}
|
|
170
|
+
catch {
|
|
171
|
+
try {
|
|
172
|
+
await op();
|
|
173
|
+
}
|
|
174
|
+
catch (retryError) {
|
|
175
|
+
throw new Error(`The question was published, but recording ${what} failed: ${retryError.message}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Asks the operator's phone. Options make a choice card (the approval envelope of lib/approvals.ts); the answer is the chosen labels.
|
|
181
|
+
* Without options the phone gets a text question with a reply field.
|
|
182
|
+
*/
|
|
183
|
+
export async function askQuestion(cfg, question, options = {}) {
|
|
184
|
+
assertWaitSeconds(options.seconds ?? 25);
|
|
185
|
+
if (typeof question !== "string" || !question.trim() || Buffer.byteLength(question) > MAX_QUESTION_BYTES) {
|
|
186
|
+
throw new Error("Question must contain 1–2000 UTF-8 bytes");
|
|
187
|
+
}
|
|
188
|
+
const id = randomBytes(6).toString("hex");
|
|
189
|
+
const sender = cfg.session ? `${cfg.peer}#${cfg.session}` : cfg.peer;
|
|
190
|
+
const topic = broadcastTopic(cfg.project);
|
|
191
|
+
const important = options.important === true;
|
|
192
|
+
const multiSelect = options.multiSelect === true;
|
|
193
|
+
const choices = validateChoices(question, options.choices, multiSelect);
|
|
194
|
+
const title = `${important ? "Important question" : "Question"} from ${sender}`;
|
|
195
|
+
let questions, message;
|
|
196
|
+
if (choices) {
|
|
197
|
+
// Same envelope as a permission choice, so the UI renders the same card; expiresAt 0 keeps it open until answered.
|
|
198
|
+
questions = [{ question: question.trim(), header: "", multiSelect, options: choices }];
|
|
199
|
+
message = fitApprovalEnvelope("approval", {
|
|
200
|
+
from: cfg.peer, ...(cfg.session ? { session: cfg.session } : {}), harness: options.harness || "other",
|
|
201
|
+
id, tool: "ask_question", summary: question.trim(), expiresAt: 0, ts: new Date().toISOString(),
|
|
202
|
+
}, questions, cfg.wire);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
const body = (important ? "IMPORTANT, the agent waits for this answer: " : "") + question.trim();
|
|
206
|
+
message = `Question from ${sender}\n\n${body}\n\nReply in this topic: reply ${id} YOUR ANSWER`;
|
|
207
|
+
}
|
|
208
|
+
if (!message || Buffer.byteLength(message) > MESSAGE_MAX_BYTES)
|
|
209
|
+
throw new Error(`The question and its options exceed ${MESSAGE_MAX_BYTES} bytes`);
|
|
210
|
+
await publish(cfg, topic, message, { title, click: deepLink({ project: cfg.project }), priority: alertPriority(readAlertLevel(), "question") });
|
|
211
|
+
const askedAt = options.now ?? Date.now();
|
|
212
|
+
// The wait request and the open list are what make the Stop hook hold the session; a silent miss strands the question.
|
|
213
|
+
await recordOrThrow("the wait request", () => requestWait(cfg, askedAt, id));
|
|
214
|
+
await recordOrThrow("the open question", () => updateQuestions(cfg, (open) => [...open, { id, important, askedAt, ...(questions ? { questions } : {}) }]));
|
|
215
|
+
try {
|
|
216
|
+
return await waitForAnswer(cfg, id, { ...options, questions });
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (options.signal?.aborted)
|
|
220
|
+
throw error;
|
|
221
|
+
return { id, status: "pending", note: "The question was published, but reading answers failed. Call wait_for_answer to retry." };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
export async function waitForAnswer(cfg, id, { seconds = 25, signal, intervalMs = 4000, questions: known } = {}) {
|
|
225
|
+
if (typeof id !== "string" || !QUESTION_ID.test(id))
|
|
226
|
+
throw new Error("Invalid question ID");
|
|
227
|
+
assertWaitSeconds(seconds);
|
|
228
|
+
const questions = known ?? openQuestions(cfg).find((q) => q.id === id)?.questions;
|
|
229
|
+
const outcome = await waitForOperatorReply({
|
|
230
|
+
cfg, topic: broadcastTopic(cfg.project), id, deadline: Date.now() + seconds * 1000, signal, mode: "poll",
|
|
231
|
+
questions, intervalMs, read: (reply) => reply,
|
|
232
|
+
});
|
|
233
|
+
if (outcome.status === "skipped") {
|
|
234
|
+
await closeQuestion(cfg, id).catch(() => { });
|
|
235
|
+
return { id, status: "skipped" };
|
|
236
|
+
}
|
|
237
|
+
if (outcome.status !== "reply")
|
|
238
|
+
return { id, status: "pending" };
|
|
239
|
+
const reply = outcome.value;
|
|
240
|
+
await closeQuestion(cfg, id).catch(() => { });
|
|
241
|
+
sendReceipts(cfg, [outcome.messageId]);
|
|
242
|
+
if (questions) {
|
|
243
|
+
const selected = Object.values(reply.labels)[0];
|
|
244
|
+
return { id, status: "answered", answer: selected.join(", "), selected, ...sourceOf(reply) };
|
|
245
|
+
}
|
|
246
|
+
return { id, answer: reply.answer, status: "answered", ...sourceOf(reply) };
|
|
247
|
+
}
|
|
248
|
+
function sourceOf(reply) {
|
|
249
|
+
return reply.verified ? { source: `${VERIFIED_TAG} ${VERIFIED_SOURCE}`, verified: true } : { source: UNVERIFIED_SOURCE };
|
|
250
|
+
}
|
package/lib/receipts.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { alertPriority, readAlertLevel } from "./alerts.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read receipts: when a hook, MCP tool or CLI command hands messages to an agent, it publishes
|
|
4
|
+
* The ai-collab.receipt event carries the reader and read message IDs to ai-collab-<project>--receipts.
|
|
5
|
+
* Best effort: publishes run in the background, never throw, and are capped at RECEIPT_TIMEOUT_MS.
|
|
6
|
+
*/
|
|
7
|
+
import { MESSAGE_MAX_BYTES, SESSION_LABEL, isValidName, receiptsTopic } from "./config.js";
|
|
8
|
+
import { publish } from "./messaging.js";
|
|
9
|
+
import { encodeEnvelope, parseWireEnvelope } from "./agui.js";
|
|
10
|
+
export const RECEIPT_TIMEOUT_MS = 1500;
|
|
11
|
+
const MESSAGE_ID = /^[a-zA-Z0-9-]{1,64}$/;
|
|
12
|
+
const READS_MAX = 5000;
|
|
13
|
+
const pending = new Set();
|
|
14
|
+
function receipt(cfg, ids, ts) {
|
|
15
|
+
return encodeEnvelope("receipt", { from: cfg.peer, ...(cfg.session ? { session: cfg.session } : {}), ids, state: "read", ts }, cfg.wire);
|
|
16
|
+
}
|
|
17
|
+
// Receipt envelopes for ids, split so each stays within the wire message cap.
|
|
18
|
+
export function receiptMessages(cfg, ids, ts = new Date().toISOString()) {
|
|
19
|
+
const batches = [];
|
|
20
|
+
for (const id of ids) {
|
|
21
|
+
const last = batches.at(-1);
|
|
22
|
+
if (last && Buffer.byteLength(receipt(cfg, [...last, id], ts)) <= MESSAGE_MAX_BYTES)
|
|
23
|
+
last.push(id);
|
|
24
|
+
else
|
|
25
|
+
batches.push([id]);
|
|
26
|
+
}
|
|
27
|
+
return batches.map((batch) => receipt(cfg, batch, ts));
|
|
28
|
+
}
|
|
29
|
+
/** Starts a background read-receipt publish for delivered message ids; await settleReceipts() before exiting. */
|
|
30
|
+
export function sendReceipts(cfg, ids) {
|
|
31
|
+
const valid = [...new Set(ids)].filter((id) => typeof id === "string" && MESSAGE_ID.test(id));
|
|
32
|
+
if (!cfg?.enabled || !valid.length)
|
|
33
|
+
return;
|
|
34
|
+
const signal = AbortSignal.timeout(RECEIPT_TIMEOUT_MS);
|
|
35
|
+
const task = Promise.all(receiptMessages(cfg, valid).map((message) => publish(cfg, receiptsTopic(cfg.project), message, { title: "temmo receipt", signal, priority: alertPriority(readAlertLevel(), "other") }))).catch(() => { });
|
|
36
|
+
pending.add(task);
|
|
37
|
+
void task.finally(() => pending.delete(task));
|
|
38
|
+
}
|
|
39
|
+
/** Resolves when every receipt publish started by this process has finished or timed out. */
|
|
40
|
+
export const settleReceipts = () => Promise.all(pending);
|
|
41
|
+
/** Adds each receipt's reader (peer#session) to reads: message id → Set of readers. Oldest ids drop past READS_MAX. */
|
|
42
|
+
export function readReceipts(events, reads = new Map(), limit = READS_MAX) {
|
|
43
|
+
for (const ev of events) {
|
|
44
|
+
const m = parseWireEnvelope(ev.message);
|
|
45
|
+
if (m?.kind !== "receipt" || m.state !== "read" || !isValidName(m.from) || !Array.isArray(m.ids))
|
|
46
|
+
continue;
|
|
47
|
+
const reader = typeof m.session === "string" && SESSION_LABEL.test(m.session) ? `${m.from}#${m.session}` : m.from;
|
|
48
|
+
for (const id of m.ids) {
|
|
49
|
+
if (typeof id !== "string" || !MESSAGE_ID.test(id))
|
|
50
|
+
continue;
|
|
51
|
+
let set = reads.get(id);
|
|
52
|
+
if (!set)
|
|
53
|
+
reads.set(id, set = new Set());
|
|
54
|
+
set.add(reader);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const id of reads.keys()) {
|
|
58
|
+
if (reads.size <= limit)
|
|
59
|
+
break;
|
|
60
|
+
reads.delete(id);
|
|
61
|
+
}
|
|
62
|
+
return reads;
|
|
63
|
+
}
|