harnessed 4.41.0 → 4.42.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/bin/harnessed-inject-state.mjs +71 -37
- package/bin/harnessed-stop-hook.mjs +45 -11
- package/dist/cli.mjs +686 -245
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/schemas/index.mjs +9 -9
- package/dist/schemas/index.mjs.map +1 -1
- package/manifests/SCHEMA.md +0 -3
- package/manifests/skill-packs/gsd.yaml +0 -3
- package/manifests/tools/superpowers.yaml +11 -5
- package/package.json +1 -1
- package/schemas/manifest.v1.schema.json +0 -24
|
@@ -5,19 +5,49 @@
|
|
|
5
5
|
|
|
6
6
|
// src/checkpoint/injectStateMain.ts
|
|
7
7
|
import { createHash as createHash2 } from "node:crypto";
|
|
8
|
-
import { existsSync as
|
|
9
|
-
import {
|
|
10
|
-
import { dirname, join as join4, resolve } from 'node:path'
|
|
8
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, statSync } from 'node:fs'
|
|
9
|
+
import { dirname, join as join5, resolve } from 'node:path'
|
|
11
10
|
|
|
12
11
|
// src/platform/ablation.ts
|
|
13
12
|
function isAblated(env = process.env) {
|
|
14
13
|
return env.HARNESSED_OFF === '1'
|
|
15
14
|
}
|
|
16
15
|
|
|
16
|
+
// src/checkpoint/hookStateRoot.ts
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
18
|
+
import { homedir } from 'node:os'
|
|
19
|
+
import { join } from 'node:path'
|
|
20
|
+
function hookStateRoot(home = homedir()) {
|
|
21
|
+
const override = process.env.HARNESSED_ROOT_OVERRIDE
|
|
22
|
+
if (override !== void 0 && override !== '') return override
|
|
23
|
+
const claudeHome = join(home, '.claude')
|
|
24
|
+
const codexHome = join(home, '.codex')
|
|
25
|
+
const rootOf = (id) =>
|
|
26
|
+
id === 'claude'
|
|
27
|
+
? join(claudeHome, 'harnessed')
|
|
28
|
+
: id === 'codex'
|
|
29
|
+
? join(codexHome, 'harnessed')
|
|
30
|
+
: null
|
|
31
|
+
const env = process.env.HARNESSED_PLATFORM
|
|
32
|
+
if (env !== void 0 && env !== '') {
|
|
33
|
+
const r = rootOf(env)
|
|
34
|
+
if (r) return r
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const r = rootOf(readFileSync(join(claudeHome, 'harnessed', '.platform'), 'utf8').trim())
|
|
38
|
+
if (r) return r
|
|
39
|
+
} catch {}
|
|
40
|
+
try {
|
|
41
|
+
if (existsSync(claudeHome)) return join(claudeHome, 'harnessed')
|
|
42
|
+
if (existsSync(codexHome)) return join(codexHome, 'harnessed')
|
|
43
|
+
} catch {}
|
|
44
|
+
return join(claudeHome, 'harnessed')
|
|
45
|
+
}
|
|
46
|
+
|
|
17
47
|
// src/checkpoint/injectCache.ts
|
|
18
48
|
import { createHash } from 'node:crypto'
|
|
19
|
-
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
20
|
-
import { join } from 'node:path'
|
|
49
|
+
import { mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync } from 'node:fs'
|
|
50
|
+
import { join as join2 } from 'node:path'
|
|
21
51
|
var DEFAULT_REFRESH_TURNS = 10
|
|
22
52
|
function decidePcEmission(cache, pcHash, refreshN, nowMs) {
|
|
23
53
|
if (cache && cache.pcHash === pcHash && cache.turns < refreshN) {
|
|
@@ -33,11 +63,11 @@ function injectCacheKey(repoKey2, sid) {
|
|
|
33
63
|
return createHash('sha256').update(`${repoKey2}::${sid}`).digest('hex').slice(0, 16)
|
|
34
64
|
}
|
|
35
65
|
function cacheFile(root, key) {
|
|
36
|
-
return
|
|
66
|
+
return join2(root, 'inject-cache', `${key}.json`)
|
|
37
67
|
}
|
|
38
68
|
function readInjectCache(root, key) {
|
|
39
69
|
try {
|
|
40
|
-
const parsed = JSON.parse(
|
|
70
|
+
const parsed = JSON.parse(readFileSync2(cacheFile(root, key), 'utf8'))
|
|
41
71
|
if (parsed && typeof parsed === 'object') {
|
|
42
72
|
const e = parsed
|
|
43
73
|
if (typeof e.pcHash === 'string' && typeof e.ts === 'number' && typeof e.turns === 'number') {
|
|
@@ -49,7 +79,7 @@ function readInjectCache(root, key) {
|
|
|
49
79
|
}
|
|
50
80
|
function writeInjectCache(root, key, entry) {
|
|
51
81
|
try {
|
|
52
|
-
mkdirSync(
|
|
82
|
+
mkdirSync(join2(root, 'inject-cache'), { recursive: true })
|
|
53
83
|
writeFileSync(
|
|
54
84
|
cacheFile(root, key),
|
|
55
85
|
`${JSON.stringify(entry)}
|
|
@@ -63,7 +93,7 @@ function writeInjectCache(root, key, entry) {
|
|
|
63
93
|
}
|
|
64
94
|
function invalidateInjectCache(root) {
|
|
65
95
|
try {
|
|
66
|
-
rmSync(
|
|
96
|
+
rmSync(join2(root, 'inject-cache'), { recursive: true, force: true })
|
|
67
97
|
return true
|
|
68
98
|
} catch {
|
|
69
99
|
return false
|
|
@@ -72,11 +102,11 @@ function invalidateInjectCache(root) {
|
|
|
72
102
|
|
|
73
103
|
// src/checkpoint/injectState.ts
|
|
74
104
|
import {
|
|
75
|
-
existsSync as
|
|
105
|
+
existsSync as existsSync3,
|
|
76
106
|
readdirSync as readdirSync2,
|
|
77
|
-
readFileSync as
|
|
107
|
+
readFileSync as readFileSync4,
|
|
78
108
|
} from 'node:fs'
|
|
79
|
-
import { join as
|
|
109
|
+
import { join as join4 } from 'node:path'
|
|
80
110
|
|
|
81
111
|
// src/checkpoint/breakLoop.ts
|
|
82
112
|
var LOOP_THRESHOLD = 3
|
|
@@ -85,6 +115,9 @@ function detectLoop(ledger) {
|
|
|
85
115
|
.filter((e) => (e.fail_count ?? 0) >= LOOP_THRESHOLD)
|
|
86
116
|
.map((e) => ({ sub: e.sub, count: e.fail_count }))
|
|
87
117
|
}
|
|
118
|
+
function isSettled(e) {
|
|
119
|
+
return e.status === 'done' || e.status === 'skipped' || e.status === 'rejected'
|
|
120
|
+
}
|
|
88
121
|
|
|
89
122
|
// src/checkpoint/ledger.ts
|
|
90
123
|
function nextPending(entries) {
|
|
@@ -129,8 +162,8 @@ function describeUnit(unit) {
|
|
|
129
162
|
}
|
|
130
163
|
|
|
131
164
|
// src/checkpoint/planningScan.ts
|
|
132
|
-
import { existsSync, readdirSync, readFileSync as
|
|
133
|
-
import { join as
|
|
165
|
+
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync3 } from 'node:fs'
|
|
166
|
+
import { join as join3 } from 'node:path'
|
|
134
167
|
var PHASE_DIR = /^(\d+(?:\.\d+)?)-(.*)$/
|
|
135
168
|
function scanPlanning(opts = {}) {
|
|
136
169
|
const repoRoot = opts.repoRoot ?? process.cwd()
|
|
@@ -143,14 +176,14 @@ function scanPlanning(opts = {}) {
|
|
|
143
176
|
}
|
|
144
177
|
function scanPhases(repoRoot, includeTasks) {
|
|
145
178
|
try {
|
|
146
|
-
const phasesDir =
|
|
147
|
-
if (!
|
|
179
|
+
const phasesDir = join3(repoRoot, '.planning', 'phases')
|
|
180
|
+
if (!existsSync2(phasesDir)) return []
|
|
148
181
|
const out = []
|
|
149
182
|
for (const dir of readdirSync(phasesDir)) {
|
|
150
183
|
const m = PHASE_DIR.exec(dir)
|
|
151
184
|
const num = m?.[1]
|
|
152
185
|
if (!num) continue
|
|
153
|
-
const dirPath =
|
|
186
|
+
const dirPath = join3(phasesDir, dir)
|
|
154
187
|
let entries
|
|
155
188
|
try {
|
|
156
189
|
entries = readdirSync(dirPath)
|
|
@@ -186,9 +219,9 @@ function scanPhases(repoRoot, includeTasks) {
|
|
|
186
219
|
function scanTasks(dirPath) {
|
|
187
220
|
for (const fname of ['task_plan.md', 'progress.md']) {
|
|
188
221
|
try {
|
|
189
|
-
const p =
|
|
190
|
-
if (!
|
|
191
|
-
const m = /^[ \t]*- \[ \]\s+(.+)$/m.exec(
|
|
222
|
+
const p = join3(dirPath, fname)
|
|
223
|
+
if (!existsSync2(p)) continue
|
|
224
|
+
const m = /^[ \t]*- \[ \]\s+(.+)$/m.exec(readFileSync3(p, 'utf8'))
|
|
192
225
|
const task = m?.[1]
|
|
193
226
|
if (task) return { nextUnchecked: task.trim() }
|
|
194
227
|
} catch {}
|
|
@@ -234,7 +267,7 @@ function buildWorkflowStateBlock(wf, forward, ledgerAgeMs) {
|
|
|
234
267
|
if (!wf) return ''
|
|
235
268
|
const ledger = wf.sub_progress ?? []
|
|
236
269
|
const next = nextPending(ledger)
|
|
237
|
-
const loops = detectLoop(ledger)
|
|
270
|
+
const loops = detectLoop(ledger.filter((e) => !isSettled(e)))
|
|
238
271
|
const lines = [
|
|
239
272
|
'<workflow-state>',
|
|
240
273
|
`phase: ${wf.phase}`,
|
|
@@ -269,6 +302,7 @@ function buildWorkflowStateBlock(wf, forward, ledgerAgeMs) {
|
|
|
269
302
|
)
|
|
270
303
|
}
|
|
271
304
|
for (const e of ledger) {
|
|
305
|
+
if (isSettled(e)) continue
|
|
272
306
|
const attempts = e.fail_count ?? 0
|
|
273
307
|
if (e.attempt_budget !== void 0 && attempts >= e.attempt_budget) {
|
|
274
308
|
lines.push(
|
|
@@ -346,14 +380,16 @@ function buildProjectContextBlock(input) {
|
|
|
346
380
|
}
|
|
347
381
|
function findPhaseContextExcerpt(repoRoot, phase, budget) {
|
|
348
382
|
try {
|
|
349
|
-
const phasesDir =
|
|
350
|
-
if (!
|
|
383
|
+
const phasesDir = join4(repoRoot, '.planning', 'phases')
|
|
384
|
+
if (!existsSync3(phasesDir)) return null
|
|
385
|
+
const phaseNum = /(\d+(?:\.\d+)?)/.exec(phase)?.[1]
|
|
386
|
+
if (phaseNum === void 0) return null
|
|
351
387
|
for (const dir of readdirSync2(phasesDir)) {
|
|
352
|
-
const num = /^(\d+)/.exec(dir)?.[1]
|
|
353
|
-
if (
|
|
354
|
-
const ctxFile =
|
|
355
|
-
if (!
|
|
356
|
-
const body =
|
|
388
|
+
const num = /^(\d+(?:\.\d+)?)/.exec(dir)?.[1]
|
|
389
|
+
if (num === void 0 || Number(num) !== Number(phaseNum)) continue
|
|
390
|
+
const ctxFile = join4(phasesDir, dir, `${num}-CONTEXT.md`)
|
|
391
|
+
if (!existsSync3(ctxFile)) continue
|
|
392
|
+
const body = readFileSync4(ctxFile, 'utf8')
|
|
357
393
|
const goalIdx = body.indexOf('## Goal')
|
|
358
394
|
const slice = goalIdx >= 0 ? body.slice(goalIdx) : body
|
|
359
395
|
const next = slice.indexOf('\n## ', 1)
|
|
@@ -406,7 +442,7 @@ function forwardPointer(repoRoot, wf) {
|
|
|
406
442
|
function repoKey(cwd) {
|
|
407
443
|
let dir = resolve(cwd)
|
|
408
444
|
for (;;) {
|
|
409
|
-
if (
|
|
445
|
+
if (existsSync4(join5(dir, '.git'))) return dir
|
|
410
446
|
const parent = dirname(dir)
|
|
411
447
|
if (parent === dir) break
|
|
412
448
|
dir = parent
|
|
@@ -414,10 +450,7 @@ function repoKey(cwd) {
|
|
|
414
450
|
return resolve(cwd)
|
|
415
451
|
}
|
|
416
452
|
function harnessedRoot() {
|
|
417
|
-
|
|
418
|
-
return override !== void 0 && override !== ''
|
|
419
|
-
? override
|
|
420
|
-
: join4(homedir(), '.claude', 'harnessed')
|
|
453
|
+
return hookStateRoot()
|
|
421
454
|
}
|
|
422
455
|
function sessionIdEnvName() {
|
|
423
456
|
const platform = (process.env.HARNESSED_PLATFORM || 'claude').trim()
|
|
@@ -436,13 +469,14 @@ function readWorkflow(root, keys) {
|
|
|
436
469
|
}
|
|
437
470
|
}
|
|
438
471
|
try {
|
|
439
|
-
const storePath =
|
|
440
|
-
const store = JSON.parse(
|
|
472
|
+
const storePath = join5(root, 'workflows.json')
|
|
473
|
+
const store = JSON.parse(readFileSync5(storePath, 'utf8'))
|
|
441
474
|
if (store?.workflows) {
|
|
442
475
|
for (const k of keys) {
|
|
443
476
|
if (store.workflows[k]) {
|
|
444
477
|
wf = store.workflows[k]
|
|
445
|
-
|
|
478
|
+
const stamped = wf?.updated_at ? Date.parse(wf.updated_at) : Number.NaN
|
|
479
|
+
ledgerAgeMs = Number.isNaN(stamped) ? ageOf(storePath) : Date.now() - stamped
|
|
446
480
|
break
|
|
447
481
|
}
|
|
448
482
|
}
|
|
@@ -485,7 +519,7 @@ function main() {
|
|
|
485
519
|
const { wf, intent, ledgerAgeMs } = readWorkflow(root, sid ? [`${key}::${sid}`, key] : [key])
|
|
486
520
|
let learningsMd = ''
|
|
487
521
|
try {
|
|
488
|
-
learningsMd =
|
|
522
|
+
learningsMd = readFileSync5(join5(key, '.planning', 'LEARNINGS.md'), 'utf8')
|
|
489
523
|
} catch {}
|
|
490
524
|
const budget = Number(process.env.HARNESSED_INJECT_BUDGET) || DEFAULT_INJECT_BUDGET
|
|
491
525
|
const pcOff = process.env.HARNESSED_INJECT_PC_OFF === '1'
|
|
@@ -5,15 +5,50 @@
|
|
|
5
5
|
|
|
6
6
|
// src/checkpoint/stopHookMain.ts
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import {
|
|
9
|
+
existsSync as existsSync2,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
readFileSync as readFileSync2,
|
|
12
|
+
writeFileSync,
|
|
13
|
+
} from 'node:fs'
|
|
14
|
+
import { join as join2 } from 'node:path'
|
|
11
15
|
|
|
12
16
|
// src/platform/ablation.ts
|
|
13
17
|
function isAblated(env = process.env) {
|
|
14
18
|
return env.HARNESSED_OFF === '1'
|
|
15
19
|
}
|
|
16
20
|
|
|
21
|
+
// src/checkpoint/hookStateRoot.ts
|
|
22
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
23
|
+
import { homedir } from 'node:os'
|
|
24
|
+
import { join } from 'node:path'
|
|
25
|
+
function hookStateRoot(home = homedir()) {
|
|
26
|
+
const override = process.env.HARNESSED_ROOT_OVERRIDE
|
|
27
|
+
if (override !== void 0 && override !== '') return override
|
|
28
|
+
const claudeHome = join(home, '.claude')
|
|
29
|
+
const codexHome = join(home, '.codex')
|
|
30
|
+
const rootOf = (id) =>
|
|
31
|
+
id === 'claude'
|
|
32
|
+
? join(claudeHome, 'harnessed')
|
|
33
|
+
: id === 'codex'
|
|
34
|
+
? join(codexHome, 'harnessed')
|
|
35
|
+
: null
|
|
36
|
+
const env = process.env.HARNESSED_PLATFORM
|
|
37
|
+
if (env !== void 0 && env !== '') {
|
|
38
|
+
const r = rootOf(env)
|
|
39
|
+
if (r) return r
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const r = rootOf(readFileSync(join(claudeHome, 'harnessed', '.platform'), 'utf8').trim())
|
|
43
|
+
if (r) return r
|
|
44
|
+
} catch {}
|
|
45
|
+
try {
|
|
46
|
+
if (existsSync(claudeHome)) return join(claudeHome, 'harnessed')
|
|
47
|
+
if (existsSync(codexHome)) return join(codexHome, 'harnessed')
|
|
48
|
+
} catch {}
|
|
49
|
+
return join(claudeHome, 'harnessed')
|
|
50
|
+
}
|
|
51
|
+
|
|
17
52
|
// src/checkpoint/modeBDetect.ts
|
|
18
53
|
var TAIL_WINDOW = 200
|
|
19
54
|
var INVOKE_RE = /<invoke name="/g
|
|
@@ -47,8 +82,7 @@ function detectModeB(content) {
|
|
|
47
82
|
// src/checkpoint/stopHookMain.ts
|
|
48
83
|
var MAX_RETRIES = 2
|
|
49
84
|
function stateRoot() {
|
|
50
|
-
|
|
51
|
-
return override !== void 0 && override !== '' ? override : join(homedir(), '.claude', 'harnessed')
|
|
85
|
+
return hookStateRoot()
|
|
52
86
|
}
|
|
53
87
|
function messageSig(content) {
|
|
54
88
|
const text = content
|
|
@@ -59,8 +93,8 @@ function messageSig(content) {
|
|
|
59
93
|
}
|
|
60
94
|
function lastAssistantContent(transcriptPath) {
|
|
61
95
|
try {
|
|
62
|
-
if (!transcriptPath || !
|
|
63
|
-
const buf =
|
|
96
|
+
if (!transcriptPath || !existsSync2(transcriptPath)) return null
|
|
97
|
+
const buf = readFileSync2(transcriptPath)
|
|
64
98
|
const slice = buf.length > 262144 ? buf.subarray(buf.length - 262144) : buf
|
|
65
99
|
const lines = slice.toString('utf8').split('\n')
|
|
66
100
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -85,12 +119,12 @@ function retryStore(sessionId) {
|
|
|
85
119
|
.update(String(sessionId ?? 'nosession'))
|
|
86
120
|
.digest('hex')
|
|
87
121
|
.slice(0, 16)
|
|
88
|
-
return
|
|
122
|
+
return join2(stateRoot(), 'stop-hook-retries', `${id}.json`)
|
|
89
123
|
}
|
|
90
124
|
function readRetry(path) {
|
|
91
125
|
try {
|
|
92
|
-
if (!
|
|
93
|
-
const j = JSON.parse(
|
|
126
|
+
if (!existsSync2(path)) return { sig: '', count: 0 }
|
|
127
|
+
const j = JSON.parse(readFileSync2(path, 'utf8'))
|
|
94
128
|
return { sig: typeof j.sig === 'string' ? j.sig : '', count: Number(j.count) || 0 }
|
|
95
129
|
} catch {
|
|
96
130
|
return { sig: '', count: 0 }
|
|
@@ -98,7 +132,7 @@ function readRetry(path) {
|
|
|
98
132
|
}
|
|
99
133
|
function writeRetry(path, sig, count) {
|
|
100
134
|
try {
|
|
101
|
-
mkdirSync(
|
|
135
|
+
mkdirSync(join2(path, '..'), { recursive: true })
|
|
102
136
|
writeFileSync(path, JSON.stringify({ sig, count }), 'utf8')
|
|
103
137
|
return true
|
|
104
138
|
} catch {
|