harnessed 4.24.0 → 4.25.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.
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
// Phase 15 repo-aware: resolves the active repo's slot from
|
|
14
14
|
// workflows.json[repoKey(cwd)] (legacy current-workflow.json as a fallback).
|
|
15
15
|
// Root: HARNESSED_ROOT_OVERRIDE if set, else <homedir>/.claude/harnessed.
|
|
16
|
-
import {
|
|
16
|
+
import { createHash } from 'node:crypto'
|
|
17
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
|
|
17
18
|
import { homedir } from 'node:os'
|
|
18
19
|
import { dirname, join, resolve } from 'node:path'
|
|
19
20
|
|
|
@@ -50,6 +51,60 @@ function sessionIdEnvName() {
|
|
|
50
51
|
return 'CLAUDE_CODE_SESSION_ID' // claude (default)
|
|
51
52
|
}
|
|
52
53
|
|
|
54
|
+
// ── 4.25.0 (intel B1) — session-scoped delta cache for <project-context>.
|
|
55
|
+
// Inline mirror of src/checkpoint/injectCache.ts (this file is self-contained
|
|
56
|
+
// plain JS by contract); the delta cells in tests/checkpoint/injectState.test.ts
|
|
57
|
+
// hold the two implementations together. Fail-soft: the cache may only ever
|
|
58
|
+
// SAVE tokens, never lose context — a skip is honored only when the
|
|
59
|
+
// incremented entry was persisted (else `turns` would freeze and the periodic
|
|
60
|
+
// compaction-hedge refresh would never fire). ──
|
|
61
|
+
|
|
62
|
+
const DEFAULT_REFRESH_TURNS = 10
|
|
63
|
+
|
|
64
|
+
function parseRefreshTurns(raw) {
|
|
65
|
+
const n = Number.parseInt(raw ?? '', 10)
|
|
66
|
+
return Number.isInteger(n) && n > 0 ? n : DEFAULT_REFRESH_TURNS
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function decidePcEmission(cache, pcHash, refreshN, nowMs) {
|
|
70
|
+
if (cache && cache.pcHash === pcHash && cache.turns < refreshN) {
|
|
71
|
+
return { emit: false, next: { pcHash, ts: cache.ts, turns: cache.turns + 1 } }
|
|
72
|
+
}
|
|
73
|
+
return { emit: true, next: { pcHash, ts: nowMs, turns: 0 } }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** true ⇔ the full pc block should be emitted this turn (default on ANY trouble). */
|
|
77
|
+
function shouldEmitPc(root, repoRoot, sid, pc) {
|
|
78
|
+
try {
|
|
79
|
+
const key = createHash('sha256').update(`${repoRoot}::${sid}`).digest('hex').slice(0, 16)
|
|
80
|
+
const file = join(root, 'inject-cache', `${key}.json`)
|
|
81
|
+
let cache = null
|
|
82
|
+
try {
|
|
83
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'))
|
|
84
|
+
if (
|
|
85
|
+
parsed &&
|
|
86
|
+
typeof parsed.pcHash === 'string' &&
|
|
87
|
+
typeof parsed.ts === 'number' &&
|
|
88
|
+
typeof parsed.turns === 'number'
|
|
89
|
+
) {
|
|
90
|
+
cache = parsed
|
|
91
|
+
}
|
|
92
|
+
} catch {}
|
|
93
|
+
const pcHash = createHash('sha256').update(pc).digest('hex')
|
|
94
|
+
const refreshN = parseRefreshTurns(process.env.HARNESSED_INJECT_REFRESH_TURNS)
|
|
95
|
+
const d = decidePcEmission(cache, pcHash, refreshN, Date.now())
|
|
96
|
+
try {
|
|
97
|
+
mkdirSync(join(root, 'inject-cache'), { recursive: true })
|
|
98
|
+
writeFileSync(file, `${JSON.stringify(d.next)}\n`, 'utf8')
|
|
99
|
+
} catch {
|
|
100
|
+
return true // could not persist the increment — never skip on an unpersisted decision
|
|
101
|
+
}
|
|
102
|
+
return d.emit
|
|
103
|
+
} catch {
|
|
104
|
+
return true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
53
108
|
// Phase 35 — try the session-scoped slot first, then the bare repoKey slot, then
|
|
54
109
|
// the legacy singleton (dual-write anchor). `keys` is ordered most→least specific.
|
|
55
110
|
// 4.22.0 — also surfaces the intent sidecar (same key order) for the freestyle nag.
|
|
@@ -371,7 +426,13 @@ try {
|
|
|
371
426
|
)
|
|
372
427
|
const used = rel.reduce((a, e) => a + tok(e.raw), 0)
|
|
373
428
|
const ctx = findPhaseContextExcerpt(key, wf.phase, Math.max(0, budget - used))
|
|
374
|
-
|
|
429
|
+
let pc = projectContextBlock(rel, ctx ?? undefined)
|
|
430
|
+
|
|
431
|
+
// 4.25.0 (intel B1) — same session + byte-identical pc already injected on a
|
|
432
|
+
// recent turn → skip it (the content is in the conversation); periodic
|
|
433
|
+
// refresh + hash-miss re-emission handled by the cache decision. No sid or
|
|
434
|
+
// any cache trouble → full injection, byte-identical to pre-4.25.0.
|
|
435
|
+
if (pc && sid && !shouldEmitPc(root, key, sid, pc)) pc = ''
|
|
375
436
|
|
|
376
437
|
const normal = pc ? `${ws}\n${pc}` : ws
|
|
377
438
|
process.stdout.write(`${ib ? `${ib}\n${normal}` : normal}\n`)
|
package/dist/cli.mjs
CHANGED
|
@@ -38,7 +38,7 @@ var init_package = __esm({
|
|
|
38
38
|
"package.json"() {
|
|
39
39
|
package_default = {
|
|
40
40
|
name: "harnessed",
|
|
41
|
-
version: "4.
|
|
41
|
+
version: "4.25.0",
|
|
42
42
|
description: "AI coding harness package manager + composition orchestrator",
|
|
43
43
|
type: "module",
|
|
44
44
|
license: "Apache-2.0",
|