@dzhechkov/harness-core 0.3.148 → 0.3.150
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/.dz-manifest.json +32 -8
- package/README.md +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/recall-domain-boost.d.ts +96 -0
- package/dist/recall-domain-boost.d.ts.map +1 -0
- package/dist/recall-domain-boost.js +152 -0
- package/dist/recall-domain-boost.js.map +1 -0
- package/dist/reqe.d.ts +106 -0
- package/dist/reqe.d.ts.map +1 -0
- package/dist/reqe.js +197 -0
- package/dist/reqe.js.map +1 -0
- package/package.json +4 -4
- package/sbom.json +67 -7
- package/src/index.ts +24 -0
- package/src/recall-domain-boost.ts +172 -0
- package/src/reqe.ts +243 -0
package/src/reqe.ts
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* re-QE debt — the pure half of `dz reqe` (backlog 6b40e667, goal honest-quality).
|
|
3
|
+
*
|
|
4
|
+
* The cross-model-QE guard ("the model that writes code must not self-review") is an ADR-named
|
|
5
|
+
* safety property of the feature-adr pipeline. The usage-adaptive override consciously SUSPENDS it
|
|
6
|
+
* (FR-2.9): at >= threshold usage every remaining stage — including Step-8 QE — switches to Codex,
|
|
7
|
+
* so coder and reviewer become the SAME family. The rule doc said "run an independent re-QE after
|
|
8
|
+
* limits reset" — a human instruction on the weakest detection layer. This module turns it into a
|
|
9
|
+
* DEBT with a lifecycle:
|
|
10
|
+
*
|
|
11
|
+
* emit — the workflow records features/<slug>/.fa-state/reqe-due.json when Step-8 actually ran
|
|
12
|
+
* same-family under the override (not on every switch — a switch before Step 8 that
|
|
13
|
+
* still got cross-family QE creates no debt);
|
|
14
|
+
* list — `dz reqe` scans the debts; `dz usage` surfaces the count so the moment limits free up
|
|
15
|
+
* is the moment the debt is visible;
|
|
16
|
+
* brief — `dz reqe --slug <s>` prints a ready cross-family review brief (the OTHER family than
|
|
17
|
+
* the coder);
|
|
18
|
+
* settle — `dz reqe --slug <s> --done --report <file>` clears the debt FAIL-CLOSED: only against
|
|
19
|
+
* an existing, non-trivial report that names a grade; the settlement is appended to
|
|
20
|
+
* 08_qe_report.md so the artifact trail closes.
|
|
21
|
+
*
|
|
22
|
+
* HONEST SCOPE: nothing here re-runs QE automatically (no background spend — the human decides);
|
|
23
|
+
* the same-family CLAUDE belt fallback (codex unavailable) is out of scope by design — it is
|
|
24
|
+
* already logged loudly at run time and is not a limit-pressure artifact; runs from before this
|
|
25
|
+
* feature carry no marker and are UNDETERMINABLE, not debt-free.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const REQE_SCHEMA = 'reqe-due-1';
|
|
29
|
+
|
|
30
|
+
export const REQE_SCOPE =
|
|
31
|
+
'scope: debt is emitted only when Step-8 QE actually ran on the coder’s own family under the ' +
|
|
32
|
+
'usage override; settling requires a graded cross-family report (fail-closed); nothing re-runs QE ' +
|
|
33
|
+
'automatically.';
|
|
34
|
+
|
|
35
|
+
export type ModelFamily = 'claude' | 'openai';
|
|
36
|
+
|
|
37
|
+
/** Family classification shared with the workflow's acFamOf (codex/gpt/openai markers ⇒ openai).
|
|
38
|
+
* DELIBERATELY binary over the workflow's own CONTROLLED vocabulary (coderUsed ∈ claude | codex |
|
|
39
|
+
* codex-fallback; qeReviewerUsed ∈ claude | codex) — this is never fed arbitrary model ids, so the
|
|
40
|
+
* claude default is the correct reading of "not a codex marker", not a fail-open (Codex QE #11,
|
|
41
|
+
* accepted with this documentation). */
|
|
42
|
+
export function modelFamily(spec: string | null | undefined): ModelFamily {
|
|
43
|
+
return /codex|gpt|openai/i.test(String(spec ?? '')) ? 'openai' : 'claude';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ReqeEmitDecision {
|
|
47
|
+
emit: boolean;
|
|
48
|
+
reason: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Emit iff the QE stage label carries the workflow's ' (usage-switched)' marker AND the reviewer
|
|
52
|
+
* family equals the coder family. Marker-only (cross-family survived the switch) or same-family
|
|
53
|
+
* WITHOUT the marker (the codex-unavailable Claude belt — degraded loudly at run time, not a
|
|
54
|
+
* limit-pressure artifact) both create NO debt. */
|
|
55
|
+
export function shouldEmitReqeDebt(input: {
|
|
56
|
+
coderUsed: string | null | undefined;
|
|
57
|
+
qeReviewerUsed: string | null | undefined;
|
|
58
|
+
qeModelLabel: string | null | undefined;
|
|
59
|
+
}): ReqeEmitDecision {
|
|
60
|
+
const switched = /\(usage-switched\)/.test(String(input.qeModelLabel ?? ''));
|
|
61
|
+
const coderFam = modelFamily(input.coderUsed);
|
|
62
|
+
const qeFam = modelFamily(input.qeReviewerUsed);
|
|
63
|
+
if (switched && coderFam === qeFam) {
|
|
64
|
+
return {
|
|
65
|
+
emit: true,
|
|
66
|
+
reason:
|
|
67
|
+
'usage-switched self-review: Step-8 QE ran on the coder’s own family (' + coderFam +
|
|
68
|
+
') under the limit override — the cross-model guard was suspended (FR-2.9)',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (switched) return { emit: false, reason: 'usage-switched but QE stayed cross-family (' + qeFam + ' vs coder ' + coderFam + ')' };
|
|
72
|
+
if (coderFam === qeFam) return { emit: false, reason: 'same-family without the usage override (belt degrade — logged loudly at run time; out of re-QE-debt scope)' };
|
|
73
|
+
return { emit: false, reason: 'cross-family QE ran' };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface ReqeDebt {
|
|
77
|
+
schema: typeof REQE_SCHEMA;
|
|
78
|
+
slug: string;
|
|
79
|
+
coderFamily: ModelFamily;
|
|
80
|
+
qeFamily: ModelFamily;
|
|
81
|
+
qeGrade: string | null;
|
|
82
|
+
reason: string;
|
|
83
|
+
emittedAt: string | null;
|
|
84
|
+
/** The emitting run's identity (the workflow's qe inputHash). Lets a LATER run on the same slug
|
|
85
|
+
* emit a fresh debt even though an older settlement exists, while the SAME run's resume never
|
|
86
|
+
* re-opens a debt its settlement already covered (Codex QE round-2 #2). Optional: debts from
|
|
87
|
+
* before this field settle normally. */
|
|
88
|
+
runStamp?: string | null;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Build the debt record (the workflow serializes this; emittedAt is stamped by the writer agent's
|
|
92
|
+
* shell `date`, so the sandbox needs no Date). */
|
|
93
|
+
export function buildReqeDebt(input: {
|
|
94
|
+
slug: string;
|
|
95
|
+
coderUsed: string | null | undefined;
|
|
96
|
+
qeReviewerUsed: string | null | undefined;
|
|
97
|
+
qeGrade: string | null | undefined;
|
|
98
|
+
reason: string;
|
|
99
|
+
emittedAt?: string | null;
|
|
100
|
+
}): ReqeDebt {
|
|
101
|
+
return {
|
|
102
|
+
schema: REQE_SCHEMA,
|
|
103
|
+
slug: input.slug,
|
|
104
|
+
coderFamily: modelFamily(input.coderUsed),
|
|
105
|
+
qeFamily: modelFamily(input.qeReviewerUsed),
|
|
106
|
+
qeGrade: input.qeGrade == null || String(input.qeGrade).trim() === '' ? null : String(input.qeGrade).trim(),
|
|
107
|
+
reason: input.reason,
|
|
108
|
+
emittedAt: input.emittedAt ?? null,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Parse + validate a debt file's text. null = not a valid debt (the caller reports it as
|
|
113
|
+
* malformed — a corrupt debt file is NAMED, never silently dropped). */
|
|
114
|
+
export function parseReqeDebt(text: string): ReqeDebt | null {
|
|
115
|
+
let raw: unknown;
|
|
116
|
+
try {
|
|
117
|
+
raw = JSON.parse(String(text ?? ''));
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const d = raw as Partial<ReqeDebt>;
|
|
122
|
+
if (!d || typeof d !== 'object') return null;
|
|
123
|
+
if (d.schema !== REQE_SCHEMA) return null;
|
|
124
|
+
if (typeof d.slug !== 'string' || d.slug.trim() === '') return null;
|
|
125
|
+
if (d.coderFamily !== 'claude' && d.coderFamily !== 'openai') return null;
|
|
126
|
+
if (d.qeFamily !== 'claude' && d.qeFamily !== 'openai') return null;
|
|
127
|
+
if (typeof d.reason !== 'string' || d.reason.trim() === '') return null;
|
|
128
|
+
return {
|
|
129
|
+
schema: REQE_SCHEMA,
|
|
130
|
+
slug: d.slug,
|
|
131
|
+
coderFamily: d.coderFamily,
|
|
132
|
+
qeFamily: d.qeFamily,
|
|
133
|
+
qeGrade: typeof d.qeGrade === 'string' && d.qeGrade.trim() !== '' ? d.qeGrade.trim() : null,
|
|
134
|
+
reason: d.reason,
|
|
135
|
+
emittedAt: typeof d.emittedAt === 'string' && d.emittedAt.trim() !== '' ? d.emittedAt : null,
|
|
136
|
+
runStamp: typeof d.runStamp === 'string' && d.runStamp.trim() !== '' ? d.runStamp : null,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface ReqeBrief {
|
|
141
|
+
reviewFamily: ModelFamily;
|
|
142
|
+
header: string;
|
|
143
|
+
instructions: readonly string[];
|
|
144
|
+
codexCmdTemplate: string | null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The ready-to-run cross-family review brief. Review family = the OTHER family than the CODER
|
|
148
|
+
* (reviewing with the other-than-reviewer family would let a codex-coded, codex-reviewed run be
|
|
149
|
+
* "re-reviewed" by codex again). */
|
|
150
|
+
export function buildReqeBrief(debt: ReqeDebt, artifactsDir: string): ReqeBrief {
|
|
151
|
+
const reviewFamily: ModelFamily = debt.coderFamily === 'openai' ? 'claude' : 'openai';
|
|
152
|
+
const files = [
|
|
153
|
+
artifactsDir + '/07_code_changes/change_manifest.md',
|
|
154
|
+
artifactsDir + '/08_qe_report.md',
|
|
155
|
+
artifactsDir + '/03_adr/',
|
|
156
|
+
];
|
|
157
|
+
const instructions = [
|
|
158
|
+
'Independent re-QE for "' + debt.slug + '": the recorded Step-8 review ran on the coder’s own family (' + debt.coderFamily + ') under the usage override' + (debt.qeGrade ? ' and graded ' + debt.qeGrade : '') + '.',
|
|
159
|
+
'Review with the ' + reviewFamily.toUpperCase() + ' family (the OTHER family than the coder — the suspended guard, restored).',
|
|
160
|
+
'Read: ' + files.join(' , ') + ' plus every file the change manifest lists.',
|
|
161
|
+
'Adversarially verify: correctness, edge cases, the ADR-named load-bearing property HAS a test, and whether the same-family review missed anything.',
|
|
162
|
+
'Output: GRADE A-F + numbered findings with file:line and severity; write the report to ' + artifactsDir + '/08b_reqe_report.md.',
|
|
163
|
+
'Then settle the debt: dz reqe --slug ' + debt.slug + ' --done --report ' + artifactsDir + '/08b_reqe_report.md',
|
|
164
|
+
];
|
|
165
|
+
const codexCmdTemplate = reviewFamily === 'openai'
|
|
166
|
+
? 'codex exec -m <probed-id> -c model_reasoning_effort="high" --sandbox read-only "<the brief above>" < /dev/null # probe the id first: ids are account-specific'
|
|
167
|
+
: null;
|
|
168
|
+
return {
|
|
169
|
+
reviewFamily,
|
|
170
|
+
header: 're-QE brief for ' + debt.slug + ' (' + (debt.emittedAt ?? 'emitted: unknown') + ')',
|
|
171
|
+
instructions,
|
|
172
|
+
codexCmdTemplate,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface ReqeSettlement {
|
|
177
|
+
ok: boolean;
|
|
178
|
+
error: string | null;
|
|
179
|
+
grade: string | null;
|
|
180
|
+
epilogue: string | null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Extract the verdict grade from a report, or null. LINE-ANCHORED and range-proof (Codex QE #7):
|
|
184
|
+
* the boilerplate phrase `GRADE A-F` must not read as grade A, so a letter followed by a dash and
|
|
185
|
+
* another grade letter is rejected; and the grade must head its line (a quoted "do not assign
|
|
186
|
+
* GRADE A" mid-paragraph is not a verdict). Conflicting distinct grades ⇒ null (ambiguous). */
|
|
187
|
+
export function extractReportGrade(text: string): string | null {
|
|
188
|
+
// the lookahead rejects RANGES in punctuation form (A-F, A/F) AND word form (A through F,
|
|
189
|
+
// A to F) — Codex QE round-2 #6: 'GRADE A through F' must not read as grade A
|
|
190
|
+
const matches = [...String(text ?? '').matchAll(/^\s*(?:\*{0,2}#{0,4}\s*)?GRADE\s*[:=—–-]?\s*([A-F])\b(?!\s*(?:[-–—/]|through|to|thru)\s*[A-F]\b)/gim)];
|
|
191
|
+
const distinct = new Set(matches.map((m) => (m[1] ?? '').toUpperCase()).filter((g) => g !== ''));
|
|
192
|
+
if (distinct.size !== 1) return null;
|
|
193
|
+
return [...distinct][0] ?? null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** FAIL-CLOSED settlement validation: the report must be non-trivial (>= 200 chars of substance)
|
|
197
|
+
* and must NAME exactly one line-anchored grade. A settlement that cannot cite its evidence is
|
|
198
|
+
* refused — clearing a debt against an empty file would re-open the exact hole this feature closes.
|
|
199
|
+
* HONEST LIMIT (documented, not hidden): the validator proves the settlement is PROCEDURALLY sound
|
|
200
|
+
* (a distinct, graded report exists); it cannot prove which model authored the text — attribution
|
|
201
|
+
* stays with the human running the brief. */
|
|
202
|
+
export function settleReqeDebt(debt: ReqeDebt, reportText: string, reportPath: string): ReqeSettlement {
|
|
203
|
+
const text = String(reportText ?? '');
|
|
204
|
+
if (text.trim().length < 200) {
|
|
205
|
+
return { ok: false, error: 'report too small to be a review (< 200 chars of substance) — refusing to settle', grade: null, epilogue: null };
|
|
206
|
+
}
|
|
207
|
+
const grade = extractReportGrade(text);
|
|
208
|
+
if (grade === null) {
|
|
209
|
+
return { ok: false, error: 'report names no unambiguous line-anchored GRADE (A-F) — text without exactly one verdict grade is not a verdict; refusing to settle', grade: null, epilogue: null };
|
|
210
|
+
}
|
|
211
|
+
const reviewFamily: ModelFamily = debt.coderFamily === 'openai' ? 'claude' : 'openai';
|
|
212
|
+
const epilogue = [
|
|
213
|
+
'',
|
|
214
|
+
'---',
|
|
215
|
+
'',
|
|
216
|
+
'## re-QE settlement (cross-model debt cleared)',
|
|
217
|
+
'',
|
|
218
|
+
'The original Step-8 review ran on the coder’s own family (' + debt.coderFamily + ') under the',
|
|
219
|
+
'usage override (' + debt.reason + '). An independent ' + reviewFamily.toUpperCase() + '-family re-QE was performed:',
|
|
220
|
+
'',
|
|
221
|
+
'- report: `' + reportPath + '`',
|
|
222
|
+
'- re-QE grade: **' + grade + '**' + (debt.qeGrade ? ' (same-family grade on record: ' + debt.qeGrade + ')' : ''),
|
|
223
|
+
'- settled via `dz reqe --done` (fail-closed: an existing graded report is required).',
|
|
224
|
+
'',
|
|
225
|
+
].join('\n');
|
|
226
|
+
return { ok: true, error: null, grade, epilogue };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** Render the debt list for `dz reqe` / the `dz usage` surfacing line. */
|
|
230
|
+
export function renderReqeList(debts: readonly ReqeDebt[], malformed: number): string[] {
|
|
231
|
+
const lines: string[] = [];
|
|
232
|
+
if (debts.length === 0 && malformed === 0) {
|
|
233
|
+
lines.push('dz reqe: no re-QE debts — every recorded run kept cross-model QE (or none used the usage override).');
|
|
234
|
+
} else {
|
|
235
|
+
lines.push('dz reqe — ' + debts.length + ' unsettled re-QE debt(s):');
|
|
236
|
+
for (const d of debts) {
|
|
237
|
+
lines.push(' ' + d.slug + ' coder=' + d.coderFamily + ' qe=' + d.qeFamily + (d.qeGrade ? ' grade=' + d.qeGrade : '') + (d.emittedAt ? ' ' + d.emittedAt : '') + ' → dz reqe --slug ' + d.slug);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (malformed > 0) lines.push(' ' + malformed + ' malformed debt file(s) skipped (named, never silent).');
|
|
241
|
+
lines.push(REQE_SCOPE);
|
|
242
|
+
return lines;
|
|
243
|
+
}
|