p-backlog 0.14.2 → 0.14.4
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/CHANGELOG.md +11 -0
- package/README.md +2 -2
- package/README.ru.md +2 -2
- package/dist/cli.js +287 -79
- package/dist/web/assets/{CodeTab-CDs1rBQ4.js → CodeTab-rgZ3oazM.js} +1 -1
- package/dist/web/assets/{CostTab-0qQD79v5.js → CostTab-DR8zJt7h.js} +1 -1
- package/dist/web/assets/{EffectTab-BJjnWEFn.js → EffectTab-DHdQSIlQ.js} +1 -1
- package/dist/web/assets/{Figure-D-jQZK8c.js → Figure-C2iLoqkF.js} +1 -1
- package/dist/web/assets/{OverviewTab-C74Mmsvu.js → OverviewTab-uNqeJSFu.js} +1 -1
- package/dist/web/assets/{Page-CMSrvnaH.js → Page-lpBrfWDj.js} +5 -5
- package/dist/web/assets/QualityTab-hbgPdBwD.js +1 -0
- package/dist/web/assets/{ShareBar-L0ptVurZ.js → ShareBar-BXak6vBR.js} +1 -1
- package/dist/web/assets/{StatsPage-QktIPzjO.js → StatsPage-CO1e1tAe.js} +1 -1
- package/dist/web/assets/{StatsTabState-C02XxbTe.js → StatsTabState-ChT0Ee4K.js} +1 -1
- package/dist/web/assets/{StatsTable-Bvr5i9ml.js → StatsTable-C0PeMtyw.js} +1 -1
- package/dist/web/assets/{UnavailableRepos-RvbbMApI.js → UnavailableRepos-CykRKvjj.js} +1 -1
- package/dist/web/assets/{index-BGSxDtU7.js → index-BuEw4eHx.js} +2 -2
- package/dist/web/assets/{start-wvWuktPy.js → start-CmS4D9jZ.js} +4 -4
- package/dist/web/assets/use-grain-panel-BrOKdaLI.js +69 -0
- package/dist/web/assets/{web-paths-DlvG-pBV.js → web-paths-B6f4e9Br.js} +1 -1
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/QualityTab-AoOwwbKW.js +0 -1
- package/dist/web/assets/use-grain-panel-Dyp91zsL.js +0 -69
package/dist/cli.js
CHANGED
|
@@ -115,7 +115,7 @@ var SERVE_COMMAND_NAME = "serve";
|
|
|
115
115
|
|
|
116
116
|
// src/cli/main.ts
|
|
117
117
|
import { homedir } from "node:os";
|
|
118
|
-
import { dirname as dirname13, resolve as
|
|
118
|
+
import { dirname as dirname13, resolve as resolve7 } from "node:path";
|
|
119
119
|
import { fileURLToPath } from "node:url";
|
|
120
120
|
|
|
121
121
|
// src/core/store/runs.ts
|
|
@@ -1171,12 +1171,12 @@ import { execFile } from "node:child_process";
|
|
|
1171
1171
|
var NOT_FOUND = 127;
|
|
1172
1172
|
var FAILED = 1;
|
|
1173
1173
|
function execProgram(file, args, { timeoutMs } = {}) {
|
|
1174
|
-
return new Promise((
|
|
1174
|
+
return new Promise((resolve8) => {
|
|
1175
1175
|
execFile(file, args, { timeout: timeoutMs }, (error, stdout, stderr) => {
|
|
1176
1176
|
const output = `${stdout}${stderr}`.trim();
|
|
1177
|
-
if (error === null)
|
|
1178
|
-
else if (error.code === "ENOENT")
|
|
1179
|
-
else
|
|
1177
|
+
if (error === null) resolve8({ code: 0, output });
|
|
1178
|
+
else if (error.code === "ENOENT") resolve8({ code: NOT_FOUND, output: error.message });
|
|
1179
|
+
else resolve8({ code: typeof error.code === "number" ? error.code : FAILED, output: output || error.message });
|
|
1180
1180
|
});
|
|
1181
1181
|
});
|
|
1182
1182
|
}
|
|
@@ -1873,6 +1873,9 @@ function hookMessage(language, projectId, text) {
|
|
|
1873
1873
|
function isBacklogHookFeedback(text) {
|
|
1874
1874
|
return text.startsWith(STOP_HOOK_FEEDBACK_PREFIX) && LANGUAGES.some((language) => text.includes(`${coreMessages(language).hookMark} `));
|
|
1875
1875
|
}
|
|
1876
|
+
function isBacklogHookReason(text) {
|
|
1877
|
+
return /^\S+ [^\s:]+:/u.test(text) && LANGUAGES.some((language) => text.startsWith(`${coreMessages(language).hookMark} `));
|
|
1878
|
+
}
|
|
1876
1879
|
|
|
1877
1880
|
// src/core/store/journal-compaction.ts
|
|
1878
1881
|
import { basename as basename4, join as join10 } from "node:path";
|
|
@@ -1959,7 +1962,8 @@ var journalEventSchema = z7.discriminatedUnion("kind", [
|
|
|
1959
1962
|
mode: recordedEnum(CHECK_MODES),
|
|
1960
1963
|
method: recordedEnum(CHECK_METHODS).optional(),
|
|
1961
1964
|
...legacyMethodFlagsSchema.shape,
|
|
1962
|
-
match: recordedEnum(DUPLICATE_MATCHES).optional()
|
|
1965
|
+
match: recordedEnum(DUPLICATE_MATCHES).optional(),
|
|
1966
|
+
model: z7.string().trim().min(1).optional().catch(void 0)
|
|
1963
1967
|
}),
|
|
1964
1968
|
z7.object({ ...eventBase, kind: z7.literal("candidate-gone"), evidence: z7.enum(CANDIDATE_EVIDENCE) }),
|
|
1965
1969
|
z7.object({ ...eventBase, kind: z7.literal("candidate-filtered"), symbol: z7.string() })
|
|
@@ -2044,7 +2048,7 @@ function snapshotOf(task) {
|
|
|
2044
2048
|
}
|
|
2045
2049
|
|
|
2046
2050
|
// src/core/journal/episodes.ts
|
|
2047
|
-
function candidateEvents(sightings, states, now, mode) {
|
|
2051
|
+
function candidateEvents(sightings, states, now, mode, model) {
|
|
2048
2052
|
const at = formatLocalIso(now);
|
|
2049
2053
|
return dedupeSightings(sightings).filter((sighting) => states.get(episodeKey(sighting.task, sighting.evidence)) !== "open").map((sighting) => ({
|
|
2050
2054
|
at,
|
|
@@ -2054,7 +2058,8 @@ function candidateEvents(sightings, states, now, mode) {
|
|
|
2054
2058
|
evidence: sighting.evidence,
|
|
2055
2059
|
mode,
|
|
2056
2060
|
...sighting.method === void 0 ? {} : { method: sighting.method },
|
|
2057
|
-
...sighting.match === void 0 ? {} : { match: sighting.match }
|
|
2061
|
+
...sighting.match === void 0 ? {} : { match: sighting.match },
|
|
2062
|
+
...model === void 0 ? {} : { model }
|
|
2058
2063
|
}));
|
|
2059
2064
|
}
|
|
2060
2065
|
function filteredEvents(filtered, states, now) {
|
|
@@ -2521,7 +2526,7 @@ import { dirname as dirname4 } from "node:path";
|
|
|
2521
2526
|
|
|
2522
2527
|
// src/core/model/integrity.ts
|
|
2523
2528
|
function integrityErrors(candidate, index) {
|
|
2524
|
-
const
|
|
2529
|
+
const resolve8 = (id) => id === candidate.id ? candidate : index.byId.get(id);
|
|
2525
2530
|
const errors = [];
|
|
2526
2531
|
if (candidate.blockedBy.includes(candidate.id)) errors.push({ code: "self-block" });
|
|
2527
2532
|
if (candidate.related.includes(candidate.id)) errors.push({ code: "self-related" });
|
|
@@ -2530,7 +2535,7 @@ function integrityErrors(candidate, index) {
|
|
|
2530
2535
|
if (candidate.type === "task" && children.length > 0) {
|
|
2531
2536
|
errors.push({ code: "referenced-as-epic", children: children.map((task) => task.id) });
|
|
2532
2537
|
}
|
|
2533
|
-
const cycle = findBlockerCycle(candidate,
|
|
2538
|
+
const cycle = findBlockerCycle(candidate, resolve8);
|
|
2534
2539
|
if (cycle) errors.push({ code: "blocker-cycle", cycle });
|
|
2535
2540
|
if (candidate.resolution !== void 0 && candidate.status !== RESOLUTION_STATUS[candidate.resolution]) {
|
|
2536
2541
|
errors.push({ code: "resolution-needs-status", resolution: candidate.resolution, status: RESOLUTION_STATUS[candidate.resolution] });
|
|
@@ -2562,14 +2567,14 @@ function taskWarnings(task, index) {
|
|
|
2562
2567
|
function missingReferenceProblem(id, file) {
|
|
2563
2568
|
return file === void 0 ? { code: "reference-missing", id } : { code: "reference-unparsed", id, fileKind: file };
|
|
2564
2569
|
}
|
|
2565
|
-
function findBlockerCycle(start,
|
|
2570
|
+
function findBlockerCycle(start, resolve8) {
|
|
2566
2571
|
const visited = /* @__PURE__ */ new Set();
|
|
2567
2572
|
const walk = (task, path) => {
|
|
2568
2573
|
for (const blockerId of task.blockedBy) {
|
|
2569
2574
|
if (blockerId === start.id) return [...path, blockerId];
|
|
2570
2575
|
if (visited.has(blockerId)) continue;
|
|
2571
2576
|
visited.add(blockerId);
|
|
2572
|
-
const blocker =
|
|
2577
|
+
const blocker = resolve8(blockerId);
|
|
2573
2578
|
const cycle = blocker ? walk(blocker, [...path, blockerId]) : null;
|
|
2574
2579
|
if (cycle) return cycle;
|
|
2575
2580
|
}
|
|
@@ -3435,7 +3440,7 @@ function createLimiter(maxRunning) {
|
|
|
3435
3440
|
running++;
|
|
3436
3441
|
return Promise.resolve();
|
|
3437
3442
|
}
|
|
3438
|
-
return new Promise((
|
|
3443
|
+
return new Promise((resolve8) => waiting.push(resolve8));
|
|
3439
3444
|
};
|
|
3440
3445
|
return async (task) => {
|
|
3441
3446
|
await acquire2();
|
|
@@ -6164,7 +6169,7 @@ function candidateOutcome(reviews) {
|
|
|
6164
6169
|
unjudged: new Set(reviews.flatMap((review) => [...review.awaitingMerge, ...review.skipped]))
|
|
6165
6170
|
};
|
|
6166
6171
|
}
|
|
6167
|
-
async function recordCandidates(root, tasks, { candidates, filtered, unchecked, unjudged }, { mode, now, projectIds, messages, warn: warn2 }) {
|
|
6172
|
+
async function recordCandidates(root, tasks, { candidates, filtered, unchecked, unjudged }, { mode, now, projectIds, messages, warn: warn2, model }) {
|
|
6168
6173
|
const projectOf2 = new Map(tasks.map((task) => [task.id, task.projectId]));
|
|
6169
6174
|
for (const projectId of projectIds) {
|
|
6170
6175
|
const dir = join19(root, projectId);
|
|
@@ -6179,7 +6184,7 @@ async function recordCandidates(root, tasks, { candidates, filtered, unchecked,
|
|
|
6179
6184
|
const states = episodeStates(journal.events);
|
|
6180
6185
|
const sightings = found.map(sightingOf);
|
|
6181
6186
|
const gone = endsGone ? candidateGoneEvents({ sightings, reviewed, unchecked: unchecked.get(projectId) ?? [] }, states, now) : [];
|
|
6182
|
-
await appendJournal(dir, [...candidateEvents(sightings, states, now, mode), ...gone, ...filteredEvents(filteredHere, states, now)], (_path, error) => reportFailure2(error));
|
|
6187
|
+
await appendJournal(dir, [...candidateEvents(sightings, states, now, mode, model), ...gone, ...filteredEvents(filteredHere, states, now)], (_path, error) => reportFailure2(error));
|
|
6183
6188
|
} catch (error) {
|
|
6184
6189
|
reportFailure2(error);
|
|
6185
6190
|
}
|
|
@@ -6409,7 +6414,7 @@ function collectEvent(item, event) {
|
|
|
6409
6414
|
item.transitions.push({ at, from: event.from, to: event.to, resolution: event.resolution, via: event.via, undo: event.undo });
|
|
6410
6415
|
return;
|
|
6411
6416
|
case "candidate":
|
|
6412
|
-
item.candidates.push({ at, evidence: event.evidence, method: recordedMethodOf(event), match: event.match ?? UNKNOWN });
|
|
6417
|
+
item.candidates.push({ at, evidence: event.evidence, method: recordedMethodOf(event), match: event.match ?? UNKNOWN, model: event.model });
|
|
6413
6418
|
return;
|
|
6414
6419
|
case "candidate-filtered":
|
|
6415
6420
|
item.filtered.push(at);
|
|
@@ -7178,6 +7183,14 @@ function methodAccuracy(histories, span2) {
|
|
|
7178
7183
|
function matchAccuracy(histories, span2) {
|
|
7179
7184
|
return splitAccuracy(histories, span2, { evidence: MATCH_EVIDENCE, keys: RECORDED_MATCHES, keyOf: (candidate) => candidate.match });
|
|
7180
7185
|
}
|
|
7186
|
+
function modelAccuracy(histories, span2) {
|
|
7187
|
+
const byModel = /* @__PURE__ */ new Map();
|
|
7188
|
+
for (const episode of episodesOf(histories, ({ at, model }) => model !== void 0 && span2.contains(at))) {
|
|
7189
|
+
const { model } = episode.candidate;
|
|
7190
|
+
if (model !== void 0) remembered(byModel, model, () => []).push(episode);
|
|
7191
|
+
}
|
|
7192
|
+
return [...byModel].sort(([a], [b]) => a.localeCompare(b)).map(([model, episodes]) => ({ model, ...outcomeCounts(episodes) }));
|
|
7193
|
+
}
|
|
7181
7194
|
function splitAccuracy(histories, span2, { evidence: evidence2, keys, keyOf }) {
|
|
7182
7195
|
const episodes = episodesOf(histories, (candidate) => candidate.evidence === evidence2 && span2.contains(candidate.at));
|
|
7183
7196
|
return countsPerKey(episodes, keys, keyOf).map(([by, counts]) => ({ evidence: evidence2, by, ...counts }));
|
|
@@ -7281,7 +7294,8 @@ var claudeEventSchema = z13.object({
|
|
|
7281
7294
|
session_id: z13.string().optional(),
|
|
7282
7295
|
turn_id: z13.string().optional(),
|
|
7283
7296
|
stop_hook_active: z13.boolean().optional(),
|
|
7284
|
-
last_assistant_message: z13.string().nullish()
|
|
7297
|
+
last_assistant_message: z13.string().nullish(),
|
|
7298
|
+
model: z13.string().trim().min(1).optional().catch(void 0)
|
|
7285
7299
|
});
|
|
7286
7300
|
var cursorEventSchema = z13.object({
|
|
7287
7301
|
workspace_roots: z13.tuple([z13.string()], z13.string()),
|
|
@@ -7307,7 +7321,7 @@ function formatStopAnswer(agent, answer) {
|
|
|
7307
7321
|
function parseClaudeEvent(text) {
|
|
7308
7322
|
const event = parseJson(text, claudeEventSchema);
|
|
7309
7323
|
if (event === null) return null;
|
|
7310
|
-
return { cwd: event.cwd, session: event.session_id, turn: event.turn_id ?? digest(event.last_assistant_message), skip: event.stop_hook_active === true };
|
|
7324
|
+
return { cwd: event.cwd, session: event.session_id, turn: event.turn_id ?? digest(event.last_assistant_message), skip: event.stop_hook_active === true, model: event.model };
|
|
7311
7325
|
}
|
|
7312
7326
|
function parseCursorEvent(text) {
|
|
7313
7327
|
const event = parseJson(text, cursorEventSchema);
|
|
@@ -7380,7 +7394,16 @@ async function runHook(args, io) {
|
|
|
7380
7394
|
if (!("project" in lookup)) return EXIT.ok;
|
|
7381
7395
|
const { project } = lookup;
|
|
7382
7396
|
if (!await isFirstHookOfTurn(agent, event, io)) return EXIT.ok;
|
|
7383
|
-
const { candidates } = await checkBacklog(io.backlogRoot, loaded, {
|
|
7397
|
+
const { candidates } = await checkBacklog(io.backlogRoot, loaded, {
|
|
7398
|
+
projectIds: [project.id],
|
|
7399
|
+
mode: "changed",
|
|
7400
|
+
now: io.now(),
|
|
7401
|
+
context,
|
|
7402
|
+
messages: io.core,
|
|
7403
|
+
warn: io.warn,
|
|
7404
|
+
workingRoots: repoRootsOf(cwdRoots),
|
|
7405
|
+
model: event.model
|
|
7406
|
+
});
|
|
7384
7407
|
const lowPriority = new Set(loaded.tasks.filter((task) => task.priority === "low").map((task) => task.id));
|
|
7385
7408
|
const pinpointed = candidates.filter((candidate) => !(candidate.kind === "source-changed" && candidate.method === "file"));
|
|
7386
7409
|
const worthTelling = pinpointed.filter((candidate) => !lowPriority.has(candidate.task.id));
|
|
@@ -9060,6 +9083,7 @@ function qualityReport(context, graphs) {
|
|
|
9060
9083
|
accuracyDays: accuracyDays(histories, now),
|
|
9061
9084
|
methodAccuracy: methodAccuracy(histories, period2),
|
|
9062
9085
|
matchAccuracy: matchAccuracy(histories, period2),
|
|
9086
|
+
modelAccuracy: modelAccuracy(histories, period2),
|
|
9063
9087
|
graph: { projects: graphs, filter: graphFilterEffect(histories, period2) },
|
|
9064
9088
|
categories: categoryBreakdown(openTasks, histories, period2),
|
|
9065
9089
|
found: foundBreakdown(histories, period2),
|
|
@@ -9159,7 +9183,8 @@ function totalTokens(tokens) {
|
|
|
9159
9183
|
// src/core/stats/cost/pricing.ts
|
|
9160
9184
|
var FAST_MODEL_MARKER = ":fast";
|
|
9161
9185
|
var LONG_PROMPT_MARKER = ":long-prompt";
|
|
9162
|
-
var
|
|
9186
|
+
var OPENAI_LONG_PROMPT_TOKENS = 272e3;
|
|
9187
|
+
var OPENAI_LONG_OUTPUT_FACTOR = 1.5;
|
|
9163
9188
|
var FAST_PRICE_FACTOR = 2;
|
|
9164
9189
|
var CACHE_WRITE_5M_FACTOR = 1.25;
|
|
9165
9190
|
var CACHE_WRITE_1H_FACTOR = 2;
|
|
@@ -9181,16 +9206,26 @@ var PRICE_TABLE = /* @__PURE__ */ new Map([
|
|
|
9181
9206
|
["claude-sonnet-5", { input: 2, output: 10, cacheRead: 0.2 }],
|
|
9182
9207
|
["claude-sonnet-4-6", { input: 3, output: 15, cacheRead: 0.3 }],
|
|
9183
9208
|
["claude-sonnet-4-5", { input: 3, output: 15, cacheRead: 0.3 }],
|
|
9184
|
-
["claude-haiku-5-5", { input: 0.1, output: 0.5, cacheRead: 0.01, longPrompt: { input: 0.5, output: 2.5, cacheRead: 0.05 } }],
|
|
9185
|
-
["claude-haiku-4-5", { input: 1, output: 5, cacheRead: 0.1 }]
|
|
9209
|
+
["claude-haiku-5-5", { input: 0.1, output: 0.5, cacheRead: 0.01, longPrompt: { threshold: 1e5, input: 0.5, output: 2.5, cacheRead: 0.05 } }],
|
|
9210
|
+
["claude-haiku-4-5", { input: 1, output: 5, cacheRead: 0.1 }],
|
|
9211
|
+
["gpt-6.2-astra", openAiPrice({ input: 8, output: 40, cacheRead: 0.4 })],
|
|
9212
|
+
["gpt-6.2-sol", openAiPrice({ input: 2, output: 10, cacheRead: 0.1 })],
|
|
9213
|
+
["gpt-6.1-sol", openAiPrice({ input: 2, output: 10, cacheRead: 0.1 })],
|
|
9214
|
+
["gpt-6.1-terra", openAiPrice({ input: 1, output: 5, cacheRead: 0.05 })],
|
|
9215
|
+
["gpt-6-astra", openAiPrice({ input: 10, output: 50, cacheRead: 1 })],
|
|
9216
|
+
["gpt-6-luna", openAiPrice({ input: 0.1, output: 0.5, cacheRead: 0.01 })]
|
|
9186
9217
|
]);
|
|
9187
|
-
var DATED_SUFFIX =
|
|
9218
|
+
var DATED_SUFFIX = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/;
|
|
9188
9219
|
var BRACKET_SUFFIX = /\[[^\]]*\]$/;
|
|
9220
|
+
function openAiPrice({ input, output, cacheRead }) {
|
|
9221
|
+
return { input, output, cacheRead, longPrompt: { threshold: OPENAI_LONG_PROMPT_TOKENS, input: input * 2, output: output * OPENAI_LONG_OUTPUT_FACTOR, cacheRead: cacheRead * 2 } };
|
|
9222
|
+
}
|
|
9189
9223
|
function baseModelId(model) {
|
|
9190
9224
|
return model.replace(BRACKET_SUFFIX, "").replace(DATED_SUFFIX, "");
|
|
9191
9225
|
}
|
|
9192
9226
|
function modelKey({ model, fast, tokens }) {
|
|
9193
|
-
const
|
|
9227
|
+
const threshold = PRICE_TABLE.get(baseModelId(model))?.longPrompt?.threshold;
|
|
9228
|
+
const longPrompt = threshold !== void 0 && promptTokens(tokens) > threshold;
|
|
9194
9229
|
return `${model}${fast ? FAST_MODEL_MARKER : ""}${longPrompt ? LONG_PROMPT_MARKER : ""}`;
|
|
9195
9230
|
}
|
|
9196
9231
|
function stripMarker(key, marker) {
|
|
@@ -9337,12 +9372,13 @@ var transcriptStateSchema = z17.object({
|
|
|
9337
9372
|
lastMessageId: z17.string().nullable(),
|
|
9338
9373
|
lastMessageTokens: tokenCountsSchema.nullable().optional(),
|
|
9339
9374
|
pending: z17.record(z17.string(), estimatedKindSchema),
|
|
9340
|
-
pendingEstimates: z17.array(z17.object({ kind: estimatedKindSchema, chars: z17.number(), slot: z17.string(), cwd: z17.string() }))
|
|
9375
|
+
pendingEstimates: z17.array(z17.object({ kind: estimatedKindSchema, chars: z17.number(), slot: z17.string(), cwd: z17.string() })),
|
|
9376
|
+
codex: z17.object({ cwd: z17.string(), total: tokenCountsSchema.nullable(), toolDirectories: z17.record(z17.string(), z17.string()).optional() }).optional()
|
|
9341
9377
|
});
|
|
9342
9378
|
|
|
9343
9379
|
// src/core/usage/usage-cache.ts
|
|
9344
9380
|
var USAGE_CACHE_FILE = ".usage-cache.json";
|
|
9345
|
-
var USAGE_CACHE_VERSION =
|
|
9381
|
+
var USAGE_CACHE_VERSION = 7;
|
|
9346
9382
|
var bucketsSchema = z18.array(usageBucketSchema);
|
|
9347
9383
|
var worktreeTenureSchema = z18.object({ main: z18.string(), since: z18.number() });
|
|
9348
9384
|
var SINCE_EVER = 0;
|
|
@@ -9641,8 +9677,8 @@ async function removeProject2(c, id, { root, readLanguage, changeHub }) {
|
|
|
9641
9677
|
function revisionEvents(c, changeHub, closed) {
|
|
9642
9678
|
return streamSSE(c, async (stream) => {
|
|
9643
9679
|
const stopSending = changeHub.onRevision((revision) => void stream.writeSSE({ event: "change", data: JSON.stringify(revision) }));
|
|
9644
|
-
const { promise: ended, resolve:
|
|
9645
|
-
const end = () =>
|
|
9680
|
+
const { promise: ended, resolve: resolve8 } = Promise.withResolvers();
|
|
9681
|
+
const end = () => resolve8();
|
|
9646
9682
|
stream.onAbort(end);
|
|
9647
9683
|
closed.addEventListener("abort", end);
|
|
9648
9684
|
if (closed.aborted) end();
|
|
@@ -9897,14 +9933,22 @@ var PACKAGE_RUNNERS = /* @__PURE__ */ new Set(["npx", "bunx", "pnpx"]);
|
|
|
9897
9933
|
var RUNNER_SUBCOMMANDS = { pnpm: ["dlx", "exec"], yarn: ["dlx", "exec"], npm: ["exec", "x"], bun: ["x"] };
|
|
9898
9934
|
var BIN_RUNNERS = /* @__PURE__ */ new Set(["yarn"]);
|
|
9899
9935
|
function invokesBacklog(script) {
|
|
9900
|
-
return simpleCommands(script).some(
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
|
|
9907
|
-
|
|
9936
|
+
return simpleCommands(script).some(isBacklogCommand);
|
|
9937
|
+
}
|
|
9938
|
+
function invokesOnlyBacklog(script) {
|
|
9939
|
+
const commands = simpleCommands(script);
|
|
9940
|
+
return commands.length > 0 && commands.every(isBacklogCommand);
|
|
9941
|
+
}
|
|
9942
|
+
function isSingleShellCommand(script) {
|
|
9943
|
+
return simpleCommands(script).length === 1;
|
|
9944
|
+
}
|
|
9945
|
+
function isBacklogCommand(command2) {
|
|
9946
|
+
const [program, ...args] = programWords(command2.split(/\s+/));
|
|
9947
|
+
if (program === void 0) return false;
|
|
9948
|
+
const name = executableName(program);
|
|
9949
|
+
if (name === BACKLOG_BIN || BIN_RUNNERS.has(name) && args[0] === BACKLOG_BIN) return true;
|
|
9950
|
+
const runnerArgs = packageRunnerArguments(name, args);
|
|
9951
|
+
return runnerArgs !== null && runsBacklogPackage(runnerArgs);
|
|
9908
9952
|
}
|
|
9909
9953
|
function programWords(words) {
|
|
9910
9954
|
let rest = dropWhile(words, (word) => word === "" || ENV_ASSIGNMENT.test(word) || SHELL_KEYWORDS.has(word));
|
|
@@ -10188,13 +10232,13 @@ function registerToolUseBlock(raw, state) {
|
|
|
10188
10232
|
if (block.data.name === BASH_TOOL) {
|
|
10189
10233
|
const input = bashInputSchema.safeParse(block.data.input);
|
|
10190
10234
|
if (!input.success || !invokesBacklog(input.data.command)) return;
|
|
10191
|
-
state
|
|
10192
|
-
forgetOldestPending(state);
|
|
10235
|
+
rememberToolCall(state, block.data.id, "cli");
|
|
10193
10236
|
}
|
|
10194
10237
|
}
|
|
10195
|
-
function
|
|
10238
|
+
function rememberToolCall(state, id, kind) {
|
|
10239
|
+
state.pending[id] = kind;
|
|
10196
10240
|
const ids = Object.keys(state.pending);
|
|
10197
|
-
for (const
|
|
10241
|
+
for (const expiredId of ids.slice(0, Math.max(0, ids.length - PENDING_TOOL_LIMIT))) Reflect.deleteProperty(state.pending, expiredId);
|
|
10198
10242
|
}
|
|
10199
10243
|
function flushEstimates(state) {
|
|
10200
10244
|
return state.lastModel === null ? [] : drainEstimates(state, state.lastModel);
|
|
@@ -10205,14 +10249,14 @@ function drainEstimates(state, model) {
|
|
|
10205
10249
|
cwd: estimate.cwd,
|
|
10206
10250
|
model,
|
|
10207
10251
|
kind: estimate.kind,
|
|
10208
|
-
tokens:
|
|
10252
|
+
tokens: { ...ZERO_TOKENS, cacheWrite5m: estimateTextTokens(estimate.chars) },
|
|
10209
10253
|
hookTurns: 0
|
|
10210
10254
|
}));
|
|
10211
10255
|
state.pendingEstimates = [];
|
|
10212
10256
|
return buckets;
|
|
10213
10257
|
}
|
|
10214
|
-
function
|
|
10215
|
-
return
|
|
10258
|
+
function estimateTextTokens(chars) {
|
|
10259
|
+
return Math.ceil(chars / CHARS_PER_TOKEN);
|
|
10216
10260
|
}
|
|
10217
10261
|
function isToolResultOnly(content) {
|
|
10218
10262
|
return Array.isArray(content) && content.length > 0 && content.every((block) => toolResultBlockSchema.safeParse(block).success);
|
|
@@ -10236,6 +10280,143 @@ function slotOf(timestamp) {
|
|
|
10236
10280
|
return Number.isNaN(moment) ? "" : new Date(moment - moment % ZONE_OFFSET_STEP_MS).toISOString();
|
|
10237
10281
|
}
|
|
10238
10282
|
|
|
10283
|
+
// src/core/usage/attribute-codex.ts
|
|
10284
|
+
import { resolve as resolve4 } from "node:path";
|
|
10285
|
+
import { z as z20 } from "zod";
|
|
10286
|
+
var ROLLOUT_MARKERS = /"type"\s*:\s*"(?:session_meta|turn_context|token_count|message|function_call(?:_output)?|custom_tool_call(?:_output)?)"/u;
|
|
10287
|
+
var INLINE_SHELL_FIELDS = /\b(cmd|workdir)\s*:\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\[\s\S]|[^`\\])*`)/gu;
|
|
10288
|
+
var APP_TOOL_CALL = /\btools\.(\w+)\s*\(/gu;
|
|
10289
|
+
var SKILL_READER = /^\s*(?:cat|sed|head|tail|nl|Get-Content)\b/iu;
|
|
10290
|
+
var STOP_HOOK_PROMPT = /^<hook_prompt hook_run_id="stop:[^"]+">\s*([\s\S]*?)<\/hook_prompt>$/u;
|
|
10291
|
+
var rolloutSchema = z20.object({
|
|
10292
|
+
type: z20.string(),
|
|
10293
|
+
timestamp: z20.string(),
|
|
10294
|
+
payload: z20.object({
|
|
10295
|
+
type: z20.string().optional(),
|
|
10296
|
+
cwd: z20.string().optional(),
|
|
10297
|
+
model: z20.string().min(1).optional()
|
|
10298
|
+
}).passthrough()
|
|
10299
|
+
});
|
|
10300
|
+
var usageSchema2 = z20.object({
|
|
10301
|
+
input_tokens: z20.number().nonnegative(),
|
|
10302
|
+
cached_input_tokens: z20.number().nonnegative().default(0),
|
|
10303
|
+
cache_write_input_tokens: z20.number().nonnegative().default(0),
|
|
10304
|
+
output_tokens: z20.number().nonnegative()
|
|
10305
|
+
});
|
|
10306
|
+
var eventSchema = z20.object({ info: z20.object({ total_token_usage: usageSchema2, last_token_usage: usageSchema2.optional() }) });
|
|
10307
|
+
var messageSchema = z20.object({ role: z20.string(), content: z20.array(z20.object({ text: z20.string().optional() })) });
|
|
10308
|
+
var callSchema = z20.object({ name: z20.string(), call_id: z20.string(), arguments: z20.string().optional(), input: z20.string().optional() });
|
|
10309
|
+
var shellSchema = z20.object({ cmd: z20.string().optional(), command: z20.string().optional(), workdir: z20.string().optional() });
|
|
10310
|
+
var textOutputSchema = z20.object({ type: z20.literal("input_text"), text: z20.string() });
|
|
10311
|
+
var resultSchema = z20.object({ call_id: z20.string(), output: z20.union([z20.string(), z20.array(z20.unknown())]) });
|
|
10312
|
+
function attributeCodexLine(line, state) {
|
|
10313
|
+
if (!ROLLOUT_MARKERS.test(line)) return [];
|
|
10314
|
+
const event = parseJson(line, rolloutSchema);
|
|
10315
|
+
if (event === null) return [];
|
|
10316
|
+
const codex = state.codex ??= { cwd: "", total: null };
|
|
10317
|
+
const { type, timestamp, payload } = event;
|
|
10318
|
+
if (type === "session_meta" || type === "turn_context") {
|
|
10319
|
+
codex.cwd = payload.cwd ?? codex.cwd;
|
|
10320
|
+
state.lastModel = payload.model ?? state.lastModel;
|
|
10321
|
+
return [];
|
|
10322
|
+
}
|
|
10323
|
+
const context = { cwd: codex.cwd, model: state.lastModel ?? "unknown", slot: slotOf(timestamp) };
|
|
10324
|
+
if (type === "event_msg" && payload.type === "token_count") return tokenBuckets(payload, state, codex, context);
|
|
10325
|
+
if (type === "response_item") return responseBuckets(payload, state, codex, context);
|
|
10326
|
+
return [];
|
|
10327
|
+
}
|
|
10328
|
+
function tokenBuckets(payload, state, codex, context) {
|
|
10329
|
+
const event = eventSchema.safeParse(payload);
|
|
10330
|
+
if (!event.success) return [];
|
|
10331
|
+
const { total_token_usage: usage, last_token_usage: last } = event.data.info;
|
|
10332
|
+
const total = tokensOf(usage);
|
|
10333
|
+
const tokens = codex.total === null ? tokensOf(last ?? usage) : tokensGrowth(codex.total, total);
|
|
10334
|
+
codex.total = total;
|
|
10335
|
+
if (!state.hookOpen || totalTokens(tokens) === 0) return [];
|
|
10336
|
+
const model = modelKey({ model: context.model, fast: false, tokens });
|
|
10337
|
+
return [{ ...context, model, kind: "hook", tokens, hookTurns: 0 }];
|
|
10338
|
+
}
|
|
10339
|
+
function tokensOf(usage) {
|
|
10340
|
+
const cacheRead = Math.min(usage.input_tokens, usage.cached_input_tokens);
|
|
10341
|
+
const cacheWrite5m = Math.min(usage.input_tokens - cacheRead, usage.cache_write_input_tokens);
|
|
10342
|
+
return { input: usage.input_tokens - cacheRead - cacheWrite5m, output: usage.output_tokens, cacheWrite5m, cacheWrite1h: 0, cacheRead };
|
|
10343
|
+
}
|
|
10344
|
+
function responseBuckets(payload, state, codex, context) {
|
|
10345
|
+
switch (payload.type) {
|
|
10346
|
+
case "message": {
|
|
10347
|
+
const message = messageSchema.safeParse(payload);
|
|
10348
|
+
if (!message.success || message.data.role !== "user") return [];
|
|
10349
|
+
state.hookOpen = message.data.content.some(({ text }) => isBacklogPrompt(text?.trim() ?? ""));
|
|
10350
|
+
return state.hookOpen ? [{ ...context, kind: "hook", tokens: ZERO_TOKENS, hookTurns: 1 }] : [];
|
|
10351
|
+
}
|
|
10352
|
+
case "function_call":
|
|
10353
|
+
case "custom_tool_call": {
|
|
10354
|
+
const call = callSchema.safeParse(payload);
|
|
10355
|
+
if (call.success) rememberBacklogCall(call.data, state, codex);
|
|
10356
|
+
return [];
|
|
10357
|
+
}
|
|
10358
|
+
case "function_call_output":
|
|
10359
|
+
case "custom_tool_call_output":
|
|
10360
|
+
return toolOutputBuckets(payload, state, codex, context);
|
|
10361
|
+
case void 0:
|
|
10362
|
+
default:
|
|
10363
|
+
return [];
|
|
10364
|
+
}
|
|
10365
|
+
}
|
|
10366
|
+
function isBacklogPrompt(text) {
|
|
10367
|
+
return isBacklogHookFeedback(text) || isBacklogHookReason(STOP_HOOK_PROMPT.exec(text)?.[1] ?? "");
|
|
10368
|
+
}
|
|
10369
|
+
function rememberBacklogCall(call, state, codex) {
|
|
10370
|
+
const { commands, workdir } = shellDetails(call);
|
|
10371
|
+
if (commands.length === 0) return;
|
|
10372
|
+
if (commands.every(invokesOnlyBacklog)) rememberToolCall(state, call.call_id, "cli");
|
|
10373
|
+
else if (commands.every(readsBacklogSkill)) rememberToolCall(state, call.call_id, "skill");
|
|
10374
|
+
if (workdir && Object.hasOwn(state.pending, call.call_id)) {
|
|
10375
|
+
codex.toolDirectories ??= {};
|
|
10376
|
+
const cwd = resolve4(codex.cwd, workdir);
|
|
10377
|
+
codex.toolDirectories = { ...codex.toolDirectories, [call.call_id]: cwd };
|
|
10378
|
+
}
|
|
10379
|
+
for (const id of Object.keys(codex.toolDirectories ?? {})) {
|
|
10380
|
+
if (!Object.hasOwn(state.pending, id) && codex.toolDirectories !== void 0) Reflect.deleteProperty(codex.toolDirectories, id);
|
|
10381
|
+
}
|
|
10382
|
+
}
|
|
10383
|
+
function shellDetails(call) {
|
|
10384
|
+
if (call.name === "exec_command" || call.name === "shell_command") {
|
|
10385
|
+
const shell = parseJson(call.arguments ?? "", shellSchema);
|
|
10386
|
+
const command2 = shell?.cmd ?? shell?.command;
|
|
10387
|
+
return { commands: command2 === void 0 ? [] : [command2], workdir: shell?.workdir };
|
|
10388
|
+
}
|
|
10389
|
+
if (call.name !== "exec" || !call.input?.includes("tools.exec_command")) return { commands: [] };
|
|
10390
|
+
const tools = [...call.input.matchAll(APP_TOOL_CALL)];
|
|
10391
|
+
if (tools.some(([, name]) => name !== "exec_command")) return { commands: [] };
|
|
10392
|
+
const commands = [];
|
|
10393
|
+
const workdirs = [];
|
|
10394
|
+
for (const [, field, literal = ""] of call.input.matchAll(INLINE_SHELL_FIELDS)) {
|
|
10395
|
+
const fields = field === "cmd" ? commands : workdirs;
|
|
10396
|
+
fields.push(parseJson(literal, z20.string()) ?? literal.slice(1, -1).replaceAll("\\n", "\n"));
|
|
10397
|
+
}
|
|
10398
|
+
if (commands.length !== tools.length || workdirs.length > 0 && commands.length !== 1) return { commands: [] };
|
|
10399
|
+
return { commands, workdir: workdirs[0] };
|
|
10400
|
+
}
|
|
10401
|
+
function readsBacklogSkill(command2) {
|
|
10402
|
+
return SKILL_READER.test(command2) && command2.replaceAll("\\", "/").includes(`/${SKILL_NAME}/SKILL.md`) && isSingleShellCommand(command2);
|
|
10403
|
+
}
|
|
10404
|
+
function toolOutputBuckets(payload, state, codex, context) {
|
|
10405
|
+
const result = resultSchema.safeParse(payload);
|
|
10406
|
+
if (!result.success) return [];
|
|
10407
|
+
const { call_id: id, output } = result.data;
|
|
10408
|
+
if (!Object.hasOwn(state.pending, id)) return [];
|
|
10409
|
+
const kind = state.pending[id];
|
|
10410
|
+
Reflect.deleteProperty(state.pending, id);
|
|
10411
|
+
const directories = codex.toolDirectories ?? {};
|
|
10412
|
+
const cwd = Object.hasOwn(directories, id) ? directories[id] ?? context.cwd : context.cwd;
|
|
10413
|
+
Reflect.deleteProperty(directories, id);
|
|
10414
|
+
if (state.hookOpen || kind === void 0) return [];
|
|
10415
|
+
const chars = typeof output === "string" ? output.length : output.reduce((total, part) => total + (textOutputSchema.safeParse(part).data?.text.length ?? 0), 0);
|
|
10416
|
+
if (chars === 0) return [];
|
|
10417
|
+
return [{ ...context, cwd, kind, tokens: { ...ZERO_TOKENS, input: estimateTextTokens(chars) }, hookTurns: 0 }];
|
|
10418
|
+
}
|
|
10419
|
+
|
|
10239
10420
|
// src/core/usage/transcripts.ts
|
|
10240
10421
|
var FINGERPRINT_BYTES = 256;
|
|
10241
10422
|
var ABANDONED_LINE_MS = 10 * 60 * 1e3;
|
|
@@ -10263,13 +10444,30 @@ async function listedFile(path) {
|
|
|
10263
10444
|
const stats = await statOrNull(path);
|
|
10264
10445
|
return stats === null ? [] : [{ path, size: stats.size, mtimeMs: stats.mtimeMs }];
|
|
10265
10446
|
}
|
|
10266
|
-
async function
|
|
10447
|
+
async function listCodexTranscripts(home2, now, onUnreadable) {
|
|
10448
|
+
const retained = retainedSince(now);
|
|
10449
|
+
const bySession = /* @__PURE__ */ new Map();
|
|
10450
|
+
for (const folder of ["sessions", "archived_sessions"]) {
|
|
10451
|
+
const entries = await attemptReportingFailure(join33(home2, folder), (path) => listDir(path, { recursive: true }), onUnreadable);
|
|
10452
|
+
for (const entry of entries ?? []) {
|
|
10453
|
+
if (!entry.isFile() || !entry.name.startsWith("rollout-") || !entry.name.endsWith(".jsonl") || bySession.has(entry.name)) continue;
|
|
10454
|
+
const path = join33(entry.parentPath, entry.name);
|
|
10455
|
+
const stat3 = await attemptReportingFailure(path, statOrNull, onUnreadable);
|
|
10456
|
+
if (stat3 !== null && stat3.mtimeMs >= retained) bySession.set(entry.name, { path, size: stat3.size, mtimeMs: stat3.mtimeMs, codex: true });
|
|
10457
|
+
}
|
|
10458
|
+
}
|
|
10459
|
+
return [...bySession.values()];
|
|
10460
|
+
}
|
|
10461
|
+
async function scanTranscripts({ files, cache, byteBudget, now, onUnreadable }) {
|
|
10267
10462
|
let remainingBudget = byteBudget;
|
|
10268
10463
|
const listedFiles = {};
|
|
10269
10464
|
for (const file of files) {
|
|
10270
|
-
const
|
|
10271
|
-
|
|
10272
|
-
|
|
10465
|
+
const read = () => scanFile(file, cache.files[file.path], remainingBudget, { longestReadableLine: byteBudget, now });
|
|
10466
|
+
const result = onUnreadable === void 0 ? await read() : await attemptReportingFailure(file.path, read, onUnreadable);
|
|
10467
|
+
if (result !== null) {
|
|
10468
|
+
listedFiles[file.path] = result.entry;
|
|
10469
|
+
remainingBudget -= result.budgetUsed;
|
|
10470
|
+
}
|
|
10273
10471
|
await yieldToEventLoop();
|
|
10274
10472
|
}
|
|
10275
10473
|
const stillReported = deletedStillReported(listedFiles, now);
|
|
@@ -10329,16 +10527,19 @@ async function scanChunk(file, start, chunkSize, { longestReadableLine, now }) {
|
|
|
10329
10527
|
return { size: file.size, offset: start.offset + (lineTooLong ? chunk.length : 0), state: start.state, buckets: start.buckets };
|
|
10330
10528
|
}
|
|
10331
10529
|
const bucketsByKey = new Map(start.buckets.map((bucket) => [bucketKey(bucket), bucket]));
|
|
10530
|
+
const readLine = file.codex ? attributeCodexLine : attributeClaudeLine;
|
|
10332
10531
|
for (const line of chunk.subarray(0, readableLength).toString("utf8").split("\n")) {
|
|
10333
|
-
|
|
10334
|
-
const parsed = parseJson(line, transcriptLineSchema);
|
|
10335
|
-
if (parsed === null) continue;
|
|
10336
|
-
for (const addition of attributeLine(parsed, start.state)) addBucket(bucketsByKey, addition);
|
|
10532
|
+
for (const addition of readLine(line, start.state)) addBucket(bucketsByKey, addition);
|
|
10337
10533
|
}
|
|
10338
10534
|
const offset = start.offset + readableLength;
|
|
10339
10535
|
if (offset === file.size) for (const addition of flushEstimates(start.state)) addBucket(bucketsByKey, addition);
|
|
10340
10536
|
return { size: file.size, offset, state: start.state, buckets: [...bucketsByKey.values()] };
|
|
10341
10537
|
}
|
|
10538
|
+
function attributeClaudeLine(line, state) {
|
|
10539
|
+
if (!COUNTED_LINE_MARKERS.some((marker) => line.includes(marker))) return [];
|
|
10540
|
+
const parsed = parseJson(line, transcriptLineSchema);
|
|
10541
|
+
return parsed === null ? [] : attributeLine(parsed, state);
|
|
10542
|
+
}
|
|
10342
10543
|
async function continues(file, previous) {
|
|
10343
10544
|
if (file.size < previous.size) return false;
|
|
10344
10545
|
if (file.size === previous.size && file.mtimeMs === previous.mtimeMs) return true;
|
|
@@ -10354,7 +10555,7 @@ async function fingerprintOf3(path, offset) {
|
|
|
10354
10555
|
});
|
|
10355
10556
|
}
|
|
10356
10557
|
function yieldToEventLoop() {
|
|
10357
|
-
return new Promise((
|
|
10558
|
+
return new Promise((resolve8) => setImmediate(resolve8));
|
|
10358
10559
|
}
|
|
10359
10560
|
function addBucket(buckets, addition) {
|
|
10360
10561
|
const key = bucketKey(addition);
|
|
@@ -10374,13 +10575,13 @@ var DEFAULT_INTERVAL_MS = MINUTE_MS;
|
|
|
10374
10575
|
var CATCH_UP_DELAY_MS = 100;
|
|
10375
10576
|
var NOT_LISTED = { listed: false, filesTotal: 0, filesDone: 0, bytesLeft: 0 };
|
|
10376
10577
|
var STOPPED = { running: false };
|
|
10377
|
-
function createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir2, byteBudget = DEFAULT_BYTE_BUDGET, intervalMs = DEFAULT_INTERVAL_MS, warn: warn2, now = () => /* @__PURE__ */ new Date() }) {
|
|
10578
|
+
function createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir2, codexHome, byteBudget = DEFAULT_BYTE_BUDGET, intervalMs = DEFAULT_INTERVAL_MS, warn: warn2, now = () => /* @__PURE__ */ new Date() }) {
|
|
10378
10579
|
let cache = null;
|
|
10379
10580
|
let scan = NOT_LISTED;
|
|
10380
10581
|
let revision = 0;
|
|
10381
10582
|
let inFlight = null;
|
|
10382
10583
|
let schedule = STOPPED;
|
|
10383
|
-
const
|
|
10584
|
+
const reportPathError = warnPathErrors((line) => void warn2(() => line));
|
|
10384
10585
|
const runsTail = createJsonlTail(join34(root, RUNS_FILE), cliRunSchema);
|
|
10385
10586
|
const newOutsideOwners = outsideWorktreeRecorder();
|
|
10386
10587
|
const setScan = (next) => {
|
|
@@ -10388,18 +10589,18 @@ function createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir2, byteB
|
|
|
10388
10589
|
scan = next;
|
|
10389
10590
|
};
|
|
10390
10591
|
const runPass = async () => {
|
|
10391
|
-
const published = cache ?? emptyUsageCache();
|
|
10392
10592
|
const current = cache ?? await readUsageCache(root);
|
|
10393
|
-
const
|
|
10593
|
+
const moment = now();
|
|
10594
|
+
const files = await transcriptFiles(claudeProjectsDir2, codexHome, moment, reportPathError);
|
|
10394
10595
|
setScan(progressBefore(files, current));
|
|
10395
|
-
const result = await scanTranscripts({ files, cache: current, byteBudget, now:
|
|
10596
|
+
const result = await scanTranscripts({ files, cache: current, byteBudget, now: moment, onUnreadable: reportPathError });
|
|
10396
10597
|
const { values: runs } = await runsTail.read();
|
|
10397
10598
|
const added = await newOutsideOwners(result.cache, runs);
|
|
10398
10599
|
const next = added.length === 0 ? result.cache : { ...result.cache, worktreeRepos: withNewOwners(result.cache.worktreeRepos, added, now()) };
|
|
10399
|
-
if (cacheChanged(
|
|
10600
|
+
if (cacheChanged(cache ?? emptyUsageCache(), next)) revision += 1;
|
|
10400
10601
|
cache = next;
|
|
10401
10602
|
setScan({ listed: true, filesTotal: files.length, filesDone: result.filesDone, bytesLeft: result.bytesLeft });
|
|
10402
|
-
if (result.bytesRead > 0 || result.prunedBuckets > 0 || added.length > 0) await writeUsageCache(root, next,
|
|
10603
|
+
if (result.bytesRead > 0 || result.prunedBuckets > 0 || added.length > 0) await writeUsageCache(root, next, reportPathError);
|
|
10403
10604
|
return result.bytesRead >= byteBudget ? "budget-spent" : "settled";
|
|
10404
10605
|
};
|
|
10405
10606
|
const scanOnce = () => {
|
|
@@ -10432,6 +10633,12 @@ function createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir2, byteB
|
|
|
10432
10633
|
snapshot: () => ({ cache: cache ?? emptyUsageCache(), scan, revision })
|
|
10433
10634
|
};
|
|
10434
10635
|
}
|
|
10636
|
+
async function transcriptFiles(claudeDir2, codexHome, now, onUnreadable) {
|
|
10637
|
+
const claudeFiles = attemptReportingFailure(claudeDir2, listTranscripts, onUnreadable);
|
|
10638
|
+
const codexFiles = codexHome === void 0 ? [] : listCodexTranscripts(codexHome, now, onUnreadable);
|
|
10639
|
+
const [claude, codex] = await Promise.all([claudeFiles, codexFiles]);
|
|
10640
|
+
return [...claude ?? [], ...codex];
|
|
10641
|
+
}
|
|
10435
10642
|
var IN_OWN_REPO = "in-own-repo";
|
|
10436
10643
|
function outsideWorktreeRecorder() {
|
|
10437
10644
|
const lookupNewCwd = cachedRepoRoots({ onUnreadable: unreadableDirHasNoRepo });
|
|
@@ -10507,7 +10714,7 @@ async function startServer({ root, port, home: home2, env, platform, log, warn:
|
|
|
10507
10714
|
const readLanguage = () => readLanguageOrLocale(root, env, onLanguageUnreadable);
|
|
10508
10715
|
const readMessages = () => readLanguage().then(serverMessages);
|
|
10509
10716
|
const warnLocalized = localizedWarn(readLanguage, warn2);
|
|
10510
|
-
const usage = createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir(env, home2), warn: warnLocalized, now });
|
|
10717
|
+
const usage = createUsageScanner({ root, claudeProjectsDir: claudeProjectsDir(env, home2), codexHome: env.CODEX_HOME || join35(home2, ".codex"), warn: warnLocalized, now });
|
|
10511
10718
|
const memory = createMemorySampler({ now });
|
|
10512
10719
|
const changes = createChangeFeed({ root, debounceMs: CHANGE_DEBOUNCE_MS, warn: warnLocalized });
|
|
10513
10720
|
const allowedHosts = /* @__PURE__ */ new Set();
|
|
@@ -10537,10 +10744,10 @@ async function startServer({ root, port, home: home2, env, platform, log, warn:
|
|
|
10537
10744
|
return { port: actualPort, close };
|
|
10538
10745
|
}
|
|
10539
10746
|
function closeOnStopSignal(server) {
|
|
10540
|
-
return new Promise((
|
|
10747
|
+
return new Promise((resolve8, reject) => {
|
|
10541
10748
|
const stop = () => {
|
|
10542
10749
|
for (const signal3 of STOP_SIGNALS) process.off(signal3, stop);
|
|
10543
|
-
server.close().then(
|
|
10750
|
+
server.close().then(resolve8, reject);
|
|
10544
10751
|
};
|
|
10545
10752
|
for (const signal3 of STOP_SIGNALS) process.once(signal3, stop);
|
|
10546
10753
|
});
|
|
@@ -10550,10 +10757,10 @@ function listenFailure(error, port, messages) {
|
|
|
10550
10757
|
return messages.listenFailed(reason);
|
|
10551
10758
|
}
|
|
10552
10759
|
function listen(app, port) {
|
|
10553
|
-
return new Promise((
|
|
10760
|
+
return new Promise((resolve8, reject) => {
|
|
10554
10761
|
const server = serve({ fetch: app.fetch, hostname: LOOPBACK_HOST, port }, (info) => {
|
|
10555
10762
|
server.off("error", reject);
|
|
10556
|
-
|
|
10763
|
+
resolve8({ server, port: info.port });
|
|
10557
10764
|
});
|
|
10558
10765
|
server.once("error", reject);
|
|
10559
10766
|
server.on("request", (_request, response) => response.on("finish", () => dropIdleWhenClosing(server)));
|
|
@@ -10564,7 +10771,7 @@ function dropIdleWhenClosing(server) {
|
|
|
10564
10771
|
setImmediate(() => server.closeIdleConnections());
|
|
10565
10772
|
}
|
|
10566
10773
|
function closeServer(server) {
|
|
10567
|
-
return new Promise((
|
|
10774
|
+
return new Promise((resolve8, reject) => server.close((error) => error ? reject(error) : resolve8()));
|
|
10568
10775
|
}
|
|
10569
10776
|
function startBackground({ usage, memory, maintain, messages, log, warn: warn2 }) {
|
|
10570
10777
|
usage.start();
|
|
@@ -10616,7 +10823,8 @@ import { setTimeout as sleep3 } from "node:timers/promises";
|
|
|
10616
10823
|
// src/cli/service/service.ts
|
|
10617
10824
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
10618
10825
|
function serviceEnvironment(launch) {
|
|
10619
|
-
|
|
10826
|
+
const { CODEX_HOME } = launch.env;
|
|
10827
|
+
return { BACKLOG_DIR: launch.backlogRoot, PORT: String(launch.port), PATH: launch.env.PATH ?? "", HOME: launch.home, ...CODEX_HOME ? { CODEX_HOME } : {} };
|
|
10620
10828
|
}
|
|
10621
10829
|
async function numberRecordedIn(file, pattern, parse2, encoding = "utf8") {
|
|
10622
10830
|
const text = await readFile3(file, encoding).catch((error) => {
|
|
@@ -10988,11 +11196,11 @@ function reportFailure({ failed: failed2, code, output }, io) {
|
|
|
10988
11196
|
}
|
|
10989
11197
|
|
|
10990
11198
|
// src/cli/agents/grouped-stop-hooks.ts
|
|
10991
|
-
import { z as
|
|
11199
|
+
import { z as z21 } from "zod";
|
|
10992
11200
|
|
|
10993
11201
|
// src/cli/agents/json-config.ts
|
|
10994
11202
|
import { mkdir as mkdir10, readFile as readFile4, realpath } from "node:fs/promises";
|
|
10995
|
-
import { dirname as dirname12, resolve as
|
|
11203
|
+
import { dirname as dirname12, resolve as resolve5 } from "node:path";
|
|
10996
11204
|
var MAX_LINK_HOPS = 40;
|
|
10997
11205
|
async function readJsonConfig(path, schema) {
|
|
10998
11206
|
const text = await readConfigText(path);
|
|
@@ -11038,7 +11246,7 @@ async function danglingLinkTarget(path) {
|
|
|
11038
11246
|
for (let hop = 0; hop < MAX_LINK_HOPS; hop++) {
|
|
11039
11247
|
const link2 = await linkTargetOrNull(current);
|
|
11040
11248
|
if (link2 === null) return current;
|
|
11041
|
-
current =
|
|
11249
|
+
current = resolve5(dirname12(current), link2);
|
|
11042
11250
|
}
|
|
11043
11251
|
return current;
|
|
11044
11252
|
}
|
|
@@ -11051,9 +11259,9 @@ function commandOfHook(hook) {
|
|
|
11051
11259
|
const command2 = typeof hook === "object" && hook !== null ? hook.command : void 0;
|
|
11052
11260
|
return typeof command2 === "string" ? command2 : void 0;
|
|
11053
11261
|
}
|
|
11054
|
-
var stopGroupSchema =
|
|
11055
|
-
var groupedConfigSchema =
|
|
11056
|
-
hooks:
|
|
11262
|
+
var stopGroupSchema = z21.object({ hooks: z21.array(z21.unknown()).optional() }).passthrough();
|
|
11263
|
+
var groupedConfigSchema = z21.object({
|
|
11264
|
+
hooks: z21.object({ Stop: z21.array(stopGroupSchema).optional() }).passthrough().optional()
|
|
11057
11265
|
}).passthrough();
|
|
11058
11266
|
function refreshOurHook(lists, hook, { isOurs, isCurrent }) {
|
|
11059
11267
|
const ours = lists.flatMap((list) => list.flatMap((entry, index) => isOurs(entry) ? [{ list, index, entry }] : []));
|
|
@@ -11132,11 +11340,11 @@ function removeClaudeStopHook(settings) {
|
|
|
11132
11340
|
}
|
|
11133
11341
|
|
|
11134
11342
|
// src/cli/agents/cursor-hooks.ts
|
|
11135
|
-
import { z as
|
|
11343
|
+
import { z as z22 } from "zod";
|
|
11136
11344
|
var CURSOR_HOOKS_VERSION = 1;
|
|
11137
|
-
var cursorConfigSchema =
|
|
11138
|
-
version:
|
|
11139
|
-
hooks:
|
|
11345
|
+
var cursorConfigSchema = z22.object({
|
|
11346
|
+
version: z22.number().optional(),
|
|
11347
|
+
hooks: z22.object({ stop: z22.array(z22.unknown()).optional() }).passthrough().optional()
|
|
11140
11348
|
}).passthrough();
|
|
11141
11349
|
function addCursorStopHook(file, hook, ourHook) {
|
|
11142
11350
|
return addStopHookIn(
|
|
@@ -11488,7 +11696,7 @@ var statusCommand = taskFieldCommand({
|
|
|
11488
11696
|
});
|
|
11489
11697
|
|
|
11490
11698
|
// src/cli/commands/take.ts
|
|
11491
|
-
import { resolve as
|
|
11699
|
+
import { resolve as resolve6 } from "node:path";
|
|
11492
11700
|
var takeCommand = {
|
|
11493
11701
|
name: "take",
|
|
11494
11702
|
usage: (language) => cliMessages(language).takeUsage(),
|
|
@@ -11562,7 +11770,7 @@ function repoRelativePath(io, project, loaded, path) {
|
|
|
11562
11770
|
const typed = sourcePath(path);
|
|
11563
11771
|
const roots = cwdGitRoots(io);
|
|
11564
11772
|
if (roots === null || !cwdBelongsTo(project, loaded, io)) return typed;
|
|
11565
|
-
return pathFromProjectRepo(project, roots, repoContext(io),
|
|
11773
|
+
return pathFromProjectRepo(project, roots, repoContext(io), resolve6(realpathOrNull(io.cwd) ?? io.cwd, typed));
|
|
11566
11774
|
}
|
|
11567
11775
|
async function takeAll(index, chosen, io) {
|
|
11568
11776
|
const write = taskWriter(io, index);
|
|
@@ -11749,7 +11957,7 @@ async function readStdin() {
|
|
|
11749
11957
|
var home = homedir();
|
|
11750
11958
|
var backlogRoot = resolveBacklogRoot(process.env, home);
|
|
11751
11959
|
var cliPath = fileURLToPath(import.meta.url);
|
|
11752
|
-
var packageRoot =
|
|
11960
|
+
var packageRoot = resolve7(dirname13(cliPath), "..");
|
|
11753
11961
|
var argv = process.argv.slice(2);
|
|
11754
11962
|
var warn = (line) => void process.stderr.write(`${line}
|
|
11755
11963
|
`);
|