dsh-agent-enhancer 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +14 -13
- package/README.md +12 -11
- package/lib/client/dsh/settings-catalog.d.ts +2 -2
- package/lib/client/dsh/settings-catalog.d.ts.map +1 -1
- package/lib/client/dsh/settings.d.ts.map +1 -1
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/locales.d.ts +282 -174
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/manager-shell.d.ts +1 -0
- package/lib/client/manager-shell.d.ts.map +1 -1
- package/lib/client/remote.d.ts +24 -0
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client/web-chat-bridge/capture-selectors.d.ts +47 -0
- package/lib/client/web-chat-bridge/capture-selectors.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/capture.d.ts +14 -0
- package/lib/client/web-chat-bridge/capture.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/export-markdown.d.ts +8 -0
- package/lib/client/web-chat-bridge/export-markdown.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/export-markdown.test.d.ts +2 -0
- package/lib/client/web-chat-bridge/export-markdown.test.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/guest-capture.d.ts +10 -0
- package/lib/client/web-chat-bridge/guest-capture.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/guest-policy-clipboard.test.d.ts +2 -0
- package/lib/client/web-chat-bridge/guest-policy-clipboard.test.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/guest-policy.d.ts +56 -0
- package/lib/client/web-chat-bridge/guest-policy.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/guest.d.ts +39 -0
- package/lib/client/web-chat-bridge/guest.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/guide-icon.d.ts +4 -0
- package/lib/client/web-chat-bridge/guide-icon.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/kind.d.ts +4 -0
- package/lib/client/web-chat-bridge/kind.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/left-nav.d.ts +27 -0
- package/lib/client/web-chat-bridge/left-nav.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/panel.d.ts +13 -0
- package/lib/client/web-chat-bridge/panel.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/preview-model.d.ts +7 -0
- package/lib/client/web-chat-bridge/preview-model.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/preview.d.ts +14 -0
- package/lib/client/web-chat-bridge/preview.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/remote.d.ts +33 -0
- package/lib/client/web-chat-bridge/remote.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/share-fetch.d.ts +7 -0
- package/lib/client/web-chat-bridge/share-fetch.d.ts.map +1 -0
- package/lib/client/web-chat-bridge/slot-types.d.ts +16 -0
- package/lib/client/web-chat-bridge/slot-types.d.ts.map +1 -0
- package/lib/client.js +2964 -1123
- package/lib/client.js.map +1 -1
- package/lib/config.d.ts +1 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/host/extra-folders/pick.d.ts +7 -0
- package/lib/host/extra-folders/pick.d.ts.map +1 -1
- package/lib/host/extra-folders/pick.test.d.ts +2 -0
- package/lib/host/extra-folders/pick.test.d.ts.map +1 -0
- package/lib/host/index.d.ts +46 -0
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +188 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/host/web-chat-bridge/import-session.d.ts +112 -0
- package/lib/host/web-chat-bridge/import-session.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/limits.d.ts +9 -0
- package/lib/host/web-chat-bridge/limits.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/login-snapshot-policy.d.ts +5 -0
- package/lib/host/web-chat-bridge/login-snapshot-policy.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/login-snapshot-types.d.ts +11 -0
- package/lib/host/web-chat-bridge/login-snapshot-types.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/login-snapshot.d.ts +14 -0
- package/lib/host/web-chat-bridge/login-snapshot.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/parse-export.d.ts +6 -0
- package/lib/host/web-chat-bridge/parse-export.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/parse-export.test.d.ts +2 -0
- package/lib/host/web-chat-bridge/parse-export.test.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/share-link.d.ts +29 -0
- package/lib/host/web-chat-bridge/share-link.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/share-link.test.d.ts +2 -0
- package/lib/host/web-chat-bridge/share-link.test.d.ts.map +1 -0
- package/lib/host/web-chat-bridge/types.d.ts +37 -0
- package/lib/host/web-chat-bridge/types.d.ts.map +1 -0
- package/lib/identity.d.ts +1 -1
- package/lib/identity.d.ts.map +1 -1
- package/lib/index.js +1847 -398
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/host/index.ts
|
|
2
|
-
import { existsSync as
|
|
2
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync11, readdirSync as readdirSync7, renameSync as renameSync9, rmdirSync } from "node:fs";
|
|
3
3
|
import { homedir as homedir6 } from "node:os";
|
|
4
|
-
import { join as
|
|
4
|
+
import { join as join32 } from "node:path";
|
|
5
5
|
import z5 from "@deepseek-ai/schemastery";
|
|
6
|
-
import { RemoteError, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
6
|
+
import { RemoteError as RemoteError2, TypertRemoteService } from "@deepseek-ai/dsh-typert-protocol";
|
|
7
7
|
|
|
8
8
|
// src/host/auto-route/sentinel.ts
|
|
9
9
|
var AUTO_PROVIDER = "agent-enhancer";
|
|
@@ -50,6 +50,7 @@ var DEFAULT_SETTINGS = {
|
|
|
50
50
|
runAlertsLevel: "unfocused",
|
|
51
51
|
browserAgentEnabled: false,
|
|
52
52
|
browserAgentBrowser: "auto",
|
|
53
|
+
webChatBridgeEnabled: true,
|
|
53
54
|
instructionsSkillsEnabled: true,
|
|
54
55
|
mcpConnectorsEnabled: true,
|
|
55
56
|
optimizeProvider: "",
|
|
@@ -94,6 +95,7 @@ function resolveSettings(value) {
|
|
|
94
95
|
runAlertsLevel: resolveRunAlertsLevel(value?.runAlertsLevel),
|
|
95
96
|
browserAgentEnabled: value?.browserAgentEnabled ?? false,
|
|
96
97
|
browserAgentBrowser: resolveBrowserAgentBrowser(value?.browserAgentBrowser),
|
|
98
|
+
webChatBridgeEnabled: value?.webChatBridgeEnabled ?? true,
|
|
97
99
|
instructionsSkillsEnabled: value?.instructionsSkillsEnabled ?? true,
|
|
98
100
|
mcpConnectorsEnabled: value?.mcpConnectorsEnabled ?? true,
|
|
99
101
|
optimizeProvider: text(value?.optimizeProvider),
|
|
@@ -253,7 +255,7 @@ var BrowserApprovalGate = class {
|
|
|
253
255
|
...input.url === void 0 ? {} : { url: input.url },
|
|
254
256
|
...origin === void 0 ? {} : { origin }
|
|
255
257
|
};
|
|
256
|
-
const decision = await new Promise((
|
|
258
|
+
const decision = await new Promise((resolve17, reject) => {
|
|
257
259
|
const onAbort = () => {
|
|
258
260
|
const entry = this.pending.get(id);
|
|
259
261
|
if (entry === void 0) return;
|
|
@@ -267,7 +269,7 @@ var BrowserApprovalGate = class {
|
|
|
267
269
|
};
|
|
268
270
|
this.pending.set(id, {
|
|
269
271
|
request,
|
|
270
|
-
resolve:
|
|
272
|
+
resolve: resolve17,
|
|
271
273
|
reject,
|
|
272
274
|
detachAbort
|
|
273
275
|
});
|
|
@@ -342,7 +344,7 @@ var BrowserHumanGate = class {
|
|
|
342
344
|
detail: input.detail,
|
|
343
345
|
...input.url === void 0 ? {} : { url: input.url }
|
|
344
346
|
};
|
|
345
|
-
return await new Promise((
|
|
347
|
+
return await new Promise((resolve17, reject) => {
|
|
346
348
|
const onAbort = () => {
|
|
347
349
|
const entry = this.pending.get(id);
|
|
348
350
|
if (entry === void 0) return;
|
|
@@ -356,7 +358,7 @@ var BrowserHumanGate = class {
|
|
|
356
358
|
};
|
|
357
359
|
this.pending.set(id, {
|
|
358
360
|
request,
|
|
359
|
-
resolve:
|
|
361
|
+
resolve: resolve17,
|
|
360
362
|
reject,
|
|
361
363
|
detachAbort
|
|
362
364
|
});
|
|
@@ -1321,8 +1323,8 @@ var PlaywrightDriver = class {
|
|
|
1321
1323
|
}
|
|
1322
1324
|
};
|
|
1323
1325
|
function sleep(ms) {
|
|
1324
|
-
return new Promise((
|
|
1325
|
-
setTimeout(
|
|
1326
|
+
return new Promise((resolve17) => {
|
|
1327
|
+
setTimeout(resolve17, ms);
|
|
1326
1328
|
});
|
|
1327
1329
|
}
|
|
1328
1330
|
async function settlePage(page, quietMs = 800) {
|
|
@@ -2795,7 +2797,7 @@ var AuxiliaryError = class extends Error {
|
|
|
2795
2797
|
// src/identity.ts
|
|
2796
2798
|
var PACKAGE_NAME = "dsh-agent-enhancer";
|
|
2797
2799
|
var PLUGIN_ID = "agent-enhancer";
|
|
2798
|
-
var PACKAGE_VERSION = "0.3.
|
|
2800
|
+
var PACKAGE_VERSION = "0.3.10";
|
|
2799
2801
|
var LEGACY_PACKAGE_NAME = "dsh-composer-enhancer";
|
|
2800
2802
|
var ROLLBACK_PREFIX = `${PACKAGE_NAME}:rollback:`;
|
|
2801
2803
|
var UNDO_PREFIX = `${PACKAGE_NAME}:undo:`;
|
|
@@ -6246,7 +6248,7 @@ async function removePathBestEffort(path) {
|
|
|
6246
6248
|
return true;
|
|
6247
6249
|
} catch {
|
|
6248
6250
|
if (attempt === 2) return false;
|
|
6249
|
-
await new Promise((
|
|
6251
|
+
await new Promise((resolve17) => setTimeout(resolve17, 120 * (attempt + 1)));
|
|
6250
6252
|
}
|
|
6251
6253
|
}
|
|
6252
6254
|
return false;
|
|
@@ -6374,35 +6376,20 @@ async function deleteSessionNow(options) {
|
|
|
6374
6376
|
};
|
|
6375
6377
|
}
|
|
6376
6378
|
|
|
6377
|
-
// src/host/
|
|
6378
|
-
import {
|
|
6379
|
-
import {
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
import {
|
|
6383
|
-
|
|
6384
|
-
|
|
6385
|
-
|
|
6386
|
-
|
|
6387
|
-
|
|
6388
|
-
|
|
6389
|
-
|
|
6390
|
-
|
|
6391
|
-
const rel = relative2(base, target);
|
|
6392
|
-
return rel === "" || !rel.startsWith(`..${sep3}`) && rel !== ".." && !isAbsolute3(rel);
|
|
6393
|
-
}
|
|
6394
|
-
function assertInsideAllowedRoots(primaryCwd, extraRoots, absolutePath2) {
|
|
6395
|
-
if (isInsideRoot(primaryCwd, absolutePath2)) return;
|
|
6396
|
-
for (const root of extraRoots) {
|
|
6397
|
-
if (isInsideRoot(root, absolutePath2)) return;
|
|
6398
|
-
}
|
|
6399
|
-
throw new Error("Path is outside the session workspace and attached folders");
|
|
6400
|
-
}
|
|
6401
|
-
function normalizeRootPath(path) {
|
|
6402
|
-
const trimmed = path.trim();
|
|
6403
|
-
if (trimmed === "") throw new Error("Path is empty");
|
|
6404
|
-
return resolve2(trimmed);
|
|
6405
|
-
}
|
|
6379
|
+
// src/host/web-chat-bridge/import-session.ts
|
|
6380
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
6381
|
+
import { existsSync as existsSync4, statSync } from "node:fs";
|
|
6382
|
+
import { resolve as resolve2 } from "node:path";
|
|
6383
|
+
import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
|
|
6384
|
+
import {
|
|
6385
|
+
createAssistantMessage,
|
|
6386
|
+
createSystemMessage,
|
|
6387
|
+
createUserMessage
|
|
6388
|
+
} from "@deepseek-ai/dsh-llm";
|
|
6389
|
+
import {
|
|
6390
|
+
SessionId,
|
|
6391
|
+
SessionSeq as SessionSeq2
|
|
6392
|
+
} from "@deepseek-ai/dsh-session";
|
|
6406
6393
|
|
|
6407
6394
|
// src/host/extra-folders/pick.ts
|
|
6408
6395
|
import { execFile } from "node:child_process";
|
|
@@ -6424,6 +6411,16 @@ var ExtraFoldersError = class extends Error {
|
|
|
6424
6411
|
// src/host/extra-folders/pick.ts
|
|
6425
6412
|
var execFileAsync = promisify(execFile);
|
|
6426
6413
|
var nodeRequire = createRequire(import.meta.url);
|
|
6414
|
+
function decodeWindowsPickerPathBase64(stdout) {
|
|
6415
|
+
const encoded = stdout.trim().replace(/\r?\n/g, "");
|
|
6416
|
+
if (encoded === "") return null;
|
|
6417
|
+
try {
|
|
6418
|
+
const path = Buffer.from(encoded, "base64").toString("utf8").trim();
|
|
6419
|
+
return path === "" ? null : path;
|
|
6420
|
+
} catch {
|
|
6421
|
+
return null;
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6427
6424
|
async function pickViaElectron() {
|
|
6428
6425
|
try {
|
|
6429
6426
|
const electron = nodeRequire("electron");
|
|
@@ -6450,7 +6447,8 @@ async function pickViaWindowsForms() {
|
|
|
6450
6447
|
"$dialog.ShowNewFolderButton = $true",
|
|
6451
6448
|
"$result = $dialog.ShowDialog()",
|
|
6452
6449
|
"if ($result -eq [System.Windows.Forms.DialogResult]::OK) {",
|
|
6453
|
-
" [
|
|
6450
|
+
" $bytes = [System.Text.Encoding]::UTF8.GetBytes($dialog.SelectedPath)",
|
|
6451
|
+
" [Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
6454
6452
|
"}"
|
|
6455
6453
|
].join("; ");
|
|
6456
6454
|
try {
|
|
@@ -6459,8 +6457,7 @@ async function pickViaWindowsForms() {
|
|
|
6459
6457
|
["-NoProfile", "-STA", "-Command", script],
|
|
6460
6458
|
{ windowsHide: true, encoding: "utf8", timeout: 12e4 }
|
|
6461
6459
|
);
|
|
6462
|
-
|
|
6463
|
-
return path === "" ? null : path;
|
|
6460
|
+
return decodeWindowsPickerPathBase64(stdout);
|
|
6464
6461
|
} catch {
|
|
6465
6462
|
return void 0;
|
|
6466
6463
|
}
|
|
@@ -6550,7 +6547,8 @@ async function pickFileViaWindowsForms(options) {
|
|
|
6550
6547
|
"$dialog.Multiselect = $false",
|
|
6551
6548
|
"$result = $dialog.ShowDialog()",
|
|
6552
6549
|
"if ($result -eq [System.Windows.Forms.DialogResult]::OK) {",
|
|
6553
|
-
" [
|
|
6550
|
+
" $bytes = [System.Text.Encoding]::UTF8.GetBytes($dialog.FileName)",
|
|
6551
|
+
" [Console]::Out.Write([Convert]::ToBase64String($bytes))",
|
|
6554
6552
|
"}"
|
|
6555
6553
|
].join("; ");
|
|
6556
6554
|
try {
|
|
@@ -6559,8 +6557,7 @@ async function pickFileViaWindowsForms(options) {
|
|
|
6559
6557
|
["-NoProfile", "-STA", "-Command", script],
|
|
6560
6558
|
{ windowsHide: true, encoding: "utf8", timeout: 12e4 }
|
|
6561
6559
|
);
|
|
6562
|
-
|
|
6563
|
-
return path === "" ? null : path;
|
|
6560
|
+
return decodeWindowsPickerPathBase64(stdout);
|
|
6564
6561
|
} catch {
|
|
6565
6562
|
return void 0;
|
|
6566
6563
|
}
|
|
@@ -6575,61 +6572,1155 @@ async function pickFileViaOsascript(options) {
|
|
|
6575
6572
|
["-e", `POSIX path of (choose file with prompt "${(options.title ?? "Select file").replace(/"/g, '\\"')}"${ofType})`],
|
|
6576
6573
|
{ encoding: "utf8", timeout: 12e4 }
|
|
6577
6574
|
);
|
|
6578
|
-
const path = stdout.trim().replace(/\/$/, "");
|
|
6579
|
-
return path === "" ? null : path;
|
|
6580
|
-
} catch (error) {
|
|
6581
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
6582
|
-
if (/User canceled|(-128)/i.test(message)) return null;
|
|
6583
|
-
return void 0;
|
|
6575
|
+
const path = stdout.trim().replace(/\/$/, "");
|
|
6576
|
+
return path === "" ? null : path;
|
|
6577
|
+
} catch (error) {
|
|
6578
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
6579
|
+
if (/User canceled|(-128)/i.test(message)) return null;
|
|
6580
|
+
return void 0;
|
|
6581
|
+
}
|
|
6582
|
+
}
|
|
6583
|
+
async function pickFileViaZenity(options) {
|
|
6584
|
+
if (process.platform === "win32" || process.platform === "darwin") return void 0;
|
|
6585
|
+
const args = ["--file-selection", `--title=${options.title ?? "Select file"}`];
|
|
6586
|
+
for (const filter of options.filters ?? []) {
|
|
6587
|
+
const patterns = filter.extensions.map((ext) => ext === "*" ? "*" : `*.${ext}`).join(" ");
|
|
6588
|
+
args.push(`--file-filter=${filter.name} | ${patterns}`);
|
|
6589
|
+
}
|
|
6590
|
+
try {
|
|
6591
|
+
const { stdout } = await execFileAsync("zenity", args, {
|
|
6592
|
+
encoding: "utf8",
|
|
6593
|
+
timeout: 12e4
|
|
6594
|
+
});
|
|
6595
|
+
const path = stdout.trim();
|
|
6596
|
+
return path === "" ? null : path;
|
|
6597
|
+
} catch (error) {
|
|
6598
|
+
const code = error !== null && typeof error === "object" ? Reflect.get(error, "code") : void 0;
|
|
6599
|
+
if (code === 1) return null;
|
|
6600
|
+
return void 0;
|
|
6601
|
+
}
|
|
6602
|
+
}
|
|
6603
|
+
async function pickFileNow(signal, options = {}) {
|
|
6604
|
+
signal.throwIfAborted();
|
|
6605
|
+
const attempts = [
|
|
6606
|
+
() => pickFileViaElectron(options),
|
|
6607
|
+
() => pickFileViaWindowsForms(options),
|
|
6608
|
+
() => pickFileViaOsascript(options),
|
|
6609
|
+
() => pickFileViaZenity(options)
|
|
6610
|
+
];
|
|
6611
|
+
for (const attempt of attempts) {
|
|
6612
|
+
signal.throwIfAborted();
|
|
6613
|
+
const path = await attempt();
|
|
6614
|
+
if (path !== void 0) return { path };
|
|
6615
|
+
}
|
|
6616
|
+
throw new ExtraFoldersError(
|
|
6617
|
+
"FILE_EDIT_FAILED",
|
|
6618
|
+
"No file picker is available in this environment"
|
|
6619
|
+
);
|
|
6620
|
+
}
|
|
6621
|
+
|
|
6622
|
+
// src/host/web-chat-bridge/limits.ts
|
|
6623
|
+
var WEB_CHAT_MAX_TEXT_BYTES = 5 * 1024 * 1024;
|
|
6624
|
+
var WEB_CHAT_MAX_MESSAGES = 5e3;
|
|
6625
|
+
var WEB_CHAT_MAX_EXPORT_CONVERSATIONS = 200;
|
|
6626
|
+
|
|
6627
|
+
// src/host/web-chat-bridge/import-session.ts
|
|
6628
|
+
var WebChatImportError = class extends Error {
|
|
6629
|
+
constructor(code, message, sessionId) {
|
|
6630
|
+
super(message);
|
|
6631
|
+
this.code = code;
|
|
6632
|
+
this.sessionId = sessionId;
|
|
6633
|
+
this.name = "WebChatImportError";
|
|
6634
|
+
}
|
|
6635
|
+
code;
|
|
6636
|
+
sessionId;
|
|
6637
|
+
};
|
|
6638
|
+
function webChatImportToRemoteError(error) {
|
|
6639
|
+
if (error instanceof WebChatImportError) {
|
|
6640
|
+
const details = {
|
|
6641
|
+
code: "FILE_EDIT_FAILED",
|
|
6642
|
+
webChatCode: error.code,
|
|
6643
|
+
...error.sessionId === void 0 ? {} : { sessionId: error.sessionId }
|
|
6644
|
+
};
|
|
6645
|
+
return new RemoteError("agent-enhancer/failed", `${error.code}: ${error.message}`, details);
|
|
6646
|
+
}
|
|
6647
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
6648
|
+
return new RemoteError("agent-enhancer/failed", detail || "Web chat import failed", {
|
|
6649
|
+
code: "FILE_EDIT_FAILED",
|
|
6650
|
+
webChatCode: "import-failed"
|
|
6651
|
+
});
|
|
6652
|
+
}
|
|
6653
|
+
function serviceOf2(ctx, key) {
|
|
6654
|
+
try {
|
|
6655
|
+
return ctx.get(key);
|
|
6656
|
+
} catch {
|
|
6657
|
+
return void 0;
|
|
6658
|
+
}
|
|
6659
|
+
}
|
|
6660
|
+
function assertTranscript(transcript) {
|
|
6661
|
+
if (transcript.turns.length === 0) {
|
|
6662
|
+
throw new WebChatImportError("invalid-transcript", "Transcript has no turns");
|
|
6663
|
+
}
|
|
6664
|
+
if (transcript.turns.length > WEB_CHAT_MAX_MESSAGES) {
|
|
6665
|
+
throw new WebChatImportError(
|
|
6666
|
+
"invalid-transcript",
|
|
6667
|
+
`Exceeds message limit (${WEB_CHAT_MAX_MESSAGES})`
|
|
6668
|
+
);
|
|
6669
|
+
}
|
|
6670
|
+
let bytes = 0;
|
|
6671
|
+
for (const turn of transcript.turns) {
|
|
6672
|
+
bytes += Buffer.byteLength(turn.text, "utf8");
|
|
6673
|
+
if (bytes > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
6674
|
+
throw new WebChatImportError(
|
|
6675
|
+
"invalid-transcript",
|
|
6676
|
+
`Exceeds text byte limit (${WEB_CHAT_MAX_TEXT_BYTES})`
|
|
6677
|
+
);
|
|
6678
|
+
}
|
|
6679
|
+
}
|
|
6680
|
+
}
|
|
6681
|
+
function importProvenancePrefix(transcript) {
|
|
6682
|
+
const partial = transcript.partial ? "yes" : "no";
|
|
6683
|
+
return `[Imported web chat \xB7 ${transcript.source.kind} \xB7 partial=${partial} \xB7 ${transcript.source.capturedAt}]
|
|
6684
|
+
|
|
6685
|
+
`;
|
|
6686
|
+
}
|
|
6687
|
+
var GENERIC_IMPORT_TITLE = /^(deepseek|shared conversation|imported chat|chat|untitled|未命名)$/i;
|
|
6688
|
+
function resolveWebChatImportTitle(transcript) {
|
|
6689
|
+
const raw = transcript.title.trim();
|
|
6690
|
+
if (raw !== "" && !GENERIC_IMPORT_TITLE.test(raw)) {
|
|
6691
|
+
return raw.length <= 80 ? raw : `${raw.slice(0, 79)}\u2026`;
|
|
6692
|
+
}
|
|
6693
|
+
const firstUser = transcript.turns.find((turn) => turn.role === "user");
|
|
6694
|
+
if (firstUser !== void 0) {
|
|
6695
|
+
const text3 = firstUser.text.trim().replace(/\s+/g, " ");
|
|
6696
|
+
if (text3 !== "") {
|
|
6697
|
+
return text3.length <= 40 ? text3 : `${text3.slice(0, 39)}\u2026`;
|
|
6698
|
+
}
|
|
6699
|
+
}
|
|
6700
|
+
if (raw !== "") return raw;
|
|
6701
|
+
return "Imported chat";
|
|
6702
|
+
}
|
|
6703
|
+
function closeOpenTurn(session, turn) {
|
|
6704
|
+
session.append("turn/end", { turn, reason: { kind: "completed" } });
|
|
6705
|
+
}
|
|
6706
|
+
function appendUserMessage(session, text3) {
|
|
6707
|
+
const message = createUserMessage({
|
|
6708
|
+
content: [{ type: "text", text: text3 }],
|
|
6709
|
+
source: { kind: "user" }
|
|
6710
|
+
});
|
|
6711
|
+
return session.append("user/message", message, { surfaceOp: "append" });
|
|
6712
|
+
}
|
|
6713
|
+
function appendSessionTitle(session, title, firstUserMessageSeq) {
|
|
6714
|
+
const trimmed = title.trim();
|
|
6715
|
+
if (trimmed === "") return;
|
|
6716
|
+
session.append("session/title", {
|
|
6717
|
+
title: trimmed,
|
|
6718
|
+
messageSeqs: firstUserMessageSeq === void 0 ? [] : [SessionSeq2(firstUserMessageSeq)],
|
|
6719
|
+
source: { kind: "fallback" }
|
|
6720
|
+
});
|
|
6721
|
+
}
|
|
6722
|
+
function appendAssistantMessage(session, turn, step, text3) {
|
|
6723
|
+
session.append("step/start", { turn, step });
|
|
6724
|
+
const message = createAssistantMessage({
|
|
6725
|
+
content: [{ type: "text", text: text3 }],
|
|
6726
|
+
source: { provider: "web-chat-bridge", model: "imported-history" }
|
|
6727
|
+
});
|
|
6728
|
+
session.append("assistant/message", {
|
|
6729
|
+
turn,
|
|
6730
|
+
step,
|
|
6731
|
+
message,
|
|
6732
|
+
stream: []
|
|
6733
|
+
}, { surfaceOp: "append" });
|
|
6734
|
+
session.append("step/end", { turn, step });
|
|
6735
|
+
}
|
|
6736
|
+
function appendProtectedSystemHead(session, turn, step) {
|
|
6737
|
+
session.append("step/start", { turn, step });
|
|
6738
|
+
session.append("system/message", {
|
|
6739
|
+
turn,
|
|
6740
|
+
step,
|
|
6741
|
+
message: createSystemMessage("")
|
|
6742
|
+
}, { surfaceOp: "append" });
|
|
6743
|
+
session.append("step/end", { turn, step });
|
|
6744
|
+
}
|
|
6745
|
+
function appendTranscript(session, transcript) {
|
|
6746
|
+
const provenance = importProvenancePrefix(transcript);
|
|
6747
|
+
const turns = transcript.turns;
|
|
6748
|
+
let turn = 1;
|
|
6749
|
+
let step = 1;
|
|
6750
|
+
let openTurn = true;
|
|
6751
|
+
let awaitingAssistant = false;
|
|
6752
|
+
let firstUser = true;
|
|
6753
|
+
let firstUserMessageSeq;
|
|
6754
|
+
session.append("turn/start", { turn });
|
|
6755
|
+
appendProtectedSystemHead(session, turn, step);
|
|
6756
|
+
for (let index = 0; index < turns.length; index += 1) {
|
|
6757
|
+
const chatTurn = turns[index];
|
|
6758
|
+
const nextRole = turns[index + 1]?.role;
|
|
6759
|
+
if (chatTurn.role === "user") {
|
|
6760
|
+
if (awaitingAssistant) {
|
|
6761
|
+
closeOpenTurn(session, turn);
|
|
6762
|
+
awaitingAssistant = false;
|
|
6763
|
+
openTurn = false;
|
|
6764
|
+
step = 0;
|
|
6765
|
+
}
|
|
6766
|
+
if (!openTurn) {
|
|
6767
|
+
turn += 1;
|
|
6768
|
+
step = 0;
|
|
6769
|
+
session.append("turn/start", { turn });
|
|
6770
|
+
openTurn = true;
|
|
6771
|
+
}
|
|
6772
|
+
const body = firstUser ? `${provenance}${chatTurn.text}` : chatTurn.text;
|
|
6773
|
+
const userEvent = appendUserMessage(session, body);
|
|
6774
|
+
if (firstUser && userEvent !== null && typeof userEvent === "object") {
|
|
6775
|
+
const seq = Number(Reflect.get(userEvent, "seq"));
|
|
6776
|
+
if (Number.isFinite(seq)) firstUserMessageSeq = seq;
|
|
6777
|
+
}
|
|
6778
|
+
awaitingAssistant = true;
|
|
6779
|
+
firstUser = false;
|
|
6780
|
+
continue;
|
|
6781
|
+
}
|
|
6782
|
+
if (chatTurn.role === "assistant") {
|
|
6783
|
+
if (!openTurn) {
|
|
6784
|
+
turn += 1;
|
|
6785
|
+
step = 0;
|
|
6786
|
+
session.append("turn/start", { turn });
|
|
6787
|
+
openTurn = true;
|
|
6788
|
+
awaitingAssistant = false;
|
|
6789
|
+
}
|
|
6790
|
+
step += 1;
|
|
6791
|
+
appendAssistantMessage(session, turn, step, chatTurn.text);
|
|
6792
|
+
awaitingAssistant = false;
|
|
6793
|
+
if (nextRole !== "assistant") {
|
|
6794
|
+
closeOpenTurn(session, turn);
|
|
6795
|
+
openTurn = false;
|
|
6796
|
+
step = 0;
|
|
6797
|
+
}
|
|
6798
|
+
}
|
|
6799
|
+
}
|
|
6800
|
+
if (openTurn) closeOpenTurn(session, turn);
|
|
6801
|
+
appendSessionTitle(session, resolveWebChatImportTitle(transcript), firstUserMessageSeq);
|
|
6802
|
+
}
|
|
6803
|
+
function buildWebChatImportSeed(transcript) {
|
|
6804
|
+
const events = [];
|
|
6805
|
+
const recorder = {
|
|
6806
|
+
append(type, data, intent) {
|
|
6807
|
+
const event = {
|
|
6808
|
+
type,
|
|
6809
|
+
seq: SessionSeq2(events.length),
|
|
6810
|
+
time: Date.now(),
|
|
6811
|
+
data,
|
|
6812
|
+
...intent?.surfaceOp === void 0 ? {} : { surfaceOp: intent.surfaceOp }
|
|
6813
|
+
};
|
|
6814
|
+
events.push(event);
|
|
6815
|
+
return event;
|
|
6816
|
+
}
|
|
6817
|
+
};
|
|
6818
|
+
appendTranscript(recorder, transcript);
|
|
6819
|
+
return events;
|
|
6820
|
+
}
|
|
6821
|
+
function onceDispose(dispose) {
|
|
6822
|
+
let settled = false;
|
|
6823
|
+
return async () => {
|
|
6824
|
+
if (settled) return true;
|
|
6825
|
+
if (dispose === void 0) return false;
|
|
6826
|
+
settled = true;
|
|
6827
|
+
try {
|
|
6828
|
+
await dispose();
|
|
6829
|
+
return true;
|
|
6830
|
+
} catch {
|
|
6831
|
+
return false;
|
|
6832
|
+
}
|
|
6833
|
+
};
|
|
6834
|
+
}
|
|
6835
|
+
function errorDetail(error) {
|
|
6836
|
+
return error instanceof Error ? error.message : String(error);
|
|
6837
|
+
}
|
|
6838
|
+
async function openAgentWorkSession(input, cwd) {
|
|
6839
|
+
const agents = input.agents;
|
|
6840
|
+
if (typeof agents.createSession === "function") {
|
|
6841
|
+
let created;
|
|
6842
|
+
try {
|
|
6843
|
+
created = await agents.createSession({
|
|
6844
|
+
cwd,
|
|
6845
|
+
reusable: () => false
|
|
6846
|
+
});
|
|
6847
|
+
} catch (error) {
|
|
6848
|
+
throw new WebChatImportError("import-failed", `Agent create failed: ${errorDetail(error)}`);
|
|
6849
|
+
}
|
|
6850
|
+
const session2 = created.agent?.session;
|
|
6851
|
+
if (session2 === void 0) {
|
|
6852
|
+
throw new WebChatImportError("import-failed", "Agent create did not return a session");
|
|
6853
|
+
}
|
|
6854
|
+
const dispose = onceDispose(created.dispose?.bind(created));
|
|
6855
|
+
try {
|
|
6856
|
+
appendTranscript(session2, input.transcript);
|
|
6857
|
+
} catch (error) {
|
|
6858
|
+
const disposed = await dispose();
|
|
6859
|
+
throw new WebChatImportError(
|
|
6860
|
+
"import-failed",
|
|
6861
|
+
errorDetail(error),
|
|
6862
|
+
disposed ? void 0 : session2.id
|
|
6863
|
+
);
|
|
6864
|
+
}
|
|
6865
|
+
return { session: session2, dispose };
|
|
6866
|
+
}
|
|
6867
|
+
if (typeof agents.create !== "function") {
|
|
6868
|
+
throw new WebChatImportError("import-failed", "Agent registry is unavailable");
|
|
6869
|
+
}
|
|
6870
|
+
const sessionId = SessionId(`session-${randomUUID6()}`);
|
|
6871
|
+
const seed = buildWebChatImportSeed(input.transcript);
|
|
6872
|
+
let handle;
|
|
6873
|
+
try {
|
|
6874
|
+
handle = await agents.create({
|
|
6875
|
+
sessionId,
|
|
6876
|
+
seed,
|
|
6877
|
+
meta: { cwd },
|
|
6878
|
+
...input.agentOptions === void 0 ? {} : { agentOptions: input.agentOptions }
|
|
6879
|
+
});
|
|
6880
|
+
} catch (error) {
|
|
6881
|
+
throw new WebChatImportError("import-failed", `Agent create failed: ${errorDetail(error)}`);
|
|
6882
|
+
}
|
|
6883
|
+
const session = handle.agent?.session;
|
|
6884
|
+
if (session === void 0) {
|
|
6885
|
+
throw new WebChatImportError("import-failed", "Agent create did not return a session", sessionId);
|
|
6886
|
+
}
|
|
6887
|
+
return { session, dispose: onceDispose(() => handle.dispose()) };
|
|
6888
|
+
}
|
|
6889
|
+
async function importWebChatHistoryNow(input) {
|
|
6890
|
+
assertTranscript(input.transcript);
|
|
6891
|
+
const cwd = resolve2(input.cwd);
|
|
6892
|
+
const opened = await openAgentWorkSession(input, cwd);
|
|
6893
|
+
try {
|
|
6894
|
+
const flushed = await input.sessions.flush(opened.session);
|
|
6895
|
+
if (flushed !== true) {
|
|
6896
|
+
const disposed = await opened.dispose();
|
|
6897
|
+
throw new WebChatImportError(
|
|
6898
|
+
"import-failed",
|
|
6899
|
+
"Session flush did not persist",
|
|
6900
|
+
disposed ? void 0 : opened.session.id
|
|
6901
|
+
);
|
|
6902
|
+
}
|
|
6903
|
+
if (input.attachToWorkspace !== void 0) {
|
|
6904
|
+
try {
|
|
6905
|
+
await input.attachToWorkspace(opened.session.id);
|
|
6906
|
+
} catch (error) {
|
|
6907
|
+
const disposed = await opened.dispose();
|
|
6908
|
+
const detail = errorDetail(error);
|
|
6909
|
+
throw new WebChatImportError(
|
|
6910
|
+
"import-failed",
|
|
6911
|
+
disposed ? `Workspace attach failed: ${detail}` : `Workspace attach failed: ${detail}; dispose session ${opened.session.id} manually`,
|
|
6912
|
+
disposed ? void 0 : opened.session.id
|
|
6913
|
+
);
|
|
6914
|
+
}
|
|
6915
|
+
}
|
|
6916
|
+
} catch (error) {
|
|
6917
|
+
if (error instanceof WebChatImportError) throw error;
|
|
6918
|
+
const disposed = await opened.dispose();
|
|
6919
|
+
throw new WebChatImportError(
|
|
6920
|
+
"import-failed",
|
|
6921
|
+
errorDetail(error),
|
|
6922
|
+
disposed ? void 0 : opened.session.id
|
|
6923
|
+
);
|
|
6924
|
+
}
|
|
6925
|
+
return { sessionId: opened.session.id };
|
|
6926
|
+
}
|
|
6927
|
+
function workspaceRegistryOf2(ctx) {
|
|
6928
|
+
const registry = serviceOf2(ctx, "workspaceRegistry");
|
|
6929
|
+
if (registry === void 0 || typeof registry.list !== "function") return void 0;
|
|
6930
|
+
return registry;
|
|
6931
|
+
}
|
|
6932
|
+
function workspacesFromStorage(ctx) {
|
|
6933
|
+
const facility = serviceOf2(ctx, "storageDomain");
|
|
6934
|
+
const domain = facility?.get?.("workspace");
|
|
6935
|
+
const table = domain?.table?.("workspaces");
|
|
6936
|
+
if (table === void 0) return [];
|
|
6937
|
+
const rows = [];
|
|
6938
|
+
for (const [id, record2] of table.entries()) {
|
|
6939
|
+
const cwd = record2?.path ?? record2?.cwd;
|
|
6940
|
+
if (typeof cwd !== "string" || cwd.trim() === "") continue;
|
|
6941
|
+
rows.push({
|
|
6942
|
+
id,
|
|
6943
|
+
title: record2.title?.trim() || id,
|
|
6944
|
+
cwd: resolve2(cwd)
|
|
6945
|
+
});
|
|
6946
|
+
}
|
|
6947
|
+
return rows;
|
|
6948
|
+
}
|
|
6949
|
+
function listWebChatWorkspacesNow(ctx) {
|
|
6950
|
+
const registry = workspaceRegistryOf2(ctx);
|
|
6951
|
+
if (registry !== void 0) {
|
|
6952
|
+
const rows = [];
|
|
6953
|
+
for (const workspace of registry.list()) {
|
|
6954
|
+
const cwd = workspace.path;
|
|
6955
|
+
if (typeof cwd !== "string" || cwd.trim() === "") continue;
|
|
6956
|
+
rows.push({
|
|
6957
|
+
id: workspace.id,
|
|
6958
|
+
title: workspace.title?.trim() || workspace.id,
|
|
6959
|
+
cwd: resolve2(cwd)
|
|
6960
|
+
});
|
|
6961
|
+
}
|
|
6962
|
+
if (rows.length > 0) return rows;
|
|
6963
|
+
}
|
|
6964
|
+
return workspacesFromStorage(ctx);
|
|
6965
|
+
}
|
|
6966
|
+
async function createWebChatWorkspaceNow(ctx, signal) {
|
|
6967
|
+
signal.throwIfAborted();
|
|
6968
|
+
const picked = await pickDirectoryNow(signal);
|
|
6969
|
+
if (picked.path === null) {
|
|
6970
|
+
return { cancelled: true, workspace: null };
|
|
6971
|
+
}
|
|
6972
|
+
signal.throwIfAborted();
|
|
6973
|
+
const absolute = resolve2(picked.path);
|
|
6974
|
+
try {
|
|
6975
|
+
if (!existsSync4(absolute) || !statSync(absolute).isDirectory()) {
|
|
6976
|
+
throw new WebChatImportError(
|
|
6977
|
+
"import-failed",
|
|
6978
|
+
`Selected folder does not exist: ${absolute}`
|
|
6979
|
+
);
|
|
6980
|
+
}
|
|
6981
|
+
} catch (error) {
|
|
6982
|
+
if (error instanceof WebChatImportError) throw error;
|
|
6983
|
+
throw new WebChatImportError(
|
|
6984
|
+
"import-failed",
|
|
6985
|
+
`Selected folder is not readable: ${absolute}`
|
|
6986
|
+
);
|
|
6987
|
+
}
|
|
6988
|
+
const registry = workspaceRegistryOf2(ctx);
|
|
6989
|
+
if (registry?.create === void 0) {
|
|
6990
|
+
throw new WebChatImportError("import-failed", "Workspace registry cannot create workspaces");
|
|
6991
|
+
}
|
|
6992
|
+
let created;
|
|
6993
|
+
try {
|
|
6994
|
+
created = await registry.create(absolute);
|
|
6995
|
+
} catch (error) {
|
|
6996
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
6997
|
+
const existing = listWebChatWorkspacesNow(ctx).find((row) => {
|
|
6998
|
+
try {
|
|
6999
|
+
return resolve2(row.cwd) === absolute;
|
|
7000
|
+
} catch {
|
|
7001
|
+
return false;
|
|
7002
|
+
}
|
|
7003
|
+
});
|
|
7004
|
+
if (existing !== void 0) {
|
|
7005
|
+
return { cancelled: false, workspace: existing };
|
|
7006
|
+
}
|
|
7007
|
+
throw new WebChatImportError("import-failed", detail || "Failed to create workspace");
|
|
7008
|
+
}
|
|
7009
|
+
const cwd = typeof created.path === "string" && created.path.trim() !== "" ? resolve2(created.path) : absolute;
|
|
7010
|
+
return {
|
|
7011
|
+
cancelled: false,
|
|
7012
|
+
workspace: {
|
|
7013
|
+
id: created.id,
|
|
7014
|
+
title: created.title?.trim() || created.id,
|
|
7015
|
+
cwd
|
|
7016
|
+
}
|
|
7017
|
+
};
|
|
7018
|
+
}
|
|
7019
|
+
function resolveWorkspace(ctx, workspaceId) {
|
|
7020
|
+
const registry = workspaceRegistryOf2(ctx);
|
|
7021
|
+
if (registry?.get !== void 0) {
|
|
7022
|
+
const workspace = registry.get(workspaceId);
|
|
7023
|
+
if (workspace !== void 0) {
|
|
7024
|
+
const cwd = workspace.path;
|
|
7025
|
+
if (typeof cwd === "string" && cwd.trim() !== "") {
|
|
7026
|
+
return {
|
|
7027
|
+
id: workspace.id,
|
|
7028
|
+
title: workspace.title?.trim() || workspace.id,
|
|
7029
|
+
cwd: resolve2(cwd)
|
|
7030
|
+
};
|
|
7031
|
+
}
|
|
7032
|
+
}
|
|
7033
|
+
}
|
|
7034
|
+
const fromList = listWebChatWorkspacesNow(ctx).find((row) => row.id === workspaceId);
|
|
7035
|
+
if (fromList !== void 0) return fromList;
|
|
7036
|
+
throw new WebChatImportError("no-workspace", `Workspace "${workspaceId}" was not found`);
|
|
7037
|
+
}
|
|
7038
|
+
async function attachToWorkspaceRegistry(ctx, workspaceId, sessionId) {
|
|
7039
|
+
const registry = workspaceRegistryOf2(ctx);
|
|
7040
|
+
const workspace = registry?.get?.(workspaceId);
|
|
7041
|
+
if (workspace?.attachSession !== void 0) {
|
|
7042
|
+
await workspace.attachSession(sessionId);
|
|
7043
|
+
return;
|
|
7044
|
+
}
|
|
7045
|
+
const facility = serviceOf2(ctx, "storageDomain");
|
|
7046
|
+
const domain = facility?.get?.("workspace");
|
|
7047
|
+
const table = domain?.table?.("workspaces");
|
|
7048
|
+
if (table === void 0) {
|
|
7049
|
+
throw new WebChatImportError("import-failed", "Workspace registry is unavailable for attach");
|
|
7050
|
+
}
|
|
7051
|
+
await table.update(workspaceId, (current) => {
|
|
7052
|
+
const row = current;
|
|
7053
|
+
const sessionIds = Array.isArray(row.sessionIds) ? row.sessionIds : [];
|
|
7054
|
+
if (sessionIds.includes(sessionId)) return row;
|
|
7055
|
+
return {
|
|
7056
|
+
...row,
|
|
7057
|
+
sessionIds: [...sessionIds, sessionId],
|
|
7058
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7059
|
+
};
|
|
7060
|
+
});
|
|
7061
|
+
}
|
|
7062
|
+
function agentOptionsOf(ctx) {
|
|
7063
|
+
const defaults = serviceOf2(ctx, "agentDefaultModel");
|
|
7064
|
+
if (typeof defaults?.currentSelection !== "function") return void 0;
|
|
7065
|
+
const current = defaults.currentSelection.bind(defaults);
|
|
7066
|
+
return {
|
|
7067
|
+
get provider() {
|
|
7068
|
+
return current().provider;
|
|
7069
|
+
},
|
|
7070
|
+
get model() {
|
|
7071
|
+
return current().model;
|
|
7072
|
+
},
|
|
7073
|
+
get reasoningEffort() {
|
|
7074
|
+
return current().reasoningEffort;
|
|
7075
|
+
}
|
|
7076
|
+
};
|
|
7077
|
+
}
|
|
7078
|
+
async function importWebChatHistoryWithContext(ctx, request) {
|
|
7079
|
+
const workspace = resolveWorkspace(ctx, request.workspaceId);
|
|
7080
|
+
const sessions = serviceOf2(ctx, "sessions");
|
|
7081
|
+
const agents = serviceOf2(ctx, "agents");
|
|
7082
|
+
if (sessions === void 0 || typeof sessions.flush !== "function") {
|
|
7083
|
+
throw new WebChatImportError("import-failed", "Session store is unavailable");
|
|
7084
|
+
}
|
|
7085
|
+
if (agents === void 0 || typeof agents.createSession !== "function" && typeof agents.create !== "function") {
|
|
7086
|
+
throw new WebChatImportError("import-failed", "Agent registry is unavailable");
|
|
7087
|
+
}
|
|
7088
|
+
const agentOptions = agentOptionsOf(ctx);
|
|
7089
|
+
return importWebChatHistoryNow({
|
|
7090
|
+
sessions: { flush: (session) => sessions.flush(session) },
|
|
7091
|
+
agents,
|
|
7092
|
+
...agentOptions === void 0 ? {} : { agentOptions },
|
|
7093
|
+
workspaceId: workspace.id,
|
|
7094
|
+
cwd: workspace.cwd,
|
|
7095
|
+
transcript: request.transcript,
|
|
7096
|
+
attachToWorkspace: (sessionId) => attachToWorkspaceRegistry(ctx, workspace.id, sessionId)
|
|
7097
|
+
});
|
|
7098
|
+
}
|
|
7099
|
+
|
|
7100
|
+
// src/host/web-chat-bridge/parse-export.ts
|
|
7101
|
+
import { inflateRawSync } from "node:zlib";
|
|
7102
|
+
var SECTION_HEADER = /^##\s*(User|Assistant|用户|助手)\s*$/gim;
|
|
7103
|
+
var MARKDOWN_CHAT_SPLIT = /^#\s+(.+)$/gm;
|
|
7104
|
+
function assertPayloadSize(bytes) {
|
|
7105
|
+
if (bytes.length > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
7106
|
+
throw new Error(`Export too large: exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
7107
|
+
}
|
|
7108
|
+
}
|
|
7109
|
+
function assertTurnCount(turns) {
|
|
7110
|
+
if (turns.length === 0) {
|
|
7111
|
+
throw new Error("No messages found in export");
|
|
7112
|
+
}
|
|
7113
|
+
if (turns.length > WEB_CHAT_MAX_MESSAGES) {
|
|
7114
|
+
throw new Error(`Exceeds message limit (${WEB_CHAT_MAX_MESSAGES})`);
|
|
7115
|
+
}
|
|
7116
|
+
}
|
|
7117
|
+
function normalizeRole(raw) {
|
|
7118
|
+
const key = raw.trim().toLowerCase();
|
|
7119
|
+
if (key === "user" || key === "\u7528\u6237") return "user";
|
|
7120
|
+
if (key === "assistant" || key === "\u52A9\u624B") return "assistant";
|
|
7121
|
+
return null;
|
|
7122
|
+
}
|
|
7123
|
+
function extractTitleFromMarkdown(text3) {
|
|
7124
|
+
const match = text3.match(/^#\s+(.+)$/m);
|
|
7125
|
+
if (match?.[1]) return match[1].trim();
|
|
7126
|
+
const firstLine = text3.split(/\r?\n/).find((line) => line.trim() !== "");
|
|
7127
|
+
return firstLine?.trim() ?? "Imported chat";
|
|
7128
|
+
}
|
|
7129
|
+
function parseMarkdownTurns(text3) {
|
|
7130
|
+
const turns = [];
|
|
7131
|
+
const matches = [...text3.matchAll(SECTION_HEADER)];
|
|
7132
|
+
if (matches.length === 0) return turns;
|
|
7133
|
+
for (let i = 0; i < matches.length; i++) {
|
|
7134
|
+
const match = matches[i];
|
|
7135
|
+
const role = normalizeRole(match[1]);
|
|
7136
|
+
if (!role) continue;
|
|
7137
|
+
const start = match.index + match[0].length;
|
|
7138
|
+
const end = i + 1 < matches.length ? matches[i + 1].index : text3.length;
|
|
7139
|
+
const body = text3.slice(start, end).trim();
|
|
7140
|
+
if (body) turns.push({ role, text: body });
|
|
7141
|
+
}
|
|
7142
|
+
return turns;
|
|
7143
|
+
}
|
|
7144
|
+
function messageText(content) {
|
|
7145
|
+
if (typeof content === "string") return content.trim();
|
|
7146
|
+
if (Array.isArray(content)) {
|
|
7147
|
+
return content.map((part) => {
|
|
7148
|
+
if (typeof part === "string") return part;
|
|
7149
|
+
if (part && typeof part === "object" && "text" in part && typeof part.text === "string") {
|
|
7150
|
+
return part.text;
|
|
7151
|
+
}
|
|
7152
|
+
return "";
|
|
7153
|
+
}).filter(Boolean).join("\n").trim();
|
|
7154
|
+
}
|
|
7155
|
+
return "";
|
|
7156
|
+
}
|
|
7157
|
+
function normalizeJsonRole(raw) {
|
|
7158
|
+
if (typeof raw !== "string") return null;
|
|
7159
|
+
const key = raw.trim().toLowerCase();
|
|
7160
|
+
if (key === "user" || key === "human") return "user";
|
|
7161
|
+
if (key === "assistant" || key === "model" || key === "ai") return "assistant";
|
|
7162
|
+
return null;
|
|
7163
|
+
}
|
|
7164
|
+
function turnsFromMessageRows(rows) {
|
|
7165
|
+
const turns = [];
|
|
7166
|
+
for (const row of rows) {
|
|
7167
|
+
if (!row || typeof row !== "object") continue;
|
|
7168
|
+
const item = row;
|
|
7169
|
+
const role = normalizeJsonRole(item.role ?? item.author ?? item.speaker);
|
|
7170
|
+
if (!role) continue;
|
|
7171
|
+
const text3 = messageText(item.content ?? item.text ?? item.message);
|
|
7172
|
+
if (text3) turns.push({ role, text: text3 });
|
|
7173
|
+
}
|
|
7174
|
+
return turns;
|
|
7175
|
+
}
|
|
7176
|
+
function titleOfObject(obj, fallback) {
|
|
7177
|
+
if (typeof obj.title === "string" && obj.title.trim()) return obj.title.trim();
|
|
7178
|
+
if (typeof obj.name === "string" && obj.name.trim()) return obj.name.trim();
|
|
7179
|
+
if (typeof obj.chat_title === "string" && obj.chat_title.trim()) return obj.chat_title.trim();
|
|
7180
|
+
return fallback;
|
|
7181
|
+
}
|
|
7182
|
+
function conversationFromObject(value, fallbackTitle) {
|
|
7183
|
+
if (Array.isArray(value)) {
|
|
7184
|
+
const turns2 = turnsFromMessageRows(value);
|
|
7185
|
+
return turns2.length > 0 ? { title: fallbackTitle, turns: turns2 } : null;
|
|
7186
|
+
}
|
|
7187
|
+
if (!value || typeof value !== "object") return null;
|
|
7188
|
+
const obj = value;
|
|
7189
|
+
const title = titleOfObject(obj, fallbackTitle);
|
|
7190
|
+
let rows = [];
|
|
7191
|
+
if (Array.isArray(obj.messages)) rows = obj.messages;
|
|
7192
|
+
else if (Array.isArray(obj.conversation)) rows = obj.conversation;
|
|
7193
|
+
else if (Array.isArray(obj.turns)) rows = obj.turns;
|
|
7194
|
+
else if (Array.isArray(obj.chat_messages)) rows = obj.chat_messages;
|
|
7195
|
+
const turns = turnsFromMessageRows(rows);
|
|
7196
|
+
return turns.length > 0 ? { title, turns } : null;
|
|
7197
|
+
}
|
|
7198
|
+
function conversationsFromJsonValue(value, fallbackTitle) {
|
|
7199
|
+
if (Array.isArray(value)) {
|
|
7200
|
+
const asMessages = turnsFromMessageRows(value);
|
|
7201
|
+
if (asMessages.length > 0 && value.every((row) => {
|
|
7202
|
+
if (!row || typeof row !== "object") return false;
|
|
7203
|
+
const item = row;
|
|
7204
|
+
return normalizeJsonRole(item.role ?? item.author ?? item.speaker) !== null;
|
|
7205
|
+
})) {
|
|
7206
|
+
return [{ title: fallbackTitle, turns: asMessages }];
|
|
7207
|
+
}
|
|
7208
|
+
const out = [];
|
|
7209
|
+
for (let i = 0; i < value.length; i++) {
|
|
7210
|
+
const parsed = conversationFromObject(value[i], `${fallbackTitle} ${i + 1}`);
|
|
7211
|
+
if (parsed) out.push(parsed);
|
|
7212
|
+
}
|
|
7213
|
+
return out;
|
|
7214
|
+
}
|
|
7215
|
+
if (!value || typeof value !== "object") return [];
|
|
7216
|
+
const obj = value;
|
|
7217
|
+
const listKeys = ["chats", "conversations", "chat_sessions", "sessions", "history"];
|
|
7218
|
+
for (const key of listKeys) {
|
|
7219
|
+
const list = obj[key];
|
|
7220
|
+
if (!Array.isArray(list) || list.length === 0) continue;
|
|
7221
|
+
const out = [];
|
|
7222
|
+
for (let i = 0; i < list.length; i++) {
|
|
7223
|
+
const parsed = conversationFromObject(list[i], `${fallbackTitle} ${i + 1}`);
|
|
7224
|
+
if (parsed) out.push(parsed);
|
|
7225
|
+
}
|
|
7226
|
+
if (out.length > 0) return out;
|
|
7227
|
+
}
|
|
7228
|
+
const single = conversationFromObject(obj, fallbackTitle);
|
|
7229
|
+
return single ? [single] : [];
|
|
7230
|
+
}
|
|
7231
|
+
function splitMarkdownConversations(text3) {
|
|
7232
|
+
const matches = [...text3.matchAll(MARKDOWN_CHAT_SPLIT)];
|
|
7233
|
+
if (matches.length <= 1) {
|
|
7234
|
+
return [{ title: extractTitleFromMarkdown(text3), body: text3 }];
|
|
7235
|
+
}
|
|
7236
|
+
const out = [];
|
|
7237
|
+
for (let i = 0; i < matches.length; i++) {
|
|
7238
|
+
const match = matches[i];
|
|
7239
|
+
const title = match[1].trim() || `Chat ${i + 1}`;
|
|
7240
|
+
const start = match.index;
|
|
7241
|
+
const end = i + 1 < matches.length ? matches[i + 1].index : text3.length;
|
|
7242
|
+
const body = text3.slice(start, end).trim();
|
|
7243
|
+
if (body) out.push({ title, body });
|
|
7244
|
+
}
|
|
7245
|
+
return out;
|
|
7246
|
+
}
|
|
7247
|
+
function parseTextConversations(text3, filename) {
|
|
7248
|
+
const chunks = splitMarkdownConversations(text3);
|
|
7249
|
+
const out = [];
|
|
7250
|
+
for (const chunk of chunks) {
|
|
7251
|
+
const turns = parseMarkdownTurns(chunk.body);
|
|
7252
|
+
if (turns.length > 0) {
|
|
7253
|
+
out.push({ title: chunk.title, turns });
|
|
7254
|
+
continue;
|
|
7255
|
+
}
|
|
7256
|
+
}
|
|
7257
|
+
if (out.length > 0) return out;
|
|
7258
|
+
const trimmed = text3.trim();
|
|
7259
|
+
if (trimmed && filename.toLowerCase().endsWith(".txt")) {
|
|
7260
|
+
return [{ title: extractTitleFromMarkdown(text3), turns: [{ role: "user", text: trimmed }] }];
|
|
7261
|
+
}
|
|
7262
|
+
return [];
|
|
7263
|
+
}
|
|
7264
|
+
function isZipArchive(bytes) {
|
|
7265
|
+
return bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75;
|
|
7266
|
+
}
|
|
7267
|
+
function zipEntryPriority(name2) {
|
|
7268
|
+
const lower = name2.toLowerCase();
|
|
7269
|
+
if (lower.endsWith(".md")) return 0;
|
|
7270
|
+
if (lower.endsWith(".json")) return 1;
|
|
7271
|
+
if (lower.endsWith(".txt")) return 2;
|
|
7272
|
+
return 9;
|
|
7273
|
+
}
|
|
7274
|
+
function decompressZipEntry(method, compressed, uncompressedSize) {
|
|
7275
|
+
if (uncompressedSize > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
7276
|
+
throw new Error(`Export too large: exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
7277
|
+
}
|
|
7278
|
+
if (method === 0) {
|
|
7279
|
+
if (compressed.length > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
7280
|
+
throw new Error(`Export too large: exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
7281
|
+
}
|
|
7282
|
+
return compressed;
|
|
7283
|
+
}
|
|
7284
|
+
if (method === 8) {
|
|
7285
|
+
return inflateRawSync(compressed, { maxOutputLength: WEB_CHAT_MAX_TEXT_BYTES + 1 });
|
|
7286
|
+
}
|
|
7287
|
+
throw new Error("unrecognized-export: unsupported zip compression");
|
|
7288
|
+
}
|
|
7289
|
+
function listZipEntryDescriptors(bytes) {
|
|
7290
|
+
const entries = [];
|
|
7291
|
+
let offset = 0;
|
|
7292
|
+
while (offset + 30 <= bytes.length) {
|
|
7293
|
+
if (bytes.readUInt32LE(offset) !== 67324752) break;
|
|
7294
|
+
const method = bytes.readUInt16LE(offset + 8);
|
|
7295
|
+
const compressedSize = bytes.readUInt32LE(offset + 18);
|
|
7296
|
+
const uncompressedSize = bytes.readUInt32LE(offset + 22);
|
|
7297
|
+
const nameLength = bytes.readUInt16LE(offset + 26);
|
|
7298
|
+
const extraLength = bytes.readUInt16LE(offset + 28);
|
|
7299
|
+
const headerSize = 30 + nameLength + extraLength;
|
|
7300
|
+
const nameStart = offset + 30;
|
|
7301
|
+
const nameEnd = nameStart + nameLength;
|
|
7302
|
+
if (nameEnd > bytes.length) break;
|
|
7303
|
+
const name2 = bytes.toString("utf8", nameStart, nameEnd);
|
|
7304
|
+
const dataStart = offset + headerSize;
|
|
7305
|
+
const dataEnd = dataStart + compressedSize;
|
|
7306
|
+
if (dataEnd > bytes.length) break;
|
|
7307
|
+
if (method === 0 || method === 8) {
|
|
7308
|
+
entries.push({
|
|
7309
|
+
name: name2,
|
|
7310
|
+
method,
|
|
7311
|
+
compressedSize,
|
|
7312
|
+
uncompressedSize,
|
|
7313
|
+
dataOffset: dataStart
|
|
7314
|
+
});
|
|
7315
|
+
}
|
|
7316
|
+
offset = dataEnd;
|
|
7317
|
+
}
|
|
7318
|
+
return entries;
|
|
7319
|
+
}
|
|
7320
|
+
function readZipEntryPayload(bytes, descriptor) {
|
|
7321
|
+
const compressed = bytes.subarray(
|
|
7322
|
+
descriptor.dataOffset,
|
|
7323
|
+
descriptor.dataOffset + descriptor.compressedSize
|
|
7324
|
+
);
|
|
7325
|
+
return decompressZipEntry(descriptor.method, compressed, descriptor.uncompressedSize);
|
|
7326
|
+
}
|
|
7327
|
+
function buildTranscript(filename, title, turns) {
|
|
7328
|
+
assertTurnCount(turns);
|
|
7329
|
+
return {
|
|
7330
|
+
title: title || "Imported chat",
|
|
7331
|
+
turns,
|
|
7332
|
+
partial: false,
|
|
7333
|
+
source: {
|
|
7334
|
+
kind: "official-export",
|
|
7335
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7336
|
+
filename
|
|
7337
|
+
}
|
|
7338
|
+
};
|
|
7339
|
+
}
|
|
7340
|
+
function previewOfTurns(turns) {
|
|
7341
|
+
const firstUser = turns.find((turn) => turn.role === "user") ?? turns[0];
|
|
7342
|
+
if (firstUser === void 0) return "";
|
|
7343
|
+
const text3 = firstUser.text.trim();
|
|
7344
|
+
return text3.length <= 160 ? text3 : `${text3.slice(0, 159)}\u2026`;
|
|
7345
|
+
}
|
|
7346
|
+
function toCatalogItems(filename, conversations) {
|
|
7347
|
+
const items = [];
|
|
7348
|
+
for (let i = 0; i < conversations.length && items.length < WEB_CHAT_MAX_EXPORT_CONVERSATIONS; i++) {
|
|
7349
|
+
const conversation = conversations[i];
|
|
7350
|
+
try {
|
|
7351
|
+
const transcript = buildTranscript(filename, conversation.title, conversation.turns);
|
|
7352
|
+
items.push({
|
|
7353
|
+
id: `chat-${i + 1}`,
|
|
7354
|
+
title: transcript.title,
|
|
7355
|
+
turnCount: transcript.turns.length,
|
|
7356
|
+
preview: previewOfTurns(transcript.turns),
|
|
7357
|
+
transcript
|
|
7358
|
+
});
|
|
7359
|
+
} catch {
|
|
7360
|
+
}
|
|
7361
|
+
}
|
|
7362
|
+
return items;
|
|
7363
|
+
}
|
|
7364
|
+
function conversationsFromBytes(filename, bytes) {
|
|
7365
|
+
const lowerName = filename.toLowerCase();
|
|
7366
|
+
if (isZipArchive(bytes) || lowerName.endsWith(".zip")) {
|
|
7367
|
+
const descriptors = listZipEntryDescriptors(bytes).filter((entry) => !entry.name.endsWith("/") && zipEntryPriority(entry.name) < 9).sort((a, b) => zipEntryPriority(a.name) - zipEntryPriority(b.name) || a.name.localeCompare(b.name));
|
|
7368
|
+
if (descriptors.length === 0) {
|
|
7369
|
+
throw new Error("unrecognized-export: no parseable file in zip");
|
|
7370
|
+
}
|
|
7371
|
+
const jsonEntries = descriptors.filter((entry) => entry.name.toLowerCase().endsWith(".json"));
|
|
7372
|
+
for (const entry of jsonEntries) {
|
|
7373
|
+
const payload = readZipEntryPayload(bytes, entry);
|
|
7374
|
+
assertPayloadSize(payload);
|
|
7375
|
+
const nestedName = entry.name.split(/[/\\]/).pop() ?? entry.name;
|
|
7376
|
+
let parsed;
|
|
7377
|
+
try {
|
|
7378
|
+
parsed = JSON.parse(payload.toString("utf8"));
|
|
7379
|
+
} catch {
|
|
7380
|
+
continue;
|
|
7381
|
+
}
|
|
7382
|
+
const conversations = conversationsFromJsonValue(parsed, extractTitleFromMarkdown(nestedName));
|
|
7383
|
+
if (conversations.length > 1) return conversations;
|
|
7384
|
+
}
|
|
7385
|
+
const out = [];
|
|
7386
|
+
for (const entry of descriptors) {
|
|
7387
|
+
if (out.length >= WEB_CHAT_MAX_EXPORT_CONVERSATIONS) break;
|
|
7388
|
+
try {
|
|
7389
|
+
const payload = readZipEntryPayload(bytes, entry);
|
|
7390
|
+
assertPayloadSize(payload);
|
|
7391
|
+
const nestedName = entry.name.split(/[/\\]/).pop() ?? entry.name;
|
|
7392
|
+
out.push(...conversationsFromBytes(nestedName, payload));
|
|
7393
|
+
} catch {
|
|
7394
|
+
}
|
|
7395
|
+
}
|
|
7396
|
+
return out;
|
|
7397
|
+
}
|
|
7398
|
+
if (lowerName.endsWith(".json") || bytes[0] === 123 || bytes[0] === 91) {
|
|
7399
|
+
const text3 = bytes.toString("utf8");
|
|
7400
|
+
let parsed;
|
|
7401
|
+
try {
|
|
7402
|
+
parsed = JSON.parse(text3);
|
|
7403
|
+
} catch {
|
|
7404
|
+
throw new Error("unrecognized-export: invalid json");
|
|
7405
|
+
}
|
|
7406
|
+
return conversationsFromJsonValue(parsed, extractTitleFromMarkdown(filename));
|
|
7407
|
+
}
|
|
7408
|
+
if (lowerName.endsWith(".md") || lowerName.endsWith(".txt")) {
|
|
7409
|
+
return parseTextConversations(bytes.toString("utf8"), filename);
|
|
7410
|
+
}
|
|
7411
|
+
throw new Error("unrecognized-export: unsupported file type");
|
|
7412
|
+
}
|
|
7413
|
+
function analyzeWebChatExport(input) {
|
|
7414
|
+
assertPayloadSize(input.bytes);
|
|
7415
|
+
const conversations = conversationsFromBytes(input.filename, input.bytes);
|
|
7416
|
+
const items = toCatalogItems(input.filename, conversations);
|
|
7417
|
+
if (items.length === 0) {
|
|
7418
|
+
throw new Error("No messages found in export");
|
|
7419
|
+
}
|
|
7420
|
+
return {
|
|
7421
|
+
items,
|
|
7422
|
+
truncated: conversations.length > items.length
|
|
7423
|
+
};
|
|
7424
|
+
}
|
|
7425
|
+
|
|
7426
|
+
// src/host/web-chat-bridge/share-link.ts
|
|
7427
|
+
var SHARE_URL_RE = /(?:https?:\/\/chat\.deepseek\.com)?\/share\/([A-Za-z0-9_-]+)/i;
|
|
7428
|
+
var SHARE_ID_RE = /^[A-Za-z0-9_-]{6,}$/;
|
|
7429
|
+
function extractWebChatShareId(raw) {
|
|
7430
|
+
const trimmed = raw.trim();
|
|
7431
|
+
if (trimmed === "") return null;
|
|
7432
|
+
const fromUrl = trimmed.match(SHARE_URL_RE);
|
|
7433
|
+
if (fromUrl?.[1]) return fromUrl[1];
|
|
7434
|
+
if (SHARE_ID_RE.test(trimmed)) return trimmed;
|
|
7435
|
+
return null;
|
|
7436
|
+
}
|
|
7437
|
+
function webChatSharePageUrl(shareId) {
|
|
7438
|
+
return `https://chat.deepseek.com/share/${shareId}`;
|
|
7439
|
+
}
|
|
7440
|
+
function webChatShareContentApiUrl(shareId) {
|
|
7441
|
+
return `https://chat.deepseek.com/api/v0/share/content?share_id=${encodeURIComponent(shareId)}`;
|
|
7442
|
+
}
|
|
7443
|
+
function normalizeRole2(raw) {
|
|
7444
|
+
if (typeof raw !== "string") return null;
|
|
7445
|
+
const key = raw.trim().toLowerCase();
|
|
7446
|
+
if (key === "user" || key === "human") return "user";
|
|
7447
|
+
if (key === "assistant" || key === "ai" || key === "model") return "assistant";
|
|
7448
|
+
return null;
|
|
7449
|
+
}
|
|
7450
|
+
function messageText2(raw) {
|
|
7451
|
+
if (typeof raw === "string") return raw.trim();
|
|
7452
|
+
if (Array.isArray(raw)) {
|
|
7453
|
+
return raw.map((part) => {
|
|
7454
|
+
if (typeof part === "string") return part;
|
|
7455
|
+
if (part && typeof part === "object" && "text" in part) {
|
|
7456
|
+
const text3 = Reflect.get(part, "text");
|
|
7457
|
+
return typeof text3 === "string" ? text3 : "";
|
|
7458
|
+
}
|
|
7459
|
+
return "";
|
|
7460
|
+
}).filter(Boolean).join("\n").trim();
|
|
7461
|
+
}
|
|
7462
|
+
return "";
|
|
7463
|
+
}
|
|
7464
|
+
function fragmentsText(fragments, preferTypes) {
|
|
7465
|
+
if (!Array.isArray(fragments)) return "";
|
|
7466
|
+
const preferred = new Set(preferTypes.map((type) => type.toUpperCase()));
|
|
7467
|
+
const preferredParts = [];
|
|
7468
|
+
const fallbackParts = [];
|
|
7469
|
+
for (const frag of fragments) {
|
|
7470
|
+
if (frag === null || typeof frag !== "object") continue;
|
|
7471
|
+
const type = String(Reflect.get(frag, "type") ?? "").toUpperCase();
|
|
7472
|
+
const content = Reflect.get(frag, "content");
|
|
7473
|
+
if (typeof content !== "string" || content.trim() === "") continue;
|
|
7474
|
+
const text3 = content.trim();
|
|
7475
|
+
if (type === "THINK" || type === "TIP" || type.startsWith("TOOL_")) {
|
|
7476
|
+
if (preferred.size === 0) fallbackParts.push(text3);
|
|
7477
|
+
continue;
|
|
7478
|
+
}
|
|
7479
|
+
if (preferred.size === 0 || preferred.has(type)) preferredParts.push(text3);
|
|
7480
|
+
else fallbackParts.push(text3);
|
|
7481
|
+
}
|
|
7482
|
+
if (preferredParts.length > 0) return preferredParts.join("\n\n");
|
|
7483
|
+
return fallbackParts.join("\n\n");
|
|
7484
|
+
}
|
|
7485
|
+
function rowText(item, role) {
|
|
7486
|
+
const direct = messageText2(item.content ?? item.text ?? item.message);
|
|
7487
|
+
if (direct) return direct;
|
|
7488
|
+
if (role === "user") return fragmentsText(item.fragments, ["REQUEST"]);
|
|
7489
|
+
return fragmentsText(item.fragments, ["RESPONSE"]);
|
|
7490
|
+
}
|
|
7491
|
+
function assertTurns(turns) {
|
|
7492
|
+
if (turns.length === 0) {
|
|
7493
|
+
throw new Error("Share link has no messages");
|
|
7494
|
+
}
|
|
7495
|
+
if (turns.length > WEB_CHAT_MAX_MESSAGES) {
|
|
7496
|
+
throw new Error(`Exceeds message limit (${WEB_CHAT_MAX_MESSAGES})`);
|
|
7497
|
+
}
|
|
7498
|
+
let bytes = 0;
|
|
7499
|
+
for (const turn of turns) {
|
|
7500
|
+
bytes += Buffer.byteLength(turn.text, "utf8");
|
|
7501
|
+
if (bytes > WEB_CHAT_MAX_TEXT_BYTES) {
|
|
7502
|
+
throw new Error(`Share content exceeds ${WEB_CHAT_MAX_TEXT_BYTES} byte limit`);
|
|
7503
|
+
}
|
|
7504
|
+
}
|
|
7505
|
+
}
|
|
7506
|
+
function bizRecord(data) {
|
|
7507
|
+
if (data === null || typeof data !== "object") return null;
|
|
7508
|
+
const root = data;
|
|
7509
|
+
if (Reflect.get(root, "code") !== 0 && Reflect.get(root, "code") !== void 0) {
|
|
7510
|
+
const msg = Reflect.get(root, "msg");
|
|
7511
|
+
throw new Error(
|
|
7512
|
+
typeof msg === "string" && msg.trim() !== "" ? `share-api: ${msg}` : "share-api: request failed"
|
|
7513
|
+
);
|
|
7514
|
+
}
|
|
7515
|
+
const payload = Reflect.get(root, "data");
|
|
7516
|
+
const biz = payload !== null && typeof payload === "object" ? Reflect.get(payload, "biz_data") : void 0;
|
|
7517
|
+
if (biz !== null && typeof biz === "object") return biz;
|
|
7518
|
+
return root;
|
|
7519
|
+
}
|
|
7520
|
+
function turnsFromBizRecord(record2) {
|
|
7521
|
+
const rowsRaw = record2.messages ?? record2.chat_messages;
|
|
7522
|
+
const rows = Array.isArray(rowsRaw) ? rowsRaw : [];
|
|
7523
|
+
const turns = [];
|
|
7524
|
+
for (const row of rows) {
|
|
7525
|
+
if (row === null || typeof row !== "object") continue;
|
|
7526
|
+
const item = row;
|
|
7527
|
+
const role = normalizeRole2(item.role ?? item.author ?? item.speaker);
|
|
7528
|
+
if (!role) continue;
|
|
7529
|
+
const text3 = rowText(item, role);
|
|
7530
|
+
if (!text3) continue;
|
|
7531
|
+
turns.push({ role, text: text3 });
|
|
7532
|
+
}
|
|
7533
|
+
return turns;
|
|
7534
|
+
}
|
|
7535
|
+
function parseWebChatShareContent(data, options) {
|
|
7536
|
+
const record2 = bizRecord(data);
|
|
7537
|
+
if (record2 === null) {
|
|
7538
|
+
throw new Error("unrecognized-share: empty response");
|
|
7539
|
+
}
|
|
7540
|
+
const titleRaw = record2.title;
|
|
7541
|
+
const title = typeof titleRaw === "string" && titleRaw.trim() !== "" ? titleRaw.trim() : `Shared chat ${options.shareId}`;
|
|
7542
|
+
const turns = turnsFromBizRecord(record2);
|
|
7543
|
+
assertTurns(turns);
|
|
7544
|
+
return {
|
|
7545
|
+
title,
|
|
7546
|
+
turns,
|
|
7547
|
+
partial: false,
|
|
7548
|
+
source: {
|
|
7549
|
+
kind: "share-link",
|
|
7550
|
+
url: options.shareUrl,
|
|
7551
|
+
chatSessionId: options.shareId,
|
|
7552
|
+
capturedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
7553
|
+
}
|
|
7554
|
+
};
|
|
7555
|
+
}
|
|
7556
|
+
async function fetchWebChatShareContent(shareId, signal) {
|
|
7557
|
+
signal.throwIfAborted();
|
|
7558
|
+
const response = await fetch(webChatShareContentApiUrl(shareId), {
|
|
7559
|
+
method: "GET",
|
|
7560
|
+
signal,
|
|
7561
|
+
headers: {
|
|
7562
|
+
accept: "application/json, text/plain, */*",
|
|
7563
|
+
referer: "https://chat.deepseek.com/",
|
|
7564
|
+
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
|
|
7565
|
+
}
|
|
7566
|
+
});
|
|
7567
|
+
if (!response.ok) {
|
|
7568
|
+
throw new Error(`share-api: HTTP ${response.status}`);
|
|
7569
|
+
}
|
|
7570
|
+
return await response.json();
|
|
7571
|
+
}
|
|
7572
|
+
|
|
7573
|
+
// src/host/web-chat-bridge/login-snapshot.ts
|
|
7574
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7575
|
+
import { dirname, join as join9 } from "node:path";
|
|
7576
|
+
|
|
7577
|
+
// src/host/web-chat-bridge/login-snapshot-types.ts
|
|
7578
|
+
var WEB_CHAT_OFFICIAL_ORIGIN = "https://chat.deepseek.com";
|
|
7579
|
+
var WEB_CHAT_LOGIN_SNAPSHOT_VERSION = 1;
|
|
7580
|
+
|
|
7581
|
+
// src/host/web-chat-bridge/login-snapshot-policy.ts
|
|
7582
|
+
function localStorageKeyCount(slice) {
|
|
7583
|
+
return Object.keys(slice.localStorage).length;
|
|
7584
|
+
}
|
|
7585
|
+
function hasCookie(slice) {
|
|
7586
|
+
return slice.cookie.trim().length > 0;
|
|
7587
|
+
}
|
|
7588
|
+
function shouldPersistWebChatLoginCapture(baseline, candidate) {
|
|
7589
|
+
if (candidate === null) return false;
|
|
7590
|
+
const candidateKeys = localStorageKeyCount(candidate);
|
|
7591
|
+
const candidateCookie = hasCookie(candidate);
|
|
7592
|
+
if (candidateKeys === 0 && !candidateCookie) return false;
|
|
7593
|
+
if (baseline === null) return true;
|
|
7594
|
+
const baselineKeys = localStorageKeyCount(baseline);
|
|
7595
|
+
const baselineCookie = hasCookie(baseline);
|
|
7596
|
+
if (baselineKeys > 0 && candidateKeys === 0) return false;
|
|
7597
|
+
if (baselineCookie && !candidateCookie && candidateKeys === 0) return false;
|
|
7598
|
+
return true;
|
|
7599
|
+
}
|
|
7600
|
+
|
|
7601
|
+
// src/host/web-chat-bridge/login-snapshot.ts
|
|
7602
|
+
var SENSITIVE_STORAGE_KEY = /password|passwd|pwd/i;
|
|
7603
|
+
function webChatBridgeDataDir(pluginDataPackageRoot) {
|
|
7604
|
+
return join9(pluginDataPackageRoot, "web-chat-bridge");
|
|
7605
|
+
}
|
|
7606
|
+
function webChatLoginSnapshotPath(pluginDataPackageRoot) {
|
|
7607
|
+
return join9(webChatBridgeDataDir(pluginDataPackageRoot), "session.json");
|
|
7608
|
+
}
|
|
7609
|
+
function sanitizeLocalStorage(entries) {
|
|
7610
|
+
const out = {};
|
|
7611
|
+
for (const [key, value] of Object.entries(entries)) {
|
|
7612
|
+
if (typeof key !== "string" || typeof value !== "string") continue;
|
|
7613
|
+
if (SENSITIVE_STORAGE_KEY.test(key)) continue;
|
|
7614
|
+
out[key] = value;
|
|
7615
|
+
}
|
|
7616
|
+
return out;
|
|
7617
|
+
}
|
|
7618
|
+
function parseSnapshot(raw) {
|
|
7619
|
+
try {
|
|
7620
|
+
const parsed = JSON.parse(raw);
|
|
7621
|
+
if (parsed.version !== WEB_CHAT_LOGIN_SNAPSHOT_VERSION) return null;
|
|
7622
|
+
if (parsed.origin !== WEB_CHAT_OFFICIAL_ORIGIN) return null;
|
|
7623
|
+
const localStorage = sanitizeLocalStorage(
|
|
7624
|
+
typeof parsed.localStorage === "object" && parsed.localStorage !== null ? parsed.localStorage : {}
|
|
7625
|
+
);
|
|
7626
|
+
const cookie = typeof parsed.cookie === "string" ? parsed.cookie : "";
|
|
7627
|
+
const savedAt = typeof parsed.savedAt === "string" && parsed.savedAt.trim() !== "" ? parsed.savedAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
7628
|
+
return {
|
|
7629
|
+
version: WEB_CHAT_LOGIN_SNAPSHOT_VERSION,
|
|
7630
|
+
origin: WEB_CHAT_OFFICIAL_ORIGIN,
|
|
7631
|
+
localStorage,
|
|
7632
|
+
cookie,
|
|
7633
|
+
savedAt
|
|
7634
|
+
};
|
|
7635
|
+
} catch {
|
|
7636
|
+
return null;
|
|
6584
7637
|
}
|
|
6585
7638
|
}
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
7639
|
+
function loadWebChatLoginSnapshot(pluginDataPackageRoot) {
|
|
7640
|
+
const path = webChatLoginSnapshotPath(pluginDataPackageRoot);
|
|
7641
|
+
if (!existsSync5(path)) return null;
|
|
7642
|
+
try {
|
|
7643
|
+
return parseSnapshot(readFileSync(path, "utf8"));
|
|
7644
|
+
} catch {
|
|
7645
|
+
return null;
|
|
6592
7646
|
}
|
|
7647
|
+
}
|
|
7648
|
+
function saveWebChatLoginSnapshot(pluginDataPackageRoot, input, options) {
|
|
7649
|
+
const baseline = options?.baseline !== void 0 ? options.baseline : loadWebChatLoginSnapshot(pluginDataPackageRoot);
|
|
7650
|
+
const candidate = {
|
|
7651
|
+
localStorage: input.localStorage,
|
|
7652
|
+
cookie: input.cookie
|
|
7653
|
+
};
|
|
7654
|
+
if (!shouldPersistWebChatLoginCapture(baseline, candidate)) {
|
|
7655
|
+
return baseline;
|
|
7656
|
+
}
|
|
7657
|
+
if (input.origin !== void 0 && input.origin !== WEB_CHAT_OFFICIAL_ORIGIN) {
|
|
7658
|
+
throw new Error("Web chat login snapshot origin mismatch");
|
|
7659
|
+
}
|
|
7660
|
+
const snapshot = {
|
|
7661
|
+
version: WEB_CHAT_LOGIN_SNAPSHOT_VERSION,
|
|
7662
|
+
origin: WEB_CHAT_OFFICIAL_ORIGIN,
|
|
7663
|
+
localStorage: sanitizeLocalStorage(input.localStorage),
|
|
7664
|
+
cookie: typeof input.cookie === "string" ? input.cookie : "",
|
|
7665
|
+
savedAt: typeof input.savedAt === "string" && input.savedAt.trim() !== "" ? input.savedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
7666
|
+
};
|
|
7667
|
+
const path = webChatLoginSnapshotPath(pluginDataPackageRoot);
|
|
7668
|
+
mkdirSync2(dirname(path), { recursive: true });
|
|
7669
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
7670
|
+
writeFileSync(tmp, `${JSON.stringify(snapshot, null, 2)}
|
|
7671
|
+
`, "utf8");
|
|
7672
|
+
renameSync(tmp, path);
|
|
7673
|
+
return snapshot;
|
|
7674
|
+
}
|
|
7675
|
+
function clearWebChatLoginSnapshot(pluginDataPackageRoot) {
|
|
7676
|
+
const path = webChatLoginSnapshotPath(pluginDataPackageRoot);
|
|
7677
|
+
if (!existsSync5(path)) return false;
|
|
6593
7678
|
try {
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
const path = stdout.trim();
|
|
6599
|
-
return path === "" ? null : path;
|
|
6600
|
-
} catch (error) {
|
|
6601
|
-
const code = error !== null && typeof error === "object" ? Reflect.get(error, "code") : void 0;
|
|
6602
|
-
if (code === 1) return null;
|
|
6603
|
-
return void 0;
|
|
7679
|
+
unlinkSync(path);
|
|
7680
|
+
return true;
|
|
7681
|
+
} catch {
|
|
7682
|
+
return false;
|
|
6604
7683
|
}
|
|
6605
7684
|
}
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
7685
|
+
|
|
7686
|
+
// src/host/extra-folders/io.ts
|
|
7687
|
+
import { promises as fsp } from "node:fs";
|
|
7688
|
+
import { basename as basename4, join as join10, resolve as resolve4, sep as sep4 } from "node:path";
|
|
7689
|
+
|
|
7690
|
+
// src/host/extra-folders/paths.ts
|
|
7691
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
7692
|
+
import { isAbsolute as isAbsolute3, relative as relative2, resolve as resolve3, sep as sep3 } from "node:path";
|
|
7693
|
+
function cwdStorageKey(primaryCwd) {
|
|
7694
|
+
const normalized = resolve3(primaryCwd);
|
|
7695
|
+
return createHash6("sha256").update(normalized).digest("hex").slice(0, 32);
|
|
7696
|
+
}
|
|
7697
|
+
function isInsideRoot(root, absolutePath2) {
|
|
7698
|
+
const base = resolve3(root);
|
|
7699
|
+
const target = resolve3(absolutePath2);
|
|
7700
|
+
const rel = relative2(base, target);
|
|
7701
|
+
return rel === "" || !rel.startsWith(`..${sep3}`) && rel !== ".." && !isAbsolute3(rel);
|
|
7702
|
+
}
|
|
7703
|
+
function assertInsideAllowedRoots(primaryCwd, extraRoots, absolutePath2) {
|
|
7704
|
+
if (isInsideRoot(primaryCwd, absolutePath2)) return;
|
|
7705
|
+
for (const root of extraRoots) {
|
|
7706
|
+
if (isInsideRoot(root, absolutePath2)) return;
|
|
6618
7707
|
}
|
|
6619
|
-
throw new
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
);
|
|
7708
|
+
throw new Error("Path is outside the session workspace and attached folders");
|
|
7709
|
+
}
|
|
7710
|
+
function normalizeRootPath(path) {
|
|
7711
|
+
const trimmed = path.trim();
|
|
7712
|
+
if (trimmed === "") throw new Error("Path is empty");
|
|
7713
|
+
return resolve3(trimmed);
|
|
6623
7714
|
}
|
|
6624
7715
|
|
|
6625
7716
|
// src/host/extra-folders/io.ts
|
|
6626
7717
|
function sessionCwd(session) {
|
|
6627
7718
|
const header = session?.header;
|
|
6628
|
-
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return
|
|
7719
|
+
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return resolve4(header.cwd);
|
|
6629
7720
|
try {
|
|
6630
7721
|
const requested = session?.requestHeader?.();
|
|
6631
7722
|
if (typeof requested?.cwd === "string" && requested.cwd.trim() !== "") {
|
|
6632
|
-
return
|
|
7723
|
+
return resolve4(requested.cwd);
|
|
6633
7724
|
}
|
|
6634
7725
|
} catch {
|
|
6635
7726
|
}
|
|
@@ -6648,7 +7739,7 @@ function titleOf(path, explicit) {
|
|
|
6648
7739
|
return name2 === "" ? path : name2;
|
|
6649
7740
|
}
|
|
6650
7741
|
function samePath(a, b) {
|
|
6651
|
-
return
|
|
7742
|
+
return resolve4(a).toLowerCase() === resolve4(b).toLowerCase();
|
|
6652
7743
|
}
|
|
6653
7744
|
async function assertDirectory(absolutePath2) {
|
|
6654
7745
|
try {
|
|
@@ -6812,7 +7903,7 @@ async function listExtraFolderEntriesNow(options) {
|
|
|
6812
7903
|
throw new ExtraFoldersError("FILE_DENIED", "Root is not the workspace or an attached folder");
|
|
6813
7904
|
}
|
|
6814
7905
|
const relativePath = relativeUnderRoot(rootPath, options.request.relativePath);
|
|
6815
|
-
const absoluteDir = relativePath === "" ? rootPath :
|
|
7906
|
+
const absoluteDir = relativePath === "" ? rootPath : join10(rootPath, relativePath);
|
|
6816
7907
|
assertInsideAllowedRoots(primaryCwd, extraPaths, absoluteDir);
|
|
6817
7908
|
await assertDirectory(absoluteDir);
|
|
6818
7909
|
let names;
|
|
@@ -6827,14 +7918,14 @@ async function listExtraFolderEntriesNow(options) {
|
|
|
6827
7918
|
const entries = [];
|
|
6828
7919
|
for (const name2 of names) {
|
|
6829
7920
|
if (name2 === "." || name2 === "..") continue;
|
|
6830
|
-
const absolutePath2 =
|
|
7921
|
+
const absolutePath2 = join10(absoluteDir, name2);
|
|
6831
7922
|
try {
|
|
6832
7923
|
assertInsideAllowedRoots(primaryCwd, extraPaths, absolutePath2);
|
|
6833
7924
|
const stat = await fsp.lstat(absolutePath2);
|
|
6834
7925
|
if (stat.isSymbolicLink()) continue;
|
|
6835
7926
|
const kind = stat.isDirectory() ? "directory" : stat.isFile() ? "file" : null;
|
|
6836
7927
|
if (kind === null) continue;
|
|
6837
|
-
const path = relativePath === "" ? name2 :
|
|
7928
|
+
const path = relativePath === "" ? name2 : join10(relativePath, name2);
|
|
6838
7929
|
entries.push({ name: name2, path: path.replace(/\\/g, "/"), absolutePath: absolutePath2, kind });
|
|
6839
7930
|
} catch {
|
|
6840
7931
|
}
|
|
@@ -6850,12 +7941,12 @@ async function listExtraFolderEntriesNow(options) {
|
|
|
6850
7941
|
};
|
|
6851
7942
|
}
|
|
6852
7943
|
function loadExtraRootPaths(store, primaryCwd) {
|
|
6853
|
-
return store.load(
|
|
7944
|
+
return store.load(resolve4(primaryCwd)).roots.map((root) => root.path);
|
|
6854
7945
|
}
|
|
6855
7946
|
|
|
6856
7947
|
// src/host/extra-folders/store.ts
|
|
6857
|
-
import { mkdirSync as
|
|
6858
|
-
import { dirname, join as
|
|
7948
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync2, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
7949
|
+
import { dirname as dirname2, join as join11 } from "node:path";
|
|
6859
7950
|
function emptyDoc(primaryCwd) {
|
|
6860
7951
|
return {
|
|
6861
7952
|
version: EXTRA_FOLDERS_VERSION,
|
|
@@ -6887,14 +7978,14 @@ function parseDoc(raw, primaryCwd) {
|
|
|
6887
7978
|
}
|
|
6888
7979
|
}
|
|
6889
7980
|
function createExtraFoldersStore(rootDir) {
|
|
6890
|
-
|
|
6891
|
-
const fileOf = (primaryCwd) =>
|
|
7981
|
+
mkdirSync3(rootDir, { recursive: true });
|
|
7982
|
+
const fileOf = (primaryCwd) => join11(rootDir, `${cwdStorageKey(primaryCwd)}.json`);
|
|
6892
7983
|
return {
|
|
6893
7984
|
rootDir,
|
|
6894
7985
|
load(primaryCwd) {
|
|
6895
7986
|
const file = fileOf(primaryCwd);
|
|
6896
7987
|
try {
|
|
6897
|
-
return parseDoc(
|
|
7988
|
+
return parseDoc(readFileSync2(file, "utf8"), primaryCwd);
|
|
6898
7989
|
} catch (error) {
|
|
6899
7990
|
const code = error !== null && typeof error === "object" ? String(Reflect.get(error, "code") ?? "") : "";
|
|
6900
7991
|
if (code === "ENOENT") return emptyDoc(primaryCwd);
|
|
@@ -6908,18 +7999,18 @@ function createExtraFoldersStore(rootDir) {
|
|
|
6908
7999
|
roots: [...roots]
|
|
6909
8000
|
};
|
|
6910
8001
|
const file = fileOf(primaryCwd);
|
|
6911
|
-
|
|
8002
|
+
mkdirSync3(dirname2(file), { recursive: true });
|
|
6912
8003
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
6913
|
-
|
|
8004
|
+
writeFileSync2(tmp, `${JSON.stringify(doc, null, 2)}
|
|
6914
8005
|
`, "utf8");
|
|
6915
|
-
|
|
8006
|
+
renameSync2(tmp, file);
|
|
6916
8007
|
return doc;
|
|
6917
8008
|
}
|
|
6918
8009
|
};
|
|
6919
8010
|
}
|
|
6920
8011
|
|
|
6921
8012
|
// src/host/file-edit/io.ts
|
|
6922
|
-
import { isAbsolute as isAbsolute4, resolve as
|
|
8013
|
+
import { isAbsolute as isAbsolute4, resolve as resolve5 } from "node:path";
|
|
6923
8014
|
|
|
6924
8015
|
// src/host/file-edit/types.ts
|
|
6925
8016
|
var FILE_EDIT_MAX_BYTES = 2 * 1024 * 1024;
|
|
@@ -7000,7 +8091,7 @@ async function resolveTarget(fs, workspaceRoot, extraRoots, path) {
|
|
|
7000
8091
|
const trimmed = path.trim();
|
|
7001
8092
|
if (trimmed === "") throw new FileEditError("FILE_NOT_FOUND", "Path is empty");
|
|
7002
8093
|
const target = await fs.resolve(trimmed, { cwd: workspaceRoot });
|
|
7003
|
-
const absolutePath2 = processPathOf(target, isAbsolute4(trimmed) ? trimmed :
|
|
8094
|
+
const absolutePath2 = processPathOf(target, isAbsolute4(trimmed) ? trimmed : resolve5(workspaceRoot, trimmed));
|
|
7004
8095
|
try {
|
|
7005
8096
|
assertInsideAllowedRoots(workspaceRoot, extraRoots, absolutePath2);
|
|
7006
8097
|
} catch (error) {
|
|
@@ -7096,9 +8187,9 @@ async function writeWorkspaceFileNow(options) {
|
|
|
7096
8187
|
}
|
|
7097
8188
|
|
|
7098
8189
|
// src/host/file-edit/monaco.ts
|
|
7099
|
-
import { existsSync as
|
|
8190
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
7100
8191
|
import { promises as fsp2 } from "node:fs";
|
|
7101
|
-
import { dirname as
|
|
8192
|
+
import { dirname as dirname3, extname, join as join12, resolve as resolve6, sep as sep5 } from "node:path";
|
|
7102
8193
|
import { fileURLToPath } from "node:url";
|
|
7103
8194
|
|
|
7104
8195
|
// src/shared/monaco-route.ts
|
|
@@ -7107,16 +8198,16 @@ var MONACO_ROUTE = "/api/agent-enhancer/monaco";
|
|
|
7107
8198
|
// src/host/file-edit/monaco.ts
|
|
7108
8199
|
var FILE_PATTERN = /^(?:vs\/)?(?:[A-Za-z0-9._-]+\/)*[A-Za-z0-9._-]+$/;
|
|
7109
8200
|
function packageRootCandidates() {
|
|
7110
|
-
const here =
|
|
8201
|
+
const here = dirname3(fileURLToPath(import.meta.url));
|
|
7111
8202
|
return [
|
|
7112
|
-
|
|
7113
|
-
|
|
7114
|
-
|
|
8203
|
+
resolve6(here, "..", "vendor", "monaco", "vs"),
|
|
8204
|
+
resolve6(here, "..", "..", "vendor", "monaco", "vs"),
|
|
8205
|
+
resolve6(here, "..", "..", "..", "vendor", "monaco", "vs")
|
|
7115
8206
|
];
|
|
7116
8207
|
}
|
|
7117
8208
|
function resolveMonacoVsDir() {
|
|
7118
8209
|
for (const candidate of packageRootCandidates()) {
|
|
7119
|
-
if (
|
|
8210
|
+
if (existsSync6(join12(candidate, "loader.js"))) return candidate;
|
|
7120
8211
|
}
|
|
7121
8212
|
return packageRootCandidates()[0];
|
|
7122
8213
|
}
|
|
@@ -7162,8 +8253,8 @@ function plain(status, message) {
|
|
|
7162
8253
|
});
|
|
7163
8254
|
}
|
|
7164
8255
|
function isInside(root, candidate) {
|
|
7165
|
-
const normalizedRoot =
|
|
7166
|
-
const normalized =
|
|
8256
|
+
const normalizedRoot = resolve6(root);
|
|
8257
|
+
const normalized = resolve6(candidate);
|
|
7167
8258
|
if (normalized === normalizedRoot) return true;
|
|
7168
8259
|
return normalized.startsWith(normalizedRoot + sep5);
|
|
7169
8260
|
}
|
|
@@ -7172,7 +8263,7 @@ async function locateFile(vsDir, relativeUnderVs) {
|
|
|
7172
8263
|
const parts = relativeUnderVs.split("/");
|
|
7173
8264
|
let cursor = rootReal;
|
|
7174
8265
|
for (const part of parts) {
|
|
7175
|
-
cursor =
|
|
8266
|
+
cursor = join12(cursor, part);
|
|
7176
8267
|
if (!isInside(rootReal, cursor)) return null;
|
|
7177
8268
|
}
|
|
7178
8269
|
if (!isInside(rootReal, cursor)) return null;
|
|
@@ -7253,16 +8344,16 @@ function installMonacoRoute(ctx) {
|
|
|
7253
8344
|
}
|
|
7254
8345
|
|
|
7255
8346
|
// src/host/instructions-skills/io.ts
|
|
7256
|
-
import { existsSync as
|
|
7257
|
-
import { basename as basename13, join as
|
|
8347
|
+
import { existsSync as existsSync16, readFileSync as readFileSync7, statSync as statSync5 } from "node:fs";
|
|
8348
|
+
import { basename as basename13, join as join26, resolve as resolve16, sep as sep7 } from "node:path";
|
|
7258
8349
|
|
|
7259
8350
|
// src/host/instructions-skills/create.ts
|
|
7260
|
-
import { existsSync as
|
|
7261
|
-
import { dirname as
|
|
8351
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync4, writeFileSync as writeFileSync3 } from "node:fs";
|
|
8352
|
+
import { dirname as dirname5, join as join14, resolve as resolve8 } from "node:path";
|
|
7262
8353
|
|
|
7263
8354
|
// src/host/instructions-skills/paths.ts
|
|
7264
|
-
import { existsSync as
|
|
7265
|
-
import { basename as basename5, dirname as
|
|
8355
|
+
import { existsSync as existsSync7, statSync as statSync2 } from "node:fs";
|
|
8356
|
+
import { basename as basename5, dirname as dirname4, join as join13, resolve as resolve7, sep as sep6 } from "node:path";
|
|
7266
8357
|
import { homedir as homedir3 } from "node:os";
|
|
7267
8358
|
var INSTRUCTION_CANDIDATES = [
|
|
7268
8359
|
"AGENTS.md",
|
|
@@ -7273,76 +8364,76 @@ var INSTRUCTION_CANDIDATES = [
|
|
|
7273
8364
|
var PROJECT_ROOT_MARKERS = [".git"];
|
|
7274
8365
|
function dshHomeOf(env = process.env) {
|
|
7275
8366
|
const fromEnv = env.DSH_HOME;
|
|
7276
|
-
if (typeof fromEnv === "string" && fromEnv.trim() !== "") return
|
|
7277
|
-
return
|
|
8367
|
+
if (typeof fromEnv === "string" && fromEnv.trim() !== "") return resolve7(fromEnv.trim());
|
|
8368
|
+
return resolve7(homedir3(), ".dsh");
|
|
7278
8369
|
}
|
|
7279
8370
|
function agentsHomeOf(env = process.env) {
|
|
7280
8371
|
const fromEnv = env.DSH_AGENTS_HOME;
|
|
7281
|
-
if (typeof fromEnv === "string" && fromEnv.trim() !== "") return
|
|
7282
|
-
return
|
|
8372
|
+
if (typeof fromEnv === "string" && fromEnv.trim() !== "") return resolve7(fromEnv.trim());
|
|
8373
|
+
return resolve7(homedir3(), ".agents");
|
|
7283
8374
|
}
|
|
7284
8375
|
function findProjectRoot(cwd, markers = PROJECT_ROOT_MARKERS) {
|
|
7285
|
-
let current =
|
|
8376
|
+
let current = resolve7(cwd);
|
|
7286
8377
|
for (; ; ) {
|
|
7287
8378
|
for (const marker of markers) {
|
|
7288
|
-
if (
|
|
8379
|
+
if (existsSync7(join13(current, marker))) return current;
|
|
7289
8380
|
}
|
|
7290
|
-
const parent =
|
|
7291
|
-
if (parent === current) return
|
|
8381
|
+
const parent = dirname4(current);
|
|
8382
|
+
if (parent === current) return resolve7(cwd);
|
|
7292
8383
|
current = parent;
|
|
7293
8384
|
}
|
|
7294
8385
|
}
|
|
7295
8386
|
function projectChainDirs(projectRoot, cwd) {
|
|
7296
|
-
const root =
|
|
7297
|
-
const tip =
|
|
8387
|
+
const root = resolve7(projectRoot);
|
|
8388
|
+
const tip = resolve7(cwd);
|
|
7298
8389
|
if (!isInsideOrSame(root, tip)) return [root];
|
|
7299
8390
|
const parts = [];
|
|
7300
8391
|
let current = tip;
|
|
7301
8392
|
for (; ; ) {
|
|
7302
8393
|
parts.push(current);
|
|
7303
8394
|
if (samePath2(current, root)) break;
|
|
7304
|
-
const parent =
|
|
8395
|
+
const parent = dirname4(current);
|
|
7305
8396
|
if (parent === current) break;
|
|
7306
8397
|
current = parent;
|
|
7307
8398
|
}
|
|
7308
8399
|
return parts.reverse();
|
|
7309
8400
|
}
|
|
7310
8401
|
function skillRootsFor(cwd, projectRoot, env = process.env) {
|
|
7311
|
-
const root =
|
|
7312
|
-
const tip =
|
|
8402
|
+
const root = resolve7(projectRoot);
|
|
8403
|
+
const tip = resolve7(cwd);
|
|
7313
8404
|
return [
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7317
|
-
|
|
7318
|
-
|
|
7319
|
-
|
|
8405
|
+
join13(root, ".agents", "skills"),
|
|
8406
|
+
join13(root, ".dsh", "skills"),
|
|
8407
|
+
join13(tip, ".agents", "skills"),
|
|
8408
|
+
join13(tip, ".dsh", "skills"),
|
|
8409
|
+
join13(agentsHomeOf(env), "skills"),
|
|
8410
|
+
join13(dshHomeOf(env), "skills")
|
|
7320
8411
|
].filter((path, index, all) => all.findIndex((other) => samePath2(other, path)) === index);
|
|
7321
8412
|
}
|
|
7322
8413
|
function previewSkillSearchRoots(cwd, projectRoot, env = process.env) {
|
|
7323
|
-
const home =
|
|
8414
|
+
const home = resolve7(homedir3());
|
|
7324
8415
|
return [
|
|
7325
8416
|
...skillRootsFor(cwd, projectRoot, env),
|
|
7326
|
-
|
|
7327
|
-
|
|
7328
|
-
|
|
7329
|
-
|
|
8417
|
+
join13(home, ".cursor", "skills"),
|
|
8418
|
+
join13(home, ".cursor", "skills-cursor"),
|
|
8419
|
+
join13(home, ".codex", "skills"),
|
|
8420
|
+
join13(home, ".claude", "skills")
|
|
7330
8421
|
].filter((path, index, all) => all.findIndex((other) => samePath2(other, path)) === index);
|
|
7331
8422
|
}
|
|
7332
8423
|
function fileBytes(path) {
|
|
7333
8424
|
try {
|
|
7334
|
-
const stat =
|
|
8425
|
+
const stat = statSync2(path);
|
|
7335
8426
|
return stat.isFile() ? stat.size : null;
|
|
7336
8427
|
} catch {
|
|
7337
8428
|
return null;
|
|
7338
8429
|
}
|
|
7339
8430
|
}
|
|
7340
8431
|
function samePath2(a, b) {
|
|
7341
|
-
return
|
|
8432
|
+
return resolve7(a).toLowerCase() === resolve7(b).toLowerCase();
|
|
7342
8433
|
}
|
|
7343
8434
|
function isInsideOrSame(root, candidate) {
|
|
7344
|
-
const base =
|
|
7345
|
-
const path =
|
|
8435
|
+
const base = resolve7(root).toLowerCase();
|
|
8436
|
+
const path = resolve7(candidate).toLowerCase();
|
|
7346
8437
|
if (path === base) return true;
|
|
7347
8438
|
const prefix = base.endsWith(sep6) ? base : `${base}${sep6}`;
|
|
7348
8439
|
return path.startsWith(prefix);
|
|
@@ -7381,12 +8472,12 @@ Instructions for the agent go here.
|
|
|
7381
8472
|
`;
|
|
7382
8473
|
}
|
|
7383
8474
|
function createWorkspaceAgentsFile(projectRoot) {
|
|
7384
|
-
const path =
|
|
7385
|
-
if (
|
|
8475
|
+
const path = resolve8(projectRoot, "AGENTS.md");
|
|
8476
|
+
if (existsSync8(path)) {
|
|
7386
8477
|
throw new AuxiliaryError("FILE_DENIED", "AGENTS.md already exists at the workspace root");
|
|
7387
8478
|
}
|
|
7388
|
-
|
|
7389
|
-
|
|
8479
|
+
mkdirSync4(dirname5(path), { recursive: true });
|
|
8480
|
+
writeFileSync3(path, AGENTS_STUB, "utf8");
|
|
7390
8481
|
return { path, created: true };
|
|
7391
8482
|
}
|
|
7392
8483
|
function createWorkspaceSkill(projectRoot, rawName) {
|
|
@@ -7394,19 +8485,19 @@ function createWorkspaceSkill(projectRoot, rawName) {
|
|
|
7394
8485
|
if (!isKebabCaseName(name2)) {
|
|
7395
8486
|
throw new AuxiliaryError("FILE_DENIED", "Skill name must be kebab-case");
|
|
7396
8487
|
}
|
|
7397
|
-
const dir =
|
|
7398
|
-
const path =
|
|
7399
|
-
if (
|
|
8488
|
+
const dir = join14(resolve8(projectRoot), ".agents", "skills", name2);
|
|
8489
|
+
const path = join14(dir, "SKILL.md");
|
|
8490
|
+
if (existsSync8(path) || existsSync8(dir)) {
|
|
7400
8491
|
throw new AuxiliaryError("FILE_DENIED", "A skill with that name already exists");
|
|
7401
8492
|
}
|
|
7402
|
-
|
|
7403
|
-
|
|
8493
|
+
mkdirSync4(dir, { recursive: true });
|
|
8494
|
+
writeFileSync3(path, skillStubMarkdown(name2), "utf8");
|
|
7404
8495
|
return { path, created: true, name: name2 };
|
|
7405
8496
|
}
|
|
7406
8497
|
|
|
7407
8498
|
// src/host/instructions-skills/discover.ts
|
|
7408
|
-
import { existsSync as
|
|
7409
|
-
import { basename as basename9, dirname as
|
|
8499
|
+
import { existsSync as existsSync12, readdirSync as readdirSync3, readFileSync as readFileSync4, statSync as statSync3 } from "node:fs";
|
|
8500
|
+
import { basename as basename9, dirname as dirname8, join as join19, resolve as resolve12 } from "node:path";
|
|
7410
8501
|
|
|
7411
8502
|
// src/host/instructions-skills/types.ts
|
|
7412
8503
|
function defaultSkillInstallMeta() {
|
|
@@ -7419,9 +8510,9 @@ function defaultSkillInstallMeta() {
|
|
|
7419
8510
|
}
|
|
7420
8511
|
|
|
7421
8512
|
// src/host/instructions-skills/transient-paths.ts
|
|
7422
|
-
import { existsSync as
|
|
8513
|
+
import { existsSync as existsSync9, lstatSync, readdirSync, renameSync as renameSync3, rmSync, unlinkSync as unlinkSync2 } from "node:fs";
|
|
7423
8514
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
7424
|
-
import { basename as basename6, join as
|
|
8515
|
+
import { basename as basename6, join as join15, resolve as resolve9 } from "node:path";
|
|
7425
8516
|
var TRANSIENT_MARK = /\.__ae_(?:removing|installing)_/;
|
|
7426
8517
|
function isTransientSkillEntryName(name2) {
|
|
7427
8518
|
const base = basename6(name2.trim());
|
|
@@ -7430,10 +8521,10 @@ function isTransientSkillEntryName(name2) {
|
|
|
7430
8521
|
}
|
|
7431
8522
|
function skillTransientWorkPath(kind, skillName) {
|
|
7432
8523
|
const safe = skillName.replace(/[^a-zA-Z0-9._-]+/g, "-").slice(0, 80) || "skill";
|
|
7433
|
-
return
|
|
8524
|
+
return join15(tmpdir2(), `ae-skill-${kind}-${safe}-${process.pid}-${Date.now()}`);
|
|
7434
8525
|
}
|
|
7435
8526
|
function sweepTransientSkillEntries(skillsRoot) {
|
|
7436
|
-
const root =
|
|
8527
|
+
const root = resolve9(skillsRoot);
|
|
7437
8528
|
let names;
|
|
7438
8529
|
try {
|
|
7439
8530
|
names = readdirSync(root);
|
|
@@ -7442,7 +8533,7 @@ function sweepTransientSkillEntries(skillsRoot) {
|
|
|
7442
8533
|
}
|
|
7443
8534
|
for (const name2 of names) {
|
|
7444
8535
|
if (!isTransientSkillEntryName(name2)) continue;
|
|
7445
|
-
const full =
|
|
8536
|
+
const full = join15(root, name2);
|
|
7446
8537
|
try {
|
|
7447
8538
|
rmSync(full, { recursive: true, force: true, maxRetries: 2, retryDelay: 20 });
|
|
7448
8539
|
} catch {
|
|
@@ -7450,14 +8541,14 @@ function sweepTransientSkillEntries(skillsRoot) {
|
|
|
7450
8541
|
}
|
|
7451
8542
|
}
|
|
7452
8543
|
function renameAsideToTemp(from, kind) {
|
|
7453
|
-
const absolute =
|
|
8544
|
+
const absolute = resolve9(from);
|
|
7454
8545
|
const preferred = skillTransientWorkPath(kind, basename6(absolute));
|
|
7455
8546
|
try {
|
|
7456
|
-
|
|
8547
|
+
renameSync3(absolute, preferred);
|
|
7457
8548
|
return preferred;
|
|
7458
8549
|
} catch {
|
|
7459
8550
|
const sibling = `${absolute}.__ae_${kind}_${process.pid}_${Date.now()}`;
|
|
7460
|
-
|
|
8551
|
+
renameSync3(absolute, sibling);
|
|
7461
8552
|
return sibling;
|
|
7462
8553
|
}
|
|
7463
8554
|
}
|
|
@@ -7466,7 +8557,7 @@ function removeQuietly(path) {
|
|
|
7466
8557
|
const stat = lstatSync(path);
|
|
7467
8558
|
if (stat.isSymbolicLink()) {
|
|
7468
8559
|
try {
|
|
7469
|
-
|
|
8560
|
+
unlinkSync2(path);
|
|
7470
8561
|
} catch {
|
|
7471
8562
|
}
|
|
7472
8563
|
return;
|
|
@@ -7474,7 +8565,7 @@ function removeQuietly(path) {
|
|
|
7474
8565
|
} catch {
|
|
7475
8566
|
return;
|
|
7476
8567
|
}
|
|
7477
|
-
if (!
|
|
8568
|
+
if (!existsSync9(path)) return;
|
|
7478
8569
|
try {
|
|
7479
8570
|
rmSync(path, { recursive: true, force: true, maxRetries: 2, retryDelay: 20 });
|
|
7480
8571
|
} catch {
|
|
@@ -7483,27 +8574,27 @@ function removeQuietly(path) {
|
|
|
7483
8574
|
|
|
7484
8575
|
// src/host/instructions-skills/uninstall.ts
|
|
7485
8576
|
import { lstatSync as lstatSync3 } from "node:fs";
|
|
7486
|
-
import { basename as basename8, dirname as
|
|
8577
|
+
import { basename as basename8, dirname as dirname7, join as join18, resolve as resolve11 } from "node:path";
|
|
7487
8578
|
|
|
7488
8579
|
// src/host/instructions-skills/install-ledger.ts
|
|
7489
|
-
import { existsSync as
|
|
7490
|
-
import { dirname as
|
|
8580
|
+
import { existsSync as existsSync10, mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync4, writeFileSync as writeFileSync4 } from "node:fs";
|
|
8581
|
+
import { dirname as dirname6, join as join16 } from "node:path";
|
|
7491
8582
|
function ledgerPath(dataRoot) {
|
|
7492
|
-
return
|
|
8583
|
+
return join16(dataRoot, "skills-install", "registry.json");
|
|
7493
8584
|
}
|
|
7494
8585
|
function writeLedger(dataRoot, ledger) {
|
|
7495
8586
|
const path = ledgerPath(dataRoot);
|
|
7496
|
-
|
|
8587
|
+
mkdirSync5(dirname6(path), { recursive: true });
|
|
7497
8588
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
7498
|
-
|
|
8589
|
+
writeFileSync4(tmp, `${JSON.stringify(ledger, null, 2)}
|
|
7499
8590
|
`, "utf8");
|
|
7500
|
-
|
|
8591
|
+
renameSync4(tmp, path);
|
|
7501
8592
|
}
|
|
7502
8593
|
function readInstallLedger(dataRoot) {
|
|
7503
8594
|
const path = ledgerPath(dataRoot);
|
|
7504
|
-
if (!
|
|
8595
|
+
if (!existsSync10(path)) return {};
|
|
7505
8596
|
try {
|
|
7506
|
-
const raw =
|
|
8597
|
+
const raw = readFileSync3(path, "utf8").trim();
|
|
7507
8598
|
if (raw === "") return {};
|
|
7508
8599
|
return JSON.parse(raw);
|
|
7509
8600
|
} catch {
|
|
@@ -7525,15 +8616,15 @@ function removeInstallRecord(dataRoot, name2) {
|
|
|
7525
8616
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
7526
8617
|
import {
|
|
7527
8618
|
chmodSync,
|
|
7528
|
-
existsSync as
|
|
8619
|
+
existsSync as existsSync11,
|
|
7529
8620
|
lstatSync as lstatSync2,
|
|
7530
8621
|
readdirSync as readdirSync2,
|
|
7531
8622
|
readlinkSync,
|
|
7532
8623
|
rmSync as rmSync2,
|
|
7533
|
-
unlinkSync as
|
|
8624
|
+
unlinkSync as unlinkSync3
|
|
7534
8625
|
} from "node:fs";
|
|
7535
8626
|
import { homedir as homedir4 } from "node:os";
|
|
7536
|
-
import { basename as basename7, join as
|
|
8627
|
+
import { basename as basename7, join as join17, resolve as resolve10 } from "node:path";
|
|
7537
8628
|
|
|
7538
8629
|
// src/host/instructions-skills/fs-access.ts
|
|
7539
8630
|
var ACCESS_DENIED_RE = /eperm|eacces|eio|ebusy|access is denied|operation not permitted|file in use|still present|拒绝访问|¾Ü¾ø·ÃÎÊ/i;
|
|
@@ -7562,10 +8653,10 @@ function pathPresent(path) {
|
|
|
7562
8653
|
}
|
|
7563
8654
|
}
|
|
7564
8655
|
function isManagedSkillEntryPath(target, env = process.env) {
|
|
7565
|
-
const absolute =
|
|
8656
|
+
const absolute = resolve10(target);
|
|
7566
8657
|
const managedRoots = [
|
|
7567
|
-
|
|
7568
|
-
|
|
8658
|
+
join17(agentsHomeOf(env), "skills"),
|
|
8659
|
+
join17(dshHomeOf(env), "skills")
|
|
7569
8660
|
];
|
|
7570
8661
|
for (const root of managedRoots) {
|
|
7571
8662
|
if (samePath2(absolute, root) || isInsideOrSame(root, absolute)) return true;
|
|
@@ -7573,17 +8664,17 @@ function isManagedSkillEntryPath(target, env = process.env) {
|
|
|
7573
8664
|
return false;
|
|
7574
8665
|
}
|
|
7575
8666
|
function isProtectedExternalSkillPath(target, env = process.env) {
|
|
7576
|
-
const absolute =
|
|
8667
|
+
const absolute = resolve10(target);
|
|
7577
8668
|
if (isManagedSkillEntryPath(absolute, env)) return false;
|
|
7578
|
-
const home =
|
|
8669
|
+
const home = resolve10(homedir4());
|
|
7579
8670
|
const protectedRoots = [
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
8671
|
+
join17(home, ".skills-manager"),
|
|
8672
|
+
join17(home, ".cursor", "skills"),
|
|
8673
|
+
join17(home, ".cursor", "skills-cursor"),
|
|
8674
|
+
join17(home, ".codex", "skills"),
|
|
8675
|
+
join17(home, ".claude", "skills"),
|
|
8676
|
+
join17(home, ".codebuddy", "skills"),
|
|
8677
|
+
join17(home, ".workbuddy", "skills")
|
|
7587
8678
|
];
|
|
7588
8679
|
for (const root of protectedRoots) {
|
|
7589
8680
|
if (samePath2(absolute, root) || isInsideOrSame(root, absolute)) return true;
|
|
@@ -7607,12 +8698,12 @@ function isReparseOrSymlink(path) {
|
|
|
7607
8698
|
}
|
|
7608
8699
|
}
|
|
7609
8700
|
function effectivelyGone(target) {
|
|
7610
|
-
if (!pathPresent(target) && !
|
|
8701
|
+
if (!pathPresent(target) && !existsSync11(target)) return true;
|
|
7611
8702
|
try {
|
|
7612
8703
|
const stat = lstatSync2(target);
|
|
7613
8704
|
if (stat.isSymbolicLink()) return false;
|
|
7614
8705
|
if (!stat.isDirectory()) return false;
|
|
7615
|
-
if (
|
|
8706
|
+
if (existsSync11(join17(target, "SKILL.md"))) return false;
|
|
7616
8707
|
let names;
|
|
7617
8708
|
try {
|
|
7618
8709
|
names = readdirSync2(target);
|
|
@@ -7626,7 +8717,7 @@ function effectivelyGone(target) {
|
|
|
7626
8717
|
}
|
|
7627
8718
|
function unlinkMountOnly(absolute) {
|
|
7628
8719
|
try {
|
|
7629
|
-
|
|
8720
|
+
unlinkSync3(absolute);
|
|
7630
8721
|
} catch {
|
|
7631
8722
|
if (process.platform === "win32") {
|
|
7632
8723
|
try {
|
|
@@ -7642,7 +8733,7 @@ function unlinkMountOnly(absolute) {
|
|
|
7642
8733
|
return false;
|
|
7643
8734
|
}
|
|
7644
8735
|
}
|
|
7645
|
-
return !pathPresent(absolute) && !
|
|
8736
|
+
return !pathPresent(absolute) && !existsSync11(absolute);
|
|
7646
8737
|
}
|
|
7647
8738
|
function tryUnlinkReparseOrFile(absolute) {
|
|
7648
8739
|
let preferUnlink = false;
|
|
@@ -7658,11 +8749,11 @@ function tryUnlinkReparseOrFile(absolute) {
|
|
|
7658
8749
|
return unlinkMountOnly(absolute);
|
|
7659
8750
|
}
|
|
7660
8751
|
function removePathRobust(target) {
|
|
7661
|
-
const absolute =
|
|
8752
|
+
const absolute = resolve10(target);
|
|
7662
8753
|
if (isProtectedExternalSkillPath(absolute)) {
|
|
7663
8754
|
return;
|
|
7664
8755
|
}
|
|
7665
|
-
if (!pathPresent(absolute) && !
|
|
8756
|
+
if (!pathPresent(absolute) && !existsSync11(absolute)) return;
|
|
7666
8757
|
if (isReparseOrSymlink(absolute)) {
|
|
7667
8758
|
if (unlinkMountOnly(absolute)) return;
|
|
7668
8759
|
if (effectivelyGone(absolute)) return;
|
|
@@ -7680,7 +8771,7 @@ function removePathRobust(target) {
|
|
|
7680
8771
|
} catch (error) {
|
|
7681
8772
|
if (!isWindowsPathBusyError(error) && effectivelyGone(absolute)) return;
|
|
7682
8773
|
}
|
|
7683
|
-
if (!pathPresent(absolute) && !
|
|
8774
|
+
if (!pathPresent(absolute) && !existsSync11(absolute)) return;
|
|
7684
8775
|
try {
|
|
7685
8776
|
const aside = renameAsideToTemp(absolute, "removing");
|
|
7686
8777
|
removeQuietly(aside);
|
|
@@ -7700,18 +8791,18 @@ function removePathRobust(target) {
|
|
|
7700
8791
|
} catch {
|
|
7701
8792
|
}
|
|
7702
8793
|
}
|
|
7703
|
-
if (!pathPresent(absolute) && !
|
|
8794
|
+
if (!pathPresent(absolute) && !existsSync11(absolute)) return;
|
|
7704
8795
|
if (effectivelyGone(absolute)) return;
|
|
7705
8796
|
}
|
|
7706
|
-
if (effectivelyGone(absolute) || !pathPresent(absolute) && !
|
|
8797
|
+
if (effectivelyGone(absolute) || !pathPresent(absolute) && !existsSync11(absolute)) return;
|
|
7707
8798
|
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename7(absolute)));
|
|
7708
8799
|
}
|
|
7709
8800
|
|
|
7710
8801
|
// src/host/instructions-skills/uninstall.ts
|
|
7711
8802
|
function skillEntryPath(skillMdOrBundlePath) {
|
|
7712
|
-
const absolute =
|
|
8803
|
+
const absolute = resolve11(skillMdOrBundlePath);
|
|
7713
8804
|
const base = basename8(absolute);
|
|
7714
|
-
if (base.toLowerCase() === "skill.md") return
|
|
8805
|
+
if (base.toLowerCase() === "skill.md") return dirname7(absolute);
|
|
7715
8806
|
if (base.toLowerCase().endsWith(".md")) return absolute;
|
|
7716
8807
|
return absolute;
|
|
7717
8808
|
}
|
|
@@ -7726,11 +8817,11 @@ function pathPresent2(path) {
|
|
|
7726
8817
|
function managedSkillEntriesForName(root, name2) {
|
|
7727
8818
|
if (!isKebabCaseName(name2)) return [];
|
|
7728
8819
|
const out = [];
|
|
7729
|
-
const asDir =
|
|
7730
|
-
const asFile =
|
|
8820
|
+
const asDir = join18(root, name2);
|
|
8821
|
+
const asFile = join18(root, `${name2}.md`);
|
|
7731
8822
|
for (const entry of [asDir, asFile]) {
|
|
7732
8823
|
if (!pathPresent2(entry)) continue;
|
|
7733
|
-
if (!samePath2(
|
|
8824
|
+
if (!samePath2(dirname7(entry), root)) continue;
|
|
7734
8825
|
if (!isInsideOrSame(root, entry)) continue;
|
|
7735
8826
|
out.push(entry);
|
|
7736
8827
|
}
|
|
@@ -7740,11 +8831,11 @@ function resolveManagedSkillRemovalTarget(path, name2, managedRoots) {
|
|
|
7740
8831
|
if (!isKebabCaseName(name2)) return null;
|
|
7741
8832
|
const entry = skillEntryPath(path);
|
|
7742
8833
|
for (const root of managedRoots) {
|
|
7743
|
-
const asDir =
|
|
7744
|
-
const asFile =
|
|
8834
|
+
const asDir = join18(root, name2);
|
|
8835
|
+
const asFile = join18(root, `${name2}.md`);
|
|
7745
8836
|
if (samePath2(entry, asDir) || samePath2(entry, asFile)) {
|
|
7746
8837
|
if (!pathPresent2(entry)) return null;
|
|
7747
|
-
if (!samePath2(
|
|
8838
|
+
if (!samePath2(dirname7(entry), root)) return null;
|
|
7748
8839
|
if (!isInsideOrSame(root, entry)) return null;
|
|
7749
8840
|
return entry;
|
|
7750
8841
|
}
|
|
@@ -7761,15 +8852,15 @@ function purgeManagedSkillName(options) {
|
|
|
7761
8852
|
if (!isKebabCaseName(name2)) {
|
|
7762
8853
|
throw new AuxiliaryError("FILE_DENIED", `Invalid skill name: ${name2}`);
|
|
7763
8854
|
}
|
|
7764
|
-
const except = (options.exceptPaths ?? []).map((entry) =>
|
|
8855
|
+
const except = (options.exceptPaths ?? []).map((entry) => resolve11(entry));
|
|
7765
8856
|
const roots = skillRootsFor(options.cwd, options.projectRoot, options.env);
|
|
7766
8857
|
const purgeTargets = /* @__PURE__ */ new Set();
|
|
7767
8858
|
for (const extra of options.also ?? []) {
|
|
7768
|
-
purgeTargets.add(
|
|
8859
|
+
purgeTargets.add(resolve11(extra));
|
|
7769
8860
|
}
|
|
7770
8861
|
for (const root of roots) {
|
|
7771
8862
|
for (const entry of managedSkillEntriesForName(root, name2)) {
|
|
7772
|
-
purgeTargets.add(
|
|
8863
|
+
purgeTargets.add(resolve11(entry));
|
|
7773
8864
|
}
|
|
7774
8865
|
}
|
|
7775
8866
|
const removed = [];
|
|
@@ -7809,54 +8900,54 @@ function uninstallManagedSkill(options) {
|
|
|
7809
8900
|
|
|
7810
8901
|
// src/host/instructions-skills/discover.ts
|
|
7811
8902
|
function entryId(scope, path) {
|
|
7812
|
-
return `${scope}:${
|
|
8903
|
+
return `${scope}:${resolve12(path).toLowerCase()}`;
|
|
7813
8904
|
}
|
|
7814
8905
|
function pushUnique(out, seen, entry) {
|
|
7815
|
-
const key =
|
|
8906
|
+
const key = resolve12(entry.path).toLowerCase();
|
|
7816
8907
|
if (seen.has(key)) return;
|
|
7817
8908
|
seen.add(key);
|
|
7818
8909
|
out.push(entry);
|
|
7819
8910
|
}
|
|
7820
8911
|
function discoverInstructionFiles(options) {
|
|
7821
8912
|
const env = options.env ?? process.env;
|
|
7822
|
-
const cwd =
|
|
8913
|
+
const cwd = resolve12(options.cwd);
|
|
7823
8914
|
const projectRoot = findProjectRoot(cwd);
|
|
7824
8915
|
const seen = /* @__PURE__ */ new Set();
|
|
7825
8916
|
const instructions = [];
|
|
7826
|
-
const globalPath =
|
|
8917
|
+
const globalPath = join19(dshHomeOf(env), "AGENTS.md");
|
|
7827
8918
|
pushUnique(instructions, seen, {
|
|
7828
8919
|
id: entryId("global", globalPath),
|
|
7829
8920
|
scope: "global",
|
|
7830
8921
|
name: "AGENTS.md",
|
|
7831
8922
|
path: globalPath,
|
|
7832
|
-
exists:
|
|
8923
|
+
exists: existsSync12(globalPath),
|
|
7833
8924
|
bytes: fileBytes(globalPath),
|
|
7834
8925
|
createable: false
|
|
7835
8926
|
});
|
|
7836
|
-
const sharedPath =
|
|
8927
|
+
const sharedPath = join19(agentsHomeOf(env), "AGENTS.md");
|
|
7837
8928
|
pushUnique(instructions, seen, {
|
|
7838
8929
|
id: entryId("shared", sharedPath),
|
|
7839
8930
|
scope: "shared",
|
|
7840
8931
|
name: "AGENTS.md",
|
|
7841
8932
|
path: sharedPath,
|
|
7842
|
-
exists:
|
|
8933
|
+
exists: existsSync12(sharedPath),
|
|
7843
8934
|
bytes: fileBytes(sharedPath),
|
|
7844
8935
|
createable: false
|
|
7845
8936
|
});
|
|
7846
|
-
const rootAgents =
|
|
8937
|
+
const rootAgents = join19(projectRoot, "AGENTS.md");
|
|
7847
8938
|
pushUnique(instructions, seen, {
|
|
7848
8939
|
id: entryId("project", rootAgents),
|
|
7849
8940
|
scope: "project",
|
|
7850
8941
|
name: "AGENTS.md",
|
|
7851
8942
|
path: rootAgents,
|
|
7852
|
-
exists:
|
|
8943
|
+
exists: existsSync12(rootAgents),
|
|
7853
8944
|
bytes: fileBytes(rootAgents),
|
|
7854
|
-
createable: !
|
|
8945
|
+
createable: !existsSync12(rootAgents)
|
|
7855
8946
|
});
|
|
7856
8947
|
for (const dir of projectChainDirs(projectRoot, cwd)) {
|
|
7857
8948
|
for (const name2 of INSTRUCTION_CANDIDATES) {
|
|
7858
|
-
const path =
|
|
7859
|
-
if (!
|
|
8949
|
+
const path = join19(dir, name2);
|
|
8950
|
+
if (!existsSync12(path)) continue;
|
|
7860
8951
|
if (samePath2(path, rootAgents)) continue;
|
|
7861
8952
|
pushUnique(instructions, seen, {
|
|
7862
8953
|
id: entryId("project", path),
|
|
@@ -7873,7 +8964,7 @@ function discoverInstructionFiles(options) {
|
|
|
7873
8964
|
}
|
|
7874
8965
|
function descriptionFromSkillMd(path) {
|
|
7875
8966
|
try {
|
|
7876
|
-
const text3 =
|
|
8967
|
+
const text3 = readFileSync4(path, "utf8");
|
|
7877
8968
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
7878
8969
|
if (match === null) return "";
|
|
7879
8970
|
const block = match[1];
|
|
@@ -7900,14 +8991,14 @@ function discoverFilesystemSkills(options) {
|
|
|
7900
8991
|
}
|
|
7901
8992
|
for (const name2 of names) {
|
|
7902
8993
|
if (isTransientSkillEntryName(name2)) continue;
|
|
7903
|
-
const skillMd =
|
|
7904
|
-
if (!
|
|
8994
|
+
const skillMd = join19(root, name2, "SKILL.md");
|
|
8995
|
+
if (!existsSync12(skillMd)) continue;
|
|
7905
8996
|
if (byName.has(name2)) continue;
|
|
7906
8997
|
byName.set(name2, {
|
|
7907
|
-
id: `fs:${
|
|
8998
|
+
id: `fs:${resolve12(skillMd).toLowerCase()}`,
|
|
7908
8999
|
name: name2,
|
|
7909
9000
|
description: descriptionFromSkillMd(skillMd),
|
|
7910
|
-
path:
|
|
9001
|
+
path: resolve12(skillMd),
|
|
7911
9002
|
provider: dirnameLabel(root, options.projectRoot, env),
|
|
7912
9003
|
modelInvocable: null,
|
|
7913
9004
|
userInvocable: null,
|
|
@@ -7920,11 +9011,11 @@ function discoverFilesystemSkills(options) {
|
|
|
7920
9011
|
return [...byName.values()].sort((a, b) => a.name.localeCompare(b.name));
|
|
7921
9012
|
}
|
|
7922
9013
|
function dirnameLabel(root, projectRoot, env) {
|
|
7923
|
-
if (samePath2(root,
|
|
7924
|
-
if (samePath2(root,
|
|
7925
|
-
if (samePath2(root,
|
|
7926
|
-
if (samePath2(root,
|
|
7927
|
-
const parent = basename9(
|
|
9014
|
+
if (samePath2(root, join19(projectRoot, ".agents", "skills"))) return "project";
|
|
9015
|
+
if (samePath2(root, join19(projectRoot, ".dsh", "skills"))) return "project-dsh";
|
|
9016
|
+
if (samePath2(root, join19(agentsHomeOf(env), "skills"))) return "shared";
|
|
9017
|
+
if (samePath2(root, join19(dshHomeOf(env), "skills"))) return "dsh-home";
|
|
9018
|
+
const parent = basename9(dirname8(root)).toLowerCase();
|
|
7928
9019
|
const leaf = basename9(root).toLowerCase();
|
|
7929
9020
|
if (parent === ".cursor" && leaf === "skills") return "cursor";
|
|
7930
9021
|
if (parent === ".cursor" && leaf === "skills-cursor") return "cursor-builtin";
|
|
@@ -7943,7 +9034,7 @@ function normalizeRegistrySkills(raw) {
|
|
|
7943
9034
|
const name2 = typeof row.name === "string" ? row.name.trim() : "";
|
|
7944
9035
|
if (name2 === "" || seen.has(name2)) continue;
|
|
7945
9036
|
seen.add(name2);
|
|
7946
|
-
const path = typeof row.path === "string" && row.path.trim() !== "" ?
|
|
9037
|
+
const path = typeof row.path === "string" && row.path.trim() !== "" ? resolve12(row.path.trim()) : null;
|
|
7947
9038
|
out.push({
|
|
7948
9039
|
id: path !== null ? `reg:${path.toLowerCase()}` : `reg:${name2}`,
|
|
7949
9040
|
name: name2,
|
|
@@ -7960,24 +9051,24 @@ function normalizeRegistrySkills(raw) {
|
|
|
7960
9051
|
}
|
|
7961
9052
|
function coerceSkillDocumentPath(path, _name) {
|
|
7962
9053
|
if (path === null || path.trim() === "") return null;
|
|
7963
|
-
const absolute =
|
|
7964
|
-
if (
|
|
9054
|
+
const absolute = resolve12(path.trim());
|
|
9055
|
+
if (existsSync12(absolute)) {
|
|
7965
9056
|
try {
|
|
7966
|
-
if (
|
|
9057
|
+
if (statSync3(absolute).isFile()) return absolute;
|
|
7967
9058
|
} catch {
|
|
7968
9059
|
}
|
|
7969
|
-
const asFile =
|
|
7970
|
-
if (
|
|
9060
|
+
const asFile = join19(absolute, "SKILL.md");
|
|
9061
|
+
if (existsSync12(asFile)) return asFile;
|
|
7971
9062
|
}
|
|
7972
9063
|
const lower = absolute.toLowerCase();
|
|
7973
9064
|
if (lower.endsWith("skill.md") || lower.endsWith(".md")) return absolute;
|
|
7974
|
-
const nested =
|
|
7975
|
-
return
|
|
9065
|
+
const nested = join19(absolute, "SKILL.md");
|
|
9066
|
+
return existsSync12(nested) ? nested : absolute;
|
|
7976
9067
|
}
|
|
7977
9068
|
function resolveSkillPathFromRoots(name2, cwd, projectRoot, env) {
|
|
7978
9069
|
for (const root of previewSkillSearchRoots(cwd, projectRoot, env)) {
|
|
7979
|
-
const skillMd =
|
|
7980
|
-
if (
|
|
9070
|
+
const skillMd = join19(root, name2, "SKILL.md");
|
|
9071
|
+
if (existsSync12(skillMd)) return resolve12(skillMd);
|
|
7981
9072
|
}
|
|
7982
9073
|
return null;
|
|
7983
9074
|
}
|
|
@@ -8138,22 +9229,22 @@ function parseGitSkillSource(raw) {
|
|
|
8138
9229
|
|
|
8139
9230
|
// src/host/instructions-skills/install.ts
|
|
8140
9231
|
import { execFile as execFile3, spawn } from "node:child_process";
|
|
8141
|
-
import { existsSync as
|
|
9232
|
+
import { existsSync as existsSync14, mkdtempSync, realpathSync, rmSync as rmSync4 } from "node:fs";
|
|
8142
9233
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
8143
|
-
import { basename as basename11, dirname as
|
|
9234
|
+
import { basename as basename11, dirname as dirname10, join as join23, resolve as resolve14 } from "node:path";
|
|
8144
9235
|
import { promisify as promisify3 } from "node:util";
|
|
8145
9236
|
|
|
8146
9237
|
// src/host/instructions-skills/github-archive.ts
|
|
8147
9238
|
import { execFile as execFile2 } from "node:child_process";
|
|
8148
9239
|
import {
|
|
8149
9240
|
createWriteStream,
|
|
8150
|
-
mkdirSync as
|
|
9241
|
+
mkdirSync as mkdirSync6,
|
|
8151
9242
|
readdirSync as readdirSync4,
|
|
8152
|
-
renameSync as
|
|
9243
|
+
renameSync as renameSync5,
|
|
8153
9244
|
rmSync as rmSync3,
|
|
8154
|
-
statSync as
|
|
9245
|
+
statSync as statSync4
|
|
8155
9246
|
} from "node:fs";
|
|
8156
|
-
import { join as
|
|
9247
|
+
import { join as join20 } from "node:path";
|
|
8157
9248
|
import { Readable } from "node:stream";
|
|
8158
9249
|
import { pipeline } from "node:stream/promises";
|
|
8159
9250
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -8198,7 +9289,7 @@ async function downloadUrl(url, destFile, signal, onBytes) {
|
|
|
8198
9289
|
}
|
|
8199
9290
|
async function extractZip(zipPath, destDir, signal) {
|
|
8200
9291
|
signal.throwIfAborted();
|
|
8201
|
-
|
|
9292
|
+
mkdirSync6(destDir, { recursive: true });
|
|
8202
9293
|
try {
|
|
8203
9294
|
await execFileAsync2("tar", ["-xf", zipPath, "-C", destDir], {
|
|
8204
9295
|
windowsHide: true,
|
|
@@ -8217,9 +9308,9 @@ function unwrapArchiveRoot(extractDir) {
|
|
|
8217
9308
|
return extractDir;
|
|
8218
9309
|
}
|
|
8219
9310
|
if (entries.length !== 1) return extractDir;
|
|
8220
|
-
const only =
|
|
9311
|
+
const only = join20(extractDir, entries[0]);
|
|
8221
9312
|
try {
|
|
8222
|
-
if (
|
|
9313
|
+
if (statSync4(only).isDirectory()) return only;
|
|
8223
9314
|
} catch {
|
|
8224
9315
|
return extractDir;
|
|
8225
9316
|
}
|
|
@@ -8256,10 +9347,10 @@ function archiveCandidates(owner, repo, defaultBranch) {
|
|
|
8256
9347
|
}
|
|
8257
9348
|
async function fetchGithubRepoArchive(options) {
|
|
8258
9349
|
const { owner, repo, workDir, signal, onDownloadProgress, onStage } = options;
|
|
8259
|
-
|
|
8260
|
-
const zipPath =
|
|
8261
|
-
const extractDir =
|
|
8262
|
-
|
|
9350
|
+
mkdirSync6(workDir, { recursive: true });
|
|
9351
|
+
const zipPath = join20(workDir, "repo.zip");
|
|
9352
|
+
const extractDir = join20(workDir, "extract");
|
|
9353
|
+
mkdirSync6(extractDir, { recursive: true });
|
|
8263
9354
|
const defaultBranch = await resolveDefaultBranch(owner, repo, signal);
|
|
8264
9355
|
const candidates = archiveCandidates(owner, repo, defaultBranch);
|
|
8265
9356
|
const errors = [];
|
|
@@ -8270,7 +9361,7 @@ async function fetchGithubRepoArchive(options) {
|
|
|
8270
9361
|
try {
|
|
8271
9362
|
rmSync3(zipPath, { force: true });
|
|
8272
9363
|
rmSync3(extractDir, { recursive: true, force: true });
|
|
8273
|
-
|
|
9364
|
+
mkdirSync6(extractDir, { recursive: true });
|
|
8274
9365
|
const detail = index === 0 ? `${owner}/${repo}` : `${owner}/${repo} \xB7 retry ${index + 1}/${candidates.length}`;
|
|
8275
9366
|
if (!downloadStarted) {
|
|
8276
9367
|
onStage?.("downloading", detail);
|
|
@@ -8282,9 +9373,9 @@ async function fetchGithubRepoArchive(options) {
|
|
|
8282
9373
|
onStage?.("extracting", `${owner}/${repo}`);
|
|
8283
9374
|
await extractZip(zipPath, extractDir, signal);
|
|
8284
9375
|
const root = unwrapArchiveRoot(extractDir);
|
|
8285
|
-
const repoDir =
|
|
9376
|
+
const repoDir = join20(workDir, "repo");
|
|
8286
9377
|
rmSync3(repoDir, { recursive: true, force: true });
|
|
8287
|
-
|
|
9378
|
+
renameSync5(root, repoDir);
|
|
8288
9379
|
try {
|
|
8289
9380
|
rmSync3(zipPath, { force: true });
|
|
8290
9381
|
rmSync3(extractDir, { recursive: true, force: true });
|
|
@@ -8312,18 +9403,18 @@ async function fetchGithubRepoArchive(options) {
|
|
|
8312
9403
|
// src/host/instructions-skills/install-fs.ts
|
|
8313
9404
|
import {
|
|
8314
9405
|
cpSync,
|
|
8315
|
-
existsSync as
|
|
9406
|
+
existsSync as existsSync13,
|
|
8316
9407
|
lstatSync as lstatSync4,
|
|
8317
|
-
mkdirSync as
|
|
9408
|
+
mkdirSync as mkdirSync7,
|
|
8318
9409
|
readdirSync as readdirSync5,
|
|
8319
|
-
readFileSync as
|
|
8320
|
-
renameSync as
|
|
9410
|
+
readFileSync as readFileSync5,
|
|
9411
|
+
renameSync as renameSync6,
|
|
8321
9412
|
symlinkSync
|
|
8322
9413
|
} from "node:fs";
|
|
8323
|
-
import { basename as basename10, dirname as
|
|
9414
|
+
import { basename as basename10, dirname as dirname9, join as join21, resolve as resolve13 } from "node:path";
|
|
8324
9415
|
function frontmatterBlock(path) {
|
|
8325
9416
|
try {
|
|
8326
|
-
const text3 =
|
|
9417
|
+
const text3 = readFileSync5(path, "utf8");
|
|
8327
9418
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
8328
9419
|
return match?.[1] ?? null;
|
|
8329
9420
|
} catch {
|
|
@@ -8340,13 +9431,13 @@ function nameFromSkillPath(path, fallback) {
|
|
|
8340
9431
|
return fallback;
|
|
8341
9432
|
}
|
|
8342
9433
|
function directoryBundleName(dir, folderName) {
|
|
8343
|
-
return nameFromSkillPath(
|
|
9434
|
+
return nameFromSkillPath(join21(dir, "SKILL.md"), folderName);
|
|
8344
9435
|
}
|
|
8345
9436
|
function findSkillBundles(root) {
|
|
8346
|
-
const absolute =
|
|
8347
|
-
if (!
|
|
8348
|
-
const rootSkill =
|
|
8349
|
-
if (
|
|
9437
|
+
const absolute = resolve13(root);
|
|
9438
|
+
if (!existsSync13(absolute)) return [];
|
|
9439
|
+
const rootSkill = join21(absolute, "SKILL.md");
|
|
9440
|
+
if (existsSync13(rootSkill)) {
|
|
8350
9441
|
const folderName = basename10(absolute);
|
|
8351
9442
|
const name2 = directoryBundleName(absolute, folderName);
|
|
8352
9443
|
if (isKebabCaseName(name2)) {
|
|
@@ -8362,8 +9453,8 @@ function findSkillBundles(root) {
|
|
|
8362
9453
|
}
|
|
8363
9454
|
for (const entry of entries) {
|
|
8364
9455
|
if (isTransientSkillEntryName(entry)) continue;
|
|
8365
|
-
const full =
|
|
8366
|
-
if (
|
|
9456
|
+
const full = join21(absolute, entry);
|
|
9457
|
+
if (existsSync13(join21(full, "SKILL.md"))) {
|
|
8367
9458
|
const name2 = directoryBundleName(full, entry);
|
|
8368
9459
|
if (!isKebabCaseName(name2)) continue;
|
|
8369
9460
|
out.push({ name: name2, sourcePath: full, kind: "directory" });
|
|
@@ -8384,12 +9475,12 @@ function findSkillBundles(root) {
|
|
|
8384
9475
|
return out.sort((a, b) => a.name.localeCompare(b.name));
|
|
8385
9476
|
}
|
|
8386
9477
|
function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
8387
|
-
const base = subpath === null || subpath === "" ?
|
|
8388
|
-
if (!
|
|
9478
|
+
const base = subpath === null || subpath === "" ? resolve13(cloneRoot) : resolve13(cloneRoot, subpath);
|
|
9479
|
+
if (!existsSync13(base)) {
|
|
8389
9480
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Path not found in repository: ${subpath ?? "."}`);
|
|
8390
9481
|
}
|
|
8391
|
-
if (base.toLowerCase().endsWith("skill.md") &&
|
|
8392
|
-
const dir =
|
|
9482
|
+
if (base.toLowerCase().endsWith("skill.md") && existsSync13(base)) {
|
|
9483
|
+
const dir = dirname9(base);
|
|
8393
9484
|
const name2 = directoryBundleName(dir, basename10(dir));
|
|
8394
9485
|
if (!isKebabCaseName(name2)) {
|
|
8395
9486
|
throw new AuxiliaryError("FILE_DENIED", `Skill directory name must be kebab-case: ${name2}`);
|
|
@@ -8398,8 +9489,8 @@ function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
|
8398
9489
|
}
|
|
8399
9490
|
const direct = findSkillBundles(base);
|
|
8400
9491
|
if (direct.length > 0) return direct;
|
|
8401
|
-
for (const rel of ["skills",
|
|
8402
|
-
const nested =
|
|
9492
|
+
for (const rel of ["skills", join21(".agents", "skills"), join21(".dsh", "skills")]) {
|
|
9493
|
+
const nested = join21(base, rel);
|
|
8403
9494
|
const found = findSkillBundles(nested);
|
|
8404
9495
|
if (found.length > 0) return found;
|
|
8405
9496
|
}
|
|
@@ -8408,13 +9499,13 @@ function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
|
8408
9499
|
function installTargetDir(target, projectRoot, agentsHome, dshHome2) {
|
|
8409
9500
|
switch (target) {
|
|
8410
9501
|
case "user":
|
|
8411
|
-
return
|
|
9502
|
+
return join21(resolve13(agentsHome), "skills");
|
|
8412
9503
|
case "user-dsh":
|
|
8413
|
-
return
|
|
9504
|
+
return join21(resolve13(dshHome2), "skills");
|
|
8414
9505
|
case "project":
|
|
8415
|
-
return
|
|
9506
|
+
return join21(resolve13(projectRoot), ".agents", "skills");
|
|
8416
9507
|
case "project-dsh":
|
|
8417
|
-
return
|
|
9508
|
+
return join21(resolve13(projectRoot), ".dsh", "skills");
|
|
8418
9509
|
default: {
|
|
8419
9510
|
const _exhaustive = target;
|
|
8420
9511
|
return _exhaustive;
|
|
@@ -8422,7 +9513,7 @@ function installTargetDir(target, projectRoot, agentsHome, dshHome2) {
|
|
|
8422
9513
|
}
|
|
8423
9514
|
}
|
|
8424
9515
|
function destinationForBundle(targetDir, bundle) {
|
|
8425
|
-
return bundle.kind === "directory" ?
|
|
9516
|
+
return bundle.kind === "directory" ? join21(targetDir, bundle.name) : join21(targetDir, `${bundle.name}.md`);
|
|
8426
9517
|
}
|
|
8427
9518
|
function removeDestination(dest) {
|
|
8428
9519
|
removePathRobust(dest);
|
|
@@ -8440,13 +9531,13 @@ function isStaleSkillDestination(dest, kind) {
|
|
|
8440
9531
|
if (kind === "file") {
|
|
8441
9532
|
try {
|
|
8442
9533
|
const stat = lstatSync4(dest);
|
|
8443
|
-
if (stat.isSymbolicLink()) return !
|
|
9534
|
+
if (stat.isSymbolicLink()) return !existsSync13(dest);
|
|
8444
9535
|
return !stat.isFile();
|
|
8445
9536
|
} catch {
|
|
8446
9537
|
return true;
|
|
8447
9538
|
}
|
|
8448
9539
|
}
|
|
8449
|
-
return !
|
|
9540
|
+
return !existsSync13(join21(dest, "SKILL.md"));
|
|
8450
9541
|
}
|
|
8451
9542
|
function copySkillTree(source, dest) {
|
|
8452
9543
|
try {
|
|
@@ -8463,7 +9554,7 @@ function copySkillTree(source, dest) {
|
|
|
8463
9554
|
}
|
|
8464
9555
|
}
|
|
8465
9556
|
function copySkillTreeAtomic(source, dest, kind) {
|
|
8466
|
-
|
|
9557
|
+
mkdirSync7(dirname9(dest), { recursive: true });
|
|
8467
9558
|
if (kind === "file") {
|
|
8468
9559
|
if (destinationPresent(dest)) removeDestination(dest);
|
|
8469
9560
|
copySkillTree(source, dest);
|
|
@@ -8477,7 +9568,7 @@ function copySkillTreeAtomic(source, dest, kind) {
|
|
|
8477
9568
|
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename10(dest)));
|
|
8478
9569
|
}
|
|
8479
9570
|
try {
|
|
8480
|
-
|
|
9571
|
+
renameSync6(staging, dest);
|
|
8481
9572
|
} catch (error) {
|
|
8482
9573
|
if (isWindowsPathBusyError(error)) {
|
|
8483
9574
|
throw new AuxiliaryError("FILE_EDIT_FAILED", busyPathHint(basename10(dest)));
|
|
@@ -8491,7 +9582,7 @@ function copySkillTreeAtomic(source, dest, kind) {
|
|
|
8491
9582
|
}
|
|
8492
9583
|
}
|
|
8493
9584
|
function linkOrCopy(source, dest, mode, kind) {
|
|
8494
|
-
|
|
9585
|
+
mkdirSync7(dirname9(dest), { recursive: true });
|
|
8495
9586
|
if (mode === "copy") {
|
|
8496
9587
|
copySkillTreeAtomic(source, dest, kind);
|
|
8497
9588
|
return "copy";
|
|
@@ -8499,7 +9590,7 @@ function linkOrCopy(source, dest, mode, kind) {
|
|
|
8499
9590
|
try {
|
|
8500
9591
|
if (process.platform === "win32") {
|
|
8501
9592
|
const stat = lstatSync4(source);
|
|
8502
|
-
if (stat.isDirectory() || stat.isSymbolicLink() &&
|
|
9593
|
+
if (stat.isDirectory() || stat.isSymbolicLink() && existsSync13(join21(source, "SKILL.md"))) {
|
|
8503
9594
|
symlinkSync(source, dest, "junction");
|
|
8504
9595
|
return "link";
|
|
8505
9596
|
}
|
|
@@ -8529,13 +9620,13 @@ function installBundle(options) {
|
|
|
8529
9620
|
|
|
8530
9621
|
// src/host/instructions-skills/content-revision.ts
|
|
8531
9622
|
import { createHash as createHash7 } from "node:crypto";
|
|
8532
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
8533
|
-
import { join as
|
|
9623
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync6 } from "node:fs";
|
|
9624
|
+
import { join as join22, relative as relative3 } from "node:path";
|
|
8534
9625
|
function listRelativeFiles(dir, root) {
|
|
8535
9626
|
const entries = [];
|
|
8536
9627
|
for (const entry of readdirSync6(dir, { withFileTypes: true })) {
|
|
8537
9628
|
if (entry.name.startsWith(".")) continue;
|
|
8538
|
-
const abs =
|
|
9629
|
+
const abs = join22(dir, entry.name);
|
|
8539
9630
|
if (entry.isDirectory()) {
|
|
8540
9631
|
entries.push(...listRelativeFiles(abs, root));
|
|
8541
9632
|
} else if (entry.isFile()) {
|
|
@@ -8548,7 +9639,7 @@ function contentRevisionOfDir(dir) {
|
|
|
8548
9639
|
const paths = listRelativeFiles(dir, dir).sort();
|
|
8549
9640
|
const aggregate = createHash7("sha256");
|
|
8550
9641
|
for (const relPath of paths) {
|
|
8551
|
-
const contents =
|
|
9642
|
+
const contents = readFileSync6(join22(dir, relPath));
|
|
8552
9643
|
const fileDigest = createHash7("sha256").update(`${relPath}\0`).update(contents).digest();
|
|
8553
9644
|
aggregate.update(fileDigest);
|
|
8554
9645
|
}
|
|
@@ -8657,7 +9748,7 @@ function tempWorkDir(prefix) {
|
|
|
8657
9748
|
base = realpathSync(base);
|
|
8658
9749
|
} catch {
|
|
8659
9750
|
}
|
|
8660
|
-
return mkdtempSync(
|
|
9751
|
+
return mkdtempSync(join23(base, prefix));
|
|
8661
9752
|
}
|
|
8662
9753
|
function execDetail(error) {
|
|
8663
9754
|
if (!(error instanceof Error)) return String(error);
|
|
@@ -8759,7 +9850,7 @@ async function materializeSkillGitTreeFromSource(source, workDir, signal, progre
|
|
|
8759
9850
|
return { rootDir, parsed };
|
|
8760
9851
|
}
|
|
8761
9852
|
async function materializeRepo(parsed, workDir, signal, progressSessionId) {
|
|
8762
|
-
const cloneDir =
|
|
9853
|
+
const cloneDir = join23(workDir, "repo");
|
|
8763
9854
|
const archiveErrors = [];
|
|
8764
9855
|
const sessionId = progressSessionId?.trim() ?? "";
|
|
8765
9856
|
if (parsed.github !== null) {
|
|
@@ -8900,14 +9991,14 @@ async function installSkillsFromGit(options) {
|
|
|
8900
9991
|
// src/host/instructions-skills/update-check.ts
|
|
8901
9992
|
import { mkdtempSync as mkdtempSync2, realpathSync as realpathSync2, rmSync as rmSync5 } from "node:fs";
|
|
8902
9993
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
8903
|
-
import { join as
|
|
9994
|
+
import { join as join24 } from "node:path";
|
|
8904
9995
|
function tempWorkDir2(prefix) {
|
|
8905
9996
|
let base = tmpdir4();
|
|
8906
9997
|
try {
|
|
8907
9998
|
base = realpathSync2(base);
|
|
8908
9999
|
} catch {
|
|
8909
10000
|
}
|
|
8910
|
-
return mkdtempSync2(
|
|
10001
|
+
return mkdtempSync2(join24(base, prefix));
|
|
8911
10002
|
}
|
|
8912
10003
|
function revisionPathForBundle(bundle) {
|
|
8913
10004
|
return bundle.kind === "directory" ? bundle.sourcePath : bundle.sourcePath;
|
|
@@ -8966,9 +10057,9 @@ async function checkGithubSkillUpdate(record2, options) {
|
|
|
8966
10057
|
|
|
8967
10058
|
// src/host/instructions-skills/zip-install.ts
|
|
8968
10059
|
import { execFile as execFile4 } from "node:child_process";
|
|
8969
|
-
import { existsSync as
|
|
10060
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync8, mkdtempSync as mkdtempSync3, realpathSync as realpathSync3, rmSync as rmSync6 } from "node:fs";
|
|
8970
10061
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
8971
|
-
import { basename as basename12, join as
|
|
10062
|
+
import { basename as basename12, join as join25, resolve as resolve15 } from "node:path";
|
|
8972
10063
|
import { promisify as promisify4 } from "node:util";
|
|
8973
10064
|
var execFileAsync4 = promisify4(execFile4);
|
|
8974
10065
|
function tempWorkDir3(prefix) {
|
|
@@ -8977,11 +10068,11 @@ function tempWorkDir3(prefix) {
|
|
|
8977
10068
|
base = realpathSync3(base);
|
|
8978
10069
|
} catch {
|
|
8979
10070
|
}
|
|
8980
|
-
return mkdtempSync3(
|
|
10071
|
+
return mkdtempSync3(join25(base, prefix));
|
|
8981
10072
|
}
|
|
8982
10073
|
async function extractZipArchive(zipPath, destDir, signal) {
|
|
8983
10074
|
signal.throwIfAborted();
|
|
8984
|
-
|
|
10075
|
+
mkdirSync8(destDir, { recursive: true });
|
|
8985
10076
|
try {
|
|
8986
10077
|
await execFileAsync4("tar", ["-xf", zipPath, "-C", destDir], {
|
|
8987
10078
|
windowsHide: true,
|
|
@@ -8994,15 +10085,15 @@ async function extractZipArchive(zipPath, destDir, signal) {
|
|
|
8994
10085
|
signal.throwIfAborted();
|
|
8995
10086
|
}
|
|
8996
10087
|
async function installSkillsFromZipFile(options) {
|
|
8997
|
-
const zipPath =
|
|
8998
|
-
if (!
|
|
10088
|
+
const zipPath = resolve15(options.zipPath);
|
|
10089
|
+
if (!existsSync15(zipPath)) {
|
|
8999
10090
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Zip not found: ${zipPath}`);
|
|
9000
10091
|
}
|
|
9001
10092
|
if (!zipPath.toLowerCase().endsWith(".zip")) {
|
|
9002
10093
|
throw new AuxiliaryError("FILE_DENIED", `Expected a .zip archive: ${basename12(zipPath)}`);
|
|
9003
10094
|
}
|
|
9004
10095
|
const workDir = tempWorkDir3("ae-skill-zip-");
|
|
9005
|
-
const extractDir =
|
|
10096
|
+
const extractDir = join25(workDir, "extract");
|
|
9006
10097
|
try {
|
|
9007
10098
|
await extractZipArchive(zipPath, extractDir, options.signal);
|
|
9008
10099
|
const root = unwrapArchiveRoot(extractDir);
|
|
@@ -9067,11 +10158,11 @@ async function installSkillsFromZipFile(options) {
|
|
|
9067
10158
|
// src/host/instructions-skills/io.ts
|
|
9068
10159
|
function sessionCwd3(session) {
|
|
9069
10160
|
const header = session?.header;
|
|
9070
|
-
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return
|
|
10161
|
+
if (typeof header?.cwd === "string" && header.cwd.trim() !== "") return resolve16(header.cwd);
|
|
9071
10162
|
try {
|
|
9072
10163
|
const requested = session?.requestHeader?.();
|
|
9073
10164
|
if (typeof requested?.cwd === "string" && requested.cwd.trim() !== "") {
|
|
9074
|
-
return
|
|
10165
|
+
return resolve16(requested.cwd);
|
|
9075
10166
|
}
|
|
9076
10167
|
} catch {
|
|
9077
10168
|
}
|
|
@@ -9165,12 +10256,12 @@ async function enrichSkillsFromLedger(skills, options) {
|
|
|
9165
10256
|
}
|
|
9166
10257
|
function inferSkillInstallTarget(name2, cwd, projectRoot, env = process.env) {
|
|
9167
10258
|
const roots = skillRootsFor(cwd, projectRoot, env);
|
|
9168
|
-
const projectAgents =
|
|
9169
|
-
const projectDsh =
|
|
9170
|
-
const userAgents =
|
|
9171
|
-
const userDsh =
|
|
10259
|
+
const projectAgents = join26(resolve16(projectRoot), ".agents", "skills");
|
|
10260
|
+
const projectDsh = join26(resolve16(projectRoot), ".dsh", "skills");
|
|
10261
|
+
const userAgents = join26(agentsHomeOf(env), "skills");
|
|
10262
|
+
const userDsh = join26(dshHomeOf(env), "skills");
|
|
9172
10263
|
for (const root of roots) {
|
|
9173
|
-
const present =
|
|
10264
|
+
const present = existsSync16(join26(root, name2, "SKILL.md")) || existsSync16(join26(root, `${name2}.md`));
|
|
9174
10265
|
if (!present) continue;
|
|
9175
10266
|
if (samePath2(root, projectAgents)) return "project";
|
|
9176
10267
|
if (samePath2(root, projectDsh)) return "project-dsh";
|
|
@@ -9178,7 +10269,7 @@ function inferSkillInstallTarget(name2, cwd, projectRoot, env = process.env) {
|
|
|
9178
10269
|
if (samePath2(root, userDsh)) return "user-dsh";
|
|
9179
10270
|
const normalized = root.toLowerCase().split(/[/\\]/).join(sep7);
|
|
9180
10271
|
const dshMarker = `${sep7}.dsh${sep7}skills`;
|
|
9181
|
-
const underProject = isInsideOrSame(
|
|
10272
|
+
const underProject = isInsideOrSame(resolve16(projectRoot), root);
|
|
9182
10273
|
if (normalized.includes(dshMarker) || normalized.endsWith(`${sep7}.dsh${sep7}skills`)) {
|
|
9183
10274
|
return underProject ? "project-dsh" : "user-dsh";
|
|
9184
10275
|
}
|
|
@@ -9391,8 +10482,8 @@ async function updateSkillFromGitNow(options) {
|
|
|
9391
10482
|
}
|
|
9392
10483
|
function skillDocumentAbsolutePath(path) {
|
|
9393
10484
|
const trimmed = path.replace(/[/\\]+$/, "");
|
|
9394
|
-
if (/\.md$/i.test(trimmed)) return
|
|
9395
|
-
return
|
|
10485
|
+
if (/\.md$/i.test(trimmed)) return resolve16(trimmed);
|
|
10486
|
+
return resolve16(trimmed, "SKILL.md");
|
|
9396
10487
|
}
|
|
9397
10488
|
async function readSkillDocumentNow(options) {
|
|
9398
10489
|
options.signal.throwIfAborted();
|
|
@@ -9408,11 +10499,11 @@ async function readSkillDocumentNow(options) {
|
|
|
9408
10499
|
throw new AuxiliaryError("FILE_DENIED", "Only SKILL.md may be previewed");
|
|
9409
10500
|
}
|
|
9410
10501
|
options.signal.throwIfAborted();
|
|
9411
|
-
if (!
|
|
10502
|
+
if (!existsSync16(absolutePath2)) {
|
|
9412
10503
|
throw new AuxiliaryError("FILE_NOT_FOUND", "Skill document not found");
|
|
9413
10504
|
}
|
|
9414
10505
|
try {
|
|
9415
|
-
const stat =
|
|
10506
|
+
const stat = statSync5(absolutePath2);
|
|
9416
10507
|
if (!stat.isFile()) {
|
|
9417
10508
|
throw new AuxiliaryError("FILE_NOT_FOUND", "Skill document not found");
|
|
9418
10509
|
}
|
|
@@ -9426,7 +10517,7 @@ async function readSkillDocumentNow(options) {
|
|
|
9426
10517
|
options.signal.throwIfAborted();
|
|
9427
10518
|
let text3;
|
|
9428
10519
|
try {
|
|
9429
|
-
text3 =
|
|
10520
|
+
text3 = readFileSync7(absolutePath2, "utf8");
|
|
9430
10521
|
} catch {
|
|
9431
10522
|
throw new AuxiliaryError("FILE_NOT_FOUND", "Skill document not found");
|
|
9432
10523
|
}
|
|
@@ -9443,7 +10534,7 @@ async function readSkillDocumentNow(options) {
|
|
|
9443
10534
|
}
|
|
9444
10535
|
|
|
9445
10536
|
// src/host/mcp-connectors/io.ts
|
|
9446
|
-
import { existsSync as
|
|
10537
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
9447
10538
|
|
|
9448
10539
|
// src/host/mcp-connectors/validate.ts
|
|
9449
10540
|
var MCP_SERVER_NAME_PATTERN = /^[A-Za-z0-9_-]{1,32}$/;
|
|
@@ -9565,22 +10656,22 @@ function parseMcpJsonText(jsonText) {
|
|
|
9565
10656
|
}
|
|
9566
10657
|
|
|
9567
10658
|
// src/host/mcp-connectors/install-git.ts
|
|
9568
|
-
import { existsSync as
|
|
9569
|
-
import { join as
|
|
10659
|
+
import { existsSync as existsSync17, mkdirSync as mkdirSync9, readFileSync as readFileSync8, renameSync as renameSync7, rmSync as rmSync7 } from "node:fs";
|
|
10660
|
+
import { join as join28 } from "node:path";
|
|
9570
10661
|
|
|
9571
10662
|
// src/host/mcp-connectors/paths.ts
|
|
9572
|
-
import { join as
|
|
10663
|
+
import { join as join27 } from "node:path";
|
|
9573
10664
|
function mcpConnectorsRoot(pluginDataPackageRoot) {
|
|
9574
|
-
return
|
|
10665
|
+
return join27(pluginDataPackageRoot, "mcp-connectors");
|
|
9575
10666
|
}
|
|
9576
10667
|
function mcpConnectorsLedgerPath(root) {
|
|
9577
|
-
return
|
|
10668
|
+
return join27(root, "mcp-connectors.json");
|
|
9578
10669
|
}
|
|
9579
10670
|
function mcpServersRoot(root) {
|
|
9580
|
-
return
|
|
10671
|
+
return join27(root, "mcp-servers");
|
|
9581
10672
|
}
|
|
9582
10673
|
function mcpServerInstallDir(root, id) {
|
|
9583
|
-
return
|
|
10674
|
+
return join27(mcpServersRoot(root), id);
|
|
9584
10675
|
}
|
|
9585
10676
|
|
|
9586
10677
|
// src/host/mcp-connectors/install-git.ts
|
|
@@ -9597,8 +10688,8 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
9597
10688
|
cwd: installDir
|
|
9598
10689
|
};
|
|
9599
10690
|
}
|
|
9600
|
-
const pkgPath =
|
|
9601
|
-
if (!
|
|
10691
|
+
const pkgPath = join28(installDir, "package.json");
|
|
10692
|
+
if (!existsSync17(pkgPath)) {
|
|
9602
10693
|
return {
|
|
9603
10694
|
transport: "stdio",
|
|
9604
10695
|
command: "npx",
|
|
@@ -9608,14 +10699,14 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
9608
10699
|
};
|
|
9609
10700
|
}
|
|
9610
10701
|
try {
|
|
9611
|
-
const pkg = JSON.parse(
|
|
10702
|
+
const pkg = JSON.parse(readFileSync8(pkgPath, "utf8"));
|
|
9612
10703
|
if (isRecord4(pkg)) {
|
|
9613
10704
|
const bin = pkg.bin;
|
|
9614
10705
|
if (typeof bin === "string" && bin.trim() !== "") {
|
|
9615
10706
|
return {
|
|
9616
10707
|
transport: "stdio",
|
|
9617
10708
|
command: process.execPath,
|
|
9618
|
-
args: [
|
|
10709
|
+
args: [join28(installDir, bin)],
|
|
9619
10710
|
env: {},
|
|
9620
10711
|
cwd: installDir
|
|
9621
10712
|
};
|
|
@@ -9628,7 +10719,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
9628
10719
|
return {
|
|
9629
10720
|
transport: "stdio",
|
|
9630
10721
|
command: process.execPath,
|
|
9631
|
-
args: [
|
|
10722
|
+
args: [join28(installDir, first)],
|
|
9632
10723
|
env: {},
|
|
9633
10724
|
cwd: installDir
|
|
9634
10725
|
};
|
|
@@ -9638,7 +10729,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
9638
10729
|
return {
|
|
9639
10730
|
transport: "stdio",
|
|
9640
10731
|
command: process.execPath,
|
|
9641
|
-
args: [
|
|
10732
|
+
args: [join28(installDir, pkg.main)],
|
|
9642
10733
|
env: {},
|
|
9643
10734
|
cwd: installDir
|
|
9644
10735
|
};
|
|
@@ -9657,17 +10748,17 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
9657
10748
|
async function installMcpServerFromGit(options) {
|
|
9658
10749
|
const parsed = parseGitSkillSource(options.source);
|
|
9659
10750
|
const installDir = mcpServerInstallDir(options.rootDir, options.id);
|
|
9660
|
-
if (
|
|
10751
|
+
if (existsSync17(installDir)) {
|
|
9661
10752
|
if (!options.force) {
|
|
9662
10753
|
throw new AuxiliaryError("FILE_EDIT_FAILED", `MCP install dir already exists: ${installDir}`);
|
|
9663
10754
|
}
|
|
9664
10755
|
removePathRobust(installDir);
|
|
9665
10756
|
}
|
|
9666
|
-
|
|
10757
|
+
mkdirSync9(join28(options.rootDir, "mcp-servers"), { recursive: true });
|
|
9667
10758
|
const staging = `${installDir}.staging.${process.pid}`;
|
|
9668
10759
|
try {
|
|
9669
|
-
if (
|
|
9670
|
-
|
|
10760
|
+
if (existsSync17(staging)) removePathRobust(staging);
|
|
10761
|
+
mkdirSync9(staging, { recursive: true });
|
|
9671
10762
|
if (parsed.github === null) {
|
|
9672
10763
|
throw new AuxiliaryError(
|
|
9673
10764
|
"FILE_EDIT_FAILED",
|
|
@@ -9683,20 +10774,20 @@ async function installMcpServerFromGit(options) {
|
|
|
9683
10774
|
options.signal.throwIfAborted();
|
|
9684
10775
|
let contentRoot = repoDir;
|
|
9685
10776
|
if (parsed.subpath !== null) {
|
|
9686
|
-
const nested =
|
|
9687
|
-
if (!
|
|
10777
|
+
const nested = join28(repoDir, parsed.subpath);
|
|
10778
|
+
if (!existsSync17(nested)) {
|
|
9688
10779
|
throw new AuxiliaryError("FILE_EDIT_FAILED", `Subpath not found in repo: ${parsed.subpath}`);
|
|
9689
10780
|
}
|
|
9690
10781
|
contentRoot = nested;
|
|
9691
10782
|
}
|
|
9692
|
-
|
|
10783
|
+
mkdirSync9(join28(options.rootDir, "mcp-servers"), { recursive: true });
|
|
9693
10784
|
if (contentRoot !== repoDir) {
|
|
9694
10785
|
const nestedStaging = `${installDir}.nested.${process.pid}`;
|
|
9695
|
-
|
|
10786
|
+
renameSync7(contentRoot, nestedStaging);
|
|
9696
10787
|
removePathRobust(staging);
|
|
9697
|
-
|
|
10788
|
+
renameSync7(nestedStaging, installDir);
|
|
9698
10789
|
} else {
|
|
9699
|
-
|
|
10790
|
+
renameSync7(repoDir, installDir);
|
|
9700
10791
|
try {
|
|
9701
10792
|
removePathRobust(staging);
|
|
9702
10793
|
} catch {
|
|
@@ -9704,11 +10795,11 @@ async function installMcpServerFromGit(options) {
|
|
|
9704
10795
|
}
|
|
9705
10796
|
} catch (error) {
|
|
9706
10797
|
try {
|
|
9707
|
-
if (
|
|
10798
|
+
if (existsSync17(staging)) rmSync7(staging, { recursive: true, force: true });
|
|
9708
10799
|
} catch {
|
|
9709
10800
|
}
|
|
9710
10801
|
try {
|
|
9711
|
-
if (
|
|
10802
|
+
if (existsSync17(installDir)) removePathRobust(installDir);
|
|
9712
10803
|
} catch {
|
|
9713
10804
|
}
|
|
9714
10805
|
if (error instanceof AuxiliaryError) throw error;
|
|
@@ -9806,7 +10897,7 @@ async function uninstallMcpConnectorNow(host, request) {
|
|
|
9806
10897
|
}
|
|
9807
10898
|
const next = doc.connectors.filter((entry) => entry.id !== request.id);
|
|
9808
10899
|
const installDir = mcpServerInstallDir(host.store.rootDir, request.id);
|
|
9809
|
-
if (
|
|
10900
|
+
if (existsSync18(installDir)) {
|
|
9810
10901
|
try {
|
|
9811
10902
|
removePathRobust(installDir);
|
|
9812
10903
|
} catch (error) {
|
|
@@ -9938,8 +11029,8 @@ function listMcpConnectorToolsNow(host, request) {
|
|
|
9938
11029
|
}
|
|
9939
11030
|
|
|
9940
11031
|
// src/host/mcp-connectors/store.ts
|
|
9941
|
-
import { mkdirSync as
|
|
9942
|
-
import { dirname as
|
|
11032
|
+
import { mkdirSync as mkdirSync10, readFileSync as readFileSync9, renameSync as renameSync8, writeFileSync as writeFileSync5 } from "node:fs";
|
|
11033
|
+
import { dirname as dirname11 } from "node:path";
|
|
9943
11034
|
|
|
9944
11035
|
// src/host/mcp-connectors/types.ts
|
|
9945
11036
|
var MCP_CONNECTORS_VERSION = 1;
|
|
@@ -10021,13 +11112,13 @@ function parseDoc2(raw) {
|
|
|
10021
11112
|
}
|
|
10022
11113
|
}
|
|
10023
11114
|
function createMcpConnectorsStore(rootDir) {
|
|
10024
|
-
|
|
11115
|
+
mkdirSync10(rootDir, { recursive: true });
|
|
10025
11116
|
const file = mcpConnectorsLedgerPath(rootDir);
|
|
10026
11117
|
return {
|
|
10027
11118
|
rootDir,
|
|
10028
11119
|
load() {
|
|
10029
11120
|
try {
|
|
10030
|
-
return parseDoc2(
|
|
11121
|
+
return parseDoc2(readFileSync9(file, "utf8"));
|
|
10031
11122
|
} catch (error) {
|
|
10032
11123
|
const code = error !== null && typeof error === "object" ? String(Reflect.get(error, "code") ?? "") : "";
|
|
10033
11124
|
if (code !== "ENOENT") {
|
|
@@ -10040,11 +11131,11 @@ function createMcpConnectorsStore(rootDir) {
|
|
|
10040
11131
|
version: MCP_CONNECTORS_VERSION,
|
|
10041
11132
|
connectors: [...connectors]
|
|
10042
11133
|
};
|
|
10043
|
-
|
|
11134
|
+
mkdirSync10(dirname11(file), { recursive: true });
|
|
10044
11135
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
10045
|
-
|
|
11136
|
+
writeFileSync5(tmp, `${JSON.stringify(doc, null, 2)}
|
|
10046
11137
|
`, "utf8");
|
|
10047
|
-
|
|
11138
|
+
renameSync8(tmp, file);
|
|
10048
11139
|
return doc;
|
|
10049
11140
|
}
|
|
10050
11141
|
};
|
|
@@ -10726,7 +11817,7 @@ var SoftPauseGate = class {
|
|
|
10726
11817
|
this.clear(sessionId);
|
|
10727
11818
|
return;
|
|
10728
11819
|
}
|
|
10729
|
-
await new Promise((
|
|
11820
|
+
await new Promise((resolve17) => {
|
|
10730
11821
|
let settled = false;
|
|
10731
11822
|
const settle = () => {
|
|
10732
11823
|
if (settled) return;
|
|
@@ -10737,7 +11828,7 @@ var SoftPauseGate = class {
|
|
|
10737
11828
|
bucket2.delete(waiter);
|
|
10738
11829
|
if (bucket2.size === 0) this.waiters.delete(sessionId);
|
|
10739
11830
|
}
|
|
10740
|
-
|
|
11831
|
+
resolve17();
|
|
10741
11832
|
};
|
|
10742
11833
|
const onAbort = () => {
|
|
10743
11834
|
this.engaged.delete(sessionId);
|
|
@@ -11949,9 +13040,9 @@ function mergeUsageCalls(stored, history) {
|
|
|
11949
13040
|
}
|
|
11950
13041
|
|
|
11951
13042
|
// src/host/usage/ledger.ts
|
|
11952
|
-
import { randomUUID as
|
|
13043
|
+
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
11953
13044
|
import { chmod as chmod4, mkdir as mkdir5, readFile as readFile5, rename as rename4, unlink as unlink5, writeFile as writeFile4 } from "node:fs/promises";
|
|
11954
|
-
import { basename as basename14, join as
|
|
13045
|
+
import { basename as basename14, join as join29 } from "node:path";
|
|
11955
13046
|
import { z as z3 } from "zod";
|
|
11956
13047
|
var callSchema = z3.object({
|
|
11957
13048
|
at: z3.number().int().nonnegative(),
|
|
@@ -11981,7 +13072,7 @@ async function removeIfPresent5(path) {
|
|
|
11981
13072
|
}
|
|
11982
13073
|
}
|
|
11983
13074
|
async function writeAtomic4(path, value) {
|
|
11984
|
-
const temporary =
|
|
13075
|
+
const temporary = join29(join29(path, ".."), `.${basename14(path)}.${randomUUID7()}.tmp`);
|
|
11985
13076
|
try {
|
|
11986
13077
|
await writeFile4(temporary, JSON.stringify(value), { encoding: "utf8", mode: 384, flag: "wx" });
|
|
11987
13078
|
await rename4(temporary, path);
|
|
@@ -11995,7 +13086,7 @@ var UsageLedger = class {
|
|
|
11995
13086
|
}) {
|
|
11996
13087
|
this.root = root;
|
|
11997
13088
|
this.warn = warn;
|
|
11998
|
-
this.file =
|
|
13089
|
+
this.file = join29(root, "ledger.json");
|
|
11999
13090
|
}
|
|
12000
13091
|
root;
|
|
12001
13092
|
warn;
|
|
@@ -12280,6 +13371,156 @@ var deleteSessionResultSchema = z4.strictObject({
|
|
|
12280
13371
|
});
|
|
12281
13372
|
var deleteSessionRequestCodec = codec("dsh-agent-enhancer#DeleteSessionRequest", deleteSessionRequestSchema);
|
|
12282
13373
|
var deleteSessionResultCodec = codec("dsh-agent-enhancer#DeleteSessionResult", deleteSessionResultSchema);
|
|
13374
|
+
var webChatTurnSchema = z4.strictObject({
|
|
13375
|
+
role: z4.enum(["user", "assistant"]),
|
|
13376
|
+
text: z4.string()
|
|
13377
|
+
});
|
|
13378
|
+
var webChatTranscriptSchema = z4.strictObject({
|
|
13379
|
+
title: z4.string(),
|
|
13380
|
+
partial: z4.boolean(),
|
|
13381
|
+
turns: z4.array(webChatTurnSchema).min(1),
|
|
13382
|
+
source: z4.strictObject({
|
|
13383
|
+
kind: z4.enum(["rendered-capture", "official-export", "share-link", "account-history"]),
|
|
13384
|
+
url: z4.string().optional(),
|
|
13385
|
+
chatSessionId: z4.string().optional(),
|
|
13386
|
+
capturedAt: z4.string(),
|
|
13387
|
+
filename: z4.string().optional()
|
|
13388
|
+
})
|
|
13389
|
+
});
|
|
13390
|
+
var listWebChatWorkspacesRequestSchema = z4.strictObject({});
|
|
13391
|
+
var listWebChatWorkspacesResultSchema = z4.strictObject({
|
|
13392
|
+
items: z4.array(z4.strictObject({
|
|
13393
|
+
id: z4.string(),
|
|
13394
|
+
title: z4.string(),
|
|
13395
|
+
cwd: z4.string()
|
|
13396
|
+
}))
|
|
13397
|
+
});
|
|
13398
|
+
var createWebChatWorkspaceRequestSchema = z4.strictObject({});
|
|
13399
|
+
var createWebChatWorkspaceResultSchema = z4.strictObject({
|
|
13400
|
+
cancelled: z4.boolean(),
|
|
13401
|
+
workspace: z4.strictObject({
|
|
13402
|
+
id: z4.string(),
|
|
13403
|
+
title: z4.string(),
|
|
13404
|
+
cwd: z4.string()
|
|
13405
|
+
}).nullable()
|
|
13406
|
+
});
|
|
13407
|
+
var importWebChatHistoryRequestSchema = z4.strictObject({
|
|
13408
|
+
workspaceId: z4.string().min(1),
|
|
13409
|
+
transcript: webChatTranscriptSchema
|
|
13410
|
+
});
|
|
13411
|
+
var importWebChatHistoryResultSchema = z4.strictObject({
|
|
13412
|
+
sessionId: sessionIdSchema3
|
|
13413
|
+
});
|
|
13414
|
+
var parseWebChatExportRequestSchema = z4.strictObject({
|
|
13415
|
+
filename: z4.string().min(1),
|
|
13416
|
+
bytesBase64: z4.string().min(1)
|
|
13417
|
+
});
|
|
13418
|
+
var webChatExportCatalogItemSchema = z4.strictObject({
|
|
13419
|
+
id: z4.string().min(1),
|
|
13420
|
+
title: z4.string(),
|
|
13421
|
+
turnCount: z4.number().int().nonnegative(),
|
|
13422
|
+
preview: z4.string(),
|
|
13423
|
+
transcript: webChatTranscriptSchema.optional()
|
|
13424
|
+
});
|
|
13425
|
+
var parseWebChatExportResultSchema = z4.strictObject({
|
|
13426
|
+
items: z4.array(webChatExportCatalogItemSchema).min(1),
|
|
13427
|
+
truncated: z4.boolean()
|
|
13428
|
+
});
|
|
13429
|
+
var resolveWebChatShareLinkRequestSchema = z4.strictObject({
|
|
13430
|
+
shareUrl: z4.string().min(1),
|
|
13431
|
+
/** Optional guest-fetched JSON string; when set, Host skips network fetch. */
|
|
13432
|
+
payloadJson: z4.string().optional()
|
|
13433
|
+
});
|
|
13434
|
+
var resolveWebChatShareLinkResultSchema = z4.strictObject({
|
|
13435
|
+
transcript: webChatTranscriptSchema
|
|
13436
|
+
});
|
|
13437
|
+
var listWebChatWorkspacesRequestCodec = codec(
|
|
13438
|
+
"dsh-agent-enhancer#ListWebChatWorkspacesRequest",
|
|
13439
|
+
listWebChatWorkspacesRequestSchema
|
|
13440
|
+
);
|
|
13441
|
+
var listWebChatWorkspacesResultCodec = codec(
|
|
13442
|
+
"dsh-agent-enhancer#ListWebChatWorkspacesResult",
|
|
13443
|
+
listWebChatWorkspacesResultSchema
|
|
13444
|
+
);
|
|
13445
|
+
var createWebChatWorkspaceRequestCodec = codec(
|
|
13446
|
+
"dsh-agent-enhancer#CreateWebChatWorkspaceRequest",
|
|
13447
|
+
createWebChatWorkspaceRequestSchema
|
|
13448
|
+
);
|
|
13449
|
+
var createWebChatWorkspaceResultCodec = codec(
|
|
13450
|
+
"dsh-agent-enhancer#CreateWebChatWorkspaceResult",
|
|
13451
|
+
createWebChatWorkspaceResultSchema
|
|
13452
|
+
);
|
|
13453
|
+
var importWebChatHistoryRequestCodec = codec(
|
|
13454
|
+
"dsh-agent-enhancer#ImportWebChatHistoryRequest",
|
|
13455
|
+
importWebChatHistoryRequestSchema
|
|
13456
|
+
);
|
|
13457
|
+
var importWebChatHistoryResultCodec = codec(
|
|
13458
|
+
"dsh-agent-enhancer#ImportWebChatHistoryResult",
|
|
13459
|
+
importWebChatHistoryResultSchema
|
|
13460
|
+
);
|
|
13461
|
+
var parseWebChatExportRequestCodec = codec(
|
|
13462
|
+
"dsh-agent-enhancer#ParseWebChatExportRequest",
|
|
13463
|
+
parseWebChatExportRequestSchema
|
|
13464
|
+
);
|
|
13465
|
+
var parseWebChatExportResultCodec = codec(
|
|
13466
|
+
"dsh-agent-enhancer#ParseWebChatExportResult",
|
|
13467
|
+
parseWebChatExportResultSchema
|
|
13468
|
+
);
|
|
13469
|
+
var resolveWebChatShareLinkRequestCodec = codec(
|
|
13470
|
+
"dsh-agent-enhancer#ResolveWebChatShareLinkRequest",
|
|
13471
|
+
resolveWebChatShareLinkRequestSchema
|
|
13472
|
+
);
|
|
13473
|
+
var resolveWebChatShareLinkResultCodec = codec(
|
|
13474
|
+
"dsh-agent-enhancer#ResolveWebChatShareLinkResult",
|
|
13475
|
+
resolveWebChatShareLinkResultSchema
|
|
13476
|
+
);
|
|
13477
|
+
var webChatLoginSnapshotSchema = z4.strictObject({
|
|
13478
|
+
version: z4.literal(1),
|
|
13479
|
+
origin: z4.string(),
|
|
13480
|
+
localStorage: z4.record(z4.string(), z4.string()),
|
|
13481
|
+
cookie: z4.string(),
|
|
13482
|
+
savedAt: z4.string()
|
|
13483
|
+
});
|
|
13484
|
+
var loadWebChatLoginSnapshotRequestSchema = z4.strictObject({});
|
|
13485
|
+
var loadWebChatLoginSnapshotResultSchema = z4.strictObject({
|
|
13486
|
+
snapshot: webChatLoginSnapshotSchema.nullable()
|
|
13487
|
+
});
|
|
13488
|
+
var saveWebChatLoginSnapshotRequestSchema = z4.strictObject({
|
|
13489
|
+
localStorage: z4.record(z4.string(), z4.string()),
|
|
13490
|
+
cookie: z4.string(),
|
|
13491
|
+
savedAt: z4.string()
|
|
13492
|
+
});
|
|
13493
|
+
var saveWebChatLoginSnapshotResultSchema = z4.strictObject({
|
|
13494
|
+
ok: z4.literal(true)
|
|
13495
|
+
});
|
|
13496
|
+
var clearWebChatLoginSnapshotRequestSchema = z4.strictObject({});
|
|
13497
|
+
var clearWebChatLoginSnapshotResultSchema = z4.strictObject({
|
|
13498
|
+
cleared: z4.boolean()
|
|
13499
|
+
});
|
|
13500
|
+
var loadWebChatLoginSnapshotRequestCodec = codec(
|
|
13501
|
+
"dsh-agent-enhancer#LoadWebChatLoginSnapshotRequest",
|
|
13502
|
+
loadWebChatLoginSnapshotRequestSchema
|
|
13503
|
+
);
|
|
13504
|
+
var loadWebChatLoginSnapshotResultCodec = codec(
|
|
13505
|
+
"dsh-agent-enhancer#LoadWebChatLoginSnapshotResult",
|
|
13506
|
+
loadWebChatLoginSnapshotResultSchema
|
|
13507
|
+
);
|
|
13508
|
+
var saveWebChatLoginSnapshotRequestCodec = codec(
|
|
13509
|
+
"dsh-agent-enhancer#SaveWebChatLoginSnapshotRequest",
|
|
13510
|
+
saveWebChatLoginSnapshotRequestSchema
|
|
13511
|
+
);
|
|
13512
|
+
var saveWebChatLoginSnapshotResultCodec = codec(
|
|
13513
|
+
"dsh-agent-enhancer#SaveWebChatLoginSnapshotResult",
|
|
13514
|
+
saveWebChatLoginSnapshotResultSchema
|
|
13515
|
+
);
|
|
13516
|
+
var clearWebChatLoginSnapshotRequestCodec = codec(
|
|
13517
|
+
"dsh-agent-enhancer#ClearWebChatLoginSnapshotRequest",
|
|
13518
|
+
clearWebChatLoginSnapshotRequestSchema
|
|
13519
|
+
);
|
|
13520
|
+
var clearWebChatLoginSnapshotResultCodec = codec(
|
|
13521
|
+
"dsh-agent-enhancer#ClearWebChatLoginSnapshotResult",
|
|
13522
|
+
clearWebChatLoginSnapshotResultSchema
|
|
13523
|
+
);
|
|
12283
13524
|
var readWorkspaceFileRequestSchema = z4.strictObject({
|
|
12284
13525
|
sessionId: sessionIdSchema3,
|
|
12285
13526
|
path: z4.string().min(1)
|
|
@@ -13611,6 +14852,110 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
13611
14852
|
}],
|
|
13612
14853
|
cancellation: { parameter: "signal" },
|
|
13613
14854
|
result: listMcpConnectorToolsResultCodec
|
|
14855
|
+
},
|
|
14856
|
+
"agentEnhancer/listWebChatWorkspaces": {
|
|
14857
|
+
service: "agentEnhancer",
|
|
14858
|
+
implementation: "listWebChatWorkspaces",
|
|
14859
|
+
invocation: { kind: "direct" },
|
|
14860
|
+
parameters: [{
|
|
14861
|
+
name: "request",
|
|
14862
|
+
source: "json",
|
|
14863
|
+
codec: listWebChatWorkspacesRequestCodec,
|
|
14864
|
+
strictCodec: listWebChatWorkspacesRequestCodec
|
|
14865
|
+
}],
|
|
14866
|
+
cancellation: { parameter: "signal" },
|
|
14867
|
+
result: listWebChatWorkspacesResultCodec
|
|
14868
|
+
},
|
|
14869
|
+
"agentEnhancer/createWebChatWorkspace": {
|
|
14870
|
+
service: "agentEnhancer",
|
|
14871
|
+
implementation: "createWebChatWorkspace",
|
|
14872
|
+
invocation: { kind: "direct" },
|
|
14873
|
+
parameters: [{
|
|
14874
|
+
name: "request",
|
|
14875
|
+
source: "json",
|
|
14876
|
+
codec: createWebChatWorkspaceRequestCodec,
|
|
14877
|
+
strictCodec: createWebChatWorkspaceRequestCodec
|
|
14878
|
+
}],
|
|
14879
|
+
cancellation: { parameter: "signal" },
|
|
14880
|
+
result: createWebChatWorkspaceResultCodec
|
|
14881
|
+
},
|
|
14882
|
+
"agentEnhancer/importWebChatHistory": {
|
|
14883
|
+
service: "agentEnhancer",
|
|
14884
|
+
implementation: "importWebChatHistory",
|
|
14885
|
+
invocation: { kind: "direct" },
|
|
14886
|
+
parameters: [{
|
|
14887
|
+
name: "request",
|
|
14888
|
+
source: "json",
|
|
14889
|
+
codec: importWebChatHistoryRequestCodec,
|
|
14890
|
+
strictCodec: importWebChatHistoryRequestCodec
|
|
14891
|
+
}],
|
|
14892
|
+
cancellation: { parameter: "signal" },
|
|
14893
|
+
result: importWebChatHistoryResultCodec
|
|
14894
|
+
},
|
|
14895
|
+
"agentEnhancer/parseWebChatExport": {
|
|
14896
|
+
service: "agentEnhancer",
|
|
14897
|
+
implementation: "parseWebChatExport",
|
|
14898
|
+
invocation: { kind: "direct" },
|
|
14899
|
+
parameters: [{
|
|
14900
|
+
name: "request",
|
|
14901
|
+
source: "json",
|
|
14902
|
+
codec: parseWebChatExportRequestCodec,
|
|
14903
|
+
strictCodec: parseWebChatExportRequestCodec
|
|
14904
|
+
}],
|
|
14905
|
+
cancellation: { parameter: "signal" },
|
|
14906
|
+
result: parseWebChatExportResultCodec
|
|
14907
|
+
},
|
|
14908
|
+
"agentEnhancer/resolveWebChatShareLink": {
|
|
14909
|
+
service: "agentEnhancer",
|
|
14910
|
+
implementation: "resolveWebChatShareLink",
|
|
14911
|
+
invocation: { kind: "direct" },
|
|
14912
|
+
parameters: [{
|
|
14913
|
+
name: "request",
|
|
14914
|
+
source: "json",
|
|
14915
|
+
codec: resolveWebChatShareLinkRequestCodec,
|
|
14916
|
+
strictCodec: resolveWebChatShareLinkRequestCodec
|
|
14917
|
+
}],
|
|
14918
|
+
cancellation: { parameter: "signal" },
|
|
14919
|
+
result: resolveWebChatShareLinkResultCodec
|
|
14920
|
+
},
|
|
14921
|
+
"agentEnhancer/loadWebChatLoginSnapshot": {
|
|
14922
|
+
service: "agentEnhancer",
|
|
14923
|
+
implementation: "loadWebChatLoginSnapshot",
|
|
14924
|
+
invocation: { kind: "direct" },
|
|
14925
|
+
parameters: [{
|
|
14926
|
+
name: "request",
|
|
14927
|
+
source: "json",
|
|
14928
|
+
codec: loadWebChatLoginSnapshotRequestCodec,
|
|
14929
|
+
strictCodec: loadWebChatLoginSnapshotRequestCodec
|
|
14930
|
+
}],
|
|
14931
|
+
cancellation: { parameter: "signal" },
|
|
14932
|
+
result: loadWebChatLoginSnapshotResultCodec
|
|
14933
|
+
},
|
|
14934
|
+
"agentEnhancer/saveWebChatLoginSnapshot": {
|
|
14935
|
+
service: "agentEnhancer",
|
|
14936
|
+
implementation: "saveWebChatLoginSnapshot",
|
|
14937
|
+
invocation: { kind: "direct" },
|
|
14938
|
+
parameters: [{
|
|
14939
|
+
name: "request",
|
|
14940
|
+
source: "json",
|
|
14941
|
+
codec: saveWebChatLoginSnapshotRequestCodec,
|
|
14942
|
+
strictCodec: saveWebChatLoginSnapshotRequestCodec
|
|
14943
|
+
}],
|
|
14944
|
+
cancellation: { parameter: "signal" },
|
|
14945
|
+
result: saveWebChatLoginSnapshotResultCodec
|
|
14946
|
+
},
|
|
14947
|
+
"agentEnhancer/clearWebChatLoginSnapshot": {
|
|
14948
|
+
service: "agentEnhancer",
|
|
14949
|
+
implementation: "clearWebChatLoginSnapshot",
|
|
14950
|
+
invocation: { kind: "direct" },
|
|
14951
|
+
parameters: [{
|
|
14952
|
+
name: "request",
|
|
14953
|
+
source: "json",
|
|
14954
|
+
codec: clearWebChatLoginSnapshotRequestCodec,
|
|
14955
|
+
strictCodec: clearWebChatLoginSnapshotRequestCodec
|
|
14956
|
+
}],
|
|
14957
|
+
cancellation: { parameter: "signal" },
|
|
14958
|
+
result: clearWebChatLoginSnapshotResultCodec
|
|
13614
14959
|
}
|
|
13615
14960
|
}
|
|
13616
14961
|
}, z4);
|
|
@@ -13896,7 +15241,7 @@ async function showOsNotificationNow(input) {
|
|
|
13896
15241
|
|
|
13897
15242
|
// src/host/update/check.ts
|
|
13898
15243
|
import { homedir as homedir5 } from "node:os";
|
|
13899
|
-
import { join as
|
|
15244
|
+
import { join as join31 } from "node:path";
|
|
13900
15245
|
|
|
13901
15246
|
// src/host/update/cli.ts
|
|
13902
15247
|
import { spawn as nodeSpawn } from "node:child_process";
|
|
@@ -13923,14 +15268,14 @@ function resolveCanAutoApply(input) {
|
|
|
13923
15268
|
return input.installKind === "npm" && input.dshAvailable;
|
|
13924
15269
|
}
|
|
13925
15270
|
function waitForExit(child, timeoutMs) {
|
|
13926
|
-
return new Promise((
|
|
15271
|
+
return new Promise((resolve17) => {
|
|
13927
15272
|
let settled = false;
|
|
13928
15273
|
const chunks = [];
|
|
13929
15274
|
const finish = (ok, detail) => {
|
|
13930
15275
|
if (settled) return;
|
|
13931
15276
|
settled = true;
|
|
13932
15277
|
clearTimeout(timer);
|
|
13933
|
-
|
|
15278
|
+
resolve17({ ok, detail });
|
|
13934
15279
|
};
|
|
13935
15280
|
const timer = setTimeout(() => {
|
|
13936
15281
|
child.kill();
|
|
@@ -13967,9 +15312,9 @@ async function runPluginAdd(latest, spawnFn = defaultSpawn) {
|
|
|
13967
15312
|
|
|
13968
15313
|
// src/host/update/install-kind.ts
|
|
13969
15314
|
import { lstatSync as lstatSync5 } from "node:fs";
|
|
13970
|
-
import { join as
|
|
15315
|
+
import { join as join30 } from "node:path";
|
|
13971
15316
|
function detectInstallKind(profileDir) {
|
|
13972
|
-
const pkgPath =
|
|
15317
|
+
const pkgPath = join30(profileDir, "node_modules", PACKAGE_NAME);
|
|
13973
15318
|
try {
|
|
13974
15319
|
const stat = lstatSync5(pkgPath);
|
|
13975
15320
|
if (stat.isSymbolicLink()) return "link";
|
|
@@ -14100,8 +15445,8 @@ function isNewerVersion(latest, current) {
|
|
|
14100
15445
|
|
|
14101
15446
|
// src/host/update/check.ts
|
|
14102
15447
|
function resolveDesktopProfileDir(env = process.env, home = homedir5()) {
|
|
14103
|
-
const dshHome2 = env.DSH_HOME ??
|
|
14104
|
-
return
|
|
15448
|
+
const dshHome2 = env.DSH_HOME ?? join31(home, ".dsh");
|
|
15449
|
+
return join31(dshHome2, "profiles", "desktop");
|
|
14105
15450
|
}
|
|
14106
15451
|
async function checkPluginUpdate(deps) {
|
|
14107
15452
|
const latest = await deps.fetchLatest();
|
|
@@ -14193,6 +15538,8 @@ var Config = z5.object({
|
|
|
14193
15538
|
/** High-risk; default off. */
|
|
14194
15539
|
browserAgentEnabled: z5.boolean().default(false).volatile(),
|
|
14195
15540
|
browserAgentBrowser: z5.string().default("auto").volatile(),
|
|
15541
|
+
/** Default off; embeds official web chat + import to work. */
|
|
15542
|
+
webChatBridgeEnabled: z5.boolean().default(true).volatile(),
|
|
14196
15543
|
instructionsSkillsEnabled: z5.boolean().default(true).volatile(),
|
|
14197
15544
|
mcpConnectorsEnabled: z5.boolean().default(true).volatile(),
|
|
14198
15545
|
// Empty provider/model = follow the current Desktop session model.
|
|
@@ -14239,12 +15586,12 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14239
15586
|
};
|
|
14240
15587
|
}
|
|
14241
15588
|
}, sessionCleanup = new SessionCleanupRegistry(), extraFolders = createExtraFoldersStore(
|
|
14242
|
-
|
|
15589
|
+
join32(homedir6(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME, "extra-folders")
|
|
14243
15590
|
), softPause = new SoftPauseGate(), softPauseEnabled = () => true, installLedgerRoot = void 0, mcpHost = null, browserAgent = null, browserAgentSettings = () => ({
|
|
14244
15591
|
enabled: false,
|
|
14245
15592
|
browser: "auto"
|
|
14246
15593
|
}), setBrowserAgentBrowser = () => void 0, browserAgentProfileDir = defaultBrowserAgentProfileDir(
|
|
14247
|
-
|
|
15594
|
+
join32(homedir6(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME)
|
|
14248
15595
|
)) {
|
|
14249
15596
|
super(ctx, "agentEnhancer");
|
|
14250
15597
|
this.models = models;
|
|
@@ -14318,7 +15665,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14318
15665
|
}
|
|
14319
15666
|
requireMcpHost() {
|
|
14320
15667
|
if (this.mcpHost === null) {
|
|
14321
|
-
throw new
|
|
15668
|
+
throw new RemoteError2("agent-enhancer/failed", "MCP connectors host is unavailable", {
|
|
14322
15669
|
code: "FILE_EDIT_FAILED"
|
|
14323
15670
|
});
|
|
14324
15671
|
}
|
|
@@ -14336,7 +15683,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14336
15683
|
}
|
|
14337
15684
|
assertOwner() {
|
|
14338
15685
|
if (this.ctx.invocation?.peer.principal.kind !== "owner") {
|
|
14339
|
-
throw new
|
|
15686
|
+
throw new RemoteError2("agent-enhancer/forbidden", "Only the desktop owner may use Agent Enhance", {});
|
|
14340
15687
|
}
|
|
14341
15688
|
}
|
|
14342
15689
|
async call(payload, signal) {
|
|
@@ -14346,7 +15693,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14346
15693
|
} catch (error) {
|
|
14347
15694
|
if (signal.aborted) throw error;
|
|
14348
15695
|
const code = error instanceof AuxiliaryError ? error.code : "MODEL_FAILED";
|
|
14349
|
-
throw new
|
|
15696
|
+
throw new RemoteError2("agent-enhancer/failed", "Agent Enhance request failed", { code });
|
|
14350
15697
|
}
|
|
14351
15698
|
}
|
|
14352
15699
|
/** Same Desktop catalog the official model selector uses (`llm` registry). */
|
|
@@ -14354,7 +15701,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14354
15701
|
try {
|
|
14355
15702
|
return await buildAuxiliaryModelCatalog(this.ctx);
|
|
14356
15703
|
} catch {
|
|
14357
|
-
throw new
|
|
15704
|
+
throw new RemoteError2("agent-enhancer/failed", "Agent Enhance catalog failed", {
|
|
14358
15705
|
code: "MODEL_UNAVAILABLE"
|
|
14359
15706
|
});
|
|
14360
15707
|
}
|
|
@@ -14364,7 +15711,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14364
15711
|
signal.throwIfAborted();
|
|
14365
15712
|
const agent = this.ctx.agents.get(request.sessionId);
|
|
14366
15713
|
if (agent === void 0) {
|
|
14367
|
-
throw new
|
|
15714
|
+
throw new RemoteError2("agent-enhancer/failed", "Session not available for context inspect", {
|
|
14368
15715
|
code: "SESSION_CHANGED"
|
|
14369
15716
|
});
|
|
14370
15717
|
}
|
|
@@ -14378,7 +15725,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14378
15725
|
};
|
|
14379
15726
|
} catch (error) {
|
|
14380
15727
|
if (signal.aborted) throw error;
|
|
14381
|
-
throw new
|
|
15728
|
+
throw new RemoteError2("agent-enhancer/failed", "Context inspect failed", { code: "MODEL_FAILED" });
|
|
14382
15729
|
}
|
|
14383
15730
|
}
|
|
14384
15731
|
/** Permanently delete one sidebar session (official logs + plugin persistence). */
|
|
@@ -14396,17 +15743,118 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14396
15743
|
if (signal.aborted) throw error;
|
|
14397
15744
|
if (error instanceof SessionDeleteError) {
|
|
14398
15745
|
this.ctx.logger.warn(`agent-enhancer deleteSession failed: ${error.code} ${error.message}`);
|
|
14399
|
-
throw new
|
|
15746
|
+
throw new RemoteError2("agent-enhancer/failed", error.message, {
|
|
14400
15747
|
code: error.code === "BUSY" ? "SESSION_BUSY" : "SESSION_DELETE_FAILED"
|
|
14401
15748
|
});
|
|
14402
15749
|
}
|
|
14403
15750
|
const detail = error instanceof Error ? error.message : String(error);
|
|
14404
15751
|
this.ctx.logger.warn(`agent-enhancer deleteSession failed: ${detail}`);
|
|
14405
|
-
throw new
|
|
15752
|
+
throw new RemoteError2("agent-enhancer/failed", detail || "Session delete failed", {
|
|
14406
15753
|
code: "SESSION_DELETE_FAILED"
|
|
14407
15754
|
});
|
|
14408
15755
|
}
|
|
14409
15756
|
}
|
|
15757
|
+
/** Workspaces eligible for imported web-chat sessions. */
|
|
15758
|
+
async listWebChatWorkspaces(_request, signal) {
|
|
15759
|
+
this.assertOwner();
|
|
15760
|
+
signal.throwIfAborted();
|
|
15761
|
+
try {
|
|
15762
|
+
return { items: listWebChatWorkspacesNow(this.ctx) };
|
|
15763
|
+
} catch (error) {
|
|
15764
|
+
if (signal.aborted) throw error;
|
|
15765
|
+
throw webChatImportToRemoteError(error);
|
|
15766
|
+
}
|
|
15767
|
+
}
|
|
15768
|
+
/** Pick a folder and register it as a workspace for web-chat import. */
|
|
15769
|
+
async createWebChatWorkspace(_request, signal) {
|
|
15770
|
+
this.assertOwner();
|
|
15771
|
+
signal.throwIfAborted();
|
|
15772
|
+
try {
|
|
15773
|
+
return await createWebChatWorkspaceNow(this.ctx, signal);
|
|
15774
|
+
} catch (error) {
|
|
15775
|
+
if (signal.aborted) throw error;
|
|
15776
|
+
throw webChatImportToRemoteError(error);
|
|
15777
|
+
}
|
|
15778
|
+
}
|
|
15779
|
+
/** Create a Desktop session from a captured/exported web transcript (no model call). */
|
|
15780
|
+
async importWebChatHistory(request, signal) {
|
|
15781
|
+
this.assertOwner();
|
|
15782
|
+
signal.throwIfAborted();
|
|
15783
|
+
try {
|
|
15784
|
+
return await importWebChatHistoryWithContext(this.ctx, request);
|
|
15785
|
+
} catch (error) {
|
|
15786
|
+
if (signal.aborted) throw error;
|
|
15787
|
+
throw webChatImportToRemoteError(error);
|
|
15788
|
+
}
|
|
15789
|
+
}
|
|
15790
|
+
/** Analyze an official export into selectable conversations (size limits enforced once). */
|
|
15791
|
+
async parseWebChatExport(request, signal) {
|
|
15792
|
+
this.assertOwner();
|
|
15793
|
+
signal.throwIfAborted();
|
|
15794
|
+
try {
|
|
15795
|
+
const bytes = Buffer.from(request.bytesBase64, "base64");
|
|
15796
|
+
return analyzeWebChatExport({ filename: request.filename, bytes });
|
|
15797
|
+
} catch (error) {
|
|
15798
|
+
if (signal.aborted) throw error;
|
|
15799
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
15800
|
+
throw webChatImportToRemoteError(
|
|
15801
|
+
error instanceof WebChatImportError ? error : new WebChatImportError("invalid-transcript", detail)
|
|
15802
|
+
);
|
|
15803
|
+
}
|
|
15804
|
+
}
|
|
15805
|
+
/**
|
|
15806
|
+
* Resolve a public DeepSeek share link (`chat.deepseek.com/share/…`) into a transcript.
|
|
15807
|
+
* Prefer `payloadJson` from the guest (same-origin) when WAF blocks Host fetch.
|
|
15808
|
+
*/
|
|
15809
|
+
async resolveWebChatShareLink(request, signal) {
|
|
15810
|
+
this.assertOwner();
|
|
15811
|
+
signal.throwIfAborted();
|
|
15812
|
+
try {
|
|
15813
|
+
const shareId = extractWebChatShareId(request.shareUrl);
|
|
15814
|
+
if (shareId === null) {
|
|
15815
|
+
throw new WebChatImportError("invalid-transcript", "unrecognized-share: not a DeepSeek share link");
|
|
15816
|
+
}
|
|
15817
|
+
const shareUrl = webChatSharePageUrl(shareId);
|
|
15818
|
+
let data;
|
|
15819
|
+
if (typeof request.payloadJson === "string" && request.payloadJson.trim() !== "") {
|
|
15820
|
+
try {
|
|
15821
|
+
data = JSON.parse(request.payloadJson);
|
|
15822
|
+
} catch {
|
|
15823
|
+
throw new WebChatImportError("invalid-transcript", "unrecognized-share: invalid payload json");
|
|
15824
|
+
}
|
|
15825
|
+
} else {
|
|
15826
|
+
data = await fetchWebChatShareContent(shareId, signal);
|
|
15827
|
+
}
|
|
15828
|
+
const transcript = parseWebChatShareContent(data, { shareUrl, shareId });
|
|
15829
|
+
return { transcript };
|
|
15830
|
+
} catch (error) {
|
|
15831
|
+
if (signal.aborted) throw error;
|
|
15832
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
15833
|
+
throw webChatImportToRemoteError(
|
|
15834
|
+
error instanceof WebChatImportError ? error : new WebChatImportError("invalid-transcript", detail)
|
|
15835
|
+
);
|
|
15836
|
+
}
|
|
15837
|
+
}
|
|
15838
|
+
webChatPluginDataRoot() {
|
|
15839
|
+
return this.installLedgerRoot ?? join32(homedir6(), ".dsh", "profiles", "desktop", "plugin-data", PACKAGE_NAME);
|
|
15840
|
+
}
|
|
15841
|
+
/** User-level web chat guest login snapshot (non-HttpOnly storage only). */
|
|
15842
|
+
async loadWebChatLoginSnapshot(_request, signal) {
|
|
15843
|
+
this.assertOwner();
|
|
15844
|
+
signal.throwIfAborted();
|
|
15845
|
+
return { snapshot: loadWebChatLoginSnapshot(this.webChatPluginDataRoot()) };
|
|
15846
|
+
}
|
|
15847
|
+
async saveWebChatLoginSnapshot(request, signal) {
|
|
15848
|
+
this.assertOwner();
|
|
15849
|
+
signal.throwIfAborted();
|
|
15850
|
+
saveWebChatLoginSnapshot(this.webChatPluginDataRoot(), request);
|
|
15851
|
+
return { ok: true };
|
|
15852
|
+
}
|
|
15853
|
+
async clearWebChatLoginSnapshot(_request, signal) {
|
|
15854
|
+
this.assertOwner();
|
|
15855
|
+
signal.throwIfAborted();
|
|
15856
|
+
return { cleared: clearWebChatLoginSnapshot(this.webChatPluginDataRoot()) };
|
|
15857
|
+
}
|
|
14410
15858
|
/** Read a workspace UTF-8 text file for the in-app Monaco editor. */
|
|
14411
15859
|
async readWorkspaceFile(request, signal) {
|
|
14412
15860
|
this.assertOwner();
|
|
@@ -14520,7 +15968,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14520
15968
|
signal.throwIfAborted();
|
|
14521
15969
|
const agent = this.ctx.agents.get(request.sessionId);
|
|
14522
15970
|
if (agent === void 0) {
|
|
14523
|
-
throw new
|
|
15971
|
+
throw new RemoteError2("agent-enhancer/failed", "Session not available for compaction", {
|
|
14524
15972
|
code: "SESSION_CHANGED"
|
|
14525
15973
|
});
|
|
14526
15974
|
}
|
|
@@ -14537,7 +15985,7 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14537
15985
|
const code = error instanceof AuxiliaryError ? error.code : "COMPACT_FAILED";
|
|
14538
15986
|
const detail = error instanceof Error ? error.message : String(error);
|
|
14539
15987
|
this.ctx.logger.warn(`agent-enhancer compact failed (${code}): ${detail}`);
|
|
14540
|
-
throw new
|
|
15988
|
+
throw new RemoteError2("agent-enhancer/failed", detail || "Context compaction failed", { code });
|
|
14541
15989
|
}
|
|
14542
15990
|
}
|
|
14543
15991
|
/** Read-only version probe — same gate policy as `listCatalog` (settings-safe). */
|
|
@@ -14888,16 +16336,16 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
14888
16336
|
}
|
|
14889
16337
|
};
|
|
14890
16338
|
function resolveCheckpointRoot(dshHome2) {
|
|
14891
|
-
const base =
|
|
14892
|
-
const nextPkg =
|
|
14893
|
-
const next =
|
|
14894
|
-
const prev =
|
|
14895
|
-
if (!
|
|
14896
|
-
|
|
14897
|
-
|
|
14898
|
-
const prevPkg =
|
|
16339
|
+
const base = join32(dshHome2, "profiles", "desktop", "plugin-data");
|
|
16340
|
+
const nextPkg = join32(base, PACKAGE_NAME);
|
|
16341
|
+
const next = join32(nextPkg, "checkpoint");
|
|
16342
|
+
const prev = join32(base, LEGACY_PACKAGE_NAME, "checkpoint");
|
|
16343
|
+
if (!existsSync19(next) && existsSync19(prev)) {
|
|
16344
|
+
mkdirSync11(nextPkg, { recursive: true });
|
|
16345
|
+
renameSync9(prev, next);
|
|
16346
|
+
const prevPkg = join32(base, LEGACY_PACKAGE_NAME);
|
|
14899
16347
|
try {
|
|
14900
|
-
if (
|
|
16348
|
+
if (existsSync19(prevPkg) && readdirSync7(prevPkg).length === 0) rmdirSync(prevPkg);
|
|
14901
16349
|
} catch {
|
|
14902
16350
|
}
|
|
14903
16351
|
}
|
|
@@ -14905,28 +16353,28 @@ function resolveCheckpointRoot(dshHome2) {
|
|
|
14905
16353
|
}
|
|
14906
16354
|
function fileEditRemoteError(error) {
|
|
14907
16355
|
if (error instanceof FileEditError) {
|
|
14908
|
-
return new
|
|
16356
|
+
return new RemoteError2("agent-enhancer/failed", error.message, { code: error.code });
|
|
14909
16357
|
}
|
|
14910
16358
|
const detail = error instanceof Error ? error.message : String(error);
|
|
14911
|
-
return new
|
|
16359
|
+
return new RemoteError2("agent-enhancer/failed", detail || "File edit failed", {
|
|
14912
16360
|
code: "FILE_EDIT_FAILED"
|
|
14913
16361
|
});
|
|
14914
16362
|
}
|
|
14915
16363
|
function extraFoldersRemoteError(error) {
|
|
14916
16364
|
if (error instanceof ExtraFoldersError) {
|
|
14917
|
-
return new
|
|
16365
|
+
return new RemoteError2("agent-enhancer/failed", error.message, { code: error.code });
|
|
14918
16366
|
}
|
|
14919
16367
|
const detail = error instanceof Error ? error.message : String(error);
|
|
14920
|
-
return new
|
|
16368
|
+
return new RemoteError2("agent-enhancer/failed", detail || "Extra folders failed", {
|
|
14921
16369
|
code: "FILE_EDIT_FAILED"
|
|
14922
16370
|
});
|
|
14923
16371
|
}
|
|
14924
16372
|
function instructionsSkillsRemoteError(error) {
|
|
14925
16373
|
if (error instanceof AuxiliaryError) {
|
|
14926
|
-
return new
|
|
16374
|
+
return new RemoteError2("agent-enhancer/failed", error.message, { code: error.code });
|
|
14927
16375
|
}
|
|
14928
16376
|
const detail = error instanceof Error ? error.message : String(error);
|
|
14929
|
-
return new
|
|
16377
|
+
return new RemoteError2("agent-enhancer/failed", detail || "Instructions & skills failed", {
|
|
14930
16378
|
code: "FILE_EDIT_FAILED"
|
|
14931
16379
|
});
|
|
14932
16380
|
}
|
|
@@ -14969,6 +16417,7 @@ function readSettings(config) {
|
|
|
14969
16417
|
runAlertsLevel: resolveRunAlertsLevel(config.runAlertsLevel.get()),
|
|
14970
16418
|
browserAgentEnabled: config.browserAgentEnabled.get(),
|
|
14971
16419
|
browserAgentBrowser: resolveBrowserAgentBrowser(config.browserAgentBrowser.get()),
|
|
16420
|
+
webChatBridgeEnabled: config.webChatBridgeEnabled.get(),
|
|
14972
16421
|
instructionsSkillsEnabled: config.instructionsSkillsEnabled.get(),
|
|
14973
16422
|
mcpConnectorsEnabled: config.mcpConnectorsEnabled.get(),
|
|
14974
16423
|
optimizeProvider: config.optimizeProvider.get(),
|
|
@@ -14999,9 +16448,9 @@ function apply(ctx, config) {
|
|
|
14999
16448
|
const settings = () => readSettings(config);
|
|
15000
16449
|
const models = new AuxiliaryModels(ctx, settings);
|
|
15001
16450
|
installAutoSessionRoute(ctx, { settings });
|
|
15002
|
-
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ??
|
|
15003
|
-
const pluginDataPackageRoot =
|
|
15004
|
-
const usage = new UsageLedger(
|
|
16451
|
+
const storageRoot = resolveCheckpointRoot(process.env.DSH_HOME ?? join32(homedir6(), ".dsh"));
|
|
16452
|
+
const pluginDataPackageRoot = join32(storageRoot, "..");
|
|
16453
|
+
const usage = new UsageLedger(join32(storageRoot, "..", "usage"), (message) => {
|
|
15005
16454
|
ctx.logger.warn(message);
|
|
15006
16455
|
});
|
|
15007
16456
|
const balancesFacade = (() => {
|
|
@@ -15031,12 +16480,12 @@ function apply(ctx, config) {
|
|
|
15031
16480
|
})();
|
|
15032
16481
|
installUsageObserver(ctx, usage);
|
|
15033
16482
|
const store = new CheckpointStore(storageRoot);
|
|
15034
|
-
const cutStore = new SessionCutStore(
|
|
16483
|
+
const cutStore = new SessionCutStore(join32(storageRoot, "cuts"));
|
|
15035
16484
|
const cutCache = /* @__PURE__ */ new Map();
|
|
15036
16485
|
const sessionCleanup = new SessionCleanupRegistry();
|
|
15037
16486
|
sessionCleanup.register(createCheckpointCleaner({ store, cutStore, storageRoot }));
|
|
15038
|
-
sessionCleanup.register(createContextExcludeCleaner(
|
|
15039
|
-
const extraFoldersStore = createExtraFoldersStore(
|
|
16487
|
+
sessionCleanup.register(createContextExcludeCleaner(join32(storageRoot, "..")));
|
|
16488
|
+
const extraFoldersStore = createExtraFoldersStore(join32(storageRoot, "..", "extra-folders"));
|
|
15040
16489
|
const softPauseGate = new SoftPauseGate();
|
|
15041
16490
|
const mcpStore = createMcpConnectorsStore(mcpConnectorsRoot(pluginDataPackageRoot));
|
|
15042
16491
|
const mcpRuntime = new McpConnectorRuntime(ctx, mcpStore);
|
|
@@ -15226,13 +16675,13 @@ var CheckpointRollbackRemoteService = class extends TypertRemoteService {
|
|
|
15226
16675
|
}
|
|
15227
16676
|
assertOwner() {
|
|
15228
16677
|
if (this.ctx.invocation?.peer.principal.kind !== "owner") {
|
|
15229
|
-
throw new
|
|
16678
|
+
throw new RemoteError2("agent-enhancer/forbidden", "Only the desktop owner may use checkpoint rollback", {});
|
|
15230
16679
|
}
|
|
15231
16680
|
}
|
|
15232
16681
|
remoteError(error, signal) {
|
|
15233
16682
|
if (signal.aborted) return error;
|
|
15234
16683
|
const code = error instanceof CheckpointRollbackError ? error.code : "ROLLBACK_FAILED";
|
|
15235
|
-
return new
|
|
16684
|
+
return new RemoteError2("agent-enhancer/rollback-failed", "Checkpoint rollback request failed", { code });
|
|
15236
16685
|
}
|
|
15237
16686
|
};
|
|
15238
16687
|
function applyCheckpointRollback(ctx, rollback) {
|