@clawos-dev/clawd 0.2.133-beta.261.f56c209 → 0.2.133-beta.263.cdd5ca9

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 +75 -32
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -10233,6 +10233,23 @@ var require_pino = __commonJS({
10233
10233
  }
10234
10234
  });
10235
10235
 
10236
+ // src/session/stdout-splitter.ts
10237
+ function splitStdoutChunk(buf, chunk) {
10238
+ let next = buf + (typeof chunk === "string" ? chunk : chunk.toString("utf8"));
10239
+ const lines = [];
10240
+ let idx;
10241
+ while ((idx = next.indexOf("\n")) >= 0) {
10242
+ lines.push(next.slice(0, idx));
10243
+ next = next.slice(idx + 1);
10244
+ }
10245
+ return { newBuf: next, lines };
10246
+ }
10247
+ var init_stdout_splitter = __esm({
10248
+ "src/session/stdout-splitter.ts"() {
10249
+ "use strict";
10250
+ }
10251
+ });
10252
+
10236
10253
  // src/session/permission-stdio.ts
10237
10254
  function encodePermissionResponse(requestId, approved, input, message) {
10238
10255
  const innerResponse = approved ? {
@@ -10255,23 +10272,6 @@ var init_permission_stdio = __esm({
10255
10272
  }
10256
10273
  });
10257
10274
 
10258
- // src/session/stdout-splitter.ts
10259
- function splitStdoutChunk(buf, chunk) {
10260
- let next = buf + (typeof chunk === "string" ? chunk : chunk.toString("utf8"));
10261
- const lines = [];
10262
- let idx;
10263
- while ((idx = next.indexOf("\n")) >= 0) {
10264
- lines.push(next.slice(0, idx));
10265
- next = next.slice(idx + 1);
10266
- }
10267
- return { newBuf: next, lines };
10268
- }
10269
- var init_stdout_splitter = __esm({
10270
- "src/session/stdout-splitter.ts"() {
10271
- "use strict";
10272
- }
10273
- });
10274
-
10275
10275
  // ../node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.mjs
10276
10276
  function Diff() {
10277
10277
  }
@@ -31625,9 +31625,6 @@ function buildRule(tool, input) {
31625
31625
  return { tool, pattern, createdAt: (/* @__PURE__ */ new Date()).toISOString() };
31626
31626
  }
31627
31627
 
31628
- // src/session/reducer.ts
31629
- init_permission_stdio();
31630
-
31631
31628
  // src/persona/connection-prompt.ts
31632
31629
  var OWNER_TEMPLATE = `# \u8FDE\u63A5\u4E0A\u4E0B\u6587
31633
31630
  \u4F60\u73B0\u5728\u4EE5 Owner \u8EAB\u4EFD\u88AB\u8FDE\u63A5\uFF0C\u5BF9\u65B9\u5C31\u662F owner \u672C\u4EBA\uFF08{ownerLabel}\uFF09\u3002
@@ -31814,10 +31811,7 @@ function applyParsedEvent(state, event, deps) {
31814
31811
  effects.push(...pushed2.effects);
31815
31812
  const hit = matchesAnyRule(next.file.permissionRules, tool, input);
31816
31813
  if (hit) {
31817
- effects.push({
31818
- kind: "write-stdin",
31819
- payload: encodePermissionResponse(requestId, true, input)
31820
- });
31814
+ effects.push({ kind: "respond-permission", requestId, allow: true, input });
31821
31815
  } else {
31822
31816
  const pending = {
31823
31817
  tool,
@@ -32210,13 +32204,11 @@ function reduceSession(state, input, deps) {
32210
32204
  next.pendingPermissions = nextPending;
32211
32205
  const effects = [
32212
32206
  {
32213
- kind: "write-stdin",
32214
- payload: encodePermissionResponse(
32215
- input.requestId,
32216
- input.allow,
32217
- pending.input,
32218
- input.message
32219
- )
32207
+ kind: "respond-permission",
32208
+ requestId: input.requestId,
32209
+ allow: input.allow,
32210
+ input: pending.input,
32211
+ message: input.message
32220
32212
  }
32221
32213
  ];
32222
32214
  if (input.allow && input.permanent) {
@@ -32356,6 +32348,7 @@ function reduceSession(state, input, deps) {
32356
32348
 
32357
32349
  // src/session/runner.ts
32358
32350
  init_stdout_splitter();
32351
+ init_permission_stdio();
32359
32352
 
32360
32353
  // src/ipc-recorder.ts
32361
32354
  var import_node_fs4 = __toESM(require("fs"), 1);
@@ -32463,6 +32456,9 @@ var SessionRunner = class {
32463
32456
  hooks;
32464
32457
  state;
32465
32458
  proc = null;
32459
+ // JSON-RPC 类 agent(codex app-server) 的 per-session 驱动器;非 null 时 runner 不用 spawn()/ChildProcess,
32460
+ // effect 路由到 session 一等方法(startTurn/respondPermission/answerQuestion/interrupt/stop)。claude 恒 null。
32461
+ session = null;
32466
32462
  stdoutBuf = "";
32467
32463
  // 未决 control_request 表;key = request_id
32468
32464
  pendingControlRequests = /* @__PURE__ */ new Map();
@@ -32571,6 +32567,15 @@ var SessionRunner = class {
32571
32567
  if (this.hooks.onFileEdit) this.observeForFileEdit(events);
32572
32568
  this.input({ kind: "inject-events", events });
32573
32569
  }
32570
+ // session:interrupt 的 SDK 通道分流:codex → AgentSession.interrupt();claude → control_request('interrupt')。
32571
+ // TUI(pty) 路径在 manager.dispatchInterrupt 里先于此处理,不进这里。
32572
+ async interrupt() {
32573
+ if (this.session) {
32574
+ this.session.interrupt();
32575
+ return;
32576
+ }
32577
+ await this.sendControlRequest("interrupt");
32578
+ }
32574
32579
  /**
32575
32580
  * file-sharing tool_use ↔ tool_result 配对(spec §6 PR 3)。
32576
32581
  *
@@ -32695,9 +32700,17 @@ var SessionRunner = class {
32695
32700
  this.doSpawn(effect.ctx);
32696
32701
  break;
32697
32702
  case "kill":
32703
+ if (this.session) {
32704
+ void this.session.stop();
32705
+ break;
32706
+ }
32698
32707
  this.doKill(effect.signal);
32699
32708
  break;
32700
32709
  case "write-stdin":
32710
+ if (this.session) {
32711
+ this.session.startTurn(effect.payload);
32712
+ break;
32713
+ }
32701
32714
  this.hooks.logger?.debug("[RG] write-stdin", {
32702
32715
  procAlive: !!this.proc,
32703
32716
  stdinWritable: !!this.proc?.stdin,
@@ -32707,7 +32720,21 @@ var SessionRunner = class {
32707
32720
  this.proc?.stdin?.write(effect.payload);
32708
32721
  this.recorder?.tapStdinWrite(effect.payload);
32709
32722
  break;
32723
+ case "respond-permission": {
32724
+ if (this.session) {
32725
+ this.session.respondPermission(effect.requestId, effect.allow);
32726
+ break;
32727
+ }
32728
+ const payload = encodePermissionResponse(effect.requestId, effect.allow, effect.input, effect.message);
32729
+ this.proc?.stdin?.write(payload);
32730
+ this.recorder?.tapStdinWrite(payload);
32731
+ break;
32732
+ }
32710
32733
  case "send-control-response-allow-with-input": {
32734
+ if (this.session) {
32735
+ this.session.answerQuestion(effect.requestId, effect.updatedInput);
32736
+ break;
32737
+ }
32711
32738
  const payload = encodeAllowWithInputControlResponse(effect.requestId, effect.updatedInput);
32712
32739
  this.proc?.stdin?.write(payload);
32713
32740
  this.recorder?.tapStdinWrite(payload);
@@ -32764,6 +32791,22 @@ var SessionRunner = class {
32764
32791
  }
32765
32792
  // 启动子进程,绑定 stdout line buffer → 回灌 reducer
32766
32793
  doSpawn(ctx) {
32794
+ if (this.hooks.adapter.createSession) {
32795
+ this.session = this.hooks.adapter.createSession(ctx, {
32796
+ pushEvents: (events) => {
32797
+ if (events.length === 0) return;
32798
+ const uuid = (this.hooks.genUuid ?? v4_default)();
32799
+ this.input({ kind: "inject-events", events: events.map((e) => e.uuid ? e : { ...e, uuid }) });
32800
+ },
32801
+ onExit: (code) => {
32802
+ this.session = null;
32803
+ this.clearIdleKillTimers();
32804
+ this.input({ kind: "proc-exit", code });
32805
+ },
32806
+ onError: (message) => this.input({ kind: "proc-error", message })
32807
+ });
32808
+ return;
32809
+ }
32767
32810
  const proc = this.hooks.spawnOverride ? this.hooks.spawnOverride(ctx) : this.hooks.adapter.spawn(ctx);
32768
32811
  this.proc = proc;
32769
32812
  this.stdoutBuf = "";
@@ -33634,7 +33677,7 @@ var SessionManager = class {
33634
33677
  tsid,
33635
33678
  mode: this.deps.mode
33636
33679
  });
33637
- await runner.sendControlRequest("interrupt");
33680
+ await runner.interrupt();
33638
33681
  }
33639
33682
  // 批量版本:UI 打开 session 时一次性拿到"磁盘和快照有差异"的 user message id 集合,
33640
33683
  // 用来在消息流里精准控制 rewind 按钮的显示。session 没 toolSessionId 时返回空
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.133-beta.261.f56c209",
3
+ "version": "0.2.133-beta.263.cdd5ca9",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",