@clawos-dev/clawd 0.2.597 → 0.2.598

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 +69 -16
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -52156,6 +52156,26 @@ function subagentSummaries(parent) {
52156
52156
  }
52157
52157
  return out;
52158
52158
  }
52159
+ function historyBase(text) {
52160
+ const newline = text.indexOf("\n");
52161
+ const firstLine = newline < 0 ? text : text.slice(0, newline);
52162
+ let payload;
52163
+ try {
52164
+ const row = JSON.parse(firstLine);
52165
+ if (row.type !== "session_meta" || !row.payload || typeof row.payload !== "object") return null;
52166
+ payload = row.payload;
52167
+ } catch {
52168
+ return null;
52169
+ }
52170
+ const base = payload.history_base;
52171
+ if (base == null) return null;
52172
+ if (typeof base !== "object" || Array.isArray(base)) throw new Error("Codex fork history_base is invalid");
52173
+ const { thread_id: threadId, end_byte_offset: endByteOffset } = base;
52174
+ if (typeof threadId !== "string" || !threadId || typeof endByteOffset !== "number" || !Number.isSafeInteger(endByteOffset) || endByteOffset < 0) {
52175
+ throw new Error("Codex fork history_base is invalid");
52176
+ }
52177
+ return { threadId, endByteOffset };
52178
+ }
52159
52179
  var CodexHistoryReader = class {
52160
52180
  deps;
52161
52181
  constructor(deps) {
@@ -52208,24 +52228,29 @@ var CodexHistoryReader = class {
52208
52228
  }
52209
52229
  async read(args) {
52210
52230
  const locate = createCodexRolloutLocator(this.deps.roots);
52211
- const parent = this.parseThread(locate, args.toolSessionId);
52212
- const messages = await withSubagentResults(
52213
- parent,
52214
- args.toolSessionId,
52215
- async (agentId) => {
52216
- const file = locate(agentId);
52217
- return file ? import_node_fs15.default.readFileSync(file, "utf8") : null;
52218
- },
52219
- this.deps.logger
52220
- );
52231
+ const segments = this.parseThreadSegments(locate, args.toolSessionId);
52232
+ const messages = [];
52233
+ for (const segment of segments) {
52234
+ messages.push(...await withSubagentResults(
52235
+ segment.parsed,
52236
+ segment.threadId,
52237
+ async (agentId) => {
52238
+ const file = locate(agentId);
52239
+ return file ? import_node_fs15.default.readFileSync(file, "utf8") : null;
52240
+ },
52241
+ this.deps.logger
52242
+ ));
52243
+ }
52221
52244
  return pageMessages(messages, args);
52222
52245
  }
52223
52246
  async listSubagents(args) {
52224
52247
  return subagentSummaries(this.parseThread(createCodexRolloutLocator(this.deps.roots), args.toolSessionId));
52225
52248
  }
52226
52249
  async readSubagent(args) {
52227
- const child = this.parseThread(createCodexRolloutLocator(this.deps.roots), args.subagentId);
52228
- if (child.meta?.threadId !== args.subagentId || child.meta.parentThreadId !== args.toolSessionId) {
52250
+ const locate = createCodexRolloutLocator(this.deps.roots);
52251
+ const owner2 = this.parseThreadSegments(locate, args.toolSessionId).find((segment) => segment.parsed.subagents.some((sub) => sub.agentId === args.subagentId));
52252
+ const child = this.parseThread(locate, args.subagentId);
52253
+ if (!owner2 || child.meta?.threadId !== args.subagentId || child.meta.parentThreadId !== owner2.threadId) {
52229
52254
  throw new Error(
52230
52255
  `Codex subagent thread ${args.subagentId} does not belong to parent thread ${args.toolSessionId}`
52231
52256
  );
@@ -52239,9 +52264,37 @@ var CodexHistoryReader = class {
52239
52264
  return [];
52240
52265
  }
52241
52266
  parseThread(locate, threadId) {
52242
- const file = locate(threadId);
52243
- if (!file) throw new Error(`Codex rollout not found for thread ${threadId}`);
52244
- return parseCodexRollout(import_node_fs15.default.readFileSync(file, "utf8"));
52267
+ const segments = this.parseThreadSegments(locate, threadId);
52268
+ const current = segments[segments.length - 1].parsed;
52269
+ return {
52270
+ ...current,
52271
+ messages: segments.flatMap((s2) => s2.parsed.messages),
52272
+ subagents: segments.flatMap((s2) => s2.parsed.subagents),
52273
+ turns: segments.flatMap((s2) => s2.parsed.turns)
52274
+ };
52275
+ }
52276
+ parseThreadSegments(locate, threadId, endByteOffset, seen = /* @__PURE__ */ new Set()) {
52277
+ const key = threadId.toLowerCase();
52278
+ if (seen.has(key)) throw new Error(`Codex fork history cycle at thread ${threadId}`);
52279
+ seen.add(key);
52280
+ try {
52281
+ const file = locate(threadId);
52282
+ if (!file) throw new Error(`Codex rollout not found for thread ${threadId}`);
52283
+ const bytes = import_node_fs15.default.readFileSync(file);
52284
+ if (endByteOffset !== void 0 && endByteOffset > bytes.length) {
52285
+ throw new Error(`Codex fork history_base exceeds source rollout ${threadId}`);
52286
+ }
52287
+ const text = (endByteOffset === void 0 ? bytes : bytes.subarray(0, endByteOffset)).toString("utf8");
52288
+ const parsed = parseCodexRollout(text);
52289
+ if (parsed.meta?.threadId.toLowerCase() !== key) {
52290
+ throw new Error(`Codex rollout metadata does not match thread ${threadId}`);
52291
+ }
52292
+ const base = historyBase(text);
52293
+ const inherited = base ? this.parseThreadSegments(locate, base.threadId, base.endByteOffset, seen) : [];
52294
+ return [...inherited, { threadId, parsed }];
52295
+ } finally {
52296
+ seen.delete(key);
52297
+ }
52245
52298
  }
52246
52299
  };
52247
52300
 
@@ -72906,7 +72959,7 @@ function computeMethodAccess(args) {
72906
72959
  }
72907
72960
 
72908
72961
  // src/version.ts
72909
- var version = "0.2.597".length > 0 ? "0.2.597" : "dev";
72962
+ var version = "0.2.598".length > 0 ? "0.2.598" : "dev";
72910
72963
 
72911
72964
  // src/cli-probe/probe.ts
72912
72965
  var fs83 = __toESM(require("fs"), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.597",
3
+ "version": "0.2.598",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",