opencode-dev-framework 1.8.0 → 1.9.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
@@ -155,10 +155,11 @@ How each layer is enforced, and what it honestly cannot do:
155
155
  | `/df-profile` | Instant modal picker (or `/df-profile <name>`): switches profile now, written to config. |
156
156
  | `/df-verify` | Runs the verification suite manually; pass/fail summary in a modal. |
157
157
  | `/df-init` | Server-side command: scaffolds templates, writes the detected config, trial-runs it, hands the brief to the agent. |
158
+ | `/df-update` | Server-side command: diffs installed templates against shipped, refresh/add each with user approval (detection only, never writes). Drift is also mentioned once at session startup. |
158
159
  | `/df-goal <objective>` | Server-side command: starts a **verified** native goal (requires native `/goal`, a blocking profile, and at least one real check). |
159
160
 
160
- The TUI commands open instantly and never feed the LLM; `/df-init` and
161
- `/df-goal` are server-side and drive the session. Full reference:
161
+ The TUI commands open instantly and never feed the LLM; `/df-init`,
162
+ `/df-update`, and `/df-goal` are server-side and drive the session. Full reference:
162
163
  [`docs/user/commands.md`](docs/user/commands.md).
163
164
 
164
165
  ## Limitations (short version)
@@ -112,6 +112,7 @@ export function renderHelp() {
112
112
  lines.push("/df-verify Run the completion gate manually");
113
113
  lines.push("/df-goal Start a verified native goal (verification contract + native /goal)");
114
114
  lines.push("/df-init Set up this project (scaffold, detected config, trial-run, brief)");
115
+ lines.push("/df-update Check installed templates against shipped (refresh/add, approved per file)");
115
116
  lines.push("/df-help Show this message");
116
117
  lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
117
118
  return lines.join("\n");
package/dist/harness.js CHANGED
@@ -178,6 +178,8 @@ function reviewMissingMessage(changedFiles) {
178
178
  `fail without the change, commands that actually pass), and code-reviewer / pattern-guardian ` +
179
179
  `for correctness and drift. Resolve every blocking finding, then write a summary of the ` +
180
180
  `review findings and their resolution to ${REVIEW_ARTIFACT_REL}.\n\n` +
181
+ `Do not re-run a specialist whose scope has not changed since its last report — ` +
182
+ `reuse that report and only re-run what your fixes invalidate.\n\n` +
181
183
  `Investigation-only reviewers: do not ask them to edit product code.`);
182
184
  }
183
185
  /** Create an empty pass cache (one per session state). */
package/dist/index.d.ts CHANGED
@@ -15,6 +15,8 @@
15
15
  * - ctx.command.transform(...) -> server-side `/df-init` project setup
16
16
  * (deterministic scaffold in code, handoff back via session.prompt;
17
17
  * see src/init.ts)
18
+ * - ctx.command.transform(...) -> server-side `/df-update` template drift
19
+ * check (detection only, handoff back via session.prompt; see src/update.ts)
18
20
  *
19
21
  * Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
20
22
  * (same execution) we run the gate and if it fails inside budget we admit
package/dist/index.js CHANGED
@@ -15,6 +15,8 @@
15
15
  * - ctx.command.transform(...) -> server-side `/df-init` project setup
16
16
  * (deterministic scaffold in code, handoff back via session.prompt;
17
17
  * see src/init.ts)
18
+ * - ctx.command.transform(...) -> server-side `/df-update` template drift
19
+ * check (detection only, handoff back via session.prompt; see src/update.ts)
18
20
  *
19
21
  * Gate enforcement: no synchronous pre-stop veto. On `experimental.idle`
20
22
  * (same execution) we run the gate and if it fails inside budget we admit
@@ -35,8 +37,10 @@ import { createLintLimiter, detectPreCommitAvailability, isLintFailure, lintFile
35
37
  import { createLogger } from "./logger.js";
36
38
  import { checkToolCall, extractFilePath, FILE_TOOLS, toPermissionGuard } from "./protect.js";
37
39
  import { constitutionPresent, loadConstitution } from "./rules.js";
40
+ import { clearSessionDirectory, hasSeenSessionStart, markSessionStartSeen } from "./registry.js";
38
41
  import { findRosterIndex, renderDutyRoster, rosterPresent } from "./roster.js";
39
42
  import { writeRuntimeStatus } from "./runtime-status.js";
43
+ import { checkTemplateUpdates, driftMentionLine } from "./update.js";
40
44
  import { snapshotEnforceable } from "./weakening.js";
41
45
  let activeState = null;
42
46
  let fallbackLog = async () => { };
@@ -358,6 +362,27 @@ const plugin = Plugin.define({
358
362
  await safeLog(state, "debug", "duty roster injected into system prompt");
359
363
  }
360
364
  }
365
+ // 1a) Startup template-drift mention — once per session, best-effort.
366
+ // First `context` sighting of a sessionID is session startup (plugin
367
+ // `setup()` has no session to mention into). Drifted installs get one
368
+ // line pointing at `/df-update`; current and empty trees stay silent.
369
+ // Never throws into prompt assembly; never writes.
370
+ const startupID = getEventSessionID(event);
371
+ if (startupID !== undefined && !hasSeenSessionStart(startupID)) {
372
+ markSessionStartSeen(startupID);
373
+ try {
374
+ const line = driftMentionLine(await checkTemplateUpdates(state.directory));
375
+ if (line !== null) {
376
+ event.system.push({ type: "text", text: line });
377
+ await safeLog(state, "debug", "template drift mentioned at session startup");
378
+ }
379
+ }
380
+ catch (error) {
381
+ await safeLog(state, "debug", "startup drift check failed silently", {
382
+ error: String(error),
383
+ });
384
+ }
385
+ }
361
386
  }));
362
387
  // Also hook other request kinds so the reminder is not missed on title/generate
363
388
  // (no-op if model doesn't need it; cheap)
@@ -897,6 +922,49 @@ const plugin = Plugin.define({
897
922
  error: String(err),
898
923
  });
899
924
  }
925
+ // 3d) Template refresh — server-side `/df-update` through
926
+ // `ctx.command.transform` (same shape as `/df-init`). Detects drift
927
+ // between the deployed templates and the shipped set, then hands the
928
+ // lists back through `session.prompt` with the invocation delivery, so
929
+ // the agent diffs, presents per file, and applies only what the user
930
+ // approves. Detection only — the command never writes.
931
+ try {
932
+ trackRegistration(await ctx.command.transform((editor) => {
933
+ editor.add({
934
+ name: "df-update",
935
+ description: "Check the project's installed templates against the shipped set and hand the drift to the agent: refresh differing files, add missing ones, each with user approval. Detection only, never writes.",
936
+ execute: async (invocation) => {
937
+ if (activeState !== state) {
938
+ throw new Error("Cannot check for updates: the plugin session state changed " +
939
+ "(teardown or reload raced the command); retry /df-update.");
940
+ }
941
+ const { runUpdateCommand } = await import("./update.js");
942
+ await runUpdateCommand({
943
+ directory: state.directory,
944
+ delivery: invocation.delivery,
945
+ checkAlive: () => {
946
+ if (activeState !== state) {
947
+ throw new Error("Update check was superseded mid-run (teardown or reload raced the command); " +
948
+ "retry /df-update — it only reads, never writes.");
949
+ }
950
+ },
951
+ deliver: async (text, delivery) => {
952
+ await ctx.session.prompt({
953
+ sessionID: invocation.sessionID,
954
+ text,
955
+ delivery,
956
+ });
957
+ },
958
+ });
959
+ },
960
+ });
961
+ }));
962
+ }
963
+ catch (err) {
964
+ await safeLog(state, "warn", "could not register df-update command; template updates unavailable", {
965
+ error: String(err),
966
+ });
967
+ }
900
968
  // 4) Event subscription — file tracking + gate enforcement net.
901
969
  // Runs the gate on `session.idle` for the boundaries the §1b hook
902
970
  // skipped (interruption, failure, steer-parked drains) or for builds
@@ -915,12 +983,14 @@ const plugin = Plugin.define({
915
983
  const type = event.type;
916
984
  if (isSessionDeletedEvent(type)) {
917
985
  // session.deleted: cleanup block counts + stuck snapshots
918
- // (memory + storage) and the idle dedup stamp for the session.
986
+ // (memory + storage), the idle dedup stamp, and the startup
987
+ // registries (directory mapping + drift-mention seen-set).
919
988
  const sid = getEventSessionID(event);
920
989
  if (sid) {
921
990
  await state.blocks.clear(sid);
922
991
  await state.stuckSnapshots.clear(sid);
923
992
  state.lastIdleHandled.delete(sid);
993
+ clearSessionDirectory(sid);
924
994
  }
925
995
  continue;
926
996
  }
@@ -49,6 +49,8 @@ export declare function setSessionDirectory(sessionID: string, directory: string
49
49
  export declare function getDirectoryForSession(sessionID: string): string | null;
50
50
  /** Forget a session's directory mapping (called on `session.deleted`). */
51
51
  export declare function clearSessionDirectory(sessionID: string): void;
52
+ export declare function hasSeenSessionStart(sessionID: string): boolean;
53
+ export declare function markSessionStartSeen(sessionID: string): void;
52
54
  /** Reset all in-memory registries. Intended for test cleanup between
53
55
  * test runs so stale session-to-directory mappings do not bleed
54
56
  * `getStateForSession` into the next test. */
package/dist/registry.js CHANGED
@@ -54,15 +54,26 @@ export function setSessionDirectory(sessionID, directory) {
54
54
  export function getDirectoryForSession(sessionID) {
55
55
  return sessionToDirectory.get(sessionID) ?? null;
56
56
  }
57
+ /** Session IDs already given their startup mention. In-memory like the
58
+ * directory map, so an opencode restart/reload naturally re-arms it. */
59
+ const sessionStartSeen = new Set();
57
60
  /** Forget a session's directory mapping (called on `session.deleted`). */
58
61
  export function clearSessionDirectory(sessionID) {
59
62
  sessionToDirectory.delete(sessionID);
63
+ sessionStartSeen.delete(sessionID);
64
+ }
65
+ export function hasSeenSessionStart(sessionID) {
66
+ return sessionStartSeen.has(sessionID);
67
+ }
68
+ export function markSessionStartSeen(sessionID) {
69
+ sessionStartSeen.add(sessionID);
60
70
  }
61
71
  /** Reset all in-memory registries. Intended for test cleanup between
62
72
  * test runs so stale session-to-directory mappings do not bleed
63
73
  * `getStateForSession` into the next test. */
64
74
  export function resetRegistry() {
65
75
  sessionToDirectory.clear();
76
+ sessionStartSeen.clear();
66
77
  hookRegistry.clear();
67
78
  activeDirectory = null;
68
79
  }
package/dist/review.js CHANGED
@@ -64,13 +64,15 @@ export function assessReviewContent(content) {
64
64
  return "thin";
65
65
  return "present";
66
66
  }
67
- /** Guidance appended to thin/template summaries: what to write. */
67
+ /** Guidance appended to thin/template/stale summaries: what to write. */
68
68
  function reviewCadenceReminder() {
69
69
  return (`Before declaring done you must run the project's peer-review cadence: ` +
70
70
  `style-enforcer on the changed files, then test-grounder (evidence: tests that ` +
71
71
  `fail without the change, commands that actually pass), and code-reviewer / pattern-guardian ` +
72
72
  `for correctness and drift. Resolve every blocking finding, then write a summary of the ` +
73
73
  `review findings and their resolution to ${REVIEW_REL}.\n\n` +
74
+ `Do not re-run a specialist whose scope has not changed since its last report — ` +
75
+ `reuse that report and only re-run what your fixes invalidate.\n\n` +
74
76
  `Investigation-only reviewers: do not ask them to edit product code.`);
75
77
  }
76
78
  export function thinReviewMessage(changedFiles) {
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Shared per-project template-update flow: the `/df-update` server command
3
+ * brings a deployment's shipped files current with per-file approval.
4
+ *
5
+ * Detection runs in code (`statusTemplates` — the same comparison `df init`
6
+ * uses); diffing, presenting, and applying stay with the agent, which hands
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.
10
+ */
11
+ export interface TemplateDrift {
12
+ /** Shipped files present and identical. */
13
+ current: string[];
14
+ /** Shipped files present with different content — offer refresh. */
15
+ refresh: string[];
16
+ /** Shipped files absent — offer add (reads as botched/partial install). */
17
+ add: string[];
18
+ /** True when nothing is installed at all — redirect to `/df-init`. */
19
+ empty: boolean;
20
+ }
21
+ export declare function checkTemplateUpdates(directory: string): Promise<TemplateDrift>;
22
+ /**
23
+ * Compose the prompt text the `/df-update` command submits back to the
24
+ * session. An installed-but-current tree reports status; an empty tree
25
+ * redirects to `/df-init`; a drifted tree hands the agent the lists plus
26
+ * standing instructions (present per file, apply only what is approved).
27
+ */
28
+ export declare function composeUpdatePrompt(drift: TemplateDrift, directory: string): string;
29
+ /**
30
+ * One-line startup mention for template drift, or null when there is
31
+ * nothing to say. Installed-but-current and empty trees stay silent: the
32
+ * mention covers drift only (an empty tree is `/df-init` territory, and
33
+ * the command itself already redirects there — no new nag is invented).
34
+ */
35
+ export declare function driftMentionLine(drift: TemplateDrift): string | null;
36
+ export interface UpdateCommandDeps {
37
+ directory: string;
38
+ delivery: unknown;
39
+ /** Throws when the owning setup/state went stale mid-check. */
40
+ checkAlive: () => void;
41
+ /** Deliver the report to the session; throws on transport failure. */
42
+ deliver: (text: string, delivery: unknown) => Promise<void>;
43
+ }
44
+ /**
45
+ * Execute the `/df-update` command with injected dependencies (pure policy,
46
+ * testable without a plugin context). Check, re-check liveness across the
47
+ * await, then deliver. A delivery failure throws: the check succeeded, only
48
+ * the handoff back failed, and the message says how to recover.
49
+ */
50
+ export declare function runUpdateCommand(deps: UpdateCommandDeps): Promise<void>;
package/dist/update.js ADDED
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Shared per-project template-update flow: the `/df-update` server command
3
+ * brings a deployment's shipped files current with per-file approval.
4
+ *
5
+ * Detection runs in code (`statusTemplates` — the same comparison `df init`
6
+ * uses); diffing, presenting, and applying stay with the agent, which hands
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.
10
+ */
11
+ import { statusTemplates } from "./installer.js";
12
+ export async function checkTemplateUpdates(directory) {
13
+ const status = await statusTemplates(directory);
14
+ return {
15
+ current: status.present,
16
+ refresh: status.different,
17
+ add: status.missing,
18
+ empty: status.present.length === 0 && status.different.length === 0,
19
+ };
20
+ }
21
+ /**
22
+ * Compose the prompt text the `/df-update` command submits back to the
23
+ * session. An installed-but-current tree reports status; an empty tree
24
+ * redirects to `/df-init`; a drifted tree hands the agent the lists plus
25
+ * standing instructions (present per file, apply only what is approved).
26
+ */
27
+ export function composeUpdatePrompt(drift, directory) {
28
+ const total = drift.current.length + drift.refresh.length + drift.add.length;
29
+ if (drift.empty) {
30
+ return [
31
+ `No opencode-dev-framework templates are installed in ${directory}.`,
32
+ "Run /df-init for the full first-time setup instead of adding files piecemeal.",
33
+ ].join("\n");
34
+ }
35
+ if (drift.refresh.length === 0 && drift.add.length === 0) {
36
+ return [
37
+ `opencode-dev-framework templates in ${directory} are current: ` +
38
+ `${drift.current.length}/${total} shipped files match.`,
39
+ "Nothing to do.",
40
+ ].join("\n");
41
+ }
42
+ const lines = [
43
+ `opencode-dev-framework template drift in ${directory}: ` +
44
+ `${drift.current.length}/${total} current, ` +
45
+ `${drift.refresh.length} to refresh, ${drift.add.length} to add.`,
46
+ ];
47
+ if (drift.refresh.length > 0) {
48
+ lines.push("", "Refresh (differs from shipped):", ...drift.refresh.map((f) => `- ${f}`));
49
+ }
50
+ if (drift.add.length > 0) {
51
+ lines.push("", "Add (shipped, absent — likely a partial install):", ...drift.add.map((f) => `- ${f}`));
52
+ }
53
+ lines.push("", "Bring the deployment current from the lists above. For each refresh file, " +
54
+ "run diff yourself against the shipped template, present the per-file diff, " +
55
+ "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. " +
58
+ "Report what was applied and what was left alone.");
59
+ return lines.join("\n");
60
+ }
61
+ /**
62
+ * One-line startup mention for template drift, or null when there is
63
+ * nothing to say. Installed-but-current and empty trees stay silent: the
64
+ * mention covers drift only (an empty tree is `/df-init` territory, and
65
+ * the command itself already redirects there — no new nag is invented).
66
+ */
67
+ export function driftMentionLine(drift) {
68
+ if (drift.empty || (drift.refresh.length === 0 && drift.add.length === 0)) {
69
+ return null;
70
+ }
71
+ const parts = [];
72
+ if (drift.refresh.length > 0) {
73
+ parts.push(`${drift.refresh.length} to refresh`);
74
+ }
75
+ if (drift.add.length > 0) {
76
+ parts.push(`${drift.add.length} to add`);
77
+ }
78
+ return (`opencode-dev-framework templates have drifted (${parts.join(", ")}). ` +
79
+ "Run /df-update to review each file with approval.");
80
+ }
81
+ /**
82
+ * Execute the `/df-update` command with injected dependencies (pure policy,
83
+ * testable without a plugin context). Check, re-check liveness across the
84
+ * await, then deliver. A delivery failure throws: the check succeeded, only
85
+ * the handoff back failed, and the message says how to recover.
86
+ */
87
+ export async function runUpdateCommand(deps) {
88
+ const drift = await checkTemplateUpdates(deps.directory);
89
+ deps.checkAlive();
90
+ const text = composeUpdatePrompt(drift, deps.directory);
91
+ try {
92
+ await deps.deliver(text, deps.delivery);
93
+ }
94
+ catch (error) {
95
+ const detail = error instanceof Error ? error.message : String(error);
96
+ throw new Error(`df-update detected drift (${drift.refresh.length} to refresh, ${drift.add.length} to add) ` +
97
+ `but the handoff back to the session failed (${detail}); retry /df-update — it only reads, never writes.`);
98
+ }
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,6 +20,13 @@ whenever the user asks for a review of the current changes.
20
20
 
21
21
  ## Steps
22
22
 
23
+ These steps are the orchestrator's. If you are running as one of the
24
+ specialist subagents below, do only your assigned step and report back —
25
+ never consolidate, fix, or re-run anything. Only the orchestrator writes
26
+ the review artifact: as a specialist you never write files, your report
27
+ text is your entire output. This overrides any session duty telling you
28
+ to write the review file.
29
+
23
30
  1. **Scope the change.** Determine exactly what changed:
24
31
 
25
32
  ```bash
@@ -39,6 +46,9 @@ whenever the user asks for a review of the current changes.
39
46
  - **code-reviewer** — general correctness: bugs, logic errors, security,
40
47
  resource/concurrency issues. High bar, high signal only.
41
48
 
49
+ On a repeat pass, run only the specialists whose scope changed since
50
+ their last report — reuse fresh reports instead of running them again.
51
+
42
52
  If the `code-reviewer` agent is not installed in this project (or cannot be
43
53
  invoked in the current environment), perform that correctness pass yourself
44
54
  inline: read the diff in full, and for each changed file check for logic
@@ -52,8 +62,9 @@ whenever the user asks for a review of the current changes.
52
62
  now, or state precisely why it does not apply. Do not produce a report of
53
63
  issues you then leave unaddressed.
54
64
 
55
- 5. **Confirm.** Re-run the relevant specialist if you made non-trivial fixes,
56
- until no blocking items remain.
65
+ 5. **Confirm.** Re-run only the specialist relevant to what you fixed,
66
+ until no blocking items remain. Never restart the full set when a
67
+ single area changed — reuse the fresh reports.
57
68
 
58
69
  ## Output
59
70