polymath-society 0.2.20 → 0.2.22
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 +23943 -21630
- package/dist/engine/chat-loops.js +8 -1
- package/dist/engine/exp-allfacets.js +8 -1
- package/dist/engine/exp-person.js +8 -1
- package/dist/engine/exp-pipeline.js +8 -1
- package/dist/engine/ingest-export.js +7 -6
- package/dist/engine/peak-demos.js +8 -1
- package/dist/engine/person-dimension-summary.js +8 -1
- package/dist/engine/person-facet-lines.js +8 -1
- package/dist/engine/person-headline.js +8 -1
- package/dist/engine/person-report.js +8 -1
- package/dist/engine/person-self-image.js +8 -1
- package/dist/engine/public-report.js +15 -7
- package/dist/engine/run-analysis.js +8 -1
- package/dist/engine/run-tagger.js +8 -1
- package/dist/index.js +19647 -17969
- package/dist/pipeline/coding-agglomerate.js +826 -82
- package/dist/pipeline/coding-aggregate.js +307 -23
- package/dist/pipeline/coding-build.js +453 -95
- package/dist/pipeline/coding-coaching.js +479 -88
- package/dist/pipeline/coding-day-digest.js +308 -36
- package/dist/pipeline/coding-delegation.js +376 -52
- package/dist/pipeline/coding-expertise.js +356 -62
- package/dist/pipeline/coding-flow.js +288 -15
- package/dist/pipeline/coding-focus.js +371 -51
- package/dist/pipeline/coding-frontier-detail.js +344 -50
- package/dist/pipeline/coding-frontier.js +7 -6
- package/dist/pipeline/coding-gap-dist.js +288 -15
- package/dist/pipeline/coding-gap.js +507 -115
- package/dist/pipeline/coding-grade.js +342 -45
- package/dist/pipeline/coding-growth.js +17041 -0
- package/dist/pipeline/coding-nutshell.js +15 -7
- package/dist/pipeline/coding-projects.js +7 -6
- package/dist/pipeline/coding-walkthrough.js +317 -37
- package/dist/pipeline/coding-workbrief.js +16387 -0
- package/dist/web/app.js +2095 -1395
- package/dist/web/styles.css +1 -1
- package/package.json +1 -1
|
@@ -134,13 +134,13 @@ var require_secure_json_parse = __commonJS({
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
// ../../scripts/coding-delegation.mts
|
|
137
|
-
import { promises as
|
|
138
|
-
import
|
|
137
|
+
import { promises as fs10 } from "fs";
|
|
138
|
+
import path13 from "path";
|
|
139
139
|
|
|
140
140
|
// ../../lib/agents/coding/delegation/detect.ts
|
|
141
|
-
import { promises as
|
|
142
|
-
import
|
|
143
|
-
import
|
|
141
|
+
import { promises as fs7 } 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
|
-
|
|
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:
|
|
2180
|
-
const fullPath = [...
|
|
2186
|
+
const { data, path: path14, errorMaps, issueData } = params;
|
|
2187
|
+
const fullPath = [...path14, ...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,
|
|
2303
|
+
constructor(parent, value, path14, key) {
|
|
2297
2304
|
this._cachedPath = [];
|
|
2298
2305
|
this.parent = parent;
|
|
2299
2306
|
this.data = value;
|
|
2300
|
-
this._path =
|
|
2307
|
+
this._path = path14;
|
|
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:
|
|
15094
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15101
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15108
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15114
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15120
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15126
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
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:
|
|
15147
|
+
url: ({ path: path14 }) => `${baseURL}${path14}`,
|
|
15141
15148
|
headers: getHeaders,
|
|
15142
15149
|
fetch: options.fetch
|
|
15143
15150
|
});
|
|
@@ -15659,7 +15666,7 @@ function invokeAgent(inv, opts = {}) {
|
|
|
15659
15666
|
}
|
|
15660
15667
|
|
|
15661
15668
|
// ../../lib/agents/coding/materialize.ts
|
|
15662
|
-
import { promises as
|
|
15669
|
+
import { promises as fs5 } from "fs";
|
|
15663
15670
|
|
|
15664
15671
|
// ../coding-core/dist/injected.js
|
|
15665
15672
|
var SYSTEM_REMINDER_RE = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
@@ -15798,6 +15805,286 @@ function codexPatchFiles(input) {
|
|
|
15798
15805
|
var CODEX_MUTATORS = /* @__PURE__ */ new Set(["apply_patch"]);
|
|
15799
15806
|
var CODEX_INVESTIGATORS = /* @__PURE__ */ new Set(["exec_command", "shell", "local_shell_call", "read_file", "list_dir", "grep", "web_search", "view_image"]);
|
|
15800
15807
|
|
|
15808
|
+
// ../coding-core/dist/cursor.js
|
|
15809
|
+
import { promises as fs4 } from "fs";
|
|
15810
|
+
var NODE_SQLITE = "node:sqlite";
|
|
15811
|
+
async function openCursorSqlite(dbPath) {
|
|
15812
|
+
try {
|
|
15813
|
+
await fs4.access(dbPath);
|
|
15814
|
+
} catch {
|
|
15815
|
+
return null;
|
|
15816
|
+
}
|
|
15817
|
+
let mod;
|
|
15818
|
+
try {
|
|
15819
|
+
mod = await import(NODE_SQLITE);
|
|
15820
|
+
} catch {
|
|
15821
|
+
return null;
|
|
15822
|
+
}
|
|
15823
|
+
const DatabaseSync = mod?.DatabaseSync;
|
|
15824
|
+
if (!DatabaseSync)
|
|
15825
|
+
return null;
|
|
15826
|
+
let db;
|
|
15827
|
+
try {
|
|
15828
|
+
db = new DatabaseSync(dbPath, { readOnly: true });
|
|
15829
|
+
} catch {
|
|
15830
|
+
try {
|
|
15831
|
+
db = new DatabaseSync(dbPath);
|
|
15832
|
+
} catch {
|
|
15833
|
+
return null;
|
|
15834
|
+
}
|
|
15835
|
+
}
|
|
15836
|
+
const asText = (v) => v == null ? null : typeof v === "string" ? v : Buffer.from(v).toString("utf-8");
|
|
15837
|
+
return {
|
|
15838
|
+
prefix(prefix) {
|
|
15839
|
+
try {
|
|
15840
|
+
const rows = db.prepare("SELECT key, value FROM cursorDiskKV WHERE key LIKE ? ESCAPE '\\'").all(likePrefix(prefix));
|
|
15841
|
+
return rows.map((r) => ({ key: r.key, value: asText(r.value) ?? "" }));
|
|
15842
|
+
} catch {
|
|
15843
|
+
return [];
|
|
15844
|
+
}
|
|
15845
|
+
},
|
|
15846
|
+
get(key) {
|
|
15847
|
+
try {
|
|
15848
|
+
const row = db.prepare("SELECT value FROM cursorDiskKV WHERE key = ?").get(key);
|
|
15849
|
+
return row ? asText(row.value) : null;
|
|
15850
|
+
} catch {
|
|
15851
|
+
return null;
|
|
15852
|
+
}
|
|
15853
|
+
},
|
|
15854
|
+
close() {
|
|
15855
|
+
try {
|
|
15856
|
+
db.close();
|
|
15857
|
+
} catch {
|
|
15858
|
+
}
|
|
15859
|
+
}
|
|
15860
|
+
};
|
|
15861
|
+
}
|
|
15862
|
+
function likePrefix(prefix) {
|
|
15863
|
+
return prefix.replace(/[\\%_]/g, (c) => "\\" + c) + "%";
|
|
15864
|
+
}
|
|
15865
|
+
var CURSOR_USER_QUERY_RE = /<user_query>\s*([\s\S]*?)\s*<\/user_query>/;
|
|
15866
|
+
function cleanUserText(raw) {
|
|
15867
|
+
let t = raw.replace(SYSTEM_REMINDER_RE, "");
|
|
15868
|
+
const m = t.match(CURSOR_USER_QUERY_RE);
|
|
15869
|
+
if (m)
|
|
15870
|
+
t = m[1];
|
|
15871
|
+
return t.trim();
|
|
15872
|
+
}
|
|
15873
|
+
var msFrom = (v) => {
|
|
15874
|
+
if (typeof v === "number" && Number.isFinite(v))
|
|
15875
|
+
return v;
|
|
15876
|
+
if (typeof v === "string") {
|
|
15877
|
+
const n = Date.parse(v);
|
|
15878
|
+
return Number.isFinite(n) ? n : null;
|
|
15879
|
+
}
|
|
15880
|
+
return null;
|
|
15881
|
+
};
|
|
15882
|
+
function readCursorComposer(db, composerId) {
|
|
15883
|
+
const cdRaw = db.get(`composerData:${composerId}`);
|
|
15884
|
+
if (!cdRaw)
|
|
15885
|
+
return null;
|
|
15886
|
+
let cd;
|
|
15887
|
+
try {
|
|
15888
|
+
cd = JSON.parse(cdRaw);
|
|
15889
|
+
} catch {
|
|
15890
|
+
return null;
|
|
15891
|
+
}
|
|
15892
|
+
const headers = Array.isArray(cd.fullConversationHeadersOnly) ? cd.fullConversationHeadersOnly : [];
|
|
15893
|
+
if (headers.length === 0)
|
|
15894
|
+
return null;
|
|
15895
|
+
const bubbles = /* @__PURE__ */ new Map();
|
|
15896
|
+
for (const row of db.prefix(`bubbleId:${composerId}:`)) {
|
|
15897
|
+
const bid = row.key.slice(`bubbleId:${composerId}:`.length);
|
|
15898
|
+
try {
|
|
15899
|
+
bubbles.set(bid, JSON.parse(row.value));
|
|
15900
|
+
} catch {
|
|
15901
|
+
}
|
|
15902
|
+
}
|
|
15903
|
+
const turns = [];
|
|
15904
|
+
let clock = msFrom(cd.createdAt) ?? 0;
|
|
15905
|
+
for (const h of headers) {
|
|
15906
|
+
const b = bubbles.get(h.bubbleId);
|
|
15907
|
+
if (!b)
|
|
15908
|
+
continue;
|
|
15909
|
+
const type = h.type === 1 ? 1 : 2;
|
|
15910
|
+
const tool2 = type === 2 && b.toolFormerData && typeof b.toolFormerData.name === "string" ? b.toolFormerData.name : null;
|
|
15911
|
+
const rawText = typeof b.text === "string" ? b.text : "";
|
|
15912
|
+
const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
|
|
15913
|
+
if (!text2 && !tool2)
|
|
15914
|
+
continue;
|
|
15915
|
+
const t = msFrom(b.createdAt);
|
|
15916
|
+
clock = Math.max(clock, t ?? clock + 1);
|
|
15917
|
+
const model = b.modelInfo && typeof b.modelInfo.modelName === "string" ? b.modelInfo.modelName : null;
|
|
15918
|
+
turns.push({ t: clock, type, text: text2, tool: tool2, model });
|
|
15919
|
+
}
|
|
15920
|
+
if (turns.length === 0)
|
|
15921
|
+
return null;
|
|
15922
|
+
const gitRepo = Array.isArray(cd.trackedGitRepos) && cd.trackedGitRepos[0] && typeof cd.trackedGitRepos[0].repoPath === "string" ? cd.trackedGitRepos[0].repoPath : null;
|
|
15923
|
+
return {
|
|
15924
|
+
composerId,
|
|
15925
|
+
createdAt: msFrom(cd.createdAt),
|
|
15926
|
+
updatedAt: msFrom(cd.lastUpdatedAt),
|
|
15927
|
+
name: typeof cd.name === "string" && cd.name.trim() ? cd.name.trim() : null,
|
|
15928
|
+
gitRepo,
|
|
15929
|
+
turns
|
|
15930
|
+
};
|
|
15931
|
+
}
|
|
15932
|
+
function sniffCursorRaw(raw) {
|
|
15933
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15934
|
+
const line = lineRaw.trim();
|
|
15935
|
+
if (!line)
|
|
15936
|
+
continue;
|
|
15937
|
+
try {
|
|
15938
|
+
const e = JSON.parse(line);
|
|
15939
|
+
return (e.role === "user" || e.role === "assistant") && typeof e.message === "object" && e.message !== null && "content" in e.message && !("type" in e);
|
|
15940
|
+
} catch {
|
|
15941
|
+
return false;
|
|
15942
|
+
}
|
|
15943
|
+
}
|
|
15944
|
+
return false;
|
|
15945
|
+
}
|
|
15946
|
+
function jsonlText(content) {
|
|
15947
|
+
const parts = [];
|
|
15948
|
+
const tools = [];
|
|
15949
|
+
if (Array.isArray(content)) {
|
|
15950
|
+
for (const item of content) {
|
|
15951
|
+
if (!item || typeof item !== "object")
|
|
15952
|
+
continue;
|
|
15953
|
+
const it = item;
|
|
15954
|
+
if (it.type === "text" && it.text)
|
|
15955
|
+
parts.push(it.text);
|
|
15956
|
+
else if (it.type === "tool_use" && it.name)
|
|
15957
|
+
tools.push(it.name);
|
|
15958
|
+
}
|
|
15959
|
+
} else if (typeof content === "string")
|
|
15960
|
+
parts.push(content);
|
|
15961
|
+
return { text: parts.join("\n"), tools };
|
|
15962
|
+
}
|
|
15963
|
+
function parseCursorJsonl(raw, base) {
|
|
15964
|
+
const turns = [];
|
|
15965
|
+
let clock = base;
|
|
15966
|
+
for (const lineRaw of raw.split("\n")) {
|
|
15967
|
+
const line = lineRaw.trim();
|
|
15968
|
+
if (!line)
|
|
15969
|
+
continue;
|
|
15970
|
+
let e;
|
|
15971
|
+
try {
|
|
15972
|
+
e = JSON.parse(line);
|
|
15973
|
+
} catch {
|
|
15974
|
+
continue;
|
|
15975
|
+
}
|
|
15976
|
+
if (e.role !== "user" && e.role !== "assistant")
|
|
15977
|
+
continue;
|
|
15978
|
+
const { text: rawText, tools } = jsonlText(e.message?.content);
|
|
15979
|
+
const type = e.role === "user" ? 1 : 2;
|
|
15980
|
+
const text2 = type === 1 ? cleanUserText(rawText) : rawText.replace(SYSTEM_REMINDER_RE, "").trim();
|
|
15981
|
+
if (type === 2 && tools.length) {
|
|
15982
|
+
for (const tool2 of tools) {
|
|
15983
|
+
clock += 1;
|
|
15984
|
+
turns.push({ t: clock, type: 2, text: "", tool: tool2, model: null });
|
|
15985
|
+
}
|
|
15986
|
+
}
|
|
15987
|
+
if (!text2)
|
|
15988
|
+
continue;
|
|
15989
|
+
clock += 1;
|
|
15990
|
+
turns.push({ t: clock, type, text: text2, tool: null, model: null });
|
|
15991
|
+
}
|
|
15992
|
+
if (turns.length === 0)
|
|
15993
|
+
return null;
|
|
15994
|
+
return { composerId: "", createdAt: base, updatedAt: clock, name: null, gitRepo: null, turns };
|
|
15995
|
+
}
|
|
15996
|
+
var AI_GIST = 500;
|
|
15997
|
+
function renderCursorTranscript(c) {
|
|
15998
|
+
const lines = [];
|
|
15999
|
+
let humanTurns = 0, humanChars = 0;
|
|
16000
|
+
let aiProse = "";
|
|
16001
|
+
const aiTools = /* @__PURE__ */ new Map();
|
|
16002
|
+
const flushAI = () => {
|
|
16003
|
+
if (!aiProse && aiTools.size === 0)
|
|
16004
|
+
return;
|
|
16005
|
+
const tools = [...aiTools.entries()].map(([n, k]) => k > 1 ? `${n}\xD7${k}` : n).join(", ");
|
|
16006
|
+
const gist = aiProse ? aiProse.length > AI_GIST ? aiProse.slice(0, AI_GIST) + "\u2026" : aiProse : "";
|
|
16007
|
+
const bits = [];
|
|
16008
|
+
if (gist)
|
|
16009
|
+
bits.push(gist);
|
|
16010
|
+
if (tools)
|
|
16011
|
+
bits.push(`ran ${tools}`);
|
|
16012
|
+
lines.push(`[AI: ${bits.join(" \xB7 ")}]`);
|
|
16013
|
+
aiProse = "";
|
|
16014
|
+
aiTools.clear();
|
|
16015
|
+
};
|
|
16016
|
+
for (const turn of c.turns) {
|
|
16017
|
+
if (turn.type === 1) {
|
|
16018
|
+
flushAI();
|
|
16019
|
+
humanTurns++;
|
|
16020
|
+
humanChars += turn.text.length;
|
|
16021
|
+
lines.push(`>> ${turn.text}`);
|
|
16022
|
+
} else {
|
|
16023
|
+
if (turn.tool)
|
|
16024
|
+
aiTools.set(turn.tool, (aiTools.get(turn.tool) ?? 0) + 1);
|
|
16025
|
+
if (turn.text)
|
|
16026
|
+
aiProse = turn.text.replace(/\s+/g, " ").trim();
|
|
16027
|
+
}
|
|
16028
|
+
}
|
|
16029
|
+
flushAI();
|
|
16030
|
+
return { text: lines.join("\n"), humanTurns, humanChars };
|
|
16031
|
+
}
|
|
16032
|
+
function composerIdFromFile(file2) {
|
|
16033
|
+
const m = file2.match(/agent-transcripts\/([^/]+)\/[^/]+\.jsonl$/);
|
|
16034
|
+
return m ? m[1] : null;
|
|
16035
|
+
}
|
|
16036
|
+
async function loadCursorComposer(file2, raw, dbPath) {
|
|
16037
|
+
const cid = composerIdFromFile(file2);
|
|
16038
|
+
if (cid && dbPath) {
|
|
16039
|
+
const db = await openCursorSqlite(dbPath);
|
|
16040
|
+
if (db) {
|
|
16041
|
+
try {
|
|
16042
|
+
const c = readCursorComposer(db, cid);
|
|
16043
|
+
if (c)
|
|
16044
|
+
return c;
|
|
16045
|
+
} finally {
|
|
16046
|
+
db.close();
|
|
16047
|
+
}
|
|
16048
|
+
}
|
|
16049
|
+
}
|
|
16050
|
+
return parseCursorJsonl(raw, 0);
|
|
16051
|
+
}
|
|
16052
|
+
|
|
16053
|
+
// ../coding-core/dist/raw.js
|
|
16054
|
+
import path9 from "path";
|
|
16055
|
+
import os2 from "os";
|
|
16056
|
+
var SOURCE_ROOT_ENV_VARS = [
|
|
16057
|
+
"CLAUDE_PROJECTS_DIR",
|
|
16058
|
+
"CODEX_SESSIONS_DIR",
|
|
16059
|
+
"CURSOR_WORKSPACE_DIR",
|
|
16060
|
+
"CURSOR_PROJECTS_DIR",
|
|
16061
|
+
// Cursor's globalStorage dir (holds state.vscdb — the composer bubbles that
|
|
16062
|
+
// carry a Cursor session's real per-turn timestamps + content). Same
|
|
16063
|
+
// isolation contract: overriding any root disables every unset source.
|
|
16064
|
+
"CURSOR_GLOBAL_DIR"
|
|
16065
|
+
];
|
|
16066
|
+
var anyRootOverridden = () => SOURCE_ROOT_ENV_VARS.some((v) => !!process.env[v]);
|
|
16067
|
+
function resolveSourceRoot(envVar, ...defaultSegments) {
|
|
16068
|
+
const explicit = process.env[envVar];
|
|
16069
|
+
if (explicit)
|
|
16070
|
+
return explicit;
|
|
16071
|
+
if (anyRootOverridden())
|
|
16072
|
+
return null;
|
|
16073
|
+
return path9.join(os2.homedir(), ...defaultSegments);
|
|
16074
|
+
}
|
|
16075
|
+
var cursorGlobalRoot = () => resolveSourceRoot("CURSOR_GLOBAL_DIR", "Library", "Application Support", "Cursor", "User", "globalStorage");
|
|
16076
|
+
function cursorGlobalDbPath() {
|
|
16077
|
+
const root = cursorGlobalRoot();
|
|
16078
|
+
return root === null ? null : path9.join(root, "state.vscdb");
|
|
16079
|
+
}
|
|
16080
|
+
var MACHINE_CURSOR_FILE_RE = /^(.*[/\\]machines[/\\][^/\\]+[/\\]\.cursor)[/\\]projects[/\\]/;
|
|
16081
|
+
function cursorDbPathForFile(file2) {
|
|
16082
|
+
const m = file2.match(MACHINE_CURSOR_FILE_RE);
|
|
16083
|
+
if (m)
|
|
16084
|
+
return path9.join(m[1], "globalStorage", "state.vscdb");
|
|
16085
|
+
return cursorGlobalDbPath();
|
|
16086
|
+
}
|
|
16087
|
+
|
|
15801
16088
|
// ../../lib/agents/coding/materialize.ts
|
|
15802
16089
|
var SYSTEM_REMINDER_RE3 = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
15803
16090
|
var INJECT_GIST = 120;
|
|
@@ -15835,7 +16122,7 @@ function extractText(content) {
|
|
|
15835
16122
|
function isToolResultOnly(content) {
|
|
15836
16123
|
return Array.isArray(content) && content.length > 0 && content.every((c) => c && typeof c === "object" && c.type === "tool_result");
|
|
15837
16124
|
}
|
|
15838
|
-
var
|
|
16125
|
+
var AI_GIST2 = 160;
|
|
15839
16126
|
function materializeCodex(raw) {
|
|
15840
16127
|
const lines = [];
|
|
15841
16128
|
let humanTurns = 0, humanChars = 0;
|
|
@@ -15844,7 +16131,7 @@ function materializeCodex(raw) {
|
|
|
15844
16131
|
const flushAI = () => {
|
|
15845
16132
|
if (!aiLastProse && aiTools.size === 0) return;
|
|
15846
16133
|
const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
|
|
15847
|
-
const gist = aiLastProse ? aiLastProse.length >
|
|
16134
|
+
const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
|
|
15848
16135
|
const bits = [];
|
|
15849
16136
|
if (gist) bits.push(gist);
|
|
15850
16137
|
if (tools) bits.push(`ran ${tools}`);
|
|
@@ -15868,14 +16155,19 @@ function materializeCodex(raw) {
|
|
|
15868
16155
|
flushAI();
|
|
15869
16156
|
return { text: lines.join("\n"), humanTurns, humanChars };
|
|
15870
16157
|
}
|
|
16158
|
+
async function materializeCursor(file2, raw) {
|
|
16159
|
+
const composer = await loadCursorComposer(file2, raw, cursorDbPathForFile(file2));
|
|
16160
|
+
return composer ? renderCursorTranscript(composer) : { text: "", humanTurns: 0, humanChars: 0 };
|
|
16161
|
+
}
|
|
15871
16162
|
async function materializeSession(file2) {
|
|
15872
16163
|
let raw;
|
|
15873
16164
|
try {
|
|
15874
|
-
raw = await
|
|
16165
|
+
raw = await fs5.readFile(file2, "utf-8");
|
|
15875
16166
|
} catch {
|
|
15876
16167
|
return null;
|
|
15877
16168
|
}
|
|
15878
16169
|
if (sniffCodexRaw(raw)) return materializeCodex(raw);
|
|
16170
|
+
if (sniffCursorRaw(raw)) return materializeCursor(file2, raw);
|
|
15879
16171
|
const lines = [];
|
|
15880
16172
|
let humanTurns = 0, humanChars = 0;
|
|
15881
16173
|
const pendingQueued = [];
|
|
@@ -15888,7 +16180,7 @@ async function materializeSession(file2) {
|
|
|
15888
16180
|
const flushAI = () => {
|
|
15889
16181
|
if (!aiLastProse && aiTools.size === 0) return;
|
|
15890
16182
|
const tools = [...aiTools.entries()].map(([n, c]) => c > 1 ? `${n}\xD7${c}` : n).join(", ");
|
|
15891
|
-
const gist = aiLastProse ? aiLastProse.length >
|
|
16183
|
+
const gist = aiLastProse ? aiLastProse.length > AI_GIST2 ? aiLastProse.slice(0, AI_GIST2) + "\u2026" : aiLastProse : "";
|
|
15892
16184
|
const bits = [];
|
|
15893
16185
|
if (gist) bits.push(gist);
|
|
15894
16186
|
if (tools) bits.push(`ran ${tools}`);
|
|
@@ -15967,7 +16259,7 @@ async function materializeSession(file2) {
|
|
|
15967
16259
|
}
|
|
15968
16260
|
|
|
15969
16261
|
// ../coding-core/dist/delegation/parse.js
|
|
15970
|
-
import { promises as
|
|
16262
|
+
import { promises as fs6 } from "fs";
|
|
15971
16263
|
var MUTATORS = /* @__PURE__ */ new Set(["Edit", "Write", "MultiEdit", "NotebookEdit"]);
|
|
15972
16264
|
var INVESTIGATORS = /* @__PURE__ */ new Set(["Read", "Grep", "Glob", "Bash", "ToolSearch", "WebSearch", "WebFetch"]);
|
|
15973
16265
|
var CORRECTIVE_RE = /\b(fix|still|again|nope?|broken|revert|undo|wrong|same (error|issue|thing|problem|bug)|doesn'?t work|not work(ing)?|didn'?t work|that'?s not|try (again|to)|no it|it'?s still|its still|stop|keeps?|why (is|isn'?t)|do (this|that|it)|make it)\b/i;
|
|
@@ -16049,15 +16341,46 @@ function parseCodexTurns(raw) {
|
|
|
16049
16341
|
}
|
|
16050
16342
|
return turns;
|
|
16051
16343
|
}
|
|
16344
|
+
var CURSOR_MUTATOR_RE = /edit|write|replace|delete|patch|reapply|create/i;
|
|
16345
|
+
var CURSOR_INVESTIGATOR_RE = /read|search|grep|list|terminal|glob|fetch|run/i;
|
|
16346
|
+
async function parseCursorTurns(file2, raw) {
|
|
16347
|
+
const c = await loadCursorComposer(file2, raw, cursorDbPathForFile(file2));
|
|
16348
|
+
if (!c)
|
|
16349
|
+
return [];
|
|
16350
|
+
const turns = [];
|
|
16351
|
+
let cur = null;
|
|
16352
|
+
let idx = 0;
|
|
16353
|
+
for (const turn of c.turns) {
|
|
16354
|
+
if (turn.type === 1) {
|
|
16355
|
+
const text2 = humanTypedText(turn.text);
|
|
16356
|
+
if (!text2)
|
|
16357
|
+
continue;
|
|
16358
|
+
cur = newTurn(idx++, turn.t, text2);
|
|
16359
|
+
turns.push(cur);
|
|
16360
|
+
} else if (cur) {
|
|
16361
|
+
if (turn.tool) {
|
|
16362
|
+
if (CURSOR_MUTATOR_RE.test(turn.tool))
|
|
16363
|
+
cur.edits++;
|
|
16364
|
+
else if (CURSOR_INVESTIGATOR_RE.test(turn.tool))
|
|
16365
|
+
cur.investigations++;
|
|
16366
|
+
}
|
|
16367
|
+
if (turn.text && STRUGGLE_RE.test(turn.text))
|
|
16368
|
+
cur.aiStruggle++;
|
|
16369
|
+
}
|
|
16370
|
+
}
|
|
16371
|
+
return turns;
|
|
16372
|
+
}
|
|
16052
16373
|
async function parseSession(file2) {
|
|
16053
16374
|
let raw;
|
|
16054
16375
|
try {
|
|
16055
|
-
raw = await
|
|
16376
|
+
raw = await fs6.readFile(file2, "utf-8");
|
|
16056
16377
|
} catch {
|
|
16057
16378
|
return [];
|
|
16058
16379
|
}
|
|
16059
16380
|
if (sniffCodexRaw(raw))
|
|
16060
16381
|
return parseCodexTurns(raw);
|
|
16382
|
+
if (sniffCursorRaw(raw))
|
|
16383
|
+
return parseCursorTurns(file2, raw);
|
|
16061
16384
|
const turns = [];
|
|
16062
16385
|
let cur = null;
|
|
16063
16386
|
let idx = 0;
|
|
@@ -16250,7 +16573,7 @@ async function detectDelegation(rec, opts = {}) {
|
|
|
16250
16573
|
let meta = {};
|
|
16251
16574
|
if (candidates.length > 0) {
|
|
16252
16575
|
const mat = await materializeSession(rec.file);
|
|
16253
|
-
const sandbox = await
|
|
16576
|
+
const sandbox = await fs7.mkdtemp(path10.join(os3.tmpdir(), "ps-deleg-"));
|
|
16254
16577
|
try {
|
|
16255
16578
|
const run2 = await invokeAgent({
|
|
16256
16579
|
prompt: buildPrompt(rec, mat?.text ?? "", candidates),
|
|
@@ -16260,7 +16583,7 @@ async function detectDelegation(rec, opts = {}) {
|
|
|
16260
16583
|
maxTurns: 6,
|
|
16261
16584
|
timeoutMs: 3e5,
|
|
16262
16585
|
model: opts.model ?? "sonnet",
|
|
16263
|
-
logPath: opts.logDir ?
|
|
16586
|
+
logPath: opts.logDir ? path10.join(opts.logDir, `${rec.sessionId}.log`) : void 0
|
|
16264
16587
|
});
|
|
16265
16588
|
const j = run2.json ?? {};
|
|
16266
16589
|
context = String(j.context ?? "").slice(0, 900);
|
|
@@ -16276,7 +16599,7 @@ async function detectDelegation(rec, opts = {}) {
|
|
|
16276
16599
|
}).filter((l) => l.confirmed);
|
|
16277
16600
|
meta = { costUsd: run2.costUsd, durationMs: run2.durationMs };
|
|
16278
16601
|
} finally {
|
|
16279
|
-
await
|
|
16602
|
+
await fs7.rm(sandbox, { recursive: true, force: true }).catch(() => {
|
|
16280
16603
|
});
|
|
16281
16604
|
}
|
|
16282
16605
|
}
|
|
@@ -16292,16 +16615,16 @@ async function detectDelegation(rec, opts = {}) {
|
|
|
16292
16615
|
meta
|
|
16293
16616
|
};
|
|
16294
16617
|
if (opts.outDir) {
|
|
16295
|
-
await
|
|
16296
|
-
await
|
|
16618
|
+
await fs7.mkdir(opts.outDir, { recursive: true });
|
|
16619
|
+
await fs7.writeFile(path10.join(opts.outDir, `${rec.sessionId}.json`), JSON.stringify(read, null, 2));
|
|
16297
16620
|
}
|
|
16298
16621
|
return read;
|
|
16299
16622
|
}
|
|
16300
16623
|
|
|
16301
16624
|
// ../../lib/agents/coding/delegation/rollup.ts
|
|
16302
|
-
import { promises as
|
|
16303
|
-
import
|
|
16304
|
-
import
|
|
16625
|
+
import { promises as fs8 } from "fs";
|
|
16626
|
+
import os4 from "os";
|
|
16627
|
+
import path11 from "path";
|
|
16305
16628
|
var median2 = (xs) => {
|
|
16306
16629
|
if (!xs.length) return 0;
|
|
16307
16630
|
const s = [...xs].sort((a, b) => a - b);
|
|
@@ -16357,7 +16680,7 @@ async function rollupDelegation(reads, records, opts = {}) {
|
|
|
16357
16680
|
}
|
|
16358
16681
|
const exemplars = ranked.map((r) => ({ sessionId: r.sessionId, title: r.title, openingChars: r.overDrive.openingChars }));
|
|
16359
16682
|
if (samples.length) {
|
|
16360
|
-
const sandbox = await
|
|
16683
|
+
const sandbox = await fs8.mkdtemp(path11.join(os4.tmpdir(), "ps-deleg-roll-"));
|
|
16361
16684
|
try {
|
|
16362
16685
|
const run2 = await invokeAgent({
|
|
16363
16686
|
prompt: buildPrompt2(samples),
|
|
@@ -16378,7 +16701,7 @@ async function rollupDelegation(reads, records, opts = {}) {
|
|
|
16378
16701
|
exemplars
|
|
16379
16702
|
};
|
|
16380
16703
|
} finally {
|
|
16381
|
-
await
|
|
16704
|
+
await fs8.rm(sandbox, { recursive: true, force: true }).catch(() => {
|
|
16382
16705
|
});
|
|
16383
16706
|
}
|
|
16384
16707
|
}
|
|
@@ -16439,7 +16762,7 @@ function aiWindowCutoff(sessions, opts = {}) {
|
|
|
16439
16762
|
|
|
16440
16763
|
// ../../lib/agents/coding/promptCache.ts
|
|
16441
16764
|
import { createHash } from "crypto";
|
|
16442
|
-
import { promises as
|
|
16765
|
+
import { promises as fs9 } from "fs";
|
|
16443
16766
|
function promptSha(parts) {
|
|
16444
16767
|
const h = createHash("sha256");
|
|
16445
16768
|
for (const p of parts) {
|
|
@@ -16450,7 +16773,7 @@ function promptSha(parts) {
|
|
|
16450
16773
|
}
|
|
16451
16774
|
async function reusableOutput(outPath, sha, valid, key = "promptSha") {
|
|
16452
16775
|
try {
|
|
16453
|
-
const o = JSON.parse(await
|
|
16776
|
+
const o = JSON.parse(await fs9.readFile(outPath, "utf8"));
|
|
16454
16777
|
if (o[key] === sha && valid(o)) return o;
|
|
16455
16778
|
} catch {
|
|
16456
16779
|
}
|
|
@@ -16458,7 +16781,7 @@ async function reusableOutput(outPath, sha, valid, key = "promptSha") {
|
|
|
16458
16781
|
}
|
|
16459
16782
|
|
|
16460
16783
|
// ../../lib/agents/coding/profile.ts
|
|
16461
|
-
import
|
|
16784
|
+
import path12 from "path";
|
|
16462
16785
|
|
|
16463
16786
|
// ../../lib/calibration/fingerprint.ts
|
|
16464
16787
|
import { createHash as createHash2 } from "node:crypto";
|
|
@@ -16612,7 +16935,7 @@ var TRANSCRIPT_LINE_RE = new RegExp(`^\\s*(${NOTE})((,| and) ${NOTE})*\\s*$|^\\s
|
|
|
16612
16935
|
|
|
16613
16936
|
// ../../lib/calibration/index.ts
|
|
16614
16937
|
var DEFAULT_CALIBRATION = {
|
|
16615
|
-
version: "2026-07-
|
|
16938
|
+
version: "2026-07-21.1",
|
|
16616
16939
|
// = RUBRIC_FINGERPRINT of the shipped npm rubric (packages/coding-analyzer/
|
|
16617
16940
|
// src/grade/criteria.ts). A unit test fails loud when the rubric changes
|
|
16618
16941
|
// without this being updated (and re-pushed to the server).
|
|
@@ -16708,13 +17031,14 @@ var DEFAULT_CALIBRATION = {
|
|
|
16708
17031
|
},
|
|
16709
17032
|
codingBenchmarks: {
|
|
16710
17033
|
flow: {
|
|
16711
|
-
// typical knowledge worker ≈ 35% of an 8h day focused; ~4h/day
|
|
16712
|
-
//
|
|
17034
|
+
// typical knowledge worker ≈ 35% of an 8h day focused; the ~4h/day
|
|
17035
|
+
// deep-work ceiling (Newport) sits nearer ~40% of a real (9-10h) top
|
|
17036
|
+
// performer's day — 50% overstated it (owner call 2026-07-21).
|
|
16713
17037
|
typicalPctOfDay: 0.35,
|
|
16714
|
-
topPctOfDay: 0.
|
|
17038
|
+
topPctOfDay: 0.4,
|
|
16715
17039
|
tag: "measured",
|
|
16716
|
-
source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling)",
|
|
16717
|
-
line: "the best spend ~
|
|
17040
|
+
source: "RescueTime 2019 (~2h48m focused/day) \xB7 Cal Newport, Deep Work (~4h/day deep-work ceiling against a 9-10h day)",
|
|
17041
|
+
line: "the best spend ~40% of the workday in true deep flow; ~4h/day is the human ceiling"
|
|
16718
17042
|
},
|
|
16719
17043
|
longestRun: {
|
|
16720
17044
|
typicalHours: 0.67,
|
|
@@ -16763,8 +17087,8 @@ var BEST = DEFAULT_CALIBRATION.codingBenchmarks;
|
|
|
16763
17087
|
|
|
16764
17088
|
// ../../lib/agents/coding/profile.ts
|
|
16765
17089
|
var ROOT = process.cwd();
|
|
16766
|
-
var CODING_DIR = process.env.POLYMATH_DATA_DIR ?
|
|
16767
|
-
var GRADES =
|
|
17090
|
+
var CODING_DIR = process.env.POLYMATH_DATA_DIR ? path12.join(process.env.POLYMATH_DATA_DIR, "coding") : path12.join(ROOT, ".data", "coding");
|
|
17091
|
+
var GRADES = path12.join(CODING_DIR, "grades");
|
|
16768
17092
|
|
|
16769
17093
|
// ../../scripts/coding-delegation.mts
|
|
16770
17094
|
var argv = process.argv.slice(2);
|
|
@@ -16792,10 +17116,10 @@ function makeLimiter(max) {
|
|
|
16792
17116
|
};
|
|
16793
17117
|
}
|
|
16794
17118
|
var CODING = CODING_DIR;
|
|
16795
|
-
var OUT =
|
|
16796
|
-
var LOGS =
|
|
17119
|
+
var OUT = path13.join(CODING, "delegation");
|
|
17120
|
+
var LOGS = path13.join(OUT, "logs");
|
|
16797
17121
|
async function main() {
|
|
16798
|
-
const sessions = JSON.parse(await
|
|
17122
|
+
const sessions = JSON.parse(await fs10.readFile(path13.join(CODING, "sessions.json"), "utf8"));
|
|
16799
17123
|
const live = sessions.filter((s) => s.klass === "interactive" && !s.duplicateOf);
|
|
16800
17124
|
const { gradable: allGradable } = partition(live);
|
|
16801
17125
|
const cutoff = aiWindowCutoff(live);
|
|
@@ -16805,7 +17129,7 @@ async function main() {
|
|
|
16805
17129
|
const set = new Set(IDS);
|
|
16806
17130
|
picked = live.filter((s) => set.has(s.sessionId));
|
|
16807
17131
|
} else if (N > 0) picked = gradable.slice().sort((a, b) => b.humanChars * Math.log1p(b.humanTurns) - a.humanChars * Math.log1p(a.humanTurns)).slice(0, N);
|
|
16808
|
-
await
|
|
17132
|
+
await fs10.mkdir(LOGS, { recursive: true });
|
|
16809
17133
|
console.log(`[delegation] ${live.length} live \xB7 ${allGradable.length} gradable${cutoff ? ` \xB7 ${gradable.length} since ${cutoff.slice(0, 10)} (AI window)` : ""} \xB7 running detect on ${picked.length} (LLM only on stuck-loop candidates)\u2026`);
|
|
16810
17134
|
const lim = makeLimiter(CONC);
|
|
16811
17135
|
let reused = 0;
|
|
@@ -16813,7 +17137,7 @@ async function main() {
|
|
|
16813
17137
|
const reads = (await Promise.all(picked.map((s) => lim(async () => {
|
|
16814
17138
|
if (!REFRESH) {
|
|
16815
17139
|
try {
|
|
16816
|
-
const prev = JSON.parse(await
|
|
17140
|
+
const prev = JSON.parse(await fs10.readFile(path13.join(OUT, `${s.sessionId}.json`), "utf8"));
|
|
16817
17141
|
reused++;
|
|
16818
17142
|
tick(true);
|
|
16819
17143
|
return prev;
|
|
@@ -16835,13 +17159,13 @@ async function main() {
|
|
|
16835
17159
|
if (reused) console.log(`[delegation] reused ${reused} existing per-session read(s) (--refresh to re-detect)`);
|
|
16836
17160
|
const stable = reads.map((r) => ({ id: r.sessionId, loops: r.stuckLoops, od: r.overDrive })).sort((a, b) => a.id < b.id ? -1 : 1);
|
|
16837
17161
|
const sha = promptSha([JSON.stringify(stable), MODEL]);
|
|
16838
|
-
const rollupPath =
|
|
17162
|
+
const rollupPath = path13.join(CODING, "delegation-rollup.json");
|
|
16839
17163
|
let rollup = REFRESH ? null : await reusableOutput(rollupPath, sha, (o) => typeof o.sessions === "number");
|
|
16840
17164
|
if (rollup) console.log(`[delegation] rollup inputs unchanged \u2014 reusing (--refresh to regenerate)`);
|
|
16841
17165
|
else {
|
|
16842
17166
|
console.log(`[delegation] corpus rollup (Case A count + Case B over-drive judgment)\u2026`);
|
|
16843
17167
|
rollup = { ...await rollupDelegation(reads, live, { model: MODEL }), promptSha: sha };
|
|
16844
|
-
await
|
|
17168
|
+
await fs10.writeFile(rollupPath, JSON.stringify(rollup, null, 2));
|
|
16845
17169
|
}
|
|
16846
17170
|
console.log(`
|
|
16847
17171
|
\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550 DELEGATION \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|