opencode-dev-framework 0.5.1 → 1.1.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 +76 -5
- package/dist/command-utils.d.ts +5 -0
- package/dist/command-utils.js +21 -0
- package/dist/commands.d.ts +23 -7
- package/dist/commands.js +24 -7
- package/dist/config.d.ts +13 -0
- package/dist/config.js +75 -0
- package/dist/format-status.js +1 -0
- package/dist/gate.d.ts +13 -5
- package/dist/gate.js +72 -14
- package/dist/goal.d.ts +101 -0
- package/dist/goal.js +177 -0
- package/dist/harness.d.ts +72 -1
- package/dist/harness.js +169 -15
- package/dist/index.d.ts +16 -0
- package/dist/index.js +86 -8
- package/dist/lint.d.ts +15 -1
- package/dist/lint.js +39 -7
- package/dist/protect.d.ts +2 -1
- package/dist/protect.js +6 -6
- package/dist/rules.d.ts +15 -0
- package/dist/rules.js +20 -1
- package/dist/types.d.ts +18 -0
- package/package.json +1 -1
- package/rules/10-quality-bar.md +6 -0
- package/rules/30-testing-discipline.md +6 -1
- package/rules/40-delegation.md +16 -0
package/README.md
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# opencode-dev-framework
|
|
2
2
|
|
|
3
3
|
An [OpenCode](https://opencode.ai) plugin that enforces project-specific
|
|
4
|
-
quality gates during AI coding sessions
|
|
4
|
+
quality gates during AI coding sessions — and verifies whole tasks, not just
|
|
5
|
+
edits, through `/df-goal`. Inspired by
|
|
5
6
|
[anticomputer/dev-framework](https://github.com/anticomputer/dev-framework),
|
|
6
7
|
reimplemented as an OpenCode-native plugin.
|
|
7
8
|
|
|
@@ -20,7 +21,7 @@ reimplemented as an OpenCode-native plugin.
|
|
|
20
21
|
`pre-commit run --files` when `precommit: auto` is set.
|
|
21
22
|
- **Completion gate.** At the would-go-idle boundary (`session.hook("experimental.idle")`,
|
|
22
23
|
with an `idle` alias registered for a future rename), runs typecheck, tests,
|
|
23
|
-
and (optionally) lint on changed files — changed files are
|
|
24
|
+
named acceptance commands (`gate.acceptance`), and (optionally) lint on changed files — changed files are
|
|
24
25
|
tracked from edit events and cross-checked against `git status`, so the gate cannot
|
|
25
26
|
silently skip due to an event-shape mismatch. In `standard`/`strict`, sessions that
|
|
26
27
|
changed files must also produce a **peer-review artifact**
|
|
@@ -32,6 +33,12 @@ reimplemented as an OpenCode-native plugin.
|
|
|
32
33
|
runs the gate twice, synthetic-first with `prompt` only as fallback.
|
|
33
34
|
`/df-status` shows `Continuation (idle): active` once the hook has completed
|
|
34
35
|
an evaluation, else the event-subscribe fallback.
|
|
36
|
+
- **Verified goals (`/df-goal`).** Runs a whole task — typically a written
|
|
37
|
+
plan — inside a native `/goal` with a verification contract appended:
|
|
38
|
+
the agent must produce a `dev_framework_verify` PASS on the final tree,
|
|
39
|
+
and the native reviewer weighs that tool result as completion evidence.
|
|
40
|
+
Refuses vacuous configs, non-blocking profiles, and goal-less cores
|
|
41
|
+
instead of starting an unverified substitute. See *Slash commands* below.
|
|
35
42
|
- **Pre-flight gate (optional).** When a `preflight:` task list is configured, edit
|
|
36
43
|
tools are **denied** (standard/strict) until the agent writes its pre-flight findings
|
|
37
44
|
to `.opencode/opencode-dev-framework/preflight.md`. Use it for work that requires
|
|
@@ -48,9 +55,32 @@ reimplemented as an OpenCode-native plugin.
|
|
|
48
55
|
- **Slash commands.** The plugin registers four TUI commands that open instant
|
|
49
56
|
modal dialogs and never feed anything to the LLM: `/df-status`, `/df-help`,
|
|
50
57
|
`/df-profile` (bare for a picker, or with an argument), and `/df-verify`
|
|
51
|
-
(runs the gate manually).
|
|
58
|
+
(runs the gate manually). `/df-goal <objective>` is a server-side command
|
|
59
|
+
instead: it starts a verified native goal (see *Slash commands* below). The `dev_framework_*` custom *tools* above remain
|
|
52
60
|
available for in-agent use.
|
|
53
61
|
|
|
62
|
+
### How it fits together
|
|
63
|
+
|
|
64
|
+
```mermaid
|
|
65
|
+
flowchart TD
|
|
66
|
+
G["/df-goal plan"] --> N["native /goal\nowns state + review"]
|
|
67
|
+
N --> A["agent implements"]
|
|
68
|
+
A --> B{"tool.execute.before"}
|
|
69
|
+
B -- "deny: protected /\ndangerous / pre-flight" --> X["blocked before landing"]
|
|
70
|
+
B -- allow --> C["edit lands"]
|
|
71
|
+
C --> D["per-edit lint\n+ change tracker"]
|
|
72
|
+
D --> V["agent runs\ndev_framework_verify"]
|
|
73
|
+
V --> R{"verdict"}
|
|
74
|
+
R -- PASS --> N
|
|
75
|
+
R -- FAIL --> A
|
|
76
|
+
D --> S{"session idle"}
|
|
77
|
+
S --> GT["completion gate\nsame full contract"]
|
|
78
|
+
GT -- PASS --> DONE["done"]
|
|
79
|
+
GT -- "FAIL, within max_blocks" --> SYN["synthetic continuation"]
|
|
80
|
+
SYN --> A
|
|
81
|
+
GT -- "FAIL, past max_blocks" --> SD["stand down:\nhonest unmet report"]
|
|
82
|
+
```
|
|
83
|
+
|
|
54
84
|
## Profiles
|
|
55
85
|
|
|
56
86
|
| Profile | Guardrails | Gate failures | Lint on edit | Pre-flight | Review required | Notes |
|
|
@@ -68,7 +98,7 @@ How each mechanism is enforced on OpenCode `v2` (idle hook landed via
|
|
|
68
98
|
| Mechanism | Primary layer | Backstop / fallback | Strength |
|
|
69
99
|
| --------- | ------------- | ------------------- | -------- |
|
|
70
100
|
| Pre-flight gate | `tool.execute.before` deny | — | **Hard block** on every build: the edit never lands. |
|
|
71
|
-
| Protected paths + dangerous commands | `tool.execute.before` deny/throw | `permission.evaluate` native layer (deny) | **Hard block** via the
|
|
101
|
+
| Protected paths + dangerous commands | `tool.execute.before` deny/throw (load-bearing: the pipeline runs before-hooks first) | `permission.evaluate` native layer (deny) as defense-in-depth — it only ever sees calls the primary already passed; matters if core ever reorders the pipeline | **Hard block** via the primary deny; the native layer is belt-and-braces, never a weakening (it only denies or abstains). |
|
|
72
102
|
| Per-edit lint | `tool.execute.after` track + lint | `filesystem.changed` event (this release) | Report-only: the edit already landed, so failures log loudly but never throw. |
|
|
73
103
|
| Completion gate | `session.hook("experimental.idle")` (+ `idle` alias) → `session.synthetic` (same execution) | `event.subscribe` idle net for the boundaries the hook skips (deduped; synthetic-first, `prompt` fallback) | **Async, bounded** by `gate.max_blocks`. `/df-status` shows `Continuation (idle): active` vs the event-subscribe fallback. `execute.before` stays the only true hard wall. |
|
|
74
104
|
|
|
@@ -182,6 +212,16 @@ gate:
|
|
|
182
212
|
# before the completion gate passes.
|
|
183
213
|
require_review: true
|
|
184
214
|
|
|
215
|
+
# Optional: named project-specific acceptance checks. Run sequentially
|
|
216
|
+
# after the typecheck/test steps; a failure fails the gate but other
|
|
217
|
+
# steps still run. Timeouts are per-check seconds (default: gate timeout).
|
|
218
|
+
# acceptance:
|
|
219
|
+
# - name: api-contract
|
|
220
|
+
# command: "./scripts/verify-api-contract.sh"
|
|
221
|
+
# - name: migration-safety
|
|
222
|
+
# command: "./scripts/check-migrations.sh"
|
|
223
|
+
# timeout: 120
|
|
224
|
+
|
|
185
225
|
# Optional: pre-flight task list. When set, edit tools are denied
|
|
186
226
|
# (standard/strict) until the agent writes its findings to
|
|
187
227
|
# .opencode/opencode-dev-framework/preflight.md.
|
|
@@ -198,6 +238,11 @@ on_edit:
|
|
|
198
238
|
# Optional: explicit rule files (replace bundled; use mode: append to extend)
|
|
199
239
|
# rules:
|
|
200
240
|
# - docs/team-rules.md
|
|
241
|
+
# Append form (keeps the bundled rules, adds project files after them):
|
|
242
|
+
# rules:
|
|
243
|
+
# mode: append
|
|
244
|
+
# files:
|
|
245
|
+
# - .opencode/opencode-dev-framework/hardening.md
|
|
201
246
|
|
|
202
247
|
# Optional: project style guide appended to the constitution.
|
|
203
248
|
# Auto-discovers STYLE.md / CONTRIBUTING.md / docs/STYLE.md when not set.
|
|
@@ -212,7 +257,7 @@ complete example.
|
|
|
212
257
|
|
|
213
258
|
## Slash commands
|
|
214
259
|
|
|
215
|
-
|
|
260
|
+
Five slash commands are **TUI commands** registered by the bundled `./tui`
|
|
216
261
|
companion module (see *Local development* above for the `tui.json` requirement).
|
|
217
262
|
They open instantly and **never** feed text back to the LLM:
|
|
218
263
|
|
|
@@ -236,6 +281,32 @@ config; the commands themselves are provided by the plugin. The
|
|
|
236
281
|
available for in-agent use (e.g. when the model wants to change the profile
|
|
237
282
|
itself).
|
|
238
283
|
|
|
284
|
+
`/df-goal <objective>` is a **server-side command** instead (registered by the
|
|
285
|
+
server plugin, not the TUI): it starts a **verified** native goal. The plugin
|
|
286
|
+
appends a short verification contract to your objective verbatim and delegates
|
|
287
|
+
exactly once to native `/goal`, which keeps owning state, review,
|
|
288
|
+
pause/resume/clear, and continuations. Requires all three: native `/goal` on
|
|
289
|
+
the core, a blocking profile (`standard`/`strict`, i.e.
|
|
290
|
+
`gate.block_on_failure: true`), and at least one configured completion check
|
|
291
|
+
(typecheck/test command, changed-file lint, `gate.acceptance`, or
|
|
292
|
+
`gate.require_review`). Otherwise it fails with an actionable error instead of
|
|
293
|
+
starting an unverified goal — use native `/goal` directly for purely semantic
|
|
294
|
+
objectives. The objective plus addendum must fit native `/goal`'s 4,000-character
|
|
295
|
+
limit; overflow is rejected, never truncated.
|
|
296
|
+
|
|
297
|
+
The agent must run `dev_framework_verify` after its final changes; the native
|
|
298
|
+
reviewer weighs that tool result as evidence and the framework idle gate stays
|
|
299
|
+
an independent backstop. This is layered verification, not a hard lock:
|
|
300
|
+
native `/goal` can still mark complete while the gate fails (or keep going
|
|
301
|
+
after it passes), both tenants can admit a continuation at one idle boundary,
|
|
302
|
+
and the framework stands down after `gate.max_blocks`.
|
|
303
|
+
|
|
304
|
+
**Run plans under `/df-goal`.** When a task starts from a written plan, make
|
|
305
|
+
the objective the plan inline (short plans) or `Implement the plan in <path>`
|
|
306
|
+
(long plans). Native completion then requires the gate's PASS on the final
|
|
307
|
+
tree — a stronger enforcement than a bare turn, where only your summary stands
|
|
308
|
+
between the plan and "done".
|
|
309
|
+
|
|
239
310
|
## Limitations
|
|
240
311
|
|
|
241
312
|
- **Post-flight enforcement is a same-execution continuation, not a veto.**
|
package/dist/command-utils.d.ts
CHANGED
|
@@ -10,3 +10,8 @@ export interface NormalizedCommandMap {
|
|
|
10
10
|
export declare function normalizeCommandMap(map: CommandMap | undefined): NormalizedCommandMap;
|
|
11
11
|
/** Split a command string into argv tokens, honoring simple quotes. */
|
|
12
12
|
export declare function splitCommand(command: string): string[];
|
|
13
|
+
export interface GlobMatcher {
|
|
14
|
+
pattern: string;
|
|
15
|
+
match: (candidate: string) => boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare function compileGlobMatchers(patterns: readonly string[]): GlobMatcher[];
|
package/dist/command-utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import picomatch from "picomatch";
|
|
1
2
|
/**
|
|
2
3
|
* Normalize a command map: a plain string becomes the default command; a record
|
|
3
4
|
* may contain a `default` key plus per-extension overrides.
|
|
@@ -44,3 +45,23 @@ export function splitCommand(command) {
|
|
|
44
45
|
}
|
|
45
46
|
return tokens;
|
|
46
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Compile glob patterns to picomatch matchers, cached by pattern-array
|
|
50
|
+
* identity. Compilation is the expensive part; the per-tool-call hot path
|
|
51
|
+
* pays matching only. A re-resolved config carries new arrays and naturally
|
|
52
|
+
* recompiles once. Shared by protected-path and exclude matching so the
|
|
53
|
+
* cache scheme exists exactly once.
|
|
54
|
+
*/
|
|
55
|
+
const globMatcherCache = new WeakMap();
|
|
56
|
+
export function compileGlobMatchers(patterns) {
|
|
57
|
+
const cached = globMatcherCache.get(patterns);
|
|
58
|
+
if (cached !== undefined) {
|
|
59
|
+
return cached;
|
|
60
|
+
}
|
|
61
|
+
const compiled = patterns.map((pattern) => ({
|
|
62
|
+
pattern,
|
|
63
|
+
match: picomatch(pattern, { dot: true }),
|
|
64
|
+
}));
|
|
65
|
+
globMatcherCache.set(patterns, compiled);
|
|
66
|
+
return compiled;
|
|
67
|
+
}
|
package/dist/commands.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { GateReport } from "./gate.js";
|
|
2
|
+
import { type CompletionInspection } from "./harness.js";
|
|
2
3
|
import type { RunCommand } from "./host.js";
|
|
3
4
|
import type { Profile, ResolvedConfig } from "./types.js";
|
|
4
5
|
/**
|
|
@@ -10,12 +11,27 @@ import type { Profile, ResolvedConfig } from "./types.js";
|
|
|
10
11
|
*/
|
|
11
12
|
export declare function changeProfile(directory: string, profile: Profile): Promise<string>;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Manual verification result. `verdict` reports the raw inspection outcome:
|
|
15
|
+
* PASS only when the gate passes AND review (when required) is satisfied.
|
|
16
|
+
* Advisory profiles report raw FAIL here — the non-blocking behavior lives
|
|
17
|
+
* in the idle policy (`evaluateCompletion`), not in this verdict.
|
|
17
18
|
*/
|
|
18
|
-
export
|
|
19
|
+
export interface VerifyResult {
|
|
19
20
|
report: GateReport;
|
|
21
|
+
inspection: CompletionInspection;
|
|
22
|
+
verdict: "PASS" | "FAIL";
|
|
20
23
|
summary: string;
|
|
21
|
-
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Run manual verification for a project: the same full completion contract
|
|
27
|
+
* as the idle gate (gate commands plus review state), without any retry
|
|
28
|
+
* policy. Side-effect-free by construction: this function receives only a
|
|
29
|
+
* read-only changed-file snapshot and has no handle on the tracker, the
|
|
30
|
+
* block store, or session input. Git discovery is included so a verify with
|
|
31
|
+
* an empty tracker still sees worktree changes.
|
|
32
|
+
*
|
|
33
|
+
* When `config` is omitted the project config is loaded from disk.
|
|
34
|
+
* `changedFiles` is normally the server's live tracker snapshot (empty for
|
|
35
|
+
* TUI callers); Git-discovered files are unioned in either way.
|
|
36
|
+
*/
|
|
37
|
+
export declare function verifyGate(run: RunCommand, directory: string, config?: ResolvedConfig, changedFiles?: string[]): Promise<VerifyResult>;
|
package/dist/commands.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { loadConfig } from "./config.js";
|
|
3
|
-
import {
|
|
3
|
+
import { inspectCompletion } from "./harness.js";
|
|
4
4
|
import { setProfileInFile } from "./installer.js";
|
|
5
|
+
import { createLintLimiter } from "./lint.js";
|
|
5
6
|
/**
|
|
6
7
|
* Change the project profile by editing the config file on disk. The server
|
|
7
8
|
* plugin reloads the in-memory config on the next tool call / gate run (see
|
|
@@ -15,13 +16,29 @@ export async function changeProfile(directory, profile) {
|
|
|
15
16
|
return `opencode-dev-framework profile set to "${profile}". Change applies on the next tool call / gate run.`;
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
|
-
* Run
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* Run manual verification for a project: the same full completion contract
|
|
20
|
+
* as the idle gate (gate commands plus review state), without any retry
|
|
21
|
+
* policy. Side-effect-free by construction: this function receives only a
|
|
22
|
+
* read-only changed-file snapshot and has no handle on the tracker, the
|
|
23
|
+
* block store, or session input. Git discovery is included so a verify with
|
|
24
|
+
* an empty tracker still sees worktree changes.
|
|
25
|
+
*
|
|
26
|
+
* When `config` is omitted the project config is loaded from disk.
|
|
27
|
+
* `changedFiles` is normally the server's live tracker snapshot (empty for
|
|
28
|
+
* TUI callers); Git-discovered files are unioned in either way.
|
|
22
29
|
*/
|
|
23
30
|
export async function verifyGate(run, directory, config, changedFiles = []) {
|
|
24
31
|
const cfg = config ?? loadConfig(directory);
|
|
25
|
-
const
|
|
26
|
-
|
|
32
|
+
const inspection = await inspectCompletion({
|
|
33
|
+
run,
|
|
34
|
+
config: cfg,
|
|
35
|
+
directory,
|
|
36
|
+
trackerFiles: changedFiles,
|
|
37
|
+
// Fresh limiter per manual verify (bounds its own lint burst); no pass
|
|
38
|
+
// cache — an explicit verify always inspects the live tree.
|
|
39
|
+
lintLimiter: createLintLimiter(),
|
|
40
|
+
});
|
|
41
|
+
const verdict = inspection.ok ? "PASS" : "FAIL";
|
|
42
|
+
const summary = `DEV_FRAMEWORK_VERDICT: ${verdict}\n${inspection.summary}`;
|
|
43
|
+
return { report: inspection.report, inspection, verdict, summary };
|
|
27
44
|
}
|
package/dist/config.d.ts
CHANGED
|
@@ -24,6 +24,19 @@ export declare function mapFlatConfig(flat: Record<string, unknown>): Config;
|
|
|
24
24
|
* always override profile defaults.
|
|
25
25
|
*/
|
|
26
26
|
export declare function resolveConfig(raw: Config, configPath?: string): ResolvedConfig;
|
|
27
|
+
/**
|
|
28
|
+
* Static "meaningful check" predicate for `/df-goal` (plan §3.3).
|
|
29
|
+
*
|
|
30
|
+
* A verified goal must imply deterministic evidence where none would exist
|
|
31
|
+
* otherwise, so `/df-goal` refuses to delegate when the resolved
|
|
32
|
+
* configuration provides no real completion check at all. A check counts
|
|
33
|
+
* only when its step would actually run — a `run_*` flag with no command
|
|
34
|
+
* behind it produces a skipped step, which is vacuous. The review check
|
|
35
|
+
* runs in the harness (`reviewMissing`), not in `runGate`, but counts all
|
|
36
|
+
* the same. Users wanting a purely semantic objective use native `/goal`
|
|
37
|
+
* directly.
|
|
38
|
+
*/
|
|
39
|
+
export declare function hasMeaningfulChecks(config: ResolvedConfig): boolean;
|
|
27
40
|
/** Clear the per-session config cache (mainly for tests). */
|
|
28
41
|
export declare function clearConfigCache(): void;
|
|
29
42
|
/**
|
package/dist/config.js
CHANGED
|
@@ -8,6 +8,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
8
8
|
import { basename, join } from "node:path";
|
|
9
9
|
import { parse as parseYaml } from "yaml";
|
|
10
10
|
import { z } from "zod";
|
|
11
|
+
import { normalizeCommandMap } from "./command-utils.js";
|
|
11
12
|
/** Config file precedence, highest first. The first file found wins. */
|
|
12
13
|
export const CONFIG_FILE_PRECEDENCE = [
|
|
13
14
|
".opencode-dev-framework.yml",
|
|
@@ -27,6 +28,38 @@ export const DEFAULT_PROTECT = [
|
|
|
27
28
|
"**/vendor/**",
|
|
28
29
|
];
|
|
29
30
|
const commandMapSchema = z.union([z.string(), z.record(z.string(), z.string())]);
|
|
31
|
+
const acceptanceCheckSchema = z.object({
|
|
32
|
+
name: z
|
|
33
|
+
.string()
|
|
34
|
+
.min(1, "acceptance check name must not be empty")
|
|
35
|
+
.refine((s) => s.trim().length > 0, "acceptance check name must not be blank"),
|
|
36
|
+
command: z
|
|
37
|
+
.string()
|
|
38
|
+
.min(1, "acceptance check command must not be empty")
|
|
39
|
+
.refine((s) => s.trim().length > 0, "acceptance check command must not be blank"),
|
|
40
|
+
timeout: z.number().positive("acceptance check timeout must be positive").optional(),
|
|
41
|
+
});
|
|
42
|
+
const acceptanceListSchema = z
|
|
43
|
+
.array(acceptanceCheckSchema)
|
|
44
|
+
.optional()
|
|
45
|
+
.superRefine((checks, ctx) => {
|
|
46
|
+
if (!checks)
|
|
47
|
+
return;
|
|
48
|
+
const seen = new Map();
|
|
49
|
+
checks.forEach((check, index) => {
|
|
50
|
+
const first = seen.get(check.name);
|
|
51
|
+
if (first !== undefined) {
|
|
52
|
+
ctx.addIssue({
|
|
53
|
+
code: "custom",
|
|
54
|
+
message: `duplicate acceptance check name "${check.name}" (first at index ${first})`,
|
|
55
|
+
path: [index, "name"],
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
seen.set(check.name, index);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
30
63
|
const configSchema = z.object({
|
|
31
64
|
profile: z.enum(["off", "advisory", "standard", "strict"]).optional(),
|
|
32
65
|
commands: z
|
|
@@ -52,6 +85,7 @@ const configSchema = z.object({
|
|
|
52
85
|
require_review: z.boolean().optional(),
|
|
53
86
|
timeout: z.number().positive().optional(),
|
|
54
87
|
max_blocks: z.number().int().positive().optional(),
|
|
88
|
+
acceptance: acceptanceListSchema,
|
|
55
89
|
})
|
|
56
90
|
.optional(),
|
|
57
91
|
preflight: z.union([z.array(z.string()), z.string()]).optional(),
|
|
@@ -294,6 +328,7 @@ export function resolveConfig(raw, configPath) {
|
|
|
294
328
|
require_review: raw.gate?.require_review ?? profile !== "off",
|
|
295
329
|
timeout: raw.gate?.timeout,
|
|
296
330
|
max_blocks: raw.gate?.max_blocks ?? 3,
|
|
331
|
+
acceptance: raw.gate?.acceptance ?? [],
|
|
297
332
|
},
|
|
298
333
|
on_edit: {
|
|
299
334
|
format: raw.on_edit?.format ?? defaults.on_edit_format,
|
|
@@ -306,6 +341,46 @@ export function resolveConfig(raw, configPath) {
|
|
|
306
341
|
preflight: raw.preflight ?? [],
|
|
307
342
|
};
|
|
308
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Static "meaningful check" predicate for `/df-goal` (plan §3.3).
|
|
346
|
+
*
|
|
347
|
+
* A verified goal must imply deterministic evidence where none would exist
|
|
348
|
+
* otherwise, so `/df-goal` refuses to delegate when the resolved
|
|
349
|
+
* configuration provides no real completion check at all. A check counts
|
|
350
|
+
* only when its step would actually run — a `run_*` flag with no command
|
|
351
|
+
* behind it produces a skipped step, which is vacuous. The review check
|
|
352
|
+
* runs in the harness (`reviewMissing`), not in `runGate`, but counts all
|
|
353
|
+
* the same. Users wanting a purely semantic objective use native `/goal`
|
|
354
|
+
* directly.
|
|
355
|
+
*/
|
|
356
|
+
export function hasMeaningfulChecks(config) {
|
|
357
|
+
const gate = config.gate;
|
|
358
|
+
if (!gate)
|
|
359
|
+
return false;
|
|
360
|
+
if (gate.require_review)
|
|
361
|
+
return true;
|
|
362
|
+
if (gate.acceptance.length > 0)
|
|
363
|
+
return true;
|
|
364
|
+
if (gate.run_typecheck && config.commands.typecheck !== undefined)
|
|
365
|
+
return true;
|
|
366
|
+
if (gate.run_tests) {
|
|
367
|
+
const template = gate.scope === "changed" ? config.commands.test_changed : config.commands.test;
|
|
368
|
+
if (template !== undefined)
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
if (gate.lint_changed) {
|
|
372
|
+
// Same resolution as the gate's per-file lint (lint.ts): a plain string
|
|
373
|
+
// is the default command, a record holds default and/or per-extension
|
|
374
|
+
// overrides. Any configured command counts as meaningful here — the
|
|
375
|
+
// per-file skip (excluded path, unmatched extension) is decided at
|
|
376
|
+
// gate time with the file list this static check does not have.
|
|
377
|
+
const { default: defaultLint, byExtension } = normalizeCommandMap(config.commands.lint);
|
|
378
|
+
if (defaultLint !== undefined || Object.keys(byExtension).length > 0) {
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
309
384
|
function validateConfig(data, configPath) {
|
|
310
385
|
const result = configSchema.safeParse(data);
|
|
311
386
|
if (!result.success) {
|
package/dist/format-status.js
CHANGED
|
@@ -110,6 +110,7 @@ export function renderHelp() {
|
|
|
110
110
|
lines.push("/df-status Show the current dev-framework state");
|
|
111
111
|
lines.push("/df-profile Change the profile to off, advisory, standard, or strict");
|
|
112
112
|
lines.push("/df-verify Run the completion gate manually");
|
|
113
|
+
lines.push("/df-goal Start a verified native goal (verification contract + native /goal)");
|
|
113
114
|
lines.push("/df-help Show this message");
|
|
114
115
|
lines.push("/df-runtime Show plugin version and live hook/gate runtime state");
|
|
115
116
|
return lines.join("\n");
|
package/dist/gate.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* hook skips.
|
|
10
10
|
*/
|
|
11
11
|
import type { CommandResult, RunCommand } from "./host.js";
|
|
12
|
+
import { type LintLimiter } from "./lint.js";
|
|
12
13
|
import type { ResolvedConfig } from "./types.js";
|
|
13
14
|
/** Fallback per-command timeout (seconds) when `gate.timeout` is unset. */
|
|
14
15
|
export declare const DEFAULT_GATE_TIMEOUT_SECONDS = 300;
|
|
@@ -26,7 +27,7 @@ export interface ChangedFileTracker {
|
|
|
26
27
|
*/
|
|
27
28
|
export declare function createChangedFileTracker(): ChangedFileTracker;
|
|
28
29
|
export interface GateStep {
|
|
29
|
-
/** `typecheck`, `test`, or `
|
|
30
|
+
/** `typecheck`, `test`, `lint:<file>`, or `acceptance:<name>`. */
|
|
30
31
|
name: string;
|
|
31
32
|
command?: string[];
|
|
32
33
|
skipped: boolean;
|
|
@@ -48,12 +49,19 @@ export interface GateReport {
|
|
|
48
49
|
* without a shell); an embedded token is replaced inline.
|
|
49
50
|
*/
|
|
50
51
|
export declare function substituteFiles(template: string, files: string[]): string[];
|
|
52
|
+
/** Options for `runGate`. */
|
|
53
|
+
export interface GateOptions {
|
|
54
|
+
/** Project directory to run commands in. */
|
|
55
|
+
cwd?: string;
|
|
56
|
+
/** Shared limiter bounding concurrent linter subprocesses; lints run direct when absent. */
|
|
57
|
+
lintLimiter?: LintLimiter;
|
|
58
|
+
}
|
|
51
59
|
/**
|
|
52
|
-
* Run the completion gate.
|
|
60
|
+
* Run the completion gate. Independent steps (typecheck, test) run
|
|
61
|
+
* concurrently while the reported step order stays stable (typecheck, test,
|
|
62
|
+
* lint per file, acceptance in declaration order). All results are
|
|
53
63
|
* aggregated — a failing step does not abort the remaining steps.
|
|
54
64
|
*/
|
|
55
|
-
export declare function runGate(run: RunCommand, config: ResolvedConfig, changedFiles: string[], options?:
|
|
56
|
-
cwd?: string;
|
|
57
|
-
}): Promise<GateReport>;
|
|
65
|
+
export declare function runGate(run: RunCommand, config: ResolvedConfig, changedFiles: string[], options?: GateOptions): Promise<GateReport>;
|
|
58
66
|
/** One-line-per-step summary of a gate report for logging. */
|
|
59
67
|
export declare function summarizeGate(report: GateReport): string;
|
package/dist/gate.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { isAbsolute, relative } from "node:path";
|
|
12
12
|
import { splitCommand } from "./command-utils.js";
|
|
13
|
-
import { lintFile } from "./lint.js";
|
|
13
|
+
import { lintFile, MAX_CONCURRENT_LINTS } from "./lint.js";
|
|
14
14
|
/** Fallback per-command timeout (seconds) when `gate.timeout` is unset. */
|
|
15
15
|
export const DEFAULT_GATE_TIMEOUT_SECONDS = 300;
|
|
16
16
|
function normalizeTrackedPath(filePath, directory) {
|
|
@@ -53,7 +53,29 @@ export function substituteFiles(template, files) {
|
|
|
53
53
|
return splitCommand(template).flatMap((token) => token === "{files}" ? files : [token.replaceAll("{files}", files.join(" "))]);
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* Map items through an async function with at most `limit` in flight.
|
|
57
|
+
* Output order matches input order regardless of completion order.
|
|
58
|
+
*/
|
|
59
|
+
async function mapBounded(items, limit, fn) {
|
|
60
|
+
const results = new Array(items.length);
|
|
61
|
+
let next = 0;
|
|
62
|
+
const workers = Array.from({ length: Math.min(Math.max(limit, 1), items.length) }, async () => {
|
|
63
|
+
while (true) {
|
|
64
|
+
const index = next;
|
|
65
|
+
next += 1;
|
|
66
|
+
if (index >= items.length) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
results[index] = await fn(items[index], index);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
await Promise.all(workers);
|
|
73
|
+
return results;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Run the completion gate. Independent steps (typecheck, test) run
|
|
77
|
+
* concurrently while the reported step order stays stable (typecheck, test,
|
|
78
|
+
* lint per file, acceptance in declaration order). All results are
|
|
57
79
|
* aggregated — a failing step does not abort the remaining steps.
|
|
58
80
|
*/
|
|
59
81
|
export async function runGate(run, config, changedFiles, options) {
|
|
@@ -72,38 +94,61 @@ export async function runGate(run, config, changedFiles, options) {
|
|
|
72
94
|
const timeout = config.gate.timeout ?? DEFAULT_GATE_TIMEOUT_SECONDS;
|
|
73
95
|
const runOptions = { cwd: options?.cwd, timeout };
|
|
74
96
|
const steps = [];
|
|
97
|
+
// Typecheck and test are independent — run them concurrently and report in
|
|
98
|
+
// stable order. Skipped steps assign synchronously and never enter the
|
|
99
|
+
// promise flow.
|
|
100
|
+
let typecheckStep = null;
|
|
101
|
+
let testStep = null;
|
|
102
|
+
const independent = [];
|
|
75
103
|
if (config.gate.run_typecheck) {
|
|
76
104
|
if (config.commands.typecheck !== undefined) {
|
|
77
105
|
const command = splitCommand(config.commands.typecheck);
|
|
78
|
-
|
|
79
|
-
name: "typecheck",
|
|
80
|
-
|
|
81
|
-
skipped: false,
|
|
82
|
-
result: await run(command, runOptions),
|
|
83
|
-
});
|
|
106
|
+
independent.push(run(command, runOptions).then((result) => {
|
|
107
|
+
typecheckStep = { name: "typecheck", command, skipped: false, result };
|
|
108
|
+
}));
|
|
84
109
|
}
|
|
85
110
|
else {
|
|
86
|
-
|
|
111
|
+
typecheckStep = {
|
|
112
|
+
name: "typecheck",
|
|
113
|
+
skipped: true,
|
|
114
|
+
reason: "no typecheck command configured",
|
|
115
|
+
};
|
|
87
116
|
}
|
|
88
117
|
}
|
|
89
118
|
if (config.gate.run_tests) {
|
|
90
119
|
const template = config.gate.scope === "changed" ? config.commands.test_changed : config.commands.test;
|
|
91
120
|
if (template !== undefined) {
|
|
92
121
|
const command = substituteFiles(template, changedFiles);
|
|
93
|
-
|
|
122
|
+
independent.push(run(command, runOptions).then((result) => {
|
|
123
|
+
testStep = { name: "test", command, skipped: false, result };
|
|
124
|
+
}));
|
|
94
125
|
}
|
|
95
126
|
else {
|
|
96
127
|
const reason = config.gate.scope === "changed"
|
|
97
128
|
? "no test_changed command configured"
|
|
98
129
|
: "no test command configured";
|
|
99
|
-
|
|
130
|
+
testStep = { name: "test", skipped: true, reason };
|
|
100
131
|
}
|
|
101
132
|
}
|
|
133
|
+
await Promise.all(independent);
|
|
134
|
+
if (typecheckStep !== null) {
|
|
135
|
+
steps.push(typecheckStep);
|
|
136
|
+
}
|
|
137
|
+
if (testStep !== null) {
|
|
138
|
+
steps.push(testStep);
|
|
139
|
+
}
|
|
102
140
|
if (config.gate.lint_changed) {
|
|
103
|
-
|
|
104
|
-
|
|
141
|
+
// Per-file lints are independent — bound concurrency instead of running
|
|
142
|
+
// them one at a time. When the session limiter is provided it also
|
|
143
|
+
// applies, so gate bursts share headroom with per-edit lints.
|
|
144
|
+
const limiter = options?.lintLimiter;
|
|
145
|
+
const runOne = (file) => limiter !== undefined
|
|
146
|
+
? limiter.run(() => lintFile(run, config, file, runOptions))
|
|
147
|
+
: lintFile(run, config, file, runOptions);
|
|
148
|
+
const outcomes = await mapBounded(changedFiles, MAX_CONCURRENT_LINTS, runOne);
|
|
149
|
+
for (const [index, outcome] of outcomes.entries()) {
|
|
105
150
|
steps.push({
|
|
106
|
-
name: `lint:${
|
|
151
|
+
name: `lint:${changedFiles[index]}`,
|
|
107
152
|
command: outcome.command,
|
|
108
153
|
skipped: outcome.skipped,
|
|
109
154
|
reason: outcome.reason,
|
|
@@ -111,6 +156,19 @@ export async function runGate(run, config, changedFiles, options) {
|
|
|
111
156
|
});
|
|
112
157
|
}
|
|
113
158
|
}
|
|
159
|
+
// Named acceptance checks run last, sequentially, in declaration order.
|
|
160
|
+
// Like every other step, a failure is aggregated — it does not abort the
|
|
161
|
+
// remaining steps. `{files}` substitution and the project `cwd` match the
|
|
162
|
+
// test-command semantics; per-check timeout overrides the gate default.
|
|
163
|
+
for (const check of config.gate.acceptance) {
|
|
164
|
+
const command = substituteFiles(check.command, changedFiles);
|
|
165
|
+
steps.push({
|
|
166
|
+
name: `acceptance:${check.name}`,
|
|
167
|
+
command,
|
|
168
|
+
skipped: false,
|
|
169
|
+
result: await run(command, { cwd: options?.cwd, timeout: check.timeout ?? timeout }),
|
|
170
|
+
});
|
|
171
|
+
}
|
|
114
172
|
const ran = steps.some((step) => !step.skipped);
|
|
115
173
|
const failedSteps = steps.filter((step) => !step.skipped && step.result !== undefined && isFailure(step.result));
|
|
116
174
|
return {
|