@ycodium-ai/agent-claude 0.2.5448 → 0.2.5542
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +501 -120
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -41,9 +41,9 @@ Facts:
|
|
|
41
41
|
- Recordings: `test/fixtures/*.sdk.ndjson`, captured by
|
|
42
42
|
`scripts/record-claude-sdk-session.ts`; `src/replay.test.ts` replays them through
|
|
43
43
|
the same `createQuery` seam the recorder tapped.
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
- `credentialSources` lists the JSON file and macOS keychain locations.
|
|
45
|
+
- `sessions.scan` lists terminal sessions in the selected directory. `sessions.readImport`
|
|
46
|
+
reads the Claude transcript and supplies the cursor for resuming that session.
|
|
47
47
|
- Quota checks first ask Claude Code for its structured `/usage` data over the
|
|
48
48
|
SDK control protocol. Each check owns a short-lived, host-managed process with
|
|
49
49
|
the instance's executable and environment; it never borrows a working session
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as NodePath21 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 = 174;
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import {
|
|
@@ -1182,9 +1182,9 @@ async function* readJsonlEntries(fs2, path, options) {
|
|
|
1182
1182
|
};
|
|
1183
1183
|
const takeLine = () => {
|
|
1184
1184
|
if (parser !== null) {
|
|
1185
|
-
const
|
|
1185
|
+
const record3 = parser.finish();
|
|
1186
1186
|
parser = null;
|
|
1187
|
-
return { oversized:
|
|
1187
|
+
return { oversized: record3 };
|
|
1188
1188
|
}
|
|
1189
1189
|
if (pending2 === 0) return null;
|
|
1190
1190
|
let line = pieces.length === 1 ? pieces[0] ?? "" : pieces.join("");
|
|
@@ -1757,14 +1757,14 @@ async function readClaudeTranscriptDigest(source, filePath) {
|
|
|
1757
1757
|
fields: DIGEST_FIELDS
|
|
1758
1758
|
});
|
|
1759
1759
|
for await (const entry of entries) {
|
|
1760
|
-
const
|
|
1760
|
+
const record3 = jsonlEntryRecord(entry, (line) => {
|
|
1761
1761
|
const isUser = line.includes('"type":"user"');
|
|
1762
1762
|
const wantsAssistant = model === null && line.includes('"type":"assistant"');
|
|
1763
1763
|
const isTitle = line.includes('"custom-title"') || line.includes('"ai-title"');
|
|
1764
1764
|
return isUser || wantsAssistant || isTitle;
|
|
1765
1765
|
});
|
|
1766
|
-
if (!
|
|
1767
|
-
const typed =
|
|
1766
|
+
if (!record3 || typeof record3 !== "object") continue;
|
|
1767
|
+
const typed = record3;
|
|
1768
1768
|
if (cwd === null && typeof typed.cwd === "string" && typed.cwd.length > 0) cwd = typed.cwd;
|
|
1769
1769
|
if (typed.type === "custom-title" && typeof typed.customTitle === "string") {
|
|
1770
1770
|
customTitle = typed.customTitle;
|
|
@@ -22412,11 +22412,11 @@ function extractTextContent(value) {
|
|
|
22412
22412
|
if (!value || typeof value !== "object") {
|
|
22413
22413
|
return "";
|
|
22414
22414
|
}
|
|
22415
|
-
const
|
|
22416
|
-
if (typeof
|
|
22417
|
-
return
|
|
22415
|
+
const record3 = value;
|
|
22416
|
+
if (typeof record3.text === "string") {
|
|
22417
|
+
return record3.text;
|
|
22418
22418
|
}
|
|
22419
|
-
return extractTextContent(
|
|
22419
|
+
return extractTextContent(record3.content);
|
|
22420
22420
|
}
|
|
22421
22421
|
function toSessionError(threadId, cause) {
|
|
22422
22422
|
const normalized = toMessage(cause, "").toLowerCase();
|
|
@@ -22569,15 +22569,15 @@ function sdkMessageType(value) {
|
|
|
22569
22569
|
if (!value || typeof value !== "object") {
|
|
22570
22570
|
return void 0;
|
|
22571
22571
|
}
|
|
22572
|
-
const
|
|
22573
|
-
return typeof
|
|
22572
|
+
const record3 = value;
|
|
22573
|
+
return typeof record3.type === "string" ? record3.type : void 0;
|
|
22574
22574
|
}
|
|
22575
22575
|
function sdkMessageSubtype(value) {
|
|
22576
22576
|
if (!value || typeof value !== "object") {
|
|
22577
22577
|
return void 0;
|
|
22578
22578
|
}
|
|
22579
|
-
const
|
|
22580
|
-
return typeof
|
|
22579
|
+
const record3 = value;
|
|
22580
|
+
return typeof record3.subtype === "string" ? record3.subtype : void 0;
|
|
22581
22581
|
}
|
|
22582
22582
|
function sdkNativeMethod(message) {
|
|
22583
22583
|
const subtype = sdkMessageSubtype(message);
|
|
@@ -23358,16 +23358,16 @@ function normalizeTaskUsage(usage) {
|
|
|
23358
23358
|
if (typeof usage !== "object" || usage === null) {
|
|
23359
23359
|
return void 0;
|
|
23360
23360
|
}
|
|
23361
|
-
const
|
|
23362
|
-
const totalTokens = nonNegativeInt(
|
|
23361
|
+
const record3 = usage;
|
|
23362
|
+
const totalTokens = nonNegativeInt(record3.total_tokens);
|
|
23363
23363
|
if (totalTokens === void 0) {
|
|
23364
23364
|
return void 0;
|
|
23365
23365
|
}
|
|
23366
|
-
const inputTokens = nonNegativeInt(
|
|
23367
|
-
const cachedInputTokens = nonNegativeInt(
|
|
23368
|
-
const outputTokens = nonNegativeInt(
|
|
23369
|
-
const toolUses = nonNegativeInt(
|
|
23370
|
-
const durationMs = nonNegativeInt(
|
|
23366
|
+
const inputTokens = nonNegativeInt(record3.input_tokens);
|
|
23367
|
+
const cachedInputTokens = nonNegativeInt(record3.cache_read_input_tokens);
|
|
23368
|
+
const outputTokens = nonNegativeInt(record3.output_tokens);
|
|
23369
|
+
const toolUses = nonNegativeInt(record3.tool_uses);
|
|
23370
|
+
const durationMs = nonNegativeInt(record3.duration_ms);
|
|
23371
23371
|
return {
|
|
23372
23372
|
totalTokens,
|
|
23373
23373
|
...inputTokens !== void 0 ? { inputTokens } : {},
|
|
@@ -23426,11 +23426,11 @@ function parseWorkflowProgress(value) {
|
|
|
23426
23426
|
if (typeof entry !== "object" || entry === null) {
|
|
23427
23427
|
continue;
|
|
23428
23428
|
}
|
|
23429
|
-
const
|
|
23430
|
-
const entryType = trimmedString(
|
|
23429
|
+
const record3 = entry;
|
|
23430
|
+
const entryType = trimmedString(record3.type);
|
|
23431
23431
|
if (entryType === "workflow_phase") {
|
|
23432
|
-
const index2 = nonNegativeInt(
|
|
23433
|
-
const title = trimmedString(
|
|
23432
|
+
const index2 = nonNegativeInt(record3.index);
|
|
23433
|
+
const title = trimmedString(record3.title);
|
|
23434
23434
|
if (index2 !== void 0 && title && !phasesByIndex.has(index2)) {
|
|
23435
23435
|
phasesByIndex.set(index2, title);
|
|
23436
23436
|
}
|
|
@@ -23439,26 +23439,26 @@ function parseWorkflowProgress(value) {
|
|
|
23439
23439
|
if (entryType !== "workflow_agent") {
|
|
23440
23440
|
continue;
|
|
23441
23441
|
}
|
|
23442
|
-
const index = nonNegativeInt(
|
|
23443
|
-
const state = trimmedString(
|
|
23442
|
+
const index = nonNegativeInt(record3.index);
|
|
23443
|
+
const state = trimmedString(record3.state);
|
|
23444
23444
|
if (index === void 0 || !state || agentsByIndex.has(index)) {
|
|
23445
23445
|
continue;
|
|
23446
23446
|
}
|
|
23447
|
-
const nativeSessionId = trimmedString(
|
|
23447
|
+
const nativeSessionId = trimmedString(record3.session_id) ?? trimmedString(record3.sessionId) ?? trimmedString(record3.agent_id) ?? trimmedString(record3.agentId);
|
|
23448
23448
|
agentsByIndex.set(index, {
|
|
23449
23449
|
index,
|
|
23450
23450
|
...nativeSessionId ? { nativeSessionId } : {},
|
|
23451
23451
|
state,
|
|
23452
|
-
label: trimmedString(
|
|
23453
|
-
phaseIndex: nonNegativeInt(
|
|
23454
|
-
phaseTitle: trimmedString(
|
|
23455
|
-
model: trimmedString(
|
|
23456
|
-
attempt: nonNegativeInt(
|
|
23457
|
-
lastToolName: trimmedString(
|
|
23458
|
-
startedAt: trimmedString(
|
|
23459
|
-
error: trimmedString(
|
|
23460
|
-
tokens: nonNegativeInt(
|
|
23461
|
-
toolCalls: nonNegativeInt(
|
|
23452
|
+
label: trimmedString(record3.label),
|
|
23453
|
+
phaseIndex: nonNegativeInt(record3.phaseIndex),
|
|
23454
|
+
phaseTitle: trimmedString(record3.phaseTitle),
|
|
23455
|
+
model: trimmedString(record3.model),
|
|
23456
|
+
attempt: nonNegativeInt(record3.attempt),
|
|
23457
|
+
lastToolName: trimmedString(record3.lastToolName),
|
|
23458
|
+
startedAt: trimmedString(record3.startedAt),
|
|
23459
|
+
error: trimmedString(record3.error),
|
|
23460
|
+
tokens: nonNegativeInt(record3.tokens),
|
|
23461
|
+
toolCalls: nonNegativeInt(record3.toolCalls)
|
|
23462
23462
|
});
|
|
23463
23463
|
}
|
|
23464
23464
|
if (phasesByIndex.size === 0 && agentsByIndex.size === 0) {
|
|
@@ -23564,8 +23564,8 @@ function extractExitPlanModePlan(value) {
|
|
|
23564
23564
|
if (!value || typeof value !== "object") {
|
|
23565
23565
|
return void 0;
|
|
23566
23566
|
}
|
|
23567
|
-
const
|
|
23568
|
-
return typeof
|
|
23567
|
+
const record3 = value;
|
|
23568
|
+
return typeof record3.plan === "string" && record3.plan.trim().length > 0 ? record3.plan.trim() : void 0;
|
|
23569
23569
|
}
|
|
23570
23570
|
function exitPlanCaptureKey(input) {
|
|
23571
23571
|
return input.toolUseId && input.toolUseId.length > 0 ? `tool:${input.toolUseId}` : `plan:${input.planMarkdown}`;
|
|
@@ -25459,9 +25459,9 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25459
25459
|
signal.removeEventListener("abort", onAbort);
|
|
25460
25460
|
}
|
|
25461
25461
|
};
|
|
25462
|
-
const handleAskUserQuestion = async (context,
|
|
25462
|
+
const handleAskUserQuestion = async (context, toolInput2, callbackOptions) => {
|
|
25463
25463
|
const requestId = randomUUIDv4();
|
|
25464
|
-
const rawQuestions = Array.isArray(
|
|
25464
|
+
const rawQuestions = Array.isArray(toolInput2.questions) ? toolInput2.questions : [];
|
|
25465
25465
|
const questions = rawQuestions.map(
|
|
25466
25466
|
(q, idx) => ({
|
|
25467
25467
|
id: typeof q.question === "string" && q.question.length > 0 ? q.question : `q-${idx}`,
|
|
@@ -25506,7 +25506,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25506
25506
|
method: "canUseTool/AskUserQuestion",
|
|
25507
25507
|
payload: {
|
|
25508
25508
|
toolName: "AskUserQuestion",
|
|
25509
|
-
input:
|
|
25509
|
+
input: toolInput2
|
|
25510
25510
|
}
|
|
25511
25511
|
}
|
|
25512
25512
|
});
|
|
@@ -25547,7 +25547,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25547
25547
|
return {
|
|
25548
25548
|
behavior: "allow",
|
|
25549
25549
|
updatedInput: {
|
|
25550
|
-
questions:
|
|
25550
|
+
questions: toolInput2.questions,
|
|
25551
25551
|
answers
|
|
25552
25552
|
}
|
|
25553
25553
|
};
|
|
@@ -25558,7 +25558,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25558
25558
|
}
|
|
25559
25559
|
return { behavior: "completed", result: "never" };
|
|
25560
25560
|
};
|
|
25561
|
-
const canUseTool = async (toolName,
|
|
25561
|
+
const canUseTool = async (toolName, toolInput2, callbackOptions) => {
|
|
25562
25562
|
const context = await waitSessionContext();
|
|
25563
25563
|
if (!context) {
|
|
25564
25564
|
return {
|
|
@@ -25573,10 +25573,10 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25573
25573
|
};
|
|
25574
25574
|
}
|
|
25575
25575
|
if (toolName === "AskUserQuestion") {
|
|
25576
|
-
return await handleAskUserQuestion(context,
|
|
25576
|
+
return await handleAskUserQuestion(context, toolInput2, callbackOptions);
|
|
25577
25577
|
}
|
|
25578
25578
|
if (toolName === "ExitPlanMode") {
|
|
25579
|
-
const planMarkdown = extractExitPlanModePlan(
|
|
25579
|
+
const planMarkdown = extractExitPlanModePlan(toolInput2);
|
|
25580
25580
|
if (planMarkdown) {
|
|
25581
25581
|
await emitProposedPlanCompleted(context, {
|
|
25582
25582
|
planMarkdown,
|
|
@@ -25585,7 +25585,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25585
25585
|
rawMethod: "canUseTool/ExitPlanMode",
|
|
25586
25586
|
rawPayload: {
|
|
25587
25587
|
toolName,
|
|
25588
|
-
input:
|
|
25588
|
+
input: toolInput2
|
|
25589
25589
|
}
|
|
25590
25590
|
});
|
|
25591
25591
|
}
|
|
@@ -25597,15 +25597,15 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25597
25597
|
if (context.currentPermissionMode === "bypassPermissions") {
|
|
25598
25598
|
return {
|
|
25599
25599
|
behavior: "allow",
|
|
25600
|
-
updatedInput:
|
|
25600
|
+
updatedInput: toolInput2
|
|
25601
25601
|
};
|
|
25602
25602
|
}
|
|
25603
25603
|
await ensureSyntheticTurn(context);
|
|
25604
25604
|
const requestId = randomUUIDv4();
|
|
25605
25605
|
const requestType = classifyRequestType(toolName);
|
|
25606
|
-
const detail = summarizeToolRequest(toolName,
|
|
25607
|
-
const fileChanges = fileChangesFromClaudeToolInput(toolName,
|
|
25608
|
-
const requestToolName = requestType === "skill_approval" ? skillNameFromClaudeToolInput(
|
|
25606
|
+
const detail = summarizeToolRequest(toolName, toolInput2);
|
|
25607
|
+
const fileChanges = fileChangesFromClaudeToolInput(toolName, toolInput2);
|
|
25608
|
+
const requestToolName = requestType === "skill_approval" ? skillNameFromClaudeToolInput(toolInput2) ?? toolName : toolName;
|
|
25609
25609
|
const decisionDeferred = Promise.withResolvers();
|
|
25610
25610
|
const pendingApproval = {
|
|
25611
25611
|
requestType,
|
|
@@ -25623,9 +25623,9 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25623
25623
|
requestType,
|
|
25624
25624
|
detail,
|
|
25625
25625
|
toolName: requestToolName,
|
|
25626
|
-
args:
|
|
25626
|
+
args: toolInput2,
|
|
25627
25627
|
...fileChanges ? { fileChanges } : {},
|
|
25628
|
-
statement: claudeRequestStatement(toolName, requestType,
|
|
25628
|
+
statement: claudeRequestStatement(toolName, requestType, toolInput2),
|
|
25629
25629
|
declineReasonRelay: "native"
|
|
25630
25630
|
},
|
|
25631
25631
|
providerRefs: nativeProviderRefs({
|
|
@@ -25636,7 +25636,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25636
25636
|
method: "canUseTool/request",
|
|
25637
25637
|
payload: {
|
|
25638
25638
|
toolName,
|
|
25639
|
-
input:
|
|
25639
|
+
input: toolInput2
|
|
25640
25640
|
}
|
|
25641
25641
|
}
|
|
25642
25642
|
});
|
|
@@ -25681,7 +25681,7 @@ var makeSessionCallbacks = (deps) => {
|
|
|
25681
25681
|
if (decision === "accept" || decision === "acceptForSession") {
|
|
25682
25682
|
return {
|
|
25683
25683
|
behavior: "allow",
|
|
25684
|
-
updatedInput:
|
|
25684
|
+
updatedInput: toolInput2,
|
|
25685
25685
|
...decision === "acceptForSession" ? {
|
|
25686
25686
|
updatedPermissions: toSessionPermissionUpdates(
|
|
25687
25687
|
toolName,
|
|
@@ -26945,10 +26945,10 @@ var makeStreamEventHandler = (deps) => {
|
|
|
26945
26945
|
}
|
|
26946
26946
|
const toolName = block.name;
|
|
26947
26947
|
const itemType = classifyToolItemType(toolName);
|
|
26948
|
-
const
|
|
26948
|
+
const toolInput2 = typeof block.input === "object" && block.input !== null ? block.input : {};
|
|
26949
26949
|
const itemId = block.id;
|
|
26950
|
-
const detail = summarizeToolRequest(toolName,
|
|
26951
|
-
const inputFingerprint = Object.keys(
|
|
26950
|
+
const detail = summarizeToolRequest(toolName, toolInput2);
|
|
26951
|
+
const inputFingerprint = Object.keys(toolInput2).length > 0 ? toolInputFingerprint(toolInput2) : void 0;
|
|
26952
26952
|
const parentToolUseId = message.parent_tool_use_id ?? void 0;
|
|
26953
26953
|
const owningAgentId = agentIdForParentToolUse(context.taskAgents, parentToolUseId);
|
|
26954
26954
|
const stamp = await makeEventStamp();
|
|
@@ -26959,7 +26959,7 @@ var makeStreamEventHandler = (deps) => {
|
|
|
26959
26959
|
toolName,
|
|
26960
26960
|
title: titleForTool(itemType),
|
|
26961
26961
|
detail,
|
|
26962
|
-
input:
|
|
26962
|
+
input: toolInput2,
|
|
26963
26963
|
partialInputJson: "",
|
|
26964
26964
|
...inputFingerprint ? { lastEmittedInputFingerprint: inputFingerprint } : {},
|
|
26965
26965
|
...owningAgentId ? { agentId: owningAgentId } : {},
|
|
@@ -26981,7 +26981,7 @@ var makeStreamEventHandler = (deps) => {
|
|
|
26981
26981
|
...tool.parentToolUseId ? { parentToolUseId: tool.parentToolUseId } : {},
|
|
26982
26982
|
data: {
|
|
26983
26983
|
toolName: tool.toolName,
|
|
26984
|
-
input:
|
|
26984
|
+
input: toolInput2
|
|
26985
26985
|
}
|
|
26986
26986
|
},
|
|
26987
26987
|
providerRefs: nativeProviderRefs({
|
|
@@ -27125,11 +27125,11 @@ var claudeSlashCommandsFromNames = (names) => Array.isArray(names) ? names.flatM
|
|
|
27125
27125
|
return name === void 0 ? [] : [{ name }];
|
|
27126
27126
|
}) : [];
|
|
27127
27127
|
var claudeSlashCommandsFromSdk = (commands) => Array.isArray(commands) ? commands.flatMap((entry) => {
|
|
27128
|
-
const
|
|
27129
|
-
const name = nonEmptyString(
|
|
27128
|
+
const record3 = asRecord(entry);
|
|
27129
|
+
const name = nonEmptyString(record3?.["name"]);
|
|
27130
27130
|
if (name === void 0) return [];
|
|
27131
|
-
const description = nonEmptyString(
|
|
27132
|
-
const hint = nonEmptyString(
|
|
27131
|
+
const description = nonEmptyString(record3?.["description"]);
|
|
27132
|
+
const hint = nonEmptyString(record3?.["argumentHint"]);
|
|
27133
27133
|
return [
|
|
27134
27134
|
{
|
|
27135
27135
|
name,
|
|
@@ -27252,7 +27252,7 @@ var makeSystemMessageHandler = (deps) => {
|
|
|
27252
27252
|
}
|
|
27253
27253
|
};
|
|
27254
27254
|
const subtype = message.subtype;
|
|
27255
|
-
const
|
|
27255
|
+
const record3 = message;
|
|
27256
27256
|
switch (subtype) {
|
|
27257
27257
|
case "background_tasks_changed":
|
|
27258
27258
|
case "vcs_state_changed":
|
|
@@ -27262,13 +27262,13 @@ var makeSystemMessageHandler = (deps) => {
|
|
|
27262
27262
|
case "conversation_reset":
|
|
27263
27263
|
return;
|
|
27264
27264
|
case "informational":
|
|
27265
|
-
if (
|
|
27266
|
-
await emitRuntimeWarning(context,
|
|
27265
|
+
if (record3.level === "warning" && typeof record3.content === "string") {
|
|
27266
|
+
await emitRuntimeWarning(context, record3.content, message);
|
|
27267
27267
|
}
|
|
27268
27268
|
return;
|
|
27269
27269
|
case "model_refusal_no_fallback": {
|
|
27270
|
-
const explanation = typeof
|
|
27271
|
-
const content = typeof
|
|
27270
|
+
const explanation = typeof record3.api_refusal_explanation === "string" ? record3.api_refusal_explanation.trim() : "";
|
|
27271
|
+
const content = typeof record3.content === "string" ? record3.content : "";
|
|
27272
27272
|
const text2 = explanation || content;
|
|
27273
27273
|
if (text2.length > 0) await emitRuntimeWarning(context, text2, message);
|
|
27274
27274
|
return;
|
|
@@ -28196,6 +28196,290 @@ function claudeSignInCommand(credentialsPath, platform4) {
|
|
|
28196
28196
|
import * as NodeFS6 from "node:fs";
|
|
28197
28197
|
import * as NodeOS7 from "node:os";
|
|
28198
28198
|
import * as NodePath15 from "node:path";
|
|
28199
|
+
|
|
28200
|
+
// ../../packages/ycodium-jsonl-stream/src/sessionTranscript.ts
|
|
28201
|
+
import * as NodeCrypto3 from "node:crypto";
|
|
28202
|
+
var SESSION_IMPORT_ACTIVITY_TEXT_LIMIT = 32e3;
|
|
28203
|
+
var record2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
28204
|
+
var nonempty = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
28205
|
+
function fallbackId(value) {
|
|
28206
|
+
let text2;
|
|
28207
|
+
try {
|
|
28208
|
+
text2 = JSON.stringify(value) ?? "";
|
|
28209
|
+
} catch {
|
|
28210
|
+
text2 = "";
|
|
28211
|
+
}
|
|
28212
|
+
return `record:${NodeCrypto3.createHash("sha256").update(text2).digest("hex").slice(0, 20)}`;
|
|
28213
|
+
}
|
|
28214
|
+
function readableContent(value, textTypes) {
|
|
28215
|
+
if (typeof value === "string") return value;
|
|
28216
|
+
if (!Array.isArray(value)) return "";
|
|
28217
|
+
return value.flatMap((entry) => {
|
|
28218
|
+
if (typeof entry === "string") return [entry];
|
|
28219
|
+
const block = record2(entry);
|
|
28220
|
+
return block && textTypes.includes(String(block.type)) && typeof block.text === "string" ? [block.text] : [];
|
|
28221
|
+
}).join("\n\n");
|
|
28222
|
+
}
|
|
28223
|
+
function toolInput(value) {
|
|
28224
|
+
if (typeof value === "string") return value;
|
|
28225
|
+
const input = record2(value);
|
|
28226
|
+
if (input && Object.keys(input).length === 1 && typeof input.command === "string")
|
|
28227
|
+
return input.command;
|
|
28228
|
+
if (input && Object.keys(input).length === 1 && typeof input.cmd === "string") return input.cmd;
|
|
28229
|
+
if (value === void 0 || value === null) return void 0;
|
|
28230
|
+
try {
|
|
28231
|
+
return JSON.stringify(value, null, 2);
|
|
28232
|
+
} catch {
|
|
28233
|
+
return void 0;
|
|
28234
|
+
}
|
|
28235
|
+
}
|
|
28236
|
+
function bounded(value, tail = false) {
|
|
28237
|
+
if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
|
|
28238
|
+
const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
|
|
28239
|
+
const character = value.charCodeAt(offset);
|
|
28240
|
+
const previous = value.charCodeAt(offset - 1);
|
|
28241
|
+
const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
|
|
28242
|
+
return {
|
|
28243
|
+
text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
|
|
28244
|
+
truncated: true
|
|
28245
|
+
};
|
|
28246
|
+
}
|
|
28247
|
+
function inputPayload(input) {
|
|
28248
|
+
if (input === void 0) return {};
|
|
28249
|
+
const result = bounded(input);
|
|
28250
|
+
return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
|
|
28251
|
+
}
|
|
28252
|
+
function outputPayload(output) {
|
|
28253
|
+
if (output === void 0) return {};
|
|
28254
|
+
const result = bounded(output, true);
|
|
28255
|
+
return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
|
|
28256
|
+
}
|
|
28257
|
+
function reasoning(identity, text2, streamKind) {
|
|
28258
|
+
const result = bounded(text2);
|
|
28259
|
+
return {
|
|
28260
|
+
...identity,
|
|
28261
|
+
kind: "reasoning",
|
|
28262
|
+
tone: "info",
|
|
28263
|
+
summary: "Reasoning",
|
|
28264
|
+
payload: {
|
|
28265
|
+
text: result.text,
|
|
28266
|
+
streamKind,
|
|
28267
|
+
chars: result.text.length,
|
|
28268
|
+
streaming: false,
|
|
28269
|
+
...result.truncated ? { truncated: true } : {}
|
|
28270
|
+
}
|
|
28271
|
+
};
|
|
28272
|
+
}
|
|
28273
|
+
|
|
28274
|
+
// src/sessionTranscript.ts
|
|
28275
|
+
var nativeText = (value) => readableContent(value, ["text", "input_text", "output_text", "summary_text", "reasoning_text"]);
|
|
28276
|
+
function nativeModel(value) {
|
|
28277
|
+
const model = nonempty(value);
|
|
28278
|
+
return model?.trim() === "<synthetic>" ? void 0 : model;
|
|
28279
|
+
}
|
|
28280
|
+
function toolType(name) {
|
|
28281
|
+
const normalized = name.toLowerCase();
|
|
28282
|
+
if (/^(bash|shell|command|terminal|exec_command|write_stdin)$/u.test(normalized))
|
|
28283
|
+
return "command_execution";
|
|
28284
|
+
if (/^(edit|write|multiedit|apply_patch|applypatch|patch)$/u.test(normalized))
|
|
28285
|
+
return "file_change";
|
|
28286
|
+
if (/^(agent|task|workflow)$/u.test(normalized)) return "dynamic_tool_call";
|
|
28287
|
+
if (normalized.startsWith("mcp")) return "mcp_tool_call";
|
|
28288
|
+
if (/^(websearch|webfetch|web_search)$/u.test(normalized)) return "web_search";
|
|
28289
|
+
return "dynamic_tool_call";
|
|
28290
|
+
}
|
|
28291
|
+
function readClaudeTranscript(records) {
|
|
28292
|
+
const messages = [];
|
|
28293
|
+
const activities = [];
|
|
28294
|
+
const byUuid = /* @__PURE__ */ new Map();
|
|
28295
|
+
const tools = /* @__PURE__ */ new Map();
|
|
28296
|
+
const toolsById = /* @__PURE__ */ new Map();
|
|
28297
|
+
for (const raw of records) {
|
|
28298
|
+
const value = record2(raw);
|
|
28299
|
+
if (!value || value.type !== "user" && value.type !== "assistant") continue;
|
|
28300
|
+
if (value.isSidechain === true || value.isSideChain === true || value.isMeta === true || nonempty(value.parent_tool_use_id))
|
|
28301
|
+
continue;
|
|
28302
|
+
const uuid = nonempty(value.uuid) ?? fallbackId(raw);
|
|
28303
|
+
const previous = byUuid.get(uuid);
|
|
28304
|
+
const beforeMessage = record2(previous?.message);
|
|
28305
|
+
const nextMessage = record2(value.message);
|
|
28306
|
+
if (previous && beforeMessage && nextMessage && Array.isArray(beforeMessage.content) && Array.isArray(nextMessage.content)) {
|
|
28307
|
+
const beforeBlocks = beforeMessage.content;
|
|
28308
|
+
byUuid.set(uuid, {
|
|
28309
|
+
...previous,
|
|
28310
|
+
...value,
|
|
28311
|
+
message: {
|
|
28312
|
+
...beforeMessage,
|
|
28313
|
+
...nextMessage,
|
|
28314
|
+
content: nextMessage.content.map((entry, index) => {
|
|
28315
|
+
const block = record2(entry);
|
|
28316
|
+
const before = record2(beforeBlocks[index]);
|
|
28317
|
+
return block?.type === "tool_result" && before?.type === "tool_result" && block.tool_use_id === before.tool_use_id && block.is_error === void 0 && before.is_error === true ? { ...block, is_error: true } : entry;
|
|
28318
|
+
})
|
|
28319
|
+
}
|
|
28320
|
+
});
|
|
28321
|
+
} else byUuid.set(uuid, value);
|
|
28322
|
+
}
|
|
28323
|
+
let nativeTurnId;
|
|
28324
|
+
let sourceOrder = 0;
|
|
28325
|
+
for (const [uuid, value] of byUuid) {
|
|
28326
|
+
const message = record2(value.message);
|
|
28327
|
+
if (!message) continue;
|
|
28328
|
+
const content = message.content;
|
|
28329
|
+
const blocks = typeof content === "string" ? [{ type: "text", text: content }] : Array.isArray(content) ? content : [];
|
|
28330
|
+
const hasToolResult = blocks.some((block) => record2(block)?.type === "tool_result");
|
|
28331
|
+
const hasUserText = value.type === "user" && !hasToolResult && blocks.some((block) => {
|
|
28332
|
+
const text2 = record2(block);
|
|
28333
|
+
return text2?.type === "text" && nonempty(text2.text) !== void 0;
|
|
28334
|
+
});
|
|
28335
|
+
const hasUserInput = hasUserText || value.type === "user" && !hasToolResult && blocks.some((block) => record2(block)?.type === "image");
|
|
28336
|
+
if (hasUserInput) nativeTurnId = nonempty(value.uuid);
|
|
28337
|
+
const createdAt = typeof value.timestamp === "string" ? value.timestamp : "";
|
|
28338
|
+
const model = nativeModel(message.model) ?? nativeModel(value.model);
|
|
28339
|
+
for (const [blockIndex, rawBlock] of blocks.entries()) {
|
|
28340
|
+
const block = record2(rawBlock);
|
|
28341
|
+
const identity = {
|
|
28342
|
+
sourceId: `claude:${uuid}:block:${blockIndex}`,
|
|
28343
|
+
sourceOrder: sourceOrder++,
|
|
28344
|
+
createdAt,
|
|
28345
|
+
...nativeTurnId !== void 0 ? { nativeTurnId } : {},
|
|
28346
|
+
...model !== void 0 ? { model } : {}
|
|
28347
|
+
};
|
|
28348
|
+
if (!block) continue;
|
|
28349
|
+
if (block.type === "text" && nonempty(block.text) !== void 0 && (value.type === "assistant" || hasUserText)) {
|
|
28350
|
+
messages.push({
|
|
28351
|
+
...identity,
|
|
28352
|
+
role: value.type === "assistant" ? "assistant" : "user",
|
|
28353
|
+
text: block.text
|
|
28354
|
+
});
|
|
28355
|
+
} else if (value.type === "assistant" && block.type === "thinking" && nonempty(block.thinking) !== void 0) {
|
|
28356
|
+
activities.push(reasoning(identity, block.thinking, "reasoning_text"));
|
|
28357
|
+
} else if (value.type === "assistant" && (block.type === "tool_use" || block.type === "server_tool_use" || block.type === "mcp_tool_use")) {
|
|
28358
|
+
const toolCallId = nonempty(block.id);
|
|
28359
|
+
if (!toolCallId) continue;
|
|
28360
|
+
const key = `${nativeTurnId ?? ""}\0${toolCallId}`;
|
|
28361
|
+
const name = nonempty(block.name) ?? "Tool";
|
|
28362
|
+
const input = toolInput(block.input);
|
|
28363
|
+
const known = tools.get(key);
|
|
28364
|
+
if (known) {
|
|
28365
|
+
if (input !== void 0 && input !== "{}" && known.startIndex !== void 0) {
|
|
28366
|
+
const { inputTruncated: _inputTruncated, ...before } = known.start.payload;
|
|
28367
|
+
known.start = { ...known.start, payload: { ...before, ...inputPayload(input) } };
|
|
28368
|
+
activities[known.startIndex] = known.start;
|
|
28369
|
+
if (known.completionIndex !== void 0) {
|
|
28370
|
+
const completion = activities[known.completionIndex];
|
|
28371
|
+
const { inputTruncated: _completedTruncated, ...completedPayload } = completion.payload;
|
|
28372
|
+
activities[known.completionIndex] = {
|
|
28373
|
+
...completion,
|
|
28374
|
+
payload: { ...completedPayload, ...inputPayload(input) }
|
|
28375
|
+
};
|
|
28376
|
+
}
|
|
28377
|
+
}
|
|
28378
|
+
continue;
|
|
28379
|
+
}
|
|
28380
|
+
const start = {
|
|
28381
|
+
...identity,
|
|
28382
|
+
kind: "tool.started",
|
|
28383
|
+
tone: "tool",
|
|
28384
|
+
summary: name,
|
|
28385
|
+
payload: {
|
|
28386
|
+
toolCallId,
|
|
28387
|
+
itemType: toolType(name),
|
|
28388
|
+
toolName: name,
|
|
28389
|
+
startedAt: createdAt,
|
|
28390
|
+
...inputPayload(input)
|
|
28391
|
+
}
|
|
28392
|
+
};
|
|
28393
|
+
const startIndex = activities.push(start) - 1;
|
|
28394
|
+
const tool = { start, startIndex, completedId: `${identity.sourceId}:completed` };
|
|
28395
|
+
tools.set(key, tool);
|
|
28396
|
+
toolsById.set(toolCallId, tool);
|
|
28397
|
+
} else if (block.type === "tool_result") {
|
|
28398
|
+
const toolCallId = nonempty(block.tool_use_id);
|
|
28399
|
+
if (!toolCallId) continue;
|
|
28400
|
+
const key = `${nativeTurnId ?? ""}\0${toolCallId}`;
|
|
28401
|
+
const tool = tools.get(key) ?? toolsById.get(toolCallId);
|
|
28402
|
+
const output = nativeText(block.content);
|
|
28403
|
+
const previousStatus = tool?.completionIndex !== void 0 ? activities[tool.completionIndex]?.payload.status : void 0;
|
|
28404
|
+
const status = block.is_error === true || block.status === "failed" ? "failed" : block.is_error === false ? "completed" : previousStatus === "failed" ? "failed" : "completed";
|
|
28405
|
+
const completed = {
|
|
28406
|
+
...identity,
|
|
28407
|
+
sourceId: tool?.completedId ?? `claude:tool:${toolCallId}:completed`,
|
|
28408
|
+
...tool?.start.nativeTurnId !== void 0 ? { nativeTurnId: tool.start.nativeTurnId } : {},
|
|
28409
|
+
...tool?.start.model !== void 0 ? { model: tool.start.model } : {},
|
|
28410
|
+
kind: "tool.completed",
|
|
28411
|
+
tone: status === "failed" ? "error" : "tool",
|
|
28412
|
+
summary: tool?.start.summary ?? "Tool",
|
|
28413
|
+
payload: {
|
|
28414
|
+
...tool?.start.payload,
|
|
28415
|
+
toolCallId,
|
|
28416
|
+
itemType: tool?.start.payload.itemType ?? "dynamic_tool_call",
|
|
28417
|
+
status,
|
|
28418
|
+
...outputPayload(output)
|
|
28419
|
+
}
|
|
28420
|
+
};
|
|
28421
|
+
if (tool?.completionIndex !== void 0) {
|
|
28422
|
+
const previous = activities[tool.completionIndex];
|
|
28423
|
+
activities[tool.completionIndex] = {
|
|
28424
|
+
...completed,
|
|
28425
|
+
sourceOrder: previous.sourceOrder,
|
|
28426
|
+
createdAt: previous.createdAt
|
|
28427
|
+
};
|
|
28428
|
+
} else {
|
|
28429
|
+
const completionIndex = activities.push(completed) - 1;
|
|
28430
|
+
if (tool) tool.completionIndex = completionIndex;
|
|
28431
|
+
else {
|
|
28432
|
+
const orphan = { start: completed, completedId: completed.sourceId, completionIndex };
|
|
28433
|
+
tools.set(key, orphan);
|
|
28434
|
+
toolsById.set(toolCallId, orphan);
|
|
28435
|
+
}
|
|
28436
|
+
}
|
|
28437
|
+
}
|
|
28438
|
+
}
|
|
28439
|
+
}
|
|
28440
|
+
return {
|
|
28441
|
+
messages,
|
|
28442
|
+
activities,
|
|
28443
|
+
availableMessages: messages.length,
|
|
28444
|
+
availableActivities: activities.length
|
|
28445
|
+
};
|
|
28446
|
+
}
|
|
28447
|
+
|
|
28448
|
+
// src/sessions.ts
|
|
28449
|
+
var TOOL_TEXT_KEEP_CHARS = 64e3;
|
|
28450
|
+
var TRANSCRIPT_FIELDS = [
|
|
28451
|
+
{ path: ["type"] },
|
|
28452
|
+
{ path: ["uuid"] },
|
|
28453
|
+
{ path: ["isSidechain"] },
|
|
28454
|
+
{ path: ["isSideChain"] },
|
|
28455
|
+
{ path: ["isMeta"] },
|
|
28456
|
+
{ path: ["parent_tool_use_id"] },
|
|
28457
|
+
{ path: ["timestamp"] },
|
|
28458
|
+
{ path: ["model"] },
|
|
28459
|
+
{ path: ["message", "model"] },
|
|
28460
|
+
{ path: ["message", "content"], scalarOnly: true },
|
|
28461
|
+
{ path: ["message", "content", "*", "type"] },
|
|
28462
|
+
// 消息正文不截:它就是导入的内容。
|
|
28463
|
+
{ path: ["message", "content", "*", "text"] },
|
|
28464
|
+
{ path: ["message", "content", "*", "thinking"], maxChars: TOOL_TEXT_KEEP_CHARS },
|
|
28465
|
+
{ path: ["message", "content", "*", "id"] },
|
|
28466
|
+
{ path: ["message", "content", "*", "name"] },
|
|
28467
|
+
{ path: ["message", "content", "*", "input"], maxChars: TOOL_TEXT_KEEP_CHARS },
|
|
28468
|
+
{ path: ["message", "content", "*", "tool_use_id"] },
|
|
28469
|
+
{ path: ["message", "content", "*", "is_error"] },
|
|
28470
|
+
{ path: ["message", "content", "*", "status"] },
|
|
28471
|
+
// tool_result 的 content 可能是字符串,也可能是块数组;块只认文本块。
|
|
28472
|
+
{
|
|
28473
|
+
path: ["message", "content", "*", "content"],
|
|
28474
|
+
scalarOnly: true,
|
|
28475
|
+
maxChars: TOOL_TEXT_KEEP_CHARS
|
|
28476
|
+
},
|
|
28477
|
+
{ path: ["message", "content", "*", "content", "*", "type"] },
|
|
28478
|
+
{
|
|
28479
|
+
path: ["message", "content", "*", "content", "*", "text"],
|
|
28480
|
+
maxChars: TOOL_TEXT_KEEP_CHARS
|
|
28481
|
+
}
|
|
28482
|
+
];
|
|
28199
28483
|
var fileSource = {
|
|
28200
28484
|
createReadStream: (path) => NodeFS6.createReadStream(path)
|
|
28201
28485
|
};
|
|
@@ -28223,7 +28507,8 @@ var sessionFileSystem = {
|
|
|
28223
28507
|
},
|
|
28224
28508
|
readFile: (path) => NodeFS6.promises.readFile(path, "utf8")
|
|
28225
28509
|
};
|
|
28226
|
-
async function scanClaudeSessions(input) {
|
|
28510
|
+
async function scanClaudeSessions(input, cache) {
|
|
28511
|
+
input.signal?.throwIfAborted();
|
|
28227
28512
|
let root;
|
|
28228
28513
|
try {
|
|
28229
28514
|
root = NodeFS6.statSync(input.transcriptDir);
|
|
@@ -28240,10 +28525,22 @@ async function scanClaudeSessions(input) {
|
|
|
28240
28525
|
].sort((left, right) => right.mtimeMs - left.mtimeMs).slice(0, CLAUDE_MAX_SCANNED_FILES);
|
|
28241
28526
|
const live = await readClaudeLiveSessionIds(sessionFileSystem, input.configDir);
|
|
28242
28527
|
const caseInsensitive = input.caseInsensitive ?? NodeOS7.type() === "Windows_NT";
|
|
28528
|
+
const signal = input.signal;
|
|
28529
|
+
const source = signal ? { createReadStream: (path) => NodeFS6.createReadStream(path, { signal }) } : fileSource;
|
|
28243
28530
|
const rows = [];
|
|
28244
28531
|
for (const file of files) {
|
|
28532
|
+
signal?.throwIfAborted();
|
|
28245
28533
|
if (rows.length >= CLAUDE_MAX_ROWS) break;
|
|
28246
|
-
const
|
|
28534
|
+
const key = JSON.stringify([file.path, file.size, file.mtimeMs]);
|
|
28535
|
+
const digest = cache?.get(key) ?? await readClaudeTranscriptDigest(source, file.path);
|
|
28536
|
+
signal?.throwIfAborted();
|
|
28537
|
+
if (digest !== null && cache && !cache.has(key)) {
|
|
28538
|
+
if (cache.size >= CLAUDE_MAX_SCANNED_FILES) {
|
|
28539
|
+
const oldest = cache.keys().next();
|
|
28540
|
+
if (!oldest.done) cache.delete(oldest.value);
|
|
28541
|
+
}
|
|
28542
|
+
cache.set(key, digest);
|
|
28543
|
+
}
|
|
28247
28544
|
if (digest === null || digest.cwd === null) continue;
|
|
28248
28545
|
if (!isWithinDirectory(digest.cwd, input.directory, caseInsensitive)) continue;
|
|
28249
28546
|
rows.push({
|
|
@@ -28258,6 +28555,7 @@ async function scanClaudeSessions(input) {
|
|
|
28258
28555
|
openElsewhere: live.has(file.sessionId)
|
|
28259
28556
|
});
|
|
28260
28557
|
}
|
|
28558
|
+
signal?.throwIfAborted();
|
|
28261
28559
|
return rows;
|
|
28262
28560
|
}
|
|
28263
28561
|
function resolveTranscriptPath(input) {
|
|
@@ -28292,7 +28590,7 @@ function resolveTranscriptPath(input) {
|
|
|
28292
28590
|
function isRecord5(value) {
|
|
28293
28591
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
28294
28592
|
}
|
|
28295
|
-
function
|
|
28593
|
+
function nonempty2(value) {
|
|
28296
28594
|
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
28297
28595
|
}
|
|
28298
28596
|
async function readClaudeSessionRecord(input) {
|
|
@@ -28320,8 +28618,8 @@ async function readClaudeSessionRecord(input) {
|
|
|
28320
28618
|
if (parsed.type !== "user" && parsed.type !== "assistant") continue;
|
|
28321
28619
|
if (parsed.isSidechain === true || parsed.isSideChain === true || parsed.isMeta === true)
|
|
28322
28620
|
continue;
|
|
28323
|
-
if (
|
|
28324
|
-
const uuid =
|
|
28621
|
+
if (nonempty2(parsed.parent_tool_use_id)) continue;
|
|
28622
|
+
const uuid = nonempty2(parsed.uuid) ?? `record:${messages.length}`;
|
|
28325
28623
|
byUuid.set(uuid, parsed);
|
|
28326
28624
|
}
|
|
28327
28625
|
for (const value of byUuid.values()) {
|
|
@@ -28354,6 +28652,82 @@ async function readClaudeSessionRecord(input) {
|
|
|
28354
28652
|
model
|
|
28355
28653
|
};
|
|
28356
28654
|
}
|
|
28655
|
+
async function findBoundClaudeTranscript(root, sessionId, signal) {
|
|
28656
|
+
let found = null;
|
|
28657
|
+
const fileName = `${sessionId}${CLAUDE_TRANSCRIPT_SUFFIX}`;
|
|
28658
|
+
const directories = await NodeFS6.promises.readdir(root, { withFileTypes: true });
|
|
28659
|
+
for (const directory of directories) {
|
|
28660
|
+
signal?.throwIfAborted();
|
|
28661
|
+
if (!directory.isDirectory()) continue;
|
|
28662
|
+
const path = NodePath15.join(root, directory.name, fileName);
|
|
28663
|
+
const stat5 = await NodeFS6.promises.lstat(path).catch((error) => {
|
|
28664
|
+
if (error.code === "ENOENT" || error.code === "ENOTDIR") return void 0;
|
|
28665
|
+
throw error;
|
|
28666
|
+
});
|
|
28667
|
+
if (!stat5?.isFile()) continue;
|
|
28668
|
+
if (found !== null) throw new Error(`Multiple transcripts for Claude session ${sessionId}.`);
|
|
28669
|
+
found = path;
|
|
28670
|
+
}
|
|
28671
|
+
return found;
|
|
28672
|
+
}
|
|
28673
|
+
function createClaudeImportReader() {
|
|
28674
|
+
let cached;
|
|
28675
|
+
return async (input) => {
|
|
28676
|
+
input.signal?.throwIfAborted();
|
|
28677
|
+
const { cwd } = input;
|
|
28678
|
+
if (!/^[\w-]+$/.test(input.nativeSessionId) || cwd !== void 0 && !NodePath15.isAbsolute(cwd)) {
|
|
28679
|
+
throw new Error("Invalid Claude session identity or working directory.");
|
|
28680
|
+
}
|
|
28681
|
+
const path = cwd === void 0 ? await findBoundClaudeTranscript(input.transcriptDir, input.nativeSessionId, input.signal) : resolveTranscriptPath({
|
|
28682
|
+
transcriptDir: input.transcriptDir,
|
|
28683
|
+
sessionId: input.nativeSessionId,
|
|
28684
|
+
cwd
|
|
28685
|
+
});
|
|
28686
|
+
if (path === null)
|
|
28687
|
+
throw new Error(`No transcript file for Claude session ${input.nativeSessionId}.`);
|
|
28688
|
+
const version = async () => {
|
|
28689
|
+
const stat5 = await NodeFS6.promises.stat(path, { bigint: true });
|
|
28690
|
+
return [stat5.dev, stat5.ino, stat5.size, stat5.mtimeNs, stat5.ctimeNs].join(":");
|
|
28691
|
+
};
|
|
28692
|
+
const before = await version();
|
|
28693
|
+
const key = JSON.stringify([path, input.cwd, before]);
|
|
28694
|
+
input.signal?.throwIfAborted();
|
|
28695
|
+
if (cached?.key === key) return cached.result;
|
|
28696
|
+
const source = {
|
|
28697
|
+
createReadStream: (path2) => NodeFS6.createReadStream(path2, input.signal ? { signal: input.signal } : {})
|
|
28698
|
+
};
|
|
28699
|
+
const digest = await readClaudeTranscriptDigest(source, path);
|
|
28700
|
+
input.signal?.throwIfAborted();
|
|
28701
|
+
const caseInsensitive = NodeOS7.type() === "Windows_NT";
|
|
28702
|
+
if (digest === null || cwd !== void 0 && (!digest.cwd || !NodePath15.isAbsolute(digest.cwd) || !isWithinDirectory(digest.cwd, cwd, caseInsensitive) || !isWithinDirectory(cwd, digest.cwd, caseInsensitive))) {
|
|
28703
|
+
throw new Error("The native Claude session does not match the requested directory.");
|
|
28704
|
+
}
|
|
28705
|
+
const records = [];
|
|
28706
|
+
for await (const entry of readJsonlEntries(source, path, {
|
|
28707
|
+
maxLineChars: CLAUDE_MAX_PARSED_LINE_BYTES,
|
|
28708
|
+
fields: TRANSCRIPT_FIELDS
|
|
28709
|
+
})) {
|
|
28710
|
+
const parsed = jsonlEntryRecord(
|
|
28711
|
+
entry,
|
|
28712
|
+
(line) => line.includes('"type":"user"') || line.includes('"type":"assistant"')
|
|
28713
|
+
);
|
|
28714
|
+
if (parsed !== void 0) records.push(parsed);
|
|
28715
|
+
}
|
|
28716
|
+
const transcript = readClaudeTranscript(records);
|
|
28717
|
+
const result = {
|
|
28718
|
+
...transcript,
|
|
28719
|
+
title: digest.title,
|
|
28720
|
+
model: digest.model,
|
|
28721
|
+
resumeCursor: { resume: input.nativeSessionId }
|
|
28722
|
+
};
|
|
28723
|
+
if (await version() !== before) {
|
|
28724
|
+
throw new Error("The native Claude transcript changed while it was being read.");
|
|
28725
|
+
}
|
|
28726
|
+
input.signal?.throwIfAborted();
|
|
28727
|
+
cached = { key, result };
|
|
28728
|
+
return result;
|
|
28729
|
+
};
|
|
28730
|
+
}
|
|
28357
28731
|
|
|
28358
28732
|
// src/textGeneration.ts
|
|
28359
28733
|
import * as NodeFSP8 from "node:fs/promises";
|
|
@@ -29212,8 +29586,8 @@ async function readAppendedJsonl(filePath, resumeFrom, openParser) {
|
|
|
29212
29586
|
for (; ; ) {
|
|
29213
29587
|
const newlineIndex = buffer.indexOf(NEWLINE, lineStart);
|
|
29214
29588
|
if (newlineIndex === -1) break;
|
|
29215
|
-
const
|
|
29216
|
-
if (
|
|
29589
|
+
const record3 = parser.line(toLineString(buffer.subarray(lineStart, newlineIndex)));
|
|
29590
|
+
if (record3 !== null) records.push(record3);
|
|
29217
29591
|
lineStart = newlineIndex + 1;
|
|
29218
29592
|
}
|
|
29219
29593
|
resumeOffset += lineStart;
|
|
@@ -29225,8 +29599,8 @@ async function readAppendedJsonl(filePath, resumeFrom, openParser) {
|
|
|
29225
29599
|
if (pendingChunks.length > 0) {
|
|
29226
29600
|
const pending2 = pendingChunks.length === 1 ? pendingChunks[0] : Buffer.concat(pendingChunks);
|
|
29227
29601
|
if (pending2.length > 0) {
|
|
29228
|
-
const
|
|
29229
|
-
if (
|
|
29602
|
+
const record3 = parser.tail(toLineString(pending2));
|
|
29603
|
+
if (record3 !== null) tailRecords.push(record3);
|
|
29230
29604
|
}
|
|
29231
29605
|
}
|
|
29232
29606
|
return {
|
|
@@ -29315,17 +29689,17 @@ var USAGE_SCAN_CACHE_VERSION = 1;
|
|
|
29315
29689
|
function encodeScanCache(cache) {
|
|
29316
29690
|
const models = createStringTable();
|
|
29317
29691
|
const sessions = createStringTable();
|
|
29318
|
-
const serializeRecord = (
|
|
29319
|
-
|
|
29320
|
-
models.intern(
|
|
29321
|
-
sessions.intern(
|
|
29322
|
-
|
|
29323
|
-
|
|
29324
|
-
|
|
29325
|
-
|
|
29326
|
-
|
|
29327
|
-
|
|
29328
|
-
|
|
29692
|
+
const serializeRecord = (record3) => [
|
|
29693
|
+
record3.timestampMs,
|
|
29694
|
+
models.intern(record3.model),
|
|
29695
|
+
sessions.intern(record3.sessionId),
|
|
29696
|
+
record3.totals.uncachedInputTokens,
|
|
29697
|
+
record3.totals.cachedInputTokens,
|
|
29698
|
+
record3.totals.cacheCreationTokens,
|
|
29699
|
+
record3.totals.outputTokens,
|
|
29700
|
+
record3.totals.reasoningTokens,
|
|
29701
|
+
record3.dedupeKey,
|
|
29702
|
+
record3.reportedCostUsd
|
|
29329
29703
|
];
|
|
29330
29704
|
const files = {};
|
|
29331
29705
|
for (const [path, entry] of cache) {
|
|
@@ -29355,12 +29729,12 @@ function decodeScanCache(document) {
|
|
|
29355
29729
|
cached,
|
|
29356
29730
|
cacheCreation,
|
|
29357
29731
|
output,
|
|
29358
|
-
|
|
29732
|
+
reasoning2,
|
|
29359
29733
|
dedupeKey,
|
|
29360
29734
|
reportedCostUsd
|
|
29361
29735
|
] = row;
|
|
29362
29736
|
const model = typeof modelIndex === "number" ? models[modelIndex] : void 0;
|
|
29363
|
-
if (typeof timestampMs !== "number" || !Number.isFinite(timestampMs) || model === void 0 || !Number.isFinite(uncached) || !Number.isFinite(cached) || !Number.isFinite(cacheCreation) || !Number.isFinite(output) || !Number.isFinite(
|
|
29737
|
+
if (typeof timestampMs !== "number" || !Number.isFinite(timestampMs) || model === void 0 || !Number.isFinite(uncached) || !Number.isFinite(cached) || !Number.isFinite(cacheCreation) || !Number.isFinite(output) || !Number.isFinite(reasoning2)) {
|
|
29364
29738
|
return null;
|
|
29365
29739
|
}
|
|
29366
29740
|
records.push({
|
|
@@ -29372,7 +29746,7 @@ function decodeScanCache(document) {
|
|
|
29372
29746
|
cachedInputTokens: cached,
|
|
29373
29747
|
cacheCreationTokens: cacheCreation,
|
|
29374
29748
|
outputTokens: output,
|
|
29375
|
-
reasoningTokens:
|
|
29749
|
+
reasoningTokens: reasoning2
|
|
29376
29750
|
},
|
|
29377
29751
|
reportedCostUsd: typeof reportedCostUsd === "number" ? reportedCostUsd : null,
|
|
29378
29752
|
dedupeKey: typeof dedupeKey === "string" ? dedupeKey : null
|
|
@@ -29402,12 +29776,12 @@ function decodeScanCache(document) {
|
|
|
29402
29776
|
}
|
|
29403
29777
|
function dedupeWithinFile(records, seen = /* @__PURE__ */ new Set()) {
|
|
29404
29778
|
const kept = [];
|
|
29405
|
-
for (const
|
|
29406
|
-
if (
|
|
29407
|
-
if (seen.has(
|
|
29408
|
-
seen.add(
|
|
29779
|
+
for (const record3 of records) {
|
|
29780
|
+
if (record3.dedupeKey !== null) {
|
|
29781
|
+
if (seen.has(record3.dedupeKey)) continue;
|
|
29782
|
+
seen.add(record3.dedupeKey);
|
|
29409
29783
|
}
|
|
29410
|
-
kept.push(
|
|
29784
|
+
kept.push(record3);
|
|
29411
29785
|
}
|
|
29412
29786
|
return kept;
|
|
29413
29787
|
}
|
|
@@ -29433,26 +29807,26 @@ var parseClaudeLine = (line) => {
|
|
|
29433
29807
|
return null;
|
|
29434
29808
|
}
|
|
29435
29809
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
29436
|
-
const
|
|
29437
|
-
if (
|
|
29438
|
-
const message =
|
|
29810
|
+
const record3 = parsed;
|
|
29811
|
+
if (record3["type"] !== "assistant") return null;
|
|
29812
|
+
const message = record3["message"];
|
|
29439
29813
|
if (typeof message !== "object" || message === null) return null;
|
|
29440
29814
|
const messageRecord = message;
|
|
29441
29815
|
const usage = messageRecord["usage"];
|
|
29442
29816
|
if (typeof usage !== "object" || usage === null) return null;
|
|
29443
29817
|
const usageRecord = usage;
|
|
29444
|
-
const timestampMs = parseTimestampMs(
|
|
29818
|
+
const timestampMs = parseTimestampMs(record3["timestamp"]);
|
|
29445
29819
|
if (timestampMs === null) return null;
|
|
29446
29820
|
const model = typeof messageRecord["model"] === "string" ? messageRecord["model"] : "";
|
|
29447
29821
|
if (model.length === 0) return null;
|
|
29448
29822
|
const messageId = typeof messageRecord["id"] === "string" ? messageRecord["id"] : null;
|
|
29449
|
-
const requestId = typeof
|
|
29823
|
+
const requestId = typeof record3["requestId"] === "string" ? record3["requestId"] : null;
|
|
29450
29824
|
const dedupeKey = messageId === null && requestId === null ? null : `${messageId ?? ""}:${requestId ?? ""}`;
|
|
29451
|
-
const cost =
|
|
29825
|
+
const cost = record3["costUSD"];
|
|
29452
29826
|
return {
|
|
29453
29827
|
timestampMs,
|
|
29454
29828
|
model,
|
|
29455
|
-
sessionId: typeof
|
|
29829
|
+
sessionId: typeof record3["sessionId"] === "string" ? record3["sessionId"] : "",
|
|
29456
29830
|
totals: {
|
|
29457
29831
|
uncachedInputTokens: tokenCount(usageRecord["input_tokens"]),
|
|
29458
29832
|
cachedInputTokens: tokenCount(usageRecord["cache_read_input_tokens"]),
|
|
@@ -29571,18 +29945,18 @@ var createClaudeTokenReader = (options) => {
|
|
|
29571
29945
|
continue;
|
|
29572
29946
|
}
|
|
29573
29947
|
scannedFiles += 1;
|
|
29574
|
-
for (const
|
|
29575
|
-
if (
|
|
29576
|
-
if (seen.has(
|
|
29577
|
-
seen.add(
|
|
29948
|
+
for (const record3 of fileRecords) {
|
|
29949
|
+
if (record3.dedupeKey !== null) {
|
|
29950
|
+
if (seen.has(record3.dedupeKey)) continue;
|
|
29951
|
+
seen.add(record3.dedupeKey);
|
|
29578
29952
|
}
|
|
29579
|
-
if (
|
|
29953
|
+
if (record3.timestampMs < sinceMs || record3.timestampMs >= untilMs) continue;
|
|
29580
29954
|
records.push({
|
|
29581
|
-
at: new Date(
|
|
29582
|
-
model:
|
|
29583
|
-
...
|
|
29584
|
-
totals:
|
|
29585
|
-
...
|
|
29955
|
+
at: new Date(record3.timestampMs).toISOString(),
|
|
29956
|
+
model: record3.model,
|
|
29957
|
+
...record3.sessionId.length > 0 ? { sessionId: record3.sessionId } : {},
|
|
29958
|
+
totals: record3.totals,
|
|
29959
|
+
...record3.reportedCostUsd === null ? {} : { reportedCostUsd: record3.reportedCostUsd }
|
|
29586
29960
|
});
|
|
29587
29961
|
}
|
|
29588
29962
|
}
|
|
@@ -29939,6 +30313,8 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
29939
30313
|
modelCatalog: adapter.modelCatalog,
|
|
29940
30314
|
launchEnvironment: adapter.buildLaunchEnvironment
|
|
29941
30315
|
});
|
|
30316
|
+
const readImport = createClaudeImportReader();
|
|
30317
|
+
const scanCache = /* @__PURE__ */ new Map();
|
|
29942
30318
|
const resolveTranscriptRoots = (directory) => {
|
|
29943
30319
|
const configDir = resolveClaudeConfigDirPath(
|
|
29944
30320
|
recipe.homePath,
|
|
@@ -29998,6 +30374,7 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
29998
30374
|
continuationKey: claudeContinuationKey(recipe.homePath),
|
|
29999
30375
|
usage: createClaudeUsage({ recipe, host, cache: usageCache }),
|
|
30000
30376
|
sessions: {
|
|
30377
|
+
readImport: (input) => readImport({ ...input, transcriptDir: resolveTranscriptRoots(input.cwd).transcriptDir }),
|
|
30001
30378
|
openHistory: async (input) => openClaudeHistory({
|
|
30002
30379
|
...input,
|
|
30003
30380
|
transcriptDir: resolveTranscriptRoots(input.cwd).transcriptDir
|
|
@@ -30005,11 +30382,15 @@ function createClaudeInstance(config, host, attachments, overrides, usageCache)
|
|
|
30005
30382
|
scan: async (input) => {
|
|
30006
30383
|
const roots = resolveTranscriptRoots(input.directory);
|
|
30007
30384
|
return {
|
|
30008
|
-
candidates: await scanClaudeSessions(
|
|
30009
|
-
|
|
30010
|
-
|
|
30011
|
-
|
|
30012
|
-
|
|
30385
|
+
candidates: await scanClaudeSessions(
|
|
30386
|
+
{
|
|
30387
|
+
transcriptDir: roots.transcriptDir,
|
|
30388
|
+
configDir: roots.configDir,
|
|
30389
|
+
directory: input.directory ?? "",
|
|
30390
|
+
signal: input.signal
|
|
30391
|
+
},
|
|
30392
|
+
scanCache
|
|
30393
|
+
)
|
|
30013
30394
|
};
|
|
30014
30395
|
},
|
|
30015
30396
|
read: async (input) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-claude",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5542",
|
|
4
4
|
"description": "Claude executor: Claude Code CLI via @anthropic-ai/claude-agent-sdk.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -24,16 +24,16 @@
|
|
|
24
24
|
"@types/node": "24.12.4",
|
|
25
25
|
"esbuild": "0.28.1",
|
|
26
26
|
"vite-plus": "0.2.2",
|
|
27
|
-
"@ycodium-ai/plugin-api": "0.2.5448",
|
|
28
27
|
"ycodium-composer-tokens": "0.0.0",
|
|
28
|
+
"@ycodium-ai/plugin-api": "0.2.5542",
|
|
29
29
|
"ycodium-credential-account": "0.0.0",
|
|
30
|
-
"ycodium-executor-testing": "0.0.0",
|
|
31
|
-
"ycodium-instance-config": "0.0.0",
|
|
32
30
|
"ycodium-duration-format": "0.0.0",
|
|
31
|
+
"ycodium-instance-config": "0.0.0",
|
|
33
32
|
"ycodium-jsonl-stream": "0.0.0",
|
|
34
|
-
"ycodium-workspace-path": "0.0.0",
|
|
35
33
|
"ycodium-text-generation": "0.0.0",
|
|
36
|
-
"ycodium-
|
|
34
|
+
"ycodium-executor-testing": "0.0.0",
|
|
35
|
+
"ycodium-tool-label": "0.0.0",
|
|
36
|
+
"ycodium-workspace-path": "0.0.0"
|
|
37
37
|
},
|
|
38
38
|
"ycodium": {
|
|
39
39
|
"plugin": "./dist/index.js",
|