opencode-dev-framework 1.0.0 → 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 +53 -3
- package/dist/command-utils.d.ts +5 -0
- package/dist/command-utils.js +21 -0
- package/dist/commands.js +4 -0
- package/dist/config.d.ts +5 -3
- package/dist/config.js +17 -6
- package/dist/gate.d.ts +12 -4
- package/dist/gate.js +59 -14
- package/dist/goal.d.ts +4 -2
- package/dist/goal.js +4 -2
- package/dist/harness.d.ts +40 -8
- package/dist/harness.js +99 -7
- package/dist/index.d.ts +14 -0
- package/dist/index.js +40 -9
- 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/package.json +1 -1
- package/rules/40-delegation.md +9 -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
|
|
@@ -52,6 +59,28 @@ reimplemented as an OpenCode-native plugin.
|
|
|
52
59
|
instead: it starts a verified native goal (see *Slash commands* below). The `dev_framework_*` custom *tools* above remain
|
|
53
60
|
available for in-agent use.
|
|
54
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
|
+
|
|
55
84
|
## Profiles
|
|
56
85
|
|
|
57
86
|
| Profile | Guardrails | Gate failures | Lint on edit | Pre-flight | Review required | Notes |
|
|
@@ -69,7 +98,7 @@ How each mechanism is enforced on OpenCode `v2` (idle hook landed via
|
|
|
69
98
|
| Mechanism | Primary layer | Backstop / fallback | Strength |
|
|
70
99
|
| --------- | ------------- | ------------------- | -------- |
|
|
71
100
|
| Pre-flight gate | `tool.execute.before` deny | — | **Hard block** on every build: the edit never lands. |
|
|
72
|
-
| 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). |
|
|
73
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. |
|
|
74
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. |
|
|
75
104
|
|
|
@@ -183,6 +212,16 @@ gate:
|
|
|
183
212
|
# before the completion gate passes.
|
|
184
213
|
require_review: true
|
|
185
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
|
+
|
|
186
225
|
# Optional: pre-flight task list. When set, edit tools are denied
|
|
187
226
|
# (standard/strict) until the agent writes its findings to
|
|
188
227
|
# .opencode/opencode-dev-framework/preflight.md.
|
|
@@ -199,6 +238,11 @@ on_edit:
|
|
|
199
238
|
# Optional: explicit rule files (replace bundled; use mode: append to extend)
|
|
200
239
|
# rules:
|
|
201
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
|
|
202
246
|
|
|
203
247
|
# Optional: project style guide appended to the constitution.
|
|
204
248
|
# Auto-discovers STYLE.md / CONTRIBUTING.md / docs/STYLE.md when not set.
|
|
@@ -257,6 +301,12 @@ native `/goal` can still mark complete while the gate fails (or keep going
|
|
|
257
301
|
after it passes), both tenants can admit a continuation at one idle boundary,
|
|
258
302
|
and the framework stands down after `gate.max_blocks`.
|
|
259
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
|
+
|
|
260
310
|
## Limitations
|
|
261
311
|
|
|
262
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.js
CHANGED
|
@@ -2,6 +2,7 @@ import { join } from "node:path";
|
|
|
2
2
|
import { loadConfig } from "./config.js";
|
|
3
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
|
|
@@ -33,6 +34,9 @@ export async function verifyGate(run, directory, config, changedFiles = []) {
|
|
|
33
34
|
config: cfg,
|
|
34
35
|
directory,
|
|
35
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(),
|
|
36
40
|
});
|
|
37
41
|
const verdict = inspection.ok ? "PASS" : "FAIL";
|
|
38
42
|
const summary = `DEV_FRAMEWORK_VERDICT: ${verdict}\n${inspection.summary}`;
|
package/dist/config.d.ts
CHANGED
|
@@ -30,9 +30,11 @@ export declare function resolveConfig(raw: Config, configPath?: string): Resolve
|
|
|
30
30
|
* A verified goal must imply deterministic evidence where none would exist
|
|
31
31
|
* otherwise, so `/df-goal` refuses to delegate when the resolved
|
|
32
32
|
* configuration provides no real completion check at all. A check counts
|
|
33
|
-
* only when its step would actually run
|
|
34
|
-
*
|
|
35
|
-
*
|
|
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.
|
|
36
38
|
*/
|
|
37
39
|
export declare function hasMeaningfulChecks(config: ResolvedConfig): boolean;
|
|
38
40
|
/** Clear the per-session config cache (mainly for tests). */
|
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",
|
|
@@ -32,7 +33,10 @@ const acceptanceCheckSchema = z.object({
|
|
|
32
33
|
.string()
|
|
33
34
|
.min(1, "acceptance check name must not be empty")
|
|
34
35
|
.refine((s) => s.trim().length > 0, "acceptance check name must not be blank"),
|
|
35
|
-
command: z
|
|
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"),
|
|
36
40
|
timeout: z.number().positive("acceptance check timeout must be positive").optional(),
|
|
37
41
|
});
|
|
38
42
|
const acceptanceListSchema = z
|
|
@@ -343,9 +347,11 @@ export function resolveConfig(raw, configPath) {
|
|
|
343
347
|
* A verified goal must imply deterministic evidence where none would exist
|
|
344
348
|
* otherwise, so `/df-goal` refuses to delegate when the resolved
|
|
345
349
|
* configuration provides no real completion check at all. A check counts
|
|
346
|
-
* only when its step would actually run
|
|
347
|
-
*
|
|
348
|
-
*
|
|
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.
|
|
349
355
|
*/
|
|
350
356
|
export function hasMeaningfulChecks(config) {
|
|
351
357
|
const gate = config.gate;
|
|
@@ -363,8 +369,13 @@ export function hasMeaningfulChecks(config) {
|
|
|
363
369
|
return true;
|
|
364
370
|
}
|
|
365
371
|
if (gate.lint_changed) {
|
|
366
|
-
|
|
367
|
-
|
|
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) {
|
|
368
379
|
return true;
|
|
369
380
|
}
|
|
370
381
|
}
|
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;
|
|
@@ -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,
|
package/dist/goal.d.ts
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* framework's idle gate stays the independent deterministic backstop.
|
|
10
10
|
*
|
|
11
11
|
* All policy here is pure (input -> data, no session I/O): `src/index.ts`
|
|
12
|
-
* owns the `ctx.command.transform` registration,
|
|
13
|
-
*
|
|
12
|
+
* owns the `ctx.command.transform` registration, the `command.list()`
|
|
13
|
+
* call, and the delegation call; the shape-tolerant listing predicate
|
|
14
|
+
* (`isNativeGoalListed`) lives here. Unit tests drive these functions
|
|
15
|
+
* with a stub delegate.
|
|
14
16
|
*/
|
|
15
17
|
import type { ResolvedConfig } from "./types.js";
|
|
16
18
|
/**
|
package/dist/goal.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
* framework's idle gate stays the independent deterministic backstop.
|
|
10
10
|
*
|
|
11
11
|
* All policy here is pure (input -> data, no session I/O): `src/index.ts`
|
|
12
|
-
* owns the `ctx.command.transform` registration,
|
|
13
|
-
*
|
|
12
|
+
* owns the `ctx.command.transform` registration, the `command.list()`
|
|
13
|
+
* call, and the delegation call; the shape-tolerant listing predicate
|
|
14
|
+
* (`isNativeGoalListed`) lives here. Unit tests drive these functions
|
|
15
|
+
* with a stub delegate.
|
|
14
16
|
*/
|
|
15
17
|
import { hasMeaningfulChecks } from "./config.js";
|
|
16
18
|
/**
|
package/dist/harness.d.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import type { BlockStore } from "./block-store.js";
|
|
20
20
|
import { type ChangedFileTracker, type GateReport } from "./gate.js";
|
|
21
21
|
import type { RunCommand } from "./host.js";
|
|
22
|
+
import type { LintLimiter } from "./lint.js";
|
|
22
23
|
import type { LogFn } from "./logger.js";
|
|
23
24
|
import type { ResolvedConfig } from "./types.js";
|
|
24
25
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
@@ -79,12 +80,19 @@ export interface CompletionDeps {
|
|
|
79
80
|
tracker: ChangedFileTracker;
|
|
80
81
|
blockCounts: BlockStore;
|
|
81
82
|
log: LogFn;
|
|
83
|
+
/** Shared limiter bounding concurrent linter subprocesses. */
|
|
84
|
+
lintLimiter?: LintLimiter;
|
|
85
|
+
/** Session pass cache; skips redundant gate suites across idle boundaries. */
|
|
86
|
+
passCache?: PassCache;
|
|
82
87
|
}
|
|
83
88
|
/**
|
|
84
|
-
* Side-effect-free inputs for a completion inspection
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
89
|
+
* Side-effect-free inputs for a completion inspection, with one deliberate
|
|
90
|
+
* exception: the session pass-cache write-through (`passCache.key/summary`
|
|
91
|
+
* store on clean runs, clear on failures) when the caller opts in by
|
|
92
|
+
* passing `passCache`. The tracker file list is a read-only snapshot:
|
|
93
|
+
* inspection never clears it, never touches block counts, never logs, and
|
|
94
|
+
* never admits input — those are policy decisions owned by
|
|
95
|
+
* `evaluateCompletion`.
|
|
88
96
|
*/
|
|
89
97
|
export interface InspectionDeps {
|
|
90
98
|
run: RunCommand;
|
|
@@ -92,7 +100,30 @@ export interface InspectionDeps {
|
|
|
92
100
|
directory: string;
|
|
93
101
|
/** Read-only snapshot of tracker files; never mutated. */
|
|
94
102
|
trackerFiles: string[];
|
|
103
|
+
/** Shared limiter bounding concurrent linter subprocesses. */
|
|
104
|
+
lintLimiter?: LintLimiter;
|
|
105
|
+
/**
|
|
106
|
+
* Pass cache owned by the session state. When set and the working tree
|
|
107
|
+
* still matches the last clean pass (same files, same mtimes/sizes,
|
|
108
|
+
* same gate-relevant config, review artifact untouched — modulo the
|
|
109
|
+
* mtime/size same-tick rewrite window), inspection returns the cached
|
|
110
|
+
* pass without spawning any gate command. Any content change, config
|
|
111
|
+
* change, or review removal misses the cache and re-runs. Only
|
|
112
|
+
* genuinely clean passes are stored — advisory problems and failures
|
|
113
|
+
* never are, so loud reporting is preserved.
|
|
114
|
+
*/
|
|
115
|
+
passCache?: PassCache;
|
|
95
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Fingerprint of the last clean pass. `key` is null when nothing is cached;
|
|
119
|
+
* a non-null key with its summary replays the pass verbatim.
|
|
120
|
+
*/
|
|
121
|
+
export interface PassCache {
|
|
122
|
+
key: string | null;
|
|
123
|
+
summary: string | null;
|
|
124
|
+
}
|
|
125
|
+
/** Create an empty pass cache (one per session state). */
|
|
126
|
+
export declare function createPassCache(): PassCache;
|
|
96
127
|
/**
|
|
97
128
|
* Raw completion report. `ok` is the unadjudicated outcome (gate passed and
|
|
98
129
|
* review satisfied); profiles, block counting, and stand-down are applied by
|
|
@@ -113,10 +144,11 @@ export interface CompletionInspection {
|
|
|
113
144
|
summary: string;
|
|
114
145
|
}
|
|
115
146
|
/**
|
|
116
|
-
* Inspect the current completion state without mutating anything
|
|
117
|
-
*
|
|
118
|
-
* Both the idle policy
|
|
119
|
-
* (`
|
|
147
|
+
* Inspect the current completion state without mutating anything except the
|
|
148
|
+
* opted-in session pass-cache write-through: no tracker clearing, no
|
|
149
|
+
* block-count changes, no logging, no input admitted. Both the idle policy
|
|
150
|
+
* (`evaluateCompletion`) and manual verification (`verifyGate`) read from
|
|
151
|
+
* here so they evaluate the same full contract.
|
|
120
152
|
*/
|
|
121
153
|
export declare function inspectCompletion(deps: InspectionDeps): Promise<CompletionInspection>;
|
|
122
154
|
/**
|
package/dist/harness.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* The verdict is consumed by the `experimental.idle` hook (same-execution
|
|
17
17
|
* synthetic continuation) and the `session.idle` event net (re-prompt).
|
|
18
18
|
*/
|
|
19
|
-
import { readFile } from "node:fs/promises";
|
|
19
|
+
import { readFile, stat } from "node:fs/promises";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { runGate, summarizeGate } from "./gate.js";
|
|
22
22
|
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
@@ -122,11 +122,53 @@ function reviewMissingMessage(changedFiles) {
|
|
|
122
122
|
`review findings and their resolution to ${REVIEW_ARTIFACT_REL}.\n\n` +
|
|
123
123
|
`Investigation-only reviewers: do not ask them to edit product code.`);
|
|
124
124
|
}
|
|
125
|
+
/** Create an empty pass cache (one per session state). */
|
|
126
|
+
export function createPassCache() {
|
|
127
|
+
return { key: null, summary: null };
|
|
128
|
+
}
|
|
125
129
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
+
* Fingerprint the current tree state for cache comparison. Returns null
|
|
131
|
+
* when any input is unreadable — an unreadable file can never prove the
|
|
132
|
+
* tree unchanged, so null forces a re-run (the safe direction). Covers
|
|
133
|
+
* every live input to `runGate` (commands, gate options, `exclude`) plus
|
|
134
|
+
* the review artifact, so any behavior-changing config edit misses.
|
|
135
|
+
*/
|
|
136
|
+
async function passCacheKey(config, directory, changedFiles, reviewRequired) {
|
|
137
|
+
const gateConfig = JSON.stringify({
|
|
138
|
+
commands: config.commands,
|
|
139
|
+
gate: config.gate,
|
|
140
|
+
exclude: config.exclude,
|
|
141
|
+
});
|
|
142
|
+
const parts = [];
|
|
143
|
+
for (const file of [...changedFiles].sort()) {
|
|
144
|
+
try {
|
|
145
|
+
const s = await stat(join(directory, file));
|
|
146
|
+
parts.push(`${file}:${s.mtimeMs}:${s.size}`);
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let review = "not-required";
|
|
153
|
+
if (reviewRequired) {
|
|
154
|
+
try {
|
|
155
|
+
const s = await stat(join(directory, REVIEW_ARTIFACT_REL));
|
|
156
|
+
review = `${s.mtimeMs}:${s.size}`;
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Review was required at pass time but is now unreadable: the
|
|
160
|
+
// requirement may have become unmet, so force a re-run.
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return `${gateConfig}\n${parts.join("\n")}\nreview:${review}`;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Inspect the current completion state without mutating anything except the
|
|
168
|
+
* opted-in session pass-cache write-through: no tracker clearing, no
|
|
169
|
+
* block-count changes, no logging, no input admitted. Both the idle policy
|
|
170
|
+
* (`evaluateCompletion`) and manual verification (`verifyGate`) read from
|
|
171
|
+
* here so they evaluate the same full contract.
|
|
130
172
|
*/
|
|
131
173
|
export async function inspectCompletion(deps) {
|
|
132
174
|
const { run, config, directory, trackerFiles } = deps;
|
|
@@ -160,9 +202,43 @@ export async function inspectCompletion(deps) {
|
|
|
160
202
|
summary: "completion gate skipped: no changed files",
|
|
161
203
|
};
|
|
162
204
|
}
|
|
163
|
-
const report = await runGate(run, config, changedFiles, { cwd: directory });
|
|
164
|
-
const gateFailed = report.ran && !report.ok;
|
|
165
205
|
const reviewRequired = config.gate.require_review && changedFiles.length > 0;
|
|
206
|
+
// Fingerprint the tree the gate is about to validate, once. A hit replays
|
|
207
|
+
// the cached pass; a clean run stores this same pre-run key. Storing the
|
|
208
|
+
// pre-run (not post-run) state matters: an edit landing mid-gate-run
|
|
209
|
+
// changes the stats, so the next idle misses and gates the edit instead
|
|
210
|
+
// of replaying a pass over content the gate never saw.
|
|
211
|
+
const fingerprint = deps.passCache !== undefined
|
|
212
|
+
? await passCacheKey(config, directory, changedFiles, reviewRequired)
|
|
213
|
+
: null;
|
|
214
|
+
// Fast path: the tree still matches the last clean pass — replay it
|
|
215
|
+
// without spawning gate commands. The key covers file identity, content
|
|
216
|
+
// freshness (mtime+size), gate-relevant config, and the review artifact,
|
|
217
|
+
// so any real change misses and re-runs.
|
|
218
|
+
const cachedKey = deps.passCache?.key;
|
|
219
|
+
const cachedSummary = deps.passCache?.summary;
|
|
220
|
+
if (cachedKey !== undefined &&
|
|
221
|
+
cachedKey !== null &&
|
|
222
|
+
cachedSummary !== undefined &&
|
|
223
|
+
cachedSummary !== null) {
|
|
224
|
+
if (fingerprint !== null && fingerprint === cachedKey) {
|
|
225
|
+
return {
|
|
226
|
+
changedFiles,
|
|
227
|
+
report: { ran: true, steps: [], ok: true, failedSteps: [] },
|
|
228
|
+
reviewRequired,
|
|
229
|
+
reviewState: "present",
|
|
230
|
+
reviewMissing: false,
|
|
231
|
+
skipped: false,
|
|
232
|
+
ok: true,
|
|
233
|
+
summary: cachedSummary,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
const report = await runGate(run, config, changedFiles, {
|
|
238
|
+
cwd: directory,
|
|
239
|
+
lintLimiter: deps.lintLimiter,
|
|
240
|
+
});
|
|
241
|
+
const gateFailed = report.ran && !report.ok;
|
|
166
242
|
const reviewState = reviewRequired
|
|
167
243
|
? await artifactState(directory, REVIEW_ARTIFACT_REL)
|
|
168
244
|
: "present";
|
|
@@ -175,6 +251,20 @@ export async function inspectCompletion(deps) {
|
|
|
175
251
|
: report.ran
|
|
176
252
|
? `completion gate passed\n${summarizeGate(report)}`
|
|
177
253
|
: `completion gate passed (${report.reason ?? "nothing to run"})`;
|
|
254
|
+
if (deps.passCache !== undefined) {
|
|
255
|
+
if (!gateFailed && !reviewMissing && report.ran && fingerprint !== null) {
|
|
256
|
+
// Genuinely clean pass that actually ran — store the pre-run
|
|
257
|
+
// fingerprint for the next idle. Advisory problems (gateFailed) and
|
|
258
|
+
// missing reviews never store; vacuous passes (nothing ran) neither
|
|
259
|
+
// store nor clear.
|
|
260
|
+
deps.passCache.key = fingerprint;
|
|
261
|
+
deps.passCache.summary = summary;
|
|
262
|
+
}
|
|
263
|
+
else if (gateFailed || reviewMissing) {
|
|
264
|
+
deps.passCache.key = null;
|
|
265
|
+
deps.passCache.summary = null;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
178
268
|
return {
|
|
179
269
|
changedFiles,
|
|
180
270
|
report,
|
|
@@ -202,6 +292,8 @@ export async function evaluateCompletion(deps) {
|
|
|
202
292
|
config,
|
|
203
293
|
directory,
|
|
204
294
|
trackerFiles: tracker.getChangedFiles(),
|
|
295
|
+
lintLimiter: deps.lintLimiter,
|
|
296
|
+
passCache: deps.passCache,
|
|
205
297
|
});
|
|
206
298
|
const { changedFiles, report } = inspection;
|
|
207
299
|
const gateFailed = report.ran && !report.ok;
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
import { Plugin } from "@opencode/plugin";
|
|
24
24
|
import { type BlockStore } from "./block-store.js";
|
|
25
25
|
import { type ChangedFileTracker } from "./gate.js";
|
|
26
|
+
import { type PassCache } from "./harness.js";
|
|
26
27
|
import { type RunCommand } from "./host.js";
|
|
28
|
+
import { type LintLimiter } from "./lint.js";
|
|
27
29
|
import { type LogFn } from "./logger.js";
|
|
28
30
|
import type { ResolvedConfig } from "./types.js";
|
|
29
31
|
export interface HookState {
|
|
@@ -46,6 +48,18 @@ export interface HookState {
|
|
|
46
48
|
blocks: BlockStore;
|
|
47
49
|
precommitAvailable?: boolean;
|
|
48
50
|
configMtime?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Shared FIFO limiter bounding concurrent linter subprocesses across
|
|
53
|
+
* per-edit lints and gate lint steps.
|
|
54
|
+
*/
|
|
55
|
+
lintLimiter: LintLimiter;
|
|
56
|
+
/** Fingerprint of the last clean gate pass; skips redundant suites. */
|
|
57
|
+
passCache: PassCache;
|
|
58
|
+
/**
|
|
59
|
+
* `Date.now()` of the last config-mtime check. Hook fires are far more
|
|
60
|
+
* frequent than config edits, so mtime stats are throttled to a 1s window.
|
|
61
|
+
*/
|
|
62
|
+
lastConfigCheck: number;
|
|
49
63
|
/**
|
|
50
64
|
* Which lever completed a gate evaluation most recently in this process:
|
|
51
65
|
* `"idle"` once the `experimental.idle` hook has (same-execution
|
package/dist/index.js
CHANGED
|
@@ -26,20 +26,33 @@ import { join } from "node:path";
|
|
|
26
26
|
import { createBlockStore } from "./block-store.js";
|
|
27
27
|
import { clearConfigCache, loadConfig } from "./config.js";
|
|
28
28
|
import { createChangedFileTracker } from "./gate.js";
|
|
29
|
-
import { artifactState, evaluateCompletion, PREFLIGHT_ARTIFACT_REL, preflightBlockReason, } from "./harness.js";
|
|
29
|
+
import { artifactState, createPassCache, evaluateCompletion, PREFLIGHT_ARTIFACT_REL, preflightBlockReason, } from "./harness.js";
|
|
30
30
|
import { runCommand } from "./host.js";
|
|
31
|
-
import {
|
|
31
|
+
import { createLintLimiter, detectPreCommitAvailability, isLintFailure, lintFile, summarizeLint, } from "./lint.js";
|
|
32
32
|
import { createLogger } from "./logger.js";
|
|
33
33
|
import { checkToolCall, extractFilePath, FILE_TOOLS, toPermissionGuard } from "./protect.js";
|
|
34
|
-
import { loadConstitution } from "./rules.js";
|
|
34
|
+
import { constitutionPresent, loadConstitution } from "./rules.js";
|
|
35
35
|
import { writeRuntimeStatus } from "./runtime-status.js";
|
|
36
36
|
let activeState = null;
|
|
37
37
|
let fallbackLog = async () => { };
|
|
38
|
+
/**
|
|
39
|
+
* Minimum interval between config-mtime checks. Every hook fire calls
|
|
40
|
+
* `reloadConfigIfChanged`, but the config file almost never changes
|
|
41
|
+
* mid-session, so a 1s staleness window is invisible.
|
|
42
|
+
*/
|
|
43
|
+
const CONFIG_RELOAD_MIN_INTERVAL_MS = 1000;
|
|
38
44
|
function safeLog(state, level, message, extra) {
|
|
39
45
|
const fn = state && typeof state.log === "function" ? state.log : fallbackLog;
|
|
40
46
|
return fn(level, message, extra);
|
|
41
47
|
}
|
|
42
48
|
async function reloadConfigIfChanged(state) {
|
|
49
|
+
// Throttle mtime checks: every hook fire calls this, but the config file
|
|
50
|
+
// almost never changes mid-session. A 1s staleness window is invisible.
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
if (now - state.lastConfigCheck < CONFIG_RELOAD_MIN_INTERVAL_MS) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
state.lastConfigCheck = now;
|
|
43
56
|
const primary = join(state.directory, ".opencode-dev-framework.yml");
|
|
44
57
|
const fallback = join(state.directory, ".dev-framework.yml");
|
|
45
58
|
// check both names; stat whichever exists
|
|
@@ -117,11 +130,11 @@ async function runPerEditLint(state, filePath) {
|
|
|
117
130
|
if (state.config.precommit === "auto" && state.precommitAvailable === undefined) {
|
|
118
131
|
state.precommitAvailable = await detectPreCommitAvailability(state.run, state.directory);
|
|
119
132
|
}
|
|
120
|
-
const outcome = await lintFile(state.run, state.config, filePath, {
|
|
133
|
+
const outcome = await state.lintLimiter.run(() => lintFile(state.run, state.config, filePath, {
|
|
121
134
|
cwd: state.directory,
|
|
122
135
|
timeout: state.config.gate?.timeout,
|
|
123
136
|
precommitAvailable: state.precommitAvailable,
|
|
124
|
-
});
|
|
137
|
+
}));
|
|
125
138
|
if (outcome.skipped) {
|
|
126
139
|
await safeLog(state, "debug", summarizeLint(outcome), {
|
|
127
140
|
filePath,
|
|
@@ -149,6 +162,8 @@ function runCompletion(state, sessionID) {
|
|
|
149
162
|
sessionID,
|
|
150
163
|
tracker: state.tracker,
|
|
151
164
|
blockCounts: state.blocks,
|
|
165
|
+
lintLimiter: state.lintLimiter,
|
|
166
|
+
passCache: state.passCache,
|
|
152
167
|
log: (level, message, extra) => safeLog(state, level, message, extra),
|
|
153
168
|
});
|
|
154
169
|
}
|
|
@@ -269,6 +284,9 @@ const plugin = Plugin.define({
|
|
|
269
284
|
blockCounts,
|
|
270
285
|
blocks,
|
|
271
286
|
configMtime,
|
|
287
|
+
lintLimiter: createLintLimiter(),
|
|
288
|
+
passCache: createPassCache(),
|
|
289
|
+
lastConfigCheck: 0,
|
|
272
290
|
lastIdleHandled: new Map(),
|
|
273
291
|
};
|
|
274
292
|
activeState = state;
|
|
@@ -307,7 +325,7 @@ const plugin = Plugin.define({
|
|
|
307
325
|
if (!constitution)
|
|
308
326
|
return;
|
|
309
327
|
// V2 system is Array<SystemPart> {type:"text", text:string}
|
|
310
|
-
const already = event.system
|
|
328
|
+
const already = constitutionPresent(event.system, constitution);
|
|
311
329
|
if (already)
|
|
312
330
|
return;
|
|
313
331
|
event.system.push({
|
|
@@ -328,7 +346,7 @@ const plugin = Plugin.define({
|
|
|
328
346
|
// generate/compaction/title also have system — inject similarly if present
|
|
329
347
|
if (!event.system)
|
|
330
348
|
return;
|
|
331
|
-
const already = event.system
|
|
349
|
+
const already = constitutionPresent(event.system, constitution);
|
|
332
350
|
if (!already)
|
|
333
351
|
event.system.push({ type: "text", text: constitution });
|
|
334
352
|
}));
|
|
@@ -754,8 +772,10 @@ const plugin = Plugin.define({
|
|
|
754
772
|
name: "df-goal",
|
|
755
773
|
description: "Start a verified native goal: appends a dev_framework_verify contract to the objective and delegates to native /goal exactly once. Requires native /goal, a blocking profile, and at least one configured completion check.",
|
|
756
774
|
execute: async (invocation) => {
|
|
757
|
-
if (activeState !== state)
|
|
758
|
-
|
|
775
|
+
if (activeState !== state) {
|
|
776
|
+
throw new Error("Cannot start a verified goal: the plugin session state changed " +
|
|
777
|
+
"(teardown or reload raced the command); retry /df-goal.");
|
|
778
|
+
}
|
|
759
779
|
await reloadConfigIfChanged(state);
|
|
760
780
|
const { extractObjectiveText, isNativeGoalListed, runGoalCommand } = await import("./goal.js");
|
|
761
781
|
let nativeGoalAvailable = false;
|
|
@@ -765,7 +785,18 @@ const plugin = Plugin.define({
|
|
|
765
785
|
catch {
|
|
766
786
|
nativeGoalAvailable = false;
|
|
767
787
|
}
|
|
788
|
+
// Flat core protocol shape
|
|
789
|
+
// (packages/protocol/src/groups/session.ts `session.command`:
|
|
790
|
+
// `{ sessionID, name: string, text, ... }`). The installed
|
|
791
|
+
// client types agree (indexed-access rendering resolves to
|
|
792
|
+
// flat `name: string`) and core source is truth (Phase 0
|
|
793
|
+
// spike receipt) — keep this cast flat.
|
|
768
794
|
const sessionCommand = ctx.session.command;
|
|
795
|
+
if (typeof sessionCommand !== "function") {
|
|
796
|
+
throw new Error("Cannot start a verified goal: session.command is not available on this " +
|
|
797
|
+
"core. Upgrade OpenCode to a build containing native /goal, or run the " +
|
|
798
|
+
"objective without verification where native /goal exists.");
|
|
799
|
+
}
|
|
769
800
|
const result = await runGoalCommand({
|
|
770
801
|
config: state.config,
|
|
771
802
|
objective: extractObjectiveText(invocation.prompt),
|
package/dist/lint.d.ts
CHANGED
|
@@ -7,6 +7,19 @@ import type { CommandResult, RunCommand } from "./host.js";
|
|
|
7
7
|
import type { ResolvedConfig } from "./types.js";
|
|
8
8
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
9
9
|
export declare const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
10
|
+
/** Cap on concurrent linter subprocesses; per-edit and gate lints share one limiter per session. */
|
|
11
|
+
export declare const MAX_CONCURRENT_LINTS = 4;
|
|
12
|
+
/** FIFO semaphore bounding concurrent linter subprocesses, shared per session. */
|
|
13
|
+
export interface LintLimiter {
|
|
14
|
+
run<T>(fn: () => Promise<T>): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create a FIFO semaphore bounding concurrent linter subprocesses. Queued
|
|
18
|
+
* callers wait their turn — lint output is delayed under burst load, never
|
|
19
|
+
* dropped. Release is in `finally`, so a throwing linter cannot wedge the
|
|
20
|
+
* limiter. Non-positive limits clamp to 1 (serial) instead of deadlocking.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createLintLimiter(limit?: number): LintLimiter;
|
|
10
23
|
export interface LintOutcome {
|
|
11
24
|
/** True when no linter ran (file excluded or no command configured). */
|
|
12
25
|
skipped: boolean;
|
|
@@ -20,7 +33,8 @@ export interface LintOutcome {
|
|
|
20
33
|
/**
|
|
21
34
|
* Match a file path against the config `exclude` globs. Returns the matching
|
|
22
35
|
* pattern, or undefined. Patterns without a slash also match basenames at
|
|
23
|
-
* any depth, mirroring protected-path semantics.
|
|
36
|
+
* any depth, mirroring protected-path semantics. Matchers are compiled once
|
|
37
|
+
* per config via the shared `compileGlobMatchers` cache.
|
|
24
38
|
*/
|
|
25
39
|
export declare function matchExclude(config: ResolvedConfig, filePath: string, directory?: string): string | undefined;
|
|
26
40
|
/**
|
package/dist/lint.js
CHANGED
|
@@ -4,14 +4,47 @@
|
|
|
4
4
|
* hook wiring lives in src/index.ts.
|
|
5
5
|
*/
|
|
6
6
|
import { basename, dirname, extname, isAbsolute, relative } from "node:path";
|
|
7
|
-
import
|
|
8
|
-
import { normalizeCommandMap, splitCommand } from "./command-utils.js";
|
|
7
|
+
import { compileGlobMatchers, normalizeCommandMap, splitCommand } from "./command-utils.js";
|
|
9
8
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
10
9
|
export const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
10
|
+
/** Cap on concurrent linter subprocesses; per-edit and gate lints share one limiter per session. */
|
|
11
|
+
export const MAX_CONCURRENT_LINTS = 4;
|
|
12
|
+
/**
|
|
13
|
+
* Create a FIFO semaphore bounding concurrent linter subprocesses. Queued
|
|
14
|
+
* callers wait their turn — lint output is delayed under burst load, never
|
|
15
|
+
* dropped. Release is in `finally`, so a throwing linter cannot wedge the
|
|
16
|
+
* limiter. Non-positive limits clamp to 1 (serial) instead of deadlocking.
|
|
17
|
+
*/
|
|
18
|
+
export function createLintLimiter(limit = MAX_CONCURRENT_LINTS) {
|
|
19
|
+
const capacity = Math.max(1, Math.floor(limit));
|
|
20
|
+
let active = 0;
|
|
21
|
+
const queue = [];
|
|
22
|
+
return {
|
|
23
|
+
async run(fn) {
|
|
24
|
+
if (active >= capacity) {
|
|
25
|
+
await new Promise((resolve) => {
|
|
26
|
+
queue.push(resolve);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
active += 1;
|
|
30
|
+
try {
|
|
31
|
+
return await fn();
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
active -= 1;
|
|
35
|
+
const next = queue.shift();
|
|
36
|
+
if (next !== undefined) {
|
|
37
|
+
next();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
11
43
|
/**
|
|
12
44
|
* Match a file path against the config `exclude` globs. Returns the matching
|
|
13
45
|
* pattern, or undefined. Patterns without a slash also match basenames at
|
|
14
|
-
* any depth, mirroring protected-path semantics.
|
|
46
|
+
* any depth, mirroring protected-path semantics. Matchers are compiled once
|
|
47
|
+
* per config via the shared `compileGlobMatchers` cache.
|
|
15
48
|
*/
|
|
16
49
|
export function matchExclude(config, filePath, directory) {
|
|
17
50
|
let candidate = filePath;
|
|
@@ -20,12 +53,11 @@ export function matchExclude(config, filePath, directory) {
|
|
|
20
53
|
}
|
|
21
54
|
candidate = candidate.replace(/^\.\//, "");
|
|
22
55
|
const name = basename(candidate);
|
|
23
|
-
for (const pattern of config.exclude) {
|
|
24
|
-
|
|
25
|
-
if (isMatch(candidate)) {
|
|
56
|
+
for (const { pattern, match } of compileGlobMatchers(config.exclude)) {
|
|
57
|
+
if (match(candidate)) {
|
|
26
58
|
return pattern;
|
|
27
59
|
}
|
|
28
|
-
if (!pattern.includes("/") &&
|
|
60
|
+
if (!pattern.includes("/") && match(name)) {
|
|
29
61
|
return pattern;
|
|
30
62
|
}
|
|
31
63
|
}
|
package/dist/protect.d.ts
CHANGED
|
@@ -29,7 +29,8 @@ export declare function extractCommand(args: unknown): string | undefined;
|
|
|
29
29
|
/**
|
|
30
30
|
* Check a file path against the protected globs. Returns the matching
|
|
31
31
|
* pattern, or undefined. Patterns without a slash also match basenames at
|
|
32
|
-
* any depth (so `.env*` protects `config/.env.local` too).
|
|
32
|
+
* any depth (so `.env*` protects `config/.env.local` too). Matchers are
|
|
33
|
+
* compiled once per config via the shared `compileGlobMatchers` cache.
|
|
33
34
|
*/
|
|
34
35
|
export declare function matchProtectedPath(config: ResolvedConfig, filePath: string, directory?: string): string | undefined;
|
|
35
36
|
/** Check a shell command against the dangerous-command list. */
|
package/dist/protect.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* src/index.ts.
|
|
5
5
|
*/
|
|
6
6
|
import { basename, isAbsolute, relative } from "node:path";
|
|
7
|
-
import
|
|
7
|
+
import { compileGlobMatchers } from "./command-utils.js";
|
|
8
8
|
/** Tools whose args carry a target file path. */
|
|
9
9
|
export const FILE_TOOLS = new Set(["edit", "write", "patch"]);
|
|
10
10
|
/** Tools whose args carry a shell command. */
|
|
@@ -55,7 +55,8 @@ export function extractCommand(args) {
|
|
|
55
55
|
/**
|
|
56
56
|
* Check a file path against the protected globs. Returns the matching
|
|
57
57
|
* pattern, or undefined. Patterns without a slash also match basenames at
|
|
58
|
-
* any depth (so `.env*` protects `config/.env.local` too).
|
|
58
|
+
* any depth (so `.env*` protects `config/.env.local` too). Matchers are
|
|
59
|
+
* compiled once per config via the shared `compileGlobMatchers` cache.
|
|
59
60
|
*/
|
|
60
61
|
export function matchProtectedPath(config, filePath, directory) {
|
|
61
62
|
let candidate = filePath;
|
|
@@ -64,12 +65,11 @@ export function matchProtectedPath(config, filePath, directory) {
|
|
|
64
65
|
}
|
|
65
66
|
candidate = candidate.replace(/^\.\//, "");
|
|
66
67
|
const name = basename(candidate);
|
|
67
|
-
for (const pattern of config.protect) {
|
|
68
|
-
|
|
69
|
-
if (isMatch(candidate)) {
|
|
68
|
+
for (const { pattern, match } of compileGlobMatchers(config.protect)) {
|
|
69
|
+
if (match(candidate)) {
|
|
70
70
|
return pattern;
|
|
71
71
|
}
|
|
72
|
-
if (!pattern.includes("/") &&
|
|
72
|
+
if (!pattern.includes("/") && match(name)) {
|
|
73
73
|
return pattern;
|
|
74
74
|
}
|
|
75
75
|
}
|
package/dist/rules.d.ts
CHANGED
|
@@ -37,6 +37,21 @@ export interface ConstitutionResult {
|
|
|
37
37
|
* "Style Guide" heading.
|
|
38
38
|
*/
|
|
39
39
|
export declare function loadConstitution(config: ResolvedConfig, directory?: string): Promise<ConstitutionResult>;
|
|
40
|
+
/**
|
|
41
|
+
* Length of the constitution prefix used as a fast precheck. Most model
|
|
42
|
+
* requests do not contain the constitution yet; scanning for a short prefix
|
|
43
|
+
* fails fast instead of running the full-text search over a 10–20KB needle.
|
|
44
|
+
*/
|
|
45
|
+
export declare const CONSTITUTION_PREFIX_LENGTH = 128;
|
|
46
|
+
/**
|
|
47
|
+
* True when the constitution is already present in the system prompt parts.
|
|
48
|
+
* Semantics match the old inline check exactly (`some(part =>
|
|
49
|
+
* part.includes(constitution))`); the prefix precheck only skips the
|
|
50
|
+
* expensive full scan when the constitution is absent.
|
|
51
|
+
*/
|
|
52
|
+
export declare function constitutionPresent(parts: ReadonlyArray<{
|
|
53
|
+
text: string;
|
|
54
|
+
} | string>, constitution: string): boolean;
|
|
40
55
|
/**
|
|
41
56
|
* Appends the constitution to the last system-prompt entry, unless it is already
|
|
42
57
|
* present. This keeps the system prompt compact instead of adding a separate
|
package/dist/rules.js
CHANGED
|
@@ -169,6 +169,25 @@ export async function loadConstitution(config, directory) {
|
|
|
169
169
|
warning: warnings.length > 0 ? warnings.join("\n") : undefined,
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Length of the constitution prefix used as a fast precheck. Most model
|
|
174
|
+
* requests do not contain the constitution yet; scanning for a short prefix
|
|
175
|
+
* fails fast instead of running the full-text search over a 10–20KB needle.
|
|
176
|
+
*/
|
|
177
|
+
export const CONSTITUTION_PREFIX_LENGTH = 128;
|
|
178
|
+
/**
|
|
179
|
+
* True when the constitution is already present in the system prompt parts.
|
|
180
|
+
* Semantics match the old inline check exactly (`some(part =>
|
|
181
|
+
* part.includes(constitution))`); the prefix precheck only skips the
|
|
182
|
+
* expensive full scan when the constitution is absent.
|
|
183
|
+
*/
|
|
184
|
+
export function constitutionPresent(parts, constitution) {
|
|
185
|
+
const prefix = constitution.slice(0, CONSTITUTION_PREFIX_LENGTH);
|
|
186
|
+
return parts.some((part) => {
|
|
187
|
+
const text = typeof part === "string" ? part : part.text;
|
|
188
|
+
return text.includes(prefix) && text.includes(constitution);
|
|
189
|
+
});
|
|
190
|
+
}
|
|
172
191
|
/**
|
|
173
192
|
* Appends the constitution to the last system-prompt entry, unless it is already
|
|
174
193
|
* present. This keeps the system prompt compact instead of adding a separate
|
|
@@ -178,7 +197,7 @@ export function injectConstitution(system, constitution) {
|
|
|
178
197
|
if (constitution === null) {
|
|
179
198
|
return system;
|
|
180
199
|
}
|
|
181
|
-
if (system
|
|
200
|
+
if (constitutionPresent(system, constitution)) {
|
|
182
201
|
return system;
|
|
183
202
|
}
|
|
184
203
|
if (system.length === 0) {
|
package/package.json
CHANGED
package/rules/40-delegation.md
CHANGED
|
@@ -50,6 +50,15 @@ does. Use judgment, but never skip the test-grounding and review steps for behav
|
|
|
50
50
|
changes. If the specialist agents are not installed in this project, perform the same
|
|
51
51
|
checks yourself with the skills in this section.
|
|
52
52
|
|
|
53
|
+
## Execute plans under `/df-goal`
|
|
54
|
+
|
|
55
|
+
When the task starts from a written plan (yours or the user's), execute it as
|
|
56
|
+
`/df-goal <objective>` — the objective is the plan inline when short, or
|
|
57
|
+
`Implement the plan in <path>` when long — so native completion requires the
|
|
58
|
+
framework gate's PASS, not just your summary. A `dev_framework_verify` FAIL is
|
|
59
|
+
a verdict: fix the underlying cause and re-verify, never declare the plan met
|
|
60
|
+
without a tool-result PASS in the transcript.
|
|
61
|
+
|
|
53
62
|
## Skills
|
|
54
63
|
|
|
55
64
|
For explicit, repeatable workflows you can invoke the bundled skills:
|