opencode-dev-framework 0.5.0 → 0.5.1

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
@@ -167,7 +167,7 @@ commands:
167
167
  typecheck: "go build ./..."
168
168
  test: "go test ./..."
169
169
  lint:
170
- ".go": "golangci-lint run {file}"
170
+ ".go": "golangci-lint run {dir}"
171
171
 
172
172
  protect:
173
173
  - ".env*"
@@ -212,12 +212,16 @@ complete example.
212
212
 
213
213
  ## Slash commands
214
214
 
215
- All four slash commands are **TUI commands** registered by the bundled `./tui`
215
+ All five slash commands are **TUI commands** registered by the bundled `./tui`
216
216
  companion module (see *Local development* above for the `tui.json` requirement).
217
217
  They open instantly and **never** feed text back to the LLM:
218
218
 
219
219
  - `/df-status` — shows the current profile, guardrails, completion gate, and
220
220
  configured commands in a modal dialog.
221
+ - `/df-runtime` — shows the plugin version and live hook/gate runtime state
222
+ (which idle-hook method the core accepted, dispatch history) in a modal
223
+ dialog. Read from a snapshot the server writes per project; reports
224
+ "not reported yet" before the first session instead of guessing.
221
225
  - `/df-help` — lists the available dev-framework commands in a modal dialog.
222
226
  - `/df-profile` — opens a profile picker (off / advisory / standard / strict) in
223
227
  a modal dialog; selecting one switches the active profile immediately (written
@@ -244,16 +248,19 @@ itself).
244
248
  hook only the net applies. `/df-status` shows which lever completed an
245
249
  evaluation (`Continuation (idle): active` vs the event-subscribe fallback).
246
250
  The user can always close the session, so treat the gate
247
- as the strongest available enforcement, not an unbreakable lock. The **pre-flight**
251
+ as the strongest available enforcement, not an unbreakable lock. The missing piece — a pre-terminal vote hook — is proposed upstream ([`anomalyco/opencode#54487`](https://github.com/anomalyco/opencode/pull/54487), open); until it lands, the above is the enforcement story. The **pre-flight**
248
252
  gate, by contrast, is a genuine hard block on every build: it denies edit tools in
249
253
  `tool.execute.before`, before the edit lands.
250
254
  - **Guardrails run inside OpenCode.** The `tool.execute.before` hook runs
251
255
  after OpenCode's own permission system; it adds project rules on top, it
252
256
  does not replace OpenCode permissions.
253
257
  - **Formatting and linting are delegated.** The plugin does not reimplement
254
- formatters or linters; you declare your formatter and linter commands in
258
+ formatters or linters; you declare your linter commands in
255
259
  `.opencode-dev-framework.yml` and the plugin runs them on edited files and
256
- at the completion gate. It does not automatically rewrite `opencode.json`
260
+ at the completion gate. Formatting is OpenCode core's job (`formatter` in
261
+ `opencode.json`, off by default) — the plugin's `commands.format` /
262
+ `on_edit.format` are accepted but ignored, deliberately not duplicated.
263
+ The plugin does not automatically rewrite `opencode.json`
257
264
  formatter/permission fragments.
258
265
 
259
266
  ## Development
package/dist/detect.js CHANGED
@@ -81,7 +81,7 @@ export function detectProject(directory) {
81
81
  result.commands.test = "go test ./...";
82
82
  result.commands.typecheck = "go build ./...";
83
83
  result.commands.format = "gofumpt -w {file}";
84
- result.commands.lint = "golangci-lint run {file}";
84
+ result.commands.lint = "golangci-lint run {dir}";
85
85
  return result;
86
86
  }
87
87
  if (has.pyProject || has.requirements) {
@@ -1,4 +1,5 @@
1
1
  import type { HookState } from "./registry.js";
2
+ import type { RuntimeStatus } from "./runtime-status.js";
2
3
  import type { ResolvedConfig } from "./types.js";
3
4
  /**
4
5
  * Render the config-only portion of the status summary.
@@ -18,3 +19,10 @@ export declare function renderHelp(): string;
18
19
  * slash-command handler.
19
20
  */
20
21
  export declare function renderStatus(config: ResolvedConfig, state?: HookState | null): string;
22
+ /**
23
+ * Render the runtime snapshot for the TUI `/df-runtime` command: plugin
24
+ * version, which session-hook method the core accepted, and dispatch
25
+ * history. A null snapshot (server hasn't reported yet) renders as such —
26
+ * never as a negative claim about the hook.
27
+ */
28
+ export declare function renderRuntimeStatus(snapshot: RuntimeStatus | null): string;
@@ -54,7 +54,7 @@ export function renderConfigStatus(config) {
54
54
  }
55
55
  lines.push("");
56
56
  lines.push("On edit:");
57
- lines.push(` format: ${config.on_edit.format}`);
57
+ lines.push(` format: ${config.on_edit.format} (ignored — formatting is OpenCode core's job)`);
58
58
  lines.push(` lint: ${config.on_edit.lint}`);
59
59
  lines.push(` precommit: ${config.precommit}`);
60
60
  lines.push("");
@@ -90,7 +90,7 @@ export function renderConfigStatus(config) {
90
90
  lines.push(config.commands.test_changed ? ` ${config.commands.test_changed}` : " (not configured)");
91
91
  lines.push(" lint:");
92
92
  lines.push(formatCommandMap(config.commands.lint, " "));
93
- lines.push(" format:");
93
+ lines.push(" format: (ignored — formatting is OpenCode core's job)");
94
94
  lines.push(formatCommandMap(config.commands.format, " "));
95
95
  lines.push("");
96
96
  lines.push("Constitution rules:");
@@ -111,6 +111,7 @@ export function renderHelp() {
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
113
  lines.push("/df-help Show this message");
114
+ lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
114
115
  return lines.join("\n");
115
116
  }
116
117
  /**
@@ -153,3 +154,31 @@ export function renderStatus(config, state) {
153
154
  }
154
155
  return lines.join("\n");
155
156
  }
157
+ /**
158
+ * Render the runtime snapshot for the TUI `/df-runtime` command: plugin
159
+ * version, which session-hook method the core accepted, and dispatch
160
+ * history. A null snapshot (server hasn't reported yet) renders as such —
161
+ * never as a negative claim about the hook.
162
+ */
163
+ export function renderRuntimeStatus(snapshot) {
164
+ const lines = ["dev-framework runtime", ""];
165
+ if (snapshot === null) {
166
+ lines.push("No runtime snapshot reported yet — open a session in this");
167
+ lines.push("project so the server plugin can record hook state.");
168
+ return lines.join("\n");
169
+ }
170
+ lines.push(`Framework: v${snapshot.frameworkVersion} (snapshot as of ${snapshot.updatedAt})`);
171
+ lines.push(snapshot.idleHookVia === "none"
172
+ ? "Idle hook: not registered — event-subscribe fallback only"
173
+ : `Idle hook: registered via ${snapshot.idleHookVia}`);
174
+ if (snapshot.continuation === "idle") {
175
+ lines.push("Continuation: active — gate failures continue the same execution");
176
+ }
177
+ else if (snapshot.continuation === "fallback") {
178
+ lines.push("Continuation: event-subscribe fallback fired for a skipped boundary");
179
+ }
180
+ else {
181
+ lines.push("Continuation: armed — registered, not yet dispatched");
182
+ }
183
+ return lines.join("\n");
184
+ }
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ import { lintFile, detectPreCommitAvailability, isLintFailure, summarizeLint } f
30
30
  import { createLogger } from "./logger.js";
31
31
  import { checkToolCall, extractFilePath, FILE_TOOLS, toPermissionGuard } from "./protect.js";
32
32
  import { loadConstitution } from "./rules.js";
33
+ import { writeRuntimeStatus } from "./runtime-status.js";
33
34
  let activeState = null;
34
35
  let fallbackLog = async () => { };
35
36
  function safeLog(state, level, message, extra) {
@@ -344,6 +345,9 @@ const plugin = Plugin.define({
344
345
  // `prompt` here — only `synthetic` keeps the same execution.
345
346
  // DEFENSIVE: any-cast because the installed @opencode/plugin may predate
346
347
  // the hook; fires only on builds dispatching it.
348
+ // idleHookVia feeds the runtime-status snapshot (`/df-runtime`): which
349
+ // key the core accepted, so the TUI can report the hook method.
350
+ let idleHookVia = "none";
347
351
  const handleIdleContinuation = async (event) => {
348
352
  if (activeState !== state)
349
353
  return;
@@ -381,6 +385,7 @@ const plugin = Plugin.define({
381
385
  // Pass/stand-down: completed evaluation, nothing to admit.
382
386
  stampIdleHandled(state, sessionID);
383
387
  state.continuationLevel = "idle";
388
+ void writeRuntimeStatus(state.directory, { idleHookVia, continuation: "idle" });
384
389
  return;
385
390
  }
386
391
  // Blocked: admit a synthetic continuation (same execution).
@@ -395,6 +400,7 @@ const plugin = Plugin.define({
395
400
  await ctx.session.synthetic({ sessionID, text: message });
396
401
  stampIdleHandled(state, sessionID);
397
402
  state.continuationLevel = "idle";
403
+ void writeRuntimeStatus(state.directory, { idleHookVia, continuation: "idle" });
398
404
  await safeLog(state, "info", `completion gate continued session ${sessionID} via idle hook`, {
399
405
  sessionID,
400
406
  blockCount: verdict.blockCount,
@@ -418,11 +424,16 @@ const plugin = Plugin.define({
418
424
  trackRegistration(
419
425
  // biome-ignore lint/suspicious/noExplicitAny: defensive idle hook, absent from SessionHooks on older cores
420
426
  await ctx.session.hook(name, handleIdleContinuation));
427
+ if (idleHookVia === "none")
428
+ idleHookVia = name;
421
429
  }
422
430
  catch {
423
431
  await safeLog(state, "warn", `could not register session hook ${name}`, { hook: name });
424
432
  }
425
433
  }
434
+ // Record the registration outcome for `/df-runtime` even before the
435
+ // first dispatch: "armed" is a real state, not a missing one.
436
+ void writeRuntimeStatus(state.directory, { idleHookVia, continuation: "armed" });
426
437
  await safeLog(state, "info", "registered experimental.idle hook (+ idle alias); gate failures continue the same execution via synthetic");
427
438
  // 2a) Native permission layer (Phase 25): `permission.evaluate` fires
428
439
  // with `{action, resources, effect}` (shapes recorded in the 25.1 spike,
@@ -795,8 +806,10 @@ const plugin = Plugin.define({
795
806
  if (wasIdleHandledRecently(state, sessionID))
796
807
  continue;
797
808
  const verdict = await runCompletion(state, sessionID);
798
- if (state.continuationLevel === undefined)
809
+ if (state.continuationLevel === undefined) {
799
810
  state.continuationLevel = "fallback";
811
+ void writeRuntimeStatus(state.directory, { idleHookVia, continuation: "fallback" });
812
+ }
800
813
  const message = await actOnVerdict(state, verdict);
801
814
  if (message === null)
802
815
  continue;
package/dist/lint.d.ts CHANGED
@@ -25,9 +25,11 @@ export interface LintOutcome {
25
25
  export declare function matchExclude(config: ResolvedConfig, filePath: string, directory?: string): string | undefined;
26
26
  /**
27
27
  * Resolve the lint command for a file: the per-extension override wins over
28
- * the default command. The `{file}` token is replaced with the file path;
29
- * commands without the token run as-is. Returns undefined when no lint
30
- * command is configured at all.
28
+ * the default command. The `{file}` token is replaced with the file path and
29
+ * `{dir}` with the file's directory (package context for tools like
30
+ * golangci-lint, which cannot typecheck a lone file); commands with neither
31
+ * token run as-is. Returns undefined when no lint command is configured
32
+ * at all.
31
33
  */
32
34
  export declare function resolveLintCommand(config: ResolvedConfig, filePath: string): string[] | undefined;
33
35
  export declare function resolvePreCommitCommand(filePath: string): string[];
package/dist/lint.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * through an injectable command runner. Pure orchestration — the OpenCode
4
4
  * hook wiring lives in src/index.ts.
5
5
  */
6
- import { basename, extname, isAbsolute, relative } from "node:path";
6
+ import { basename, dirname, extname, isAbsolute, relative } from "node:path";
7
7
  import picomatch from "picomatch";
8
8
  import { normalizeCommandMap, splitCommand } from "./command-utils.js";
9
9
  /** Fallback per-lint timeout (seconds) when the config sets none. */
@@ -33,9 +33,11 @@ export function matchExclude(config, filePath, directory) {
33
33
  }
34
34
  /**
35
35
  * Resolve the lint command for a file: the per-extension override wins over
36
- * the default command. The `{file}` token is replaced with the file path;
37
- * commands without the token run as-is. Returns undefined when no lint
38
- * command is configured at all.
36
+ * the default command. The `{file}` token is replaced with the file path and
37
+ * `{dir}` with the file's directory (package context for tools like
38
+ * golangci-lint, which cannot typecheck a lone file); commands with neither
39
+ * token run as-is. Returns undefined when no lint command is configured
40
+ * at all.
39
41
  */
40
42
  export function resolveLintCommand(config, filePath) {
41
43
  const { default: defaultCommand, byExtension } = normalizeCommandMap(config.commands.lint);
@@ -43,7 +45,8 @@ export function resolveLintCommand(config, filePath) {
43
45
  if (template === undefined) {
44
46
  return undefined;
45
47
  }
46
- return splitCommand(template).map((token) => token.replaceAll("{file}", filePath));
48
+ const dir = dirname(filePath);
49
+ return splitCommand(template).map((token) => token.replaceAll("{file}", filePath).replaceAll("{dir}", dir));
47
50
  }
48
51
  export function resolvePreCommitCommand(filePath) {
49
52
  return ["pre-commit", "run", "--files", filePath];
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Runtime status snapshot: the cross-process bridge between the server
3
+ * plugin (which owns hook registration and gate dispatch state) and the
4
+ * TUI plugin (which can only read the project directory).
5
+ *
6
+ * Written best-effort by the server after hook registration and on every
7
+ * continuation dispatch; read by the TUI `/df-runtime` command. Never
8
+ * throws: a missing, corrupt, or stale snapshot renders as
9
+ * "not reported yet".
10
+ */
11
+ /** Snapshot location, relative to the project directory. */
12
+ export declare const RUNTIME_STATUS_DIR = ".opencode/opencode-dev-framework";
13
+ export declare const RUNTIME_STATUS_FILE = "runtime-status.json";
14
+ /** Which session-hook key the core accepted, or neither. */
15
+ export type IdleHookVia = "experimental.idle" | "idle" | "none";
16
+ /** Dispatch history this session: hook-fired, net-fired, or neither yet. */
17
+ export type ContinuationState = "idle" | "fallback" | "armed";
18
+ export interface RuntimeStatus {
19
+ frameworkVersion: string;
20
+ idleHookVia: IdleHookVia;
21
+ continuation: ContinuationState;
22
+ updatedAt: string;
23
+ }
24
+ export declare function snapshotPath(directory: string): string;
25
+ export declare function writeRuntimeStatus(directory: string, partial: {
26
+ idleHookVia: IdleHookVia;
27
+ continuation: ContinuationState;
28
+ }): Promise<void>;
29
+ export declare function readRuntimeStatus(directory: string): Promise<RuntimeStatus | null>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Runtime status snapshot: the cross-process bridge between the server
3
+ * plugin (which owns hook registration and gate dispatch state) and the
4
+ * TUI plugin (which can only read the project directory).
5
+ *
6
+ * Written best-effort by the server after hook registration and on every
7
+ * continuation dispatch; read by the TUI `/df-runtime` command. Never
8
+ * throws: a missing, corrupt, or stale snapshot renders as
9
+ * "not reported yet".
10
+ */
11
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
12
+ import { dirname, join } from "node:path";
13
+ import { fileURLToPath } from "node:url";
14
+ /** Snapshot location, relative to the project directory. */
15
+ export const RUNTIME_STATUS_DIR = ".opencode/opencode-dev-framework";
16
+ export const RUNTIME_STATUS_FILE = "runtime-status.json";
17
+ export function snapshotPath(directory) {
18
+ return join(directory, RUNTIME_STATUS_DIR, RUNTIME_STATUS_FILE);
19
+ }
20
+ /** Resolve the plugin version from the installed package.json. Works from
21
+ * both `dist/` (production) and `src/` (vitest) layouts; "unknown" when
22
+ * neither candidate parses. */
23
+ async function resolveFrameworkVersion() {
24
+ const here = dirname(fileURLToPath(import.meta.url));
25
+ const candidates = [join(here, "..", "package.json"), join(here, "..", "..", "package.json")];
26
+ for (const candidate of candidates) {
27
+ try {
28
+ const pkg = JSON.parse(await readFile(candidate, "utf8"));
29
+ if (pkg.name === "opencode-dev-framework" && typeof pkg.version === "string") {
30
+ return pkg.version;
31
+ }
32
+ }
33
+ catch {
34
+ // try the next candidate
35
+ }
36
+ }
37
+ return "unknown";
38
+ }
39
+ export async function writeRuntimeStatus(directory, partial) {
40
+ try {
41
+ const status = {
42
+ frameworkVersion: await resolveFrameworkVersion(),
43
+ ...partial,
44
+ updatedAt: new Date().toISOString(),
45
+ };
46
+ await mkdir(join(directory, RUNTIME_STATUS_DIR), { recursive: true });
47
+ await writeFile(snapshotPath(directory), `${JSON.stringify(status, null, 2)}\n`, "utf8");
48
+ }
49
+ catch {
50
+ // Best-effort only: runtime reporting must never break the gate.
51
+ }
52
+ }
53
+ function isIdleHookVia(value) {
54
+ return value === "experimental.idle" || value === "idle" || value === "none";
55
+ }
56
+ function isContinuationState(value) {
57
+ return value === "idle" || value === "fallback" || value === "armed";
58
+ }
59
+ export async function readRuntimeStatus(directory) {
60
+ try {
61
+ const parsed = JSON.parse(await readFile(snapshotPath(directory), "utf8"));
62
+ if (typeof parsed.frameworkVersion !== "string" || typeof parsed.updatedAt !== "string") {
63
+ return null;
64
+ }
65
+ return {
66
+ frameworkVersion: parsed.frameworkVersion,
67
+ idleHookVia: isIdleHookVia(parsed.idleHookVia) ? parsed.idleHookVia : "none",
68
+ continuation: isContinuationState(parsed.continuation) ? parsed.continuation : "armed",
69
+ updatedAt: parsed.updatedAt,
70
+ };
71
+ }
72
+ catch {
73
+ return null;
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/tui.tsx CHANGED
@@ -4,7 +4,8 @@ import { Plugin } from "@opencode/plugin/tui";
4
4
  import { changeProfile, verifyGate } from "./dist/commands.js";
5
5
  import { loadConfig } from "./dist/config.js";
6
6
  import { runCommand } from "./dist/host.js";
7
- import { renderConfigStatus, renderHelp } from "./dist/format-status.js";
7
+ import { renderConfigStatus, renderHelp, renderRuntimeStatus } from "./dist/format-status.js";
8
+ import { readRuntimeStatus } from "./dist/runtime-status.js";
8
9
  import type { Profile } from "./dist/types.js";
9
10
 
10
11
  const PROFILES: Profile[] = ["off", "advisory", "standard", "strict"];
@@ -39,10 +40,17 @@ export default Plugin.define({
39
40
  run: () => {
40
41
  const dir = getDirectory();
41
42
  const config = loadConfig(dir);
42
- void ctx.ui.dialog.alert({
43
+ // The dialog title already carries the heading; drop the
44
+ // duplicated first line from the shared text renderer.
45
+ const message = renderConfigStatus(config).split("\n").slice(2).join("\n");
46
+ const shown = ctx.ui.dialog.alert({
43
47
  title: "opencode-dev-framework status",
44
- message: renderConfigStatus(config),
48
+ message,
45
49
  });
50
+ // Presentation is core-owned (alert takes no layout opts);
51
+ // large+centered is the available lever for long content.
52
+ ctx.ui.dialog.set({ size: "large", centered: true });
53
+ void shown;
46
54
  },
47
55
  },
48
56
  {
@@ -92,6 +100,24 @@ export default Plugin.define({
92
100
  }
93
101
  },
94
102
  },
103
+ {
104
+ id: "df-runtime",
105
+ title: "dev-framework runtime",
106
+ description: "Show plugin version and live hook/gate runtime state",
107
+ group: "dev-framework",
108
+ palette: true,
109
+ slash: { name: "df-runtime" },
110
+ run: async () => {
111
+ const dir = getDirectory();
112
+ const snapshot = await readRuntimeStatus(dir);
113
+ const shown = ctx.ui.dialog.alert({
114
+ title: "dev-framework runtime",
115
+ message: renderRuntimeStatus(snapshot),
116
+ });
117
+ ctx.ui.dialog.set({ size: "large", centered: true });
118
+ await shown;
119
+ },
120
+ },
95
121
  {
96
122
  id: "df-verify",
97
123
  title: "dev-framework verify",
@@ -103,10 +129,12 @@ export default Plugin.define({
103
129
  const dir = getDirectory();
104
130
  const config = loadConfig(dir);
105
131
  const { summary, report } = await verifyGate(runCommand, dir, config);
106
- await ctx.ui.dialog.alert({
132
+ const shown = ctx.ui.dialog.alert({
107
133
  title: report.ok ? "dev-framework gate passed" : "dev-framework gate failed",
108
134
  message: summary,
109
135
  });
136
+ ctx.ui.dialog.set({ size: "large", centered: true });
137
+ await shown;
110
138
  ctx.ui.toast.show({ message: summary, variant: report.ok ? "success" : "error" });
111
139
  },
112
140
  },