polymath-society 0.2.18 → 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.
@@ -15788,8 +15788,99 @@ function isHarnessEntry(e) {
15788
15788
  return e.isMeta === true || e.isCompactSummary === true;
15789
15789
  }
15790
15790
 
15791
- // ../../lib/agents/coding/materialize.ts
15791
+ // ../coding-core/dist/codex.js
15792
15792
  var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15793
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15794
+ function isCodexInjectedUserText(text2) {
15795
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15796
+ }
15797
+ function codexContentText(content) {
15798
+ if (typeof content === "string")
15799
+ return content;
15800
+ if (!Array.isArray(content))
15801
+ return "";
15802
+ const parts = [];
15803
+ for (const item of content) {
15804
+ if (typeof item === "string") {
15805
+ parts.push(item);
15806
+ continue;
15807
+ }
15808
+ if (item && typeof item === "object") {
15809
+ const it = item;
15810
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15811
+ parts.push(it.text || "");
15812
+ }
15813
+ }
15814
+ return parts.join("\n");
15815
+ }
15816
+ function sniffCodexRaw(raw) {
15817
+ let checked = 0;
15818
+ for (const lineRaw of raw.split("\n")) {
15819
+ const line = lineRaw.trim();
15820
+ if (!line)
15821
+ continue;
15822
+ if (checked++ >= 5)
15823
+ break;
15824
+ try {
15825
+ const e = JSON.parse(line);
15826
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15827
+ return true;
15828
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15829
+ return false;
15830
+ } catch {
15831
+ }
15832
+ }
15833
+ return false;
15834
+ }
15835
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15836
+ function extractCodexEvents(raw) {
15837
+ const out = [];
15838
+ for (const lineRaw of raw.split("\n")) {
15839
+ const line = lineRaw.trim();
15840
+ if (!line)
15841
+ continue;
15842
+ let e;
15843
+ try {
15844
+ e = JSON.parse(line);
15845
+ } catch {
15846
+ continue;
15847
+ }
15848
+ if (e.type !== "response_item")
15849
+ continue;
15850
+ const p = e.payload ?? {};
15851
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15852
+ const ptype = p.type;
15853
+ if (ptype === "message") {
15854
+ const role = p.role;
15855
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE, "").trim();
15856
+ if (!text2)
15857
+ continue;
15858
+ if (role === "user") {
15859
+ if (isCodexInjectedUserText(text2))
15860
+ continue;
15861
+ out.push({ kind: "user", t, text: text2 });
15862
+ } else if (role === "assistant") {
15863
+ out.push({ kind: "assistant", t, text: text2 });
15864
+ }
15865
+ continue;
15866
+ }
15867
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15868
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15869
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15870
+ out.push({ kind: "tool", t, name: name17, input });
15871
+ continue;
15872
+ }
15873
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15874
+ const output = typeof p.output === "string" ? p.output : "";
15875
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15876
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15877
+ }
15878
+ }
15879
+ return out;
15880
+ }
15881
+
15882
+ // ../../lib/agents/coding/materialize.ts
15883
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15793
15884
  var INJECT_GIST = 120;
15794
15885
  var INJECTED = [
15795
15886
  { re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
@@ -15809,7 +15900,7 @@ function collapseInjected(input) {
15809
15900
  return "";
15810
15901
  });
15811
15902
  }
15812
- return { text: text2.replace(SYSTEM_REMINDER_RE, "").trim(), markers };
15903
+ return { text: text2.replace(SYSTEM_REMINDER_RE2, "").trim(), markers };
15813
15904
  }
15814
15905
  function extractText(content) {
15815
15906
  if (typeof content === "string") return content;
@@ -15826,6 +15917,38 @@ function isToolResultOnly(content) {
15826
15917
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15827
15918
  }
15828
15919
  var AI_GIST = 160;
15920
+ function materializeCodex(raw) {
15921
+ const lines = [];
15922
+ let humanTurns = 0, humanChars = 0;
15923
+ let aiLastProse = "";
15924
+ const aiTools = /* @__PURE__ */ new Map();
15925
+ const flushAI = () => {
15926
+ if (!aiLastProse && aiTools.size === 0) return;
15927
+ const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15928
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
15929
+ const bits = [];
15930
+ if (gist) bits.push(gist);
15931
+ if (tools) bits.push(`ran ${tools}`);
15932
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
15933
+ aiLastProse = "";
15934
+ aiTools.clear();
15935
+ };
15936
+ for (const ev of extractCodexEvents(raw)) {
15937
+ if (ev.kind === "user") {
15938
+ flushAI();
15939
+ humanTurns++;
15940
+ humanChars += ev.text.length;
15941
+ lines.push(`>> ${ev.text}`);
15942
+ } else if (ev.kind === "assistant") {
15943
+ const prose = ev.text.replace(/\s+/g, " ").trim();
15944
+ if (prose) aiLastProse = prose;
15945
+ } else if (ev.kind === "tool") {
15946
+ aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
15947
+ }
15948
+ }
15949
+ flushAI();
15950
+ return { text: lines.join("\n"), humanTurns, humanChars };
15951
+ }
15829
15952
  async function materializeSession(file2) {
15830
15953
  let raw;
15831
15954
  try {
@@ -15833,6 +15956,7 @@ async function materializeSession(file2) {
15833
15956
  } catch {
15834
15957
  return null;
15835
15958
  }
15959
+ if (sniffCodexRaw(raw)) return materializeCodex(raw);
15836
15960
  const lines = [];
15837
15961
  let humanTurns = 0, humanChars = 0;
15838
15962
  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")
@@ -106,6 +197,49 @@ function createMessageDeduper() {
106
197
  return true;
107
198
  };
108
199
  }
200
+ function extractMessagesCodex(raw) {
201
+ const out = [];
202
+ let aiProse = [];
203
+ let aiTools = {};
204
+ let aiStart = 0;
205
+ const flushAI = () => {
206
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
207
+ return;
208
+ const toolStr = Object.entries(aiTools).map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
209
+ let prose = aiProse.join(" ").replace(/\s+/g, " ").trim();
210
+ if (prose.length > 2200)
211
+ prose = prose.slice(0, 2200) + "\u2026";
212
+ let text = prose;
213
+ if (toolStr)
214
+ text = (text ? text + " " : "") + `[ran ${toolStr}]`;
215
+ if (text)
216
+ out.push({ t: aiStart, role: "ai", text });
217
+ aiProse = [];
218
+ aiTools = {};
219
+ };
220
+ for (const ev of extractCodexEvents(raw)) {
221
+ if (!Number.isFinite(ev.t))
222
+ continue;
223
+ if (ev.kind === "user") {
224
+ const text = humanTypedText(ev.text);
225
+ if (text) {
226
+ flushAI();
227
+ out.push({ t: ev.t, role: "user", text });
228
+ }
229
+ } else if (ev.kind === "assistant") {
230
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
231
+ aiStart = ev.t;
232
+ if (ev.text)
233
+ aiProse.push(ev.text);
234
+ } else if (ev.kind === "tool") {
235
+ if (!aiProse.length && Object.keys(aiTools).length === 0)
236
+ aiStart = ev.t;
237
+ aiTools[ev.name] = (aiTools[ev.name] ?? 0) + 1;
238
+ }
239
+ }
240
+ flushAI();
241
+ return out.sort((a, b) => a.t - b.t);
242
+ }
109
243
  async function extractMessages(file) {
110
244
  let raw;
111
245
  try {
@@ -113,6 +247,8 @@ async function extractMessages(file) {
113
247
  } catch {
114
248
  return [];
115
249
  }
250
+ if (sniffCodexRaw(raw))
251
+ return extractMessagesCodex(raw);
116
252
  const out = [];
117
253
  const userTexts = /* @__PURE__ */ new Set();
118
254
  const seenUuids = /* @__PURE__ */ new Set();
@@ -42,6 +42,97 @@ function isHarnessEntry(e) {
42
42
  return e.isMeta === true || e.isCompactSummary === true;
43
43
  }
44
44
 
45
+ // ../coding-core/dist/codex.js
46
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
47
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
48
+ function isCodexInjectedUserText(text) {
49
+ return CODEX_INJECTED_TEXT_RE.test(text);
50
+ }
51
+ function codexContentText(content) {
52
+ if (typeof content === "string")
53
+ return content;
54
+ if (!Array.isArray(content))
55
+ return "";
56
+ const parts = [];
57
+ for (const item of content) {
58
+ if (typeof item === "string") {
59
+ parts.push(item);
60
+ continue;
61
+ }
62
+ if (item && typeof item === "object") {
63
+ const it = item;
64
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
65
+ parts.push(it.text || "");
66
+ }
67
+ }
68
+ return parts.join("\n");
69
+ }
70
+ function sniffCodexRaw(raw) {
71
+ let checked = 0;
72
+ for (const lineRaw of raw.split("\n")) {
73
+ const line = lineRaw.trim();
74
+ if (!line)
75
+ continue;
76
+ if (checked++ >= 5)
77
+ break;
78
+ try {
79
+ const e = JSON.parse(line);
80
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
81
+ return true;
82
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
83
+ return false;
84
+ } catch {
85
+ }
86
+ }
87
+ return false;
88
+ }
89
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
90
+ function extractCodexEvents(raw) {
91
+ const out = [];
92
+ for (const lineRaw of raw.split("\n")) {
93
+ const line = lineRaw.trim();
94
+ if (!line)
95
+ continue;
96
+ let e;
97
+ try {
98
+ e = JSON.parse(line);
99
+ } catch {
100
+ continue;
101
+ }
102
+ if (e.type !== "response_item")
103
+ continue;
104
+ const p = e.payload ?? {};
105
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
106
+ const ptype = p.type;
107
+ if (ptype === "message") {
108
+ const role = p.role;
109
+ const text = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
110
+ if (!text)
111
+ continue;
112
+ if (role === "user") {
113
+ if (isCodexInjectedUserText(text))
114
+ continue;
115
+ out.push({ kind: "user", t, text });
116
+ } else if (role === "assistant") {
117
+ out.push({ kind: "assistant", t, text });
118
+ }
119
+ continue;
120
+ }
121
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
122
+ const name = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
123
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
124
+ out.push({ kind: "tool", t, name, input });
125
+ continue;
126
+ }
127
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
128
+ const output = typeof p.output === "string" ? p.output : "";
129
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
130
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
131
+ }
132
+ }
133
+ return out;
134
+ }
135
+
45
136
  // ../coding-core/dist/raw.js
46
137
  var SOURCE_ROOT_ENV_VARS = [
47
138
  "CLAUDE_PROJECTS_DIR",
@@ -292,7 +383,6 @@ function codexText(content) {
292
383
  }
293
384
  return "";
294
385
  }
295
- var CODEX_INJECTED_RE = /^\s*<(environment_context|user_instructions)>/;
296
386
  function parseCodex(raw, file) {
297
387
  let sessionId = path.basename(file, ".jsonl");
298
388
  const s = blank(sessionId, "codex", file);
@@ -332,7 +422,7 @@ function parseCodex(raw, file) {
332
422
  const role = p.role;
333
423
  const text = codexText(p.content).replace(SYSTEM_REMINDER_RE, "").trim();
334
424
  if (role === "user") {
335
- if (text && !CODEX_INJECTED_RE.test(text)) {
425
+ if (text && !isCodexInjectedUserText(text)) {
336
426
  s.humanTurns++;
337
427
  s.humanChars += text.length;
338
428
  if (!s.firstHuman)
@@ -1007,6 +1097,22 @@ function extractText2(content) {
1007
1097
  function isToolResultOnly(content) {
1008
1098
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
1009
1099
  }
1100
+ function extractUserMessagesCodex(raw) {
1101
+ const out = [];
1102
+ let lastTs = null;
1103
+ for (const ev of extractCodexEvents(raw)) {
1104
+ const t = ev.t;
1105
+ const gapMs = Number.isFinite(t) && lastTs != null ? t - lastTs : NaN;
1106
+ if (Number.isFinite(t))
1107
+ lastTs = t;
1108
+ if (ev.kind !== "user")
1109
+ continue;
1110
+ const text = humanTypedText(ev.text);
1111
+ if (text && Number.isFinite(t))
1112
+ out.push({ t, text, gapMs });
1113
+ }
1114
+ return out.sort((a, b) => a.t - b.t);
1115
+ }
1010
1116
  async function extractUserMessages(file) {
1011
1117
  let raw;
1012
1118
  try {
@@ -1014,6 +1120,8 @@ async function extractUserMessages(file) {
1014
1120
  } catch {
1015
1121
  return [];
1016
1122
  }
1123
+ if (sniffCodexRaw(raw))
1124
+ return extractUserMessagesCodex(raw);
1017
1125
  const out = [];
1018
1126
  const userTexts = /* @__PURE__ */ new Set();
1019
1127
  const seenUuids = /* @__PURE__ */ new Set();
@@ -1451,15 +1559,21 @@ var GRADES = path2.join(CODING_DIR, "grades");
1451
1559
  // ../../scripts/coding-build.mts
1452
1560
  var args = process.argv.slice(2);
1453
1561
  var codex = !args.includes("--no-codex");
1562
+ var claude = !args.includes("--no-claude");
1454
1563
  var idleGapMin = Number(args[args.indexOf("--idle") + 1]) || DEFAULT_IDLE_GAP_MIN;
1455
1564
  var OUT = CODING_DIR;
1456
1565
  function fmt(n) {
1457
1566
  return n.toLocaleString("en-US");
1458
1567
  }
1459
1568
  async function main() {
1460
- console.log(`[coding] reading raw logs (codex=${codex}, idleGap=${idleGapMin}m, tz=${DEFAULT_TZ}) \u2026`);
1569
+ console.log(`[coding] reading raw logs (claude=${claude}, codex=${codex}, idleGap=${idleGapMin}m, tz=${DEFAULT_TZ}) \u2026`);
1461
1570
  const t0 = Date.now();
1462
- const raw = await readAllSessions({ codex });
1571
+ let raw = await readAllSessions({ codex });
1572
+ if (!claude) {
1573
+ const dropped = raw.filter((s) => s.source === "claude-code").length;
1574
+ raw = raw.filter((s) => s.source !== "claude-code");
1575
+ console.log(`[coding] \u26D4 Claude Code EXCLUDED (--no-claude, consent) \u2014 ${dropped} session file(s) dropped before any analysis.`);
1576
+ }
1463
1577
  console.log(`[coding] parsed ${fmt(raw.length)} sessions in ${((Date.now() - t0) / 1e3).toFixed(1)}s`);
1464
1578
  const interactive = raw.filter((s) => s.klass === "interactive");
1465
1579
  const agent = raw.filter((s) => s.klass === "agent");