harnessed 4.31.1 → 4.32.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/README.md CHANGED
@@ -93,6 +93,8 @@ Native agents give you primitives; harnessed wires them into a methodology. Wher
93
93
 
94
94
  > Native agents win on zero-setup, zero-overhead for trivial one-off edits. harnessed earns its keep the moment work spans multiple steps, sessions, or subagents — where freestyle drift and lost-in-chat state start costing you.
95
95
 
96
+ **Don't take our word for it — we ran the experiment.** A published A/B evidence pack ([docs/evidence/2026-07-b1/](./docs/evidence/2026-07-b1/)) compares `/auto` against bare Claude Code on 4 machine-graded tasks, full transcripts included. Honest headline: on small, fully-specified tasks both arms score 100% and bare is 4-5× cheaper — use bare (or auto-lite) there. The orchestration value claim lives in fuzzy-spec / multi-session territory, which that experiment deliberately does not cover; bring us a real task from that territory and we'll run the same protocol on it.
97
+
96
98
  ---
97
99
 
98
100
  ## 📦 Quick Install
package/dist/cli.mjs CHANGED
@@ -6,7 +6,7 @@ import { Type } from '@sinclair/typebox';
6
6
  import { readFile, readdir, unlink, writeFile, stat, rm, cp, mkdir, access, rename, appendFile, copyFile, chmod } from 'fs/promises';
7
7
  import { Value } from '@sinclair/typebox/value';
8
8
  import lockfile from 'proper-lockfile';
9
- import { LineCounter, parseDocument, parse, isSeq, isScalar } from 'yaml';
9
+ import { LineCounter, parseDocument, parse, isSeq, isScalar, stringify } from 'yaml';
10
10
  import { Ajv } from 'ajv';
11
11
  import * as ajvFormatsNs from 'ajv-formats';
12
12
  import { execFileSync, spawnSync, spawn, execSync, exec, execFile } from 'child_process';
@@ -38,7 +38,7 @@ var init_package = __esm({
38
38
  "package.json"() {
39
39
  package_default = {
40
40
  name: "harnessed",
41
- version: "4.31.1",
41
+ version: "4.32.0",
42
42
  description: "AI coding harness package manager + composition orchestrator",
43
43
  type: "module",
44
44
  license: "Apache-2.0",
@@ -3177,7 +3177,7 @@ function nameToYamlHintPath(name) {
3177
3177
  function shouldOverwriteFile(content) {
3178
3178
  return HARNESSED_MARKER_RX.test(content) || V3_4_3_SIGNATURE_SUB_RX.test(content) || V3_4_3_SIGNATURE_MASTER_RX.test(content);
3179
3179
  }
3180
- async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync, readFileSync18 = (p7) => readFileSync(p7, "utf8")) {
3180
+ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabilities, installedPlugins, installedUserSkills, writer, fileExists2 = existsSync, readFileSync19 = (p7) => readFileSync(p7, "utf8")) {
3181
3181
  const results = [];
3182
3182
  const aggregatedWarnings = /* @__PURE__ */ new Set();
3183
3183
  for (const name of slashNames) {
@@ -3196,7 +3196,7 @@ async function writeAllCommands(slashNames, commandsDir, rolePrompts, capabiliti
3196
3196
  if (fileExists2(path)) {
3197
3197
  let existing = "";
3198
3198
  try {
3199
- existing = readFileSync18(path);
3199
+ existing = readFileSync19(path);
3200
3200
  } catch {
3201
3201
  existing = "";
3202
3202
  }
@@ -4102,10 +4102,10 @@ async function runMasterOrchestrator(masterName, context, packageRoot, spawnDriv
4102
4102
  (m) => console.warn(m)
4103
4103
  );
4104
4104
  emitGateTransparency(masterName, master.delegates_to.length, gateEvalled);
4105
- const PARALLEL_MID_ANCHOR2 = 50;
4105
+ const PARALLEL_MID_ANCHOR3 = 50;
4106
4106
  const firedClauses = gateEvalled.filter((g) => g.passes).map((g) => g.clause);
4107
- const serialLeading = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) < PARALLEL_MID_ANCHOR2).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
4108
- const serialTrailing = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) >= PARALLEL_MID_ANCHOR2).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
4107
+ const serialLeading = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) < PARALLEL_MID_ANCHOR3).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
4108
+ const serialTrailing = firedClauses.filter((c) => c.mode === "serial" && (c.order ?? 0) >= PARALLEL_MID_ANCHOR3).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
4109
4109
  const parallelClauses = firedClauses.filter((c) => (c.mode ?? "parallel") === "parallel");
4110
4110
  const serialN = serialLeading.length + serialTrailing.length;
4111
4111
  const parallelN = parallelClauses.length;
@@ -6884,6 +6884,16 @@ var init_doctor_registry = __esm({
6884
6884
  }
6885
6885
  });
6886
6886
 
6887
+ // src/cli/lib/detectHeadless.ts
6888
+ function detectHeadless(env, _isTTY) {
6889
+ if (env.HARNESSED_HEADLESS === "1") return { headless: true, signal: "explicit-env" };
6890
+ return { headless: false, signal: "none" };
6891
+ }
6892
+ var init_detectHeadless = __esm({
6893
+ "src/cli/lib/detectHeadless.ts"() {
6894
+ }
6895
+ });
6896
+
6887
6897
  // src/cli/gates.ts
6888
6898
  var gates_exports = {};
6889
6899
  __export(gates_exports, {
@@ -7004,11 +7014,19 @@ async function runGatesPlan(master, raw, deps = defaultRunDeps) {
7004
7014
  (m) => deps.warn(m)
7005
7015
  );
7006
7016
  let parallelism = { escalate_to_teams: false, reason: null };
7007
- try {
7008
- const escalate = await resolveJudgmentGate(PARALLELISM_GATE, ctx, packageRoot);
7009
- parallelism = escalate ? { escalate_to_teams: true, reason: "agent-teams-upgrade gate fired" } : { escalate_to_teams: false, reason: null };
7010
- } catch {
7011
- parallelism = { escalate_to_teams: false, reason: null };
7017
+ const hl = detectHeadless(process.env, Boolean(process.stdout.isTTY));
7018
+ if (hl.headless) {
7019
+ parallelism = {
7020
+ escalate_to_teams: false,
7021
+ reason: "headless mode \u2014 Agent Teams are session-scoped, incompatible with -p (issue #7)"
7022
+ };
7023
+ } else {
7024
+ try {
7025
+ const escalate = await resolveJudgmentGate(PARALLELISM_GATE, ctx, packageRoot);
7026
+ parallelism = escalate ? { escalate_to_teams: true, reason: "agent-teams-upgrade gate fired" } : { escalate_to_teams: false, reason: null };
7027
+ } catch {
7028
+ parallelism = { escalate_to_teams: false, reason: null };
7029
+ }
7012
7030
  }
7013
7031
  const result = { master, fire, skip, parallelism };
7014
7032
  deps.log(JSON.stringify(result, null, 2));
@@ -7045,6 +7063,7 @@ var init_gates = __esm({
7045
7063
  init_judgmentResolver();
7046
7064
  init_skipSubs();
7047
7065
  init_assetsRoot();
7066
+ init_detectHeadless();
7048
7067
  init_gateContext();
7049
7068
  init_runDeps();
7050
7069
  VALID_MASTERS = /* @__PURE__ */ new Set(["auto", "discuss", "plan", "task", "verify", "ship"]);
@@ -10897,6 +10916,111 @@ function registerDoctor(program2) {
10897
10916
  process.exit(hasFail ? 1 : 0);
10898
10917
  });
10899
10918
  }
10919
+ var SUMMARY_PLACEHOLDER = "<SUMMARY-REDACTED>";
10920
+ var PARALLEL_MID_ANCHOR2 = 50;
10921
+ function scrubSecretShapes(text) {
10922
+ return text.replace(
10923
+ /\b(gh[opusr]_[A-Za-z0-9]{16,}|github_pat_[A-Za-z0-9_]{20,}|sk-[A-Za-z0-9-]{20,}|xox[bap]-[A-Za-z0-9-]{10,}|AKIA[A-Z0-9]{16})\b/g,
10924
+ (m) => `[REDACTED-${m.slice(0, 4)}]`
10925
+ ).replace(
10926
+ /([A-Z0-9_]*(?:TOKEN|SECRET|KEY|PASSWORD|CREDENTIAL|AUTH)[A-Z0-9_]*)=([^\s\\"']{8,})/g,
10927
+ (m, k, v) => /REDACTED/.test(v) ? m : `${k}=[REDACTED-ENV]`
10928
+ );
10929
+ }
10930
+ function redactText(text, placeholder, includeText) {
10931
+ if (text === void 0) return void 0;
10932
+ if (!includeText) return placeholder;
10933
+ return scrubSecretShapes(text);
10934
+ }
10935
+ function effectiveOrder(e) {
10936
+ if (e.mode === "serial" && typeof e.order === "number") return e.order;
10937
+ return PARALLEL_MID_ANCHOR2;
10938
+ }
10939
+ function buildScenarioFromEnvelope(wf, opts = {}) {
10940
+ const includeText = opts.includeText === true;
10941
+ const subs = wf.sub_progress ?? [];
10942
+ const fired = subs.filter((e) => e.status !== "skipped");
10943
+ const skipped = subs.filter((e) => e.status === "skipped");
10944
+ const plan = {
10945
+ fire: fired.map((e) => ({
10946
+ sub: e.sub,
10947
+ ...e.mode !== void 0 ? { mode: e.mode } : {},
10948
+ ...e.order !== void 0 ? { order: e.order } : {}
10949
+ })),
10950
+ skip: skipped.map((e) => ({
10951
+ sub: e.sub,
10952
+ // skip reason is engine-generated metadata ("gate <ref> = false" / "skipped
10953
+ // via skip_subs"), not user free-text — keep it (only scrub secret shapes),
10954
+ // it makes the trap meaningful and carries no business content.
10955
+ reason: e.reason ? scrubSecretShapes(e.reason) : "skipped"
10956
+ }))
10957
+ };
10958
+ const steps = [
10959
+ // skeleton so the planning-sync gate does not warn/block during replay.
10960
+ { file: { path: ".planning/ROADMAP.md", content: "# Roadmap\n" } },
10961
+ { file: { path: ".planning/STATE.md", content: "# STATE\n" } },
10962
+ { checkpoint: { action: "start", sub: wf.phase, plan } }
10963
+ ];
10964
+ const resolveOrder = [...fired].filter((e) => e.status === "done" || e.status === "failed" || e.status === "rejected").sort((a, b) => effectiveOrder(a) - effectiveOrder(b));
10965
+ for (const e of resolveOrder) {
10966
+ const summaryText = e.summary_text;
10967
+ const summary = redactText(summaryText, SUMMARY_PLACEHOLDER, includeText);
10968
+ if (e.status === "done") {
10969
+ steps.push({
10970
+ checkpoint: {
10971
+ action: "complete",
10972
+ sub: e.sub,
10973
+ ...summary !== void 0 ? { summary } : { summary: SUMMARY_PLACEHOLDER },
10974
+ // a real `overridden` posture came from --force; reproduce it.
10975
+ ...e.evidence_status === "overridden" ? { force: true } : {}
10976
+ }
10977
+ });
10978
+ } else {
10979
+ steps.push({
10980
+ checkpoint: {
10981
+ action: "fail",
10982
+ sub: e.sub,
10983
+ ...summary !== void 0 ? { summary } : { summary: SUMMARY_PLACEHOLDER }
10984
+ }
10985
+ });
10986
+ }
10987
+ }
10988
+ const hasVerified = fired.some((e) => e.evidence_status === "verified");
10989
+ const desc = `auto-recorded from a real ${wf.phase} run (eval Slice C). ${includeText ? "original text preserved (--include-text)" : "free text redacted"}.` + (hasVerified ? " KNOWN BOUNDARY: a real `verified` evidence posture is not reconstructed (no artifacts recreated) \u2192 replay yields `none_declared`." : "");
10990
+ return {
10991
+ name: opts.name ?? `recorded-${wf.phase}`,
10992
+ description: desc,
10993
+ steps
10994
+ };
10995
+ }
10996
+ function recordScenario(from, opts = {}) {
10997
+ const path = from.endsWith(".json") ? from : join(from, "current-workflow.json");
10998
+ let raw;
10999
+ try {
11000
+ raw = readFileSync(path, "utf8");
11001
+ } catch {
11002
+ throw new Error(
11003
+ `no current-workflow envelope at ${path} \u2014 point --from at a harnessed root (or a real run's checkpoint dir) that contains current-workflow.json`
11004
+ );
11005
+ }
11006
+ let wf;
11007
+ try {
11008
+ wf = JSON.parse(raw);
11009
+ } catch (e) {
11010
+ throw new Error(
11011
+ `current-workflow envelope at ${path} is not valid JSON: ${e.message}`
11012
+ );
11013
+ }
11014
+ if (!wf || typeof wf.phase !== "string" || wf.phase.length === 0) {
11015
+ throw new Error(`current-workflow envelope at ${path} has no 'phase' \u2014 not a recordable run`);
11016
+ }
11017
+ const scenario = buildScenarioFromEnvelope(wf, opts);
11018
+ const header = `# AUTO-RECORDED trap (eval Slice C, 4.32.0) \u2014 do not hand-edit; re-record via
11019
+ # \`harnessed eval record --from <run>\`. golden.json is replay-generated.
11020
+ `;
11021
+ const scenarioYaml = header + stringify(scenario);
11022
+ return { scenario, scenarioYaml };
11023
+ }
10900
11024
 
10901
11025
  // src/eval/runner.ts
10902
11026
  init_runDeps();
@@ -11356,12 +11480,51 @@ async function runEvalCommand(raw, deps = defaultRunDeps) {
11356
11480
  deps.exit(failing > 0 ? 1 : 0);
11357
11481
  return;
11358
11482
  }
11483
+ async function runEvalRecordCommand(raw, deps = defaultRunDeps) {
11484
+ if (!raw.from) {
11485
+ deps.error("error: --from <dir> is required (a harnessed root / checkpoint dir)");
11486
+ deps.exit(2);
11487
+ return;
11488
+ }
11489
+ let scenarioYaml;
11490
+ let name;
11491
+ try {
11492
+ const rec = recordScenario(raw.from, {
11493
+ ...raw.includeText !== void 0 ? { includeText: raw.includeText } : {},
11494
+ ...raw.name !== void 0 ? { name: raw.name } : {}
11495
+ });
11496
+ scenarioYaml = rec.scenarioYaml;
11497
+ name = rec.scenario.name;
11498
+ } catch (e) {
11499
+ deps.error(`error: ${e.message}`);
11500
+ deps.exit(1);
11501
+ return;
11502
+ }
11503
+ if (!raw.out) {
11504
+ deps.log(scenarioYaml);
11505
+ deps.log("# (no --out \u2014 scenario printed only; pass --out <dir> to also generate golden.json)");
11506
+ deps.exit(0);
11507
+ return;
11508
+ }
11509
+ const scenarioDir = resolve(raw.out, name);
11510
+ mkdirSync(scenarioDir, { recursive: true });
11511
+ writeFileSync(resolve(scenarioDir, "scenario.yaml"), scenarioYaml, "utf8");
11512
+ const suite = await runEvalSuite(resolve(raw.out), { updateGolden: true, filter: name });
11513
+ const r = suite.results.find((x) => x.name === name);
11514
+ deps.log(`[harnessed eval record] wrote ${scenarioDir}/scenario.yaml + golden.json`);
11515
+ deps.log(`[harnessed eval record] replay: ${r?.status ?? "UNKNOWN"} (golden generated)`);
11516
+ deps.exit(r?.status === "UPDATED" ? 0 : 1);
11517
+ return;
11518
+ }
11359
11519
  function registerEval(program2) {
11360
- program2.command("eval").description(
11520
+ const evalCmd = program2.command("eval").description(
11361
11521
  "run the orchestrator-behavior regression trap suite (deterministic replay; CI gate)"
11362
11522
  ).option("--dir <path>", "scenario suite directory (default: ./fixtures/eval)").option("--json", "machine-readable results").option("--coverage", "print judgments-trigger coverage matrix (bare triggers highlighted)").option("--update-golden", "re-record goldens (prints the diff \u2014 review it, never blind-bless)").option("--filter <substr>", "run only scenarios whose name/dir matches").action(async (raw) => {
11363
11523
  await runEvalCommand(raw);
11364
11524
  });
11525
+ evalCmd.command("record").description("record a real run trajectory into a replayable trap scenario (Slice C)").requiredOption("--from <dir>", "a harnessed root / checkpoint dir with current-workflow.json").option("--out <dir>", "write <out>/<name>/{scenario.yaml,golden.json} (also generates golden)").option("--include-text", "keep original task/summary text (default: redact \u2014 privacy)").option("--name <name>", "scenario name (default: recorded-<phase>)").action(async (raw) => {
11526
+ await runEvalRecordCommand(raw);
11527
+ });
11365
11528
  }
11366
11529
 
11367
11530
  // src/cli/exempt-gateguard.ts