@clawos-dev/clawd 0.2.37 → 0.2.38-beta.54.cac95f0

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 +50 -11
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -8738,9 +8738,10 @@ var init_schemas = __esm({
8738
8738
  // NewSessionDialog 勾选 worktree 创建的 session 才会持久化这两个字段
8739
8739
  worktreeRoot: external_exports.string().min(1).optional(),
8740
8740
  worktreeBranch: external_exports.string().min(1).optional(),
8741
- // 由 session:fork 派生的 session 在 create 时记录源 transcripttoolSessionId;
8742
- // sidebar 据此挂 fork 图标。非 fork session 该字段缺省
8743
- forkedFromToolSessionId: external_exports.string().min(1).optional(),
8741
+ // 由 session:fork 派生的 session 在 create 时记录源 sessionsessionId(稳定 key,
8742
+ // 不受 parent clear / re-spawn 影响);sidebar 据此挂 fork 图标。非 fork session 该字段缺省。
8743
+ // 旧字段 forkedFromToolSessionId 已弃用,daemon 启动时一次性迁移老数据
8744
+ forkedFromSessionId: external_exports.string().min(1).optional(),
8744
8745
  // owner-mode persona session 身份标识;UI 用它在 SessionList 过滤 + jump,
8745
8746
  // daemon 用它做 idempotent dedupe + spawn 时派生 ctx.personaMode='owner'
8746
8747
  ownerPersonaId: external_exports.string().min(1).optional(),
@@ -8955,8 +8956,8 @@ var init_schemas = __esm({
8955
8956
  // NewSessionDialog 勾选 worktree 时由 UI 传入,daemon 原样持久化,不做额外副作用
8956
8957
  worktreeRoot: external_exports.string().min(1).optional(),
8957
8958
  worktreeBranch: external_exports.string().min(1).optional(),
8958
- // session:fork 派生 session 时由 UI 传入,daemon 写到 SessionFile.forkedFromToolSessionId
8959
- forkedFromToolSessionId: external_exports.string().min(1).optional(),
8959
+ // session:fork 派生 session 时由 UI 传入源 sessionId,daemon 写到 SessionFile.forkedFromSessionId
8960
+ forkedFromSessionId: external_exports.string().min(1).optional(),
8960
8961
  // owner-mode persona session:传此字段时 daemon 自行派生 cwd 和启动参数,
8961
8962
  // 且按 ownerPersonaId 做 idempotent dedupe(每 persona 永远只有一个 owner session)
8962
8963
  ownerPersonaId: external_exports.string().min(1).optional()
@@ -15522,20 +15523,52 @@ var SessionStore = class {
15522
15523
  if (code === "ENOENT") return [];
15523
15524
  throw err;
15524
15525
  }
15525
- const out = [];
15526
+ const raws = [];
15526
15527
  for (const name of entries) {
15527
15528
  if (!name.endsWith(".json")) continue;
15528
15529
  if (name.includes(".tmp-")) continue;
15529
15530
  const full = import_node_path3.default.join(this.root, name);
15530
15531
  try {
15531
- const raw = import_node_fs3.default.readFileSync(full, "utf8");
15532
- const parsed = JSON.parse(raw);
15533
- const validated = SessionFileSchema.parse(parsed);
15534
- out.push(validated);
15532
+ const text = import_node_fs3.default.readFileSync(full, "utf8");
15533
+ const parsed = JSON.parse(text);
15534
+ raws.push({ raw: parsed, path: full });
15535
15535
  } catch {
15536
15536
  continue;
15537
15537
  }
15538
15538
  }
15539
+ const byToolId = /* @__PURE__ */ new Map();
15540
+ for (const { raw } of raws) {
15541
+ const sid = raw["sessionId"];
15542
+ const tsid = raw["toolSessionId"];
15543
+ if (typeof sid === "string" && typeof tsid === "string") byToolId.set(tsid, sid);
15544
+ }
15545
+ const out = [];
15546
+ for (const { raw, path: full } of raws) {
15547
+ const legacy = raw["forkedFromToolSessionId"];
15548
+ const dirty = typeof legacy === "string";
15549
+ if (dirty) {
15550
+ if (raw["forkedFromSessionId"] === void 0) {
15551
+ const parentSid = byToolId.get(legacy);
15552
+ if (typeof parentSid === "string") raw["forkedFromSessionId"] = parentSid;
15553
+ }
15554
+ delete raw["forkedFromToolSessionId"];
15555
+ }
15556
+ let validated;
15557
+ try {
15558
+ validated = SessionFileSchema.parse(raw);
15559
+ } catch {
15560
+ continue;
15561
+ }
15562
+ if (dirty) {
15563
+ try {
15564
+ const tmp = `${full}.tmp-${process.pid}-${Date.now()}`;
15565
+ import_node_fs3.default.writeFileSync(tmp, JSON.stringify(validated, null, 2), { encoding: "utf8", mode: 384 });
15566
+ import_node_fs3.default.renameSync(tmp, full);
15567
+ } catch {
15568
+ }
15569
+ }
15570
+ out.push(validated);
15571
+ }
15539
15572
  return out.sort((a, b) => a.updatedAt > b.updatedAt ? -1 : a.updatedAt < b.updatedAt ? 1 : 0);
15540
15573
  }
15541
15574
  };
@@ -16759,6 +16792,12 @@ var SessionManager = class {
16759
16792
  }
16760
16793
  // ---- 命令方法:均返回 { response, broadcast[] },由 dispatcher 聚合 ----
16761
16794
  create(args) {
16795
+ if (args.ownerPersonaId) {
16796
+ const existing = this.deps.store.list().find((s) => s.ownerPersonaId === args.ownerPersonaId);
16797
+ if (existing) {
16798
+ return { response: existing, broadcast: [] };
16799
+ }
16800
+ }
16762
16801
  let cwd = args.cwd;
16763
16802
  if (args.ownerPersonaId && !cwd) {
16764
16803
  if (!this.deps.personaRoot) {
@@ -16789,7 +16828,7 @@ var SessionManager = class {
16789
16828
  iconKey: args.iconKey,
16790
16829
  worktreeRoot: args.worktreeRoot,
16791
16830
  worktreeBranch: args.worktreeBranch,
16792
- forkedFromToolSessionId: args.forkedFromToolSessionId,
16831
+ forkedFromSessionId: args.forkedFromSessionId,
16793
16832
  ownerPersonaId: args.ownerPersonaId,
16794
16833
  createdAt: iso,
16795
16834
  updatedAt: iso
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.37",
3
+ "version": "0.2.38-beta.54.cac95f0",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",