polymath-society 0.2.19 → 0.2.21

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 (40) hide show
  1. package/dist/cli.js +24620 -22073
  2. package/dist/engine/chat-loops.js +8 -1
  3. package/dist/engine/exp-allfacets.js +8 -1
  4. package/dist/engine/exp-person.js +8 -1
  5. package/dist/engine/exp-pipeline.js +8 -1
  6. package/dist/engine/ingest-export.js +7 -6
  7. package/dist/engine/peak-demos.js +8 -1
  8. package/dist/engine/person-dimension-summary.js +8 -1
  9. package/dist/engine/person-facet-lines.js +8 -1
  10. package/dist/engine/person-headline.js +8 -1
  11. package/dist/engine/person-report.js +8 -1
  12. package/dist/engine/person-self-image.js +8 -1
  13. package/dist/engine/public-report.js +15 -7
  14. package/dist/engine/run-analysis.js +8 -1
  15. package/dist/engine/run-tagger.js +8 -1
  16. package/dist/index.js +19600 -17706
  17. package/dist/pipeline/FOCUS-EXAMPLES.md +127 -0
  18. package/dist/pipeline/FOCUS-RUBRIC.md +418 -0
  19. package/dist/pipeline/coding-agglomerate.js +947 -79
  20. package/dist/pipeline/coding-aggregate.js +443 -23
  21. package/dist/pipeline/coding-build.js +569 -97
  22. package/dist/pipeline/coding-coaching.js +651 -101
  23. package/dist/pipeline/coding-day-digest.js +417 -36
  24. package/dist/pipeline/coding-delegation.js +564 -68
  25. package/dist/pipeline/coding-expertise.js +477 -59
  26. package/dist/pipeline/coding-flow.js +424 -15
  27. package/dist/pipeline/coding-focus.js +507 -51
  28. package/dist/pipeline/coding-frontier-detail.js +465 -47
  29. package/dist/pipeline/coding-frontier.js +7 -6
  30. package/dist/pipeline/coding-gap-dist.js +424 -15
  31. package/dist/pipeline/coding-gap.js +679 -128
  32. package/dist/pipeline/coding-grade.js +469 -42
  33. package/dist/pipeline/coding-growth.js +17041 -0
  34. package/dist/pipeline/coding-nutshell.js +168 -151
  35. package/dist/pipeline/coding-projects.js +7 -6
  36. package/dist/pipeline/coding-walkthrough.js +461 -37
  37. package/dist/pipeline/coding-workbrief.js +16387 -0
  38. package/dist/web/app.js +2095 -1396
  39. package/dist/web/styles.css +1 -1
  40. package/package.json +1 -1
@@ -134,13 +134,13 @@ var require_secure_json_parse = __commonJS({
134
134
  });
135
135
 
136
136
  // ../../scripts/coding-grade.mts
137
- import { promises as fs6 } from "fs";
138
- import path11 from "path";
137
+ import { promises as fs7 } from "fs";
138
+ import path12 from "path";
139
139
 
140
140
  // ../../lib/agents/coding/grade.ts
141
- import { promises as fs5 } from "fs";
142
- import os2 from "os";
143
- import path9 from "path";
141
+ import { promises as fs6 } from "fs";
142
+ import os3 from "os";
143
+ import path10 from "path";
144
144
 
145
145
  // ../../lib/agents/shared/agent.ts
146
146
  import { readFileSync } from "fs";
@@ -508,6 +508,13 @@ ${report}`);
508
508
  }
509
509
 
510
510
  // ../../lib/agents/shared/codexAdapter.ts
511
+ var CODEX_DEFAULT_MODEL = "gpt-5.5";
512
+ var CODEX_MINI_MODEL = "gpt-5.4-mini";
513
+ function mapCodexTier(model, env = process.env) {
514
+ if (model && !/^(claude|haiku|sonnet|opus)/i.test(model)) return model;
515
+ if (model && /^haiku/i.test(model)) return env.POLYMATH_CODEX_MODEL_MINI || CODEX_MINI_MODEL;
516
+ return env.POLYMATH_CODEX_MODEL || CODEX_DEFAULT_MODEL;
517
+ }
511
518
  function composePrompt(inv, roots) {
512
519
  return [
513
520
  inv.systemPrompt ? `<system>
@@ -548,7 +555,7 @@ var codexAdapter = {
548
555
  "read-only",
549
556
  "--json"
550
557
  ];
551
- if (inv.model && !/^claude/i.test(inv.model)) args.push("--model", inv.model);
558
+ args.push("--model", mapCodexTier(inv.model));
552
559
  args.push(composePrompt(inv, roots));
553
560
  const started = Date.now();
554
561
  const toolCalls = [];
@@ -2176,8 +2183,8 @@ function getErrorMap() {
2176
2183
 
2177
2184
  // ../../node_modules/zod/v3/helpers/parseUtil.js
2178
2185
  var makeIssue = (params) => {
2179
- const { data, path: path12, errorMaps, issueData } = params;
2180
- const fullPath = [...path12, ...issueData.path || []];
2186
+ const { data, path: path13, errorMaps, issueData } = params;
2187
+ const fullPath = [...path13, ...issueData.path || []];
2181
2188
  const fullIssue = {
2182
2189
  ...issueData,
2183
2190
  path: fullPath
@@ -2293,11 +2300,11 @@ var errorUtil;
2293
2300
 
2294
2301
  // ../../node_modules/zod/v3/types.js
2295
2302
  var ParseInputLazyPath = class {
2296
- constructor(parent, value, path12, key) {
2303
+ constructor(parent, value, path13, key) {
2297
2304
  this._cachedPath = [];
2298
2305
  this.parent = parent;
2299
2306
  this.data = value;
2300
- this._path = path12;
2307
+ this._path = path13;
2301
2308
  this._key = key;
2302
2309
  }
2303
2310
  get path() {
@@ -15084,39 +15091,39 @@ function createOpenAI(options = {}) {
15084
15091
  });
15085
15092
  const createChatModel = (modelId, settings = {}) => new OpenAIChatLanguageModel(modelId, settings, {
15086
15093
  provider: `${providerName}.chat`,
15087
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15094
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15088
15095
  headers: getHeaders,
15089
15096
  compatibility,
15090
15097
  fetch: options.fetch
15091
15098
  });
15092
15099
  const createCompletionModel = (modelId, settings = {}) => new OpenAICompletionLanguageModel(modelId, settings, {
15093
15100
  provider: `${providerName}.completion`,
15094
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15101
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15095
15102
  headers: getHeaders,
15096
15103
  compatibility,
15097
15104
  fetch: options.fetch
15098
15105
  });
15099
15106
  const createEmbeddingModel = (modelId, settings = {}) => new OpenAIEmbeddingModel(modelId, settings, {
15100
15107
  provider: `${providerName}.embedding`,
15101
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15108
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15102
15109
  headers: getHeaders,
15103
15110
  fetch: options.fetch
15104
15111
  });
15105
15112
  const createImageModel = (modelId, settings = {}) => new OpenAIImageModel(modelId, settings, {
15106
15113
  provider: `${providerName}.image`,
15107
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15114
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15108
15115
  headers: getHeaders,
15109
15116
  fetch: options.fetch
15110
15117
  });
15111
15118
  const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
15112
15119
  provider: `${providerName}.transcription`,
15113
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15120
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15114
15121
  headers: getHeaders,
15115
15122
  fetch: options.fetch
15116
15123
  });
15117
15124
  const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
15118
15125
  provider: `${providerName}.speech`,
15119
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15126
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15120
15127
  headers: getHeaders,
15121
15128
  fetch: options.fetch
15122
15129
  });
@@ -15137,7 +15144,7 @@ function createOpenAI(options = {}) {
15137
15144
  const createResponsesModel = (modelId) => {
15138
15145
  return new OpenAIResponsesLanguageModel(modelId, {
15139
15146
  provider: `${providerName}.responses`,
15140
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15147
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15141
15148
  headers: getHeaders,
15142
15149
  fetch: options.fetch
15143
15150
  });
@@ -15856,15 +15863,387 @@ var GRADED_CRITERIA = CODING_CRITERIA.filter((c) => c.graded);
15856
15863
  var RUBRIC_FINGERPRINT = rubricFingerprint(GRADED_CRITERIA);
15857
15864
 
15858
15865
  // ../../lib/agents/coding/materialize.ts
15859
- import { promises as fs4 } from "fs";
15866
+ import { promises as fs5 } from "fs";
15860
15867
 
15861
15868
  // ../coding-core/dist/injected.js
15869
+ var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15862
15870
  function isHarnessEntry(e) {
15863
15871
  return e.isMeta === true || e.isCompactSummary === true;
15864
15872
  }
15865
15873
 
15874
+ // ../coding-core/dist/codex.js
15875
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15876
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15877
+ function isCodexInjectedUserText(text2) {
15878
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15879
+ }
15880
+ function codexContentText(content) {
15881
+ if (typeof content === "string")
15882
+ return content;
15883
+ if (!Array.isArray(content))
15884
+ return "";
15885
+ const parts = [];
15886
+ for (const item of content) {
15887
+ if (typeof item === "string") {
15888
+ parts.push(item);
15889
+ continue;
15890
+ }
15891
+ if (item && typeof item === "object") {
15892
+ const it = item;
15893
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15894
+ parts.push(it.text || "");
15895
+ }
15896
+ }
15897
+ return parts.join("\n");
15898
+ }
15899
+ function sniffCodexRaw(raw) {
15900
+ let checked = 0;
15901
+ for (const lineRaw of raw.split("\n")) {
15902
+ const line = lineRaw.trim();
15903
+ if (!line)
15904
+ continue;
15905
+ if (checked++ >= 5)
15906
+ break;
15907
+ try {
15908
+ const e = JSON.parse(line);
15909
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15910
+ return true;
15911
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15912
+ return false;
15913
+ } catch {
15914
+ }
15915
+ }
15916
+ return false;
15917
+ }
15918
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15919
+ function extractCodexEvents(raw) {
15920
+ const out = [];
15921
+ for (const lineRaw of raw.split("\n")) {
15922
+ const line = lineRaw.trim();
15923
+ if (!line)
15924
+ continue;
15925
+ let e;
15926
+ try {
15927
+ e = JSON.parse(line);
15928
+ } catch {
15929
+ continue;
15930
+ }
15931
+ if (e.type !== "response_item")
15932
+ continue;
15933
+ const p = e.payload ?? {};
15934
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15935
+ const ptype = p.type;
15936
+ if (ptype === "message") {
15937
+ const role = p.role;
15938
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
15939
+ if (!text2)
15940
+ continue;
15941
+ if (role === "user") {
15942
+ if (isCodexInjectedUserText(text2))
15943
+ continue;
15944
+ out.push({ kind: "user", t, text: text2 });
15945
+ } else if (role === "assistant") {
15946
+ out.push({ kind: "assistant", t, text: text2 });
15947
+ }
15948
+ continue;
15949
+ }
15950
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15951
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15952
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15953
+ out.push({ kind: "tool", t, name: name17, input });
15954
+ continue;
15955
+ }
15956
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15957
+ const output = typeof p.output === "string" ? p.output : "";
15958
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15959
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15960
+ }
15961
+ }
15962
+ return out;
15963
+ }
15964
+
15965
+ // ../coding-core/dist/cursor.js
15966
+ import { promises as fs4 } from "fs";
15967
+ var NODE_SQLITE = "node:sqlite";
15968
+ async function openCursorSqlite(dbPath) {
15969
+ try {
15970
+ await fs4.access(dbPath);
15971
+ } catch {
15972
+ return null;
15973
+ }
15974
+ let mod;
15975
+ try {
15976
+ mod = await import(NODE_SQLITE);
15977
+ } catch {
15978
+ return null;
15979
+ }
15980
+ const DatabaseSync = mod?.DatabaseSync;
15981
+ if (!DatabaseSync)
15982
+ return null;
15983
+ let db;
15984
+ try {
15985
+ db = new DatabaseSync(dbPath, { readOnly: true });
15986
+ } catch {
15987
+ try {
15988
+ db = new DatabaseSync(dbPath);
15989
+ } catch {
15990
+ return null;
15991
+ }
15992
+ }
15993
+ const asText = (v) => v == null ? null : typeof v === "string" ? v : Buffer.from(v).toString("utf-8");
15994
+ return {
15995
+ prefix(prefix) {
15996
+ try {
15997
+ const rows = db.prepare("SELECT key, value FROM cursorDiskKV WHERE key LIKE ? ESCAPE '\\'").all(likePrefix(prefix));
15998
+ return rows.map((r) => ({ key: r.key, value: asText(r.value) ?? "" }));
15999
+ } catch {
16000
+ return [];
16001
+ }
16002
+ },
16003
+ get(key) {
16004
+ try {
16005
+ const row = db.prepare("SELECT value FROM cursorDiskKV WHERE key = ?").get(key);
16006
+ return row ? asText(row.value) : null;
16007
+ } catch {
16008
+ return null;
16009
+ }
16010
+ },
16011
+ close() {
16012
+ try {
16013
+ db.close();
16014
+ } catch {
16015
+ }
16016
+ }
16017
+ };
16018
+ }
16019
+ function likePrefix(prefix) {
16020
+ return prefix.replace(/[\\%_]/g, (c) => "\\" + c) + "%";
16021
+ }
16022
+ var CURSOR_USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
16023
+ function cleanUserText(raw) {
16024
+ let t = raw.replace(SYSTEM_REMINDER_RE, "");
16025
+ const m = t.match(CURSOR_USER_QUERY_RE);
16026
+ if (m)
16027
+ t = m[1];
16028
+ return t.trim();
16029
+ }
16030
+ var msFrom = (v) => {
16031
+ if (typeof v === "number" && Number.isFinite(v))
16032
+ return v;
16033
+ if (typeof v === "string") {
16034
+ const n = Date.parse(v);
16035
+ return Number.isFinite(n) ? n : null;
16036
+ }
16037
+ return null;
16038
+ };
16039
+ function readCursorComposer(db, composerId) {
16040
+ const cdRaw = db.get(`composerData:${composerId}`);
16041
+ if (!cdRaw)
16042
+ return null;
16043
+ let cd;
16044
+ try {
16045
+ cd = JSON.parse(cdRaw);
16046
+ } catch {
16047
+ return null;
16048
+ }
16049
+ const headers = Array.isArray(cd.fullConversationHeadersOnly) ? cd.fullConversationHeadersOnly : [];
16050
+ if (headers.length === 0)
16051
+ return null;
16052
+ const bubbles = /* @__PURE__ */ new Map();
16053
+ for (const row of db.prefix(`bubbleId:${composerId}:`)) {
16054
+ const bid = row.key.slice(`bubbleId:${composerId}:`.length);
16055
+ try {
16056
+ bubbles.set(bid, JSON.parse(row.value));
16057
+ } catch {
16058
+ }
16059
+ }
16060
+ const turns = [];
16061
+ let clock = msFrom(cd.createdAt) ?? 0;
16062
+ for (const h of headers) {
16063
+ const b = bubbles.get(h.bubbleId);
16064
+ if (!b)
16065
+ continue;
16066
+ const type = h.type === 1 ? 1 : 2;
16067
+ const tool2 = type === 2 && b.toolFormerData && typeof b.toolFormerData.name === "string" ? b.toolFormerData.name : null;
16068
+ const rawText = typeof b.text === "string" ? b.text : "";
16069
+ const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
16070
+ if (!text2 && !tool2)
16071
+ continue;
16072
+ const t = msFrom(b.createdAt);
16073
+ clock = Math.max(clock, t ?? clock + 1);
16074
+ const model = b.modelInfo && typeof b.modelInfo.modelName === "string" ? b.modelInfo.modelName : null;
16075
+ turns.push({ t: clock, type, text: text2, tool: tool2, model });
16076
+ }
16077
+ if (turns.length === 0)
16078
+ return null;
16079
+ const gitRepo = Array.isArray(cd.trackedGitRepos) && cd.trackedGitRepos[0] && typeof cd.trackedGitRepos[0].repoPath === "string" ? cd.trackedGitRepos[0].repoPath : null;
16080
+ return {
16081
+ composerId,
16082
+ createdAt: msFrom(cd.createdAt),
16083
+ updatedAt: msFrom(cd.lastUpdatedAt),
16084
+ name: typeof cd.name === "string" && cd.name.trim() ? cd.name.trim() : null,
16085
+ gitRepo,
16086
+ turns
16087
+ };
16088
+ }
16089
+ function sniffCursorRaw(raw) {
16090
+ for (const lineRaw of raw.split("\n")) {
16091
+ const line = lineRaw.trim();
16092
+ if (!line)
16093
+ continue;
16094
+ try {
16095
+ const e = JSON.parse(line);
16096
+ return (e.role === "user" || e.role === "assistant") && typeof e.message === "object" && e.message !== null && "content" in e.message && !("type" in e);
16097
+ } catch {
16098
+ return false;
16099
+ }
16100
+ }
16101
+ return false;
16102
+ }
16103
+ function jsonlText(content) {
16104
+ const parts = [];
16105
+ const tools = [];
16106
+ if (Array.isArray(content)) {
16107
+ for (const item of content) {
16108
+ if (!item || typeof item !== "object")
16109
+ continue;
16110
+ const it = item;
16111
+ if (it.type === "text" && it.text)
16112
+ parts.push(it.text);
16113
+ else if (it.type === "tool_use" && it.name)
16114
+ tools.push(it.name);
16115
+ }
16116
+ } else if (typeof content === "string")
16117
+ parts.push(content);
16118
+ return { text: parts.join("\n"), tools };
16119
+ }
16120
+ function parseCursorJsonl(raw, base) {
16121
+ const turns = [];
16122
+ let clock = base;
16123
+ for (const lineRaw of raw.split("\n")) {
16124
+ const line = lineRaw.trim();
16125
+ if (!line)
16126
+ continue;
16127
+ let e;
16128
+ try {
16129
+ e = JSON.parse(line);
16130
+ } catch {
16131
+ continue;
16132
+ }
16133
+ if (e.role !== "user" && e.role !== "assistant")
16134
+ continue;
16135
+ const { text: rawText, tools } = jsonlText(e.message?.content);
16136
+ const type = e.role === "user" ? 1 : 2;
16137
+ const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
16138
+ if (type === 2 && tools.length) {
16139
+ for (const tool2 of tools) {
16140
+ clock += 1;
16141
+ turns.push({ t: clock, type: 2, text: "", tool: tool2, model: null });
16142
+ }
16143
+ }
16144
+ if (!text2)
16145
+ continue;
16146
+ clock += 1;
16147
+ turns.push({ t: clock, type, text: text2, tool: null, model: null });
16148
+ }
16149
+ if (turns.length === 0)
16150
+ return null;
16151
+ return { composerId: "", createdAt: base, updatedAt: clock, name: null, gitRepo: null, turns };
16152
+ }
16153
+ var AI_GIST = 500;
16154
+ function renderCursorTranscript(c) {
16155
+ const lines = [];
16156
+ let humanTurns = 0, humanChars = 0;
16157
+ let aiProse = "";
16158
+ const aiTools = /* @__PURE__ */ new Map();
16159
+ const flushAI = () => {
16160
+ if (!aiProse && aiTools.size === 0)
16161
+ return;
16162
+ const tools = [...aiTools.entries()].map(([n, k]) => k > 1 ? `${n}\xD7${k}` : n).join(", ");
16163
+ const gist = aiProse ? aiProse.length > AI_GIST ? aiProse.slice(0, AI_GIST) + "\u2026" : aiProse : "";
16164
+ const bits = [];
16165
+ if (gist)
16166
+ bits.push(gist);
16167
+ if (tools)
16168
+ bits.push(`ran ${tools}`);
16169
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
16170
+ aiProse = "";
16171
+ aiTools.clear();
16172
+ };
16173
+ for (const turn of c.turns) {
16174
+ if (turn.type === 1) {
16175
+ flushAI();
16176
+ humanTurns++;
16177
+ humanChars += turn.text.length;
16178
+ lines.push(`>> ${turn.text}`);
16179
+ } else {
16180
+ if (turn.tool)
16181
+ aiTools.set(turn.tool, (aiTools.get(turn.tool) ?? 0) + 1);
16182
+ if (turn.text)
16183
+ aiProse = turn.text.replace(/\s+/g, " ").trim();
16184
+ }
16185
+ }
16186
+ flushAI();
16187
+ return { text: lines.join("\n"), humanTurns, humanChars };
16188
+ }
16189
+ function composerIdFromFile(file2) {
16190
+ const m = file2.match(/agent-transcripts\/([^/]+)\/[^/]+\.jsonl$/);
16191
+ return m ? m[1] : null;
16192
+ }
16193
+ async function loadCursorComposer(file2, raw, dbPath) {
16194
+ const cid = composerIdFromFile(file2);
16195
+ if (cid && dbPath) {
16196
+ const db = await openCursorSqlite(dbPath);
16197
+ if (db) {
16198
+ try {
16199
+ const c = readCursorComposer(db, cid);
16200
+ if (c)
16201
+ return c;
16202
+ } finally {
16203
+ db.close();
16204
+ }
16205
+ }
16206
+ }
16207
+ return parseCursorJsonl(raw, 0);
16208
+ }
16209
+
16210
+ // ../coding-core/dist/raw.js
16211
+ import path9 from "path";
16212
+ import os2 from "os";
16213
+ var SOURCE_ROOT_ENV_VARS = [
16214
+ "CLAUDE_PROJECTS_DIR",
16215
+ "CODEX_SESSIONS_DIR",
16216
+ "CURSOR_WORKSPACE_DIR",
16217
+ "CURSOR_PROJECTS_DIR",
16218
+ // Cursor's globalStorage dir (holds state.vscdb — the composer bubbles that
16219
+ // carry a Cursor session's real per-turn timestamps + content). Same
16220
+ // isolation contract: overriding any root disables every unset source.
16221
+ "CURSOR_GLOBAL_DIR"
16222
+ ];
16223
+ var anyRootOverridden = () => SOURCE_ROOT_ENV_VARS.some((v) => !!process.env[v]);
16224
+ function resolveSourceRoot(envVar, ...defaultSegments) {
16225
+ const explicit = process.env[envVar];
16226
+ if (explicit)
16227
+ return explicit;
16228
+ if (anyRootOverridden())
16229
+ return null;
16230
+ return path9.join(os2.homedir(), ...defaultSegments);
16231
+ }
16232
+ var cursorGlobalRoot = () => resolveSourceRoot("CURSOR_GLOBAL_DIR", "Library", "Application Support", "Cursor", "User", "globalStorage");
16233
+ function cursorGlobalDbPath() {
16234
+ const root = cursorGlobalRoot();
16235
+ return root === null ? null : path9.join(root, "state.vscdb");
16236
+ }
16237
+ var MACHINE_CURSOR_FILE_RE = /^(.*[/\\]machines[/\\][^/\\]+[/\\]\.cursor)[/\\]projects[/\\]/;
16238
+ function cursorDbPathForFile(file2) {
16239
+ const m = file2.match(MACHINE_CURSOR_FILE_RE);
16240
+ if (m)
16241
+ return path9.join(m[1], "globalStorage", "state.vscdb");
16242
+ return cursorGlobalDbPath();
16243
+ }
16244
+
15866
16245
  // ../../lib/agents/coding/materialize.ts
15867
- var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
16246
+ var SYSTEM_REMINDER_RE3 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15868
16247
  var INJECT_GIST = 120;
15869
16248
  var INJECTED = [
15870
16249
  { re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
@@ -15884,7 +16263,7 @@ function collapseInjected(input) {
15884
16263
  return "";
15885
16264
  });
15886
16265
  }
15887
- return { text: text2.replace(SYSTEM_REMINDER_RE, "").trim(), markers };
16266
+ return { text: text2.replace(SYSTEM_REMINDER_RE3, "").trim(), markers };
15888
16267
  }
15889
16268
  function extractText(content) {
15890
16269
  if (typeof content === "string") return content;
@@ -15900,14 +16279,52 @@ function extractText(content) {
15900
16279
  function isToolResultOnly(content) {
15901
16280
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15902
16281
  }
15903
- var AI_GIST = 160;
16282
+ var AI_GIST2 = 160;
16283
+ function materializeCodex(raw) {
16284
+ const lines = [];
16285
+ let humanTurns = 0, humanChars = 0;
16286
+ let aiLastProse = "";
16287
+ const aiTools = /* @__PURE__ */ new Map();
16288
+ const flushAI = () => {
16289
+ if (!aiLastProse && aiTools.size === 0) return;
16290
+ const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
16291
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
16292
+ const bits = [];
16293
+ if (gist) bits.push(gist);
16294
+ if (tools) bits.push(`ran ${tools}`);
16295
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
16296
+ aiLastProse = "";
16297
+ aiTools.clear();
16298
+ };
16299
+ for (const ev of extractCodexEvents(raw)) {
16300
+ if (ev.kind === "user") {
16301
+ flushAI();
16302
+ humanTurns++;
16303
+ humanChars += ev.text.length;
16304
+ lines.push(`>> ${ev.text}`);
16305
+ } else if (ev.kind === "assistant") {
16306
+ const prose = ev.text.replace(/\s+/g, " ").trim();
16307
+ if (prose) aiLastProse = prose;
16308
+ } else if (ev.kind === "tool") {
16309
+ aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
16310
+ }
16311
+ }
16312
+ flushAI();
16313
+ return { text: lines.join("\n"), humanTurns, humanChars };
16314
+ }
16315
+ async function materializeCursor(file2, raw) {
16316
+ const composer = await loadCursorComposer(file2, raw, cursorDbPathForFile(file2));
16317
+ return composer ? renderCursorTranscript(composer) : { text: "", humanTurns: 0, humanChars: 0 };
16318
+ }
15904
16319
  async function materializeSession(file2) {
15905
16320
  let raw;
15906
16321
  try {
15907
- raw = await fs4.readFile(file2, "utf-8");
16322
+ raw = await fs5.readFile(file2, "utf-8");
15908
16323
  } catch {
15909
16324
  return null;
15910
16325
  }
16326
+ if (sniffCodexRaw(raw)) return materializeCodex(raw);
16327
+ if (sniffCursorRaw(raw)) return materializeCursor(file2, raw);
15911
16328
  const lines = [];
15912
16329
  let humanTurns = 0, humanChars = 0;
15913
16330
  const pendingQueued = [];
@@ -15920,7 +16337,7 @@ async function materializeSession(file2) {
15920
16337
  const flushAI = () => {
15921
16338
  if (!aiLastProse && aiTools.size === 0) return;
15922
16339
  const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15923
- const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
16340
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
15924
16341
  const bits = [];
15925
16342
  if (gist) bits.push(gist);
15926
16343
  if (tools) bits.push(`ran ${tools}`);
@@ -16085,8 +16502,11 @@ function validate(raw) {
16085
16502
  }
16086
16503
  async function gradeSession(rec, opts = { outDir: "" }) {
16087
16504
  const mat = await materializeSession(rec.file);
16505
+ if (rec.humanChars >= 200 && (!mat || mat.humanChars === 0)) {
16506
+ throw new Error(`[grade] ${rec.source} session ${rec.sessionId} has ${rec.humanChars} human chars on disk but materialized EMPTY \u2014 the materializer is missing a branch for this source (see the Codex/Cursor lesson in CLAUDE.md). Refusing to silently skip.`);
16507
+ }
16088
16508
  if (!mat || mat.humanChars < 200) return null;
16089
- const sandbox = await fs5.mkdtemp(path9.join(os2.tmpdir(), "ps-coding-"));
16509
+ const sandbox = await fs6.mkdtemp(path10.join(os3.tmpdir(), "ps-coding-"));
16090
16510
  try {
16091
16511
  const chunks = chunkText(mat.text, CHUNK);
16092
16512
  const perChunk = [];
@@ -16102,7 +16522,7 @@ async function gradeSession(rec, opts = { outDir: "" }) {
16102
16522
  maxTurns: 6,
16103
16523
  timeoutMs: 3e5,
16104
16524
  model: opts.model ?? "sonnet",
16105
- logPath: opts.logDir ? path9.join(opts.logDir, `${rec.sessionId}${chunks.length > 1 ? `.part${ci + 1}` : ""}.log`) : void 0
16525
+ logPath: opts.logDir ? path10.join(opts.logDir, `${rec.sessionId}${chunks.length > 1 ? `.part${ci + 1}` : ""}.log`) : void 0
16106
16526
  });
16107
16527
  const c = validate(run2.json);
16108
16528
  if (c.length) perChunk.push(c);
@@ -16129,11 +16549,11 @@ async function gradeSession(rec, opts = { outDir: "" }) {
16129
16549
  criteria,
16130
16550
  meta: { costUsd, durationMs, calls: chunks.length, ...small ? { scoreMap: HAIKU_SCORE_MAP_ID } : {} }
16131
16551
  };
16132
- await fs5.mkdir(opts.outDir, { recursive: true });
16133
- await fs5.writeFile(path9.join(opts.outDir, `${rec.sessionId}.json`), JSON.stringify(grade, null, 2));
16552
+ await fs6.mkdir(opts.outDir, { recursive: true });
16553
+ await fs6.writeFile(path10.join(opts.outDir, `${rec.sessionId}.json`), JSON.stringify(grade, null, 2));
16134
16554
  return grade;
16135
16555
  } finally {
16136
- await fs5.rm(sandbox, { recursive: true, force: true }).catch(() => {
16556
+ await fs6.rm(sandbox, { recursive: true, force: true }).catch(() => {
16137
16557
  });
16138
16558
  }
16139
16559
  }
@@ -16198,7 +16618,7 @@ function capGradable(gradable) {
16198
16618
  }
16199
16619
 
16200
16620
  // ../../lib/agents/coding/profile.ts
16201
- import path10 from "path";
16621
+ import path11 from "path";
16202
16622
 
16203
16623
  // ../../lib/agents/coding/walkthrough.ts
16204
16624
  var IDLE_CAP_MS = 12 * 6e4;
@@ -16209,7 +16629,7 @@ var TRANSCRIPT_LINE_RE = new RegExp(`^\\s*(${NOTE})((,| and) ${NOTE})*\\s*$|^\\s
16209
16629
 
16210
16630
  // ../../lib/calibration/index.ts
16211
16631
  var DEFAULT_CALIBRATION = {
16212
- version: "2026-07-16.2",
16632
+ version: "2026-07-21.1",
16213
16633
  // = RUBRIC_FINGERPRINT of the shipped npm rubric (packages/coding-analyzer/
16214
16634
  // src/grade/criteria.ts). A unit test fails loud when the rubric changes
16215
16635
  // without this being updated (and re-pushed to the server).
@@ -16305,13 +16725,14 @@ var DEFAULT_CALIBRATION = {
16305
16725
  },
16306
16726
  codingBenchmarks: {
16307
16727
  flow: {
16308
- // typical knowledge worker ≈ 35% of an 8h day focused; ~4h/day is the
16309
- // recognized deep-work ceiling (Newport) 50% most sit far below it.
16728
+ // typical knowledge worker ≈ 35% of an 8h day focused; the ~4h/day
16729
+ // deep-work ceiling (Newport) sits nearer ~40% of a real (9-10h) top
16730
+ // performer's day — 50% overstated it (owner call 2026-07-21).
16310
16731
  typicalPctOfDay: 0.35,
16311
- topPctOfDay: 0.5,
16732
+ topPctOfDay: 0.4,
16312
16733
  tag: "measured",
16313
- source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling)",
16314
- line: "the best spend ~half the workday in true deep flow; ~4h/day is the human ceiling"
16734
+ source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling against a 9-10h day)",
16735
+ line: "the best spend ~40% of the workday in true deep flow; ~4h/day is the human ceiling"
16315
16736
  },
16316
16737
  longestRun: {
16317
16738
  typicalHours: 0.67,
@@ -16360,8 +16781,8 @@ var BEST = DEFAULT_CALIBRATION.codingBenchmarks;
16360
16781
 
16361
16782
  // ../../lib/agents/coding/profile.ts
16362
16783
  var ROOT = process.cwd();
16363
- var CODING_DIR = process.env.POLYMATH_DATA_DIR ? path10.join(process.env.POLYMATH_DATA_DIR, "coding") : path10.join(ROOT, ".data", "coding");
16364
- var GRADES = path10.join(CODING_DIR, "grades");
16784
+ var CODING_DIR = process.env.POLYMATH_DATA_DIR ? path11.join(process.env.POLYMATH_DATA_DIR, "coding") : path11.join(ROOT, ".data", "coding");
16785
+ var GRADES = path11.join(CODING_DIR, "grades");
16365
16786
 
16366
16787
  // ../../scripts/coding-grade.mts
16367
16788
  var argv = process.argv.slice(2);
@@ -16389,10 +16810,10 @@ function makeLimiter(max) {
16389
16810
  };
16390
16811
  }
16391
16812
  var CODING = CODING_DIR;
16392
- var GRADES2 = path11.join(CODING, "grades");
16393
- var LOGS = path11.join(GRADES2, "logs");
16813
+ var GRADES2 = path12.join(CODING, "grades");
16814
+ var LOGS = path12.join(GRADES2, "logs");
16394
16815
  async function main() {
16395
- const sessions = JSON.parse(await fs6.readFile(path11.join(CODING, "sessions.json"), "utf8"));
16816
+ const sessions = JSON.parse(await fs7.readFile(path12.join(CODING, "sessions.json"), "utf8"));
16396
16817
  const live = sessions.filter((s) => s.klass === "interactive" && !s.duplicateOf);
16397
16818
  const { gradable: allGradable, thin, trivial } = partition(live);
16398
16819
  const cutoff = aiWindowCutoff(live);
@@ -16401,13 +16822,13 @@ async function main() {
16401
16822
  console.log(`[coding-grade] ${sessions.length} sessions \u2192 ${allGradable.length} gradable \xB7 ${thin.length} thin \xB7 ${trivial.length} trivial (skipped)`);
16402
16823
  if (cutoff) console.log(`[coding-grade] AI window: grading sessions since ${cutoff.slice(0, 10)} \u2014 ${gradable.length} of ${allGradable.length} gradable (POLYMATH_AI_WINDOW_DAYS=0 for full history)`);
16403
16824
  if (ranked.length < gradable.length) console.log(`[coding-grade] cap: grading the ${ranked.length} richest of ${gradable.length} gradable sessions (POLYMATH_MAX_GRADED=${maxGraded()}; 0 = uncapped) \u2014 the rest still feed every deterministic number`);
16404
- await fs6.mkdir(LOGS, { recursive: true });
16825
+ await fs7.mkdir(LOGS, { recursive: true });
16405
16826
  const limit = ALL ? ranked.length : N;
16406
16827
  const picked = [];
16407
16828
  for (const s of ranked) {
16408
16829
  if (picked.length >= limit) break;
16409
16830
  if (!REGRADE) {
16410
- const done = await fs6.readFile(path11.join(GRADES2, `${s.sessionId}.json`), "utf8").catch(() => null);
16831
+ const done = await fs7.readFile(path12.join(GRADES2, `${s.sessionId}.json`), "utf8").catch(() => null);
16411
16832
  if (done) continue;
16412
16833
  }
16413
16834
  picked.push(s);
@@ -16440,6 +16861,12 @@ async function main() {
16440
16861
  }
16441
16862
  })));
16442
16863
  endRun();
16864
+ if (picked.length > 0 && doneN === 0) {
16865
+ console.error(`
16866
+ [coding-grade] FATAL: 0 of ${picked.length} attempted sessions produced a grade \u2014 every attempt failed or returned no usable grade.`);
16867
+ console.error(`[coding-grade] The report must NOT pretend to be graded. Likely cause: unreadable or unsupported transcript files (a log format the reader cannot parse). Fix ingestion, then re-run this stage.`);
16868
+ process.exit(1);
16869
+ }
16443
16870
  console.log(`[coding-grade] wrote \u2192 .data/coding/grades/`);
16444
16871
  }
16445
16872
  main().catch((e) => {