harnessed 4.48.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
@@ -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
@@ -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