@linxin666/dsh-ssh 0.3.23 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import z from "@deepseek-ai/schemastery";
1
2
  import { closeSync, createReadStream, createWriteStream, existsSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
2
3
  import { Client } from "ssh2";
3
4
  import { homedir, tmpdir } from "node:os";
@@ -10,1022 +11,7 @@ import { unlink } from "node:fs/promises";
10
11
  import { randomBytes } from "node:crypto";
11
12
  import { WebSocket, WebSocketServer } from "ws";
12
13
  import { defineTool } from "@deepseek-ai/dsh-tools";
13
- //#region \0rolldown/runtime.js
14
- var __create = Object.create;
15
- var __defProp = Object.defineProperty;
16
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
17
- var __getOwnPropNames = Object.getOwnPropertyNames;
18
- var __getProtoOf = Object.getPrototypeOf;
19
- var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
21
- var __copyProps = (to, from, except, desc) => {
22
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
- key = keys[i];
24
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
25
- get: ((k) => from[k]).bind(null, key),
26
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
27
- });
28
- }
29
- return to;
30
- };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
32
- value: mod,
33
- enumerable: true
34
- }) : target, mod));
35
- //#endregion
36
- //#region ../../node_modules/.pnpm/cosmokit@1.8.1/node_modules/cosmokit/lib/index.cjs
37
- var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
38
- var __defProp = Object.defineProperty;
39
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
40
- var __getOwnPropNames = Object.getOwnPropertyNames;
41
- var __hasOwnProp = Object.prototype.hasOwnProperty;
42
- var __export = (target, all) => {
43
- for (var name in all) __defProp(target, name, {
44
- get: all[name],
45
- enumerable: true
46
- });
47
- };
48
- var __copyProps = (to, from, except, desc) => {
49
- if (from && typeof from === "object" || typeof from === "function") {
50
- for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
51
- get: () => from[key],
52
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
53
- });
54
- }
55
- return to;
56
- };
57
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
58
- var index_exports = {};
59
- __export(index_exports, {
60
- Binary: () => Binary,
61
- Time: () => Time,
62
- arrayBufferToBase64: () => arrayBufferToBase64,
63
- arrayBufferToHex: () => arrayBufferToHex,
64
- base64ToArrayBuffer: () => base64ToArrayBuffer,
65
- camelCase: () => camelCase,
66
- camelize: () => camelize,
67
- capitalize: () => capitalize,
68
- clone: () => clone,
69
- contain: () => contain,
70
- deduplicate: () => deduplicate,
71
- deepEqual: () => deepEqual,
72
- defineProperty: () => defineProperty,
73
- difference: () => difference,
74
- filterKeys: () => filterKeys,
75
- formatProperty: () => formatProperty,
76
- hexToArrayBuffer: () => hexToArrayBuffer,
77
- hyphenate: () => hyphenate,
78
- intersection: () => intersection,
79
- is: () => is,
80
- isNonNullable: () => isNonNullable,
81
- isNullable: () => isNullable,
82
- isPlainObject: () => isPlainObject,
83
- makeArray: () => makeArray,
84
- mapValues: () => mapValues,
85
- noop: () => noop,
86
- omit: () => omit,
87
- paramCase: () => paramCase,
88
- pick: () => pick,
89
- remove: () => remove,
90
- sanitize: () => sanitize,
91
- snakeCase: () => snakeCase,
92
- trimSlash: () => trimSlash,
93
- uncapitalize: () => uncapitalize,
94
- union: () => union,
95
- valueMap: () => mapValues
96
- });
97
- module.exports = __toCommonJS(index_exports);
98
- function noop() {}
99
- function isNullable(value) {
100
- return value === null || value === void 0;
101
- }
102
- function isNonNullable(value) {
103
- return !isNullable(value);
104
- }
105
- function isPlainObject(data) {
106
- return data && typeof data === "object" && !Array.isArray(data);
107
- }
108
- function filterKeys(object, filter) {
109
- return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
110
- }
111
- function mapValues(object, transform) {
112
- return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
113
- }
114
- function pick(source, keys, forced) {
115
- if (!keys) return { ...source };
116
- const result = {};
117
- for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
118
- return result;
119
- }
120
- function omit(source, keys) {
121
- if (!keys) return { ...source };
122
- const result = { ...source };
123
- for (const key of keys) Reflect.deleteProperty(result, key);
124
- return result;
125
- }
126
- function defineProperty(object, key, value) {
127
- return Object.defineProperty(object, key, {
128
- writable: true,
129
- value,
130
- enumerable: false
131
- });
132
- }
133
- function contain(array1, array2) {
134
- return array2.every((item) => array1.includes(item));
135
- }
136
- function intersection(array1, array2) {
137
- return array1.filter((item) => array2.includes(item));
138
- }
139
- function difference(array1, array2) {
140
- return array1.filter((item) => !array2.includes(item));
141
- }
142
- function union(array1, array2) {
143
- return Array.from(/* @__PURE__ */ new Set([...array1, ...array2]));
144
- }
145
- function deduplicate(array) {
146
- return [...new Set(array)];
147
- }
148
- function remove(list, item) {
149
- const index = list?.indexOf(item);
150
- if (index >= 0) {
151
- list.splice(index, 1);
152
- return true;
153
- } else return false;
154
- }
155
- function makeArray(source) {
156
- return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
157
- }
158
- function is(type, value) {
159
- if (arguments.length === 1) return (value2) => is(type, value2);
160
- return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
161
- }
162
- function isArrayBufferLike(value) {
163
- return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
164
- }
165
- function isArrayBufferSource(value) {
166
- return isArrayBufferLike(value) || ArrayBuffer.isView(value);
167
- }
168
- var Binary;
169
- ((Binary2) => {
170
- Binary2.is = isArrayBufferLike;
171
- Binary2.isSource = isArrayBufferSource;
172
- function fromSource(source) {
173
- if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
174
- else return source;
175
- }
176
- Binary2.fromSource = fromSource;
177
- function toBase64(source) {
178
- source = fromSource(source);
179
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
180
- let binary = "";
181
- const bytes = new Uint8Array(source);
182
- for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
183
- return btoa(binary);
184
- }
185
- Binary2.toBase64 = toBase64;
186
- function fromBase64(source) {
187
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
188
- return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
189
- }
190
- Binary2.fromBase64 = fromBase64;
191
- function toHex(source) {
192
- source = fromSource(source);
193
- if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
194
- return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
195
- }
196
- Binary2.toHex = toHex;
197
- function fromHex(source) {
198
- if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
199
- const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
200
- const buffer = [];
201
- for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
202
- return Uint8Array.from(buffer).buffer;
203
- }
204
- Binary2.fromHex = fromHex;
205
- })(Binary || (Binary = {}));
206
- var base64ToArrayBuffer = Binary.fromBase64;
207
- var arrayBufferToBase64 = Binary.toBase64;
208
- var hexToArrayBuffer = Binary.fromHex;
209
- var arrayBufferToHex = Binary.toHex;
210
- function clone(source, refs = /* @__PURE__ */ new Map()) {
211
- if (!source || typeof source !== "object") return source;
212
- if (is("Date", source)) return new Date(source.valueOf());
213
- if (is("RegExp", source)) return new RegExp(source.source, source.flags);
214
- if (isArrayBufferLike(source)) return source.slice(0);
215
- if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
216
- const cached = refs.get(source);
217
- if (cached) return cached;
218
- if (Array.isArray(source)) {
219
- const result2 = [];
220
- refs.set(source, result2);
221
- source.forEach((value, index) => {
222
- result2[index] = Reflect.apply(clone, null, [value, refs]);
223
- });
224
- return result2;
225
- }
226
- const result = Object.create(Object.getPrototypeOf(source));
227
- refs.set(source, result);
228
- for (const key of Reflect.ownKeys(source)) {
229
- const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
230
- if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
231
- Reflect.defineProperty(result, key, descriptor);
232
- }
233
- return result;
234
- }
235
- function deepEqual(a, b, strict) {
236
- if (a === b) return true;
237
- if (!strict && isNullable(a) && isNullable(b)) return true;
238
- if (typeof a !== typeof b) return false;
239
- if (typeof a !== "object") return false;
240
- if (!a || !b) return false;
241
- function check(test, then) {
242
- return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
243
- }
244
- return check(Array.isArray, (a2, b2) => a2.length === b2.length && a2.every((item, index) => deepEqual(item, b2[index]))) ?? check(is("Date"), (a2, b2) => a2.valueOf() === b2.valueOf()) ?? check(is("RegExp"), (a2, b2) => a2.source === b2.source && a2.flags === b2.flags) ?? check(isArrayBufferLike, (a2, b2) => {
245
- if (a2.byteLength !== b2.byteLength) return false;
246
- const viewA = new Uint8Array(a2);
247
- const viewB = new Uint8Array(b2);
248
- for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
249
- return true;
250
- }) ?? Object.keys({
251
- ...a,
252
- ...b
253
- }).every((key) => deepEqual(a[key], b[key], strict));
254
- }
255
- function capitalize(source) {
256
- return source.charAt(0).toUpperCase() + source.slice(1);
257
- }
258
- function uncapitalize(source) {
259
- return source.charAt(0).toLowerCase() + source.slice(1);
260
- }
261
- function camelCase(source) {
262
- return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
263
- }
264
- function tokenize(source, delimiters, delimiter) {
265
- const output = [];
266
- let state = 0;
267
- for (let i = 0; i < source.length; i++) {
268
- const code = source.charCodeAt(i);
269
- if (code >= 65 && code <= 90) {
270
- if (state === 1) {
271
- const next = source.charCodeAt(i + 1);
272
- if (next >= 97 && next <= 122) output.push(delimiter);
273
- output.push(code + 32);
274
- } else {
275
- if (state !== 0) output.push(delimiter);
276
- output.push(code + 32);
277
- }
278
- state = 1;
279
- } else if (code >= 97 && code <= 122) {
280
- output.push(code);
281
- state = 2;
282
- } else if (delimiters.includes(code)) {
283
- if (state !== 0) output.push(delimiter);
284
- state = 0;
285
- } else output.push(code);
286
- }
287
- return String.fromCharCode(...output);
288
- }
289
- function paramCase(source) {
290
- return tokenize(source, [45, 95], 45);
291
- }
292
- function snakeCase(source) {
293
- return tokenize(source, [45, 95], 95);
294
- }
295
- var camelize = camelCase;
296
- var hyphenate = paramCase;
297
- function formatProperty(key) {
298
- if (typeof key !== "string") return `[${key.toString()}]`;
299
- return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
300
- }
301
- function trimSlash(source) {
302
- return source.replace(/\/$/, "");
303
- }
304
- function sanitize(source) {
305
- if (!source.startsWith("/")) source = "/" + source;
306
- return trimSlash(source);
307
- }
308
- var Time;
309
- ((Time2) => {
310
- Time2.millisecond = 1;
311
- Time2.second = 1e3;
312
- Time2.minute = Time2.second * 60;
313
- Time2.hour = Time2.minute * 60;
314
- Time2.day = Time2.hour * 24;
315
- Time2.week = Time2.day * 7;
316
- let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
317
- function setTimezoneOffset(offset) {
318
- timezoneOffset = offset;
319
- }
320
- Time2.setTimezoneOffset = setTimezoneOffset;
321
- function getTimezoneOffset() {
322
- return timezoneOffset;
323
- }
324
- Time2.getTimezoneOffset = getTimezoneOffset;
325
- function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
326
- if (typeof date === "number") date = new Date(date);
327
- if (offset === void 0) offset = timezoneOffset;
328
- return Math.floor((date.valueOf() / Time2.minute - offset) / 1440);
329
- }
330
- Time2.getDateNumber = getDateNumber;
331
- function fromDateNumber(value, offset) {
332
- const date = new Date(value * Time2.day);
333
- if (offset === void 0) offset = timezoneOffset;
334
- return new Date(+date + offset * Time2.minute);
335
- }
336
- Time2.fromDateNumber = fromDateNumber;
337
- const numeric = /\d+(?:\.\d+)?/.source;
338
- const timeRegExp = new RegExp(`^${[
339
- "w(?:eek(?:s)?)?",
340
- "d(?:ay(?:s)?)?",
341
- "h(?:our(?:s)?)?",
342
- "m(?:in(?:ute)?(?:s)?)?",
343
- "s(?:ec(?:ond)?(?:s)?)?"
344
- ].map((unit) => `(${numeric}${unit})?`).join("")}$`);
345
- function parseTime(source) {
346
- const capture = timeRegExp.exec(source);
347
- if (!capture) return 0;
348
- return (parseFloat(capture[1]) * Time2.week || 0) + (parseFloat(capture[2]) * Time2.day || 0) + (parseFloat(capture[3]) * Time2.hour || 0) + (parseFloat(capture[4]) * Time2.minute || 0) + (parseFloat(capture[5]) * Time2.second || 0);
349
- }
350
- Time2.parseTime = parseTime;
351
- function parseDate(date) {
352
- const parsed = parseTime(date);
353
- if (parsed) date = Date.now() + parsed;
354
- else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
355
- else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
356
- return date ? new Date(date) : /* @__PURE__ */ new Date();
357
- }
358
- Time2.parseDate = parseDate;
359
- function format(ms) {
360
- const abs = Math.abs(ms);
361
- if (abs >= Time2.day - Time2.hour / 2) return Math.round(ms / Time2.day) + "d";
362
- else if (abs >= Time2.hour - Time2.minute / 2) return Math.round(ms / Time2.hour) + "h";
363
- else if (abs >= Time2.minute - Time2.second / 2) return Math.round(ms / Time2.minute) + "m";
364
- else if (abs >= Time2.second) return Math.round(ms / Time2.second) + "s";
365
- return ms + "ms";
366
- }
367
- Time2.format = format;
368
- function toDigits(source, length = 2) {
369
- return source.toString().padStart(length, "0");
370
- }
371
- Time2.toDigits = toDigits;
372
- function template(template2, time = /* @__PURE__ */ new Date()) {
373
- return template2.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
374
- }
375
- Time2.template = template;
376
- })(Time || (Time = {}));
377
- 0 && (module.exports = {
378
- Binary,
379
- Time,
380
- arrayBufferToBase64,
381
- arrayBufferToHex,
382
- base64ToArrayBuffer,
383
- camelCase,
384
- camelize,
385
- capitalize,
386
- clone,
387
- contain,
388
- deduplicate,
389
- deepEqual,
390
- defineProperty,
391
- difference,
392
- filterKeys,
393
- formatProperty,
394
- hexToArrayBuffer,
395
- hyphenate,
396
- intersection,
397
- is,
398
- isNonNullable,
399
- isNullable,
400
- isPlainObject,
401
- makeArray,
402
- mapValues,
403
- noop,
404
- omit,
405
- paramCase,
406
- pick,
407
- remove,
408
- sanitize,
409
- snakeCase,
410
- trimSlash,
411
- uncapitalize,
412
- union,
413
- valueMap
414
- });
415
- }));
416
- //#endregion
417
14
  //#region src/dsh-home.ts
418
- var import_lib = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
419
- var __defProp = Object.defineProperty;
420
- var __name = (target, value) => __defProp(target, "name", {
421
- value,
422
- configurable: true
423
- });
424
- var import_cosmokit = require_lib$1();
425
- var kSchema = Symbol.for("schemastery");
426
- var kValidationError = Symbol.for("ValidationError");
427
- globalThis.__schemastery_index__ ??= 0;
428
- globalThis.__schemastery_refs__ = void 0;
429
- var ValidationError = class extends TypeError {
430
- constructor(message, options) {
431
- let prefix = "$";
432
- for (const segment of options.path || []) if (typeof segment === "string") prefix += "." + segment;
433
- else if (typeof segment === "number") prefix += "[" + segment + "]";
434
- else if (typeof segment === "symbol") prefix += `[Symbol(${segment.toString()})]`;
435
- if (prefix.startsWith(".")) prefix = prefix.slice(1);
436
- super((prefix === "$" ? "" : `${prefix} `) + message);
437
- this.options = options;
438
- }
439
- static {
440
- __name(this, "ValidationError");
441
- }
442
- name = "ValidationError";
443
- static is(error) {
444
- return !!error?.[kValidationError];
445
- }
446
- };
447
- Object.defineProperty(ValidationError.prototype, kValidationError, { value: true });
448
- var Schema = /* @__PURE__ */ __name(function(options) {
449
- const schema = /* @__PURE__ */ __name(function(data, options2 = {}) {
450
- return Schema.resolve(data, schema, options2)[0];
451
- }, "schema");
452
- if (options.refs) {
453
- const refs = (0, import_cosmokit.valueMap)(options.refs, (options2) => new Schema(options2));
454
- const getRef = /* @__PURE__ */ __name((uid) => refs[uid], "getRef");
455
- for (const key in refs) {
456
- const options2 = refs[key];
457
- options2.sKey = getRef(options2.sKey);
458
- options2.inner = getRef(options2.inner);
459
- options2.list = options2.list && options2.list.map(getRef);
460
- options2.dict = options2.dict && (0, import_cosmokit.valueMap)(options2.dict, getRef);
461
- }
462
- return refs[options.uid];
463
- }
464
- Object.assign(schema, options);
465
- if (typeof schema.callback === "string") try {
466
- schema.callback = new Function("return " + schema.callback)();
467
- } catch {}
468
- Object.defineProperty(schema, "uid", { value: globalThis.__schemastery_index__++ });
469
- Object.setPrototypeOf(schema, Schema.prototype);
470
- schema.meta ||= {};
471
- schema.toString = schema.toString.bind(schema);
472
- return schema;
473
- }, "Schema");
474
- Schema.prototype = Object.create(Function.prototype);
475
- Schema.prototype[kSchema] = true;
476
- Object.defineProperty(Schema.prototype, "~standard", { get() {
477
- return {
478
- version: 1,
479
- vendor: "schemastery",
480
- validate: /* @__PURE__ */ __name((value) => {
481
- try {
482
- return { value: Schema.resolve(value, this, {})[0] };
483
- } catch (error) {
484
- if (ValidationError.is(error)) return { issues: [{
485
- message: error.message,
486
- path: error.options.path
487
- }] };
488
- throw error;
489
- }
490
- }, "validate")
491
- };
492
- } });
493
- Schema.ValidationError = ValidationError;
494
- Schema.prototype.toJSON = /* @__PURE__ */ __name(function toJSON() {
495
- if (globalThis.__schemastery_refs__) {
496
- globalThis.__schemastery_refs__[this.uid] ??= JSON.parse(JSON.stringify({ ...this }));
497
- return this.uid;
498
- }
499
- globalThis.__schemastery_refs__ = { [this.uid]: { ...this } };
500
- globalThis.__schemastery_refs__[this.uid] = JSON.parse(JSON.stringify({ ...this }));
501
- const result = {
502
- uid: this.uid,
503
- refs: globalThis.__schemastery_refs__
504
- };
505
- globalThis.__schemastery_refs__ = void 0;
506
- return result;
507
- }, "toJSON");
508
- Schema.prototype.set = /* @__PURE__ */ __name(function set(key, value) {
509
- this.dict[key] = value;
510
- return this;
511
- }, "set");
512
- Schema.prototype.push = /* @__PURE__ */ __name(function push(value) {
513
- this.list.push(value);
514
- return this;
515
- }, "push");
516
- function mergeDesc(original, messages) {
517
- const result = typeof original === "string" ? { "": original } : { ...original };
518
- for (const locale in messages) {
519
- const value = messages[locale];
520
- if (value?.$description || value?.$desc) result[locale] = value.$description || value.$desc;
521
- else if (typeof value === "string") result[locale] = value;
522
- }
523
- return result;
524
- }
525
- __name(mergeDesc, "mergeDesc");
526
- function getInner(value) {
527
- return value?.$value ?? value?.$inner;
528
- }
529
- __name(getInner, "getInner");
530
- function extractKeys(data) {
531
- return (0, import_cosmokit.filterKeys)(data ?? {}, (key) => !key.startsWith("$"));
532
- }
533
- __name(extractKeys, "extractKeys");
534
- Schema.prototype.i18n = /* @__PURE__ */ __name(function i18n(messages) {
535
- const schema = Schema(this);
536
- const desc = mergeDesc(schema.meta.description, messages);
537
- if (Object.keys(desc).length) schema.meta.description = desc;
538
- if (schema.dict) schema.dict = (0, import_cosmokit.valueMap)(schema.dict, (inner, key) => {
539
- return inner.i18n((0, import_cosmokit.valueMap)(messages, (data) => getInner(data)?.[key] ?? data?.[key]));
540
- });
541
- if (schema.list) schema.list = schema.list.map((inner, index) => {
542
- return inner.i18n((0, import_cosmokit.valueMap)(messages, (data = {}) => {
543
- if (Array.isArray(getInner(data))) return getInner(data)[index];
544
- if (Array.isArray(data)) return data[index];
545
- return extractKeys(data);
546
- }));
547
- });
548
- if (schema.inner) schema.inner = schema.inner.i18n((0, import_cosmokit.valueMap)(messages, (data) => {
549
- if (getInner(data)) return getInner(data);
550
- return extractKeys(data);
551
- }));
552
- if (schema.sKey) schema.sKey = schema.sKey.i18n((0, import_cosmokit.valueMap)(messages, (data) => data?.$key));
553
- return schema;
554
- }, "i18n");
555
- Schema.prototype.extra = /* @__PURE__ */ __name(function extra(key, value) {
556
- const schema = Schema(this);
557
- schema.meta = {
558
- ...schema.meta,
559
- [key]: value
560
- };
561
- return schema;
562
- }, "extra");
563
- for (const key of [
564
- "required",
565
- "disabled",
566
- "collapse",
567
- "hidden",
568
- "loose"
569
- ]) Object.assign(Schema.prototype, { [key](value = true) {
570
- const schema = Schema(this);
571
- schema.meta = {
572
- ...schema.meta,
573
- [key]: value
574
- };
575
- return schema;
576
- } });
577
- Schema.prototype.deprecated = /* @__PURE__ */ __name(function deprecated() {
578
- const schema = Schema(this);
579
- schema.meta.badges ||= [];
580
- schema.meta.badges.push({
581
- text: "deprecated",
582
- type: "danger"
583
- });
584
- return schema;
585
- }, "deprecated");
586
- Schema.prototype.experimental = /* @__PURE__ */ __name(function experimental() {
587
- const schema = Schema(this);
588
- schema.meta.badges ||= [];
589
- schema.meta.badges.push({
590
- text: "experimental",
591
- type: "warning"
592
- });
593
- return schema;
594
- }, "experimental");
595
- Schema.prototype.pattern = /* @__PURE__ */ __name(function pattern(regexp) {
596
- const schema = Schema(this);
597
- const pattern2 = (0, import_cosmokit.pick)(regexp, ["source", "flags"]);
598
- schema.meta = {
599
- ...schema.meta,
600
- pattern: pattern2
601
- };
602
- return schema;
603
- }, "pattern");
604
- Schema.prototype.simplify = /* @__PURE__ */ __name(function simplify(value) {
605
- if ((0, import_cosmokit.deepEqual)(value, this.meta.default, this.type === "dict")) return null;
606
- if ((0, import_cosmokit.isNullable)(value)) return value;
607
- if (this.type === "object" || this.type === "dict") {
608
- const result = {};
609
- for (const key in value) {
610
- const item = (this.type === "object" ? this.dict[key] : this.inner)?.simplify(value[key]);
611
- if (this.type === "dict" || !(0, import_cosmokit.isNullable)(item)) result[key] = item;
612
- }
613
- if ((0, import_cosmokit.deepEqual)(result, this.meta.default, this.type === "dict")) return null;
614
- return result;
615
- } else if (this.type === "array" || this.type === "tuple") {
616
- const result = [];
617
- value.forEach((value2, index) => {
618
- const schema = this.type === "array" ? this.inner : this.list[index];
619
- const item = schema ? schema.simplify(value2) : value2;
620
- result.push(item);
621
- });
622
- return result;
623
- } else if (this.type === "intersect") {
624
- const result = {};
625
- for (const item of this.list) Object.assign(result, item.simplify(value));
626
- return result;
627
- } else if (this.type === "union") for (const schema of this.list) try {
628
- Schema.resolve(value, schema, {});
629
- return schema.simplify(value);
630
- } catch {}
631
- return value;
632
- }, "simplify");
633
- Schema.prototype.toString = /* @__PURE__ */ __name(function toString(inline) {
634
- return formatters[this.type]?.(this, inline) ?? `Schema<${this.type}>`;
635
- }, "toString");
636
- Schema.prototype.role = /* @__PURE__ */ __name(function role(role, extra2) {
637
- const schema = Schema(this);
638
- schema.meta = {
639
- ...schema.meta,
640
- role,
641
- extra: extra2
642
- };
643
- return schema;
644
- }, "role");
645
- for (const key of [
646
- "default",
647
- "link",
648
- "comment",
649
- "description",
650
- "max",
651
- "min",
652
- "step"
653
- ]) Object.assign(Schema.prototype, { [key](value) {
654
- const schema = Schema(this);
655
- schema.meta = {
656
- ...schema.meta,
657
- [key]: value
658
- };
659
- return schema;
660
- } });
661
- var resolvers = {};
662
- Schema.extend = /* @__PURE__ */ __name(function extend(type, resolve2) {
663
- resolvers[type] = resolve2;
664
- }, "extend");
665
- Schema.resolve = /* @__PURE__ */ __name(function resolve(data, schema, options = {}, strict = false) {
666
- if (!schema) return [data];
667
- if (options.ignore?.(data, schema)) return [data];
668
- if ((0, import_cosmokit.isNullable)(data) && schema.type !== "lazy") {
669
- if (schema.meta.required) throw new ValidationError(`missing required value`, options);
670
- let current = schema;
671
- let fallback = schema.meta.default;
672
- while (current?.type === "intersect" && (0, import_cosmokit.isNullable)(fallback)) {
673
- current = current.list[0];
674
- fallback = current?.meta.default;
675
- }
676
- if ((0, import_cosmokit.isNullable)(fallback)) return [data];
677
- data = (0, import_cosmokit.clone)(fallback);
678
- }
679
- const callback = resolvers[schema.type];
680
- if (!callback) throw new ValidationError(`unsupported type "${schema.type}"`, options);
681
- try {
682
- return callback(data, schema, options, strict);
683
- } catch (error) {
684
- if (!schema.meta.loose) throw error;
685
- return [schema.meta.default];
686
- }
687
- }, "resolve");
688
- Schema.from = /* @__PURE__ */ __name(function from(source) {
689
- if ((0, import_cosmokit.isNullable)(source)) return Schema.any();
690
- else if ([
691
- "string",
692
- "number",
693
- "boolean"
694
- ].includes(typeof source)) return Schema.const(source).required();
695
- else if (source[kSchema]) return source;
696
- else if (typeof source === "function") switch (source) {
697
- case String: return Schema.string().required();
698
- case Number: return Schema.number().required();
699
- case Boolean: return Schema.boolean().required();
700
- case Function: return Schema.function().required();
701
- default: return Schema.is(source).required();
702
- }
703
- else throw new TypeError(`cannot infer schema from ${source}`);
704
- }, "from");
705
- Schema.lazy = /* @__PURE__ */ __name(function lazy(builder) {
706
- const schema = new Schema({
707
- type: "lazy",
708
- builder,
709
- inner: { toJSON: /* @__PURE__ */ __name(() => {
710
- if (!schema.inner[kSchema]) {
711
- schema.inner = schema.builder();
712
- schema.inner.meta = {
713
- ...schema.meta,
714
- ...schema.inner.meta
715
- };
716
- }
717
- return schema.inner.toJSON();
718
- }, "toJSON") }
719
- });
720
- return schema;
721
- }, "lazy");
722
- Schema.natural = /* @__PURE__ */ __name(function natural() {
723
- return Schema.number().step(1).min(0);
724
- }, "natural");
725
- Schema.percent = /* @__PURE__ */ __name(function percent() {
726
- return Schema.number().step(.01).min(0).max(1).role("slider");
727
- }, "percent");
728
- Schema.date = /* @__PURE__ */ __name(function date() {
729
- return Schema.union([Schema.is(Date), Schema.transform(Schema.string().role("datetime"), (value, options) => {
730
- const date2 = new Date(value);
731
- if (isNaN(+date2)) throw new ValidationError(`invalid date "${value}"`, options);
732
- return date2;
733
- }, true)]);
734
- }, "date");
735
- Schema.regExp = /* @__PURE__ */ __name(function regExp(flag = "") {
736
- return Schema.union([Schema.is(RegExp), Schema.transform(Schema.string().role("regexp", { flag }), (value, options) => {
737
- try {
738
- return new RegExp(value, flag);
739
- } catch (e) {
740
- throw new ValidationError(e.message, options);
741
- }
742
- }, true)]);
743
- }, "regExp");
744
- Schema.arrayBuffer = /* @__PURE__ */ __name(function arrayBuffer(encoding) {
745
- return Schema.union([
746
- Schema.is(ArrayBuffer),
747
- Schema.is(SharedArrayBuffer),
748
- Schema.transform(Schema.any(), (value, options) => {
749
- if (import_cosmokit.Binary.isSource(value)) return import_cosmokit.Binary.fromSource(value);
750
- throw new ValidationError(`expected ArrayBufferSource but got ${value}`, options);
751
- }, true),
752
- ...encoding ? [Schema.transform(Schema.string(), (value, options) => {
753
- try {
754
- return encoding === "base64" ? import_cosmokit.Binary.fromBase64(value) : import_cosmokit.Binary.fromHex(value);
755
- } catch (e) {
756
- throw new ValidationError(e.message, options);
757
- }
758
- }, true)] : []
759
- ]);
760
- }, "arrayBuffer");
761
- Schema.extend("lazy", (data, schema, options, strict) => {
762
- if (!schema.inner[kSchema]) {
763
- schema.inner = schema.builder();
764
- schema.inner.meta = {
765
- ...schema.meta,
766
- ...schema.inner.meta
767
- };
768
- }
769
- return Schema.resolve(data, schema.inner, options, strict);
770
- });
771
- Schema.extend("any", (data) => {
772
- return [data];
773
- });
774
- Schema.extend("never", (data, _, options) => {
775
- throw new ValidationError(`expected nullable but got ${data}`, options);
776
- });
777
- Schema.extend("const", (data, { value }, options) => {
778
- if ((0, import_cosmokit.deepEqual)(data, value)) return [value];
779
- throw new ValidationError(`expected ${value} but got ${data}`, options);
780
- });
781
- function checkWithinRange(data, meta, description, options, skipMin = false) {
782
- const { max = Infinity, min = -Infinity } = meta;
783
- if (data > max) throw new ValidationError(`expected ${description} <= ${max} but got ${data}`, options);
784
- if (data < min && !skipMin) throw new ValidationError(`expected ${description} >= ${min} but got ${data}`, options);
785
- }
786
- __name(checkWithinRange, "checkWithinRange");
787
- Schema.extend("string", (data, { meta }, options) => {
788
- if (typeof data !== "string") throw new ValidationError(`expected string but got ${data}`, options);
789
- if (meta.pattern) {
790
- const regexp = new RegExp(meta.pattern.source, meta.pattern.flags);
791
- if (!regexp.test(data)) throw new ValidationError(`expect string to match regexp ${regexp}`, options);
792
- }
793
- checkWithinRange(data.length, meta, "string length", options);
794
- return [data];
795
- });
796
- function decimalShift(data, digits) {
797
- const str = data.toString();
798
- if (str.includes("e")) return data * Math.pow(10, digits);
799
- const index = str.indexOf(".");
800
- if (index === -1) return data * Math.pow(10, digits);
801
- const frac = str.slice(index + 1);
802
- const integer = str.slice(0, index);
803
- if (frac.length <= digits) return +(integer + frac.padEnd(digits, "0"));
804
- return +(integer + frac.slice(0, digits) + "." + frac.slice(digits));
805
- }
806
- __name(decimalShift, "decimalShift");
807
- function isMultipleOf(data, min, step) {
808
- step = Math.abs(step);
809
- if (!/^\d+\.\d+$/.test(step.toString())) return (data - min) % step === 0;
810
- const index = step.toString().indexOf(".");
811
- const digits = step.toString().slice(index + 1).length;
812
- return Math.abs(decimalShift(data, digits) - decimalShift(min, digits)) % decimalShift(step, digits) === 0;
813
- }
814
- __name(isMultipleOf, "isMultipleOf");
815
- Schema.extend("number", (data, { meta }, options) => {
816
- if (typeof data !== "number") throw new ValidationError(`expected number but got ${data}`, options);
817
- checkWithinRange(data, meta, "number", options);
818
- const { step } = meta;
819
- if (step && !isMultipleOf(data, meta.min ?? 0, step)) throw new ValidationError(`expected number multiple of ${step} but got ${data}`, options);
820
- return [data];
821
- });
822
- Schema.extend("boolean", (data, _, options) => {
823
- if (typeof data === "boolean") return [data];
824
- throw new ValidationError(`expected boolean but got ${data}`, options);
825
- });
826
- Schema.extend("bitset", (data, { bits, meta }, options) => {
827
- let value = 0, keys = [];
828
- if (typeof data === "number") {
829
- value = data;
830
- for (const key in bits) if (data & bits[key]) keys.push(key);
831
- } else if (Array.isArray(data)) {
832
- keys = data;
833
- for (const key of keys) {
834
- if (typeof key !== "string") throw new ValidationError(`expected string but got ${key}`, options);
835
- if (key in bits) value |= bits[key];
836
- }
837
- } else throw new ValidationError(`expected number or array but got ${data}`, options);
838
- if (value === meta.default) return [value];
839
- return [value, keys];
840
- });
841
- Schema.extend("function", (data, _, options) => {
842
- if (typeof data === "function") return [data];
843
- throw new ValidationError(`expected function but got ${data}`, options);
844
- });
845
- Schema.extend("is", (data, { constructor }, options) => {
846
- if (typeof constructor === "function") {
847
- if (data instanceof constructor) return [data];
848
- throw new ValidationError(`expected ${constructor.name} but got ${data}`, options);
849
- } else {
850
- if ((0, import_cosmokit.isNullable)(data)) throw new ValidationError(`expected ${constructor} but got ${data}`, options);
851
- let prototype = Object.getPrototypeOf(data);
852
- while (prototype) {
853
- if (prototype.constructor?.name === constructor) return [data];
854
- prototype = Object.getPrototypeOf(prototype);
855
- }
856
- throw new ValidationError(`expected ${constructor} but got ${data}`, options);
857
- }
858
- });
859
- function property(data, key, schema, options) {
860
- try {
861
- const [value, adapted] = Schema.resolve(data[key], schema, {
862
- ...options,
863
- path: [...options.path || [], key]
864
- });
865
- if (adapted !== void 0) data[key] = adapted;
866
- return value;
867
- } catch (e) {
868
- if (!options?.autofix) throw e;
869
- delete data[key];
870
- return schema.meta.default;
871
- }
872
- }
873
- __name(property, "property");
874
- Schema.extend("array", (data, { inner, meta }, options) => {
875
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
876
- checkWithinRange(data.length, meta, "array length", options, !(0, import_cosmokit.isNullable)(inner.meta.default));
877
- return [data.map((_, index) => property(data, index, inner, options))];
878
- });
879
- Schema.extend("dict", (data, { inner, sKey }, options, strict) => {
880
- if (!(0, import_cosmokit.isPlainObject)(data)) throw new ValidationError(`expected object but got ${data}`, options);
881
- const result = {};
882
- for (const key in data) {
883
- let rKey;
884
- try {
885
- rKey = Schema.resolve(key, sKey, options)[0];
886
- } catch (error) {
887
- if (strict) continue;
888
- throw error;
889
- }
890
- result[rKey] = property(data, key, inner, options);
891
- data[rKey] = data[key];
892
- if (key !== rKey) delete data[key];
893
- }
894
- return [result];
895
- });
896
- Schema.extend("tuple", (data, { list }, options, strict) => {
897
- if (!Array.isArray(data)) throw new ValidationError(`expected array but got ${data}`, options);
898
- const result = list.map((inner, index) => property(data, index, inner, options));
899
- if (strict) return [result];
900
- result.push(...data.slice(list.length));
901
- return [result];
902
- });
903
- function merge(result, data) {
904
- for (const key in data) {
905
- if (key in result) continue;
906
- result[key] = data[key];
907
- }
908
- }
909
- __name(merge, "merge");
910
- Schema.extend("object", (data, { dict }, options, strict) => {
911
- if (!(0, import_cosmokit.isPlainObject)(data)) throw new ValidationError(`expected object but got ${data}`, options);
912
- const result = {};
913
- for (const key in dict) {
914
- const value = property(data, key, dict[key], options);
915
- if (!(0, import_cosmokit.isNullable)(value) || key in data) result[key] = value;
916
- }
917
- if (!strict) merge(result, data);
918
- return [result];
919
- });
920
- Schema.extend("union", (data, { list, toString: toString2 }, options, strict) => {
921
- const messages = [];
922
- for (const inner of list) try {
923
- return Schema.resolve(data, inner, options, strict);
924
- } catch (error) {
925
- messages.push(error);
926
- }
927
- throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
928
- });
929
- Schema.extend("intersect", (data, { list, toString: toString2 }, options, strict) => {
930
- if (!list.length) return [data];
931
- let result;
932
- for (const inner of list) {
933
- const value = Schema.resolve(data, inner, options, true)[0];
934
- if ((0, import_cosmokit.isNullable)(value)) continue;
935
- if ((0, import_cosmokit.isNullable)(result)) result = value;
936
- else if (typeof result !== typeof value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
937
- else if (typeof value === "object") merge(result ??= {}, value);
938
- else if (result !== value) throw new ValidationError(`expected ${toString2()} but got ${JSON.stringify(data)}`, options);
939
- }
940
- if (!strict && (0, import_cosmokit.isPlainObject)(data)) merge(result, data);
941
- return [result];
942
- });
943
- Schema.extend("transform", (data, { inner, callback, preserve }, options) => {
944
- const [result, adapted = data] = Schema.resolve(data, inner, options, true);
945
- if (preserve) return [callback(result)];
946
- else return [callback(result), callback(adapted)];
947
- });
948
- var formatters = {};
949
- function defineMethod(name, keys, format) {
950
- formatters[name] = format;
951
- Object.assign(Schema, { [name](...args) {
952
- const schema = new Schema({ type: name });
953
- keys.forEach((key, index) => {
954
- switch (key) {
955
- case "sKey":
956
- schema.sKey = args[index] ?? Schema.string();
957
- break;
958
- case "inner":
959
- schema.inner = Schema.from(args[index]);
960
- break;
961
- case "list":
962
- schema.list = args[index].map(Schema.from);
963
- break;
964
- case "dict":
965
- schema.dict = (0, import_cosmokit.valueMap)(args[index], Schema.from);
966
- break;
967
- case "bits":
968
- schema.bits = {};
969
- for (const key2 in args[index]) {
970
- if (typeof args[index][key2] !== "number") continue;
971
- schema.bits[key2] = args[index][key2];
972
- }
973
- break;
974
- case "callback": {
975
- const callback = schema.callback = args[index];
976
- callback["toJSON"] ||= () => callback.toString();
977
- break;
978
- }
979
- case "constructor": {
980
- const constructor = schema.constructor = args[index];
981
- if (typeof constructor === "function") constructor["toJSON"] ||= () => constructor["name"];
982
- break;
983
- }
984
- default: schema[key] = args[index];
985
- }
986
- });
987
- if (name === "object" || name === "dict") schema.meta.default = {};
988
- else if (name === "array" || name === "tuple") schema.meta.default = [];
989
- else if (name === "bitset") schema.meta.default = 0;
990
- return schema;
991
- } });
992
- }
993
- __name(defineMethod, "defineMethod");
994
- defineMethod("is", ["constructor"], ({ constructor }) => {
995
- if (typeof constructor === "function") return constructor.name;
996
- else return constructor;
997
- });
998
- defineMethod("any", [], () => "any");
999
- defineMethod("never", [], () => "never");
1000
- defineMethod("const", ["value"], ({ value }) => typeof value === "string" ? JSON.stringify(value) : value);
1001
- defineMethod("string", [], () => "string");
1002
- defineMethod("number", [], () => "number");
1003
- defineMethod("boolean", [], () => "boolean");
1004
- defineMethod("bitset", ["bits"], () => "bitset");
1005
- defineMethod("function", [], () => "function");
1006
- defineMethod("array", ["inner"], ({ inner }) => `${inner.toString(true)}[]`);
1007
- defineMethod("dict", ["inner", "sKey"], ({ inner, sKey }) => `{ [key: ${sKey.toString()}]: ${inner.toString()} }`);
1008
- defineMethod("tuple", ["list"], ({ list }) => `[${list.map((inner) => inner.toString()).join(", ")}]`);
1009
- defineMethod("object", ["dict"], ({ dict }) => {
1010
- if (Object.keys(dict).length === 0) return "{}";
1011
- return `{ ${Object.entries(dict).map(([key, inner]) => {
1012
- return `${key}${inner.meta.required ? "" : "?"}: ${inner.toString()}`;
1013
- }).join(", ")} }`;
1014
- });
1015
- defineMethod("union", ["list"], ({ list }, inline) => {
1016
- const result = list.map(({ toString: format }) => format()).join(" | ");
1017
- return inline ? `(${result})` : result;
1018
- });
1019
- defineMethod("intersect", ["list"], ({ list }) => {
1020
- return `${list.map((inner) => inner.toString(true)).join(" & ")}`;
1021
- });
1022
- defineMethod("transform", [
1023
- "inner",
1024
- "callback",
1025
- "preserve"
1026
- ], ({ inner }, isInner) => inner.toString(isInner));
1027
- module.exports = Schema;
1028
- })))(), 1);
1029
15
  /**
1030
16
  * DSH_HOME resolution shared by the plugin family's Host halves: the
1031
17
  * environment override wins, the platform home fallback follows. Mirrors
@@ -4019,18 +3005,36 @@ const inject = [
4019
3005
  "systemPrompt"
4020
3006
  ];
4021
3007
  /**
4022
- * Settings namespace of the SSH capability — the section the web settings
4023
- * surface edits. Spelled here rather than imported: the browser half spells
4024
- * the same value and must not depend on a Host package.
3008
+ * Plugin config schema. Under the 0.1.7 settings model this schema IS the
3009
+ * entry's settings page: the Host derives one form per profile entry from it
3010
+ * and serves it through the shared configuration forms. Every field is
3011
+ * `volatile()`, which is what puts it on that page and what lets an edit reach
3012
+ * a running instance without a remount: the loader commits the new value into
3013
+ * the field's reference and announces `loader/volatile-update` on this fiber.
4025
3014
  */
4026
- const SSH_SETTINGS_NAMESPACE = "dsh-ssh";
4027
- const Config = import_lib.default.object({
4028
- announceToAgent: import_lib.default.boolean().default(false),
4029
- enabled: import_lib.default.boolean().default(true),
4030
- terminalFontFamily: import_lib.default.string().default("")
3015
+ const Config = z.object({
3016
+ announceToAgent: z.boolean().default(false).volatile(),
3017
+ enabled: z.boolean().default(true).volatile(),
3018
+ terminalFontFamily: z.string().default("").volatile()
4031
3019
  });
4032
- /** Schema default, re-read for hand-built test contexts (the loader applies them normally). */
3020
+ /** Schema defaults, re-read for hand-built test contexts (the loader applies them normally). */
4033
3021
  const DEFAULT_ANNOUNCE = false;
3022
+ const DEFAULT_ENABLED = true;
3023
+ /** Read one resolved config field, following the live reference the schema produces. */
3024
+ function readConfigField(field, fallback) {
3025
+ if (field === void 0) return fallback;
3026
+ if (typeof field === "object" && field !== null && typeof field.get === "function") {
3027
+ const value = field.get();
3028
+ return value === void 0 ? fallback : value;
3029
+ }
3030
+ return field;
3031
+ }
3032
+ /** Raw config the profile declares for this entry, when the loader exposes it. */
3033
+ function profileConfig(ctx) {
3034
+ const config = ctx.fiber.entry?.options?.config;
3035
+ if (typeof config !== "object" || config === null || Array.isArray(config)) return void 0;
3036
+ return config;
3037
+ }
4034
3038
  /** Order of the announcement section within the tool-guidance band. */
4035
3039
  const SECTION_ORDER = 150;
4036
3040
  /** Model-facing announcement: plugin presence, capabilities, and limits. */
@@ -4042,19 +3046,16 @@ const SSH_GUIDANCE = "本机已安装 dsh-ssh 插件(DSH 远程 SSH 运维)
4042
3046
  */
4043
3047
  const apply = mountOnce("@linxin666/dsh-ssh", applyImpl);
4044
3048
  function applyImpl(ctx, config) {
4045
- let current = () => config ?? {};
4046
- let isSettingsBound = false;
4047
3049
  const store = new HostStore();
4048
3050
  const engine = new SshEngine(store);
4049
3051
  ctx.effect(() => () => {
4050
3052
  engine.dispose();
4051
3053
  }, "dsh-ssh: engine");
4052
3054
  const resolve = () => {
4053
- const value = current();
4054
- let enabled = value.enabled ?? true;
4055
- if (enabled === false && !isSettingsBound && store.list().length > 0) enabled = true;
3055
+ let enabled = readConfigField(config?.enabled, DEFAULT_ENABLED);
3056
+ if (enabled === false && profileConfig(ctx)?.enabled === void 0 && store.list().length > 0) enabled = true;
4056
3057
  return {
4057
- announceToAgent: value.announceToAgent ?? DEFAULT_ANNOUNCE,
3058
+ announceToAgent: readConfigField(config?.announceToAgent, DEFAULT_ANNOUNCE),
4058
3059
  enabled
4059
3060
  };
4060
3061
  };
@@ -4108,27 +3109,10 @@ function applyImpl(ctx, config) {
4108
3109
  };
4109
3110
  }, "dsh-ssh: tools");
4110
3111
  };
4111
- ctx.inject(["settings"], (settingsCtx) => {
4112
- try {
4113
- if (typeof settingsCtx.settings?.installSection === "function") settingsCtx.settings.installSection(ctx, SSH_SETTINGS_NAMESPACE, Config, config ?? {}, {
4114
- setSource: (source) => {
4115
- isSettingsBound = true;
4116
- current = source;
4117
- sync();
4118
- },
4119
- onChange: sync
4120
- });
4121
- else if (typeof settingsCtx.settings?.register === "function") {
4122
- const scope = settingsCtx.settings.register(SSH_SETTINGS_NAMESPACE, Config, { base: config ?? {} });
4123
- isSettingsBound = true;
4124
- current = () => scope?.get?.() ?? config ?? {};
4125
- scope?.watch?.(() => {
4126
- sync();
4127
- });
4128
- }
4129
- } catch {}
3112
+ ctx.on("loader/volatile-update", () => {
3113
+ sync();
4130
3114
  });
4131
3115
  sync();
4132
3116
  }
4133
3117
  //#endregion
4134
- export { Config, SSH_GUIDANCE, SSH_SETTINGS_NAMESPACE, apply, inject, name };
3118
+ export { Config, SSH_GUIDANCE, apply, inject, name };