@clawos-dev/clawd 0.2.680 → 0.2.682

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/cli.cjs +27 -25
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -47952,7 +47952,6 @@ function cloneState(s2) {
47952
47952
  bufferStartSeq: s2.bufferStartSeq,
47953
47953
  turnOpen: s2.turnOpen,
47954
47954
  turnStartedAt: s2.turnStartedAt,
47955
- turnSelfWoke: s2.turnSelfWoke,
47956
47955
  pendingPermissions: s2.pendingPermissions,
47957
47956
  pendingQuestions: s2.pendingQuestions,
47958
47957
  freshSpawn: s2.freshSpawn,
@@ -47975,14 +47974,6 @@ function idleKillDelayOf(state) {
47975
47974
  const ms = state.subSessionMeta?.idleKillDelayMs;
47976
47975
  return ms !== void 0 && ms > 0 ? ms : void 0;
47977
47976
  }
47978
- var STALE_TURN_END_TOLERANCE_MS = 2e3;
47979
- function isLateTurnEnd(event, turnStartedAt, now) {
47980
- if (event.kind !== "turn_end") return false;
47981
- const durationMs = event.durationMs;
47982
- if (typeof durationMs !== "number" || typeof turnStartedAt !== "number") return false;
47983
- const elapsed = now - turnStartedAt;
47984
- return durationMs > elapsed + STALE_TURN_END_TOLERANCE_MS;
47985
- }
47986
47977
  function tryFlushPending(state, deps) {
47987
47978
  if (!state.readyForSend || state.pendingSend.length === 0) return [];
47988
47979
  const text = state.pendingSend.shift();
@@ -48350,9 +48341,6 @@ function pushEventToBufferInPlace(next, event, deps) {
48350
48341
  next.pendingBgTasks = [...pending, bg.agentId];
48351
48342
  }
48352
48343
  }
48353
- if (isTurnEnd && next.turnOpen && !next.turnSelfWoke && isLateTurnEnd(withSeq, next.turnStartedAt, deps.now())) {
48354
- return [emitSessionEvent(next.file.sessionId, withSeq)];
48355
- }
48356
48344
  if (isTurnEnd) {
48357
48345
  const te2 = withSeq;
48358
48346
  if (te2.durationMs === void 0 && typeof next.turnStartedAt === "number") {
@@ -48363,7 +48351,6 @@ function pushEventToBufferInPlace(next, event, deps) {
48363
48351
  } else if (!isBackgroundEvent && !isSessionInit && !next.turnOpen) {
48364
48352
  next.turnOpen = true;
48365
48353
  next.turnStartedAt = deps.now();
48366
- next.turnSelfWoke = next.status === "running-idle";
48367
48354
  }
48368
48355
  if (!next.turnOpen && next.buffer.length > deps.bufferCap) {
48369
48356
  const remove = next.buffer.length - deps.bufferCap;
@@ -48431,7 +48418,7 @@ function pushEventToBufferInPlace(next, event, deps) {
48431
48418
  next.stdinClosed = true;
48432
48419
  effects.push({ kind: "close-stdin" });
48433
48420
  } else if (isRpcAgentTool(tool) && !isCloudTool(tool)) {
48434
- if (tool === PI_TOOL_ID) next.stdinClosed = true;
48421
+ next.stdinClosed = true;
48435
48422
  effects.push({ kind: "kill", signal: "SIGTERM" });
48436
48423
  } else {
48437
48424
  const idleKillMs = idleKillDelayOf(next);
@@ -49183,6 +49170,7 @@ var SessionRunner = class {
49183
49170
  // JSON-RPC 类 agent(codex app-server) 的 per-session 驱动器;非 null 时 runner 不用 spawn()/ChildProcess,
49184
49171
  // effect 路由到 session 一等方法(startTurn/respondPermission/answerQuestion/interrupt/stop)。claude 恒 null。
49185
49172
  session = null;
49173
+ sessionGeneration = 0;
49186
49174
  stdoutBuf = "";
49187
49175
  // 未决 control_request 表;key = request_id
49188
49176
  pendingControlRequests = /* @__PURE__ */ new Map();
@@ -49229,6 +49217,7 @@ var SessionRunner = class {
49229
49217
  };
49230
49218
  const { state, effects } = reduceSession(this.state, inputMsg, deps);
49231
49219
  this.state = state;
49220
+ if (this.session && effects.some((effect) => effect.kind === "spawn")) this.sessionGeneration++;
49232
49221
  for (const e of effects) this.applyEffect(e, inputMsg);
49233
49222
  if (!this.state.procAlive && this.stopWaiters.length > 0) {
49234
49223
  const waiters = this.stopWaiters;
@@ -49594,25 +49583,35 @@ var SessionRunner = class {
49594
49583
  return;
49595
49584
  }
49596
49585
  if (this.hooks.adapter.createSession) {
49597
- this.session = this.hooks.adapter.createSession(ctx, {
49586
+ const generation = ++this.sessionGeneration;
49587
+ const isCurrent = () => this.sessionGeneration === generation;
49588
+ const session = this.hooks.adapter.createSession(ctx, {
49598
49589
  pushEvents: (events) => {
49599
- if (events.length === 0) return;
49590
+ if (!isCurrent() || events.length === 0) return;
49600
49591
  const uuid = (this.hooks.genUuid ?? import_node_crypto4.randomUUID)();
49601
49592
  this.input({ kind: "inject-events", events: events.map((e) => e.uuid ? e : { ...e, uuid }) });
49602
49593
  },
49603
49594
  onExit: (code) => {
49595
+ if (!isCurrent()) return;
49596
+ this.sessionGeneration++;
49604
49597
  this.session = null;
49605
49598
  this.clearIdleKillTimers();
49606
49599
  this.input({ kind: "proc-exit", code });
49607
49600
  },
49608
- onError: (message) => this.input({ kind: "proc-error", message }),
49609
- onHistoryGap: (synchronized) => this.hooks.broadcastFrame({
49610
- type: "session:control",
49611
- sessionId: this.state.file.sessionId,
49612
- kind: CLOUD_HISTORY_REFRESH_KIND,
49613
- synchronized
49614
- }, "broadcast"),
49601
+ onError: (message) => {
49602
+ if (isCurrent()) this.input({ kind: "proc-error", message });
49603
+ },
49604
+ onHistoryGap: (synchronized) => {
49605
+ if (!isCurrent()) return;
49606
+ this.hooks.broadcastFrame({
49607
+ type: "session:control",
49608
+ sessionId: this.state.file.sessionId,
49609
+ kind: CLOUD_HISTORY_REFRESH_KIND,
49610
+ synchronized
49611
+ }, "broadcast");
49612
+ },
49615
49613
  onCommandPrepared: (commandId, text, prepared) => {
49614
+ if (!isCurrent()) return false;
49616
49615
  const pending = this.state.file.cloudPendingTurns?.find((turn) => turn.id === commandId) ?? this.state.file.cloudPendingCommand;
49617
49616
  if (!pending || pending.id !== commandId) return false;
49618
49617
  if (!prepared && pending !== this.state.file.cloudPendingCommand) {
@@ -49620,8 +49619,11 @@ var SessionRunner = class {
49620
49619
  }
49621
49620
  return true;
49622
49621
  },
49623
- onCloudTurnTerminal: (turnId) => this.input({ kind: "cloud-turn-terminal", turnId })
49622
+ onCloudTurnTerminal: (turnId) => {
49623
+ if (isCurrent()) this.input({ kind: "cloud-turn-terminal", turnId });
49624
+ }
49624
49625
  });
49626
+ if (isCurrent()) this.session = session;
49625
49627
  return;
49626
49628
  }
49627
49629
  const proc = this.hooks.spawnOverride ? this.hooks.spawnOverride(ctx) : this.hooks.adapter.spawn(ctx);
@@ -75336,7 +75338,7 @@ function computeMethodAccess(args) {
75336
75338
  }
75337
75339
 
75338
75340
  // src/version.ts
75339
- var version = "0.2.680".length > 0 ? "0.2.680" : "dev";
75341
+ var version = "0.2.682".length > 0 ? "0.2.682" : "dev";
75340
75342
 
75341
75343
  // src/cli-probe/probe.ts
75342
75344
  var fs86 = __toESM(require("fs"), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.680",
3
+ "version": "0.2.682",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",