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.
Files changed (70) hide show
  1. package/README.md +137 -33
  2. package/bin/df +94 -4
  3. package/cordis.patch.yml +17 -0
  4. package/dist/adapters/dsh/extract.d.ts +47 -0
  5. package/dist/adapters/dsh/extract.js +62 -0
  6. package/dist/adapters/dsh/index.d.ts +332 -0
  7. package/dist/adapters/dsh/index.js +1643 -0
  8. package/dist/adapters/opencode/index.d.ts +30 -0
  9. package/dist/{index.js → adapters/opencode/index.js} +120 -235
  10. package/dist/{block-store.d.ts → core/block-store.d.ts} +10 -3
  11. package/dist/{commands.js → core/commands.js} +4 -2
  12. package/dist/{config.d.ts → core/config.d.ts} +16 -4
  13. package/dist/{config.js → core/config.js} +102 -10
  14. package/dist/{format-status.d.ts → core/format-status.d.ts} +13 -2
  15. package/dist/{format-status.js → core/format-status.js} +30 -7
  16. package/dist/{gate.d.ts → core/gate.d.ts} +9 -1
  17. package/dist/{gate.js → core/gate.js} +14 -2
  18. package/dist/{goal.d.ts → core/goal.d.ts} +4 -3
  19. package/dist/{goal.js → core/goal.js} +4 -3
  20. package/dist/{harness.d.ts → core/harness.d.ts} +10 -5
  21. package/dist/{harness.js → core/harness.js} +119 -32
  22. package/dist/{init.d.ts → core/init.d.ts} +18 -1
  23. package/dist/{init.js → core/init.js} +33 -8
  24. package/dist/core/install-dsh.d.ts +67 -0
  25. package/dist/core/install-dsh.js +235 -0
  26. package/dist/{installer.d.ts → core/installer.d.ts} +32 -2
  27. package/dist/{installer.js → core/installer.js} +129 -12
  28. package/dist/{lint.d.ts → core/lint.d.ts} +43 -2
  29. package/dist/{lint.js → core/lint.js} +89 -2
  30. package/dist/core/paths.d.ts +35 -0
  31. package/dist/core/paths.js +41 -0
  32. package/dist/{protect.d.ts → core/protect.d.ts} +18 -4
  33. package/dist/{protect.js → core/protect.js} +85 -34
  34. package/dist/{registry.d.ts → core/registry.d.ts} +9 -1
  35. package/dist/{review.js → core/review.js} +14 -6
  36. package/dist/{rules.d.ts → core/rules.d.ts} +3 -2
  37. package/dist/{rules.js → core/rules.js} +21 -5
  38. package/dist/core/run-hooks.d.ts +138 -0
  39. package/dist/core/run-hooks.js +196 -0
  40. package/dist/{runtime-status.d.ts → core/runtime-status.d.ts} +5 -4
  41. package/dist/{runtime-status.js → core/runtime-status.js} +29 -17
  42. package/dist/{types.d.ts → core/types.d.ts} +17 -0
  43. package/dist/{update.d.ts → core/update.d.ts} +12 -4
  44. package/dist/{update.js → core/update.js} +28 -12
  45. package/dist/{weakening.js → core/weakening.js} +2 -1
  46. package/package.json +23 -8
  47. package/rules/40-delegation.md +13 -2
  48. package/templates/.opencode/agents/style-enforcer.md +1 -1
  49. package/templates/.opencode/agents/test-grounder.md +1 -1
  50. package/templates/.opencode/skills/ground-in-tests/SKILL.md +1 -1
  51. package/templates/.opencode/skills/project-config/SKILL.md +2 -2
  52. package/tui.tsx +6 -6
  53. package/dist/index.d.ts +0 -101
  54. /package/dist/{block-store.js → core/block-store.js} +0 -0
  55. /package/dist/{command-utils.d.ts → core/command-utils.d.ts} +0 -0
  56. /package/dist/{command-utils.js → core/command-utils.js} +0 -0
  57. /package/dist/{commands.d.ts → core/commands.d.ts} +0 -0
  58. /package/dist/{detect.d.ts → core/detect.d.ts} +0 -0
  59. /package/dist/{detect.js → core/detect.js} +0 -0
  60. /package/dist/{host.d.ts → core/host.d.ts} +0 -0
  61. /package/dist/{host.js → core/host.js} +0 -0
  62. /package/dist/{logger.d.ts → core/logger.d.ts} +0 -0
  63. /package/dist/{logger.js → core/logger.js} +0 -0
  64. /package/dist/{registry.js → core/registry.js} +0 -0
  65. /package/dist/{review.d.ts → core/review.d.ts} +0 -0
  66. /package/dist/{roster.d.ts → core/roster.d.ts} +0 -0
  67. /package/dist/{roster.js → core/roster.js} +0 -0
  68. /package/dist/{types.js → core/types.js} +0 -0
  69. /package/dist/{weakening.d.ts → core/weakening.d.ts} +0 -0
  70. /package/templates/{.opencode/opencode-dev-framework → .dev-framework}/rules/.gitkeep +0 -0
@@ -0,0 +1,332 @@
1
+ /**
2
+ * DSH adapter (plan 25 slice 4, packaged promotion of the slice-3 dogfood).
3
+ *
4
+ * One logic, two wirings: every verdict, reason string, and gate evaluation
5
+ * comes from core (`decideFileGuard`/`decideShellGuard`, `formatFile`/
6
+ * `lintFile`, `runCompletion`/`actOnVerdict`). This module is only wiring:
7
+ * Cordis event registration, `ctx.subprocess` transport, `ctx.logger`
8
+ * logging, and `dsh-commands` slash registration.
9
+ *
10
+ * Seams touched: `commands` (slash registration at load) and `subprocess`
11
+ * (lint/format/gate execution). Events (`ctx.on`) and `ctx.logger` are
12
+ * ambient on the verified DSH build (`0.2.2-rc.3`) and need no declaration —
13
+ * re-probe `inject` if a future host tightens seams.
14
+ *
15
+ * Directory: `ODF_WORKDIR` env override, else `process.cwd()`. No throw on
16
+ * unset env (safe default); the resolved directory is the config source and
17
+ * the `cwd` for every subprocess.
18
+ */
19
+ import { type LintOutcome } from "../../core/lint.js";
20
+ import type { Profile } from "../../core/types.js";
21
+ import { type DshExec, type DshSessionHeader } from "./extract.js";
22
+ export declare const name = "opencode-dev-framework-dsh";
23
+ /** Seams this adapter touches: slash registration + subprocess transport. */
24
+ export declare const inject: readonly ["commands", "subprocess"];
25
+ export interface DshCollectedStream {
26
+ readFrom(offset: number): {
27
+ text: string;
28
+ };
29
+ }
30
+ export interface DshSubprocessHandle {
31
+ readonly done: Promise<{
32
+ exitCode: number | null;
33
+ signal: NodeJS.Signals | null;
34
+ }>;
35
+ readonly collected: {
36
+ readonly stdout?: DshCollectedStream;
37
+ readonly stderr?: DshCollectedStream;
38
+ };
39
+ }
40
+ export interface DshSubprocess {
41
+ spawn(spec: {
42
+ argv: string[];
43
+ cwd?: string;
44
+ stdio: {
45
+ stdin: "ignore";
46
+ stdout: {
47
+ maxBytes: number;
48
+ spill: {
49
+ maxBytes: number;
50
+ };
51
+ };
52
+ stderr: {
53
+ maxBytes: number;
54
+ spill: {
55
+ maxBytes: number;
56
+ };
57
+ };
58
+ };
59
+ graceMs: number;
60
+ signal?: AbortSignal;
61
+ }): DshSubprocessHandle;
62
+ }
63
+ export interface DshLogger {
64
+ info(message: string, extra?: Record<string, unknown>): void;
65
+ warn(message: string, extra?: Record<string, unknown>): void;
66
+ error(message: string, extra?: Record<string, unknown>): void;
67
+ debug(message: string, extra?: Record<string, unknown>): void;
68
+ }
69
+ export interface DshUserMessage {
70
+ role: "user";
71
+ content: Array<{
72
+ type: "text";
73
+ text: string;
74
+ }>;
75
+ source: {
76
+ kind: string;
77
+ };
78
+ /**
79
+ * Host session-event id. The host commits these messages as
80
+ * user/message session events and its resume validator requires a
81
+ * non-empty `data.id` on every message event — an id-less message
82
+ * poisons the log for the next resume. Always stamped by
83
+ * `dshUserMessage()`; optional here so hand-built messages still
84
+ * compile, but never omit it on the wire.
85
+ */
86
+ id?: string;
87
+ }
88
+ export interface DshAgent {
89
+ readonly id?: unknown;
90
+ readonly session?: {
91
+ readonly header?: DshSessionHeader & {
92
+ readonly id?: unknown;
93
+ };
94
+ };
95
+ steer?(message: DshUserMessage): void;
96
+ followup?(message: DshUserMessage): void;
97
+ }
98
+ /** Structured error identity for denials, mirroring the host `ToolErrorInfo`. */
99
+ export interface DshToolErrorInfo {
100
+ name: string;
101
+ code: string;
102
+ reason?: string;
103
+ }
104
+ export type DshPreDecision = {
105
+ kind: "allow";
106
+ } | {
107
+ kind: "deny";
108
+ reason: string;
109
+ info?: DshToolErrorInfo;
110
+ } | {
111
+ kind: "cancel";
112
+ } | {
113
+ kind: "ask";
114
+ reason?: string;
115
+ };
116
+ export type DshPostDecision = {
117
+ kind: "accept";
118
+ additionalContexts?: DshUserMessage[];
119
+ } | {
120
+ kind: "block";
121
+ feedback: Array<{
122
+ type: "text";
123
+ text: string;
124
+ }>;
125
+ info?: DshToolErrorInfo;
126
+ additionalContexts?: DshUserMessage[];
127
+ };
128
+ /** `agent/pre-step` decision: reject the step or let edited messages enter. */
129
+ export type DshPreStepDecision = {
130
+ kind: "reject";
131
+ } | {
132
+ kind: "enter";
133
+ messages: DshUserMessage[];
134
+ };
135
+ /** Minimal structural face of the host agent-preset registry (plan 26). */
136
+ export interface DshAgentPresets {
137
+ register(definition: {
138
+ id: string;
139
+ name?: string;
140
+ description?: string;
141
+ plugins: Array<{
142
+ id?: string;
143
+ name: string;
144
+ config?: unknown;
145
+ }>;
146
+ }): Promise<unknown>;
147
+ }
148
+ /** Minimal structural face of the host subagent service (plan 26). */
149
+ export interface DshSubagents {
150
+ getProvider(name: string): {
151
+ name: string;
152
+ } | undefined;
153
+ resolveMaxDepth(value: unknown): unknown;
154
+ startActivation(request: {
155
+ provider: string;
156
+ label: string;
157
+ name?: string;
158
+ prompt: Array<{
159
+ type: "text";
160
+ text: string;
161
+ }>;
162
+ parent: unknown;
163
+ agentPreset?: string;
164
+ maxDepth?: unknown;
165
+ signal?: AbortSignal;
166
+ delivery: "parent";
167
+ }): Promise<{
168
+ name: string;
169
+ }>;
170
+ }
171
+ /** What a DSH command handler receives: the invoking agent, raw input, abort. */
172
+ export interface DshCommandInvocation {
173
+ readonly agent: DshAgent;
174
+ readonly rawInput: string;
175
+ readonly signal?: AbortSignal;
176
+ }
177
+ /** What a DSH command handler returns: text rendered by the dispatching UI. */
178
+ export type DshCommandResult = {
179
+ kind: "success";
180
+ text?: string;
181
+ } | {
182
+ kind: "error";
183
+ text: string;
184
+ };
185
+ /** Host goal service (`ctx.goals`), used only by `df-goal`. */
186
+ export interface DshGoals {
187
+ create(agent: DshAgent, request: {
188
+ objective: string;
189
+ }): unknown;
190
+ }
191
+ export interface DshCommands {
192
+ register(def: {
193
+ name: string;
194
+ description: string;
195
+ input?: {
196
+ hint?: string;
197
+ };
198
+ handler: (invocation: DshCommandInvocation) => DshCommandResult | Promise<DshCommandResult>;
199
+ }): void;
200
+ /** Optional: present on hosts that expose the command list (used to probe for native `/goal`). */
201
+ list?: (agent: DshAgent) => ReadonlyArray<{
202
+ name: string;
203
+ }> | Promise<ReadonlyArray<{
204
+ name: string;
205
+ }>>;
206
+ }
207
+ export interface DshToolResult {
208
+ readonly isError: boolean;
209
+ }
210
+ /** Host tool service (`ctx.tools`), used only for agent-invokable tools. */
211
+ export interface DshTools {
212
+ register(definition: DshToolDefinition): void;
213
+ }
214
+ /**
215
+ * Minimal tool definition twin: the plain-object shape the host's
216
+ * `ctx.tools.register` consumes. Deliberately NOT imported from the
217
+ * host's `@deepseek-ai/dsh-tools` package — that package is workspace
218
+ * internal (not published), and this plugin keeps zero runtime
219
+ * dependencies. The shape mirrors `defineTool` output: JSON-Schema
220
+ * parameters, a canonical string value schema with a text renderer,
221
+ * and an async execute returning the canonical value.
222
+ */
223
+ export interface DshToolDefinition {
224
+ readonly name: string;
225
+ readonly description: string;
226
+ readonly parameters: Record<string, unknown>;
227
+ readonly output: {
228
+ readonly schema: Record<string, unknown>;
229
+ render: (args: unknown, value: unknown) => Array<{
230
+ type: "text";
231
+ text: string;
232
+ }>;
233
+ };
234
+ readonly isConcurrencySafe?: (args: unknown) => boolean;
235
+ execute: (args: unknown, exec: unknown) => Promise<unknown>;
236
+ }
237
+ /** Structural plugin context: only the seams the adapter touches. */
238
+ export interface DshContext {
239
+ readonly subprocess: DshSubprocess;
240
+ readonly logger: DshLogger;
241
+ readonly commands: DshCommands;
242
+ readonly tools?: DshTools;
243
+ readonly goals?: DshGoals;
244
+ /**
245
+ * Subagent service for specialist dispatch (plan 26). Optional like
246
+ * `tools`/`goals`: the host throws on reading a non-injected service,
247
+ * so every read is guarded and absence degrades to inline review.
248
+ */
249
+ readonly subagents?: DshSubagents;
250
+ /**
251
+ * Agent-preset registry for the read-only reviewer preset (plan 26.3).
252
+ * Same guarded-read contract: absence degrades to spawning without a
253
+ * preset (prompt-level restriction + per-exec guards).
254
+ */
255
+ readonly agentPresets?: DshAgentPresets;
256
+ /**
257
+ * User-approval seam. Optional like `tools`/`goals`: the host throws on
258
+ * reading a non-injected service, so every read is guarded and absence
259
+ * degrades to allow+log. Declared structurally (no host import).
260
+ */
261
+ readonly approval?: unknown;
262
+ /**
263
+ * Session-history query service for the continuity probe (plan 27).
264
+ * Optional like the other services; resolved via `get` where present
265
+ * so no bundle inject change is needed, with guarded property read
266
+ * as the fallback. Absence degrades to unknown continuity.
267
+ */
268
+ readonly sessionQuery?: unknown;
269
+ /**
270
+ * Optional service lookup on the sandbox facade: never throws for
271
+ * absent services (unlike undeclared property reads), so probing an
272
+ * unmounted service degrades silently instead of reporting failure.
273
+ */
274
+ readonly get?: (name: string) => unknown;
275
+ on(event: "tools/pre-execute", listener: (exec: DshExec, next: () => Promise<DshPreDecision>) => Promise<DshPreDecision>): void;
276
+ on(event: "tools/post-execute", listener: (exec: DshExec, result: DshToolResult, next: () => Promise<DshPostDecision>) => Promise<DshPostDecision>): void;
277
+ on(event: "agent/turn-stopping", listener: (payload: {
278
+ agent: DshAgent;
279
+ turn: unknown;
280
+ signal?: AbortSignal;
281
+ }) => Promise<void> | void): void;
282
+ on(event: "agent/pre-step", listener: (payload: {
283
+ agent: DshAgent;
284
+ messages: DshUserMessage[];
285
+ turn: unknown;
286
+ step?: unknown;
287
+ signal?: AbortSignal;
288
+ }, next: () => Promise<DshPreStepDecision>) => Promise<DshPreStepDecision>): void;
289
+ }
290
+ /** Resolve the project directory: explicit env override, else process cwd. */
291
+ export declare function resolveDshDirectory(env?: NodeJS.ProcessEnv): string;
292
+ /**
293
+ * What a guard *evaluation failure* (not a verdict — an exception) does.
294
+ * Profile-dependent like every other enforcement decision: advisory and
295
+ * off report and allow; standard/strict fail closed (unknown =
296
+ * untrusted). Pure for testability. (`off` never reaches evaluation —
297
+ * the kill switch returns first — but mapping it to allow keeps the
298
+ * helper safe under any future call ordering.)
299
+ */
300
+ export declare function guardErrorDecision(profile: Profile): "allow" | "deny";
301
+ /**
302
+ * Model-fault lint failures for a post-execute `block` decision.
303
+ * A finding blames the edit, so the model sees it as a failed tool call
304
+ * and fixes it in the same turn — stronger than the OpenCode
305
+ * `execute.after`, which can only log after the edit lands. A finding
306
+ * means: nonzero exit, no timeout, not the 127 command-not-found
307
+ * convention, and the linter actually printed something. Everything else
308
+ * (timeouts, spawn failures, missing binaries, silent crashes and silent
309
+ * nonzero exits) is infra the model cannot fix by editing: accept +
310
+ * error-log, file still tracked, gate re-checks. Pure for testability.
311
+ */
312
+ export declare function lintBlockLines(outcomes: LintOutcome[]): string[];
313
+ /**
314
+ * Child-session predicate for the review-duty guard. DSH-native shape:
315
+ * the host attaches the session header to the agent, so parentage is a
316
+ * synchronous header read — no session lookup, no cache, no walk (all of
317
+ * that is OpenCode's problem, where the event carries no parentage).
318
+ * The rule mirrors the host's own classification: `parentSession` names
319
+ * the direct creator, but historical ordinary forks may retain it, so a
320
+ * child is `origin === "subagent"` *with* a creator id (cf. the host's
321
+ * `archive-admission` walk condition). An absent agent or header reads
322
+ * as top-level — the pre-existing behavior, never a new block.
323
+ */
324
+ export declare function isChildAgent(agent: DshAgent | DshExec["agent"] | undefined): boolean;
325
+ /**
326
+ * Register the ODF gates on a DSH Cordis context. Synchronous like every
327
+ * DSH plugin `apply`. A project without (or with a broken) config gets no
328
+ * hooks at all — error-logged, never throwing: failing the whole host
329
+ * mount for one project's missing yml would brick unrelated sessions
330
+ * (mirror of the OpenCode adapter's setup behavior).
331
+ */
332
+ export declare function apply(ctx: DshContext): void;