harnessed 4.36.0 → 4.38.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.
@@ -11,7 +11,7 @@ import { dirname, join as join4, resolve } from 'node:path'
11
11
 
12
12
  // src/checkpoint/injectCache.ts
13
13
  import { createHash } from 'node:crypto'
14
- import { mkdirSync, readFileSync, writeFileSync } from 'node:fs'
14
+ import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
15
15
  import { join } from 'node:path'
16
16
  var DEFAULT_REFRESH_TURNS = 10
17
17
  function decidePcEmission(cache, pcHash, refreshN, nowMs) {
@@ -56,6 +56,14 @@ function writeInjectCache(root, key, entry) {
56
56
  return false
57
57
  }
58
58
  }
59
+ function invalidateInjectCache(root) {
60
+ try {
61
+ rmSync(join(root, 'inject-cache'), { recursive: true, force: true })
62
+ return true
63
+ } catch {
64
+ return false
65
+ }
66
+ }
59
67
 
60
68
  // src/checkpoint/injectState.ts
61
69
  import {
@@ -238,6 +246,12 @@ function buildWorkflowStateBlock(wf, forward, ledgerAgeMs) {
238
246
  `ENGINE: mid state-machine \u2014 drive sub '${next}' via \`harnessed prompt ${next}\` \u2192 spawn \u2192 \`harnessed checkpoint complete/fail\`. Do NOT freestyle the orchestration or skip the ledger; run \`harnessed status --recover\` if unsure where you are.`,
239
247
  )
240
248
  }
249
+ const nextEntry = next ? ledger.find((e) => e.sub === next) : void 0
250
+ if (nextEntry?.reason && (nextEntry.fail_count ?? 0) > 0) {
251
+ lines.push(
252
+ `REOPENED: sub '${next}' was sent back (attempt ${nextEntry.fail_count}${nextEntry.attempt_budget !== void 0 ? `/${nextEntry.attempt_budget}` : ''}) \u2014 ${nextEntry.reason}. Address THAT before re-running it; a repeat of the same attempt burns the budget.`,
253
+ )
254
+ }
241
255
  if (!next && forward && (forward.unit.kind === 'phase' || forward.unit.kind === 'task')) {
242
256
  const n = forward.remainingPhases
243
257
  lines.push(
@@ -455,6 +469,10 @@ function shouldEmitPc(root, repoRoot, sid, pc) {
455
469
  function main() {
456
470
  try {
457
471
  const root = harnessedRoot()
472
+ if (process.argv.includes('--invalidate')) {
473
+ invalidateInjectCache(root)
474
+ return
475
+ }
458
476
  const key = repoKey(process.cwd())
459
477
  const envName = sessionIdEnvName()
460
478
  const sid = envName ? process.env[envName]?.trim() : void 0
@@ -464,9 +482,11 @@ function main() {
464
482
  learningsMd = readFileSync4(join4(key, '.planning', 'LEARNINGS.md'), 'utf8')
465
483
  } catch {}
466
484
  const budget = Number(process.env.HARNESSED_INJECT_BUDGET) || DEFAULT_INJECT_BUDGET
485
+ const pcOff = process.env.HARNESSED_INJECT_PC_OFF === '1'
486
+ const pcGate = pcOff ? () => false : sid ? (pc) => shouldEmitPc(root, key, sid, pc) : void 0
467
487
  const out = buildInjection(key, wf, learningsMd, budget, intent, Date.now(), {
468
488
  ledgerAgeMs,
469
- pcGate: sid ? (pc) => shouldEmitPc(root, key, sid, pc) : void 0,
489
+ pcGate,
470
490
  })
471
491
  if (out)
472
492
  process.stdout.write(`${out}