@xth26/dsh-plan-build-mode 0.4.0 → 0.5.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 +255 -146
- package/README.zh.md +237 -143
- package/cordis.patch.yml +13 -1
- package/lib/helpers.d.ts +21 -5
- package/lib/helpers.d.ts.map +1 -1
- package/lib/helpers.js +38 -6
- package/lib/helpers.js.map +1 -1
- package/lib/index.d.ts +14 -17
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +186 -33
- package/lib/index.js.map +1 -1
- package/lib/invariant.d.ts +4 -4
- package/lib/invariant.d.ts.map +1 -1
- package/lib/invariant.js +31 -8
- package/lib/invariant.js.map +1 -1
- package/lib/permissions.d.ts +164 -0
- package/lib/permissions.d.ts.map +1 -0
- package/lib/permissions.js +351 -0
- package/lib/permissions.js.map +1 -0
- package/lib/types.d.ts +44 -1
- package/lib/types.d.ts.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,42 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Host half of `dsh-plan-build-mode`.
|
|
3
3
|
*
|
|
4
|
-
* Implements an OpenCode-style Plan / Build mode
|
|
5
|
-
* DSH's built-in `/plan` soft-guidance mode:
|
|
4
|
+
* Implements an OpenCode-style Plan / Build mode with a tool permission gate:
|
|
6
5
|
*
|
|
7
6
|
* - `/plan-build` -> Toggle between Plan and Build modes
|
|
8
7
|
* - `/plan-build status` -> Show the current mode
|
|
9
|
-
* - `/plan-build switch plan` -> Plan mode
|
|
10
|
-
* - `/plan-build switch build` -> Build mode
|
|
11
|
-
* -
|
|
8
|
+
* - `/plan-build switch plan` -> Plan mode (read-only by policy)
|
|
9
|
+
* - `/plan-build switch build` -> Build mode (writable)
|
|
10
|
+
* - `/permission status|allow|deny` -> Inspect / adjust the permission gate
|
|
11
|
+
* - Denies write-category tools while in Plan mode (OpenCode `edit` permission)
|
|
12
|
+
* - Permits reads outside the workspace (DSH reads pass through every mode);
|
|
13
|
+
* external writes stay gated by the sandbox unless `external_directory` is
|
|
14
|
+
* configured to `ask`
|
|
12
15
|
* - Injects a `plan-build:policy` system prompt section
|
|
13
16
|
*
|
|
17
|
+
* Mode state lives in the plugin-owned `plan-build/mode` session event; the
|
|
18
|
+
* `sandbox/mode` event is still written for sandbox enforcement whenever the
|
|
19
|
+
* target sandbox actually differs.
|
|
20
|
+
*
|
|
14
21
|
* @module dsh-plan-build-mode
|
|
15
22
|
*/
|
|
16
23
|
import z from '@deepseek-ai/schemastery';
|
|
17
|
-
import { DEFAULT_BUILD_SANDBOX, DEFAULT_PLAN_SANDBOX, isPlanModeActive,
|
|
24
|
+
import { currentPlanBuildMode, currentSandboxMode, DEFAULT_BUILD_SANDBOX, DEFAULT_PLAN_SANDBOX, isPlanModeActive, setPlanBuildMode, } from "./helpers.js";
|
|
25
|
+
import { approvalDenyReason, canonicalize, categoryDenyReason, categoryOf, DEFAULT_ACTIONS, DEFAULT_EXTERNAL_DEFAULT, DEFAULT_PERMISSION, DEFAULT_PLAN_OVERRIDES, extractCommand, extractTargets, externalDenyReason, externalWriteEscalationReason, gateDecision, matchSubjectsFor, noApprovalChannelReason, planWriteDenyReason, resolveCategory, resolveTarget, sandboxAllowsWrite, } from "./permissions.js";
|
|
18
26
|
/** Cordis plugin name. */
|
|
19
27
|
export const name = 'dsh-plan-build-mode';
|
|
20
28
|
/**
|
|
21
29
|
* Service dependencies for the host half. `commands` is injected optionally at
|
|
22
30
|
* runtime via ctx.inject(['commands'], ...) so headless assemblies stay
|
|
23
|
-
* unaffected;
|
|
31
|
+
* unaffected; `approval` is read optionally via ctx.get('approval').
|
|
24
32
|
*/
|
|
25
33
|
export const inject = ['tools', 'systemPrompt'];
|
|
34
|
+
const PERMISSION_ACTIONS = z.union([z.const('allow'), z.const('ask'), z.const('deny')]);
|
|
35
|
+
const PERMISSION_VALUE = z.union([PERMISSION_ACTIONS, z.dict(PERMISSION_ACTIONS)]);
|
|
36
|
+
const CATEGORY_MAP = z.dict(PERMISSION_VALUE);
|
|
37
|
+
const SANDBOX = z.union([z.const('read-only'), z.const('workspace-write'), z.const('danger-full-access')]);
|
|
26
38
|
/** Configuration schema. */
|
|
27
39
|
export const Config = z.object({
|
|
28
|
-
planSandbox:
|
|
29
|
-
|
|
30
|
-
z.const('workspace-write'),
|
|
31
|
-
z.const('danger-full-access'),
|
|
32
|
-
]).required(false),
|
|
33
|
-
buildSandbox: z.union([
|
|
34
|
-
z.const('read-only'),
|
|
35
|
-
z.const('workspace-write'),
|
|
36
|
-
z.const('danger-full-access'),
|
|
37
|
-
]).required(false),
|
|
40
|
+
planSandbox: SANDBOX.required(false),
|
|
41
|
+
buildSandbox: SANDBOX.required(false),
|
|
38
42
|
denyWriteTools: z.boolean().default(true),
|
|
39
43
|
section: z.boolean().default(true),
|
|
44
|
+
plansDirectory: z.string().default('.opencode/plans'),
|
|
45
|
+
permission: CATEGORY_MAP.required(false),
|
|
46
|
+
externalDirectory: z.object({
|
|
47
|
+
default: PERMISSION_ACTIONS.required(false),
|
|
48
|
+
rules: z.array(z.object({ pattern: z.string(), action: PERMISSION_ACTIONS })).required(false),
|
|
49
|
+
}).required(false),
|
|
50
|
+
modes: z.object({
|
|
51
|
+
plan: CATEGORY_MAP.required(false),
|
|
52
|
+
build: CATEGORY_MAP.required(false),
|
|
53
|
+
}).required(false),
|
|
40
54
|
});
|
|
41
55
|
/**
|
|
42
56
|
* Plugin entry point.
|
|
@@ -46,16 +60,23 @@ export const Config = z.object({
|
|
|
46
60
|
export function apply(ctx, config = {}) {
|
|
47
61
|
const planSandbox = config.planSandbox ?? DEFAULT_PLAN_SANDBOX;
|
|
48
62
|
const buildSandbox = config.buildSandbox ?? DEFAULT_BUILD_SANDBOX;
|
|
49
|
-
if (planSandbox === buildSandbox) {
|
|
50
|
-
throw new Error(`planSandbox and buildSandbox must be different, but both are '${planSandbox}'.`);
|
|
51
|
-
}
|
|
52
63
|
const denyWriteTools = config.denyWriteTools !== false;
|
|
53
64
|
const enableSection = config.section !== false;
|
|
65
|
+
const plansDirectory = config.plansDirectory ?? '.opencode/plans';
|
|
66
|
+
// Session-scoped external-path allowlist (OpenCode "always", in-memory).
|
|
67
|
+
const allowlist = new Map();
|
|
68
|
+
const executionConfig = {
|
|
69
|
+
planSandbox,
|
|
70
|
+
buildSandbox,
|
|
71
|
+
denyWriteTools,
|
|
72
|
+
plansDirectory,
|
|
73
|
+
permission: config.permission,
|
|
74
|
+
externalDirectory: config.externalDirectory,
|
|
75
|
+
modes: config.modes,
|
|
76
|
+
};
|
|
54
77
|
ctx.effect(() => {
|
|
55
78
|
const disposers = [];
|
|
56
79
|
// Inject a system prompt section describing the current mode.
|
|
57
|
-
// AssembleContext carries `agent?: Agent` (merged by @deepseek-ai/dsh-agent)
|
|
58
|
-
// since the scope-based system-prompt rewrite; it is absent on diagnostics.
|
|
59
80
|
if (enableSection) {
|
|
60
81
|
disposers.push(ctx.systemPrompt.section({
|
|
61
82
|
name: 'plan-build:policy',
|
|
@@ -65,22 +86,47 @@ export function apply(ctx, config = {}) {
|
|
|
65
86
|
if (agent === undefined)
|
|
66
87
|
return '';
|
|
67
88
|
return isPlanModeActive(agent.session, planSandbox)
|
|
68
|
-
? 'You are in OpenCode Plan Mode. You are READ-ONLY. You may read files, search code, browse directories, ask questions, and inspect data or run quick read-only sanity checks. You are encouraged to write short command-line Python snippets (for example, python -B -c "...") to read data files, compute statistics, sample records, or run fast tests that do not modify the filesystem or write caches. Avoid commands that install packages, write files, generate build artifacts, or change the system. If a verification requires writing files, leave it for Build Mode. Present a complete plan and use /plan-build (or /plan-build switch build) to enter Build Mode before implementing.'
|
|
69
|
-
: 'You are in OpenCode Build Mode. You may edit files, run commands, and execute the approved plan. Make minimal changes, run tests/verification after changes, and ask for confirmation before destructive git operations or system-wide changes. Run /plan-build (or /plan-build switch plan) to return to Plan Mode when you need to re-plan.';
|
|
89
|
+
? 'You are in OpenCode Plan Mode. You are READ-ONLY: you may not modify files except under the configured plans directory. You may read files anywhere (including outside the workspace), search code, browse directories, ask questions, and inspect data or run quick read-only sanity checks. You are encouraged to write short command-line Python snippets (for example, python -B -c "...") to read data files, compute statistics, sample records, or run fast tests that do not modify the filesystem or write caches. Avoid commands that install packages, write files, generate build artifacts, or change the system. If a verification requires writing files, leave it for Build Mode. Present a complete plan and use /plan-build (or /plan-build switch build) to enter Build Mode before implementing. In Plan Mode you may write plan files only under the configured plans directory.'
|
|
90
|
+
: 'You are in OpenCode Build Mode. You may edit files, run commands, and execute the approved plan. Make minimal changes, run tests/verification after changes, and ask for confirmation before destructive git operations or system-wide changes. Run /plan-build (or /plan-build switch plan) to return to Plan Mode when you need to re-plan. Reading files outside the session workspace is allowed; writing outside the workspace requires sandbox escalation (retry with sandbox_permissions + justification).';
|
|
70
91
|
},
|
|
71
92
|
}));
|
|
72
93
|
}
|
|
73
|
-
//
|
|
94
|
+
// The tool permission gate (OpenCode `permission` + `external_directory`).
|
|
74
95
|
disposers.push(ctx.on('tools/pre-execute', async (exec, next) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (reason !== undefined)
|
|
79
|
-
return { kind: 'deny', reason };
|
|
96
|
+
const decision = await evaluateExecution(exec, executionConfig, allowlist, ctx);
|
|
97
|
+
if (decision.kind === 'deny')
|
|
98
|
+
return { kind: 'deny', reason: decision.reason };
|
|
80
99
|
return next();
|
|
81
100
|
}));
|
|
82
|
-
//
|
|
83
|
-
//
|
|
101
|
+
// Pin a deterministic mode event on new sessions (and legacy-loaded ones)
|
|
102
|
+
// so mode state does not depend on sandbox inference forever.
|
|
103
|
+
const pinMode = (session) => {
|
|
104
|
+
if (currentPlanBuildMode(session, planSandbox) !== undefined)
|
|
105
|
+
return;
|
|
106
|
+
const sandbox = currentSandboxMode(session);
|
|
107
|
+
let inferred;
|
|
108
|
+
if (sandbox === undefined) {
|
|
109
|
+
inferred = 'build';
|
|
110
|
+
}
|
|
111
|
+
else if (planSandbox !== buildSandbox) {
|
|
112
|
+
inferred = sandbox === planSandbox ? 'plan' : 'build';
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
inferred = sandbox === 'read-only' ? 'plan' : 'build';
|
|
116
|
+
}
|
|
117
|
+
session.append('plan-build/mode', { mode: inferred });
|
|
118
|
+
};
|
|
119
|
+
disposers.push(ctx.on('session/created', pinMode));
|
|
120
|
+
const sessions = ctx.sessions;
|
|
121
|
+
if (sessions !== undefined) {
|
|
122
|
+
for (const session of sessions.list())
|
|
123
|
+
pinMode(session);
|
|
124
|
+
}
|
|
125
|
+
// Drop session-scoped allowlist entries when their session is disposed.
|
|
126
|
+
disposers.push(ctx.on('session/disposed', (session) => {
|
|
127
|
+
allowlist.delete(session.id);
|
|
128
|
+
}));
|
|
129
|
+
// User-facing slash commands: mode toggle + permission gate control.
|
|
84
130
|
ctx.inject(['commands'], (commandCtx) => {
|
|
85
131
|
disposers.push(commandCtx.commands.register({
|
|
86
132
|
name: 'plan-build',
|
|
@@ -101,7 +147,7 @@ export function apply(ctx, config = {}) {
|
|
|
101
147
|
return {
|
|
102
148
|
kind: 'success',
|
|
103
149
|
text: active
|
|
104
|
-
? 'Plan mode is active (read-only). Run /plan-build to enter Build mode, or /plan-build switch build.'
|
|
150
|
+
? 'Plan mode is active (read-only by policy). Run /plan-build to enter Build mode, or /plan-build switch build.'
|
|
105
151
|
: 'Build mode is active. Run /plan-build to enter Plan mode, or /plan-build switch plan.',
|
|
106
152
|
};
|
|
107
153
|
}
|
|
@@ -126,6 +172,43 @@ export function apply(ctx, config = {}) {
|
|
|
126
172
|
return { kind: 'success', text: `Switched to ${target} mode.` };
|
|
127
173
|
},
|
|
128
174
|
}));
|
|
175
|
+
disposers.push(commandCtx.commands.register({
|
|
176
|
+
name: 'permission',
|
|
177
|
+
description: 'Inspect or adjust the OpenCode-style permission gate (external-path allowlist)',
|
|
178
|
+
input: { hint: '[status | allow <pattern> | deny <pattern>]' },
|
|
179
|
+
handler: ({ agent, rawInput }) => {
|
|
180
|
+
const arg = rawInput.trim();
|
|
181
|
+
const sessionId = agent.session.id;
|
|
182
|
+
const entries = allowlist.get(sessionId) ?? [];
|
|
183
|
+
if (arg === '' || arg === 'status') {
|
|
184
|
+
const rules = (config.externalDirectory?.rules ?? []).map((r) => `${r.pattern}=${r.action}`).join(', ');
|
|
185
|
+
return {
|
|
186
|
+
kind: 'success',
|
|
187
|
+
text: [
|
|
188
|
+
'Permission gate status:',
|
|
189
|
+
`- external_directory default: ${config.externalDirectory?.default ?? DEFAULT_EXTERNAL_DEFAULT}`,
|
|
190
|
+
`- external_directory rules: ${rules || '(none)'}`,
|
|
191
|
+
`- session allowlist: ${entries.join(', ') || '(empty)'}`,
|
|
192
|
+
].join('\n'),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const parts = arg.split(/\s+/);
|
|
196
|
+
const verb = parts[0] ?? '';
|
|
197
|
+
const pattern = parts.slice(1).join(' ');
|
|
198
|
+
if (verb === 'allow' && pattern !== '') {
|
|
199
|
+
if (!entries.includes(pattern)) {
|
|
200
|
+
entries.push(pattern);
|
|
201
|
+
allowlist.set(sessionId, entries);
|
|
202
|
+
}
|
|
203
|
+
return { kind: 'success', text: `Allowed external path pattern for this session: ${pattern}` };
|
|
204
|
+
}
|
|
205
|
+
if (verb === 'deny' && pattern !== '') {
|
|
206
|
+
allowlist.set(sessionId, entries.filter((p) => p !== pattern));
|
|
207
|
+
return { kind: 'success', text: `Removed external path pattern from this session's allowlist: ${pattern}` };
|
|
208
|
+
}
|
|
209
|
+
return { kind: 'error', text: 'Usage: /permission status, /permission allow <pattern>, or /permission deny <pattern>.' };
|
|
210
|
+
},
|
|
211
|
+
}));
|
|
129
212
|
});
|
|
130
213
|
return () => {
|
|
131
214
|
for (const dispose of disposers)
|
|
@@ -133,4 +216,74 @@ export function apply(ctx, config = {}) {
|
|
|
133
216
|
};
|
|
134
217
|
});
|
|
135
218
|
}
|
|
219
|
+
/** The plugin's view of the effective category policy for a mode. */
|
|
220
|
+
function categorySpecFor(config, mode, category) {
|
|
221
|
+
const globalValue = config.permission?.[category] ?? DEFAULT_PERMISSION[category];
|
|
222
|
+
const modeValue = mode === 'plan'
|
|
223
|
+
? (config.modes?.plan?.[category] ?? (category === 'edit' && !config.denyWriteTools ? 'allow' : DEFAULT_PLAN_OVERRIDES[category]))
|
|
224
|
+
: config.modes?.build?.[category];
|
|
225
|
+
return resolveCategory(modeValue ?? globalValue, DEFAULT_ACTIONS[category]);
|
|
226
|
+
}
|
|
227
|
+
/** Evaluate one tool call through the permission gate; pure decision + approval. */
|
|
228
|
+
async function evaluateExecution(exec, config, allowlist, ctx) {
|
|
229
|
+
if (exec.agent === undefined)
|
|
230
|
+
return { kind: 'allow' };
|
|
231
|
+
const session = exec.agent.session;
|
|
232
|
+
const mode = currentPlanBuildMode(session, config.planSandbox) ?? 'build';
|
|
233
|
+
const workspaceRoot = canonicalize(session.header.cwd ?? process.cwd());
|
|
234
|
+
const plansDir = canonicalize(resolveTarget(config.plansDirectory, workspaceRoot));
|
|
235
|
+
const category = categoryOf(exec.name);
|
|
236
|
+
const targets = extractTargets(exec.name, exec.arguments).map((t) => canonicalize(resolveTarget(t, workspaceRoot)));
|
|
237
|
+
const command = extractCommand(exec.name, exec.arguments);
|
|
238
|
+
const matchSubjects = matchSubjectsFor(exec.name, targets, workspaceRoot, command);
|
|
239
|
+
const effectiveSandbox = currentSandboxMode(session);
|
|
240
|
+
const decision = gateDecision({
|
|
241
|
+
mode,
|
|
242
|
+
category,
|
|
243
|
+
targets,
|
|
244
|
+
matchSubjects,
|
|
245
|
+
workspaceRoot,
|
|
246
|
+
plansDir,
|
|
247
|
+
allowlist: allowlist.get(session.id) ?? [],
|
|
248
|
+
externalDefault: config.externalDirectory?.default ?? DEFAULT_EXTERNAL_DEFAULT,
|
|
249
|
+
externalRules: config.externalDirectory?.rules,
|
|
250
|
+
categorySpec: category === undefined ? { action: 'allow' } : categorySpecFor(config, mode, category),
|
|
251
|
+
sandboxAllowsWrite: (target) => sandboxAllowsWrite(effectiveSandbox, target, workspaceRoot),
|
|
252
|
+
});
|
|
253
|
+
if (decision.kind === 'allow')
|
|
254
|
+
return { kind: 'allow' };
|
|
255
|
+
if (decision.kind === 'deny')
|
|
256
|
+
return { kind: 'deny', reason: denialReason(exec.name, mode, category, decision) };
|
|
257
|
+
// ask → approval channel (fail closed on any resolution problem).
|
|
258
|
+
const approval = ctx.get?.('approval');
|
|
259
|
+
if (approval === undefined)
|
|
260
|
+
return { kind: 'deny', reason: noApprovalChannelReason(exec.name) };
|
|
261
|
+
let outcome;
|
|
262
|
+
try {
|
|
263
|
+
outcome = await approval.request({
|
|
264
|
+
agent: exec.agent,
|
|
265
|
+
toolName: exec.name,
|
|
266
|
+
callId: exec.callId,
|
|
267
|
+
reason: `permission gate: ${exec.name} requires approval under the configured permission`,
|
|
268
|
+
signal: exec.signal,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
return { kind: 'deny', reason: `Tool '${exec.name}' requires approval, but the approval request failed closed.` };
|
|
273
|
+
}
|
|
274
|
+
if (outcome !== 'allowed-once')
|
|
275
|
+
return { kind: 'deny', reason: approvalDenyReason(exec.name, outcome) };
|
|
276
|
+
return { kind: 'allow' };
|
|
277
|
+
}
|
|
278
|
+
/** Map a gate decision onto a model-facing reason string. */
|
|
279
|
+
function denialReason(toolName, mode, category, decision) {
|
|
280
|
+
if (decision.code === 'plan-write' || (mode === 'plan' && category === 'edit' && decision.code === 'category-deny')) {
|
|
281
|
+
return planWriteDenyReason(toolName);
|
|
282
|
+
}
|
|
283
|
+
if (decision.code === 'external-deny')
|
|
284
|
+
return externalDenyReason(toolName, decision.target ?? '');
|
|
285
|
+
if (decision.code === 'external-write-escalation')
|
|
286
|
+
return externalWriteEscalationReason(toolName, decision.target ?? '');
|
|
287
|
+
return categoryDenyReason(toolName, decision.subject);
|
|
288
|
+
}
|
|
136
289
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHAN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AE7C,IAAI,QAAQ,CAAC,IAAI,KAAK,YAAY,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,QAAQ,KAAK,MAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAe,CAAC,EAAE,CAAC;QACpH,OAAO,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IACtC,CAAC;IACD,IAAI,QAAQ,CAAC,IAAI,KAAK,eAAe;QAAE,OAAO,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IACjG,IAAI,QAAQ,CAAC,IAAI,KAAK,2BAA2B;QAAE,OAAO,6BAA6B,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,IAAI,EAAE,CAAC,CAAA;IACxH,OAAO,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAA;AACvD,CAAC"}
|
package/lib/invariant.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Package-owned invariant companion for `dsh-plan-build-mode`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The plugin stores its Plan/Build mode in its own `plan-build/mode` session
|
|
5
|
+
* event, so the companion validates that event's payload before it reaches
|
|
6
|
+
* the durable log. The `sandbox/mode` event it also writes is validated by
|
|
7
|
+
* `@deepseek-ai/dsh-sandbox-policy`.
|
|
8
8
|
*
|
|
9
9
|
* @module dsh-plan-build-mode/invariant
|
|
10
10
|
*/
|
package/lib/invariant.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,kCAAkC,CAAA;AACnD,2EAA2E;AAC3E,eAAO,MAAM,MAAM,yBAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAGlD,oCAAoC;AACpC,eAAO,MAAM,IAAI,kCAAkC,CAAA;AACnD,2EAA2E;AAC3E,eAAO,MAAM,MAAM,yBAA0B,CAAA;AA8B7C;;;;GAIG;AACH,eAAO,MAAM,KAAK,GAAI,KAAK,OAAO,GAAG;IAAE,UAAU,EAAE,OAAO,CAAA;CAAE,KAAG,OAAO,CAAC,MAAM,IAAI,CAM9E,CAAA"}
|
package/lib/invariant.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Package-owned invariant companion for `dsh-plan-build-mode`.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The plugin stores its Plan/Build mode in its own `plan-build/mode` session
|
|
5
|
+
* event, so the companion validates that event's payload before it reaches
|
|
6
|
+
* the durable log. The `sandbox/mode` event it also writes is validated by
|
|
7
|
+
* `@deepseek-ai/dsh-sandbox-policy`.
|
|
8
8
|
*
|
|
9
9
|
* @module dsh-plan-build-mode/invariant
|
|
10
10
|
*/
|
|
@@ -12,10 +12,33 @@
|
|
|
12
12
|
export const name = 'dsh-plan-build-mode-invariant';
|
|
13
13
|
/** Service required before the companion can reserve package ownership. */
|
|
14
14
|
export const inject = ['invariants'];
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
/** Validate one `plan-build/mode` event before it reaches the durable log. */
|
|
16
|
+
function validateEvent(event, fail) {
|
|
17
|
+
if (event.type !== 'plan-build/mode')
|
|
18
|
+
return;
|
|
19
|
+
const mode = event.data?.mode;
|
|
20
|
+
if (mode !== 'plan' && mode !== 'build') {
|
|
21
|
+
fail(`plan-build/mode carries invalid mode ${JSON.stringify(mode)}; expected 'plan' or 'build'`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Validate loaded and newly appended plan-build/mode state. */
|
|
25
|
+
const install = Object.assign((ctx, fail) => {
|
|
26
|
+
const seed = (session) => {
|
|
27
|
+
for (const event of session.snapshotEvents())
|
|
28
|
+
validateEvent(event, fail);
|
|
29
|
+
};
|
|
30
|
+
for (const session of ctx.sessions.list())
|
|
31
|
+
seed(session);
|
|
32
|
+
ctx.on('session/created', (session) => {
|
|
33
|
+
seed(session);
|
|
34
|
+
}, { global: true });
|
|
35
|
+
ctx.on('internal/dispatch', (_mode, eventName, args) => {
|
|
36
|
+
if (eventName !== 'session/event')
|
|
37
|
+
return;
|
|
38
|
+
const event = args[1];
|
|
39
|
+
validateEvent(event, fail);
|
|
40
|
+
}, { global: true });
|
|
41
|
+
}, { inject: ['sessions'] });
|
|
19
42
|
/**
|
|
20
43
|
* Register the plan-build-mode invariant companion.
|
|
21
44
|
* @param ctx - Cordis context carrying the invariant service.
|
package/lib/invariant.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,+BAA+B,CAAA;AACnD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAU,CAAA;AAE7C,
|
|
1
|
+
{"version":3,"file":"invariant.js","sourceRoot":"","sources":["../src/invariant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAKH,oCAAoC;AACpC,MAAM,CAAC,MAAM,IAAI,GAAG,+BAA+B,CAAA;AACnD,2EAA2E;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,YAAY,CAAU,CAAA;AAE7C,8EAA8E;AAC9E,SAAS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B,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAsC,EAAuB,EAAE,CACnF,OAAO,CAAC,OAAO,CACZ,GAAG,CAAC,UAAoF,CAAC,QAAQ,CAChG,qBAAqB,EACrB,OAAO,CACR,CACF,CAAA"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode-style tool permission engine for `dsh-plan-build-mode`.
|
|
3
|
+
*
|
|
4
|
+
* Models OpenCode's `permission` system — allow | ask | deny per tool
|
|
5
|
+
* category, object-syntax rules with last-match-wins, `~`/`$HOME` expansion,
|
|
6
|
+
* and the `external_directory` gate that asks for any path outside the
|
|
7
|
+
* session workspace — as pure, testable functions evaluated by the plugin's
|
|
8
|
+
* `tools/pre-execute` hook.
|
|
9
|
+
*
|
|
10
|
+
* The DSH sandbox stays the hard enforcement floor: a permission grant can
|
|
11
|
+
* never widen what the sandbox permits, and the gate only ever `ask`s for
|
|
12
|
+
* targets the sandbox can actually allow (the single-prompt principle — an
|
|
13
|
+
* external write the sandbox rejects goes straight to the existing
|
|
14
|
+
* sandbox-escalation flow instead of asking here first).
|
|
15
|
+
*
|
|
16
|
+
* @module dsh-plan-build-mode/permissions
|
|
17
|
+
*/
|
|
18
|
+
import type { SandboxMode } from '@deepseek-ai/dsh-sandbox';
|
|
19
|
+
/** One of OpenCode's permission verdicts. */
|
|
20
|
+
export type PermissionAction = 'allow' | 'ask' | 'deny';
|
|
21
|
+
/** Tool categories the permission engine gates (mirrors OpenCode's permission keys). */
|
|
22
|
+
export type ToolCategory = 'read' | 'edit' | 'glob' | 'grep' | 'bash' | 'pwsh' | 'webfetch' | 'websearch';
|
|
23
|
+
/** A wildcard permission rule: pattern → action. */
|
|
24
|
+
export interface PermissionRule {
|
|
25
|
+
pattern: string;
|
|
26
|
+
action: PermissionAction;
|
|
27
|
+
}
|
|
28
|
+
/** Scalar value, or object-syntax rules (`{ pattern: action, ... }`, last-match-wins). */
|
|
29
|
+
export type PermissionValue = PermissionAction | Record<string, PermissionAction>;
|
|
30
|
+
/** The `external_directory` gate config: default action + explicit rules. */
|
|
31
|
+
export interface ExternalDirectoryConfig {
|
|
32
|
+
default?: PermissionAction;
|
|
33
|
+
rules?: PermissionRule[];
|
|
34
|
+
}
|
|
35
|
+
/** Per-mode permission overrides, applied over the global `permission`. */
|
|
36
|
+
export interface ModePermissionConfig {
|
|
37
|
+
plan?: Partial<Record<ToolCategory, PermissionValue>>;
|
|
38
|
+
build?: Partial<Record<ToolCategory, PermissionValue>>;
|
|
39
|
+
}
|
|
40
|
+
/** Scalar default action per category (the fallback when no value is given). */
|
|
41
|
+
export declare const DEFAULT_ACTIONS: Record<ToolCategory, PermissionAction>;
|
|
42
|
+
/** Global default actions, mirroring OpenCode (most allow; `.env*` reads denied). */
|
|
43
|
+
export declare const DEFAULT_PERMISSION: Record<ToolCategory, PermissionValue>;
|
|
44
|
+
/** Default Plan-mode overrides (write tools denied, commands ask). */
|
|
45
|
+
export declare const DEFAULT_PLAN_OVERRIDES: Partial<Record<ToolCategory, PermissionValue>>;
|
|
46
|
+
/**
|
|
47
|
+
* Default `external_directory` action. Reads of files outside the workspace
|
|
48
|
+
* stay permitted (DSH reads pass through every sandbox mode); only writes are
|
|
49
|
+
* gated. Set to `'ask'` for full OpenCode behavior (external access prompts).
|
|
50
|
+
*/
|
|
51
|
+
export declare const DEFAULT_EXTERNAL_DEFAULT: PermissionAction;
|
|
52
|
+
/** Map a tool name to its permission category, or undefined for ungated tools. */
|
|
53
|
+
export declare function categoryOf(name: string): ToolCategory | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Extract the model-controlled path targets from one tool call's parsed
|
|
56
|
+
* arguments. Unknown or malformed arguments yield no targets: the category
|
|
57
|
+
* gate still applies, and the sandbox remains the floor for writes.
|
|
58
|
+
*/
|
|
59
|
+
export declare function extractTargets(name: string, args: unknown): string[];
|
|
60
|
+
/** Extract the raw command text for bash/pwsh tools (used for prefix rules). */
|
|
61
|
+
export declare function extractCommand(name: string, args: unknown): string | undefined;
|
|
62
|
+
/** Normalize a path/pattern for cross-platform wildcard matching (forward slashes). */
|
|
63
|
+
export declare function normalizePath(p: string): string;
|
|
64
|
+
/** Expand `~` / `$HOME` at the start of a pattern to the user home directory. */
|
|
65
|
+
export declare function expandHome(pattern: string, home: string): string;
|
|
66
|
+
/** OpenCode wildcard match: `*` = any run, `?` = one char, everything else literal. */
|
|
67
|
+
export declare function wildcardMatch(pattern: string, value: string): boolean;
|
|
68
|
+
/** Matching options for rule evaluation. */
|
|
69
|
+
export interface RuleMatchContext {
|
|
70
|
+
/** User home for `~` expansion (defaults to `os.homedir()`). */
|
|
71
|
+
home?: string;
|
|
72
|
+
/** Whether comparisons ignore case — Windows paths. */
|
|
73
|
+
caseSensitive?: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** Whether one permission pattern matches a value under the match context. */
|
|
76
|
+
export declare function ruleMatches(pattern: string, value: string, ctx?: RuleMatchContext): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Evaluate an ordered rule list against any of several subjects, last matching
|
|
79
|
+
* rule wins (OpenCode's evaluation order). Returns undefined when nothing matches.
|
|
80
|
+
*/
|
|
81
|
+
export declare function matchRules(rules: readonly PermissionRule[] | undefined, subjects: readonly string[], ctx?: RuleMatchContext): PermissionAction | undefined;
|
|
82
|
+
/** A category's resolved policy: a scalar action plus optional object-form rules. */
|
|
83
|
+
export interface ResolvedCategory {
|
|
84
|
+
action: PermissionAction;
|
|
85
|
+
rules?: readonly PermissionRule[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Normalize a `PermissionValue` into a scalar action plus ordered rules. The
|
|
89
|
+
* object form's `*` key becomes the catch-all default; later matching
|
|
90
|
+
* non-`*` rules override it (last-match-wins).
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveCategory(value: PermissionValue | undefined, fallback: PermissionAction): ResolvedCategory;
|
|
93
|
+
/** Canonicalize a path (resolve symlinks of the deepest existing ancestor). */
|
|
94
|
+
export declare function canonicalize(path: string): string;
|
|
95
|
+
/** Resolve a model-provided path against the session working directory. */
|
|
96
|
+
export declare function resolveTarget(path: string, cwd: string): string;
|
|
97
|
+
/** Whether `target` is `root` or lies beneath it (lexical, canonical spellings). */
|
|
98
|
+
export declare function isUnder(target: string, root: string, caseSensitive: boolean): boolean;
|
|
99
|
+
/** Host filesystem case sensitivity (Windows paths compare case-insensitively). */
|
|
100
|
+
export declare function caseSensitiveHost(): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the effective sandbox mode would permit a WRITE to the given
|
|
103
|
+
* canonical target — the single-prompt principle: the gate only asks for
|
|
104
|
+
* writes the sandbox can actually allow.
|
|
105
|
+
*/
|
|
106
|
+
export declare function sandboxAllowsWrite(mode: SandboxMode | undefined, target: string, workspaceRoot: string, tempRoots?: readonly string[]): boolean;
|
|
107
|
+
/** Subjects category rules are matched against: relative and absolute forms. */
|
|
108
|
+
export declare function matchSubjectsFor(name: string, targets: readonly string[], workspaceRoot: string, command: string | undefined): string[];
|
|
109
|
+
/** The resolved verdict of {@link gateDecision}. */
|
|
110
|
+
export type Decision = {
|
|
111
|
+
kind: 'allow';
|
|
112
|
+
} | {
|
|
113
|
+
kind: 'ask';
|
|
114
|
+
} | {
|
|
115
|
+
kind: 'deny';
|
|
116
|
+
code: 'plan-write' | 'external-deny' | 'external-write-escalation' | 'category-deny';
|
|
117
|
+
/** The offending external target, when the denial is external. */
|
|
118
|
+
target?: string | undefined;
|
|
119
|
+
/** The matched subject, when the denial comes from a category rule. */
|
|
120
|
+
subject?: string | undefined;
|
|
121
|
+
};
|
|
122
|
+
/** Pure inputs for the gate's decision procedure. */
|
|
123
|
+
export interface GateInput {
|
|
124
|
+
mode: 'plan' | 'build';
|
|
125
|
+
category: ToolCategory | undefined;
|
|
126
|
+
/** Canonical absolute targets (resolved + canonicalized). */
|
|
127
|
+
targets: readonly string[];
|
|
128
|
+
/** Subjects matched against category rules. */
|
|
129
|
+
matchSubjects: readonly string[];
|
|
130
|
+
/** Canonical workspace root. */
|
|
131
|
+
workspaceRoot: string;
|
|
132
|
+
/** Canonical plans directory (`workspaceRoot`/`plansDirectory`). */
|
|
133
|
+
plansDir: string;
|
|
134
|
+
/** Session-scoped allowlist patterns (OpenCode "always"). */
|
|
135
|
+
allowlist: readonly string[];
|
|
136
|
+
/** `external_directory` default action. */
|
|
137
|
+
externalDefault: PermissionAction;
|
|
138
|
+
/** `external_directory` explicit rules (last-match-wins). */
|
|
139
|
+
externalRules: readonly PermissionRule[] | undefined;
|
|
140
|
+
/** The category's resolved policy. */
|
|
141
|
+
categorySpec: ResolvedCategory;
|
|
142
|
+
/** Per-target sandbox write allowance. */
|
|
143
|
+
sandboxAllowsWrite: (target: string) => boolean;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Pure decision procedure. Order: plans-dir carve-out → external-directory
|
|
147
|
+
* gate → category gate. `ask` is only returned when an approval channel can
|
|
148
|
+
* resolve it; writes the sandbox cannot permit never ask (single-prompt
|
|
149
|
+
* principle — they surface as a `external-write-escalation` denial instead).
|
|
150
|
+
*/
|
|
151
|
+
export declare function gateDecision(input: GateInput): Decision;
|
|
152
|
+
/** Denial wording: Plan-mode write (keeps the historical `forbidden in Plan Mode` phrase). */
|
|
153
|
+
export declare function planWriteDenyReason(toolName: string): string;
|
|
154
|
+
/** Denial wording: an explicit external-directory deny rule matched. */
|
|
155
|
+
export declare function externalDenyReason(toolName: string, target: string): string;
|
|
156
|
+
/** Denial wording: a write the sandbox cannot permit (single-prompt handoff). */
|
|
157
|
+
export declare function externalWriteEscalationReason(toolName: string, target: string): string;
|
|
158
|
+
/** Denial wording: a category rule denied the call. */
|
|
159
|
+
export declare function categoryDenyReason(toolName: string, subject: string | undefined): string;
|
|
160
|
+
/** Denial wording: the approval channel rejected/aborted the ask. */
|
|
161
|
+
export declare function approvalDenyReason(toolName: string, outcome: string): string;
|
|
162
|
+
/** Denial wording: no approval channel is composed to resolve an ask. */
|
|
163
|
+
export declare function noApprovalChannelReason(toolName: string): string;
|
|
164
|
+
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAI3D,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,KAAK,GAAG,MAAM,CAAA;AAEvD,wFAAwF;AACxF,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,WAAW,CAAA;AAEzG,oDAAoD;AACpD,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,gBAAgB,CAAA;CACzB;AAED,0FAA0F;AAC1F,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAA;AAEjF,6EAA6E;AAC7E,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,gBAAgB,CAAA;IAC1B,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;CACzB;AAED,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACnC,IAAI,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;IACrD,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC,CAAA;CACvD;AAED,gFAAgF;AAChF,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,YAAY,EAAE,gBAAgB,CASlE,CAAA;AAED,qFAAqF;AACrF,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,YAAY,EAAE,eAAe,CASpE,C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