harness-everything 1.1.0 → 1.2.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.
Files changed (32) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +19 -0
  4. package/benchmarks/results/live-host/agy-2026-11-25/README.md +32 -0
  5. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/README.md +32 -0
  6. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/claude-records.json +1 -0
  7. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/codex-hook-trace.txt +24 -0
  8. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/opencode-records.json +1 -0
  9. package/benchmarks/results/live-host/multi-host-2026-11-25-496-capture/probe.sh +16 -0
  10. package/ci/mechanism-498-local-store-promote.test.js +402 -0
  11. package/ci/mechanism-498-local-store-scan.test.js +570 -0
  12. package/ci/mechanism-516-windows-verify-and-shell.test.js +328 -0
  13. package/docs/platform-capabilities.md +2 -2
  14. package/docs/platform-compatibility.json +2 -2
  15. package/error-ledger-bootstrap/SKILL.md +1 -1
  16. package/error-ledger-bootstrap/references/workflow.md +15 -1
  17. package/error-ledger-bootstrap/scripts/promote.js +145 -9
  18. package/error-ledger-bootstrap/scripts/scan.js +394 -3
  19. package/hooks/scripts/lib/workflow-isolation.js +1 -1
  20. package/opencode-plugin/plugin.json +1 -1
  21. package/package.json +1 -1
  22. package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
  23. package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
  24. package/plugins/harness-everything/hooks/scripts/lib/workflow-isolation.js +1 -1
  25. package/plugins/harness-everything/plugin.json +1 -1
  26. package/plugins/harness-everything/scripts/lib/verification-contract.js +68 -12
  27. package/plugins/harness-everything/skills/error-ledger-bootstrap/SKILL.md +1 -1
  28. package/plugins/harness-everything/skills/error-ledger-bootstrap/references/workflow.md +15 -1
  29. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/promote.js +145 -9
  30. package/plugins/harness-everything/skills/error-ledger-bootstrap/scripts/scan.js +394 -3
  31. package/sbom.cdx.json +7 -7
  32. package/scripts/lib/verification-contract.js +68 -12
@@ -7,10 +7,14 @@ const fs = require('node:fs');
7
7
  const os = require('node:os');
8
8
  const path = require('node:path');
9
9
 
10
- const USAGE = 'usage: node scan.js --root <repo> [--out <dir>] [--no-memory] [--memory <path>]... [--instructions <path>]... [--tracker <file.json>]... [--hide-ledger] [--home <dir>] [--json]';
10
+ const USAGE = 'usage: node scan.js --root <repo> [--out <dir>] [--no-memory] [--memory <path>]... [--instructions <path>]... [--tracker <file.json>]... [--source local-store --destination harness|project] [--hide-ledger] [--home <dir>] [--json]';
11
11
  const HASH = /^[0-9a-f]{40}$/i;
12
- const SOURCE_STATUSES = new Set(['used', 'missing', 'disabled', 'unverified']);
12
+ const SOURCE_STATUSES = new Set(['used', 'missing', 'disabled', 'unverified', 'unavailable']);
13
13
  const GIT_MAX_BUFFER = 32 * 1024 * 1024;
14
+ const LEDGER_INDEX_MAX_BYTES = 512 * 1024;
15
+ const LOCAL_IDENTIFIER = /^[a-z0-9][a-z0-9_-]{0,63}$/;
16
+ const PROVISIONAL_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
17
+ const RECORD_ID = /^E-\d{4,}$/;
14
18
 
15
19
  function failure(message, exitCode = 2) {
16
20
  const error = new Error(message);
@@ -21,7 +25,7 @@ function failure(message, exitCode = 2) {
21
25
  function parseArgs(args) {
22
26
  const options = { memory: [], instructions: [], tracker: [], noMemory: false, hideLedger: false, json: false };
23
27
  const seen = new Set();
24
- const values = new Set(['--root', '--out', '--home', '--memory', '--instructions', '--tracker']);
28
+ const values = new Set(['--root', '--out', '--home', '--memory', '--instructions', '--tracker', '--source', '--destination']);
25
29
  for (let i = 0; i < args.length; i++) {
26
30
  const arg = args[i];
27
31
  if (arg === '--no-memory' || arg === '--hide-ledger' || arg === '--json') {
@@ -44,6 +48,12 @@ function parseArgs(args) {
44
48
  options[arg.slice(2)] = value;
45
49
  }
46
50
  if (!options.root) failure(`--root is required; ${USAGE}`);
51
+ if (options.source !== undefined && options.source !== 'local-store') failure(`unknown source: ${options.source}`);
52
+ if (options.source === 'local-store' && !options.destination) failure('--destination is required for --source local-store');
53
+ if (options.destination !== undefined && options.source !== 'local-store') failure('--destination requires --source local-store');
54
+ if (options.destination !== undefined && !['harness', 'project'].includes(options.destination)) {
55
+ failure(`invalid --destination: ${options.destination}`);
56
+ }
47
57
  return options;
48
58
  }
49
59
 
@@ -444,6 +454,369 @@ function collectSources(options, root, home, files, historyCandidates) {
444
454
  return { sources, candidates };
445
455
  }
446
456
 
457
+ function localStoreRef(workspaceKey, provisionalId) {
458
+ const key = JSON.stringify([workspaceKey, provisionalId]);
459
+ return `p-local-${crypto.createHash('sha256').update(key).digest('hex')}`;
460
+ }
461
+
462
+ function workspaceRef(workspaceKey) {
463
+ return `w-local-${crypto.createHash('sha256').update(workspaceKey).digest('hex')}`;
464
+ }
465
+
466
+ function validLocalRecord(record, workspaceKey, store) {
467
+ if (!record || typeof record !== 'object' || Array.isArray(record) ||
468
+ record.schemaVersion !== store.SCHEMA_VERSION ||
469
+ !['occurrence', 'provisional-lesson'].includes(record.kind) ||
470
+ record.workspaceKey !== workspaceKey ||
471
+ typeof record.provisionalId !== 'string' || !PROVISIONAL_ID.test(record.provisionalId) || /^E-/i.test(record.provisionalId) ||
472
+ !store.DESTINATIONS.includes(record.destination) ||
473
+ typeof record.signature !== 'string' || !LOCAL_IDENTIFIER.test(record.signature) ||
474
+ typeof record.createdAt !== 'string' || !Number.isFinite(Date.parse(record.createdAt))) return false;
475
+ if (record.kind === 'occurrence') {
476
+ return record.source === 'tool-failure' && ['claude', 'codex', 'opencode', 'unknown'].includes(record.host) &&
477
+ store.COMMAND_CLASSES.includes(record.commandClass) &&
478
+ (record.exitCode === null || Number.isSafeInteger(record.exitCode)) &&
479
+ (record.sessionKey === null || /^[a-f0-9]{24}$/.test(record.sessionKey)) &&
480
+ (record.toolUseId === null || /^[a-f0-9]{24}$/.test(record.toolUseId)) &&
481
+ typeof record.outputExcerpt === 'string' && Buffer.byteLength(record.outputExcerpt, 'utf8') <= store.LIMITS.maxExcerptBytes &&
482
+ Array.isArray(record.matchedLedgerIds) && record.matchedLedgerIds.length <= store.LIMITS.maxMatchedLedgerIds &&
483
+ record.matchedLedgerIds.every(id => typeof id === 'string' && (RECORD_ID.test(id) || LOCAL_IDENTIFIER.test(id)));
484
+ }
485
+ try {
486
+ store.validateMatch(record.match);
487
+ } catch (_) { return false; }
488
+ return typeof record.lesson === 'string' && record.lesson.trim().length > 0 &&
489
+ Buffer.byteLength(record.lesson, 'utf8') <= store.LIMITS.maxLessonChars &&
490
+ (record.cue === undefined || (typeof record.cue === 'string' && Buffer.byteLength(record.cue, 'utf8') <= store.LIMITS.maxCueChars)) &&
491
+ (record.issueUrl === null || typeof record.issueUrl === 'string') &&
492
+ (record.promotionId === null || (typeof record.promotionId === 'string' && RECORD_ID.test(record.promotionId)));
493
+ }
494
+
495
+ function validLocalStoreReader(store) {
496
+ try {
497
+ if (!store || typeof store !== 'object' || Array.isArray(store)) return false;
498
+ const destinations = store.DESTINATIONS;
499
+ const commandClasses = store.COMMAND_CLASSES;
500
+ const limits = store.LIMITS;
501
+ const validEnum = (values, required) => Array.isArray(values) &&
502
+ required.every(value => values.includes(value)) &&
503
+ values.every((value, index) => typeof value === 'string' && value.length > 0 && values.indexOf(value) === index);
504
+ return Number.isSafeInteger(store.SCHEMA_VERSION) && store.SCHEMA_VERSION > 0 &&
505
+ typeof store.INDEX_FILE === 'string' && /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(store.INDEX_FILE) &&
506
+ typeof store.INDEX_KIND === 'string' && store.INDEX_KIND.length > 0 &&
507
+ validEnum(destinations, ['harness', 'project', 'unknown']) &&
508
+ validEnum(commandClasses, ['git', 'gh', 'test', 'build', 'package', 'shell']) &&
509
+ limits !== null && typeof limits === 'object' && !Array.isArray(limits) &&
510
+ ['maxIndexBytes', 'maxExcerptBytes', 'maxMatchedLedgerIds', 'maxLessonChars', 'maxCueChars']
511
+ .every(name => Number.isSafeInteger(limits[name]) && limits[name] > 0) &&
512
+ ['getStorePath', 'resolveWorkspaceKey', 'listRecords', 'validateMatch']
513
+ .every(name => typeof store[name] === 'function');
514
+ } catch (_) { return false; }
515
+ }
516
+
517
+ function inspectLocalStore(file, store) {
518
+ let stat;
519
+ try { stat = fs.lstatSync(file); }
520
+ catch (cause) {
521
+ return cause.code === 'ENOENT'
522
+ ? { status: 'missing', reason: 'index-missing' }
523
+ : { status: 'unverified', reason: 'store-unreadable' };
524
+ }
525
+ if (stat.isSymbolicLink() || !stat.isFile()) return { status: 'unverified', reason: 'store-unreadable' };
526
+ if (stat.size > store.LIMITS.maxIndexBytes) return { status: 'unverified', reason: 'store-corrupt' };
527
+ let envelope;
528
+ try {
529
+ const bytes = fs.readFileSync(file);
530
+ if (bytes.length > store.LIMITS.maxIndexBytes) return { status: 'unverified', reason: 'store-corrupt' };
531
+ envelope = JSON.parse(bytes.toString('utf8'));
532
+ } catch (_) { return { status: 'unverified', reason: 'store-corrupt' }; }
533
+ if (!envelope || typeof envelope !== 'object' || Array.isArray(envelope) || !Array.isArray(envelope.records)) {
534
+ return { status: 'unverified', reason: 'store-corrupt' };
535
+ }
536
+ if (envelope.schemaVersion !== store.SCHEMA_VERSION || envelope.kind !== store.INDEX_KIND) {
537
+ return { status: 'unverified', reason: 'store-unsupported' };
538
+ }
539
+ return { status: 'used', rowCount: envelope.records.length };
540
+ }
541
+
542
+ function inspectDestinationLedger(root, store) {
543
+ const errors = path.join(root, '.agents', 'harness-everything', 'errors');
544
+ let errorsStat;
545
+ try { errorsStat = fs.lstatSync(errors); }
546
+ catch (cause) {
547
+ return cause.code === 'ENOENT'
548
+ ? { status: 'unverified', reason: 'ledger-missing', rows: [] }
549
+ : { status: 'unverified', reason: 'ledger-unreadable', rows: [] };
550
+ }
551
+ if (errorsStat.isSymbolicLink() || !errorsStat.isDirectory()) return { status: 'unverified', reason: 'ledger-unreadable', rows: [] };
552
+ let realErrors;
553
+ try { realErrors = canonical(errors); }
554
+ catch (_) { return { status: 'unverified', reason: 'ledger-unreadable', rows: [] }; }
555
+ if (!isWithin(root, realErrors)) return { status: 'unverified', reason: 'ledger-unreadable', rows: [] };
556
+
557
+ const file = path.join(realErrors, 'index.jsonl');
558
+ let stat;
559
+ try { stat = fs.lstatSync(file); }
560
+ catch (cause) {
561
+ return cause.code === 'ENOENT'
562
+ ? { status: 'unverified', reason: 'ledger-missing', rows: [] }
563
+ : { status: 'unverified', reason: 'ledger-unreadable', rows: [] };
564
+ }
565
+ if (stat.isSymbolicLink() || !stat.isFile()) return { status: 'unverified', reason: 'ledger-unreadable', rows: [] };
566
+ if (stat.size > LEDGER_INDEX_MAX_BYTES) return { status: 'unverified', reason: 'ledger-corrupt', rows: [] };
567
+
568
+ let text;
569
+ try {
570
+ text = fs.readFileSync(file, 'utf8');
571
+ if (Buffer.byteLength(text, 'utf8') > LEDGER_INDEX_MAX_BYTES) return { status: 'unverified', reason: 'ledger-corrupt', rows: [] };
572
+ } catch (_) { return { status: 'unverified', reason: 'ledger-unreadable', rows: [] }; }
573
+
574
+ const lines = text.split(/\r?\n/);
575
+ if (lines.at(-1) === '') lines.pop();
576
+ if (lines.length > 512 || lines.some(line => !line.trim())) return { status: 'unverified', reason: 'ledger-corrupt', rows: [] };
577
+ const rows = [];
578
+ const ids = new Set();
579
+ try {
580
+ for (const line of lines) {
581
+ const row = JSON.parse(line);
582
+ if (!row || typeof row !== 'object' || Array.isArray(row) ||
583
+ typeof row.id !== 'string' || !RECORD_ID.test(row.id) || ids.has(row.id) ||
584
+ typeof row.signature !== 'string' || !LOCAL_IDENTIFIER.test(row.signature) ||
585
+ typeof row.file !== 'string' || !new RegExp(`^\\.agents/harness-everything/errors/${row.id}-[a-z0-9-]+\\.md$`).test(row.file)) {
586
+ throw new Error('invalid index row');
587
+ }
588
+ let match = null;
589
+ if (Object.hasOwn(row, 'match')) {
590
+ match = store.validateMatch(row.match);
591
+ if (typeof row.matchBinding !== 'string' || !/^[a-f0-9]{64}$/.test(row.matchBinding)) throw new Error('invalid match binding');
592
+ } else if (Object.hasOwn(row, 'matchBinding')) throw new Error('invalid match binding');
593
+ ids.add(row.id);
594
+ rows.push({ id: row.id, signature: row.signature, match });
595
+ }
596
+ } catch (_) { return { status: 'unverified', reason: 'ledger-corrupt', rows: [] }; }
597
+ return { status: 'verified', rows };
598
+ }
599
+
600
+ function canonicalMatch(match, store) {
601
+ const validated = store.validateMatch(match);
602
+ const normalized = {};
603
+ for (const phase of ['actions', 'failures']) {
604
+ if (!validated[phase]) continue;
605
+ normalized[phase] = validated[phase].map(rule => ({
606
+ ...rule,
607
+ ...(rule.diagnostics ? { diagnostics: [...rule.diagnostics].sort() } : {})
608
+ })).sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
609
+ }
610
+ return JSON.stringify(normalized);
611
+ }
612
+
613
+ function destinationDedupe(signature, match, ledger, store) {
614
+ if (ledger.status !== 'verified') {
615
+ return { status: 'unverified', classIds: [], matchedBy: [], newClassEligible: false };
616
+ }
617
+ const matches = new Map();
618
+ const localMatch = match ? canonicalMatch(match, store) : null;
619
+ for (const row of ledger.rows) {
620
+ const methods = [];
621
+ if (row.signature === signature) methods.push('signature');
622
+ if (localMatch && row.match && canonicalMatch(row.match, store) === localMatch) methods.push('whole-rule');
623
+ if (methods.length) matches.set(row.id, new Set([...(matches.get(row.id) || []), ...methods]));
624
+ }
625
+ const classIds = [...matches.keys()].sort();
626
+ const matchedBy = [...new Set([...matches.values()].flatMap(methods => [...methods]))].sort();
627
+ return {
628
+ status: classIds.length > 1 ? 'ambiguous' : classIds.length === 1 ? 'existing' : 'none',
629
+ classIds,
630
+ matchedBy,
631
+ newClassEligible: classIds.length === 0
632
+ };
633
+ }
634
+
635
+ function localCandidate(title, signature, records, match, ledger, store, destination) {
636
+ const candidate = makeCandidate({
637
+ title,
638
+ signature,
639
+ sites: [],
640
+ sources: records.map(record => ({
641
+ type: 'local-store',
642
+ kind: record.kind,
643
+ ref: localStoreRef(record.workspaceKey, record.provisionalId),
644
+ destination,
645
+ signature: record.signature,
646
+ ...(record.kind === 'occurrence' ? { commandClass: record.commandClass } : {})
647
+ }))
648
+ });
649
+ candidate.local = {
650
+ evidenceReadiness: 'needs-evidence',
651
+ occurrenceCount: records.filter(record => record.kind === 'occurrence').length,
652
+ dedupe: destinationDedupe(signature, match, ledger, store)
653
+ };
654
+ return candidate;
655
+ }
656
+
657
+ function collectLocalStore(options, root) {
658
+ const fallbackWorkspaceRef = workspaceRef(root);
659
+ const emptyCounts = { workspaceRecords: 0, lessons: 0, occurrences: 0, candidates: 0, destinationMismatch: 0, unknownDestination: 0, malformed: 0, suppressedOccurrences: 0 };
660
+ let store;
661
+ try { store = require(path.join(__dirname, '..', '..', 'hooks', 'scripts', 'lib', 'local-errors.js')); }
662
+ catch (_) {
663
+ const ledger = { status: 'unverified', reason: 'ledger-not-checked' };
664
+ return {
665
+ source: sourceStatus('local-store', 'workspace', 'unavailable', {
666
+ reason: 'reader-unavailable', workspaceRef: fallbackWorkspaceRef, destination: options.destination,
667
+ ledgerStatus: ledger.status, ledgerReason: ledger.reason,
668
+ counts: { workspaceRecords: 0, lessons: 0, occurrences: 0, candidates: 0, destinationMismatch: 0, unknownDestination: 0, malformed: 0, suppressedOccurrences: 0 }
669
+ }),
670
+ candidates: []
671
+ };
672
+ }
673
+ if (!validLocalStoreReader(store)) {
674
+ return {
675
+ source: sourceStatus('local-store', 'workspace', 'unavailable', {
676
+ reason: 'reader-contract-incomplete', workspaceRef: fallbackWorkspaceRef, destination: options.destination,
677
+ ledgerStatus: 'unverified', ledgerReason: 'ledger-not-checked', counts: emptyCounts
678
+ }),
679
+ candidates: []
680
+ };
681
+ }
682
+
683
+ let workspaceKey;
684
+ try { workspaceKey = store.resolveWorkspaceKey({ workspaceRoot: root }); }
685
+ catch (_) {
686
+ return {
687
+ source: sourceStatus('local-store', 'workspace', 'unverified', {
688
+ reason: 'workspace-unavailable', workspaceRef: fallbackWorkspaceRef, destination: options.destination,
689
+ ledgerStatus: 'unverified', ledgerReason: 'ledger-not-checked',
690
+ counts: emptyCounts
691
+ }),
692
+ candidates: []
693
+ };
694
+ }
695
+ const ref = workspaceRef(workspaceKey);
696
+ const hostBinding = ['HARNESS_WORKSPACE_ROOT', 'CLAUDE_PROJECT_DIR', 'CODEX_PROJECT_DIR']
697
+ .some(name => typeof process.env[name] === 'string' && process.env[name].trim());
698
+ if (hostBinding) {
699
+ let hostKey;
700
+ try { hostKey = store.resolveWorkspaceKey({}, { env: process.env }); }
701
+ catch (_) {
702
+ return {
703
+ source: sourceStatus('local-store', 'workspace', 'unverified', {
704
+ reason: 'workspace-binding-unavailable', workspaceRef: ref, destination: options.destination,
705
+ ledgerStatus: 'unverified', ledgerReason: 'ledger-not-checked',
706
+ counts: emptyCounts
707
+ }),
708
+ candidates: []
709
+ };
710
+ }
711
+ if (hostKey !== workspaceKey) {
712
+ return {
713
+ source: sourceStatus('local-store', 'workspace', 'unverified', {
714
+ reason: 'workspace-binding-mismatch', workspaceRef: ref, destination: options.destination,
715
+ ledgerStatus: 'unverified', ledgerReason: 'ledger-not-checked',
716
+ counts: emptyCounts
717
+ }),
718
+ candidates: []
719
+ };
720
+ }
721
+ }
722
+
723
+ let storePath;
724
+ try { storePath = store.getStorePath().file; }
725
+ catch (_) {
726
+ return {
727
+ source: sourceStatus('local-store', 'workspace', 'unverified', {
728
+ reason: 'store-unreadable', workspaceRef: ref, destination: options.destination,
729
+ ledgerStatus: 'unverified', ledgerReason: 'ledger-not-checked',
730
+ counts: emptyCounts
731
+ }),
732
+ candidates: []
733
+ };
734
+ }
735
+ const diagnostic = inspectLocalStore(storePath, store);
736
+ const ledger = inspectDestinationLedger(root, store);
737
+ if (diagnostic.status !== 'used') {
738
+ return {
739
+ source: sourceStatus('local-store', 'workspace', diagnostic.status, {
740
+ reason: diagnostic.reason, workspaceRef: ref, destination: options.destination,
741
+ ledgerStatus: ledger.status, ...(ledger.reason ? { ledgerReason: ledger.reason } : {}), counts: emptyCounts
742
+ }),
743
+ candidates: []
744
+ };
745
+ }
746
+
747
+ let records;
748
+ try {
749
+ records = store.listRecords({ workspaceRoot: root, workspaceKey });
750
+ } catch (_) {
751
+ return {
752
+ source: sourceStatus('local-store', 'workspace', 'unverified', {
753
+ reason: 'reader-failed', workspaceRef: ref, destination: options.destination,
754
+ ledgerStatus: ledger.status, ...(ledger.reason ? { ledgerReason: ledger.reason } : {}), counts: emptyCounts
755
+ }),
756
+ candidates: []
757
+ };
758
+ }
759
+ const scoped = Array.isArray(records) ? records.filter(record => record && record.workspaceKey === workspaceKey) : [];
760
+ let malformed = Array.isArray(records) ? 0 : 1;
761
+ const valid = [];
762
+ const seen = new Set();
763
+ for (const record of scoped) {
764
+ const key = `${record.kind}:${record.provisionalId}`;
765
+ if (!validLocalRecord(record, workspaceKey, store) || seen.has(key)) {
766
+ malformed += 1;
767
+ continue;
768
+ }
769
+ seen.add(key);
770
+ valid.push(record);
771
+ }
772
+ const idKinds = new Map();
773
+ for (const record of valid) {
774
+ const kinds = idKinds.get(record.provisionalId) || new Set();
775
+ kinds.add(record.kind);
776
+ idKinds.set(record.provisionalId, kinds);
777
+ }
778
+ const collisions = new Set([...idKinds].filter(([, kinds]) => kinds.size > 1).map(([id]) => id));
779
+ const unambiguous = valid.filter(record => {
780
+ if (!collisions.has(record.provisionalId)) return true;
781
+ malformed += 1;
782
+ return false;
783
+ });
784
+ const counts = { ...emptyCounts, workspaceRecords: unambiguous.length, malformed };
785
+ const selected = [];
786
+ for (const record of unambiguous) {
787
+ if (record.destination === 'unknown') { counts.unknownDestination += 1; continue; }
788
+ if (record.destination !== options.destination) { counts.destinationMismatch += 1; continue; }
789
+ selected.push(record);
790
+ if (record.kind === 'provisional-lesson') counts.lessons += 1;
791
+ else counts.occurrences += 1;
792
+ }
793
+ const lessons = selected.filter(record => record.kind === 'provisional-lesson');
794
+ const covered = new Set(lessons.map(record => record.signature));
795
+ const candidates = lessons.map(record => localCandidate(
796
+ 'Local provisional lesson', record.signature, [record], record.match, ledger, store, options.destination
797
+ ));
798
+ const occurrences = new Map();
799
+ for (const record of selected.filter(record => record.kind === 'occurrence')) {
800
+ if (covered.has(record.signature)) { counts.suppressedOccurrences += 1; continue; }
801
+ const group = occurrences.get(record.signature) || [];
802
+ group.push(record);
803
+ occurrences.set(record.signature, group);
804
+ }
805
+ for (const [signature, group] of occurrences) {
806
+ candidates.push(localCandidate('Local tool-failure lead', signature, group, null, ledger, store, options.destination));
807
+ }
808
+ counts.candidates = candidates.length;
809
+ const status = malformed || scoped.length === 0 ? 'unverified' : 'used';
810
+ const reason = collisions.size ? 'provisional-id-collision' : malformed ? 'malformed-records' : scoped.length === 0 ? 'empty-reader-result' : undefined;
811
+ return {
812
+ source: sourceStatus('local-store', 'workspace', status, {
813
+ ...(reason ? { reason } : {}), workspaceRef: ref, destination: options.destination,
814
+ ledgerStatus: ledger.status, ...(ledger.reason ? { ledgerReason: ledger.reason } : {}), counts
815
+ }),
816
+ candidates
817
+ };
818
+ }
819
+
447
820
  function addAttachments(candidates, files, root, hideLedger) {
448
821
  const testFiles = files.filter(file => {
449
822
  const base = path.posix.basename(file);
@@ -498,10 +871,23 @@ function markdownReport(report) {
498
871
  for (const source of report.sources) {
499
872
  const label = source.ref || (source.refs && source.refs.join(', ')) || source.origin;
500
873
  lines.push(`- \`${source.type}\` (${source.origin}) — **${source.status}** — ${label}${source.reason ? ` — ${source.reason}` : ''}${source.verified === undefined ? '' : ` — verified: ${source.verified}`}${source.verificationRef ? ` — verification: ${source.verificationRef}` : ''}`);
874
+ if (source.type === 'local-store') {
875
+ lines.push(` - Workspace ref: \`${source.workspaceRef}\``, ` - Destination: \`${source.destination}\``,
876
+ ` - Records: ${source.counts.workspaceRecords}; lessons: ${source.counts.lessons}; occurrences: ${source.counts.occurrences}; candidates: ${source.counts.candidates}`,
877
+ ` - Destination mismatches: ${source.counts.destinationMismatch}; unknown destinations: ${source.counts.unknownDestination}; malformed: ${source.counts.malformed}; suppressed occurrences: ${source.counts.suppressedOccurrences}`,
878
+ ` - Destination ledger dedupe: **${source.ledgerStatus}**${source.ledgerReason ? ` — ${source.ledgerReason}` : ''}`);
879
+ }
501
880
  }
502
881
  lines.push('', '## Candidates', '');
503
882
  for (const item of report.candidates) {
504
883
  lines.push(`### ${item.title}`, '', `- ID: \`${item.id}\``, `- Kind: \`${item.kind}\``, `- Domain: \`${item.domain}\``, `- Signature: \`${item.signature}\``, `- Status: **${item.status}**`, `- Sites: ${item.sites.length ? item.sites.map(site => `\`${site}\``).join(', ') : 'none'}`, '- Sources:');
884
+ if (item.local) {
885
+ lines.push(`- Evidence readiness: **${item.local.evidenceReadiness}**`,
886
+ `- Occurrence count: ${item.local.occurrenceCount}`,
887
+ `- Destination dedupe: **${item.local.dedupe.status}**${item.local.dedupe.classIds.length ? ` — ${item.local.dedupe.classIds.map(id => `\`${id}\``).join(', ')}` : ''}`,
888
+ `- Exact match signals: ${item.local.dedupe.matchedBy.length ? item.local.dedupe.matchedBy.join(', ') : 'none'}`,
889
+ `- New-class dedupe eligible: ${item.local.dedupe.newClassEligible}`);
890
+ }
505
891
  for (const source of item.sources) {
506
892
  lines.push(` - \`${source.type}\` ${source.ref || source.path || source.sha}${source.path && source.sha ? ` — ${source.sha}` : ''}${source.subject ? ` — ${source.subject}` : ''}`);
507
893
  }
@@ -597,6 +983,11 @@ function scan(options) {
597
983
  const historyCandidates = parseHistory(root, options.hideLedger);
598
984
  const files = repoFiles(root);
599
985
  const selected = collectSources(options, root, home, files, historyCandidates);
986
+ if (options.source === 'local-store') {
987
+ const local = collectLocalStore(options, root);
988
+ selected.sources.push(local.source);
989
+ selected.candidates.push(...local.candidates);
990
+ }
600
991
  const candidates = [...new Map([...historyCandidates, ...selected.candidates].map(item => [item.id, item])).values()];
601
992
  addAttachments(candidates, files, root, options.hideLedger);
602
993
  for (const item of candidates) {
@@ -192,7 +192,7 @@ function linkedWorktree(cwd, boundRoot) {
192
192
  // a raw regex split so quoted/escaped separator characters remain arguments.
193
193
  // Unsupported shell syntax still fails closed.
194
194
  const DANGEROUS_FLAG_RE = /\s(?:--(?:output|ext-diff|textconv|exec|pre|pre-glob|pager|open|batch|filters)|-[xoO])(?:\b|=)|\s-(?:exec|execdir|delete|fprint|fprintf)\b/i;
195
- const READ_ONLY_PREFIX_RE = /^(?:git\s+(?:status|rev-parse|diff|log|show|ls-files|check-ignore)(?:\s|$)|git\s+branch\s+--show-current$|git\s+worktree\s+list(?:\s|$)|gh\s+(?:issue|pr)\s+(?:view|list)(?:\s|$)|gh\s+repo\s+view(?:\s|$)|gh\s+auth\s+status(?:\s|$)|(?:pwd|ls|dir|cat|type|head|tail|wc|stat|rg|grep|echo|Get-Location|Get-ChildItem|Get-Content|Select-String|Test-Path)(?:\s|$))/i;
195
+ const READ_ONLY_PREFIX_RE = /^(?:git\s+(?:status|rev-parse|diff|log|show|ls-files|check-ignore)(?:\s|$)|git\s+branch\s+--show-current$|git\s+worktree\s+list(?:\s|$)|gh\s+(?:issue|pr)\s+(?:view|list)(?:\s|$)|gh\s+repo\s+view(?:\s|$)|gh\s+auth\s+status(?:\s|$)|agy\s+(?:--version|plugin\s+(?:list|validate))(?:\s|$)|(?:pwd|ls|dir|cat|type|head|tail|wc|stat|rg|grep|echo|Get-Location|Get-ChildItem|Get-Content|Get-Command|Get-FileHash|Select-String|Select-Object|Sort-Object|Measure-Object|Format-Table|Format-List|Out-String|ConvertTo-Json|ConvertFrom-Json|Test-Path)(?:\s|$))/i;
196
196
  function isVerificationShell(command, options = {}) {
197
197
  return isVerificationCommand(command, options);
198
198
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "harness-enforcement",
3
3
  "description": "Repository inventory for the opencode enforcement plugin and its standalone helper",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "runtime": "index.mjs",
6
6
  "hooks": {
7
7
  "verify": "hooks/verify.js"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Harness OS: An Orchestrated Agent Operating System for AI-driven Development",
5
5
  "main": "harness-everything/scripts/bootstrap.js",
6
6
  "bin": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
5
5
  "author": {
6
6
  "name": "Miya Daniel",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "harness-everything",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
5
5
  "author": {
6
6
  "name": "Miya Daniel",
@@ -192,7 +192,7 @@ function linkedWorktree(cwd, boundRoot) {
192
192
  // a raw regex split so quoted/escaped separator characters remain arguments.
193
193
  // Unsupported shell syntax still fails closed.
194
194
  const DANGEROUS_FLAG_RE = /\s(?:--(?:output|ext-diff|textconv|exec|pre|pre-glob|pager|open|batch|filters)|-[xoO])(?:\b|=)|\s-(?:exec|execdir|delete|fprint|fprintf)\b/i;
195
- const READ_ONLY_PREFIX_RE = /^(?:git\s+(?:status|rev-parse|diff|log|show|ls-files|check-ignore)(?:\s|$)|git\s+branch\s+--show-current$|git\s+worktree\s+list(?:\s|$)|gh\s+(?:issue|pr)\s+(?:view|list)(?:\s|$)|gh\s+repo\s+view(?:\s|$)|gh\s+auth\s+status(?:\s|$)|(?:pwd|ls|dir|cat|type|head|tail|wc|stat|rg|grep|echo|Get-Location|Get-ChildItem|Get-Content|Select-String|Test-Path)(?:\s|$))/i;
195
+ const READ_ONLY_PREFIX_RE = /^(?:git\s+(?:status|rev-parse|diff|log|show|ls-files|check-ignore)(?:\s|$)|git\s+branch\s+--show-current$|git\s+worktree\s+list(?:\s|$)|gh\s+(?:issue|pr)\s+(?:view|list)(?:\s|$)|gh\s+repo\s+view(?:\s|$)|gh\s+auth\s+status(?:\s|$)|agy\s+(?:--version|plugin\s+(?:list|validate))(?:\s|$)|(?:pwd|ls|dir|cat|type|head|tail|wc|stat|rg|grep|echo|Get-Location|Get-ChildItem|Get-Content|Get-Command|Get-FileHash|Select-String|Select-Object|Sort-Object|Measure-Object|Format-Table|Format-List|Out-String|ConvertTo-Json|ConvertFrom-Json|Test-Path)(?:\s|$))/i;
196
196
  function isVerificationShell(command, options = {}) {
197
197
  return isVerificationCommand(command, options);
198
198
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "harness-everything",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "description": "Invariant-first engineering harness for routing, verification, and failure recovery while preserving agent autonomy.",
6
6
  "author": {
7
7
  "name": "Miya Daniel",
@@ -201,6 +201,12 @@ function detectRoot(root) {
201
201
  }
202
202
  if (fs.existsSync(path.join(root, 'tox.ini'))) addCandidate(candidates, seen, { source: 'tox', run: 'tox', cwd: root });
203
203
  if (fs.existsSync(path.join(root, 'noxfile.py'))) addCandidate(candidates, seen, { source: 'nox', run: 'nox', cwd: root });
204
+ if (fs.existsSync(path.join(root, 'mkdocs.yml')) || fs.existsSync(path.join(root, 'mkdocs.yaml'))) {
205
+ addCandidate(candidates, seen, { source: 'mkdocs', run: 'mkdocs build --strict', cwd: root });
206
+ if (/\[tool\.poetry(?:\.|\])/m.test(pyproject)) {
207
+ addCandidate(candidates, seen, { source: 'mkdocs:poetry', run: 'poetry run mkdocs build --strict', cwd: root });
208
+ }
209
+ }
204
210
  if (fs.existsSync(path.join(root, 'Cargo.toml'))) addCandidate(candidates, seen, { source: 'cargo', run: 'cargo test', cwd: root });
205
211
  if (fs.existsSync(path.join(root, 'go.mod'))) addCandidate(candidates, seen, { source: 'go', run: 'go test ./...', cwd: root });
206
212
 
@@ -245,6 +251,10 @@ function normalizeCommand(command) {
245
251
  return String(command || '').trim().replace(/\s+/g, ' ');
246
252
  }
247
253
 
254
+ function stripWindowsCmdShim(command) {
255
+ return String(command || '').replace(/^(npm|pnpm|yarn|bun|npx)\.cmd(?=\s|$)/i, '$1');
256
+ }
257
+
248
258
  function hasControlOperators(command) {
249
259
  return /(?:&&|\|\||[;|\r\n])/.test(command);
250
260
  }
@@ -253,7 +263,9 @@ function commandMatches(command, expected) {
253
263
  const actual = normalizeCommand(command);
254
264
  const target = normalizeCommand(expected);
255
265
  if (!actual || !target || hasControlOperators(actual)) return false;
256
- return actual === target || actual.startsWith(target + ' ');
266
+ const normalizedActual = stripWindowsCmdShim(actual);
267
+ const normalizedTarget = stripWindowsCmdShim(target);
268
+ return normalizedActual === normalizedTarget || normalizedActual.startsWith(normalizedTarget + ' ');
257
269
  }
258
270
 
259
271
  function isGitCommit(command) {
@@ -274,9 +286,28 @@ function bypassesHooks(command) {
274
286
  );
275
287
  }
276
288
 
289
+ const NODE_TEST_RE = /^node\s+--test(?:\s|$)/i;
290
+ const DOC_BUILD_RE = /^(?:(?:uv|poetry)\s+run\s+mkdocs(?:\.exe)?\s+build|(?:(?:\.?[/\\])?(?:\.?venv|env)[/\\](?:Scripts|bin)[/\\])?(?:mkdocs(?:\.exe)?\s+build|sphinx-build(?:\.exe)?))(?:\s|$)/i;
291
+
292
+ function isVerifierInfoQuery(command) {
293
+ const nodeTest = NODE_TEST_RE.exec(command);
294
+ const verifier = nodeTest || DOC_BUILD_RE.exec(command);
295
+ if (!verifier) return false;
296
+
297
+ // Keep quoted argument values together, while recognizing quoted switches.
298
+ const args = command.slice(verifier[0].length).match(/(?:[^\s"'\x60\\]|\\.|\x60.|"[^"]*"|'[^']*')+/g) || [];
299
+ const options = args.map(arg => arg.replace(/["']/g, '').replace(/(?:\\|\x60)(?=[A-Za-z-])/g, ''));
300
+ if (options[0] === '-M' && options[1] === 'help' && /sphinx-build(?:\.exe)?\s*$/i.test(verifier[0])) return true;
301
+ const versionFlag = nodeTest ? '-v' : '-V';
302
+ return options.some(option =>
303
+ option === '--help' || option === '--version' || option === '-h' || option === versionFlag
304
+ );
305
+ }
306
+
277
307
  function legacyVerificationCommand(command) {
278
- const value = normalizeCommand(command);
279
- return /^(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|typecheck|check|verify)\b|npx\s+(?:jest|vitest|mocha|tsc|eslint)\b|(?:jest|vitest|mocha|pytest|rspec|phpunit)\b|uv\s+run\s+(?:pytest|ruff)\b|(?:make|just)\s+(?:test|check|lint|ci)\b|cargo\s+(?:test|check)\b|go\s+test\b|dotnet\s+(?:test|build)\b)/i.test(value);
308
+ const value = stripWindowsCmdShim(normalizeCommand(command));
309
+ if (NODE_TEST_RE.test(value) || DOC_BUILD_RE.test(value)) return !isVerifierInfoQuery(value);
310
+ return /^(?:(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:test|lint|build|typecheck|check|verify)\b|npx\s+(?:jest|vitest|mocha|tsc|eslint)\b|(?:jest|vitest|mocha|pytest|rspec|phpunit)\b|(?:uv|poetry)\s+run\s+(?:pytest|ruff)\b|(?:make|just)\s+(?:test|check|lint|ci)\b|cargo\s+(?:test|check)\b|go\s+test\b|dotnet\s+(?:test|build)\b)/i.test(value);
280
311
  }
281
312
 
282
313
  function verificationCommandSet(cwd, options = {}) {
@@ -334,6 +365,9 @@ function verificationCommandSet(cwd, options = {}) {
334
365
  // command must be one plain command: no further control operators,
335
366
  // redirection, substitution, expansion, subshell, or background syntax.
336
367
  const CWD_PRELUDE_RE = /^cd\s+(?:"([^"]*)"|'([^']*)'|([A-Za-z0-9_./:@%+,-]+))\s*&&\s*([\s\S]+)$/;
368
+ // PowerShell 7 must stop on a failed location change before running the
369
+ // verifier. Match only a single-quoted filesystem path with explicit flags.
370
+ const PS_CWD_PRELUDE_RE = /^Set-Location[ \t]+-LiteralPath[ \t]+'([^'\r\n]+)'[ \t]+-ErrorAction[ \t]+Stop[ \t]*&&[ \t]*([^\r\n]+)$/i;
337
371
  const UNSAFE_WRAPPED_RE = /[`$<>&|;()\r\n]/;
338
372
  const UNSAFE_DOUBLE_QUOTED_RE = /[$`!]|\\[\\"$`]|\\$/;
339
373
 
@@ -355,22 +389,44 @@ function stableCdTarget(target, platform = process.platform) {
355
389
  return target.startsWith('/');
356
390
  }
357
391
 
392
+ function stablePowerShellTarget(target, platform = process.platform) {
393
+ const start = platform === 'win32' ? /^(?:[A-Za-z]:|\.)[/\\]/ : /^(?:\.)?\//;
394
+ if (target === '.') return true;
395
+ if (!start.test(target) || (platform !== 'win32' && target.includes('\\'))) return false;
396
+ // Restrict segments to unambiguous filesystem names. In particular, a
397
+ // parent component after a symlink can resolve differently from path.resolve.
398
+ return target.replace(start, '').split(/[/\\]/).every(part =>
399
+ /^[A-Za-z0-9_. -]*[A-Za-z0-9_-]$/.test(part) && !part.startsWith(' ')
400
+ );
401
+ }
402
+
358
403
  function parseCwdPrelude(command, options = {}) {
359
- const match = String(command || '').trim().match(CWD_PRELUDE_RE);
360
- if (!match) return null;
361
- const [, doubleQuoted, singleQuoted, bare, restRaw] = match;
362
- const target = doubleQuoted ?? singleQuoted ?? bare;
404
+ const trimmed = String(command || '').trim();
405
+ const bash = trimmed.match(CWD_PRELUDE_RE);
406
+ const powerShell = bash ? null : trimmed.match(PS_CWD_PRELUDE_RE);
407
+ if (!bash && !powerShell) return null;
408
+ let target;
409
+ let restRaw;
410
+ if (bash) {
411
+ const [, doubleQuoted, singleQuoted, bare, bashRest] = bash;
412
+ target = doubleQuoted ?? singleQuoted ?? bare;
413
+ if (!target || (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target))) return null;
414
+ if (!stableCdTarget(target, options.platform)) return null;
415
+ target = hostPathToNative(target, options.platform);
416
+ restRaw = bashRest;
417
+ } else {
418
+ [, target, restRaw] = powerShell;
419
+ if (!stablePowerShellTarget(target, options.platform)) return null;
420
+ }
363
421
  const rest = restRaw.trim();
364
- if (!target || !rest) return null;
365
- if (doubleQuoted !== undefined && UNSAFE_DOUBLE_QUOTED_RE.test(target)) return null;
422
+ if (!rest) return null;
366
423
  if (UNSAFE_WRAPPED_RE.test(rest) || hasControlOperators(rest)) return null;
367
- if (!stableCdTarget(target, options.platform)) return null;
368
424
 
369
425
  const cwd = path.resolve(options.cwd || process.cwd());
370
426
  let resolved;
371
427
  let root;
372
428
  try {
373
- resolved = fs.realpathSync.native(path.resolve(cwd, hostPathToNative(target, options.platform)));
429
+ resolved = fs.realpathSync.native(path.resolve(cwd, target));
374
430
  if (!fs.statSync(resolved).isDirectory()) return null;
375
431
  root = fs.realpathSync.native(path.resolve(options.root || findGitRoot(cwd)));
376
432
  } catch (_) {
@@ -395,7 +451,7 @@ function cwdKey(dir) {
395
451
  function isPlainVerificationCommand(command, options = {}) {
396
452
  const cwd = path.resolve(options.cwd || process.cwd());
397
453
  const actual = normalizeCommand(command);
398
- if (!actual || hasControlOperators(actual)) return false;
454
+ if (!actual || hasControlOperators(actual) || isVerifierInfoQuery(actual)) return false;
399
455
  const set = verificationCommandSet(cwd, options);
400
456
  if (set.contractInvalid) return false;
401
457