opencode-dev-framework 1.5.1 → 1.6.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 +2 -1
- package/dist/harness.d.ts +37 -8
- package/dist/harness.js +74 -25
- package/dist/index.d.ts +8 -0
- package/dist/index.js +31 -12
- package/dist/logger.d.ts +31 -0
- package/dist/logger.js +105 -14
- package/dist/review.d.ts +14 -0
- package/dist/review.js +88 -0
- package/dist/roster.d.ts +26 -0
- package/dist/roster.js +99 -0
- package/dist/weakening.d.ts +36 -0
- package/dist/weakening.js +116 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,7 +68,8 @@ Requires OpenCode `v2.x` — tested on `v2.0.26` and `v2.2.0`. On
|
|
|
68
68
|
- **Per-edit lint.** Runs your linter on each edited file and reports loudly.
|
|
69
69
|
- **Completion gate.** At the would-go-idle boundary, runs typecheck, tests,
|
|
70
70
|
acceptance checks, and (optionally) lint on changed files — plus a required
|
|
71
|
-
peer-review artifact in `standard`/`strict
|
|
71
|
+
substantive peer-review artifact in `standard`/`strict` (length floors, no
|
|
72
|
+
template checkboxes). Failures steer the session
|
|
72
73
|
back with the failure summary, bounded by `gate.max_blocks` (fewer when
|
|
73
74
|
the failure repeats with no new edits — the gate stands down early on
|
|
74
75
|
zero progress).
|
package/dist/harness.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ import { type ChangedFileTracker, type GateReport } from "./gate.js";
|
|
|
21
21
|
import type { RunCommand } from "./host.js";
|
|
22
22
|
import type { LintLimiter } from "./lint.js";
|
|
23
23
|
import type { LogFn } from "./logger.js";
|
|
24
|
+
import { type ReviewState } from "./review.js";
|
|
24
25
|
import type { ResolvedConfig } from "./types.js";
|
|
26
|
+
import { type EnforceableSnapshot } from "./weakening.js";
|
|
25
27
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
26
28
|
export declare const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
27
29
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
@@ -40,6 +42,13 @@ export type ArtifactState = "missing" | "empty" | "present";
|
|
|
40
42
|
* Never throws — unreadable files count as missing.
|
|
41
43
|
*/
|
|
42
44
|
export declare function artifactState(directory: string, relPath: string): Promise<ArtifactState>;
|
|
45
|
+
/**
|
|
46
|
+
* Grade the peer-review artifact including substance (plan 17 §3).
|
|
47
|
+
* Never throws — unreadable files count as missing. Thin or
|
|
48
|
+
* template content names the duty-escape on the record instead of
|
|
49
|
+
* passing a checkbox note.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readReviewState(directory: string): Promise<ReviewState>;
|
|
43
52
|
/**
|
|
44
53
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
45
54
|
* Handles renames (`R old -> new` — keeps the new path) and dedupes.
|
|
@@ -69,14 +78,14 @@ export type CompletionVerdict = {
|
|
|
69
78
|
note?: string;
|
|
70
79
|
} | {
|
|
71
80
|
decision: "blocked";
|
|
72
|
-
reason: "gate" | "review";
|
|
81
|
+
reason: "gate" | "review" | "weakened";
|
|
73
82
|
summary: string;
|
|
74
83
|
blockCount: number;
|
|
75
84
|
maxBlocks: number;
|
|
76
85
|
changedFiles: string[];
|
|
77
86
|
} | {
|
|
78
87
|
decision: "standdown";
|
|
79
|
-
reason: "gate" | "review";
|
|
88
|
+
reason: "gate" | "review" | "weakened";
|
|
80
89
|
summary: string;
|
|
81
90
|
changedFiles: string[];
|
|
82
91
|
};
|
|
@@ -94,6 +103,13 @@ export interface CompletionDeps {
|
|
|
94
103
|
lintLimiter?: LintLimiter;
|
|
95
104
|
/** Session pass cache; skips redundant gate suites across idle boundaries. */
|
|
96
105
|
passCache?: PassCache;
|
|
106
|
+
/**
|
|
107
|
+
* Session-start enforceable snapshot (plan 17 §2). When present, a
|
|
108
|
+
* mid-session duty reduction blocks in standard/strict (reason
|
|
109
|
+
* `"weakened"`) and warns in advisory. Absent (e.g. manual
|
|
110
|
+
* `/df-verify`), the live contract evaluates as-is.
|
|
111
|
+
*/
|
|
112
|
+
baseline?: EnforceableSnapshot;
|
|
97
113
|
}
|
|
98
114
|
/**
|
|
99
115
|
* Side-effect-free inputs for a completion inspection, with one deliberate
|
|
@@ -123,6 +139,14 @@ export interface InspectionDeps {
|
|
|
123
139
|
* never are, so loud reporting is preserved.
|
|
124
140
|
*/
|
|
125
141
|
passCache?: PassCache;
|
|
142
|
+
/**
|
|
143
|
+
* Session-start enforceable snapshot (plan 17 §2). When present, a
|
|
144
|
+
* mid-session duty reduction fails the inspection (`ok: false`) with
|
|
145
|
+
* the reductions listed in `weakenings` and leading the summary.
|
|
146
|
+
* Absent (e.g. manual `/df-verify`), the live contract evaluates
|
|
147
|
+
* as-is.
|
|
148
|
+
*/
|
|
149
|
+
baseline?: EnforceableSnapshot;
|
|
126
150
|
}
|
|
127
151
|
/**
|
|
128
152
|
* Fingerprint of the last clean pass. `key` is null when nothing is cached;
|
|
@@ -135,24 +159,29 @@ export interface PassCache {
|
|
|
135
159
|
/** Create an empty pass cache (one per session state). */
|
|
136
160
|
export declare function createPassCache(): PassCache;
|
|
137
161
|
/**
|
|
138
|
-
* Raw completion report. `ok` is the unadjudicated outcome (gate passed
|
|
139
|
-
* review satisfied); profiles, block counting,
|
|
140
|
-
* `evaluateCompletion`, and `verifyGate`
|
|
141
|
-
* PASS/FAIL verdict.
|
|
162
|
+
* Raw completion report. `ok` is the unadjudicated outcome (gate passed,
|
|
163
|
+
* review satisfied, and contract unweakened); profiles, block counting,
|
|
164
|
+
* and stand-down are applied by `evaluateCompletion`, and `verifyGate`
|
|
165
|
+
* reports `ok` verbatim as its PASS/FAIL verdict.
|
|
142
166
|
*/
|
|
143
167
|
export interface CompletionInspection {
|
|
144
168
|
changedFiles: string[];
|
|
145
169
|
report: GateReport;
|
|
146
170
|
reviewRequired: boolean;
|
|
147
|
-
|
|
171
|
+
/** Substance-graded review state (plan 17 §3): only `present` satisfies the duty. */
|
|
172
|
+
reviewState: ReviewState;
|
|
148
173
|
reviewMissing: boolean;
|
|
149
174
|
/** True when the gate short-circuited on `skip_unchanged` with no files. */
|
|
150
175
|
skipped: boolean;
|
|
151
|
-
/**
|
|
176
|
+
/** Mid-session duty reductions vs the session-start snapshot (empty when intact). */
|
|
177
|
+
weakenings: string[];
|
|
178
|
+
/** Raw outcome: gate ok AND review satisfied AND contract unweakened. No profile/policy applied. */
|
|
152
179
|
ok: boolean;
|
|
153
180
|
/** Human- and transcript-readable summary (gate detail or review notice). */
|
|
154
181
|
summary: string;
|
|
155
182
|
}
|
|
183
|
+
/** Lead section for a weakened-contract summary; the live gate detail follows. */
|
|
184
|
+
export declare function weakeningSection(weakenings: string[]): string;
|
|
156
185
|
/**
|
|
157
186
|
* Inspect the current completion state without mutating anything except the
|
|
158
187
|
* opted-in session pass-cache write-through: no tracker clearing, no
|
package/dist/harness.js
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
import { readFile, stat } from "node:fs/promises";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { runGate, summarizeGate } from "./gate.js";
|
|
22
|
+
import { assessReviewContent, templateReviewMessage, thinReviewMessage, } from "./review.js";
|
|
23
|
+
import { diffWeakening } from "./weakening.js";
|
|
22
24
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
23
25
|
export const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
24
26
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
@@ -44,6 +46,22 @@ export async function artifactState(directory, relPath) {
|
|
|
44
46
|
return "missing";
|
|
45
47
|
}
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Grade the peer-review artifact including substance (plan 17 §3).
|
|
51
|
+
* Never throws — unreadable files count as missing. Thin or
|
|
52
|
+
* template content names the duty-escape on the record instead of
|
|
53
|
+
* passing a checkbox note.
|
|
54
|
+
*/
|
|
55
|
+
export async function readReviewState(directory) {
|
|
56
|
+
let content;
|
|
57
|
+
try {
|
|
58
|
+
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return "missing";
|
|
62
|
+
}
|
|
63
|
+
return assessReviewContent(content);
|
|
64
|
+
}
|
|
47
65
|
/**
|
|
48
66
|
* Parse `git status --porcelain=v1` output into repo-relative changed paths.
|
|
49
67
|
* Handles renames (`R old -> new` — keeps the new path) and dedupes.
|
|
@@ -179,6 +197,12 @@ async function passCacheKey(config, directory, changedFiles, reviewRequired) {
|
|
|
179
197
|
}
|
|
180
198
|
return `${gateConfig}\n${parts.join("\n")}\nreview:${review}`;
|
|
181
199
|
}
|
|
200
|
+
/** Lead section for a weakened-contract summary; the live gate detail follows. */
|
|
201
|
+
export function weakeningSection(weakenings) {
|
|
202
|
+
const lines = weakenings.map((w) => ` - ${w}`);
|
|
203
|
+
return (`opencode-dev-framework completion contract was weakened mid-session ` +
|
|
204
|
+
`(duties were reduced after the session started):\n${lines.join("\n")}`);
|
|
205
|
+
}
|
|
182
206
|
/**
|
|
183
207
|
* Inspect the current completion state without mutating anything except the
|
|
184
208
|
* opted-in session pass-cache write-through: no tracker clearing, no
|
|
@@ -201,6 +225,7 @@ export async function inspectCompletion(deps) {
|
|
|
201
225
|
reviewState: "present",
|
|
202
226
|
reviewMissing: false,
|
|
203
227
|
skipped: false,
|
|
228
|
+
weakenings: [],
|
|
204
229
|
ok: true,
|
|
205
230
|
summary: "completion gate disabled (profile off or no gate section)",
|
|
206
231
|
};
|
|
@@ -219,6 +244,13 @@ export async function inspectCompletion(deps) {
|
|
|
219
244
|
};
|
|
220
245
|
}
|
|
221
246
|
const reviewRequired = config.gate.require_review && changedFiles.length > 0;
|
|
247
|
+
// Mid-session duty reduction vs the session-start snapshot. Computed
|
|
248
|
+
// before the pass-cache lookup: the fingerprint does not cover the
|
|
249
|
+
// profile, so a weakened contract must never replay a cached pass.
|
|
250
|
+
// Only evaluated when the gate actually runs — a skipped gate (no
|
|
251
|
+
// changed files) has no duties to escape.
|
|
252
|
+
const weakenings = deps.baseline !== undefined ? diffWeakening(deps.baseline, config) : [];
|
|
253
|
+
const weakened = weakenings.length > 0;
|
|
222
254
|
// Fingerprint the tree the gate is about to validate, once. A hit replays
|
|
223
255
|
// the cached pass; a clean run stores this same pre-run key. Storing the
|
|
224
256
|
// pre-run (not post-run) state matters: an edit landing mid-gate-run
|
|
@@ -236,7 +268,8 @@ export async function inspectCompletion(deps) {
|
|
|
236
268
|
if (cachedKey !== undefined &&
|
|
237
269
|
cachedKey !== null &&
|
|
238
270
|
cachedSummary !== undefined &&
|
|
239
|
-
cachedSummary !== null
|
|
271
|
+
cachedSummary !== null &&
|
|
272
|
+
!weakened) {
|
|
240
273
|
if (fingerprint !== null && fingerprint === cachedKey) {
|
|
241
274
|
return {
|
|
242
275
|
changedFiles,
|
|
@@ -245,6 +278,7 @@ export async function inspectCompletion(deps) {
|
|
|
245
278
|
reviewState: "present",
|
|
246
279
|
reviewMissing: false,
|
|
247
280
|
skipped: false,
|
|
281
|
+
weakenings,
|
|
248
282
|
ok: true,
|
|
249
283
|
summary: cachedSummary,
|
|
250
284
|
};
|
|
@@ -255,28 +289,31 @@ export async function inspectCompletion(deps) {
|
|
|
255
289
|
lintLimiter: deps.lintLimiter,
|
|
256
290
|
});
|
|
257
291
|
const gateFailed = report.ran && !report.ok;
|
|
258
|
-
const reviewState = reviewRequired
|
|
259
|
-
? await artifactState(directory, REVIEW_ARTIFACT_REL)
|
|
260
|
-
: "present";
|
|
292
|
+
const reviewState = reviewRequired ? await readReviewState(directory) : "present";
|
|
261
293
|
const reviewMissing = reviewRequired && reviewState !== "present";
|
|
262
|
-
const ok = !gateFailed && !reviewMissing;
|
|
263
|
-
const
|
|
294
|
+
const ok = !gateFailed && !reviewMissing && !weakened;
|
|
295
|
+
const baseSummary = gateFailed
|
|
264
296
|
? summarizeGate(report)
|
|
265
|
-
:
|
|
266
|
-
?
|
|
267
|
-
:
|
|
268
|
-
?
|
|
269
|
-
:
|
|
297
|
+
: reviewState === "thin"
|
|
298
|
+
? thinReviewMessage(changedFiles)
|
|
299
|
+
: reviewState === "template"
|
|
300
|
+
? templateReviewMessage(changedFiles)
|
|
301
|
+
: reviewMissing
|
|
302
|
+
? reviewMissingMessage(changedFiles)
|
|
303
|
+
: report.ran
|
|
304
|
+
? `completion gate passed\n${summarizeGate(report)}`
|
|
305
|
+
: `completion gate passed (${report.reason ?? "nothing to run"})`;
|
|
306
|
+
const summary = weakened ? `${weakeningSection(weakenings)}\n\n${baseSummary}` : baseSummary;
|
|
270
307
|
if (deps.passCache !== undefined) {
|
|
271
|
-
if (!gateFailed && !reviewMissing && report.ran && fingerprint !== null) {
|
|
308
|
+
if (!gateFailed && !reviewMissing && !weakened && report.ran && fingerprint !== null) {
|
|
272
309
|
// Genuinely clean pass that actually ran — store the pre-run
|
|
273
|
-
// fingerprint for the next idle. Advisory problems (gateFailed)
|
|
274
|
-
// missing reviews never store; vacuous
|
|
275
|
-
// store nor clear.
|
|
310
|
+
// fingerprint for the next idle. Advisory problems (gateFailed),
|
|
311
|
+
// missing reviews, and weakened contracts never store; vacuous
|
|
312
|
+
// passes (nothing ran) neither store nor clear.
|
|
276
313
|
deps.passCache.key = fingerprint;
|
|
277
314
|
deps.passCache.summary = summary;
|
|
278
315
|
}
|
|
279
|
-
else if (gateFailed || reviewMissing) {
|
|
316
|
+
else if (gateFailed || reviewMissing || weakened) {
|
|
280
317
|
deps.passCache.key = null;
|
|
281
318
|
deps.passCache.summary = null;
|
|
282
319
|
}
|
|
@@ -287,6 +324,7 @@ export async function inspectCompletion(deps) {
|
|
|
287
324
|
reviewRequired,
|
|
288
325
|
reviewState,
|
|
289
326
|
reviewMissing,
|
|
327
|
+
weakenings,
|
|
290
328
|
skipped: false,
|
|
291
329
|
ok,
|
|
292
330
|
summary,
|
|
@@ -310,11 +348,13 @@ export async function evaluateCompletion(deps) {
|
|
|
310
348
|
trackerFiles: tracker.getChangedFiles(),
|
|
311
349
|
lintLimiter: deps.lintLimiter,
|
|
312
350
|
passCache: deps.passCache,
|
|
351
|
+
baseline: deps.baseline,
|
|
313
352
|
});
|
|
314
353
|
const { changedFiles, report } = inspection;
|
|
315
354
|
const gateFailed = report.ran && !report.ok;
|
|
316
355
|
const reviewMissing = inspection.reviewMissing;
|
|
317
|
-
|
|
356
|
+
const weakened = inspection.weakenings.length > 0;
|
|
357
|
+
if (!gateFailed && !reviewMissing && !weakened) {
|
|
318
358
|
tracker.clearChangedFiles();
|
|
319
359
|
await blockCounts.clear(sessionID);
|
|
320
360
|
await stuckSnapshots.clear(sessionID);
|
|
@@ -326,7 +366,8 @@ export async function evaluateCompletion(deps) {
|
|
|
326
366
|
note: report.ran || inspection.skipped ? inspection.summary : undefined,
|
|
327
367
|
};
|
|
328
368
|
}
|
|
329
|
-
// Advisory: report loudly, never block.
|
|
369
|
+
// Advisory: report loudly, never block. A weakened contract in advisory
|
|
370
|
+
// lands here too — visible in the log and the pass note, never a block.
|
|
330
371
|
if (!config.gate.block_on_failure) {
|
|
331
372
|
const summary = inspection.summary;
|
|
332
373
|
await deps.log("error", `completion gate (advisory — not blocking) saw problems:\n${summary}`);
|
|
@@ -336,7 +377,13 @@ export async function evaluateCompletion(deps) {
|
|
|
336
377
|
note: `completion gate (advisory — not blocking) saw problems:\n${summary}`,
|
|
337
378
|
};
|
|
338
379
|
}
|
|
339
|
-
|
|
380
|
+
// A weakened contract outranks the live gate outcome: the evidence was
|
|
381
|
+
// gathered against moved goalposts, so the verdict names that first.
|
|
382
|
+
const reason = weakened
|
|
383
|
+
? "weakened"
|
|
384
|
+
: gateFailed
|
|
385
|
+
? "gate"
|
|
386
|
+
: "review";
|
|
340
387
|
const summary = inspection.summary;
|
|
341
388
|
const maxBlocks = config.gate.max_blocks ?? 3;
|
|
342
389
|
// No-progress early stand-down (docs/plans/14-stuck-detection.md): consecutive blocked
|
|
@@ -344,12 +391,14 @@ export async function evaluateCompletion(deps) {
|
|
|
344
391
|
// zero information, so stop spending the budget on them. One
|
|
345
392
|
// investigate-then-fix cycle is tolerated (a single repeat still
|
|
346
393
|
// blocks); the third identical evaluation stands down.
|
|
347
|
-
const signature =
|
|
348
|
-
? `
|
|
349
|
-
|
|
350
|
-
.
|
|
351
|
-
|
|
352
|
-
|
|
394
|
+
const signature = weakened
|
|
395
|
+
? `weakened:${[...inspection.weakenings].sort().join("|")}`
|
|
396
|
+
: gateFailed
|
|
397
|
+
? `gate:${report.failedSteps
|
|
398
|
+
.map((s) => s.name)
|
|
399
|
+
.sort()
|
|
400
|
+
.join(",")}`
|
|
401
|
+
: `review:${inspection.reviewState}`;
|
|
353
402
|
const files = [...changedFiles].sort();
|
|
354
403
|
const previous = await stuckSnapshots.get(sessionID);
|
|
355
404
|
const noProgress = previous !== undefined &&
|
package/dist/index.d.ts
CHANGED
|
@@ -28,9 +28,17 @@ import { type RunCommand } from "./host.js";
|
|
|
28
28
|
import { type LintLimiter } from "./lint.js";
|
|
29
29
|
import { type LogFn } from "./logger.js";
|
|
30
30
|
import type { ResolvedConfig } from "./types.js";
|
|
31
|
+
import { type EnforceableSnapshot } from "./weakening.js";
|
|
31
32
|
export interface HookState {
|
|
32
33
|
directory: string;
|
|
33
34
|
config: ResolvedConfig;
|
|
35
|
+
/**
|
|
36
|
+
* Session-start enforceable snapshot (plan 17 §2). Compared against the
|
|
37
|
+
* live config at every gate evaluation so mid-session duty reductions
|
|
38
|
+
* surface in the verdict. Never re-baselined — including across
|
|
39
|
+
* `set_profile` — so a profile downgrade reads as the weakening it is.
|
|
40
|
+
*/
|
|
41
|
+
initialEnforceable: EnforceableSnapshot;
|
|
34
42
|
log: LogFn;
|
|
35
43
|
run: RunCommand;
|
|
36
44
|
tracker: ChangedFileTracker;
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,9 @@ import { createLintLimiter, detectPreCommitAvailability, isLintFailure, lintFile
|
|
|
32
32
|
import { createLogger } from "./logger.js";
|
|
33
33
|
import { checkToolCall, extractFilePath, FILE_TOOLS, toPermissionGuard } from "./protect.js";
|
|
34
34
|
import { constitutionPresent, loadConstitution } from "./rules.js";
|
|
35
|
+
import { findRosterIndex, renderDutyRoster, rosterPresent } from "./roster.js";
|
|
35
36
|
import { writeRuntimeStatus } from "./runtime-status.js";
|
|
37
|
+
import { snapshotEnforceable } from "./weakening.js";
|
|
36
38
|
let activeState = null;
|
|
37
39
|
let fallbackLog = async () => { };
|
|
38
40
|
/**
|
|
@@ -97,7 +99,9 @@ async function reloadConfigIfChanged(state) {
|
|
|
97
99
|
function continuationMessage(verdict) {
|
|
98
100
|
const why = verdict.reason === "review"
|
|
99
101
|
? "the peer-review requirement is unmet"
|
|
100
|
-
:
|
|
102
|
+
: verdict.reason === "weakened"
|
|
103
|
+
? "the completion contract was weakened mid-session"
|
|
104
|
+
: "the repo's checks are failing";
|
|
101
105
|
return (`opencode-dev-framework completion gate blocked you from finishing because ${why} ` +
|
|
102
106
|
`(block ${verdict.blockCount}/${verdict.maxBlocks}).\n\n${verdict.summary}\n\n` +
|
|
103
107
|
`Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to ` +
|
|
@@ -165,6 +169,7 @@ function runCompletion(state, sessionID) {
|
|
|
165
169
|
stuckSnapshots: state.stuckSnapshots,
|
|
166
170
|
lintLimiter: state.lintLimiter,
|
|
167
171
|
passCache: state.passCache,
|
|
172
|
+
baseline: state.initialEnforceable,
|
|
168
173
|
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
169
174
|
});
|
|
170
175
|
}
|
|
@@ -279,6 +284,7 @@ const plugin = Plugin.define({
|
|
|
279
284
|
const state = {
|
|
280
285
|
directory,
|
|
281
286
|
config,
|
|
287
|
+
initialEnforceable: snapshotEnforceable(config),
|
|
282
288
|
log,
|
|
283
289
|
run: runCommand,
|
|
284
290
|
tracker,
|
|
@@ -325,17 +331,30 @@ const plugin = Plugin.define({
|
|
|
325
331
|
if (state.config.profile === "off")
|
|
326
332
|
return;
|
|
327
333
|
const constitution = state.constitution;
|
|
328
|
-
if (
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
334
|
+
if (constitution) {
|
|
335
|
+
// V2 system is Array<SystemPart> {type:"text", text:string}
|
|
336
|
+
const already = constitutionPresent(event.system, constitution);
|
|
337
|
+
if (!already) {
|
|
338
|
+
event.system.push({
|
|
339
|
+
type: "text",
|
|
340
|
+
text: constitution,
|
|
341
|
+
});
|
|
342
|
+
await safeLog(state, "info", "constitution injected into system prompt");
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const roster = renderDutyRoster(state.config);
|
|
346
|
+
if (roster) {
|
|
347
|
+
if (!rosterPresent(event.system, roster)) {
|
|
348
|
+
const at = findRosterIndex(event.system);
|
|
349
|
+
if (at >= 0) {
|
|
350
|
+
event.system[at].text = roster;
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
event.system.push({ type: "text", text: roster });
|
|
354
|
+
}
|
|
355
|
+
await safeLog(state, "debug", "duty roster injected into system prompt");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
339
358
|
}));
|
|
340
359
|
// Also hook other request kinds so the reminder is not missed on title/generate
|
|
341
360
|
// (no-op if model doesn't need it; cheap)
|
package/dist/logger.d.ts
CHANGED
|
@@ -3,6 +3,15 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
5
5
|
export declare const LOG_SERVICE = "opencode-dev-framework";
|
|
6
|
+
/** Leaf directory/file for the default user-level log. */
|
|
7
|
+
export declare const LOG_DIR_NAME = "opencode-dev-framework";
|
|
8
|
+
export declare const LOG_FILE_NAME = "opencode-dev-framework.log";
|
|
9
|
+
/**
|
|
10
|
+
* Rotation cap: the active log never grows past this; one backup
|
|
11
|
+
* (`*.1`) is kept, so worst case is 2× cap. 5MB holds thousands of
|
|
12
|
+
* evaluations (lines are a few hundred bytes, summaries a few KB).
|
|
13
|
+
*/
|
|
14
|
+
export declare const MAX_LOG_BYTES: number;
|
|
6
15
|
export type LogFn = (level: LogLevel, message: string, extra?: Record<string, unknown>) => Promise<void>;
|
|
7
16
|
type V1Client = {
|
|
8
17
|
app?: {
|
|
@@ -16,6 +25,28 @@ type V1Client = {
|
|
|
16
25
|
}) => Promise<unknown>;
|
|
17
26
|
};
|
|
18
27
|
};
|
|
28
|
+
export interface LogPathInput {
|
|
29
|
+
platform?: string;
|
|
30
|
+
env?: Record<string, string | undefined>;
|
|
31
|
+
home?: string | null;
|
|
32
|
+
tmp?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resolve the user-level default log file. Pure given explicit
|
|
36
|
+
* inputs (production passes the real ones). `null` only when no
|
|
37
|
+
* home directory is known AND tmp is unavailable — vanishingly
|
|
38
|
+
* rare; callers treat null as file-logging-off (stderr remains).
|
|
39
|
+
* Never inside the repo: a repo-local log would surface as an
|
|
40
|
+
* untracked changed file and poison the tracker.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveDefaultLogFile(input?: LogPathInput): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* Rotate the active log past the cap: the previous backup is
|
|
45
|
+
* dropped, the active file becomes the backup, and appends start
|
|
46
|
+
* fresh. Concurrent writers can interleave stat/rename and lose a
|
|
47
|
+
* line — acceptable for a best-effort log, never for enforcement.
|
|
48
|
+
*/
|
|
49
|
+
export declare function rotateLogFile(filePath: string, maxBytes: number): Promise<void>;
|
|
19
50
|
/**
|
|
20
51
|
* Create a logger. If a V1 client is provided, forwards to `client.app.log`
|
|
21
52
|
* (as tests expect). Otherwise logs to stderr/file (V2 runtime).
|
package/dist/logger.js
CHANGED
|
@@ -1,14 +1,115 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Structured logging wrapper. Supports both V1 (client.app.log) and V2 (stderr/file).
|
|
3
3
|
*/
|
|
4
|
-
import { appendFile } from "node:fs/promises";
|
|
4
|
+
import { appendFile, mkdir, rename, rm, stat } from "node:fs/promises";
|
|
5
|
+
import { homedir, tmpdir } from "node:os";
|
|
6
|
+
import { dirname, isAbsolute, join } from "node:path";
|
|
5
7
|
export const LOG_SERVICE = "opencode-dev-framework";
|
|
8
|
+
/** Leaf directory/file for the default user-level log. */
|
|
9
|
+
export const LOG_DIR_NAME = "opencode-dev-framework";
|
|
10
|
+
export const LOG_FILE_NAME = "opencode-dev-framework.log";
|
|
11
|
+
/**
|
|
12
|
+
* Rotation cap: the active log never grows past this; one backup
|
|
13
|
+
* (`*.1`) is kept, so worst case is 2× cap. 5MB holds thousands of
|
|
14
|
+
* evaluations (lines are a few hundred bytes, summaries a few KB).
|
|
15
|
+
*/
|
|
16
|
+
export const MAX_LOG_BYTES = 5 * 1024 * 1024;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the user-level default log file. Pure given explicit
|
|
19
|
+
* inputs (production passes the real ones). `null` only when no
|
|
20
|
+
* home directory is known AND tmp is unavailable — vanishingly
|
|
21
|
+
* rare; callers treat null as file-logging-off (stderr remains).
|
|
22
|
+
* Never inside the repo: a repo-local log would surface as an
|
|
23
|
+
* untracked changed file and poison the tracker.
|
|
24
|
+
*/
|
|
25
|
+
export function resolveDefaultLogFile(input = {}) {
|
|
26
|
+
const platform = input.platform ?? process.platform;
|
|
27
|
+
const env = input.env ?? process.env;
|
|
28
|
+
const home = input.home !== undefined ? input.home : safeHomedir();
|
|
29
|
+
if (platform === "win32") {
|
|
30
|
+
if (env.LOCALAPPDATA) {
|
|
31
|
+
return join(env.LOCALAPPDATA, LOG_DIR_NAME, LOG_FILE_NAME);
|
|
32
|
+
}
|
|
33
|
+
// No LOCALAPPDATA: fall through to tmp, not a Unix-style home path.
|
|
34
|
+
const winTmp = input.tmp ?? safeTmpdir();
|
|
35
|
+
return winTmp ? join(winTmp, LOG_DIR_NAME, LOG_FILE_NAME) : null;
|
|
36
|
+
}
|
|
37
|
+
if (platform === "darwin" && home) {
|
|
38
|
+
return join(home, "Library", "Logs", LOG_FILE_NAME);
|
|
39
|
+
}
|
|
40
|
+
if (home) {
|
|
41
|
+
// Empty counts as unset and relative as invalid (XDG basedir spec);
|
|
42
|
+
// either would otherwise land the log relative to CWD — possibly
|
|
43
|
+
// inside the repo, where it would poison the change tracker.
|
|
44
|
+
const xdg = env.XDG_DATA_HOME;
|
|
45
|
+
const base = xdg && isAbsolute(xdg) ? xdg : join(home, ".local", "share");
|
|
46
|
+
return join(base, LOG_DIR_NAME, LOG_FILE_NAME);
|
|
47
|
+
}
|
|
48
|
+
const tmp = input.tmp ?? safeTmpdir();
|
|
49
|
+
return tmp ? join(tmp, LOG_DIR_NAME, LOG_FILE_NAME) : null;
|
|
50
|
+
}
|
|
51
|
+
function safeHomedir() {
|
|
52
|
+
try {
|
|
53
|
+
return homedir();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function safeTmpdir() {
|
|
60
|
+
try {
|
|
61
|
+
return tmpdir();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** Best-effort file write: creates the parent dir, rotates past the cap, never throws. */
|
|
68
|
+
async function appendLogFile(filePath, line, maxBytes = MAX_LOG_BYTES) {
|
|
69
|
+
try {
|
|
70
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
71
|
+
await rotateLogFile(filePath, maxBytes);
|
|
72
|
+
await appendFile(filePath, `${line}\n`);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// best-effort
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Rotate the active log past the cap: the previous backup is
|
|
80
|
+
* dropped, the active file becomes the backup, and appends start
|
|
81
|
+
* fresh. Concurrent writers can interleave stat/rename and lose a
|
|
82
|
+
* line — acceptable for a best-effort log, never for enforcement.
|
|
83
|
+
*/
|
|
84
|
+
export async function rotateLogFile(filePath, maxBytes) {
|
|
85
|
+
let size = 0;
|
|
86
|
+
try {
|
|
87
|
+
size = (await stat(filePath)).size;
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return; // missing — nothing to rotate
|
|
91
|
+
}
|
|
92
|
+
if (size <= maxBytes)
|
|
93
|
+
return;
|
|
94
|
+
try {
|
|
95
|
+
await rm(`${filePath}.1`, { force: true });
|
|
96
|
+
await rename(filePath, `${filePath}.1`);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// best-effort
|
|
100
|
+
}
|
|
101
|
+
}
|
|
6
102
|
/**
|
|
7
103
|
* Create a logger. If a V1 client is provided, forwards to `client.app.log`
|
|
8
104
|
* (as tests expect). Otherwise logs to stderr/file (V2 runtime).
|
|
9
105
|
*/
|
|
10
106
|
export function createLogger(client) {
|
|
11
|
-
|
|
107
|
+
// Explicit override wins (empty string disables file logging:
|
|
108
|
+
// the falsy filePath below skips all writes); otherwise a
|
|
109
|
+
// user-level default so the "loud" record exists without
|
|
110
|
+
// configuration. Resolved once: the path cannot change under
|
|
111
|
+
// a running server.
|
|
112
|
+
const filePath = process.env.OPENCODE_DEV_FRAMEWORK_LOG_FILE ?? resolveDefaultLogFile() ?? undefined;
|
|
12
113
|
return async (level, message, extra) => {
|
|
13
114
|
const line = JSON.stringify({
|
|
14
115
|
timestamp: new Date().toISOString(),
|
|
@@ -33,12 +134,7 @@ export function createLogger(client) {
|
|
|
33
134
|
}
|
|
34
135
|
}
|
|
35
136
|
if (filePath) {
|
|
36
|
-
|
|
37
|
-
await appendFile(filePath, `${line}\n`);
|
|
38
|
-
}
|
|
39
|
-
catch {
|
|
40
|
-
// best-effort
|
|
41
|
-
}
|
|
137
|
+
await appendLogFile(filePath, line);
|
|
42
138
|
}
|
|
43
139
|
return;
|
|
44
140
|
}
|
|
@@ -52,12 +148,7 @@ export function createLogger(client) {
|
|
|
52
148
|
// ignore
|
|
53
149
|
}
|
|
54
150
|
if (filePath) {
|
|
55
|
-
|
|
56
|
-
await appendFile(filePath, `${line}\n`);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// best-effort
|
|
60
|
-
}
|
|
151
|
+
await appendLogFile(filePath, line);
|
|
61
152
|
}
|
|
62
153
|
};
|
|
63
154
|
}
|
package/dist/review.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Trimmed-character floor for a substantive review. */
|
|
2
|
+
export declare const REVIEW_MIN_CHARS = 200;
|
|
3
|
+
/** Whitespace-separated-token floor for a substantive review. */
|
|
4
|
+
export declare const REVIEW_MIN_WORDS = 30;
|
|
5
|
+
/** Review artifact state with substance gradations. */
|
|
6
|
+
export type ReviewState = "missing" | "empty" | "thin" | "template" | "present";
|
|
7
|
+
/**
|
|
8
|
+
* Assess already-read review content. Pure. Order matters: empty,
|
|
9
|
+
* then template markers (a short file with TODOs reports the more
|
|
10
|
+
* actionable reason), then length floors.
|
|
11
|
+
*/
|
|
12
|
+
export declare function assessReviewContent(content: string): Exclude<ReviewState, "missing">;
|
|
13
|
+
export declare function thinReviewMessage(changedFiles: string[]): string;
|
|
14
|
+
export declare function templateReviewMessage(changedFiles: string[]): string;
|
package/dist/review.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review substance (plan 17 §3).
|
|
3
|
+
*
|
|
4
|
+
* `artifactState()` accepts any non-empty file, so a five-word
|
|
5
|
+
* "looks good" checkboxes the `require_review` duty without doing
|
|
6
|
+
* it. These are the framework's contract for what counts as a
|
|
7
|
+
* review: long enough to hold scope, findings, and resolutions,
|
|
8
|
+
* with no leftover template scaffolding.
|
|
9
|
+
*
|
|
10
|
+
* Thresholds stay constants in code with tests, not user config —
|
|
11
|
+
* "what counts as a review" is a framework contract, not a
|
|
12
|
+
* per-project preference. Deliberate padding (`ok ok ok …` to the
|
|
13
|
+
* floor) is out of scope: nothing here stops deliberate sabotage,
|
|
14
|
+
* it only puts checkboxing on the record for honest-but-eager
|
|
15
|
+
* agents.
|
|
16
|
+
*
|
|
17
|
+
* The artifact path literal mirrors `REVIEW_ARTIFACT_REL` in
|
|
18
|
+
* `harness.ts` (kept inline to avoid a module cycle; both are
|
|
19
|
+
* pinned by tests).
|
|
20
|
+
*/
|
|
21
|
+
const REVIEW_REL = ".opencode/opencode-dev-framework/review.md";
|
|
22
|
+
/** Trimmed-character floor for a substantive review. */
|
|
23
|
+
export const REVIEW_MIN_CHARS = 200;
|
|
24
|
+
/** Whitespace-separated-token floor for a substantive review. */
|
|
25
|
+
export const REVIEW_MIN_WORDS = 30;
|
|
26
|
+
/**
|
|
27
|
+
* Universal placeholder markers — editing conventions, not
|
|
28
|
+
* per-project vocabulary, so a single hardcoded list is safe.
|
|
29
|
+
* Short tokens use word boundaries so ordinary prose never trips
|
|
30
|
+
* them; all matched case-insensitively against the raw content.
|
|
31
|
+
*/
|
|
32
|
+
const TEMPLATE_PATTERNS = [
|
|
33
|
+
/\btodo\b/i,
|
|
34
|
+
/\btbd\b/i,
|
|
35
|
+
/\bfixme\b/i,
|
|
36
|
+
/\bxxx\b/i,
|
|
37
|
+
/lorem ipsum/i,
|
|
38
|
+
/placeholder/i,
|
|
39
|
+
/\[insert/i,
|
|
40
|
+
/to be (filled|completed|determined)/i,
|
|
41
|
+
/\bfill in\b/i,
|
|
42
|
+
/unfilled/i,
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Assess already-read review content. Pure. Order matters: empty,
|
|
46
|
+
* then template markers (a short file with TODOs reports the more
|
|
47
|
+
* actionable reason), then length floors.
|
|
48
|
+
*/
|
|
49
|
+
export function assessReviewContent(content) {
|
|
50
|
+
if (content.trim() === "")
|
|
51
|
+
return "empty";
|
|
52
|
+
if (TEMPLATE_PATTERNS.some((pattern) => pattern.test(content)))
|
|
53
|
+
return "template";
|
|
54
|
+
// Unfilled checklist scaffolding with nothing checked off.
|
|
55
|
+
if (/\[ \]/.test(content) && !/\[[xX]\]/.test(content))
|
|
56
|
+
return "template";
|
|
57
|
+
const words = content.trim().split(/\s+/).length;
|
|
58
|
+
if (content.trim().length < REVIEW_MIN_CHARS || words < REVIEW_MIN_WORDS)
|
|
59
|
+
return "thin";
|
|
60
|
+
return "present";
|
|
61
|
+
}
|
|
62
|
+
/** Guidance appended to thin/template summaries: what to write. */
|
|
63
|
+
function reviewCadenceReminder() {
|
|
64
|
+
return (`Before declaring done you must run the project's peer-review cadence: ` +
|
|
65
|
+
`style-enforcer on the changed files, then test-grounder (evidence: tests that ` +
|
|
66
|
+
`fail without the change, commands that actually pass), and code-reviewer / pattern-guardian ` +
|
|
67
|
+
`for correctness and drift. Resolve every blocking finding, then write a summary of the ` +
|
|
68
|
+
`review findings and their resolution to ${REVIEW_REL}.\n\n` +
|
|
69
|
+
`Investigation-only reviewers: do not ask them to edit product code.`);
|
|
70
|
+
}
|
|
71
|
+
export function thinReviewMessage(changedFiles) {
|
|
72
|
+
const files = changedFiles.map((f) => ` - ${f}`).join("\n");
|
|
73
|
+
return (`opencode-dev-framework completion gate — the peer-review artifact exists but has no ` +
|
|
74
|
+
`substance (under ${REVIEW_MIN_CHARS} characters / ${REVIEW_MIN_WORDS} words). ` +
|
|
75
|
+
`A checkbox note is not a review. This session changed files:\n${files}\n\n` +
|
|
76
|
+
`Rewrite ${REVIEW_REL} fresh for THIS session's changes — scope, findings, ` +
|
|
77
|
+
`and resolutions, in your own words.\n\n` +
|
|
78
|
+
reviewCadenceReminder());
|
|
79
|
+
}
|
|
80
|
+
export function templateReviewMessage(changedFiles) {
|
|
81
|
+
const files = changedFiles.map((f) => ` - ${f}`).join("\n");
|
|
82
|
+
return (`opencode-dev-framework completion gate — the peer-review artifact still contains ` +
|
|
83
|
+
`template placeholders or an unfilled checklist. Finish the review before declaring ` +
|
|
84
|
+
`done. This session changed files:\n${files}\n\n` +
|
|
85
|
+
`Rewrite ${REVIEW_REL} fresh for THIS session's changes — scope, findings, ` +
|
|
86
|
+
`and resolutions, with every placeholder replaced by real findings.\n\n` +
|
|
87
|
+
reviewCadenceReminder());
|
|
88
|
+
}
|
package/dist/roster.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ResolvedConfig } from "./types.js";
|
|
2
|
+
/** Stable header prefix identifying roster parts in the system prompt. */
|
|
3
|
+
export declare const ROSTER_MARKER = "## Session duties (opencode-dev-framework";
|
|
4
|
+
/** Max acceptance checks listed verbatim before collapsing to `+ N more`. */
|
|
5
|
+
export declare const MAX_ROSTER_ACCEPTANCE = 5;
|
|
6
|
+
/** Max command characters shown verbatim before truncation. */
|
|
7
|
+
export declare const MAX_ROSTER_COMMAND_LENGTH = 120;
|
|
8
|
+
/**
|
|
9
|
+
* Render the per-project duty roster for session-start legibility.
|
|
10
|
+
*
|
|
11
|
+
* Pure projection of `ResolvedConfig` to a short markdown checklist:
|
|
12
|
+
* which gate steps will run at idle, over what scope, whether the
|
|
13
|
+
* review artifact is required, and the block budget. Returns null
|
|
14
|
+
* only for `off` (no duties enforced). When nothing is configured
|
|
15
|
+
* the roster says so explicitly — "nothing will stop you" is itself
|
|
16
|
+
* legibility.
|
|
17
|
+
*/
|
|
18
|
+
export declare function renderDutyRoster(config: ResolvedConfig): string | null;
|
|
19
|
+
/** True when the exact roster text is already present in the system parts. */
|
|
20
|
+
export declare function rosterPresent(parts: ReadonlyArray<{
|
|
21
|
+
text: string;
|
|
22
|
+
} | string>, roster: string): boolean;
|
|
23
|
+
/** Index of an existing roster part (by stable marker), or -1 when absent. */
|
|
24
|
+
export declare function findRosterIndex(parts: ReadonlyArray<{
|
|
25
|
+
text: string;
|
|
26
|
+
} | string>): number;
|
package/dist/roster.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { normalizeCommandMap } from "./command-utils.js";
|
|
2
|
+
import { REVIEW_ARTIFACT_REL } from "./harness.js";
|
|
3
|
+
/** Stable header prefix identifying roster parts in the system prompt. */
|
|
4
|
+
export const ROSTER_MARKER = "## Session duties (opencode-dev-framework";
|
|
5
|
+
/** Max acceptance checks listed verbatim before collapsing to `+ N more`. */
|
|
6
|
+
export const MAX_ROSTER_ACCEPTANCE = 5;
|
|
7
|
+
/** Max command characters shown verbatim before truncation. */
|
|
8
|
+
export const MAX_ROSTER_COMMAND_LENGTH = 120;
|
|
9
|
+
function truncateCommand(command) {
|
|
10
|
+
if (command.length <= MAX_ROSTER_COMMAND_LENGTH)
|
|
11
|
+
return command;
|
|
12
|
+
return `${command.slice(0, MAX_ROSTER_COMMAND_LENGTH - 1)}…`;
|
|
13
|
+
}
|
|
14
|
+
function describeLint(config) {
|
|
15
|
+
const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
|
|
16
|
+
const exts = Object.keys(byExtension);
|
|
17
|
+
if (defaultLint !== undefined && exts.length === 0) {
|
|
18
|
+
return `\`${truncateCommand(defaultLint)}\``;
|
|
19
|
+
}
|
|
20
|
+
if (defaultLint !== undefined && exts.length > 0) {
|
|
21
|
+
return `\`${truncateCommand(defaultLint)}\` + per-extension (${exts.sort().join(", ")})`;
|
|
22
|
+
}
|
|
23
|
+
if (exts.length > 0) {
|
|
24
|
+
return `per-extension (${exts.sort().join(", ")})`;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Render the per-project duty roster for session-start legibility.
|
|
30
|
+
*
|
|
31
|
+
* Pure projection of `ResolvedConfig` to a short markdown checklist:
|
|
32
|
+
* which gate steps will run at idle, over what scope, whether the
|
|
33
|
+
* review artifact is required, and the block budget. Returns null
|
|
34
|
+
* only for `off` (no duties enforced). When nothing is configured
|
|
35
|
+
* the roster says so explicitly — "nothing will stop you" is itself
|
|
36
|
+
* legibility.
|
|
37
|
+
*/
|
|
38
|
+
export function renderDutyRoster(config) {
|
|
39
|
+
if (config.profile === "off")
|
|
40
|
+
return null;
|
|
41
|
+
const blockingNote = config.profile === "advisory" ? " (advisory — failures warn, never block)" : "";
|
|
42
|
+
const lines = [`${ROSTER_MARKER}, profile ${config.profile})${blockingNote}`];
|
|
43
|
+
lines.push("Before you finish, this will run:");
|
|
44
|
+
const steps = [];
|
|
45
|
+
if (config.gate.run_typecheck && config.commands.typecheck !== undefined) {
|
|
46
|
+
steps.push(`- [ ] typecheck: \`${truncateCommand(config.commands.typecheck)}\``);
|
|
47
|
+
}
|
|
48
|
+
if (config.gate.run_tests) {
|
|
49
|
+
const template = config.gate.scope === "changed" ? config.commands.test_changed : config.commands.test;
|
|
50
|
+
if (template !== undefined) {
|
|
51
|
+
steps.push(`- [ ] test (${config.gate.scope}): \`${truncateCommand(template)}\``);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (config.gate.lint_changed) {
|
|
55
|
+
const lint = describeLint(config);
|
|
56
|
+
if (lint !== null) {
|
|
57
|
+
steps.push(`- [ ] lint changed files: ${lint}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const acceptance = config.gate.acceptance;
|
|
61
|
+
for (const check of acceptance.slice(0, MAX_ROSTER_ACCEPTANCE)) {
|
|
62
|
+
steps.push(`- [ ] acceptance:${check.name}: \`${truncateCommand(check.command)}\``);
|
|
63
|
+
}
|
|
64
|
+
if (acceptance.length > MAX_ROSTER_ACCEPTANCE) {
|
|
65
|
+
steps.push(`- [ ] + ${acceptance.length - MAX_ROSTER_ACCEPTANCE} more acceptance checks`);
|
|
66
|
+
}
|
|
67
|
+
if (config.gate.require_review) {
|
|
68
|
+
steps.push(`- [ ] review: write ${REVIEW_ARTIFACT_REL}`);
|
|
69
|
+
}
|
|
70
|
+
if (config.preflight.length > 0) {
|
|
71
|
+
const taskWord = config.preflight.length === 1 ? "task" : "tasks";
|
|
72
|
+
steps.push(`- [ ] preflight: complete ${config.preflight.length} ${taskWord} -> preflight.md before editing`);
|
|
73
|
+
}
|
|
74
|
+
if (steps.length === 0) {
|
|
75
|
+
lines.push("No checks configured — gate will skip.");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
lines.push(...steps);
|
|
79
|
+
}
|
|
80
|
+
const skipNote = config.gate.skip_unchanged
|
|
81
|
+
? "Skips only when no files changed."
|
|
82
|
+
: "Runs even with no changed files.";
|
|
83
|
+
lines.push(`Budget: ${config.gate.max_blocks} blocks. ${skipNote}`);
|
|
84
|
+
return lines.join("\n");
|
|
85
|
+
}
|
|
86
|
+
/** True when the exact roster text is already present in the system parts. */
|
|
87
|
+
export function rosterPresent(parts, roster) {
|
|
88
|
+
return parts.some((part) => {
|
|
89
|
+
const text = typeof part === "string" ? part : part.text;
|
|
90
|
+
return text.includes(roster);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/** Index of an existing roster part (by stable marker), or -1 when absent. */
|
|
94
|
+
export function findRosterIndex(parts) {
|
|
95
|
+
return parts.findIndex((part) => {
|
|
96
|
+
const text = typeof part === "string" ? part : part.text;
|
|
97
|
+
return text.includes(ROSTER_MARKER);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Profile, ResolvedConfig } from "./types.js";
|
|
2
|
+
/** Enforceable subset of the resolved config, snapshotted at session start. */
|
|
3
|
+
export interface EnforceableSnapshot {
|
|
4
|
+
profile: Profile;
|
|
5
|
+
runTypecheck: boolean;
|
|
6
|
+
runTests: boolean;
|
|
7
|
+
lintChanged: boolean;
|
|
8
|
+
requireReview: boolean;
|
|
9
|
+
blockOnFailure: boolean;
|
|
10
|
+
scope: "all" | "changed";
|
|
11
|
+
maxBlocks: number;
|
|
12
|
+
hasTypecheck: boolean;
|
|
13
|
+
hasTest: boolean;
|
|
14
|
+
hasTestChanged: boolean;
|
|
15
|
+
hasLint: boolean;
|
|
16
|
+
/** Acceptance check name → command. */
|
|
17
|
+
acceptance: Record<string, string>;
|
|
18
|
+
preflightCount: number;
|
|
19
|
+
}
|
|
20
|
+
/** Project the enforceable subset out of a resolved config. Pure. */
|
|
21
|
+
export declare function snapshotEnforceable(config: ResolvedConfig): EnforceableSnapshot;
|
|
22
|
+
/**
|
|
23
|
+
* Diff a session-start snapshot against the live config, returning one
|
|
24
|
+
* human-readable line per duty reduction. Empty means the contract is
|
|
25
|
+
* intact (or was only strengthened). Pure.
|
|
26
|
+
*
|
|
27
|
+
* Deliberate limitations:
|
|
28
|
+
* - Command *modifications* are not flagged — only removals. A changed
|
|
29
|
+
* command string cannot be judged statically.
|
|
30
|
+
* - Acceptance command edits for a retained name are not flagged, for
|
|
31
|
+
* the same reason; only removed names are.
|
|
32
|
+
* - A weakened profile reports as a single profile line; field-level
|
|
33
|
+
* cascades (e.g. `block_on_failure` flipping with the profile
|
|
34
|
+
* default) are suppressed as noise.
|
|
35
|
+
*/
|
|
36
|
+
export declare function diffWeakening(before: EnforceableSnapshot, after: ResolvedConfig): string[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { normalizeCommandMap } from "./command-utils.js";
|
|
2
|
+
/**
|
|
3
|
+
* Config-weakening detection (plan 17 §2).
|
|
4
|
+
*
|
|
5
|
+
* The duties document (`.opencode-dev-framework.yml`) is freely rewritable
|
|
6
|
+
* mid-session and reloads on mtime — deleting checks, dropping
|
|
7
|
+
* `require_review`, or lowering `max_blocks` silently moves the goalposts.
|
|
8
|
+
* Rewriting the duties to make them pass is the canonical duty-escape, so
|
|
9
|
+
* the session-start contract is snapshotted and any mid-session reduction
|
|
10
|
+
* is surfaced in the gate summary. Detection, not prevention: edits stay
|
|
11
|
+
* allowed (agent-driven flows like `df init` must keep working); the gate
|
|
12
|
+
* just refuses to pass a weakened contract silently.
|
|
13
|
+
*
|
|
14
|
+
* Only monotonic weakenings are flagged (removed checks, disabled flags,
|
|
15
|
+
* lowered budgets). Command *modifications* (`npm test` → `vitest run`)
|
|
16
|
+
* are ambiguous — possibly a legitimate toolchain fix — and are left
|
|
17
|
+
* unflagged by design; see the limitation note on `diffWeakening`.
|
|
18
|
+
*/
|
|
19
|
+
const PROFILE_STRICTNESS = {
|
|
20
|
+
off: 0,
|
|
21
|
+
advisory: 1,
|
|
22
|
+
standard: 2,
|
|
23
|
+
strict: 3,
|
|
24
|
+
};
|
|
25
|
+
/** Project the enforceable subset out of a resolved config. Pure. */
|
|
26
|
+
export function snapshotEnforceable(config) {
|
|
27
|
+
const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
|
|
28
|
+
return {
|
|
29
|
+
profile: config.profile,
|
|
30
|
+
runTypecheck: config.gate.run_typecheck,
|
|
31
|
+
runTests: config.gate.run_tests,
|
|
32
|
+
lintChanged: config.gate.lint_changed,
|
|
33
|
+
requireReview: config.gate.require_review,
|
|
34
|
+
blockOnFailure: config.gate.block_on_failure,
|
|
35
|
+
scope: config.gate.scope,
|
|
36
|
+
maxBlocks: config.gate.max_blocks,
|
|
37
|
+
hasTypecheck: config.commands.typecheck !== undefined,
|
|
38
|
+
hasTest: config.commands.test !== undefined,
|
|
39
|
+
hasTestChanged: config.commands.test_changed !== undefined,
|
|
40
|
+
hasLint: defaultLint !== undefined || Object.keys(byExtension).length > 0,
|
|
41
|
+
acceptance: Object.fromEntries(config.gate.acceptance.map((c) => [c.name, c.command])),
|
|
42
|
+
preflightCount: config.preflight.length,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function hasLintNow(config) {
|
|
46
|
+
const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
|
|
47
|
+
return defaultLint !== undefined || Object.keys(byExtension).length > 0;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Diff a session-start snapshot against the live config, returning one
|
|
51
|
+
* human-readable line per duty reduction. Empty means the contract is
|
|
52
|
+
* intact (or was only strengthened). Pure.
|
|
53
|
+
*
|
|
54
|
+
* Deliberate limitations:
|
|
55
|
+
* - Command *modifications* are not flagged — only removals. A changed
|
|
56
|
+
* command string cannot be judged statically.
|
|
57
|
+
* - Acceptance command edits for a retained name are not flagged, for
|
|
58
|
+
* the same reason; only removed names are.
|
|
59
|
+
* - A weakened profile reports as a single profile line; field-level
|
|
60
|
+
* cascades (e.g. `block_on_failure` flipping with the profile
|
|
61
|
+
* default) are suppressed as noise.
|
|
62
|
+
*/
|
|
63
|
+
export function diffWeakening(before, after) {
|
|
64
|
+
if (PROFILE_STRICTNESS[after.profile] < PROFILE_STRICTNESS[before.profile]) {
|
|
65
|
+
return [`profile was weakened (${before.profile} → ${after.profile})`];
|
|
66
|
+
}
|
|
67
|
+
const lines = [];
|
|
68
|
+
const flag = (was, is, label) => {
|
|
69
|
+
if (was && !is)
|
|
70
|
+
lines.push(`${label} was disabled (true → false)`);
|
|
71
|
+
};
|
|
72
|
+
flag(before.runTypecheck, after.gate.run_typecheck, "run_typecheck");
|
|
73
|
+
flag(before.runTests, after.gate.run_tests, "run_tests");
|
|
74
|
+
flag(before.lintChanged, after.gate.lint_changed, "lint_changed");
|
|
75
|
+
if (before.requireReview && !after.gate.require_review) {
|
|
76
|
+
lines.push("require_review was dropped (true → false)");
|
|
77
|
+
}
|
|
78
|
+
flag(before.blockOnFailure, after.gate.block_on_failure, "block_on_failure");
|
|
79
|
+
if (before.scope === "all" &&
|
|
80
|
+
after.gate.scope === "changed" &&
|
|
81
|
+
after.commands.test_changed === undefined) {
|
|
82
|
+
lines.push('scope changed to "changed" with no test_changed command — the test step will now skip');
|
|
83
|
+
}
|
|
84
|
+
if (after.gate.max_blocks < before.maxBlocks) {
|
|
85
|
+
lines.push(`max_blocks was lowered (${before.maxBlocks} → ${after.gate.max_blocks})`);
|
|
86
|
+
}
|
|
87
|
+
if (after.gate.run_typecheck && before.hasTypecheck && after.commands.typecheck === undefined) {
|
|
88
|
+
lines.push("typecheck command was removed — the typecheck step will now skip");
|
|
89
|
+
}
|
|
90
|
+
if (after.gate.run_tests) {
|
|
91
|
+
if (after.gate.scope === "changed" &&
|
|
92
|
+
before.hasTestChanged &&
|
|
93
|
+
after.commands.test_changed === undefined) {
|
|
94
|
+
lines.push("test_changed command was removed — the test step will now skip");
|
|
95
|
+
}
|
|
96
|
+
else if (after.gate.scope !== "changed" &&
|
|
97
|
+
before.hasTest &&
|
|
98
|
+
after.commands.test === undefined) {
|
|
99
|
+
lines.push("test command was removed — the test step will now skip");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (after.gate.lint_changed && before.hasLint && !hasLintNow(after)) {
|
|
103
|
+
lines.push("lint commands were removed — changed-file lint will now skip");
|
|
104
|
+
}
|
|
105
|
+
const afterNames = new Set(after.gate.acceptance.map((c) => c.name));
|
|
106
|
+
for (const name of Object.keys(before.acceptance)) {
|
|
107
|
+
if (!afterNames.has(name)) {
|
|
108
|
+
lines.push(`acceptance check "${name}" was removed`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (after.preflight.length < before.preflightCount) {
|
|
112
|
+
const taskWord = before.preflightCount - after.preflight.length === 1 ? "task" : "tasks";
|
|
113
|
+
lines.push(`preflight ${taskWord} were reduced (${before.preflightCount} → ${after.preflight.length})`);
|
|
114
|
+
}
|
|
115
|
+
return lines;
|
|
116
|
+
}
|