@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
package/README.md
CHANGED
|
@@ -83,7 +83,13 @@ Parked `needs_user` tickets still count toward the combined unfinished cap (`slo
|
|
|
83
83
|
|
|
84
84
|
Workers share the owner's workspace. There is no filesystem isolation; briefings should state file boundaries, or dependent work should stay serial.
|
|
85
85
|
|
|
86
|
-
Workers use the `foundations-files` preset: official file tools plus official `@deepseek-ai/dsh-tool-bash` and `@deepseek-ai/dsh-tool-jobs`. A canvas worker uses `foundations-canvas` instead, which mounts the file tools with `write` and `edit` disabled and does not mount bash or jobs. Preview bytes go through `canvas_write`, not the workspace. The
|
|
86
|
+
Workers use the `foundations-files` preset: official file tools plus official `@deepseek-ai/dsh-tool-bash` and `@deepseek-ai/dsh-tool-jobs`. A canvas worker uses `foundations-canvas` instead, which mounts the file tools with `write` and `edit` disabled and does not mount bash or jobs. Preview bytes go through `canvas_write`, not the workspace. The tool preset does not mount the web preset or add writable roots. Sandbox mode and approval policy are copied from the parent main session at dispatch, not left on the host `workspace-write` pin. A reserved start that does not create a worker within `min(ticket wallMs, 10m)` fails with `reserve-wall` and frees the slot; a late `createChild` is cancelled instead of attached.
|
|
87
|
+
|
|
88
|
+
## Default permission for new main sessions
|
|
89
|
+
|
|
90
|
+
A new bot main session used to keep the host composition default, which is `workspace-write` when that preset matches the composed sandbox and approval defaults. The workbench now has an instance-wide default. When `permission-default.json` has no `defaultPreset` field, a main session created afterward starts at `danger-full-access` (Fully allow / 完全允许): full file access and no approval prompts. Change it in the session permissions drawer. The choice is stored in the profile data directory and read again after a restart. It applies through `permissionPresets.set`, so the session's sandbox mode and approval policy change with it.
|
|
91
|
+
|
|
92
|
+
The setting does not rewrite a session that already exists, and a permission set on one session stays on that session. It also does not write the host `permission` settings namespace, because that namespace is pinned onto every fresh Agent. A worker does not read this default. When `foundations_dispatch` creates it, the worker inherits the parent main session's current preset (`permissionPresets.set` after the host pin). A later change on the main session does not rewrite a worker that already exists. See [docs/permission-default.md](docs/permission-default.md).
|
|
87
93
|
|
|
88
94
|
Runnable examples (any one of these is enough; `config.work` wins over the environment):
|
|
89
95
|
|
|
@@ -162,7 +168,7 @@ A visible connected view reconciles once on entry and every 60 seconds. Unsuppor
|
|
|
162
168
|
|
|
163
169
|
The authorization drawer loads the provider directory only on demand, with a per-App single-flight 30-second cache, no browser storage or cross-App cache. Local authorization lifecycle changes and mutations invalidate it. An open drawer revalidates every 30 seconds and on background resume: native provider registration has no complete event hook, so these changes are eventually reconciled rather than falsely treated as push-complete. Dynamic prompts/notices remain on the compact channel even when the drawer is closed.
|
|
164
170
|
|
|
165
|
-
DSH loads `dist/`. Rebuild after changing `src/`. Until `npm --prefix ui run build` has run, `/dsh-bot/` is 404.
|
|
171
|
+
DSH loads `dist/`. Rebuild after changing `src/`. The plugin build also writes `dist/canvas-inspector.js`; a published install reads that file and does not compile the inspector on startup. Until `npm --prefix ui run build` has run, `/dsh-bot/` is 404.
|
|
166
172
|
|
|
167
173
|
Host integration needs Node `>= 24.9` and `DSH_BIN`:
|
|
168
174
|
|
package/dist/canvas-http.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { buildSync } from 'esbuild';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
2
|
import { composeInspect } from "./canvas-compose.js";
|
|
5
3
|
import { asStoreFailure, toolError } from "./errors.js";
|
|
6
4
|
import { CANVAS_MAX_JSON_BYTES, normalizeCanvasPath } from "./canvas-store.js";
|
|
@@ -357,23 +355,18 @@ function writeBody(res, method, status, type, body, policy) {
|
|
|
357
355
|
function inspectorSource() {
|
|
358
356
|
if (inspectorCode != null)
|
|
359
357
|
return inspectorCode;
|
|
360
|
-
//
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
});
|
|
375
|
-
inspectorCode = result.outputFiles[0]?.text ?? '';
|
|
376
|
-
if (inspectorCode === '')
|
|
377
|
-
throw new Error('inspector bundle was empty');
|
|
378
|
-
return inspectorCode;
|
|
358
|
+
// dist/canvas-http.js reads the sibling bundle. Tests import src/ and use the same built file.
|
|
359
|
+
const candidates = [
|
|
360
|
+
new URL('./canvas-inspector.js', import.meta.url),
|
|
361
|
+
new URL('../dist/canvas-inspector.js', import.meta.url),
|
|
362
|
+
];
|
|
363
|
+
for (const url of candidates) {
|
|
364
|
+
if (!existsSync(url))
|
|
365
|
+
continue;
|
|
366
|
+
inspectorCode = readFileSync(url, 'utf8');
|
|
367
|
+
if (inspectorCode === '')
|
|
368
|
+
throw new Error('inspector bundle was empty');
|
|
369
|
+
return inspectorCode;
|
|
370
|
+
}
|
|
371
|
+
throw new Error('canvas inspector bundle is missing; run npm run build');
|
|
379
372
|
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// src/canvas-path.ts
|
|
4
|
+
var TABLE_SECTION = /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]);
|
|
5
|
+
var SEGMENT = /^(\d+):([a-z][a-z0-9-]*)$/;
|
|
6
|
+
function collapseText(value) {
|
|
7
|
+
return (value ?? "").replace(/\s+/g, " ").trim().slice(0, 120);
|
|
8
|
+
}
|
|
9
|
+
function adoptElement(el, parent = null) {
|
|
10
|
+
const node = {
|
|
11
|
+
tag: el.tagName.toLowerCase(),
|
|
12
|
+
classes: el.classList ? [...el.classList] : [],
|
|
13
|
+
text: collapseText(el.textContent),
|
|
14
|
+
rawChildren: [],
|
|
15
|
+
parent
|
|
16
|
+
};
|
|
17
|
+
for (let i = 0; i < el.children.length; i++) node.rawChildren.push(adoptElement(el.children[i], node));
|
|
18
|
+
return node;
|
|
19
|
+
}
|
|
20
|
+
function visibleChildren(node) {
|
|
21
|
+
const out = [];
|
|
22
|
+
for (const child of node.rawChildren) {
|
|
23
|
+
if (node.tag === "table" && TABLE_SECTION.has(child.tag)) out.push(...child.rawChildren);
|
|
24
|
+
else out.push(child);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
function parsePath(path) {
|
|
29
|
+
if (path === "") return [];
|
|
30
|
+
if (path.length > 500 || path.includes("//")) return null;
|
|
31
|
+
const parts = path.split("/");
|
|
32
|
+
const segs = [];
|
|
33
|
+
for (const part of parts) {
|
|
34
|
+
const match = SEGMENT.exec(part);
|
|
35
|
+
if (!match) return null;
|
|
36
|
+
const index = Number(match[1]);
|
|
37
|
+
if (!Number.isInteger(index) || index > 1e4 || String(index) !== match[1]) return null;
|
|
38
|
+
segs.push({ index, tag: match[2] });
|
|
39
|
+
}
|
|
40
|
+
return segs;
|
|
41
|
+
}
|
|
42
|
+
function formatPath(segs) {
|
|
43
|
+
return segs.map((seg) => `${seg.index}:${seg.tag}`).join("/");
|
|
44
|
+
}
|
|
45
|
+
function resolvePath(body, path) {
|
|
46
|
+
const segs = parsePath(path);
|
|
47
|
+
if (!segs) return null;
|
|
48
|
+
const breadcrumb = [{ path: "", tag: body.tag, classes: body.classes }];
|
|
49
|
+
const acc = [];
|
|
50
|
+
let current = body;
|
|
51
|
+
for (const seg of segs) {
|
|
52
|
+
const child = visibleChildren(current)[seg.index];
|
|
53
|
+
if (!child || child.tag !== seg.tag) return null;
|
|
54
|
+
acc.push(seg);
|
|
55
|
+
current = child;
|
|
56
|
+
breadcrumb.push({ path: formatPath(acc), tag: child.tag, classes: child.classes });
|
|
57
|
+
}
|
|
58
|
+
return { node: current, breadcrumb };
|
|
59
|
+
}
|
|
60
|
+
function pathTo(body, node) {
|
|
61
|
+
if (node === body) return "";
|
|
62
|
+
const parts = [];
|
|
63
|
+
let current = node;
|
|
64
|
+
while (current && current !== body) {
|
|
65
|
+
let parent = current.parent;
|
|
66
|
+
if (!parent) return null;
|
|
67
|
+
if (TABLE_SECTION.has(parent.tag) && parent.parent?.tag === "table") parent = parent.parent;
|
|
68
|
+
const index = visibleChildren(parent).indexOf(current);
|
|
69
|
+
if (index < 0) return null;
|
|
70
|
+
parts.push(`${index}:${current.tag}`);
|
|
71
|
+
current = parent;
|
|
72
|
+
}
|
|
73
|
+
if (current !== body) return null;
|
|
74
|
+
return parts.reverse().join("/");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/canvas-mention.ts
|
|
78
|
+
function mentionFrom(body, path) {
|
|
79
|
+
const found = resolvePath(body, path);
|
|
80
|
+
if (!found) return null;
|
|
81
|
+
const text = found.node.text.slice(0, 80);
|
|
82
|
+
const shown = text.length > 42 ? `${text.slice(0, 42)}\u2026` : text;
|
|
83
|
+
return {
|
|
84
|
+
path,
|
|
85
|
+
tag: found.node.tag,
|
|
86
|
+
classes: found.node.classes,
|
|
87
|
+
text,
|
|
88
|
+
breadcrumb: found.breadcrumb,
|
|
89
|
+
label: shown ? `${found.node.tag} \xB7 ${shown}` : found.node.tag
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/canvas-inspector.ts
|
|
94
|
+
var CHANNEL = "canvas-inspect";
|
|
95
|
+
function meta(name) {
|
|
96
|
+
return document.querySelector(`meta[name="${name}"]`)?.getAttribute("content") ?? "";
|
|
97
|
+
}
|
|
98
|
+
function box(id, outline, fill) {
|
|
99
|
+
const el = document.createElement("div");
|
|
100
|
+
el.id = id;
|
|
101
|
+
el.setAttribute("aria-hidden", "true");
|
|
102
|
+
el.style.setProperty("all", "initial");
|
|
103
|
+
el.style.position = "fixed";
|
|
104
|
+
el.style.pointerEvents = "none";
|
|
105
|
+
el.style.zIndex = "2147483646";
|
|
106
|
+
el.style.boxSizing = "border-box";
|
|
107
|
+
el.style.display = "none";
|
|
108
|
+
el.style.outline = outline;
|
|
109
|
+
el.style.outlineOffset = "-2px";
|
|
110
|
+
el.style.background = fill;
|
|
111
|
+
document.documentElement.append(el);
|
|
112
|
+
return el;
|
|
113
|
+
}
|
|
114
|
+
function place(el, target) {
|
|
115
|
+
const rect = target.getBoundingClientRect();
|
|
116
|
+
el.style.display = "block";
|
|
117
|
+
el.style.left = `${rect.left}px`;
|
|
118
|
+
el.style.top = `${rect.top}px`;
|
|
119
|
+
el.style.width = `${Math.max(rect.width, 0)}px`;
|
|
120
|
+
el.style.height = `${Math.max(rect.height, 0)}px`;
|
|
121
|
+
}
|
|
122
|
+
var nonce = meta("dsh-inspect-nonce");
|
|
123
|
+
var parentOrigin = meta("dsh-parent-origin");
|
|
124
|
+
var pageName = meta("dsh-inspect-page");
|
|
125
|
+
function anchorPage(target) {
|
|
126
|
+
const anchor = target.closest("a");
|
|
127
|
+
if (!(anchor instanceof HTMLAnchorElement)) return null;
|
|
128
|
+
const href = anchor.getAttribute("href")?.trim() ?? "";
|
|
129
|
+
if (href === "" || href.startsWith("#")) return null;
|
|
130
|
+
let url;
|
|
131
|
+
try {
|
|
132
|
+
url = new URL(href, document.baseURI);
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
const base = new URL(document.baseURI);
|
|
137
|
+
if (url.origin !== base.origin || !url.pathname.startsWith(base.pathname)) return null;
|
|
138
|
+
let rel = url.pathname.slice(base.pathname.length);
|
|
139
|
+
try {
|
|
140
|
+
rel = decodeURIComponent(rel);
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
if (!/^[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*\.html$/.test(rel)) return null;
|
|
145
|
+
return { path: rel, hash: url.hash };
|
|
146
|
+
}
|
|
147
|
+
if (nonce && parentOrigin && document.body) {
|
|
148
|
+
const hoverBox = box("dsh-hover", "2px solid #2563eb", "rgba(37, 99, 235, 0.12)");
|
|
149
|
+
const pinBox = box("dsh-pin", "2px solid #b45309", "rgba(180, 83, 9, 0.1)");
|
|
150
|
+
const tip = document.createElement("div");
|
|
151
|
+
tip.id = "dsh-tip";
|
|
152
|
+
tip.setAttribute("aria-hidden", "true");
|
|
153
|
+
tip.style.setProperty("all", "initial");
|
|
154
|
+
tip.style.position = "fixed";
|
|
155
|
+
tip.style.pointerEvents = "none";
|
|
156
|
+
tip.style.zIndex = "2147483647";
|
|
157
|
+
tip.style.display = "none";
|
|
158
|
+
tip.style.font = "12px/1.3 ui-sans-serif, system-ui, sans-serif";
|
|
159
|
+
tip.style.color = "#fff";
|
|
160
|
+
tip.style.background = "#1c1917";
|
|
161
|
+
tip.style.padding = "4px 8px";
|
|
162
|
+
tip.style.borderRadius = "6px";
|
|
163
|
+
tip.style.whiteSpace = "nowrap";
|
|
164
|
+
tip.style.maxWidth = "70vw";
|
|
165
|
+
tip.style.overflow = "hidden";
|
|
166
|
+
tip.style.textOverflow = "ellipsis";
|
|
167
|
+
document.documentElement.append(tip);
|
|
168
|
+
const body = adoptElement(document.body);
|
|
169
|
+
const elements = /* @__PURE__ */ new Map();
|
|
170
|
+
const nodes = /* @__PURE__ */ new WeakMap();
|
|
171
|
+
const index = (el, node) => {
|
|
172
|
+
nodes.set(el, node);
|
|
173
|
+
elements.set(node, el);
|
|
174
|
+
for (let i = 0; i < el.children.length; i++) index(el.children[i], node.rawChildren[i]);
|
|
175
|
+
};
|
|
176
|
+
index(document.body, body);
|
|
177
|
+
let armed = false;
|
|
178
|
+
let hoverEl = null;
|
|
179
|
+
let pinnedEl = null;
|
|
180
|
+
let hoverPath = "";
|
|
181
|
+
let queued = null;
|
|
182
|
+
let scheduled = false;
|
|
183
|
+
const post = (type, path, target) => {
|
|
184
|
+
const rect = target?.getBoundingClientRect();
|
|
185
|
+
const node = target ? nodes.get(target) : null;
|
|
186
|
+
window.parent.postMessage(
|
|
187
|
+
{
|
|
188
|
+
dsh: CHANNEL,
|
|
189
|
+
nonce,
|
|
190
|
+
type,
|
|
191
|
+
path,
|
|
192
|
+
tag: node?.tag ?? "",
|
|
193
|
+
classes: node?.classes ?? [],
|
|
194
|
+
text: node?.text ?? "",
|
|
195
|
+
rect: rect ? { x: rect.x, y: rect.y, width: rect.width, height: rect.height } : { x: 0, y: 0, width: 0, height: 0 }
|
|
196
|
+
},
|
|
197
|
+
parentOrigin
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
const nodeFor = (el) => {
|
|
201
|
+
let current = el;
|
|
202
|
+
while (current && current !== document.documentElement) {
|
|
203
|
+
if (current.id.startsWith("dsh-") || current.tagName === "SCRIPT") {
|
|
204
|
+
current = current.parentElement;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
const found = nodes.get(current);
|
|
208
|
+
if (found) return found;
|
|
209
|
+
current = current.parentElement;
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
};
|
|
213
|
+
const hideHover = () => {
|
|
214
|
+
hoverEl = null;
|
|
215
|
+
hoverPath = "";
|
|
216
|
+
hoverBox.style.display = "none";
|
|
217
|
+
tip.style.display = "none";
|
|
218
|
+
post("leave", "", null);
|
|
219
|
+
};
|
|
220
|
+
const showTip = (el, node, path) => {
|
|
221
|
+
const rect = el.getBoundingClientRect();
|
|
222
|
+
const mention = mentionFrom(body, path);
|
|
223
|
+
const trail = mention ? mention.breadcrumb.map((item) => item.classes[0] ? `${item.tag}.${item.classes[0]}` : item.tag).join(" / ") : node.tag;
|
|
224
|
+
tip.textContent = `${trail} ${Math.round(rect.width)}\xD7${Math.round(rect.height)}`;
|
|
225
|
+
tip.style.display = "block";
|
|
226
|
+
const top = rect.top < 28 ? rect.bottom + 6 : rect.top - 26;
|
|
227
|
+
tip.style.left = `${Math.max(rect.left, 4)}px`;
|
|
228
|
+
tip.style.top = `${top}px`;
|
|
229
|
+
};
|
|
230
|
+
const hover = (el) => {
|
|
231
|
+
if (!el) {
|
|
232
|
+
hideHover();
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const node = nodeFor(el);
|
|
236
|
+
if (!node) {
|
|
237
|
+
hideHover();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const path = pathTo(body, node);
|
|
241
|
+
const target = path == null ? null : elements.get(resolvePath(body, path)?.node ?? node);
|
|
242
|
+
if (path == null || !target) {
|
|
243
|
+
hideHover();
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
if (path === hoverPath) return;
|
|
247
|
+
hoverPath = path;
|
|
248
|
+
hoverEl = target;
|
|
249
|
+
place(hoverBox, target);
|
|
250
|
+
showTip(target, nodes.get(target) ?? node, path);
|
|
251
|
+
post("hover", path, target);
|
|
252
|
+
};
|
|
253
|
+
const pin = (el) => {
|
|
254
|
+
const node = nodeFor(el);
|
|
255
|
+
if (!node) return;
|
|
256
|
+
const path = pathTo(body, node);
|
|
257
|
+
if (path == null) return;
|
|
258
|
+
const target = elements.get(resolvePath(body, path)?.node ?? node);
|
|
259
|
+
if (!target) return;
|
|
260
|
+
pinnedEl = target;
|
|
261
|
+
place(pinBox, target);
|
|
262
|
+
post("select", path, target);
|
|
263
|
+
};
|
|
264
|
+
document.addEventListener("pointermove", (event) => {
|
|
265
|
+
if (!armed) return;
|
|
266
|
+
const hit = document.elementFromPoint(event.clientX, event.clientY);
|
|
267
|
+
queued = hit instanceof Element ? hit : null;
|
|
268
|
+
if (scheduled) return;
|
|
269
|
+
scheduled = true;
|
|
270
|
+
requestAnimationFrame(() => {
|
|
271
|
+
scheduled = false;
|
|
272
|
+
hover(queued);
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
document.documentElement.addEventListener("pointerleave", () => {
|
|
276
|
+
if (armed) hideHover();
|
|
277
|
+
});
|
|
278
|
+
document.addEventListener(
|
|
279
|
+
"click",
|
|
280
|
+
(event) => {
|
|
281
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
282
|
+
const target = event.target;
|
|
283
|
+
if (!(target instanceof Element)) return;
|
|
284
|
+
if (armed) {
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
event.stopPropagation();
|
|
287
|
+
pin(target);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const link = anchorPage(target);
|
|
291
|
+
if (!link) return;
|
|
292
|
+
if (link.path === pageName) {
|
|
293
|
+
if (!link.hash) event.preventDefault();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
event.stopPropagation();
|
|
298
|
+
post("open", link.hash ? `${link.path}${link.hash}` : link.path, null);
|
|
299
|
+
},
|
|
300
|
+
true
|
|
301
|
+
);
|
|
302
|
+
document.addEventListener(
|
|
303
|
+
"scroll",
|
|
304
|
+
() => {
|
|
305
|
+
if (!armed) return;
|
|
306
|
+
if (pinnedEl) place(pinBox, pinnedEl);
|
|
307
|
+
if (hoverEl) {
|
|
308
|
+
place(hoverBox, hoverEl);
|
|
309
|
+
const node = nodes.get(hoverEl);
|
|
310
|
+
if (node) showTip(hoverEl, node, hoverPath);
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
true
|
|
314
|
+
);
|
|
315
|
+
window.addEventListener("message", (event) => {
|
|
316
|
+
if (event.source !== window.parent || event.origin !== parentOrigin) return;
|
|
317
|
+
const data = event.data;
|
|
318
|
+
if (!data || data.dsh !== CHANNEL || data.nonce !== nonce) return;
|
|
319
|
+
if (data.type === "hello") {
|
|
320
|
+
post("ready", "", document.body);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (data.type === "focus" && typeof data.anchor === "string" && /^[A-Za-z][\w-]{0,64}$/.test(data.anchor)) {
|
|
324
|
+
document.getElementById(data.anchor)?.scrollIntoView({ block: "start" });
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (data.type === "arm") {
|
|
328
|
+
armed = true;
|
|
329
|
+
if (pinnedEl) place(pinBox, pinnedEl);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (data.type === "disarm") {
|
|
333
|
+
armed = false;
|
|
334
|
+
hideHover();
|
|
335
|
+
pinBox.style.display = "none";
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (data.type !== "pin") return;
|
|
339
|
+
if (typeof data.path !== "string" || !parsePath(data.path)) return;
|
|
340
|
+
const found = resolvePath(body, data.path);
|
|
341
|
+
const el = found ? elements.get(found.node) : null;
|
|
342
|
+
if (!el) return;
|
|
343
|
+
pinnedEl = el;
|
|
344
|
+
if (!armed) return;
|
|
345
|
+
place(pinBox, el);
|
|
346
|
+
el.scrollIntoView({ block: "nearest" });
|
|
347
|
+
});
|
|
348
|
+
post("ready", "", document.body);
|
|
349
|
+
}
|
|
350
|
+
})();
|
package/dist/desk.js
CHANGED
|
@@ -221,10 +221,19 @@ export function createDesk(options) {
|
|
|
221
221
|
return { status: 502, body: { error: 'bot_marker_failed', sessionId } };
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
|
+
const reused = Boolean(reusable) && sessionId === reusable.sessionId;
|
|
224
225
|
ledger.rememberSession(key, sessionId);
|
|
226
|
+
if (!reused) {
|
|
227
|
+
try {
|
|
228
|
+
options.onFreshMain?.(sessionId);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
/* creation already succeeded; agent/created applies a saved pending id */
|
|
232
|
+
}
|
|
233
|
+
}
|
|
225
234
|
return {
|
|
226
235
|
status: 201,
|
|
227
|
-
body: { sessionId, kind: 'bot', marker, reused
|
|
236
|
+
body: { sessionId, kind: 'bot', marker, reused },
|
|
228
237
|
};
|
|
229
238
|
}
|
|
230
239
|
/**
|
package/dist/http.js
CHANGED
|
@@ -11,6 +11,7 @@ import { serveWorkspaceImage } from "./workspace-image.js";
|
|
|
11
11
|
import { selectBrowserHome } from "./workspace-files.js";
|
|
12
12
|
import { toolError } from "./errors.js";
|
|
13
13
|
import { permissionView, setPermission } from "./permissions.js";
|
|
14
|
+
import { applyFreshMainPermission, forgetPending, permissionDefaultFile, permissionDefaultView, rememberFreshMain, setDefaultPermission, } from "./permission-default.js";
|
|
14
15
|
import { cuaAction, cuaSnapshot } from "./cua-access.js";
|
|
15
16
|
import { provisionSession } from "./provision.js";
|
|
16
17
|
import { handleWorkApi, openPageLive, openWorkLive } from "./work-http.js";
|
|
@@ -62,6 +63,18 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
62
63
|
stillAttached: sessionId => attachedSession(ctx, sessionId),
|
|
63
64
|
rpc: (endpoint, args, req) => hostRpc(req, endpoint, args),
|
|
64
65
|
usage: req => hostUsage(req),
|
|
66
|
+
onFreshMain: sessionId => {
|
|
67
|
+
if (storeDir === '')
|
|
68
|
+
return;
|
|
69
|
+
const file = permissionDefaultFile(storeDir);
|
|
70
|
+
try {
|
|
71
|
+
rememberFreshMain(file, sessionId);
|
|
72
|
+
applyFreshMainPermission(ctx, file, sessionId, id => engine.isBot(id));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
ctx.logger?.warn?.('session-foundations: default permission was not armed session=%s %s', sessionId, error instanceof Error ? error.message : String(error));
|
|
76
|
+
}
|
|
77
|
+
},
|
|
65
78
|
files: {
|
|
66
79
|
home: selectBrowserHome(process.env, extras.filesHome),
|
|
67
80
|
dshHome: process.env.DSH_HOME ?? '',
|
|
@@ -277,9 +290,24 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
277
290
|
const sessionId = url.searchParams.get('sessionId') ?? '';
|
|
278
291
|
return send(res, 200, { ok: true, ...permissionView(ctx, sessionId) });
|
|
279
292
|
}
|
|
293
|
+
if (req.method === 'GET' && path === '/session-foundations/api/permissions/default') {
|
|
294
|
+
if (storeDir === '')
|
|
295
|
+
return send(res, 503, toolError('UNAVAILABLE', 'Permission defaults need a profile data directory.'));
|
|
296
|
+
return send(res, 200, { ok: true, ...permissionDefaultView(ctx, permissionDefaultFile(storeDir)) });
|
|
297
|
+
}
|
|
298
|
+
if (req.method === 'POST' && path === '/session-foundations/api/permissions/default') {
|
|
299
|
+
if (storeDir === '')
|
|
300
|
+
return send(res, 503, toolError('UNAVAILABLE', 'Permission defaults need a profile data directory.'));
|
|
301
|
+
const body = await readJson(req);
|
|
302
|
+
return sendTool(res, setDefaultPermission(ctx, permissionDefaultFile(storeDir), typeof body.name === 'string' ? body.name : ''));
|
|
303
|
+
}
|
|
280
304
|
if (req.method === 'POST' && path === '/session-foundations/api/permissions') {
|
|
281
305
|
const body = await readJson(req);
|
|
282
|
-
|
|
306
|
+
const sessionId = typeof body.sessionId === 'string' ? body.sessionId : '';
|
|
307
|
+
const result = setPermission(ctx, sessionId, typeof body.name === 'string' ? body.name : '');
|
|
308
|
+
if (result.ok !== false && storeDir !== '')
|
|
309
|
+
forgetPending(permissionDefaultFile(storeDir), sessionId);
|
|
310
|
+
return sendTool(res, result);
|
|
283
311
|
}
|
|
284
312
|
if (req.method === 'GET' && path === '/session-foundations/api/authorization') {
|
|
285
313
|
const authorization = getAuthorization();
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,8 @@ import { openCanvasStore } from "./canvas-store.js";
|
|
|
21
21
|
import { backlogCanvases, bindCanvasCards, createCardLog, publishCardLog } from "./card-log.js";
|
|
22
22
|
import { canvasToolDefinitions } from "./canvas-tools.js";
|
|
23
23
|
import { forgetWorker, rememberWorker } from "./worker-handles.js";
|
|
24
|
+
import { applyFreshMainPermission, permissionDefaultFile } from "./permission-default.js";
|
|
25
|
+
import { applyWorkerPermission, dropWorkerPermission, rememberWorkerPermission } from "./worker-permission.js";
|
|
24
26
|
export const name = 'session-foundations';
|
|
25
27
|
// Cordis throws if a plugin reads a service it did not inject. Crash recovery reads the session log through this one.
|
|
26
28
|
export const inject = [
|
|
@@ -212,6 +214,22 @@ export function apply(ctx, config = {}) {
|
|
|
212
214
|
ctx.on('agent/created', (payload) => {
|
|
213
215
|
const agent = payload?.agent;
|
|
214
216
|
pinMainReasoning(agent, id => engine.isBot(id));
|
|
217
|
+
if (typeof agent?.id === 'string') {
|
|
218
|
+
try {
|
|
219
|
+
const source = typeof payload?.source === 'string' && payload.source !== '' ? payload.source : 'startup';
|
|
220
|
+
const inherited = applyWorkerPermission(ctx, agent.id, source);
|
|
221
|
+
// `rejected` stays pending so the create path can retry once the session is visible.
|
|
222
|
+
if (!inherited.applied &&
|
|
223
|
+
inherited.reason !== 'not-pending' &&
|
|
224
|
+
inherited.reason !== 'not-startup' &&
|
|
225
|
+
inherited.reason !== 'rejected') {
|
|
226
|
+
ctx.logger?.warn?.('session-foundations: worker permission was not inherited session=%s reason=%s', agent.id, inherited.reason);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
catch (error) {
|
|
230
|
+
ctx.logger?.warn?.('session-foundations: worker permission inheritance failed session=%s %s', agent.id, error instanceof Error ? error.message : String(error));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
215
233
|
if (!agent?.id || !engine.isBot(agent.id))
|
|
216
234
|
return;
|
|
217
235
|
let session = null;
|
|
@@ -225,6 +243,12 @@ export function apply(ctx, config = {}) {
|
|
|
225
243
|
parentSessionId: session?.header?.parentSession ?? null,
|
|
226
244
|
seeded: session?.header?.isSeeded === true,
|
|
227
245
|
});
|
|
246
|
+
try {
|
|
247
|
+
applyFreshMainPermission(ctx, permissionDefaultFile(dataDir), agent.id, id => engine.isBot(id));
|
|
248
|
+
}
|
|
249
|
+
catch (error) {
|
|
250
|
+
ctx.logger?.warn?.('session-foundations: default permission was not applied session=%s %s', agent.id, error instanceof Error ? error.message : String(error));
|
|
251
|
+
}
|
|
228
252
|
});
|
|
229
253
|
ctx.on('agent/inbox/inserted', (payload) => {
|
|
230
254
|
pinMainReasoning(payload?.agent, id => engine.isBot(id));
|
|
@@ -398,6 +422,8 @@ function startWork(ctx, store, engine, config, cards, onDrop = () => { }) {
|
|
|
398
422
|
if (isFenced(spec.ownerSessionId) || isFenced(spec.sessionId)) {
|
|
399
423
|
throw Object.assign(new Error('session is being deleted'), { code: 'DELETING' });
|
|
400
424
|
}
|
|
425
|
+
// Snapshot before create. The host pin runs inside create, on agent/created.
|
|
426
|
+
rememberWorkerPermission(ctx, spec.sessionId, spec.ownerSessionId);
|
|
401
427
|
let cwd = '';
|
|
402
428
|
let model = null;
|
|
403
429
|
try {
|
|
@@ -425,9 +451,24 @@ function startWork(ctx, store, engine, config, cards, onDrop = () => { }) {
|
|
|
425
451
|
options.meta = { ...(options.meta ?? {}), agentPreset: preset };
|
|
426
452
|
options.setup = workerFileSetup(ctx, preset);
|
|
427
453
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
454
|
+
try {
|
|
455
|
+
const handle = await ctx.agents.create(options);
|
|
456
|
+
rememberWorker(spec.sessionId, handle);
|
|
457
|
+
try {
|
|
458
|
+
const inherited = applyWorkerPermission(ctx, spec.sessionId, 'startup');
|
|
459
|
+
if (!inherited.applied && inherited.reason !== 'not-pending' && inherited.reason !== 'not-startup') {
|
|
460
|
+
ctx.logger?.warn?.('session-foundations: worker permission was not inherited session=%s parent=%s reason=%s', spec.sessionId, spec.ownerSessionId, inherited.reason);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
catch (error) {
|
|
464
|
+
ctx.logger?.warn?.('session-foundations: worker permission inheritance failed session=%s %s', spec.sessionId, error instanceof Error ? error.message : String(error));
|
|
465
|
+
}
|
|
466
|
+
return spec.sessionId;
|
|
467
|
+
}
|
|
468
|
+
catch (error) {
|
|
469
|
+
dropWorkerPermission(spec.sessionId);
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
431
472
|
},
|
|
432
473
|
recordCard: input => {
|
|
433
474
|
cards.record(ctx, input);
|