harnessed 4.47.0 → 4.49.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/README-en.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="./assets/logo.svg" alt="harnessed" width="440">
3
3
  </p>
4
4
 
5
- **English** | [简体中文](./README-cn.md) | [繁體中文](./README-tw.md) | [日本語](./README-ja.md) | [한국어](./README-ko.md) | [Português (Brasil)](./README-pt-BR.md) | [Türkçe](./README-tr.md) | [Русский](./README-ru.md) | [Tiếng Việt](./README-vi.md) | [ไทย](./README-th.md)
5
+ **English** | [简体中文](./README.md) | [繁體中文](./README-tw.md) | [日本語](./README-ja.md) | [한국어](./README-ko.md) | [Português (Brasil)](./README-pt-BR.md) | [Türkçe](./README-tr.md) | [Русский](./README-ru.md) | [Tiếng Việt](./README-vi.md) | [ไทย](./README-th.md)
6
6
 
7
7
  > _AI coding harness package manager + composition orchestrator_ — it assembles the best of the open-source ecosystem into one executable engine, wired by the three-layer **BDD → SDD → TDD** methodology.
8
8
 
@@ -16,6 +16,67 @@
16
16
 
17
17
  ---
18
18
 
19
+ ## 📦 Quick Install
20
+
21
+ **Via npm** (recommended — both channels are first-class and stay in sync):
22
+
23
+ ```bash
24
+ npm install -g harnessed && harnessed setup
25
+ ```
26
+
27
+ > Windows PowerShell 5.x does not support `&&` chaining — use `;` or two lines (`npm install -g harnessed; harnessed setup`). bash / zsh / PowerShell 7+ / cmd.exe all work normally.
28
+
29
+ **No Node.js? Standalone binary** — per-platform, self-updates via `harnessed update`:
30
+
31
+ ```bash
32
+ # macOS (Apple Silicon) / Linux (x64)
33
+ curl -fsSL https://raw.githubusercontent.com/easyinplay/harnessed/main/install.sh | bash
34
+ ```
35
+
36
+ ```powershell
37
+ # Windows (x64)
38
+ irm https://raw.githubusercontent.com/easyinplay/harnessed/main/install.ps1 | iex
39
+ ```
40
+
41
+ 🤖 **Or have an AI install it for you** — paste this sentence to Claude Code (or any AI assistant):
42
+
43
+ > Install harnessed for me following the guide at `https://github.com/easyinplay/harnessed/blob/main/INSTALL-WITH-AI.md`
44
+
45
+ The AI will auto-fetch the doc + run the install, handling OS / permissions / PATH / corepack edge cases — no need to copy large chunks of text.
46
+
47
+ > [!TIP]
48
+ > 🚀 **The much-loved Agent Teams and Subagent features are auto-enabled in harnessed based on the task!**
49
+ > No need to manually configure `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` — `harnessed setup` writes it to `~/.claude/settings.json` automatically. Pattern A full-stack three-way / Pattern C 4-specialist and other multi-agent workflows work out of the box.
50
+
51
+ ---
52
+
53
+ ## ⏱️ First 5 Minutes
54
+
55
+ The shortest path from zero to a running workflow:
56
+
57
+ ```
58
+ # 1. Inside Claude Code — kick off your first workflow
59
+ /auto "your first requirement" # newcomer default: runs all stages end-to-end
60
+ ```
61
+
62
+ ```bash
63
+ # 2. Lost? Run harnessed with no arguments — it tells you where you are + what's next
64
+ harnessed
65
+ # → you-are-here dashboard (active phase + per-step status) + a NEXT: auto|manual|done line
66
+ # no need to remember status / next / resume — one command (comet `/comet` analog, read-only)
67
+ # add --json for machine-readable output
68
+ ```
69
+
70
+ ```bash
71
+ # 3. Resume any time after an interruption
72
+ harnessed # same you-are-here view
73
+ harnessed resume # continue from the latest checkpoint
74
+ ```
75
+
76
+ > Want finer control over which stage runs and when? See the 3 modes below.
77
+
78
+ ---
79
+
19
80
  ## ✨ TL;DR
20
81
 
21
82
  **How it works**: harnessed **assembles** the best open-source Claude Code agents (gstack, GSD, superpowers, planning-with-files) and **orchestrates** them into one workflow via opinionated composition skills. It does **not** vendor upstream code — manifests describe install/check, and composition skills conduct the multi-upstream collaboration (so an upstream upgrade is just a re-install, never a manual code sync).
@@ -83,13 +144,13 @@ Native agents give you primitives; harnessed wires them into a methodology. Wher
83
144
  | Dimension | Native Claude Code | Native Codex | harnessed |
84
145
  |---|---|---|---|
85
146
  | **Workflow / methodology** | Primitives only — you design the flow each time | Fewer primitives — freestyle per prompt | Codified **Discuss→Ship** 5-stage three-layer-stack engine — BDD + SDD + TDD loops + 2 cross-cutting (Review + Ship) |
86
- | **Instruction injection** | `CLAUDE.md` + skills + hooks exist, but static & wired by hand | `AGENTS.md` only — no skills/hooks | Per-turn breadcrumb hook + task-scoped routing + learnings injected each cycle |
147
+ | **Instruction injection** | `CLAUDE.md` + skills + hooks exist, but static & wired by hand | `AGENTS.md` + skills (`~/.agents/skills`) + hooks — also static & wired by hand | Per-turn breadcrumb hook + task-scoped routing + learnings injected each cycle |
87
148
  | **State / progress** | Chat context — lost on `/clear` / compaction | Chat context — no persistence layer | On-disk `.planning/` + `workflows.json` per-repo ledger + checkpoint evidence |
88
149
  | **Cross-session recovery** | Re-explain the context by hand | Re-explain the context by hand | `harnessed status --recover`: you-are-here + next step |
89
150
  | **Verification / "done"** | Agent self-reports "done" | Agent self-reports "done" | Independent review subagents + **fail-CLOSED evidence guard** (missing artifact = not done) |
90
- | **Subagent orchestration** | Subagents + Agent Teams available, but orchestrated by hand | No subagent/team primitive | `gates → prompt → spawn → checkpoint`; Agent Teams auto-enabled per task |
151
+ | **Subagent orchestration** | Subagents + Agent Teams available, but orchestrated by hand | `spawn_agent` / `send_input` / `wait_agent` exist — also orchestrated by hand; no Agent-Teams equivalent | `gates → prompt → spawn → checkpoint`; Agent Teams auto-enabled per task |
91
152
  | **Learning loop** | None | None | `LEARNINGS.md` auto-captured + injected into the next cycle |
92
- | **Platform reach** | Claude Code only | Codex only | **Cross-harness** — Claude Code primary, Codex via platform layer |
153
+ | **Platform reach** | Claude Code only | Codex only | **Cross-harness** — Claude Code and Codex both first-class (hooks / agent roles / spawn dispatch / `doctor --matrix` / host-rendered prose) |
93
154
 
94
155
  > Native agents win on zero-setup, zero-overhead for trivial one-off edits. harnessed earns its keep the moment work spans multiple steps, sessions, or subagents — where freestyle drift and lost-in-chat state start costing you.
95
156
 
@@ -97,67 +158,6 @@ Native agents give you primitives; harnessed wires them into a methodology. Wher
97
158
 
98
159
  ---
99
160
 
100
- ## 📦 Quick Install
101
-
102
- **Via npm** (recommended — both channels are first-class and stay in sync):
103
-
104
- ```bash
105
- npm install -g harnessed && harnessed setup
106
- ```
107
-
108
- > Windows PowerShell 5.x does not support `&&` chaining — use `;` or two lines (`npm install -g harnessed; harnessed setup`). bash / zsh / PowerShell 7+ / cmd.exe all work normally.
109
-
110
- **No Node.js? Standalone binary** — per-platform, self-updates via `harnessed update`:
111
-
112
- ```bash
113
- # macOS (Apple Silicon) / Linux (x64)
114
- curl -fsSL https://raw.githubusercontent.com/easyinplay/harnessed/main/install.sh | bash
115
- ```
116
-
117
- ```powershell
118
- # Windows (x64)
119
- irm https://raw.githubusercontent.com/easyinplay/harnessed/main/install.ps1 | iex
120
- ```
121
-
122
- 🤖 **Or have an AI install it for you** — paste this sentence to Claude Code (or any AI assistant):
123
-
124
- > Install harnessed for me following the guide at `https://github.com/easyinplay/harnessed/blob/main/INSTALL-WITH-AI.md`
125
-
126
- The AI will auto-fetch the doc + run the install, handling OS / permissions / PATH / corepack edge cases — no need to copy large chunks of text.
127
-
128
- > [!TIP]
129
- > 🚀 **The much-loved Agent Teams and Subagent features are auto-enabled in harnessed based on the task!**
130
- > No need to manually configure `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` — `harnessed setup` writes it to `~/.claude/settings.json` automatically. Pattern A full-stack three-way / Pattern C 4-specialist and other multi-agent workflows work out of the box.
131
-
132
- ---
133
-
134
- ## ⏱️ First 5 Minutes
135
-
136
- The shortest path from zero to a running workflow:
137
-
138
- ```
139
- # 1. Inside Claude Code — kick off your first workflow
140
- /auto "your first requirement" # newcomer default: runs all stages end-to-end
141
- ```
142
-
143
- ```bash
144
- # 2. Lost? Run harnessed with no arguments — it tells you where you are + what's next
145
- harnessed
146
- # → you-are-here dashboard (active phase + per-step status) + a NEXT: auto|manual|done line
147
- # no need to remember status / next / resume — one command (comet `/comet` analog, read-only)
148
- # add --json for machine-readable output
149
- ```
150
-
151
- ```bash
152
- # 3. Resume any time after an interruption
153
- harnessed # same you-are-here view
154
- harnessed resume # continue from the latest checkpoint
155
- ```
156
-
157
- > Want finer control over which stage runs and when? See the 3 modes below.
158
-
159
- ---
160
-
161
161
  ## 🚀 Quick Start — 3 Options
162
162
 
163
163
  In order of increasing user intervention:
@@ -491,6 +491,7 @@ planning-with-files /plan (cross-cutting tool) → write artifacts to .planning/
491
491
  | `harnessed gates <master>` | Evaluate which sub-workflows fire for a master stage (JSON: fire/skip/parallelism). Used by slash commands to orchestrate native spawns. |
492
492
  | `harnessed prompt <sub>` | Output a spawn-ready prompt (role + checklist + disciplines + completion/clarification protocols) for a sub-workflow. |
493
493
  | `harnessed checkpoint <action> <sub>` | Record sub-workflow start/complete/fail to `~/.claude/harnessed/checkpoints/`. |
494
+ | `harnessed checkpoint adopt [--from <host>]` | Cross-host relay: read-only copy of the other host's active workflow slot into this host's state root; the source is never modified; `--from <host>` overrides the inferred source host. |
494
495
  | `harnessed` (no args) | Zero-arg you-are-here: active-workflow dashboard + `NEXT: auto\|manual\|done` + run hint; `--json` machine-readable; no active workflow → onboarding hint (comet `/comet` analog, read-only). |
495
496
  | `harnessed next` | Deterministic next-step contract. Within a workflow: `NEXT: auto\|manual\|done`. When the workflow's subs are all resolved it falls through to the next **cross-unit** (next phase/task derived from `.planning/` disk state) with an exit-code contract (`0` advance · `2` done · `10` blocked). |
496
497
  | `harnessed advance` | Forward continuation — print the next work unit (next phase/task) across the milestone and the command to run it. Print-only (the main session runs the next `/auto`); refuses to step past an incomplete earlier phase (`--force` overrides); `--json` drives a `while harnessed advance --json; do :; done` loop. |
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="./assets/logo.svg" alt="harnessed" width="440">
3
3
  </p>
4
4
 
5
- [English](./README.md) | **简体中文** | [繁體中文](./README-tw.md) | [日本語](./README-ja.md) | [한국어](./README-ko.md) | [Português (Brasil)](./README-pt-BR.md) | [Türkçe](./README-tr.md) | [Русский](./README-ru.md) | [Tiếng Việt](./README-vi.md) | [ไทย](./README-th.md)
5
+ [English](./README-en.md) | **简体中文** | [繁體中文](./README-tw.md) | [日本語](./README-ja.md) | [한국어](./README-ko.md) | [Português (Brasil)](./README-pt-BR.md) | [Türkçe](./README-tr.md) | [Русский](./README-ru.md) | [Tiếng Việt](./README-vi.md) | [ไทย](./README-th.md)
6
6
 
7
7
  > _AI coding harness 包管理器 + composition orchestrator_ —— 它把开源生态最优秀的组件装配成一个可执行的 engine,由三层 **BDD → SDD → TDD** 方法论接线。
8
8
 
@@ -16,6 +16,67 @@
16
16
 
17
17
  ---
18
18
 
19
+ ## 📦 快速安装
20
+
21
+ **走 npm**(推荐 —— 两条通道同为一等公民,版本保持同步):
22
+
23
+ ```bash
24
+ npm install -g harnessed && harnessed setup
25
+ ```
26
+
27
+ > Windows PowerShell 5.x 不支持 `&&` 链接 —— 改用 `;` 或分两行 (`npm install -g harnessed; harnessed setup`)。bash / zsh / PowerShell 7+ / cmd.exe 都正常。
28
+
29
+ **没有 Node.js?独立二进制** —— 分平台安装,后续用 `harnessed update` 自更新:
30
+
31
+ ```bash
32
+ # macOS (Apple Silicon) / Linux (x64)
33
+ curl -fsSL https://raw.githubusercontent.com/easyinplay/harnessed/main/install.sh | bash
34
+ ```
35
+
36
+ ```powershell
37
+ # Windows (x64)
38
+ irm https://raw.githubusercontent.com/easyinplay/harnessed/main/install.ps1 | iex
39
+ ```
40
+
41
+ 🤖 **或让 AI 帮你装** —— 把下面这句话发给 Claude Code (或任何 AI 助手):
42
+
43
+ > Install harnessed for me following the guide at `https://github.com/easyinplay/harnessed/blob/main/INSTALL-WITH-AI.md`
44
+
45
+ AI 会自动 fetch 文档 + 跑安装,处理 OS / 权限 / PATH / corepack 等 edge case —— 无需复制大段文字。
46
+
47
+ > [!TIP]
48
+ > 🚀 **很多人喜爱的 Agent Teams 和 Subagent 功能,在 harnessed 中会根据任务自动启用!**
49
+ > 无需手动配置 `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` —— `harnessed setup` 会自动写入 `~/.claude/settings.json`。Pattern A 全栈三路 / Pattern C 4-specialist 等 multi-agent workflow 即开即用。
50
+
51
+ ---
52
+
53
+ ## ⏱️ First 5 Minutes
54
+
55
+ 从零到一条运转中的 workflow,最短路径:
56
+
57
+ ```
58
+ # 1. 在 Claude Code 内 —— 启动你的第一条 workflow
59
+ /auto "你的第一个需求" # 新手默认: 端到端跑完所有 stage
60
+ ```
61
+
62
+ ```bash
63
+ # 2. 迷路了? 不带参数跑 harnessed —— 它会告诉你身在何处 + 下一步是什么
64
+ harnessed
65
+ # → you-are-here 仪表盘 (active phase + 每步状态) + 一行 NEXT: auto|manual|done
66
+ # 不必记 status / next / resume —— 一个命令 (comet `/comet` 类比,read-only)
67
+ # 加 --json 输出机器可读格式
68
+ ```
69
+
70
+ ```bash
71
+ # 3. 中断后随时恢复
72
+ harnessed # 同一个 you-are-here 视图
73
+ harnessed resume # 从最近 checkpoint 继续
74
+ ```
75
+
76
+ > 想更精细地控制哪个 stage 何时跑? 看下面 3 种模式。
77
+
78
+ ---
79
+
19
80
  ## ✨ TL;DR
20
81
 
21
82
  **它怎么运作**: harnessed **装配** 市面上最优秀的开源 Claude Code agent (gstack、GSD、superpowers、planning-with-files),再用强意见 composition skill 把它们 **编排** 成一条工作流。它 **不** vendor 上游代码 —— manifest 描述 install/check,composition skill 指挥多上游协作 (所以上游升级只是一次 re-install,从不需要手动 sync code)。
@@ -83,79 +144,18 @@ harnessed 的三层栈方案是软件工程上既有的 **BDD → SDD → TDD**
83
144
  | 维度 | 原生 Claude Code | 原生 Codex | harnessed |
84
145
  |---|---|---|---|
85
146
  | **工作流 / 方法论** | 只有原语 —— 每次自己设计流程 | 原语更少 —— 每条 prompt 即兴发挥 | 编码化的 **Discuss→Ship** 5-stage 三层栈 engine —— BDD + SDD + TDD 循环 + 2 横切 (Review + Ship) |
86
- | **指令注入** | `CLAUDE.md` + skill + hook 存在,但静态、得手工接线 | 只有 `AGENTS.md` —— 无 skill/hook | 每轮 breadcrumb hook + task-scoped 路由 + 每轮注入 learnings |
147
+ | **指令注入** | `CLAUDE.md` + skill + hook 存在,但静态、得手工接线 | `AGENTS.md` + skills(`~/.agents/skills`)+ hook —— 同样静态、得手工接线 | 每轮 breadcrumb hook + task-scoped 路由 + 每轮注入 learnings |
87
148
  | **状态 / 进度** | 对话 context —— `/clear` / compaction 即丢失 | 对话 context —— 无持久化层 | 落盘 `.planning/` + 每 repo 一份的 `workflows.json` ledger + checkpoint 证据 |
88
149
  | **跨 session 恢复** | 手工重新解释 context | 手工重新解释 context | `harnessed status --recover`: you-are-here + 下一步 |
89
150
  | **验证 / 「完成」** | agent 自报「完成」 | agent 自报「完成」 | 独立审查 subagent + **fail-CLOSED 证据 guard** (缺产物 = 没完成) |
90
- | **Subagent 编排** | 有 subagent + Agent Teams,但得手工编排 | 无 subagent/team 原语 | `gates → prompt → spawn → checkpoint`;Agent Teams 按任务自动启用 |
151
+ | **Subagent 编排** | 有 subagent + Agent Teams,但得手工编排 | 有 `spawn_agent` / `send_input` / `wait_agent` —— 同样得手工编排;无 Agent Teams 对等物 | `gates → prompt → spawn → checkpoint`;Agent Teams 按任务自动启用 |
91
152
  | **学习循环** | 无 | 无 | `LEARNINGS.md` 自动捕获 + 注入下一轮 |
92
- | **平台覆盖** | 仅 Claude Code | 仅 Codex | **Cross-harness** —— Claude Code 主力,Codex 经 platform 层 |
153
+ | **平台覆盖** | 仅 Claude Code | 仅 Codex | **Cross-harness** —— Claude Code 与 Codex 均为一等宿主(hook / agent role / spawn 分派 / `doctor --matrix` / 正文按宿主渲染) |
93
154
 
94
155
  > 原生 agent 在零配置、零开销的琐碎一次性改动上取胜。一旦工作跨越多步骤、多 session 或多 subagent —— 即兴漂移和迷失在对话里的状态开始让你付出代价 —— harnessed 就开始挣回它的价值。
95
156
 
96
157
  ---
97
158
 
98
- ## 📦 快速安装
99
-
100
- **走 npm**(推荐 —— 两条通道同为一等公民,版本保持同步):
101
-
102
- ```bash
103
- npm install -g harnessed && harnessed setup
104
- ```
105
-
106
- > Windows PowerShell 5.x 不支持 `&&` 链接 —— 改用 `;` 或分两行 (`npm install -g harnessed; harnessed setup`)。bash / zsh / PowerShell 7+ / cmd.exe 都正常。
107
-
108
- **没有 Node.js?独立二进制** —— 分平台安装,后续用 `harnessed update` 自更新:
109
-
110
- ```bash
111
- # macOS (Apple Silicon) / Linux (x64)
112
- curl -fsSL https://raw.githubusercontent.com/easyinplay/harnessed/main/install.sh | bash
113
- ```
114
-
115
- ```powershell
116
- # Windows (x64)
117
- irm https://raw.githubusercontent.com/easyinplay/harnessed/main/install.ps1 | iex
118
- ```
119
-
120
- 🤖 **或让 AI 帮你装** —— 把下面这句话发给 Claude Code (或任何 AI 助手):
121
-
122
- > Install harnessed for me following the guide at `https://github.com/easyinplay/harnessed/blob/main/INSTALL-WITH-AI.md`
123
-
124
- AI 会自动 fetch 文档 + 跑安装,处理 OS / 权限 / PATH / corepack 等 edge case —— 无需复制大段文字。
125
-
126
- > [!TIP]
127
- > 🚀 **很多人喜爱的 Agent Teams 和 Subagent 功能,在 harnessed 中会根据任务自动启用!**
128
- > 无需手动配置 `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` —— `harnessed setup` 会自动写入 `~/.claude/settings.json`。Pattern A 全栈三路 / Pattern C 4-specialist 等 multi-agent workflow 即开即用。
129
-
130
- ---
131
-
132
- ## ⏱️ First 5 Minutes
133
-
134
- 从零到一条运转中的 workflow,最短路径:
135
-
136
- ```
137
- # 1. 在 Claude Code 内 —— 启动你的第一条 workflow
138
- /auto "你的第一个需求" # 新手默认: 端到端跑完所有 stage
139
- ```
140
-
141
- ```bash
142
- # 2. 迷路了? 不带参数跑 harnessed —— 它会告诉你身在何处 + 下一步是什么
143
- harnessed
144
- # → you-are-here 仪表盘 (active phase + 每步状态) + 一行 NEXT: auto|manual|done
145
- # 不必记 status / next / resume —— 一个命令 (comet `/comet` 类比,read-only)
146
- # 加 --json 输出机器可读格式
147
- ```
148
-
149
- ```bash
150
- # 3. 中断后随时恢复
151
- harnessed # 同一个 you-are-here 视图
152
- harnessed resume # 从最近 checkpoint 继续
153
- ```
154
-
155
- > 想更精细地控制哪个 stage 何时跑? 看下面 3 种模式。
156
-
157
- ---
158
-
159
159
  ## 🚀 快捷使用 — 3 种选择
160
160
 
161
161
  按用户介入程度由低到高:
@@ -489,6 +489,7 @@ planning-with-files /plan (cross-cutting tool) → write artifacts to .planning/
489
489
  | `harnessed gates <master>` | 评估某 master stage 下哪些 sub-workflow 会 fire (JSON: fire/skip/parallelism)。供 slash command 编排 native spawn |
490
490
  | `harnessed prompt <sub>` | 输出某 sub-workflow 的 spawn-ready prompt (role + checklist + disciplines + completion/clarification 协议) |
491
491
  | `harnessed checkpoint <action> <sub>` | 记录 sub-workflow 的 start/complete/fail 到 `~/.claude/harnessed/checkpoints/` |
492
+ | `harnessed checkpoint adopt [--from <host>]` | 记录到当前宿主的状态根;跨宿主接力:把另一宿主的活跃 workflow 槽位只读复制过来,源不动,默认从另一宿主推断,`--from <host>` 指定 |
492
493
  | `harnessed` (无参数) | Zero-arg you-are-here: active-workflow 仪表盘 + `NEXT: auto\|manual\|done` + run hint;`--json` 机器可读;无 active workflow → onboarding hint (comet `/comet` 类比,read-only) |
493
494
  | `harnessed next` | 确定性的下一步契约。workflow 内: `NEXT: auto\|manual\|done`。当 workflow 的所有 sub 都已解决,它会落到下一 **cross-unit** (下一 phase/task,从 `.planning/` 磁盘状态派生),带 exit-code 契约 (`0` advance · `2` done · `10` blocked) |
494
495
  | `harnessed advance` | Forward continuation —— 打印跨 milestone 的下一工作单元 (下一 phase/task) 及运行它的命令。Print-only (由主 session 运行下一个 `/auto`);拒绝越过未完成的更早 phase (`--force` 覆盖);`--json` 驱动 `while harnessed advance --json; do :; done` 循环 |
@@ -54,10 +54,15 @@ function codexDescriptor(home = homedir()) {
54
54
  sessionIdEnv: 'CODEX_SESSION_ID',
55
55
  }
56
56
  }
57
+ var HOST_IDS = ['claude', 'codex']
58
+ function isHostId(id) {
59
+ return HOST_IDS.includes(id)
60
+ }
61
+ function descriptorFor(id, home = homedir()) {
62
+ return id === 'codex' ? codexDescriptor(home) : claudeDescriptor(home)
63
+ }
57
64
  function descriptorById(id, home) {
58
- if (id === 'claude') return claudeDescriptor(home)
59
- if (id === 'codex') return codexDescriptor(home)
60
- return void 0
65
+ return isHostId(id) ? descriptorFor(id, home) : void 0
61
66
  }
62
67
  function detectPlatform(home = homedir()) {
63
68
  const resolved = resolveHost(home)
@@ -66,27 +71,63 @@ function detectPlatform(home = homedir()) {
66
71
  return resolved
67
72
  }
68
73
  function resolveHost(home) {
74
+ return resolveHostWithReason(home).descriptor
75
+ }
76
+ function resolveHostWithReason(home = homedir()) {
69
77
  const base = claudeDescriptor(home)
78
+ const skipped = []
70
79
  const envPlatform = process.env.HARNESSED_PLATFORM
71
80
  if (envPlatform !== void 0 && envPlatform !== '') {
72
81
  const d = descriptorById(envPlatform, home)
73
- if (d) return d
82
+ if (d) {
83
+ return {
84
+ descriptor: d,
85
+ reason: { kind: 'env-platform', envVar: 'HARNESSED_PLATFORM', value: envPlatform },
86
+ skipped,
87
+ }
88
+ }
89
+ skipped.push({ kind: 'env-platform-unknown', envVar: 'HARNESSED_PLATFORM', value: envPlatform })
74
90
  }
75
91
  const inClaude = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim())
76
92
  const inCodex = Boolean(process.env.CODEX_SESSION_ID?.trim())
77
- if (inClaude !== inCodex) return inClaude ? base : codexDescriptor(home)
93
+ if (inClaude !== inCodex) {
94
+ return {
95
+ descriptor: inClaude ? base : codexDescriptor(home),
96
+ reason: {
97
+ kind: 'host-session-env',
98
+ envVar: inClaude ? 'CLAUDE_CODE_SESSION_ID' : 'CODEX_SESSION_ID',
99
+ },
100
+ skipped,
101
+ }
102
+ }
103
+ if (inClaude && inCodex) skipped.push({ kind: 'host-session-env-ambiguous' })
78
104
  for (const pinRoot of [codexDescriptor(home).stateRoot, base.stateRoot]) {
105
+ const pinPath = join(pinRoot, '.platform')
79
106
  try {
80
- const d = descriptorById(readFileSync(join(pinRoot, '.platform'), 'utf8').trim(), home)
81
- if (d) return d
107
+ const value = readFileSync(pinPath, 'utf8').trim()
108
+ const d = descriptorById(value, home)
109
+ if (d) return { descriptor: d, reason: { kind: 'platform-pin', pinPath, value }, skipped }
110
+ skipped.push({ kind: 'platform-pin-unknown', pinPath, value })
82
111
  } catch {}
83
112
  }
84
113
  try {
85
- if (existsSync(base.homeDir)) return base
114
+ if (existsSync(base.homeDir)) {
115
+ return {
116
+ descriptor: base,
117
+ reason: { kind: 'directory-probe', probedDir: base.homeDir },
118
+ skipped,
119
+ }
120
+ }
86
121
  const codex = codexDescriptor(home)
87
- if (existsSync(codex.homeDir)) return codex
122
+ if (existsSync(codex.homeDir)) {
123
+ return {
124
+ descriptor: codex,
125
+ reason: { kind: 'directory-probe', probedDir: codex.homeDir },
126
+ skipped,
127
+ }
128
+ }
88
129
  } catch {}
89
- return base
130
+ return { descriptor: base, reason: { kind: 'fallback' }, skipped }
90
131
  }
91
132
 
92
133
  // src/checkpoint/hookHost.ts
@@ -523,7 +564,7 @@ function forwardPointer(repoRoot, wf) {
523
564
  }
524
565
 
525
566
  // src/checkpoint/injectStateMain.ts
526
- function repoKey(cwd) {
567
+ function repoRootPath(cwd) {
527
568
  let dir = resolve(cwd)
528
569
  for (;;) {
529
570
  if (existsSync4(join5(dir, '.git'))) return dir
@@ -533,6 +574,10 @@ function repoKey(cwd) {
533
574
  }
534
575
  return resolve(cwd)
535
576
  }
577
+ function repoKey(cwd) {
578
+ const root = repoRootPath(cwd)
579
+ return process.platform === 'win32' ? root.toLowerCase() : root
580
+ }
536
581
  function readWorkflow(root, keys) {
537
582
  let wf = null
538
583
  let intent = null
@@ -591,20 +636,31 @@ async function main() {
591
636
  invalidateInjectCache(root)
592
637
  return
593
638
  }
594
- const key = repoKey(process.cwd())
639
+ const repoPath = repoRootPath(process.cwd())
640
+ const slotKey = repoKey(process.cwd())
595
641
  const envName = platform.sessionIdEnv
596
642
  const sid =
597
643
  (envName ? process.env[envName]?.trim() : void 0) ||
598
644
  (hostArg ? sessionIdFromPayload(await readHookStdin()) : void 0)
599
- const { wf, intent, ledgerAgeMs } = readWorkflow(root, sid ? [`${key}::${sid}`, key] : [key])
645
+ const { wf, intent, ledgerAgeMs } = readWorkflow(
646
+ root,
647
+ sid ? [`${slotKey}::${sid}`, slotKey] : [slotKey],
648
+ )
600
649
  let learningsMd = ''
601
650
  try {
602
- learningsMd = readFileSync5(join5(key, '.planning', 'LEARNINGS.md'), 'utf8')
651
+ learningsMd = readFileSync5(join5(repoPath, '.planning', 'LEARNINGS.md'), 'utf8')
603
652
  } catch {}
604
653
  const budget = Number(process.env.HARNESSED_INJECT_BUDGET) || DEFAULT_INJECT_BUDGET
605
654
  const pcOff = process.env.HARNESSED_INJECT_PC_OFF === '1'
606
- const pcGate = pcOff ? () => false : sid ? (pc) => shouldEmitPc(root, key, sid, pc) : void 0
607
- const out = buildInjection(key, wf, learningsMd, budget, intent, Date.now(), {
655
+ const pcGate = pcOff
656
+ ? () => false
657
+ : sid
658
+ ? // slotKey (folded): the PC-emission cache keys state, same reason as the
659
+ // ledger. Pre-upgrade entries keyed by the unfolded path simply become
660
+ // unreachable — at most one extra emission after upgrading.
661
+ (pc) => shouldEmitPc(root, slotKey, sid, pc)
662
+ : void 0
663
+ const out = buildInjection(repoPath, wf, learningsMd, budget, intent, Date.now(), {
608
664
  ledgerAgeMs,
609
665
  pcGate,
610
666
  })
@@ -59,10 +59,15 @@ function codexDescriptor(home = homedir()) {
59
59
  sessionIdEnv: 'CODEX_SESSION_ID',
60
60
  }
61
61
  }
62
+ var HOST_IDS = ['claude', 'codex']
63
+ function isHostId(id) {
64
+ return HOST_IDS.includes(id)
65
+ }
66
+ function descriptorFor(id, home = homedir()) {
67
+ return id === 'codex' ? codexDescriptor(home) : claudeDescriptor(home)
68
+ }
62
69
  function descriptorById(id, home) {
63
- if (id === 'claude') return claudeDescriptor(home)
64
- if (id === 'codex') return codexDescriptor(home)
65
- return void 0
70
+ return isHostId(id) ? descriptorFor(id, home) : void 0
66
71
  }
67
72
  function detectPlatform(home = homedir()) {
68
73
  const resolved = resolveHost(home)
@@ -71,27 +76,63 @@ function detectPlatform(home = homedir()) {
71
76
  return resolved
72
77
  }
73
78
  function resolveHost(home) {
79
+ return resolveHostWithReason(home).descriptor
80
+ }
81
+ function resolveHostWithReason(home = homedir()) {
74
82
  const base = claudeDescriptor(home)
83
+ const skipped = []
75
84
  const envPlatform = process.env.HARNESSED_PLATFORM
76
85
  if (envPlatform !== void 0 && envPlatform !== '') {
77
86
  const d = descriptorById(envPlatform, home)
78
- if (d) return d
87
+ if (d) {
88
+ return {
89
+ descriptor: d,
90
+ reason: { kind: 'env-platform', envVar: 'HARNESSED_PLATFORM', value: envPlatform },
91
+ skipped,
92
+ }
93
+ }
94
+ skipped.push({ kind: 'env-platform-unknown', envVar: 'HARNESSED_PLATFORM', value: envPlatform })
79
95
  }
80
96
  const inClaude = Boolean(process.env.CLAUDE_CODE_SESSION_ID?.trim())
81
97
  const inCodex = Boolean(process.env.CODEX_SESSION_ID?.trim())
82
- if (inClaude !== inCodex) return inClaude ? base : codexDescriptor(home)
98
+ if (inClaude !== inCodex) {
99
+ return {
100
+ descriptor: inClaude ? base : codexDescriptor(home),
101
+ reason: {
102
+ kind: 'host-session-env',
103
+ envVar: inClaude ? 'CLAUDE_CODE_SESSION_ID' : 'CODEX_SESSION_ID',
104
+ },
105
+ skipped,
106
+ }
107
+ }
108
+ if (inClaude && inCodex) skipped.push({ kind: 'host-session-env-ambiguous' })
83
109
  for (const pinRoot of [codexDescriptor(home).stateRoot, base.stateRoot]) {
110
+ const pinPath = join(pinRoot, '.platform')
84
111
  try {
85
- const d = descriptorById(readFileSync(join(pinRoot, '.platform'), 'utf8').trim(), home)
86
- if (d) return d
112
+ const value = readFileSync(pinPath, 'utf8').trim()
113
+ const d = descriptorById(value, home)
114
+ if (d) return { descriptor: d, reason: { kind: 'platform-pin', pinPath, value }, skipped }
115
+ skipped.push({ kind: 'platform-pin-unknown', pinPath, value })
87
116
  } catch {}
88
117
  }
89
118
  try {
90
- if (existsSync(base.homeDir)) return base
119
+ if (existsSync(base.homeDir)) {
120
+ return {
121
+ descriptor: base,
122
+ reason: { kind: 'directory-probe', probedDir: base.homeDir },
123
+ skipped,
124
+ }
125
+ }
91
126
  const codex = codexDescriptor(home)
92
- if (existsSync(codex.homeDir)) return codex
127
+ if (existsSync(codex.homeDir)) {
128
+ return {
129
+ descriptor: codex,
130
+ reason: { kind: 'directory-probe', probedDir: codex.homeDir },
131
+ skipped,
132
+ }
133
+ }
93
134
  } catch {}
94
- return base
135
+ return { descriptor: base, reason: { kind: 'fallback' }, skipped }
95
136
  }
96
137
 
97
138
  // src/checkpoint/modeBDetect.ts