@dotobokuri/fleet-console 1.57.1 → 1.58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.mjs +92 -7
- package/dist/client/assets/{_baseUniq-dvybACFL.js → _baseUniq-DJ4C0UQF.js} +1 -1
- package/dist/client/assets/{arc-BM1EQJ5i.js → arc-DkQKttnC.js} +1 -1
- package/dist/client/assets/{architectureDiagram-Q4EWVU46-C5NpB_9B.js → architectureDiagram-Q4EWVU46-BpuET3uK.js} +1 -1
- package/dist/client/assets/{blockDiagram-DXYQGD6D-BemCHdjP.js → blockDiagram-DXYQGD6D-CatlulZp.js} +1 -1
- package/dist/client/assets/{c4Diagram-AHTNJAMY-BB7Qe4id.js → c4Diagram-AHTNJAMY-BPfWevDh.js} +1 -1
- package/dist/client/assets/channel-DDcyY5eB.js +1 -0
- package/dist/client/assets/{chunk-4BX2VUAB-CqmbYj1h.js → chunk-4BX2VUAB-a7lkla2P.js} +1 -1
- package/dist/client/assets/{chunk-4TB4RGXK-DY8csFL8.js → chunk-4TB4RGXK-Bh-20OVN.js} +1 -1
- package/dist/client/assets/{chunk-55IACEB6-Bc2JNsBB.js → chunk-55IACEB6-DiPm-_AS.js} +1 -1
- package/dist/client/assets/{chunk-EDXVE4YY-B7fkHilr.js → chunk-EDXVE4YY-BcGep4mz.js} +1 -1
- package/dist/client/assets/{chunk-FMBD7UC4-CKS1kchI.js → chunk-FMBD7UC4-Cn0A6Wm1.js} +1 -1
- package/dist/client/assets/{chunk-OYMX7WX6-BoSMhV9B.js → chunk-OYMX7WX6-DNTIDjw4.js} +1 -1
- package/dist/client/assets/{chunk-QZHKN3VN-B6NI5Nv8.js → chunk-QZHKN3VN-cji_BhbG.js} +1 -1
- package/dist/client/assets/{chunk-YZCP3GAM-DDwSQ8RI.js → chunk-YZCP3GAM-B6I5kLlB.js} +1 -1
- package/dist/client/assets/classDiagram-6PBFFD2Q-CqqUqRwS.js +1 -0
- package/dist/client/assets/classDiagram-v2-HSJHXN6E-CqqUqRwS.js +1 -0
- package/dist/client/assets/clone-CjMEm_X8.js +1 -0
- package/dist/client/assets/{cose-bilkent-S5V4N54A-VjTSxeFA.js → cose-bilkent-S5V4N54A-_Xmui3Dj.js} +1 -1
- package/dist/client/assets/{dagre-KV5264BT-BQSQIPKP.js → dagre-KV5264BT-BI_m6tGN.js} +1 -1
- package/dist/client/assets/{diagram-5BDNPKRD-C6e_Ovvo.js → diagram-5BDNPKRD-JDBqcRRR.js} +1 -1
- package/dist/client/assets/{diagram-G4DWMVQ6-D6vqaIMN.js → diagram-G4DWMVQ6-CdIHKaZT.js} +1 -1
- package/dist/client/assets/{diagram-MMDJMWI5-DFxtu5Sa.js → diagram-MMDJMWI5-CULX6wM5.js} +1 -1
- package/dist/client/assets/{diagram-TYMM5635-BcYaszXB.js → diagram-TYMM5635-C1JXiI2W.js} +1 -1
- package/dist/client/assets/{erDiagram-SMLLAGMA-DLSCg-9y.js → erDiagram-SMLLAGMA-RJI8bZrW.js} +1 -1
- package/dist/client/assets/{flowDiagram-DWJPFMVM-_kx-OfzH.js → flowDiagram-DWJPFMVM-CSrF7U0E.js} +1 -1
- package/dist/client/assets/{ganttDiagram-T4ZO3ILL-DluEefPv.js → ganttDiagram-T4ZO3ILL-CHp3LObA.js} +1 -1
- package/dist/client/assets/{gitGraphDiagram-UUTBAWPF-BDHypYJk.js → gitGraphDiagram-UUTBAWPF-BEeoTjqh.js} +1 -1
- package/dist/client/assets/{graph-CHPq19s3.js → graph-DNvMdh3j.js} +1 -1
- package/dist/client/assets/index-BG857Idy.css +1 -0
- package/dist/client/assets/index-CCNdSGui.js +483 -0
- package/dist/client/assets/{infoDiagram-42DDH7IO-BhntKSlv.js → infoDiagram-42DDH7IO-31kh8JMu.js} +1 -1
- package/dist/client/assets/{ishikawaDiagram-UXIWVN3A-Vo0lWYeZ.js → ishikawaDiagram-UXIWVN3A-DZgEgolJ.js} +1 -1
- package/dist/client/assets/{journeyDiagram-VCZTEJTY-B-jydfQ3.js → journeyDiagram-VCZTEJTY-DfZ3i3Bu.js} +1 -1
- package/dist/client/assets/{kanban-definition-6JOO6SKY-CR7_O2tt.js → kanban-definition-6JOO6SKY-giivFfnv.js} +1 -1
- package/dist/client/assets/{layout-C7qyIJFE.js → layout-DdVRNrH8.js} +1 -1
- package/dist/client/assets/{linear-ClKfz3Xw.js → linear-3cmeYdGh.js} +1 -1
- package/dist/client/assets/{mermaid.core-eHgX1dDu.js → mermaid.core-Cjqy_Y5Z.js} +4 -4
- package/dist/client/assets/{min-CBcfPH4t.js → min-Cgsd0one.js} +1 -1
- package/dist/client/assets/{mindmap-definition-QFDTVHPH-BrjeA0rz.js → mindmap-definition-QFDTVHPH-PfuGubxC.js} +1 -1
- package/dist/client/assets/{pieDiagram-DEJITSTG-Bx3gB3ns.js → pieDiagram-DEJITSTG-B9O6H439.js} +1 -1
- package/dist/client/assets/{quadrantDiagram-34T5L4WZ-Y_8L8YCa.js → quadrantDiagram-34T5L4WZ-DJH7RQzs.js} +1 -1
- package/dist/client/assets/{requirementDiagram-MS252O5E-BByFdhc4.js → requirementDiagram-MS252O5E-BZHTYV2q.js} +1 -1
- package/dist/client/assets/{sankeyDiagram-XADWPNL6-Du7m7fuy.js → sankeyDiagram-XADWPNL6-B5aGVyLG.js} +1 -1
- package/dist/client/assets/{sequenceDiagram-FGHM5R23-DovViawI.js → sequenceDiagram-FGHM5R23-D2890FYU.js} +1 -1
- package/dist/client/assets/{stateDiagram-FHFEXIEX-7fVJHvbx.js → stateDiagram-FHFEXIEX-DWmhZMWZ.js} +1 -1
- package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-DoQKtZ4H.js +1 -0
- package/dist/client/assets/{timeline-definition-GMOUNBTQ-Dgsxq4-O.js → timeline-definition-GMOUNBTQ-B0pTOfcD.js} +1 -1
- package/dist/client/assets/{vennDiagram-DHZGUBPP-D2tu5aMx.js → vennDiagram-DHZGUBPP-D-S4XLnE.js} +1 -1
- package/dist/client/assets/{wardley-RL74JXVD-C4IVs_k4.js → wardley-RL74JXVD-ClPA8Fc3.js} +1 -1
- package/dist/client/assets/{wardleyDiagram-NUSXRM2D-DCVn_9G_.js → wardleyDiagram-NUSXRM2D-JJgj7CxJ.js} +1 -1
- package/dist/client/assets/{xychartDiagram-5P7HB3ND-D1TZkyWh.js → xychartDiagram-5P7HB3ND-BBIy9-Kq.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/fleet-plugins/ledger/routes.mjs +35 -0
- package/dist/fleet-plugins/quota/routes.mjs +484 -63
- package/dist/fleet-plugins/scuttlebutt/routes.mjs +92 -7
- package/dist/fleet-plugins/terminal/routes.mjs +1379 -543
- package/dist/fleet.mjs +1603 -676
- package/package.json +1 -1
- package/dist/client/assets/channel-t207uO3V.js +0 -1
- package/dist/client/assets/classDiagram-6PBFFD2Q-Dg0z8qFh.js +0 -1
- package/dist/client/assets/classDiagram-v2-HSJHXN6E-Dg0z8qFh.js +0 -1
- package/dist/client/assets/clone-B47TzRxK.js +0 -1
- package/dist/client/assets/index-D6_LDhkV.css +0 -1
- package/dist/client/assets/index-DeiAnv0J.js +0 -483
- package/dist/client/assets/stateDiagram-v2-QKLJ7IA2-CQPjJLLI.js +0 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
2
|
+
import * as path19 from 'node:path';
|
|
3
|
+
import path19__default, { posix, dirname } from 'node:path';
|
|
4
4
|
import * as fs9 from 'node:fs';
|
|
5
5
|
import fs9__default, { constants, existsSync, readFileSync, mkdirSync, rmSync, renameSync, appendFileSync, mkdtempSync, writeFileSync, statSync, chmodSync, readdirSync, closeSync, fstatSync, lstatSync, accessSync, realpathSync, openSync, promises } from 'node:fs';
|
|
6
6
|
import * as os3 from 'node:os';
|
|
7
7
|
import os3__default, { tmpdir } from 'node:os';
|
|
8
8
|
import { execFile } from 'node:child_process';
|
|
9
|
-
import
|
|
9
|
+
import fs32, { appendFile, chmod, open, mkdtemp, mkdir, rm, writeFile, rename, stat, readFile, readdir, realpath, lstat, unlink } from 'node:fs/promises';
|
|
10
10
|
import { promisify } from 'node:util';
|
|
11
11
|
import crypto5, { randomUUID, createHash } from 'node:crypto';
|
|
12
12
|
import http2 from 'node:http2';
|
|
@@ -26,33 +26,33 @@ var __export = (target2, all) => {
|
|
|
26
26
|
function definePlugin(definition) {
|
|
27
27
|
return definition;
|
|
28
28
|
}
|
|
29
|
-
function registerRouter(ctx,
|
|
29
|
+
function registerRouter(ctx, path43, handler, catalog) {
|
|
30
30
|
if (catalog) {
|
|
31
|
-
ctx.registerRouter(normalizePath(
|
|
31
|
+
ctx.registerRouter(normalizePath(path43), handler, catalog);
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
|
-
ctx.registerRouter(normalizePath(
|
|
34
|
+
ctx.registerRouter(normalizePath(path43), handler);
|
|
35
35
|
}
|
|
36
|
-
function registerWsHandler(ctx,
|
|
36
|
+
function registerWsHandler(ctx, path43, handler, catalog) {
|
|
37
37
|
if (catalog) {
|
|
38
|
-
ctx.registerWsHandler(normalizePath(
|
|
38
|
+
ctx.registerWsHandler(normalizePath(path43), handler, catalog);
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
ctx.registerWsHandler(normalizePath(
|
|
41
|
+
ctx.registerWsHandler(normalizePath(path43), handler);
|
|
42
42
|
}
|
|
43
43
|
function registerLaunchCatalog(ctx, provider) {
|
|
44
44
|
return ctx.host.operations.registerLaunchCatalog(ctx.pluginId, provider);
|
|
45
45
|
}
|
|
46
|
-
function normalizePath(
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
46
|
+
function normalizePath(path43) {
|
|
47
|
+
if (path43.length === 0 || path43 === "/") return "/";
|
|
48
|
+
return path43;
|
|
49
49
|
}
|
|
50
50
|
var FLEET_DATA_DIR_NAME = ".fleet";
|
|
51
51
|
var FLEET_DATA_DIR_ENV = "FLEET_DATA_DIR";
|
|
52
52
|
function getFleetDataDir(env = process.env) {
|
|
53
53
|
const override = env[FLEET_DATA_DIR_ENV];
|
|
54
|
-
if (override === void 0 || override.trim().length === 0) return
|
|
55
|
-
if (!
|
|
54
|
+
if (override === void 0 || override.trim().length === 0) return path19.join(os3.homedir(), FLEET_DATA_DIR_NAME);
|
|
55
|
+
if (!path19.isAbsolute(override)) throw new Error(`${FLEET_DATA_DIR_ENV} must be an absolute path, received: ${override}`);
|
|
56
56
|
return override;
|
|
57
57
|
}
|
|
58
58
|
var SECURE_DIR_MODE = 448;
|
|
@@ -85,9 +85,9 @@ function ensureSafeDirectory(dirPath) {
|
|
|
85
85
|
fs9.chmodSync(dirPath, SECURE_DIR_MODE);
|
|
86
86
|
}
|
|
87
87
|
function assertWithinRoot(root, candidatePath) {
|
|
88
|
-
const resolvedRoot =
|
|
89
|
-
const resolvedCandidate =
|
|
90
|
-
if (!resolvedCandidate.startsWith(`${resolvedRoot}${
|
|
88
|
+
const resolvedRoot = path19.resolve(root);
|
|
89
|
+
const resolvedCandidate = path19.resolve(candidatePath);
|
|
90
|
+
if (!resolvedCandidate.startsWith(`${resolvedRoot}${path19.sep}`) && resolvedCandidate !== resolvedRoot) {
|
|
91
91
|
throw new Error(`Path escapes root: ${candidatePath}`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -148,7 +148,7 @@ function cleanupTempFiles(dir, prefix, minAgeMs, now) {
|
|
|
148
148
|
if (!entry.startsWith(prefix)) {
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
const tempPath =
|
|
151
|
+
const tempPath = path19.join(dir, entry);
|
|
152
152
|
try {
|
|
153
153
|
const stat4 = fs9.lstatSync(tempPath);
|
|
154
154
|
if (stat4?.isFile() && !stat4.isSymbolicLink() && now - stat4.mtimeMs >= minAgeMs) {
|
|
@@ -254,7 +254,7 @@ function writeLockOwner(lockDir, ownerFileName, startedAt) {
|
|
|
254
254
|
hostname: os3.hostname(),
|
|
255
255
|
startedAt
|
|
256
256
|
};
|
|
257
|
-
const ownerPath =
|
|
257
|
+
const ownerPath = path19.join(lockDir, ownerFileName);
|
|
258
258
|
try {
|
|
259
259
|
fs9.writeFileSync(ownerPath, JSON.stringify(owner), { encoding: "utf-8", mode: 384 });
|
|
260
260
|
} catch (error51) {
|
|
@@ -263,7 +263,7 @@ function writeLockOwner(lockDir, ownerFileName, startedAt) {
|
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
function readLockOwner(lockDir, ownerFileName) {
|
|
266
|
-
const ownerPath =
|
|
266
|
+
const ownerPath = path19.join(lockDir, ownerFileName);
|
|
267
267
|
try {
|
|
268
268
|
return sanitizeLockOwner(JSON.parse(fs9.readFileSync(ownerPath, "utf-8")));
|
|
269
269
|
} catch (error51) {
|
|
@@ -303,10 +303,10 @@ function isProcessAlive(pid) {
|
|
|
303
303
|
}
|
|
304
304
|
function sanitizeLockOwner(value) {
|
|
305
305
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
306
|
-
const
|
|
307
|
-
const pid =
|
|
308
|
-
const hostname5 =
|
|
309
|
-
const startedAt =
|
|
306
|
+
const record7 = value;
|
|
307
|
+
const pid = record7.pid;
|
|
308
|
+
const hostname5 = record7.hostname;
|
|
309
|
+
const startedAt = record7.startedAt;
|
|
310
310
|
if (!Number.isInteger(pid) || pid <= 0) return null;
|
|
311
311
|
if (typeof hostname5 !== "string" || !hostname5) return null;
|
|
312
312
|
if (!Number.isFinite(startedAt) || startedAt <= 0) return null;
|
|
@@ -321,7 +321,7 @@ function sleepSync(ms) {
|
|
|
321
321
|
}
|
|
322
322
|
|
|
323
323
|
// ../../packages/core-infra/src/auth/auth-storage.ts
|
|
324
|
-
var DEFAULT_AUTH_PATH =
|
|
324
|
+
var DEFAULT_AUTH_PATH = path19.join(getFleetDataDir(), "auth.json");
|
|
325
325
|
var AUTH_LOCK_OWNER_FILE_NAME = "owner.json";
|
|
326
326
|
var AUTH_LOCK_TIMEOUT_MS = 5e3;
|
|
327
327
|
function readAuthStoreFile(filePath) {
|
|
@@ -396,7 +396,7 @@ function createAuthService(deps = {}) {
|
|
|
396
396
|
}
|
|
397
397
|
},
|
|
398
398
|
async setApiKey(providerId, key) {
|
|
399
|
-
const dir =
|
|
399
|
+
const dir = path19.dirname(authPath);
|
|
400
400
|
ensureSafeDirectory(dir);
|
|
401
401
|
withAuthLock(authPath, lockDir, () => {
|
|
402
402
|
const data = fs9.existsSync(authPath) ? readAuthStoreFile(authPath) : {};
|
|
@@ -432,7 +432,7 @@ function createDurableJsonStore(deps) {
|
|
|
432
432
|
const sensitivity = deps.sensitivity;
|
|
433
433
|
const mode = sensitivity === "sensitive" ? SECURE_FILE_MODE : 420;
|
|
434
434
|
const minAgeMs = deps.tempCleanupMinAgeMs ?? DEFAULT_TEMP_FILE_MIN_AGE_MS;
|
|
435
|
-
const dir =
|
|
435
|
+
const dir = path19.dirname(deps.filePath);
|
|
436
436
|
return {
|
|
437
437
|
path: deps.filePath,
|
|
438
438
|
load() {
|
|
@@ -532,8 +532,8 @@ function updateGlobalOptions(store, mutate) {
|
|
|
532
532
|
}
|
|
533
533
|
function createGlobalOptionsStore(deps = {}) {
|
|
534
534
|
const dataDir = deps.dataDir ?? getFleetDataDir();
|
|
535
|
-
const optionsPath =
|
|
536
|
-
const lockDir =
|
|
535
|
+
const optionsPath = path19.join(dataDir, GLOBAL_OPTIONS_FILE_NAME);
|
|
536
|
+
const lockDir = path19.join(dataDir, LOCK_DIR_NAME);
|
|
537
537
|
const store = createDurableJsonStore({
|
|
538
538
|
filePath: optionsPath,
|
|
539
539
|
lockDir,
|
|
@@ -676,7 +676,7 @@ function getWorkspaceDirectoryRoot(dataDir) {
|
|
|
676
676
|
if (!dataDir.trim()) {
|
|
677
677
|
throw new Error("Fleet data directory is required");
|
|
678
678
|
}
|
|
679
|
-
return
|
|
679
|
+
return path19.join(path19.resolve(dataDir), WORKSPACES_DIRECTORY_NAME);
|
|
680
680
|
}
|
|
681
681
|
function resolveWorkspaceDirectory(dataDir, cwd) {
|
|
682
682
|
const canonicalCwd = canonicalizeWorkspaceCwd(cwd);
|
|
@@ -684,7 +684,7 @@ function resolveWorkspaceDirectory(dataDir, cwd) {
|
|
|
684
684
|
}
|
|
685
685
|
function ensureWorkspaceDirectory(dataDir, cwd) {
|
|
686
686
|
const workspace = resolveWorkspaceDirectory(dataDir, cwd);
|
|
687
|
-
const resolvedDataDir =
|
|
687
|
+
const resolvedDataDir = path19.resolve(dataDir);
|
|
688
688
|
ensureSafeDirectory(resolvedDataDir);
|
|
689
689
|
ensureSafeDirectory(workspace.root);
|
|
690
690
|
assertWithinRoot(workspace.root, workspace.path);
|
|
@@ -709,11 +709,11 @@ function ensureWorkspaceDirectory(dataDir, cwd) {
|
|
|
709
709
|
function buildWorkspaceDirectory(dataDir, name, cwd) {
|
|
710
710
|
assertWorkspaceDirectoryName(name);
|
|
711
711
|
const root = getWorkspaceDirectoryRoot(dataDir);
|
|
712
|
-
const workspacePath =
|
|
712
|
+
const workspacePath = path19.join(root, name);
|
|
713
713
|
assertWithinRoot(root, workspacePath);
|
|
714
714
|
return {
|
|
715
715
|
cwd,
|
|
716
|
-
identityPath:
|
|
716
|
+
identityPath: path19.join(workspacePath, WORKSPACE_IDENTITY_FILE_NAME),
|
|
717
717
|
name,
|
|
718
718
|
path: workspacePath,
|
|
719
719
|
root
|
|
@@ -723,7 +723,7 @@ function canonicalizeWorkspaceCwd(cwd) {
|
|
|
723
723
|
if (!cwd.trim()) {
|
|
724
724
|
throw new Error("Workspace cwd is required");
|
|
725
725
|
}
|
|
726
|
-
return fs9.realpathSync.native(
|
|
726
|
+
return fs9.realpathSync.native(path19.resolve(cwd));
|
|
727
727
|
}
|
|
728
728
|
function assertWorkspaceDirectoryName(name) {
|
|
729
729
|
if (!name || !WORKSPACE_NAME_PATTERN.test(name)) {
|
|
@@ -749,8 +749,8 @@ function readWorkspaceIdentity(identityPath) {
|
|
|
749
749
|
}
|
|
750
750
|
function isWorkspaceDirectoryIdentity(value) {
|
|
751
751
|
if (typeof value !== "object" || value === null) return false;
|
|
752
|
-
const
|
|
753
|
-
return typeof
|
|
752
|
+
const record7 = value;
|
|
753
|
+
return typeof record7.cwd === "string" && record7.cwd.length > 0;
|
|
754
754
|
}
|
|
755
755
|
|
|
756
756
|
// ../../packages/core-infra/src/index.ts
|
|
@@ -1008,9 +1008,14 @@ function isHostSessionToolAllowed(_toolId, _doctrine) {
|
|
|
1008
1008
|
|
|
1009
1009
|
// ../../packages/fleet-admiral/src/agent-cli/types.ts
|
|
1010
1010
|
var MAX_LAUNCH_PROMPT_CHARS = 16e3;
|
|
1011
|
-
|
|
1012
|
-
// ../../packages/fleet-admiral/src/agent-cli/prompt.ts
|
|
1013
1011
|
var CMD_UNSAFE_PROMPT_PATTERN = /["&<>()@^|%]/;
|
|
1012
|
+
var LAUNCH_PROMPT_FILE_MODE = 384;
|
|
1013
|
+
var LAUNCH_PROMPT_TEMP_DIR_PREFIX = "fleet-quick-launch-";
|
|
1014
|
+
var LAUNCH_PROMPT_FILE_NAME = "prompt.md";
|
|
1015
|
+
var LAUNCH_PROMPT_FILE_INSTRUCTION_PREFIX = "Read and follow the launch prompt file: ";
|
|
1016
|
+
function launchPromptHasCmdUnsafeChars(prompt) {
|
|
1017
|
+
return CMD_UNSAFE_PROMPT_PATTERN.test(prompt);
|
|
1018
|
+
}
|
|
1014
1019
|
var WINDOWS_CMD_SHIM_COMMAND_LINE_MAX_CHARS = 8191;
|
|
1015
1020
|
var WINDOWS_CREATE_PROCESS_COMMAND_LINE_MAX_CHARS = 32767;
|
|
1016
1021
|
var LaunchPromptError = class extends Error {
|
|
@@ -1074,6 +1079,12 @@ function assertLaunchCommandLineBudget(options) {
|
|
|
1074
1079
|
`The launch command line is ${withoutPrompt} characters before any launch prompt, over the ${limit.maxChars}-character Windows ${boundary} limit. Shortening the prompt cannot help; reduce the launch configuration instead.`
|
|
1075
1080
|
);
|
|
1076
1081
|
}
|
|
1082
|
+
if (options.promptIsFixedLength === true) {
|
|
1083
|
+
throw new LaunchPromptError(
|
|
1084
|
+
"launch_command_line_too_long",
|
|
1085
|
+
`The launch command line is ${total} characters, over the ${limit.maxChars}-character Windows ${boundary} limit even after moving the launch prompt into a file. Shortening the prompt cannot help; reduce the launch configuration instead.`
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1077
1088
|
const shortenByChars = total - limit.maxChars;
|
|
1078
1089
|
throw new LaunchPromptError(
|
|
1079
1090
|
"prompt_command_line_too_long",
|
|
@@ -1087,6 +1098,57 @@ function sanitizeLaunchPrompt(value) {
|
|
|
1087
1098
|
const trimmed = normalized.trim();
|
|
1088
1099
|
return trimmed.length === 0 ? void 0 : trimmed;
|
|
1089
1100
|
}
|
|
1101
|
+
function formatLaunchPromptFileInstruction(filePath) {
|
|
1102
|
+
return `${LAUNCH_PROMPT_FILE_INSTRUCTION_PREFIX}${filePath}`;
|
|
1103
|
+
}
|
|
1104
|
+
function writeLaunchPromptPointer(body, onCleanup, cmdWrapped) {
|
|
1105
|
+
const written = writeLaunchPromptFile(body, onCleanup);
|
|
1106
|
+
try {
|
|
1107
|
+
assertLaunchPromptShimSafe(written.instruction, cmdWrapped ? ["cmd-shim"] : []);
|
|
1108
|
+
} catch (error51) {
|
|
1109
|
+
written.cleanup();
|
|
1110
|
+
if (error51 instanceof LaunchPromptError && error51.code === "prompt_unsafe_for_shim") {
|
|
1111
|
+
throw new LaunchPromptError(
|
|
1112
|
+
"prompt_unsafe_for_shim",
|
|
1113
|
+
'The launch prompt file path contains a character cmd.exe would reinterpret (" & < > ( ) @ ^ | %) while running the Windows shim. Fleet cannot start this launch from the current Windows temp directory.'
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
throw error51;
|
|
1117
|
+
}
|
|
1118
|
+
return written.instruction;
|
|
1119
|
+
}
|
|
1120
|
+
function writeLaunchPromptFile(body, onCleanup) {
|
|
1121
|
+
const tempRoot = path19__default.resolve(os3__default.tmpdir());
|
|
1122
|
+
mkdirSync(tempRoot, { recursive: true });
|
|
1123
|
+
const tempDir = mkdtempSync(path19__default.join(tempRoot, LAUNCH_PROMPT_TEMP_DIR_PREFIX));
|
|
1124
|
+
const cleanup = () => rmBestEffort(tempDir);
|
|
1125
|
+
try {
|
|
1126
|
+
const filePath = path19__default.join(tempDir, LAUNCH_PROMPT_FILE_NAME);
|
|
1127
|
+
writeFileSync(filePath, body, { encoding: "utf8", flag: "wx", mode: LAUNCH_PROMPT_FILE_MODE });
|
|
1128
|
+
chmodBestEffort(filePath, LAUNCH_PROMPT_FILE_MODE);
|
|
1129
|
+
onCleanup(cleanup);
|
|
1130
|
+
return {
|
|
1131
|
+
cleanup,
|
|
1132
|
+
filePath,
|
|
1133
|
+
instruction: formatLaunchPromptFileInstruction(filePath)
|
|
1134
|
+
};
|
|
1135
|
+
} catch (error51) {
|
|
1136
|
+
cleanup();
|
|
1137
|
+
throw error51;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
function chmodBestEffort(targetPath, mode) {
|
|
1141
|
+
try {
|
|
1142
|
+
chmodSync(targetPath, mode);
|
|
1143
|
+
} catch {
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function rmBestEffort(targetPath) {
|
|
1147
|
+
try {
|
|
1148
|
+
rmSync(targetPath, { force: true, recursive: true });
|
|
1149
|
+
} catch {
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1090
1152
|
|
|
1091
1153
|
// ../../node_modules/.pnpm/zod@4.4.1/node_modules/zod/v4/classic/external.js
|
|
1092
1154
|
var external_exports = {};
|
|
@@ -1850,10 +1912,10 @@ function mergeDefs(...defs) {
|
|
|
1850
1912
|
function cloneDef(schema) {
|
|
1851
1913
|
return mergeDefs(schema._zod.def);
|
|
1852
1914
|
}
|
|
1853
|
-
function getElementAtPath(obj,
|
|
1854
|
-
if (!
|
|
1915
|
+
function getElementAtPath(obj, path43) {
|
|
1916
|
+
if (!path43)
|
|
1855
1917
|
return obj;
|
|
1856
|
-
return
|
|
1918
|
+
return path43.reduce((acc, key) => acc?.[key], obj);
|
|
1857
1919
|
}
|
|
1858
1920
|
function promiseAllObject(promisesObj) {
|
|
1859
1921
|
const keys = Object.keys(promisesObj);
|
|
@@ -2262,11 +2324,11 @@ function explicitlyAborted(x, startIndex = 0) {
|
|
|
2262
2324
|
}
|
|
2263
2325
|
return false;
|
|
2264
2326
|
}
|
|
2265
|
-
function prefixIssues(
|
|
2327
|
+
function prefixIssues(path43, issues) {
|
|
2266
2328
|
return issues.map((iss) => {
|
|
2267
2329
|
var _a3;
|
|
2268
2330
|
(_a3 = iss).path ?? (_a3.path = []);
|
|
2269
|
-
iss.path.unshift(
|
|
2331
|
+
iss.path.unshift(path43);
|
|
2270
2332
|
return iss;
|
|
2271
2333
|
});
|
|
2272
2334
|
}
|
|
@@ -2413,16 +2475,16 @@ function flattenError(error51, mapper = (issue3) => issue3.message) {
|
|
|
2413
2475
|
}
|
|
2414
2476
|
function formatError(error51, mapper = (issue3) => issue3.message) {
|
|
2415
2477
|
const fieldErrors = { _errors: [] };
|
|
2416
|
-
const processError = (error52,
|
|
2478
|
+
const processError = (error52, path43 = []) => {
|
|
2417
2479
|
for (const issue3 of error52.issues) {
|
|
2418
2480
|
if (issue3.code === "invalid_union" && issue3.errors.length) {
|
|
2419
|
-
issue3.errors.map((issues) => processError({ issues }, [...
|
|
2481
|
+
issue3.errors.map((issues) => processError({ issues }, [...path43, ...issue3.path]));
|
|
2420
2482
|
} else if (issue3.code === "invalid_key") {
|
|
2421
|
-
processError({ issues: issue3.issues }, [...
|
|
2483
|
+
processError({ issues: issue3.issues }, [...path43, ...issue3.path]);
|
|
2422
2484
|
} else if (issue3.code === "invalid_element") {
|
|
2423
|
-
processError({ issues: issue3.issues }, [...
|
|
2485
|
+
processError({ issues: issue3.issues }, [...path43, ...issue3.path]);
|
|
2424
2486
|
} else {
|
|
2425
|
-
const fullpath = [...
|
|
2487
|
+
const fullpath = [...path43, ...issue3.path];
|
|
2426
2488
|
if (fullpath.length === 0) {
|
|
2427
2489
|
fieldErrors._errors.push(mapper(issue3));
|
|
2428
2490
|
} else {
|
|
@@ -2449,17 +2511,17 @@ function formatError(error51, mapper = (issue3) => issue3.message) {
|
|
|
2449
2511
|
}
|
|
2450
2512
|
function treeifyError(error51, mapper = (issue3) => issue3.message) {
|
|
2451
2513
|
const result = { errors: [] };
|
|
2452
|
-
const processError = (error52,
|
|
2514
|
+
const processError = (error52, path43 = []) => {
|
|
2453
2515
|
var _a3, _b;
|
|
2454
2516
|
for (const issue3 of error52.issues) {
|
|
2455
2517
|
if (issue3.code === "invalid_union" && issue3.errors.length) {
|
|
2456
|
-
issue3.errors.map((issues) => processError({ issues }, [...
|
|
2518
|
+
issue3.errors.map((issues) => processError({ issues }, [...path43, ...issue3.path]));
|
|
2457
2519
|
} else if (issue3.code === "invalid_key") {
|
|
2458
|
-
processError({ issues: issue3.issues }, [...
|
|
2520
|
+
processError({ issues: issue3.issues }, [...path43, ...issue3.path]);
|
|
2459
2521
|
} else if (issue3.code === "invalid_element") {
|
|
2460
|
-
processError({ issues: issue3.issues }, [...
|
|
2522
|
+
processError({ issues: issue3.issues }, [...path43, ...issue3.path]);
|
|
2461
2523
|
} else {
|
|
2462
|
-
const fullpath = [...
|
|
2524
|
+
const fullpath = [...path43, ...issue3.path];
|
|
2463
2525
|
if (fullpath.length === 0) {
|
|
2464
2526
|
result.errors.push(mapper(issue3));
|
|
2465
2527
|
continue;
|
|
@@ -2491,8 +2553,8 @@ function treeifyError(error51, mapper = (issue3) => issue3.message) {
|
|
|
2491
2553
|
}
|
|
2492
2554
|
function toDotPath(_path) {
|
|
2493
2555
|
const segs = [];
|
|
2494
|
-
const
|
|
2495
|
-
for (const seg of
|
|
2556
|
+
const path43 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
|
|
2557
|
+
for (const seg of path43) {
|
|
2496
2558
|
if (typeof seg === "number")
|
|
2497
2559
|
segs.push(`[${seg}]`);
|
|
2498
2560
|
else if (typeof seg === "symbol")
|
|
@@ -15156,13 +15218,13 @@ function resolveRef(ref, ctx) {
|
|
|
15156
15218
|
if (!ref.startsWith("#")) {
|
|
15157
15219
|
throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
|
|
15158
15220
|
}
|
|
15159
|
-
const
|
|
15160
|
-
if (
|
|
15221
|
+
const path43 = ref.slice(1).split("/").filter(Boolean);
|
|
15222
|
+
if (path43.length === 0) {
|
|
15161
15223
|
return ctx.rootSchema;
|
|
15162
15224
|
}
|
|
15163
15225
|
const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
|
|
15164
|
-
if (
|
|
15165
|
-
const key =
|
|
15226
|
+
if (path43[0] === defsKey) {
|
|
15227
|
+
const key = path43[1];
|
|
15166
15228
|
if (!key || !ctx.defs[key]) {
|
|
15167
15229
|
throw new Error(`Reference not found: ${ref}`);
|
|
15168
15230
|
}
|
|
@@ -18564,8 +18626,8 @@ function bootEnumDescriptorProto(init) {
|
|
|
18564
18626
|
}
|
|
18565
18627
|
|
|
18566
18628
|
// ../../node_modules/.pnpm/@bufbuild+protobuf@2.13.0/node_modules/@bufbuild/protobuf/dist/esm/codegenv2/message.js
|
|
18567
|
-
function messageDesc(file2,
|
|
18568
|
-
return paths.reduce((acc, cur) => acc.nestedMessages[cur], file2.messages[
|
|
18629
|
+
function messageDesc(file2, path43, ...paths) {
|
|
18630
|
+
return paths.reduce((acc, cur) => acc.nestedMessages[cur], file2.messages[path43]);
|
|
18569
18631
|
}
|
|
18570
18632
|
|
|
18571
18633
|
// ../../node_modules/.pnpm/@bufbuild+protobuf@2.13.0/node_modules/@bufbuild/protobuf/dist/esm/wkt/gen/google/protobuf/descriptor_pb.js
|
|
@@ -19963,11 +20025,11 @@ function fieldMaskFromJson(fieldMask, json2) {
|
|
|
19963
20025
|
if (json2 === "") {
|
|
19964
20026
|
return;
|
|
19965
20027
|
}
|
|
19966
|
-
fieldMask.paths = json2.split(",").map((
|
|
19967
|
-
if (
|
|
20028
|
+
fieldMask.paths = json2.split(",").map((path43) => {
|
|
20029
|
+
if (path43.includes("_")) {
|
|
19968
20030
|
throw new Error(`cannot decode message ${fieldMask.$typeName} from JSON: path names must be lowerCamelCase`);
|
|
19969
20031
|
}
|
|
19970
|
-
return protoSnakeCase(
|
|
20032
|
+
return protoSnakeCase(path43);
|
|
19971
20033
|
});
|
|
19972
20034
|
}
|
|
19973
20035
|
function structFromJson(struct, json2, ctx) {
|
|
@@ -20329,17 +20391,17 @@ function projectAnthropicUsageEnvelope(value, contextWindow, responseModel) {
|
|
|
20329
20391
|
return { changed, value: projectedValue };
|
|
20330
20392
|
}
|
|
20331
20393
|
function projectUsageProperty(container, property, contextWindow) {
|
|
20332
|
-
const
|
|
20333
|
-
if (!isRecord2(
|
|
20394
|
+
const usage4 = container[property];
|
|
20395
|
+
if (!isRecord2(usage4)) return { changed: false, value: container };
|
|
20334
20396
|
const coordinates = ANTHROPIC_INPUT_USAGE_FIELDS.map((field) => {
|
|
20335
|
-
const tokens =
|
|
20397
|
+
const tokens = usage4[field];
|
|
20336
20398
|
return typeof tokens === "number" && Number.isFinite(tokens) && tokens >= 0 ? { field, tokens } : void 0;
|
|
20337
20399
|
}).filter((entry) => entry !== void 0);
|
|
20338
20400
|
if (coordinates.length === 0) return { changed: false, value: container };
|
|
20339
20401
|
const total = coordinates.reduce((sum, entry) => sum + entry.tokens, 0);
|
|
20340
20402
|
const projectedTotal = projectClaudeContextInputTokens(total, contextWindow);
|
|
20341
20403
|
if (projectedTotal === total) return { changed: false, value: container };
|
|
20342
|
-
const projectedUsage = { ...
|
|
20404
|
+
const projectedUsage = { ...usage4 };
|
|
20343
20405
|
const remainderField = coordinates.some((entry) => entry.field === "input_tokens") ? "input_tokens" : coordinates[0].field;
|
|
20344
20406
|
let assigned = 0;
|
|
20345
20407
|
for (const entry of coordinates) {
|
|
@@ -20486,13 +20548,46 @@ function removeClaudeSkillListingEntries(text2, withheld, delisted) {
|
|
|
20486
20548
|
function withheldClaudeSkillStub(name, tokens, budget) {
|
|
20487
20549
|
return `[Fleet AI gateway withheld the "${name}" skill: its body is about ${tokens} tokens, over the ${budget}-token ceiling one skill may take from this model's context window. Read the skill's own files if you need it, or run this work on a model with a larger window.]`;
|
|
20488
20550
|
}
|
|
20551
|
+
var CLAUDE_WEB_SEARCH_TOOL_NAME = "WebSearch";
|
|
20552
|
+
var ANTHROPIC_WEB_SEARCH_TOOL_NAME = "web_search";
|
|
20553
|
+
var ANTHROPIC_WEB_SEARCH_TOOL_TYPE = "web_search_20250305";
|
|
20554
|
+
function isClaudeWebSearchTool(tool) {
|
|
20555
|
+
return tool.type === ANTHROPIC_WEB_SEARCH_TOOL_TYPE || tool.name === CLAUDE_WEB_SEARCH_TOOL_NAME || tool.name === ANTHROPIC_WEB_SEARCH_TOOL_NAME;
|
|
20556
|
+
}
|
|
20557
|
+
function isClaudeWebSearchToolChoice(choice) {
|
|
20558
|
+
return choice?.type === "tool" && (choice.name === CLAUDE_WEB_SEARCH_TOOL_NAME || choice.name === ANTHROPIC_WEB_SEARCH_TOOL_NAME);
|
|
20559
|
+
}
|
|
20560
|
+
function omitClaudeWebSearchTools(request) {
|
|
20561
|
+
const tools = request.tools;
|
|
20562
|
+
const kept = tools?.filter((tool) => !isClaudeWebSearchTool(tool));
|
|
20563
|
+
const toolsChanged = tools !== void 0 && kept !== void 0 && kept.length !== tools.length;
|
|
20564
|
+
const choice = request.tool_choice;
|
|
20565
|
+
const choiceChanged = isClaudeWebSearchToolChoice(choice);
|
|
20566
|
+
if (!toolsChanged && !choiceChanged) {
|
|
20567
|
+
return { request, changed: false };
|
|
20568
|
+
}
|
|
20569
|
+
const { tools: _tools, tool_choice: _toolChoice, ...rest } = request;
|
|
20570
|
+
return {
|
|
20571
|
+
request: {
|
|
20572
|
+
...rest,
|
|
20573
|
+
...toolsChanged ? kept.length === 0 ? {} : { tools: kept } : tools === void 0 ? {} : { tools },
|
|
20574
|
+
...choiceChanged ? {
|
|
20575
|
+
tool_choice: {
|
|
20576
|
+
type: "auto",
|
|
20577
|
+
...choice?.disable_parallel_tool_use === void 0 ? {} : { disable_parallel_tool_use: choice.disable_parallel_tool_use }
|
|
20578
|
+
}
|
|
20579
|
+
} : choice === void 0 ? {} : { tool_choice: choice }
|
|
20580
|
+
},
|
|
20581
|
+
changed: true
|
|
20582
|
+
};
|
|
20583
|
+
}
|
|
20489
20584
|
var benchmarks_default = {
|
|
20490
20585
|
version: 2,
|
|
20491
20586
|
sources: {
|
|
20492
20587
|
cursorbench: {
|
|
20493
20588
|
name: "CursorBench",
|
|
20494
20589
|
benchVersion: "3.2",
|
|
20495
|
-
observedAt: "2026-
|
|
20590
|
+
observedAt: "2026-08-13T00:00:00Z",
|
|
20496
20591
|
url: "https://cursor.com/cursorbench",
|
|
20497
20592
|
method: "Third-party agentic-coding benchmark: ambiguous multi-file tasks from real Cursor sessions, run in Cursor's own harness. Scores are evidence about the vendor model and transfer across gateway providers serving it; token and step figures are harness-relative efficiency signals, not billing facts.",
|
|
20498
20593
|
routingTieBandPoints: 2
|
|
@@ -20610,6 +20705,31 @@ var benchmarks_default = {
|
|
|
20610
20705
|
},
|
|
20611
20706
|
caveat: "Bench footnote: an earlier snapshot of Cursor's codebase was unintentionally present in this model's training data, inflating scores by an unknown amount; the advantage does not transfer to other repositories."
|
|
20612
20707
|
},
|
|
20708
|
+
"grok-4.6": {
|
|
20709
|
+
source: "cursorbench",
|
|
20710
|
+
rungs: {
|
|
20711
|
+
low: {
|
|
20712
|
+
score: 61,
|
|
20713
|
+
tokensPerTask: 10658,
|
|
20714
|
+
stepsPerTask: 23
|
|
20715
|
+
},
|
|
20716
|
+
medium: {
|
|
20717
|
+
score: 67.1,
|
|
20718
|
+
tokensPerTask: 17942,
|
|
20719
|
+
stepsPerTask: 29
|
|
20720
|
+
},
|
|
20721
|
+
high: {
|
|
20722
|
+
score: 69.9,
|
|
20723
|
+
tokensPerTask: 32449,
|
|
20724
|
+
stepsPerTask: 39
|
|
20725
|
+
},
|
|
20726
|
+
xhigh: {
|
|
20727
|
+
score: 70.8,
|
|
20728
|
+
tokensPerTask: 41136,
|
|
20729
|
+
stepsPerTask: 46
|
|
20730
|
+
}
|
|
20731
|
+
}
|
|
20732
|
+
},
|
|
20613
20733
|
"kimi-k3": {
|
|
20614
20734
|
source: "cursorbench",
|
|
20615
20735
|
rungs: {
|
|
@@ -20658,7 +20778,7 @@ var benchmarks_default = {
|
|
|
20658
20778
|
};
|
|
20659
20779
|
var models_default = {
|
|
20660
20780
|
version: 1,
|
|
20661
|
-
updatedAt: "2026-08-
|
|
20781
|
+
updatedAt: "2026-08-14T00:00:00Z",
|
|
20662
20782
|
providers: {
|
|
20663
20783
|
codex: {
|
|
20664
20784
|
name: "Codex",
|
|
@@ -20800,7 +20920,7 @@ var models_default = {
|
|
|
20800
20920
|
cursor: {
|
|
20801
20921
|
name: "Cursor",
|
|
20802
20922
|
defaultModel: "auto",
|
|
20803
|
-
source: "Cursor GetUsableModels + Run conversationCheckpointUpdate.token_details.max_tokens (cli-2026.07.08-0c04a8a; auto, composer-2.5, and grok-4.5 families observed 2026-08-01); quotaScope from DashboardService/GetCurrentPeriodUsage autoBucketModels (2026-08-05)",
|
|
20923
|
+
source: "Cursor GetUsableModels + Run conversationCheckpointUpdate.token_details.max_tokens (cli-2026.07.08-0c04a8a; auto, composer-2.5, and grok-4.5 families observed 2026-08-01); cursor-agent 2026.08.11-e8db854 observed 2026-08-13 for grok-4.6; quotaScope from DashboardService/GetCurrentPeriodUsage autoBucketModels (2026-08-05)",
|
|
20804
20924
|
models: [
|
|
20805
20925
|
{
|
|
20806
20926
|
modelId: "auto",
|
|
@@ -20859,6 +20979,41 @@ var models_default = {
|
|
|
20859
20979
|
],
|
|
20860
20980
|
upstreamModelIdTemplate: "cursor-grok-4.5-{effort}-fast"
|
|
20861
20981
|
}
|
|
20982
|
+
},
|
|
20983
|
+
{
|
|
20984
|
+
modelId: "grok-4.6",
|
|
20985
|
+
name: "Grok-4.6",
|
|
20986
|
+
capabilityClass: "flagship",
|
|
20987
|
+
quotaScope: "auto",
|
|
20988
|
+
contextWindow: 256e3,
|
|
20989
|
+
effort: {
|
|
20990
|
+
supported: true,
|
|
20991
|
+
levels: [
|
|
20992
|
+
"low",
|
|
20993
|
+
"medium",
|
|
20994
|
+
"high",
|
|
20995
|
+
"xhigh"
|
|
20996
|
+
],
|
|
20997
|
+
upstreamModelIdTemplate: "cursor-grok-4.6-{effort}"
|
|
20998
|
+
},
|
|
20999
|
+
benchmarkKey: "grok-4.6"
|
|
21000
|
+
},
|
|
21001
|
+
{
|
|
21002
|
+
modelId: "grok-4.6-fast",
|
|
21003
|
+
name: "Grok-4.6-Fast",
|
|
21004
|
+
capabilityClass: "light",
|
|
21005
|
+
quotaScope: "auto",
|
|
21006
|
+
contextWindow: 256e3,
|
|
21007
|
+
effort: {
|
|
21008
|
+
supported: true,
|
|
21009
|
+
levels: [
|
|
21010
|
+
"low",
|
|
21011
|
+
"medium",
|
|
21012
|
+
"high",
|
|
21013
|
+
"xhigh"
|
|
21014
|
+
],
|
|
21015
|
+
upstreamModelIdTemplate: "cursor-grok-4.6-{effort}-fast"
|
|
21016
|
+
}
|
|
20862
21017
|
}
|
|
20863
21018
|
]
|
|
20864
21019
|
},
|
|
@@ -21008,13 +21163,37 @@ var models_default = {
|
|
|
21008
21163
|
contextWindow: 256e3
|
|
21009
21164
|
}
|
|
21010
21165
|
]
|
|
21166
|
+
},
|
|
21167
|
+
xai: {
|
|
21168
|
+
name: "xAI",
|
|
21169
|
+
defaultModel: "grok-4.6",
|
|
21170
|
+
source: "official Grok CLI 1.0.3 ~/.grok/models_cache.json from GET https://cli-chat-proxy.grok.com/v1/models (observed 2026-08-13)",
|
|
21171
|
+
models: [
|
|
21172
|
+
{
|
|
21173
|
+
modelId: "grok-4.6",
|
|
21174
|
+
name: "Grok-4.6",
|
|
21175
|
+
capabilityClass: "flagship",
|
|
21176
|
+
wire: "responses",
|
|
21177
|
+
contextWindow: 5e5,
|
|
21178
|
+
effort: {
|
|
21179
|
+
supported: true,
|
|
21180
|
+
levels: [
|
|
21181
|
+
"low",
|
|
21182
|
+
"medium",
|
|
21183
|
+
"high",
|
|
21184
|
+
"xhigh"
|
|
21185
|
+
]
|
|
21186
|
+
},
|
|
21187
|
+
benchmarkKey: "grok-4.6"
|
|
21188
|
+
}
|
|
21189
|
+
]
|
|
21011
21190
|
}
|
|
21012
21191
|
}
|
|
21013
21192
|
};
|
|
21014
21193
|
var KIMI_AUTH_PROVIDER_ID = "Claude Code with Moonshot Kimi";
|
|
21015
21194
|
var KIMI_CODE_API_BASE_URL = "https://api.kimi.com/coding";
|
|
21016
21195
|
var KIMI_CODE_MODEL = "k3";
|
|
21017
|
-
var GATEWAY_PROVIDERS = ["codex", "
|
|
21196
|
+
var GATEWAY_PROVIDERS = ["codex", "xai", "cursor", "opencode", "kimi"];
|
|
21018
21197
|
var GATEWAY_MODEL_WIRES = ["anthropic", "responses", "chat-completions"];
|
|
21019
21198
|
var GATEWAY_REASONING_EFFORTS = [
|
|
21020
21199
|
"low",
|
|
@@ -21102,7 +21281,8 @@ var GatewayModelsRegistrySchema = external_exports.object({
|
|
|
21102
21281
|
codex: GatewayProviderSchema,
|
|
21103
21282
|
cursor: GatewayProviderSchema,
|
|
21104
21283
|
kimi: GatewayProviderSchema,
|
|
21105
|
-
opencode: GatewayProviderSchema
|
|
21284
|
+
opencode: GatewayProviderSchema,
|
|
21285
|
+
xai: GatewayProviderSchema
|
|
21106
21286
|
}).strict()
|
|
21107
21287
|
}).strict();
|
|
21108
21288
|
var UNSUPPORTED_GATEWAY_MODEL_EFFORT = Object.freeze({ supported: false });
|
|
@@ -21367,8 +21547,8 @@ function validateRegistry(value) {
|
|
|
21367
21547
|
if (model.quotaScope && provider !== "cursor") {
|
|
21368
21548
|
throw new Error(`Gateway quota scope is only supported by Cursor: ${provider}/${model.modelId}`);
|
|
21369
21549
|
}
|
|
21370
|
-
if (model.wire && provider !== "opencode") {
|
|
21371
|
-
throw new Error(`Gateway model wire is
|
|
21550
|
+
if (model.wire && provider !== "opencode" && provider !== "xai") {
|
|
21551
|
+
throw new Error(`Gateway model wire is not supported by provider: ${provider}/${model.modelId}`);
|
|
21372
21552
|
}
|
|
21373
21553
|
if (model.effort?.supported) {
|
|
21374
21554
|
if (new Set(model.effort.levels).size !== model.effort.levels.length) {
|
|
@@ -21823,14 +22003,14 @@ function nonNegativeCacheValue(value) {
|
|
|
21823
22003
|
}
|
|
21824
22004
|
return value;
|
|
21825
22005
|
}
|
|
21826
|
-
function anthropicUsageFromCanonical(
|
|
22006
|
+
function anthropicUsageFromCanonical(usage4, advertisedContextWindow, options = {}) {
|
|
21827
22007
|
return toAnthropicCacheAwareUsage(
|
|
21828
|
-
|
|
21829
|
-
|
|
21830
|
-
|
|
21831
|
-
options.forceOutputZero ? 0 :
|
|
22008
|
+
usage4?.input_tokens ?? 0,
|
|
22009
|
+
usage4?.cached_input_tokens,
|
|
22010
|
+
usage4?.cache_write_input_tokens,
|
|
22011
|
+
options.forceOutputZero ? 0 : usage4?.output_tokens ?? 0,
|
|
21832
22012
|
advertisedContextWindow,
|
|
21833
|
-
|
|
22013
|
+
usage4?.context_window
|
|
21834
22014
|
);
|
|
21835
22015
|
}
|
|
21836
22016
|
async function collectAnthropicMessage(events, fallbackModel, options = {}) {
|
|
@@ -23671,7 +23851,7 @@ var execFileAsync = promisify(execFile);
|
|
|
23671
23851
|
var MAX_CREDENTIAL_BYTES = 65536;
|
|
23672
23852
|
var CREDENTIAL_OPEN_FLAGS = process.platform === "win32" ? constants.O_RDONLY : constants.O_RDONLY | constants.O_NONBLOCK;
|
|
23673
23853
|
async function readBoundedFile(filePath, maxBytes) {
|
|
23674
|
-
const handle = await
|
|
23854
|
+
const handle = await fs32.open(filePath, CREDENTIAL_OPEN_FLAGS);
|
|
23675
23855
|
try {
|
|
23676
23856
|
const stat22 = await handle.stat();
|
|
23677
23857
|
if (!stat22.isFile() || stat22.size > maxBytes) return null;
|
|
@@ -23714,7 +23894,7 @@ function optionalNonEmptyString(value) {
|
|
|
23714
23894
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
23715
23895
|
}
|
|
23716
23896
|
function codexAuthFilePath(deps) {
|
|
23717
|
-
return
|
|
23897
|
+
return path19__default.join(deps.env.CODEX_HOME || path19__default.join(deps.homedir(), ".codex"), "auth.json");
|
|
23718
23898
|
}
|
|
23719
23899
|
async function resolveCodexCredentials(deps) {
|
|
23720
23900
|
try {
|
|
@@ -23753,12 +23933,12 @@ function parseCursorCredentialJson(raw, method) {
|
|
|
23753
23933
|
function cursorAuthFilePath(deps) {
|
|
23754
23934
|
const home = deps.homedir();
|
|
23755
23935
|
if (deps.platform === "win32") {
|
|
23756
|
-
return
|
|
23936
|
+
return path19__default.join(deps.env.APPDATA || path19__default.join(home, "AppData", "Roaming"), "Cursor", "auth.json");
|
|
23757
23937
|
}
|
|
23758
23938
|
if (deps.platform === "darwin") {
|
|
23759
|
-
return
|
|
23939
|
+
return path19__default.join(home, ".cursor", "auth.json");
|
|
23760
23940
|
}
|
|
23761
|
-
return
|
|
23941
|
+
return path19__default.join(deps.env.XDG_CONFIG_HOME || path19__default.join(home, ".config"), "cursor", "auth.json");
|
|
23762
23942
|
}
|
|
23763
23943
|
async function resolveCursorCredentials(deps) {
|
|
23764
23944
|
if (deps.platform === "darwin") {
|
|
@@ -24080,7 +24260,7 @@ async function* translateChatCompletionsStream(body, options, toolSchemas) {
|
|
|
24080
24260
|
let createdEmitted = false;
|
|
24081
24261
|
let textSeen = false;
|
|
24082
24262
|
let accumulatedText = "";
|
|
24083
|
-
let
|
|
24263
|
+
let usage4 = null;
|
|
24084
24264
|
let failed = false;
|
|
24085
24265
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
24086
24266
|
const MESSAGE_ITEM_ID = "chat_message_0";
|
|
@@ -24111,7 +24291,7 @@ async function* translateChatCompletionsStream(body, options, toolSchemas) {
|
|
|
24111
24291
|
};
|
|
24112
24292
|
}
|
|
24113
24293
|
if (isRecord5(value.usage)) {
|
|
24114
|
-
|
|
24294
|
+
usage4 = chatUsage(value.usage);
|
|
24115
24295
|
}
|
|
24116
24296
|
const choices = Array.isArray(value.choices) ? value.choices : [];
|
|
24117
24297
|
for (const choice of choices) {
|
|
@@ -24204,7 +24384,7 @@ async function* translateChatCompletionsStream(body, options, toolSchemas) {
|
|
|
24204
24384
|
model: responseModel ?? "",
|
|
24205
24385
|
// 하류 message_delta는 usage가 필수다. include_usage에도 usage 청크를 주지
|
|
24206
24386
|
// 않는 백엔드에서는 0-usage로 완결하고, 실제 회계는 provider 콘솔이 맡는다.
|
|
24207
|
-
usage:
|
|
24387
|
+
usage: usage4 ?? { input_tokens: 0, output_tokens: 0 }
|
|
24208
24388
|
}
|
|
24209
24389
|
};
|
|
24210
24390
|
}
|
|
@@ -24865,6 +25045,610 @@ function createOpencodeGoAdapter(wire, options = {}) {
|
|
|
24865
25045
|
...options.fetch ? { fetch: options.fetch } : {}
|
|
24866
25046
|
});
|
|
24867
25047
|
}
|
|
25048
|
+
var XAI_OIDC_ISSUER = "https://auth.x.ai";
|
|
25049
|
+
var XAI_CLI_REFRESH_URL = "https://auth.x.ai/oauth2/token";
|
|
25050
|
+
var XAI_CLI_DEFAULT_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
|
|
25051
|
+
var XAI_CLI_REFRESH_BUFFER_MS = 5 * 60 * 1e3;
|
|
25052
|
+
var REFRESH_TIMEOUT_MS = 15e3;
|
|
25053
|
+
var FALLBACK_ACCESS_TOKEN_TTL_MS = 36e5;
|
|
25054
|
+
function xaiCliAuthFilePath(deps) {
|
|
25055
|
+
return path19__default.join(deps.env.GROK_HOME || path19__default.join(deps.homedir(), ".grok"), "auth.json");
|
|
25056
|
+
}
|
|
25057
|
+
function expiry(value) {
|
|
25058
|
+
if (typeof value !== "string" && typeof value !== "number") return void 0;
|
|
25059
|
+
const parsed = typeof value === "number" ? value : Date.parse(value);
|
|
25060
|
+
if (!Number.isFinite(parsed)) return void 0;
|
|
25061
|
+
return parsed < 1e12 ? Math.round(parsed * 1e3) : Math.round(parsed);
|
|
25062
|
+
}
|
|
25063
|
+
function jwtExpiry(token) {
|
|
25064
|
+
const parts = token.split(".");
|
|
25065
|
+
if (parts.length < 2) return void 0;
|
|
25066
|
+
try {
|
|
25067
|
+
const payload = JSON.parse(Buffer.from(parts[1] ?? "", "base64url").toString("utf8"));
|
|
25068
|
+
const record42 = credentialRecord(payload);
|
|
25069
|
+
const exp = record42?.exp;
|
|
25070
|
+
if (typeof exp !== "number" || !Number.isFinite(exp)) return void 0;
|
|
25071
|
+
return Math.round(exp * 1e3);
|
|
25072
|
+
} catch {
|
|
25073
|
+
return void 0;
|
|
25074
|
+
}
|
|
25075
|
+
}
|
|
25076
|
+
function effectiveExpiry(entry, accessToken) {
|
|
25077
|
+
const fromEntry = expiry(entry.expires_at) ?? expiry(entry.expires);
|
|
25078
|
+
const fromJwt = jwtExpiry(accessToken);
|
|
25079
|
+
if (fromEntry !== void 0 && fromJwt !== void 0) return Math.min(fromEntry, fromJwt);
|
|
25080
|
+
return fromEntry ?? fromJwt;
|
|
25081
|
+
}
|
|
25082
|
+
function clientId(entryKey, entry) {
|
|
25083
|
+
const fromEntry = optionalTrimmedString(entry.oidc_client_id);
|
|
25084
|
+
if (fromEntry) return fromEntry;
|
|
25085
|
+
const suffix = optionalTrimmedString(entryKey.split("::").at(-1));
|
|
25086
|
+
return suffix ?? XAI_CLI_DEFAULT_CLIENT_ID;
|
|
25087
|
+
}
|
|
25088
|
+
function refreshToken(entry) {
|
|
25089
|
+
return optionalTrimmedString(entry.refresh_token) ?? optionalTrimmedString(entry.refresh);
|
|
25090
|
+
}
|
|
25091
|
+
async function defaultWriteAuthFile(filePath, contents) {
|
|
25092
|
+
const tmpPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;
|
|
25093
|
+
try {
|
|
25094
|
+
await fs32.writeFile(tmpPath, contents, { encoding: "utf8", mode: 384 });
|
|
25095
|
+
await fs32.rename(tmpPath, filePath);
|
|
25096
|
+
} catch (error51) {
|
|
25097
|
+
await fs32.unlink(tmpPath).catch(() => void 0);
|
|
25098
|
+
throw error51;
|
|
25099
|
+
}
|
|
25100
|
+
}
|
|
25101
|
+
async function persistRefreshedEntry(deps, filePath, entryKey, expected, patch, writeAuthFile) {
|
|
25102
|
+
const raw = await deps.readBounded(filePath, MAX_CREDENTIAL_BYTES);
|
|
25103
|
+
if (raw === null) return;
|
|
25104
|
+
const auth = credentialRecord(JSON.parse(raw));
|
|
25105
|
+
if (!auth) return;
|
|
25106
|
+
const current = credentialRecord(auth[entryKey]);
|
|
25107
|
+
if (!current) return;
|
|
25108
|
+
if (optionalTrimmedString(current.key) !== expected.accessToken) return;
|
|
25109
|
+
if (expected.refreshToken !== void 0 && refreshToken(current) !== expected.refreshToken) return;
|
|
25110
|
+
auth[entryKey] = { ...current, ...patch };
|
|
25111
|
+
await writeAuthFile(filePath, `${JSON.stringify(auth, null, 2)}
|
|
25112
|
+
`);
|
|
25113
|
+
}
|
|
25114
|
+
async function refreshAccessToken(entryKey, entry, fetchImpl, now) {
|
|
25115
|
+
const token = refreshToken(entry);
|
|
25116
|
+
if (!token) return null;
|
|
25117
|
+
const controller = new AbortController();
|
|
25118
|
+
const timer = setTimeout(() => controller.abort(), REFRESH_TIMEOUT_MS);
|
|
25119
|
+
try {
|
|
25120
|
+
const body = new URLSearchParams({
|
|
25121
|
+
grant_type: "refresh_token",
|
|
25122
|
+
client_id: clientId(entryKey, entry),
|
|
25123
|
+
refresh_token: token
|
|
25124
|
+
});
|
|
25125
|
+
const response = await fetchImpl(XAI_CLI_REFRESH_URL, {
|
|
25126
|
+
method: "POST",
|
|
25127
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json" },
|
|
25128
|
+
body,
|
|
25129
|
+
signal: controller.signal
|
|
25130
|
+
});
|
|
25131
|
+
if (!response.ok) return null;
|
|
25132
|
+
const payload = credentialRecord(await response.json());
|
|
25133
|
+
const accessToken = optionalTrimmedString(payload?.access_token);
|
|
25134
|
+
if (!accessToken) return null;
|
|
25135
|
+
const expiresIn = payload?.expires_in;
|
|
25136
|
+
const expiresAt = typeof expiresIn === "number" && Number.isFinite(expiresIn) && expiresIn > 0 ? now() + Math.round(expiresIn * 1e3) : jwtExpiry(accessToken) ?? now() + FALLBACK_ACCESS_TOKEN_TTL_MS;
|
|
25137
|
+
const rotated = optionalTrimmedString(payload?.refresh_token);
|
|
25138
|
+
return {
|
|
25139
|
+
accessToken,
|
|
25140
|
+
expiresAt,
|
|
25141
|
+
...rotated === void 0 ? {} : { refreshToken: rotated }
|
|
25142
|
+
};
|
|
25143
|
+
} catch {
|
|
25144
|
+
return null;
|
|
25145
|
+
} finally {
|
|
25146
|
+
clearTimeout(timer);
|
|
25147
|
+
}
|
|
25148
|
+
}
|
|
25149
|
+
async function resolveXaiCliAuth(deps, options = {}) {
|
|
25150
|
+
const now = options.now ?? Date.now;
|
|
25151
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
25152
|
+
const writeAuthFile = options.writeAuthFile ?? defaultWriteAuthFile;
|
|
25153
|
+
const filePath = xaiCliAuthFilePath(deps);
|
|
25154
|
+
try {
|
|
25155
|
+
const raw = await deps.readBounded(filePath, MAX_CREDENTIAL_BYTES);
|
|
25156
|
+
if (raw === null || raw.length > MAX_CREDENTIAL_BYTES) return { status: "signed_out" };
|
|
25157
|
+
const auth = credentialRecord(JSON.parse(raw));
|
|
25158
|
+
if (!auth) return { status: "signed_out" };
|
|
25159
|
+
let sawExpired = false;
|
|
25160
|
+
for (const [entryKey, value] of Object.entries(auth)) {
|
|
25161
|
+
if (!entryKey.startsWith(`${XAI_OIDC_ISSUER}::`)) continue;
|
|
25162
|
+
const entry = credentialRecord(value);
|
|
25163
|
+
const issuer = optionalTrimmedString(entry?.oidc_issuer);
|
|
25164
|
+
const accessToken = optionalTrimmedString(entry?.key);
|
|
25165
|
+
if (!entry || issuer !== XAI_OIDC_ISSUER || !accessToken) continue;
|
|
25166
|
+
const expiresAt = effectiveExpiry(entry, accessToken);
|
|
25167
|
+
const expired2 = expiresAt !== void 0 && expiresAt <= now();
|
|
25168
|
+
const needsRefresh = options.forceRefresh === true || expiresAt !== void 0 && expiresAt - now() <= XAI_CLI_REFRESH_BUFFER_MS;
|
|
25169
|
+
if (needsRefresh) {
|
|
25170
|
+
const refreshed = await refreshAccessToken(entryKey, entry, fetchImpl, now);
|
|
25171
|
+
if (refreshed) {
|
|
25172
|
+
const userId2 = optionalTrimmedString(entry.user_id) ?? optionalTrimmedString(entry.principal_id);
|
|
25173
|
+
const patch = {
|
|
25174
|
+
key: refreshed.accessToken,
|
|
25175
|
+
expires_at: new Date(refreshed.expiresAt).toISOString()
|
|
25176
|
+
};
|
|
25177
|
+
if (refreshed.refreshToken !== void 0) patch.refresh_token = refreshed.refreshToken;
|
|
25178
|
+
try {
|
|
25179
|
+
await persistRefreshedEntry(
|
|
25180
|
+
deps,
|
|
25181
|
+
filePath,
|
|
25182
|
+
entryKey,
|
|
25183
|
+
{ accessToken, refreshToken: refreshToken(entry) },
|
|
25184
|
+
patch,
|
|
25185
|
+
writeAuthFile
|
|
25186
|
+
);
|
|
25187
|
+
} catch {
|
|
25188
|
+
}
|
|
25189
|
+
return {
|
|
25190
|
+
status: "ok",
|
|
25191
|
+
credentials: {
|
|
25192
|
+
accessToken: refreshed.accessToken,
|
|
25193
|
+
expiresAt: refreshed.expiresAt,
|
|
25194
|
+
...userId2 === void 0 ? {} : { userId: userId2 }
|
|
25195
|
+
}
|
|
25196
|
+
};
|
|
25197
|
+
}
|
|
25198
|
+
if (options.forceRefresh === true || expired2) {
|
|
25199
|
+
sawExpired = true;
|
|
25200
|
+
continue;
|
|
25201
|
+
}
|
|
25202
|
+
} else if (expired2) {
|
|
25203
|
+
sawExpired = true;
|
|
25204
|
+
continue;
|
|
25205
|
+
}
|
|
25206
|
+
const userId = optionalTrimmedString(entry.user_id) ?? optionalTrimmedString(entry.principal_id);
|
|
25207
|
+
return {
|
|
25208
|
+
status: "ok",
|
|
25209
|
+
credentials: {
|
|
25210
|
+
accessToken,
|
|
25211
|
+
...expiresAt === void 0 ? {} : { expiresAt },
|
|
25212
|
+
...userId === void 0 ? {} : { userId }
|
|
25213
|
+
}
|
|
25214
|
+
};
|
|
25215
|
+
}
|
|
25216
|
+
return { status: sawExpired ? "expired" : "signed_out" };
|
|
25217
|
+
} catch {
|
|
25218
|
+
return { status: "signed_out" };
|
|
25219
|
+
}
|
|
25220
|
+
}
|
|
25221
|
+
async function resolveXaiCliCredentials(deps, nowOrOptions = Date.now) {
|
|
25222
|
+
const options = typeof nowOrOptions === "function" ? { now: nowOrOptions } : nowOrOptions;
|
|
25223
|
+
const result = await resolveXaiCliAuth(deps, options);
|
|
25224
|
+
return result.status === "ok" ? result.credentials : null;
|
|
25225
|
+
}
|
|
25226
|
+
var XAI_CLI_RESPONSES_URL = "https://cli-chat-proxy.grok.com/v1/responses";
|
|
25227
|
+
var XAI_CLI_CLIENT_VERSION = "1.0.3";
|
|
25228
|
+
var DEFAULT_XAI_RESPONSES_MAX_UPSTREAM_BODY_BYTES = 64 * 1024 * 1024;
|
|
25229
|
+
var DEFAULT_XAI_RESPONSES_UPSTREAM_IDLE_TIMEOUT_MS = 3e4;
|
|
25230
|
+
var DEFAULT_XAI_RESPONSES_FUNCTION_CALL_TIMEOUT_MS = 3e4;
|
|
25231
|
+
var XaiResponsesAdapter = class {
|
|
25232
|
+
capabilities = {};
|
|
25233
|
+
fetchImpl;
|
|
25234
|
+
maxBodyBytes;
|
|
25235
|
+
idleTimeoutMs;
|
|
25236
|
+
functionCallTimeoutMs;
|
|
25237
|
+
url;
|
|
25238
|
+
extraHeaders;
|
|
25239
|
+
constructor(options = {}) {
|
|
25240
|
+
this.url = XAI_CLI_RESPONSES_URL;
|
|
25241
|
+
this.extraHeaders = options.headers ?? {};
|
|
25242
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
|
|
25243
|
+
this.maxBodyBytes = positiveInteger(
|
|
25244
|
+
options.maxBodyBytes ?? DEFAULT_XAI_RESPONSES_MAX_UPSTREAM_BODY_BYTES,
|
|
25245
|
+
"maxBodyBytes"
|
|
25246
|
+
);
|
|
25247
|
+
this.idleTimeoutMs = positiveInteger(
|
|
25248
|
+
options.idleTimeoutMs ?? DEFAULT_XAI_RESPONSES_UPSTREAM_IDLE_TIMEOUT_MS,
|
|
25249
|
+
"idleTimeoutMs"
|
|
25250
|
+
);
|
|
25251
|
+
this.functionCallTimeoutMs = positiveInteger(
|
|
25252
|
+
options.functionCallTimeoutMs ?? DEFAULT_XAI_RESPONSES_FUNCTION_CALL_TIMEOUT_MS,
|
|
25253
|
+
"functionCallTimeoutMs"
|
|
25254
|
+
);
|
|
25255
|
+
}
|
|
25256
|
+
async stream(request, options) {
|
|
25257
|
+
if (options.apiKey.length === 0) {
|
|
25258
|
+
throw new TypeError("apiKey must not be empty");
|
|
25259
|
+
}
|
|
25260
|
+
const controller = new AbortController();
|
|
25261
|
+
const unlinkAbort = linkAbortSignal(options.signal, controller);
|
|
25262
|
+
const payload = forXaiResponsesBackend(request);
|
|
25263
|
+
wireLog("xai-responses.wire.request", { url: this.url, payload });
|
|
25264
|
+
let response;
|
|
25265
|
+
try {
|
|
25266
|
+
response = await this.fetchImpl(this.url, {
|
|
25267
|
+
method: "POST",
|
|
25268
|
+
headers: {
|
|
25269
|
+
accept: "text/event-stream",
|
|
25270
|
+
authorization: `Bearer ${options.apiKey}`,
|
|
25271
|
+
"content-type": "application/json",
|
|
25272
|
+
"x-xai-token-auth": "xai-grok-cli",
|
|
25273
|
+
"x-grok-client-version": XAI_CLI_CLIENT_VERSION,
|
|
25274
|
+
"x-grok-model-override": request.model,
|
|
25275
|
+
...this.extraHeaders
|
|
25276
|
+
},
|
|
25277
|
+
body: JSON.stringify(payload),
|
|
25278
|
+
signal: controller.signal
|
|
25279
|
+
});
|
|
25280
|
+
} catch (error51) {
|
|
25281
|
+
unlinkAbort();
|
|
25282
|
+
throw error51;
|
|
25283
|
+
}
|
|
25284
|
+
if (!response.ok) {
|
|
25285
|
+
if (process.env.FLEET_AI_GATEWAY_DEBUG === "1") {
|
|
25286
|
+
const roles = payload.input.map((item) => "role" in item ? item.role : item.type);
|
|
25287
|
+
console.error(`[ai-gateway] upstream ${response.status} input roles=${JSON.stringify(roles)} keys=${JSON.stringify(Object.keys(payload))}`);
|
|
25288
|
+
}
|
|
25289
|
+
try {
|
|
25290
|
+
const body = await readBoundedBody(response.body, {
|
|
25291
|
+
controller,
|
|
25292
|
+
idleTimeoutMs: this.idleTimeoutMs,
|
|
25293
|
+
maxBodyBytes: this.maxBodyBytes
|
|
25294
|
+
});
|
|
25295
|
+
return {
|
|
25296
|
+
ok: false,
|
|
25297
|
+
status: response.status,
|
|
25298
|
+
headers: response.headers,
|
|
25299
|
+
body
|
|
25300
|
+
};
|
|
25301
|
+
} finally {
|
|
25302
|
+
unlinkAbort();
|
|
25303
|
+
}
|
|
25304
|
+
}
|
|
25305
|
+
return {
|
|
25306
|
+
ok: true,
|
|
25307
|
+
status: response.status,
|
|
25308
|
+
headers: response.headers,
|
|
25309
|
+
events: parseXaiEventStream(response.body, {
|
|
25310
|
+
controller,
|
|
25311
|
+
idleTimeoutMs: this.idleTimeoutMs,
|
|
25312
|
+
maxBodyBytes: this.maxBodyBytes,
|
|
25313
|
+
onClose: unlinkAbort
|
|
25314
|
+
}, this.functionCallTimeoutMs)
|
|
25315
|
+
};
|
|
25316
|
+
}
|
|
25317
|
+
};
|
|
25318
|
+
function forXaiResponsesBackend(request) {
|
|
25319
|
+
const { metadata: _metadata, native_tools: _nativeTools, ...rest } = request;
|
|
25320
|
+
return {
|
|
25321
|
+
...rest,
|
|
25322
|
+
input: request.input.map((item) => {
|
|
25323
|
+
if (item.type === "function_call_output") {
|
|
25324
|
+
const { is_error: _isError, tool_references: _toolReferences, ...wireItem2 } = item;
|
|
25325
|
+
return wireItem2;
|
|
25326
|
+
}
|
|
25327
|
+
const { reasoning_content: _reasoningContent, ...wireItem } = item;
|
|
25328
|
+
return wireItem;
|
|
25329
|
+
}),
|
|
25330
|
+
...request.tools === void 0 ? {} : { tools: request.tools.map(({ defer_loading: _deferLoading, ...tool }) => tool) }
|
|
25331
|
+
};
|
|
25332
|
+
}
|
|
25333
|
+
function parseXaiEventStream(body, options, functionCallTimeoutMs) {
|
|
25334
|
+
return assembleXaiFunctionCalls(
|
|
25335
|
+
parseUpstreamSseStream(
|
|
25336
|
+
body,
|
|
25337
|
+
{ ...options, missingBodyMessage: "Grok CLI streaming response had no body" },
|
|
25338
|
+
parseEventFrame3
|
|
25339
|
+
),
|
|
25340
|
+
options.controller,
|
|
25341
|
+
functionCallTimeoutMs
|
|
25342
|
+
);
|
|
25343
|
+
}
|
|
25344
|
+
async function* assembleXaiFunctionCalls(source, controller, timeoutMs) {
|
|
25345
|
+
const iterator = source[Symbol.asyncIterator]();
|
|
25346
|
+
const pending = /* @__PURE__ */ new Map();
|
|
25347
|
+
let completedNormally = false;
|
|
25348
|
+
try {
|
|
25349
|
+
while (true) {
|
|
25350
|
+
const deadlineAt = earliestXaiFunctionCallDeadline(pending);
|
|
25351
|
+
const result = deadlineAt === void 0 ? await iterator.next() : await nextXaiEventBeforeDeadline(iterator, deadlineAt, controller, timeoutMs);
|
|
25352
|
+
if (result.done) {
|
|
25353
|
+
if (pending.size > 0) {
|
|
25354
|
+
throw incompleteXaiFunctionCall("stream ended before function call output_item.done");
|
|
25355
|
+
}
|
|
25356
|
+
completedNormally = true;
|
|
25357
|
+
return;
|
|
25358
|
+
}
|
|
25359
|
+
const event = result.value;
|
|
25360
|
+
if (event.type === "response.completed" && pending.size > 0) {
|
|
25361
|
+
throw incompleteXaiFunctionCall("response.completed arrived before function call output_item.done");
|
|
25362
|
+
}
|
|
25363
|
+
if (event.type === "response.output_item.added" && event.item.type === "function_call") {
|
|
25364
|
+
const key = xaiFunctionCallKey(event.output_index, event.item.id);
|
|
25365
|
+
pending.set(key, {
|
|
25366
|
+
added: event,
|
|
25367
|
+
// Each call gets a full timeout from its own added event. Waiting uses the
|
|
25368
|
+
// earliest active deadline, so a later parallel call is never shortened by
|
|
25369
|
+
// an earlier call's age.
|
|
25370
|
+
deadlineAt: Date.now() + timeoutMs
|
|
25371
|
+
});
|
|
25372
|
+
continue;
|
|
25373
|
+
}
|
|
25374
|
+
if (event.type === "response.function_call_arguments.done") {
|
|
25375
|
+
const call = pending.get(xaiFunctionCallKey(event.output_index, event.item_id));
|
|
25376
|
+
if (call !== void 0) {
|
|
25377
|
+
call.argumentsDone = event;
|
|
25378
|
+
continue;
|
|
25379
|
+
}
|
|
25380
|
+
}
|
|
25381
|
+
if (event.type === "response.output_item.done" && event.item.type === "function_call") {
|
|
25382
|
+
const key = xaiFunctionCallKey(event.output_index, event.item.id);
|
|
25383
|
+
const call = pending.get(key);
|
|
25384
|
+
if (call !== void 0) {
|
|
25385
|
+
pending.delete(key);
|
|
25386
|
+
yield call.added;
|
|
25387
|
+
if (call.argumentsDone !== void 0) {
|
|
25388
|
+
yield call.argumentsDone;
|
|
25389
|
+
} else if (event.item.arguments.length > 0) {
|
|
25390
|
+
yield {
|
|
25391
|
+
type: "response.function_call_arguments.done",
|
|
25392
|
+
item_id: event.item.id,
|
|
25393
|
+
output_index: event.output_index,
|
|
25394
|
+
arguments: event.item.arguments
|
|
25395
|
+
};
|
|
25396
|
+
}
|
|
25397
|
+
yield event;
|
|
25398
|
+
continue;
|
|
25399
|
+
}
|
|
25400
|
+
}
|
|
25401
|
+
yield event;
|
|
25402
|
+
}
|
|
25403
|
+
} finally {
|
|
25404
|
+
if (!completedNormally && !controller.signal.aborted) {
|
|
25405
|
+
controller.abort();
|
|
25406
|
+
}
|
|
25407
|
+
const returned = iterator.return?.();
|
|
25408
|
+
if (returned !== void 0) {
|
|
25409
|
+
await returned.catch(() => void 0);
|
|
25410
|
+
}
|
|
25411
|
+
}
|
|
25412
|
+
}
|
|
25413
|
+
function earliestXaiFunctionCallDeadline(pending) {
|
|
25414
|
+
let earliest;
|
|
25415
|
+
for (const call of pending.values()) {
|
|
25416
|
+
if (earliest === void 0 || call.deadlineAt < earliest) {
|
|
25417
|
+
earliest = call.deadlineAt;
|
|
25418
|
+
}
|
|
25419
|
+
}
|
|
25420
|
+
return earliest;
|
|
25421
|
+
}
|
|
25422
|
+
async function nextXaiEventBeforeDeadline(iterator, deadlineAt, controller, timeoutMs) {
|
|
25423
|
+
const remainingMs = deadlineAt - Date.now();
|
|
25424
|
+
if (remainingMs <= 0) {
|
|
25425
|
+
const error51 = incompleteXaiFunctionCall(`function call assembly exceeded ${timeoutMs}ms`);
|
|
25426
|
+
controller.abort(error51);
|
|
25427
|
+
throw error51;
|
|
25428
|
+
}
|
|
25429
|
+
let timeout;
|
|
25430
|
+
const next = iterator.next();
|
|
25431
|
+
void next.catch(() => void 0);
|
|
25432
|
+
try {
|
|
25433
|
+
return await Promise.race([
|
|
25434
|
+
next,
|
|
25435
|
+
new Promise((_, reject) => {
|
|
25436
|
+
timeout = setTimeout(() => {
|
|
25437
|
+
const error51 = incompleteXaiFunctionCall(`function call assembly exceeded ${timeoutMs}ms`);
|
|
25438
|
+
controller.abort(error51);
|
|
25439
|
+
reject(error51);
|
|
25440
|
+
}, remainingMs);
|
|
25441
|
+
})
|
|
25442
|
+
]);
|
|
25443
|
+
} finally {
|
|
25444
|
+
if (timeout !== void 0) {
|
|
25445
|
+
clearTimeout(timeout);
|
|
25446
|
+
}
|
|
25447
|
+
}
|
|
25448
|
+
}
|
|
25449
|
+
function incompleteXaiFunctionCall(reason) {
|
|
25450
|
+
return new UpstreamProtocolError(`Grok CLI ${reason}`);
|
|
25451
|
+
}
|
|
25452
|
+
function xaiFunctionCallKey(outputIndex, itemId) {
|
|
25453
|
+
return `${outputIndex}:${itemId}`;
|
|
25454
|
+
}
|
|
25455
|
+
function parseEventFrame3(frame) {
|
|
25456
|
+
const { event: eventName, data } = parseSseFrameFields(frame);
|
|
25457
|
+
if (data.length === 0 || data === "[DONE]") {
|
|
25458
|
+
return void 0;
|
|
25459
|
+
}
|
|
25460
|
+
let parsed;
|
|
25461
|
+
try {
|
|
25462
|
+
parsed = JSON.parse(data);
|
|
25463
|
+
} catch (error51) {
|
|
25464
|
+
throw new UpstreamProtocolError(
|
|
25465
|
+
`Grok CLI SSE contained invalid JSON: ${error51 instanceof Error ? error51.message : String(error51)}`
|
|
25466
|
+
);
|
|
25467
|
+
}
|
|
25468
|
+
if (isRecord7(parsed) && typeof parsed.type !== "string" && eventName !== void 0) {
|
|
25469
|
+
parsed = { ...parsed, type: eventName };
|
|
25470
|
+
}
|
|
25471
|
+
return canonicalEvent3(parsed);
|
|
25472
|
+
}
|
|
25473
|
+
function canonicalEvent3(value) {
|
|
25474
|
+
if (!isRecord7(value) || typeof value.type !== "string") {
|
|
25475
|
+
throw new UpstreamProtocolError("Grok CLI SSE event was not an object with a type");
|
|
25476
|
+
}
|
|
25477
|
+
switch (value.type) {
|
|
25478
|
+
case "response.created":
|
|
25479
|
+
return { type: value.type, response: responseSnapshot3(value.response) };
|
|
25480
|
+
case "response.content_part.added": {
|
|
25481
|
+
const part = record3(value.part, "response.content_part.added.part");
|
|
25482
|
+
if (part.type !== "output_text") {
|
|
25483
|
+
return void 0;
|
|
25484
|
+
}
|
|
25485
|
+
return {
|
|
25486
|
+
type: value.type,
|
|
25487
|
+
item_id: string32(value.item_id, "item_id"),
|
|
25488
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25489
|
+
content_index: number32(value.content_index, "content_index"),
|
|
25490
|
+
part: {
|
|
25491
|
+
type: "output_text",
|
|
25492
|
+
text: typeof part.text === "string" ? part.text : ""
|
|
25493
|
+
}
|
|
25494
|
+
};
|
|
25495
|
+
}
|
|
25496
|
+
case "response.output_text.delta":
|
|
25497
|
+
return {
|
|
25498
|
+
type: value.type,
|
|
25499
|
+
item_id: string32(value.item_id, "item_id"),
|
|
25500
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25501
|
+
content_index: number32(value.content_index, "content_index"),
|
|
25502
|
+
delta: string32(value.delta, "delta")
|
|
25503
|
+
};
|
|
25504
|
+
case "response.output_text.done":
|
|
25505
|
+
return {
|
|
25506
|
+
type: value.type,
|
|
25507
|
+
item_id: string32(value.item_id, "item_id"),
|
|
25508
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25509
|
+
content_index: number32(value.content_index, "content_index"),
|
|
25510
|
+
text: string32(value.text, "text")
|
|
25511
|
+
};
|
|
25512
|
+
case "response.reasoning_summary_text.delta":
|
|
25513
|
+
case "response.reasoning_text.delta":
|
|
25514
|
+
return {
|
|
25515
|
+
type: "response.reasoning_summary_text.delta",
|
|
25516
|
+
item_id: string32(value.item_id, "item_id"),
|
|
25517
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25518
|
+
delta: string32(value.delta, "delta")
|
|
25519
|
+
};
|
|
25520
|
+
case "response.output_item.added":
|
|
25521
|
+
case "response.output_item.done": {
|
|
25522
|
+
const item = outputItem3(value.item);
|
|
25523
|
+
if (item === void 0) {
|
|
25524
|
+
return void 0;
|
|
25525
|
+
}
|
|
25526
|
+
return {
|
|
25527
|
+
type: value.type,
|
|
25528
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25529
|
+
item
|
|
25530
|
+
};
|
|
25531
|
+
}
|
|
25532
|
+
// Hold argument fragments until the Grok CLI proxy's partial-JSON behavior is observed.
|
|
25533
|
+
// The `.done` event carries the complete argument object, which downstream treats as the
|
|
25534
|
+
// remainder when nothing was streamed ahead of it.
|
|
25535
|
+
case "response.function_call_arguments.delta":
|
|
25536
|
+
return void 0;
|
|
25537
|
+
case "response.function_call_arguments.done":
|
|
25538
|
+
return {
|
|
25539
|
+
type: value.type,
|
|
25540
|
+
item_id: string32(value.item_id, "item_id"),
|
|
25541
|
+
output_index: number32(value.output_index, "output_index"),
|
|
25542
|
+
arguments: string32(value.arguments, "arguments")
|
|
25543
|
+
};
|
|
25544
|
+
case "response.completed":
|
|
25545
|
+
return { type: value.type, response: responseSnapshot3(value.response) };
|
|
25546
|
+
case "response.failed": {
|
|
25547
|
+
const response = record3(value.response, "response.failed.response");
|
|
25548
|
+
return {
|
|
25549
|
+
type: value.type,
|
|
25550
|
+
response: {
|
|
25551
|
+
...responseSnapshot3(response),
|
|
25552
|
+
error: canonicalError3(response.error)
|
|
25553
|
+
}
|
|
25554
|
+
};
|
|
25555
|
+
}
|
|
25556
|
+
case "error":
|
|
25557
|
+
return { type: "error", error: canonicalError3(value.error ?? value) };
|
|
25558
|
+
default:
|
|
25559
|
+
return void 0;
|
|
25560
|
+
}
|
|
25561
|
+
}
|
|
25562
|
+
function responseSnapshot3(value) {
|
|
25563
|
+
const response = record3(value, "response");
|
|
25564
|
+
return {
|
|
25565
|
+
id: string32(response.id, "response.id"),
|
|
25566
|
+
model: string32(response.model, "response.model"),
|
|
25567
|
+
usage: response.usage === null || response.usage === void 0 ? null : usage3(response.usage)
|
|
25568
|
+
};
|
|
25569
|
+
}
|
|
25570
|
+
function usage3(value) {
|
|
25571
|
+
const parsed = record3(value, "usage");
|
|
25572
|
+
const inputTokens = number32(parsed.input_tokens, "usage.input_tokens");
|
|
25573
|
+
const outputTokens = number32(parsed.output_tokens, "usage.output_tokens");
|
|
25574
|
+
const inputDetails = optionalRecord3(parsed.input_tokens_details, "usage.input_tokens_details");
|
|
25575
|
+
const cachedInputTokens = inputDetails === void 0 ? void 0 : optionalNonNegativeNumber3(inputDetails.cached_tokens, "usage.input_tokens_details.cached_tokens");
|
|
25576
|
+
const cacheWriteInputTokens = inputDetails === void 0 ? void 0 : optionalNonNegativeNumber3(inputDetails.cache_write_tokens, "usage.input_tokens_details.cache_write_tokens");
|
|
25577
|
+
const outputDetails = optionalRecord3(parsed.output_tokens_details, "usage.output_tokens_details");
|
|
25578
|
+
const reasoningOutputTokens = outputDetails === void 0 ? void 0 : optionalNonNegativeNumber3(outputDetails.reasoning_tokens, "usage.output_tokens_details.reasoning_tokens");
|
|
25579
|
+
const totalTokens = optionalNonNegativeNumber3(parsed.total_tokens, "usage.total_tokens");
|
|
25580
|
+
return {
|
|
25581
|
+
input_tokens: inputTokens,
|
|
25582
|
+
output_tokens: outputTokens,
|
|
25583
|
+
...cachedInputTokens === void 0 ? {} : { cached_input_tokens: cachedInputTokens },
|
|
25584
|
+
...cacheWriteInputTokens === void 0 ? {} : { cache_write_input_tokens: cacheWriteInputTokens },
|
|
25585
|
+
...reasoningOutputTokens === void 0 ? {} : { reasoning_output_tokens: reasoningOutputTokens },
|
|
25586
|
+
...totalTokens === void 0 ? {} : { total_tokens: totalTokens }
|
|
25587
|
+
};
|
|
25588
|
+
}
|
|
25589
|
+
function outputItem3(value) {
|
|
25590
|
+
const item = record3(value, "item");
|
|
25591
|
+
if (item.type === "message") {
|
|
25592
|
+
return {
|
|
25593
|
+
id: string32(item.id, "item.id"),
|
|
25594
|
+
type: "message",
|
|
25595
|
+
role: "assistant"
|
|
25596
|
+
};
|
|
25597
|
+
}
|
|
25598
|
+
if (item.type === "function_call") {
|
|
25599
|
+
const id = string32(item.id, "item.id");
|
|
25600
|
+
return {
|
|
25601
|
+
id,
|
|
25602
|
+
type: "function_call",
|
|
25603
|
+
call_id: typeof item.call_id === "string" ? item.call_id : id,
|
|
25604
|
+
name: string32(item.name, "item.name"),
|
|
25605
|
+
arguments: typeof item.arguments === "string" ? item.arguments : ""
|
|
25606
|
+
};
|
|
25607
|
+
}
|
|
25608
|
+
return void 0;
|
|
25609
|
+
}
|
|
25610
|
+
function canonicalError3(value) {
|
|
25611
|
+
const error51 = record3(value, "error");
|
|
25612
|
+
const message = string32(error51.message, "error.message");
|
|
25613
|
+
const type = typeof error51.type === "string" && error51.type !== "error" ? error51.type : typeof error51.code === "string" ? error51.code : "api_error";
|
|
25614
|
+
return { type, message };
|
|
25615
|
+
}
|
|
25616
|
+
function isRecord7(value) {
|
|
25617
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25618
|
+
}
|
|
25619
|
+
function record3(value, name) {
|
|
25620
|
+
if (!isRecord7(value)) {
|
|
25621
|
+
throw new UpstreamProtocolError(`${name} must be an object`);
|
|
25622
|
+
}
|
|
25623
|
+
return value;
|
|
25624
|
+
}
|
|
25625
|
+
function optionalRecord3(value, name) {
|
|
25626
|
+
if (value === void 0 || value === null) {
|
|
25627
|
+
return void 0;
|
|
25628
|
+
}
|
|
25629
|
+
return record3(value, name);
|
|
25630
|
+
}
|
|
25631
|
+
function string32(value, name) {
|
|
25632
|
+
if (typeof value !== "string") {
|
|
25633
|
+
throw new UpstreamProtocolError(`${name} must be a string`);
|
|
25634
|
+
}
|
|
25635
|
+
return value;
|
|
25636
|
+
}
|
|
25637
|
+
function number32(value, name) {
|
|
25638
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
25639
|
+
throw new UpstreamProtocolError(`${name} must be a number`);
|
|
25640
|
+
}
|
|
25641
|
+
return value;
|
|
25642
|
+
}
|
|
25643
|
+
function optionalNonNegativeNumber3(value, name) {
|
|
25644
|
+
if (value === void 0 || value === null) {
|
|
25645
|
+
return void 0;
|
|
25646
|
+
}
|
|
25647
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
25648
|
+
throw new UpstreamProtocolError(`${name} must be a finite nonnegative number`);
|
|
25649
|
+
}
|
|
25650
|
+
return value;
|
|
25651
|
+
}
|
|
24868
25652
|
var NO_USER_FACING_BLOCK = "Do not tell the user access is blocked, disabled, or denied.";
|
|
24869
25653
|
var CLIENT_TOOL_RETRY = `${NO_USER_FACING_BLOCK} Silently retry with the matching client bridge tool from the current catalog.`;
|
|
24870
25654
|
function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
@@ -24905,38 +25689,38 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24905
25689
|
"shell_command",
|
|
24906
25690
|
"exec_command"
|
|
24907
25691
|
]);
|
|
24908
|
-
if (
|
|
25692
|
+
if (isRecord8(exec2.readArgs)) {
|
|
24909
25693
|
return [execReply(exec2, "readResult", {
|
|
24910
25694
|
error: { path: stringValue(exec2.readArgs.path), error: readMessage3 }
|
|
24911
25695
|
})];
|
|
24912
25696
|
}
|
|
24913
|
-
if (
|
|
25697
|
+
if (isRecord8(exec2.writeArgs)) {
|
|
24914
25698
|
return [execReply(exec2, "writeResult", {
|
|
24915
25699
|
rejected: { path: stringValue(exec2.writeArgs.path), reason: mutationMessage }
|
|
24916
25700
|
})];
|
|
24917
25701
|
}
|
|
24918
|
-
if (
|
|
25702
|
+
if (isRecord8(exec2.deleteArgs)) {
|
|
24919
25703
|
return [execReply(exec2, "deleteResult", {
|
|
24920
25704
|
rejected: { path: stringValue(exec2.deleteArgs.path), reason: mutationMessage }
|
|
24921
25705
|
})];
|
|
24922
25706
|
}
|
|
24923
|
-
if (
|
|
25707
|
+
if (isRecord8(exec2.lsArgs)) {
|
|
24924
25708
|
return [execReply(exec2, "lsResult", {
|
|
24925
25709
|
error: { path: stringValue(exec2.lsArgs.path), error: listMessage }
|
|
24926
25710
|
})];
|
|
24927
25711
|
}
|
|
24928
|
-
if (
|
|
25712
|
+
if (isRecord8(exec2.grepArgs)) {
|
|
24929
25713
|
return [execReply(exec2, "grepResult", { error: { error: grepMessage } })];
|
|
24930
25714
|
}
|
|
24931
|
-
if (
|
|
25715
|
+
if (isRecord8(exec2.shellArgs)) {
|
|
24932
25716
|
return [execReply(exec2, "shellResult", shellFailure(exec2.shellArgs, shellMessage))];
|
|
24933
25717
|
}
|
|
24934
|
-
if (
|
|
25718
|
+
if (isRecord8(exec2.shellStreamArgs)) {
|
|
24935
25719
|
const args = exec2.shellStreamArgs;
|
|
24936
25720
|
const cwd = stringValue(args.workingDirectory);
|
|
24937
25721
|
return [
|
|
24938
25722
|
execReply(exec2, "shellStream", {
|
|
24939
|
-
start:
|
|
25723
|
+
start: isRecord8(args.requestedSandboxPolicy) ? { sandboxPolicy: args.requestedSandboxPolicy } : {}
|
|
24940
25724
|
}),
|
|
24941
25725
|
execReply(exec2, "shellStream", { stderr: { data: shellMessage } }),
|
|
24942
25726
|
execReply(exec2, "shellStream", { exit: { code: 1, cwd, aborted: true } }),
|
|
@@ -24944,7 +25728,7 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24944
25728
|
{ execClientControlMessage: { streamClose: { id: numberValue(exec2.id) } } }
|
|
24945
25729
|
];
|
|
24946
25730
|
}
|
|
24947
|
-
if (
|
|
25731
|
+
if (isRecord8(exec2.backgroundShellSpawnArgs)) {
|
|
24948
25732
|
const args = exec2.backgroundShellSpawnArgs;
|
|
24949
25733
|
return [execReply(exec2, "backgroundShellSpawnResult", {
|
|
24950
25734
|
error: {
|
|
@@ -24954,15 +25738,15 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24954
25738
|
}
|
|
24955
25739
|
})];
|
|
24956
25740
|
}
|
|
24957
|
-
if (
|
|
25741
|
+
if (isRecord8(exec2.writeShellStdinArgs)) {
|
|
24958
25742
|
return [execReply(exec2, "writeShellStdinResult", { error: { error: shellMessage } })];
|
|
24959
25743
|
}
|
|
24960
|
-
if (
|
|
25744
|
+
if (isRecord8(exec2.fetchArgs)) {
|
|
24961
25745
|
return [execReply(exec2, "fetchResult", {
|
|
24962
25746
|
error: { url: stringValue(exec2.fetchArgs.url), error: networkMessage }
|
|
24963
25747
|
})];
|
|
24964
25748
|
}
|
|
24965
|
-
if (
|
|
25749
|
+
if (isRecord8(exec2.diagnosticsArgs)) {
|
|
24966
25750
|
return [execReply(exec2, "diagnosticsResult", {
|
|
24967
25751
|
error: {
|
|
24968
25752
|
path: stringValue(exec2.diagnosticsArgs.path),
|
|
@@ -24970,12 +25754,12 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24970
25754
|
}
|
|
24971
25755
|
})];
|
|
24972
25756
|
}
|
|
24973
|
-
if (
|
|
25757
|
+
if (isRecord8(exec2.listMcpResourcesExecArgs)) {
|
|
24974
25758
|
return [execReply(exec2, "listMcpResourcesExecResult", {
|
|
24975
25759
|
error: { error: retryMessage(clientTools, ["ListMcpResources", "list_mcp_resources"]) }
|
|
24976
25760
|
})];
|
|
24977
25761
|
}
|
|
24978
|
-
if (
|
|
25762
|
+
if (isRecord8(exec2.readMcpResourceExecArgs)) {
|
|
24979
25763
|
return [execReply(exec2, "readMcpResourceExecResult", {
|
|
24980
25764
|
error: {
|
|
24981
25765
|
uri: stringValue(exec2.readMcpResourceExecArgs.uri),
|
|
@@ -24983,12 +25767,12 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24983
25767
|
}
|
|
24984
25768
|
})];
|
|
24985
25769
|
}
|
|
24986
|
-
if (
|
|
25770
|
+
if (isRecord8(exec2.recordScreenArgs)) {
|
|
24987
25771
|
return [execReply(exec2, "recordScreenResult", {
|
|
24988
25772
|
failure: { error: retryMessage(clientTools, ["record_screen", "computer_use"]) }
|
|
24989
25773
|
})];
|
|
24990
25774
|
}
|
|
24991
|
-
if (
|
|
25775
|
+
if (isRecord8(exec2.computerUseArgs)) {
|
|
24992
25776
|
return [execReply(exec2, "computerUseResult", {
|
|
24993
25777
|
error: {
|
|
24994
25778
|
error: retryMessage(clientTools, ["computer_use"]),
|
|
@@ -24998,7 +25782,7 @@ function cursorNativeExecPolicyReplies(exec2, clientTools) {
|
|
|
24998
25782
|
}
|
|
24999
25783
|
})];
|
|
25000
25784
|
}
|
|
25001
|
-
if (
|
|
25785
|
+
if (isRecord8(exec2.mcpArgs)) {
|
|
25002
25786
|
return [execReply(exec2, "mcpResult", {
|
|
25003
25787
|
error: { error: retryMessage(clientTools, []) }
|
|
25004
25788
|
})];
|
|
@@ -25070,7 +25854,7 @@ function numberValue(value) {
|
|
|
25070
25854
|
function stringValue(value) {
|
|
25071
25855
|
return typeof value === "string" ? value : "";
|
|
25072
25856
|
}
|
|
25073
|
-
function
|
|
25857
|
+
function isRecord8(value) {
|
|
25074
25858
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25075
25859
|
}
|
|
25076
25860
|
var EXECUTE_HOOK_FIELD_NUMBER = 27;
|
|
@@ -25222,14 +26006,14 @@ function isCursorNativeRedirectToolName(name) {
|
|
|
25222
26006
|
function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
25223
26007
|
const messageId = numberValue2(exec2.id ?? 0);
|
|
25224
26008
|
const execId = stringValue2(exec2.execId) || `redirect-${messageId}`;
|
|
25225
|
-
if (
|
|
25226
|
-
const
|
|
25227
|
-
if (!
|
|
26009
|
+
if (isRecord9(exec2.readArgs)) {
|
|
26010
|
+
const path82 = stringValue2(exec2.readArgs.path);
|
|
26011
|
+
if (!path82) return null;
|
|
25228
26012
|
if ([exec2.readArgs.offset, exec2.readArgs.limit].some((value) => typeof value === "number" && value < 0)) return null;
|
|
25229
26013
|
const offset = positiveNumber(exec2.readArgs.offset);
|
|
25230
26014
|
const limit = positiveNumber(exec2.readArgs.limit);
|
|
25231
26015
|
if (offset !== void 0 || limit !== void 0) return null;
|
|
25232
|
-
const mapped = tools.filter((tool) => matchesLeaf(tool, READ_CANDIDATES)).map((tool) => ({ tool, args: readArguments(tool.inputSchemaValue,
|
|
26016
|
+
const mapped = tools.filter((tool) => matchesLeaf(tool, READ_CANDIDATES)).map((tool) => ({ tool, args: readArguments(tool.inputSchemaValue, path82) })).find((candidate) => candidate.args !== null);
|
|
25233
26017
|
if (!mapped?.args) return null;
|
|
25234
26018
|
return redirect(
|
|
25235
26019
|
exec2,
|
|
@@ -25241,14 +26025,14 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
25241
26025
|
"readResult",
|
|
25242
26026
|
"read-direct",
|
|
25243
26027
|
mapped.args,
|
|
25244
|
-
{ path:
|
|
26028
|
+
{ path: path82 }
|
|
25245
26029
|
);
|
|
25246
26030
|
}
|
|
25247
|
-
if (
|
|
26031
|
+
if (isRecord9(exec2.grepArgs)) {
|
|
25248
26032
|
const grepArgs = exec2.grepArgs;
|
|
25249
26033
|
const pattern = stringValue2(grepArgs.pattern);
|
|
25250
26034
|
if (!pattern.trim()) return null;
|
|
25251
|
-
const
|
|
26035
|
+
const path82 = stringValue2(grepArgs.path) || ".";
|
|
25252
26036
|
const glob = stringValue2(grepArgs.glob);
|
|
25253
26037
|
const outputMode = normalizedGrepOutputMode(stringValue2(grepArgs.outputMode));
|
|
25254
26038
|
if (!outputMode) return null;
|
|
@@ -25264,7 +26048,7 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
25264
26048
|
if (numericOptions.some((value) => typeof value === "number" && value < 0)) return null;
|
|
25265
26049
|
const mappingInput = {
|
|
25266
26050
|
pattern,
|
|
25267
|
-
path:
|
|
26051
|
+
path: path82,
|
|
25268
26052
|
glob,
|
|
25269
26053
|
outputMode,
|
|
25270
26054
|
caseInsensitive: grepArgs.caseInsensitive === true,
|
|
@@ -25281,7 +26065,7 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
25281
26065
|
const mapped = tools.filter((tool) => matchesLeaf(tool, GREP_CANDIDATES)).map((tool) => ({ tool, args: grepArguments(tool, mappingInput) })).find((candidate) => candidate.args !== null);
|
|
25282
26066
|
const nativeArgs = {
|
|
25283
26067
|
pattern,
|
|
25284
|
-
path:
|
|
26068
|
+
path: path82,
|
|
25285
26069
|
outputMode,
|
|
25286
26070
|
...glob ? { glob } : {},
|
|
25287
26071
|
...positiveNumber(grepArgs.offset) === void 0 ? {} : { offset: String(positiveNumber(grepArgs.offset)) }
|
|
@@ -25318,15 +26102,15 @@ function cursorNativeExecRedirect(exec2, tools, providerIdentifier) {
|
|
|
25318
26102
|
nativeArgs
|
|
25319
26103
|
);
|
|
25320
26104
|
}
|
|
25321
|
-
if (
|
|
25322
|
-
const argsRecord =
|
|
26105
|
+
if (isRecord9(exec2.shellArgs) || isRecord9(exec2.shellStreamArgs)) {
|
|
26106
|
+
const argsRecord = isRecord9(exec2.shellArgs) ? exec2.shellArgs : exec2.shellStreamArgs;
|
|
25323
26107
|
const command = stringValue2(argsRecord.command);
|
|
25324
26108
|
if (!command) return null;
|
|
25325
26109
|
const cwd = stringValue2(argsRecord.workingDirectory);
|
|
25326
26110
|
const timeout = positiveNumber(argsRecord.timeout) ?? positiveNumber(argsRecord.hardTimeout);
|
|
25327
26111
|
const mapped = tools.filter((tool) => matchesLeaf(tool, SHELL_CANDIDATES)).map((tool) => ({ tool, args: shellArguments(tool.inputSchemaValue, command, cwd || void 0, timeout) })).find((candidate) => candidate.args !== null);
|
|
25328
26112
|
if (!mapped?.args) return null;
|
|
25329
|
-
const stream =
|
|
26113
|
+
const stream = isRecord9(exec2.shellStreamArgs);
|
|
25330
26114
|
return redirect(
|
|
25331
26115
|
exec2,
|
|
25332
26116
|
mapped.tool,
|
|
@@ -25416,9 +26200,9 @@ function cursorNativeRedirectErrorReplies(correlation, error51) {
|
|
|
25416
26200
|
}
|
|
25417
26201
|
}
|
|
25418
26202
|
}
|
|
25419
|
-
function readArguments(schema,
|
|
26203
|
+
function readArguments(schema, path82) {
|
|
25420
26204
|
const pathKey = firstSchemaProperty(schema, ["file_path", "path"]);
|
|
25421
|
-
return pathKey ? { [pathKey]:
|
|
26205
|
+
return pathKey ? { [pathKey]: path82 } : null;
|
|
25422
26206
|
}
|
|
25423
26207
|
function grepArguments(tool, input) {
|
|
25424
26208
|
const leaf = normalizedLeaf(tool.clientName);
|
|
@@ -25579,7 +26363,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
25579
26363
|
output.slice(CURSOR_GREP_RECEIPT_PREFIX.length).trim(),
|
|
25580
26364
|
"base64url"
|
|
25581
26365
|
).toString("utf8"));
|
|
25582
|
-
if (!
|
|
26366
|
+
if (!isRecord9(decoded)) throw new Error("receipt is not an object");
|
|
25583
26367
|
if (decoded.ok === false && typeof decoded.error === "string") {
|
|
25584
26368
|
return { ok: false, error: decoded.error };
|
|
25585
26369
|
}
|
|
@@ -25592,7 +26376,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
25592
26376
|
if (!Array.isArray(decoded.counts) || !decoded.counts.every((entry) => Array.isArray(entry) && entry.length === 2 && typeof entry[0] === "string" && typeof entry[1] === "number" && Number.isSafeInteger(entry[1]) && entry[1] >= 0)) {
|
|
25593
26377
|
throw new Error("receipt counts are invalid");
|
|
25594
26378
|
}
|
|
25595
|
-
if (!Array.isArray(decoded.matches) || !decoded.matches.every((entry) =>
|
|
26379
|
+
if (!Array.isArray(decoded.matches) || !decoded.matches.every((entry) => isRecord9(entry) && typeof entry.file === "string" && typeof entry.lineNumber === "number" && Number.isSafeInteger(entry.lineNumber) && entry.lineNumber > 0 && typeof entry.content === "string" && typeof entry.contentTruncated === "boolean" && typeof entry.isContextLine === "boolean")) {
|
|
25596
26380
|
throw new Error("receipt matches are invalid");
|
|
25597
26381
|
}
|
|
25598
26382
|
for (const key of ["totalFiles", "totalLines", "totalMatchedLines"]) {
|
|
@@ -25610,7 +26394,7 @@ function parseGrepShellReceipt(output, expectedOutputMode) {
|
|
|
25610
26394
|
}
|
|
25611
26395
|
}
|
|
25612
26396
|
function buildGrepReceiptSuccess(args, receipt) {
|
|
25613
|
-
const
|
|
26397
|
+
const path82 = args.path || ".";
|
|
25614
26398
|
let result;
|
|
25615
26399
|
if (receipt.outputMode === "files_with_matches") {
|
|
25616
26400
|
result = {
|
|
@@ -25656,15 +26440,15 @@ function buildGrepReceiptSuccess(args, receipt) {
|
|
|
25656
26440
|
}
|
|
25657
26441
|
return {
|
|
25658
26442
|
pattern: args.pattern ?? "",
|
|
25659
|
-
path:
|
|
26443
|
+
path: path82,
|
|
25660
26444
|
outputMode: receipt.outputMode,
|
|
25661
|
-
workspaceResults: { [
|
|
26445
|
+
workspaceResults: { [path82]: result }
|
|
25662
26446
|
};
|
|
25663
26447
|
}
|
|
25664
26448
|
function buildGrepSuccess(args, output) {
|
|
25665
26449
|
const outputMode = normalizedGrepOutputMode(args.outputMode) ?? "content";
|
|
25666
26450
|
const lines = output.split(/\r?\n/).map((line) => line.trimEnd()).filter((line) => line.length > 0 && !line.startsWith("[") && !/^no matches/i.test(line));
|
|
25667
|
-
const
|
|
26451
|
+
const path82 = args.path || ".";
|
|
25668
26452
|
let result;
|
|
25669
26453
|
if (outputMode === "files_with_matches") {
|
|
25670
26454
|
result = {
|
|
@@ -25727,9 +26511,9 @@ function buildGrepSuccess(args, output) {
|
|
|
25727
26511
|
}
|
|
25728
26512
|
return {
|
|
25729
26513
|
pattern: args.pattern ?? "",
|
|
25730
|
-
path:
|
|
26514
|
+
path: path82,
|
|
25731
26515
|
outputMode,
|
|
25732
|
-
workspaceResults: { [
|
|
26516
|
+
workspaceResults: { [path82]: result }
|
|
25733
26517
|
};
|
|
25734
26518
|
}
|
|
25735
26519
|
function parseCallerShellOutput(output, isError) {
|
|
@@ -25791,7 +26575,7 @@ function redirect(exec2, tool, providerIdentifier, messageId, execId, execCase,
|
|
|
25791
26575
|
}
|
|
25792
26576
|
function execArgsToolCallId(exec2) {
|
|
25793
26577
|
for (const value of Object.values(exec2)) {
|
|
25794
|
-
if (!
|
|
26578
|
+
if (!isRecord9(value)) continue;
|
|
25795
26579
|
const toolCallId = stringValue2(value.toolCallId);
|
|
25796
26580
|
if (toolCallId) return toolCallId;
|
|
25797
26581
|
}
|
|
@@ -25812,7 +26596,7 @@ function firstSchemaProperty(schema, candidates) {
|
|
|
25812
26596
|
return candidates.find((candidate) => schemaHasProperty(schema, candidate));
|
|
25813
26597
|
}
|
|
25814
26598
|
function schemaHasProperty(schema, name) {
|
|
25815
|
-
return
|
|
26599
|
+
return isRecord9(schema.properties) && Object.prototype.hasOwnProperty.call(schema.properties, name);
|
|
25816
26600
|
}
|
|
25817
26601
|
function execReply2(exec2, resultName, result) {
|
|
25818
26602
|
return {
|
|
@@ -25833,13 +26617,13 @@ function numberOrUndefined(value) {
|
|
|
25833
26617
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
25834
26618
|
}
|
|
25835
26619
|
function positiveNumber(value) {
|
|
25836
|
-
const
|
|
25837
|
-
return
|
|
26620
|
+
const number42 = numberOrUndefined(value);
|
|
26621
|
+
return number42 !== void 0 && number42 > 0 ? number42 : void 0;
|
|
25838
26622
|
}
|
|
25839
26623
|
function stringValue2(value) {
|
|
25840
26624
|
return typeof value === "string" ? value : "";
|
|
25841
26625
|
}
|
|
25842
|
-
function
|
|
26626
|
+
function isRecord9(value) {
|
|
25843
26627
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25844
26628
|
}
|
|
25845
26629
|
var cursorAgentDescriptor = [
|
|
@@ -26670,18 +27454,18 @@ function decodeCursorServerMessage(payload) {
|
|
|
26670
27454
|
const message = fromBinary(AgentServerMessageSchema, payload);
|
|
26671
27455
|
const unknownExecFields = extractCursorUnknownExecFields(message);
|
|
26672
27456
|
const json2 = toJson(AgentServerMessageSchema, message);
|
|
26673
|
-
if (!
|
|
27457
|
+
if (!isRecord10(json2)) throw new TypeError("Cursor server frame was not a message object");
|
|
26674
27458
|
if (unknownExecFields.length > 0) {
|
|
26675
27459
|
Object.defineProperty(json2, CURSOR_UNKNOWN_EXEC_FIELDS, { value: unknownExecFields });
|
|
26676
27460
|
}
|
|
26677
27461
|
return json2;
|
|
26678
27462
|
}
|
|
26679
27463
|
function extractCursorUnknownExecFields(message) {
|
|
26680
|
-
if (!
|
|
26681
|
-
if (message.message.case !== "execServerMessage" || !
|
|
27464
|
+
if (!isRecord10(message) || !isRecord10(message.message)) return [];
|
|
27465
|
+
if (message.message.case !== "execServerMessage" || !isRecord10(message.message.value)) return [];
|
|
26682
27466
|
const fields = message.message.value.$unknown;
|
|
26683
27467
|
if (!Array.isArray(fields)) return [];
|
|
26684
|
-
return fields.filter((field) =>
|
|
27468
|
+
return fields.filter((field) => isRecord10(field) && typeof field.no === "number" && typeof field.wireType === "number" && field.data instanceof Uint8Array);
|
|
26685
27469
|
}
|
|
26686
27470
|
function parseConnectEndStreamError(payload) {
|
|
26687
27471
|
try {
|
|
@@ -26976,7 +27760,7 @@ function cursorToolArgumentBytes(argumentsText) {
|
|
|
26976
27760
|
} catch {
|
|
26977
27761
|
return {};
|
|
26978
27762
|
}
|
|
26979
|
-
if (!
|
|
27763
|
+
if (!isRecord10(parsed)) return {};
|
|
26980
27764
|
return Object.fromEntries(Object.entries(parsed).map(([name, value]) => [
|
|
26981
27765
|
name,
|
|
26982
27766
|
Buffer.from(toBinary(ValueSchema, fromJson(ValueSchema, value))).toString("base64")
|
|
@@ -27953,7 +28737,7 @@ function createCursorLiveRun(options) {
|
|
|
27953
28737
|
let blobFetchBytes = 0;
|
|
27954
28738
|
let blobFetchMisses = 0;
|
|
27955
28739
|
let redirectOperationSequence = 0;
|
|
27956
|
-
const
|
|
28740
|
+
const usage4 = (segment) => {
|
|
27957
28741
|
const outputTokens = Math.max(
|
|
27958
28742
|
segment.contextOutputTokens,
|
|
27959
28743
|
estimateTokens(segment.outputText, model)
|
|
@@ -27999,7 +28783,7 @@ function createCursorLiveRun(options) {
|
|
|
27999
28783
|
else if (segment.started) {
|
|
28000
28784
|
segment.queue.push({
|
|
28001
28785
|
type: "response.completed",
|
|
28002
|
-
response: { id: segment.responseId, model, usage:
|
|
28786
|
+
response: { id: segment.responseId, model, usage: usage4(segment) }
|
|
28003
28787
|
});
|
|
28004
28788
|
}
|
|
28005
28789
|
report("turn.finish", {
|
|
@@ -28066,7 +28850,7 @@ function createCursorLiveRun(options) {
|
|
|
28066
28850
|
response: {
|
|
28067
28851
|
id: activeSegment.responseId,
|
|
28068
28852
|
model,
|
|
28069
|
-
usage:
|
|
28853
|
+
usage: usage4(activeSegment)
|
|
28070
28854
|
}
|
|
28071
28855
|
});
|
|
28072
28856
|
}
|
|
@@ -28256,7 +29040,7 @@ ${argumentsText}`;
|
|
|
28256
29040
|
const handleFrame = (frame, replayed = false) => {
|
|
28257
29041
|
const unknownExecFields = frame[CURSOR_UNKNOWN_EXEC_FIELDS] ?? [];
|
|
28258
29042
|
lastFrame = describeCursorServerFrame(frame, unknownExecFields);
|
|
28259
|
-
const tokenDetails =
|
|
29043
|
+
const tokenDetails = isRecord10(frame.conversationCheckpointUpdate) && isRecord10(frame.conversationCheckpointUpdate.tokenDetails) ? frame.conversationCheckpointUpdate.tokenDetails : void 0;
|
|
28260
29044
|
const checkpointContextTokens = positiveTokenCount(tokenDetails?.usedTokens);
|
|
28261
29045
|
const checkpointContextWindow = positiveTokenCount(tokenDetails?.maxTokens);
|
|
28262
29046
|
if (!replayed) {
|
|
@@ -28269,7 +29053,7 @@ ${argumentsText}`;
|
|
|
28269
29053
|
...checkpointContextWindow === void 0 ? {} : { contextWindow: checkpointContextWindow }
|
|
28270
29054
|
});
|
|
28271
29055
|
}
|
|
28272
|
-
if (
|
|
29056
|
+
if (isRecord10(frame.conversationCheckpointUpdate)) {
|
|
28273
29057
|
if (checkpointContextTokens !== void 0) {
|
|
28274
29058
|
wireLog("cursor.wire.checkpoint", {
|
|
28275
29059
|
model: diagnosticModel,
|
|
@@ -28292,7 +29076,7 @@ ${argumentsText}`;
|
|
|
28292
29076
|
}
|
|
28293
29077
|
return;
|
|
28294
29078
|
}
|
|
28295
|
-
if (
|
|
29079
|
+
if (isRecord10(frame.kvServerMessage)) {
|
|
28296
29080
|
const kv = kvReply(frame.kvServerMessage, blobs);
|
|
28297
29081
|
stream.write(encodeCursorClientMessage(kv.message));
|
|
28298
29082
|
if (kv.fetch) {
|
|
@@ -28313,7 +29097,7 @@ ${argumentsText}`;
|
|
|
28313
29097
|
});
|
|
28314
29098
|
return;
|
|
28315
29099
|
}
|
|
28316
|
-
if (
|
|
29100
|
+
if (isRecord10(frame.interactionQuery)) {
|
|
28317
29101
|
const reply = cursorInteractionQueryReply(frame.interactionQuery);
|
|
28318
29102
|
stream.write(encodeCursorClientMessage(reply.message));
|
|
28319
29103
|
report("client.reply", { model: diagnosticModel, reply: reply.replyKind });
|
|
@@ -28329,7 +29113,7 @@ ${argumentsText}`;
|
|
|
28329
29113
|
}
|
|
28330
29114
|
return;
|
|
28331
29115
|
}
|
|
28332
|
-
if (
|
|
29116
|
+
if (isRecord10(frame.error)) {
|
|
28333
29117
|
if (state === "attached") {
|
|
28334
29118
|
emit({ type: "error", error: cursorError(frame.error) });
|
|
28335
29119
|
completeRun("server_error");
|
|
@@ -28358,8 +29142,8 @@ ${argumentsText}`;
|
|
|
28358
29142
|
return;
|
|
28359
29143
|
}
|
|
28360
29144
|
if (state !== "attached") return;
|
|
28361
|
-
if (
|
|
28362
|
-
if (
|
|
29145
|
+
if (isRecord10(frame.execServerMessage)) {
|
|
29146
|
+
if (isRecord10(frame.execServerMessage.requestContextArgs)) {
|
|
28363
29147
|
stream.write(encodeCursorClientMessage(cursorRequestContextReply(frame.execServerMessage, tools)));
|
|
28364
29148
|
report("client.reply", { model: diagnosticModel, reply: "exec.requestContext" });
|
|
28365
29149
|
return;
|
|
@@ -28448,10 +29232,10 @@ ${argumentsText}`;
|
|
|
28448
29232
|
}
|
|
28449
29233
|
return;
|
|
28450
29234
|
}
|
|
28451
|
-
const update =
|
|
29235
|
+
const update = isRecord10(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
28452
29236
|
if (update === void 0) return;
|
|
28453
29237
|
if (isSettledToolUpdate(update)) return;
|
|
28454
|
-
if (
|
|
29238
|
+
if (isRecord10(update.textDelta) && typeof update.textDelta.text === "string") {
|
|
28455
29239
|
activeSegment.outputText += update.textDelta.text;
|
|
28456
29240
|
emit({
|
|
28457
29241
|
type: "response.output_text.delta",
|
|
@@ -28462,7 +29246,7 @@ ${argumentsText}`;
|
|
|
28462
29246
|
});
|
|
28463
29247
|
return;
|
|
28464
29248
|
}
|
|
28465
|
-
if (
|
|
29249
|
+
if (isRecord10(update.thinkingDelta) && typeof update.thinkingDelta.text === "string") {
|
|
28466
29250
|
activeSegment.outputText += update.thinkingDelta.text;
|
|
28467
29251
|
emit({
|
|
28468
29252
|
type: "response.reasoning_summary_text.delta",
|
|
@@ -28472,12 +29256,12 @@ ${argumentsText}`;
|
|
|
28472
29256
|
});
|
|
28473
29257
|
return;
|
|
28474
29258
|
}
|
|
28475
|
-
if (
|
|
29259
|
+
if (isRecord10(update.tokenDelta)) {
|
|
28476
29260
|
const tokens = positiveTokenCount(update.tokenDelta.tokens);
|
|
28477
29261
|
if (tokens !== void 0) activeSegment.contextOutputTokens += tokens;
|
|
28478
29262
|
return;
|
|
28479
29263
|
}
|
|
28480
|
-
if (
|
|
29264
|
+
if (isRecord10(update.toolCallStarted)) {
|
|
28481
29265
|
const wireCall = mcpCallFromToolUpdate(update.toolCallStarted);
|
|
28482
29266
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
28483
29267
|
if (call) {
|
|
@@ -28487,7 +29271,7 @@ ${argumentsText}`;
|
|
|
28487
29271
|
}
|
|
28488
29272
|
return;
|
|
28489
29273
|
}
|
|
28490
|
-
if (
|
|
29274
|
+
if (isRecord10(update.partialToolCall)) {
|
|
28491
29275
|
const wireCall = mcpCallFromToolUpdate(update.partialToolCall);
|
|
28492
29276
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
28493
29277
|
if (!call) return;
|
|
@@ -28498,7 +29282,7 @@ ${argumentsText}`;
|
|
|
28498
29282
|
rescheduleToolTurnFinish();
|
|
28499
29283
|
return;
|
|
28500
29284
|
}
|
|
28501
|
-
if (
|
|
29285
|
+
if (isRecord10(update.toolCallCompleted)) {
|
|
28502
29286
|
const wireCall = mcpCallFromToolUpdate(update.toolCallCompleted);
|
|
28503
29287
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
28504
29288
|
if (!call) return;
|
|
@@ -28511,7 +29295,7 @@ ${argumentsText}`;
|
|
|
28511
29295
|
rescheduleToolTurnFinish();
|
|
28512
29296
|
return;
|
|
28513
29297
|
}
|
|
28514
|
-
if (
|
|
29298
|
+
if (isRecord10(update.turnEnded)) completeRun("turn_ended");
|
|
28515
29299
|
};
|
|
28516
29300
|
const eventsFor = (segment) => (async function* () {
|
|
28517
29301
|
try {
|
|
@@ -28721,34 +29505,34 @@ var CURSOR_INTERACTION_QUERY_CASES = [
|
|
|
28721
29505
|
];
|
|
28722
29506
|
var CURSOR_KV_CASES = ["getBlobArgs", "setBlobArgs"];
|
|
28723
29507
|
function describeCursorServerFrame(frame, unknownExecFields = []) {
|
|
28724
|
-
if (
|
|
29508
|
+
if (isRecord10(frame.interactionUpdate)) {
|
|
28725
29509
|
return `interactionUpdate.${cursorNestedRecordCase(
|
|
28726
29510
|
frame.interactionUpdate,
|
|
28727
29511
|
CURSOR_INTERACTION_UPDATE_CASES
|
|
28728
29512
|
)}`;
|
|
28729
29513
|
}
|
|
28730
|
-
if (
|
|
29514
|
+
if (isRecord10(frame.execServerMessage)) {
|
|
28731
29515
|
const knownCase = cursorNestedRecordCase(frame.execServerMessage, CURSOR_EXEC_CASES);
|
|
28732
29516
|
return `execServerMessage.${knownCase === "unknown" ? cursorUnknownExecCaseName(unknownExecFields) : knownCase}`;
|
|
28733
29517
|
}
|
|
28734
|
-
if (
|
|
29518
|
+
if (isRecord10(frame.interactionQuery)) {
|
|
28735
29519
|
return `interactionQuery.${cursorNestedRecordCase(
|
|
28736
29520
|
frame.interactionQuery,
|
|
28737
29521
|
CURSOR_INTERACTION_QUERY_CASES
|
|
28738
29522
|
)}`;
|
|
28739
29523
|
}
|
|
28740
|
-
if (
|
|
29524
|
+
if (isRecord10(frame.kvServerMessage)) {
|
|
28741
29525
|
return `kvServerMessage.${cursorNestedRecordCase(frame.kvServerMessage, CURSOR_KV_CASES)}`;
|
|
28742
29526
|
}
|
|
28743
|
-
if (
|
|
28744
|
-
if (
|
|
29527
|
+
if (isRecord10(frame.conversationCheckpointUpdate)) return "conversationCheckpointUpdate";
|
|
29528
|
+
if (isRecord10(frame.error)) return "error";
|
|
28745
29529
|
return "unknown";
|
|
28746
29530
|
}
|
|
28747
29531
|
function isCursorHeartbeatFrame(frame) {
|
|
28748
|
-
return
|
|
29532
|
+
return isRecord10(frame.interactionUpdate) && isRecord10(frame.interactionUpdate.heartbeat);
|
|
28749
29533
|
}
|
|
28750
29534
|
function cursorNestedRecordCase(value, cases) {
|
|
28751
|
-
return cases.find((candidate) =>
|
|
29535
|
+
return cases.find((candidate) => isRecord10(value[candidate])) ?? "unknown";
|
|
28752
29536
|
}
|
|
28753
29537
|
function positiveTokenCount(value) {
|
|
28754
29538
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) return void 0;
|
|
@@ -28760,8 +29544,8 @@ function cursorInteractionQueryReply(query) {
|
|
|
28760
29544
|
const response = (result = {}) => ({
|
|
28761
29545
|
interactionResponse: { id, ...result }
|
|
28762
29546
|
});
|
|
28763
|
-
if (
|
|
28764
|
-
const args =
|
|
29547
|
+
if (isRecord10(query.createPlanRequestQuery)) {
|
|
29548
|
+
const args = isRecord10(query.createPlanRequestQuery.args) ? query.createPlanRequestQuery.args : void 0;
|
|
28765
29549
|
const name = stringValue3(args?.name)?.trim();
|
|
28766
29550
|
const overview = stringValue3(args?.overview)?.trim();
|
|
28767
29551
|
const plan = stringValue3(args?.plan)?.trim();
|
|
@@ -28777,7 +29561,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
28777
29561
|
` } : {}
|
|
28778
29562
|
};
|
|
28779
29563
|
}
|
|
28780
|
-
if (
|
|
29564
|
+
if (isRecord10(query.askQuestionInteractionQuery)) {
|
|
28781
29565
|
return {
|
|
28782
29566
|
message: response({
|
|
28783
29567
|
askQuestionInteractionResponse: {
|
|
@@ -28787,7 +29571,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
28787
29571
|
replyKind: "interaction.askQuestion.rejected"
|
|
28788
29572
|
};
|
|
28789
29573
|
}
|
|
28790
|
-
if (
|
|
29574
|
+
if (isRecord10(query.switchModeRequestQuery)) {
|
|
28791
29575
|
return {
|
|
28792
29576
|
message: response({
|
|
28793
29577
|
switchModeRequestResponse: {
|
|
@@ -28797,19 +29581,19 @@ function cursorInteractionQueryReply(query) {
|
|
|
28797
29581
|
replyKind: "interaction.switchMode.rejected"
|
|
28798
29582
|
};
|
|
28799
29583
|
}
|
|
28800
|
-
if (
|
|
29584
|
+
if (isRecord10(query.webSearchRequestQuery)) {
|
|
28801
29585
|
return {
|
|
28802
29586
|
message: response({ webSearchRequestResponse: { approved: {} } }),
|
|
28803
29587
|
replyKind: "interaction.webSearch.approved"
|
|
28804
29588
|
};
|
|
28805
29589
|
}
|
|
28806
|
-
if (
|
|
29590
|
+
if (isRecord10(query.exaSearchRequestQuery)) {
|
|
28807
29591
|
return {
|
|
28808
29592
|
message: response({ exaSearchRequestResponse: { approved: {} } }),
|
|
28809
29593
|
replyKind: "interaction.exaSearch.approved"
|
|
28810
29594
|
};
|
|
28811
29595
|
}
|
|
28812
|
-
if (
|
|
29596
|
+
if (isRecord10(query.exaFetchRequestQuery)) {
|
|
28813
29597
|
return {
|
|
28814
29598
|
message: response({ exaFetchRequestResponse: { approved: {} } }),
|
|
28815
29599
|
replyKind: "interaction.exaFetch.approved"
|
|
@@ -28819,7 +29603,7 @@ function cursorInteractionQueryReply(query) {
|
|
|
28819
29603
|
}
|
|
28820
29604
|
function kvReply(kv, blobs) {
|
|
28821
29605
|
const id = kv.id ?? 0;
|
|
28822
|
-
if (
|
|
29606
|
+
if (isRecord10(kv.getBlobArgs)) {
|
|
28823
29607
|
const blobId = typeof kv.getBlobArgs.blobId === "string" ? kv.getBlobArgs.blobId : "";
|
|
28824
29608
|
const blobData = blobs.get(blobId);
|
|
28825
29609
|
return {
|
|
@@ -28831,7 +29615,7 @@ function kvReply(kv, blobs) {
|
|
|
28831
29615
|
}
|
|
28832
29616
|
};
|
|
28833
29617
|
}
|
|
28834
|
-
if (
|
|
29618
|
+
if (isRecord10(kv.setBlobArgs)) {
|
|
28835
29619
|
const blobId = typeof kv.setBlobArgs.blobId === "string" ? kv.setBlobArgs.blobId : "";
|
|
28836
29620
|
const blobData = typeof kv.setBlobArgs.blobData === "string" ? kv.setBlobArgs.blobData : "";
|
|
28837
29621
|
if (blobId) blobs.set(blobId, blobData);
|
|
@@ -28882,7 +29666,7 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
28882
29666
|
return { value: String(value), count: 1 };
|
|
28883
29667
|
}
|
|
28884
29668
|
if (Array.isArray(value)) {
|
|
28885
|
-
const itemSchema =
|
|
29669
|
+
const itemSchema = isRecord10(schema) ? schema.items : void 0;
|
|
28886
29670
|
if (itemSchema === void 0) return { value, count: 0 };
|
|
28887
29671
|
let repairedValues;
|
|
28888
29672
|
let count2 = 0;
|
|
@@ -28895,7 +29679,7 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
28895
29679
|
});
|
|
28896
29680
|
return { value: repairedValues ?? value, count: count2 };
|
|
28897
29681
|
}
|
|
28898
|
-
if (!
|
|
29682
|
+
if (!isRecord10(value) || !isRecord10(schema) || !isRecord10(schema.properties)) {
|
|
28899
29683
|
return { value, count: 0 };
|
|
28900
29684
|
}
|
|
28901
29685
|
let repairedValue;
|
|
@@ -28911,12 +29695,12 @@ function repairCursorArgumentValue(value, schema) {
|
|
|
28911
29695
|
return { value: repairedValue ?? value, count };
|
|
28912
29696
|
}
|
|
28913
29697
|
function cursorSchemaRequiresString(schema) {
|
|
28914
|
-
if (!
|
|
29698
|
+
if (!isRecord10(schema)) return false;
|
|
28915
29699
|
if (schema.type === "string") return true;
|
|
28916
29700
|
return Array.isArray(schema.type) && schema.type.includes("string") && schema.type.every((type) => type === "string" || type === "null");
|
|
28917
29701
|
}
|
|
28918
29702
|
function mcpCallFromToolUpdate(value) {
|
|
28919
|
-
const toolCall =
|
|
29703
|
+
const toolCall = isRecord10(value.toolCall) ? value.toolCall : void 0;
|
|
28920
29704
|
const args = toolCall ? mcpArgsFromToolCall(toolCall) : void 0;
|
|
28921
29705
|
if (!args) return null;
|
|
28922
29706
|
const publicCallId = stringValue3(value.callId);
|
|
@@ -28941,7 +29725,7 @@ var CURSOR_TOOL_UPDATE_CASES = [
|
|
|
28941
29725
|
function cursorToolUpdateIdentifiers(update) {
|
|
28942
29726
|
for (const key of CURSOR_TOOL_UPDATE_CASES) {
|
|
28943
29727
|
const value = update[key];
|
|
28944
|
-
if (!
|
|
29728
|
+
if (!isRecord10(value)) continue;
|
|
28945
29729
|
const call = mcpCallFromToolUpdate(value);
|
|
28946
29730
|
if (!call) return [];
|
|
28947
29731
|
return [...new Set(
|
|
@@ -28951,9 +29735,9 @@ function cursorToolUpdateIdentifiers(update) {
|
|
|
28951
29735
|
return void 0;
|
|
28952
29736
|
}
|
|
28953
29737
|
function isCursorClientToolFrame(frame, tools, redirectTools) {
|
|
28954
|
-
const update =
|
|
29738
|
+
const update = isRecord10(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
28955
29739
|
if (update !== void 0) return cursorToolUpdateIdentifiers(update) !== void 0;
|
|
28956
|
-
const exec2 =
|
|
29740
|
+
const exec2 = isRecord10(frame.execServerMessage) ? frame.execServerMessage : void 0;
|
|
28957
29741
|
if (exec2 === void 0) return false;
|
|
28958
29742
|
const wireCall = mcpCallFromExecMessage(exec2);
|
|
28959
29743
|
const call = wireCall ? cursorClientMcpCall(wireCall, tools) : null;
|
|
@@ -28969,16 +29753,16 @@ function isCursorClientToolFrame(frame, tools, redirectTools) {
|
|
|
28969
29753
|
) !== null;
|
|
28970
29754
|
}
|
|
28971
29755
|
function isCursorParkedResidueFrame(frame, parked) {
|
|
28972
|
-
const update =
|
|
29756
|
+
const update = isRecord10(frame.interactionUpdate) ? frame.interactionUpdate : void 0;
|
|
28973
29757
|
if (update === void 0) return false;
|
|
28974
|
-
if (
|
|
29758
|
+
if (isRecord10(update.tokenDelta)) return true;
|
|
28975
29759
|
const identifiers = cursorToolUpdateIdentifiers(update);
|
|
28976
29760
|
if (identifiers === void 0 || identifiers.length === 0 || parked === void 0) return false;
|
|
28977
29761
|
const sealed = new Set(parked.flatMap((call) => [call.callId, call.toolCallId]));
|
|
28978
29762
|
return identifiers.some((identifier) => sealed.has(identifier));
|
|
28979
29763
|
}
|
|
28980
29764
|
function mcpCallFromExecMessage(value) {
|
|
28981
|
-
const args =
|
|
29765
|
+
const args = isRecord10(value.mcpArgs) ? value.mcpArgs : void 0;
|
|
28982
29766
|
if (!args) return null;
|
|
28983
29767
|
const toolCallId = stringValue3(args.toolCallId);
|
|
28984
29768
|
if (!toolCallId) return null;
|
|
@@ -28996,14 +29780,14 @@ function mcpCallFromExecMessage(value) {
|
|
|
28996
29780
|
};
|
|
28997
29781
|
}
|
|
28998
29782
|
function mcpArgsFromToolCall(toolCall) {
|
|
28999
|
-
const direct =
|
|
29000
|
-
if (direct &&
|
|
29001
|
-
const tool =
|
|
29002
|
-
const nested = tool &&
|
|
29003
|
-
return nested &&
|
|
29783
|
+
const direct = isRecord10(toolCall.mcpToolCall) ? toolCall.mcpToolCall : void 0;
|
|
29784
|
+
if (direct && isRecord10(direct.args)) return direct.args;
|
|
29785
|
+
const tool = isRecord10(toolCall.tool) ? toolCall.tool : void 0;
|
|
29786
|
+
const nested = tool && isRecord10(tool.mcpToolCall) ? tool.mcpToolCall : void 0;
|
|
29787
|
+
return nested && isRecord10(nested.args) ? nested.args : void 0;
|
|
29004
29788
|
}
|
|
29005
29789
|
function cursorMcpArguments(args) {
|
|
29006
|
-
if (!
|
|
29790
|
+
if (!isRecord10(args.args) || Object.keys(args.args).length === 0) return {};
|
|
29007
29791
|
const decoded = {};
|
|
29008
29792
|
for (const [name, value] of Object.entries(args.args)) {
|
|
29009
29793
|
if (typeof value !== "string") {
|
|
@@ -29078,7 +29862,7 @@ function cursorError(value) {
|
|
|
29078
29862
|
message: typeof value.message === "string" ? value.message : "Cursor request failed"
|
|
29079
29863
|
};
|
|
29080
29864
|
}
|
|
29081
|
-
function
|
|
29865
|
+
function isRecord10(value) {
|
|
29082
29866
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29083
29867
|
}
|
|
29084
29868
|
var DEFAULT_CURSOR_DIAGNOSTIC_MAX_BYTES = 4 * 1024 * 1024;
|
|
@@ -29112,7 +29896,7 @@ var CURSOR_DIAGNOSTIC_EVENTS = /* @__PURE__ */ new Set([
|
|
|
29112
29896
|
"turn.finish"
|
|
29113
29897
|
]);
|
|
29114
29898
|
function createCursorDiagnosticLog(dir, options = {}) {
|
|
29115
|
-
const logPath =
|
|
29899
|
+
const logPath = path19__default.join(dir, CURSOR_DIAGNOSTIC_FILE);
|
|
29116
29900
|
const backupPath = `${logPath}.1`;
|
|
29117
29901
|
const maxBytes = positiveInteger2(options.maxBytes) ?? DEFAULT_CURSOR_DIAGNOSTIC_MAX_BYTES;
|
|
29118
29902
|
let initialized = false;
|
|
@@ -29170,43 +29954,43 @@ function createCursorDiagnosticLog(dir, options = {}) {
|
|
|
29170
29954
|
}
|
|
29171
29955
|
function serializeCursorDiagnosticEvent(event) {
|
|
29172
29956
|
if (!CURSOR_DIAGNOSTIC_EVENTS.has(event.event)) return null;
|
|
29173
|
-
const
|
|
29957
|
+
const record42 = {
|
|
29174
29958
|
timestamp: safeString(event.timestamp, 40),
|
|
29175
29959
|
runId: safeString(event.runId, 64),
|
|
29176
29960
|
event: event.event,
|
|
29177
29961
|
elapsedMs: safeNumber(event.elapsedMs)
|
|
29178
29962
|
};
|
|
29179
|
-
addString(
|
|
29180
|
-
addString(
|
|
29181
|
-
addString(
|
|
29963
|
+
addString(record42, "model", event.model, 128);
|
|
29964
|
+
addString(record42, "wireModel", event.wireModel, 128);
|
|
29965
|
+
addString(record42, "previousWireModel", event.previousWireModel, 128);
|
|
29182
29966
|
if (event.requestedEffort && CURSOR_DIAGNOSTIC_EFFORTS.has(event.requestedEffort)) {
|
|
29183
|
-
|
|
29184
|
-
}
|
|
29185
|
-
if (event.turn === "prompt" || event.turn === "tool-continuation")
|
|
29186
|
-
addNumber(
|
|
29187
|
-
addString(
|
|
29188
|
-
addString(
|
|
29189
|
-
addNumber(
|
|
29190
|
-
addNumber(
|
|
29191
|
-
addNumber(
|
|
29192
|
-
addString(
|
|
29193
|
-
addNumber(
|
|
29194
|
-
addNumber(
|
|
29195
|
-
addNumber(
|
|
29196
|
-
addNumber(
|
|
29197
|
-
addNumber(
|
|
29198
|
-
addString(
|
|
29199
|
-
addNumber(
|
|
29200
|
-
addString(
|
|
29201
|
-
addString(
|
|
29202
|
-
return `${JSON.stringify(
|
|
29967
|
+
record42.requestedEffort = event.requestedEffort;
|
|
29968
|
+
}
|
|
29969
|
+
if (event.turn === "prompt" || event.turn === "tool-continuation") record42.turn = event.turn;
|
|
29970
|
+
addNumber(record42, "status", event.status);
|
|
29971
|
+
addString(record42, "frame", event.frame, 128);
|
|
29972
|
+
addString(record42, "reply", event.reply, 128);
|
|
29973
|
+
addNumber(record42, "sequence", event.sequence);
|
|
29974
|
+
addNumber(record42, "count", event.count);
|
|
29975
|
+
addNumber(record42, "frameCount", event.frameCount);
|
|
29976
|
+
addString(record42, "lastFrame", event.lastFrame, 128);
|
|
29977
|
+
addNumber(record42, "toolCount", event.toolCount);
|
|
29978
|
+
addNumber(record42, "argumentRepairCount", event.argumentRepairCount);
|
|
29979
|
+
addNumber(record42, "estimatedInputTokens", event.estimatedInputTokens);
|
|
29980
|
+
addNumber(record42, "contextTokens", event.contextTokens);
|
|
29981
|
+
addNumber(record42, "contextWindow", event.contextWindow);
|
|
29982
|
+
addString(record42, "outcome", event.outcome, 128);
|
|
29983
|
+
addNumber(record42, "operationSequence", event.operationSequence);
|
|
29984
|
+
addString(record42, "adapter", event.adapter, 32);
|
|
29985
|
+
addString(record42, "error", event.error, 128);
|
|
29986
|
+
return `${JSON.stringify(record42)}
|
|
29203
29987
|
`;
|
|
29204
29988
|
}
|
|
29205
|
-
function addString(
|
|
29206
|
-
if (value !== void 0)
|
|
29989
|
+
function addString(record42, key, value, maxLength) {
|
|
29990
|
+
if (value !== void 0) record42[key] = safeString(value, maxLength);
|
|
29207
29991
|
}
|
|
29208
|
-
function addNumber(
|
|
29209
|
-
if (value !== void 0)
|
|
29992
|
+
function addNumber(record42, key, value) {
|
|
29993
|
+
if (value !== void 0) record42[key] = safeNumber(value);
|
|
29210
29994
|
}
|
|
29211
29995
|
function safeString(value, maxLength) {
|
|
29212
29996
|
return value.replace(/[\r\n\t]/g, " ").slice(0, maxLength);
|
|
@@ -29256,8 +30040,8 @@ function kimiAnthropicHeaders(requestHeaders, apiKey) {
|
|
|
29256
30040
|
return headers;
|
|
29257
30041
|
}
|
|
29258
30042
|
function normalizeAiGatewaySettings(value) {
|
|
29259
|
-
if (!
|
|
29260
|
-
const models = Array.isArray(value.models) ? value.models.filter((entry) =>
|
|
30043
|
+
if (!isRecord11(value) || value.version !== 1) return { version: 1 };
|
|
30044
|
+
const models = Array.isArray(value.models) ? value.models.filter((entry) => isRecord11(entry) && typeof entry.id === "string" && entry.id.length > 0).flatMap((entry) => {
|
|
29261
30045
|
const model = findGatewayModel(entry.id);
|
|
29262
30046
|
if (!model) return [];
|
|
29263
30047
|
const efforts = Array.isArray(entry.efforts) ? entry.efforts.filter((level) => typeof level === "string" && level.length > 0) : [];
|
|
@@ -29291,7 +30075,7 @@ function sanitizeProviderPriority(value) {
|
|
|
29291
30075
|
}
|
|
29292
30076
|
return cleaned.length > 0 ? cleaned : void 0;
|
|
29293
30077
|
}
|
|
29294
|
-
function
|
|
30078
|
+
function isRecord11(value) {
|
|
29295
30079
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29296
30080
|
}
|
|
29297
30081
|
function resolveAiGatewaySelection(settings2) {
|
|
@@ -29331,15 +30115,15 @@ function sortGatewayModelsByProvider(models) {
|
|
|
29331
30115
|
function parseAiGatewayUpdate(value) {
|
|
29332
30116
|
if (value === null) return { ok: true, value: void 0 };
|
|
29333
30117
|
if (!value || typeof value !== "object" || Array.isArray(value)) return { ok: false };
|
|
29334
|
-
const
|
|
29335
|
-
const extraKeys = Object.keys(
|
|
30118
|
+
const record42 = value;
|
|
30119
|
+
const extraKeys = Object.keys(record42).filter(
|
|
29336
30120
|
(key) => key !== "models" && key !== "defaultModel" && key !== "providerPriority"
|
|
29337
30121
|
);
|
|
29338
30122
|
if (extraKeys.length > 0) return { ok: false };
|
|
29339
30123
|
const models = [];
|
|
29340
|
-
if (
|
|
29341
|
-
if (!Array.isArray(
|
|
29342
|
-
for (const raw of
|
|
30124
|
+
if (record42.models !== void 0) {
|
|
30125
|
+
if (!Array.isArray(record42.models)) return { ok: false };
|
|
30126
|
+
for (const raw of record42.models) {
|
|
29343
30127
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { ok: false };
|
|
29344
30128
|
const entry = raw;
|
|
29345
30129
|
if (Object.keys(entry).some((key) => key !== "id" && key !== "efforts" && key !== "hostOnly")) {
|
|
@@ -29360,11 +30144,11 @@ function parseAiGatewayUpdate(value) {
|
|
|
29360
30144
|
}
|
|
29361
30145
|
}
|
|
29362
30146
|
let providerPriority;
|
|
29363
|
-
const hasProviderPriority = Object.prototype.hasOwnProperty.call(
|
|
30147
|
+
const hasProviderPriority = Object.prototype.hasOwnProperty.call(record42, "providerPriority");
|
|
29364
30148
|
if (hasProviderPriority) {
|
|
29365
|
-
if (!Array.isArray(
|
|
30149
|
+
if (!Array.isArray(record42.providerPriority)) return { ok: false };
|
|
29366
30150
|
providerPriority = [];
|
|
29367
|
-
for (const raw of
|
|
30151
|
+
for (const raw of record42.providerPriority) {
|
|
29368
30152
|
if (typeof raw !== "string") return { ok: false };
|
|
29369
30153
|
if (!GATEWAY_PROVIDERS.includes(raw)) return { ok: false };
|
|
29370
30154
|
const provider = raw;
|
|
@@ -29536,6 +30320,10 @@ async function readCursorSubscriptionToken() {
|
|
|
29536
30320
|
const credentials = await resolveCursorCredentials(defaultCredentialDeps);
|
|
29537
30321
|
return credentials?.accessToken ?? null;
|
|
29538
30322
|
}
|
|
30323
|
+
async function readXaiSubscriptionToken() {
|
|
30324
|
+
const credentials = await resolveXaiCliCredentials(defaultCredentialDeps);
|
|
30325
|
+
return credentials?.accessToken ?? null;
|
|
30326
|
+
}
|
|
29539
30327
|
async function readCodexSubscriptionAuth() {
|
|
29540
30328
|
const credentials = await resolveCodexCredentials(defaultCredentialDeps);
|
|
29541
30329
|
if (!credentials?.accountId) return null;
|
|
@@ -29633,6 +30421,10 @@ function createAiGatewayRouter(deps) {
|
|
|
29633
30421
|
for (const skill of pruned.withheld) withheldSkills.add(skill.name);
|
|
29634
30422
|
if (pruned.changed) body = { ...body, messages: [...pruned.messages] };
|
|
29635
30423
|
}
|
|
30424
|
+
if (target2 && target2.provider !== "kimi") {
|
|
30425
|
+
const omitted = omitClaudeWebSearchTools(body);
|
|
30426
|
+
if (omitted.changed) body = omitted.request;
|
|
30427
|
+
}
|
|
29636
30428
|
let credential = "";
|
|
29637
30429
|
let chatgptAccountId = "";
|
|
29638
30430
|
if (target2?.provider === "cursor") {
|
|
@@ -29664,6 +30456,13 @@ function createAiGatewayRouter(deps) {
|
|
|
29664
30456
|
return true;
|
|
29665
30457
|
}
|
|
29666
30458
|
credential = opencodeApiKey;
|
|
30459
|
+
} else if (target2?.provider === "xai") {
|
|
30460
|
+
const xaiToken = await deps.readXaiToken?.();
|
|
30461
|
+
if (!xaiToken) {
|
|
30462
|
+
writeAnthropicError(res, 401, "authentication_error", "No active Grok CLI sign-in was found. Run `grok login` first.");
|
|
30463
|
+
return true;
|
|
30464
|
+
}
|
|
30465
|
+
credential = xaiToken;
|
|
29667
30466
|
}
|
|
29668
30467
|
const controller = new AbortController();
|
|
29669
30468
|
const abort = () => controller.abort(new Error("client disconnected"));
|
|
@@ -29700,7 +30499,7 @@ function createAiGatewayRouter(deps) {
|
|
|
29700
30499
|
);
|
|
29701
30500
|
return true;
|
|
29702
30501
|
}
|
|
29703
|
-
const gateway = deps.gateway ?? (target2.provider === "cursor" ? ownedCursorGateway : target2.provider === "opencode" ? createOpencodeGateway(opencodeGoWire(target2)) : createGatewayFor(target2, chatgptAccountId, deps.originator));
|
|
30502
|
+
const gateway = deps.gateway ?? (target2.provider === "cursor" ? ownedCursorGateway : target2.provider === "opencode" ? createOpencodeGateway(opencodeGoWire(target2)) : target2.provider === "xai" ? new AnthropicMessagesGateway(new XaiResponsesAdapter({ fetch: fetchImpl })) : createGatewayFor(target2, chatgptAccountId, deps.originator));
|
|
29704
30503
|
const diagnosticsEnabled = target2.provider === "cursor" ? cursorDiagnosticsEnabled() : void 0;
|
|
29705
30504
|
const modelContextWindow = typeof target2.contextWindow === "number" && Number.isFinite(target2.contextWindow) && target2.contextWindow > 0 ? target2.contextWindow : void 0;
|
|
29706
30505
|
const upstream = await gateway.stream(body, {
|
|
@@ -29806,11 +30605,11 @@ var LOCK_OWNER_FILE_NAME2 = "owner";
|
|
|
29806
30605
|
var TEMP_FILE_PREFIX2 = `${AI_GATEWAY_SETTINGS_FILE_NAME}.`;
|
|
29807
30606
|
function createAiGatewaySettingsStore(deps = {}) {
|
|
29808
30607
|
const dataDir = deps.dataDir ?? getFleetDataDir();
|
|
29809
|
-
const settingsPath =
|
|
29810
|
-
const legacyPath = deps.legacyDir === void 0 ? void 0 :
|
|
30608
|
+
const settingsPath = path19.join(dataDir, AI_GATEWAY_SETTINGS_FILE_NAME);
|
|
30609
|
+
const legacyPath = deps.legacyDir === void 0 ? void 0 : path19.join(deps.legacyDir, AI_GATEWAY_SETTINGS_FILE_NAME);
|
|
29811
30610
|
const store = createDurableJsonStore({
|
|
29812
30611
|
filePath: settingsPath,
|
|
29813
|
-
lockDir:
|
|
30612
|
+
lockDir: path19.join(dataDir, LOCK_DIR_NAME2),
|
|
29814
30613
|
lockOwnerFileName: LOCK_OWNER_FILE_NAME2,
|
|
29815
30614
|
sanitize: (value) => normalizeAiGatewaySettings(value),
|
|
29816
30615
|
sensitivity: "sensitive",
|
|
@@ -29958,9 +30757,9 @@ function prepareAiGatewayLaunchProfile(profile, options) {
|
|
|
29958
30757
|
return { ...profile, env };
|
|
29959
30758
|
}
|
|
29960
30759
|
function writeClaudeGatewayModelCache(baseUrl, env, homeDir, exposedModels = GATEWAY_MODELS) {
|
|
29961
|
-
const configDir = env.CLAUDE_CONFIG_DIR && env.CLAUDE_CONFIG_DIR.length > 0 ? env.CLAUDE_CONFIG_DIR :
|
|
29962
|
-
const cacheDir =
|
|
29963
|
-
const cachePath =
|
|
30760
|
+
const configDir = env.CLAUDE_CONFIG_DIR && env.CLAUDE_CONFIG_DIR.length > 0 ? env.CLAUDE_CONFIG_DIR : path19__default.join(homeDir, ".claude");
|
|
30761
|
+
const cacheDir = path19__default.join(configDir, "cache");
|
|
30762
|
+
const cachePath = path19__default.join(cacheDir, "gateway-models.json");
|
|
29964
30763
|
const models = buildAnthropicModelList(exposedModels).data.filter((model) => /^(claude|anthropic)/i.test(model.id)).map((model) => ({ id: model.id, display_name: model.display_name }));
|
|
29965
30764
|
fs9__default.mkdirSync(cacheDir, { recursive: true, mode: 448 });
|
|
29966
30765
|
writeAtomicSync(cachePath, JSON.stringify({ baseUrl, fetchedAt: Date.now(), models }), { mode: 384 });
|
|
@@ -30249,7 +31048,7 @@ async function resolveLoadout(deps) {
|
|
|
30249
31048
|
}
|
|
30250
31049
|
|
|
30251
31050
|
// ../../packages/fleet-admiral/src/ai-gateway/quota-snapshot.ts
|
|
30252
|
-
function
|
|
31051
|
+
function record4(value) {
|
|
30253
31052
|
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
30254
31053
|
}
|
|
30255
31054
|
var AMOUNT_PATTERN = /^\d{1,15}$/;
|
|
@@ -30257,7 +31056,7 @@ var MAX_WINDOW_DURATION_MS2 = 400 * 24 * 36e5;
|
|
|
30257
31056
|
var DURATION_BASES = /* @__PURE__ */ new Set(["upstream", "catalog"]);
|
|
30258
31057
|
var START_BASES = /* @__PURE__ */ new Set(["upstream", "derived"]);
|
|
30259
31058
|
function toWindowPeriod(value) {
|
|
30260
|
-
const period =
|
|
31059
|
+
const period = record4(value);
|
|
30261
31060
|
if (!period) return void 0;
|
|
30262
31061
|
const durationMs = period.durationMs;
|
|
30263
31062
|
const durationBasis = period.durationBasis;
|
|
@@ -30274,7 +31073,7 @@ function toWindowPeriod(value) {
|
|
|
30274
31073
|
};
|
|
30275
31074
|
}
|
|
30276
31075
|
function toWindowAmounts(value) {
|
|
30277
|
-
const amounts =
|
|
31076
|
+
const amounts = record4(value);
|
|
30278
31077
|
if (!amounts) return void 0;
|
|
30279
31078
|
const used = amounts.used;
|
|
30280
31079
|
const limit = amounts.limit;
|
|
@@ -30283,14 +31082,14 @@ function toWindowAmounts(value) {
|
|
|
30283
31082
|
return { used, limit };
|
|
30284
31083
|
}
|
|
30285
31084
|
function parseGatewayQuotaSnapshot(value) {
|
|
30286
|
-
const providers =
|
|
31085
|
+
const providers = record4(record4(value)?.providers);
|
|
30287
31086
|
if (!providers) return void 0;
|
|
30288
31087
|
const snapshot = {};
|
|
30289
31088
|
for (const [id, value2] of Object.entries(providers)) {
|
|
30290
|
-
const provider =
|
|
31089
|
+
const provider = record4(value2);
|
|
30291
31090
|
if (!provider || typeof provider.status !== "string") continue;
|
|
30292
31091
|
const windows = Array.isArray(provider.windows) ? provider.windows.flatMap((entry) => {
|
|
30293
|
-
const window =
|
|
31092
|
+
const window = record4(entry);
|
|
30294
31093
|
if (!window || typeof window.id !== "string" || typeof window.usedPercent !== "number") return [];
|
|
30295
31094
|
const period = toWindowPeriod(window.period);
|
|
30296
31095
|
const amounts = toWindowAmounts(window.amounts);
|
|
@@ -30358,7 +31157,7 @@ function createChildEnv(env, overlay) {
|
|
|
30358
31157
|
return child;
|
|
30359
31158
|
}
|
|
30360
31159
|
function wrapWindowsShim(resolved, env, platform) {
|
|
30361
|
-
if (platform !== "win32" || !WINDOWS_SHIM_EXTENSIONS.has(
|
|
31160
|
+
if (platform !== "win32" || !WINDOWS_SHIM_EXTENSIONS.has(path19__default.extname(resolved).toLowerCase())) {
|
|
30362
31161
|
return { bin: resolved, prefixArgs: [] };
|
|
30363
31162
|
}
|
|
30364
31163
|
rejectCmdExpansionSensitiveShim(resolved);
|
|
@@ -30376,13 +31175,13 @@ function forceWindowsArgQuoting(value) {
|
|
|
30376
31175
|
return `${value} `;
|
|
30377
31176
|
}
|
|
30378
31177
|
function findOnPath(bin, pathValue, pathExts, platform) {
|
|
30379
|
-
const pathSeparator = platform === "win32" ? WINDOWS_PATH_SEPARATOR :
|
|
30380
|
-
if (hasPathSeparator(bin, platform) ||
|
|
31178
|
+
const pathSeparator = platform === "win32" ? WINDOWS_PATH_SEPARATOR : path19__default.delimiter;
|
|
31179
|
+
if (hasPathSeparator(bin, platform) || path19__default.isAbsolute(bin)) {
|
|
30381
31180
|
return resolveWithExtensions(bin, pathExts, platform);
|
|
30382
31181
|
}
|
|
30383
31182
|
for (const entry of pathValue.split(pathSeparator)) {
|
|
30384
31183
|
const searchDir = entry.length === 0 ? "." : entry;
|
|
30385
|
-
const candidate = resolveWithExtensions(
|
|
31184
|
+
const candidate = resolveWithExtensions(path19__default.join(searchDir, bin), pathExts, platform);
|
|
30386
31185
|
if (candidate) {
|
|
30387
31186
|
return candidate;
|
|
30388
31187
|
}
|
|
@@ -30390,7 +31189,7 @@ function findOnPath(bin, pathValue, pathExts, platform) {
|
|
|
30390
31189
|
return void 0;
|
|
30391
31190
|
}
|
|
30392
31191
|
function resolveWithExtensions(candidate, pathExts, platform) {
|
|
30393
|
-
if (platform !== "win32" ||
|
|
31192
|
+
if (platform !== "win32" || path19__default.extname(candidate).length > 0) {
|
|
30394
31193
|
return isAccessibleExecutable(candidate, platform) ? candidate : void 0;
|
|
30395
31194
|
}
|
|
30396
31195
|
for (const ext of pathExts) {
|
|
@@ -30436,7 +31235,6 @@ function createClaudeFamilyCliDefinition(options) {
|
|
|
30436
31235
|
async createProfile(profileOptions) {
|
|
30437
31236
|
const { bin, prefixArgs } = resolveBinary("claude", "CLAUDE_BIN", profileOptions.env);
|
|
30438
31237
|
const launchPrompt = sanitizeLaunchPrompt(profileOptions.prompt);
|
|
30439
|
-
assertLaunchPromptShimSafe(launchPrompt, prefixArgs);
|
|
30440
31238
|
const commandLineLimit = resolveLaunchCommandLineLimit(prefixArgs);
|
|
30441
31239
|
const childEnv = createChildEnv(profileOptions.env, {});
|
|
30442
31240
|
return {
|
|
@@ -30632,9 +31430,9 @@ function writePrivateJson(filePath, value, rootBase) {
|
|
|
30632
31430
|
function writePrivateFile(filePath, content, rootBase) {
|
|
30633
31431
|
const resolvedBase = ensureRootBase(rootBase);
|
|
30634
31432
|
ensurePathWithinRoot(resolvedBase, filePath);
|
|
30635
|
-
ensureDirectorySegments(resolvedBase,
|
|
31433
|
+
ensureDirectorySegments(resolvedBase, path19__default.dirname(filePath));
|
|
30636
31434
|
writeFileNoFollow(filePath, content);
|
|
30637
|
-
|
|
31435
|
+
chmodBestEffort2(filePath, FILE_MODE);
|
|
30638
31436
|
}
|
|
30639
31437
|
function removePrivatePath(targetPath, rootBase) {
|
|
30640
31438
|
const resolvedBase = assertRootBaseSafe(rootBase);
|
|
@@ -30662,7 +31460,7 @@ function cleanupPrivateRoot(rootPath, rootBase) {
|
|
|
30662
31460
|
throw error51;
|
|
30663
31461
|
}
|
|
30664
31462
|
}
|
|
30665
|
-
function
|
|
31463
|
+
function chmodBestEffort2(targetPath, mode) {
|
|
30666
31464
|
try {
|
|
30667
31465
|
chmodSync(targetPath, mode);
|
|
30668
31466
|
} catch (_error) {
|
|
@@ -30679,20 +31477,20 @@ function writeFileNoFollow(filePath, content) {
|
|
|
30679
31477
|
}
|
|
30680
31478
|
}
|
|
30681
31479
|
function ensureRootBase(rootBase) {
|
|
30682
|
-
const resolvedBase =
|
|
30683
|
-
const anchor = findExistingDirectoryAnchor(
|
|
31480
|
+
const resolvedBase = path19__default.resolve(rootBase);
|
|
31481
|
+
const anchor = findExistingDirectoryAnchor(path19__default.dirname(resolvedBase));
|
|
30684
31482
|
ensureDirectorySegments(anchor, resolvedBase);
|
|
30685
31483
|
assertDirectorySafe(resolvedBase, "Plugin root base");
|
|
30686
31484
|
return resolvedBase;
|
|
30687
31485
|
}
|
|
30688
31486
|
function assertRootBaseSafe(rootBase) {
|
|
30689
|
-
const resolvedBase =
|
|
30690
|
-
assertExistingSegmentsSafe(findExistingDirectoryAnchor(
|
|
31487
|
+
const resolvedBase = path19__default.resolve(rootBase);
|
|
31488
|
+
assertExistingSegmentsSafe(findExistingDirectoryAnchor(path19__default.dirname(resolvedBase)), resolvedBase);
|
|
30691
31489
|
assertDirectorySafe(resolvedBase, "Plugin root base");
|
|
30692
31490
|
return resolvedBase;
|
|
30693
31491
|
}
|
|
30694
31492
|
function findExistingDirectoryAnchor(targetPath) {
|
|
30695
|
-
const resolvedTarget =
|
|
31493
|
+
const resolvedTarget = path19__default.resolve(targetPath);
|
|
30696
31494
|
let current = resolvedTarget;
|
|
30697
31495
|
while (true) {
|
|
30698
31496
|
try {
|
|
@@ -30700,7 +31498,7 @@ function findExistingDirectoryAnchor(targetPath) {
|
|
|
30700
31498
|
return current;
|
|
30701
31499
|
} catch (error51) {
|
|
30702
31500
|
if (error51 instanceof Error && "code" in error51 && error51.code === "ENOENT") {
|
|
30703
|
-
const parent =
|
|
31501
|
+
const parent = path19__default.dirname(current);
|
|
30704
31502
|
if (parent === current) throw error51;
|
|
30705
31503
|
current = parent;
|
|
30706
31504
|
continue;
|
|
@@ -30719,17 +31517,17 @@ function assertDirectorySafe(dirPath, label) {
|
|
|
30719
31517
|
}
|
|
30720
31518
|
}
|
|
30721
31519
|
function ensurePathWithinRoot(resolvedBase, candidatePath) {
|
|
30722
|
-
const resolvedCandidate =
|
|
30723
|
-
const relative =
|
|
30724
|
-
if (relative === "" || !relative.startsWith("..") && !
|
|
31520
|
+
const resolvedCandidate = path19__default.resolve(candidatePath);
|
|
31521
|
+
const relative = path19__default.relative(resolvedBase, resolvedCandidate);
|
|
31522
|
+
if (relative === "" || !relative.startsWith("..") && !path19__default.isAbsolute(relative)) return;
|
|
30725
31523
|
throw new Error(`Plugin path escapes root base: ${candidatePath}`);
|
|
30726
31524
|
}
|
|
30727
31525
|
function ensureDirectorySegments(resolvedBase, dirPath) {
|
|
30728
|
-
const target2 =
|
|
30729
|
-
const relative =
|
|
31526
|
+
const target2 = path19__default.resolve(dirPath);
|
|
31527
|
+
const relative = path19__default.relative(resolvedBase, target2);
|
|
30730
31528
|
let current = resolvedBase;
|
|
30731
|
-
for (const segment of relative.split(
|
|
30732
|
-
current =
|
|
31529
|
+
for (const segment of relative.split(path19__default.sep).filter(Boolean)) {
|
|
31530
|
+
current = path19__default.join(current, segment);
|
|
30733
31531
|
try {
|
|
30734
31532
|
const stat4 = lstatSync(current);
|
|
30735
31533
|
if (stat4.isSymbolicLink()) {
|
|
@@ -30741,7 +31539,7 @@ function ensureDirectorySegments(resolvedBase, dirPath) {
|
|
|
30741
31539
|
} catch (error51) {
|
|
30742
31540
|
if (error51 instanceof Error && "code" in error51 && error51.code === "ENOENT") {
|
|
30743
31541
|
mkdirSync(current, { mode: DIR_MODE });
|
|
30744
|
-
|
|
31542
|
+
chmodBestEffort2(current, DIR_MODE);
|
|
30745
31543
|
} else {
|
|
30746
31544
|
throw error51;
|
|
30747
31545
|
}
|
|
@@ -30750,11 +31548,11 @@ function ensureDirectorySegments(resolvedBase, dirPath) {
|
|
|
30750
31548
|
}
|
|
30751
31549
|
}
|
|
30752
31550
|
function assertExistingSegmentsSafe(resolvedBase, targetPath) {
|
|
30753
|
-
const target2 =
|
|
30754
|
-
const relative =
|
|
31551
|
+
const target2 = path19__default.resolve(targetPath);
|
|
31552
|
+
const relative = path19__default.relative(resolvedBase, target2);
|
|
30755
31553
|
let current = resolvedBase;
|
|
30756
|
-
for (const segment of relative.split(
|
|
30757
|
-
current =
|
|
31554
|
+
for (const segment of relative.split(path19__default.sep).filter(Boolean)) {
|
|
31555
|
+
current = path19__default.join(current, segment);
|
|
30758
31556
|
const stat4 = lstatSync(current);
|
|
30759
31557
|
if (stat4.isSymbolicLink()) {
|
|
30760
31558
|
throw new Error(`Plugin path segment is a symlink: ${current}`);
|
|
@@ -30766,13 +31564,13 @@ function assertExistingSegmentsSafe(resolvedBase, targetPath) {
|
|
|
30766
31564
|
}
|
|
30767
31565
|
}
|
|
30768
31566
|
function assertExistingParentSegmentsSafe(resolvedBase, targetPath) {
|
|
30769
|
-
assertExistingSegmentsSafe(resolvedBase,
|
|
31567
|
+
assertExistingSegmentsSafe(resolvedBase, path19__default.dirname(targetPath));
|
|
30770
31568
|
}
|
|
30771
31569
|
function assertSegmentRealpathWithinRoot(resolvedBase, segmentPath) {
|
|
30772
31570
|
const baseRealpath = realpathSync(resolvedBase);
|
|
30773
31571
|
const segmentRealpath = realpathSync(segmentPath);
|
|
30774
|
-
const relative =
|
|
30775
|
-
if (relative === "" || !relative.startsWith("..") && !
|
|
31572
|
+
const relative = path19__default.relative(baseRealpath, segmentRealpath);
|
|
31573
|
+
if (relative === "" || !relative.startsWith("..") && !path19__default.isAbsolute(relative)) return;
|
|
30776
31574
|
throw new Error(`Plugin path segment escapes root base: ${segmentPath}`);
|
|
30777
31575
|
}
|
|
30778
31576
|
|
|
@@ -30792,18 +31590,18 @@ function renderAssetPluginRoot(pluginRoot, bundle, options) {
|
|
|
30792
31590
|
options.doctrine ?? resolveDoctrineFromCliId(options.cliId);
|
|
30793
31591
|
renderEmbeddedSkillAssets(pluginRoot);
|
|
30794
31592
|
const workflowGuardScriptPath = writeWorkflowGuardScript(pluginRoot);
|
|
30795
|
-
writePrivateJson(
|
|
31593
|
+
writePrivateJson(path19__default.join(pluginRoot, "hooks", "hooks.json"), claudeHooks(options, workflowGuardScriptPath), pluginRoot);
|
|
30796
31594
|
renderGatewayAgentAssets(pluginRoot, options);
|
|
30797
31595
|
}
|
|
30798
31596
|
function renderGatewayAgentAssets(pluginRoot, options) {
|
|
30799
31597
|
for (const file2 of buildGatewayAgentFiles(options.gatewayDelegationModels ?? [], options.gatewayEffortExposure)) {
|
|
30800
|
-
writePrivateFile(
|
|
31598
|
+
writePrivateFile(path19__default.join(pluginRoot, "agents", file2.fileName), file2.content, pluginRoot);
|
|
30801
31599
|
}
|
|
30802
31600
|
}
|
|
30803
31601
|
function writeWorkflowGuardScript(pluginRoot) {
|
|
30804
31602
|
const asset = EMBEDDED_AGENT_CLI_HOOK_ASSETS.find((entry) => entry.relativePath === "workflow-guard.mjs");
|
|
30805
31603
|
if (!asset) throw new Error("Missing embedded workflow-guard hook asset");
|
|
30806
|
-
const scriptPath =
|
|
31604
|
+
const scriptPath = path19__default.join(pluginRoot, "hooks", "workflow-guard.mjs");
|
|
30807
31605
|
writePrivateFile(scriptPath, asset.content, pluginRoot);
|
|
30808
31606
|
return scriptPath;
|
|
30809
31607
|
}
|
|
@@ -30862,7 +31660,7 @@ function claudeCommandHook(hookExec) {
|
|
|
30862
31660
|
}
|
|
30863
31661
|
function renderEmbeddedSkillAssets(pluginRoot, doctrine) {
|
|
30864
31662
|
for (const asset of selectSkillAssetsForDoctrine()) {
|
|
30865
|
-
writePrivateFile(
|
|
31663
|
+
writePrivateFile(path19__default.join(pluginRoot, "skills", asset.relativePath), asset.content, pluginRoot);
|
|
30866
31664
|
}
|
|
30867
31665
|
}
|
|
30868
31666
|
function selectSkillAssetsForDoctrine(_doctrine) {
|
|
@@ -30939,7 +31737,7 @@ function resolveRenderablePluginBundles(fleetRoot, options) {
|
|
|
30939
31737
|
function homeMarketplaceTarget(fleetRoot) {
|
|
30940
31738
|
return {
|
|
30941
31739
|
name: FLEET_MARKETPLACE_NAME,
|
|
30942
|
-
root:
|
|
31740
|
+
root: path19__default.join(fleetRoot, MARKETPLACE_DIR_NAME)
|
|
30943
31741
|
};
|
|
30944
31742
|
}
|
|
30945
31743
|
function groupRenderableBundlesByMarketplace(bundles) {
|
|
@@ -30955,17 +31753,17 @@ function groupRenderableBundlesByMarketplace(bundles) {
|
|
|
30955
31753
|
return groups;
|
|
30956
31754
|
}
|
|
30957
31755
|
function renderPluginRoot(pluginRoot, bundle, options) {
|
|
30958
|
-
const parentRoot =
|
|
31756
|
+
const parentRoot = path19__default.dirname(pluginRoot);
|
|
30959
31757
|
ensurePrivateDir(parentRoot, parentRoot);
|
|
30960
31758
|
const stageParent = createStagingDir(parentRoot);
|
|
30961
|
-
const stagedPluginRoot =
|
|
31759
|
+
const stagedPluginRoot = path19__default.join(stageParent, path19__default.basename(pluginRoot));
|
|
30962
31760
|
try {
|
|
30963
31761
|
ensurePrivateDir(stagedPluginRoot, stagedPluginRoot);
|
|
30964
|
-
writePrivateJson(
|
|
31762
|
+
writePrivateJson(path19__default.join(stagedPluginRoot, ".claude-plugin", "plugin.json"), claudeManifest(bundle), stagedPluginRoot);
|
|
30965
31763
|
switch (bundle.source) {
|
|
30966
31764
|
case "asset":
|
|
30967
|
-
ensurePrivateDir(
|
|
30968
|
-
ensurePrivateDir(
|
|
31765
|
+
ensurePrivateDir(path19__default.join(stagedPluginRoot, "agents"), stagedPluginRoot);
|
|
31766
|
+
ensurePrivateDir(path19__default.join(stagedPluginRoot, "skills"), stagedPluginRoot);
|
|
30969
31767
|
renderAssetPluginRoot(stagedPluginRoot, bundle, options);
|
|
30970
31768
|
break;
|
|
30971
31769
|
}
|
|
@@ -30980,11 +31778,11 @@ function renderMarketplaceRoot(target2, bundles) {
|
|
|
30980
31778
|
ensurePrivateDir(marketplaceRoot, marketplaceRoot);
|
|
30981
31779
|
const stagedRoot = createStagingDir(marketplaceRoot);
|
|
30982
31780
|
try {
|
|
30983
|
-
writePrivateJson(
|
|
31781
|
+
writePrivateJson(path19__default.join(stagedRoot, ".claude-plugin", "marketplace.json"), claudeMarketplace(target2, bundles), stagedRoot);
|
|
30984
31782
|
pruneMarketplaceRoot(target2);
|
|
30985
31783
|
pruneStalePluginDirs(target2, bundles);
|
|
30986
31784
|
for (const entry of readdirSync(stagedRoot)) {
|
|
30987
|
-
renameSync(
|
|
31785
|
+
renameSync(path19__default.join(stagedRoot, entry), path19__default.join(marketplaceRoot, entry));
|
|
30988
31786
|
}
|
|
30989
31787
|
} finally {
|
|
30990
31788
|
cleanupPrivateRoot(stagedRoot, marketplaceRoot);
|
|
@@ -30992,11 +31790,11 @@ function renderMarketplaceRoot(target2, bundles) {
|
|
|
30992
31790
|
}
|
|
30993
31791
|
function pruneMarketplaceRoot(target2) {
|
|
30994
31792
|
for (const entry of MARKETPLACE_PRUNE_ENTRIES) {
|
|
30995
|
-
removePrivatePath(
|
|
31793
|
+
removePrivatePath(path19__default.join(target2.root, entry), target2.root);
|
|
30996
31794
|
}
|
|
30997
31795
|
}
|
|
30998
31796
|
function pruneStalePluginDirs(target2, bundles) {
|
|
30999
|
-
const pluginsDir =
|
|
31797
|
+
const pluginsDir = path19__default.join(target2.root, PLUGIN_BUNDLES_DIR_NAME);
|
|
31000
31798
|
if (!existsSync(pluginsDir)) return;
|
|
31001
31799
|
const activeDirectoryNames = /* @__PURE__ */ new Set();
|
|
31002
31800
|
for (const bundle of bundles) {
|
|
@@ -31010,11 +31808,11 @@ function pruneStalePluginDirs(target2, bundles) {
|
|
|
31010
31808
|
}
|
|
31011
31809
|
for (const entry of readdirSync(pluginsDir)) {
|
|
31012
31810
|
if (activeDirectoryNames.has(entry)) continue;
|
|
31013
|
-
removePrivatePath(
|
|
31811
|
+
removePrivatePath(path19__default.join(pluginsDir, entry), target2.root);
|
|
31014
31812
|
}
|
|
31015
31813
|
}
|
|
31016
31814
|
function createStagingDir(rootPath) {
|
|
31017
|
-
const stageRoot = mkdtempSync(
|
|
31815
|
+
const stageRoot = mkdtempSync(path19__default.join(rootPath, `.fleet-stage-${process.pid}-${Date.now()}-`));
|
|
31018
31816
|
return stageRoot;
|
|
31019
31817
|
}
|
|
31020
31818
|
function claudeMarketplace(target2, bundles) {
|
|
@@ -31036,7 +31834,7 @@ function claudeMarketplace(target2, bundles) {
|
|
|
31036
31834
|
};
|
|
31037
31835
|
}
|
|
31038
31836
|
function pluginRootForTarget(target2, bundle) {
|
|
31039
|
-
return
|
|
31837
|
+
return path19__default.join(target2.root, PLUGIN_BUNDLES_DIR_NAME, bundle.directoryName);
|
|
31040
31838
|
}
|
|
31041
31839
|
function marketplacePluginPath(target2, bundle) {
|
|
31042
31840
|
return `./${PLUGIN_BUNDLES_DIR_NAME}/${bundle.directoryName}`;
|
|
@@ -31067,6 +31865,22 @@ async function injectAgentCliProfile(profile, options) {
|
|
|
31067
31865
|
const tempCleanups = [];
|
|
31068
31866
|
try {
|
|
31069
31867
|
const systemPromptFile = systemPromptMode === "off" ? void 0 : writeSystemPromptFile(profile.id, options.buildSystemPrompt(), (cleanup2) => tempCleanups.push(cleanup2));
|
|
31868
|
+
let promptArgs = [...profile.promptArgs ?? []];
|
|
31869
|
+
let deliveredViaFile = false;
|
|
31870
|
+
const cmdWrapped = profile.commandLineLimit?.via === "cmd-shim";
|
|
31871
|
+
const windowsLaunch = profile.commandLineLimit !== void 0;
|
|
31872
|
+
const convertPromptToFile = (body) => {
|
|
31873
|
+
promptArgs = [writeLaunchPromptPointer(
|
|
31874
|
+
body,
|
|
31875
|
+
(cleanupFn) => tempCleanups.push(cleanupFn),
|
|
31876
|
+
cmdWrapped
|
|
31877
|
+
)];
|
|
31878
|
+
deliveredViaFile = true;
|
|
31879
|
+
};
|
|
31880
|
+
if (promptArgs.length > 0 && windowsLaunch) {
|
|
31881
|
+
const body = takeLaunchPromptBody(promptArgs);
|
|
31882
|
+
if (launchPromptHasCmdUnsafeChars(body)) convertPromptToFile(body);
|
|
31883
|
+
}
|
|
31070
31884
|
const plugin = await createAgentCliPlugin({
|
|
31071
31885
|
cliId: profile.id,
|
|
31072
31886
|
doctrine,
|
|
@@ -31103,26 +31917,39 @@ async function injectAgentCliProfile(profile, options) {
|
|
|
31103
31917
|
systemPromptFile
|
|
31104
31918
|
};
|
|
31105
31919
|
const injectedArgs = buildAgentCliArgs(capability2.builderId, context);
|
|
31106
|
-
const
|
|
31920
|
+
const mergeArgs = (nextPromptArgs) => mergeAgentCliArgs(
|
|
31921
|
+
{ ...profile, promptArgs: nextPromptArgs },
|
|
31922
|
+
capability2.builderId,
|
|
31923
|
+
context,
|
|
31924
|
+
injectedArgs
|
|
31925
|
+
);
|
|
31926
|
+
const argsWithoutPrompt = mergeArgs([]);
|
|
31927
|
+
const checkBudget = () => assertLaunchCommandLineBudget({
|
|
31928
|
+
args: mergeArgs(promptArgs),
|
|
31929
|
+
argsWithoutPrompt,
|
|
31930
|
+
bin: profile.bin,
|
|
31931
|
+
limit: profile.commandLineLimit,
|
|
31932
|
+
promptIsFixedLength: deliveredViaFile
|
|
31933
|
+
});
|
|
31107
31934
|
try {
|
|
31108
|
-
|
|
31109
|
-
args: mergedArgs,
|
|
31110
|
-
argsWithoutPrompt: mergeAgentCliArgs(
|
|
31111
|
-
{ ...profile, promptArgs: [] },
|
|
31112
|
-
capability2.builderId,
|
|
31113
|
-
context,
|
|
31114
|
-
injectedArgs
|
|
31115
|
-
),
|
|
31116
|
-
bin: profile.bin,
|
|
31117
|
-
limit: profile.commandLineLimit
|
|
31118
|
-
});
|
|
31935
|
+
checkBudget();
|
|
31119
31936
|
} catch (error51) {
|
|
31120
|
-
|
|
31121
|
-
|
|
31937
|
+
const canMoveToFile = !deliveredViaFile && windowsLaunch && promptArgs.length === 1 && error51 instanceof LaunchPromptError && error51.code === "prompt_command_line_too_long";
|
|
31938
|
+
if (!canMoveToFile) {
|
|
31939
|
+
cleanup();
|
|
31940
|
+
throw error51;
|
|
31941
|
+
}
|
|
31942
|
+
convertPromptToFile(takeLaunchPromptBody(promptArgs));
|
|
31943
|
+
try {
|
|
31944
|
+
checkBudget();
|
|
31945
|
+
} catch (retryError) {
|
|
31946
|
+
cleanup();
|
|
31947
|
+
throw retryError;
|
|
31948
|
+
}
|
|
31122
31949
|
}
|
|
31123
31950
|
return {
|
|
31124
31951
|
...profile,
|
|
31125
|
-
args:
|
|
31952
|
+
args: mergeArgs(promptArgs),
|
|
31126
31953
|
// 위치 인자는 이미 args 끝에 합쳐졌으므로 비운다. 남겨 두면 하류가 한 번 더 붙일 수 있다.
|
|
31127
31954
|
promptArgs: [],
|
|
31128
31955
|
cleanup
|
|
@@ -31148,21 +31975,27 @@ function buildAgentCliMcpServerConfigs(endpoints, tokens) {
|
|
|
31148
31975
|
};
|
|
31149
31976
|
});
|
|
31150
31977
|
}
|
|
31978
|
+
function takeLaunchPromptBody(promptArgs) {
|
|
31979
|
+
if (promptArgs.length !== 1) {
|
|
31980
|
+
throw new Error(`Launch prompt file conversion expects a single positional prompt, got ${promptArgs.length}`);
|
|
31981
|
+
}
|
|
31982
|
+
return promptArgs[0];
|
|
31983
|
+
}
|
|
31151
31984
|
function writeSystemPromptFile(cliId, systemPrompt, onCleanup) {
|
|
31152
|
-
const tempDir = mkdtempSync(
|
|
31153
|
-
onCleanup(() =>
|
|
31154
|
-
const filePath =
|
|
31985
|
+
const tempDir = mkdtempSync(path19__default.join(os3__default.tmpdir(), `fleet-${cliId}-`));
|
|
31986
|
+
onCleanup(() => rmBestEffort2(tempDir));
|
|
31987
|
+
const filePath = path19__default.join(tempDir, "system-prompt.md");
|
|
31155
31988
|
writeFileSync(filePath, systemPrompt, { encoding: "utf8", flag: "wx", mode: SYSTEM_PROMPT_FILE_MODE });
|
|
31156
|
-
|
|
31989
|
+
chmodBestEffort3(filePath, SYSTEM_PROMPT_FILE_MODE);
|
|
31157
31990
|
return filePath;
|
|
31158
31991
|
}
|
|
31159
|
-
function
|
|
31992
|
+
function chmodBestEffort3(targetPath, mode) {
|
|
31160
31993
|
try {
|
|
31161
31994
|
chmodSync(targetPath, mode);
|
|
31162
31995
|
} catch {
|
|
31163
31996
|
}
|
|
31164
31997
|
}
|
|
31165
|
-
function
|
|
31998
|
+
function rmBestEffort2(targetPath) {
|
|
31166
31999
|
try {
|
|
31167
32000
|
rmSync(targetPath, { force: true, recursive: true });
|
|
31168
32001
|
} catch {
|
|
@@ -32323,18 +33156,18 @@ Always read \`schema/wiki-schema.md\` directly before composing or revising entr
|
|
|
32323
33156
|
`;
|
|
32324
33157
|
async function ensureWorkspaceSchema(paths) {
|
|
32325
33158
|
await mkdir(paths.schemaDir, { recursive: true });
|
|
32326
|
-
await writeDefaultFileIfMissing(
|
|
32327
|
-
await writeDefaultFileIfMissing(
|
|
33159
|
+
await writeDefaultFileIfMissing(path19__default.join(paths.schemaDir, WORKSPACE_SCHEMA_AGENTS_FILENAME), DEFAULT_WORKSPACE_SCHEMA_AGENTS);
|
|
33160
|
+
await writeDefaultFileIfMissing(path19__default.join(paths.schemaDir, WORKSPACE_SCHEMA_FILENAME), DEFAULT_WORKSPACE_WIKI_SCHEMA);
|
|
32328
33161
|
await writeDefaultFileIfMissing(buildTemplatePath(paths, "prd"), DEFAULT_TEMPLATE_PRD);
|
|
32329
33162
|
return readWorkspaceSchemaSummary(paths);
|
|
32330
33163
|
}
|
|
32331
33164
|
async function ensureWorkspaceDoctrine(paths) {
|
|
32332
33165
|
await mkdir(paths.root, { recursive: true });
|
|
32333
|
-
await writeDefaultFileIfMissing(
|
|
33166
|
+
await writeDefaultFileIfMissing(path19__default.join(paths.root, WORKSPACE_KNOWLEDGE_AGENTS_FILENAME), DEFAULT_WORKSPACE_KNOWLEDGE_AGENTS);
|
|
32334
33167
|
}
|
|
32335
33168
|
async function readWorkspaceSchemaSummary(paths) {
|
|
32336
|
-
const agentsPath =
|
|
32337
|
-
const wikiSchemaPath =
|
|
33169
|
+
const agentsPath = path19__default.join(paths.schemaDir, WORKSPACE_SCHEMA_AGENTS_FILENAME);
|
|
33170
|
+
const wikiSchemaPath = path19__default.join(paths.schemaDir, WORKSPACE_SCHEMA_FILENAME);
|
|
32338
33171
|
const wikiSchemaContent = await tryReadSchemaFile(paths, wikiSchemaPath);
|
|
32339
33172
|
const templates = await scanTemplates(paths);
|
|
32340
33173
|
if (wikiSchemaContent === null) {
|
|
@@ -32373,7 +33206,7 @@ async function scanTemplates(paths) {
|
|
|
32373
33206
|
if (!entry.name.startsWith(WORKSPACE_TEMPLATE_PREFIX) || !entry.name.endsWith(WORKSPACE_TEMPLATE_SUFFIX)) continue;
|
|
32374
33207
|
const id = entry.name.slice(WORKSPACE_TEMPLATE_PREFIX.length, -WORKSPACE_TEMPLATE_SUFFIX.length);
|
|
32375
33208
|
if (!TEMPLATE_ID_PATTERN.test(id)) continue;
|
|
32376
|
-
const filePath =
|
|
33209
|
+
const filePath = path19__default.join(paths.schemaDir, entry.name);
|
|
32377
33210
|
try {
|
|
32378
33211
|
const parsed = parseTemplateMarkdown(await readFile(filePath, "utf8"));
|
|
32379
33212
|
templates.push({
|
|
@@ -32405,7 +33238,7 @@ async function readSchemaCatalog(paths) {
|
|
|
32405
33238
|
}
|
|
32406
33239
|
async function readSchemaDocument(paths, resource, templateId) {
|
|
32407
33240
|
const ref = resource === "schema" ? "schema/wiki-schema.md" : schemaTemplateRef(templateId ?? "");
|
|
32408
|
-
const absolute =
|
|
33241
|
+
const absolute = path19__default.resolve(paths.root, ref);
|
|
32409
33242
|
await assertContainedSchemaFile(paths, absolute, false);
|
|
32410
33243
|
return { ref, content: await readFile(absolute, "utf8") };
|
|
32411
33244
|
}
|
|
@@ -32430,10 +33263,10 @@ async function validateSchemaTemplateCreate(paths, templateId, markdown) {
|
|
|
32430
33263
|
if (folded.has(key)) throw new Error(`schema template contains duplicate ## section: ${section}`);
|
|
32431
33264
|
folded.add(key);
|
|
32432
33265
|
}
|
|
32433
|
-
const absolute =
|
|
33266
|
+
const absolute = path19__default.resolve(paths.root, ref);
|
|
32434
33267
|
await assertContainedSchemaFile(paths, absolute, true);
|
|
32435
33268
|
const entries = await readdir(paths.schemaDir).catch(() => []);
|
|
32436
|
-
const basename =
|
|
33269
|
+
const basename = path19__default.basename(absolute).toLocaleLowerCase("en-US");
|
|
32437
33270
|
if (entries.some((entry) => entry.toLocaleLowerCase("en-US") === basename)) throw new Error("schema template target already exists");
|
|
32438
33271
|
return absolute;
|
|
32439
33272
|
}
|
|
@@ -32441,13 +33274,13 @@ function assertTemplateId(id) {
|
|
|
32441
33274
|
if (!TEMPLATE_ID_PATTERN.test(id)) throw new Error("template_id must match /^[a-z][a-z0-9-]{0,63}$/");
|
|
32442
33275
|
}
|
|
32443
33276
|
async function assertContainedSchemaFile(paths, absolute, allowMissing) {
|
|
32444
|
-
const schemaReal = await realpath(paths.schemaDir).catch(() =>
|
|
32445
|
-
const parentReal = await realpath(
|
|
33277
|
+
const schemaReal = await realpath(paths.schemaDir).catch(() => path19__default.resolve(paths.schemaDir));
|
|
33278
|
+
const parentReal = await realpath(path19__default.dirname(absolute)).catch(() => path19__default.resolve(path19__default.dirname(absolute)));
|
|
32446
33279
|
if (parentReal !== schemaReal) throw new Error("schema resource escapes schema directory");
|
|
32447
|
-
const relative =
|
|
33280
|
+
const relative = path19__default.relative(paths.root, absolute);
|
|
32448
33281
|
let cursor = paths.root;
|
|
32449
|
-
for (const part of relative.split(
|
|
32450
|
-
cursor =
|
|
33282
|
+
for (const part of relative.split(path19__default.sep)) {
|
|
33283
|
+
cursor = path19__default.join(cursor, part);
|
|
32451
33284
|
try {
|
|
32452
33285
|
if ((await lstat(cursor)).isSymbolicLink()) throw new Error("schema resource path contains symlink");
|
|
32453
33286
|
} catch (error51) {
|
|
@@ -32475,7 +33308,7 @@ async function validateTemplateCompliance(paths, templateId, body) {
|
|
|
32475
33308
|
}
|
|
32476
33309
|
}
|
|
32477
33310
|
function inferTemplateIdFromTarget(target2, knownTemplateIds) {
|
|
32478
|
-
const basename =
|
|
33311
|
+
const basename = path19__default.basename(target2, ".md");
|
|
32479
33312
|
const ids = knownTemplateIds ?? DEFAULT_TEMPLATE_IDS;
|
|
32480
33313
|
const sorted = [...ids].sort((a, b) => b.length - a.length);
|
|
32481
33314
|
for (const id of sorted) {
|
|
@@ -32507,7 +33340,7 @@ function extractSchemaSummary(content) {
|
|
|
32507
33340
|
return lines.find((line) => line.length > 0 && !line.startsWith("#")) ?? "Workspace schema is present.";
|
|
32508
33341
|
}
|
|
32509
33342
|
function buildTemplatePath(paths, id) {
|
|
32510
|
-
return
|
|
33343
|
+
return path19__default.join(paths.schemaDir, `${WORKSPACE_TEMPLATE_PREFIX}${id}${WORKSPACE_TEMPLATE_SUFFIX}`);
|
|
32511
33344
|
}
|
|
32512
33345
|
function parseTemplateMarkdown(content) {
|
|
32513
33346
|
const normalized = content.replace(/\r\n/g, "\n");
|
|
@@ -32612,18 +33445,18 @@ function isAlreadyExistsError(error51) {
|
|
|
32612
33445
|
|
|
32613
33446
|
// ../../packages/fleet-wiki/src/paths.ts
|
|
32614
33447
|
function resolveMemoryPaths(cwd) {
|
|
32615
|
-
return createMemoryPaths(
|
|
33448
|
+
return createMemoryPaths(path19__default.join(cwd, KNOWLEDGE_ROOT_DIRNAME));
|
|
32616
33449
|
}
|
|
32617
33450
|
function createMemoryPaths(root) {
|
|
32618
33451
|
return {
|
|
32619
33452
|
root,
|
|
32620
|
-
rawDir:
|
|
32621
|
-
wikiDir:
|
|
32622
|
-
schemaDir:
|
|
32623
|
-
queueDir:
|
|
32624
|
-
archiveDir:
|
|
32625
|
-
conflictsDir:
|
|
32626
|
-
indexFile:
|
|
33453
|
+
rawDir: path19__default.join(root, RAW_DIRNAME),
|
|
33454
|
+
wikiDir: path19__default.join(root, WIKI_DIRNAME),
|
|
33455
|
+
schemaDir: path19__default.join(root, SCHEMA_DIRNAME),
|
|
33456
|
+
queueDir: path19__default.join(root, QUEUE_DIRNAME),
|
|
33457
|
+
archiveDir: path19__default.join(root, ARCHIVE_DIRNAME),
|
|
33458
|
+
conflictsDir: path19__default.join(root, CONFLICTS_DIRNAME),
|
|
33459
|
+
indexFile: path19__default.join(root, INDEX_FILENAME)
|
|
32627
33460
|
};
|
|
32628
33461
|
}
|
|
32629
33462
|
function resolveToolMemoryPaths(ctx) {
|
|
@@ -32641,10 +33474,10 @@ async function ensureMemoryRoot(paths) {
|
|
|
32641
33474
|
await ensureWorkspaceDoctrine(paths);
|
|
32642
33475
|
}
|
|
32643
33476
|
function getIndexMarkdownFile(paths) {
|
|
32644
|
-
return
|
|
33477
|
+
return path19__default.join(paths.wikiDir, INDEX_MD_FILENAME);
|
|
32645
33478
|
}
|
|
32646
33479
|
function getLogFile(paths) {
|
|
32647
|
-
return
|
|
33480
|
+
return path19__default.join(paths.root, LOG_MD_FILENAME);
|
|
32648
33481
|
}
|
|
32649
33482
|
|
|
32650
33483
|
// ../../packages/fleet-wiki/src/conflicts.ts
|
|
@@ -32656,7 +33489,7 @@ async function createConflict(input, paths) {
|
|
|
32656
33489
|
await ensureMemoryRoot(paths);
|
|
32657
33490
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
32658
33491
|
const conflictId = buildConflictId(now, input.wikiId, input.reason, input.proposed);
|
|
32659
|
-
const conflictDir =
|
|
33492
|
+
const conflictDir = path19__default.join(paths.conflictsDir, conflictId);
|
|
32660
33493
|
await mkdir(conflictDir, { recursive: true });
|
|
32661
33494
|
const meta3 = {
|
|
32662
33495
|
id: conflictId,
|
|
@@ -32676,13 +33509,13 @@ async function createConflict(input, paths) {
|
|
|
32676
33509
|
currentHash: input.currentHash,
|
|
32677
33510
|
warnings: input.warnings
|
|
32678
33511
|
};
|
|
32679
|
-
await writeJsonFile(
|
|
32680
|
-
await writePatchFile(
|
|
33512
|
+
await writeJsonFile(path19__default.join(conflictDir, CONFLICT_META_FILENAME), meta3, paths);
|
|
33513
|
+
await writePatchFile(path19__default.join(conflictDir, CONFLICT_PROPOSED_FILENAME), input.proposed, paths);
|
|
32681
33514
|
if (input.current !== void 0) {
|
|
32682
|
-
await writePatchFile(
|
|
33515
|
+
await writePatchFile(path19__default.join(conflictDir, CONFLICT_CURRENT_FILENAME), input.current, paths);
|
|
32683
33516
|
}
|
|
32684
33517
|
if (input.rawSource !== void 0) {
|
|
32685
|
-
await writePatchFile(
|
|
33518
|
+
await writePatchFile(path19__default.join(conflictDir, CONFLICT_RAW_SOURCE_FILENAME), input.rawSource, paths);
|
|
32686
33519
|
}
|
|
32687
33520
|
return {
|
|
32688
33521
|
meta: meta3,
|
|
@@ -32696,7 +33529,7 @@ async function listConflicts(paths) {
|
|
|
32696
33529
|
const metas = [];
|
|
32697
33530
|
for (const id of ids) {
|
|
32698
33531
|
try {
|
|
32699
|
-
metas.push(await readJsonFile2(
|
|
33532
|
+
metas.push(await readJsonFile2(path19__default.join(paths.conflictsDir, id, CONFLICT_META_FILENAME)));
|
|
32700
33533
|
} catch {
|
|
32701
33534
|
continue;
|
|
32702
33535
|
}
|
|
@@ -32705,13 +33538,13 @@ async function listConflicts(paths) {
|
|
|
32705
33538
|
}
|
|
32706
33539
|
async function readConflict(conflictId, paths) {
|
|
32707
33540
|
const conflictDir = resolveConflictDir(conflictId, paths);
|
|
32708
|
-
const meta3 = await readJsonFile2(
|
|
32709
|
-
const currentPath =
|
|
32710
|
-
const rawSourcePath =
|
|
33541
|
+
const meta3 = await readJsonFile2(path19__default.join(conflictDir, CONFLICT_META_FILENAME));
|
|
33542
|
+
const currentPath = path19__default.join(conflictDir, CONFLICT_CURRENT_FILENAME);
|
|
33543
|
+
const rawSourcePath = path19__default.join(conflictDir, CONFLICT_RAW_SOURCE_FILENAME);
|
|
32711
33544
|
return {
|
|
32712
33545
|
meta: meta3,
|
|
32713
33546
|
current: await pathExists(currentPath) ? await readPatchFile(currentPath) : void 0,
|
|
32714
|
-
proposed: await readPatchFile(
|
|
33547
|
+
proposed: await readPatchFile(path19__default.join(conflictDir, CONFLICT_PROPOSED_FILENAME)),
|
|
32715
33548
|
rawSource: await pathExists(rawSourcePath) ? await readPatchFile(rawSourcePath) : void 0
|
|
32716
33549
|
};
|
|
32717
33550
|
}
|
|
@@ -32730,9 +33563,9 @@ function sanitizeConflictToken(value) {
|
|
|
32730
33563
|
return value.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64) || "unknown";
|
|
32731
33564
|
}
|
|
32732
33565
|
function resolveConflictDir(conflictId, paths) {
|
|
32733
|
-
const conflictDir =
|
|
32734
|
-
const relative =
|
|
32735
|
-
if (!relative || relative.startsWith("..") ||
|
|
33566
|
+
const conflictDir = path19__default.resolve(paths.conflictsDir, conflictId);
|
|
33567
|
+
const relative = path19__default.relative(paths.conflictsDir, conflictDir);
|
|
33568
|
+
if (!relative || relative.startsWith("..") || path19__default.isAbsolute(relative)) {
|
|
32736
33569
|
throw new Error(`[fleet-wiki] conflict id escapes conflicts/: ${conflictId}`);
|
|
32737
33570
|
}
|
|
32738
33571
|
return conflictDir;
|
|
@@ -32896,11 +33729,11 @@ async function validatePatch(patch, paths) {
|
|
|
32896
33729
|
if (!target2 || !summary || !proposer || !created) throw new Error("patch frontmatter is incomplete");
|
|
32897
33730
|
if (summary.length > 120) throw new Error("patch summary exceeds 120 chars");
|
|
32898
33731
|
assertCanonicalPatchTarget(target2);
|
|
32899
|
-
const absoluteTarget =
|
|
32900
|
-
if (!absoluteTarget.startsWith(`${paths.root}${
|
|
33732
|
+
const absoluteTarget = path19__default.resolve(paths.root, target2);
|
|
33733
|
+
if (!absoluteTarget.startsWith(`${paths.root}${path19__default.sep}`) && absoluteTarget !== paths.root) {
|
|
32901
33734
|
throw new Error("patch target escapes wiki root");
|
|
32902
33735
|
}
|
|
32903
|
-
if (!absoluteTarget.startsWith(`${paths.wikiDir}${
|
|
33736
|
+
if (!absoluteTarget.startsWith(`${paths.wikiDir}${path19__default.sep}`)) throw new Error("wiki patch must target wiki/");
|
|
32904
33737
|
assertNoSymlinkPathComponents(target2, paths);
|
|
32905
33738
|
if (op === "create_wiki" && await pathExists(absoluteTarget)) {
|
|
32906
33739
|
throw new Error(
|
|
@@ -32921,19 +33754,19 @@ async function applyPatch(patch, paths) {
|
|
|
32921
33754
|
async function enqueuePatch(patch, paths, metaOverrides) {
|
|
32922
33755
|
await ensureMemoryRoot(paths);
|
|
32923
33756
|
const patchId = buildPatchId(patch.frontmatter.created, patch.frontmatter.summary, patch.frontmatter.target, patch.body);
|
|
32924
|
-
const queueDir =
|
|
33757
|
+
const queueDir = path19__default.join(paths.queueDir, patchId);
|
|
32925
33758
|
if (await pathExists(queueDir)) {
|
|
32926
33759
|
throw new Error(`[fleet-wiki] patch id collision: ${patchId} - this should never happen with target+body hashing`);
|
|
32927
33760
|
}
|
|
32928
33761
|
await mkdir(queueDir, { recursive: true });
|
|
32929
|
-
await writePatchFile(
|
|
33762
|
+
await writePatchFile(path19__default.join(queueDir, PATCH_FILENAME), serializePatch(patch), paths);
|
|
32930
33763
|
const meta3 = {
|
|
32931
33764
|
id: patchId,
|
|
32932
33765
|
status: "pending",
|
|
32933
33766
|
createdAt: patch.frontmatter.created,
|
|
32934
33767
|
...metaOverrides
|
|
32935
33768
|
};
|
|
32936
|
-
await writeJsonFile(
|
|
33769
|
+
await writeJsonFile(path19__default.join(queueDir, PATCH_META_FILENAME), meta3, paths);
|
|
32937
33770
|
await appendLog(paths, "patch enqueued", {
|
|
32938
33771
|
patch_id: patchId,
|
|
32939
33772
|
patch_set_id: meta3.patch_set_id ?? null,
|
|
@@ -32951,7 +33784,7 @@ async function listQueue(paths) {
|
|
|
32951
33784
|
for (const id of ids) {
|
|
32952
33785
|
if (id === "_sets") continue;
|
|
32953
33786
|
try {
|
|
32954
|
-
const meta3 = await readJsonFile2(
|
|
33787
|
+
const meta3 = await readJsonFile2(path19__default.join(paths.queueDir, id, PATCH_META_FILENAME));
|
|
32955
33788
|
results.push({ id, meta: meta3 });
|
|
32956
33789
|
} catch {
|
|
32957
33790
|
continue;
|
|
@@ -32976,17 +33809,17 @@ async function resolveQueueSelection(id, paths) {
|
|
|
32976
33809
|
}
|
|
32977
33810
|
async function showQueue(id, paths) {
|
|
32978
33811
|
const selection = await resolveQueueSelection(id, paths);
|
|
32979
|
-
const queueDir =
|
|
32980
|
-
const patch = await parsePatch(await readPatchFile(
|
|
32981
|
-
const meta3 = await readJsonFile2(
|
|
33812
|
+
const queueDir = path19__default.join(paths.queueDir, selection.id);
|
|
33813
|
+
const patch = await parsePatch(await readPatchFile(path19__default.join(queueDir, PATCH_FILENAME)));
|
|
33814
|
+
const meta3 = await readJsonFile2(path19__default.join(queueDir, PATCH_META_FILENAME));
|
|
32982
33815
|
return { patch, meta: meta3 };
|
|
32983
33816
|
}
|
|
32984
33817
|
async function rewriteQueuedPatch(id, paths, patch, meta3, expectedPatchHash) {
|
|
32985
33818
|
assertSafeQueueId(id);
|
|
32986
33819
|
return withPatchEditLock(paths, id, async () => {
|
|
32987
|
-
const queueDir =
|
|
33820
|
+
const queueDir = path19__default.join(paths.queueDir, id);
|
|
32988
33821
|
if (expectedPatchHash !== void 0) {
|
|
32989
|
-
const currentMarkdown = await readPatchFile(
|
|
33822
|
+
const currentMarkdown = await readPatchFile(path19__default.join(queueDir, PATCH_FILENAME));
|
|
32990
33823
|
const currentHash = computeContentHash(currentMarkdown);
|
|
32991
33824
|
if (currentHash !== expectedPatchHash) {
|
|
32992
33825
|
throw new Error(`[fleet-wiki] wiki_patch_edit stale base_patch_hash: expected ${currentHash}, got ${expectedPatchHash}`);
|
|
@@ -32995,8 +33828,8 @@ async function rewriteQueuedPatch(id, paths, patch, meta3, expectedPatchHash) {
|
|
|
32995
33828
|
const patchMarkdown = serializePatch(patch);
|
|
32996
33829
|
const patchHash = computeContentHash(patchMarkdown);
|
|
32997
33830
|
const nextMeta = { ...meta3, lastEditHash: patchHash };
|
|
32998
|
-
await writePatchFile(
|
|
32999
|
-
await writeJsonFile(
|
|
33831
|
+
await writePatchFile(path19__default.join(queueDir, PATCH_FILENAME), patchMarkdown, paths);
|
|
33832
|
+
await writeJsonFile(path19__default.join(queueDir, PATCH_META_FILENAME), nextMeta, paths);
|
|
33000
33833
|
return patchHash;
|
|
33001
33834
|
});
|
|
33002
33835
|
}
|
|
@@ -33020,8 +33853,8 @@ async function approvePatch(id, paths) {
|
|
|
33020
33853
|
rawSourceRef: meta3.rawSourceRef,
|
|
33021
33854
|
warnings: meta3.warnings
|
|
33022
33855
|
});
|
|
33023
|
-
const queueDir =
|
|
33024
|
-
await writeJsonFile(
|
|
33856
|
+
const queueDir = path19__default.join(paths.queueDir, id);
|
|
33857
|
+
await writeJsonFile(path19__default.join(queueDir, PATCH_META_FILENAME), {
|
|
33025
33858
|
...meta3,
|
|
33026
33859
|
conflictId
|
|
33027
33860
|
}, paths);
|
|
@@ -33057,7 +33890,7 @@ async function approvePatchSet(patchSetId, paths) {
|
|
|
33057
33890
|
const failed = [];
|
|
33058
33891
|
const missing = [];
|
|
33059
33892
|
for (const patchId of patchSet.patchIds) {
|
|
33060
|
-
const queueDir =
|
|
33893
|
+
const queueDir = path19__default.join(paths.queueDir, patchId);
|
|
33061
33894
|
if (!await pathExists(queueDir)) {
|
|
33062
33895
|
missing.push(patchId);
|
|
33063
33896
|
continue;
|
|
@@ -33123,7 +33956,7 @@ ${patch.body}`;
|
|
|
33123
33956
|
}
|
|
33124
33957
|
async function normalizeWikiEntryPatch(entry, target2, paths) {
|
|
33125
33958
|
assertSafeEntryId(entry.id);
|
|
33126
|
-
if (entry.id !==
|
|
33959
|
+
if (entry.id !== path19__default.basename(target2, ".md")) {
|
|
33127
33960
|
throw new Error("wiki patch body id must match target filename");
|
|
33128
33961
|
}
|
|
33129
33962
|
const inlineRawSourceRef = extractInlineRawSourceRef(entry.body);
|
|
@@ -33166,9 +33999,9 @@ function buildPatchId(createdAt, summary, target2, body) {
|
|
|
33166
33999
|
}
|
|
33167
34000
|
async function validatePatchBase(patch, meta3, paths) {
|
|
33168
34001
|
if (patch.frontmatter.op !== "update_wiki" || !meta3?.baseVersion && !meta3?.baseHash) return;
|
|
33169
|
-
const wikiId =
|
|
34002
|
+
const wikiId = path19__default.basename(patch.frontmatter.target, ".md");
|
|
33170
34003
|
const currentEntry = await readWikiEntry(wikiId, paths);
|
|
33171
|
-
const currentPath =
|
|
34004
|
+
const currentPath = path19__default.join(paths.root, patch.frontmatter.target);
|
|
33172
34005
|
const currentMarkdown = await pathExists(currentPath) ? await readPatchFile(currentPath) : void 0;
|
|
33173
34006
|
if (meta3.baseVersion !== void 0 && currentEntry?.version !== meta3.baseVersion) {
|
|
33174
34007
|
throw new Error(
|
|
@@ -33227,17 +34060,17 @@ function assertCanonicalPatchTarget(target2) {
|
|
|
33227
34060
|
if (target2.endsWith("/")) {
|
|
33228
34061
|
throw new Error("patch target must not end with a slash");
|
|
33229
34062
|
}
|
|
33230
|
-
if (target2.startsWith("/") ||
|
|
34063
|
+
if (target2.startsWith("/") || path19__default.posix.isAbsolute(target2) || path19__default.win32.isAbsolute(target2)) {
|
|
33231
34064
|
throw new Error("patch target must be relative");
|
|
33232
34065
|
}
|
|
33233
|
-
if (
|
|
34066
|
+
if (path19__default.posix.normalize(target2) !== target2) {
|
|
33234
34067
|
throw new Error("patch target must not contain dot segments or redundant separators");
|
|
33235
34068
|
}
|
|
33236
34069
|
}
|
|
33237
34070
|
function canonicalApprovalLockKey(paths, target2) {
|
|
33238
34071
|
const wikiRoot = realpathSync(paths.wikiDir);
|
|
33239
|
-
const relativeTarget =
|
|
33240
|
-
const targetPath =
|
|
34072
|
+
const relativeTarget = path19__default.posix.relative("wiki", target2);
|
|
34073
|
+
const targetPath = path19__default.join(wikiRoot, ...relativeTarget.split("/"));
|
|
33241
34074
|
return `${wikiRoot}\0${targetPath}`.toLowerCase();
|
|
33242
34075
|
}
|
|
33243
34076
|
function canonicalPatchEditLockKey(paths, patchId) {
|
|
@@ -33253,7 +34086,7 @@ function assertNoSymlinkPathComponents(target2, paths) {
|
|
|
33253
34086
|
throw error51;
|
|
33254
34087
|
}
|
|
33255
34088
|
for (const part of parts) {
|
|
33256
|
-
current =
|
|
34089
|
+
current = path19__default.join(current, part);
|
|
33257
34090
|
try {
|
|
33258
34091
|
if (lstatSync(current).isSymbolicLink()) {
|
|
33259
34092
|
throw new Error("patch target must not include symlink path components");
|
|
@@ -33268,8 +34101,8 @@ function assertSafeRawSourceRef(rawSourceRef, paths) {
|
|
|
33268
34101
|
if (!rawSourceRef.startsWith("raw/")) {
|
|
33269
34102
|
throw new Error("raw source provenance must point into raw/");
|
|
33270
34103
|
}
|
|
33271
|
-
const absoluteRef =
|
|
33272
|
-
if (!absoluteRef.startsWith(`${paths.rawDir}${
|
|
34104
|
+
const absoluteRef = path19__default.resolve(paths.root, rawSourceRef);
|
|
34105
|
+
if (!absoluteRef.startsWith(`${paths.rawDir}${path19__default.sep}`)) {
|
|
33273
34106
|
throw new Error("raw source provenance must point into raw/");
|
|
33274
34107
|
}
|
|
33275
34108
|
}
|
|
@@ -33285,14 +34118,14 @@ function classifyPatchConflict(error51) {
|
|
|
33285
34118
|
}
|
|
33286
34119
|
async function recordPatchConflict(patch, paths, reason, options) {
|
|
33287
34120
|
const now = /* @__PURE__ */ new Date();
|
|
33288
|
-
const targetPath =
|
|
34121
|
+
const targetPath = path19__default.join(paths.root, patch.frontmatter.target);
|
|
33289
34122
|
const current = await pathExists(targetPath) ? await readPatchFile(targetPath) : void 0;
|
|
33290
34123
|
const currentEntry = current ? parseStoredWikiEntry(current) : void 0;
|
|
33291
34124
|
const proposedEntry = parsePatchBodyEntry(patch.body);
|
|
33292
|
-
const
|
|
34125
|
+
const record7 = await createConflict({
|
|
33293
34126
|
reason,
|
|
33294
34127
|
target: patch.frontmatter.target,
|
|
33295
|
-
wikiId: proposedEntry?.id ??
|
|
34128
|
+
wikiId: proposedEntry?.id ?? path19__default.basename(patch.frontmatter.target, ".md"),
|
|
33296
34129
|
title: proposedEntry?.title,
|
|
33297
34130
|
proposer: patch.frontmatter.proposer,
|
|
33298
34131
|
rawSourceRef: options?.rawSourceRef,
|
|
@@ -33308,14 +34141,14 @@ async function recordPatchConflict(patch, paths, reason, options) {
|
|
|
33308
34141
|
now
|
|
33309
34142
|
}, paths);
|
|
33310
34143
|
await appendLog(paths, "conflict detected", {
|
|
33311
|
-
conflict_id:
|
|
34144
|
+
conflict_id: record7.meta.id,
|
|
33312
34145
|
patch_id: options?.patchId ?? null,
|
|
33313
34146
|
raw_source_ref: options?.rawSourceRef ?? null,
|
|
33314
34147
|
reason,
|
|
33315
34148
|
target: patch.frontmatter.target,
|
|
33316
|
-
wiki_id:
|
|
34149
|
+
wiki_id: record7.meta.wikiId
|
|
33317
34150
|
}, now);
|
|
33318
|
-
return
|
|
34151
|
+
return record7.meta.id;
|
|
33319
34152
|
}
|
|
33320
34153
|
function parsePatchBodyEntry(content) {
|
|
33321
34154
|
try {
|
|
@@ -33404,11 +34237,11 @@ function parseInlineArray(value) {
|
|
|
33404
34237
|
return inner.split(",").map((item) => decodeFrontmatter(item.trim().replace(/^"(.*)"$/, "$1")));
|
|
33405
34238
|
}
|
|
33406
34239
|
async function archiveQueueEntry(id, paths, meta3) {
|
|
33407
|
-
const fromDir =
|
|
33408
|
-
const toDir =
|
|
34240
|
+
const fromDir = path19__default.join(paths.queueDir, id);
|
|
34241
|
+
const toDir = path19__default.join(paths.archiveDir, id);
|
|
33409
34242
|
await removePath(toDir);
|
|
33410
34243
|
await movePath(fromDir, toDir);
|
|
33411
|
-
await writeJsonFile(
|
|
34244
|
+
await writeJsonFile(path19__default.join(toDir, PATCH_META_FILENAME), meta3, paths);
|
|
33412
34245
|
}
|
|
33413
34246
|
function buildQueueIdHelp(prefix, availableIds) {
|
|
33414
34247
|
if (availableIds.length === 0) {
|
|
@@ -33440,15 +34273,15 @@ var PATCH_SET_DIRNAME = "_sets";
|
|
|
33440
34273
|
var PATCH_SET_META_FILENAME = PATCH_META_FILENAME;
|
|
33441
34274
|
function getPatchSetDir(paths, patchSetId) {
|
|
33442
34275
|
assertSafePatchSetId(patchSetId);
|
|
33443
|
-
const patchSetDir =
|
|
33444
|
-
const relative =
|
|
33445
|
-
if (!relative || relative.startsWith("..") ||
|
|
34276
|
+
const patchSetDir = path19__default.join(paths.queueDir, PATCH_SET_DIRNAME, patchSetId);
|
|
34277
|
+
const relative = path19__default.relative(path19__default.join(paths.queueDir, PATCH_SET_DIRNAME), patchSetDir);
|
|
34278
|
+
if (!relative || relative.startsWith("..") || path19__default.isAbsolute(relative)) {
|
|
33446
34279
|
throw new Error(`[fleet-wiki] patch set id escapes queue/_sets: ${patchSetId}`);
|
|
33447
34280
|
}
|
|
33448
34281
|
return patchSetDir;
|
|
33449
34282
|
}
|
|
33450
34283
|
function getPatchSetMetaFile(paths, patchSetId) {
|
|
33451
|
-
return
|
|
34284
|
+
return path19__default.join(getPatchSetDir(paths, patchSetId), PATCH_SET_META_FILENAME);
|
|
33452
34285
|
}
|
|
33453
34286
|
function buildPatchSetId(createdAt, sourceRef) {
|
|
33454
34287
|
const compact = createdAt.replace(/[:.]/g, "-");
|
|
@@ -33507,36 +34340,36 @@ async function readWikiEntry(id, paths) {
|
|
|
33507
34340
|
const index = await loadIndex(paths);
|
|
33508
34341
|
const indexed = index[id];
|
|
33509
34342
|
if (indexed) {
|
|
33510
|
-
const resolved =
|
|
33511
|
-
const rel =
|
|
33512
|
-
if (!rel || rel.startsWith("..") ||
|
|
34343
|
+
const resolved = path19__default.resolve(paths.root, indexed.path);
|
|
34344
|
+
const rel = path19__default.relative(paths.wikiDir, resolved);
|
|
34345
|
+
if (!rel || rel.startsWith("..") || path19__default.isAbsolute(rel)) return null;
|
|
33513
34346
|
return readMarkdownFile(resolved);
|
|
33514
34347
|
}
|
|
33515
|
-
const fallbackPath =
|
|
34348
|
+
const fallbackPath = path19__default.join(paths.wikiDir, `${id}.md`);
|
|
33516
34349
|
if (await pathExists(fallbackPath)) {
|
|
33517
34350
|
return readMarkdownFile(fallbackPath);
|
|
33518
34351
|
}
|
|
33519
34352
|
const records = await listWikiRecords(paths);
|
|
33520
|
-
const match = records.find((
|
|
34353
|
+
const match = records.find((record7) => record7.entry.id === id);
|
|
33521
34354
|
return match ? match.entry : null;
|
|
33522
34355
|
}
|
|
33523
34356
|
async function writeWikiEntryAtTarget(entry, target2, paths) {
|
|
33524
34357
|
await ensureMemoryRoot(paths);
|
|
33525
34358
|
assertSafeEntryId(entry.id);
|
|
33526
|
-
const absoluteTarget =
|
|
33527
|
-
const relativeTarget =
|
|
33528
|
-
if (!relativeTarget || relativeTarget.startsWith("..") ||
|
|
34359
|
+
const absoluteTarget = path19__default.resolve(paths.root, target2);
|
|
34360
|
+
const relativeTarget = path19__default.relative(paths.wikiDir, absoluteTarget);
|
|
34361
|
+
if (!relativeTarget || relativeTarget.startsWith("..") || path19__default.isAbsolute(relativeTarget)) {
|
|
33529
34362
|
throw new Error(`[fleet-wiki] wiki target escapes wiki/: ${target2}`);
|
|
33530
34363
|
}
|
|
33531
34364
|
if (!absoluteTarget.endsWith(".md")) {
|
|
33532
34365
|
throw new Error(`[fleet-wiki] wiki target must end with .md: ${target2}`);
|
|
33533
34366
|
}
|
|
33534
|
-
if (
|
|
34367
|
+
if (path19__default.basename(absoluteTarget, ".md") !== entry.id) {
|
|
33535
34368
|
throw new Error("wiki patch body id must match target filename");
|
|
33536
34369
|
}
|
|
33537
|
-
await mkdir(
|
|
34370
|
+
await mkdir(path19__default.dirname(absoluteTarget), { recursive: true });
|
|
33538
34371
|
await writeAtomic(absoluteTarget, serializeWikiEntry(entry), paths);
|
|
33539
|
-
return
|
|
34372
|
+
return path19__default.join("wiki", relativeTarget).replaceAll(path19__default.sep, "/");
|
|
33540
34373
|
}
|
|
33541
34374
|
async function writeRawSourceEntry(entry, paths) {
|
|
33542
34375
|
await ensureMemoryRoot(paths);
|
|
@@ -33555,11 +34388,11 @@ async function writeRawSourceEntry(entry, paths) {
|
|
|
33555
34388
|
},
|
|
33556
34389
|
entry.content
|
|
33557
34390
|
);
|
|
33558
|
-
await writeAtomic(
|
|
34391
|
+
await writeAtomic(path19__default.join(paths.root, relativePath), content, paths);
|
|
33559
34392
|
return relativePath;
|
|
33560
34393
|
}
|
|
33561
34394
|
async function readRawSourceEntry(rawSourceRef, paths) {
|
|
33562
|
-
const absolutePath =
|
|
34395
|
+
const absolutePath = path19__default.resolve(paths.root, rawSourceRef);
|
|
33563
34396
|
assertWithinRawDir(absolutePath, paths);
|
|
33564
34397
|
const parsed = parseMarkdown(await readFile(absolutePath, "utf8"));
|
|
33565
34398
|
return {
|
|
@@ -33750,8 +34583,8 @@ function computeContentHash(content) {
|
|
|
33750
34583
|
return crypto5.createHash("sha256").update(content, "utf8").digest("hex").slice(0, 8);
|
|
33751
34584
|
}
|
|
33752
34585
|
function assertWithinRawDir(absolutePath, paths) {
|
|
33753
|
-
const relative =
|
|
33754
|
-
if (!relative || relative.startsWith("..") ||
|
|
34586
|
+
const relative = path19__default.relative(paths.rawDir, absolutePath);
|
|
34587
|
+
if (!relative || relative.startsWith("..") || path19__default.isAbsolute(relative)) {
|
|
33755
34588
|
throw new Error(`[fleet-wiki] raw source ref escapes raw/: ${absolutePath}`);
|
|
33756
34589
|
}
|
|
33757
34590
|
}
|
|
@@ -33807,7 +34640,7 @@ function parseWikiEntry(content) {
|
|
|
33807
34640
|
async function listWikiRecords(paths) {
|
|
33808
34641
|
return listMarkdownEntriesRecursive(paths.wikiDir, paths, (content, filePath) => ({
|
|
33809
34642
|
entry: parseWikiEntry(content),
|
|
33810
|
-
path:
|
|
34643
|
+
path: path19__default.relative(paths.root, filePath).replaceAll(path19__default.sep, "/")
|
|
33811
34644
|
}));
|
|
33812
34645
|
}
|
|
33813
34646
|
async function listMarkdownEntriesRecursive(dirPath, paths, parser) {
|
|
@@ -33820,7 +34653,7 @@ async function listMarkdownEntriesRecursive(dirPath, paths, parser) {
|
|
|
33820
34653
|
}
|
|
33821
34654
|
const sortedEntries = entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
33822
34655
|
for (const entry of sortedEntries) {
|
|
33823
|
-
const filePath =
|
|
34656
|
+
const filePath = path19__default.join(dirPath, entry.name);
|
|
33824
34657
|
if (entry.isDirectory()) {
|
|
33825
34658
|
items.push(...await listMarkdownEntriesRecursive(filePath, paths, parser));
|
|
33826
34659
|
continue;
|
|
@@ -33955,8 +34788,8 @@ async function writeJsonAtomic(filePath, value, paths) {
|
|
|
33955
34788
|
}
|
|
33956
34789
|
async function writeAtomic(filePath, content, paths) {
|
|
33957
34790
|
await ensureMemoryRoot(paths);
|
|
33958
|
-
const tempPath =
|
|
33959
|
-
|
|
34791
|
+
const tempPath = path19__default.join(
|
|
34792
|
+
path19__default.dirname(filePath),
|
|
33960
34793
|
`.tmp-${process.pid}-${Date.now()}-${crypto5.randomUUID()}-${os3__default.hostname()}`
|
|
33961
34794
|
);
|
|
33962
34795
|
await writeFile(tempPath, content, "utf8");
|
|
@@ -34037,7 +34870,7 @@ function extractLegacyMarkdownWikiLinks(body, wikiDir, basePath) {
|
|
|
34037
34870
|
}
|
|
34038
34871
|
function resolveLegacyWikiTarget(target2, wikiDir, basePath) {
|
|
34039
34872
|
if (!target2 || target2.startsWith("#")) return null;
|
|
34040
|
-
if (
|
|
34873
|
+
if (path19__default.isAbsolute(target2)) return null;
|
|
34041
34874
|
if (/^[a-z][a-z0-9+.-]*:/i.test(target2)) return null;
|
|
34042
34875
|
const withoutFragment = target2.split("#", 1)[0]?.split("?", 1)[0] ?? "";
|
|
34043
34876
|
if (!withoutFragment.endsWith(".md")) return null;
|
|
@@ -34047,12 +34880,12 @@ function resolveLegacyWikiTarget(target2, wikiDir, basePath) {
|
|
|
34047
34880
|
} catch {
|
|
34048
34881
|
return null;
|
|
34049
34882
|
}
|
|
34050
|
-
const resolved =
|
|
34051
|
-
const relative =
|
|
34052
|
-
if (!relative || relative.startsWith("..") ||
|
|
34883
|
+
const resolved = path19__default.resolve(path19__default.dirname(basePath), decodedTarget);
|
|
34884
|
+
const relative = path19__default.relative(wikiDir, resolved);
|
|
34885
|
+
if (!relative || relative.startsWith("..") || path19__default.isAbsolute(relative)) return null;
|
|
34053
34886
|
return {
|
|
34054
34887
|
target: target2,
|
|
34055
|
-
entryId:
|
|
34888
|
+
entryId: path19__default.basename(relative, ".md")
|
|
34056
34889
|
};
|
|
34057
34890
|
}
|
|
34058
34891
|
var FLEET_WIKI_ENTRY_BEGIN = "<<<FLEET_WIKI_ENTRY_BEGIN";
|
|
@@ -34119,7 +34952,7 @@ async function enhancedSearch(paths, options) {
|
|
|
34119
34952
|
for (const entry of entries) {
|
|
34120
34953
|
if (!index[entry.id]) {
|
|
34121
34954
|
index[entry.id] = {
|
|
34122
|
-
path:
|
|
34955
|
+
path: path19__default.join("wiki", `${entry.id}.md`),
|
|
34123
34956
|
title: entry.title,
|
|
34124
34957
|
tags: entry.tags,
|
|
34125
34958
|
updated: entry.updated
|
|
@@ -34255,7 +35088,7 @@ function toEnhancedHit(entry, signals) {
|
|
|
34255
35088
|
score: enhancedScore,
|
|
34256
35089
|
reason: signals.legacyReason ?? "body",
|
|
34257
35090
|
excerpt,
|
|
34258
|
-
path:
|
|
35091
|
+
path: path19__default.join("wiki", `${entry.id}.md`),
|
|
34259
35092
|
tags: entry.tags,
|
|
34260
35093
|
updated: entry.updated,
|
|
34261
35094
|
version: entry.version,
|
|
@@ -34451,7 +35284,7 @@ function toRankedHit(entry, reason, detail, graphBoost, backlinksById) {
|
|
|
34451
35284
|
score: basePriority * 100 + statusPriority * 10 + graphScore + (detail.tagBoost ?? 0),
|
|
34452
35285
|
reason,
|
|
34453
35286
|
excerpt,
|
|
34454
|
-
path:
|
|
35287
|
+
path: path19__default.join("wiki", `${entry.id}.md`),
|
|
34455
35288
|
tags: entry.tags,
|
|
34456
35289
|
updated: entry.updated,
|
|
34457
35290
|
version: entry.version,
|
|
@@ -35993,8 +36826,8 @@ function CreateObject(types, value) {
|
|
|
35993
36826
|
}
|
|
35994
36827
|
function FromUnionKey(types, value) {
|
|
35995
36828
|
const flattened = Flatten(types);
|
|
35996
|
-
const
|
|
35997
|
-
return IsSchema(
|
|
36829
|
+
const record7 = TryBuildRecord(flattened, value);
|
|
36830
|
+
return IsSchema(record7) ? record7 : CreateObject(flattened, value);
|
|
35998
36831
|
}
|
|
35999
36832
|
|
|
36000
36833
|
// ../../node_modules/.pnpm/typebox@1.1.34/node_modules/typebox/build/type/engine/record/from_key.mjs
|
|
@@ -39217,13 +40050,13 @@ async function readClaims(entryId, paths) {
|
|
|
39217
40050
|
}
|
|
39218
40051
|
}
|
|
39219
40052
|
function getClaimsDir(paths) {
|
|
39220
|
-
return
|
|
40053
|
+
return path19__default.join(paths.wikiDir, CLAIMS_DIRNAME);
|
|
39221
40054
|
}
|
|
39222
40055
|
function getClaimsFile(paths, entryId) {
|
|
39223
40056
|
assertSafeEntryId(entryId);
|
|
39224
|
-
const claimsFile =
|
|
39225
|
-
const relative =
|
|
39226
|
-
if (!relative || relative.startsWith("..") ||
|
|
40057
|
+
const claimsFile = path19__default.join(getClaimsDir(paths), `${entryId}.json`);
|
|
40058
|
+
const relative = path19__default.relative(getClaimsDir(paths), claimsFile);
|
|
40059
|
+
if (!relative || relative.startsWith("..") || path19__default.isAbsolute(relative)) {
|
|
39227
40060
|
throw new Error(`[fleet-wiki] claims sidecar escapes wiki/.claims: ${entryId}`);
|
|
39228
40061
|
}
|
|
39229
40062
|
return claimsFile;
|
|
@@ -39314,7 +40147,7 @@ function assertSafeClaimRawRef(ref) {
|
|
|
39314
40147
|
if (!ref.startsWith("raw/")) {
|
|
39315
40148
|
throw new Error(`claim sourceRef must point into raw/: ${ref}`);
|
|
39316
40149
|
}
|
|
39317
|
-
if (ref.includes("..") ||
|
|
40150
|
+
if (ref.includes("..") || path19__default.isAbsolute(ref)) {
|
|
39318
40151
|
throw new Error(`claim sourceRef escapes raw/: ${ref}`);
|
|
39319
40152
|
}
|
|
39320
40153
|
}
|
|
@@ -39392,22 +40225,22 @@ async function runDryDock(paths, options = {}) {
|
|
|
39392
40225
|
}
|
|
39393
40226
|
for (const fileName of await listFileNames(paths.rawDir)) {
|
|
39394
40227
|
if (!fileName.endsWith(".md")) continue;
|
|
39395
|
-
const filePath =
|
|
40228
|
+
const filePath = path19__default.join(paths.rawDir, fileName);
|
|
39396
40229
|
issues.push(...safetyIssues(await readPatchFile(filePath), filePath));
|
|
39397
40230
|
}
|
|
39398
40231
|
for (const queueId of await listDirectoryNames(paths.queueDir)) {
|
|
39399
40232
|
if (queueId === PATCH_SET_DIRNAME) continue;
|
|
39400
|
-
const queueDir =
|
|
40233
|
+
const queueDir = path19__default.join(paths.queueDir, queueId);
|
|
39401
40234
|
try {
|
|
39402
|
-
const patchContent = await readPatchFile(
|
|
39403
|
-
issues.push(...safetyIssues(patchContent,
|
|
39404
|
-
await readJsonFile2(
|
|
40235
|
+
const patchContent = await readPatchFile(path19__default.join(queueDir, PATCH_FILENAME));
|
|
40236
|
+
issues.push(...safetyIssues(patchContent, path19__default.join(queueDir, PATCH_FILENAME)));
|
|
40237
|
+
await readJsonFile2(path19__default.join(queueDir, PATCH_META_FILENAME));
|
|
39405
40238
|
} catch {
|
|
39406
40239
|
issues.push(issue2("malformed_queue", "error", "\uC190\uC0C1\uB41C queue \uC5D4\uD2B8\uB9AC", queueDir));
|
|
39407
40240
|
}
|
|
39408
40241
|
}
|
|
39409
|
-
for (const patchSetId of await listDirectoryNames(
|
|
39410
|
-
const patchSetMetaFile =
|
|
40242
|
+
for (const patchSetId of await listDirectoryNames(path19__default.join(paths.queueDir, PATCH_SET_DIRNAME))) {
|
|
40243
|
+
const patchSetMetaFile = path19__default.join(paths.queueDir, PATCH_SET_DIRNAME, patchSetId, PATCH_META_FILENAME);
|
|
39411
40244
|
let patchSet;
|
|
39412
40245
|
try {
|
|
39413
40246
|
patchSet = await readPatchSet(paths, patchSetId);
|
|
@@ -39416,8 +40249,8 @@ async function runDryDock(paths, options = {}) {
|
|
|
39416
40249
|
continue;
|
|
39417
40250
|
}
|
|
39418
40251
|
for (const patchId of patchSet.patchIds) {
|
|
39419
|
-
const queueMetaFile =
|
|
39420
|
-
const archiveMetaFile =
|
|
40252
|
+
const queueMetaFile = path19__default.join(paths.queueDir, patchId, PATCH_META_FILENAME);
|
|
40253
|
+
const archiveMetaFile = path19__default.join(paths.archiveDir, patchId, PATCH_META_FILENAME);
|
|
39421
40254
|
if (!await pathExists(queueMetaFile) && !await pathExists(archiveMetaFile)) {
|
|
39422
40255
|
issues.push(
|
|
39423
40256
|
issue2(
|
|
@@ -39454,7 +40287,7 @@ async function runDryDock(paths, options = {}) {
|
|
|
39454
40287
|
"conflict_unresolved",
|
|
39455
40288
|
"warning",
|
|
39456
40289
|
`\uBBF8\uD574\uACB0 conflict: ${conflict.reason} (${conflict.target})`,
|
|
39457
|
-
|
|
40290
|
+
path19__default.join(paths.conflictsDir, conflict.id, "meta.json")
|
|
39458
40291
|
)
|
|
39459
40292
|
);
|
|
39460
40293
|
}
|
|
@@ -39467,7 +40300,7 @@ async function runDryDock(paths, options = {}) {
|
|
|
39467
40300
|
"unresolved_conflict",
|
|
39468
40301
|
"warning",
|
|
39469
40302
|
"\uC190\uC0C1\uB41C conflict \uC5D4\uD2B8\uB9AC",
|
|
39470
|
-
|
|
40303
|
+
path19__default.join(paths.conflictsDir, conflictId, "meta.json")
|
|
39471
40304
|
)
|
|
39472
40305
|
);
|
|
39473
40306
|
}
|
|
@@ -39524,8 +40357,8 @@ async function claimIssues(paths, wikiIds) {
|
|
|
39524
40357
|
const claimsDir = getClaimsDir(paths);
|
|
39525
40358
|
for (const fileName of await listFileNames(claimsDir)) {
|
|
39526
40359
|
if (!fileName.endsWith(".json")) continue;
|
|
39527
|
-
const filePath =
|
|
39528
|
-
const entryIdFromFile =
|
|
40360
|
+
const filePath = path19__default.join(claimsDir, fileName);
|
|
40361
|
+
const entryIdFromFile = path19__default.basename(fileName, ".json");
|
|
39529
40362
|
let raw;
|
|
39530
40363
|
try {
|
|
39531
40364
|
raw = await readJsonFile2(filePath);
|
|
@@ -39604,7 +40437,7 @@ function toSemanticEntry(filePath, frontmatter, body) {
|
|
|
39604
40437
|
async function schemaIssues(paths) {
|
|
39605
40438
|
const issues = [];
|
|
39606
40439
|
const schema = await readWorkspaceSchemaSummary(paths);
|
|
39607
|
-
const agentsPath =
|
|
40440
|
+
const agentsPath = path19__default.join(paths.schemaDir, WORKSPACE_SCHEMA_AGENTS_FILENAME);
|
|
39608
40441
|
if (!await pathExists(schema.wikiSchemaPath)) {
|
|
39609
40442
|
issues.push(issue2("schema_missing", "warning", `Workspace schema file is missing: schema/${WORKSPACE_SCHEMA_FILENAME}`, schema.wikiSchemaPath));
|
|
39610
40443
|
} else {
|
|
@@ -39991,7 +40824,7 @@ async function listWikiMarkdownFiles(dirPath) {
|
|
|
39991
40824
|
const files = [];
|
|
39992
40825
|
const sortedEntries = entries.sort((left, right) => left.name.localeCompare(right.name));
|
|
39993
40826
|
for (const entry of sortedEntries) {
|
|
39994
|
-
const filePath =
|
|
40827
|
+
const filePath = path19__default.join(dirPath, entry.name);
|
|
39995
40828
|
if (entry.isDirectory()) {
|
|
39996
40829
|
files.push(...await listWikiMarkdownFiles(filePath));
|
|
39997
40830
|
continue;
|
|
@@ -40215,7 +41048,7 @@ async function resolveCompileSource(input, paths, now) {
|
|
|
40215
41048
|
}
|
|
40216
41049
|
async function buildCompileProposals(input, paths, now, resolvedSource) {
|
|
40217
41050
|
const sourceTarget = `wiki/sources/${resolvedSource.sourcePageId}.md`;
|
|
40218
|
-
const sourceExists = await pathExists(
|
|
41051
|
+
const sourceExists = await pathExists(path19__default.join(paths.root, sourceTarget));
|
|
40219
41052
|
const existingEntries = await listWiki(paths);
|
|
40220
41053
|
const sourcePageTitle = resolvedSource.sourceTitle?.trim() || `Source ${resolvedSource.sourcePageId}`;
|
|
40221
41054
|
const existingSourceEntry = existingEntries.find((entry) => entry.id === resolvedSource.sourcePageId);
|
|
@@ -40237,7 +41070,7 @@ async function buildCompileProposals(input, paths, now, resolvedSource) {
|
|
|
40237
41070
|
target: sourceTarget,
|
|
40238
41071
|
summary: truncateSummary(`Compile source page ${sourcePageTitle}`),
|
|
40239
41072
|
entry: sourceEntry,
|
|
40240
|
-
baseHash: sourceExists ? computeContentHash(await readPatchFile(
|
|
41073
|
+
baseHash: sourceExists ? computeContentHash(await readPatchFile(path19__default.join(paths.root, sourceTarget))) : void 0,
|
|
40241
41074
|
baseVersion: existingSourceEntry?.version
|
|
40242
41075
|
}];
|
|
40243
41076
|
const relatedCandidates = await discoverRelatedEntryCandidates(paths, resolvedSource.sourceContent, resolvedSource.sourceTitle);
|
|
@@ -40257,7 +41090,7 @@ async function buildCompileProposals(input, paths, now, resolvedSource) {
|
|
|
40257
41090
|
rawSourceRefs: mergeRawSourceRefs(existing.rawSourceRefs, existing.rawSourceRef, { ref: resolvedSource.rawSourceRef }),
|
|
40258
41091
|
body: appendSourceCompileNote(existing.body, resolvedSource.sourcePageId, resolvedSource.rawSourceRef)
|
|
40259
41092
|
},
|
|
40260
|
-
baseHash: computeContentHash(await readPatchFile(
|
|
41093
|
+
baseHash: computeContentHash(await readPatchFile(path19__default.join(paths.wikiDir, `${existing.id}.md`))),
|
|
40261
41094
|
baseVersion: existing.version
|
|
40262
41095
|
});
|
|
40263
41096
|
}
|
|
@@ -40431,7 +41264,7 @@ async function planIngest(input, paths, now) {
|
|
|
40431
41264
|
const target2 = `wiki/${input.id}.md`;
|
|
40432
41265
|
const proposer = input.proposer ?? "tool:wiki_ingest";
|
|
40433
41266
|
const currentEntry = await readWikiEntry(input.id, paths);
|
|
40434
|
-
const currentMarkdown = currentEntry ? await readPatchFile(
|
|
41267
|
+
const currentMarkdown = currentEntry ? await readPatchFile(path19__default.join(paths.wikiDir, `${input.id}.md`)) : void 0;
|
|
40435
41268
|
const currentHash = currentMarkdown ? computeContentHash(currentMarkdown) : void 0;
|
|
40436
41269
|
const rawSource = buildRawSourceEntry(input, now);
|
|
40437
41270
|
await ensureWorkspaceSchema(paths);
|
|
@@ -40626,7 +41459,7 @@ async function stageIngestPlan(plan, paths) {
|
|
|
40626
41459
|
})
|
|
40627
41460
|
};
|
|
40628
41461
|
if (plan.kind === "conflict") {
|
|
40629
|
-
const
|
|
41462
|
+
const record7 = await createConflict({
|
|
40630
41463
|
reason: plan.conflict.reason,
|
|
40631
41464
|
target: `wiki/${entry.id}.md`,
|
|
40632
41465
|
wikiId: entry.id,
|
|
@@ -40644,17 +41477,17 @@ async function stageIngestPlan(plan, paths) {
|
|
|
40644
41477
|
warnings: plan.warnings
|
|
40645
41478
|
}, paths);
|
|
40646
41479
|
await appendLog(paths, "conflict detected", {
|
|
40647
|
-
conflict_id:
|
|
41480
|
+
conflict_id: record7.meta.id,
|
|
40648
41481
|
patch_id: null,
|
|
40649
41482
|
raw_source_ref: rawSourceRef,
|
|
40650
41483
|
reason: plan.conflict.reason,
|
|
40651
|
-
target:
|
|
40652
|
-
wiki_id:
|
|
41484
|
+
target: record7.meta.target,
|
|
41485
|
+
wiki_id: record7.meta.wikiId
|
|
40653
41486
|
});
|
|
40654
41487
|
return {
|
|
40655
41488
|
ok: false,
|
|
40656
41489
|
mode: plan.mode,
|
|
40657
|
-
conflict_id:
|
|
41490
|
+
conflict_id: record7.meta.id,
|
|
40658
41491
|
raw_source_ref: rawSourceRef,
|
|
40659
41492
|
warnings: plan.warnings
|
|
40660
41493
|
};
|
|
@@ -41110,11 +41943,11 @@ async function editQueuedPatch(input, paths) {
|
|
|
41110
41943
|
};
|
|
41111
41944
|
}
|
|
41112
41945
|
async function readQueuedPatchSnapshot(paths, patchId) {
|
|
41113
|
-
const queueDir =
|
|
41114
|
-
const markdown = await readPatchFile(
|
|
41946
|
+
const queueDir = path19__default.join(paths.queueDir, patchId);
|
|
41947
|
+
const markdown = await readPatchFile(path19__default.join(queueDir, PATCH_FILENAME));
|
|
41115
41948
|
return {
|
|
41116
41949
|
patch: await parsePatch(markdown),
|
|
41117
|
-
meta: await readJsonFile2(
|
|
41950
|
+
meta: await readJsonFile2(path19__default.join(queueDir, PATCH_META_FILENAME)),
|
|
41118
41951
|
patchHash: computeContentHash(markdown)
|
|
41119
41952
|
};
|
|
41120
41953
|
}
|
|
@@ -41200,11 +42033,11 @@ function applyBodyReplacement(entry, replaceInput) {
|
|
|
41200
42033
|
}
|
|
41201
42034
|
function parseBodyReplace(value) {
|
|
41202
42035
|
if (value === void 0 || value === null) return void 0;
|
|
41203
|
-
const
|
|
42036
|
+
const record7 = value;
|
|
41204
42037
|
return {
|
|
41205
|
-
find: String(
|
|
41206
|
-
replace: String(
|
|
41207
|
-
expected_occurrences: typeof
|
|
42038
|
+
find: String(record7.find ?? ""),
|
|
42039
|
+
replace: String(record7.replace ?? ""),
|
|
42040
|
+
expected_occurrences: typeof record7.expected_occurrences === "number" ? record7.expected_occurrences : void 0
|
|
41208
42041
|
};
|
|
41209
42042
|
}
|
|
41210
42043
|
function stringParam(value) {
|
|
@@ -41876,7 +42709,7 @@ ${input.answer ?? ""}`)}`;
|
|
|
41876
42709
|
assertSafeEntryId(targetId);
|
|
41877
42710
|
const subdir = input.targetType === "synthesis" ? "synthesis" : "queries";
|
|
41878
42711
|
const target2 = `wiki/${subdir}/${targetId}.md`;
|
|
41879
|
-
const absoluteTarget =
|
|
42712
|
+
const absoluteTarget = path19__default.join(paths.root, target2);
|
|
41880
42713
|
const exists = await pathExists(absoluteTarget);
|
|
41881
42714
|
const existingEntry = exists ? await readWikiEntry(targetId, paths) : null;
|
|
41882
42715
|
if (exists && !existingEntry) {
|
|
@@ -41958,7 +42791,7 @@ function assertSafeRawRef(rawRef) {
|
|
|
41958
42791
|
if (!rawRef.startsWith("raw/")) {
|
|
41959
42792
|
throw new Error(`[fleet-wiki] wiki_query raw source ref must point into raw/: ${rawRef}`);
|
|
41960
42793
|
}
|
|
41961
|
-
if (rawRef.includes("..") ||
|
|
42794
|
+
if (rawRef.includes("..") || path19__default.isAbsolute(rawRef)) {
|
|
41962
42795
|
throw new Error(`[fleet-wiki] wiki_query raw source ref escapes raw/: ${rawRef}`);
|
|
41963
42796
|
}
|
|
41964
42797
|
}
|
|
@@ -42527,15 +43360,15 @@ function buildWikiResolveSpec(resolver) {
|
|
|
42527
43360
|
]
|
|
42528
43361
|
}, resolver);
|
|
42529
43362
|
}
|
|
42530
|
-
function buildWikiToolSpec(config2,
|
|
43363
|
+
function buildWikiToolSpec(config2, usage4, resolver) {
|
|
42531
43364
|
return {
|
|
42532
43365
|
id: config2.name,
|
|
42533
43366
|
tag: config2.name,
|
|
42534
43367
|
title: config2.label,
|
|
42535
43368
|
description: config2.description,
|
|
42536
43369
|
promptSnippet: config2.promptSnippet,
|
|
42537
|
-
whenToUse:
|
|
42538
|
-
whenNotToUse:
|
|
43370
|
+
whenToUse: usage4.whenToUse,
|
|
43371
|
+
whenNotToUse: usage4.whenNotToUse,
|
|
42539
43372
|
usageGuidelines: config2.promptGuidelines,
|
|
42540
43373
|
parameters: config2.parameters,
|
|
42541
43374
|
execute: async (args, ctx) => {
|
|
@@ -42564,16 +43397,16 @@ function createResolver(deps, hooks) {
|
|
|
42564
43397
|
} };
|
|
42565
43398
|
}
|
|
42566
43399
|
function resolveLocked(workspace, hooks) {
|
|
42567
|
-
const destination =
|
|
42568
|
-
const source =
|
|
42569
|
-
const markerPath =
|
|
43400
|
+
const destination = path19__default.join(workspace.path, "knowledge");
|
|
43401
|
+
const source = path19__default.join(workspace.cwd, ".fleet", "knowledge");
|
|
43402
|
+
const markerPath = path19__default.join(workspace.path, MARKER_NAME);
|
|
42570
43403
|
const destinationState = inspectTree(destination, true);
|
|
42571
43404
|
if (destinationState === "content") return createMemoryPaths(destination);
|
|
42572
43405
|
if (destinationState === "unsafe") throw new Error("Unsafe Fleet Wiki destination state");
|
|
42573
43406
|
const marker = readMarker(markerPath);
|
|
42574
43407
|
const stagingEntries = inspectReservedControlState(workspace.path);
|
|
42575
43408
|
if (marker) {
|
|
42576
|
-
const staging2 =
|
|
43409
|
+
const staging2 = path19__default.join(workspace.path, `${STAGING_PREFIX}${marker.transactionId}`);
|
|
42577
43410
|
const stagingState = inspectTree(staging2);
|
|
42578
43411
|
if (stagingState === "content") {
|
|
42579
43412
|
removeEmptyDirectories(destination);
|
|
@@ -42588,7 +43421,7 @@ function resolveLocked(workspace, hooks) {
|
|
|
42588
43421
|
if (sourceState !== "content") return createMemoryPaths(destination);
|
|
42589
43422
|
removeEmptyDirectories(destination);
|
|
42590
43423
|
const transactionId = randomUUID();
|
|
42591
|
-
const staging =
|
|
43424
|
+
const staging = path19__default.join(workspace.path, `${STAGING_PREFIX}${transactionId}`);
|
|
42592
43425
|
copyTree(source, staging, hooks);
|
|
42593
43426
|
if (inspectTree(staging) !== "content") throw new Error("Invalid Fleet Wiki migration staging result");
|
|
42594
43427
|
syncDirectory(staging);
|
|
@@ -42616,7 +43449,7 @@ function inspectTree(target2, regularRootIsContent = false, treeRoot = target2)
|
|
|
42616
43449
|
if (nodeKind === "file") return regularRootIsContent ? "content" : "unsafe";
|
|
42617
43450
|
let content = false;
|
|
42618
43451
|
for (const entry of fs9.readdirSync(target2, { withFileTypes: true })) {
|
|
42619
|
-
const entryPath =
|
|
43452
|
+
const entryPath = path19__default.join(target2, entry.name);
|
|
42620
43453
|
if (entry.isSymbolicLink()) {
|
|
42621
43454
|
if (readSafeFileSymlink(treeRoot, entryPath) === null) return "unsafe";
|
|
42622
43455
|
content = true;
|
|
@@ -42648,15 +43481,15 @@ function readMarker(markerPath) {
|
|
|
42648
43481
|
throw new Error("Invalid Fleet Wiki migration marker");
|
|
42649
43482
|
}
|
|
42650
43483
|
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid Fleet Wiki migration marker");
|
|
42651
|
-
const
|
|
42652
|
-
if (
|
|
42653
|
-
return
|
|
43484
|
+
const record7 = value;
|
|
43485
|
+
if (record7.version !== 1 || record7.outcome !== "copied" || typeof record7.transactionId !== "string" || !/^[0-9a-f-]{36}$/i.test(record7.transactionId) || typeof record7.completedAt !== "string") throw new Error("Invalid Fleet Wiki migration marker");
|
|
43486
|
+
return record7;
|
|
42654
43487
|
}
|
|
42655
43488
|
function copyTree(source, destination, hooks, sourceRoot = source) {
|
|
42656
43489
|
fs9.mkdirSync(destination, { recursive: true });
|
|
42657
43490
|
for (const entry of fs9.readdirSync(source, { withFileTypes: true })) {
|
|
42658
|
-
const from =
|
|
42659
|
-
const to =
|
|
43491
|
+
const from = path19__default.join(source, entry.name);
|
|
43492
|
+
const to = path19__default.join(destination, entry.name);
|
|
42660
43493
|
const stat4 = fs9.lstatSync(from);
|
|
42661
43494
|
if (stat4.isSymbolicLink()) {
|
|
42662
43495
|
const target2 = readSafeFileSymlink(sourceRoot, from);
|
|
@@ -42676,9 +43509,9 @@ function copyTree(source, destination, hooks, sourceRoot = source) {
|
|
|
42676
43509
|
}
|
|
42677
43510
|
function readSafeFileSymlink(treeRoot, linkPath) {
|
|
42678
43511
|
const target2 = fs9.readlinkSync(linkPath);
|
|
42679
|
-
if (
|
|
42680
|
-
const lexicalRoot =
|
|
42681
|
-
const lexicalTarget =
|
|
43512
|
+
if (path19__default.posix.isAbsolute(target2) || path19__default.win32.isAbsolute(target2)) return null;
|
|
43513
|
+
const lexicalRoot = path19__default.resolve(treeRoot);
|
|
43514
|
+
const lexicalTarget = path19__default.resolve(path19__default.dirname(linkPath), target2);
|
|
42682
43515
|
if (!isWithinRoot(lexicalRoot, lexicalTarget)) return null;
|
|
42683
43516
|
let canonicalRoot;
|
|
42684
43517
|
let canonicalTarget;
|
|
@@ -42695,8 +43528,8 @@ function readSafeFileSymlink(treeRoot, linkPath) {
|
|
|
42695
43528
|
return target2;
|
|
42696
43529
|
}
|
|
42697
43530
|
function isWithinRoot(root, target2) {
|
|
42698
|
-
const relative =
|
|
42699
|
-
return relative === "" || relative !== ".." && !relative.startsWith(`..${
|
|
43531
|
+
const relative = path19__default.relative(root, target2);
|
|
43532
|
+
return relative === "" || relative !== ".." && !relative.startsWith(`..${path19__default.sep}`) && !path19__default.isAbsolute(relative);
|
|
42700
43533
|
}
|
|
42701
43534
|
function classifyWikiWorkspaceNodeForTest(stat4) {
|
|
42702
43535
|
if (stat4.isSymbolicLink()) return "unsafe";
|
|
@@ -42711,13 +43544,13 @@ function removeEmptyDirectories(target2) {
|
|
|
42711
43544
|
if (state === "empty") fs9.rmSync(target2, { recursive: true, force: false });
|
|
42712
43545
|
}
|
|
42713
43546
|
function removePriorStaging(workspacePath, stagingEntries) {
|
|
42714
|
-
for (const name of stagingEntries) fs9.rmSync(
|
|
43547
|
+
for (const name of stagingEntries) fs9.rmSync(path19__default.join(workspacePath, name), { recursive: true, force: false });
|
|
42715
43548
|
}
|
|
42716
43549
|
function inspectReservedControlState(workspacePath) {
|
|
42717
43550
|
const stagingEntries = [];
|
|
42718
43551
|
for (const entry of fs9.readdirSync(workspacePath, { withFileTypes: true })) {
|
|
42719
43552
|
if (entry.name.startsWith(`${MARKER_NAME}.`)) {
|
|
42720
|
-
const residuePath =
|
|
43553
|
+
const residuePath = path19__default.join(workspacePath, entry.name);
|
|
42721
43554
|
const residue = fs9.lstatSync(residuePath);
|
|
42722
43555
|
if (MARKER_TEMP_REGEXP.test(entry.name) && residue.isFile() && !residue.isSymbolicLink()) {
|
|
42723
43556
|
fs9.unlinkSync(residuePath);
|
|
@@ -42727,7 +43560,7 @@ function inspectReservedControlState(workspacePath) {
|
|
|
42727
43560
|
}
|
|
42728
43561
|
if (!entry.name.startsWith(STAGING_PREFIX)) continue;
|
|
42729
43562
|
if (!/^[0-9a-f-]{36}$/i.test(entry.name.slice(STAGING_PREFIX.length)) || entry.isSymbolicLink() || !entry.isDirectory()) throw new Error("Unsafe Fleet Wiki migration staging state");
|
|
42730
|
-
if (inspectTree(
|
|
43563
|
+
if (inspectTree(path19__default.join(workspacePath, entry.name)) === "unsafe") throw new Error("Unsafe Fleet Wiki migration staging state");
|
|
42731
43564
|
stagingEntries.push(entry.name);
|
|
42732
43565
|
}
|
|
42733
43566
|
return stagingEntries;
|
|
@@ -42812,18 +43645,18 @@ function resolveConsolePackageRequire(currentFile, fallback) {
|
|
|
42812
43645
|
function findConsolePackageRequire(currentFile) {
|
|
42813
43646
|
const explicitRoot = process.env.FLEET_CONSOLE_PACKAGE_ROOT;
|
|
42814
43647
|
if (explicitRoot) {
|
|
42815
|
-
const explicitPackageJson =
|
|
43648
|
+
const explicitPackageJson = path19__default.join(explicitRoot, "package.json");
|
|
42816
43649
|
if (isFleetConsolePackage(explicitPackageJson)) return createRequire(explicitPackageJson);
|
|
42817
43650
|
}
|
|
42818
|
-
let dir =
|
|
43651
|
+
let dir = path19__default.dirname(currentFile);
|
|
42819
43652
|
while (true) {
|
|
42820
|
-
const packageJson =
|
|
43653
|
+
const packageJson = path19__default.join(dir, "package.json");
|
|
42821
43654
|
if (isFleetConsolePackage(packageJson)) return createRequire(packageJson);
|
|
42822
|
-
const nestedConsolePackage =
|
|
43655
|
+
const nestedConsolePackage = path19__default.join(dir, "runtime", "fleet-console", "package.json");
|
|
42823
43656
|
if (isFleetConsolePackage(nestedConsolePackage)) return createRequire(nestedConsolePackage);
|
|
42824
|
-
const siblingConsolePackage =
|
|
43657
|
+
const siblingConsolePackage = path19__default.join(dir, "..", "..", "fleet-console", "package.json");
|
|
42825
43658
|
if (isFleetConsolePackage(siblingConsolePackage)) return createRequire(siblingConsolePackage);
|
|
42826
|
-
const parent =
|
|
43659
|
+
const parent = path19__default.dirname(dir);
|
|
42827
43660
|
if (parent === dir) return null;
|
|
42828
43661
|
dir = parent;
|
|
42829
43662
|
}
|
|
@@ -42890,7 +43723,7 @@ function resolveUseConptyDll(platform, env) {
|
|
|
42890
43723
|
}
|
|
42891
43724
|
function loadNodePty() {
|
|
42892
43725
|
const nodePtyRequire = loadNodePtyRequire(fileURLToPath(import.meta.url));
|
|
42893
|
-
ensureNodePtySpawnHelpersExecutable(
|
|
43726
|
+
ensureNodePtySpawnHelpersExecutable(path19__default.dirname(nodePtyRequire.resolve("node-pty/package.json")));
|
|
42894
43727
|
return nodePtyRequire("node-pty");
|
|
42895
43728
|
}
|
|
42896
43729
|
function loadNodePtyRequire(currentFile) {
|
|
@@ -42899,7 +43732,7 @@ function loadNodePtyRequire(currentFile) {
|
|
|
42899
43732
|
function ensureNodePtySpawnHelpersExecutable(packageRoot, platform = process4.platform, architecture = process4.arch) {
|
|
42900
43733
|
if (platform !== "darwin") return;
|
|
42901
43734
|
for (const directory of ["build/Release", "build/Debug", `prebuilds/darwin-${architecture}`]) {
|
|
42902
|
-
const helper =
|
|
43735
|
+
const helper = path19__default.join(packageRoot, directory, "spawn-helper");
|
|
42903
43736
|
try {
|
|
42904
43737
|
const stat4 = lstatSync(helper);
|
|
42905
43738
|
if (!stat4.isFile() || stat4.isSymbolicLink() || (stat4.mode & 73) === 73) continue;
|
|
@@ -43600,7 +44433,7 @@ function serializeAgentCliPathsWrite(write) {
|
|
|
43600
44433
|
return result;
|
|
43601
44434
|
}
|
|
43602
44435
|
function normalizeAgentCliPaths(value) {
|
|
43603
|
-
if (!
|
|
44436
|
+
if (!isRecord12(value) || value.version !== 1 || !isRecord12(value.paths)) {
|
|
43604
44437
|
return { version: 1, paths: {} };
|
|
43605
44438
|
}
|
|
43606
44439
|
const paths = {};
|
|
@@ -43615,7 +44448,7 @@ function resolveAgentCliBinary(options) {
|
|
|
43615
44448
|
const envName = OVERRIDE_ENV_BY_COMMAND[options.cliCommand];
|
|
43616
44449
|
const envOverride = envName ? options.env[envName]?.trim() : void 0;
|
|
43617
44450
|
if (envOverride) {
|
|
43618
|
-
const searchedPathEntries2 =
|
|
44451
|
+
const searchedPathEntries2 = path19__default.isAbsolute(envOverride) ? [] : readPathEntries(options.env, platform);
|
|
43619
44452
|
const resolved2 = resolveBinarySafely(envOverride, options.env, platform);
|
|
43620
44453
|
if (!resolved2) {
|
|
43621
44454
|
return { resolved: void 0, source: "env", error: "path_not_found", launchPath: envOverride, searchedPathEntries: searchedPathEntries2 };
|
|
@@ -43657,7 +44490,7 @@ function applyAgentCliPathEnvOverlay(env, cliId, userPaths) {
|
|
|
43657
44490
|
return { ...env, [envName]: userPath };
|
|
43658
44491
|
}
|
|
43659
44492
|
function resolveConfiguredPath(executablePath, env, platform) {
|
|
43660
|
-
if (executablePath.includes("\0") || executablePath.startsWith("~") || !
|
|
44493
|
+
if (executablePath.includes("\0") || executablePath.startsWith("~") || !path19__default.isAbsolute(executablePath)) {
|
|
43661
44494
|
return { resolved: void 0, error: "path_not_absolute" };
|
|
43662
44495
|
}
|
|
43663
44496
|
let stats;
|
|
@@ -43698,10 +44531,10 @@ function validateResolvedFile(resolved, platform) {
|
|
|
43698
44531
|
}
|
|
43699
44532
|
function readPathEntries(env, platform) {
|
|
43700
44533
|
const value = platform === "win32" ? env.Path ?? env.PATH ?? "" : env.PATH ?? "";
|
|
43701
|
-
const separator = platform === "win32" ? ";" :
|
|
44534
|
+
const separator = platform === "win32" ? ";" : path19__default.delimiter;
|
|
43702
44535
|
return value.split(separator).filter((entry) => entry.length > 0);
|
|
43703
44536
|
}
|
|
43704
|
-
function
|
|
44537
|
+
function isRecord12(value) {
|
|
43705
44538
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43706
44539
|
}
|
|
43707
44540
|
function isNodeError(error51) {
|
|
@@ -44093,9 +44926,9 @@ function claudeGatewayModelCache(options) {
|
|
|
44093
44926
|
|
|
44094
44927
|
// ../../packages/core-agent/src/claude/config-dir.ts
|
|
44095
44928
|
async function createIsolatedClaudeConfigDir(tempRoot = tmpdir()) {
|
|
44096
|
-
const root = await mkdtemp(
|
|
44097
|
-
const cachePath =
|
|
44098
|
-
await mkdir(
|
|
44929
|
+
const root = await mkdtemp(path19__default.join(tempRoot, "core-agent-claude-"));
|
|
44930
|
+
const cachePath = path19__default.join(root, CLAUDE_GATEWAY_MODEL_CACHE_RELPATH);
|
|
44931
|
+
await mkdir(path19__default.dirname(cachePath), { recursive: true, mode: 448 });
|
|
44099
44932
|
let disposed = false;
|
|
44100
44933
|
return {
|
|
44101
44934
|
path: root,
|
|
@@ -44381,7 +45214,7 @@ function buildConsoleAutoNameHookCommand(entry) {
|
|
|
44381
45214
|
return buildConsoleCliHookExec(entry, ["hook", "auto-name"]);
|
|
44382
45215
|
}
|
|
44383
45216
|
function buildConsoleCaptureHookCommand(entry, cliId, createCaptureHook = createSessionCaptureHookExec) {
|
|
44384
|
-
const extension =
|
|
45217
|
+
const extension = path19__default.extname(entry.entryPath);
|
|
44385
45218
|
if (JAVASCRIPT_ENTRY_EXTENSIONS.has(extension)) {
|
|
44386
45219
|
return createCaptureHook({
|
|
44387
45220
|
entryPath: entry.entryPath,
|
|
@@ -44407,11 +45240,11 @@ function toCaptureProvider(cliId) {
|
|
|
44407
45240
|
}
|
|
44408
45241
|
function withConsoleMarketplaceLock(target2, fn) {
|
|
44409
45242
|
const lockDir = `${target2}${MARKETPLACE_LOCK_DIR_SUFFIX}`;
|
|
44410
|
-
mkdirSync(
|
|
45243
|
+
mkdirSync(path19__default.dirname(lockDir), { recursive: true });
|
|
44411
45244
|
return withDirectoryLock({ lockDir }, fn);
|
|
44412
45245
|
}
|
|
44413
45246
|
function buildConsoleCliHookExec(entry, trailingArgs) {
|
|
44414
|
-
const extension =
|
|
45247
|
+
const extension = path19__default.extname(entry.entryPath);
|
|
44415
45248
|
if (JAVASCRIPT_ENTRY_EXTENSIONS.has(extension)) {
|
|
44416
45249
|
return {
|
|
44417
45250
|
command: entry.execPath,
|
|
@@ -44526,7 +45359,7 @@ function resolveHookEntryPath(candidate) {
|
|
|
44526
45359
|
return CONSOLE_ENTRY_PATH;
|
|
44527
45360
|
}
|
|
44528
45361
|
function hasHookEntryExtension(entryPath) {
|
|
44529
|
-
return HOOK_ENTRY_EXTENSIONS.has(
|
|
45362
|
+
return HOOK_ENTRY_EXTENSIONS.has(path19__default.extname(entryPath));
|
|
44530
45363
|
}
|
|
44531
45364
|
async function createAgentCliLaunchSpec(options) {
|
|
44532
45365
|
const cleanupStack = [];
|
|
@@ -44765,7 +45598,7 @@ function createConsoleObservabilityStore(deps = {}) {
|
|
|
44765
45598
|
return terminalSessionsById.get(sessionId)?.cwd ?? workspacesByCliRunId.get(sessionId)?.session.cwd ?? null;
|
|
44766
45599
|
}
|
|
44767
45600
|
function createPendingTerminalSession(input) {
|
|
44768
|
-
if (!
|
|
45601
|
+
if (!path19__default.isAbsolute(input.cwd)) throw new Error("Terminal session cwd must be absolute");
|
|
44769
45602
|
const createdAt = input.createdAt ?? now();
|
|
44770
45603
|
const canonicalCwd = canonicalizeTheaterPath(input.cwd);
|
|
44771
45604
|
const theaterId = workspaceHash(canonicalCwd);
|
|
@@ -44775,7 +45608,7 @@ function createConsoleObservabilityStore(deps = {}) {
|
|
|
44775
45608
|
sessionId: input.sessionId,
|
|
44776
45609
|
cwd: input.cwd,
|
|
44777
45610
|
canonicalCwd,
|
|
44778
|
-
cwdLabel:
|
|
45611
|
+
cwdLabel: path19__default.basename(input.cwd) || input.cwd,
|
|
44779
45612
|
cliId: input.cliId,
|
|
44780
45613
|
createdAt,
|
|
44781
45614
|
theaterId,
|
|
@@ -44792,7 +45625,7 @@ function createConsoleObservabilityStore(deps = {}) {
|
|
|
44792
45625
|
sessionId: operation.sessionId,
|
|
44793
45626
|
cwd: operation.cwd,
|
|
44794
45627
|
canonicalCwd: canonicalizeTheaterPath(operation.cwd),
|
|
44795
|
-
cwdLabel:
|
|
45628
|
+
cwdLabel: path19__default.basename(operation.cwd) || operation.cwd,
|
|
44796
45629
|
label: operation.label,
|
|
44797
45630
|
labelSource: operation.labelSource,
|
|
44798
45631
|
providerTitle: operation.providerTitle,
|
|
@@ -45053,7 +45886,7 @@ function defaultWorkspaceHash(canonicalCwd) {
|
|
|
45053
45886
|
return crypto5.createHash("sha256").update(canonicalCwd).digest("hex").slice(0, 12);
|
|
45054
45887
|
}
|
|
45055
45888
|
function defaultCanonicalizeTheaterPath(cwd) {
|
|
45056
|
-
const resolved =
|
|
45889
|
+
const resolved = path19__default.resolve(cwd);
|
|
45057
45890
|
try {
|
|
45058
45891
|
return fs9__default.realpathSync.native(resolved);
|
|
45059
45892
|
} catch {
|
|
@@ -45483,24 +46316,24 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
|
|
|
45483
46316
|
registerCleanup: (cleanup2) => ctx.host.lifecycle.registerCleanup(cleanup2)
|
|
45484
46317
|
});
|
|
45485
46318
|
async function handle({ req, res, pathname }) {
|
|
45486
|
-
const
|
|
45487
|
-
if (
|
|
46319
|
+
const path43 = pathname.slice(`${ctx.basePath}/agent`.length) || "/";
|
|
46320
|
+
if (path43 === "/state") {
|
|
45488
46321
|
if (req.method !== "GET") return methodNotAllowed2(res);
|
|
45489
46322
|
ctx.host.http.writeJson(res, 200, { agentClis: await buildAgentCliLaunchMetadata() });
|
|
45490
46323
|
return true;
|
|
45491
46324
|
}
|
|
45492
|
-
if (
|
|
46325
|
+
if (path43 === "/agent-cli/state") {
|
|
45493
46326
|
if (req.method !== "GET") return methodNotAllowed2(res);
|
|
45494
46327
|
ctx.host.http.writeJson(res, 200, { clis: await detector.detect() });
|
|
45495
46328
|
return true;
|
|
45496
46329
|
}
|
|
45497
|
-
if (
|
|
46330
|
+
if (path43 === "/agent-cli/diagnostics") {
|
|
45498
46331
|
if (req.method !== "GET") return methodNotAllowed2(res);
|
|
45499
46332
|
if (!ctx.host.security.isTerminalAuthorized(req)) return unauthorized(res);
|
|
45500
46333
|
ctx.host.http.writeJson(res, 200, await buildAgentCliDiagnostics());
|
|
45501
46334
|
return true;
|
|
45502
46335
|
}
|
|
45503
|
-
if (
|
|
46336
|
+
if (path43 === "/agent-cli/path") {
|
|
45504
46337
|
if (req.method !== "PUT") return methodNotAllowed2(res);
|
|
45505
46338
|
if (!ctx.host.security.isTerminalAuthorized(req)) return unauthorized(res);
|
|
45506
46339
|
const body = await ctx.host.http.readJsonBody(req);
|
|
@@ -45520,15 +46353,15 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
|
|
|
45520
46353
|
ctx.host.http.writeJson(res, 200, { ok: true });
|
|
45521
46354
|
return true;
|
|
45522
46355
|
}
|
|
45523
|
-
if (
|
|
46356
|
+
if (path43 === "/events") {
|
|
45524
46357
|
if (req.method !== "GET") return methodNotAllowed2(res);
|
|
45525
46358
|
writeAgentSessionEvents(req, res, observability);
|
|
45526
46359
|
return true;
|
|
45527
46360
|
}
|
|
45528
|
-
if (
|
|
45529
|
-
const sessionMatch =
|
|
46361
|
+
if (path43 === "/sessions") return handleSessions(req, res);
|
|
46362
|
+
const sessionMatch = path43.match(/^\/sessions\/([^/]+)(?:\/([^/]+))?$/);
|
|
45530
46363
|
if (sessionMatch) return handleSessionItem(req, res, decodeURIComponent(sessionMatch[1] ?? ""), sessionMatch[2] ?? "");
|
|
45531
|
-
if (
|
|
46364
|
+
if (path43 === "/ticket") {
|
|
45532
46365
|
if (req.method !== "POST") return methodNotAllowed2(res);
|
|
45533
46366
|
if (!ctx.host.security.isTerminalAuthorized(req)) {
|
|
45534
46367
|
ctx.host.http.writeJson(res, 401, { error: "Unauthorized" });
|
|
@@ -45677,16 +46510,18 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
|
|
|
45677
46510
|
}
|
|
45678
46511
|
const sessionId = crypto5.randomUUID();
|
|
45679
46512
|
const session = observability.createPendingTerminalSession({ sessionId, cwd, cliId });
|
|
46513
|
+
const named = launchOptions.prompt === void 0 ? null : observability.autoNameTerminalSession(sessionId, deriveOperationLabel(launchOptions.prompt));
|
|
46514
|
+
const namedSession = named?.session ?? session;
|
|
45680
46515
|
ctx.host.operations.create({
|
|
45681
46516
|
id: session.sessionId,
|
|
45682
46517
|
theaterId,
|
|
45683
46518
|
type: AGENT_OPERATION_TYPE,
|
|
45684
46519
|
pluginId: ctx.pluginId,
|
|
45685
|
-
title: session.label ??
|
|
46520
|
+
title: namedSession.label ?? session.label ?? path19__default.basename(cwd),
|
|
45686
46521
|
// 공급자는 실행 시점에 한 번 확정되고 이후 어떤 patch도 다시 쓰지 않는다 —
|
|
45687
46522
|
// toOperationPayload가 지우는 키 목록 밖이라 resume·복원을 지나도 그대로 남는다.
|
|
45688
46523
|
payload: {
|
|
45689
|
-
...toOperationPayload(void 0, cwd,
|
|
46524
|
+
...toOperationPayload(void 0, cwd, namedSession),
|
|
45690
46525
|
[AGENT_LAUNCH_PROVIDER_PAYLOAD_KEY]: agentLaunchProviderFromModel(launchOptions.model),
|
|
45691
46526
|
// Claude Code의 resume가 launch 좌표를 자체 복원한다고 가정하지 않는다 — 정규화된
|
|
45692
46527
|
// 최초 선택을 Operation에 남겨 dormant·Console 재시작 뒤에도 같은 인자로 재개한다.
|
|
@@ -45712,7 +46547,7 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
|
|
|
45712
46547
|
});
|
|
45713
46548
|
const runtimeSession = pendingRuntimeSessions.get(sessionId);
|
|
45714
46549
|
pendingRuntimeSessions.delete(sessionId);
|
|
45715
|
-
const created = runtimeSession ? observability.registerTerminalRuntimeSession(runtimeSession) ??
|
|
46550
|
+
const created = runtimeSession ? observability.registerTerminalRuntimeSession(runtimeSession) ?? namedSession : observability.updateTerminalSessionStatus(sessionId, "terminal-only") ?? namedSession;
|
|
45716
46551
|
observability.notifySessionUpdated(created);
|
|
45717
46552
|
ctx.host.operations.patch(sessionId, { payload: toOperationPayload(ctx.host.operations.get(sessionId)?.payload, cwd, created, void 0, observability.getDurableOperation(sessionId)?.providerTitle) });
|
|
45718
46553
|
ctx.host.http.writeJson(res, 200, created);
|
|
@@ -45935,7 +46770,7 @@ async function createAgentApi(ctx, terminalRuntime, deps) {
|
|
|
45935
46770
|
if (result?.renamed) {
|
|
45936
46771
|
observability.notifySessionUpdated(result.session);
|
|
45937
46772
|
const autoNameCwd = readPayloadString(ctx.host.operations.get(sessionId)?.payload ?? {}, "cwd") ?? result.session.cwdLabel;
|
|
45938
|
-
ctx.host.operations.patch(sessionId, { title: result.session.label ??
|
|
46773
|
+
ctx.host.operations.patch(sessionId, { title: result.session.label ?? path19__default.basename(autoNameCwd) });
|
|
45939
46774
|
}
|
|
45940
46775
|
ctx.host.http.writeJson(res, 200, { ok: true, renamed: result?.renamed === true });
|
|
45941
46776
|
return true;
|
|
@@ -46152,7 +46987,7 @@ function createTerminalWikiToolSpecs(fleetDataDir) {
|
|
|
46152
46987
|
const resolver = createWikiWorkspaceResolver({
|
|
46153
46988
|
ensureWorkspace: (cwd) => ensureWorkspaceDirectory(fleetDataDir, cwd),
|
|
46154
46989
|
withMigrationLock: (workspace, operation) => withDirectoryLock(
|
|
46155
|
-
{ lockDir:
|
|
46990
|
+
{ lockDir: path19__default.join(workspace.path, "knowledge.migration.lock") },
|
|
46156
46991
|
operation
|
|
46157
46992
|
)
|
|
46158
46993
|
});
|
|
@@ -46636,7 +47471,7 @@ var AnalystTools = class {
|
|
|
46636
47471
|
id: metadata.id,
|
|
46637
47472
|
description: metadata.description,
|
|
46638
47473
|
parameters: metadata.parameters,
|
|
46639
|
-
execute: async (args) => execute(
|
|
47474
|
+
execute: async (args) => execute(record5(args))
|
|
46640
47475
|
};
|
|
46641
47476
|
}
|
|
46642
47477
|
events(args) {
|
|
@@ -46681,7 +47516,7 @@ var AnalystTools = class {
|
|
|
46681
47516
|
return { artifact: { id: artifact.id, title, createdAt: artifact.createdAt } };
|
|
46682
47517
|
}
|
|
46683
47518
|
};
|
|
46684
|
-
function
|
|
47519
|
+
function record5(value) {
|
|
46685
47520
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
46686
47521
|
}
|
|
46687
47522
|
function integer2(value) {
|
|
@@ -46859,9 +47694,9 @@ var AnalystSession = class {
|
|
|
46859
47694
|
};
|
|
46860
47695
|
function toAnalystEvents(event, toolNames, redact) {
|
|
46861
47696
|
if (event.type === "stream_event") {
|
|
46862
|
-
const inner =
|
|
47697
|
+
const inner = record6(event.event);
|
|
46863
47698
|
if (inner.type !== "content_block_delta") return [];
|
|
46864
|
-
const delta =
|
|
47699
|
+
const delta = record6(inner.delta);
|
|
46865
47700
|
if (delta.type === "text_delta" && typeof delta.text === "string" && delta.text.length > 0) {
|
|
46866
47701
|
return [{ type: "chunk", text: redact(delta.text) }];
|
|
46867
47702
|
}
|
|
@@ -46899,10 +47734,10 @@ function toAnalystEvents(event, toolNames, redact) {
|
|
|
46899
47734
|
return [];
|
|
46900
47735
|
}
|
|
46901
47736
|
function blocks(message) {
|
|
46902
|
-
const content =
|
|
46903
|
-
return Array.isArray(content) ? content.map(
|
|
47737
|
+
const content = record6(message).content;
|
|
47738
|
+
return Array.isArray(content) ? content.map(record6) : [];
|
|
46904
47739
|
}
|
|
46905
|
-
function
|
|
47740
|
+
function record6(value) {
|
|
46906
47741
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
46907
47742
|
}
|
|
46908
47743
|
function errorMessage2(error51) {
|
|
@@ -47106,7 +47941,7 @@ function analysisError(code, message) {
|
|
|
47106
47941
|
return { error: { code, message } };
|
|
47107
47942
|
}
|
|
47108
47943
|
function isAnalysisSelection(catalog, value) {
|
|
47109
|
-
if (!
|
|
47944
|
+
if (!isRecord13(value) || !hasExactKeys(value, ["cliId", "model", "effort", "language"]) || typeof value.cliId !== "string" || typeof value.model !== "string" || value.effort !== void 0 && typeof value.effort !== "string" || value.language !== void 0 && value.language !== "en" && value.language !== "ko") return false;
|
|
47110
47945
|
const cli = catalog.clis.find((candidate) => candidate.cliId === value.cliId);
|
|
47111
47946
|
if (!cli?.available) return false;
|
|
47112
47947
|
const model = cli.models.find((candidate) => candidate.id === value.model);
|
|
@@ -47115,9 +47950,9 @@ function isAnalysisSelection(catalog, value) {
|
|
|
47115
47950
|
return typeof value.effort === "string" && value.effort.length > 0 && model.effortLevels.includes(value.effort);
|
|
47116
47951
|
}
|
|
47117
47952
|
function isMessageBody(value) {
|
|
47118
|
-
return
|
|
47953
|
+
return isRecord13(value) && hasExactKeys(value, ["text"]) && typeof value.text === "string" && value.text.trim().length > 0;
|
|
47119
47954
|
}
|
|
47120
|
-
function
|
|
47955
|
+
function isRecord13(value) {
|
|
47121
47956
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
47122
47957
|
}
|
|
47123
47958
|
function hasExactKeys(value, keys) {
|
|
@@ -47150,14 +47985,14 @@ function registerAnalysisRoutes(ctx, deps = {}) {
|
|
|
47150
47985
|
writeError(ctx, res, 403, ANALYSIS_ERROR_CODES.catalogInvalid, "Analysis request is not accepted by this host.");
|
|
47151
47986
|
return true;
|
|
47152
47987
|
}
|
|
47153
|
-
const
|
|
47154
|
-
if (
|
|
47155
|
-
if (
|
|
47156
|
-
const artifactMatch =
|
|
47988
|
+
const path43 = pathname.slice(`${ctx.basePath}/analysis`.length) || "/";
|
|
47989
|
+
if (path43 === "/catalog") return handleCatalog(ctx, req, res, catalog);
|
|
47990
|
+
if (path43 === "/stream") return handleGlobalStream(ctx, req, res, registry3);
|
|
47991
|
+
const artifactMatch = path43.match(/^\/artifacts\/([^/]+)$/);
|
|
47157
47992
|
if (artifactMatch) return handleArtifact(ctx, req, res, decodeURIComponent(artifactMatch[1] ?? ""), registry3);
|
|
47158
|
-
const clearArtifactsMatch =
|
|
47993
|
+
const clearArtifactsMatch = path43.match(/^\/([^/]+)\/artifacts$/);
|
|
47159
47994
|
if (clearArtifactsMatch) return handleClearArtifacts(ctx, req, res, decodeURIComponent(clearArtifactsMatch[1] ?? ""), registry3);
|
|
47160
|
-
const match =
|
|
47995
|
+
const match = path43.match(/^\/([^/]+)\/(ready|start|message|stream|stop)$/);
|
|
47161
47996
|
if (!match) return false;
|
|
47162
47997
|
const operationId = decodeURIComponent(match[1] ?? "");
|
|
47163
47998
|
const action = match[2] ?? "";
|
|
@@ -47607,14 +48442,14 @@ async function handleStop(ctx, req, res, operationId, registry3) {
|
|
|
47607
48442
|
}
|
|
47608
48443
|
async function resolveTranscriptPath(capturePath, operationCreatedAt) {
|
|
47609
48444
|
if (await fileExists2(capturePath)) return capturePath;
|
|
47610
|
-
const dir =
|
|
48445
|
+
const dir = path19__default.dirname(capturePath);
|
|
47611
48446
|
const bornCutoff = operationCreatedAt - 6e4;
|
|
47612
48447
|
try {
|
|
47613
48448
|
const entries = await promises.readdir(dir);
|
|
47614
48449
|
const candidates = [];
|
|
47615
48450
|
for (const entry of entries) {
|
|
47616
48451
|
if (!entry.endsWith(".jsonl")) continue;
|
|
47617
|
-
const candidate =
|
|
48452
|
+
const candidate = path19__default.join(dir, entry);
|
|
47618
48453
|
const stat4 = await promises.stat(candidate).catch(() => null);
|
|
47619
48454
|
if (!stat4?.isFile()) continue;
|
|
47620
48455
|
if (stat4.birthtimeMs > 0 && stat4.birthtimeMs < bornCutoff) continue;
|
|
@@ -47664,7 +48499,7 @@ function artifactHeaders() {
|
|
|
47664
48499
|
return { "Content-Type": "text/html; charset=utf-8", "Content-Security-Policy": ANALYSIS_ARTIFACT_CSP, "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Content-Type-Options": "nosniff" };
|
|
47665
48500
|
}
|
|
47666
48501
|
function registerAiGatewayRoutes(ctx, deps = {}) {
|
|
47667
|
-
const ownedDiagnostics = deps.cursorDiagnostics ? void 0 : createCursorDiagnosticLog(
|
|
48502
|
+
const ownedDiagnostics = deps.cursorDiagnostics ? void 0 : createCursorDiagnosticLog(path19__default.join(
|
|
47668
48503
|
ctx.host.paths.pluginDataDir(ctx.pluginId),
|
|
47669
48504
|
"ai-gateway"
|
|
47670
48505
|
));
|
|
@@ -47674,6 +48509,7 @@ function registerAiGatewayRoutes(ctx, deps = {}) {
|
|
|
47674
48509
|
// 자격증명 조달은 호스트 결정이다 — Console은 core-ai-gateway가 export한 기본 reader를 주입한다.
|
|
47675
48510
|
readAuth: deps.readAuth ?? (() => readCodexSubscriptionAuth()),
|
|
47676
48511
|
readCursorToken: deps.readCursorToken ?? (() => readCursorSubscriptionToken()),
|
|
48512
|
+
readXaiToken: deps.readXaiToken ?? (() => readXaiSubscriptionToken()),
|
|
47677
48513
|
readModelOverride: () => process.env[AI_GATEWAY_MODEL_ENV],
|
|
47678
48514
|
cursorDiagnostics: deps.cursorDiagnostics ?? ownedDiagnostics?.write
|
|
47679
48515
|
});
|
|
@@ -47803,8 +48639,8 @@ function registerTerminalModelAuthRoutes(ctx, deps) {
|
|
|
47803
48639
|
}
|
|
47804
48640
|
function createTerminalModelAuthRouter(ctx, deps) {
|
|
47805
48641
|
return async function handleTerminalModelAuthRoute({ req, res, pathname }) {
|
|
47806
|
-
const
|
|
47807
|
-
if (
|
|
48642
|
+
const path43 = pathname.slice(`${ctx.basePath}/model-auth`.length) || "/";
|
|
48643
|
+
if (path43 === "/state") {
|
|
47808
48644
|
if (req.method !== "GET") {
|
|
47809
48645
|
ctx.host.http.writeJson(res, 405, { error: "Method not allowed" });
|
|
47810
48646
|
return true;
|
|
@@ -47812,7 +48648,7 @@ function createTerminalModelAuthRouter(ctx, deps) {
|
|
|
47812
48648
|
ctx.host.http.writeJson(res, 200, await buildModelAuthState(deps.authService));
|
|
47813
48649
|
return true;
|
|
47814
48650
|
}
|
|
47815
|
-
const providerId = parseProviderPath(
|
|
48651
|
+
const providerId = parseProviderPath(path43);
|
|
47816
48652
|
if (!providerId) return false;
|
|
47817
48653
|
if (!isTerminalModelAuthProviderId(providerId)) {
|
|
47818
48654
|
ctx.host.http.writeJson(res, 404, { error: "provider_not_found" });
|
|
@@ -47880,8 +48716,8 @@ async function findProvider(deps, providerId) {
|
|
|
47880
48716
|
const state = await buildModelAuthState(deps.authService);
|
|
47881
48717
|
return state.providers.find((provider) => provider.provider === providerId) ?? null;
|
|
47882
48718
|
}
|
|
47883
|
-
function parseProviderPath(
|
|
47884
|
-
const parts =
|
|
48719
|
+
function parseProviderPath(path43) {
|
|
48720
|
+
const parts = path43.split("/").filter(Boolean);
|
|
47885
48721
|
if (parts.length !== 2 || parts[0] !== "providers") return null;
|
|
47886
48722
|
try {
|
|
47887
48723
|
return decodeURIComponent(parts[1] ?? "");
|
|
@@ -48016,7 +48852,7 @@ function isRestoredShellEvent(value, pluginId) {
|
|
|
48016
48852
|
var CONTROL_HOLDER_EVENT_CHANNEL = "control:holder";
|
|
48017
48853
|
function applyWireLog(ctx, stored) {
|
|
48018
48854
|
setWireLogTarget(stored === void 0 ? void 0 : stored ? {
|
|
48019
|
-
path:
|
|
48855
|
+
path: path19__default.join(ctx.host.paths.pluginDataDir(ctx.pluginId), "ai-gateway", "wire-log.jsonl"),
|
|
48020
48856
|
maxBytes: DEFAULT_WIRE_LOG_MAX_BYTES
|
|
48021
48857
|
} : null);
|
|
48022
48858
|
}
|