@gkorepanov/ccodex 0.4.18 → 0.4.19

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.
@@ -1,7 +1,7 @@
1
1
  import { v7 as uuidv7 } from "uuid";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { MetricsRegistry } from "../../observability/metrics.js";
4
- import { invalidParams } from "../../protocol/errors.js";
4
+ import { invalidParams, RpcError } from "../../protocol/errors.js";
5
5
  import { classifyClaudeResult, classifyClaudeRuntimeError, } from "../resultClassifier.js";
6
6
  import { runtimeWorkspaceRoots, settingsGeneration, withSettingsFrom } from "../../store/HybridStore.js";
7
7
  import { addUsage } from "./usage.js";
@@ -109,6 +109,13 @@ function commandLane(command) {
109
109
  return "provider";
110
110
  return "normal";
111
111
  }
112
+ export class ActiveClaudeTurnError extends RpcError {
113
+ turnId;
114
+ constructor(threadId, turnId) {
115
+ super(-32602, `Thread '${threadId}' already has an active turn.`);
116
+ this.turnId = turnId;
117
+ }
118
+ }
112
119
  export class ClaudeSession {
113
120
  threadId;
114
121
  repository;
@@ -775,6 +782,8 @@ export class ClaudeSession {
775
782
  messageUuid,
776
783
  });
777
784
  if (staged.kind === "busy") {
785
+ if (staged.activeTurnId)
786
+ throw new ActiveClaudeTurnError(this.threadId, staged.activeTurnId);
778
787
  throw invalidParams(`Thread '${this.threadId}' already has an active turn.`);
779
788
  }
780
789
  if (staged.kind === "stale") {
@@ -4079,7 +4088,10 @@ export class ClaudeSession {
4079
4088
  return { kind: "staged" };
4080
4089
  }
4081
4090
  if (this.stagedRuntimeTurns.size)
4082
- return { kind: "busy" };
4091
+ return {
4092
+ kind: "busy",
4093
+ activeTurnId: this.scopes.get(this.threadId)?.turnId ?? null,
4094
+ };
4083
4095
  }
4084
4096
  if (command.runtimeGeneration !== this.runtimeGeneration
4085
4097
  || command.settingsGeneration !== settingsGeneration(record)) {
@@ -4103,7 +4115,10 @@ export class ClaudeSession {
4103
4115
  }
4104
4116
  if (this.interruptFence || this.transportStopFence
4105
4117
  || this.lifecycle || this.compaction || record.thread.status.type === "active") {
4106
- return { kind: "busy" };
4118
+ return {
4119
+ kind: "busy",
4120
+ activeTurnId: this.scopes.get(this.threadId)?.turnId ?? null,
4121
+ };
4107
4122
  }
4108
4123
  this.stagedRuntimeTurns.add(command.messageUuid);
4109
4124
  this.emitLifecycle();