@dsmm/dsmm 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/cordis.patch.yml +9 -0
  2. package/docs/compatibility.md +10 -0
  3. package/docs/releasing.md +25 -65
  4. package/docs/roadmap.md +44 -2
  5. package/lib/client/ChildPermissions.d.ts +43 -0
  6. package/lib/client/ChildPermissions.js +100 -0
  7. package/lib/client/ChildrenPanel.d.ts +4 -1
  8. package/lib/client/ChildrenPanel.js +3 -3
  9. package/lib/client/DeploymentFields.d.ts +6 -2
  10. package/lib/client/DeploymentFields.js +8 -6
  11. package/lib/client/DeploymentPage.d.ts +4 -1
  12. package/lib/client/DeploymentPage.js +5 -4
  13. package/lib/client/HistoryContinuation.d.ts +7 -0
  14. package/lib/client/HistoryContinuation.js +22 -0
  15. package/lib/client/PermissionPanelEntry.d.ts +8 -0
  16. package/lib/client/PermissionPanelEntry.js +11 -0
  17. package/lib/client/PermissionsPanel.d.ts +3 -1
  18. package/lib/client/PermissionsPanel.js +3 -2
  19. package/lib/client/ProfilesSection.js +3 -3
  20. package/lib/client/RoleAvailability.js +1 -1
  21. package/lib/client/SessionProfiles.js +21 -18
  22. package/lib/client/TemporaryPermissions.d.ts +21 -0
  23. package/lib/client/TemporaryPermissions.js +94 -0
  24. package/lib/client/children-locales.d.ts +4 -4
  25. package/lib/client/controller.d.ts +17 -0
  26. package/lib/client/controller.js +101 -18
  27. package/lib/client/deployment-locales.js +26 -26
  28. package/lib/client/history-controller.d.ts +29 -0
  29. package/lib/client/history-controller.js +111 -0
  30. package/lib/client/history-entry.d.ts +11 -0
  31. package/lib/client/history-entry.js +106 -0
  32. package/lib/client/history-locales.d.ts +95 -0
  33. package/lib/client/history-locales.js +41 -0
  34. package/lib/client/index.js +16 -3
  35. package/lib/client/locales.d.ts +6 -0
  36. package/lib/client/locales.js +104 -92
  37. package/lib/client/permission-locales.d.ts +26 -0
  38. package/lib/client/permission-locales.js +55 -35
  39. package/lib/client/temporary-permission-client.d.ts +20 -0
  40. package/lib/client/temporary-permission-client.js +52 -0
  41. package/lib/client/temporary-permission-entry.d.ts +6 -0
  42. package/lib/client/temporary-permission-entry.js +56 -0
  43. package/lib/client.js +3881 -1981
  44. package/lib/history-candidates.d.ts +30 -0
  45. package/lib/history-candidates.js +176 -0
  46. package/lib/history-codec.d.ts +11 -0
  47. package/lib/history-codec.js +102 -0
  48. package/lib/history-contract.d.ts +44 -0
  49. package/lib/history-contract.js +2 -0
  50. package/lib/history-controller.d.ts +42 -0
  51. package/lib/history-controller.js +329 -0
  52. package/lib/history-policy.d.ts +4 -0
  53. package/lib/history-policy.js +8 -0
  54. package/lib/history-remote.d.ts +28 -0
  55. package/lib/history-remote.js +17 -0
  56. package/lib/history-rpc.d.ts +24 -0
  57. package/lib/history-rpc.js +136 -0
  58. package/lib/history-support.d.ts +15 -0
  59. package/lib/history-support.js +21 -0
  60. package/lib/history-types.d.ts +67 -0
  61. package/lib/history-types.js +2 -0
  62. package/lib/index.d.ts +2 -0
  63. package/lib/index.js +24 -6
  64. package/lib/native-admission.d.ts +21 -0
  65. package/lib/native-admission.js +206 -16
  66. package/lib/permission-child-control.d.ts +36 -0
  67. package/lib/permission-child-control.js +164 -0
  68. package/lib/permission-control.d.ts +2 -0
  69. package/lib/permission-control.js +7 -0
  70. package/lib/permission-controller.js +2 -2
  71. package/lib/permission-exec-argv.d.ts +32 -0
  72. package/lib/permission-exec-argv.js +171 -0
  73. package/lib/permission-fs-search.js +2 -1
  74. package/lib/permission-fs.js +2 -1
  75. package/lib/permission-native-rules.js +3 -3
  76. package/lib/permission-temporary-files.d.ts +19 -0
  77. package/lib/permission-temporary-files.js +248 -0
  78. package/lib/permission-temporary-grants.d.ts +106 -0
  79. package/lib/permission-temporary-grants.js +198 -0
  80. package/lib/permission-temporary-install.d.ts +25 -0
  81. package/lib/permission-temporary-install.js +86 -0
  82. package/lib/permission-temporary-remote.d.ts +19 -0
  83. package/lib/permission-temporary-remote.js +75 -0
  84. package/lib/permission-temporary-rpc.d.ts +37 -0
  85. package/lib/permission-temporary-rpc.js +154 -0
  86. package/lib/permission-temporary-types.d.ts +47 -0
  87. package/lib/permission-temporary-types.js +2 -0
  88. package/lib/permission-temporary-web.d.ts +11 -0
  89. package/lib/permission-temporary-web.js +154 -0
  90. package/lib/permission-web.js +2 -1
  91. package/lib/preset-skills.d.ts +1 -1
  92. package/lib/preset-skills.js +2 -2
  93. package/lib/profile-rpc.js +2 -0
  94. package/lib/profile-runtime.d.ts +12 -1
  95. package/lib/profile-runtime.js +122 -10
  96. package/lib/profile-store.d.ts +2 -2
  97. package/lib/profile-store.js +8 -1
  98. package/lib/profile-types.d.ts +1 -0
  99. package/lib/role-invocation.d.ts +1 -1
  100. package/lib/role-invocation.js +2 -2
  101. package/lib/role-subagents.js +16 -3
  102. package/lib/skills.d.ts +1 -0
  103. package/lib/skills.js +5 -1
  104. package/package.json +41 -33
  105. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-gateway@0.2.1-rc.2.patch +13291 -0
  106. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-api-remotes@0.2.1-rc.2.patch +9133 -0
  107. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-client-ui-approval@0.2.1-rc.2.patch +156 -0
  108. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-subagent@0.2.1-rc.2.patch +3546 -0
  109. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-user-approval@0.2.1-rc.2.patch +431 -0
  110. package/patches/dsh-approval-settlement/@deepseek-ai__dsh-web@0.2.1-rc.2.patch +119 -0
  111. package/patches/dsh-approval-settlement/README.md +41 -0
  112. package/patches/dsh-approval-settlement/metadata.json +10 -0
  113. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-loop@0.2.1-rc.2.patch +383 -0
  114. package/patches/dsh-session-activation/@deepseek-ai__dsh-agent-preset-registry@0.2.1-rc.2.patch +55 -0
  115. package/patches/dsh-session-activation/@deepseek-ai__dsh-api-session-controller@0.2.1-rc.2.patch +16673 -0
  116. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-subagent@0.2.1-rc.2.patch +29 -0
  117. package/patches/dsh-session-activation/@deepseek-ai__dsh-client-ui-workspace@0.2.1-rc.2.patch +196 -0
  118. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence-jsonl@0.2.1-rc.2.patch +35 -0
  119. package/patches/dsh-session-activation/@deepseek-ai__dsh-session-persistence@0.2.1-rc.2.patch +40 -0
@@ -0,0 +1,106 @@
1
+ import type { TemporaryPermissionDuration, TemporaryPermissionGrantView } from "./permission-temporary-types.js";
2
+ export interface TemporaryApprovalWinner {
3
+ readonly requestId: string;
4
+ readonly deliveryId?: string;
5
+ readonly answerId?: string;
6
+ readonly candidate: string;
7
+ readonly source: "operator" | "temporary" | "unknown";
8
+ readonly automatic: boolean;
9
+ readonly permit?: string;
10
+ readonly retention?: string;
11
+ }
12
+ export interface TemporaryApprovalReceipt {
13
+ readonly requestId: string;
14
+ readonly generation: string;
15
+ readonly outcome: string;
16
+ readonly auditSeq: number;
17
+ readonly source: TemporaryApprovalWinner["source"];
18
+ readonly winner?: TemporaryApprovalWinner;
19
+ }
20
+ export interface TemporaryApprovalDelivery {
21
+ readonly requestId: string;
22
+ readonly deliveryId: string;
23
+ readonly peer: object;
24
+ readonly request: object;
25
+ readonly signal: AbortSignal;
26
+ }
27
+ export interface TemporaryApprovalRuntime {
28
+ request(request: object, options: {
29
+ opened(id: string): void;
30
+ }): Promise<string>;
31
+ settlement(id: string): TemporaryApprovalReceipt | undefined;
32
+ forgetSettlement(id: string): void;
33
+ }
34
+ export interface TemporaryApprovalGateway {
35
+ approvalDelivery(peer: object, requestId: string, deliveryId: string): TemporaryApprovalDelivery | undefined;
36
+ registerApprovalPermits(verify: (delivery: TemporaryApprovalDelivery, permit: string) => boolean): () => void;
37
+ }
38
+ /** Captured by the actual execution adapter. All object identities are Host-only. */
39
+ export interface TemporaryPermissionExecution {
40
+ readonly token: unknown;
41
+ readonly agent: object;
42
+ readonly owner: object;
43
+ readonly generation: string | number;
44
+ readonly registration: object;
45
+ readonly provider: object;
46
+ readonly sessionId: string;
47
+ readonly tool: string;
48
+ readonly project: string;
49
+ readonly target: string;
50
+ readonly summary: string;
51
+ readonly reusable: boolean;
52
+ readonly signal: AbortSignal;
53
+ readonly sessionSignal: AbortSignal;
54
+ /** Host-owned resolved resource and explicit additional scopes; never accepted from RPC. */
55
+ readonly resource?: object;
56
+ readonly scopes?: readonly TemporaryPermissionScope[];
57
+ /** Integrity must not invalidate a manual same-call approval merely for a config revision. */
58
+ assertIntegrity(): void;
59
+ /** Rechecks deny, policy, provider, effective env and owner for automatic use. */
60
+ assertReusable(): void;
61
+ }
62
+ export interface TemporaryPermissionScope {
63
+ readonly id: string;
64
+ readonly summary: string;
65
+ allows(execution: TemporaryPermissionExecution): boolean;
66
+ }
67
+ /** One Host store; it holds grant authority, never pending UI questions or retry work. */
68
+ export declare class TemporaryPermissionGrants {
69
+ private readonly approval;
70
+ private readonly gateway;
71
+ private readonly now;
72
+ private readonly grants;
73
+ private readonly pending;
74
+ private readonly permits;
75
+ private readonly unregister;
76
+ private retired;
77
+ constructor(approval: TemporaryApprovalRuntime, gateway: TemporaryApprovalGateway, now?: () => number);
78
+ private integrity;
79
+ private active;
80
+ private delivery;
81
+ request(peer: object, requestId: string, deliveryId: string): Readonly<{
82
+ scopes?: {
83
+ id: string;
84
+ summary: string;
85
+ }[] | undefined;
86
+ requestId: string;
87
+ deliveryId: string;
88
+ sessionId: string;
89
+ tool: string;
90
+ summary: string;
91
+ reusable: boolean;
92
+ }>;
93
+ retain(peer: object, requestId: string, deliveryId: string, duration: TemporaryPermissionDuration, scopeId?: string): string;
94
+ permit(peer: object, requestId: string, deliveryId: string): string | null;
95
+ private validatePermit;
96
+ approve(request: object, execution: TemporaryPermissionExecution): Promise<{
97
+ check(): void;
98
+ consume(): void;
99
+ finish(): void;
100
+ }>;
101
+ list(agent: object): readonly TemporaryPermissionGrantView[];
102
+ revoke(agent: object, id: string): readonly TemporaryPermissionGrantView[];
103
+ revokeAgent(agent: object): void;
104
+ dispose(): void;
105
+ }
106
+ //# sourceMappingURL=permission-temporary-grants.d.ts.map
@@ -0,0 +1,198 @@
1
+ import { randomUUID } from "node:crypto";
2
+ const durations = new Set(["once", "session", "15min", "1h"]);
3
+ /** One Host store; it holds grant authority, never pending UI questions or retry work. */
4
+ export class TemporaryPermissionGrants {
5
+ approval;
6
+ gateway;
7
+ now;
8
+ grants = new Map();
9
+ pending = new Map();
10
+ permits = new Map();
11
+ unregister;
12
+ retired = false;
13
+ constructor(approval, gateway, now = () => performance.now()) {
14
+ this.approval = approval;
15
+ this.gateway = gateway;
16
+ this.now = now;
17
+ this.unregister = gateway.registerApprovalPermits((delivery, permit) => this.validatePermit(delivery, permit));
18
+ }
19
+ integrity(execution) {
20
+ if (this.retired || execution.signal.aborted)
21
+ throw new Error("Temporary permission execution ended.");
22
+ execution.assertIntegrity();
23
+ }
24
+ active(grant, execution) {
25
+ if (!grant.active || grant.deadline <= this.now() || grant.execution.sessionSignal.aborted)
26
+ return false;
27
+ const previous = grant.execution;
28
+ return previous.agent === execution.agent && previous.owner === execution.owner && previous.generation === execution.generation
29
+ && previous.registration === execution.registration && previous.provider === execution.provider
30
+ && previous.sessionId === execution.sessionId && previous.tool === execution.tool && previous.project === execution.project
31
+ && (grant.scope ? grant.scope.allows(execution) : previous.target === execution.target);
32
+ }
33
+ delivery(peer, requestId, deliveryId) {
34
+ const binding = this.pending.get(requestId), delivery = this.gateway.approvalDelivery(peer, requestId, deliveryId);
35
+ if (!binding || binding.closed || binding.receipt !== undefined || !delivery || delivery.request !== binding.request || delivery.signal.aborted)
36
+ throw new Error("Approval delivery is not current.");
37
+ this.integrity(binding.execution);
38
+ return { binding, delivery };
39
+ }
40
+ request(peer, requestId, deliveryId) {
41
+ const { binding } = this.delivery(peer, requestId, deliveryId), exec = binding.execution;
42
+ return Object.freeze({ requestId, deliveryId, sessionId: exec.sessionId, tool: exec.tool, summary: exec.summary, reusable: exec.reusable,
43
+ ...(exec.scopes?.length ? { scopes: exec.scopes.map(({ id, summary }) => ({ id, summary })) } : {}) });
44
+ }
45
+ retain(peer, requestId, deliveryId, duration, scopeId = "exact") {
46
+ if (!durations.has(duration))
47
+ throw new TypeError("Invalid permission duration.");
48
+ const { binding, delivery } = this.delivery(peer, requestId, deliveryId);
49
+ const scope = scopeId === "exact" ? undefined : binding.execution.scopes?.find(scope => scope.id === scopeId);
50
+ if (scopeId !== "exact" && !scope)
51
+ throw new Error("Unsupported permission scope.");
52
+ if (duration !== "once" && !binding.execution.reusable)
53
+ throw new Error("This execution supports approval once only.");
54
+ this.list(binding.execution.agent);
55
+ if (duration !== "once" && this.grants.size >= 1024)
56
+ throw new Error("Revoke an existing temporary approval before retaining another.");
57
+ if (binding.intents.size >= 128)
58
+ throw new Error("Too many approval intents for this pending request.");
59
+ const retention = randomUUID();
60
+ binding.intents.set(retention, { delivery, duration, scope });
61
+ return retention;
62
+ }
63
+ permit(peer, requestId, deliveryId) {
64
+ const { binding, delivery } = this.delivery(peer, requestId, deliveryId), execution = binding.execution;
65
+ if (!execution.reusable)
66
+ return null;
67
+ execution.assertReusable();
68
+ for (const grant of this.grants.values()) {
69
+ if (!this.active(grant, execution))
70
+ continue;
71
+ for (const key of binding.permits)
72
+ if (this.permits.get(key)?.delivery === delivery)
73
+ return key;
74
+ const permit = randomUUID();
75
+ this.permits.set(permit, { binding, delivery, grant });
76
+ binding.permits.add(permit);
77
+ return permit;
78
+ }
79
+ return null;
80
+ }
81
+ validatePermit(delivery, key) {
82
+ const permit = this.permits.get(key);
83
+ if (!permit || permit.delivery !== delivery || permit.binding.closed || permit.binding.receipt !== undefined || permit.binding.request !== delivery.request)
84
+ return false;
85
+ try {
86
+ this.integrity(permit.binding.execution);
87
+ permit.binding.execution.assertReusable();
88
+ return !delivery.signal.aborted && this.active(permit.grant, permit.binding.execution);
89
+ }
90
+ catch {
91
+ return false;
92
+ }
93
+ }
94
+ async approve(request, execution) {
95
+ this.integrity(execution);
96
+ let binding;
97
+ const finish = () => {
98
+ if (!binding || binding.closed)
99
+ return;
100
+ binding.closed = true;
101
+ for (const permit of binding.permits)
102
+ this.permits.delete(permit);
103
+ this.pending.delete(binding.id);
104
+ this.approval.forgetSettlement(binding.id);
105
+ };
106
+ try {
107
+ const outcome = await this.approval.request(request, { opened: id => {
108
+ binding = { id, request, execution, intents: new Map(), permits: new Set(), consumed: false, closed: false };
109
+ this.pending.set(id, binding);
110
+ } });
111
+ if (!binding)
112
+ throw new Error("Compatible approval settlement runtime required.");
113
+ this.integrity(execution);
114
+ const receipt = this.approval.settlement(binding.id);
115
+ binding.receipt = receipt;
116
+ if (outcome !== "allowed-once")
117
+ throw new Error("Native approval did not allow this execution.");
118
+ if (!receipt)
119
+ throw new Error("Native approval audit receipt unavailable.");
120
+ const winner = receipt.winner;
121
+ if (receipt.outcome !== outcome || receipt.requestId !== binding.id)
122
+ throw new Error("Native approval receipt mismatch.");
123
+ if (winner?.automatic) {
124
+ if (receipt.source !== "temporary" || winner.source !== "temporary" || !winner.permit
125
+ || !this.permits.has(winner.permit))
126
+ throw new Error("Automatic approval source is not continuous.");
127
+ }
128
+ else if (receipt.source === "operator" && winner?.source === "operator" && winner.deliveryId && winner.retention) {
129
+ const intent = binding.intents.get(winner.retention);
130
+ if (intent && intent.delivery.deliveryId === winner.deliveryId && intent.duration !== "once" && execution.reusable && !intent.delivery.signal.aborted) {
131
+ try {
132
+ execution.assertReusable();
133
+ const id = randomUUID();
134
+ this.grants.set(id, { id, execution, duration: intent.duration, scope: intent.scope, active: true,
135
+ deadline: intent.duration === "session" ? Infinity : this.now() + (intent.duration === "15min" ? 900_000 : 3_600_000) });
136
+ }
137
+ catch { /* A failed retention check does not revoke a native manual same-call decision. */ }
138
+ }
139
+ }
140
+ const checked = binding;
141
+ const check = () => {
142
+ this.integrity(execution);
143
+ if (checked.closed)
144
+ throw new Error("Approval execution ended.");
145
+ if (!winner?.automatic)
146
+ return;
147
+ const permit = winner.permit && this.permits.get(winner.permit);
148
+ if (!permit || permit.binding !== checked || permit.delivery.deliveryId !== winner.deliveryId
149
+ || permit.delivery.signal.aborted || !this.active(permit.grant, execution))
150
+ throw new Error("Temporary permission expired or was revoked.");
151
+ execution.assertReusable();
152
+ if (checked.closed || this.retired || !this.active(permit.grant, execution))
153
+ throw new Error("Temporary permission expired or was revoked.");
154
+ };
155
+ check();
156
+ return Object.freeze({ check, consume() { check(); if (checked.consumed)
157
+ throw new Error("Approval execution already consumed."); checked.consumed = true; }, finish });
158
+ }
159
+ catch (error) {
160
+ finish();
161
+ throw error;
162
+ }
163
+ }
164
+ list(agent) {
165
+ const result = [];
166
+ for (const [id, grant] of this.grants) {
167
+ if (!grant.active || grant.deadline <= this.now() || grant.execution.sessionSignal.aborted) {
168
+ this.grants.delete(id);
169
+ continue;
170
+ }
171
+ if (grant.execution.agent !== agent)
172
+ continue;
173
+ result.push(Object.freeze({ id, sessionId: grant.execution.sessionId, tool: grant.execution.tool, summary: grant.scope?.summary ?? grant.execution.summary,
174
+ duration: grant.duration, ...(grant.deadline === Infinity ? {} : { remainingMs: Math.max(0, grant.deadline - this.now()) }) }));
175
+ }
176
+ return Object.freeze(result);
177
+ }
178
+ revoke(agent, id) {
179
+ const grant = this.grants.get(id);
180
+ if (grant && grant.execution.agent !== agent)
181
+ throw new Error("Grant belongs to another live session.");
182
+ if (grant) {
183
+ grant.active = false;
184
+ this.grants.delete(id);
185
+ }
186
+ return this.list(agent);
187
+ }
188
+ revokeAgent(agent) {
189
+ for (const [id, grant] of this.grants)
190
+ if (grant.execution.agent === agent) {
191
+ grant.active = false;
192
+ this.grants.delete(id);
193
+ }
194
+ }
195
+ dispose() { this.retired = true; for (const grant of this.grants.values())
196
+ grant.active = false; this.grants.clear(); this.permits.clear(); this.pending.clear(); this.unregister(); }
197
+ }
198
+ //# sourceMappingURL=permission-temporary-grants.js.map
@@ -0,0 +1,25 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import type { ToolExecution } from "@deepseek-ai/dsh-tools";
3
+ import type { CorePermissionAuthority } from "./core-permission-authority.js";
4
+ import type { DsmmRolePolicy } from "./role-policy.js";
5
+ import type { PermissionRulesRuntimeSync } from "./permission-rules.js";
6
+ import { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
7
+ import type { ArgvPermissionOptions, ArgvPermissionAuthority } from "./permission-exec-argv.js";
8
+ import { ChildPermissionControl } from "./permission-child-control.js";
9
+ export interface TemporaryPermissionInstallOptions {
10
+ readonly core: CorePermissionAuthority;
11
+ readonly roles: DsmmRolePolicy;
12
+ readonly rules: PermissionRulesRuntimeSync;
13
+ /** Explicit owned argv composition. Omit only when this capability is not installed. */
14
+ readonly argv?: Pick<ArgvPermissionOptions, "programKind" | "environment" | "maxOutputBytes" | "timeoutMs">;
15
+ }
16
+ /** Composition from the real Core/role owners; no boolean ownership or test-provider authority. */
17
+ export declare function temporaryPermissionCapture(options: TemporaryPermissionInstallOptions, exec: Readonly<ToolExecution>): ArgvPermissionAuthority;
18
+ /** Install in the same Host fiber as the Core authority, after the patched Approval/Gateway and rules owners. */
19
+ export declare function installTemporaryPermissions(ctx: Context, options: TemporaryPermissionInstallOptions): {
20
+ grants: TemporaryPermissionGrants;
21
+ rpc: import("./permission-temporary-rpc.js").DsmmTemporaryPermissionsHost;
22
+ children: ChildPermissionControl;
23
+ dispose(): void;
24
+ };
25
+ //# sourceMappingURL=permission-temporary-install.d.ts.map
@@ -0,0 +1,86 @@
1
+ import { PermissionRefusal, permissionOriginal } from "./permission-control.js";
2
+ import { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
3
+ import { installPermissionExecArgv } from "./permission-exec-argv.js";
4
+ import { installTemporaryFilePermissions } from "./permission-temporary-files.js";
5
+ import { installTemporaryWebPermissions } from "./permission-temporary-web.js";
6
+ import { registerTemporaryPermissionRpc } from "./permission-temporary-rpc.js";
7
+ import { ChildPermissionControl } from "./permission-child-control.js";
8
+ import { DSMM_ROLES } from "./roles.js";
9
+ /** Composition from the real Core/role owners; no boolean ownership or test-provider authority. */
10
+ export function temporaryPermissionCapture(options, exec) {
11
+ const current = options.core.authority.current(exec), integrity = options.core.authority.captureIntegrity?.(exec);
12
+ if (!integrity || !integrity.signal || !exec.agent)
13
+ throw new PermissionRefusal("unavailable");
14
+ const snapshot = options.rules.getPolicy();
15
+ const assertIntegrity = () => {
16
+ integrity.assertCurrent();
17
+ options.roles.assertToolExecution(exec);
18
+ const tools = exec.agent.ctx.get("tools");
19
+ if (!tools || options.roles.toolDenial(exec.agent, exec.name, tools, exec))
20
+ throw new PermissionRefusal("denied");
21
+ };
22
+ return { owner: current.owner, generation: current.permissionRevision, sessionSignal: integrity.signal, assertIntegrity,
23
+ assertProgramAllowed() {
24
+ assertIntegrity();
25
+ options.core.authority.assertCurrent(current, exec);
26
+ if (options.rules.getPolicy() !== snapshot || options.rules.status().state !== "synced")
27
+ throw new PermissionRefusal("stale");
28
+ } };
29
+ }
30
+ /** Install in the same Host fiber as the Core authority, after the patched Approval/Gateway and rules owners. */
31
+ export function installTemporaryPermissions(ctx, options) {
32
+ const approval = ctx.get("approval"), gateway = ctx.get("typertGateway");
33
+ if (!options.rules.status().mounted || !approval || !gateway || typeof approval.settlement !== "function" || typeof gateway.registerApprovalPermits !== "function")
34
+ throw new PermissionRefusal("unavailable");
35
+ const grants = new TemporaryPermissionGrants(approval, gateway);
36
+ ctx.effect(() => () => grants.dispose());
37
+ const children = new ChildPermissionControl(ctx, grants, { refresh: () => options.rules.refresh(), capture(parent, child) {
38
+ options.core.assertWritable(parent);
39
+ const structural = child, root = parent;
40
+ options.roles.assertModuleAdmission(structural);
41
+ const identity = options.roles.identity(structural), parentIdentity = options.roles.identity(root);
42
+ const check = () => {
43
+ options.core.assertWritable(parent);
44
+ options.roles.assertModuleAdmission(structural);
45
+ const current = options.roles.identity(structural), currentParent = options.roles.identity(root);
46
+ if (!current.child || current.parent !== parent || current.epoch !== identity.epoch || current.role !== identity.role || current.readOnly !== identity.readOnly
47
+ || currentParent.epoch !== parentIdentity.epoch || currentParent.role !== parentIdentity.role)
48
+ throw new PermissionRefusal("stale");
49
+ };
50
+ check();
51
+ return { check, role: identity.role, readOnly: identity.readOnly === true || DSMM_ROLES.find(role => role.id === identity.role)?.access === "read-only" };
52
+ } });
53
+ const capture = (exec) => {
54
+ const nativeApproval = exec.agent?.ctx.get("approval");
55
+ if (!nativeApproval || permissionOriginal(nativeApproval) !== permissionOriginal(approval))
56
+ throw new PermissionRefusal("unavailable");
57
+ const authority = temporaryPermissionCapture(options, exec);
58
+ return { ...authority, assertRetentionAllowed() {
59
+ if (!exec.agent || !ctx.get("agents")?.roots().includes(exec.agent) || exec.agent.session.header.origin === "subagent")
60
+ children.assertEnabled(exec.agent);
61
+ } };
62
+ };
63
+ const files = installTemporaryFilePermissions(ctx, { grants, capture, refresh: () => options.rules.refresh() });
64
+ const web = installTemporaryWebPermissions(ctx, { grants, capture, refresh: () => options.rules.refresh() });
65
+ const argv = options.argv && installPermissionExecArgv(ctx, { ...options.argv, grants, capture(exec) {
66
+ const authority = capture(exec);
67
+ return { ...authority, assertProgramAllowed() {
68
+ authority.assertProgramAllowed();
69
+ const { policy } = options.rules.getPolicy();
70
+ // Arbitrary argv cannot prove shell-rule equivalence or confined file reads.
71
+ if (policy.outsideReads === "deny" || policy.rules.some(rule => !rule.revoked && rule.action === "deny"
72
+ && (rule.match.kind === "shell" || rule.match.kind === "outside-read")))
73
+ throw new PermissionRefusal("unavailable");
74
+ } };
75
+ } });
76
+ const argvDefinition = argv && ctx.tools.get("dsmm_exec_argv");
77
+ const refreshArgv = argvDefinition && ctx.on("tools/pre-execute", async (exec, next) => {
78
+ if (ctx.tools.get(exec.name, exec.agent) === argvDefinition)
79
+ await options.rules.refresh();
80
+ return next();
81
+ }, { prepend: true, global: true });
82
+ const rpc = registerTemporaryPermissionRpc(ctx, grants, { children });
83
+ ctx.on("agent/disposed", ({ agent }) => grants.revokeAgent(agent), { global: true });
84
+ return { grants, rpc, children, dispose() { children.dispose(); refreshArgv?.(); argv?.(); web(); files(); grants.dispose(); } };
85
+ }
86
+ //# sourceMappingURL=permission-temporary-install.js.map
@@ -0,0 +1,19 @@
1
+ import type { TypertRemoteContribution } from "@deepseek-ai/dsh-typert-protocol";
2
+ import type { TypertContribution } from "@deepseek-ai/dsh-typert-registry";
3
+ import type { ChildPermissionView, TemporaryPermissionDelivery, TemporaryPermissionDuration, TemporaryPermissionGrantView, TemporaryPermissionRequestView } from "./permission-temporary-types.js";
4
+ export declare function parseTemporaryId(value: unknown): string;
5
+ export declare function parseTemporaryDuration(value: unknown): TemporaryPermissionDuration;
6
+ export declare function parseTemporaryDelivery(value: unknown): TemporaryPermissionDelivery;
7
+ export declare function parseTemporaryGrants(value: unknown): readonly TemporaryPermissionGrantView[];
8
+ export declare function parseTemporaryRequest(value: unknown): TemporaryPermissionRequestView;
9
+ export declare function parseChildPermission(value: unknown): ChildPermissionView;
10
+ export declare const TEMPORARY_PERMISSION_REMOTE: TypertRemoteContribution;
11
+ export declare const TEMPORARY_PERMISSION_HOST: TypertContribution;
12
+ declare module "@deepseek-ai/dsh-typert-protocol/types" {
13
+ interface RemoteErrorDetailsMap {
14
+ "dsmm-temporary-permissions/refused": {
15
+ code: string;
16
+ };
17
+ }
18
+ }
19
+ //# sourceMappingURL=permission-temporary-remote.d.ts.map
@@ -0,0 +1,75 @@
1
+ function row(value, required, optional = []) {
2
+ if (!value || typeof value !== "object" || Array.isArray(value) || required.some(key => !Object.hasOwn(value, key))
3
+ || Object.keys(value).some(key => !required.includes(key) && !optional.includes(key)))
4
+ throw new TypeError("Invalid temporary permission DTO.");
5
+ return value;
6
+ }
7
+ export function parseTemporaryId(value) {
8
+ if (typeof value !== "string" || !value.length || value.length > 512 || /[\u0000-\u001f]/u.test(value))
9
+ throw new TypeError("Invalid temporary permission identity.");
10
+ return value;
11
+ }
12
+ export function parseTemporaryDuration(value) {
13
+ if (value !== "once" && value !== "session" && value !== "15min" && value !== "1h")
14
+ throw new TypeError("Invalid duration.");
15
+ return value;
16
+ }
17
+ export function parseTemporaryDelivery(value) {
18
+ const input = row(value, ["requestId", "deliveryId"]);
19
+ return { requestId: parseTemporaryId(input.requestId), deliveryId: parseTemporaryId(input.deliveryId) };
20
+ }
21
+ function summary(value) {
22
+ if (typeof value !== "string" || value.length > 65_536)
23
+ throw new TypeError("Invalid summary.");
24
+ return value;
25
+ }
26
+ export function parseTemporaryGrants(value) {
27
+ if (!Array.isArray(value) || value.length > 1024)
28
+ throw new TypeError("Invalid grants.");
29
+ return value.map(item => {
30
+ const input = row(item, ["id", "sessionId", "tool", "summary", "duration"], ["remainingMs"]), duration = parseTemporaryDuration(input.duration);
31
+ if (duration === "once" || input.remainingMs !== undefined && (typeof input.remainingMs !== "number" || !Number.isFinite(input.remainingMs) || input.remainingMs < 0))
32
+ throw new TypeError("Invalid grant lifetime.");
33
+ return { id: parseTemporaryId(input.id), sessionId: parseTemporaryId(input.sessionId), tool: parseTemporaryId(input.tool), summary: summary(input.summary), duration,
34
+ ...(typeof input.remainingMs === "number" ? { remainingMs: input.remainingMs } : {}) };
35
+ });
36
+ }
37
+ export function parseTemporaryRequest(value) {
38
+ const input = row(value, ["requestId", "deliveryId", "sessionId", "tool", "summary", "reusable"], ["scopes"]);
39
+ if (typeof input.reusable !== "boolean")
40
+ throw new TypeError("Invalid request capability.");
41
+ let scopes;
42
+ if (input.scopes !== undefined) {
43
+ if (!Array.isArray(input.scopes) || input.scopes.length > 4)
44
+ throw new TypeError("Invalid scopes.");
45
+ scopes = input.scopes.map(value => { const scope = row(value, ["id", "summary"]); return { id: parseTemporaryId(scope.id), summary: summary(scope.summary) }; });
46
+ }
47
+ return { requestId: parseTemporaryId(input.requestId), deliveryId: parseTemporaryId(input.deliveryId), sessionId: parseTemporaryId(input.sessionId),
48
+ tool: parseTemporaryId(input.tool), summary: summary(input.summary), reusable: input.reusable, ...(scopes ? { scopes } : {}) };
49
+ }
50
+ const codec = (name, parse) => ({ mode: "strict", typeSymbol: `@dsmm/dsmm#Temporary${name}`, create: () => ({ parse }) });
51
+ export function parseChildPermission(value) {
52
+ const input = row(value, ["parentSessionId", "childSessionId", "project", "state", "canEnable", "canRevoke"], ["role", "readOnly"]);
53
+ const state = input.state;
54
+ if (state !== "disabled" && state !== "enabled" && state !== "unavailable" || typeof input.canEnable !== "boolean" || typeof input.canRevoke !== "boolean"
55
+ || input.readOnly !== undefined && typeof input.readOnly !== "boolean")
56
+ throw new TypeError("Invalid child permission state.");
57
+ return { parentSessionId: parseTemporaryId(input.parentSessionId), childSessionId: parseTemporaryId(input.childSessionId), project: summary(input.project),
58
+ state, canEnable: input.canEnable, canRevoke: input.canRevoke,
59
+ ...(input.role === undefined ? {} : { role: parseTemporaryId(input.role) }), ...(typeof input.readOnly === "boolean" ? { readOnly: input.readOnly } : {}) };
60
+ }
61
+ const id = codec("Id", parseTemporaryId), delivery = codec("Delivery", parseTemporaryDelivery);
62
+ const grants = codec("Grants", parseTemporaryGrants), request = codec("Request", parseTemporaryRequest);
63
+ function descriptor(method, fields, result) {
64
+ return { id: `@dsmm/dsmm-temporary-permissions#dsmmTemporaryPermissions/${method}`, service: "dsmmTemporaryPermissions", namespace: "dsmmTemporaryPermissions", method,
65
+ invocation: { kind: "direct" }, parameters: [["sessionId", id], ...fields].map(([name, codec]) => ({ name, wire: name, source: "json", codec })), result };
66
+ }
67
+ export const TEMPORARY_PERMISSION_REMOTE = { package: "@dsmm/dsmm-temporary-permissions", descriptors: [
68
+ descriptor("describe", [], grants), descriptor("request", [["delivery", delivery]], request),
69
+ descriptor("retain", [["delivery", delivery], ["duration", codec("Duration", parseTemporaryDuration)], ["scope", codec("Scope", value => value === undefined ? "exact" : parseTemporaryId(value))]], id),
70
+ descriptor("permit", [["delivery", delivery]], codec("Permit", value => value === null ? null : parseTemporaryId(value))),
71
+ descriptor("revoke", [["grantId", id]], grants),
72
+ ...["child", "enableChild", "revokeChild"].map(method => descriptor(method, [["childSessionId", id]], codec("Child", parseChildPermission))),
73
+ ] };
74
+ export const TEMPORARY_PERMISSION_HOST = { package: TEMPORARY_PERMISSION_REMOTE.package, face: "host", schemas: [], model: { services: [], events: [], objects: [] }, invocations: TEMPORARY_PERMISSION_REMOTE.descriptors };
75
+ //# sourceMappingURL=permission-temporary-remote.js.map
@@ -0,0 +1,37 @@
1
+ import type { Context } from "@deepseek-ai/cordis";
2
+ import { TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
3
+ import type { Agent } from "@deepseek-ai/dsh-agent";
4
+ import type { TemporaryPermissionGrants } from "./permission-temporary-grants.js";
5
+ import type { TemporaryPermissionDelivery, TemporaryPermissionDuration } from "./permission-temporary-types.js";
6
+ import type { ChildPermissionControl } from "./permission-child-control.js";
7
+ /** Child access is an explicit current operator capability, never inferred from lineage strings. */
8
+ export interface TemporaryPermissionRpcOptions {
9
+ readonly children?: ChildPermissionControl;
10
+ authorizeChild?(peer: object, child: Agent): {
11
+ assertCurrent(): void;
12
+ };
13
+ }
14
+ export declare class DsmmTemporaryPermissionsHost extends TypertRemoteService {
15
+ private readonly grants;
16
+ private readonly options;
17
+ private readonly lifetime;
18
+ constructor(ctx: Context, grants: TemporaryPermissionGrants, options: TemporaryPermissionRpcOptions);
19
+ private invoke;
20
+ private delivery;
21
+ describe(sessionId: string): readonly import("./permission-temporary-types.js").TemporaryPermissionGrantView[];
22
+ request(sessionId: string, delivery: TemporaryPermissionDelivery): unknown;
23
+ retain(sessionId: string, delivery: TemporaryPermissionDelivery, duration: TemporaryPermissionDuration, scope?: string): unknown;
24
+ permit(sessionId: string, delivery: TemporaryPermissionDelivery): unknown;
25
+ revoke(sessionId: string, grantId: string): readonly import("./permission-temporary-types.js").TemporaryPermissionGrantView[];
26
+ private childOperation;
27
+ child(sessionId: string, childSessionId: string): Promise<import("./permission-temporary-types.js").ChildPermissionView>;
28
+ enableChild(sessionId: string, childSessionId: string): Promise<import("./permission-temporary-types.js").ChildPermissionView>;
29
+ revokeChild(sessionId: string, childSessionId: string): Promise<import("./permission-temporary-types.js").ChildPermissionView>;
30
+ }
31
+ declare module "@deepseek-ai/cordis" {
32
+ interface Context {
33
+ dsmmTemporaryPermissions: DsmmTemporaryPermissionsHost;
34
+ }
35
+ }
36
+ export declare function registerTemporaryPermissionRpc(ctx: Context, grants: TemporaryPermissionGrants, options?: TemporaryPermissionRpcOptions): DsmmTemporaryPermissionsHost;
37
+ //# sourceMappingURL=permission-temporary-rpc.d.ts.map