opencode-dev-framework 1.3.0 → 1.5.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.
- package/README.md +18 -3
- package/dist/command-utils.d.ts +7 -0
- package/dist/command-utils.js +12 -0
- package/dist/gate.d.ts +5 -0
- package/dist/gate.js +57 -10
- package/dist/harness.js +9 -1
- package/dist/lint.d.ts +4 -0
- package/dist/lint.js +23 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,11 +29,26 @@ npm install opencode-dev-framework
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
npx df init
|
|
32
|
+
npx df init --wizard
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
Three ways in, same gate out — pick by how much attention you want to spend:
|
|
36
|
+
|
|
37
|
+
- **Wizard (recommended).** `--wizard` scaffolds, trial-runs the detected
|
|
38
|
+
commands, and hands your session agent a brief: what was detected, what
|
|
39
|
+
passed, Makefile targets worth mapping to wrappers, at most 3 open
|
|
40
|
+
questions. The agent resolves what it can, asks only genuinely
|
|
41
|
+
user-only questions, and ends with a config + hardening draft for your
|
|
42
|
+
review. Budget ~5 minutes, review-only at the end; imperfections
|
|
43
|
+
assumed, manual always possible.
|
|
44
|
+
- **Fast.** `df init` alone: scaffold + trial-run with PASS/FAIL per
|
|
45
|
+
command. Good guesses arrive verified, bad ones arrive flagged — but
|
|
46
|
+
mapping wrappers (e.g. `make check`) is on you.
|
|
47
|
+
- **Thorough.** Ask the agent to follow the `project-config` skill from
|
|
48
|
+
scratch: reads your Makefile, CI, and CONTRIBUTING, maps the real
|
|
49
|
+
verification commands, drafts `hardening.md`, presents the diff.
|
|
50
|
+
|
|
51
|
+
Then start a session in your project and ask
|
|
37
52
|
the agent for a small edit. You will see the plugin working: the edit is
|
|
38
53
|
checked against guardrails before it lands, your linter runs on the edited
|
|
39
54
|
file, and when the session goes idle the completion gate runs your
|
package/dist/command-utils.d.ts
CHANGED
|
@@ -8,6 +8,13 @@ export interface NormalizedCommandMap {
|
|
|
8
8
|
* may contain a `default` key plus per-extension overrides.
|
|
9
9
|
*/
|
|
10
10
|
export declare function normalizeCommandMap(map: CommandMap | undefined): NormalizedCommandMap;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a tracked file path against the project directory. Absolute paths
|
|
13
|
+
* pass through; relative paths join onto `cwd`. Without `cwd` the relative
|
|
14
|
+
* path passes through untouched (resolves against the process cwd) — both
|
|
15
|
+
* production callers always set it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toAbsolutePath(filePath: string, cwd?: string): string;
|
|
11
18
|
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
12
19
|
export declare function splitCommand(command: string): string[];
|
|
13
20
|
export interface GlobMatcher {
|
package/dist/command-utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute, join } from "node:path";
|
|
1
2
|
import picomatch from "picomatch";
|
|
2
3
|
/**
|
|
3
4
|
* Normalize a command map: a plain string becomes the default command; a record
|
|
@@ -13,6 +14,17 @@ export function normalizeCommandMap(map) {
|
|
|
13
14
|
const { default: defaultCommand, ...byExtension } = map;
|
|
14
15
|
return defaultCommand === undefined ? { byExtension } : { default: defaultCommand, byExtension };
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a tracked file path against the project directory. Absolute paths
|
|
19
|
+
* pass through; relative paths join onto `cwd`. Without `cwd` the relative
|
|
20
|
+
* path passes through untouched (resolves against the process cwd) — both
|
|
21
|
+
* production callers always set it.
|
|
22
|
+
*/
|
|
23
|
+
export function toAbsolutePath(filePath, cwd) {
|
|
24
|
+
if (isAbsolute(filePath))
|
|
25
|
+
return filePath;
|
|
26
|
+
return cwd !== undefined ? join(cwd, filePath) : filePath;
|
|
27
|
+
}
|
|
16
28
|
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
17
29
|
export function splitCommand(command) {
|
|
18
30
|
const tokens = [];
|
package/dist/gate.d.ts
CHANGED
|
@@ -61,6 +61,11 @@ export interface GateOptions {
|
|
|
61
61
|
* concurrently while the reported step order stays stable (typecheck, test,
|
|
62
62
|
* lint per file, acceptance in declaration order). All results are
|
|
63
63
|
* aggregated — a failing step does not abort the remaining steps.
|
|
64
|
+
* `changedFiles` carries the full session journal, deletions included:
|
|
65
|
+
* a deleted file can break dependents, so typecheck/test still run.
|
|
66
|
+
* Only path-consuming legs filter: `{files}` substitution drops
|
|
67
|
+
* nonexistent paths (runners cannot take them), and `lintFile` skips
|
|
68
|
+
* deleted entries (there is nothing to lint).
|
|
64
69
|
*/
|
|
65
70
|
export declare function runGate(run: RunCommand, config: ResolvedConfig, changedFiles: string[], options?: GateOptions): Promise<GateReport>;
|
|
66
71
|
/** One-line-per-step summary of a gate report for logging. */
|
package/dist/gate.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* - `session.idle` event net: re-prompt fallback for the boundaries the
|
|
9
9
|
* hook skips.
|
|
10
10
|
*/
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
11
12
|
import { isAbsolute, relative } from "node:path";
|
|
12
|
-
import { splitCommand } from "./command-utils.js";
|
|
13
|
+
import { splitCommand, toAbsolutePath } from "./command-utils.js";
|
|
13
14
|
import { lintFile, MAX_CONCURRENT_LINTS } from "./lint.js";
|
|
14
15
|
/** Fallback per-command timeout (seconds) when `gate.timeout` is unset. */
|
|
15
16
|
export const DEFAULT_GATE_TIMEOUT_SECONDS = 300;
|
|
@@ -44,6 +45,16 @@ export function createChangedFileTracker() {
|
|
|
44
45
|
function isFailure(result) {
|
|
45
46
|
return result.timedOut || result.exitCode !== 0;
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* True when any of a step's substituted inputs vanished mid-run: the failure
|
|
50
|
+
* may blame a ghost rather than the tree. Callers convert such failures to
|
|
51
|
+
* skips — the next idle re-evaluates with the ghost filtered out, so a
|
|
52
|
+
* genuine failure is only ever deferred by one idle, never masked. Steps
|
|
53
|
+
* whose commands name no files cannot race this way.
|
|
54
|
+
*/
|
|
55
|
+
function ghostRace(files, cwd) {
|
|
56
|
+
return files.some((file) => !existsSync(toAbsolutePath(file, cwd)));
|
|
57
|
+
}
|
|
47
58
|
/**
|
|
48
59
|
* Substitute the `{files}` token with the changed-file list. A token that is
|
|
49
60
|
* exactly `{files}` expands to multiple argv entries (the commands run
|
|
@@ -77,6 +88,11 @@ async function mapBounded(items, limit, fn) {
|
|
|
77
88
|
* concurrently while the reported step order stays stable (typecheck, test,
|
|
78
89
|
* lint per file, acceptance in declaration order). All results are
|
|
79
90
|
* aggregated — a failing step does not abort the remaining steps.
|
|
91
|
+
* `changedFiles` carries the full session journal, deletions included:
|
|
92
|
+
* a deleted file can break dependents, so typecheck/test still run.
|
|
93
|
+
* Only path-consuming legs filter: `{files}` substitution drops
|
|
94
|
+
* nonexistent paths (runners cannot take them), and `lintFile` skips
|
|
95
|
+
* deleted entries (there is nothing to lint).
|
|
80
96
|
*/
|
|
81
97
|
export async function runGate(run, config, changedFiles, options) {
|
|
82
98
|
if (!config.gate) {
|
|
@@ -115,12 +131,31 @@ export async function runGate(run, config, changedFiles, options) {
|
|
|
115
131
|
};
|
|
116
132
|
}
|
|
117
133
|
}
|
|
134
|
+
// Ghost entries (tracked files deleted mid-session) are filtered out of
|
|
135
|
+
// `{files}` substitution inputs only: commands cannot run against paths
|
|
136
|
+
// that aren't there. Typecheck/test still run (a deletion can break
|
|
137
|
+
// dependents); the lint loop still sees the full list so ghosts surface
|
|
138
|
+
// as visible skips. Existence is checked here, not in the harness, so
|
|
139
|
+
// the journal semantics of `changedFiles` stay intact for skip_unchanged,
|
|
140
|
+
// review, signature, and verdict consumers.
|
|
141
|
+
const existingFiles = changedFiles.filter((file) => existsSync(toAbsolutePath(file, options?.cwd)));
|
|
118
142
|
if (config.gate.run_tests) {
|
|
119
143
|
const template = config.gate.scope === "changed" ? config.commands.test_changed : config.commands.test;
|
|
120
144
|
if (template !== undefined) {
|
|
121
|
-
const
|
|
145
|
+
const substituted = template.includes("{files}") ? existingFiles : [];
|
|
146
|
+
const command = substituteFiles(template, existingFiles);
|
|
122
147
|
independent.push(run(command, runOptions).then((result) => {
|
|
123
|
-
|
|
148
|
+
if (isFailure(result) && ghostRace(substituted, options?.cwd)) {
|
|
149
|
+
testStep = {
|
|
150
|
+
name: "test",
|
|
151
|
+
command,
|
|
152
|
+
skipped: true,
|
|
153
|
+
reason: "inputs changed mid-run (tracked file deleted)",
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
testStep = { name: "test", command, skipped: false, result };
|
|
158
|
+
}
|
|
124
159
|
}));
|
|
125
160
|
}
|
|
126
161
|
else {
|
|
@@ -161,13 +196,25 @@ export async function runGate(run, config, changedFiles, options) {
|
|
|
161
196
|
// remaining steps. `{files}` substitution and the project `cwd` match the
|
|
162
197
|
// test-command semantics; per-check timeout overrides the gate default.
|
|
163
198
|
for (const check of config.gate.acceptance) {
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
199
|
+
const substituted = check.command.includes("{files}") ? existingFiles : [];
|
|
200
|
+
const command = substituteFiles(check.command, existingFiles);
|
|
201
|
+
const result = await run(command, { cwd: options?.cwd, timeout: check.timeout ?? timeout });
|
|
202
|
+
if (isFailure(result) && ghostRace(substituted, options?.cwd)) {
|
|
203
|
+
steps.push({
|
|
204
|
+
name: `acceptance:${check.name}`,
|
|
205
|
+
command,
|
|
206
|
+
skipped: true,
|
|
207
|
+
reason: "inputs changed mid-run (tracked file deleted)",
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
steps.push({
|
|
212
|
+
name: `acceptance:${check.name}`,
|
|
213
|
+
command,
|
|
214
|
+
skipped: false,
|
|
215
|
+
result,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
171
218
|
}
|
|
172
219
|
const ran = steps.some((step) => !step.skipped);
|
|
173
220
|
const failedSteps = steps.filter((step) => !step.skipped && step.result !== undefined && isFailure(step.result));
|
package/dist/harness.js
CHANGED
|
@@ -153,7 +153,15 @@ async function passCacheKey(config, directory, changedFiles, reviewRequired) {
|
|
|
153
153
|
const s = await stat(join(directory, file));
|
|
154
154
|
parts.push(`${file}:${s.mtimeMs}:${s.size}`);
|
|
155
155
|
}
|
|
156
|
-
catch {
|
|
156
|
+
catch (error) {
|
|
157
|
+
// A deleted file is known state (gone), not unknown state: finger-
|
|
158
|
+
// print the deletion itself so a clean pass stays cacheable, and so
|
|
159
|
+
// a deletion vs. an empty list never share a key. Any other stat
|
|
160
|
+
// failure still bails — the tree may be unreadable.
|
|
161
|
+
if (error?.code === "ENOENT") {
|
|
162
|
+
parts.push(`${file}:deleted`);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
157
165
|
return null;
|
|
158
166
|
}
|
|
159
167
|
}
|
package/dist/lint.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ export declare function detectPreCommitAvailability(run: RunCommand, directory?:
|
|
|
54
54
|
/**
|
|
55
55
|
* Lint a single file. Excluded files and file types without a configured
|
|
56
56
|
* linter are skipped; everything else runs through the injected runner.
|
|
57
|
+
* Files that no longer exist (deleted mid-session but still tracked) are
|
|
58
|
+
* skipped with reason "file no longer exists" — never failed. Relative
|
|
59
|
+
* `filePath` values resolve against `options.cwd`; both production callers
|
|
60
|
+
* always set it.
|
|
57
61
|
*/
|
|
58
62
|
export declare function lintFile(run: RunCommand, config: ResolvedConfig, filePath: string, options?: {
|
|
59
63
|
cwd?: string;
|
package/dist/lint.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* through an injectable command runner. Pure orchestration — the OpenCode
|
|
4
4
|
* hook wiring lives in src/index.ts.
|
|
5
5
|
*/
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
6
7
|
import { basename, dirname, extname, isAbsolute, relative } from "node:path";
|
|
7
|
-
import { compileGlobMatchers, normalizeCommandMap, splitCommand } from "./command-utils.js";
|
|
8
|
+
import { compileGlobMatchers, normalizeCommandMap, splitCommand, toAbsolutePath, } from "./command-utils.js";
|
|
8
9
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
9
10
|
export const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
10
11
|
/** Cap on concurrent linter subprocesses; per-edit and gate lints share one limiter per session. */
|
|
@@ -93,6 +94,10 @@ export async function detectPreCommitAvailability(run, directory) {
|
|
|
93
94
|
/**
|
|
94
95
|
* Lint a single file. Excluded files and file types without a configured
|
|
95
96
|
* linter are skipped; everything else runs through the injected runner.
|
|
97
|
+
* Files that no longer exist (deleted mid-session but still tracked) are
|
|
98
|
+
* skipped with reason "file no longer exists" — never failed. Relative
|
|
99
|
+
* `filePath` values resolve against `options.cwd`; both production callers
|
|
100
|
+
* always set it.
|
|
96
101
|
*/
|
|
97
102
|
export async function lintFile(run, config, filePath, options) {
|
|
98
103
|
const excluded = matchExclude(config, filePath, options?.cwd);
|
|
@@ -106,10 +111,27 @@ export async function lintFile(run, config, filePath, options) {
|
|
|
106
111
|
if (command === undefined) {
|
|
107
112
|
return { skipped: true, reason: "no lint command configured for this file type", filePath };
|
|
108
113
|
}
|
|
114
|
+
// Ghost entries: the tracker holds every file touched this session and
|
|
115
|
+
// only clears on pass, so files deleted mid-session are still listed.
|
|
116
|
+
// There is nothing to lint in a file that isn't there — skip, never fail.
|
|
117
|
+
// (A file deleted between this probe and the linter spawn is excused by
|
|
118
|
+
// the re-probe below.)
|
|
119
|
+
const absolute = toAbsolutePath(filePath, options?.cwd);
|
|
120
|
+
if (!existsSync(absolute)) {
|
|
121
|
+
return { skipped: true, reason: "file no longer exists", filePath };
|
|
122
|
+
}
|
|
109
123
|
const result = await run(command, {
|
|
110
124
|
cwd: options?.cwd,
|
|
111
125
|
timeout: options?.timeout ?? DEFAULT_LINT_TIMEOUT_SECONDS,
|
|
112
126
|
});
|
|
127
|
+
if (result.timedOut || result.exitCode !== 0) {
|
|
128
|
+
// TOCTOU safety net: the file may have vanished between the probe
|
|
129
|
+
// above and the linter spawn. A missing file can never be at fault,
|
|
130
|
+
// so re-probe before blaming it — skip rather than fail on a ghost.
|
|
131
|
+
if (!existsSync(absolute)) {
|
|
132
|
+
return { skipped: true, reason: "file no longer exists", filePath };
|
|
133
|
+
}
|
|
134
|
+
}
|
|
113
135
|
return { skipped: false, filePath, command, result };
|
|
114
136
|
}
|
|
115
137
|
/** True when a lint outcome represents a failure (non-zero exit or timeout). */
|