@clawos-dev/clawd 0.2.409 → 0.2.411

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.
package/dist/cli.cjs CHANGED
@@ -14365,22 +14365,49 @@ var init_tool_result_extra = __esm({
14365
14365
  function cwdToHashDir(cwd) {
14366
14366
  return cwd.replace(/[^a-zA-Z0-9]/g, "-");
14367
14367
  }
14368
- function newestSubagentMtimeMs(projectsRoot, cwd, toolSessionId) {
14369
- const dir = import_node_path5.default.join(projectsRoot, cwdToHashDir(cwd), toolSessionId, "subagents");
14368
+ function subagentsDirCandidates(projectsRoot, cwd, toolSessionId) {
14369
+ const out = [];
14370
+ const seen = /* @__PURE__ */ new Set();
14371
+ const add = (dir) => {
14372
+ if (seen.has(dir)) return;
14373
+ try {
14374
+ if (!import_node_fs6.default.statSync(dir).isDirectory()) return;
14375
+ } catch {
14376
+ return;
14377
+ }
14378
+ seen.add(dir);
14379
+ out.push(dir);
14380
+ };
14381
+ add(import_node_path5.default.join(projectsRoot, cwdToHashDir(cwd), toolSessionId, "subagents"));
14370
14382
  let entries;
14371
14383
  try {
14372
- entries = import_node_fs6.default.readdirSync(dir, { withFileTypes: true });
14384
+ entries = import_node_fs6.default.readdirSync(projectsRoot, { withFileTypes: true });
14373
14385
  } catch {
14374
- return null;
14386
+ return out;
14387
+ }
14388
+ for (const ent of entries) {
14389
+ if (!ent.isDirectory()) continue;
14390
+ add(import_node_path5.default.join(projectsRoot, ent.name, toolSessionId, "subagents"));
14375
14391
  }
14392
+ return out;
14393
+ }
14394
+ function newestSubagentMtimeMs(projectsRoot, cwd, toolSessionId) {
14376
14395
  let newest = null;
14377
- for (const e of entries) {
14378
- if (!e.isFile()) continue;
14379
- if (!e.name.startsWith("agent-") || !e.name.endsWith(".jsonl")) continue;
14396
+ for (const dir of subagentsDirCandidates(projectsRoot, cwd, toolSessionId)) {
14397
+ let entries;
14380
14398
  try {
14381
- const m2 = import_node_fs6.default.statSync(import_node_path5.default.join(dir, e.name)).mtimeMs;
14382
- if (newest === null || m2 > newest) newest = m2;
14399
+ entries = import_node_fs6.default.readdirSync(dir, { withFileTypes: true });
14383
14400
  } catch {
14401
+ continue;
14402
+ }
14403
+ for (const e of entries) {
14404
+ if (!e.isFile()) continue;
14405
+ if (!e.name.startsWith("agent-") || !e.name.endsWith(".jsonl")) continue;
14406
+ try {
14407
+ const m2 = import_node_fs6.default.statSync(import_node_path5.default.join(dir, e.name)).mtimeMs;
14408
+ if (newest === null || m2 > newest) newest = m2;
14409
+ } catch {
14410
+ }
14384
14411
  }
14385
14412
  }
14386
14413
  return newest;
@@ -14934,38 +14961,41 @@ var init_claude_history = __esm({
14934
14961
  return { messages: this.readSubagentFromMainJsonl(args.cwd, args.toolSessionId, args.subagentId) };
14935
14962
  }
14936
14963
  // 独立目录路径:<projectsRoot>/<cwdHash>/<toolSessionId>/subagents/*.jsonl
14937
- // 返回 null 表示目录不存在(调用方回退旧实现);返回空数组表示目录存在但无 jsonl
14964
+ // 返回 null 表示一个候选目录都没有(调用方回退旧实现);返回空数组表示目录在但无 jsonl。
14965
+ // [cwd 漂移] 下取**所有候选目录的并集**:漂移前后的 agent 都该列出来。同名 agentId 只可能
14966
+ // 是同一个 agent(id 全局唯一),取先遇到的那份(byCwd 优先)。
14938
14967
  listSubagentsFromDirectory(cwd, toolSessionId) {
14939
- const dir = import_node_path5.default.join(
14940
- this.resolveSessionDir(cwd, toolSessionId),
14941
- toolSessionId,
14942
- "subagents"
14943
- );
14944
- let entries;
14945
- try {
14946
- entries = import_node_fs6.default.readdirSync(dir, { withFileTypes: true });
14947
- } catch (err) {
14948
- if (err.code === "ENOENT") return null;
14949
- return null;
14950
- }
14968
+ const dirs = subagentsDirCandidates(this.projectsRoot, cwd, toolSessionId);
14969
+ if (dirs.length === 0) return null;
14951
14970
  const out = [];
14952
- for (const e of entries) {
14953
- if (!e.isFile()) continue;
14954
- if (!e.name.startsWith("agent-") || !e.name.endsWith(".jsonl")) continue;
14955
- const subagentId = e.name.slice("agent-".length, -".jsonl".length);
14956
- const filePath = import_node_path5.default.join(dir, e.name);
14957
- const lines = readJsonlLines(filePath);
14958
- let firstText = "";
14959
- let messageCount = 0;
14960
- for (const line of lines) {
14961
- const msg = messageFromJsonl(line);
14962
- if (!msg) continue;
14963
- messageCount += 1;
14964
- if (!firstText && msg.kind === "user-text" && msg.text) {
14965
- firstText = msg.text.slice(0, 120);
14971
+ const seen = /* @__PURE__ */ new Set();
14972
+ for (const dir of dirs) {
14973
+ let entries;
14974
+ try {
14975
+ entries = import_node_fs6.default.readdirSync(dir, { withFileTypes: true });
14976
+ } catch {
14977
+ continue;
14978
+ }
14979
+ for (const e of entries) {
14980
+ if (!e.isFile()) continue;
14981
+ if (!e.name.startsWith("agent-") || !e.name.endsWith(".jsonl")) continue;
14982
+ const subagentId = e.name.slice("agent-".length, -".jsonl".length);
14983
+ if (seen.has(subagentId)) continue;
14984
+ seen.add(subagentId);
14985
+ const filePath = import_node_path5.default.join(dir, e.name);
14986
+ const lines = readJsonlLines(filePath);
14987
+ let firstText = "";
14988
+ let messageCount = 0;
14989
+ for (const line of lines) {
14990
+ const msg = messageFromJsonl(line);
14991
+ if (!msg) continue;
14992
+ messageCount += 1;
14993
+ if (!firstText && msg.kind === "user-text" && msg.text) {
14994
+ firstText = msg.text.slice(0, 120);
14995
+ }
14966
14996
  }
14997
+ out.push({ subagentId, summary: firstText, messageCount });
14967
14998
  }
14968
- out.push({ subagentId, summary: firstText, messageCount });
14969
14999
  }
14970
15000
  return out;
14971
15001
  }
@@ -15002,28 +15032,26 @@ var init_claude_history = __esm({
15002
15032
  messageCount: buckets.get(id)?.count ?? 0
15003
15033
  }));
15004
15034
  }
15005
- // 独立文件路径:agent-<subagentId>.jsonl;文件不存在返回 null 让调用方回退旧实现
15035
+ // 独立文件路径:agent-<subagentId>.jsonl;所有候选目录里都没有才返回 null,让调用方
15036
+ // 回退去扫主 jsonl 的 sidechain。[cwd 漂移] 下要的就是「这个文件落在哪一侧」——
15037
+ // 只看某一个目录在不在,会把漂移侧的 agent 判成不存在。
15006
15038
  readSubagentFromFile(cwd, toolSessionId, subagentId) {
15007
- const file = import_node_path5.default.join(
15008
- this.resolveSessionDir(cwd, toolSessionId),
15009
- toolSessionId,
15010
- "subagents",
15011
- `agent-${subagentId}.jsonl`
15012
- );
15013
- let exists = false;
15014
- try {
15015
- exists = import_node_fs6.default.statSync(file).isFile();
15016
- } catch {
15017
- return null;
15018
- }
15019
- if (!exists) return null;
15020
- const lines = readJsonlLines(file);
15021
- const messages = [];
15022
- for (const line of lines) {
15023
- const msg = messageFromJsonl(line);
15024
- if (msg) messages.push(msg);
15039
+ for (const dir of subagentsDirCandidates(this.projectsRoot, cwd, toolSessionId)) {
15040
+ const file = import_node_path5.default.join(dir, `agent-${subagentId}.jsonl`);
15041
+ try {
15042
+ if (!import_node_fs6.default.statSync(file).isFile()) continue;
15043
+ } catch {
15044
+ continue;
15045
+ }
15046
+ const lines = readJsonlLines(file);
15047
+ const messages = [];
15048
+ for (const line of lines) {
15049
+ const msg = messageFromJsonl(line);
15050
+ if (msg) messages.push(msg);
15051
+ }
15052
+ return messages;
15025
15053
  }
15026
- return messages;
15054
+ return null;
15027
15055
  }
15028
15056
  /**
15029
15057
  * 遍历 session JSONL 找所有 `type:'file-history-snapshot'` 条目,按 messageId 建表
@@ -62305,7 +62333,7 @@ function computeMethodAccess(args) {
62305
62333
  }
62306
62334
 
62307
62335
  // src/version.ts
62308
- var version = "0.2.409".length > 0 ? "0.2.409" : "dev";
62336
+ var version = "0.2.411".length > 0 ? "0.2.411" : "dev";
62309
62337
 
62310
62338
  // src/cli-probe/probe.ts
62311
62339
  var fs66 = __toESM(require("fs"), 1);