harness-everything 1.0.1 → 1.1.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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +14 -0
- package/ci/mechanism-394-ledger-match.test.js +219 -0
- package/ci/mechanism-496-claude-capture.test.js +342 -0
- package/ci/mechanism-496-codex-capture.test.js +508 -0
- package/ci/mechanism-496-local-error-cli-edges.test.js +234 -0
- package/ci/mechanism-496-local-error-cli.test.js +517 -0
- package/ci/mechanism-496-local-error-store.test.js +731 -0
- package/ci/mechanism-496-opencode-capture.test.js +483 -0
- package/ci/mechanism-496-review-fixes.test.js +278 -0
- package/hooks/scripts/codex-ledger-lesson.js +103 -27
- package/hooks/scripts/ledger-lesson.js +94 -23
- package/hooks/scripts/lib/ledger-match.js +39 -3
- package/hooks/scripts/lib/local-error-source.js +127 -0
- package/hooks/scripts/lib/local-errors.js +597 -0
- package/hooks/scripts/lib/observations.js +1 -1
- package/opencode-plugin/index.mjs +86 -1
- package/opencode-plugin/plugin.json +1 -1
- package/package.json +2 -1
- package/plugins/harness-everything/.antigravity-plugin/plugin.json +1 -1
- package/plugins/harness-everything/.codex-plugin/plugin.json +1 -1
- package/plugins/harness-everything/hooks/scripts/codex-ledger-lesson.js +103 -27
- package/plugins/harness-everything/hooks/scripts/ledger-lesson.js +94 -23
- package/plugins/harness-everything/hooks/scripts/lib/ledger-match.js +39 -3
- package/plugins/harness-everything/hooks/scripts/lib/local-error-source.js +127 -0
- package/plugins/harness-everything/hooks/scripts/lib/local-errors.js +597 -0
- package/plugins/harness-everything/hooks/scripts/lib/observations.js +1 -1
- package/plugins/harness-everything/plugin.json +1 -1
- package/sbom.cdx.json +7 -7
- package/scripts/errors-local.js +357 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Provisional local lesson source reader (#496 C2) for hooks/scripts/lib/ledger-match.js.
|
|
3
|
+
// Reads workspace-scoped provisional lessons from local-errors.js on each lookup,
|
|
4
|
+
// projecting only the bounded matcher fields and failing open on any store error.
|
|
5
|
+
|
|
6
|
+
const localErrors = require('./local-errors');
|
|
7
|
+
|
|
8
|
+
const IDENTIFIER_PATTERN = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
9
|
+
const RECORD_ID_PATTERN = /^E-\d{4,}$/;
|
|
10
|
+
const RESERVED_E_PREFIX = /^E-/i;
|
|
11
|
+
const DEFAULT_MAX_CANDIDATES = 32;
|
|
12
|
+
const DEFAULT_MAX_BYTES = 64 * 1024;
|
|
13
|
+
const DEFAULT_MAX_TEXT_CHARS = 4096;
|
|
14
|
+
|
|
15
|
+
function validIdentifier(value) {
|
|
16
|
+
return typeof value === 'string' && IDENTIFIER_PATTERN.test(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function projectProvisionalRecord(record, maxTextChars) {
|
|
20
|
+
if (!record || typeof record !== 'object' || record.kind !== 'provisional-lesson') return null;
|
|
21
|
+
|
|
22
|
+
const identity = record.provisionalId;
|
|
23
|
+
if (!validIdentifier(identity) || RESERVED_E_PREFIX.test(identity)) return null;
|
|
24
|
+
|
|
25
|
+
if (typeof record.lesson !== 'string') return null;
|
|
26
|
+
const lesson = record.lesson.trim().slice(0, maxTextChars);
|
|
27
|
+
if (!lesson) return null;
|
|
28
|
+
|
|
29
|
+
let match;
|
|
30
|
+
try {
|
|
31
|
+
match = localErrors.validateMatch(record.match);
|
|
32
|
+
} catch (_) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const candidate = { identity, match, lesson };
|
|
37
|
+
|
|
38
|
+
if (validIdentifier(record.signature)) {
|
|
39
|
+
candidate.signature = record.signature;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof record.promotionId === 'string' && RECORD_ID_PATTERN.test(record.promotionId)) {
|
|
43
|
+
candidate.promotionId = record.promotionId;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (typeof record.cue === 'string') {
|
|
47
|
+
candidate.cue = record.cue.slice(0, maxTextChars);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return candidate;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Mirror ledger-match.js validProvisionalCandidate shape when checking byte budget
|
|
54
|
+
// so readProvisional's serialized byte check cannot fail on accepted candidates.
|
|
55
|
+
function matcherSerializedBytes(candidates) {
|
|
56
|
+
const transformed = candidates.map(candidate => ({
|
|
57
|
+
id: candidate.identity,
|
|
58
|
+
identity: candidate.signature ? `signature:${candidate.signature}` : `identity:${candidate.identity}`,
|
|
59
|
+
signature: candidate.signature || null,
|
|
60
|
+
promotionId: candidate.promotionId || null,
|
|
61
|
+
match: candidate.match,
|
|
62
|
+
cue: candidate.cue || '',
|
|
63
|
+
lesson: candidate.lesson,
|
|
64
|
+
source: 'provisional',
|
|
65
|
+
}));
|
|
66
|
+
return Buffer.byteLength(JSON.stringify(transformed), 'utf8');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createProvisionalSource(options = {}) {
|
|
70
|
+
const env = options && options.env ? options.env : process.env;
|
|
71
|
+
const root = options && typeof options.root === 'string' && options.root ? options.root : undefined;
|
|
72
|
+
const boundWorkspaceRoot = options && typeof options.workspaceRoot === 'string' && options.workspaceRoot.trim()
|
|
73
|
+
? options.workspaceRoot.trim()
|
|
74
|
+
: null;
|
|
75
|
+
|
|
76
|
+
return function provisionalSource(workspaceIdentity, budget = {}) {
|
|
77
|
+
try {
|
|
78
|
+
const maxCandidates = Number.isInteger(budget && budget.maxCandidates) && budget.maxCandidates > 0
|
|
79
|
+
? budget.maxCandidates
|
|
80
|
+
: DEFAULT_MAX_CANDIDATES;
|
|
81
|
+
const maxBytes = Number.isInteger(budget && budget.maxBytes) && budget.maxBytes > 0
|
|
82
|
+
? budget.maxBytes
|
|
83
|
+
: DEFAULT_MAX_BYTES;
|
|
84
|
+
const maxTextChars = Number.isInteger(budget && budget.maxTextChars) && budget.maxTextChars > 0
|
|
85
|
+
? budget.maxTextChars
|
|
86
|
+
: DEFAULT_MAX_TEXT_CHARS;
|
|
87
|
+
|
|
88
|
+
const query = {
|
|
89
|
+
env,
|
|
90
|
+
kind: 'provisional-lesson',
|
|
91
|
+
...(root ? { root } : {}),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
if (boundWorkspaceRoot) {
|
|
95
|
+
query.workspaceRoot = boundWorkspaceRoot;
|
|
96
|
+
} else if (typeof workspaceIdentity === 'string' && workspaceIdentity.trim()) {
|
|
97
|
+
query.workspaceKey = workspaceIdentity.trim();
|
|
98
|
+
} else {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const records = localErrors.listRecords(query);
|
|
103
|
+
if (!Array.isArray(records) || !records.length) return [];
|
|
104
|
+
|
|
105
|
+
// localErrors.listRecords returns oldest-first; walk newest-first so recent lessons win within budget.
|
|
106
|
+
const projected = [];
|
|
107
|
+
for (let i = records.length - 1; i >= 0; i -= 1) {
|
|
108
|
+
if (projected.length >= maxCandidates) break;
|
|
109
|
+
const candidate = projectProvisionalRecord(records[i], maxTextChars);
|
|
110
|
+
if (!candidate) continue;
|
|
111
|
+
const next = [...projected, candidate];
|
|
112
|
+
if (Buffer.byteLength(JSON.stringify(next), 'utf8') > maxBytes) continue;
|
|
113
|
+
if (matcherSerializedBytes(next) > maxBytes) continue;
|
|
114
|
+
projected.push(candidate);
|
|
115
|
+
}
|
|
116
|
+
projected.reverse();
|
|
117
|
+
return projected;
|
|
118
|
+
} catch (_) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
createProvisionalSource,
|
|
126
|
+
projectProvisionalRecord,
|
|
127
|
+
};
|