opencode-dev-framework 1.9.4 → 1.10.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.
Files changed (71) hide show
  1. package/README.md +137 -33
  2. package/bin/df +94 -4
  3. package/cordis.patch.yml +17 -0
  4. package/dist/adapters/dsh/extract.d.ts +47 -0
  5. package/dist/adapters/dsh/extract.js +62 -0
  6. package/dist/adapters/dsh/index.d.ts +332 -0
  7. package/dist/adapters/dsh/index.js +1643 -0
  8. package/dist/adapters/opencode/index.d.ts +30 -0
  9. package/dist/{index.js → adapters/opencode/index.js} +138 -251
  10. package/dist/{block-store.d.ts → core/block-store.d.ts} +10 -3
  11. package/dist/{commands.js → core/commands.js} +4 -2
  12. package/dist/{config.d.ts → core/config.d.ts} +16 -4
  13. package/dist/{config.js → core/config.js} +102 -10
  14. package/dist/{format-status.d.ts → core/format-status.d.ts} +13 -2
  15. package/dist/{format-status.js → core/format-status.js} +30 -7
  16. package/dist/{gate.d.ts → core/gate.d.ts} +9 -1
  17. package/dist/{gate.js → core/gate.js} +14 -2
  18. package/dist/{goal.d.ts → core/goal.d.ts} +4 -3
  19. package/dist/{goal.js → core/goal.js} +4 -3
  20. package/dist/{harness.d.ts → core/harness.d.ts} +10 -5
  21. package/dist/{harness.js → core/harness.js} +119 -32
  22. package/dist/{init.d.ts → core/init.d.ts} +18 -1
  23. package/dist/{init.js → core/init.js} +33 -8
  24. package/dist/core/install-dsh.d.ts +67 -0
  25. package/dist/core/install-dsh.js +235 -0
  26. package/dist/{installer.d.ts → core/installer.d.ts} +32 -2
  27. package/dist/{installer.js → core/installer.js} +129 -12
  28. package/dist/{lint.d.ts → core/lint.d.ts} +43 -2
  29. package/dist/{lint.js → core/lint.js} +89 -2
  30. package/dist/{logger.js → core/logger.js} +30 -1
  31. package/dist/core/paths.d.ts +35 -0
  32. package/dist/core/paths.js +41 -0
  33. package/dist/{protect.d.ts → core/protect.d.ts} +18 -4
  34. package/dist/{protect.js → core/protect.js} +85 -34
  35. package/dist/{registry.d.ts → core/registry.d.ts} +36 -15
  36. package/dist/{registry.js → core/registry.js} +66 -52
  37. package/dist/{review.js → core/review.js} +18 -6
  38. package/dist/{rules.d.ts → core/rules.d.ts} +3 -2
  39. package/dist/{rules.js → core/rules.js} +21 -5
  40. package/dist/core/run-hooks.d.ts +138 -0
  41. package/dist/core/run-hooks.js +196 -0
  42. package/dist/{runtime-status.d.ts → core/runtime-status.d.ts} +5 -4
  43. package/dist/{runtime-status.js → core/runtime-status.js} +29 -17
  44. package/dist/{types.d.ts → core/types.d.ts} +17 -0
  45. package/dist/{update.d.ts → core/update.d.ts} +12 -4
  46. package/dist/{update.js → core/update.js} +28 -12
  47. package/dist/{weakening.js → core/weakening.js} +2 -1
  48. package/package.json +16 -6
  49. package/rules/40-delegation.md +13 -2
  50. package/templates/.opencode/agents/style-enforcer.md +1 -1
  51. package/templates/.opencode/agents/test-grounder.md +1 -1
  52. package/templates/.opencode/skills/ground-in-tests/SKILL.md +1 -1
  53. package/templates/.opencode/skills/peer-review/SKILL.md +6 -1
  54. package/templates/.opencode/skills/project-config/SKILL.md +2 -2
  55. package/tui.tsx +6 -6
  56. package/dist/index.d.ts +0 -101
  57. /package/dist/{block-store.js → core/block-store.js} +0 -0
  58. /package/dist/{command-utils.d.ts → core/command-utils.d.ts} +0 -0
  59. /package/dist/{command-utils.js → core/command-utils.js} +0 -0
  60. /package/dist/{commands.d.ts → core/commands.d.ts} +0 -0
  61. /package/dist/{detect.d.ts → core/detect.d.ts} +0 -0
  62. /package/dist/{detect.js → core/detect.js} +0 -0
  63. /package/dist/{host.d.ts → core/host.d.ts} +0 -0
  64. /package/dist/{host.js → core/host.js} +0 -0
  65. /package/dist/{logger.d.ts → core/logger.d.ts} +0 -0
  66. /package/dist/{review.d.ts → core/review.d.ts} +0 -0
  67. /package/dist/{roster.d.ts → core/roster.d.ts} +0 -0
  68. /package/dist/{roster.js → core/roster.js} +0 -0
  69. /package/dist/{types.js → core/types.js} +0 -0
  70. /package/dist/{weakening.d.ts → core/weakening.d.ts} +0 -0
  71. /package/templates/{.opencode/opencode-dev-framework → .dev-framework}/rules/.gitkeep +0 -0
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Shared hook flow: harness-agnostic hook state and the per-edit / gate
3
+ * evaluation flows that every host adapter drives. Host-specific code
4
+ * (opencode `Plugin.define` registration, DSH Cordis bundle wiring) lives
5
+ * in the adapters and calls into these flows with a populated `HookState`.
6
+ *
7
+ * This module was extracted from the OpenCode adapter
8
+ * (`src/adapters/opencode/index.ts`, formerly `src/index.ts`) with
9
+ * relocation only — plus formatter line-breaks, added explicit types, and
10
+ * a `blockCounts` doc comment. No behavior change; the adapter keeps
11
+ * registration thin.
12
+ */
13
+ import type { BlockStore, StuckSnapshotStore } from "./block-store.js";
14
+ import type { ChangedFileTracker } from "./gate.js";
15
+ import { type CompletionVerdict, type PassCache } from "./harness.js";
16
+ import type { RunCommand } from "./host.js";
17
+ import { type LintLimiter } from "./lint.js";
18
+ import type { LogFn, LogLevel } from "./logger.js";
19
+ import { type IdleHookVia } from "./runtime-status.js";
20
+ import type { HostSeams, ResolvedConfig } from "./types.js";
21
+ import type { EnforceableSnapshot } from "./weakening.js";
22
+ export interface HookState {
23
+ directory: string;
24
+ config: ResolvedConfig;
25
+ /**
26
+ * Session-start enforceable snapshot (plan 17 §2). Compared against the
27
+ * live config at every gate evaluation so mid-session duty reductions
28
+ * surface in the verdict. Never re-baselined — including across
29
+ * `set_profile` — so a profile downgrade reads as the weakening it is.
30
+ */
31
+ initialEnforceable: EnforceableSnapshot;
32
+ log: LogFn;
33
+ run: RunCommand;
34
+ tracker: ChangedFileTracker;
35
+ constitution: string | null;
36
+ /** Per-session count of completion-gate blocks (keyed by sessionID). */
37
+ blockCounts: Map<string, number>;
38
+ /**
39
+ * Persistent block-count store over `ctx.storage`, write-through into
40
+ * `blockCounts` (which stays the live L1 cache for status rendering).
41
+ * Survives plugin reload / session_move / server restart.
42
+ * Note: this `HookState` is intentionally forked from `registry.ts`
43
+ * `HookState` (module state is per-location here, not registry-keyed);
44
+ * `format-status.ts` reads the `blockCounts` Map projection, which the
45
+ * store keeps live on every get/increment/clear.
46
+ */
47
+ blocks: BlockStore;
48
+ /**
49
+ * Last-blocked-evaluation snapshots for no-progress early stand-down
50
+ * (docs/plans/14-stuck-detection.md). Same storage-backed, best-effort pattern as `blocks`;
51
+ * memory-only here (no status projection needed).
52
+ */
53
+ stuckSnapshots: StuckSnapshotStore;
54
+ precommitAvailable?: boolean;
55
+ configMtime?: number;
56
+ /**
57
+ * Shared FIFO limiter bounding concurrent linter subprocesses across
58
+ * per-edit lints and gate lint steps.
59
+ */
60
+ lintLimiter: LintLimiter;
61
+ /** Fingerprint of the last clean gate pass; skips redundant suites. */
62
+ passCache: PassCache;
63
+ /**
64
+ * Host seam availability (see `HostSeams`), probed once at mount with
65
+ * guarded reads. Rendered by status so a degraded mount reads as
66
+ * degraded, never as silently whole. The DSH adapter probes this at
67
+ * mount; OpenCode leaves it unset (its seams are core-guaranteed).
68
+ * Forked from `registry.ts` `HookState` like the stores above.
69
+ */
70
+ seams?: HostSeams;
71
+ /**
72
+ * `Date.now()` of the last config-mtime check. Hook fires are far more
73
+ * frequent than config edits, so mtime stats are throttled to a 1s window.
74
+ */
75
+ lastConfigCheck: number;
76
+ /**
77
+ * Which lever completed a gate evaluation most recently in this process:
78
+ * `"idle"` once the `experimental.idle` hook has (same-execution
79
+ * continuation active), `"fallback"` when only the `event.subscribe`
80
+ * idle re-prompt net has. Absent until either fires. Memory-only: a
81
+ * reload re-derives it on the next idle boundary. `/df-status` renders
82
+ * the active level.
83
+ */
84
+ continuationLevel?: "idle" | "fallback";
85
+ /**
86
+ * Dedup map for the idle-first cutover: sessionID → `Date.now()` at the
87
+ * last COMPLETED hook evaluation (pass, blocked-admitted, and standdown
88
+ * all stamp; throw/early-return paths do not). The `event.subscribe` idle net
89
+ * skips when the stamp is fresh so one boundary never runs the gate
90
+ * twice. Memory-only; worst case on reload is one extra suite run.
91
+ */
92
+ lastIdleHandled: Map<string, number>;
93
+ }
94
+ export declare function getActiveState(): HookState | null;
95
+ export declare function setActiveState(state: HookState | null): void;
96
+ export declare function getFallbackLog(): LogFn;
97
+ export declare function setFallbackLog(log: LogFn): void;
98
+ export declare function safeLog(state: HookState | null, level: LogLevel, message: string, extra?: Record<string, unknown>): Promise<void>;
99
+ export declare function reloadConfigIfChanged(state: HookState): Promise<void>;
100
+ /**
101
+ * Turn a completion verdict into the continuation message fed back to the
102
+ * agent when blocked. Shared by the `experimental.idle` hook (same
103
+ * execution, via synthetic) and the `event.subscribe` idle re-prompt
104
+ * fallback so wording (and block counting) is identical on every
105
+ * enforcement level.
106
+ */
107
+ export declare function continuationMessage(verdict: Extract<CompletionVerdict, {
108
+ decision: "blocked";
109
+ }>): string;
110
+ /** Log pass/standdown verdicts; returns the continuation message when blocked. */
111
+ export declare function actOnVerdict(state: HookState, verdict: CompletionVerdict): Promise<string | null>;
112
+ /**
113
+ * Per-edit lint flow, shared by the `execute.after` hook (primary) and the
114
+ * `filesystem.changed` fallback. Skipped files log at debug; passes at info;
115
+ * failures log loudly at error (the edit already landed, so unlike
116
+ * `execute.before` this never throws — it only reports).
117
+ */
118
+ export declare function runPerEditLint(state: HookState, filePath: string): Promise<void>;
119
+ /** Assemble the completion verdict with the state's live dependencies. */
120
+ export declare function runCompletion(state: HookState, sessionID: string): Promise<CompletionVerdict>;
121
+ /**
122
+ * Record a completed idle-hook evaluation for the dedup map. Stamp ONLY on
123
+ * the completed-evaluation paths (pass, blocked-admitted, standdown);
124
+ * throw/early-return paths must not stamp so the subscriber net retries.
125
+ */
126
+ export declare function stampIdleHandled(state: HookState, sessionID: string): void;
127
+ /**
128
+ * Best-effort runtime snapshot for `/df-runtime`: hook state plus template
129
+ * drift, fire-and-forget (never throws, never blocks the caller).
130
+ */
131
+ export declare function stampRuntimeStatus(directory: string, idleHookVia: IdleHookVia, continuation: "idle" | "fallback" | "armed", skillMirrorRoot?: string): void;
132
+ /**
133
+ * True when the idle hook completed an evaluation for this session inside
134
+ * `windowMs`. The hook itself uses a short window (same-boundary
135
+ * double-fire guard for the dual key registration below); the subscriber
136
+ * net uses the full window (one boundary, one gate run).
137
+ */
138
+ export declare function wasIdleHandledRecently(state: HookState, sessionID: string, windowMs?: number): boolean;
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Shared hook flow: harness-agnostic hook state and the per-edit / gate
3
+ * evaluation flows that every host adapter drives. Host-specific code
4
+ * (opencode `Plugin.define` registration, DSH Cordis bundle wiring) lives
5
+ * in the adapters and calls into these flows with a populated `HookState`.
6
+ *
7
+ * This module was extracted from the OpenCode adapter
8
+ * (`src/adapters/opencode/index.ts`, formerly `src/index.ts`) with
9
+ * relocation only — plus formatter line-breaks, added explicit types, and
10
+ * a `blockCounts` doc comment. No behavior change; the adapter keeps
11
+ * registration thin.
12
+ */
13
+ import { clearConfigCache, configMtimeMs, loadConfig } from "./config.js";
14
+ import { evaluateCompletion } from "./harness.js";
15
+ import { detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint, } from "./lint.js";
16
+ import { loadConstitution } from "./rules.js";
17
+ import { writeRuntimeStatus } from "./runtime-status.js";
18
+ import { checkTemplateUpdates, summarizeDrift } from "./update.js";
19
+ /**
20
+ * Live hook state for stale-hook guards. Private binding — read it via
21
+ * `getActiveState()` (writes go through `setActiveState`), mirroring the
22
+ * `registry.ts` getter/setter idiom. Never exported mutable: an ESM live
23
+ * `let` binding would let any importer assign past the setter.
24
+ */
25
+ let activeState = null;
26
+ export function getActiveState() {
27
+ return activeState;
28
+ }
29
+ export function setActiveState(state) {
30
+ activeState = state;
31
+ }
32
+ /** Fallback logger before any adapter registers one. Same idiom as above. */
33
+ let fallbackLog = async () => { };
34
+ export function getFallbackLog() {
35
+ return fallbackLog;
36
+ }
37
+ export function setFallbackLog(log) {
38
+ fallbackLog = log;
39
+ }
40
+ /**
41
+ * Minimum interval between config-mtime checks. Every hook fire calls
42
+ * `reloadConfigIfChanged`, but the config file almost never changes
43
+ * mid-session, so a 1s staleness window is invisible.
44
+ */
45
+ const CONFIG_RELOAD_MIN_INTERVAL_MS = 1000;
46
+ export function safeLog(state, level, message, extra) {
47
+ const fn = state && typeof state.log === "function" ? state.log : fallbackLog;
48
+ return fn(level, message, extra);
49
+ }
50
+ export async function reloadConfigIfChanged(state) {
51
+ // Throttle mtime checks: every hook fire calls this, but the config file
52
+ // almost never changes mid-session. A 1s staleness window is invisible.
53
+ const now = Date.now();
54
+ if (now - state.lastConfigCheck < CONFIG_RELOAD_MIN_INTERVAL_MS) {
55
+ return;
56
+ }
57
+ state.lastConfigCheck = now;
58
+ const mtime = configMtimeMs(state.directory);
59
+ if (mtime === undefined) {
60
+ return;
61
+ }
62
+ if (state.configMtime !== undefined && state.configMtime === mtime) {
63
+ return;
64
+ }
65
+ try {
66
+ clearConfigCache();
67
+ const next = loadConfig(state.directory);
68
+ const { constitution } = await loadConstitution(next, state.directory);
69
+ state.config = next;
70
+ state.constitution = constitution;
71
+ state.configMtime = mtime;
72
+ }
73
+ catch {
74
+ // keep current state on read failure
75
+ }
76
+ }
77
+ /**
78
+ * Turn a completion verdict into the continuation message fed back to the
79
+ * agent when blocked. Shared by the `experimental.idle` hook (same
80
+ * execution, via synthetic) and the `event.subscribe` idle re-prompt
81
+ * fallback so wording (and block counting) is identical on every
82
+ * enforcement level.
83
+ */
84
+ export function continuationMessage(verdict) {
85
+ const why = verdict.reason === "review"
86
+ ? "the peer-review requirement is unmet"
87
+ : verdict.reason === "weakened"
88
+ ? "the completion contract was weakened mid-session"
89
+ : "the repo's checks are failing";
90
+ return (`opencode-dev-framework completion gate blocked you from finishing because ${why} ` +
91
+ `(block ${verdict.blockCount}/${verdict.maxBlocks}).\n\n${verdict.summary}\n\n` +
92
+ `Fix the underlying cause and continue. Do NOT disable, skip, or weaken these checks to ` +
93
+ `get past the gate. If a failure is pre-existing and unrelated to your work, prove it ` +
94
+ `(show it fails on a clean tree) and report it to the user.\n\n` +
95
+ `You can inspect live gate state with dev_framework_runtime; if the setup ` +
96
+ `looks stale, check drift with dev_framework_update.`);
97
+ }
98
+ /** Log pass/standdown verdicts; returns the continuation message when blocked. */
99
+ export async function actOnVerdict(state, verdict) {
100
+ if (verdict.decision === "pass") {
101
+ if (verdict.note) {
102
+ await safeLog(state, "info", verdict.note, { changedFiles: verdict.changedFiles });
103
+ }
104
+ return null;
105
+ }
106
+ if (verdict.decision === "standdown") {
107
+ // evaluateCompletion already logged the stand-down loudly.
108
+ return null;
109
+ }
110
+ return continuationMessage(verdict);
111
+ }
112
+ /**
113
+ * Per-edit lint flow, shared by the `execute.after` hook (primary) and the
114
+ * `filesystem.changed` fallback. Skipped files log at debug; passes at info;
115
+ * failures log loudly at error (the edit already landed, so unlike
116
+ * `execute.before` this never throws — it only reports).
117
+ */
118
+ export async function runPerEditLint(state, filePath) {
119
+ if (!state.config.on_edit.lint)
120
+ return;
121
+ if (state.config.precommit === "auto" && state.precommitAvailable === undefined) {
122
+ state.precommitAvailable = await detectPreCommitAvailability(state.run, state.directory);
123
+ }
124
+ const outcome = await state.lintLimiter.run(() => lintFile(state.run, state.config, filePath, {
125
+ cwd: state.directory,
126
+ timeout: state.config.gate?.timeout,
127
+ precommitAvailable: state.precommitAvailable,
128
+ }));
129
+ if (outcome.skipped) {
130
+ await safeLog(state, "debug", summarizeLint(outcome), {
131
+ filePath,
132
+ reason: outcome.reason,
133
+ });
134
+ return;
135
+ }
136
+ if (!isLintFailure(outcome)) {
137
+ await safeLog(state, "info", summarizeLint(outcome), { filePath });
138
+ return;
139
+ }
140
+ await safeLog(state, "error", summarizeLint(outcome), {
141
+ filePath,
142
+ command: outcome.command?.join(" "),
143
+ stdout: outcome.result?.stdout,
144
+ stderr: outcome.result?.stderr,
145
+ });
146
+ }
147
+ /** Assemble the completion verdict with the state's live dependencies. */
148
+ export function runCompletion(state, sessionID) {
149
+ return evaluateCompletion({
150
+ run: state.run,
151
+ config: state.config,
152
+ directory: state.directory,
153
+ sessionID,
154
+ tracker: state.tracker,
155
+ blockCounts: state.blocks,
156
+ stuckSnapshots: state.stuckSnapshots,
157
+ lintLimiter: state.lintLimiter,
158
+ passCache: state.passCache,
159
+ baseline: state.initialEnforceable,
160
+ log: (level, message, extra) => safeLog(state, level, message, extra),
161
+ });
162
+ }
163
+ /**
164
+ * Record a completed idle-hook evaluation for the dedup map. Stamp ONLY on
165
+ * the completed-evaluation paths (pass, blocked-admitted, standdown);
166
+ * throw/early-return paths must not stamp so the subscriber net retries.
167
+ */
168
+ export function stampIdleHandled(state, sessionID) {
169
+ state.lastIdleHandled.set(sessionID, Date.now());
170
+ }
171
+ /**
172
+ * Best-effort runtime snapshot for `/df-runtime`: hook state plus template
173
+ * drift, fire-and-forget (never throws, never blocks the caller).
174
+ */
175
+ export function stampRuntimeStatus(directory, idleHookVia, continuation, skillMirrorRoot) {
176
+ void (async () => {
177
+ let templates;
178
+ try {
179
+ templates = summarizeDrift(await checkTemplateUpdates(directory, skillMirrorRoot));
180
+ }
181
+ catch {
182
+ // Best-effort: the snapshot renders without template state.
183
+ }
184
+ await writeRuntimeStatus(directory, { idleHookVia, continuation, templates });
185
+ })();
186
+ }
187
+ /**
188
+ * True when the idle hook completed an evaluation for this session inside
189
+ * `windowMs`. The hook itself uses a short window (same-boundary
190
+ * double-fire guard for the dual key registration below); the subscriber
191
+ * net uses the full window (one boundary, one gate run).
192
+ */
193
+ export function wasIdleHandledRecently(state, sessionID, windowMs = 5_000) {
194
+ const at = state.lastIdleHandled.get(sessionID);
195
+ return at !== undefined && Date.now() - at < windowMs;
196
+ }
@@ -8,11 +8,12 @@
8
8
  * throws: a missing, corrupt, or stale snapshot renders as
9
9
  * "not reported yet".
10
10
  */
11
+ import { RUNTIME_STATUS_FILE } from "./paths.js";
12
+ export { RUNTIME_STATUS_FILE };
11
13
  /** 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";
14
+ export declare const RUNTIME_STATUS_DIR = ".dev-framework";
15
+ /** Which session hook the core accepted, or neither (DSH uses `agent/turn-stopping`). */
16
+ export type IdleHookVia = "experimental.idle" | "idle" | "none" | "turn-stopping";
16
17
  /** Dispatch history this session: hook-fired, net-fired, or neither yet. */
17
18
  export type ContinuationState = "idle" | "fallback" | "armed";
18
19
  /** Template drift state for the TUI `/df-runtime` command: up to date,
@@ -11,9 +11,10 @@
11
11
  import { mkdir, readFile, writeFile } from "node:fs/promises";
12
12
  import { dirname, join } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
+ import { FRAMEWORK_DIR, RUNTIME_STATUS_FILE, RUNTIME_STATUS_RELS } from "./paths.js";
15
+ export { RUNTIME_STATUS_FILE };
14
16
  /** 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 const RUNTIME_STATUS_DIR = FRAMEWORK_DIR;
17
18
  export function snapshotPath(directory) {
18
19
  return join(directory, RUNTIME_STATUS_DIR, RUNTIME_STATUS_FILE);
19
20
  }
@@ -51,7 +52,10 @@ export async function writeRuntimeStatus(directory, partial) {
51
52
  }
52
53
  }
53
54
  function isIdleHookVia(value) {
54
- return value === "experimental.idle" || value === "idle" || value === "none";
55
+ return (value === "experimental.idle" ||
56
+ value === "idle" ||
57
+ value === "none" ||
58
+ value === "turn-stopping");
55
59
  }
56
60
  function isContinuationState(value) {
57
61
  return value === "idle" || value === "fallback" || value === "armed";
@@ -67,20 +71,28 @@ function isTemplateState(value) {
67
71
  typeof t.add === "number");
68
72
  }
69
73
  export async function readRuntimeStatus(directory) {
70
- try {
71
- const parsed = JSON.parse(await readFile(snapshotPath(directory), "utf8"));
72
- if (typeof parsed.frameworkVersion !== "string" || typeof parsed.updatedAt !== "string") {
73
- return null;
74
+ // New home first, previous home as fallback; writers use the new home
75
+ // only, so old snapshots fade with the next stamp.
76
+ const candidates = RUNTIME_STATUS_RELS.map((rel) => join(directory, rel));
77
+ for (const candidate of candidates) {
78
+ try {
79
+ const parsed = JSON.parse(await readFile(candidate, "utf8"));
80
+ if (typeof parsed.frameworkVersion !== "string" || typeof parsed.updatedAt !== "string") {
81
+ // Valid JSON, wrong shape: fall through to the legacy home
82
+ // rather than letting an invalid new snapshot shadow valid data.
83
+ continue;
84
+ }
85
+ return {
86
+ frameworkVersion: parsed.frameworkVersion,
87
+ idleHookVia: isIdleHookVia(parsed.idleHookVia) ? parsed.idleHookVia : "none",
88
+ continuation: isContinuationState(parsed.continuation) ? parsed.continuation : "armed",
89
+ ...(isTemplateState(parsed.templates) ? { templates: parsed.templates } : {}),
90
+ updatedAt: parsed.updatedAt,
91
+ };
92
+ }
93
+ catch {
94
+ // try the next (legacy) location
74
95
  }
75
- return {
76
- frameworkVersion: parsed.frameworkVersion,
77
- idleHookVia: isIdleHookVia(parsed.idleHookVia) ? parsed.idleHookVia : "none",
78
- continuation: isContinuationState(parsed.continuation) ? parsed.continuation : "armed",
79
- ...(isTemplateState(parsed.templates) ? { templates: parsed.templates } : {}),
80
- updatedAt: parsed.updatedAt,
81
- };
82
- }
83
- catch {
84
- return null;
85
96
  }
97
+ return null;
86
98
  }
@@ -6,6 +6,23 @@
6
6
  export type Profile = "off" | "advisory" | "standard" | "strict";
7
7
  export type ProtectMode = "warn" | "deny";
8
8
  export type GateScope = "all" | "changed";
9
+ /**
10
+ * Host seam availability, probed once at mount with guarded reads and
11
+ * rendered by status so a degraded mount reads as degraded. Shared named
12
+ * type so the forked `HookState` definitions (`registry.ts`,
13
+ * `run-hooks.ts`) cannot skew: one shape, two references.
14
+ */
15
+ export interface HostSeams {
16
+ tools: boolean;
17
+ goals: boolean;
18
+ approval: boolean;
19
+ /** DSH-only: the host subagent service (specialist dispatch). */
20
+ subagents: boolean;
21
+ /** DSH-only: the agent-preset registry (read-only reviewer preset). */
22
+ agentPresets: boolean;
23
+ /** DSH-only: the session-history query service (continuity probe). */
24
+ sessionQuery: boolean;
25
+ }
9
26
  /**
10
27
  * A command specification: either a single default command string, or a map
11
28
  * of per-extension overrides keyed by extension (e.g. `.go`).
@@ -5,8 +5,9 @@
5
5
  * Detection runs in code (`statusTemplates` — the same comparison `df init`
6
6
  * uses); diffing, presenting, and applying stay with the agent, which hands
7
7
  * each drifted file to the user before touching it. There is no auto-apply
8
- * path by construction. The user config (`.opencode-dev-framework.yml`) is
9
- * structurally out of scope: it was never in the template set.
8
+ * path by construction. The user config (`.dev-framework.yml`, or the legacy
9
+ * `.opencode-dev-framework.yml`) is structurally out of scope: it was never
10
+ * in the template set.
10
11
  */
11
12
  import type { TemplateState } from "./runtime-status.js";
12
13
  export interface TemplateDrift {
@@ -16,10 +17,11 @@ export interface TemplateDrift {
16
17
  refresh: string[];
17
18
  /** Shipped files absent — offer add (reads as botched/partial install). */
18
19
  add: string[];
19
- /** True when nothing is installed at all — redirect to `/df-init`. */
20
+ /** True when no templates are installed at all — redirect to `/df-init`.
21
+ * Mirror copies never count: they are derived output, not the install. */
20
22
  empty: boolean;
21
23
  }
22
- export declare function checkTemplateUpdates(directory: string): Promise<TemplateDrift>;
24
+ export declare function checkTemplateUpdates(directory: string, skillMirrorRoot?: string): Promise<TemplateDrift>;
23
25
  /**
24
26
  * Compose the prompt text the `/df-update` command submits back to the
25
27
  * session. An installed-but-current tree reports status; an empty tree
@@ -53,6 +55,12 @@ export declare function driftMentionLine(drift: TemplateDrift): string | null;
53
55
  export interface UpdateCommandDeps {
54
56
  directory: string;
55
57
  delivery: unknown;
58
+ /**
59
+ * Skill mirror root to include in drift (same capability as
60
+ * `skillMirrorRoot` on the init side). Unset: drift covers the
61
+ * template set only.
62
+ */
63
+ skillMirrorRoot?: string;
56
64
  /** Throws when the owning setup/state went stale mid-check. */
57
65
  checkAlive: () => void;
58
66
  /** Deliver the report to the session; throws on transport failure. */
@@ -5,18 +5,33 @@
5
5
  * Detection runs in code (`statusTemplates` — the same comparison `df init`
6
6
  * uses); diffing, presenting, and applying stay with the agent, which hands
7
7
  * each drifted file to the user before touching it. There is no auto-apply
8
- * path by construction. The user config (`.opencode-dev-framework.yml`) is
9
- * structurally out of scope: it was never in the template set.
8
+ * path by construction. The user config (`.dev-framework.yml`, or the legacy
9
+ * `.opencode-dev-framework.yml`) is structurally out of scope: it was never
10
+ * in the template set.
10
11
  */
11
- import { statusTemplates } from "./installer.js";
12
- export async function checkTemplateUpdates(directory) {
12
+ import { statusMirror, statusTemplates } from "./installer.js";
13
+ export async function checkTemplateUpdates(directory, skillMirrorRoot) {
13
14
  const status = await statusTemplates(directory);
14
- return {
15
- current: status.present,
16
- refresh: status.different,
17
- add: status.missing,
15
+ const drift = {
16
+ current: [...status.present],
17
+ refresh: [...status.different],
18
+ add: [...status.missing],
19
+ // Deliberately template-only: the mirror is derived output, not the
20
+ // install. A populated mirror must never mask missing templates and
21
+ // suppress the /df-init redirect — an unloadable setup with no
22
+ // templates needs reinstalling, not mirror diffing.
18
23
  empty: status.present.length === 0 && status.different.length === 0,
19
24
  };
25
+ // Mirror maintenance: a host-scanned skill copy that is missing or
26
+ // edited-out-of-sync leaves the setup unloadable, so it reads as drift
27
+ // exactly like a template file. Unset means no mirror to maintain.
28
+ if (skillMirrorRoot !== undefined) {
29
+ const mirror = await statusMirror(directory, skillMirrorRoot);
30
+ drift.current.push(...mirror.present);
31
+ drift.refresh.push(...mirror.different);
32
+ drift.add.push(...mirror.missing);
33
+ }
34
+ return drift;
20
35
  }
21
36
  /**
22
37
  * Compose the prompt text the `/df-update` command submits back to the
@@ -53,8 +68,9 @@ export function composeUpdatePrompt(drift, directory) {
53
68
  lines.push("", "Bring the deployment current from the lists above. For each refresh file, " +
54
69
  "run diff yourself against the shipped template, present the per-file diff, " +
55
70
  "and overwrite only what the user approves. For each add file, present what it " +
56
- "is and add only what the user approves. Never touch " +
57
- ".opencode-dev-framework.yml — it is user config, not a shipped template. " +
71
+ "is and add only what the user approves. Never touch the config file " +
72
+ "(`.dev-framework.yml`, or legacy `.opencode-dev-framework.yml`) — it is user " +
73
+ "config, not a shipped template. " +
58
74
  "Report what was applied and what was left alone.");
59
75
  return lines.join("\n");
60
76
  }
@@ -109,7 +125,7 @@ export function driftMentionLine(drift) {
109
125
  parts.push(`${drift.add.length} to add`);
110
126
  }
111
127
  return (`opencode-dev-framework templates have drifted (${parts.join(", ")}). ` +
112
- "Run /df-update to review each file with approval.");
128
+ "Run dev_framework_update to review each file with approval.");
113
129
  }
114
130
  /**
115
131
  * Execute the `/df-update` command with injected dependencies (pure policy,
@@ -122,7 +138,7 @@ export function driftMentionLine(drift) {
122
138
  * recover. Returns whether the handoff was delivered.
123
139
  */
124
140
  export async function runUpdateCommand(deps) {
125
- const drift = await checkTemplateUpdates(deps.directory);
141
+ const drift = await checkTemplateUpdates(deps.directory, deps.skillMirrorRoot);
126
142
  deps.checkAlive();
127
143
  if (!needsAgentHandoff(drift)) {
128
144
  return false;
@@ -2,7 +2,8 @@ import { normalizeCommandMap } from "./command-utils.js";
2
2
  /**
3
3
  * Config-weakening detection (plan 17 §2).
4
4
  *
5
- * The duties document (`.opencode-dev-framework.yml`) is freely rewritable
5
+ * The duties document (`.dev-framework.yml`, or the legacy
6
+ * `.opencode-dev-framework.yml`) is freely rewritable
6
7
  * mid-session and reloads on mtime — deleting checks, dropping
7
8
  * `require_review`, or lowering `max_blocks` silently moves the goalposts.
8
9
  * Rewriting the duties to make them pass is the canonical duty-escape, so
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "1.9.4",
3
+ "version": "1.10.0",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "main": "dist/index.js",
8
- "types": "dist/index.d.ts",
7
+ "main": "dist/adapters/opencode/index.js",
8
+ "types": "dist/adapters/opencode/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
11
+ "types": "./dist/adapters/opencode/index.d.ts",
12
+ "import": "./dist/adapters/opencode/index.js"
13
+ },
14
+ "./dsh": {
15
+ "types": "./dist/adapters/dsh/index.d.ts",
16
+ "import": "./dist/adapters/dsh/index.js"
13
17
  },
14
18
  "./tui": {
15
19
  "types": "./dist/tui.d.ts",
@@ -25,7 +29,8 @@
25
29
  "bin",
26
30
  "rules",
27
31
  "templates",
28
- "tui.tsx"
32
+ "tui.tsx",
33
+ "cordis.patch.yml"
29
34
  ],
30
35
  "bin": {
31
36
  "df": "bin/df"
@@ -74,5 +79,10 @@
74
79
  "solid-js": "^1.9.12",
75
80
  "typescript": "^7.0.2",
76
81
  "vitest": "^4.1.10"
82
+ },
83
+ "dsh": {
84
+ "bundle": {
85
+ "patch": "./cordis.patch.yml"
86
+ }
77
87
  }
78
88
  }
@@ -4,6 +4,17 @@ When the framework is active, you are not a lone coder; you are the lead enginee
4
4
  coordinating specialist reviewers. Use them as a continuous loop, not a final
5
5
  rubber-stamp. Catching issues early is cheaper than catching them at the gate.
6
6
 
7
+ ## Harness rule (read first)
8
+
9
+ - **On OpenCode**, the specialists below are runnable subagents (installed
10
+ under `.opencode/agents/`). Delegate to them per the cadence.
11
+ - **On DSH**, the adapter dispatches `pattern-guardian`, `style-enforcer`,
12
+ and `code-reviewer` as read-only child sessions at review-blocks when the
13
+ host subagent seam is available, then folds their findings into the
14
+ blocking feedback. `test-grounder` remains an inline lead duty. When the
15
+ dispatch seam is absent, run the same checks inline via the skills, at the
16
+ same bar, and record each pass and its outcome in the review artifact.
17
+
7
18
  ## The specialists
8
19
 
9
20
  When the project has the specialist agents installed (under `.opencode/agents/`),
@@ -47,8 +58,8 @@ change you plan first, implement from the plan without expanding scope, then
47
58
  harden (full verification + review + fresh artifact) before declaring done.
48
59
  Keep delegation proportional: a one-line fix doesn't need the full loop; a new module
49
60
  does. Use judgment, but never skip the test-grounding and review steps for behavioral
50
- changes. If the specialist agents are not installed in this project, perform the same
51
- checks yourself with the skills in this section.
61
+ changes. If specialist agents or DSH dispatch are unavailable, perform the same
62
+ checks yourself with the skills in this section (see the harness rule above).
52
63
 
53
64
  ## Execute plans under `/df-goal`
54
65
 
@@ -18,7 +18,7 @@ written by one careful author.
18
18
  Given a set of changed files, check them against — in priority order:
19
19
 
20
20
  1. **An explicit project style guide**, if one exists. Look for it at the path
21
- named in `.opencode-dev-framework.yml` (`style_guide:`), or common
21
+ named in `.dev-framework.yml` (`style_guide:`), or common
22
22
  locations: `STYLE.md`, `STYLEGUIDE.md`, `docs/style*.md`, `CONTRIBUTING.md`,
23
23
  `.editorconfig`, and lint configs (`.eslintrc*`, `ruff.toml`,
24
24
  `.rubocop.yml`, `pyproject.toml`, etc.).
@@ -38,7 +38,7 @@ running the project's real commands and reading the output.
38
38
  ## How to work
39
39
 
40
40
  1. Determine the change scope (git diff) and what was claimed.
41
- 2. Discover the project's commands: from `.opencode-dev-framework.yml`
41
+ 2. Discover the project's commands: from `.dev-framework.yml`
42
42
  (`commands.test`, `commands.typecheck`) if present, else from
43
43
  `package.json` scripts, `pyproject.toml`/`pytest`, `go test`, `Cargo.toml`,
44
44
  `Makefile`, etc.