opencode-dev-framework 1.5.1 → 1.7.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.
@@ -0,0 +1,116 @@
1
+ import { normalizeCommandMap } from "./command-utils.js";
2
+ /**
3
+ * Config-weakening detection (plan 17 §2).
4
+ *
5
+ * The duties document (`.opencode-dev-framework.yml`) is freely rewritable
6
+ * mid-session and reloads on mtime — deleting checks, dropping
7
+ * `require_review`, or lowering `max_blocks` silently moves the goalposts.
8
+ * Rewriting the duties to make them pass is the canonical duty-escape, so
9
+ * the session-start contract is snapshotted and any mid-session reduction
10
+ * is surfaced in the gate summary. Detection, not prevention: edits stay
11
+ * allowed (agent-driven flows like `df init` must keep working); the gate
12
+ * just refuses to pass a weakened contract silently.
13
+ *
14
+ * Only monotonic weakenings are flagged (removed checks, disabled flags,
15
+ * lowered budgets). Command *modifications* (`npm test` → `vitest run`)
16
+ * are ambiguous — possibly a legitimate toolchain fix — and are left
17
+ * unflagged by design; see the limitation note on `diffWeakening`.
18
+ */
19
+ const PROFILE_STRICTNESS = {
20
+ off: 0,
21
+ advisory: 1,
22
+ standard: 2,
23
+ strict: 3,
24
+ };
25
+ /** Project the enforceable subset out of a resolved config. Pure. */
26
+ export function snapshotEnforceable(config) {
27
+ const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
28
+ return {
29
+ profile: config.profile,
30
+ runTypecheck: config.gate.run_typecheck,
31
+ runTests: config.gate.run_tests,
32
+ lintChanged: config.gate.lint_changed,
33
+ requireReview: config.gate.require_review,
34
+ blockOnFailure: config.gate.block_on_failure,
35
+ scope: config.gate.scope,
36
+ maxBlocks: config.gate.max_blocks,
37
+ hasTypecheck: config.commands.typecheck !== undefined,
38
+ hasTest: config.commands.test !== undefined,
39
+ hasTestChanged: config.commands.test_changed !== undefined,
40
+ hasLint: defaultLint !== undefined || Object.keys(byExtension).length > 0,
41
+ acceptance: Object.fromEntries(config.gate.acceptance.map((c) => [c.name, c.command])),
42
+ preflightCount: config.preflight.length,
43
+ };
44
+ }
45
+ function hasLintNow(config) {
46
+ const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
47
+ return defaultLint !== undefined || Object.keys(byExtension).length > 0;
48
+ }
49
+ /**
50
+ * Diff a session-start snapshot against the live config, returning one
51
+ * human-readable line per duty reduction. Empty means the contract is
52
+ * intact (or was only strengthened). Pure.
53
+ *
54
+ * Deliberate limitations:
55
+ * - Command *modifications* are not flagged — only removals. A changed
56
+ * command string cannot be judged statically.
57
+ * - Acceptance command edits for a retained name are not flagged, for
58
+ * the same reason; only removed names are.
59
+ * - A weakened profile reports as a single profile line; field-level
60
+ * cascades (e.g. `block_on_failure` flipping with the profile
61
+ * default) are suppressed as noise.
62
+ */
63
+ export function diffWeakening(before, after) {
64
+ if (PROFILE_STRICTNESS[after.profile] < PROFILE_STRICTNESS[before.profile]) {
65
+ return [`profile was weakened (${before.profile} → ${after.profile})`];
66
+ }
67
+ const lines = [];
68
+ const flag = (was, is, label) => {
69
+ if (was && !is)
70
+ lines.push(`${label} was disabled (true → false)`);
71
+ };
72
+ flag(before.runTypecheck, after.gate.run_typecheck, "run_typecheck");
73
+ flag(before.runTests, after.gate.run_tests, "run_tests");
74
+ flag(before.lintChanged, after.gate.lint_changed, "lint_changed");
75
+ if (before.requireReview && !after.gate.require_review) {
76
+ lines.push("require_review was dropped (true → false)");
77
+ }
78
+ flag(before.blockOnFailure, after.gate.block_on_failure, "block_on_failure");
79
+ if (before.scope === "all" &&
80
+ after.gate.scope === "changed" &&
81
+ after.commands.test_changed === undefined) {
82
+ lines.push('scope changed to "changed" with no test_changed command — the test step will now skip');
83
+ }
84
+ if (after.gate.max_blocks < before.maxBlocks) {
85
+ lines.push(`max_blocks was lowered (${before.maxBlocks} → ${after.gate.max_blocks})`);
86
+ }
87
+ if (after.gate.run_typecheck && before.hasTypecheck && after.commands.typecheck === undefined) {
88
+ lines.push("typecheck command was removed — the typecheck step will now skip");
89
+ }
90
+ if (after.gate.run_tests) {
91
+ if (after.gate.scope === "changed" &&
92
+ before.hasTestChanged &&
93
+ after.commands.test_changed === undefined) {
94
+ lines.push("test_changed command was removed — the test step will now skip");
95
+ }
96
+ else if (after.gate.scope !== "changed" &&
97
+ before.hasTest &&
98
+ after.commands.test === undefined) {
99
+ lines.push("test command was removed — the test step will now skip");
100
+ }
101
+ }
102
+ if (after.gate.lint_changed && before.hasLint && !hasLintNow(after)) {
103
+ lines.push("lint commands were removed — changed-file lint will now skip");
104
+ }
105
+ const afterNames = new Set(after.gate.acceptance.map((c) => c.name));
106
+ for (const name of Object.keys(before.acceptance)) {
107
+ if (!afterNames.has(name)) {
108
+ lines.push(`acceptance check "${name}" was removed`);
109
+ }
110
+ }
111
+ if (after.preflight.length < before.preflightCount) {
112
+ const taskWord = before.preflightCount - after.preflight.length === 1 ? "task" : "tasks";
113
+ lines.push(`preflight ${taskWord} were reduced (${before.preflightCount} → ${after.preflight.length})`);
114
+ }
115
+ return lines;
116
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-dev-framework",
3
- "version": "1.5.1",
3
+ "version": "1.7.0",
4
4
  "description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,9 +20,10 @@ detection alone. Also when the existing config smells wrong — gate
20
20
  passing vacuously, commands that don't match CI, a red tree nobody can
21
21
  explain.
22
22
 
23
- ## Wizard brief (when `df init --wizard` ran first)
23
+ ## Wizard brief (when setup ran first)
24
24
 
25
- The brief hands you machine-generated hints: detected language, guessed
25
+ `/df-init`, `dev_framework_init` (with `wizard: true`), or `df init --wizard`
26
+ hand you machine-generated hints before this skill runs: detected language, guessed
26
27
  commands with trial-run results, Makefile target names, the shared
27
28
  enforceability verdict, and at most 3 open questions. Treat it as a
28
29
  starting brief, not findings: