@temmo/cli 0.0.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +112 -1
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
package/lib/agui.js
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
// AG-UI 1.0 wire discriminators used by the dependency-free hook and MCP codec.
|
|
2
|
+
const EventType = Object.freeze({
|
|
3
|
+
CUSTOM: "CUSTOM",
|
|
4
|
+
RUN_STARTED: "RUN_STARTED",
|
|
5
|
+
RUN_FINISHED: "RUN_FINISHED",
|
|
6
|
+
RUN_ERROR: "RUN_ERROR",
|
|
7
|
+
TEXT_MESSAGE_CHUNK: "TEXT_MESSAGE_CHUNK",
|
|
8
|
+
TOOL_CALL_CHUNK: "TOOL_CALL_CHUNK",
|
|
9
|
+
TOOL_CALL_RESULT: "TOOL_CALL_RESULT",
|
|
10
|
+
STEP_STARTED: "STEP_STARTED",
|
|
11
|
+
STEP_FINISHED: "STEP_FINISHED",
|
|
12
|
+
STATE_SNAPSHOT: "STATE_SNAPSHOT",
|
|
13
|
+
ACTIVITY_SNAPSHOT: "ACTIVITY_SNAPSHOT",
|
|
14
|
+
});
|
|
15
|
+
// Kept across the product rename: stored events and sessions started before it use these names.
|
|
16
|
+
const CUSTOM_PREFIX = "ai-collab.";
|
|
17
|
+
// parseWireEnvelope's memo: about 40 hub topics of 500 events each fit.
|
|
18
|
+
const PARSED_MAX = 25_000;
|
|
19
|
+
const parsed = new Map();
|
|
20
|
+
const ENVELOPE_KINDS = new Set(["activity", "msg", "receipt", "approval", "approval-view", "approval-end", "question", "mode", "status", "alert", "fetch-origin", "fetch-origin-end", "pr-request", "pr-request-end"]);
|
|
21
|
+
function object(value) {
|
|
22
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
23
|
+
}
|
|
24
|
+
function read(raw) {
|
|
25
|
+
if (typeof raw !== "string")
|
|
26
|
+
return raw;
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(raw);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function legacy(value) {
|
|
35
|
+
return object(value) && value.v === 1 && ENVELOPE_KINDS.has(value.kind);
|
|
36
|
+
}
|
|
37
|
+
const string = (value) => typeof value === "string";
|
|
38
|
+
const optionalString = (value) => value === undefined || string(value);
|
|
39
|
+
function problem(event) {
|
|
40
|
+
if (!object(event))
|
|
41
|
+
return "expected an event object";
|
|
42
|
+
if (event.timestamp !== undefined && !Number.isSafeInteger(event.timestamp))
|
|
43
|
+
return "invalid timestamp";
|
|
44
|
+
if (event.metadata !== undefined && !object(event.metadata))
|
|
45
|
+
return "invalid metadata";
|
|
46
|
+
if (!optionalString(event.subagentRunId))
|
|
47
|
+
return "invalid subagentRunId";
|
|
48
|
+
switch (event.type) {
|
|
49
|
+
case EventType.CUSTOM:
|
|
50
|
+
return string(event.name) && event.value !== undefined ? null : "name and value required";
|
|
51
|
+
case EventType.RUN_STARTED:
|
|
52
|
+
case EventType.RUN_FINISHED:
|
|
53
|
+
if (!string(event.threadId) || !string(event.runId))
|
|
54
|
+
return "threadId and runId required";
|
|
55
|
+
if (!optionalString(event.parentRunId))
|
|
56
|
+
return "invalid parentRunId";
|
|
57
|
+
if (event.input !== undefined &&
|
|
58
|
+
(!object(event.input) || !Array.isArray(event.input.messages) ||
|
|
59
|
+
!event.input.messages.every((message) => object(message) && string(message.id) && string(message.role))))
|
|
60
|
+
return "invalid input";
|
|
61
|
+
if (event.outcome !== undefined &&
|
|
62
|
+
(!object(event.outcome) || !["success", "cancelled", "interrupt"].includes(event.outcome.type) ||
|
|
63
|
+
(event.outcome.type === "interrupt" &&
|
|
64
|
+
(!Array.isArray(event.outcome.interrupts) || !event.outcome.interrupts.length))))
|
|
65
|
+
return "invalid outcome";
|
|
66
|
+
return null;
|
|
67
|
+
case EventType.RUN_ERROR:
|
|
68
|
+
return string(event.message) ? null : "message required";
|
|
69
|
+
case EventType.TEXT_MESSAGE_CHUNK:
|
|
70
|
+
return optionalString(event.messageId) && optionalString(event.delta) ? null : "invalid text chunk";
|
|
71
|
+
case EventType.TOOL_CALL_CHUNK:
|
|
72
|
+
return optionalString(event.toolCallId) && optionalString(event.toolCallName) && optionalString(event.delta) ? null : "invalid tool chunk";
|
|
73
|
+
case EventType.TOOL_CALL_RESULT:
|
|
74
|
+
return string(event.messageId) && string(event.toolCallId) && string(event.content)
|
|
75
|
+
? null : "messageId, toolCallId and content required";
|
|
76
|
+
case EventType.STEP_STARTED:
|
|
77
|
+
case EventType.STEP_FINISHED:
|
|
78
|
+
return string(event.stepName) ? null : "stepName required";
|
|
79
|
+
case EventType.STATE_SNAPSHOT:
|
|
80
|
+
return event.snapshot !== undefined ? null : "snapshot required";
|
|
81
|
+
case EventType.ACTIVITY_SNAPSHOT:
|
|
82
|
+
return string(event.messageId) && string(event.activityType) && object(event.content) ? null : "messageId, activityType and content required";
|
|
83
|
+
default:
|
|
84
|
+
return "unsupported event type";
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Build an event supported by the wire codec, throwing on a producer error. */
|
|
88
|
+
export function buildEvent(type, fields = {}) {
|
|
89
|
+
const event = { ...fields, type };
|
|
90
|
+
const issue = problem(event);
|
|
91
|
+
if (issue)
|
|
92
|
+
throw new TypeError(issue);
|
|
93
|
+
return event;
|
|
94
|
+
}
|
|
95
|
+
/** Read untrusted wire JSON or an event object. */
|
|
96
|
+
export function parseEvent(raw) {
|
|
97
|
+
const event = read(raw);
|
|
98
|
+
return problem(event) ? null : event;
|
|
99
|
+
}
|
|
100
|
+
function activityEvent(fields, timestamp, id, run) {
|
|
101
|
+
const { type, callId, input, output, tool, agent } = fields;
|
|
102
|
+
const subagent = typeof agent?.id === "string" && agent.id ? { subagentRunId: agent.id } : {};
|
|
103
|
+
const metadata = (...keys) => ({ aiCollab: Object.fromEntries(Object.entries(fields).filter(([key]) => !keys.includes(key))) });
|
|
104
|
+
const runId = run?.runId ?? run?.metadata?.aiCollab?.runId;
|
|
105
|
+
if (runId && fields.session) {
|
|
106
|
+
const threadId = `${fields.from}#${fields.session}`;
|
|
107
|
+
if (run.type === EventType.RUN_STARTED && type === "prompt" && typeof input === "string") {
|
|
108
|
+
const { parentRunId } = run;
|
|
109
|
+
const lineage = { threadId, runId, ...(parentRunId ? { parentRunId } : {}) };
|
|
110
|
+
const messageId = run.input?.messages.findLast((message) => message.role === "user")?.id ?? `${runId}:input`;
|
|
111
|
+
return buildEvent(EventType.RUN_STARTED, {
|
|
112
|
+
...lineage, timestamp, metadata: metadata("type", "input"),
|
|
113
|
+
input: { ...lineage, tools: [], context: [], messages: [{ id: messageId, role: "user", content: input }] },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (run.type === EventType.RUN_FINISHED && type === "stop") {
|
|
117
|
+
return buildEvent(EventType.RUN_FINISHED, {
|
|
118
|
+
threadId, runId, timestamp, outcome: run.outcome, metadata: metadata("type"),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (run.type === EventType.RUN_ERROR && type === "error" && typeof output === "string") {
|
|
122
|
+
const meta = metadata("type", "output");
|
|
123
|
+
return buildEvent(EventType.RUN_ERROR, {
|
|
124
|
+
timestamp, message: output, metadata: { aiCollab: { ...meta.aiCollab, runId } },
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (typeof callId === "string" && callId) {
|
|
129
|
+
if (type === "text" && typeof output === "string" && !tool) {
|
|
130
|
+
return buildEvent(EventType.TEXT_MESSAGE_CHUNK, {
|
|
131
|
+
timestamp, ...subagent, messageId: callId, role: "assistant", delta: output,
|
|
132
|
+
metadata: metadata("type", "callId", "output"),
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (type === "tool_call" && typeof tool === "string" && tool && (input === undefined || typeof input === "string")) {
|
|
136
|
+
return buildEvent(EventType.TOOL_CALL_CHUNK, {
|
|
137
|
+
timestamp, ...subagent, toolCallId: callId, toolCallName: tool, delta: input,
|
|
138
|
+
metadata: metadata("type", "callId", "tool", "input"),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if ((type === "tool_result" || type === "error") && typeof output === "string") {
|
|
142
|
+
return buildEvent(EventType.TOOL_CALL_RESULT, {
|
|
143
|
+
timestamp, ...subagent, messageId: id ?? globalThis.crypto.randomUUID(), toolCallId: callId, role: "tool", content: output,
|
|
144
|
+
metadata: metadata("callId", "output"),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (type === "model") {
|
|
149
|
+
return buildEvent(EventType.STEP_FINISHED, { timestamp, ...subagent, stepName: "model", metadata: metadata("type") });
|
|
150
|
+
}
|
|
151
|
+
if (type === "compact") {
|
|
152
|
+
const phase = fields.compaction?.phase;
|
|
153
|
+
const stepType = phase === "finished" || phase === "failed" ? EventType.STEP_FINISHED : EventType.STEP_STARTED;
|
|
154
|
+
return buildEvent(stepType, { timestamp, ...subagent, stepName: "compact", metadata: metadata("type") });
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
/** Convert a v1 envelope into one AG-UI event. The bus event ID can identify a legacy tool-result message. */
|
|
159
|
+
export function envelopeToEvent(raw, { id, run } = {}) {
|
|
160
|
+
const value = read(raw);
|
|
161
|
+
if (!legacy(value))
|
|
162
|
+
return null;
|
|
163
|
+
const { v, kind, ...fields } = value;
|
|
164
|
+
const time = typeof fields.ts === "string" ? Date.parse(fields.ts) : fields.ts;
|
|
165
|
+
const timestamp = Number.isSafeInteger(time) ? time : undefined;
|
|
166
|
+
if (kind === "activity") {
|
|
167
|
+
const event = activityEvent(fields, timestamp, id, run);
|
|
168
|
+
if (event)
|
|
169
|
+
return event;
|
|
170
|
+
}
|
|
171
|
+
return buildEvent(EventType.CUSTOM, { name: CUSTOM_PREFIX + kind, value: fields, timestamp });
|
|
172
|
+
}
|
|
173
|
+
/** Encode a Temmo control or messaging event for the bus. */
|
|
174
|
+
export function encodeEnvelope(kind, fields, wire) {
|
|
175
|
+
const envelope = { v: 1, kind, ...fields };
|
|
176
|
+
if (wire !== "agui")
|
|
177
|
+
return JSON.stringify(envelope);
|
|
178
|
+
const event = envelopeToEvent(envelope);
|
|
179
|
+
if (!event)
|
|
180
|
+
throw new Error("unknown Temmo event kind");
|
|
181
|
+
return JSON.stringify(event);
|
|
182
|
+
}
|
|
183
|
+
function activityFields(event) {
|
|
184
|
+
switch (event.type) {
|
|
185
|
+
case EventType.RUN_STARTED: {
|
|
186
|
+
const prompt = event.input?.messages.findLast((message) => message.role === "user")?.content;
|
|
187
|
+
return typeof prompt === "string" ? { type: "prompt", input: prompt } : null;
|
|
188
|
+
}
|
|
189
|
+
case EventType.RUN_FINISHED:
|
|
190
|
+
return { type: "stop" };
|
|
191
|
+
case EventType.RUN_ERROR:
|
|
192
|
+
return { type: "error", output: event.message };
|
|
193
|
+
case EventType.TEXT_MESSAGE_CHUNK:
|
|
194
|
+
return typeof event.messageId === "string" && typeof event.delta === "string"
|
|
195
|
+
? { type: "text", callId: event.messageId, output: event.delta } : null;
|
|
196
|
+
case EventType.TOOL_CALL_CHUNK:
|
|
197
|
+
return typeof event.toolCallId === "string" && typeof event.toolCallName === "string"
|
|
198
|
+
? { type: "tool_call", callId: event.toolCallId, tool: event.toolCallName,
|
|
199
|
+
...(event.delta === undefined ? {} : { input: event.delta }) }
|
|
200
|
+
: null;
|
|
201
|
+
case EventType.TOOL_CALL_RESULT:
|
|
202
|
+
return typeof event.content === "string"
|
|
203
|
+
? { type: event.metadata?.aiCollab?.type === "error" ? "error" : "tool_result",
|
|
204
|
+
callId: event.toolCallId, output: event.content }
|
|
205
|
+
: null;
|
|
206
|
+
case EventType.STEP_STARTED:
|
|
207
|
+
case EventType.STEP_FINISHED:
|
|
208
|
+
if (event.stepName === "model")
|
|
209
|
+
return { type: "model" };
|
|
210
|
+
return event.stepName === "compact" ? { type: "compact" } : null;
|
|
211
|
+
default:
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Project a Temmo event into the v1 envelope consumed by existing readers. */
|
|
216
|
+
export function eventToEnvelope(raw) {
|
|
217
|
+
const event = parseEvent(raw);
|
|
218
|
+
return event ? projectEvent(event) : null;
|
|
219
|
+
}
|
|
220
|
+
/** Project an already validated event. */
|
|
221
|
+
export function projectEvent(event) {
|
|
222
|
+
if (event.type === EventType.CUSTOM) {
|
|
223
|
+
if (!event.name.startsWith(CUSTOM_PREFIX) || !object(event.value))
|
|
224
|
+
return null;
|
|
225
|
+
const kind = event.name.slice(CUSTOM_PREFIX.length);
|
|
226
|
+
return ENVELOPE_KINDS.has(kind) ? { ...event.value, v: 1, kind } : null;
|
|
227
|
+
}
|
|
228
|
+
const context = event.metadata?.aiCollab;
|
|
229
|
+
if (!object(context) || typeof context.from !== "string")
|
|
230
|
+
return null;
|
|
231
|
+
const { runId, ...metadata } = context;
|
|
232
|
+
const fields = activityFields(event);
|
|
233
|
+
return fields ? { ...metadata, ...fields, v: 1, kind: "activity" } : null;
|
|
234
|
+
}
|
|
235
|
+
/** Read a legacy record or validate an AG-UI event at the wire boundary. */
|
|
236
|
+
export function readWireRecord(raw) {
|
|
237
|
+
const value = read(raw);
|
|
238
|
+
return object(value) && value.v === 1 ? value : parseEvent(value);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Read either wire format during the migration. A string's result is memoized: the UI server re-reads every event it
|
|
242
|
+
* holds on each snapshot. Callers treat the envelope as read-only.
|
|
243
|
+
*/
|
|
244
|
+
export function parseWireEnvelope(raw) {
|
|
245
|
+
if (typeof raw !== "string")
|
|
246
|
+
return projectRecord(readWireRecord(raw));
|
|
247
|
+
if (parsed.has(raw))
|
|
248
|
+
return parsed.get(raw);
|
|
249
|
+
const envelope = projectRecord(readWireRecord(raw));
|
|
250
|
+
if (parsed.size >= PARSED_MAX)
|
|
251
|
+
parsed.clear();
|
|
252
|
+
parsed.set(raw, envelope);
|
|
253
|
+
return envelope;
|
|
254
|
+
}
|
|
255
|
+
const projectRecord = (record) => !record || record.v === 1 ? record : projectEvent(record);
|
package/lib/alerts.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Phone alert level: which notifications buzz. Messages always arrive; a level silences the rest with wire priority 1.
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { configDir } from "./config.js";
|
|
4
|
+
import { readJson, writeJson } from "./store.js";
|
|
5
|
+
export const ALERT_LEVELS = ["all", "questions-and-direct", "questions", "none"];
|
|
6
|
+
export const DEFAULT_ALERT_LEVEL = "all";
|
|
7
|
+
// Wire priority of a silent notification: listed in the app, no sound or vibration.
|
|
8
|
+
const SILENT_PRIORITY = 1;
|
|
9
|
+
/** Kinds: question (ask_question, terminal questions, approvals), direct (agent replies to the operator), other (status, receipts, mode, usage). */
|
|
10
|
+
export function buzzes(level, kind) {
|
|
11
|
+
if (level === "all")
|
|
12
|
+
return true;
|
|
13
|
+
if (level === "none")
|
|
14
|
+
return false;
|
|
15
|
+
if (level === "questions")
|
|
16
|
+
return kind === "question";
|
|
17
|
+
return kind === "question" || kind === "direct";
|
|
18
|
+
}
|
|
19
|
+
/** The wire priority for a publish: its own when it buzzes at this level, else the silent priority. */
|
|
20
|
+
export function alertPriority(level, kind, priority) {
|
|
21
|
+
return buzzes(level, kind) ? priority : SILENT_PRIORITY;
|
|
22
|
+
}
|
|
23
|
+
function alertsFile(env) {
|
|
24
|
+
return join(configDir(env), "alerts.json");
|
|
25
|
+
}
|
|
26
|
+
/** The stored level; the default when the file is missing, unreadable or names no level. */
|
|
27
|
+
export function readAlertLevel(env = process.env) {
|
|
28
|
+
const level = readJson(alertsFile(env))?.level;
|
|
29
|
+
return ALERT_LEVELS.includes(level) ? level : DEFAULT_ALERT_LEVEL;
|
|
30
|
+
}
|
|
31
|
+
/** Stores the level atomically; throws on a level outside ALERT_LEVELS. */
|
|
32
|
+
export function writeAlertLevel(env, level) {
|
|
33
|
+
if (!ALERT_LEVELS.includes(level))
|
|
34
|
+
throw Object.assign(new Error("Alert level must be " + ALERT_LEVELS.join(", ")), { status: 400 });
|
|
35
|
+
writeJson(alertsFile(env), { level });
|
|
36
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** Minimal OTLP/HTTP protobuf encoder for ExportTraceServiceRequest (spans with scalar attributes); no dependency. */
|
|
2
|
+
const varint = (value) => {
|
|
3
|
+
let v = BigInt(value);
|
|
4
|
+
const bytes = [];
|
|
5
|
+
while (v > 0x7fn) {
|
|
6
|
+
bytes.push(Number(v & 0x7fn) | 0x80);
|
|
7
|
+
v >>= 7n;
|
|
8
|
+
}
|
|
9
|
+
bytes.push(Number(v));
|
|
10
|
+
return Buffer.from(bytes);
|
|
11
|
+
};
|
|
12
|
+
const tag = (field, wire) => varint((field << 3) | wire);
|
|
13
|
+
const bytesField = (field, buf) => Buffer.concat([tag(field, 2), varint(buf.length), buf]);
|
|
14
|
+
const stringField = (field, s) => bytesField(field, Buffer.from(String(s), "utf8"));
|
|
15
|
+
const varintField = (field, v) => Buffer.concat([tag(field, 0), varint(v)]);
|
|
16
|
+
const fixed64 = (field, ms) => { const b = Buffer.alloc(8); b.writeBigUInt64LE(BigInt(Math.round(ms)) * 1000000n); return Buffer.concat([tag(field, 1), b]); };
|
|
17
|
+
function anyValue(v) {
|
|
18
|
+
if (typeof v === "boolean")
|
|
19
|
+
return varintField(2, v ? 1 : 0);
|
|
20
|
+
if (typeof v === "number" && Number.isInteger(v))
|
|
21
|
+
return varintField(3, BigInt.asUintN(64, BigInt(v)));
|
|
22
|
+
if (typeof v === "number") {
|
|
23
|
+
const b = Buffer.alloc(8);
|
|
24
|
+
b.writeDoubleLE(v);
|
|
25
|
+
return Buffer.concat([tag(4, 1), b]);
|
|
26
|
+
}
|
|
27
|
+
return stringField(1, v);
|
|
28
|
+
}
|
|
29
|
+
const keyValue = (k, v) => Buffer.concat([stringField(1, k), bytesField(2, anyValue(v))]);
|
|
30
|
+
function span({ traceId, spanId, parentSpanId, name, startMs, endMs, attrs = {} }) {
|
|
31
|
+
return Buffer.concat([
|
|
32
|
+
bytesField(1, Buffer.from(traceId, "hex")), bytesField(2, Buffer.from(spanId, "hex")),
|
|
33
|
+
...(parentSpanId ? [bytesField(4, Buffer.from(parentSpanId, "hex"))] : []), stringField(5, name), varintField(6, 1),
|
|
34
|
+
fixed64(7, startMs), fixed64(8, endMs),
|
|
35
|
+
...Object.entries(attrs).map(([k, v]) => bytesField(9, keyValue(k, v))),
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
/** The request body for POST /v1/traces (Content-Type: application/x-protobuf). */
|
|
39
|
+
export function encodeTraceRequest(spans, { project = "temmo", service = "temmo-analyze", scope: scopeName = "temmo.analyze-run-code" } = {}) {
|
|
40
|
+
const resource = bytesField(1, Buffer.concat([
|
|
41
|
+
bytesField(1, keyValue("service.name", service)), bytesField(1, keyValue("openinference.project.name", project)),
|
|
42
|
+
]));
|
|
43
|
+
const scope = bytesField(1, stringField(1, scopeName));
|
|
44
|
+
const scopeSpans = bytesField(2, Buffer.concat([scope, ...spans.map((s) => bytesField(2, span(s)))]));
|
|
45
|
+
return bytesField(1, Buffer.concat([resource, scopeSpans]));
|
|
46
|
+
}
|