@clawos-dev/clawd 0.2.101-beta.192.2f41caf → 0.2.101-beta.194.a406ba4

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 +99 -42
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -5378,6 +5378,36 @@ function ownerNamespace(ownerPrincipalId) {
5378
5378
  function namespacedExtId(slug, ownerPrincipalId) {
5379
5379
  return `${slug}-${ownerNamespace(ownerPrincipalId)}`;
5380
5380
  }
5381
+ function validateSimpleSemver(v2) {
5382
+ if (typeof v2 !== "string") {
5383
+ return { ok: false, reason: "version must be a string" };
5384
+ }
5385
+ const parts = v2.split(".");
5386
+ if (parts.length !== 3) {
5387
+ return { ok: false, reason: `"${v2}" \u2014 only MAJOR.MINOR.PATCH allowed` };
5388
+ }
5389
+ for (const p2 of parts) {
5390
+ if (!/^\d+$/.test(p2)) {
5391
+ return { ok: false, reason: `"${v2}" \u2014 only numeric segments allowed` };
5392
+ }
5393
+ }
5394
+ return { ok: true };
5395
+ }
5396
+ function compareSimpleSemver(a, b2) {
5397
+ const pa = parseOrThrow(a);
5398
+ const pb = parseOrThrow(b2);
5399
+ for (let i = 0; i < 3; i++) {
5400
+ if (pa[i] < pb[i]) return -1;
5401
+ if (pa[i] > pb[i]) return 1;
5402
+ }
5403
+ return 0;
5404
+ }
5405
+ function parseOrThrow(v2) {
5406
+ const r = validateSimpleSemver(v2);
5407
+ if (!r.ok) throw new Error(r.reason);
5408
+ const [a, b2, c] = v2.split(".").map((p2) => parseInt(p2, 10));
5409
+ return [a, b2, c];
5410
+ }
5381
5411
  var EXT_ID_REGEX, ExtensionStateSchema, ExtensionManifestSchema, ExtensionRecordSchema, PublishedSnapshotSchema, ChannelRefSchema, SourceRefSchema, PublishedExtensionRecordSchema, PublishCheckSchema, PublishStatusResultSchema;
5382
5412
  var init_extension = __esm({
5383
5413
  "../protocol/src/extension.ts"() {
@@ -31201,7 +31231,11 @@ function tryFlushPending(state, deps) {
31201
31231
  const payload = deps.encodeStdin(text, { sessionId: state.file.sessionId });
31202
31232
  return [{ kind: "write-stdin", payload }];
31203
31233
  }
31204
- function rgDbg(event, info) {
31234
+ function rgDbg(deps, event, info) {
31235
+ if (deps.logger) {
31236
+ deps.logger.debug(`[RG] ${event}`, info);
31237
+ return;
31238
+ }
31205
31239
  console.debug(`[RG] ${event}`, info);
31206
31240
  }
31207
31241
  function resetReadyGate(next) {
@@ -31477,7 +31511,7 @@ function applyCommand(state, command, deps) {
31477
31511
  const payload = deps.encodeStdin(command.text, { sessionId });
31478
31512
  effects.push({ kind: "write-stdin", payload });
31479
31513
  }
31480
- rgDbg("send", {
31514
+ rgDbg(deps, "send", {
31481
31515
  sid: sessionId,
31482
31516
  mode: deps.mode ?? "sdk",
31483
31517
  procAliveBefore,
@@ -31849,13 +31883,13 @@ function reduceSession(state, input, deps) {
31849
31883
  }
31850
31884
  case "ready-detected": {
31851
31885
  if (deps.mode !== "tui") {
31852
- rgDbg("ready-input", { sid: state.file.sessionId, skipped: "non-tui-mode" });
31886
+ rgDbg(deps, "ready-input", { sid: state.file.sessionId, skipped: "non-tui-mode" });
31853
31887
  return { state, effects: [] };
31854
31888
  }
31855
31889
  const next = cloneState(state);
31856
31890
  next.readyForSend = true;
31857
31891
  const flushEffects = tryFlushPending(next, deps);
31858
- rgDbg("ready-input", {
31892
+ rgDbg(deps, "ready-input", {
31859
31893
  sid: next.file.sessionId,
31860
31894
  wroteStdin: flushEffects.length > 0,
31861
31895
  readyAfter: next.readyForSend,
@@ -32028,7 +32062,9 @@ var SessionRunner = class {
32028
32062
  ownerDisplayName: this.hooks.ownerDisplayName,
32029
32063
  personaRoot: this.hooks.personaRoot,
32030
32064
  // ReadyGate v2:透传 mode 让 reducer send / ready-detected 分支决定走暂存队列还是直写
32031
- mode: this.hooks.mode
32065
+ mode: this.hooks.mode,
32066
+ // [RG-DBG] 注入 logger 让 reducer rgDbg 走 pino 进 clawd.log;定位完跟 rgDbg 一起删
32067
+ logger: this.hooks.logger
32032
32068
  };
32033
32069
  const { state, effects } = reduceSession(this.state, inputMsg, deps);
32034
32070
  this.state = state;
@@ -32207,7 +32243,7 @@ var SessionRunner = class {
32207
32243
  this.doKill(effect.signal);
32208
32244
  break;
32209
32245
  case "write-stdin":
32210
- console.debug("[RG] write-stdin", {
32246
+ this.hooks.logger?.debug("[RG] write-stdin", {
32211
32247
  procAlive: !!this.proc,
32212
32248
  stdinWritable: !!this.proc?.stdin,
32213
32249
  len: effect.payload.length,
@@ -33863,12 +33899,12 @@ var SessionManager = class {
33863
33899
  */
33864
33900
  dispatchReadyDetected(toolSessionId) {
33865
33901
  if (this.deps.mode !== "tui") {
33866
- console.debug("[RG] mgr-disp", { tsid: toolSessionId, skipped: "non-tui-mode" });
33902
+ this.deps.logger?.debug("[RG] mgr-disp", { tsid: toolSessionId, skipped: "non-tui-mode" });
33867
33903
  return;
33868
33904
  }
33869
33905
  const sid = this.sessionIdByToolSid(toolSessionId);
33870
33906
  const runner = sid ? this.runners.get(sid) : void 0;
33871
- console.debug("[RG] mgr-disp", {
33907
+ this.deps.logger?.debug("[RG] mgr-disp", {
33872
33908
  tsid: toolSessionId,
33873
33909
  sid: sid ?? null,
33874
33910
  runnerFound: !!runner
@@ -34997,20 +35033,19 @@ var PtyChildProcess = class extends import_node_events.EventEmitter {
34997
35033
  if (match) {
34998
35034
  const paste = match[1];
34999
35035
  const enter = match[2];
35000
- console.debug("[RG] pty-paste", { pasteLen: paste.length, enterLen: enter.length });
35036
+ logger?.debug("[RG] pty-paste", { tag, pasteLen: paste.length, enterLen: enter.length });
35001
35037
  pty.write(paste);
35002
35038
  setTimeout(() => {
35003
35039
  try {
35004
35040
  pty.write(enter);
35005
- console.debug("[RG] pty-paste-enter", { wrote: "\\r", disposed: false });
35006
- logger?.debug("pty bracketed paste submit \\r delayed", { tag, pid: this.pid });
35041
+ logger?.debug("[RG] pty-paste-enter", { tag, wrote: "\\r", disposed: false });
35007
35042
  } catch (err) {
35008
- console.debug("[RG] pty-paste-enter", { error: err.message });
35043
+ logger?.debug("[RG] pty-paste-enter", { tag, error: err.message });
35009
35044
  logger?.warn("pty delayed \\r failed", { tag, error: err.message });
35010
35045
  }
35011
- }, 120);
35046
+ }, 240);
35012
35047
  } else {
35013
- console.debug("[RG] pty-write-direct", { len: data.length });
35048
+ logger?.debug("[RG] pty-write-direct", { tag, len: data.length });
35014
35049
  pty.write(data);
35015
35050
  }
35016
35051
  };
@@ -35251,14 +35286,21 @@ function createReadyDetector(opts) {
35251
35286
  quietTimer = null;
35252
35287
  }
35253
35288
  };
35289
+ const dbg = (info) => {
35290
+ if (opts.logger) {
35291
+ opts.logger.debug("[RG] det-state", info);
35292
+ return;
35293
+ }
35294
+ console.debug("[RG] det-state", info);
35295
+ };
35254
35296
  const quietFire = () => {
35255
35297
  quietTimer = null;
35256
35298
  if (disposed) return;
35257
35299
  if (!scanReadyFrame()) {
35258
- console.debug("[RG] det-state", { event: "quiet-fire-but-not-ready-anymore" });
35300
+ dbg({ event: "quiet-fire-but-not-ready-anymore" });
35259
35301
  return;
35260
35302
  }
35261
- console.debug("[RG] det-state", { event: "quiet-fire \u2192 onReady" });
35303
+ dbg({ event: "quiet-fire \u2192 onReady" });
35262
35304
  opts.onReady();
35263
35305
  };
35264
35306
  let prevReady = false;
@@ -35268,13 +35310,13 @@ function createReadyDetector(opts) {
35268
35310
  if (!ready) {
35269
35311
  clearQuiet();
35270
35312
  if (prevReady) {
35271
- console.debug("[RG] det-state", { event: "ready \u2192 not-ready" });
35313
+ dbg({ event: "ready \u2192 not-ready" });
35272
35314
  prevReady = false;
35273
35315
  }
35274
35316
  return;
35275
35317
  }
35276
35318
  if (!prevReady) {
35277
- console.debug("[RG] det-state", { event: "not-ready \u2192 ready-candidate (quiet timer set)" });
35319
+ dbg({ event: "not-ready \u2192 ready-candidate (quiet timer set)" });
35278
35320
  prevReady = true;
35279
35321
  }
35280
35322
  clearQuiet();
@@ -35391,7 +35433,9 @@ var ClaudeTuiAdapter = class extends ClaudeAdapter {
35391
35433
  if (!ctx.toolSessionId || !this.tuiOpts.onReady) return;
35392
35434
  this.tuiLogger?.debug("ready-detected", { toolSessionId: ctx.toolSessionId });
35393
35435
  this.tuiOpts.onReady(ctx.toolSessionId);
35394
- }
35436
+ },
35437
+ // [RG-DBG] 排查 ReadyGate 偶现卡输入用;定位完跟所有 [RG] 日志一起删
35438
+ logger: this.tuiLogger
35395
35439
  });
35396
35440
  if (ctx.toolSessionId && this.tuiOpts.onDetectorRegister) {
35397
35441
  this.tuiOpts.onDetectorRegister(ctx.toolSessionId, detector);
@@ -40511,7 +40555,7 @@ function computePublishCheck(args) {
40511
40555
  }
40512
40556
  return { kind: "error-same-hash", version: head.version };
40513
40557
  }
40514
- const cmp = compareSemver(localVersion, head.version);
40558
+ const cmp = compareSimpleSemver(localVersion, head.version);
40515
40559
  if (cmp > 0) {
40516
40560
  return {
40517
40561
  kind: "ready-new-version",
@@ -40532,28 +40576,6 @@ function computePublishCheck(args) {
40532
40576
  publishedVersion: head.version
40533
40577
  };
40534
40578
  }
40535
- function compareSemver(a, b2) {
40536
- const pa = parseSimpleSemver(a);
40537
- const pb = parseSimpleSemver(b2);
40538
- for (let i = 0; i < 3; i++) {
40539
- if (pa[i] < pb[i]) return -1;
40540
- if (pa[i] > pb[i]) return 1;
40541
- }
40542
- return 0;
40543
- }
40544
- function parseSimpleSemver(v2) {
40545
- const parts = v2.split(".");
40546
- if (parts.length !== 3) {
40547
- throw new Error(`unsupported version "${v2}" \u2014 only MAJOR.MINOR.PATCH allowed`);
40548
- }
40549
- const nums = parts.map((p2) => {
40550
- if (!/^\d+$/.test(p2)) {
40551
- throw new Error(`unsupported version "${v2}" \u2014 only numeric segments allowed`);
40552
- }
40553
- return parseInt(p2, 10);
40554
- });
40555
- return nums;
40556
- }
40557
40579
 
40558
40580
  // src/extension/install-flow.ts
40559
40581
  var import_promises5 = __toESM(require("fs/promises"), 1);
@@ -40842,6 +40864,37 @@ function pickStringField(frame, name) {
40842
40864
  }
40843
40865
  return v2;
40844
40866
  }
40867
+ function pickOptionalString(frame, name) {
40868
+ const v2 = frame[name];
40869
+ if (v2 === void 0 || v2 === null) return null;
40870
+ if (typeof v2 !== "string") {
40871
+ throw new ClawdError(ERROR_CODES.INVALID_PARAM, `${name} must be string`);
40872
+ }
40873
+ return v2;
40874
+ }
40875
+ async function rewriteManifestVersion(root, extId, newVersion, previousPublishedVersion) {
40876
+ const v2 = validateSimpleSemver(newVersion);
40877
+ if (!v2.ok) {
40878
+ throw new ClawdError(
40879
+ ERROR_CODES.VALIDATION_ERROR,
40880
+ `INVALID_VERSION: ${v2.reason}`
40881
+ );
40882
+ }
40883
+ if (previousPublishedVersion !== void 0) {
40884
+ if (compareSimpleSemver(newVersion, previousPublishedVersion) <= 0) {
40885
+ throw new ClawdError(
40886
+ ERROR_CODES.VALIDATION_ERROR,
40887
+ `VERSION_NOT_BUMPED: newVersion ${newVersion} must be > published ${previousPublishedVersion}`
40888
+ );
40889
+ }
40890
+ }
40891
+ const manifestPath = import_node_path38.default.join(root, extId, "manifest.json");
40892
+ const manifest = await readManifest(root, extId);
40893
+ const next = { ...manifest, version: newVersion };
40894
+ const tmp = `${manifestPath}.tmp`;
40895
+ await import_promises7.default.writeFile(tmp, JSON.stringify(next, null, 2));
40896
+ await import_promises7.default.rename(tmp, manifestPath);
40897
+ }
40845
40898
  async function readManifest(root, extId) {
40846
40899
  const file = import_node_path38.default.join(root, extId, "manifest.json");
40847
40900
  let raw;
@@ -40933,6 +40986,10 @@ function buildExtensionHandlers(deps) {
40933
40986
  const publish = async (frame, _client, ctx) => {
40934
40987
  assertOwner(ctx);
40935
40988
  const extId = pickExtId(frame);
40989
+ const newVersion = pickOptionalString(frame, "newVersion");
40990
+ if (newVersion !== null) {
40991
+ await rewriteManifestVersion(deps.root, extId, newVersion, deps.publishedChannelStore.get(extId)?.version);
40992
+ }
40936
40993
  const { manifest, contentHash } = await buildSnapshotMeta(extId);
40937
40994
  const head = deps.publishedChannelStore.get(extId);
40938
40995
  const check = computePublishCheck({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.101-beta.192.2f41caf",
3
+ "version": "0.2.101-beta.194.a406ba4",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",