@thready-web/dsh-bot-plugin 0.1.0-beta.12 → 0.1.0-beta.14
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 +8 -2
- package/dist/canvas-http.js +15 -22
- package/dist/canvas-inspector.js +350 -0
- package/dist/desk.js +10 -1
- package/dist/http.js +29 -1
- package/dist/index.js +44 -3
- package/dist/permission-default.js +167 -0
- package/dist/permissions.js +18 -0
- package/dist/work-child.js +5 -4
- package/dist/worker-permission.js +75 -0
- package/package.json +6 -3
- package/public/assets/{SourceEditor-BjtoMvcX.js → SourceEditor-D5hkHEda.js} +3 -3
- package/public/assets/{cssMode--96PQtWh.js → cssMode-BnFhgVEg.js} +1 -1
- package/public/assets/{freemarker2-Bz-HlISL.js → freemarker2-CZnj0JQj.js} +1 -1
- package/public/assets/{handlebars-D9ScJ8AM.js → handlebars-DphCsr4u.js} +1 -1
- package/public/assets/{html-Czc0jojJ.js → html-OCowmZFv.js} +1 -1
- package/public/assets/{htmlMode-CCww5Z1w.js → htmlMode-CoLh_9Z9.js} +1 -1
- package/public/assets/{index-ztUdW074.js → index-FZCH-ncM.js} +41 -41
- package/public/assets/{javascript-B-yRZSiz.js → javascript-iZ7A5Jj8.js} +1 -1
- package/public/assets/{jsonMode-ASWsY833.js → jsonMode-Di_cLA3H.js} +1 -1
- package/public/assets/{liquid-BGoox2vJ.js → liquid-CiQRe5pn.js} +1 -1
- package/public/assets/{mdx-DHgvnl_U.js → mdx-DN_t25k0.js} +1 -1
- package/public/assets/{python-BJvVD30_.js → python-BjuxmwHR.js} +1 -1
- package/public/assets/{razor-0PwR35mu.js → razor-8ivZBBa_.js} +1 -1
- package/public/assets/{tsMode-3ETp8Gdh.js → tsMode-Bd30jXnV.js} +1 -1
- package/public/assets/{typescript-BT0iTK6K.js → typescript-yjXIK0i2.js} +1 -1
- package/public/assets/{xml-BTaNc_uT.js → xml-SwYrmBdL.js} +1 -1
- package/public/assets/{yaml-Dr7LW3tK.js → yaml-B5ynY56t.js} +1 -1
- package/public/index.html +1 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instance-wide default permission for bot main sessions created from now on.
|
|
3
|
+
*
|
|
4
|
+
* The host's `permission` settings namespace pins `defaultPreset` onto every
|
|
5
|
+
* fresh Agent, including workers. This file does not write that namespace.
|
|
6
|
+
* A new bot main session is applied later through `permissionPresets.set`,
|
|
7
|
+
* the same sandbox-mode and approval-policy write the per-session control uses.
|
|
8
|
+
* Sessions that already exist, and any explicit per-session choice, are left
|
|
9
|
+
* alone. Workers are never added to the pending list. A worker copies its
|
|
10
|
+
* parent main session at creation (`worker-permission.ts`), not this file.
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { toolError } from "./errors.js";
|
|
15
|
+
import { ensureDir, writeAtomic } from "./fs-safe.js";
|
|
16
|
+
import { permissionView, setPermission } from "./permissions.js";
|
|
17
|
+
/** Official preset id for full file access and no approval prompts. */
|
|
18
|
+
export const PRODUCT_DEFAULT_PRESET = 'danger-full-access';
|
|
19
|
+
const MAIN_SESSION = /^session-[A-Za-z0-9-]+$/;
|
|
20
|
+
const RESERVED = new Set(['auto', 'custom']);
|
|
21
|
+
export function permissionDefaultFile(dataDir) {
|
|
22
|
+
return join(dataDir, 'permission-default.json');
|
|
23
|
+
}
|
|
24
|
+
function readBody(file) {
|
|
25
|
+
if (!existsSync(file))
|
|
26
|
+
return { body: {}, corrupt: false };
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
29
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
30
|
+
return { body: {}, corrupt: true };
|
|
31
|
+
return { body: parsed, corrupt: false };
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return { body: {}, corrupt: true };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function pendingOf(value) {
|
|
38
|
+
if (!Array.isArray(value))
|
|
39
|
+
return [];
|
|
40
|
+
const ids = value.filter((item) => typeof item === 'string' && MAIN_SESSION.test(item));
|
|
41
|
+
return [...new Set(ids)];
|
|
42
|
+
}
|
|
43
|
+
function interpretStored(body, corrupt) {
|
|
44
|
+
if (corrupt)
|
|
45
|
+
return { stored: null, ignoredStored: true };
|
|
46
|
+
if (!Object.hasOwn(body, 'defaultPreset'))
|
|
47
|
+
return { stored: null, ignoredStored: false };
|
|
48
|
+
const value = body.defaultPreset;
|
|
49
|
+
if (typeof value !== 'string' || value === '' || RESERVED.has(value))
|
|
50
|
+
return { stored: null, ignoredStored: true };
|
|
51
|
+
return { stored: value, ignoredStored: false };
|
|
52
|
+
}
|
|
53
|
+
export function readPermissionDefault(file) {
|
|
54
|
+
const { body, corrupt } = readBody(file);
|
|
55
|
+
const interpreted = interpretStored(body, corrupt);
|
|
56
|
+
return { ...interpreted, pending: pendingOf(body.pending), corrupt };
|
|
57
|
+
}
|
|
58
|
+
function writeBody(file, body) {
|
|
59
|
+
ensureDir(dirname(file));
|
|
60
|
+
writeAtomic(file, `${JSON.stringify(body, null, 2)}\n`);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Preset a new main session should receive. A missing or unusable stored
|
|
64
|
+
* value uses Fully allow when the live catalog contains it.
|
|
65
|
+
*/
|
|
66
|
+
export function resolveDefaultPreset(stored, allowed) {
|
|
67
|
+
if (stored && allowed.includes(stored))
|
|
68
|
+
return stored;
|
|
69
|
+
if (allowed.includes(PRODUCT_DEFAULT_PRESET))
|
|
70
|
+
return PRODUCT_DEFAULT_PRESET;
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
function allowedPresets(options) {
|
|
74
|
+
return options.map(option => option.value).filter(value => value !== '' && !RESERVED.has(value));
|
|
75
|
+
}
|
|
76
|
+
export function permissionDefaultView(ctx, file) {
|
|
77
|
+
const catalog = permissionView(ctx, '');
|
|
78
|
+
const saved = readPermissionDefault(file);
|
|
79
|
+
const options = catalog.defaultOptions.filter(option => !RESERVED.has(option.value));
|
|
80
|
+
const allowed = allowedPresets(options);
|
|
81
|
+
const ignoredStored = saved.ignoredStored || (saved.stored !== null && !allowed.includes(saved.stored));
|
|
82
|
+
const defaultPreset = catalog.available ? resolveDefaultPreset(saved.stored, allowed) : '';
|
|
83
|
+
return {
|
|
84
|
+
available: catalog.available,
|
|
85
|
+
defaultPreset,
|
|
86
|
+
stored: saved.stored,
|
|
87
|
+
ignoredStored,
|
|
88
|
+
options,
|
|
89
|
+
productDefault: PRODUCT_DEFAULT_PRESET,
|
|
90
|
+
scope: 'new-main-session',
|
|
91
|
+
hostDefault: catalog.defaultPreset,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export function setDefaultPermission(ctx, file, name) {
|
|
95
|
+
if (typeof name !== 'string' || name === '' || RESERVED.has(name)) {
|
|
96
|
+
return toolError('VALIDATION', 'A configured preset is required. Auto and custom cannot be the default for new sessions.');
|
|
97
|
+
}
|
|
98
|
+
const catalog = permissionView(ctx, '');
|
|
99
|
+
if (!catalog.available) {
|
|
100
|
+
return toolError('UNAVAILABLE', 'Official permission presets are not composed on this host.');
|
|
101
|
+
}
|
|
102
|
+
const allowed = new Set(allowedPresets(catalog.defaultOptions));
|
|
103
|
+
if (!allowed.has(name)) {
|
|
104
|
+
return toolError('VALIDATION', 'That preset is not a configured permission mode.');
|
|
105
|
+
}
|
|
106
|
+
const { body } = readBody(file);
|
|
107
|
+
writeBody(file, { ...body, defaultPreset: name });
|
|
108
|
+
return { ok: true, ...permissionDefaultView(ctx, file) };
|
|
109
|
+
}
|
|
110
|
+
/** Remember a workbench-created main session until its first live permission write. */
|
|
111
|
+
export function rememberFreshMain(file, sessionId) {
|
|
112
|
+
if (!MAIN_SESSION.test(sessionId))
|
|
113
|
+
return false;
|
|
114
|
+
const { body } = readBody(file);
|
|
115
|
+
const pending = pendingOf(body.pending);
|
|
116
|
+
if (pending.includes(sessionId))
|
|
117
|
+
return true;
|
|
118
|
+
writeBody(file, { ...body, pending: [...pending, sessionId] });
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
/** An explicit per-session choice wins over the global default. */
|
|
122
|
+
export function forgetPending(file, sessionId) {
|
|
123
|
+
const { body } = readBody(file);
|
|
124
|
+
const pending = pendingOf(body.pending);
|
|
125
|
+
if (!pending.includes(sessionId))
|
|
126
|
+
return false;
|
|
127
|
+
writeBody(file, { ...body, pending: pending.filter(id => id !== sessionId) });
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
function consumePending(file, sessionId) {
|
|
131
|
+
const { body } = readBody(file);
|
|
132
|
+
const pending = pendingOf(body.pending);
|
|
133
|
+
if (!pending.includes(sessionId))
|
|
134
|
+
return false;
|
|
135
|
+
writeBody(file, { ...body, pending: pending.filter(id => id !== sessionId) });
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
function restorePending(file, sessionId) {
|
|
139
|
+
const { body } = readBody(file);
|
|
140
|
+
const pending = pendingOf(body.pending);
|
|
141
|
+
if (pending.includes(sessionId))
|
|
142
|
+
return;
|
|
143
|
+
writeBody(file, { ...body, pending: [...pending, sessionId] });
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Apply the configured default once, through the official preset setter.
|
|
147
|
+
* A session that is not pending is not touched, so a later change to the
|
|
148
|
+
* global default does not rewrite it.
|
|
149
|
+
*/
|
|
150
|
+
export function applyFreshMainPermission(ctx, file, sessionId, isBot) {
|
|
151
|
+
if (!MAIN_SESSION.test(sessionId) || !isBot(sessionId))
|
|
152
|
+
return { applied: false, reason: 'not-main' };
|
|
153
|
+
if (!consumePending(file, sessionId))
|
|
154
|
+
return { applied: false, reason: 'not-pending' };
|
|
155
|
+
const view = permissionDefaultView(ctx, file);
|
|
156
|
+
if (!view.available || view.defaultPreset === '') {
|
|
157
|
+
restorePending(file, sessionId);
|
|
158
|
+
return { applied: false, reason: view.available ? 'unresolved' : 'unavailable' };
|
|
159
|
+
}
|
|
160
|
+
const result = setPermission(ctx, sessionId, view.defaultPreset);
|
|
161
|
+
if (result.ok === false) {
|
|
162
|
+
if (result.code === 'NOT_FOUND' || result.code === 'UNAVAILABLE')
|
|
163
|
+
restorePending(file, sessionId);
|
|
164
|
+
return { applied: false, reason: 'rejected' };
|
|
165
|
+
}
|
|
166
|
+
return { applied: true, reason: 'applied', preset: view.defaultPreset };
|
|
167
|
+
}
|
package/dist/permissions.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* The write path is `ctx.permissionPresets.set(session, name)`. Auto is
|
|
5
5
|
* offered only when the live catalog includes it (the experimental package
|
|
6
6
|
* has registered it). This is a settings concern, not a transcript card.
|
|
7
|
+
* The instance default for a future main session is `permission-default.ts`;
|
|
8
|
+
* a worker copies its parent with `worker-permission.ts`. Both call this
|
|
9
|
+
* setter and do not invent a second sandbox policy.
|
|
7
10
|
*/
|
|
8
11
|
import { toolError } from "./errors.js";
|
|
9
12
|
function sessionOf(ctx, sessionId) {
|
|
@@ -31,6 +34,21 @@ function optionList(value) {
|
|
|
31
34
|
return [option];
|
|
32
35
|
});
|
|
33
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The preset the live session is actually running under.
|
|
39
|
+
* A missing session does not fall back to the catalog composition default:
|
|
40
|
+
* that default is the host pin, not this session's policy.
|
|
41
|
+
*/
|
|
42
|
+
export function effectivePermission(ctx, sessionId) {
|
|
43
|
+
const service = ctx.get?.('permissionPresets');
|
|
44
|
+
if (!service || typeof service.catalog !== 'function' || typeof service.current !== 'function') {
|
|
45
|
+
return { available: false, found: false, preset: '' };
|
|
46
|
+
}
|
|
47
|
+
const session = sessionOf(ctx, sessionId);
|
|
48
|
+
if (!session)
|
|
49
|
+
return { available: true, found: false, preset: '' };
|
|
50
|
+
return { available: true, found: true, preset: String(service.current(session) ?? '') };
|
|
51
|
+
}
|
|
34
52
|
export function permissionView(ctx, sessionId) {
|
|
35
53
|
const service = ctx.get?.('permissionPresets');
|
|
36
54
|
if (!service || typeof service.catalog !== 'function') {
|
package/dist/work-child.js
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* so their request header otherwise lists only host tools.
|
|
4
4
|
* This preset mounts official file tools and official command tools
|
|
5
5
|
* (`@deepseek-ai/dsh-tool-bash`, `@deepseek-ai/dsh-tool-jobs`). It does not
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* mount the web preset (no web_fetch, subagent, or other profile tools),
|
|
7
|
+
* add writable roots, or itself change the sandbox mode or approval policy.
|
|
8
|
+
* Those knobs are copied from the parent main session when the worker is
|
|
9
|
+
* created. The session cwd copied at create remains the workspace path;
|
|
10
|
+
* bash uses the composed host bash-sandbox under the inherited sandbox mode.
|
|
10
11
|
*/
|
|
11
12
|
export const WORKER_FILE_PRESET = 'foundations-files';
|
|
12
13
|
/**
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { effectivePermission, permissionView, setPermission } from "./permissions.js";
|
|
2
|
+
const WORKER_ID = /^worker-[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
3
|
+
const SKIP_SOURCE = new Set(['resume', 'clear', 'compact']);
|
|
4
|
+
const pending = new Map();
|
|
5
|
+
function snapshotParent(ctx, parentId) {
|
|
6
|
+
if (typeof parentId !== 'string' || parentId === '')
|
|
7
|
+
return { preset: '', reason: 'missing' };
|
|
8
|
+
const effective = effectivePermission(ctx, parentId);
|
|
9
|
+
if (!effective.available)
|
|
10
|
+
return { preset: '', reason: 'unavailable' };
|
|
11
|
+
if (!effective.found || effective.preset === '')
|
|
12
|
+
return { preset: '', reason: 'missing' };
|
|
13
|
+
if (effective.preset === 'custom')
|
|
14
|
+
return { preset: '', reason: 'custom' };
|
|
15
|
+
const known = permissionView(ctx, '').options.some(option => option.value === effective.preset);
|
|
16
|
+
if (!known)
|
|
17
|
+
return { preset: '', reason: 'invalid' };
|
|
18
|
+
return { preset: effective.preset, reason: 'ok' };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Record the parent preset before `agents.create`. A worker id that does not
|
|
22
|
+
* match the ticket child form is ignored, so this cannot arm an unrelated agent.
|
|
23
|
+
*/
|
|
24
|
+
export function rememberWorkerPermission(ctx, workerId, parentId) {
|
|
25
|
+
if (!WORKER_ID.test(workerId))
|
|
26
|
+
return null;
|
|
27
|
+
const snap = snapshotParent(ctx, parentId);
|
|
28
|
+
const intent = {
|
|
29
|
+
workerId,
|
|
30
|
+
parentId,
|
|
31
|
+
preset: snap.preset,
|
|
32
|
+
reason: snap.reason,
|
|
33
|
+
};
|
|
34
|
+
pending.set(workerId, intent);
|
|
35
|
+
return intent;
|
|
36
|
+
}
|
|
37
|
+
/** Drop an intent when create fails before a worker exists. */
|
|
38
|
+
export function dropWorkerPermission(workerId) {
|
|
39
|
+
pending.delete(workerId);
|
|
40
|
+
}
|
|
41
|
+
/** Test isolation. Production create either applies or drops its own intent. */
|
|
42
|
+
export function clearPendingWorkerPermissions() {
|
|
43
|
+
pending.clear();
|
|
44
|
+
}
|
|
45
|
+
export function pendingWorkerPermission(workerId) {
|
|
46
|
+
return pending.get(workerId) ?? null;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Apply the snapshotted parent preset once.
|
|
50
|
+
* `resume`, `clear`, and `compact` do not consume the intent: those events
|
|
51
|
+
* are not the creation pin. A missing source is treated as creation because
|
|
52
|
+
* the only writer of an intent is the dispatch create path.
|
|
53
|
+
* An empty snapshot fails closed: the host pin is left in place, and the
|
|
54
|
+
* instance default is not substituted.
|
|
55
|
+
*/
|
|
56
|
+
export function applyWorkerPermission(ctx, workerId, source = 'startup') {
|
|
57
|
+
const intent = pending.get(workerId);
|
|
58
|
+
if (!intent)
|
|
59
|
+
return { applied: false, reason: 'not-pending' };
|
|
60
|
+
if (SKIP_SOURCE.has(source))
|
|
61
|
+
return { applied: false, reason: 'not-startup' };
|
|
62
|
+
if (intent.preset === '') {
|
|
63
|
+
pending.delete(workerId);
|
|
64
|
+
return { applied: false, reason: intent.reason };
|
|
65
|
+
}
|
|
66
|
+
const result = setPermission(ctx, workerId, intent.preset);
|
|
67
|
+
if (result.ok === false) {
|
|
68
|
+
if (result.code === 'NOT_FOUND' || result.code === 'UNAVAILABLE')
|
|
69
|
+
return { applied: false, reason: 'rejected' };
|
|
70
|
+
pending.delete(workerId);
|
|
71
|
+
return { applied: false, reason: 'rejected' };
|
|
72
|
+
}
|
|
73
|
+
pending.delete(workerId);
|
|
74
|
+
return { applied: true, reason: 'applied', preset: intent.preset };
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thready-web/dsh-bot-plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "DSH bot plugin: session persona, memory, work, hash routing, and the workbench. Pinned to @deepseek-ai/dsh 0.2.2-rc.1.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "node build.mjs",
|
|
34
|
+
"verify:publish": "node scripts/verify-publish.mjs",
|
|
34
35
|
"type-check": "tsc -p tsconfig.typecheck.json --noEmit && tsc -p tsconfig.client.json --noEmit",
|
|
35
36
|
"test": "node scripts/unit-tests.mjs",
|
|
36
37
|
"test:host": "npm run build && node --test test/host-integration.test.ts && node --test test/triggers-host.test.ts && node --test test/budget-host.test.ts && node --test test/activity-host.test.ts && node --test test/work-host.test.ts && node --test test/work-bash-host.test.ts",
|
|
@@ -41,16 +42,18 @@
|
|
|
41
42
|
"node": ">=22.18.0",
|
|
42
43
|
"dsh": ">=0.2.2-rc.1 <0.2.3-0"
|
|
43
44
|
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@deepseek-ai/dsh-session": "^0.2.2-rc.1",
|
|
47
|
+
"linkedom": "^0.18.15"
|
|
48
|
+
},
|
|
44
49
|
"devDependencies": {
|
|
45
50
|
"@biomejs/biome": "^2.6.6",
|
|
46
51
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
47
52
|
"@deepseek-ai/dsh-api-session-controller": "^0.2.2-rc.1",
|
|
48
53
|
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.1",
|
|
49
|
-
"@deepseek-ai/dsh-session": "^0.2.2-rc.1",
|
|
50
54
|
"@deepseek-ai/dsh-session-query": "^0.2.2-rc.1",
|
|
51
55
|
"@types/node": "^24.10.0",
|
|
52
56
|
"esbuild": "^0.25.0",
|
|
53
|
-
"linkedom": "^0.18.15",
|
|
54
57
|
"typescript": "^5.9.3"
|
|
55
58
|
},
|
|
56
59
|
"dsh": {
|