@dsmm/dsmm 0.3.4 → 0.3.5
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/docs/settings-status.md +1 -1
- package/lib/client/DeploymentFields.js +18 -1
- package/lib/client/PermissionsPanel.js +6 -5
- package/lib/client/index.js +2 -18
- package/lib/client/permission-controller.d.ts +11 -1
- package/lib/client/permission-controller.js +17 -12
- package/lib/client/permission-locales.d.ts +2 -0
- package/lib/client/permission-locales.js +4 -0
- package/lib/client/permission-session.d.ts +37 -0
- package/lib/client/permission-session.js +34 -0
- package/lib/client/styles.d.ts +1 -1
- package/lib/client/styles.js +4 -0
- package/lib/client.js +433 -391
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -5465,6 +5465,10 @@ var PROFILE_STYLES = `
|
|
|
5465
5465
|
.dsmm-scope-save{display:flex;flex-direction:column;gap:8px;padding-top:16px;border-top:1px solid var(--dsw-alias-border-l4)}
|
|
5466
5466
|
.dsmm-deployment .dsmm-deployment-group{border-top:1px solid var(--dsw-alias-border-l4);padding-top:8px;min-width:0}
|
|
5467
5467
|
.dsmm-deployment .dsmm-deployment-group>div{display:flex;flex-direction:column;gap:8px;padding-top:8px}
|
|
5468
|
+
.dsmm-deployment summary .dsmm-group-summary{display:flex;align-items:center;gap:8px;min-width:0}
|
|
5469
|
+
.dsmm-deployment .dsmm-group-summary-label{flex:1 1 auto;min-width:0;overflow-wrap:anywhere}
|
|
5470
|
+
.dsmm-deployment .dsmm-group-summary-action{flex:0 0 auto;min-height:28px;height:28px;padding:0 8px}
|
|
5471
|
+
.dsmm-deployment .dsmm-group-summary-action[hidden]{display:none}
|
|
5468
5472
|
.dsmm-deployment code{font-family:var(--ds-font-family-code);overflow-wrap:anywhere}
|
|
5469
5473
|
.dsmm-deployment label code,.dsmm-deployment summary code{margin-left:8px;font-size:12px;line-height:18px;font-weight:400;color:var(--dsw-alias-label-secondary)}
|
|
5470
5474
|
.dsmm-deployment pre{margin:0;max-width:100%;white-space:pre-wrap;overflow-wrap:anywhere;font-family:var(--ds-font-family-code)}
|
|
@@ -6272,6 +6276,8 @@ var permissionEn = {
|
|
|
6272
6276
|
title: "Permission control",
|
|
6273
6277
|
rules: "Global permission rules (through the selected main session)",
|
|
6274
6278
|
nativeApproval: "Approve commands in the native prompt. Allow approves only that call.",
|
|
6279
|
+
sandboxScope: "These rules decide allow, ask or deny for tools and matches. The Host sandbox and its native approval prompt remain separate and authoritative for what an approved call may touch.",
|
|
6280
|
+
unconfirmedObservation: "Showing the last successful observation. The current selection is not confirmed yet, so editing and saving stay unavailable.",
|
|
6275
6281
|
root: "Selected main session",
|
|
6276
6282
|
noRoot: "Select a main session to view its permission rules.",
|
|
6277
6283
|
child: "Select this child’s main session to edit Global rules.",
|
|
@@ -6426,6 +6432,8 @@ var permissionZh = {
|
|
|
6426
6432
|
title: "权限控制",
|
|
6427
6433
|
rules: "全局权限规则(通过所选主会话管理)",
|
|
6428
6434
|
nativeApproval: "请在原生提示中批准命令;「允许」仅批准本次调用。",
|
|
6435
|
+
sandboxScope: "这些规则决定工具与匹配项的允许、询问或拒绝;具体调用可触及的范围仍由宿主沙箱及其原生批准提示单独决定。",
|
|
6436
|
+
unconfirmedObservation: "当前显示上次成功观测;当前选择尚未确认,编辑与保存暂不可用。",
|
|
6429
6437
|
root: "所选主会话",
|
|
6430
6438
|
noRoot: "请选择主会话以查看权限规则。",
|
|
6431
6439
|
child: "请切换到此子会话的主会话后编辑全局规则。",
|
|
@@ -6992,19 +7000,35 @@ function Field({ schema, path, controller, initiallyOpen = false, disclosures, t
|
|
|
6992
7000
|
disclosures?.set(name2, expanded);
|
|
6993
7001
|
setOpen(expanded);
|
|
6994
7002
|
};
|
|
7003
|
+
const unsetGroup = (event) => {
|
|
7004
|
+
event?.preventDefault();
|
|
7005
|
+
event?.stopPropagation();
|
|
7006
|
+
const summary = event?.currentTarget.closest("summary"), action2 = event?.currentTarget ?? null;
|
|
7007
|
+
controller.clearRaw(name2);
|
|
7008
|
+
controller.edit(path, void 0);
|
|
7009
|
+
if (summary !== null && summary !== void 0) {
|
|
7010
|
+
const restore = () => {
|
|
7011
|
+
const active = document.activeElement;
|
|
7012
|
+
if (active === null || active === document.body || active === action2) summary.focus();
|
|
7013
|
+
};
|
|
7014
|
+
if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => {
|
|
7015
|
+
restore();
|
|
7016
|
+
requestAnimationFrame(restore);
|
|
7017
|
+
});
|
|
7018
|
+
}
|
|
7019
|
+
};
|
|
6995
7020
|
const explicit = at(state.draft, path), inherited = controller.layer === "global" ? at(snapshot4.defaults, path) : at(mergeLayer(mergeLayer(snapshot4.defaults, snapshot4.global), snapshot4.nativeForm?.base ?? {}), path);
|
|
6996
7021
|
const choices = enumValues(schema), disabled = !controller.canEdit();
|
|
6997
7022
|
if (name2 === "permissionControl.nativeCommands.entries") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { "data-field": name2, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(NativeCommandEntries, { controller, value: explicit, inherited: inherited ?? [], disabled, onChange: (value) => controller.edit(path, value), setInvalid: (key, bad) => controller.setInvalid(key, bad), t: permissionText(t) }) });
|
|
6998
7023
|
if (name2 === "permissionControl.rules") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { "data-field": name2, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PermissionRuleEntries, { controller, value: explicit, inherited: inherited ?? [], disabled, onChange: (value) => controller.edit(path, value), expanded: open, onExpandedChange: expand, t: permissionText(t) }) });
|
|
6999
7024
|
if (schema.type === "object" && schema.fields !== void 0 && path[0] !== "roleRouting") return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("details", { className: "dsmm-deployment-group", "data-field": name2, open, onToggle: (event) => expand(event.currentTarget.open), children: [
|
|
7000
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { children:
|
|
7025
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("summary", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "dsmm-group-summary", children: [
|
|
7026
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "dsmm-group-summary-label", children: fieldLabel(path, t) }),
|
|
7027
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dsh_client_ui_primitives7.Button, { type: "button", variant: "outline", className: "dsmm-group-summary-action", "data-dsmm-unset": name2, hidden: !open, disabled: disabled || explicit === void 0 && !Object.keys(state.raw).some((key) => key === name2 || key.startsWith(`${name2}.`)), onClick: unsetGroup, children: t("unsetGroup") })
|
|
7028
|
+
] }) }),
|
|
7001
7029
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { children: [
|
|
7002
7030
|
name2 === "permissionControl" && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "dsmm-hint", children: permissionText(t)("configPolicyHint") }),
|
|
7003
7031
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "dsmm-hint", children: t(explicit === void 0 ? "inherit" : "explicit") }),
|
|
7004
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_dsh_client_ui_primitives7.Button, { type: "button", variant: "outline", "data-dsmm-unset": name2, disabled: disabled || explicit === void 0 && !Object.keys(state.raw).some((key) => key === name2 || key.startsWith(`${name2}.`)), onClick: () => {
|
|
7005
|
-
controller.clearRaw(name2);
|
|
7006
|
-
controller.edit(path, void 0);
|
|
7007
|
-
}, children: t("unsetGroup") }),
|
|
7008
7032
|
Object.entries(schema.fields).map(([key, node]) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Field, { schema: node, path: [...path, key], controller, disclosures, t }, key))
|
|
7009
7033
|
] })
|
|
7010
7034
|
] });
|
|
@@ -7034,6 +7058,328 @@ function Field({ schema, path, controller, initiallyOpen = false, disclosures, t
|
|
|
7034
7058
|
// src/client/PermissionsPanel.tsx
|
|
7035
7059
|
var import_react8 = require("react");
|
|
7036
7060
|
var import_dsh_client_ui_primitives8 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
7061
|
+
|
|
7062
|
+
// src/permission-remote.ts
|
|
7063
|
+
function fail3() {
|
|
7064
|
+
throw new TypeError("Invalid permission DTO.");
|
|
7065
|
+
}
|
|
7066
|
+
function text3(value, max = 512) {
|
|
7067
|
+
if (typeof value !== "string" || value.length === 0 || value.length > max || /[\u0000-\u001f\u007f]/u.test(value)) fail3();
|
|
7068
|
+
return value;
|
|
7069
|
+
}
|
|
7070
|
+
function parsePermissionSessionId(value) {
|
|
7071
|
+
return text3(value, 256);
|
|
7072
|
+
}
|
|
7073
|
+
function parseRuntime(value) {
|
|
7074
|
+
const runtime = permissionRuleRow(value, ["savedRevision", "runtimeRevision", "state", "mounted", "restartRequired"]);
|
|
7075
|
+
if (!["synced", "updating", "unsynced"].includes(runtime.state) || typeof runtime.mounted !== "boolean" || typeof runtime.restartRequired !== "boolean") fail3();
|
|
7076
|
+
return { savedRevision: permissionRevision(runtime.savedRevision), runtimeRevision: permissionRevision(runtime.runtimeRevision), state: runtime.state, mounted: runtime.mounted, restartRequired: runtime.restartRequired };
|
|
7077
|
+
}
|
|
7078
|
+
function parseCapabilities(value) {
|
|
7079
|
+
const input = permissionRuleRow(value, ["limits", "runtime", "tools"]);
|
|
7080
|
+
const limits = permissionRuleRow(input.limits, ["outsideReads", "finalInode", "scopedMemory", "webFetch", "webSearchDestinations", "proxyAddressBinding", "shellSockets", "providerAuthMcp"]);
|
|
7081
|
+
if (limits.outsideReads !== "tool-call-boundary" || limits.finalInode !== false || limits.scopedMemory !== "not-provided-by-native-rules" || limits.webFetch !== "native-public-only" || limits.webSearchDestinations !== "unsupported" || limits.proxyAddressBinding !== "native-proxy-dependent" || limits.shellSockets !== "native-executor-dependent" || limits.providerAuthMcp !== "not-covered") fail3();
|
|
7082
|
+
if (!Array.isArray(input.tools) || input.tools.length > 1024) fail3();
|
|
7083
|
+
const tools = [];
|
|
7084
|
+
const names = /* @__PURE__ */ new Set();
|
|
7085
|
+
for (const value2 of input.tools) {
|
|
7086
|
+
const tool = permissionRuleRow(value2, ["name", "kind", "approval", "scopedMemory"]), name2 = text3(tool.name);
|
|
7087
|
+
if (!["read", "glob", "grep", "shell", "webSearch", "webFetch"].includes(tool.kind) || tool.approval !== "native-once" || tool.scopedMemory !== false || names.has(name2)) fail3();
|
|
7088
|
+
names.add(name2);
|
|
7089
|
+
tools.push({ name: name2, kind: tool.kind, approval: "native-once", scopedMemory: false });
|
|
7090
|
+
}
|
|
7091
|
+
return { limits: {
|
|
7092
|
+
outsideReads: "tool-call-boundary",
|
|
7093
|
+
finalInode: false,
|
|
7094
|
+
scopedMemory: "not-provided-by-native-rules",
|
|
7095
|
+
webFetch: "native-public-only",
|
|
7096
|
+
webSearchDestinations: "unsupported",
|
|
7097
|
+
proxyAddressBinding: "native-proxy-dependent",
|
|
7098
|
+
shellSockets: "native-executor-dependent",
|
|
7099
|
+
providerAuthMcp: "not-covered"
|
|
7100
|
+
}, runtime: parseRuntime(input.runtime), tools };
|
|
7101
|
+
}
|
|
7102
|
+
function parsePermissionRulesResult(value) {
|
|
7103
|
+
const input = permissionRuleRow(value, ["snapshot", "runtime"], ["capabilities"]), snapshot4 = permissionRuleRow(input.snapshot, ["revision", "policy"]);
|
|
7104
|
+
return {
|
|
7105
|
+
snapshot: { revision: permissionRevision(snapshot4.revision), policy: resolvePermissionControl(snapshot4.policy) },
|
|
7106
|
+
runtime: parseRuntime(input.runtime),
|
|
7107
|
+
...Object.hasOwn(input, "capabilities") ? { capabilities: parseCapabilities(input.capabilities) } : {}
|
|
7108
|
+
};
|
|
7109
|
+
}
|
|
7110
|
+
var codec2 = (name2, parse3) => ({ mode: "strict", typeSymbol: `@dsmm/dsmm#${name2}`, create: () => ({ parse: parse3 }) });
|
|
7111
|
+
function descriptor2(method, result, request) {
|
|
7112
|
+
return {
|
|
7113
|
+
id: `@dsmm/dsmm-permissions#dsmmPermissions/${method}`,
|
|
7114
|
+
service: "dsmmPermissions",
|
|
7115
|
+
namespace: "dsmmPermissions",
|
|
7116
|
+
method,
|
|
7117
|
+
invocation: { kind: "direct" },
|
|
7118
|
+
parameters: [
|
|
7119
|
+
{ name: "sessionId", wire: "sessionId", source: "json", codec: codec2("PermissionSessionId", parsePermissionSessionId) },
|
|
7120
|
+
...request === void 0 ? [] : [{ name: "request", wire: "request", source: "json", codec: request }]
|
|
7121
|
+
],
|
|
7122
|
+
result
|
|
7123
|
+
};
|
|
7124
|
+
}
|
|
7125
|
+
var PERMISSION_REMOTE = { package: "@dsmm/dsmm-permissions", descriptors: [
|
|
7126
|
+
descriptor2("describeRules", codec2("PermissionRulesResult", parsePermissionRulesResult)),
|
|
7127
|
+
descriptor2("saveRules", codec2("PermissionRulesResult", parsePermissionRulesResult), codec2("PermissionRulesSaveRequest", parsePermissionRulesSave))
|
|
7128
|
+
] };
|
|
7129
|
+
var PERMISSION_HOST = { package: PERMISSION_REMOTE.package, face: "host", schemas: [], model: { services: [], events: [], objects: [] }, invocations: PERMISSION_REMOTE.descriptors };
|
|
7130
|
+
|
|
7131
|
+
// src/client/permission-client.ts
|
|
7132
|
+
var PermissionClientError = class extends Error {
|
|
7133
|
+
constructor(code) {
|
|
7134
|
+
super("Permission operation unavailable.");
|
|
7135
|
+
this.code = code;
|
|
7136
|
+
}
|
|
7137
|
+
};
|
|
7138
|
+
var codes = /* @__PURE__ */ new Set(["not-owned", "stale", "cancelled", "unavailable", "validation", "not-found", "scope-unavailable", "replayed", "denied"]);
|
|
7139
|
+
function permissionClient(connection) {
|
|
7140
|
+
return async (method, args, signal) => {
|
|
7141
|
+
const descriptor4 = PERMISSION_REMOTE.descriptors.find((item) => item.method === method);
|
|
7142
|
+
const payload = {};
|
|
7143
|
+
descriptor4.parameters.forEach((parameter, index) => {
|
|
7144
|
+
payload[parameter.wire] = args[index];
|
|
7145
|
+
});
|
|
7146
|
+
let result;
|
|
7147
|
+
try {
|
|
7148
|
+
result = await connection.rpc.call("/api", `dsmmPermissions/${method}`, { args: payload }, signal);
|
|
7149
|
+
} catch {
|
|
7150
|
+
throw new PermissionClientError(signal.aborted ? "cancelled" : "transport");
|
|
7151
|
+
}
|
|
7152
|
+
if (!result.ok) {
|
|
7153
|
+
const code = Reflect.get(result.error.details, "code");
|
|
7154
|
+
throw new PermissionClientError(result.error.code === "dsmm-permissions/refused" && codes.has(code) ? code : "unavailable");
|
|
7155
|
+
}
|
|
7156
|
+
signal.throwIfAborted();
|
|
7157
|
+
try {
|
|
7158
|
+
if (descriptor4.result.mode !== "strict") throw new Error("Strict permission codec required.");
|
|
7159
|
+
return descriptor4.result.create().parse(result.value);
|
|
7160
|
+
} catch {
|
|
7161
|
+
throw new PermissionClientError("protocol");
|
|
7162
|
+
}
|
|
7163
|
+
};
|
|
7164
|
+
}
|
|
7165
|
+
|
|
7166
|
+
// src/client/permission-controller.ts
|
|
7167
|
+
var draftOf = (policy) => ({ outsideReads: policy.outsideReads, webSearch: { ...policy.webSearch }, webFetch: { ...policy.webFetch }, upsert: [], revoke: [], editor: null });
|
|
7168
|
+
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
7169
|
+
function permissionChanges(view) {
|
|
7170
|
+
const { base, draft: draft2 } = view;
|
|
7171
|
+
if (base === null || draft2 === null) return null;
|
|
7172
|
+
const changes = Object.fromEntries(["outsideReads", "webSearch", "webFetch"].filter((key) => !same(base.policy[key], draft2[key])).map((key) => [key, draft2[key]]));
|
|
7173
|
+
if (Object.keys(changes).length === 0 && draft2.upsert.length === 0 && draft2.revoke.length === 0) return null;
|
|
7174
|
+
return { expectedRevision: base.revision, ...Object.keys(changes).length ? { changes } : {}, ...draft2.upsert.length ? { upsert: draft2.upsert } : {}, ...draft2.revoke.length ? { revoke: draft2.revoke } : {} };
|
|
7175
|
+
}
|
|
7176
|
+
var empty = () => ({
|
|
7177
|
+
generation: 0,
|
|
7178
|
+
sessionId: null,
|
|
7179
|
+
scope: "unknown",
|
|
7180
|
+
connected: false,
|
|
7181
|
+
reading: false,
|
|
7182
|
+
revalidating: false,
|
|
7183
|
+
busy: null,
|
|
7184
|
+
rules: null,
|
|
7185
|
+
display: null,
|
|
7186
|
+
base: null,
|
|
7187
|
+
draft: null,
|
|
7188
|
+
rulesIssue: null,
|
|
7189
|
+
dirty: false,
|
|
7190
|
+
notice: null
|
|
7191
|
+
});
|
|
7192
|
+
var observedRules = (view) => view.rules ?? view.display;
|
|
7193
|
+
var displayUnconfirmed = (view) => view.display !== null && view.rules === null;
|
|
7194
|
+
var PermissionController = class {
|
|
7195
|
+
state = empty();
|
|
7196
|
+
listeners = /* @__PURE__ */ new Set();
|
|
7197
|
+
invoke = null;
|
|
7198
|
+
connection;
|
|
7199
|
+
owner = null;
|
|
7200
|
+
request = new AbortController();
|
|
7201
|
+
requestSequence = 0;
|
|
7202
|
+
timer;
|
|
7203
|
+
watchers = 0;
|
|
7204
|
+
disposed = false;
|
|
7205
|
+
/** A successful read/save exists for the current scope fence; not mutation authority. */
|
|
7206
|
+
observed = false;
|
|
7207
|
+
store = { getSnapshot: () => this.state, subscribe: (listener) => {
|
|
7208
|
+
this.listeners.add(listener);
|
|
7209
|
+
return () => {
|
|
7210
|
+
this.listeners.delete(listener);
|
|
7211
|
+
};
|
|
7212
|
+
} };
|
|
7213
|
+
publish(patch) {
|
|
7214
|
+
if (this.disposed) return;
|
|
7215
|
+
this.state = { ...this.state, ...patch };
|
|
7216
|
+
for (const listener of this.listeners) listener();
|
|
7217
|
+
}
|
|
7218
|
+
cancel() {
|
|
7219
|
+
this.request.abort();
|
|
7220
|
+
this.request = new AbortController();
|
|
7221
|
+
this.requestSequence++;
|
|
7222
|
+
clearTimeout(this.timer);
|
|
7223
|
+
}
|
|
7224
|
+
/** An observed snapshot exists for this fence; background work must stay invisible until it changes what is possible. */
|
|
7225
|
+
trusted() {
|
|
7226
|
+
return this.observed;
|
|
7227
|
+
}
|
|
7228
|
+
fence(preserveDraft, preserveBase = preserveDraft, preserveDisplay = true) {
|
|
7229
|
+
this.cancel();
|
|
7230
|
+
this.observed = false;
|
|
7231
|
+
this.publish({
|
|
7232
|
+
generation: this.state.generation + 1,
|
|
7233
|
+
reading: false,
|
|
7234
|
+
revalidating: false,
|
|
7235
|
+
busy: null,
|
|
7236
|
+
notice: null,
|
|
7237
|
+
rules: null,
|
|
7238
|
+
rulesIssue: null,
|
|
7239
|
+
...preserveDisplay ? {} : { display: null },
|
|
7240
|
+
...preserveDraft ? {} : { draft: null, dirty: false },
|
|
7241
|
+
...preserveBase ? {} : { base: null }
|
|
7242
|
+
});
|
|
7243
|
+
}
|
|
7244
|
+
bindConnection(invoke, generation) {
|
|
7245
|
+
if (this.disposed || this.invoke === invoke && this.connection === generation) return;
|
|
7246
|
+
this.invoke = invoke;
|
|
7247
|
+
this.connection = generation;
|
|
7248
|
+
this.fence(true);
|
|
7249
|
+
this.publish({ connected: invoke !== null });
|
|
7250
|
+
this.schedule(true);
|
|
7251
|
+
}
|
|
7252
|
+
bindScope(sessionId2, owner, scope) {
|
|
7253
|
+
if (this.disposed || this.state.sessionId === sessionId2 && this.owner === owner && this.state.scope === scope) return;
|
|
7254
|
+
const sameSession = sessionId2 !== null && sessionId2 === this.state.sessionId;
|
|
7255
|
+
this.owner = owner;
|
|
7256
|
+
this.fence(sameSession, false, sameSession);
|
|
7257
|
+
this.publish({ sessionId: sessionId2, scope });
|
|
7258
|
+
this.schedule(true);
|
|
7259
|
+
}
|
|
7260
|
+
watch() {
|
|
7261
|
+
this.watchers++;
|
|
7262
|
+
if (this.watchers === 1) this.schedule(true);
|
|
7263
|
+
let active = true;
|
|
7264
|
+
return () => {
|
|
7265
|
+
if (!active) return;
|
|
7266
|
+
active = false;
|
|
7267
|
+
this.watchers--;
|
|
7268
|
+
if (this.watchers === 0) this.fence(true);
|
|
7269
|
+
};
|
|
7270
|
+
}
|
|
7271
|
+
dispose() {
|
|
7272
|
+
if (this.disposed) return;
|
|
7273
|
+
this.fence(false, false, false);
|
|
7274
|
+
this.disposed = true;
|
|
7275
|
+
this.listeners.clear();
|
|
7276
|
+
this.invoke = null;
|
|
7277
|
+
this.owner = null;
|
|
7278
|
+
}
|
|
7279
|
+
live(generation) {
|
|
7280
|
+
return !this.disposed && generation === this.state.generation && this.owner !== null && this.invoke !== null && this.state.scope === "root" && this.state.sessionId !== null;
|
|
7281
|
+
}
|
|
7282
|
+
schedule(immediate = false) {
|
|
7283
|
+
clearTimeout(this.timer);
|
|
7284
|
+
if (this.watchers === 0 || !this.live(this.state.generation)) return;
|
|
7285
|
+
this.timer = setTimeout(() => {
|
|
7286
|
+
void this.revalidate(this.state.generation);
|
|
7287
|
+
}, immediate ? 0 : 1e3);
|
|
7288
|
+
this.timer.unref?.();
|
|
7289
|
+
}
|
|
7290
|
+
issue(error) {
|
|
7291
|
+
return error instanceof PermissionClientError ? error.code : "transport";
|
|
7292
|
+
}
|
|
7293
|
+
synchronized() {
|
|
7294
|
+
const value = this.state.rules;
|
|
7295
|
+
return value !== null && value.runtime.state === "synced" && value.runtime.savedRevision === value.snapshot.revision && value.runtime.runtimeRevision === value.snapshot.revision;
|
|
7296
|
+
}
|
|
7297
|
+
/** A background request in flight never disables editing or saving; only its own save/authority does. */
|
|
7298
|
+
canEdit(generation) {
|
|
7299
|
+
return this.live(generation) && this.state.rulesIssue === null && this.synchronized() && this.state.busy === null;
|
|
7300
|
+
}
|
|
7301
|
+
canSave(generation) {
|
|
7302
|
+
return this.canEdit(generation) && this.state.dirty && this.state.draft?.editor === null;
|
|
7303
|
+
}
|
|
7304
|
+
/** User-triggered refresh: visible busy state on this transaction only. */
|
|
7305
|
+
async refresh(generation, discard = false) {
|
|
7306
|
+
await this.load(generation, discard, false);
|
|
7307
|
+
}
|
|
7308
|
+
/** Watch-driven revalidation. Invisible once a trusted snapshot exists. */
|
|
7309
|
+
async revalidate(generation) {
|
|
7310
|
+
await this.load(generation, false, true);
|
|
7311
|
+
}
|
|
7312
|
+
async load(generation, discard, background) {
|
|
7313
|
+
if (!this.live(generation) || this.state.busy !== null || this.state.reading) return;
|
|
7314
|
+
if (background && this.state.revalidating) return;
|
|
7315
|
+
if (!background && this.state.revalidating) this.cancel();
|
|
7316
|
+
const visible = !background || !this.trusted() && this.state.display === null;
|
|
7317
|
+
const sequence = ++this.requestSequence, signal = this.request.signal, id2 = this.state.sessionId;
|
|
7318
|
+
this.publish(visible ? { reading: true, revalidating: false } : { revalidating: true });
|
|
7319
|
+
try {
|
|
7320
|
+
const value = await this.invoke("describeRules", [id2], signal);
|
|
7321
|
+
if (!this.live(generation) || signal.aborted || sequence !== this.requestSequence) return;
|
|
7322
|
+
this.observed = true;
|
|
7323
|
+
const retain = this.state.dirty && !discard;
|
|
7324
|
+
this.publish({
|
|
7325
|
+
rules: value,
|
|
7326
|
+
display: value,
|
|
7327
|
+
rulesIssue: retain && this.state.base?.revision !== value.snapshot.revision ? "stale" : null,
|
|
7328
|
+
...retain ? {} : { base: value.snapshot, draft: draftOf(value.snapshot.policy), dirty: false }
|
|
7329
|
+
});
|
|
7330
|
+
} catch (error) {
|
|
7331
|
+
if (!this.live(generation) || signal.aborted || sequence !== this.requestSequence) return;
|
|
7332
|
+
this.publish({ rulesIssue: this.issue(error) });
|
|
7333
|
+
} finally {
|
|
7334
|
+
if (this.live(generation) && sequence === this.requestSequence) this.publish({ reading: false, revalidating: false });
|
|
7335
|
+
}
|
|
7336
|
+
this.schedule();
|
|
7337
|
+
}
|
|
7338
|
+
edit(generation, patch) {
|
|
7339
|
+
if (!this.canEdit(generation) || this.state.draft === null) return;
|
|
7340
|
+
const draft2 = { ...this.state.draft, ...patch };
|
|
7341
|
+
this.publish({ draft: draft2, notice: null });
|
|
7342
|
+
this.publish({ dirty: draft2.editor !== null || permissionChanges(this.state) !== null });
|
|
7343
|
+
}
|
|
7344
|
+
stageRule(generation) {
|
|
7345
|
+
const draft2 = this.state.draft, editor = draft2?.editor;
|
|
7346
|
+
if (editor == null || !editor.id || editor.id.length > 256 || editor.id.includes("\0")) return;
|
|
7347
|
+
const match = editor.match;
|
|
7348
|
+
if (match.kind === "outside-read" && !match.path || match.kind === "shell" && (!match.executable || !match.command || !match.workingDirectory)) return;
|
|
7349
|
+
this.edit(generation, { upsert: [...draft2.upsert.filter((row) => row.id !== editor.id), structuredClone(editor)], revoke: draft2.revoke.filter((id2) => id2 !== editor.id), editor: null });
|
|
7350
|
+
}
|
|
7351
|
+
stageRevoke(generation, id2) {
|
|
7352
|
+
const draft2 = this.state.draft;
|
|
7353
|
+
if (draft2 === null || !this.state.base?.policy.rules.some((rule) => rule.id === id2)) return;
|
|
7354
|
+
this.edit(generation, { upsert: draft2.upsert.filter((row) => row.id !== id2), revoke: [.../* @__PURE__ */ new Set([...draft2.revoke, id2])], editor: draft2.editor?.id === id2 ? null : draft2.editor });
|
|
7355
|
+
}
|
|
7356
|
+
begin(busy) {
|
|
7357
|
+
this.cancel();
|
|
7358
|
+
this.publish({ busy, reading: false, revalidating: false, notice: null });
|
|
7359
|
+
return { signal: this.request.signal, id: this.state.sessionId };
|
|
7360
|
+
}
|
|
7361
|
+
async save(generation) {
|
|
7362
|
+
const request = permissionChanges(this.state);
|
|
7363
|
+
if (!this.canSave(generation) || request === null) return;
|
|
7364
|
+
const current = this.begin("save");
|
|
7365
|
+
try {
|
|
7366
|
+
const result = await this.invoke("saveRules", [current.id, request], current.signal);
|
|
7367
|
+
if (this.live(generation)) {
|
|
7368
|
+
this.observed = true;
|
|
7369
|
+
this.publish({ rules: result, display: result, base: result.snapshot, draft: draftOf(result.snapshot.policy), dirty: false, rulesIssue: null, notice: "saved" });
|
|
7370
|
+
}
|
|
7371
|
+
} catch (error) {
|
|
7372
|
+
if (this.live(generation)) this.publish({ rulesIssue: this.issue(error) });
|
|
7373
|
+
} finally {
|
|
7374
|
+
if (this.live(generation)) {
|
|
7375
|
+
this.publish({ busy: null });
|
|
7376
|
+
this.schedule();
|
|
7377
|
+
}
|
|
7378
|
+
}
|
|
7379
|
+
}
|
|
7380
|
+
};
|
|
7381
|
+
|
|
7382
|
+
// src/client/PermissionsPanel.tsx
|
|
7037
7383
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
7038
7384
|
var actions2 = ["inherit", "allow", "ask", "deny"];
|
|
7039
7385
|
var kinds2 = ["outside-read", "shell", "webSearch", "webFetch"];
|
|
@@ -7117,7 +7463,7 @@ function RuleEditor({ controller, state, t }) {
|
|
|
7117
7463
|
] });
|
|
7118
7464
|
}
|
|
7119
7465
|
function RuleRecords({ controller, state, t }) {
|
|
7120
|
-
const records = state
|
|
7466
|
+
const records = observedRules(state)?.snapshot.policy.rules ?? state.base?.policy.rules;
|
|
7121
7467
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "dsmm-structured", children: [
|
|
7122
7468
|
records?.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { children: t("noRules") }),
|
|
7123
7469
|
records?.map((rule) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("fieldset", { children: [
|
|
@@ -7157,7 +7503,7 @@ function RuleRecords({ controller, state, t }) {
|
|
|
7157
7503
|
] });
|
|
7158
7504
|
}
|
|
7159
7505
|
function PermissionCoverage({ state, t }) {
|
|
7160
|
-
const value = state
|
|
7506
|
+
const value = observedRules(state)?.capabilities;
|
|
7161
7507
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "dsmm-structured", "aria-label": t("coverageTitle"), children: [
|
|
7162
7508
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: t("coverageTitle") }),
|
|
7163
7509
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("coverage") }),
|
|
@@ -7207,7 +7553,7 @@ function PermissionCoverage({ state, t }) {
|
|
|
7207
7553
|
] });
|
|
7208
7554
|
}
|
|
7209
7555
|
function PermissionRulesEditor({ controller, state, t }) {
|
|
7210
|
-
const id2 = (0, import_react8.useId)(), draft2 = state.draft, disabled = !controller.canEdit(state.generation), value = state
|
|
7556
|
+
const id2 = (0, import_react8.useId)(), draft2 = state.draft, disabled = !controller.canEdit(state.generation), value = observedRules(state), observedPolicy = value?.snapshot ?? null;
|
|
7211
7557
|
const writable = state.scope === "root" && state.connected;
|
|
7212
7558
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "dsmm-zone", "aria-label": t("rules"), children: [
|
|
7213
7559
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h3", { children: t("rules") }),
|
|
@@ -7215,6 +7561,7 @@ function PermissionRulesEditor({ controller, state, t }) {
|
|
|
7215
7561
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("networkLimit") }),
|
|
7216
7562
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("matchHint") }),
|
|
7217
7563
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Issue, { value: state.rulesIssue, t }),
|
|
7564
|
+
displayUnconfirmed(state) && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("unconfirmedObservation") }),
|
|
7218
7565
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("observedPolicy") }),
|
|
7219
7566
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("dl", { className: "dsmm-child-meta", children: [
|
|
7220
7567
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dt", { children: t("profileOverrideState") }),
|
|
@@ -7227,16 +7574,16 @@ function PermissionRulesEditor({ controller, state, t }) {
|
|
|
7227
7574
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dd", { children: value === null ? t("unknown") : t(value.runtime.mounted ? "on" : "off") })
|
|
7228
7575
|
] }),
|
|
7229
7576
|
value?.runtime.restartRequired && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { children: t("restart") }),
|
|
7230
|
-
disabled && !state.reading && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("rulesUnavailable") }),
|
|
7231
|
-
|
|
7577
|
+
disabled && !state.reading && !displayUnconfirmed(state) && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("rulesUnavailable") }),
|
|
7578
|
+
observedPolicy !== null && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("dl", { className: "dsmm-child-meta", children: [
|
|
7232
7579
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dt", { children: "permissionControl.enabled" }),
|
|
7233
7580
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("dd", { children: [
|
|
7234
|
-
t(
|
|
7581
|
+
t(observedPolicy.policy.enabled ? "on" : "off"),
|
|
7235
7582
|
" · ",
|
|
7236
7583
|
t("coldHint")
|
|
7237
7584
|
] }),
|
|
7238
7585
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dt", { children: "permissionControl.nativeCommands.enabled" }),
|
|
7239
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dd", { children: t(
|
|
7586
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dd", { children: t(observedPolicy.policy.nativeCommands.enabled ? "on" : "off") })
|
|
7240
7587
|
] }),
|
|
7241
7588
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("details", { className: "dsmm-deployment-group", children: [
|
|
7242
7589
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("summary", { children: t("coverageDetails") }),
|
|
@@ -7307,6 +7654,7 @@ function PermissionsPanel({ controller, t, sessionId: sessionId2 }) {
|
|
|
7307
7654
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("h2", { children: t("title") }),
|
|
7308
7655
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(RootState, { state, t }),
|
|
7309
7656
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("nativeApproval") }),
|
|
7657
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-hint", children: t("sandboxScope") }),
|
|
7310
7658
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", children: state.busy !== null ? t("busy") : state.reading ? t("reading") : state.notice === null ? "" : t(state.notice) }),
|
|
7311
7659
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(PermissionRulesEditor, { controller, state, t })
|
|
7312
7660
|
] });
|
|
@@ -7572,65 +7920,65 @@ var ROLE_CONTROL_ERROR_CODES = ["validation", "not-owned", "unavailable", "cance
|
|
|
7572
7920
|
var ROLE_CONTROL_ERROR_FIELDS = ["sessionId", "parentSessionId", "childSessionId", "request", "content", "clientTimeZone"];
|
|
7573
7921
|
|
|
7574
7922
|
// src/role-control-remote.ts
|
|
7575
|
-
function
|
|
7923
|
+
function fail4() {
|
|
7576
7924
|
throw new TypeError("Invalid Deepwork child control DTO.");
|
|
7577
7925
|
}
|
|
7578
7926
|
function json(value, depth2 = 0, active = /* @__PURE__ */ new Set()) {
|
|
7579
|
-
if (depth2 > 24)
|
|
7927
|
+
if (depth2 > 24) fail4();
|
|
7580
7928
|
if (value === null || typeof value === "boolean" || typeof value === "string") return value;
|
|
7581
7929
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
7582
|
-
if (typeof value !== "object" || value === null || active.has(value))
|
|
7930
|
+
if (typeof value !== "object" || value === null || active.has(value)) fail4();
|
|
7583
7931
|
const isArray = Array.isArray(value);
|
|
7584
|
-
if (Object.getPrototypeOf(value) !== (isArray ? Array.prototype : Object.prototype) && (isArray || Object.getPrototypeOf(value) !== null))
|
|
7585
|
-
if (Object.getOwnPropertySymbols(value).length)
|
|
7932
|
+
if (Object.getPrototypeOf(value) !== (isArray ? Array.prototype : Object.prototype) && (isArray || Object.getPrototypeOf(value) !== null)) fail4();
|
|
7933
|
+
if (Object.getOwnPropertySymbols(value).length) fail4();
|
|
7586
7934
|
for (const [key, property2] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
|
|
7587
7935
|
if (isArray && key === "length") continue;
|
|
7588
|
-
if (!Object.hasOwn(property2, "value") || !property2.enumerable || ["__proto__", "prototype", "constructor"].includes(key) || isArray && !/^(0|[1-9][0-9]*)$/u.test(key))
|
|
7936
|
+
if (!Object.hasOwn(property2, "value") || !property2.enumerable || ["__proto__", "prototype", "constructor"].includes(key) || isArray && !/^(0|[1-9][0-9]*)$/u.test(key)) fail4();
|
|
7589
7937
|
}
|
|
7590
|
-
if (isArray && Object.keys(value).length !== value.length)
|
|
7938
|
+
if (isArray && Object.keys(value).length !== value.length) fail4();
|
|
7591
7939
|
active.add(value);
|
|
7592
7940
|
const result = isArray ? value.map((child2) => json(child2, depth2 + 1, active)) : Object.fromEntries(Object.entries(value).map(([key, child2]) => [key, json(child2, depth2 + 1, active)]));
|
|
7593
7941
|
active.delete(value);
|
|
7594
7942
|
return result;
|
|
7595
7943
|
}
|
|
7596
7944
|
function object2(value, required, optional2 = []) {
|
|
7597
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
7945
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) fail4();
|
|
7598
7946
|
const row = value;
|
|
7599
|
-
if (required.some((key) => !Object.hasOwn(row, key)) || Object.keys(row).some((key) => !required.includes(key) && !optional2.includes(key)))
|
|
7947
|
+
if (required.some((key) => !Object.hasOwn(row, key)) || Object.keys(row).some((key) => !required.includes(key) && !optional2.includes(key))) fail4();
|
|
7600
7948
|
return row;
|
|
7601
7949
|
}
|
|
7602
7950
|
function choice(value, choices) {
|
|
7603
|
-
if (!choices.includes(value))
|
|
7951
|
+
if (!choices.includes(value)) fail4();
|
|
7604
7952
|
return value;
|
|
7605
7953
|
}
|
|
7606
|
-
function
|
|
7607
|
-
if (typeof value !== "string" || value.length > max || /[\u0000-\u001f\u007f]/u.test(value) || new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(new TextEncoder().encode(value)) !== value)
|
|
7954
|
+
function text4(value, max) {
|
|
7955
|
+
if (typeof value !== "string" || value.length > max || /[\u0000-\u001f\u007f]/u.test(value) || new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(new TextEncoder().encode(value)) !== value) fail4();
|
|
7608
7956
|
return value;
|
|
7609
7957
|
}
|
|
7610
7958
|
function identity(value) {
|
|
7611
|
-
if (!isNativeSessionId(value))
|
|
7959
|
+
if (!isNativeSessionId(value)) fail4();
|
|
7612
7960
|
return value;
|
|
7613
7961
|
}
|
|
7614
7962
|
function epoch2(value) {
|
|
7615
|
-
if (typeof value !== "string" || !/^[a-f0-9]{64}$/u.test(value))
|
|
7963
|
+
if (typeof value !== "string" || !/^[a-f0-9]{64}$/u.test(value)) fail4();
|
|
7616
7964
|
return value;
|
|
7617
7965
|
}
|
|
7618
7966
|
function array(value, max = 4096) {
|
|
7619
|
-
if (!Array.isArray(value) || value.length > max)
|
|
7967
|
+
if (!Array.isArray(value) || value.length > max) fail4();
|
|
7620
7968
|
return value;
|
|
7621
7969
|
}
|
|
7622
7970
|
function bool(value) {
|
|
7623
|
-
if (typeof value !== "boolean")
|
|
7971
|
+
if (typeof value !== "boolean") fail4();
|
|
7624
7972
|
return value;
|
|
7625
7973
|
}
|
|
7626
7974
|
function depth(value) {
|
|
7627
|
-
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 4096)
|
|
7975
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1 || value > 4096) fail4();
|
|
7628
7976
|
return value;
|
|
7629
7977
|
}
|
|
7630
7978
|
function availability(value) {
|
|
7631
7979
|
const row = object2(value, ["enabled"], ["reason"]);
|
|
7632
7980
|
if (row.enabled === true && !Object.hasOwn(row, "reason")) return { enabled: true };
|
|
7633
|
-
if (row.enabled !== false)
|
|
7981
|
+
if (row.enabled !== false) fail4();
|
|
7634
7982
|
return { enabled: false, reason: choice(row.reason, ROLE_CONTROL_DISABLED_REASONS) };
|
|
7635
7983
|
}
|
|
7636
7984
|
function capabilities(value) {
|
|
@@ -7643,12 +7991,12 @@ function child(value) {
|
|
|
7643
7991
|
const mode = choice(row.mode, ["one-shot", "continuable", "unknown"]);
|
|
7644
7992
|
const prompt = availability(controls.prompt), interrupt = availability(controls.interrupt);
|
|
7645
7993
|
const readonly = bool(row.readonly);
|
|
7646
|
-
if (readonly !== (!prompt.enabled && !interrupt.enabled) || mode !== "continuable" && (prompt.enabled || interrupt.enabled))
|
|
7994
|
+
if (readonly !== (!prompt.enabled && !interrupt.enabled) || mode !== "continuable" && (prompt.enabled || interrupt.enabled)) fail4();
|
|
7647
7995
|
const invocation = Object.hasOwn(row, "invocation") ? parseDsmmInvocationView(row.invocation) : void 0;
|
|
7648
7996
|
const routeComparison = Object.hasOwn(row, "routeComparison") ? parseDsmmRoleRouteComparison(row.routeComparison) : void 0;
|
|
7649
7997
|
const id2 = identity(row.id);
|
|
7650
|
-
if (invocation !== void 0 && (invocation.childId !== id2 || invocation.mode !== mode))
|
|
7651
|
-
if (routeComparison !== void 0 && routeComparison.childId !== id2)
|
|
7998
|
+
if (invocation !== void 0 && (invocation.childId !== id2 || invocation.mode !== mode)) fail4();
|
|
7999
|
+
if (routeComparison !== void 0 && routeComparison.childId !== id2) fail4();
|
|
7652
8000
|
return {
|
|
7653
8001
|
id: id2,
|
|
7654
8002
|
parentSessionId: identity(row.parentSessionId),
|
|
@@ -7656,7 +8004,7 @@ function child(value) {
|
|
|
7656
8004
|
activity: choice(row.activity, ["running", "inactive"]),
|
|
7657
8005
|
readonly,
|
|
7658
8006
|
controls: { prompt, interrupt },
|
|
7659
|
-
...Object.hasOwn(row, "label") ? { label:
|
|
8007
|
+
...Object.hasOwn(row, "label") ? { label: text4(row.label, 120) } : {},
|
|
7660
8008
|
...invocation === void 0 ? {} : { invocation },
|
|
7661
8009
|
...routeComparison === void 0 ? {} : { routeComparison }
|
|
7662
8010
|
};
|
|
@@ -7664,7 +8012,7 @@ function child(value) {
|
|
|
7664
8012
|
function snapshot3(value) {
|
|
7665
8013
|
const row = object2(value, ["sessionId", "admissionEpoch", "children", "capabilities"]);
|
|
7666
8014
|
const sessionId2 = identity(row.sessionId), admissionEpoch = epoch2(row.admissionEpoch), children = array(row.children).map(child);
|
|
7667
|
-
if (children.some((child2) => child2.parentSessionId !== sessionId2))
|
|
8015
|
+
if (children.some((child2) => child2.parentSessionId !== sessionId2)) fail4();
|
|
7668
8016
|
return { sessionId: sessionId2, admissionEpoch, children, capabilities: capabilities(row.capabilities) };
|
|
7669
8017
|
}
|
|
7670
8018
|
function descendants(value) {
|
|
@@ -7675,39 +8023,39 @@ function descendants(value) {
|
|
|
7675
8023
|
if (entry.kind === "child") {
|
|
7676
8024
|
object2(entry, ["kind", "depth", "child", "hasChildren"]);
|
|
7677
8025
|
const projected = child(entry.child);
|
|
7678
|
-
if (entry.depth !== 1 && (projected.controls.prompt.enabled || projected.controls.interrupt.enabled))
|
|
8026
|
+
if (entry.depth !== 1 && (projected.controls.prompt.enabled || projected.controls.interrupt.enabled)) fail4();
|
|
7679
8027
|
return { kind: "child", depth: depth(entry.depth), child: projected, hasChildren: bool(entry.hasChildren) };
|
|
7680
8028
|
}
|
|
7681
8029
|
object2(entry, ["kind", "depth", "id", "parentSessionId", "reason"]);
|
|
7682
|
-
if (entry.kind !== "diagnostic")
|
|
8030
|
+
if (entry.kind !== "diagnostic") fail4();
|
|
7683
8031
|
return { kind: "diagnostic", depth: depth(entry.depth), id: identity(entry.id), parentSessionId: identity(entry.parentSessionId), reason: choice(entry.reason, ["corrupt", "unsupported", "unavailable"]) };
|
|
7684
8032
|
});
|
|
7685
8033
|
for (const entry of entries) {
|
|
7686
8034
|
const parent = entry.kind === "child" ? entry.child.parentSessionId : entry.parentSessionId;
|
|
7687
|
-
if (entry.depth === 1 !== (parent === sessionId2))
|
|
8035
|
+
if (entry.depth === 1 !== (parent === sessionId2)) fail4();
|
|
7688
8036
|
}
|
|
7689
8037
|
return { sessionId: sessionId2, admissionEpoch, descendants: entries };
|
|
7690
8038
|
}
|
|
7691
8039
|
function promptRequest(value) {
|
|
7692
8040
|
const row = object2(value, ["requestId", "parentSessionId", "childSessionId", "mode", "delivery", "content"], ["clientTimeZone"]);
|
|
7693
|
-
if (row.mode !== "continuable")
|
|
8041
|
+
if (row.mode !== "continuable") fail4();
|
|
7694
8042
|
const content2 = array(row.content, Number.MAX_SAFE_INTEGER).map((value2) => {
|
|
7695
8043
|
const part = object2(value2, ["type"], ["text", "mediaType", "data", "name"]);
|
|
7696
8044
|
if (part.type === "text") {
|
|
7697
8045
|
object2(part, ["type", "text"]);
|
|
7698
|
-
if (typeof part.text !== "string")
|
|
8046
|
+
if (typeof part.text !== "string") fail4();
|
|
7699
8047
|
return { type: "text", text: part.text };
|
|
7700
8048
|
}
|
|
7701
8049
|
object2(part, ["type", "mediaType", "data"], ["name"]);
|
|
7702
|
-
if (part.type !== "image" || typeof part.data !== "string")
|
|
8050
|
+
if (part.type !== "image" || typeof part.data !== "string") fail4();
|
|
7703
8051
|
return {
|
|
7704
8052
|
type: "image",
|
|
7705
8053
|
mediaType: choice(part.mediaType, ["image/png", "image/jpeg", "image/webp", "image/gif"]),
|
|
7706
8054
|
data: part.data,
|
|
7707
|
-
...Object.hasOwn(part, "name") ? { name:
|
|
8055
|
+
...Object.hasOwn(part, "name") ? { name: text4(part.name, 256) } : {}
|
|
7708
8056
|
};
|
|
7709
8057
|
});
|
|
7710
|
-
if (content2.length === 0)
|
|
8058
|
+
if (content2.length === 0) fail4();
|
|
7711
8059
|
return {
|
|
7712
8060
|
requestId: identity(row.requestId),
|
|
7713
8061
|
parentSessionId: identity(row.parentSessionId),
|
|
@@ -7715,12 +8063,12 @@ function promptRequest(value) {
|
|
|
7715
8063
|
mode: "continuable",
|
|
7716
8064
|
delivery: choice(row.delivery, ["queue", "steer"]),
|
|
7717
8065
|
content: content2,
|
|
7718
|
-
...Object.hasOwn(row, "clientTimeZone") ? { clientTimeZone:
|
|
8066
|
+
...Object.hasOwn(row, "clientTimeZone") ? { clientTimeZone: text4(row.clientTimeZone, 128) } : {}
|
|
7719
8067
|
};
|
|
7720
8068
|
}
|
|
7721
8069
|
function interruptRequest(value) {
|
|
7722
8070
|
const row = object2(value, ["parentSessionId", "childSessionId", "mode"]);
|
|
7723
|
-
if (row.mode !== "continuable")
|
|
8071
|
+
if (row.mode !== "continuable") fail4();
|
|
7724
8072
|
return { parentSessionId: identity(row.parentSessionId), childSessionId: identity(row.childSessionId), mode: "continuable" };
|
|
7725
8073
|
}
|
|
7726
8074
|
function promptReceipt(value) {
|
|
@@ -7729,7 +8077,7 @@ function promptReceipt(value) {
|
|
|
7729
8077
|
}
|
|
7730
8078
|
function interruptReceipt(value) {
|
|
7731
8079
|
const row = object2(value, ["accepted"]);
|
|
7732
|
-
if (row.accepted !== true)
|
|
8080
|
+
if (row.accepted !== true) fail4();
|
|
7733
8081
|
return { accepted: true };
|
|
7734
8082
|
}
|
|
7735
8083
|
function errorInfo2(value) {
|
|
@@ -7742,348 +8090,61 @@ function errorInfo2(value) {
|
|
|
7742
8090
|
}
|
|
7743
8091
|
var parseRoleControlErrorInfo = (value) => errorInfo2(json(value));
|
|
7744
8092
|
var parseChildSessionSnapshot = (value) => snapshot3(json(value));
|
|
7745
|
-
var parseRoleControlDescendants = (value) => descendants(json(value));
|
|
7746
|
-
var parseRoleControlPromptRequest = (value) => promptRequest(json(value));
|
|
7747
|
-
function
|
|
7748
|
-
return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: (value) => parse3(json(value)) }) };
|
|
7749
|
-
}
|
|
7750
|
-
function descriptor2(method, result, request) {
|
|
7751
|
-
return {
|
|
7752
|
-
id: `@dsmm/dsmm-children#dsmmChildren/${method}`,
|
|
7753
|
-
service: "dsmmChildren",
|
|
7754
|
-
namespace: "dsmmChildren",
|
|
7755
|
-
method,
|
|
7756
|
-
invocation: { kind: "direct" },
|
|
7757
|
-
parameters: [
|
|
7758
|
-
{ name: "sessionId", wire: "sessionId", source: "json", codec: codec2("ChildControlSessionId", identity) },
|
|
7759
|
-
...request === void 0 ? [] : [{ name: "request", wire: "request", source: "json", codec: request }]
|
|
7760
|
-
],
|
|
7761
|
-
result
|
|
7762
|
-
};
|
|
7763
|
-
}
|
|
7764
|
-
var ROLE_CONTROL_REMOTE = { package: "@dsmm/dsmm-children", descriptors: [
|
|
7765
|
-
descriptor2("describe", codec2("ChildSessionSnapshot", snapshot3)),
|
|
7766
|
-
descriptor2("descendants", codec2("RoleControlDescendantsSnapshot", descendants)),
|
|
7767
|
-
descriptor2("prompt", codec2("SubagentPromptReceipt", promptReceipt), codec2("SubagentPromptRequest", promptRequest)),
|
|
7768
|
-
descriptor2("interrupt", codec2("SubagentInterruptReceipt", interruptReceipt), codec2("RoleControlInterruptRequest", interruptRequest))
|
|
7769
|
-
] };
|
|
7770
|
-
var ROLE_CONTROL_HOST = { package: ROLE_CONTROL_REMOTE.package, face: "host", schemas: [], model: { services: [], events: [], objects: [] }, invocations: ROLE_CONTROL_REMOTE.descriptors };
|
|
7771
|
-
|
|
7772
|
-
// src/permission-remote.ts
|
|
7773
|
-
function fail4() {
|
|
7774
|
-
throw new TypeError("Invalid permission DTO.");
|
|
7775
|
-
}
|
|
7776
|
-
function text4(value, max = 512) {
|
|
7777
|
-
if (typeof value !== "string" || value.length === 0 || value.length > max || /[\u0000-\u001f\u007f]/u.test(value)) fail4();
|
|
7778
|
-
return value;
|
|
7779
|
-
}
|
|
7780
|
-
function parsePermissionSessionId(value) {
|
|
7781
|
-
return text4(value, 256);
|
|
7782
|
-
}
|
|
7783
|
-
function parseRuntime(value) {
|
|
7784
|
-
const runtime = permissionRuleRow(value, ["savedRevision", "runtimeRevision", "state", "mounted", "restartRequired"]);
|
|
7785
|
-
if (!["synced", "updating", "unsynced"].includes(runtime.state) || typeof runtime.mounted !== "boolean" || typeof runtime.restartRequired !== "boolean") fail4();
|
|
7786
|
-
return { savedRevision: permissionRevision(runtime.savedRevision), runtimeRevision: permissionRevision(runtime.runtimeRevision), state: runtime.state, mounted: runtime.mounted, restartRequired: runtime.restartRequired };
|
|
7787
|
-
}
|
|
7788
|
-
function parseCapabilities(value) {
|
|
7789
|
-
const input = permissionRuleRow(value, ["limits", "runtime", "tools"]);
|
|
7790
|
-
const limits = permissionRuleRow(input.limits, ["outsideReads", "finalInode", "scopedMemory", "webFetch", "webSearchDestinations", "proxyAddressBinding", "shellSockets", "providerAuthMcp"]);
|
|
7791
|
-
if (limits.outsideReads !== "tool-call-boundary" || limits.finalInode !== false || limits.scopedMemory !== "not-provided-by-native-rules" || limits.webFetch !== "native-public-only" || limits.webSearchDestinations !== "unsupported" || limits.proxyAddressBinding !== "native-proxy-dependent" || limits.shellSockets !== "native-executor-dependent" || limits.providerAuthMcp !== "not-covered") fail4();
|
|
7792
|
-
if (!Array.isArray(input.tools) || input.tools.length > 1024) fail4();
|
|
7793
|
-
const tools = [];
|
|
7794
|
-
const names = /* @__PURE__ */ new Set();
|
|
7795
|
-
for (const value2 of input.tools) {
|
|
7796
|
-
const tool = permissionRuleRow(value2, ["name", "kind", "approval", "scopedMemory"]), name2 = text4(tool.name);
|
|
7797
|
-
if (!["read", "glob", "grep", "shell", "webSearch", "webFetch"].includes(tool.kind) || tool.approval !== "native-once" || tool.scopedMemory !== false || names.has(name2)) fail4();
|
|
7798
|
-
names.add(name2);
|
|
7799
|
-
tools.push({ name: name2, kind: tool.kind, approval: "native-once", scopedMemory: false });
|
|
7800
|
-
}
|
|
7801
|
-
return { limits: {
|
|
7802
|
-
outsideReads: "tool-call-boundary",
|
|
7803
|
-
finalInode: false,
|
|
7804
|
-
scopedMemory: "not-provided-by-native-rules",
|
|
7805
|
-
webFetch: "native-public-only",
|
|
7806
|
-
webSearchDestinations: "unsupported",
|
|
7807
|
-
proxyAddressBinding: "native-proxy-dependent",
|
|
7808
|
-
shellSockets: "native-executor-dependent",
|
|
7809
|
-
providerAuthMcp: "not-covered"
|
|
7810
|
-
}, runtime: parseRuntime(input.runtime), tools };
|
|
7811
|
-
}
|
|
7812
|
-
function parsePermissionRulesResult(value) {
|
|
7813
|
-
const input = permissionRuleRow(value, ["snapshot", "runtime"], ["capabilities"]), snapshot4 = permissionRuleRow(input.snapshot, ["revision", "policy"]);
|
|
7814
|
-
return {
|
|
7815
|
-
snapshot: { revision: permissionRevision(snapshot4.revision), policy: resolvePermissionControl(snapshot4.policy) },
|
|
7816
|
-
runtime: parseRuntime(input.runtime),
|
|
7817
|
-
...Object.hasOwn(input, "capabilities") ? { capabilities: parseCapabilities(input.capabilities) } : {}
|
|
7818
|
-
};
|
|
8093
|
+
var parseRoleControlDescendants = (value) => descendants(json(value));
|
|
8094
|
+
var parseRoleControlPromptRequest = (value) => promptRequest(json(value));
|
|
8095
|
+
function codec3(symbol, parse3) {
|
|
8096
|
+
return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: (value) => parse3(json(value)) }) };
|
|
7819
8097
|
}
|
|
7820
|
-
var codec3 = (name2, parse3) => ({ mode: "strict", typeSymbol: `@dsmm/dsmm#${name2}`, create: () => ({ parse: parse3 }) });
|
|
7821
8098
|
function descriptor3(method, result, request) {
|
|
7822
8099
|
return {
|
|
7823
|
-
id: `@dsmm/dsmm-
|
|
7824
|
-
service: "
|
|
7825
|
-
namespace: "
|
|
8100
|
+
id: `@dsmm/dsmm-children#dsmmChildren/${method}`,
|
|
8101
|
+
service: "dsmmChildren",
|
|
8102
|
+
namespace: "dsmmChildren",
|
|
7826
8103
|
method,
|
|
7827
8104
|
invocation: { kind: "direct" },
|
|
7828
8105
|
parameters: [
|
|
7829
|
-
{ name: "sessionId", wire: "sessionId", source: "json", codec: codec3("
|
|
8106
|
+
{ name: "sessionId", wire: "sessionId", source: "json", codec: codec3("ChildControlSessionId", identity) },
|
|
7830
8107
|
...request === void 0 ? [] : [{ name: "request", wire: "request", source: "json", codec: request }]
|
|
7831
8108
|
],
|
|
7832
8109
|
result
|
|
7833
8110
|
};
|
|
7834
8111
|
}
|
|
7835
|
-
var
|
|
7836
|
-
descriptor3("
|
|
7837
|
-
descriptor3("
|
|
8112
|
+
var ROLE_CONTROL_REMOTE = { package: "@dsmm/dsmm-children", descriptors: [
|
|
8113
|
+
descriptor3("describe", codec3("ChildSessionSnapshot", snapshot3)),
|
|
8114
|
+
descriptor3("descendants", codec3("RoleControlDescendantsSnapshot", descendants)),
|
|
8115
|
+
descriptor3("prompt", codec3("SubagentPromptReceipt", promptReceipt), codec3("SubagentPromptRequest", promptRequest)),
|
|
8116
|
+
descriptor3("interrupt", codec3("SubagentInterruptReceipt", interruptReceipt), codec3("RoleControlInterruptRequest", interruptRequest))
|
|
7838
8117
|
] };
|
|
7839
|
-
var
|
|
8118
|
+
var ROLE_CONTROL_HOST = { package: ROLE_CONTROL_REMOTE.package, face: "host", schemas: [], model: { services: [], events: [], objects: [] }, invocations: ROLE_CONTROL_REMOTE.descriptors };
|
|
7840
8119
|
|
|
7841
|
-
// src/client/permission-
|
|
7842
|
-
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7848
|
-
|
|
7849
|
-
|
|
7850
|
-
return async (method, args, signal) => {
|
|
7851
|
-
const descriptor4 = PERMISSION_REMOTE.descriptors.find((item) => item.method === method);
|
|
7852
|
-
const payload = {};
|
|
7853
|
-
descriptor4.parameters.forEach((parameter, index) => {
|
|
7854
|
-
payload[parameter.wire] = args[index];
|
|
7855
|
-
});
|
|
7856
|
-
let result;
|
|
7857
|
-
try {
|
|
7858
|
-
result = await connection.rpc.call("/api", `dsmmPermissions/${method}`, { args: payload }, signal);
|
|
7859
|
-
} catch {
|
|
7860
|
-
throw new PermissionClientError(signal.aborted ? "cancelled" : "transport");
|
|
7861
|
-
}
|
|
7862
|
-
if (!result.ok) {
|
|
7863
|
-
const code = Reflect.get(result.error.details, "code");
|
|
7864
|
-
throw new PermissionClientError(result.error.code === "dsmm-permissions/refused" && codes.has(code) ? code : "unavailable");
|
|
7865
|
-
}
|
|
7866
|
-
signal.throwIfAborted();
|
|
7867
|
-
try {
|
|
7868
|
-
if (descriptor4.result.mode !== "strict") throw new Error("Strict permission codec required.");
|
|
7869
|
-
return descriptor4.result.create().parse(result.value);
|
|
7870
|
-
} catch {
|
|
7871
|
-
throw new PermissionClientError("protocol");
|
|
8120
|
+
// src/client/permission-session.ts
|
|
8121
|
+
function bindPermissionSession(source, sessions, permissions) {
|
|
8122
|
+
let observed, stop;
|
|
8123
|
+
const update = () => {
|
|
8124
|
+
const id2 = source.getSnapshot().key, binding = id2 === void 0 ? void 0 : sessions.binding(id2);
|
|
8125
|
+
if (binding !== observed) {
|
|
8126
|
+
stop?.();
|
|
8127
|
+
observed = binding;
|
|
8128
|
+
stop = binding?.session.subscribe(update);
|
|
7872
8129
|
}
|
|
8130
|
+
const snapshot4 = binding?.session.getSnapshot(), catalog = sessions.list.getSnapshot(), summary = id2 === void 0 ? void 0 : catalog.byId[id2];
|
|
8131
|
+
const child2 = snapshot4?.subagent != null || summary?.origin === "subagent" || summary?.parentId !== void 0;
|
|
8132
|
+
const root = id2 !== void 0 && binding?.sessionId === id2 && snapshot4?.sessionId === id2 && snapshot4.openState === "open" && !snapshot4.removed && catalog.ids.includes(id2) && summary !== void 0 && !child2;
|
|
8133
|
+
permissions.bindScope(id2 ?? null, binding ?? null, child2 ? "child" : root ? "root" : "unknown");
|
|
8134
|
+
};
|
|
8135
|
+
update();
|
|
8136
|
+
const stopSource = source.subscribe(update), stopCatalog = sessions.list.subscribe(update);
|
|
8137
|
+
let active = true;
|
|
8138
|
+
return () => {
|
|
8139
|
+
if (!active) return;
|
|
8140
|
+
active = false;
|
|
8141
|
+
stopSource();
|
|
8142
|
+
stopCatalog();
|
|
8143
|
+
stop?.();
|
|
8144
|
+
permissions.bindScope(null, null, "unknown");
|
|
7873
8145
|
};
|
|
7874
8146
|
}
|
|
7875
8147
|
|
|
7876
|
-
// src/client/permission-controller.ts
|
|
7877
|
-
var draftOf = (policy) => ({ outsideReads: policy.outsideReads, webSearch: { ...policy.webSearch }, webFetch: { ...policy.webFetch }, upsert: [], revoke: [], editor: null });
|
|
7878
|
-
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
7879
|
-
function permissionChanges(view) {
|
|
7880
|
-
const { base, draft: draft2 } = view;
|
|
7881
|
-
if (base === null || draft2 === null) return null;
|
|
7882
|
-
const changes = Object.fromEntries(["outsideReads", "webSearch", "webFetch"].filter((key) => !same(base.policy[key], draft2[key])).map((key) => [key, draft2[key]]));
|
|
7883
|
-
if (Object.keys(changes).length === 0 && draft2.upsert.length === 0 && draft2.revoke.length === 0) return null;
|
|
7884
|
-
return { expectedRevision: base.revision, ...Object.keys(changes).length ? { changes } : {}, ...draft2.upsert.length ? { upsert: draft2.upsert } : {}, ...draft2.revoke.length ? { revoke: draft2.revoke } : {} };
|
|
7885
|
-
}
|
|
7886
|
-
var empty = () => ({
|
|
7887
|
-
generation: 0,
|
|
7888
|
-
sessionId: null,
|
|
7889
|
-
scope: "unknown",
|
|
7890
|
-
connected: false,
|
|
7891
|
-
reading: false,
|
|
7892
|
-
revalidating: false,
|
|
7893
|
-
busy: null,
|
|
7894
|
-
rules: null,
|
|
7895
|
-
base: null,
|
|
7896
|
-
draft: null,
|
|
7897
|
-
rulesIssue: null,
|
|
7898
|
-
dirty: false,
|
|
7899
|
-
notice: null
|
|
7900
|
-
});
|
|
7901
|
-
var PermissionController = class {
|
|
7902
|
-
state = empty();
|
|
7903
|
-
listeners = /* @__PURE__ */ new Set();
|
|
7904
|
-
invoke = null;
|
|
7905
|
-
connection;
|
|
7906
|
-
owner = null;
|
|
7907
|
-
request = new AbortController();
|
|
7908
|
-
requestSequence = 0;
|
|
7909
|
-
timer;
|
|
7910
|
-
watchers = 0;
|
|
7911
|
-
disposed = false;
|
|
7912
|
-
/** A successful read/save exists for the current scope fence; not mutation authority. */
|
|
7913
|
-
observed = false;
|
|
7914
|
-
store = { getSnapshot: () => this.state, subscribe: (listener) => {
|
|
7915
|
-
this.listeners.add(listener);
|
|
7916
|
-
return () => {
|
|
7917
|
-
this.listeners.delete(listener);
|
|
7918
|
-
};
|
|
7919
|
-
} };
|
|
7920
|
-
publish(patch) {
|
|
7921
|
-
if (this.disposed) return;
|
|
7922
|
-
this.state = { ...this.state, ...patch };
|
|
7923
|
-
for (const listener of this.listeners) listener();
|
|
7924
|
-
}
|
|
7925
|
-
cancel() {
|
|
7926
|
-
this.request.abort();
|
|
7927
|
-
this.request = new AbortController();
|
|
7928
|
-
this.requestSequence++;
|
|
7929
|
-
clearTimeout(this.timer);
|
|
7930
|
-
}
|
|
7931
|
-
/** An observed snapshot exists; background work must stay invisible until it changes what is possible. */
|
|
7932
|
-
trusted() {
|
|
7933
|
-
return this.observed;
|
|
7934
|
-
}
|
|
7935
|
-
fence(preserveDraft, preserveBase = preserveDraft) {
|
|
7936
|
-
this.cancel();
|
|
7937
|
-
this.observed = false;
|
|
7938
|
-
this.publish({
|
|
7939
|
-
generation: this.state.generation + 1,
|
|
7940
|
-
reading: false,
|
|
7941
|
-
revalidating: false,
|
|
7942
|
-
busy: null,
|
|
7943
|
-
notice: null,
|
|
7944
|
-
rules: null,
|
|
7945
|
-
rulesIssue: null,
|
|
7946
|
-
...preserveDraft ? {} : { draft: null, dirty: false },
|
|
7947
|
-
...preserveBase ? {} : { base: null }
|
|
7948
|
-
});
|
|
7949
|
-
}
|
|
7950
|
-
bindConnection(invoke, generation) {
|
|
7951
|
-
if (this.disposed || this.invoke === invoke && this.connection === generation) return;
|
|
7952
|
-
this.invoke = invoke;
|
|
7953
|
-
this.connection = generation;
|
|
7954
|
-
this.fence(true);
|
|
7955
|
-
this.publish({ connected: invoke !== null });
|
|
7956
|
-
this.schedule(true);
|
|
7957
|
-
}
|
|
7958
|
-
bindScope(sessionId2, owner, scope) {
|
|
7959
|
-
if (this.disposed || this.state.sessionId === sessionId2 && this.owner === owner && this.state.scope === scope) return;
|
|
7960
|
-
const sameSession = sessionId2 === this.state.sessionId;
|
|
7961
|
-
this.owner = owner;
|
|
7962
|
-
this.fence(sameSession, false);
|
|
7963
|
-
this.publish({ sessionId: sessionId2, scope });
|
|
7964
|
-
this.schedule(true);
|
|
7965
|
-
}
|
|
7966
|
-
watch() {
|
|
7967
|
-
this.watchers++;
|
|
7968
|
-
if (this.watchers === 1) this.schedule(true);
|
|
7969
|
-
let active = true;
|
|
7970
|
-
return () => {
|
|
7971
|
-
if (!active) return;
|
|
7972
|
-
active = false;
|
|
7973
|
-
this.watchers--;
|
|
7974
|
-
if (this.watchers === 0) this.fence(true);
|
|
7975
|
-
};
|
|
7976
|
-
}
|
|
7977
|
-
dispose() {
|
|
7978
|
-
if (this.disposed) return;
|
|
7979
|
-
this.fence(false);
|
|
7980
|
-
this.disposed = true;
|
|
7981
|
-
this.listeners.clear();
|
|
7982
|
-
this.invoke = null;
|
|
7983
|
-
this.owner = null;
|
|
7984
|
-
}
|
|
7985
|
-
live(generation) {
|
|
7986
|
-
return !this.disposed && generation === this.state.generation && this.owner !== null && this.invoke !== null && this.state.scope === "root" && this.state.sessionId !== null;
|
|
7987
|
-
}
|
|
7988
|
-
schedule(immediate = false) {
|
|
7989
|
-
clearTimeout(this.timer);
|
|
7990
|
-
if (this.watchers === 0 || !this.live(this.state.generation)) return;
|
|
7991
|
-
this.timer = setTimeout(() => {
|
|
7992
|
-
void this.revalidate(this.state.generation);
|
|
7993
|
-
}, immediate ? 0 : 1e3);
|
|
7994
|
-
this.timer.unref?.();
|
|
7995
|
-
}
|
|
7996
|
-
issue(error) {
|
|
7997
|
-
return error instanceof PermissionClientError ? error.code : "transport";
|
|
7998
|
-
}
|
|
7999
|
-
synchronized() {
|
|
8000
|
-
const value = this.state.rules;
|
|
8001
|
-
return value !== null && value.runtime.state === "synced" && value.runtime.savedRevision === value.snapshot.revision && value.runtime.runtimeRevision === value.snapshot.revision;
|
|
8002
|
-
}
|
|
8003
|
-
/** A background request in flight never disables editing or saving; only its own save/authority does. */
|
|
8004
|
-
canEdit(generation) {
|
|
8005
|
-
return this.live(generation) && this.state.rulesIssue === null && this.synchronized() && this.state.busy === null;
|
|
8006
|
-
}
|
|
8007
|
-
canSave(generation) {
|
|
8008
|
-
return this.canEdit(generation) && this.state.dirty && this.state.draft?.editor === null;
|
|
8009
|
-
}
|
|
8010
|
-
/** User-triggered refresh: visible busy state on this transaction only. */
|
|
8011
|
-
async refresh(generation, discard = false) {
|
|
8012
|
-
await this.load(generation, discard, false);
|
|
8013
|
-
}
|
|
8014
|
-
/** Watch-driven revalidation. Invisible once a trusted snapshot exists. */
|
|
8015
|
-
async revalidate(generation) {
|
|
8016
|
-
await this.load(generation, false, true);
|
|
8017
|
-
}
|
|
8018
|
-
async load(generation, discard, background) {
|
|
8019
|
-
if (!this.live(generation) || this.state.busy !== null || this.state.reading) return;
|
|
8020
|
-
if (background && this.state.revalidating) return;
|
|
8021
|
-
if (!background && this.state.revalidating) this.cancel();
|
|
8022
|
-
const visible = !background || !this.trusted();
|
|
8023
|
-
const sequence = ++this.requestSequence, signal = this.request.signal, id2 = this.state.sessionId;
|
|
8024
|
-
this.publish(visible ? { reading: true, revalidating: false } : { revalidating: true });
|
|
8025
|
-
try {
|
|
8026
|
-
const value = await this.invoke("describeRules", [id2], signal);
|
|
8027
|
-
if (!this.live(generation) || signal.aborted || sequence !== this.requestSequence) return;
|
|
8028
|
-
this.observed = true;
|
|
8029
|
-
const retain = this.state.dirty && !discard;
|
|
8030
|
-
this.publish({
|
|
8031
|
-
rules: value,
|
|
8032
|
-
rulesIssue: retain && this.state.base?.revision !== value.snapshot.revision ? "stale" : null,
|
|
8033
|
-
...retain ? {} : { base: value.snapshot, draft: draftOf(value.snapshot.policy), dirty: false }
|
|
8034
|
-
});
|
|
8035
|
-
} catch (error) {
|
|
8036
|
-
if (!this.live(generation) || signal.aborted || sequence !== this.requestSequence) return;
|
|
8037
|
-
this.publish({ rulesIssue: this.issue(error) });
|
|
8038
|
-
} finally {
|
|
8039
|
-
if (this.live(generation) && sequence === this.requestSequence) this.publish({ reading: false, revalidating: false });
|
|
8040
|
-
}
|
|
8041
|
-
this.schedule();
|
|
8042
|
-
}
|
|
8043
|
-
edit(generation, patch) {
|
|
8044
|
-
if (!this.canEdit(generation) || this.state.draft === null) return;
|
|
8045
|
-
const draft2 = { ...this.state.draft, ...patch };
|
|
8046
|
-
this.publish({ draft: draft2, notice: null });
|
|
8047
|
-
this.publish({ dirty: draft2.editor !== null || permissionChanges(this.state) !== null });
|
|
8048
|
-
}
|
|
8049
|
-
stageRule(generation) {
|
|
8050
|
-
const draft2 = this.state.draft, editor = draft2?.editor;
|
|
8051
|
-
if (editor == null || !editor.id || editor.id.length > 256 || editor.id.includes("\0")) return;
|
|
8052
|
-
const match = editor.match;
|
|
8053
|
-
if (match.kind === "outside-read" && !match.path || match.kind === "shell" && (!match.executable || !match.command || !match.workingDirectory)) return;
|
|
8054
|
-
this.edit(generation, { upsert: [...draft2.upsert.filter((row) => row.id !== editor.id), structuredClone(editor)], revoke: draft2.revoke.filter((id2) => id2 !== editor.id), editor: null });
|
|
8055
|
-
}
|
|
8056
|
-
stageRevoke(generation, id2) {
|
|
8057
|
-
const draft2 = this.state.draft;
|
|
8058
|
-
if (draft2 === null || !this.state.base?.policy.rules.some((rule) => rule.id === id2)) return;
|
|
8059
|
-
this.edit(generation, { upsert: draft2.upsert.filter((row) => row.id !== id2), revoke: [.../* @__PURE__ */ new Set([...draft2.revoke, id2])], editor: draft2.editor?.id === id2 ? null : draft2.editor });
|
|
8060
|
-
}
|
|
8061
|
-
begin(busy) {
|
|
8062
|
-
this.cancel();
|
|
8063
|
-
this.publish({ busy, reading: false, revalidating: false, notice: null });
|
|
8064
|
-
return { signal: this.request.signal, id: this.state.sessionId };
|
|
8065
|
-
}
|
|
8066
|
-
async save(generation) {
|
|
8067
|
-
const request = permissionChanges(this.state);
|
|
8068
|
-
if (!this.canSave(generation) || request === null) return;
|
|
8069
|
-
const current = this.begin("save");
|
|
8070
|
-
try {
|
|
8071
|
-
const result = await this.invoke("saveRules", [current.id, request], current.signal);
|
|
8072
|
-
if (this.live(generation)) {
|
|
8073
|
-
this.observed = true;
|
|
8074
|
-
this.publish({ rules: result, base: result.snapshot, draft: draftOf(result.snapshot.policy), dirty: false, rulesIssue: null, notice: "saved" });
|
|
8075
|
-
}
|
|
8076
|
-
} catch (error) {
|
|
8077
|
-
if (this.live(generation)) this.publish({ rulesIssue: this.issue(error) });
|
|
8078
|
-
} finally {
|
|
8079
|
-
if (this.live(generation)) {
|
|
8080
|
-
this.publish({ busy: null });
|
|
8081
|
-
this.schedule();
|
|
8082
|
-
}
|
|
8083
|
-
}
|
|
8084
|
-
}
|
|
8085
|
-
};
|
|
8086
|
-
|
|
8087
8148
|
// src/client/RoleToolView.tsx
|
|
8088
8149
|
var import_dsh_client_ui_primitives10 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
8089
8150
|
|
|
@@ -8959,26 +9020,7 @@ async function apply(ctx) {
|
|
|
8959
9020
|
});
|
|
8960
9021
|
void ctx.inject(["uiSession", "sessions"], (sessionCtx) => {
|
|
8961
9022
|
const source = sessionCtx.uiSession.adapter.current, sessions = sessionCtx.sessions;
|
|
8962
|
-
|
|
8963
|
-
const update = () => {
|
|
8964
|
-
const id2 = source.getSnapshot().key, binding = id2 === void 0 ? void 0 : sessions.binding(id2);
|
|
8965
|
-
if (binding !== observed) {
|
|
8966
|
-
stop?.();
|
|
8967
|
-
observed = binding;
|
|
8968
|
-
stop = binding?.session.subscribe(update);
|
|
8969
|
-
}
|
|
8970
|
-
const snapshot4 = binding?.session.getSnapshot(), catalog = sessions.list.getSnapshot(), summary = id2 === void 0 ? void 0 : catalog.byId[id2];
|
|
8971
|
-
const child2 = snapshot4?.subagent != null || summary?.origin === "subagent" || summary?.parentId !== void 0;
|
|
8972
|
-
const root = id2 !== void 0 && binding?.sessionId === id2 && snapshot4?.sessionId === id2 && snapshot4.openState === "open" && !snapshot4.removed && catalog.ids.includes(id2) && summary !== void 0 && !child2;
|
|
8973
|
-
permissions.bindScope(id2 ?? null, binding ?? null, child2 ? "child" : root ? "root" : "unknown");
|
|
8974
|
-
};
|
|
8975
|
-
update();
|
|
8976
|
-
sessionCtx.effect(() => source.subscribe(update));
|
|
8977
|
-
sessionCtx.effect(() => sessions.list.subscribe(update));
|
|
8978
|
-
sessionCtx.effect(() => () => {
|
|
8979
|
-
stop?.();
|
|
8980
|
-
permissions.bindScope(null, null, "unknown");
|
|
8981
|
-
}, "dsmm: permission native session withdrawal");
|
|
9023
|
+
sessionCtx.effect(() => bindPermissionSession(source, sessions, permissions), "dsmm: permission native session withdrawal");
|
|
8982
9024
|
});
|
|
8983
9025
|
let deployment = null;
|
|
8984
9026
|
let profiles = null;
|