@temmo/cli 0.0.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +14 -0
- package/.claude-plugin/plugin.json +16 -0
- package/.codex-plugin/plugin.json +30 -0
- package/.cursor-plugin/plugin.json +22 -0
- package/.mcp.json +18 -0
- package/LICENSE +202 -0
- package/README.md +82 -2
- package/THIRD_PARTY_NOTICES +32 -0
- package/commands/afk.md +17 -0
- package/deploy/build-ui.mjs +65 -0
- package/deploy/claude/README.md +16 -0
- package/deploy/claude/auto-mode.json +31 -0
- package/deploy/postgres/compose.yaml +26 -0
- package/deploy/temmo-runner.service +24 -0
- package/deploy/verify-ui.mjs +15 -0
- package/harness-core/README.md +27 -0
- package/harness-core/bin/harness.mjs +17 -0
- package/harness-core/package.json +10 -0
- package/harness-core/stage.mjs +108 -0
- package/harness-core/stages/commit.md +7 -0
- package/harness-core/stages/pr.md +7 -0
- package/harness-core/stages/push.md +7 -0
- package/hooks/codex-hooks.json +14 -0
- package/hooks/cursor-hooks.json +17 -0
- package/hooks/hooks.json +27 -0
- package/lib/acp/permission.js +72 -0
- package/lib/acp/sessionConfig.js +109 -0
- package/lib/activity.js +244 -0
- package/lib/agent-guard.js +72 -0
- package/lib/agents-route.js +55 -0
- package/lib/agents.js +213 -0
- package/lib/agui.js +255 -0
- package/lib/alerts.js +36 -0
- package/lib/analyze-otlp.js +46 -0
- package/lib/analyze-run-code.js +397 -0
- package/lib/analyze-sources.js +372 -0
- package/lib/approval-card.js +54 -0
- package/lib/approval-cli.js +53 -0
- package/lib/approval-request.js +81 -0
- package/lib/approval-signer.js +48 -0
- package/lib/approvals.js +295 -0
- package/lib/attachment-cache.js +236 -0
- package/lib/attachment.js +63 -0
- package/lib/blocked.js +20 -0
- package/lib/build-review.js +90 -0
- package/lib/builder/cli.js +90 -0
- package/lib/builder/policy.js +176 -0
- package/lib/builder/recover.js +189 -0
- package/lib/builder/run.js +240 -0
- package/lib/builder/settle.js +198 -0
- package/lib/builder/stage.js +240 -0
- package/lib/builder/state.js +73 -0
- package/lib/builder/supervisor.js +289 -0
- package/lib/builder-clean.js +223 -0
- package/lib/builder-code.cjs +67 -0
- package/lib/builder.js +9 -0
- package/lib/bus-postgres.js +281 -0
- package/lib/bus.js +349 -0
- package/lib/catalog/author.js +278 -0
- package/lib/catalog/dot.js +426 -0
- package/lib/catalog/pattern-model.js +193 -0
- package/lib/catalog/patterns.js +324 -0
- package/lib/catalog/projects.js +83 -0
- package/lib/catalog/records.js +2 -0
- package/lib/catalog/roster.js +70 -0
- package/lib/catalog/team-files.js +49 -0
- package/lib/catalog/teams.js +109 -0
- package/lib/claude-socket.js +333 -0
- package/lib/cli.js +741 -0
- package/lib/code-mode.js +45 -0
- package/lib/code-read-policy.yaml +9 -0
- package/lib/code-run.js +461 -0
- package/lib/codex-compact.js +141 -0
- package/lib/compaction.js +21 -0
- package/lib/config.js +424 -0
- package/lib/cursor-trace.js +248 -0
- package/lib/deep-link.js +20 -0
- package/lib/deliver-push.js +120 -0
- package/lib/delivery.js +28 -0
- package/lib/deploy-tree.js +227 -0
- package/lib/durable.js +404 -0
- package/lib/factory-tick.js +32 -0
- package/lib/family.js +63 -0
- package/lib/fetch-origin.js +53 -0
- package/lib/format.js +133 -0
- package/lib/harness-surface-cli.js +153 -0
- package/lib/harness-surface.js +486 -0
- package/lib/harness.js +271 -0
- package/lib/hook.mjs +291 -0
- package/lib/idle.js +40 -0
- package/lib/install-cursor.js +115 -0
- package/lib/install-opencode.js +105 -0
- package/lib/job.js +82 -0
- package/lib/land-cli.js +319 -0
- package/lib/land-member.js +64 -0
- package/lib/land.js +320 -0
- package/lib/lessons.js +223 -0
- package/lib/limit-alert.js +423 -0
- package/lib/limits.js +284 -0
- package/lib/machine-prompt.js +19 -0
- package/lib/merge-sweep.js +149 -0
- package/lib/messaging.js +1002 -0
- package/lib/mission-cli.js +103 -0
- package/lib/mission.js +241 -0
- package/lib/mode.js +215 -0
- package/lib/models.js +114 -0
- package/lib/names.js +86 -0
- package/lib/opencode-api.js +57 -0
- package/lib/opencode-plugin.mjs +313 -0
- package/lib/operator-token.js +78 -0
- package/lib/operator.js +187 -0
- package/lib/pad-activity.js +143 -0
- package/lib/pad-fresh.js +44 -0
- package/lib/pad.js +198 -0
- package/lib/pattern-cli.js +120 -0
- package/lib/pattern-compiler.js +68 -0
- package/lib/pattern-runs.js +795 -0
- package/lib/pattern-stall.js +58 -0
- package/lib/pattern-tick.js +45 -0
- package/lib/pattern-workflow.js +69 -0
- package/lib/pi-extension.mjs +98 -0
- package/lib/pi.js +57 -0
- package/lib/plugin-copy.js +76 -0
- package/lib/pm-review.js +32 -0
- package/lib/pm-workspace.js +87 -0
- package/lib/postgres.js +115 -0
- package/lib/pr-card.js +34 -0
- package/lib/probe.js +295 -0
- package/lib/process.js +67 -0
- package/lib/project-pause.js +23 -0
- package/lib/prune.js +793 -0
- package/lib/questions.js +250 -0
- package/lib/receipts.js +63 -0
- package/lib/reflect.js +962 -0
- package/lib/rename-migration.js +118 -0
- package/lib/run-terminal.js +437 -0
- package/lib/runner-request.js +33 -0
- package/lib/sandbox-app.js +120 -0
- package/lib/sandbox-claims.js +258 -0
- package/lib/sandbox-cli.js +188 -0
- package/lib/sandbox-hosts-cli.js +68 -0
- package/lib/sandbox-hosts.js +94 -0
- package/lib/sandbox-pr.js +102 -0
- package/lib/sandbox-proposal.js +367 -0
- package/lib/sandbox-tools.js +143 -0
- package/lib/sandbox.js +501 -0
- package/lib/schedule-session.js +68 -0
- package/lib/session-activity.js +67 -0
- package/lib/session-events.js +94 -0
- package/lib/sessions/control.js +244 -0
- package/lib/sessions/git-refs.js +265 -0
- package/lib/sessions/launch.js +359 -0
- package/lib/sessions/registry.js +450 -0
- package/lib/sessions/scope.js +111 -0
- package/lib/setup.js +377 -0
- package/lib/signed-approval.js +225 -0
- package/lib/slash.js +167 -0
- package/lib/spawn-cli.js +45 -0
- package/lib/spawn.js +107 -0
- package/lib/start-limit.js +58 -0
- package/lib/state.js +24 -0
- package/lib/stop.js +308 -0
- package/lib/store-read.js +62 -0
- package/lib/store.js +252 -0
- package/lib/subagent-guard.js +240 -0
- package/lib/surfaces/channel-post.js +43 -0
- package/lib/surfaces/instructions.js +15 -0
- package/lib/surfaces/mcp-reload.js +144 -0
- package/lib/surfaces/ops.js +629 -0
- package/lib/surfaces/render-mcp.js +33 -0
- package/lib/surfaces/run-terminal-ops.js +40 -0
- package/lib/surfaces/sandbox-ops.js +36 -0
- package/lib/surfaces/schema.js +7 -0
- package/lib/surfaces/task-view.js +90 -0
- package/lib/surfaces/types.js +4 -0
- package/lib/task-cli.js +274 -0
- package/lib/task-order.js +34 -0
- package/lib/task-order.mjs +2 -0
- package/lib/task-route.js +125 -0
- package/lib/tasks.js +631 -0
- package/lib/team-permission.js +34 -0
- package/lib/team-templates/blitz/team.dot +9 -0
- package/lib/team-templates/factory/team.dot +26 -0
- package/lib/team-templates/feature/team.dot +14 -0
- package/lib/team-templates/fix-and-review/team.dot +12 -0
- package/lib/team-templates/product/team.dot +16 -0
- package/lib/team-templates/release/team.dot +7 -0
- package/lib/team-templates/review/team.dot +6 -0
- package/lib/terminal-draft.js +42 -0
- package/lib/thread-branch.js +82 -0
- package/lib/thread-channel-store.js +181 -0
- package/lib/thread-channels.js +116 -0
- package/lib/thread-listening.js +20 -0
- package/lib/thread-routes.js +91 -0
- package/lib/threads.js +441 -0
- package/lib/tool-api.js +33 -0
- package/lib/transcript.js +98 -0
- package/lib/ui-build-output.js +19 -0
- package/lib/ui-capabilities.js +90 -0
- package/lib/usage.js +182 -0
- package/lib/vendor/mcp-sdk.d.mts +4 -0
- package/lib/vendor/mcp-sdk.mjs +17046 -0
- package/lib/waiter.js +127 -0
- package/lib/workflows.js +546 -0
- package/lib/worktree-setup.js +86 -0
- package/package.json +112 -1
- package/runner/adapters/claude.js +465 -0
- package/runner/adapters/cli-sandbox.js +277 -0
- package/runner/adapters/codex.js +675 -0
- package/runner/adapters/cursor.mjs +937 -0
- package/runner/adapters/fake.js +119 -0
- package/runner/adapters/opencode-sandbox.js +370 -0
- package/runner/adapters/opencode.js +486 -0
- package/runner/adapters/pi-sandbox.js +134 -0
- package/runner/adapters/pi.js +364 -0
- package/runner/client.js +40 -0
- package/runner/contract.js +129 -0
- package/runner/control.js +178 -0
- package/runner/delivery.js +184 -0
- package/runner/factory-tick.mjs +10 -0
- package/runner/lock.js +41 -0
- package/runner/main.mjs +118 -0
- package/runner/pattern-tick.mjs +16 -0
- package/runner/publish.js +113 -0
- package/runner/runner.js +2612 -0
- package/runner/sandbox-run.mjs +239 -0
- package/runner/schedules.js +294 -0
- package/runner/task-wake.js +59 -0
- package/scripts/ai-collab +3 -0
- package/scripts/ai-collab-bus.mjs +4 -0
- package/scripts/ai-collab-code-mcp.mjs +3 -0
- package/scripts/ai-collab-hook +3 -0
- package/scripts/ai-collab-hook.mjs +3 -0
- package/scripts/ai-collab-mcp-tools.mjs +2 -0
- package/scripts/ai-collab-mcp.mjs +3 -0
- package/scripts/ai-collab.mjs +3 -0
- package/scripts/install-cursor.mjs +11 -0
- package/scripts/install-opencode.mjs +10 -0
- package/scripts/temmo +3 -0
- package/scripts/temmo-bus.mjs +151 -0
- package/scripts/temmo-code-mcp.mjs +63 -0
- package/scripts/temmo-hook +3 -0
- package/scripts/temmo-hook.mjs +201 -0
- package/scripts/temmo-mcp-tools.mjs +22 -0
- package/scripts/temmo-mcp.mjs +27 -0
- package/scripts/temmo.mjs +4 -0
- package/skills/antislop/SKILL.md +701 -0
- package/skills/antislop/VERSION +1 -0
- package/skills/antislop-code/SKILL.md +128 -0
- package/skills/antislop-human/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-human/SKILL.md +204 -0
- package/skills/antislop-human/contrast-check.py +168 -0
- package/skills/antislop-human/contrast-mcp.py +125 -0
- package/skills/antislop-human/references/A11Y-PATTERNS.md +249 -0
- package/skills/antislop-human/references/WCAG.md +127 -0
- package/skills/antislop-layoutmobile/SKILL.md +170 -0
- package/skills/antislop-ui/LICENSE-web-quality-skills +21 -0
- package/skills/antislop-ui/SKILL.md +351 -0
- package/skills/antislop-ui/references/CORE-WEB-VITALS.md +181 -0
- package/skills/antislop-ui/references/WEB-BASELINE.md +28 -0
- package/skills/harness-surface/SKILL.md +42 -0
- package/skills/land/SKILL.md +32 -0
- package/skills/memory-file/SKILL.md +39 -0
- package/skills/temmo/SKILL.md +101 -0
- package/skills/temmo/references/role-programs.md +47 -0
- package/skills/ui-sdk/SKILL.md +56 -0
- package/skills/ui-sdk/references/agent-ready.md +136 -0
- package/skills/ui-sdk/references/build-interface.md +187 -0
- package/skills/ui-sdk/references/create-component.md +88 -0
- package/skills/ui-sdk/references/patterns.md +246 -0
- package/skills/ui-sdk/references/styles.md +66 -0
- package/skills/ui-sdk/references/testing.md +172 -0
- package/skills/ui-sdk/references/web-components.md +78 -0
- package/tools/screen-state.mjs +119 -0
- package/tools/smoke-ui.mjs +540 -0
- package/web/app/activity.jsx +251 -0
- package/web/app/agent-mark.tsx +43 -0
- package/web/app/alert-level.jsx +16 -0
- package/web/app/api/[action]/route.js +8 -0
- package/web/app/api/auth/[step]/route.js +12 -0
- package/web/app/api/events/route.js +8 -0
- package/web/app/api/file/[name]/route.js +8 -0
- package/web/app/api/land/route.js +12 -0
- package/web/app/api/lessons/route.js +8 -0
- package/web/app/api/push/key/route.js +8 -0
- package/web/app/api/push/subscribe/route.js +12 -0
- package/web/app/api/push/test/route.js +8 -0
- package/web/app/api/refs/route.js +8 -0
- package/web/app/api/review-diff/route.js +8 -0
- package/web/app/api/schedules/route.js +8 -0
- package/web/app/api/thread-diff/route.js +8 -0
- package/web/app/api/version/route.js +6 -0
- package/web/app/cards.jsx +189 -0
- package/web/app/chat-api.js +82 -0
- package/web/app/chat-composer.jsx +313 -0
- package/web/app/chat-console.jsx +691 -0
- package/web/app/chat-image.tsx +61 -0
- package/web/app/chat-message.jsx +122 -0
- package/web/app/chat-shared.jsx +59 -0
- package/web/app/chat-sidebar.jsx +25 -0
- package/web/app/chat-stream.js +127 -0
- package/web/app/chat.jsx +31 -0
- package/web/app/compactions.jsx +57 -0
- package/web/app/composer-actions.tsx +87 -0
- package/web/app/decisions.jsx +53 -0
- package/web/app/fonts/OFL-hanken-grotesk.txt +93 -0
- package/web/app/fonts/OFL-ibm-plex-mono.txt +93 -0
- package/web/app/fonts/hanken-grotesk-latin-wght-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- package/web/app/fonts/ibm-plex-mono-latin-500-normal.woff2 +0 -0
- package/web/app/globals.css +199 -0
- package/web/app/home.jsx +246 -0
- package/web/app/icon.svg +1 -0
- package/web/app/land-panel.jsx +63 -0
- package/web/app/land-reviews.jsx +20 -0
- package/web/app/layout.jsx +17 -0
- package/web/app/lessons.tsx +76 -0
- package/web/app/logo.tsx +13 -0
- package/web/app/logos.jsx +16 -0
- package/web/app/manifest.js +8 -0
- package/web/app/mode-menu.tsx +46 -0
- package/web/app/new-session.jsx +275 -0
- package/web/app/notify.jsx +180 -0
- package/web/app/outcomes.tsx +94 -0
- package/web/app/page.jsx +9 -0
- package/web/app/pattern-graph.jsx +75 -0
- package/web/app/patterns-page.jsx +293 -0
- package/web/app/phone-nav.tsx +36 -0
- package/web/app/progress-feed.tsx +33 -0
- package/web/app/providers.tsx +27 -0
- package/web/app/quote.jsx +15 -0
- package/web/app/run-card.tsx +200 -0
- package/web/app/run-requests.tsx +148 -0
- package/web/app/scheduled.jsx +105 -0
- package/web/app/session-panel.tsx +174 -0
- package/web/app/session-toolbar.tsx +180 -0
- package/web/app/shadcn.css +638 -0
- package/web/app/shipped.jsx +49 -0
- package/web/app/subagent-runs.jsx +31 -0
- package/web/app/task-graph.jsx +67 -0
- package/web/app/tasks-strip.tsx +36 -0
- package/web/app/tasks.jsx +375 -0
- package/web/app/team-author.jsx +145 -0
- package/web/app/team-editor.jsx +88 -0
- package/web/app/thread-agents.tsx +32 -0
- package/web/app/thread-place.tsx +9 -0
- package/web/app/thread-sessions.tsx +149 -0
- package/web/app/thread-sidebar.tsx +418 -0
- package/web/app/thread-switcher.tsx +27 -0
- package/web/app/tool-diff.jsx +94 -0
- package/web/components/a2ui/controls.jsx +36 -0
- package/web/components/a2ui/option-picker.jsx +23 -0
- package/web/components/a2ui/script.tsx +121 -0
- package/web/components/a2ui/surface.jsx +81 -0
- package/web/components/chat/thread.jsx +50 -0
- package/web/components/script-text.tsx +42 -0
- package/web/components/ui/avatar.jsx +115 -0
- package/web/components/ui/badge.jsx +47 -0
- package/web/components/ui/button.jsx +63 -0
- package/web/components/ui/chat-container.jsx +52 -0
- package/web/components/ui/choice-list.tsx +72 -0
- package/web/components/ui/code-block.jsx +60 -0
- package/web/components/ui/copy-button.tsx +41 -0
- package/web/components/ui/dropdown-menu.jsx +257 -0
- package/web/components/ui/markdown.jsx +84 -0
- package/web/components/ui/message.jsx +28 -0
- package/web/components/ui/popover.jsx +33 -0
- package/web/components/ui/scroll-button.jsx +34 -0
- package/web/components/ui/select.jsx +189 -0
- package/web/components/ui/sheet.jsx +152 -0
- package/web/components/ui/sonner.jsx +10 -0
- package/web/components/ui/tabs.jsx +88 -0
- package/web/components/ui/textarea.jsx +20 -0
- package/web/components/ui/tooltip.jsx +56 -0
- package/web/components.json +24 -0
- package/web/instrumentation.js +8 -0
- package/web/lib/a2ui-catalog.js +34 -0
- package/web/lib/a2ui-pr.js +76 -0
- package/web/lib/a2ui-run-catalog.js +18 -0
- package/web/lib/a2ui-run.js +93 -0
- package/web/lib/a2ui.js +262 -0
- package/web/lib/activity-rows.js +275 -0
- package/web/lib/agent-detail.js +5 -0
- package/web/lib/alert-level.js +44 -0
- package/web/lib/approval-mode.js +22 -0
- package/web/lib/chat-turns.js +174 -0
- package/web/lib/child-subagents.js +16 -0
- package/web/lib/compaction-view.js +48 -0
- package/web/lib/composer-actions.js +40 -0
- package/web/lib/context-view.js +57 -0
- package/web/lib/fuzzy.js +26 -0
- package/web/lib/highlight.js +44 -0
- package/web/lib/lessons-view.js +23 -0
- package/web/lib/mentions.js +16 -0
- package/web/lib/message-routing.js +105 -0
- package/web/lib/new-session.js +85 -0
- package/web/lib/operator-messages.js +28 -0
- package/web/lib/pattern-graph.js +165 -0
- package/web/lib/pattern-view.js +33 -0
- package/web/lib/pending-summary.js +18 -0
- package/web/lib/permission-modes.js +30 -0
- package/web/lib/project-feed.js +107 -0
- package/web/lib/quote.js +7 -0
- package/web/lib/reply-quote.js +31 -0
- package/web/lib/scheduled.js +79 -0
- package/web/lib/selection.js +110 -0
- package/web/lib/send-confirmation.js +22 -0
- package/web/lib/session-dead.js +10 -0
- package/web/lib/session-state.js +132 -0
- package/web/lib/sidebar.js +15 -0
- package/web/lib/slash-commands.js +164 -0
- package/web/lib/start-default.js +35 -0
- package/web/lib/start-mode.js +35 -0
- package/web/lib/stream-views.js +49 -0
- package/web/lib/subagent-state.js +20 -0
- package/web/lib/task-board.js +54 -0
- package/web/lib/task-graph.js +183 -0
- package/web/lib/task-tags.js +41 -0
- package/web/lib/team-editor.js +10 -0
- package/web/lib/thread-groups.js +86 -0
- package/web/lib/threads.js +28 -0
- package/web/lib/tool-diff.js +273 -0
- package/web/lib/ui-events.js +58 -0
- package/web/lib/utils.js +5 -0
- package/web/lib/view-memory.js +25 -0
- package/web/next.config.mjs +37 -0
- package/web/postcss.config.mjs +1 -0
- package/web/proxy.js +25 -0
- package/web/public/sw.js +39 -0
- package/web/server/auth.js +178 -0
- package/web/server/dispatch.js +293 -0
- package/web/server/history.js +56 -0
- package/web/server/hosted.js +58 -0
- package/web/server/hub.js +126 -0
- package/web/server/instance.js +5 -0
- package/web/server/land-reviews.js +64 -0
- package/web/server/push.js +148 -0
- package/web/server/run-terminal.js +79 -0
- package/web/server/schedules.js +38 -0
- package/web/server/shipped.js +51 -0
- package/web/server/task-board.js +71 -0
- package/web/server/threads.js +209 -0
- package/web/server/ui.js +2937 -0
- package/web/tsconfig.base.json +16 -0
- package/web/tsconfig.json +9 -0
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `temmo analyze run-code`: how forcing temmo reads through run_code / run_read_code changed agent behaviour
|
|
3
|
+
* and cost, before vs after a cutover. Reads local harness logs only; sources live in analyze-sources.ts.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
import { configDir, sessionLabel } from "./config.js";
|
|
11
|
+
import { sessionOfCommand } from "./schedule-session.js";
|
|
12
|
+
import { READ_PATHS, claudeSource, codexSource, cursorSource, journalSource, opencodeSource, taskStoreSource } from "./analyze-sources.js";
|
|
13
|
+
import { encodeTraceRequest } from "./analyze-otlp.js";
|
|
14
|
+
export const DEFAULT_CUTOVER = "2026-11-23T03:15:00Z";
|
|
15
|
+
export const DEFAULT_PARTIAL = "2026-11-23T02:30:00Z";
|
|
16
|
+
export const DEFAULT_TZ = "America/Toronto";
|
|
17
|
+
export const HARNESSES = ["claude", "codex", "cursor", "opencode", "pi"];
|
|
18
|
+
export const ROLES = ["pm", "builder", "interactive", "subagent"];
|
|
19
|
+
const PERIODS = ["before", "partial", "after"];
|
|
20
|
+
const TOP_AGENTS = 15;
|
|
21
|
+
export const USAGE = `usage: temmo analyze run-code [--since ISO] [--until ISO] [--cutover ISO] [--partial ISO|none] [--agent SELECTOR]...
|
|
22
|
+
[--tz ZONE] [--out FILE|-] [--jsonl FILE] [--otlp-export URL] [--phoenix-project NAME]
|
|
23
|
+
--cutover instant run_code reads became enforced everywhere (default ${DEFAULT_CUTOVER})
|
|
24
|
+
--partial instant MCP reads became enforced, CLI reads not yet (default ${DEFAULT_PARTIAL}; none disables the middle period)
|
|
25
|
+
--agent keep one agent: harness#label (16 hex), a harness (claude codex cursor opencode) or a role (pm builder interactive subagent);
|
|
26
|
+
repeatable; values of one kind are alternatives, different kinds must all match
|
|
27
|
+
--tz zone for ISO weeks (default ${DEFAULT_TZ})
|
|
28
|
+
--out markdown report (default docs/research/run-code-impact-<date>.md; - prints it)
|
|
29
|
+
--jsonl one JSON row per agent x model x period x week
|
|
30
|
+
--otlp-export URL POST one span per turn (OTLP/HTTP protobuf, e.g. http://localhost:6006/v1/traces for Phoenix)`;
|
|
31
|
+
// Official list prices in USD per million tokens (docs/research/api-cost-estimate-2026-11-22.md).
|
|
32
|
+
// Claude: [input, 5-minute cache write, 1-hour cache write, cache read, output].
|
|
33
|
+
const CLAUDE = {
|
|
34
|
+
"claude-opus-5-5": [4, 5, 8, 0.2, 20], "claude-sonnet-5-5": [2, 2.5, 4, 0.1, 10],
|
|
35
|
+
"claude-fable-5-2": [8, 10, 16, 0.2, 40], "claude-fable-5-1": [10, 12.5, 20, 0.25, 50],
|
|
36
|
+
};
|
|
37
|
+
const HAIKU_LOW = [0.1, 0.125, 0.2, 0.01, 0.5];
|
|
38
|
+
const HAIKU_HIGH = [0.5, 0.625, 1, 0.05, 2.5];
|
|
39
|
+
// OpenAI: [short, long (> 272K input)] each [input, cached input, output].
|
|
40
|
+
const OPENAI = {
|
|
41
|
+
"gpt-6-astra": [[10, 1, 50], [20, 2, 75]], "gpt-6-sol": [[2, 0.2, 10], [4, 0.4, 15]], "gpt-6-luna": [[0.1, 0.01, 0.5], [0.2, 0.02, 0.75]],
|
|
42
|
+
"gpt-6.1-sol": [[2, 0.1, 10], [4, 0.2, 15]], "gpt-6.1-terra": [[1, 0.05, 5], [2, 0.1, 7.5]], "gpt-6.2-astra": [[8, 0.4, 40], [16, 0.8, 60]],
|
|
43
|
+
"gpt-6.2-sol": [[2, 0.1, 10], [4, 0.2, 15]], "gpt-5.6-sol": [[4, 0.4, 20], [8, 0.8, 30]], "gpt-5.6-terra": [[2, 0.2, 12], [4, 0.4, 18]],
|
|
44
|
+
"gpt-5.6-luna": [[0.2, 0.02, 1.2], [0.4, 0.04, 1.8]], "gpt-5.3-codex": [[1.75, 0.175, 14], [1.75, 0.175, 14]],
|
|
45
|
+
};
|
|
46
|
+
const BUILDER_CWD = /\/ai-collab-wt-|\/\.local\/state\/(?:temmo|ai-collab)\/builders\/|^\/sandbox(?:\/|$)/;
|
|
47
|
+
const ADDRESS = /^(claude|codex|cursor|opencode)#[0-9a-f]{16}$/;
|
|
48
|
+
const VALUE_FLAGS = ["since", "until", "cutover", "partial", "out", "jsonl", "tz", "otlp-export", "phoenix-project", "schedules"];
|
|
49
|
+
const OPTIONS = {
|
|
50
|
+
help: { type: "boolean", short: "h" },
|
|
51
|
+
agent: { type: "string", multiple: true, default: [] },
|
|
52
|
+
...Object.fromEntries(VALUE_FLAGS.map((name) => [name, { type: "string" }])),
|
|
53
|
+
};
|
|
54
|
+
/** List-price USD for one turn's tokens, or null when the model has no published price. */
|
|
55
|
+
export function priceTurn(harness, model, tok) {
|
|
56
|
+
if (!tok)
|
|
57
|
+
return null;
|
|
58
|
+
const { input, cw5, cw1, cacheRead, output } = tok;
|
|
59
|
+
if (harness === "claude") {
|
|
60
|
+
const p = model === "claude-haiku-5-5" ? (input + cw5 + cw1 + cacheRead > 100000 ? HAIKU_HIGH : HAIKU_LOW) : CLAUDE[model];
|
|
61
|
+
return p ? (input * p[0] + cw5 * p[1] + cw1 * p[2] + cacheRead * p[3] + output * p[4]) / 1e6 : null;
|
|
62
|
+
}
|
|
63
|
+
if (harness === "codex" && OPENAI[model]) {
|
|
64
|
+
const [short, long] = OPENAI[model];
|
|
65
|
+
const p = input + cacheRead > 272000 ? long : short;
|
|
66
|
+
return (input * p[0] + cacheRead * p[1] + output * p[2]) / 1e6;
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
/** before / partial / after for a timestamp in ms; cut = {partial: ms|null, cutover: ms}. */
|
|
71
|
+
export function periodOf(ts, { partial, cutover }) {
|
|
72
|
+
if (ts >= cutover)
|
|
73
|
+
return "after";
|
|
74
|
+
return partial != null && partial < cutover && ts >= partial ? "partial" : "before";
|
|
75
|
+
}
|
|
76
|
+
/** ISO 8601 week (YYYY-Www) of a timestamp in a time zone. */
|
|
77
|
+
export function isoWeek(ts, tz) {
|
|
78
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat("en-CA", { timeZone: tz, year: "numeric", month: "2-digit", day: "2-digit" }).formatToParts(ts).map((p) => [p.type, p.value]));
|
|
79
|
+
const d = new Date(Date.UTC(+parts.year, +parts.month - 1, +parts.day));
|
|
80
|
+
const day = d.getUTCDay() || 7;
|
|
81
|
+
d.setUTCDate(d.getUTCDate() + 4 - day);
|
|
82
|
+
const week = Math.ceil(((d.getTime() - Date.UTC(d.getUTCFullYear(), 0, 1)) / 86400000 + 1) / 7);
|
|
83
|
+
return `${d.getUTCFullYear()}-W${String(week).padStart(2, "0")}`;
|
|
84
|
+
}
|
|
85
|
+
/** pm: a session a schedule resumes; subagent: spawned by another session; builder: a builder worktree or sandbox cwd. */
|
|
86
|
+
export function classifyRole({ native, cwd, sub }, { pmLabels }) {
|
|
87
|
+
if (sub)
|
|
88
|
+
return "subagent";
|
|
89
|
+
if (pmLabels.has(sessionLabel(native)))
|
|
90
|
+
return "pm";
|
|
91
|
+
return BUILDER_CWD.test(cwd || "") ? "builder" : "interactive";
|
|
92
|
+
}
|
|
93
|
+
/** --agent values to selectors; throws on an unknown one. */
|
|
94
|
+
export function parseSelectors(values) {
|
|
95
|
+
return values.map((v) => {
|
|
96
|
+
if (ADDRESS.test(v))
|
|
97
|
+
return { type: "address", value: v };
|
|
98
|
+
if (HARNESSES.includes(v))
|
|
99
|
+
return { type: "harness", value: v };
|
|
100
|
+
if (ROLES.includes(v))
|
|
101
|
+
return { type: "role", value: v };
|
|
102
|
+
throw new Error(`bad agent selector "${v}": use harness#<16 hex>, ${HARNESSES.join("|")} or ${ROLES.join("|")}`);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** Selectors of one kind are alternatives; every kind present must match. */
|
|
106
|
+
export function matchesSelectors(row, selectors) {
|
|
107
|
+
const field = { address: row.agent, harness: row.harness, role: row.role };
|
|
108
|
+
for (const type of new Set(selectors.map((s) => s.type))) {
|
|
109
|
+
if (!selectors.some((s) => s.type === type && s.value === field[type]))
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
/** Turns with agent, role, period and week attached, filtered by the selectors. */
|
|
115
|
+
export function annotate(turns, { cut, tz, pmLabels, selectors }) {
|
|
116
|
+
const out = [];
|
|
117
|
+
for (const t of turns) {
|
|
118
|
+
const a = { ...t, agent: `${t.harness}#${sessionLabel(t.native)}`, role: classifyRole(t, { pmLabels }), period: periodOf(t.ts, cut), week: isoWeek(t.ts, tz) };
|
|
119
|
+
if (matchesSelectors(a, selectors))
|
|
120
|
+
out.push(a);
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
const zeroTok = () => ({ n: 0, input: 0, cacheRead: 0, output: 0 });
|
|
125
|
+
const emptyRow = (key = {}) => ({
|
|
126
|
+
...key, turns: 0, usageTurns: 0, calls: 0,
|
|
127
|
+
reads: Object.fromEntries([...READ_PATHS, "bypass_read"].map((p) => [p, 0])),
|
|
128
|
+
refusals: { mcp: 0, cli: 0 }, runCodeErrors: 0,
|
|
129
|
+
tok: { input: 0, cacheWrite: 0, cacheRead: 0, output: 0 },
|
|
130
|
+
readTurns: zeroTok(), plainTurns: zeroTok(), usd: 0, pricedTurns: 0,
|
|
131
|
+
});
|
|
132
|
+
const addTok = (a, b) => { for (const k of Object.keys(a))
|
|
133
|
+
a[k] += b[k]; };
|
|
134
|
+
function addRow(a, b) {
|
|
135
|
+
for (const k of ["turns", "usageTurns", "calls", "runCodeErrors", "usd", "pricedTurns"])
|
|
136
|
+
a[k] += b[k];
|
|
137
|
+
for (const k of Object.keys(a.reads))
|
|
138
|
+
a.reads[k] += b.reads[k];
|
|
139
|
+
addTok(a.refusals, b.refusals);
|
|
140
|
+
addTok(a.tok, b.tok);
|
|
141
|
+
addTok(a.readTurns, b.readTurns);
|
|
142
|
+
addTok(a.plainTurns, b.plainTurns);
|
|
143
|
+
return a;
|
|
144
|
+
}
|
|
145
|
+
/** Group rows by a key function; each group sums the rows it holds. */
|
|
146
|
+
export function groupRows(rows, keyOf) {
|
|
147
|
+
const groups = new Map();
|
|
148
|
+
for (const r of rows) {
|
|
149
|
+
const key = keyOf(r);
|
|
150
|
+
const k = JSON.stringify(key);
|
|
151
|
+
if (!groups.has(k))
|
|
152
|
+
groups.set(k, emptyRow(key));
|
|
153
|
+
addRow(groups.get(k), r);
|
|
154
|
+
}
|
|
155
|
+
return [...groups.values()];
|
|
156
|
+
}
|
|
157
|
+
/** One row per agent x harness x model x role x period x week. */
|
|
158
|
+
export function aggregate(turns, ctx) {
|
|
159
|
+
const rows = new Map();
|
|
160
|
+
for (const t of annotate(turns, ctx)) {
|
|
161
|
+
const key = { agent: t.agent, harness: t.harness, model: t.model, role: t.role, period: t.period, week: t.week };
|
|
162
|
+
const k = Object.values(key).join("|");
|
|
163
|
+
if (!rows.has(k))
|
|
164
|
+
rows.set(k, emptyRow(key));
|
|
165
|
+
const r = rows.get(k);
|
|
166
|
+
r.turns += 1;
|
|
167
|
+
r.calls += t.calls.length;
|
|
168
|
+
let reads = false;
|
|
169
|
+
for (const c of t.calls) {
|
|
170
|
+
if (!c.path)
|
|
171
|
+
continue;
|
|
172
|
+
r.reads[c.path] += 1;
|
|
173
|
+
if (READ_PATHS.includes(c.path))
|
|
174
|
+
reads = true;
|
|
175
|
+
if (c.refused)
|
|
176
|
+
r.refusals[c.path === "mcp_read" ? "mcp" : "cli"] += 1;
|
|
177
|
+
if (c.failed)
|
|
178
|
+
r.runCodeErrors += 1;
|
|
179
|
+
}
|
|
180
|
+
if (!t.tok)
|
|
181
|
+
continue;
|
|
182
|
+
r.usageTurns += 1;
|
|
183
|
+
const input = t.tok.input + t.tok.cw5 + t.tok.cw1;
|
|
184
|
+
addTok(r.tok, { input: t.tok.input, cacheWrite: t.tok.cw5 + t.tok.cw1, cacheRead: t.tok.cacheRead, output: t.tok.output });
|
|
185
|
+
addTok(reads ? r.readTurns : r.plainTurns, { n: 1, input, cacheRead: t.tok.cacheRead, output: t.tok.output });
|
|
186
|
+
const usd = priceTurn(t.harness, t.model, t.tok);
|
|
187
|
+
if (usd != null) {
|
|
188
|
+
r.usd += usd;
|
|
189
|
+
r.pricedTurns += 1;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return [...rows.values()];
|
|
193
|
+
}
|
|
194
|
+
const n = (x) => Math.round(x).toLocaleString("en-US");
|
|
195
|
+
const per = (sum, count) => count ? n(sum / count) : "-";
|
|
196
|
+
const ratio = (sum, count) => count ? (sum / count).toFixed(2) : "-";
|
|
197
|
+
const usdCell = (r) => !r.usageTurns ? "no usage data" : r.pricedTurns === 0 ? "unpriced" : `$${r.usd.toFixed(2)}${r.pricedTurns < r.usageTurns ? "*" : ""}`;
|
|
198
|
+
const table = (head, body) => [`| ${head.join(" | ")} |`, `|${head.map((_, i) => i < 1 ? "---" : "---:").join("|")}|`, ...body.map((r) => `| ${r.join(" | ")} |`)].join("\n");
|
|
199
|
+
const order = (a, b) => PERIODS.indexOf(a) - PERIODS.indexOf(b);
|
|
200
|
+
const readCalls = (r) => READ_PATHS.reduce((s, p) => s + r.reads[p], 0);
|
|
201
|
+
const pct = (xs, p) => xs.length ? [...xs].sort((a, b) => a - b)[Math.min(xs.length - 1, Math.floor(p * xs.length))] : 0;
|
|
202
|
+
const sec = (ms) => `${(ms / 1000).toFixed(1)}s`;
|
|
203
|
+
const iso = (ms) => new Date(ms).toISOString().replace(".000Z", "Z");
|
|
204
|
+
/** The markdown report for aggregated rows. */
|
|
205
|
+
export function renderReport(rows, { cut, tz, since, until, scheduleRuns = [], tasks = null, notes = [], generated, selectors = [], sources = [], latest = null }) {
|
|
206
|
+
const present = PERIODS.filter((p) => rows.some((r) => r.period === p));
|
|
207
|
+
const out = [`# Impact of run_code reads, generated ${generated}`, ""];
|
|
208
|
+
out.push("Measured from local harness logs. Periods split at the cutover instants below; every figure counts only what the logs record.", "");
|
|
209
|
+
out.push(`- Cutover (CLI and MCP reads both enforced): ${iso(cut.cutover)}`);
|
|
210
|
+
out.push(`- Partial marker (MCP reads enforced, CLI reads not yet): ${cut.partial != null && cut.partial < cut.cutover ? iso(cut.partial) : "none"}`);
|
|
211
|
+
out.push(`- Window: ${since != null ? iso(since) : "all data"} to ${until != null ? iso(until) : "now"}`);
|
|
212
|
+
out.push(`- ISO weeks in ${tz}`);
|
|
213
|
+
out.push(`- Agent filter: ${selectors.length ? selectors.map((s) => s.value).join(", ") : "none"}`);
|
|
214
|
+
out.push(`- Sources: ${sources.join(", ")}`);
|
|
215
|
+
if (latest != null && latest > cut.cutover && latest - cut.cutover < 48 * 3600e3)
|
|
216
|
+
out.push(`- Early data: the after period covers ${((latest - cut.cutover) / 3600e3).toFixed(1)} hours (latest turn ${iso(latest)}); read its figures as a first look.`);
|
|
217
|
+
out.push("");
|
|
218
|
+
out.push("## Headline by period", "");
|
|
219
|
+
const head = (rs) => groupRows(rs, (r) => ({ period: r.period })).sort((a, b) => order(a.period, b.period));
|
|
220
|
+
out.push(table(["Period", "Turns", "MCP reads", "CLI reads", "run_code", "run_read_code", "Bypass reads", "MCP refused", "CLI refused", "run_code failures", "Calls/turn", "Tokens", "List $"], head(rows).map((r) => [r.period, n(r.turns), r.reads.mcp_read, r.reads.cli_read, r.reads.run_code, r.reads.run_read_code, r.reads.bypass_read, r.refusals.mcp, r.refusals.cli, r.runCodeErrors, ratio(r.calls, r.turns), n(r.tok.input + r.tok.cacheWrite + r.tok.cacheRead + r.tok.output), usdCell(r)])), "");
|
|
221
|
+
out.push("Tokens sum uncached input, cache writes, cache reads and output over turns with usage data. List $ prices only turns whose model has a published price; `*` marks a partly priced group.", "");
|
|
222
|
+
out.push("## Read paths by harness, model and period", "");
|
|
223
|
+
out.push(table(["Harness", "Model", "Period", "Turns", "Read turns", "MCP", "CLI", "run_code", "run_read_code", "Bypass", "MCP refused", "CLI refused", "run_code failures", "Calls/turn"], groupRows(rows, (r) => ({ harness: r.harness, model: r.model, period: r.period })).sort((a, b) => a.harness.localeCompare(b.harness) || a.model.localeCompare(b.model) || order(a.period, b.period))
|
|
224
|
+
.map((r) => [r.harness, r.model, r.period, n(r.turns), r.readTurns.n, r.reads.mcp_read, r.reads.cli_read, r.reads.run_code, r.reads.run_read_code, r.reads.bypass_read, r.refusals.mcp, r.refusals.cli, r.runCodeErrors, ratio(r.calls, r.turns)])), "");
|
|
225
|
+
out.push("## Tokens per turn: turns with temmo reads vs without", "");
|
|
226
|
+
out.push("Input counts uncached input plus cache writes; cached is cache reads. Turns without usage data (Cursor) are left out.", "");
|
|
227
|
+
out.push(table(["Harness", "Model", "Period", "Read turns", "Input", "Cached", "Output", "Plain turns", "Input", "Cached", "Output"], groupRows(rows, (r) => ({ harness: r.harness, model: r.model, period: r.period })).filter((r) => r.usageTurns).sort((a, b) => a.harness.localeCompare(b.harness) || a.model.localeCompare(b.model) || order(a.period, b.period))
|
|
228
|
+
.map((r) => [r.harness, r.model, r.period, r.readTurns.n, per(r.readTurns.input, r.readTurns.n), per(r.readTurns.cacheRead, r.readTurns.n), per(r.readTurns.output, r.readTurns.n), r.plainTurns.n, per(r.plainTurns.input, r.plainTurns.n), per(r.plainTurns.cacheRead, r.plainTurns.n), per(r.plainTurns.output, r.plainTurns.n)])), "");
|
|
229
|
+
out.push("## By role and period", "");
|
|
230
|
+
out.push(table(["Role", "Period", "Turns", "Read calls", "Refused", "Bypass", "run_code failures", "Calls/turn", "Tokens", "List $"], groupRows(rows, (r) => ({ role: r.role, period: r.period })).sort((a, b) => ROLES.indexOf(a.role) - ROLES.indexOf(b.role) || order(a.period, b.period))
|
|
231
|
+
.map((r) => [r.role, r.period, n(r.turns), readCalls(r), r.refusals.mcp + r.refusals.cli, r.reads.bypass_read, r.runCodeErrors, ratio(r.calls, r.turns), n(r.tok.input + r.tok.cacheWrite + r.tok.cacheRead + r.tok.output), usdCell(r)])), "");
|
|
232
|
+
out.push("## Tokens and list price per ISO week", "");
|
|
233
|
+
out.push(table(["Week", "Harness", "Model", "Turns", "Input", "Cache write", "Cache read", "Output", "List $"], groupRows(rows, (r) => ({ week: r.week, harness: r.harness, model: r.model })).sort((a, b) => a.week.localeCompare(b.week) || a.harness.localeCompare(b.harness) || a.model.localeCompare(b.model))
|
|
234
|
+
.map((r) => [r.week, r.harness, r.model, n(r.turns), n(r.tok.input), n(r.tok.cacheWrite), n(r.tok.cacheRead), n(r.tok.output), usdCell(r)])), "");
|
|
235
|
+
out.push("## Per-agent (top by tokens)", "");
|
|
236
|
+
const agents = groupRows(rows, (r) => ({ agent: r.agent, harness: r.harness, role: r.role }));
|
|
237
|
+
const total = (r) => r.tok.input + r.tok.cacheWrite + r.tok.cacheRead + r.tok.output;
|
|
238
|
+
agents.sort((a, b) => total(b) - total(a) || b.turns - a.turns);
|
|
239
|
+
out.push(table(["Agent", "Harness", "Role", "Models", "Turns", "Tokens", "MCP", "CLI", "run_code", "run_read_code", "Bypass", "Refused", "List $"], agents.slice(0, TOP_AGENTS).map((r) => [r.agent, r.harness, r.role, [...new Set(rows.filter((x) => x.agent === r.agent && x.role === r.role).map((x) => x.model))].join(", "), n(r.turns), n(total(r)), r.reads.mcp_read, r.reads.cli_read, r.reads.run_code, r.reads.run_read_code, r.reads.bypass_read, r.refusals.mcp + r.refusals.cli, usdCell(r)])), "");
|
|
240
|
+
out.push(`${agents.length} agents in total; the table lists the top ${Math.min(TOP_AGENTS, agents.length)}. The JSONL file holds every agent.`, "");
|
|
241
|
+
out.push("## Runner schedule runs (wall time)", "");
|
|
242
|
+
if (scheduleRuns.length) {
|
|
243
|
+
const g = new Map();
|
|
244
|
+
for (const r of scheduleRuns) {
|
|
245
|
+
const k = `${r.name}|${periodOf(r.ts, cut)}`;
|
|
246
|
+
const list = g.get(k) ?? [];
|
|
247
|
+
g.set(k, list);
|
|
248
|
+
list.push(r);
|
|
249
|
+
}
|
|
250
|
+
out.push(table(["Schedule", "Period", "Runs", "Failed", "Median", "p90", "Mean"], [...g.entries()].map(([k, rs]) => [...k.split("|"), rs]).sort((a, b) => a[0].localeCompare(b[0]) || order(a[1], b[1])).map(([name, period, rs]) => {
|
|
251
|
+
const ms = rs.map((r) => r.ms);
|
|
252
|
+
return [name, period, rs.length, rs.filter((r) => !r.ok).length, sec(pct(ms, 0.5)), sec(pct(ms, 0.9)), sec(ms.reduce((s, x) => s + x, 0) / ms.length)];
|
|
253
|
+
})), "");
|
|
254
|
+
out.push("These are machine-wide schedule runs, not filtered by --agent.", "");
|
|
255
|
+
}
|
|
256
|
+
else
|
|
257
|
+
out.push("No schedule run lines found in the window.", "");
|
|
258
|
+
if (tasks) {
|
|
259
|
+
out.push("## Task store throughput", "");
|
|
260
|
+
const done = tasks.filter((t) => t.status === "done" && Number.isFinite(t.updated));
|
|
261
|
+
out.push(table(["Period", "Tasks last updated as done"], present.map((p) => [p, done.filter((t) => periodOf(t.updated, cut) === p).length])), "");
|
|
262
|
+
out.push("A task's last update time stands for its completion time; later edits move it.", "");
|
|
263
|
+
}
|
|
264
|
+
out.push("## Method and gaps", "");
|
|
265
|
+
out.push("- Turn = one model response. Claude: one per message.id + requestId, keeping the largest output count; tool_use blocks are the union over the split lines. Codex: one per response_id of token_usage_record, with tool calls attached to the next record. OpenCode: one per assistant message.", "- Read paths: MCP read tools of the temmo server (task_list, list_agents, list_sessions, channel_history, team_status, pattern_list, pattern_status); CLI reads (`temmo task list|show`, `agents`, `sessions`, `history`, `peers`, `team status`, `pattern list`, `status`); run_code; run_read_code; bypass reads (read tools, cat, grep, jq and similar on ~/.local/share/temmo/tasks or ~/.local/state/temmo, builder state excluded).", "- A refusal is a result containing `through run_code` (MCP isError, CLI exit 3). A run_code failure is `ok:false`, a staging error, or an error that is not a refusal. Calls from an agent that runs a CLI read inside a Codex `exec` script are matched by text.", "- Roles: subagent = sidechain or child session; pm = a session a schedule named `pm` resumes (`--resume <id>` in schedules.json); builder = cwd in an ai-collab-wt-* worktree, a builder state directory or /sandbox; everything else is interactive. The builder rule also matches an interactive session that works in such a worktree.", "- Agent address = harness#sha256(native session id)[0:16]. Subagents carry their parent's address.", "- Prices: list prices from docs/research/api-cost-estimate-2026-11-22.md for Claude and Codex models; other models show tokens only. Pay-as-you-go list price, not what the subscription costs.", "- Cursor stores tool calls but no token usage and no per-message time, so its turns date from the session's creation and a session that spans a cutover counts wholly before it. A long-lived resumed PM session therefore lands in the period it started.", "- Before/after is not a controlled comparison: workload, models and sessions differ between periods, and the after period holds only the hours since the cutover.", ...notes.map((x) => `- ${x}`));
|
|
266
|
+
return out.join("\n") + "\n";
|
|
267
|
+
}
|
|
268
|
+
function spanOf(t) {
|
|
269
|
+
const id = createHash("sha256").update(`${t.agent}|${t.ts}|${t.model}`).digest("hex");
|
|
270
|
+
const attrs = {
|
|
271
|
+
"openinference.span.kind": "LLM", "llm.model_name": t.model, "session.id": t.agent, "temmo.agent": t.agent, "temmo.harness": t.harness, "temmo.role": t.role,
|
|
272
|
+
"temmo.period": t.period, "temmo.tool_calls": t.calls.length,
|
|
273
|
+
"temmo.read_calls": t.calls.filter((c) => READ_PATHS.includes(c.path)).length, "temmo.bypass_reads": t.calls.filter((c) => c.path === "bypass_read").length,
|
|
274
|
+
"temmo.refused": t.calls.filter((c) => c.refused).length,
|
|
275
|
+
};
|
|
276
|
+
if (t.tok)
|
|
277
|
+
Object.assign(attrs, { "llm.token_count.prompt": t.tok.input + t.tok.cw5 + t.tok.cw1 + t.tok.cacheRead, "llm.token_count.completion": t.tok.output, "llm.token_count.prompt_details.cache_read": t.tok.cacheRead });
|
|
278
|
+
return { traceId: createHash("sha256").update(t.agent).digest("hex").slice(0, 32), spanId: id.slice(0, 16), name: `${t.harness} turn`, startMs: t.ts, endMs: t.ts + 1, attrs };
|
|
279
|
+
}
|
|
280
|
+
/** POST turns as OTLP spans in batches; returns the number sent. */
|
|
281
|
+
export async function exportOtlp(turns, url, { project = "temmo-run-code-impact", batch = 500, fetchImpl = fetch } = {}) {
|
|
282
|
+
let sent = 0;
|
|
283
|
+
for (let i = 0; i < turns.length; i += batch) {
|
|
284
|
+
const body = encodeTraceRequest(turns.slice(i, i + batch).map(spanOf), { project });
|
|
285
|
+
const res = await fetchImpl(url, { method: "POST", headers: { "content-type": "application/x-protobuf" }, body });
|
|
286
|
+
if (!res.ok)
|
|
287
|
+
throw new Error(`OTLP export to ${url} failed: HTTP ${res.status}`);
|
|
288
|
+
sent += Math.min(batch, turns.length - i);
|
|
289
|
+
}
|
|
290
|
+
return sent;
|
|
291
|
+
}
|
|
292
|
+
function parseFlags(args) {
|
|
293
|
+
const { values: { agent, ...rest } } = parseArgs({ args, options: OPTIONS, strict: true });
|
|
294
|
+
return { ...rest, agents: agent };
|
|
295
|
+
}
|
|
296
|
+
const instant = (value, flag) => {
|
|
297
|
+
const ms = Date.parse(value);
|
|
298
|
+
if (!Number.isFinite(ms))
|
|
299
|
+
throw new Error(`${flag} must be an ISO timestamp, got "${value}"`);
|
|
300
|
+
return ms;
|
|
301
|
+
};
|
|
302
|
+
function pmLabelsOf(file) {
|
|
303
|
+
const labels = new Set();
|
|
304
|
+
if (!existsSync(file))
|
|
305
|
+
return labels;
|
|
306
|
+
try {
|
|
307
|
+
for (const s of JSON.parse(readFileSync(file, "utf8"))) {
|
|
308
|
+
if (s?.name !== "pm")
|
|
309
|
+
continue;
|
|
310
|
+
const found = sessionOfCommand(s.command);
|
|
311
|
+
if (found)
|
|
312
|
+
labels.add(found.session);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
catch { /* an unreadable schedules file leaves no PM sessions */ }
|
|
316
|
+
return labels;
|
|
317
|
+
}
|
|
318
|
+
/** Entry point. io: {env, stdout, stderr, journal (journalctl override), sources (replace the defaults)}. */
|
|
319
|
+
export async function analyze(args, io = {}) {
|
|
320
|
+
const env = io.env || process.env;
|
|
321
|
+
const out = io.stdout || process.stdout;
|
|
322
|
+
const err = io.stderr || process.stderr;
|
|
323
|
+
let o;
|
|
324
|
+
let selectors;
|
|
325
|
+
let cut;
|
|
326
|
+
let win;
|
|
327
|
+
try {
|
|
328
|
+
o = parseFlags(args);
|
|
329
|
+
if (o.help) {
|
|
330
|
+
out.write(`${USAGE}\n`);
|
|
331
|
+
return 0;
|
|
332
|
+
}
|
|
333
|
+
selectors = parseSelectors(o.agents);
|
|
334
|
+
const cutover = instant(o.cutover || DEFAULT_CUTOVER, "--cutover");
|
|
335
|
+
const partial = o.partial === "none" ? null : instant(o.partial || DEFAULT_PARTIAL, "--partial");
|
|
336
|
+
cut = { cutover, partial };
|
|
337
|
+
win = { since: o.since ? instant(o.since, "--since") : null, until: o.until ? instant(o.until, "--until") : null };
|
|
338
|
+
new Intl.DateTimeFormat("en-CA", { timeZone: o.tz || DEFAULT_TZ });
|
|
339
|
+
}
|
|
340
|
+
catch (e) {
|
|
341
|
+
err.write(`temmo: ${e.message}\n${USAGE}\n`);
|
|
342
|
+
return 2;
|
|
343
|
+
}
|
|
344
|
+
const home = env.HOME || homedir();
|
|
345
|
+
const tz = o.tz || DEFAULT_TZ;
|
|
346
|
+
const sources = io.sources || [claudeSource({ home }), codexSource({ home }), opencodeSource({ home }), cursorSource({ home }), journalSource({ run: io.journal }), taskStoreSource({ home })];
|
|
347
|
+
const turns = [];
|
|
348
|
+
const scheduleRuns = [];
|
|
349
|
+
let tasks = null;
|
|
350
|
+
const notes = [];
|
|
351
|
+
for (const s of sources) {
|
|
352
|
+
let r;
|
|
353
|
+
try {
|
|
354
|
+
r = await s.load(win);
|
|
355
|
+
}
|
|
356
|
+
catch (e) {
|
|
357
|
+
notes.push(`source ${s.name} failed: ${e.message}`);
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
turns.push(...(r.turns || []));
|
|
361
|
+
scheduleRuns.push(...(r.scheduleRuns || []));
|
|
362
|
+
if (r.tasks)
|
|
363
|
+
tasks = r.tasks;
|
|
364
|
+
for (const x of r.notes || [])
|
|
365
|
+
if (!notes.includes(x))
|
|
366
|
+
notes.push(x);
|
|
367
|
+
}
|
|
368
|
+
const pmLabels = pmLabelsOf(env.TEMMO_SCHEDULES || join(configDir(env), "schedules.json"));
|
|
369
|
+
const ctx = { cut, tz, pmLabels, selectors };
|
|
370
|
+
const rows = aggregate(turns, ctx);
|
|
371
|
+
const generated = new Date().toISOString().slice(0, 10);
|
|
372
|
+
const md = renderReport(rows, { ...ctx, ...win, scheduleRuns, tasks, notes, generated, latest: turns.reduce((m, t) => Math.max(m, t.ts), 0) || null, sources: sources.map((s) => s.name) });
|
|
373
|
+
const file = o.out || join("docs/research", `run-code-impact-${generated}.md`);
|
|
374
|
+
if (file === "-")
|
|
375
|
+
out.write(md);
|
|
376
|
+
else {
|
|
377
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
378
|
+
writeFileSync(file, md);
|
|
379
|
+
err.write(`temmo: wrote ${file}\n`);
|
|
380
|
+
}
|
|
381
|
+
if (o.jsonl) {
|
|
382
|
+
mkdirSync(dirname(o.jsonl), { recursive: true });
|
|
383
|
+
writeFileSync(o.jsonl, rows.map((r) => JSON.stringify(r)).join("\n") + (rows.length ? "\n" : ""));
|
|
384
|
+
err.write(`temmo: wrote ${o.jsonl} (${rows.length} rows)\n`);
|
|
385
|
+
}
|
|
386
|
+
if (o["otlp-export"]) {
|
|
387
|
+
try {
|
|
388
|
+
const sent = await exportOtlp(annotate(turns, ctx), o["otlp-export"], { project: o["phoenix-project"] });
|
|
389
|
+
err.write(`temmo: exported ${sent} spans to ${o["otlp-export"]}\n`);
|
|
390
|
+
}
|
|
391
|
+
catch (e) {
|
|
392
|
+
err.write(`temmo: ${e.message}\n`);
|
|
393
|
+
return 1;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return 0;
|
|
397
|
+
}
|