opencode-dev-framework 1.9.4 → 1.10.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 +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} +138 -251
- 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/{logger.js → core/logger.js} +30 -1
- 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} +36 -15
- package/dist/{registry.js → core/registry.js} +66 -52
- package/dist/{review.js → core/review.js} +18 -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 +16 -6
- 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/peer-review/SKILL.md +6 -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/{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
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
import { readFile, stat } from "node:fs/promises";
|
|
20
20
|
import { isAbsolute, join, normalize, relative } from "node:path";
|
|
21
21
|
import { runGate, summarizeGate } from "./gate.js";
|
|
22
|
+
import { LEGACY_PREFLIGHT_ARTIFACT_REL, LEGACY_REVIEW_ARTIFACT_REL, PREFLIGHT_ARTIFACT_REL, REVIEW_ARTIFACT_REL, REVIEW_RELS, RUNTIME_STATUS_RELS, } from "./paths.js";
|
|
22
23
|
import { assessReviewContent, findUncoveredFiles, normalizeReviewPath, staleReviewMessage, templateReviewMessage, thinReviewMessage, } from "./review.js";
|
|
23
|
-
import
|
|
24
|
+
// Re-exported so existing import sites keep working: the paths module is
|
|
25
|
+
// the single owner, this module the historical home.
|
|
26
|
+
export { LEGACY_PREFLIGHT_ARTIFACT_REL, LEGACY_REVIEW_ARTIFACT_REL, PREFLIGHT_ARTIFACT_REL, REVIEW_ARTIFACT_REL, };
|
|
24
27
|
import { diffWeakening } from "./weakening.js";
|
|
25
|
-
/** Project-relative path of the peer-review artifact the agent must produce. */
|
|
26
|
-
export const REVIEW_ARTIFACT_REL = ".opencode/opencode-dev-framework/review.md";
|
|
27
28
|
/**
|
|
28
29
|
* True when a tool-call target is the review artifact. Normalizes like the
|
|
29
30
|
* guardrail path matcher (absolute paths resolve against the project
|
|
@@ -37,7 +38,8 @@ export function isReviewArtifact(filePath, directory) {
|
|
|
37
38
|
if (directory !== undefined && isAbsolute(filePath)) {
|
|
38
39
|
candidate = relative(directory, filePath);
|
|
39
40
|
}
|
|
40
|
-
return normalize(candidate) === normalize(REVIEW_ARTIFACT_REL)
|
|
41
|
+
return (normalize(candidate) === normalize(REVIEW_ARTIFACT_REL) ||
|
|
42
|
+
normalize(candidate) === normalize(LEGACY_REVIEW_ARTIFACT_REL));
|
|
41
43
|
}
|
|
42
44
|
/**
|
|
43
45
|
* Shared denial text for the child-session artifact guard (plan 23): one
|
|
@@ -49,8 +51,6 @@ export function childArtifactDenial() {
|
|
|
49
51
|
`to the top-level session — report back as text and let the orchestrator ` +
|
|
50
52
|
`write the artifact`);
|
|
51
53
|
}
|
|
52
|
-
/** Project-relative path of the pre-flight artifact the agent must produce. */
|
|
53
|
-
export const PREFLIGHT_ARTIFACT_REL = ".opencode/opencode-dev-framework/preflight.md";
|
|
54
54
|
/**
|
|
55
55
|
* Consecutive no-progress repeats before early stand-down (docs/plans/14-stuck-detection.md): the
|
|
56
56
|
* third identical blocked evaluation (two repeats) stands down. One
|
|
@@ -59,6 +59,21 @@ export const PREFLIGHT_ARTIFACT_REL = ".opencode/opencode-dev-framework/prefligh
|
|
|
59
59
|
* key: the profile stays the single enforcement axis.
|
|
60
60
|
*/
|
|
61
61
|
export const NO_PROGRESS_REPEATS = 2;
|
|
62
|
+
/**
|
|
63
|
+
* Inspect artifact files, new location first: present (non-trivial
|
|
64
|
+
* content), empty, or missing. The first non-missing candidate wins, so
|
|
65
|
+
* an agent mid-migration (both files present) answers from the new one.
|
|
66
|
+
* Never throws — unreadable files count as missing.
|
|
67
|
+
*/
|
|
68
|
+
export async function artifactStateFirst(directory, rels) {
|
|
69
|
+
for (const rel of rels) {
|
|
70
|
+
const state = await artifactState(directory, rel);
|
|
71
|
+
if (state !== "missing") {
|
|
72
|
+
return state;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return "missing";
|
|
76
|
+
}
|
|
62
77
|
/**
|
|
63
78
|
* Inspect an artifact file: present (non-trivial content), empty, or missing.
|
|
64
79
|
* Never throws — unreadable files count as missing.
|
|
@@ -72,6 +87,53 @@ export async function artifactState(directory, relPath) {
|
|
|
72
87
|
return "missing";
|
|
73
88
|
}
|
|
74
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Read the review artifact, new location first. Undefined when neither
|
|
92
|
+
* location is readable — callers report that path as `missing`, never
|
|
93
|
+
* `stale`. Writers always use the new location.
|
|
94
|
+
*/
|
|
95
|
+
async function readReviewSnapshot(directory) {
|
|
96
|
+
for (const rel of REVIEW_RELS) {
|
|
97
|
+
try {
|
|
98
|
+
return { content: await readFile(join(directory, rel), "utf8"), rel };
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// try the next (legacy) location
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
async function readReviewContent(directory) {
|
|
107
|
+
return (await readReviewSnapshot(directory))?.content;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A review must be written after the latest existing covered edit. Deleted
|
|
111
|
+
* files have no current mtime, so they retain the filename-coverage check.
|
|
112
|
+
* Unknown stat results fail stale rather than representing unproven ordering
|
|
113
|
+
* as fresh. Equal timestamps pass for coarse-resolution filesystems.
|
|
114
|
+
*/
|
|
115
|
+
async function reviewPredatesChanges(directory, reviewRel, changedFiles) {
|
|
116
|
+
let reviewMtimeMs;
|
|
117
|
+
try {
|
|
118
|
+
reviewMtimeMs = (await stat(join(directory, reviewRel))).mtimeMs;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
let latestChangeMs;
|
|
124
|
+
for (const file of changedFiles) {
|
|
125
|
+
try {
|
|
126
|
+
const changedMtimeMs = (await stat(join(directory, file))).mtimeMs;
|
|
127
|
+
latestChangeMs = Math.max(latestChangeMs ?? changedMtimeMs, changedMtimeMs);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (error?.code === "ENOENT")
|
|
131
|
+
continue;
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return latestChangeMs !== undefined && reviewMtimeMs < latestChangeMs;
|
|
136
|
+
}
|
|
75
137
|
/**
|
|
76
138
|
* Grade the peer-review artifact including substance (plan 17 §3) and
|
|
77
139
|
* freshness (plan 18): a substantive review of the wrong task reports
|
|
@@ -80,19 +142,19 @@ export async function artifactState(directory, relPath) {
|
|
|
80
142
|
* duty-escape on the record instead of passing a checkbox note.
|
|
81
143
|
*/
|
|
82
144
|
export async function readReviewState(directory, changedFiles = []) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
86
|
-
}
|
|
87
|
-
catch {
|
|
145
|
+
const review = await readReviewSnapshot(directory);
|
|
146
|
+
if (review === undefined) {
|
|
88
147
|
return "missing";
|
|
89
148
|
}
|
|
90
|
-
const substance = assessReviewContent(content);
|
|
149
|
+
const substance = assessReviewContent(review.content);
|
|
91
150
|
if (substance !== "present")
|
|
92
151
|
return substance;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
152
|
+
const covered = coverableChangedFiles(directory, changedFiles);
|
|
153
|
+
if (findUncoveredFiles(review.content, covered).length > 0)
|
|
154
|
+
return "stale";
|
|
155
|
+
if (covered.length === 0)
|
|
156
|
+
return "present";
|
|
157
|
+
return (await reviewPredatesChanges(directory, review.rel, covered)) ? "stale" : "present";
|
|
96
158
|
}
|
|
97
159
|
/**
|
|
98
160
|
* Files the freshness check covers: everything the session changed except
|
|
@@ -102,7 +164,11 @@ export async function readReviewState(directory, changedFiles = []) {
|
|
|
102
164
|
* continuation; surfaces via git where `.opencode/` is not ignored).
|
|
103
165
|
*/
|
|
104
166
|
export function coverableChangedFiles(directory, changedFiles) {
|
|
105
|
-
const owned = new Set([
|
|
167
|
+
const owned = new Set([
|
|
168
|
+
REVIEW_ARTIFACT_REL,
|
|
169
|
+
LEGACY_REVIEW_ARTIFACT_REL,
|
|
170
|
+
...RUNTIME_STATUS_RELS.map((rel) => rel),
|
|
171
|
+
]);
|
|
106
172
|
return changedFiles.map((f) => normalizeReviewPath(f, directory)).filter((f) => !owned.has(f));
|
|
107
173
|
}
|
|
108
174
|
/**
|
|
@@ -110,11 +176,8 @@ export function coverableChangedFiles(directory, changedFiles) {
|
|
|
110
176
|
* unreadable — that path already reports `missing`, never `stale`.
|
|
111
177
|
*/
|
|
112
178
|
export async function uncoveredReviewFiles(directory, changedFiles) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
content = await readFile(join(directory, REVIEW_ARTIFACT_REL), "utf8");
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
179
|
+
const content = await readReviewContent(directory);
|
|
180
|
+
if (content === undefined) {
|
|
118
181
|
return [];
|
|
119
182
|
}
|
|
120
183
|
return findUncoveredFiles(content, coverableChangedFiles(directory, changedFiles));
|
|
@@ -174,7 +237,7 @@ export function mergeChangedFiles(trackerFiles, gitFiles) {
|
|
|
174
237
|
* Blocking only applies to standard/strict; advisory callers should treat a
|
|
175
238
|
* non-null reason as a warning instead of a denial.
|
|
176
239
|
*/
|
|
177
|
-
export function preflightBlockReason(config, toolName, targetFile, artifact) {
|
|
240
|
+
export function preflightBlockReason(config, toolName, targetFile, artifact, directory) {
|
|
178
241
|
if (config.preflight.length === 0)
|
|
179
242
|
return null;
|
|
180
243
|
if (config.profile === "off")
|
|
@@ -184,8 +247,20 @@ export function preflightBlockReason(config, toolName, targetFile, artifact) {
|
|
|
184
247
|
const FILE_TOOLS = new Set(["edit", "write", "patch"]);
|
|
185
248
|
if (!FILE_TOOLS.has(toolName))
|
|
186
249
|
return null;
|
|
187
|
-
|
|
188
|
-
|
|
250
|
+
// The artifact is always writable so the agent can comply — by
|
|
251
|
+
// project-relative or absolute spelling (mirrors `isReviewArtifact`:
|
|
252
|
+
// compare where the path resolves, not how it is spelled).
|
|
253
|
+
if (targetFile !== undefined) {
|
|
254
|
+
let candidate = targetFile;
|
|
255
|
+
if (directory !== undefined && isAbsolute(targetFile)) {
|
|
256
|
+
candidate = relative(directory, targetFile);
|
|
257
|
+
}
|
|
258
|
+
// Either home keeps the artifact writable (old deployments comply
|
|
259
|
+
// through the legacy path until they converge on the new one).
|
|
260
|
+
if (normalize(candidate) === normalize(PREFLIGHT_ARTIFACT_REL) ||
|
|
261
|
+
normalize(candidate) === normalize(LEGACY_PREFLIGHT_ARTIFACT_REL)) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
189
264
|
}
|
|
190
265
|
const tasks = config.preflight.map((t, i) => `${i + 1}. ${t}`).join("\n");
|
|
191
266
|
return (`opencode-dev-framework pre-flight check is not complete. Before editing product code, ` +
|
|
@@ -244,15 +319,27 @@ async function passCacheKey(config, directory, changedFiles, reviewRequired) {
|
|
|
244
319
|
}
|
|
245
320
|
let review = "not-required";
|
|
246
321
|
if (reviewRequired) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
322
|
+
// Fingerprint BOTH candidate locations, including absence. Content
|
|
323
|
+
// selection is first-readable; tracking only the first stat-able path
|
|
324
|
+
// could fingerprint a directory while a legacy review supplied content,
|
|
325
|
+
// and tracking only the selected path would miss creation of a new-path
|
|
326
|
+
// artifact that takes precedence on the next evaluation.
|
|
327
|
+
const candidates = [];
|
|
328
|
+
for (const rel of REVIEW_RELS) {
|
|
329
|
+
try {
|
|
330
|
+
const s = await stat(join(directory, rel));
|
|
331
|
+
candidates.push(`${rel}:${s.mtimeMs}:${s.size}`);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
if (error?.code === "ENOENT") {
|
|
335
|
+
candidates.push(`${rel}:missing`);
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
// An unknown artifact state cannot support a cached proof.
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
255
341
|
}
|
|
342
|
+
review = candidates.join("\n");
|
|
256
343
|
}
|
|
257
344
|
return `${gateConfig}\n${parts.join("\n")}\nreview:${review}`;
|
|
258
345
|
}
|
|
@@ -14,6 +14,12 @@ export interface InitScaffoldOptions {
|
|
|
14
14
|
wizard?: boolean;
|
|
15
15
|
/** Rewrite files that differ from the templates (default: skip them). */
|
|
16
16
|
overwrite?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Mirror the bundled skills into this host-scanned skill root (e.g.
|
|
19
|
+
* ".dsh/skills") so the host `skill` tool catalogs them. Unset means
|
|
20
|
+
* no mirror (hosts that read `.opencode/skills` directly need none).
|
|
21
|
+
*/
|
|
22
|
+
skillMirrorRoot?: string;
|
|
17
23
|
}
|
|
18
24
|
export interface InitScaffold {
|
|
19
25
|
created: string[];
|
|
@@ -44,11 +50,22 @@ export declare function scaffoldReportLines(scaffold: InitScaffold, directory: s
|
|
|
44
50
|
* the counts cannot tell them apart, so the status says so instead of
|
|
45
51
|
* claiming everything is current.
|
|
46
52
|
*/
|
|
47
|
-
export declare function composeInitPrompt(scaffold: InitScaffold, directory: string, warnings?: string[]): string;
|
|
53
|
+
export declare function composeInitPrompt(scaffold: InitScaffold, directory: string, warnings?: string[], skillAccess?: "name" | "tool"): string;
|
|
48
54
|
export interface InitCommandDeps {
|
|
49
55
|
directory: string;
|
|
50
56
|
run: RunCommand;
|
|
51
57
|
delivery: unknown;
|
|
58
|
+
/**
|
|
59
|
+
* Mirror skills into this host-scanned root (setup only reaches the
|
|
60
|
+
* agent where the host looks). Unset: no mirror.
|
|
61
|
+
*/
|
|
62
|
+
skillMirrorRoot?: string;
|
|
63
|
+
/**
|
|
64
|
+
* How the brief names skill loading: `"tool"` loads via a host `skill`
|
|
65
|
+
* tool with user questions via `ask_user_question`; `"name"` (default)
|
|
66
|
+
* follows the skill by registered name through conversation.
|
|
67
|
+
*/
|
|
68
|
+
skillAccess?: "name" | "tool";
|
|
52
69
|
/** Throws when the owning setup/state went stale mid-scaffold. */
|
|
53
70
|
checkAlive: () => void;
|
|
54
71
|
/** Reload the project config after scaffolding; throws on invalid config. */
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* (TTY), while everything here is non-interactive by construction.
|
|
11
11
|
*/
|
|
12
12
|
import { detectProject } from "./detect.js";
|
|
13
|
-
import { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, trialRunDetectedCommands, writeDetectedConfig, } from "./installer.js";
|
|
13
|
+
import { buildWizardBrief, formatBriefSkipped, formatTrialRun, formatWizardBrief, installTemplates, mirrorSkillsToDsh, trialRunDetectedCommands, writeDetectedConfig, } from "./installer.js";
|
|
14
14
|
/**
|
|
15
15
|
* Whether the scaffold result needs an agent handoff (a turn). Fresh
|
|
16
16
|
* scaffolds do (the agent must resolve the brief); re-runs with warnings
|
|
@@ -27,6 +27,16 @@ export async function runInitScaffold(directory, run, options = {}) {
|
|
|
27
27
|
const io = { overwriteExisting: overwrite, skipExisting: !overwrite };
|
|
28
28
|
const result = await installTemplates(directory, io);
|
|
29
29
|
const configResult = await writeDetectedConfig(directory, io);
|
|
30
|
+
if (options.skillMirrorRoot !== undefined) {
|
|
31
|
+
// Setup intent: the framework only "kicks in" if the agent can load
|
|
32
|
+
// the shipped skills through the host `skill` tool. Roots the host
|
|
33
|
+
// never scans (e.g. `.opencode/skills` on DSH) get mirrored where
|
|
34
|
+
// discovery looks — same skip/overwrite contract as the templates.
|
|
35
|
+
const mirror = await mirrorSkillsToDsh(directory, options.skillMirrorRoot, io);
|
|
36
|
+
result.created.push(...mirror.created);
|
|
37
|
+
result.skipped.push(...mirror.skipped);
|
|
38
|
+
result.overwritten.push(...mirror.overwritten);
|
|
39
|
+
}
|
|
30
40
|
const fresh = result.created.length > 0 ||
|
|
31
41
|
result.overwritten.length > 0 ||
|
|
32
42
|
configResult.action === "created" ||
|
|
@@ -86,6 +96,8 @@ export function scaffoldReportLines(scaffold, directory) {
|
|
|
86
96
|
...(!scaffold.fresh
|
|
87
97
|
? ["", "Already configured: nothing changed, so no brief was rebuilt."]
|
|
88
98
|
: []),
|
|
99
|
+
"",
|
|
100
|
+
"If the setup drifts later, run dev_framework_update to check.",
|
|
89
101
|
];
|
|
90
102
|
}
|
|
91
103
|
/**
|
|
@@ -96,7 +108,7 @@ export function scaffoldReportLines(scaffold, directory) {
|
|
|
96
108
|
* the counts cannot tell them apart, so the status says so instead of
|
|
97
109
|
* claiming everything is current.
|
|
98
110
|
*/
|
|
99
|
-
export function composeInitPrompt(scaffold, directory, warnings = []) {
|
|
111
|
+
export function composeInitPrompt(scaffold, directory, warnings = [], skillAccess = "name") {
|
|
100
112
|
const warningLines = warnings.length > 0 ? [...warnings.map((w) => `Warning: ${w}`), ""] : [];
|
|
101
113
|
if (!scaffold.fresh) {
|
|
102
114
|
return [
|
|
@@ -111,10 +123,20 @@ export function composeInitPrompt(scaffold, directory, warnings = []) {
|
|
|
111
123
|
...scaffoldReportLines(scaffold, directory),
|
|
112
124
|
...warningLines,
|
|
113
125
|
"",
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
...(skillAccess === "tool"
|
|
127
|
+
? [
|
|
128
|
+
"Set up opencode-dev-framework for this project from the report and brief above. " +
|
|
129
|
+
"Load the project-config skill with the `skill` tool and follow it to resolve the open questions — " +
|
|
130
|
+
"ask at most 3 genuinely user-only questions with `ask_user_question`, resolve the rest yourself " +
|
|
131
|
+
"by reading the repo and running the commands — " +
|
|
132
|
+
"then present .dev-framework.yml + .dev-framework/hardening.md for review. Do not commit unreviewed.",
|
|
133
|
+
]
|
|
134
|
+
: [
|
|
135
|
+
"Set up opencode-dev-framework for this project from the report and brief above. " +
|
|
136
|
+
"Follow the project-config skill to resolve the open questions — ask at most 3 genuinely " +
|
|
137
|
+
"user-only questions, resolve the rest yourself by reading the repo and running the commands — " +
|
|
138
|
+
"then present .dev-framework.yml + .dev-framework/hardening.md for review. Do not commit unreviewed.",
|
|
139
|
+
]),
|
|
118
140
|
].join("\n");
|
|
119
141
|
}
|
|
120
142
|
/**
|
|
@@ -132,7 +154,10 @@ export function composeInitPrompt(scaffold, directory, warnings = []) {
|
|
|
132
154
|
* handoff was delivered.
|
|
133
155
|
*/
|
|
134
156
|
export async function runInitCommand(deps) {
|
|
135
|
-
const scaffold = await runInitScaffold(deps.directory, deps.run, {
|
|
157
|
+
const scaffold = await runInitScaffold(deps.directory, deps.run, {
|
|
158
|
+
wizard: true,
|
|
159
|
+
skillMirrorRoot: deps.skillMirrorRoot,
|
|
160
|
+
});
|
|
136
161
|
deps.checkAlive();
|
|
137
162
|
const warnings = [];
|
|
138
163
|
try {
|
|
@@ -149,7 +174,7 @@ export async function runInitCommand(deps) {
|
|
|
149
174
|
if (!initNeedsHandoff(scaffold, warnings)) {
|
|
150
175
|
return false;
|
|
151
176
|
}
|
|
152
|
-
const text = composeInitPrompt(scaffold, deps.directory, warnings);
|
|
177
|
+
const text = composeInitPrompt(scaffold, deps.directory, warnings, deps.skillAccess ?? "name");
|
|
153
178
|
try {
|
|
154
179
|
await deps.deliver(text, deps.delivery);
|
|
155
180
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type RunCommand } from "./host.js";
|
|
2
|
+
/**
|
|
3
|
+
* One-command DSH profile wiring (`df install-dsh`). Writes a managed block
|
|
4
|
+
* into the profile's `cordis.patch.yml` — never rewrites user content:
|
|
5
|
+
* everything outside the markers is preserved byte-for-byte, so user
|
|
6
|
+
* comments and foreign entries survive every run.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ODF_ENTRY_ID = "odf-gates";
|
|
9
|
+
/** Default entry name (npm-first): resolves once the package ships `./dsh`. */
|
|
10
|
+
export declare const ODF_NPM_SPEC = "opencode-dev-framework/dsh";
|
|
11
|
+
export declare const ODF_MANAGED_BEGIN = "# BEGIN odf-gates (managed by `df install-dsh` \u2014 do not hand-edit)";
|
|
12
|
+
export declare const ODF_MANAGED_END = "# END odf-gates";
|
|
13
|
+
/** Seams every profile provides. `agentPresets` joins only where detected. */
|
|
14
|
+
export declare const ODF_BASE_SEAMS: string[];
|
|
15
|
+
export interface InstallDshOptions {
|
|
16
|
+
profile: string;
|
|
17
|
+
dshHome?: string;
|
|
18
|
+
/** Local adapter build (absolute path). Mutually exclusive with packageSpec. */
|
|
19
|
+
distFile?: string;
|
|
20
|
+
/** Package specifier. Defaults to {@link ODF_NPM_SPEC} (npm-first). */
|
|
21
|
+
packageSpec?: string;
|
|
22
|
+
/** Preset seam: auto-detect (default), force on, or force off. */
|
|
23
|
+
withPresets?: "auto" | true | false;
|
|
24
|
+
/** Replace a hand-maintained (unmarked) odf-gates entry. */
|
|
25
|
+
force?: boolean;
|
|
26
|
+
dryRun?: boolean;
|
|
27
|
+
dshBin?: string;
|
|
28
|
+
run?: RunCommand;
|
|
29
|
+
}
|
|
30
|
+
export interface InstallDshResult {
|
|
31
|
+
profileDir: string;
|
|
32
|
+
patchFile: string;
|
|
33
|
+
createdPatchFile: boolean;
|
|
34
|
+
changed: boolean;
|
|
35
|
+
entryName: string;
|
|
36
|
+
seams: string[];
|
|
37
|
+
presetIncluded: boolean;
|
|
38
|
+
packageSupportsDsh: boolean | undefined;
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
export declare function resolveDshHome(explicit?: string): string;
|
|
42
|
+
/** Probe one composed dump for preset-registry presence AND an
|
|
43
|
+
* already-resolving `odf-gates` entry (bundle-provided base). A single
|
|
44
|
+
* read-only subprocess call answers both; any failure degrades to
|
|
45
|
+
* "absent / unsupported". */
|
|
46
|
+
export declare function probeComposition(run: RunCommand, dshBin: string, profile: string): Promise<{
|
|
47
|
+
dump: string;
|
|
48
|
+
presetsSupported: boolean;
|
|
49
|
+
bundleEntry: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
/** Probe the composed tree for the agent-preset registry. False on any failure. */
|
|
52
|
+
export declare function detectPresetSupport(run: RunCommand, dshBin: string, profile: string): Promise<boolean>;
|
|
53
|
+
/** Whether the profile's installed package already ships `./dsh`. Unknown on any failure. */
|
|
54
|
+
export declare function checkPackageSupportsDsh(profileDir: string): Promise<boolean | undefined>;
|
|
55
|
+
export declare function buildManagedBlock(entryName: string, seams: string[]): string;
|
|
56
|
+
/** True when the text already carries our managed block (idempotent reruns). */
|
|
57
|
+
export declare function hasManagedBlock(patchText: string): boolean;
|
|
58
|
+
/** True when an odf-gates entry exists OUTSIDE the managed block. */
|
|
59
|
+
export declare function hasHandMaintainedEntry(patchText: string): boolean;
|
|
60
|
+
export declare function upsertManagedBlock(patchText: string | null, block: string): string;
|
|
61
|
+
/**
|
|
62
|
+
* Remove unmarked odf-gates entries (force mode): a header line naming the
|
|
63
|
+
* id plus its more-indented continuation lines. Foreign entries and comments
|
|
64
|
+
* are untouched — only lines that DECLARE the id match.
|
|
65
|
+
*/
|
|
66
|
+
export declare function removeUnmarkedEntries(patchText: string): string;
|
|
67
|
+
export declare function installDshProfile(options: InstallDshOptions): Promise<InstallDshResult>;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { runCommand as defaultRunCommand } from "./host.js";
|
|
5
|
+
/**
|
|
6
|
+
* One-command DSH profile wiring (`df install-dsh`). Writes a managed block
|
|
7
|
+
* into the profile's `cordis.patch.yml` — never rewrites user content:
|
|
8
|
+
* everything outside the markers is preserved byte-for-byte, so user
|
|
9
|
+
* comments and foreign entries survive every run.
|
|
10
|
+
*/
|
|
11
|
+
export const ODF_ENTRY_ID = "odf-gates";
|
|
12
|
+
/** Default entry name (npm-first): resolves once the package ships `./dsh`. */
|
|
13
|
+
export const ODF_NPM_SPEC = "opencode-dev-framework/dsh";
|
|
14
|
+
export const ODF_MANAGED_BEGIN = "# BEGIN odf-gates (managed by `df install-dsh` — do not hand-edit)";
|
|
15
|
+
export const ODF_MANAGED_END = "# END odf-gates";
|
|
16
|
+
/** Seams every profile provides. `agentPresets` joins only where detected. */
|
|
17
|
+
export const ODF_BASE_SEAMS = ["tools", "goals", "approval", "subagents"];
|
|
18
|
+
export function resolveDshHome(explicit) {
|
|
19
|
+
const fromEnv = process.env["DSH_HOME"];
|
|
20
|
+
return (explicit ?? (typeof fromEnv === "string" && fromEnv !== "" ? fromEnv : join(homedir(), ".dsh")));
|
|
21
|
+
}
|
|
22
|
+
/** Probe one composed dump for preset-registry presence AND an
|
|
23
|
+
* already-resolving `odf-gates` entry (bundle-provided base). A single
|
|
24
|
+
* read-only subprocess call answers both; any failure degrades to
|
|
25
|
+
* "absent / unsupported". */
|
|
26
|
+
export async function probeComposition(run, dshBin, profile) {
|
|
27
|
+
const empty = { dump: "", presetsSupported: false, bundleEntry: false };
|
|
28
|
+
try {
|
|
29
|
+
const probe = await run([dshBin, "--profile", profile, "--dump-config"], {});
|
|
30
|
+
const dump = `${probe.stdout}\n${probe.stderr}`;
|
|
31
|
+
return {
|
|
32
|
+
dump,
|
|
33
|
+
presetsSupported: /agent-preset-registry|agent-presets/i.test(dump),
|
|
34
|
+
bundleEntry: /(^|\n)\s*-\s*id:\s*odf-gates\b/.test(dump),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return empty;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Probe the composed tree for the agent-preset registry. False on any failure. */
|
|
42
|
+
export async function detectPresetSupport(run, dshBin, profile) {
|
|
43
|
+
return (await probeComposition(run, dshBin, profile)).presetsSupported;
|
|
44
|
+
}
|
|
45
|
+
/** Whether the profile's installed package already ships `./dsh`. Unknown on any failure. */
|
|
46
|
+
export async function checkPackageSupportsDsh(profileDir) {
|
|
47
|
+
try {
|
|
48
|
+
const manifestRaw = await readFile(join(profileDir, "package.json"), "utf8");
|
|
49
|
+
const manifest = JSON.parse(manifestRaw);
|
|
50
|
+
const version = manifest.dependencies?.["opencode-dev-framework"] ??
|
|
51
|
+
manifest.devDependencies?.["opencode-dev-framework"];
|
|
52
|
+
if (version === undefined) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const installedRaw = await readFile(join(profileDir, "node_modules", "opencode-dev-framework", "package.json"), "utf8");
|
|
56
|
+
const installed = JSON.parse(installedRaw);
|
|
57
|
+
return (typeof installed.exports === "object" &&
|
|
58
|
+
installed.exports !== null &&
|
|
59
|
+
"./dsh" in installed.exports);
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function buildManagedBlock(entryName, seams) {
|
|
66
|
+
const lines = [
|
|
67
|
+
ODF_MANAGED_BEGIN,
|
|
68
|
+
"- insert:",
|
|
69
|
+
` - id: ${ODF_ENTRY_ID}`,
|
|
70
|
+
` name: ${entryName}`,
|
|
71
|
+
`- id: ${ODF_ENTRY_ID}`,
|
|
72
|
+
" inject:",
|
|
73
|
+
...seams.map((seam) => ` - ${seam}`),
|
|
74
|
+
ODF_MANAGED_END,
|
|
75
|
+
];
|
|
76
|
+
return `${lines.join("\n")}\n`;
|
|
77
|
+
}
|
|
78
|
+
/** True when the text already carries our managed block (idempotent reruns). */
|
|
79
|
+
export function hasManagedBlock(patchText) {
|
|
80
|
+
return patchText.includes(ODF_MANAGED_BEGIN);
|
|
81
|
+
}
|
|
82
|
+
/** True when an odf-gates entry exists OUTSIDE the managed block. */
|
|
83
|
+
export function hasHandMaintainedEntry(patchText) {
|
|
84
|
+
const withoutManaged = patchText.replace(new RegExp(`${escapeRegExp(ODF_MANAGED_BEGIN)}[\\s\\S]*?${escapeRegExp(ODF_MANAGED_END)}\n?`, "g"), "");
|
|
85
|
+
return new RegExp(`(^|\\n)\\s*(-\\s+id:\\s+${ODF_ENTRY_ID}\\b|id:\\s+${ODF_ENTRY_ID}\\b)`).test(withoutManaged);
|
|
86
|
+
}
|
|
87
|
+
export function upsertManagedBlock(patchText, block) {
|
|
88
|
+
const previous = patchText ?? "";
|
|
89
|
+
const stripped = previous.replace(new RegExp(`${escapeRegExp(ODF_MANAGED_BEGIN)}[\\s\\S]*?${escapeRegExp(ODF_MANAGED_END)}\n?`, "g"), "");
|
|
90
|
+
const trimmed = stripped.replace(/\s+$/, "");
|
|
91
|
+
return trimmed === "" ? block : `${trimmed}\n\n${block}`;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Remove unmarked odf-gates entries (force mode): a header line naming the
|
|
95
|
+
* id plus its more-indented continuation lines. Foreign entries and comments
|
|
96
|
+
* are untouched — only lines that DECLARE the id match.
|
|
97
|
+
*/
|
|
98
|
+
export function removeUnmarkedEntries(patchText) {
|
|
99
|
+
const lines = patchText.split("\n");
|
|
100
|
+
const kept = [];
|
|
101
|
+
let skippingIndent = null;
|
|
102
|
+
for (const line of lines) {
|
|
103
|
+
if (skippingIndent !== null) {
|
|
104
|
+
const indent = line.match(/^\s*/)?.[0].length ?? 0;
|
|
105
|
+
if (line.trim() === "" || indent > skippingIndent) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
skippingIndent = null;
|
|
109
|
+
}
|
|
110
|
+
const header = line.match(/^(\s*)(?:-\s+id|id):\s+odf-gates\b/);
|
|
111
|
+
if (header !== null) {
|
|
112
|
+
skippingIndent = header[1].length;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
kept.push(line);
|
|
116
|
+
}
|
|
117
|
+
return kept.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
118
|
+
}
|
|
119
|
+
function escapeRegExp(text) {
|
|
120
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
121
|
+
}
|
|
122
|
+
async function fileExists(path) {
|
|
123
|
+
try {
|
|
124
|
+
await stat(path);
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export async function installDshProfile(options) {
|
|
132
|
+
const { profile, distFile, packageSpec = ODF_NPM_SPEC, withPresets = "auto", force = false, dryRun = false, dshBin = "dsh", run = defaultRunCommand, } = options;
|
|
133
|
+
if (distFile !== undefined && options.packageSpec !== undefined) {
|
|
134
|
+
throw new Error("df install-dsh: --dist and --package are mutually exclusive");
|
|
135
|
+
}
|
|
136
|
+
const profileDir = join(resolveDshHome(options.dshHome), "profiles", profile);
|
|
137
|
+
if (!(await fileExists(profileDir))) {
|
|
138
|
+
throw new Error(`df install-dsh: profile directory not found: ${profileDir} (create it with \`dsh plugin --profile ${profile} ...\` first)`);
|
|
139
|
+
}
|
|
140
|
+
const entryName = distFile ?? packageSpec;
|
|
141
|
+
const warnings = [];
|
|
142
|
+
const explicitEntry = distFile !== undefined;
|
|
143
|
+
const patchFile = join(profileDir, "cordis.patch.yml");
|
|
144
|
+
const existing = (await fileExists(patchFile)) ? await readFile(patchFile, "utf8") : null;
|
|
145
|
+
const handMaintained = !force && existing !== null && hasHandMaintainedEntry(existing);
|
|
146
|
+
if (handMaintained) {
|
|
147
|
+
throw new Error("df install-dsh: a hand-maintained odf-gates entry already exists in cordis.patch.yml (refusing to touch it; rerun with --force to replace it with the managed block)");
|
|
148
|
+
}
|
|
149
|
+
// One read-only probe answers preset support AND whether the bundle
|
|
150
|
+
// layer already provides the entry (post-release world).
|
|
151
|
+
const probe = await probeComposition(run, dshBin, profile);
|
|
152
|
+
const bundleMode = !explicitEntry && existing !== null && !hasManagedBlock(existing) && probe.bundleEntry;
|
|
153
|
+
if (bundleMode) {
|
|
154
|
+
// The bundle base already resolves: only the profile-dependent
|
|
155
|
+
// preset seam can still need a user-layer override.
|
|
156
|
+
let presetIncluded;
|
|
157
|
+
if (withPresets === false) {
|
|
158
|
+
presetIncluded = false;
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
presetIncluded = probe.presetsSupported;
|
|
162
|
+
}
|
|
163
|
+
if (!presetIncluded) {
|
|
164
|
+
return {
|
|
165
|
+
profileDir,
|
|
166
|
+
patchFile,
|
|
167
|
+
createdPatchFile: false,
|
|
168
|
+
changed: false,
|
|
169
|
+
entryName,
|
|
170
|
+
seams: [...ODF_BASE_SEAMS],
|
|
171
|
+
presetIncluded,
|
|
172
|
+
packageSupportsDsh: undefined,
|
|
173
|
+
warnings: ["bundle base entry already resolves; no user-layer override needed."],
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const seams = [...ODF_BASE_SEAMS, "agentPresets"];
|
|
177
|
+
const next = upsertManagedBlock(existing, buildManagedBlock(entryName, seams));
|
|
178
|
+
const changed = next !== existing;
|
|
179
|
+
if (!dryRun && changed) {
|
|
180
|
+
await writeFile(patchFile, next, "utf8");
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
profileDir,
|
|
184
|
+
patchFile,
|
|
185
|
+
createdPatchFile: false,
|
|
186
|
+
changed: changed && !dryRun,
|
|
187
|
+
entryName,
|
|
188
|
+
seams,
|
|
189
|
+
presetIncluded,
|
|
190
|
+
packageSupportsDsh: undefined,
|
|
191
|
+
warnings: ["preset seam added as a user-layer override of the bundle base."],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
let presetIncluded;
|
|
195
|
+
if (withPresets === true) {
|
|
196
|
+
presetIncluded = true;
|
|
197
|
+
}
|
|
198
|
+
else if (withPresets === false) {
|
|
199
|
+
presetIncluded = false;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
presetIncluded = probe.presetsSupported;
|
|
203
|
+
if (!presetIncluded) {
|
|
204
|
+
warnings.push("agent-preset registry not detected in this profile: spawning without the read-only preset (prompt-level restriction + guards).");
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
const seams = presetIncluded ? [...ODF_BASE_SEAMS, "agentPresets"] : [...ODF_BASE_SEAMS];
|
|
208
|
+
const packageSupportsDsh = entryName === packageSpec ? await checkPackageSupportsDsh(profileDir) : undefined;
|
|
209
|
+
if (packageSupportsDsh === false) {
|
|
210
|
+
warnings.push(`installed opencode-dev-framework predates DSH support (no ./dsh export): run \`dsh plugin --profile ${profile} add opencode-dev-framework@latest\` after release, or reinstall with --dist.`);
|
|
211
|
+
}
|
|
212
|
+
else if (packageSupportsDsh === undefined && entryName === packageSpec) {
|
|
213
|
+
warnings.push(`could not confirm opencode-dev-framework is installed in this profile: run \`dsh plugin --profile ${profile} add opencode-dev-framework\` if the entry fails to resolve.`);
|
|
214
|
+
}
|
|
215
|
+
const base = force && existing !== null ? removeUnmarkedEntries(existing) : (existing ?? "");
|
|
216
|
+
const next = upsertManagedBlock(base === "" ? null : base, buildManagedBlock(entryName, seams));
|
|
217
|
+
const changed = next !== (existing ?? "");
|
|
218
|
+
if (!dryRun && changed) {
|
|
219
|
+
if (existing === null) {
|
|
220
|
+
await mkdir(profileDir, { recursive: true });
|
|
221
|
+
}
|
|
222
|
+
await writeFile(patchFile, next, "utf8");
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
profileDir,
|
|
226
|
+
patchFile,
|
|
227
|
+
createdPatchFile: existing === null && !dryRun,
|
|
228
|
+
changed: changed && !dryRun,
|
|
229
|
+
entryName,
|
|
230
|
+
seams,
|
|
231
|
+
presetIncluded,
|
|
232
|
+
packageSupportsDsh,
|
|
233
|
+
warnings,
|
|
234
|
+
};
|
|
235
|
+
}
|