opencode-dev-framework 1.1.0 → 1.3.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 +136 -327
- package/bin/df +33 -0
- package/dist/block-store.d.ts +28 -6
- package/dist/block-store.js +94 -6
- package/dist/config.d.ts +15 -0
- package/dist/config.js +38 -0
- package/dist/goal.js +4 -29
- package/dist/harness.d.ts +11 -1
- package/dist/harness.js +41 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +34 -6
- package/dist/installer.d.ts +72 -0
- package/dist/installer.js +180 -1
- package/package.json +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +101 -0
package/dist/block-store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Persistent per-session completion-gate block counts.
|
|
2
|
+
* Persistent per-session completion-gate block counts (+ stuck snapshots).
|
|
3
3
|
*
|
|
4
4
|
* Counts live in `ctx.storage` (survives plugin reload / `session_move` /
|
|
5
5
|
* server restart) with a caller-provided `Map` as the write-through L1
|
|
@@ -9,21 +9,27 @@
|
|
|
9
9
|
* a broken storage backend degrades to pre-Phase-23 behavior instead of
|
|
10
10
|
* breaking the gate.
|
|
11
11
|
*
|
|
12
|
-
* Stored values are only block counts (`number`)
|
|
13
|
-
*
|
|
12
|
+
* Stored values are only block counts (`number`) and stuck-detection
|
|
13
|
+
* snapshots (`{ signature, files, repeats }` — step names and relative
|
|
14
|
+
* paths, no file contents). Never store secrets, prompts, or file contents
|
|
15
|
+
* here.
|
|
14
16
|
*
|
|
15
|
-
* Key namespacing: counts are keyed `df:blocks:<sessionID
|
|
16
|
-
* session IDs are globally unique, so
|
|
17
|
-
* shared across projects).
|
|
17
|
+
* Key namespacing: counts are keyed `df:blocks:<sessionID>`, snapshots
|
|
18
|
+
* `df:stuck:<sessionID>` (OpenCode session IDs are globally unique, so
|
|
19
|
+
* this is safe even if storage is shared across projects).
|
|
18
20
|
*
|
|
19
21
|
* Historical note: pre-cutover builds persisted a `df:stopSupported` flag
|
|
20
22
|
* recording which stopping probe fired. The idle-first cutover removed
|
|
21
23
|
* that API; a stale key left by an older install is simply never read.
|
|
22
24
|
*/
|
|
23
25
|
export const BLOCK_COUNT_KEY_PREFIX = "df:blocks:";
|
|
26
|
+
export const STUCK_SNAPSHOT_KEY_PREFIX = "df:stuck:";
|
|
24
27
|
function blockKey(sessionID) {
|
|
25
28
|
return `${BLOCK_COUNT_KEY_PREFIX}${sessionID}`;
|
|
26
29
|
}
|
|
30
|
+
function stuckKey(sessionID) {
|
|
31
|
+
return `${STUCK_SNAPSHOT_KEY_PREFIX}${sessionID}`;
|
|
32
|
+
}
|
|
27
33
|
/** Accept only sane counts; anything else (foreign/corrupt value) is treated as missing. */
|
|
28
34
|
function asCount(value) {
|
|
29
35
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0)
|
|
@@ -88,3 +94,85 @@ export function createBlockStore(storage, memory) {
|
|
|
88
94
|
},
|
|
89
95
|
};
|
|
90
96
|
}
|
|
97
|
+
/** Accept only sane snapshots; anything else is treated as missing. */
|
|
98
|
+
function asSnapshot(value) {
|
|
99
|
+
if (typeof value !== "object" || value === null)
|
|
100
|
+
return undefined;
|
|
101
|
+
const v = value;
|
|
102
|
+
if (typeof v.signature !== "string" || v.signature.length === 0 || v.signature.length > 4096)
|
|
103
|
+
return undefined;
|
|
104
|
+
if (!Array.isArray(v.files) || !v.files.every((f) => typeof f === "string"))
|
|
105
|
+
return undefined;
|
|
106
|
+
if (typeof v.repeats !== "number" || !Number.isFinite(v.repeats) || v.repeats < 0)
|
|
107
|
+
return undefined;
|
|
108
|
+
return {
|
|
109
|
+
signature: v.signature,
|
|
110
|
+
files: [...v.files].sort(),
|
|
111
|
+
repeats: Math.floor(v.repeats),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export function createStuckSnapshotStore(storage, memory) {
|
|
115
|
+
const snapshots = memory ?? new Map();
|
|
116
|
+
let degraded = false;
|
|
117
|
+
async function readSnapshot(sessionID) {
|
|
118
|
+
if (storage == null)
|
|
119
|
+
return snapshots.get(sessionID);
|
|
120
|
+
try {
|
|
121
|
+
const stored = asSnapshot(await storage.get(stuckKey(sessionID)));
|
|
122
|
+
if (stored !== undefined) {
|
|
123
|
+
snapshots.set(sessionID, stored);
|
|
124
|
+
return stored;
|
|
125
|
+
}
|
|
126
|
+
return snapshots.get(sessionID);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
degraded = true;
|
|
130
|
+
return snapshots.get(sessionID);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
async function writeSnapshot(sessionID, snapshot) {
|
|
134
|
+
snapshots.set(sessionID, snapshot);
|
|
135
|
+
if (storage == null)
|
|
136
|
+
return;
|
|
137
|
+
try {
|
|
138
|
+
// Plain literal (not the interface): satisfies the Json param type.
|
|
139
|
+
await storage.set(stuckKey(sessionID), {
|
|
140
|
+
signature: snapshot.signature,
|
|
141
|
+
files: [...snapshot.files],
|
|
142
|
+
repeats: snapshot.repeats,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
degraded = true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
get(sessionID) {
|
|
151
|
+
return readSnapshot(sessionID);
|
|
152
|
+
},
|
|
153
|
+
async record(sessionID, snapshot) {
|
|
154
|
+
await writeSnapshot(sessionID, {
|
|
155
|
+
signature: snapshot.signature,
|
|
156
|
+
files: [...snapshot.files].sort(),
|
|
157
|
+
repeats: Math.max(0, Math.floor(snapshot.repeats)),
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
async clear(sessionID) {
|
|
161
|
+
snapshots.delete(sessionID);
|
|
162
|
+
if (storage == null)
|
|
163
|
+
return;
|
|
164
|
+
try {
|
|
165
|
+
await storage.remove(stuckKey(sessionID));
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
degraded = true;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
get size() {
|
|
172
|
+
return snapshots.size;
|
|
173
|
+
},
|
|
174
|
+
isDegraded() {
|
|
175
|
+
return degraded;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -37,6 +37,21 @@ export declare function resolveConfig(raw: Config, configPath?: string): Resolve
|
|
|
37
37
|
* directly.
|
|
38
38
|
*/
|
|
39
39
|
export declare function hasMeaningfulChecks(config: ResolvedConfig): boolean;
|
|
40
|
+
export type ConfigEnforceability = {
|
|
41
|
+
ok: true;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Enforceability bar shared by `/df-goal` and init validation (plan 15):
|
|
48
|
+
* a blocking profile plus at least one meaningful check. Every failure
|
|
49
|
+
* names the exact cause and points at the alternatives. The native-`/goal`
|
|
50
|
+
* availability check stays in `checkGoalAvailability` (`src/goal.ts`) —
|
|
51
|
+
* this is the config half only, so agent-drafted configs can be validated
|
|
52
|
+
* without a live core.
|
|
53
|
+
*/
|
|
54
|
+
export declare function checkConfigEnforceable(config: ResolvedConfig): ConfigEnforceability;
|
|
40
55
|
/** Clear the per-session config cache (mainly for tests). */
|
|
41
56
|
export declare function clearConfigCache(): void;
|
|
42
57
|
/**
|
package/dist/config.js
CHANGED
|
@@ -381,6 +381,44 @@ export function hasMeaningfulChecks(config) {
|
|
|
381
381
|
}
|
|
382
382
|
return false;
|
|
383
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Enforceability bar shared by `/df-goal` and init validation (plan 15):
|
|
386
|
+
* a blocking profile plus at least one meaningful check. Every failure
|
|
387
|
+
* names the exact cause and points at the alternatives. The native-`/goal`
|
|
388
|
+
* availability check stays in `checkGoalAvailability` (`src/goal.ts`) —
|
|
389
|
+
* this is the config half only, so agent-drafted configs can be validated
|
|
390
|
+
* without a live core.
|
|
391
|
+
*/
|
|
392
|
+
export function checkConfigEnforceable(config) {
|
|
393
|
+
if (config.profile === "off") {
|
|
394
|
+
return {
|
|
395
|
+
ok: false,
|
|
396
|
+
error: 'Cannot start a verified goal: profile is "off", so verification would be vacuous. ' +
|
|
397
|
+
"Enable a blocking profile (standard or strict), or use native /goal directly " +
|
|
398
|
+
"for an unverified objective.",
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
if (!config.gate?.block_on_failure) {
|
|
402
|
+
const found = config.gate?.block_on_failure;
|
|
403
|
+
return {
|
|
404
|
+
ok: false,
|
|
405
|
+
error: `Cannot start a verified goal: gate.block_on_failure is ${String(found)}, ` +
|
|
406
|
+
"but /df-goal requires it to be true. Advisory mode must not gain a blocking " +
|
|
407
|
+
"side channel through /df-goal. Enable a blocking profile (standard or strict), " +
|
|
408
|
+
"or use native /goal directly.",
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (!hasMeaningfulChecks(config)) {
|
|
412
|
+
return {
|
|
413
|
+
ok: false,
|
|
414
|
+
error: "Cannot start a verified goal: the resolved configuration provides no meaningful " +
|
|
415
|
+
"completion check (no typecheck/test command, no changed-file lint, no acceptance " +
|
|
416
|
+
"commands, and no review requirement). Configure at least one check, or use native " +
|
|
417
|
+
"/goal directly for a purely semantic objective.",
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
return { ok: true };
|
|
421
|
+
}
|
|
384
422
|
function validateConfig(data, configPath) {
|
|
385
423
|
const result = configSchema.safeParse(data);
|
|
386
424
|
if (!result.success) {
|
package/dist/goal.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* (`isNativeGoalListed`) lives here. Unit tests drive these functions
|
|
15
15
|
* with a stub delegate.
|
|
16
16
|
*/
|
|
17
|
-
import {
|
|
17
|
+
import { checkConfigEnforceable } from "./config.js";
|
|
18
18
|
/**
|
|
19
19
|
* Native `/goal` objective limit. Counts JS `text.length` (UTF-16 code
|
|
20
20
|
* units) — confirmed by the Phase 0 spike against core `goal.ts`
|
|
@@ -90,34 +90,9 @@ export function checkGoalAvailability(config, nativeGoalAvailable) {
|
|
|
90
90
|
"without verification where native /goal exists.",
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
error: 'Cannot start a verified goal: profile is "off", so verification would be vacuous. ' +
|
|
97
|
-
"Enable a blocking profile (standard or strict), or use native /goal directly " +
|
|
98
|
-
"for an unverified objective.",
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
if (!config.gate?.block_on_failure) {
|
|
102
|
-
const found = config.gate?.block_on_failure;
|
|
103
|
-
return {
|
|
104
|
-
ok: false,
|
|
105
|
-
error: `Cannot start a verified goal: gate.block_on_failure is ${String(found)}, ` +
|
|
106
|
-
"but /df-goal requires it to be true. Advisory mode must not gain a blocking " +
|
|
107
|
-
"side channel through /df-goal. Enable a blocking profile (standard or strict), " +
|
|
108
|
-
"or use native /goal directly.",
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (!hasMeaningfulChecks(config)) {
|
|
112
|
-
return {
|
|
113
|
-
ok: false,
|
|
114
|
-
error: "Cannot start a verified goal: the resolved configuration provides no meaningful " +
|
|
115
|
-
"completion check (no typecheck/test command, no changed-file lint, no acceptance " +
|
|
116
|
-
"commands, and no review requirement). Configure at least one check, or use native " +
|
|
117
|
-
"/goal directly for a purely semantic objective.",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return { ok: true };
|
|
93
|
+
// Config half of the bar lives in `checkConfigEnforceable` (plan 15) so
|
|
94
|
+
// init validation reuses the identical messages.
|
|
95
|
+
return checkConfigEnforceable(config);
|
|
121
96
|
}
|
|
122
97
|
/**
|
|
123
98
|
* Validate, wrap, and delegate exactly once. Native delegation errors
|
package/dist/harness.d.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* The verdict is consumed by the `experimental.idle` hook (same-execution
|
|
17
17
|
* synthetic continuation) and the `session.idle` event net (re-prompt).
|
|
18
18
|
*/
|
|
19
|
-
import type { BlockStore } from "./block-store.js";
|
|
19
|
+
import type { BlockStore, StuckSnapshotStore } from "./block-store.js";
|
|
20
20
|
import { type ChangedFileTracker, type GateReport } from "./gate.js";
|
|
21
21
|
import type { RunCommand } from "./host.js";
|
|
22
22
|
import type { LintLimiter } from "./lint.js";
|
|
@@ -26,6 +26,14 @@ import type { ResolvedConfig } from "./types.js";
|
|
|
26
26
|
export declare const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
27
27
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
28
28
|
export declare const PREFLIGHT_ARTIFACT_REL = ".opencode/opencode-dev-framework/preflight.md";
|
|
29
|
+
/**
|
|
30
|
+
* Consecutive no-progress repeats before early stand-down (docs/plans/14-stuck-detection.md): the
|
|
31
|
+
* third identical blocked evaluation (two repeats) stands down. One
|
|
32
|
+
* investigate-then-fix cycle — a repeat with no edits while the agent
|
|
33
|
+
* reads logs or runs diagnostics — still blocks. Hardcoded, not a config
|
|
34
|
+
* key: the profile stays the single enforcement axis.
|
|
35
|
+
*/
|
|
36
|
+
export declare const NO_PROGRESS_REPEATS = 2;
|
|
29
37
|
export type ArtifactState = "missing" | "empty" | "present";
|
|
30
38
|
/**
|
|
31
39
|
* Inspect an artifact file: present (non-trivial content), empty, or missing.
|
|
@@ -79,6 +87,8 @@ export interface CompletionDeps {
|
|
|
79
87
|
sessionID: string;
|
|
80
88
|
tracker: ChangedFileTracker;
|
|
81
89
|
blockCounts: BlockStore;
|
|
90
|
+
/** Last-blocked-evaluation snapshots for no-progress early stand-down. */
|
|
91
|
+
stuckSnapshots: StuckSnapshotStore;
|
|
82
92
|
log: LogFn;
|
|
83
93
|
/** Shared limiter bounding concurrent linter subprocesses. */
|
|
84
94
|
lintLimiter?: LintLimiter;
|
package/dist/harness.js
CHANGED
|
@@ -23,6 +23,14 @@ import { runGate, summarizeGate } from "./gate.js";
|
|
|
23
23
|
export const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
24
24
|
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
25
25
|
export const PREFLIGHT_ARTIFACT_REL = ".opencode/opencode-dev-framework/preflight.md";
|
|
26
|
+
/**
|
|
27
|
+
* Consecutive no-progress repeats before early stand-down (docs/plans/14-stuck-detection.md): the
|
|
28
|
+
* third identical blocked evaluation (two repeats) stands down. One
|
|
29
|
+
* investigate-then-fix cycle — a repeat with no edits while the agent
|
|
30
|
+
* reads logs or runs diagnostics — still blocks. Hardcoded, not a config
|
|
31
|
+
* key: the profile stays the single enforcement axis.
|
|
32
|
+
*/
|
|
33
|
+
export const NO_PROGRESS_REPEATS = 2;
|
|
26
34
|
/**
|
|
27
35
|
* Inspect an artifact file: present (non-trivial content), empty, or missing.
|
|
28
36
|
* Never throws — unreadable files count as missing.
|
|
@@ -283,7 +291,7 @@ export async function inspectCompletion(deps) {
|
|
|
283
291
|
* block count applies to either lever.
|
|
284
292
|
*/
|
|
285
293
|
export async function evaluateCompletion(deps) {
|
|
286
|
-
const { run, config, directory, sessionID, tracker, blockCounts } = deps;
|
|
294
|
+
const { run, config, directory, sessionID, tracker, blockCounts, stuckSnapshots } = deps;
|
|
287
295
|
if (config.profile === "off" || !config.gate) {
|
|
288
296
|
return { decision: "pass", changedFiles: [] };
|
|
289
297
|
}
|
|
@@ -301,6 +309,7 @@ export async function evaluateCompletion(deps) {
|
|
|
301
309
|
if (!gateFailed && !reviewMissing) {
|
|
302
310
|
tracker.clearChangedFiles();
|
|
303
311
|
await blockCounts.clear(sessionID);
|
|
312
|
+
await stuckSnapshots.clear(sessionID);
|
|
304
313
|
return {
|
|
305
314
|
decision: "pass",
|
|
306
315
|
changedFiles,
|
|
@@ -322,10 +331,41 @@ export async function evaluateCompletion(deps) {
|
|
|
322
331
|
const reason = gateFailed ? "gate" : "review";
|
|
323
332
|
const summary = inspection.summary;
|
|
324
333
|
const maxBlocks = config.gate.max_blocks ?? 3;
|
|
334
|
+
// No-progress early stand-down (docs/plans/14-stuck-detection.md): consecutive blocked
|
|
335
|
+
// evaluations with the identical failure signature and no new edits buy
|
|
336
|
+
// zero information, so stop spending the budget on them. One
|
|
337
|
+
// investigate-then-fix cycle is tolerated (a single repeat still
|
|
338
|
+
// blocks); the third identical evaluation stands down.
|
|
339
|
+
const signature = gateFailed
|
|
340
|
+
? `gate:${report.failedSteps
|
|
341
|
+
.map((s) => s.name)
|
|
342
|
+
.sort()
|
|
343
|
+
.join(",")}`
|
|
344
|
+
: "review";
|
|
345
|
+
const files = [...changedFiles].sort();
|
|
346
|
+
const previous = await stuckSnapshots.get(sessionID);
|
|
347
|
+
const noProgress = previous !== undefined &&
|
|
348
|
+
previous.signature === signature &&
|
|
349
|
+
previous.files.length === files.length &&
|
|
350
|
+
previous.files.every((f, i) => f === files[i]);
|
|
351
|
+
const repeats = noProgress ? previous.repeats + 1 : 0;
|
|
352
|
+
if (repeats >= NO_PROGRESS_REPEATS) {
|
|
353
|
+
tracker.clearChangedFiles();
|
|
354
|
+
await blockCounts.clear(sessionID);
|
|
355
|
+
await stuckSnapshots.clear(sessionID);
|
|
356
|
+
const stuckSummary = `opencode-dev-framework completion gate has seen the identical failure across ` +
|
|
357
|
+
`${repeats + 1} evaluations with no new changes and is standing down to avoid ` +
|
|
358
|
+
`trapping you. The requirement is STILL unmet:\n\n${summary}\n\n` +
|
|
359
|
+
`Do not claim the work is complete. Tell the user plainly what remains unmet and why.`;
|
|
360
|
+
await deps.log("error", stuckSummary, { reason, sessionID });
|
|
361
|
+
return { decision: "standdown", reason, summary: stuckSummary, changedFiles };
|
|
362
|
+
}
|
|
363
|
+
await stuckSnapshots.record(sessionID, { signature, files, repeats });
|
|
325
364
|
const blockCount = await blockCounts.increment(sessionID);
|
|
326
365
|
if (blockCount > maxBlocks) {
|
|
327
366
|
tracker.clearChangedFiles();
|
|
328
367
|
await blockCounts.clear(sessionID);
|
|
368
|
+
await stuckSnapshots.clear(sessionID);
|
|
329
369
|
const standdownSummary = `opencode-dev-framework completion gate has blocked ${maxBlocks} times and is standing ` +
|
|
330
370
|
`down to avoid trapping you. The requirement is STILL unmet:\n\n${summary}\n\n` +
|
|
331
371
|
`Do not claim the work is complete. Tell the user plainly what remains unmet and why.`;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* stays as a deduped fallback for the boundaries the hook skips.
|
|
22
22
|
*/
|
|
23
23
|
import { Plugin } from "@opencode/plugin";
|
|
24
|
-
import { type BlockStore } from "./block-store.js";
|
|
24
|
+
import { type BlockStore, type StuckSnapshotStore } from "./block-store.js";
|
|
25
25
|
import { type ChangedFileTracker } from "./gate.js";
|
|
26
26
|
import { type PassCache } from "./harness.js";
|
|
27
27
|
import { type RunCommand } from "./host.js";
|
|
@@ -46,6 +46,12 @@ export interface HookState {
|
|
|
46
46
|
* store keeps live on every get/increment/clear.
|
|
47
47
|
*/
|
|
48
48
|
blocks: BlockStore;
|
|
49
|
+
/**
|
|
50
|
+
* Last-blocked-evaluation snapshots for no-progress early stand-down
|
|
51
|
+
* (docs/plans/14-stuck-detection.md). Same storage-backed, best-effort pattern as `blocks`;
|
|
52
|
+
* memory-only here (no status projection needed).
|
|
53
|
+
*/
|
|
54
|
+
stuckSnapshots: StuckSnapshotStore;
|
|
49
55
|
precommitAvailable?: boolean;
|
|
50
56
|
configMtime?: number;
|
|
51
57
|
/**
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { Plugin } from "@opencode/plugin";
|
|
24
24
|
import { stat } from "node:fs/promises";
|
|
25
25
|
import { join } from "node:path";
|
|
26
|
-
import { createBlockStore } from "./block-store.js";
|
|
26
|
+
import { createBlockStore, createStuckSnapshotStore, } from "./block-store.js";
|
|
27
27
|
import { clearConfigCache, loadConfig } from "./config.js";
|
|
28
28
|
import { createChangedFileTracker } from "./gate.js";
|
|
29
29
|
import { artifactState, createPassCache, evaluateCompletion, PREFLIGHT_ARTIFACT_REL, preflightBlockReason, } from "./harness.js";
|
|
@@ -162,6 +162,7 @@ function runCompletion(state, sessionID) {
|
|
|
162
162
|
sessionID,
|
|
163
163
|
tracker: state.tracker,
|
|
164
164
|
blockCounts: state.blocks,
|
|
165
|
+
stuckSnapshots: state.stuckSnapshots,
|
|
165
166
|
lintLimiter: state.lintLimiter,
|
|
166
167
|
passCache: state.passCache,
|
|
167
168
|
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
@@ -274,6 +275,7 @@ const plugin = Plugin.define({
|
|
|
274
275
|
const tracker = createChangedFileTracker();
|
|
275
276
|
const blockCounts = new Map();
|
|
276
277
|
const blocks = createBlockStore(ctx.storage, blockCounts);
|
|
278
|
+
const stuckSnapshots = createStuckSnapshotStore(ctx.storage);
|
|
277
279
|
const state = {
|
|
278
280
|
directory,
|
|
279
281
|
config,
|
|
@@ -283,6 +285,7 @@ const plugin = Plugin.define({
|
|
|
283
285
|
constitution,
|
|
284
286
|
blockCounts,
|
|
285
287
|
blocks,
|
|
288
|
+
stuckSnapshots,
|
|
286
289
|
configMtime,
|
|
287
290
|
lintLimiter: createLintLimiter(),
|
|
288
291
|
passCache: createPassCache(),
|
|
@@ -294,7 +297,7 @@ const plugin = Plugin.define({
|
|
|
294
297
|
// With the stop-level hydration gone there is no setup-time storage
|
|
295
298
|
// read left, so this rarely fires here — the store still degrades
|
|
296
299
|
// lazily on first use and reports via isDegraded().
|
|
297
|
-
if (blocks.isDegraded()) {
|
|
300
|
+
if (blocks.isDegraded() || stuckSnapshots.isDegraded()) {
|
|
298
301
|
await log("warn", "ctx.storage is unavailable; gate block counts are in-memory only and reset on reload", { directory });
|
|
299
302
|
}
|
|
300
303
|
const registrations = [];
|
|
@@ -616,7 +619,7 @@ const plugin = Plugin.define({
|
|
|
616
619
|
trackRegistration(await ctx.tool.transform((editor) => {
|
|
617
620
|
editor.add({
|
|
618
621
|
name: "dev_framework_init",
|
|
619
|
-
description: "Scaffold opencode-dev-framework project files (agents, skills, commands, default config) into the current project. Missing files are created; existing files are skipped unless overwrite is true.",
|
|
622
|
+
description: "Scaffold opencode-dev-framework project files (agents, skills, commands, default config) into the current project. Missing files are created; existing files are skipped unless overwrite is true. With wizard:true, appends a wizard brief (detection, trial-run, Makefile targets, open questions) — follow the project-config skill to resolve it and present the config for review.",
|
|
620
623
|
input: {
|
|
621
624
|
type: "object",
|
|
622
625
|
properties: {
|
|
@@ -628,11 +631,15 @@ const plugin = Plugin.define({
|
|
|
628
631
|
type: "boolean",
|
|
629
632
|
description: "Overwrite existing files that differ from templates",
|
|
630
633
|
},
|
|
634
|
+
wizard: {
|
|
635
|
+
type: "boolean",
|
|
636
|
+
description: "Append a wizard brief for agent-led handoff to the project-config skill",
|
|
637
|
+
},
|
|
631
638
|
},
|
|
632
639
|
additionalProperties: false,
|
|
633
640
|
},
|
|
634
641
|
async execute(input) {
|
|
635
|
-
const { installTemplates, writeDetectedConfig } = await import("./installer.js");
|
|
642
|
+
const { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, trialRunDetectedCommands, writeDetectedConfig, } = await import("./installer.js");
|
|
636
643
|
const args = input;
|
|
637
644
|
const targetDir = args.directory ?? directory;
|
|
638
645
|
const result = await installTemplates(targetDir, {
|
|
@@ -654,6 +661,26 @@ const plugin = Plugin.define({
|
|
|
654
661
|
lines.push("", "Created files:", ...result.created.map((f) => `- ${f}`));
|
|
655
662
|
if (result.overwritten.length > 0)
|
|
656
663
|
lines.push("", "Overwritten files:", ...result.overwritten.map((f) => `- ${f}`));
|
|
664
|
+
if (args.wizard === true) {
|
|
665
|
+
try {
|
|
666
|
+
const brief = await buildWizardBrief(targetDir, state.run);
|
|
667
|
+
lines.push("", ...formatWizardBrief(brief));
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
lines.push("", formatBriefSkipped(error));
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
else if (configResult.action === "created" || configResult.action === "overwritten") {
|
|
674
|
+
try {
|
|
675
|
+
const { detectProject } = await import("./detect.js");
|
|
676
|
+
const { commands } = detectProject(targetDir);
|
|
677
|
+
const trial = await trialRunDetectedCommands(targetDir, commands, state.run);
|
|
678
|
+
lines.push("", ...formatTrialRun(trial));
|
|
679
|
+
}
|
|
680
|
+
catch (error) {
|
|
681
|
+
lines.push("", `Trial-run: skipped (${error instanceof Error ? error.message : String(error)}) — verify commands manually`);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
657
684
|
return { content: lines.join("\n") };
|
|
658
685
|
},
|
|
659
686
|
});
|
|
@@ -833,11 +860,12 @@ const plugin = Plugin.define({
|
|
|
833
860
|
const event = rawEvent;
|
|
834
861
|
const type = event.type;
|
|
835
862
|
if (isSessionDeletedEvent(type)) {
|
|
836
|
-
// session.deleted: cleanup block counts
|
|
837
|
-
// the idle dedup stamp for the session.
|
|
863
|
+
// session.deleted: cleanup block counts + stuck snapshots
|
|
864
|
+
// (memory + storage) and the idle dedup stamp for the session.
|
|
838
865
|
const sid = getEventSessionID(event);
|
|
839
866
|
if (sid) {
|
|
840
867
|
await state.blocks.clear(sid);
|
|
868
|
+
await state.stuckSnapshots.clear(sid);
|
|
841
869
|
state.lastIdleHandled.delete(sid);
|
|
842
870
|
}
|
|
843
871
|
continue;
|
package/dist/installer.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { RunCommand } from "./host.js";
|
|
1
2
|
import type { Profile } from "./types.js";
|
|
2
3
|
/** Directory containing the project templates shipped with the package. */
|
|
3
4
|
export declare const TEMPLATES_DIR: string;
|
|
@@ -41,8 +42,79 @@ export interface ConfigWriteResult {
|
|
|
41
42
|
* `installTemplates`.
|
|
42
43
|
*/
|
|
43
44
|
export declare function writeDetectedConfig(targetDir: string, options?: InstallOptions): Promise<ConfigWriteResult>;
|
|
45
|
+
/** Bounded trial-run timeout (seconds): init UX, not a gate suite. */
|
|
46
|
+
export declare const TRIAL_RUN_TIMEOUT_SECONDS = 120;
|
|
47
|
+
export interface TrialRunResult {
|
|
48
|
+
name: "test" | "typecheck";
|
|
49
|
+
command: string;
|
|
50
|
+
ok: boolean;
|
|
51
|
+
exitCode: number;
|
|
52
|
+
timedOut: boolean;
|
|
53
|
+
durationMs: number;
|
|
54
|
+
/** Spawn failure detail (run threw instead of resolving). */
|
|
55
|
+
error?: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Run each runnable detected command once to verify the guess (plan 15).
|
|
59
|
+
* Only `test`/`typecheck` run bare — lint/format templates carry
|
|
60
|
+
* `{file}`/`{dir}` placeholders and are reported as unverified by the
|
|
61
|
+
* caller skipping them (absent or empty commands are skipped, not failed).
|
|
62
|
+
* The two trials run concurrently; each is bounded by `timeout` seconds.
|
|
63
|
+
* Report-only by construction: results annotate, never throw — including
|
|
64
|
+
* for runners that reject despite the host never-rejects contract.
|
|
65
|
+
*/
|
|
66
|
+
export declare function trialRunDetectedCommands(directory: string, commands: {
|
|
67
|
+
test?: string;
|
|
68
|
+
typecheck?: string;
|
|
69
|
+
}, run: RunCommand, opts?: {
|
|
70
|
+
timeout?: number;
|
|
71
|
+
}): Promise<TrialRunResult[]>;
|
|
72
|
+
/** Render trial-run results as CLI/tool output lines. */
|
|
73
|
+
export declare function formatTrialRun(results: TrialRunResult[]): string[];
|
|
44
74
|
/** Resolve a user-supplied directory (default cwd) to an absolute path. */
|
|
45
75
|
export declare function resolveTargetDir(dir?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* List Makefile target names (plan 16). Names only, no semantics: the
|
|
78
|
+
* agent decides which (if any) are canonical wrappers. Capped at 30.
|
|
79
|
+
* Grouped targets (`lint test: deps`) split into both names; pattern
|
|
80
|
+
* rules, dot-directives, assignments, and make keywords never match.
|
|
81
|
+
* Probes GNUmakefile/makefile/Makefile in GNU make precedence order.
|
|
82
|
+
* Empty when no makefile exists or none is readable — report-only.
|
|
83
|
+
*/
|
|
84
|
+
export declare function listMakefileTargets(directory: string): Promise<string[]>;
|
|
85
|
+
export interface WizardBrief {
|
|
86
|
+
language: string | null;
|
|
87
|
+
commands: {
|
|
88
|
+
test?: string;
|
|
89
|
+
typecheck?: string;
|
|
90
|
+
};
|
|
91
|
+
trial: TrialRunResult[];
|
|
92
|
+
makeTargets: string[];
|
|
93
|
+
enforceability: {
|
|
94
|
+
ok: true;
|
|
95
|
+
} | {
|
|
96
|
+
ok: false;
|
|
97
|
+
error: string;
|
|
98
|
+
};
|
|
99
|
+
/** Open questions for the agent, capped at 3 — never exhaustive. */
|
|
100
|
+
questions: string[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Build the agent-handoff brief (plan 16): detection, trial-run, Makefile
|
|
104
|
+
* target names, and the shared enforceability verdict in one bundle. The
|
|
105
|
+
* LLM session agent is the wizard's presenter — this is the machine side,
|
|
106
|
+
* hints only, and the project-config skill still verifies everything by
|
|
107
|
+
* running. Trial/target failures annotate, never throw; a nonexistent
|
|
108
|
+
* directory rejects via detection, so both callers isolate the brief in
|
|
109
|
+
* try/catch (see `formatBriefSkipped`).
|
|
110
|
+
*/
|
|
111
|
+
export declare function buildWizardBrief(directory: string, run: RunCommand, opts?: {
|
|
112
|
+
timeout?: number;
|
|
113
|
+
}): Promise<WizardBrief>;
|
|
114
|
+
/** Shared report-only fallback when the brief itself cannot be built. */
|
|
115
|
+
export declare function formatBriefSkipped(error: unknown): string;
|
|
116
|
+
/** Render the wizard brief as CLI/tool output lines, ending in the handoff. */
|
|
117
|
+
export declare function formatWizardBrief(brief: WizardBrief): string[];
|
|
46
118
|
/**
|
|
47
119
|
* Set the top-level `profile:` key in a config file. Edits the raw text
|
|
48
120
|
* instead of re-serializing the YAML so user comments and formatting survive.
|