@ysgao/web-cli 0.2.0 → 0.3.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/README.md +28 -1
- package/dist/index.js +592 -186
- package/package.json +1 -1
- package/skills/web-cli/SKILL.md +95 -4
package/dist/index.js
CHANGED
|
@@ -1364,8 +1364,8 @@ var require_command = __commonJS({
|
|
|
1364
1364
|
"node_modules/commander/lib/command.js"(exports2) {
|
|
1365
1365
|
var EventEmitter2 = require("node:events").EventEmitter;
|
|
1366
1366
|
var childProcess = require("node:child_process");
|
|
1367
|
-
var
|
|
1368
|
-
var
|
|
1367
|
+
var path14 = require("node:path");
|
|
1368
|
+
var fs16 = require("node:fs");
|
|
1369
1369
|
var process2 = require("node:process");
|
|
1370
1370
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1371
1371
|
var { CommanderError: CommanderError2 } = require_error();
|
|
@@ -2297,11 +2297,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2297
2297
|
let launchWithNode = false;
|
|
2298
2298
|
const sourceExt = [".js", ".ts", ".tsx", ".mjs", ".cjs"];
|
|
2299
2299
|
function findFile(baseDir, baseName) {
|
|
2300
|
-
const localBin =
|
|
2301
|
-
if (
|
|
2302
|
-
if (sourceExt.includes(
|
|
2300
|
+
const localBin = path14.resolve(baseDir, baseName);
|
|
2301
|
+
if (fs16.existsSync(localBin)) return localBin;
|
|
2302
|
+
if (sourceExt.includes(path14.extname(baseName))) return void 0;
|
|
2303
2303
|
const foundExt = sourceExt.find(
|
|
2304
|
-
(ext) =>
|
|
2304
|
+
(ext) => fs16.existsSync(`${localBin}${ext}`)
|
|
2305
2305
|
);
|
|
2306
2306
|
if (foundExt) return `${localBin}${foundExt}`;
|
|
2307
2307
|
return void 0;
|
|
@@ -2313,21 +2313,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2313
2313
|
if (this._scriptPath) {
|
|
2314
2314
|
let resolvedScriptPath;
|
|
2315
2315
|
try {
|
|
2316
|
-
resolvedScriptPath =
|
|
2316
|
+
resolvedScriptPath = fs16.realpathSync(this._scriptPath);
|
|
2317
2317
|
} catch (err) {
|
|
2318
2318
|
resolvedScriptPath = this._scriptPath;
|
|
2319
2319
|
}
|
|
2320
|
-
executableDir =
|
|
2321
|
-
|
|
2320
|
+
executableDir = path14.resolve(
|
|
2321
|
+
path14.dirname(resolvedScriptPath),
|
|
2322
2322
|
executableDir
|
|
2323
2323
|
);
|
|
2324
2324
|
}
|
|
2325
2325
|
if (executableDir) {
|
|
2326
2326
|
let localFile = findFile(executableDir, executableFile);
|
|
2327
2327
|
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
2328
|
-
const legacyName =
|
|
2328
|
+
const legacyName = path14.basename(
|
|
2329
2329
|
this._scriptPath,
|
|
2330
|
-
|
|
2330
|
+
path14.extname(this._scriptPath)
|
|
2331
2331
|
);
|
|
2332
2332
|
if (legacyName !== this._name) {
|
|
2333
2333
|
localFile = findFile(
|
|
@@ -2338,7 +2338,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2338
2338
|
}
|
|
2339
2339
|
executableFile = localFile || executableFile;
|
|
2340
2340
|
}
|
|
2341
|
-
launchWithNode = sourceExt.includes(
|
|
2341
|
+
launchWithNode = sourceExt.includes(path14.extname(executableFile));
|
|
2342
2342
|
let proc;
|
|
2343
2343
|
if (process2.platform !== "win32") {
|
|
2344
2344
|
if (launchWithNode) {
|
|
@@ -3178,7 +3178,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3178
3178
|
* @return {Command}
|
|
3179
3179
|
*/
|
|
3180
3180
|
nameFromFilename(filename) {
|
|
3181
|
-
this._name =
|
|
3181
|
+
this._name = path14.basename(filename, path14.extname(filename));
|
|
3182
3182
|
return this;
|
|
3183
3183
|
}
|
|
3184
3184
|
/**
|
|
@@ -3192,9 +3192,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3192
3192
|
* @param {string} [path]
|
|
3193
3193
|
* @return {(string|null|Command)}
|
|
3194
3194
|
*/
|
|
3195
|
-
executableDir(
|
|
3196
|
-
if (
|
|
3197
|
-
this._executableDir =
|
|
3195
|
+
executableDir(path15) {
|
|
3196
|
+
if (path15 === void 0) return this._executableDir;
|
|
3197
|
+
this._executableDir = path15;
|
|
3198
3198
|
return this;
|
|
3199
3199
|
}
|
|
3200
3200
|
/**
|
|
@@ -12271,11 +12271,11 @@ var require_mime_types = __commonJS({
|
|
|
12271
12271
|
}
|
|
12272
12272
|
return exts[0];
|
|
12273
12273
|
}
|
|
12274
|
-
function lookup(
|
|
12275
|
-
if (!
|
|
12274
|
+
function lookup(path14) {
|
|
12275
|
+
if (!path14 || typeof path14 !== "string") {
|
|
12276
12276
|
return false;
|
|
12277
12277
|
}
|
|
12278
|
-
var extension2 = extname("x." +
|
|
12278
|
+
var extension2 = extname("x." + path14).toLowerCase().substr(1);
|
|
12279
12279
|
if (!extension2) {
|
|
12280
12280
|
return false;
|
|
12281
12281
|
}
|
|
@@ -13380,11 +13380,11 @@ var require_form_data = __commonJS({
|
|
|
13380
13380
|
"use strict";
|
|
13381
13381
|
var CombinedStream = require_combined_stream();
|
|
13382
13382
|
var util4 = require("util");
|
|
13383
|
-
var
|
|
13383
|
+
var path14 = require("path");
|
|
13384
13384
|
var http4 = require("http");
|
|
13385
13385
|
var https2 = require("https");
|
|
13386
13386
|
var parseUrl2 = require("url").parse;
|
|
13387
|
-
var
|
|
13387
|
+
var fs16 = require("fs");
|
|
13388
13388
|
var Stream = require("stream").Stream;
|
|
13389
13389
|
var crypto4 = require("crypto");
|
|
13390
13390
|
var mime = require_mime_types();
|
|
@@ -13454,7 +13454,7 @@ var require_form_data = __commonJS({
|
|
|
13454
13454
|
if (value.end != void 0 && value.end != Infinity && value.start != void 0) {
|
|
13455
13455
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
13456
13456
|
} else {
|
|
13457
|
-
|
|
13457
|
+
fs16.stat(value.path, function(err, stat) {
|
|
13458
13458
|
if (err) {
|
|
13459
13459
|
callback(err);
|
|
13460
13460
|
return;
|
|
@@ -13511,11 +13511,11 @@ var require_form_data = __commonJS({
|
|
|
13511
13511
|
FormData3.prototype._getContentDisposition = function(value, options) {
|
|
13512
13512
|
var filename;
|
|
13513
13513
|
if (typeof options.filepath === "string") {
|
|
13514
|
-
filename =
|
|
13514
|
+
filename = path14.normalize(options.filepath).replace(/\\/g, "/");
|
|
13515
13515
|
} else if (options.filename || value && (value.name || value.path)) {
|
|
13516
|
-
filename =
|
|
13516
|
+
filename = path14.basename(options.filename || value && (value.name || value.path));
|
|
13517
13517
|
} else if (value && value.readable && hasOwn(value, "httpVersion")) {
|
|
13518
|
-
filename =
|
|
13518
|
+
filename = path14.basename(value.client._httpMessage.path || "");
|
|
13519
13519
|
}
|
|
13520
13520
|
if (filename) {
|
|
13521
13521
|
return 'filename="' + escapeHeaderParam(filename) + '"';
|
|
@@ -43574,14 +43574,14 @@ var require_devtools = __commonJS({
|
|
|
43574
43574
|
var https2 = require("https");
|
|
43575
43575
|
var defaults2 = require_defaults();
|
|
43576
43576
|
var externalRequest = require_external_request();
|
|
43577
|
-
function devToolsInterface(
|
|
43577
|
+
function devToolsInterface(path14, options, callback) {
|
|
43578
43578
|
const transport = options.secure ? https2 : http4;
|
|
43579
43579
|
const requestOptions = {
|
|
43580
43580
|
method: options.method,
|
|
43581
43581
|
host: options.host || defaults2.HOST,
|
|
43582
43582
|
port: options.port || defaults2.PORT,
|
|
43583
43583
|
useHostName: options.useHostName,
|
|
43584
|
-
path: options.alterPath ? options.alterPath(
|
|
43584
|
+
path: options.alterPath ? options.alterPath(path14) : path14
|
|
43585
43585
|
};
|
|
43586
43586
|
externalRequest(transport, requestOptions, callback);
|
|
43587
43587
|
}
|
|
@@ -43632,12 +43632,12 @@ var require_devtools = __commonJS({
|
|
|
43632
43632
|
});
|
|
43633
43633
|
}
|
|
43634
43634
|
function New(options, callback) {
|
|
43635
|
-
let
|
|
43635
|
+
let path14 = "/json/new";
|
|
43636
43636
|
if (Object.prototype.hasOwnProperty.call(options, "url")) {
|
|
43637
|
-
|
|
43637
|
+
path14 += `?${options.url}`;
|
|
43638
43638
|
}
|
|
43639
43639
|
options.method = options.method || "PUT";
|
|
43640
|
-
devToolsInterface(
|
|
43640
|
+
devToolsInterface(path14, options, (err, tab) => {
|
|
43641
43641
|
if (err) {
|
|
43642
43642
|
callback(err);
|
|
43643
43643
|
} else {
|
|
@@ -43812,7 +43812,7 @@ var require_chrome = __commonJS({
|
|
|
43812
43812
|
this.port = options.port || defaults2.PORT;
|
|
43813
43813
|
this.secure = !!options.secure;
|
|
43814
43814
|
this.useHostName = !!options.useHostName;
|
|
43815
|
-
this.alterPath = options.alterPath || ((
|
|
43815
|
+
this.alterPath = options.alterPath || ((path14) => path14);
|
|
43816
43816
|
this.protocol = options.protocol;
|
|
43817
43817
|
this.local = !!options.local;
|
|
43818
43818
|
this.target = options.target || defaultTarget;
|
|
@@ -44072,7 +44072,7 @@ __export(index_exports, {
|
|
|
44072
44072
|
program: () => program2
|
|
44073
44073
|
});
|
|
44074
44074
|
module.exports = __toCommonJS(index_exports);
|
|
44075
|
-
var
|
|
44075
|
+
var path13 = __toESM(require("path"));
|
|
44076
44076
|
var dotenv = __toESM(require_dist());
|
|
44077
44077
|
|
|
44078
44078
|
// src/core/paths.ts
|
|
@@ -45198,9 +45198,9 @@ function isVisitable(thing) {
|
|
|
45198
45198
|
function removeBrackets(key) {
|
|
45199
45199
|
return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
|
|
45200
45200
|
}
|
|
45201
|
-
function renderKey(
|
|
45202
|
-
if (!
|
|
45203
|
-
return
|
|
45201
|
+
function renderKey(path14, key, dots) {
|
|
45202
|
+
if (!path14) return key;
|
|
45203
|
+
return path14.concat(key).map(function each(token, i) {
|
|
45204
45204
|
token = removeBrackets(token);
|
|
45205
45205
|
return !dots && i ? "[" + token + "]" : token;
|
|
45206
45206
|
}).join(dots ? "." : "");
|
|
@@ -45286,13 +45286,13 @@ function toFormData(obj, formData, options) {
|
|
|
45286
45286
|
return currentValue;
|
|
45287
45287
|
});
|
|
45288
45288
|
}
|
|
45289
|
-
function defaultVisitor(value, key,
|
|
45289
|
+
function defaultVisitor(value, key, path14) {
|
|
45290
45290
|
let arr = value;
|
|
45291
45291
|
if (utils_default.isReactNative(formData) && utils_default.isReactNativeBlob(value)) {
|
|
45292
|
-
formData.append(renderKey(
|
|
45292
|
+
formData.append(renderKey(path14, key, dots), convertValue(value));
|
|
45293
45293
|
return false;
|
|
45294
45294
|
}
|
|
45295
|
-
if (value && !
|
|
45295
|
+
if (value && !path14 && typeof value === "object") {
|
|
45296
45296
|
if (utils_default.endsWith(key, "{}")) {
|
|
45297
45297
|
key = metaTokens ? key : key.slice(0, -2);
|
|
45298
45298
|
value = stringifyWithDepthLimit(value, 1);
|
|
@@ -45311,7 +45311,7 @@ function toFormData(obj, formData, options) {
|
|
|
45311
45311
|
if (isVisitable(value)) {
|
|
45312
45312
|
return true;
|
|
45313
45313
|
}
|
|
45314
|
-
formData.append(renderKey(
|
|
45314
|
+
formData.append(renderKey(path14, key, dots), convertValue(value));
|
|
45315
45315
|
return false;
|
|
45316
45316
|
}
|
|
45317
45317
|
const exposedHelpers = Object.assign(predicates, {
|
|
@@ -45319,17 +45319,17 @@ function toFormData(obj, formData, options) {
|
|
|
45319
45319
|
convertValue,
|
|
45320
45320
|
isVisitable
|
|
45321
45321
|
});
|
|
45322
|
-
function build(value,
|
|
45322
|
+
function build(value, path14, depth = 0) {
|
|
45323
45323
|
if (utils_default.isUndefined(value)) return;
|
|
45324
45324
|
throwIfMaxDepthExceeded(depth);
|
|
45325
45325
|
if (stack.indexOf(value) !== -1) {
|
|
45326
|
-
throw new Error("Circular reference detected in " +
|
|
45326
|
+
throw new Error("Circular reference detected in " + path14.join("."));
|
|
45327
45327
|
}
|
|
45328
45328
|
stack.push(value);
|
|
45329
45329
|
utils_default.forEach(value, function each(el, key) {
|
|
45330
|
-
const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key,
|
|
45330
|
+
const result = !(utils_default.isUndefined(el) || el === null) && visitor.call(formData, el, utils_default.isString(key) ? key.trim() : key, path14, exposedHelpers);
|
|
45331
45331
|
if (result === true) {
|
|
45332
|
-
build(el,
|
|
45332
|
+
build(el, path14 ? path14.concat(key) : [key], depth + 1);
|
|
45333
45333
|
}
|
|
45334
45334
|
});
|
|
45335
45335
|
stack.pop();
|
|
@@ -45541,7 +45541,7 @@ var platform_default = {
|
|
|
45541
45541
|
// node_modules/axios/lib/helpers/toURLEncodedForm.js
|
|
45542
45542
|
function toURLEncodedForm(data, options) {
|
|
45543
45543
|
return toFormData_default(data, new platform_default.classes.URLSearchParams(), {
|
|
45544
|
-
visitor: function(value, key,
|
|
45544
|
+
visitor: function(value, key, path14, helpers) {
|
|
45545
45545
|
if (platform_default.isNode && utils_default.isBuffer(value)) {
|
|
45546
45546
|
this.append(key, value.toString("base64"));
|
|
45547
45547
|
return false;
|
|
@@ -45563,14 +45563,14 @@ function throwIfDepthExceeded(index) {
|
|
|
45563
45563
|
}
|
|
45564
45564
|
}
|
|
45565
45565
|
function parsePropPath(name) {
|
|
45566
|
-
const
|
|
45566
|
+
const path14 = [];
|
|
45567
45567
|
const pattern = /[^.[\]]+|\[([^.[\]]*)]/g;
|
|
45568
45568
|
let match;
|
|
45569
45569
|
while ((match = pattern.exec(name)) !== null) {
|
|
45570
|
-
throwIfDepthExceeded(
|
|
45571
|
-
|
|
45570
|
+
throwIfDepthExceeded(path14.length);
|
|
45571
|
+
path14.push(match[0] === "[]" ? "" : match[1] || match[0]);
|
|
45572
45572
|
}
|
|
45573
|
-
return
|
|
45573
|
+
return path14;
|
|
45574
45574
|
}
|
|
45575
45575
|
function arrayToObject(arr) {
|
|
45576
45576
|
const obj = {};
|
|
@@ -45585,12 +45585,12 @@ function arrayToObject(arr) {
|
|
|
45585
45585
|
return obj;
|
|
45586
45586
|
}
|
|
45587
45587
|
function formDataToJSON(formData) {
|
|
45588
|
-
function buildPath(
|
|
45588
|
+
function buildPath(path14, value, target, index) {
|
|
45589
45589
|
throwIfDepthExceeded(index);
|
|
45590
|
-
let name =
|
|
45590
|
+
let name = path14[index++];
|
|
45591
45591
|
if (name === "__proto__") return true;
|
|
45592
45592
|
const isNumericKey = Number.isFinite(+name);
|
|
45593
|
-
const isLast = index >=
|
|
45593
|
+
const isLast = index >= path14.length;
|
|
45594
45594
|
name = !name && utils_default.isArray(target) ? target.length : name;
|
|
45595
45595
|
if (isLast) {
|
|
45596
45596
|
if (utils_default.hasOwnProp(target, name)) {
|
|
@@ -45603,7 +45603,7 @@ function formDataToJSON(formData) {
|
|
|
45603
45603
|
if (!utils_default.hasOwnProp(target, name) || !utils_default.isObject(target[name])) {
|
|
45604
45604
|
target[name] = [];
|
|
45605
45605
|
}
|
|
45606
|
-
const result = buildPath(
|
|
45606
|
+
const result = buildPath(path14, value, target[name], index);
|
|
45607
45607
|
if (result && utils_default.isArray(target[name])) {
|
|
45608
45608
|
target[name] = arrayToObject(target[name]);
|
|
45609
45609
|
}
|
|
@@ -47321,9 +47321,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
47321
47321
|
auth2 = urlUsername + ":" + urlPassword;
|
|
47322
47322
|
}
|
|
47323
47323
|
auth2 && headers.delete("authorization");
|
|
47324
|
-
let
|
|
47324
|
+
let path14;
|
|
47325
47325
|
try {
|
|
47326
|
-
|
|
47326
|
+
path14 = buildURL(
|
|
47327
47327
|
parsed.pathname + parsed.search,
|
|
47328
47328
|
own2("params"),
|
|
47329
47329
|
own2("paramsSerializer")
|
|
@@ -47342,7 +47342,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config2) {
|
|
|
47342
47342
|
false
|
|
47343
47343
|
);
|
|
47344
47344
|
const options = Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
47345
|
-
path:
|
|
47345
|
+
path: path14,
|
|
47346
47346
|
method,
|
|
47347
47347
|
headers: toByteStringHeaderObject(headers),
|
|
47348
47348
|
agents: { http: httpAgent, https: httpsAgent },
|
|
@@ -47744,14 +47744,14 @@ var isURLSameOrigin_default = platform_default.hasStandardBrowserEnv ? /* @__PUR
|
|
|
47744
47744
|
var cookies_default = platform_default.hasStandardBrowserEnv ? (
|
|
47745
47745
|
// Standard browser envs support document.cookie
|
|
47746
47746
|
{
|
|
47747
|
-
write(name, value, expires,
|
|
47747
|
+
write(name, value, expires, path14, domain, secure, sameSite) {
|
|
47748
47748
|
if (typeof document === "undefined") return;
|
|
47749
47749
|
const cookie = [`${name}=${encodeURIComponent(value)}`];
|
|
47750
47750
|
if (utils_default.isNumber(expires)) {
|
|
47751
47751
|
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
|
47752
47752
|
}
|
|
47753
|
-
if (utils_default.isString(
|
|
47754
|
-
cookie.push(`path=${
|
|
47753
|
+
if (utils_default.isString(path14)) {
|
|
47754
|
+
cookie.push(`path=${path14}`);
|
|
47755
47755
|
}
|
|
47756
47756
|
if (utils_default.isString(domain)) {
|
|
47757
47757
|
cookie.push(`domain=${domain}`);
|
|
@@ -50058,6 +50058,14 @@ function mergeHeadersCaseInsensitively(base, incoming) {
|
|
|
50058
50058
|
}
|
|
50059
50059
|
return merged;
|
|
50060
50060
|
}
|
|
50061
|
+
var SELECT_FOCUSED_FIELD_SCRIPT = `(() => {
|
|
50062
|
+
const el = document.activeElement;
|
|
50063
|
+
if (el && typeof el.select === 'function') {
|
|
50064
|
+
el.select();
|
|
50065
|
+
return true;
|
|
50066
|
+
}
|
|
50067
|
+
return false;
|
|
50068
|
+
})()`;
|
|
50061
50069
|
function withTimeout(promise, timeoutMs, message) {
|
|
50062
50070
|
return new Promise((resolve4, reject) => {
|
|
50063
50071
|
const timer = setTimeout(() => reject(new Error(message)), timeoutMs);
|
|
@@ -50091,8 +50099,8 @@ async function connectToAnyPageTarget(port, connector = realCdpConnector) {
|
|
|
50091
50099
|
return connector.connect({ port, target: target.id });
|
|
50092
50100
|
}
|
|
50093
50101
|
}
|
|
50094
|
-
async function connectCdpSession(port) {
|
|
50095
|
-
const client = await connectToAnyPageTarget(port);
|
|
50102
|
+
async function connectCdpSession(port, connector = realCdpConnector) {
|
|
50103
|
+
const client = await connectToAnyPageTarget(port, connector);
|
|
50096
50104
|
const { Network, Page, Runtime, Browser, Input } = client;
|
|
50097
50105
|
await Promise.all([Network.enable(), Page.enable(), Runtime.enable()]);
|
|
50098
50106
|
const version = await Browser.getVersion();
|
|
@@ -50141,6 +50149,12 @@ async function connectCdpSession(port) {
|
|
|
50141
50149
|
}).catch(() => {
|
|
50142
50150
|
});
|
|
50143
50151
|
});
|
|
50152
|
+
async function selectFocusedFieldContents() {
|
|
50153
|
+
try {
|
|
50154
|
+
await Runtime.evaluate({ expression: SELECT_FOCUSED_FIELD_SCRIPT, returnByValue: true });
|
|
50155
|
+
} catch {
|
|
50156
|
+
}
|
|
50157
|
+
}
|
|
50144
50158
|
async function typeCharacter(ch) {
|
|
50145
50159
|
await Input.dispatchKeyEvent({ type: "rawKeyDown", text: ch, unmodifiedText: ch });
|
|
50146
50160
|
await Input.dispatchKeyEvent({ type: "char", text: ch, unmodifiedText: ch });
|
|
@@ -50165,6 +50179,9 @@ async function connectCdpSession(port) {
|
|
|
50165
50179
|
await Input.dispatchMouseEvent({ type: "mouseReleased", x, y, button: "left", clickCount: 1 });
|
|
50166
50180
|
},
|
|
50167
50181
|
async type(text, opts) {
|
|
50182
|
+
if (opts?.replaceExisting) {
|
|
50183
|
+
await selectFocusedFieldContents();
|
|
50184
|
+
}
|
|
50168
50185
|
for (const ch of text) {
|
|
50169
50186
|
await typeCharacter(ch);
|
|
50170
50187
|
}
|
|
@@ -51097,7 +51114,7 @@ async function locateFields(session, timeoutMs) {
|
|
|
51097
51114
|
}
|
|
51098
51115
|
async function fillField(session, point, text, pressEnter) {
|
|
51099
51116
|
await session.click(point.x, point.y);
|
|
51100
|
-
await session.type(text, { pressEnter });
|
|
51117
|
+
await session.type(text, { pressEnter, replaceExisting: true });
|
|
51101
51118
|
}
|
|
51102
51119
|
async function attemptAutoFillLogin(session, credentials, opts = {}) {
|
|
51103
51120
|
const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
@@ -51254,6 +51271,13 @@ async function loadCredentials(site, deps = {}) {
|
|
|
51254
51271
|
const { username, password } = candidates[0];
|
|
51255
51272
|
return { username, password };
|
|
51256
51273
|
}
|
|
51274
|
+
async function hasStoredCredentials(site, deps = {}) {
|
|
51275
|
+
try {
|
|
51276
|
+
return await loadCredentials(site, deps) !== void 0;
|
|
51277
|
+
} catch {
|
|
51278
|
+
return false;
|
|
51279
|
+
}
|
|
51280
|
+
}
|
|
51257
51281
|
async function clearCredentials(site, deps = {}) {
|
|
51258
51282
|
const keychain = resolveKeychain(deps);
|
|
51259
51283
|
if (keychain) {
|
|
@@ -51415,10 +51439,11 @@ function mergeStoredSession(profileJar, storedJar) {
|
|
|
51415
51439
|
var DEFAULT_LOGIN_TIMEOUT_MS = 24e4;
|
|
51416
51440
|
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
51417
51441
|
var SILENT_REFRESH_TIMEOUT_MS = 25e3;
|
|
51442
|
+
var SILENT_REFRESH_NO_CREDENTIAL_TIMEOUT_MS = 8e3;
|
|
51418
51443
|
var SILENT_REFRESH_POLL_INTERVAL_MS = 2e3;
|
|
51419
|
-
async function attemptAutoFill(site, session, deps) {
|
|
51444
|
+
async function attemptAutoFill(site, session, deps, preloaded) {
|
|
51420
51445
|
try {
|
|
51421
|
-
const credentials = await (deps
|
|
51446
|
+
const credentials = preloaded === void 0 ? await loadSavedCredentials(site, deps) : preloaded;
|
|
51422
51447
|
if (!credentials) {
|
|
51423
51448
|
return false;
|
|
51424
51449
|
}
|
|
@@ -51427,6 +51452,13 @@ async function attemptAutoFill(site, session, deps) {
|
|
|
51427
51452
|
return false;
|
|
51428
51453
|
}
|
|
51429
51454
|
}
|
|
51455
|
+
async function loadSavedCredentials(site, deps) {
|
|
51456
|
+
try {
|
|
51457
|
+
return await (deps.loadCredentials ?? loadCredentials)(site) ?? null;
|
|
51458
|
+
} catch {
|
|
51459
|
+
return null;
|
|
51460
|
+
}
|
|
51461
|
+
}
|
|
51430
51462
|
var inFlightLogins = /* @__PURE__ */ new Map();
|
|
51431
51463
|
var completedLogins = /* @__PURE__ */ new Set();
|
|
51432
51464
|
function loginKey(site, intent) {
|
|
@@ -51457,12 +51489,11 @@ async function getLoginPageCookies(session, loginUrl) {
|
|
|
51457
51489
|
}
|
|
51458
51490
|
return session.getCookies(Array.from(urls));
|
|
51459
51491
|
}
|
|
51460
|
-
async function attemptSilentRefresh(opts, deps) {
|
|
51492
|
+
async function attemptSilentRefresh(opts, deps, credentials) {
|
|
51461
51493
|
const withChrome = deps.withChrome ?? withAutomationChrome;
|
|
51462
51494
|
const connect = deps.connect ?? connectCdpSession;
|
|
51463
51495
|
const now = deps.now ?? (() => Date.now());
|
|
51464
51496
|
const sleep = deps.sleep ?? defaultSleep;
|
|
51465
|
-
const silentTimeoutMs = deps.silentRefreshTimeoutMs ?? SILENT_REFRESH_TIMEOUT_MS;
|
|
51466
51497
|
try {
|
|
51467
51498
|
return await withChrome({ headless: true }, async (chrome) => {
|
|
51468
51499
|
const session = await connect(chrome.port);
|
|
@@ -51471,7 +51502,8 @@ async function attemptSilentRefresh(opts, deps) {
|
|
|
51471
51502
|
await session.navigate(opts.loginUrl);
|
|
51472
51503
|
} catch {
|
|
51473
51504
|
}
|
|
51474
|
-
await attemptAutoFill(opts.site, session, deps);
|
|
51505
|
+
await attemptAutoFill(opts.site, session, deps, credentials);
|
|
51506
|
+
const silentTimeoutMs = deps.silentRefreshTimeoutMs ?? (credentials ? SILENT_REFRESH_TIMEOUT_MS : SILENT_REFRESH_NO_CREDENTIAL_TIMEOUT_MS);
|
|
51475
51507
|
const deadline = now() + silentTimeoutMs;
|
|
51476
51508
|
for (; ; ) {
|
|
51477
51509
|
const jar = await getLoginPageCookies(session, opts.loginUrl);
|
|
@@ -51538,7 +51570,13 @@ async function runVisibleLogin(opts, deps) {
|
|
|
51538
51570
|
}
|
|
51539
51571
|
});
|
|
51540
51572
|
}
|
|
51541
|
-
function noVisibleWindowError(site) {
|
|
51573
|
+
function noVisibleWindowError(site, hasCredential) {
|
|
51574
|
+
if (hasCredential) {
|
|
51575
|
+
return new CliError(
|
|
51576
|
+
"SESSION_EXPIRED",
|
|
51577
|
+
`No valid session for "${site}" \u2014 a credential IS already saved for this site (from an earlier "web-cli login ${site} --save-credentials"), and the silent refresh already tried it, but a working session still could not be re-established this run. Re-running "--save-credentials" again will not help unless the saved password is actually out of date \u2014 a likely cause here is something the automatic form-fill can't get past on its own (a CAPTCHA, a 2FA prompt, or a changed login page), or a transient site issue. A visible sign-in window is not allowed for this run (pass --allow-visible-login to permit one and see, in person, what is actually blocking it), or run "web-cli login ${site}" directly to sign in by hand right now.`
|
|
51578
|
+
);
|
|
51579
|
+
}
|
|
51542
51580
|
return new CliError(
|
|
51543
51581
|
"SESSION_EXPIRED",
|
|
51544
51582
|
`No valid session for "${site}" \u2014 the silent, credential-based refresh did not recover it, and a visible sign-in window is not allowed for this run (pass --allow-visible-login to permit one). Run "web-cli login ${site}" to sign in manually, or "web-cli login ${site} --save-credentials" so a future run can recover silently without ever needing a window.`
|
|
@@ -51546,14 +51584,15 @@ function noVisibleWindowError(site) {
|
|
|
51546
51584
|
}
|
|
51547
51585
|
async function runInteractiveLogin(opts, deps) {
|
|
51548
51586
|
const allowVisible = opts.allowVisible ?? true;
|
|
51549
|
-
const
|
|
51587
|
+
const credentials = await loadSavedCredentials(opts.site, deps);
|
|
51588
|
+
const silentJar = await attemptSilentRefresh(opts, deps, credentials);
|
|
51550
51589
|
if (silentJar) {
|
|
51551
51590
|
establishedJars.set(opts.site, silentJar);
|
|
51552
51591
|
await (deps.saveSession ?? saveSessionJar)(opts.site, silentJar);
|
|
51553
51592
|
return silentJar;
|
|
51554
51593
|
}
|
|
51555
51594
|
if (!allowVisible) {
|
|
51556
|
-
throw noVisibleWindowError(opts.site);
|
|
51595
|
+
throw noVisibleWindowError(opts.site, credentials !== null);
|
|
51557
51596
|
}
|
|
51558
51597
|
return runVisibleLogin(opts, deps);
|
|
51559
51598
|
}
|
|
@@ -51601,17 +51640,74 @@ function getSiteConfig(site) {
|
|
|
51601
51640
|
return config2;
|
|
51602
51641
|
}
|
|
51603
51642
|
|
|
51643
|
+
// src/core/callOptions.ts
|
|
51644
|
+
function isAbortError(err) {
|
|
51645
|
+
if (typeof err !== "object" || err === null) {
|
|
51646
|
+
return false;
|
|
51647
|
+
}
|
|
51648
|
+
const e = err;
|
|
51649
|
+
return e.code === "ERR_CANCELED" || e.name === "CanceledError" || e.name === "AbortError";
|
|
51650
|
+
}
|
|
51651
|
+
var SEARCH_CALL_OPTIONS = {
|
|
51652
|
+
timeoutMs: 8e3,
|
|
51653
|
+
retryOnTransportError: { timeoutMs: 15e3 }
|
|
51654
|
+
};
|
|
51655
|
+
|
|
51604
51656
|
// src/core/replayEngine.ts
|
|
51605
51657
|
var HTTP_REPLAY_TIMEOUT_MS = 3e4;
|
|
51606
|
-
|
|
51607
|
-
|
|
51658
|
+
var TRANSPORT_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
51659
|
+
"ECONNABORTED",
|
|
51660
|
+
// axios's own timeout
|
|
51661
|
+
"ETIMEDOUT",
|
|
51662
|
+
"ECONNRESET",
|
|
51663
|
+
"EPIPE",
|
|
51664
|
+
"EAI_AGAIN",
|
|
51665
|
+
"ENETUNREACH",
|
|
51666
|
+
"ERR_NETWORK"
|
|
51667
|
+
]);
|
|
51668
|
+
function isTransportError(err) {
|
|
51669
|
+
if (typeof err !== "object" || err === null) {
|
|
51670
|
+
return false;
|
|
51671
|
+
}
|
|
51672
|
+
const e = err;
|
|
51673
|
+
if (e.response !== void 0) {
|
|
51674
|
+
return false;
|
|
51675
|
+
}
|
|
51676
|
+
if (typeof e.code === "string" && TRANSPORT_ERROR_CODES.has(e.code)) {
|
|
51677
|
+
return true;
|
|
51678
|
+
}
|
|
51679
|
+
return typeof e.message === "string" && /timeout of \d+ms exceeded|socket hang up/i.test(e.message);
|
|
51680
|
+
}
|
|
51681
|
+
function hostOf(url2) {
|
|
51682
|
+
try {
|
|
51683
|
+
return new URL(url2).host;
|
|
51684
|
+
} catch {
|
|
51685
|
+
return url2;
|
|
51686
|
+
}
|
|
51687
|
+
}
|
|
51688
|
+
async function callTemplate(rendered, cookieHeader, options = {}) {
|
|
51689
|
+
const send = (timeout) => axios_default.request({
|
|
51608
51690
|
method: rendered.method,
|
|
51609
51691
|
url: rendered.url,
|
|
51610
51692
|
headers: { ...rendered.headers, Cookie: cookieHeader },
|
|
51611
51693
|
data: rendered.body,
|
|
51612
51694
|
validateStatus: () => true,
|
|
51613
|
-
timeout
|
|
51695
|
+
timeout,
|
|
51696
|
+
signal: options.signal
|
|
51614
51697
|
});
|
|
51698
|
+
let response;
|
|
51699
|
+
try {
|
|
51700
|
+
response = await send(options.timeoutMs ?? HTTP_REPLAY_TIMEOUT_MS);
|
|
51701
|
+
} catch (err) {
|
|
51702
|
+
if (!options.retryOnTransportError || !isTransportError(err) || rendered.method.toUpperCase() !== "GET") {
|
|
51703
|
+
throw err;
|
|
51704
|
+
}
|
|
51705
|
+
process.stderr.write(
|
|
51706
|
+
`web-cli: request to ${hostOf(rendered.url)} failed (${err instanceof Error ? err.message : String(err)}) \u2014 retrying once.
|
|
51707
|
+
`
|
|
51708
|
+
);
|
|
51709
|
+
response = await send(options.retryOnTransportError.timeoutMs);
|
|
51710
|
+
}
|
|
51615
51711
|
if (response.status < 200 || response.status >= 300) {
|
|
51616
51712
|
const body = typeof response.data === "string" ? response.data : JSON.stringify(response.data);
|
|
51617
51713
|
throw new ReplayHttpError(`Replay got HTTP ${response.status}`, response.status, body);
|
|
@@ -51651,7 +51747,7 @@ async function replay(site, intent, param, opts = {}) {
|
|
|
51651
51747
|
const siteSupportsLogin = config2.requiresLogin !== false;
|
|
51652
51748
|
const loginRecoveryDisabled = opts.disableLoginRecovery === true;
|
|
51653
51749
|
try {
|
|
51654
|
-
return await attemptReplay(site, intent, param);
|
|
51750
|
+
return await attemptReplay(site, intent, param, void 0, opts.signal);
|
|
51655
51751
|
} catch (err) {
|
|
51656
51752
|
if (!isAuthFailure(err)) {
|
|
51657
51753
|
throw err;
|
|
@@ -51676,7 +51772,7 @@ async function replay(site, intent, param, opts = {}) {
|
|
|
51676
51772
|
isSessionReady: (jar) => isSessionUsable(site, intent, param, jar),
|
|
51677
51773
|
allowVisible: opts.allowVisibleLogin === true
|
|
51678
51774
|
});
|
|
51679
|
-
return await attemptReplay(site, intent, param, freshJar);
|
|
51775
|
+
return await attemptReplay(site, intent, param, freshJar, opts.signal);
|
|
51680
51776
|
}
|
|
51681
51777
|
}
|
|
51682
51778
|
async function isSessionUsable(site, intent, param, jar) {
|
|
@@ -51702,7 +51798,11 @@ function assertNotPaywalled(site, intent, data, baseUrl) {
|
|
|
51702
51798
|
);
|
|
51703
51799
|
}
|
|
51704
51800
|
}
|
|
51705
|
-
|
|
51801
|
+
function callOptionsFor(intent, signal) {
|
|
51802
|
+
const base = intent === "search" ? SEARCH_CALL_OPTIONS : {};
|
|
51803
|
+
return signal ? { ...base, signal } : base;
|
|
51804
|
+
}
|
|
51805
|
+
async function attemptReplay(site, intent, param, jarOverride, signal) {
|
|
51706
51806
|
const config2 = getSiteConfig(site);
|
|
51707
51807
|
const cookieJar = jarOverride ?? getEstablishedSession(site) ?? mergeStoredSession(await getLiveCookieJar(config2.host), await loadSessionJar(site));
|
|
51708
51808
|
if (Object.keys(cookieJar).length === 0) {
|
|
@@ -51716,10 +51816,13 @@ async function attemptReplay(site, intent, param, jarOverride) {
|
|
|
51716
51816
|
const existing = readTemplate(site, intent);
|
|
51717
51817
|
if (existing) {
|
|
51718
51818
|
try {
|
|
51719
|
-
const data = await callTemplate(renderTemplate(existing, needle), cookieHeader);
|
|
51819
|
+
const data = await callTemplate(renderTemplate(existing, needle), cookieHeader, callOptionsFor(intent, signal));
|
|
51720
51820
|
assertNotPaywalled(site, intent, data, config2.baseUrl);
|
|
51721
51821
|
return { data, discovered: false };
|
|
51722
51822
|
} catch (err) {
|
|
51823
|
+
if (isAbortError(err)) {
|
|
51824
|
+
throw err;
|
|
51825
|
+
}
|
|
51723
51826
|
if (isAuthFailure(err)) {
|
|
51724
51827
|
throw err;
|
|
51725
51828
|
}
|
|
@@ -51728,12 +51831,12 @@ async function attemptReplay(site, intent, param, jarOverride) {
|
|
|
51728
51831
|
const preseed = getPreseedTemplate(site, intent);
|
|
51729
51832
|
if (preseed) {
|
|
51730
51833
|
try {
|
|
51731
|
-
const data = await callTemplate(renderTemplate(preseed, needle), cookieHeader);
|
|
51834
|
+
const data = await callTemplate(renderTemplate(preseed, needle), cookieHeader, callOptionsFor(intent, signal));
|
|
51732
51835
|
assertNotPaywalled(site, intent, data, config2.baseUrl);
|
|
51733
51836
|
persistTemplateBestEffort(site, intent, preseed);
|
|
51734
51837
|
return { data, discovered: false };
|
|
51735
51838
|
} catch (err) {
|
|
51736
|
-
if (isAuthFailure(err)) {
|
|
51839
|
+
if (isAuthFailure(err) || isAbortError(err)) {
|
|
51737
51840
|
throw err;
|
|
51738
51841
|
}
|
|
51739
51842
|
}
|
|
@@ -51781,6 +51884,107 @@ async function attemptReplay(site, intent, param, jarOverride) {
|
|
|
51781
51884
|
}
|
|
51782
51885
|
}
|
|
51783
51886
|
|
|
51887
|
+
// src/commands/fullTextBudget.ts
|
|
51888
|
+
var DEFAULT_FULLTEXT_BUDGET_MS = 5e3;
|
|
51889
|
+
var FullTextBudget = class {
|
|
51890
|
+
constructor(budgetMs, timers = {
|
|
51891
|
+
set: (fn, ms) => setTimeout(fn, ms),
|
|
51892
|
+
clear: (handle) => clearTimeout(handle)
|
|
51893
|
+
}) {
|
|
51894
|
+
this.budgetMs = budgetMs;
|
|
51895
|
+
this.timers = timers;
|
|
51896
|
+
this.signal = this.controller.signal;
|
|
51897
|
+
this.limited = Number.isFinite(budgetMs) && budgetMs > 0;
|
|
51898
|
+
if (this.limited) {
|
|
51899
|
+
this.timer = timers.set(() => {
|
|
51900
|
+
this.expired = true;
|
|
51901
|
+
this.abortIfAnyFetched();
|
|
51902
|
+
}, budgetMs);
|
|
51903
|
+
}
|
|
51904
|
+
}
|
|
51905
|
+
budgetMs;
|
|
51906
|
+
signal;
|
|
51907
|
+
/** Whether this budget can ever abort anything (false for the unlimited form). */
|
|
51908
|
+
limited;
|
|
51909
|
+
controller = new AbortController();
|
|
51910
|
+
timer;
|
|
51911
|
+
expired = false;
|
|
51912
|
+
fetched = 0;
|
|
51913
|
+
timers;
|
|
51914
|
+
/** Report that a full text arrived. If the budget has already run out while nothing had arrived
|
|
51915
|
+
* yet, this is the moment the remaining fetches are cut. */
|
|
51916
|
+
noteFetched() {
|
|
51917
|
+
this.fetched += 1;
|
|
51918
|
+
this.abortIfAnyFetched();
|
|
51919
|
+
}
|
|
51920
|
+
/** Whether the budget has aborted the remaining fetches. */
|
|
51921
|
+
get aborted() {
|
|
51922
|
+
return this.signal.aborted;
|
|
51923
|
+
}
|
|
51924
|
+
/** Stops the timer. Always call when the site's expansions are done, so a finished search never
|
|
51925
|
+
* leaves a live timer behind. */
|
|
51926
|
+
dispose() {
|
|
51927
|
+
if (this.timer !== void 0) {
|
|
51928
|
+
this.timers.clear(this.timer);
|
|
51929
|
+
this.timer = void 0;
|
|
51930
|
+
}
|
|
51931
|
+
}
|
|
51932
|
+
abortIfAnyFetched() {
|
|
51933
|
+
if (this.expired && this.fetched > 0 && !this.controller.signal.aborted) {
|
|
51934
|
+
this.controller.abort();
|
|
51935
|
+
}
|
|
51936
|
+
}
|
|
51937
|
+
};
|
|
51938
|
+
|
|
51939
|
+
// src/parsers/truncateArticle.ts
|
|
51940
|
+
var DEFAULT_MAX_ARTICLE_CHARS = 6e4;
|
|
51941
|
+
function shellQuote3(value) {
|
|
51942
|
+
return `'${value.replace(/'/g, `'\\''`)}'`;
|
|
51943
|
+
}
|
|
51944
|
+
function fetchFullTextCommand(site, url2) {
|
|
51945
|
+
return `web-cli get ${site} ${shellQuote3(url2)}`;
|
|
51946
|
+
}
|
|
51947
|
+
function cutAtBoundary(text, max) {
|
|
51948
|
+
const head = text.slice(0, max);
|
|
51949
|
+
const floor = Math.floor(max * 0.8);
|
|
51950
|
+
const paragraph = head.lastIndexOf("\n\n");
|
|
51951
|
+
if (paragraph >= floor) {
|
|
51952
|
+
return head.slice(0, paragraph).trimEnd();
|
|
51953
|
+
}
|
|
51954
|
+
const sentence = Math.max(head.lastIndexOf(". "), head.lastIndexOf(".\n"));
|
|
51955
|
+
if (sentence >= floor) {
|
|
51956
|
+
return head.slice(0, sentence + 1).trimEnd();
|
|
51957
|
+
}
|
|
51958
|
+
return head.trimEnd();
|
|
51959
|
+
}
|
|
51960
|
+
function truncateArticle(article, maxChars, site, url2) {
|
|
51961
|
+
if (!Number.isFinite(maxChars) || maxChars <= 0 || article.text.length <= maxChars) {
|
|
51962
|
+
return { article };
|
|
51963
|
+
}
|
|
51964
|
+
const totalChars = article.text.length;
|
|
51965
|
+
const kept = cutAtBoundary(article.text, maxChars);
|
|
51966
|
+
const command = fetchFullTextCommand(site, url2);
|
|
51967
|
+
const message = `Only the first ${kept.length.toLocaleString("en-US")} of ${totalChars.toLocaleString("en-US")} characters of this article's text are included here (its full outline is kept in "article.outline"). The complete text can be fetched on demand with the command below.`;
|
|
51968
|
+
const { html: _html, references: _references, ...rest } = article;
|
|
51969
|
+
return {
|
|
51970
|
+
article: {
|
|
51971
|
+
...rest,
|
|
51972
|
+
text: `${kept}
|
|
51973
|
+
|
|
51974
|
+
[\u2026 truncated: showing the first ${kept.length} of ${totalChars} characters. Fetch the complete text on demand: ${command}]`
|
|
51975
|
+
},
|
|
51976
|
+
moreAvailable: { reason: "truncated", message, command, shownChars: kept.length, totalChars }
|
|
51977
|
+
};
|
|
51978
|
+
}
|
|
51979
|
+
function deferredFullText(site, url2, budgetMs) {
|
|
51980
|
+
const seconds = Math.round(budgetMs / 100) / 10;
|
|
51981
|
+
return {
|
|
51982
|
+
reason: "deferred",
|
|
51983
|
+
message: `Full text was NOT fetched in this search: this article was still being prepared by the site after the ${seconds}s full-text time budget (very large articles, such as book chapters, can take 10s or more), and waiting would have held up everything else. Its title, url and snippet are still valid. The full text can be fetched on demand with the command below.`,
|
|
51984
|
+
command: fetchFullTextCommand(site, url2)
|
|
51985
|
+
};
|
|
51986
|
+
}
|
|
51987
|
+
|
|
51784
51988
|
// src/output/searchMarkdown.ts
|
|
51785
51989
|
var fs10 = __toESM(require("fs"));
|
|
51786
51990
|
var path9 = __toESM(require("path"));
|
|
@@ -51873,6 +52077,25 @@ function renderSearchMarkdown(doc, now = /* @__PURE__ */ new Date()) {
|
|
|
51873
52077
|
"_Full text was retrieved (kept out of this report to stay readable \u2014 see the search command\u2019s JSON result)._",
|
|
51874
52078
|
""
|
|
51875
52079
|
);
|
|
52080
|
+
if (ref.moreAvailable?.reason === "truncated") {
|
|
52081
|
+
lines.push(
|
|
52082
|
+
`_The text in the JSON result is cut to ${ref.moreAvailable.shownChars ?? "?"} of ${ref.moreAvailable.totalChars ?? "?"} characters (its outline is complete). Fetch the full text on demand:_`,
|
|
52083
|
+
"",
|
|
52084
|
+
"```bash",
|
|
52085
|
+
ref.moreAvailable.command,
|
|
52086
|
+
"```",
|
|
52087
|
+
""
|
|
52088
|
+
);
|
|
52089
|
+
}
|
|
52090
|
+
} else if (ref.moreAvailable?.reason === "deferred") {
|
|
52091
|
+
lines.push(
|
|
52092
|
+
"_Full text was deferred (the site was still preparing this article when the full-text time budget ran out) \u2014 not a failure. Fetch it on demand:_",
|
|
52093
|
+
"",
|
|
52094
|
+
"```bash",
|
|
52095
|
+
ref.moreAvailable.command,
|
|
52096
|
+
"```",
|
|
52097
|
+
""
|
|
52098
|
+
);
|
|
51876
52099
|
} else if (ref.fetchError) {
|
|
51877
52100
|
lines.push(
|
|
51878
52101
|
`_Full text unavailable (\`${ref.fetchError.code}\`: ${inline(ref.fetchError.error)})._`,
|
|
@@ -52013,6 +52236,63 @@ function isExistingDirectory2(candidate) {
|
|
|
52013
52236
|
|
|
52014
52237
|
// src/auth/sessionPreflight.ts
|
|
52015
52238
|
init_endpointLearner();
|
|
52239
|
+
|
|
52240
|
+
// src/auth/validationStamp.ts
|
|
52241
|
+
var import_crypto2 = require("crypto");
|
|
52242
|
+
var fs12 = __toESM(require("fs"));
|
|
52243
|
+
var path11 = __toESM(require("path"));
|
|
52244
|
+
var RECENT_VALIDATION_TTL_MS = 6e4;
|
|
52245
|
+
function defaultValidationDir() {
|
|
52246
|
+
return process.env.WEB_CLI_VALIDATION_DIR || path11.join(WEB_CLI_HOME, "session-validated");
|
|
52247
|
+
}
|
|
52248
|
+
function defaultWorkspaceValidationDir() {
|
|
52249
|
+
return process.env.WEB_CLI_WORKSPACE_VALIDATION_DIR || path11.join(process.cwd(), ".web-cli", "session-validated");
|
|
52250
|
+
}
|
|
52251
|
+
function fingerprintJar(jar) {
|
|
52252
|
+
const canonical = Object.keys(jar).sort().map((name) => `${name}=${jar[name]}`).join("\n");
|
|
52253
|
+
return (0, import_crypto2.createHash)("sha256").update(canonical).digest("hex").slice(0, 32);
|
|
52254
|
+
}
|
|
52255
|
+
function stampFile(dir, site) {
|
|
52256
|
+
return path11.join(dir, `${site.replace(/[^a-zA-Z0-9._-]/g, "_")}.json`);
|
|
52257
|
+
}
|
|
52258
|
+
function readStamp(dir, site) {
|
|
52259
|
+
try {
|
|
52260
|
+
const parsed = JSON.parse(fs12.readFileSync(stampFile(dir, site), "utf8"));
|
|
52261
|
+
if (typeof parsed.validatedAt === "number" && typeof parsed.fingerprint === "string") {
|
|
52262
|
+
return { validatedAt: parsed.validatedAt, fingerprint: parsed.fingerprint };
|
|
52263
|
+
}
|
|
52264
|
+
} catch {
|
|
52265
|
+
}
|
|
52266
|
+
return void 0;
|
|
52267
|
+
}
|
|
52268
|
+
function markSessionValidated(site, jar, deps = {}) {
|
|
52269
|
+
const payload = JSON.stringify({
|
|
52270
|
+
validatedAt: (deps.now ?? Date.now)(),
|
|
52271
|
+
fingerprint: fingerprintJar(jar)
|
|
52272
|
+
});
|
|
52273
|
+
for (const dir of [deps.dir ?? defaultValidationDir(), deps.workspaceDir ?? defaultWorkspaceValidationDir()]) {
|
|
52274
|
+
try {
|
|
52275
|
+
fs12.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
52276
|
+
fs12.writeFileSync(stampFile(dir, site), payload, { mode: 384 });
|
|
52277
|
+
return;
|
|
52278
|
+
} catch {
|
|
52279
|
+
}
|
|
52280
|
+
}
|
|
52281
|
+
}
|
|
52282
|
+
function wasRecentlyValidated(site, jar, deps = {}) {
|
|
52283
|
+
const now = (deps.now ?? Date.now)();
|
|
52284
|
+
const ttlMs = deps.ttlMs ?? RECENT_VALIDATION_TTL_MS;
|
|
52285
|
+
const fingerprint = fingerprintJar(jar);
|
|
52286
|
+
const stamps = [deps.dir ?? defaultValidationDir(), deps.workspaceDir ?? defaultWorkspaceValidationDir()].map((dir) => readStamp(dir, site)).filter((s) => s !== void 0);
|
|
52287
|
+
const newest = stamps.sort((a, b) => b.validatedAt - a.validatedAt)[0];
|
|
52288
|
+
if (!newest || newest.fingerprint !== fingerprint) {
|
|
52289
|
+
return false;
|
|
52290
|
+
}
|
|
52291
|
+
const age = now - newest.validatedAt;
|
|
52292
|
+
return age >= 0 && age <= ttlMs;
|
|
52293
|
+
}
|
|
52294
|
+
|
|
52295
|
+
// src/auth/sessionPreflight.ts
|
|
52016
52296
|
function templateFor(site, intent = "search") {
|
|
52017
52297
|
return readTemplate(site, intent) ?? getPreseedTemplate(site, intent);
|
|
52018
52298
|
}
|
|
@@ -52030,30 +52310,34 @@ async function probeWithJar(site, probeQuery, jar) {
|
|
|
52030
52310
|
const header = cookieJarToHeader(jar);
|
|
52031
52311
|
const searchTemplate = templateFor(site, "search");
|
|
52032
52312
|
if (!searchTemplate) {
|
|
52033
|
-
return "unknown";
|
|
52313
|
+
return { state: "unknown" };
|
|
52034
52314
|
}
|
|
52035
52315
|
let searchData;
|
|
52036
52316
|
try {
|
|
52037
|
-
searchData = await callTemplate(renderTemplate(searchTemplate, probeQuery), header);
|
|
52317
|
+
searchData = await callTemplate(renderTemplate(searchTemplate, probeQuery), header, SEARCH_CALL_OPTIONS);
|
|
52038
52318
|
} catch (err) {
|
|
52039
|
-
return isAuthFailure(err) ? "expired" : "unknown";
|
|
52319
|
+
return { state: isAuthFailure(err) ? "expired" : "unknown" };
|
|
52040
52320
|
}
|
|
52321
|
+
const reusable = readTemplate(site, "search") ? { searchData } : {};
|
|
52041
52322
|
const articleTemplate = templateFor(site, "getArticle");
|
|
52042
52323
|
if (!articleTemplate) {
|
|
52043
|
-
return "valid";
|
|
52324
|
+
return { state: "valid", ...reusable };
|
|
52325
|
+
}
|
|
52326
|
+
if (wasRecentlyValidated(site, jar)) {
|
|
52327
|
+
return { state: "valid", ...reusable };
|
|
52044
52328
|
}
|
|
52045
52329
|
let key = articleKeyFrom(site, searchData, config2.baseUrl);
|
|
52046
52330
|
if (!key && probeQuery !== PROBE_CANARY_QUERY) {
|
|
52047
52331
|
let canaryData;
|
|
52048
52332
|
try {
|
|
52049
|
-
canaryData = await callTemplate(renderTemplate(searchTemplate, PROBE_CANARY_QUERY), header);
|
|
52333
|
+
canaryData = await callTemplate(renderTemplate(searchTemplate, PROBE_CANARY_QUERY), header, SEARCH_CALL_OPTIONS);
|
|
52050
52334
|
} catch (err) {
|
|
52051
|
-
return isAuthFailure(err) ? "expired" : "valid";
|
|
52335
|
+
return isAuthFailure(err) ? { state: "expired" } : { state: "valid", ...reusable };
|
|
52052
52336
|
}
|
|
52053
52337
|
key = articleKeyFrom(site, canaryData, config2.baseUrl);
|
|
52054
52338
|
}
|
|
52055
52339
|
if (!key) {
|
|
52056
|
-
return "valid";
|
|
52340
|
+
return { state: "valid", ...reusable };
|
|
52057
52341
|
}
|
|
52058
52342
|
try {
|
|
52059
52343
|
const articleData = await callTemplate(
|
|
@@ -52061,40 +52345,32 @@ async function probeWithJar(site, probeQuery, jar) {
|
|
|
52061
52345
|
header
|
|
52062
52346
|
);
|
|
52063
52347
|
if (looksPaywalled(site, articleData, config2.baseUrl)) {
|
|
52064
|
-
return "expired";
|
|
52348
|
+
return { state: "expired" };
|
|
52065
52349
|
}
|
|
52066
|
-
|
|
52350
|
+
markSessionValidated(site, jar);
|
|
52351
|
+
const reusableArticle = readTemplate(site, "getArticle") ? { article: { key, data: articleData } } : {};
|
|
52352
|
+
return { state: "valid", ...reusable, ...reusableArticle };
|
|
52067
52353
|
} catch (err) {
|
|
52068
|
-
return isAuthFailure(err) ? "expired" : "valid";
|
|
52354
|
+
return isAuthFailure(err) ? { state: "expired" } : { state: "valid", ...reusable };
|
|
52069
52355
|
}
|
|
52070
52356
|
}
|
|
52071
|
-
async function
|
|
52357
|
+
async function probeSession(site, probeQuery) {
|
|
52072
52358
|
const config2 = getSiteConfig(site);
|
|
52073
52359
|
const jar = getEstablishedSession(site) ?? mergeStoredSession(await getLiveCookieJar(config2.host), await loadSessionJar(site));
|
|
52074
52360
|
if (Object.keys(jar).length === 0) {
|
|
52075
|
-
return "expired";
|
|
52361
|
+
return { state: "expired" };
|
|
52076
52362
|
}
|
|
52077
52363
|
return probeWithJar(site, probeQuery, jar);
|
|
52078
52364
|
}
|
|
52079
|
-
|
|
52080
|
-
|
|
52365
|
+
function asProbeResult(value) {
|
|
52366
|
+
return typeof value === "string" ? { state: value } : value;
|
|
52367
|
+
}
|
|
52368
|
+
function startSessionPreflight(sites2, probeQuery, opts = {}) {
|
|
52369
|
+
const checkState = opts.checkState ?? probeSession;
|
|
52081
52370
|
const login = opts.login ?? ensureInteractiveLogin;
|
|
52082
52371
|
const candidates = sites2.filter((site) => getSiteConfig(site).requiresLogin !== false);
|
|
52083
|
-
|
|
52084
|
-
|
|
52085
|
-
try {
|
|
52086
|
-
return { site, state: await checkState(site, probeQuery) };
|
|
52087
|
-
} catch {
|
|
52088
|
-
return { site, state: "unknown" };
|
|
52089
|
-
}
|
|
52090
|
-
})
|
|
52091
|
-
);
|
|
52092
|
-
const outcomes = [];
|
|
52093
|
-
for (const { site, state } of states) {
|
|
52094
|
-
if (state !== "expired") {
|
|
52095
|
-
outcomes.push({ site, state, loggedIn: false });
|
|
52096
|
-
continue;
|
|
52097
|
-
}
|
|
52372
|
+
let loginChain = Promise.resolve();
|
|
52373
|
+
const signIn = async (site, state) => {
|
|
52098
52374
|
try {
|
|
52099
52375
|
await login({
|
|
52100
52376
|
site,
|
|
@@ -52106,20 +52382,41 @@ async function ensureSessionsForSites(sites2, probeQuery, opts = {}) {
|
|
|
52106
52382
|
// The same probe as the up-front check, which is what makes this window stay open until
|
|
52107
52383
|
// the user is genuinely signed in rather than closing the moment the site hands out an
|
|
52108
52384
|
// anonymous session.
|
|
52109
|
-
isSessionReady: async (jar) => await probeWithJar(site, probeQuery, jar) !== "expired",
|
|
52385
|
+
isSessionReady: async (jar) => (await probeWithJar(site, probeQuery, jar)).state !== "expired",
|
|
52110
52386
|
allowVisible: opts.allowVisible === true
|
|
52111
52387
|
});
|
|
52112
|
-
|
|
52388
|
+
return { site, state, loggedIn: true };
|
|
52113
52389
|
} catch (err) {
|
|
52114
|
-
|
|
52115
|
-
site,
|
|
52116
|
-
state,
|
|
52117
|
-
loggedIn: false,
|
|
52118
|
-
error: err instanceof Error ? err.message : String(err)
|
|
52119
|
-
});
|
|
52390
|
+
return { site, state, loggedIn: false, error: err instanceof Error ? err.message : String(err) };
|
|
52120
52391
|
}
|
|
52392
|
+
};
|
|
52393
|
+
const result = /* @__PURE__ */ new Map();
|
|
52394
|
+
for (const site of candidates) {
|
|
52395
|
+
result.set(
|
|
52396
|
+
site,
|
|
52397
|
+
(async () => {
|
|
52398
|
+
let probe;
|
|
52399
|
+
try {
|
|
52400
|
+
probe = asProbeResult(await checkState(site, probeQuery));
|
|
52401
|
+
} catch {
|
|
52402
|
+
probe = { state: "unknown" };
|
|
52403
|
+
}
|
|
52404
|
+
if (probe.state !== "expired") {
|
|
52405
|
+
return {
|
|
52406
|
+
site,
|
|
52407
|
+
state: probe.state,
|
|
52408
|
+
loggedIn: false,
|
|
52409
|
+
...probe.searchData !== void 0 ? { searchData: probe.searchData } : {},
|
|
52410
|
+
...probe.article !== void 0 ? { article: probe.article } : {}
|
|
52411
|
+
};
|
|
52412
|
+
}
|
|
52413
|
+
const attempt = loginChain.then(() => signIn(site, probe.state));
|
|
52414
|
+
loginChain = attempt;
|
|
52415
|
+
return attempt;
|
|
52416
|
+
})()
|
|
52417
|
+
);
|
|
52121
52418
|
}
|
|
52122
|
-
return
|
|
52419
|
+
return result;
|
|
52123
52420
|
}
|
|
52124
52421
|
|
|
52125
52422
|
// src/commands/search.ts
|
|
@@ -52130,10 +52427,17 @@ function describeError(err) {
|
|
|
52130
52427
|
code: err instanceof CliError ? err.code : "INTERNAL_ERROR"
|
|
52131
52428
|
};
|
|
52132
52429
|
}
|
|
52133
|
-
function recommendedActionFor(code, site) {
|
|
52430
|
+
function recommendedActionFor(code, site, sessionExpiredContext) {
|
|
52134
52431
|
switch (code) {
|
|
52135
|
-
case "SESSION_EXPIRED":
|
|
52432
|
+
case "SESSION_EXPIRED": {
|
|
52433
|
+
if (sessionExpiredContext && !sessionExpiredContext.siteSupportsLogin) {
|
|
52434
|
+
return `"${site}" has no login/account concept at all (requiresLogin: false), so web-cli never attempted a credential-based refresh here \u2014 there is nothing to sign into, and telling the user to save credentials or sign in would be wrong. This SESSION_EXPIRED means the site's own short-lived per-request token went stale; simply retrying re-discovers a fresh one automatically. If it keeps failing, run "web-cli observe --site ${site} --intent search --param \\"<a real query>\\"" once to re-learn the endpoint by hand. Never substitute another site's results in place of this one without saying so.`;
|
|
52435
|
+
}
|
|
52436
|
+
if (sessionExpiredContext?.hasCredential) {
|
|
52437
|
+
return `A credential is ALREADY saved for "${site}" \u2014 web-cli's own silent, credential-based refresh already tried it before returning this. Do NOT tell the user to run "web-cli login ${site} --save-credentials" again as if nothing were saved; it is, and re-saving an unchanged password will not fix this. The likely cause is something the automatic form-fill cannot get past on its own (a CAPTCHA, a 2FA prompt, a changed login page) or a now-incorrect saved password. Tell the user to re-run with --allow-visible-login to sign in by hand and see what is actually blocking it, or run "web-cli login ${site}" directly \u2014 and to re-save credentials only if the password genuinely changed. Never substitute another site's results, a previously-saved file, or any other data in place of this one without saying so.`;
|
|
52438
|
+
}
|
|
52136
52439
|
return `The silent, credential-based session refresh for "${site}" already ran and did not recover \u2014 do not retry the same call expecting a different result. Tell the user to run "web-cli login ${site} --save-credentials" once so every future run recovers silently with no human needed, or re-run with --allow-visible-login if a human can sign in right now. Never substitute another site's results, a previously-saved file, or any other data in place of this one without saying so.`;
|
|
52440
|
+
}
|
|
52137
52441
|
case "DISCOVERY_FAILED":
|
|
52138
52442
|
return `This site's endpoint needs re-learning: run "web-cli observe --site ${site} --intent <search|getArticle> --param \\"<a real query/article for ${site}>\\"" once, then retry.`;
|
|
52139
52443
|
case "ARTICLE_MISMATCH":
|
|
@@ -52144,7 +52448,27 @@ function recommendedActionFor(code, site) {
|
|
|
52144
52448
|
return `No specific automatic recovery is known for this code ("${code}") \u2014 do not silently drop or paper over it; state the failure and its message/code plainly in your answer.`;
|
|
52145
52449
|
}
|
|
52146
52450
|
}
|
|
52147
|
-
function buildAgentTask(query, keyReferences, sites2) {
|
|
52451
|
+
async function buildAgentTask(query, keyReferences, sites2) {
|
|
52452
|
+
const sessionExpiredSites = /* @__PURE__ */ new Set();
|
|
52453
|
+
for (const [site, outcome] of Object.entries(sites2)) {
|
|
52454
|
+
if (outcome.error !== void 0 && (outcome.code ?? "INTERNAL_ERROR") === "SESSION_EXPIRED") {
|
|
52455
|
+
sessionExpiredSites.add(site);
|
|
52456
|
+
}
|
|
52457
|
+
}
|
|
52458
|
+
for (const ref of keyReferences) {
|
|
52459
|
+
if (ref.fetchError !== void 0 && (ref.fetchError.code ?? "INTERNAL_ERROR") === "SESSION_EXPIRED") {
|
|
52460
|
+
sessionExpiredSites.add(ref.site);
|
|
52461
|
+
}
|
|
52462
|
+
}
|
|
52463
|
+
const sessionExpiredContext = new Map(
|
|
52464
|
+
await Promise.all(
|
|
52465
|
+
Array.from(sessionExpiredSites).map(async (site) => {
|
|
52466
|
+
const siteSupportsLogin = getSiteConfig(site).requiresLogin !== false;
|
|
52467
|
+
const hasCredential = siteSupportsLogin ? await hasStoredCredentials(site) : false;
|
|
52468
|
+
return [site, { siteSupportsLogin, hasCredential }];
|
|
52469
|
+
})
|
|
52470
|
+
)
|
|
52471
|
+
);
|
|
52148
52472
|
const unrecoveredFailures = [];
|
|
52149
52473
|
for (const [site, outcome] of Object.entries(sites2)) {
|
|
52150
52474
|
if (outcome.error !== void 0) {
|
|
@@ -52154,7 +52478,7 @@ function buildAgentTask(query, keyReferences, sites2) {
|
|
|
52154
52478
|
site,
|
|
52155
52479
|
code,
|
|
52156
52480
|
error: outcome.error,
|
|
52157
|
-
recommendedAction: recommendedActionFor(code, site)
|
|
52481
|
+
recommendedAction: recommendedActionFor(code, site, sessionExpiredContext.get(site))
|
|
52158
52482
|
});
|
|
52159
52483
|
}
|
|
52160
52484
|
}
|
|
@@ -52168,12 +52492,18 @@ function buildAgentTask(query, keyReferences, sites2) {
|
|
|
52168
52492
|
url: ref.url,
|
|
52169
52493
|
code,
|
|
52170
52494
|
error: ref.fetchError.error,
|
|
52171
|
-
recommendedAction: recommendedActionFor(code, ref.site)
|
|
52495
|
+
recommendedAction: recommendedActionFor(code, ref.site, sessionExpiredContext.get(ref.site))
|
|
52172
52496
|
});
|
|
52173
52497
|
}
|
|
52174
52498
|
}
|
|
52175
52499
|
const failureNote = unrecoveredFailures.length > 0 ? ` IMPORTANT: "unrecoveredFailures" lists ${pluralize(unrecoveredFailures.length, "source")} that did NOT come back (web-cli's own default recovery already ran for these and did not succeed) \u2014 you must state plainly, in your answer, which source(s) failed and why, and follow each entry's own "recommendedAction". Never silently substitute another site's results or any previously-cached/saved data in their place, and never present the answer as if coverage were complete when it wasn't.` : "";
|
|
52176
52500
|
const withFullText = keyReferences.filter((ref) => !!ref.article?.text);
|
|
52501
|
+
const deferred = keyReferences.filter((ref) => ref.moreAvailable?.reason === "deferred");
|
|
52502
|
+
const truncated = keyReferences.filter((ref) => ref.moreAvailable?.reason === "truncated");
|
|
52503
|
+
const moreAvailableNote = deferred.length + truncated.length > 0 ? ` MORE DETAIL IS AVAILABLE ON DEMAND (this is NOT a failure and is not in "unrecoveredFailures"): ` + [
|
|
52504
|
+
deferred.length > 0 ? `${pluralize(deferred.length, "reference")} ${deferred.length === 1 ? "was" : "were"} DEFERRED \u2014 no "article" is included because the site was still preparing ${deferred.length === 1 ? "it" : "them"} when the full-text time budget ran out; their "title", "url" and "snippet" are valid` : void 0,
|
|
52505
|
+
truncated.length > 0 ? `${pluralize(truncated.length, "reference")} ${truncated.length === 1 ? "is" : "are"} TRUNCATED \u2014 "article.text" stops partway (it ends with a "[\u2026 truncated \u2026]" line) but "article.outline" lists every section, so you can see what the rest holds` : void 0
|
|
52506
|
+
].filter((part) => part !== void 0).join("; ") + `. Every such entry has a "moreAvailable" field whose "command" is an exact, ready-to-run shell command that fetches that article's COMPLETE text on demand (\`web-cli get <site> '<url>'\` \u2014 the same "url" shown on the entry). If the snippet, outline or truncated text is not enough to answer the question, RUN THAT COMMAND for the one or two entries that matter most (a large chapter can take 10-15s to come back) instead of answering from partial material or guessing; don't fetch every one by reflex. Until you have fetched it, treat what you can see of such an entry as incomplete and say so if you rely on it.` : "";
|
|
52177
52507
|
if (keyReferences.length === 0) {
|
|
52178
52508
|
return {
|
|
52179
52509
|
question: query,
|
|
@@ -52183,7 +52513,7 @@ function buildAgentTask(query, keyReferences, sites2) {
|
|
|
52183
52513
|
}
|
|
52184
52514
|
return {
|
|
52185
52515
|
question: query,
|
|
52186
|
-
instructions: `Answer the question above using the material already retrieved into "keyReferences" \u2014 do not just relay this JSON, "summary", or a list of titles as if that were the answer. For each "keyReferences" entry that has "article.text": read it and decide whether it actually helps answer the question. If it does, cite it (its "url") in your answer. If it does not, treat it as irrelevant to this question \u2014 leave it out of your answer entirely, rather than citing it just because it was fetched.` + (withFullText.length < keyReferences.length ? ` For an entry with no "article.text" (see "fetchError"/omitted from ${withFullText.length}/${keyReferences.length} with full text in "summary.keyReferences"), fall back to its "snippet" instead of skipping it, but note that fallback is unconfirmed.` : "") + ` If nothing retrieved actually answers the question, say so plainly rather than forcing an answer out of unrelated material.` + failureNote,
|
|
52516
|
+
instructions: `Answer the question above using the material already retrieved into "keyReferences" \u2014 do not just relay this JSON, "summary", or a list of titles as if that were the answer. For each "keyReferences" entry that has "article.text": read it and decide whether it actually helps answer the question. If it does, cite it (its "url") in your answer. If it does not, treat it as irrelevant to this question \u2014 leave it out of your answer entirely, rather than citing it just because it was fetched.` + (withFullText.length < keyReferences.length ? ` For an entry with no "article.text" (see "fetchError"/omitted from ${withFullText.length}/${keyReferences.length} with full text in "summary.keyReferences"), fall back to its "snippet" instead of skipping it, but note that fallback is unconfirmed.` : "") + moreAvailableNote + ` If nothing retrieved actually answers the question, say so plainly rather than forcing an answer out of unrelated material.` + failureNote,
|
|
52187
52517
|
...unrecoveredFailures.length > 0 ? { unrecoveredFailures } : {}
|
|
52188
52518
|
};
|
|
52189
52519
|
}
|
|
@@ -52202,7 +52532,7 @@ function formatSiteSettledNotice(site, outcome, err) {
|
|
|
52202
52532
|
const hitCount = siteHitCount(outcome);
|
|
52203
52533
|
return hitCount === null ? `web-cli: ${site} finished \u2014 hit count unavailable (response shape not recognized)` : `web-cli: ${site} finished \u2014 ${pluralize(hitCount, "hit")}`;
|
|
52204
52534
|
}
|
|
52205
|
-
async function expandKeyReference(site, hit, baseUrl, replayOpts) {
|
|
52535
|
+
async function expandKeyReference(site, hit, baseUrl, replayOpts, prefetched, limits = {}) {
|
|
52206
52536
|
const base = {
|
|
52207
52537
|
site,
|
|
52208
52538
|
title: hit.title,
|
|
@@ -52214,7 +52544,15 @@ async function expandKeyReference(site, hit, baseUrl, replayOpts) {
|
|
|
52214
52544
|
};
|
|
52215
52545
|
const fetchKey = hit.url ?? hit.id;
|
|
52216
52546
|
try {
|
|
52217
|
-
const
|
|
52547
|
+
const usePrefetched = prefetched !== void 0 && prefetched.key === fetchKey;
|
|
52548
|
+
const { data } = usePrefetched ? { data: prefetched.data } : await replay(
|
|
52549
|
+
site,
|
|
52550
|
+
"getArticle",
|
|
52551
|
+
fetchKey,
|
|
52552
|
+
// Only a LIMITED budget cancels anything; an unlimited one leaves the call exactly as it
|
|
52553
|
+
// was, so a caller that opted out of the budget gets the old behavior byte for byte.
|
|
52554
|
+
limits.budget?.limited ? { ...replayOpts, signal: limits.budget.signal } : replayOpts
|
|
52555
|
+
);
|
|
52218
52556
|
const article = parseArticle3(site, data, baseUrl);
|
|
52219
52557
|
if (article?.id !== void 0 && hit.id !== void 0 && String(article.id) !== String(hit.id)) {
|
|
52220
52558
|
return {
|
|
@@ -52234,19 +52572,56 @@ async function expandKeyReference(site, hit, baseUrl, replayOpts) {
|
|
|
52234
52572
|
}
|
|
52235
52573
|
};
|
|
52236
52574
|
}
|
|
52237
|
-
|
|
52575
|
+
if (!article) {
|
|
52576
|
+
return { ...base, article: void 0 };
|
|
52577
|
+
}
|
|
52578
|
+
if (article.text) {
|
|
52579
|
+
limits.budget?.noteFetched();
|
|
52580
|
+
}
|
|
52581
|
+
const truncated = truncateArticle(article, limits.maxArticleChars ?? 0, site, fetchKey);
|
|
52582
|
+
return {
|
|
52583
|
+
...base,
|
|
52584
|
+
article: truncated.article,
|
|
52585
|
+
...truncated.moreAvailable ? { moreAvailable: truncated.moreAvailable } : {}
|
|
52586
|
+
};
|
|
52238
52587
|
} catch (err) {
|
|
52588
|
+
if (limits.budget?.aborted && isAbortError(err)) {
|
|
52589
|
+
return { ...base, moreAvailable: deferredFullText(site, fetchKey, limits.budget.budgetMs) };
|
|
52590
|
+
}
|
|
52239
52591
|
return { ...base, fetchError: describeError(err) };
|
|
52240
52592
|
}
|
|
52241
52593
|
}
|
|
52242
|
-
async function searchOneSite(site, query, replayOpts) {
|
|
52594
|
+
async function searchOneSite(site, query, replayOpts, preflight, limits = {}) {
|
|
52243
52595
|
const config2 = getSiteConfig(site);
|
|
52244
|
-
const
|
|
52596
|
+
const session = preflight ? await preflight : void 0;
|
|
52597
|
+
let data;
|
|
52598
|
+
let discovered;
|
|
52599
|
+
if (session && session.state !== "expired" && session.searchData !== void 0) {
|
|
52600
|
+
data = session.searchData;
|
|
52601
|
+
discovered = false;
|
|
52602
|
+
} else {
|
|
52603
|
+
({ data, discovered } = await replay(site, "search", query, replayOpts));
|
|
52604
|
+
}
|
|
52245
52605
|
const parsed = parseSearchResults4(site, data, config2.baseUrl);
|
|
52246
52606
|
const selected = parsed && !NO_KEY_REFERENCE_EXPANSION_SITES.has(site) ? selectKeyReferences(parsed.hits) : [];
|
|
52247
|
-
const
|
|
52248
|
-
|
|
52249
|
-
)
|
|
52607
|
+
const prefetched = session && session.state !== "expired" ? session.article : void 0;
|
|
52608
|
+
const budget = new FullTextBudget(limits.fullTextBudgetMs ?? 0);
|
|
52609
|
+
if (prefetched) {
|
|
52610
|
+
budget.noteFetched();
|
|
52611
|
+
}
|
|
52612
|
+
let keyReferences;
|
|
52613
|
+
try {
|
|
52614
|
+
keyReferences = await Promise.all(
|
|
52615
|
+
selected.map(
|
|
52616
|
+
(hit) => expandKeyReference(site, hit, config2.baseUrl, replayOpts, prefetched, {
|
|
52617
|
+
budget,
|
|
52618
|
+
maxArticleChars: limits.maxArticleChars
|
|
52619
|
+
})
|
|
52620
|
+
)
|
|
52621
|
+
);
|
|
52622
|
+
} finally {
|
|
52623
|
+
budget.dispose();
|
|
52624
|
+
}
|
|
52250
52625
|
return { outcome: { discovered, results: data, parsed }, keyReferences };
|
|
52251
52626
|
}
|
|
52252
52627
|
var DEFAULT_SITE_TIMEOUT_MS = 18e4;
|
|
@@ -52282,6 +52657,8 @@ function withSiteTimeout(promise, site, timeoutMs, excludedWaitMs = getInteracti
|
|
|
52282
52657
|
}
|
|
52283
52658
|
async function runSearch(query, extraSites = [], opts = {}) {
|
|
52284
52659
|
const siteTimeoutMs = opts.siteTimeoutMs ?? DEFAULT_SITE_TIMEOUT_MS;
|
|
52660
|
+
const fullTextBudgetMs = opts.fullTextBudgetMs ?? DEFAULT_FULLTEXT_BUDGET_MS;
|
|
52661
|
+
const maxArticleChars = opts.maxArticleChars ?? DEFAULT_MAX_ARTICLE_CHARS;
|
|
52285
52662
|
const notify = opts.notify ?? ((message) => process.stderr.write(`${message}
|
|
52286
52663
|
`));
|
|
52287
52664
|
const siteNames = Array.from(/* @__PURE__ */ new Set([...MEDICAL_SEARCH_SITES, ...extraSites]));
|
|
@@ -52325,16 +52702,20 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52325
52702
|
`);
|
|
52326
52703
|
}
|
|
52327
52704
|
}
|
|
52328
|
-
let loginAttempts = [];
|
|
52329
|
-
if (replayOpts.disableLoginRecovery !== true) {
|
|
52330
|
-
const outcomes2 = await ensureSessionsForSites(siteNames, query, {
|
|
52331
|
-
loginTimeoutMs: replayOpts.loginTimeoutMs,
|
|
52332
|
-
allowVisible: replayOpts.allowVisibleLogin
|
|
52333
|
-
});
|
|
52334
|
-
loginAttempts = outcomes2.filter((outcome) => outcome.state === "expired");
|
|
52335
|
-
}
|
|
52336
52705
|
notify(`web-cli: searching ${pluralize(siteNames.length, "site")} \u2014 ${siteNames.join(", ")}`);
|
|
52337
|
-
const
|
|
52706
|
+
const preflight = replayOpts.disableLoginRecovery !== true ? startSessionPreflight(siteNames, query, {
|
|
52707
|
+
loginTimeoutMs: replayOpts.loginTimeoutMs,
|
|
52708
|
+
allowVisible: replayOpts.allowVisibleLogin
|
|
52709
|
+
}) : /* @__PURE__ */ new Map();
|
|
52710
|
+
const settledPreflight = [];
|
|
52711
|
+
preflight.forEach((promise) => void promise.then((outcome) => settledPreflight.push(outcome)));
|
|
52712
|
+
const sitePromises = siteNames.map(
|
|
52713
|
+
(site) => withSiteTimeout(
|
|
52714
|
+
searchOneSite(site, query, replayOpts, preflight.get(site), { fullTextBudgetMs, maxArticleChars }),
|
|
52715
|
+
site,
|
|
52716
|
+
siteTimeoutMs
|
|
52717
|
+
)
|
|
52718
|
+
);
|
|
52338
52719
|
sitePromises.forEach((promise, i) => {
|
|
52339
52720
|
const site = siteNames[i];
|
|
52340
52721
|
promise.then(
|
|
@@ -52343,6 +52724,7 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52343
52724
|
);
|
|
52344
52725
|
});
|
|
52345
52726
|
const outcomes = await Promise.allSettled(sitePromises);
|
|
52727
|
+
const loginAttempts = settledPreflight.filter((outcome) => outcome.state === "expired").sort((a, b) => siteNames.indexOf(a.site) - siteNames.indexOf(b.site)).map(({ searchData: _searchData, article: _article, ...outcome }) => outcome);
|
|
52346
52728
|
const sites2 = {};
|
|
52347
52729
|
const keyReferences = [];
|
|
52348
52730
|
const sitesSucceeded = [];
|
|
@@ -52367,6 +52749,8 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52367
52749
|
});
|
|
52368
52750
|
const fullTextFetched = keyReferences.filter((ref) => !!ref.article?.text).length;
|
|
52369
52751
|
const fullTextFailed = keyReferences.filter((ref) => ref.fetchError !== void 0).length;
|
|
52752
|
+
const fullTextDeferred = keyReferences.filter((ref) => ref.moreAvailable?.reason === "deferred").length;
|
|
52753
|
+
const fullTextTruncated = keyReferences.filter((ref) => ref.moreAvailable?.reason === "truncated").length;
|
|
52370
52754
|
const summary = {
|
|
52371
52755
|
sitesRequested: siteNames,
|
|
52372
52756
|
sitesSucceeded,
|
|
@@ -52377,7 +52761,9 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52377
52761
|
selected: keyReferences.length,
|
|
52378
52762
|
fullTextFetched,
|
|
52379
52763
|
fullTextFailed,
|
|
52380
|
-
|
|
52764
|
+
fullTextDeferred,
|
|
52765
|
+
fullTextTruncated,
|
|
52766
|
+
fullTextUnparsed: keyReferences.length - fullTextFetched - fullTextFailed - fullTextDeferred
|
|
52381
52767
|
}
|
|
52382
52768
|
};
|
|
52383
52769
|
notify(
|
|
@@ -52396,10 +52782,11 @@ async function runSearch(query, extraSites = [], opts = {}) {
|
|
|
52396
52782
|
markdownPath = void 0;
|
|
52397
52783
|
}
|
|
52398
52784
|
}
|
|
52785
|
+
const agentTask = await buildAgentTask(query, keyReferences, sites2);
|
|
52399
52786
|
const result = {
|
|
52400
52787
|
...document2,
|
|
52401
52788
|
summary,
|
|
52402
|
-
agentTask
|
|
52789
|
+
agentTask,
|
|
52403
52790
|
...markdownPath !== void 0 ? { markdownPath } : {},
|
|
52404
52791
|
// Present only when something actually went wrong, so its mere presence is the signal.
|
|
52405
52792
|
...markdownError !== void 0 ? { markdownError } : {},
|
|
@@ -52689,6 +53076,8 @@ function renderSearchCoverage(stats) {
|
|
|
52689
53076
|
const parts = [
|
|
52690
53077
|
typeof kr.selected === "number" ? `${kr.selected} selected` : void 0,
|
|
52691
53078
|
typeof kr.fullTextFetched === "number" ? `${kr.fullTextFetched} with full text` : void 0,
|
|
53079
|
+
typeof kr.fullTextTruncated === "number" && kr.fullTextTruncated > 0 ? `${kr.fullTextTruncated} truncated` : void 0,
|
|
53080
|
+
typeof kr.fullTextDeferred === "number" && kr.fullTextDeferred > 0 ? `${kr.fullTextDeferred} deferred` : void 0,
|
|
52692
53081
|
typeof kr.fullTextFailed === "number" ? `${kr.fullTextFailed} fetch failed` : void 0,
|
|
52693
53082
|
typeof kr.fullTextUnparsed === "number" ? `${kr.fullTextUnparsed} unparsed` : void 0
|
|
52694
53083
|
].filter((p) => p !== void 0);
|
|
@@ -52896,7 +53285,7 @@ async function runFinalize(opts = {}, deps = {}) {
|
|
|
52896
53285
|
}
|
|
52897
53286
|
|
|
52898
53287
|
// src/commands/renderMarkdown.ts
|
|
52899
|
-
var
|
|
53288
|
+
var fs13 = __toESM(require("fs"));
|
|
52900
53289
|
function invalidInput2(message) {
|
|
52901
53290
|
throw new CliError(
|
|
52902
53291
|
"INVALID_INPUT",
|
|
@@ -52948,13 +53337,13 @@ function describeError3(err) {
|
|
|
52948
53337
|
code: err instanceof CliError ? err.code : "INTERNAL_ERROR"
|
|
52949
53338
|
};
|
|
52950
53339
|
}
|
|
52951
|
-
function readFromFile(
|
|
53340
|
+
function readFromFile(path14) {
|
|
52952
53341
|
try {
|
|
52953
|
-
return
|
|
53342
|
+
return fs13.readFileSync(path14, "utf8");
|
|
52954
53343
|
} catch (err) {
|
|
52955
53344
|
throw new CliError(
|
|
52956
53345
|
"INPUT_READ_FAILED",
|
|
52957
|
-
`Could not read --from ${
|
|
53346
|
+
`Could not read --from ${path14} (${err instanceof Error ? err.message : String(err)}).`
|
|
52958
53347
|
);
|
|
52959
53348
|
}
|
|
52960
53349
|
}
|
|
@@ -53108,7 +53497,7 @@ async function bingWebSearch(query, options = {}) {
|
|
|
53108
53497
|
}
|
|
53109
53498
|
|
|
53110
53499
|
// src/search/googleSearch.ts
|
|
53111
|
-
var
|
|
53500
|
+
var fs14 = __toESM(require("fs"));
|
|
53112
53501
|
var CDP2 = require_chrome_remote_interface();
|
|
53113
53502
|
var DEFAULT_MAX_RESULTS2 = 10;
|
|
53114
53503
|
var DEFAULT_SETTLE_MS = 3e3;
|
|
@@ -53227,7 +53616,7 @@ async function googleWebSearch(query, options = {}, deps = {}) {
|
|
|
53227
53616
|
function writeDebugHtml(debugHtmlPath, html) {
|
|
53228
53617
|
if (!debugHtmlPath) return;
|
|
53229
53618
|
try {
|
|
53230
|
-
|
|
53619
|
+
fs14.writeFileSync(debugHtmlPath, html);
|
|
53231
53620
|
} catch {
|
|
53232
53621
|
}
|
|
53233
53622
|
}
|
|
@@ -53408,9 +53797,9 @@ async function runWeather(location, options = {}) {
|
|
|
53408
53797
|
var os6 = __toESM(require("os"));
|
|
53409
53798
|
|
|
53410
53799
|
// src/skillInstall.ts
|
|
53411
|
-
var
|
|
53800
|
+
var fs15 = __toESM(require("fs"));
|
|
53412
53801
|
var os5 = __toESM(require("os"));
|
|
53413
|
-
var
|
|
53802
|
+
var path12 = __toESM(require("path"));
|
|
53414
53803
|
var SKILL_NAME = "web-cli";
|
|
53415
53804
|
var INSTALL_MARKER_FILE = ".installed-by-web-cli.json";
|
|
53416
53805
|
var COPY_EXCLUDES = /* @__PURE__ */ new Set([".DS_Store"]);
|
|
@@ -53418,34 +53807,34 @@ var AGENT_CHOICES = ["claude", "codex", "agents", "dsh"];
|
|
|
53418
53807
|
function resolveCodexHomeDir(homeDir, override) {
|
|
53419
53808
|
const fromEnv = process.env.CODEX_HOME;
|
|
53420
53809
|
if (override !== void 0) {
|
|
53421
|
-
return
|
|
53810
|
+
return path12.resolve(override);
|
|
53422
53811
|
}
|
|
53423
|
-
return fromEnv !== void 0 && fromEnv.trim().length > 0 ?
|
|
53812
|
+
return fromEnv !== void 0 && fromEnv.trim().length > 0 ? path12.resolve(fromEnv) : path12.join(homeDir, ".codex");
|
|
53424
53813
|
}
|
|
53425
53814
|
function resolveAgentsHomeDir(homeDir, override) {
|
|
53426
|
-
return override ?? process.env.DSH_AGENTS_HOME ??
|
|
53815
|
+
return override ?? process.env.DSH_AGENTS_HOME ?? path12.join(homeDir, ".agents");
|
|
53427
53816
|
}
|
|
53428
53817
|
function resolveDshHomeDir(homeDir, override) {
|
|
53429
53818
|
const fromEnv = process.env.DSH_HOME;
|
|
53430
53819
|
const configured = override ?? (fromEnv !== void 0 && fromEnv.trim().length > 0 ? fromEnv : void 0);
|
|
53431
53820
|
if (configured === void 0) {
|
|
53432
|
-
return
|
|
53821
|
+
return path12.join(homeDir, ".dsh");
|
|
53433
53822
|
}
|
|
53434
53823
|
if (configured === "~") {
|
|
53435
53824
|
return homeDir;
|
|
53436
53825
|
}
|
|
53437
53826
|
if (configured.startsWith("~/") || configured.startsWith("~\\")) {
|
|
53438
|
-
return
|
|
53827
|
+
return path12.join(homeDir, configured.slice(2));
|
|
53439
53828
|
}
|
|
53440
|
-
return
|
|
53829
|
+
return path12.resolve(configured);
|
|
53441
53830
|
}
|
|
53442
53831
|
function resolveShippedSkillDir(fromDir) {
|
|
53443
53832
|
const candidates = [
|
|
53444
|
-
|
|
53445
|
-
|
|
53833
|
+
path12.resolve(fromDir, "..", "skills", SKILL_NAME),
|
|
53834
|
+
path12.resolve(fromDir, "..", "..", "skills", SKILL_NAME)
|
|
53446
53835
|
];
|
|
53447
53836
|
for (const candidate of candidates) {
|
|
53448
|
-
if (
|
|
53837
|
+
if (fs15.existsSync(path12.join(candidate, "SKILL.md"))) {
|
|
53449
53838
|
return candidate;
|
|
53450
53839
|
}
|
|
53451
53840
|
}
|
|
@@ -53455,7 +53844,7 @@ function resolveShippedSkillDir(fromDir) {
|
|
|
53455
53844
|
}
|
|
53456
53845
|
function shippedSkillVersion(shippedSkillDir) {
|
|
53457
53846
|
try {
|
|
53458
|
-
const pkg = JSON.parse(
|
|
53847
|
+
const pkg = JSON.parse(fs15.readFileSync(path12.resolve(shippedSkillDir, "..", "..", "package.json"), "utf8"));
|
|
53459
53848
|
return typeof pkg.version === "string" ? pkg.version : void 0;
|
|
53460
53849
|
} catch {
|
|
53461
53850
|
return void 0;
|
|
@@ -53463,13 +53852,13 @@ function shippedSkillVersion(shippedSkillDir) {
|
|
|
53463
53852
|
}
|
|
53464
53853
|
function detectAgents(homeDir, overrides = {}) {
|
|
53465
53854
|
const detected = [];
|
|
53466
|
-
if (
|
|
53855
|
+
if (fs15.existsSync(path12.join(homeDir, ".claude"))) {
|
|
53467
53856
|
detected.push("claude");
|
|
53468
53857
|
}
|
|
53469
|
-
if (
|
|
53858
|
+
if (fs15.existsSync(resolveCodexHomeDir(homeDir, overrides.codexHomeDir))) {
|
|
53470
53859
|
detected.push("codex");
|
|
53471
53860
|
}
|
|
53472
|
-
if (
|
|
53861
|
+
if (fs15.existsSync(resolveDshHomeDir(homeDir, overrides.dshHomeDir))) {
|
|
53473
53862
|
detected.push("dsh");
|
|
53474
53863
|
}
|
|
53475
53864
|
return detected;
|
|
@@ -53492,14 +53881,14 @@ function resolveAgents(requested, homeDir, overrides = {}) {
|
|
|
53492
53881
|
var CODEX_PROMPT_MARKER = "# web-cli \u2014 search/retrieval CLI usage guidance";
|
|
53493
53882
|
function symlinkTarget(target) {
|
|
53494
53883
|
try {
|
|
53495
|
-
return
|
|
53884
|
+
return path12.resolve(path12.dirname(target), fs15.readlinkSync(target));
|
|
53496
53885
|
} catch {
|
|
53497
53886
|
return null;
|
|
53498
53887
|
}
|
|
53499
53888
|
}
|
|
53500
53889
|
function lstatOrNull(target) {
|
|
53501
53890
|
try {
|
|
53502
|
-
return
|
|
53891
|
+
return fs15.lstatSync(target);
|
|
53503
53892
|
} catch {
|
|
53504
53893
|
return null;
|
|
53505
53894
|
}
|
|
@@ -53507,14 +53896,14 @@ function lstatOrNull(target) {
|
|
|
53507
53896
|
function describeExisting(target) {
|
|
53508
53897
|
const linked = symlinkTarget(target);
|
|
53509
53898
|
if (linked) {
|
|
53510
|
-
return
|
|
53899
|
+
return fs15.existsSync(linked) ? `an existing symlink -> ${linked}` : `a dangling symlink -> ${linked}`;
|
|
53511
53900
|
}
|
|
53512
53901
|
const stats = lstatOrNull(target);
|
|
53513
53902
|
return stats?.isDirectory() ? "an existing directory" : "an existing file";
|
|
53514
53903
|
}
|
|
53515
53904
|
function isOurSkillLink(target) {
|
|
53516
53905
|
const linked = symlinkTarget(target);
|
|
53517
|
-
return linked !== null &&
|
|
53906
|
+
return linked !== null && path12.basename(linked) === SKILL_NAME && path12.basename(path12.dirname(linked)) === "skills";
|
|
53518
53907
|
}
|
|
53519
53908
|
function isOurCodexPrompt(target) {
|
|
53520
53909
|
const stats = lstatOrNull(target);
|
|
@@ -53522,20 +53911,20 @@ function isOurCodexPrompt(target) {
|
|
|
53522
53911
|
return false;
|
|
53523
53912
|
}
|
|
53524
53913
|
try {
|
|
53525
|
-
return
|
|
53914
|
+
return fs15.readFileSync(target, "utf8").startsWith(CODEX_PROMPT_MARKER);
|
|
53526
53915
|
} catch {
|
|
53527
53916
|
return false;
|
|
53528
53917
|
}
|
|
53529
53918
|
}
|
|
53530
53919
|
function isOurInstalledCopy(target) {
|
|
53531
53920
|
const stats = lstatOrNull(target);
|
|
53532
|
-
return stats !== null && stats.isDirectory() && !stats.isSymbolicLink() &&
|
|
53921
|
+
return stats !== null && stats.isDirectory() && !stats.isSymbolicLink() && fs15.existsSync(path12.join(target, INSTALL_MARKER_FILE));
|
|
53533
53922
|
}
|
|
53534
53923
|
function relativeFileList(dir) {
|
|
53535
|
-
return
|
|
53924
|
+
return fs15.readdirSync(dir, { recursive: true, withFileTypes: true }).filter((entry) => entry.isFile() && entry.name !== INSTALL_MARKER_FILE && !COPY_EXCLUDES.has(entry.name)).map((entry) => path12.relative(dir, path12.join(entry.parentPath, entry.name))).sort();
|
|
53536
53925
|
}
|
|
53537
53926
|
function matchesShippedSkill(target, shippedSkillDir) {
|
|
53538
|
-
if (!shippedSkillDir || !
|
|
53927
|
+
if (!shippedSkillDir || !fs15.existsSync(shippedSkillDir) || !lstatOrNull(target)?.isDirectory()) {
|
|
53539
53928
|
return false;
|
|
53540
53929
|
}
|
|
53541
53930
|
try {
|
|
@@ -53544,17 +53933,17 @@ function matchesShippedSkill(target, shippedSkillDir) {
|
|
|
53544
53933
|
return false;
|
|
53545
53934
|
}
|
|
53546
53935
|
return shippedFiles.every(
|
|
53547
|
-
(file) =>
|
|
53936
|
+
(file) => fs15.readFileSync(path12.join(target, file)).equals(fs15.readFileSync(path12.join(shippedSkillDir, file)))
|
|
53548
53937
|
);
|
|
53549
53938
|
} catch {
|
|
53550
53939
|
return false;
|
|
53551
53940
|
}
|
|
53552
53941
|
}
|
|
53553
53942
|
function copyShippedSkill(shippedSkillDir, target) {
|
|
53554
|
-
|
|
53555
|
-
|
|
53943
|
+
fs15.mkdirSync(path12.dirname(target), { recursive: true });
|
|
53944
|
+
fs15.cpSync(shippedSkillDir, target, {
|
|
53556
53945
|
recursive: true,
|
|
53557
|
-
filter: (src) => !COPY_EXCLUDES.has(
|
|
53946
|
+
filter: (src) => !COPY_EXCLUDES.has(path12.basename(src))
|
|
53558
53947
|
});
|
|
53559
53948
|
const marker = {
|
|
53560
53949
|
installer: "web-cli",
|
|
@@ -53563,33 +53952,33 @@ function copyShippedSkill(shippedSkillDir, target) {
|
|
|
53563
53952
|
installedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
53564
53953
|
note: "This directory is a copy managed by `web-cli install-skill`; re-run it to refresh, or `web-cli uninstall-skill` to remove."
|
|
53565
53954
|
};
|
|
53566
|
-
|
|
53955
|
+
fs15.writeFileSync(path12.join(target, INSTALL_MARKER_FILE), JSON.stringify(marker, null, 2) + "\n", "utf8");
|
|
53567
53956
|
}
|
|
53568
53957
|
function skillsRootFor(agent, options, homeDir, cwd) {
|
|
53569
53958
|
switch (agent) {
|
|
53570
53959
|
case "claude":
|
|
53571
|
-
return
|
|
53960
|
+
return path12.join(options.project ? cwd : homeDir, ".claude", "skills");
|
|
53572
53961
|
case "codex":
|
|
53573
|
-
return
|
|
53962
|
+
return path12.join(resolveCodexHomeDir(homeDir, options.codexHomeDir), "skills");
|
|
53574
53963
|
case "agents":
|
|
53575
|
-
return
|
|
53964
|
+
return path12.join(resolveAgentsHomeDir(homeDir, options.agentsHomeDir), "skills");
|
|
53576
53965
|
case "dsh":
|
|
53577
|
-
return
|
|
53966
|
+
return path12.join(resolveDshHomeDir(homeDir, options.dshHomeDir), "skills");
|
|
53578
53967
|
}
|
|
53579
53968
|
}
|
|
53580
53969
|
function legacyCodexPromptPath(options, homeDir) {
|
|
53581
|
-
return
|
|
53970
|
+
return path12.join(resolveCodexHomeDir(homeDir, options.codexHomeDir), "prompts", `${SKILL_NAME}.md`);
|
|
53582
53971
|
}
|
|
53583
53972
|
function cleanUpLegacyCodexPrompt(options, homeDir) {
|
|
53584
53973
|
const prompt = legacyCodexPromptPath(options, homeDir);
|
|
53585
53974
|
if (!isOurCodexPrompt(prompt)) {
|
|
53586
53975
|
return null;
|
|
53587
53976
|
}
|
|
53588
|
-
|
|
53977
|
+
fs15.rmSync(prompt, { force: true });
|
|
53589
53978
|
return `removed legacy pointer prompt ${prompt}`;
|
|
53590
53979
|
}
|
|
53591
53980
|
function installCopyInto(agent, skillsRoot, options) {
|
|
53592
|
-
const target =
|
|
53981
|
+
const target = path12.join(skillsRoot, SKILL_NAME);
|
|
53593
53982
|
const shipped = options.shippedSkillDir;
|
|
53594
53983
|
const version = shippedSkillVersion(shipped);
|
|
53595
53984
|
const provenance = `copied from ${shipped}${version ? ` (v${version})` : ""}`;
|
|
@@ -53608,7 +53997,7 @@ function installCopyInto(agent, skillsRoot, options) {
|
|
|
53608
53997
|
} else {
|
|
53609
53998
|
return { agent, path: target, status: "blocked", kind: "copy", detail: describeExisting(target) };
|
|
53610
53999
|
}
|
|
53611
|
-
|
|
54000
|
+
fs15.rmSync(target, { recursive: true, force: true });
|
|
53612
54001
|
}
|
|
53613
54002
|
copyShippedSkill(shipped, target);
|
|
53614
54003
|
return { agent, path: target, status, kind: "copy", detail: provenance };
|
|
@@ -53632,7 +54021,7 @@ function uninstallSkill(options) {
|
|
|
53632
54021
|
const homeDir = options.homeDir ?? os5.homedir();
|
|
53633
54022
|
const cwd = options.cwd ?? process.cwd();
|
|
53634
54023
|
return options.agents.map((agent) => {
|
|
53635
|
-
const target =
|
|
54024
|
+
const target = path12.join(skillsRootFor(agent, options, homeDir, cwd), SKILL_NAME);
|
|
53636
54025
|
const legacyNote = agent === "codex" ? cleanUpLegacyCodexPrompt(options, homeDir) : null;
|
|
53637
54026
|
if (!lstatOrNull(target)) {
|
|
53638
54027
|
return { agent, path: target, status: "not-registered", ...legacyNote ? { detail: legacyNote } : {} };
|
|
@@ -53647,7 +54036,7 @@ function uninstallSkill(options) {
|
|
|
53647
54036
|
};
|
|
53648
54037
|
}
|
|
53649
54038
|
const what = symlinkTarget(target) ? `symlink -> ${symlinkTarget(target)}` : "installed copy";
|
|
53650
|
-
|
|
54039
|
+
fs15.rmSync(target, { recursive: true, force: true });
|
|
53651
54040
|
return { agent, path: target, status: "removed", detail: legacyNote ? `${what}; ${legacyNote}` : what };
|
|
53652
54041
|
});
|
|
53653
54042
|
}
|
|
@@ -53689,7 +54078,7 @@ function installWarningFilter(target = process) {
|
|
|
53689
54078
|
}
|
|
53690
54079
|
|
|
53691
54080
|
// src/index.ts
|
|
53692
|
-
dotenv.config({ path: [WEB_CLI_ENV_PATH,
|
|
54081
|
+
dotenv.config({ path: [WEB_CLI_ENV_PATH, path13.join(process.cwd(), ".env")] });
|
|
53693
54082
|
function printSuccess(value) {
|
|
53694
54083
|
process.stdout.write(`${JSON.stringify(value)}
|
|
53695
54084
|
`);
|
|
@@ -53714,6 +54103,13 @@ function wrap(fn) {
|
|
|
53714
54103
|
}
|
|
53715
54104
|
};
|
|
53716
54105
|
}
|
|
54106
|
+
function parseNonNegative(flag, value) {
|
|
54107
|
+
const n = Number(value);
|
|
54108
|
+
if (value.trim() === "" || !Number.isFinite(n) || n < 0) {
|
|
54109
|
+
throw new CliError("INVALID_ARGUMENT", `${flag} must be a number >= 0 (got "${value}").`);
|
|
54110
|
+
}
|
|
54111
|
+
return n;
|
|
54112
|
+
}
|
|
53717
54113
|
function wantsJsonOutput(opts) {
|
|
53718
54114
|
if (opts.json && opts.pretty) {
|
|
53719
54115
|
throw new CliError("INVALID_ARGUMENT", "--json and --pretty are mutually exclusive \u2014 pass at most one.");
|
|
@@ -53757,6 +54153,14 @@ program2.command("search <query>").description(
|
|
|
53757
54153
|
"--disable-login-recovery",
|
|
53758
54154
|
"don't attempt ANY recovery at all when a site's session has expired \u2014 not even the default silent, credential-based refresh (zero browser launches of any kind); report SESSION_EXPIRED immediately. A strict, rarely-needed escape hatch for an environment that cannot tolerate ANY browser automation attempt \u2014 most unattended callers want the default (silent refresh still tried) instead of this"
|
|
53759
54155
|
).option("--loginTimeoutSeconds <n>", "how long to wait for you to finish signing in", "240").option(
|
|
54156
|
+
"--fulltext-budget <seconds>",
|
|
54157
|
+
`how long to wait, per site, for the key references' full texts before DEFERRING the ones the site is still preparing (large book chapters can take 10s+ on the site's side; nothing shortens that wait but not waiting). Deferred references keep their title/url/snippet and carry a "moreAvailable.command" that fetches them on demand. At least one full text per site is always waited for. 0 waits for every full text, as before`,
|
|
54158
|
+
"5"
|
|
54159
|
+
).option(
|
|
54160
|
+
"--max-article-chars <n>",
|
|
54161
|
+
"cut each returned article's text to this many characters (its outline is kept whole and a trailing line says how to fetch the rest on demand with `web-cli get`). 0 never truncates",
|
|
54162
|
+
"60000"
|
|
54163
|
+
).option(
|
|
53760
54164
|
"--markdown [path]",
|
|
53761
54165
|
"also write this report to disk as a file (independent of --json \u2014 works either way); omit the value for the current directory, or give a .md file or a directory"
|
|
53762
54166
|
).option(
|
|
@@ -53776,6 +54180,8 @@ program2.command("search <query>").description(
|
|
|
53776
54180
|
disableLoginRecovery: opts.disableLoginRecovery,
|
|
53777
54181
|
allowVisibleLogin: opts.allowVisibleLogin,
|
|
53778
54182
|
loginTimeoutMs: Number(opts.loginTimeoutSeconds) * 1e3,
|
|
54183
|
+
fullTextBudgetMs: parseNonNegative("--fulltext-budget", opts.fulltextBudget) * 1e3,
|
|
54184
|
+
maxArticleChars: parseNonNegative("--max-article-chars", opts.maxArticleChars),
|
|
53779
54185
|
markdown: opts.markdown,
|
|
53780
54186
|
out: opts.out
|
|
53781
54187
|
});
|