agent-orchestrator-kit 0.6.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,26 @@ 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
+
7
27
  ## [0.6.0] - 2026-08-29
8
28
 
9
29
  ### Added
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 (auto-collect spend + Cursor hook in v0.6.0+, 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,22 +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
- - **`session.model`** LLM product id. Primary from collected sources, otherwise `--model` `AOK_MODEL` `null` (stderr warning). Never a Closed role.
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.
805
806
  - **Session start** — `handoff --restore` writes a `pending` marker (`startedAt`, expected role).
806
- - **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 persist/archive auto-collect local usage from Claude JSONL, Amp threads, and the Cursor spend hook file (.agents/spend/cursor-usage.jsonl). `--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`.
807
- - **Archive** — successful `archive <name>` always creates or finalizes `metrics.json`, sets `archivedAt`, appends an Archiver session, and runs collect unless `--no-collect`.
808
- - **Platform** — optional `--platform` / `AOK_PLATFORM` (`cursor|claude|amp` only). Invalid `--platform` fails before persist/move.
809
- - **Cursor spend hook (mandatory)** — Cursor never writes token usage to disk, so the kit installs `scripts/cursor-spend-hook.cjs` plus a `.cursor/hooks.json` entry (`stop` + `subagentStop`) in every project: the hook appends each turn's `input_tokens` / `output_tokens` / model from the hook payload to gitignored `.agents/spend/cursor-usage.jsonl`, and collect reads it (`source: "cursor-hook"`). Installed by `init` / `update` / `sync` / `mcp-setup` and self-healed on every `handoff` restore/persist — no manual step, no flags. 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
+ - **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.
810
811
 
811
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.
812
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
+ ```
826
+
813
827
  ```bash
814
- npx agent-orchestrator-kit handoff add-thing --input-tokens 12000 --output-tokens 3000 --cost-usd 0.42 --model claude-sonnet
815
- npx agent-orchestrator-kit metrics add-thing # human summary: phases, tokens, cost, roles / models
816
- 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
817
833
  ```
818
834
 
819
- Recording is on by default and never a persist/archive/`gate-check` gate; opt out per persist with `--no-metrics`. `--no-collect` skips adapters only.
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.
820
836
 
821
837
  ### Skill inventory
822
838
 
@@ -915,9 +931,10 @@ npx agent-orchestrator-kit hooks-setup
915
931
  npx agent-orchestrator-kit mcp-setup [--vcs github|gitlab] [--no-browser]
916
932
  Install GitHub/GitLab (from origin) and browser MCP launchers
917
933
 
918
- npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force]
934
+ npx agent-orchestrator-kit archive <name> [--sync | --no-sync --force] [--collect]
919
935
  Gate-check a completed change, optionally merge delta specs, move to
920
- 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.
921
938
 
922
939
  npx agent-orchestrator-kit handoff [change-name] [options]
923
940
  --restore Print the restore briefing instead of persisting
@@ -927,15 +944,18 @@ npx agent-orchestrator-kit handoff [change-name] [options]
927
944
  --cloud-check Verify change artifacts are committed and pushed
928
945
  (cloud: non-zero on failure; local: warning, exit 0)
929
946
  --started-at <iso> Session start override when --restore was not run
930
- --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
931
949
  --input-tokens <n> / --output-tokens <n> / --total-tokens <n>
932
950
  Token spend for this session (total defaults to in+out)
933
951
  --cost-usd <usd> Session cost in USD
952
+ --collect Also run local spend adapters (off by default)
934
953
  --no-metrics Skip recording this session into metrics.json
935
954
 
936
- npx agent-orchestrator-kit metrics [change-name] [--json]
955
+ npx agent-orchestrator-kit metrics [change-name] [--json] [--collect]
937
956
  Show recorded session metrics for a change (active or archived):
938
- time per phase, sessions, tokens, cost, roles, 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.
939
959
  ```
940
960
 
941
961
  ## Directory Reference
@@ -982,8 +1002,14 @@ Phase bounds and non-goals: [`openspec/specs/agentic-factory-roadmap/spec.md`](o
982
1002
 
983
1003
  ## Changelog
984
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
+
985
1011
  ### 0.6.0
986
- - **Mandatory Cursor spend hook** — `scripts/cursor-spend-hook.cjs` + `.cursor/hooks.json` (`stop` / `subagentStop`) write `.agents/spend/cursor-usage.jsonl`; installed by `init` / `update` / `sync` / `mcp-setup` and self-healed on `handoff`
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`
987
1013
  - Persist/archive auto-collect local usage from Claude JSONL, Amp threads, and the Cursor hook file into `spendByPlatform` / `spendByModel`
988
1014
  - Amp source ids namespaced as `<threadId>:<messageId>` so thread-local counters do not collide
989
1015
  - `status` prints a `Spend capture` section