opencode-dev-framework 0.5.1 → 1.0.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 CHANGED
@@ -48,7 +48,8 @@ reimplemented as an OpenCode-native plugin.
48
48
  - **Slash commands.** The plugin registers four TUI commands that open instant
49
49
  modal dialogs and never feed anything to the LLM: `/df-status`, `/df-help`,
50
50
  `/df-profile` (bare for a picker, or with an argument), and `/df-verify`
51
- (runs the gate manually). The `dev_framework_*` custom *tools* above remain
51
+ (runs the gate manually). `/df-goal <objective>` is a server-side command
52
+ instead: it starts a verified native goal (see *Slash commands* below). The `dev_framework_*` custom *tools* above remain
52
53
  available for in-agent use.
53
54
 
54
55
  ## Profiles
@@ -212,7 +213,7 @@ complete example.
212
213
 
213
214
  ## Slash commands
214
215
 
215
- All five slash commands are **TUI commands** registered by the bundled `./tui`
216
+ Five slash commands are **TUI commands** registered by the bundled `./tui`
216
217
  companion module (see *Local development* above for the `tui.json` requirement).
217
218
  They open instantly and **never** feed text back to the LLM:
218
219
 
@@ -236,6 +237,26 @@ config; the commands themselves are provided by the plugin. The
236
237
  available for in-agent use (e.g. when the model wants to change the profile
237
238
  itself).
238
239
 
240
+ `/df-goal <objective>` is a **server-side command** instead (registered by the
241
+ server plugin, not the TUI): it starts a **verified** native goal. The plugin
242
+ appends a short verification contract to your objective verbatim and delegates
243
+ exactly once to native `/goal`, which keeps owning state, review,
244
+ pause/resume/clear, and continuations. Requires all three: native `/goal` on
245
+ the core, a blocking profile (`standard`/`strict`, i.e.
246
+ `gate.block_on_failure: true`), and at least one configured completion check
247
+ (typecheck/test command, changed-file lint, `gate.acceptance`, or
248
+ `gate.require_review`). Otherwise it fails with an actionable error instead of
249
+ starting an unverified goal — use native `/goal` directly for purely semantic
250
+ objectives. The objective plus addendum must fit native `/goal`'s 4,000-character
251
+ limit; overflow is rejected, never truncated.
252
+
253
+ The agent must run `dev_framework_verify` after its final changes; the native
254
+ reviewer weighs that tool result as evidence and the framework idle gate stays
255
+ an independent backstop. This is layered verification, not a hard lock:
256
+ native `/goal` can still mark complete while the gate fails (or keep going
257
+ after it passes), both tenants can admit a continuation at one idle boundary,
258
+ and the framework stands down after `gate.max_blocks`.
259
+
239
260
  ## Limitations
240
261
 
241
262
  - **Post-flight enforcement is a same-execution continuation, not a veto.**
@@ -1,4 +1,5 @@
1
- import { type GateReport } from "./gate.js";
1
+ import type { GateReport } from "./gate.js";
2
+ import { type CompletionInspection } from "./harness.js";
2
3
  import type { RunCommand } from "./host.js";
3
4
  import type { Profile, ResolvedConfig } from "./types.js";
4
5
  /**
@@ -10,12 +11,27 @@ import type { Profile, ResolvedConfig } from "./types.js";
10
11
  */
11
12
  export declare function changeProfile(directory: string, profile: Profile): Promise<string>;
12
13
  /**
13
- * Run the completion gate manually for a project. When `config` is omitted the
14
- * project config is loaded from disk. `changedFiles` is normally empty for a
15
- * manual verify (the server's live tracker is not visible from the TUI), so a
16
- * `scope: changed` gate will report "no changed files".
14
+ * Manual verification result. `verdict` reports the raw inspection outcome:
15
+ * PASS only when the gate passes AND review (when required) is satisfied.
16
+ * Advisory profiles report raw FAIL here — the non-blocking behavior lives
17
+ * in the idle policy (`evaluateCompletion`), not in this verdict.
17
18
  */
18
- export declare function verifyGate(run: RunCommand, directory: string, config?: ResolvedConfig, changedFiles?: string[]): Promise<{
19
+ export interface VerifyResult {
19
20
  report: GateReport;
21
+ inspection: CompletionInspection;
22
+ verdict: "PASS" | "FAIL";
20
23
  summary: string;
21
- }>;
24
+ }
25
+ /**
26
+ * Run manual verification for a project: the same full completion contract
27
+ * as the idle gate (gate commands plus review state), without any retry
28
+ * policy. Side-effect-free by construction: this function receives only a
29
+ * read-only changed-file snapshot and has no handle on the tracker, the
30
+ * block store, or session input. Git discovery is included so a verify with
31
+ * an empty tracker still sees worktree changes.
32
+ *
33
+ * When `config` is omitted the project config is loaded from disk.
34
+ * `changedFiles` is normally the server's live tracker snapshot (empty for
35
+ * TUI callers); Git-discovered files are unioned in either way.
36
+ */
37
+ export declare function verifyGate(run: RunCommand, directory: string, config?: ResolvedConfig, changedFiles?: string[]): Promise<VerifyResult>;
package/dist/commands.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { join } from "node:path";
2
2
  import { loadConfig } from "./config.js";
3
- import { runGate, summarizeGate } from "./gate.js";
3
+ import { inspectCompletion } from "./harness.js";
4
4
  import { setProfileInFile } from "./installer.js";
5
5
  /**
6
6
  * Change the project profile by editing the config file on disk. The server
@@ -15,13 +15,26 @@ export async function changeProfile(directory, profile) {
15
15
  return `opencode-dev-framework profile set to "${profile}". Change applies on the next tool call / gate run.`;
16
16
  }
17
17
  /**
18
- * Run the completion gate manually for a project. When `config` is omitted the
19
- * project config is loaded from disk. `changedFiles` is normally empty for a
20
- * manual verify (the server's live tracker is not visible from the TUI), so a
21
- * `scope: changed` gate will report "no changed files".
18
+ * Run manual verification for a project: the same full completion contract
19
+ * as the idle gate (gate commands plus review state), without any retry
20
+ * policy. Side-effect-free by construction: this function receives only a
21
+ * read-only changed-file snapshot and has no handle on the tracker, the
22
+ * block store, or session input. Git discovery is included so a verify with
23
+ * an empty tracker still sees worktree changes.
24
+ *
25
+ * When `config` is omitted the project config is loaded from disk.
26
+ * `changedFiles` is normally the server's live tracker snapshot (empty for
27
+ * TUI callers); Git-discovered files are unioned in either way.
22
28
  */
23
29
  export async function verifyGate(run, directory, config, changedFiles = []) {
24
30
  const cfg = config ?? loadConfig(directory);
25
- const report = await runGate(run, cfg, changedFiles, { cwd: directory });
26
- return { report, summary: summarizeGate(report) };
31
+ const inspection = await inspectCompletion({
32
+ run,
33
+ config: cfg,
34
+ directory,
35
+ trackerFiles: changedFiles,
36
+ });
37
+ const verdict = inspection.ok ? "PASS" : "FAIL";
38
+ const summary = `DEV_FRAMEWORK_VERDICT: ${verdict}\n${inspection.summary}`;
39
+ return { report: inspection.report, inspection, verdict, summary };
27
40
  }
package/dist/config.d.ts CHANGED
@@ -24,6 +24,17 @@ export declare function mapFlatConfig(flat: Record<string, unknown>): Config;
24
24
  * always override profile defaults.
25
25
  */
26
26
  export declare function resolveConfig(raw: Config, configPath?: string): ResolvedConfig;
27
+ /**
28
+ * Static "meaningful check" predicate for `/df-goal` (plan §3.3).
29
+ *
30
+ * A verified goal must imply deterministic evidence where none would exist
31
+ * otherwise, so `/df-goal` refuses to delegate when the resolved
32
+ * configuration provides no real completion check at all. A check counts
33
+ * only when its step would actually run in `runGate` — a `run_*` flag with
34
+ * no command behind it produces a skipped step, which is vacuous. Users
35
+ * wanting a purely semantic objective use native `/goal` directly.
36
+ */
37
+ export declare function hasMeaningfulChecks(config: ResolvedConfig): boolean;
27
38
  /** Clear the per-session config cache (mainly for tests). */
28
39
  export declare function clearConfigCache(): void;
29
40
  /**
package/dist/config.js CHANGED
@@ -27,6 +27,35 @@ export const DEFAULT_PROTECT = [
27
27
  "**/vendor/**",
28
28
  ];
29
29
  const commandMapSchema = z.union([z.string(), z.record(z.string(), z.string())]);
30
+ const acceptanceCheckSchema = z.object({
31
+ name: z
32
+ .string()
33
+ .min(1, "acceptance check name must not be empty")
34
+ .refine((s) => s.trim().length > 0, "acceptance check name must not be blank"),
35
+ command: z.string().min(1, "acceptance check command must not be empty"),
36
+ timeout: z.number().positive("acceptance check timeout must be positive").optional(),
37
+ });
38
+ const acceptanceListSchema = z
39
+ .array(acceptanceCheckSchema)
40
+ .optional()
41
+ .superRefine((checks, ctx) => {
42
+ if (!checks)
43
+ return;
44
+ const seen = new Map();
45
+ checks.forEach((check, index) => {
46
+ const first = seen.get(check.name);
47
+ if (first !== undefined) {
48
+ ctx.addIssue({
49
+ code: "custom",
50
+ message: `duplicate acceptance check name "${check.name}" (first at index ${first})`,
51
+ path: [index, "name"],
52
+ });
53
+ }
54
+ else {
55
+ seen.set(check.name, index);
56
+ }
57
+ });
58
+ });
30
59
  const configSchema = z.object({
31
60
  profile: z.enum(["off", "advisory", "standard", "strict"]).optional(),
32
61
  commands: z
@@ -52,6 +81,7 @@ const configSchema = z.object({
52
81
  require_review: z.boolean().optional(),
53
82
  timeout: z.number().positive().optional(),
54
83
  max_blocks: z.number().int().positive().optional(),
84
+ acceptance: acceptanceListSchema,
55
85
  })
56
86
  .optional(),
57
87
  preflight: z.union([z.array(z.string()), z.string()]).optional(),
@@ -294,6 +324,7 @@ export function resolveConfig(raw, configPath) {
294
324
  require_review: raw.gate?.require_review ?? profile !== "off",
295
325
  timeout: raw.gate?.timeout,
296
326
  max_blocks: raw.gate?.max_blocks ?? 3,
327
+ acceptance: raw.gate?.acceptance ?? [],
297
328
  },
298
329
  on_edit: {
299
330
  format: raw.on_edit?.format ?? defaults.on_edit_format,
@@ -306,6 +337,39 @@ export function resolveConfig(raw, configPath) {
306
337
  preflight: raw.preflight ?? [],
307
338
  };
308
339
  }
340
+ /**
341
+ * Static "meaningful check" predicate for `/df-goal` (plan §3.3).
342
+ *
343
+ * A verified goal must imply deterministic evidence where none would exist
344
+ * otherwise, so `/df-goal` refuses to delegate when the resolved
345
+ * configuration provides no real completion check at all. A check counts
346
+ * only when its step would actually run in `runGate` — a `run_*` flag with
347
+ * no command behind it produces a skipped step, which is vacuous. Users
348
+ * wanting a purely semantic objective use native `/goal` directly.
349
+ */
350
+ export function hasMeaningfulChecks(config) {
351
+ const gate = config.gate;
352
+ if (!gate)
353
+ return false;
354
+ if (gate.require_review)
355
+ return true;
356
+ if (gate.acceptance.length > 0)
357
+ return true;
358
+ if (gate.run_typecheck && config.commands.typecheck !== undefined)
359
+ return true;
360
+ if (gate.run_tests) {
361
+ const template = gate.scope === "changed" ? config.commands.test_changed : config.commands.test;
362
+ if (template !== undefined)
363
+ return true;
364
+ }
365
+ if (gate.lint_changed) {
366
+ const lint = config.commands.lint;
367
+ if (typeof lint === "string" || (lint !== undefined && Object.keys(lint).length > 0)) {
368
+ return true;
369
+ }
370
+ }
371
+ return false;
372
+ }
309
373
  function validateConfig(data, configPath) {
310
374
  const result = configSchema.safeParse(data);
311
375
  if (!result.success) {
@@ -110,6 +110,7 @@ export function renderHelp() {
110
110
  lines.push("/df-status Show the current dev-framework state");
111
111
  lines.push("/df-profile Change the profile to off, advisory, standard, or strict");
112
112
  lines.push("/df-verify Run the completion gate manually");
113
+ lines.push("/df-goal Start a verified native goal (verification contract + native /goal)");
113
114
  lines.push("/df-help Show this message");
114
115
  lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
115
116
  return lines.join("\n");
package/dist/gate.d.ts CHANGED
@@ -26,7 +26,7 @@ export interface ChangedFileTracker {
26
26
  */
27
27
  export declare function createChangedFileTracker(): ChangedFileTracker;
28
28
  export interface GateStep {
29
- /** `typecheck`, `test`, or `lint:<file>`. */
29
+ /** `typecheck`, `test`, `lint:<file>`, or `acceptance:<name>`. */
30
30
  name: string;
31
31
  command?: string[];
32
32
  skipped: boolean;
package/dist/gate.js CHANGED
@@ -111,6 +111,19 @@ export async function runGate(run, config, changedFiles, options) {
111
111
  });
112
112
  }
113
113
  }
114
+ // Named acceptance checks run last, sequentially, in declaration order.
115
+ // Like every other step, a failure is aggregated — it does not abort the
116
+ // remaining steps. `{files}` substitution and the project `cwd` match the
117
+ // test-command semantics; per-check timeout overrides the gate default.
118
+ for (const check of config.gate.acceptance) {
119
+ const command = substituteFiles(check.command, changedFiles);
120
+ steps.push({
121
+ name: `acceptance:${check.name}`,
122
+ command,
123
+ skipped: false,
124
+ result: await run(command, { cwd: options?.cwd, timeout: check.timeout ?? timeout }),
125
+ });
126
+ }
114
127
  const ran = steps.some((step) => !step.skipped);
115
128
  const failedSteps = steps.filter((step) => !step.skipped && step.result !== undefined && isFailure(step.result));
116
129
  return {
package/dist/goal.d.ts ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * `/df-goal`: verified-goal wrapper around native `/goal`.
3
+ *
4
+ * A thin adapter, not a second goal engine: it validates that verified-goal
5
+ * mode is meaningful and available (§3.3), appends the framework verification
6
+ * addendum to the user's objective verbatim (§3.2), and delegates exactly
7
+ * once to native `/goal` via `session.command`. Native `/goal` keeps owning
8
+ * kickoff, state, reviewer, pause/resume/clear, and continuations; the
9
+ * framework's idle gate stays the independent deterministic backstop.
10
+ *
11
+ * All policy here is pure (input -> data, no session I/O): `src/index.ts`
12
+ * owns the `ctx.command.transform` registration, capability probing, and
13
+ * delegation call. Unit tests drive these functions with a stub delegate.
14
+ */
15
+ import type { ResolvedConfig } from "./types.js";
16
+ /**
17
+ * Native `/goal` objective limit. Counts JS `text.length` (UTF-16 code
18
+ * units) — confirmed by the Phase 0 spike against core `goal.ts`
19
+ * (`MAX_OBJECTIVE = 4_000`), not bytes or grapheme clusters.
20
+ */
21
+ export declare const NATIVE_GOAL_LIMIT = 4000;
22
+ /**
23
+ * Verification addendum appended to the objective (plan §3.2). The addendum
24
+ * length in limit accounting is computed from this exact string at
25
+ * delegation time, never from a hardcoded constant.
26
+ */
27
+ export declare const VERIFICATION_ADDENDUM = "Verification contract added by opencode-dev-framework:\n\nBefore declaring this goal complete, run dev_framework_verify after your final changes. A FAIL result means the goal is incomplete: fix the underlying cause and run verification again. Any later edit invalidates an earlier verification result. PASS is required but does not replace the original objective or its acceptance criteria. Do not disable, skip, or weaken the configured checks to obtain PASS.";
28
+ export type GoalBuildResult = {
29
+ ok: true;
30
+ text: string;
31
+ alreadyWrapped: boolean;
32
+ } | {
33
+ ok: false;
34
+ error: string;
35
+ };
36
+ /**
37
+ * Append the verification addendum to the objective without rewriting the
38
+ * user's text. An objective that already contains the addendum is used
39
+ * verbatim (never double-wrapped on retry). The complete string counts
40
+ * toward the native limit; overflow is rejected with lengths, never
41
+ * silently truncated.
42
+ */
43
+ export declare function buildVerifiedObjective(objective: string): GoalBuildResult;
44
+ export type GoalAvailability = {
45
+ ok: true;
46
+ } | {
47
+ ok: false;
48
+ error: string;
49
+ };
50
+ /**
51
+ * Availability/profile/meaningful-check rules (plan §3.3). `/df-goal` means
52
+ * verified goal, not an alias for `/goal`: every failure names the exact
53
+ * cause and points at the alternatives (enable a blocking profile or use
54
+ * native `/goal` directly for an unverified objective).
55
+ */
56
+ export declare function checkGoalAvailability(config: ResolvedConfig, nativeGoalAvailable: boolean): GoalAvailability;
57
+ /** Single delegation call to native `/goal` (flat core protocol shape). */
58
+ export type GoalDelegate = (args: {
59
+ sessionID: string;
60
+ name: string;
61
+ text: string;
62
+ }) => Promise<unknown>;
63
+ export interface RunGoalDeps {
64
+ config: ResolvedConfig;
65
+ /** Raw objective text from the command invocation. */
66
+ objective: string;
67
+ sessionID: string;
68
+ nativeGoalAvailable: boolean;
69
+ delegate: GoalDelegate;
70
+ }
71
+ export type RunGoalResult = {
72
+ delegated: true;
73
+ text: string;
74
+ alreadyWrapped: boolean;
75
+ } | {
76
+ delegated: false;
77
+ error: string;
78
+ };
79
+ /**
80
+ * Validate, wrap, and delegate exactly once. Native delegation errors
81
+ * propagate untouched — never an unverified fallback. The wrapper itself
82
+ * admits no kickoff synthetic message.
83
+ */
84
+ export declare function runGoalCommand(deps: RunGoalDeps): Promise<RunGoalResult>;
85
+ /**
86
+ * Extract the raw objective from a command invocation prompt. The
87
+ * invocation prompt is a `Prompt` struct (`{ text, ... }`); accept a bare
88
+ * string defensively and fall back to empty (rejected downstream as an
89
+ * empty objective) for anything else.
90
+ */
91
+ export declare function extractObjectiveText(prompt: unknown): string;
92
+ /**
93
+ * Capability probe over `command.list()` output: true when an entry named
94
+ * `goal` is present. The real output shape is `{ location, data: [...] }`
95
+ * (`CommandListOutput`); a bare array is tolerated for forward
96
+ * compatibility. Defensive throughout (SDK codegen drifts; core is truth) —
97
+ * anything unrecognized means unavailable, never an assumed capability.
98
+ */
99
+ export declare function isNativeGoalListed(listed: unknown): boolean;
package/dist/goal.js ADDED
@@ -0,0 +1,175 @@
1
+ /**
2
+ * `/df-goal`: verified-goal wrapper around native `/goal`.
3
+ *
4
+ * A thin adapter, not a second goal engine: it validates that verified-goal
5
+ * mode is meaningful and available (§3.3), appends the framework verification
6
+ * addendum to the user's objective verbatim (§3.2), and delegates exactly
7
+ * once to native `/goal` via `session.command`. Native `/goal` keeps owning
8
+ * kickoff, state, reviewer, pause/resume/clear, and continuations; the
9
+ * framework's idle gate stays the independent deterministic backstop.
10
+ *
11
+ * All policy here is pure (input -> data, no session I/O): `src/index.ts`
12
+ * owns the `ctx.command.transform` registration, capability probing, and
13
+ * delegation call. Unit tests drive these functions with a stub delegate.
14
+ */
15
+ import { hasMeaningfulChecks } from "./config.js";
16
+ /**
17
+ * Native `/goal` objective limit. Counts JS `text.length` (UTF-16 code
18
+ * units) — confirmed by the Phase 0 spike against core `goal.ts`
19
+ * (`MAX_OBJECTIVE = 4_000`), not bytes or grapheme clusters.
20
+ */
21
+ export const NATIVE_GOAL_LIMIT = 4000;
22
+ /**
23
+ * Verification addendum appended to the objective (plan §3.2). The addendum
24
+ * length in limit accounting is computed from this exact string at
25
+ * delegation time, never from a hardcoded constant.
26
+ */
27
+ export const VERIFICATION_ADDENDUM = `Verification contract added by opencode-dev-framework:
28
+
29
+ Before declaring this goal complete, run dev_framework_verify after your final changes. A FAIL result means the goal is incomplete: fix the underlying cause and run verification again. Any later edit invalidates an earlier verification result. PASS is required but does not replace the original objective or its acceptance criteria. Do not disable, skip, or weaken the configured checks to obtain PASS.`;
30
+ /** Separator between the verbatim objective and the addendum. */
31
+ const OBJECTIVE_SEPARATOR = "\n\n";
32
+ /**
33
+ * Append the verification addendum to the objective without rewriting the
34
+ * user's text. An objective that already contains the addendum is used
35
+ * verbatim (never double-wrapped on retry). The complete string counts
36
+ * toward the native limit; overflow is rejected with lengths, never
37
+ * silently truncated.
38
+ */
39
+ export function buildVerifiedObjective(objective) {
40
+ if (objective.trim().length === 0) {
41
+ return {
42
+ ok: false,
43
+ error: "Cannot start a verified goal: the objective is empty. " +
44
+ "Provide an objective, e.g. /df-goal <objective>.",
45
+ };
46
+ }
47
+ if (objective.includes(VERIFICATION_ADDENDUM)) {
48
+ // Already wrapped (e.g. a retry of wrapper output): idempotent, but the
49
+ // combined text still counts toward the native limit. Report the single
50
+ // combined length — the addendum is inside, not additive.
51
+ if (objective.length > NATIVE_GOAL_LIMIT) {
52
+ return {
53
+ ok: false,
54
+ error: `Cannot start a verified goal: objective including the previously appended ` +
55
+ `verification addendum is ${objective.length} characters, exceeding the native ` +
56
+ `/goal limit of ${NATIVE_GOAL_LIMIT} characters. Shorten the objective by at ` +
57
+ `least ${objective.length - NATIVE_GOAL_LIMIT} characters; the addendum is never truncated.`,
58
+ };
59
+ }
60
+ return { ok: true, text: objective, alreadyWrapped: true };
61
+ }
62
+ const text = `${objective}${OBJECTIVE_SEPARATOR}${VERIFICATION_ADDENDUM}`;
63
+ // Same unit native uses: JS string length (UTF-16 code units).
64
+ if (text.length > NATIVE_GOAL_LIMIT) {
65
+ return {
66
+ ok: false,
67
+ error: `Cannot start a verified goal: objective is ${objective.length} characters, ` +
68
+ `the verification addendum adds ${VERIFICATION_ADDENDUM.length} characters plus a ` +
69
+ `blank-line separator, total ${text.length} exceeds the native /goal limit of ` +
70
+ `${NATIVE_GOAL_LIMIT} characters. ` +
71
+ `Shorten the objective; the addendum is never truncated.`,
72
+ };
73
+ }
74
+ return { ok: true, text, alreadyWrapped: false };
75
+ }
76
+ /**
77
+ * Availability/profile/meaningful-check rules (plan §3.3). `/df-goal` means
78
+ * verified goal, not an alias for `/goal`: every failure names the exact
79
+ * cause and points at the alternatives (enable a blocking profile or use
80
+ * native `/goal` directly for an unverified objective).
81
+ */
82
+ export function checkGoalAvailability(config, nativeGoalAvailable) {
83
+ if (!nativeGoalAvailable) {
84
+ return {
85
+ ok: false,
86
+ error: "Cannot start a verified goal: native /goal is not available on this core. " +
87
+ "Upgrade OpenCode to a build containing native /goal, or run the objective " +
88
+ "without verification where native /goal exists.",
89
+ };
90
+ }
91
+ if (config.profile === "off") {
92
+ return {
93
+ ok: false,
94
+ error: 'Cannot start a verified goal: profile is "off", so verification would be vacuous. ' +
95
+ "Enable a blocking profile (standard or strict), or use native /goal directly " +
96
+ "for an unverified objective.",
97
+ };
98
+ }
99
+ if (!config.gate?.block_on_failure) {
100
+ const found = config.gate?.block_on_failure;
101
+ return {
102
+ ok: false,
103
+ error: `Cannot start a verified goal: gate.block_on_failure is ${String(found)}, ` +
104
+ "but /df-goal requires it to be true. Advisory mode must not gain a blocking " +
105
+ "side channel through /df-goal. Enable a blocking profile (standard or strict), " +
106
+ "or use native /goal directly.",
107
+ };
108
+ }
109
+ if (!hasMeaningfulChecks(config)) {
110
+ return {
111
+ ok: false,
112
+ error: "Cannot start a verified goal: the resolved configuration provides no meaningful " +
113
+ "completion check (no typecheck/test command, no changed-file lint, no acceptance " +
114
+ "commands, and no review requirement). Configure at least one check, or use native " +
115
+ "/goal directly for a purely semantic objective.",
116
+ };
117
+ }
118
+ return { ok: true };
119
+ }
120
+ /**
121
+ * Validate, wrap, and delegate exactly once. Native delegation errors
122
+ * propagate untouched — never an unverified fallback. The wrapper itself
123
+ * admits no kickoff synthetic message.
124
+ */
125
+ export async function runGoalCommand(deps) {
126
+ const availability = checkGoalAvailability(deps.config, deps.nativeGoalAvailable);
127
+ if (!availability.ok) {
128
+ return { delegated: false, error: availability.error };
129
+ }
130
+ const built = buildVerifiedObjective(deps.objective);
131
+ if (!built.ok) {
132
+ return { delegated: false, error: built.error };
133
+ }
134
+ await deps.delegate({ sessionID: deps.sessionID, name: "goal", text: built.text });
135
+ return { delegated: true, text: built.text, alreadyWrapped: built.alreadyWrapped };
136
+ }
137
+ /**
138
+ * Extract the raw objective from a command invocation prompt. The
139
+ * invocation prompt is a `Prompt` struct (`{ text, ... }`); accept a bare
140
+ * string defensively and fall back to empty (rejected downstream as an
141
+ * empty objective) for anything else.
142
+ */
143
+ export function extractObjectiveText(prompt) {
144
+ if (typeof prompt === "string")
145
+ return prompt;
146
+ if (prompt !== null && typeof prompt === "object") {
147
+ const text = prompt.text;
148
+ if (typeof text === "string")
149
+ return text;
150
+ }
151
+ return "";
152
+ }
153
+ /**
154
+ * Capability probe over `command.list()` output: true when an entry named
155
+ * `goal` is present. The real output shape is `{ location, data: [...] }`
156
+ * (`CommandListOutput`); a bare array is tolerated for forward
157
+ * compatibility. Defensive throughout (SDK codegen drifts; core is truth) —
158
+ * anything unrecognized means unavailable, never an assumed capability.
159
+ */
160
+ export function isNativeGoalListed(listed) {
161
+ const entries = unwrapCommandEntries(listed);
162
+ if (entries === null)
163
+ return false;
164
+ return entries.some((entry) => entry !== null && typeof entry === "object" && entry.name === "goal");
165
+ }
166
+ function unwrapCommandEntries(listed) {
167
+ if (Array.isArray(listed))
168
+ return listed;
169
+ if (listed !== null && typeof listed === "object") {
170
+ const data = listed.data;
171
+ if (Array.isArray(data))
172
+ return data;
173
+ }
174
+ return null;
175
+ }
package/dist/harness.d.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  * synthetic continuation) and the `session.idle` event net (re-prompt).
18
18
  */
19
19
  import type { BlockStore } from "./block-store.js";
20
- import { type ChangedFileTracker } from "./gate.js";
20
+ import { type ChangedFileTracker, type GateReport } from "./gate.js";
21
21
  import type { RunCommand } from "./host.js";
22
22
  import type { LogFn } from "./logger.js";
23
23
  import type { ResolvedConfig } from "./types.js";
@@ -80,6 +80,45 @@ export interface CompletionDeps {
80
80
  blockCounts: BlockStore;
81
81
  log: LogFn;
82
82
  }
83
+ /**
84
+ * Side-effect-free inputs for a completion inspection. The tracker file
85
+ * list is a read-only snapshot: inspection never clears it, never touches
86
+ * block counts, and never admits input — those are policy decisions owned
87
+ * by `evaluateCompletion`.
88
+ */
89
+ export interface InspectionDeps {
90
+ run: RunCommand;
91
+ config: ResolvedConfig;
92
+ directory: string;
93
+ /** Read-only snapshot of tracker files; never mutated. */
94
+ trackerFiles: string[];
95
+ }
96
+ /**
97
+ * Raw completion report. `ok` is the unadjudicated outcome (gate passed and
98
+ * review satisfied); profiles, block counting, and stand-down are applied by
99
+ * `evaluateCompletion`, and `verifyGate` reports `ok` verbatim as its
100
+ * PASS/FAIL verdict.
101
+ */
102
+ export interface CompletionInspection {
103
+ changedFiles: string[];
104
+ report: GateReport;
105
+ reviewRequired: boolean;
106
+ reviewState: ArtifactState;
107
+ reviewMissing: boolean;
108
+ /** True when the gate short-circuited on `skip_unchanged` with no files. */
109
+ skipped: boolean;
110
+ /** Raw outcome: gate ok AND review satisfied. No profile/policy applied. */
111
+ ok: boolean;
112
+ /** Human- and transcript-readable summary (gate detail or review notice). */
113
+ summary: string;
114
+ }
115
+ /**
116
+ * Inspect the current completion state without mutating anything: no
117
+ * tracker clearing, no block-count changes, no logging, no input admitted.
118
+ * Both the idle policy (`evaluateCompletion`) and manual verification
119
+ * (`verifyGate`) read from here so they evaluate the same full contract.
120
+ */
121
+ export declare function inspectCompletion(deps: InspectionDeps): Promise<CompletionInspection>;
83
122
  /**
84
123
  * Evaluate the completion gate + review requirement and update block state.
85
124
  * Pure orchestration: both the `experimental.idle` hook and the
package/dist/harness.js CHANGED
@@ -123,21 +123,42 @@ function reviewMissingMessage(changedFiles) {
123
123
  `Investigation-only reviewers: do not ask them to edit product code.`);
124
124
  }
125
125
  /**
126
- * Evaluate the completion gate + review requirement and update block state.
127
- * Pure orchestration: both the `experimental.idle` hook and the
128
- * `session.idle` event net feed their outcome from here so one session's
129
- * block count applies to either lever.
126
+ * Inspect the current completion state without mutating anything: no
127
+ * tracker clearing, no block-count changes, no logging, no input admitted.
128
+ * Both the idle policy (`evaluateCompletion`) and manual verification
129
+ * (`verifyGate`) read from here so they evaluate the same full contract.
130
130
  */
131
- export async function evaluateCompletion(deps) {
132
- const { run, config, directory, sessionID, tracker, blockCounts } = deps;
131
+ export async function inspectCompletion(deps) {
132
+ const { run, config, directory, trackerFiles } = deps;
133
+ const disabled = {
134
+ changedFiles: [],
135
+ report: {
136
+ ran: false,
137
+ reason: "completion gate disabled",
138
+ steps: [],
139
+ ok: true,
140
+ failedSteps: [],
141
+ },
142
+ reviewRequired: false,
143
+ reviewState: "present",
144
+ reviewMissing: false,
145
+ skipped: false,
146
+ ok: true,
147
+ summary: "completion gate disabled (profile off or no gate section)",
148
+ };
133
149
  if (config.profile === "off" || !config.gate) {
134
- return { decision: "pass", changedFiles: [] };
150
+ return disabled;
135
151
  }
136
- const trackerFiles = tracker.getChangedFiles();
137
152
  const gitFiles = await gitChangedFiles(run, directory);
138
153
  const changedFiles = mergeChangedFiles(trackerFiles, gitFiles);
139
154
  if (config.gate.skip_unchanged && changedFiles.length === 0) {
140
- return { decision: "pass", changedFiles, note: "completion gate skipped: no changed files" };
155
+ return {
156
+ ...disabled,
157
+ changedFiles,
158
+ report: { ran: false, reason: "no changed files", steps: [], ok: true, failedSteps: [] },
159
+ skipped: true,
160
+ summary: "completion gate skipped: no changed files",
161
+ };
141
162
  }
142
163
  const report = await runGate(run, config, changedFiles, { cwd: directory });
143
164
  const gateFailed = report.ran && !report.ok;
@@ -146,18 +167,59 @@ export async function evaluateCompletion(deps) {
146
167
  ? await artifactState(directory, REVIEW_ARTIFACT_REL)
147
168
  : "present";
148
169
  const reviewMissing = reviewRequired && reviewState !== "present";
170
+ const ok = !gateFailed && !reviewMissing;
171
+ const summary = gateFailed
172
+ ? summarizeGate(report)
173
+ : reviewMissing
174
+ ? reviewMissingMessage(changedFiles)
175
+ : report.ran
176
+ ? `completion gate passed\n${summarizeGate(report)}`
177
+ : `completion gate passed (${report.reason ?? "nothing to run"})`;
178
+ return {
179
+ changedFiles,
180
+ report,
181
+ reviewRequired,
182
+ reviewState,
183
+ reviewMissing,
184
+ skipped: false,
185
+ ok,
186
+ summary,
187
+ };
188
+ }
189
+ /**
190
+ * Evaluate the completion gate + review requirement and update block state.
191
+ * Pure orchestration: both the `experimental.idle` hook and the
192
+ * `session.idle` event net feed their outcome from here so one session's
193
+ * block count applies to either lever.
194
+ */
195
+ export async function evaluateCompletion(deps) {
196
+ const { run, config, directory, sessionID, tracker, blockCounts } = deps;
197
+ if (config.profile === "off" || !config.gate) {
198
+ return { decision: "pass", changedFiles: [] };
199
+ }
200
+ const inspection = await inspectCompletion({
201
+ run,
202
+ config,
203
+ directory,
204
+ trackerFiles: tracker.getChangedFiles(),
205
+ });
206
+ const { changedFiles, report } = inspection;
207
+ const gateFailed = report.ran && !report.ok;
208
+ const reviewMissing = inspection.reviewMissing;
149
209
  if (!gateFailed && !reviewMissing) {
150
210
  tracker.clearChangedFiles();
151
211
  await blockCounts.clear(sessionID);
152
212
  return {
153
213
  decision: "pass",
154
214
  changedFiles,
155
- note: report.ran ? `completion gate passed\n${summarizeGate(report)}` : undefined,
215
+ // Preserve the historical note shape: detailed on run, skip note on
216
+ // skip, absent when the gate never ran for any other reason.
217
+ note: report.ran || inspection.skipped ? inspection.summary : undefined,
156
218
  };
157
219
  }
158
220
  // Advisory: report loudly, never block.
159
221
  if (!config.gate.block_on_failure) {
160
- const summary = gateFailed ? summarizeGate(report) : reviewMissingMessage(changedFiles);
222
+ const summary = inspection.summary;
161
223
  await deps.log("error", `completion gate (advisory — not blocking) saw problems:\n${summary}`);
162
224
  return {
163
225
  decision: "pass",
@@ -166,7 +228,7 @@ export async function evaluateCompletion(deps) {
166
228
  };
167
229
  }
168
230
  const reason = gateFailed ? "gate" : "review";
169
- const summary = gateFailed ? summarizeGate(report) : reviewMissingMessage(changedFiles);
231
+ const summary = inspection.summary;
170
232
  const maxBlocks = config.gate.max_blocks ?? 3;
171
233
  const blockCount = await blockCounts.increment(sessionID);
172
234
  if (blockCount > maxBlocks) {
package/dist/index.d.ts CHANGED
@@ -10,6 +10,8 @@
10
10
  * (`filesystem.changed` stays as a fallback this release; see Phase 24)
11
11
  * - ctx.event.subscribe() -> file tracking + gate enforcement via re-prompt
12
12
  * - ctx.tool.transform(...) -> custom tools
13
+ * - ctx.command.transform(...) -> server-side `/df-goal` verified-goal
14
+ * wrapper (thin adapter delegating to native `/goal`; see src/goal.ts)
13
15
  *
14
16
  * Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
15
17
  * (same execution) we run the gate and if it fails inside budget we admit
package/dist/index.js CHANGED
@@ -10,6 +10,8 @@
10
10
  * (`filesystem.changed` stays as a fallback this release; see Phase 24)
11
11
  * - ctx.event.subscribe() -> file tracking + gate enforcement via re-prompt
12
12
  * - ctx.tool.transform(...) -> custom tools
13
+ * - ctx.command.transform(...) -> server-side `/df-goal` verified-goal
14
+ * wrapper (thin adapter delegating to native `/goal`; see src/goal.ts)
13
15
  *
14
16
  * Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
15
17
  * (same execution) we run the gate and if it fails inside budget we admit
@@ -685,7 +687,7 @@ const plugin = Plugin.define({
685
687
  });
686
688
  editor.add({
687
689
  name: "dev_framework_verify",
688
- description: "Run the opencode-dev-framework completion gate now (typecheck, tests, changed-file lint) and return the summary. Use for a mid-session gate check without waiting for session idle; unlike the idle gate this never re-prompts, it only reports.",
690
+ description: "Run the full opencode-dev-framework completion contract now (typecheck, tests, changed-file lint, peer-review state) and return the summary. The first line is DEV_FRAMEWORK_VERDICT: PASS or FAIL, reporting the raw inspection outcome. Use for a mid-session gate check without waiting for session idle; unlike the idle gate this never re-prompts, it only reports, and it never mutates retry state.",
689
691
  input: {
690
692
  type: "object",
691
693
  properties: {
@@ -738,6 +740,51 @@ const plugin = Plugin.define({
738
740
  },
739
741
  });
740
742
  }));
743
+ // 3b) Verified-goal wrapper — server-side `/df-goal` through
744
+ // `ctx.command.transform` (see src/goal.ts for the pure policy). Thin
745
+ // adapter around native `/goal`: probes native capability, checks
746
+ // availability/profile/meaningful-checks, appends the verification
747
+ // addendum verbatim, and delegates exactly once via the flat core
748
+ // `session.command` shape. Defensive like the permission hook: on a
749
+ // core without the command API the wrapper is skipped with a warning
750
+ // and every other layer keeps working.
751
+ try {
752
+ trackRegistration(await ctx.command.transform((editor) => {
753
+ editor.add({
754
+ name: "df-goal",
755
+ description: "Start a verified native goal: appends a dev_framework_verify contract to the objective and delegates to native /goal exactly once. Requires native /goal, a blocking profile, and at least one configured completion check.",
756
+ execute: async (invocation) => {
757
+ if (activeState !== state)
758
+ return;
759
+ await reloadConfigIfChanged(state);
760
+ const { extractObjectiveText, isNativeGoalListed, runGoalCommand } = await import("./goal.js");
761
+ let nativeGoalAvailable = false;
762
+ try {
763
+ nativeGoalAvailable = isNativeGoalListed(await ctx.command.list());
764
+ }
765
+ catch {
766
+ nativeGoalAvailable = false;
767
+ }
768
+ const sessionCommand = ctx.session.command;
769
+ const result = await runGoalCommand({
770
+ config: state.config,
771
+ objective: extractObjectiveText(invocation.prompt),
772
+ sessionID: invocation.sessionID,
773
+ nativeGoalAvailable,
774
+ delegate: (args) => sessionCommand(args),
775
+ });
776
+ if (!result.delegated) {
777
+ throw new Error(result.error);
778
+ }
779
+ },
780
+ });
781
+ }));
782
+ }
783
+ catch (err) {
784
+ await safeLog(state, "warn", "could not register df-goal command; verified goals unavailable", {
785
+ error: String(err),
786
+ });
787
+ }
741
788
  // 4) Event subscription — file tracking + gate enforcement net.
742
789
  // Runs the gate on `session.idle` for the boundaries the §1b hook
743
790
  // skipped (interruption, failure, steer-parked drains) or for builds
package/dist/types.d.ts CHANGED
@@ -18,6 +18,19 @@ export interface CommandsConfig {
18
18
  lint?: CommandMap;
19
19
  test_changed?: string;
20
20
  }
21
+ /**
22
+ * A named project-specific acceptance check, run by the gate after the
23
+ * built-in steps. Sequential in declaration order; every step runs even
24
+ * when an earlier one fails (same aggregation as the rest of `runGate`).
25
+ */
26
+ export interface AcceptanceCheck {
27
+ /** Unique, non-empty step name. Reported as `acceptance:<name>`. */
28
+ name: string;
29
+ /** Command template. Supports the same `{files}` substitution as tests. */
30
+ command: string;
31
+ /** Per-check timeout in seconds. Falls back to `gate.timeout`, then default. */
32
+ timeout?: number;
33
+ }
21
34
  export interface GateConfig {
22
35
  run_typecheck: boolean;
23
36
  run_tests: boolean;
@@ -34,6 +47,11 @@ export interface GateConfig {
34
47
  * also produce a peer-review artifact before the completion gate passes.
35
48
  */
36
49
  require_review: boolean;
50
+ /**
51
+ * Named project-specific acceptance checks (`acceptance:<name>` steps).
52
+ * Empty by default; run after the built-in gate steps, sequentially.
53
+ */
54
+ acceptance: AcceptanceCheck[];
37
55
  /** Per-command timeout in seconds. */
38
56
  timeout?: number;
39
57
  /** Maximum number of times a failing gate may re-block before standing down. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "0.5.1",
3
+ "version": "1.0.0",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,6 +29,12 @@ A task is done only when:
29
29
  - The change matches existing patterns in the surrounding code (see
30
30
  `20-match-existing-patterns`).
31
31
  - A peer-review pass found no blocking issues (see `40-delegation`).
32
+ - If the task came from a written plan, you re-read the plan and verified every
33
+ requirement was implemented — fix gaps rather than declaring success.
34
+ - Any required review artifact describes THIS session's changes. Never reuse a
35
+ review file left over from a previous task; rewrite it fresh every time.
36
+ - You ran the project's full verification yourself (not just the completion
37
+ gate) and read the output — the gate is a backstop, not your test run.
32
38
 
33
39
  If you cannot meet the bar, stop and tell the user what is blocking you rather than
34
40
  declaring success.
@@ -15,7 +15,12 @@ plausible-sounding assertions. Running code is the source of truth.
15
15
  concrete command), then fix it, then show the same check now passes.
16
16
  4. **Run the narrowest useful check often, the full suite before done.** Iterate with
17
17
  targeted tests for speed; the completion gate will run the broader suite.
18
- 5. **Read the actual output.** Don't pattern-match on exit codes — read failures and
18
+ Do not treat the gate as your test run — run the full verification yourself
19
+ before finishing, and read the output.
20
+ 5. **A stale PASS is not evidence.** Any further product edit after a passing run
21
+ invalidates it. Re-run the checks on the final tree; never present an earlier
22
+ PASS as covering later changes.
23
+ 6. **Read the actual output.** Don't pattern-match on exit codes — read failures and
19
24
  address the real cause. Treat a flaky or skipped test as a finding, not a pass.
20
25
 
21
26
  ## Use existing tooling only
@@ -37,7 +37,14 @@ before completion.
37
37
  3. **After a batch of edits** → `style-enforcer` on the changed files.
38
38
  4. **Before declaring done** → `test-grounder` (evidence) and a final
39
39
  `pattern-guardian` / review pass; resolve every blocking item.
40
-
40
+ 5. **Write the review artifact fresh, every task.** When the completion gate
41
+ requires a review file, rewrite it for THIS session's changes — scope,
42
+ findings, and resolutions. A file left over from a previous task never
43
+ counts, even if it exists and is non-empty.
44
+
45
+ This cadence is the default working loop, not an opt-in. For a non-trivial
46
+ change you plan first, implement from the plan without expanding scope, then
47
+ harden (full verification + review + fresh artifact) before declaring done.
41
48
  Keep delegation proportional: a one-line fix doesn't need the full loop; a new module
42
49
  does. Use judgment, but never skip the test-grounding and review steps for behavioral
43
50
  changes. If the specialist agents are not installed in this project, perform the same