harnessed 4.40.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 +76 -36
- package/bin/harnessed-stop-hook.mjs +49 -9
- package/dist/cli.mjs +750 -246
- 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,14 +5,49 @@
|
|
|
5
5
|
|
|
6
6
|
// src/checkpoint/injectStateMain.ts
|
|
7
7
|
import { createHash as createHash2 } from "node:crypto";
|
|
8
|
-
import { existsSync as
|
|
8
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5, statSync } from 'node:fs'
|
|
9
|
+
import { dirname, join as join5, resolve } from 'node:path'
|
|
10
|
+
|
|
11
|
+
// src/platform/ablation.ts
|
|
12
|
+
function isAblated(env = process.env) {
|
|
13
|
+
return env.HARNESSED_OFF === '1'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/checkpoint/hookStateRoot.ts
|
|
17
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
9
18
|
import { homedir } from 'node:os'
|
|
10
|
-
import {
|
|
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
|
+
}
|
|
11
46
|
|
|
12
47
|
// src/checkpoint/injectCache.ts
|
|
13
48
|
import { createHash } from 'node:crypto'
|
|
14
|
-
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
15
|
-
import { join } from 'node:path'
|
|
49
|
+
import { mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync } from 'node:fs'
|
|
50
|
+
import { join as join2 } from 'node:path'
|
|
16
51
|
var DEFAULT_REFRESH_TURNS = 10
|
|
17
52
|
function decidePcEmission(cache, pcHash, refreshN, nowMs) {
|
|
18
53
|
if (cache && cache.pcHash === pcHash && cache.turns < refreshN) {
|
|
@@ -28,11 +63,11 @@ function injectCacheKey(repoKey2, sid) {
|
|
|
28
63
|
return createHash('sha256').update(`${repoKey2}::${sid}`).digest('hex').slice(0, 16)
|
|
29
64
|
}
|
|
30
65
|
function cacheFile(root, key) {
|
|
31
|
-
return
|
|
66
|
+
return join2(root, 'inject-cache', `${key}.json`)
|
|
32
67
|
}
|
|
33
68
|
function readInjectCache(root, key) {
|
|
34
69
|
try {
|
|
35
|
-
const parsed = JSON.parse(
|
|
70
|
+
const parsed = JSON.parse(readFileSync2(cacheFile(root, key), 'utf8'))
|
|
36
71
|
if (parsed && typeof parsed === 'object') {
|
|
37
72
|
const e = parsed
|
|
38
73
|
if (typeof e.pcHash === 'string' && typeof e.ts === 'number' && typeof e.turns === 'number') {
|
|
@@ -44,7 +79,7 @@ function readInjectCache(root, key) {
|
|
|
44
79
|
}
|
|
45
80
|
function writeInjectCache(root, key, entry) {
|
|
46
81
|
try {
|
|
47
|
-
mkdirSync(
|
|
82
|
+
mkdirSync(join2(root, 'inject-cache'), { recursive: true })
|
|
48
83
|
writeFileSync(
|
|
49
84
|
cacheFile(root, key),
|
|
50
85
|
`${JSON.stringify(entry)}
|
|
@@ -58,7 +93,7 @@ function writeInjectCache(root, key, entry) {
|
|
|
58
93
|
}
|
|
59
94
|
function invalidateInjectCache(root) {
|
|
60
95
|
try {
|
|
61
|
-
rmSync(
|
|
96
|
+
rmSync(join2(root, 'inject-cache'), { recursive: true, force: true })
|
|
62
97
|
return true
|
|
63
98
|
} catch {
|
|
64
99
|
return false
|
|
@@ -67,11 +102,11 @@ function invalidateInjectCache(root) {
|
|
|
67
102
|
|
|
68
103
|
// src/checkpoint/injectState.ts
|
|
69
104
|
import {
|
|
70
|
-
existsSync as
|
|
105
|
+
existsSync as existsSync3,
|
|
71
106
|
readdirSync as readdirSync2,
|
|
72
|
-
readFileSync as
|
|
107
|
+
readFileSync as readFileSync4,
|
|
73
108
|
} from 'node:fs'
|
|
74
|
-
import { join as
|
|
109
|
+
import { join as join4 } from 'node:path'
|
|
75
110
|
|
|
76
111
|
// src/checkpoint/breakLoop.ts
|
|
77
112
|
var LOOP_THRESHOLD = 3
|
|
@@ -80,6 +115,9 @@ function detectLoop(ledger) {
|
|
|
80
115
|
.filter((e) => (e.fail_count ?? 0) >= LOOP_THRESHOLD)
|
|
81
116
|
.map((e) => ({ sub: e.sub, count: e.fail_count }))
|
|
82
117
|
}
|
|
118
|
+
function isSettled(e) {
|
|
119
|
+
return e.status === 'done' || e.status === 'skipped' || e.status === 'rejected'
|
|
120
|
+
}
|
|
83
121
|
|
|
84
122
|
// src/checkpoint/ledger.ts
|
|
85
123
|
function nextPending(entries) {
|
|
@@ -124,8 +162,8 @@ function describeUnit(unit) {
|
|
|
124
162
|
}
|
|
125
163
|
|
|
126
164
|
// src/checkpoint/planningScan.ts
|
|
127
|
-
import { existsSync, readdirSync, readFileSync as
|
|
128
|
-
import { join as
|
|
165
|
+
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync3 } from 'node:fs'
|
|
166
|
+
import { join as join3 } from 'node:path'
|
|
129
167
|
var PHASE_DIR = /^(\d+(?:\.\d+)?)-(.*)$/
|
|
130
168
|
function scanPlanning(opts = {}) {
|
|
131
169
|
const repoRoot = opts.repoRoot ?? process.cwd()
|
|
@@ -138,14 +176,14 @@ function scanPlanning(opts = {}) {
|
|
|
138
176
|
}
|
|
139
177
|
function scanPhases(repoRoot, includeTasks) {
|
|
140
178
|
try {
|
|
141
|
-
const phasesDir =
|
|
142
|
-
if (!
|
|
179
|
+
const phasesDir = join3(repoRoot, '.planning', 'phases')
|
|
180
|
+
if (!existsSync2(phasesDir)) return []
|
|
143
181
|
const out = []
|
|
144
182
|
for (const dir of readdirSync(phasesDir)) {
|
|
145
183
|
const m = PHASE_DIR.exec(dir)
|
|
146
184
|
const num = m?.[1]
|
|
147
185
|
if (!num) continue
|
|
148
|
-
const dirPath =
|
|
186
|
+
const dirPath = join3(phasesDir, dir)
|
|
149
187
|
let entries
|
|
150
188
|
try {
|
|
151
189
|
entries = readdirSync(dirPath)
|
|
@@ -181,9 +219,9 @@ function scanPhases(repoRoot, includeTasks) {
|
|
|
181
219
|
function scanTasks(dirPath) {
|
|
182
220
|
for (const fname of ['task_plan.md', 'progress.md']) {
|
|
183
221
|
try {
|
|
184
|
-
const p =
|
|
185
|
-
if (!
|
|
186
|
-
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'))
|
|
187
225
|
const task = m?.[1]
|
|
188
226
|
if (task) return { nextUnchecked: task.trim() }
|
|
189
227
|
} catch {}
|
|
@@ -229,7 +267,7 @@ function buildWorkflowStateBlock(wf, forward, ledgerAgeMs) {
|
|
|
229
267
|
if (!wf) return ''
|
|
230
268
|
const ledger = wf.sub_progress ?? []
|
|
231
269
|
const next = nextPending(ledger)
|
|
232
|
-
const loops = detectLoop(ledger)
|
|
270
|
+
const loops = detectLoop(ledger.filter((e) => !isSettled(e)))
|
|
233
271
|
const lines = [
|
|
234
272
|
'<workflow-state>',
|
|
235
273
|
`phase: ${wf.phase}`,
|
|
@@ -264,6 +302,7 @@ function buildWorkflowStateBlock(wf, forward, ledgerAgeMs) {
|
|
|
264
302
|
)
|
|
265
303
|
}
|
|
266
304
|
for (const e of ledger) {
|
|
305
|
+
if (isSettled(e)) continue
|
|
267
306
|
const attempts = e.fail_count ?? 0
|
|
268
307
|
if (e.attempt_budget !== void 0 && attempts >= e.attempt_budget) {
|
|
269
308
|
lines.push(
|
|
@@ -341,14 +380,16 @@ function buildProjectContextBlock(input) {
|
|
|
341
380
|
}
|
|
342
381
|
function findPhaseContextExcerpt(repoRoot, phase, budget) {
|
|
343
382
|
try {
|
|
344
|
-
const phasesDir =
|
|
345
|
-
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
|
|
346
387
|
for (const dir of readdirSync2(phasesDir)) {
|
|
347
|
-
const num = /^(\d+)/.exec(dir)?.[1]
|
|
348
|
-
if (
|
|
349
|
-
const ctxFile =
|
|
350
|
-
if (!
|
|
351
|
-
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')
|
|
352
393
|
const goalIdx = body.indexOf('## Goal')
|
|
353
394
|
const slice = goalIdx >= 0 ? body.slice(goalIdx) : body
|
|
354
395
|
const next = slice.indexOf('\n## ', 1)
|
|
@@ -401,7 +442,7 @@ function forwardPointer(repoRoot, wf) {
|
|
|
401
442
|
function repoKey(cwd) {
|
|
402
443
|
let dir = resolve(cwd)
|
|
403
444
|
for (;;) {
|
|
404
|
-
if (
|
|
445
|
+
if (existsSync4(join5(dir, '.git'))) return dir
|
|
405
446
|
const parent = dirname(dir)
|
|
406
447
|
if (parent === dir) break
|
|
407
448
|
dir = parent
|
|
@@ -409,10 +450,7 @@ function repoKey(cwd) {
|
|
|
409
450
|
return resolve(cwd)
|
|
410
451
|
}
|
|
411
452
|
function harnessedRoot() {
|
|
412
|
-
|
|
413
|
-
return override !== void 0 && override !== ''
|
|
414
|
-
? override
|
|
415
|
-
: join4(homedir(), '.claude', 'harnessed')
|
|
453
|
+
return hookStateRoot()
|
|
416
454
|
}
|
|
417
455
|
function sessionIdEnvName() {
|
|
418
456
|
const platform = (process.env.HARNESSED_PLATFORM || 'claude').trim()
|
|
@@ -431,13 +469,14 @@ function readWorkflow(root, keys) {
|
|
|
431
469
|
}
|
|
432
470
|
}
|
|
433
471
|
try {
|
|
434
|
-
const storePath =
|
|
435
|
-
const store = JSON.parse(
|
|
472
|
+
const storePath = join5(root, 'workflows.json')
|
|
473
|
+
const store = JSON.parse(readFileSync5(storePath, 'utf8'))
|
|
436
474
|
if (store?.workflows) {
|
|
437
475
|
for (const k of keys) {
|
|
438
476
|
if (store.workflows[k]) {
|
|
439
477
|
wf = store.workflows[k]
|
|
440
|
-
|
|
478
|
+
const stamped = wf?.updated_at ? Date.parse(wf.updated_at) : Number.NaN
|
|
479
|
+
ledgerAgeMs = Number.isNaN(stamped) ? ageOf(storePath) : Date.now() - stamped
|
|
441
480
|
break
|
|
442
481
|
}
|
|
443
482
|
}
|
|
@@ -467,6 +506,7 @@ function shouldEmitPc(root, repoRoot, sid, pc) {
|
|
|
467
506
|
}
|
|
468
507
|
}
|
|
469
508
|
function main() {
|
|
509
|
+
if (isAblated()) return
|
|
470
510
|
try {
|
|
471
511
|
const root = harnessedRoot()
|
|
472
512
|
if (process.argv.includes('--invalidate')) {
|
|
@@ -479,7 +519,7 @@ function main() {
|
|
|
479
519
|
const { wf, intent, ledgerAgeMs } = readWorkflow(root, sid ? [`${key}::${sid}`, key] : [key])
|
|
480
520
|
let learningsMd = ''
|
|
481
521
|
try {
|
|
482
|
-
learningsMd =
|
|
522
|
+
learningsMd = readFileSync5(join5(key, '.planning', 'LEARNINGS.md'), 'utf8')
|
|
483
523
|
} catch {}
|
|
484
524
|
const budget = Number(process.env.HARNESSED_INJECT_BUDGET) || DEFAULT_INJECT_BUDGET
|
|
485
525
|
const pcOff = process.env.HARNESSED_INJECT_PC_OFF === '1'
|
|
@@ -5,9 +5,49 @@
|
|
|
5
5
|
|
|
6
6
|
// src/checkpoint/stopHookMain.ts
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
|
-
import {
|
|
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'
|
|
15
|
+
|
|
16
|
+
// src/platform/ablation.ts
|
|
17
|
+
function isAblated(env = process.env) {
|
|
18
|
+
return env.HARNESSED_OFF === '1'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/checkpoint/hookStateRoot.ts
|
|
22
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
9
23
|
import { homedir } from 'node:os'
|
|
10
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
|
+
}
|
|
11
51
|
|
|
12
52
|
// src/checkpoint/modeBDetect.ts
|
|
13
53
|
var TAIL_WINDOW = 200
|
|
@@ -42,8 +82,7 @@ function detectModeB(content) {
|
|
|
42
82
|
// src/checkpoint/stopHookMain.ts
|
|
43
83
|
var MAX_RETRIES = 2
|
|
44
84
|
function stateRoot() {
|
|
45
|
-
|
|
46
|
-
return override !== void 0 && override !== '' ? override : join(homedir(), '.claude', 'harnessed')
|
|
85
|
+
return hookStateRoot()
|
|
47
86
|
}
|
|
48
87
|
function messageSig(content) {
|
|
49
88
|
const text = content
|
|
@@ -54,8 +93,8 @@ function messageSig(content) {
|
|
|
54
93
|
}
|
|
55
94
|
function lastAssistantContent(transcriptPath) {
|
|
56
95
|
try {
|
|
57
|
-
if (!transcriptPath || !
|
|
58
|
-
const buf =
|
|
96
|
+
if (!transcriptPath || !existsSync2(transcriptPath)) return null
|
|
97
|
+
const buf = readFileSync2(transcriptPath)
|
|
59
98
|
const slice = buf.length > 262144 ? buf.subarray(buf.length - 262144) : buf
|
|
60
99
|
const lines = slice.toString('utf8').split('\n')
|
|
61
100
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
@@ -80,12 +119,12 @@ function retryStore(sessionId) {
|
|
|
80
119
|
.update(String(sessionId ?? 'nosession'))
|
|
81
120
|
.digest('hex')
|
|
82
121
|
.slice(0, 16)
|
|
83
|
-
return
|
|
122
|
+
return join2(stateRoot(), 'stop-hook-retries', `${id}.json`)
|
|
84
123
|
}
|
|
85
124
|
function readRetry(path) {
|
|
86
125
|
try {
|
|
87
|
-
if (!
|
|
88
|
-
const j = JSON.parse(
|
|
126
|
+
if (!existsSync2(path)) return { sig: '', count: 0 }
|
|
127
|
+
const j = JSON.parse(readFileSync2(path, 'utf8'))
|
|
89
128
|
return { sig: typeof j.sig === 'string' ? j.sig : '', count: Number(j.count) || 0 }
|
|
90
129
|
} catch {
|
|
91
130
|
return { sig: '', count: 0 }
|
|
@@ -93,7 +132,7 @@ function readRetry(path) {
|
|
|
93
132
|
}
|
|
94
133
|
function writeRetry(path, sig, count) {
|
|
95
134
|
try {
|
|
96
|
-
mkdirSync(
|
|
135
|
+
mkdirSync(join2(path, '..'), { recursive: true })
|
|
97
136
|
writeFileSync(path, JSON.stringify({ sig, count }), 'utf8')
|
|
98
137
|
return true
|
|
99
138
|
} catch {
|
|
@@ -114,6 +153,7 @@ function readStdin() {
|
|
|
114
153
|
})
|
|
115
154
|
}
|
|
116
155
|
async function main() {
|
|
156
|
+
if (isAblated()) return
|
|
117
157
|
const raw = await readStdin()
|
|
118
158
|
let payload
|
|
119
159
|
try {
|