harnessed 4.24.0 → 4.26.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 +63 -2
- package/dist/cli.mjs +68 -13
- package/dist/cli.mjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/workflows/role-prompts.yaml +4 -0
- package/workflows/role-prompts.zh-Hans.yaml +4 -0
|
@@ -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.26.0",
|
|
42
42
|
description: "AI coding harness package manager + composition orchestrator",
|
|
43
43
|
type: "module",
|
|
44
44
|
license: "Apache-2.0",
|
|
@@ -448,7 +448,13 @@ var init_currentWorkflow_v1 = __esm({
|
|
|
448
448
|
evidence: Type.Optional(Type.Array(EvidenceRef)),
|
|
449
449
|
// G6 — failure counter; incremented only on each ->failed transition (drives
|
|
450
450
|
// breakLoop detection). 'rejected' is terminal and does NOT increment it.
|
|
451
|
-
fail_count: Type.Optional(Type.Integer({ minimum: 0 }))
|
|
451
|
+
fail_count: Type.Optional(Type.Integer({ minimum: 0 })),
|
|
452
|
+
// 4.26.0 (A3 serial-order guard) — seeding-time serial/parallel semantics
|
|
453
|
+
// carried over from the gates plan (fire[].mode/order). Optional: pre-4.26.0
|
|
454
|
+
// envelopes lack them, and the guard no-ops on entries without `mode`
|
|
455
|
+
// (back-compat fail-soft; comet 0.3.9 phase-skip lesson).
|
|
456
|
+
mode: Type.Optional(Type.Union([Type.Literal("serial"), Type.Literal("parallel")])),
|
|
457
|
+
order: Type.Optional(Type.Integer())
|
|
452
458
|
},
|
|
453
459
|
{ additionalProperties: false }
|
|
454
460
|
);
|
|
@@ -829,19 +835,25 @@ var init_planningScan = __esm({
|
|
|
829
835
|
// src/checkpoint/ledger.ts
|
|
830
836
|
var ledger_exports = {};
|
|
831
837
|
__export(ledger_exports, {
|
|
838
|
+
findSerialBlockers: () => findSerialBlockers,
|
|
832
839
|
markSub: () => markSub,
|
|
833
840
|
nextPending: () => nextPending,
|
|
834
841
|
seedLedger: () => seedLedger
|
|
835
842
|
});
|
|
836
843
|
function seedLedger(plan) {
|
|
837
844
|
const fireEntries = plan.fire.map(
|
|
838
|
-
(f, i) =>
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
+
(f, i) => {
|
|
846
|
+
const entry = { sub: f.sub, status: "pending", gate_fired: true };
|
|
847
|
+
if (f.mode === "serial" || f.mode === "parallel") entry.mode = f.mode;
|
|
848
|
+
if (f.order !== void 0) entry.order = f.order;
|
|
849
|
+
return {
|
|
850
|
+
// missing order → Infinity so explicitly-ordered subs sort ahead while
|
|
851
|
+
// unordered ones retain relative input order (stabilized by idx).
|
|
852
|
+
order: f.order ?? Number.POSITIVE_INFINITY,
|
|
853
|
+
idx: i,
|
|
854
|
+
entry
|
|
855
|
+
};
|
|
856
|
+
}
|
|
845
857
|
);
|
|
846
858
|
fireEntries.sort((a, b) => a.order - b.order || a.idx - b.idx);
|
|
847
859
|
const skipEntries = plan.skip.map(
|
|
@@ -873,8 +885,17 @@ function markSub(entries, sub, status, opts) {
|
|
|
873
885
|
function nextPending(entries) {
|
|
874
886
|
return entries.find((e) => e.status === "pending")?.sub ?? null;
|
|
875
887
|
}
|
|
888
|
+
function findSerialBlockers(entries, sub) {
|
|
889
|
+
const target = entries.find((e) => e.sub === sub);
|
|
890
|
+
if (!target) return [];
|
|
891
|
+
const eff = (e) => e.order ?? PARALLEL_MID_ANCHOR;
|
|
892
|
+
const counts = target.mode === "serial" ? (e) => e.mode === "serial" || e.mode === "parallel" : (e) => e.mode === "serial";
|
|
893
|
+
return entries.filter((e) => e.sub !== sub && e.status === "pending" && counts(e) && eff(e) < eff(target)).map((e) => e.sub);
|
|
894
|
+
}
|
|
895
|
+
var PARALLEL_MID_ANCHOR;
|
|
876
896
|
var init_ledger = __esm({
|
|
877
897
|
"src/checkpoint/ledger.ts"() {
|
|
898
|
+
PARALLEL_MID_ANCHOR = 50;
|
|
878
899
|
}
|
|
879
900
|
});
|
|
880
901
|
|
|
@@ -4101,10 +4122,10 @@ async function runMasterOrchestrator(masterName, context, packageRoot, spawnDriv
|
|
|
4101
4122
|
(m) => console.warn(m)
|
|
4102
4123
|
);
|
|
4103
4124
|
emitGateTransparency(masterName, master.delegates_to.length, gateEvalled);
|
|
4104
|
-
const
|
|
4125
|
+
const PARALLEL_MID_ANCHOR2 = 50;
|
|
4105
4126
|
const firedClauses = gateEvalled.filter((g) => g.passes).map((g) => g.clause);
|
|
4106
|
-
const serialLeading = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) <
|
|
4107
|
-
const serialTrailing = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) >=
|
|
4127
|
+
const serialLeading = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) < PARALLEL_MID_ANCHOR2).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
4128
|
+
const serialTrailing = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) >= PARALLEL_MID_ANCHOR2).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
4108
4129
|
const parallelClauses = firedClauses.filter((c) => (c.mode ?? "parallel") === "parallel");
|
|
4109
4130
|
const serialN = serialLeading.length + serialTrailing.length;
|
|
4110
4131
|
const parallelN = parallelClauses.length;
|
|
@@ -9710,12 +9731,38 @@ async function absorbIntentFor(sub) {
|
|
|
9710
9731
|
} catch {
|
|
9711
9732
|
}
|
|
9712
9733
|
}
|
|
9734
|
+
async function serialOrderBlockers(sub) {
|
|
9735
|
+
try {
|
|
9736
|
+
const { readCurrentWorkflow: readCurrentWorkflow2 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
9737
|
+
const { findSerialBlockers: findSerialBlockers2 } = await Promise.resolve().then(() => (init_ledger(), ledger_exports));
|
|
9738
|
+
const wf = await readCurrentWorkflow2();
|
|
9739
|
+
return findSerialBlockers2(wf?.sub_progress ?? [], sub);
|
|
9740
|
+
} catch (e) {
|
|
9741
|
+
console.warn(`[harnessed] serial-order guard skipped (fail-soft): ${e.message}`);
|
|
9742
|
+
return [];
|
|
9743
|
+
}
|
|
9744
|
+
}
|
|
9745
|
+
function enforceSerialOrder(action, sub, blockers, force) {
|
|
9746
|
+
if (blockers.length === 0) return true;
|
|
9747
|
+
if (!force) {
|
|
9748
|
+
console.error(
|
|
9749
|
+
`[harnessed] checkpoint ${action} BLOCKED: ${sub} \u2014 ${blockers.length} earlier serial-sequence sub(s) still pending (serial-order guard, fail-closed):`
|
|
9750
|
+
);
|
|
9751
|
+
for (const b of blockers) console.error(` - ${b} (complete or fail it first)`);
|
|
9752
|
+
console.error(" (re-run with --force to jump the sequence deliberately)");
|
|
9753
|
+
return false;
|
|
9754
|
+
}
|
|
9755
|
+
console.warn(
|
|
9756
|
+
`[harnessed] serial-order guard overridden (--force): ${action} ${sub} ahead of pending sub(s) ${blockers.join(", ")}`
|
|
9757
|
+
);
|
|
9758
|
+
return true;
|
|
9759
|
+
}
|
|
9713
9760
|
function registerCheckpoint(program2) {
|
|
9714
9761
|
program2.command("checkpoint <action> <sub>").description(
|
|
9715
9762
|
"Record workflow progress: intent | start | complete | fail <sub-workflow> (writes to ~/.claude/harnessed/checkpoints/)"
|
|
9716
9763
|
).option("--summary <text>", "short summary stored as the checkpoint lastTask").option("--plan <json>", "gates plan JSON (start only) \u2014 seeds the sub-progress ledger").option(
|
|
9717
9764
|
"--force",
|
|
9718
|
-
"complete
|
|
9765
|
+
"complete/fail \u2014 override a fail-closed guard: the missing-artifact evidence block (complete; records overridden) or the serial-order guard"
|
|
9719
9766
|
).option(
|
|
9720
9767
|
"--tokens <n>",
|
|
9721
9768
|
"complete only \u2014 conversation token count; auto-compacts the ledger when >= the shouldCompact threshold (Phase 14)"
|
|
@@ -9835,6 +9882,10 @@ function registerCheckpoint(program2) {
|
|
|
9835
9882
|
return;
|
|
9836
9883
|
}
|
|
9837
9884
|
if (action === "complete") {
|
|
9885
|
+
if (!enforceSerialOrder("complete", sub, await serialOrderBlockers(sub), opts.force)) {
|
|
9886
|
+
process.exit(1);
|
|
9887
|
+
return;
|
|
9888
|
+
}
|
|
9838
9889
|
const { checkArtifacts: checkArtifacts2 } = await Promise.resolve().then(() => (init_evidence(), evidence_exports));
|
|
9839
9890
|
const { mutateSubProgress: mutateSubProgress3 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
9840
9891
|
const { getAssetsRoot: getAssetsRoot2 } = await Promise.resolve().then(() => (init_assetsRoot(), assetsRoot_exports));
|
|
@@ -9924,6 +9975,10 @@ function registerCheckpoint(program2) {
|
|
|
9924
9975
|
process.exit(0);
|
|
9925
9976
|
return;
|
|
9926
9977
|
}
|
|
9978
|
+
if (!enforceSerialOrder("fail", sub, await serialOrderBlockers(sub), opts.force)) {
|
|
9979
|
+
process.exit(1);
|
|
9980
|
+
return;
|
|
9981
|
+
}
|
|
9927
9982
|
const { mutateSubProgress: mutateSubProgress2 } = await Promise.resolve().then(() => (init_state(), state_exports));
|
|
9928
9983
|
await mutateSubProgress2((e) => markIfSeeded(e, sub, "failed"));
|
|
9929
9984
|
await absorbIntentFor(sub);
|