@ycodium-ai/agent-claude 0.2.4351 → 0.2.4372

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -15
  2. package/package.json +4 -4
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 = 110;
6
+ var PLUGIN_API_VERSION = 112;
7
7
 
8
8
  // src/index.ts
9
9
  import {
@@ -23813,7 +23813,7 @@ var makeEmitters = (emitter) => {
23813
23813
  providerRefs: nativeProviderRefs()
23814
23814
  });
23815
23815
  };
23816
- const emitRuntimeWarning = async (context, message, detail) => {
23816
+ const emitRuntimeWarning = async (context, message, detail, code) => {
23817
23817
  const turnState = context.turnState;
23818
23818
  const stamp = await makeEventStamp();
23819
23819
  offerRuntimeEvent(context, {
@@ -23822,7 +23822,8 @@ var makeEmitters = (emitter) => {
23822
23822
  ...turnState ? { turnId: asCanonicalTurnId(turnState.turnId) } : {},
23823
23823
  payload: {
23824
23824
  message,
23825
- ...detail !== void 0 ? { detail } : {}
23825
+ ...detail !== void 0 ? { detail } : {},
23826
+ ...code !== void 0 ? { code } : {}
23826
23827
  },
23827
23828
  providerRefs: nativeProviderRefs()
23828
23829
  });
@@ -24550,7 +24551,8 @@ var makeSdkStream = (deps) => {
24550
24551
  handleAssistantMessage,
24551
24552
  handleResultMessage,
24552
24553
  handleSystemMessage,
24553
- handleSdkTelemetryMessage
24554
+ handleSdkTelemetryMessage,
24555
+ unresumableSessions
24554
24556
  } = deps;
24555
24557
  const handleSdkMessage = async (context, message) => {
24556
24558
  await ensureThreadId(context, message);
@@ -24628,6 +24630,7 @@ var makeSdkStream = (deps) => {
24628
24630
  if (context.stopped) {
24629
24631
  return;
24630
24632
  }
24633
+ unresumableSessions.noteStreamExit(context);
24631
24634
  if (cause != null) {
24632
24635
  if (isClaudeInterruptedCause(cause)) {
24633
24636
  if (context.turnState) {
@@ -24635,7 +24638,9 @@ var makeSdkStream = (deps) => {
24635
24638
  }
24636
24639
  } else {
24637
24640
  const reason = cause instanceof Error ? cause.message : "Claude runtime stream failed.";
24638
- const message = claudeStreamExitMessage(reason, context.stderrTail.read());
24641
+ const stderrTail = context.stderrTail.read();
24642
+ unresumableSessions.noteStderr(context, stderrTail);
24643
+ const message = claudeStreamExitMessage(reason, stderrTail);
24639
24644
  const category = claudeFailureCategory({
24640
24645
  establishedStreamExit: streamBroke && context.sessionEstablished
24641
24646
  });
@@ -26190,7 +26195,9 @@ var makeStartSession = (deps) => {
26190
26195
  stopSessionInternal,
26191
26196
  withProcessGeneration,
26192
26197
  sessionCallbacks,
26193
- runSdkStream
26198
+ runSdkStream,
26199
+ unresumableSessions,
26200
+ emitRuntimeWarning
26194
26201
  } = deps;
26195
26202
  const claudeSdkExecutablePath = deps.executablePath;
26196
26203
  const currentModelCatalog = modelCatalog.current;
@@ -26269,11 +26276,14 @@ var makeStartSession = (deps) => {
26269
26276
  await stopSessionInternal(existingContext);
26270
26277
  }
26271
26278
  const startedAt = nowIso();
26272
- const resumeState = input.discardResumeCursor === true ? void 0 : readClaudeResumeState(input.resumeCursor);
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;
26273
26283
  const threadId = input.threadId;
26274
26284
  const existingResumeSessionId = resumeState?.resume;
26275
- const newSessionId = existingResumeSessionId === void 0 ? randomUUIDv4() : void 0;
26276
- const sessionId = existingResumeSessionId ?? newSessionId;
26285
+ const sessionId = existingResumeSessionId ?? randomUUIDv4();
26286
+ const newSessionId = existingResumeSessionId === void 0 ? sessionId : void 0;
26277
26287
  const promptQueue = new PromptQueue();
26278
26288
  const pendingApprovals = /* @__PURE__ */ new Map();
26279
26289
  const pendingUserInputs = /* @__PURE__ */ new Map();
@@ -26418,7 +26428,7 @@ var makeStartSession = (deps) => {
26418
26428
  ...modelSelection?.model ? { model: modelSelection.model } : {},
26419
26429
  resumeCursor: {
26420
26430
  threadId,
26421
- ...sessionId ? { resume: sessionId } : {},
26431
+ resume: sessionId,
26422
26432
  ...resumeState?.resumeSessionAt ? { resumeSessionAt: resumeState.resumeSessionAt } : {},
26423
26433
  turnCount: resumeState?.turnCount ?? 0
26424
26434
  },
@@ -26429,7 +26439,11 @@ var makeStartSession = (deps) => {
26429
26439
  session,
26430
26440
  events: input.events,
26431
26441
  bindingGeneration: input.bindingGeneration,
26432
- origin: input.resumeCursor === void 0 ? {} : { originResumeCursor: input.resumeCursor },
26442
+ // 来源身份是这个进程真正接着的游标:作废了交来的旧号,就是交回宿主的新游标,否则交互答复会被当成过期请求。
26443
+ origin: input.resumeCursor === void 0 ? {} : {
26444
+ originResumeCursor: unresumable === void 0 ? input.resumeCursor : session.resumeCursor
26445
+ },
26446
+ launch: { sessionId, resumed: existingResumeSessionId !== void 0 },
26433
26447
  promptQueue,
26434
26448
  query: queryRuntime,
26435
26449
  cliProcess,
@@ -26472,6 +26486,7 @@ var makeStartSession = (deps) => {
26472
26486
  stopping: false,
26473
26487
  stopped: false,
26474
26488
  sessionEstablished: false,
26489
+ launchConfirmed: false,
26475
26490
  stopWork: void 0
26476
26491
  };
26477
26492
  contextDeferred.resolve(context);
@@ -26504,6 +26519,14 @@ var makeStartSession = (deps) => {
26504
26519
  },
26505
26520
  providerRefs: {}
26506
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
+ }
26507
26530
  const readyStamp = await makeEventStamp();
26508
26531
  offerRuntimeEvent(context, {
26509
26532
  type: "session.state.changed",
@@ -26524,11 +26547,43 @@ var makeStartSession = (deps) => {
26524
26547
  cause: cause instanceof Error ? cause.message : String(cause)
26525
26548
  });
26526
26549
  });
26550
+ if (unresumable !== void 0 && persistedResumeId !== void 0)
26551
+ unresumableSessions.forget(persistedResumeId);
26527
26552
  return withProcessGeneration(session, context);
26528
26553
  };
26529
26554
  return { startSession };
26530
26555
  };
26531
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
+
26532
26587
  // src/adapter/streamEvents.ts
26533
26588
  var makeStreamEventHandler = (deps) => {
26534
26589
  const { emitter, emitThreadTokenUsage, ensureAssistantTextBlock, completeAssistantTextBlock } = deps;
@@ -27684,7 +27739,8 @@ var makeTurnMessageHandlers = (deps) => {
27684
27739
  updateResumeCursor,
27685
27740
  ensureSyntheticTurn,
27686
27741
  completeTurn,
27687
- backfillAssistantTextBlocksFromSnapshot
27742
+ backfillAssistantTextBlocksFromSnapshot,
27743
+ unresumableSessions
27688
27744
  } = deps;
27689
27745
  const { makeEventStamp, eventHeader, offerRuntimeEvent } = emitter;
27690
27746
  const emitReportedModel = makeReportedModelEmitter(emitter);
@@ -27934,7 +27990,10 @@ var makeTurnMessageHandlers = (deps) => {
27934
27990
  quotaWindowRejected: (turn?.rejectedRateLimits.size ?? 0) > 0,
27935
27991
  structuredErrorType: claudeStructuredErrorType(message)
27936
27992
  }) : void 0;
27993
+ if (status === "completed") context.launchConfirmed = true;
27937
27994
  if (status === "failed") {
27995
+ if ("errors" in message && Array.isArray(message.errors))
27996
+ unresumableSessions.noteResultErrors(context, message.errors);
27938
27997
  await emitRuntimeError(context, errorMessage ?? "Claude turn failed.", void 0, category);
27939
27998
  }
27940
27999
  await completeTurn(context, status, errorMessage, message, category);
@@ -29297,6 +29356,7 @@ function createClaudeAdapter(recipe, host, options) {
29297
29356
  completeAssistantTextBlock,
29298
29357
  backfillAssistantTextBlocksFromSnapshot
29299
29358
  } = makeAssistantText(emitter);
29359
+ const unresumableSessions = createUnresumableSessions();
29300
29360
  const { ensureSyntheticTurn, completeTurn } = makeTurnLifecycle({
29301
29361
  emitter,
29302
29362
  log: options?.log ?? host.log,
@@ -29321,7 +29381,8 @@ function createClaudeAdapter(recipe, host, options) {
29321
29381
  updateResumeCursor,
29322
29382
  ensureSyntheticTurn,
29323
29383
  completeTurn,
29324
- backfillAssistantTextBlocksFromSnapshot
29384
+ backfillAssistantTextBlocksFromSnapshot,
29385
+ unresumableSessions
29325
29386
  });
29326
29387
  const { handleSystemMessage } = makeSystemMessageHandler({
29327
29388
  emitter,
@@ -29352,7 +29413,8 @@ function createClaudeAdapter(recipe, host, options) {
29352
29413
  handleAssistantMessage,
29353
29414
  handleResultMessage,
29354
29415
  handleSystemMessage,
29355
- handleSdkTelemetryMessage
29416
+ handleSdkTelemetryMessage,
29417
+ unresumableSessions
29356
29418
  });
29357
29419
  const sessionCallbacks = makeSessionCallbacks({
29358
29420
  emitter,
@@ -29375,7 +29437,9 @@ function createClaudeAdapter(recipe, host, options) {
29375
29437
  stopSessionInternal,
29376
29438
  withProcessGeneration,
29377
29439
  sessionCallbacks,
29378
- runSdkStream
29440
+ runSdkStream,
29441
+ unresumableSessions,
29442
+ emitRuntimeWarning
29379
29443
  });
29380
29444
  const {
29381
29445
  compactContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-claude",
3
- "version": "0.2.4351",
3
+ "version": "0.2.4372",
4
4
  "description": "Claude executor: Claude Code CLI via @anthropic-ai/claude-agent-sdk.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -24,10 +24,10 @@
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.4351",
28
27
  "ycodium-composer-tokens": "0.0.0",
29
- "ycodium-executor-testing": "0.0.0",
30
- "ycodium-jsonl-stream": "0.0.0"
28
+ "@ycodium-ai/plugin-api": "0.2.4372",
29
+ "ycodium-jsonl-stream": "0.0.0",
30
+ "ycodium-executor-testing": "0.0.0"
31
31
  },
32
32
  "ycodium": {
33
33
  "plugin": "./dist/index.js",