agent-orchestrator-kit 0.5.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -4,6 +4,38 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.7.0] - 2026-08-30
8
+
9
+ ### Breaking
10
+ - **`--no-collect` removed** — persist and archive no longer collect local spend adapters by default. Pass `--collect` to run Claude JSONL, Amp thread, and Cursor hook adapters. Scripts that still pass `--no-collect` fail as an unknown option.
11
+
12
+ ### Added
13
+ - **`## Metrics` in `handoff.md`** — Session Exit self-report (`platform`, `model`, `input_tokens`, `output_tokens`, `cost_usd`, `amp_credits`, `spend_source`). Persist and archive resolve spend from flags → self-report → optional `--collect` sources. The section stays the agent's declaration; `metrics.json` is the source of truth.
14
+ - **`session.spendSource`** and **`session.ampCredits`** — origin of the numbers (`self-report` / `flag` / `adapter` / `unreported`, or a custom `spend_source`) and Amp credits kept out of USD totals.
15
+ - **Archive summary** — after finalize, `archive` prints the same human tables as `metrics <name>` (by phase / platform / model, unreported count).
16
+
17
+ ### Changed
18
+ - **Resolve chains** — `model`: `--model` → `## Metrics` → `AOK_MODEL` → sources (with `--collect`) → `null`. `platform`: `--platform` → `## Metrics` → `AOK_PLATFORM` → host env → sources.
19
+ - **Cursor spend hook** — still installed by `init` / `update` / `sync` / `mcp-setup`; persist, restore, and `metrics` no longer self-heal `.cursor/hooks.json`.
20
+ - **`spendByPlatform` / `spendByModel`** — include session-level self-report; matching `sources` are counted once; buckets without adapters keep `source: "none"`.
21
+
22
+ ### Fixed
23
+ - **Spend collect window** — persist no longer starts the collect window at `pending.startedAt`. Window is `[last session.endedAt || createdAt, endedAt]`.
24
+ - **Amp collect without trees** — a thread is no longer skipped solely because `env.initial.trees` is missing; cwd fields, `AMP_CURRENT_THREAD` / `AMP_THREAD_ID`, or an exact cwd mention still match.
25
+ - **Amp leftover after persist/archive** — persist and archive run the same last-session backfill as `metrics --collect`.
26
+
27
+ ## [0.6.0] - 2026-08-29
28
+
29
+ ### Added
30
+ - **Mandatory Cursor spend hook** — `scripts/cursor-spend-hook.cjs` (fail-open, silent) appends per-turn token usage from Cursor `stop` / `subagentStop` hook payloads to gitignored `.agents/spend/cursor-usage.jsonl`; `ensureCursorSpendHook` installs the script and merges `.cursor/hooks.json` in `init`, `update`, `sync`, `mcp-setup`, and self-heals on every `handoff` restore/persist (persist reports to stderr only) so every kit project records Cursor spend without manual flags; `status` prints a `Spend capture` section (cursor hook state + record count, local Claude/Amp data presence)
31
+
32
+ ### Changed
33
+ - **Change metrics** — `session.model` resolves `--model` → `AOK_MODEL` → `null` (stderr warning); persist/archive auto-collect local usage from Claude JSONL, Amp threads, and the Cursor spend hook file (`.agents/spend/cursor-usage.jsonl`) into separate `spendByPlatform` / `spendByModel` figures (flags override session totals only; never merge Amp credits into USD); human `metrics` table prints `roles` and `models` plus platform/model tables; `archive` always creates or finalizes `metrics.json` with an Archiver session; Session Exit protocol requires `--model <llm-product-id>`
34
+ - **Cursor spend adapter** — replaced the dead `state.vscdb` probe (Cursor never writes token usage to its local DB) with reading the hook-generated `.agents/spend/cursor-usage.jsonl` (window by `at`, dedup by `generation_id`, cumulative loop repeats keep the largest record, `source: "cursor-hook"`)
35
+
36
+ ### Fixed
37
+ - **Amp source ids** — `messageId` is a thread-local counter (1, 3, 5…), so dedup ids are now namespaced as `<threadId>:<messageId>` to prevent collisions across threads
38
+
7
39
  ## [0.5.0] - 2026-08-29
8
40
 
9
41
  ### Added
@@ -199,6 +231,7 @@ All notable changes to this project will be documented in this file.
199
231
  ### Added
200
232
  - Initial release: 5-role orchestration pipeline, `/opsx:*` commands, IDE sync
201
233
 
234
+ [0.6.0]: https://github.com/makshc2/agent-orchestrator-kit/compare/v0.5.0...v0.6.0
202
235
  [0.5.0]: https://github.com/makshc2/agent-orchestrator-kit/compare/v0.4.0...v0.5.0
203
236
  [0.4.0]: https://github.com/makshc2/agent-orchestrator-kit/compare/v0.3.0...v0.4.0
204
237
  [0.3.0]: https://github.com/makshc2/agent-orchestrator-kit/compare/v0.2.0...v0.3.0
package/README.md CHANGED
@@ -74,7 +74,7 @@ npx agent-orchestrator-kit@latest init --profile generic --ci gitlab --spec-veri
74
74
 
75
75
  See [Installation](#installation) for profile/CI options.
76
76
 
77
- **🔄 Already have the kit installed? Upgrade to latest (change metrics in v0.5.0+, factory phases 1–3 in v0.4.0+, lean pipeline / archive CLI in v0.3.0+, handoff CLI in v0.1.14+, Figma PAT in v0.1.11+):**
77
+ **🔄 Already have the kit installed? Upgrade to latest (`## Metrics` self-report + opt-in `--collect` in v0.7.0 — **BREAKING:** `--no-collect` is gone; change metrics in v0.5.0+, factory phases 1–3 in v0.4.0+, lean pipeline / archive CLI in v0.3.0+, handoff CLI in v0.1.14+, Figma PAT in v0.1.11+):**
78
78
 
79
79
  ```bash
80
80
  npx agent-orchestrator-kit@latest update
@@ -597,10 +597,10 @@ After PR merged + CI green:
597
597
  Archive is a **deterministic CLI**, not an agent workflow:
598
598
 
599
599
  ```bash
600
- npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force]
600
+ npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force] [--collect]
601
601
  ```
602
602
 
603
- It checks the gates (APPROVE in `review.md` when required, all tasks `[x]`, target folder free), merges delta specs into `openspec/specs/` (`--sync`: ADDED append, MODIFIED replace, REMOVED delete), moves the change to `openspec/changes/archive/YYYY-MM-DD-<name>`, and runs `npx openspec validate --all --strict` with a full rollback on failure (main specs restored, new spec files deleted, move reverted). With delta specs present you must decide: `--sync` merges, `--no-sync --force` archives without merging, and no flag refuses with exit 1. It finishes by writing the final `handoff.md` (`next_command: none`) and updating memory. The `/opsx:archive` command is a thin wrapper that calls this CLI; the `spec-archiver` subagent remains only as a fallback when the CLI is unavailable.
603
+ It checks the gates (APPROVE in `review.md` when required, all tasks `[x]`, target folder free), merges delta specs into `openspec/specs/` (`--sync`: ADDED append, MODIFIED replace, REMOVED delete), moves the change to `openspec/changes/archive/YYYY-MM-DD-<name>`, and runs `npx openspec validate --all --strict` with a full rollback on failure (main specs restored, new spec files deleted, move reverted). With delta specs present you must decide: `--sync` merges, `--no-sync --force` archives without merging, and no flag refuses with exit 1. It finishes by writing the final `handoff.md` (`next_command: none`), updating memory, and printing the same human metrics summary as `metrics <name>`. Fill `## Metrics` in the change `handoff.md` before archive so the Archiver session can resolve platform / model / spend. `--collect` is optional. The `/opsx:archive` command is a thin wrapper that calls this CLI; the `spec-archiver` subagent remains only as a fallback when the CLI is unavailable.
604
604
 
605
605
  ## Configuration
606
606
 
@@ -801,19 +801,38 @@ Persist with `runtime: cloud` prints those four steps on stderr; stdout stays th
801
801
 
802
802
  Every change accumulates git-tracked `openspec/changes/<name>/metrics.json` — the data source for planning the next feature: how long each phase took, how many sessions it needed, what it cost.
803
803
 
804
+ - **`## Metrics` self-report** — Session Exit fills `handoff.md` with `platform`, `model`, `input_tokens`, `output_tokens`, `cost_usd`, `amp_credits`, `spend_source` (`unknown` when missing). Persist reads that section; `metrics.json` is the source of truth for what landed. CLI flags do not rewrite the section.
805
+ - **`session.model`** — `--model` → `## Metrics: model` → `AOK_MODEL` → collected sources (only with `--collect`) → `null` (stderr warning). Never a Closed role.
804
806
  - **Session start** — `handoff --restore` writes a `pending` marker (`startedAt`, expected role).
805
- - **Session end** — `handoff <name>` closes the pending session: duration, closed role, mapped phase (`explore` / `design` / `spec` / `review` / `apply` / `archive`), runtime (local/cloud), tasks snapshot (`n/m`), and when the agent passes them `--model`, `--input-tokens`, `--output-tokens`, `--total-tokens`, `--cost-usd`. No restore marker? Pass `--started-at <iso>` or the duration stays honestly `null`.
806
- - **Archive** — `archive <name>` sets `archivedAt` and clears any pending marker; the file moves to the archive folder with the change.
807
+ - **Session end** — `handoff <name>` closes the pending session: duration, closed role, mapped phase (`explore` / `design` / `spec` / `review` / `apply` / `archive`), runtime (local/cloud), tasks snapshot (`n/m`), and spend from flags self-report optional `--collect` adapters. `--input-tokens` / `--output-tokens` / `--total-tokens` / `--cost-usd` override session totals only and do not wipe `spendByPlatform` / `spendByModel`. Never guess. Never invent USD from Amp credits. Never Cursor SDK / npm sqlite / a pricing table. No restore marker? Pass `--started-at <iso>` or the duration stays honestly `null`.
808
+ - **Archive** — successful `archive <name>` always creates or finalizes `metrics.json`, sets `archivedAt`, appends an Archiver session from the archived `## Metrics` (or archive flags), prints the same human summary as `metrics <name>`, and collects adapters only with `--collect`.
809
+ - **Platform** — `--platform` → `## Metrics: platform` → `AOK_PLATFORM` → host env (Amp / Cursor / Claude Code) → collected sources (`cursor|claude|amp` only). Invalid `--platform` fails before persist/move.
810
+ - **Cursor spend hook (optional)** — Cursor never writes token usage to disk, so the kit can install `scripts/cursor-spend-hook.cjs` plus `.cursor/hooks.json` entries (`stop` / `subagentStop` / `afterAgentResponse`) in `init` / `update` / `sync` / `mcp-setup`: the hook appends each turn's tokens to gitignored `.agents/spend/cursor-usage.jsonl`. Collect is opt-in (`handoff`/`archive`/`metrics --collect`). Persist and restore do not self-heal the hook. `sessionEnd` still runs `scripts/cursor-spend-collect.cjs`. Restart Cursor once after the first install. `status` shows a `Spend capture` section. Claude (`~/.claude/projects/*.jsonl`) and Amp (`~/.local/share/amp/threads/*.json`) already persist usage locally and need no hook.
807
811
 
808
- Aggregates are recomputed on every write: per-phase totals (`durationMs`, tokens, `costUsd`, `sessions`, agents, models) plus overall `totals` (`sessions`, `cloudSessions`, `durationMs` = sum of session work time, `leadTimeMs` = wall clock from first session start to last session end) and `spend` (token/cost sums). Numbers are null-honest: a metric nobody reported stays `null`, never a fake `0`.
812
+ Aggregates are recomputed on every write: per-phase totals (`durationMs`, tokens, `costUsd`, `sessions`, `roles`, `models`) plus overall `totals` (`sessions`, `cloudSessions`, `durationMs` = sum of session work time, `leadTimeMs` = wall clock from first session start to last session end), `spend` (USD only), and separate **by platform** / **by model** tables. Numbers are null-honest: a metric nobody reported stays `null`, never a fake `0`. No single total that adds Amp credits to USD.
813
+
814
+ Fill `## Metrics` in `handoff.md` **before** persist (unknown is fine; do not invent `0`):
815
+
816
+ ```markdown
817
+ ## Metrics
818
+ - platform: cursor
819
+ - model: cursor-grok-4.6
820
+ - input_tokens: 128000
821
+ - output_tokens: 9400
822
+ - cost_usd: unknown
823
+ - amp_credits: unknown
824
+ - spend_source: self-report
825
+ ```
809
826
 
810
827
  ```bash
811
- npx agent-orchestrator-kit handoff add-thing --input-tokens 12000 --output-tokens 3000 --cost-usd 0.42 --model claude-sonnet
812
- npx agent-orchestrator-kit metrics add-thing # human summary: phases, tokens, cost, agents
813
- npx agent-orchestrator-kit metrics add-thing --json # raw metrics.json (works for archived changes too)
828
+ npx agent-orchestrator-kit handoff add-thing
829
+ npx agent-orchestrator-kit handoff add-thing --collect # optional: Claude JSONL / Amp threads / Cursor hook
830
+ npx agent-orchestrator-kit metrics add-thing # human summary: phases, tokens, cost, roles / models
831
+ npx agent-orchestrator-kit metrics add-thing --json # raw metrics.json (works for archived changes too)
832
+ npx agent-orchestrator-kit archive add-thing --sync # finalize + the same tables as metrics
814
833
  ```
815
834
 
816
- Recording is on by default and never blocks persist; opt out per session with `--no-metrics`.
835
+ Recording is on by default and never a persist/archive/`gate-check` gate; opt out per persist with `--no-metrics`. Adapters run only with `--collect`. Flags (`--model`, `--platform`, `--input-tokens`, …) override session totals in `metrics.json` and do not rewrite the `## Metrics` section.
817
836
 
818
837
  ### Skill inventory
819
838
 
@@ -912,9 +931,10 @@ npx agent-orchestrator-kit hooks-setup
912
931
  npx agent-orchestrator-kit mcp-setup [--vcs github|gitlab] [--no-browser]
913
932
  Install GitHub/GitLab (from origin) and browser MCP launchers
914
933
 
915
- npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force]
934
+ npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force] [--collect]
916
935
  Gate-check a completed change, optionally merge delta specs, move to
917
- openspec/changes/archive/YYYY-MM-DD-<name>, validate, write final handoff
936
+ openspec/changes/archive/YYYY-MM-DD-<name>, validate, write final handoff,
937
+ and print the change-wide metrics summary. --collect also runs adapters.
918
938
 
919
939
  npx agent-orchestrator-kit handoff [change-name] [options]
920
940
  --restore Print the restore briefing instead of persisting
@@ -924,15 +944,18 @@ npx agent-orchestrator-kit handoff [change-name] [options]
924
944
  --cloud-check Verify change artifacts are committed and pushed
925
945
  (cloud: non-zero on failure; local: warning, exit 0)
926
946
  --started-at <iso> Session start override when --restore was not run
927
- --model <name> Model used in this session (metrics.json)
947
+ --model <name> LLM product id (metrics.json); never a Closed role
948
+ --platform <id> cursor | claude | amp
928
949
  --input-tokens <n> / --output-tokens <n> / --total-tokens <n>
929
950
  Token spend for this session (total defaults to in+out)
930
951
  --cost-usd <usd> Session cost in USD
952
+ --collect Also run local spend adapters (off by default)
931
953
  --no-metrics Skip recording this session into metrics.json
932
954
 
933
- npx agent-orchestrator-kit metrics [change-name] [--json]
955
+ npx agent-orchestrator-kit metrics [change-name] [--json] [--collect]
934
956
  Show recorded session metrics for a change (active or archived):
935
- time per phase, sessions, tokens, cost, agents, models, lead time
957
+ time per phase, sessions, tokens, cost, roles, models, lead time.
958
+ --collect backfills the last session from adapters without adding a session.
936
959
  ```
937
960
 
938
961
  ## Directory Reference
@@ -979,6 +1002,18 @@ Phase bounds and non-goals: [`openspec/specs/agentic-factory-roadmap/spec.md`](o
979
1002
 
980
1003
  ## Changelog
981
1004
 
1005
+ ### 0.7.0
1006
+ - **`## Metrics` self-report** — persist reads the session section in `handoff.md`; `metrics.json` is the source of truth; CLI flags do not rewrite the section
1007
+ - **BREAKING** — `--no-collect` removed; `handoff` and `archive` collect local adapters only with opt-in `--collect`
1008
+ - Archive prints the same human summary as `metrics <name>` (by phase / platform / model, `spendSource`, unreported count)
1009
+ - Cursor spend hook is optional setup (`init` / `update` / `sync` / `mcp-setup`); persist and restore no longer self-heal `.cursor/hooks.json`
1010
+
1011
+ ### 0.6.0
1012
+ - **Mandatory Cursor spend hook** — `scripts/cursor-spend-hook.cjs` + `.cursor/hooks.json` (`stop` / `subagentStop` / `afterAgentResponse`) write `.agents/spend/cursor-usage.jsonl`; `sessionEnd` + `metrics --collect` backfill the last session; installed by `init` / `update` / `sync` / `mcp-setup` and self-healed on `handoff`
1013
+ - Persist/archive auto-collect local usage from Claude JSONL, Amp threads, and the Cursor hook file into `spendByPlatform` / `spendByModel`
1014
+ - Amp source ids namespaced as `<threadId>:<messageId>` so thread-local counters do not collide
1015
+ - `status` prints a `Spend capture` section
1016
+
982
1017
  ### 0.5.0
983
1018
  - **Change metrics** — git-tracked `openspec/changes/<name>/metrics.json` (session start on `handoff --restore`, close on persist)
984
1019
  - **`metrics` CLI** — human summary or `--json`; phases, tokens, cost, agents, models, lead time