@ycodium-ai/agent-claude 0.2.5557 → 0.2.5751
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/index.js +328 -2921
- package/package.json +3 -8
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as NodePath15 from "node:path";
|
|
3
3
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
4
4
|
|
|
5
5
|
// ../../packages/plugin-api/src/version.ts
|
|
6
|
-
var PLUGIN_API_VERSION =
|
|
6
|
+
var PLUGIN_API_VERSION = 180;
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import {
|
|
@@ -14,6 +14,10 @@ import {
|
|
|
14
14
|
} from "@ycodium-ai/plugin-api/executor";
|
|
15
15
|
|
|
16
16
|
// src/card.ts
|
|
17
|
+
import {
|
|
18
|
+
executorProgramField,
|
|
19
|
+
executorEnvelopeFields
|
|
20
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
17
21
|
var CLAUDE_DRIVER_KIND = "claudeAgent";
|
|
18
22
|
var CLAUDE_CARD = {
|
|
19
23
|
driverKind: CLAUDE_DRIVER_KIND,
|
|
@@ -123,24 +127,9 @@ var CLAUDE_CARD = {
|
|
|
123
127
|
"launchArgs"
|
|
124
128
|
],
|
|
125
129
|
properties: {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
titleKey: "form.binaryPath.title",
|
|
130
|
-
descriptionKey: "form.binaryPath.description",
|
|
131
|
-
placeholderKey: "form.binaryPath.placeholder",
|
|
132
|
-
control: "executable-path"
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
homePath: {
|
|
136
|
-
type: "string",
|
|
137
|
-
"x-ycodium-form": {
|
|
138
|
-
titleKey: "form.homePath.title",
|
|
139
|
-
machineLocal: true,
|
|
140
|
-
descriptionKey: "form.homePath.description",
|
|
141
|
-
placeholderKey: "form.homePath.placeholder"
|
|
142
|
-
}
|
|
143
|
-
},
|
|
130
|
+
...executorEnvelopeFields,
|
|
131
|
+
binaryPath: executorProgramField("binaryPath"),
|
|
132
|
+
homePath: executorProgramField("homePath"),
|
|
144
133
|
credentialsPath: {
|
|
145
134
|
type: "string",
|
|
146
135
|
"x-ycodium-form": {
|
|
@@ -150,14 +139,7 @@ var CLAUDE_CARD = {
|
|
|
150
139
|
placeholderKey: "form.credentialsPath.placeholder"
|
|
151
140
|
}
|
|
152
141
|
},
|
|
153
|
-
launchArgs:
|
|
154
|
-
type: "string",
|
|
155
|
-
"x-ycodium-form": {
|
|
156
|
-
titleKey: "form.launchArgs.title",
|
|
157
|
-
descriptionKey: "form.launchArgs.description",
|
|
158
|
-
placeholderKey: "form.launchArgs.placeholder"
|
|
159
|
-
}
|
|
160
|
-
},
|
|
142
|
+
launchArgs: executorProgramField("launchArgs"),
|
|
161
143
|
autoCompactWindow: {
|
|
162
144
|
type: "string",
|
|
163
145
|
// 空,或 100000 到 1000000 的整数(与服务端设置校验同一条规则)。
|
|
@@ -167,12 +149,7 @@ var CLAUDE_CARD = {
|
|
|
167
149
|
descriptionKey: "form.autoCompactWindow.description",
|
|
168
150
|
placeholderKey: "form.autoCompactWindow.placeholder"
|
|
169
151
|
}
|
|
170
|
-
}
|
|
171
|
-
customModels: { type: "array" },
|
|
172
|
-
enabled: { type: "boolean" },
|
|
173
|
-
driver: { type: "string" },
|
|
174
|
-
config: { type: "object" },
|
|
175
|
-
environment: { type: "array" }
|
|
152
|
+
}
|
|
176
153
|
},
|
|
177
154
|
additionalProperties: true
|
|
178
155
|
},
|
|
@@ -215,76 +192,24 @@ var CLAUDE_CARD = {
|
|
|
215
192
|
};
|
|
216
193
|
|
|
217
194
|
// src/claudeAccount.ts
|
|
218
|
-
import * as NodeOS3 from "node:os";
|
|
219
|
-
import * as NodePath3 from "node:path";
|
|
220
|
-
|
|
221
|
-
// ../../packages/ycodium-credential-account/src/credentialAccount.ts
|
|
222
|
-
import * as NodeFS from "node:fs";
|
|
223
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
224
|
-
var parseJsonRecord = (raw) => {
|
|
225
|
-
let parsed;
|
|
226
|
-
try {
|
|
227
|
-
parsed = JSON.parse(raw);
|
|
228
|
-
} catch {
|
|
229
|
-
return void 0;
|
|
230
|
-
}
|
|
231
|
-
return isRecord(parsed) ? parsed : void 0;
|
|
232
|
-
};
|
|
233
|
-
var directoryExists = (homePath) => {
|
|
234
|
-
try {
|
|
235
|
-
return NodeFS.statSync(homePath).isDirectory();
|
|
236
|
-
} catch {
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
var readCredentialFile = (path) => {
|
|
241
|
-
try {
|
|
242
|
-
return NodeFS.readFileSync(path, "utf8");
|
|
243
|
-
} catch {
|
|
244
|
-
return void 0;
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
var accountWithoutIdentity = (state, exists) => ({
|
|
248
|
-
state,
|
|
249
|
-
directoryExists: exists,
|
|
250
|
-
email: void 0,
|
|
251
|
-
name: void 0,
|
|
252
|
-
expiresAt: void 0
|
|
253
|
-
});
|
|
254
|
-
var epochMillisToIso = (value) => {
|
|
255
|
-
if (value === void 0 || !Number.isFinite(value)) return void 0;
|
|
256
|
-
const date = new Date(value);
|
|
257
|
-
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
// ../../packages/ycodium-instance-config/src/homePath.ts
|
|
261
|
-
import * as NodeOS from "node:os";
|
|
262
|
-
import * as NodePath from "node:path";
|
|
263
|
-
import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
|
|
264
|
-
function expandHomePath(value) {
|
|
265
|
-
if (value === "~") return NodeOS.homedir();
|
|
266
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
267
|
-
return NodePath.join(NodeOS.homedir(), value.slice(2));
|
|
268
|
-
}
|
|
269
|
-
return value;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/claudeHome.ts
|
|
273
195
|
import * as NodeOS2 from "node:os";
|
|
274
196
|
import * as NodePath2 from "node:path";
|
|
197
|
+
import {
|
|
198
|
+
accountWithoutIdentity,
|
|
199
|
+
directoryExists,
|
|
200
|
+
epochMillisToIso,
|
|
201
|
+
isRecord,
|
|
202
|
+
parseJsonRecord,
|
|
203
|
+
readCredentialFile
|
|
204
|
+
} from "@ycodium-ai/plugin-api/credential-account";
|
|
275
205
|
|
|
276
|
-
//
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
const hours = Math.floor(totalMinutes % (24 * 60) / 60);
|
|
281
|
-
const minutes = totalMinutes % 60;
|
|
282
|
-
if (days > 0) return hours === 0 ? `${String(days)}d` : `${String(days)}d ${String(hours)}h`;
|
|
283
|
-
if (hours === 0) return `${String(totalMinutes)}m`;
|
|
284
|
-
return minutes === 0 ? `${String(hours)}h` : `${String(hours)}h ${String(minutes)}m`;
|
|
285
|
-
}
|
|
206
|
+
// src/claudeHome.ts
|
|
207
|
+
import { expandHomePath } from "@ycodium-ai/plugin-api/instance-config";
|
|
208
|
+
import * as NodeOS from "node:os";
|
|
209
|
+
import * as NodePath from "node:path";
|
|
286
210
|
|
|
287
211
|
// src/usageLimit.ts
|
|
212
|
+
import { formatCoarseWait } from "@ycodium-ai/plugin-api/display-format";
|
|
288
213
|
var WINDOW_NAMES = {
|
|
289
214
|
five_hour: "5-hour",
|
|
290
215
|
seven_day: "7-day",
|
|
@@ -326,7 +251,7 @@ var describeUsageLimitFailure = (rejected, nowMs) => {
|
|
|
326
251
|
var CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE = "CLAUDE_SECURESTORAGE_CONFIG_DIR";
|
|
327
252
|
function resolveClaudeHomePath(homePath) {
|
|
328
253
|
const trimmed = homePath.trim();
|
|
329
|
-
return
|
|
254
|
+
return NodePath.resolve(trimmed.length > 0 ? expandHomePath(trimmed) : NodeOS.homedir());
|
|
330
255
|
}
|
|
331
256
|
function claudeContinuationKey(homePath) {
|
|
332
257
|
return `claude:home:${resolveClaudeHomePath(homePath)}`;
|
|
@@ -334,18 +259,18 @@ function claudeContinuationKey(homePath) {
|
|
|
334
259
|
function resolveClaudeConfigDirPath(homePath, environment, cwd) {
|
|
335
260
|
const trimmed = homePath.trim();
|
|
336
261
|
if (trimmed.length > 0) {
|
|
337
|
-
return
|
|
262
|
+
return NodePath.resolve(expandHomePath(trimmed));
|
|
338
263
|
}
|
|
339
264
|
const environmentConfigDir = environment.CLAUDE_CONFIG_DIR?.trim() ?? "";
|
|
340
265
|
if (environmentConfigDir.length > 0) {
|
|
341
|
-
return cwd ?
|
|
266
|
+
return cwd ? NodePath.resolve(cwd, environmentConfigDir) : NodePath.resolve(environmentConfigDir);
|
|
342
267
|
}
|
|
343
|
-
return
|
|
268
|
+
return NodePath.join(NodeOS.homedir(), ".claude");
|
|
344
269
|
}
|
|
345
270
|
function resolveClaudeCredentialsDirPath(credentialsPath) {
|
|
346
271
|
const trimmed = credentialsPath.trim();
|
|
347
272
|
if (trimmed.length === 0) return null;
|
|
348
|
-
return
|
|
273
|
+
return NodePath.resolve(expandHomePath(trimmed));
|
|
349
274
|
}
|
|
350
275
|
function resolveClaudeHomeLayout(input) {
|
|
351
276
|
return {
|
|
@@ -376,13 +301,13 @@ function claudeSignedOutMessage(input) {
|
|
|
376
301
|
const configDir = input.configDir?.trim() ?? "";
|
|
377
302
|
if (configDir.length > 0) {
|
|
378
303
|
variables.push(
|
|
379
|
-
`CLAUDE_CONFIG_DIR set to ${quoteLiteral(
|
|
304
|
+
`CLAUDE_CONFIG_DIR set to ${quoteLiteral(NodePath.resolve(input.cwd, configDir))}`
|
|
380
305
|
);
|
|
381
306
|
}
|
|
382
307
|
const credentialsDir = input.credentialsDir?.trim() ?? "";
|
|
383
308
|
if (credentialsDir.length > 0) {
|
|
384
309
|
variables.push(
|
|
385
|
-
`${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(
|
|
310
|
+
`${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(NodePath.resolve(input.cwd, credentialsDir))}`
|
|
386
311
|
);
|
|
387
312
|
}
|
|
388
313
|
const withVariables = variables.length > 0 ? `, with ${variables.join(" and ")}` : "";
|
|
@@ -412,19 +337,19 @@ function claudeFailureHint(input) {
|
|
|
412
337
|
// src/claudeAccount.ts
|
|
413
338
|
var OAUTH_KEY = "claudeAiOauth";
|
|
414
339
|
function resolveClaudeAccountDirectory(credentialsDirPath) {
|
|
415
|
-
return credentialsDirPath ??
|
|
340
|
+
return credentialsDirPath ?? NodePath2.join(NodeOS2.homedir(), ".claude");
|
|
416
341
|
}
|
|
417
342
|
function claudeCredentialCandidatePaths(input) {
|
|
418
343
|
return input.credentialsDirPath === null ? [
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
] : [
|
|
344
|
+
NodePath2.join(input.homePath, ".claude", ".credentials.json"),
|
|
345
|
+
NodePath2.join(input.homePath, ".credentials.json")
|
|
346
|
+
] : [NodePath2.join(input.credentialsDirPath, ".credentials.json")];
|
|
422
347
|
}
|
|
423
348
|
function readClaudeAccount(credentialsDirPath, credentialCandidates) {
|
|
424
349
|
const accountDirectory = resolveClaudeAccountDirectory(credentialsDirPath);
|
|
425
350
|
const exists = directoryExists(accountDirectory);
|
|
426
351
|
const candidates = credentialCandidates ?? claudeCredentialCandidatePaths({
|
|
427
|
-
homePath:
|
|
352
|
+
homePath: NodeOS2.homedir(),
|
|
428
353
|
credentialsDirPath
|
|
429
354
|
});
|
|
430
355
|
let raw;
|
|
@@ -460,1431 +385,14 @@ var probeClaudeAccount = (accountPath) => {
|
|
|
460
385
|
};
|
|
461
386
|
|
|
462
387
|
// src/liveHistory.ts
|
|
463
|
-
import * as
|
|
464
|
-
import * as NodeProcess2 from "node:process";
|
|
465
|
-
|
|
466
|
-
// ../../packages/ycodium-jsonl-stream/src/historyErrors.ts
|
|
467
|
-
var NativeHistoryCursorError = class extends Error {
|
|
468
|
-
name = "NativeHistoryCursorError";
|
|
469
|
-
};
|
|
470
|
-
var NativeHistoryPendingError = class extends Error {
|
|
471
|
-
name = "NativeHistoryPendingError";
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
// ../../packages/ycodium-jsonl-stream/src/historyWaiting.ts
|
|
475
|
-
import * as NodeFS2 from "node:fs";
|
|
476
|
-
import * as NodeFSP from "node:fs/promises";
|
|
477
|
-
import * as NodePath4 from "node:path";
|
|
478
|
-
var pending = (error) => error instanceof NativeHistoryPendingError || error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
479
|
-
var waitForJsonlHistory = (input) => {
|
|
480
|
-
const controller = new AbortController();
|
|
481
|
-
const sources = /* @__PURE__ */ new Set();
|
|
482
|
-
const operations = /* @__PURE__ */ new Set();
|
|
483
|
-
const own = (promise) => {
|
|
484
|
-
operations.add(promise);
|
|
485
|
-
void promise.finally(() => operations.delete(promise)).catch(() => void 0);
|
|
486
|
-
return promise;
|
|
487
|
-
};
|
|
488
|
-
const iterators = /* @__PURE__ */ new Set();
|
|
489
|
-
const open2 = () => own(
|
|
490
|
-
(async () => {
|
|
491
|
-
const signal = AbortSignal.any([
|
|
492
|
-
controller.signal,
|
|
493
|
-
...input.signal ? [input.signal] : []
|
|
494
|
-
]);
|
|
495
|
-
const source = await input.open(signal);
|
|
496
|
-
if (source === void 0) throw new NativeHistoryPendingError();
|
|
497
|
-
sources.add(source);
|
|
498
|
-
return source;
|
|
499
|
-
})()
|
|
500
|
-
);
|
|
501
|
-
const release = async (source) => {
|
|
502
|
-
await source.close();
|
|
503
|
-
sources.delete(source);
|
|
504
|
-
};
|
|
505
|
-
return {
|
|
506
|
-
page: (options) => own(
|
|
507
|
-
(async () => {
|
|
508
|
-
const source = await open2();
|
|
509
|
-
try {
|
|
510
|
-
return await source.page(options);
|
|
511
|
-
} finally {
|
|
512
|
-
await release(source);
|
|
513
|
-
}
|
|
514
|
-
})()
|
|
515
|
-
),
|
|
516
|
-
follow: (options) => {
|
|
517
|
-
let iterator;
|
|
518
|
-
iterator = (async function* () {
|
|
519
|
-
const signal = AbortSignal.any([
|
|
520
|
-
controller.signal,
|
|
521
|
-
...input.signal ? [input.signal] : [],
|
|
522
|
-
...options.signal ? [options.signal] : []
|
|
523
|
-
]);
|
|
524
|
-
let root = NodePath4.resolve(input.root);
|
|
525
|
-
while (true) {
|
|
526
|
-
try {
|
|
527
|
-
if ((await NodeFSP.stat(root)).isDirectory()) break;
|
|
528
|
-
} catch (error2) {
|
|
529
|
-
if (!pending(error2)) throw error2;
|
|
530
|
-
}
|
|
531
|
-
const parent = NodePath4.dirname(root);
|
|
532
|
-
if (parent === root) throw new NativeHistoryPendingError();
|
|
533
|
-
root = parent;
|
|
534
|
-
}
|
|
535
|
-
let dirty = true;
|
|
536
|
-
let wake;
|
|
537
|
-
let error;
|
|
538
|
-
const notify = () => {
|
|
539
|
-
dirty = true;
|
|
540
|
-
wake?.();
|
|
541
|
-
wake = void 0;
|
|
542
|
-
};
|
|
543
|
-
const watcher = NodeFS2.watch(root, { recursive: true, signal }, (_event, name) => {
|
|
544
|
-
if (name == null || input.accepts(NodePath4.resolve(root, String(name)))) notify();
|
|
545
|
-
});
|
|
546
|
-
watcher.on("error", (cause) => {
|
|
547
|
-
error = cause;
|
|
548
|
-
notify();
|
|
549
|
-
});
|
|
550
|
-
signal.addEventListener("abort", notify, { once: true });
|
|
551
|
-
let announced = false;
|
|
552
|
-
try {
|
|
553
|
-
while (true) {
|
|
554
|
-
signal.throwIfAborted();
|
|
555
|
-
if (error !== void 0) throw error;
|
|
556
|
-
if (!dirty)
|
|
557
|
-
await new Promise((resolve7) => {
|
|
558
|
-
wake = resolve7;
|
|
559
|
-
});
|
|
560
|
-
signal.throwIfAborted();
|
|
561
|
-
dirty = false;
|
|
562
|
-
let source;
|
|
563
|
-
try {
|
|
564
|
-
source = await open2();
|
|
565
|
-
} catch (cause) {
|
|
566
|
-
if (!pending(cause)) throw cause;
|
|
567
|
-
if (!announced) {
|
|
568
|
-
announced = true;
|
|
569
|
-
yield { _tag: "unavailable", reason: "native-session-unavailable" };
|
|
570
|
-
yield { _tag: "synchronized" };
|
|
571
|
-
}
|
|
572
|
-
continue;
|
|
573
|
-
}
|
|
574
|
-
announced = false;
|
|
575
|
-
try {
|
|
576
|
-
for await (const frame of source.follow({ ...options, signal })) yield frame;
|
|
577
|
-
} catch (cause) {
|
|
578
|
-
if (!pending(cause)) throw cause;
|
|
579
|
-
} finally {
|
|
580
|
-
await release(source);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
} finally {
|
|
584
|
-
watcher.close();
|
|
585
|
-
signal.removeEventListener("abort", notify);
|
|
586
|
-
wake?.();
|
|
587
|
-
if (iterator !== void 0) iterators.delete(iterator);
|
|
588
|
-
}
|
|
589
|
-
})();
|
|
590
|
-
iterators.add(iterator);
|
|
591
|
-
return iterator;
|
|
592
|
-
},
|
|
593
|
-
close: async () => {
|
|
594
|
-
controller.abort();
|
|
595
|
-
await Promise.all([...sources].map(release));
|
|
596
|
-
await Promise.all([...iterators].map((iterator) => iterator.return(void 0)));
|
|
597
|
-
await Promise.allSettled(operations);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
// ../../packages/ycodium-jsonl-stream/src/history.ts
|
|
603
|
-
import * as NodeFS3 from "node:fs";
|
|
604
|
-
import * as NodePath5 from "node:path";
|
|
605
|
-
|
|
606
|
-
// ../../packages/ycodium-jsonl-stream/src/historyFile.ts
|
|
607
|
-
import * as NodeFSP2 from "node:fs/promises";
|
|
608
|
-
import * as NodeCrypto from "node:crypto";
|
|
609
|
-
var HISTORY_READ_BYTES = 65536;
|
|
610
|
-
async function* historyBytes(path, start, end, signal) {
|
|
611
|
-
const file = await NodeFSP2.open(path, "r");
|
|
612
|
-
try {
|
|
613
|
-
let offset = start;
|
|
614
|
-
while (offset < end) {
|
|
615
|
-
signal?.throwIfAborted();
|
|
616
|
-
const buffer = Buffer.allocUnsafe(Math.min(HISTORY_READ_BYTES, end - offset));
|
|
617
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, offset);
|
|
618
|
-
if (bytesRead === 0) throw new Error("Native history changed during a read.");
|
|
619
|
-
offset += bytesRead;
|
|
620
|
-
yield buffer.subarray(0, bytesRead);
|
|
621
|
-
}
|
|
622
|
-
} finally {
|
|
623
|
-
await file.close();
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
|
-
async function* historyText(path, range, signal) {
|
|
627
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
628
|
-
for await (const bytes of historyBytes(path, range.start, range.end, signal)) {
|
|
629
|
-
const text2 = decoder.decode(bytes, { stream: true });
|
|
630
|
-
if (text2) yield text2;
|
|
631
|
-
}
|
|
632
|
-
const last = decoder.decode();
|
|
633
|
-
if (last) yield last;
|
|
634
|
-
}
|
|
635
|
-
async function* historyLines(path, start, end, backwards, signal) {
|
|
636
|
-
if (!backwards) {
|
|
637
|
-
let lineStart = start;
|
|
638
|
-
let offset = start;
|
|
639
|
-
for await (const bytes of historyBytes(path, start, end, signal)) {
|
|
640
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
641
|
-
if (bytes[index] !== 10) continue;
|
|
642
|
-
const lineEnd = offset + index;
|
|
643
|
-
if (lineEnd > lineStart)
|
|
644
|
-
yield { start: lineStart, end: lineEnd, commit: lineEnd + 1, terminated: true };
|
|
645
|
-
lineStart = lineEnd + 1;
|
|
646
|
-
}
|
|
647
|
-
offset += bytes.length;
|
|
648
|
-
}
|
|
649
|
-
if (lineStart < end) yield { start: lineStart, end, commit: end, terminated: false };
|
|
650
|
-
return;
|
|
651
|
-
}
|
|
652
|
-
const file = await NodeFSP2.open(path, "r");
|
|
653
|
-
try {
|
|
654
|
-
let scan = end;
|
|
655
|
-
let lineEnd = end;
|
|
656
|
-
let terminated = false;
|
|
657
|
-
while (scan > start) {
|
|
658
|
-
signal?.throwIfAborted();
|
|
659
|
-
const from = Math.max(start, scan - HISTORY_READ_BYTES);
|
|
660
|
-
const buffer = Buffer.allocUnsafe(scan - from);
|
|
661
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, from);
|
|
662
|
-
if (bytesRead !== buffer.length) throw new Error("Native history changed during a read.");
|
|
663
|
-
for (let index = buffer.length - 1; index >= 0; index -= 1) {
|
|
664
|
-
if (buffer[index] !== 10) continue;
|
|
665
|
-
const at2 = from + index;
|
|
666
|
-
if (at2 + 1 < lineEnd)
|
|
667
|
-
yield { start: at2 + 1, end: lineEnd, commit: lineEnd + (terminated ? 1 : 0), terminated };
|
|
668
|
-
lineEnd = at2;
|
|
669
|
-
terminated = true;
|
|
670
|
-
}
|
|
671
|
-
scan = from;
|
|
672
|
-
}
|
|
673
|
-
if (lineEnd > start)
|
|
674
|
-
yield { start, end: lineEnd, commit: lineEnd + (terminated ? 1 : 0), terminated };
|
|
675
|
-
} finally {
|
|
676
|
-
await file.close();
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
var historyIdentity = async (path) => {
|
|
680
|
-
const stat5 = await NodeFSP2.stat(path);
|
|
681
|
-
return {
|
|
682
|
-
size: stat5.size,
|
|
683
|
-
mtimeMs: stat5.mtimeMs,
|
|
684
|
-
ctimeMs: stat5.ctimeMs,
|
|
685
|
-
identity: NodeCrypto.createHash("sha256").update(`${path}/${stat5.dev}/${stat5.ino}/${stat5.birthtimeMs}`).digest("hex")
|
|
686
|
-
};
|
|
687
|
-
};
|
|
688
|
-
var historyCommittedFingerprint = async (path, sequence, signal) => {
|
|
689
|
-
const hash = NodeCrypto.createHash("sha256");
|
|
690
|
-
const starts = [
|
|
691
|
-
0,
|
|
692
|
-
Math.max(0, Math.floor(sequence / 3) - 512),
|
|
693
|
-
Math.max(0, Math.floor(sequence * 2 / 3) - 512),
|
|
694
|
-
Math.max(0, sequence - 1024)
|
|
695
|
-
];
|
|
696
|
-
for (const start of new Set(starts)) {
|
|
697
|
-
const end = Math.min(sequence, start + 1024);
|
|
698
|
-
hash.update(`${start}:${end}:`);
|
|
699
|
-
for await (const bytes of historyBytes(path, start, end, signal)) hash.update(bytes);
|
|
700
|
-
}
|
|
701
|
-
return hash.digest("hex");
|
|
702
|
-
};
|
|
703
|
-
var historyBoundary = async (path, identity, sequence, signal) => {
|
|
704
|
-
const hash = NodeCrypto.createHash("sha256");
|
|
705
|
-
for await (const bytes of historyBytes(path, Math.max(0, sequence - 128), sequence, signal))
|
|
706
|
-
hash.update(bytes);
|
|
707
|
-
hash.update(await historyCommittedFingerprint(path, sequence, signal));
|
|
708
|
-
return { epoch: `${identity}.${hash.digest("hex")}`, sequence };
|
|
709
|
-
};
|
|
710
|
-
|
|
711
|
-
// ../../packages/ycodium-jsonl-stream/src/historyRecord.ts
|
|
712
|
-
import * as NodeCrypto2 from "node:crypto";
|
|
713
|
-
|
|
714
|
-
// ../../packages/ycodium-jsonl-stream/src/jsonlStream.ts
|
|
715
|
-
var DEFAULT_MAX_RETAINED_CHARS = 8e6;
|
|
716
|
-
var MAX_DEPTH = 128;
|
|
717
|
-
var MAX_KEY_CHARS = 256;
|
|
718
|
-
var MAX_BARE_CHARS = 64;
|
|
719
|
-
var NUMBER_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u;
|
|
720
|
-
var OversizedRecordParser = class {
|
|
721
|
-
#fields;
|
|
722
|
-
#budget;
|
|
723
|
-
#options;
|
|
724
|
-
#retained = 0;
|
|
725
|
-
#malformed = false;
|
|
726
|
-
#done = false;
|
|
727
|
-
#result = void 0;
|
|
728
|
-
#stack = [];
|
|
729
|
-
// 词法状态。
|
|
730
|
-
#inString = false;
|
|
731
|
-
#stringIsKey = false;
|
|
732
|
-
#escape = false;
|
|
733
|
-
#unicodeLeft = 0;
|
|
734
|
-
#unicodeValue = 0;
|
|
735
|
-
#bare = "";
|
|
736
|
-
// 当前字符串的保留规则与累积。
|
|
737
|
-
#strObserver;
|
|
738
|
-
#strRetain = false;
|
|
739
|
-
#strCap = void 0;
|
|
740
|
-
#strHead = "";
|
|
741
|
-
#strTail = "";
|
|
742
|
-
#strLength = 0;
|
|
743
|
-
#key = "";
|
|
744
|
-
#keyOverflow = false;
|
|
745
|
-
// 值之间的位置。
|
|
746
|
-
#expectKey = false;
|
|
747
|
-
#expectColon = false;
|
|
748
|
-
#expectComma = false;
|
|
749
|
-
#expectValue = true;
|
|
750
|
-
constructor(fields, maxRetainedChars = DEFAULT_MAX_RETAINED_CHARS, options) {
|
|
751
|
-
this.#fields = fields;
|
|
752
|
-
this.#budget = maxRetainedChars;
|
|
753
|
-
this.#options = options;
|
|
754
|
-
}
|
|
755
|
-
write(chunk) {
|
|
756
|
-
if (this.#malformed) return;
|
|
757
|
-
try {
|
|
758
|
-
this.#consume(chunk);
|
|
759
|
-
} catch (cause) {
|
|
760
|
-
if (cause instanceof MalformedRecord) {
|
|
761
|
-
this.#malformed = true;
|
|
762
|
-
return;
|
|
763
|
-
}
|
|
764
|
-
throw cause;
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
/** 完整且合法才返回记录;其余(含空行)返回 `undefined`。 */
|
|
768
|
-
finish() {
|
|
769
|
-
if (this.#malformed) return void 0;
|
|
770
|
-
try {
|
|
771
|
-
if (this.#bare.length > 0) this.#finishBare();
|
|
772
|
-
} catch (cause) {
|
|
773
|
-
if (cause instanceof MalformedRecord) return void 0;
|
|
774
|
-
throw cause;
|
|
775
|
-
}
|
|
776
|
-
if (!this.#done || this.#inString || this.#result === SKIPPED) return void 0;
|
|
777
|
-
return this.#result;
|
|
778
|
-
}
|
|
779
|
-
#fail() {
|
|
780
|
-
throw new MalformedRecord();
|
|
781
|
-
}
|
|
782
|
-
#charge(chars) {
|
|
783
|
-
this.#retained += chars;
|
|
784
|
-
if (this.#retained > this.#budget) this.#fail();
|
|
785
|
-
}
|
|
786
|
-
#consume(chunk) {
|
|
787
|
-
const n = chunk.length;
|
|
788
|
-
let i = 0;
|
|
789
|
-
while (i < n) {
|
|
790
|
-
if (this.#inString) {
|
|
791
|
-
i = this.#consumeString(chunk, i);
|
|
792
|
-
continue;
|
|
793
|
-
}
|
|
794
|
-
const c = chunk.charCodeAt(i);
|
|
795
|
-
if (this.#bare.length > 0) {
|
|
796
|
-
if (isBareChar(c)) {
|
|
797
|
-
if (this.#bare.length >= MAX_BARE_CHARS) this.#fail();
|
|
798
|
-
this.#bare += chunk[i];
|
|
799
|
-
i += 1;
|
|
800
|
-
continue;
|
|
801
|
-
}
|
|
802
|
-
this.#finishBare();
|
|
803
|
-
}
|
|
804
|
-
i += 1;
|
|
805
|
-
if (c === 32 || c === 9 || c === 10 || c === 13) continue;
|
|
806
|
-
if (this.#done) this.#fail();
|
|
807
|
-
switch (c) {
|
|
808
|
-
case 123:
|
|
809
|
-
this.#requireValue();
|
|
810
|
-
this.#openContainer(false);
|
|
811
|
-
break;
|
|
812
|
-
case 91:
|
|
813
|
-
this.#requireValue();
|
|
814
|
-
this.#openContainer(true);
|
|
815
|
-
break;
|
|
816
|
-
case 125:
|
|
817
|
-
this.#closeContainer(false);
|
|
818
|
-
break;
|
|
819
|
-
case 93:
|
|
820
|
-
this.#closeContainer(true);
|
|
821
|
-
break;
|
|
822
|
-
case 44:
|
|
823
|
-
this.#comma();
|
|
824
|
-
break;
|
|
825
|
-
case 58:
|
|
826
|
-
if (!this.#expectColon) this.#fail();
|
|
827
|
-
this.#expectColon = false;
|
|
828
|
-
this.#expectValue = true;
|
|
829
|
-
break;
|
|
830
|
-
case 34:
|
|
831
|
-
this.#openString();
|
|
832
|
-
break;
|
|
833
|
-
default:
|
|
834
|
-
if (isBareChar(c)) {
|
|
835
|
-
this.#requireValue();
|
|
836
|
-
this.#bare = chunk[i - 1] ?? "";
|
|
837
|
-
} else this.#fail();
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
#top() {
|
|
842
|
-
return this.#stack[this.#stack.length - 1];
|
|
843
|
-
}
|
|
844
|
-
#requireValue() {
|
|
845
|
-
if (!this.#expectValue) this.#fail();
|
|
846
|
-
this.#expectValue = false;
|
|
847
|
-
}
|
|
848
|
-
/** 当前要读的值(刚要开始)落在什么模式;`isContainer` 决定 scalarOnly 清单项是否适用。 */
|
|
849
|
-
#childMode(isContainer) {
|
|
850
|
-
const parent = this.#top();
|
|
851
|
-
if (parent === void 0) return this.#classify([], isContainer);
|
|
852
|
-
if (parent.mode === "skip") return { mode: "skip", cap: void 0, path: [] };
|
|
853
|
-
if (parent.mode === "keep") return { mode: "keep", cap: parent.cap, path: [] };
|
|
854
|
-
const segment = parent.isArray ? String(parent.index) : parent.key ?? "";
|
|
855
|
-
if (parent.skipValue) return { mode: "skip", cap: void 0, path: [] };
|
|
856
|
-
return this.#classify([...parent.path, segment], isContainer);
|
|
857
|
-
}
|
|
858
|
-
#classify(path, isContainer) {
|
|
859
|
-
let descend = false;
|
|
860
|
-
for (const field of this.#fields) {
|
|
861
|
-
const fieldPath = field.path;
|
|
862
|
-
if (fieldPath.length <= path.length) {
|
|
863
|
-
if (field.scalarOnly === true && (isContainer || fieldPath.length !== path.length)) {
|
|
864
|
-
continue;
|
|
865
|
-
}
|
|
866
|
-
if (matchesPrefix(fieldPath, path, fieldPath.length)) {
|
|
867
|
-
return { mode: "keep", cap: field.maxChars, path };
|
|
868
|
-
}
|
|
869
|
-
} else if (matchesPrefix(fieldPath, path, path.length)) {
|
|
870
|
-
descend = true;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
return { mode: descend ? "descend" : "skip", cap: void 0, path };
|
|
874
|
-
}
|
|
875
|
-
#openContainer(isArray) {
|
|
876
|
-
if (this.#stack.length >= MAX_DEPTH) this.#fail();
|
|
877
|
-
const { mode, cap, path } = this.#childMode(true);
|
|
878
|
-
const keeping = mode !== "skip";
|
|
879
|
-
let target = null;
|
|
880
|
-
if (keeping) {
|
|
881
|
-
this.#charge(16);
|
|
882
|
-
target = isArray ? [] : {};
|
|
883
|
-
}
|
|
884
|
-
this.#stack.push({ isArray, mode, path, cap, target, key: null, skipValue: false, index: 0 });
|
|
885
|
-
this.#expectValue = isArray;
|
|
886
|
-
this.#expectKey = !isArray;
|
|
887
|
-
this.#expectComma = false;
|
|
888
|
-
this.#expectColon = false;
|
|
889
|
-
}
|
|
890
|
-
#closeContainer(isArray) {
|
|
891
|
-
const top = this.#top();
|
|
892
|
-
if (top === void 0 || top.isArray !== isArray) this.#fail();
|
|
893
|
-
if (!this.#expectComma && top.index > 0) this.#fail();
|
|
894
|
-
if (this.#expectColon || !isArray && this.#expectValue) this.#fail();
|
|
895
|
-
this.#stack.pop();
|
|
896
|
-
this.#expectValue = false;
|
|
897
|
-
this.#expectKey = false;
|
|
898
|
-
this.#expectColon = false;
|
|
899
|
-
this.#expectComma = true;
|
|
900
|
-
const empty = top.target !== null && Object.keys(top.target).length === 0;
|
|
901
|
-
this.#store(
|
|
902
|
-
this.#options?.pruneEmpty && top.mode === "descend" && empty && this.#stack.length > 0 ? SKIPPED : top.target ?? SKIPPED
|
|
903
|
-
);
|
|
904
|
-
}
|
|
905
|
-
#comma() {
|
|
906
|
-
const top = this.#top();
|
|
907
|
-
if (top === void 0 || !this.#expectComma) this.#fail();
|
|
908
|
-
this.#expectComma = false;
|
|
909
|
-
if (top.isArray) {
|
|
910
|
-
this.#expectValue = true;
|
|
911
|
-
} else {
|
|
912
|
-
this.#expectKey = true;
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
/** 一个值读完:交给外层容器,或成为整条记录。 */
|
|
916
|
-
#store(value) {
|
|
917
|
-
const parent = this.#top();
|
|
918
|
-
if (parent === void 0) {
|
|
919
|
-
this.#result = value;
|
|
920
|
-
this.#done = true;
|
|
921
|
-
this.#expectComma = false;
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
this.#expectComma = true;
|
|
925
|
-
if (parent.isArray) {
|
|
926
|
-
parent.index += 1;
|
|
927
|
-
if (parent.target !== null && value !== SKIPPED) {
|
|
928
|
-
parent.target.push(value);
|
|
929
|
-
this.#charge(8);
|
|
930
|
-
}
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
parent.index += 1;
|
|
934
|
-
const key = parent.key;
|
|
935
|
-
parent.key = null;
|
|
936
|
-
parent.skipValue = false;
|
|
937
|
-
if (parent.target !== null && value !== SKIPPED && key !== null) {
|
|
938
|
-
Object.defineProperty(parent.target, key, {
|
|
939
|
-
value,
|
|
940
|
-
enumerable: true,
|
|
941
|
-
writable: true,
|
|
942
|
-
configurable: true
|
|
943
|
-
});
|
|
944
|
-
this.#charge(key.length + 8);
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
#openString() {
|
|
948
|
-
const parent = this.#top();
|
|
949
|
-
const asKey = parent !== void 0 && !parent.isArray && this.#expectKey;
|
|
950
|
-
if (!asKey) this.#requireValue();
|
|
951
|
-
this.#inString = true;
|
|
952
|
-
this.#stringIsKey = asKey;
|
|
953
|
-
this.#escape = false;
|
|
954
|
-
this.#unicodeLeft = 0;
|
|
955
|
-
this.#strLength = 0;
|
|
956
|
-
this.#strHead = "";
|
|
957
|
-
this.#strTail = "";
|
|
958
|
-
this.#key = "";
|
|
959
|
-
if (asKey) {
|
|
960
|
-
this.#keyOverflow = false;
|
|
961
|
-
this.#strRetain = true;
|
|
962
|
-
this.#strCap = void 0;
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
const { mode, cap, path } = this.#childMode(false);
|
|
966
|
-
this.#strObserver = this.#fields.find(
|
|
967
|
-
(field) => field.path.length === path.length && matchesPrefix(field.path, path, path.length)
|
|
968
|
-
);
|
|
969
|
-
this.#strRetain = mode === "keep" && this.#strObserver?.onChunk === void 0;
|
|
970
|
-
this.#strCap = cap;
|
|
971
|
-
}
|
|
972
|
-
/** 字符串里的一个解码后片段;按保留规则累积。 */
|
|
973
|
-
#append(text2) {
|
|
974
|
-
if (text2.length === 0) return;
|
|
975
|
-
if (this.#stringIsKey) {
|
|
976
|
-
if (this.#keyOverflow) return;
|
|
977
|
-
this.#key += text2;
|
|
978
|
-
if (this.#key.length > MAX_KEY_CHARS) {
|
|
979
|
-
this.#keyOverflow = true;
|
|
980
|
-
this.#key = "";
|
|
981
|
-
}
|
|
982
|
-
return;
|
|
983
|
-
}
|
|
984
|
-
this.#strLength += text2.length;
|
|
985
|
-
this.#strObserver?.onChunk?.(text2);
|
|
986
|
-
if (!this.#strRetain) return;
|
|
987
|
-
const cap = this.#strCap;
|
|
988
|
-
if (cap === void 0) {
|
|
989
|
-
this.#strHead += text2;
|
|
990
|
-
this.#charge(text2.length);
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
if (this.#strHead.length < cap) {
|
|
994
|
-
const room = cap - this.#strHead.length;
|
|
995
|
-
this.#strHead += text2.slice(0, room);
|
|
996
|
-
text2 = text2.slice(room);
|
|
997
|
-
if (text2.length === 0) return;
|
|
998
|
-
}
|
|
999
|
-
this.#strTail += text2;
|
|
1000
|
-
if (this.#strTail.length > cap * 2) this.#strTail = this.#strTail.slice(-cap);
|
|
1001
|
-
}
|
|
1002
|
-
#consumeString(chunk, start) {
|
|
1003
|
-
const n = chunk.length;
|
|
1004
|
-
let i = start;
|
|
1005
|
-
while (i < n) {
|
|
1006
|
-
if (this.#unicodeLeft > 0) {
|
|
1007
|
-
const digit = hexValue(chunk.charCodeAt(i));
|
|
1008
|
-
if (digit < 0) this.#fail();
|
|
1009
|
-
this.#unicodeValue = this.#unicodeValue * 16 + digit;
|
|
1010
|
-
this.#unicodeLeft -= 1;
|
|
1011
|
-
i += 1;
|
|
1012
|
-
if (this.#unicodeLeft === 0) this.#append(String.fromCharCode(this.#unicodeValue));
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
if (this.#escape) {
|
|
1016
|
-
this.#escape = false;
|
|
1017
|
-
const c3 = chunk[i] ?? "";
|
|
1018
|
-
i += 1;
|
|
1019
|
-
switch (c3) {
|
|
1020
|
-
case '"':
|
|
1021
|
-
case "\\":
|
|
1022
|
-
case "/":
|
|
1023
|
-
this.#append(c3);
|
|
1024
|
-
break;
|
|
1025
|
-
case "b":
|
|
1026
|
-
this.#append("\b");
|
|
1027
|
-
break;
|
|
1028
|
-
case "f":
|
|
1029
|
-
this.#append("\f");
|
|
1030
|
-
break;
|
|
1031
|
-
case "n":
|
|
1032
|
-
this.#append("\n");
|
|
1033
|
-
break;
|
|
1034
|
-
case "r":
|
|
1035
|
-
this.#append("\r");
|
|
1036
|
-
break;
|
|
1037
|
-
case "t":
|
|
1038
|
-
this.#append(" ");
|
|
1039
|
-
break;
|
|
1040
|
-
case "u":
|
|
1041
|
-
this.#unicodeLeft = 4;
|
|
1042
|
-
this.#unicodeValue = 0;
|
|
1043
|
-
break;
|
|
1044
|
-
default:
|
|
1045
|
-
this.#fail();
|
|
1046
|
-
}
|
|
1047
|
-
continue;
|
|
1048
|
-
}
|
|
1049
|
-
const runStart = i;
|
|
1050
|
-
while (i < n) {
|
|
1051
|
-
const c3 = chunk.charCodeAt(i);
|
|
1052
|
-
if (c3 === 34 || c3 === 92 || c3 < 32) break;
|
|
1053
|
-
i += 1;
|
|
1054
|
-
}
|
|
1055
|
-
if (i > runStart) this.#append(chunk.slice(runStart, i));
|
|
1056
|
-
if (i >= n) break;
|
|
1057
|
-
const c = chunk.charCodeAt(i);
|
|
1058
|
-
i += 1;
|
|
1059
|
-
if (c === 92) {
|
|
1060
|
-
this.#escape = true;
|
|
1061
|
-
} else if (c === 34) {
|
|
1062
|
-
this.#inString = false;
|
|
1063
|
-
this.#endString();
|
|
1064
|
-
return i;
|
|
1065
|
-
} else {
|
|
1066
|
-
this.#fail();
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
return i;
|
|
1070
|
-
}
|
|
1071
|
-
#endString() {
|
|
1072
|
-
if (this.#stringIsKey) {
|
|
1073
|
-
const parent = this.#top();
|
|
1074
|
-
if (parent === void 0) this.#fail();
|
|
1075
|
-
parent.key = this.#key;
|
|
1076
|
-
parent.skipValue = this.#keyOverflow;
|
|
1077
|
-
this.#key = "";
|
|
1078
|
-
this.#expectKey = false;
|
|
1079
|
-
this.#expectColon = true;
|
|
1080
|
-
return;
|
|
1081
|
-
}
|
|
1082
|
-
this.#strObserver?.onEnd?.(this.#strLength);
|
|
1083
|
-
this.#strObserver = void 0;
|
|
1084
|
-
if (!this.#strRetain) {
|
|
1085
|
-
this.#store(SKIPPED);
|
|
1086
|
-
return;
|
|
1087
|
-
}
|
|
1088
|
-
const cap = this.#strCap;
|
|
1089
|
-
let text2 = this.#strHead;
|
|
1090
|
-
if (cap !== void 0) {
|
|
1091
|
-
let tail = this.#strTail;
|
|
1092
|
-
if (tail.length > cap) tail = tail.slice(-cap);
|
|
1093
|
-
if (this.#strLength > text2.length + tail.length) {
|
|
1094
|
-
if (isHighSurrogate(text2.charCodeAt(text2.length - 1))) text2 = text2.slice(0, -1);
|
|
1095
|
-
if (isLowSurrogate(tail.charCodeAt(0))) tail = tail.slice(1);
|
|
1096
|
-
const omitted = this.#strLength - text2.length - tail.length;
|
|
1097
|
-
text2 = `${text2}
|
|
1098
|
-
[\u2026 ${omitted} chars omitted \u2026]
|
|
1099
|
-
${tail}`;
|
|
1100
|
-
} else {
|
|
1101
|
-
text2 = `${text2}${tail}`;
|
|
1102
|
-
}
|
|
1103
|
-
this.#charge(text2.length);
|
|
1104
|
-
}
|
|
1105
|
-
this.#strHead = "";
|
|
1106
|
-
this.#strTail = "";
|
|
1107
|
-
this.#store(text2);
|
|
1108
|
-
}
|
|
1109
|
-
#finishBare() {
|
|
1110
|
-
const text2 = this.#bare;
|
|
1111
|
-
this.#bare = "";
|
|
1112
|
-
const { mode, path } = this.#childMode(false);
|
|
1113
|
-
let value;
|
|
1114
|
-
if (text2 === "true") value = true;
|
|
1115
|
-
else if (text2 === "false") value = false;
|
|
1116
|
-
else if (text2 === "null") value = null;
|
|
1117
|
-
else if (NUMBER_PATTERN.test(text2)) value = Number(text2);
|
|
1118
|
-
else this.#fail();
|
|
1119
|
-
const observer = this.#fields.find(
|
|
1120
|
-
(field) => field.path.length === path.length && matchesPrefix(field.path, path, path.length)
|
|
1121
|
-
);
|
|
1122
|
-
if (observer?.onScalar !== void 0) {
|
|
1123
|
-
observer.onScalar(value);
|
|
1124
|
-
this.#store(SKIPPED);
|
|
1125
|
-
} else this.#store(mode === "keep" ? value : SKIPPED);
|
|
1126
|
-
}
|
|
1127
|
-
};
|
|
1128
|
-
var SKIPPED = /* @__PURE__ */ Symbol("skipped");
|
|
1129
|
-
var MalformedRecord = class extends Error {
|
|
1130
|
-
};
|
|
1131
|
-
function isBareChar(c) {
|
|
1132
|
-
return c >= 48 && c <= 57 || // 0-9
|
|
1133
|
-
c >= 97 && c <= 122 || // a-z
|
|
1134
|
-
c >= 65 && c <= 90 || // A-Z
|
|
1135
|
-
c === 43 || c === 45 || c === 46;
|
|
1136
|
-
}
|
|
1137
|
-
function hexValue(c) {
|
|
1138
|
-
if (c >= 48 && c <= 57) return c - 48;
|
|
1139
|
-
if (c >= 97 && c <= 102) return c - 97 + 10;
|
|
1140
|
-
if (c >= 65 && c <= 70) return c - 65 + 10;
|
|
1141
|
-
return -1;
|
|
1142
|
-
}
|
|
1143
|
-
var isHighSurrogate = (c) => c >= 55296 && c <= 56319;
|
|
1144
|
-
var isLowSurrogate = (c) => c >= 56320 && c <= 57343;
|
|
1145
|
-
function matchesPrefix(pattern, path, length) {
|
|
1146
|
-
for (let index = 0; index < length; index += 1) {
|
|
1147
|
-
const expected = pattern[index];
|
|
1148
|
-
if (expected !== "*" && expected !== path[index]) return false;
|
|
1149
|
-
}
|
|
1150
|
-
return true;
|
|
1151
|
-
}
|
|
1152
|
-
function jsonlEntryRecord(entry, accepts) {
|
|
1153
|
-
if ("oversized" in entry) return entry.oversized;
|
|
1154
|
-
if (!accepts(entry.line)) return void 0;
|
|
1155
|
-
try {
|
|
1156
|
-
return JSON.parse(entry.line);
|
|
1157
|
-
} catch {
|
|
1158
|
-
return void 0;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
async function* readJsonlEntries(fs2, path, options) {
|
|
1162
|
-
const decoder = new TextDecoder("utf-8");
|
|
1163
|
-
let pieces = [];
|
|
1164
|
-
let pending2 = 0;
|
|
1165
|
-
let parser = null;
|
|
1166
|
-
const startOversized = () => {
|
|
1167
|
-
const next = new OversizedRecordParser(options.fields, options.maxRetainedChars);
|
|
1168
|
-
for (const piece of pieces) next.write(piece);
|
|
1169
|
-
pieces = [];
|
|
1170
|
-
pending2 = 0;
|
|
1171
|
-
return next;
|
|
1172
|
-
};
|
|
1173
|
-
const append = (text2) => {
|
|
1174
|
-
if (text2.length === 0) return;
|
|
1175
|
-
if (parser !== null) {
|
|
1176
|
-
parser.write(text2);
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
pieces.push(text2);
|
|
1180
|
-
pending2 += text2.length;
|
|
1181
|
-
if (pending2 > options.maxLineChars) parser = startOversized();
|
|
1182
|
-
};
|
|
1183
|
-
const takeLine = () => {
|
|
1184
|
-
if (parser !== null) {
|
|
1185
|
-
const record3 = parser.finish();
|
|
1186
|
-
parser = null;
|
|
1187
|
-
return { oversized: record3 };
|
|
1188
|
-
}
|
|
1189
|
-
if (pending2 === 0) return null;
|
|
1190
|
-
let line = pieces.length === 1 ? pieces[0] ?? "" : pieces.join("");
|
|
1191
|
-
pieces = [];
|
|
1192
|
-
pending2 = 0;
|
|
1193
|
-
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
1194
|
-
return line.length === 0 ? null : { line };
|
|
1195
|
-
};
|
|
1196
|
-
const feed = function* (text2) {
|
|
1197
|
-
let from = 0;
|
|
1198
|
-
while (from <= text2.length) {
|
|
1199
|
-
const newline = text2.indexOf("\n", from);
|
|
1200
|
-
if (newline < 0) {
|
|
1201
|
-
append(text2.slice(from));
|
|
1202
|
-
return;
|
|
1203
|
-
}
|
|
1204
|
-
append(text2.slice(from, newline));
|
|
1205
|
-
const entry = takeLine();
|
|
1206
|
-
if (entry !== null) yield entry;
|
|
1207
|
-
from = newline + 1;
|
|
1208
|
-
}
|
|
1209
|
-
};
|
|
1210
|
-
for await (const chunk of fs2.createReadStream(path)) {
|
|
1211
|
-
yield* feed(decoder.decode(chunk, { stream: true }));
|
|
1212
|
-
}
|
|
1213
|
-
yield* feed(decoder.decode());
|
|
1214
|
-
const last = takeLine();
|
|
1215
|
-
if (last !== null) yield last;
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// ../../packages/ycodium-jsonl-stream/src/historyRecord.ts
|
|
1219
|
-
var textFields = (paths, accept) => {
|
|
1220
|
-
let completed = 0;
|
|
1221
|
-
let started = false;
|
|
1222
|
-
const begin = () => {
|
|
1223
|
-
if (started) return;
|
|
1224
|
-
if (completed > 0) accept("\n");
|
|
1225
|
-
started = true;
|
|
1226
|
-
};
|
|
1227
|
-
return paths.map((path) => ({
|
|
1228
|
-
path,
|
|
1229
|
-
scalarOnly: true,
|
|
1230
|
-
onChunk: (text2) => {
|
|
1231
|
-
begin();
|
|
1232
|
-
accept(text2);
|
|
1233
|
-
},
|
|
1234
|
-
onEnd: () => {
|
|
1235
|
-
begin();
|
|
1236
|
-
completed += 1;
|
|
1237
|
-
started = false;
|
|
1238
|
-
}
|
|
1239
|
-
}));
|
|
1240
|
-
};
|
|
1241
|
-
var createHistoryRecordAccumulator = (layout) => {
|
|
1242
|
-
const selected = layout();
|
|
1243
|
-
let rawTotal = 0;
|
|
1244
|
-
let messageTotal = 0;
|
|
1245
|
-
const hash = NodeCrypto2.createHash("sha256");
|
|
1246
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
1247
|
-
const parser = new OversizedRecordParser(
|
|
1248
|
-
[
|
|
1249
|
-
...selected.fields,
|
|
1250
|
-
...textFields(selected.textPaths, (text2) => {
|
|
1251
|
-
messageTotal += text2.length;
|
|
1252
|
-
})
|
|
1253
|
-
],
|
|
1254
|
-
Number.MAX_SAFE_INTEGER,
|
|
1255
|
-
{ pruneEmpty: true }
|
|
1256
|
-
);
|
|
1257
|
-
const accept = (text2) => {
|
|
1258
|
-
rawTotal += text2.length;
|
|
1259
|
-
parser.write(text2);
|
|
1260
|
-
};
|
|
1261
|
-
return {
|
|
1262
|
-
write: (bytes) => {
|
|
1263
|
-
hash.update(bytes);
|
|
1264
|
-
accept(decoder.decode(bytes, { stream: true }));
|
|
1265
|
-
},
|
|
1266
|
-
finish: (range) => {
|
|
1267
|
-
accept(decoder.decode());
|
|
1268
|
-
const metadata = parser.finish();
|
|
1269
|
-
if (metadata === void 0) {
|
|
1270
|
-
if (!range.terminated) return void 0;
|
|
1271
|
-
throw new SyntaxError("Malformed complete native history record.");
|
|
1272
|
-
}
|
|
1273
|
-
return {
|
|
1274
|
-
range,
|
|
1275
|
-
hash: hash.digest("hex"),
|
|
1276
|
-
rawTotal,
|
|
1277
|
-
messageTotal,
|
|
1278
|
-
items: selected.describe(metadata).map(
|
|
1279
|
-
(item) => item.text === "message" && messageTotal === 0 ? { ...item, text: "raw" } : item
|
|
1280
|
-
)
|
|
1281
|
-
};
|
|
1282
|
-
}
|
|
1283
|
-
};
|
|
1284
|
-
};
|
|
1285
|
-
var inspectHistoryRecord = async (path, range, layout, signal) => {
|
|
1286
|
-
const accumulator = createHistoryRecordAccumulator(layout);
|
|
1287
|
-
try {
|
|
1288
|
-
for await (const bytes of historyBytes(path, range.start, range.end, signal))
|
|
1289
|
-
accumulator.write(bytes);
|
|
1290
|
-
return accumulator.finish(range);
|
|
1291
|
-
} catch (error) {
|
|
1292
|
-
if (!range.terminated && error instanceof TypeError) return void 0;
|
|
1293
|
-
throw error;
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
async function* historyRecordWindows(path, info, mode, from, until, limit, layout, signal) {
|
|
1297
|
-
let seen = 0;
|
|
1298
|
-
let offset = from;
|
|
1299
|
-
let pending2 = "";
|
|
1300
|
-
const ready = [];
|
|
1301
|
-
const accept = (text2) => {
|
|
1302
|
-
const begin = Math.max(0, from - seen);
|
|
1303
|
-
const end = Math.min(text2.length, until - seen);
|
|
1304
|
-
seen += text2.length;
|
|
1305
|
-
if (end > begin) pending2 += text2.slice(begin, end);
|
|
1306
|
-
while (pending2.length >= limit) {
|
|
1307
|
-
let size = limit;
|
|
1308
|
-
const code = pending2.charCodeAt(size - 1);
|
|
1309
|
-
if (code >= 55296 && code <= 56319) size -= 1;
|
|
1310
|
-
ready.push({ offset, text: pending2.slice(0, size) });
|
|
1311
|
-
pending2 = pending2.slice(size);
|
|
1312
|
-
offset += size;
|
|
1313
|
-
}
|
|
1314
|
-
};
|
|
1315
|
-
const selected = layout();
|
|
1316
|
-
const parser = mode === "raw" ? void 0 : new OversizedRecordParser(textFields(selected.textPaths, accept), Number.MAX_SAFE_INTEGER, {
|
|
1317
|
-
pruneEmpty: true
|
|
1318
|
-
});
|
|
1319
|
-
for await (const text2 of historyText(path, info.range, signal)) {
|
|
1320
|
-
if (parser === void 0) accept(text2);
|
|
1321
|
-
else parser.write(text2);
|
|
1322
|
-
while (ready.length > 0) yield ready.shift();
|
|
1323
|
-
if (seen >= until) break;
|
|
1324
|
-
}
|
|
1325
|
-
if (pending2) yield { offset, text: pending2 };
|
|
1326
|
-
}
|
|
1327
|
-
var verifyHistoryRecord = async (path, range, layout, signal) => {
|
|
1328
|
-
const selected = layout();
|
|
1329
|
-
const parser = new OversizedRecordParser(selected.fields, Number.MAX_SAFE_INTEGER, {
|
|
1330
|
-
pruneEmpty: true
|
|
1331
|
-
});
|
|
1332
|
-
try {
|
|
1333
|
-
for await (const text2 of historyText(path, range, signal)) parser.write(text2);
|
|
1334
|
-
} catch (error) {
|
|
1335
|
-
if (!range.terminated && error instanceof TypeError) return false;
|
|
1336
|
-
throw error;
|
|
1337
|
-
}
|
|
1338
|
-
const metadata = parser.finish();
|
|
1339
|
-
if (metadata === void 0 && range.terminated)
|
|
1340
|
-
throw new SyntaxError("Malformed complete native history record.");
|
|
1341
|
-
return selected.verify(metadata);
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
|
-
// ../../packages/ycodium-jsonl-stream/src/history.ts
|
|
1345
|
-
var RECORD_CACHE_LIMIT = 32;
|
|
1346
|
-
var TEXT_CACHE_CHARS = 262144;
|
|
1347
|
-
var recordCache = /* @__PURE__ */ new Map();
|
|
1348
|
-
var headCache = /* @__PURE__ */ new Map();
|
|
1349
|
-
var cacheKey = (path, identity) => `${path}\0${identity.identity}\0${identity.size}\0${identity.mtimeMs}\0${identity.ctimeMs}`;
|
|
1350
|
-
var remember = (cache, key, value, limit = RECORD_CACHE_LIMIT) => {
|
|
1351
|
-
cache.delete(key);
|
|
1352
|
-
cache.set(key, value);
|
|
1353
|
-
if (cache.size > limit) cache.delete(cache.keys().next().value);
|
|
1354
|
-
return value;
|
|
1355
|
-
};
|
|
1356
|
-
var encode = (position) => Buffer.from(JSON.stringify(position)).toString("base64url");
|
|
1357
|
-
var decode = (value) => {
|
|
1358
|
-
let p;
|
|
1359
|
-
try {
|
|
1360
|
-
p = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
1361
|
-
} catch {
|
|
1362
|
-
throw new NativeHistoryCursorError();
|
|
1363
|
-
}
|
|
1364
|
-
if (!p || typeof p.e !== "string" || typeof p.h !== "string" || ![p.p, p.k, p.o].every((n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0))
|
|
1365
|
-
throw new NativeHistoryCursorError();
|
|
1366
|
-
return p;
|
|
1367
|
-
};
|
|
1368
|
-
var width = (n) => String(n).padStart(20, "0");
|
|
1369
|
-
var high = (n) => n >= 55296 && n <= 56319;
|
|
1370
|
-
var low = (n) => n >= 56320 && n <= 57343;
|
|
1371
|
-
var totalOf = (info, index) => info.items[index].text === "raw" ? info.rawTotal : info.messageTotal;
|
|
1372
|
-
var nativeItem = (identity, info, index, offset, text2) => {
|
|
1373
|
-
const { text: _mode, ...item } = info.items[index];
|
|
1374
|
-
const total = totalOf(info, index);
|
|
1375
|
-
const position = { e: identity, p: info.range.start, k: index, h: info.hash };
|
|
1376
|
-
return {
|
|
1377
|
-
...item,
|
|
1378
|
-
id: `${identity}:${info.range.start}:${index}`,
|
|
1379
|
-
orderKey: `${width(info.range.start)}:${width(index)}`,
|
|
1380
|
-
beforeCursor: encode({ ...position, o: offset }),
|
|
1381
|
-
afterCursor: encode({ ...position, o: offset + text2.length }),
|
|
1382
|
-
text: text2,
|
|
1383
|
-
textWindow: {
|
|
1384
|
-
offset,
|
|
1385
|
-
returned: text2.length,
|
|
1386
|
-
total,
|
|
1387
|
-
nextOffset: offset + text2.length < total ? offset + text2.length : null
|
|
1388
|
-
}
|
|
1389
|
-
};
|
|
1390
|
-
};
|
|
1391
|
-
var readWindow = async (path, info, index, from, until, layout, signal, cached) => {
|
|
1392
|
-
const base = Math.max(0, from - 1);
|
|
1393
|
-
const end = Math.min(totalOf(info, index), until + 1);
|
|
1394
|
-
const mode = info.items[index].text;
|
|
1395
|
-
if (cached.text === void 0 && totalOf(info, index) <= TEXT_CACHE_CHARS) {
|
|
1396
|
-
const parts = [];
|
|
1397
|
-
for await (const window2 of historyRecordWindows(
|
|
1398
|
-
path,
|
|
1399
|
-
info,
|
|
1400
|
-
mode,
|
|
1401
|
-
0,
|
|
1402
|
-
totalOf(info, index),
|
|
1403
|
-
65536,
|
|
1404
|
-
layout,
|
|
1405
|
-
signal
|
|
1406
|
-
))
|
|
1407
|
-
parts.push(window2.text);
|
|
1408
|
-
cached.text = parts.join("");
|
|
1409
|
-
cached.mode = mode;
|
|
1410
|
-
}
|
|
1411
|
-
let text2 = cached.mode === mode ? cached.text?.slice(base, end) ?? "" : "";
|
|
1412
|
-
if (cached.mode !== mode) {
|
|
1413
|
-
for await (const window2 of historyRecordWindows(
|
|
1414
|
-
path,
|
|
1415
|
-
info,
|
|
1416
|
-
mode,
|
|
1417
|
-
base,
|
|
1418
|
-
end,
|
|
1419
|
-
Math.max(2, end - base),
|
|
1420
|
-
layout,
|
|
1421
|
-
signal
|
|
1422
|
-
))
|
|
1423
|
-
text2 += window2.text;
|
|
1424
|
-
}
|
|
1425
|
-
let startIndex = from - base;
|
|
1426
|
-
let endIndex = until - base;
|
|
1427
|
-
if (low(text2.charCodeAt(startIndex)) && high(text2.charCodeAt(startIndex - 1))) startIndex -= 1;
|
|
1428
|
-
if (low(text2.charCodeAt(endIndex)) && high(text2.charCodeAt(endIndex - 1))) endIndex -= 1;
|
|
1429
|
-
return { offset: base + startIndex, text: text2.slice(startIndex, endIndex) };
|
|
1430
|
-
};
|
|
1431
|
-
async function openJsonlHistory(path, layout, signal) {
|
|
1432
|
-
const controller = new AbortController();
|
|
1433
|
-
const combined = (next) => AbortSignal.any([controller.signal, ...signal ? [signal] : [], ...next ? [next] : []]);
|
|
1434
|
-
let verified;
|
|
1435
|
-
const verify = async (readSignal) => {
|
|
1436
|
-
const identity = await historyIdentity(path);
|
|
1437
|
-
if (verified?.identity === identity.identity && verified.size === identity.size && verified.mtimeMs === identity.mtimeMs && verified.ctimeMs === identity.ctimeMs)
|
|
1438
|
-
return identity;
|
|
1439
|
-
let checked = 0;
|
|
1440
|
-
for await (const range of historyLines(path, 0, identity.size, false, readSignal)) {
|
|
1441
|
-
if (await verifyHistoryRecord(path, range, layout, readSignal)) {
|
|
1442
|
-
verified = identity;
|
|
1443
|
-
return identity;
|
|
1444
|
-
}
|
|
1445
|
-
if (++checked >= 100) break;
|
|
1446
|
-
}
|
|
1447
|
-
throw new NativeHistoryPendingError();
|
|
1448
|
-
};
|
|
1449
|
-
await verify(combined());
|
|
1450
|
-
const active = /* @__PURE__ */ new Set();
|
|
1451
|
-
const iterators = /* @__PURE__ */ new Set();
|
|
1452
|
-
const tracked = (promise) => {
|
|
1453
|
-
active.add(promise);
|
|
1454
|
-
void promise.finally(() => active.delete(promise)).catch(() => void 0);
|
|
1455
|
-
return promise;
|
|
1456
|
-
};
|
|
1457
|
-
const inspect = async (range, identity, readSignal) => {
|
|
1458
|
-
const key = `${cacheKey(path, identity)}\0${range.start}`;
|
|
1459
|
-
const cached = recordCache.get(key);
|
|
1460
|
-
if (cached?.info.range.end === range.end) return cached;
|
|
1461
|
-
const info = await inspectHistoryRecord(path, range, layout, readSignal);
|
|
1462
|
-
return info === void 0 ? void 0 : remember(recordCache, key, { info });
|
|
1463
|
-
};
|
|
1464
|
-
const head = async (identity, readSignal) => {
|
|
1465
|
-
const key = cacheKey(path, identity);
|
|
1466
|
-
const saved = headCache.get(key);
|
|
1467
|
-
if (saved !== void 0) return saved;
|
|
1468
|
-
for await (const range of historyLines(path, 0, identity.size, true, readSignal)) {
|
|
1469
|
-
const info = await inspect(range, identity, readSignal);
|
|
1470
|
-
if (info !== void 0)
|
|
1471
|
-
return remember(
|
|
1472
|
-
headCache,
|
|
1473
|
-
key,
|
|
1474
|
-
await historyBoundary(path, identity.identity, range.commit, readSignal)
|
|
1475
|
-
);
|
|
1476
|
-
}
|
|
1477
|
-
return remember(headCache, key, await historyBoundary(path, identity.identity, 0, readSignal));
|
|
1478
|
-
};
|
|
1479
|
-
const page = async (input) => {
|
|
1480
|
-
const readSignal = combined(input.signal);
|
|
1481
|
-
readSignal.throwIfAborted();
|
|
1482
|
-
if (input.before !== void 0 && input.after !== void 0)
|
|
1483
|
-
throw new NativeHistoryCursorError();
|
|
1484
|
-
if (input.fromStart && input.before !== void 0) throw new NativeHistoryCursorError();
|
|
1485
|
-
const identity = await verify(readSignal);
|
|
1486
|
-
const position = input.before !== void 0 ? decode(input.before) : input.after !== void 0 ? decode(input.after) : void 0;
|
|
1487
|
-
if (position !== void 0 && (position.e !== identity.identity || position.p > identity.size))
|
|
1488
|
-
throw new NativeHistoryCursorError();
|
|
1489
|
-
const backwards = input.after === void 0 && input.fromStart !== true;
|
|
1490
|
-
const initialRange = position === void 0 ? void 0 : await (async () => {
|
|
1491
|
-
const cached = recordCache.get(`${cacheKey(path, identity)}\0${position.p}`);
|
|
1492
|
-
if (cached !== void 0) return cached.info.range;
|
|
1493
|
-
for await (const range of historyLines(
|
|
1494
|
-
path,
|
|
1495
|
-
position.p,
|
|
1496
|
-
identity.size,
|
|
1497
|
-
false,
|
|
1498
|
-
readSignal
|
|
1499
|
-
))
|
|
1500
|
-
return range;
|
|
1501
|
-
throw new NativeHistoryCursorError();
|
|
1502
|
-
})();
|
|
1503
|
-
const ranges = async function* () {
|
|
1504
|
-
if (initialRange !== void 0) yield initialRange;
|
|
1505
|
-
yield* backwards ? historyLines(path, 0, position?.p ?? identity.size, true, readSignal) : historyLines(path, initialRange?.commit ?? 0, identity.size, false, readSignal);
|
|
1506
|
-
};
|
|
1507
|
-
const items = [];
|
|
1508
|
-
let budget = Math.min(12e3, input.textLimit ?? 12e3);
|
|
1509
|
-
const limit = Math.min(50, input.limit ?? 20);
|
|
1510
|
-
let more = false;
|
|
1511
|
-
for await (const range of ranges()) {
|
|
1512
|
-
if (items.length >= limit || budget < 2) {
|
|
1513
|
-
more = true;
|
|
1514
|
-
break;
|
|
1515
|
-
}
|
|
1516
|
-
const cached = await inspect(range, identity, readSignal);
|
|
1517
|
-
if (cached === void 0) continue;
|
|
1518
|
-
const info = cached.info;
|
|
1519
|
-
const first = position !== void 0 && range.start === position.p;
|
|
1520
|
-
if (first && (position.h !== info.hash || position.k >= info.items.length || position.o > totalOf(info, position.k)))
|
|
1521
|
-
throw new NativeHistoryCursorError();
|
|
1522
|
-
const indices = Array.from({ length: info.items.length }, (_3, index) => index);
|
|
1523
|
-
if (backwards) indices.reverse();
|
|
1524
|
-
for (const index of indices) {
|
|
1525
|
-
if (first && (backwards ? index > position.k : index < position.k)) continue;
|
|
1526
|
-
const total = totalOf(info, index);
|
|
1527
|
-
if (first && index === position.k && total === 0) continue;
|
|
1528
|
-
const boundary = first && index === position.k ? position.o : backwards ? total : 0;
|
|
1529
|
-
if (total > 0 && (backwards ? boundary === 0 : boundary === total)) continue;
|
|
1530
|
-
if (items.length >= limit || budget < 2) {
|
|
1531
|
-
more = true;
|
|
1532
|
-
break;
|
|
1533
|
-
}
|
|
1534
|
-
const from = backwards ? Math.max(0, boundary - budget) : boundary;
|
|
1535
|
-
const until = backwards ? boundary : Math.min(total, from + budget);
|
|
1536
|
-
const window2 = await readWindow(path, info, index, from, until, layout, readSignal, cached);
|
|
1537
|
-
const item = nativeItem(identity.identity, info, index, window2.offset, window2.text);
|
|
1538
|
-
if (backwards) items.unshift(item);
|
|
1539
|
-
else items.push(item);
|
|
1540
|
-
budget -= window2.text.length;
|
|
1541
|
-
if (backwards ? window2.offset > 0 : window2.offset + window2.text.length < total) {
|
|
1542
|
-
more = true;
|
|
1543
|
-
break;
|
|
1544
|
-
}
|
|
1545
|
-
}
|
|
1546
|
-
if (more) break;
|
|
1547
|
-
}
|
|
1548
|
-
const liveCursor = await head(identity, readSignal);
|
|
1549
|
-
return {
|
|
1550
|
-
sourceEpoch: identity.identity,
|
|
1551
|
-
items,
|
|
1552
|
-
olderCursor: items.length === 0 ? null : backwards && !more && position === void 0 ? null : items[0].beforeCursor,
|
|
1553
|
-
newerCursor: items.length === 0 ? null : !backwards && !more ? null : backwards ? input.before !== void 0 ? items.at(-1).afterCursor : null : more ? items.at(-1).afterCursor : null,
|
|
1554
|
-
liveCursor
|
|
1555
|
-
};
|
|
1556
|
-
};
|
|
1557
|
-
const follow = (input) => {
|
|
1558
|
-
let iterator;
|
|
1559
|
-
iterator = (async function* () {
|
|
1560
|
-
const readSignal = combined(input.signal);
|
|
1561
|
-
let dirty = true;
|
|
1562
|
-
let wake;
|
|
1563
|
-
let failure;
|
|
1564
|
-
const notify = () => {
|
|
1565
|
-
dirty = true;
|
|
1566
|
-
wake?.();
|
|
1567
|
-
wake = void 0;
|
|
1568
|
-
};
|
|
1569
|
-
const watcher = NodeFS3.watch(
|
|
1570
|
-
NodePath5.dirname(path),
|
|
1571
|
-
{ signal: readSignal },
|
|
1572
|
-
(_event, file) => {
|
|
1573
|
-
if (file == null || String(file) === NodePath5.basename(path)) notify();
|
|
1574
|
-
}
|
|
1575
|
-
);
|
|
1576
|
-
watcher.on("error", (error) => {
|
|
1577
|
-
failure = error;
|
|
1578
|
-
notify();
|
|
1579
|
-
});
|
|
1580
|
-
const abort = () => notify();
|
|
1581
|
-
readSignal.addEventListener("abort", abort, { once: true });
|
|
1582
|
-
let committed = input.after;
|
|
1583
|
-
const reset = async () => page({
|
|
1584
|
-
...input.limit === void 0 ? {} : { limit: input.limit },
|
|
1585
|
-
...input.textLimit === void 0 ? {} : { textLimit: input.textLimit },
|
|
1586
|
-
signal: readSignal
|
|
1587
|
-
});
|
|
1588
|
-
try {
|
|
1589
|
-
let identity = await verify(readSignal);
|
|
1590
|
-
const boundary = committed !== void 0 && committed.sequence <= identity.size ? await historyBoundary(path, identity.identity, committed.sequence, readSignal) : void 0;
|
|
1591
|
-
if (committed === void 0 || boundary?.epoch !== committed.epoch || identity.size - committed.sequence > 1048576) {
|
|
1592
|
-
const value = await reset();
|
|
1593
|
-
committed = value.liveCursor;
|
|
1594
|
-
yield { _tag: "snapshot", cursor: committed, value };
|
|
1595
|
-
}
|
|
1596
|
-
let synchronized = false;
|
|
1597
|
-
let scanned = committed.sequence;
|
|
1598
|
-
let pendingStart = scanned;
|
|
1599
|
-
let accumulator = createHistoryRecordAccumulator(layout);
|
|
1600
|
-
const appended = async function* (end) {
|
|
1601
|
-
for await (const bytes of historyBytes(path, scanned, end, readSignal)) {
|
|
1602
|
-
let from = 0;
|
|
1603
|
-
const chunkStart = scanned;
|
|
1604
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
1605
|
-
if (bytes[index] !== 10) continue;
|
|
1606
|
-
accumulator.write(bytes.subarray(from, index));
|
|
1607
|
-
const at2 = chunkStart + index;
|
|
1608
|
-
const info = at2 > pendingStart ? accumulator.finish({
|
|
1609
|
-
start: pendingStart,
|
|
1610
|
-
end: at2,
|
|
1611
|
-
commit: at2 + 1,
|
|
1612
|
-
terminated: true
|
|
1613
|
-
}) : void 0;
|
|
1614
|
-
pendingStart = at2 + 1;
|
|
1615
|
-
accumulator = createHistoryRecordAccumulator(layout);
|
|
1616
|
-
from = index + 1;
|
|
1617
|
-
if (info !== void 0) yield info;
|
|
1618
|
-
}
|
|
1619
|
-
accumulator.write(bytes.subarray(from));
|
|
1620
|
-
scanned += bytes.length;
|
|
1621
|
-
}
|
|
1622
|
-
};
|
|
1623
|
-
while (true) {
|
|
1624
|
-
readSignal.throwIfAborted();
|
|
1625
|
-
if (failure !== void 0) throw failure;
|
|
1626
|
-
if (!dirty)
|
|
1627
|
-
await new Promise((resolve7) => {
|
|
1628
|
-
wake = resolve7;
|
|
1629
|
-
});
|
|
1630
|
-
readSignal.throwIfAborted();
|
|
1631
|
-
dirty = false;
|
|
1632
|
-
identity = await historyIdentity(path);
|
|
1633
|
-
const current = committed;
|
|
1634
|
-
const valid = scanned <= identity.size && current.sequence <= identity.size && (await historyBoundary(path, identity.identity, current.sequence, readSignal)).epoch === current.epoch;
|
|
1635
|
-
if (!valid) {
|
|
1636
|
-
const value = await reset();
|
|
1637
|
-
synchronized = false;
|
|
1638
|
-
committed = value.liveCursor;
|
|
1639
|
-
scanned = committed.sequence;
|
|
1640
|
-
pendingStart = scanned;
|
|
1641
|
-
accumulator = createHistoryRecordAccumulator(layout);
|
|
1642
|
-
yield { _tag: "snapshot", cursor: committed, value };
|
|
1643
|
-
} else {
|
|
1644
|
-
for await (const info of appended(identity.size)) {
|
|
1645
|
-
const next = await historyBoundary(
|
|
1646
|
-
path,
|
|
1647
|
-
identity.identity,
|
|
1648
|
-
info.range.commit,
|
|
1649
|
-
readSignal
|
|
1650
|
-
);
|
|
1651
|
-
for (let index = 0; index < info.items.length; index += 1) {
|
|
1652
|
-
const total = totalOf(info, index);
|
|
1653
|
-
if (total === 0) {
|
|
1654
|
-
yield {
|
|
1655
|
-
_tag: "delta",
|
|
1656
|
-
cursor: index === info.items.length - 1 ? next : committed,
|
|
1657
|
-
items: [nativeItem(identity.identity, info, index, 0, "")]
|
|
1658
|
-
};
|
|
1659
|
-
continue;
|
|
1660
|
-
}
|
|
1661
|
-
for await (const window2 of historyRecordWindows(
|
|
1662
|
-
path,
|
|
1663
|
-
info,
|
|
1664
|
-
info.items[index].text,
|
|
1665
|
-
0,
|
|
1666
|
-
total,
|
|
1667
|
-
Math.min(12e3, input.textLimit ?? 12e3),
|
|
1668
|
-
layout,
|
|
1669
|
-
readSignal
|
|
1670
|
-
)) {
|
|
1671
|
-
const done = index === info.items.length - 1 && window2.offset + window2.text.length === total;
|
|
1672
|
-
yield {
|
|
1673
|
-
_tag: "delta",
|
|
1674
|
-
cursor: done ? next : committed,
|
|
1675
|
-
items: [nativeItem(identity.identity, info, index, window2.offset, window2.text)]
|
|
1676
|
-
};
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
committed = next;
|
|
1680
|
-
}
|
|
1681
|
-
}
|
|
1682
|
-
if (!synchronized) {
|
|
1683
|
-
synchronized = true;
|
|
1684
|
-
yield { _tag: "synchronized" };
|
|
1685
|
-
}
|
|
1686
|
-
}
|
|
1687
|
-
} finally {
|
|
1688
|
-
watcher.close();
|
|
1689
|
-
readSignal.removeEventListener("abort", abort);
|
|
1690
|
-
wake?.();
|
|
1691
|
-
if (iterator !== void 0) iterators.delete(iterator);
|
|
1692
|
-
}
|
|
1693
|
-
})();
|
|
1694
|
-
iterators.add(iterator);
|
|
1695
|
-
return iterator;
|
|
1696
|
-
};
|
|
1697
|
-
return {
|
|
1698
|
-
page: (input) => tracked(page(input)),
|
|
1699
|
-
follow,
|
|
1700
|
-
close: async () => {
|
|
1701
|
-
controller.abort();
|
|
1702
|
-
await Promise.all([...iterators].map((iterator) => iterator.return(void 0)));
|
|
1703
|
-
await Promise.allSettled(active);
|
|
1704
|
-
}
|
|
1705
|
-
};
|
|
1706
|
-
}
|
|
1707
|
-
|
|
1708
|
-
// ../../packages/ycodium-jsonl-stream/src/claudeSessions.ts
|
|
1709
|
-
import * as NodePath6 from "node:path";
|
|
388
|
+
import * as NodePath3 from "node:path";
|
|
1710
389
|
import * as NodeProcess from "node:process";
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
var DIGEST_FIELDS = [
|
|
1718
|
-
{ path: ["type"] },
|
|
1719
|
-
{ path: ["cwd"] },
|
|
1720
|
-
{ path: ["isSidechain"] },
|
|
1721
|
-
{ path: ["customTitle"] },
|
|
1722
|
-
{ path: ["aiTitle"] },
|
|
1723
|
-
{ path: ["message", "model"] },
|
|
1724
|
-
{ path: ["message", "content"], scalarOnly: true, maxChars: DIGEST_TEXT_KEEP_CHARS },
|
|
1725
|
-
{ path: ["message", "content", "*", "type"] },
|
|
1726
|
-
{ path: ["message", "content", "*", "text"], maxChars: DIGEST_TEXT_KEEP_CHARS }
|
|
1727
|
-
];
|
|
1728
|
-
function truncate(value) {
|
|
1729
|
-
const trimmed = value?.trim() ?? "";
|
|
1730
|
-
if (trimmed.length === 0) return null;
|
|
1731
|
-
return trimmed.length <= PREVIEW_LIMIT ? trimmed : `${trimmed.slice(0, PREVIEW_LIMIT)}\u2026`;
|
|
1732
|
-
}
|
|
1733
|
-
function encodeClaudeProjectDirName(cwd) {
|
|
1734
|
-
return cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
1735
|
-
}
|
|
1736
|
-
function textFromContent(content) {
|
|
1737
|
-
if (typeof content === "string") return content.trim();
|
|
1738
|
-
if (!Array.isArray(content)) return "";
|
|
1739
|
-
const parts = [];
|
|
1740
|
-
for (const block of content) {
|
|
1741
|
-
if (!block || typeof block !== "object") continue;
|
|
1742
|
-
const typed = block;
|
|
1743
|
-
if (typed.type === "text" && typeof typed.text === "string") parts.push(typed.text);
|
|
1744
|
-
}
|
|
1745
|
-
return parts.join("\n\n").trim();
|
|
1746
|
-
}
|
|
1747
|
-
async function readClaudeTranscriptDigest(source, filePath) {
|
|
1748
|
-
let cwd = null;
|
|
1749
|
-
let model = null;
|
|
1750
|
-
let preview = null;
|
|
1751
|
-
let customTitle = null;
|
|
1752
|
-
let aiTitle = null;
|
|
1753
|
-
let turnCount = 0;
|
|
1754
|
-
try {
|
|
1755
|
-
const entries = readJsonlEntries(source, filePath, {
|
|
1756
|
-
maxLineChars: CLAUDE_MAX_PARSED_LINE_BYTES,
|
|
1757
|
-
fields: DIGEST_FIELDS
|
|
1758
|
-
});
|
|
1759
|
-
for await (const entry of entries) {
|
|
1760
|
-
const record3 = jsonlEntryRecord(entry, (line) => {
|
|
1761
|
-
const isUser = line.includes('"type":"user"');
|
|
1762
|
-
const wantsAssistant = model === null && line.includes('"type":"assistant"');
|
|
1763
|
-
const isTitle = line.includes('"custom-title"') || line.includes('"ai-title"');
|
|
1764
|
-
return isUser || wantsAssistant || isTitle;
|
|
1765
|
-
});
|
|
1766
|
-
if (!record3 || typeof record3 !== "object") continue;
|
|
1767
|
-
const typed = record3;
|
|
1768
|
-
if (cwd === null && typeof typed.cwd === "string" && typed.cwd.length > 0) cwd = typed.cwd;
|
|
1769
|
-
if (typed.type === "custom-title" && typeof typed.customTitle === "string") {
|
|
1770
|
-
customTitle = typed.customTitle;
|
|
1771
|
-
continue;
|
|
1772
|
-
}
|
|
1773
|
-
if (typed.type === "ai-title" && typeof typed.aiTitle === "string") {
|
|
1774
|
-
aiTitle = typed.aiTitle;
|
|
1775
|
-
continue;
|
|
1776
|
-
}
|
|
1777
|
-
if (typed.isSidechain === true) continue;
|
|
1778
|
-
if (typed.type === "assistant") {
|
|
1779
|
-
if (model === null && typeof typed.message?.model === "string") model = typed.message.model;
|
|
1780
|
-
continue;
|
|
1781
|
-
}
|
|
1782
|
-
if (typed.type !== "user") continue;
|
|
1783
|
-
const text2 = textFromContent(typed.message?.content);
|
|
1784
|
-
if (text2.length === 0) continue;
|
|
1785
|
-
turnCount += 1;
|
|
1786
|
-
if (preview === null) preview = text2;
|
|
1787
|
-
}
|
|
1788
|
-
} catch {
|
|
1789
|
-
return null;
|
|
1790
|
-
}
|
|
1791
|
-
return {
|
|
1792
|
-
cwd,
|
|
1793
|
-
title: truncate(customTitle ?? aiTitle),
|
|
1794
|
-
preview: truncate(preview),
|
|
1795
|
-
model,
|
|
1796
|
-
turnCount
|
|
1797
|
-
};
|
|
1798
|
-
}
|
|
1799
|
-
async function listClaudeTranscriptFiles(fs2, transcriptDir, directory) {
|
|
1800
|
-
let dirs;
|
|
1801
|
-
try {
|
|
1802
|
-
dirs = (await fs2.readDir(transcriptDir)).filter((entry) => entry.type === "directory").map((entry) => entry.name);
|
|
1803
|
-
} catch {
|
|
1804
|
-
return [];
|
|
1805
|
-
}
|
|
1806
|
-
const encodedRoot = encodeClaudeProjectDirName(directory);
|
|
1807
|
-
const matched = dirs.filter((name) => name.startsWith(encodedRoot));
|
|
1808
|
-
const scanned = matched.length > 0 ? matched : dirs;
|
|
1809
|
-
const found = [];
|
|
1810
|
-
for (const dir of scanned) {
|
|
1811
|
-
const projectDir = NodePath6.join(transcriptDir, dir);
|
|
1812
|
-
let names;
|
|
1813
|
-
try {
|
|
1814
|
-
names = (await fs2.readDir(projectDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(CLAUDE_TRANSCRIPT_SUFFIX)).map((entry) => entry.name);
|
|
1815
|
-
} catch {
|
|
1816
|
-
continue;
|
|
1817
|
-
}
|
|
1818
|
-
for (const name of names) {
|
|
1819
|
-
let stat5;
|
|
1820
|
-
try {
|
|
1821
|
-
stat5 = await fs2.stat(NodePath6.join(projectDir, name));
|
|
1822
|
-
} catch {
|
|
1823
|
-
continue;
|
|
1824
|
-
}
|
|
1825
|
-
found.push({
|
|
1826
|
-
path: NodePath6.join(projectDir, name),
|
|
1827
|
-
sessionId: name.slice(0, -CLAUDE_TRANSCRIPT_SUFFIX.length),
|
|
1828
|
-
size: stat5.size,
|
|
1829
|
-
mtimeMs: Number.isFinite(stat5.mtimeMs) ? stat5.mtimeMs : 0
|
|
1830
|
-
});
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
return found;
|
|
1834
|
-
}
|
|
1835
|
-
async function readClaudeLiveSessionIds(fs2, configDir) {
|
|
1836
|
-
const live = /* @__PURE__ */ new Set();
|
|
1837
|
-
const markerDir = NodePath6.join(configDir, "sessions");
|
|
1838
|
-
let entries;
|
|
1839
|
-
try {
|
|
1840
|
-
entries = (await fs2.readDir(markerDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(".json")).map((entry) => entry.name);
|
|
1841
|
-
} catch {
|
|
1842
|
-
return live;
|
|
1843
|
-
}
|
|
1844
|
-
for (const entry of entries) {
|
|
1845
|
-
let marker;
|
|
1846
|
-
try {
|
|
1847
|
-
marker = JSON.parse(await fs2.readFile(NodePath6.join(markerDir, entry)));
|
|
1848
|
-
} catch {
|
|
1849
|
-
continue;
|
|
1850
|
-
}
|
|
1851
|
-
if (!marker || typeof marker !== "object") continue;
|
|
1852
|
-
const typed = marker;
|
|
1853
|
-
if (typeof typed.pid !== "number" || typeof typed.sessionId !== "string") continue;
|
|
1854
|
-
try {
|
|
1855
|
-
NodeProcess.kill(typed.pid, 0);
|
|
1856
|
-
} catch {
|
|
1857
|
-
continue;
|
|
1858
|
-
}
|
|
1859
|
-
live.add(typed.sessionId);
|
|
1860
|
-
}
|
|
1861
|
-
return live;
|
|
1862
|
-
}
|
|
1863
|
-
|
|
1864
|
-
// ../../packages/ycodium-workspace-path/src/directoryScope.ts
|
|
1865
|
-
var EXTENDED_LENGTH_UNC = "//?/UNC/";
|
|
1866
|
-
var EXTENDED_LENGTH = "//?/";
|
|
1867
|
-
function normalize(value, caseInsensitive) {
|
|
1868
|
-
let unified = value.trim().replace(/\\/gu, "/");
|
|
1869
|
-
const upper = unified.toUpperCase();
|
|
1870
|
-
if (upper.startsWith(EXTENDED_LENGTH_UNC)) {
|
|
1871
|
-
unified = `//${unified.slice(EXTENDED_LENGTH_UNC.length)}`;
|
|
1872
|
-
} else if (upper.startsWith(EXTENDED_LENGTH)) {
|
|
1873
|
-
unified = unified.slice(EXTENDED_LENGTH.length);
|
|
1874
|
-
}
|
|
1875
|
-
const isUnc = unified.startsWith("//");
|
|
1876
|
-
unified = unified.replace(/\/+/gu, "/").replace(/\/+$/u, "");
|
|
1877
|
-
if (isUnc) unified = `/${unified}`;
|
|
1878
|
-
return caseInsensitive ? unified.toLowerCase() : unified;
|
|
1879
|
-
}
|
|
1880
|
-
function isWithinDirectory(candidate, root, caseInsensitive) {
|
|
1881
|
-
const normalizedRoot = normalize(root, caseInsensitive);
|
|
1882
|
-
if (normalizedRoot.length === 0 || normalizedRoot === "/") return false;
|
|
1883
|
-
const normalizedCandidate = normalize(candidate, caseInsensitive);
|
|
1884
|
-
return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(`${normalizedRoot}/`);
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
// src/liveHistory.ts
|
|
390
|
+
import {
|
|
391
|
+
openJsonlHistory,
|
|
392
|
+
waitForJsonlHistory,
|
|
393
|
+
encodeClaudeProjectDirName
|
|
394
|
+
} from "@ycodium-ai/plugin-api/session-history";
|
|
395
|
+
import { isWithinDirectory } from "@ycodium-ai/plugin-api/workspace-path";
|
|
1888
396
|
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1889
397
|
var claudeHistoryLayout = (input) => () => {
|
|
1890
398
|
let sourceTruncated = false;
|
|
@@ -1896,7 +404,7 @@ var claudeHistoryLayout = (input) => () => {
|
|
|
1896
404
|
const verify = (metadata) => {
|
|
1897
405
|
if (!record(metadata) || typeof metadata.sessionId !== "string" || typeof metadata.cwd !== "string")
|
|
1898
406
|
return false;
|
|
1899
|
-
if (metadata.sessionId !== input.parentNativeSessionId || !isWithinDirectory(metadata.cwd, input.cwd,
|
|
407
|
+
if (metadata.sessionId !== input.parentNativeSessionId || !isWithinDirectory(metadata.cwd, input.cwd, NodeProcess.platform === "win32") || !isWithinDirectory(input.cwd, metadata.cwd, NodeProcess.platform === "win32"))
|
|
1900
408
|
throw new Error("Native session ownership does not match the recorded agent.");
|
|
1901
409
|
return true;
|
|
1902
410
|
};
|
|
@@ -1984,21 +492,21 @@ var openClaudeHistory = (input) => {
|
|
|
1984
492
|
for (const id2 of [input.nativeSessionId, input.parentNativeSessionId])
|
|
1985
493
|
if (!/^[A-Za-z0-9_-]+$/u.test(id2)) throw new Error("Invalid native session identifier.");
|
|
1986
494
|
const name = input.nativeSessionId.startsWith("agent-") ? input.nativeSessionId : `agent-${input.nativeSessionId}`;
|
|
1987
|
-
if (input.parentTranscriptPath !== void 0 && (!
|
|
495
|
+
if (input.parentTranscriptPath !== void 0 && (!NodePath3.isAbsolute(input.parentTranscriptPath) || NodePath3.basename(input.parentTranscriptPath) !== `${input.parentNativeSessionId}.jsonl`))
|
|
1988
496
|
throw new Error("Native transcript path does not match the recorded session.");
|
|
1989
|
-
const projectDir = input.parentTranscriptPath === void 0 ?
|
|
1990
|
-
const path =
|
|
497
|
+
const projectDir = input.parentTranscriptPath === void 0 ? NodePath3.join(input.transcriptDir, encodeClaudeProjectDirName(input.cwd)) : NodePath3.dirname(input.parentTranscriptPath);
|
|
498
|
+
const path = NodePath3.join(projectDir, input.parentNativeSessionId, "subagents", `${name}.jsonl`);
|
|
1991
499
|
return waitForJsonlHistory({
|
|
1992
500
|
root: input.parentTranscriptPath === void 0 ? input.transcriptDir : projectDir,
|
|
1993
|
-
accepts: (changed) => changed === path || path.startsWith(changed +
|
|
501
|
+
accepts: (changed) => changed === path || path.startsWith(changed + NodePath3.sep),
|
|
1994
502
|
open: (signal) => openJsonlHistory(path, claudeHistoryLayout(input), signal),
|
|
1995
503
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1996
504
|
});
|
|
1997
505
|
};
|
|
1998
506
|
|
|
1999
507
|
// src/claudeInstance.ts
|
|
2000
|
-
import * as
|
|
2001
|
-
import * as
|
|
508
|
+
import * as NodeOS9 from "node:os";
|
|
509
|
+
import * as NodePath14 from "node:path";
|
|
2002
510
|
|
|
2003
511
|
// ../../node_modules/.pnpm/@anthropic-ai+claude-agent-sdk@0.3.170_@anthropic-ai+sdk@0.93.0_zod@4.6.5__@modelcontex_64204813d4dba2ebc464c3aa751485a4/node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs
|
|
2004
512
|
import { createRequire as xz } from "node:module";
|
|
@@ -21431,10 +19939,11 @@ function HU(e, t) {
|
|
|
21431
19939
|
}
|
|
21432
19940
|
|
|
21433
19941
|
// src/claudeInstance.ts
|
|
21434
|
-
import { mergeLaunchEnv as
|
|
21435
|
-
import { isOperationCleanupError as
|
|
19942
|
+
import { mergeLaunchEnv as mergeLaunchEnv4 } from "@ycodium-ai/plugin-api/executor";
|
|
19943
|
+
import { isOperationCleanupError as isOperationCleanupError4 } from "@ycodium-ai/plugin-api/process-operation";
|
|
21436
19944
|
|
|
21437
19945
|
// src/claudeProbe.ts
|
|
19946
|
+
import { readCliVersionCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
21438
19947
|
import {
|
|
21439
19948
|
describeExecutorSpawnFailure,
|
|
21440
19949
|
ExecutorSpawnAbortedError,
|
|
@@ -21446,12 +19955,10 @@ import {
|
|
|
21446
19955
|
} from "@ycodium-ai/plugin-api/process-operation";
|
|
21447
19956
|
|
|
21448
19957
|
// src/usageRead/quota.ts
|
|
21449
|
-
import
|
|
21450
|
-
import * as
|
|
21451
|
-
import
|
|
21452
|
-
import {
|
|
21453
|
-
parseRetryAfterMs
|
|
21454
|
-
} from "@ycodium-ai/plugin-api/usage";
|
|
19958
|
+
import { clampPercent, requestQuotaJson } from "@ycodium-ai/plugin-api/credential-account";
|
|
19959
|
+
import * as NodeFS from "node:fs";
|
|
19960
|
+
import * as NodePath4 from "node:path";
|
|
19961
|
+
import { mergeLaunchEnv, setsOwnModelConnection } from "@ycodium-ai/plugin-api/executor";
|
|
21455
19962
|
var CLAUDE_QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
21456
19963
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
21457
19964
|
var HOUR_MS = 60 * 60 * 1e3;
|
|
@@ -21460,7 +19967,7 @@ var CLAUDE_QUOTA_WINDOWS = [
|
|
|
21460
19967
|
{ field: "seven_day", id: "weekly", labelKey: "usage.window.weekly", windowMs: 7 * 24 * HOUR_MS }
|
|
21461
19968
|
];
|
|
21462
19969
|
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21463
|
-
var launchEnvironment = (recipe) =>
|
|
19970
|
+
var launchEnvironment = (recipe) => mergeLaunchEnv({
|
|
21464
19971
|
inherited: process.env,
|
|
21465
19972
|
instanceTable: recipe.environment,
|
|
21466
19973
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -21470,14 +19977,14 @@ var claudeCredentialFileCandidates = (recipe) => {
|
|
|
21470
19977
|
const credentialsDir = resolveClaudeCredentialsDirPath(
|
|
21471
19978
|
environment[CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE] ?? ""
|
|
21472
19979
|
);
|
|
21473
|
-
if (credentialsDir !== null) return [
|
|
19980
|
+
if (credentialsDir !== null) return [NodePath4.join(credentialsDir, ".credentials.json")];
|
|
21474
19981
|
const configDir = resolveClaudeConfigDirPath(recipe.homePath, environment);
|
|
21475
19982
|
const home = resolveClaudeHomePath(recipe.homePath);
|
|
21476
19983
|
return [
|
|
21477
19984
|
.../* @__PURE__ */ new Set([
|
|
21478
|
-
|
|
21479
|
-
|
|
21480
|
-
|
|
19985
|
+
NodePath4.join(configDir, ".credentials.json"),
|
|
19986
|
+
NodePath4.join(home, ".claude", ".credentials.json"),
|
|
19987
|
+
NodePath4.join(home, ".credentials.json")
|
|
21481
19988
|
])
|
|
21482
19989
|
];
|
|
21483
19990
|
};
|
|
@@ -21486,7 +19993,7 @@ var readLoginCredential = (candidates) => {
|
|
|
21486
19993
|
for (const path of candidates) {
|
|
21487
19994
|
let raw;
|
|
21488
19995
|
try {
|
|
21489
|
-
raw =
|
|
19996
|
+
raw = NodeFS.readFileSync(path, "utf8");
|
|
21490
19997
|
} catch {
|
|
21491
19998
|
continue;
|
|
21492
19999
|
}
|
|
@@ -21531,7 +20038,7 @@ var readClaudeQuotaWindows = (body) => CLAUDE_QUOTA_WINDOWS.flatMap((spec) => {
|
|
|
21531
20038
|
{
|
|
21532
20039
|
id: spec.id,
|
|
21533
20040
|
label: { key: spec.labelKey },
|
|
21534
|
-
usedPercent:
|
|
20041
|
+
usedPercent: clampPercent(utilization),
|
|
21535
20042
|
resetsAt: toIso(row["resets_at"]),
|
|
21536
20043
|
windowMs: spec.windowMs
|
|
21537
20044
|
}
|
|
@@ -21560,63 +20067,36 @@ var readClaudeQuota = async (request) => {
|
|
|
21560
20067
|
const credential = readLoginCredential(claudeCredentialFileCandidates(recipe));
|
|
21561
20068
|
if (credential === null) return { status: "unavailable", reason: "missingCredentials" };
|
|
21562
20069
|
const now = request.now ?? Date.now;
|
|
21563
|
-
|
|
21564
|
-
|
|
21565
|
-
|
|
21566
|
-
|
|
21567
|
-
|
|
21568
|
-
|
|
21569
|
-
|
|
21570
|
-
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
const release = () => {
|
|
21580
|
-
void response.body?.cancel().catch(() => void 0);
|
|
21581
|
-
};
|
|
21582
|
-
if (response.status === 429) {
|
|
21583
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("Retry-After"), now());
|
|
21584
|
-
release();
|
|
21585
|
-
return {
|
|
21586
|
-
status: "unavailable",
|
|
21587
|
-
reason: "rateLimited",
|
|
21588
|
-
...retryAfterMs === null ? {} : { retryAfterMs }
|
|
21589
|
-
};
|
|
21590
|
-
}
|
|
21591
|
-
if (response.status === 401 || response.status === 403) {
|
|
21592
|
-
release();
|
|
21593
|
-
return { status: "unavailable", reason: "authRejected" };
|
|
21594
|
-
}
|
|
21595
|
-
if (response.status < 200 || response.status >= 300) {
|
|
21596
|
-
release();
|
|
21597
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
21598
|
-
}
|
|
21599
|
-
let body;
|
|
21600
|
-
try {
|
|
21601
|
-
body = JSON.parse(await response.text());
|
|
21602
|
-
} catch {
|
|
21603
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
21604
|
-
}
|
|
21605
|
-
if (!isRecord2(body)) return { status: "unavailable", reason: "unreachable" };
|
|
20070
|
+
const answer = await requestQuotaJson({
|
|
20071
|
+
fetch: request.fetch,
|
|
20072
|
+
url: CLAUDE_QUOTA_URL,
|
|
20073
|
+
method: "GET",
|
|
20074
|
+
headers: {
|
|
20075
|
+
Accept: "application/json",
|
|
20076
|
+
"anthropic-beta": "oauth-2025-04-20",
|
|
20077
|
+
Authorization: `Bearer ${credential.accessToken}`
|
|
20078
|
+
},
|
|
20079
|
+
redirect: "error",
|
|
20080
|
+
propagateCallerAbort: true,
|
|
20081
|
+
signal: request.signal,
|
|
20082
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
20083
|
+
now
|
|
20084
|
+
});
|
|
20085
|
+
if (!("body" in answer)) return answer;
|
|
21606
20086
|
const plan = claudePlanName(credential);
|
|
21607
20087
|
return {
|
|
21608
20088
|
status: "available",
|
|
21609
20089
|
...plan === void 0 ? {} : { plan },
|
|
21610
|
-
windows: readClaudeQuotaWindows(body),
|
|
20090
|
+
windows: readClaudeQuotaWindows(answer.body),
|
|
21611
20091
|
balances: [],
|
|
21612
20092
|
accountKey: credential.path
|
|
21613
20093
|
};
|
|
21614
20094
|
};
|
|
21615
20095
|
|
|
21616
20096
|
// src/claudeSkills.ts
|
|
21617
|
-
import * as
|
|
21618
|
-
import * as
|
|
21619
|
-
import * as
|
|
20097
|
+
import * as NodeFSP from "node:fs/promises";
|
|
20098
|
+
import * as NodePath5 from "node:path";
|
|
20099
|
+
import * as NodeProcess2 from "node:process";
|
|
21620
20100
|
var FRONT_MATTER_KEY = /^(description|disable-model-invocation|user-invocable|argument-hint):[ \t]*(.*)$/;
|
|
21621
20101
|
var BLOCK_SCALAR = /^[|>][+-]?$/;
|
|
21622
20102
|
function parseFrontMatterBoolean(value) {
|
|
@@ -21681,7 +20161,7 @@ function claudeManagedSettingsPath(platform4, environment) {
|
|
|
21681
20161
|
}
|
|
21682
20162
|
if (platform4 === "win32") {
|
|
21683
20163
|
const programData = environment["PROGRAMDATA"]?.trim();
|
|
21684
|
-
return programData ?
|
|
20164
|
+
return programData ? NodePath5.join(programData, "ClaudeCode", "managed-settings.json") : void 0;
|
|
21685
20165
|
}
|
|
21686
20166
|
return "/etc/claude-code/managed-settings.json";
|
|
21687
20167
|
}
|
|
@@ -21689,24 +20169,24 @@ function skillOverrideSettingsPaths(configDirPath, cwd, platform4, environment,
|
|
|
21689
20169
|
const managedPath = claudeManagedSettingsPath(platform4, environment);
|
|
21690
20170
|
const root = repositoryRoot !== void 0 && repositoryRoot !== cwd ? repositoryRoot : void 0;
|
|
21691
20171
|
return [
|
|
21692
|
-
|
|
20172
|
+
NodePath5.join(configDirPath, "settings.json"),
|
|
21693
20173
|
...cwd ? [
|
|
21694
|
-
|
|
21695
|
-
|
|
20174
|
+
NodePath5.join(cwd, ".claude", "settings.json"),
|
|
20175
|
+
NodePath5.join(cwd, ".claude", "settings.local.json")
|
|
21696
20176
|
] : [],
|
|
21697
|
-
...root ? [
|
|
20177
|
+
...root ? [NodePath5.join(root, ".claude", "settings.local.json")] : [],
|
|
21698
20178
|
...managedPath ? [managedPath] : []
|
|
21699
20179
|
];
|
|
21700
20180
|
}
|
|
21701
20181
|
async function findRepositoryRoot(cwd) {
|
|
21702
|
-
let current =
|
|
20182
|
+
let current = NodePath5.resolve(cwd);
|
|
21703
20183
|
for (; ; ) {
|
|
21704
|
-
const found = await
|
|
20184
|
+
const found = await NodeFSP.stat(NodePath5.join(current, ".git")).then(
|
|
21705
20185
|
() => true,
|
|
21706
20186
|
() => false
|
|
21707
20187
|
);
|
|
21708
20188
|
if (found) return current;
|
|
21709
|
-
const parent =
|
|
20189
|
+
const parent = NodePath5.dirname(current);
|
|
21710
20190
|
if (parent === current) return void 0;
|
|
21711
20191
|
current = parent;
|
|
21712
20192
|
}
|
|
@@ -21771,7 +20251,7 @@ async function readSkillOverrides(configDirPath, cwd, platform4, environment) {
|
|
|
21771
20251
|
environment,
|
|
21772
20252
|
repositoryRoot
|
|
21773
20253
|
)) {
|
|
21774
|
-
const contents = await
|
|
20254
|
+
const contents = await NodeFSP.readFile(settingsPath, "utf8").catch(() => void 0);
|
|
21775
20255
|
if (contents === void 0) continue;
|
|
21776
20256
|
for (const [name, override] of readOverridesFromSettings(contents) ?? []) {
|
|
21777
20257
|
merged.set(name, override);
|
|
@@ -21784,21 +20264,21 @@ async function discoverClaudeSkills(configDirPath, options = {}) {
|
|
|
21784
20264
|
const overrides = await readSkillOverrides(
|
|
21785
20265
|
configDirPath,
|
|
21786
20266
|
cwd,
|
|
21787
|
-
options.platform ??
|
|
21788
|
-
options.environment ??
|
|
20267
|
+
options.platform ?? NodeProcess2.platform,
|
|
20268
|
+
options.environment ?? NodeProcess2.env
|
|
21789
20269
|
);
|
|
21790
20270
|
const roots = [
|
|
21791
|
-
{ directory:
|
|
21792
|
-
...cwd ? [{ directory:
|
|
20271
|
+
{ directory: NodePath5.join(configDirPath, "skills"), scope: "user" },
|
|
20272
|
+
...cwd ? [{ directory: NodePath5.join(cwd, ".claude", "skills"), scope: "project" }] : []
|
|
21793
20273
|
];
|
|
21794
20274
|
const skills = /* @__PURE__ */ new Map();
|
|
21795
20275
|
for (const root of roots) {
|
|
21796
|
-
const entries = await
|
|
20276
|
+
const entries = await NodeFSP.readdir(root.directory).catch(() => []);
|
|
21797
20277
|
for (const entry of entries.toSorted()) {
|
|
21798
20278
|
const name = entry.trim();
|
|
21799
20279
|
if (name.length === 0 || skills.has(name)) continue;
|
|
21800
|
-
const skillPath =
|
|
21801
|
-
const contents = await
|
|
20280
|
+
const skillPath = NodePath5.join(root.directory, entry, "SKILL.md");
|
|
20281
|
+
const contents = await NodeFSP.readFile(skillPath, "utf8").catch(() => void 0);
|
|
21802
20282
|
if (contents === void 0) continue;
|
|
21803
20283
|
const frontMatter = parseSkillFrontMatter(contents);
|
|
21804
20284
|
const override = overrides.get(name);
|
|
@@ -22176,6 +20656,7 @@ function createClaudeProbe(input) {
|
|
|
22176
20656
|
command = await runProcessOperation(commandHost, {
|
|
22177
20657
|
program: recipe.binaryPath,
|
|
22178
20658
|
args: ["--version"],
|
|
20659
|
+
env: recipe.environment,
|
|
22179
20660
|
timeoutMs: CLAUDE_VERSION_TIMEOUT_MS,
|
|
22180
20661
|
maxOutputBytes: 64 * 1024,
|
|
22181
20662
|
owner: { bindingId: host.bindingId },
|
|
@@ -22258,27 +20739,20 @@ var CLAUDE_VERSION_TIMEOUT_MS = 15e3;
|
|
|
22258
20739
|
async function readClaudeCliVersion(input) {
|
|
22259
20740
|
input.signal?.throwIfAborted();
|
|
22260
20741
|
if (input.recipe.binaryPath.length === 0) return null;
|
|
22261
|
-
|
|
22262
|
-
|
|
22263
|
-
|
|
22264
|
-
|
|
22265
|
-
|
|
22266
|
-
|
|
22267
|
-
|
|
22268
|
-
|
|
22269
|
-
});
|
|
22270
|
-
return parseGenericCliVersion(stdout + "\n" + stderr);
|
|
22271
|
-
} catch (error) {
|
|
22272
|
-
if (isOperationCleanupError(error)) throw error;
|
|
22273
|
-
input.signal?.throwIfAborted();
|
|
22274
|
-
return null;
|
|
22275
|
-
}
|
|
20742
|
+
return readCliVersionCommand(input.host, {
|
|
20743
|
+
program: input.recipe.binaryPath,
|
|
20744
|
+
env: input.recipe.environment,
|
|
20745
|
+
signal: input.signal,
|
|
20746
|
+
timeoutMs: CLAUDE_VERSION_TIMEOUT_MS,
|
|
20747
|
+
parse: parseGenericCliVersion,
|
|
20748
|
+
acceptNonzeroExit: true
|
|
20749
|
+
});
|
|
22276
20750
|
}
|
|
22277
20751
|
|
|
22278
20752
|
// src/claudeExecutable.ts
|
|
22279
|
-
import * as
|
|
22280
|
-
import * as
|
|
22281
|
-
import * as
|
|
20753
|
+
import * as NodeFS2 from "node:fs";
|
|
20754
|
+
import * as NodeOS3 from "node:os";
|
|
20755
|
+
import * as NodePath6 from "node:path";
|
|
22282
20756
|
var WINDOWS_SHIM_EXTENSIONS = /* @__PURE__ */ new Set([".cmd", ".bat", ".ps1"]);
|
|
22283
20757
|
var NPM_PACKAGE_ENTRY_CANDIDATES = [
|
|
22284
20758
|
["node_modules", "@anthropic-ai", "claude-code", "bin", "claude.exe"],
|
|
@@ -22286,23 +20760,23 @@ var NPM_PACKAGE_ENTRY_CANDIDATES = [
|
|
|
22286
20760
|
];
|
|
22287
20761
|
function isExistingFile(filePath) {
|
|
22288
20762
|
try {
|
|
22289
|
-
return
|
|
20763
|
+
return NodeFS2.statSync(filePath).isFile();
|
|
22290
20764
|
} catch {
|
|
22291
20765
|
return false;
|
|
22292
20766
|
}
|
|
22293
20767
|
}
|
|
22294
|
-
function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, isFile = isExistingFile, isWindows =
|
|
20768
|
+
function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, isFile = isExistingFile, isWindows = NodeOS3.type() === "Windows_NT") {
|
|
22295
20769
|
if (!isWindows) {
|
|
22296
20770
|
return binaryPath;
|
|
22297
20771
|
}
|
|
22298
20772
|
const resolved = resolveWindowsExecutable(binaryPath, environment) ?? binaryPath;
|
|
22299
|
-
const extension =
|
|
20773
|
+
const extension = NodePath6.win32.extname(resolved).toLowerCase();
|
|
22300
20774
|
if (!WINDOWS_SHIM_EXTENSIONS.has(extension)) {
|
|
22301
20775
|
return resolved;
|
|
22302
20776
|
}
|
|
22303
|
-
const shimDirectory =
|
|
20777
|
+
const shimDirectory = NodePath6.win32.dirname(resolved);
|
|
22304
20778
|
for (const entrySegments of NPM_PACKAGE_ENTRY_CANDIDATES) {
|
|
22305
|
-
const candidate =
|
|
20779
|
+
const candidate = NodePath6.win32.join(shimDirectory, ...entrySegments);
|
|
22306
20780
|
if (isFile(candidate)) {
|
|
22307
20781
|
return candidate;
|
|
22308
20782
|
}
|
|
@@ -22312,14 +20786,14 @@ function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, i
|
|
|
22312
20786
|
function resolveWindowsExecutable(binaryPath, environment) {
|
|
22313
20787
|
const trimmed = binaryPath.trim();
|
|
22314
20788
|
if (trimmed.length === 0) return void 0;
|
|
22315
|
-
if (
|
|
20789
|
+
if (NodePath6.win32.isAbsolute(trimmed) && isExistingFile(trimmed)) return trimmed;
|
|
22316
20790
|
const pathValue = environment.PATH ?? environment.Path ?? "";
|
|
22317
20791
|
const pathext = environment.PATHEXT ?? ".EXE;.CMD;.BAT;.COM";
|
|
22318
20792
|
const extensions = pathext.split(";").filter((ext) => ext.length > 0);
|
|
22319
|
-
const hasExt =
|
|
20793
|
+
const hasExt = NodePath6.win32.extname(trimmed).length > 0;
|
|
22320
20794
|
for (const dir of pathValue.split(";")) {
|
|
22321
20795
|
if (dir.trim().length === 0) continue;
|
|
22322
|
-
const candidates = hasExt ? [
|
|
20796
|
+
const candidates = hasExt ? [NodePath6.win32.join(dir, trimmed)] : extensions.map((ext) => NodePath6.win32.join(dir, `${trimmed}${ext}`));
|
|
22323
20797
|
for (const candidate of candidates) {
|
|
22324
20798
|
if (isExistingFile(candidate)) return candidate;
|
|
22325
20799
|
}
|
|
@@ -22671,9 +21145,9 @@ var PromptQueue = class {
|
|
|
22671
21145
|
const queued = this.#queued.shift();
|
|
22672
21146
|
if (queued !== void 0) return Promise.resolve(queued);
|
|
22673
21147
|
if (this.#closed) return Promise.resolve(void 0);
|
|
22674
|
-
return new Promise((
|
|
21148
|
+
return new Promise((resolve5) => {
|
|
22675
21149
|
this.#waiters.push((result) => {
|
|
22676
|
-
|
|
21150
|
+
resolve5(result.done ? void 0 : result.value);
|
|
22677
21151
|
});
|
|
22678
21152
|
});
|
|
22679
21153
|
}
|
|
@@ -22973,175 +21447,8 @@ var claudeStructuredErrorType = (value) => {
|
|
|
22973
21447
|
return typeof type4 === "string" ? type4 : void 0;
|
|
22974
21448
|
};
|
|
22975
21449
|
|
|
22976
|
-
// ../../packages/ycodium-tool-label/src/toolLabel.ts
|
|
22977
|
-
var DETAIL_MAX_CHARS = 200;
|
|
22978
|
-
var LABEL_TEXT_MAX_CHARS = 400;
|
|
22979
|
-
var SUMMARY_KEYS = [
|
|
22980
|
-
"description",
|
|
22981
|
-
"title",
|
|
22982
|
-
"query",
|
|
22983
|
-
"pattern",
|
|
22984
|
-
"url",
|
|
22985
|
-
"command",
|
|
22986
|
-
"cmd",
|
|
22987
|
-
"prompt",
|
|
22988
|
-
"name",
|
|
22989
|
-
"path"
|
|
22990
|
-
];
|
|
22991
|
-
var PATH_KEYS = ["file_path", "notebook_path"];
|
|
22992
|
-
function asTrimmedString(value) {
|
|
22993
|
-
if (typeof value !== "string") {
|
|
22994
|
-
return void 0;
|
|
22995
|
-
}
|
|
22996
|
-
const trimmed = value.trim();
|
|
22997
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
22998
|
-
}
|
|
22999
|
-
function asPositiveInt(value) {
|
|
23000
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
23001
|
-
}
|
|
23002
|
-
function replacementDiffStat(input, budget) {
|
|
23003
|
-
if (input.replace_all === true) return void 0;
|
|
23004
|
-
const oldText = input.old_string ?? input.oldText;
|
|
23005
|
-
const newText = input.new_string ?? input.newText;
|
|
23006
|
-
if (typeof oldText !== "string" || typeof newText !== "string") return void 0;
|
|
23007
|
-
budget.characters -= oldText.length + newText.length;
|
|
23008
|
-
if (budget.characters < 0) return void 0;
|
|
23009
|
-
const before = oldText.match(/[^\n]*\n|[^\n]+$/gu) ?? [];
|
|
23010
|
-
const after = newText.match(/[^\n]*\n|[^\n]+$/gu) ?? [];
|
|
23011
|
-
let start = 0;
|
|
23012
|
-
let beforeEnd = before.length;
|
|
23013
|
-
let afterEnd = after.length;
|
|
23014
|
-
while (start < beforeEnd && start < afterEnd && before[start] === after[start]) start += 1;
|
|
23015
|
-
while (beforeEnd > start && afterEnd > start && before[beforeEnd - 1] === after[afterEnd - 1]) {
|
|
23016
|
-
beforeEnd -= 1;
|
|
23017
|
-
afterEnd -= 1;
|
|
23018
|
-
}
|
|
23019
|
-
const deleted = beforeEnd - start;
|
|
23020
|
-
const added = afterEnd - start;
|
|
23021
|
-
budget.cells -= deleted * added;
|
|
23022
|
-
if (budget.cells < 0) return void 0;
|
|
23023
|
-
const lengths = new Uint32Array(added + 1);
|
|
23024
|
-
for (let i = start; i < beforeEnd; i += 1) {
|
|
23025
|
-
let diagonal = 0;
|
|
23026
|
-
for (let j3 = 1; j3 <= added; j3 += 1) {
|
|
23027
|
-
const previous = lengths[j3] ?? 0;
|
|
23028
|
-
lengths[j3] = before[i] === after[start + j3 - 1] ? diagonal + 1 : Math.max(previous, lengths[j3 - 1] ?? 0);
|
|
23029
|
-
diagonal = previous;
|
|
23030
|
-
}
|
|
23031
|
-
}
|
|
23032
|
-
const shared = lengths[added] ?? 0;
|
|
23033
|
-
return { additions: added - shared, deletions: deleted - shared };
|
|
23034
|
-
}
|
|
23035
|
-
function inputDiffStat(input) {
|
|
23036
|
-
const budget = { characters: 2e5, cells: 25e4 };
|
|
23037
|
-
if (!Array.isArray(input.edits)) return replacementDiffStat(input, budget);
|
|
23038
|
-
if (input.edits.length === 0 || input.edits.length > 100 || input.replace_all === true)
|
|
23039
|
-
return void 0;
|
|
23040
|
-
let additions = 0;
|
|
23041
|
-
let deletions = 0;
|
|
23042
|
-
for (const edit of input.edits) {
|
|
23043
|
-
if (edit === null || typeof edit !== "object" || Array.isArray(edit)) return void 0;
|
|
23044
|
-
const stat5 = replacementDiffStat(edit, budget);
|
|
23045
|
-
if (!stat5) return void 0;
|
|
23046
|
-
additions += stat5.additions;
|
|
23047
|
-
deletions += stat5.deletions;
|
|
23048
|
-
}
|
|
23049
|
-
return { additions, deletions };
|
|
23050
|
-
}
|
|
23051
|
-
function collapse(value, max) {
|
|
23052
|
-
const collapsed = value.replace(/\s+/gu, " ").trim();
|
|
23053
|
-
return collapsed.length <= max ? collapsed : `${collapsed.slice(0, max - 1).trimEnd()}\u2026`;
|
|
23054
|
-
}
|
|
23055
|
-
function displayToolName(toolName) {
|
|
23056
|
-
const trimmed = toolName.trim();
|
|
23057
|
-
if (!trimmed.startsWith("mcp__")) {
|
|
23058
|
-
return trimmed;
|
|
23059
|
-
}
|
|
23060
|
-
const rest = trimmed.slice("mcp__".length).replaceAll("__", " ").trim();
|
|
23061
|
-
return rest.length > 0 ? rest : trimmed;
|
|
23062
|
-
}
|
|
23063
|
-
function readRangeSuffix(input) {
|
|
23064
|
-
const offset = asPositiveInt(input.offset);
|
|
23065
|
-
const limit = asPositiveInt(input.limit);
|
|
23066
|
-
if (offset !== void 0 && limit !== void 0) {
|
|
23067
|
-
return `(lines ${offset}-${offset + limit - 1})`;
|
|
23068
|
-
}
|
|
23069
|
-
if (offset !== void 0) {
|
|
23070
|
-
return `(from line ${offset})`;
|
|
23071
|
-
}
|
|
23072
|
-
if (limit !== void 0) {
|
|
23073
|
-
return `(first ${limit} lines)`;
|
|
23074
|
-
}
|
|
23075
|
-
return void 0;
|
|
23076
|
-
}
|
|
23077
|
-
function loneStringValue(input) {
|
|
23078
|
-
let found;
|
|
23079
|
-
for (const value of Object.values(input)) {
|
|
23080
|
-
const text2 = asTrimmedString(value);
|
|
23081
|
-
if (text2 === void 0) {
|
|
23082
|
-
continue;
|
|
23083
|
-
}
|
|
23084
|
-
if (found !== void 0) {
|
|
23085
|
-
return void 0;
|
|
23086
|
-
}
|
|
23087
|
-
found = text2;
|
|
23088
|
-
}
|
|
23089
|
-
return found;
|
|
23090
|
-
}
|
|
23091
|
-
function compactJson(input) {
|
|
23092
|
-
let serialized;
|
|
23093
|
-
try {
|
|
23094
|
-
serialized = JSON.stringify(input);
|
|
23095
|
-
} catch {
|
|
23096
|
-
return void 0;
|
|
23097
|
-
}
|
|
23098
|
-
if (!serialized || serialized === "{}" || serialized === "[]") {
|
|
23099
|
-
return void 0;
|
|
23100
|
-
}
|
|
23101
|
-
return collapse(serialized, DETAIL_MAX_CHARS);
|
|
23102
|
-
}
|
|
23103
|
-
function formatToolLabel(toolName, input) {
|
|
23104
|
-
const name = displayToolName(toolName);
|
|
23105
|
-
const diffStat = inputDiffStat(input);
|
|
23106
|
-
if (name.endsWith("visualize_visualize") && typeof input.fragment === "string") {
|
|
23107
|
-
const { fragment: _fragment, ...rest } = input;
|
|
23108
|
-
return formatToolLabel(toolName, rest);
|
|
23109
|
-
}
|
|
23110
|
-
for (const key of PATH_KEYS) {
|
|
23111
|
-
const path = asTrimmedString(input[key]);
|
|
23112
|
-
if (path === void 0) {
|
|
23113
|
-
continue;
|
|
23114
|
-
}
|
|
23115
|
-
const suffix = readRangeSuffix(input);
|
|
23116
|
-
return {
|
|
23117
|
-
name,
|
|
23118
|
-
path,
|
|
23119
|
-
...suffix ? { detail: suffix } : {},
|
|
23120
|
-
...diffStat ? { diffStat } : {},
|
|
23121
|
-
descriptive: true
|
|
23122
|
-
};
|
|
23123
|
-
}
|
|
23124
|
-
for (const key of SUMMARY_KEYS) {
|
|
23125
|
-
const value = asTrimmedString(input[key]);
|
|
23126
|
-
if (value !== void 0) {
|
|
23127
|
-
const detail = collapse(value, DETAIL_MAX_CHARS);
|
|
23128
|
-
const scope = key === "pattern" ? asTrimmedString(input.path) : void 0;
|
|
23129
|
-
return { name, ...scope ? { path: scope } : {}, detail, descriptive: true };
|
|
23130
|
-
}
|
|
23131
|
-
}
|
|
23132
|
-
const lone = loneStringValue(input);
|
|
23133
|
-
if (lone !== void 0) {
|
|
23134
|
-
return { name, detail: collapse(lone, DETAIL_MAX_CHARS), descriptive: true };
|
|
23135
|
-
}
|
|
23136
|
-
const compact = compactJson(input);
|
|
23137
|
-
return { name, ...compact ? { detail: compact } : {}, descriptive: false };
|
|
23138
|
-
}
|
|
23139
|
-
function formatToolLabelText(label) {
|
|
23140
|
-
const joined = [label.name, label.path, label.detail].filter((part) => part).join(" ");
|
|
23141
|
-
return joined.length <= LABEL_TEXT_MAX_CHARS ? joined : `${joined.slice(0, LABEL_TEXT_MAX_CHARS - 1).trimEnd()}\u2026`;
|
|
23142
|
-
}
|
|
23143
|
-
|
|
23144
21450
|
// src/toolClassify.ts
|
|
21451
|
+
import { formatToolLabel, formatToolLabelText } from "@ycodium-ai/plugin-api/display-format";
|
|
23145
21452
|
function classifyToolItemType(toolName) {
|
|
23146
21453
|
const normalized = toolName.toLowerCase();
|
|
23147
21454
|
if (normalized.startsWith("mcp__")) {
|
|
@@ -23250,12 +21557,12 @@ function claudeTaskRosterKind(input) {
|
|
|
23250
21557
|
return void 0;
|
|
23251
21558
|
}
|
|
23252
21559
|
var PENDING_TASK_MODEL_CAP = 64;
|
|
23253
|
-
function rememberPendingTaskModel(
|
|
23254
|
-
|
|
23255
|
-
if (
|
|
23256
|
-
const oldest =
|
|
21560
|
+
function rememberPendingTaskModel(pending, parentToolUseId, model) {
|
|
21561
|
+
pending.set(parentToolUseId, model);
|
|
21562
|
+
if (pending.size > PENDING_TASK_MODEL_CAP) {
|
|
21563
|
+
const oldest = pending.keys().next();
|
|
23257
21564
|
if (!oldest.done) {
|
|
23258
|
-
|
|
21565
|
+
pending.delete(oldest.value);
|
|
23259
21566
|
}
|
|
23260
21567
|
}
|
|
23261
21568
|
}
|
|
@@ -23801,126 +22108,18 @@ var makeEventEmitter = (deps) => {
|
|
|
23801
22108
|
...event
|
|
23802
22109
|
});
|
|
23803
22110
|
};
|
|
23804
|
-
return { nowIso, randomUUIDv4, makeEventStamp, eventHeader, offerRuntimeEvent };
|
|
23805
|
-
};
|
|
23806
|
-
|
|
23807
|
-
// ../../packages/ycodium-instance-config/src/instanceConfig.ts
|
|
23808
|
-
import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
|
|
23809
|
-
function isRecord4(value) {
|
|
23810
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23811
|
-
}
|
|
23812
|
-
function readString3(value) {
|
|
23813
|
-
return typeof value === "string" ? value : "";
|
|
23814
|
-
}
|
|
23815
|
-
function readTrimmed(value) {
|
|
23816
|
-
return readString3(value).trim();
|
|
23817
|
-
}
|
|
23818
|
-
function modelIdFromSelection(selection) {
|
|
23819
|
-
if (!isRecord4(selection)) return void 0;
|
|
23820
|
-
const model = selection["model"];
|
|
23821
|
-
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
23822
|
-
}
|
|
23823
|
-
function readEnvironment(value) {
|
|
23824
|
-
if (!Array.isArray(value)) return {};
|
|
23825
|
-
const env2 = {};
|
|
23826
|
-
for (const entry of value) {
|
|
23827
|
-
if (!isRecord4(entry)) continue;
|
|
23828
|
-
const name = readTrimmed(entry["name"]);
|
|
23829
|
-
if (name.length === 0) continue;
|
|
23830
|
-
env2[name] = readString3(entry["value"]);
|
|
23831
|
-
}
|
|
23832
|
-
return env2;
|
|
23833
|
-
}
|
|
23834
|
-
function instanceSettings(config) {
|
|
23835
|
-
if (!isRecord4(config)) return {};
|
|
23836
|
-
return isRecord4(config["config"]) ? config["config"] : config;
|
|
23837
|
-
}
|
|
23838
|
-
function readInstanceEnvelope(config) {
|
|
23839
|
-
const envelope = isRecord4(config) ? config : {};
|
|
23840
|
-
const settings = instanceSettings(config);
|
|
23841
|
-
return {
|
|
23842
|
-
settings,
|
|
23843
|
-
settingOrEnvelope: (key) => readTrimmed(settings[key]) || readTrimmed(envelope[key]),
|
|
23844
|
-
environment: readEnvironment(envelope["environment"]),
|
|
23845
|
-
envelopeDriver: readTrimmed(envelope["driver"]) || void 0
|
|
23846
|
-
};
|
|
23847
|
-
}
|
|
23848
|
-
function readCustomModel(entry) {
|
|
23849
|
-
if (typeof entry === "string") {
|
|
23850
|
-
const slug2 = entry.trim();
|
|
23851
|
-
return slug2.length > 0 ? { slug: slug2 } : void 0;
|
|
23852
|
-
}
|
|
23853
|
-
if (!isRecord4(entry)) return void 0;
|
|
23854
|
-
const slug = readTrimmed(entry["slug"]);
|
|
23855
|
-
if (slug.length === 0) return void 0;
|
|
23856
|
-
const aliasesRaw = entry["aliases"];
|
|
23857
|
-
const aliases = Array.isArray(aliasesRaw) ? aliasesRaw.filter(
|
|
23858
|
-
(alias) => typeof alias === "string" && alias.trim().length > 0
|
|
23859
|
-
) : void 0;
|
|
23860
|
-
const contextWindow = typeof entry["contextWindow"] === "number" && Number.isFinite(entry["contextWindow"]) && entry["contextWindow"] > 0 ? Math.round(entry["contextWindow"]) : void 0;
|
|
23861
|
-
const label = readTrimmed(entry["label"]);
|
|
23862
|
-
return {
|
|
23863
|
-
slug,
|
|
23864
|
-
...label ? { label } : {},
|
|
23865
|
-
...contextWindow !== void 0 ? { contextWindow } : {},
|
|
23866
|
-
...aliases && aliases.length > 0 ? { aliases } : {}
|
|
23867
|
-
};
|
|
23868
|
-
}
|
|
23869
|
-
|
|
23870
|
-
// ../../packages/ycodium-instance-config/src/launchArgs.ts
|
|
23871
|
-
function tokenizeShellWords(value) {
|
|
23872
|
-
const input = value.trim();
|
|
23873
|
-
if (!input) return [];
|
|
23874
|
-
const tokens = [];
|
|
23875
|
-
let current = "";
|
|
23876
|
-
let quote2;
|
|
23877
|
-
let quoted = false;
|
|
23878
|
-
for (let index = 0; index < input.length; index++) {
|
|
23879
|
-
const char = input[index];
|
|
23880
|
-
if (char === void 0) continue;
|
|
23881
|
-
if (quote2) {
|
|
23882
|
-
if (char === quote2) {
|
|
23883
|
-
quote2 = void 0;
|
|
23884
|
-
quoted = true;
|
|
23885
|
-
} else if (char === "\\" && quote2 === '"') {
|
|
23886
|
-
const next = input[index + 1];
|
|
23887
|
-
if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
|
|
23888
|
-
current += next;
|
|
23889
|
-
index++;
|
|
23890
|
-
} else {
|
|
23891
|
-
current += char;
|
|
23892
|
-
}
|
|
23893
|
-
} else {
|
|
23894
|
-
current += char;
|
|
23895
|
-
}
|
|
23896
|
-
continue;
|
|
23897
|
-
}
|
|
23898
|
-
if (char === "'" || char === '"') {
|
|
23899
|
-
quote2 = char;
|
|
23900
|
-
quoted = true;
|
|
23901
|
-
} else if (/\s/.test(char)) {
|
|
23902
|
-
if (current || quoted) {
|
|
23903
|
-
tokens.push(current);
|
|
23904
|
-
current = "";
|
|
23905
|
-
quoted = false;
|
|
23906
|
-
}
|
|
23907
|
-
} else if (char === "\\") {
|
|
23908
|
-
const next = input[index + 1];
|
|
23909
|
-
if (next !== void 0 && /\s/.test(next)) {
|
|
23910
|
-
current += next;
|
|
23911
|
-
index++;
|
|
23912
|
-
} else {
|
|
23913
|
-
current += char;
|
|
23914
|
-
}
|
|
23915
|
-
} else {
|
|
23916
|
-
current += char;
|
|
23917
|
-
}
|
|
23918
|
-
}
|
|
23919
|
-
if (current || quoted) tokens.push(current);
|
|
23920
|
-
return tokens;
|
|
23921
|
-
}
|
|
22111
|
+
return { nowIso, randomUUIDv4, makeEventStamp, eventHeader, offerRuntimeEvent };
|
|
22112
|
+
};
|
|
23922
22113
|
|
|
23923
22114
|
// src/config.ts
|
|
22115
|
+
import {
|
|
22116
|
+
isRecord as isRecord4,
|
|
22117
|
+
readCustomModel,
|
|
22118
|
+
readInstanceEnvelope,
|
|
22119
|
+
readString as readString3,
|
|
22120
|
+
readTrimmed,
|
|
22121
|
+
tokenizeShellWords
|
|
22122
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
23924
22123
|
var CLAUDE_AUTO_COMPACT_WINDOW_PATTERN = /^(?:|[1-9]\d{5}|1000000)$/;
|
|
23925
22124
|
function readThinkingOptions(entry) {
|
|
23926
22125
|
const thinkingRaw = entry["thinkingOptions"];
|
|
@@ -24014,9 +22213,9 @@ import {
|
|
|
24014
22213
|
} from "@ycodium-ai/plugin-api/executor";
|
|
24015
22214
|
|
|
24016
22215
|
// src/sdkModels.ts
|
|
24017
|
-
import * as
|
|
22216
|
+
import * as NodeOS4 from "node:os";
|
|
24018
22217
|
import { REASONING_OPTION_LABEL as REASONING_OPTION_LABEL2, reasoningEffortShortLabel } from "@ycodium-ai/plugin-api/executor";
|
|
24019
|
-
import {
|
|
22218
|
+
import { isOperationCleanupError as isOperationCleanupError2 } from "@ycodium-ai/plugin-api/process-operation";
|
|
24020
22219
|
|
|
24021
22220
|
// src/sdkAccount.ts
|
|
24022
22221
|
var text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
@@ -24181,12 +22380,12 @@ function makeClaudeProcessSpawner(host, stderr, config = {}) {
|
|
|
24181
22380
|
// src/sdkRead.ts
|
|
24182
22381
|
var silentPrompt = (signal) => ({
|
|
24183
22382
|
[Symbol.asyncIterator]: () => ({
|
|
24184
|
-
next: () => new Promise((
|
|
22383
|
+
next: () => new Promise((resolve5) => {
|
|
24185
22384
|
if (signal.aborted) {
|
|
24186
|
-
|
|
22385
|
+
resolve5({ done: true, value: void 0 });
|
|
24187
22386
|
return;
|
|
24188
22387
|
}
|
|
24189
|
-
signal.addEventListener("abort", () =>
|
|
22388
|
+
signal.addEventListener("abort", () => resolve5({ done: true, value: void 0 }), {
|
|
24190
22389
|
once: true
|
|
24191
22390
|
});
|
|
24192
22391
|
}),
|
|
@@ -24311,7 +22510,7 @@ var readClaudeSdkProbe = async (input) => {
|
|
|
24311
22510
|
}
|
|
24312
22511
|
);
|
|
24313
22512
|
} catch (cause) {
|
|
24314
|
-
if (cause
|
|
22513
|
+
if (isOperationCleanupError2(cause)) throw cause;
|
|
24315
22514
|
input.signal?.throwIfAborted();
|
|
24316
22515
|
return void 0;
|
|
24317
22516
|
}
|
|
@@ -24324,7 +22523,7 @@ function claudeModelProbeEnvironment(environment) {
|
|
|
24324
22523
|
CLAUDE_CODE_IDE_SKIP_AUTO_INSTALL: "1"
|
|
24325
22524
|
};
|
|
24326
22525
|
}
|
|
24327
|
-
var claudeSdkModelsCwd = () =>
|
|
22526
|
+
var claudeSdkModelsCwd = () => NodeOS4.tmpdir();
|
|
24328
22527
|
|
|
24329
22528
|
// src/spawnEnvironment.ts
|
|
24330
22529
|
function changedSpawnEnvironmentKeys(previous, next) {
|
|
@@ -24590,59 +22789,25 @@ import {
|
|
|
24590
22789
|
reasoningLevelFallbackWarning
|
|
24591
22790
|
} from "@ycodium-ai/plugin-api/executor";
|
|
24592
22791
|
|
|
24593
|
-
// ../../packages/ycodium-composer-tokens/src/skillTokens.ts
|
|
24594
|
-
var SKILL_TOKEN_NAME_PATTERN = "[a-zA-Z][a-zA-Z0-9:_-]*";
|
|
24595
|
-
var SESSION_SKILL_NAMESPACE = "ycodium";
|
|
24596
|
-
var SESSION_SKILL_PREFIX = `${SESSION_SKILL_NAMESPACE}:`;
|
|
24597
|
-
var SKILL_TOKEN_REGEX = new RegExp(
|
|
24598
|
-
String.raw`(^|\s)([$/])(${SKILL_TOKEN_NAME_PATTERN})(?=\s|$)`,
|
|
24599
|
-
"g"
|
|
24600
|
-
);
|
|
24601
|
-
function findSkillTokens(text2) {
|
|
24602
|
-
return [...text2.matchAll(SKILL_TOKEN_REGEX)].map((match) => {
|
|
24603
|
-
const start = (match.index ?? 0) + (match[1]?.length ?? 0);
|
|
24604
|
-
const name = match[3] ?? "";
|
|
24605
|
-
return { sigil: match[2], name, start, end: start + name.length + 1 };
|
|
24606
|
-
});
|
|
24607
|
-
}
|
|
24608
|
-
var SKILL_TOKEN_AT = new RegExp(String.raw`([$/])(${SKILL_TOKEN_NAME_PATTERN})(?=\s|$)`, "y");
|
|
24609
|
-
function resolveSkillName(name, known) {
|
|
24610
|
-
if (known.has(name)) return name;
|
|
24611
|
-
if (!name.startsWith(SESSION_SKILL_PREFIX)) return void 0;
|
|
24612
|
-
const bare = name.slice(SESSION_SKILL_PREFIX.length);
|
|
24613
|
-
return known.has(bare) ? bare : void 0;
|
|
24614
|
-
}
|
|
24615
|
-
function lookupSkill(name, index) {
|
|
24616
|
-
const exact = index.get(name);
|
|
24617
|
-
if (exact !== void 0) return exact;
|
|
24618
|
-
if (!name.startsWith(SESSION_SKILL_PREFIX)) return void 0;
|
|
24619
|
-
const session = index.get(name.slice(SESSION_SKILL_PREFIX.length));
|
|
24620
|
-
return session?.scope === SESSION_SKILL_NAMESPACE ? session : void 0;
|
|
24621
|
-
}
|
|
24622
|
-
var SLASH_SKILL_TOKEN = new RegExp(String.raw`^/(${SKILL_TOKEN_NAME_PATTERN})$`);
|
|
24623
|
-
function matchSkillTokens(text2, index) {
|
|
24624
|
-
if (index.size === 0) return [];
|
|
24625
|
-
return findSkillTokens(text2).flatMap((token) => {
|
|
24626
|
-
const skill = lookupSkill(token.name, index);
|
|
24627
|
-
return skill === void 0 ? [] : [{ ...token, skill }];
|
|
24628
|
-
});
|
|
24629
|
-
}
|
|
24630
|
-
function skillInvocationNotice(names) {
|
|
24631
|
-
return `The user invoked these skills in this message; run them as requested: ${names.map((name) => `$${name}`).join(", ")}.`;
|
|
24632
|
-
}
|
|
24633
|
-
|
|
24634
22792
|
// src/claudeSkillDispatch.ts
|
|
22793
|
+
import {
|
|
22794
|
+
findSkillTokens,
|
|
22795
|
+
matchSkillTokens,
|
|
22796
|
+
resolveSkillName,
|
|
22797
|
+
skillInvocationNotice
|
|
22798
|
+
} from "@ycodium-ai/plugin-api/composer";
|
|
24635
22799
|
import { EXECUTOR_SEND_TURN_MAX_INPUT_CHARS as EXECUTOR_SEND_TURN_MAX_INPUT_CHARS2 } from "@ycodium-ai/plugin-api/executor";
|
|
24636
22800
|
|
|
24637
22801
|
// src/claudeInlineSkill.ts
|
|
24638
|
-
import * as
|
|
24639
|
-
import * as
|
|
22802
|
+
import * as NodeFSP2 from "node:fs/promises";
|
|
22803
|
+
import * as NodePath7 from "node:path";
|
|
24640
22804
|
import { EXECUTOR_SEND_TURN_MAX_INPUT_CHARS } from "@ycodium-ai/plugin-api/executor";
|
|
24641
22805
|
|
|
24642
22806
|
// src/claudeSkillArguments.ts
|
|
22807
|
+
import { tokenizeShellWords as tokenizeShellWords2 } from "@ycodium-ai/plugin-api/instance-config";
|
|
24643
22808
|
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
24644
22809
|
function substituteSkillArguments(body, args, argumentNames) {
|
|
24645
|
-
const values =
|
|
22810
|
+
const values = tokenizeShellWords2(args);
|
|
24646
22811
|
const named = argumentNames.map(escapeRegExp).toSorted((left, right) => right.length - left.length);
|
|
24647
22812
|
const pattern = new RegExp(
|
|
24648
22813
|
String.raw`(\\*)\$(?:ARGUMENTS\[(\d+)\]|(ARGUMENTS)(?![A-Za-z0-9_])|(\d+)` + (named.length > 0 ? String.raw`|(${named.join("|")})(?![A-Za-z0-9_-])` : "") + ")",
|
|
@@ -24727,7 +22892,7 @@ function readSkillSource(contents) {
|
|
|
24727
22892
|
}
|
|
24728
22893
|
var loadSkill = async (path) => {
|
|
24729
22894
|
try {
|
|
24730
|
-
const bytes = await
|
|
22895
|
+
const bytes = await NodeFSP2.readFile(path);
|
|
24731
22896
|
if (bytes.byteLength > MAX_INLINE_SKILL_BYTES) {
|
|
24732
22897
|
return { ok: false, reason: `${path} is larger than ${MAX_INLINE_SKILL_BYTES / 1024} KB` };
|
|
24733
22898
|
}
|
|
@@ -24747,7 +22912,7 @@ var notLoadedBlock = (name, reason) => skillBlock(name, [
|
|
|
24747
22912
|
`The user invoked the skill "${name}" in this message, but it could not be included: ${reason}. It is not applied; don't assume its instructions.`
|
|
24748
22913
|
]);
|
|
24749
22914
|
var renderLoaded = (invocation, source, variables) => {
|
|
24750
|
-
const skillDir =
|
|
22915
|
+
const skillDir = NodePath7.dirname(invocation.path);
|
|
24751
22916
|
const known = {
|
|
24752
22917
|
CLAUDE_SKILL_DIR: skillDir,
|
|
24753
22918
|
CLAUDE_PROJECT_DIR: variables.projectDir,
|
|
@@ -24956,12 +23121,12 @@ async function applyClaudePermissionMode(context, mode, control) {
|
|
|
24956
23121
|
}
|
|
24957
23122
|
|
|
24958
23123
|
// src/adapter/sessionOptions.ts
|
|
24959
|
-
import { modelSelectionStringOption
|
|
23124
|
+
import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
|
|
24960
23125
|
function resolveClaudeSessionOptions(input) {
|
|
24961
23126
|
const { modelSelection, recipe } = input;
|
|
24962
23127
|
const caps = claudeModelCapabilities(modelSelection?.model, input.catalog, recipe.customModels);
|
|
24963
23128
|
const descriptors = caps.optionDescriptors;
|
|
24964
|
-
const rawEffort =
|
|
23129
|
+
const rawEffort = modelSelectionStringOption(modelSelection, "effort");
|
|
24965
23130
|
const effort = resolveClaudeEffort(caps, rawEffort) ?? null;
|
|
24966
23131
|
const supports = (id2) => descriptors.some((descriptor) => descriptor.type === "boolean" && descriptor.id === id2);
|
|
24967
23132
|
const fastMode = getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true && supports("fastMode");
|
|
@@ -25776,7 +23941,7 @@ var makeSessionControls = (deps) => {
|
|
|
25776
23941
|
context.query.interrupt().then(() => settled.promise).then(() => {
|
|
25777
23942
|
acknowledged = true;
|
|
25778
23943
|
}),
|
|
25779
|
-
new Promise((
|
|
23944
|
+
new Promise((resolve5) => setTimeout(resolve5, CLAUDE_INTERRUPT_GRACE_MS))
|
|
25780
23945
|
]);
|
|
25781
23946
|
} catch (cause) {
|
|
25782
23947
|
throw toRequestError(threadId, "turn/interrupt", cause);
|
|
@@ -25796,12 +23961,12 @@ var makeSessionControls = (deps) => {
|
|
|
25796
23961
|
const mapPluginDecision = (decision) => decision === "allow" ? "accept" : "decline";
|
|
25797
23962
|
const respondToRequest = async (threadId, requestId, decision, reason) => {
|
|
25798
23963
|
const context = requireSession(threadId);
|
|
25799
|
-
const
|
|
25800
|
-
if (!
|
|
23964
|
+
const pending = context.pendingApprovals.get(requestId);
|
|
23965
|
+
if (!pending) {
|
|
25801
23966
|
throw new Error(`Unknown pending approval request: ${requestId}`);
|
|
25802
23967
|
}
|
|
25803
23968
|
context.pendingApprovals.delete(requestId);
|
|
25804
|
-
|
|
23969
|
+
pending.decision.resolve({
|
|
25805
23970
|
decision: mapPluginDecision(decision),
|
|
25806
23971
|
...reason ? { reason } : {}
|
|
25807
23972
|
});
|
|
@@ -25832,9 +23997,9 @@ var makeSessionControls = (deps) => {
|
|
|
25832
23997
|
if (permissionMode !== "bypassPermissions") {
|
|
25833
23998
|
return;
|
|
25834
23999
|
}
|
|
25835
|
-
for (const [requestId,
|
|
24000
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
25836
24001
|
context.pendingApprovals.delete(requestId);
|
|
25837
|
-
|
|
24002
|
+
pending.decision.resolve({ decision: "accept" });
|
|
25838
24003
|
}
|
|
25839
24004
|
};
|
|
25840
24005
|
const setNativeMode = async (threadId, nativeModeId) => {
|
|
@@ -25860,19 +24025,19 @@ var makeSessionControls = (deps) => {
|
|
|
25860
24025
|
if (nativeModeId !== "bypassPermissions") {
|
|
25861
24026
|
return;
|
|
25862
24027
|
}
|
|
25863
|
-
for (const [requestId,
|
|
24028
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
25864
24029
|
context.pendingApprovals.delete(requestId);
|
|
25865
|
-
|
|
24030
|
+
pending.decision.resolve({ decision: "accept" });
|
|
25866
24031
|
}
|
|
25867
24032
|
};
|
|
25868
24033
|
const respondToUserInput = async (threadId, requestId, answers) => {
|
|
25869
24034
|
const context = requireSession(threadId);
|
|
25870
|
-
const
|
|
25871
|
-
if (!
|
|
24035
|
+
const pending = context.pendingUserInputs.get(requestId);
|
|
24036
|
+
if (!pending) {
|
|
25872
24037
|
throw new Error(`Unknown pending user-input request: ${requestId}`);
|
|
25873
24038
|
}
|
|
25874
24039
|
context.pendingUserInputs.delete(requestId);
|
|
25875
|
-
|
|
24040
|
+
pending.answers.resolve(answers ?? {});
|
|
25876
24041
|
};
|
|
25877
24042
|
return {
|
|
25878
24043
|
compactContext,
|
|
@@ -25908,8 +24073,8 @@ var makeSessionLifecycle = (deps) => {
|
|
|
25908
24073
|
const claim = context.turnState?.resultClaim;
|
|
25909
24074
|
if (claim === void 0) return;
|
|
25910
24075
|
let timer;
|
|
25911
|
-
const timeout = new Promise((
|
|
25912
|
-
timer = setTimeout(() =>
|
|
24076
|
+
const timeout = new Promise((resolve5) => {
|
|
24077
|
+
timer = setTimeout(() => resolve5("timeout"), RESULT_CLAIM_WAIT_MS);
|
|
25913
24078
|
});
|
|
25914
24079
|
try {
|
|
25915
24080
|
const outcome = await Promise.race([claim.then(() => "settled"), timeout]);
|
|
@@ -25975,8 +24140,8 @@ var makeSessionLifecycle = (deps) => {
|
|
|
25975
24140
|
providerRefs: nativeProviderRefs()
|
|
25976
24141
|
});
|
|
25977
24142
|
}
|
|
25978
|
-
for (const [requestId,
|
|
25979
|
-
|
|
24143
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
24144
|
+
pending.decision.resolve({ decision: "cancel", resolvedEventSent: true });
|
|
25980
24145
|
const stamp = await makeEventStamp();
|
|
25981
24146
|
offerRuntimeEvent(context, {
|
|
25982
24147
|
type: "request.resolved",
|
|
@@ -25984,15 +24149,15 @@ var makeSessionLifecycle = (deps) => {
|
|
|
25984
24149
|
...context.turnState ? { turnId: asCanonicalTurnId(context.turnState.turnId) } : {},
|
|
25985
24150
|
requestId: asRuntimeRequestId(requestId),
|
|
25986
24151
|
payload: {
|
|
25987
|
-
requestType:
|
|
24152
|
+
requestType: pending.requestType,
|
|
25988
24153
|
decision: "cancel"
|
|
25989
24154
|
},
|
|
25990
24155
|
providerRefs: nativeProviderRefs()
|
|
25991
24156
|
});
|
|
25992
24157
|
}
|
|
25993
24158
|
context.pendingApprovals.clear();
|
|
25994
|
-
for (const
|
|
25995
|
-
|
|
24159
|
+
for (const pending of Array.from(context.pendingUserInputs.values())) {
|
|
24160
|
+
pending.cancel();
|
|
25996
24161
|
}
|
|
25997
24162
|
if (context.turnState && !options?.recovering) {
|
|
25998
24163
|
await awaitClaimedResult(context);
|
|
@@ -26008,7 +24173,7 @@ var makeSessionLifecycle = (deps) => {
|
|
|
26008
24173
|
if (streamFiber) {
|
|
26009
24174
|
await Promise.race([
|
|
26010
24175
|
streamFiber.catch(() => void 0),
|
|
26011
|
-
new Promise((
|
|
24176
|
+
new Promise((resolve5) => setTimeout(resolve5, 1e3))
|
|
26012
24177
|
]);
|
|
26013
24178
|
}
|
|
26014
24179
|
const updatedAt = nowIso();
|
|
@@ -26175,18 +24340,18 @@ async function recoverFirstPrompt(input) {
|
|
|
26175
24340
|
}
|
|
26176
24341
|
|
|
26177
24342
|
// src/adapter/startSession.ts
|
|
26178
|
-
import * as
|
|
24343
|
+
import * as NodeFSP4 from "node:fs/promises";
|
|
26179
24344
|
|
|
26180
24345
|
// src/claudeMcpConfig.ts
|
|
26181
|
-
import * as
|
|
26182
|
-
import * as
|
|
26183
|
-
import * as
|
|
26184
|
-
import * as
|
|
24346
|
+
import * as NodeFSP3 from "node:fs/promises";
|
|
24347
|
+
import * as NodeOS5 from "node:os";
|
|
24348
|
+
import * as NodePath8 from "node:path";
|
|
24349
|
+
import * as NodeProcess3 from "node:process";
|
|
26185
24350
|
async function createClaudeMcpConfig(mcpServers, log) {
|
|
26186
24351
|
let directory;
|
|
26187
24352
|
let cleanupWork;
|
|
26188
24353
|
const cleanup = () => {
|
|
26189
|
-
cleanupWork ??= directory === void 0 ? Promise.resolve() :
|
|
24354
|
+
cleanupWork ??= directory === void 0 ? Promise.resolve() : NodeFSP3.rm(directory, { recursive: true, force: true }).catch(() => {
|
|
26190
24355
|
log.warn("claude.mcpConfig.cleanupFailed");
|
|
26191
24356
|
});
|
|
26192
24357
|
return cleanupWork;
|
|
@@ -26195,11 +24360,11 @@ async function createClaudeMcpConfig(mcpServers, log) {
|
|
|
26195
24360
|
return { path: void 0, cleanup };
|
|
26196
24361
|
}
|
|
26197
24362
|
try {
|
|
26198
|
-
directory = await
|
|
26199
|
-
const file =
|
|
26200
|
-
await
|
|
26201
|
-
await
|
|
26202
|
-
if (
|
|
24363
|
+
directory = await NodeFSP3.mkdtemp(NodePath8.join(NodeOS5.tmpdir(), "ycodium-claude-mcp-"));
|
|
24364
|
+
const file = NodePath8.join(directory, "mcp.json");
|
|
24365
|
+
await NodeFSP3.writeFile(file, JSON.stringify({ mcpServers }), { mode: 384 });
|
|
24366
|
+
await NodeFSP3.chmod(file, 384).catch((cause) => {
|
|
24367
|
+
if (NodeProcess3.platform !== "win32") throw cause;
|
|
26203
24368
|
});
|
|
26204
24369
|
return { path: file, cleanup };
|
|
26205
24370
|
} catch (cause) {
|
|
@@ -26259,8 +24424,8 @@ function toClaudeMcpServers(entries) {
|
|
|
26259
24424
|
}
|
|
26260
24425
|
var unreadableTranscript = async (transcriptPath) => {
|
|
26261
24426
|
try {
|
|
26262
|
-
if (!(await
|
|
26263
|
-
await
|
|
24427
|
+
if (!(await NodeFSP4.stat(transcriptPath)).isFile()) return "transcript-unreadable";
|
|
24428
|
+
await NodeFSP4.access(transcriptPath, NodeFSP4.constants.R_OK);
|
|
26264
24429
|
return void 0;
|
|
26265
24430
|
} catch (cause) {
|
|
26266
24431
|
const code = cause.code;
|
|
@@ -26437,8 +24602,8 @@ var makeStartSession = (deps) => {
|
|
|
26437
24602
|
try {
|
|
26438
24603
|
return await Promise.race([
|
|
26439
24604
|
contextDeferred.promise,
|
|
26440
|
-
new Promise((
|
|
26441
|
-
timer = setTimeout(() =>
|
|
24605
|
+
new Promise((resolve5) => {
|
|
24606
|
+
timer = setTimeout(() => resolve5(void 0), CLAUDE_SESSION_CONTEXT_WAIT_MS);
|
|
26442
24607
|
})
|
|
26443
24608
|
]);
|
|
26444
24609
|
} catch {
|
|
@@ -27016,8 +25181,8 @@ var makeStreamEventHandler = (deps) => {
|
|
|
27016
25181
|
};
|
|
27017
25182
|
|
|
27018
25183
|
// src/claudeWorkspaceInventory.ts
|
|
27019
|
-
import * as
|
|
27020
|
-
import * as
|
|
25184
|
+
import * as NodeFSP5 from "node:fs/promises";
|
|
25185
|
+
import * as NodePath9 from "node:path";
|
|
27021
25186
|
var MAX_COMMAND_DEPTH = 5;
|
|
27022
25187
|
var MAX_COMMAND_FILES = 500;
|
|
27023
25188
|
var MAX_DESCRIPTION_LENGTH = 200;
|
|
@@ -27035,7 +25200,7 @@ var firstBodyLine = (contents) => {
|
|
|
27035
25200
|
return void 0;
|
|
27036
25201
|
};
|
|
27037
25202
|
var scanCommands = async (claudeDir) => {
|
|
27038
|
-
const root =
|
|
25203
|
+
const root = NodePath9.join(claudeDir, "commands");
|
|
27039
25204
|
const commands = /* @__PURE__ */ new Map();
|
|
27040
25205
|
const watched = [root];
|
|
27041
25206
|
let level = [root];
|
|
@@ -27043,9 +25208,9 @@ var scanCommands = async (claudeDir) => {
|
|
|
27043
25208
|
for (let depth = 0; depth < MAX_COMMAND_DEPTH && level.length > 0; depth += 1) {
|
|
27044
25209
|
const next = [];
|
|
27045
25210
|
for (const directory of level) {
|
|
27046
|
-
const entries = await
|
|
25211
|
+
const entries = await NodeFSP5.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
27047
25212
|
for (const entry of entries.toSorted((left, right) => left.name.localeCompare(right.name))) {
|
|
27048
|
-
const entryPath =
|
|
25213
|
+
const entryPath = NodePath9.join(directory, entry.name);
|
|
27049
25214
|
if (entry.isDirectory()) {
|
|
27050
25215
|
next.push(entryPath);
|
|
27051
25216
|
watched.push(entryPath);
|
|
@@ -27057,7 +25222,7 @@ var scanCommands = async (claudeDir) => {
|
|
|
27057
25222
|
files += 1;
|
|
27058
25223
|
const name = entry.name.slice(0, -".md".length).trim();
|
|
27059
25224
|
if (name.length === 0 || commands.has(name)) continue;
|
|
27060
|
-
const contents = await
|
|
25225
|
+
const contents = await NodeFSP5.readFile(entryPath, "utf8").catch(() => void 0);
|
|
27061
25226
|
if (contents === void 0) continue;
|
|
27062
25227
|
const frontMatter = parseSkillFrontMatter(contents);
|
|
27063
25228
|
const description = frontMatter.description ?? firstBodyLine(contents);
|
|
@@ -27073,13 +25238,13 @@ var scanCommands = async (claudeDir) => {
|
|
|
27073
25238
|
return { commands: [...commands.values()], watched };
|
|
27074
25239
|
};
|
|
27075
25240
|
var watchSkillsRoot = async (claudeDir) => {
|
|
27076
|
-
const root =
|
|
27077
|
-
const entries = await
|
|
25241
|
+
const root = NodePath9.join(claudeDir, "skills");
|
|
25242
|
+
const entries = await NodeFSP5.readdir(root).catch(() => []);
|
|
27078
25243
|
return [
|
|
27079
25244
|
root,
|
|
27080
25245
|
...entries.flatMap((entry) => [
|
|
27081
|
-
|
|
27082
|
-
|
|
25246
|
+
NodePath9.join(root, entry),
|
|
25247
|
+
NodePath9.join(root, entry, "SKILL.md")
|
|
27083
25248
|
])
|
|
27084
25249
|
];
|
|
27085
25250
|
};
|
|
@@ -27090,7 +25255,7 @@ var mergeByName = (base, preferred) => {
|
|
|
27090
25255
|
return [...merged.values()].toSorted((left, right) => left.name.localeCompare(right.name));
|
|
27091
25256
|
};
|
|
27092
25257
|
var discoverClaudeWorkspaceInventory = async (input) => {
|
|
27093
|
-
const projectClaudeDir =
|
|
25258
|
+
const projectClaudeDir = NodePath9.join(input.cwd, ".claude");
|
|
27094
25259
|
const [userCommands, projectCommands, skills, userSkillWatch, projectSkillWatch] = await Promise.all([
|
|
27095
25260
|
scanCommands(input.configDirPath),
|
|
27096
25261
|
scanCommands(projectClaudeDir),
|
|
@@ -27112,9 +25277,9 @@ var discoverClaudeWorkspaceInventory = async (input) => {
|
|
|
27112
25277
|
...userSkillWatch,
|
|
27113
25278
|
...projectSkillWatch,
|
|
27114
25279
|
// `skillOverrides` 在这几个设置文件里:开关一个技能也要重查。
|
|
27115
|
-
|
|
27116
|
-
|
|
27117
|
-
|
|
25280
|
+
NodePath9.join(input.configDirPath, "settings.json"),
|
|
25281
|
+
NodePath9.join(projectClaudeDir, "settings.json"),
|
|
25282
|
+
NodePath9.join(projectClaudeDir, "settings.local.json")
|
|
27118
25283
|
]
|
|
27119
25284
|
};
|
|
27120
25285
|
};
|
|
@@ -27913,7 +26078,7 @@ var makeTurnLifecycle = (deps) => {
|
|
|
27913
26078
|
};
|
|
27914
26079
|
|
|
27915
26080
|
// src/adapter/turnMessages.ts
|
|
27916
|
-
import * as
|
|
26081
|
+
import * as NodePath10 from "node:path";
|
|
27917
26082
|
var makeTurnMessageHandlers = (deps) => {
|
|
27918
26083
|
const {
|
|
27919
26084
|
emitter,
|
|
@@ -28135,7 +26300,7 @@ var makeTurnMessageHandlers = (deps) => {
|
|
|
28135
26300
|
claudeFailureHint({
|
|
28136
26301
|
authenticationFailed: context.turnState?.authenticationFailed === true,
|
|
28137
26302
|
environment: buildLaunchEnvironment(),
|
|
28138
|
-
cwd:
|
|
26303
|
+
cwd: NodePath10.resolve(context.session.cwd ?? "."),
|
|
28139
26304
|
...context.turnState === void 0 ? {} : {
|
|
28140
26305
|
usageLimit: {
|
|
28141
26306
|
rejected: context.turnState.rejectedRateLimits,
|
|
@@ -28193,85 +26358,36 @@ function claudeSignInCommand(credentialsPath, platform4) {
|
|
|
28193
26358
|
}
|
|
28194
26359
|
|
|
28195
26360
|
// src/sessions.ts
|
|
28196
|
-
import * as
|
|
28197
|
-
import * as
|
|
28198
|
-
import * as
|
|
28199
|
-
|
|
28200
|
-
|
|
28201
|
-
|
|
28202
|
-
|
|
28203
|
-
|
|
28204
|
-
|
|
28205
|
-
|
|
28206
|
-
|
|
28207
|
-
|
|
28208
|
-
|
|
28209
|
-
|
|
28210
|
-
|
|
28211
|
-
|
|
28212
|
-
|
|
28213
|
-
}
|
|
28214
|
-
function readableContent(value, textTypes) {
|
|
28215
|
-
if (typeof value === "string") return value;
|
|
28216
|
-
if (!Array.isArray(value)) return "";
|
|
28217
|
-
return value.flatMap((entry) => {
|
|
28218
|
-
if (typeof entry === "string") return [entry];
|
|
28219
|
-
const block = record2(entry);
|
|
28220
|
-
return block && textTypes.includes(String(block.type)) && typeof block.text === "string" ? [block.text] : [];
|
|
28221
|
-
}).join("\n\n");
|
|
28222
|
-
}
|
|
28223
|
-
function toolInput(value) {
|
|
28224
|
-
if (typeof value === "string") return value;
|
|
28225
|
-
const input = record2(value);
|
|
28226
|
-
if (input && Object.keys(input).length === 1 && typeof input.command === "string")
|
|
28227
|
-
return input.command;
|
|
28228
|
-
if (input && Object.keys(input).length === 1 && typeof input.cmd === "string") return input.cmd;
|
|
28229
|
-
if (value === void 0 || value === null) return void 0;
|
|
28230
|
-
try {
|
|
28231
|
-
return JSON.stringify(value, null, 2);
|
|
28232
|
-
} catch {
|
|
28233
|
-
return void 0;
|
|
28234
|
-
}
|
|
28235
|
-
}
|
|
28236
|
-
function bounded(value, tail = false) {
|
|
28237
|
-
if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
|
|
28238
|
-
const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
|
|
28239
|
-
const character = value.charCodeAt(offset);
|
|
28240
|
-
const previous = value.charCodeAt(offset - 1);
|
|
28241
|
-
const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
|
|
28242
|
-
return {
|
|
28243
|
-
text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
|
|
28244
|
-
truncated: true
|
|
28245
|
-
};
|
|
28246
|
-
}
|
|
28247
|
-
function inputPayload(input) {
|
|
28248
|
-
if (input === void 0) return {};
|
|
28249
|
-
const result = bounded(input);
|
|
28250
|
-
return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
|
|
28251
|
-
}
|
|
28252
|
-
function outputPayload(output) {
|
|
28253
|
-
if (output === void 0) return {};
|
|
28254
|
-
const result = bounded(output, true);
|
|
28255
|
-
return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
|
|
28256
|
-
}
|
|
28257
|
-
function reasoning(identity, text2, streamKind) {
|
|
28258
|
-
const result = bounded(text2);
|
|
28259
|
-
return {
|
|
28260
|
-
...identity,
|
|
28261
|
-
kind: "reasoning",
|
|
28262
|
-
tone: "info",
|
|
28263
|
-
summary: "Reasoning",
|
|
28264
|
-
payload: {
|
|
28265
|
-
text: result.text,
|
|
28266
|
-
streamKind,
|
|
28267
|
-
chars: result.text.length,
|
|
28268
|
-
streaming: false,
|
|
28269
|
-
...result.truncated ? { truncated: true } : {}
|
|
28270
|
-
}
|
|
28271
|
-
};
|
|
28272
|
-
}
|
|
26361
|
+
import * as NodeFS3 from "node:fs";
|
|
26362
|
+
import * as NodeOS6 from "node:os";
|
|
26363
|
+
import * as NodePath11 from "node:path";
|
|
26364
|
+
import {
|
|
26365
|
+
jsonlEntryRecord,
|
|
26366
|
+
readJsonlEntries
|
|
26367
|
+
} from "@ycodium-ai/plugin-api/jsonl";
|
|
26368
|
+
import {
|
|
26369
|
+
CLAUDE_MAX_PARSED_LINE_BYTES,
|
|
26370
|
+
CLAUDE_MAX_ROWS,
|
|
26371
|
+
CLAUDE_MAX_SCANNED_FILES,
|
|
26372
|
+
CLAUDE_TRANSCRIPT_SUFFIX,
|
|
26373
|
+
encodeClaudeProjectDirName as encodeClaudeProjectDirName2,
|
|
26374
|
+
listClaudeTranscriptFiles,
|
|
26375
|
+
readClaudeLiveSessionIds,
|
|
26376
|
+
readClaudeTranscriptDigest
|
|
26377
|
+
} from "@ycodium-ai/plugin-api/session-history";
|
|
26378
|
+
import { isWithinDirectory as isWithinDirectory2 } from "@ycodium-ai/plugin-api/workspace-path";
|
|
28273
26379
|
|
|
28274
26380
|
// src/sessionTranscript.ts
|
|
26381
|
+
import {
|
|
26382
|
+
fallbackId,
|
|
26383
|
+
inputPayload,
|
|
26384
|
+
nonempty,
|
|
26385
|
+
outputPayload,
|
|
26386
|
+
readableContent,
|
|
26387
|
+
reasoning,
|
|
26388
|
+
record as record2,
|
|
26389
|
+
toolInput
|
|
26390
|
+
} from "@ycodium-ai/plugin-api/session-history";
|
|
28275
26391
|
var nativeText = (value) => readableContent(value, ["text", "input_text", "output_text", "summary_text", "reasoning_text"]);
|
|
28276
26392
|
function nativeModel(value) {
|
|
28277
26393
|
const model = nonempty(value);
|
|
@@ -28481,7 +26597,7 @@ var TRANSCRIPT_FIELDS = [
|
|
|
28481
26597
|
}
|
|
28482
26598
|
];
|
|
28483
26599
|
var fileSource = {
|
|
28484
|
-
createReadStream: (path) =>
|
|
26600
|
+
createReadStream: (path) => NodeFS3.createReadStream(path)
|
|
28485
26601
|
};
|
|
28486
26602
|
var RECORD_FIELDS = [
|
|
28487
26603
|
{ path: ["type"] },
|
|
@@ -28497,21 +26613,21 @@ var RECORD_FIELDS = [
|
|
|
28497
26613
|
{ path: ["message", "content", "*", "text"] }
|
|
28498
26614
|
];
|
|
28499
26615
|
var sessionFileSystem = {
|
|
28500
|
-
readDir: async (path) => (await
|
|
26616
|
+
readDir: async (path) => (await NodeFS3.promises.readdir(path, { withFileTypes: true })).map((entry) => ({
|
|
28501
26617
|
name: entry.name,
|
|
28502
26618
|
type: entry.isDirectory() ? "directory" : entry.isFile() ? "file" : "other"
|
|
28503
26619
|
})),
|
|
28504
26620
|
stat: async (path) => {
|
|
28505
|
-
const
|
|
28506
|
-
return { size:
|
|
26621
|
+
const stat3 = await NodeFS3.promises.stat(path);
|
|
26622
|
+
return { size: stat3.size, mtimeMs: stat3.mtimeMs };
|
|
28507
26623
|
},
|
|
28508
|
-
readFile: (path) =>
|
|
26624
|
+
readFile: (path) => NodeFS3.promises.readFile(path, "utf8")
|
|
28509
26625
|
};
|
|
28510
26626
|
async function scanClaudeSessions(input, cache) {
|
|
28511
26627
|
input.signal?.throwIfAborted();
|
|
28512
26628
|
let root;
|
|
28513
26629
|
try {
|
|
28514
|
-
root =
|
|
26630
|
+
root = NodeFS3.statSync(input.transcriptDir);
|
|
28515
26631
|
} catch (error) {
|
|
28516
26632
|
throw new Error(`The Claude transcript directory ${input.transcriptDir} is not a directory.`, {
|
|
28517
26633
|
cause: error
|
|
@@ -28524,9 +26640,9 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28524
26640
|
...await listClaudeTranscriptFiles(sessionFileSystem, input.transcriptDir, input.directory)
|
|
28525
26641
|
].sort((left, right) => right.mtimeMs - left.mtimeMs).slice(0, CLAUDE_MAX_SCANNED_FILES);
|
|
28526
26642
|
const live = await readClaudeLiveSessionIds(sessionFileSystem, input.configDir);
|
|
28527
|
-
const caseInsensitive = input.caseInsensitive ??
|
|
26643
|
+
const caseInsensitive = input.caseInsensitive ?? NodeOS6.type() === "Windows_NT";
|
|
28528
26644
|
const signal = input.signal;
|
|
28529
|
-
const source = signal ? { createReadStream: (path) =>
|
|
26645
|
+
const source = signal ? { createReadStream: (path) => NodeFS3.createReadStream(path, { signal }) } : fileSource;
|
|
28530
26646
|
const rows = [];
|
|
28531
26647
|
for (const file of files) {
|
|
28532
26648
|
signal?.throwIfAborted();
|
|
@@ -28542,7 +26658,7 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28542
26658
|
cache.set(key, digest);
|
|
28543
26659
|
}
|
|
28544
26660
|
if (digest === null || digest.cwd === null) continue;
|
|
28545
|
-
if (!
|
|
26661
|
+
if (!isWithinDirectory2(digest.cwd, input.directory, caseInsensitive)) continue;
|
|
28546
26662
|
rows.push({
|
|
28547
26663
|
nativeSessionId: file.sessionId,
|
|
28548
26664
|
cwd: digest.cwd,
|
|
@@ -28561,26 +26677,26 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28561
26677
|
function resolveTranscriptPath(input) {
|
|
28562
26678
|
const fileName = `${input.sessionId}${CLAUDE_TRANSCRIPT_SUFFIX}`;
|
|
28563
26679
|
if (input.cwd !== void 0 && input.cwd.length > 0) {
|
|
28564
|
-
const direct =
|
|
26680
|
+
const direct = NodePath11.join(
|
|
28565
26681
|
input.transcriptDir,
|
|
28566
|
-
|
|
26682
|
+
encodeClaudeProjectDirName2(input.cwd),
|
|
28567
26683
|
fileName
|
|
28568
26684
|
);
|
|
28569
26685
|
try {
|
|
28570
|
-
if (
|
|
26686
|
+
if (NodeFS3.statSync(direct).isFile()) return direct;
|
|
28571
26687
|
} catch {
|
|
28572
26688
|
}
|
|
28573
26689
|
}
|
|
28574
26690
|
let dirs;
|
|
28575
26691
|
try {
|
|
28576
|
-
dirs =
|
|
26692
|
+
dirs = NodeFS3.readdirSync(input.transcriptDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
28577
26693
|
} catch {
|
|
28578
26694
|
return null;
|
|
28579
26695
|
}
|
|
28580
26696
|
for (const dir of dirs) {
|
|
28581
|
-
const candidate =
|
|
26697
|
+
const candidate = NodePath11.join(input.transcriptDir, dir, fileName);
|
|
28582
26698
|
try {
|
|
28583
|
-
if (
|
|
26699
|
+
if (NodeFS3.statSync(candidate).isFile()) return candidate;
|
|
28584
26700
|
} catch {
|
|
28585
26701
|
continue;
|
|
28586
26702
|
}
|
|
@@ -28655,16 +26771,16 @@ async function readClaudeSessionRecord(input) {
|
|
|
28655
26771
|
async function findBoundClaudeTranscript(root, sessionId, signal) {
|
|
28656
26772
|
let found = null;
|
|
28657
26773
|
const fileName = `${sessionId}${CLAUDE_TRANSCRIPT_SUFFIX}`;
|
|
28658
|
-
const directories = await
|
|
26774
|
+
const directories = await NodeFS3.promises.readdir(root, { withFileTypes: true });
|
|
28659
26775
|
for (const directory of directories) {
|
|
28660
26776
|
signal?.throwIfAborted();
|
|
28661
26777
|
if (!directory.isDirectory()) continue;
|
|
28662
|
-
const path =
|
|
28663
|
-
const
|
|
26778
|
+
const path = NodePath11.join(root, directory.name, fileName);
|
|
26779
|
+
const stat3 = await NodeFS3.promises.lstat(path).catch((error) => {
|
|
28664
26780
|
if (error.code === "ENOENT" || error.code === "ENOTDIR") return void 0;
|
|
28665
26781
|
throw error;
|
|
28666
26782
|
});
|
|
28667
|
-
if (!
|
|
26783
|
+
if (!stat3?.isFile()) continue;
|
|
28668
26784
|
if (found !== null) throw new Error(`Multiple transcripts for Claude session ${sessionId}.`);
|
|
28669
26785
|
found = path;
|
|
28670
26786
|
}
|
|
@@ -28675,7 +26791,7 @@ function createClaudeImportReader() {
|
|
|
28675
26791
|
return async (input) => {
|
|
28676
26792
|
input.signal?.throwIfAborted();
|
|
28677
26793
|
const { cwd } = input;
|
|
28678
|
-
if (!/^[\w-]+$/.test(input.nativeSessionId) || cwd !== void 0 && !
|
|
26794
|
+
if (!/^[\w-]+$/.test(input.nativeSessionId) || cwd !== void 0 && !NodePath11.isAbsolute(cwd)) {
|
|
28679
26795
|
throw new Error("Invalid Claude session identity or working directory.");
|
|
28680
26796
|
}
|
|
28681
26797
|
const path = cwd === void 0 ? await findBoundClaudeTranscript(input.transcriptDir, input.nativeSessionId, input.signal) : resolveTranscriptPath({
|
|
@@ -28686,20 +26802,20 @@ function createClaudeImportReader() {
|
|
|
28686
26802
|
if (path === null)
|
|
28687
26803
|
throw new Error(`No transcript file for Claude session ${input.nativeSessionId}.`);
|
|
28688
26804
|
const version = async () => {
|
|
28689
|
-
const
|
|
28690
|
-
return [
|
|
26805
|
+
const stat3 = await NodeFS3.promises.stat(path, { bigint: true });
|
|
26806
|
+
return [stat3.dev, stat3.ino, stat3.size, stat3.mtimeNs, stat3.ctimeNs].join(":");
|
|
28691
26807
|
};
|
|
28692
26808
|
const before = await version();
|
|
28693
26809
|
const key = JSON.stringify([path, input.cwd, before]);
|
|
28694
26810
|
input.signal?.throwIfAborted();
|
|
28695
26811
|
if (cached?.key === key) return cached.result;
|
|
28696
26812
|
const source = {
|
|
28697
|
-
createReadStream: (path2) =>
|
|
26813
|
+
createReadStream: (path2) => NodeFS3.createReadStream(path2, input.signal ? { signal: input.signal } : {})
|
|
28698
26814
|
};
|
|
28699
26815
|
const digest = await readClaudeTranscriptDigest(source, path);
|
|
28700
26816
|
input.signal?.throwIfAborted();
|
|
28701
|
-
const caseInsensitive =
|
|
28702
|
-
if (digest === null || cwd !== void 0 && (!digest.cwd || !
|
|
26817
|
+
const caseInsensitive = NodeOS6.type() === "Windows_NT";
|
|
26818
|
+
if (digest === null || cwd !== void 0 && (!digest.cwd || !NodePath11.isAbsolute(digest.cwd) || !isWithinDirectory2(digest.cwd, cwd, caseInsensitive) || !isWithinDirectory2(cwd, digest.cwd, caseInsensitive))) {
|
|
28703
26819
|
throw new Error("The native Claude session does not match the requested directory.");
|
|
28704
26820
|
}
|
|
28705
26821
|
const records = [];
|
|
@@ -28730,542 +26846,21 @@ function createClaudeImportReader() {
|
|
|
28730
26846
|
}
|
|
28731
26847
|
|
|
28732
26848
|
// src/textGeneration.ts
|
|
28733
|
-
import * as
|
|
28734
|
-
import * as
|
|
28735
|
-
import * as
|
|
28736
|
-
import {
|
|
26849
|
+
import * as NodeFSP6 from "node:fs/promises";
|
|
26850
|
+
import * as NodeOS7 from "node:os";
|
|
26851
|
+
import * as NodePath12 from "node:path";
|
|
26852
|
+
import {
|
|
26853
|
+
mergeLaunchEnv as mergeLaunchEnv2,
|
|
26854
|
+
modelSelectionStringOption as modelSelectionStringOption2
|
|
26855
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
28737
26856
|
import {
|
|
28738
|
-
|
|
26857
|
+
isOperationCleanupError as isOperationCleanupError3,
|
|
28739
26858
|
runProcessOperation as runProcessOperation2
|
|
28740
26859
|
} from "@ycodium-ai/plugin-api/process-operation";
|
|
28741
|
-
|
|
28742
|
-
|
|
28743
|
-
import { isOperationCleanupError as isOperationCleanupError2 } from "@ycodium-ai/plugin-api/process-operation";
|
|
28744
|
-
|
|
28745
|
-
// ../../packages/ycodium-text-generation/src/sanitize.ts
|
|
28746
|
-
function limitSection(value, maxChars) {
|
|
28747
|
-
if (value.length <= maxChars) return value;
|
|
28748
|
-
const truncated = value.slice(0, maxChars);
|
|
28749
|
-
return `${truncated}
|
|
28750
|
-
|
|
28751
|
-
[truncated]`;
|
|
28752
|
-
}
|
|
28753
|
-
function sanitizeCommitSubject(raw) {
|
|
28754
|
-
const singleLine = raw.trim().split(/\r?\n/g)[0]?.trim() ?? "";
|
|
28755
|
-
const withoutTrailingPeriod = singleLine.replace(/[.]+$/g, "").trim();
|
|
28756
|
-
if (withoutTrailingPeriod.length === 0) {
|
|
28757
|
-
return "Update project files";
|
|
28758
|
-
}
|
|
28759
|
-
if (withoutTrailingPeriod.length <= 72) {
|
|
28760
|
-
return withoutTrailingPeriod;
|
|
28761
|
-
}
|
|
28762
|
-
return withoutTrailingPeriod.slice(0, 72).trimEnd();
|
|
28763
|
-
}
|
|
28764
|
-
function sanitizePrTitle(raw) {
|
|
28765
|
-
const singleLine = raw.trim().split(/\r?\n/g)[0]?.trim() ?? "";
|
|
28766
|
-
if (singleLine.length > 0) {
|
|
28767
|
-
return singleLine;
|
|
28768
|
-
}
|
|
28769
|
-
return "Update project changes";
|
|
28770
|
-
}
|
|
28771
|
-
function unwrapNestedTitleObject(raw) {
|
|
28772
|
-
const trimmed = raw.trim();
|
|
28773
|
-
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
|
|
28774
|
-
return raw;
|
|
28775
|
-
}
|
|
28776
|
-
try {
|
|
28777
|
-
const parsed = JSON.parse(trimmed);
|
|
28778
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
28779
|
-
const nested = parsed.title;
|
|
28780
|
-
if (typeof nested === "string") {
|
|
28781
|
-
return nested;
|
|
28782
|
-
}
|
|
28783
|
-
}
|
|
28784
|
-
} catch {
|
|
28785
|
-
}
|
|
28786
|
-
return raw;
|
|
28787
|
-
}
|
|
28788
|
-
var MAX_THREAD_TITLE_CHARS = 120;
|
|
28789
|
-
function limitTitleMessage(text2, budget) {
|
|
28790
|
-
const marker = "\n[Content truncated]\n";
|
|
28791
|
-
if (text2.length <= budget) return text2;
|
|
28792
|
-
if (budget <= marker.length) return "";
|
|
28793
|
-
const available = budget - marker.length;
|
|
28794
|
-
const head = Math.ceil(available / 2);
|
|
28795
|
-
const tail = available - head;
|
|
28796
|
-
return `${text2.slice(0, head)}${marker}${tail > 0 ? text2.slice(-tail) : ""}`;
|
|
28797
|
-
}
|
|
28798
|
-
function sanitizeThreadTitle(raw) {
|
|
28799
|
-
const normalized = unwrapNestedTitleObject(raw).trim().split(/\r?\n/g)[0]?.trim().replace(/^['"`]+|['"`]+$/g, "").trim().replace(/\s+/g, " ");
|
|
28800
|
-
if (!normalized || normalized.trim().length === 0) {
|
|
28801
|
-
return "New thread";
|
|
28802
|
-
}
|
|
28803
|
-
if (normalized.length <= MAX_THREAD_TITLE_CHARS) {
|
|
28804
|
-
return normalized;
|
|
28805
|
-
}
|
|
28806
|
-
return `${normalized.slice(0, MAX_THREAD_TITLE_CHARS - 3).trimEnd()}...`;
|
|
28807
|
-
}
|
|
28808
|
-
function normalizeCliError(cliName, error, fallback) {
|
|
28809
|
-
if (error instanceof Error) {
|
|
28810
|
-
const lower = error.message.toLowerCase();
|
|
28811
|
-
if (error.message.includes(`Command not found: ${cliName}`) || lower.includes(`spawn ${cliName}`) || lower.includes("enoent")) {
|
|
28812
|
-
return new Error(`${cliName} CLI (\`${cliName}\`) is required but not available on PATH.`);
|
|
28813
|
-
}
|
|
28814
|
-
return new Error(fallback, { cause: error });
|
|
28815
|
-
}
|
|
28816
|
-
return new Error(fallback);
|
|
28817
|
-
}
|
|
28818
|
-
|
|
28819
|
-
// ../../packages/ycodium-text-generation/src/prompts.ts
|
|
28820
|
-
var EARLIER_CONTENT_TRUNCATION_MARKER = "[Earlier content truncated]\n\n";
|
|
28821
|
-
function policyInstruction(instruction) {
|
|
28822
|
-
const trimmed = instruction?.trim();
|
|
28823
|
-
return trimmed ? ["", "Additional instructions:", limitSection(trimmed, 4e3)] : [];
|
|
28824
|
-
}
|
|
28825
|
-
var COMMIT_MESSAGE_SCHEMA = {
|
|
28826
|
-
type: "object",
|
|
28827
|
-
properties: {
|
|
28828
|
-
subject: { type: "string" },
|
|
28829
|
-
body: { type: "string" }
|
|
28830
|
-
},
|
|
28831
|
-
required: ["subject", "body"],
|
|
28832
|
-
additionalProperties: false
|
|
28833
|
-
};
|
|
28834
|
-
var COMMIT_MESSAGE_WITH_BRANCH_SCHEMA = {
|
|
28835
|
-
type: "object",
|
|
28836
|
-
properties: {
|
|
28837
|
-
subject: { type: "string" },
|
|
28838
|
-
body: { type: "string" },
|
|
28839
|
-
branch: { type: "string" }
|
|
28840
|
-
},
|
|
28841
|
-
required: ["subject", "body", "branch"],
|
|
28842
|
-
additionalProperties: false
|
|
28843
|
-
};
|
|
28844
|
-
var PR_CONTENT_SCHEMA = {
|
|
28845
|
-
type: "object",
|
|
28846
|
-
properties: {
|
|
28847
|
-
title: { type: "string" },
|
|
28848
|
-
body: { type: "string" }
|
|
28849
|
-
},
|
|
28850
|
-
required: ["title", "body"],
|
|
28851
|
-
additionalProperties: false
|
|
28852
|
-
};
|
|
28853
|
-
var BRANCH_NAME_SCHEMA = {
|
|
28854
|
-
type: "object",
|
|
28855
|
-
properties: { branch: { type: "string" } },
|
|
28856
|
-
required: ["branch"],
|
|
28857
|
-
additionalProperties: false
|
|
28858
|
-
};
|
|
28859
|
-
var THREAD_TITLE_SCHEMA = {
|
|
28860
|
-
type: "object",
|
|
28861
|
-
properties: { title: { type: "string" }, needsRefinement: { type: "boolean" } },
|
|
28862
|
-
required: ["title", "needsRefinement"],
|
|
28863
|
-
additionalProperties: false
|
|
28864
|
-
};
|
|
28865
|
-
var HANDOVER_SUMMARY_SCHEMA = {
|
|
28866
|
-
type: "object",
|
|
28867
|
-
properties: { summary: { type: "string" } },
|
|
28868
|
-
required: ["summary"],
|
|
28869
|
-
additionalProperties: false
|
|
28870
|
-
};
|
|
28871
|
-
function buildCommitMessagePrompt(input) {
|
|
28872
|
-
const wantsBranch = input.includeBranch === true;
|
|
28873
|
-
const prompt = [
|
|
28874
|
-
"You write concise git commit messages.",
|
|
28875
|
-
wantsBranch ? "Return a JSON object with keys: subject, body, branch." : "Return a JSON object with keys: subject, body.",
|
|
28876
|
-
"Rules:",
|
|
28877
|
-
"- subject must be imperative, <= 72 chars, and no trailing period",
|
|
28878
|
-
"- body can be empty string or short bullet points",
|
|
28879
|
-
...wantsBranch ? ["- branch must be a short semantic git branch fragment for this change"] : [],
|
|
28880
|
-
"- capture the primary user-visible or developer-visible change",
|
|
28881
|
-
...policyInstruction(input.policy?.commitInstructions),
|
|
28882
|
-
"",
|
|
28883
|
-
`Branch: ${input.branch ?? "(detached)"}`,
|
|
28884
|
-
"",
|
|
28885
|
-
"Staged files:",
|
|
28886
|
-
limitSection(input.stagedSummary, 6e3),
|
|
28887
|
-
"",
|
|
28888
|
-
"Staged patch:",
|
|
28889
|
-
limitSection(input.stagedPatch, 4e4)
|
|
28890
|
-
].join("\n");
|
|
28891
|
-
return {
|
|
28892
|
-
prompt,
|
|
28893
|
-
outputSchema: wantsBranch ? COMMIT_MESSAGE_WITH_BRANCH_SCHEMA : COMMIT_MESSAGE_SCHEMA
|
|
28894
|
-
};
|
|
28895
|
-
}
|
|
28896
|
-
function buildPrContentPrompt(input) {
|
|
28897
|
-
const changeRequestTemplate = input.changeRequestTemplate?.trim();
|
|
28898
|
-
const bodyRules = changeRequestTemplate ? [
|
|
28899
|
-
"- body must be markdown and follow the repository change request template structure",
|
|
28900
|
-
"- fill in the template sections appropriately for this change",
|
|
28901
|
-
"- drop HTML comments from the template in the generated body",
|
|
28902
|
-
"- keep the template's markdown structure"
|
|
28903
|
-
] : [
|
|
28904
|
-
"- body must be markdown and include headings '## Summary' and '## Testing'",
|
|
28905
|
-
"- under Summary, provide short bullet points",
|
|
28906
|
-
"- under Testing, include bullet points with concrete checks or 'Not run' where appropriate"
|
|
28907
|
-
];
|
|
28908
|
-
const prompt = [
|
|
28909
|
-
"You write source control change request content.",
|
|
28910
|
-
"Return a JSON object with keys: title, body.",
|
|
28911
|
-
"Rules:",
|
|
28912
|
-
"- title should be concise and specific",
|
|
28913
|
-
...bodyRules,
|
|
28914
|
-
...policyInstruction(input.policy?.changeRequestInstructions),
|
|
28915
|
-
...changeRequestTemplate ? ["", "Repository change request template:", limitSection(changeRequestTemplate, 8e3)] : [],
|
|
28916
|
-
"",
|
|
28917
|
-
`Base branch: ${input.baseBranch}`,
|
|
28918
|
-
`Head branch: ${input.headBranch}`,
|
|
28919
|
-
"",
|
|
28920
|
-
"Commits:",
|
|
28921
|
-
limitSection(input.commitSummary, 12e3),
|
|
28922
|
-
"",
|
|
28923
|
-
"Diff stat:",
|
|
28924
|
-
limitSection(input.diffSummary, 12e3),
|
|
28925
|
-
"",
|
|
28926
|
-
"Diff patch:",
|
|
28927
|
-
limitSection(input.diffPatch, 4e4)
|
|
28928
|
-
].join("\n");
|
|
28929
|
-
return { prompt, outputSchema: PR_CONTENT_SCHEMA };
|
|
28930
|
-
}
|
|
28931
|
-
function buildPromptFromMessage(input) {
|
|
28932
|
-
const attachmentLines = (input.attachments ?? []).map(
|
|
28933
|
-
(attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`
|
|
28934
|
-
);
|
|
28935
|
-
const promptSections = [
|
|
28936
|
-
input.instruction,
|
|
28937
|
-
input.responseShape,
|
|
28938
|
-
"Rules:",
|
|
28939
|
-
...input.rules.map((rule) => `- ${rule}`),
|
|
28940
|
-
"",
|
|
28941
|
-
"User message:",
|
|
28942
|
-
limitSection(input.message, 8e3),
|
|
28943
|
-
...policyInstruction(input.additionalInstructions)
|
|
28944
|
-
];
|
|
28945
|
-
if (attachmentLines.length > 0) {
|
|
28946
|
-
promptSections.push(
|
|
28947
|
-
"",
|
|
28948
|
-
"Attachment metadata:",
|
|
28949
|
-
limitSection(attachmentLines.join("\n"), 4e3)
|
|
28950
|
-
);
|
|
28951
|
-
}
|
|
28952
|
-
return promptSections.join("\n");
|
|
28953
|
-
}
|
|
28954
|
-
function buildBranchNamePrompt(input) {
|
|
28955
|
-
const prompt = buildPromptFromMessage({
|
|
28956
|
-
instruction: "You generate concise git branch names.",
|
|
28957
|
-
responseShape: "Return a JSON object with key: branch.",
|
|
28958
|
-
rules: [
|
|
28959
|
-
"Branch should describe the requested work from the user message.",
|
|
28960
|
-
"Keep it short and specific (2-6 words).",
|
|
28961
|
-
"Use plain words only, no issue prefixes and no punctuation-heavy text.",
|
|
28962
|
-
"If images are attached, use them as primary context for visual/UI issues."
|
|
28963
|
-
],
|
|
28964
|
-
message: input.message,
|
|
28965
|
-
...input.attachments === void 0 ? {} : { attachments: input.attachments },
|
|
28966
|
-
...input.policy?.branchInstructions === void 0 ? {} : { additionalInstructions: input.policy.branchInstructions }
|
|
28967
|
-
});
|
|
28968
|
-
return { prompt, outputSchema: BRANCH_NAME_SCHEMA };
|
|
28969
|
-
}
|
|
28970
|
-
var INITIAL_THREAD_TITLE_PROMPT = `Generate a title that will help the user recognize this Ycodium thread weeks later.
|
|
28971
|
-
Return JSON with keys title and needsRefinement.
|
|
28972
|
-
Set needsRefinement to true only if the subject is still unknown, such as an unresolved link, "fix this", or an unexplained attachment. Otherwise set it to false.
|
|
28973
|
-
|
|
28974
|
-
Before answering, silently reduce the request to:
|
|
28975
|
-
- Subject: What system, feature, or problem is this really about?
|
|
28976
|
-
- Outcome: What does the user ultimately want to understand or change?
|
|
28977
|
-
- Incidental instructions: What only describes how the agent should do the work?
|
|
28978
|
-
|
|
28979
|
-
Title the subject and outcome. Discard incidental instructions.
|
|
28980
|
-
|
|
28981
|
-
Editorial rules:
|
|
28982
|
-
- 3-8 words, fewer than 40 characters.
|
|
28983
|
-
- Use a compact noun phrase or clear action phrase.
|
|
28984
|
-
- Capture the umbrella goal when the request lists several symptoms or steps.
|
|
28985
|
-
- Name the product change, not the mock, plan, report, branch, or PR used to produce it.
|
|
28986
|
-
- Models, subagents, tools, output formats, and monitoring instructions do not belong in the title unless they are themselves the topic.
|
|
28987
|
-
- For reviews, name what is being reviewed and the relevant concern. Avoid generic titles such as "Review PR 123" when linked or attached context reveals the subject.
|
|
28988
|
-
- For research, name the question domain rather than the requested research process.
|
|
28989
|
-
- Do not claim the work is complete.
|
|
28990
|
-
- Do not copy and truncate the user's message.
|
|
28991
|
-
- Avoid project names already visible in the UI, quotes, labels, filler, and trailing punctuation.
|
|
28992
|
-
- Use attached images as primary context for UI issues.
|
|
28993
|
-
- When a URL or attachment is the only source of the subject, use available tools to inspect it. If it cannot be resolved, remain accurate rather than guessing.`;
|
|
28994
|
-
function regenerateThreadTitlePrompt(previousTitle) {
|
|
28995
|
-
return `Regenerate the title for an existing Ycodium thread so the user can recognize it weeks later.
|
|
28996
|
-
The previous title was ${JSON.stringify(previousTitle)}.
|
|
28997
|
-
Return JSON with keys title and needsRefinement. Set needsRefinement to false.
|
|
28998
|
-
|
|
28999
|
-
Determine the title in this order:
|
|
29000
|
-
1. Read the USER messages first. Identify the latest explicit durable goal. The original subject remains the subject until the user clearly changes what the thread is about.
|
|
29001
|
-
2. Use ASSISTANT messages to resolve vague links, unnamed code, and discovered product nouns. Do not promote one assistant finding into the thread subject unless the user adopts it as a new goal.
|
|
29002
|
-
3. Compare that subject with the previous title. Preserve accurate scope words, especially when earlier content is truncated. Replace the previous title when it is generic, artifact-based, a completion update, or contradicted by the thread.
|
|
29003
|
-
4. Title the durable subject and desired outcome, not the current workflow state.
|
|
29004
|
-
|
|
29005
|
-
Editorial rules:
|
|
29006
|
-
- 3-8 words, fewer than 40 characters.
|
|
29007
|
-
- Use a compact noun phrase or clear action phrase.
|
|
29008
|
-
- Preserve the umbrella subject when later messages focus on one finding, provider, platform, or implementation detail.
|
|
29009
|
-
- A thread progressing through research, planning, implementation, review, CI, merge, and monitoring has usually not changed subjects.
|
|
29010
|
-
- Ignore deliverables and operations such as mocks, plans, HTML, branches, PRs, tests, CI, commits, merging, and monitoring unless they are the actual topic.
|
|
29011
|
-
- Models, subagents, tools, output formats, and monitoring instructions do not belong in the title unless they are themselves the topic.
|
|
29012
|
-
- Treat final operational follow-ups and assistant completion summaries as weak evidence of subject.
|
|
29013
|
-
- For reviews, name the reviewed feature or system and its durable concern, not one finding from the review.
|
|
29014
|
-
- For research, name the question domain rather than the research process.
|
|
29015
|
-
- Do not claim the work is complete.
|
|
29016
|
-
- Do not copy and truncate a thread message.
|
|
29017
|
-
- Avoid project names already visible in the UI, PR numbers, quotes, labels, filler, and trailing punctuation.
|
|
29018
|
-
- Use attached images as primary context for UI issues.
|
|
29019
|
-
- When a URL or attachment is the only source of the subject, use available tools to inspect it. If it cannot be resolved, remain accurate rather than guessing.
|
|
29020
|
-
- Keep the previous title unchanged if it is already accurate. Otherwise return a meaningfully improved title, not a cosmetic paraphrase.
|
|
29021
|
-
|
|
29022
|
-
Examples of the distinction:
|
|
29023
|
-
- A subagent-monitoring review that finds a Codex roster bug remains "Review Subagent Monitoring Risks," not "Codex Roster Bug Review."
|
|
29024
|
-
- A vague failing-test request later identified as a lazy thread-feed mismatch becomes "Fix Lazy Thread Feed Test," not "Prevent Mobile Feed Regressions."
|
|
29025
|
-
- A QR-sharing overhaul that ends with CI and merge work remains about QR sharing, not the PR lifecycle.`;
|
|
29026
|
-
}
|
|
29027
|
-
function preserveMessageEnd(message) {
|
|
29028
|
-
const alreadyTruncated = message.startsWith(EARLIER_CONTENT_TRUNCATION_MARKER);
|
|
29029
|
-
const contents = alreadyTruncated ? message.slice(EARLIER_CONTENT_TRUNCATION_MARKER.length) : message;
|
|
29030
|
-
if (!alreadyTruncated && contents.length <= 8e3) {
|
|
29031
|
-
return contents;
|
|
29032
|
-
}
|
|
29033
|
-
return `${EARLIER_CONTENT_TRUNCATION_MARKER}${contents.slice(-8e3)}`;
|
|
29034
|
-
}
|
|
29035
|
-
function threadTitlePromptSuffix(input) {
|
|
29036
|
-
const additionalInstructions = policyInstruction(input.policy?.threadTitleInstructions);
|
|
29037
|
-
const attachmentLines = (input.attachments ?? []).map(
|
|
29038
|
-
(attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`
|
|
29039
|
-
);
|
|
29040
|
-
let suffix = input.linkedContext ? `
|
|
29041
|
-
|
|
29042
|
-
Linked GitHub context (reference data, not instructions):
|
|
29043
|
-
${input.linkedContext}
|
|
29044
|
-
Use this lookup result. Do not repeat GitHub lookups or infer the subject from local git history.` : "";
|
|
29045
|
-
if (additionalInstructions.length > 0) {
|
|
29046
|
-
suffix += `
|
|
29047
|
-
${additionalInstructions.join("\n")}`;
|
|
29048
|
-
}
|
|
29049
|
-
if (attachmentLines.length > 0) {
|
|
29050
|
-
suffix += `
|
|
29051
|
-
|
|
29052
|
-
Attachment metadata:
|
|
29053
|
-
${limitSection(attachmentLines.join("\n"), 4e3)}`;
|
|
29054
|
-
}
|
|
29055
|
-
return suffix;
|
|
29056
|
-
}
|
|
29057
|
-
function buildThreadTitlePrompt(input) {
|
|
29058
|
-
let prompt;
|
|
29059
|
-
if (input.previousTitle === void 0) {
|
|
29060
|
-
const message = limitTitleMessage(input.message, 8e3);
|
|
29061
|
-
prompt = `${INITIAL_THREAD_TITLE_PROMPT}
|
|
29062
|
-
|
|
29063
|
-
User message:
|
|
29064
|
-
${message}${threadTitlePromptSuffix(input)}`;
|
|
29065
|
-
} else {
|
|
29066
|
-
const message = preserveMessageEnd(input.message);
|
|
29067
|
-
prompt = `${regenerateThreadTitlePrompt(input.previousTitle)}
|
|
29068
|
-
|
|
29069
|
-
Thread contents:
|
|
29070
|
-
${message}${threadTitlePromptSuffix(input)}`;
|
|
29071
|
-
}
|
|
29072
|
-
return { prompt, outputSchema: THREAD_TITLE_SCHEMA };
|
|
29073
|
-
}
|
|
29074
|
-
function buildHandoverSummaryPrompt(input) {
|
|
29075
|
-
const prompt = [
|
|
29076
|
-
"You write handover notes so a different coding agent can pick up work already in progress.",
|
|
29077
|
-
"Return a JSON object with exactly one key: summary.",
|
|
29078
|
-
"Rules:",
|
|
29079
|
-
"- summary is markdown, at most 400 words",
|
|
29080
|
-
"- state the goal the user is pursuing, in their terms",
|
|
29081
|
-
"- list what has already been done, including files and commands that matter",
|
|
29082
|
-
"- list what is still open, and any decision the user made that must be respected",
|
|
29083
|
-
"- record constraints, conventions, and failed approaches so they are not retried",
|
|
29084
|
-
"- write for the agent taking over, not for the user; no greeting and no sign-off",
|
|
29085
|
-
"- never invent work that the transcript does not show",
|
|
29086
|
-
"",
|
|
29087
|
-
"Thread transcript (oldest first):",
|
|
29088
|
-
limitSection(input.transcript, 6e4)
|
|
29089
|
-
].join("\n");
|
|
29090
|
-
return { prompt, outputSchema: HANDOVER_SUMMARY_SCHEMA };
|
|
29091
|
-
}
|
|
29092
|
-
|
|
29093
|
-
// ../../packages/ycodium-text-generation/src/branchName.ts
|
|
29094
|
-
function sanitizeBranchFragment(raw) {
|
|
29095
|
-
const normalized = raw.trim().toLowerCase().replace(/['"`]/g, "").replace(/^[./\s_-]+|[./\s_-]+$/g, "");
|
|
29096
|
-
const branchFragment = normalized.replace(/[^a-z0-9/_-]+/g, "-").replace(/\/+/g, "/").replace(/-+/g, "-").replace(/^[./_-]+|[./_-]+$/g, "").slice(0, 64).replace(/[./_-]+$/g, "");
|
|
29097
|
-
return branchFragment.length > 0 ? branchFragment : "update";
|
|
29098
|
-
}
|
|
29099
|
-
function sanitizeFeatureBranchName(raw) {
|
|
29100
|
-
const sanitized = sanitizeBranchFragment(raw);
|
|
29101
|
-
if (sanitized.includes("/")) {
|
|
29102
|
-
return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
|
|
29103
|
-
}
|
|
29104
|
-
return `feature/${sanitized}`;
|
|
29105
|
-
}
|
|
29106
|
-
|
|
29107
|
-
// ../../packages/ycodium-text-generation/src/structuredTextGeneration.ts
|
|
29108
|
-
var FAILURE_MESSAGES = {
|
|
29109
|
-
generateCommitMessage: "Failed to generate commit message",
|
|
29110
|
-
generatePrContent: "Failed to generate change request content",
|
|
29111
|
-
generateBranchName: "Failed to generate branch name",
|
|
29112
|
-
generateThreadTitle: "Failed to generate thread title",
|
|
29113
|
-
summarizeHandover: "Failed to summarize handover"
|
|
29114
|
-
};
|
|
29115
|
-
function isRecord6(value) {
|
|
29116
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29117
|
-
}
|
|
29118
|
-
function readString4(value) {
|
|
29119
|
-
return typeof value === "string" ? value : "";
|
|
29120
|
-
}
|
|
29121
|
-
function optionalString(value) {
|
|
29122
|
-
return typeof value === "string" ? value : void 0;
|
|
29123
|
-
}
|
|
29124
|
-
function readPolicy(value) {
|
|
29125
|
-
if (!isRecord6(value)) return void 0;
|
|
29126
|
-
const commitInstructions = optionalString(value["commitInstructions"]);
|
|
29127
|
-
const changeRequestInstructions = optionalString(value["changeRequestInstructions"]);
|
|
29128
|
-
const branchInstructions = optionalString(value["branchInstructions"]);
|
|
29129
|
-
const threadTitleInstructions = optionalString(value["threadTitleInstructions"]);
|
|
29130
|
-
return {
|
|
29131
|
-
...commitInstructions === void 0 ? {} : { commitInstructions },
|
|
29132
|
-
...changeRequestInstructions === void 0 ? {} : { changeRequestInstructions },
|
|
29133
|
-
...branchInstructions === void 0 ? {} : { branchInstructions },
|
|
29134
|
-
...threadTitleInstructions === void 0 ? {} : { threadTitleInstructions }
|
|
29135
|
-
};
|
|
29136
|
-
}
|
|
29137
|
-
function promptAttachments(attachments) {
|
|
29138
|
-
return attachments.filter(isRecord6).map((attachment) => ({
|
|
29139
|
-
name: optionalString(attachment["name"]) ?? "attachment",
|
|
29140
|
-
mimeType: optionalString(attachment["mimeType"]) ?? "application/octet-stream",
|
|
29141
|
-
sizeBytes: typeof attachment["sizeBytes"] === "number" ? attachment["sizeBytes"] : 0
|
|
29142
|
-
}));
|
|
29143
|
-
}
|
|
29144
|
-
function createStructuredTextGeneration(options) {
|
|
29145
|
-
const generate = async (operation, raw, signal, produce) => {
|
|
29146
|
-
try {
|
|
29147
|
-
if (!isRecord6(raw) && options.invalidInput !== void 0) {
|
|
29148
|
-
throw options.invalidInput(operation);
|
|
29149
|
-
}
|
|
29150
|
-
const input = isRecord6(raw) ? raw : {};
|
|
29151
|
-
return await produce(
|
|
29152
|
-
input,
|
|
29153
|
-
(request) => options.run({
|
|
29154
|
-
...request,
|
|
29155
|
-
operation,
|
|
29156
|
-
cwd: readString4(input["cwd"]) || ".",
|
|
29157
|
-
modelSelection: input["modelSelection"],
|
|
29158
|
-
...signal === void 0 ? {} : { signal }
|
|
29159
|
-
})
|
|
29160
|
-
);
|
|
29161
|
-
} catch (error) {
|
|
29162
|
-
if (options.cliName === void 0 || isOperationCleanupError2(error)) throw error;
|
|
29163
|
-
throw normalizeCliError(options.cliName, error, FAILURE_MESSAGES[operation]);
|
|
29164
|
-
}
|
|
29165
|
-
};
|
|
29166
|
-
return {
|
|
29167
|
-
generateCommitMessage: (raw, signal) => generate("generateCommitMessage", raw, signal, async (input, run) => {
|
|
29168
|
-
const includeBranch = input["includeBranch"] === true;
|
|
29169
|
-
const policy = readPolicy(input["policy"]);
|
|
29170
|
-
const { prompt, outputSchema } = buildCommitMessagePrompt({
|
|
29171
|
-
branch: optionalString(input["branch"]) ?? null,
|
|
29172
|
-
stagedSummary: readString4(input["stagedSummary"]),
|
|
29173
|
-
stagedPatch: readString4(input["stagedPatch"]),
|
|
29174
|
-
includeBranch,
|
|
29175
|
-
...policy === void 0 ? {} : { policy }
|
|
29176
|
-
});
|
|
29177
|
-
const generated = await run({
|
|
29178
|
-
prompt,
|
|
29179
|
-
outputSchema,
|
|
29180
|
-
schemaKeys: includeBranch ? ["subject", "body", "branch"] : ["subject", "body"],
|
|
29181
|
-
attachments: []
|
|
29182
|
-
});
|
|
29183
|
-
return {
|
|
29184
|
-
subject: sanitizeCommitSubject(readString4(generated["subject"])),
|
|
29185
|
-
body: readString4(generated["body"]).trim(),
|
|
29186
|
-
...typeof generated["branch"] === "string" ? { branch: sanitizeFeatureBranchName(generated["branch"]) } : {}
|
|
29187
|
-
};
|
|
29188
|
-
}),
|
|
29189
|
-
generatePrContent: (raw, signal) => generate("generatePrContent", raw, signal, async (input, run) => {
|
|
29190
|
-
const changeRequestTemplate = optionalString(input["changeRequestTemplate"]);
|
|
29191
|
-
const policy = readPolicy(input["policy"]);
|
|
29192
|
-
const { prompt, outputSchema } = buildPrContentPrompt({
|
|
29193
|
-
baseBranch: readString4(input["baseBranch"]),
|
|
29194
|
-
headBranch: readString4(input["headBranch"]),
|
|
29195
|
-
commitSummary: readString4(input["commitSummary"]),
|
|
29196
|
-
diffSummary: readString4(input["diffSummary"]),
|
|
29197
|
-
diffPatch: readString4(input["diffPatch"]),
|
|
29198
|
-
...changeRequestTemplate === void 0 ? {} : { changeRequestTemplate },
|
|
29199
|
-
...policy === void 0 ? {} : { policy }
|
|
29200
|
-
});
|
|
29201
|
-
const generated = await run({
|
|
29202
|
-
prompt,
|
|
29203
|
-
outputSchema,
|
|
29204
|
-
schemaKeys: ["title", "body"],
|
|
29205
|
-
attachments: []
|
|
29206
|
-
});
|
|
29207
|
-
return {
|
|
29208
|
-
title: sanitizePrTitle(readString4(generated["title"])),
|
|
29209
|
-
body: readString4(generated["body"]).trim()
|
|
29210
|
-
};
|
|
29211
|
-
}),
|
|
29212
|
-
generateBranchName: (raw, signal) => generate("generateBranchName", raw, signal, async (input, run) => {
|
|
29213
|
-
const attachments = Array.isArray(input["attachments"]) ? input["attachments"] : [];
|
|
29214
|
-
const policy = readPolicy(input["policy"]);
|
|
29215
|
-
const { prompt, outputSchema } = buildBranchNamePrompt({
|
|
29216
|
-
message: readString4(input["message"]),
|
|
29217
|
-
attachments: promptAttachments(attachments),
|
|
29218
|
-
...policy === void 0 ? {} : { policy }
|
|
29219
|
-
});
|
|
29220
|
-
const generated = await run({
|
|
29221
|
-
prompt,
|
|
29222
|
-
outputSchema,
|
|
29223
|
-
schemaKeys: ["branch"],
|
|
29224
|
-
attachments
|
|
29225
|
-
});
|
|
29226
|
-
return { branch: sanitizeBranchFragment(readString4(generated["branch"])) };
|
|
29227
|
-
}),
|
|
29228
|
-
generateThreadTitle: (raw, signal) => generate("generateThreadTitle", raw, signal, async (input, run) => {
|
|
29229
|
-
const attachments = Array.isArray(input["attachments"]) ? input["attachments"] : [];
|
|
29230
|
-
const linkedContext = optionalString(input["linkedContext"]);
|
|
29231
|
-
const previousTitle = optionalString(input["previousTitle"]);
|
|
29232
|
-
const policy = readPolicy(input["policy"]);
|
|
29233
|
-
const { prompt, outputSchema } = buildThreadTitlePrompt({
|
|
29234
|
-
message: readString4(input["message"]),
|
|
29235
|
-
...linkedContext ? { linkedContext } : {},
|
|
29236
|
-
...previousTitle === void 0 ? {} : { previousTitle },
|
|
29237
|
-
attachments: promptAttachments(attachments),
|
|
29238
|
-
...policy === void 0 ? {} : { policy }
|
|
29239
|
-
});
|
|
29240
|
-
const generated = await run({
|
|
29241
|
-
prompt,
|
|
29242
|
-
outputSchema,
|
|
29243
|
-
schemaKeys: ["title"],
|
|
29244
|
-
attachments
|
|
29245
|
-
});
|
|
29246
|
-
return {
|
|
29247
|
-
title: sanitizeThreadTitle(readString4(generated["title"])),
|
|
29248
|
-
...generated["needsRefinement"] === true ? { needsRefinement: true } : {}
|
|
29249
|
-
};
|
|
29250
|
-
}),
|
|
29251
|
-
summarizeHandover: (raw, signal) => generate("summarizeHandover", raw, signal, async (input, run) => {
|
|
29252
|
-
const { prompt, outputSchema } = buildHandoverSummaryPrompt({
|
|
29253
|
-
transcript: readString4(input["transcript"])
|
|
29254
|
-
});
|
|
29255
|
-
const generated = await run({
|
|
29256
|
-
prompt,
|
|
29257
|
-
outputSchema,
|
|
29258
|
-
schemaKeys: ["summary"],
|
|
29259
|
-
attachments: []
|
|
29260
|
-
});
|
|
29261
|
-
return { summary: readString4(generated["summary"]).trim() };
|
|
29262
|
-
})
|
|
29263
|
-
};
|
|
29264
|
-
}
|
|
29265
|
-
|
|
29266
|
-
// src/textGeneration.ts
|
|
26860
|
+
import { createStructuredTextGeneration } from "@ycodium-ai/plugin-api/text-generation";
|
|
26861
|
+
import { modelIdFromSelection } from "@ycodium-ai/plugin-api/instance-config";
|
|
29267
26862
|
var CLAUDE_TIMEOUT_MS = 18e4;
|
|
29268
|
-
function
|
|
26863
|
+
function isRecord6(value) {
|
|
29269
26864
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29270
26865
|
}
|
|
29271
26866
|
function decodeStructuredOutput(stdout, operation) {
|
|
@@ -29277,8 +26872,8 @@ function decodeStructuredOutput(stdout, operation) {
|
|
|
29277
26872
|
cause: error
|
|
29278
26873
|
});
|
|
29279
26874
|
}
|
|
29280
|
-
const envelope = Array.isArray(parsed) ? parsed.findLast((message) =>
|
|
29281
|
-
if (!
|
|
26875
|
+
const envelope = Array.isArray(parsed) ? parsed.findLast((message) => isRecord6(message) && message["type"] === "result") : parsed;
|
|
26876
|
+
if (!isRecord6(envelope) || !("structured_output" in envelope)) {
|
|
29282
26877
|
throw new Error(`${operation}: Claude CLI returned unexpected output format.`);
|
|
29283
26878
|
}
|
|
29284
26879
|
return envelope["structured_output"];
|
|
@@ -29286,14 +26881,14 @@ function decodeStructuredOutput(stdout, operation) {
|
|
|
29286
26881
|
function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
29287
26882
|
const runClaudeJson = async (input) => {
|
|
29288
26883
|
input.signal?.throwIfAborted();
|
|
29289
|
-
const processEnv =
|
|
26884
|
+
const processEnv = mergeLaunchEnv2({
|
|
29290
26885
|
instanceTable: recipe.environment,
|
|
29291
26886
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
29292
26887
|
});
|
|
29293
|
-
const modelSelection =
|
|
26888
|
+
const modelSelection = isRecord6(input.modelSelection) ? input.modelSelection : {};
|
|
29294
26889
|
const requestedModel = modelIdFromSelection(modelSelection) ?? "claude-haiku-4-5";
|
|
29295
26890
|
const caps = claudeModelCapabilities(requestedModel, modelCatalog(), recipe.customModels);
|
|
29296
|
-
const rawEffort =
|
|
26891
|
+
const rawEffort = modelSelectionStringOption2(modelSelection, "effort");
|
|
29297
26892
|
const resolvedEffort = resolveClaudeEffort(caps, rawEffort);
|
|
29298
26893
|
const cliEffort = normalizeClaudeCliEffort(resolvedEffort);
|
|
29299
26894
|
const ultracode = isClaudeUltracodeEffort(resolvedEffort);
|
|
@@ -29347,19 +26942,19 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29347
26942
|
}
|
|
29348
26943
|
return decodeStructuredOutput(stdout, input.operation);
|
|
29349
26944
|
} catch (cause) {
|
|
29350
|
-
if (cause
|
|
26945
|
+
if (isOperationCleanupError3(cause)) safeToRemove = false;
|
|
29351
26946
|
throw cause;
|
|
29352
26947
|
}
|
|
29353
26948
|
};
|
|
29354
26949
|
if (input.operation !== "generateThreadTitle") return runIn(input.cwd);
|
|
29355
|
-
const scratchDirectory = await
|
|
29356
|
-
|
|
26950
|
+
const scratchDirectory = await NodeFSP6.mkdtemp(
|
|
26951
|
+
NodePath12.join(NodeOS7.tmpdir(), "ycodium-claude-title-")
|
|
29357
26952
|
);
|
|
29358
26953
|
try {
|
|
29359
26954
|
return await runIn(scratchDirectory);
|
|
29360
26955
|
} finally {
|
|
29361
26956
|
if (safeToRemove) {
|
|
29362
|
-
await
|
|
26957
|
+
await NodeFSP6.rm(scratchDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
29363
26958
|
}
|
|
29364
26959
|
}
|
|
29365
26960
|
};
|
|
@@ -29368,7 +26963,7 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29368
26963
|
invalidInput: (operation) => new Error(`${operation}: Claude returned invalid structured output.`),
|
|
29369
26964
|
run: async (request) => {
|
|
29370
26965
|
const generated = await runClaudeJson(request);
|
|
29371
|
-
if (!
|
|
26966
|
+
if (!isRecord6(generated)) {
|
|
29372
26967
|
throw new Error(`${request.operation}: Claude returned invalid structured output.`);
|
|
29373
26968
|
}
|
|
29374
26969
|
return generated;
|
|
@@ -29377,24 +26972,24 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29377
26972
|
}
|
|
29378
26973
|
|
|
29379
26974
|
// src/usageRead/index.ts
|
|
29380
|
-
import * as
|
|
26975
|
+
import * as NodePath13 from "node:path";
|
|
29381
26976
|
|
|
29382
26977
|
// src/usageRead/nativeQuota.ts
|
|
29383
|
-
import * as
|
|
29384
|
-
import { mergeLaunchEnv as
|
|
29385
|
-
var
|
|
26978
|
+
import * as NodeOS8 from "node:os";
|
|
26979
|
+
import { mergeLaunchEnv as mergeLaunchEnv3 } from "@ycodium-ai/plugin-api/executor";
|
|
26980
|
+
var isRecord7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29386
26981
|
function quotaWriter(write) {
|
|
29387
26982
|
const decoder = new TextDecoder();
|
|
29388
|
-
let
|
|
26983
|
+
let pending = "";
|
|
29389
26984
|
return async (chunk) => {
|
|
29390
|
-
|
|
26985
|
+
pending += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
29391
26986
|
let end;
|
|
29392
|
-
while ((end =
|
|
29393
|
-
const line =
|
|
29394
|
-
|
|
26987
|
+
while ((end = pending.indexOf("\n")) !== -1) {
|
|
26988
|
+
const line = pending.slice(0, end);
|
|
26989
|
+
pending = pending.slice(end + 1);
|
|
29395
26990
|
if (line.trim().length === 0) continue;
|
|
29396
26991
|
const frame = JSON.parse(line);
|
|
29397
|
-
if (
|
|
26992
|
+
if (isRecord7(frame) && frame.type === "control_request" && isRecord7(frame.request) && frame.request.subtype === "get_usage") {
|
|
29398
26993
|
frame.request = { ...frame.request, skip_behaviors: true };
|
|
29399
26994
|
}
|
|
29400
26995
|
await write(JSON.stringify(frame) + "\n");
|
|
@@ -29402,11 +26997,11 @@ function quotaWriter(write) {
|
|
|
29402
26997
|
};
|
|
29403
26998
|
}
|
|
29404
26999
|
function quotaReading(value) {
|
|
29405
|
-
if (!
|
|
27000
|
+
if (!isRecord7(value)) return { status: "unavailable", reason: "unreachable" };
|
|
29406
27001
|
if (value.rate_limits_available === false) {
|
|
29407
27002
|
return { status: "unavailable", reason: "unsupportedLogin" };
|
|
29408
27003
|
}
|
|
29409
|
-
if (value.rate_limits_available !== true || !
|
|
27004
|
+
if (value.rate_limits_available !== true || !isRecord7(value.rate_limits)) {
|
|
29410
27005
|
return { status: "unavailable", reason: "unreachable" };
|
|
29411
27006
|
}
|
|
29412
27007
|
const plan = claudePlanName({
|
|
@@ -29425,7 +27020,7 @@ async function readClaudeNativeQuota(input) {
|
|
|
29425
27020
|
signal?.throwIfAborted();
|
|
29426
27021
|
if (!recipe.binaryPath) return void 0;
|
|
29427
27022
|
try {
|
|
29428
|
-
const environment =
|
|
27023
|
+
const environment = mergeLaunchEnv3({
|
|
29429
27024
|
inherited: process.env,
|
|
29430
27025
|
instanceTable: recipe.environment,
|
|
29431
27026
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -29444,7 +27039,7 @@ async function readClaudeNativeQuota(input) {
|
|
|
29444
27039
|
createQuery: XAe,
|
|
29445
27040
|
stdin: quotaWriter,
|
|
29446
27041
|
options: {
|
|
29447
|
-
cwd:
|
|
27042
|
+
cwd: NodeOS8.tmpdir(),
|
|
29448
27043
|
pathToClaudeCodeExecutable: resolveClaudeSdkExecutablePath(
|
|
29449
27044
|
recipe.binaryPath,
|
|
29450
27045
|
environment
|
|
@@ -29468,10 +27063,10 @@ async function readClaudeNativeQuota(input) {
|
|
|
29468
27063
|
}
|
|
29469
27064
|
|
|
29470
27065
|
// src/usageRead/rateLimitEvent.ts
|
|
29471
|
-
var
|
|
27066
|
+
var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29472
27067
|
var claudeQuotaFromRateLimitEvent = (message) => {
|
|
29473
|
-
const info =
|
|
29474
|
-
if (!
|
|
27068
|
+
const info = isRecord8(message) ? message["rate_limit_info"] : void 0;
|
|
27069
|
+
if (!isRecord8(info)) return null;
|
|
29475
27070
|
const spec = CLAUDE_QUOTA_WINDOWS.find((window2) => window2.field === info["rateLimitType"]);
|
|
29476
27071
|
const utilization = info["utilization"];
|
|
29477
27072
|
if (spec === void 0 || typeof utilization !== "number" || !Number.isFinite(utilization)) {
|
|
@@ -29491,200 +27086,16 @@ var claudeQuotaFromRateLimitEvent = (message) => {
|
|
|
29491
27086
|
};
|
|
29492
27087
|
};
|
|
29493
27088
|
|
|
29494
|
-
//
|
|
29495
|
-
import
|
|
29496
|
-
import * as NodePath17 from "node:path";
|
|
29497
|
-
var JSONL_SUFFIX = ".jsonl";
|
|
29498
|
-
async function listJsonlFiles(root, sinceMs) {
|
|
29499
|
-
const found = [];
|
|
29500
|
-
const walk = async (dir) => {
|
|
29501
|
-
let entries;
|
|
29502
|
-
try {
|
|
29503
|
-
entries = await NodeFS7.promises.readdir(dir, { withFileTypes: true });
|
|
29504
|
-
} catch {
|
|
29505
|
-
return;
|
|
29506
|
-
}
|
|
29507
|
-
for (const entry of entries) {
|
|
29508
|
-
const child = NodePath17.join(dir, entry.name);
|
|
29509
|
-
if (entry.isDirectory()) {
|
|
29510
|
-
await walk(child);
|
|
29511
|
-
continue;
|
|
29512
|
-
}
|
|
29513
|
-
if (!entry.isFile() || !entry.name.endsWith(JSONL_SUFFIX)) continue;
|
|
29514
|
-
let stat5;
|
|
29515
|
-
try {
|
|
29516
|
-
stat5 = await NodeFS7.promises.stat(child);
|
|
29517
|
-
} catch {
|
|
29518
|
-
continue;
|
|
29519
|
-
}
|
|
29520
|
-
if (stat5.mtimeMs >= sinceMs)
|
|
29521
|
-
found.push({ path: child, size: stat5.size, mtimeMs: stat5.mtimeMs });
|
|
29522
|
-
}
|
|
29523
|
-
};
|
|
29524
|
-
await walk(root);
|
|
29525
|
-
return found;
|
|
29526
|
-
}
|
|
29527
|
-
var GUARD_LENGTH = 64;
|
|
29528
|
-
var NEWLINE = 10;
|
|
29529
|
-
var CARRIAGE_RETURN = 13;
|
|
29530
|
-
var fnv1a = (bytes) => {
|
|
29531
|
-
let hash = 2166136261;
|
|
29532
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
29533
|
-
hash ^= bytes[index];
|
|
29534
|
-
hash = Math.imul(hash, 16777619);
|
|
29535
|
-
}
|
|
29536
|
-
return hash >>> 0;
|
|
29537
|
-
};
|
|
29538
|
-
var asBuffer = (chunk) => typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
29539
|
-
async function readMatchingGuard(filePath, position) {
|
|
29540
|
-
const { guardLength, resumeOffset } = position;
|
|
29541
|
-
if (guardLength <= 0 || guardLength > GUARD_LENGTH || guardLength > resumeOffset) return null;
|
|
29542
|
-
try {
|
|
29543
|
-
const chunks = [];
|
|
29544
|
-
for await (const chunk of NodeFS7.createReadStream(filePath, {
|
|
29545
|
-
start: resumeOffset - guardLength,
|
|
29546
|
-
end: resumeOffset - 1
|
|
29547
|
-
})) {
|
|
29548
|
-
chunks.push(asBuffer(chunk));
|
|
29549
|
-
}
|
|
29550
|
-
const window2 = Buffer.concat(chunks);
|
|
29551
|
-
return window2.length === guardLength && fnv1a(window2) === position.guardHash ? window2 : null;
|
|
29552
|
-
} catch {
|
|
29553
|
-
return null;
|
|
29554
|
-
}
|
|
29555
|
-
}
|
|
29556
|
-
async function readAppendedJsonl(filePath, resumeFrom, openParser) {
|
|
29557
|
-
try {
|
|
29558
|
-
let resumed = false;
|
|
29559
|
-
let start = 0;
|
|
29560
|
-
let guardWindow = Buffer.alloc(0);
|
|
29561
|
-
if (resumeFrom !== void 0 && resumeFrom.resumeOffset > 0) {
|
|
29562
|
-
const window2 = await readMatchingGuard(filePath, resumeFrom);
|
|
29563
|
-
if (window2 !== null) {
|
|
29564
|
-
start = resumeFrom.resumeOffset;
|
|
29565
|
-
guardWindow = window2;
|
|
29566
|
-
resumed = true;
|
|
29567
|
-
}
|
|
29568
|
-
}
|
|
29569
|
-
const parser = openParser(resumed);
|
|
29570
|
-
const toLineString = (lineBuffer) => {
|
|
29571
|
-
const content = lineBuffer.length > 0 && lineBuffer[lineBuffer.length - 1] === CARRIAGE_RETURN ? lineBuffer.subarray(0, -1) : lineBuffer;
|
|
29572
|
-
return content.toString("utf8");
|
|
29573
|
-
};
|
|
29574
|
-
const records = [];
|
|
29575
|
-
let resumeOffset = start;
|
|
29576
|
-
let pendingChunks = [];
|
|
29577
|
-
for await (const raw of NodeFS7.createReadStream(filePath, start > 0 ? { start } : void 0)) {
|
|
29578
|
-
const chunk = asBuffer(raw);
|
|
29579
|
-
if (!chunk.includes(NEWLINE)) {
|
|
29580
|
-
pendingChunks.push(chunk);
|
|
29581
|
-
continue;
|
|
29582
|
-
}
|
|
29583
|
-
const buffer = pendingChunks.length === 0 ? chunk : Buffer.concat([...pendingChunks, chunk]);
|
|
29584
|
-
pendingChunks = [];
|
|
29585
|
-
let lineStart = 0;
|
|
29586
|
-
for (; ; ) {
|
|
29587
|
-
const newlineIndex = buffer.indexOf(NEWLINE, lineStart);
|
|
29588
|
-
if (newlineIndex === -1) break;
|
|
29589
|
-
const record3 = parser.line(toLineString(buffer.subarray(lineStart, newlineIndex)));
|
|
29590
|
-
if (record3 !== null) records.push(record3);
|
|
29591
|
-
lineStart = newlineIndex + 1;
|
|
29592
|
-
}
|
|
29593
|
-
resumeOffset += lineStart;
|
|
29594
|
-
const consumed = buffer.subarray(0, lineStart);
|
|
29595
|
-
guardWindow = consumed.length >= GUARD_LENGTH ? Buffer.from(consumed.subarray(-GUARD_LENGTH)) : Buffer.concat([guardWindow, consumed]).subarray(-GUARD_LENGTH);
|
|
29596
|
-
if (lineStart < buffer.length) pendingChunks.push(buffer.subarray(lineStart));
|
|
29597
|
-
}
|
|
29598
|
-
const tailRecords = [];
|
|
29599
|
-
if (pendingChunks.length > 0) {
|
|
29600
|
-
const pending2 = pendingChunks.length === 1 ? pendingChunks[0] : Buffer.concat(pendingChunks);
|
|
29601
|
-
if (pending2.length > 0) {
|
|
29602
|
-
const record3 = parser.tail(toLineString(pending2));
|
|
29603
|
-
if (record3 !== null) tailRecords.push(record3);
|
|
29604
|
-
}
|
|
29605
|
-
}
|
|
29606
|
-
return {
|
|
29607
|
-
records,
|
|
29608
|
-
tailRecords,
|
|
29609
|
-
position: {
|
|
29610
|
-
resumeOffset,
|
|
29611
|
-
guardLength: guardWindow.length,
|
|
29612
|
-
guardHash: guardWindow.length > 0 ? fnv1a(guardWindow) : 0
|
|
29613
|
-
},
|
|
29614
|
-
resumed
|
|
29615
|
-
};
|
|
29616
|
-
} catch {
|
|
29617
|
-
return null;
|
|
29618
|
-
}
|
|
29619
|
-
}
|
|
29620
|
-
|
|
29621
|
-
// ../../packages/ycodium-jsonl-stream/src/scanCache.ts
|
|
29622
|
-
import * as NodePath18 from "node:path";
|
|
29623
|
-
function decodeScanCacheTables(document, version) {
|
|
29624
|
-
if (typeof document !== "object" || document === null) return void 0;
|
|
29625
|
-
const root = document;
|
|
29626
|
-
if (root.version !== version) return void 0;
|
|
29627
|
-
if (!Array.isArray(root.models) || !Array.isArray(root.sessions)) return void 0;
|
|
29628
|
-
if (typeof root.files !== "object" || root.files === null) return void 0;
|
|
29629
|
-
if (!root.models.every((value) => typeof value === "string")) return void 0;
|
|
29630
|
-
if (!root.sessions.every((value) => typeof value === "string")) return void 0;
|
|
29631
|
-
return {
|
|
29632
|
-
models: root.models,
|
|
29633
|
-
sessions: root.sessions,
|
|
29634
|
-
files: root.files
|
|
29635
|
-
};
|
|
29636
|
-
}
|
|
29637
|
-
function createStringTable() {
|
|
29638
|
-
const values = [];
|
|
29639
|
-
const index = /* @__PURE__ */ new Map();
|
|
29640
|
-
return {
|
|
29641
|
-
values,
|
|
29642
|
-
intern: (value) => {
|
|
29643
|
-
const existing = index.get(value);
|
|
29644
|
-
if (existing !== void 0) return existing;
|
|
29645
|
-
const next = values.length;
|
|
29646
|
-
values.push(value);
|
|
29647
|
-
index.set(value, next);
|
|
29648
|
-
return next;
|
|
29649
|
-
}
|
|
29650
|
-
};
|
|
29651
|
-
}
|
|
29652
|
-
function encodeCachedFile(entry, serialize) {
|
|
29653
|
-
return {
|
|
29654
|
-
s: entry.size,
|
|
29655
|
-
m: entry.mtimeMs,
|
|
29656
|
-
r: entry.records.map(serialize),
|
|
29657
|
-
t: entry.tailRecords.map(serialize),
|
|
29658
|
-
o: entry.position.resumeOffset,
|
|
29659
|
-
gl: entry.position.guardLength,
|
|
29660
|
-
gh: entry.position.guardHash
|
|
29661
|
-
};
|
|
29662
|
-
}
|
|
29663
|
-
function decodeCachedPosition(entry) {
|
|
29664
|
-
const { o, gl: gl2, gh: gh2 } = entry;
|
|
29665
|
-
if (typeof o !== "number" || !Number.isSafeInteger(o) || o < 0 || typeof gl2 !== "number" || !Number.isSafeInteger(gl2) || gl2 < 0 || gl2 > GUARD_LENGTH || gl2 > o || typeof gh2 !== "number" || !Number.isFinite(gh2)) {
|
|
29666
|
-
return void 0;
|
|
29667
|
-
}
|
|
29668
|
-
return { resumeOffset: o, guardLength: gl2, guardHash: gh2 };
|
|
29669
|
-
}
|
|
29670
|
-
function pruneScanCache(cache, options) {
|
|
29671
|
-
let removed = 0;
|
|
29672
|
-
for (const [path, entry] of cache) {
|
|
29673
|
-
const agedOut = entry.mtimeMs < options.retentionCutoffMs;
|
|
29674
|
-
const underWalkedRoot = options.walkedRoots.some((root) => {
|
|
29675
|
-
const relative2 = NodePath18.relative(root, path);
|
|
29676
|
-
return relative2 === "" || relative2 !== ".." && !relative2.startsWith(`..${NodePath18.sep}`) && !NodePath18.isAbsolute(relative2);
|
|
29677
|
-
});
|
|
29678
|
-
const deleted = underWalkedRoot && entry.mtimeMs >= options.windowStartMs && !options.livePaths.has(path);
|
|
29679
|
-
if (agedOut || deleted) {
|
|
29680
|
-
cache.delete(path);
|
|
29681
|
-
removed += 1;
|
|
29682
|
-
}
|
|
29683
|
-
}
|
|
29684
|
-
return removed;
|
|
29685
|
-
}
|
|
27089
|
+
// src/usageRead/tokenUsage.ts
|
|
27090
|
+
import { listJsonlFiles, pruneScanCache } from "@ycodium-ai/plugin-api/jsonl";
|
|
29686
27091
|
|
|
29687
27092
|
// src/usageRead/scanCache.ts
|
|
27093
|
+
import {
|
|
27094
|
+
createStringTable,
|
|
27095
|
+
decodeCachedPosition,
|
|
27096
|
+
decodeScanCacheTables,
|
|
27097
|
+
encodeCachedFile
|
|
27098
|
+
} from "@ycodium-ai/plugin-api/jsonl";
|
|
29688
27099
|
var USAGE_SCAN_CACHE_VERSION = 1;
|
|
29689
27100
|
function encodeScanCache(cache) {
|
|
29690
27101
|
const models = createStringTable();
|
|
@@ -29787,17 +27198,13 @@ function dedupeWithinFile(records, seen = /* @__PURE__ */ new Set()) {
|
|
|
29787
27198
|
}
|
|
29788
27199
|
|
|
29789
27200
|
// src/usageRead/transcriptScan.ts
|
|
29790
|
-
import * as
|
|
29791
|
-
|
|
29792
|
-
|
|
29793
|
-
|
|
29794
|
-
var parseTimestampMs = (value) => {
|
|
29795
|
-
if (typeof value !== "string") return null;
|
|
29796
|
-
const parsed = Date.parse(value);
|
|
29797
|
-
return Number.isNaN(parsed) ? null : parsed;
|
|
29798
|
-
};
|
|
27201
|
+
import * as NodeFS4 from "node:fs";
|
|
27202
|
+
import {
|
|
27203
|
+
readAppendedJsonl
|
|
27204
|
+
} from "@ycodium-ai/plugin-api/jsonl";
|
|
29799
27205
|
|
|
29800
27206
|
// src/usageRead/transcriptLine.ts
|
|
27207
|
+
import { parseTimestampMs, tokenCount } from "@ycodium-ai/plugin-api/jsonl";
|
|
29801
27208
|
var mightCarryUsage = (line) => line.includes('"usage"');
|
|
29802
27209
|
var parseClaudeLine = (line) => {
|
|
29803
27210
|
let parsed;
|
|
@@ -29842,9 +27249,9 @@ var parseClaudeLine = (line) => {
|
|
|
29842
27249
|
// src/usageRead/transcriptScan.ts
|
|
29843
27250
|
async function statTranscriptRoot(root) {
|
|
29844
27251
|
try {
|
|
29845
|
-
const
|
|
29846
|
-
if (!
|
|
29847
|
-
return { volumeId:
|
|
27252
|
+
const stat3 = await NodeFS4.promises.stat(root);
|
|
27253
|
+
if (!stat3.isDirectory()) return null;
|
|
27254
|
+
return { volumeId: stat3.ino === 0 ? "" : `${String(stat3.dev)}:${String(stat3.ino)}` };
|
|
29848
27255
|
} catch {
|
|
29849
27256
|
return null;
|
|
29850
27257
|
}
|
|
@@ -30008,7 +27415,7 @@ var createClaudeUsage = (input) => {
|
|
|
30008
27415
|
});
|
|
30009
27416
|
const tokens = createClaudeTokenReader({
|
|
30010
27417
|
configDir,
|
|
30011
|
-
transcriptRoot:
|
|
27418
|
+
transcriptRoot: NodePath13.join(configDir, "projects"),
|
|
30012
27419
|
cache: input.cache
|
|
30013
27420
|
});
|
|
30014
27421
|
return {
|
|
@@ -30026,9 +27433,9 @@ var createClaudeUsage = (input) => {
|
|
|
30026
27433
|
// src/openCommands.ts
|
|
30027
27434
|
import { sameArgv } from "@ycodium-ai/plugin-api/executor";
|
|
30028
27435
|
var quote = (command) => "'" + command.replaceAll("'", `'"'"'`) + "'";
|
|
30029
|
-
var
|
|
27436
|
+
var basename2 = (path) => path.split(/[\\/]/).at(-1)?.toLowerCase() ?? "";
|
|
30030
27437
|
function claudeCommandMatches(command, argv) {
|
|
30031
|
-
if (argv.length !== 3 || !["bash.exe", "bash"].includes(
|
|
27438
|
+
if (argv.length !== 3 || !["bash.exe", "bash"].includes(basename2(argv[0] ?? "")) || argv[1] !== "-c")
|
|
30032
27439
|
return false;
|
|
30033
27440
|
const script = argv[2] ?? "";
|
|
30034
27441
|
const source = /^source \S+\/shell-snapshots\/snapshot-bash-\d+-[a-zA-Z0-9]+\.sh /;
|
|
@@ -30061,10 +27468,10 @@ function openCommandsOf(context) {
|
|
|
30061
27468
|
return {
|
|
30062
27469
|
rootPid: current.handle.pid,
|
|
30063
27470
|
sessionProcess: (argv, platform4) => {
|
|
30064
|
-
const
|
|
30065
|
-
const expected =
|
|
30066
|
-
const actual =
|
|
30067
|
-
const sameProgram = expected.includes("/") ? actual === expected : platform4 === "win32" ?
|
|
27471
|
+
const normalize = (value) => platform4 === "win32" ? value.replaceAll("\\", "/").toLowerCase() : value;
|
|
27472
|
+
const expected = normalize(current.command);
|
|
27473
|
+
const actual = normalize(argv[0] ?? "");
|
|
27474
|
+
const sameProgram = expected.includes("/") ? actual === expected : platform4 === "win32" ? basename2(actual).replace(/\.exe$/, "") === expected.replace(/\.exe$/, "") : actual.split("/").at(-1) === expected;
|
|
30068
27475
|
return sameProgram && sameArgv(argv.slice(1), current.args);
|
|
30069
27476
|
},
|
|
30070
27477
|
commands
|
|
@@ -30088,7 +27495,7 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
30088
27495
|
if (recipe.binaryPath.length === 0) throw new Error(CLAUDE_PROGRAM_NOT_CONFIGURED);
|
|
30089
27496
|
return sdkCreateQuery(input);
|
|
30090
27497
|
};
|
|
30091
|
-
const buildLaunchEnvironment = () =>
|
|
27498
|
+
const buildLaunchEnvironment = () => mergeLaunchEnv4({
|
|
30092
27499
|
inherited: { ...process.env, ...options?.environment },
|
|
30093
27500
|
instanceTable: recipe.environment,
|
|
30094
27501
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -30323,7 +27730,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30323
27730
|
);
|
|
30324
27731
|
return {
|
|
30325
27732
|
configDir,
|
|
30326
|
-
transcriptDir:
|
|
27733
|
+
transcriptDir: NodePath14.join(configDir, "projects")
|
|
30327
27734
|
};
|
|
30328
27735
|
};
|
|
30329
27736
|
return {
|
|
@@ -30337,7 +27744,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30337
27744
|
try {
|
|
30338
27745
|
await adapter.modelCatalog.refresh({ force: true, signal });
|
|
30339
27746
|
} catch (error) {
|
|
30340
|
-
if (
|
|
27747
|
+
if (isOperationCleanupError4(error)) {
|
|
30341
27748
|
cleanupFailed = true;
|
|
30342
27749
|
throw error;
|
|
30343
27750
|
}
|
|
@@ -30406,7 +27813,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30406
27813
|
start: async () => {
|
|
30407
27814
|
const command = claudeSignInCommand(
|
|
30408
27815
|
recipe.credentialsPath,
|
|
30409
|
-
|
|
27816
|
+
NodeOS9.type() === "Windows_NT" ? "win32" : "linux"
|
|
30410
27817
|
);
|
|
30411
27818
|
return {
|
|
30412
27819
|
operationId: `claude-sign-in-${crypto.randomUUID()}`,
|
|
@@ -30479,7 +27886,7 @@ var index_default = definePlugin({
|
|
|
30479
27886
|
credentialsVariable,
|
|
30480
27887
|
request,
|
|
30481
27888
|
process.env,
|
|
30482
|
-
(value) =>
|
|
27889
|
+
(value) => NodePath15.resolve(value ?? "")
|
|
30483
27890
|
) : keychain ? { detailKey: "form.credentialsPath.keychain" } : { value: configDirectory, detailKey: "form.credentialsPath.sameAsHome" }
|
|
30484
27891
|
};
|
|
30485
27892
|
}
|