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,9 +134,9 @@ var require_secure_json_parse = __commonJS({
134
134
  });
135
135
 
136
136
  // ../../scripts/coding-expertise.mts
137
- import { promises as fs7 } from "fs";
138
- import os2 from "os";
139
- import path11 from "path";
137
+ import { promises as fs8 } from "fs";
138
+ import os3 from "os";
139
+ import path12 from "path";
140
140
 
141
141
  // ../../lib/agents/shared/agent.ts
142
142
  import { readFileSync } from "fs";
@@ -504,6 +504,13 @@ ${report}`);
504
504
  }
505
505
 
506
506
  // ../../lib/agents/shared/codexAdapter.ts
507
+ var CODEX_DEFAULT_MODEL = "gpt-5.5";
508
+ var CODEX_MINI_MODEL = "gpt-5.4-mini";
509
+ function mapCodexTier(model, env = process.env) {
510
+ if (model && !/^(claude|haiku|sonnet|opus)/i.test(model)) return model;
511
+ if (model && /^haiku/i.test(model)) return env.POLYMATH_CODEX_MODEL_MINI || CODEX_MINI_MODEL;
512
+ return env.POLYMATH_CODEX_MODEL || CODEX_DEFAULT_MODEL;
513
+ }
507
514
  function composePrompt(inv, roots) {
508
515
  return [
509
516
  inv.systemPrompt ? `<system>
@@ -544,7 +551,7 @@ var codexAdapter = {
544
551
  "read-only",
545
552
  "--json"
546
553
  ];
547
- if (inv.model && !/^claude/i.test(inv.model)) args.push("--model", inv.model);
554
+ args.push("--model", mapCodexTier(inv.model));
548
555
  args.push(composePrompt(inv, roots));
549
556
  const started = Date.now();
550
557
  const toolCalls = [];
@@ -2172,8 +2179,8 @@ function getErrorMap() {
2172
2179
 
2173
2180
  // ../../node_modules/zod/v3/helpers/parseUtil.js
2174
2181
  var makeIssue = (params) => {
2175
- const { data, path: path12, errorMaps, issueData } = params;
2176
- const fullPath = [...path12, ...issueData.path || []];
2182
+ const { data, path: path13, errorMaps, issueData } = params;
2183
+ const fullPath = [...path13, ...issueData.path || []];
2177
2184
  const fullIssue = {
2178
2185
  ...issueData,
2179
2186
  path: fullPath
@@ -2289,11 +2296,11 @@ var errorUtil;
2289
2296
 
2290
2297
  // ../../node_modules/zod/v3/types.js
2291
2298
  var ParseInputLazyPath = class {
2292
- constructor(parent, value, path12, key) {
2299
+ constructor(parent, value, path13, key) {
2293
2300
  this._cachedPath = [];
2294
2301
  this.parent = parent;
2295
2302
  this.data = value;
2296
- this._path = path12;
2303
+ this._path = path13;
2297
2304
  this._key = key;
2298
2305
  }
2299
2306
  get path() {
@@ -15080,39 +15087,39 @@ function createOpenAI(options = {}) {
15080
15087
  });
15081
15088
  const createChatModel = (modelId, settings = {}) => new OpenAIChatLanguageModel(modelId, settings, {
15082
15089
  provider: `${providerName}.chat`,
15083
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15090
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15084
15091
  headers: getHeaders,
15085
15092
  compatibility,
15086
15093
  fetch: options.fetch
15087
15094
  });
15088
15095
  const createCompletionModel = (modelId, settings = {}) => new OpenAICompletionLanguageModel(modelId, settings, {
15089
15096
  provider: `${providerName}.completion`,
15090
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15097
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15091
15098
  headers: getHeaders,
15092
15099
  compatibility,
15093
15100
  fetch: options.fetch
15094
15101
  });
15095
15102
  const createEmbeddingModel = (modelId, settings = {}) => new OpenAIEmbeddingModel(modelId, settings, {
15096
15103
  provider: `${providerName}.embedding`,
15097
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15104
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15098
15105
  headers: getHeaders,
15099
15106
  fetch: options.fetch
15100
15107
  });
15101
15108
  const createImageModel = (modelId, settings = {}) => new OpenAIImageModel(modelId, settings, {
15102
15109
  provider: `${providerName}.image`,
15103
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15110
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15104
15111
  headers: getHeaders,
15105
15112
  fetch: options.fetch
15106
15113
  });
15107
15114
  const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
15108
15115
  provider: `${providerName}.transcription`,
15109
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15116
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15110
15117
  headers: getHeaders,
15111
15118
  fetch: options.fetch
15112
15119
  });
15113
15120
  const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
15114
15121
  provider: `${providerName}.speech`,
15115
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15122
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15116
15123
  headers: getHeaders,
15117
15124
  fetch: options.fetch
15118
15125
  });
@@ -15133,7 +15140,7 @@ function createOpenAI(options = {}) {
15133
15140
  const createResponsesModel = (modelId) => {
15134
15141
  return new OpenAIResponsesLanguageModel(modelId, {
15135
15142
  provider: `${providerName}.responses`,
15136
- url: ({ path: path12 }) => `${baseURL}${path12}`,
15143
+ url: ({ path: path13 }) => `${baseURL}${path13}`,
15137
15144
  headers: getHeaders,
15138
15145
  fetch: options.fetch
15139
15146
  });
@@ -15647,19 +15654,391 @@ function chunkText(text2, max) {
15647
15654
  }
15648
15655
 
15649
15656
  // ../../lib/agents/coding/docsDir.ts
15650
- import { promises as fs5 } from "fs";
15651
- import path9 from "path";
15657
+ import { promises as fs6 } from "fs";
15658
+ import path10 from "path";
15652
15659
 
15653
15660
  // ../../lib/agents/coding/materialize.ts
15654
- import { promises as fs4 } from "fs";
15661
+ import { promises as fs5 } from "fs";
15655
15662
 
15656
15663
  // ../coding-core/dist/injected.js
15664
+ var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15657
15665
  function isHarnessEntry(e) {
15658
15666
  return e.isMeta === true || e.isCompactSummary === true;
15659
15667
  }
15660
15668
 
15669
+ // ../coding-core/dist/codex.js
15670
+ var SYSTEM_REMINDER_RE2 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15671
+ var CODEX_INJECTED_TEXT_RE = /^\s*(<(environment_context|user_instructions|ENVIRONMENT_CONTEXT|turn_aborted)\b|#\s*AGENTS\.md instructions\b)/;
15672
+ function isCodexInjectedUserText(text2) {
15673
+ return CODEX_INJECTED_TEXT_RE.test(text2);
15674
+ }
15675
+ function codexContentText(content) {
15676
+ if (typeof content === "string")
15677
+ return content;
15678
+ if (!Array.isArray(content))
15679
+ return "";
15680
+ const parts = [];
15681
+ for (const item of content) {
15682
+ if (typeof item === "string") {
15683
+ parts.push(item);
15684
+ continue;
15685
+ }
15686
+ if (item && typeof item === "object") {
15687
+ const it = item;
15688
+ if (it.type === "input_text" || it.type === "output_text" || it.type === "text")
15689
+ parts.push(it.text || "");
15690
+ }
15691
+ }
15692
+ return parts.join("\n");
15693
+ }
15694
+ function sniffCodexRaw(raw) {
15695
+ let checked = 0;
15696
+ for (const lineRaw of raw.split("\n")) {
15697
+ const line = lineRaw.trim();
15698
+ if (!line)
15699
+ continue;
15700
+ if (checked++ >= 5)
15701
+ break;
15702
+ try {
15703
+ const e = JSON.parse(line);
15704
+ if (e.type === "session_meta" || e.type === "response_item" || e.type === "turn_context")
15705
+ return true;
15706
+ if (e.type === "user" || e.type === "assistant" || e.type === "summary" || e.type === "queue-operation")
15707
+ return false;
15708
+ } catch {
15709
+ }
15710
+ }
15711
+ return false;
15712
+ }
15713
+ var EXIT_CODE_RE = /(?:Process exited with code|Exit code:)\s+(\d+)/;
15714
+ function extractCodexEvents(raw) {
15715
+ const out = [];
15716
+ for (const lineRaw of raw.split("\n")) {
15717
+ const line = lineRaw.trim();
15718
+ if (!line)
15719
+ continue;
15720
+ let e;
15721
+ try {
15722
+ e = JSON.parse(line);
15723
+ } catch {
15724
+ continue;
15725
+ }
15726
+ if (e.type !== "response_item")
15727
+ continue;
15728
+ const p = e.payload ?? {};
15729
+ const t = typeof e.timestamp === "string" ? Date.parse(e.timestamp) : NaN;
15730
+ const ptype = p.type;
15731
+ if (ptype === "message") {
15732
+ const role = p.role;
15733
+ const text2 = codexContentText(p.content).replace(SYSTEM_REMINDER_RE2, "").trim();
15734
+ if (!text2)
15735
+ continue;
15736
+ if (role === "user") {
15737
+ if (isCodexInjectedUserText(text2))
15738
+ continue;
15739
+ out.push({ kind: "user", t, text: text2 });
15740
+ } else if (role === "assistant") {
15741
+ out.push({ kind: "assistant", t, text: text2 });
15742
+ }
15743
+ continue;
15744
+ }
15745
+ if (ptype === "function_call" || ptype === "custom_tool_call" || ptype === "local_shell_call") {
15746
+ const name17 = typeof p.name === "string" && p.name ? p.name : ptype === "local_shell_call" ? "shell" : String(ptype);
15747
+ const input = typeof p.arguments === "string" ? p.arguments : typeof p.input === "string" ? p.input : "";
15748
+ out.push({ kind: "tool", t, name: name17, input });
15749
+ continue;
15750
+ }
15751
+ if (ptype === "function_call_output" || ptype === "custom_tool_call_output") {
15752
+ const output = typeof p.output === "string" ? p.output : "";
15753
+ const m = EXIT_CODE_RE.exec(output.slice(0, 200));
15754
+ out.push({ kind: "tool_output", t, output, isError: !!m && m[1] !== "0" });
15755
+ }
15756
+ }
15757
+ return out;
15758
+ }
15759
+
15760
+ // ../coding-core/dist/cursor.js
15761
+ import { promises as fs4 } from "fs";
15762
+ var NODE_SQLITE = "node:sqlite";
15763
+ async function openCursorSqlite(dbPath) {
15764
+ try {
15765
+ await fs4.access(dbPath);
15766
+ } catch {
15767
+ return null;
15768
+ }
15769
+ let mod;
15770
+ try {
15771
+ mod = await import(NODE_SQLITE);
15772
+ } catch {
15773
+ return null;
15774
+ }
15775
+ const DatabaseSync = mod?.DatabaseSync;
15776
+ if (!DatabaseSync)
15777
+ return null;
15778
+ let db;
15779
+ try {
15780
+ db = new DatabaseSync(dbPath, { readOnly: true });
15781
+ } catch {
15782
+ try {
15783
+ db = new DatabaseSync(dbPath);
15784
+ } catch {
15785
+ return null;
15786
+ }
15787
+ }
15788
+ const asText = (v) => v == null ? null : typeof v === "string" ? v : Buffer.from(v).toString("utf-8");
15789
+ return {
15790
+ prefix(prefix) {
15791
+ try {
15792
+ const rows = db.prepare("SELECT key, value FROM cursorDiskKV WHERE key LIKE ? ESCAPE '\\'").all(likePrefix(prefix));
15793
+ return rows.map((r) => ({ key: r.key, value: asText(r.value) ?? "" }));
15794
+ } catch {
15795
+ return [];
15796
+ }
15797
+ },
15798
+ get(key) {
15799
+ try {
15800
+ const row = db.prepare("SELECT value FROM cursorDiskKV WHERE key = ?").get(key);
15801
+ return row ? asText(row.value) : null;
15802
+ } catch {
15803
+ return null;
15804
+ }
15805
+ },
15806
+ close() {
15807
+ try {
15808
+ db.close();
15809
+ } catch {
15810
+ }
15811
+ }
15812
+ };
15813
+ }
15814
+ function likePrefix(prefix) {
15815
+ return prefix.replace(/[\\%_]/g, (c) => "\\" + c) + "%";
15816
+ }
15817
+ var CURSOR_USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
15818
+ function cleanUserText(raw) {
15819
+ let t = raw.replace(SYSTEM_REMINDER_RE, "");
15820
+ const m = t.match(CURSOR_USER_QUERY_RE);
15821
+ if (m)
15822
+ t = m[1];
15823
+ return t.trim();
15824
+ }
15825
+ var msFrom = (v) => {
15826
+ if (typeof v === "number" && Number.isFinite(v))
15827
+ return v;
15828
+ if (typeof v === "string") {
15829
+ const n = Date.parse(v);
15830
+ return Number.isFinite(n) ? n : null;
15831
+ }
15832
+ return null;
15833
+ };
15834
+ function readCursorComposer(db, composerId) {
15835
+ const cdRaw = db.get(`composerData:${composerId}`);
15836
+ if (!cdRaw)
15837
+ return null;
15838
+ let cd;
15839
+ try {
15840
+ cd = JSON.parse(cdRaw);
15841
+ } catch {
15842
+ return null;
15843
+ }
15844
+ const headers = Array.isArray(cd.fullConversationHeadersOnly) ? cd.fullConversationHeadersOnly : [];
15845
+ if (headers.length === 0)
15846
+ return null;
15847
+ const bubbles = /* @__PURE__ */ new Map();
15848
+ for (const row of db.prefix(`bubbleId:${composerId}:`)) {
15849
+ const bid = row.key.slice(`bubbleId:${composerId}:`.length);
15850
+ try {
15851
+ bubbles.set(bid, JSON.parse(row.value));
15852
+ } catch {
15853
+ }
15854
+ }
15855
+ const turns = [];
15856
+ let clock = msFrom(cd.createdAt) ?? 0;
15857
+ for (const h of headers) {
15858
+ const b = bubbles.get(h.bubbleId);
15859
+ if (!b)
15860
+ continue;
15861
+ const type = h.type === 1 ? 1 : 2;
15862
+ const tool2 = type === 2 && b.toolFormerData && typeof b.toolFormerData.name === "string" ? b.toolFormerData.name : null;
15863
+ const rawText = typeof b.text === "string" ? b.text : "";
15864
+ const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
15865
+ if (!text2 && !tool2)
15866
+ continue;
15867
+ const t = msFrom(b.createdAt);
15868
+ clock = Math.max(clock, t ?? clock + 1);
15869
+ const model = b.modelInfo && typeof b.modelInfo.modelName === "string" ? b.modelInfo.modelName : null;
15870
+ turns.push({ t: clock, type, text: text2, tool: tool2, model });
15871
+ }
15872
+ if (turns.length === 0)
15873
+ return null;
15874
+ const gitRepo = Array.isArray(cd.trackedGitRepos) && cd.trackedGitRepos[0] && typeof cd.trackedGitRepos[0].repoPath === "string" ? cd.trackedGitRepos[0].repoPath : null;
15875
+ return {
15876
+ composerId,
15877
+ createdAt: msFrom(cd.createdAt),
15878
+ updatedAt: msFrom(cd.lastUpdatedAt),
15879
+ name: typeof cd.name === "string" && cd.name.trim() ? cd.name.trim() : null,
15880
+ gitRepo,
15881
+ turns
15882
+ };
15883
+ }
15884
+ function sniffCursorRaw(raw) {
15885
+ for (const lineRaw of raw.split("\n")) {
15886
+ const line = lineRaw.trim();
15887
+ if (!line)
15888
+ continue;
15889
+ try {
15890
+ const e = JSON.parse(line);
15891
+ return (e.role === "user" || e.role === "assistant") && typeof e.message === "object" && e.message !== null && "content" in e.message && !("type" in e);
15892
+ } catch {
15893
+ return false;
15894
+ }
15895
+ }
15896
+ return false;
15897
+ }
15898
+ function jsonlText(content) {
15899
+ const parts = [];
15900
+ const tools = [];
15901
+ if (Array.isArray(content)) {
15902
+ for (const item of content) {
15903
+ if (!item || typeof item !== "object")
15904
+ continue;
15905
+ const it = item;
15906
+ if (it.type === "text" && it.text)
15907
+ parts.push(it.text);
15908
+ else if (it.type === "tool_use" && it.name)
15909
+ tools.push(it.name);
15910
+ }
15911
+ } else if (typeof content === "string")
15912
+ parts.push(content);
15913
+ return { text: parts.join("\n"), tools };
15914
+ }
15915
+ function parseCursorJsonl(raw, base) {
15916
+ const turns = [];
15917
+ let clock = base;
15918
+ for (const lineRaw of raw.split("\n")) {
15919
+ const line = lineRaw.trim();
15920
+ if (!line)
15921
+ continue;
15922
+ let e;
15923
+ try {
15924
+ e = JSON.parse(line);
15925
+ } catch {
15926
+ continue;
15927
+ }
15928
+ if (e.role !== "user" && e.role !== "assistant")
15929
+ continue;
15930
+ const { text: rawText, tools } = jsonlText(e.message?.content);
15931
+ const type = e.role === "user" ? 1 : 2;
15932
+ const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
15933
+ if (type === 2 && tools.length) {
15934
+ for (const tool2 of tools) {
15935
+ clock += 1;
15936
+ turns.push({ t: clock, type: 2, text: "", tool: tool2, model: null });
15937
+ }
15938
+ }
15939
+ if (!text2)
15940
+ continue;
15941
+ clock += 1;
15942
+ turns.push({ t: clock, type, text: text2, tool: null, model: null });
15943
+ }
15944
+ if (turns.length === 0)
15945
+ return null;
15946
+ return { composerId: "", createdAt: base, updatedAt: clock, name: null, gitRepo: null, turns };
15947
+ }
15948
+ var AI_GIST = 500;
15949
+ function renderCursorTranscript(c) {
15950
+ const lines = [];
15951
+ let humanTurns = 0, humanChars = 0;
15952
+ let aiProse = "";
15953
+ const aiTools = /* @__PURE__ */ new Map();
15954
+ const flushAI = () => {
15955
+ if (!aiProse && aiTools.size === 0)
15956
+ return;
15957
+ const tools = [...aiTools.entries()].map(([n, k]) => k > 1 ? `${n}\xD7${k}` : n).join(", ");
15958
+ const gist = aiProse ? aiProse.length > AI_GIST ? aiProse.slice(0, AI_GIST) + "\u2026" : aiProse : "";
15959
+ const bits = [];
15960
+ if (gist)
15961
+ bits.push(gist);
15962
+ if (tools)
15963
+ bits.push(`ran ${tools}`);
15964
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
15965
+ aiProse = "";
15966
+ aiTools.clear();
15967
+ };
15968
+ for (const turn of c.turns) {
15969
+ if (turn.type === 1) {
15970
+ flushAI();
15971
+ humanTurns++;
15972
+ humanChars += turn.text.length;
15973
+ lines.push(`>> ${turn.text}`);
15974
+ } else {
15975
+ if (turn.tool)
15976
+ aiTools.set(turn.tool, (aiTools.get(turn.tool) ?? 0) + 1);
15977
+ if (turn.text)
15978
+ aiProse = turn.text.replace(/\s+/g, " ").trim();
15979
+ }
15980
+ }
15981
+ flushAI();
15982
+ return { text: lines.join("\n"), humanTurns, humanChars };
15983
+ }
15984
+ function composerIdFromFile(file2) {
15985
+ const m = file2.match(/agent-transcripts\/([^/]+)\/[^/]+\.jsonl$/);
15986
+ return m ? m[1] : null;
15987
+ }
15988
+ async function loadCursorComposer(file2, raw, dbPath) {
15989
+ const cid = composerIdFromFile(file2);
15990
+ if (cid && dbPath) {
15991
+ const db = await openCursorSqlite(dbPath);
15992
+ if (db) {
15993
+ try {
15994
+ const c = readCursorComposer(db, cid);
15995
+ if (c)
15996
+ return c;
15997
+ } finally {
15998
+ db.close();
15999
+ }
16000
+ }
16001
+ }
16002
+ return parseCursorJsonl(raw, 0);
16003
+ }
16004
+
16005
+ // ../coding-core/dist/raw.js
16006
+ import path9 from "path";
16007
+ import os2 from "os";
16008
+ var SOURCE_ROOT_ENV_VARS = [
16009
+ "CLAUDE_PROJECTS_DIR",
16010
+ "CODEX_SESSIONS_DIR",
16011
+ "CURSOR_WORKSPACE_DIR",
16012
+ "CURSOR_PROJECTS_DIR",
16013
+ // Cursor's globalStorage dir (holds state.vscdb — the composer bubbles that
16014
+ // carry a Cursor session's real per-turn timestamps + content). Same
16015
+ // isolation contract: overriding any root disables every unset source.
16016
+ "CURSOR_GLOBAL_DIR"
16017
+ ];
16018
+ var anyRootOverridden = () => SOURCE_ROOT_ENV_VARS.some((v) => !!process.env[v]);
16019
+ function resolveSourceRoot(envVar, ...defaultSegments) {
16020
+ const explicit = process.env[envVar];
16021
+ if (explicit)
16022
+ return explicit;
16023
+ if (anyRootOverridden())
16024
+ return null;
16025
+ return path9.join(os2.homedir(), ...defaultSegments);
16026
+ }
16027
+ var cursorGlobalRoot = () => resolveSourceRoot("CURSOR_GLOBAL_DIR", "Library", "Application Support", "Cursor", "User", "globalStorage");
16028
+ function cursorGlobalDbPath() {
16029
+ const root = cursorGlobalRoot();
16030
+ return root === null ? null : path9.join(root, "state.vscdb");
16031
+ }
16032
+ var MACHINE_CURSOR_FILE_RE = /^(.*[/\\]machines[/\\][^/\\]+[/\\]\.cursor)[/\\]projects[/\\]/;
16033
+ function cursorDbPathForFile(file2) {
16034
+ const m = file2.match(MACHINE_CURSOR_FILE_RE);
16035
+ if (m)
16036
+ return path9.join(m[1], "globalStorage", "state.vscdb");
16037
+ return cursorGlobalDbPath();
16038
+ }
16039
+
15661
16040
  // ../../lib/agents/coding/materialize.ts
15662
- var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
16041
+ var SYSTEM_REMINDER_RE3 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
15663
16042
  var INJECT_GIST = 120;
15664
16043
  var INJECTED = [
15665
16044
  { re: /<task-notification>[\s\S]*?<\/task-notification>/g, label: "bg task", gistRe: /<summary>([\s\S]*?)<\/summary>/ },
@@ -15679,7 +16058,7 @@ function collapseInjected(input) {
15679
16058
  return "";
15680
16059
  });
15681
16060
  }
15682
- return { text: text2.replace(SYSTEM_REMINDER_RE, "").trim(), markers };
16061
+ return { text: text2.replace(SYSTEM_REMINDER_RE3, "").trim(), markers };
15683
16062
  }
15684
16063
  function extractText(content) {
15685
16064
  if (typeof content === "string") return content;
@@ -15695,14 +16074,52 @@ function extractText(content) {
15695
16074
  function isToolResultOnly(content) {
15696
16075
  return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
15697
16076
  }
15698
- var AI_GIST = 160;
16077
+ var AI_GIST2 = 160;
16078
+ function materializeCodex(raw) {
16079
+ const lines = [];
16080
+ let humanTurns = 0, humanChars = 0;
16081
+ let aiLastProse = "";
16082
+ const aiTools = /* @__PURE__ */ new Map();
16083
+ const flushAI = () => {
16084
+ if (!aiLastProse && aiTools.size === 0) return;
16085
+ const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
16086
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
16087
+ const bits = [];
16088
+ if (gist) bits.push(gist);
16089
+ if (tools) bits.push(`ran ${tools}`);
16090
+ lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
16091
+ aiLastProse = "";
16092
+ aiTools.clear();
16093
+ };
16094
+ for (const ev of extractCodexEvents(raw)) {
16095
+ if (ev.kind === "user") {
16096
+ flushAI();
16097
+ humanTurns++;
16098
+ humanChars += ev.text.length;
16099
+ lines.push(`>> ${ev.text}`);
16100
+ } else if (ev.kind === "assistant") {
16101
+ const prose = ev.text.replace(/\s+/g, " ").trim();
16102
+ if (prose) aiLastProse = prose;
16103
+ } else if (ev.kind === "tool") {
16104
+ aiTools.set(ev.name, (aiTools.get(ev.name) ?? 0) + 1);
16105
+ }
16106
+ }
16107
+ flushAI();
16108
+ return { text: lines.join("\n"), humanTurns, humanChars };
16109
+ }
16110
+ async function materializeCursor(file2, raw) {
16111
+ const composer = await loadCursorComposer(file2, raw, cursorDbPathForFile(file2));
16112
+ return composer ? renderCursorTranscript(composer) : { text: "", humanTurns: 0, humanChars: 0 };
16113
+ }
15699
16114
  async function materializeSession(file2) {
15700
16115
  let raw;
15701
16116
  try {
15702
- raw = await fs4.readFile(file2, "utf-8");
16117
+ raw = await fs5.readFile(file2, "utf-8");
15703
16118
  } catch {
15704
16119
  return null;
15705
16120
  }
16121
+ if (sniffCodexRaw(raw)) return materializeCodex(raw);
16122
+ if (sniffCursorRaw(raw)) return materializeCursor(file2, raw);
15706
16123
  const lines = [];
15707
16124
  let humanTurns = 0, humanChars = 0;
15708
16125
  const pendingQueued = [];
@@ -15715,7 +16132,7 @@ async function materializeSession(file2) {
15715
16132
  const flushAI = () => {
15716
16133
  if (!aiLastProse && aiTools.size === 0) return;
15717
16134
  const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
15718
- const gist = aiLastProse ? aiLastProse.length > AI_GIST ? aiLastProse.slice(0, AI_GIST) + "\u2026" : aiLastProse : "";
16135
+ const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
15719
16136
  const bits = [];
15720
16137
  if (gist) bits.push(gist);
15721
16138
  if (tools) bits.push(`ran ${tools}`);
@@ -15795,10 +16212,10 @@ async function materializeSession(file2) {
15795
16212
 
15796
16213
  // ../../lib/agents/coding/docsDir.ts
15797
16214
  async function writeScoreboard(codingDir, docs) {
15798
- const gradesDir = path9.join(codingDir, "grades");
16215
+ const gradesDir = path10.join(codingDir, "grades");
15799
16216
  let files = [];
15800
16217
  try {
15801
- files = (await fs5.readdir(gradesDir)).filter((f) => f.endsWith(".json")).sort();
16218
+ files = (await fs6.readdir(gradesDir)).filter((f) => f.endsWith(".json")).sort();
15802
16219
  } catch {
15803
16220
  return;
15804
16221
  }
@@ -15806,7 +16223,7 @@ async function writeScoreboard(codingDir, docs) {
15806
16223
  for (const f of files) {
15807
16224
  let g;
15808
16225
  try {
15809
- g = JSON.parse(await fs5.readFile(path9.join(gradesDir, f), "utf8"));
16226
+ g = JSON.parse(await fs6.readFile(path10.join(gradesDir, f), "utf8"));
15810
16227
  } catch {
15811
16228
  continue;
15812
16229
  }
@@ -15822,8 +16239,8 @@ async function writeScoreboard(codingDir, docs) {
15822
16239
  ([key, rows]) => `## ${key}
15823
16240
  ${rows.sort((a, b) => b.s - a.s).map((r) => r.line).join("\n")}`
15824
16241
  );
15825
- await fs5.writeFile(
15826
- path9.join(docs, "_scoreboard.md"),
16242
+ await fs6.writeFile(
16243
+ path10.join(docs, "_scoreboard.md"),
15827
16244
  `# Scoreboard \u2014 every graded session per criterion, best first.
15828
16245
  # Lx~ = estimate. Format: level \xB7 date \xB7 title \xB7 sessionId \u2014 graded instance.
15829
16246
 
@@ -15832,24 +16249,24 @@ ${blocks.join("\n\n")}
15832
16249
  );
15833
16250
  }
15834
16251
  async function ensureCodingDocs(codingDir, sessions) {
15835
- const docs = path9.join(codingDir, "docs");
15836
- await fs5.mkdir(docs, { recursive: true });
16252
+ const docs = path10.join(codingDir, "docs");
16253
+ await fs6.mkdir(docs, { recursive: true });
15837
16254
  const user = sessions.filter((s) => s.sessionId && !s.duplicateOf && (!("klass" in s) || s.klass === "interactive"));
15838
16255
  let written = 0;
15839
16256
  for (const s of user) {
15840
- const out = path9.join(docs, `${s.sessionId}.txt`);
16257
+ const out = path10.join(docs, `${s.sessionId}.txt`);
15841
16258
  try {
15842
- await fs5.access(out);
16259
+ await fs6.access(out);
15843
16260
  continue;
15844
16261
  } catch {
15845
16262
  }
15846
16263
  const mat = await materializeSession(s.file).catch(() => null);
15847
16264
  if (!mat?.text) continue;
15848
- await fs5.writeFile(out, mat.text);
16265
+ await fs6.writeFile(out, mat.text);
15849
16266
  written++;
15850
16267
  }
15851
16268
  const rows = user.sort((a, b) => (a.start ?? "") < (b.start ?? "") ? -1 : 1).map((s) => `${(s.start ?? "").slice(0, 10)} \xB7 ${(s.title ?? "").replace(/\n.*/s, "").slice(0, 80)} \xB7 ${s.sessionId}`);
15852
- await fs5.writeFile(path9.join(docs, "_map.md"), rows.join("\n") + "\n");
16269
+ await fs6.writeFile(path10.join(docs, "_map.md"), rows.join("\n") + "\n");
15853
16270
  await writeScoreboard(codingDir, docs);
15854
16271
  if (written) console.log(`[docs] materialized ${written} new transcript(s) \u2192 ${docs}`);
15855
16272
  return docs;
@@ -15877,7 +16294,7 @@ function applyExpertiseFloor(domains, min = MIN_EXPERTISE_SESSIONS) {
15877
16294
 
15878
16295
  // ../../lib/agents/coding/promptCache.ts
15879
16296
  import { createHash } from "crypto";
15880
- import { promises as fs6 } from "fs";
16297
+ import { promises as fs7 } from "fs";
15881
16298
  function promptSha(parts) {
15882
16299
  const h = createHash("sha256");
15883
16300
  for (const p of parts) {
@@ -15888,7 +16305,7 @@ function promptSha(parts) {
15888
16305
  }
15889
16306
  async function reusableOutput(outPath, sha, valid, key = "promptSha") {
15890
16307
  try {
15891
- const o = JSON.parse(await fs6.readFile(outPath, "utf8"));
16308
+ const o = JSON.parse(await fs7.readFile(outPath, "utf8"));
15892
16309
  if (o[key] === sha && valid(o)) return o;
15893
16310
  } catch {
15894
16311
  }
@@ -15896,7 +16313,7 @@ async function reusableOutput(outPath, sha, valid, key = "promptSha") {
15896
16313
  }
15897
16314
 
15898
16315
  // ../../lib/agents/coding/profile.ts
15899
- import path10 from "path";
16316
+ import path11 from "path";
15900
16317
 
15901
16318
  // ../../lib/calibration/fingerprint.ts
15902
16319
  import { createHash as createHash2 } from "node:crypto";
@@ -16050,7 +16467,7 @@ var TRANSCRIPT_LINE_RE = new RegExp(`^\\s*(${NOTE})((,| and) ${NOTE})*\\s*$|^\\s
16050
16467
 
16051
16468
  // ../../lib/calibration/index.ts
16052
16469
  var DEFAULT_CALIBRATION = {
16053
- version: "2026-07-16.2",
16470
+ version: "2026-07-21.1",
16054
16471
  // = RUBRIC_FINGERPRINT of the shipped npm rubric (packages/coding-analyzer/
16055
16472
  // src/grade/criteria.ts). A unit test fails loud when the rubric changes
16056
16473
  // without this being updated (and re-pushed to the server).
@@ -16146,13 +16563,14 @@ var DEFAULT_CALIBRATION = {
16146
16563
  },
16147
16564
  codingBenchmarks: {
16148
16565
  flow: {
16149
- // typical knowledge worker ≈ 35% of an 8h day focused; ~4h/day is the
16150
- // recognized deep-work ceiling (Newport) 50% most sit far below it.
16566
+ // typical knowledge worker ≈ 35% of an 8h day focused; the ~4h/day
16567
+ // deep-work ceiling (Newport) sits nearer ~40% of a real (9-10h) top
16568
+ // performer's day — 50% overstated it (owner call 2026-07-21).
16151
16569
  typicalPctOfDay: 0.35,
16152
- topPctOfDay: 0.5,
16570
+ topPctOfDay: 0.4,
16153
16571
  tag: "measured",
16154
- source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling)",
16155
- line: "the best spend ~half the workday in true deep flow; ~4h/day is the human ceiling"
16572
+ source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling against a 9-10h day)",
16573
+ line: "the best spend ~40% of the workday in true deep flow; ~4h/day is the human ceiling"
16156
16574
  },
16157
16575
  longestRun: {
16158
16576
  typicalHours: 0.67,
@@ -16201,12 +16619,12 @@ var BEST = DEFAULT_CALIBRATION.codingBenchmarks;
16201
16619
 
16202
16620
  // ../../lib/agents/coding/profile.ts
16203
16621
  var ROOT = process.cwd();
16204
- var CODING_DIR = process.env.POLYMATH_DATA_DIR ? path10.join(process.env.POLYMATH_DATA_DIR, "coding") : path10.join(ROOT, ".data", "coding");
16205
- var GRADES = path10.join(CODING_DIR, "grades");
16622
+ var CODING_DIR = process.env.POLYMATH_DATA_DIR ? path11.join(process.env.POLYMATH_DATA_DIR, "coding") : path11.join(ROOT, ".data", "coding");
16623
+ var GRADES = path11.join(CODING_DIR, "grades");
16206
16624
 
16207
16625
  // ../../scripts/coding-expertise.mts
16208
16626
  var CODING = CODING_DIR;
16209
- var OUTDIR = path11.join(CODING, "expertise");
16627
+ var OUTDIR = path12.join(CODING, "expertise");
16210
16628
  var CHUNK = 46e3;
16211
16629
  var concFlag = process.argv.indexOf("--conc");
16212
16630
  var CONC = concFlag >= 0 ? Math.max(1, Number(process.argv[concFlag + 1]) || 5) : 5;
@@ -16248,17 +16666,17 @@ async function pool(items, n, fn) {
16248
16666
  }
16249
16667
  async function main() {
16250
16668
  const aggOnly = process.argv.includes("--agg");
16251
- await fs7.mkdir(OUTDIR, { recursive: true });
16252
- const sessions = JSON.parse(await fs7.readFile(path11.join(CODING, "sessions.json"), "utf8"));
16669
+ await fs8.mkdir(OUTDIR, { recursive: true });
16670
+ const sessions = JSON.parse(await fs8.readFile(path12.join(CODING, "sessions.json"), "utf8"));
16253
16671
  const byId = new Map(sessions.map((s) => [s.sessionId, s]));
16254
- const gradeFiles = (await fs7.readdir(path11.join(CODING, "grades"))).filter((f) => f.endsWith(".json")).sort();
16672
+ const gradeFiles = (await fs8.readdir(path12.join(CODING, "grades"))).filter((f) => f.endsWith(".json")).sort();
16255
16673
  const ids = gradeFiles.map((f) => f.replace(".json", ""));
16256
16674
  if (!aggOnly) {
16257
16675
  let done = 0;
16258
16676
  await pool(ids, CONC, async (id) => {
16259
- const out = path11.join(OUTDIR, id + ".json");
16677
+ const out = path12.join(OUTDIR, id + ".json");
16260
16678
  try {
16261
- await fs7.access(out);
16679
+ await fs8.access(out);
16262
16680
  done++;
16263
16681
  return;
16264
16682
  } catch {
@@ -16267,7 +16685,7 @@ async function main() {
16267
16685
  if (!rec) return;
16268
16686
  const mat = await materializeSession(rec.file);
16269
16687
  if (!mat) return;
16270
- const sandbox = await fs7.mkdtemp(path11.join(os2.tmpdir(), "exp-"));
16688
+ const sandbox = await fs8.mkdtemp(path12.join(os3.tmpdir(), "exp-"));
16271
16689
  try {
16272
16690
  const chunks = chunkText(mat.text, CHUNK);
16273
16691
  const realExpertise = [];
@@ -16283,21 +16701,21 @@ async function main() {
16283
16701
  for (const d of j.domains || []) if (!domains.includes(d)) domains.push(d);
16284
16702
  if (j.summary) summaries.push(j.summary);
16285
16703
  }
16286
- await fs7.writeFile(out, JSON.stringify({ sessionId: id, date: rec.start?.slice(0, 10), title: rec.title, realExpertise, excluded, domains, summary: summaries.join(" ") }, null, 1));
16704
+ await fs8.writeFile(out, JSON.stringify({ sessionId: id, date: rec.start?.slice(0, 10), title: rec.title, realExpertise, excluded, domains, summary: summaries.join(" ") }, null, 1));
16287
16705
  done++;
16288
16706
  console.log(`[${done}/${ids.length}] ${rec.title} \u2014 ${realExpertise.length} real`);
16289
16707
  } catch (e) {
16290
16708
  console.log(`ERR ${rec.title}: ${e.message.slice(0, 80)}`);
16291
16709
  } finally {
16292
- await fs7.rm(sandbox, { recursive: true, force: true }).catch(() => {
16710
+ await fs8.rm(sandbox, { recursive: true, force: true }).catch(() => {
16293
16711
  });
16294
16712
  }
16295
16713
  });
16296
16714
  }
16297
16715
  const perSession = [];
16298
- for (const f of (await fs7.readdir(OUTDIR)).filter((f2) => f2.endsWith(".json")).sort()) {
16716
+ for (const f of (await fs8.readdir(OUTDIR)).filter((f2) => f2.endsWith(".json")).sort()) {
16299
16717
  try {
16300
- perSession.push(JSON.parse(await fs7.readFile(path11.join(OUTDIR, f), "utf8")));
16718
+ perSession.push(JSON.parse(await fs8.readFile(path12.join(OUTDIR, f), "utf8")));
16301
16719
  } catch {
16302
16720
  }
16303
16721
  }
@@ -16308,7 +16726,7 @@ async function main() {
16308
16726
  const prompt2 = aggPrompt(items, stats, titles);
16309
16727
  const sha = promptSha([AGG_SYSX, prompt2, "sonnet"]);
16310
16728
  if (!process.argv.includes("--refresh")) {
16311
- const prev = await reusableOutput(path11.join(CODING, "expertise.json"), sha, (o) => Array.isArray(o.domains));
16729
+ const prev = await reusableOutput(path12.join(CODING, "expertise.json"), sha, (o) => Array.isArray(o.domains));
16312
16730
  if (prev) {
16313
16731
  console.log(`[expertise] inputs unchanged \u2014 reusing aggregate from ${prev.generatedAt} (--refresh to regenerate)`);
16314
16732
  return;
@@ -16337,7 +16755,7 @@ async function main() {
16337
16755
  map.domains = kept;
16338
16756
  }
16339
16757
  if (!aggOk && !(map.domains || []).length) {
16340
- const existing = await fs7.readFile(path11.join(CODING, "expertise.json"), "utf8").then(JSON.parse).catch(() => null);
16758
+ const existing = await fs8.readFile(path12.join(CODING, "expertise.json"), "utf8").then(JSON.parse).catch(() => null);
16341
16759
  if (existing && (existing.domains || []).length) {
16342
16760
  console.log("AGG FAILED (0 domains) \u2014 keeping existing", existing.domains.length, "domains");
16343
16761
  return;
@@ -16345,7 +16763,7 @@ async function main() {
16345
16763
  console.log("AGG failed and no good existing file \u2014 writing empty");
16346
16764
  }
16347
16765
  const result = { generatedAt: (/* @__PURE__ */ new Date()).toISOString(), ...aggOk ? { promptSha: sha } : {}, ...stats, ...map };
16348
- await fs7.writeFile(path11.join(CODING, "expertise.json"), JSON.stringify(result, null, 2));
16766
+ await fs8.writeFile(path12.join(CODING, "expertise.json"), JSON.stringify(result, null, 2));
16349
16767
  console.log("\nWROTE .data/coding/expertise.json \u2014", (map.domains || []).length, "domains");
16350
16768
  }
16351
16769
  main().catch((e) => {