dsh-connect-workbuddy 5.17.0 → 5.18.2
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/CHANGELOG.md +1454 -0
- package/README.en.md +18 -6
- package/README.md +88 -9
- package/docs/WINDOWS.md +4 -3
- package/lib/bin.js +12 -4
- package/lib/client.js +1788 -802
- package/lib/{host-heartbeat-09tOJATV.js → host-heartbeat-DFqDsnte.js} +485 -90
- package/lib/index.d.ts +333 -7
- package/lib/index.js +1436 -110
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { lstat, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import { createDecipheriv, createHash, randomBytes, randomUUID } from "node:crypto";
|
|
3
3
|
import { homedir, tmpdir } from "node:os";
|
|
4
|
-
import { dirname, join, posix, resolve, win32 } from "node:path";
|
|
4
|
+
import { dirname, join, posix, resolve, sep, win32 } from "node:path";
|
|
5
5
|
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -1003,14 +1003,56 @@ function clearAtRestKeyCache() {
|
|
|
1003
1003
|
* `Everyone` but `BUILTIN\Administrators` does not). The `*S-1-5-…` form makes
|
|
1004
1004
|
* every argument locale-independent, so the same argv works on any UI language.
|
|
1005
1005
|
*
|
|
1006
|
-
* WHY `OWNER RIGHTS` (S-1-3-4) RATHER THAN THE CURRENT USER
|
|
1007
|
-
* current user's SID costs a child process
|
|
1008
|
-
*
|
|
1009
|
-
*
|
|
1010
|
-
*
|
|
1011
|
-
*
|
|
1012
|
-
*
|
|
1013
|
-
* not the one
|
|
1006
|
+
* WHY `OWNER RIGHTS` (S-1-3-4) RATHER THAN THE CURRENT USER — AND WHERE THAT
|
|
1007
|
+
* ASSUMPTION BREAKS. Resolving the current user's SID costs a child process
|
|
1008
|
+
* (`whoami`) on every hardening round, and the answer is usually already
|
|
1009
|
+
* implied: the process that creates a file becomes its owner, so `OWNER RIGHTS`
|
|
1010
|
+
* grants exactly the account that will read it back. `SYSTEM` and
|
|
1011
|
+
* `Administrators` are kept so backup/AV/service software that legitimately
|
|
1012
|
+
* expects to reach user files is not locked out — removing them would make the
|
|
1013
|
+
* vault unmanageable on a machine where the user's own session is not the one
|
|
1014
|
+
* repairing it.
|
|
1015
|
+
*
|
|
1016
|
+
* THE BREAK. "The creator is the owner" only holds when the creating process
|
|
1017
|
+
* runs with the user's own (possibly elevated) token. When a directory was
|
|
1018
|
+
* created by a process whose token derives from the Administrators group — an
|
|
1019
|
+
* elevated DSH started from a RunLevel=Highest scheduled task, an installer,
|
|
1020
|
+
* a recovery console — the directory owner is `BUILTIN\Administrators`, and
|
|
1021
|
+
* `OWNER RIGHTS` then grants Administrators, not the user. Because
|
|
1022
|
+
* {@link applyAcl} also drops inherited ACEs (`/inheritance:r`), a non-admin
|
|
1023
|
+
* user is left with NO access at all to their own vault: stat/readdir/write
|
|
1024
|
+
* all fail with EPERM, and recovery requires an explicit `takeown`. Reproduced
|
|
1025
|
+
* as a controlled experiment (same command, only the owner differs):
|
|
1026
|
+
* owner=user → writable; owner=Administrators → locked. Reported in issue
|
|
1027
|
+
* #199 (forensic: fork branch `forensic/acl-lockout-20261102`).
|
|
1028
|
+
*
|
|
1029
|
+
* THE FIX. The grant names the account that will read the vault — the current
|
|
1030
|
+
* user — EXPLICITLY, and never relies on `OWNER RIGHTS`. {@link resolveUserSid}
|
|
1031
|
+
* reads that SID once per process (memoized) via `whoami.exe`, which measured
|
|
1032
|
+
* 22–26 ms on the reported host against PowerShell's 133 ms;
|
|
1033
|
+
* {@link hardenDirectory} then issues the same single `icacls` call the 5.x
|
|
1034
|
+
* design used, with `*<userSid>:(OI)(CI)(F)` in place of `*S-1-3-4`. Because
|
|
1035
|
+
* the granted principal no longer depends on who owns the object, a vault
|
|
1036
|
+
* created by an elevated process (owner = Administrators) stays readable by
|
|
1037
|
+
* its user.
|
|
1038
|
+
*
|
|
1039
|
+
* WHY NOT COMPARE THE OWNER FIRST. The alternative — read each directory's
|
|
1040
|
+
* owner and keep `OWNER RIGHTS` when it matches the user — needs a PowerShell
|
|
1041
|
+
* `Get-Acl` (~133 ms) on the credential-write path, and it does not buy
|
|
1042
|
+
* anything: the granted principal is always the user, so the comparison only
|
|
1043
|
+
* decides which spelling of the same grant to emit. That extra child process
|
|
1044
|
+
* is also what broke the 1 s polling budget of
|
|
1045
|
+
* `tests/issue12-region-hiding.spec.ts` while this fix was being developed
|
|
1046
|
+
* (measured: the owner lookup plus the user lookup pushed a first vault write
|
|
1047
|
+
* past the budget, the startup refresh lost the race, and the global region
|
|
1048
|
+
* kept advertising its fallback models). One memoized `whoami` for the whole
|
|
1049
|
+
* process replaces a per-directory `Get-Acl`.
|
|
1050
|
+
*
|
|
1051
|
+
* OWNER RIGHTS IS STILL ACCEPTED ON READ. {@link ALLOWED_SIDS} keeps
|
|
1052
|
+
* `S-1-3-4` so a vault hardened by 5.x — where the user usually IS the owner
|
|
1053
|
+
* and the ACE therefore was correct — still reads as `protected` instead of
|
|
1054
|
+
* being reported as a widening that never happened. It is simply no longer
|
|
1055
|
+
* ever GRANTED.
|
|
1014
1056
|
*
|
|
1015
1057
|
* WHAT THIS IS AND IS NOT. This is the issue's suggestion #2 (explicit ACLs
|
|
1016
1058
|
* after writing), which it calls "the smallest change". It is NOT DPAPI
|
|
@@ -1035,6 +1077,12 @@ function clearAtRestKeyCache() {
|
|
|
1035
1077
|
*
|
|
1036
1078
|
* Deliberately a SID rather than an account name: it needs no lookup, it works
|
|
1037
1079
|
* on every UI language, and `icacls` accepts it in the `*S-…` form.
|
|
1080
|
+
*
|
|
1081
|
+
* Since issue #199 it is READ-ONLY here: 5.x granted it, which locks a user out
|
|
1082
|
+
* of a directory owned by somebody else, so {@link directoryGrants} and
|
|
1083
|
+
* {@link fileGrants} no longer use it — but {@link ALLOWED_SIDS} still accepts
|
|
1084
|
+
* it, so a vault hardened by 5.x (where the user normally IS the owner) still
|
|
1085
|
+
* inspects as `protected`.
|
|
1038
1086
|
*/
|
|
1039
1087
|
const OWNER_RIGHTS_SID = "S-1-3-4";
|
|
1040
1088
|
/** Well-known SID for `NT AUTHORITY\SYSTEM`. */
|
|
@@ -1057,12 +1105,19 @@ const ALLOWED_SIDS = /* @__PURE__ */ new Set([
|
|
|
1057
1105
|
* Grant specs for a DIRECTORY: `(OI)` object-inherit and `(CI)` container-inherit
|
|
1058
1106
|
* make the ACE apply to files and subdirectories created later, which is the
|
|
1059
1107
|
* whole mechanism this module relies on.
|
|
1108
|
+
*
|
|
1109
|
+
* `userSid` is deliberately a PARAMETER rather than a constant: it is the only
|
|
1110
|
+
* principal whose identity is not a well-known SID, and making it explicit at
|
|
1111
|
+
* the call site is what keeps a future edit from quietly falling back to
|
|
1112
|
+
* `OWNER RIGHTS` (the issue #199 lockout).
|
|
1060
1113
|
*/
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1114
|
+
function directoryGrants(userSid) {
|
|
1115
|
+
return [
|
|
1116
|
+
`*${userSid}:(OI)(CI)(F)`,
|
|
1117
|
+
`*${SYSTEM_SID}:(OI)(CI)(F)`,
|
|
1118
|
+
`*${ADMINISTRATORS_SID}:(OI)(CI)(F)`
|
|
1119
|
+
];
|
|
1120
|
+
}
|
|
1066
1121
|
/** How long one `icacls` (or PowerShell) child may take before it is abandoned. */
|
|
1067
1122
|
const ACL_COMMAND_TIMEOUT_MS = 1e4;
|
|
1068
1123
|
/** Paths already hardened by THIS process, so repeat writes cost nothing. */
|
|
@@ -1153,6 +1208,11 @@ async function applyAcl(path, grants) {
|
|
|
1153
1208
|
*/
|
|
1154
1209
|
async function protectCredentialDirectory(directory) {
|
|
1155
1210
|
if (!isWindows()) return { state: "not-windows" };
|
|
1211
|
+
const refusal = harnessHomeRefusal(directory);
|
|
1212
|
+
if (refusal !== void 0) return {
|
|
1213
|
+
state: "skipped",
|
|
1214
|
+
reason: refusal
|
|
1215
|
+
};
|
|
1156
1216
|
if (protectedDirectories.has(directory)) return { state: "protected" };
|
|
1157
1217
|
const pending = inflightProtection.get(directory);
|
|
1158
1218
|
if (pending !== void 0) return pending;
|
|
@@ -1164,11 +1224,104 @@ async function protectCredentialDirectory(directory) {
|
|
|
1164
1224
|
inflightProtection.delete(directory);
|
|
1165
1225
|
}
|
|
1166
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Why `directory` must NOT be hardened, or `undefined` when it may be
|
|
1229
|
+
* (issue #208).
|
|
1230
|
+
*
|
|
1231
|
+
* THE DEFECT THIS CLOSES. Hardening drops inherited ACEs (`/inheritance:r`).
|
|
1232
|
+
* Applied to `<DSH home>` itself that also drops what every OTHER directory
|
|
1233
|
+
* under it inherits — `<DSH home>/attachments`, sessions, profile config —
|
|
1234
|
+
* and a child whose DACL came purely from that inheritance becomes
|
|
1235
|
+
* unreadable even to its owner. The reporter measured exactly that: after
|
|
1236
|
+
* installing the plugin, sending an image failed with `EPERM: operation not
|
|
1237
|
+
* permitted, scandir '<DSH home>/attachments'` while text messages were
|
|
1238
|
+
* unaffected, and `icacls <DSH home>` itself printed "Access is denied". The
|
|
1239
|
+
* UI showed the host's generic `prompt rejected (session/agent-busy)`, so the
|
|
1240
|
+
* symptom pointed at sessions rather than at the DACL.
|
|
1241
|
+
*
|
|
1242
|
+
* HOW THIS PLUGIN COULD REACH IT. `writeVaultEntry` hardens `dirname(dir)`.
|
|
1243
|
+
* For a region-scoped store that is `<DSH home>/workbuddy-vault` (correct), but
|
|
1244
|
+
* the UNREGIONED store — which `doctor` builds via `makeAnyStore()` — keeps its
|
|
1245
|
+
* vault AT `<DSH home>/workbuddy-vault` itself, so `dirname` resolves to
|
|
1246
|
+
* `<DSH home>`. Reproduced here with a stubbed `icacls`: the argv target was
|
|
1247
|
+
* the Harness home, and the three SIDs the reporter found on `<DSH home>` are
|
|
1248
|
+
* exactly `directoryGrants()`'s.
|
|
1249
|
+
*
|
|
1250
|
+
* WHY REFUSE RATHER THAN SPECIAL-CASE THE CALLER. A guard at THIS layer also
|
|
1251
|
+
* covers `<DSH home>/.dsh`-style ancestors, a future call site computing the
|
|
1252
|
+
* root one level too high (the reporter's own third question), and a
|
|
1253
|
+
* `WORKBUDDY_*` variable pointing the vault at `$HOME`. The blast radius of
|
|
1254
|
+
* getting it wrong is the whole harness home, so the check belongs where the
|
|
1255
|
+
* destructive operation is, not where its arguments are assembled.
|
|
1256
|
+
*
|
|
1257
|
+
* Ancestors are refused too, not just equality: hardening the PARENT of the
|
|
1258
|
+
* harness home strips the inheritance the home itself relies on, which breaks
|
|
1259
|
+
* it just as thoroughly and is even harder to recognise afterwards.
|
|
1260
|
+
*/
|
|
1261
|
+
function harnessHomeRefusal(directory) {
|
|
1262
|
+
let home;
|
|
1263
|
+
try {
|
|
1264
|
+
home = resolve(resolveDshHome());
|
|
1265
|
+
} catch {
|
|
1266
|
+
return "the Harness home could not be resolved, so this directory cannot be proven safe to harden";
|
|
1267
|
+
}
|
|
1268
|
+
const target = resolve(directory);
|
|
1269
|
+
if (target.toLowerCase() === home.toLowerCase()) return `refusing to harden the Harness home itself (${home}); /inheritance:r there would strip the ACEs every other directory under it inherits`;
|
|
1270
|
+
if (`${home}${sep}`.toLowerCase().startsWith(`${target}${sep}`.toLowerCase())) return `refusing to harden ${target}, which contains the Harness home (${home}); dropping inherited ACEs on an ancestor breaks the whole home tree`;
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* The current user's SID, resolved once per process.
|
|
1274
|
+
*
|
|
1275
|
+
* Node's `os.userInfo()` does NOT expose a SID on Windows (its typings have no
|
|
1276
|
+
* `sid`, and the runtime object carries none — measured), so the SID has to
|
|
1277
|
+
* come from outside the process.
|
|
1278
|
+
*
|
|
1279
|
+
* `whoami.exe` rather than PowerShell: measured on the machine that reported
|
|
1280
|
+
* issue #199, `whoami /user /fo csv /nh` takes 22–26 ms while a
|
|
1281
|
+
* `powershell -Command` round trip takes 133 ms — and since this shape pays the
|
|
1282
|
+
* cost on the credential-write path, which the startup roster refresh is
|
|
1283
|
+
* racing, that 5× difference is the difference between fitting the poll budget
|
|
1284
|
+
* and blowing it.
|
|
1285
|
+
*
|
|
1286
|
+
* The absolute path is deliberate: a bare `whoami` resolves through `PATH`,
|
|
1287
|
+
* where Git for Windows ships an MSYS `whoami` that does not understand
|
|
1288
|
+
* `/user` at all. `/fo csv /nh` gives one quoted line
|
|
1289
|
+
* (`"desktop\user","S-1-5-21-…"`), which is parsed rather than the default
|
|
1290
|
+
* formatted block, again for locale independence.
|
|
1291
|
+
*
|
|
1292
|
+
* Memoized for the process on SUCCESS only: an unresolvable SID is a real
|
|
1293
|
+
* failure and must be retried by the next write, not cached as broken forever.
|
|
1294
|
+
*/
|
|
1295
|
+
let cachedUserSid;
|
|
1296
|
+
async function resolveUserSid() {
|
|
1297
|
+
if (cachedUserSid === void 0) {
|
|
1298
|
+
const line = (await runCommand(join(process.env.SystemRoot ?? "C:\\Windows", "System32", "whoami.exe"), [
|
|
1299
|
+
"/user",
|
|
1300
|
+
"/fo",
|
|
1301
|
+
"csv",
|
|
1302
|
+
"/nh"
|
|
1303
|
+
])).split(/\r?\n/u).map((entry) => entry.trim()).find((entry) => /S-1-5-[\d-]+/u.test(entry));
|
|
1304
|
+
if (line === void 0) throw new Error("whoami returned no resolvable user SID");
|
|
1305
|
+
const match = /"(S-1-5-[\d-]+)"/u.exec(line) ?? /S-1-5-[\d-]+/u.exec(line);
|
|
1306
|
+
if (match === null) throw new Error("whoami output has no parseable SID field");
|
|
1307
|
+
cachedUserSid = match[1] ?? match[0];
|
|
1308
|
+
}
|
|
1309
|
+
return cachedUserSid;
|
|
1310
|
+
}
|
|
1167
1311
|
/** The work behind {@link protectCredentialDirectory}: one `icacls` call. */
|
|
1168
1312
|
async function hardenDirectory(directory) {
|
|
1169
1313
|
try {
|
|
1170
1314
|
await mkdir(directory, { recursive: true });
|
|
1171
|
-
|
|
1315
|
+
let grants;
|
|
1316
|
+
try {
|
|
1317
|
+
grants = directoryGrants(await resolveUserSid());
|
|
1318
|
+
} catch (error) {
|
|
1319
|
+
return {
|
|
1320
|
+
state: "failed",
|
|
1321
|
+
reason: `user SID lookup failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
await applyAcl(directory, grants);
|
|
1172
1325
|
protectedDirectories.add(directory);
|
|
1173
1326
|
return { state: "protected" };
|
|
1174
1327
|
} catch (error) {
|
|
@@ -1224,7 +1377,32 @@ async function inspectCredentialDirectory(directory) {
|
|
|
1224
1377
|
state: "unverified",
|
|
1225
1378
|
reason: "Get-Acl returned no principals"
|
|
1226
1379
|
};
|
|
1227
|
-
|
|
1380
|
+
/**
|
|
1381
|
+
* The current user is an ALLOWED principal, not a widening.
|
|
1382
|
+
*
|
|
1383
|
+
* This is the read side of the issue #199 fix: 5.x granted `OWNER RIGHTS`,
|
|
1384
|
+
* whose SID (S-1-3-4) can be compared against {@link ALLOWED_SIDS} without
|
|
1385
|
+
* knowing who runs the process, but the fix grants the user's REAL SID — so
|
|
1386
|
+
* the allowlist has to learn it, or a correctly hardened directory reports as
|
|
1387
|
+
* `exposed` naming the user themselves. Measured on a real host before this
|
|
1388
|
+
* was wired up: `weak: ["S-1-5-21-…-1001"]` on a freshly hardened vault.
|
|
1389
|
+
*
|
|
1390
|
+
* An unresolvable user SID is reported as `unverified` rather than guessed:
|
|
1391
|
+
* without it the read cannot tell "the user" from "some other account", and
|
|
1392
|
+
* both wrong answers (allowing everyone / accusing the user) are worse than
|
|
1393
|
+
* saying the measurement did not happen.
|
|
1394
|
+
*/
|
|
1395
|
+
let userSid;
|
|
1396
|
+
try {
|
|
1397
|
+
userSid = await resolveUserSid();
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
return {
|
|
1400
|
+
directory,
|
|
1401
|
+
state: "unverified",
|
|
1402
|
+
reason: `user SID lookup failed: ${error instanceof Error ? error.message : String(error)}`
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
const weak = entries.filter((sid) => sid !== userSid && !ALLOWED_SIDS.has(sid));
|
|
1228
1406
|
return {
|
|
1229
1407
|
directory,
|
|
1230
1408
|
state: weak.length === 0 ? "protected" : "exposed",
|
|
@@ -1812,8 +1990,6 @@ function queueNoticeText(report) {
|
|
|
1812
1990
|
const IMAGE_TAG_TEXT_TO_IMAGE = "text-to-image";
|
|
1813
1991
|
/** 产品配置里「图生图 / 改图」模型的标签。 */
|
|
1814
1992
|
const IMAGE_TAG_IMAGE_TO_IMAGE = "image-to-image";
|
|
1815
|
-
/** 官方 CLI 的默认尺寸。 */
|
|
1816
|
-
const DEFAULT_IMAGE_SIZE = "1024x1024";
|
|
1817
1993
|
/** 生图路由。 */
|
|
1818
1994
|
const IMAGE_GENERATIONS_PATH = "/v2/images/generations";
|
|
1819
1995
|
/** 改图路由:官方 CLI 的 `ImageService.editImage` 打的就是这条(2026-10-25 国际区实测 200)。 */
|
|
@@ -2339,9 +2515,40 @@ function parseVideoTask(payload) {
|
|
|
2339
2515
|
}
|
|
2340
2516
|
return {
|
|
2341
2517
|
status,
|
|
2342
|
-
videos: []
|
|
2518
|
+
videos: [],
|
|
2519
|
+
detail: describeUnknownTaskFields(data)
|
|
2343
2520
|
};
|
|
2344
2521
|
}
|
|
2522
|
+
/**
|
|
2523
|
+
* `data` 里除已知键以外的内容,序列化成一行短文本。
|
|
2524
|
+
*
|
|
2525
|
+
* 已知键:`status`(状态机自己用)、`data`(成品 URL 列表)、`usage`(扣费)。
|
|
2526
|
+
* 其余全部带上——那正是"上游说了原因但我们没读"的地方(issue #187)。
|
|
2527
|
+
*
|
|
2528
|
+
* 深层结构做 JSON 序列化并截断到 400 字符:一轮报错不该因为上游回了一棵大树而
|
|
2529
|
+
* 变成几 KB。空对象返回 `undefined`,好让调用方不拼一个空的「(上游未给出原因)」。
|
|
2530
|
+
*/
|
|
2531
|
+
function describeUnknownTaskFields(data) {
|
|
2532
|
+
const known = /* @__PURE__ */ new Set([
|
|
2533
|
+
"status",
|
|
2534
|
+
"data",
|
|
2535
|
+
"usage"
|
|
2536
|
+
]);
|
|
2537
|
+
const extra = {};
|
|
2538
|
+
for (const [key, value] of Object.entries(data)) {
|
|
2539
|
+
if (known.has(key)) continue;
|
|
2540
|
+
if (value === void 0 || value === null || value === "") continue;
|
|
2541
|
+
extra[key] = value;
|
|
2542
|
+
}
|
|
2543
|
+
if (Object.keys(extra).length === 0) return void 0;
|
|
2544
|
+
let text;
|
|
2545
|
+
try {
|
|
2546
|
+
text = JSON.stringify(extra);
|
|
2547
|
+
} catch {
|
|
2548
|
+
return "(上游返回了无法序列化的额外字段)";
|
|
2549
|
+
}
|
|
2550
|
+
return text.length > 400 ? `${text.slice(0, 400)}…` : text;
|
|
2551
|
+
}
|
|
2345
2552
|
/** 把一次非 2xx 的提交/轮询响应翻成带 `code` 的错误,好让上层决定怎么提示。 */
|
|
2346
2553
|
function describeVideoFailure(status, bodyText, phase = "submit") {
|
|
2347
2554
|
const text = bodyText.trim();
|
|
@@ -2998,16 +3205,30 @@ const ERROR_BODY_LIMIT = 4096;
|
|
|
2998
3205
|
* tokens, so prompt processing legitimately takes a while before the first byte
|
|
2999
3206
|
* comes back. It exists only to stop a connection that will NEVER answer — the
|
|
3000
3207
|
* pool's batch is serial, so one hung member would otherwise block all the rest
|
|
3001
|
-
* with nothing in the UI to say which one it was
|
|
3002
|
-
*
|
|
3003
|
-
*
|
|
3208
|
+
* with nothing in the UI to say which one it was; the budget covers the response
|
|
3209
|
+
* only, never the one-line body that follows.
|
|
3210
|
+
*
|
|
3211
|
+
* THIRTY SECONDS, NOT TEN. The old 10 s was chosen as "comfortably above a
|
|
3212
|
+
* working gateway's first byte", and on a fast path it is — but measured on a
|
|
3213
|
+
* real 25k-token probe body over ordinary Chinese broadband, the first byte
|
|
3214
|
+
* alone took 3.47 s / 3.57 s / 6.97 s on three consecutive attempts. A 10 s
|
|
3215
|
+
* ceiling therefore left under 3 s of margin on the worst run, and any jitter
|
|
3216
|
+
* blew through it.
|
|
3217
|
+
*
|
|
3218
|
+
* The cost of tripping it was never just a failed test: `status: 0` carries no
|
|
3219
|
+
* `retryAtMs`, so the pool fell back to {@link POOL_UNKNOWN_COOLDOWN_MS} (30
|
|
3220
|
+
* minutes) and benched healthy accounts, answering "池中已无可用账号" and a 502 to
|
|
3221
|
+
* every request until the cooldown lapsed. The two failure directions are not
|
|
3222
|
+
* symmetric — waiting an extra 20 s on a genuinely dead endpoint costs one
|
|
3223
|
+
* stalled batch member, while firing early costs half an hour of the whole pool
|
|
3224
|
+
* — so this ceiling is deliberately generous.
|
|
3004
3225
|
*
|
|
3005
3226
|
* It also does not cover THIS MACHINE's identity work. Since P3 the header build
|
|
3006
3227
|
* may spawn the device-token subprocess (budget 20 s), and starting the clock
|
|
3007
3228
|
* before that would turn a healthy gateway into "unreachable" on a cold start —
|
|
3008
3229
|
* see the note in `probeChat` for why that matters to the pool.
|
|
3009
3230
|
*/
|
|
3010
|
-
const PROBE_TIMEOUT_MS =
|
|
3231
|
+
const PROBE_TIMEOUT_MS = 3e4;
|
|
3011
3232
|
/**
|
|
3012
3233
|
* 生图请求的超时。
|
|
3013
3234
|
*
|
|
@@ -3021,8 +3242,15 @@ const IMAGE_TIMEOUT_MS = 18e4;
|
|
|
3021
3242
|
const VIDEO_TIMEOUT_MS = 6e5;
|
|
3022
3243
|
/** 轮询之间的间隔(官方 CLI pollTask 用 5s)。 */
|
|
3023
3244
|
const VIDEO_POLL_INTERVAL_MS = 5e3;
|
|
3024
|
-
/**
|
|
3025
|
-
|
|
3245
|
+
/**
|
|
3246
|
+
* 轮询循环自身上限(防死循环)。
|
|
3247
|
+
*
|
|
3248
|
+
* 比 {@link VIDEO_TIMEOUT_MS} 短 60s:工具层给的是一个更短的 signal
|
|
3249
|
+
* (`VIDEO_TOOL_TIMEOUT_MS`),两者叠在一起时**这个检查要先生效**,才能带着
|
|
3250
|
+
* task id 抛出 `POLL_TIMEOUT`。曾经的 600s 与宿主工具上限相等,先在宿主那边
|
|
3251
|
+
* 掐断,于是用户只看到 `tool call timed out after 600000ms`(issue #187)。
|
|
3252
|
+
*/
|
|
3253
|
+
const VIDEO_POLL_TIMEOUT_MS = 54e4;
|
|
3026
3254
|
/** 单条视频下载超时(官方 CLI 用 120s)。 */
|
|
3027
3255
|
const VIDEO_DOWNLOAD_TIMEOUT_MS = 12e4;
|
|
3028
3256
|
/**
|
|
@@ -6148,7 +6376,7 @@ var WorkBuddyUpstreamClient = class {
|
|
|
6148
6376
|
...result.credit !== void 0 ? { credit: result.credit } : {}
|
|
6149
6377
|
};
|
|
6150
6378
|
}
|
|
6151
|
-
if (result.status === "failed") throw new WorkBuddyVideoError(`workbuddy video: 生视频任务失败(task ${taskId}
|
|
6379
|
+
if (result.status === "failed") throw new WorkBuddyVideoError(`workbuddy video: 生视频任务失败(task ${taskId})。` + (result.detail === void 0 ? "上游没有给出任何原因字段。" : ` 上游返回的额外字段:${result.detail}`), "TASK_FAILED");
|
|
6152
6380
|
await new Promise((resolve, reject) => {
|
|
6153
6381
|
const timer = setTimeout(resolve, VIDEO_POLL_INTERVAL_MS);
|
|
6154
6382
|
const onAbort = () => {
|
|
@@ -6811,6 +7039,15 @@ function isVaultCredentialFileName(name) {
|
|
|
6811
7039
|
/** Current on-disk format of the vault; readers reject others. */
|
|
6812
7040
|
const VAULT_FORMAT_VERSION = 1;
|
|
6813
7041
|
/**
|
|
7042
|
+
* 鸿蒙上用户可见的家目录。
|
|
7043
|
+
*
|
|
7044
|
+
* `os.homedir()` 在鸿蒙上返回的是**应用沙箱**
|
|
7045
|
+
* (`/data/storage/el2/base/haps/entry/files`),不是用户目录,所以不能像
|
|
7046
|
+
* linux 那样由 `home` 派生。真实凭据落在 `/storage/Users/currentUser` 下,
|
|
7047
|
+
* 这个挂载点由系统规定,不随应用变化。
|
|
7048
|
+
*/
|
|
7049
|
+
const OPENHARMONY_USER_HOME = "/storage/Users/currentUser";
|
|
7050
|
+
/**
|
|
6814
7051
|
* Platform-default directories holding the WorkBuddy desktop app's auth file.
|
|
6815
7052
|
*
|
|
6816
7053
|
* Windows and Linux prefer the OS-issued env location and fall back to the
|
|
@@ -6818,6 +7055,9 @@ const VAULT_FORMAT_VERSION = 1;
|
|
|
6818
7055
|
* folder backup, enterprise policy) still resolves. macOS has no equivalent
|
|
6819
7056
|
* env variable; the single Application Support path is used as-is.
|
|
6820
7057
|
*
|
|
7058
|
+
* 鸿蒙(issue #190)没有 `homedir()` 可用——它返回应用沙箱,所以那条分支用
|
|
7059
|
+
* 系统固定挂载点。Linux 会同时看 XDG 的 data 与 config 两套目录。
|
|
7060
|
+
*
|
|
6821
7061
|
* `platform`, `home`, and `env` are injectable so the platform branches are
|
|
6822
7062
|
* testable on any host without touching a real machine.
|
|
6823
7063
|
*/
|
|
@@ -6828,9 +7068,41 @@ function defaultDesktopAuthDirs(platform = process.platform, home = homedir(), e
|
|
|
6828
7068
|
const roaming = nonEmptyEnv(env["APPDATA"]) ?? join(home, "AppData", "Roaming");
|
|
6829
7069
|
return [join(local, "CodeBuddyExtension", "Data", "Public", "auth"), join(roaming, "CodeBuddyExtension", "Data", "Public", "auth")];
|
|
6830
7070
|
}
|
|
7071
|
+
/**
|
|
7072
|
+
* 鸿蒙(issue #190)。
|
|
7073
|
+
*
|
|
7074
|
+
* 走 XDG 的 `~/.local/share` 形状,但 `~` **不能**用 `homedir()`——那是
|
|
7075
|
+
* 沙箱路径。用系统固定挂载点,并允许 `WORKBUDDY_USER_HOME` 覆盖(未来的
|
|
7076
|
+
* 多用户或不同发行版挂法)。
|
|
7077
|
+
*
|
|
7078
|
+
* 没有这个分支时落到 `return []`,卡片连一个候选路径都扫不到,账号池恒为 0,
|
|
7079
|
+
* 而 `doctor` 只会说"no platform default; set WORKBUDDY_AUTH_FILE"——
|
|
7080
|
+
* 把一个本该自动完成的事推给用户。
|
|
7081
|
+
*/
|
|
7082
|
+
if (platform === "openharmony") {
|
|
7083
|
+
const root = nonEmptyEnv(env["WORKBUDDY_USER_HOME"]) ?? OPENHARMONY_USER_HOME;
|
|
7084
|
+
return [posix.join(root, ".local", "share", "CodeBuddyExtension", "Data", "Public", "auth")];
|
|
7085
|
+
}
|
|
6831
7086
|
if (platform === "linux") {
|
|
7087
|
+
/**
|
|
7088
|
+
* Linux 同时看 XDG 的**两套**目录(issue #190 附带发现)。
|
|
7089
|
+
*
|
|
7090
|
+
* `Data/Public/auth` 是**数据**,按 XDG 惯例该在 `$XDG_DATA_HOME`
|
|
7091
|
+
* (缺省 `~/.local/share`)下;而这里原先只读 `$XDG_CONFIG_HOME`
|
|
7092
|
+
* (缺省 `~/.config`)。issue #190 的报告机器与鸿蒙实测都指向
|
|
7093
|
+
* `.local/share`,所以两套都给。
|
|
7094
|
+
*
|
|
7095
|
+
* ⚠️ **`.config` 仍然排在前面**,也就是探测顺序与改动前完全一致。
|
|
7096
|
+
* 理由:README §平台支持写明"其余候选仍未经真机逐项验证",Linux 从来没有
|
|
7097
|
+
* 真机证据;把 data 提到前面会改变"没设 WORKBUDDY_AUTH_FILE 时用哪一个"
|
|
7098
|
+
* 这个已经上线的行为,而换来的收益尚无证据。这里只做**加法**:多一个候选,
|
|
7099
|
+
* 不动已有的顺序,老用户的行为一个字节都不变。
|
|
7100
|
+
*
|
|
7101
|
+
* 两个目录都不存在时与以前一致:扫不到,回落 `WORKBUDDY_AUTH_FILE`。
|
|
7102
|
+
*/
|
|
6832
7103
|
const config = nonEmptyEnv(env["XDG_CONFIG_HOME"]) ?? join(home, ".config");
|
|
6833
|
-
|
|
7104
|
+
const data = nonEmptyEnv(env["XDG_DATA_HOME"]) ?? join(home, ".local", "share");
|
|
7105
|
+
return [join(config, "CodeBuddyExtension", "Data", "Public", "auth"), join(data, "CodeBuddyExtension", "Data", "Public", "auth")];
|
|
6834
7106
|
}
|
|
6835
7107
|
return [];
|
|
6836
7108
|
}
|
|
@@ -7167,28 +7439,13 @@ async function readVaultEntries(dir) {
|
|
|
7167
7439
|
* to persist a credential because an ACL call failed would turn it into an
|
|
7168
7440
|
* outage. `doctor` reports the outcome so a machine where it failed is visible.
|
|
7169
7441
|
* On POSIX this call is a no-op, and `mode` below carries the same intent.
|
|
7442
|
+
*
|
|
7443
|
+
* WHICH directory gets hardened is decided by {@link vaultRootToHarden}, not by
|
|
7444
|
+
* a bare `dirname(dir)` — see the issue #208 note there.
|
|
7170
7445
|
*/
|
|
7171
7446
|
async function writeVaultEntry(dir, accountId, credential, refreshedFrom) {
|
|
7172
7447
|
const path = join(dir, `${accountId}.json`);
|
|
7173
|
-
|
|
7174
|
-
* Harden the vault ROOT, which also hardens this region's directory and sweeps
|
|
7175
|
-
* the files already inside (issue #183).
|
|
7176
|
-
*
|
|
7177
|
-
* The root, not just `dir`: `dir` is `<vault>/<region>`, and the root is what
|
|
7178
|
-
* carries the inherited `Everyone: FullControl` from `~/.dsh`. Leaving the
|
|
7179
|
-
* root widened would let any local process delete or replace the region
|
|
7180
|
-
* directory itself, which defeats the file-level restriction inside it.
|
|
7181
|
-
*
|
|
7182
|
-
* BEFORE the write, so the commit's temp inode — and the file it is renamed
|
|
7183
|
-
* over — inherit the hardened ACEs instead of the widened ones. A file-level
|
|
7184
|
-
* pass AFTER the write would leave the pre-rename window open and would be
|
|
7185
|
-
* lost by the next atomic replace, which creates a fresh inode each time.
|
|
7186
|
-
*
|
|
7187
|
-
* Memoized per directory per process, so the second account costs nothing: see
|
|
7188
|
-
* the cost model in `src/windows-acl.ts` for why the per-write budget matters
|
|
7189
|
-
* here.
|
|
7190
|
-
*/
|
|
7191
|
-
await protectCredentialDirectory(dirname(dir));
|
|
7448
|
+
await protectCredentialDirectory(vaultRootToHarden(dir));
|
|
7192
7449
|
await withFileLock(path, async () => {
|
|
7193
7450
|
await writeFileAtomic(path, `${JSON.stringify(vaultDocument(credential, accountId, refreshedFrom), null, 2)}\n`, {
|
|
7194
7451
|
mode: 384,
|
|
@@ -7197,6 +7454,38 @@ async function writeVaultEntry(dir, accountId, credential, refreshedFrom) {
|
|
|
7197
7454
|
});
|
|
7198
7455
|
}
|
|
7199
7456
|
/**
|
|
7457
|
+
* The directory {@link writeVaultEntry} hardens: the vault ROOT, not this
|
|
7458
|
+
* entry's own directory (issue #183), and never the Harness home (issue #208).
|
|
7459
|
+
*
|
|
7460
|
+
* WHY THE ROOT. `Everyone: FullControl` is inherited from `~/.dsh` onto
|
|
7461
|
+
* `…/workbuddy-vault`; hardening only `<vault>/<region>` would leave the root
|
|
7462
|
+
* writable, so any local process could replace the region directory itself and
|
|
7463
|
+
* defeat the restriction inside it. Hardening the root propagates down the
|
|
7464
|
+
* whole tree in one `icacls` call (measured on a real host: one call on the
|
|
7465
|
+
* root left the root, both region directories AND the files inside with exactly
|
|
7466
|
+
* the three intended ACEs).
|
|
7467
|
+
*
|
|
7468
|
+
* WHY NOT ALWAYS `dirname(dir)` — THE ISSUE #208 DEFECT. That shape assumes
|
|
7469
|
+
* `dir` is `<vault>/<region>`. It is not for the UNREGIONED store, whose vault
|
|
7470
|
+
* directory IS `<DSH home>/workbuddy-vault`; `dirname` then yields `<DSH home>`
|
|
7471
|
+
* itself, and `/inheritance:r` there strips the ACEs every other directory
|
|
7472
|
+
* under the home inherits. A reporter hit exactly that: `<DSH home>/attachments`
|
|
7473
|
+
* became unreadable (EPERM on `scandir`) and every image send failed with the
|
|
7474
|
+
* host's unrelated `prompt rejected (session/agent-busy)`. `doctor` reaches
|
|
7475
|
+
* this path because it builds an unregioned store.
|
|
7476
|
+
*
|
|
7477
|
+
* So the parent is used only when it is genuinely a vault root — i.e. NOT the
|
|
7478
|
+
* Harness home. When `dir` already IS the vault root, `dir` is the right
|
|
7479
|
+
* target. `src/windows-acl.ts` independently refuses the home and its
|
|
7480
|
+
* ancestors, which covers an injected `vaultDir` and any future call site that
|
|
7481
|
+
* computes this one level too high; this function is what keeps the CORRECT
|
|
7482
|
+
* call from relying on that backstop.
|
|
7483
|
+
*/
|
|
7484
|
+
function vaultRootToHarden(dir) {
|
|
7485
|
+
const parent = dirname(dir);
|
|
7486
|
+
return resolve(parent) === resolve(resolveDshHome()) ? dir : parent;
|
|
7487
|
+
}
|
|
7488
|
+
/**
|
|
7200
7489
|
* Probe one auth file, reporting WHY it yielded no credential.
|
|
7201
7490
|
*
|
|
7202
7491
|
* The desktop app encrypts its token fields on Windows builds. The plain read
|
|
@@ -7665,6 +7954,34 @@ var WorkBuddyCredentialStore = class {
|
|
|
7665
7954
|
if (credentials.length === 0) return false;
|
|
7666
7955
|
return !credentials.some((credential) => workbuddyAccountId(credential) === this.accountId);
|
|
7667
7956
|
}
|
|
7957
|
+
/**
|
|
7958
|
+
* Why the vault could not be read, when it could not (issue #199).
|
|
7959
|
+
*
|
|
7960
|
+
* `syncVault` deliberately swallows a failed `readVaultEntries` so account
|
|
7961
|
+
* discovery stays up — the right call for availability, the wrong call for
|
|
7962
|
+
* honesty: the user then sees the SAVED account reported as "no longer on
|
|
7963
|
+
* this machine" when the truth is "this process may not read the directory".
|
|
7964
|
+
* The issue #199 lockout (foreign owner + `/inheritance:r`) produces exactly
|
|
7965
|
+
* that shape: readdir EPERM while per-path readFile still works, so nothing
|
|
7966
|
+
* else in the diagnostics reports the directory either.
|
|
7967
|
+
*
|
|
7968
|
+
* A dedicated readdir probe rather than a field recorded during the scan:
|
|
7969
|
+
* the scan is shared/cached (`scanInflight`), its failure is transient by
|
|
7970
|
+
* design, and a probe here is one cheap readdir on a path that is already
|
|
7971
|
+
* failing — the error string is the fact the card needs.
|
|
7972
|
+
*
|
|
7973
|
+
* Returns the raw error message, or `undefined` when the directory reads
|
|
7974
|
+
* (including the absent case, which is normal before the first OAuth add).
|
|
7975
|
+
*/
|
|
7976
|
+
async vaultReadError() {
|
|
7977
|
+
try {
|
|
7978
|
+
await readdir(this.vaultDir());
|
|
7979
|
+
return;
|
|
7980
|
+
} catch (error) {
|
|
7981
|
+
if (isENOENT(error)) return void 0;
|
|
7982
|
+
return error instanceof Error ? error.message : String(error);
|
|
7983
|
+
}
|
|
7984
|
+
}
|
|
7668
7985
|
/** The freshest stored credential for the current selection, no refresh. */
|
|
7669
7986
|
async current() {
|
|
7670
7987
|
const credentials = await this.readAll();
|
|
@@ -8173,141 +8490,143 @@ const FALLBACK_WORKBUDDY_MODELS = [
|
|
|
8173
8490
|
* expose different rosters — the CN list has no `gpt-*`/`gemini-*` entries —
|
|
8174
8491
|
* so a global account must never be seeded with the CN list. Like the CN
|
|
8175
8492
|
* fallback this is replaced by the live refresh; it only keeps the provider
|
|
8176
|
-
* usable before the first fetch lands. Order
|
|
8493
|
+
* usable before the first fetch lands. Order mirrors the upstream.
|
|
8494
|
+
*
|
|
8495
|
+
* ⚠️ IT CARRIES NO `creditMultiplier`, AND THAT IS THE FIX FOR ISSUE #214.
|
|
8496
|
+
* This list used to hardcode one rate per model, captured on 2026-09-11. The
|
|
8497
|
+
* upstream moves those rates — the reporter measured `glm-5.3` at x0.69 and
|
|
8498
|
+
* `hy4-preview` at x0.29 on 2026-11-04 against the x0.79 / x0.00 written
|
|
8499
|
+
* here — so every captured rate aged into a WRONG PRICE. Worse, the overlay
|
|
8500
|
+
* rule (`overlayLiveCapabilities`: the live side owns `creditMultiplier`)
|
|
8501
|
+
* meant this table WON over the user's saved directory whenever the catalog
|
|
8502
|
+
* still held it, which is exactly the reported symptom: the card showed the
|
|
8503
|
+
* built-in table's figures, not the saved ones and not the upstream's.
|
|
8504
|
+
*
|
|
8505
|
+
* A price is a FACT ABOUT NOW, and this module never learns "now": it is the
|
|
8506
|
+
* offline placeholder, written once and never refreshed. So it must not
|
|
8507
|
+
* assert a price at all. An absent multiplier renders as "no rate" — the
|
|
8508
|
+
* honest answer — and `pickFreeModel` deliberately treats absence as NOT
|
|
8509
|
+
* free, so the account pool can never probe a paid model by mistake. The CN
|
|
8510
|
+
* table has always been shaped this way for the same reason.
|
|
8511
|
+
*
|
|
8512
|
+
* The ROSTER (ids, names, windows) stays: that is what keeps the provider
|
|
8513
|
+
* non-empty while the first fetch is in flight, and an id list ages far
|
|
8514
|
+
* more slowly than a price list.
|
|
8177
8515
|
*/
|
|
8178
8516
|
const FALLBACK_WORKBUDDY_MODELS_GLOBAL = [
|
|
8179
8517
|
{
|
|
8180
8518
|
id: "fast-model",
|
|
8181
8519
|
name: "Fast",
|
|
8182
8520
|
contextWindow: 2e5,
|
|
8183
|
-
maxTokens: 32e3
|
|
8184
|
-
creditMultiplier: .34
|
|
8521
|
+
maxTokens: 32e3
|
|
8185
8522
|
},
|
|
8186
8523
|
{
|
|
8187
8524
|
id: "balanced-model",
|
|
8188
8525
|
name: "Balanced",
|
|
8189
8526
|
contextWindow: 256e3,
|
|
8190
|
-
maxTokens: 32e3
|
|
8191
|
-
creditMultiplier: .59
|
|
8527
|
+
maxTokens: 32e3
|
|
8192
8528
|
},
|
|
8193
8529
|
{
|
|
8194
8530
|
id: "primary-model",
|
|
8195
8531
|
name: "Primary",
|
|
8196
8532
|
contextWindow: 272e3,
|
|
8197
|
-
maxTokens: 72e3
|
|
8198
|
-
creditMultiplier: 3.31
|
|
8533
|
+
maxTokens: 72e3
|
|
8199
8534
|
},
|
|
8200
8535
|
{
|
|
8201
8536
|
id: "deep-model",
|
|
8202
8537
|
name: "Deep",
|
|
8203
8538
|
contextWindow: 176e3,
|
|
8204
|
-
maxTokens: 24e3
|
|
8205
|
-
creditMultiplier: 3.33
|
|
8539
|
+
maxTokens: 24e3
|
|
8206
8540
|
},
|
|
8207
8541
|
{
|
|
8208
8542
|
id: "deepseek-v4.1-flash",
|
|
8209
8543
|
name: "Deepseek-V4.1-Flash",
|
|
8210
8544
|
contextWindow: 1e6,
|
|
8211
|
-
maxTokens: 128e3
|
|
8212
|
-
creditMultiplier: 0
|
|
8545
|
+
maxTokens: 128e3
|
|
8213
8546
|
},
|
|
8214
8547
|
{
|
|
8215
8548
|
id: "gpt-6-astra",
|
|
8216
8549
|
name: "GPT-6-Astra",
|
|
8217
8550
|
contextWindow: 1e6,
|
|
8218
|
-
maxTokens: 128e3
|
|
8219
|
-
creditMultiplier: 6.67
|
|
8551
|
+
maxTokens: 128e3
|
|
8220
8552
|
},
|
|
8221
8553
|
{
|
|
8222
8554
|
id: "hy4-preview",
|
|
8223
8555
|
name: "Hy4 preview",
|
|
8224
8556
|
contextWindow: 1e6,
|
|
8225
|
-
maxTokens: 64e3
|
|
8226
|
-
creditMultiplier: 0
|
|
8557
|
+
maxTokens: 64e3
|
|
8227
8558
|
},
|
|
8228
8559
|
{
|
|
8229
8560
|
id: "hy3",
|
|
8230
8561
|
name: "Hy3",
|
|
8231
8562
|
contextWindow: 192e3,
|
|
8232
|
-
maxTokens: 64e3
|
|
8233
|
-
creditMultiplier: 0
|
|
8563
|
+
maxTokens: 64e3
|
|
8234
8564
|
},
|
|
8235
8565
|
{
|
|
8236
8566
|
id: "gpt-5.6-sol",
|
|
8237
8567
|
name: "GPT-5.6-Sol",
|
|
8238
8568
|
contextWindow: 1e6,
|
|
8239
|
-
maxTokens: 128e3
|
|
8240
|
-
creditMultiplier: 3.47
|
|
8569
|
+
maxTokens: 128e3
|
|
8241
8570
|
},
|
|
8242
8571
|
{
|
|
8243
8572
|
id: "gpt-5.6-terra",
|
|
8244
8573
|
name: "GPT-5.6-Terra",
|
|
8245
8574
|
contextWindow: 1e6,
|
|
8246
|
-
maxTokens: 128e3
|
|
8247
|
-
creditMultiplier: 1.39
|
|
8575
|
+
maxTokens: 128e3
|
|
8248
8576
|
},
|
|
8249
8577
|
{
|
|
8250
8578
|
id: "gpt-5.6-luna",
|
|
8251
8579
|
name: "GPT-5.6-Luna",
|
|
8252
8580
|
contextWindow: 1e6,
|
|
8253
|
-
maxTokens: 128e3
|
|
8254
|
-
creditMultiplier: .14
|
|
8581
|
+
maxTokens: 128e3
|
|
8255
8582
|
},
|
|
8256
8583
|
{
|
|
8257
8584
|
id: "gpt-5.5",
|
|
8258
8585
|
name: "GPT-5.5",
|
|
8259
8586
|
contextWindow: 1e6,
|
|
8260
|
-
maxTokens: 128e3
|
|
8261
|
-
creditMultiplier: 3.31
|
|
8587
|
+
maxTokens: 128e3
|
|
8262
8588
|
},
|
|
8263
8589
|
{
|
|
8264
8590
|
id: "gpt-5.4",
|
|
8265
8591
|
name: "GPT-5.4",
|
|
8266
8592
|
contextWindow: 272e3,
|
|
8267
|
-
maxTokens: 72e3
|
|
8268
|
-
creditMultiplier: 1.65
|
|
8593
|
+
maxTokens: 72e3
|
|
8269
8594
|
},
|
|
8270
8595
|
{
|
|
8271
8596
|
id: "gpt-5.3-codex",
|
|
8272
8597
|
name: "GPT-5.3-Codex",
|
|
8273
8598
|
contextWindow: 272e3,
|
|
8274
|
-
maxTokens: 72e3
|
|
8275
|
-
creditMultiplier: 1.25
|
|
8599
|
+
maxTokens: 72e3
|
|
8276
8600
|
},
|
|
8277
8601
|
{
|
|
8278
8602
|
id: "gemini-3.5-flash",
|
|
8279
8603
|
name: "Gemini-3.5-Flash",
|
|
8280
8604
|
contextWindow: 1e6,
|
|
8281
|
-
maxTokens: 65536
|
|
8282
|
-
creditMultiplier: .99
|
|
8605
|
+
maxTokens: 65536
|
|
8283
8606
|
},
|
|
8284
8607
|
{
|
|
8285
8608
|
id: "glm-5.3",
|
|
8286
8609
|
name: "GLM-5.3",
|
|
8287
8610
|
contextWindow: 1e6,
|
|
8288
|
-
maxTokens: 48e3
|
|
8289
|
-
creditMultiplier: .79
|
|
8611
|
+
maxTokens: 48e3
|
|
8290
8612
|
},
|
|
8291
8613
|
{
|
|
8292
8614
|
id: "glm-5.2",
|
|
8293
8615
|
name: "GLM-5.2",
|
|
8294
8616
|
contextWindow: 1e6,
|
|
8295
|
-
maxTokens: 48e3
|
|
8296
|
-
creditMultiplier: .79
|
|
8617
|
+
maxTokens: 48e3
|
|
8297
8618
|
},
|
|
8298
8619
|
{
|
|
8299
8620
|
id: "kimi-k3",
|
|
8300
8621
|
name: "Kimi-K3",
|
|
8301
8622
|
contextWindow: 1e6,
|
|
8302
|
-
maxTokens: 32e3
|
|
8303
|
-
creditMultiplier: 1.62
|
|
8623
|
+
maxTokens: 32e3
|
|
8304
8624
|
},
|
|
8305
8625
|
{
|
|
8306
8626
|
id: "kimi-k2.6",
|
|
8307
8627
|
name: "Kimi-K2.6",
|
|
8308
8628
|
contextWindow: 256e3,
|
|
8309
|
-
maxTokens: 32e3
|
|
8310
|
-
creditMultiplier: .52
|
|
8629
|
+
maxTokens: 32e3
|
|
8311
8630
|
}
|
|
8312
8631
|
];
|
|
8313
8632
|
/**
|
|
@@ -8385,6 +8704,13 @@ function deriveCatalog(catalog, enabled, budgets = {}) {
|
|
|
8385
8704
|
var WorkBuddyCatalog = class {
|
|
8386
8705
|
models;
|
|
8387
8706
|
/**
|
|
8707
|
+
* Whether {@link models} came from the upstream at least once.
|
|
8708
|
+
*
|
|
8709
|
+
* Starts `false`: the constructor seeds the static fallback, and that list
|
|
8710
|
+
* must never be mistaken for a live answer (see {@link hasLiveRoster}).
|
|
8711
|
+
*/
|
|
8712
|
+
live = false;
|
|
8713
|
+
/**
|
|
8388
8714
|
* Whether this region has any local sign-in. Defaults to `true` — the
|
|
8389
8715
|
* permissive direction — so a scan that has not run yet (or failed) keeps
|
|
8390
8716
|
* serving the fallback rather than blanking a region that may be fine.
|
|
@@ -8424,6 +8750,28 @@ var WorkBuddyCatalog = class {
|
|
|
8424
8750
|
current() {
|
|
8425
8751
|
return this.usable && this.enabled ? this.models : [];
|
|
8426
8752
|
}
|
|
8753
|
+
/**
|
|
8754
|
+
* Whether {@link current} is an UPSTREAM answer rather than the built-in
|
|
8755
|
+
* fallback it was constructed with.
|
|
8756
|
+
*
|
|
8757
|
+
* This distinction is what keeps issue #32 fixed. `applySelection` passes
|
|
8758
|
+
* `current()` into `configuredModels` as the live roster to fall back to, so
|
|
8759
|
+
* a partial saved slot demotes to the live directory instead of the static
|
|
8760
|
+
* list. But before the first refresh lands, `current()` IS the static list
|
|
8761
|
+
* (the constructor seeds it), and `resolveRoster` cannot tell the two apart
|
|
8762
|
+
* because it only sees a non-empty array. The result was the exact bug #32
|
|
8763
|
+
* describes, reached from the other direction: a settings write arriving
|
|
8764
|
+
* before the first catalog refresh let the STATIC roster masquerade as live,
|
|
8765
|
+
* and `set()` then committed it — so a model that only exists upstream
|
|
8766
|
+
* (`space-bunny`) vanished from the picker while the runtime still served it.
|
|
8767
|
+
*
|
|
8768
|
+
* Callers that use `current()` as a *live* answer must check this first. A
|
|
8769
|
+
* caller that only wants "what would we advertise right now" does not need
|
|
8770
|
+
* to: the fallback is the honest answer to that question.
|
|
8771
|
+
*/
|
|
8772
|
+
hasLiveRoster() {
|
|
8773
|
+
return this.live;
|
|
8774
|
+
}
|
|
8427
8775
|
/** Whether this region currently advertises any model. */
|
|
8428
8776
|
isRegionUsable() {
|
|
8429
8777
|
return this.usable;
|
|
@@ -8462,9 +8810,21 @@ var WorkBuddyCatalog = class {
|
|
|
8462
8810
|
this.enabled = enabled;
|
|
8463
8811
|
return true;
|
|
8464
8812
|
}
|
|
8465
|
-
/**
|
|
8466
|
-
|
|
8813
|
+
/**
|
|
8814
|
+
* Replace the list; callers invalidate their adapter snapshot after this.
|
|
8815
|
+
*
|
|
8816
|
+
* `origin` says where the list came from, and it is not cosmetic: only an
|
|
8817
|
+
* `upstream` answer may mark the catalog live. `applySelection` also calls
|
|
8818
|
+
* this on every settings write — including before the first refresh has
|
|
8819
|
+
* landed — and the list it passes then is the static fallback. Letting that
|
|
8820
|
+
* count as live is what re-opened issue #32 (see {@link hasLiveRoster}).
|
|
8821
|
+
*
|
|
8822
|
+
* The default is `'upstream'` so every pre-existing call site keeps meaning
|
|
8823
|
+
* what it meant; only the re-derivation path opts into `'derived'`.
|
|
8824
|
+
*/
|
|
8825
|
+
set(models, origin = "upstream") {
|
|
8467
8826
|
if (models.length === 0) throw new Error("workbuddy model catalog cannot be empty");
|
|
8827
|
+
if (origin === "upstream") this.live = true;
|
|
8468
8828
|
this.models = models.map((model) => ({ ...model }));
|
|
8469
8829
|
}
|
|
8470
8830
|
};
|
|
@@ -9032,7 +9392,9 @@ function createDeviceSdkPort(options) {
|
|
|
9032
9392
|
await options.sdk.tokens.refresh();
|
|
9033
9393
|
return snap();
|
|
9034
9394
|
},
|
|
9035
|
-
reveal: () => options.sdk.tokens.reveal()
|
|
9395
|
+
reveal: () => options.sdk.tokens.reveal(),
|
|
9396
|
+
readEnabled: async () => options.enabled === void 0 ? void 0 : options.enabled.read(),
|
|
9397
|
+
writeEnabled: async (enabled) => options.enabled === void 0 ? false : options.enabled.write(enabled)
|
|
9036
9398
|
};
|
|
9037
9399
|
}
|
|
9038
9400
|
/**
|
|
@@ -9049,6 +9411,21 @@ function createTuringSdk(options = {}) {
|
|
|
9049
9411
|
...TURING_KEEP_ALIVE_TIMING,
|
|
9050
9412
|
...options.keepAliveTiming
|
|
9051
9413
|
};
|
|
9414
|
+
/**
|
|
9415
|
+
* 每次**现读**开关,不在构造时求值一次。
|
|
9416
|
+
*
|
|
9417
|
+
* 开关是 `asVolatile` 的配置项,热更新后会变;而句柄活到卸载。钉死一次会让
|
|
9418
|
+
* "关掉开关"必须重启宿主才生效——那与这个开关存在的理由(随时能停)矛盾。
|
|
9419
|
+
*
|
|
9420
|
+
* 未传 `enabled` 时回落到环境变量({@link TURING_SDK_ENABLED_ENV}):那是给
|
|
9421
|
+
* `doctor` 这种读不到插件配置的独立进程用的。插件永远显式传,所以两边不会打架。
|
|
9422
|
+
*
|
|
9423
|
+
* **默认也是关**,与插件的 `default(false)` 同一个答案。代价是 `doctor` 在用户
|
|
9424
|
+
* 开启之前只答 `disabled`——但那正是现状,而 `doctor` 的全部价值就是如实回答
|
|
9425
|
+
* 现状。想排障"这个 SDK 到底能不能用",用
|
|
9426
|
+
* `WORKBUDDY_DEVICE_SDK_ENABLED=1 node lib/bin.js doctor` 临时打开即可。
|
|
9427
|
+
*/
|
|
9428
|
+
const isEnabled = () => options.enabled !== void 0 ? options.enabled !== false : /^(?:1|true)$/u.test(String((options.env ?? process.env)["WORKBUDDY_DEVICE_SDK_ENABLED"] ?? "").trim());
|
|
9052
9429
|
const platform = options.platform ?? process.platform;
|
|
9053
9430
|
const arch = options.arch ?? process.arch;
|
|
9054
9431
|
const env = options.env ?? process.env;
|
|
@@ -9110,6 +9487,21 @@ function createTuringSdk(options = {}) {
|
|
|
9110
9487
|
};
|
|
9111
9488
|
async function probe() {
|
|
9112
9489
|
const at = now();
|
|
9490
|
+
/**
|
|
9491
|
+
* 总开关先于一切:关掉时**不解析目录、不碰文件系统、不起子进程**。
|
|
9492
|
+
*
|
|
9493
|
+
* 放在 `resolveDir()` 之前是刻意的——目录解析本身要读环境、可能读注册表(win32),
|
|
9494
|
+
* 而关掉开关的人要的正是"这个插件别去碰桌面端"。
|
|
9495
|
+
*/
|
|
9496
|
+
if (!isEnabled()) return {
|
|
9497
|
+
state: "disabled",
|
|
9498
|
+
bundle,
|
|
9499
|
+
path: "",
|
|
9500
|
+
platform,
|
|
9501
|
+
arch,
|
|
9502
|
+
runtime: runtimeLabel,
|
|
9503
|
+
reason: "the real-device SDK is turned off in this plugin's settings"
|
|
9504
|
+
};
|
|
9113
9505
|
const dir = await resolveDir();
|
|
9114
9506
|
if (probeCache !== void 0 && probeCache.path === dir && at - probeCache.at < PROBE_CACHE_MS) return probeCache.info;
|
|
9115
9507
|
let info;
|
|
@@ -9197,6 +9589,7 @@ function createTuringSdk(options = {}) {
|
|
|
9197
9589
|
}
|
|
9198
9590
|
async function current() {
|
|
9199
9591
|
const at = now();
|
|
9592
|
+
if (!isEnabled()) return void 0;
|
|
9200
9593
|
if (cached !== void 0 && at - cached.fetchedAtMs <= ttlMs) return cached.token;
|
|
9201
9594
|
if (lastFailureAtMs !== void 0 && at - lastFailureAtMs < RETRY_BACKOFF_MS) return cached !== void 0 && at - cached.fetchedAtMs <= TURING_TOKEN_STALE_MS ? cached.token : void 0;
|
|
9202
9595
|
if (inFlight !== void 0) return inFlight;
|
|
@@ -9219,6 +9612,7 @@ function createTuringSdk(options = {}) {
|
|
|
9219
9612
|
*/
|
|
9220
9613
|
async function warm() {
|
|
9221
9614
|
const at = now();
|
|
9615
|
+
if (!isEnabled()) return;
|
|
9222
9616
|
const failedSinceFetch = cached !== void 0 && lastFailureAtMs !== void 0 && lastFailureAtMs >= cached.fetchedAtMs;
|
|
9223
9617
|
if (cached !== void 0 && at - cached.fetchedAtMs < ttlMs - keepAliveTiming.leadMs && !failedSinceFetch) return;
|
|
9224
9618
|
if (lastFailureAtMs !== void 0 && at - lastFailureAtMs < RETRY_BACKOFF_MS) return;
|
|
@@ -9261,6 +9655,7 @@ function createTuringSdk(options = {}) {
|
|
|
9261
9655
|
return {
|
|
9262
9656
|
info: probe,
|
|
9263
9657
|
startAutoRefresh() {
|
|
9658
|
+
if (!isEnabled()) return;
|
|
9264
9659
|
if (keepAliveActive) return;
|
|
9265
9660
|
keepAliveActive = true;
|
|
9266
9661
|
tick();
|
|
@@ -9665,7 +10060,7 @@ function describeRosterSeenPayload(raw) {
|
|
|
9665
10060
|
//#endregion
|
|
9666
10061
|
//#region src/version.ts
|
|
9667
10062
|
/** The npm package version this build was produced from. */
|
|
9668
|
-
const WORKBUDDY_CONNECT_VERSION = "5.
|
|
10063
|
+
const WORKBUDDY_CONNECT_VERSION = "5.18.2";
|
|
9669
10064
|
//#endregion
|
|
9670
10065
|
//#region src/host-heartbeat.ts
|
|
9671
10066
|
/**
|
|
@@ -9876,4 +10271,4 @@ async function clearHostHeartbeat() {
|
|
|
9876
10271
|
await rm(workbuddyHostHeartbeatPath(), { force: true });
|
|
9877
10272
|
}
|
|
9878
10273
|
//#endregion
|
|
9879
|
-
export { WorkBuddyCredentialRejectedError as $,
|
|
10274
|
+
export { WorkBuddyCredentialRejectedError as $, ensureDeviceSalt as $t, WORKBUDDY_AUTH_FILENAME as A, VIDEO_TAG_TEXT_TO_VIDEO as At, isEncryptedCredentialError as B, imageMimeForPath as Bt, FALLBACK_WORKBUDDY_MODELS_GLOBAL as C, defaultOffModelIds as Ct, fallbackModelsFor as D, recordRefusal as Dt, deriveCatalog as E, offRefused as Et, authFileName as F, IMAGE_TAG_IMAGE_TO_IMAGE as Ft, workbuddyAccountId as G, parseQueueAnswer as Gt, legacyWorkbuddyOwnAuthPath as H, parseImageDataUrl as Ht, defaultDesktopAuthCandidates as I, IMAGE_TAG_TEXT_TO_IMAGE as It, APP_VERSION as J, NATIVE_MODALITY_BY_MODEL_ID as Jt, workbuddyOwnAuthPath as K, queueNoticeText as Kt, defaultDesktopAuthDirs as L, MAX_INPUT_IMAGE_BYTES as Lt, WORKBUDDY_VAULT_DIRNAME as M, parseSupportedSecondsRange as Mt, WorkBuddyCredentialStore as N, pickVideoModel as Nt, withoutRouters as O, withEffectiveOff as Ot, WorkBuddyEncryptedCredentialError as P, resolveVideoParams as Pt, WORKBUDDY_FALLBACK_SYSTEM_PROMPT as Q, readDeviceTokenFile as Qt, defaultDesktopAuthPath as R, WorkBuddyImageError as Rt, FALLBACK_WORKBUDDY_MODELS as S, writeFileAtomic as Sn, REFUSES_OFF_MODEL_IDS as St, applyContextBudgets as T, offDefaultFor as Tt, parseWorkBuddyAuth as U, pickMediaModel as Ut, isVaultAccountId as V, isBareBase64Image as Vt, preferredAccountName as W, sniffImageMime as Wt, CREDENTIAL_REJECTED_CODE as X, nativeModalityOf as Xt, CONTEXT_OVERFLOW_MARKER as Y, imageDefaultFor as Yt, DEFAULT_WIRE_PROFILE as Z, WORKBUDDY_DEVICE_TOKEN_FILE_ENV as Zt, isDeviceMode as _, readAtRestKey as _n, prepareChatBody as _t, readHostHeartbeat as a, WORKBUDDY_APP_EXECUTABLE_ENV as an, forceNeutralHead as at, saveDeviceSdkSettings as b, resolveDshHome as bn, rewriteSessionTitleModel as bt, WORKBUDDY_CONNECT_VERSION as c, deriveAtRestKeyId as cn, isCredentialRejectedError as ct, rosterSeenPath as d, findWorkbuddyAppExecutableWithSource as dn, modelIdOfBody as dt, readDeviceSalt as en, WorkBuddyUpstreamClient as et, piAiRuntimeInfo as f, isEncryptedFieldWrapper as fn, openingEvidenceOfBody as ft, describeDerivedDevices as g, openEncryptedField as gn, perturbChannelFingerprints as gt, createDeviceProfileLookup as h, macosNestedAppBundles as hn, parseUpstreamModel as ht, processStartTimeMs as i, protectCredentialDirectory as in, describeRequestHeaderNames as it, WORKBUDDY_AUTH_FILE_ENV as j, WorkBuddyVideoError as jt, ENCRYPTED_CREDENTIAL_CODE as k, VIDEO_TAG_IMAGE_TO_VIDEO as kt, createFileRosterSeenStore as l, fetchAtRestKeyPayload as ln, isFirstMessageGateBody as lt, createTuringSdk as m, macosBundleExecutable as mn, parseReasoning as mt, clearHostHeartbeat as n, isDeviceId as nn, classifyUpstreamError as nt, workbuddyHostHeartbeatPath as o, clearAtRestKeyCache as on, isContextTooLongBody as ot, createDeviceSdkPort as p, isWorkbuddyBundle as pn, parseCreditMultiplier as pt, workbuddyVaultDir as q, pruneTempDir as qt, isHeartbeatProcessAlive as r, inspectCredentialDirectory as rn, declaredTools as rt, writeHostHeartbeat as s, deriveAtRestKey as sn, isConversationIdGateBody as st, WORKBUDDY_HOST_HEARTBEAT_FILENAME as t, deriveDeviceId as tn, channelGateMemberOf as tt, describeRosterSeenPayload as u, findWorkbuddyAppExecutable as un, knownRegionOf as ut, readDeviceSettings as v, workbuddyAppExecutableCandidates as vn, regionOf as vt, WorkBuddyCatalog as w, lastRefusalFor as wt, setDeviceMode as x, withFileLock as xn, attachBusyLevels as xt, saveDeviceProfile as y, hostPeersInfo as yn, requestEvidenceOf as yt, hasEncryptedCredentialFields as z, imageDataUrl as zt };
|