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.
- package/dist/cli.js +503 -167
- package/dist/index.js +418 -140
- package/dist/pipeline/FOCUS-EXAMPLES.md +127 -0
- package/dist/pipeline/FOCUS-RUBRIC.md +418 -0
- package/dist/pipeline/coding-agglomerate.js +126 -2
- package/dist/pipeline/coding-aggregate.js +136 -0
- package/dist/pipeline/coding-build.js +118 -4
- package/dist/pipeline/coding-coaching.js +173 -14
- package/dist/pipeline/coding-day-digest.js +109 -0
- package/dist/pipeline/coding-delegation.js +189 -17
- package/dist/pipeline/coding-expertise.js +126 -2
- package/dist/pipeline/coding-flow.js +136 -0
- package/dist/pipeline/coding-focus.js +136 -0
- package/dist/pipeline/coding-frontier-detail.js +126 -2
- package/dist/pipeline/coding-gap-dist.js +136 -0
- package/dist/pipeline/coding-gap.js +182 -16
- package/dist/pipeline/coding-grade.js +132 -2
- package/dist/pipeline/coding-nutshell.js +159 -150
- package/dist/pipeline/coding-walkthrough.js +144 -0
- package/dist/web/app.js +59 -19
- package/package.json +1 -1
|
@@ -15810,6 +15810,97 @@ function isHarnessEntry(e) {
|
|
|
15810
15810
|
return e.isMeta === true || e.isCompactSummary === true;
|
|
15811
15811
|
}
|
|
15812
15812
|
|
|
15813
|
+
// ../coding-core/dist/codex.js
|
|
15814
|
+
var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
15815
|
+
var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
|
|
15816
|
+
function isCodexInjectedUserText(text2) {
|
|
15817
|
+
return CODEX_INJECTED_TEXT_RE.test(text2);
|
|
15818
|
+
}
|
|
15819
|
+
function codexContentText(content) {
|
|
15820
|
+
if (typeof content === "string")
|
|
15821
|
+
return content;
|
|
15822
|
+
if (!Array.isArray(content))
|
|
15823
|
+
return "";
|
|
15824
|
+
const parts = [];
|
|
15825
|
+
for (const item of content) {
|
|
15826
|
+
if (typeof item === "string") {
|
|
15827
|
+
parts.push(item);
|
|
15828
|
+
continue;
|
|
15829
|
+
}
|
|
15830
|
+
if (item && typeof item === "object") {
|
|
15831
|
+
const it = item;
|
|
15832
|
+
if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
|
|
15833
|
+
parts.push(it.text || "");
|
|
15834
|
+
}
|
|
15835
|
+
}
|
|
15836
|
+
return parts.join("\n");
|
|
15837
|
+
}
|
|
15838
|
+
function sniffCodexRaw(raw) {
|
|
15839
|
+
let checked = 0;
|
|
15840
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15841
|
+
const line = lineRaw.trim();
|
|
15842
|
+
if (!line)
|
|
15843
|
+
continue;
|
|
15844
|
+
if (checked++ >= 5)
|
|
15845
|
+
break;
|
|
15846
|
+
try {
|
|
15847
|
+
const e = JSON.parse(line);
|
|
15848
|
+
if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
|
|
15849
|
+
return true;
|
|
15850
|
+
if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
|
|
15851
|
+
return false;
|
|
15852
|
+
} catch {
|
|
15853
|
+
}
|
|
15854
|
+
}
|
|
15855
|
+
return false;
|
|
15856
|
+
}
|
|
15857
|
+
var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
|
|
15858
|
+
function extractCodexEvents(raw) {
|
|
15859
|
+
const out = [];
|
|
15860
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15861
|
+
const line = lineRaw.trim();
|
|
15862
|
+
if (!line)
|
|
15863
|
+
continue;
|
|
15864
|
+
let e;
|
|
15865
|
+
try {
|
|
15866
|
+
e = JSON.parse(line);
|
|
15867
|
+
} catch {
|
|
15868
|
+
continue;
|
|
15869
|
+
}
|
|
15870
|
+
if (e.type !== "response_item")
|
|
15871
|
+
continue;
|
|
15872
|
+
const p = e.payload ?? {};
|
|
15873
|
+
const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
|
|
15874
|
+
const ptype = p.type;
|
|
15875
|
+
if (ptype === "message") {
|
|
15876
|
+
const role = p.role;
|
|
15877
|
+
const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
|
|
15878
|
+
if (!text2)
|
|
15879
|
+
continue;
|
|
15880
|
+
if (role === "user") {
|
|
15881
|
+
if (isCodexInjectedUserText(text2))
|
|
15882
|
+
continue;
|
|
15883
|
+
out.push({ kind: "user", t, text: text2 });
|
|
15884
|
+
} else if (role === "assistant") {
|
|
15885
|
+
out.push({ kind: "assistant", t, text: text2 });
|
|
15886
|
+
}
|
|
15887
|
+
continue;
|
|
15888
|
+
}
|
|
15889
|
+
if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
|
|
15890
|
+
const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
|
|
15891
|
+
const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
|
|
15892
|
+
out.push({ kind: "tool", t, name: name17, input });
|
|
15893
|
+
continue;
|
|
15894
|
+
}
|
|
15895
|
+
if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
|
|
15896
|
+
const output = typeof p.output === "string" ? p.output : "";
|
|
15897
|
+
const m = EXIT_CODE_RE.exec(output.slice(0, 200));
|
|
15898
|
+
out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
|
|
15899
|
+
}
|
|
15900
|
+
}
|
|
15901
|
+
return out;
|
|
15902
|
+
}
|
|
15903
|
+
|
|
15813
15904
|
// ../coding-core/dist/messages.js
|
|
15814
15905
|
function extractText(content) {
|
|
15815
15906
|
if (typeof content === "string")
|
|
@@ -15821,6 +15912,22 @@ function extractText(content) {
|
|
|
15821
15912
|
function isToolResultOnly(content) {
|
|
15822
15913
|
return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
|
|
15823
15914
|
}
|
|
15915
|
+
function extractUserMessagesCodex(raw) {
|
|
15916
|
+
const out = [];
|
|
15917
|
+
let lastTs = null;
|
|
15918
|
+
for (const ev of extractCodexEvents(raw)) {
|
|
15919
|
+
const t = ev.t;
|
|
15920
|
+
const gapMs = Number.isFinite(t) && lastTs != null ? t - lastTs : NaN;
|
|
15921
|
+
if (Number.isFinite(t))
|
|
15922
|
+
lastTs = t;
|
|
15923
|
+
if (ev.kind !== "user")
|
|
15924
|
+
continue;
|
|
15925
|
+
const text2 = humanTypedText(ev.text);
|
|
15926
|
+
if (text2 && Number.isFinite(t))
|
|
15927
|
+
out.push({ t, text: text2, gapMs });
|
|
15928
|
+
}
|
|
15929
|
+
return out.sort((a, b) => a.t - b.t);
|
|
15930
|
+
}
|
|
15824
15931
|
async function extractUserMessages(file2) {
|
|
15825
15932
|
let raw;
|
|
15826
15933
|
try {
|
|
@@ -15828,6 +15935,8 @@ async function extractUserMessages(file2) {
|
|
|
15828
15935
|
} catch {
|
|
15829
15936
|
return [];
|
|
15830
15937
|
}
|
|
15938
|
+
if (sniffCodexRaw(raw))
|
|
15939
|
+
return extractUserMessagesCodex(raw);
|
|
15831
15940
|
const out = [];
|
|
15832
15941
|
const userTexts = /* @__PURE__ */ new Set();
|
|
15833
15942
|
const seenUuids = /* @__PURE__ */ new Set();
|
|
@@ -16487,6 +16596,18 @@ function distOf(takes) {
|
|
|
16487
16596
|
const hist = [...h.keys()].sort((a, b) => b - a).map((level) => ({ level, count: h.get(level) }));
|
|
16488
16597
|
return { n, observed, mean, median: median2, hist };
|
|
16489
16598
|
}
|
|
16599
|
+
var phi = (z) => {
|
|
16600
|
+
const t = 1 / (1 + 0.2316419 * Math.abs(z));
|
|
16601
|
+
const d = 0.3989423 * Math.exp(-z * z / 2);
|
|
16602
|
+
let pr = d * t * (0.3193815 + t * (-0.3565638 + t * (1.781478 + t * (-1.821256 + t * 1.330274))));
|
|
16603
|
+
if (z > 0) pr = 1 - pr;
|
|
16604
|
+
return pr;
|
|
16605
|
+
};
|
|
16606
|
+
var lognPct = (x, c) => x == null || !c || x <= 0 ? null : Math.min(99.9, Math.max(0.1, Math.round(phi(Math.log(x / c.median) / c.sigma) * 1e3) / 10));
|
|
16607
|
+
var NO_GRADES_GAP = "no sessions graded for this yet \u2014 this fills in once grading has run";
|
|
16608
|
+
function estimateRowParts(score, nTakes, evidenceGap) {
|
|
16609
|
+
return nTakes === 0 && score == null ? { score: null, gap: NO_GRADES_GAP } : { score, gap: evidenceGap };
|
|
16610
|
+
}
|
|
16490
16611
|
async function compileCodingProfile() {
|
|
16491
16612
|
const allRecords = await readJson(path10.join(CODING_DIR, "sessions.json"), []);
|
|
16492
16613
|
const dupIds = new Set(allRecords.filter((s) => s.duplicateOf).map((s) => s.sessionId));
|
|
@@ -16741,15 +16862,11 @@ async function compileCodingProfile() {
|
|
|
16741
16862
|
const unb = ceilOf("unblocking");
|
|
16742
16863
|
const agency = out2 != null && unb != null ? Math.round((out2 + unb) / 2) : out2 ?? unb;
|
|
16743
16864
|
const sRow = (label, score, gap2) => ({ label, score, percentile: pctOf(score), gap: gap2 });
|
|
16744
|
-
const
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
const d = 0.3989423 * Math.exp(-z * z / 2);
|
|
16748
|
-
let pr = d * t * (0.3193815 + t * (-0.3565638 + t * (1.781478 + t * (-1.821256 + t * 1.330274))));
|
|
16749
|
-
if (z > 0) pr = 1 - pr;
|
|
16750
|
-
return pr;
|
|
16865
|
+
const est = (label, score, key, evidenceGap) => {
|
|
16866
|
+
const e = estimateRowParts(score, nTk(key), evidenceGap);
|
|
16867
|
+
return sRow(label, e.score, e.gap);
|
|
16751
16868
|
};
|
|
16752
|
-
const
|
|
16869
|
+
const tiers = DEFAULT_CALIBRATION.codingTiers;
|
|
16753
16870
|
const avgWords = aggregate?.throughput?.avgWordsPerDay ?? null;
|
|
16754
16871
|
const pushPctl = lognPct(avgWords, tiers?.push);
|
|
16755
16872
|
const focusPctl = lognPct(flowPctDay, tiers?.focus);
|
|
@@ -16768,10 +16885,16 @@ async function compileCodingProfile() {
|
|
|
16768
16885
|
null,
|
|
16769
16886
|
workDayHrs != null ? `~${workDayHrs}h of active building on a typical work day \u2014 engaged builders average ~3h, and sustaining 7h+ day after day, week after week, is top-1% territory` : "not enough dated activity yet to measure a typical work day"
|
|
16770
16887
|
),
|
|
16888
|
+
// The copy FOLLOWS the person's actual orchestration band (orchPctl above) —
|
|
16889
|
+
// a hardcoded "single biggest speed-up still on the table" once shipped to a
|
|
16890
|
+
// user at orchPctl 99.5 (18 agents peak, 48% of hours at 2+), flatly
|
|
16891
|
+
// contradicting the gap section's "already strong" on the same page
|
|
16892
|
+
// (2026-07-17). The still-on-the-table claim is reserved for genuinely low
|
|
16893
|
+
// orchestration.
|
|
16771
16894
|
sRow(
|
|
16772
16895
|
"Your AI parallelism",
|
|
16773
16896
|
ceilOf("delegation"),
|
|
16774
|
-
soloPct != null ? `~${soloPct}% of your hours you drive a single agent (${Math.round(soloMin / 60)}h solo vs ${Math.round(parMin / 60)}h with 2+ live) \u2014 the Claude Code lead keeps 10\u201315 going at once, so this is the single biggest speed-up still on the table` : "you brief the AI sharply, but mostly drive one agent at a time \u2014 the top run 10\u201315 in parallel, a several-fold speed-up"
|
|
16897
|
+
soloPct != null ? orchPctl >= 97 ? `you already run parallel at the frontier \u2014 ${Math.round(parMin / 60)}h of your hours with 2+ agents live vs ${Math.round(soloMin / 60)}h solo; the Claude Code lead keeps 10\u201315 going at once, and you work the same way` : `~${soloPct}% of your hours you drive a single agent (${Math.round(soloMin / 60)}h solo vs ${Math.round(parMin / 60)}h with 2+ live) \u2014 the Claude Code lead keeps 10\u201315 going at once, so this is the single biggest speed-up still on the table` : "you brief the AI sharply, but mostly drive one agent at a time \u2014 the top run 10\u201315 in parallel, a several-fold speed-up"
|
|
16775
16898
|
),
|
|
16776
16899
|
// The evidence line cites the RANKING metric (flow as a share of the work
|
|
16777
16900
|
// day), never absolute hours — a friend with MORE flow hours over a longer
|
|
@@ -16787,22 +16910,25 @@ async function compileCodingProfile() {
|
|
|
16787
16910
|
// The four estimates LEAD with a concrete moment from their own sessions, then an
|
|
16788
16911
|
// HONEST caveat — how many graded sessions back the read. No invented weakness, no
|
|
16789
16912
|
// claim about what they "didn't" do (false specifics churn a real user); it's an estimate.
|
|
16790
|
-
|
|
16913
|
+
est(
|
|
16791
16914
|
"Agency",
|
|
16792
16915
|
agency,
|
|
16916
|
+
"outcomes",
|
|
16793
16917
|
`${proud("outcomes", "you ship working systems and unblock yourself")} \u2014 one of ${nTk("outcomes")} sessions behind this read; a strong, consistent signal, still an estimate from your logs`
|
|
16794
16918
|
),
|
|
16795
16919
|
// Judgement/Taste use the SAME numbers their ability cards prove (aggregate
|
|
16796
16920
|
// peak-with-consistency over near-peak instances) — a chip saying "top 1%"
|
|
16797
16921
|
// above a card proving 10/Top 0.1% with ten receipts reads as a bug.
|
|
16798
|
-
|
|
16922
|
+
est(
|
|
16799
16923
|
"Judgement",
|
|
16800
16924
|
aggregate?.ability?.abstraction?.score ?? ceilOf("generative"),
|
|
16925
|
+
"generative",
|
|
16801
16926
|
`${proud("generative", "you make sharp, non-obvious calls on what actually matters")} \u2014 one of ${nTk("generative")} sessions we've graded for this; clear so far, not yet a final verdict`
|
|
16802
16927
|
),
|
|
16803
|
-
|
|
16928
|
+
est(
|
|
16804
16929
|
"Taste",
|
|
16805
16930
|
aggregate?.ability?.taste?.score ?? ceilOf("taste"),
|
|
16931
|
+
"taste",
|
|
16806
16932
|
`${proud("taste", "you hold a high, opinionated quality bar")} \u2014 one of ${nTk("taste")} sessions behind this read; a real signal, still an estimate`
|
|
16807
16933
|
)
|
|
16808
16934
|
// Expertise: NO chip — the scored criterion is deprecated; the real judge is
|
|
@@ -16859,7 +16985,7 @@ import path12 from "path";
|
|
|
16859
16985
|
|
|
16860
16986
|
// ../../lib/agents/coding/materialize.ts
|
|
16861
16987
|
import { promises as fs8 } from "fs";
|
|
16862
|
-
var
|
|
16988
|
+
var SYSTEM_REMINDER_RE3 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
16863
16989
|
var INJECT_GIST = 120;
|
|
16864
16990
|
var INJECTED = [
|
|
16865
16991
|
{ re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
|
|
@@ -16879,7 +17005,7 @@ function collapseInjected(input) {
|
|
|
16879
17005
|
return "";
|
|
16880
17006
|
});
|
|
16881
17007
|
}
|
|
16882
|
-
return { text: text2.replace(
|
|
17008
|
+
return { text: text2.replace(SYSTEM_REMINDER_RE3, "").trim(), markers };
|
|
16883
17009
|
}
|
|
16884
17010
|
function extractText2(content) {
|
|
16885
17011
|
if (typeof content === "string") return content;
|
|
@@ -16896,6 +17022,38 @@ function isToolResultOnly2(content) {
|
|
|
16896
17022
|
return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
|
|
16897
17023
|
}
|
|
16898
17024
|
var AI_GIST = 160;
|
|
17025
|
+
function materializeCodex(raw) {
|
|
17026
|
+
const lines = [];
|
|
17027
|
+
let humanTurns = 0, humanChars = 0;
|
|
17028
|
+
let aiLastProse = "";
|
|
17029
|
+
const aiTools = /* @__PURE__ */ new Map();
|
|
17030
|
+
const flushAI = () => {
|
|
17031
|
+
if (!aiLastProse && aiTools.size === 0) return;
|
|
17032
|
+
const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
|
|
17033
|
+
const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
|
|
17034
|
+
const bits = [];
|
|
17035
|
+
if (gist) bits.push(gist);
|
|
17036
|
+
if (tools) bits.push(`ran ${tools}`);
|
|
17037
|
+
lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
|
|
17038
|
+
aiLastProse = "";
|
|
17039
|
+
aiTools.clear();
|
|
17040
|
+
};
|
|
17041
|
+
for (const ev of extractCodexEvents(raw)) {
|
|
17042
|
+
if (ev.kind === "user") {
|
|
17043
|
+
flushAI();
|
|
17044
|
+
humanTurns++;
|
|
17045
|
+
humanChars += ev.text.length;
|
|
17046
|
+
lines.push(`>> ${ev.text}`);
|
|
17047
|
+
} else if (ev.kind === "assistant") {
|
|
17048
|
+
const prose = ev.text.replace(/\s+/g, " ").trim();
|
|
17049
|
+
if (prose) aiLastProse = prose;
|
|
17050
|
+
} else if (ev.kind === "tool") {
|
|
17051
|
+
aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
|
|
17052
|
+
}
|
|
17053
|
+
}
|
|
17054
|
+
flushAI();
|
|
17055
|
+
return { text: lines.join("\n"), humanTurns, humanChars };
|
|
17056
|
+
}
|
|
16899
17057
|
async function materializeSession(file2) {
|
|
16900
17058
|
let raw;
|
|
16901
17059
|
try {
|
|
@@ -16903,6 +17061,7 @@ async function materializeSession(file2) {
|
|
|
16903
17061
|
} catch {
|
|
16904
17062
|
return null;
|
|
16905
17063
|
}
|
|
17064
|
+
if (sniffCodexRaw(raw)) return materializeCodex(raw);
|
|
16906
17065
|
const lines = [];
|
|
16907
17066
|
let humanTurns = 0, humanChars = 0;
|
|
16908
17067
|
const pendingQueued = [];
|
|
@@ -15694,6 +15694,97 @@ function isHarnessEntry(e) {
|
|
|
15694
15694
|
return e.isMeta === true || e.isCompactSummary === true;
|
|
15695
15695
|
}
|
|
15696
15696
|
|
|
15697
|
+
// ../coding-core/dist/codex.js
|
|
15698
|
+
var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
15699
|
+
var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
|
|
15700
|
+
function isCodexInjectedUserText(text2) {
|
|
15701
|
+
return CODEX_INJECTED_TEXT_RE.test(text2);
|
|
15702
|
+
}
|
|
15703
|
+
function codexContentText(content) {
|
|
15704
|
+
if (typeof content === "string")
|
|
15705
|
+
return content;
|
|
15706
|
+
if (!Array.isArray(content))
|
|
15707
|
+
return "";
|
|
15708
|
+
const parts = [];
|
|
15709
|
+
for (const item of content) {
|
|
15710
|
+
if (typeof item === "string") {
|
|
15711
|
+
parts.push(item);
|
|
15712
|
+
continue;
|
|
15713
|
+
}
|
|
15714
|
+
if (item && typeof item === "object") {
|
|
15715
|
+
const it = item;
|
|
15716
|
+
if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
|
|
15717
|
+
parts.push(it.text || "");
|
|
15718
|
+
}
|
|
15719
|
+
}
|
|
15720
|
+
return parts.join("\n");
|
|
15721
|
+
}
|
|
15722
|
+
function sniffCodexRaw(raw) {
|
|
15723
|
+
let checked = 0;
|
|
15724
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15725
|
+
const line = lineRaw.trim();
|
|
15726
|
+
if (!line)
|
|
15727
|
+
continue;
|
|
15728
|
+
if (checked++ >= 5)
|
|
15729
|
+
break;
|
|
15730
|
+
try {
|
|
15731
|
+
const e = JSON.parse(line);
|
|
15732
|
+
if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
|
|
15733
|
+
return true;
|
|
15734
|
+
if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
|
|
15735
|
+
return false;
|
|
15736
|
+
} catch {
|
|
15737
|
+
}
|
|
15738
|
+
}
|
|
15739
|
+
return false;
|
|
15740
|
+
}
|
|
15741
|
+
var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
|
|
15742
|
+
function extractCodexEvents(raw) {
|
|
15743
|
+
const out = [];
|
|
15744
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15745
|
+
const line = lineRaw.trim();
|
|
15746
|
+
if (!line)
|
|
15747
|
+
continue;
|
|
15748
|
+
let e;
|
|
15749
|
+
try {
|
|
15750
|
+
e = JSON.parse(line);
|
|
15751
|
+
} catch {
|
|
15752
|
+
continue;
|
|
15753
|
+
}
|
|
15754
|
+
if (e.type !== "response_item")
|
|
15755
|
+
continue;
|
|
15756
|
+
const p = e.payload ?? {};
|
|
15757
|
+
const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
|
|
15758
|
+
const ptype = p.type;
|
|
15759
|
+
if (ptype === "message") {
|
|
15760
|
+
const role = p.role;
|
|
15761
|
+
const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
|
|
15762
|
+
if (!text2)
|
|
15763
|
+
continue;
|
|
15764
|
+
if (role === "user") {
|
|
15765
|
+
if (isCodexInjectedUserText(text2))
|
|
15766
|
+
continue;
|
|
15767
|
+
out.push({ kind: "user", t, text: text2 });
|
|
15768
|
+
} else if (role === "assistant") {
|
|
15769
|
+
out.push({ kind: "assistant", t, text: text2 });
|
|
15770
|
+
}
|
|
15771
|
+
continue;
|
|
15772
|
+
}
|
|
15773
|
+
if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
|
|
15774
|
+
const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
|
|
15775
|
+
const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
|
|
15776
|
+
out.push({ kind: "tool", t, name: name17, input });
|
|
15777
|
+
continue;
|
|
15778
|
+
}
|
|
15779
|
+
if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
|
|
15780
|
+
const output = typeof p.output === "string" ? p.output : "";
|
|
15781
|
+
const m = EXIT_CODE_RE.exec(output.slice(0, 200));
|
|
15782
|
+
out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
|
|
15783
|
+
}
|
|
15784
|
+
}
|
|
15785
|
+
return out;
|
|
15786
|
+
}
|
|
15787
|
+
|
|
15697
15788
|
// ../coding-core/dist/messages.js
|
|
15698
15789
|
function extractText(content) {
|
|
15699
15790
|
if (typeof content === "string")
|
|
@@ -15705,6 +15796,22 @@ function extractText(content) {
|
|
|
15705
15796
|
function isToolResultOnly(content) {
|
|
15706
15797
|
return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
|
|
15707
15798
|
}
|
|
15799
|
+
function extractUserMessagesCodex(raw) {
|
|
15800
|
+
const out = [];
|
|
15801
|
+
let lastTs = null;
|
|
15802
|
+
for (const ev of extractCodexEvents(raw)) {
|
|
15803
|
+
const t = ev.t;
|
|
15804
|
+
const gapMs = Number.isFinite(t) && lastTs != null ? t - lastTs : NaN;
|
|
15805
|
+
if (Number.isFinite(t))
|
|
15806
|
+
lastTs = t;
|
|
15807
|
+
if (ev.kind !== "user")
|
|
15808
|
+
continue;
|
|
15809
|
+
const text2 = humanTypedText(ev.text);
|
|
15810
|
+
if (text2 && Number.isFinite(t))
|
|
15811
|
+
out.push({ t, text: text2, gapMs });
|
|
15812
|
+
}
|
|
15813
|
+
return out.sort((a, b) => a.t - b.t);
|
|
15814
|
+
}
|
|
15708
15815
|
async function extractUserMessages(file2) {
|
|
15709
15816
|
let raw;
|
|
15710
15817
|
try {
|
|
@@ -15712,6 +15819,8 @@ async function extractUserMessages(file2) {
|
|
|
15712
15819
|
} catch {
|
|
15713
15820
|
return [];
|
|
15714
15821
|
}
|
|
15822
|
+
if (sniffCodexRaw(raw))
|
|
15823
|
+
return extractUserMessagesCodex(raw);
|
|
15715
15824
|
const out = [];
|
|
15716
15825
|
const userTexts = /* @__PURE__ */ new Set();
|
|
15717
15826
|
const seenUuids = /* @__PURE__ */ new Set();
|
|
@@ -15694,8 +15694,112 @@ function isHarnessEntry(e) {
|
|
|
15694
15694
|
return e.isMeta === true || e.isCompactSummary === true;
|
|
15695
15695
|
}
|
|
15696
15696
|
|
|
15697
|
-
//
|
|
15697
|
+
// ../coding-core/dist/codex.js
|
|
15698
15698
|
var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
15699
|
+
var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
|
|
15700
|
+
function isCodexInjectedUserText(text2) {
|
|
15701
|
+
return CODEX_INJECTED_TEXT_RE.test(text2);
|
|
15702
|
+
}
|
|
15703
|
+
function codexContentText(content) {
|
|
15704
|
+
if (typeof content === "string")
|
|
15705
|
+
return content;
|
|
15706
|
+
if (!Array.isArray(content))
|
|
15707
|
+
return "";
|
|
15708
|
+
const parts = [];
|
|
15709
|
+
for (const item of content) {
|
|
15710
|
+
if (typeof item === "string") {
|
|
15711
|
+
parts.push(item);
|
|
15712
|
+
continue;
|
|
15713
|
+
}
|
|
15714
|
+
if (item && typeof item === "object") {
|
|
15715
|
+
const it = item;
|
|
15716
|
+
if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
|
|
15717
|
+
parts.push(it.text || "");
|
|
15718
|
+
}
|
|
15719
|
+
}
|
|
15720
|
+
return parts.join("\n");
|
|
15721
|
+
}
|
|
15722
|
+
function sniffCodexRaw(raw) {
|
|
15723
|
+
let checked = 0;
|
|
15724
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15725
|
+
const line = lineRaw.trim();
|
|
15726
|
+
if (!line)
|
|
15727
|
+
continue;
|
|
15728
|
+
if (checked++ >= 5)
|
|
15729
|
+
break;
|
|
15730
|
+
try {
|
|
15731
|
+
const e = JSON.parse(line);
|
|
15732
|
+
if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
|
|
15733
|
+
return true;
|
|
15734
|
+
if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
|
|
15735
|
+
return false;
|
|
15736
|
+
} catch {
|
|
15737
|
+
}
|
|
15738
|
+
}
|
|
15739
|
+
return false;
|
|
15740
|
+
}
|
|
15741
|
+
var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
|
|
15742
|
+
function extractCodexEvents(raw) {
|
|
15743
|
+
const out = [];
|
|
15744
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15745
|
+
const line = lineRaw.trim();
|
|
15746
|
+
if (!line)
|
|
15747
|
+
continue;
|
|
15748
|
+
let e;
|
|
15749
|
+
try {
|
|
15750
|
+
e = JSON.parse(line);
|
|
15751
|
+
} catch {
|
|
15752
|
+
continue;
|
|
15753
|
+
}
|
|
15754
|
+
if (e.type !== "response_item")
|
|
15755
|
+
continue;
|
|
15756
|
+
const p = e.payload ?? {};
|
|
15757
|
+
const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
|
|
15758
|
+
const ptype = p.type;
|
|
15759
|
+
if (ptype === "message") {
|
|
15760
|
+
const role = p.role;
|
|
15761
|
+
const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
|
|
15762
|
+
if (!text2)
|
|
15763
|
+
continue;
|
|
15764
|
+
if (role === "user") {
|
|
15765
|
+
if (isCodexInjectedUserText(text2))
|
|
15766
|
+
continue;
|
|
15767
|
+
out.push({ kind: "user", t, text: text2 });
|
|
15768
|
+
} else if (role === "assistant") {
|
|
15769
|
+
out.push({ kind: "assistant", t, text: text2 });
|
|
15770
|
+
}
|
|
15771
|
+
continue;
|
|
15772
|
+
}
|
|
15773
|
+
if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
|
|
15774
|
+
const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
|
|
15775
|
+
const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
|
|
15776
|
+
out.push({ kind: "tool", t, name: name17, input });
|
|
15777
|
+
continue;
|
|
15778
|
+
}
|
|
15779
|
+
if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
|
|
15780
|
+
const output = typeof p.output === "string" ? p.output : "";
|
|
15781
|
+
const m = EXIT_CODE_RE.exec(output.slice(0, 200));
|
|
15782
|
+
out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
|
|
15783
|
+
}
|
|
15784
|
+
}
|
|
15785
|
+
return out;
|
|
15786
|
+
}
|
|
15787
|
+
function codexPatchFiles(input) {
|
|
15788
|
+
const files = [];
|
|
15789
|
+
const re2 = /\*\*\*\s+(?:Update|Add|Delete)\s+File:\s+(.+)/g;
|
|
15790
|
+
let m;
|
|
15791
|
+
while (m = re2.exec(input)) {
|
|
15792
|
+
const short = m[1].trim().split("/").slice(-2).join("/");
|
|
15793
|
+
if (short && !files.includes(short))
|
|
15794
|
+
files.push(short);
|
|
15795
|
+
}
|
|
15796
|
+
return files;
|
|
15797
|
+
}
|
|
15798
|
+
var CODEX_MUTATORS = /* @__PURE__ */ new Set(["apply_patch"]);
|
|
15799
|
+
var CODEX_INVESTIGATORS = /* @__PURE__ */ new Set(["exec_command", "shell", "local_shell_call", "read_file", "list_dir", "grep", "web_search", "view_image"]);
|
|
15800
|
+
|
|
15801
|
+
// ../../lib/agents/coding/materialize.ts
|
|
15802
|
+
var SYSTEM_REMINDER_RE3 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
15699
15803
|
var INJECT_GIST = 120;
|
|
15700
15804
|
var INJECTED = [
|
|
15701
15805
|
{ re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
|
|
@@ -15715,7 +15819,7 @@ function collapseInjected(input) {
|
|
|
15715
15819
|
return "";
|
|
15716
15820
|
});
|
|
15717
15821
|
}
|
|
15718
|
-
return { text: text2.replace(
|
|
15822
|
+
return { text: text2.replace(SYSTEM_REMINDER_RE3, "").trim(), markers };
|
|
15719
15823
|
}
|
|
15720
15824
|
function extractText(content) {
|
|
15721
15825
|
if (typeof content === "string") return content;
|
|
@@ -15732,6 +15836,38 @@ function isToolResultOnly(content) {
|
|
|
15732
15836
|
return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
|
|
15733
15837
|
}
|
|
15734
15838
|
var AI_GIST = 160;
|
|
15839
|
+
function materializeCodex(raw) {
|
|
15840
|
+
const lines = [];
|
|
15841
|
+
let humanTurns = 0, humanChars = 0;
|
|
15842
|
+
let aiLastProse = "";
|
|
15843
|
+
const aiTools = /* @__PURE__ */ new Map();
|
|
15844
|
+
const flushAI = () => {
|
|
15845
|
+
if (!aiLastProse && aiTools.size === 0) return;
|
|
15846
|
+
const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
|
|
15847
|
+
const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
|
|
15848
|
+
const bits = [];
|
|
15849
|
+
if (gist) bits.push(gist);
|
|
15850
|
+
if (tools) bits.push(`ran ${tools}`);
|
|
15851
|
+
lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
|
|
15852
|
+
aiLastProse = "";
|
|
15853
|
+
aiTools.clear();
|
|
15854
|
+
};
|
|
15855
|
+
for (const ev of extractCodexEvents(raw)) {
|
|
15856
|
+
if (ev.kind === "user") {
|
|
15857
|
+
flushAI();
|
|
15858
|
+
humanTurns++;
|
|
15859
|
+
humanChars += ev.text.length;
|
|
15860
|
+
lines.push(`>> ${ev.text}`);
|
|
15861
|
+
} else if (ev.kind === "assistant") {
|
|
15862
|
+
const prose = ev.text.replace(/\s+/g, " ").trim();
|
|
15863
|
+
if (prose) aiLastProse = prose;
|
|
15864
|
+
} else if (ev.kind === "tool") {
|
|
15865
|
+
aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
|
|
15866
|
+
}
|
|
15867
|
+
}
|
|
15868
|
+
flushAI();
|
|
15869
|
+
return { text: lines.join("\n"), humanTurns, humanChars };
|
|
15870
|
+
}
|
|
15735
15871
|
async function materializeSession(file2) {
|
|
15736
15872
|
let raw;
|
|
15737
15873
|
try {
|
|
@@ -15739,6 +15875,7 @@ async function materializeSession(file2) {
|
|
|
15739
15875
|
} catch {
|
|
15740
15876
|
return null;
|
|
15741
15877
|
}
|
|
15878
|
+
if (sniffCodexRaw(raw)) return materializeCodex(raw);
|
|
15742
15879
|
const lines = [];
|
|
15743
15880
|
let humanTurns = 0, humanChars = 0;
|
|
15744
15881
|
const pendingQueued = [];
|
|
@@ -15865,6 +16002,53 @@ function countToolErrors(content) {
|
|
|
15865
16002
|
}
|
|
15866
16003
|
return n;
|
|
15867
16004
|
}
|
|
16005
|
+
function newTurn(i, t, text2) {
|
|
16006
|
+
const len = text2.length;
|
|
16007
|
+
const deepDive = len >= DEEPDIVE_MIN_LEN || DEEPDIVE_RE.test(text2);
|
|
16008
|
+
return {
|
|
16009
|
+
i,
|
|
16010
|
+
t,
|
|
16011
|
+
text: text2,
|
|
16012
|
+
len,
|
|
16013
|
+
corrective: !deepDive && len <= CORRECTIVE_MAX_LEN && CORRECTIVE_RE.test(text2),
|
|
16014
|
+
deepDive,
|
|
16015
|
+
edits: 0,
|
|
16016
|
+
editFiles: [],
|
|
16017
|
+
investigations: 0,
|
|
16018
|
+
toolErrors: 0,
|
|
16019
|
+
aiStruggle: 0
|
|
16020
|
+
};
|
|
16021
|
+
}
|
|
16022
|
+
function parseCodexTurns(raw) {
|
|
16023
|
+
const turns = [];
|
|
16024
|
+
let cur = null;
|
|
16025
|
+
let idx = 0;
|
|
16026
|
+
for (const ev of extractCodexEvents(raw)) {
|
|
16027
|
+
if (ev.kind === "user") {
|
|
16028
|
+
const text2 = humanTypedText(ev.text);
|
|
16029
|
+
if (!text2)
|
|
16030
|
+
continue;
|
|
16031
|
+
cur = newTurn(idx++, Number.isFinite(ev.t) ? ev.t : cur ? cur.t : 0, text2);
|
|
16032
|
+
turns.push(cur);
|
|
16033
|
+
} else if (ev.kind === "tool" && cur) {
|
|
16034
|
+
if (CODEX_MUTATORS.has(ev.name)) {
|
|
16035
|
+
cur.edits++;
|
|
16036
|
+
for (const f of codexPatchFiles(ev.input))
|
|
16037
|
+
if (!cur.editFiles.includes(f))
|
|
16038
|
+
cur.editFiles.push(f);
|
|
16039
|
+
} else if (CODEX_INVESTIGATORS.has(ev.name)) {
|
|
16040
|
+
cur.investigations++;
|
|
16041
|
+
}
|
|
16042
|
+
} else if (ev.kind === "tool_output" && cur) {
|
|
16043
|
+
if (ev.isError)
|
|
16044
|
+
cur.toolErrors++;
|
|
16045
|
+
} else if (ev.kind === "assistant" && cur) {
|
|
16046
|
+
if (STRUGGLE_RE.test(ev.text))
|
|
16047
|
+
cur.aiStruggle++;
|
|
16048
|
+
}
|
|
16049
|
+
}
|
|
16050
|
+
return turns;
|
|
16051
|
+
}
|
|
15868
16052
|
async function parseSession(file2) {
|
|
15869
16053
|
let raw;
|
|
15870
16054
|
try {
|
|
@@ -15872,6 +16056,8 @@ async function parseSession(file2) {
|
|
|
15872
16056
|
} catch {
|
|
15873
16057
|
return [];
|
|
15874
16058
|
}
|
|
16059
|
+
if (sniffCodexRaw(raw))
|
|
16060
|
+
return parseCodexTurns(raw);
|
|
15875
16061
|
const turns = [];
|
|
15876
16062
|
let cur = null;
|
|
15877
16063
|
let idx = 0;
|
|
@@ -15898,21 +16084,7 @@ async function parseSession(file2) {
|
|
|
15898
16084
|
const text2 = humanTypedText(extractText2(content));
|
|
15899
16085
|
if (!text2)
|
|
15900
16086
|
continue;
|
|
15901
|
-
|
|
15902
|
-
const deepDive = len >= DEEPDIVE_MIN_LEN || DEEPDIVE_RE.test(text2);
|
|
15903
|
-
cur = {
|
|
15904
|
-
i: idx++,
|
|
15905
|
-
t: Number.isFinite(ts) ? ts : cur ? cur.t : 0,
|
|
15906
|
-
text: text2,
|
|
15907
|
-
len,
|
|
15908
|
-
corrective: !deepDive && len <= CORRECTIVE_MAX_LEN && CORRECTIVE_RE.test(text2),
|
|
15909
|
-
deepDive,
|
|
15910
|
-
edits: 0,
|
|
15911
|
-
editFiles: [],
|
|
15912
|
-
investigations: 0,
|
|
15913
|
-
toolErrors: 0,
|
|
15914
|
-
aiStruggle: 0
|
|
15915
|
-
};
|
|
16087
|
+
cur = newTurn(idx++, Number.isFinite(ts) ? ts : cur ? cur.t : 0, text2);
|
|
15916
16088
|
turns.push(cur);
|
|
15917
16089
|
} else if (e.type === "assistant" && cur) {
|
|
15918
16090
|
const msg = e.message ?? {};
|