browserpaw 5.0.0 → 5.0.1
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/dist/v5/cli.cjs +1207 -335
- package/dist/v5/extension/background.js +8649 -6972
- package/dist/v5/extension/browserpaw-build.json +52 -45
- package/dist/v5/extension/chunks/{popup-DjxqduQH.js → popup-BSqTH70w.js} +39 -6
- package/dist/v5/extension/content-scripts/agent-cursor.js +30 -14
- package/dist/v5/extension/inject-scripts/accessibility-tree-helper.js +377 -229
- package/dist/v5/extension/inject-scripts/keyboard-helper.js +12 -2
- package/dist/v5/extension/inject-scripts/network-helper.js +166 -1
- package/dist/v5/extension/inject-scripts/screenshot-helper.js +397 -356
- package/dist/v5/extension/inpage-engine.js +7070 -6933
- package/dist/v5/extension/manifest.json +1 -1
- package/dist/v5/extension/popup.html +1 -1
- package/dist/v5/host.cjs +445 -73
- package/dist/v5/recipes/bilibili-popular-videos.json +364 -0
- package/dist/v5/recipes/bilibili-video-detail.json +395 -0
- package/dist/v5/recipes/github-issue-thread.json +313 -0
- package/dist/v5/recipes/github-releases.json +86 -45
- package/dist/v5/recipes/github-repo-readme.json +306 -0
- package/dist/v5/recipes/github-repo-search.json +313 -0
- package/dist/v5/recipes/mdn-search.json +93 -48
- package/dist/v5/recipes/npm-compare.json +6 -4
- package/dist/v5/recipes/reddit-post-read.json +289 -0
- package/dist/v5/recipes/reddit-subreddit-posts.json +331 -0
- package/dist/v5/recipes/v2ex-node-topics.json +334 -0
- package/dist/v5/recipes/v2ex-topic-read.json +325 -0
- package/dist/v5/recipes/x-profile-posts.json +332 -0
- package/dist/v5/recipes/x-search-thread.json +13 -41
- package/dist/v5/recipes/x-visible-thread.json +40 -83
- package/dist/v5/recipes/youtube-search-videos.json +279 -0
- package/dist/v5/recipes/youtube-video-read.json +349 -0
- package/dist/v5/skill/browserpaw/SKILL.md +4 -4
- package/dist/v5/skill/browserpaw/assets/recipes/bilibili-popular-videos.json +364 -0
- package/dist/v5/skill/browserpaw/assets/recipes/bilibili-video-detail.json +395 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-issue-thread.json +313 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-releases.json +86 -45
- package/dist/v5/skill/browserpaw/assets/recipes/github-repo-readme.json +306 -0
- package/dist/v5/skill/browserpaw/assets/recipes/github-repo-search.json +313 -0
- package/dist/v5/skill/browserpaw/assets/recipes/mdn-search.json +93 -48
- package/dist/v5/skill/browserpaw/assets/recipes/npm-compare.json +6 -4
- package/dist/v5/skill/browserpaw/assets/recipes/reddit-post-read.json +289 -0
- package/dist/v5/skill/browserpaw/assets/recipes/reddit-subreddit-posts.json +331 -0
- package/dist/v5/skill/browserpaw/assets/recipes/v2ex-node-topics.json +334 -0
- package/dist/v5/skill/browserpaw/assets/recipes/v2ex-topic-read.json +325 -0
- package/dist/v5/skill/browserpaw/assets/recipes/x-profile-posts.json +332 -0
- package/dist/v5/skill/browserpaw/assets/recipes/x-search-thread.json +13 -41
- package/dist/v5/skill/browserpaw/assets/recipes/x-visible-thread.json +40 -83
- package/dist/v5/skill/browserpaw/assets/recipes/youtube-search-videos.json +279 -0
- package/dist/v5/skill/browserpaw/assets/recipes/youtube-video-read.json +349 -0
- package/dist/v5/skill/browserpaw/references/recipe-contract.md +4 -3
- package/package.json +1 -1
package/dist/v5/host.cjs
CHANGED
|
@@ -9802,6 +9802,8 @@ var schemas = [
|
|
|
9802
9802
|
},
|
|
9803
9803
|
x: { type: "number" },
|
|
9804
9804
|
y: { type: "number" },
|
|
9805
|
+
coordinateSpace: { type: "string", enum: ["viewport", "screenshot"] },
|
|
9806
|
+
captureId: { type: "string" },
|
|
9805
9807
|
at: { type: "number" },
|
|
9806
9808
|
direction: { type: "string", enum: ["up", "down", "left", "right"] },
|
|
9807
9809
|
amount: { type: "number" },
|
|
@@ -9849,6 +9851,8 @@ var schemas = [
|
|
|
9849
9851
|
quiescenceTimeoutMs: { type: "number" },
|
|
9850
9852
|
includeDelta: { type: "boolean" },
|
|
9851
9853
|
sessionId: { type: "string" },
|
|
9854
|
+
coordinateSpace: { type: "string", enum: ["viewport", "screenshot"] },
|
|
9855
|
+
captureId: { type: "string" },
|
|
9852
9856
|
captureNetwork: CAPTURE_NETWORK_SCHEMA
|
|
9853
9857
|
},
|
|
9854
9858
|
required: ["actions"]
|
|
@@ -9976,7 +9980,7 @@ var GITHUB_REPO_OWNER = "GoldenLoaf24h";
|
|
|
9976
9980
|
var GITHUB_REPO_NAME = "browserpaw";
|
|
9977
9981
|
var GITHUB_REPO_URL = `https://github.com/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}`;
|
|
9978
9982
|
var GITHUB_API_LATEST_RELEASE_URL = `https://api.github.com/repos/${GITHUB_REPO_OWNER}/${GITHUB_REPO_NAME}/releases/latest`;
|
|
9979
|
-
var CURRENT_VERSION = "5.0.
|
|
9983
|
+
var CURRENT_VERSION = "5.0.1";
|
|
9980
9984
|
var DEFAULT_CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
9981
9985
|
var DEFAULT_MAX_SLIDING_WINDOW_MS = 24 * 60 * 60 * 1e3;
|
|
9982
9986
|
var MemoryVersionCacheStorage = class {
|
|
@@ -13274,13 +13278,33 @@ var fs6 = __toESM(require("fs"));
|
|
|
13274
13278
|
var import_ajv = __toESM(require_ajv());
|
|
13275
13279
|
var import_ajv_formats = __toESM(require_dist());
|
|
13276
13280
|
var ajv = (0, import_ajv_formats.default)(new import_ajv.default({ strict: false, validateSchema: false, allErrors: true }));
|
|
13281
|
+
var defaultingAjv = (0, import_ajv_formats.default)(
|
|
13282
|
+
new import_ajv.default({ strict: false, validateSchema: false, allErrors: true, useDefaults: true })
|
|
13283
|
+
);
|
|
13284
|
+
var compiledValidators = /* @__PURE__ */ new WeakMap();
|
|
13285
|
+
var compiledDefaultingValidators = /* @__PURE__ */ new WeakMap();
|
|
13286
|
+
function compileCached(instance, cache, schema) {
|
|
13287
|
+
let validate = cache.get(schema);
|
|
13288
|
+
if (!validate) {
|
|
13289
|
+
validate = instance.compile(schema);
|
|
13290
|
+
cache.set(schema, validate);
|
|
13291
|
+
}
|
|
13292
|
+
return validate;
|
|
13293
|
+
}
|
|
13277
13294
|
var validator = {
|
|
13278
13295
|
getValidator(schema) {
|
|
13279
|
-
const validate = ajv
|
|
13296
|
+
const validate = compileCached(ajv, compiledValidators, schema);
|
|
13280
13297
|
return (value) => ({
|
|
13281
13298
|
valid: validate(value),
|
|
13282
13299
|
errorMessage: ajv.errorsText(validate.errors)
|
|
13283
13300
|
});
|
|
13301
|
+
},
|
|
13302
|
+
getDefaultingValidator(schema) {
|
|
13303
|
+
const validate = compileCached(defaultingAjv, compiledDefaultingValidators, schema);
|
|
13304
|
+
return (value) => ({
|
|
13305
|
+
valid: validate(value),
|
|
13306
|
+
errorMessage: defaultingAjv.errorsText(validate.errors)
|
|
13307
|
+
});
|
|
13284
13308
|
}
|
|
13285
13309
|
};
|
|
13286
13310
|
|
|
@@ -14457,8 +14481,18 @@ var BrowserTaskManager = class {
|
|
|
14457
14481
|
}
|
|
14458
14482
|
let committed;
|
|
14459
14483
|
try {
|
|
14460
|
-
|
|
14461
|
-
|
|
14484
|
+
let inventory = await this.readInventory(sessionId);
|
|
14485
|
+
let observed = inventory.tabs.find((tab) => tab.tabId === tabId);
|
|
14486
|
+
if (this.isInitialOpenNavigationPending(observed)) {
|
|
14487
|
+
inventory = await this.waitForInitialOpenNavigation(
|
|
14488
|
+
tabId,
|
|
14489
|
+
inventory,
|
|
14490
|
+
sessionId,
|
|
14491
|
+
() => this.requireTask(taskId).status === "cancelled",
|
|
14492
|
+
signal
|
|
14493
|
+
);
|
|
14494
|
+
observed = inventory.tabs.find((tab) => tab.tabId === tabId);
|
|
14495
|
+
}
|
|
14462
14496
|
if (!observed) {
|
|
14463
14497
|
throw new Error(`Created tab ${tabId} was not observed in browser inventory`);
|
|
14464
14498
|
}
|
|
@@ -15156,6 +15190,41 @@ var BrowserTaskManager = class {
|
|
|
15156
15190
|
};
|
|
15157
15191
|
});
|
|
15158
15192
|
}
|
|
15193
|
+
isInitialOpenNavigationPending(observed) {
|
|
15194
|
+
return Boolean(
|
|
15195
|
+
observed && observed.isAgentManaged === true && observed.status?.toLowerCase() === "loading" && typeof observed.pendingUrl === "string" && observed.pendingUrl.length > 0
|
|
15196
|
+
);
|
|
15197
|
+
}
|
|
15198
|
+
async waitForInitialOpenNavigation(tabId, initial, sessionId, isCancelled, signal) {
|
|
15199
|
+
const controller = new AbortController();
|
|
15200
|
+
const forwardAbort = () => controller.abort();
|
|
15201
|
+
signal?.addEventListener("abort", forwardAbort, { once: true });
|
|
15202
|
+
if (signal?.aborted) controller.abort();
|
|
15203
|
+
const deadline = Date.now() + DELAYED_NAVIGATION_TIMEOUT_MS;
|
|
15204
|
+
let inventory = initial;
|
|
15205
|
+
try {
|
|
15206
|
+
while (!isCancelled() && !controller.signal.aborted) {
|
|
15207
|
+
const remaining = deadline - Date.now();
|
|
15208
|
+
if (remaining <= 0) return inventory;
|
|
15209
|
+
await this.waitForDelayedNavigationPoll(
|
|
15210
|
+
Math.min(DELAYED_NAVIGATION_POLL_MS, remaining),
|
|
15211
|
+
controller.signal
|
|
15212
|
+
);
|
|
15213
|
+
if (isCancelled() || controller.signal.aborted) return inventory;
|
|
15214
|
+
const read = await this.readInventoryBeforeDeadline(sessionId, controller.signal, deadline);
|
|
15215
|
+
if (read.kind === "stopped") return inventory;
|
|
15216
|
+
if (read.kind === "error") throw read.error;
|
|
15217
|
+
inventory = read.inventory;
|
|
15218
|
+
const observed = inventory.tabs.find((candidate) => candidate.tabId === tabId);
|
|
15219
|
+
if (!observed || inventory.browserInstanceId !== initial.browserInstanceId || observed.browserInstanceId !== initial.browserInstanceId || !this.isInitialOpenNavigationPending(observed)) {
|
|
15220
|
+
return inventory;
|
|
15221
|
+
}
|
|
15222
|
+
}
|
|
15223
|
+
return inventory;
|
|
15224
|
+
} finally {
|
|
15225
|
+
signal?.removeEventListener("abort", forwardAbort);
|
|
15226
|
+
}
|
|
15227
|
+
}
|
|
15159
15228
|
isDelayedNavigationLoading(inventory, page) {
|
|
15160
15229
|
const observed = inventory.tabs.find((candidate) => candidate.tabId === page.tabId);
|
|
15161
15230
|
return Boolean(
|
|
@@ -15768,11 +15837,78 @@ function programHash(code) {
|
|
|
15768
15837
|
}
|
|
15769
15838
|
var DOM_EXTRACTION_PROGRAM_HASH = programHash(DOM_EXTRACTION_PROGRAM);
|
|
15770
15839
|
var PUBLISHED_READ_ONLY_PROGRAMS = Object.freeze({
|
|
15771
|
-
"
|
|
15772
|
-
"
|
|
15773
|
-
"
|
|
15774
|
-
"
|
|
15775
|
-
"
|
|
15840
|
+
"bilibili-popular-videos": "9365eeb13a6dd90bb5114282b92381b5cf5e9865a2778c1cce276924cf2d35f1",
|
|
15841
|
+
"bilibili-video-detail": "940f9aaeb008fbf3f1d3180cb60c6b0efd6588d74dfbca4cd1384b0a225f94b7",
|
|
15842
|
+
"github-issue-thread": "4e2e21ce0247a08544fd7a8ca0bce3ee84cf2e06c0086f02d9e2488b81cb05ef",
|
|
15843
|
+
"github-releases": "34bee85d1ab7184f5a065dc61a8faf57e680681f0dd6fb23917bdeb8a6e5b8cd",
|
|
15844
|
+
"github-repo-readme": "55d7de67ff423593ce21c586f0650043a50b10b60abe86d2d4835982c91c872f",
|
|
15845
|
+
"github-repo-search": "dcd573dbcf66e4071186c4a69c226af984f095cac13ce5f2aca974016fe871f2",
|
|
15846
|
+
"mdn-search": "1ff226134f13fd1b923623887628b96256d51c9535a08f5c3df3a19a5ebb02ad",
|
|
15847
|
+
"npm-compare": "5785a9129d5c88e4df8a8b25745fa095e163b91eb1ee0477f58081e8a9329401",
|
|
15848
|
+
"reddit-post-read": "a8db61c52d2246b417374436cab2867cf51082c73d45102040ceaec2d8264cbf",
|
|
15849
|
+
"reddit-subreddit-posts": "cc9dc138b60209908aab7cb49205321ce59f480f6d744e8938e444dc230f2d0b",
|
|
15850
|
+
"v2ex-node-topics": "ab6b30af79f295bae137b928a6284574f58858c63dcd3e84f597d9dda7ae11b3",
|
|
15851
|
+
"v2ex-topic-read": "ee9ae86e6881e38a540d9efc51fd7282dd069195a33e700d3ae786122140b5c2",
|
|
15852
|
+
"x-profile-posts": "fb0869522e1aff847a4a70c124bd42712107bb3ba2b1d061073e2faa55e41064",
|
|
15853
|
+
"x-search-thread": "59fb2cd25479f332563c217bad8722c388967864bc056dd6f98e970ce11d6c11",
|
|
15854
|
+
"x-visible-thread": "9db24745e0451e22390001e825e9fd6a229d461d52383b8caa19bea6ebc0f710",
|
|
15855
|
+
"youtube-search-videos": "4a4e2a8b5316920c1229815a926921527b85dd9bc0388b9dcb9708fca0d5a9c0",
|
|
15856
|
+
"youtube-video-read": "b0c33f1c76499c2913461e553466a8ff648094990b8677631239b6fe5b11ace5"
|
|
15857
|
+
});
|
|
15858
|
+
var PREVIOUS_PUBLISHED_READ_ONLY_PROGRAMS = Object.freeze({
|
|
15859
|
+
"bilibili-popular-videos": Object.freeze([
|
|
15860
|
+
"450dc01c9a427ccd7ec17c1422983b1fa8b00e87f33118c30f4763bd737943d3"
|
|
15861
|
+
]),
|
|
15862
|
+
"bilibili-video-detail": Object.freeze([
|
|
15863
|
+
"d2da238b495b8980d072cdc380f9f637d20487cc847e543d66780e0bb8ec88b2"
|
|
15864
|
+
]),
|
|
15865
|
+
"github-issue-thread": Object.freeze([
|
|
15866
|
+
"384e5adeab48a56892583d00d96db6f6af6a53c70aa3e13f9b0ed4e4423cde70"
|
|
15867
|
+
]),
|
|
15868
|
+
"github-releases": Object.freeze([
|
|
15869
|
+
"f629eb72cf3c97505029d424eb60b65e8236b331f9a5f30a4556fd64cec34ad4"
|
|
15870
|
+
]),
|
|
15871
|
+
"github-repo-readme": Object.freeze([
|
|
15872
|
+
"f9fc48e7f46d395e9eadc5ec6ac0f89f97a232ed0d4c5e47ecda16d78d09df67"
|
|
15873
|
+
]),
|
|
15874
|
+
"github-repo-search": Object.freeze([
|
|
15875
|
+
"12e93f0ca4606fcc825b983bbdc00e68e1a873a36649277d838ec15abe3f48ec"
|
|
15876
|
+
]),
|
|
15877
|
+
"mdn-search": Object.freeze([
|
|
15878
|
+
"533aa263b275356f18068c86d6cb1f240412f4a4dc2866fb9c5a58065cb6f17f"
|
|
15879
|
+
]),
|
|
15880
|
+
"npm-compare": Object.freeze([
|
|
15881
|
+
"ead55b7b52e965c16e9902c916306f955a259ee860a78fd66981909f18e9436e"
|
|
15882
|
+
]),
|
|
15883
|
+
"reddit-post-read": Object.freeze([
|
|
15884
|
+
"e40f0b8e5f99607b7ef691cfd98985500d31b82edee0d3c942ed87d0a63de8e3",
|
|
15885
|
+
"ef4f788eaeee0fe5ca33db705d6331726ad4cf6d739e4ab60972d949e35544b2"
|
|
15886
|
+
]),
|
|
15887
|
+
"reddit-subreddit-posts": Object.freeze([
|
|
15888
|
+
"789f71122d0772072cda01d718ed29f97dfbeb49f84643b1935972e9013e75b3"
|
|
15889
|
+
]),
|
|
15890
|
+
"v2ex-node-topics": Object.freeze([
|
|
15891
|
+
"a5dfb4036c8107c02a58e61d29af7f1d86c3a59f5969d3b0d45221e6c913f95b"
|
|
15892
|
+
]),
|
|
15893
|
+
"v2ex-topic-read": Object.freeze([
|
|
15894
|
+
"9477b4a08c9debbdf09c02d2a546bf4d958c24ddfd2bd65e941569b5dc4954fb"
|
|
15895
|
+
]),
|
|
15896
|
+
"x-profile-posts": Object.freeze([
|
|
15897
|
+
"f4fed984860f39f7c28f798df0a878c1224a8a0b3551834f72f02eff9d244b14",
|
|
15898
|
+
"0df6ed3703aec5713946014de767236c67bddce4092ea1c9426d647c21a7bdb2"
|
|
15899
|
+
]),
|
|
15900
|
+
"x-search-thread": Object.freeze([
|
|
15901
|
+
"f92986d0c7d618296abcb4d9234dd0fcda17ab10674c7d2c1f9b1411331e8dc6"
|
|
15902
|
+
]),
|
|
15903
|
+
"x-visible-thread": Object.freeze([
|
|
15904
|
+
"0ca61ddfb91bc18c7edd2ad209a485923ac2fc4c4c9a326977c06b64e014b145"
|
|
15905
|
+
]),
|
|
15906
|
+
"youtube-search-videos": Object.freeze([
|
|
15907
|
+
"f5aa24d95aac9610b541590106bef037ec7833cd43f1f69ec4f1974977bf0a01"
|
|
15908
|
+
]),
|
|
15909
|
+
"youtube-video-read": Object.freeze([
|
|
15910
|
+
"86ed74b0ee1a335be453bb71250cf8bccb6b1c0f8c504f8316d21ef220c696fe"
|
|
15911
|
+
])
|
|
15776
15912
|
});
|
|
15777
15913
|
|
|
15778
15914
|
// src/browser-skills.ts
|
|
@@ -15797,6 +15933,10 @@ function check(schema, value, label) {
|
|
|
15797
15933
|
const result = validator.getValidator(schema)(value);
|
|
15798
15934
|
if (!result.valid) throw new SkillContractError(`${label}: ${result.errorMessage}`);
|
|
15799
15935
|
}
|
|
15936
|
+
function checkWithDefaults(schema, value, label) {
|
|
15937
|
+
const result = validator.getDefaultingValidator(schema)(value);
|
|
15938
|
+
if (!result.valid) throw new SkillContractError(`${label}: ${result.errorMessage}`);
|
|
15939
|
+
}
|
|
15800
15940
|
function assertNoCredentials(value) {
|
|
15801
15941
|
if (!value || typeof value !== "object") return;
|
|
15802
15942
|
for (const [key, item] of Object.entries(value)) {
|
|
@@ -15956,15 +16096,35 @@ var BrowserSkillStore = class {
|
|
|
15956
16096
|
constructor(options) {
|
|
15957
16097
|
this.running = /* @__PURE__ */ new Set();
|
|
15958
16098
|
this.executions = /* @__PURE__ */ new Map();
|
|
16099
|
+
this.validating = /* @__PURE__ */ new Map();
|
|
15959
16100
|
this.approvedPrograms = /* @__PURE__ */ new Set([DOM_EXTRACTION_PROGRAM_HASH]);
|
|
16101
|
+
this.bundledDefinitionHashes = /* @__PURE__ */ new Map();
|
|
15960
16102
|
this.root = path5.resolve(
|
|
15961
16103
|
options.root || path5.join(process.env.BROWSERPAW_HOME || path5.join(os4.homedir(), ".browserpaw"), "skills")
|
|
15962
16104
|
);
|
|
15963
16105
|
this.browser = options.browser;
|
|
16106
|
+
this.publishedPrograms = options.publishedPrograms ?? PUBLISHED_READ_ONLY_PROGRAMS;
|
|
16107
|
+
this.previousPublishedPrograms = options.previousPublishedPrograms ?? PREVIOUS_PUBLISHED_READ_ONLY_PROGRAMS;
|
|
15964
16108
|
fs5.mkdirSync(this.root, { recursive: true });
|
|
15965
16109
|
if (fs5.lstatSync(this.root).isSymbolicLink())
|
|
15966
16110
|
throw new Error("Skill directory cannot be a symbolic link");
|
|
15967
16111
|
}
|
|
16112
|
+
approvedProgramsFor(definition, allowVerifiedBuiltin = false) {
|
|
16113
|
+
if (!allowVerifiedBuiltin || definition.source?.type !== "builtin") {
|
|
16114
|
+
return this.approvedPrograms;
|
|
16115
|
+
}
|
|
16116
|
+
const currentPublished = this.publishedPrograms[definition.id];
|
|
16117
|
+
const previousPublished = this.previousPublishedPrograms[definition.id];
|
|
16118
|
+
if (!currentPublished && (!previousPublished || previousPublished.length === 0)) {
|
|
16119
|
+
return this.approvedPrograms;
|
|
16120
|
+
}
|
|
16121
|
+
const allowed = new Set(this.approvedPrograms);
|
|
16122
|
+
if (currentPublished) allowed.add(currentPublished);
|
|
16123
|
+
if (previousPublished) {
|
|
16124
|
+
for (const digest of previousPublished) allowed.add(digest);
|
|
16125
|
+
}
|
|
16126
|
+
return allowed;
|
|
16127
|
+
}
|
|
15968
16128
|
resolveProgramStep(step, approvedPrograms = this.approvedPrograms) {
|
|
15969
16129
|
const hasCode = Object.prototype.hasOwnProperty.call(step.args, "code");
|
|
15970
16130
|
const hasProgram = Object.prototype.hasOwnProperty.call(step.args, "program");
|
|
@@ -16081,7 +16241,10 @@ var BrowserSkillStore = class {
|
|
|
16081
16241
|
);
|
|
16082
16242
|
if (!version) return [];
|
|
16083
16243
|
try {
|
|
16084
|
-
this.assertSupportedDefinition(
|
|
16244
|
+
this.assertSupportedDefinition(
|
|
16245
|
+
version.definition,
|
|
16246
|
+
this.approvedProgramsFor(version.definition, true)
|
|
16247
|
+
);
|
|
16085
16248
|
return [this.summary(record, version)];
|
|
16086
16249
|
} catch {
|
|
16087
16250
|
return [];
|
|
@@ -16140,24 +16303,65 @@ var BrowserSkillStore = class {
|
|
|
16140
16303
|
diagnostics: { strategy: "keyword", reason: "ambiguous_keywords" }
|
|
16141
16304
|
}));
|
|
16142
16305
|
}
|
|
16306
|
+
findAutoUpdatableBundledCandidate(record) {
|
|
16307
|
+
const bundledHash = this.bundledDefinitionHashes.get(record.id);
|
|
16308
|
+
if (!bundledHash) return void 0;
|
|
16309
|
+
if (record.autoUpdatePolicy === "disabled" || record.autoUpdatePolicy === "pinned") {
|
|
16310
|
+
return void 0;
|
|
16311
|
+
}
|
|
16312
|
+
const active = record.versions.find(
|
|
16313
|
+
(item) => item.version === record.activeVersion && item.status === "active"
|
|
16314
|
+
);
|
|
16315
|
+
if (active) {
|
|
16316
|
+
if (active.hash === bundledHash) return void 0;
|
|
16317
|
+
if (active.definition.source.type !== "builtin") return void 0;
|
|
16318
|
+
if (record.versions.some(
|
|
16319
|
+
(item) => item.version > active.version && (item.status === "verified" || item.status === "disabled")
|
|
16320
|
+
)) {
|
|
16321
|
+
return void 0;
|
|
16322
|
+
}
|
|
16323
|
+
} else {
|
|
16324
|
+
if (record.versions.some((item) => item.status === "disabled")) return void 0;
|
|
16325
|
+
if (record.versions.some((item) => item.definition.source.type !== "builtin")) {
|
|
16326
|
+
return void 0;
|
|
16327
|
+
}
|
|
16328
|
+
}
|
|
16329
|
+
const candidate = [...record.versions].reverse().find(
|
|
16330
|
+
(item) => item.status === "candidate" && item.hash === bundledHash && item.definition.source.type === "builtin"
|
|
16331
|
+
);
|
|
16332
|
+
if (!candidate) return void 0;
|
|
16333
|
+
if (active && candidate.version <= active.version) return void 0;
|
|
16334
|
+
try {
|
|
16335
|
+
this.assertSupportedDefinition(candidate.definition);
|
|
16336
|
+
} catch {
|
|
16337
|
+
return void 0;
|
|
16338
|
+
}
|
|
16339
|
+
return { version: candidate.version, hash: candidate.hash };
|
|
16340
|
+
}
|
|
16143
16341
|
get(id, requestedVersion) {
|
|
16144
16342
|
const record = this.read(id);
|
|
16145
16343
|
const version = record.versions.find(
|
|
16146
16344
|
(item) => item.version === (requestedVersion ?? record.activeVersion ?? record.versions[record.versions.length - 1]?.version)
|
|
16147
16345
|
);
|
|
16148
16346
|
if (!version) throw new Error("No matching verified skill version");
|
|
16347
|
+
const allowVerifiedBuiltin = version.status === "active" || version.status === "verified" && Boolean(version.verifiedAt);
|
|
16149
16348
|
let executionSupported = true;
|
|
16150
16349
|
let unsupportedReason;
|
|
16151
16350
|
try {
|
|
16152
|
-
this.assertSupportedDefinition(
|
|
16351
|
+
this.assertSupportedDefinition(
|
|
16352
|
+
version.definition,
|
|
16353
|
+
this.approvedProgramsFor(version.definition, allowVerifiedBuiltin)
|
|
16354
|
+
);
|
|
16153
16355
|
} catch (error) {
|
|
16154
16356
|
executionSupported = false;
|
|
16155
16357
|
unsupportedReason = error instanceof Error ? error.message : String(error);
|
|
16156
16358
|
}
|
|
16359
|
+
const pendingBundledCandidate = requestedVersion === void 0 ? this.findAutoUpdatableBundledCandidate(record) : void 0;
|
|
16157
16360
|
return {
|
|
16158
16361
|
...this.summary(record, version),
|
|
16159
16362
|
executionSupported,
|
|
16160
16363
|
...unsupportedReason ? { unsupportedReason } : {},
|
|
16364
|
+
...pendingBundledCandidate ? { pendingBundledCandidate } : {},
|
|
16161
16365
|
definition: version.definition,
|
|
16162
16366
|
evidence: version.evidence
|
|
16163
16367
|
};
|
|
@@ -16201,7 +16405,7 @@ var BrowserSkillStore = class {
|
|
|
16201
16405
|
approved.add(digest);
|
|
16202
16406
|
continue;
|
|
16203
16407
|
}
|
|
16204
|
-
const publishedHash =
|
|
16408
|
+
const publishedHash = this.publishedPrograms[definition.id];
|
|
16205
16409
|
if (publishedHash !== digest) {
|
|
16206
16410
|
unsupported(
|
|
16207
16411
|
`Unsupported bundled skill ${definition.id}: JavaScript is not a locally reviewed published program`
|
|
@@ -16212,11 +16416,27 @@ var BrowserSkillStore = class {
|
|
|
16212
16416
|
this.assertSupportedDefinition(definition, approved);
|
|
16213
16417
|
}
|
|
16214
16418
|
for (const digest of approved) this.approvedPrograms.add(digest);
|
|
16419
|
+
const nextBundledHashes = /* @__PURE__ */ new Map();
|
|
16215
16420
|
for (const definition of definitions) {
|
|
16421
|
+
const digest = hash(definition);
|
|
16422
|
+
if (definition.source?.type === "builtin") {
|
|
16423
|
+
nextBundledHashes.set(definition.id, digest);
|
|
16424
|
+
}
|
|
16216
16425
|
const target = this.filename(definition.id);
|
|
16217
|
-
if (
|
|
16218
|
-
|
|
16426
|
+
if (fs5.existsSync(target)) {
|
|
16427
|
+
const existing = this.read(definition.id);
|
|
16428
|
+
const active = existing.versions.find(
|
|
16429
|
+
(item) => item.version === existing.activeVersion && item.status === "active"
|
|
16430
|
+
);
|
|
16431
|
+
const isUserOwned = active?.definition.source.type === "agent" || existing.versions.length > 0 && existing.versions.every((item) => item.definition.source.type !== "builtin");
|
|
16432
|
+
if (isUserOwned) continue;
|
|
16433
|
+
if (existing.versions.some((item) => item.hash === digest)) continue;
|
|
16219
16434
|
}
|
|
16435
|
+
await this.propose(definition);
|
|
16436
|
+
}
|
|
16437
|
+
this.bundledDefinitionHashes.clear();
|
|
16438
|
+
for (const [id, digest] of nextBundledHashes) {
|
|
16439
|
+
this.bundledDefinitionHashes.set(id, digest);
|
|
16220
16440
|
}
|
|
16221
16441
|
}
|
|
16222
16442
|
async propose(definition) {
|
|
@@ -16245,7 +16465,8 @@ var BrowserSkillStore = class {
|
|
|
16245
16465
|
"Verification requires explicit output and independent observation assertions"
|
|
16246
16466
|
);
|
|
16247
16467
|
}
|
|
16248
|
-
|
|
16468
|
+
const testInputs = test.inputs && typeof test.inputs === "object" && !Array.isArray(test.inputs) ? structuredClone(test.inputs) : test.inputs;
|
|
16469
|
+
checkWithDefaults(definition.inputSchema, testInputs, "input");
|
|
16249
16470
|
validator.getValidator(test.expect);
|
|
16250
16471
|
const observations = Array.isArray(test.observe) ? test.observe : [test.observe];
|
|
16251
16472
|
if (observations.length !== verifications.length)
|
|
@@ -16257,7 +16478,7 @@ var BrowserSkillStore = class {
|
|
|
16257
16478
|
throw new Error("Independent observation must contain a concrete assertion");
|
|
16258
16479
|
validator.getValidator(observation);
|
|
16259
16480
|
}
|
|
16260
|
-
assertDomain(expandUrl(definition.startUrl,
|
|
16481
|
+
assertDomain(expandUrl(definition.startUrl, testInputs), definition);
|
|
16261
16482
|
}
|
|
16262
16483
|
for (const verification of verifications) {
|
|
16263
16484
|
if (!verification || !verification.args || typeof verification.args !== "object" || Array.isArray(verification.args) || !["chrome_read_dom", "chrome_network_request"].includes(verification.tool)) {
|
|
@@ -16325,7 +16546,7 @@ var BrowserSkillStore = class {
|
|
|
16325
16546
|
this.write(record);
|
|
16326
16547
|
return this.summary(record, version);
|
|
16327
16548
|
}
|
|
16328
|
-
async executeVersion(version,
|
|
16549
|
+
async executeVersion(version, rawInputs, callerTaskId, observationSchema, signal, sessionId, approvedPrograms = this.approvedPrograms) {
|
|
16329
16550
|
const checkCancelled = () => {
|
|
16330
16551
|
if (signal?.aborted)
|
|
16331
16552
|
throw Object.assign(new Error("Skill cancelled; dispatched actions were not rolled back"), {
|
|
@@ -16335,8 +16556,9 @@ var BrowserSkillStore = class {
|
|
|
16335
16556
|
};
|
|
16336
16557
|
checkCancelled();
|
|
16337
16558
|
const def = version.definition;
|
|
16338
|
-
this.assertSupportedDefinition(def);
|
|
16339
|
-
|
|
16559
|
+
this.assertSupportedDefinition(def, approvedPrograms);
|
|
16560
|
+
const inputs = rawInputs && typeof rawInputs === "object" && !Array.isArray(rawInputs) ? structuredClone(rawInputs) : rawInputs;
|
|
16561
|
+
checkWithDefaults(def.inputSchema, inputs, "input");
|
|
16340
16562
|
if (!outputContract(def.outputSchema)) {
|
|
16341
16563
|
throw new Error("Skill output contract is no longer valid");
|
|
16342
16564
|
}
|
|
@@ -16355,7 +16577,7 @@ var BrowserSkillStore = class {
|
|
|
16355
16577
|
delete args.config;
|
|
16356
16578
|
delete args.program;
|
|
16357
16579
|
if (step.tool === "chrome_javascript") {
|
|
16358
|
-
const program = this.resolveProgramStep(step);
|
|
16580
|
+
const program = this.resolveProgramStep(step, approvedPrograms);
|
|
16359
16581
|
const runtimeInputs = program.config === void 0 ? inputs : { ...inputs, config: program.config };
|
|
16360
16582
|
args.code = `const input = ${JSON.stringify(runtimeInputs)};
|
|
16361
16583
|
${program.code}`;
|
|
@@ -16421,6 +16643,14 @@ ${program.code}`;
|
|
|
16421
16643
|
return { output, taskId };
|
|
16422
16644
|
}
|
|
16423
16645
|
async validate(id, requestedVersion, signal, sessionId) {
|
|
16646
|
+
if (this.executions.has(id)) throw new Error("Skill is already running");
|
|
16647
|
+
const activeValidation = this.validating.get(id);
|
|
16648
|
+
if (activeValidation) {
|
|
16649
|
+
if (requestedVersion !== void 0 && requestedVersion !== activeValidation.version) {
|
|
16650
|
+
throw new Error("Skill is already running");
|
|
16651
|
+
}
|
|
16652
|
+
return activeValidation.promise;
|
|
16653
|
+
}
|
|
16424
16654
|
if (this.running.has(id) || this.executions.has(id))
|
|
16425
16655
|
throw new Error("Skill is already running");
|
|
16426
16656
|
const record = this.read(id);
|
|
@@ -16429,34 +16659,40 @@ ${program.code}`;
|
|
|
16429
16659
|
throw new Error("Select a candidate skill version");
|
|
16430
16660
|
this.assertSupportedDefinition(version.definition);
|
|
16431
16661
|
this.running.add(id);
|
|
16432
|
-
|
|
16433
|
-
|
|
16434
|
-
|
|
16435
|
-
const
|
|
16436
|
-
|
|
16437
|
-
|
|
16438
|
-
|
|
16439
|
-
|
|
16440
|
-
|
|
16441
|
-
|
|
16442
|
-
|
|
16443
|
-
|
|
16444
|
-
|
|
16445
|
-
|
|
16446
|
-
|
|
16447
|
-
|
|
16448
|
-
|
|
16449
|
-
|
|
16662
|
+
const runValidation = (async () => {
|
|
16663
|
+
try {
|
|
16664
|
+
version.evidence = [];
|
|
16665
|
+
for (const test of version.definition.tests) {
|
|
16666
|
+
const { output, taskId } = await this.executeVersion(
|
|
16667
|
+
version,
|
|
16668
|
+
test.inputs,
|
|
16669
|
+
void 0,
|
|
16670
|
+
test.observe,
|
|
16671
|
+
signal,
|
|
16672
|
+
sessionId
|
|
16673
|
+
);
|
|
16674
|
+
check(test.expect, output, "verification output");
|
|
16675
|
+
version.evidence.push({
|
|
16676
|
+
taskId,
|
|
16677
|
+
inputHash: hash(test.inputs),
|
|
16678
|
+
outputHash: hash(output),
|
|
16679
|
+
at: (/* @__PURE__ */ new Date()).toISOString()
|
|
16680
|
+
});
|
|
16681
|
+
}
|
|
16682
|
+
for (const old of record.versions) if (old.status === "active") old.status = "verified";
|
|
16683
|
+
version.status = "active";
|
|
16684
|
+
version.verifiedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
16685
|
+
record.activeVersion = version.version;
|
|
16686
|
+
delete record.autoUpdatePolicy;
|
|
16687
|
+
this.write(record);
|
|
16688
|
+
return this.summary(record, version);
|
|
16689
|
+
} finally {
|
|
16690
|
+
this.running.delete(id);
|
|
16691
|
+
this.validating.delete(id);
|
|
16450
16692
|
}
|
|
16451
|
-
|
|
16452
|
-
|
|
16453
|
-
|
|
16454
|
-
record.activeVersion = version.version;
|
|
16455
|
-
this.write(record);
|
|
16456
|
-
return this.summary(record, version);
|
|
16457
|
-
} finally {
|
|
16458
|
-
this.running.delete(id);
|
|
16459
|
-
}
|
|
16693
|
+
})();
|
|
16694
|
+
this.validating.set(id, { version: version.version, promise: runValidation });
|
|
16695
|
+
return runValidation;
|
|
16460
16696
|
}
|
|
16461
16697
|
async run(id, inputs, taskId, signal, sessionId, options) {
|
|
16462
16698
|
if (this.running.has(id)) throw new Error("Skill is already running");
|
|
@@ -16489,14 +16725,23 @@ ${program.code}`;
|
|
|
16489
16725
|
}
|
|
16490
16726
|
);
|
|
16491
16727
|
}
|
|
16492
|
-
this.
|
|
16728
|
+
const approved = this.approvedProgramsFor(version.definition, true);
|
|
16729
|
+
this.assertSupportedDefinition(version.definition, approved);
|
|
16493
16730
|
this.executions.set(id, (this.executions.get(id) || 0) + 1);
|
|
16494
16731
|
try {
|
|
16495
16732
|
return {
|
|
16496
16733
|
id,
|
|
16497
16734
|
version: version.version,
|
|
16498
16735
|
hash: version.hash,
|
|
16499
|
-
...await this.executeVersion(
|
|
16736
|
+
...await this.executeVersion(
|
|
16737
|
+
version,
|
|
16738
|
+
inputs,
|
|
16739
|
+
taskId,
|
|
16740
|
+
void 0,
|
|
16741
|
+
signal,
|
|
16742
|
+
sessionId,
|
|
16743
|
+
approved
|
|
16744
|
+
)
|
|
16500
16745
|
};
|
|
16501
16746
|
} catch (error) {
|
|
16502
16747
|
if (error instanceof SkillContractError && !error.message.startsWith("input:")) {
|
|
@@ -16519,6 +16764,7 @@ ${program.code}`;
|
|
|
16519
16764
|
const version = record.versions.find((item) => item.version === record.activeVersion);
|
|
16520
16765
|
if (version) version.status = "disabled";
|
|
16521
16766
|
record.activeVersion = void 0;
|
|
16767
|
+
record.autoUpdatePolicy = "disabled";
|
|
16522
16768
|
this.write(record);
|
|
16523
16769
|
return { id, status: "disabled" };
|
|
16524
16770
|
}
|
|
@@ -16530,10 +16776,14 @@ ${program.code}`;
|
|
|
16530
16776
|
);
|
|
16531
16777
|
if (!target)
|
|
16532
16778
|
throw new Error("Rollback requires an independently verified, non-disabled version");
|
|
16533
|
-
this.assertSupportedDefinition(
|
|
16779
|
+
this.assertSupportedDefinition(
|
|
16780
|
+
target.definition,
|
|
16781
|
+
this.approvedProgramsFor(target.definition, true)
|
|
16782
|
+
);
|
|
16534
16783
|
for (const old of record.versions) if (old.status === "active") old.status = "verified";
|
|
16535
16784
|
target.status = "active";
|
|
16536
16785
|
record.activeVersion = target.version;
|
|
16786
|
+
record.autoUpdatePolicy = "pinned";
|
|
16537
16787
|
this.write(record);
|
|
16538
16788
|
return this.summary(record, target);
|
|
16539
16789
|
}
|
|
@@ -16543,14 +16793,38 @@ ${program.code}`;
|
|
|
16543
16793
|
function resolveBundledRecipesDir() {
|
|
16544
16794
|
const candidates = [
|
|
16545
16795
|
path6.join(__dirname, "recipes"),
|
|
16546
|
-
path6.
|
|
16547
|
-
path6.
|
|
16796
|
+
path6.resolve(__dirname, "..", "..", "..", "skills", "browserpaw", "assets", "recipes"),
|
|
16797
|
+
path6.join(__dirname, "..", "dist", "v5", "recipes"),
|
|
16798
|
+
path6.join(__dirname, "..", "dist", "recipes")
|
|
16548
16799
|
];
|
|
16549
16800
|
const directory = candidates.find((candidate) => fs6.existsSync(candidate));
|
|
16550
16801
|
if (!directory) throw new Error("Bundled BrowserPaw recipes are missing");
|
|
16551
16802
|
return directory;
|
|
16552
16803
|
}
|
|
16553
|
-
function
|
|
16804
|
+
function bundledRecipesVersionMatchesHost(directory) {
|
|
16805
|
+
const versionFile = path6.join(path6.dirname(directory), "host-version.txt");
|
|
16806
|
+
if (!fs6.existsSync(versionFile)) return true;
|
|
16807
|
+
try {
|
|
16808
|
+
const stat = fs6.lstatSync(versionFile);
|
|
16809
|
+
if (stat.isSymbolicLink() || !stat.isFile()) return false;
|
|
16810
|
+
return fs6.readFileSync(versionFile, "utf8").trim() === CURRENT_VERSION;
|
|
16811
|
+
} catch {
|
|
16812
|
+
return false;
|
|
16813
|
+
}
|
|
16814
|
+
}
|
|
16815
|
+
function bundledRecipesSignature(directory) {
|
|
16816
|
+
try {
|
|
16817
|
+
if (fs6.lstatSync(directory).isSymbolicLink()) return "symlink";
|
|
16818
|
+
return fs6.readdirSync(directory).filter((item) => /^[a-z][a-z0-9-]*\.json$/.test(item)).sort().map((name) => {
|
|
16819
|
+
const stat = fs6.lstatSync(path6.join(directory, name));
|
|
16820
|
+
if (stat.isSymbolicLink()) return `${name}:symlink`;
|
|
16821
|
+
return `${name}:${stat.size}:${stat.mtimeMs}`;
|
|
16822
|
+
}).join("|");
|
|
16823
|
+
} catch {
|
|
16824
|
+
return `unreadable:${Date.now()}`;
|
|
16825
|
+
}
|
|
16826
|
+
}
|
|
16827
|
+
function createBrowserServices(call, storageDir, bundledRecipesDir) {
|
|
16554
16828
|
const tasks = new BrowserTaskManager({ call, storageDir });
|
|
16555
16829
|
const requireTask = async (action, args, sessionId, signal) => {
|
|
16556
16830
|
const result = await tasks.execute({ action, ...args }, sessionId, signal);
|
|
@@ -16580,6 +16854,7 @@ function createBrowserServices(call, storageDir) {
|
|
|
16580
16854
|
}
|
|
16581
16855
|
});
|
|
16582
16856
|
let ready;
|
|
16857
|
+
let readySignature;
|
|
16583
16858
|
async function execute(name, args, sessionId, signal) {
|
|
16584
16859
|
const schema = TOOL_SCHEMAS.find((tool) => tool.name === name)?.inputSchema;
|
|
16585
16860
|
if (!schema) throw new Error(`Unknown Native browser service: ${name}`);
|
|
@@ -16601,10 +16876,20 @@ function createBrowserServices(call, storageDir) {
|
|
|
16601
16876
|
isError: !value.ok
|
|
16602
16877
|
};
|
|
16603
16878
|
}
|
|
16604
|
-
|
|
16605
|
-
|
|
16606
|
-
|
|
16607
|
-
|
|
16879
|
+
const bundledDir = bundledRecipesDir ?? resolveBundledRecipesDir();
|
|
16880
|
+
const signature = `${bundledDir}|${bundledRecipesSignature(bundledDir)}`;
|
|
16881
|
+
const versionMatches = bundledRecipesVersionMatchesHost(bundledDir);
|
|
16882
|
+
if (!ready || versionMatches && readySignature !== signature) {
|
|
16883
|
+
if (versionMatches) {
|
|
16884
|
+
readySignature = signature;
|
|
16885
|
+
ready = skills.loadBundledSkills(bundledDir).catch((error) => {
|
|
16886
|
+
ready = void 0;
|
|
16887
|
+
readySignature = void 0;
|
|
16888
|
+
throw error;
|
|
16889
|
+
});
|
|
16890
|
+
}
|
|
16891
|
+
}
|
|
16892
|
+
if (ready) await ready;
|
|
16608
16893
|
const id = typeof args.id === "string" ? args.id : "";
|
|
16609
16894
|
const version = typeof args.version === "number" ? args.version : void 0;
|
|
16610
16895
|
try {
|
|
@@ -17533,7 +17818,7 @@ function formatFrontmatterDescription(base, entries) {
|
|
|
17533
17818
|
}
|
|
17534
17819
|
function renderLearnedSection(entries) {
|
|
17535
17820
|
if (!entries.length) return "";
|
|
17536
|
-
const visible = entries.slice(0,
|
|
17821
|
+
const visible = entries.slice(0, 30);
|
|
17537
17822
|
const rows = visible.map((entry) => {
|
|
17538
17823
|
const sites = entry.domains.length ? entry.domains.slice(0, 3).map((d) => `\`${d}\``).join(", ") : "-";
|
|
17539
17824
|
const summary = escapeMarkdownCell(entry.description || entry.name).slice(0, 110);
|
|
@@ -17623,6 +17908,39 @@ var INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
|
17623
17908
|
"object",
|
|
17624
17909
|
"array"
|
|
17625
17910
|
]);
|
|
17911
|
+
var READ_ONLY_SKILL_TOOLS = /* @__PURE__ */ new Set([
|
|
17912
|
+
"chrome_javascript",
|
|
17913
|
+
"chrome_network_request",
|
|
17914
|
+
"chrome_read_dom",
|
|
17915
|
+
"chrome_get_markdown",
|
|
17916
|
+
"chrome_grep",
|
|
17917
|
+
"chrome_screenshot"
|
|
17918
|
+
]);
|
|
17919
|
+
function isTrustedBundledReadOnlySkill(raw) {
|
|
17920
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return false;
|
|
17921
|
+
const def = raw;
|
|
17922
|
+
if (typeof def.id !== "string" || def.source?.type !== "builtin") return false;
|
|
17923
|
+
if (!Array.isArray(def.steps) || def.steps.length < 1 || def.steps.length > 20) return false;
|
|
17924
|
+
for (const step of def.steps) {
|
|
17925
|
+
if (!step || typeof step !== "object" || typeof step.tool !== "string") return false;
|
|
17926
|
+
if (!READ_ONLY_SKILL_TOOLS.has(step.tool)) return false;
|
|
17927
|
+
if (step.tool === "chrome_javascript") {
|
|
17928
|
+
const args = step.args;
|
|
17929
|
+
if (!args || typeof args !== "object") return false;
|
|
17930
|
+
const hasProgram = args.program !== void 0;
|
|
17931
|
+
const hasCode = typeof args.code === "string";
|
|
17932
|
+
if (hasProgram && hasCode) return false;
|
|
17933
|
+
if (hasProgram) {
|
|
17934
|
+
if (args.program !== DOM_EXTRACTION_PROGRAM_ALIAS) return false;
|
|
17935
|
+
continue;
|
|
17936
|
+
}
|
|
17937
|
+
if (!hasCode) return false;
|
|
17938
|
+
const expectedHash = PUBLISHED_READ_ONLY_PROGRAMS[def.id];
|
|
17939
|
+
if (!expectedHash || programHash(args.code) !== expectedHash) return false;
|
|
17940
|
+
}
|
|
17941
|
+
}
|
|
17942
|
+
return true;
|
|
17943
|
+
}
|
|
17626
17944
|
var TARGET_ARGUMENTS = /* @__PURE__ */ new Map([
|
|
17627
17945
|
["text", [0]],
|
|
17628
17946
|
["screenshot", [0]],
|
|
@@ -17640,12 +17958,25 @@ var TARGET_ARGUMENTS = /* @__PURE__ */ new Map([
|
|
|
17640
17958
|
var QUERY_ALIASES = [
|
|
17641
17959
|
[/推特|推文|twitter/i, ["twitter", "x", "x.com", "twitter.com"]],
|
|
17642
17960
|
[/搜索|查找|搜一下|搜一搜|检索/i, ["search", "find", "query"]],
|
|
17643
|
-
[/帖子|动态|话题|讨论|串|thread/i, ["posts", "thread", "status"]],
|
|
17961
|
+
[/帖子|动态|话题|讨论|串|thread/i, ["posts", "thread", "status", "topic"]],
|
|
17644
17962
|
[/版本|发布|发行版|更新日志/i, ["releases", "release", "version"]],
|
|
17645
17963
|
[/文档|手册|参考/i, ["docs", "documentation", "reference", "mdn"]],
|
|
17646
17964
|
[/对比|比较/i, ["compare", "comparison"]],
|
|
17647
17965
|
[/包|依赖|npm/i, ["npm", "package"]],
|
|
17648
|
-
[/下载/i, ["download"]]
|
|
17966
|
+
[/下载/i, ["download"]],
|
|
17967
|
+
[/仓库|代码库|开源|项目/i, ["github", "repo", "repository", "repositories"]],
|
|
17968
|
+
[/readme|项目说明|简介/i, ["readme", "overview", "repo"]],
|
|
17969
|
+
[/议题|工单|issue|pr/i, ["issue", "issues", "pr", "comments"]],
|
|
17970
|
+
[/v2ex|v站/i, ["v2ex", "www.v2ex.com", "topics"]],
|
|
17971
|
+
[/b站|哔哩哔哩|bilibili|bv号/i, ["bilibili", "www.bilibili.com", "video", "bvid"]],
|
|
17972
|
+
[/油管|youtube|ytb/i, ["youtube", "www.youtube.com", "video"]],
|
|
17973
|
+
[/字幕|台词|文稿/i, ["subtitles", "captions", "transcript", "subtitle"]],
|
|
17974
|
+
[/视频/i, ["video", "videos"]],
|
|
17975
|
+
[/热门|热榜|趋势|流行/i, ["popular", "hot", "trending"]],
|
|
17976
|
+
[/红迪|reddit|板块/i, ["reddit", "www.reddit.com", "subreddit"]],
|
|
17977
|
+
[/评论|回复/i, ["comments", "replies"]],
|
|
17978
|
+
[/主页|资料|用户/i, ["profile", "user", "tweets"]],
|
|
17979
|
+
[/节点/i, ["node", "topics"]]
|
|
17649
17980
|
];
|
|
17650
17981
|
function browserPawHome(override) {
|
|
17651
17982
|
return import_node_path3.default.resolve(
|
|
@@ -17895,9 +18226,9 @@ function resolveBundledRecipesDirectory(homeDir = browserPawHome()) {
|
|
|
17895
18226
|
const candidates = [
|
|
17896
18227
|
import_node_path3.default.join(__dirname, "recipes"),
|
|
17897
18228
|
import_node_path3.default.join(homeDir, "host", "recipes"),
|
|
18229
|
+
import_node_path3.default.resolve(__dirname, "..", "..", "..", "skills", "browserpaw", "assets", "recipes"),
|
|
17898
18230
|
import_node_path3.default.join(__dirname, "..", "dist", "v5", "recipes"),
|
|
17899
|
-
import_node_path3.default.join(__dirname, "..", "dist", "recipes")
|
|
17900
|
-
import_node_path3.default.resolve(__dirname, "..", "..", "..", "skills", "browserpaw", "assets", "recipes")
|
|
18231
|
+
import_node_path3.default.join(__dirname, "..", "dist", "recipes")
|
|
17901
18232
|
];
|
|
17902
18233
|
return candidates.find((candidate) => import_node_fs3.default.existsSync(candidate));
|
|
17903
18234
|
}
|
|
@@ -17911,7 +18242,9 @@ function readJsonSafe(filePath, maxBytes = 4 * 1024 * 1024) {
|
|
|
17911
18242
|
}
|
|
17912
18243
|
}
|
|
17913
18244
|
function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
18245
|
+
const includeBundled = options.includeBundled ?? true;
|
|
17914
18246
|
const byId = /* @__PURE__ */ new Map();
|
|
18247
|
+
const suppressedBundledIds = /* @__PURE__ */ new Set();
|
|
17915
18248
|
const recipesDir = recipesDirectory(homeDir);
|
|
17916
18249
|
if (import_node_fs3.default.existsSync(recipesDir) && !import_node_fs3.default.lstatSync(recipesDir).isSymbolicLink()) {
|
|
17917
18250
|
for (const file of import_node_fs3.default.readdirSync(recipesDir).filter((name) => /^[a-z][a-z0-9-]{0,63}(?:\.candidate)?\.json$/.test(name)).sort()) {
|
|
@@ -17952,7 +18285,16 @@ function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
|
17952
18285
|
const active = record.versions.find(
|
|
17953
18286
|
(item) => item.version === record.activeVersion && item.status === "active"
|
|
17954
18287
|
);
|
|
17955
|
-
const
|
|
18288
|
+
const hasUserOwnedVersion = record.versions.some(
|
|
18289
|
+
(item) => item.definition?.source?.type && item.definition.source.type !== "builtin"
|
|
18290
|
+
);
|
|
18291
|
+
const isDisabledByUser = record.autoUpdatePolicy === "disabled" || !active && record.versions.some((item) => item.status === "disabled");
|
|
18292
|
+
if (hasUserOwnedVersion || isDisabledByUser) {
|
|
18293
|
+
suppressedBundledIds.add(record.id);
|
|
18294
|
+
}
|
|
18295
|
+
const latestCandidate = [...record.versions].reverse().find((item) => item.status === "candidate");
|
|
18296
|
+
const autoDiscoverableBundled = !active && includeBundled && !suppressedBundledIds.has(record.id) && latestCandidate?.definition && isTrustedBundledReadOnlySkill(latestCandidate.definition) ? latestCandidate : void 0;
|
|
18297
|
+
const chosen = active ?? autoDiscoverableBundled ?? (options.includeCandidates ? latestCandidate : void 0);
|
|
17956
18298
|
if (!chosen?.definition) continue;
|
|
17957
18299
|
if (byId.has(record.id) && chosen.status !== "active") continue;
|
|
17958
18300
|
const def = chosen.definition;
|
|
@@ -17960,7 +18302,7 @@ function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
|
17960
18302
|
byId.set(record.id, {
|
|
17961
18303
|
id: record.id,
|
|
17962
18304
|
kind: "skill",
|
|
17963
|
-
status: chosen.status === "active" ? "active" : "candidate",
|
|
18305
|
+
status: chosen.status === "active" ? "active" : autoDiscoverableBundled ? "bundled" : "candidate",
|
|
17964
18306
|
name: def.name || record.id,
|
|
17965
18307
|
description: def.description || "",
|
|
17966
18308
|
domains: Array.isArray(def.domains) ? def.domains : [],
|
|
@@ -17971,7 +18313,7 @@ function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
|
17971
18313
|
});
|
|
17972
18314
|
}
|
|
17973
18315
|
}
|
|
17974
|
-
if (options.includeCandidates) {
|
|
18316
|
+
if (includeBundled || options.includeCandidates) {
|
|
17975
18317
|
const bundledDir = options.bundledDir ?? resolveBundledRecipesDirectory(homeDir);
|
|
17976
18318
|
if (bundledDir && import_node_fs3.default.existsSync(bundledDir) && !import_node_fs3.default.lstatSync(bundledDir).isSymbolicLink()) {
|
|
17977
18319
|
for (const file of import_node_fs3.default.readdirSync(bundledDir).filter((name) => /^[a-z][a-z0-9-]{0,63}\.json$/.test(name)).sort()) {
|
|
@@ -17980,11 +18322,15 @@ function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
|
17980
18322
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) continue;
|
|
17981
18323
|
const def = parsed;
|
|
17982
18324
|
if (typeof def.id !== "string" || byId.has(def.id)) continue;
|
|
18325
|
+
if (suppressedBundledIds.has(def.id)) continue;
|
|
18326
|
+
const trustedBundled = isTrustedBundledReadOnlySkill(parsed);
|
|
18327
|
+
if (!trustedBundled && !options.includeCandidates) continue;
|
|
18328
|
+
if (trustedBundled && !includeBundled && !options.includeCandidates) continue;
|
|
17983
18329
|
const inputs = schemaToInputSpecs(def.inputSchema);
|
|
17984
18330
|
byId.set(def.id, {
|
|
17985
18331
|
id: def.id,
|
|
17986
18332
|
kind: "skill",
|
|
17987
|
-
status: "candidate",
|
|
18333
|
+
status: trustedBundled ? "bundled" : "candidate",
|
|
17988
18334
|
name: def.name || def.id,
|
|
17989
18335
|
description: def.description || "",
|
|
17990
18336
|
domains: Array.isArray(def.domains) ? def.domains : [],
|
|
@@ -17996,8 +18342,9 @@ function loadLearnedWorkflows(homeDir = browserPawHome(), options = {}) {
|
|
|
17996
18342
|
}
|
|
17997
18343
|
}
|
|
17998
18344
|
}
|
|
18345
|
+
const statusRank = (status) => status === "active" ? 0 : status === "bundled" ? 1 : 2;
|
|
17999
18346
|
return [...byId.values()].sort((left, right) => {
|
|
18000
|
-
if (left.status !== right.status) return left.status
|
|
18347
|
+
if (left.status !== right.status) return statusRank(left.status) - statusRank(right.status);
|
|
18001
18348
|
return left.id.localeCompare(right.id);
|
|
18002
18349
|
});
|
|
18003
18350
|
}
|
|
@@ -18140,9 +18487,11 @@ function inspectLearnedWorkflow(id, homeDir = browserPawHome(), bundledDir, pref
|
|
|
18140
18487
|
"Recipe ID must begin with a lowercase letter and contain only letters, digits, or hyphens."
|
|
18141
18488
|
);
|
|
18142
18489
|
}
|
|
18143
|
-
const active = preferActive ? loadLearnedWorkflows(homeDir, {
|
|
18144
|
-
|
|
18145
|
-
|
|
18490
|
+
const active = preferActive ? loadLearnedWorkflows(homeDir, {
|
|
18491
|
+
includeCandidates: false,
|
|
18492
|
+
includeBundled: false,
|
|
18493
|
+
bundledDir
|
|
18494
|
+
}).find((item) => item.id === id) : void 0;
|
|
18146
18495
|
const candidatePath = candidateRecipeFilePath(id, homeDir);
|
|
18147
18496
|
const candidate = active ? void 0 : readJsonSafe(candidatePath, 256 * 1024);
|
|
18148
18497
|
if (candidate && typeof candidate === "object" && !Array.isArray(candidate)) {
|
|
@@ -18729,9 +19078,32 @@ async function dispatchCommand(command, signal, input) {
|
|
|
18729
19078
|
};
|
|
18730
19079
|
}
|
|
18731
19080
|
if (inspected.summary.kind === "skill") {
|
|
18732
|
-
|
|
18733
|
-
|
|
18734
|
-
|
|
19081
|
+
let skillResult = await run("chrome_skill", { action: "get", id: first });
|
|
19082
|
+
let skillMeta = tryParseCallResult(skillResult);
|
|
19083
|
+
const pending = skillMeta?.pendingBundledCandidate;
|
|
19084
|
+
if (!failed(skillResult) && typeof pending?.version === "number") {
|
|
19085
|
+
const validated = await run("chrome_skill", {
|
|
19086
|
+
action: "validate",
|
|
19087
|
+
id: first,
|
|
19088
|
+
version: pending.version
|
|
19089
|
+
});
|
|
19090
|
+
if (!failed(validated)) {
|
|
19091
|
+
syncLearnedRouting(homeDir);
|
|
19092
|
+
skillResult = await run("chrome_skill", { action: "get", id: first });
|
|
19093
|
+
skillMeta = tryParseCallResult(skillResult);
|
|
19094
|
+
} else {
|
|
19095
|
+
const validatedMeta = tryParseCallResult(validated);
|
|
19096
|
+
const validatedStatus = validatedMeta?.status;
|
|
19097
|
+
const validatedOutcome = validatedMeta?.outcome;
|
|
19098
|
+
const mustStop = signal.aborted || validatedStatus === "cancelled" || validatedStatus === "unknown" || validatedOutcome === "unknown" || validatedMeta?.code === "extension_disconnected";
|
|
19099
|
+
const canFallbackToActive = !mustStop && skillMeta?.status === "active" && skillMeta?.executionSupported !== false;
|
|
19100
|
+
if (!canFallbackToActive) {
|
|
19101
|
+
return validated;
|
|
19102
|
+
}
|
|
19103
|
+
}
|
|
19104
|
+
}
|
|
19105
|
+
const effectiveStatus = skillMeta?.status ?? inspected.summary.status;
|
|
19106
|
+
if (effectiveStatus === "candidate" || effectiveStatus === "bundled") {
|
|
18735
19107
|
return {
|
|
18736
19108
|
content: [],
|
|
18737
19109
|
structuredContent: {
|