opencode-dev-framework 1.9.5 → 1.10.1
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 +137 -33
- package/bin/df +94 -4
- package/cordis.patch.yml +17 -0
- package/dist/adapters/dsh/extract.d.ts +47 -0
- package/dist/adapters/dsh/extract.js +62 -0
- package/dist/adapters/dsh/index.d.ts +332 -0
- package/dist/adapters/dsh/index.js +1643 -0
- package/dist/adapters/opencode/index.d.ts +30 -0
- package/dist/{index.js → adapters/opencode/index.js} +120 -235
- package/dist/{block-store.d.ts → core/block-store.d.ts} +10 -3
- package/dist/{commands.js → core/commands.js} +4 -2
- package/dist/{config.d.ts → core/config.d.ts} +16 -4
- package/dist/{config.js → core/config.js} +102 -10
- package/dist/{format-status.d.ts → core/format-status.d.ts} +13 -2
- package/dist/{format-status.js → core/format-status.js} +30 -7
- package/dist/{gate.d.ts → core/gate.d.ts} +9 -1
- package/dist/{gate.js → core/gate.js} +14 -2
- package/dist/{goal.d.ts → core/goal.d.ts} +4 -3
- package/dist/{goal.js → core/goal.js} +4 -3
- package/dist/{harness.d.ts → core/harness.d.ts} +10 -5
- package/dist/{harness.js → core/harness.js} +119 -32
- package/dist/{init.d.ts → core/init.d.ts} +18 -1
- package/dist/{init.js → core/init.js} +33 -8
- package/dist/core/install-dsh.d.ts +67 -0
- package/dist/core/install-dsh.js +235 -0
- package/dist/{installer.d.ts → core/installer.d.ts} +32 -2
- package/dist/{installer.js → core/installer.js} +129 -12
- package/dist/{lint.d.ts → core/lint.d.ts} +43 -2
- package/dist/{lint.js → core/lint.js} +89 -2
- package/dist/core/paths.d.ts +35 -0
- package/dist/core/paths.js +41 -0
- package/dist/{protect.d.ts → core/protect.d.ts} +18 -4
- package/dist/{protect.js → core/protect.js} +85 -34
- package/dist/{registry.d.ts → core/registry.d.ts} +9 -1
- package/dist/{review.js → core/review.js} +14 -6
- package/dist/{rules.d.ts → core/rules.d.ts} +3 -2
- package/dist/{rules.js → core/rules.js} +21 -5
- package/dist/core/run-hooks.d.ts +138 -0
- package/dist/core/run-hooks.js +196 -0
- package/dist/{runtime-status.d.ts → core/runtime-status.d.ts} +5 -4
- package/dist/{runtime-status.js → core/runtime-status.js} +29 -17
- package/dist/{types.d.ts → core/types.d.ts} +17 -0
- package/dist/{update.d.ts → core/update.d.ts} +12 -4
- package/dist/{update.js → core/update.js} +28 -12
- package/dist/{weakening.js → core/weakening.js} +2 -1
- package/package.json +23 -8
- package/rules/40-delegation.md +13 -2
- package/templates/.opencode/agents/style-enforcer.md +1 -1
- package/templates/.opencode/agents/test-grounder.md +1 -1
- package/templates/.opencode/skills/ground-in-tests/SKILL.md +1 -1
- package/templates/.opencode/skills/project-config/SKILL.md +2 -2
- package/tui.tsx +6 -6
- package/dist/index.d.ts +0 -101
- /package/dist/{block-store.js → core/block-store.js} +0 -0
- /package/dist/{command-utils.d.ts → core/command-utils.d.ts} +0 -0
- /package/dist/{command-utils.js → core/command-utils.js} +0 -0
- /package/dist/{commands.d.ts → core/commands.d.ts} +0 -0
- /package/dist/{detect.d.ts → core/detect.d.ts} +0 -0
- /package/dist/{detect.js → core/detect.js} +0 -0
- /package/dist/{host.d.ts → core/host.d.ts} +0 -0
- /package/dist/{host.js → core/host.js} +0 -0
- /package/dist/{logger.d.ts → core/logger.d.ts} +0 -0
- /package/dist/{logger.js → core/logger.js} +0 -0
- /package/dist/{registry.js → core/registry.js} +0 -0
- /package/dist/{review.d.ts → core/review.d.ts} +0 -0
- /package/dist/{roster.d.ts → core/roster.d.ts} +0 -0
- /package/dist/{roster.js → core/roster.js} +0 -0
- /package/dist/{types.js → core/types.js} +0 -0
- /package/dist/{weakening.d.ts → core/weakening.d.ts} +0 -0
- /package/templates/{.opencode/opencode-dev-framework → .dev-framework}/rules/.gitkeep +0 -0
|
@@ -22,6 +22,25 @@ export interface TemplateStatus {
|
|
|
22
22
|
present: string[];
|
|
23
23
|
different: string[];
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* DSH skill roots scanned by the host skill-filesystem provider, highest
|
|
27
|
+
* rank first. `.opencode/skills` (the OpenCode layout `installTemplates`
|
|
28
|
+
* writes) is not among them, so a DSH `df-init` must mirror the bundled
|
|
29
|
+
* skills here or the `skill` tool never catalogs them and the setup brief
|
|
30
|
+
* names something the agent cannot load — the framework would not start.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DSH_SKILL_ROOTS: readonly [".dsh/skills", ".agents/skills"];
|
|
33
|
+
/**
|
|
34
|
+
* Mirror the bundled `.opencode/skills` templates into a DSH-scanned skill
|
|
35
|
+
* root so the host `skill` tool catalogs them. Same skip/overwrite
|
|
36
|
+
* semantics as `installTemplates`: never clobber user files unasked.
|
|
37
|
+
* Returns created/skipped/overwritten paths relative to the target dir.
|
|
38
|
+
* `statusTemplates` only iterates the template set, so these copies never
|
|
39
|
+
* read as drift.
|
|
40
|
+
*/
|
|
41
|
+
export declare function mirrorSkillsToDsh(targetDir: string, root?: string, options?: InstallOptions): Promise<InstallResult>;
|
|
42
|
+
/** List the bundled skill names (subdirectories of `.opencode/skills`). */
|
|
43
|
+
export declare function listSkillNames(): Promise<string[]>;
|
|
25
44
|
/** List all template files relative to TEMPLATES_DIR. */
|
|
26
45
|
export declare function listTemplateFiles(): Promise<string[]>;
|
|
27
46
|
/**
|
|
@@ -29,6 +48,15 @@ export declare function listTemplateFiles(): Promise<string[]>;
|
|
|
29
48
|
* Returns lists of created, skipped, and overwritten files (relative paths).
|
|
30
49
|
*/
|
|
31
50
|
export declare function installTemplates(targetDir: string, options?: InstallOptions): Promise<InstallResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Compare a skill mirror root against its `.opencode/skills` sources.
|
|
53
|
+
* Returns mirror-relative drift: absent mirrors read as `add`, differing
|
|
54
|
+
* ones as `refresh`. Orphaned mirrors (no template source — a skill the
|
|
55
|
+
* shipment dropped) are ignored: never nag about files we no longer ship.
|
|
56
|
+
* Like `statusTemplates`, a broken source dir throws instead of reading
|
|
57
|
+
* as clean. Shares the `TemplateStatus` shape so drift merges trivially.
|
|
58
|
+
*/
|
|
59
|
+
export declare function statusMirror(targetDir: string, root?: string): Promise<TemplateStatus>;
|
|
32
60
|
/**
|
|
33
61
|
* Compare the target project against the bundled templates.
|
|
34
62
|
*/
|
|
@@ -37,9 +65,11 @@ export interface ConfigWriteResult {
|
|
|
37
65
|
action: "created" | "skipped" | "overwritten";
|
|
38
66
|
}
|
|
39
67
|
/**
|
|
40
|
-
* Write a project-level `.
|
|
68
|
+
* Write a project-level `.dev-framework.yml` based on detected
|
|
41
69
|
* tooling. Respects the same overwrite/skip flags and prompt as
|
|
42
|
-
* `installTemplates`.
|
|
70
|
+
* `installTemplates`. An existing legacy `.opencode-dev-framework.yml`
|
|
71
|
+
* is left alone (the loader still reads it) — new files use the
|
|
72
|
+
* neutral name.
|
|
43
73
|
*/
|
|
44
74
|
export declare function writeDetectedConfig(targetDir: string, options?: InstallOptions): Promise<ConfigWriteResult>;
|
|
45
75
|
/** Bounded trial-run timeout (seconds): init UX, not a gate suite. */
|
|
@@ -3,10 +3,93 @@ import { dirname, join, resolve } from "node:path";
|
|
|
3
3
|
import { createInterface } from "node:readline";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { splitCommand } from "./command-utils.js";
|
|
6
|
-
import { checkConfigEnforceable, DEFAULT_PROTECT, resolveConfig } from "./config.js";
|
|
6
|
+
import { checkConfigEnforceable, DEFAULT_PROTECT, existingConfigPath, resolveConfig, } from "./config.js";
|
|
7
7
|
import { detectProject } from "./detect.js";
|
|
8
8
|
/** Directory containing the project templates shipped with the package. */
|
|
9
|
-
export const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "templates");
|
|
9
|
+
export const TEMPLATES_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "templates");
|
|
10
|
+
/**
|
|
11
|
+
* DSH skill roots scanned by the host skill-filesystem provider, highest
|
|
12
|
+
* rank first. `.opencode/skills` (the OpenCode layout `installTemplates`
|
|
13
|
+
* writes) is not among them, so a DSH `df-init` must mirror the bundled
|
|
14
|
+
* skills here or the `skill` tool never catalogs them and the setup brief
|
|
15
|
+
* names something the agent cannot load — the framework would not start.
|
|
16
|
+
*/
|
|
17
|
+
export const DSH_SKILL_ROOTS = [".dsh/skills", ".agents/skills"];
|
|
18
|
+
/**
|
|
19
|
+
* Mirror the bundled `.opencode/skills` templates into a DSH-scanned skill
|
|
20
|
+
* root so the host `skill` tool catalogs them. Same skip/overwrite
|
|
21
|
+
* semantics as `installTemplates`: never clobber user files unasked.
|
|
22
|
+
* Returns created/skipped/overwritten paths relative to the target dir.
|
|
23
|
+
* `statusTemplates` only iterates the template set, so these copies never
|
|
24
|
+
* read as drift.
|
|
25
|
+
*/
|
|
26
|
+
export async function mirrorSkillsToDsh(targetDir, root = DSH_SKILL_ROOTS[0], options = {}) {
|
|
27
|
+
const result = { created: [], skipped: [], overwritten: [] };
|
|
28
|
+
const prompt = options.prompt ?? defaultPrompt;
|
|
29
|
+
/** Sticky decision set when the user answers "all" or "none". */
|
|
30
|
+
let stickyDecision = null;
|
|
31
|
+
// Loud like `listTemplateFiles`: a missing/unreadable skills dir is
|
|
32
|
+
// packaging breakage, and silence would present a clean init whose brief
|
|
33
|
+
// names a skill the host can never catalog.
|
|
34
|
+
const names = await listSkillNames();
|
|
35
|
+
const skillsDir = join(TEMPLATES_DIR, ".opencode", "skills");
|
|
36
|
+
for (const name of names) {
|
|
37
|
+
const source = join(skillsDir, name, "SKILL.md");
|
|
38
|
+
const sourceContent = await readFileSafe(source);
|
|
39
|
+
if (sourceContent === null) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const relative = `${root}/${name}/SKILL.md`;
|
|
43
|
+
const destination = join(targetDir, relative);
|
|
44
|
+
if (!(await fileExists(destination))) {
|
|
45
|
+
await fs.mkdir(dirname(destination), { recursive: true });
|
|
46
|
+
await fs.writeFile(destination, sourceContent, "utf8");
|
|
47
|
+
result.created.push(relative);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if ((await readFileSafe(destination)) === sourceContent) {
|
|
51
|
+
result.skipped.push(relative);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
let decision;
|
|
55
|
+
if (stickyDecision !== null) {
|
|
56
|
+
decision = stickyDecision;
|
|
57
|
+
}
|
|
58
|
+
else if (options.skipExisting) {
|
|
59
|
+
decision = "skip";
|
|
60
|
+
}
|
|
61
|
+
else if (options.overwriteExisting) {
|
|
62
|
+
decision = "overwrite";
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
decision = await prompt(relative);
|
|
66
|
+
}
|
|
67
|
+
if (decision === "overwrite-all") {
|
|
68
|
+
stickyDecision = "overwrite";
|
|
69
|
+
decision = "overwrite";
|
|
70
|
+
}
|
|
71
|
+
else if (decision === "skip-all") {
|
|
72
|
+
stickyDecision = "skip";
|
|
73
|
+
decision = "skip";
|
|
74
|
+
}
|
|
75
|
+
if (decision === "overwrite") {
|
|
76
|
+
await fs.writeFile(destination, sourceContent, "utf8");
|
|
77
|
+
result.overwritten.push(relative);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
result.skipped.push(relative);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
/** List the bundled skill names (subdirectories of `.opencode/skills`). */
|
|
86
|
+
export async function listSkillNames() {
|
|
87
|
+
const skillsDir = join(TEMPLATES_DIR, ".opencode", "skills");
|
|
88
|
+
return (await fs.readdir(skillsDir, { withFileTypes: true }))
|
|
89
|
+
.filter((entry) => entry.isDirectory())
|
|
90
|
+
.map((entry) => entry.name)
|
|
91
|
+
.sort();
|
|
92
|
+
}
|
|
10
93
|
/** List all template files relative to TEMPLATES_DIR. */
|
|
11
94
|
export async function listTemplateFiles() {
|
|
12
95
|
const files = [];
|
|
@@ -129,6 +212,36 @@ export async function installTemplates(targetDir, options = {}) {
|
|
|
129
212
|
}
|
|
130
213
|
return result;
|
|
131
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* Compare a skill mirror root against its `.opencode/skills` sources.
|
|
217
|
+
* Returns mirror-relative drift: absent mirrors read as `add`, differing
|
|
218
|
+
* ones as `refresh`. Orphaned mirrors (no template source — a skill the
|
|
219
|
+
* shipment dropped) are ignored: never nag about files we no longer ship.
|
|
220
|
+
* Like `statusTemplates`, a broken source dir throws instead of reading
|
|
221
|
+
* as clean. Shares the `TemplateStatus` shape so drift merges trivially.
|
|
222
|
+
*/
|
|
223
|
+
export async function statusMirror(targetDir, root = DSH_SKILL_ROOTS[0]) {
|
|
224
|
+
const drift = { present: [], different: [], missing: [] };
|
|
225
|
+
const skillsDir = join(TEMPLATES_DIR, ".opencode", "skills");
|
|
226
|
+
for (const name of await listSkillNames()) {
|
|
227
|
+
const sourceContent = await readFileSafe(join(skillsDir, name, "SKILL.md"));
|
|
228
|
+
if (sourceContent === null) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const relative = `${root}/${name}/SKILL.md`;
|
|
232
|
+
const existing = await readFileSafe(join(targetDir, relative));
|
|
233
|
+
if (existing === null) {
|
|
234
|
+
drift.missing.push(relative);
|
|
235
|
+
}
|
|
236
|
+
else if (existing === sourceContent) {
|
|
237
|
+
drift.present.push(relative);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
drift.different.push(relative);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return drift;
|
|
244
|
+
}
|
|
132
245
|
/**
|
|
133
246
|
* Compare the target project against the bundled templates.
|
|
134
247
|
*/
|
|
@@ -212,14 +325,14 @@ function buildDefaultConfigYaml(language, commands, hasPreCommitConfig) {
|
|
|
212
325
|
lines.push(" scope: all");
|
|
213
326
|
lines.push(" lint_changed: false");
|
|
214
327
|
lines.push(" # standard/strict default: sessions that changed files must produce a");
|
|
215
|
-
lines.push(" # peer-review artifact (.
|
|
328
|
+
lines.push(" # peer-review artifact (.dev-framework/review.md).");
|
|
216
329
|
lines.push(" require_review: true");
|
|
217
330
|
lines.push(" timeout: 300");
|
|
218
331
|
lines.push(" max_blocks: 3");
|
|
219
332
|
lines.push("");
|
|
220
333
|
lines.push("# Optional: pre-flight task list. When set, edit tools are denied");
|
|
221
334
|
lines.push("# (standard/strict) until the agent writes its findings to");
|
|
222
|
-
lines.push("# .
|
|
335
|
+
lines.push("# .dev-framework/preflight.md. Use for work that");
|
|
223
336
|
lines.push("# must establish baseline state/knowledge before editing.");
|
|
224
337
|
lines.push("# preflight:");
|
|
225
338
|
lines.push('# - "Summarize the current state of the component you will change"');
|
|
@@ -231,21 +344,25 @@ function buildDefaultConfigYaml(language, commands, hasPreCommitConfig) {
|
|
|
231
344
|
return lines.join("\n");
|
|
232
345
|
}
|
|
233
346
|
/**
|
|
234
|
-
* Write a project-level `.
|
|
347
|
+
* Write a project-level `.dev-framework.yml` based on detected
|
|
235
348
|
* tooling. Respects the same overwrite/skip flags and prompt as
|
|
236
|
-
* `installTemplates`.
|
|
349
|
+
* `installTemplates`. An existing legacy `.opencode-dev-framework.yml`
|
|
350
|
+
* is left alone (the loader still reads it) — new files use the
|
|
351
|
+
* neutral name.
|
|
237
352
|
*/
|
|
238
353
|
export async function writeDetectedConfig(targetDir, options = {}) {
|
|
239
354
|
const { language, commands, hasPreCommitConfig } = detectProject(targetDir);
|
|
240
355
|
const content = buildDefaultConfigYaml(language, commands, hasPreCommitConfig);
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
356
|
+
// Honor the deployment's established name: a config under any supported
|
|
357
|
+
// name keeps its name (no shadowing duplicate); new deployments get the
|
|
358
|
+
// neutral one.
|
|
359
|
+
const destination = existingConfigPath(targetDir) ?? join(targetDir, ".dev-framework.yml");
|
|
360
|
+
const relativePath = destination.slice(targetDir.length + 1);
|
|
361
|
+
const existing = await readFileSafe(destination);
|
|
362
|
+
if (existing === null) {
|
|
245
363
|
await fs.writeFile(destination, content, "utf8");
|
|
246
364
|
return { action: "created" };
|
|
247
365
|
}
|
|
248
|
-
const existing = await readFileSafe(destination);
|
|
249
366
|
if (existing === content) {
|
|
250
367
|
return { action: "skipped" };
|
|
251
368
|
}
|
|
@@ -451,7 +568,7 @@ export function formatWizardBrief(brief) {
|
|
|
451
568
|
}
|
|
452
569
|
lines.push("", "Handoff: follow the project-config skill (templates/.opencode/skills/project-config/SKILL.md) " +
|
|
453
570
|
"to resolve the questions above, run the real commands, and present " +
|
|
454
|
-
".
|
|
571
|
+
".dev-framework.yml + .dev-framework/hardening.md for review. Do not write without review.");
|
|
455
572
|
return lines;
|
|
456
573
|
}
|
|
457
574
|
/**
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-edit lint: resolve the linter command for a changed file and run it
|
|
3
|
-
* through an injectable command runner. Pure orchestration — the
|
|
4
|
-
*
|
|
3
|
+
* through an injectable command runner. Pure orchestration — the hook flows
|
|
4
|
+
* live in `src/core/run-hooks.ts`, driven by thin registration in
|
|
5
|
+
* `src/adapters/opencode/index.ts`.
|
|
5
6
|
*/
|
|
6
7
|
import type { CommandResult, RunCommand } from "./host.js";
|
|
7
8
|
import type { ResolvedConfig } from "./types.js";
|
|
8
9
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
9
10
|
export declare const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
11
|
+
/**
|
|
12
|
+
* Fallback per-format timeout (seconds). Same value as the lint default —
|
|
13
|
+
* a separate name so each concern can be tuned (and audited) independently.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_FORMAT_TIMEOUT_SECONDS = 60;
|
|
10
16
|
/** Cap on concurrent linter subprocesses; per-edit and gate lints share one limiter per session. */
|
|
11
17
|
export declare const MAX_CONCURRENT_LINTS = 4;
|
|
12
18
|
/** FIFO semaphore bounding concurrent linter subprocesses, shared per session. */
|
|
@@ -68,3 +74,38 @@ export declare function lintFile(run: RunCommand, config: ResolvedConfig, filePa
|
|
|
68
74
|
export declare function isLintFailure(outcome: LintOutcome): boolean;
|
|
69
75
|
/** One-line summary of a lint outcome for logging. */
|
|
70
76
|
export declare function summarizeLint(outcome: LintOutcome): string;
|
|
77
|
+
export interface FormatOutcome {
|
|
78
|
+
/** True when no formatter ran (file excluded or no command configured). */
|
|
79
|
+
skipped: boolean;
|
|
80
|
+
/** Why the file was skipped, when it was. */
|
|
81
|
+
reason?: string;
|
|
82
|
+
filePath: string;
|
|
83
|
+
/** The argv that was executed, when a formatter ran. */
|
|
84
|
+
command?: string[];
|
|
85
|
+
result?: CommandResult;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Resolve the format command for a file: the per-extension override wins over
|
|
89
|
+
* the default command. The `{file}` token is replaced with the file path and
|
|
90
|
+
* `{dir}` with the file's directory (same package-context rationale as lint —
|
|
91
|
+
* some formatters resolve config per directory); commands with neither token
|
|
92
|
+
* run as-is. Returns undefined when no format command is configured at all.
|
|
93
|
+
*/
|
|
94
|
+
export declare function resolveFormatCommand(config: ResolvedConfig, filePath: string): string[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Format a single file. Excluded files and file types without a configured
|
|
97
|
+
* formatter are skipped; everything else runs through the injected runner.
|
|
98
|
+
* Files that no longer exist (deleted mid-session but still tracked) are
|
|
99
|
+
* skipped with reason "file no longer exists" — never failed. Relative
|
|
100
|
+
* `filePath` values resolve against `options.cwd`; pass `cwd` at call
|
|
101
|
+
* sites (no production caller yet — the opencode adapter intentionally
|
|
102
|
+
* never calls `formatFile`; see plan 25).
|
|
103
|
+
*/
|
|
104
|
+
export declare function formatFile(run: RunCommand, config: ResolvedConfig, filePath: string, options?: {
|
|
105
|
+
cwd?: string;
|
|
106
|
+
timeout?: number;
|
|
107
|
+
}): Promise<FormatOutcome>;
|
|
108
|
+
/** True when a format outcome represents a failure (non-zero exit or timeout). */
|
|
109
|
+
export declare function isFormatFailure(outcome: FormatOutcome): boolean;
|
|
110
|
+
/** One-line summary of a format outcome for logging. */
|
|
111
|
+
export declare function summarizeFormat(outcome: FormatOutcome): string;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-edit lint: resolve the linter command for a changed file and run it
|
|
3
|
-
* through an injectable command runner. Pure orchestration — the
|
|
4
|
-
*
|
|
3
|
+
* through an injectable command runner. Pure orchestration — the hook flows
|
|
4
|
+
* live in `src/core/run-hooks.ts`, driven by thin registration in
|
|
5
|
+
* `src/adapters/opencode/index.ts`.
|
|
5
6
|
*/
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { basename, dirname, extname, isAbsolute, relative } from "node:path";
|
|
8
9
|
import { compileGlobMatchers, normalizeCommandMap, splitCommand, toAbsolutePath, } from "./command-utils.js";
|
|
9
10
|
/** Fallback per-lint timeout (seconds) when the config sets none. */
|
|
10
11
|
export const DEFAULT_LINT_TIMEOUT_SECONDS = 60;
|
|
12
|
+
/**
|
|
13
|
+
* Fallback per-format timeout (seconds). Same value as the lint default —
|
|
14
|
+
* a separate name so each concern can be tuned (and audited) independently.
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_FORMAT_TIMEOUT_SECONDS = 60;
|
|
11
17
|
/** Cap on concurrent linter subprocesses; per-edit and gate lints share one limiter per session. */
|
|
12
18
|
export const MAX_CONCURRENT_LINTS = 4;
|
|
13
19
|
/**
|
|
@@ -158,3 +164,84 @@ export function summarizeLint(outcome) {
|
|
|
158
164
|
}
|
|
159
165
|
return `lint passed for ${outcome.filePath}`;
|
|
160
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Resolve the format command for a file: the per-extension override wins over
|
|
169
|
+
* the default command. The `{file}` token is replaced with the file path and
|
|
170
|
+
* `{dir}` with the file's directory (same package-context rationale as lint —
|
|
171
|
+
* some formatters resolve config per directory); commands with neither token
|
|
172
|
+
* run as-is. Returns undefined when no format command is configured at all.
|
|
173
|
+
*/
|
|
174
|
+
export function resolveFormatCommand(config, filePath) {
|
|
175
|
+
const { default: defaultCommand, byExtension } = normalizeCommandMap(config.commands.format);
|
|
176
|
+
const template = byExtension[extname(filePath)] ?? defaultCommand;
|
|
177
|
+
if (template === undefined) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const dir = dirname(filePath);
|
|
181
|
+
return splitCommand(template).map((token) => token.replaceAll("{file}", filePath).replaceAll("{dir}", dir));
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Format a single file. Excluded files and file types without a configured
|
|
185
|
+
* formatter are skipped; everything else runs through the injected runner.
|
|
186
|
+
* Files that no longer exist (deleted mid-session but still tracked) are
|
|
187
|
+
* skipped with reason "file no longer exists" — never failed. Relative
|
|
188
|
+
* `filePath` values resolve against `options.cwd`; pass `cwd` at call
|
|
189
|
+
* sites (no production caller yet — the opencode adapter intentionally
|
|
190
|
+
* never calls `formatFile`; see plan 25).
|
|
191
|
+
*/
|
|
192
|
+
export async function formatFile(run, config, filePath, options) {
|
|
193
|
+
const excluded = matchExclude(config, filePath, options?.cwd);
|
|
194
|
+
if (excluded !== undefined) {
|
|
195
|
+
return { skipped: true, reason: `excluded by "${excluded}"`, filePath };
|
|
196
|
+
}
|
|
197
|
+
const command = resolveFormatCommand(config, filePath);
|
|
198
|
+
if (command === undefined) {
|
|
199
|
+
return { skipped: true, reason: "no format command configured for this file type", filePath };
|
|
200
|
+
}
|
|
201
|
+
// Ghost entries: the tracker holds every file touched this session and
|
|
202
|
+
// only clears on pass, so files deleted mid-session are still listed.
|
|
203
|
+
// There is nothing to format in a file that isn't there — skip, never fail.
|
|
204
|
+
// (A file deleted between this probe and the formatter spawn is excused by
|
|
205
|
+
// the re-probe below.)
|
|
206
|
+
const absolute = toAbsolutePath(filePath, options?.cwd);
|
|
207
|
+
if (!existsSync(absolute)) {
|
|
208
|
+
return { skipped: true, reason: "file no longer exists", filePath };
|
|
209
|
+
}
|
|
210
|
+
const result = await run(command, {
|
|
211
|
+
cwd: options?.cwd,
|
|
212
|
+
timeout: options?.timeout ?? DEFAULT_FORMAT_TIMEOUT_SECONDS,
|
|
213
|
+
});
|
|
214
|
+
if (result.timedOut || result.exitCode !== 0) {
|
|
215
|
+
// TOCTOU safety net: the file may have vanished between the probe
|
|
216
|
+
// above and the formatter spawn. A missing file can never be at fault,
|
|
217
|
+
// so re-probe before blaming it — skip rather than fail on a ghost.
|
|
218
|
+
if (!existsSync(absolute)) {
|
|
219
|
+
return { skipped: true, reason: "file no longer exists", filePath };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return { skipped: false, filePath, command, result };
|
|
223
|
+
}
|
|
224
|
+
/** True when a format outcome represents a failure (non-zero exit or timeout). */
|
|
225
|
+
export function isFormatFailure(outcome) {
|
|
226
|
+
if (outcome.skipped || outcome.result === undefined) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
return outcome.result.timedOut || outcome.result.exitCode !== 0;
|
|
230
|
+
}
|
|
231
|
+
/** One-line summary of a format outcome for logging. */
|
|
232
|
+
export function summarizeFormat(outcome) {
|
|
233
|
+
if (outcome.skipped) {
|
|
234
|
+
return `format skipped for ${outcome.filePath}: ${outcome.reason ?? "unknown reason"}`;
|
|
235
|
+
}
|
|
236
|
+
const result = outcome.result;
|
|
237
|
+
if (result === undefined) {
|
|
238
|
+
return `format produced no result for ${outcome.filePath}`;
|
|
239
|
+
}
|
|
240
|
+
if (result.timedOut) {
|
|
241
|
+
return `format timed out for ${outcome.filePath}`;
|
|
242
|
+
}
|
|
243
|
+
if (result.exitCode !== 0) {
|
|
244
|
+
return `format failed for ${outcome.filePath} (exit ${result.exitCode})`;
|
|
245
|
+
}
|
|
246
|
+
return `format passed for ${outcome.filePath}`;
|
|
247
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-private project paths, harness-neutral by design.
|
|
3
|
+
*
|
|
4
|
+
* Harness-discovered directories (`.opencode/agents`, `.opencode/skills`,
|
|
5
|
+
* the DSH `.dsh/skills` mirror) live where each host looks and are NOT
|
|
6
|
+
* here. Everything below is read and written only by the framework
|
|
7
|
+
* itself, so it shares one neutral home (`.dev-framework/`) on every
|
|
8
|
+
* harness. The previous home (`.opencode/opencode-dev-framework/`) is
|
|
9
|
+
* kept as a read fallback so existing deployments converge without a
|
|
10
|
+
* migration: readers try the new location first, writers use it only.
|
|
11
|
+
*/
|
|
12
|
+
/** Neutral framework-private home (new deployments). */
|
|
13
|
+
export declare const FRAMEWORK_DIR = ".dev-framework";
|
|
14
|
+
/** Previous framework-private home (existing deployments; read fallback). */
|
|
15
|
+
export declare const LEGACY_FRAMEWORK_DIR = ".opencode/opencode-dev-framework";
|
|
16
|
+
export declare const REVIEW_FILE = "review.md";
|
|
17
|
+
export declare const PREFLIGHT_FILE = "preflight.md";
|
|
18
|
+
export declare const RULES_DIR = "rules";
|
|
19
|
+
export declare const RUNTIME_STATUS_FILE = "runtime-status.json";
|
|
20
|
+
/** Review artifact (new neutral home). */
|
|
21
|
+
export declare const REVIEW_ARTIFACT_REL = ".dev-framework/review.md";
|
|
22
|
+
/** Previous review artifact home (existing deployments; still enforced). */
|
|
23
|
+
export declare const LEGACY_REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
24
|
+
/** Pre-flight artifact (new neutral home). */
|
|
25
|
+
export declare const PREFLIGHT_ARTIFACT_REL = ".dev-framework/preflight.md";
|
|
26
|
+
/** Previous pre-flight artifact home (existing deployments; still read). */
|
|
27
|
+
export declare const LEGACY_PREFLIGHT_ARTIFACT_REL = ".opencode/opencode-dev-framework/preflight.md";
|
|
28
|
+
/** Review artifact, new location first. */
|
|
29
|
+
export declare const REVIEW_RELS: readonly [".dev-framework/review.md", ".opencode/opencode-dev-framework/review.md"];
|
|
30
|
+
/** Pre-flight artifact, new location first. */
|
|
31
|
+
export declare const PREFLIGHT_RELS: readonly [".dev-framework/preflight.md", ".opencode/opencode-dev-framework/preflight.md"];
|
|
32
|
+
/** Local rules directory, new location first. */
|
|
33
|
+
export declare const RULES_DIR_RELS: readonly [".dev-framework/rules", ".opencode/opencode-dev-framework/rules"];
|
|
34
|
+
/** Runtime snapshot, new location first. */
|
|
35
|
+
export declare const RUNTIME_STATUS_RELS: readonly [".dev-framework/runtime-status.json", ".opencode/opencode-dev-framework/runtime-status.json"];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-private project paths, harness-neutral by design.
|
|
3
|
+
*
|
|
4
|
+
* Harness-discovered directories (`.opencode/agents`, `.opencode/skills`,
|
|
5
|
+
* the DSH `.dsh/skills` mirror) live where each host looks and are NOT
|
|
6
|
+
* here. Everything below is read and written only by the framework
|
|
7
|
+
* itself, so it shares one neutral home (`.dev-framework/`) on every
|
|
8
|
+
* harness. The previous home (`.opencode/opencode-dev-framework/`) is
|
|
9
|
+
* kept as a read fallback so existing deployments converge without a
|
|
10
|
+
* migration: readers try the new location first, writers use it only.
|
|
11
|
+
*/
|
|
12
|
+
/** Neutral framework-private home (new deployments). */
|
|
13
|
+
export const FRAMEWORK_DIR = ".dev-framework";
|
|
14
|
+
/** Previous framework-private home (existing deployments; read fallback). */
|
|
15
|
+
export const LEGACY_FRAMEWORK_DIR = ".opencode/opencode-dev-framework";
|
|
16
|
+
export const REVIEW_FILE = "review.md";
|
|
17
|
+
export const PREFLIGHT_FILE = "preflight.md";
|
|
18
|
+
export const RULES_DIR = "rules";
|
|
19
|
+
export const RUNTIME_STATUS_FILE = "runtime-status.json";
|
|
20
|
+
/** Review artifact (new neutral home). */
|
|
21
|
+
export const REVIEW_ARTIFACT_REL = `${FRAMEWORK_DIR}/${REVIEW_FILE}`;
|
|
22
|
+
/** Previous review artifact home (existing deployments; still enforced). */
|
|
23
|
+
export const LEGACY_REVIEW_ARTIFACT_REL = `${LEGACY_FRAMEWORK_DIR}/${REVIEW_FILE}`;
|
|
24
|
+
/** Pre-flight artifact (new neutral home). */
|
|
25
|
+
export const PREFLIGHT_ARTIFACT_REL = `${FRAMEWORK_DIR}/${PREFLIGHT_FILE}`;
|
|
26
|
+
/** Previous pre-flight artifact home (existing deployments; still read). */
|
|
27
|
+
export const LEGACY_PREFLIGHT_ARTIFACT_REL = `${LEGACY_FRAMEWORK_DIR}/${PREFLIGHT_FILE}`;
|
|
28
|
+
/** Review artifact, new location first. */
|
|
29
|
+
export const REVIEW_RELS = [REVIEW_ARTIFACT_REL, LEGACY_REVIEW_ARTIFACT_REL];
|
|
30
|
+
/** Pre-flight artifact, new location first. */
|
|
31
|
+
export const PREFLIGHT_RELS = [PREFLIGHT_ARTIFACT_REL, LEGACY_PREFLIGHT_ARTIFACT_REL];
|
|
32
|
+
/** Local rules directory, new location first. */
|
|
33
|
+
export const RULES_DIR_RELS = [
|
|
34
|
+
`${FRAMEWORK_DIR}/${RULES_DIR}`,
|
|
35
|
+
`${LEGACY_FRAMEWORK_DIR}/${RULES_DIR}`,
|
|
36
|
+
];
|
|
37
|
+
/** Runtime snapshot, new location first. */
|
|
38
|
+
export const RUNTIME_STATUS_RELS = [
|
|
39
|
+
`${FRAMEWORK_DIR}/${RUNTIME_STATUS_FILE}`,
|
|
40
|
+
`${LEGACY_FRAMEWORK_DIR}/${RUNTIME_STATUS_FILE}`,
|
|
41
|
+
];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Guardrail logic: match tool calls against protected paths and dangerous
|
|
3
3
|
* shell commands. Pure functions — the OpenCode hook wiring lives in
|
|
4
|
-
* src/index.ts
|
|
4
|
+
* src/adapters/opencode/index.ts, the DSH wiring in src/adapters/dsh/.
|
|
5
5
|
*/
|
|
6
6
|
import type { OpenCodePermission } from "./registry.js";
|
|
7
7
|
import type { ResolvedConfig } from "./types.js";
|
|
@@ -33,7 +33,8 @@ export declare function extractCommand(args: unknown): string | undefined;
|
|
|
33
33
|
* herestrings (`<<<`) carry input, never a target, so they are ignored.
|
|
34
34
|
* Token-based and deliberately over-collecting within a command tail: that
|
|
35
35
|
* is harmless because callers only act on exact artifact matches, while a
|
|
36
|
-
* false negative would reopen a write path. Quote-aware
|
|
36
|
+
* false negative would reopen a write path. Quote-aware: quoted spans are
|
|
37
|
+
* operands, never operators.
|
|
37
38
|
*/
|
|
38
39
|
export declare function extractRedirectTargets(command: string): string[];
|
|
39
40
|
/**
|
|
@@ -45,6 +46,19 @@ export declare function extractRedirectTargets(command: string): string[];
|
|
|
45
46
|
export declare function matchProtectedPath(config: ResolvedConfig, filePath: string, directory?: string): string | undefined;
|
|
46
47
|
/** Check a shell command against the dangerous-command list. */
|
|
47
48
|
export declare function matchDangerousCommand(command: string): DangerousCommand | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Decide a file-path guard without touching tool args (plan 25 slice 4).
|
|
51
|
+
* Harness-agnostic seam: the OpenCode adapter reaches it via `checkToolCall`,
|
|
52
|
+
* the DSH adapter calls it directly with its own envelope extraction
|
|
53
|
+
* (`file_path`, `apply_patch` headers). Same verdicts, same reason text —
|
|
54
|
+
* one logic, two wirings.
|
|
55
|
+
*/
|
|
56
|
+
export declare function decideFileGuard(config: ResolvedConfig, filePath: string, directory?: string, hostPermissions?: OpenCodePermission, tool?: string): GuardResult;
|
|
57
|
+
/**
|
|
58
|
+
* Decide a shell-command guard without touching tool args (plan 25 slice 4).
|
|
59
|
+
* Same sharing contract as `decideFileGuard`.
|
|
60
|
+
*/
|
|
61
|
+
export declare function decideShellGuard(config: ResolvedConfig, command: string, hostPermissions?: OpenCodePermission, tool?: string): GuardResult;
|
|
48
62
|
/**
|
|
49
63
|
* Evaluate a tool call against the guardrail config.
|
|
50
64
|
*
|
|
@@ -54,8 +68,8 @@ export declare function matchDangerousCommand(command: string): DangerousCommand
|
|
|
54
68
|
*/
|
|
55
69
|
export declare function checkToolCall(config: ResolvedConfig, tool: string, args: unknown, directory?: string, hostPermissions?: OpenCodePermission): GuardResult;
|
|
56
70
|
/**
|
|
57
|
-
* Phase 25
|
|
58
|
-
* verdict. Maps the observed engine shapes (spike 25.1, OpenCode v2.0.26 —
|
|
71
|
+
* Phase 25 (permission spike, items 25.1/25.2): adapt a native
|
|
72
|
+
* `permission.evaluate` event to the guardrail verdict. Maps the observed engine shapes (spike 25.1, OpenCode v2.0.26 —
|
|
59
73
|
* recorded in docs/plans/08-notes.md, never guessed):
|
|
60
74
|
* - action `"edit"` (covers edit/write/patch tools) with `resources[0]` =
|
|
61
75
|
* the target file path (repo-relative).
|