@ycodium-ai/agent-claude 0.2.4343 → 0.2.4368
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 +94 -18
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as NodePath20 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 = 112;
|
|
7
7
|
|
|
8
8
|
// src/index.ts
|
|
9
9
|
import {
|
|
@@ -23494,7 +23494,8 @@ var claudeFailureCategory = (signals) => {
|
|
|
23494
23494
|
if (signals.assistantError === "rate_limit" || status === 429) {
|
|
23495
23495
|
return signals.quotaWindowRejected === true ? "quota" : "rate-limit";
|
|
23496
23496
|
}
|
|
23497
|
-
if (status === 524
|
|
23497
|
+
if (status === 524) return "transport";
|
|
23498
|
+
if (signals.establishedStreamExit === true) return "process-exit";
|
|
23498
23499
|
return void 0;
|
|
23499
23500
|
};
|
|
23500
23501
|
var failureCategoryField = (category) => category === void 0 ? {} : { failureCategory: category };
|
|
@@ -23812,7 +23813,7 @@ var makeEmitters = (emitter) => {
|
|
|
23812
23813
|
providerRefs: nativeProviderRefs()
|
|
23813
23814
|
});
|
|
23814
23815
|
};
|
|
23815
|
-
const emitRuntimeWarning = async (context, message, detail) => {
|
|
23816
|
+
const emitRuntimeWarning = async (context, message, detail, code) => {
|
|
23816
23817
|
const turnState = context.turnState;
|
|
23817
23818
|
const stamp = await makeEventStamp();
|
|
23818
23819
|
offerRuntimeEvent(context, {
|
|
@@ -23821,7 +23822,8 @@ var makeEmitters = (emitter) => {
|
|
|
23821
23822
|
...turnState ? { turnId: asCanonicalTurnId(turnState.turnId) } : {},
|
|
23822
23823
|
payload: {
|
|
23823
23824
|
message,
|
|
23824
|
-
...detail !== void 0 ? { detail } : {}
|
|
23825
|
+
...detail !== void 0 ? { detail } : {},
|
|
23826
|
+
...code !== void 0 ? { code } : {}
|
|
23825
23827
|
},
|
|
23826
23828
|
providerRefs: nativeProviderRefs()
|
|
23827
23829
|
});
|
|
@@ -24526,6 +24528,16 @@ var makeClaudeModelCatalog = (deps) => {
|
|
|
24526
24528
|
};
|
|
24527
24529
|
};
|
|
24528
24530
|
|
|
24531
|
+
// src/streamExitMessage.ts
|
|
24532
|
+
import { lastStderrLines, redactStderrExcerpt } from "@ycodium-ai/plugin-api/process-stdin";
|
|
24533
|
+
var STREAM_EXIT_STDERR_MAX_CHARS = 800;
|
|
24534
|
+
function claudeStreamExitMessage(reason, stderrTail) {
|
|
24535
|
+
const excerpt = lastStderrLines(redactStderrExcerpt(stderrTail), STREAM_EXIT_STDERR_MAX_CHARS);
|
|
24536
|
+
return excerpt.length === 0 ? reason : `${reason}
|
|
24537
|
+
Claude stderr (last lines):
|
|
24538
|
+
${excerpt}`;
|
|
24539
|
+
}
|
|
24540
|
+
|
|
24529
24541
|
// src/adapter/sdkStream.ts
|
|
24530
24542
|
var makeSdkStream = (deps) => {
|
|
24531
24543
|
const {
|
|
@@ -24539,7 +24551,8 @@ var makeSdkStream = (deps) => {
|
|
|
24539
24551
|
handleAssistantMessage,
|
|
24540
24552
|
handleResultMessage,
|
|
24541
24553
|
handleSystemMessage,
|
|
24542
|
-
handleSdkTelemetryMessage
|
|
24554
|
+
handleSdkTelemetryMessage,
|
|
24555
|
+
unresumableSessions
|
|
24543
24556
|
} = deps;
|
|
24544
24557
|
const handleSdkMessage = async (context, message) => {
|
|
24545
24558
|
await ensureThreadId(context, message);
|
|
@@ -24617,19 +24630,23 @@ var makeSdkStream = (deps) => {
|
|
|
24617
24630
|
if (context.stopped) {
|
|
24618
24631
|
return;
|
|
24619
24632
|
}
|
|
24633
|
+
unresumableSessions.noteStreamExit(context);
|
|
24620
24634
|
if (cause != null) {
|
|
24621
24635
|
if (isClaudeInterruptedCause(cause)) {
|
|
24622
24636
|
if (context.turnState) {
|
|
24623
24637
|
await completeTurn(context, "interrupted", "Claude runtime interrupted.");
|
|
24624
24638
|
}
|
|
24625
24639
|
} else {
|
|
24626
|
-
const cliSaid = context.stderrTail.read();
|
|
24627
24640
|
const reason = cause instanceof Error ? cause.message : "Claude runtime stream failed.";
|
|
24628
|
-
const
|
|
24641
|
+
const stderrTail = context.stderrTail.read();
|
|
24642
|
+
unresumableSessions.noteStderr(context, stderrTail);
|
|
24643
|
+
const message = claudeStreamExitMessage(reason, stderrTail);
|
|
24629
24644
|
const category = claudeFailureCategory({
|
|
24630
24645
|
establishedStreamExit: streamBroke && context.sessionEstablished
|
|
24631
24646
|
});
|
|
24632
|
-
|
|
24647
|
+
if (!context.turnState) {
|
|
24648
|
+
await emitRuntimeError(context, message, { cause: String(cause) }, category);
|
|
24649
|
+
}
|
|
24633
24650
|
await completeTurn(context, "failed", message, void 0, category);
|
|
24634
24651
|
}
|
|
24635
24652
|
} else if (context.turnState) {
|
|
@@ -26178,7 +26195,9 @@ var makeStartSession = (deps) => {
|
|
|
26178
26195
|
stopSessionInternal,
|
|
26179
26196
|
withProcessGeneration,
|
|
26180
26197
|
sessionCallbacks,
|
|
26181
|
-
runSdkStream
|
|
26198
|
+
runSdkStream,
|
|
26199
|
+
unresumableSessions,
|
|
26200
|
+
emitRuntimeWarning
|
|
26182
26201
|
} = deps;
|
|
26183
26202
|
const claudeSdkExecutablePath = deps.executablePath;
|
|
26184
26203
|
const currentModelCatalog = modelCatalog.current;
|
|
@@ -26257,11 +26276,14 @@ var makeStartSession = (deps) => {
|
|
|
26257
26276
|
await stopSessionInternal(existingContext);
|
|
26258
26277
|
}
|
|
26259
26278
|
const startedAt = nowIso();
|
|
26260
|
-
const
|
|
26279
|
+
const persistedResumeState = input.discardResumeCursor === true ? void 0 : readClaudeResumeState(input.resumeCursor);
|
|
26280
|
+
const persistedResumeId = persistedResumeState?.resume;
|
|
26281
|
+
const unresumable = persistedResumeId === void 0 ? void 0 : unresumableSessions.reasonFor(persistedResumeId);
|
|
26282
|
+
const resumeState = unresumable === void 0 ? persistedResumeState : void 0;
|
|
26261
26283
|
const threadId = input.threadId;
|
|
26262
26284
|
const existingResumeSessionId = resumeState?.resume;
|
|
26263
|
-
const
|
|
26264
|
-
const
|
|
26285
|
+
const sessionId = existingResumeSessionId ?? randomUUIDv4();
|
|
26286
|
+
const newSessionId = existingResumeSessionId === void 0 ? sessionId : void 0;
|
|
26265
26287
|
const promptQueue = new PromptQueue();
|
|
26266
26288
|
const pendingApprovals = /* @__PURE__ */ new Map();
|
|
26267
26289
|
const pendingUserInputs = /* @__PURE__ */ new Map();
|
|
@@ -26406,7 +26428,7 @@ var makeStartSession = (deps) => {
|
|
|
26406
26428
|
...modelSelection?.model ? { model: modelSelection.model } : {},
|
|
26407
26429
|
resumeCursor: {
|
|
26408
26430
|
threadId,
|
|
26409
|
-
|
|
26431
|
+
resume: sessionId,
|
|
26410
26432
|
...resumeState?.resumeSessionAt ? { resumeSessionAt: resumeState.resumeSessionAt } : {},
|
|
26411
26433
|
turnCount: resumeState?.turnCount ?? 0
|
|
26412
26434
|
},
|
|
@@ -26417,7 +26439,11 @@ var makeStartSession = (deps) => {
|
|
|
26417
26439
|
session,
|
|
26418
26440
|
events: input.events,
|
|
26419
26441
|
bindingGeneration: input.bindingGeneration,
|
|
26420
|
-
|
|
26442
|
+
// 来源身份是这个进程真正接着的游标:作废了交来的旧号,就是交回宿主的新游标,否则交互答复会被当成过期请求。
|
|
26443
|
+
origin: input.resumeCursor === void 0 ? {} : {
|
|
26444
|
+
originResumeCursor: unresumable === void 0 ? input.resumeCursor : session.resumeCursor
|
|
26445
|
+
},
|
|
26446
|
+
launch: { sessionId, resumed: existingResumeSessionId !== void 0 },
|
|
26421
26447
|
promptQueue,
|
|
26422
26448
|
query: queryRuntime,
|
|
26423
26449
|
cliProcess,
|
|
@@ -26460,6 +26486,7 @@ var makeStartSession = (deps) => {
|
|
|
26460
26486
|
stopping: false,
|
|
26461
26487
|
stopped: false,
|
|
26462
26488
|
sessionEstablished: false,
|
|
26489
|
+
launchConfirmed: false,
|
|
26463
26490
|
stopWork: void 0
|
|
26464
26491
|
};
|
|
26465
26492
|
contextDeferred.resolve(context);
|
|
@@ -26492,6 +26519,14 @@ var makeStartSession = (deps) => {
|
|
|
26492
26519
|
},
|
|
26493
26520
|
providerRefs: {}
|
|
26494
26521
|
});
|
|
26522
|
+
if (unresumable === "missing") {
|
|
26523
|
+
await emitRuntimeWarning(
|
|
26524
|
+
context,
|
|
26525
|
+
`Claude Code has no record of this thread's earlier conversation (session ${String(persistedResumeId)}), so the thread continues in a new Claude Code session. The messages here are kept, but the agent no longer has their context.`,
|
|
26526
|
+
void 0,
|
|
26527
|
+
"resume-thread-reset"
|
|
26528
|
+
);
|
|
26529
|
+
}
|
|
26495
26530
|
const readyStamp = await makeEventStamp();
|
|
26496
26531
|
offerRuntimeEvent(context, {
|
|
26497
26532
|
type: "session.state.changed",
|
|
@@ -26512,11 +26547,43 @@ var makeStartSession = (deps) => {
|
|
|
26512
26547
|
cause: cause instanceof Error ? cause.message : String(cause)
|
|
26513
26548
|
});
|
|
26514
26549
|
});
|
|
26550
|
+
if (unresumable !== void 0 && persistedResumeId !== void 0)
|
|
26551
|
+
unresumableSessions.forget(persistedResumeId);
|
|
26515
26552
|
return withProcessGeneration(session, context);
|
|
26516
26553
|
};
|
|
26517
26554
|
return { startSession };
|
|
26518
26555
|
};
|
|
26519
26556
|
|
|
26557
|
+
// src/unresumableSessions.ts
|
|
26558
|
+
var missingConversationLine = (sessionId) => `No conversation found with session ID: ${sessionId}`.toLowerCase();
|
|
26559
|
+
var createUnresumableSessions = () => {
|
|
26560
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
26561
|
+
const noteDiagnostics = (context, diagnostics) => {
|
|
26562
|
+
const { launch } = context;
|
|
26563
|
+
if (!launch.resumed || context.launchConfirmed) return;
|
|
26564
|
+
const expected = missingConversationLine(launch.sessionId);
|
|
26565
|
+
if (diagnostics.some((line) => line.trim().toLowerCase() === expected))
|
|
26566
|
+
reasons.set(launch.sessionId, "missing");
|
|
26567
|
+
};
|
|
26568
|
+
return {
|
|
26569
|
+
/** 失败结果里 CLI 列出的错误项,逐项整条比。 */
|
|
26570
|
+
noteResultErrors: noteDiagnostics,
|
|
26571
|
+
/** CLI 写给 stderr 的尾巴,逐行整行比。 */
|
|
26572
|
+
noteStderr: (context, stderr) => noteDiagnostics(context, stderr.split(/\r?\n/u)),
|
|
26573
|
+
/** 进程自己退了(不是宿主停的):新会话还没建立就退,预先定的号作废。 */
|
|
26574
|
+
noteStreamExit: (context) => {
|
|
26575
|
+
if (!context.launch.resumed && !context.sessionEstablished)
|
|
26576
|
+
reasons.set(context.launch.sessionId, "never-started");
|
|
26577
|
+
},
|
|
26578
|
+
/** 起会话时查:查到就别再续接这个号。只读,不删。 */
|
|
26579
|
+
reasonFor: (sessionId) => reasons.get(sessionId),
|
|
26580
|
+
/** 换上的新会话已经建好、新游标就要交回宿主时才删:起会话中途失败,下次还要接着避开这个号。 */
|
|
26581
|
+
forget: (sessionId) => {
|
|
26582
|
+
reasons.delete(sessionId);
|
|
26583
|
+
}
|
|
26584
|
+
};
|
|
26585
|
+
};
|
|
26586
|
+
|
|
26520
26587
|
// src/adapter/streamEvents.ts
|
|
26521
26588
|
var makeStreamEventHandler = (deps) => {
|
|
26522
26589
|
const { emitter, emitThreadTokenUsage, ensureAssistantTextBlock, completeAssistantTextBlock } = deps;
|
|
@@ -27672,7 +27739,8 @@ var makeTurnMessageHandlers = (deps) => {
|
|
|
27672
27739
|
updateResumeCursor,
|
|
27673
27740
|
ensureSyntheticTurn,
|
|
27674
27741
|
completeTurn,
|
|
27675
|
-
backfillAssistantTextBlocksFromSnapshot
|
|
27742
|
+
backfillAssistantTextBlocksFromSnapshot,
|
|
27743
|
+
unresumableSessions
|
|
27676
27744
|
} = deps;
|
|
27677
27745
|
const { makeEventStamp, eventHeader, offerRuntimeEvent } = emitter;
|
|
27678
27746
|
const emitReportedModel = makeReportedModelEmitter(emitter);
|
|
@@ -27922,7 +27990,10 @@ var makeTurnMessageHandlers = (deps) => {
|
|
|
27922
27990
|
quotaWindowRejected: (turn?.rejectedRateLimits.size ?? 0) > 0,
|
|
27923
27991
|
structuredErrorType: claudeStructuredErrorType(message)
|
|
27924
27992
|
}) : void 0;
|
|
27993
|
+
if (status === "completed") context.launchConfirmed = true;
|
|
27925
27994
|
if (status === "failed") {
|
|
27995
|
+
if ("errors" in message && Array.isArray(message.errors))
|
|
27996
|
+
unresumableSessions.noteResultErrors(context, message.errors);
|
|
27926
27997
|
await emitRuntimeError(context, errorMessage ?? "Claude turn failed.", void 0, category);
|
|
27927
27998
|
}
|
|
27928
27999
|
await completeTurn(context, status, errorMessage, message, category);
|
|
@@ -29285,6 +29356,7 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
29285
29356
|
completeAssistantTextBlock,
|
|
29286
29357
|
backfillAssistantTextBlocksFromSnapshot
|
|
29287
29358
|
} = makeAssistantText(emitter);
|
|
29359
|
+
const unresumableSessions = createUnresumableSessions();
|
|
29288
29360
|
const { ensureSyntheticTurn, completeTurn } = makeTurnLifecycle({
|
|
29289
29361
|
emitter,
|
|
29290
29362
|
log: options?.log ?? host.log,
|
|
@@ -29309,7 +29381,8 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
29309
29381
|
updateResumeCursor,
|
|
29310
29382
|
ensureSyntheticTurn,
|
|
29311
29383
|
completeTurn,
|
|
29312
|
-
backfillAssistantTextBlocksFromSnapshot
|
|
29384
|
+
backfillAssistantTextBlocksFromSnapshot,
|
|
29385
|
+
unresumableSessions
|
|
29313
29386
|
});
|
|
29314
29387
|
const { handleSystemMessage } = makeSystemMessageHandler({
|
|
29315
29388
|
emitter,
|
|
@@ -29340,7 +29413,8 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
29340
29413
|
handleAssistantMessage,
|
|
29341
29414
|
handleResultMessage,
|
|
29342
29415
|
handleSystemMessage,
|
|
29343
|
-
handleSdkTelemetryMessage
|
|
29416
|
+
handleSdkTelemetryMessage,
|
|
29417
|
+
unresumableSessions
|
|
29344
29418
|
});
|
|
29345
29419
|
const sessionCallbacks = makeSessionCallbacks({
|
|
29346
29420
|
emitter,
|
|
@@ -29363,7 +29437,9 @@ function createClaudeAdapter(recipe, host, options) {
|
|
|
29363
29437
|
stopSessionInternal,
|
|
29364
29438
|
withProcessGeneration,
|
|
29365
29439
|
sessionCallbacks,
|
|
29366
|
-
runSdkStream
|
|
29440
|
+
runSdkStream,
|
|
29441
|
+
unresumableSessions,
|
|
29442
|
+
emitRuntimeWarning
|
|
29367
29443
|
});
|
|
29368
29444
|
const {
|
|
29369
29445
|
compactContext,
|
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.4368",
|
|
4
4
|
"description": "Claude executor: Claude Code CLI via @anthropic-ai/claude-agent-sdk.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -24,9 +24,9 @@
|
|
|
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.
|
|
28
|
-
"ycodium-executor-testing": "0.0.0",
|
|
27
|
+
"@ycodium-ai/plugin-api": "0.2.4368",
|
|
29
28
|
"ycodium-composer-tokens": "0.0.0",
|
|
29
|
+
"ycodium-executor-testing": "0.0.0",
|
|
30
30
|
"ycodium-jsonl-stream": "0.0.0"
|
|
31
31
|
},
|
|
32
32
|
"ycodium": {
|