opencode-dev-framework 0.1.6 → 0.1.12
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 +64 -13
- package/bin/df +129 -0
- package/dist/config.js +16 -11
- package/dist/detect.d.ts +26 -0
- package/dist/detect.js +183 -0
- package/dist/gate.d.ts +6 -4
- package/dist/gate.js +6 -4
- package/dist/index.d.ts +20 -5
- package/dist/index.js +81 -34
- package/dist/installer.d.ts +50 -0
- package/dist/installer.js +287 -0
- package/dist/lint.d.ts +6 -0
- package/dist/lint.js +14 -1
- package/dist/logger.d.ts +4 -2
- package/dist/logger.js +11 -4
- package/dist/registry.d.ts +25 -0
- package/dist/registry.js +40 -0
- package/dist/rules.d.ts +24 -10
- package/dist/rules.js +140 -33
- package/dist/tools.d.ts +3 -0
- package/dist/tools.js +80 -0
- package/dist/types.d.ts +12 -5
- package/package.json +7 -3
- package/rules/00-activation.md +36 -0
- package/rules/10-quality-bar.md +34 -0
- package/rules/20-match-existing-patterns.md +41 -0
- package/rules/30-testing-discipline.md +41 -0
- package/rules/40-delegation.md +50 -0
- package/templates/.opencode/agents/pattern-guardian.md +78 -0
- package/templates/.opencode/agents/style-enforcer.md +75 -0
- package/templates/.opencode/agents/test-grounder.md +71 -0
- package/templates/.opencode/commands/df-profile.md +7 -0
- package/templates/.opencode/commands/df-verify.md +8 -0
- package/templates/.opencode/opencode-dev-framework/rules/.gitkeep +0 -0
- package/templates/.opencode/skills/ground-in-tests/SKILL.md +53 -0
- package/templates/.opencode/skills/match-patterns/SKILL.md +60 -0
- package/templates/.opencode/skills/peer-review/SKILL.md +56 -0
- package/commands/df-verify.md +0 -5
- package/rules/constitution.md +0 -23
package/dist/registry.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-directory hook state registry. OpenCode's effect runtime can strip
|
|
3
|
+
* closure variables when invoking hooks asynchronously, so we store the state
|
|
4
|
+
* in module-level maps and look it up at call time.
|
|
5
|
+
*/
|
|
6
|
+
const hookRegistry = new Map();
|
|
7
|
+
let activeDirectory = null;
|
|
8
|
+
export function setHookState(directory, state) {
|
|
9
|
+
hookRegistry.set(directory, state);
|
|
10
|
+
activeDirectory = directory;
|
|
11
|
+
}
|
|
12
|
+
export function getHookState(directoryHint) {
|
|
13
|
+
const directory = directoryHint ?? activeDirectory;
|
|
14
|
+
if (!directory) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return hookRegistry.get(directory) ?? null;
|
|
18
|
+
}
|
|
19
|
+
export function updateHookState(directory, updates) {
|
|
20
|
+
const state = hookRegistry.get(directory);
|
|
21
|
+
if (!state) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const next = { ...state, ...updates };
|
|
25
|
+
hookRegistry.set(directory, next);
|
|
26
|
+
return next;
|
|
27
|
+
}
|
|
28
|
+
/** Map session IDs to their project directory so hooks that only receive a
|
|
29
|
+
* session ID can still find their state. */
|
|
30
|
+
const sessionToDirectory = new Map();
|
|
31
|
+
export function setSessionDirectory(sessionID, directory) {
|
|
32
|
+
sessionToDirectory.set(sessionID, directory);
|
|
33
|
+
}
|
|
34
|
+
export function getDirectoryForSession(sessionID) {
|
|
35
|
+
return sessionToDirectory.get(sessionID) ?? null;
|
|
36
|
+
}
|
|
37
|
+
/** Forget a session's directory mapping (called on `session.deleted`). */
|
|
38
|
+
export function clearSessionDirectory(sessionID) {
|
|
39
|
+
sessionToDirectory.delete(sessionID);
|
|
40
|
+
}
|
package/dist/rules.d.ts
CHANGED
|
@@ -1,26 +1,40 @@
|
|
|
1
1
|
import type { ResolvedConfig } from "./types.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Built code lives in `dist/`, so `../rules
|
|
5
|
-
*
|
|
6
|
-
* relative to `src/`.
|
|
3
|
+
* Directory containing the constitution bundled with the plugin package.
|
|
4
|
+
* Built code lives in `dist/`, so `../rules` resolves to the package root at
|
|
5
|
+
* runtime; during tests (ts source) it resolves the same way relative to `src/`.
|
|
7
6
|
*/
|
|
8
|
-
export declare const
|
|
7
|
+
export declare const BUNDLED_CONSTITUTION_DIR: string;
|
|
8
|
+
/** Namespaced directory inside the project for local rule overrides. */
|
|
9
|
+
export declare const LOCAL_RULES_DIR = ".opencode/opencode-dev-framework/rules";
|
|
10
|
+
/** Default style-guide filenames the plugin auto-discovers. */
|
|
11
|
+
export declare const STYLE_GUIDE_CANDIDATES: string[];
|
|
9
12
|
export interface ConstitutionResult {
|
|
10
13
|
/** Constitution text to inject, or null when nothing should be injected. */
|
|
11
14
|
constitution: string | null;
|
|
12
15
|
source: "custom" | "bundled" | null;
|
|
13
|
-
/** Human-readable warning when a configured
|
|
16
|
+
/** Human-readable warning when a configured rule file could not be read. */
|
|
14
17
|
warning?: string;
|
|
15
18
|
}
|
|
16
19
|
/**
|
|
17
20
|
* Loads the constitution to inject for a session.
|
|
18
21
|
*
|
|
19
22
|
* - `off` profile never injects anything.
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* - Explicit `rules` config wins:
|
|
24
|
+
* - `rules` as an array (or `mode: replace`) loads only those rule files.
|
|
25
|
+
* - `rules: { mode: append, files: [...] }` loads the bundled/local rules
|
|
26
|
+
* first, then the listed files.
|
|
27
|
+
* - If no explicit `rules` config is set, the plugin auto-discovers
|
|
28
|
+
* `.opencode/opencode-dev-framework/rules/*.md` in the project root. If that
|
|
29
|
+
* directory exists and contains markdown files, it replaces the bundled
|
|
30
|
+
* rules.
|
|
31
|
+
* - If no local override exists, the bundled `rules/*.md` files are used.
|
|
32
|
+
* - Missing rule files produce warnings but do not stop other files from
|
|
33
|
+
* loading.
|
|
34
|
+
* - `style_guide` config always wins. When it is not set, the plugin
|
|
35
|
+
* auto-discovers `STYLE.md`, `CONTRIBUTING.md`, `docs/STYLE.md`, or
|
|
36
|
+
* `docs/CONTRIBUTING.md` in the project root and appends it under a
|
|
37
|
+
* "Style Guide" heading.
|
|
24
38
|
*/
|
|
25
39
|
export declare function loadConstitution(config: ResolvedConfig, directory?: string): Promise<ConstitutionResult>;
|
|
26
40
|
/**
|
package/dist/rules.js
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
1
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Built code lives in `dist/`, so `../rules
|
|
7
|
-
*
|
|
8
|
-
* relative to `src/`.
|
|
5
|
+
* Directory containing the constitution bundled with the plugin package.
|
|
6
|
+
* Built code lives in `dist/`, so `../rules` resolves to the package root at
|
|
7
|
+
* runtime; during tests (ts source) it resolves the same way relative to `src/`.
|
|
9
8
|
*/
|
|
10
|
-
export const
|
|
11
|
-
|
|
9
|
+
export const BUNDLED_CONSTITUTION_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "rules");
|
|
10
|
+
/** Namespaced directory inside the project for local rule overrides. */
|
|
11
|
+
export const LOCAL_RULES_DIR = ".opencode/opencode-dev-framework/rules";
|
|
12
|
+
/** Default style-guide filenames the plugin auto-discovers. */
|
|
13
|
+
export const STYLE_GUIDE_CANDIDATES = [
|
|
14
|
+
"STYLE.md",
|
|
15
|
+
"docs/STYLE.md",
|
|
16
|
+
"CONTRIBUTING.md",
|
|
17
|
+
"docs/CONTRIBUTING.md",
|
|
18
|
+
];
|
|
19
|
+
async function readRuleFile(path) {
|
|
12
20
|
try {
|
|
13
21
|
const content = await readFile(path, "utf8");
|
|
14
22
|
return content.trim() === "" ? null : content;
|
|
@@ -17,49 +25,148 @@ async function readConstitution(path) {
|
|
|
17
25
|
return null;
|
|
18
26
|
}
|
|
19
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads all `.md` files in a directory and concatenates them in sorted order,
|
|
30
|
+
* separated by blank lines. Returns null when the directory is missing or
|
|
31
|
+
* contains no non-empty markdown files.
|
|
32
|
+
*/
|
|
33
|
+
async function readRuleDir(dir) {
|
|
34
|
+
try {
|
|
35
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
36
|
+
const files = entries
|
|
37
|
+
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
|
|
38
|
+
.map((entry) => entry.name)
|
|
39
|
+
.sort();
|
|
40
|
+
if (files.length === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const parts = [];
|
|
44
|
+
for (const name of files) {
|
|
45
|
+
const content = await readFile(join(dir, name), "utf8");
|
|
46
|
+
if (content.trim() !== "") {
|
|
47
|
+
parts.push(content.trim());
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return parts.length === 0 ? null : parts.join("\n\n");
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function readRulesFiles(paths, directory) {
|
|
57
|
+
const parts = [];
|
|
58
|
+
const warnings = [];
|
|
59
|
+
for (const rawPath of paths) {
|
|
60
|
+
const path = isAbsolute(rawPath) ? rawPath : resolve(directory, rawPath);
|
|
61
|
+
const content = await readRuleFile(path);
|
|
62
|
+
if (content !== null) {
|
|
63
|
+
parts.push(content);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
warnings.push(`Could not read rule file ${path}; skipping.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return { content: parts.length === 0 ? null : parts.join("\n\n"), warnings };
|
|
70
|
+
}
|
|
71
|
+
async function discoverStyleGuide(directory) {
|
|
72
|
+
for (const candidate of STYLE_GUIDE_CANDIDATES) {
|
|
73
|
+
const content = await readRuleFile(resolve(directory, candidate));
|
|
74
|
+
if (content !== null) {
|
|
75
|
+
return content;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
20
80
|
/**
|
|
21
81
|
* Loads the constitution to inject for a session.
|
|
22
82
|
*
|
|
23
83
|
* - `off` profile never injects anything.
|
|
24
|
-
* -
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
84
|
+
* - Explicit `rules` config wins:
|
|
85
|
+
* - `rules` as an array (or `mode: replace`) loads only those rule files.
|
|
86
|
+
* - `rules: { mode: append, files: [...] }` loads the bundled/local rules
|
|
87
|
+
* first, then the listed files.
|
|
88
|
+
* - If no explicit `rules` config is set, the plugin auto-discovers
|
|
89
|
+
* `.opencode/opencode-dev-framework/rules/*.md` in the project root. If that
|
|
90
|
+
* directory exists and contains markdown files, it replaces the bundled
|
|
91
|
+
* rules.
|
|
92
|
+
* - If no local override exists, the bundled `rules/*.md` files are used.
|
|
93
|
+
* - Missing rule files produce warnings but do not stop other files from
|
|
94
|
+
* loading.
|
|
95
|
+
* - `style_guide` config always wins. When it is not set, the plugin
|
|
96
|
+
* auto-discovers `STYLE.md`, `CONTRIBUTING.md`, `docs/STYLE.md`, or
|
|
97
|
+
* `docs/CONTRIBUTING.md` in the project root and appends it under a
|
|
98
|
+
* "Style Guide" heading.
|
|
28
99
|
*/
|
|
29
100
|
export async function loadConstitution(config, directory) {
|
|
30
101
|
if (config.profile === "off") {
|
|
31
102
|
return { constitution: null, source: null };
|
|
32
103
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
104
|
+
const cwd = directory ?? process.cwd();
|
|
105
|
+
const warnings = [];
|
|
106
|
+
const parts = [];
|
|
107
|
+
let source = null;
|
|
108
|
+
if (config.rules && config.rules.files.length > 0) {
|
|
109
|
+
const rulesResult = await readRulesFiles(config.rules.files, cwd);
|
|
110
|
+
if (rulesResult.content !== null) {
|
|
111
|
+
parts.push(rulesResult.content);
|
|
112
|
+
source = "custom";
|
|
40
113
|
}
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
114
|
+
warnings.push(...rulesResult.warnings);
|
|
115
|
+
if (config.rules.mode === "append") {
|
|
116
|
+
const local = await readRuleDir(resolve(cwd, LOCAL_RULES_DIR));
|
|
117
|
+
const bundled = await readRuleDir(BUNDLED_CONSTITUTION_DIR);
|
|
118
|
+
const base = local ?? bundled;
|
|
119
|
+
if (base !== null) {
|
|
120
|
+
parts.unshift(base);
|
|
121
|
+
source = local !== null ? "custom" : "bundled";
|
|
122
|
+
}
|
|
48
123
|
}
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const local = await readRuleDir(resolve(cwd, LOCAL_RULES_DIR));
|
|
127
|
+
if (local !== null) {
|
|
128
|
+
parts.push(local);
|
|
129
|
+
source = "custom";
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const bundled = await readRuleDir(BUNDLED_CONSTITUTION_DIR);
|
|
133
|
+
if (bundled !== null) {
|
|
134
|
+
parts.push(bundled);
|
|
135
|
+
source = "bundled";
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (config.style_guide) {
|
|
140
|
+
const stylePath = isAbsolute(config.style_guide)
|
|
141
|
+
? config.style_guide
|
|
142
|
+
: resolve(cwd, config.style_guide);
|
|
143
|
+
const style = await readRuleFile(stylePath);
|
|
144
|
+
if (style !== null) {
|
|
145
|
+
parts.push(`# Style Guide\n\n${style}`);
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
warnings.push(`Could not read style guide at ${stylePath}; skipping.`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
const discovered = await discoverStyleGuide(cwd);
|
|
153
|
+
if (discovered !== null) {
|
|
154
|
+
parts.push(`# Style Guide\n\n${discovered}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (parts.length === 0) {
|
|
49
158
|
return {
|
|
50
159
|
constitution: null,
|
|
51
160
|
source: null,
|
|
52
|
-
warning:
|
|
161
|
+
warning: warnings.length > 0
|
|
162
|
+
? warnings.join("\n")
|
|
163
|
+
: "Could not read the bundled constitution; no constitution injected.",
|
|
53
164
|
};
|
|
54
165
|
}
|
|
55
|
-
const bundled = await readConstitution(BUNDLED_CONSTITUTION_PATH);
|
|
56
|
-
if (bundled !== null) {
|
|
57
|
-
return { constitution: bundled, source: "bundled" };
|
|
58
|
-
}
|
|
59
166
|
return {
|
|
60
|
-
constitution:
|
|
61
|
-
source
|
|
62
|
-
warning:
|
|
167
|
+
constitution: parts.join("\n\n"),
|
|
168
|
+
source,
|
|
169
|
+
warning: warnings.length > 0 ? warnings.join("\n") : undefined,
|
|
63
170
|
};
|
|
64
171
|
}
|
|
65
172
|
/**
|
package/dist/tools.d.ts
ADDED
package/dist/tools.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { tool } from "@opencode-ai/plugin";
|
|
3
|
+
import { loadConfig, clearConfigCache } from "./config.js";
|
|
4
|
+
import { installTemplates, setProfileInFile, writeDetectedConfig } from "./installer.js";
|
|
5
|
+
import { getHookState, updateHookState } from "./registry.js";
|
|
6
|
+
import { loadConstitution } from "./rules.js";
|
|
7
|
+
const PROFILES = ["off", "advisory", "standard", "strict"];
|
|
8
|
+
function isProfile(value) {
|
|
9
|
+
return PROFILES.includes(value);
|
|
10
|
+
}
|
|
11
|
+
export function buildTools(_ctx) {
|
|
12
|
+
return {
|
|
13
|
+
dev_framework_init: tool({
|
|
14
|
+
description: "Scaffold opencode-dev-framework project files (agents, skills, commands, default config) into the current project. Missing files are created; existing files are skipped unless overwrite is true.",
|
|
15
|
+
args: {
|
|
16
|
+
directory: tool.schema
|
|
17
|
+
.string()
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Target project directory (defaults to current project)"),
|
|
20
|
+
overwrite: tool.schema
|
|
21
|
+
.boolean()
|
|
22
|
+
.optional()
|
|
23
|
+
.describe("Overwrite existing files that differ from templates"),
|
|
24
|
+
},
|
|
25
|
+
async execute(args, context) {
|
|
26
|
+
const targetDir = args.directory ?? context.directory;
|
|
27
|
+
const result = await installTemplates(targetDir, {
|
|
28
|
+
overwriteExisting: args.overwrite ?? false,
|
|
29
|
+
skipExisting: !(args.overwrite ?? false),
|
|
30
|
+
});
|
|
31
|
+
const configResult = await writeDetectedConfig(targetDir, {
|
|
32
|
+
overwriteExisting: args.overwrite ?? false,
|
|
33
|
+
skipExisting: !(args.overwrite ?? false),
|
|
34
|
+
});
|
|
35
|
+
const lines = [
|
|
36
|
+
`Installed opencode-dev-framework templates into ${targetDir}.`,
|
|
37
|
+
`Created: ${result.created.length} file(s)`,
|
|
38
|
+
`Overwritten: ${result.overwritten.length} file(s)`,
|
|
39
|
+
`Skipped: ${result.skipped.length} file(s)`,
|
|
40
|
+
`Config: ${configResult.action}`,
|
|
41
|
+
];
|
|
42
|
+
if (result.created.length > 0) {
|
|
43
|
+
lines.push("", "Created files:", ...result.created.map((file) => `- ${file}`));
|
|
44
|
+
}
|
|
45
|
+
if (result.overwritten.length > 0) {
|
|
46
|
+
lines.push("", "Overwritten files:", ...result.overwritten.map((file) => `- ${file}`));
|
|
47
|
+
}
|
|
48
|
+
return lines.join("\n");
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
dev_framework_set_profile: tool({
|
|
52
|
+
description: "Change the opencode-dev-framework profile (off, advisory, standard, strict) for the current project and apply it immediately without restarting OpenCode.",
|
|
53
|
+
args: {
|
|
54
|
+
profile: tool.schema.string().describe("New profile: off, advisory, standard, or strict"),
|
|
55
|
+
directory: tool.schema
|
|
56
|
+
.string()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("Project directory (defaults to current project)"),
|
|
59
|
+
},
|
|
60
|
+
async execute(args, context) {
|
|
61
|
+
const targetDir = args.directory ?? context.directory;
|
|
62
|
+
const profile = args.profile.trim().toLowerCase();
|
|
63
|
+
if (!isProfile(profile)) {
|
|
64
|
+
return `Invalid profile "${args.profile}". Valid values: ${PROFILES.join(", ")}.`;
|
|
65
|
+
}
|
|
66
|
+
const configPath = join(targetDir, ".opencode-dev-framework.yml");
|
|
67
|
+
await setProfileInFile(configPath, profile);
|
|
68
|
+
// Reload config and constitution so the change takes effect immediately.
|
|
69
|
+
clearConfigCache();
|
|
70
|
+
const config = loadConfig(targetDir);
|
|
71
|
+
const { constitution } = await loadConstitution(config, targetDir);
|
|
72
|
+
const state = getHookState(targetDir);
|
|
73
|
+
if (state) {
|
|
74
|
+
updateHookState(targetDir, { config, constitution });
|
|
75
|
+
}
|
|
76
|
+
return `opencode-dev-framework profile set to "${profile}" in ${configPath}. Change applied immediately.`;
|
|
77
|
+
},
|
|
78
|
+
}),
|
|
79
|
+
};
|
|
80
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -38,6 +38,12 @@ export interface OnEditConfig {
|
|
|
38
38
|
format: boolean;
|
|
39
39
|
lint: boolean;
|
|
40
40
|
}
|
|
41
|
+
export interface RulesConfig {
|
|
42
|
+
/** Default is `replace` for the bundled constitution. */
|
|
43
|
+
mode: "replace" | "append";
|
|
44
|
+
/** Paths to Markdown rule files (absolute or relative to project root). */
|
|
45
|
+
files: string[];
|
|
46
|
+
}
|
|
41
47
|
/**
|
|
42
48
|
* Raw config as parsed from a config file. Every field is optional; defaults
|
|
43
49
|
* are applied during resolution (see resolveConfig in config.ts).
|
|
@@ -51,10 +57,11 @@ export interface Config {
|
|
|
51
57
|
gate?: Partial<GateConfig>;
|
|
52
58
|
on_edit?: Partial<OnEditConfig>;
|
|
53
59
|
exclude?: string[];
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
rules?: string[];
|
|
60
|
+
rules?: string[] | RulesConfig;
|
|
61
|
+
/** Path to a project style guide (absolute or relative to project root). */
|
|
57
62
|
style_guide?: string;
|
|
63
|
+
/** Use pre-commit for per-file linting when available (`auto`) or never (`off`). */
|
|
64
|
+
precommit?: "auto" | "off";
|
|
58
65
|
}
|
|
59
66
|
/**
|
|
60
67
|
* Fully resolved config with profile defaults applied. All consumers of the
|
|
@@ -71,7 +78,7 @@ export interface ResolvedConfig {
|
|
|
71
78
|
gate: GateConfig;
|
|
72
79
|
on_edit: OnEditConfig;
|
|
73
80
|
exclude: string[];
|
|
74
|
-
|
|
75
|
-
rules?: string[];
|
|
81
|
+
rules?: RulesConfig;
|
|
76
82
|
style_guide?: string;
|
|
83
|
+
precommit: "auto" | "off";
|
|
77
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-dev-framework",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.12",
|
|
4
4
|
"description": "OpenCode plugin that enforces project-specific quality gates during AI coding sessions",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
15
|
-
"
|
|
16
|
-
"rules"
|
|
15
|
+
"bin",
|
|
16
|
+
"rules",
|
|
17
|
+
"templates"
|
|
17
18
|
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"df": "bin/df"
|
|
21
|
+
},
|
|
18
22
|
"scripts": {
|
|
19
23
|
"build": "tsc -p tsconfig.json",
|
|
20
24
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# OpenCode Dev Framework — Activation Gate
|
|
2
|
+
|
|
3
|
+
You are running with the **opencode-dev-framework** plugin installed. This framework
|
|
4
|
+
enforces disciplined software engineering: a quality bar, close style-guide adherence,
|
|
5
|
+
continuous peer review to prevent code fragmentation and drift, and test-grounded
|
|
6
|
+
completion.
|
|
7
|
+
|
|
8
|
+
## When these rules apply
|
|
9
|
+
|
|
10
|
+
The framework is **ACTIVE** for this session only if **either** of the following is true:
|
|
11
|
+
|
|
12
|
+
- The environment variable `DEV_FRAMEWORK` is set to a non-empty value, **or**
|
|
13
|
+
- A file named `.opencode-dev-framework.yml` exists at the root of the working repository.
|
|
14
|
+
|
|
15
|
+
When the framework is active, the plugin injects a `DEV-FRAMEWORK: ACTIVE` banner at
|
|
16
|
+
the start of the session stating the **profile** in effect — `advisory`, `standard`, or
|
|
17
|
+
`strict`:
|
|
18
|
+
|
|
19
|
+
- **advisory** — you receive formatting, lint, and review feedback, but nothing blocks.
|
|
20
|
+
Treat it as strong guidance.
|
|
21
|
+
- **standard** — feedback as above, plus a completion gate that runs type-check and
|
|
22
|
+
tests and blocks finishing while they are red; protected paths cannot be edited.
|
|
23
|
+
- **strict** — as standard, plus lint of changed files must also pass at the gate.
|
|
24
|
+
|
|
25
|
+
Apply the rules with intensity matching the profile, but the disciplines themselves
|
|
26
|
+
(quality bar, matching patterns, grounding in tests) always hold when active.
|
|
27
|
+
|
|
28
|
+
- **If the session is active**, follow every rule in this set as a hard requirement,
|
|
29
|
+
and use the specialist agents and skills described in `40-delegation` as your default
|
|
30
|
+
working loop.
|
|
31
|
+
- **If the session is NOT active** (no banner, no env var, no config file), treat these
|
|
32
|
+
rules as dormant. Do not change your behavior and do not mention the framework.
|
|
33
|
+
Proceed exactly as you normally would.
|
|
34
|
+
|
|
35
|
+
Never disable, bypass, or talk the user out of an active framework gate. If a hook
|
|
36
|
+
blocks completion, fix the underlying problem rather than working around the gate.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Quality Bar
|
|
2
|
+
|
|
3
|
+
When the framework is active, every change you propose must clear this bar before you
|
|
4
|
+
consider a task done. The goal is output a careful senior engineer on this codebase
|
|
5
|
+
would approve without rework.
|
|
6
|
+
|
|
7
|
+
## Non-negotiables
|
|
8
|
+
|
|
9
|
+
1. **Correctness over completion.** A change that compiles but is unverified is not
|
|
10
|
+
done. Prefer a smaller, fully-correct change to a larger speculative one.
|
|
11
|
+
2. **No broken windows.** Do not leave the tree in a worse state than you found it:
|
|
12
|
+
no failing builds, no failing tests you caused, no dead code you introduced, no
|
|
13
|
+
commented-out experiments, no debug prints.
|
|
14
|
+
3. **Scope discipline.** Make precise, surgical changes that fully address the request.
|
|
15
|
+
Do not refactor unrelated code. If you discover an unrelated bug, note it; do not
|
|
16
|
+
silently expand scope.
|
|
17
|
+
4. **Complete, not minimal.** Within the requested scope, deliver the complete correct
|
|
18
|
+
solution — handle the edge cases and error paths, don't stub them.
|
|
19
|
+
5. **Evidence, not assertion.** Do not claim something works, passes, or is fixed
|
|
20
|
+
unless you have run it and observed the result. See `30-testing-discipline`.
|
|
21
|
+
|
|
22
|
+
## Definition of done (active sessions)
|
|
23
|
+
|
|
24
|
+
A task is done only when:
|
|
25
|
+
|
|
26
|
+
- The change builds / type-checks clean (or the project had no such step).
|
|
27
|
+
- Relevant tests pass, and new behavior has a test that fails without your change.
|
|
28
|
+
- Files you touched are formatted and lint-clean per project tooling.
|
|
29
|
+
- The change matches existing patterns in the surrounding code (see
|
|
30
|
+
`20-match-existing-patterns`).
|
|
31
|
+
- A peer-review pass found no blocking issues (see `40-delegation`).
|
|
32
|
+
|
|
33
|
+
If you cannot meet the bar, stop and tell the user what is blocking you rather than
|
|
34
|
+
declaring success.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Match Existing Patterns (Anti-Fragmentation)
|
|
2
|
+
|
|
3
|
+
The single biggest cause of codebase drift is agents writing *plausible* code instead
|
|
4
|
+
of *consistent* code — re-inventing helpers, introducing a second way to do something
|
|
5
|
+
that already has an established way, and diverging from local conventions. When the
|
|
6
|
+
framework is active, you actively fight this.
|
|
7
|
+
|
|
8
|
+
## Look before you write
|
|
9
|
+
|
|
10
|
+
Before introducing **any** new function, type, abstraction, dependency, config key,
|
|
11
|
+
error pattern, logging call, or file, search the codebase for how this is already done:
|
|
12
|
+
|
|
13
|
+
- Is there an existing utility/helper/service that does this? **Reuse it.**
|
|
14
|
+
- Is there an established pattern for this concern (error handling, validation, data
|
|
15
|
+
access, DI, naming, file layout)? **Follow it**, even if you'd personally prefer
|
|
16
|
+
another style.
|
|
17
|
+
- Is there already a dependency that solves this? **Don't add a new one.**
|
|
18
|
+
|
|
19
|
+
Prefer the conventions of the **immediately surrounding code and the nearest sibling
|
|
20
|
+
files** over global or generic "best practices." Consistency with the local module
|
|
21
|
+
beats theoretical purity.
|
|
22
|
+
|
|
23
|
+
## Concrete rules
|
|
24
|
+
|
|
25
|
+
1. **Reuse before create.** Adding a new helper that duplicates existing behavior is a
|
|
26
|
+
defect. If an existing helper is *almost* right, extend it rather than fork it.
|
|
27
|
+
2. **One way to do a thing.** Do not introduce a second pattern for a concern that
|
|
28
|
+
already has one. If the existing pattern is genuinely inadequate, raise it with the
|
|
29
|
+
user instead of quietly diverging.
|
|
30
|
+
3. **Match names and shapes.** Mirror the naming conventions, file/folder structure,
|
|
31
|
+
import ordering, parameter ordering, and return/error conventions already in use.
|
|
32
|
+
4. **No new dependencies without cause.** Adding a library is a scope and drift
|
|
33
|
+
decision — call it out and justify it; never slip one in.
|
|
34
|
+
5. **When in doubt, copy the neighbor.** Find the closest existing example of the thing
|
|
35
|
+
you're building and follow its structure.
|
|
36
|
+
|
|
37
|
+
## How to verify
|
|
38
|
+
|
|
39
|
+
For non-trivial additions, delegate a check to the **`pattern-guardian`** agent (see
|
|
40
|
+
`40-delegation`). It exists to catch duplication, divergence, and "second way to do it"
|
|
41
|
+
drift that is easy to miss while focused on the immediate task.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Testing Discipline (Ground in Reality)
|
|
2
|
+
|
|
3
|
+
When the framework is active, you ground your claims in observed reality, not in
|
|
4
|
+
plausible-sounding assertions. Running code is the source of truth.
|
|
5
|
+
|
|
6
|
+
## Principles
|
|
7
|
+
|
|
8
|
+
1. **Verify, don't assume.** Never say "this works", "tests pass", "this fixes it", or
|
|
9
|
+
"this should be fine" unless you have just run the relevant command and seen it
|
|
10
|
+
succeed. If you have not run it, say so explicitly.
|
|
11
|
+
2. **New behavior needs a test.** Any behavioral change should come with a test that
|
|
12
|
+
**fails before** your change and **passes after**. If you can't write such a test,
|
|
13
|
+
explain why.
|
|
14
|
+
3. **Reproduce before you fix.** For a bug, first reproduce it (a failing test or a
|
|
15
|
+
concrete command), then fix it, then show the same check now passes.
|
|
16
|
+
4. **Run the narrowest useful check often, the full suite before done.** Iterate with
|
|
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
|
|
19
|
+
address the real cause. Treat a flaky or skipped test as a finding, not a pass.
|
|
20
|
+
|
|
21
|
+
## Use existing tooling only
|
|
22
|
+
|
|
23
|
+
Use the project's existing test/build/lint commands. Do not introduce a new test
|
|
24
|
+
framework, runner, or CI tooling unless the user asks. If the project has no tests at
|
|
25
|
+
all, say so and propose the smallest reasonable way to verify, rather than claiming
|
|
26
|
+
success blind.
|
|
27
|
+
|
|
28
|
+
## The completion gate
|
|
29
|
+
|
|
30
|
+
When the framework is active, a completion gate runs the project's type-check and test
|
|
31
|
+
commands before you finish. If it reports failures:
|
|
32
|
+
|
|
33
|
+
- **Do not** try to disable the gate, weaken the assertion, or mark the test skipped to
|
|
34
|
+
get past it.
|
|
35
|
+
- Read the failure, fix the underlying cause, and let the gate re-run.
|
|
36
|
+
|
|
37
|
+
If you believe a failure is pre-existing and unrelated to your change, prove it (e.g.
|
|
38
|
+
show it fails on a clean tree) and tell the user — don't silently ignore it.
|
|
39
|
+
|
|
40
|
+
For an explicit, thorough verification pass, use the **`ground-in-tests`** skill or the
|
|
41
|
+
**`test-grounder`** agent (see `40-delegation`).
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Delegation — Your Working Loop
|
|
2
|
+
|
|
3
|
+
When the framework is active, you are not a lone coder; you are the lead engineer
|
|
4
|
+
coordinating specialist reviewers. Use them as a continuous loop, not a final
|
|
5
|
+
rubber-stamp. Catching issues early is cheaper than catching them at the gate.
|
|
6
|
+
|
|
7
|
+
## The specialists
|
|
8
|
+
|
|
9
|
+
Invoke these as subagents (delegate the task to them; they investigate and report,
|
|
10
|
+
they do **not** edit code):
|
|
11
|
+
|
|
12
|
+
- **`pattern-guardian`** — checks new/changed code against existing codebase patterns:
|
|
13
|
+
duplication, re-invented helpers, divergent conventions, "second way to do a thing",
|
|
14
|
+
unjustified new dependencies. Use it whenever you add a new abstraction, helper,
|
|
15
|
+
module, or dependency, and before finishing a non-trivial change.
|
|
16
|
+
- **`style-enforcer`** — checks changed files against the project's style guide and the
|
|
17
|
+
conventions of surrounding code (naming, structure, idioms, lint rules). Use it after
|
|
18
|
+
a batch of edits, before the completion gate.
|
|
19
|
+
- **`test-grounder`** — audits whether your claims are backed by evidence: is there a
|
|
20
|
+
test that fails without the change? do the cited commands actually pass? did you
|
|
21
|
+
verify the edge cases? Use it before declaring a task done.
|
|
22
|
+
|
|
23
|
+
You may also use the built-in review or planning agents for a general high-signal
|
|
24
|
+
second opinion — the best moment is after planning, before implementing, and again
|
|
25
|
+
before completion.
|
|
26
|
+
|
|
27
|
+
## When to delegate (default cadence)
|
|
28
|
+
|
|
29
|
+
1. **After planning, before implementing** a non-trivial change → a design sanity check.
|
|
30
|
+
2. **While implementing**, before adding any new helper/abstraction/dependency →
|
|
31
|
+
quick `pattern-guardian` check that you're not duplicating or diverging.
|
|
32
|
+
3. **After a batch of edits** → `style-enforcer` on the changed files.
|
|
33
|
+
4. **Before declaring done** → `test-grounder` (evidence) and a final
|
|
34
|
+
`pattern-guardian` / review pass; resolve every blocking item.
|
|
35
|
+
|
|
36
|
+
Keep delegation proportional: a one-line fix doesn't need the full loop; a new module
|
|
37
|
+
does. Use judgment, but never skip the test-grounding and review steps for behavioral
|
|
38
|
+
changes.
|
|
39
|
+
|
|
40
|
+
## Skills
|
|
41
|
+
|
|
42
|
+
For explicit, repeatable workflows you can invoke the bundled skills:
|
|
43
|
+
**`peer-review`**, **`ground-in-tests`**, and **`match-patterns`**. They codify the
|
|
44
|
+
steps above so you run them consistently.
|
|
45
|
+
|
|
46
|
+
## Acting on feedback
|
|
47
|
+
|
|
48
|
+
Specialist and hook feedback is to be **acted on**, not summarized and ignored. For each
|
|
49
|
+
blocking item: fix it, or explain to the user why it is not applicable. Do not pad your
|
|
50
|
+
response by listing feedback you didn't address.
|