dsh-agent-enhancer 0.3.17 → 0.3.18
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 +2 -2
- package/README.md +2 -2
- package/lib/client/browser-agent/tab.d.ts.map +1 -1
- package/lib/client/locales.d.ts +25 -1
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/remote.d.ts +4 -1
- package/lib/client/remote.d.ts.map +1 -1
- package/lib/client.js +190 -2
- package/lib/client.js.map +1 -1
- package/lib/host/browser-agent/demo-recipes.d.ts +54 -0
- package/lib/host/browser-agent/demo-recipes.d.ts.map +1 -0
- package/lib/host/browser-agent/demo-replay.d.ts +9 -0
- package/lib/host/browser-agent/demo-replay.d.ts.map +1 -1
- package/lib/host/browser-agent/install.d.ts +22 -0
- package/lib/host/browser-agent/install.d.ts.map +1 -1
- package/lib/host/browser-agent/playwright-driver.d.ts.map +1 -1
- package/lib/host/browser-agent/tools.d.ts +3 -0
- package/lib/host/browser-agent/tools.d.ts.map +1 -1
- package/lib/host/index.d.ts +2 -1
- package/lib/host/index.d.ts.map +1 -1
- package/lib/host/rpc.d.ts +54 -0
- package/lib/host/rpc.d.ts.map +1 -1
- package/lib/index.js +384 -89
- package/lib/index.js.map +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/host/index.ts
|
|
2
|
-
import { existsSync as existsSync20, mkdirSync as
|
|
2
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync13, readdirSync as readdirSync7, renameSync as renameSync9, rmdirSync } from "node:fs";
|
|
3
3
|
import { homedir as homedir5 } from "node:os";
|
|
4
4
|
import { join as join30 } from "node:path";
|
|
5
5
|
import z5 from "@deepseek-ai/schemastery";
|
|
@@ -2014,9 +2014,9 @@ var PlaywrightDriver = class {
|
|
|
2014
2014
|
/** Small crop around the control a pending approval is about. */
|
|
2015
2015
|
async thumbnail(ref) {
|
|
2016
2016
|
const page = await this.requirePage();
|
|
2017
|
-
const tabId = this.tabIdFor(page);
|
|
2018
|
-
if (this.tabs.ref(tabId, ref) === void 0) return null;
|
|
2019
2017
|
const locator = page.locator(`[${PLAYWRIGHT_REF_ATTR}="${ref}"]`).first();
|
|
2018
|
+
const count = await locator.count().catch(() => 0);
|
|
2019
|
+
if (count === 0) return null;
|
|
2020
2020
|
const box = await locator.boundingBox().catch(() => null);
|
|
2021
2021
|
if (box === null) return null;
|
|
2022
2022
|
const viewport = page.viewportSize() ?? { width: 1280, height: 800 };
|
|
@@ -2689,9 +2689,6 @@ function classify(input) {
|
|
|
2689
2689
|
};
|
|
2690
2690
|
}
|
|
2691
2691
|
|
|
2692
|
-
// src/host/browser-agent/tools.ts
|
|
2693
|
-
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2694
|
-
|
|
2695
2692
|
// src/host/browser-agent/demo-replay.ts
|
|
2696
2693
|
function normalizeControlName(raw) {
|
|
2697
2694
|
return raw.replace(/[\u200b-\u200d\ufeff]/gu, "").replace(/\s+/gu, " ").trim().toLowerCase();
|
|
@@ -2731,7 +2728,10 @@ async function performStep(driver, step) {
|
|
|
2731
2728
|
const snapshot = await driver.snapshot();
|
|
2732
2729
|
const node = matchDemoControl(snapshot.nodes, step.role, step.name);
|
|
2733
2730
|
if (node === void 0) {
|
|
2734
|
-
return {
|
|
2731
|
+
return {
|
|
2732
|
+
ok: false,
|
|
2733
|
+
reason: `no control matching ${step.role} ${JSON.stringify(step.name)} on ${snapshot.url}`
|
|
2734
|
+
};
|
|
2735
2735
|
}
|
|
2736
2736
|
const result = await driver.click(node.ref);
|
|
2737
2737
|
return { ok: true, url: result.url };
|
|
@@ -2740,7 +2740,10 @@ async function performStep(driver, step) {
|
|
|
2740
2740
|
const snapshot = await driver.snapshot();
|
|
2741
2741
|
const node = matchDemoControl(snapshot.nodes, step.role, step.name);
|
|
2742
2742
|
if (node === void 0) {
|
|
2743
|
-
return {
|
|
2743
|
+
return {
|
|
2744
|
+
ok: false,
|
|
2745
|
+
reason: `no field matching ${step.role} ${JSON.stringify(step.name)} on ${snapshot.url}`
|
|
2746
|
+
};
|
|
2744
2747
|
}
|
|
2745
2748
|
const result = await driver.type(node.ref, step.value);
|
|
2746
2749
|
return { ok: true, url: result.url };
|
|
@@ -2755,27 +2758,77 @@ async function performStep(driver, step) {
|
|
|
2755
2758
|
}
|
|
2756
2759
|
}
|
|
2757
2760
|
}
|
|
2761
|
+
function samePage(a, b) {
|
|
2762
|
+
try {
|
|
2763
|
+
const left = new URL(a);
|
|
2764
|
+
const right = new URL(b);
|
|
2765
|
+
const path = (value) => value.replace(/\/+$/u, "");
|
|
2766
|
+
return left.origin === right.origin && path(left.pathname) === path(right.pathname);
|
|
2767
|
+
} catch {
|
|
2768
|
+
return a === b;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2758
2771
|
async function replayDemoSteps(driver, steps) {
|
|
2759
2772
|
const lines = [];
|
|
2760
2773
|
let currentTab;
|
|
2761
2774
|
let url;
|
|
2775
|
+
const recordedTabs = [];
|
|
2776
|
+
const tabUrls = /* @__PURE__ */ new Map();
|
|
2777
|
+
for (const step of steps) {
|
|
2778
|
+
if (step.tabId === void 0) continue;
|
|
2779
|
+
if (!recordedTabs.includes(step.tabId)) recordedTabs.push(step.tabId);
|
|
2780
|
+
if (!tabUrls.has(step.tabId) && step.tabUrl !== void 0) tabUrls.set(step.tabId, step.tabUrl);
|
|
2781
|
+
}
|
|
2782
|
+
const multiTab = recordedTabs.length > 1;
|
|
2783
|
+
const liveTabs = multiTab && typeof driver.listTabs === "function" ? await driver.listTabs().then((result) => result.tabs).catch(() => []) : [];
|
|
2784
|
+
const first = steps[0];
|
|
2785
|
+
if (first !== void 0 && first.kind !== "navigate" && first.tabUrl !== void 0 && /^https?:\/\//i.test(first.tabUrl)) {
|
|
2786
|
+
const current = await driver.snapshot().then((result) => result.url).catch(() => void 0);
|
|
2787
|
+
if (current === void 0 || !samePage(current, first.tabUrl)) {
|
|
2788
|
+
await driver.navigate(first.tabUrl).catch(() => void 0);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
const resolveTab = (recordedId) => {
|
|
2792
|
+
const wanted = tabUrls.get(recordedId);
|
|
2793
|
+
if (wanted === void 0) return void 0;
|
|
2794
|
+
return liveTabs.find((tab) => samePage(tab.url, wanted))?.tabId;
|
|
2795
|
+
};
|
|
2762
2796
|
for (let index = 0; index < steps.length; index += 1) {
|
|
2763
2797
|
const step = steps[index];
|
|
2764
|
-
if (step.tabId !== void 0 && step.tabId !== currentTab) {
|
|
2798
|
+
if (multiTab && step.tabId !== void 0 && step.tabId !== currentTab) {
|
|
2765
2799
|
try {
|
|
2766
|
-
const followed = await driver.followTab(step.tabId);
|
|
2800
|
+
const followed = await driver.followTab(resolveTab(step.tabId) ?? step.tabId);
|
|
2767
2801
|
currentTab = step.tabId;
|
|
2768
2802
|
url = followed.url;
|
|
2769
2803
|
} catch {
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2804
|
+
const tabUrl = tabUrls.get(step.tabId);
|
|
2805
|
+
if (tabUrl !== void 0) {
|
|
2806
|
+
try {
|
|
2807
|
+
const navigated = await driver.navigate(tabUrl);
|
|
2808
|
+
currentTab = step.tabId;
|
|
2809
|
+
url = navigated.url;
|
|
2810
|
+
} catch {
|
|
2811
|
+
return {
|
|
2812
|
+
status: "blocked",
|
|
2813
|
+
performed: index,
|
|
2814
|
+
total: steps.length,
|
|
2815
|
+
lines,
|
|
2816
|
+
reason: `tab ${step.tabId} is no longer open and ${tabUrl} could not be reopened`,
|
|
2817
|
+
pending: steps.slice(index),
|
|
2818
|
+
...url === void 0 ? {} : { url }
|
|
2819
|
+
};
|
|
2820
|
+
}
|
|
2821
|
+
} else {
|
|
2822
|
+
return {
|
|
2823
|
+
status: "blocked",
|
|
2824
|
+
performed: index,
|
|
2825
|
+
total: steps.length,
|
|
2826
|
+
lines,
|
|
2827
|
+
reason: `tab ${step.tabId} is no longer open and the recording has no URL for it`,
|
|
2828
|
+
pending: steps.slice(index),
|
|
2829
|
+
...url === void 0 ? {} : { url }
|
|
2830
|
+
};
|
|
2831
|
+
}
|
|
2779
2832
|
}
|
|
2780
2833
|
}
|
|
2781
2834
|
const obstacle = replayObstacle(step);
|
|
@@ -2818,6 +2871,7 @@ async function replayDemoSteps(driver, steps) {
|
|
|
2818
2871
|
}
|
|
2819
2872
|
|
|
2820
2873
|
// src/host/browser-agent/tools.ts
|
|
2874
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2821
2875
|
var HUMAN_WAIT_TIMEOUT_MS = 15 * 6e4;
|
|
2822
2876
|
function textTool(name2, description, parameters, execute, timeoutMs = 6e4) {
|
|
2823
2877
|
return defineTool({
|
|
@@ -3954,6 +4008,7 @@ Action: browser_extract or browser_snapshot next. Do not navigate away unless th
|
|
|
3954
4008
|
if (status === "cancelled") {
|
|
3955
4009
|
return "user_ack: cancelled\nAction: the demonstration was cancelled. Ask what they want next.";
|
|
3956
4010
|
}
|
|
4011
|
+
if (steps.length > 0) options.onDemonstration?.(steps);
|
|
3957
4012
|
const summary = summarizeDemoSteps(steps);
|
|
3958
4013
|
options.sessions.record({
|
|
3959
4014
|
sessionId,
|
|
@@ -4106,6 +4161,8 @@ function installBrowserAgent(ctx, options) {
|
|
|
4106
4161
|
const human = new BrowserHumanGate();
|
|
4107
4162
|
const sessions = new BrowserSessionState();
|
|
4108
4163
|
const tabScope = new TabScopeStore();
|
|
4164
|
+
const recipes = options.recipes;
|
|
4165
|
+
let lastDemoSteps = [];
|
|
4109
4166
|
let availabilityCache = null;
|
|
4110
4167
|
const browserAvailability = () => {
|
|
4111
4168
|
if (availabilityCache !== null) return availabilityCache;
|
|
@@ -4225,6 +4282,9 @@ function installBrowserAgent(ctx, options) {
|
|
|
4225
4282
|
tabScope,
|
|
4226
4283
|
debugTools: () => options.debugTools?.() === true,
|
|
4227
4284
|
demonstrate: () => options.demonstrate?.() === true,
|
|
4285
|
+
onDemonstration: (steps) => {
|
|
4286
|
+
lastDemoSteps = steps;
|
|
4287
|
+
},
|
|
4228
4288
|
diagnosis: diagnoseNow,
|
|
4229
4289
|
// Gate on settings only — `active` flips false during driver align and
|
|
4230
4290
|
// must not make browser_* look "disabled" mid-turn.
|
|
@@ -4404,6 +4464,7 @@ function installBrowserAgent(ctx, options) {
|
|
|
4404
4464
|
const aligned = await alignToPreference();
|
|
4405
4465
|
if (!aligned.ok) return { ok: false, error: aligned.error ?? "Browser agent failed to start" };
|
|
4406
4466
|
await requireDriver().startDemonstration();
|
|
4467
|
+
lastDemoSteps = [];
|
|
4407
4468
|
sessions.record({
|
|
4408
4469
|
sessionId: "sidebar",
|
|
4409
4470
|
tool: "browser_demonstrate",
|
|
@@ -4420,6 +4481,7 @@ function installBrowserAgent(ctx, options) {
|
|
|
4420
4481
|
if (driver === null) return { ok: false, error: "Browser agent is not running" };
|
|
4421
4482
|
try {
|
|
4422
4483
|
const steps = await driver.stopDemonstration();
|
|
4484
|
+
lastDemoSteps = steps;
|
|
4423
4485
|
const summary = summarizeDemoSteps(steps);
|
|
4424
4486
|
sessions.record({
|
|
4425
4487
|
sessionId: "sidebar",
|
|
@@ -4435,6 +4497,72 @@ function installBrowserAgent(ctx, options) {
|
|
|
4435
4497
|
demoActive() {
|
|
4436
4498
|
return activeDriver?.demonstrationActive() === true;
|
|
4437
4499
|
},
|
|
4500
|
+
lastDemonstrationSteps() {
|
|
4501
|
+
return lastDemoSteps.length;
|
|
4502
|
+
},
|
|
4503
|
+
async demoRecipes(input) {
|
|
4504
|
+
if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
|
|
4505
|
+
if (recipes === void 0) return { ok: false, error: "recipe store unavailable" };
|
|
4506
|
+
if (input.action === "list") {
|
|
4507
|
+
return { ok: true, recipes: recipes.list() };
|
|
4508
|
+
}
|
|
4509
|
+
if (input.action === "delete") {
|
|
4510
|
+
const id = input.id ?? "";
|
|
4511
|
+
const removed = recipes.remove(id);
|
|
4512
|
+
sessions.record({
|
|
4513
|
+
sessionId: "sidebar",
|
|
4514
|
+
tool: "browser_demo_recipe",
|
|
4515
|
+
summary: removed ? `Deleted demonstration recipe ${id}` : `Recipe ${id} not found`,
|
|
4516
|
+
outcome: removed ? "ok" : "error"
|
|
4517
|
+
});
|
|
4518
|
+
return removed ? { ok: true, recipes: recipes.list() } : { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728", recipes: recipes.list() };
|
|
4519
|
+
}
|
|
4520
|
+
if (input.action === "save") {
|
|
4521
|
+
if (options.demonstrate?.() !== true) {
|
|
4522
|
+
return { ok: false, error: "\u6F14\u793A\u5F55\u5236\u672A\u5F00\u542F\uFF1A\u8BBE\u7F6E \u2192 \u529F\u80FD \u2192 \u6D4F\u89C8\u5668 Agent" };
|
|
4523
|
+
}
|
|
4524
|
+
if (lastDemoSteps.length === 0) {
|
|
4525
|
+
return { ok: false, error: "\u5148\u5F55\u5236\u4E00\u6B21\uFF0C\u518D\u4FDD\u5B58\u4E3A\u6D41\u7A0B", recipes: recipes.list() };
|
|
4526
|
+
}
|
|
4527
|
+
const saved = recipes.save({ name: input.name ?? "", steps: lastDemoSteps });
|
|
4528
|
+
if (!saved.ok) return { ok: false, error: saved.error, recipes: recipes.list() };
|
|
4529
|
+
sessions.record({
|
|
4530
|
+
sessionId: "sidebar",
|
|
4531
|
+
tool: "browser_demo_recipe",
|
|
4532
|
+
summary: `Saved demonstration recipe "${saved.recipe.name}" (${saved.recipe.steps} step(s))`,
|
|
4533
|
+
outcome: "ok"
|
|
4534
|
+
});
|
|
4535
|
+
return { ok: true, recipe: saved.recipe, recipes: recipes.list() };
|
|
4536
|
+
}
|
|
4537
|
+
const recipe = recipes.get(input.id ?? "");
|
|
4538
|
+
if (recipe === void 0) return { ok: false, error: "\u6D41\u7A0B\u4E0D\u5B58\u5728", recipes: recipes.list() };
|
|
4539
|
+
const driver = activeDriver;
|
|
4540
|
+
if (driver === null) return { ok: false, error: "Browser agent is not running", recipes: recipes.list() };
|
|
4541
|
+
const aligned = await alignToPreference().catch(() => ({ ok: true, error: void 0 }));
|
|
4542
|
+
if (!aligned.ok) return { ok: false, error: aligned.error ?? "Browser agent failed to start", recipes: recipes.list() };
|
|
4543
|
+
const outcome = await replayDemoSteps(driver, recipe.steps).catch((error) => ({
|
|
4544
|
+
status: "blocked",
|
|
4545
|
+
performed: 0,
|
|
4546
|
+
total: recipe.steps.length,
|
|
4547
|
+
lines: [],
|
|
4548
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
4549
|
+
pending: [...recipe.steps]
|
|
4550
|
+
}));
|
|
4551
|
+
const ranAll = outcome.status === "done";
|
|
4552
|
+
sessions.record({
|
|
4553
|
+
sessionId: "sidebar",
|
|
4554
|
+
tool: "browser_demo_recipe",
|
|
4555
|
+
summary: `Ran demonstration recipe "${recipe.name}" (${outcome.performed}/${outcome.total}${ranAll ? "" : ", stopped"})`,
|
|
4556
|
+
outcome: ranAll ? "ok" : "error"
|
|
4557
|
+
});
|
|
4558
|
+
return {
|
|
4559
|
+
ok: true,
|
|
4560
|
+
recipes: recipes.list(),
|
|
4561
|
+
lines: [...outcome.lines],
|
|
4562
|
+
...ranAll ? {} : { stoppedAt: outcome.performed + 1 },
|
|
4563
|
+
...ranAll ? {} : { reason: outcome.reason }
|
|
4564
|
+
};
|
|
4565
|
+
},
|
|
4438
4566
|
async selectTab(input) {
|
|
4439
4567
|
if (!options.enabled()) return { ok: false, error: "Browser agent disabled" };
|
|
4440
4568
|
await switchGate.catch(() => void 0);
|
|
@@ -4587,6 +4715,106 @@ function installBrowserAgent(ctx, options) {
|
|
|
4587
4715
|
};
|
|
4588
4716
|
}
|
|
4589
4717
|
|
|
4718
|
+
// src/host/browser-agent/demo-recipes.ts
|
|
4719
|
+
import { mkdirSync as mkdirSync2, readFileSync, writeFileSync } from "node:fs";
|
|
4720
|
+
import { dirname } from "node:path";
|
|
4721
|
+
var MAX_RECIPES = 20;
|
|
4722
|
+
var MAX_RECIPE_NAME = 60;
|
|
4723
|
+
var MAX_RECIPE_STEPS = 200;
|
|
4724
|
+
var FILE_VERSION = 1;
|
|
4725
|
+
function metaOf(recipe) {
|
|
4726
|
+
return {
|
|
4727
|
+
id: recipe.id,
|
|
4728
|
+
name: recipe.name,
|
|
4729
|
+
createdAt: recipe.createdAt,
|
|
4730
|
+
updatedAt: recipe.updatedAt,
|
|
4731
|
+
steps: recipe.steps.length
|
|
4732
|
+
};
|
|
4733
|
+
}
|
|
4734
|
+
function isStep(value) {
|
|
4735
|
+
if (value === null || typeof value !== "object") return false;
|
|
4736
|
+
const kind = value.kind;
|
|
4737
|
+
return kind === "navigate" || kind === "click" || kind === "fill" || kind === "press";
|
|
4738
|
+
}
|
|
4739
|
+
function sanitizeRecipeSteps(raw) {
|
|
4740
|
+
if (!Array.isArray(raw)) return [];
|
|
4741
|
+
const steps = raw.filter(isStep).slice(0, MAX_RECIPE_STEPS);
|
|
4742
|
+
return sanitizeDemoSteps(steps).map((step) => {
|
|
4743
|
+
const { tabId: _volatileTabId, ...rest } = step;
|
|
4744
|
+
return rest;
|
|
4745
|
+
});
|
|
4746
|
+
}
|
|
4747
|
+
var DemoRecipeStore = class {
|
|
4748
|
+
constructor(filePath = null) {
|
|
4749
|
+
this.filePath = filePath;
|
|
4750
|
+
}
|
|
4751
|
+
filePath;
|
|
4752
|
+
memory = [];
|
|
4753
|
+
list() {
|
|
4754
|
+
return this.read().map(metaOf).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
4755
|
+
}
|
|
4756
|
+
get(id) {
|
|
4757
|
+
return this.read().find((recipe) => recipe.id === id);
|
|
4758
|
+
}
|
|
4759
|
+
/** Save under `name`; the same name (case-insensitive) updates in place. */
|
|
4760
|
+
save(input) {
|
|
4761
|
+
const name2 = input.name.replace(/\s+/gu, " ").trim();
|
|
4762
|
+
if (name2 === "") return { ok: false, error: "\u6D41\u7A0B\u540D\u4E0D\u80FD\u4E3A\u7A7A" };
|
|
4763
|
+
if (name2.length > MAX_RECIPE_NAME) return { ok: false, error: `\u6D41\u7A0B\u540D\u6700\u957F ${MAX_RECIPE_NAME} \u4E2A\u5B57\u7B26` };
|
|
4764
|
+
const steps = sanitizeRecipeSteps(input.steps);
|
|
4765
|
+
if (steps.length === 0) return { ok: false, error: "\u8FD9\u6B21\u5F55\u5236\u6CA1\u6709\u53EF\u4FDD\u5B58\u7684\u6B65\u9AA4" };
|
|
4766
|
+
const now = input.now ?? Date.now();
|
|
4767
|
+
const recipes = this.read();
|
|
4768
|
+
const existing = recipes.find((recipe) => recipe.name.toLowerCase() === name2.toLowerCase());
|
|
4769
|
+
let saved;
|
|
4770
|
+
if (existing !== void 0) {
|
|
4771
|
+
saved = { ...existing, name: name2, steps, updatedAt: now };
|
|
4772
|
+
} else {
|
|
4773
|
+
if (recipes.length >= MAX_RECIPES) {
|
|
4774
|
+
return { ok: false, error: `\u6700\u591A\u4FDD\u5B58 ${MAX_RECIPES} \u4E2A\u6D41\u7A0B\uFF0C\u5148\u5220\u6389\u4E00\u4E2A` };
|
|
4775
|
+
}
|
|
4776
|
+
saved = { id: `r-${now.toString(36)}-${Math.random().toString(36).slice(2, 7)}`, name: name2, createdAt: now, updatedAt: now, steps };
|
|
4777
|
+
}
|
|
4778
|
+
const next = existing === void 0 ? [...recipes, saved] : recipes.map((recipe) => recipe.id === saved.id ? saved : recipe);
|
|
4779
|
+
this.write(next);
|
|
4780
|
+
return { ok: true, recipe: metaOf(saved) };
|
|
4781
|
+
}
|
|
4782
|
+
remove(id) {
|
|
4783
|
+
const recipes = this.read();
|
|
4784
|
+
const next = recipes.filter((recipe) => recipe.id !== id);
|
|
4785
|
+
if (next.length === recipes.length) return false;
|
|
4786
|
+
this.write(next);
|
|
4787
|
+
return true;
|
|
4788
|
+
}
|
|
4789
|
+
read() {
|
|
4790
|
+
if (this.filePath === null) return this.memory;
|
|
4791
|
+
try {
|
|
4792
|
+
const parsed = JSON.parse(readFileSync(this.filePath, "utf8"));
|
|
4793
|
+
if (parsed.version !== FILE_VERSION || !Array.isArray(parsed.recipes)) return [];
|
|
4794
|
+
return parsed.recipes.filter((recipe) => {
|
|
4795
|
+
if (recipe === null || typeof recipe !== "object") return false;
|
|
4796
|
+
if (typeof recipe.id !== "string" || typeof recipe.name !== "string") return false;
|
|
4797
|
+
return typeof recipe.createdAt === "number" && typeof recipe.updatedAt === "number";
|
|
4798
|
+
}).map((recipe) => ({ ...recipe, steps: sanitizeRecipeSteps(recipe.steps) })).filter((recipe) => recipe.steps.length > 0).slice(0, MAX_RECIPES);
|
|
4799
|
+
} catch {
|
|
4800
|
+
return [];
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
write(recipes) {
|
|
4804
|
+
if (this.filePath === null) {
|
|
4805
|
+
this.memory = [...recipes];
|
|
4806
|
+
return;
|
|
4807
|
+
}
|
|
4808
|
+
try {
|
|
4809
|
+
mkdirSync2(dirname(this.filePath), { recursive: true });
|
|
4810
|
+
const shape = { version: FILE_VERSION, recipes };
|
|
4811
|
+
writeFileSync(this.filePath, `${JSON.stringify(shape, null, 2)}
|
|
4812
|
+
`, "utf8");
|
|
4813
|
+
} catch {
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
};
|
|
4817
|
+
|
|
4590
4818
|
// src/errors.ts
|
|
4591
4819
|
var MESSAGES = {
|
|
4592
4820
|
MODEL_UNAVAILABLE: "No model is available for Agent Enhance",
|
|
@@ -8216,7 +8444,7 @@ async function deleteSessionNow(options) {
|
|
|
8216
8444
|
|
|
8217
8445
|
// src/host/web-chat-bridge/import-session.ts
|
|
8218
8446
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
8219
|
-
import { existsSync as existsSync5, mkdirSync as
|
|
8447
|
+
import { existsSync as existsSync5, mkdirSync as mkdirSync3, statSync } from "node:fs";
|
|
8220
8448
|
import { resolve as resolve2 } from "node:path";
|
|
8221
8449
|
import { RemoteError } from "@deepseek-ai/dsh-typert-protocol";
|
|
8222
8450
|
import {
|
|
@@ -9177,7 +9405,7 @@ function ensureResolvableWorkspaceCwd(cwd) {
|
|
|
9177
9405
|
const absolute = resolve2(cwd);
|
|
9178
9406
|
try {
|
|
9179
9407
|
if (!existsSync5(absolute)) {
|
|
9180
|
-
|
|
9408
|
+
mkdirSync3(absolute, { recursive: true });
|
|
9181
9409
|
}
|
|
9182
9410
|
if (!statSync(absolute).isDirectory()) {
|
|
9183
9411
|
throw new WebChatImportError(
|
|
@@ -10044,8 +10272,8 @@ async function fetchWebChatShareContent(shareId, signal) {
|
|
|
10044
10272
|
}
|
|
10045
10273
|
|
|
10046
10274
|
// src/host/web-chat-bridge/login-snapshot.ts
|
|
10047
|
-
import { existsSync as existsSync6, mkdirSync as
|
|
10048
|
-
import { dirname, join as join9 } from "node:path";
|
|
10275
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync4, readFileSync as readFileSync2, renameSync, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
10276
|
+
import { dirname as dirname2, join as join9 } from "node:path";
|
|
10049
10277
|
|
|
10050
10278
|
// src/host/web-chat-bridge/login-snapshot-types.ts
|
|
10051
10279
|
var WEB_CHAT_OFFICIAL_ORIGIN = "https://chat.deepseek.com";
|
|
@@ -10113,7 +10341,7 @@ function loadWebChatLoginSnapshot(pluginDataPackageRoot) {
|
|
|
10113
10341
|
const path = webChatLoginSnapshotPath(pluginDataPackageRoot);
|
|
10114
10342
|
if (!existsSync6(path)) return null;
|
|
10115
10343
|
try {
|
|
10116
|
-
return parseSnapshot(
|
|
10344
|
+
return parseSnapshot(readFileSync2(path, "utf8"));
|
|
10117
10345
|
} catch {
|
|
10118
10346
|
return null;
|
|
10119
10347
|
}
|
|
@@ -10138,9 +10366,9 @@ function saveWebChatLoginSnapshot(pluginDataPackageRoot, input, options) {
|
|
|
10138
10366
|
savedAt: typeof input.savedAt === "string" && input.savedAt.trim() !== "" ? input.savedAt : (/* @__PURE__ */ new Date()).toISOString()
|
|
10139
10367
|
};
|
|
10140
10368
|
const path = webChatLoginSnapshotPath(pluginDataPackageRoot);
|
|
10141
|
-
|
|
10369
|
+
mkdirSync4(dirname2(path), { recursive: true });
|
|
10142
10370
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
10143
|
-
|
|
10371
|
+
writeFileSync2(tmp, `${JSON.stringify(snapshot, null, 2)}
|
|
10144
10372
|
`, "utf8");
|
|
10145
10373
|
renameSync(tmp, path);
|
|
10146
10374
|
return snapshot;
|
|
@@ -10418,8 +10646,8 @@ function loadExtraRootPaths(store, primaryCwd) {
|
|
|
10418
10646
|
}
|
|
10419
10647
|
|
|
10420
10648
|
// src/host/extra-folders/store.ts
|
|
10421
|
-
import { mkdirSync as
|
|
10422
|
-
import { dirname as
|
|
10649
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync3, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
10650
|
+
import { dirname as dirname3, join as join11 } from "node:path";
|
|
10423
10651
|
function emptyDoc(primaryCwd) {
|
|
10424
10652
|
return {
|
|
10425
10653
|
version: EXTRA_FOLDERS_VERSION,
|
|
@@ -10451,14 +10679,14 @@ function parseDoc(raw, primaryCwd) {
|
|
|
10451
10679
|
}
|
|
10452
10680
|
}
|
|
10453
10681
|
function createExtraFoldersStore(rootDir) {
|
|
10454
|
-
|
|
10682
|
+
mkdirSync5(rootDir, { recursive: true });
|
|
10455
10683
|
const fileOf = (primaryCwd) => join11(rootDir, `${cwdStorageKey(primaryCwd)}.json`);
|
|
10456
10684
|
return {
|
|
10457
10685
|
rootDir,
|
|
10458
10686
|
load(primaryCwd) {
|
|
10459
10687
|
const file = fileOf(primaryCwd);
|
|
10460
10688
|
try {
|
|
10461
|
-
return parseDoc(
|
|
10689
|
+
return parseDoc(readFileSync3(file, "utf8"), primaryCwd);
|
|
10462
10690
|
} catch (error) {
|
|
10463
10691
|
const code = error !== null && typeof error === "object" ? String(Reflect.get(error, "code") ?? "") : "";
|
|
10464
10692
|
if (code === "ENOENT") return emptyDoc(primaryCwd);
|
|
@@ -10472,9 +10700,9 @@ function createExtraFoldersStore(rootDir) {
|
|
|
10472
10700
|
roots: [...roots]
|
|
10473
10701
|
};
|
|
10474
10702
|
const file = fileOf(primaryCwd);
|
|
10475
|
-
|
|
10703
|
+
mkdirSync5(dirname3(file), { recursive: true });
|
|
10476
10704
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
10477
|
-
|
|
10705
|
+
writeFileSync3(tmp, `${JSON.stringify(doc, null, 2)}
|
|
10478
10706
|
`, "utf8");
|
|
10479
10707
|
renameSync2(tmp, file);
|
|
10480
10708
|
return doc;
|
|
@@ -10662,7 +10890,7 @@ async function writeWorkspaceFileNow(options) {
|
|
|
10662
10890
|
// src/host/file-edit/monaco.ts
|
|
10663
10891
|
import { existsSync as existsSync7 } from "node:fs";
|
|
10664
10892
|
import { promises as fsp2 } from "node:fs";
|
|
10665
|
-
import { dirname as
|
|
10893
|
+
import { dirname as dirname4, extname, join as join12, resolve as resolve6, sep as sep5 } from "node:path";
|
|
10666
10894
|
import { fileURLToPath } from "node:url";
|
|
10667
10895
|
|
|
10668
10896
|
// src/shared/monaco-route.ts
|
|
@@ -10671,7 +10899,7 @@ var MONACO_ROUTE = "/api/agent-enhancer/monaco";
|
|
|
10671
10899
|
// src/host/file-edit/monaco.ts
|
|
10672
10900
|
var FILE_PATTERN = /^(?:vs\/)?(?:[A-Za-z0-9._-]+\/)*[A-Za-z0-9._-]+$/;
|
|
10673
10901
|
function packageRootCandidates() {
|
|
10674
|
-
const here =
|
|
10902
|
+
const here = dirname4(fileURLToPath(import.meta.url));
|
|
10675
10903
|
return [
|
|
10676
10904
|
resolve6(here, "..", "vendor", "monaco", "vs"),
|
|
10677
10905
|
resolve6(here, "..", "..", "vendor", "monaco", "vs"),
|
|
@@ -10817,16 +11045,16 @@ function installMonacoRoute(ctx) {
|
|
|
10817
11045
|
}
|
|
10818
11046
|
|
|
10819
11047
|
// src/host/instructions-skills/io.ts
|
|
10820
|
-
import { existsSync as existsSync17, readFileSync as
|
|
11048
|
+
import { existsSync as existsSync17, readFileSync as readFileSync8, statSync as statSync5 } from "node:fs";
|
|
10821
11049
|
import { basename as basename13, join as join26, resolve as resolve16, sep as sep7 } from "node:path";
|
|
10822
11050
|
|
|
10823
11051
|
// src/host/instructions-skills/create.ts
|
|
10824
|
-
import { existsSync as existsSync9, mkdirSync as
|
|
10825
|
-
import { dirname as
|
|
11052
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync6, writeFileSync as writeFileSync4 } from "node:fs";
|
|
11053
|
+
import { dirname as dirname6, join as join14, resolve as resolve8 } from "node:path";
|
|
10826
11054
|
|
|
10827
11055
|
// src/host/instructions-skills/paths.ts
|
|
10828
11056
|
import { existsSync as existsSync8, statSync as statSync2 } from "node:fs";
|
|
10829
|
-
import { basename as basename5, dirname as
|
|
11057
|
+
import { basename as basename5, dirname as dirname5, join as join13, resolve as resolve7, sep as sep6 } from "node:path";
|
|
10830
11058
|
import { homedir as homedir3 } from "node:os";
|
|
10831
11059
|
var INSTRUCTION_CANDIDATES = [
|
|
10832
11060
|
"AGENTS.md",
|
|
@@ -10851,7 +11079,7 @@ function findProjectRoot(cwd, markers = PROJECT_ROOT_MARKERS) {
|
|
|
10851
11079
|
for (const marker of markers) {
|
|
10852
11080
|
if (existsSync8(join13(current, marker))) return current;
|
|
10853
11081
|
}
|
|
10854
|
-
const parent =
|
|
11082
|
+
const parent = dirname5(current);
|
|
10855
11083
|
if (parent === current) return resolve7(cwd);
|
|
10856
11084
|
current = parent;
|
|
10857
11085
|
}
|
|
@@ -10865,7 +11093,7 @@ function projectChainDirs(projectRoot, cwd) {
|
|
|
10865
11093
|
for (; ; ) {
|
|
10866
11094
|
parts.push(current);
|
|
10867
11095
|
if (samePath2(current, root)) break;
|
|
10868
|
-
const parent =
|
|
11096
|
+
const parent = dirname5(current);
|
|
10869
11097
|
if (parent === current) break;
|
|
10870
11098
|
current = parent;
|
|
10871
11099
|
}
|
|
@@ -10949,8 +11177,8 @@ function createWorkspaceAgentsFile(projectRoot) {
|
|
|
10949
11177
|
if (existsSync9(path)) {
|
|
10950
11178
|
throw new AuxiliaryError("FILE_DENIED", "AGENTS.md already exists at the workspace root");
|
|
10951
11179
|
}
|
|
10952
|
-
|
|
10953
|
-
|
|
11180
|
+
mkdirSync6(dirname6(path), { recursive: true });
|
|
11181
|
+
writeFileSync4(path, AGENTS_STUB, "utf8");
|
|
10954
11182
|
return { path, created: true };
|
|
10955
11183
|
}
|
|
10956
11184
|
function createWorkspaceSkill(projectRoot, rawName) {
|
|
@@ -10963,14 +11191,14 @@ function createWorkspaceSkill(projectRoot, rawName) {
|
|
|
10963
11191
|
if (existsSync9(path) || existsSync9(dir)) {
|
|
10964
11192
|
throw new AuxiliaryError("FILE_DENIED", "A skill with that name already exists");
|
|
10965
11193
|
}
|
|
10966
|
-
|
|
10967
|
-
|
|
11194
|
+
mkdirSync6(dir, { recursive: true });
|
|
11195
|
+
writeFileSync4(path, skillStubMarkdown(name2), "utf8");
|
|
10968
11196
|
return { path, created: true, name: name2 };
|
|
10969
11197
|
}
|
|
10970
11198
|
|
|
10971
11199
|
// src/host/instructions-skills/discover.ts
|
|
10972
|
-
import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as
|
|
10973
|
-
import { basename as basename9, dirname as
|
|
11200
|
+
import { existsSync as existsSync13, readdirSync as readdirSync3, readFileSync as readFileSync5, statSync as statSync3 } from "node:fs";
|
|
11201
|
+
import { basename as basename9, dirname as dirname9, join as join19, resolve as resolve12 } from "node:path";
|
|
10974
11202
|
|
|
10975
11203
|
// src/host/instructions-skills/types.ts
|
|
10976
11204
|
function defaultSkillInstallMeta() {
|
|
@@ -11047,19 +11275,19 @@ function removeQuietly(path) {
|
|
|
11047
11275
|
|
|
11048
11276
|
// src/host/instructions-skills/uninstall.ts
|
|
11049
11277
|
import { lstatSync as lstatSync3 } from "node:fs";
|
|
11050
|
-
import { basename as basename8, dirname as
|
|
11278
|
+
import { basename as basename8, dirname as dirname8, join as join18, resolve as resolve11 } from "node:path";
|
|
11051
11279
|
|
|
11052
11280
|
// src/host/instructions-skills/install-ledger.ts
|
|
11053
|
-
import { existsSync as existsSync11, mkdirSync as
|
|
11054
|
-
import { dirname as
|
|
11281
|
+
import { existsSync as existsSync11, mkdirSync as mkdirSync7, readFileSync as readFileSync4, renameSync as renameSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
11282
|
+
import { dirname as dirname7, join as join16 } from "node:path";
|
|
11055
11283
|
function ledgerPath(dataRoot) {
|
|
11056
11284
|
return join16(dataRoot, "skills-install", "registry.json");
|
|
11057
11285
|
}
|
|
11058
11286
|
function writeLedger(dataRoot, ledger) {
|
|
11059
11287
|
const path = ledgerPath(dataRoot);
|
|
11060
|
-
|
|
11288
|
+
mkdirSync7(dirname7(path), { recursive: true });
|
|
11061
11289
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
11062
|
-
|
|
11290
|
+
writeFileSync5(tmp, `${JSON.stringify(ledger, null, 2)}
|
|
11063
11291
|
`, "utf8");
|
|
11064
11292
|
renameSync4(tmp, path);
|
|
11065
11293
|
}
|
|
@@ -11067,7 +11295,7 @@ function readInstallLedger(dataRoot) {
|
|
|
11067
11295
|
const path = ledgerPath(dataRoot);
|
|
11068
11296
|
if (!existsSync11(path)) return {};
|
|
11069
11297
|
try {
|
|
11070
|
-
const raw =
|
|
11298
|
+
const raw = readFileSync4(path, "utf8").trim();
|
|
11071
11299
|
if (raw === "") return {};
|
|
11072
11300
|
return JSON.parse(raw);
|
|
11073
11301
|
} catch {
|
|
@@ -11275,7 +11503,7 @@ function removePathRobust(target) {
|
|
|
11275
11503
|
function skillEntryPath(skillMdOrBundlePath) {
|
|
11276
11504
|
const absolute = resolve11(skillMdOrBundlePath);
|
|
11277
11505
|
const base = basename8(absolute);
|
|
11278
|
-
if (base.toLowerCase() === "skill.md") return
|
|
11506
|
+
if (base.toLowerCase() === "skill.md") return dirname8(absolute);
|
|
11279
11507
|
if (base.toLowerCase().endsWith(".md")) return absolute;
|
|
11280
11508
|
return absolute;
|
|
11281
11509
|
}
|
|
@@ -11294,7 +11522,7 @@ function managedSkillEntriesForName(root, name2) {
|
|
|
11294
11522
|
const asFile = join18(root, `${name2}.md`);
|
|
11295
11523
|
for (const entry of [asDir, asFile]) {
|
|
11296
11524
|
if (!pathPresent2(entry)) continue;
|
|
11297
|
-
if (!samePath2(
|
|
11525
|
+
if (!samePath2(dirname8(entry), root)) continue;
|
|
11298
11526
|
if (!isInsideOrSame(root, entry)) continue;
|
|
11299
11527
|
out.push(entry);
|
|
11300
11528
|
}
|
|
@@ -11308,7 +11536,7 @@ function resolveManagedSkillRemovalTarget(path, name2, managedRoots) {
|
|
|
11308
11536
|
const asFile = join18(root, `${name2}.md`);
|
|
11309
11537
|
if (samePath2(entry, asDir) || samePath2(entry, asFile)) {
|
|
11310
11538
|
if (!pathPresent2(entry)) return null;
|
|
11311
|
-
if (!samePath2(
|
|
11539
|
+
if (!samePath2(dirname8(entry), root)) return null;
|
|
11312
11540
|
if (!isInsideOrSame(root, entry)) return null;
|
|
11313
11541
|
return entry;
|
|
11314
11542
|
}
|
|
@@ -11437,7 +11665,7 @@ function discoverInstructionFiles(options) {
|
|
|
11437
11665
|
}
|
|
11438
11666
|
function descriptionFromSkillMd(path) {
|
|
11439
11667
|
try {
|
|
11440
|
-
const text3 =
|
|
11668
|
+
const text3 = readFileSync5(path, "utf8");
|
|
11441
11669
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
11442
11670
|
if (match === null) return "";
|
|
11443
11671
|
const block = match[1];
|
|
@@ -11488,7 +11716,7 @@ function dirnameLabel(root, projectRoot, env) {
|
|
|
11488
11716
|
if (samePath2(root, join19(projectRoot, ".dsh", "skills"))) return "project-dsh";
|
|
11489
11717
|
if (samePath2(root, join19(agentsHomeOf(env), "skills"))) return "shared";
|
|
11490
11718
|
if (samePath2(root, join19(dshHomeOf(env), "skills"))) return "dsh-home";
|
|
11491
|
-
const parent = basename9(
|
|
11719
|
+
const parent = basename9(dirname9(root)).toLowerCase();
|
|
11492
11720
|
const leaf = basename9(root).toLowerCase();
|
|
11493
11721
|
if (parent === ".cursor" && leaf === "skills") return "cursor";
|
|
11494
11722
|
if (parent === ".cursor" && leaf === "skills-cursor") return "cursor-builtin";
|
|
@@ -11704,14 +11932,14 @@ function parseGitSkillSource(raw) {
|
|
|
11704
11932
|
import { execFile as execFile3, spawn } from "node:child_process";
|
|
11705
11933
|
import { existsSync as existsSync15, mkdtempSync, realpathSync, rmSync as rmSync4 } from "node:fs";
|
|
11706
11934
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
11707
|
-
import { basename as basename11, dirname as
|
|
11935
|
+
import { basename as basename11, dirname as dirname11, join as join23, resolve as resolve14 } from "node:path";
|
|
11708
11936
|
import { promisify as promisify3 } from "node:util";
|
|
11709
11937
|
|
|
11710
11938
|
// src/host/instructions-skills/github-archive.ts
|
|
11711
11939
|
import { execFile as execFile2 } from "node:child_process";
|
|
11712
11940
|
import {
|
|
11713
11941
|
createWriteStream,
|
|
11714
|
-
mkdirSync as
|
|
11942
|
+
mkdirSync as mkdirSync8,
|
|
11715
11943
|
readdirSync as readdirSync4,
|
|
11716
11944
|
renameSync as renameSync5,
|
|
11717
11945
|
rmSync as rmSync3,
|
|
@@ -11762,7 +11990,7 @@ async function downloadUrl(url, destFile, signal, onBytes) {
|
|
|
11762
11990
|
}
|
|
11763
11991
|
async function extractZip(zipPath, destDir, signal) {
|
|
11764
11992
|
signal.throwIfAborted();
|
|
11765
|
-
|
|
11993
|
+
mkdirSync8(destDir, { recursive: true });
|
|
11766
11994
|
try {
|
|
11767
11995
|
await execFileAsync2("tar", ["-xf", zipPath, "-C", destDir], {
|
|
11768
11996
|
windowsHide: true,
|
|
@@ -11820,10 +12048,10 @@ function archiveCandidates(owner, repo, defaultBranch) {
|
|
|
11820
12048
|
}
|
|
11821
12049
|
async function fetchGithubRepoArchive(options) {
|
|
11822
12050
|
const { owner, repo, workDir, signal, onDownloadProgress, onStage } = options;
|
|
11823
|
-
|
|
12051
|
+
mkdirSync8(workDir, { recursive: true });
|
|
11824
12052
|
const zipPath = join20(workDir, "repo.zip");
|
|
11825
12053
|
const extractDir = join20(workDir, "extract");
|
|
11826
|
-
|
|
12054
|
+
mkdirSync8(extractDir, { recursive: true });
|
|
11827
12055
|
const defaultBranch = await resolveDefaultBranch(owner, repo, signal);
|
|
11828
12056
|
const candidates = archiveCandidates(owner, repo, defaultBranch);
|
|
11829
12057
|
const errors = [];
|
|
@@ -11834,7 +12062,7 @@ async function fetchGithubRepoArchive(options) {
|
|
|
11834
12062
|
try {
|
|
11835
12063
|
rmSync3(zipPath, { force: true });
|
|
11836
12064
|
rmSync3(extractDir, { recursive: true, force: true });
|
|
11837
|
-
|
|
12065
|
+
mkdirSync8(extractDir, { recursive: true });
|
|
11838
12066
|
const detail = index === 0 ? `${owner}/${repo}` : `${owner}/${repo} \xB7 retry ${index + 1}/${candidates.length}`;
|
|
11839
12067
|
if (!downloadStarted) {
|
|
11840
12068
|
onStage?.("downloading", detail);
|
|
@@ -11878,16 +12106,16 @@ import {
|
|
|
11878
12106
|
cpSync,
|
|
11879
12107
|
existsSync as existsSync14,
|
|
11880
12108
|
lstatSync as lstatSync4,
|
|
11881
|
-
mkdirSync as
|
|
12109
|
+
mkdirSync as mkdirSync9,
|
|
11882
12110
|
readdirSync as readdirSync5,
|
|
11883
|
-
readFileSync as
|
|
12111
|
+
readFileSync as readFileSync6,
|
|
11884
12112
|
renameSync as renameSync6,
|
|
11885
12113
|
symlinkSync
|
|
11886
12114
|
} from "node:fs";
|
|
11887
|
-
import { basename as basename10, dirname as
|
|
12115
|
+
import { basename as basename10, dirname as dirname10, join as join21, resolve as resolve13 } from "node:path";
|
|
11888
12116
|
function frontmatterBlock(path) {
|
|
11889
12117
|
try {
|
|
11890
|
-
const text3 =
|
|
12118
|
+
const text3 = readFileSync6(path, "utf8");
|
|
11891
12119
|
const match = /^---\r?\n([\s\S]*?)\r?\n---/.exec(text3);
|
|
11892
12120
|
return match?.[1] ?? null;
|
|
11893
12121
|
} catch {
|
|
@@ -11953,7 +12181,7 @@ function resolveBundlesFromClone(cloneRoot, subpath) {
|
|
|
11953
12181
|
throw new AuxiliaryError("FILE_NOT_FOUND", `Path not found in repository: ${subpath ?? "."}`);
|
|
11954
12182
|
}
|
|
11955
12183
|
if (base.toLowerCase().endsWith("skill.md") && existsSync14(base)) {
|
|
11956
|
-
const dir =
|
|
12184
|
+
const dir = dirname10(base);
|
|
11957
12185
|
const name2 = directoryBundleName(dir, basename10(dir));
|
|
11958
12186
|
if (!isKebabCaseName(name2)) {
|
|
11959
12187
|
throw new AuxiliaryError("FILE_DENIED", `Skill directory name must be kebab-case: ${name2}`);
|
|
@@ -12027,7 +12255,7 @@ function copySkillTree(source, dest) {
|
|
|
12027
12255
|
}
|
|
12028
12256
|
}
|
|
12029
12257
|
function copySkillTreeAtomic(source, dest, kind) {
|
|
12030
|
-
|
|
12258
|
+
mkdirSync9(dirname10(dest), { recursive: true });
|
|
12031
12259
|
if (kind === "file") {
|
|
12032
12260
|
if (destinationPresent(dest)) removeDestination(dest);
|
|
12033
12261
|
copySkillTree(source, dest);
|
|
@@ -12055,7 +12283,7 @@ function copySkillTreeAtomic(source, dest, kind) {
|
|
|
12055
12283
|
}
|
|
12056
12284
|
}
|
|
12057
12285
|
function linkOrCopy(source, dest, mode, kind) {
|
|
12058
|
-
|
|
12286
|
+
mkdirSync9(dirname10(dest), { recursive: true });
|
|
12059
12287
|
if (mode === "copy") {
|
|
12060
12288
|
copySkillTreeAtomic(source, dest, kind);
|
|
12061
12289
|
return "copy";
|
|
@@ -12093,7 +12321,7 @@ function installBundle(options) {
|
|
|
12093
12321
|
|
|
12094
12322
|
// src/host/instructions-skills/content-revision.ts
|
|
12095
12323
|
import { createHash as createHash7 } from "node:crypto";
|
|
12096
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
12324
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync7 } from "node:fs";
|
|
12097
12325
|
import { join as join22, relative as relative3 } from "node:path";
|
|
12098
12326
|
function listRelativeFiles(dir, root) {
|
|
12099
12327
|
const entries = [];
|
|
@@ -12112,7 +12340,7 @@ function contentRevisionOfDir(dir) {
|
|
|
12112
12340
|
const paths = listRelativeFiles(dir, dir).sort();
|
|
12113
12341
|
const aggregate = createHash7("sha256");
|
|
12114
12342
|
for (const relPath of paths) {
|
|
12115
|
-
const contents =
|
|
12343
|
+
const contents = readFileSync7(join22(dir, relPath));
|
|
12116
12344
|
const fileDigest = createHash7("sha256").update(`${relPath}\0`).update(contents).digest();
|
|
12117
12345
|
aggregate.update(fileDigest);
|
|
12118
12346
|
}
|
|
@@ -12530,7 +12758,7 @@ async function checkGithubSkillUpdate(record2, options) {
|
|
|
12530
12758
|
|
|
12531
12759
|
// src/host/instructions-skills/zip-install.ts
|
|
12532
12760
|
import { execFile as execFile4 } from "node:child_process";
|
|
12533
|
-
import { existsSync as existsSync16, mkdirSync as
|
|
12761
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync10, mkdtempSync as mkdtempSync3, realpathSync as realpathSync3, rmSync as rmSync6 } from "node:fs";
|
|
12534
12762
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
12535
12763
|
import { basename as basename12, join as join25, resolve as resolve15 } from "node:path";
|
|
12536
12764
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -12545,7 +12773,7 @@ function tempWorkDir3(prefix) {
|
|
|
12545
12773
|
}
|
|
12546
12774
|
async function extractZipArchive(zipPath, destDir, signal) {
|
|
12547
12775
|
signal.throwIfAborted();
|
|
12548
|
-
|
|
12776
|
+
mkdirSync10(destDir, { recursive: true });
|
|
12549
12777
|
try {
|
|
12550
12778
|
await execFileAsync4("tar", ["-xf", zipPath, "-C", destDir], {
|
|
12551
12779
|
windowsHide: true,
|
|
@@ -12990,7 +13218,7 @@ async function readSkillDocumentNow(options) {
|
|
|
12990
13218
|
options.signal.throwIfAborted();
|
|
12991
13219
|
let text3;
|
|
12992
13220
|
try {
|
|
12993
|
-
text3 =
|
|
13221
|
+
text3 = readFileSync8(absolutePath2, "utf8");
|
|
12994
13222
|
} catch {
|
|
12995
13223
|
throw new AuxiliaryError("FILE_NOT_FOUND", "Skill document not found");
|
|
12996
13224
|
}
|
|
@@ -13129,7 +13357,7 @@ function parseMcpJsonText(jsonText) {
|
|
|
13129
13357
|
}
|
|
13130
13358
|
|
|
13131
13359
|
// src/host/mcp-connectors/install-git.ts
|
|
13132
|
-
import { existsSync as existsSync18, mkdirSync as
|
|
13360
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync11, readFileSync as readFileSync9, renameSync as renameSync7, rmSync as rmSync7 } from "node:fs";
|
|
13133
13361
|
import { join as join28 } from "node:path";
|
|
13134
13362
|
|
|
13135
13363
|
// src/host/mcp-connectors/paths.ts
|
|
@@ -13172,7 +13400,7 @@ function inferStdioFromPackageJson(installDir, override) {
|
|
|
13172
13400
|
};
|
|
13173
13401
|
}
|
|
13174
13402
|
try {
|
|
13175
|
-
const pkg = JSON.parse(
|
|
13403
|
+
const pkg = JSON.parse(readFileSync9(pkgPath, "utf8"));
|
|
13176
13404
|
if (isRecord4(pkg)) {
|
|
13177
13405
|
const bin = pkg.bin;
|
|
13178
13406
|
if (typeof bin === "string" && bin.trim() !== "") {
|
|
@@ -13227,11 +13455,11 @@ async function installMcpServerFromGit(options) {
|
|
|
13227
13455
|
}
|
|
13228
13456
|
removePathRobust(installDir);
|
|
13229
13457
|
}
|
|
13230
|
-
|
|
13458
|
+
mkdirSync11(join28(options.rootDir, "mcp-servers"), { recursive: true });
|
|
13231
13459
|
const staging = `${installDir}.staging.${process.pid}`;
|
|
13232
13460
|
try {
|
|
13233
13461
|
if (existsSync18(staging)) removePathRobust(staging);
|
|
13234
|
-
|
|
13462
|
+
mkdirSync11(staging, { recursive: true });
|
|
13235
13463
|
if (parsed.github === null) {
|
|
13236
13464
|
throw new AuxiliaryError(
|
|
13237
13465
|
"FILE_EDIT_FAILED",
|
|
@@ -13253,7 +13481,7 @@ async function installMcpServerFromGit(options) {
|
|
|
13253
13481
|
}
|
|
13254
13482
|
contentRoot = nested;
|
|
13255
13483
|
}
|
|
13256
|
-
|
|
13484
|
+
mkdirSync11(join28(options.rootDir, "mcp-servers"), { recursive: true });
|
|
13257
13485
|
if (contentRoot !== repoDir) {
|
|
13258
13486
|
const nestedStaging = `${installDir}.nested.${process.pid}`;
|
|
13259
13487
|
renameSync7(contentRoot, nestedStaging);
|
|
@@ -13519,8 +13747,8 @@ async function probeMcpConnectorNow(host, request, signal) {
|
|
|
13519
13747
|
}
|
|
13520
13748
|
|
|
13521
13749
|
// src/host/mcp-connectors/store.ts
|
|
13522
|
-
import { mkdirSync as
|
|
13523
|
-
import { dirname as
|
|
13750
|
+
import { mkdirSync as mkdirSync12, readFileSync as readFileSync10, renameSync as renameSync8, writeFileSync as writeFileSync6 } from "node:fs";
|
|
13751
|
+
import { dirname as dirname12 } from "node:path";
|
|
13524
13752
|
|
|
13525
13753
|
// src/host/mcp-connectors/types.ts
|
|
13526
13754
|
var MCP_CONNECTORS_VERSION = 1;
|
|
@@ -13602,13 +13830,13 @@ function parseDoc2(raw) {
|
|
|
13602
13830
|
}
|
|
13603
13831
|
}
|
|
13604
13832
|
function createMcpConnectorsStore(rootDir) {
|
|
13605
|
-
|
|
13833
|
+
mkdirSync12(rootDir, { recursive: true });
|
|
13606
13834
|
const file = mcpConnectorsLedgerPath(rootDir);
|
|
13607
13835
|
return {
|
|
13608
13836
|
rootDir,
|
|
13609
13837
|
load() {
|
|
13610
13838
|
try {
|
|
13611
|
-
return parseDoc2(
|
|
13839
|
+
return parseDoc2(readFileSync10(file, "utf8"));
|
|
13612
13840
|
} catch (error) {
|
|
13613
13841
|
const code = error !== null && typeof error === "object" ? String(Reflect.get(error, "code") ?? "") : "";
|
|
13614
13842
|
if (code !== "ENOENT") {
|
|
@@ -13621,9 +13849,9 @@ function createMcpConnectorsStore(rootDir) {
|
|
|
13621
13849
|
version: MCP_CONNECTORS_VERSION,
|
|
13622
13850
|
connectors: [...connectors]
|
|
13623
13851
|
};
|
|
13624
|
-
|
|
13852
|
+
mkdirSync12(dirname12(file), { recursive: true });
|
|
13625
13853
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
13626
|
-
|
|
13854
|
+
writeFileSync6(tmp, `${JSON.stringify(doc, null, 2)}
|
|
13627
13855
|
`, "utf8");
|
|
13628
13856
|
renameSync8(tmp, file);
|
|
13629
13857
|
return doc;
|
|
@@ -16601,7 +16829,9 @@ var browserAgentSnapshotSchema = z4.strictObject({
|
|
|
16601
16829
|
/** Demonstration recorder: switch state and whether it is recording now. */
|
|
16602
16830
|
demo: z4.strictObject({
|
|
16603
16831
|
enabled: z4.boolean(),
|
|
16604
|
-
recording: z4.boolean()
|
|
16832
|
+
recording: z4.boolean(),
|
|
16833
|
+
/** Steps from the last finished recording, whoever stopped it. */
|
|
16834
|
+
lastSteps: z4.number().int()
|
|
16605
16835
|
}),
|
|
16606
16836
|
tabConflict: browserAgentTabConflictSchema.nullable(),
|
|
16607
16837
|
needsHuman: browserAgentNeedsHumanSchema.nullable(),
|
|
@@ -16651,6 +16881,38 @@ var browserAgentThumbnailResultCodec = codec(
|
|
|
16651
16881
|
"dsh-agent-enhancer#BrowserAgentThumbnailResult",
|
|
16652
16882
|
browserAgentThumbnailResultSchema
|
|
16653
16883
|
);
|
|
16884
|
+
var demoRecipeMetaSchema = z4.strictObject({
|
|
16885
|
+
id: z4.string().min(1),
|
|
16886
|
+
name: z4.string().min(1),
|
|
16887
|
+
createdAt: z4.number(),
|
|
16888
|
+
updatedAt: z4.number(),
|
|
16889
|
+
steps: z4.number().int()
|
|
16890
|
+
});
|
|
16891
|
+
var browserAgentDemoRecipesRequestSchema = z4.discriminatedUnion("action", [
|
|
16892
|
+
z4.strictObject({ action: z4.literal("list") }),
|
|
16893
|
+
z4.strictObject({ action: z4.literal("save"), name: z4.string() }),
|
|
16894
|
+
z4.strictObject({ action: z4.literal("run"), id: z4.string().min(1) }),
|
|
16895
|
+
z4.strictObject({ action: z4.literal("delete"), id: z4.string().min(1) })
|
|
16896
|
+
]);
|
|
16897
|
+
var browserAgentDemoRecipesRequestCodec = codec(
|
|
16898
|
+
"dsh-agent-enhancer#BrowserAgentDemoRecipesRequest",
|
|
16899
|
+
browserAgentDemoRecipesRequestSchema
|
|
16900
|
+
);
|
|
16901
|
+
var browserAgentDemoRecipesResultSchema = z4.strictObject({
|
|
16902
|
+
ok: z4.boolean(),
|
|
16903
|
+
recipes: z4.array(demoRecipeMetaSchema).optional(),
|
|
16904
|
+
recipe: demoRecipeMetaSchema.optional(),
|
|
16905
|
+
/** Replay lines when running a recipe (`1. ok …`). */
|
|
16906
|
+
lines: z4.array(z4.string()).optional(),
|
|
16907
|
+
/** 1-based step where a replay stopped. */
|
|
16908
|
+
stoppedAt: z4.number().int().optional(),
|
|
16909
|
+
reason: z4.string().optional(),
|
|
16910
|
+
error: z4.string().optional()
|
|
16911
|
+
});
|
|
16912
|
+
var browserAgentDemoRecipesResultCodec = codec(
|
|
16913
|
+
"dsh-agent-enhancer#BrowserAgentDemoRecipesResult",
|
|
16914
|
+
browserAgentDemoRecipesResultSchema
|
|
16915
|
+
);
|
|
16654
16916
|
var browserAgentResolveRequestSchema = z4.strictObject({
|
|
16655
16917
|
id: z4.string().min(1),
|
|
16656
16918
|
decision: browserAgentApprovalDecisionSchema
|
|
@@ -17545,6 +17807,18 @@ var remoteInfo = createTypertRemoteInfo({
|
|
|
17545
17807
|
}],
|
|
17546
17808
|
result: browserAgentSelectTabResultCodec
|
|
17547
17809
|
},
|
|
17810
|
+
"agentEnhancer/browserAgentDemoRecipes": {
|
|
17811
|
+
service: "agentEnhancer",
|
|
17812
|
+
implementation: "browserAgentDemoRecipes",
|
|
17813
|
+
invocation: { kind: "direct" },
|
|
17814
|
+
parameters: [{
|
|
17815
|
+
name: "request",
|
|
17816
|
+
source: "json",
|
|
17817
|
+
codec: browserAgentDemoRecipesRequestCodec,
|
|
17818
|
+
strictCodec: browserAgentDemoRecipesRequestCodec
|
|
17819
|
+
}],
|
|
17820
|
+
result: browserAgentDemoRecipesResultCodec
|
|
17821
|
+
},
|
|
17548
17822
|
"agentEnhancer/browserAgentThumbnail": {
|
|
17549
17823
|
service: "agentEnhancer",
|
|
17550
17824
|
implementation: "browserAgentThumbnail",
|
|
@@ -18389,7 +18663,8 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
18389
18663
|
},
|
|
18390
18664
|
demo: {
|
|
18391
18665
|
enabled: settings.demonstrate,
|
|
18392
|
-
recording: this.browserAgent?.demoActive() === true
|
|
18666
|
+
recording: this.browserAgent?.demoActive() === true,
|
|
18667
|
+
lastSteps: this.browserAgent?.lastDemonstrationSteps() ?? 0
|
|
18393
18668
|
},
|
|
18394
18669
|
diagnosis: diag ?? {
|
|
18395
18670
|
code: settings.enabled ? "idle" : "disabled",
|
|
@@ -19104,6 +19379,25 @@ var AgentEnhancerService = class extends TypertRemoteService {
|
|
|
19104
19379
|
if (thumb === null) return { ok: false, error: "no preview for this approval" };
|
|
19105
19380
|
return { ok: true, mime: thumb.mime, base64: thumb.base64 };
|
|
19106
19381
|
}
|
|
19382
|
+
async browserAgentDemoRecipes(request) {
|
|
19383
|
+
this.assertOwner();
|
|
19384
|
+
const runtime = this.browserAgent;
|
|
19385
|
+
if (runtime === null) return { ok: false, error: "runtime unavailable" };
|
|
19386
|
+
const result = await runtime.demoRecipes({
|
|
19387
|
+
action: request.action,
|
|
19388
|
+
..."name" in request ? { name: request.name } : {},
|
|
19389
|
+
..."id" in request ? { id: request.id } : {}
|
|
19390
|
+
});
|
|
19391
|
+
return {
|
|
19392
|
+
ok: result.ok,
|
|
19393
|
+
...result.recipes === void 0 ? {} : { recipes: result.recipes.map((recipe) => ({ ...recipe })) },
|
|
19394
|
+
...result.recipe === void 0 ? {} : { recipe: { ...result.recipe } },
|
|
19395
|
+
...result.lines === void 0 ? {} : { lines: [...result.lines] },
|
|
19396
|
+
...result.stoppedAt === void 0 ? {} : { stoppedAt: result.stoppedAt },
|
|
19397
|
+
...result.reason === void 0 ? {} : { reason: result.reason },
|
|
19398
|
+
...result.error === void 0 ? {} : { error: result.error }
|
|
19399
|
+
};
|
|
19400
|
+
}
|
|
19107
19401
|
async browserAgentDemo(request) {
|
|
19108
19402
|
this.assertOwner();
|
|
19109
19403
|
if (request.action === "start") {
|
|
@@ -19141,7 +19435,7 @@ function resolveCheckpointRoot(dshHome2) {
|
|
|
19141
19435
|
const next = join30(nextPkg, "checkpoint");
|
|
19142
19436
|
const prev = join30(base, LEGACY_PACKAGE_NAME, "checkpoint");
|
|
19143
19437
|
if (!existsSync20(next) && existsSync20(prev)) {
|
|
19144
|
-
|
|
19438
|
+
mkdirSync13(nextPkg, { recursive: true });
|
|
19145
19439
|
renameSync9(prev, next);
|
|
19146
19440
|
const prevPkg = join30(base, LEGACY_PACKAGE_NAME);
|
|
19147
19441
|
try {
|
|
@@ -19310,6 +19604,7 @@ function apply(ctx, config) {
|
|
|
19310
19604
|
debugTools: () => settings().browserAgentDebugTools,
|
|
19311
19605
|
demonstrate: () => settings().browserAgentDemonstrate,
|
|
19312
19606
|
idleClose: () => settings().browserAgentIdleClose,
|
|
19607
|
+
recipes: new DemoRecipeStore(join30(pluginDataPackageRoot, "demo-recipes.json")),
|
|
19313
19608
|
profileRoot: pluginDataPackageRoot,
|
|
19314
19609
|
softPause: softPauseGate,
|
|
19315
19610
|
softPauseEnabled: () => settings().softPauseEnabled,
|