polymath-society 0.2.19 → 0.2.20

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.
@@ -15658,8 +15658,99 @@ function isHarnessEntry(e) {
15658
15658
  return e.isMeta === true || e.isCompactSummary === true;
15659
15659
  }
15660
15660
 
15661
- // ../../lib/agents/coding/materialize.ts
15661
+ // ../coding-core/dist/codex.js
15662
15662
  var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15663
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15664
+ function isCodexInjectedUserText(text2) {
15665
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15666
+ }
15667
+ function codexContentText(content) {
15668
+ if (typeof content === "string")
15669
+ return content;
15670
+ if (!Array.isArray(content))
15671
+ return "";
15672
+ const parts = [];
15673
+ for (const item of content) {
15674
+ if (typeof item === "string") {
15675
+ parts.push(item);
15676
+ continue;
15677
+ }
15678
+ if (item && typeof item === "object") {
15679
+ const it = item;
15680
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15681
+ parts.push(it.text || "");
15682
+ }
15683
+ }
15684
+ return parts.join("\n");
15685
+ }
15686
+ function sniffCodexRaw(raw) {
15687
+ let checked = 0;
15688
+ for (const lineRaw of raw.split("\n")) {
15689
+ const line = lineRaw.trim();
15690
+ if (!line)
15691
+ continue;
15692
+ if (checked++ >= 5)
15693
+ break;
15694
+ try {
15695
+ const e = JSON.parse(line);
15696
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15697
+ return true;
15698
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15699
+ return false;
15700
+ } catch {
15701
+ }
15702
+ }
15703
+ return false;
15704
+ }
15705
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15706
+ function extractCodexEvents(raw) {
15707
+ const out = [];
15708
+ for (const lineRaw of raw.split("\n")) {
15709
+ const line = lineRaw.trim();
15710
+ if (!line)
15711
+ continue;
15712
+ let e;
15713
+ try {
15714
+ e = JSON.parse(line);
15715
+ } catch {
15716
+ continue;
15717
+ }
15718
+ if (e.type !== "response_item")
15719
+ continue;
15720
+ const p = e.payload ?? {};
15721
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15722
+ const ptype = p.type;
15723
+ if (ptype === "message") {
15724
+ const role = p.role;
15725
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE, "").trim();
15726
+ if (!text2)
15727
+ continue;
15728
+ if (role === "user") {
15729
+ if (isCodexInjectedUserText(text2))
15730
+ continue;
15731
+ out.push({ kind: "user", t, text: text2 });
15732
+ } else if (role === "assistant") {
15733
+ out.push({ kind: "assistant", t, text: text2 });
15734
+ }
15735
+ continue;
15736
+ }
15737
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15738
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15739
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15740
+ out.push({ kind: "tool", t, name: name17, input });
15741
+ continue;
15742
+ }
15743
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15744
+ const output = typeof p.output === "string" ? p.output : "";
15745
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15746
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15747
+ }
15748
+ }
15749
+ return out;
15750
+ }
15751
+
15752
+ // ../../lib/agents/coding/materialize.ts
15753
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15663
15754
  var INJECT_GIST = 120;
15664
15755
  var INJECTED = [
15665
15756
  { re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
@@ -15679,7 +15770,7 @@ function collapseInjected(input) {
15679
15770
  return "";
15680
15771
  });
15681
15772
  }
15682
- return { text: text2.replace(SYSTEM_REMINDER_RE, "").trim(), markers };
15773
+ return { text: text2.replace(SYSTEM_REMINDER_RE2, "").trim(), markers };
15683
15774
  }
15684
15775
  function extractText(content) {
15685
15776
  if (typeof content === "string") return content;
@@ -15696,6 +15787,38 @@ function isToolResultOnly(content) {
15696
15787
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15697
15788
  }
15698
15789
  var AI_GIST = 160;
15790
+ function materializeCodex(raw) {
15791
+ const lines = [];
15792
+ let humanTurns = 0, humanChars = 0;
15793
+ let aiLastProse = "";
15794
+ const aiTools = /* @__PURE__ */ new Map();
15795
+ const flushAI = () => {
15796
+ if (!aiLastProse && aiTools.size === 0) return;
15797
+ const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15798
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
15799
+ const bits = [];
15800
+ if (gist) bits.push(gist);
15801
+ if (tools) bits.push(`ran ${tools}`);
15802
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
15803
+ aiLastProse = "";
15804
+ aiTools.clear();
15805
+ };
15806
+ for (const ev of extractCodexEvents(raw)) {
15807
+ if (ev.kind === "user") {
15808
+ flushAI();
15809
+ humanTurns++;
15810
+ humanChars += ev.text.length;
15811
+ lines.push(`>> ${ev.text}`);
15812
+ } else if (ev.kind === "assistant") {
15813
+ const prose = ev.text.replace(/\s+/g, " ").trim();
15814
+ if (prose) aiLastProse = prose;
15815
+ } else if (ev.kind === "tool") {
15816
+ aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
15817
+ }
15818
+ }
15819
+ flushAI();
15820
+ return { text: lines.join("\n"), humanTurns, humanChars };
15821
+ }
15699
15822
  async function materializeSession(file2) {
15700
15823
  let raw;
15701
15824
  try {
@@ -15703,6 +15826,7 @@ async function materializeSession(file2) {
15703
15826
  } catch {
15704
15827
  return null;
15705
15828
  }
15829
+ if (sniffCodexRaw(raw)) return materializeCodex(raw);
15706
15830
  const lines = [];
15707
15831
  let humanTurns = 0, humanChars = 0;
15708
15832
  const pendingQueued = [];
@@ -85,6 +85,97 @@ function isHarnessEntry(e) {
85
85
  return e.isMeta === true || e.isCompactSummary === true;
86
86
  }
87
87
 
88
+ // ../coding-core/dist/codex.js
89
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
90
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
91
+ function isCodexInjectedUserText(text) {
92
+ return CODEX_INJECTED_TEXT_RE.test(text);
93
+ }
94
+ function codexContentText(content) {
95
+ if (typeof content === "string")
96
+ return content;
97
+ if (!Array.isArray(content))
98
+ return "";
99
+ const parts = [];
100
+ for (const item of content) {
101
+ if (typeof item === "string") {
102
+ parts.push(item);
103
+ continue;
104
+ }
105
+ if (item && typeof item === "object") {
106
+ const it = item;
107
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
108
+ parts.push(it.text || "");
109
+ }
110
+ }
111
+ return parts.join("\n");
112
+ }
113
+ function sniffCodexRaw(raw) {
114
+ let checked = 0;
115
+ for (const lineRaw of raw.split("\n")) {
116
+ const line = lineRaw.trim();
117
+ if (!line)
118
+ continue;
119
+ if (checked++ >= 5)
120
+ break;
121
+ try {
122
+ const e = JSON.parse(line);
123
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
124
+ return true;
125
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
126
+ return false;
127
+ } catch {
128
+ }
129
+ }
130
+ return false;
131
+ }
132
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
133
+ function extractCodexEvents(raw) {
134
+ const out = [];
135
+ for (const lineRaw of raw.split("\n")) {
136
+ const line = lineRaw.trim();
137
+ if (!line)
138
+ continue;
139
+ let e;
140
+ try {
141
+ e = JSON.parse(line);
142
+ } catch {
143
+ continue;
144
+ }
145
+ if (e.type !== "response_item")
146
+ continue;
147
+ const p = e.payload ?? {};
148
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
149
+ const ptype = p.type;
150
+ if (ptype === "message") {
151
+ const role = p.role;
152
+ const text = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
153
+ if (!text)
154
+ continue;
155
+ if (role === "user") {
156
+ if (isCodexInjectedUserText(text))
157
+ continue;
158
+ out.push({ kind: "user", t, text });
159
+ } else if (role === "assistant") {
160
+ out.push({ kind: "assistant", t, text });
161
+ }
162
+ continue;
163
+ }
164
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
165
+ const name = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
166
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
167
+ out.push({ kind: "tool", t, name, input });
168
+ continue;
169
+ }
170
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
171
+ const output = typeof p.output === "string" ? p.output : "";
172
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
173
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
174
+ }
175
+ }
176
+ return out;
177
+ }
178
+
88
179
  // ../coding-core/dist/messages.js
89
180
  function extractText(content) {
90
181
  if (typeof content === "string")
@@ -96,6 +187,49 @@ function extractText(content) {
96
187
  function isToolResultOnly(content) {
97
188
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
98
189
  }
190
+ function extractMessagesCodex(raw) {
191
+ const out = [];
192
+ let aiProse = [];
193
+ let aiTools = {};
194
+ let aiStart = 0;
195
+ const flushAI = () => {
196
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
197
+ return;
198
+ const toolStr = Object.entries(aiTools).map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
199
+ let prose = aiProse.join(" ").replace(/\s+/g, " ").trim();
200
+ if (prose.length > 2200)
201
+ prose = prose.slice(0, 2200) + "\u2026";
202
+ let text = prose;
203
+ if (toolStr)
204
+ text = (text ? text + " " : "") + `[ran ${toolStr}]`;
205
+ if (text)
206
+ out.push({ t: aiStart, role: "ai", text });
207
+ aiProse = [];
208
+ aiTools = {};
209
+ };
210
+ for (const ev of extractCodexEvents(raw)) {
211
+ if (!Number.isFinite(ev.t))
212
+ continue;
213
+ if (ev.kind === "user") {
214
+ const text = humanTypedText(ev.text);
215
+ if (text) {
216
+ flushAI();
217
+ out.push({ t: ev.t, role: "user", text });
218
+ }
219
+ } else if (ev.kind === "assistant") {
220
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
221
+ aiStart = ev.t;
222
+ if (ev.text)
223
+ aiProse.push(ev.text);
224
+ } else if (ev.kind === "tool") {
225
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
226
+ aiStart = ev.t;
227
+ aiTools[ev.name] = (aiTools[ev.name] ?? 0) + 1;
228
+ }
229
+ }
230
+ flushAI();
231
+ return out.sort((a, b) => a.t - b.t);
232
+ }
99
233
  async function extractMessages(file) {
100
234
  let raw;
101
235
  try {
@@ -103,6 +237,8 @@ async function extractMessages(file) {
103
237
  } catch {
104
238
  return [];
105
239
  }
240
+ if (sniffCodexRaw(raw))
241
+ return extractMessagesCodex(raw);
106
242
  const out = [];
107
243
  const userTexts = /* @__PURE__ */ new Set();
108
244
  const seenUuids = /* @__PURE__ */ new Set();
@@ -15677,6 +15677,97 @@ function isHarnessEntry(e) {
15677
15677
  return e.isMeta === true || e.isCompactSummary === true;
15678
15678
  }
15679
15679
 
15680
+ // ../coding-core/dist/codex.js
15681
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15682
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15683
+ function isCodexInjectedUserText(text2) {
15684
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15685
+ }
15686
+ function codexContentText(content) {
15687
+ if (typeof content === "string")
15688
+ return content;
15689
+ if (!Array.isArray(content))
15690
+ return "";
15691
+ const parts = [];
15692
+ for (const item of content) {
15693
+ if (typeof item === "string") {
15694
+ parts.push(item);
15695
+ continue;
15696
+ }
15697
+ if (item && typeof item === "object") {
15698
+ const it = item;
15699
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15700
+ parts.push(it.text || "");
15701
+ }
15702
+ }
15703
+ return parts.join("\n");
15704
+ }
15705
+ function sniffCodexRaw(raw) {
15706
+ let checked = 0;
15707
+ for (const lineRaw of raw.split("\n")) {
15708
+ const line = lineRaw.trim();
15709
+ if (!line)
15710
+ continue;
15711
+ if (checked++ >= 5)
15712
+ break;
15713
+ try {
15714
+ const e = JSON.parse(line);
15715
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15716
+ return true;
15717
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15718
+ return false;
15719
+ } catch {
15720
+ }
15721
+ }
15722
+ return false;
15723
+ }
15724
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15725
+ function extractCodexEvents(raw) {
15726
+ const out = [];
15727
+ for (const lineRaw of raw.split("\n")) {
15728
+ const line = lineRaw.trim();
15729
+ if (!line)
15730
+ continue;
15731
+ let e;
15732
+ try {
15733
+ e = JSON.parse(line);
15734
+ } catch {
15735
+ continue;
15736
+ }
15737
+ if (e.type !== "response_item")
15738
+ continue;
15739
+ const p = e.payload ?? {};
15740
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15741
+ const ptype = p.type;
15742
+ if (ptype === "message") {
15743
+ const role = p.role;
15744
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
15745
+ if (!text2)
15746
+ continue;
15747
+ if (role === "user") {
15748
+ if (isCodexInjectedUserText(text2))
15749
+ continue;
15750
+ out.push({ kind: "user", t, text: text2 });
15751
+ } else if (role === "assistant") {
15752
+ out.push({ kind: "assistant", t, text: text2 });
15753
+ }
15754
+ continue;
15755
+ }
15756
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15757
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15758
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15759
+ out.push({ kind: "tool", t, name: name17, input });
15760
+ continue;
15761
+ }
15762
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15763
+ const output = typeof p.output === "string" ? p.output : "";
15764
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15765
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15766
+ }
15767
+ }
15768
+ return out;
15769
+ }
15770
+
15680
15771
  // ../coding-core/dist/messages.js
15681
15772
  function extractText(content) {
15682
15773
  if (typeof content === "string")
@@ -15688,6 +15779,49 @@ function extractText(content) {
15688
15779
  function isToolResultOnly(content) {
15689
15780
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15690
15781
  }
15782
+ function extractMessagesCodex(raw) {
15783
+ const out = [];
15784
+ let aiProse = [];
15785
+ let aiTools = {};
15786
+ let aiStart = 0;
15787
+ const flushAI = () => {
15788
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
15789
+ return;
15790
+ const toolStr = Object.entries(aiTools).map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15791
+ let prose = aiProse.join(" ").replace(/\s+/g, " ").trim();
15792
+ if (prose.length > 2200)
15793
+ prose = prose.slice(0, 2200) + "\u2026";
15794
+ let text2 = prose;
15795
+ if (toolStr)
15796
+ text2 = (text2 ? text2 + " " : "") + `[ran ${toolStr}]`;
15797
+ if (text2)
15798
+ out.push({ t: aiStart, role: "ai", text: text2 });
15799
+ aiProse = [];
15800
+ aiTools = {};
15801
+ };
15802
+ for (const ev of extractCodexEvents(raw)) {
15803
+ if (!Number.isFinite(ev.t))
15804
+ continue;
15805
+ if (ev.kind === "user") {
15806
+ const text2 = humanTypedText(ev.text);
15807
+ if (text2) {
15808
+ flushAI();
15809
+ out.push({ t: ev.t, role: "user", text: text2 });
15810
+ }
15811
+ } else if (ev.kind === "assistant") {
15812
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
15813
+ aiStart = ev.t;
15814
+ if (ev.text)
15815
+ aiProse.push(ev.text);
15816
+ } else if (ev.kind === "tool") {
15817
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
15818
+ aiStart = ev.t;
15819
+ aiTools[ev.name] = (aiTools[ev.name] ?? 0) + 1;
15820
+ }
15821
+ }
15822
+ flushAI();
15823
+ return out.sort((a, b) => a.t - b.t);
15824
+ }
15691
15825
  async function extractMessages(file2) {
15692
15826
  let raw;
15693
15827
  try {
@@ -15695,6 +15829,8 @@ async function extractMessages(file2) {
15695
15829
  } catch {
15696
15830
  return [];
15697
15831
  }
15832
+ if (sniffCodexRaw(raw))
15833
+ return extractMessagesCodex(raw);
15698
15834
  const out = [];
15699
15835
  const userTexts = /* @__PURE__ */ new Set();
15700
15836
  const seenUuids = /* @__PURE__ */ new Set();
@@ -15639,8 +15639,99 @@ function isHarnessEntry(e) {
15639
15639
  return e.isMeta === true || e.isCompactSummary === true;
15640
15640
  }
15641
15641
 
15642
- // ../../lib/agents/coding/materialize.ts
15642
+ // ../coding-core/dist/codex.js
15643
15643
  var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15644
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15645
+ function isCodexInjectedUserText(text2) {
15646
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15647
+ }
15648
+ function codexContentText(content) {
15649
+ if (typeof content === "string")
15650
+ return content;
15651
+ if (!Array.isArray(content))
15652
+ return "";
15653
+ const parts = [];
15654
+ for (const item of content) {
15655
+ if (typeof item === "string") {
15656
+ parts.push(item);
15657
+ continue;
15658
+ }
15659
+ if (item && typeof item === "object") {
15660
+ const it = item;
15661
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15662
+ parts.push(it.text || "");
15663
+ }
15664
+ }
15665
+ return parts.join("\n");
15666
+ }
15667
+ function sniffCodexRaw(raw) {
15668
+ let checked = 0;
15669
+ for (const lineRaw of raw.split("\n")) {
15670
+ const line = lineRaw.trim();
15671
+ if (!line)
15672
+ continue;
15673
+ if (checked++ >= 5)
15674
+ break;
15675
+ try {
15676
+ const e = JSON.parse(line);
15677
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15678
+ return true;
15679
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15680
+ return false;
15681
+ } catch {
15682
+ }
15683
+ }
15684
+ return false;
15685
+ }
15686
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15687
+ function extractCodexEvents(raw) {
15688
+ const out = [];
15689
+ for (const lineRaw of raw.split("\n")) {
15690
+ const line = lineRaw.trim();
15691
+ if (!line)
15692
+ continue;
15693
+ let e;
15694
+ try {
15695
+ e = JSON.parse(line);
15696
+ } catch {
15697
+ continue;
15698
+ }
15699
+ if (e.type !== "response_item")
15700
+ continue;
15701
+ const p = e.payload ?? {};
15702
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15703
+ const ptype = p.type;
15704
+ if (ptype === "message") {
15705
+ const role = p.role;
15706
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE, "").trim();
15707
+ if (!text2)
15708
+ continue;
15709
+ if (role === "user") {
15710
+ if (isCodexInjectedUserText(text2))
15711
+ continue;
15712
+ out.push({ kind: "user", t, text: text2 });
15713
+ } else if (role === "assistant") {
15714
+ out.push({ kind: "assistant", t, text: text2 });
15715
+ }
15716
+ continue;
15717
+ }
15718
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15719
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15720
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15721
+ out.push({ kind: "tool", t, name: name17, input });
15722
+ continue;
15723
+ }
15724
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15725
+ const output = typeof p.output === "string" ? p.output : "";
15726
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15727
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15728
+ }
15729
+ }
15730
+ return out;
15731
+ }
15732
+
15733
+ // ../../lib/agents/coding/materialize.ts
15734
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15644
15735
  var INJECT_GIST = 120;
15645
15736
  var INJECTED = [
15646
15737
  { re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
@@ -15660,7 +15751,7 @@ function collapseInjected(input) {
15660
15751
  return "";
15661
15752
  });
15662
15753
  }
15663
- return { text: text2.replace(SYSTEM_REMINDER_RE, "").trim(), markers };
15754
+ return { text: text2.replace(SYSTEM_REMINDER_RE2, "").trim(), markers };
15664
15755
  }
15665
15756
  function extractText(content) {
15666
15757
  if (typeof content === "string") return content;
@@ -15677,6 +15768,38 @@ function isToolResultOnly(content) {
15677
15768
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15678
15769
  }
15679
15770
  var AI_GIST = 160;
15771
+ function materializeCodex(raw) {
15772
+ const lines = [];
15773
+ let humanTurns = 0, humanChars = 0;
15774
+ let aiLastProse = "";
15775
+ const aiTools = /* @__PURE__ */ new Map();
15776
+ const flushAI = () => {
15777
+ if (!aiLastProse && aiTools.size === 0) return;
15778
+ const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15779
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
15780
+ const bits = [];
15781
+ if (gist) bits.push(gist);
15782
+ if (tools) bits.push(`ran ${tools}`);
15783
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
15784
+ aiLastProse = "";
15785
+ aiTools.clear();
15786
+ };
15787
+ for (const ev of extractCodexEvents(raw)) {
15788
+ if (ev.kind === "user") {
15789
+ flushAI();
15790
+ humanTurns++;
15791
+ humanChars += ev.text.length;
15792
+ lines.push(`>> ${ev.text}`);
15793
+ } else if (ev.kind === "assistant") {
15794
+ const prose = ev.text.replace(/\s+/g, " ").trim();
15795
+ if (prose) aiLastProse = prose;
15796
+ } else if (ev.kind === "tool") {
15797
+ aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
15798
+ }
15799
+ }
15800
+ flushAI();
15801
+ return { text: lines.join("\n"), humanTurns, humanChars };
15802
+ }
15680
15803
  async function materializeSession(file2) {
15681
15804
  let raw;
15682
15805
  try {
@@ -15684,6 +15807,7 @@ async function materializeSession(file2) {
15684
15807
  } catch {
15685
15808
  return null;
15686
15809
  }
15810
+ if (sniffCodexRaw(raw)) return materializeCodex(raw);
15687
15811
  const lines = [];
15688
15812
  let humanTurns = 0, humanChars = 0;
15689
15813
  const pendingQueued = [];