@memnexus-ai/mx-agent-cli 0.1.294 → 0.1.295-next.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/dist/__tests__/agents-md-canonicalization.test.js +31 -1
- package/dist/__tests__/agents-md-canonicalization.test.js.map +1 -1
- package/dist/__tests__/behavioral-extraction.test.js +50 -0
- package/dist/__tests__/behavioral-extraction.test.js.map +1 -1
- package/dist/__tests__/bootstrap-behavioral-contract.test.js +6 -3
- package/dist/__tests__/bootstrap-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/bundle-config.test.js +28 -2
- package/dist/__tests__/bundle-config.test.js.map +1 -1
- package/dist/__tests__/catalog-interaction.test.d.ts +25 -0
- package/dist/__tests__/catalog-interaction.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-interaction.test.js +269 -0
- package/dist/__tests__/catalog-interaction.test.js.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts +2 -0
- package/dist/__tests__/catalog-named-memories.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-named-memories.test.js +204 -0
- package/dist/__tests__/catalog-named-memories.test.js.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts +15 -0
- package/dist/__tests__/catalog-origin-main.test.d.ts.map +1 -0
- package/dist/__tests__/catalog-origin-main.test.js +296 -0
- package/dist/__tests__/catalog-origin-main.test.js.map +1 -0
- package/dist/__tests__/catalog.test.d.ts +2 -0
- package/dist/__tests__/catalog.test.d.ts.map +1 -0
- package/dist/__tests__/catalog.test.js +131 -0
- package/dist/__tests__/catalog.test.js.map +1 -0
- package/dist/__tests__/cli-build-integration.test.d.ts +2 -0
- package/dist/__tests__/cli-build-integration.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build-integration.test.js +64 -0
- package/dist/__tests__/cli-build-integration.test.js.map +1 -0
- package/dist/__tests__/cli-build.test.d.ts +2 -0
- package/dist/__tests__/cli-build.test.d.ts.map +1 -0
- package/dist/__tests__/cli-build.test.js +640 -0
- package/dist/__tests__/cli-build.test.js.map +1 -0
- package/dist/__tests__/codex-deploy-config.test.js +60 -0
- package/dist/__tests__/codex-deploy-config.test.js.map +1 -1
- package/dist/__tests__/completion-rows-discriminate.test.d.ts +20 -0
- package/dist/__tests__/completion-rows-discriminate.test.d.ts.map +1 -0
- package/dist/__tests__/completion-rows-discriminate.test.js +481 -0
- package/dist/__tests__/completion-rows-discriminate.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js +127 -0
- package/dist/__tests__/config-fidelity-archived-symlinks.test.js.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts +2 -0
- package/dist/__tests__/config-fidelity-display.test.d.ts.map +1 -0
- package/dist/__tests__/config-fidelity-display.test.js +77 -0
- package/dist/__tests__/config-fidelity-display.test.js.map +1 -0
- package/dist/__tests__/config-fidelity.test.js +166 -33
- package/dist/__tests__/config-fidelity.test.js.map +1 -1
- package/dist/__tests__/config-generation-gate.test.js +78 -0
- package/dist/__tests__/config-generation-gate.test.js.map +1 -1
- package/dist/__tests__/config-sync.test.js +89 -1
- package/dist/__tests__/config-sync.test.js.map +1 -1
- package/dist/__tests__/coordination-401-production-wiring.test.js +12 -7
- package/dist/__tests__/coordination-401-production-wiring.test.js.map +1 -1
- package/dist/__tests__/coordination-401-recovery.test.js +39 -32
- package/dist/__tests__/coordination-401-recovery.test.js.map +1 -1
- package/dist/__tests__/coordination-brief-pin.test.js +21 -8
- package/dist/__tests__/coordination-brief-pin.test.js.map +1 -1
- package/dist/__tests__/coordination-client.test.js +227 -3
- package/dist/__tests__/coordination-client.test.js.map +1 -1
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts +24 -0
- package/dist/__tests__/coordination-credential-endpoint.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js +1230 -0
- package/dist/__tests__/coordination-credential-endpoint.test.js.map +1 -0
- package/dist/__tests__/coordination-memory.test.js +20 -4
- package/dist/__tests__/coordination-memory.test.js.map +1 -1
- package/dist/__tests__/coordination-provision.test.js +22 -14
- package/dist/__tests__/coordination-provision.test.js.map +1 -1
- package/dist/__tests__/coordination-status-registration.test.d.ts +16 -0
- package/dist/__tests__/coordination-status-registration.test.d.ts.map +1 -0
- package/dist/__tests__/coordination-status-registration.test.js +480 -0
- package/dist/__tests__/coordination-status-registration.test.js.map +1 -0
- package/dist/__tests__/coordination-token-multitenant.test.js +11 -11
- package/dist/__tests__/coordination-token-multitenant.test.js.map +1 -1
- package/dist/__tests__/coordination-token.test.js +35 -28
- package/dist/__tests__/coordination-token.test.js.map +1 -1
- package/dist/__tests__/creation-pr-class-check.test.d.ts +17 -0
- package/dist/__tests__/creation-pr-class-check.test.d.ts.map +1 -0
- package/dist/__tests__/creation-pr-class-check.test.js +346 -0
- package/dist/__tests__/creation-pr-class-check.test.js.map +1 -0
- package/dist/__tests__/decision-check.test.d.ts +2 -0
- package/dist/__tests__/decision-check.test.d.ts.map +1 -0
- package/dist/__tests__/decision-check.test.js +105 -0
- package/dist/__tests__/decision-check.test.js.map +1 -0
- package/dist/__tests__/digest-team-omission.test.d.ts +15 -0
- package/dist/__tests__/digest-team-omission.test.d.ts.map +1 -0
- package/dist/__tests__/digest-team-omission.test.js +247 -0
- package/dist/__tests__/digest-team-omission.test.js.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts +17 -0
- package/dist/__tests__/doctor-worktree-path.test.d.ts.map +1 -0
- package/dist/__tests__/doctor-worktree-path.test.js +158 -0
- package/dist/__tests__/doctor-worktree-path.test.js.map +1 -0
- package/dist/__tests__/fleet-data.test.js +40 -7
- package/dist/__tests__/fleet-data.test.js.map +1 -1
- package/dist/__tests__/fleet-tmux.test.js +2 -2
- package/dist/__tests__/fleet-tmux.test.js.map +1 -1
- package/dist/__tests__/generate-claude.test.js +137 -3
- package/dist/__tests__/generate-claude.test.js.map +1 -1
- package/dist/__tests__/git-env.test.d.ts +14 -0
- package/dist/__tests__/git-env.test.d.ts.map +1 -0
- package/dist/__tests__/git-env.test.js +131 -0
- package/dist/__tests__/git-env.test.js.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts +33 -0
- package/dist/__tests__/git-identity-isolation.test.d.ts.map +1 -0
- package/dist/__tests__/git-identity-isolation.test.js +626 -0
- package/dist/__tests__/git-identity-isolation.test.js.map +1 -0
- package/dist/__tests__/harness-extract.test.d.ts +19 -0
- package/dist/__tests__/harness-extract.test.d.ts.map +1 -0
- package/dist/__tests__/harness-extract.test.js +566 -0
- package/dist/__tests__/harness-extract.test.js.map +1 -0
- package/dist/__tests__/harness-wiring.test.d.ts +16 -0
- package/dist/__tests__/harness-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/harness-wiring.test.js +469 -0
- package/dist/__tests__/harness-wiring.test.js.map +1 -0
- package/dist/__tests__/hook-heal.test.js +17 -0
- package/dist/__tests__/hook-heal.test.js.map +1 -1
- package/dist/__tests__/init-coordination-url.test.d.ts +11 -0
- package/dist/__tests__/init-coordination-url.test.d.ts.map +1 -0
- package/dist/__tests__/init-coordination-url.test.js +114 -0
- package/dist/__tests__/init-coordination-url.test.js.map +1 -0
- package/dist/__tests__/memory-autocreate.test.js +574 -8
- package/dist/__tests__/memory-autocreate.test.js.map +1 -1
- package/dist/__tests__/memory-log-result.test.d.ts +13 -0
- package/dist/__tests__/memory-log-result.test.d.ts.map +1 -0
- package/dist/__tests__/memory-log-result.test.js +113 -0
- package/dist/__tests__/memory-log-result.test.js.map +1 -0
- package/dist/__tests__/memory-named-exists.test.d.ts +16 -0
- package/dist/__tests__/memory-named-exists.test.d.ts.map +1 -0
- package/dist/__tests__/memory-named-exists.test.js +288 -0
- package/dist/__tests__/memory-named-exists.test.js.map +1 -0
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js +23 -47
- package/dist/__tests__/mx-agent-cli-pin-validation.test.js.map +1 -1
- package/dist/__tests__/mx-agent-cli-version-pin.test.js +34 -88
- package/dist/__tests__/mx-agent-cli-version-pin.test.js.map +1 -1
- package/dist/__tests__/new-project-first-team.test.d.ts +15 -0
- package/dist/__tests__/new-project-first-team.test.d.ts.map +1 -0
- package/dist/__tests__/new-project-first-team.test.js +263 -0
- package/dist/__tests__/new-project-first-team.test.js.map +1 -0
- package/dist/__tests__/otel-env.test.d.ts +2 -0
- package/dist/__tests__/otel-env.test.d.ts.map +1 -0
- package/dist/__tests__/otel-env.test.js +127 -0
- package/dist/__tests__/otel-env.test.js.map +1 -0
- package/dist/__tests__/project-config.test.js +283 -1
- package/dist/__tests__/project-config.test.js.map +1 -1
- package/dist/__tests__/provision-behavioral-contract.test.js +96 -4
- package/dist/__tests__/provision-behavioral-contract.test.js.map +1 -1
- package/dist/__tests__/provision-catalog-precondition.test.d.ts +26 -0
- package/dist/__tests__/provision-catalog-precondition.test.d.ts.map +1 -0
- package/dist/__tests__/provision-catalog-precondition.test.js +620 -0
- package/dist/__tests__/provision-catalog-precondition.test.js.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts +17 -0
- package/dist/__tests__/provision-completion-rows.test.d.ts.map +1 -0
- package/dist/__tests__/provision-completion-rows.test.js +3095 -0
- package/dist/__tests__/provision-completion-rows.test.js.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts +20 -0
- package/dist/__tests__/provision-identity-gate.test.d.ts.map +1 -0
- package/dist/__tests__/provision-identity-gate.test.js +600 -0
- package/dist/__tests__/provision-identity-gate.test.js.map +1 -0
- package/dist/__tests__/provision-resume.test.d.ts +26 -0
- package/dist/__tests__/provision-resume.test.d.ts.map +1 -0
- package/dist/__tests__/provision-resume.test.js +1164 -0
- package/dist/__tests__/provision-resume.test.js.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts +27 -0
- package/dist/__tests__/provision-roleguide-anchors.test.d.ts.map +1 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js +747 -0
- package/dist/__tests__/provision-roleguide-anchors.test.js.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts +16 -0
- package/dist/__tests__/provision-skeleton-fill.test.d.ts.map +1 -0
- package/dist/__tests__/provision-skeleton-fill.test.js +488 -0
- package/dist/__tests__/provision-skeleton-fill.test.js.map +1 -0
- package/dist/__tests__/provision-teambuilder-flow.test.js +93 -7
- package/dist/__tests__/provision-teambuilder-flow.test.js.map +1 -1
- package/dist/__tests__/repo-guard-wiring.test.d.ts +21 -0
- package/dist/__tests__/repo-guard-wiring.test.d.ts.map +1 -0
- package/dist/__tests__/repo-guard-wiring.test.js +638 -0
- package/dist/__tests__/repo-guard-wiring.test.js.map +1 -0
- package/dist/__tests__/report-format.test.d.ts +2 -0
- package/dist/__tests__/report-format.test.d.ts.map +1 -0
- package/dist/__tests__/report-format.test.js +219 -0
- package/dist/__tests__/report-format.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js +309 -0
- package/dist/__tests__/runtime-codex-gateway-pilot.test.js.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts +2 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js +163 -0
- package/dist/__tests__/runtime-codex-gateway-provider.test.js.map +1 -0
- package/dist/__tests__/runtime-identity.test.d.ts +2 -0
- package/dist/__tests__/runtime-identity.test.d.ts.map +1 -0
- package/dist/__tests__/runtime-identity.test.js +117 -0
- package/dist/__tests__/runtime-identity.test.js.map +1 -0
- package/dist/__tests__/session-pause-provisioning.test.js +6 -1
- package/dist/__tests__/session-pause-provisioning.test.js.map +1 -1
- package/dist/__tests__/session-record-disclosure.test.d.ts +24 -0
- package/dist/__tests__/session-record-disclosure.test.d.ts.map +1 -0
- package/dist/__tests__/session-record-disclosure.test.js +494 -0
- package/dist/__tests__/session-record-disclosure.test.js.map +1 -0
- package/dist/__tests__/session.test.js +35 -0
- package/dist/__tests__/session.test.js.map +1 -1
- package/dist/__tests__/slug-validation.test.js +27 -21
- package/dist/__tests__/slug-validation.test.js.map +1 -1
- package/dist/__tests__/standards-injection.test.d.ts +2 -0
- package/dist/__tests__/standards-injection.test.d.ts.map +1 -0
- package/dist/__tests__/standards-injection.test.js +179 -0
- package/dist/__tests__/standards-injection.test.js.map +1 -0
- package/dist/__tests__/start-interactive-role.test.d.ts +22 -0
- package/dist/__tests__/start-interactive-role.test.d.ts.map +1 -0
- package/dist/__tests__/start-interactive-role.test.js +204 -0
- package/dist/__tests__/start-interactive-role.test.js.map +1 -0
- package/dist/__tests__/start-team-identity.test.d.ts +25 -0
- package/dist/__tests__/start-team-identity.test.d.ts.map +1 -0
- package/dist/__tests__/start-team-identity.test.js +307 -0
- package/dist/__tests__/start-team-identity.test.js.map +1 -0
- package/dist/__tests__/team-memory-commands.test.js +142 -19
- package/dist/__tests__/team-memory-commands.test.js.map +1 -1
- package/dist/__tests__/template-sync.test.d.ts +19 -0
- package/dist/__tests__/template-sync.test.d.ts.map +1 -0
- package/dist/__tests__/template-sync.test.js +270 -0
- package/dist/__tests__/template-sync.test.js.map +1 -0
- package/dist/__tests__/test-project.test.d.ts +18 -0
- package/dist/__tests__/test-project.test.d.ts.map +1 -0
- package/dist/__tests__/test-project.test.js +465 -0
- package/dist/__tests__/test-project.test.js.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts +25 -0
- package/dist/__tests__/usage-per-call-grouping.test.d.ts.map +1 -0
- package/dist/__tests__/usage-per-call-grouping.test.js +952 -0
- package/dist/__tests__/usage-per-call-grouping.test.js.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts +32 -0
- package/dist/__tests__/verify-hooks-check-all.test.d.ts.map +1 -0
- package/dist/__tests__/verify-hooks-check-all.test.js +553 -0
- package/dist/__tests__/verify-hooks-check-all.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts +17 -0
- package/dist/__tests__/worktree-sync-fixture.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-fixture.test.js +519 -0
- package/dist/__tests__/worktree-sync-fixture.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts +13 -0
- package/dist/__tests__/worktree-sync-hardening.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-hardening.test.js +919 -0
- package/dist/__tests__/worktree-sync-hardening.test.js.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts +25 -0
- package/dist/__tests__/worktree-sync-shell-free.test.d.ts.map +1 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js +185 -0
- package/dist/__tests__/worktree-sync-shell-free.test.js.map +1 -0
- package/dist/__tests__/worktree.test.js +75 -1
- package/dist/__tests__/worktree.test.js.map +1 -1
- package/dist/agent-config/.mx-config-generation.json +2 -2
- package/dist/agent-config/AGENTS.md.template +2 -2
- package/dist/agent-config/agents/bar-raiser.md +34 -1
- package/dist/agent-config/agents/red-team.md +34 -1
- package/dist/agent-config/agents/security-reviewer.md +22 -1
- package/dist/agent-config/claude-md/CLAUDE.core.md +6 -1
- package/dist/agent-config/claude-md/CLAUDE.overlay.memnexus.md +1 -3
- package/dist/agent-config/coordination-rosters.generated.json +10 -0
- package/dist/agent-config/hooks/HOOK-TIMEOUTS.md +27 -1
- package/dist/agent-config/hooks/OR-TRUE-AUDIT.md +8 -8
- package/dist/agent-config/hooks/auto-capture-precompact.sh +180 -83
- package/dist/agent-config/hooks/auto-capture-session-end.sh +216 -87
- package/dist/agent-config/hooks/auto-checkpoint.sh +75 -5
- package/dist/agent-config/hooks/coordination-brief.sh +290 -245
- package/dist/agent-config/hooks/deploy-verification-reminder.sh +359 -22
- package/dist/agent-config/hooks/git-mutation-guard.sh +85 -13
- package/dist/agent-config/hooks/observability-sync.sh +46 -9
- package/dist/agent-config/hooks/session-idle-gate.sh +177 -12
- package/dist/agent-config/hooks/subagent-write-guard.sh +670 -0
- package/dist/agent-config/hooks/worktree-guard.sh +36 -7
- package/dist/agent-config/settings.json +15 -2
- package/dist/agent-config/shared/creation-pr-review-checklist.md +317 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +22 -10
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/config-sync.d.ts +37 -0
- package/dist/commands/config-sync.d.ts.map +1 -1
- package/dist/commands/config-sync.js +36 -18
- package/dist/commands/config-sync.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +28 -1
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/coordination.d.ts +150 -8
- package/dist/commands/coordination.d.ts.map +1 -1
- package/dist/commands/coordination.js +519 -25
- package/dist/commands/coordination.js.map +1 -1
- package/dist/commands/create.d.ts +913 -1
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +4879 -345
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/dashboard.d.ts.map +1 -1
- package/dist/commands/dashboard.js +10 -2
- package/dist/commands/dashboard.js.map +1 -1
- package/dist/commands/decision.d.ts +20 -0
- package/dist/commands/decision.d.ts.map +1 -0
- package/dist/commands/decision.js +54 -0
- package/dist/commands/decision.js.map +1 -0
- package/dist/commands/digest.d.ts.map +1 -1
- package/dist/commands/digest.js +91 -7
- package/dist/commands/digest.js.map +1 -1
- package/dist/commands/fleet-tmux.js +1 -1
- package/dist/commands/fleet-tmux.js.map +1 -1
- package/dist/commands/init.d.ts +8 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +26 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/list.d.ts +32 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +98 -5
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/monitor.d.ts.map +1 -1
- package/dist/commands/monitor.js +8 -2
- package/dist/commands/monitor.js.map +1 -1
- package/dist/commands/new.d.ts +2 -0
- package/dist/commands/new.d.ts.map +1 -1
- package/dist/commands/new.js +114 -21
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/report.d.ts +33 -0
- package/dist/commands/report.d.ts.map +1 -0
- package/dist/commands/report.js +73 -0
- package/dist/commands/report.js.map +1 -0
- package/dist/commands/session.js +1 -1
- package/dist/commands/session.js.map +1 -1
- package/dist/commands/start.d.ts +42 -0
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +177 -8
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/sync.d.ts +57 -0
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +117 -3
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/update.d.ts +13 -1
- package/dist/commands/update.d.ts.map +1 -1
- package/dist/commands/update.js +50 -1
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/usage.d.ts +64 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +96 -3
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/verify-hooks.d.ts +37 -1
- package/dist/commands/verify-hooks.d.ts.map +1 -1
- package/dist/commands/verify-hooks.js +114 -2
- package/dist/commands/verify-hooks.js.map +1 -1
- package/dist/commands/window.d.ts +10 -0
- package/dist/commands/window.d.ts.map +1 -0
- package/dist/commands/window.js +265 -0
- package/dist/commands/window.js.map +1 -0
- package/dist/commands/worktree-sync.d.ts +54 -0
- package/dist/commands/worktree-sync.d.ts.map +1 -0
- package/dist/commands/worktree-sync.js +135 -0
- package/dist/commands/worktree-sync.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +189 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/agent-session.d.ts +12 -0
- package/dist/lib/agent-session.d.ts.map +1 -1
- package/dist/lib/agent-session.js +189 -42
- package/dist/lib/agent-session.js.map +1 -1
- package/dist/lib/catalog.d.ts +321 -2
- package/dist/lib/catalog.d.ts.map +1 -1
- package/dist/lib/catalog.js +490 -11
- package/dist/lib/catalog.js.map +1 -1
- package/dist/lib/claude.d.ts +65 -23
- package/dist/lib/claude.d.ts.map +1 -1
- package/dist/lib/claude.js +335 -19
- package/dist/lib/claude.js.map +1 -1
- package/dist/lib/cli-build.d.ts +172 -0
- package/dist/lib/cli-build.d.ts.map +1 -0
- package/dist/lib/cli-build.js +654 -0
- package/dist/lib/cli-build.js.map +1 -0
- package/dist/lib/code-context-file.d.ts +109 -0
- package/dist/lib/code-context-file.d.ts.map +1 -0
- package/dist/lib/code-context-file.js +219 -0
- package/dist/lib/code-context-file.js.map +1 -0
- package/dist/lib/code-context-file.test.d.ts +19 -0
- package/dist/lib/code-context-file.test.d.ts.map +1 -0
- package/dist/lib/code-context-file.test.js +202 -0
- package/dist/lib/code-context-file.test.js.map +1 -0
- package/dist/lib/config-fidelity.d.ts +40 -20
- package/dist/lib/config-fidelity.d.ts.map +1 -1
- package/dist/lib/config-fidelity.js +144 -56
- package/dist/lib/config-fidelity.js.map +1 -1
- package/dist/lib/coordination-client.d.ts +73 -0
- package/dist/lib/coordination-client.d.ts.map +1 -1
- package/dist/lib/coordination-client.js +180 -8
- package/dist/lib/coordination-client.js.map +1 -1
- package/dist/lib/coordination-token.d.ts +304 -6
- package/dist/lib/coordination-token.d.ts.map +1 -1
- package/dist/lib/coordination-token.js +851 -52
- package/dist/lib/coordination-token.js.map +1 -1
- package/dist/lib/decision-check.d.ts +48 -0
- package/dist/lib/decision-check.d.ts.map +1 -0
- package/dist/lib/decision-check.js +149 -0
- package/dist/lib/decision-check.js.map +1 -0
- package/dist/lib/fleet-data.d.ts +34 -0
- package/dist/lib/fleet-data.d.ts.map +1 -1
- package/dist/lib/fleet-data.js +37 -9
- package/dist/lib/fleet-data.js.map +1 -1
- package/dist/lib/fleet-render.js +1 -1
- package/dist/lib/fleet-render.js.map +1 -1
- package/dist/lib/git-identity.d.ts +302 -0
- package/dist/lib/git-identity.d.ts.map +1 -0
- package/dist/lib/git-identity.js +546 -0
- package/dist/lib/git-identity.js.map +1 -0
- package/dist/lib/harness/console/announce.d.ts +45 -0
- package/dist/lib/harness/console/announce.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.js +48 -0
- package/dist/lib/harness/console/announce.js.map +1 -0
- package/dist/lib/harness/console/announce.test.d.ts +2 -0
- package/dist/lib/harness/console/announce.test.d.ts.map +1 -0
- package/dist/lib/harness/console/announce.test.js +104 -0
- package/dist/lib/harness/console/announce.test.js.map +1 -0
- package/dist/lib/harness/console/by-session.d.ts +50 -0
- package/dist/lib/harness/console/by-session.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.js +83 -0
- package/dist/lib/harness/console/by-session.js.map +1 -0
- package/dist/lib/harness/console/by-session.test.d.ts +2 -0
- package/dist/lib/harness/console/by-session.test.d.ts.map +1 -0
- package/dist/lib/harness/console/by-session.test.js +86 -0
- package/dist/lib/harness/console/by-session.test.js.map +1 -0
- package/dist/lib/harness/console/console.d.ts +67 -0
- package/dist/lib/harness/console/console.d.ts.map +1 -0
- package/dist/lib/harness/console/console.js +373 -0
- package/dist/lib/harness/console/console.js.map +1 -0
- package/dist/lib/harness/console/console.test.d.ts +2 -0
- package/dist/lib/harness/console/console.test.d.ts.map +1 -0
- package/dist/lib/harness/console/console.test.js +269 -0
- package/dist/lib/harness/console/console.test.js.map +1 -0
- package/dist/lib/harness/console/decision-request.d.ts +32 -0
- package/dist/lib/harness/console/decision-request.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.js +112 -0
- package/dist/lib/harness/console/decision-request.js.map +1 -0
- package/dist/lib/harness/console/decision-request.test.d.ts +2 -0
- package/dist/lib/harness/console/decision-request.test.d.ts.map +1 -0
- package/dist/lib/harness/console/decision-request.test.js +75 -0
- package/dist/lib/harness/console/decision-request.test.js.map +1 -0
- package/dist/lib/harness/console/fixtures.d.ts +16 -0
- package/dist/lib/harness/console/fixtures.d.ts.map +1 -0
- package/dist/lib/harness/console/fixtures.js +49 -0
- package/dist/lib/harness/console/fixtures.js.map +1 -0
- package/dist/lib/harness/console/index.d.ts +15 -0
- package/dist/lib/harness/console/index.d.ts.map +1 -0
- package/dist/lib/harness/console/index.js +14 -0
- package/dist/lib/harness/console/index.js.map +1 -0
- package/dist/lib/harness/console/rank.d.ts +73 -0
- package/dist/lib/harness/console/rank.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.js +113 -0
- package/dist/lib/harness/console/rank.js.map +1 -0
- package/dist/lib/harness/console/rank.test.d.ts +2 -0
- package/dist/lib/harness/console/rank.test.d.ts.map +1 -0
- package/dist/lib/harness/console/rank.test.js +124 -0
- package/dist/lib/harness/console/rank.test.js.map +1 -0
- package/dist/lib/harness/console/render.d.ts +22 -0
- package/dist/lib/harness/console/render.d.ts.map +1 -0
- package/dist/lib/harness/console/render.js +65 -0
- package/dist/lib/harness/console/render.js.map +1 -0
- package/dist/lib/harness/console/render.test.d.ts +2 -0
- package/dist/lib/harness/console/render.test.d.ts.map +1 -0
- package/dist/lib/harness/console/render.test.js +96 -0
- package/dist/lib/harness/console/render.test.js.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts +2 -0
- package/dist/lib/harness/console/replay-cli.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay-cli.test.js +96 -0
- package/dist/lib/harness/console/replay-cli.test.js.map +1 -0
- package/dist/lib/harness/console/replay.d.ts +36 -0
- package/dist/lib/harness/console/replay.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.js +59 -0
- package/dist/lib/harness/console/replay.js.map +1 -0
- package/dist/lib/harness/console/replay.test.d.ts +2 -0
- package/dist/lib/harness/console/replay.test.d.ts.map +1 -0
- package/dist/lib/harness/console/replay.test.js +81 -0
- package/dist/lib/harness/console/replay.test.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.d.ts +50 -0
- package/dist/lib/harness/console/turn-reader.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.js +184 -0
- package/dist/lib/harness/console/turn-reader.js.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts +2 -0
- package/dist/lib/harness/console/turn-reader.test.d.ts.map +1 -0
- package/dist/lib/harness/console/turn-reader.test.js +108 -0
- package/dist/lib/harness/console/turn-reader.test.js.map +1 -0
- package/dist/lib/harness/console/types.d.ts +109 -0
- package/dist/lib/harness/console/types.d.ts.map +1 -0
- package/dist/lib/harness/console/types.js +2 -0
- package/dist/lib/harness/console/types.js.map +1 -0
- package/dist/lib/harness/contract.d.ts +229 -0
- package/dist/lib/harness/contract.d.ts.map +1 -0
- package/dist/lib/harness/contract.js +22 -0
- package/dist/lib/harness/contract.js.map +1 -0
- package/dist/lib/harness/credential.d.ts +23 -0
- package/dist/lib/harness/credential.d.ts.map +1 -0
- package/dist/lib/harness/credential.js +81 -0
- package/dist/lib/harness/credential.js.map +1 -0
- package/dist/lib/harness/credential.test.d.ts +2 -0
- package/dist/lib/harness/credential.test.d.ts.map +1 -0
- package/dist/lib/harness/credential.test.js +74 -0
- package/dist/lib/harness/credential.test.js.map +1 -0
- package/dist/lib/harness/evaluate.d.ts +390 -0
- package/dist/lib/harness/evaluate.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.js +988 -0
- package/dist/lib/harness/evaluate.js.map +1 -0
- package/dist/lib/harness/evaluate.test.d.ts +2 -0
- package/dist/lib/harness/evaluate.test.d.ts.map +1 -0
- package/dist/lib/harness/evaluate.test.js +621 -0
- package/dist/lib/harness/evaluate.test.js.map +1 -0
- package/dist/lib/harness/extract.d.ts +152 -0
- package/dist/lib/harness/extract.d.ts.map +1 -0
- package/dist/lib/harness/extract.js +1601 -0
- package/dist/lib/harness/extract.js.map +1 -0
- package/dist/lib/harness/gate.d.ts +48 -0
- package/dist/lib/harness/gate.d.ts.map +1 -0
- package/dist/lib/harness/gate.js +60 -0
- package/dist/lib/harness/gate.js.map +1 -0
- package/dist/lib/harness/gate.test.d.ts +2 -0
- package/dist/lib/harness/gate.test.d.ts.map +1 -0
- package/dist/lib/harness/gate.test.js +111 -0
- package/dist/lib/harness/gate.test.js.map +1 -0
- package/dist/lib/harness/self-check.d.ts +59 -0
- package/dist/lib/harness/self-check.d.ts.map +1 -0
- package/dist/lib/harness/self-check.js +56 -0
- package/dist/lib/harness/self-check.js.map +1 -0
- package/dist/lib/harness/self-check.test.d.ts +2 -0
- package/dist/lib/harness/self-check.test.d.ts.map +1 -0
- package/dist/lib/harness/self-check.test.js +43 -0
- package/dist/lib/harness/self-check.test.js.map +1 -0
- package/dist/lib/harness/transcript.d.ts +65 -0
- package/dist/lib/harness/transcript.d.ts.map +1 -0
- package/dist/lib/harness/transcript.js +144 -0
- package/dist/lib/harness/transcript.js.map +1 -0
- package/dist/lib/harness/transcript.test.d.ts +2 -0
- package/dist/lib/harness/transcript.test.d.ts.map +1 -0
- package/dist/lib/harness/transcript.test.js +118 -0
- package/dist/lib/harness/transcript.test.js.map +1 -0
- package/dist/lib/harness-wiring.d.ts +145 -0
- package/dist/lib/harness-wiring.d.ts.map +1 -0
- package/dist/lib/harness-wiring.js +280 -0
- package/dist/lib/harness-wiring.js.map +1 -0
- package/dist/lib/hook-staleness.d.ts +95 -0
- package/dist/lib/hook-staleness.d.ts.map +1 -0
- package/dist/lib/hook-staleness.js +304 -0
- package/dist/lib/hook-staleness.js.map +1 -0
- package/dist/lib/jsonl.d.ts +270 -2
- package/dist/lib/jsonl.d.ts.map +1 -1
- package/dist/lib/jsonl.js +472 -76
- package/dist/lib/jsonl.js.map +1 -1
- package/dist/lib/memory.d.ts +350 -23
- package/dist/lib/memory.d.ts.map +1 -1
- package/dist/lib/memory.js +751 -38
- package/dist/lib/memory.js.map +1 -1
- package/dist/lib/otel-env.d.ts +90 -0
- package/dist/lib/otel-env.d.ts.map +1 -0
- package/dist/lib/otel-env.js +98 -0
- package/dist/lib/otel-env.js.map +1 -0
- package/dist/lib/project-config.d.ts +167 -0
- package/dist/lib/project-config.d.ts.map +1 -1
- package/dist/lib/project-config.js +321 -5
- package/dist/lib/project-config.js.map +1 -1
- package/dist/lib/projects-registry.d.ts +82 -0
- package/dist/lib/projects-registry.d.ts.map +1 -0
- package/dist/lib/projects-registry.js +145 -0
- package/dist/lib/projects-registry.js.map +1 -0
- package/dist/lib/projects-registry.test.d.ts +2 -0
- package/dist/lib/projects-registry.test.d.ts.map +1 -0
- package/dist/lib/projects-registry.test.js +176 -0
- package/dist/lib/projects-registry.test.js.map +1 -0
- package/dist/lib/repo-guard-scope.d.ts +126 -0
- package/dist/lib/repo-guard-scope.d.ts.map +1 -0
- package/dist/lib/repo-guard-scope.js +249 -0
- package/dist/lib/repo-guard-scope.js.map +1 -0
- package/dist/lib/report-format.d.ts +132 -0
- package/dist/lib/report-format.d.ts.map +1 -0
- package/dist/lib/report-format.js +317 -0
- package/dist/lib/report-format.js.map +1 -0
- package/dist/lib/roster.d.ts +87 -0
- package/dist/lib/roster.d.ts.map +1 -0
- package/dist/lib/roster.js +332 -0
- package/dist/lib/roster.js.map +1 -0
- package/dist/lib/roster.test.d.ts +15 -0
- package/dist/lib/roster.test.d.ts.map +1 -0
- package/dist/lib/roster.test.js +299 -0
- package/dist/lib/roster.test.js.map +1 -0
- package/dist/lib/runtime/codex-adapter.d.ts.map +1 -1
- package/dist/lib/runtime/codex-adapter.js +5 -0
- package/dist/lib/runtime/codex-adapter.js.map +1 -1
- package/dist/lib/runtime/codex-config.d.ts +129 -0
- package/dist/lib/runtime/codex-config.d.ts.map +1 -1
- package/dist/lib/runtime/codex-config.js +225 -0
- package/dist/lib/runtime/codex-config.js.map +1 -1
- package/dist/lib/runtime/identity.d.ts +72 -0
- package/dist/lib/runtime/identity.d.ts.map +1 -0
- package/dist/lib/runtime/identity.js +128 -0
- package/dist/lib/runtime/identity.js.map +1 -0
- package/dist/lib/standards.d.ts +99 -0
- package/dist/lib/standards.d.ts.map +1 -0
- package/dist/lib/standards.js +201 -0
- package/dist/lib/standards.js.map +1 -0
- package/dist/lib/team-identity.d.ts +134 -0
- package/dist/lib/team-identity.d.ts.map +1 -0
- package/dist/lib/team-identity.js +193 -0
- package/dist/lib/team-identity.js.map +1 -0
- package/dist/lib/templates.d.ts +29 -2
- package/dist/lib/templates.d.ts.map +1 -1
- package/dist/lib/templates.js +1042 -82
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/terminal-ui.d.ts.map +1 -1
- package/dist/lib/terminal-ui.js +12 -1
- package/dist/lib/terminal-ui.js.map +1 -1
- package/dist/lib/test-project.d.ts +95 -0
- package/dist/lib/test-project.d.ts.map +1 -0
- package/dist/lib/test-project.js +103 -0
- package/dist/lib/test-project.js.map +1 -0
- package/dist/lib/vault.d.ts +60 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +102 -0
- package/dist/lib/vault.js.map +1 -0
- package/dist/lib/vault.test.d.ts +17 -0
- package/dist/lib/vault.test.d.ts.map +1 -0
- package/dist/lib/vault.test.js +169 -0
- package/dist/lib/vault.test.js.map +1 -0
- package/dist/lib/window-view.d.ts +63 -0
- package/dist/lib/window-view.d.ts.map +1 -0
- package/dist/lib/window-view.js +217 -0
- package/dist/lib/window-view.js.map +1 -0
- package/dist/lib/window-view.test.d.ts +2 -0
- package/dist/lib/window-view.test.d.ts.map +1 -0
- package/dist/lib/window-view.test.js +168 -0
- package/dist/lib/window-view.test.js.map +1 -0
- package/dist/lib/worktree-sync.d.ts +439 -0
- package/dist/lib/worktree-sync.d.ts.map +1 -0
- package/dist/lib/worktree-sync.js +1167 -0
- package/dist/lib/worktree-sync.js.map +1 -0
- package/dist/lib/worktree.d.ts +58 -1
- package/dist/lib/worktree.d.ts.map +1 -1
- package/dist/lib/worktree.js +91 -4
- package/dist/lib/worktree.js.map +1 -1
- package/dist/standards/decision-request.md +98 -0
- package/dist/standards/fail-loud-standard.md +495 -0
- package/dist/standards/po-communication-standard.md +126 -0
- package/dist/standards/report-format.md +128 -0
- package/dist/standards/writing-standard.md +382 -0
- package/package.json +3 -2
- package/scripts/generate-claude.mjs +119 -46
package/dist/lib/jsonl.js
CHANGED
|
@@ -75,7 +75,17 @@ export function normalizeModelId(model) {
|
|
|
75
75
|
* getRates('opus') test in usage-pricing.test.ts (#5283 item 3).
|
|
76
76
|
*/
|
|
77
77
|
export function getRates(model) {
|
|
78
|
-
|
|
78
|
+
// hasOwnProperty, not a bare lookup, and the same call hasRates makes.
|
|
79
|
+
// MODEL_PRICING is a plain object literal, so a bare lookup reaches
|
|
80
|
+
// Object.prototype: a transcript model of 'constructor', 'toString',
|
|
81
|
+
// 'valueOf' or '__proto__' returned a function or an object instead of rates,
|
|
82
|
+
// every field of it was undefined, and calcLineCost returned NaN, which then
|
|
83
|
+
// poisoned the fleet total. hasRates already read it correctly and returned
|
|
84
|
+
// false for those four, so the two disagreed. Reproduced on all four.
|
|
85
|
+
const id = normalizeModelId(model);
|
|
86
|
+
return Object.prototype.hasOwnProperty.call(MODEL_PRICING, id)
|
|
87
|
+
? MODEL_PRICING[id]
|
|
88
|
+
: DEFAULT_RATES;
|
|
79
89
|
}
|
|
80
90
|
/**
|
|
81
91
|
* True when the model can be priced from an explicit MODEL_PRICING entry (not a
|
|
@@ -102,6 +112,11 @@ export function newTotals() {
|
|
|
102
112
|
models: new Set(),
|
|
103
113
|
mxCalls: 0,
|
|
104
114
|
mxEstTokens: 0,
|
|
115
|
+
usageGrouped: 0,
|
|
116
|
+
usageUngrouped: 0,
|
|
117
|
+
usageInconsistent: 0,
|
|
118
|
+
usageUndated: 0,
|
|
119
|
+
mxUndated: 0,
|
|
105
120
|
};
|
|
106
121
|
}
|
|
107
122
|
/**
|
|
@@ -123,6 +138,11 @@ export function addToTotals(dest, src) {
|
|
|
123
138
|
dest.cost += src.cost;
|
|
124
139
|
dest.mxCalls += src.mxCalls;
|
|
125
140
|
dest.mxEstTokens += src.mxEstTokens;
|
|
141
|
+
dest.usageGrouped += src.usageGrouped;
|
|
142
|
+
dest.usageUngrouped += src.usageUngrouped;
|
|
143
|
+
dest.usageInconsistent += src.usageInconsistent;
|
|
144
|
+
dest.usageUndated += src.usageUndated;
|
|
145
|
+
dest.mxUndated += src.mxUndated;
|
|
126
146
|
src.sessions.forEach((s) => dest.sessions.add(s));
|
|
127
147
|
src.models.forEach((m) => dest.models.add(m));
|
|
128
148
|
}
|
|
@@ -210,9 +230,179 @@ export function collectJsonlFiles(projectDir) {
|
|
|
210
230
|
const { leadFiles, childFiles, legacyChildFiles } = scanProjectDir(projectDir);
|
|
211
231
|
return [...leadFiles, ...childFiles.map((c) => c.path), ...legacyChildFiles];
|
|
212
232
|
}
|
|
233
|
+
export function newUsageGrouper() {
|
|
234
|
+
return { byKey: new Map(), unkeyed: [] };
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The grouping key for a transcript entry: `requestId`, else `message.id`, else
|
|
238
|
+
* '' when the entry carries neither.
|
|
239
|
+
*/
|
|
240
|
+
export function usageGroupKey(entry) {
|
|
241
|
+
const requestId = entry?.requestId;
|
|
242
|
+
if (typeof requestId === 'string' && requestId)
|
|
243
|
+
return requestId;
|
|
244
|
+
const message = entry?.message;
|
|
245
|
+
const messageId = message?.id;
|
|
246
|
+
if (typeof messageId === 'string' && messageId)
|
|
247
|
+
return messageId;
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* One usage field as a token count. The transcript reports these as JSON
|
|
252
|
+
* numbers; every other shape is one we cannot price.
|
|
253
|
+
*
|
|
254
|
+
* A cast plus `|| 0` kept a non-number and then added to it. Measured on the
|
|
255
|
+
* pre-change code, a single line with `input_tokens: '100'` reported
|
|
256
|
+
* `inputTokens` as the STRING '0100', because `0 + '100'` concatenates. That
|
|
257
|
+
* figure printed as a token count and was summed into cost, with no signal to
|
|
258
|
+
* the operator. Read the type, and count an unreadable value as 0.
|
|
259
|
+
*
|
|
260
|
+
* A negative count is as unreadable as a string: no API call bills a negative
|
|
261
|
+
* number of tokens, and a negative SUBTRACTS. Measured on the code that accepted
|
|
262
|
+
* one, a single line carrying `input_tokens: -6000000000` cancelled the whole
|
|
263
|
+
* corrected fleet input total of 6,649,443,346 (issue #307), printed nothing,
|
|
264
|
+
* warned nothing, and still counted as one healthy grouped call. An in-fleet
|
|
265
|
+
* agent writes these transcript lines, and this tool attributes spend to those
|
|
266
|
+
* same agents, so a line that makes one agent's spend read low is inside what
|
|
267
|
+
* this function defends against. `> 0` rather than `>= 0` so that both 0 and -0
|
|
268
|
+
* return the literal 0: -0 is a valid count but it is not what a reader expects
|
|
269
|
+
* a token total to hold.
|
|
270
|
+
*/
|
|
271
|
+
export function usageTokenCount(value) {
|
|
272
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* The entry's timestamp as epoch ms, or undefined when it carries none this code
|
|
276
|
+
* can read. Only a string or a number is read; an object, an array or a boolean
|
|
277
|
+
* is not a timestamp.
|
|
278
|
+
*
|
|
279
|
+
* `new Date(x).getTime()` is NaN for an object or an unparseable string, and
|
|
280
|
+
* every comparison against NaN is false. Measured on the pre-change code, one
|
|
281
|
+
* line whose timestamp was an object reported `in=10` with `recentIn=0`: the row
|
|
282
|
+
* counted in the all-time total and never in the recent window. NaN also poisoned
|
|
283
|
+
* the group, because `ts > existing.ts` is false against NaN, so one unreadable
|
|
284
|
+
* first line kept a whole call out of the window even when later lines were
|
|
285
|
+
* dated.
|
|
286
|
+
*/
|
|
287
|
+
export function usageEntryTs(entry) {
|
|
288
|
+
const raw = entry?.timestamp;
|
|
289
|
+
if (typeof raw !== 'string' && typeof raw !== 'number')
|
|
290
|
+
return undefined;
|
|
291
|
+
const t = new Date(raw).getTime();
|
|
292
|
+
return Number.isFinite(t) ? t : undefined;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Merge one transcript entry into the grouper. Returns false when the entry has
|
|
296
|
+
* no usage object, so callers can keep their own per-line work separate.
|
|
297
|
+
*
|
|
298
|
+
* NINE transcript fields are read here, and no content field is among them:
|
|
299
|
+
* `message.usage.input_tokens`, `message.usage.output_tokens`,
|
|
300
|
+
* `message.usage.cache_read_input_tokens`,
|
|
301
|
+
* `message.usage.cache_creation_input_tokens`, `message.model`, `message.id`
|
|
302
|
+
* (through usageGroupKey), `requestId` (through usageGroupKey), `sessionId`, and
|
|
303
|
+
* `timestamp` (through usageEntryTs). `message.content` is never read by this
|
|
304
|
+
* function. The gateway team's security review of PR #325 reported seven; the
|
|
305
|
+
* bootstrap team's security-reviewer corrected it to nine (INFO-4 on that pull
|
|
306
|
+
* request). The list above is re-derived from this function, not copied from
|
|
307
|
+
* either report.
|
|
308
|
+
*/
|
|
309
|
+
export function addUsageLine(g, entry) {
|
|
310
|
+
const message = entry?.message;
|
|
311
|
+
const usage = message?.usage;
|
|
312
|
+
if (!usage || typeof usage !== 'object' || !('input_tokens' in usage))
|
|
313
|
+
return false;
|
|
314
|
+
const input = usageTokenCount(usage.input_tokens);
|
|
315
|
+
const output = usageTokenCount(usage.output_tokens);
|
|
316
|
+
const cacheRead = usageTokenCount(usage.cache_read_input_tokens);
|
|
317
|
+
const cacheWrite = usageTokenCount(usage.cache_creation_input_tokens);
|
|
318
|
+
// A cast plus `|| ''` keeps a truthy non-string, and normalizeModelId then
|
|
319
|
+
// calls .replace on it and throws. Pricing used to run inside the per-line
|
|
320
|
+
// try/catch, which swallowed that; it now runs once per group after the file
|
|
321
|
+
// is read, so one malformed line would abort the whole usage report and name
|
|
322
|
+
// no file. Read the type, not the cast.
|
|
323
|
+
const model = typeof message?.model === 'string' ? message.model : '';
|
|
324
|
+
// Same reason as the model line above. A cast plus `|| ''` keeps a truthy
|
|
325
|
+
// non-string, and `allTime.sessions` is a Set: it treats each object as
|
|
326
|
+
// distinct, so N malformed lines inflated the session count by N. Measured on
|
|
327
|
+
// the code that cast: three lines with `sessionId: {id:'x'}` gave
|
|
328
|
+
// sessions.size 3, every member an object.
|
|
329
|
+
const session = typeof entry?.sessionId === 'string' ? entry.sessionId : '';
|
|
330
|
+
const parsedTs = usageEntryTs(entry);
|
|
331
|
+
const key = usageGroupKey(entry);
|
|
332
|
+
const row = {
|
|
333
|
+
key, keyed: key !== '',
|
|
334
|
+
input, output, cacheRead, cacheWrite,
|
|
335
|
+
model, session,
|
|
336
|
+
ts: parsedTs ?? 0, dated: parsedTs !== undefined,
|
|
337
|
+
lines: 1, inconsistent: false,
|
|
338
|
+
};
|
|
339
|
+
// No requestId and no message.id: the line cannot be joined to anything, so it
|
|
340
|
+
// is its own row. Counted once, reported under ungrouped, never dropped.
|
|
341
|
+
if (!key) {
|
|
342
|
+
g.unkeyed.push(row);
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
const existing = g.byKey.get(key);
|
|
346
|
+
if (!existing) {
|
|
347
|
+
g.byKey.set(key, row);
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
existing.lines++;
|
|
351
|
+
// Constancy check. These three are equal on every line of a group in the
|
|
352
|
+
// measured corpus. When they are not, take the maximum, which never sums, and
|
|
353
|
+
// record the group so the count reaches the operator.
|
|
354
|
+
if (input !== existing.input || cacheRead !== existing.cacheRead || cacheWrite !== existing.cacheWrite) {
|
|
355
|
+
existing.inconsistent = true;
|
|
356
|
+
existing.input = Math.max(existing.input, input);
|
|
357
|
+
existing.cacheRead = Math.max(existing.cacheRead, cacheRead);
|
|
358
|
+
existing.cacheWrite = Math.max(existing.cacheWrite, cacheWrite);
|
|
359
|
+
}
|
|
360
|
+
// output_tokens grows across the group's lines. The maximum is the final value.
|
|
361
|
+
if (output > existing.output)
|
|
362
|
+
existing.output = output;
|
|
363
|
+
// An undated line never overwrites a dated one, and the first dated line in a
|
|
364
|
+
// group sets the timestamp whatever its position.
|
|
365
|
+
if (parsedTs !== undefined && (!existing.dated || parsedTs > existing.ts)) {
|
|
366
|
+
existing.ts = parsedTs;
|
|
367
|
+
existing.dated = true;
|
|
368
|
+
}
|
|
369
|
+
// model is the field that selects the rate in calcLineCost, and it was the one
|
|
370
|
+
// grouped field exempt from the constancy check above: the first line of a
|
|
371
|
+
// group set the price and every later line's model was discarded with
|
|
372
|
+
// usageInconsistent staying 0. Measured on the code that skipped this check, a
|
|
373
|
+
// two-line group of claude-haiku-4-5 then claude-opus-5 priced at $0.0055
|
|
374
|
+
// instead of $0.0275 and reported no inconsistency. Before grouping, mispricing
|
|
375
|
+
// a call took a wrong model on every line; now the first line decides, so the
|
|
376
|
+
// check has to cover it. Compared only when both sides are non-empty, because a
|
|
377
|
+
// message_delta line carries no model and that is not a disagreement.
|
|
378
|
+
if (existing.model && model && model !== existing.model)
|
|
379
|
+
existing.inconsistent = true;
|
|
380
|
+
if (!existing.model && model)
|
|
381
|
+
existing.model = model;
|
|
382
|
+
if (!existing.session && session)
|
|
383
|
+
existing.session = session;
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
/** Every row the grouper holds, plus the three outcome counts. */
|
|
387
|
+
export function drainUsageGroups(g) {
|
|
388
|
+
const keyed = Array.from(g.byKey.values());
|
|
389
|
+
return {
|
|
390
|
+
rows: [...keyed, ...g.unkeyed],
|
|
391
|
+
stats: {
|
|
392
|
+
grouped: keyed.length,
|
|
393
|
+
ungrouped: g.unkeyed.length,
|
|
394
|
+
inconsistent: keyed.filter((r) => r.inconsistent).length,
|
|
395
|
+
undated: [...keyed, ...g.unkeyed].filter((r) => !r.dated).length,
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
}
|
|
213
399
|
// ── Aggregated usage (used by mx-agent usage) ─────────────────────────────────
|
|
214
400
|
/**
|
|
215
401
|
* Read a project dir's JSONL logs and return all-time and recent token totals.
|
|
402
|
+
*
|
|
403
|
+
* Usage is counted once per billed API call, not once per transcript line: lines
|
|
404
|
+
* are grouped by requestId, falling back to message.id (#307). See the per-call
|
|
405
|
+
* usage grouping section above for the mechanism and the measured overcount.
|
|
216
406
|
*/
|
|
217
407
|
export function readProjectUsage(projectDir, recentCutoffMs) {
|
|
218
408
|
const allTime = newTotals();
|
|
@@ -227,12 +417,17 @@ export function readProjectUsage(projectDir, recentCutoffMs) {
|
|
|
227
417
|
continue;
|
|
228
418
|
}
|
|
229
419
|
const mxToolUseIds = new Map();
|
|
420
|
+
// One row per billed call rather than one per transcript line (#307).
|
|
421
|
+
const grouper = newUsageGrouper();
|
|
230
422
|
for (const line of content.split('\n')) {
|
|
231
423
|
if (!line.trim())
|
|
232
424
|
continue;
|
|
233
425
|
try {
|
|
234
426
|
const entry = JSON.parse(line);
|
|
235
|
-
|
|
427
|
+
// undefined when the line carries no timestamp this code can read. The
|
|
428
|
+
// MemNexus tool counters below treat that the same way the usage rows do:
|
|
429
|
+
// counted in the recent window rather than silently dropped from it.
|
|
430
|
+
const ts = usageEntryTs(entry);
|
|
236
431
|
const role = entry?.message?.role;
|
|
237
432
|
const msgContent = entry?.message?.content;
|
|
238
433
|
// ── MemNexus tool tracking ──────────────────────────────────────
|
|
@@ -247,7 +442,16 @@ export function readProjectUsage(projectDir, recentCutoffMs) {
|
|
|
247
442
|
if (isMcp || isCli) {
|
|
248
443
|
mxToolUseIds.set(block.id, ts);
|
|
249
444
|
allTime.mxCalls++;
|
|
250
|
-
|
|
445
|
+
// Undated counts as recent, the rule the usage rows use, and it is
|
|
446
|
+
// counted so the recent column is not silently resting on it. On
|
|
447
|
+
// origin/main a missing timestamp gave 0 and `0 >= cutoff` was
|
|
448
|
+
// false, so these lines did not count as recent; they do now, and
|
|
449
|
+
// that is what this counter discloses.
|
|
450
|
+
if (ts === undefined) {
|
|
451
|
+
allTime.mxUndated++;
|
|
452
|
+
recent.mxUndated++;
|
|
453
|
+
}
|
|
454
|
+
if (ts === undefined || ts >= cutoff)
|
|
251
455
|
recent.mxCalls++;
|
|
252
456
|
}
|
|
253
457
|
}
|
|
@@ -260,45 +464,62 @@ export function readProjectUsage(projectDir, recentCutoffMs) {
|
|
|
260
464
|
const origTs = mxToolUseIds.get(block.tool_use_id);
|
|
261
465
|
const estTokens = Math.round(JSON.stringify(block.content ?? '').length / 4);
|
|
262
466
|
allTime.mxEstTokens += estTokens;
|
|
263
|
-
if (origTs >= cutoff)
|
|
467
|
+
if (origTs === undefined || origTs >= cutoff)
|
|
264
468
|
recent.mxEstTokens += estTokens;
|
|
265
469
|
}
|
|
266
470
|
}
|
|
267
471
|
}
|
|
268
472
|
// ── Token usage ─────────────────────────────────────────────────
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
continue;
|
|
272
|
-
const input = usage.input_tokens || 0;
|
|
273
|
-
const output = usage.output_tokens || 0;
|
|
274
|
-
const cacheR = usage.cache_read_input_tokens || 0;
|
|
275
|
-
const cacheW = usage.cache_creation_input_tokens || 0;
|
|
276
|
-
const model = entry?.message?.model || '';
|
|
277
|
-
const session = entry?.sessionId || '';
|
|
278
|
-
const lineCost = calcLineCost(input, output, cacheR, cacheW, getRates(model));
|
|
279
|
-
allTime.inputTokens += input;
|
|
280
|
-
allTime.outputTokens += output;
|
|
281
|
-
allTime.cacheReadTokens += cacheR;
|
|
282
|
-
allTime.cacheWriteTokens += cacheW;
|
|
283
|
-
allTime.cost += lineCost;
|
|
284
|
-
if (session)
|
|
285
|
-
allTime.sessions.add(session);
|
|
286
|
-
if (model)
|
|
287
|
-
allTime.models.add(model);
|
|
288
|
-
if (ts >= cutoff) {
|
|
289
|
-
recent.inputTokens += input;
|
|
290
|
-
recent.outputTokens += output;
|
|
291
|
-
recent.cacheReadTokens += cacheR;
|
|
292
|
-
recent.cacheWriteTokens += cacheW;
|
|
293
|
-
recent.cost += lineCost;
|
|
294
|
-
if (session)
|
|
295
|
-
recent.sessions.add(session);
|
|
296
|
-
if (model)
|
|
297
|
-
recent.models.add(model);
|
|
298
|
-
}
|
|
473
|
+
// Held per requestId (or message.id) and priced once the file is read.
|
|
474
|
+
addUsageLine(grouper, entry);
|
|
299
475
|
}
|
|
300
476
|
catch { /* skip malformed line */ }
|
|
301
477
|
}
|
|
478
|
+
// ── One priced row per billed call (#307) ──────────────────────────
|
|
479
|
+
for (const row of drainUsageGroups(grouper).rows) {
|
|
480
|
+
const rowCost = calcLineCost(row.input, row.output, row.cacheRead, row.cacheWrite, getRates(row.model));
|
|
481
|
+
allTime.inputTokens += row.input;
|
|
482
|
+
allTime.outputTokens += row.output;
|
|
483
|
+
allTime.cacheReadTokens += row.cacheRead;
|
|
484
|
+
allTime.cacheWriteTokens += row.cacheWrite;
|
|
485
|
+
allTime.cost += rowCost;
|
|
486
|
+
if (row.keyed)
|
|
487
|
+
allTime.usageGrouped++;
|
|
488
|
+
else
|
|
489
|
+
allTime.usageUngrouped++;
|
|
490
|
+
if (row.inconsistent)
|
|
491
|
+
allTime.usageInconsistent++;
|
|
492
|
+
if (!row.dated)
|
|
493
|
+
allTime.usageUndated++;
|
|
494
|
+
if (row.session)
|
|
495
|
+
allTime.sessions.add(row.session);
|
|
496
|
+
if (row.model)
|
|
497
|
+
allTime.models.add(row.model);
|
|
498
|
+
// A group's window membership is its latest dated line, the point the call
|
|
499
|
+
// ended. A row no line of which is dated counts in the recent window as
|
|
500
|
+
// well as the all-time total: excluding it understates the window and the
|
|
501
|
+
// operator cannot see the difference, while including it can only make the
|
|
502
|
+
// window read closer to the all-time total, which is visible.
|
|
503
|
+
if (!row.dated || row.ts >= cutoff) {
|
|
504
|
+
recent.inputTokens += row.input;
|
|
505
|
+
recent.outputTokens += row.output;
|
|
506
|
+
recent.cacheReadTokens += row.cacheRead;
|
|
507
|
+
recent.cacheWriteTokens += row.cacheWrite;
|
|
508
|
+
recent.cost += rowCost;
|
|
509
|
+
if (row.keyed)
|
|
510
|
+
recent.usageGrouped++;
|
|
511
|
+
else
|
|
512
|
+
recent.usageUngrouped++;
|
|
513
|
+
if (row.inconsistent)
|
|
514
|
+
recent.usageInconsistent++;
|
|
515
|
+
if (!row.dated)
|
|
516
|
+
recent.usageUndated++;
|
|
517
|
+
if (row.session)
|
|
518
|
+
recent.sessions.add(row.session);
|
|
519
|
+
if (row.model)
|
|
520
|
+
recent.models.add(row.model);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
302
523
|
}
|
|
303
524
|
return { allTime, recent };
|
|
304
525
|
}
|
|
@@ -430,12 +651,81 @@ export function isMachineGeneratedUserRecord(entry) {
|
|
|
430
651
|
return isEntirelyMachineWrapper(trimmed);
|
|
431
652
|
}
|
|
432
653
|
/**
|
|
433
|
-
*
|
|
654
|
+
* Object keys this code never publishes in a JSON body.
|
|
655
|
+
*
|
|
656
|
+
* `subagentTypes` keys are `tool_use.input.subagent_type`, chosen by the model
|
|
657
|
+
* that writes the Agent call, so they are the most caller-influenced strings in
|
|
658
|
+
* a SessionRecord. The local accumulator is a Map and nothing is polluted here,
|
|
659
|
+
* but `Object.fromEntries` produced a plain object whose `__proto__` key
|
|
660
|
+
* survived JSON.stringify into the /v1/sessions/sync body. Measured on the
|
|
661
|
+
* pre-change code, one line with `subagent_type: "__proto__"` gave
|
|
662
|
+
* `"subagentTypes":{"__proto__":1}` with hasOwnProperty true.
|
|
663
|
+
*
|
|
664
|
+
* `JSON.parse` on the receiving side creates an own property and is safe by
|
|
665
|
+
* itself. The sink is any later `Object.assign`, spread-merge or deep-merge on
|
|
666
|
+
* the server, where an own `__proto__` data property is copied with [[Set]] and
|
|
667
|
+
* reaches the target's prototype. Nobody here has reviewed the observability
|
|
668
|
+
* service, so this makes no claim that such a sink exists. The filter is three
|
|
669
|
+
* string comparisons per session and it removes the question.
|
|
670
|
+
*
|
|
671
|
+
* Reported by the bootstrap team's security-reviewer on PR #325 (SF-2).
|
|
672
|
+
*/
|
|
673
|
+
const UNSAFE_WIRE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
674
|
+
/**
|
|
675
|
+
* The `subagentTypes` object that goes on the wire, with every UNSAFE_WIRE_KEYS
|
|
676
|
+
* key dropped. Exported for tests.
|
|
677
|
+
*
|
|
678
|
+
* Dropping loses a spawn count. `agentSpawns` still counts those spawns, and
|
|
679
|
+
* SessionRecordStats.droppedSubagentTypeKeys counts the keys dropped here, so no
|
|
680
|
+
* count disappears without a number an operator can read.
|
|
681
|
+
*/
|
|
682
|
+
export function toWireSubagentTypes(counts) {
|
|
683
|
+
const out = {};
|
|
684
|
+
for (const [key, n] of counts) {
|
|
685
|
+
if (UNSAFE_WIRE_KEYS.has(key))
|
|
686
|
+
continue;
|
|
687
|
+
out[key] = n;
|
|
688
|
+
}
|
|
689
|
+
return out;
|
|
690
|
+
}
|
|
691
|
+
/** How many of a session's subagent_type keys toWireSubagentTypes will drop. */
|
|
692
|
+
export function unsafeWireKeyCount(counts) {
|
|
693
|
+
let n = 0;
|
|
694
|
+
for (const key of counts.keys())
|
|
695
|
+
if (UNSAFE_WIRE_KEYS.has(key))
|
|
696
|
+
n++;
|
|
697
|
+
return n;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Parse all JSONL files in a project dir and return one SessionRecord per
|
|
701
|
+
* session, with the counts of what the walk discarded.
|
|
434
702
|
*
|
|
435
703
|
* Only returns sessions that have at least one assistant record with usage data.
|
|
436
704
|
* Sessions without token data (e.g. failed starts) are excluded.
|
|
705
|
+
*
|
|
706
|
+
* Token counts are one row per billed API call, not one per transcript line:
|
|
707
|
+
* lines are grouped by requestId, falling back to message.id (#307). These
|
|
708
|
+
* records are what `mx-agent sync` POSTs to /v1/sessions/sync, so a per-line sum
|
|
709
|
+
* here writes the same overcount into the observability store, where correcting
|
|
710
|
+
* it needs a backfill. `model` is now the model of the most billed CALLS in the
|
|
711
|
+
* session rather than of the most lines.
|
|
712
|
+
*
|
|
713
|
+
* `sessionId`, `timestamp` and every usage field are read by type here, not by
|
|
714
|
+
* cast. Commit b6b8e23 is titled "read every transcript timestamp and sessionId
|
|
715
|
+
* by type"; its sessionId change covered readProjectUsage only, and this walk's
|
|
716
|
+
* own sessionId read was fixed afterwards. Both are covered now, and the title
|
|
717
|
+
* is what made the gap easy to miss.
|
|
437
718
|
*/
|
|
438
|
-
export function
|
|
719
|
+
export function parseSessionRecordsWithStats(projectDir) {
|
|
720
|
+
const stats = {
|
|
721
|
+
skippedLines: 0,
|
|
722
|
+
skippedUsageLines: 0,
|
|
723
|
+
skippedUsageInputTokens: 0,
|
|
724
|
+
skippedUsageOutputTokens: 0,
|
|
725
|
+
skippedUsageCacheReadTokens: 0,
|
|
726
|
+
skippedUsageCacheWriteTokens: 0,
|
|
727
|
+
droppedSubagentTypeKeys: 0,
|
|
728
|
+
};
|
|
439
729
|
// Per-session accumulators
|
|
440
730
|
const sessions = new Map();
|
|
441
731
|
for (const filePath of collectJsonlFiles(projectDir)) {
|
|
@@ -446,15 +736,64 @@ export function parseSessionRecords(projectDir) {
|
|
|
446
736
|
catch {
|
|
447
737
|
continue;
|
|
448
738
|
}
|
|
739
|
+
// One grouper per session per FILE (#307). Grouping scope is one transcript
|
|
740
|
+
// file, the same scope readProjectUsage uses: every line of one call is
|
|
741
|
+
// written by the file that made the call, so a key never spans files.
|
|
742
|
+
const fileGroupers = new Map();
|
|
743
|
+
// The dropped lines get a grouper of their own, on the same one-file scope,
|
|
744
|
+
// so their tokens are counted once per billed call exactly as
|
|
745
|
+
// readProjectUsage counts the same lines. See the skip branch below.
|
|
746
|
+
const skippedGrouper = newUsageGrouper();
|
|
449
747
|
for (const line of content.split('\n')) {
|
|
450
748
|
if (!line.trim())
|
|
451
749
|
continue;
|
|
452
750
|
try {
|
|
453
751
|
const entry = JSON.parse(line);
|
|
454
|
-
|
|
455
|
-
|
|
752
|
+
// Read the type, do not cast. Any truthy value passed this check, and
|
|
753
|
+
// both Maps below key on it: a JS Map keys an object by reference, so N
|
|
754
|
+
// lines carrying `sessionId: {}` made N `sessions` entries and N
|
|
755
|
+
// `fileGroupers` entries. Measured on the code that cast: three such
|
|
756
|
+
// lines produced three SessionRecords, each with an object sessionId,
|
|
757
|
+
// and `records.push({ sessionId, ... })` puts that value in the array
|
|
758
|
+
// mx-agent sync POSTs to /v1/sessions/sync, where it is durable.
|
|
759
|
+
// A string of blanks is unreadable in the same way a number or an
|
|
760
|
+
// object is, and `!sessionId` is false for ' ', so such a line was
|
|
761
|
+
// neither dropped nor counted: it created a session record keyed by
|
|
762
|
+
// ' ' and mx-agent sync POSTed it. Measured on the code without the
|
|
763
|
+
// trim, two lines where one carries `sessionId: ' '` and 1000 input
|
|
764
|
+
// tokens gave 2 records with sessionIds [' ', 'session-good'] and
|
|
765
|
+
// every counter at 0. Only the emptiness test trims. The untrimmed
|
|
766
|
+
// value stays the key whenever it is not blank, so no session that
|
|
767
|
+
// syncs today changes identity.
|
|
768
|
+
const rawSessionId = typeof entry?.sessionId === 'string' ? entry.sessionId : '';
|
|
769
|
+
const sessionId = rawSessionId.trim() ? rawSessionId : '';
|
|
770
|
+
if (!sessionId) {
|
|
771
|
+
// Counted rather than dropped in silence. readProjectUsage keeps this
|
|
772
|
+
// line and counts its tokens, so a usage-bearing line dropped here is
|
|
773
|
+
// a difference between what the observability store holds and what
|
|
774
|
+
// `mx-agent usage` prints, with nothing else for an operator to read.
|
|
775
|
+
//
|
|
776
|
+
// The tokens go through addUsageLine and a grouper rather than a
|
|
777
|
+
// per-line sum. Two dropped lines of ONE streamed call repeat the same
|
|
778
|
+
// input number, and adding them reports 2,000 tokens for a gap of
|
|
779
|
+
// 1,000. That is the #307 overcount, and putting it inside the
|
|
780
|
+
// disclosure that measures what #307 left behind would be the same
|
|
781
|
+
// defect one level up. Measured on this fixture: naive per-line sum
|
|
782
|
+
// 2,000 against a real gap of 1,000, 2x.
|
|
783
|
+
stats.skippedLines++;
|
|
784
|
+
if (addUsageLine(skippedGrouper, entry)) {
|
|
785
|
+
stats.skippedUsageLines++;
|
|
786
|
+
}
|
|
456
787
|
continue;
|
|
457
|
-
|
|
788
|
+
}
|
|
789
|
+
// 0 when the line carries no timestamp this code can read, never NaN.
|
|
790
|
+
// The `ts > 0` guards below already skip 0, but they cannot skip NaN:
|
|
791
|
+
// `firstTs: ts` at the accumulator's first line kept NaN, `ts < NaN` and
|
|
792
|
+
// `ts > NaN` are both false, and every later dated line was then ignored.
|
|
793
|
+
// Measured on the code that cast: a session whose FIRST line had an
|
|
794
|
+
// object timestamp reported durationMs 0 and a `date` of the moment the
|
|
795
|
+
// report ran, discarding the timestamps its other lines carried.
|
|
796
|
+
const ts = usageEntryTs(entry) ?? 0;
|
|
458
797
|
const entryType = entry?.type;
|
|
459
798
|
const msgContent = entry?.message?.content;
|
|
460
799
|
// Get or create session accumulator
|
|
@@ -616,23 +955,43 @@ export function parseSessionRecords(projectDir) {
|
|
|
616
955
|
}
|
|
617
956
|
}
|
|
618
957
|
// ── Token usage ──────────────────────────────────────────────
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
s.cacheWriteTokens += usage.cache_creation_input_tokens || 0;
|
|
625
|
-
const model = entry?.message?.model || '';
|
|
626
|
-
if (model) {
|
|
627
|
-
s.modelCounts.set(model, (s.modelCounts.get(model) || 0) + 1);
|
|
628
|
-
}
|
|
958
|
+
// Held per requestId (or message.id) and totalled once the file is read.
|
|
959
|
+
let grouper = fileGroupers.get(sessionId);
|
|
960
|
+
if (!grouper) {
|
|
961
|
+
grouper = newUsageGrouper();
|
|
962
|
+
fileGroupers.set(sessionId, grouper);
|
|
629
963
|
}
|
|
964
|
+
addUsageLine(grouper, entry);
|
|
630
965
|
// Track last entry timestamp for wait-time calculation
|
|
631
966
|
if (ts > 0)
|
|
632
967
|
s.lastEntryTs = ts;
|
|
633
968
|
}
|
|
634
969
|
catch { /* skip malformed line */ }
|
|
635
970
|
}
|
|
971
|
+
// One row per billed call for the dropped lines too, so the number the
|
|
972
|
+
// summary prints is the same arithmetic mx-agent usage does.
|
|
973
|
+
for (const row of drainUsageGroups(skippedGrouper).rows) {
|
|
974
|
+
stats.skippedUsageInputTokens += row.input;
|
|
975
|
+
stats.skippedUsageOutputTokens += row.output;
|
|
976
|
+
stats.skippedUsageCacheReadTokens += row.cacheRead;
|
|
977
|
+
stats.skippedUsageCacheWriteTokens += row.cacheWrite;
|
|
978
|
+
}
|
|
979
|
+
// ── One row per billed call, added to the session's totals (#307) ──────
|
|
980
|
+
for (const [sessionId, grouper] of fileGroupers) {
|
|
981
|
+
const s = sessions.get(sessionId);
|
|
982
|
+
if (!s)
|
|
983
|
+
continue;
|
|
984
|
+
for (const row of drainUsageGroups(grouper).rows) {
|
|
985
|
+
s.inputTokens += row.input;
|
|
986
|
+
s.outputTokens += row.output;
|
|
987
|
+
s.cacheReadTokens += row.cacheRead;
|
|
988
|
+
s.cacheWriteTokens += row.cacheWrite;
|
|
989
|
+
// One count per billed call. Counting per line made the model of the
|
|
990
|
+
// longest-streamed responses win, which is not the most-used model.
|
|
991
|
+
if (row.model)
|
|
992
|
+
s.modelCounts.set(row.model, (s.modelCounts.get(row.model) || 0) + 1);
|
|
993
|
+
}
|
|
994
|
+
}
|
|
636
995
|
}
|
|
637
996
|
// Convert accumulators to SessionRecord[], dropping sessions with no token data
|
|
638
997
|
const records = [];
|
|
@@ -648,6 +1007,9 @@ export function parseSessionRecords(projectDir) {
|
|
|
648
1007
|
topCount = count;
|
|
649
1008
|
}
|
|
650
1009
|
}
|
|
1010
|
+
// Counted only for sessions that become a record, because only those reach
|
|
1011
|
+
// the wire object toWireSubagentTypes builds.
|
|
1012
|
+
stats.droppedSubagentTypeKeys += unsafeWireKeyCount(s.subagentTypes);
|
|
651
1013
|
records.push({
|
|
652
1014
|
sessionId,
|
|
653
1015
|
date: s.firstTs ? new Date(s.firstTs).toISOString() : new Date().toISOString(),
|
|
@@ -667,11 +1029,22 @@ export function parseSessionRecords(projectDir) {
|
|
|
667
1029
|
prNumbers: Array.from(s.prNumbers),
|
|
668
1030
|
memorySaves: s.memorySaves,
|
|
669
1031
|
agentSpawns: s.agentSpawns,
|
|
670
|
-
subagentTypes:
|
|
1032
|
+
subagentTypes: toWireSubagentTypes(s.subagentTypes),
|
|
671
1033
|
deployVerified: s.deployVerified,
|
|
672
1034
|
});
|
|
673
1035
|
}
|
|
674
|
-
return records;
|
|
1036
|
+
return { records, stats };
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* The records alone, for the callers that read no counter.
|
|
1040
|
+
*
|
|
1041
|
+
* `commands/pager.ts` and `commands/pr-sync.ts` read toolCalls, memorySaves,
|
|
1042
|
+
* agentSpawns and PR numbers, never a token field, so a dropped line changes
|
|
1043
|
+
* nothing they publish. `commands/sync.ts` POSTs the token fields and calls
|
|
1044
|
+
* parseSessionRecordsWithStats instead.
|
|
1045
|
+
*/
|
|
1046
|
+
export function parseSessionRecords(projectDir) {
|
|
1047
|
+
return parseSessionRecordsWithStats(projectDir).records;
|
|
675
1048
|
}
|
|
676
1049
|
function newAgentUsage(subagentType) {
|
|
677
1050
|
return {
|
|
@@ -754,7 +1127,10 @@ function collectJoins(content, into) {
|
|
|
754
1127
|
* Build per-subagent-definition token/cost attribution for a project dir.
|
|
755
1128
|
*
|
|
756
1129
|
* Additive: does not touch Totals, SessionRecord, or readProjectUsage. Prices
|
|
757
|
-
* child transcripts
|
|
1130
|
+
* child transcripts once per billed API call with the existing
|
|
1131
|
+
* calcLineCost/getRates. Lines are grouped by requestId, falling back to
|
|
1132
|
+
* message.id (#307); before that they were priced one row per transcript line,
|
|
1133
|
+
* which counted each streamed call two or three times.
|
|
758
1134
|
*/
|
|
759
1135
|
export function parseAgentAttribution(projectDir) {
|
|
760
1136
|
const { parentFiles, childFiles } = discoverAttributionFiles(projectDir);
|
|
@@ -795,6 +1171,10 @@ export function parseAgentAttribution(projectDir) {
|
|
|
795
1171
|
let unattributedTokens = 0;
|
|
796
1172
|
let oldestTs = 0;
|
|
797
1173
|
let newestTs = 0;
|
|
1174
|
+
let usageGrouped = 0;
|
|
1175
|
+
let usageUngrouped = 0;
|
|
1176
|
+
let usageInconsistent = 0;
|
|
1177
|
+
let usageUndated = 0;
|
|
798
1178
|
for (const { path, agentId } of childFiles) {
|
|
799
1179
|
const content = childContents.get(path);
|
|
800
1180
|
if (content === undefined)
|
|
@@ -815,6 +1195,8 @@ export function parseAgentAttribution(projectDir) {
|
|
|
815
1195
|
unattributed.fileCount++;
|
|
816
1196
|
}
|
|
817
1197
|
const counts = subagentType ? modelCounts.get(subagentType) : null;
|
|
1198
|
+
// One row per billed call rather than one per transcript line (#307).
|
|
1199
|
+
const grouper = newUsageGrouper();
|
|
818
1200
|
for (const line of content.split('\n')) {
|
|
819
1201
|
if (!line.trim())
|
|
820
1202
|
continue;
|
|
@@ -827,7 +1209,10 @@ export function parseAgentAttribution(projectDir) {
|
|
|
827
1209
|
}
|
|
828
1210
|
const message = entry.message;
|
|
829
1211
|
const usage = message?.usage;
|
|
830
|
-
|
|
1212
|
+
// 0 rather than NaN, the same read as the other two walks. This one's
|
|
1213
|
+
// `ts > 0` guard already rejected NaN, so the range it reports is
|
|
1214
|
+
// unchanged; the read is here so the three paths cannot drift.
|
|
1215
|
+
const ts = usageEntryTs(entry) ?? 0;
|
|
831
1216
|
if (ts > 0) {
|
|
832
1217
|
if (oldestTs === 0 || ts < oldestTs)
|
|
833
1218
|
oldestTs = ts;
|
|
@@ -836,39 +1221,46 @@ export function parseAgentAttribution(projectDir) {
|
|
|
836
1221
|
}
|
|
837
1222
|
if (!usage || typeof usage !== 'object' || !('input_tokens' in usage))
|
|
838
1223
|
continue;
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
1224
|
+
// Held per requestId (or message.id) and priced once the file is read.
|
|
1225
|
+
addUsageLine(grouper, entry);
|
|
1226
|
+
}
|
|
1227
|
+
// ── One priced row per billed call (#307) ────────────────────────────
|
|
1228
|
+
const { rows, stats } = drainUsageGroups(grouper);
|
|
1229
|
+
usageGrouped += stats.grouped;
|
|
1230
|
+
usageUngrouped += stats.ungrouped;
|
|
1231
|
+
usageInconsistent += stats.inconsistent;
|
|
1232
|
+
usageUndated += stats.undated;
|
|
1233
|
+
for (const row of rows) {
|
|
1234
|
+
const model = row.model;
|
|
844
1235
|
// getRates/hasRates normalize internally (#5283); passing the raw ID here
|
|
845
|
-
// is
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
|
|
849
|
-
const
|
|
850
|
-
const lineTokens = input + output + cacheR + cacheW;
|
|
1236
|
+
// is identical to an explicit normalizeModelId() call, since normalization
|
|
1237
|
+
// is idempotent. The raw ID is what gets REPORTED when unknown, so the
|
|
1238
|
+
// operator sees the exact string the transcript carried.
|
|
1239
|
+
const rowCost = calcLineCost(row.input, row.output, row.cacheRead, row.cacheWrite, getRates(model));
|
|
1240
|
+
const rowTokens = row.input + row.output + row.cacheRead + row.cacheWrite;
|
|
851
1241
|
if (model && !hasRates(model))
|
|
852
1242
|
unknownModels.add(model);
|
|
853
1243
|
if (bucket) {
|
|
854
|
-
bucket.inputTokens += input;
|
|
855
|
-
bucket.outputTokens += output;
|
|
856
|
-
bucket.cacheReadTokens +=
|
|
857
|
-
bucket.cacheWriteTokens +=
|
|
858
|
-
bucket.cost +=
|
|
1244
|
+
bucket.inputTokens += row.input;
|
|
1245
|
+
bucket.outputTokens += row.output;
|
|
1246
|
+
bucket.cacheReadTokens += row.cacheRead;
|
|
1247
|
+
bucket.cacheWriteTokens += row.cacheWrite;
|
|
1248
|
+
bucket.cost += rowCost;
|
|
859
1249
|
if (model) {
|
|
860
1250
|
bucket.models.add(model);
|
|
1251
|
+
// Dominant model is now weighted by billed call, not by transcript
|
|
1252
|
+
// line, so a streamed call no longer votes two or three times.
|
|
861
1253
|
counts.set(model, (counts.get(model) || 0) + 1);
|
|
862
1254
|
}
|
|
863
|
-
attributedTokens +=
|
|
1255
|
+
attributedTokens += rowTokens;
|
|
864
1256
|
}
|
|
865
1257
|
else {
|
|
866
|
-
unattributed.inputTokens += input;
|
|
867
|
-
unattributed.outputTokens += output;
|
|
868
|
-
unattributed.cacheReadTokens +=
|
|
869
|
-
unattributed.cacheWriteTokens +=
|
|
870
|
-
unattributed.cost +=
|
|
871
|
-
unattributedTokens +=
|
|
1258
|
+
unattributed.inputTokens += row.input;
|
|
1259
|
+
unattributed.outputTokens += row.output;
|
|
1260
|
+
unattributed.cacheReadTokens += row.cacheRead;
|
|
1261
|
+
unattributed.cacheWriteTokens += row.cacheWrite;
|
|
1262
|
+
unattributed.cost += rowCost;
|
|
1263
|
+
unattributedTokens += rowTokens;
|
|
872
1264
|
}
|
|
873
1265
|
}
|
|
874
1266
|
}
|
|
@@ -896,6 +1288,10 @@ export function parseAgentAttribution(projectDir) {
|
|
|
896
1288
|
coveragePct,
|
|
897
1289
|
oldestTs,
|
|
898
1290
|
newestTs,
|
|
1291
|
+
usageGrouped,
|
|
1292
|
+
usageUngrouped,
|
|
1293
|
+
usageInconsistent,
|
|
1294
|
+
usageUndated,
|
|
899
1295
|
};
|
|
900
1296
|
}
|
|
901
1297
|
//# sourceMappingURL=jsonl.js.map
|