@xmoon76/dsh-pi-tui 0.5.8 → 0.5.9

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 (77) hide show
  1. package/README.en.md +61 -25
  2. package/README.md +61 -25
  3. package/cordis.patch.yml +13 -0
  4. package/dist/acp-stdio.mjs +151 -0
  5. package/dist/{bootstrap-CMIjGyuk.mjs → bootstrap-CVyHGQDX.mjs} +21901 -6575
  6. package/dist/browser-CDUSHIIr.mjs +76 -0
  7. package/dist/builtins.mjs +2 -2
  8. package/dist/{client-bootstrap-BjGPc-DM.mjs → client-bootstrap-4UoeVIHE.mjs} +2488 -2734
  9. package/dist/client-runtime-BHBlVUf5.mjs +1376 -0
  10. package/dist/{daemon-launcher-Dult7Jxv.mjs → daemon-launcher-DxIgjBHW.mjs} +1549 -172
  11. package/dist/daemon-launcher.d.mts +85 -14
  12. package/dist/daemon-launcher.mjs +2 -2
  13. package/dist/{local-profile-daemon-admin-BmQSdzT0.mjs → diagnostics-Db5iVcuJ.mjs} +3 -90
  14. package/dist/{entry-control-DjNsE3I0.mjs → entry-control-BDLZgg4m.mjs} +1 -1
  15. package/dist/{extensions-B4uLpSTv.mjs → extensions-Dx7ncPNA.mjs} +1 -1
  16. package/dist/extensions.mjs +1 -1
  17. package/dist/handoff-BjoEy3f8.mjs +106 -0
  18. package/dist/history-search-limits-Cx2UvRC2.mjs +16 -0
  19. package/dist/history-search-remote-BHuoellG.mjs +113 -0
  20. package/dist/history-search-remote-BzXdvrxk.mjs +26 -0
  21. package/dist/history-search-seat-BcHJTpeB.mjs +639 -0
  22. package/dist/history-search-seat-rZcq0XV6.mjs +639 -0
  23. package/dist/{host-bootstrap-MVxks641.mjs → host-bootstrap-BfnufpnW.mjs} +37 -72
  24. package/dist/{host-foundation-probe-DMNTmNrH.mjs → host-foundation-probe-DlD8-N_Q.mjs} +2 -2
  25. package/dist/host-runtime.mjs +5611 -290
  26. package/dist/index.d.mts +13 -6
  27. package/dist/index.mjs +22334 -6695
  28. package/dist/installed-dsh-BjUiJSwR.mjs +142 -0
  29. package/dist/interaction-port-D1Yv9zgu.mjs +45 -0
  30. package/dist/local-acp-control-CC5z4Xbq.mjs +304 -0
  31. package/dist/local-acp-endpoint-D1jYdJdv.mjs +41 -0
  32. package/dist/local-acp-listener-Cmgb5M0H.mjs +9493 -0
  33. package/dist/local-acp-status-B_25Q6kU.mjs +101 -0
  34. package/dist/local-client.mjs +292 -63
  35. package/dist/local-daemon-control-BFJAC8Kg.mjs +2199 -0
  36. package/dist/local-daemon-control-Bm3imctD.mjs +2101 -0
  37. package/dist/{local-discovery-uOBfFq5j.mjs → local-discovery-BMhaGIiJ.mjs} +254 -544
  38. package/dist/{local-discovery-egN4_gsQ.mjs → local-discovery-Ba7_-NNC.mjs} +1 -1
  39. package/dist/{local-discovery-DOSsCh9q.mjs → local-discovery-QSbFpjK2.mjs} +301 -544
  40. package/dist/local-host.mjs +952 -501
  41. package/dist/local-profile-daemon-admin-otpm69R6.mjs +469 -0
  42. package/dist/{local-scope-DamiMqPd.mjs → local-scope-5DEKA_lW.mjs} +1023 -96
  43. package/dist/{local-transport-Iwo0mtu3.mjs → local-transport-DeWmdZ5E.mjs} +14 -3
  44. package/dist/{local-web-control-DMrjwCkl.mjs → local-web-control-Dny93N-r.mjs} +10 -7
  45. package/dist/{local-workspace-object-D06GL0UO.mjs → local-workspace-object-D0RVQt8U.mjs} +33 -9
  46. package/dist/model-selection-CYlqg2DV.mjs +83 -0
  47. package/dist/native-client-domains-Dg4srzYt.mjs +2 -0
  48. package/dist/native-client.d.mts +735 -0
  49. package/dist/native-client.mjs +3534 -0
  50. package/dist/{open-CmOBxSjN.mjs → open-QQva8-ar.mjs} +24 -20
  51. package/dist/{pi-tui-remote-contribution-Do8ECrUy.mjs → pi-tui-remote-contribution-565wiLWp.mjs} +741 -150
  52. package/dist/preferences.mjs +1 -1
  53. package/dist/{profile-preferences-migration-CThz4rHH.mjs → profile-preferences-migration-CNOWIdnr.mjs} +1 -1
  54. package/dist/{profile-preferences-migration-BfUGdPZx.mjs → profile-preferences-migration-IrnXcJWK.mjs} +10 -8
  55. package/dist/{prompt-sections-DXmjB58H.mjs → prompt-sections-Bi-9_Gr_.mjs} +28 -10
  56. package/dist/{prompt-sections-DUKmWb8g.mjs → prompt-sections-DFS1dqsY.mjs} +342 -56
  57. package/dist/{dist-BFgC-5tL.mjs → recall-scope-9Nuoto_i.mjs} +353 -1
  58. package/dist/rolldown-runtime-8H4AJuhK.mjs +14 -0
  59. package/dist/schema-CCLvDa7Q.mjs +177 -0
  60. package/dist/{schema-qE_P09zJ.mjs → schema-t97l3aK8.mjs} +56 -3
  61. package/dist/{session-C6tSs86s.mjs → session-Cs8iLCEx.mjs} +784 -342
  62. package/dist/{session-CstInGIA.mjs → session-EBRZF6Ow.mjs} +783 -341
  63. package/dist/session-create-facts-CkfG5DpQ.mjs +20 -0
  64. package/dist/{startup-CarQxWwi.d.mts → startup-Dti3Udne.d.mts} +30 -3
  65. package/dist/{startup-EG5UqIcd.mjs → startup-UtFQSDe_.mjs} +90 -15
  66. package/dist/startup.d.mts +2 -2
  67. package/dist/startup.mjs +1 -1
  68. package/dist/task-read-remote-DRtkXDrZ.mjs +1083 -0
  69. package/dist/{terminal-progress-source-CpfpQO_h.mjs → terminal-progress-source-VsczdXA-.mjs} +610 -332
  70. package/dist/{transcript-view-CuJYWkhp.mjs → transcript-view-B6vCnukn.mjs} +2096 -977
  71. package/dist/{transcript-view-C1YtJ49Y.mjs → transcript-view-DSSdE2vK.mjs} +2078 -651
  72. package/dist/write-failure-xNKczXH7.mjs +189 -0
  73. package/package.json +20 -3
  74. package/dist/local-acp-listener-B65J0Bx4.mjs +0 -3115
  75. package/dist/local-daemon-control-C14q9KnD.mjs +0 -1588
  76. package/dist/local-daemon-control-TCnERL7n.mjs +0 -1424
  77. package/dist/preset-BcWqOtY7.mjs +0 -46
@@ -0,0 +1,1376 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-8H4AJuhK.mjs";
2
+ import { t as mergeCause } from "./dispose-cause-CNFuUnjR.mjs";
3
+ import { t as PI_TUI_CLIENT_CONTRIBUTION } from "./pi-tui-remote-contribution-565wiLWp.mjs";
4
+ import { createRequire } from "node:module";
5
+ import { realpathSync } from "node:fs";
6
+ import { pathToFileURL } from "node:url";
7
+ import "@deepseek-ai/cordis";
8
+ import commandsRemote from "@deepseek-ai/dsh-commands/remote";
9
+ import subagentsRemote from "@deepseek-ai/dsh-subagent/remote";
10
+ import agentPresetsRemote from "@deepseek-ai/dsh-agent-preset-registry/remote";
11
+ import pluginManagerRemote from "@deepseek-ai/dsh-plugin-manager/remote";
12
+ import mcpManagerRemote from "@deepseek-ai/dsh-mcp-manager/remote";
13
+ import permissionPresetsRemote from "@deepseek-ai/dsh-permission-presets/remote";
14
+ import llmRemote from "@deepseek-ai/dsh-llm/remote";
15
+ import sessionRemote from "@deepseek-ai/dsh-api-session-controller/remote";
16
+ import jobRemote from "@deepseek-ai/dsh-api-job-controller/remote";
17
+ import settingsRemote from "@deepseek-ai/dsh-api-settings-controller/remote";
18
+ import accountRemote from "@deepseek-ai/dsh-deepseek-account/remote";
19
+ import userQuestionsRemote from "@deepseek-ai/dsh-user-questions/remote";
20
+ import fileUploadsRemote from "@deepseek-ai/dsh-client-file-upload/remote";
21
+ import workspaceFilesRemote from "@deepseek-ai/dsh-api-workspace-files/remote";
22
+ import workspaceRemote from "@deepseek-ai/dsh-api-workspace-controller/remote";
23
+ import scheduleRemote from "@deepseek-ai/dsh-schedule/remote";
24
+ import agentTeamsRemote from "@deepseek-ai/dsh-agent-team/remote";
25
+ import cuaRemote from "@deepseek-ai/dsh-cua/remote";
26
+ //#region node_modules/.pnpm/zustand@4.5.7_immer@10.2.0_react@18.3.1/node_modules/zustand/esm/vanilla.mjs
27
+ const createStoreImpl = (createState) => {
28
+ let state;
29
+ const listeners = /* @__PURE__ */ new Set();
30
+ const setState = (partial, replace) => {
31
+ const nextState = typeof partial === "function" ? partial(state) : partial;
32
+ if (!Object.is(nextState, state)) {
33
+ const previousState = state;
34
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
35
+ listeners.forEach((listener) => listener(state, previousState));
36
+ }
37
+ };
38
+ const getState = () => state;
39
+ const getInitialState = () => initialState;
40
+ const subscribe = (listener) => {
41
+ listeners.add(listener);
42
+ return () => listeners.delete(listener);
43
+ };
44
+ const destroy = () => {
45
+ if ((import.meta.env ? import.meta.env.MODE : void 0) !== "production") console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected.");
46
+ listeners.clear();
47
+ };
48
+ const api = {
49
+ setState,
50
+ getState,
51
+ getInitialState,
52
+ subscribe,
53
+ destroy
54
+ };
55
+ const initialState = state = createState(setState, getState, api);
56
+ return api;
57
+ };
58
+ const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
59
+ //#endregion
60
+ //#region node_modules/.pnpm/zustand@4.5.7_immer@10.2.0_react@18.3.1/node_modules/zustand/esm/middleware.mjs
61
+ const subscribeWithSelectorImpl = (fn) => (set, get, api) => {
62
+ const origSubscribe = api.subscribe;
63
+ api.subscribe = (selector, optListener, options) => {
64
+ let listener = selector;
65
+ if (optListener) {
66
+ const equalityFn = (options == null ? void 0 : options.equalityFn) || Object.is;
67
+ let currentSlice = selector(api.getState());
68
+ listener = (state) => {
69
+ const nextSlice = selector(state);
70
+ if (!equalityFn(currentSlice, nextSlice)) {
71
+ const previousSlice = currentSlice;
72
+ optListener(currentSlice = nextSlice, previousSlice);
73
+ }
74
+ };
75
+ if (options == null ? void 0 : options.fireImmediately) optListener(currentSlice, currentSlice);
76
+ }
77
+ return origSubscribe(listener);
78
+ };
79
+ return fn(set, get, api);
80
+ };
81
+ const subscribeWithSelector = subscribeWithSelectorImpl;
82
+ //#endregion
83
+ //#region node_modules/.pnpm/zustand@4.5.7_immer@10.2.0_react@18.3.1/node_modules/zustand/esm/shallow.mjs
84
+ function shallow$1(objA, objB) {
85
+ if (Object.is(objA, objB)) return true;
86
+ if (typeof objA !== "object" || objA === null || typeof objB !== "object" || objB === null) return false;
87
+ if (objA instanceof Map && objB instanceof Map) {
88
+ if (objA.size !== objB.size) return false;
89
+ for (const [key, value] of objA) if (!Object.is(value, objB.get(key))) return false;
90
+ return true;
91
+ }
92
+ if (objA instanceof Set && objB instanceof Set) {
93
+ if (objA.size !== objB.size) return false;
94
+ for (const value of objA) if (!objB.has(value)) return false;
95
+ return true;
96
+ }
97
+ const keysA = Object.keys(objA);
98
+ if (keysA.length !== Object.keys(objB).length) return false;
99
+ for (const keyA of keysA) if (!Object.prototype.hasOwnProperty.call(objB, keyA) || !Object.is(objA[keyA], objB[keyA])) return false;
100
+ return true;
101
+ }
102
+ //#endregion
103
+ //#region node_modules/.pnpm/immer@10.2.0/node_modules/immer/dist/immer.mjs
104
+ var NOTHING = Symbol.for("immer-nothing");
105
+ var DRAFTABLE = Symbol.for("immer-draftable");
106
+ var DRAFT_STATE = Symbol.for("immer-state");
107
+ var errors = process.env.NODE_ENV !== "production" ? [
108
+ function(plugin) {
109
+ return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
110
+ },
111
+ function(thing) {
112
+ return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
113
+ },
114
+ "This object has been frozen and should not be mutated",
115
+ function(data) {
116
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
117
+ },
118
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
119
+ "Immer forbids circular references",
120
+ "The first or second argument to `produce` must be a function",
121
+ "The third argument to `produce` must be a function or undefined",
122
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
123
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
124
+ function(thing) {
125
+ return `'current' expects a draft, got: ${thing}`;
126
+ },
127
+ "Object.defineProperty() cannot be used on an Immer draft",
128
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
129
+ "Immer only supports deleting array indices",
130
+ "Immer only supports setting array indices and the 'length' property",
131
+ function(thing) {
132
+ return `'original' expects a draft, got: ${thing}`;
133
+ }
134
+ ] : [];
135
+ function die(error, ...args) {
136
+ if (process.env.NODE_ENV !== "production") {
137
+ const e = errors[error];
138
+ const msg = typeof e === "function" ? e.apply(null, args) : e;
139
+ throw new Error(`[Immer] ${msg}`);
140
+ }
141
+ throw new Error(`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`);
142
+ }
143
+ var getPrototypeOf = Object.getPrototypeOf;
144
+ function isDraft(value) {
145
+ return !!value && !!value[DRAFT_STATE];
146
+ }
147
+ function isDraftable(value) {
148
+ if (!value) return false;
149
+ return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!value.constructor?.[DRAFTABLE] || isMap(value) || isSet(value);
150
+ }
151
+ var objectCtorString = Object.prototype.constructor.toString();
152
+ var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
153
+ function isPlainObject(value) {
154
+ if (!value || typeof value !== "object") return false;
155
+ const proto = Object.getPrototypeOf(value);
156
+ if (proto === null || proto === Object.prototype) return true;
157
+ const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
158
+ if (Ctor === Object) return true;
159
+ if (typeof Ctor !== "function") return false;
160
+ let ctorString = cachedCtorStrings.get(Ctor);
161
+ if (ctorString === void 0) {
162
+ ctorString = Function.toString.call(Ctor);
163
+ cachedCtorStrings.set(Ctor, ctorString);
164
+ }
165
+ return ctorString === objectCtorString;
166
+ }
167
+ function each(obj, iter, strict = true) {
168
+ if (getArchtype(obj) === 0) (strict ? Reflect.ownKeys(obj) : Object.keys(obj)).forEach((key) => {
169
+ iter(key, obj[key], obj);
170
+ });
171
+ else obj.forEach((entry, index) => iter(index, entry, obj));
172
+ }
173
+ function getArchtype(thing) {
174
+ const state = thing[DRAFT_STATE];
175
+ return state ? state.type_ : Array.isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
176
+ }
177
+ function has(thing, prop) {
178
+ return getArchtype(thing) === 2 ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
179
+ }
180
+ function set(thing, propOrOldValue, value) {
181
+ const t = getArchtype(thing);
182
+ if (t === 2) thing.set(propOrOldValue, value);
183
+ else if (t === 3) thing.add(value);
184
+ else thing[propOrOldValue] = value;
185
+ }
186
+ function is(x, y) {
187
+ if (x === y) return x !== 0 || 1 / x === 1 / y;
188
+ else return x !== x && y !== y;
189
+ }
190
+ function isMap(target) {
191
+ return target instanceof Map;
192
+ }
193
+ function isSet(target) {
194
+ return target instanceof Set;
195
+ }
196
+ function latest(state) {
197
+ return state.copy_ || state.base_;
198
+ }
199
+ function shallowCopy(base, strict) {
200
+ if (isMap(base)) return new Map(base);
201
+ if (isSet(base)) return new Set(base);
202
+ if (Array.isArray(base)) return Array.prototype.slice.call(base);
203
+ const isPlain = isPlainObject(base);
204
+ if (strict === true || strict === "class_only" && !isPlain) {
205
+ const descriptors = Object.getOwnPropertyDescriptors(base);
206
+ delete descriptors[DRAFT_STATE];
207
+ let keys = Reflect.ownKeys(descriptors);
208
+ for (let i = 0; i < keys.length; i++) {
209
+ const key = keys[i];
210
+ const desc = descriptors[key];
211
+ if (desc.writable === false) {
212
+ desc.writable = true;
213
+ desc.configurable = true;
214
+ }
215
+ if (desc.get || desc.set) descriptors[key] = {
216
+ configurable: true,
217
+ writable: true,
218
+ enumerable: desc.enumerable,
219
+ value: base[key]
220
+ };
221
+ }
222
+ return Object.create(getPrototypeOf(base), descriptors);
223
+ } else {
224
+ const proto = getPrototypeOf(base);
225
+ if (proto !== null && isPlain) return { ...base };
226
+ const obj = Object.create(proto);
227
+ return Object.assign(obj, base);
228
+ }
229
+ }
230
+ function freeze(obj, deep = false) {
231
+ if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
232
+ if (getArchtype(obj) > 1) Object.defineProperties(obj, {
233
+ set: dontMutateMethodOverride,
234
+ add: dontMutateMethodOverride,
235
+ clear: dontMutateMethodOverride,
236
+ delete: dontMutateMethodOverride
237
+ });
238
+ Object.freeze(obj);
239
+ if (deep) Object.values(obj).forEach((value) => freeze(value, true));
240
+ return obj;
241
+ }
242
+ function dontMutateFrozenCollections() {
243
+ die(2);
244
+ }
245
+ var dontMutateMethodOverride = { value: dontMutateFrozenCollections };
246
+ function isFrozen(obj) {
247
+ if (obj === null || typeof obj !== "object") return true;
248
+ return Object.isFrozen(obj);
249
+ }
250
+ var plugins = {};
251
+ function getPlugin(pluginKey) {
252
+ const plugin = plugins[pluginKey];
253
+ if (!plugin) die(0, pluginKey);
254
+ return plugin;
255
+ }
256
+ var currentScope;
257
+ function getCurrentScope() {
258
+ return currentScope;
259
+ }
260
+ function createScope(parent_, immer_) {
261
+ return {
262
+ drafts_: [],
263
+ parent_,
264
+ immer_,
265
+ canAutoFreeze_: true,
266
+ unfinalizedDrafts_: 0
267
+ };
268
+ }
269
+ function usePatchesInScope(scope, patchListener) {
270
+ if (patchListener) {
271
+ getPlugin("Patches");
272
+ scope.patches_ = [];
273
+ scope.inversePatches_ = [];
274
+ scope.patchListener_ = patchListener;
275
+ }
276
+ }
277
+ function revokeScope(scope) {
278
+ leaveScope(scope);
279
+ scope.drafts_.forEach(revokeDraft);
280
+ scope.drafts_ = null;
281
+ }
282
+ function leaveScope(scope) {
283
+ if (scope === currentScope) currentScope = scope.parent_;
284
+ }
285
+ function enterScope(immer2) {
286
+ return currentScope = createScope(currentScope, immer2);
287
+ }
288
+ function revokeDraft(draft) {
289
+ const state = draft[DRAFT_STATE];
290
+ if (state.type_ === 0 || state.type_ === 1) state.revoke_();
291
+ else state.revoked_ = true;
292
+ }
293
+ function processResult(result, scope) {
294
+ scope.unfinalizedDrafts_ = scope.drafts_.length;
295
+ const baseDraft = scope.drafts_[0];
296
+ if (result !== void 0 && result !== baseDraft) {
297
+ if (baseDraft[DRAFT_STATE].modified_) {
298
+ revokeScope(scope);
299
+ die(4);
300
+ }
301
+ if (isDraftable(result)) {
302
+ result = finalize(scope, result);
303
+ if (!scope.parent_) maybeFreeze(scope, result);
304
+ }
305
+ if (scope.patches_) getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);
306
+ } else result = finalize(scope, baseDraft, []);
307
+ revokeScope(scope);
308
+ if (scope.patches_) scope.patchListener_(scope.patches_, scope.inversePatches_);
309
+ return result !== NOTHING ? result : void 0;
310
+ }
311
+ function finalize(rootScope, value, path) {
312
+ if (isFrozen(value)) return value;
313
+ const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
314
+ const state = value[DRAFT_STATE];
315
+ if (!state) {
316
+ each(value, (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path), useStrictIteration);
317
+ return value;
318
+ }
319
+ if (state.scope_ !== rootScope) return value;
320
+ if (!state.modified_) {
321
+ maybeFreeze(rootScope, state.base_, true);
322
+ return state.base_;
323
+ }
324
+ if (!state.finalized_) {
325
+ state.finalized_ = true;
326
+ state.scope_.unfinalizedDrafts_--;
327
+ const result = state.copy_;
328
+ let resultEach = result;
329
+ let isSet2 = false;
330
+ if (state.type_ === 3) {
331
+ resultEach = new Set(result);
332
+ result.clear();
333
+ isSet2 = true;
334
+ }
335
+ each(resultEach, (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path, isSet2), useStrictIteration);
336
+ maybeFreeze(rootScope, result, false);
337
+ if (path && rootScope.patches_) getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);
338
+ }
339
+ return state.copy_;
340
+ }
341
+ function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
342
+ if (childValue == null) return;
343
+ if (typeof childValue !== "object" && !targetIsSet) return;
344
+ const childIsFrozen = isFrozen(childValue);
345
+ if (childIsFrozen && !targetIsSet) return;
346
+ if (process.env.NODE_ENV !== "production" && childValue === targetObject) die(5);
347
+ if (isDraft(childValue)) {
348
+ const res = finalize(rootScope, childValue, rootPath && parentState && parentState.type_ !== 3 && !has(parentState.assigned_, prop) ? rootPath.concat(prop) : void 0);
349
+ set(targetObject, prop, res);
350
+ if (isDraft(res)) rootScope.canAutoFreeze_ = false;
351
+ else return;
352
+ } else if (targetIsSet) targetObject.add(childValue);
353
+ if (isDraftable(childValue) && !childIsFrozen) {
354
+ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) return;
355
+ if (parentState && parentState.base_ && parentState.base_[prop] === childValue && childIsFrozen) return;
356
+ finalize(rootScope, childValue);
357
+ if ((!parentState || !parentState.scope_.parent_) && typeof prop !== "symbol" && (isMap(targetObject) ? targetObject.has(prop) : Object.prototype.propertyIsEnumerable.call(targetObject, prop))) maybeFreeze(rootScope, childValue);
358
+ }
359
+ }
360
+ function maybeFreeze(scope, value, deep = false) {
361
+ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) freeze(value, deep);
362
+ }
363
+ function createProxyProxy(base, parent) {
364
+ const isArray = Array.isArray(base);
365
+ const state = {
366
+ type_: isArray ? 1 : 0,
367
+ scope_: parent ? parent.scope_ : getCurrentScope(),
368
+ modified_: false,
369
+ finalized_: false,
370
+ assigned_: {},
371
+ parent_: parent,
372
+ base_: base,
373
+ draft_: null,
374
+ copy_: null,
375
+ revoke_: null,
376
+ isManual_: false
377
+ };
378
+ let target = state;
379
+ let traps = objectTraps;
380
+ if (isArray) {
381
+ target = [state];
382
+ traps = arrayTraps;
383
+ }
384
+ const { revoke, proxy } = Proxy.revocable(target, traps);
385
+ state.draft_ = proxy;
386
+ state.revoke_ = revoke;
387
+ return proxy;
388
+ }
389
+ var objectTraps = {
390
+ get(state, prop) {
391
+ if (prop === DRAFT_STATE) return state;
392
+ const source = latest(state);
393
+ if (!has(source, prop)) return readPropFromProto(state, source, prop);
394
+ const value = source[prop];
395
+ if (state.finalized_ || !isDraftable(value)) return value;
396
+ if (value === peek(state.base_, prop)) {
397
+ prepareCopy(state);
398
+ return state.copy_[prop] = createProxy(value, state);
399
+ }
400
+ return value;
401
+ },
402
+ has(state, prop) {
403
+ return prop in latest(state);
404
+ },
405
+ ownKeys(state) {
406
+ return Reflect.ownKeys(latest(state));
407
+ },
408
+ set(state, prop, value) {
409
+ const desc = getDescriptorFromProto(latest(state), prop);
410
+ if (desc?.set) {
411
+ desc.set.call(state.draft_, value);
412
+ return true;
413
+ }
414
+ if (!state.modified_) {
415
+ const current2 = peek(latest(state), prop);
416
+ const currentState = current2?.[DRAFT_STATE];
417
+ if (currentState && currentState.base_ === value) {
418
+ state.copy_[prop] = value;
419
+ state.assigned_[prop] = false;
420
+ return true;
421
+ }
422
+ if (is(value, current2) && (value !== void 0 || has(state.base_, prop))) return true;
423
+ prepareCopy(state);
424
+ markChanged(state);
425
+ }
426
+ if (state.copy_[prop] === value && (value !== void 0 || prop in state.copy_) || Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
427
+ state.copy_[prop] = value;
428
+ state.assigned_[prop] = true;
429
+ return true;
430
+ },
431
+ deleteProperty(state, prop) {
432
+ if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
433
+ state.assigned_[prop] = false;
434
+ prepareCopy(state);
435
+ markChanged(state);
436
+ } else delete state.assigned_[prop];
437
+ if (state.copy_) delete state.copy_[prop];
438
+ return true;
439
+ },
440
+ getOwnPropertyDescriptor(state, prop) {
441
+ const owner = latest(state);
442
+ const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
443
+ if (!desc) return desc;
444
+ return {
445
+ writable: true,
446
+ configurable: state.type_ !== 1 || prop !== "length",
447
+ enumerable: desc.enumerable,
448
+ value: owner[prop]
449
+ };
450
+ },
451
+ defineProperty() {
452
+ die(11);
453
+ },
454
+ getPrototypeOf(state) {
455
+ return getPrototypeOf(state.base_);
456
+ },
457
+ setPrototypeOf() {
458
+ die(12);
459
+ }
460
+ };
461
+ var arrayTraps = {};
462
+ each(objectTraps, (key, fn) => {
463
+ arrayTraps[key] = function() {
464
+ arguments[0] = arguments[0][0];
465
+ return fn.apply(this, arguments);
466
+ };
467
+ });
468
+ arrayTraps.deleteProperty = function(state, prop) {
469
+ if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13);
470
+ return arrayTraps.set.call(this, state, prop, void 0);
471
+ };
472
+ arrayTraps.set = function(state, prop, value) {
473
+ if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop))) die(14);
474
+ return objectTraps.set.call(this, state[0], prop, value, state[0]);
475
+ };
476
+ function peek(draft, prop) {
477
+ const state = draft[DRAFT_STATE];
478
+ return (state ? latest(state) : draft)[prop];
479
+ }
480
+ function readPropFromProto(state, source, prop) {
481
+ const desc = getDescriptorFromProto(source, prop);
482
+ return desc ? `value` in desc ? desc.value : desc.get?.call(state.draft_) : void 0;
483
+ }
484
+ function getDescriptorFromProto(source, prop) {
485
+ if (!(prop in source)) return void 0;
486
+ let proto = getPrototypeOf(source);
487
+ while (proto) {
488
+ const desc = Object.getOwnPropertyDescriptor(proto, prop);
489
+ if (desc) return desc;
490
+ proto = getPrototypeOf(proto);
491
+ }
492
+ }
493
+ function markChanged(state) {
494
+ if (!state.modified_) {
495
+ state.modified_ = true;
496
+ if (state.parent_) markChanged(state.parent_);
497
+ }
498
+ }
499
+ function prepareCopy(state) {
500
+ if (!state.copy_) state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
501
+ }
502
+ var Immer2 = class {
503
+ constructor(config) {
504
+ this.autoFreeze_ = true;
505
+ this.useStrictShallowCopy_ = false;
506
+ this.useStrictIteration_ = true;
507
+ /**
508
+ * The `produce` function takes a value and a "recipe function" (whose
509
+ * return value often depends on the base state). The recipe function is
510
+ * free to mutate its first argument however it wants. All mutations are
511
+ * only ever applied to a __copy__ of the base state.
512
+ *
513
+ * Pass only a function to create a "curried producer" which relieves you
514
+ * from passing the recipe function every time.
515
+ *
516
+ * Only plain objects and arrays are made mutable. All other objects are
517
+ * considered uncopyable.
518
+ *
519
+ * Note: This function is __bound__ to its `Immer` instance.
520
+ *
521
+ * @param {any} base - the initial state
522
+ * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
523
+ * @param {Function} patchListener - optional function that will be called with all the patches produced here
524
+ * @returns {any} a new state, or the initial state if nothing was modified
525
+ */
526
+ this.produce = (base, recipe, patchListener) => {
527
+ if (typeof base === "function" && typeof recipe !== "function") {
528
+ const defaultBase = recipe;
529
+ recipe = base;
530
+ const self = this;
531
+ return function curriedProduce(base2 = defaultBase, ...args) {
532
+ return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
533
+ };
534
+ }
535
+ if (typeof recipe !== "function") die(6);
536
+ if (patchListener !== void 0 && typeof patchListener !== "function") die(7);
537
+ let result;
538
+ if (isDraftable(base)) {
539
+ const scope = enterScope(this);
540
+ const proxy = createProxy(base, void 0);
541
+ let hasError = true;
542
+ try {
543
+ result = recipe(proxy);
544
+ hasError = false;
545
+ } finally {
546
+ if (hasError) revokeScope(scope);
547
+ else leaveScope(scope);
548
+ }
549
+ usePatchesInScope(scope, patchListener);
550
+ return processResult(result, scope);
551
+ } else if (!base || typeof base !== "object") {
552
+ result = recipe(base);
553
+ if (result === void 0) result = base;
554
+ if (result === NOTHING) result = void 0;
555
+ if (this.autoFreeze_) freeze(result, true);
556
+ if (patchListener) {
557
+ const p = [];
558
+ const ip = [];
559
+ getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
560
+ patchListener(p, ip);
561
+ }
562
+ return result;
563
+ } else die(1, base);
564
+ };
565
+ this.produceWithPatches = (base, recipe) => {
566
+ if (typeof base === "function") return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
567
+ let patches, inversePatches;
568
+ return [
569
+ this.produce(base, recipe, (p, ip) => {
570
+ patches = p;
571
+ inversePatches = ip;
572
+ }),
573
+ patches,
574
+ inversePatches
575
+ ];
576
+ };
577
+ if (typeof config?.autoFreeze === "boolean") this.setAutoFreeze(config.autoFreeze);
578
+ if (typeof config?.useStrictShallowCopy === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
579
+ if (typeof config?.useStrictIteration === "boolean") this.setUseStrictIteration(config.useStrictIteration);
580
+ }
581
+ createDraft(base) {
582
+ if (!isDraftable(base)) die(8);
583
+ if (isDraft(base)) base = current(base);
584
+ const scope = enterScope(this);
585
+ const proxy = createProxy(base, void 0);
586
+ proxy[DRAFT_STATE].isManual_ = true;
587
+ leaveScope(scope);
588
+ return proxy;
589
+ }
590
+ finishDraft(draft, patchListener) {
591
+ const state = draft && draft[DRAFT_STATE];
592
+ if (!state || !state.isManual_) die(9);
593
+ const { scope_: scope } = state;
594
+ usePatchesInScope(scope, patchListener);
595
+ return processResult(void 0, scope);
596
+ }
597
+ /**
598
+ * Pass true to automatically freeze all copies created by Immer.
599
+ *
600
+ * By default, auto-freezing is enabled.
601
+ */
602
+ setAutoFreeze(value) {
603
+ this.autoFreeze_ = value;
604
+ }
605
+ /**
606
+ * Pass true to enable strict shallow copy.
607
+ *
608
+ * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
609
+ */
610
+ setUseStrictShallowCopy(value) {
611
+ this.useStrictShallowCopy_ = value;
612
+ }
613
+ /**
614
+ * Pass false to use faster iteration that skips non-enumerable properties
615
+ * but still handles symbols for compatibility.
616
+ *
617
+ * By default, strict iteration is enabled (includes all own properties).
618
+ */
619
+ setUseStrictIteration(value) {
620
+ this.useStrictIteration_ = value;
621
+ }
622
+ shouldUseStrictIteration() {
623
+ return this.useStrictIteration_;
624
+ }
625
+ applyPatches(base, patches) {
626
+ let i;
627
+ for (i = patches.length - 1; i >= 0; i--) {
628
+ const patch = patches[i];
629
+ if (patch.path.length === 0 && patch.op === "replace") {
630
+ base = patch.value;
631
+ break;
632
+ }
633
+ }
634
+ if (i > -1) patches = patches.slice(i + 1);
635
+ const applyPatchesImpl = getPlugin("Patches").applyPatches_;
636
+ if (isDraft(base)) return applyPatchesImpl(base, patches);
637
+ return this.produce(base, (draft) => applyPatchesImpl(draft, patches));
638
+ }
639
+ };
640
+ function createProxy(value, parent) {
641
+ const draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : createProxyProxy(value, parent);
642
+ (parent ? parent.scope_ : getCurrentScope()).drafts_.push(draft);
643
+ return draft;
644
+ }
645
+ function current(value) {
646
+ if (!isDraft(value)) die(10, value);
647
+ return currentImpl(value);
648
+ }
649
+ function currentImpl(value) {
650
+ if (!isDraftable(value) || isFrozen(value)) return value;
651
+ const state = value[DRAFT_STATE];
652
+ let copy;
653
+ let strict = true;
654
+ if (state) {
655
+ if (!state.modified_) return state.base_;
656
+ state.finalized_ = true;
657
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
658
+ strict = state.scope_.immer_.shouldUseStrictIteration();
659
+ } else copy = shallowCopy(value, true);
660
+ each(copy, (key, childValue) => {
661
+ set(copy, key, currentImpl(childValue));
662
+ }, strict);
663
+ if (state) state.finalized_ = false;
664
+ return copy;
665
+ }
666
+ var produce = new Immer2().produce;
667
+ //#endregion
668
+ //#region node_modules/.pnpm/@deepseek-ai+dsh-client-store@0.2.2-rc.5_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-client-store/lib/index.js
669
+ var lib_exports = /* @__PURE__ */ __exportAll({
670
+ createSnapshotStore: () => createSnapshotStore,
671
+ defineStore: () => defineStore,
672
+ notifySubscribers: () => notifySubscribers,
673
+ shallowEqual: () => shallowEqual
674
+ });
675
+ /**
676
+ * React-free snapshot store engine (zustand vanilla + immer + subscribeWithSelector +
677
+ * rafFlush middleware + opt-in persist + dev freeze) plus the declarative
678
+ * shell over it: {@link defineStore} bakes an init/persist/actions literal
679
+ * into a {@link StoreHandle}, the registration-side store seat of slot
680
+ * terminals. Engine products are bare observables — subscribe/getSnapshot/
681
+ * update/set, NO selector hook. Hook synthesis is ui-renderer's (the one
682
+ * uSES bridge, cached per source at the binding site).
683
+ */
684
+ /**
685
+ * Notify an observer set without allowing one callback to starve the rest.
686
+ * @param listeners - current observer callbacks; copied before dispatch.
687
+ * @param label - diagnostic owner prefix.
688
+ * @param args - callback arguments.
689
+ */
690
+ function notifySubscribers(listeners, label, ...args) {
691
+ for (const listener of [...listeners]) try {
692
+ listener(...args);
693
+ } catch (error) {
694
+ console.error(`${label} subscriber failed:`, error);
695
+ }
696
+ }
697
+ /**
698
+ * Shallow equality for selector slices (zustand/shallow semantics; travels
699
+ * with the engine so hook consumers need no zustand dependency).
700
+ * @param a - left value.
701
+ * @param b - right value.
702
+ * @returns whether the values are shallowly equal.
703
+ */
704
+ function shallowEqual(a, b) {
705
+ return shallow$1(a, b);
706
+ }
707
+ /** Batches subscriber notification into one flush per animation frame. */
708
+ function rafBatch(notify) {
709
+ const schedule = typeof requestAnimationFrame === "function" ? (fn) => {
710
+ requestAnimationFrame(() => {
711
+ fn();
712
+ });
713
+ } : (fn) => {
714
+ queueMicrotask(fn);
715
+ };
716
+ let scheduled = false;
717
+ return () => {
718
+ if (scheduled) return;
719
+ scheduled = true;
720
+ schedule(() => {
721
+ scheduled = false;
722
+ notify();
723
+ });
724
+ };
725
+ }
726
+ /**
727
+ * Create a snapshot store.
728
+ *
729
+ * Flush default is 'sync' (controlled inputs need same-tick echo); frame-driven
730
+ * stores opt into 'raf', where a frame's worth of updates coalesces into one
731
+ * notification. Known raf-mode tradeoff: a component mounting mid-frame reads
732
+ * fresh state while existing subscribers hear it next flush — transient
733
+ * frame-level skew, same nature as the object layer's microtask batching.
734
+ *
735
+ * @param init - initial state.
736
+ * @param opts - flush mode and opt-in persistence (localStorage, keyed by name).
737
+ * @returns the store.
738
+ */
739
+ function createSnapshotStore(init, opts) {
740
+ const withSelector = subscribeWithSelector(() => init);
741
+ const api = createStore()(withSelector);
742
+ if (opts?.persist) attachPersistence(api, opts.persist.name);
743
+ let subscribe = (fn) => api.subscribe(() => {
744
+ notifySubscribers([fn], "[client-store]");
745
+ });
746
+ if (opts?.flush === "raf") {
747
+ const listeners = /* @__PURE__ */ new Set();
748
+ const flush = rafBatch(() => {
749
+ notifySubscribers(listeners, "[client-store]");
750
+ });
751
+ api.subscribe(flush);
752
+ subscribe = (fn) => {
753
+ listeners.add(fn);
754
+ return () => {
755
+ listeners.delete(fn);
756
+ };
757
+ };
758
+ }
759
+ return {
760
+ getSnapshot: () => api.getState(),
761
+ subscribe: (fn) => subscribe(fn),
762
+ update: (mutator) => {
763
+ api.setState(produce(api.getState(), (draft) => {
764
+ mutator(draft);
765
+ }), true);
766
+ },
767
+ set: (next) => {
768
+ api.setState(devFreeze(next), true);
769
+ }
770
+ };
771
+ }
772
+ /**
773
+ * Whole-value JSON persistence to localStorage. Hand-rolled instead of the
774
+ * zustand persist middleware: its write path spreads state into an object
775
+ * (`partialize({ ...get() })`), exploding primitive state (a persisted string
776
+ * draft becomes {0:'h',1:'e',...}) — not fixable via merge/deserialize options
777
+ * because the corruption happens before serialization. Storage failures
778
+ * (quota, private mode) only disable persistence, never break the store.
779
+ */
780
+ function attachPersistence(api, name) {
781
+ if (typeof localStorage === "undefined") return;
782
+ try {
783
+ const raw = localStorage.getItem(name);
784
+ if (raw !== null) api.setState(devFreeze(JSON.parse(raw)), true);
785
+ } catch (error) {
786
+ console.error(`snapshot store '${name}' rehydration failed:`, error);
787
+ }
788
+ api.subscribe((state) => {
789
+ try {
790
+ localStorage.setItem(name, JSON.stringify(state));
791
+ } catch (error) {
792
+ console.error(`snapshot store '${name}' persistence failed:`, error);
793
+ }
794
+ });
795
+ }
796
+ /** Deep-freeze draftable wholesale-set state outside production: set() bypasses immer's freeze. */
797
+ function devFreeze(value) {
798
+ return value;
799
+ }
800
+ /**
801
+ * Declare a store: initial state, optional persistence, and the full write
802
+ * set as pure draft mutators. The returned handle is the registration
803
+ * currency of the store seat — its identity keys instance sharing. Satisfies
804
+ * ui-slots' DefineStore contract (the handle/instance are the engine-extended
805
+ * subtypes).
806
+ *
807
+ * The `A & ActionsDecl<T>` actions position is load-bearing: T resolves from
808
+ * `init` in the first inference round, and the intersection then contextually
809
+ * types each mutator's draft parameter (context-sensitive functions defer),
810
+ * so call sites write `(d, x: X) => { ... }` with no draft annotation. If a
811
+ * future TS version breaks this single-literal inference, the design's
812
+ * documented fallback is currying (`defineStore(init).actions({...})`).
813
+ * @param decl - init lambda (fresh state per instance), optional persist key, actions table.
814
+ * @returns the store handle.
815
+ */
816
+ function defineStore(decl) {
817
+ return {
818
+ spec: decl,
819
+ create(scopeKey) {
820
+ const persistKey = decl.persist === void 0 ? void 0 : scopeKey === void 0 ? decl.persist : `${decl.persist}.${scopeKey}`;
821
+ const store = createSnapshotStore(decl.init(), persistKey !== void 0 ? { persist: { name: persistKey } } : void 0);
822
+ const actions = {};
823
+ for (const key of Object.keys(decl.actions)) {
824
+ const mutate = decl.actions[key];
825
+ actions[key] = (...params) => {
826
+ store.update((draft) => {
827
+ mutate(draft, ...params);
828
+ });
829
+ };
830
+ }
831
+ return {
832
+ actions,
833
+ getSnapshot: () => store.getSnapshot(),
834
+ subscribe: (fn) => store.subscribe(fn),
835
+ store,
836
+ clearPersisted: () => {
837
+ if (persistKey === void 0 || typeof localStorage === "undefined") return;
838
+ try {
839
+ localStorage.removeItem(persistKey);
840
+ } catch {}
841
+ }
842
+ };
843
+ }
844
+ };
845
+ }
846
+ //#endregion
847
+ //#region src/app/remote/client-runtime.ts
848
+ /**
849
+ * Experimental official Client runtime composition (M3-1).
850
+ *
851
+ * Owns the official Client bundle capture, the Client `Context`, the exact
852
+ * plugin mount order, the explicit `/remote` contributions, initial
853
+ * readiness, and reverse disposal.
854
+ * It does not assemble the TUI semantic `Backend`.
855
+ *
856
+ * rc.2 publishes the six required Client plugin entries as Web
857
+ * module-loader bundles: each bundle registers through
858
+ * `window.__ModuleLoader__.load(...)`, which plain Node dynamic imports
859
+ * cannot consume directly. The scoped loader below is therefore a packaging
860
+ * adapter only: it is installed around exactly the six dynamic imports,
861
+ * rejects unknown/duplicate/missing registrations, and restores the previous
862
+ * process state before any Client plugin runs.
863
+ *
864
+ * Because ESM evaluates each bundle at most once per process, the capture is
865
+ * a process-wide single-flight: the captured package module exports are
866
+ * reused for every Client `Context`, while each Context still gets its own
867
+ * independent Connection, Gateway, Remote namespaces, Sessions, Jobs,
868
+ * subscriptions, and lifetimes. Captured bundle factories are never re-run.
869
+ *
870
+ * @module app/remote/client-runtime
871
+ */
872
+ /**
873
+ * The exact allowlist: dynamic import specifier paired with its expected
874
+ * `__ModuleLoader__` registration id (§9.1). Kept distinct by design.
875
+ */
876
+ const OFFICIAL_CLIENT_BUNDLES = [
877
+ {
878
+ specifier: "@deepseek-ai/dsh-typert-registry/client",
879
+ id: "@deepseek-ai/dsh-typert-registry"
880
+ },
881
+ {
882
+ specifier: "@deepseek-ai/dsh-client-connection/client",
883
+ id: "@deepseek-ai/dsh-client-connection"
884
+ },
885
+ {
886
+ specifier: "@deepseek-ai/dsh-api-gateway/client",
887
+ id: "@deepseek-ai/dsh-api-gateway"
888
+ },
889
+ {
890
+ specifier: "@deepseek-ai/dsh-client-file-upload/client",
891
+ id: "@deepseek-ai/dsh-client-file-upload"
892
+ },
893
+ {
894
+ specifier: "@deepseek-ai/dsh-api-session-controller/client",
895
+ id: "@deepseek-ai/dsh-api-session-controller"
896
+ },
897
+ {
898
+ specifier: "@deepseek-ai/dsh-api-job-controller/client",
899
+ id: "@deepseek-ai/dsh-api-job-controller"
900
+ }
901
+ ];
902
+ /** Expected registration ids, in dependency order. */
903
+ const EXPECTED_REGISTRATION_IDS = OFFICIAL_CLIENT_BUNDLES.map((bundle) => bundle.id);
904
+ /**
905
+ * The official web shell's platform static modules, which the browser-form
906
+ * `/client` bundles resolve through the Loader's `require` (the published web
907
+ * seed shares exactly these singletons). The Node Client shell is that shell:
908
+ * it supplies the installed Harness-family `@deepseek-ai/dsh-client-store`
909
+ * instance instead of relying on a transitive resolution from a bundle's own
910
+ * package graph. `@deepseek-ai/cordis` is imported directly by this module and
911
+ * therefore already resolves normally.
912
+ */
913
+ /** The ONE platform static module table the official `/client` bundle loader
914
+ * receives. Exported only as a module-internal seam (never a package export)
915
+ * so the L5 contract test can prove every factory sees the same namespace. */
916
+ const CLIENT_PLATFORM_MODULES = { "@deepseek-ai/dsh-client-store": lib_exports };
917
+ /** The loader's bare-dependency resolver: platform statics first, then the
918
+ * CALLER's installation resolver. The real Client passes the DSH anchor
919
+ * resolver so every non-platform dependency of a browser-form bundle also
920
+ * resolves from the anchored installation, never from an unrelated source
921
+ * tree. */
922
+ function createPlatformRequire(fallback) {
923
+ return (specifier) => Object.hasOwn(CLIENT_PLATFORM_MODULES, specifier) ? CLIENT_PLATFORM_MODULES[specifier] : fallback(specifier);
924
+ }
925
+ /** Process-wide single-flight capture; module code evaluates once per process. */
926
+ let officialClientModulesPromise;
927
+ /**
928
+ * Load the six official Client bundles once per process and freeze their
929
+ * captured module exports. Concurrent callers share the same promise.
930
+ *
931
+ * DSH 0.2.1-rc.1 and later select the `./client` entry by condition: `@deepseek-ai/dsh-typert-registry`,
932
+ * `@deepseek-ai/dsh-client-connection` and `@deepseek-ai/dsh-api-gateway` publish
933
+ * a standalone Node ESM variant (which never touches `window.__ModuleLoader__`),
934
+ * while the remaining three publish the browser loader factory. Both channels
935
+ * feed one table, so the registration order below still holds for every
936
+ * `/client` dependency.
937
+ *
938
+ * Failure semantics: a rejected capture stays cached (fail fast, no silent
939
+ * retry). ESM evaluates each bundle at most once per process, so bundles
940
+ * already imported during a failed capture can never re-register — a retry
941
+ * would deterministically fail the completeness check anyway.
942
+ */
943
+ function loadOfficialClientModulesOnce() {
944
+ officialClientModulesPromise ??= captureOfficialClientModules();
945
+ return officialClientModulesPromise;
946
+ }
947
+ /**
948
+ * Exact scoped loader capture: install a temporary `window.__ModuleLoader__`,
949
+ * dynamic-import the six bundles in dependency order, admit each bundle from
950
+ * exactly the channel the published `./client` entry selected (loader
951
+ * registration or standalone Node module — see {@link captureOfficialClientModules}),
952
+ * freeze the module-export table, and restore the previous process state in
953
+ * `finally` — before any Client Context exists.
954
+ */
955
+ /**
956
+ * The exact scoped loader admission rules (module-internal seam, exercised by
957
+ * the L5 loader-exactness test): reject an unknown registration id, a
958
+ * duplicate id, a non-function factory, and a `/client` dependency requested
959
+ * before its dependency-order capture; admit a directly imported Node bundle
960
+ * for an id the loader did not register; report missing expected ids.
961
+ */
962
+ function createScopedClientModuleLoader(expectedIds, requireFrom = createRequire(import.meta.url)) {
963
+ const nodeRequire = requireFrom;
964
+ const registrations = /* @__PURE__ */ new Map();
965
+ const captured = /* @__PURE__ */ new Map();
966
+ const requireModule = (specifier) => {
967
+ if (specifier.endsWith("/client")) {
968
+ const id = specifier.slice(0, -7);
969
+ const module = captured.get(id);
970
+ if (module === void 0) throw new Error(`official Client module ${specifier} was requested before ${id} was captured`);
971
+ return module;
972
+ }
973
+ return nodeRequire(specifier);
974
+ };
975
+ const load = ({ id, factory }) => {
976
+ if (!expectedIds.includes(id)) throw new Error(`official Client bundle loader received an unexpected registration id: ${String(id)}`);
977
+ if (registrations.has(id)) throw new Error(`official Client bundle ${id} registered twice`);
978
+ if (typeof factory !== "function") throw new Error(`official Client bundle ${id} registered a non-function factory`);
979
+ registrations.set(id, factory);
980
+ captured.set(id, factory(requireModule));
981
+ };
982
+ /**
983
+ * Admit one directly imported bundle whose `./client` entry did not register
984
+ * through the loader shim (the standalone Node variant). The module joins the
985
+ * SAME table {@link requireModule} resolves `/client` dependencies from, so a
986
+ * registering bundle can still depend on a Node-variant one. A bundle that did
987
+ * register is left to its own registration: the browser factory result is the
988
+ * authoritative module for that id.
989
+ * @param id - the bundle's registration id.
990
+ * @param module - the imported module namespace.
991
+ * @throws when the id is unexpected or already admitted by a direct import.
992
+ */
993
+ const acceptImported = (id, module) => {
994
+ if (!expectedIds.includes(id)) throw new Error(`official Client bundle import produced an unexpected id: ${String(id)}`);
995
+ if (registrations.has(id)) return;
996
+ if (captured.has(id)) throw new Error(`official Client bundle ${id} was imported as a Node module twice`);
997
+ captured.set(id, module);
998
+ };
999
+ return {
1000
+ load,
1001
+ requireModule,
1002
+ registeredIds: () => [...registrations.keys()],
1003
+ acceptImported,
1004
+ assertComplete() {
1005
+ for (const id of expectedIds) if (!captured.has(id)) throw new Error(`official Client bundle ${id} was neither registered through __ModuleLoader__ nor imported as a Node module`);
1006
+ }
1007
+ };
1008
+ }
1009
+ /**
1010
+ * Install the temporary `window.__ModuleLoader__` shim around exactly the six
1011
+ * bundle imports, preserving the exact previous process state: when
1012
+ * `globalThis.window` is absent, only the minimal temporary object is created
1013
+ * and deleted again; when a `window` own property already exists (including a
1014
+ * property whose value is `undefined`/`null`, and accessor descriptors), its
1015
+ * exact property descriptor is restored, and any pre-existing
1016
+ * `__ModuleLoader__` property descriptor on an existing window object is
1017
+ * preserved and restored verbatim.
1018
+ * @returns the restore function; it must run before any Client plugin executes
1019
+ * (and on every failure path).
1020
+ */
1021
+ function installScopedModuleLoaderShim(load) {
1022
+ const globalScope = globalThis;
1023
+ const previousWindowDescriptor = Object.getOwnPropertyDescriptor(globalScope, "window");
1024
+ const previousWindowValue = previousWindowDescriptor?.value;
1025
+ const usableExistingWindow = typeof previousWindowValue === "object" && previousWindowValue !== null || typeof previousWindowValue === "function";
1026
+ let previousLoaderDescriptor;
1027
+ const install = () => {
1028
+ if (usableExistingWindow) {
1029
+ const existingWindow = previousWindowValue;
1030
+ previousLoaderDescriptor = Object.getOwnPropertyDescriptor(existingWindow, "__ModuleLoader__");
1031
+ existingWindow.__ModuleLoader__ = { load };
1032
+ } else Object.defineProperty(globalScope, "window", {
1033
+ configurable: true,
1034
+ writable: true,
1035
+ value: { __ModuleLoader__: { load } }
1036
+ });
1037
+ };
1038
+ const restore = () => {
1039
+ if (previousWindowDescriptor === void 0) {
1040
+ delete globalScope.window;
1041
+ return;
1042
+ }
1043
+ Object.defineProperty(globalScope, "window", previousWindowDescriptor);
1044
+ if (usableExistingWindow) {
1045
+ const existingWindow = previousWindowValue;
1046
+ if (previousLoaderDescriptor === void 0) delete existingWindow.__ModuleLoader__;
1047
+ else Object.defineProperty(existingWindow, "__ModuleLoader__", previousLoaderDescriptor);
1048
+ }
1049
+ };
1050
+ install();
1051
+ return restore;
1052
+ }
1053
+ async function captureOfficialClientModules() {
1054
+ const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(createRequire(import.meta.url)));
1055
+ const restoreShim = installScopedModuleLoaderShim(loader.load);
1056
+ try {
1057
+ for (const bundle of OFFICIAL_CLIENT_BUNDLES) loader.acceptImported(bundle.id, await import(bundle.specifier));
1058
+ loader.assertComplete();
1059
+ } finally {
1060
+ restoreShim();
1061
+ }
1062
+ const captured = /* @__PURE__ */ new Map();
1063
+ for (const id of EXPECTED_REGISTRATION_IDS) captured.set(id, loader.requireModule(`${id}/client`));
1064
+ return freezeOfficialClientModules(captured);
1065
+ }
1066
+ function freezeOfficialClientModules(captured) {
1067
+ const modules = {
1068
+ typert: captured.get("@deepseek-ai/dsh-typert-registry"),
1069
+ connection: captured.get("@deepseek-ai/dsh-client-connection"),
1070
+ gateway: captured.get("@deepseek-ai/dsh-api-gateway"),
1071
+ fileUpload: captured.get("@deepseek-ai/dsh-client-file-upload"),
1072
+ session: captured.get("@deepseek-ai/dsh-api-session-controller"),
1073
+ jobs: captured.get("@deepseek-ai/dsh-api-job-controller")
1074
+ };
1075
+ for (const [id, module] of Object.entries(modules)) if (module === void 0) throw new Error(`official Client bundle capture produced no module exports for ${id}`);
1076
+ return Object.freeze(modules);
1077
+ }
1078
+ /** Explicit generated `/remote` contributions (§2.4.2), never the aggregate.
1079
+ * Exported (module-internal seam, not a package export) so the L5 suite can
1080
+ * prove these two frozen tables agree package-by-package and that the
1081
+ * six-bundle Client list stays exactly six. */
1082
+ const REMOTE_CONTRIBUTIONS = [
1083
+ sessionRemote,
1084
+ jobRemote,
1085
+ commandsRemote,
1086
+ subagentsRemote,
1087
+ agentPresetsRemote,
1088
+ pluginManagerRemote,
1089
+ mcpManagerRemote,
1090
+ settingsRemote,
1091
+ accountRemote,
1092
+ permissionPresetsRemote,
1093
+ llmRemote,
1094
+ fileUploadsRemote,
1095
+ userQuestionsRemote,
1096
+ workspaceFilesRemote,
1097
+ workspaceRemote,
1098
+ scheduleRemote,
1099
+ agentTeamsRemote,
1100
+ cuaRemote
1101
+ ];
1102
+ /**
1103
+ * The exact generated `/remote` contribution specifiers in the SAME frozen
1104
+ * order as {@link REMOTE_CONTRIBUTIONS}. A real installed Client process
1105
+ * resolves THESE from its DSH installation anchor instead of consuming the
1106
+ * statically imported source-tree copy; both channels produce the one table
1107
+ * `mountRemoteClientDomains` mounts.
1108
+ */
1109
+ const REMOTE_CONTRIBUTION_SPECIFIERS = [
1110
+ "@deepseek-ai/dsh-api-session-controller/remote",
1111
+ "@deepseek-ai/dsh-api-job-controller/remote",
1112
+ "@deepseek-ai/dsh-commands/remote",
1113
+ "@deepseek-ai/dsh-subagent/remote",
1114
+ "@deepseek-ai/dsh-agent-preset-registry/remote",
1115
+ "@deepseek-ai/dsh-plugin-manager/remote",
1116
+ "@deepseek-ai/dsh-mcp-manager/remote",
1117
+ "@deepseek-ai/dsh-api-settings-controller/remote",
1118
+ "@deepseek-ai/dsh-deepseek-account/remote",
1119
+ "@deepseek-ai/dsh-permission-presets/remote",
1120
+ "@deepseek-ai/dsh-llm/remote",
1121
+ "@deepseek-ai/dsh-client-file-upload/remote",
1122
+ "@deepseek-ai/dsh-user-questions/remote",
1123
+ "@deepseek-ai/dsh-api-workspace-files/remote",
1124
+ "@deepseek-ai/dsh-api-workspace-controller/remote",
1125
+ "@deepseek-ai/dsh-schedule/remote",
1126
+ "@deepseek-ai/dsh-agent-team/remote",
1127
+ "@deepseek-ai/dsh-cua/remote"
1128
+ ];
1129
+ /** Per-installation single-flight captures, keyed by the real anchor path. */
1130
+ const installedClientDomainModules = /* @__PURE__ */ new Map();
1131
+ /** Capture the six official `/client` bundles through the installation anchor. */
1132
+ async function captureInstalledOfficialClientModules(requireFromAnchor) {
1133
+ const loader = createScopedClientModuleLoader(EXPECTED_REGISTRATION_IDS, createPlatformRequire(requireFromAnchor));
1134
+ const restoreShim = installScopedModuleLoaderShim(loader.load);
1135
+ try {
1136
+ for (const bundle of OFFICIAL_CLIENT_BUNDLES) {
1137
+ const resolved = requireFromAnchor.resolve(bundle.specifier);
1138
+ loader.acceptImported(bundle.id, await import(pathToFileURL(resolved).href));
1139
+ }
1140
+ loader.assertComplete();
1141
+ } finally {
1142
+ restoreShim();
1143
+ }
1144
+ const captured = /* @__PURE__ */ new Map();
1145
+ for (const id of EXPECTED_REGISTRATION_IDS) captured.set(id, loader.requireModule(`${id}/client`));
1146
+ return freezeOfficialClientModules(captured);
1147
+ }
1148
+ /**
1149
+ * Capture ONE installed DSH generation's whole Client domain composition: the
1150
+ * six official `/client` bundles and the generated `/remote` contributions,
1151
+ * every specifier resolved from `dshAnchor`. A rejection stays cached (fail
1152
+ * fast; a retry cannot succeed because ESM evaluates the bundles once).
1153
+ */
1154
+ async function captureInstalledClientDomainModules(anchor) {
1155
+ const requireFromAnchor = createRequire(anchor);
1156
+ const modules = await captureInstalledOfficialClientModules(requireFromAnchor);
1157
+ const contributions = [];
1158
+ for (const specifier of REMOTE_CONTRIBUTION_SPECIFIERS) {
1159
+ const contribution = (await import(pathToFileURL(requireFromAnchor.resolve(specifier)).href)).default;
1160
+ if (typeof contribution !== "object" || contribution === null || !Array.isArray(contribution.descriptors)) throw new Error(`remote client domains: installed ${specifier} is not a generated Remote contribution`);
1161
+ contributions.push(contribution);
1162
+ }
1163
+ return {
1164
+ modules,
1165
+ contributions
1166
+ };
1167
+ }
1168
+ /** Load the Client domain composition from one installed DSH anchor (single-flight). */
1169
+ function loadInstalledClientDomainModules(dshAnchor) {
1170
+ const anchor = realpathSync(dshAnchor);
1171
+ let pending = installedClientDomainModules.get(anchor);
1172
+ if (pending === void 0) {
1173
+ pending = captureInstalledClientDomainModules(anchor);
1174
+ installedClientDomainModules.set(anchor, pending);
1175
+ }
1176
+ return pending;
1177
+ }
1178
+ /**
1179
+ * Reverse-dispose the recorded `/remote` contribution disposers. Per-step
1180
+ * error isolation: one rejecting disposer cannot truncate the remaining
1181
+ * cleanup. Returns the collected cleanup errors in encounter order.
1182
+ *
1183
+ * Exported so the L5 suite can exercise the exact collection semantics the
1184
+ * production composition relies on (module-internal seam, like
1185
+ * `createScopedClientModuleLoader`).
1186
+ */
1187
+ async function disposeRemoteContributions(disposers) {
1188
+ const errors = [];
1189
+ for (let index = disposers.length - 1; index >= 0; index -= 1) try {
1190
+ await disposers[index]();
1191
+ } catch (error) {
1192
+ errors.push(error);
1193
+ }
1194
+ return errors;
1195
+ }
1196
+ /** Reverse-order Domain teardown. Contribution failures are isolated. */
1197
+ async function shutdownDomainState(state) {
1198
+ if (state.disposed) return [];
1199
+ state.disposed = true;
1200
+ const initialGenerationOff = state.initialGenerationOff;
1201
+ state.initialGenerationOff = void 0;
1202
+ initialGenerationOff?.();
1203
+ for (const fiber of [
1204
+ state.jobsFiber,
1205
+ state.sessionFiber,
1206
+ state.fileUploadFiber
1207
+ ]) await fiber?.dispose();
1208
+ state.jobsFiber = void 0;
1209
+ state.sessionFiber = void 0;
1210
+ state.fileUploadFiber = void 0;
1211
+ const contributionErrors = await disposeRemoteContributions(state.contributionDisposers);
1212
+ state.contributionDisposers.length = 0;
1213
+ return contributionErrors;
1214
+ }
1215
+ /**
1216
+ * Mount the official Client Domain prerequisites on the caller's
1217
+ * ALREADY-AUTHENTICATED Client `Context`: the thirteen generated `/remote`
1218
+ * contributions, the private pi-tui contribution, the official fileUpload
1219
+ * Client, then the official Session Client (which registers the `agent`
1220
+ * `typert.contexts` resolver). It deliberately does NOT wait for a Connection
1221
+ * generation: the split Client must mount the Session resolver and its root
1222
+ * interaction listeners before the official Gateway starts its event pump.
1223
+ *
1224
+ * Failure semantics: a construction failure unwinds exactly what this stage
1225
+ * created, in reverse order; the original error stays primary and any cleanup
1226
+ * failures ride its cause chain.
1227
+ */
1228
+ async function mountRemoteClientDomainPrerequisites(options) {
1229
+ const { context } = options;
1230
+ const connection = context.get("connection");
1231
+ const remote = context.get("remote");
1232
+ if (context.get("typert") === void 0 || connection === void 0 || remote === void 0) throw new Error("remote client domains: the caller must install typert, the authenticated connection and the API gateway first");
1233
+ const source = options.dshAnchor === void 0 ? {
1234
+ modules: await loadOfficialClientModulesOnce(),
1235
+ contributions: REMOTE_CONTRIBUTIONS
1236
+ } : await loadInstalledClientDomainModules(options.dshAnchor);
1237
+ const state = {
1238
+ context,
1239
+ connection,
1240
+ remote,
1241
+ sessions: void 0,
1242
+ contributionDisposers: [],
1243
+ disposed: false
1244
+ };
1245
+ const unwind = async (error) => {
1246
+ const cleanupErrors = await shutdownDomainState(state);
1247
+ const failure = error instanceof Error ? error : new Error(String(error));
1248
+ if (cleanupErrors.length > 0) {
1249
+ const secondary = cleanupErrors.length === 1 ? cleanupErrors[0] : new AggregateError(cleanupErrors, "remote client domains: unwind disposal failures");
1250
+ mergeCause(failure, secondary);
1251
+ }
1252
+ throw failure;
1253
+ };
1254
+ try {
1255
+ for (const contribution of source.contributions) state.contributionDisposers.push(await remote.$mount(contribution));
1256
+ state.contributionDisposers.push(await remote.$mount(PI_TUI_CLIENT_CONTRIBUTION));
1257
+ state.fileUploadFiber = context.plugin(source.modules.fileUpload);
1258
+ await state.fileUploadFiber;
1259
+ state.sessionFiber = context.plugin(source.modules.session);
1260
+ await state.sessionFiber;
1261
+ state.sessions = context.get("sessions");
1262
+ if (state.sessions === void 0) throw new Error("remote client domains: the official Session Client did not install");
1263
+ } catch (error) {
1264
+ return await unwind(error);
1265
+ }
1266
+ let initialGeneration = connection.generation.getSnapshot();
1267
+ if (initialGeneration === void 0) {
1268
+ const off = connection.generation.subscribe(() => {
1269
+ initialGeneration ??= connection.generation.getSnapshot();
1270
+ if (initialGeneration === void 0) return;
1271
+ if (state.initialGenerationOff !== off) return;
1272
+ state.initialGenerationOff = void 0;
1273
+ off();
1274
+ });
1275
+ state.initialGenerationOff = off;
1276
+ }
1277
+ return {
1278
+ context,
1279
+ connection,
1280
+ remote,
1281
+ sessions: state.sessions,
1282
+ async complete(completeOptions = {}) {
1283
+ if (state.disposed) throw new Error("remote client domains: the prerequisites were already disposed");
1284
+ state.completion ??= (async () => {
1285
+ try {
1286
+ state.jobsFiber = context.plugin(source.modules.jobs);
1287
+ await state.jobsFiber;
1288
+ try {
1289
+ await waitForInitialReadiness(connection, state.sessions, completeOptions.signal);
1290
+ } finally {
1291
+ const off = state.initialGenerationOff;
1292
+ state.initialGenerationOff = void 0;
1293
+ off?.();
1294
+ }
1295
+ const jobs = context.get("jobs");
1296
+ if (jobs === void 0) throw new Error("remote client domains: the official Jobs Client did not install");
1297
+ return {
1298
+ context,
1299
+ connection,
1300
+ sessions: state.sessions,
1301
+ jobs,
1302
+ remote,
1303
+ workspaceStream: {
1304
+ stream: remote.$stream.bind(remote),
1305
+ carrierError: source.modules.gateway.RemoteStreamCarrierError
1306
+ },
1307
+ initialGeneration,
1308
+ async dispose() {
1309
+ const cleanupErrors = await shutdownDomainState(state);
1310
+ if (cleanupErrors.length === 0) return;
1311
+ const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
1312
+ if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
1313
+ throw failure;
1314
+ }
1315
+ };
1316
+ } catch (error) {
1317
+ return await unwind(error);
1318
+ }
1319
+ })();
1320
+ return await state.completion;
1321
+ },
1322
+ async dispose() {
1323
+ const cleanupErrors = await shutdownDomainState(state);
1324
+ if (cleanupErrors.length === 0) return;
1325
+ const failure = cleanupErrors[0] instanceof Error ? cleanupErrors[0] : new Error(String(cleanupErrors[0]));
1326
+ if (cleanupErrors.length > 1) mergeCause(failure, new AggregateError(cleanupErrors.slice(1), "remote client domains: remaining disposal failures"));
1327
+ throw failure;
1328
+ }
1329
+ };
1330
+ }
1331
+ /**
1332
+ * Initial readiness: a defined Connection
1333
+ * generation AND a `ready` Session list. Subscription-driven with no
1334
+ * production timeout; the lifecycle signal aborts the wait and every listener
1335
+ * is removed on settle or abort.
1336
+ */
1337
+ async function waitForInitialReadiness(connection, sessions, signal) {
1338
+ const isReady = () => connection.generation.getSnapshot() !== void 0 && sessions.list.getSnapshot().phase === "ready";
1339
+ if (signal?.aborted) throw new Error("remote client runtime: aborted before initial readiness", { cause: signal.reason });
1340
+ if (isReady()) return;
1341
+ await new Promise((resolve, reject) => {
1342
+ let settled = false;
1343
+ let abortListener;
1344
+ const settle = () => {
1345
+ if (settled) return;
1346
+ if (isReady()) {
1347
+ settled = true;
1348
+ cleanup();
1349
+ resolve();
1350
+ }
1351
+ };
1352
+ const generationUnsubscribe = connection.generation.subscribe(settle);
1353
+ const listUnsubscribe = sessions.list.subscribe(settle);
1354
+ const cleanup = () => {
1355
+ generationUnsubscribe();
1356
+ listUnsubscribe();
1357
+ if (abortListener !== void 0) signal?.removeEventListener("abort", abortListener);
1358
+ };
1359
+ if (signal !== void 0) {
1360
+ abortListener = () => {
1361
+ if (settled) return;
1362
+ settled = true;
1363
+ cleanup();
1364
+ reject(new Error("remote client runtime: aborted before initial readiness", { cause: signal.reason }));
1365
+ };
1366
+ if (signal.aborted) {
1367
+ abortListener();
1368
+ return;
1369
+ }
1370
+ signal.addEventListener("abort", abortListener, { once: true });
1371
+ }
1372
+ settle();
1373
+ });
1374
+ }
1375
+ //#endregion
1376
+ export { mountRemoteClientDomainPrerequisites as t };