@ycodium-ai/agent-claude 0.2.5634 → 0.2.5763
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 +316 -2951
- package/package.json +4 -9
package/dist/index.js
CHANGED
|
@@ -1,40 +1,23 @@
|
|
|
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 = 181;
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import {
|
|
10
|
-
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA
|
|
10
|
+
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
11
11
|
executorEnvironmentValue,
|
|
12
|
-
executorHomeEffectiveValue
|
|
13
|
-
readExecutorEffectiveRequest
|
|
12
|
+
executorHomeEffectiveValue,
|
|
13
|
+
readExecutorEffectiveRequest
|
|
14
14
|
} from "@ycodium-ai/plugin-api/executor";
|
|
15
15
|
|
|
16
|
-
// ../../packages/ycodium-instance-config/src/programHomeSchema.ts
|
|
17
|
-
var executorEnvelopeFields = {
|
|
18
|
-
enabled: { type: "boolean" },
|
|
19
|
-
customModels: { type: "array" },
|
|
20
|
-
driver: { type: "string" },
|
|
21
|
-
config: { type: "object" },
|
|
22
|
-
environment: { type: "array" }
|
|
23
|
-
};
|
|
24
|
-
function executorProgramField(name, options = {}) {
|
|
25
|
-
return {
|
|
26
|
-
type: "string",
|
|
27
|
-
"x-ycodium-form": {
|
|
28
|
-
titleKey: `form.${name}.title`,
|
|
29
|
-
...options.description === false ? {} : { descriptionKey: `form.${name}.description` },
|
|
30
|
-
...options.placeholder === false ? {} : { placeholderKey: `form.${name}.placeholder` },
|
|
31
|
-
...name === "binaryPath" ? { control: options.control ?? "executable-path" } : {},
|
|
32
|
-
...name === "homePath" || options.machineLocal ? { machineLocal: true } : {}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
16
|
// src/card.ts
|
|
17
|
+
import {
|
|
18
|
+
executorProgramField,
|
|
19
|
+
executorEnvelopeFields
|
|
20
|
+
} from "@ycodium-ai/plugin-api/instance-config";
|
|
38
21
|
var CLAUDE_DRIVER_KIND = "claudeAgent";
|
|
39
22
|
var CLAUDE_CARD = {
|
|
40
23
|
driverKind: CLAUDE_DRIVER_KIND,
|
|
@@ -209,81 +192,24 @@ var CLAUDE_CARD = {
|
|
|
209
192
|
};
|
|
210
193
|
|
|
211
194
|
// src/claudeAccount.ts
|
|
212
|
-
import * as NodeOS3 from "node:os";
|
|
213
|
-
import * as NodePath3 from "node:path";
|
|
214
|
-
|
|
215
|
-
// ../../packages/ycodium-credential-account/src/credentialAccount.ts
|
|
216
|
-
import * as NodeFS from "node:fs";
|
|
217
|
-
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
218
|
-
var parseJsonRecord = (raw) => {
|
|
219
|
-
let parsed;
|
|
220
|
-
try {
|
|
221
|
-
parsed = JSON.parse(raw);
|
|
222
|
-
} catch {
|
|
223
|
-
return void 0;
|
|
224
|
-
}
|
|
225
|
-
return isRecord(parsed) ? parsed : void 0;
|
|
226
|
-
};
|
|
227
|
-
var directoryExists = (homePath) => {
|
|
228
|
-
try {
|
|
229
|
-
return NodeFS.statSync(homePath).isDirectory();
|
|
230
|
-
} catch {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
var readCredentialFile = (path) => {
|
|
235
|
-
try {
|
|
236
|
-
return NodeFS.readFileSync(path, "utf8");
|
|
237
|
-
} catch {
|
|
238
|
-
return void 0;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
var accountWithoutIdentity = (state, exists) => ({
|
|
242
|
-
state,
|
|
243
|
-
directoryExists: exists,
|
|
244
|
-
email: void 0,
|
|
245
|
-
name: void 0,
|
|
246
|
-
expiresAt: void 0
|
|
247
|
-
});
|
|
248
|
-
var epochMillisToIso = (value) => {
|
|
249
|
-
if (value === void 0 || !Number.isFinite(value)) return void 0;
|
|
250
|
-
const date = new Date(value);
|
|
251
|
-
return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
// ../../packages/ycodium-instance-config/src/homePath.ts
|
|
255
|
-
import * as NodeOS from "node:os";
|
|
256
|
-
import * as NodePath from "node:path";
|
|
257
|
-
import {
|
|
258
|
-
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
259
|
-
executorHomeEffectiveValue,
|
|
260
|
-
readExecutorEffectiveRequest,
|
|
261
|
-
mergeLaunchEnv
|
|
262
|
-
} from "@ycodium-ai/plugin-api/executor";
|
|
263
|
-
function expandHomePath(value) {
|
|
264
|
-
if (value === "~") return NodeOS.homedir();
|
|
265
|
-
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
266
|
-
return NodePath.join(NodeOS.homedir(), value.slice(2));
|
|
267
|
-
}
|
|
268
|
-
return value;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// src/claudeHome.ts
|
|
272
195
|
import * as NodeOS2 from "node:os";
|
|
273
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";
|
|
274
205
|
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
const hours = Math.floor(totalMinutes % (24 * 60) / 60);
|
|
280
|
-
const minutes = totalMinutes % 60;
|
|
281
|
-
if (days > 0) return hours === 0 ? `${String(days)}d` : `${String(days)}d ${String(hours)}h`;
|
|
282
|
-
if (hours === 0) return `${String(totalMinutes)}m`;
|
|
283
|
-
return minutes === 0 ? `${String(hours)}h` : `${String(hours)}h ${String(minutes)}m`;
|
|
284
|
-
}
|
|
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";
|
|
285
210
|
|
|
286
211
|
// src/usageLimit.ts
|
|
212
|
+
import { formatCoarseWait } from "@ycodium-ai/plugin-api/display-format";
|
|
287
213
|
var WINDOW_NAMES = {
|
|
288
214
|
five_hour: "5-hour",
|
|
289
215
|
seven_day: "7-day",
|
|
@@ -325,7 +251,7 @@ var describeUsageLimitFailure = (rejected, nowMs) => {
|
|
|
325
251
|
var CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE = "CLAUDE_SECURESTORAGE_CONFIG_DIR";
|
|
326
252
|
function resolveClaudeHomePath(homePath) {
|
|
327
253
|
const trimmed = homePath.trim();
|
|
328
|
-
return
|
|
254
|
+
return NodePath.resolve(trimmed.length > 0 ? expandHomePath(trimmed) : NodeOS.homedir());
|
|
329
255
|
}
|
|
330
256
|
function claudeContinuationKey(homePath) {
|
|
331
257
|
return `claude:home:${resolveClaudeHomePath(homePath)}`;
|
|
@@ -333,18 +259,18 @@ function claudeContinuationKey(homePath) {
|
|
|
333
259
|
function resolveClaudeConfigDirPath(homePath, environment, cwd) {
|
|
334
260
|
const trimmed = homePath.trim();
|
|
335
261
|
if (trimmed.length > 0) {
|
|
336
|
-
return
|
|
262
|
+
return NodePath.resolve(expandHomePath(trimmed));
|
|
337
263
|
}
|
|
338
264
|
const environmentConfigDir = environment.CLAUDE_CONFIG_DIR?.trim() ?? "";
|
|
339
265
|
if (environmentConfigDir.length > 0) {
|
|
340
|
-
return cwd ?
|
|
266
|
+
return cwd ? NodePath.resolve(cwd, environmentConfigDir) : NodePath.resolve(environmentConfigDir);
|
|
341
267
|
}
|
|
342
|
-
return
|
|
268
|
+
return NodePath.join(NodeOS.homedir(), ".claude");
|
|
343
269
|
}
|
|
344
270
|
function resolveClaudeCredentialsDirPath(credentialsPath) {
|
|
345
271
|
const trimmed = credentialsPath.trim();
|
|
346
272
|
if (trimmed.length === 0) return null;
|
|
347
|
-
return
|
|
273
|
+
return NodePath.resolve(expandHomePath(trimmed));
|
|
348
274
|
}
|
|
349
275
|
function resolveClaudeHomeLayout(input) {
|
|
350
276
|
return {
|
|
@@ -375,13 +301,13 @@ function claudeSignedOutMessage(input) {
|
|
|
375
301
|
const configDir = input.configDir?.trim() ?? "";
|
|
376
302
|
if (configDir.length > 0) {
|
|
377
303
|
variables.push(
|
|
378
|
-
`CLAUDE_CONFIG_DIR set to ${quoteLiteral(
|
|
304
|
+
`CLAUDE_CONFIG_DIR set to ${quoteLiteral(NodePath.resolve(input.cwd, configDir))}`
|
|
379
305
|
);
|
|
380
306
|
}
|
|
381
307
|
const credentialsDir = input.credentialsDir?.trim() ?? "";
|
|
382
308
|
if (credentialsDir.length > 0) {
|
|
383
309
|
variables.push(
|
|
384
|
-
`${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(
|
|
310
|
+
`${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(NodePath.resolve(input.cwd, credentialsDir))}`
|
|
385
311
|
);
|
|
386
312
|
}
|
|
387
313
|
const withVariables = variables.length > 0 ? `, with ${variables.join(" and ")}` : "";
|
|
@@ -411,19 +337,19 @@ function claudeFailureHint(input) {
|
|
|
411
337
|
// src/claudeAccount.ts
|
|
412
338
|
var OAUTH_KEY = "claudeAiOauth";
|
|
413
339
|
function resolveClaudeAccountDirectory(credentialsDirPath) {
|
|
414
|
-
return credentialsDirPath ??
|
|
340
|
+
return credentialsDirPath ?? NodePath2.join(NodeOS2.homedir(), ".claude");
|
|
415
341
|
}
|
|
416
342
|
function claudeCredentialCandidatePaths(input) {
|
|
417
343
|
return input.credentialsDirPath === null ? [
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
] : [
|
|
344
|
+
NodePath2.join(input.homePath, ".claude", ".credentials.json"),
|
|
345
|
+
NodePath2.join(input.homePath, ".credentials.json")
|
|
346
|
+
] : [NodePath2.join(input.credentialsDirPath, ".credentials.json")];
|
|
421
347
|
}
|
|
422
348
|
function readClaudeAccount(credentialsDirPath, credentialCandidates) {
|
|
423
349
|
const accountDirectory = resolveClaudeAccountDirectory(credentialsDirPath);
|
|
424
350
|
const exists = directoryExists(accountDirectory);
|
|
425
351
|
const candidates = credentialCandidates ?? claudeCredentialCandidatePaths({
|
|
426
|
-
homePath:
|
|
352
|
+
homePath: NodeOS2.homedir(),
|
|
427
353
|
credentialsDirPath
|
|
428
354
|
});
|
|
429
355
|
let raw;
|
|
@@ -459,1431 +385,14 @@ var probeClaudeAccount = (accountPath) => {
|
|
|
459
385
|
};
|
|
460
386
|
|
|
461
387
|
// src/liveHistory.ts
|
|
462
|
-
import * as
|
|
463
|
-
import * as NodeProcess2 from "node:process";
|
|
464
|
-
|
|
465
|
-
// ../../packages/ycodium-jsonl-stream/src/historyErrors.ts
|
|
466
|
-
var NativeHistoryCursorError = class extends Error {
|
|
467
|
-
name = "NativeHistoryCursorError";
|
|
468
|
-
};
|
|
469
|
-
var NativeHistoryPendingError = class extends Error {
|
|
470
|
-
name = "NativeHistoryPendingError";
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
// ../../packages/ycodium-jsonl-stream/src/historyWaiting.ts
|
|
474
|
-
import * as NodeFS2 from "node:fs";
|
|
475
|
-
import * as NodeFSP from "node:fs/promises";
|
|
476
|
-
import * as NodePath4 from "node:path";
|
|
477
|
-
var pending = (error) => error instanceof NativeHistoryPendingError || error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
|
|
478
|
-
var waitForJsonlHistory = (input) => {
|
|
479
|
-
const controller = new AbortController();
|
|
480
|
-
const sources = /* @__PURE__ */ new Set();
|
|
481
|
-
const operations = /* @__PURE__ */ new Set();
|
|
482
|
-
const own = (promise) => {
|
|
483
|
-
operations.add(promise);
|
|
484
|
-
void promise.finally(() => operations.delete(promise)).catch(() => void 0);
|
|
485
|
-
return promise;
|
|
486
|
-
};
|
|
487
|
-
const iterators = /* @__PURE__ */ new Set();
|
|
488
|
-
const open2 = () => own(
|
|
489
|
-
(async () => {
|
|
490
|
-
const signal = AbortSignal.any([
|
|
491
|
-
controller.signal,
|
|
492
|
-
...input.signal ? [input.signal] : []
|
|
493
|
-
]);
|
|
494
|
-
const source = await input.open(signal);
|
|
495
|
-
if (source === void 0) throw new NativeHistoryPendingError();
|
|
496
|
-
sources.add(source);
|
|
497
|
-
return source;
|
|
498
|
-
})()
|
|
499
|
-
);
|
|
500
|
-
const release = async (source) => {
|
|
501
|
-
await source.close();
|
|
502
|
-
sources.delete(source);
|
|
503
|
-
};
|
|
504
|
-
return {
|
|
505
|
-
page: (options) => own(
|
|
506
|
-
(async () => {
|
|
507
|
-
const source = await open2();
|
|
508
|
-
try {
|
|
509
|
-
return await source.page(options);
|
|
510
|
-
} finally {
|
|
511
|
-
await release(source);
|
|
512
|
-
}
|
|
513
|
-
})()
|
|
514
|
-
),
|
|
515
|
-
follow: (options) => {
|
|
516
|
-
let iterator;
|
|
517
|
-
iterator = (async function* () {
|
|
518
|
-
const signal = AbortSignal.any([
|
|
519
|
-
controller.signal,
|
|
520
|
-
...input.signal ? [input.signal] : [],
|
|
521
|
-
...options.signal ? [options.signal] : []
|
|
522
|
-
]);
|
|
523
|
-
let root = NodePath4.resolve(input.root);
|
|
524
|
-
while (true) {
|
|
525
|
-
try {
|
|
526
|
-
if ((await NodeFSP.stat(root)).isDirectory()) break;
|
|
527
|
-
} catch (error2) {
|
|
528
|
-
if (!pending(error2)) throw error2;
|
|
529
|
-
}
|
|
530
|
-
const parent = NodePath4.dirname(root);
|
|
531
|
-
if (parent === root) throw new NativeHistoryPendingError();
|
|
532
|
-
root = parent;
|
|
533
|
-
}
|
|
534
|
-
let dirty = true;
|
|
535
|
-
let wake;
|
|
536
|
-
let error;
|
|
537
|
-
const notify = () => {
|
|
538
|
-
dirty = true;
|
|
539
|
-
wake?.();
|
|
540
|
-
wake = void 0;
|
|
541
|
-
};
|
|
542
|
-
const watcher = NodeFS2.watch(root, { recursive: true, signal }, (_event, name) => {
|
|
543
|
-
if (name == null || input.accepts(NodePath4.resolve(root, String(name)))) notify();
|
|
544
|
-
});
|
|
545
|
-
watcher.on("error", (cause) => {
|
|
546
|
-
error = cause;
|
|
547
|
-
notify();
|
|
548
|
-
});
|
|
549
|
-
signal.addEventListener("abort", notify, { once: true });
|
|
550
|
-
let announced = false;
|
|
551
|
-
try {
|
|
552
|
-
while (true) {
|
|
553
|
-
signal.throwIfAborted();
|
|
554
|
-
if (error !== void 0) throw error;
|
|
555
|
-
if (!dirty)
|
|
556
|
-
await new Promise((resolve7) => {
|
|
557
|
-
wake = resolve7;
|
|
558
|
-
});
|
|
559
|
-
signal.throwIfAborted();
|
|
560
|
-
dirty = false;
|
|
561
|
-
let source;
|
|
562
|
-
try {
|
|
563
|
-
source = await open2();
|
|
564
|
-
} catch (cause) {
|
|
565
|
-
if (!pending(cause)) throw cause;
|
|
566
|
-
if (!announced) {
|
|
567
|
-
announced = true;
|
|
568
|
-
yield { _tag: "unavailable", reason: "native-session-unavailable" };
|
|
569
|
-
yield { _tag: "synchronized" };
|
|
570
|
-
}
|
|
571
|
-
continue;
|
|
572
|
-
}
|
|
573
|
-
announced = false;
|
|
574
|
-
try {
|
|
575
|
-
for await (const frame of source.follow({ ...options, signal })) yield frame;
|
|
576
|
-
} catch (cause) {
|
|
577
|
-
if (!pending(cause)) throw cause;
|
|
578
|
-
} finally {
|
|
579
|
-
await release(source);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
} finally {
|
|
583
|
-
watcher.close();
|
|
584
|
-
signal.removeEventListener("abort", notify);
|
|
585
|
-
wake?.();
|
|
586
|
-
if (iterator !== void 0) iterators.delete(iterator);
|
|
587
|
-
}
|
|
588
|
-
})();
|
|
589
|
-
iterators.add(iterator);
|
|
590
|
-
return iterator;
|
|
591
|
-
},
|
|
592
|
-
close: async () => {
|
|
593
|
-
controller.abort();
|
|
594
|
-
await Promise.all([...sources].map(release));
|
|
595
|
-
await Promise.all([...iterators].map((iterator) => iterator.return(void 0)));
|
|
596
|
-
await Promise.allSettled(operations);
|
|
597
|
-
}
|
|
598
|
-
};
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
// ../../packages/ycodium-jsonl-stream/src/history.ts
|
|
602
|
-
import * as NodeFS3 from "node:fs";
|
|
603
|
-
import * as NodePath5 from "node:path";
|
|
604
|
-
|
|
605
|
-
// ../../packages/ycodium-jsonl-stream/src/historyFile.ts
|
|
606
|
-
import * as NodeFSP2 from "node:fs/promises";
|
|
607
|
-
import * as NodeCrypto from "node:crypto";
|
|
608
|
-
var HISTORY_READ_BYTES = 65536;
|
|
609
|
-
async function* historyBytes(path, start, end, signal) {
|
|
610
|
-
const file = await NodeFSP2.open(path, "r");
|
|
611
|
-
try {
|
|
612
|
-
let offset = start;
|
|
613
|
-
while (offset < end) {
|
|
614
|
-
signal?.throwIfAborted();
|
|
615
|
-
const buffer = Buffer.allocUnsafe(Math.min(HISTORY_READ_BYTES, end - offset));
|
|
616
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, offset);
|
|
617
|
-
if (bytesRead === 0) throw new Error("Native history changed during a read.");
|
|
618
|
-
offset += bytesRead;
|
|
619
|
-
yield buffer.subarray(0, bytesRead);
|
|
620
|
-
}
|
|
621
|
-
} finally {
|
|
622
|
-
await file.close();
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
async function* historyText(path, range, signal) {
|
|
626
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
627
|
-
for await (const bytes of historyBytes(path, range.start, range.end, signal)) {
|
|
628
|
-
const text2 = decoder.decode(bytes, { stream: true });
|
|
629
|
-
if (text2) yield text2;
|
|
630
|
-
}
|
|
631
|
-
const last = decoder.decode();
|
|
632
|
-
if (last) yield last;
|
|
633
|
-
}
|
|
634
|
-
async function* historyLines(path, start, end, backwards, signal) {
|
|
635
|
-
if (!backwards) {
|
|
636
|
-
let lineStart = start;
|
|
637
|
-
let offset = start;
|
|
638
|
-
for await (const bytes of historyBytes(path, start, end, signal)) {
|
|
639
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
640
|
-
if (bytes[index] !== 10) continue;
|
|
641
|
-
const lineEnd = offset + index;
|
|
642
|
-
if (lineEnd > lineStart)
|
|
643
|
-
yield { start: lineStart, end: lineEnd, commit: lineEnd + 1, terminated: true };
|
|
644
|
-
lineStart = lineEnd + 1;
|
|
645
|
-
}
|
|
646
|
-
offset += bytes.length;
|
|
647
|
-
}
|
|
648
|
-
if (lineStart < end) yield { start: lineStart, end, commit: end, terminated: false };
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
const file = await NodeFSP2.open(path, "r");
|
|
652
|
-
try {
|
|
653
|
-
let scan = end;
|
|
654
|
-
let lineEnd = end;
|
|
655
|
-
let terminated = false;
|
|
656
|
-
while (scan > start) {
|
|
657
|
-
signal?.throwIfAborted();
|
|
658
|
-
const from = Math.max(start, scan - HISTORY_READ_BYTES);
|
|
659
|
-
const buffer = Buffer.allocUnsafe(scan - from);
|
|
660
|
-
const { bytesRead } = await file.read(buffer, 0, buffer.length, from);
|
|
661
|
-
if (bytesRead !== buffer.length) throw new Error("Native history changed during a read.");
|
|
662
|
-
for (let index = buffer.length - 1; index >= 0; index -= 1) {
|
|
663
|
-
if (buffer[index] !== 10) continue;
|
|
664
|
-
const at2 = from + index;
|
|
665
|
-
if (at2 + 1 < lineEnd)
|
|
666
|
-
yield { start: at2 + 1, end: lineEnd, commit: lineEnd + (terminated ? 1 : 0), terminated };
|
|
667
|
-
lineEnd = at2;
|
|
668
|
-
terminated = true;
|
|
669
|
-
}
|
|
670
|
-
scan = from;
|
|
671
|
-
}
|
|
672
|
-
if (lineEnd > start)
|
|
673
|
-
yield { start, end: lineEnd, commit: lineEnd + (terminated ? 1 : 0), terminated };
|
|
674
|
-
} finally {
|
|
675
|
-
await file.close();
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
var historyIdentity = async (path) => {
|
|
679
|
-
const stat5 = await NodeFSP2.stat(path);
|
|
680
|
-
return {
|
|
681
|
-
size: stat5.size,
|
|
682
|
-
mtimeMs: stat5.mtimeMs,
|
|
683
|
-
ctimeMs: stat5.ctimeMs,
|
|
684
|
-
identity: NodeCrypto.createHash("sha256").update(`${path}/${stat5.dev}/${stat5.ino}/${stat5.birthtimeMs}`).digest("hex")
|
|
685
|
-
};
|
|
686
|
-
};
|
|
687
|
-
var historyCommittedFingerprint = async (path, sequence, signal) => {
|
|
688
|
-
const hash = NodeCrypto.createHash("sha256");
|
|
689
|
-
const starts = [
|
|
690
|
-
0,
|
|
691
|
-
Math.max(0, Math.floor(sequence / 3) - 512),
|
|
692
|
-
Math.max(0, Math.floor(sequence * 2 / 3) - 512),
|
|
693
|
-
Math.max(0, sequence - 1024)
|
|
694
|
-
];
|
|
695
|
-
for (const start of new Set(starts)) {
|
|
696
|
-
const end = Math.min(sequence, start + 1024);
|
|
697
|
-
hash.update(`${start}:${end}:`);
|
|
698
|
-
for await (const bytes of historyBytes(path, start, end, signal)) hash.update(bytes);
|
|
699
|
-
}
|
|
700
|
-
return hash.digest("hex");
|
|
701
|
-
};
|
|
702
|
-
var historyBoundary = async (path, identity, sequence, signal) => {
|
|
703
|
-
const hash = NodeCrypto.createHash("sha256");
|
|
704
|
-
for await (const bytes of historyBytes(path, Math.max(0, sequence - 128), sequence, signal))
|
|
705
|
-
hash.update(bytes);
|
|
706
|
-
hash.update(await historyCommittedFingerprint(path, sequence, signal));
|
|
707
|
-
return { epoch: `${identity}.${hash.digest("hex")}`, sequence };
|
|
708
|
-
};
|
|
709
|
-
|
|
710
|
-
// ../../packages/ycodium-jsonl-stream/src/historyRecord.ts
|
|
711
|
-
import * as NodeCrypto2 from "node:crypto";
|
|
712
|
-
|
|
713
|
-
// ../../packages/ycodium-jsonl-stream/src/jsonlStream.ts
|
|
714
|
-
var DEFAULT_MAX_RETAINED_CHARS = 8e6;
|
|
715
|
-
var MAX_DEPTH = 128;
|
|
716
|
-
var MAX_KEY_CHARS = 256;
|
|
717
|
-
var MAX_BARE_CHARS = 64;
|
|
718
|
-
var NUMBER_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u;
|
|
719
|
-
var OversizedRecordParser = class {
|
|
720
|
-
#fields;
|
|
721
|
-
#budget;
|
|
722
|
-
#options;
|
|
723
|
-
#retained = 0;
|
|
724
|
-
#malformed = false;
|
|
725
|
-
#done = false;
|
|
726
|
-
#result = void 0;
|
|
727
|
-
#stack = [];
|
|
728
|
-
// 词法状态。
|
|
729
|
-
#inString = false;
|
|
730
|
-
#stringIsKey = false;
|
|
731
|
-
#escape = false;
|
|
732
|
-
#unicodeLeft = 0;
|
|
733
|
-
#unicodeValue = 0;
|
|
734
|
-
#bare = "";
|
|
735
|
-
// 当前字符串的保留规则与累积。
|
|
736
|
-
#strObserver;
|
|
737
|
-
#strRetain = false;
|
|
738
|
-
#strCap = void 0;
|
|
739
|
-
#strHead = "";
|
|
740
|
-
#strTail = "";
|
|
741
|
-
#strLength = 0;
|
|
742
|
-
#key = "";
|
|
743
|
-
#keyOverflow = false;
|
|
744
|
-
// 值之间的位置。
|
|
745
|
-
#expectKey = false;
|
|
746
|
-
#expectColon = false;
|
|
747
|
-
#expectComma = false;
|
|
748
|
-
#expectValue = true;
|
|
749
|
-
constructor(fields, maxRetainedChars = DEFAULT_MAX_RETAINED_CHARS, options) {
|
|
750
|
-
this.#fields = fields;
|
|
751
|
-
this.#budget = maxRetainedChars;
|
|
752
|
-
this.#options = options;
|
|
753
|
-
}
|
|
754
|
-
write(chunk) {
|
|
755
|
-
if (this.#malformed) return;
|
|
756
|
-
try {
|
|
757
|
-
this.#consume(chunk);
|
|
758
|
-
} catch (cause) {
|
|
759
|
-
if (cause instanceof MalformedRecord) {
|
|
760
|
-
this.#malformed = true;
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
throw cause;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
/** 完整且合法才返回记录;其余(含空行)返回 `undefined`。 */
|
|
767
|
-
finish() {
|
|
768
|
-
if (this.#malformed) return void 0;
|
|
769
|
-
try {
|
|
770
|
-
if (this.#bare.length > 0) this.#finishBare();
|
|
771
|
-
} catch (cause) {
|
|
772
|
-
if (cause instanceof MalformedRecord) return void 0;
|
|
773
|
-
throw cause;
|
|
774
|
-
}
|
|
775
|
-
if (!this.#done || this.#inString || this.#result === SKIPPED) return void 0;
|
|
776
|
-
return this.#result;
|
|
777
|
-
}
|
|
778
|
-
#fail() {
|
|
779
|
-
throw new MalformedRecord();
|
|
780
|
-
}
|
|
781
|
-
#charge(chars) {
|
|
782
|
-
this.#retained += chars;
|
|
783
|
-
if (this.#retained > this.#budget) this.#fail();
|
|
784
|
-
}
|
|
785
|
-
#consume(chunk) {
|
|
786
|
-
const n = chunk.length;
|
|
787
|
-
let i = 0;
|
|
788
|
-
while (i < n) {
|
|
789
|
-
if (this.#inString) {
|
|
790
|
-
i = this.#consumeString(chunk, i);
|
|
791
|
-
continue;
|
|
792
|
-
}
|
|
793
|
-
const c = chunk.charCodeAt(i);
|
|
794
|
-
if (this.#bare.length > 0) {
|
|
795
|
-
if (isBareChar(c)) {
|
|
796
|
-
if (this.#bare.length >= MAX_BARE_CHARS) this.#fail();
|
|
797
|
-
this.#bare += chunk[i];
|
|
798
|
-
i += 1;
|
|
799
|
-
continue;
|
|
800
|
-
}
|
|
801
|
-
this.#finishBare();
|
|
802
|
-
}
|
|
803
|
-
i += 1;
|
|
804
|
-
if (c === 32 || c === 9 || c === 10 || c === 13) continue;
|
|
805
|
-
if (this.#done) this.#fail();
|
|
806
|
-
switch (c) {
|
|
807
|
-
case 123:
|
|
808
|
-
this.#requireValue();
|
|
809
|
-
this.#openContainer(false);
|
|
810
|
-
break;
|
|
811
|
-
case 91:
|
|
812
|
-
this.#requireValue();
|
|
813
|
-
this.#openContainer(true);
|
|
814
|
-
break;
|
|
815
|
-
case 125:
|
|
816
|
-
this.#closeContainer(false);
|
|
817
|
-
break;
|
|
818
|
-
case 93:
|
|
819
|
-
this.#closeContainer(true);
|
|
820
|
-
break;
|
|
821
|
-
case 44:
|
|
822
|
-
this.#comma();
|
|
823
|
-
break;
|
|
824
|
-
case 58:
|
|
825
|
-
if (!this.#expectColon) this.#fail();
|
|
826
|
-
this.#expectColon = false;
|
|
827
|
-
this.#expectValue = true;
|
|
828
|
-
break;
|
|
829
|
-
case 34:
|
|
830
|
-
this.#openString();
|
|
831
|
-
break;
|
|
832
|
-
default:
|
|
833
|
-
if (isBareChar(c)) {
|
|
834
|
-
this.#requireValue();
|
|
835
|
-
this.#bare = chunk[i - 1] ?? "";
|
|
836
|
-
} else this.#fail();
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
#top() {
|
|
841
|
-
return this.#stack[this.#stack.length - 1];
|
|
842
|
-
}
|
|
843
|
-
#requireValue() {
|
|
844
|
-
if (!this.#expectValue) this.#fail();
|
|
845
|
-
this.#expectValue = false;
|
|
846
|
-
}
|
|
847
|
-
/** 当前要读的值(刚要开始)落在什么模式;`isContainer` 决定 scalarOnly 清单项是否适用。 */
|
|
848
|
-
#childMode(isContainer) {
|
|
849
|
-
const parent = this.#top();
|
|
850
|
-
if (parent === void 0) return this.#classify([], isContainer);
|
|
851
|
-
if (parent.mode === "skip") return { mode: "skip", cap: void 0, path: [] };
|
|
852
|
-
if (parent.mode === "keep") return { mode: "keep", cap: parent.cap, path: [] };
|
|
853
|
-
const segment = parent.isArray ? String(parent.index) : parent.key ?? "";
|
|
854
|
-
if (parent.skipValue) return { mode: "skip", cap: void 0, path: [] };
|
|
855
|
-
return this.#classify([...parent.path, segment], isContainer);
|
|
856
|
-
}
|
|
857
|
-
#classify(path, isContainer) {
|
|
858
|
-
let descend = false;
|
|
859
|
-
for (const field of this.#fields) {
|
|
860
|
-
const fieldPath = field.path;
|
|
861
|
-
if (fieldPath.length <= path.length) {
|
|
862
|
-
if (field.scalarOnly === true && (isContainer || fieldPath.length !== path.length)) {
|
|
863
|
-
continue;
|
|
864
|
-
}
|
|
865
|
-
if (matchesPrefix(fieldPath, path, fieldPath.length)) {
|
|
866
|
-
return { mode: "keep", cap: field.maxChars, path };
|
|
867
|
-
}
|
|
868
|
-
} else if (matchesPrefix(fieldPath, path, path.length)) {
|
|
869
|
-
descend = true;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
return { mode: descend ? "descend" : "skip", cap: void 0, path };
|
|
873
|
-
}
|
|
874
|
-
#openContainer(isArray) {
|
|
875
|
-
if (this.#stack.length >= MAX_DEPTH) this.#fail();
|
|
876
|
-
const { mode, cap, path } = this.#childMode(true);
|
|
877
|
-
const keeping = mode !== "skip";
|
|
878
|
-
let target = null;
|
|
879
|
-
if (keeping) {
|
|
880
|
-
this.#charge(16);
|
|
881
|
-
target = isArray ? [] : {};
|
|
882
|
-
}
|
|
883
|
-
this.#stack.push({ isArray, mode, path, cap, target, key: null, skipValue: false, index: 0 });
|
|
884
|
-
this.#expectValue = isArray;
|
|
885
|
-
this.#expectKey = !isArray;
|
|
886
|
-
this.#expectComma = false;
|
|
887
|
-
this.#expectColon = false;
|
|
888
|
-
}
|
|
889
|
-
#closeContainer(isArray) {
|
|
890
|
-
const top = this.#top();
|
|
891
|
-
if (top === void 0 || top.isArray !== isArray) this.#fail();
|
|
892
|
-
if (!this.#expectComma && top.index > 0) this.#fail();
|
|
893
|
-
if (this.#expectColon || !isArray && this.#expectValue) this.#fail();
|
|
894
|
-
this.#stack.pop();
|
|
895
|
-
this.#expectValue = false;
|
|
896
|
-
this.#expectKey = false;
|
|
897
|
-
this.#expectColon = false;
|
|
898
|
-
this.#expectComma = true;
|
|
899
|
-
const empty = top.target !== null && Object.keys(top.target).length === 0;
|
|
900
|
-
this.#store(
|
|
901
|
-
this.#options?.pruneEmpty && top.mode === "descend" && empty && this.#stack.length > 0 ? SKIPPED : top.target ?? SKIPPED
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
#comma() {
|
|
905
|
-
const top = this.#top();
|
|
906
|
-
if (top === void 0 || !this.#expectComma) this.#fail();
|
|
907
|
-
this.#expectComma = false;
|
|
908
|
-
if (top.isArray) {
|
|
909
|
-
this.#expectValue = true;
|
|
910
|
-
} else {
|
|
911
|
-
this.#expectKey = true;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
/** 一个值读完:交给外层容器,或成为整条记录。 */
|
|
915
|
-
#store(value) {
|
|
916
|
-
const parent = this.#top();
|
|
917
|
-
if (parent === void 0) {
|
|
918
|
-
this.#result = value;
|
|
919
|
-
this.#done = true;
|
|
920
|
-
this.#expectComma = false;
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
this.#expectComma = true;
|
|
924
|
-
if (parent.isArray) {
|
|
925
|
-
parent.index += 1;
|
|
926
|
-
if (parent.target !== null && value !== SKIPPED) {
|
|
927
|
-
parent.target.push(value);
|
|
928
|
-
this.#charge(8);
|
|
929
|
-
}
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
parent.index += 1;
|
|
933
|
-
const key = parent.key;
|
|
934
|
-
parent.key = null;
|
|
935
|
-
parent.skipValue = false;
|
|
936
|
-
if (parent.target !== null && value !== SKIPPED && key !== null) {
|
|
937
|
-
Object.defineProperty(parent.target, key, {
|
|
938
|
-
value,
|
|
939
|
-
enumerable: true,
|
|
940
|
-
writable: true,
|
|
941
|
-
configurable: true
|
|
942
|
-
});
|
|
943
|
-
this.#charge(key.length + 8);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
#openString() {
|
|
947
|
-
const parent = this.#top();
|
|
948
|
-
const asKey = parent !== void 0 && !parent.isArray && this.#expectKey;
|
|
949
|
-
if (!asKey) this.#requireValue();
|
|
950
|
-
this.#inString = true;
|
|
951
|
-
this.#stringIsKey = asKey;
|
|
952
|
-
this.#escape = false;
|
|
953
|
-
this.#unicodeLeft = 0;
|
|
954
|
-
this.#strLength = 0;
|
|
955
|
-
this.#strHead = "";
|
|
956
|
-
this.#strTail = "";
|
|
957
|
-
this.#key = "";
|
|
958
|
-
if (asKey) {
|
|
959
|
-
this.#keyOverflow = false;
|
|
960
|
-
this.#strRetain = true;
|
|
961
|
-
this.#strCap = void 0;
|
|
962
|
-
return;
|
|
963
|
-
}
|
|
964
|
-
const { mode, cap, path } = this.#childMode(false);
|
|
965
|
-
this.#strObserver = this.#fields.find(
|
|
966
|
-
(field) => field.path.length === path.length && matchesPrefix(field.path, path, path.length)
|
|
967
|
-
);
|
|
968
|
-
this.#strRetain = mode === "keep" && this.#strObserver?.onChunk === void 0;
|
|
969
|
-
this.#strCap = cap;
|
|
970
|
-
}
|
|
971
|
-
/** 字符串里的一个解码后片段;按保留规则累积。 */
|
|
972
|
-
#append(text2) {
|
|
973
|
-
if (text2.length === 0) return;
|
|
974
|
-
if (this.#stringIsKey) {
|
|
975
|
-
if (this.#keyOverflow) return;
|
|
976
|
-
this.#key += text2;
|
|
977
|
-
if (this.#key.length > MAX_KEY_CHARS) {
|
|
978
|
-
this.#keyOverflow = true;
|
|
979
|
-
this.#key = "";
|
|
980
|
-
}
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
|
-
this.#strLength += text2.length;
|
|
984
|
-
this.#strObserver?.onChunk?.(text2);
|
|
985
|
-
if (!this.#strRetain) return;
|
|
986
|
-
const cap = this.#strCap;
|
|
987
|
-
if (cap === void 0) {
|
|
988
|
-
this.#strHead += text2;
|
|
989
|
-
this.#charge(text2.length);
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
if (this.#strHead.length < cap) {
|
|
993
|
-
const room = cap - this.#strHead.length;
|
|
994
|
-
this.#strHead += text2.slice(0, room);
|
|
995
|
-
text2 = text2.slice(room);
|
|
996
|
-
if (text2.length === 0) return;
|
|
997
|
-
}
|
|
998
|
-
this.#strTail += text2;
|
|
999
|
-
if (this.#strTail.length > cap * 2) this.#strTail = this.#strTail.slice(-cap);
|
|
1000
|
-
}
|
|
1001
|
-
#consumeString(chunk, start) {
|
|
1002
|
-
const n = chunk.length;
|
|
1003
|
-
let i = start;
|
|
1004
|
-
while (i < n) {
|
|
1005
|
-
if (this.#unicodeLeft > 0) {
|
|
1006
|
-
const digit = hexValue(chunk.charCodeAt(i));
|
|
1007
|
-
if (digit < 0) this.#fail();
|
|
1008
|
-
this.#unicodeValue = this.#unicodeValue * 16 + digit;
|
|
1009
|
-
this.#unicodeLeft -= 1;
|
|
1010
|
-
i += 1;
|
|
1011
|
-
if (this.#unicodeLeft === 0) this.#append(String.fromCharCode(this.#unicodeValue));
|
|
1012
|
-
continue;
|
|
1013
|
-
}
|
|
1014
|
-
if (this.#escape) {
|
|
1015
|
-
this.#escape = false;
|
|
1016
|
-
const c3 = chunk[i] ?? "";
|
|
1017
|
-
i += 1;
|
|
1018
|
-
switch (c3) {
|
|
1019
|
-
case '"':
|
|
1020
|
-
case "\\":
|
|
1021
|
-
case "/":
|
|
1022
|
-
this.#append(c3);
|
|
1023
|
-
break;
|
|
1024
|
-
case "b":
|
|
1025
|
-
this.#append("\b");
|
|
1026
|
-
break;
|
|
1027
|
-
case "f":
|
|
1028
|
-
this.#append("\f");
|
|
1029
|
-
break;
|
|
1030
|
-
case "n":
|
|
1031
|
-
this.#append("\n");
|
|
1032
|
-
break;
|
|
1033
|
-
case "r":
|
|
1034
|
-
this.#append("\r");
|
|
1035
|
-
break;
|
|
1036
|
-
case "t":
|
|
1037
|
-
this.#append(" ");
|
|
1038
|
-
break;
|
|
1039
|
-
case "u":
|
|
1040
|
-
this.#unicodeLeft = 4;
|
|
1041
|
-
this.#unicodeValue = 0;
|
|
1042
|
-
break;
|
|
1043
|
-
default:
|
|
1044
|
-
this.#fail();
|
|
1045
|
-
}
|
|
1046
|
-
continue;
|
|
1047
|
-
}
|
|
1048
|
-
const runStart = i;
|
|
1049
|
-
while (i < n) {
|
|
1050
|
-
const c3 = chunk.charCodeAt(i);
|
|
1051
|
-
if (c3 === 34 || c3 === 92 || c3 < 32) break;
|
|
1052
|
-
i += 1;
|
|
1053
|
-
}
|
|
1054
|
-
if (i > runStart) this.#append(chunk.slice(runStart, i));
|
|
1055
|
-
if (i >= n) break;
|
|
1056
|
-
const c = chunk.charCodeAt(i);
|
|
1057
|
-
i += 1;
|
|
1058
|
-
if (c === 92) {
|
|
1059
|
-
this.#escape = true;
|
|
1060
|
-
} else if (c === 34) {
|
|
1061
|
-
this.#inString = false;
|
|
1062
|
-
this.#endString();
|
|
1063
|
-
return i;
|
|
1064
|
-
} else {
|
|
1065
|
-
this.#fail();
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
return i;
|
|
1069
|
-
}
|
|
1070
|
-
#endString() {
|
|
1071
|
-
if (this.#stringIsKey) {
|
|
1072
|
-
const parent = this.#top();
|
|
1073
|
-
if (parent === void 0) this.#fail();
|
|
1074
|
-
parent.key = this.#key;
|
|
1075
|
-
parent.skipValue = this.#keyOverflow;
|
|
1076
|
-
this.#key = "";
|
|
1077
|
-
this.#expectKey = false;
|
|
1078
|
-
this.#expectColon = true;
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
this.#strObserver?.onEnd?.(this.#strLength);
|
|
1082
|
-
this.#strObserver = void 0;
|
|
1083
|
-
if (!this.#strRetain) {
|
|
1084
|
-
this.#store(SKIPPED);
|
|
1085
|
-
return;
|
|
1086
|
-
}
|
|
1087
|
-
const cap = this.#strCap;
|
|
1088
|
-
let text2 = this.#strHead;
|
|
1089
|
-
if (cap !== void 0) {
|
|
1090
|
-
let tail = this.#strTail;
|
|
1091
|
-
if (tail.length > cap) tail = tail.slice(-cap);
|
|
1092
|
-
if (this.#strLength > text2.length + tail.length) {
|
|
1093
|
-
if (isHighSurrogate(text2.charCodeAt(text2.length - 1))) text2 = text2.slice(0, -1);
|
|
1094
|
-
if (isLowSurrogate(tail.charCodeAt(0))) tail = tail.slice(1);
|
|
1095
|
-
const omitted = this.#strLength - text2.length - tail.length;
|
|
1096
|
-
text2 = `${text2}
|
|
1097
|
-
[\u2026 ${omitted} chars omitted \u2026]
|
|
1098
|
-
${tail}`;
|
|
1099
|
-
} else {
|
|
1100
|
-
text2 = `${text2}${tail}`;
|
|
1101
|
-
}
|
|
1102
|
-
this.#charge(text2.length);
|
|
1103
|
-
}
|
|
1104
|
-
this.#strHead = "";
|
|
1105
|
-
this.#strTail = "";
|
|
1106
|
-
this.#store(text2);
|
|
1107
|
-
}
|
|
1108
|
-
#finishBare() {
|
|
1109
|
-
const text2 = this.#bare;
|
|
1110
|
-
this.#bare = "";
|
|
1111
|
-
const { mode, path } = this.#childMode(false);
|
|
1112
|
-
let value;
|
|
1113
|
-
if (text2 === "true") value = true;
|
|
1114
|
-
else if (text2 === "false") value = false;
|
|
1115
|
-
else if (text2 === "null") value = null;
|
|
1116
|
-
else if (NUMBER_PATTERN.test(text2)) value = Number(text2);
|
|
1117
|
-
else this.#fail();
|
|
1118
|
-
const observer = this.#fields.find(
|
|
1119
|
-
(field) => field.path.length === path.length && matchesPrefix(field.path, path, path.length)
|
|
1120
|
-
);
|
|
1121
|
-
if (observer?.onScalar !== void 0) {
|
|
1122
|
-
observer.onScalar(value);
|
|
1123
|
-
this.#store(SKIPPED);
|
|
1124
|
-
} else this.#store(mode === "keep" ? value : SKIPPED);
|
|
1125
|
-
}
|
|
1126
|
-
};
|
|
1127
|
-
var SKIPPED = /* @__PURE__ */ Symbol("skipped");
|
|
1128
|
-
var MalformedRecord = class extends Error {
|
|
1129
|
-
};
|
|
1130
|
-
function isBareChar(c) {
|
|
1131
|
-
return c >= 48 && c <= 57 || // 0-9
|
|
1132
|
-
c >= 97 && c <= 122 || // a-z
|
|
1133
|
-
c >= 65 && c <= 90 || // A-Z
|
|
1134
|
-
c === 43 || c === 45 || c === 46;
|
|
1135
|
-
}
|
|
1136
|
-
function hexValue(c) {
|
|
1137
|
-
if (c >= 48 && c <= 57) return c - 48;
|
|
1138
|
-
if (c >= 97 && c <= 102) return c - 97 + 10;
|
|
1139
|
-
if (c >= 65 && c <= 70) return c - 65 + 10;
|
|
1140
|
-
return -1;
|
|
1141
|
-
}
|
|
1142
|
-
var isHighSurrogate = (c) => c >= 55296 && c <= 56319;
|
|
1143
|
-
var isLowSurrogate = (c) => c >= 56320 && c <= 57343;
|
|
1144
|
-
function matchesPrefix(pattern, path, length) {
|
|
1145
|
-
for (let index = 0; index < length; index += 1) {
|
|
1146
|
-
const expected = pattern[index];
|
|
1147
|
-
if (expected !== "*" && expected !== path[index]) return false;
|
|
1148
|
-
}
|
|
1149
|
-
return true;
|
|
1150
|
-
}
|
|
1151
|
-
function jsonlEntryRecord(entry, accepts) {
|
|
1152
|
-
if ("oversized" in entry) return entry.oversized;
|
|
1153
|
-
if (!accepts(entry.line)) return void 0;
|
|
1154
|
-
try {
|
|
1155
|
-
return JSON.parse(entry.line);
|
|
1156
|
-
} catch {
|
|
1157
|
-
return void 0;
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
async function* readJsonlEntries(fs2, path, options) {
|
|
1161
|
-
const decoder = new TextDecoder("utf-8");
|
|
1162
|
-
let pieces = [];
|
|
1163
|
-
let pending2 = 0;
|
|
1164
|
-
let parser = null;
|
|
1165
|
-
const startOversized = () => {
|
|
1166
|
-
const next = new OversizedRecordParser(options.fields, options.maxRetainedChars);
|
|
1167
|
-
for (const piece of pieces) next.write(piece);
|
|
1168
|
-
pieces = [];
|
|
1169
|
-
pending2 = 0;
|
|
1170
|
-
return next;
|
|
1171
|
-
};
|
|
1172
|
-
const append = (text2) => {
|
|
1173
|
-
if (text2.length === 0) return;
|
|
1174
|
-
if (parser !== null) {
|
|
1175
|
-
parser.write(text2);
|
|
1176
|
-
return;
|
|
1177
|
-
}
|
|
1178
|
-
pieces.push(text2);
|
|
1179
|
-
pending2 += text2.length;
|
|
1180
|
-
if (pending2 > options.maxLineChars) parser = startOversized();
|
|
1181
|
-
};
|
|
1182
|
-
const takeLine = () => {
|
|
1183
|
-
if (parser !== null) {
|
|
1184
|
-
const record3 = parser.finish();
|
|
1185
|
-
parser = null;
|
|
1186
|
-
return { oversized: record3 };
|
|
1187
|
-
}
|
|
1188
|
-
if (pending2 === 0) return null;
|
|
1189
|
-
let line = pieces.length === 1 ? pieces[0] ?? "" : pieces.join("");
|
|
1190
|
-
pieces = [];
|
|
1191
|
-
pending2 = 0;
|
|
1192
|
-
if (line.endsWith("\r")) line = line.slice(0, -1);
|
|
1193
|
-
return line.length === 0 ? null : { line };
|
|
1194
|
-
};
|
|
1195
|
-
const feed = function* (text2) {
|
|
1196
|
-
let from = 0;
|
|
1197
|
-
while (from <= text2.length) {
|
|
1198
|
-
const newline = text2.indexOf("\n", from);
|
|
1199
|
-
if (newline < 0) {
|
|
1200
|
-
append(text2.slice(from));
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
append(text2.slice(from, newline));
|
|
1204
|
-
const entry = takeLine();
|
|
1205
|
-
if (entry !== null) yield entry;
|
|
1206
|
-
from = newline + 1;
|
|
1207
|
-
}
|
|
1208
|
-
};
|
|
1209
|
-
for await (const chunk of fs2.createReadStream(path)) {
|
|
1210
|
-
yield* feed(decoder.decode(chunk, { stream: true }));
|
|
1211
|
-
}
|
|
1212
|
-
yield* feed(decoder.decode());
|
|
1213
|
-
const last = takeLine();
|
|
1214
|
-
if (last !== null) yield last;
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
|
-
// ../../packages/ycodium-jsonl-stream/src/historyRecord.ts
|
|
1218
|
-
var textFields = (paths, accept) => {
|
|
1219
|
-
let completed = 0;
|
|
1220
|
-
let started = false;
|
|
1221
|
-
const begin = () => {
|
|
1222
|
-
if (started) return;
|
|
1223
|
-
if (completed > 0) accept("\n");
|
|
1224
|
-
started = true;
|
|
1225
|
-
};
|
|
1226
|
-
return paths.map((path) => ({
|
|
1227
|
-
path,
|
|
1228
|
-
scalarOnly: true,
|
|
1229
|
-
onChunk: (text2) => {
|
|
1230
|
-
begin();
|
|
1231
|
-
accept(text2);
|
|
1232
|
-
},
|
|
1233
|
-
onEnd: () => {
|
|
1234
|
-
begin();
|
|
1235
|
-
completed += 1;
|
|
1236
|
-
started = false;
|
|
1237
|
-
}
|
|
1238
|
-
}));
|
|
1239
|
-
};
|
|
1240
|
-
var createHistoryRecordAccumulator = (layout) => {
|
|
1241
|
-
const selected = layout();
|
|
1242
|
-
let rawTotal = 0;
|
|
1243
|
-
let messageTotal = 0;
|
|
1244
|
-
const hash = NodeCrypto2.createHash("sha256");
|
|
1245
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
1246
|
-
const parser = new OversizedRecordParser(
|
|
1247
|
-
[
|
|
1248
|
-
...selected.fields,
|
|
1249
|
-
...textFields(selected.textPaths, (text2) => {
|
|
1250
|
-
messageTotal += text2.length;
|
|
1251
|
-
})
|
|
1252
|
-
],
|
|
1253
|
-
Number.MAX_SAFE_INTEGER,
|
|
1254
|
-
{ pruneEmpty: true }
|
|
1255
|
-
);
|
|
1256
|
-
const accept = (text2) => {
|
|
1257
|
-
rawTotal += text2.length;
|
|
1258
|
-
parser.write(text2);
|
|
1259
|
-
};
|
|
1260
|
-
return {
|
|
1261
|
-
write: (bytes) => {
|
|
1262
|
-
hash.update(bytes);
|
|
1263
|
-
accept(decoder.decode(bytes, { stream: true }));
|
|
1264
|
-
},
|
|
1265
|
-
finish: (range) => {
|
|
1266
|
-
accept(decoder.decode());
|
|
1267
|
-
const metadata = parser.finish();
|
|
1268
|
-
if (metadata === void 0) {
|
|
1269
|
-
if (!range.terminated) return void 0;
|
|
1270
|
-
throw new SyntaxError("Malformed complete native history record.");
|
|
1271
|
-
}
|
|
1272
|
-
return {
|
|
1273
|
-
range,
|
|
1274
|
-
hash: hash.digest("hex"),
|
|
1275
|
-
rawTotal,
|
|
1276
|
-
messageTotal,
|
|
1277
|
-
items: selected.describe(metadata).map(
|
|
1278
|
-
(item) => item.text === "message" && messageTotal === 0 ? { ...item, text: "raw" } : item
|
|
1279
|
-
)
|
|
1280
|
-
};
|
|
1281
|
-
}
|
|
1282
|
-
};
|
|
1283
|
-
};
|
|
1284
|
-
var inspectHistoryRecord = async (path, range, layout, signal) => {
|
|
1285
|
-
const accumulator = createHistoryRecordAccumulator(layout);
|
|
1286
|
-
try {
|
|
1287
|
-
for await (const bytes of historyBytes(path, range.start, range.end, signal))
|
|
1288
|
-
accumulator.write(bytes);
|
|
1289
|
-
return accumulator.finish(range);
|
|
1290
|
-
} catch (error) {
|
|
1291
|
-
if (!range.terminated && error instanceof TypeError) return void 0;
|
|
1292
|
-
throw error;
|
|
1293
|
-
}
|
|
1294
|
-
};
|
|
1295
|
-
async function* historyRecordWindows(path, info, mode, from, until, limit, layout, signal) {
|
|
1296
|
-
let seen = 0;
|
|
1297
|
-
let offset = from;
|
|
1298
|
-
let pending2 = "";
|
|
1299
|
-
const ready = [];
|
|
1300
|
-
const accept = (text2) => {
|
|
1301
|
-
const begin = Math.max(0, from - seen);
|
|
1302
|
-
const end = Math.min(text2.length, until - seen);
|
|
1303
|
-
seen += text2.length;
|
|
1304
|
-
if (end > begin) pending2 += text2.slice(begin, end);
|
|
1305
|
-
while (pending2.length >= limit) {
|
|
1306
|
-
let size = limit;
|
|
1307
|
-
const code = pending2.charCodeAt(size - 1);
|
|
1308
|
-
if (code >= 55296 && code <= 56319) size -= 1;
|
|
1309
|
-
ready.push({ offset, text: pending2.slice(0, size) });
|
|
1310
|
-
pending2 = pending2.slice(size);
|
|
1311
|
-
offset += size;
|
|
1312
|
-
}
|
|
1313
|
-
};
|
|
1314
|
-
const selected = layout();
|
|
1315
|
-
const parser = mode === "raw" ? void 0 : new OversizedRecordParser(textFields(selected.textPaths, accept), Number.MAX_SAFE_INTEGER, {
|
|
1316
|
-
pruneEmpty: true
|
|
1317
|
-
});
|
|
1318
|
-
for await (const text2 of historyText(path, info.range, signal)) {
|
|
1319
|
-
if (parser === void 0) accept(text2);
|
|
1320
|
-
else parser.write(text2);
|
|
1321
|
-
while (ready.length > 0) yield ready.shift();
|
|
1322
|
-
if (seen >= until) break;
|
|
1323
|
-
}
|
|
1324
|
-
if (pending2) yield { offset, text: pending2 };
|
|
1325
|
-
}
|
|
1326
|
-
var verifyHistoryRecord = async (path, range, layout, signal) => {
|
|
1327
|
-
const selected = layout();
|
|
1328
|
-
const parser = new OversizedRecordParser(selected.fields, Number.MAX_SAFE_INTEGER, {
|
|
1329
|
-
pruneEmpty: true
|
|
1330
|
-
});
|
|
1331
|
-
try {
|
|
1332
|
-
for await (const text2 of historyText(path, range, signal)) parser.write(text2);
|
|
1333
|
-
} catch (error) {
|
|
1334
|
-
if (!range.terminated && error instanceof TypeError) return false;
|
|
1335
|
-
throw error;
|
|
1336
|
-
}
|
|
1337
|
-
const metadata = parser.finish();
|
|
1338
|
-
if (metadata === void 0 && range.terminated)
|
|
1339
|
-
throw new SyntaxError("Malformed complete native history record.");
|
|
1340
|
-
return selected.verify(metadata);
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
// ../../packages/ycodium-jsonl-stream/src/history.ts
|
|
1344
|
-
var RECORD_CACHE_LIMIT = 32;
|
|
1345
|
-
var TEXT_CACHE_CHARS = 262144;
|
|
1346
|
-
var recordCache = /* @__PURE__ */ new Map();
|
|
1347
|
-
var headCache = /* @__PURE__ */ new Map();
|
|
1348
|
-
var cacheKey = (path, identity) => `${path}\0${identity.identity}\0${identity.size}\0${identity.mtimeMs}\0${identity.ctimeMs}`;
|
|
1349
|
-
var remember = (cache, key, value, limit = RECORD_CACHE_LIMIT) => {
|
|
1350
|
-
cache.delete(key);
|
|
1351
|
-
cache.set(key, value);
|
|
1352
|
-
if (cache.size > limit) cache.delete(cache.keys().next().value);
|
|
1353
|
-
return value;
|
|
1354
|
-
};
|
|
1355
|
-
var encode = (position) => Buffer.from(JSON.stringify(position)).toString("base64url");
|
|
1356
|
-
var decode = (value) => {
|
|
1357
|
-
let p;
|
|
1358
|
-
try {
|
|
1359
|
-
p = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
1360
|
-
} catch {
|
|
1361
|
-
throw new NativeHistoryCursorError();
|
|
1362
|
-
}
|
|
1363
|
-
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))
|
|
1364
|
-
throw new NativeHistoryCursorError();
|
|
1365
|
-
return p;
|
|
1366
|
-
};
|
|
1367
|
-
var width = (n) => String(n).padStart(20, "0");
|
|
1368
|
-
var high = (n) => n >= 55296 && n <= 56319;
|
|
1369
|
-
var low = (n) => n >= 56320 && n <= 57343;
|
|
1370
|
-
var totalOf = (info, index) => info.items[index].text === "raw" ? info.rawTotal : info.messageTotal;
|
|
1371
|
-
var nativeItem = (identity, info, index, offset, text2) => {
|
|
1372
|
-
const { text: _mode, ...item } = info.items[index];
|
|
1373
|
-
const total = totalOf(info, index);
|
|
1374
|
-
const position = { e: identity, p: info.range.start, k: index, h: info.hash };
|
|
1375
|
-
return {
|
|
1376
|
-
...item,
|
|
1377
|
-
id: `${identity}:${info.range.start}:${index}`,
|
|
1378
|
-
orderKey: `${width(info.range.start)}:${width(index)}`,
|
|
1379
|
-
beforeCursor: encode({ ...position, o: offset }),
|
|
1380
|
-
afterCursor: encode({ ...position, o: offset + text2.length }),
|
|
1381
|
-
text: text2,
|
|
1382
|
-
textWindow: {
|
|
1383
|
-
offset,
|
|
1384
|
-
returned: text2.length,
|
|
1385
|
-
total,
|
|
1386
|
-
nextOffset: offset + text2.length < total ? offset + text2.length : null
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
};
|
|
1390
|
-
var readWindow = async (path, info, index, from, until, layout, signal, cached) => {
|
|
1391
|
-
const base = Math.max(0, from - 1);
|
|
1392
|
-
const end = Math.min(totalOf(info, index), until + 1);
|
|
1393
|
-
const mode = info.items[index].text;
|
|
1394
|
-
if (cached.text === void 0 && totalOf(info, index) <= TEXT_CACHE_CHARS) {
|
|
1395
|
-
const parts = [];
|
|
1396
|
-
for await (const window2 of historyRecordWindows(
|
|
1397
|
-
path,
|
|
1398
|
-
info,
|
|
1399
|
-
mode,
|
|
1400
|
-
0,
|
|
1401
|
-
totalOf(info, index),
|
|
1402
|
-
65536,
|
|
1403
|
-
layout,
|
|
1404
|
-
signal
|
|
1405
|
-
))
|
|
1406
|
-
parts.push(window2.text);
|
|
1407
|
-
cached.text = parts.join("");
|
|
1408
|
-
cached.mode = mode;
|
|
1409
|
-
}
|
|
1410
|
-
let text2 = cached.mode === mode ? cached.text?.slice(base, end) ?? "" : "";
|
|
1411
|
-
if (cached.mode !== mode) {
|
|
1412
|
-
for await (const window2 of historyRecordWindows(
|
|
1413
|
-
path,
|
|
1414
|
-
info,
|
|
1415
|
-
mode,
|
|
1416
|
-
base,
|
|
1417
|
-
end,
|
|
1418
|
-
Math.max(2, end - base),
|
|
1419
|
-
layout,
|
|
1420
|
-
signal
|
|
1421
|
-
))
|
|
1422
|
-
text2 += window2.text;
|
|
1423
|
-
}
|
|
1424
|
-
let startIndex = from - base;
|
|
1425
|
-
let endIndex = until - base;
|
|
1426
|
-
if (low(text2.charCodeAt(startIndex)) && high(text2.charCodeAt(startIndex - 1))) startIndex -= 1;
|
|
1427
|
-
if (low(text2.charCodeAt(endIndex)) && high(text2.charCodeAt(endIndex - 1))) endIndex -= 1;
|
|
1428
|
-
return { offset: base + startIndex, text: text2.slice(startIndex, endIndex) };
|
|
1429
|
-
};
|
|
1430
|
-
async function openJsonlHistory(path, layout, signal) {
|
|
1431
|
-
const controller = new AbortController();
|
|
1432
|
-
const combined = (next) => AbortSignal.any([controller.signal, ...signal ? [signal] : [], ...next ? [next] : []]);
|
|
1433
|
-
let verified;
|
|
1434
|
-
const verify = async (readSignal) => {
|
|
1435
|
-
const identity = await historyIdentity(path);
|
|
1436
|
-
if (verified?.identity === identity.identity && verified.size === identity.size && verified.mtimeMs === identity.mtimeMs && verified.ctimeMs === identity.ctimeMs)
|
|
1437
|
-
return identity;
|
|
1438
|
-
let checked = 0;
|
|
1439
|
-
for await (const range of historyLines(path, 0, identity.size, false, readSignal)) {
|
|
1440
|
-
if (await verifyHistoryRecord(path, range, layout, readSignal)) {
|
|
1441
|
-
verified = identity;
|
|
1442
|
-
return identity;
|
|
1443
|
-
}
|
|
1444
|
-
if (++checked >= 100) break;
|
|
1445
|
-
}
|
|
1446
|
-
throw new NativeHistoryPendingError();
|
|
1447
|
-
};
|
|
1448
|
-
await verify(combined());
|
|
1449
|
-
const active = /* @__PURE__ */ new Set();
|
|
1450
|
-
const iterators = /* @__PURE__ */ new Set();
|
|
1451
|
-
const tracked = (promise) => {
|
|
1452
|
-
active.add(promise);
|
|
1453
|
-
void promise.finally(() => active.delete(promise)).catch(() => void 0);
|
|
1454
|
-
return promise;
|
|
1455
|
-
};
|
|
1456
|
-
const inspect = async (range, identity, readSignal) => {
|
|
1457
|
-
const key = `${cacheKey(path, identity)}\0${range.start}`;
|
|
1458
|
-
const cached = recordCache.get(key);
|
|
1459
|
-
if (cached?.info.range.end === range.end) return cached;
|
|
1460
|
-
const info = await inspectHistoryRecord(path, range, layout, readSignal);
|
|
1461
|
-
return info === void 0 ? void 0 : remember(recordCache, key, { info });
|
|
1462
|
-
};
|
|
1463
|
-
const head = async (identity, readSignal) => {
|
|
1464
|
-
const key = cacheKey(path, identity);
|
|
1465
|
-
const saved = headCache.get(key);
|
|
1466
|
-
if (saved !== void 0) return saved;
|
|
1467
|
-
for await (const range of historyLines(path, 0, identity.size, true, readSignal)) {
|
|
1468
|
-
const info = await inspect(range, identity, readSignal);
|
|
1469
|
-
if (info !== void 0)
|
|
1470
|
-
return remember(
|
|
1471
|
-
headCache,
|
|
1472
|
-
key,
|
|
1473
|
-
await historyBoundary(path, identity.identity, range.commit, readSignal)
|
|
1474
|
-
);
|
|
1475
|
-
}
|
|
1476
|
-
return remember(headCache, key, await historyBoundary(path, identity.identity, 0, readSignal));
|
|
1477
|
-
};
|
|
1478
|
-
const page = async (input) => {
|
|
1479
|
-
const readSignal = combined(input.signal);
|
|
1480
|
-
readSignal.throwIfAborted();
|
|
1481
|
-
if (input.before !== void 0 && input.after !== void 0)
|
|
1482
|
-
throw new NativeHistoryCursorError();
|
|
1483
|
-
if (input.fromStart && input.before !== void 0) throw new NativeHistoryCursorError();
|
|
1484
|
-
const identity = await verify(readSignal);
|
|
1485
|
-
const position = input.before !== void 0 ? decode(input.before) : input.after !== void 0 ? decode(input.after) : void 0;
|
|
1486
|
-
if (position !== void 0 && (position.e !== identity.identity || position.p > identity.size))
|
|
1487
|
-
throw new NativeHistoryCursorError();
|
|
1488
|
-
const backwards = input.after === void 0 && input.fromStart !== true;
|
|
1489
|
-
const initialRange = position === void 0 ? void 0 : await (async () => {
|
|
1490
|
-
const cached = recordCache.get(`${cacheKey(path, identity)}\0${position.p}`);
|
|
1491
|
-
if (cached !== void 0) return cached.info.range;
|
|
1492
|
-
for await (const range of historyLines(
|
|
1493
|
-
path,
|
|
1494
|
-
position.p,
|
|
1495
|
-
identity.size,
|
|
1496
|
-
false,
|
|
1497
|
-
readSignal
|
|
1498
|
-
))
|
|
1499
|
-
return range;
|
|
1500
|
-
throw new NativeHistoryCursorError();
|
|
1501
|
-
})();
|
|
1502
|
-
const ranges = async function* () {
|
|
1503
|
-
if (initialRange !== void 0) yield initialRange;
|
|
1504
|
-
yield* backwards ? historyLines(path, 0, position?.p ?? identity.size, true, readSignal) : historyLines(path, initialRange?.commit ?? 0, identity.size, false, readSignal);
|
|
1505
|
-
};
|
|
1506
|
-
const items = [];
|
|
1507
|
-
let budget = Math.min(12e3, input.textLimit ?? 12e3);
|
|
1508
|
-
const limit = Math.min(50, input.limit ?? 20);
|
|
1509
|
-
let more = false;
|
|
1510
|
-
for await (const range of ranges()) {
|
|
1511
|
-
if (items.length >= limit || budget < 2) {
|
|
1512
|
-
more = true;
|
|
1513
|
-
break;
|
|
1514
|
-
}
|
|
1515
|
-
const cached = await inspect(range, identity, readSignal);
|
|
1516
|
-
if (cached === void 0) continue;
|
|
1517
|
-
const info = cached.info;
|
|
1518
|
-
const first = position !== void 0 && range.start === position.p;
|
|
1519
|
-
if (first && (position.h !== info.hash || position.k >= info.items.length || position.o > totalOf(info, position.k)))
|
|
1520
|
-
throw new NativeHistoryCursorError();
|
|
1521
|
-
const indices = Array.from({ length: info.items.length }, (_3, index) => index);
|
|
1522
|
-
if (backwards) indices.reverse();
|
|
1523
|
-
for (const index of indices) {
|
|
1524
|
-
if (first && (backwards ? index > position.k : index < position.k)) continue;
|
|
1525
|
-
const total = totalOf(info, index);
|
|
1526
|
-
if (first && index === position.k && total === 0) continue;
|
|
1527
|
-
const boundary = first && index === position.k ? position.o : backwards ? total : 0;
|
|
1528
|
-
if (total > 0 && (backwards ? boundary === 0 : boundary === total)) continue;
|
|
1529
|
-
if (items.length >= limit || budget < 2) {
|
|
1530
|
-
more = true;
|
|
1531
|
-
break;
|
|
1532
|
-
}
|
|
1533
|
-
const from = backwards ? Math.max(0, boundary - budget) : boundary;
|
|
1534
|
-
const until = backwards ? boundary : Math.min(total, from + budget);
|
|
1535
|
-
const window2 = await readWindow(path, info, index, from, until, layout, readSignal, cached);
|
|
1536
|
-
const item = nativeItem(identity.identity, info, index, window2.offset, window2.text);
|
|
1537
|
-
if (backwards) items.unshift(item);
|
|
1538
|
-
else items.push(item);
|
|
1539
|
-
budget -= window2.text.length;
|
|
1540
|
-
if (backwards ? window2.offset > 0 : window2.offset + window2.text.length < total) {
|
|
1541
|
-
more = true;
|
|
1542
|
-
break;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
if (more) break;
|
|
1546
|
-
}
|
|
1547
|
-
const liveCursor = await head(identity, readSignal);
|
|
1548
|
-
return {
|
|
1549
|
-
sourceEpoch: identity.identity,
|
|
1550
|
-
items,
|
|
1551
|
-
olderCursor: items.length === 0 ? null : backwards && !more && position === void 0 ? null : items[0].beforeCursor,
|
|
1552
|
-
newerCursor: items.length === 0 ? null : !backwards && !more ? null : backwards ? input.before !== void 0 ? items.at(-1).afterCursor : null : more ? items.at(-1).afterCursor : null,
|
|
1553
|
-
liveCursor
|
|
1554
|
-
};
|
|
1555
|
-
};
|
|
1556
|
-
const follow = (input) => {
|
|
1557
|
-
let iterator;
|
|
1558
|
-
iterator = (async function* () {
|
|
1559
|
-
const readSignal = combined(input.signal);
|
|
1560
|
-
let dirty = true;
|
|
1561
|
-
let wake;
|
|
1562
|
-
let failure;
|
|
1563
|
-
const notify = () => {
|
|
1564
|
-
dirty = true;
|
|
1565
|
-
wake?.();
|
|
1566
|
-
wake = void 0;
|
|
1567
|
-
};
|
|
1568
|
-
const watcher = NodeFS3.watch(
|
|
1569
|
-
NodePath5.dirname(path),
|
|
1570
|
-
{ signal: readSignal },
|
|
1571
|
-
(_event, file) => {
|
|
1572
|
-
if (file == null || String(file) === NodePath5.basename(path)) notify();
|
|
1573
|
-
}
|
|
1574
|
-
);
|
|
1575
|
-
watcher.on("error", (error) => {
|
|
1576
|
-
failure = error;
|
|
1577
|
-
notify();
|
|
1578
|
-
});
|
|
1579
|
-
const abort = () => notify();
|
|
1580
|
-
readSignal.addEventListener("abort", abort, { once: true });
|
|
1581
|
-
let committed = input.after;
|
|
1582
|
-
const reset = async () => page({
|
|
1583
|
-
...input.limit === void 0 ? {} : { limit: input.limit },
|
|
1584
|
-
...input.textLimit === void 0 ? {} : { textLimit: input.textLimit },
|
|
1585
|
-
signal: readSignal
|
|
1586
|
-
});
|
|
1587
|
-
try {
|
|
1588
|
-
let identity = await verify(readSignal);
|
|
1589
|
-
const boundary = committed !== void 0 && committed.sequence <= identity.size ? await historyBoundary(path, identity.identity, committed.sequence, readSignal) : void 0;
|
|
1590
|
-
if (committed === void 0 || boundary?.epoch !== committed.epoch || identity.size - committed.sequence > 1048576) {
|
|
1591
|
-
const value = await reset();
|
|
1592
|
-
committed = value.liveCursor;
|
|
1593
|
-
yield { _tag: "snapshot", cursor: committed, value };
|
|
1594
|
-
}
|
|
1595
|
-
let synchronized = false;
|
|
1596
|
-
let scanned = committed.sequence;
|
|
1597
|
-
let pendingStart = scanned;
|
|
1598
|
-
let accumulator = createHistoryRecordAccumulator(layout);
|
|
1599
|
-
const appended = async function* (end) {
|
|
1600
|
-
for await (const bytes of historyBytes(path, scanned, end, readSignal)) {
|
|
1601
|
-
let from = 0;
|
|
1602
|
-
const chunkStart = scanned;
|
|
1603
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
1604
|
-
if (bytes[index] !== 10) continue;
|
|
1605
|
-
accumulator.write(bytes.subarray(from, index));
|
|
1606
|
-
const at2 = chunkStart + index;
|
|
1607
|
-
const info = at2 > pendingStart ? accumulator.finish({
|
|
1608
|
-
start: pendingStart,
|
|
1609
|
-
end: at2,
|
|
1610
|
-
commit: at2 + 1,
|
|
1611
|
-
terminated: true
|
|
1612
|
-
}) : void 0;
|
|
1613
|
-
pendingStart = at2 + 1;
|
|
1614
|
-
accumulator = createHistoryRecordAccumulator(layout);
|
|
1615
|
-
from = index + 1;
|
|
1616
|
-
if (info !== void 0) yield info;
|
|
1617
|
-
}
|
|
1618
|
-
accumulator.write(bytes.subarray(from));
|
|
1619
|
-
scanned += bytes.length;
|
|
1620
|
-
}
|
|
1621
|
-
};
|
|
1622
|
-
while (true) {
|
|
1623
|
-
readSignal.throwIfAborted();
|
|
1624
|
-
if (failure !== void 0) throw failure;
|
|
1625
|
-
if (!dirty)
|
|
1626
|
-
await new Promise((resolve7) => {
|
|
1627
|
-
wake = resolve7;
|
|
1628
|
-
});
|
|
1629
|
-
readSignal.throwIfAborted();
|
|
1630
|
-
dirty = false;
|
|
1631
|
-
identity = await historyIdentity(path);
|
|
1632
|
-
const current = committed;
|
|
1633
|
-
const valid = scanned <= identity.size && current.sequence <= identity.size && (await historyBoundary(path, identity.identity, current.sequence, readSignal)).epoch === current.epoch;
|
|
1634
|
-
if (!valid) {
|
|
1635
|
-
const value = await reset();
|
|
1636
|
-
synchronized = false;
|
|
1637
|
-
committed = value.liveCursor;
|
|
1638
|
-
scanned = committed.sequence;
|
|
1639
|
-
pendingStart = scanned;
|
|
1640
|
-
accumulator = createHistoryRecordAccumulator(layout);
|
|
1641
|
-
yield { _tag: "snapshot", cursor: committed, value };
|
|
1642
|
-
} else {
|
|
1643
|
-
for await (const info of appended(identity.size)) {
|
|
1644
|
-
const next = await historyBoundary(
|
|
1645
|
-
path,
|
|
1646
|
-
identity.identity,
|
|
1647
|
-
info.range.commit,
|
|
1648
|
-
readSignal
|
|
1649
|
-
);
|
|
1650
|
-
for (let index = 0; index < info.items.length; index += 1) {
|
|
1651
|
-
const total = totalOf(info, index);
|
|
1652
|
-
if (total === 0) {
|
|
1653
|
-
yield {
|
|
1654
|
-
_tag: "delta",
|
|
1655
|
-
cursor: index === info.items.length - 1 ? next : committed,
|
|
1656
|
-
items: [nativeItem(identity.identity, info, index, 0, "")]
|
|
1657
|
-
};
|
|
1658
|
-
continue;
|
|
1659
|
-
}
|
|
1660
|
-
for await (const window2 of historyRecordWindows(
|
|
1661
|
-
path,
|
|
1662
|
-
info,
|
|
1663
|
-
info.items[index].text,
|
|
1664
|
-
0,
|
|
1665
|
-
total,
|
|
1666
|
-
Math.min(12e3, input.textLimit ?? 12e3),
|
|
1667
|
-
layout,
|
|
1668
|
-
readSignal
|
|
1669
|
-
)) {
|
|
1670
|
-
const done = index === info.items.length - 1 && window2.offset + window2.text.length === total;
|
|
1671
|
-
yield {
|
|
1672
|
-
_tag: "delta",
|
|
1673
|
-
cursor: done ? next : committed,
|
|
1674
|
-
items: [nativeItem(identity.identity, info, index, window2.offset, window2.text)]
|
|
1675
|
-
};
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
committed = next;
|
|
1679
|
-
}
|
|
1680
|
-
}
|
|
1681
|
-
if (!synchronized) {
|
|
1682
|
-
synchronized = true;
|
|
1683
|
-
yield { _tag: "synchronized" };
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
} finally {
|
|
1687
|
-
watcher.close();
|
|
1688
|
-
readSignal.removeEventListener("abort", abort);
|
|
1689
|
-
wake?.();
|
|
1690
|
-
if (iterator !== void 0) iterators.delete(iterator);
|
|
1691
|
-
}
|
|
1692
|
-
})();
|
|
1693
|
-
iterators.add(iterator);
|
|
1694
|
-
return iterator;
|
|
1695
|
-
};
|
|
1696
|
-
return {
|
|
1697
|
-
page: (input) => tracked(page(input)),
|
|
1698
|
-
follow,
|
|
1699
|
-
close: async () => {
|
|
1700
|
-
controller.abort();
|
|
1701
|
-
await Promise.all([...iterators].map((iterator) => iterator.return(void 0)));
|
|
1702
|
-
await Promise.allSettled(active);
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
// ../../packages/ycodium-jsonl-stream/src/claudeSessions.ts
|
|
1708
|
-
import * as NodePath6 from "node:path";
|
|
388
|
+
import * as NodePath3 from "node:path";
|
|
1709
389
|
import * as NodeProcess from "node:process";
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
var DIGEST_FIELDS = [
|
|
1717
|
-
{ path: ["type"] },
|
|
1718
|
-
{ path: ["cwd"] },
|
|
1719
|
-
{ path: ["isSidechain"] },
|
|
1720
|
-
{ path: ["customTitle"] },
|
|
1721
|
-
{ path: ["aiTitle"] },
|
|
1722
|
-
{ path: ["message", "model"] },
|
|
1723
|
-
{ path: ["message", "content"], scalarOnly: true, maxChars: DIGEST_TEXT_KEEP_CHARS },
|
|
1724
|
-
{ path: ["message", "content", "*", "type"] },
|
|
1725
|
-
{ path: ["message", "content", "*", "text"], maxChars: DIGEST_TEXT_KEEP_CHARS }
|
|
1726
|
-
];
|
|
1727
|
-
function truncate(value) {
|
|
1728
|
-
const trimmed = value?.trim() ?? "";
|
|
1729
|
-
if (trimmed.length === 0) return null;
|
|
1730
|
-
return trimmed.length <= PREVIEW_LIMIT ? trimmed : `${trimmed.slice(0, PREVIEW_LIMIT)}\u2026`;
|
|
1731
|
-
}
|
|
1732
|
-
function encodeClaudeProjectDirName(cwd) {
|
|
1733
|
-
return cwd.replace(/[^A-Za-z0-9]/gu, "-");
|
|
1734
|
-
}
|
|
1735
|
-
function textFromContent(content) {
|
|
1736
|
-
if (typeof content === "string") return content.trim();
|
|
1737
|
-
if (!Array.isArray(content)) return "";
|
|
1738
|
-
const parts = [];
|
|
1739
|
-
for (const block of content) {
|
|
1740
|
-
if (!block || typeof block !== "object") continue;
|
|
1741
|
-
const typed = block;
|
|
1742
|
-
if (typed.type === "text" && typeof typed.text === "string") parts.push(typed.text);
|
|
1743
|
-
}
|
|
1744
|
-
return parts.join("\n\n").trim();
|
|
1745
|
-
}
|
|
1746
|
-
async function readClaudeTranscriptDigest(source, filePath) {
|
|
1747
|
-
let cwd = null;
|
|
1748
|
-
let model = null;
|
|
1749
|
-
let preview = null;
|
|
1750
|
-
let customTitle = null;
|
|
1751
|
-
let aiTitle = null;
|
|
1752
|
-
let turnCount = 0;
|
|
1753
|
-
try {
|
|
1754
|
-
const entries = readJsonlEntries(source, filePath, {
|
|
1755
|
-
maxLineChars: CLAUDE_MAX_PARSED_LINE_BYTES,
|
|
1756
|
-
fields: DIGEST_FIELDS
|
|
1757
|
-
});
|
|
1758
|
-
for await (const entry of entries) {
|
|
1759
|
-
const record3 = jsonlEntryRecord(entry, (line) => {
|
|
1760
|
-
const isUser = line.includes('"type":"user"');
|
|
1761
|
-
const wantsAssistant = model === null && line.includes('"type":"assistant"');
|
|
1762
|
-
const isTitle = line.includes('"custom-title"') || line.includes('"ai-title"');
|
|
1763
|
-
return isUser || wantsAssistant || isTitle;
|
|
1764
|
-
});
|
|
1765
|
-
if (!record3 || typeof record3 !== "object") continue;
|
|
1766
|
-
const typed = record3;
|
|
1767
|
-
if (cwd === null && typeof typed.cwd === "string" && typed.cwd.length > 0) cwd = typed.cwd;
|
|
1768
|
-
if (typed.type === "custom-title" && typeof typed.customTitle === "string") {
|
|
1769
|
-
customTitle = typed.customTitle;
|
|
1770
|
-
continue;
|
|
1771
|
-
}
|
|
1772
|
-
if (typed.type === "ai-title" && typeof typed.aiTitle === "string") {
|
|
1773
|
-
aiTitle = typed.aiTitle;
|
|
1774
|
-
continue;
|
|
1775
|
-
}
|
|
1776
|
-
if (typed.isSidechain === true) continue;
|
|
1777
|
-
if (typed.type === "assistant") {
|
|
1778
|
-
if (model === null && typeof typed.message?.model === "string") model = typed.message.model;
|
|
1779
|
-
continue;
|
|
1780
|
-
}
|
|
1781
|
-
if (typed.type !== "user") continue;
|
|
1782
|
-
const text2 = textFromContent(typed.message?.content);
|
|
1783
|
-
if (text2.length === 0) continue;
|
|
1784
|
-
turnCount += 1;
|
|
1785
|
-
if (preview === null) preview = text2;
|
|
1786
|
-
}
|
|
1787
|
-
} catch {
|
|
1788
|
-
return null;
|
|
1789
|
-
}
|
|
1790
|
-
return {
|
|
1791
|
-
cwd,
|
|
1792
|
-
title: truncate(customTitle ?? aiTitle),
|
|
1793
|
-
preview: truncate(preview),
|
|
1794
|
-
model,
|
|
1795
|
-
turnCount
|
|
1796
|
-
};
|
|
1797
|
-
}
|
|
1798
|
-
async function listClaudeTranscriptFiles(fs2, transcriptDir, directory) {
|
|
1799
|
-
let dirs;
|
|
1800
|
-
try {
|
|
1801
|
-
dirs = (await fs2.readDir(transcriptDir)).filter((entry) => entry.type === "directory").map((entry) => entry.name);
|
|
1802
|
-
} catch {
|
|
1803
|
-
return [];
|
|
1804
|
-
}
|
|
1805
|
-
const encodedRoot = encodeClaudeProjectDirName(directory);
|
|
1806
|
-
const matched = dirs.filter((name) => name.startsWith(encodedRoot));
|
|
1807
|
-
const scanned = matched.length > 0 ? matched : dirs;
|
|
1808
|
-
const found = [];
|
|
1809
|
-
for (const dir of scanned) {
|
|
1810
|
-
const projectDir = NodePath6.join(transcriptDir, dir);
|
|
1811
|
-
let names;
|
|
1812
|
-
try {
|
|
1813
|
-
names = (await fs2.readDir(projectDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(CLAUDE_TRANSCRIPT_SUFFIX)).map((entry) => entry.name);
|
|
1814
|
-
} catch {
|
|
1815
|
-
continue;
|
|
1816
|
-
}
|
|
1817
|
-
for (const name of names) {
|
|
1818
|
-
let stat5;
|
|
1819
|
-
try {
|
|
1820
|
-
stat5 = await fs2.stat(NodePath6.join(projectDir, name));
|
|
1821
|
-
} catch {
|
|
1822
|
-
continue;
|
|
1823
|
-
}
|
|
1824
|
-
found.push({
|
|
1825
|
-
path: NodePath6.join(projectDir, name),
|
|
1826
|
-
sessionId: name.slice(0, -CLAUDE_TRANSCRIPT_SUFFIX.length),
|
|
1827
|
-
size: stat5.size,
|
|
1828
|
-
mtimeMs: Number.isFinite(stat5.mtimeMs) ? stat5.mtimeMs : 0
|
|
1829
|
-
});
|
|
1830
|
-
}
|
|
1831
|
-
}
|
|
1832
|
-
return found;
|
|
1833
|
-
}
|
|
1834
|
-
async function readClaudeLiveSessionIds(fs2, configDir) {
|
|
1835
|
-
const live = /* @__PURE__ */ new Set();
|
|
1836
|
-
const markerDir = NodePath6.join(configDir, "sessions");
|
|
1837
|
-
let entries;
|
|
1838
|
-
try {
|
|
1839
|
-
entries = (await fs2.readDir(markerDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(".json")).map((entry) => entry.name);
|
|
1840
|
-
} catch {
|
|
1841
|
-
return live;
|
|
1842
|
-
}
|
|
1843
|
-
for (const entry of entries) {
|
|
1844
|
-
let marker;
|
|
1845
|
-
try {
|
|
1846
|
-
marker = JSON.parse(await fs2.readFile(NodePath6.join(markerDir, entry)));
|
|
1847
|
-
} catch {
|
|
1848
|
-
continue;
|
|
1849
|
-
}
|
|
1850
|
-
if (!marker || typeof marker !== "object") continue;
|
|
1851
|
-
const typed = marker;
|
|
1852
|
-
if (typeof typed.pid !== "number" || typeof typed.sessionId !== "string") continue;
|
|
1853
|
-
try {
|
|
1854
|
-
NodeProcess.kill(typed.pid, 0);
|
|
1855
|
-
} catch {
|
|
1856
|
-
continue;
|
|
1857
|
-
}
|
|
1858
|
-
live.add(typed.sessionId);
|
|
1859
|
-
}
|
|
1860
|
-
return live;
|
|
1861
|
-
}
|
|
1862
|
-
|
|
1863
|
-
// ../../packages/ycodium-workspace-path/src/directoryScope.ts
|
|
1864
|
-
var EXTENDED_LENGTH_UNC = "//?/UNC/";
|
|
1865
|
-
var EXTENDED_LENGTH = "//?/";
|
|
1866
|
-
function normalize(value, caseInsensitive) {
|
|
1867
|
-
let unified = value.trim().replace(/\\/gu, "/");
|
|
1868
|
-
const upper = unified.toUpperCase();
|
|
1869
|
-
if (upper.startsWith(EXTENDED_LENGTH_UNC)) {
|
|
1870
|
-
unified = `//${unified.slice(EXTENDED_LENGTH_UNC.length)}`;
|
|
1871
|
-
} else if (upper.startsWith(EXTENDED_LENGTH)) {
|
|
1872
|
-
unified = unified.slice(EXTENDED_LENGTH.length);
|
|
1873
|
-
}
|
|
1874
|
-
const isUnc = unified.startsWith("//");
|
|
1875
|
-
unified = unified.replace(/\/+/gu, "/").replace(/\/+$/u, "");
|
|
1876
|
-
if (isUnc) unified = `/${unified}`;
|
|
1877
|
-
return caseInsensitive ? unified.toLowerCase() : unified;
|
|
1878
|
-
}
|
|
1879
|
-
function isWithinDirectory(candidate, root, caseInsensitive) {
|
|
1880
|
-
const normalizedRoot = normalize(root, caseInsensitive);
|
|
1881
|
-
if (normalizedRoot.length === 0 || normalizedRoot === "/") return false;
|
|
1882
|
-
const normalizedCandidate = normalize(candidate, caseInsensitive);
|
|
1883
|
-
return normalizedCandidate === normalizedRoot || normalizedCandidate.startsWith(`${normalizedRoot}/`);
|
|
1884
|
-
}
|
|
1885
|
-
|
|
1886
|
-
// 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";
|
|
1887
396
|
var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1888
397
|
var claudeHistoryLayout = (input) => () => {
|
|
1889
398
|
let sourceTruncated = false;
|
|
@@ -1895,7 +404,7 @@ var claudeHistoryLayout = (input) => () => {
|
|
|
1895
404
|
const verify = (metadata) => {
|
|
1896
405
|
if (!record(metadata) || typeof metadata.sessionId !== "string" || typeof metadata.cwd !== "string")
|
|
1897
406
|
return false;
|
|
1898
|
-
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"))
|
|
1899
408
|
throw new Error("Native session ownership does not match the recorded agent.");
|
|
1900
409
|
return true;
|
|
1901
410
|
};
|
|
@@ -1983,21 +492,21 @@ var openClaudeHistory = (input) => {
|
|
|
1983
492
|
for (const id2 of [input.nativeSessionId, input.parentNativeSessionId])
|
|
1984
493
|
if (!/^[A-Za-z0-9_-]+$/u.test(id2)) throw new Error("Invalid native session identifier.");
|
|
1985
494
|
const name = input.nativeSessionId.startsWith("agent-") ? input.nativeSessionId : `agent-${input.nativeSessionId}`;
|
|
1986
|
-
if (input.parentTranscriptPath !== void 0 && (!
|
|
495
|
+
if (input.parentTranscriptPath !== void 0 && (!NodePath3.isAbsolute(input.parentTranscriptPath) || NodePath3.basename(input.parentTranscriptPath) !== `${input.parentNativeSessionId}.jsonl`))
|
|
1987
496
|
throw new Error("Native transcript path does not match the recorded session.");
|
|
1988
|
-
const projectDir = input.parentTranscriptPath === void 0 ?
|
|
1989
|
-
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`);
|
|
1990
499
|
return waitForJsonlHistory({
|
|
1991
500
|
root: input.parentTranscriptPath === void 0 ? input.transcriptDir : projectDir,
|
|
1992
|
-
accepts: (changed) => changed === path || path.startsWith(changed +
|
|
501
|
+
accepts: (changed) => changed === path || path.startsWith(changed + NodePath3.sep),
|
|
1993
502
|
open: (signal) => openJsonlHistory(path, claudeHistoryLayout(input), signal),
|
|
1994
503
|
...input.signal === void 0 ? {} : { signal: input.signal }
|
|
1995
504
|
});
|
|
1996
505
|
};
|
|
1997
506
|
|
|
1998
507
|
// src/claudeInstance.ts
|
|
1999
|
-
import * as
|
|
2000
|
-
import * as
|
|
508
|
+
import * as NodeOS9 from "node:os";
|
|
509
|
+
import * as NodePath14 from "node:path";
|
|
2001
510
|
|
|
2002
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
|
|
2003
512
|
import { createRequire as xz } from "node:module";
|
|
@@ -21430,103 +19939,26 @@ function HU(e, t) {
|
|
|
21430
19939
|
}
|
|
21431
19940
|
|
|
21432
19941
|
// src/claudeInstance.ts
|
|
21433
|
-
import { mergeLaunchEnv as
|
|
21434
|
-
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";
|
|
21435
19944
|
|
|
21436
|
-
//
|
|
19945
|
+
// src/claudeProbe.ts
|
|
19946
|
+
import { readCliVersionCommand } from "@ycodium-ai/plugin-api/instance-config";
|
|
21437
19947
|
import {
|
|
21438
19948
|
describeExecutorSpawnFailure,
|
|
21439
19949
|
ExecutorSpawnAbortedError,
|
|
21440
19950
|
ExecutorSpawnRefusedError
|
|
21441
19951
|
} from "@ycodium-ai/plugin-api/executor";
|
|
21442
19952
|
import {
|
|
21443
|
-
|
|
21444
|
-
|
|
19953
|
+
runProcessOperation,
|
|
19954
|
+
isOperationCleanupError
|
|
21445
19955
|
} from "@ycodium-ai/plugin-api/process-operation";
|
|
21446
|
-
async function readCliVersionCommand(host, input) {
|
|
21447
|
-
try {
|
|
21448
|
-
const run = await runProcessOperation(host, {
|
|
21449
|
-
program: input.program,
|
|
21450
|
-
args: ["--version"],
|
|
21451
|
-
owner: { bindingId: host.bindingId },
|
|
21452
|
-
...Object.keys(input.env).length > 0 ? { env: input.env } : {},
|
|
21453
|
-
signal: input.signal,
|
|
21454
|
-
timeoutMs: input.timeoutMs,
|
|
21455
|
-
maxOutputBytes: 64 * 1024
|
|
21456
|
-
});
|
|
21457
|
-
if (run.exitCode !== 0 && !input.acceptNonzeroExit) return null;
|
|
21458
|
-
return input.parse(run.stdout) ?? input.parse(run.stderr);
|
|
21459
|
-
} catch (error) {
|
|
21460
|
-
if (isOperationCleanupError(error) || input.signal?.aborted) throw error;
|
|
21461
|
-
return null;
|
|
21462
|
-
}
|
|
21463
|
-
}
|
|
21464
|
-
|
|
21465
|
-
// src/claudeProbe.ts
|
|
21466
|
-
import {
|
|
21467
|
-
describeExecutorSpawnFailure as describeExecutorSpawnFailure2,
|
|
21468
|
-
ExecutorSpawnAbortedError as ExecutorSpawnAbortedError2,
|
|
21469
|
-
ExecutorSpawnRefusedError as ExecutorSpawnRefusedError2
|
|
21470
|
-
} from "@ycodium-ai/plugin-api/executor";
|
|
21471
|
-
import {
|
|
21472
|
-
runProcessOperation as runProcessOperation2,
|
|
21473
|
-
isOperationCleanupError as isOperationCleanupError2
|
|
21474
|
-
} from "@ycodium-ai/plugin-api/process-operation";
|
|
21475
|
-
|
|
21476
|
-
// ../../packages/ycodium-credential-account/src/quotaJson.ts
|
|
21477
|
-
var clampPercent = (value) => Math.min(100, Math.max(0, value));
|
|
21478
|
-
|
|
21479
|
-
// src/usageRead/quota.ts
|
|
21480
|
-
import * as NodeFS4 from "node:fs";
|
|
21481
|
-
import * as NodePath8 from "node:path";
|
|
21482
|
-
import { mergeLaunchEnv as mergeLaunchEnv2, setsOwnModelConnection } from "@ycodium-ai/plugin-api/executor";
|
|
21483
|
-
|
|
21484
|
-
// ../../packages/ycodium-credential-account/src/quotaRequest.ts
|
|
21485
|
-
import { parseRetryAfterMs } from "@ycodium-ai/plugin-api/usage";
|
|
21486
|
-
async function requestQuotaJsonValue(input) {
|
|
21487
|
-
let response;
|
|
21488
|
-
try {
|
|
21489
|
-
response = await input.fetch(input.url, {
|
|
21490
|
-
headers: input.headers,
|
|
21491
|
-
...input.method === void 0 ? {} : { method: input.method },
|
|
21492
|
-
...input.body === void 0 ? {} : { body: input.body },
|
|
21493
|
-
...input.redirect === void 0 ? {} : { redirect: input.redirect },
|
|
21494
|
-
signal: AbortSignal.any([
|
|
21495
|
-
...input.signal === void 0 ? [] : [input.signal],
|
|
21496
|
-
AbortSignal.timeout(input.timeoutMs)
|
|
21497
|
-
])
|
|
21498
|
-
});
|
|
21499
|
-
} catch (cause) {
|
|
21500
|
-
if (input.propagateCallerAbort && input.signal?.aborted) throw cause;
|
|
21501
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
21502
|
-
}
|
|
21503
|
-
if (!response.ok) {
|
|
21504
|
-
void response.body?.cancel().catch(() => void 0);
|
|
21505
|
-
if (response.status === 429) {
|
|
21506
|
-
const retryAfterMs = parseRetryAfterMs(response.headers.get("retry-after"), input.now());
|
|
21507
|
-
return {
|
|
21508
|
-
status: "unavailable",
|
|
21509
|
-
reason: "rateLimited",
|
|
21510
|
-
...retryAfterMs === null ? {} : { retryAfterMs }
|
|
21511
|
-
};
|
|
21512
|
-
}
|
|
21513
|
-
const reason = input.statusReasons?.[response.status] ?? (response.status === 401 || response.status === 403 ? "authRejected" : "unreachable");
|
|
21514
|
-
return { status: "unavailable", reason };
|
|
21515
|
-
}
|
|
21516
|
-
try {
|
|
21517
|
-
return { body: JSON.parse(await response.text()) };
|
|
21518
|
-
} catch (cause) {
|
|
21519
|
-
if (input.propagateCallerAbort && input.signal?.aborted) throw cause;
|
|
21520
|
-
return { status: "unavailable", reason: "unreachable" };
|
|
21521
|
-
}
|
|
21522
|
-
}
|
|
21523
|
-
async function requestQuotaJson(input) {
|
|
21524
|
-
const answer = await requestQuotaJsonValue(input);
|
|
21525
|
-
if (!("body" in answer)) return answer;
|
|
21526
|
-
return isRecord(answer.body) ? { body: answer.body } : { status: "unavailable", reason: "unreachable" };
|
|
21527
|
-
}
|
|
21528
19956
|
|
|
21529
19957
|
// src/usageRead/quota.ts
|
|
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";
|
|
21530
19962
|
var CLAUDE_QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
|
|
21531
19963
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
21532
19964
|
var HOUR_MS = 60 * 60 * 1e3;
|
|
@@ -21535,7 +19967,7 @@ var CLAUDE_QUOTA_WINDOWS = [
|
|
|
21535
19967
|
{ field: "seven_day", id: "weekly", labelKey: "usage.window.weekly", windowMs: 7 * 24 * HOUR_MS }
|
|
21536
19968
|
];
|
|
21537
19969
|
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21538
|
-
var launchEnvironment = (recipe) =>
|
|
19970
|
+
var launchEnvironment = (recipe) => mergeLaunchEnv({
|
|
21539
19971
|
inherited: process.env,
|
|
21540
19972
|
instanceTable: recipe.environment,
|
|
21541
19973
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -21545,14 +19977,14 @@ var claudeCredentialFileCandidates = (recipe) => {
|
|
|
21545
19977
|
const credentialsDir = resolveClaudeCredentialsDirPath(
|
|
21546
19978
|
environment[CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE] ?? ""
|
|
21547
19979
|
);
|
|
21548
|
-
if (credentialsDir !== null) return [
|
|
19980
|
+
if (credentialsDir !== null) return [NodePath4.join(credentialsDir, ".credentials.json")];
|
|
21549
19981
|
const configDir = resolveClaudeConfigDirPath(recipe.homePath, environment);
|
|
21550
19982
|
const home = resolveClaudeHomePath(recipe.homePath);
|
|
21551
19983
|
return [
|
|
21552
19984
|
.../* @__PURE__ */ new Set([
|
|
21553
|
-
|
|
21554
|
-
|
|
21555
|
-
|
|
19985
|
+
NodePath4.join(configDir, ".credentials.json"),
|
|
19986
|
+
NodePath4.join(home, ".claude", ".credentials.json"),
|
|
19987
|
+
NodePath4.join(home, ".credentials.json")
|
|
21556
19988
|
])
|
|
21557
19989
|
];
|
|
21558
19990
|
};
|
|
@@ -21561,7 +19993,7 @@ var readLoginCredential = (candidates) => {
|
|
|
21561
19993
|
for (const path of candidates) {
|
|
21562
19994
|
let raw;
|
|
21563
19995
|
try {
|
|
21564
|
-
raw =
|
|
19996
|
+
raw = NodeFS.readFileSync(path, "utf8");
|
|
21565
19997
|
} catch {
|
|
21566
19998
|
continue;
|
|
21567
19999
|
}
|
|
@@ -21662,9 +20094,9 @@ var readClaudeQuota = async (request) => {
|
|
|
21662
20094
|
};
|
|
21663
20095
|
|
|
21664
20096
|
// src/claudeSkills.ts
|
|
21665
|
-
import * as
|
|
21666
|
-
import * as
|
|
21667
|
-
import * as
|
|
20097
|
+
import * as NodeFSP from "node:fs/promises";
|
|
20098
|
+
import * as NodePath5 from "node:path";
|
|
20099
|
+
import * as NodeProcess2 from "node:process";
|
|
21668
20100
|
var FRONT_MATTER_KEY = /^(description|disable-model-invocation|user-invocable|argument-hint):[ \t]*(.*)$/;
|
|
21669
20101
|
var BLOCK_SCALAR = /^[|>][+-]?$/;
|
|
21670
20102
|
function parseFrontMatterBoolean(value) {
|
|
@@ -21729,7 +20161,7 @@ function claudeManagedSettingsPath(platform4, environment) {
|
|
|
21729
20161
|
}
|
|
21730
20162
|
if (platform4 === "win32") {
|
|
21731
20163
|
const programData = environment["PROGRAMDATA"]?.trim();
|
|
21732
|
-
return programData ?
|
|
20164
|
+
return programData ? NodePath5.join(programData, "ClaudeCode", "managed-settings.json") : void 0;
|
|
21733
20165
|
}
|
|
21734
20166
|
return "/etc/claude-code/managed-settings.json";
|
|
21735
20167
|
}
|
|
@@ -21737,24 +20169,24 @@ function skillOverrideSettingsPaths(configDirPath, cwd, platform4, environment,
|
|
|
21737
20169
|
const managedPath = claudeManagedSettingsPath(platform4, environment);
|
|
21738
20170
|
const root = repositoryRoot !== void 0 && repositoryRoot !== cwd ? repositoryRoot : void 0;
|
|
21739
20171
|
return [
|
|
21740
|
-
|
|
20172
|
+
NodePath5.join(configDirPath, "settings.json"),
|
|
21741
20173
|
...cwd ? [
|
|
21742
|
-
|
|
21743
|
-
|
|
20174
|
+
NodePath5.join(cwd, ".claude", "settings.json"),
|
|
20175
|
+
NodePath5.join(cwd, ".claude", "settings.local.json")
|
|
21744
20176
|
] : [],
|
|
21745
|
-
...root ? [
|
|
20177
|
+
...root ? [NodePath5.join(root, ".claude", "settings.local.json")] : [],
|
|
21746
20178
|
...managedPath ? [managedPath] : []
|
|
21747
20179
|
];
|
|
21748
20180
|
}
|
|
21749
20181
|
async function findRepositoryRoot(cwd) {
|
|
21750
|
-
let current =
|
|
20182
|
+
let current = NodePath5.resolve(cwd);
|
|
21751
20183
|
for (; ; ) {
|
|
21752
|
-
const found = await
|
|
20184
|
+
const found = await NodeFSP.stat(NodePath5.join(current, ".git")).then(
|
|
21753
20185
|
() => true,
|
|
21754
20186
|
() => false
|
|
21755
20187
|
);
|
|
21756
20188
|
if (found) return current;
|
|
21757
|
-
const parent =
|
|
20189
|
+
const parent = NodePath5.dirname(current);
|
|
21758
20190
|
if (parent === current) return void 0;
|
|
21759
20191
|
current = parent;
|
|
21760
20192
|
}
|
|
@@ -21819,7 +20251,7 @@ async function readSkillOverrides(configDirPath, cwd, platform4, environment) {
|
|
|
21819
20251
|
environment,
|
|
21820
20252
|
repositoryRoot
|
|
21821
20253
|
)) {
|
|
21822
|
-
const contents = await
|
|
20254
|
+
const contents = await NodeFSP.readFile(settingsPath, "utf8").catch(() => void 0);
|
|
21823
20255
|
if (contents === void 0) continue;
|
|
21824
20256
|
for (const [name, override] of readOverridesFromSettings(contents) ?? []) {
|
|
21825
20257
|
merged.set(name, override);
|
|
@@ -21832,21 +20264,21 @@ async function discoverClaudeSkills(configDirPath, options = {}) {
|
|
|
21832
20264
|
const overrides = await readSkillOverrides(
|
|
21833
20265
|
configDirPath,
|
|
21834
20266
|
cwd,
|
|
21835
|
-
options.platform ??
|
|
21836
|
-
options.environment ??
|
|
20267
|
+
options.platform ?? NodeProcess2.platform,
|
|
20268
|
+
options.environment ?? NodeProcess2.env
|
|
21837
20269
|
);
|
|
21838
20270
|
const roots = [
|
|
21839
|
-
{ directory:
|
|
21840
|
-
...cwd ? [{ directory:
|
|
20271
|
+
{ directory: NodePath5.join(configDirPath, "skills"), scope: "user" },
|
|
20272
|
+
...cwd ? [{ directory: NodePath5.join(cwd, ".claude", "skills"), scope: "project" }] : []
|
|
21841
20273
|
];
|
|
21842
20274
|
const skills = /* @__PURE__ */ new Map();
|
|
21843
20275
|
for (const root of roots) {
|
|
21844
|
-
const entries = await
|
|
20276
|
+
const entries = await NodeFSP.readdir(root.directory).catch(() => []);
|
|
21845
20277
|
for (const entry of entries.toSorted()) {
|
|
21846
20278
|
const name = entry.trim();
|
|
21847
20279
|
if (name.length === 0 || skills.has(name)) continue;
|
|
21848
|
-
const skillPath =
|
|
21849
|
-
const contents = await
|
|
20280
|
+
const skillPath = NodePath5.join(root.directory, entry, "SKILL.md");
|
|
20281
|
+
const contents = await NodeFSP.readFile(skillPath, "utf8").catch(() => void 0);
|
|
21850
20282
|
if (contents === void 0) continue;
|
|
21851
20283
|
const frontMatter = parseSkillFrontMatter(contents);
|
|
21852
20284
|
const override = overrides.get(name);
|
|
@@ -22206,7 +20638,7 @@ function createClaudeProbe(input) {
|
|
|
22206
20638
|
};
|
|
22207
20639
|
}
|
|
22208
20640
|
if (signal?.aborted) {
|
|
22209
|
-
throw new
|
|
20641
|
+
throw new ExecutorSpawnAbortedError();
|
|
22210
20642
|
}
|
|
22211
20643
|
let command;
|
|
22212
20644
|
let commandStarted = false;
|
|
@@ -22221,7 +20653,7 @@ function createClaudeProbe(input) {
|
|
|
22221
20653
|
}
|
|
22222
20654
|
};
|
|
22223
20655
|
try {
|
|
22224
|
-
command = await
|
|
20656
|
+
command = await runProcessOperation(commandHost, {
|
|
22225
20657
|
program: recipe.binaryPath,
|
|
22226
20658
|
args: ["--version"],
|
|
22227
20659
|
env: recipe.environment,
|
|
@@ -22231,12 +20663,12 @@ function createClaudeProbe(input) {
|
|
|
22231
20663
|
...signal === void 0 ? {} : { signal }
|
|
22232
20664
|
});
|
|
22233
20665
|
} catch (error) {
|
|
22234
|
-
if (
|
|
22235
|
-
if (signal?.aborted) throw new
|
|
22236
|
-
if (commandStarted || error instanceof
|
|
20666
|
+
if (isOperationCleanupError(error)) throw error;
|
|
20667
|
+
if (signal?.aborted) throw new ExecutorSpawnAbortedError();
|
|
20668
|
+
if (commandStarted || error instanceof ExecutorSpawnRefusedError || error instanceof ExecutorSpawnAbortedError) {
|
|
22237
20669
|
throw error;
|
|
22238
20670
|
}
|
|
22239
|
-
const failure =
|
|
20671
|
+
const failure = describeExecutorSpawnFailure(error);
|
|
22240
20672
|
return {
|
|
22241
20673
|
installed: false,
|
|
22242
20674
|
version: null,
|
|
@@ -22246,7 +20678,7 @@ function createClaudeProbe(input) {
|
|
|
22246
20678
|
};
|
|
22247
20679
|
}
|
|
22248
20680
|
const { stdout, stderr, exitCode } = command;
|
|
22249
|
-
if (signal?.aborted) throw new
|
|
20681
|
+
if (signal?.aborted) throw new ExecutorSpawnAbortedError();
|
|
22250
20682
|
const version = parseGenericCliVersion(`${stdout}
|
|
22251
20683
|
${stderr}`);
|
|
22252
20684
|
if (version !== null || exitCode === 0) {
|
|
@@ -22318,9 +20750,9 @@ async function readClaudeCliVersion(input) {
|
|
|
22318
20750
|
}
|
|
22319
20751
|
|
|
22320
20752
|
// src/claudeExecutable.ts
|
|
22321
|
-
import * as
|
|
22322
|
-
import * as
|
|
22323
|
-
import * as
|
|
20753
|
+
import * as NodeFS2 from "node:fs";
|
|
20754
|
+
import * as NodeOS3 from "node:os";
|
|
20755
|
+
import * as NodePath6 from "node:path";
|
|
22324
20756
|
var WINDOWS_SHIM_EXTENSIONS = /* @__PURE__ */ new Set([".cmd", ".bat", ".ps1"]);
|
|
22325
20757
|
var NPM_PACKAGE_ENTRY_CANDIDATES = [
|
|
22326
20758
|
["node_modules", "@anthropic-ai", "claude-code", "bin", "claude.exe"],
|
|
@@ -22328,23 +20760,23 @@ var NPM_PACKAGE_ENTRY_CANDIDATES = [
|
|
|
22328
20760
|
];
|
|
22329
20761
|
function isExistingFile(filePath) {
|
|
22330
20762
|
try {
|
|
22331
|
-
return
|
|
20763
|
+
return NodeFS2.statSync(filePath).isFile();
|
|
22332
20764
|
} catch {
|
|
22333
20765
|
return false;
|
|
22334
20766
|
}
|
|
22335
20767
|
}
|
|
22336
|
-
function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, isFile = isExistingFile, isWindows =
|
|
20768
|
+
function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, isFile = isExistingFile, isWindows = NodeOS3.type() === "Windows_NT") {
|
|
22337
20769
|
if (!isWindows) {
|
|
22338
20770
|
return binaryPath;
|
|
22339
20771
|
}
|
|
22340
20772
|
const resolved = resolveWindowsExecutable(binaryPath, environment) ?? binaryPath;
|
|
22341
|
-
const extension =
|
|
20773
|
+
const extension = NodePath6.win32.extname(resolved).toLowerCase();
|
|
22342
20774
|
if (!WINDOWS_SHIM_EXTENSIONS.has(extension)) {
|
|
22343
20775
|
return resolved;
|
|
22344
20776
|
}
|
|
22345
|
-
const shimDirectory =
|
|
20777
|
+
const shimDirectory = NodePath6.win32.dirname(resolved);
|
|
22346
20778
|
for (const entrySegments of NPM_PACKAGE_ENTRY_CANDIDATES) {
|
|
22347
|
-
const candidate =
|
|
20779
|
+
const candidate = NodePath6.win32.join(shimDirectory, ...entrySegments);
|
|
22348
20780
|
if (isFile(candidate)) {
|
|
22349
20781
|
return candidate;
|
|
22350
20782
|
}
|
|
@@ -22354,14 +20786,14 @@ function resolveClaudeSdkExecutablePath(binaryPath, environment = process.env, i
|
|
|
22354
20786
|
function resolveWindowsExecutable(binaryPath, environment) {
|
|
22355
20787
|
const trimmed = binaryPath.trim();
|
|
22356
20788
|
if (trimmed.length === 0) return void 0;
|
|
22357
|
-
if (
|
|
20789
|
+
if (NodePath6.win32.isAbsolute(trimmed) && isExistingFile(trimmed)) return trimmed;
|
|
22358
20790
|
const pathValue = environment.PATH ?? environment.Path ?? "";
|
|
22359
20791
|
const pathext = environment.PATHEXT ?? ".EXE;.CMD;.BAT;.COM";
|
|
22360
20792
|
const extensions = pathext.split(";").filter((ext) => ext.length > 0);
|
|
22361
|
-
const hasExt =
|
|
20793
|
+
const hasExt = NodePath6.win32.extname(trimmed).length > 0;
|
|
22362
20794
|
for (const dir of pathValue.split(";")) {
|
|
22363
20795
|
if (dir.trim().length === 0) continue;
|
|
22364
|
-
const candidates = hasExt ? [
|
|
20796
|
+
const candidates = hasExt ? [NodePath6.win32.join(dir, trimmed)] : extensions.map((ext) => NodePath6.win32.join(dir, `${trimmed}${ext}`));
|
|
22365
20797
|
for (const candidate of candidates) {
|
|
22366
20798
|
if (isExistingFile(candidate)) return candidate;
|
|
22367
20799
|
}
|
|
@@ -22713,9 +21145,9 @@ var PromptQueue = class {
|
|
|
22713
21145
|
const queued = this.#queued.shift();
|
|
22714
21146
|
if (queued !== void 0) return Promise.resolve(queued);
|
|
22715
21147
|
if (this.#closed) return Promise.resolve(void 0);
|
|
22716
|
-
return new Promise((
|
|
21148
|
+
return new Promise((resolve5) => {
|
|
22717
21149
|
this.#waiters.push((result) => {
|
|
22718
|
-
|
|
21150
|
+
resolve5(result.done ? void 0 : result.value);
|
|
22719
21151
|
});
|
|
22720
21152
|
});
|
|
22721
21153
|
}
|
|
@@ -23015,175 +21447,8 @@ var claudeStructuredErrorType = (value) => {
|
|
|
23015
21447
|
return typeof type4 === "string" ? type4 : void 0;
|
|
23016
21448
|
};
|
|
23017
21449
|
|
|
23018
|
-
// ../../packages/ycodium-tool-label/src/toolLabel.ts
|
|
23019
|
-
var DETAIL_MAX_CHARS = 200;
|
|
23020
|
-
var LABEL_TEXT_MAX_CHARS = 400;
|
|
23021
|
-
var SUMMARY_KEYS = [
|
|
23022
|
-
"description",
|
|
23023
|
-
"title",
|
|
23024
|
-
"query",
|
|
23025
|
-
"pattern",
|
|
23026
|
-
"url",
|
|
23027
|
-
"command",
|
|
23028
|
-
"cmd",
|
|
23029
|
-
"prompt",
|
|
23030
|
-
"name",
|
|
23031
|
-
"path"
|
|
23032
|
-
];
|
|
23033
|
-
var PATH_KEYS = ["file_path", "notebook_path"];
|
|
23034
|
-
function asTrimmedString(value) {
|
|
23035
|
-
if (typeof value !== "string") {
|
|
23036
|
-
return void 0;
|
|
23037
|
-
}
|
|
23038
|
-
const trimmed = value.trim();
|
|
23039
|
-
return trimmed.length > 0 ? trimmed : void 0;
|
|
23040
|
-
}
|
|
23041
|
-
function asPositiveInt(value) {
|
|
23042
|
-
return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
|
|
23043
|
-
}
|
|
23044
|
-
function replacementDiffStat(input, budget) {
|
|
23045
|
-
if (input.replace_all === true) return void 0;
|
|
23046
|
-
const oldText = input.old_string ?? input.oldText;
|
|
23047
|
-
const newText = input.new_string ?? input.newText;
|
|
23048
|
-
if (typeof oldText !== "string" || typeof newText !== "string") return void 0;
|
|
23049
|
-
budget.characters -= oldText.length + newText.length;
|
|
23050
|
-
if (budget.characters < 0) return void 0;
|
|
23051
|
-
const before = oldText.match(/[^\n]*\n|[^\n]+$/gu) ?? [];
|
|
23052
|
-
const after = newText.match(/[^\n]*\n|[^\n]+$/gu) ?? [];
|
|
23053
|
-
let start = 0;
|
|
23054
|
-
let beforeEnd = before.length;
|
|
23055
|
-
let afterEnd = after.length;
|
|
23056
|
-
while (start < beforeEnd && start < afterEnd && before[start] === after[start]) start += 1;
|
|
23057
|
-
while (beforeEnd > start && afterEnd > start && before[beforeEnd - 1] === after[afterEnd - 1]) {
|
|
23058
|
-
beforeEnd -= 1;
|
|
23059
|
-
afterEnd -= 1;
|
|
23060
|
-
}
|
|
23061
|
-
const deleted = beforeEnd - start;
|
|
23062
|
-
const added = afterEnd - start;
|
|
23063
|
-
budget.cells -= deleted * added;
|
|
23064
|
-
if (budget.cells < 0) return void 0;
|
|
23065
|
-
const lengths = new Uint32Array(added + 1);
|
|
23066
|
-
for (let i = start; i < beforeEnd; i += 1) {
|
|
23067
|
-
let diagonal = 0;
|
|
23068
|
-
for (let j3 = 1; j3 <= added; j3 += 1) {
|
|
23069
|
-
const previous = lengths[j3] ?? 0;
|
|
23070
|
-
lengths[j3] = before[i] === after[start + j3 - 1] ? diagonal + 1 : Math.max(previous, lengths[j3 - 1] ?? 0);
|
|
23071
|
-
diagonal = previous;
|
|
23072
|
-
}
|
|
23073
|
-
}
|
|
23074
|
-
const shared = lengths[added] ?? 0;
|
|
23075
|
-
return { additions: added - shared, deletions: deleted - shared };
|
|
23076
|
-
}
|
|
23077
|
-
function inputDiffStat(input) {
|
|
23078
|
-
const budget = { characters: 2e5, cells: 25e4 };
|
|
23079
|
-
if (!Array.isArray(input.edits)) return replacementDiffStat(input, budget);
|
|
23080
|
-
if (input.edits.length === 0 || input.edits.length > 100 || input.replace_all === true)
|
|
23081
|
-
return void 0;
|
|
23082
|
-
let additions = 0;
|
|
23083
|
-
let deletions = 0;
|
|
23084
|
-
for (const edit of input.edits) {
|
|
23085
|
-
if (edit === null || typeof edit !== "object" || Array.isArray(edit)) return void 0;
|
|
23086
|
-
const stat5 = replacementDiffStat(edit, budget);
|
|
23087
|
-
if (!stat5) return void 0;
|
|
23088
|
-
additions += stat5.additions;
|
|
23089
|
-
deletions += stat5.deletions;
|
|
23090
|
-
}
|
|
23091
|
-
return { additions, deletions };
|
|
23092
|
-
}
|
|
23093
|
-
function collapse(value, max) {
|
|
23094
|
-
const collapsed = value.replace(/\s+/gu, " ").trim();
|
|
23095
|
-
return collapsed.length <= max ? collapsed : `${collapsed.slice(0, max - 1).trimEnd()}\u2026`;
|
|
23096
|
-
}
|
|
23097
|
-
function displayToolName(toolName) {
|
|
23098
|
-
const trimmed = toolName.trim();
|
|
23099
|
-
if (!trimmed.startsWith("mcp__")) {
|
|
23100
|
-
return trimmed;
|
|
23101
|
-
}
|
|
23102
|
-
const rest = trimmed.slice("mcp__".length).replaceAll("__", " ").trim();
|
|
23103
|
-
return rest.length > 0 ? rest : trimmed;
|
|
23104
|
-
}
|
|
23105
|
-
function readRangeSuffix(input) {
|
|
23106
|
-
const offset = asPositiveInt(input.offset);
|
|
23107
|
-
const limit = asPositiveInt(input.limit);
|
|
23108
|
-
if (offset !== void 0 && limit !== void 0) {
|
|
23109
|
-
return `(lines ${offset}-${offset + limit - 1})`;
|
|
23110
|
-
}
|
|
23111
|
-
if (offset !== void 0) {
|
|
23112
|
-
return `(from line ${offset})`;
|
|
23113
|
-
}
|
|
23114
|
-
if (limit !== void 0) {
|
|
23115
|
-
return `(first ${limit} lines)`;
|
|
23116
|
-
}
|
|
23117
|
-
return void 0;
|
|
23118
|
-
}
|
|
23119
|
-
function loneStringValue(input) {
|
|
23120
|
-
let found;
|
|
23121
|
-
for (const value of Object.values(input)) {
|
|
23122
|
-
const text2 = asTrimmedString(value);
|
|
23123
|
-
if (text2 === void 0) {
|
|
23124
|
-
continue;
|
|
23125
|
-
}
|
|
23126
|
-
if (found !== void 0) {
|
|
23127
|
-
return void 0;
|
|
23128
|
-
}
|
|
23129
|
-
found = text2;
|
|
23130
|
-
}
|
|
23131
|
-
return found;
|
|
23132
|
-
}
|
|
23133
|
-
function compactJson(input) {
|
|
23134
|
-
let serialized;
|
|
23135
|
-
try {
|
|
23136
|
-
serialized = JSON.stringify(input);
|
|
23137
|
-
} catch {
|
|
23138
|
-
return void 0;
|
|
23139
|
-
}
|
|
23140
|
-
if (!serialized || serialized === "{}" || serialized === "[]") {
|
|
23141
|
-
return void 0;
|
|
23142
|
-
}
|
|
23143
|
-
return collapse(serialized, DETAIL_MAX_CHARS);
|
|
23144
|
-
}
|
|
23145
|
-
function formatToolLabel(toolName, input) {
|
|
23146
|
-
const name = displayToolName(toolName);
|
|
23147
|
-
const diffStat = inputDiffStat(input);
|
|
23148
|
-
if (name.endsWith("visualize_visualize") && typeof input.fragment === "string") {
|
|
23149
|
-
const { fragment: _fragment, ...rest } = input;
|
|
23150
|
-
return formatToolLabel(toolName, rest);
|
|
23151
|
-
}
|
|
23152
|
-
for (const key of PATH_KEYS) {
|
|
23153
|
-
const path = asTrimmedString(input[key]);
|
|
23154
|
-
if (path === void 0) {
|
|
23155
|
-
continue;
|
|
23156
|
-
}
|
|
23157
|
-
const suffix = readRangeSuffix(input);
|
|
23158
|
-
return {
|
|
23159
|
-
name,
|
|
23160
|
-
path,
|
|
23161
|
-
...suffix ? { detail: suffix } : {},
|
|
23162
|
-
...diffStat ? { diffStat } : {},
|
|
23163
|
-
descriptive: true
|
|
23164
|
-
};
|
|
23165
|
-
}
|
|
23166
|
-
for (const key of SUMMARY_KEYS) {
|
|
23167
|
-
const value = asTrimmedString(input[key]);
|
|
23168
|
-
if (value !== void 0) {
|
|
23169
|
-
const detail = collapse(value, DETAIL_MAX_CHARS);
|
|
23170
|
-
const scope = key === "pattern" ? asTrimmedString(input.path) : void 0;
|
|
23171
|
-
return { name, ...scope ? { path: scope } : {}, detail, descriptive: true };
|
|
23172
|
-
}
|
|
23173
|
-
}
|
|
23174
|
-
const lone = loneStringValue(input);
|
|
23175
|
-
if (lone !== void 0) {
|
|
23176
|
-
return { name, detail: collapse(lone, DETAIL_MAX_CHARS), descriptive: true };
|
|
23177
|
-
}
|
|
23178
|
-
const compact = compactJson(input);
|
|
23179
|
-
return { name, ...compact ? { detail: compact } : {}, descriptive: false };
|
|
23180
|
-
}
|
|
23181
|
-
function formatToolLabelText(label) {
|
|
23182
|
-
const joined = [label.name, label.path, label.detail].filter((part) => part).join(" ");
|
|
23183
|
-
return joined.length <= LABEL_TEXT_MAX_CHARS ? joined : `${joined.slice(0, LABEL_TEXT_MAX_CHARS - 1).trimEnd()}\u2026`;
|
|
23184
|
-
}
|
|
23185
|
-
|
|
23186
21450
|
// src/toolClassify.ts
|
|
21451
|
+
import { formatToolLabel, formatToolLabelText } from "@ycodium-ai/plugin-api/display-format";
|
|
23187
21452
|
function classifyToolItemType(toolName) {
|
|
23188
21453
|
const normalized = toolName.toLowerCase();
|
|
23189
21454
|
if (normalized.startsWith("mcp__")) {
|
|
@@ -23292,12 +21557,12 @@ function claudeTaskRosterKind(input) {
|
|
|
23292
21557
|
return void 0;
|
|
23293
21558
|
}
|
|
23294
21559
|
var PENDING_TASK_MODEL_CAP = 64;
|
|
23295
|
-
function rememberPendingTaskModel(
|
|
23296
|
-
|
|
23297
|
-
if (
|
|
23298
|
-
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();
|
|
23299
21564
|
if (!oldest.done) {
|
|
23300
|
-
|
|
21565
|
+
pending.delete(oldest.value);
|
|
23301
21566
|
}
|
|
23302
21567
|
}
|
|
23303
21568
|
}
|
|
@@ -23841,128 +22106,20 @@ var makeEventEmitter = (deps) => {
|
|
|
23841
22106
|
context.events.emit({
|
|
23842
22107
|
...context.origin,
|
|
23843
22108
|
...event
|
|
23844
|
-
});
|
|
23845
|
-
};
|
|
23846
|
-
return { nowIso, randomUUIDv4, makeEventStamp, eventHeader, offerRuntimeEvent };
|
|
23847
|
-
};
|
|
23848
|
-
|
|
23849
|
-
// ../../packages/ycodium-instance-config/src/instanceConfig.ts
|
|
23850
|
-
import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
|
|
23851
|
-
function isRecord4(value) {
|
|
23852
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
23853
|
-
}
|
|
23854
|
-
function readString3(value) {
|
|
23855
|
-
return typeof value === "string" ? value : "";
|
|
23856
|
-
}
|
|
23857
|
-
function readTrimmed(value) {
|
|
23858
|
-
return readString3(value).trim();
|
|
23859
|
-
}
|
|
23860
|
-
function modelIdFromSelection(selection) {
|
|
23861
|
-
if (!isRecord4(selection)) return void 0;
|
|
23862
|
-
const model = selection["model"];
|
|
23863
|
-
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
23864
|
-
}
|
|
23865
|
-
function readEnvironment(value) {
|
|
23866
|
-
if (!Array.isArray(value)) return {};
|
|
23867
|
-
const entries = [];
|
|
23868
|
-
for (const entry of value) {
|
|
23869
|
-
if (!isRecord4(entry)) continue;
|
|
23870
|
-
const name = readTrimmed(entry["name"]);
|
|
23871
|
-
if (name.length === 0) continue;
|
|
23872
|
-
entries.push([name, readString3(entry["value"])]);
|
|
23873
|
-
}
|
|
23874
|
-
return Object.fromEntries(entries);
|
|
23875
|
-
}
|
|
23876
|
-
function instanceSettings(config) {
|
|
23877
|
-
if (!isRecord4(config)) return {};
|
|
23878
|
-
return isRecord4(config["config"]) ? config["config"] : config;
|
|
23879
|
-
}
|
|
23880
|
-
function readInstanceEnvelope(config) {
|
|
23881
|
-
const envelope = isRecord4(config) ? config : {};
|
|
23882
|
-
const settings = instanceSettings(config);
|
|
23883
|
-
return {
|
|
23884
|
-
settings,
|
|
23885
|
-
settingOrEnvelope: (key) => readTrimmed(settings[key]) || readTrimmed(envelope[key]),
|
|
23886
|
-
environment: readEnvironment(envelope["environment"]),
|
|
23887
|
-
envelopeDriver: readTrimmed(envelope["driver"]) || void 0
|
|
23888
|
-
};
|
|
23889
|
-
}
|
|
23890
|
-
function readCustomModel(entry) {
|
|
23891
|
-
if (typeof entry === "string") {
|
|
23892
|
-
const slug2 = entry.trim();
|
|
23893
|
-
return slug2.length > 0 ? { slug: slug2 } : void 0;
|
|
23894
|
-
}
|
|
23895
|
-
if (!isRecord4(entry)) return void 0;
|
|
23896
|
-
const slug = readTrimmed(entry["slug"]);
|
|
23897
|
-
if (slug.length === 0) return void 0;
|
|
23898
|
-
const aliasesRaw = entry["aliases"];
|
|
23899
|
-
const aliases = Array.isArray(aliasesRaw) ? aliasesRaw.filter(
|
|
23900
|
-
(alias) => typeof alias === "string" && alias.trim().length > 0
|
|
23901
|
-
) : void 0;
|
|
23902
|
-
const contextWindow = typeof entry["contextWindow"] === "number" && Number.isFinite(entry["contextWindow"]) && entry["contextWindow"] > 0 ? Math.round(entry["contextWindow"]) : void 0;
|
|
23903
|
-
const label = readTrimmed(entry["label"]);
|
|
23904
|
-
return {
|
|
23905
|
-
slug,
|
|
23906
|
-
...label ? { label } : {},
|
|
23907
|
-
...contextWindow !== void 0 ? { contextWindow } : {},
|
|
23908
|
-
...aliases && aliases.length > 0 ? { aliases } : {}
|
|
22109
|
+
});
|
|
23909
22110
|
};
|
|
23910
|
-
}
|
|
23911
|
-
|
|
23912
|
-
// ../../packages/ycodium-instance-config/src/launchArgs.ts
|
|
23913
|
-
function tokenizeShellWords(value) {
|
|
23914
|
-
const input = value.trim();
|
|
23915
|
-
if (!input) return [];
|
|
23916
|
-
const tokens = [];
|
|
23917
|
-
let current = "";
|
|
23918
|
-
let quote2;
|
|
23919
|
-
let quoted = false;
|
|
23920
|
-
for (let index = 0; index < input.length; index++) {
|
|
23921
|
-
const char = input[index];
|
|
23922
|
-
if (char === void 0) continue;
|
|
23923
|
-
if (quote2) {
|
|
23924
|
-
if (char === quote2) {
|
|
23925
|
-
quote2 = void 0;
|
|
23926
|
-
quoted = true;
|
|
23927
|
-
} else if (char === "\\" && quote2 === '"') {
|
|
23928
|
-
const next = input[index + 1];
|
|
23929
|
-
if (next !== void 0 && ['"', "\\", "$", "`"].includes(next)) {
|
|
23930
|
-
current += next;
|
|
23931
|
-
index++;
|
|
23932
|
-
} else {
|
|
23933
|
-
current += char;
|
|
23934
|
-
}
|
|
23935
|
-
} else {
|
|
23936
|
-
current += char;
|
|
23937
|
-
}
|
|
23938
|
-
continue;
|
|
23939
|
-
}
|
|
23940
|
-
if (char === "'" || char === '"') {
|
|
23941
|
-
quote2 = char;
|
|
23942
|
-
quoted = true;
|
|
23943
|
-
} else if (/\s/.test(char)) {
|
|
23944
|
-
if (current || quoted) {
|
|
23945
|
-
tokens.push(current);
|
|
23946
|
-
current = "";
|
|
23947
|
-
quoted = false;
|
|
23948
|
-
}
|
|
23949
|
-
} else if (char === "\\") {
|
|
23950
|
-
const next = input[index + 1];
|
|
23951
|
-
if (next !== void 0 && /\s/.test(next)) {
|
|
23952
|
-
current += next;
|
|
23953
|
-
index++;
|
|
23954
|
-
} else {
|
|
23955
|
-
current += char;
|
|
23956
|
-
}
|
|
23957
|
-
} else {
|
|
23958
|
-
current += char;
|
|
23959
|
-
}
|
|
23960
|
-
}
|
|
23961
|
-
if (current || quoted) tokens.push(current);
|
|
23962
|
-
return tokens;
|
|
23963
|
-
}
|
|
22111
|
+
return { nowIso, randomUUIDv4, makeEventStamp, eventHeader, offerRuntimeEvent };
|
|
22112
|
+
};
|
|
23964
22113
|
|
|
23965
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";
|
|
23966
22123
|
var CLAUDE_AUTO_COMPACT_WINDOW_PATTERN = /^(?:|[1-9]\d{5}|1000000)$/;
|
|
23967
22124
|
function readThinkingOptions(entry) {
|
|
23968
22125
|
const thinkingRaw = entry["thinkingOptions"];
|
|
@@ -24056,9 +22213,9 @@ import {
|
|
|
24056
22213
|
} from "@ycodium-ai/plugin-api/executor";
|
|
24057
22214
|
|
|
24058
22215
|
// src/sdkModels.ts
|
|
24059
|
-
import * as
|
|
22216
|
+
import * as NodeOS4 from "node:os";
|
|
24060
22217
|
import { REASONING_OPTION_LABEL as REASONING_OPTION_LABEL2, reasoningEffortShortLabel } from "@ycodium-ai/plugin-api/executor";
|
|
24061
|
-
import { isOperationCleanupError as
|
|
22218
|
+
import { isOperationCleanupError as isOperationCleanupError2 } from "@ycodium-ai/plugin-api/process-operation";
|
|
24062
22219
|
|
|
24063
22220
|
// src/sdkAccount.ts
|
|
24064
22221
|
var text = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
@@ -24223,12 +22380,12 @@ function makeClaudeProcessSpawner(host, stderr, config = {}) {
|
|
|
24223
22380
|
// src/sdkRead.ts
|
|
24224
22381
|
var silentPrompt = (signal) => ({
|
|
24225
22382
|
[Symbol.asyncIterator]: () => ({
|
|
24226
|
-
next: () => new Promise((
|
|
22383
|
+
next: () => new Promise((resolve5) => {
|
|
24227
22384
|
if (signal.aborted) {
|
|
24228
|
-
|
|
22385
|
+
resolve5({ done: true, value: void 0 });
|
|
24229
22386
|
return;
|
|
24230
22387
|
}
|
|
24231
|
-
signal.addEventListener("abort", () =>
|
|
22388
|
+
signal.addEventListener("abort", () => resolve5({ done: true, value: void 0 }), {
|
|
24232
22389
|
once: true
|
|
24233
22390
|
});
|
|
24234
22391
|
}),
|
|
@@ -24353,7 +22510,7 @@ var readClaudeSdkProbe = async (input) => {
|
|
|
24353
22510
|
}
|
|
24354
22511
|
);
|
|
24355
22512
|
} catch (cause) {
|
|
24356
|
-
if (
|
|
22513
|
+
if (isOperationCleanupError2(cause)) throw cause;
|
|
24357
22514
|
input.signal?.throwIfAborted();
|
|
24358
22515
|
return void 0;
|
|
24359
22516
|
}
|
|
@@ -24366,7 +22523,7 @@ function claudeModelProbeEnvironment(environment) {
|
|
|
24366
22523
|
CLAUDE_CODE_IDE_SKIP_AUTO_INSTALL: "1"
|
|
24367
22524
|
};
|
|
24368
22525
|
}
|
|
24369
|
-
var claudeSdkModelsCwd = () =>
|
|
22526
|
+
var claudeSdkModelsCwd = () => NodeOS4.tmpdir();
|
|
24370
22527
|
|
|
24371
22528
|
// src/spawnEnvironment.ts
|
|
24372
22529
|
function changedSpawnEnvironmentKeys(previous, next) {
|
|
@@ -24632,59 +22789,25 @@ import {
|
|
|
24632
22789
|
reasoningLevelFallbackWarning
|
|
24633
22790
|
} from "@ycodium-ai/plugin-api/executor";
|
|
24634
22791
|
|
|
24635
|
-
// ../../packages/ycodium-composer-tokens/src/skillTokens.ts
|
|
24636
|
-
var SKILL_TOKEN_NAME_PATTERN = "[a-zA-Z][a-zA-Z0-9:_-]*";
|
|
24637
|
-
var SESSION_SKILL_NAMESPACE = "ycodium";
|
|
24638
|
-
var SESSION_SKILL_PREFIX = `${SESSION_SKILL_NAMESPACE}:`;
|
|
24639
|
-
var SKILL_TOKEN_REGEX = new RegExp(
|
|
24640
|
-
String.raw`(^|\s)([$/])(${SKILL_TOKEN_NAME_PATTERN})(?=\s|$)`,
|
|
24641
|
-
"g"
|
|
24642
|
-
);
|
|
24643
|
-
function findSkillTokens(text2) {
|
|
24644
|
-
return [...text2.matchAll(SKILL_TOKEN_REGEX)].map((match) => {
|
|
24645
|
-
const start = (match.index ?? 0) + (match[1]?.length ?? 0);
|
|
24646
|
-
const name = match[3] ?? "";
|
|
24647
|
-
return { sigil: match[2], name, start, end: start + name.length + 1 };
|
|
24648
|
-
});
|
|
24649
|
-
}
|
|
24650
|
-
var SKILL_TOKEN_AT = new RegExp(String.raw`([$/])(${SKILL_TOKEN_NAME_PATTERN})(?=\s|$)`, "y");
|
|
24651
|
-
function resolveSkillName(name, known) {
|
|
24652
|
-
if (known.has(name)) return name;
|
|
24653
|
-
if (!name.startsWith(SESSION_SKILL_PREFIX)) return void 0;
|
|
24654
|
-
const bare = name.slice(SESSION_SKILL_PREFIX.length);
|
|
24655
|
-
return known.has(bare) ? bare : void 0;
|
|
24656
|
-
}
|
|
24657
|
-
function lookupSkill(name, index) {
|
|
24658
|
-
const exact = index.get(name);
|
|
24659
|
-
if (exact !== void 0) return exact;
|
|
24660
|
-
if (!name.startsWith(SESSION_SKILL_PREFIX)) return void 0;
|
|
24661
|
-
const session = index.get(name.slice(SESSION_SKILL_PREFIX.length));
|
|
24662
|
-
return session?.scope === SESSION_SKILL_NAMESPACE ? session : void 0;
|
|
24663
|
-
}
|
|
24664
|
-
var SLASH_SKILL_TOKEN = new RegExp(String.raw`^/(${SKILL_TOKEN_NAME_PATTERN})$`);
|
|
24665
|
-
function matchSkillTokens(text2, index) {
|
|
24666
|
-
if (index.size === 0) return [];
|
|
24667
|
-
return findSkillTokens(text2).flatMap((token) => {
|
|
24668
|
-
const skill = lookupSkill(token.name, index);
|
|
24669
|
-
return skill === void 0 ? [] : [{ ...token, skill }];
|
|
24670
|
-
});
|
|
24671
|
-
}
|
|
24672
|
-
function skillInvocationNotice(names) {
|
|
24673
|
-
return `The user invoked these skills in this message; run them as requested: ${names.map((name) => `$${name}`).join(", ")}.`;
|
|
24674
|
-
}
|
|
24675
|
-
|
|
24676
22792
|
// src/claudeSkillDispatch.ts
|
|
22793
|
+
import {
|
|
22794
|
+
findSkillTokens,
|
|
22795
|
+
matchSkillTokens,
|
|
22796
|
+
resolveSkillName,
|
|
22797
|
+
skillInvocationNotice
|
|
22798
|
+
} from "@ycodium-ai/plugin-api/composer";
|
|
24677
22799
|
import { EXECUTOR_SEND_TURN_MAX_INPUT_CHARS as EXECUTOR_SEND_TURN_MAX_INPUT_CHARS2 } from "@ycodium-ai/plugin-api/executor";
|
|
24678
22800
|
|
|
24679
22801
|
// src/claudeInlineSkill.ts
|
|
24680
|
-
import * as
|
|
24681
|
-
import * as
|
|
22802
|
+
import * as NodeFSP2 from "node:fs/promises";
|
|
22803
|
+
import * as NodePath7 from "node:path";
|
|
24682
22804
|
import { EXECUTOR_SEND_TURN_MAX_INPUT_CHARS } from "@ycodium-ai/plugin-api/executor";
|
|
24683
22805
|
|
|
24684
22806
|
// src/claudeSkillArguments.ts
|
|
22807
|
+
import { tokenizeShellWords as tokenizeShellWords2 } from "@ycodium-ai/plugin-api/instance-config";
|
|
24685
22808
|
var escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
24686
22809
|
function substituteSkillArguments(body, args, argumentNames) {
|
|
24687
|
-
const values =
|
|
22810
|
+
const values = tokenizeShellWords2(args);
|
|
24688
22811
|
const named = argumentNames.map(escapeRegExp).toSorted((left, right) => right.length - left.length);
|
|
24689
22812
|
const pattern = new RegExp(
|
|
24690
22813
|
String.raw`(\\*)\$(?:ARGUMENTS\[(\d+)\]|(ARGUMENTS)(?![A-Za-z0-9_])|(\d+)` + (named.length > 0 ? String.raw`|(${named.join("|")})(?![A-Za-z0-9_-])` : "") + ")",
|
|
@@ -24769,7 +22892,7 @@ function readSkillSource(contents) {
|
|
|
24769
22892
|
}
|
|
24770
22893
|
var loadSkill = async (path) => {
|
|
24771
22894
|
try {
|
|
24772
|
-
const bytes = await
|
|
22895
|
+
const bytes = await NodeFSP2.readFile(path);
|
|
24773
22896
|
if (bytes.byteLength > MAX_INLINE_SKILL_BYTES) {
|
|
24774
22897
|
return { ok: false, reason: `${path} is larger than ${MAX_INLINE_SKILL_BYTES / 1024} KB` };
|
|
24775
22898
|
}
|
|
@@ -24789,7 +22912,7 @@ var notLoadedBlock = (name, reason) => skillBlock(name, [
|
|
|
24789
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.`
|
|
24790
22913
|
]);
|
|
24791
22914
|
var renderLoaded = (invocation, source, variables) => {
|
|
24792
|
-
const skillDir =
|
|
22915
|
+
const skillDir = NodePath7.dirname(invocation.path);
|
|
24793
22916
|
const known = {
|
|
24794
22917
|
CLAUDE_SKILL_DIR: skillDir,
|
|
24795
22918
|
CLAUDE_PROJECT_DIR: variables.projectDir,
|
|
@@ -24998,12 +23121,12 @@ async function applyClaudePermissionMode(context, mode, control) {
|
|
|
24998
23121
|
}
|
|
24999
23122
|
|
|
25000
23123
|
// src/adapter/sessionOptions.ts
|
|
25001
|
-
import { modelSelectionStringOption
|
|
23124
|
+
import { modelSelectionStringOption } from "@ycodium-ai/plugin-api/executor";
|
|
25002
23125
|
function resolveClaudeSessionOptions(input) {
|
|
25003
23126
|
const { modelSelection, recipe } = input;
|
|
25004
23127
|
const caps = claudeModelCapabilities(modelSelection?.model, input.catalog, recipe.customModels);
|
|
25005
23128
|
const descriptors = caps.optionDescriptors;
|
|
25006
|
-
const rawEffort =
|
|
23129
|
+
const rawEffort = modelSelectionStringOption(modelSelection, "effort");
|
|
25007
23130
|
const effort = resolveClaudeEffort(caps, rawEffort) ?? null;
|
|
25008
23131
|
const supports = (id2) => descriptors.some((descriptor) => descriptor.type === "boolean" && descriptor.id === id2);
|
|
25009
23132
|
const fastMode = getModelSelectionBooleanOptionValue(modelSelection, "fastMode") === true && supports("fastMode");
|
|
@@ -25818,7 +23941,7 @@ var makeSessionControls = (deps) => {
|
|
|
25818
23941
|
context.query.interrupt().then(() => settled.promise).then(() => {
|
|
25819
23942
|
acknowledged = true;
|
|
25820
23943
|
}),
|
|
25821
|
-
new Promise((
|
|
23944
|
+
new Promise((resolve5) => setTimeout(resolve5, CLAUDE_INTERRUPT_GRACE_MS))
|
|
25822
23945
|
]);
|
|
25823
23946
|
} catch (cause) {
|
|
25824
23947
|
throw toRequestError(threadId, "turn/interrupt", cause);
|
|
@@ -25838,12 +23961,12 @@ var makeSessionControls = (deps) => {
|
|
|
25838
23961
|
const mapPluginDecision = (decision) => decision === "allow" ? "accept" : "decline";
|
|
25839
23962
|
const respondToRequest = async (threadId, requestId, decision, reason) => {
|
|
25840
23963
|
const context = requireSession(threadId);
|
|
25841
|
-
const
|
|
25842
|
-
if (!
|
|
23964
|
+
const pending = context.pendingApprovals.get(requestId);
|
|
23965
|
+
if (!pending) {
|
|
25843
23966
|
throw new Error(`Unknown pending approval request: ${requestId}`);
|
|
25844
23967
|
}
|
|
25845
23968
|
context.pendingApprovals.delete(requestId);
|
|
25846
|
-
|
|
23969
|
+
pending.decision.resolve({
|
|
25847
23970
|
decision: mapPluginDecision(decision),
|
|
25848
23971
|
...reason ? { reason } : {}
|
|
25849
23972
|
});
|
|
@@ -25874,9 +23997,9 @@ var makeSessionControls = (deps) => {
|
|
|
25874
23997
|
if (permissionMode !== "bypassPermissions") {
|
|
25875
23998
|
return;
|
|
25876
23999
|
}
|
|
25877
|
-
for (const [requestId,
|
|
24000
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
25878
24001
|
context.pendingApprovals.delete(requestId);
|
|
25879
|
-
|
|
24002
|
+
pending.decision.resolve({ decision: "accept" });
|
|
25880
24003
|
}
|
|
25881
24004
|
};
|
|
25882
24005
|
const setNativeMode = async (threadId, nativeModeId) => {
|
|
@@ -25902,19 +24025,19 @@ var makeSessionControls = (deps) => {
|
|
|
25902
24025
|
if (nativeModeId !== "bypassPermissions") {
|
|
25903
24026
|
return;
|
|
25904
24027
|
}
|
|
25905
|
-
for (const [requestId,
|
|
24028
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
25906
24029
|
context.pendingApprovals.delete(requestId);
|
|
25907
|
-
|
|
24030
|
+
pending.decision.resolve({ decision: "accept" });
|
|
25908
24031
|
}
|
|
25909
24032
|
};
|
|
25910
24033
|
const respondToUserInput = async (threadId, requestId, answers) => {
|
|
25911
24034
|
const context = requireSession(threadId);
|
|
25912
|
-
const
|
|
25913
|
-
if (!
|
|
24035
|
+
const pending = context.pendingUserInputs.get(requestId);
|
|
24036
|
+
if (!pending) {
|
|
25914
24037
|
throw new Error(`Unknown pending user-input request: ${requestId}`);
|
|
25915
24038
|
}
|
|
25916
24039
|
context.pendingUserInputs.delete(requestId);
|
|
25917
|
-
|
|
24040
|
+
pending.answers.resolve(answers ?? {});
|
|
25918
24041
|
};
|
|
25919
24042
|
return {
|
|
25920
24043
|
compactContext,
|
|
@@ -25950,8 +24073,8 @@ var makeSessionLifecycle = (deps) => {
|
|
|
25950
24073
|
const claim = context.turnState?.resultClaim;
|
|
25951
24074
|
if (claim === void 0) return;
|
|
25952
24075
|
let timer;
|
|
25953
|
-
const timeout = new Promise((
|
|
25954
|
-
timer = setTimeout(() =>
|
|
24076
|
+
const timeout = new Promise((resolve5) => {
|
|
24077
|
+
timer = setTimeout(() => resolve5("timeout"), RESULT_CLAIM_WAIT_MS);
|
|
25955
24078
|
});
|
|
25956
24079
|
try {
|
|
25957
24080
|
const outcome = await Promise.race([claim.then(() => "settled"), timeout]);
|
|
@@ -26017,8 +24140,8 @@ var makeSessionLifecycle = (deps) => {
|
|
|
26017
24140
|
providerRefs: nativeProviderRefs()
|
|
26018
24141
|
});
|
|
26019
24142
|
}
|
|
26020
|
-
for (const [requestId,
|
|
26021
|
-
|
|
24143
|
+
for (const [requestId, pending] of context.pendingApprovals) {
|
|
24144
|
+
pending.decision.resolve({ decision: "cancel", resolvedEventSent: true });
|
|
26022
24145
|
const stamp = await makeEventStamp();
|
|
26023
24146
|
offerRuntimeEvent(context, {
|
|
26024
24147
|
type: "request.resolved",
|
|
@@ -26026,15 +24149,15 @@ var makeSessionLifecycle = (deps) => {
|
|
|
26026
24149
|
...context.turnState ? { turnId: asCanonicalTurnId(context.turnState.turnId) } : {},
|
|
26027
24150
|
requestId: asRuntimeRequestId(requestId),
|
|
26028
24151
|
payload: {
|
|
26029
|
-
requestType:
|
|
24152
|
+
requestType: pending.requestType,
|
|
26030
24153
|
decision: "cancel"
|
|
26031
24154
|
},
|
|
26032
24155
|
providerRefs: nativeProviderRefs()
|
|
26033
24156
|
});
|
|
26034
24157
|
}
|
|
26035
24158
|
context.pendingApprovals.clear();
|
|
26036
|
-
for (const
|
|
26037
|
-
|
|
24159
|
+
for (const pending of Array.from(context.pendingUserInputs.values())) {
|
|
24160
|
+
pending.cancel();
|
|
26038
24161
|
}
|
|
26039
24162
|
if (context.turnState && !options?.recovering) {
|
|
26040
24163
|
await awaitClaimedResult(context);
|
|
@@ -26050,7 +24173,7 @@ var makeSessionLifecycle = (deps) => {
|
|
|
26050
24173
|
if (streamFiber) {
|
|
26051
24174
|
await Promise.race([
|
|
26052
24175
|
streamFiber.catch(() => void 0),
|
|
26053
|
-
new Promise((
|
|
24176
|
+
new Promise((resolve5) => setTimeout(resolve5, 1e3))
|
|
26054
24177
|
]);
|
|
26055
24178
|
}
|
|
26056
24179
|
const updatedAt = nowIso();
|
|
@@ -26217,18 +24340,18 @@ async function recoverFirstPrompt(input) {
|
|
|
26217
24340
|
}
|
|
26218
24341
|
|
|
26219
24342
|
// src/adapter/startSession.ts
|
|
26220
|
-
import * as
|
|
24343
|
+
import * as NodeFSP4 from "node:fs/promises";
|
|
26221
24344
|
|
|
26222
24345
|
// src/claudeMcpConfig.ts
|
|
26223
|
-
import * as
|
|
26224
|
-
import * as
|
|
26225
|
-
import * as
|
|
26226
|
-
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";
|
|
26227
24350
|
async function createClaudeMcpConfig(mcpServers, log) {
|
|
26228
24351
|
let directory;
|
|
26229
24352
|
let cleanupWork;
|
|
26230
24353
|
const cleanup = () => {
|
|
26231
|
-
cleanupWork ??= directory === void 0 ? Promise.resolve() :
|
|
24354
|
+
cleanupWork ??= directory === void 0 ? Promise.resolve() : NodeFSP3.rm(directory, { recursive: true, force: true }).catch(() => {
|
|
26232
24355
|
log.warn("claude.mcpConfig.cleanupFailed");
|
|
26233
24356
|
});
|
|
26234
24357
|
return cleanupWork;
|
|
@@ -26237,11 +24360,11 @@ async function createClaudeMcpConfig(mcpServers, log) {
|
|
|
26237
24360
|
return { path: void 0, cleanup };
|
|
26238
24361
|
}
|
|
26239
24362
|
try {
|
|
26240
|
-
directory = await
|
|
26241
|
-
const file =
|
|
26242
|
-
await
|
|
26243
|
-
await
|
|
26244
|
-
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;
|
|
26245
24368
|
});
|
|
26246
24369
|
return { path: file, cleanup };
|
|
26247
24370
|
} catch (cause) {
|
|
@@ -26301,8 +24424,8 @@ function toClaudeMcpServers(entries) {
|
|
|
26301
24424
|
}
|
|
26302
24425
|
var unreadableTranscript = async (transcriptPath) => {
|
|
26303
24426
|
try {
|
|
26304
|
-
if (!(await
|
|
26305
|
-
await
|
|
24427
|
+
if (!(await NodeFSP4.stat(transcriptPath)).isFile()) return "transcript-unreadable";
|
|
24428
|
+
await NodeFSP4.access(transcriptPath, NodeFSP4.constants.R_OK);
|
|
26306
24429
|
return void 0;
|
|
26307
24430
|
} catch (cause) {
|
|
26308
24431
|
const code = cause.code;
|
|
@@ -26479,8 +24602,8 @@ var makeStartSession = (deps) => {
|
|
|
26479
24602
|
try {
|
|
26480
24603
|
return await Promise.race([
|
|
26481
24604
|
contextDeferred.promise,
|
|
26482
|
-
new Promise((
|
|
26483
|
-
timer = setTimeout(() =>
|
|
24605
|
+
new Promise((resolve5) => {
|
|
24606
|
+
timer = setTimeout(() => resolve5(void 0), CLAUDE_SESSION_CONTEXT_WAIT_MS);
|
|
26484
24607
|
})
|
|
26485
24608
|
]);
|
|
26486
24609
|
} catch {
|
|
@@ -27058,8 +25181,8 @@ var makeStreamEventHandler = (deps) => {
|
|
|
27058
25181
|
};
|
|
27059
25182
|
|
|
27060
25183
|
// src/claudeWorkspaceInventory.ts
|
|
27061
|
-
import * as
|
|
27062
|
-
import * as
|
|
25184
|
+
import * as NodeFSP5 from "node:fs/promises";
|
|
25185
|
+
import * as NodePath9 from "node:path";
|
|
27063
25186
|
var MAX_COMMAND_DEPTH = 5;
|
|
27064
25187
|
var MAX_COMMAND_FILES = 500;
|
|
27065
25188
|
var MAX_DESCRIPTION_LENGTH = 200;
|
|
@@ -27077,7 +25200,7 @@ var firstBodyLine = (contents) => {
|
|
|
27077
25200
|
return void 0;
|
|
27078
25201
|
};
|
|
27079
25202
|
var scanCommands = async (claudeDir) => {
|
|
27080
|
-
const root =
|
|
25203
|
+
const root = NodePath9.join(claudeDir, "commands");
|
|
27081
25204
|
const commands = /* @__PURE__ */ new Map();
|
|
27082
25205
|
const watched = [root];
|
|
27083
25206
|
let level = [root];
|
|
@@ -27085,9 +25208,9 @@ var scanCommands = async (claudeDir) => {
|
|
|
27085
25208
|
for (let depth = 0; depth < MAX_COMMAND_DEPTH && level.length > 0; depth += 1) {
|
|
27086
25209
|
const next = [];
|
|
27087
25210
|
for (const directory of level) {
|
|
27088
|
-
const entries = await
|
|
25211
|
+
const entries = await NodeFSP5.readdir(directory, { withFileTypes: true }).catch(() => []);
|
|
27089
25212
|
for (const entry of entries.toSorted((left, right) => left.name.localeCompare(right.name))) {
|
|
27090
|
-
const entryPath =
|
|
25213
|
+
const entryPath = NodePath9.join(directory, entry.name);
|
|
27091
25214
|
if (entry.isDirectory()) {
|
|
27092
25215
|
next.push(entryPath);
|
|
27093
25216
|
watched.push(entryPath);
|
|
@@ -27099,7 +25222,7 @@ var scanCommands = async (claudeDir) => {
|
|
|
27099
25222
|
files += 1;
|
|
27100
25223
|
const name = entry.name.slice(0, -".md".length).trim();
|
|
27101
25224
|
if (name.length === 0 || commands.has(name)) continue;
|
|
27102
|
-
const contents = await
|
|
25225
|
+
const contents = await NodeFSP5.readFile(entryPath, "utf8").catch(() => void 0);
|
|
27103
25226
|
if (contents === void 0) continue;
|
|
27104
25227
|
const frontMatter = parseSkillFrontMatter(contents);
|
|
27105
25228
|
const description = frontMatter.description ?? firstBodyLine(contents);
|
|
@@ -27115,13 +25238,13 @@ var scanCommands = async (claudeDir) => {
|
|
|
27115
25238
|
return { commands: [...commands.values()], watched };
|
|
27116
25239
|
};
|
|
27117
25240
|
var watchSkillsRoot = async (claudeDir) => {
|
|
27118
|
-
const root =
|
|
27119
|
-
const entries = await
|
|
25241
|
+
const root = NodePath9.join(claudeDir, "skills");
|
|
25242
|
+
const entries = await NodeFSP5.readdir(root).catch(() => []);
|
|
27120
25243
|
return [
|
|
27121
25244
|
root,
|
|
27122
25245
|
...entries.flatMap((entry) => [
|
|
27123
|
-
|
|
27124
|
-
|
|
25246
|
+
NodePath9.join(root, entry),
|
|
25247
|
+
NodePath9.join(root, entry, "SKILL.md")
|
|
27125
25248
|
])
|
|
27126
25249
|
];
|
|
27127
25250
|
};
|
|
@@ -27132,7 +25255,7 @@ var mergeByName = (base, preferred) => {
|
|
|
27132
25255
|
return [...merged.values()].toSorted((left, right) => left.name.localeCompare(right.name));
|
|
27133
25256
|
};
|
|
27134
25257
|
var discoverClaudeWorkspaceInventory = async (input) => {
|
|
27135
|
-
const projectClaudeDir =
|
|
25258
|
+
const projectClaudeDir = NodePath9.join(input.cwd, ".claude");
|
|
27136
25259
|
const [userCommands, projectCommands, skills, userSkillWatch, projectSkillWatch] = await Promise.all([
|
|
27137
25260
|
scanCommands(input.configDirPath),
|
|
27138
25261
|
scanCommands(projectClaudeDir),
|
|
@@ -27154,9 +25277,9 @@ var discoverClaudeWorkspaceInventory = async (input) => {
|
|
|
27154
25277
|
...userSkillWatch,
|
|
27155
25278
|
...projectSkillWatch,
|
|
27156
25279
|
// `skillOverrides` 在这几个设置文件里:开关一个技能也要重查。
|
|
27157
|
-
|
|
27158
|
-
|
|
27159
|
-
|
|
25280
|
+
NodePath9.join(input.configDirPath, "settings.json"),
|
|
25281
|
+
NodePath9.join(projectClaudeDir, "settings.json"),
|
|
25282
|
+
NodePath9.join(projectClaudeDir, "settings.local.json")
|
|
27160
25283
|
]
|
|
27161
25284
|
};
|
|
27162
25285
|
};
|
|
@@ -27955,7 +26078,7 @@ var makeTurnLifecycle = (deps) => {
|
|
|
27955
26078
|
};
|
|
27956
26079
|
|
|
27957
26080
|
// src/adapter/turnMessages.ts
|
|
27958
|
-
import * as
|
|
26081
|
+
import * as NodePath10 from "node:path";
|
|
27959
26082
|
var makeTurnMessageHandlers = (deps) => {
|
|
27960
26083
|
const {
|
|
27961
26084
|
emitter,
|
|
@@ -28177,7 +26300,7 @@ var makeTurnMessageHandlers = (deps) => {
|
|
|
28177
26300
|
claudeFailureHint({
|
|
28178
26301
|
authenticationFailed: context.turnState?.authenticationFailed === true,
|
|
28179
26302
|
environment: buildLaunchEnvironment(),
|
|
28180
|
-
cwd:
|
|
26303
|
+
cwd: NodePath10.resolve(context.session.cwd ?? "."),
|
|
28181
26304
|
...context.turnState === void 0 ? {} : {
|
|
28182
26305
|
usageLimit: {
|
|
28183
26306
|
rejected: context.turnState.rejectedRateLimits,
|
|
@@ -28235,85 +26358,36 @@ function claudeSignInCommand(credentialsPath, platform4) {
|
|
|
28235
26358
|
}
|
|
28236
26359
|
|
|
28237
26360
|
// src/sessions.ts
|
|
28238
|
-
import * as
|
|
28239
|
-
import * as
|
|
28240
|
-
import * as
|
|
28241
|
-
|
|
28242
|
-
|
|
28243
|
-
|
|
28244
|
-
|
|
28245
|
-
|
|
28246
|
-
|
|
28247
|
-
|
|
28248
|
-
|
|
28249
|
-
|
|
28250
|
-
|
|
28251
|
-
|
|
28252
|
-
|
|
28253
|
-
|
|
28254
|
-
|
|
28255
|
-
}
|
|
28256
|
-
function readableContent(value, textTypes) {
|
|
28257
|
-
if (typeof value === "string") return value;
|
|
28258
|
-
if (!Array.isArray(value)) return "";
|
|
28259
|
-
return value.flatMap((entry) => {
|
|
28260
|
-
if (typeof entry === "string") return [entry];
|
|
28261
|
-
const block = record2(entry);
|
|
28262
|
-
return block && textTypes.includes(String(block.type)) && typeof block.text === "string" ? [block.text] : [];
|
|
28263
|
-
}).join("\n\n");
|
|
28264
|
-
}
|
|
28265
|
-
function toolInput(value) {
|
|
28266
|
-
if (typeof value === "string") return value;
|
|
28267
|
-
const input = record2(value);
|
|
28268
|
-
if (input && Object.keys(input).length === 1 && typeof input.command === "string")
|
|
28269
|
-
return input.command;
|
|
28270
|
-
if (input && Object.keys(input).length === 1 && typeof input.cmd === "string") return input.cmd;
|
|
28271
|
-
if (value === void 0 || value === null) return void 0;
|
|
28272
|
-
try {
|
|
28273
|
-
return JSON.stringify(value, null, 2);
|
|
28274
|
-
} catch {
|
|
28275
|
-
return void 0;
|
|
28276
|
-
}
|
|
28277
|
-
}
|
|
28278
|
-
function bounded(value, tail = false) {
|
|
28279
|
-
if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
|
|
28280
|
-
const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
|
|
28281
|
-
const character = value.charCodeAt(offset);
|
|
28282
|
-
const previous = value.charCodeAt(offset - 1);
|
|
28283
|
-
const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
|
|
28284
|
-
return {
|
|
28285
|
-
text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
|
|
28286
|
-
truncated: true
|
|
28287
|
-
};
|
|
28288
|
-
}
|
|
28289
|
-
function inputPayload(input) {
|
|
28290
|
-
if (input === void 0) return {};
|
|
28291
|
-
const result = bounded(input);
|
|
28292
|
-
return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
|
|
28293
|
-
}
|
|
28294
|
-
function outputPayload(output) {
|
|
28295
|
-
if (output === void 0) return {};
|
|
28296
|
-
const result = bounded(output, true);
|
|
28297
|
-
return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
|
|
28298
|
-
}
|
|
28299
|
-
function reasoning(identity, text2, streamKind) {
|
|
28300
|
-
const result = bounded(text2);
|
|
28301
|
-
return {
|
|
28302
|
-
...identity,
|
|
28303
|
-
kind: "reasoning",
|
|
28304
|
-
tone: "info",
|
|
28305
|
-
summary: "Reasoning",
|
|
28306
|
-
payload: {
|
|
28307
|
-
text: result.text,
|
|
28308
|
-
streamKind,
|
|
28309
|
-
chars: result.text.length,
|
|
28310
|
-
streaming: false,
|
|
28311
|
-
...result.truncated ? { truncated: true } : {}
|
|
28312
|
-
}
|
|
28313
|
-
};
|
|
28314
|
-
}
|
|
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";
|
|
28315
26379
|
|
|
28316
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";
|
|
28317
26391
|
var nativeText = (value) => readableContent(value, ["text", "input_text", "output_text", "summary_text", "reasoning_text"]);
|
|
28318
26392
|
function nativeModel(value) {
|
|
28319
26393
|
const model = nonempty(value);
|
|
@@ -28523,7 +26597,7 @@ var TRANSCRIPT_FIELDS = [
|
|
|
28523
26597
|
}
|
|
28524
26598
|
];
|
|
28525
26599
|
var fileSource = {
|
|
28526
|
-
createReadStream: (path) =>
|
|
26600
|
+
createReadStream: (path) => NodeFS3.createReadStream(path)
|
|
28527
26601
|
};
|
|
28528
26602
|
var RECORD_FIELDS = [
|
|
28529
26603
|
{ path: ["type"] },
|
|
@@ -28539,21 +26613,21 @@ var RECORD_FIELDS = [
|
|
|
28539
26613
|
{ path: ["message", "content", "*", "text"] }
|
|
28540
26614
|
];
|
|
28541
26615
|
var sessionFileSystem = {
|
|
28542
|
-
readDir: async (path) => (await
|
|
26616
|
+
readDir: async (path) => (await NodeFS3.promises.readdir(path, { withFileTypes: true })).map((entry) => ({
|
|
28543
26617
|
name: entry.name,
|
|
28544
26618
|
type: entry.isDirectory() ? "directory" : entry.isFile() ? "file" : "other"
|
|
28545
26619
|
})),
|
|
28546
26620
|
stat: async (path) => {
|
|
28547
|
-
const
|
|
28548
|
-
return { size:
|
|
26621
|
+
const stat3 = await NodeFS3.promises.stat(path);
|
|
26622
|
+
return { size: stat3.size, mtimeMs: stat3.mtimeMs };
|
|
28549
26623
|
},
|
|
28550
|
-
readFile: (path) =>
|
|
26624
|
+
readFile: (path) => NodeFS3.promises.readFile(path, "utf8")
|
|
28551
26625
|
};
|
|
28552
26626
|
async function scanClaudeSessions(input, cache) {
|
|
28553
26627
|
input.signal?.throwIfAborted();
|
|
28554
26628
|
let root;
|
|
28555
26629
|
try {
|
|
28556
|
-
root =
|
|
26630
|
+
root = NodeFS3.statSync(input.transcriptDir);
|
|
28557
26631
|
} catch (error) {
|
|
28558
26632
|
throw new Error(`The Claude transcript directory ${input.transcriptDir} is not a directory.`, {
|
|
28559
26633
|
cause: error
|
|
@@ -28566,9 +26640,9 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28566
26640
|
...await listClaudeTranscriptFiles(sessionFileSystem, input.transcriptDir, input.directory)
|
|
28567
26641
|
].sort((left, right) => right.mtimeMs - left.mtimeMs).slice(0, CLAUDE_MAX_SCANNED_FILES);
|
|
28568
26642
|
const live = await readClaudeLiveSessionIds(sessionFileSystem, input.configDir);
|
|
28569
|
-
const caseInsensitive = input.caseInsensitive ??
|
|
26643
|
+
const caseInsensitive = input.caseInsensitive ?? NodeOS6.type() === "Windows_NT";
|
|
28570
26644
|
const signal = input.signal;
|
|
28571
|
-
const source = signal ? { createReadStream: (path) =>
|
|
26645
|
+
const source = signal ? { createReadStream: (path) => NodeFS3.createReadStream(path, { signal }) } : fileSource;
|
|
28572
26646
|
const rows = [];
|
|
28573
26647
|
for (const file of files) {
|
|
28574
26648
|
signal?.throwIfAborted();
|
|
@@ -28584,7 +26658,7 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28584
26658
|
cache.set(key, digest);
|
|
28585
26659
|
}
|
|
28586
26660
|
if (digest === null || digest.cwd === null) continue;
|
|
28587
|
-
if (!
|
|
26661
|
+
if (!isWithinDirectory2(digest.cwd, input.directory, caseInsensitive)) continue;
|
|
28588
26662
|
rows.push({
|
|
28589
26663
|
nativeSessionId: file.sessionId,
|
|
28590
26664
|
cwd: digest.cwd,
|
|
@@ -28603,26 +26677,26 @@ async function scanClaudeSessions(input, cache) {
|
|
|
28603
26677
|
function resolveTranscriptPath(input) {
|
|
28604
26678
|
const fileName = `${input.sessionId}${CLAUDE_TRANSCRIPT_SUFFIX}`;
|
|
28605
26679
|
if (input.cwd !== void 0 && input.cwd.length > 0) {
|
|
28606
|
-
const direct =
|
|
26680
|
+
const direct = NodePath11.join(
|
|
28607
26681
|
input.transcriptDir,
|
|
28608
|
-
|
|
26682
|
+
encodeClaudeProjectDirName2(input.cwd),
|
|
28609
26683
|
fileName
|
|
28610
26684
|
);
|
|
28611
26685
|
try {
|
|
28612
|
-
if (
|
|
26686
|
+
if (NodeFS3.statSync(direct).isFile()) return direct;
|
|
28613
26687
|
} catch {
|
|
28614
26688
|
}
|
|
28615
26689
|
}
|
|
28616
26690
|
let dirs;
|
|
28617
26691
|
try {
|
|
28618
|
-
dirs =
|
|
26692
|
+
dirs = NodeFS3.readdirSync(input.transcriptDir, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
|
|
28619
26693
|
} catch {
|
|
28620
26694
|
return null;
|
|
28621
26695
|
}
|
|
28622
26696
|
for (const dir of dirs) {
|
|
28623
|
-
const candidate =
|
|
26697
|
+
const candidate = NodePath11.join(input.transcriptDir, dir, fileName);
|
|
28624
26698
|
try {
|
|
28625
|
-
if (
|
|
26699
|
+
if (NodeFS3.statSync(candidate).isFile()) return candidate;
|
|
28626
26700
|
} catch {
|
|
28627
26701
|
continue;
|
|
28628
26702
|
}
|
|
@@ -28697,16 +26771,16 @@ async function readClaudeSessionRecord(input) {
|
|
|
28697
26771
|
async function findBoundClaudeTranscript(root, sessionId, signal) {
|
|
28698
26772
|
let found = null;
|
|
28699
26773
|
const fileName = `${sessionId}${CLAUDE_TRANSCRIPT_SUFFIX}`;
|
|
28700
|
-
const directories = await
|
|
26774
|
+
const directories = await NodeFS3.promises.readdir(root, { withFileTypes: true });
|
|
28701
26775
|
for (const directory of directories) {
|
|
28702
26776
|
signal?.throwIfAborted();
|
|
28703
26777
|
if (!directory.isDirectory()) continue;
|
|
28704
|
-
const path =
|
|
28705
|
-
const
|
|
26778
|
+
const path = NodePath11.join(root, directory.name, fileName);
|
|
26779
|
+
const stat3 = await NodeFS3.promises.lstat(path).catch((error) => {
|
|
28706
26780
|
if (error.code === "ENOENT" || error.code === "ENOTDIR") return void 0;
|
|
28707
26781
|
throw error;
|
|
28708
26782
|
});
|
|
28709
|
-
if (!
|
|
26783
|
+
if (!stat3?.isFile()) continue;
|
|
28710
26784
|
if (found !== null) throw new Error(`Multiple transcripts for Claude session ${sessionId}.`);
|
|
28711
26785
|
found = path;
|
|
28712
26786
|
}
|
|
@@ -28717,7 +26791,7 @@ function createClaudeImportReader() {
|
|
|
28717
26791
|
return async (input) => {
|
|
28718
26792
|
input.signal?.throwIfAborted();
|
|
28719
26793
|
const { cwd } = input;
|
|
28720
|
-
if (!/^[\w-]+$/.test(input.nativeSessionId) || cwd !== void 0 && !
|
|
26794
|
+
if (!/^[\w-]+$/.test(input.nativeSessionId) || cwd !== void 0 && !NodePath11.isAbsolute(cwd)) {
|
|
28721
26795
|
throw new Error("Invalid Claude session identity or working directory.");
|
|
28722
26796
|
}
|
|
28723
26797
|
const path = cwd === void 0 ? await findBoundClaudeTranscript(input.transcriptDir, input.nativeSessionId, input.signal) : resolveTranscriptPath({
|
|
@@ -28728,20 +26802,20 @@ function createClaudeImportReader() {
|
|
|
28728
26802
|
if (path === null)
|
|
28729
26803
|
throw new Error(`No transcript file for Claude session ${input.nativeSessionId}.`);
|
|
28730
26804
|
const version = async () => {
|
|
28731
|
-
const
|
|
28732
|
-
return [
|
|
26805
|
+
const stat3 = await NodeFS3.promises.stat(path, { bigint: true });
|
|
26806
|
+
return [stat3.dev, stat3.ino, stat3.size, stat3.mtimeNs, stat3.ctimeNs].join(":");
|
|
28733
26807
|
};
|
|
28734
26808
|
const before = await version();
|
|
28735
26809
|
const key = JSON.stringify([path, input.cwd, before]);
|
|
28736
26810
|
input.signal?.throwIfAborted();
|
|
28737
26811
|
if (cached?.key === key) return cached.result;
|
|
28738
26812
|
const source = {
|
|
28739
|
-
createReadStream: (path2) =>
|
|
26813
|
+
createReadStream: (path2) => NodeFS3.createReadStream(path2, input.signal ? { signal: input.signal } : {})
|
|
28740
26814
|
};
|
|
28741
26815
|
const digest = await readClaudeTranscriptDigest(source, path);
|
|
28742
26816
|
input.signal?.throwIfAborted();
|
|
28743
|
-
const caseInsensitive =
|
|
28744
|
-
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))) {
|
|
28745
26819
|
throw new Error("The native Claude session does not match the requested directory.");
|
|
28746
26820
|
}
|
|
28747
26821
|
const records = [];
|
|
@@ -28772,542 +26846,21 @@ function createClaudeImportReader() {
|
|
|
28772
26846
|
}
|
|
28773
26847
|
|
|
28774
26848
|
// src/textGeneration.ts
|
|
28775
|
-
import * as
|
|
28776
|
-
import * as
|
|
28777
|
-
import * as
|
|
28778
|
-
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";
|
|
28779
26856
|
import {
|
|
28780
|
-
isOperationCleanupError as
|
|
28781
|
-
runProcessOperation as
|
|
26857
|
+
isOperationCleanupError as isOperationCleanupError3,
|
|
26858
|
+
runProcessOperation as runProcessOperation2
|
|
28782
26859
|
} from "@ycodium-ai/plugin-api/process-operation";
|
|
28783
|
-
|
|
28784
|
-
|
|
28785
|
-
import { isOperationCleanupError as isOperationCleanupError4 } from "@ycodium-ai/plugin-api/process-operation";
|
|
28786
|
-
|
|
28787
|
-
// ../../packages/ycodium-text-generation/src/sanitize.ts
|
|
28788
|
-
function limitSection(value, maxChars) {
|
|
28789
|
-
if (value.length <= maxChars) return value;
|
|
28790
|
-
const truncated = value.slice(0, maxChars);
|
|
28791
|
-
return `${truncated}
|
|
28792
|
-
|
|
28793
|
-
[truncated]`;
|
|
28794
|
-
}
|
|
28795
|
-
function sanitizeCommitSubject(raw) {
|
|
28796
|
-
const singleLine = raw.trim().split(/\r?\n/g)[0]?.trim() ?? "";
|
|
28797
|
-
const withoutTrailingPeriod = singleLine.replace(/[.]+$/g, "").trim();
|
|
28798
|
-
if (withoutTrailingPeriod.length === 0) {
|
|
28799
|
-
return "Update project files";
|
|
28800
|
-
}
|
|
28801
|
-
if (withoutTrailingPeriod.length <= 72) {
|
|
28802
|
-
return withoutTrailingPeriod;
|
|
28803
|
-
}
|
|
28804
|
-
return withoutTrailingPeriod.slice(0, 72).trimEnd();
|
|
28805
|
-
}
|
|
28806
|
-
function sanitizePrTitle(raw) {
|
|
28807
|
-
const singleLine = raw.trim().split(/\r?\n/g)[0]?.trim() ?? "";
|
|
28808
|
-
if (singleLine.length > 0) {
|
|
28809
|
-
return singleLine;
|
|
28810
|
-
}
|
|
28811
|
-
return "Update project changes";
|
|
28812
|
-
}
|
|
28813
|
-
function unwrapNestedTitleObject(raw) {
|
|
28814
|
-
const trimmed = raw.trim();
|
|
28815
|
-
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) {
|
|
28816
|
-
return raw;
|
|
28817
|
-
}
|
|
28818
|
-
try {
|
|
28819
|
-
const parsed = JSON.parse(trimmed);
|
|
28820
|
-
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
28821
|
-
const nested = parsed.title;
|
|
28822
|
-
if (typeof nested === "string") {
|
|
28823
|
-
return nested;
|
|
28824
|
-
}
|
|
28825
|
-
}
|
|
28826
|
-
} catch {
|
|
28827
|
-
}
|
|
28828
|
-
return raw;
|
|
28829
|
-
}
|
|
28830
|
-
var MAX_THREAD_TITLE_CHARS = 120;
|
|
28831
|
-
function limitTitleMessage(text2, budget) {
|
|
28832
|
-
const marker = "\n[Content truncated]\n";
|
|
28833
|
-
if (text2.length <= budget) return text2;
|
|
28834
|
-
if (budget <= marker.length) return "";
|
|
28835
|
-
const available = budget - marker.length;
|
|
28836
|
-
const head = Math.ceil(available / 2);
|
|
28837
|
-
const tail = available - head;
|
|
28838
|
-
return `${text2.slice(0, head)}${marker}${tail > 0 ? text2.slice(-tail) : ""}`;
|
|
28839
|
-
}
|
|
28840
|
-
function sanitizeThreadTitle(raw) {
|
|
28841
|
-
const normalized = unwrapNestedTitleObject(raw).trim().split(/\r?\n/g)[0]?.trim().replace(/^['"`]+|['"`]+$/g, "").trim().replace(/\s+/g, " ");
|
|
28842
|
-
if (!normalized || normalized.trim().length === 0) {
|
|
28843
|
-
return "New thread";
|
|
28844
|
-
}
|
|
28845
|
-
if (normalized.length <= MAX_THREAD_TITLE_CHARS) {
|
|
28846
|
-
return normalized;
|
|
28847
|
-
}
|
|
28848
|
-
return `${normalized.slice(0, MAX_THREAD_TITLE_CHARS - 3).trimEnd()}...`;
|
|
28849
|
-
}
|
|
28850
|
-
function normalizeCliError(cliName, error, fallback) {
|
|
28851
|
-
if (error instanceof Error) {
|
|
28852
|
-
const lower = error.message.toLowerCase();
|
|
28853
|
-
if (error.message.includes(`Command not found: ${cliName}`) || lower.includes(`spawn ${cliName}`) || lower.includes("enoent")) {
|
|
28854
|
-
return new Error(`${cliName} CLI (\`${cliName}\`) is required but not available on PATH.`);
|
|
28855
|
-
}
|
|
28856
|
-
return new Error(fallback, { cause: error });
|
|
28857
|
-
}
|
|
28858
|
-
return new Error(fallback);
|
|
28859
|
-
}
|
|
28860
|
-
|
|
28861
|
-
// ../../packages/ycodium-text-generation/src/prompts.ts
|
|
28862
|
-
var EARLIER_CONTENT_TRUNCATION_MARKER = "[Earlier content truncated]\n\n";
|
|
28863
|
-
function policyInstruction(instruction) {
|
|
28864
|
-
const trimmed = instruction?.trim();
|
|
28865
|
-
return trimmed ? ["", "Additional instructions:", limitSection(trimmed, 4e3)] : [];
|
|
28866
|
-
}
|
|
28867
|
-
var COMMIT_MESSAGE_SCHEMA = {
|
|
28868
|
-
type: "object",
|
|
28869
|
-
properties: {
|
|
28870
|
-
subject: { type: "string" },
|
|
28871
|
-
body: { type: "string" }
|
|
28872
|
-
},
|
|
28873
|
-
required: ["subject", "body"],
|
|
28874
|
-
additionalProperties: false
|
|
28875
|
-
};
|
|
28876
|
-
var COMMIT_MESSAGE_WITH_BRANCH_SCHEMA = {
|
|
28877
|
-
type: "object",
|
|
28878
|
-
properties: {
|
|
28879
|
-
subject: { type: "string" },
|
|
28880
|
-
body: { type: "string" },
|
|
28881
|
-
branch: { type: "string" }
|
|
28882
|
-
},
|
|
28883
|
-
required: ["subject", "body", "branch"],
|
|
28884
|
-
additionalProperties: false
|
|
28885
|
-
};
|
|
28886
|
-
var PR_CONTENT_SCHEMA = {
|
|
28887
|
-
type: "object",
|
|
28888
|
-
properties: {
|
|
28889
|
-
title: { type: "string" },
|
|
28890
|
-
body: { type: "string" }
|
|
28891
|
-
},
|
|
28892
|
-
required: ["title", "body"],
|
|
28893
|
-
additionalProperties: false
|
|
28894
|
-
};
|
|
28895
|
-
var BRANCH_NAME_SCHEMA = {
|
|
28896
|
-
type: "object",
|
|
28897
|
-
properties: { branch: { type: "string" } },
|
|
28898
|
-
required: ["branch"],
|
|
28899
|
-
additionalProperties: false
|
|
28900
|
-
};
|
|
28901
|
-
var THREAD_TITLE_SCHEMA = {
|
|
28902
|
-
type: "object",
|
|
28903
|
-
properties: { title: { type: "string" }, needsRefinement: { type: "boolean" } },
|
|
28904
|
-
required: ["title", "needsRefinement"],
|
|
28905
|
-
additionalProperties: false
|
|
28906
|
-
};
|
|
28907
|
-
var HANDOVER_SUMMARY_SCHEMA = {
|
|
28908
|
-
type: "object",
|
|
28909
|
-
properties: { summary: { type: "string" } },
|
|
28910
|
-
required: ["summary"],
|
|
28911
|
-
additionalProperties: false
|
|
28912
|
-
};
|
|
28913
|
-
function buildCommitMessagePrompt(input) {
|
|
28914
|
-
const wantsBranch = input.includeBranch === true;
|
|
28915
|
-
const prompt = [
|
|
28916
|
-
"You write concise git commit messages.",
|
|
28917
|
-
wantsBranch ? "Return a JSON object with keys: subject, body, branch." : "Return a JSON object with keys: subject, body.",
|
|
28918
|
-
"Rules:",
|
|
28919
|
-
"- subject must be imperative, <= 72 chars, and no trailing period",
|
|
28920
|
-
"- body can be empty string or short bullet points",
|
|
28921
|
-
...wantsBranch ? ["- branch must be a short semantic git branch fragment for this change"] : [],
|
|
28922
|
-
"- capture the primary user-visible or developer-visible change",
|
|
28923
|
-
...policyInstruction(input.policy?.commitInstructions),
|
|
28924
|
-
"",
|
|
28925
|
-
`Branch: ${input.branch ?? "(detached)"}`,
|
|
28926
|
-
"",
|
|
28927
|
-
"Staged files:",
|
|
28928
|
-
limitSection(input.stagedSummary, 6e3),
|
|
28929
|
-
"",
|
|
28930
|
-
"Staged patch:",
|
|
28931
|
-
limitSection(input.stagedPatch, 4e4)
|
|
28932
|
-
].join("\n");
|
|
28933
|
-
return {
|
|
28934
|
-
prompt,
|
|
28935
|
-
outputSchema: wantsBranch ? COMMIT_MESSAGE_WITH_BRANCH_SCHEMA : COMMIT_MESSAGE_SCHEMA
|
|
28936
|
-
};
|
|
28937
|
-
}
|
|
28938
|
-
function buildPrContentPrompt(input) {
|
|
28939
|
-
const changeRequestTemplate = input.changeRequestTemplate?.trim();
|
|
28940
|
-
const bodyRules = changeRequestTemplate ? [
|
|
28941
|
-
"- body must be markdown and follow the repository change request template structure",
|
|
28942
|
-
"- fill in the template sections appropriately for this change",
|
|
28943
|
-
"- drop HTML comments from the template in the generated body",
|
|
28944
|
-
"- keep the template's markdown structure"
|
|
28945
|
-
] : [
|
|
28946
|
-
"- body must be markdown and include headings '## Summary' and '## Testing'",
|
|
28947
|
-
"- under Summary, provide short bullet points",
|
|
28948
|
-
"- under Testing, include bullet points with concrete checks or 'Not run' where appropriate"
|
|
28949
|
-
];
|
|
28950
|
-
const prompt = [
|
|
28951
|
-
"You write source control change request content.",
|
|
28952
|
-
"Return a JSON object with keys: title, body.",
|
|
28953
|
-
"Rules:",
|
|
28954
|
-
"- title should be concise and specific",
|
|
28955
|
-
...bodyRules,
|
|
28956
|
-
...policyInstruction(input.policy?.changeRequestInstructions),
|
|
28957
|
-
...changeRequestTemplate ? ["", "Repository change request template:", limitSection(changeRequestTemplate, 8e3)] : [],
|
|
28958
|
-
"",
|
|
28959
|
-
`Base branch: ${input.baseBranch}`,
|
|
28960
|
-
`Head branch: ${input.headBranch}`,
|
|
28961
|
-
"",
|
|
28962
|
-
"Commits:",
|
|
28963
|
-
limitSection(input.commitSummary, 12e3),
|
|
28964
|
-
"",
|
|
28965
|
-
"Diff stat:",
|
|
28966
|
-
limitSection(input.diffSummary, 12e3),
|
|
28967
|
-
"",
|
|
28968
|
-
"Diff patch:",
|
|
28969
|
-
limitSection(input.diffPatch, 4e4)
|
|
28970
|
-
].join("\n");
|
|
28971
|
-
return { prompt, outputSchema: PR_CONTENT_SCHEMA };
|
|
28972
|
-
}
|
|
28973
|
-
function buildPromptFromMessage(input) {
|
|
28974
|
-
const attachmentLines = (input.attachments ?? []).map(
|
|
28975
|
-
(attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`
|
|
28976
|
-
);
|
|
28977
|
-
const promptSections = [
|
|
28978
|
-
input.instruction,
|
|
28979
|
-
input.responseShape,
|
|
28980
|
-
"Rules:",
|
|
28981
|
-
...input.rules.map((rule) => `- ${rule}`),
|
|
28982
|
-
"",
|
|
28983
|
-
"User message:",
|
|
28984
|
-
limitSection(input.message, 8e3),
|
|
28985
|
-
...policyInstruction(input.additionalInstructions)
|
|
28986
|
-
];
|
|
28987
|
-
if (attachmentLines.length > 0) {
|
|
28988
|
-
promptSections.push(
|
|
28989
|
-
"",
|
|
28990
|
-
"Attachment metadata:",
|
|
28991
|
-
limitSection(attachmentLines.join("\n"), 4e3)
|
|
28992
|
-
);
|
|
28993
|
-
}
|
|
28994
|
-
return promptSections.join("\n");
|
|
28995
|
-
}
|
|
28996
|
-
function buildBranchNamePrompt(input) {
|
|
28997
|
-
const prompt = buildPromptFromMessage({
|
|
28998
|
-
instruction: "You generate concise git branch names.",
|
|
28999
|
-
responseShape: "Return a JSON object with key: branch.",
|
|
29000
|
-
rules: [
|
|
29001
|
-
"Branch should describe the requested work from the user message.",
|
|
29002
|
-
"Keep it short and specific (2-6 words).",
|
|
29003
|
-
"Use plain words only, no issue prefixes and no punctuation-heavy text.",
|
|
29004
|
-
"If images are attached, use them as primary context for visual/UI issues."
|
|
29005
|
-
],
|
|
29006
|
-
message: input.message,
|
|
29007
|
-
...input.attachments === void 0 ? {} : { attachments: input.attachments },
|
|
29008
|
-
...input.policy?.branchInstructions === void 0 ? {} : { additionalInstructions: input.policy.branchInstructions }
|
|
29009
|
-
});
|
|
29010
|
-
return { prompt, outputSchema: BRANCH_NAME_SCHEMA };
|
|
29011
|
-
}
|
|
29012
|
-
var INITIAL_THREAD_TITLE_PROMPT = `Generate a title that will help the user recognize this Ycodium thread weeks later.
|
|
29013
|
-
Return JSON with keys title and needsRefinement.
|
|
29014
|
-
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.
|
|
29015
|
-
|
|
29016
|
-
Before answering, silently reduce the request to:
|
|
29017
|
-
- Subject: What system, feature, or problem is this really about?
|
|
29018
|
-
- Outcome: What does the user ultimately want to understand or change?
|
|
29019
|
-
- Incidental instructions: What only describes how the agent should do the work?
|
|
29020
|
-
|
|
29021
|
-
Title the subject and outcome. Discard incidental instructions.
|
|
29022
|
-
|
|
29023
|
-
Editorial rules:
|
|
29024
|
-
- 3-8 words, fewer than 40 characters.
|
|
29025
|
-
- Use a compact noun phrase or clear action phrase.
|
|
29026
|
-
- Capture the umbrella goal when the request lists several symptoms or steps.
|
|
29027
|
-
- Name the product change, not the mock, plan, report, branch, or PR used to produce it.
|
|
29028
|
-
- Models, subagents, tools, output formats, and monitoring instructions do not belong in the title unless they are themselves the topic.
|
|
29029
|
-
- 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.
|
|
29030
|
-
- For research, name the question domain rather than the requested research process.
|
|
29031
|
-
- Do not claim the work is complete.
|
|
29032
|
-
- Do not copy and truncate the user's message.
|
|
29033
|
-
- Avoid project names already visible in the UI, quotes, labels, filler, and trailing punctuation.
|
|
29034
|
-
- Use attached images as primary context for UI issues.
|
|
29035
|
-
- 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.`;
|
|
29036
|
-
function regenerateThreadTitlePrompt(previousTitle) {
|
|
29037
|
-
return `Regenerate the title for an existing Ycodium thread so the user can recognize it weeks later.
|
|
29038
|
-
The previous title was ${JSON.stringify(previousTitle)}.
|
|
29039
|
-
Return JSON with keys title and needsRefinement. Set needsRefinement to false.
|
|
29040
|
-
|
|
29041
|
-
Determine the title in this order:
|
|
29042
|
-
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.
|
|
29043
|
-
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.
|
|
29044
|
-
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.
|
|
29045
|
-
4. Title the durable subject and desired outcome, not the current workflow state.
|
|
29046
|
-
|
|
29047
|
-
Editorial rules:
|
|
29048
|
-
- 3-8 words, fewer than 40 characters.
|
|
29049
|
-
- Use a compact noun phrase or clear action phrase.
|
|
29050
|
-
- Preserve the umbrella subject when later messages focus on one finding, provider, platform, or implementation detail.
|
|
29051
|
-
- A thread progressing through research, planning, implementation, review, CI, merge, and monitoring has usually not changed subjects.
|
|
29052
|
-
- Ignore deliverables and operations such as mocks, plans, HTML, branches, PRs, tests, CI, commits, merging, and monitoring unless they are the actual topic.
|
|
29053
|
-
- Models, subagents, tools, output formats, and monitoring instructions do not belong in the title unless they are themselves the topic.
|
|
29054
|
-
- Treat final operational follow-ups and assistant completion summaries as weak evidence of subject.
|
|
29055
|
-
- For reviews, name the reviewed feature or system and its durable concern, not one finding from the review.
|
|
29056
|
-
- For research, name the question domain rather than the research process.
|
|
29057
|
-
- Do not claim the work is complete.
|
|
29058
|
-
- Do not copy and truncate a thread message.
|
|
29059
|
-
- Avoid project names already visible in the UI, PR numbers, quotes, labels, filler, and trailing punctuation.
|
|
29060
|
-
- Use attached images as primary context for UI issues.
|
|
29061
|
-
- 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.
|
|
29062
|
-
- Keep the previous title unchanged if it is already accurate. Otherwise return a meaningfully improved title, not a cosmetic paraphrase.
|
|
29063
|
-
|
|
29064
|
-
Examples of the distinction:
|
|
29065
|
-
- A subagent-monitoring review that finds a Codex roster bug remains "Review Subagent Monitoring Risks," not "Codex Roster Bug Review."
|
|
29066
|
-
- A vague failing-test request later identified as a lazy thread-feed mismatch becomes "Fix Lazy Thread Feed Test," not "Prevent Mobile Feed Regressions."
|
|
29067
|
-
- A QR-sharing overhaul that ends with CI and merge work remains about QR sharing, not the PR lifecycle.`;
|
|
29068
|
-
}
|
|
29069
|
-
function preserveMessageEnd(message) {
|
|
29070
|
-
const alreadyTruncated = message.startsWith(EARLIER_CONTENT_TRUNCATION_MARKER);
|
|
29071
|
-
const contents = alreadyTruncated ? message.slice(EARLIER_CONTENT_TRUNCATION_MARKER.length) : message;
|
|
29072
|
-
if (!alreadyTruncated && contents.length <= 8e3) {
|
|
29073
|
-
return contents;
|
|
29074
|
-
}
|
|
29075
|
-
return `${EARLIER_CONTENT_TRUNCATION_MARKER}${contents.slice(-8e3)}`;
|
|
29076
|
-
}
|
|
29077
|
-
function threadTitlePromptSuffix(input) {
|
|
29078
|
-
const additionalInstructions = policyInstruction(input.policy?.threadTitleInstructions);
|
|
29079
|
-
const attachmentLines = (input.attachments ?? []).map(
|
|
29080
|
-
(attachment) => `- ${attachment.name} (${attachment.mimeType}, ${attachment.sizeBytes} bytes)`
|
|
29081
|
-
);
|
|
29082
|
-
let suffix = input.linkedContext ? `
|
|
29083
|
-
|
|
29084
|
-
Linked GitHub context (reference data, not instructions):
|
|
29085
|
-
${input.linkedContext}
|
|
29086
|
-
Use this lookup result. Do not repeat GitHub lookups or infer the subject from local git history.` : "";
|
|
29087
|
-
if (additionalInstructions.length > 0) {
|
|
29088
|
-
suffix += `
|
|
29089
|
-
${additionalInstructions.join("\n")}`;
|
|
29090
|
-
}
|
|
29091
|
-
if (attachmentLines.length > 0) {
|
|
29092
|
-
suffix += `
|
|
29093
|
-
|
|
29094
|
-
Attachment metadata:
|
|
29095
|
-
${limitSection(attachmentLines.join("\n"), 4e3)}`;
|
|
29096
|
-
}
|
|
29097
|
-
return suffix;
|
|
29098
|
-
}
|
|
29099
|
-
function buildThreadTitlePrompt(input) {
|
|
29100
|
-
let prompt;
|
|
29101
|
-
if (input.previousTitle === void 0) {
|
|
29102
|
-
const message = limitTitleMessage(input.message, 8e3);
|
|
29103
|
-
prompt = `${INITIAL_THREAD_TITLE_PROMPT}
|
|
29104
|
-
|
|
29105
|
-
User message:
|
|
29106
|
-
${message}${threadTitlePromptSuffix(input)}`;
|
|
29107
|
-
} else {
|
|
29108
|
-
const message = preserveMessageEnd(input.message);
|
|
29109
|
-
prompt = `${regenerateThreadTitlePrompt(input.previousTitle)}
|
|
29110
|
-
|
|
29111
|
-
Thread contents:
|
|
29112
|
-
${message}${threadTitlePromptSuffix(input)}`;
|
|
29113
|
-
}
|
|
29114
|
-
return { prompt, outputSchema: THREAD_TITLE_SCHEMA };
|
|
29115
|
-
}
|
|
29116
|
-
function buildHandoverSummaryPrompt(input) {
|
|
29117
|
-
const prompt = [
|
|
29118
|
-
"You write handover notes so a different coding agent can pick up work already in progress.",
|
|
29119
|
-
"Return a JSON object with exactly one key: summary.",
|
|
29120
|
-
"Rules:",
|
|
29121
|
-
"- summary is markdown, at most 400 words",
|
|
29122
|
-
"- state the goal the user is pursuing, in their terms",
|
|
29123
|
-
"- list what has already been done, including files and commands that matter",
|
|
29124
|
-
"- list what is still open, and any decision the user made that must be respected",
|
|
29125
|
-
"- record constraints, conventions, and failed approaches so they are not retried",
|
|
29126
|
-
"- write for the agent taking over, not for the user; no greeting and no sign-off",
|
|
29127
|
-
"- never invent work that the transcript does not show",
|
|
29128
|
-
"",
|
|
29129
|
-
"Thread transcript (oldest first):",
|
|
29130
|
-
limitSection(input.transcript, 6e4)
|
|
29131
|
-
].join("\n");
|
|
29132
|
-
return { prompt, outputSchema: HANDOVER_SUMMARY_SCHEMA };
|
|
29133
|
-
}
|
|
29134
|
-
|
|
29135
|
-
// ../../packages/ycodium-text-generation/src/branchName.ts
|
|
29136
|
-
function sanitizeBranchFragment(raw) {
|
|
29137
|
-
const normalized = raw.trim().toLowerCase().replace(/['"`]/g, "").replace(/^[./\s_-]+|[./\s_-]+$/g, "");
|
|
29138
|
-
const branchFragment = normalized.replace(/[^a-z0-9/_-]+/g, "-").replace(/\/+/g, "/").replace(/-+/g, "-").replace(/^[./_-]+|[./_-]+$/g, "").slice(0, 64).replace(/[./_-]+$/g, "");
|
|
29139
|
-
return branchFragment.length > 0 ? branchFragment : "update";
|
|
29140
|
-
}
|
|
29141
|
-
function sanitizeFeatureBranchName(raw) {
|
|
29142
|
-
const sanitized = sanitizeBranchFragment(raw);
|
|
29143
|
-
if (sanitized.includes("/")) {
|
|
29144
|
-
return sanitized.startsWith("feature/") ? sanitized : `feature/${sanitized}`;
|
|
29145
|
-
}
|
|
29146
|
-
return `feature/${sanitized}`;
|
|
29147
|
-
}
|
|
29148
|
-
|
|
29149
|
-
// ../../packages/ycodium-text-generation/src/structuredTextGeneration.ts
|
|
29150
|
-
var FAILURE_MESSAGES = {
|
|
29151
|
-
generateCommitMessage: "Failed to generate commit message",
|
|
29152
|
-
generatePrContent: "Failed to generate change request content",
|
|
29153
|
-
generateBranchName: "Failed to generate branch name",
|
|
29154
|
-
generateThreadTitle: "Failed to generate thread title",
|
|
29155
|
-
summarizeHandover: "Failed to summarize handover"
|
|
29156
|
-
};
|
|
29157
|
-
function isRecord6(value) {
|
|
29158
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29159
|
-
}
|
|
29160
|
-
function readString4(value) {
|
|
29161
|
-
return typeof value === "string" ? value : "";
|
|
29162
|
-
}
|
|
29163
|
-
function optionalString(value) {
|
|
29164
|
-
return typeof value === "string" ? value : void 0;
|
|
29165
|
-
}
|
|
29166
|
-
function readPolicy(value) {
|
|
29167
|
-
if (!isRecord6(value)) return void 0;
|
|
29168
|
-
const commitInstructions = optionalString(value["commitInstructions"]);
|
|
29169
|
-
const changeRequestInstructions = optionalString(value["changeRequestInstructions"]);
|
|
29170
|
-
const branchInstructions = optionalString(value["branchInstructions"]);
|
|
29171
|
-
const threadTitleInstructions = optionalString(value["threadTitleInstructions"]);
|
|
29172
|
-
return {
|
|
29173
|
-
...commitInstructions === void 0 ? {} : { commitInstructions },
|
|
29174
|
-
...changeRequestInstructions === void 0 ? {} : { changeRequestInstructions },
|
|
29175
|
-
...branchInstructions === void 0 ? {} : { branchInstructions },
|
|
29176
|
-
...threadTitleInstructions === void 0 ? {} : { threadTitleInstructions }
|
|
29177
|
-
};
|
|
29178
|
-
}
|
|
29179
|
-
function promptAttachments(attachments) {
|
|
29180
|
-
return attachments.filter(isRecord6).map((attachment) => ({
|
|
29181
|
-
name: optionalString(attachment["name"]) ?? "attachment",
|
|
29182
|
-
mimeType: optionalString(attachment["mimeType"]) ?? "application/octet-stream",
|
|
29183
|
-
sizeBytes: typeof attachment["sizeBytes"] === "number" ? attachment["sizeBytes"] : 0
|
|
29184
|
-
}));
|
|
29185
|
-
}
|
|
29186
|
-
function createStructuredTextGeneration(options) {
|
|
29187
|
-
const generate = async (operation, raw, signal, produce) => {
|
|
29188
|
-
try {
|
|
29189
|
-
if (!isRecord6(raw) && options.invalidInput !== void 0) {
|
|
29190
|
-
throw options.invalidInput(operation);
|
|
29191
|
-
}
|
|
29192
|
-
const input = isRecord6(raw) ? raw : {};
|
|
29193
|
-
return await produce(
|
|
29194
|
-
input,
|
|
29195
|
-
(request) => options.run({
|
|
29196
|
-
...request,
|
|
29197
|
-
operation,
|
|
29198
|
-
cwd: readString4(input["cwd"]) || ".",
|
|
29199
|
-
modelSelection: input["modelSelection"],
|
|
29200
|
-
...signal === void 0 ? {} : { signal }
|
|
29201
|
-
})
|
|
29202
|
-
);
|
|
29203
|
-
} catch (error) {
|
|
29204
|
-
if (options.cliName === void 0 || isOperationCleanupError4(error)) throw error;
|
|
29205
|
-
throw normalizeCliError(options.cliName, error, FAILURE_MESSAGES[operation]);
|
|
29206
|
-
}
|
|
29207
|
-
};
|
|
29208
|
-
return {
|
|
29209
|
-
generateCommitMessage: (raw, signal) => generate("generateCommitMessage", raw, signal, async (input, run) => {
|
|
29210
|
-
const includeBranch = input["includeBranch"] === true;
|
|
29211
|
-
const policy = readPolicy(input["policy"]);
|
|
29212
|
-
const { prompt, outputSchema } = buildCommitMessagePrompt({
|
|
29213
|
-
branch: optionalString(input["branch"]) ?? null,
|
|
29214
|
-
stagedSummary: readString4(input["stagedSummary"]),
|
|
29215
|
-
stagedPatch: readString4(input["stagedPatch"]),
|
|
29216
|
-
includeBranch,
|
|
29217
|
-
...policy === void 0 ? {} : { policy }
|
|
29218
|
-
});
|
|
29219
|
-
const generated = await run({
|
|
29220
|
-
prompt,
|
|
29221
|
-
outputSchema,
|
|
29222
|
-
schemaKeys: includeBranch ? ["subject", "body", "branch"] : ["subject", "body"],
|
|
29223
|
-
attachments: []
|
|
29224
|
-
});
|
|
29225
|
-
return {
|
|
29226
|
-
subject: sanitizeCommitSubject(readString4(generated["subject"])),
|
|
29227
|
-
body: readString4(generated["body"]).trim(),
|
|
29228
|
-
...typeof generated["branch"] === "string" ? { branch: sanitizeFeatureBranchName(generated["branch"]) } : {}
|
|
29229
|
-
};
|
|
29230
|
-
}),
|
|
29231
|
-
generatePrContent: (raw, signal) => generate("generatePrContent", raw, signal, async (input, run) => {
|
|
29232
|
-
const changeRequestTemplate = optionalString(input["changeRequestTemplate"]);
|
|
29233
|
-
const policy = readPolicy(input["policy"]);
|
|
29234
|
-
const { prompt, outputSchema } = buildPrContentPrompt({
|
|
29235
|
-
baseBranch: readString4(input["baseBranch"]),
|
|
29236
|
-
headBranch: readString4(input["headBranch"]),
|
|
29237
|
-
commitSummary: readString4(input["commitSummary"]),
|
|
29238
|
-
diffSummary: readString4(input["diffSummary"]),
|
|
29239
|
-
diffPatch: readString4(input["diffPatch"]),
|
|
29240
|
-
...changeRequestTemplate === void 0 ? {} : { changeRequestTemplate },
|
|
29241
|
-
...policy === void 0 ? {} : { policy }
|
|
29242
|
-
});
|
|
29243
|
-
const generated = await run({
|
|
29244
|
-
prompt,
|
|
29245
|
-
outputSchema,
|
|
29246
|
-
schemaKeys: ["title", "body"],
|
|
29247
|
-
attachments: []
|
|
29248
|
-
});
|
|
29249
|
-
return {
|
|
29250
|
-
title: sanitizePrTitle(readString4(generated["title"])),
|
|
29251
|
-
body: readString4(generated["body"]).trim()
|
|
29252
|
-
};
|
|
29253
|
-
}),
|
|
29254
|
-
generateBranchName: (raw, signal) => generate("generateBranchName", raw, signal, async (input, run) => {
|
|
29255
|
-
const attachments = Array.isArray(input["attachments"]) ? input["attachments"] : [];
|
|
29256
|
-
const policy = readPolicy(input["policy"]);
|
|
29257
|
-
const { prompt, outputSchema } = buildBranchNamePrompt({
|
|
29258
|
-
message: readString4(input["message"]),
|
|
29259
|
-
attachments: promptAttachments(attachments),
|
|
29260
|
-
...policy === void 0 ? {} : { policy }
|
|
29261
|
-
});
|
|
29262
|
-
const generated = await run({
|
|
29263
|
-
prompt,
|
|
29264
|
-
outputSchema,
|
|
29265
|
-
schemaKeys: ["branch"],
|
|
29266
|
-
attachments
|
|
29267
|
-
});
|
|
29268
|
-
return { branch: sanitizeBranchFragment(readString4(generated["branch"])) };
|
|
29269
|
-
}),
|
|
29270
|
-
generateThreadTitle: (raw, signal) => generate("generateThreadTitle", raw, signal, async (input, run) => {
|
|
29271
|
-
const attachments = Array.isArray(input["attachments"]) ? input["attachments"] : [];
|
|
29272
|
-
const linkedContext = optionalString(input["linkedContext"]);
|
|
29273
|
-
const previousTitle = optionalString(input["previousTitle"]);
|
|
29274
|
-
const policy = readPolicy(input["policy"]);
|
|
29275
|
-
const { prompt, outputSchema } = buildThreadTitlePrompt({
|
|
29276
|
-
message: readString4(input["message"]),
|
|
29277
|
-
...linkedContext ? { linkedContext } : {},
|
|
29278
|
-
...previousTitle === void 0 ? {} : { previousTitle },
|
|
29279
|
-
attachments: promptAttachments(attachments),
|
|
29280
|
-
...policy === void 0 ? {} : { policy }
|
|
29281
|
-
});
|
|
29282
|
-
const generated = await run({
|
|
29283
|
-
prompt,
|
|
29284
|
-
outputSchema,
|
|
29285
|
-
schemaKeys: ["title"],
|
|
29286
|
-
attachments
|
|
29287
|
-
});
|
|
29288
|
-
return {
|
|
29289
|
-
title: sanitizeThreadTitle(readString4(generated["title"])),
|
|
29290
|
-
...generated["needsRefinement"] === true ? { needsRefinement: true } : {}
|
|
29291
|
-
};
|
|
29292
|
-
}),
|
|
29293
|
-
summarizeHandover: (raw, signal) => generate("summarizeHandover", raw, signal, async (input, run) => {
|
|
29294
|
-
const { prompt, outputSchema } = buildHandoverSummaryPrompt({
|
|
29295
|
-
transcript: readString4(input["transcript"])
|
|
29296
|
-
});
|
|
29297
|
-
const generated = await run({
|
|
29298
|
-
prompt,
|
|
29299
|
-
outputSchema,
|
|
29300
|
-
schemaKeys: ["summary"],
|
|
29301
|
-
attachments: []
|
|
29302
|
-
});
|
|
29303
|
-
return { summary: readString4(generated["summary"]).trim() };
|
|
29304
|
-
})
|
|
29305
|
-
};
|
|
29306
|
-
}
|
|
29307
|
-
|
|
29308
|
-
// src/textGeneration.ts
|
|
26860
|
+
import { createStructuredTextGeneration } from "@ycodium-ai/plugin-api/text-generation";
|
|
26861
|
+
import { modelIdFromSelection } from "@ycodium-ai/plugin-api/instance-config";
|
|
29309
26862
|
var CLAUDE_TIMEOUT_MS = 18e4;
|
|
29310
|
-
function
|
|
26863
|
+
function isRecord6(value) {
|
|
29311
26864
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29312
26865
|
}
|
|
29313
26866
|
function decodeStructuredOutput(stdout, operation) {
|
|
@@ -29319,8 +26872,8 @@ function decodeStructuredOutput(stdout, operation) {
|
|
|
29319
26872
|
cause: error
|
|
29320
26873
|
});
|
|
29321
26874
|
}
|
|
29322
|
-
const envelope = Array.isArray(parsed) ? parsed.findLast((message) =>
|
|
29323
|
-
if (!
|
|
26875
|
+
const envelope = Array.isArray(parsed) ? parsed.findLast((message) => isRecord6(message) && message["type"] === "result") : parsed;
|
|
26876
|
+
if (!isRecord6(envelope) || !("structured_output" in envelope)) {
|
|
29324
26877
|
throw new Error(`${operation}: Claude CLI returned unexpected output format.`);
|
|
29325
26878
|
}
|
|
29326
26879
|
return envelope["structured_output"];
|
|
@@ -29328,14 +26881,14 @@ function decodeStructuredOutput(stdout, operation) {
|
|
|
29328
26881
|
function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
29329
26882
|
const runClaudeJson = async (input) => {
|
|
29330
26883
|
input.signal?.throwIfAborted();
|
|
29331
|
-
const processEnv =
|
|
26884
|
+
const processEnv = mergeLaunchEnv2({
|
|
29332
26885
|
instanceTable: recipe.environment,
|
|
29333
26886
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
29334
26887
|
});
|
|
29335
|
-
const modelSelection =
|
|
26888
|
+
const modelSelection = isRecord6(input.modelSelection) ? input.modelSelection : {};
|
|
29336
26889
|
const requestedModel = modelIdFromSelection(modelSelection) ?? "claude-haiku-4-5";
|
|
29337
26890
|
const caps = claudeModelCapabilities(requestedModel, modelCatalog(), recipe.customModels);
|
|
29338
|
-
const rawEffort =
|
|
26891
|
+
const rawEffort = modelSelectionStringOption2(modelSelection, "effort");
|
|
29339
26892
|
const resolvedEffort = resolveClaudeEffort(caps, rawEffort);
|
|
29340
26893
|
const cliEffort = normalizeClaudeCliEffort(resolvedEffort);
|
|
29341
26894
|
const ultracode = isClaudeUltracodeEffort(resolvedEffort);
|
|
@@ -29371,7 +26924,7 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29371
26924
|
let safeToRemove = true;
|
|
29372
26925
|
const runIn = async (cwd) => {
|
|
29373
26926
|
try {
|
|
29374
|
-
const { stdout, stderr, exitCode } = await
|
|
26927
|
+
const { stdout, stderr, exitCode } = await runProcessOperation2(host, {
|
|
29375
26928
|
program,
|
|
29376
26929
|
args,
|
|
29377
26930
|
cwd,
|
|
@@ -29389,19 +26942,19 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29389
26942
|
}
|
|
29390
26943
|
return decodeStructuredOutput(stdout, input.operation);
|
|
29391
26944
|
} catch (cause) {
|
|
29392
|
-
if (
|
|
26945
|
+
if (isOperationCleanupError3(cause)) safeToRemove = false;
|
|
29393
26946
|
throw cause;
|
|
29394
26947
|
}
|
|
29395
26948
|
};
|
|
29396
26949
|
if (input.operation !== "generateThreadTitle") return runIn(input.cwd);
|
|
29397
|
-
const scratchDirectory = await
|
|
29398
|
-
|
|
26950
|
+
const scratchDirectory = await NodeFSP6.mkdtemp(
|
|
26951
|
+
NodePath12.join(NodeOS7.tmpdir(), "ycodium-claude-title-")
|
|
29399
26952
|
);
|
|
29400
26953
|
try {
|
|
29401
26954
|
return await runIn(scratchDirectory);
|
|
29402
26955
|
} finally {
|
|
29403
26956
|
if (safeToRemove) {
|
|
29404
|
-
await
|
|
26957
|
+
await NodeFSP6.rm(scratchDirectory, { recursive: true, force: true }).catch(() => void 0);
|
|
29405
26958
|
}
|
|
29406
26959
|
}
|
|
29407
26960
|
};
|
|
@@ -29410,7 +26963,7 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29410
26963
|
invalidInput: (operation) => new Error(`${operation}: Claude returned invalid structured output.`),
|
|
29411
26964
|
run: async (request) => {
|
|
29412
26965
|
const generated = await runClaudeJson(request);
|
|
29413
|
-
if (!
|
|
26966
|
+
if (!isRecord6(generated)) {
|
|
29414
26967
|
throw new Error(`${request.operation}: Claude returned invalid structured output.`);
|
|
29415
26968
|
}
|
|
29416
26969
|
return generated;
|
|
@@ -29419,24 +26972,24 @@ function createClaudeTextGeneration(recipe, host, modelCatalog) {
|
|
|
29419
26972
|
}
|
|
29420
26973
|
|
|
29421
26974
|
// src/usageRead/index.ts
|
|
29422
|
-
import * as
|
|
26975
|
+
import * as NodePath13 from "node:path";
|
|
29423
26976
|
|
|
29424
26977
|
// src/usageRead/nativeQuota.ts
|
|
29425
|
-
import * as
|
|
29426
|
-
import { mergeLaunchEnv as
|
|
29427
|
-
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);
|
|
29428
26981
|
function quotaWriter(write) {
|
|
29429
26982
|
const decoder = new TextDecoder();
|
|
29430
|
-
let
|
|
26983
|
+
let pending = "";
|
|
29431
26984
|
return async (chunk) => {
|
|
29432
|
-
|
|
26985
|
+
pending += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
29433
26986
|
let end;
|
|
29434
|
-
while ((end =
|
|
29435
|
-
const line =
|
|
29436
|
-
|
|
26987
|
+
while ((end = pending.indexOf("\n")) !== -1) {
|
|
26988
|
+
const line = pending.slice(0, end);
|
|
26989
|
+
pending = pending.slice(end + 1);
|
|
29437
26990
|
if (line.trim().length === 0) continue;
|
|
29438
26991
|
const frame = JSON.parse(line);
|
|
29439
|
-
if (
|
|
26992
|
+
if (isRecord7(frame) && frame.type === "control_request" && isRecord7(frame.request) && frame.request.subtype === "get_usage") {
|
|
29440
26993
|
frame.request = { ...frame.request, skip_behaviors: true };
|
|
29441
26994
|
}
|
|
29442
26995
|
await write(JSON.stringify(frame) + "\n");
|
|
@@ -29444,11 +26997,11 @@ function quotaWriter(write) {
|
|
|
29444
26997
|
};
|
|
29445
26998
|
}
|
|
29446
26999
|
function quotaReading(value) {
|
|
29447
|
-
if (!
|
|
27000
|
+
if (!isRecord7(value)) return { status: "unavailable", reason: "unreachable" };
|
|
29448
27001
|
if (value.rate_limits_available === false) {
|
|
29449
27002
|
return { status: "unavailable", reason: "unsupportedLogin" };
|
|
29450
27003
|
}
|
|
29451
|
-
if (value.rate_limits_available !== true || !
|
|
27004
|
+
if (value.rate_limits_available !== true || !isRecord7(value.rate_limits)) {
|
|
29452
27005
|
return { status: "unavailable", reason: "unreachable" };
|
|
29453
27006
|
}
|
|
29454
27007
|
const plan = claudePlanName({
|
|
@@ -29467,7 +27020,7 @@ async function readClaudeNativeQuota(input) {
|
|
|
29467
27020
|
signal?.throwIfAborted();
|
|
29468
27021
|
if (!recipe.binaryPath) return void 0;
|
|
29469
27022
|
try {
|
|
29470
|
-
const environment =
|
|
27023
|
+
const environment = mergeLaunchEnv3({
|
|
29471
27024
|
inherited: process.env,
|
|
29472
27025
|
instanceTable: recipe.environment,
|
|
29473
27026
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -29486,7 +27039,7 @@ async function readClaudeNativeQuota(input) {
|
|
|
29486
27039
|
createQuery: XAe,
|
|
29487
27040
|
stdin: quotaWriter,
|
|
29488
27041
|
options: {
|
|
29489
|
-
cwd:
|
|
27042
|
+
cwd: NodeOS8.tmpdir(),
|
|
29490
27043
|
pathToClaudeCodeExecutable: resolveClaudeSdkExecutablePath(
|
|
29491
27044
|
recipe.binaryPath,
|
|
29492
27045
|
environment
|
|
@@ -29510,10 +27063,10 @@ async function readClaudeNativeQuota(input) {
|
|
|
29510
27063
|
}
|
|
29511
27064
|
|
|
29512
27065
|
// src/usageRead/rateLimitEvent.ts
|
|
29513
|
-
var
|
|
27066
|
+
var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
29514
27067
|
var claudeQuotaFromRateLimitEvent = (message) => {
|
|
29515
|
-
const info =
|
|
29516
|
-
if (!
|
|
27068
|
+
const info = isRecord8(message) ? message["rate_limit_info"] : void 0;
|
|
27069
|
+
if (!isRecord8(info)) return null;
|
|
29517
27070
|
const spec = CLAUDE_QUOTA_WINDOWS.find((window2) => window2.field === info["rateLimitType"]);
|
|
29518
27071
|
const utilization = info["utilization"];
|
|
29519
27072
|
if (spec === void 0 || typeof utilization !== "number" || !Number.isFinite(utilization)) {
|
|
@@ -29533,200 +27086,16 @@ var claudeQuotaFromRateLimitEvent = (message) => {
|
|
|
29533
27086
|
};
|
|
29534
27087
|
};
|
|
29535
27088
|
|
|
29536
|
-
//
|
|
29537
|
-
import
|
|
29538
|
-
import * as NodePath17 from "node:path";
|
|
29539
|
-
var JSONL_SUFFIX = ".jsonl";
|
|
29540
|
-
async function listJsonlFiles(root, sinceMs) {
|
|
29541
|
-
const found = [];
|
|
29542
|
-
const walk = async (dir) => {
|
|
29543
|
-
let entries;
|
|
29544
|
-
try {
|
|
29545
|
-
entries = await NodeFS7.promises.readdir(dir, { withFileTypes: true });
|
|
29546
|
-
} catch {
|
|
29547
|
-
return;
|
|
29548
|
-
}
|
|
29549
|
-
for (const entry of entries) {
|
|
29550
|
-
const child = NodePath17.join(dir, entry.name);
|
|
29551
|
-
if (entry.isDirectory()) {
|
|
29552
|
-
await walk(child);
|
|
29553
|
-
continue;
|
|
29554
|
-
}
|
|
29555
|
-
if (!entry.isFile() || !entry.name.endsWith(JSONL_SUFFIX)) continue;
|
|
29556
|
-
let stat5;
|
|
29557
|
-
try {
|
|
29558
|
-
stat5 = await NodeFS7.promises.stat(child);
|
|
29559
|
-
} catch {
|
|
29560
|
-
continue;
|
|
29561
|
-
}
|
|
29562
|
-
if (stat5.mtimeMs >= sinceMs)
|
|
29563
|
-
found.push({ path: child, size: stat5.size, mtimeMs: stat5.mtimeMs });
|
|
29564
|
-
}
|
|
29565
|
-
};
|
|
29566
|
-
await walk(root);
|
|
29567
|
-
return found;
|
|
29568
|
-
}
|
|
29569
|
-
var GUARD_LENGTH = 64;
|
|
29570
|
-
var NEWLINE = 10;
|
|
29571
|
-
var CARRIAGE_RETURN = 13;
|
|
29572
|
-
var fnv1a = (bytes) => {
|
|
29573
|
-
let hash = 2166136261;
|
|
29574
|
-
for (let index = 0; index < bytes.length; index += 1) {
|
|
29575
|
-
hash ^= bytes[index];
|
|
29576
|
-
hash = Math.imul(hash, 16777619);
|
|
29577
|
-
}
|
|
29578
|
-
return hash >>> 0;
|
|
29579
|
-
};
|
|
29580
|
-
var asBuffer = (chunk) => typeof chunk === "string" ? Buffer.from(chunk) : Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
29581
|
-
async function readMatchingGuard(filePath, position) {
|
|
29582
|
-
const { guardLength, resumeOffset } = position;
|
|
29583
|
-
if (guardLength <= 0 || guardLength > GUARD_LENGTH || guardLength > resumeOffset) return null;
|
|
29584
|
-
try {
|
|
29585
|
-
const chunks = [];
|
|
29586
|
-
for await (const chunk of NodeFS7.createReadStream(filePath, {
|
|
29587
|
-
start: resumeOffset - guardLength,
|
|
29588
|
-
end: resumeOffset - 1
|
|
29589
|
-
})) {
|
|
29590
|
-
chunks.push(asBuffer(chunk));
|
|
29591
|
-
}
|
|
29592
|
-
const window2 = Buffer.concat(chunks);
|
|
29593
|
-
return window2.length === guardLength && fnv1a(window2) === position.guardHash ? window2 : null;
|
|
29594
|
-
} catch {
|
|
29595
|
-
return null;
|
|
29596
|
-
}
|
|
29597
|
-
}
|
|
29598
|
-
async function readAppendedJsonl(filePath, resumeFrom, openParser) {
|
|
29599
|
-
try {
|
|
29600
|
-
let resumed = false;
|
|
29601
|
-
let start = 0;
|
|
29602
|
-
let guardWindow = Buffer.alloc(0);
|
|
29603
|
-
if (resumeFrom !== void 0 && resumeFrom.resumeOffset > 0) {
|
|
29604
|
-
const window2 = await readMatchingGuard(filePath, resumeFrom);
|
|
29605
|
-
if (window2 !== null) {
|
|
29606
|
-
start = resumeFrom.resumeOffset;
|
|
29607
|
-
guardWindow = window2;
|
|
29608
|
-
resumed = true;
|
|
29609
|
-
}
|
|
29610
|
-
}
|
|
29611
|
-
const parser = openParser(resumed);
|
|
29612
|
-
const toLineString = (lineBuffer) => {
|
|
29613
|
-
const content = lineBuffer.length > 0 && lineBuffer[lineBuffer.length - 1] === CARRIAGE_RETURN ? lineBuffer.subarray(0, -1) : lineBuffer;
|
|
29614
|
-
return content.toString("utf8");
|
|
29615
|
-
};
|
|
29616
|
-
const records = [];
|
|
29617
|
-
let resumeOffset = start;
|
|
29618
|
-
let pendingChunks = [];
|
|
29619
|
-
for await (const raw of NodeFS7.createReadStream(filePath, start > 0 ? { start } : void 0)) {
|
|
29620
|
-
const chunk = asBuffer(raw);
|
|
29621
|
-
if (!chunk.includes(NEWLINE)) {
|
|
29622
|
-
pendingChunks.push(chunk);
|
|
29623
|
-
continue;
|
|
29624
|
-
}
|
|
29625
|
-
const buffer = pendingChunks.length === 0 ? chunk : Buffer.concat([...pendingChunks, chunk]);
|
|
29626
|
-
pendingChunks = [];
|
|
29627
|
-
let lineStart = 0;
|
|
29628
|
-
for (; ; ) {
|
|
29629
|
-
const newlineIndex = buffer.indexOf(NEWLINE, lineStart);
|
|
29630
|
-
if (newlineIndex === -1) break;
|
|
29631
|
-
const record3 = parser.line(toLineString(buffer.subarray(lineStart, newlineIndex)));
|
|
29632
|
-
if (record3 !== null) records.push(record3);
|
|
29633
|
-
lineStart = newlineIndex + 1;
|
|
29634
|
-
}
|
|
29635
|
-
resumeOffset += lineStart;
|
|
29636
|
-
const consumed = buffer.subarray(0, lineStart);
|
|
29637
|
-
guardWindow = consumed.length >= GUARD_LENGTH ? Buffer.from(consumed.subarray(-GUARD_LENGTH)) : Buffer.concat([guardWindow, consumed]).subarray(-GUARD_LENGTH);
|
|
29638
|
-
if (lineStart < buffer.length) pendingChunks.push(buffer.subarray(lineStart));
|
|
29639
|
-
}
|
|
29640
|
-
const tailRecords = [];
|
|
29641
|
-
if (pendingChunks.length > 0) {
|
|
29642
|
-
const pending2 = pendingChunks.length === 1 ? pendingChunks[0] : Buffer.concat(pendingChunks);
|
|
29643
|
-
if (pending2.length > 0) {
|
|
29644
|
-
const record3 = parser.tail(toLineString(pending2));
|
|
29645
|
-
if (record3 !== null) tailRecords.push(record3);
|
|
29646
|
-
}
|
|
29647
|
-
}
|
|
29648
|
-
return {
|
|
29649
|
-
records,
|
|
29650
|
-
tailRecords,
|
|
29651
|
-
position: {
|
|
29652
|
-
resumeOffset,
|
|
29653
|
-
guardLength: guardWindow.length,
|
|
29654
|
-
guardHash: guardWindow.length > 0 ? fnv1a(guardWindow) : 0
|
|
29655
|
-
},
|
|
29656
|
-
resumed
|
|
29657
|
-
};
|
|
29658
|
-
} catch {
|
|
29659
|
-
return null;
|
|
29660
|
-
}
|
|
29661
|
-
}
|
|
29662
|
-
|
|
29663
|
-
// ../../packages/ycodium-jsonl-stream/src/scanCache.ts
|
|
29664
|
-
import * as NodePath18 from "node:path";
|
|
29665
|
-
function decodeScanCacheTables(document, version) {
|
|
29666
|
-
if (typeof document !== "object" || document === null) return void 0;
|
|
29667
|
-
const root = document;
|
|
29668
|
-
if (root.version !== version) return void 0;
|
|
29669
|
-
if (!Array.isArray(root.models) || !Array.isArray(root.sessions)) return void 0;
|
|
29670
|
-
if (typeof root.files !== "object" || root.files === null) return void 0;
|
|
29671
|
-
if (!root.models.every((value) => typeof value === "string")) return void 0;
|
|
29672
|
-
if (!root.sessions.every((value) => typeof value === "string")) return void 0;
|
|
29673
|
-
return {
|
|
29674
|
-
models: root.models,
|
|
29675
|
-
sessions: root.sessions,
|
|
29676
|
-
files: root.files
|
|
29677
|
-
};
|
|
29678
|
-
}
|
|
29679
|
-
function createStringTable() {
|
|
29680
|
-
const values = [];
|
|
29681
|
-
const index = /* @__PURE__ */ new Map();
|
|
29682
|
-
return {
|
|
29683
|
-
values,
|
|
29684
|
-
intern: (value) => {
|
|
29685
|
-
const existing = index.get(value);
|
|
29686
|
-
if (existing !== void 0) return existing;
|
|
29687
|
-
const next = values.length;
|
|
29688
|
-
values.push(value);
|
|
29689
|
-
index.set(value, next);
|
|
29690
|
-
return next;
|
|
29691
|
-
}
|
|
29692
|
-
};
|
|
29693
|
-
}
|
|
29694
|
-
function encodeCachedFile(entry, serialize) {
|
|
29695
|
-
return {
|
|
29696
|
-
s: entry.size,
|
|
29697
|
-
m: entry.mtimeMs,
|
|
29698
|
-
r: entry.records.map(serialize),
|
|
29699
|
-
t: entry.tailRecords.map(serialize),
|
|
29700
|
-
o: entry.position.resumeOffset,
|
|
29701
|
-
gl: entry.position.guardLength,
|
|
29702
|
-
gh: entry.position.guardHash
|
|
29703
|
-
};
|
|
29704
|
-
}
|
|
29705
|
-
function decodeCachedPosition(entry) {
|
|
29706
|
-
const { o, gl: gl2, gh: gh2 } = entry;
|
|
29707
|
-
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)) {
|
|
29708
|
-
return void 0;
|
|
29709
|
-
}
|
|
29710
|
-
return { resumeOffset: o, guardLength: gl2, guardHash: gh2 };
|
|
29711
|
-
}
|
|
29712
|
-
function pruneScanCache(cache, options) {
|
|
29713
|
-
let removed = 0;
|
|
29714
|
-
for (const [path, entry] of cache) {
|
|
29715
|
-
const agedOut = entry.mtimeMs < options.retentionCutoffMs;
|
|
29716
|
-
const underWalkedRoot = options.walkedRoots.some((root) => {
|
|
29717
|
-
const relative2 = NodePath18.relative(root, path);
|
|
29718
|
-
return relative2 === "" || relative2 !== ".." && !relative2.startsWith(`..${NodePath18.sep}`) && !NodePath18.isAbsolute(relative2);
|
|
29719
|
-
});
|
|
29720
|
-
const deleted = underWalkedRoot && entry.mtimeMs >= options.windowStartMs && !options.livePaths.has(path);
|
|
29721
|
-
if (agedOut || deleted) {
|
|
29722
|
-
cache.delete(path);
|
|
29723
|
-
removed += 1;
|
|
29724
|
-
}
|
|
29725
|
-
}
|
|
29726
|
-
return removed;
|
|
29727
|
-
}
|
|
27089
|
+
// src/usageRead/tokenUsage.ts
|
|
27090
|
+
import { listJsonlFiles, pruneScanCache } from "@ycodium-ai/plugin-api/jsonl";
|
|
29728
27091
|
|
|
29729
27092
|
// src/usageRead/scanCache.ts
|
|
27093
|
+
import {
|
|
27094
|
+
createStringTable,
|
|
27095
|
+
decodeCachedPosition,
|
|
27096
|
+
decodeScanCacheTables,
|
|
27097
|
+
encodeCachedFile
|
|
27098
|
+
} from "@ycodium-ai/plugin-api/jsonl";
|
|
29730
27099
|
var USAGE_SCAN_CACHE_VERSION = 1;
|
|
29731
27100
|
function encodeScanCache(cache) {
|
|
29732
27101
|
const models = createStringTable();
|
|
@@ -29829,17 +27198,13 @@ function dedupeWithinFile(records, seen = /* @__PURE__ */ new Set()) {
|
|
|
29829
27198
|
}
|
|
29830
27199
|
|
|
29831
27200
|
// src/usageRead/transcriptScan.ts
|
|
29832
|
-
import * as
|
|
29833
|
-
|
|
29834
|
-
|
|
29835
|
-
|
|
29836
|
-
var parseTimestampMs = (value) => {
|
|
29837
|
-
if (typeof value !== "string") return null;
|
|
29838
|
-
const parsed = Date.parse(value);
|
|
29839
|
-
return Number.isNaN(parsed) ? null : parsed;
|
|
29840
|
-
};
|
|
27201
|
+
import * as NodeFS4 from "node:fs";
|
|
27202
|
+
import {
|
|
27203
|
+
readAppendedJsonl
|
|
27204
|
+
} from "@ycodium-ai/plugin-api/jsonl";
|
|
29841
27205
|
|
|
29842
27206
|
// src/usageRead/transcriptLine.ts
|
|
27207
|
+
import { parseTimestampMs, tokenCount } from "@ycodium-ai/plugin-api/jsonl";
|
|
29843
27208
|
var mightCarryUsage = (line) => line.includes('"usage"');
|
|
29844
27209
|
var parseClaudeLine = (line) => {
|
|
29845
27210
|
let parsed;
|
|
@@ -29884,9 +27249,9 @@ var parseClaudeLine = (line) => {
|
|
|
29884
27249
|
// src/usageRead/transcriptScan.ts
|
|
29885
27250
|
async function statTranscriptRoot(root) {
|
|
29886
27251
|
try {
|
|
29887
|
-
const
|
|
29888
|
-
if (!
|
|
29889
|
-
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)}` };
|
|
29890
27255
|
} catch {
|
|
29891
27256
|
return null;
|
|
29892
27257
|
}
|
|
@@ -30050,7 +27415,7 @@ var createClaudeUsage = (input) => {
|
|
|
30050
27415
|
});
|
|
30051
27416
|
const tokens = createClaudeTokenReader({
|
|
30052
27417
|
configDir,
|
|
30053
|
-
transcriptRoot:
|
|
27418
|
+
transcriptRoot: NodePath13.join(configDir, "projects"),
|
|
30054
27419
|
cache: input.cache
|
|
30055
27420
|
});
|
|
30056
27421
|
return {
|
|
@@ -30068,9 +27433,9 @@ var createClaudeUsage = (input) => {
|
|
|
30068
27433
|
// src/openCommands.ts
|
|
30069
27434
|
import { sameArgv } from "@ycodium-ai/plugin-api/executor";
|
|
30070
27435
|
var quote = (command) => "'" + command.replaceAll("'", `'"'"'`) + "'";
|
|
30071
|
-
var
|
|
27436
|
+
var basename2 = (path) => path.split(/[\\/]/).at(-1)?.toLowerCase() ?? "";
|
|
30072
27437
|
function claudeCommandMatches(command, argv) {
|
|
30073
|
-
if (argv.length !== 3 || !["bash.exe", "bash"].includes(
|
|
27438
|
+
if (argv.length !== 3 || !["bash.exe", "bash"].includes(basename2(argv[0] ?? "")) || argv[1] !== "-c")
|
|
30074
27439
|
return false;
|
|
30075
27440
|
const script = argv[2] ?? "";
|
|
30076
27441
|
const source = /^source \S+\/shell-snapshots\/snapshot-bash-\d+-[a-zA-Z0-9]+\.sh /;
|
|
@@ -30103,10 +27468,10 @@ function openCommandsOf(context) {
|
|
|
30103
27468
|
return {
|
|
30104
27469
|
rootPid: current.handle.pid,
|
|
30105
27470
|
sessionProcess: (argv, platform4) => {
|
|
30106
|
-
const
|
|
30107
|
-
const expected =
|
|
30108
|
-
const actual =
|
|
30109
|
-
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;
|
|
30110
27475
|
return sameProgram && sameArgv(argv.slice(1), current.args);
|
|
30111
27476
|
},
|
|
30112
27477
|
commands
|
|
@@ -30130,7 +27495,7 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
30130
27495
|
if (recipe.binaryPath.length === 0) throw new Error(CLAUDE_PROGRAM_NOT_CONFIGURED);
|
|
30131
27496
|
return sdkCreateQuery(input);
|
|
30132
27497
|
};
|
|
30133
|
-
const buildLaunchEnvironment = () =>
|
|
27498
|
+
const buildLaunchEnvironment = () => mergeLaunchEnv4({
|
|
30134
27499
|
inherited: { ...process.env, ...options?.environment },
|
|
30135
27500
|
instanceTable: recipe.environment,
|
|
30136
27501
|
handOverrides: claudeHomeVariables(resolveClaudeHomeLayout(recipe))
|
|
@@ -30365,7 +27730,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30365
27730
|
);
|
|
30366
27731
|
return {
|
|
30367
27732
|
configDir,
|
|
30368
|
-
transcriptDir:
|
|
27733
|
+
transcriptDir: NodePath14.join(configDir, "projects")
|
|
30369
27734
|
};
|
|
30370
27735
|
};
|
|
30371
27736
|
return {
|
|
@@ -30379,7 +27744,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30379
27744
|
try {
|
|
30380
27745
|
await adapter.modelCatalog.refresh({ force: true, signal });
|
|
30381
27746
|
} catch (error) {
|
|
30382
|
-
if (
|
|
27747
|
+
if (isOperationCleanupError4(error)) {
|
|
30383
27748
|
cleanupFailed = true;
|
|
30384
27749
|
throw error;
|
|
30385
27750
|
}
|
|
@@ -30448,7 +27813,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30448
27813
|
start: async () => {
|
|
30449
27814
|
const command = claudeSignInCommand(
|
|
30450
27815
|
recipe.credentialsPath,
|
|
30451
|
-
|
|
27816
|
+
NodeOS9.type() === "Windows_NT" ? "win32" : "linux"
|
|
30452
27817
|
);
|
|
30453
27818
|
return {
|
|
30454
27819
|
operationId: `claude-sign-in-${crypto.randomUUID()}`,
|
|
@@ -30495,10 +27860,10 @@ var index_default = definePlugin({
|
|
|
30495
27860
|
name: "effectiveConfig",
|
|
30496
27861
|
description: "Settings form: the config and credentials directories empty fields resolve to.",
|
|
30497
27862
|
scope: "read",
|
|
30498
|
-
payloadSchema:
|
|
27863
|
+
payloadSchema: EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
30499
27864
|
handle: async (payload) => {
|
|
30500
|
-
const request =
|
|
30501
|
-
const home =
|
|
27865
|
+
const request = readExecutorEffectiveRequest(payload);
|
|
27866
|
+
const home = executorHomeEffectiveValue(
|
|
30502
27867
|
"CLAUDE_CONFIG_DIR",
|
|
30503
27868
|
request,
|
|
30504
27869
|
process.env,
|
|
@@ -30517,11 +27882,11 @@ var index_default = definePlugin({
|
|
|
30517
27882
|
);
|
|
30518
27883
|
return {
|
|
30519
27884
|
homePath: home,
|
|
30520
|
-
credentialsPath: executorEnvironmentValue(credentialsVariable, request, process.env) !== null ?
|
|
27885
|
+
credentialsPath: executorEnvironmentValue(credentialsVariable, request, process.env) !== null ? executorHomeEffectiveValue(
|
|
30521
27886
|
credentialsVariable,
|
|
30522
27887
|
request,
|
|
30523
27888
|
process.env,
|
|
30524
|
-
(value) =>
|
|
27889
|
+
(value) => NodePath15.resolve(value ?? "")
|
|
30525
27890
|
) : keychain ? { detailKey: "form.credentialsPath.keychain" } : { value: configDirectory, detailKey: "form.credentialsPath.sameAsHome" }
|
|
30526
27891
|
};
|
|
30527
27892
|
}
|