@clawos-dev/clawd 0.2.596 → 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 +104 -20
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -51818,13 +51818,22 @@ function parseCodexRolloutMeta(firstLine) {
51818
51818
  return obj ? metaFrom(obj) : null;
51819
51819
  }
51820
51820
  function firstUserMessageText(text) {
51821
+ let responseText;
51821
51822
  for (const line of text.split("\n")) {
51822
51823
  const obj = parseLine(line);
51823
- if (!obj || obj.type !== "event_msg") continue;
51824
+ if (!obj) continue;
51824
51825
  const p3 = rec(obj.payload);
51825
- if (p3?.type === "user_message") return str(p3.message);
51826
+ if (obj.type === "event_msg" && p3?.type === "user_message") return str(p3.message);
51827
+ if (!responseText && obj.type === "response_item" && p3?.type === "message" && p3.role === "user" && hasContentKind(p3, "user.text")) responseText = outputText(p3.content) || void 0;
51826
51828
  }
51827
- return void 0;
51829
+ return responseText;
51830
+ }
51831
+ function hasContentKind(payload, kind) {
51832
+ const kinds = rec(payload.internal_chat_message_metadata_passthrough)?.content_item_kinds;
51833
+ return Array.isArray(kinds) && kinds.includes(kind);
51834
+ }
51835
+ function messageTurnId(payload) {
51836
+ return str(rec(payload.internal_chat_message_metadata_passthrough)?.turn_id);
51828
51837
  }
51829
51838
  function outputText(output) {
51830
51839
  if (typeof output === "string") return output;
@@ -51852,8 +51861,21 @@ function functionCallInput(name, rawArgs) {
51852
51861
  }
51853
51862
  function parseCodexRollout(text) {
51854
51863
  const out = { meta: null, messages: [], subagents: [], turns: [] };
51864
+ const lines = text.split("\n");
51855
51865
  const collabCallIds = /* @__PURE__ */ new Set();
51856
- for (const line of text.split("\n")) {
51866
+ const eventTexts = /* @__PURE__ */ new Set();
51867
+ let eventTurnId;
51868
+ for (const line of lines) {
51869
+ const obj = parseLine(line);
51870
+ const p3 = obj && rec(obj.payload);
51871
+ if (!p3 || obj?.type !== "event_msg") continue;
51872
+ if (p3.type === "task_started") eventTurnId = str(p3.turn_id);
51873
+ if (p3.type === "user_message" || p3.type === "agent_message") {
51874
+ const body = str(p3.message);
51875
+ if (body) eventTexts.add(JSON.stringify([eventTurnId, p3.type === "user_message" ? "user" : "assistant", body]));
51876
+ }
51877
+ }
51878
+ for (const line of lines) {
51857
51879
  const obj = parseLine(line);
51858
51880
  if (!obj) continue;
51859
51881
  const ts = str(obj.timestamp);
@@ -51921,6 +51943,15 @@ function parseCodexRollout(text) {
51921
51943
  }
51922
51944
  if (obj.type === "response_item") {
51923
51945
  switch (p3.type) {
51946
+ case "message": {
51947
+ const role = str(p3.role);
51948
+ if (role !== "user" && role !== "assistant") break;
51949
+ if (role === "user" ? !hasContentKind(p3, "user.text") : !Array.isArray(rec(p3.internal_chat_message_metadata_passthrough)?.content_item_kinds)) break;
51950
+ const body = outputText(p3.content);
51951
+ if (!body || eventTexts.has(JSON.stringify([messageTurnId(p3), role, body]))) break;
51952
+ out.messages.push({ kind: role === "user" ? "user-text" : "assistant-text", text: body, raw: obj, ...ts ? { ts } : {} });
51953
+ break;
51954
+ }
51924
51955
  case "function_call": {
51925
51956
  const callId = str(p3.call_id);
51926
51957
  const name = str(p3.name);
@@ -52125,6 +52156,26 @@ function subagentSummaries(parent) {
52125
52156
  }
52126
52157
  return out;
52127
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
+ }
52128
52179
  var CodexHistoryReader = class {
52129
52180
  deps;
52130
52181
  constructor(deps) {
@@ -52177,24 +52228,29 @@ var CodexHistoryReader = class {
52177
52228
  }
52178
52229
  async read(args) {
52179
52230
  const locate = createCodexRolloutLocator(this.deps.roots);
52180
- const parent = this.parseThread(locate, args.toolSessionId);
52181
- const messages = await withSubagentResults(
52182
- parent,
52183
- args.toolSessionId,
52184
- async (agentId) => {
52185
- const file = locate(agentId);
52186
- return file ? import_node_fs15.default.readFileSync(file, "utf8") : null;
52187
- },
52188
- this.deps.logger
52189
- );
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
+ }
52190
52244
  return pageMessages(messages, args);
52191
52245
  }
52192
52246
  async listSubagents(args) {
52193
52247
  return subagentSummaries(this.parseThread(createCodexRolloutLocator(this.deps.roots), args.toolSessionId));
52194
52248
  }
52195
52249
  async readSubagent(args) {
52196
- const child = this.parseThread(createCodexRolloutLocator(this.deps.roots), args.subagentId);
52197
- 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) {
52198
52254
  throw new Error(
52199
52255
  `Codex subagent thread ${args.subagentId} does not belong to parent thread ${args.toolSessionId}`
52200
52256
  );
@@ -52208,9 +52264,37 @@ var CodexHistoryReader = class {
52208
52264
  return [];
52209
52265
  }
52210
52266
  parseThread(locate, threadId) {
52211
- const file = locate(threadId);
52212
- if (!file) throw new Error(`Codex rollout not found for thread ${threadId}`);
52213
- 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
+ }
52214
52298
  }
52215
52299
  };
52216
52300
 
@@ -72875,7 +72959,7 @@ function computeMethodAccess(args) {
72875
72959
  }
72876
72960
 
72877
72961
  // src/version.ts
72878
- var version = "0.2.596".length > 0 ? "0.2.596" : "dev";
72962
+ var version = "0.2.598".length > 0 ? "0.2.598" : "dev";
72879
72963
 
72880
72964
  // src/cli-probe/probe.ts
72881
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.596",
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",