@staff0rd/assist 0.692.0 → 0.693.1
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/README.md +1 -1
- package/dist/commands/sessions/web/bundle.js +417 -417
- package/dist/index.js +1198 -893
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.693.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -296,8 +296,8 @@ function getRemoteOriginUrl(cwd) {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
// src/commands/backlog/getCurrentOrigin.ts
|
|
299
|
-
function stripLeadingSlashes(
|
|
300
|
-
return
|
|
299
|
+
function stripLeadingSlashes(path96) {
|
|
300
|
+
return path96.replace(/^\/+/, "");
|
|
301
301
|
}
|
|
302
302
|
function normalizeOrigin(raw) {
|
|
303
303
|
const trimmed = raw.trim().replace(/\.git$/i, "").replace(/\/+$/, "");
|
|
@@ -318,8 +318,8 @@ function normalizeOrigin(raw) {
|
|
|
318
318
|
function resolveCurrentOrigin(cwd) {
|
|
319
319
|
const remote = remoteUrl(cwd);
|
|
320
320
|
if (remote.url) return { origin: normalizeOrigin(remote.url), stable: true };
|
|
321
|
-
const
|
|
322
|
-
return { origin: `local:${
|
|
321
|
+
const root2 = tryGit(cwd, ["rev-parse", "--show-toplevel"]);
|
|
322
|
+
return { origin: `local:${root2 ?? cwd}`, stable: remote.ok };
|
|
323
323
|
}
|
|
324
324
|
function getCurrentOrigin(cwd) {
|
|
325
325
|
return resolveCurrentOrigin(cwd).origin;
|
|
@@ -329,14 +329,14 @@ function getCurrentOrigin(cwd) {
|
|
|
329
329
|
import { existsSync as existsSync2, readFileSync as readFileSync2, statSync } from "fs";
|
|
330
330
|
import { basename, dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
|
|
331
331
|
function linkedWorktree(dir) {
|
|
332
|
-
const
|
|
333
|
-
if (!
|
|
334
|
-
const gitDir = readGitDirPointer(
|
|
332
|
+
const root2 = findGitLink(dir);
|
|
333
|
+
if (!root2) return null;
|
|
334
|
+
const gitDir = readGitDirPointer(root2);
|
|
335
335
|
if (!gitDir) return null;
|
|
336
336
|
const commonDir = resolveCommonDir(gitDir);
|
|
337
337
|
if (!commonDir || basename(commonDir) !== ".git") return null;
|
|
338
338
|
const clone = dirname2(commonDir);
|
|
339
|
-
return existsSync2(clone) ? { root, clone } : null;
|
|
339
|
+
return existsSync2(clone) ? { root: root2, clone } : null;
|
|
340
340
|
}
|
|
341
341
|
function findGitLink(dir) {
|
|
342
342
|
let current = resolve(dir);
|
|
@@ -347,17 +347,17 @@ function findGitLink(dir) {
|
|
|
347
347
|
}
|
|
348
348
|
return null;
|
|
349
349
|
}
|
|
350
|
-
function isFile(
|
|
350
|
+
function isFile(path96) {
|
|
351
351
|
try {
|
|
352
|
-
return statSync(
|
|
352
|
+
return statSync(path96).isFile();
|
|
353
353
|
} catch {
|
|
354
354
|
return false;
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
function readGitDirPointer(
|
|
358
|
-
const target = readTrimmed(join2(
|
|
357
|
+
function readGitDirPointer(root2) {
|
|
358
|
+
const target = readTrimmed(join2(root2, ".git"));
|
|
359
359
|
if (!target?.startsWith("gitdir:")) return null;
|
|
360
|
-
return absolute(target.slice("gitdir:".length).trim(),
|
|
360
|
+
return absolute(target.slice("gitdir:".length).trim(), root2);
|
|
361
361
|
}
|
|
362
362
|
function resolveCommonDir(gitDir) {
|
|
363
363
|
const recorded = readTrimmed(join2(gitDir, "commondir"));
|
|
@@ -368,9 +368,9 @@ function linkedGitDirParent(gitDir) {
|
|
|
368
368
|
const match = /^(.*)[/\\]worktrees[/\\][^/\\]+[/\\]?$/.exec(gitDir);
|
|
369
369
|
return match ? match[1] : null;
|
|
370
370
|
}
|
|
371
|
-
function readTrimmed(
|
|
371
|
+
function readTrimmed(path96) {
|
|
372
372
|
try {
|
|
373
|
-
const content = readFileSync2(
|
|
373
|
+
const content = readFileSync2(path96, "utf8").trim();
|
|
374
374
|
return content === "" ? null : content;
|
|
375
375
|
} catch {
|
|
376
376
|
return null;
|
|
@@ -383,10 +383,10 @@ function absolute(target, from) {
|
|
|
383
383
|
// src/shared/loadRawYaml.ts
|
|
384
384
|
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
385
385
|
import { parse as parseYaml } from "yaml";
|
|
386
|
-
function loadRawYaml(
|
|
387
|
-
if (!existsSync3(
|
|
386
|
+
function loadRawYaml(path96) {
|
|
387
|
+
if (!existsSync3(path96)) return {};
|
|
388
388
|
try {
|
|
389
|
-
const content = readFileSync3(
|
|
389
|
+
const content = readFileSync3(path96, "utf8");
|
|
390
390
|
return parseYaml(content) || {};
|
|
391
391
|
} catch {
|
|
392
392
|
return {};
|
|
@@ -458,8 +458,8 @@ function mergeRawConfigs(globalRaw, projectRaw) {
|
|
|
458
458
|
// src/commands/backlog/originDisplayName.ts
|
|
459
459
|
function originDisplayName(origin) {
|
|
460
460
|
if (origin.startsWith("local:")) {
|
|
461
|
-
const
|
|
462
|
-
const segments =
|
|
461
|
+
const path96 = origin.slice("local:".length).replace(/\/+$/, "");
|
|
462
|
+
const segments = path96.split("/").filter(Boolean);
|
|
463
463
|
return segments[segments.length - 1] ?? origin;
|
|
464
464
|
}
|
|
465
465
|
const firstSlash = origin.indexOf("/");
|
|
@@ -2175,14 +2175,14 @@ function extractRazorComments(content) {
|
|
|
2175
2175
|
continue;
|
|
2176
2176
|
}
|
|
2177
2177
|
if (codeDepth > 0) {
|
|
2178
|
-
const
|
|
2179
|
-
codeDepth +=
|
|
2180
|
-
index3 =
|
|
2178
|
+
const step4 = stepRazorCode(content, index3);
|
|
2179
|
+
codeDepth += step4.depthChange;
|
|
2180
|
+
index3 = step4.next;
|
|
2181
2181
|
continue;
|
|
2182
2182
|
}
|
|
2183
|
-
const
|
|
2184
|
-
if (
|
|
2185
|
-
index3 =
|
|
2183
|
+
const step3 = stepRazorMarkup(content, index3);
|
|
2184
|
+
if (step3.enteredCode) codeDepth = 1;
|
|
2185
|
+
index3 = step3.next;
|
|
2186
2186
|
}
|
|
2187
2187
|
return comments3;
|
|
2188
2188
|
}
|
|
@@ -2573,9 +2573,9 @@ function segmentText(segment) {
|
|
|
2573
2573
|
if (segment.kind === "index") return `[${segment.index}]`;
|
|
2574
2574
|
return "[]";
|
|
2575
2575
|
}
|
|
2576
|
-
function formatConfigPath(
|
|
2576
|
+
function formatConfigPath(path96) {
|
|
2577
2577
|
let text18 = "";
|
|
2578
|
-
for (const segment of
|
|
2578
|
+
for (const segment of path96) {
|
|
2579
2579
|
const dotted = segment.kind === "key" || segment.kind === "entry";
|
|
2580
2580
|
const rendered = segmentText(segment);
|
|
2581
2581
|
text18 += dotted && text18 ? `.${rendered}` : rendered;
|
|
@@ -2736,11 +2736,11 @@ function enumValues(node) {
|
|
|
2736
2736
|
function opaqueConfigNode(inner, base) {
|
|
2737
2737
|
return { ...base, kind: "other", type: leafTypeOf(inner) };
|
|
2738
2738
|
}
|
|
2739
|
-
function build(node,
|
|
2739
|
+
function build(node, path96) {
|
|
2740
2740
|
const { inner, defaultValue, optional } = unwrapSchemaNode(node);
|
|
2741
2741
|
const secret = isSecretSchemaNode(node) || isSecretSchemaNode(inner);
|
|
2742
2742
|
const base = {
|
|
2743
|
-
path:
|
|
2743
|
+
path: path96,
|
|
2744
2744
|
...optional ? { optional: true } : {},
|
|
2745
2745
|
...defaultValue === void 0 ? {} : { defaultValue },
|
|
2746
2746
|
...secret ? { secret: true } : {}
|
|
@@ -3490,9 +3490,9 @@ import { existsSync as existsSync14, readFileSync as readFileSync11 } from "fs";
|
|
|
3490
3490
|
|
|
3491
3491
|
// src/commands/verify/forbiddenStrings/findForbiddenStrings.ts
|
|
3492
3492
|
import { minimatch as minimatch2 } from "minimatch";
|
|
3493
|
-
function resolveStringsAtPath(data,
|
|
3493
|
+
function resolveStringsAtPath(data, path96) {
|
|
3494
3494
|
let current = data;
|
|
3495
|
-
for (const segment of
|
|
3495
|
+
for (const segment of path96.split(".")) {
|
|
3496
3496
|
if (current === null || typeof current !== "object") return [];
|
|
3497
3497
|
current = current[segment];
|
|
3498
3498
|
}
|
|
@@ -3505,10 +3505,10 @@ function resolveStringsAtPath(data, path91) {
|
|
|
3505
3505
|
}
|
|
3506
3506
|
function findRuleViolations(data, rule) {
|
|
3507
3507
|
const violations = [];
|
|
3508
|
-
for (const
|
|
3509
|
-
for (const value of resolveStringsAtPath(data,
|
|
3508
|
+
for (const path96 of rule.paths) {
|
|
3509
|
+
for (const value of resolveStringsAtPath(data, path96)) {
|
|
3510
3510
|
if (minimatch2(value, rule.disallowed))
|
|
3511
|
-
violations.push({ file: rule.file, path:
|
|
3511
|
+
violations.push({ file: rule.file, path: path96, value });
|
|
3512
3512
|
}
|
|
3513
3513
|
}
|
|
3514
3514
|
return violations;
|
|
@@ -3547,8 +3547,8 @@ function forbiddenStrings() {
|
|
|
3547
3547
|
process.exit(0);
|
|
3548
3548
|
}
|
|
3549
3549
|
console.log("Forbidden strings found:\n");
|
|
3550
|
-
for (const { file, path:
|
|
3551
|
-
console.log(` ${file} ${
|
|
3550
|
+
for (const { file, path: path96, value } of violations) {
|
|
3551
|
+
console.log(` ${file} ${path96}: ${value}`);
|
|
3552
3552
|
}
|
|
3553
3553
|
console.log(`
|
|
3554
3554
|
Total: ${violations.length} forbidden string(s).`);
|
|
@@ -4151,15 +4151,15 @@ function readBaselineMigrations(repoRelativeDir, ref) {
|
|
|
4151
4151
|
} catch {
|
|
4152
4152
|
return baseline;
|
|
4153
4153
|
}
|
|
4154
|
-
const paths = listing.split("\n").map((line) => line.trim()).filter(Boolean).filter((
|
|
4155
|
-
for (const
|
|
4154
|
+
const paths = listing.split("\n").map((line) => line.trim()).filter(Boolean).filter((path96) => MIGRATION_FILE3.test(basename3(path96)));
|
|
4155
|
+
for (const path96 of paths) {
|
|
4156
4156
|
try {
|
|
4157
|
-
const content = execSync5(`git show "${ref}:${
|
|
4157
|
+
const content = execSync5(`git show "${ref}:${path96}"`, {
|
|
4158
4158
|
encoding: "utf8",
|
|
4159
4159
|
maxBuffer: 16 * 1024 * 1024,
|
|
4160
4160
|
stdio: ["pipe", "pipe", "pipe"]
|
|
4161
4161
|
});
|
|
4162
|
-
baseline.set(basename3(
|
|
4162
|
+
baseline.set(basename3(path96), content);
|
|
4163
4163
|
} catch {
|
|
4164
4164
|
}
|
|
4165
4165
|
}
|
|
@@ -5966,9 +5966,9 @@ function groupColumns(rows) {
|
|
|
5966
5966
|
}
|
|
5967
5967
|
|
|
5968
5968
|
// src/commands/backlog/dump/orderDumpTables.ts
|
|
5969
|
-
function buildGraph(
|
|
5970
|
-
const present = new Set(
|
|
5971
|
-
const indegree = new Map(
|
|
5969
|
+
function buildGraph(names2, edges) {
|
|
5970
|
+
const present = new Set(names2);
|
|
5971
|
+
const indegree = new Map(names2.map((n) => [n, 0]));
|
|
5972
5972
|
const children = /* @__PURE__ */ new Map();
|
|
5973
5973
|
for (const { child, parent } of edges) {
|
|
5974
5974
|
if (!present.has(child) || !present.has(parent)) continue;
|
|
@@ -5977,17 +5977,17 @@ function buildGraph(names, edges) {
|
|
|
5977
5977
|
}
|
|
5978
5978
|
return { indegree, children };
|
|
5979
5979
|
}
|
|
5980
|
-
function nextReady(
|
|
5981
|
-
return
|
|
5980
|
+
function nextReady(names2, emitted, indegree) {
|
|
5981
|
+
return names2.find((n) => !emitted.has(n) && (indegree.get(n) ?? 0) === 0);
|
|
5982
5982
|
}
|
|
5983
5983
|
function topoSort(entries, edges) {
|
|
5984
|
-
const
|
|
5985
|
-
const { indegree, children } = buildGraph(
|
|
5984
|
+
const names2 = entries.map((e) => e.raw);
|
|
5985
|
+
const { indegree, children } = buildGraph(names2, edges);
|
|
5986
5986
|
const byRaw = new Map(entries.map((e) => [e.raw, e.table]));
|
|
5987
5987
|
const ordered = [];
|
|
5988
5988
|
const emitted = /* @__PURE__ */ new Set();
|
|
5989
5989
|
while (ordered.length < entries.length) {
|
|
5990
|
-
const next3 = nextReady(
|
|
5990
|
+
const next3 = nextReady(names2, emitted, indegree);
|
|
5991
5991
|
if (!next3)
|
|
5992
5992
|
throw new Error("Cannot dump: foreign-key cycle between tables.");
|
|
5993
5993
|
emitted.add(next3);
|
|
@@ -6406,10 +6406,10 @@ var hooksSettings = {
|
|
|
6406
6406
|
}
|
|
6407
6407
|
};
|
|
6408
6408
|
function ensureHooksSettings() {
|
|
6409
|
-
const
|
|
6410
|
-
mkdirSync5(dirname14(
|
|
6411
|
-
writeFileSync15(
|
|
6412
|
-
return
|
|
6409
|
+
const path96 = daemonPaths.hooksSettings;
|
|
6410
|
+
mkdirSync5(dirname14(path96), { recursive: true });
|
|
6411
|
+
writeFileSync15(path96, JSON.stringify(hooksSettings, null, 2));
|
|
6412
|
+
return path96;
|
|
6413
6413
|
}
|
|
6414
6414
|
|
|
6415
6415
|
// src/shared/spawnInherit.ts
|
|
@@ -6587,8 +6587,8 @@ function getPreferredRemoteRepo(cwd) {
|
|
|
6587
6587
|
function gitRefUrl(kind, ref, cwd) {
|
|
6588
6588
|
const repo = getPreferredRemoteRepo(cwd);
|
|
6589
6589
|
if (!repo) return void 0;
|
|
6590
|
-
const
|
|
6591
|
-
return `https://github.com/${repo.org}/${repo.repo}/${
|
|
6590
|
+
const path96 = kind === "branch" ? "tree" : "commit";
|
|
6591
|
+
return `https://github.com/${repo.org}/${repo.repo}/${path96}/${ref}`;
|
|
6592
6592
|
}
|
|
6593
6593
|
|
|
6594
6594
|
// src/commands/branch/buildBranchName.ts
|
|
@@ -6671,13 +6671,13 @@ var TICK_MS = 80;
|
|
|
6671
6671
|
async function withSpinner(text18, task) {
|
|
6672
6672
|
if (!process.stderr.isTTY) return task();
|
|
6673
6673
|
let frame = 0;
|
|
6674
|
-
const
|
|
6674
|
+
const render2 = () => {
|
|
6675
6675
|
process.stderr.write(`\r${SPINNER_FRAMES[frame]} ${text18}`);
|
|
6676
6676
|
};
|
|
6677
|
-
|
|
6677
|
+
render2();
|
|
6678
6678
|
const timer = setInterval(() => {
|
|
6679
6679
|
frame = (frame + 1) % SPINNER_FRAMES.length;
|
|
6680
|
-
|
|
6680
|
+
render2();
|
|
6681
6681
|
}, TICK_MS);
|
|
6682
6682
|
try {
|
|
6683
6683
|
return await task();
|
|
@@ -6831,9 +6831,9 @@ var LOCAL_FILES = ["backlog.jsonl", "backlog.db"];
|
|
|
6831
6831
|
function backupLocalBacklogFiles(dir) {
|
|
6832
6832
|
const moved = [];
|
|
6833
6833
|
for (const name of LOCAL_FILES) {
|
|
6834
|
-
const
|
|
6835
|
-
if (existsSync21(
|
|
6836
|
-
renameSync(
|
|
6834
|
+
const path96 = join18(dir, ".assist", name);
|
|
6835
|
+
if (existsSync21(path96)) {
|
|
6836
|
+
renameSync(path96, `${path96}.bak`);
|
|
6837
6837
|
moved.push(`${name} \u2192 ${name}.bak`);
|
|
6838
6838
|
}
|
|
6839
6839
|
}
|
|
@@ -7317,8 +7317,8 @@ var backlogItemSchema = z4.strictObject({
|
|
|
7317
7317
|
var backlogFileSchema = z4.array(backlogItemSchema);
|
|
7318
7318
|
|
|
7319
7319
|
// src/commands/backlog/parseBacklogJsonl.ts
|
|
7320
|
-
function parseBacklogJsonl(
|
|
7321
|
-
const content = readFileSync16(
|
|
7320
|
+
function parseBacklogJsonl(path96) {
|
|
7321
|
+
const content = readFileSync16(path96, "utf8").trim();
|
|
7322
7322
|
if (content.length === 0) return [];
|
|
7323
7323
|
return content.split("\n").map((line) => line.trim()).filter(Boolean).map((line) => backlogItemSchema.parse(JSON.parse(line)));
|
|
7324
7324
|
}
|
|
@@ -7741,7 +7741,7 @@ function sendToDaemonAwaitAck(message3) {
|
|
|
7741
7741
|
return new Promise((resolve25, reject) => {
|
|
7742
7742
|
connectToDaemon().then((socket) => {
|
|
7743
7743
|
let settled = false;
|
|
7744
|
-
const
|
|
7744
|
+
const finish2 = (error) => {
|
|
7745
7745
|
if (settled) return;
|
|
7746
7746
|
settled = true;
|
|
7747
7747
|
clearTimeout(timer);
|
|
@@ -7750,16 +7750,16 @@ function sendToDaemonAwaitAck(message3) {
|
|
|
7750
7750
|
else resolve25();
|
|
7751
7751
|
};
|
|
7752
7752
|
const timer = setTimeout(
|
|
7753
|
-
() =>
|
|
7753
|
+
() => finish2(new Error("timed out awaiting daemon ack")),
|
|
7754
7754
|
ACK_TIMEOUT_MS
|
|
7755
7755
|
);
|
|
7756
7756
|
readSocketLines(socket, (line) => {
|
|
7757
|
-
if (isAck(line))
|
|
7757
|
+
if (isAck(line)) finish2();
|
|
7758
7758
|
});
|
|
7759
|
-
socket.on("error", (error) =>
|
|
7759
|
+
socket.on("error", (error) => finish2(error));
|
|
7760
7760
|
socket.on(
|
|
7761
7761
|
"close",
|
|
7762
|
-
() =>
|
|
7762
|
+
() => finish2(new Error("daemon closed before acknowledging"))
|
|
7763
7763
|
);
|
|
7764
7764
|
socket.write(`${JSON.stringify(message3)}
|
|
7765
7765
|
`);
|
|
@@ -8177,24 +8177,24 @@ function getOwnerPath(itemId2) {
|
|
|
8177
8177
|
function recordSignalOwner(itemId2) {
|
|
8178
8178
|
const sessionId = process.env.ASSIST_SESSION_ID;
|
|
8179
8179
|
if (!sessionId) return;
|
|
8180
|
-
const
|
|
8181
|
-
mkdirSync7(dirname16(
|
|
8182
|
-
writeFileSync17(
|
|
8180
|
+
const path96 = getOwnerPath(itemId2);
|
|
8181
|
+
mkdirSync7(dirname16(path96), { recursive: true });
|
|
8182
|
+
writeFileSync17(path96, JSON.stringify({ sessionId }));
|
|
8183
8183
|
}
|
|
8184
8184
|
function readSignalOwner(itemId2) {
|
|
8185
|
-
const
|
|
8186
|
-
if (!existsSync25(
|
|
8185
|
+
const path96 = getOwnerPath(itemId2);
|
|
8186
|
+
if (!existsSync25(path96)) return void 0;
|
|
8187
8187
|
try {
|
|
8188
|
-
const parsed = JSON.parse(readFileSync17(
|
|
8188
|
+
const parsed = JSON.parse(readFileSync17(path96, "utf8"));
|
|
8189
8189
|
return parsed.sessionId;
|
|
8190
8190
|
} catch {
|
|
8191
8191
|
return void 0;
|
|
8192
8192
|
}
|
|
8193
8193
|
}
|
|
8194
8194
|
function clearSignalOwner(itemId2) {
|
|
8195
|
-
const
|
|
8195
|
+
const path96 = getOwnerPath(itemId2);
|
|
8196
8196
|
try {
|
|
8197
|
-
rmSync(
|
|
8197
|
+
rmSync(path96);
|
|
8198
8198
|
} catch {
|
|
8199
8199
|
}
|
|
8200
8200
|
}
|
|
@@ -8231,19 +8231,19 @@ function resolveSignalTarget(event, data) {
|
|
|
8231
8231
|
function writeSignal(event, data) {
|
|
8232
8232
|
const target = resolveSignalTarget(event, data);
|
|
8233
8233
|
if (!target) return;
|
|
8234
|
-
const
|
|
8235
|
-
if (!
|
|
8234
|
+
const path96 = getSignalPath(target);
|
|
8235
|
+
if (!path96) return;
|
|
8236
8236
|
const signal = { event, sessionId: target, ...data };
|
|
8237
|
-
mkdirSync8(dirname17(
|
|
8238
|
-
writeFileSync18(
|
|
8237
|
+
mkdirSync8(dirname17(path96), { recursive: true });
|
|
8238
|
+
writeFileSync18(path96, JSON.stringify(signal));
|
|
8239
8239
|
}
|
|
8240
8240
|
|
|
8241
8241
|
// src/commands/backlog/readSignal.ts
|
|
8242
8242
|
function readSignal() {
|
|
8243
|
-
const
|
|
8244
|
-
if (!
|
|
8243
|
+
const path96 = getSignalPath();
|
|
8244
|
+
if (!path96 || !existsSync26(path96)) return void 0;
|
|
8245
8245
|
try {
|
|
8246
|
-
return JSON.parse(readFileSync18(
|
|
8246
|
+
return JSON.parse(readFileSync18(path96, "utf8"));
|
|
8247
8247
|
} catch {
|
|
8248
8248
|
return void 0;
|
|
8249
8249
|
}
|
|
@@ -8441,13 +8441,13 @@ function activityPath(sessionId) {
|
|
|
8441
8441
|
function emitActivity(activity2) {
|
|
8442
8442
|
const sessionId = process.env.ASSIST_ACTIVITY_ID;
|
|
8443
8443
|
if (!sessionId) return;
|
|
8444
|
-
const
|
|
8445
|
-
mkdirSync9(dirname18(
|
|
8446
|
-
writeFileSync19(
|
|
8444
|
+
const path96 = activityPath(sessionId);
|
|
8445
|
+
mkdirSync9(dirname18(path96), { recursive: true });
|
|
8446
|
+
writeFileSync19(path96, JSON.stringify({ ...activity2, startedAt: Date.now() }));
|
|
8447
8447
|
}
|
|
8448
|
-
function readActivity(
|
|
8448
|
+
function readActivity(path96) {
|
|
8449
8449
|
try {
|
|
8450
|
-
return JSON.parse(readFileSync19(
|
|
8450
|
+
return JSON.parse(readFileSync19(path96, "utf8"));
|
|
8451
8451
|
} catch {
|
|
8452
8452
|
return void 0;
|
|
8453
8453
|
}
|
|
@@ -8457,9 +8457,9 @@ function reconcileActivity(sessionId, activity2) {
|
|
|
8457
8457
|
removeActivity(sessionId);
|
|
8458
8458
|
return;
|
|
8459
8459
|
}
|
|
8460
|
-
const
|
|
8461
|
-
mkdirSync9(dirname18(
|
|
8462
|
-
writeFileSync19(
|
|
8460
|
+
const path96 = activityPath(sessionId);
|
|
8461
|
+
mkdirSync9(dirname18(path96), { recursive: true });
|
|
8462
|
+
writeFileSync19(path96, JSON.stringify(activity2));
|
|
8463
8463
|
}
|
|
8464
8464
|
function removeActivity(sessionId) {
|
|
8465
8465
|
try {
|
|
@@ -9942,10 +9942,10 @@ function getStorePath(filename) {
|
|
|
9942
9942
|
return join29(getStoreDir(), filename);
|
|
9943
9943
|
}
|
|
9944
9944
|
function loadJson(filename) {
|
|
9945
|
-
const
|
|
9946
|
-
if (existsSync31(
|
|
9945
|
+
const path96 = getStorePath(filename);
|
|
9946
|
+
if (existsSync31(path96)) {
|
|
9947
9947
|
try {
|
|
9948
|
-
return JSON.parse(readFileSync20(
|
|
9948
|
+
return JSON.parse(readFileSync20(path96, "utf8"));
|
|
9949
9949
|
} catch {
|
|
9950
9950
|
return {};
|
|
9951
9951
|
}
|
|
@@ -9964,22 +9964,22 @@ function saveJson(filename, data) {
|
|
|
9964
9964
|
var REGISTRY_FILE = "worktrees.json";
|
|
9965
9965
|
function readWorktreeRegistry() {
|
|
9966
9966
|
const data = loadJson(REGISTRY_FILE);
|
|
9967
|
-
return Object.entries(data).filter(([, record]) => !record.reaped).map(([
|
|
9967
|
+
return Object.entries(data).filter(([, record]) => !record.reaped).map(([path96, record]) => ({ path: path96, ...record }));
|
|
9968
9968
|
}
|
|
9969
|
-
function worktreeAttributionIncludingReaped(
|
|
9970
|
-
const record = loadJson(REGISTRY_FILE)[
|
|
9969
|
+
function worktreeAttributionIncludingReaped(path96) {
|
|
9970
|
+
const record = loadJson(REGISTRY_FILE)[path96];
|
|
9971
9971
|
return record ? { clone: record.clone, origin: record.origin } : void 0;
|
|
9972
9972
|
}
|
|
9973
|
-
function recordWorktree(
|
|
9973
|
+
function recordWorktree(path96, clone, origin) {
|
|
9974
9974
|
const data = loadJson(REGISTRY_FILE);
|
|
9975
|
-
data[
|
|
9975
|
+
data[path96] = { clone, origin };
|
|
9976
9976
|
saveJson(REGISTRY_FILE, data);
|
|
9977
9977
|
}
|
|
9978
|
-
function forgetWorktree(
|
|
9978
|
+
function forgetWorktree(path96) {
|
|
9979
9979
|
const data = loadJson(REGISTRY_FILE);
|
|
9980
|
-
const record = data[
|
|
9980
|
+
const record = data[path96];
|
|
9981
9981
|
if (!record || record.reaped) return;
|
|
9982
|
-
data[
|
|
9982
|
+
data[path96] = { ...record, reaped: true };
|
|
9983
9983
|
saveJson(REGISTRY_FILE, data);
|
|
9984
9984
|
}
|
|
9985
9985
|
|
|
@@ -10807,8 +10807,8 @@ async function loadCommittedPaths(cwd, sessionId) {
|
|
|
10807
10807
|
for (const commit2 of commits2) {
|
|
10808
10808
|
const resolved = await resolveCommit(cwd, commit2.sha);
|
|
10809
10809
|
if (!resolved) continue;
|
|
10810
|
-
for (const
|
|
10811
|
-
if (!bases.has(
|
|
10810
|
+
for (const path96 of resolved.paths) {
|
|
10811
|
+
if (!bases.has(path96)) bases.set(path96, resolved.base);
|
|
10812
10812
|
}
|
|
10813
10813
|
}
|
|
10814
10814
|
return { commits: commits2, bases };
|
|
@@ -10826,16 +10826,16 @@ async function itemChangeSet(cwd, sessionId) {
|
|
|
10826
10826
|
}
|
|
10827
10827
|
function groupByBase(bases) {
|
|
10828
10828
|
const groups = /* @__PURE__ */ new Map();
|
|
10829
|
-
for (const [
|
|
10829
|
+
for (const [path96, base] of bases) {
|
|
10830
10830
|
const paths = groups.get(base);
|
|
10831
|
-
if (paths) paths.push(
|
|
10832
|
-
else groups.set(base, [
|
|
10831
|
+
if (paths) paths.push(path96);
|
|
10832
|
+
else groups.set(base, [path96]);
|
|
10833
10833
|
}
|
|
10834
10834
|
return [...groups].map(([base, paths]) => ({ base, paths: paths.sort() }));
|
|
10835
10835
|
}
|
|
10836
10836
|
async function dirtyPaths(cwd, bases) {
|
|
10837
10837
|
const output = await execGit(cwd, ["diff", "--name-only", "HEAD"]);
|
|
10838
|
-
return output.split("\n").filter((
|
|
10838
|
+
return output.split("\n").filter((path96) => path96 && !bases.has(path96)).sort();
|
|
10839
10839
|
}
|
|
10840
10840
|
|
|
10841
10841
|
// src/commands/sessions/web/scopedDiff.ts
|
|
@@ -10844,8 +10844,8 @@ async function scopedDiff(cwd, session, scope) {
|
|
|
10844
10844
|
if (scope.kind === "commit") return commitDiff(cwd, scope.sha);
|
|
10845
10845
|
return await trackedScopeDiff(cwd, session, scope) + await untrackedDiff(cwd);
|
|
10846
10846
|
}
|
|
10847
|
-
async function untrackedFileDiff(cwd,
|
|
10848
|
-
return execGit(cwd, ["diff", "--no-index", "--", "/dev/null",
|
|
10847
|
+
async function untrackedFileDiff(cwd, path96) {
|
|
10848
|
+
return execGit(cwd, ["diff", "--no-index", "--", "/dev/null", path96], {
|
|
10849
10849
|
maxBuffer: MAX_DIFF_BYTES,
|
|
10850
10850
|
allowFailure: true
|
|
10851
10851
|
});
|
|
@@ -10858,7 +10858,7 @@ async function untrackedDiff(cwd) {
|
|
|
10858
10858
|
]);
|
|
10859
10859
|
const paths = list5.split("\n").filter(Boolean);
|
|
10860
10860
|
const diffs = await Promise.all(
|
|
10861
|
-
paths.map((
|
|
10861
|
+
paths.map((path96) => untrackedFileDiff(cwd, path96))
|
|
10862
10862
|
);
|
|
10863
10863
|
return diffs.join("");
|
|
10864
10864
|
}
|
|
@@ -10951,10 +10951,10 @@ import { isAbsolute as isAbsolute2, relative as relative2, resolve as resolve10
|
|
|
10951
10951
|
function repoRoot(cwd) {
|
|
10952
10952
|
return resolve10(toGitCwd(cwd));
|
|
10953
10953
|
}
|
|
10954
|
-
function resolveWithinCwd(cwd,
|
|
10955
|
-
const
|
|
10956
|
-
const target = resolve10(
|
|
10957
|
-
const rel = relative2(
|
|
10954
|
+
function resolveWithinCwd(cwd, path96) {
|
|
10955
|
+
const root2 = repoRoot(cwd);
|
|
10956
|
+
const target = resolve10(root2, path96);
|
|
10957
|
+
const rel = relative2(root2, target);
|
|
10958
10958
|
if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) return null;
|
|
10959
10959
|
return target;
|
|
10960
10960
|
}
|
|
@@ -10963,14 +10963,14 @@ function resolveWithinCwd(cwd, path91) {
|
|
|
10963
10963
|
function getFileTarget(req, res) {
|
|
10964
10964
|
const cwd = getCwdParam(req, res);
|
|
10965
10965
|
if (!cwd) return null;
|
|
10966
|
-
const
|
|
10966
|
+
const path96 = new URL(req.url ?? "/", "http://localhost").searchParams.get(
|
|
10967
10967
|
"path"
|
|
10968
10968
|
);
|
|
10969
|
-
if (!
|
|
10969
|
+
if (!path96) {
|
|
10970
10970
|
respondJson(res, 400, { error: "Missing path" });
|
|
10971
10971
|
return null;
|
|
10972
10972
|
}
|
|
10973
|
-
const target = resolveWithinCwd(cwd,
|
|
10973
|
+
const target = resolveWithinCwd(cwd, path96);
|
|
10974
10974
|
if (!target) {
|
|
10975
10975
|
respondJson(res, 400, { error: "Path outside cwd" });
|
|
10976
10976
|
return null;
|
|
@@ -11045,11 +11045,11 @@ function globalConfigTargetFor(cwd) {
|
|
|
11045
11045
|
|
|
11046
11046
|
// src/commands/config/globalConfigFileLabel.ts
|
|
11047
11047
|
var WINDOWS_MOUNT_PREFIX = "/mnt/";
|
|
11048
|
-
function globalConfigFileLabel(
|
|
11049
|
-
if (
|
|
11050
|
-
if (
|
|
11051
|
-
return `${
|
|
11052
|
-
return
|
|
11048
|
+
function globalConfigFileLabel(path96) {
|
|
11049
|
+
if (path96 === getGlobalConfigPath()) return "~/.assist.yml";
|
|
11050
|
+
if (path96.startsWith(WINDOWS_MOUNT_PREFIX))
|
|
11051
|
+
return `${path96} on the Windows host`;
|
|
11052
|
+
return path96;
|
|
11053
11053
|
}
|
|
11054
11054
|
|
|
11055
11055
|
// src/commands/config/readRawConfigLayers.ts
|
|
@@ -11106,35 +11106,35 @@ function isPlainRecord(value) {
|
|
|
11106
11106
|
}
|
|
11107
11107
|
|
|
11108
11108
|
// src/shared/mapConfigSecrets.ts
|
|
11109
|
-
function mapChildren(value,
|
|
11109
|
+
function mapChildren(value, path96, childNode, map) {
|
|
11110
11110
|
if (!isPlainRecord(value)) return value;
|
|
11111
11111
|
return Object.fromEntries(
|
|
11112
11112
|
Object.entries(value).map(([name, child]) => [
|
|
11113
11113
|
name,
|
|
11114
|
-
walk(child, [...
|
|
11114
|
+
walk(child, [...path96, name], childNode(name), map)
|
|
11115
11115
|
])
|
|
11116
11116
|
);
|
|
11117
11117
|
}
|
|
11118
|
-
function mapItems(value,
|
|
11118
|
+
function mapItems(value, path96, item, map) {
|
|
11119
11119
|
if (!Array.isArray(value)) return value;
|
|
11120
|
-
return value.map((entry, index3) => walk(entry, [...
|
|
11120
|
+
return value.map((entry, index3) => walk(entry, [...path96, index3], item, map));
|
|
11121
11121
|
}
|
|
11122
|
-
function walk(value,
|
|
11122
|
+
function walk(value, path96, node, map) {
|
|
11123
11123
|
if (!node || value === void 0 || value === null) return value;
|
|
11124
|
-
if (node.secret) return map(value,
|
|
11124
|
+
if (node.secret) return map(value, path96);
|
|
11125
11125
|
switch (node.kind) {
|
|
11126
11126
|
case "object":
|
|
11127
11127
|
case "unionOfObjects":
|
|
11128
11128
|
return mapChildren(
|
|
11129
11129
|
value,
|
|
11130
|
-
|
|
11130
|
+
path96,
|
|
11131
11131
|
(name) => configNodeField(node, name),
|
|
11132
11132
|
map
|
|
11133
11133
|
);
|
|
11134
11134
|
case "objectList":
|
|
11135
|
-
return mapItems(value,
|
|
11135
|
+
return mapItems(value, path96, node.item, map);
|
|
11136
11136
|
case "record":
|
|
11137
|
-
return mapChildren(value,
|
|
11137
|
+
return mapChildren(value, path96, () => node.value, map);
|
|
11138
11138
|
default:
|
|
11139
11139
|
return value;
|
|
11140
11140
|
}
|
|
@@ -11159,9 +11159,9 @@ function isTraversable(value) {
|
|
|
11159
11159
|
function stepInto(current, key) {
|
|
11160
11160
|
return isTraversable(current) ? current[key] : void 0;
|
|
11161
11161
|
}
|
|
11162
|
-
function getNestedValue(obj,
|
|
11162
|
+
function getNestedValue(obj, path96) {
|
|
11163
11163
|
let current = obj;
|
|
11164
|
-
for (const key of
|
|
11164
|
+
for (const key of path96.split(".")) current = stepInto(current, key);
|
|
11165
11165
|
return current;
|
|
11166
11166
|
}
|
|
11167
11167
|
|
|
@@ -11211,9 +11211,9 @@ function step(node, segment) {
|
|
|
11211
11211
|
return void 0;
|
|
11212
11212
|
}
|
|
11213
11213
|
}
|
|
11214
|
-
function findConfigNode(
|
|
11215
|
-
let current =
|
|
11216
|
-
for (const segment of
|
|
11214
|
+
function findConfigNode(root2, path96) {
|
|
11215
|
+
let current = root2;
|
|
11216
|
+
for (const segment of path96) {
|
|
11217
11217
|
if (!current) return void 0;
|
|
11218
11218
|
current = step(current, segment);
|
|
11219
11219
|
}
|
|
@@ -11230,34 +11230,34 @@ function nameSegment(name) {
|
|
|
11230
11230
|
return name === RECORD_ENTRY_TOKEN ? { kind: "entry" } : { kind: "key", name };
|
|
11231
11231
|
}
|
|
11232
11232
|
function parseConfigPath(text18) {
|
|
11233
|
-
const
|
|
11233
|
+
const path96 = [];
|
|
11234
11234
|
let at2 = 0;
|
|
11235
11235
|
while (at2 < text18.length) {
|
|
11236
11236
|
if (text18[at2] === "[") {
|
|
11237
11237
|
const close = text18.indexOf("]", at2);
|
|
11238
11238
|
const segment = close === -1 ? void 0 : bracketSegment(text18.slice(at2 + 1, close));
|
|
11239
11239
|
if (!segment) return void 0;
|
|
11240
|
-
|
|
11240
|
+
path96.push(segment);
|
|
11241
11241
|
at2 = close + 1;
|
|
11242
11242
|
continue;
|
|
11243
11243
|
}
|
|
11244
11244
|
if (text18[at2] === ".") {
|
|
11245
|
-
if (
|
|
11245
|
+
if (path96.length === 0) return void 0;
|
|
11246
11246
|
at2 += 1;
|
|
11247
11247
|
}
|
|
11248
11248
|
const start3 = at2;
|
|
11249
11249
|
while (at2 < text18.length && text18[at2] !== "." && text18[at2] !== "[") at2 += 1;
|
|
11250
11250
|
const name = text18.slice(start3, at2);
|
|
11251
11251
|
if (!name) return void 0;
|
|
11252
|
-
|
|
11252
|
+
path96.push(nameSegment(name));
|
|
11253
11253
|
}
|
|
11254
|
-
return
|
|
11254
|
+
return path96;
|
|
11255
11255
|
}
|
|
11256
11256
|
|
|
11257
11257
|
// src/commands/config/configEntryNode.ts
|
|
11258
|
-
function configEntryNode(
|
|
11259
|
-
const
|
|
11260
|
-
return
|
|
11258
|
+
function configEntryNode(root2, key) {
|
|
11259
|
+
const path96 = parseConfigPath(key);
|
|
11260
|
+
return path96 ? findConfigNode(root2, path96) : void 0;
|
|
11261
11261
|
}
|
|
11262
11262
|
|
|
11263
11263
|
// src/commands/config/configHelpForKey.ts
|
|
@@ -11392,7 +11392,7 @@ function findSynthesisForBranch(repoReviewsDir, branch2) {
|
|
|
11392
11392
|
const parent = dirname22(branchKeyPath);
|
|
11393
11393
|
const branchPrefix = basename10(branchKeyPath);
|
|
11394
11394
|
if (!existsSync34(parent)) return null;
|
|
11395
|
-
const synthesisFiles = readdirSync3(parent).filter((name) => name.startsWith(branchPrefix)).map((name) => join32(parent, name, "synthesis.md")).filter((
|
|
11395
|
+
const synthesisFiles = readdirSync3(parent).filter((name) => name.startsWith(branchPrefix)).map((name) => join32(parent, name, "synthesis.md")).filter((path96) => existsSync34(path96)).map((path96) => ({ path: path96, mtime: statSync4(path96).mtimeMs })).sort((a, b) => b.mtime - a.mtime);
|
|
11396
11396
|
return synthesisFiles[0]?.path ?? null;
|
|
11397
11397
|
}
|
|
11398
11398
|
|
|
@@ -11422,12 +11422,12 @@ async function getReviewSynthesis(req, res) {
|
|
|
11422
11422
|
const cwd = getCwdParam(req, res);
|
|
11423
11423
|
if (!cwd) return;
|
|
11424
11424
|
try {
|
|
11425
|
-
const
|
|
11426
|
-
if (!
|
|
11425
|
+
const path96 = await resolveSynthesisPath(cwd);
|
|
11426
|
+
if (!path96) {
|
|
11427
11427
|
respondJson(res, 404, { error: "No synthesis found" });
|
|
11428
11428
|
return;
|
|
11429
11429
|
}
|
|
11430
|
-
respondJson(res, 200, { synthesis: readFileSync22(
|
|
11430
|
+
respondJson(res, 200, { synthesis: readFileSync22(path96, "utf8") });
|
|
11431
11431
|
} catch {
|
|
11432
11432
|
respondJson(res, 404, { error: "No synthesis found" });
|
|
11433
11433
|
}
|
|
@@ -11510,8 +11510,8 @@ function parseDiffNameStatus(output) {
|
|
|
11510
11510
|
if (!status3 || fields.length < 2) continue;
|
|
11511
11511
|
const category = categorize(status3[0]);
|
|
11512
11512
|
if (!category) continue;
|
|
11513
|
-
const
|
|
11514
|
-
if (
|
|
11513
|
+
const path96 = fields[fields.length - 1];
|
|
11514
|
+
if (path96) result[category].push(path96);
|
|
11515
11515
|
}
|
|
11516
11516
|
return result;
|
|
11517
11517
|
}
|
|
@@ -11647,21 +11647,21 @@ function subsequenceScore(text18, query) {
|
|
|
11647
11647
|
}
|
|
11648
11648
|
return score - Math.min(text18.length, MAX_LENGTH_PENALTY);
|
|
11649
11649
|
}
|
|
11650
|
-
function scoreFilePath(
|
|
11650
|
+
function scoreFilePath(path96, query) {
|
|
11651
11651
|
const needle = query.trim().toLowerCase();
|
|
11652
11652
|
if (!needle) return 0;
|
|
11653
|
-
const basename30 =
|
|
11653
|
+
const basename30 = path96.slice(path96.lastIndexOf("/") + 1);
|
|
11654
11654
|
const inBasename = subsequenceScore(basename30, needle);
|
|
11655
11655
|
if (inBasename !== null) return BASENAME_WEIGHT + inBasename;
|
|
11656
|
-
return subsequenceScore(
|
|
11656
|
+
return subsequenceScore(path96, needle);
|
|
11657
11657
|
}
|
|
11658
11658
|
|
|
11659
11659
|
// src/commands/sessions/web/rankFilePaths.ts
|
|
11660
11660
|
function rankFilePaths(paths, query, limit) {
|
|
11661
11661
|
const scored = [];
|
|
11662
|
-
for (const
|
|
11663
|
-
const score = scoreFilePath(
|
|
11664
|
-
if (score !== null) scored.push({ path:
|
|
11662
|
+
for (const path96 of paths) {
|
|
11663
|
+
const score = scoreFilePath(path96, query);
|
|
11664
|
+
if (score !== null) scored.push({ path: path96, score });
|
|
11665
11665
|
}
|
|
11666
11666
|
scored.sort((a, b) => b.score - a.score || a.path.localeCompare(b.path));
|
|
11667
11667
|
return scored.slice(0, limit).map((entry) => entry.path);
|
|
@@ -11882,13 +11882,13 @@ function scopeDirectory(target) {
|
|
|
11882
11882
|
// src/commands/rules/readScopedRules.ts
|
|
11883
11883
|
function scopedClaudeFiles(target) {
|
|
11884
11884
|
const startDir = scopeDirectory(target);
|
|
11885
|
-
const
|
|
11885
|
+
const root2 = findRepoRoot(startDir) ?? startDir;
|
|
11886
11886
|
const files = [];
|
|
11887
11887
|
let current = startDir;
|
|
11888
11888
|
while (true) {
|
|
11889
11889
|
const candidate = path25.join(current, "CLAUDE.md");
|
|
11890
11890
|
if (existsSync36(candidate)) files.push(candidate);
|
|
11891
|
-
if (current ===
|
|
11891
|
+
if (current === root2 || current === path25.dirname(current)) break;
|
|
11892
11892
|
current = path25.dirname(current);
|
|
11893
11893
|
}
|
|
11894
11894
|
return files;
|
|
@@ -11910,8 +11910,8 @@ function listScopedRules(req, res) {
|
|
|
11910
11910
|
req.url ?? "/",
|
|
11911
11911
|
"http://localhost"
|
|
11912
11912
|
).searchParams.get("path");
|
|
11913
|
-
const
|
|
11914
|
-
const target = requested ? resolveWithinCwd(cwd, requested) :
|
|
11913
|
+
const root2 = repoRoot(cwd);
|
|
11914
|
+
const target = requested ? resolveWithinCwd(cwd, requested) : root2;
|
|
11915
11915
|
if (!target) {
|
|
11916
11916
|
respondJson(res, 400, { error: "Path outside cwd" });
|
|
11917
11917
|
return;
|
|
@@ -11920,7 +11920,7 @@ function listScopedRules(req, res) {
|
|
|
11920
11920
|
respondJson(res, 200, {
|
|
11921
11921
|
rules: readScopedRules(target).map((rule) => ({
|
|
11922
11922
|
...rule,
|
|
11923
|
-
source: path26.relative(
|
|
11923
|
+
source: path26.relative(root2, rule.source) || rule.source
|
|
11924
11924
|
}))
|
|
11925
11925
|
});
|
|
11926
11926
|
} catch {
|
|
@@ -11976,6 +11976,22 @@ async function listUsagePeaks(db, options2) {
|
|
|
11976
11976
|
return query;
|
|
11977
11977
|
}
|
|
11978
11978
|
|
|
11979
|
+
// src/shared/usageWindowKey.ts
|
|
11980
|
+
var RATE_LIMIT_WINDOWS = ["five_hour", "seven_day"];
|
|
11981
|
+
var HARNESS_KINDS = ["claude", "codex", "pi"];
|
|
11982
|
+
function usageWindowKey(harness, window) {
|
|
11983
|
+
const kind = resolveHarness(harness);
|
|
11984
|
+
return kind === "claude" ? window : `${kind}:${window}`;
|
|
11985
|
+
}
|
|
11986
|
+
function parseUsageWindowKey(key) {
|
|
11987
|
+
const [prefix2, suffix] = key.includes(":") ? key.split(":", 2) : ["claude", key];
|
|
11988
|
+
const harness = HARNESS_KINDS.find((h) => h === prefix2);
|
|
11989
|
+
const window = RATE_LIMIT_WINDOWS.find((w) => w === suffix);
|
|
11990
|
+
if (!harness || !window) return void 0;
|
|
11991
|
+
if (harness === "claude" && key.includes(":")) return void 0;
|
|
11992
|
+
return { harness, window };
|
|
11993
|
+
}
|
|
11994
|
+
|
|
11979
11995
|
// src/commands/sessions/web/respondPagedRows.ts
|
|
11980
11996
|
var DEFAULT_PAGE_SIZE = 30;
|
|
11981
11997
|
async function respondPagedRows(req, res, load3) {
|
|
@@ -11987,7 +12003,9 @@ async function respondPagedRows(req, res, load3) {
|
|
|
11987
12003
|
|
|
11988
12004
|
// src/commands/sessions/web/listUsageHistory.ts
|
|
11989
12005
|
function parseWindow(value) {
|
|
11990
|
-
|
|
12006
|
+
if (!value) return void 0;
|
|
12007
|
+
const parsed = parseUsageWindowKey(value);
|
|
12008
|
+
return parsed ? usageWindowKey(parsed.harness, parsed.window) : void 0;
|
|
11991
12009
|
}
|
|
11992
12010
|
function listUsageHistory(req, res) {
|
|
11993
12011
|
return respondPagedRows(req, res, async (range, params) => {
|
|
@@ -12593,8 +12611,8 @@ async function liveDeployments(cwd, repo, environments) {
|
|
|
12593
12611
|
|
|
12594
12612
|
// src/commands/sessions/web/releases/latestRun.ts
|
|
12595
12613
|
async function latestRun(cwd, repo, workflow) {
|
|
12596
|
-
const
|
|
12597
|
-
const response = await ghJson(cwd, ["api",
|
|
12614
|
+
const path96 = `repos/${repo}/actions/workflows/${encodeURIComponent(workflow)}/runs?per_page=1&exclude_pull_requests=true`;
|
|
12615
|
+
const response = await ghJson(cwd, ["api", path96]);
|
|
12598
12616
|
const run4 = response.workflow_runs?.[0];
|
|
12599
12617
|
if (!run4) return null;
|
|
12600
12618
|
return {
|
|
@@ -12657,18 +12675,18 @@ function mostSpecificFirst(nodes) {
|
|
|
12657
12675
|
(a, b) => (b.tokens[0]?.length ?? 0) - (a.tokens[0]?.length ?? 0) || a.index - b.index
|
|
12658
12676
|
);
|
|
12659
12677
|
}
|
|
12660
|
-
function firstUnclaimed(
|
|
12678
|
+
function firstUnclaimed(names2, claimed, tokens) {
|
|
12661
12679
|
for (const token of tokens)
|
|
12662
|
-
for (const [index3, name] of
|
|
12680
|
+
for (const [index3, name] of names2.entries())
|
|
12663
12681
|
if (!claimed.has(index3) && name.includes(token)) return index3;
|
|
12664
12682
|
return void 0;
|
|
12665
12683
|
}
|
|
12666
12684
|
function matchRunJobs(nodes, jobs) {
|
|
12667
|
-
const
|
|
12685
|
+
const names2 = jobs.map((job) => normaliseJobName(job.name));
|
|
12668
12686
|
const claimed = /* @__PURE__ */ new Set();
|
|
12669
12687
|
const matched = /* @__PURE__ */ new Map();
|
|
12670
12688
|
for (const { node, tokens } of mostSpecificFirst(nodes)) {
|
|
12671
|
-
const hit = firstUnclaimed(
|
|
12689
|
+
const hit = firstUnclaimed(names2, claimed, tokens);
|
|
12672
12690
|
const job = hit === void 0 ? void 0 : jobs[hit];
|
|
12673
12691
|
if (hit !== void 0) claimed.add(hit);
|
|
12674
12692
|
matched.set(node.id, job ? runJobState(job) : UNREACHED_BY_RUN);
|
|
@@ -12870,38 +12888,38 @@ async function restartWeb(req, res, deps2 = {}) {
|
|
|
12870
12888
|
import { relative as relative3 } from "path";
|
|
12871
12889
|
|
|
12872
12890
|
// src/commands/sessions/web/revertPathChanges.ts
|
|
12873
|
-
async function isTracked(cwd,
|
|
12891
|
+
async function isTracked(cwd, path96) {
|
|
12874
12892
|
try {
|
|
12875
|
-
await execGit(cwd, ["ls-files", "--error-unmatch", "--",
|
|
12893
|
+
await execGit(cwd, ["ls-files", "--error-unmatch", "--", path96]);
|
|
12876
12894
|
return true;
|
|
12877
12895
|
} catch {
|
|
12878
12896
|
return false;
|
|
12879
12897
|
}
|
|
12880
12898
|
}
|
|
12881
|
-
async function isInHead(cwd,
|
|
12882
|
-
const listing = await execGit(cwd, ["ls-tree", "HEAD", "--",
|
|
12899
|
+
async function isInHead(cwd, path96) {
|
|
12900
|
+
const listing = await execGit(cwd, ["ls-tree", "HEAD", "--", path96]);
|
|
12883
12901
|
return listing.trim().length > 0;
|
|
12884
12902
|
}
|
|
12885
|
-
async function revertPathChanges(cwd,
|
|
12886
|
-
if (!await isTracked(cwd,
|
|
12887
|
-
await execGit(cwd, ["clean", "-f", "--",
|
|
12903
|
+
async function revertPathChanges(cwd, path96) {
|
|
12904
|
+
if (!await isTracked(cwd, path96)) {
|
|
12905
|
+
await execGit(cwd, ["clean", "-f", "--", path96]);
|
|
12888
12906
|
return;
|
|
12889
12907
|
}
|
|
12890
|
-
if (await isInHead(cwd,
|
|
12891
|
-
await execGit(cwd, ["checkout", "HEAD", "--",
|
|
12908
|
+
if (await isInHead(cwd, path96)) {
|
|
12909
|
+
await execGit(cwd, ["checkout", "HEAD", "--", path96]);
|
|
12892
12910
|
return;
|
|
12893
12911
|
}
|
|
12894
|
-
await execGit(cwd, ["rm", "-f", "--",
|
|
12912
|
+
await execGit(cwd, ["rm", "-f", "--", path96]);
|
|
12895
12913
|
}
|
|
12896
12914
|
|
|
12897
12915
|
// src/commands/sessions/web/revertDiffFile.ts
|
|
12898
12916
|
async function revertDiffFile(req, res) {
|
|
12899
12917
|
const resolved = getFileTarget(req, res);
|
|
12900
12918
|
if (!resolved) return;
|
|
12901
|
-
const
|
|
12919
|
+
const path96 = relative3(repoRoot(resolved.cwd), resolved.target);
|
|
12902
12920
|
try {
|
|
12903
|
-
await revertPathChanges(resolved.cwd,
|
|
12904
|
-
respondJson(res, 200, { reverted:
|
|
12921
|
+
await revertPathChanges(resolved.cwd, path96);
|
|
12922
|
+
respondJson(res, 200, { reverted: path96 });
|
|
12905
12923
|
} catch (error) {
|
|
12906
12924
|
respondJson(res, 500, {
|
|
12907
12925
|
error: error instanceof Error ? error.message : "Failed to revert file"
|
|
@@ -12923,7 +12941,7 @@ async function readJsonBody(req) {
|
|
|
12923
12941
|
function requestedPaths(body) {
|
|
12924
12942
|
const paths = body.paths;
|
|
12925
12943
|
if (!Array.isArray(paths)) return null;
|
|
12926
|
-
if (paths.some((
|
|
12944
|
+
if (paths.some((path96) => typeof path96 !== "string")) return null;
|
|
12927
12945
|
return paths;
|
|
12928
12946
|
}
|
|
12929
12947
|
async function revertDiffPaths(req, res) {
|
|
@@ -12940,16 +12958,16 @@ async function revertDiffPaths(req, res) {
|
|
|
12940
12958
|
respondJson(res, 400, { error: "Missing paths" });
|
|
12941
12959
|
return;
|
|
12942
12960
|
}
|
|
12943
|
-
const
|
|
12961
|
+
const root2 = repoRoot(cwd);
|
|
12944
12962
|
const reverted = [];
|
|
12945
12963
|
const failed2 = [];
|
|
12946
|
-
for (const
|
|
12947
|
-
const target = resolveWithinCwd(cwd,
|
|
12964
|
+
for (const path96 of paths) {
|
|
12965
|
+
const target = resolveWithinCwd(cwd, path96);
|
|
12948
12966
|
if (!target) {
|
|
12949
|
-
failed2.push({ path:
|
|
12967
|
+
failed2.push({ path: path96, error: "Path outside cwd" });
|
|
12950
12968
|
continue;
|
|
12951
12969
|
}
|
|
12952
|
-
const relativePath = relative4(
|
|
12970
|
+
const relativePath = relative4(root2, target);
|
|
12953
12971
|
try {
|
|
12954
12972
|
await revertPathChanges(cwd, relativePath);
|
|
12955
12973
|
reverted.push(relativePath);
|
|
@@ -13036,11 +13054,11 @@ function coerceStructuredConfigValue(key, raw) {
|
|
|
13036
13054
|
};
|
|
13037
13055
|
}
|
|
13038
13056
|
function formatIssue(key, issue) {
|
|
13039
|
-
const
|
|
13057
|
+
const path96 = formatConfigPath([
|
|
13040
13058
|
{ kind: "key", name: key },
|
|
13041
13059
|
...issue.path.map(toSegment)
|
|
13042
13060
|
]);
|
|
13043
|
-
return `${
|
|
13061
|
+
return `${path96}: ${issue.message}`;
|
|
13044
13062
|
}
|
|
13045
13063
|
function toSegment(part) {
|
|
13046
13064
|
return typeof part === "number" ? { kind: "index", index: part } : { kind: "key", name: String(part) };
|
|
@@ -13135,9 +13153,9 @@ function coerceUnion(key, raw, types) {
|
|
|
13135
13153
|
}
|
|
13136
13154
|
|
|
13137
13155
|
// src/shared/valueAtConfigPath.ts
|
|
13138
|
-
function valueAtConfigPath(value,
|
|
13156
|
+
function valueAtConfigPath(value, path96) {
|
|
13139
13157
|
let current = value;
|
|
13140
|
-
for (const key of
|
|
13158
|
+
for (const key of path96) {
|
|
13141
13159
|
if (typeof key === "number") {
|
|
13142
13160
|
if (!Array.isArray(current)) return void 0;
|
|
13143
13161
|
current = current[key];
|
|
@@ -13154,7 +13172,7 @@ function restoreConfigSecrets(value, stored, node) {
|
|
|
13154
13172
|
return mapConfigSecrets(
|
|
13155
13173
|
value,
|
|
13156
13174
|
node,
|
|
13157
|
-
(secret,
|
|
13175
|
+
(secret, path96) => isRedactedSecret(secret) ? valueAtConfigPath(stored, path96) : secret
|
|
13158
13176
|
);
|
|
13159
13177
|
}
|
|
13160
13178
|
|
|
@@ -13203,8 +13221,8 @@ function stepIntoNested(container, key, nextKey) {
|
|
|
13203
13221
|
}
|
|
13204
13222
|
return ensureObject(container, resolved);
|
|
13205
13223
|
}
|
|
13206
|
-
function setNestedValue(obj,
|
|
13207
|
-
const keys =
|
|
13224
|
+
function setNestedValue(obj, path96, value) {
|
|
13225
|
+
const keys = path96.split(".");
|
|
13208
13226
|
const result = { ...obj };
|
|
13209
13227
|
let current = result;
|
|
13210
13228
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
@@ -13231,8 +13249,8 @@ function formatIssue2(issue, key) {
|
|
|
13231
13249
|
return issue.keys.map(
|
|
13232
13250
|
(unrecognized) => `${[...issue.path, unrecognized].join(".")}: Unrecognized key`
|
|
13233
13251
|
);
|
|
13234
|
-
const
|
|
13235
|
-
return [`${
|
|
13252
|
+
const path96 = issue.path.length > 0 ? issue.path.join(".") : key;
|
|
13253
|
+
return [`${path96}: ${issue.message}`];
|
|
13236
13254
|
}
|
|
13237
13255
|
|
|
13238
13256
|
// src/commands/config/applyConfigSet.ts
|
|
@@ -13489,8 +13507,8 @@ function removeAt(container, keys) {
|
|
|
13489
13507
|
}
|
|
13490
13508
|
return removeFromChild(container, key, rest);
|
|
13491
13509
|
}
|
|
13492
|
-
function unsetNestedValue(obj,
|
|
13493
|
-
const { container, removed } = removeAt(obj,
|
|
13510
|
+
function unsetNestedValue(obj, path96) {
|
|
13511
|
+
const { container, removed } = removeAt(obj, path96.split("."));
|
|
13494
13512
|
return { config: container, removed };
|
|
13495
13513
|
}
|
|
13496
13514
|
|
|
@@ -13744,8 +13762,8 @@ import { dirname as dirname23, join as join35 } from "path";
|
|
|
13744
13762
|
import { promisify as promisify10 } from "util";
|
|
13745
13763
|
var execFileAsync9 = promisify10(execFile10);
|
|
13746
13764
|
var TIMEOUT_MS = 15e3;
|
|
13747
|
-
function findOxfmtScript(
|
|
13748
|
-
let dir =
|
|
13765
|
+
function findOxfmtScript(root2) {
|
|
13766
|
+
let dir = root2;
|
|
13749
13767
|
for (; ; ) {
|
|
13750
13768
|
const candidate = join35(dir, "node_modules", "oxfmt", "bin", "oxfmt");
|
|
13751
13769
|
if (existsSync37(candidate)) return candidate;
|
|
@@ -13754,11 +13772,11 @@ function findOxfmtScript(root) {
|
|
|
13754
13772
|
dir = parent;
|
|
13755
13773
|
}
|
|
13756
13774
|
}
|
|
13757
|
-
async function formatWithOxfmt(target,
|
|
13758
|
-
const script = findOxfmtScript(
|
|
13775
|
+
async function formatWithOxfmt(target, root2) {
|
|
13776
|
+
const script = findOxfmtScript(root2);
|
|
13759
13777
|
if (!script) return;
|
|
13760
13778
|
await execFileAsync9(process.execPath, [script, target], {
|
|
13761
|
-
cwd:
|
|
13779
|
+
cwd: root2,
|
|
13762
13780
|
windowsHide: true,
|
|
13763
13781
|
timeout: TIMEOUT_MS
|
|
13764
13782
|
}).catch(() => {
|
|
@@ -14101,13 +14119,13 @@ function renderRestartMenu(items2, selected) {
|
|
|
14101
14119
|
function createMenuState(items2, log2) {
|
|
14102
14120
|
let open = false;
|
|
14103
14121
|
let selected = firstEnabledIndex(items2);
|
|
14104
|
-
const
|
|
14122
|
+
const render2 = () => log2(renderRestartMenu(items2, selected));
|
|
14105
14123
|
return {
|
|
14106
14124
|
isOpen: () => open,
|
|
14107
14125
|
open() {
|
|
14108
14126
|
open = true;
|
|
14109
14127
|
selected = firstEnabledIndex(items2);
|
|
14110
|
-
|
|
14128
|
+
render2();
|
|
14111
14129
|
},
|
|
14112
14130
|
close() {
|
|
14113
14131
|
if (!open) return;
|
|
@@ -14116,14 +14134,14 @@ function createMenuState(items2, log2) {
|
|
|
14116
14134
|
},
|
|
14117
14135
|
move(direction) {
|
|
14118
14136
|
selected = nextIndex(items2, selected, direction);
|
|
14119
|
-
|
|
14137
|
+
render2();
|
|
14120
14138
|
},
|
|
14121
14139
|
selectedItem: () => items2[selected],
|
|
14122
14140
|
jumpTo(index3) {
|
|
14123
14141
|
const item = items2[index3];
|
|
14124
14142
|
if (!item) return false;
|
|
14125
14143
|
selected = index3;
|
|
14126
|
-
|
|
14144
|
+
render2();
|
|
14127
14145
|
return !item.disabled;
|
|
14128
14146
|
}
|
|
14129
14147
|
};
|
|
@@ -14652,9 +14670,9 @@ function originToSshUrl(origin) {
|
|
|
14652
14670
|
const firstSlash = origin.indexOf("/");
|
|
14653
14671
|
if (firstSlash <= 0) return null;
|
|
14654
14672
|
const host = origin.slice(0, firstSlash);
|
|
14655
|
-
const
|
|
14656
|
-
if (!
|
|
14657
|
-
return `git@${host}:${
|
|
14673
|
+
const path96 = origin.slice(firstSlash + 1);
|
|
14674
|
+
if (!path96) return null;
|
|
14675
|
+
return `git@${host}:${path96}.git`;
|
|
14658
14676
|
}
|
|
14659
14677
|
|
|
14660
14678
|
// src/commands/backlog/cloneRepo.ts
|
|
@@ -14791,7 +14809,7 @@ function requestPreviewDecision(request) {
|
|
|
14791
14809
|
return new Promise((resolve25, reject) => {
|
|
14792
14810
|
connectToDaemon().then((socket) => {
|
|
14793
14811
|
let settled = false;
|
|
14794
|
-
const
|
|
14812
|
+
const finish2 = (error, decision) => {
|
|
14795
14813
|
if (settled) return;
|
|
14796
14814
|
settled = true;
|
|
14797
14815
|
socket.destroy();
|
|
@@ -14801,13 +14819,13 @@ function requestPreviewDecision(request) {
|
|
|
14801
14819
|
readSocketLines(socket, (line) => {
|
|
14802
14820
|
const incoming = parsePreviewDecision(line, request.requestId);
|
|
14803
14821
|
if (!incoming) return;
|
|
14804
|
-
if (incoming.kind === "error")
|
|
14805
|
-
else
|
|
14822
|
+
if (incoming.kind === "error") finish2(new Error(incoming.message));
|
|
14823
|
+
else finish2(void 0, incoming.decision);
|
|
14806
14824
|
});
|
|
14807
|
-
socket.on("error", (error) =>
|
|
14825
|
+
socket.on("error", (error) => finish2(error));
|
|
14808
14826
|
socket.on(
|
|
14809
14827
|
"close",
|
|
14810
|
-
() =>
|
|
14828
|
+
() => finish2(new Error("daemon closed before a decision was made"))
|
|
14811
14829
|
);
|
|
14812
14830
|
socket.write(`${JSON.stringify({ type: "pr-preview", ...request })}
|
|
14813
14831
|
`);
|
|
@@ -17387,9 +17405,9 @@ var UNPARSEABLE = { ok: false, error: "unable to parse" };
|
|
|
17387
17405
|
function groupByOperator(tokens) {
|
|
17388
17406
|
const groups = [[]];
|
|
17389
17407
|
for (let i = 0; i < tokens.length; i++) {
|
|
17390
|
-
const
|
|
17391
|
-
if (!
|
|
17392
|
-
i =
|
|
17408
|
+
const step3 = handleToken(tokens, i, groups);
|
|
17409
|
+
if (!step3.ok) return step3;
|
|
17410
|
+
i = step3.nextIndex;
|
|
17393
17411
|
}
|
|
17394
17412
|
return { ok: true, groups };
|
|
17395
17413
|
}
|
|
@@ -17717,13 +17735,13 @@ function findBuiltinDenyRaw(rawCommand) {
|
|
|
17717
17735
|
|
|
17718
17736
|
// src/commands/cliHook/findRestrictedPathDeny.ts
|
|
17719
17737
|
var RESTRICTED_PATHS = [".assist/restricted"];
|
|
17720
|
-
function restrictedPathRegex(
|
|
17721
|
-
const pattern2 =
|
|
17738
|
+
function restrictedPathRegex(path96) {
|
|
17739
|
+
const pattern2 = path96.split("/").map((segment) => segment.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`)).join(String.raw`[/\\]`);
|
|
17722
17740
|
return new RegExp(pattern2);
|
|
17723
17741
|
}
|
|
17724
|
-
var RESTRICTED_PATH_RULES = RESTRICTED_PATHS.map((
|
|
17725
|
-
path:
|
|
17726
|
-
regex: restrictedPathRegex(
|
|
17742
|
+
var RESTRICTED_PATH_RULES = RESTRICTED_PATHS.map((path96) => ({
|
|
17743
|
+
path: path96,
|
|
17744
|
+
regex: restrictedPathRegex(path96)
|
|
17727
17745
|
}));
|
|
17728
17746
|
function findRestrictedPathDenyRaw(rawCommand) {
|
|
17729
17747
|
const rule = RESTRICTED_PATH_RULES.find(
|
|
@@ -17900,9 +17918,9 @@ var __dirname4 = dirname24(__filename3);
|
|
|
17900
17918
|
function packageRoot() {
|
|
17901
17919
|
return __dirname4;
|
|
17902
17920
|
}
|
|
17903
|
-
function readLines(
|
|
17904
|
-
if (!existsSync40(
|
|
17905
|
-
return readFileSync27(
|
|
17921
|
+
function readLines(path96) {
|
|
17922
|
+
if (!existsSync40(path96)) return [];
|
|
17923
|
+
return readFileSync27(path96, "utf8").split("\n").filter((line) => line.trim() !== "");
|
|
17906
17924
|
}
|
|
17907
17925
|
var cachedReads;
|
|
17908
17926
|
var cachedWrites;
|
|
@@ -18427,14 +18445,14 @@ function showProgress(p, label2) {
|
|
|
18427
18445
|
const pct = Math.round(p.done / p.total * 100);
|
|
18428
18446
|
process.stderr.write(`\r\x1B[K[${pct}%] Scanning ${label2}...`);
|
|
18429
18447
|
}
|
|
18430
|
-
async function resolveCommand(cli,
|
|
18431
|
-
showProgress(p,
|
|
18432
|
-
const subHelp = await runHelp([cli, ...
|
|
18448
|
+
async function resolveCommand(cli, path96, description, depth, p) {
|
|
18449
|
+
showProgress(p, path96.join(" "));
|
|
18450
|
+
const subHelp = await runHelp([cli, ...path96]);
|
|
18433
18451
|
if (!subHelp || !hasSubcommands(subHelp)) {
|
|
18434
|
-
return [{ path:
|
|
18452
|
+
return [{ path: path96, description }];
|
|
18435
18453
|
}
|
|
18436
|
-
const children = await discoverAt(cli,
|
|
18437
|
-
return children.length > 0 ? children : [{ path:
|
|
18454
|
+
const children = await discoverAt(cli, path96, depth + 1, p);
|
|
18455
|
+
return children.length > 0 ? children : [{ path: path96, description }];
|
|
18438
18456
|
}
|
|
18439
18457
|
async function discoverAt(cli, parentPath, depth, p) {
|
|
18440
18458
|
if (depth > SAFETY_DEPTH) return [];
|
|
@@ -18537,12 +18555,12 @@ function prefix(kind) {
|
|
|
18537
18555
|
return " ? ";
|
|
18538
18556
|
}
|
|
18539
18557
|
function formatHuman(cli, commands) {
|
|
18540
|
-
const
|
|
18558
|
+
const sorted2 = [...commands].sort(
|
|
18541
18559
|
(a, b) => a.path.join(" ").localeCompare(b.path.join(" "))
|
|
18542
18560
|
);
|
|
18543
18561
|
const lines2 = [`Discovered ${commands.length} commands for "${cli}":
|
|
18544
18562
|
`];
|
|
18545
|
-
for (const cmd of
|
|
18563
|
+
for (const cmd of sorted2) {
|
|
18546
18564
|
const full = `${cli} ${cmd.path.join(" ")}`;
|
|
18547
18565
|
const text18 = cmd.description ? `${full} \u2014 ${cmd.description}` : full;
|
|
18548
18566
|
lines2.push(`${prefix(classifyVerb(cmd.path))}${text18}`);
|
|
@@ -18582,9 +18600,9 @@ function logPath(cli) {
|
|
|
18582
18600
|
return join42(homedir17(), ".assist", `cli-discover-${safeName}.log`);
|
|
18583
18601
|
}
|
|
18584
18602
|
function readCache(cli) {
|
|
18585
|
-
const
|
|
18586
|
-
if (!existsSync42(
|
|
18587
|
-
return readFileSync29(
|
|
18603
|
+
const path96 = logPath(cli);
|
|
18604
|
+
if (!existsSync42(path96)) return void 0;
|
|
18605
|
+
return readFileSync29(path96, "utf8");
|
|
18588
18606
|
}
|
|
18589
18607
|
function writeCache(cli, output) {
|
|
18590
18608
|
const dir = join42(homedir17(), ".assist");
|
|
@@ -18744,9 +18762,9 @@ function sweepRestrictedDir(dir = getRestrictedDir()) {
|
|
|
18744
18762
|
}
|
|
18745
18763
|
const cutoff = Date.now() - STALE_AFTER_MS;
|
|
18746
18764
|
for (const entry of entries) {
|
|
18747
|
-
const
|
|
18765
|
+
const path96 = join44(dir, entry);
|
|
18748
18766
|
try {
|
|
18749
|
-
if (statSync7(
|
|
18767
|
+
if (statSync7(path96).mtimeMs < cutoff) unlinkSync7(path96);
|
|
18750
18768
|
} catch {
|
|
18751
18769
|
continue;
|
|
18752
18770
|
}
|
|
@@ -18756,10 +18774,10 @@ function sweepRestrictedDir(dir = getRestrictedDir()) {
|
|
|
18756
18774
|
// src/commands/codeComment/readPinState.ts
|
|
18757
18775
|
import { existsSync as existsSync43, readFileSync as readFileSync30 } from "fs";
|
|
18758
18776
|
function readPinState(pin) {
|
|
18759
|
-
const
|
|
18760
|
-
if (!existsSync43(
|
|
18777
|
+
const path96 = getPinStatePath(pin);
|
|
18778
|
+
if (!existsSync43(path96)) return void 0;
|
|
18761
18779
|
try {
|
|
18762
|
-
const state = JSON.parse(readFileSync30(
|
|
18780
|
+
const state = JSON.parse(readFileSync30(path96, "utf8"));
|
|
18763
18781
|
if (state.pin !== pin) return void 0;
|
|
18764
18782
|
return state;
|
|
18765
18783
|
} catch {
|
|
@@ -18967,21 +18985,46 @@ function registerCodeComment(parent) {
|
|
|
18967
18985
|
|
|
18968
18986
|
// src/commands/codexHook/parseCodexHookInput.ts
|
|
18969
18987
|
var SUPPORTED_TOOLS = /* @__PURE__ */ new Set(["Bash", "PowerShell"]);
|
|
18988
|
+
function optionalString(value) {
|
|
18989
|
+
return typeof value === "string" ? value : void 0;
|
|
18990
|
+
}
|
|
18970
18991
|
function parseCodexHookInput(raw) {
|
|
18971
18992
|
try {
|
|
18972
18993
|
const data = JSON.parse(raw);
|
|
18973
|
-
const
|
|
18974
|
-
|
|
18994
|
+
const base = {
|
|
18995
|
+
event: data.hook_event_name ?? "PreToolUse",
|
|
18996
|
+
cwd: optionalString(data.cwd)
|
|
18997
|
+
};
|
|
18998
|
+
const transcriptPath2 = optionalString(data.transcript_path);
|
|
18999
|
+
if (transcriptPath2) base.transcriptPath = transcriptPath2;
|
|
18975
19000
|
const command = data.tool_input?.command;
|
|
18976
|
-
if (typeof command !== "string" || !command.trim()) return
|
|
18977
|
-
if (!data.tool_name || !SUPPORTED_TOOLS.has(data.tool_name))
|
|
18978
|
-
|
|
18979
|
-
return { event, cwd, toolName: data.tool_name, command: command.trim() };
|
|
19001
|
+
if (typeof command !== "string" || !command.trim()) return base;
|
|
19002
|
+
if (!data.tool_name || !SUPPORTED_TOOLS.has(data.tool_name)) return base;
|
|
19003
|
+
return { ...base, toolName: data.tool_name, command: command.trim() };
|
|
18980
19004
|
} catch {
|
|
18981
19005
|
return void 0;
|
|
18982
19006
|
}
|
|
18983
19007
|
}
|
|
18984
19008
|
|
|
19009
|
+
// src/commands/codexHook/relayCodexUsage.ts
|
|
19010
|
+
var USAGE_EVENTS = /* @__PURE__ */ new Set(["PostToolUse", "Stop"]);
|
|
19011
|
+
async function relayCodexUsage(event, transcriptPath2) {
|
|
19012
|
+
const sessionId = process.env.ASSIST_SESSION_ID;
|
|
19013
|
+
if (!sessionId || !transcriptPath2 || !USAGE_EVENTS.has(event)) return;
|
|
19014
|
+
try {
|
|
19015
|
+
await sendToDaemonAwaitAck({
|
|
19016
|
+
type: "codex-usage",
|
|
19017
|
+
sessionId,
|
|
19018
|
+
transcriptPath: transcriptPath2,
|
|
19019
|
+
ack: true
|
|
19020
|
+
});
|
|
19021
|
+
} catch (error) {
|
|
19022
|
+
appendDaemonLog(
|
|
19023
|
+
`codex-usage relay failed: id=${sessionId}: ${error instanceof Error ? error.message : String(error)}`
|
|
19024
|
+
);
|
|
19025
|
+
}
|
|
19026
|
+
}
|
|
19027
|
+
|
|
18985
19028
|
// src/commands/codexHook/codexStatusFor.ts
|
|
18986
19029
|
function codexStatusFor(event, autoDecided) {
|
|
18987
19030
|
if (event === "UserPromptSubmit")
|
|
@@ -19041,6 +19084,7 @@ async function codexHook() {
|
|
|
19041
19084
|
const output = outputFor(input, decision);
|
|
19042
19085
|
if (output) console.log(JSON.stringify(output));
|
|
19043
19086
|
await reportCodexStatus(input.event, decision !== void 0);
|
|
19087
|
+
await relayCodexUsage(input.event, input.transcriptPath);
|
|
19044
19088
|
}
|
|
19045
19089
|
|
|
19046
19090
|
// src/commands/registerCodexHook.ts
|
|
@@ -19154,8 +19198,8 @@ function findUnmergedPaths() {
|
|
|
19154
19198
|
}
|
|
19155
19199
|
const found = /* @__PURE__ */ new Set();
|
|
19156
19200
|
for (const line of output.split("\n")) {
|
|
19157
|
-
const
|
|
19158
|
-
if (
|
|
19201
|
+
const path96 = line.split(" ")[1];
|
|
19202
|
+
if (path96) found.add(path96.trim());
|
|
19159
19203
|
}
|
|
19160
19204
|
return [...found];
|
|
19161
19205
|
}
|
|
@@ -19885,10 +19929,10 @@ import path33 from "path";
|
|
|
19885
19929
|
function git3(command) {
|
|
19886
19930
|
return execSync35(command, { encoding: "utf8" });
|
|
19887
19931
|
}
|
|
19888
|
-
function toAbsolute(
|
|
19889
|
-
return path33.resolve(
|
|
19932
|
+
function toAbsolute(root2, repoRelative) {
|
|
19933
|
+
return path33.resolve(root2, repoRelative);
|
|
19890
19934
|
}
|
|
19891
|
-
function collectShrunkFiles(
|
|
19935
|
+
function collectShrunkFiles(root2) {
|
|
19892
19936
|
const shrunk = /* @__PURE__ */ new Set();
|
|
19893
19937
|
const numstat = git3("git diff --numstat HEAD").trim();
|
|
19894
19938
|
if (numstat === "") return shrunk;
|
|
@@ -19898,7 +19942,7 @@ function collectShrunkFiles(root) {
|
|
|
19898
19942
|
const added = Number.parseInt(addedRaw, 10);
|
|
19899
19943
|
const removed = Number.parseInt(removedRaw, 10);
|
|
19900
19944
|
if (Number.isNaN(added) || Number.isNaN(removed)) continue;
|
|
19901
|
-
if (removed > added) shrunk.add(toAbsolute(
|
|
19945
|
+
if (removed > added) shrunk.add(toAbsolute(root2, file));
|
|
19902
19946
|
}
|
|
19903
19947
|
return shrunk;
|
|
19904
19948
|
}
|
|
@@ -19915,9 +19959,9 @@ function hasNewSourceFile() {
|
|
|
19915
19959
|
}
|
|
19916
19960
|
function getMaintainabilityGitState() {
|
|
19917
19961
|
try {
|
|
19918
|
-
const
|
|
19962
|
+
const root2 = git3("git rev-parse --show-toplevel").trim();
|
|
19919
19963
|
return {
|
|
19920
|
-
shrunkFiles: collectShrunkFiles(
|
|
19964
|
+
shrunkFiles: collectShrunkFiles(root2),
|
|
19921
19965
|
newFileCreated: hasNewSourceFile()
|
|
19922
19966
|
};
|
|
19923
19967
|
} catch {
|
|
@@ -20380,11 +20424,11 @@ async function loadPath(source) {
|
|
|
20380
20424
|
}
|
|
20381
20425
|
}
|
|
20382
20426
|
async function criteriaExtension() {
|
|
20383
|
-
const
|
|
20427
|
+
const path96 = await loadPath(criteriaExtensionDir());
|
|
20384
20428
|
console.log(
|
|
20385
20429
|
chalk137.bold("acceptance criteria outliner \u2014 GitHub browser extension")
|
|
20386
20430
|
);
|
|
20387
|
-
console.log(chalk137.dim(`load the unpacked extension from ${
|
|
20431
|
+
console.log(chalk137.dim(`load the unpacked extension from ${path96}`));
|
|
20388
20432
|
}
|
|
20389
20433
|
|
|
20390
20434
|
// src/commands/criteriaExtension/signCriteriaExtension.ts
|
|
@@ -20509,10 +20553,10 @@ async function signCriteriaExtension() {
|
|
|
20509
20553
|
process.exitCode = 1;
|
|
20510
20554
|
return;
|
|
20511
20555
|
}
|
|
20512
|
-
const
|
|
20556
|
+
const path96 = await signedAddonInstallPath(
|
|
20513
20557
|
await copySignedXpi(xpi, ARTIFACTS_DIR)
|
|
20514
20558
|
);
|
|
20515
|
-
console.log(chalk139.dim(`install the signed add-on from ${
|
|
20559
|
+
console.log(chalk139.dim(`install the signed add-on from ${path96}`));
|
|
20516
20560
|
}
|
|
20517
20561
|
|
|
20518
20562
|
// src/commands/registerCriteriaExtension.ts
|
|
@@ -20610,10 +20654,10 @@ function getMigrationApprovalPath(migrationId) {
|
|
|
20610
20654
|
// src/commands/dbMigration/readMigrationPinState.ts
|
|
20611
20655
|
import { existsSync as existsSync48, readFileSync as readFileSync32 } from "fs";
|
|
20612
20656
|
function readMigrationPinState(pin) {
|
|
20613
|
-
const
|
|
20614
|
-
if (!existsSync48(
|
|
20657
|
+
const path96 = getMigrationPinPath(pin);
|
|
20658
|
+
if (!existsSync48(path96)) return void 0;
|
|
20615
20659
|
try {
|
|
20616
|
-
const state = JSON.parse(readFileSync32(
|
|
20660
|
+
const state = JSON.parse(readFileSync32(path96, "utf8"));
|
|
20617
20661
|
if (state.pin !== pin) return void 0;
|
|
20618
20662
|
if (!Number.isInteger(state.migrationId)) return void 0;
|
|
20619
20663
|
return state;
|
|
@@ -22043,10 +22087,10 @@ function decideCommentGuard(input, existingContent) {
|
|
|
22043
22087
|
import { existsSync as existsSync54, unlinkSync as unlinkSync11 } from "fs";
|
|
22044
22088
|
function consumeMigrationApproval(migrationId) {
|
|
22045
22089
|
sweepRestrictedDir();
|
|
22046
|
-
const
|
|
22047
|
-
if (!existsSync54(
|
|
22090
|
+
const path96 = getMigrationApprovalPath(migrationId);
|
|
22091
|
+
if (!existsSync54(path96)) return false;
|
|
22048
22092
|
try {
|
|
22049
|
-
unlinkSync11(
|
|
22093
|
+
unlinkSync11(path96);
|
|
22050
22094
|
return true;
|
|
22051
22095
|
} catch {
|
|
22052
22096
|
return false;
|
|
@@ -22596,7 +22640,7 @@ function orderDepthFirst(issues) {
|
|
|
22596
22640
|
ordered.push(issue);
|
|
22597
22641
|
for (const child of byParent.get(issue.id) ?? []) visit(child);
|
|
22598
22642
|
};
|
|
22599
|
-
for (const
|
|
22643
|
+
for (const root2 of byParent.get(null) ?? []) visit(root2);
|
|
22600
22644
|
return ordered;
|
|
22601
22645
|
}
|
|
22602
22646
|
|
|
@@ -22648,9 +22692,9 @@ function fetchSubtreeIssues(ids) {
|
|
|
22648
22692
|
}
|
|
22649
22693
|
|
|
22650
22694
|
// src/commands/github/issue/fixStructure/walkSubtree.ts
|
|
22651
|
-
function walkSubtree(
|
|
22652
|
-
const placed = [{ ...
|
|
22653
|
-
const seen = /* @__PURE__ */ new Set([
|
|
22695
|
+
function walkSubtree(root2, maxDepth, fetchIssues = fetchSubtreeIssues) {
|
|
22696
|
+
const placed = [{ ...root2, depth: 0, parentId: null }];
|
|
22697
|
+
const seen = /* @__PURE__ */ new Set([root2.id]);
|
|
22654
22698
|
let frontier = placed;
|
|
22655
22699
|
for (let depth = 1; depth <= maxDepth && frontier.length > 0; depth += 1) {
|
|
22656
22700
|
const parentOf2 = /* @__PURE__ */ new Map();
|
|
@@ -22674,9 +22718,9 @@ function walkSubtree(root, maxDepth, fetchIssues = fetchSubtreeIssues) {
|
|
|
22674
22718
|
}
|
|
22675
22719
|
|
|
22676
22720
|
// src/commands/github/issue/fixStructure/planSubtree.ts
|
|
22677
|
-
function planSubtree(
|
|
22721
|
+
function planSubtree(root2, context) {
|
|
22678
22722
|
const depth = context.chain.length - context.rootLevelIndex;
|
|
22679
|
-
return buildFixStructurePlan(walkSubtree(
|
|
22723
|
+
return buildFixStructurePlan(walkSubtree(root2, depth), context);
|
|
22680
22724
|
}
|
|
22681
22725
|
|
|
22682
22726
|
// src/commands/github/issue/fixStructure/applyAndVerifySubtree.ts
|
|
@@ -22862,10 +22906,10 @@ function fixStructure(target, options2) {
|
|
|
22862
22906
|
const resolved = resolveFixStructureTarget(target, options2.repo);
|
|
22863
22907
|
const issueTypes = resolveOrgIssueTypes(resolved.owner);
|
|
22864
22908
|
assertChainTypesExist(chain2, issueTypes);
|
|
22865
|
-
const
|
|
22909
|
+
const root2 = fetchRootIssue(resolved);
|
|
22866
22910
|
const { index: index3, asserted } = resolveRootLevelIndex(
|
|
22867
22911
|
chain2,
|
|
22868
|
-
|
|
22912
|
+
root2.typeName,
|
|
22869
22913
|
options2.level
|
|
22870
22914
|
);
|
|
22871
22915
|
const context = {
|
|
@@ -22875,7 +22919,7 @@ function fixStructure(target, options2) {
|
|
|
22875
22919
|
issueTypes,
|
|
22876
22920
|
stripLabels: options2.stripLabel ?? []
|
|
22877
22921
|
};
|
|
22878
|
-
const plan2 = planSubtree(
|
|
22922
|
+
const plan2 = planSubtree(root2, context);
|
|
22879
22923
|
printFixStructurePlan(plan2, chain2, options2.apply === true);
|
|
22880
22924
|
assertNothingTooDeep(plan2.tooDeep, chain2);
|
|
22881
22925
|
if (options2.apply) applyAndVerifySubtree(resolved, plan2, context);
|
|
@@ -23107,23 +23151,23 @@ function setProjectItemStatus(input) {
|
|
|
23107
23151
|
|
|
23108
23152
|
// src/commands/github/issue/applyCreatedIssueMetadata.ts
|
|
23109
23153
|
function applyCreatedIssueMetadata(createOutput, metadata2) {
|
|
23110
|
-
let
|
|
23154
|
+
let step3 = "identifying the created issue";
|
|
23111
23155
|
try {
|
|
23112
23156
|
const issueId = fetchIssueNodeId(parseCreatedIssueUrl(createOutput));
|
|
23113
23157
|
const { issueType, parent, project } = metadata2;
|
|
23114
23158
|
if (issueType) {
|
|
23115
|
-
|
|
23159
|
+
step3 = `setting its issue type to ${issueType.name}`;
|
|
23116
23160
|
updateIssueType(issueId, issueType.id);
|
|
23117
23161
|
}
|
|
23118
23162
|
if (parent) {
|
|
23119
|
-
|
|
23163
|
+
step3 = `adding it as a sub-issue of ${parent.owner}/${parent.repo}#${parent.number}`;
|
|
23120
23164
|
addSubIssue(parent.id, issueId);
|
|
23121
23165
|
}
|
|
23122
23166
|
if (project) {
|
|
23123
|
-
|
|
23167
|
+
step3 = `adding it to project ${project.number} (${project.title})`;
|
|
23124
23168
|
const itemId2 = addIssueToProject(project.id, issueId);
|
|
23125
23169
|
if (project.status) {
|
|
23126
|
-
|
|
23170
|
+
step3 = `setting its status to ${project.status.optionName}`;
|
|
23127
23171
|
setProjectItemStatus({
|
|
23128
23172
|
projectId: project.id,
|
|
23129
23173
|
itemId: itemId2,
|
|
@@ -23135,7 +23179,7 @@ function applyCreatedIssueMetadata(createOutput, metadata2) {
|
|
|
23135
23179
|
} catch (error) {
|
|
23136
23180
|
const message3 = error instanceof Error ? error.message : String(error);
|
|
23137
23181
|
console.error(
|
|
23138
|
-
`The issue was created at ${createOutput.trim()}, but ${
|
|
23182
|
+
`The issue was created at ${createOutput.trim()}, but ${step3} failed: ${message3}`
|
|
23139
23183
|
);
|
|
23140
23184
|
process.exit(1);
|
|
23141
23185
|
}
|
|
@@ -23187,7 +23231,7 @@ var QUERY5 = `query($owner: String!, $repo: String!, $after: String) {
|
|
|
23187
23231
|
}
|
|
23188
23232
|
}`;
|
|
23189
23233
|
function readRepoLabels(target) {
|
|
23190
|
-
const
|
|
23234
|
+
const names2 = [];
|
|
23191
23235
|
let after;
|
|
23192
23236
|
do {
|
|
23193
23237
|
const page = JSON.parse(
|
|
@@ -23198,22 +23242,22 @@ function readRepoLabels(target) {
|
|
|
23198
23242
|
`No labels could be read for ${target.owner}/${target.repo}`
|
|
23199
23243
|
);
|
|
23200
23244
|
}
|
|
23201
|
-
for (const node of page.nodes ?? []) if (node?.name)
|
|
23245
|
+
for (const node of page.nodes ?? []) if (node?.name) names2.push(node.name);
|
|
23202
23246
|
after = page.pageInfo?.hasNextPage ? page.pageInfo.endCursor ?? void 0 : void 0;
|
|
23203
23247
|
} while (after);
|
|
23204
|
-
return
|
|
23248
|
+
return names2;
|
|
23205
23249
|
}
|
|
23206
|
-
function matchLabel(
|
|
23250
|
+
function matchLabel(names2, wanted) {
|
|
23207
23251
|
const normalised = normaliseTypeName(wanted);
|
|
23208
|
-
return
|
|
23252
|
+
return names2.find((name) => name === wanted) ?? names2.find((name) => name.toLowerCase() === wanted.toLowerCase()) ?? names2.find((name) => normaliseTypeName(name) === normalised);
|
|
23209
23253
|
}
|
|
23210
23254
|
function resolveIssueLabels(target, wanted) {
|
|
23211
|
-
const
|
|
23255
|
+
const names2 = readRepoLabels(target);
|
|
23212
23256
|
return wanted.map((label2) => {
|
|
23213
|
-
const match = matchLabel(
|
|
23257
|
+
const match = matchLabel(names2, label2);
|
|
23214
23258
|
if (!match) {
|
|
23215
23259
|
throw new Error(
|
|
23216
|
-
`${target.owner}/${target.repo} has no ${label2} label. It has ${
|
|
23260
|
+
`${target.owner}/${target.repo} has no ${label2} label. It has ${names2.join(", ")}`
|
|
23217
23261
|
);
|
|
23218
23262
|
}
|
|
23219
23263
|
return match;
|
|
@@ -23347,9 +23391,9 @@ function assertProjectScope() {
|
|
|
23347
23391
|
}
|
|
23348
23392
|
|
|
23349
23393
|
// src/commands/github/issue/projectV2Query.ts
|
|
23350
|
-
function projectV2Query(
|
|
23394
|
+
function projectV2Query(root2) {
|
|
23351
23395
|
return `query($owner: String!, $number: Int!) {
|
|
23352
|
-
${
|
|
23396
|
+
${root2}(login: $owner) {
|
|
23353
23397
|
projectV2(number: $number) {
|
|
23354
23398
|
id
|
|
23355
23399
|
title
|
|
@@ -23362,18 +23406,18 @@ function projectV2Query(root) {
|
|
|
23362
23406
|
}
|
|
23363
23407
|
|
|
23364
23408
|
// src/commands/github/issue/readProject.ts
|
|
23365
|
-
function readProject(owner, number,
|
|
23409
|
+
function readProject(owner, number, root2) {
|
|
23366
23410
|
let raw;
|
|
23367
23411
|
try {
|
|
23368
|
-
raw = runGhGraphqlJson(projectV2Query(
|
|
23412
|
+
raw = runGhGraphqlJson(projectV2Query(root2), { owner, number });
|
|
23369
23413
|
} catch (error) {
|
|
23370
23414
|
const message3 = error instanceof Error ? error.message : String(error);
|
|
23371
|
-
if (
|
|
23415
|
+
if (root2 === "organization" && message3.includes("Could not resolve to an")) {
|
|
23372
23416
|
return void 0;
|
|
23373
23417
|
}
|
|
23374
23418
|
throw error;
|
|
23375
23419
|
}
|
|
23376
|
-
const project = JSON.parse(raw).data?.[
|
|
23420
|
+
const project = JSON.parse(raw).data?.[root2]?.projectV2;
|
|
23377
23421
|
if (!project?.id) return void 0;
|
|
23378
23422
|
const field = project.field;
|
|
23379
23423
|
return {
|
|
@@ -23926,9 +23970,9 @@ function moveItem(item) {
|
|
|
23926
23970
|
(candidate) => candidate.name.toLowerCase() === IN_PROGRESS
|
|
23927
23971
|
);
|
|
23928
23972
|
if (!option) {
|
|
23929
|
-
const
|
|
23973
|
+
const names2 = statusField.options.map((candidate) => candidate.name);
|
|
23930
23974
|
console.log(
|
|
23931
|
-
`The Status field on ${boardName(item)} has no In Progress option, so it was not moved. It offers ${
|
|
23975
|
+
`The Status field on ${boardName(item)} has no In Progress option, so it was not moved. It offers ${names2.join(", ") || "no options"}`
|
|
23932
23976
|
);
|
|
23933
23977
|
return;
|
|
23934
23978
|
}
|
|
@@ -24450,11 +24494,11 @@ function recentDaemonLogLines() {
|
|
|
24450
24494
|
// src/commands/sessions/daemon/worktree/canonicalTreePath.ts
|
|
24451
24495
|
import { realpathSync as realpathSync2 } from "fs";
|
|
24452
24496
|
import { resolve as resolve14 } from "path";
|
|
24453
|
-
function canonicalTreePath(
|
|
24497
|
+
function canonicalTreePath(path96) {
|
|
24454
24498
|
try {
|
|
24455
|
-
return realpathSync2(
|
|
24499
|
+
return realpathSync2(path96);
|
|
24456
24500
|
} catch {
|
|
24457
|
-
return resolve14(
|
|
24501
|
+
return resolve14(path96);
|
|
24458
24502
|
}
|
|
24459
24503
|
}
|
|
24460
24504
|
|
|
@@ -24507,22 +24551,22 @@ function createWorktree(clone, strategy, boundTreeRoots2, preferredPath) {
|
|
|
24507
24551
|
const registered = new Set(listWorktreePaths(clone));
|
|
24508
24552
|
const branches = new Set(listLocalBranches(clone));
|
|
24509
24553
|
const isTaken = (candidate) => registered.has(candidate) || existsSync57(candidate) || boundTreeRoots2.has(candidate) || branches.has(basename18(candidate));
|
|
24510
|
-
const
|
|
24554
|
+
const path96 = preferredPath && !isTaken(preferredPath) ? preferredPath : nextWorktreePath(clone, base, isTaken);
|
|
24511
24555
|
const start3 = worktreeStartPoint(clone, strategy.trunk);
|
|
24512
24556
|
gitSync(clone, [
|
|
24513
24557
|
"worktree",
|
|
24514
24558
|
"add",
|
|
24515
24559
|
start3.track ? "--track" : "--no-track",
|
|
24516
24560
|
"-b",
|
|
24517
|
-
basename18(
|
|
24518
|
-
|
|
24561
|
+
basename18(path96),
|
|
24562
|
+
path96,
|
|
24519
24563
|
start3.ref
|
|
24520
24564
|
]);
|
|
24521
|
-
recordWorktree(
|
|
24565
|
+
recordWorktree(path96, clone, getCurrentOrigin(clone));
|
|
24522
24566
|
daemonLog(
|
|
24523
|
-
start3.track ? `worktree allocated ${
|
|
24567
|
+
start3.track ? `worktree allocated ${path96} (branch ${basename18(path96)} tracking ${start3.ref}) for clone ${clone}` : `worktree allocated ${path96} (branch ${basename18(path96)} off ${start3.ref}, no mainline tracking) for clone ${clone}`
|
|
24524
24568
|
);
|
|
24525
|
-
return
|
|
24569
|
+
return path96;
|
|
24526
24570
|
}
|
|
24527
24571
|
|
|
24528
24572
|
// src/commands/sessions/daemon/worktree/keptInTree.ts
|
|
@@ -24565,16 +24609,16 @@ function* durabilityProbes() {
|
|
|
24565
24609
|
async function checkDurability(cwd) {
|
|
24566
24610
|
if (!existsSync58(cwd)) return treeIsGone;
|
|
24567
24611
|
const probes = durabilityProbes();
|
|
24568
|
-
let
|
|
24569
|
-
while (!
|
|
24570
|
-
return
|
|
24612
|
+
let step3 = probes.next();
|
|
24613
|
+
while (!step3.done) step3 = probes.next(await gitResult(cwd, step3.value));
|
|
24614
|
+
return step3.value;
|
|
24571
24615
|
}
|
|
24572
24616
|
function checkDurabilitySync(cwd) {
|
|
24573
24617
|
if (!existsSync58(cwd)) return treeIsGone;
|
|
24574
24618
|
const probes = durabilityProbes();
|
|
24575
|
-
let
|
|
24576
|
-
while (!
|
|
24577
|
-
return
|
|
24619
|
+
let step3 = probes.next();
|
|
24620
|
+
while (!step3.done) step3 = probes.next(gitSyncResult(cwd, step3.value));
|
|
24621
|
+
return step3.value;
|
|
24578
24622
|
}
|
|
24579
24623
|
|
|
24580
24624
|
// src/commands/sessions/daemon/worktree/reusesClone.ts
|
|
@@ -24663,13 +24707,13 @@ function allocateTree(requestedCwd, boundTreeRoots2, options2 = {}) {
|
|
|
24663
24707
|
if (forcedSpill) daemonLog(forcedSpill);
|
|
24664
24708
|
else if (reusesClone(clone, boundTreeRoots2, reuse))
|
|
24665
24709
|
return { cwd: clone, kind: "primary", created: false, clone };
|
|
24666
|
-
const
|
|
24710
|
+
const path96 = createWorktree(
|
|
24667
24711
|
clone,
|
|
24668
24712
|
{ root: cfg.root, trunk: cfg.trunk },
|
|
24669
24713
|
boundTreeRoots2,
|
|
24670
24714
|
options2.replacesTree
|
|
24671
24715
|
);
|
|
24672
|
-
return { cwd:
|
|
24716
|
+
return { cwd: path96, kind: "worktree", created: true, clone };
|
|
24673
24717
|
}
|
|
24674
24718
|
|
|
24675
24719
|
// src/commands/sessions/daemon/describePersistedSession.ts
|
|
@@ -25015,13 +25059,13 @@ function worktreeHoldingBranch(cwd, branch2) {
|
|
|
25015
25059
|
const listing = gitSyncOrNull(cwd, ["worktree", "list", "--porcelain"]);
|
|
25016
25060
|
if (!listing) return null;
|
|
25017
25061
|
const here = gitSyncOrNull(cwd, ["rev-parse", "--show-toplevel"]);
|
|
25018
|
-
let
|
|
25062
|
+
let path96 = null;
|
|
25019
25063
|
for (const line of listing.split("\n")) {
|
|
25020
25064
|
const trimmed = line.trim();
|
|
25021
25065
|
if (trimmed.startsWith("worktree "))
|
|
25022
|
-
|
|
25066
|
+
path96 = trimmed.slice("worktree ".length).trim();
|
|
25023
25067
|
else if (trimmed === `branch refs/heads/${branch2}`)
|
|
25024
|
-
return
|
|
25068
|
+
return path96 && path96 !== here ? path96 : null;
|
|
25025
25069
|
}
|
|
25026
25070
|
return null;
|
|
25027
25071
|
}
|
|
@@ -25737,12 +25781,12 @@ function extractLayers(layers, cwd, globalConfigPath) {
|
|
|
25737
25781
|
];
|
|
25738
25782
|
}
|
|
25739
25783
|
function unknownExtract(name, layers) {
|
|
25740
|
-
const
|
|
25784
|
+
const names2 = [
|
|
25741
25785
|
...new Set(layers.flatMap((layer) => Object.keys(layer.extracts)))
|
|
25742
25786
|
].sort();
|
|
25743
|
-
if (
|
|
25787
|
+
if (names2.length === 0)
|
|
25744
25788
|
return `No extract named "${name}" is configured. Pick a rectangle with no anchor flags, then save it as "${name}".`;
|
|
25745
|
-
return `No extract named "${name}" is configured. Configured extracts: ${
|
|
25789
|
+
return `No extract named "${name}" is configured. Configured extracts: ${names2.join(", ")}.`;
|
|
25746
25790
|
}
|
|
25747
25791
|
|
|
25748
25792
|
// src/commands/miro/mergeExtractOptions.ts
|
|
@@ -26125,9 +26169,9 @@ function parseRscRows(flight) {
|
|
|
26125
26169
|
}
|
|
26126
26170
|
function makeRscResolver(rows) {
|
|
26127
26171
|
return (ref) => {
|
|
26128
|
-
const [id, ...
|
|
26172
|
+
const [id, ...path96] = ref.slice(1).replace(/^[L@]/, "").split(":");
|
|
26129
26173
|
let v = rows[id];
|
|
26130
|
-
for (const key of
|
|
26174
|
+
for (const key of path96) {
|
|
26131
26175
|
if (v == null || typeof v !== "object") return void 0;
|
|
26132
26176
|
v = v[key];
|
|
26133
26177
|
}
|
|
@@ -26180,8 +26224,8 @@ function profileActionUrl(o) {
|
|
|
26180
26224
|
return void 0;
|
|
26181
26225
|
}
|
|
26182
26226
|
var slugFromProfileUrl = (url) => url.match(/\/in\/([^/?]+)/)?.[1];
|
|
26183
|
-
function visitObjects(
|
|
26184
|
-
const stack = [
|
|
26227
|
+
function visitObjects(root2, fn) {
|
|
26228
|
+
const stack = [root2];
|
|
26185
26229
|
while (stack.length) {
|
|
26186
26230
|
const v = stack.pop();
|
|
26187
26231
|
if (v == null || typeof v !== "object") continue;
|
|
@@ -26457,13 +26501,13 @@ function voyagerProfileMentions(included) {
|
|
|
26457
26501
|
}
|
|
26458
26502
|
|
|
26459
26503
|
// src/commands/netcap/extractVoyagerPosts.ts
|
|
26460
|
-
function includedObjects(
|
|
26461
|
-
const included =
|
|
26504
|
+
function includedObjects(root2) {
|
|
26505
|
+
const included = root2.included;
|
|
26462
26506
|
if (!Array.isArray(included)) return [];
|
|
26463
26507
|
return included.map((item) => asObject(item)).filter((o) => o !== void 0);
|
|
26464
26508
|
}
|
|
26465
|
-
function elementUrns(
|
|
26466
|
-
const data = asObject(asObject(
|
|
26509
|
+
function elementUrns(root2) {
|
|
26510
|
+
const data = asObject(asObject(root2.data)?.data);
|
|
26467
26511
|
if (!data) return [];
|
|
26468
26512
|
for (const value of Object.values(data)) {
|
|
26469
26513
|
const elements = asObject(value)?.["*elements"];
|
|
@@ -26473,13 +26517,13 @@ function elementUrns(root) {
|
|
|
26473
26517
|
return [];
|
|
26474
26518
|
}
|
|
26475
26519
|
function extractVoyagerPosts(body) {
|
|
26476
|
-
let
|
|
26520
|
+
let root2;
|
|
26477
26521
|
try {
|
|
26478
|
-
|
|
26522
|
+
root2 = JSON.parse(body);
|
|
26479
26523
|
} catch {
|
|
26480
26524
|
return [];
|
|
26481
26525
|
}
|
|
26482
|
-
const rootObj = asObject(
|
|
26526
|
+
const rootObj = asObject(root2);
|
|
26483
26527
|
if (!rootObj) return [];
|
|
26484
26528
|
const included = includedObjects(rootObj);
|
|
26485
26529
|
const byUrn = /* @__PURE__ */ new Map();
|
|
@@ -26747,18 +26791,18 @@ function validateLine(line) {
|
|
|
26747
26791
|
process.exit(1);
|
|
26748
26792
|
}
|
|
26749
26793
|
}
|
|
26750
|
-
async function comment2(
|
|
26794
|
+
async function comment2(path96, line, body, options2 = {}) {
|
|
26751
26795
|
const { startLine, skipPreview } = options2;
|
|
26752
26796
|
validateBody(body);
|
|
26753
26797
|
validateLine(line);
|
|
26754
26798
|
if (startLine !== void 0) validateLine(startLine);
|
|
26755
26799
|
const range = startLine !== void 0 ? `${startLine}-${line}` : `${line}`;
|
|
26756
26800
|
if (!skipPreview)
|
|
26757
|
-
await reviewProposedPrComment(`Comment on ${
|
|
26801
|
+
await reviewProposedPrComment(`Comment on ${path96}:${range}`, body, null);
|
|
26758
26802
|
try {
|
|
26759
26803
|
const prId = getCurrentPrNodeId();
|
|
26760
|
-
postReviewComment({ prId, body, path:
|
|
26761
|
-
console.log(`Added review comment on ${
|
|
26804
|
+
postReviewComment({ prId, body, path: path96, line, startLine });
|
|
26805
|
+
console.log(`Added review comment on ${path96}:${range}`);
|
|
26762
26806
|
} catch (error) {
|
|
26763
26807
|
if (isGhNotInstalled(error)) {
|
|
26764
26808
|
console.error("Error: GitHub CLI (gh) is not installed.");
|
|
@@ -27694,7 +27738,7 @@ function requestSession(message3) {
|
|
|
27694
27738
|
return new Promise((resolve25, reject) => {
|
|
27695
27739
|
connectToDaemon().then((socket) => {
|
|
27696
27740
|
let settled = false;
|
|
27697
|
-
const
|
|
27741
|
+
const finish2 = (error, sessionId) => {
|
|
27698
27742
|
if (settled) return;
|
|
27699
27743
|
settled = true;
|
|
27700
27744
|
socket.destroy();
|
|
@@ -27704,13 +27748,13 @@ function requestSession(message3) {
|
|
|
27704
27748
|
readSocketLines(socket, (line) => {
|
|
27705
27749
|
const incoming = parseIncoming(line, message3.type);
|
|
27706
27750
|
if (!incoming) return;
|
|
27707
|
-
if (incoming.kind === "error")
|
|
27708
|
-
else
|
|
27751
|
+
if (incoming.kind === "error") finish2(new Error(incoming.message));
|
|
27752
|
+
else finish2(void 0, incoming.sessionId);
|
|
27709
27753
|
});
|
|
27710
|
-
socket.on("error", (error) =>
|
|
27754
|
+
socket.on("error", (error) => finish2(error));
|
|
27711
27755
|
socket.on(
|
|
27712
27756
|
"close",
|
|
27713
|
-
() =>
|
|
27757
|
+
() => finish2(new Error("daemon closed before the session was created"))
|
|
27714
27758
|
);
|
|
27715
27759
|
socket.write(`${JSON.stringify(message3)}
|
|
27716
27760
|
`);
|
|
@@ -28278,9 +28322,9 @@ function registerPrsComments(prsCommand) {
|
|
|
28278
28322
|
});
|
|
28279
28323
|
prsCommand.command("comment <path> <line> <body>").description(
|
|
28280
28324
|
"Add a line comment to the pending review (body of - reads it from stdin)"
|
|
28281
|
-
).action(async (
|
|
28325
|
+
).action(async (path96, line, body) => {
|
|
28282
28326
|
await comment2(
|
|
28283
|
-
|
|
28327
|
+
path96,
|
|
28284
28328
|
Number.parseInt(line, 10),
|
|
28285
28329
|
await readBodyArgument(body)
|
|
28286
28330
|
);
|
|
@@ -28680,11 +28724,11 @@ async function loadBody(target) {
|
|
|
28680
28724
|
if (target.kind === "file") return readDraftFile(target.path);
|
|
28681
28725
|
return fetchPrBody(target.number, target.repo);
|
|
28682
28726
|
}
|
|
28683
|
-
function readDraftFile(
|
|
28727
|
+
function readDraftFile(path96) {
|
|
28684
28728
|
try {
|
|
28685
|
-
return readFileSync46(
|
|
28729
|
+
return readFileSync46(path96, "utf8");
|
|
28686
28730
|
} catch {
|
|
28687
|
-
console.error(`Error: Could not read \`${
|
|
28731
|
+
console.error(`Error: Could not read \`${path96}\`.`);
|
|
28688
28732
|
console.error(
|
|
28689
28733
|
"Pass a pull request number, a GitHub pull request URL, - for stdin, or a path to a file."
|
|
28690
28734
|
);
|
|
@@ -28964,10 +29008,10 @@ function resolveOpSecret(reference) {
|
|
|
28964
29008
|
}
|
|
28965
29009
|
|
|
28966
29010
|
// src/commands/ravendb/ravenFetch.ts
|
|
28967
|
-
async function ravenFetch(connection,
|
|
29011
|
+
async function ravenFetch(connection, path96) {
|
|
28968
29012
|
const apiKey = resolveOpSecret(connection.apiKeyRef);
|
|
28969
29013
|
let accessToken = await getAccessToken(apiKey);
|
|
28970
|
-
const url = `${connection.url}${
|
|
29014
|
+
const url = `${connection.url}${path96}`;
|
|
28971
29015
|
const headers = {
|
|
28972
29016
|
Authorization: `Bearer ${accessToken}`,
|
|
28973
29017
|
"Content-Type": "application/json"
|
|
@@ -29057,16 +29101,16 @@ import chalk195 from "chalk";
|
|
|
29057
29101
|
// src/commands/ravendb/buildQueryPath.ts
|
|
29058
29102
|
function buildQueryPath(opts) {
|
|
29059
29103
|
const db = encodeURIComponent(opts.db);
|
|
29060
|
-
let
|
|
29104
|
+
let path96;
|
|
29061
29105
|
if (opts.collection) {
|
|
29062
|
-
|
|
29106
|
+
path96 = `/databases/${db}/indexes/dynamic/${encodeURIComponent(opts.collection)}?start=${opts.start}&pageSize=${opts.pageSize}&sort=${encodeURIComponent(opts.sort)}`;
|
|
29063
29107
|
} else {
|
|
29064
|
-
|
|
29108
|
+
path96 = `/databases/${db}/queries?start=${opts.start}&pageSize=${opts.pageSize}`;
|
|
29065
29109
|
}
|
|
29066
29110
|
if (opts.query) {
|
|
29067
|
-
|
|
29111
|
+
path96 += `&query=${encodeURIComponent(opts.query)}`;
|
|
29068
29112
|
}
|
|
29069
|
-
return
|
|
29113
|
+
return path96;
|
|
29070
29114
|
}
|
|
29071
29115
|
|
|
29072
29116
|
// src/commands/ravendb/fetchAllPages.ts
|
|
@@ -29075,7 +29119,7 @@ async function fetchAllPages(connection, opts) {
|
|
|
29075
29119
|
let start3 = 0;
|
|
29076
29120
|
while (true) {
|
|
29077
29121
|
const effectivePageSize = opts.limit !== void 0 ? Math.min(opts.pageSize, opts.limit - allResults.length) : opts.pageSize;
|
|
29078
|
-
const
|
|
29122
|
+
const path96 = buildQueryPath({
|
|
29079
29123
|
db: connection.database,
|
|
29080
29124
|
collection: opts.collection,
|
|
29081
29125
|
start: start3,
|
|
@@ -29083,7 +29127,7 @@ async function fetchAllPages(connection, opts) {
|
|
|
29083
29127
|
sort: opts.sort,
|
|
29084
29128
|
query: opts.query
|
|
29085
29129
|
});
|
|
29086
|
-
const data = await ravenFetch(connection,
|
|
29130
|
+
const data = await ravenFetch(connection, path96);
|
|
29087
29131
|
const results = data.Results ?? [];
|
|
29088
29132
|
const totalResults = data.TotalResults ?? 0;
|
|
29089
29133
|
if (results.length === 0) break;
|
|
@@ -29926,9 +29970,15 @@ function screenshot(processName) {
|
|
|
29926
29970
|
import chalk205 from "chalk";
|
|
29927
29971
|
|
|
29928
29972
|
// src/shared/contextLevel.ts
|
|
29929
|
-
|
|
29930
|
-
|
|
29931
|
-
|
|
29973
|
+
var THRESHOLDS = {
|
|
29974
|
+
claude: { red: 30, yellow: 20 },
|
|
29975
|
+
codex: { red: 75, yellow: 50 },
|
|
29976
|
+
pi: { red: 30, yellow: 20 }
|
|
29977
|
+
};
|
|
29978
|
+
function contextLevel(pct, harness) {
|
|
29979
|
+
const { red, yellow } = THRESHOLDS[resolveHarness(harness)];
|
|
29980
|
+
if (pct >= red) return "red";
|
|
29981
|
+
if (pct >= yellow) return "yellow";
|
|
29932
29982
|
return "dim";
|
|
29933
29983
|
}
|
|
29934
29984
|
|
|
@@ -30432,12 +30482,12 @@ function addImportPreservingSuppressions(sourceFile, structure) {
|
|
|
30432
30482
|
// src/commands/refactor/extract/removeStaleImports.ts
|
|
30433
30483
|
import { SyntaxKind as SyntaxKind3 } from "ts-morph";
|
|
30434
30484
|
function collectReferencedNames(sourceFile) {
|
|
30435
|
-
const
|
|
30485
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
30436
30486
|
for (const id of sourceFile.getDescendantsOfKind(SyntaxKind3.Identifier)) {
|
|
30437
30487
|
if (id.getFirstAncestorByKind(SyntaxKind3.ImportDeclaration)) continue;
|
|
30438
|
-
|
|
30488
|
+
names2.add(id.getText());
|
|
30439
30489
|
}
|
|
30440
|
-
return
|
|
30490
|
+
return names2;
|
|
30441
30491
|
}
|
|
30442
30492
|
function isImportEmpty(importDecl, usedNames) {
|
|
30443
30493
|
if (importDecl.getNamedImports().length > 0) return false;
|
|
@@ -30536,14 +30586,14 @@ function isPrivate(fn) {
|
|
|
30536
30586
|
return !fn.isExported() && !fn.isDefaultExport();
|
|
30537
30587
|
}
|
|
30538
30588
|
function getCalledFunctionNames(fn) {
|
|
30539
|
-
const
|
|
30589
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
30540
30590
|
for (const call of fn.getDescendantsOfKind(SyntaxKind5.CallExpression)) {
|
|
30541
30591
|
const expr = call.getExpression();
|
|
30542
30592
|
if (expr.getKind() === SyntaxKind5.Identifier) {
|
|
30543
|
-
|
|
30593
|
+
names2.add(expr.getText());
|
|
30544
30594
|
}
|
|
30545
30595
|
}
|
|
30546
|
-
return
|
|
30596
|
+
return names2;
|
|
30547
30597
|
}
|
|
30548
30598
|
function collectPrivateFunctions(target, fnMap) {
|
|
30549
30599
|
const collected = /* @__PURE__ */ new Set();
|
|
@@ -30569,11 +30619,11 @@ function collectPrivateFunctions(target, fnMap) {
|
|
|
30569
30619
|
// src/commands/refactor/extract/collectPrivateStatements.ts
|
|
30570
30620
|
import { SyntaxKind as SyntaxKind6 } from "ts-morph";
|
|
30571
30621
|
function getReferencedIdentifiers(fn) {
|
|
30572
|
-
const
|
|
30622
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
30573
30623
|
for (const id of fn.getDescendantsOfKind(SyntaxKind6.Identifier)) {
|
|
30574
|
-
|
|
30624
|
+
names2.add(id.getText());
|
|
30575
30625
|
}
|
|
30576
|
-
return
|
|
30626
|
+
return names2;
|
|
30577
30627
|
}
|
|
30578
30628
|
function collectPrivateStatements(functions, stmtMap) {
|
|
30579
30629
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -30758,31 +30808,31 @@ function matchImport(importDecl, neededNames) {
|
|
|
30758
30808
|
|
|
30759
30809
|
// src/commands/refactor/extract/resolveImports.ts
|
|
30760
30810
|
function getReferencedNames(nodes) {
|
|
30761
|
-
const
|
|
30811
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
30762
30812
|
for (const node of nodes) {
|
|
30763
30813
|
for (const id of node.getDescendantsOfKind(SyntaxKind13.Identifier)) {
|
|
30764
|
-
|
|
30814
|
+
names2.add(id.getText());
|
|
30765
30815
|
}
|
|
30766
30816
|
}
|
|
30767
|
-
return
|
|
30817
|
+
return names2;
|
|
30768
30818
|
}
|
|
30769
30819
|
function getLocallyDeclaredNames(nodes) {
|
|
30770
|
-
const
|
|
30820
|
+
const names2 = /* @__PURE__ */ new Set();
|
|
30771
30821
|
for (const node of nodes) {
|
|
30772
30822
|
if (Node.isFunctionDeclaration(node)) {
|
|
30773
30823
|
const name = node.getName();
|
|
30774
|
-
if (name)
|
|
30824
|
+
if (name) names2.add(name);
|
|
30775
30825
|
}
|
|
30776
30826
|
for (const param of node.getDescendantsOfKind(SyntaxKind13.Parameter)) {
|
|
30777
|
-
|
|
30827
|
+
names2.add(param.getName());
|
|
30778
30828
|
}
|
|
30779
30829
|
for (const varDecl of node.getDescendantsOfKind(
|
|
30780
30830
|
SyntaxKind13.VariableDeclaration
|
|
30781
30831
|
)) {
|
|
30782
|
-
|
|
30832
|
+
names2.add(varDecl.getName());
|
|
30783
30833
|
}
|
|
30784
30834
|
}
|
|
30785
|
-
return
|
|
30835
|
+
return names2;
|
|
30786
30836
|
}
|
|
30787
30837
|
function resolveImports(target, dependencies, sourceFile, statements = []) {
|
|
30788
30838
|
const allFunctions = [target, ...dependencies];
|
|
@@ -31325,16 +31375,21 @@ import ts7 from "typescript";
|
|
|
31325
31375
|
|
|
31326
31376
|
// src/commands/refactor/restructure/buildImportGraph/getImportSpecifiers.ts
|
|
31327
31377
|
import ts6 from "typescript";
|
|
31378
|
+
function moduleSpecifierOf(node) {
|
|
31379
|
+
if (ts6.isImportDeclaration(node) || ts6.isExportDeclaration(node))
|
|
31380
|
+
return node.moduleSpecifier;
|
|
31381
|
+
if (ts6.isCallExpression(node) && node.expression.kind === ts6.SyntaxKind.ImportKeyword && node.arguments.length === 1)
|
|
31382
|
+
return node.arguments[0];
|
|
31383
|
+
if (ts6.isImportTypeNode(node) && ts6.isLiteralTypeNode(node.argument))
|
|
31384
|
+
return node.argument.literal;
|
|
31385
|
+
return void 0;
|
|
31386
|
+
}
|
|
31328
31387
|
function getImportSpecifiers(sourceFile) {
|
|
31329
31388
|
const specifiers = [];
|
|
31330
31389
|
const visit = (node) => {
|
|
31331
|
-
|
|
31332
|
-
|
|
31333
|
-
|
|
31334
|
-
specifiers.push(node.moduleSpecifier.text);
|
|
31335
|
-
} else if (ts6.isCallExpression(node) && node.expression.kind === ts6.SyntaxKind.ImportKeyword && node.arguments.length === 1 && ts6.isStringLiteral(node.arguments[0])) {
|
|
31336
|
-
specifiers.push(node.arguments[0].text);
|
|
31337
|
-
}
|
|
31390
|
+
const specifier = moduleSpecifierOf(node);
|
|
31391
|
+
if (specifier && ts6.isStringLiteral(specifier))
|
|
31392
|
+
specifiers.push(specifier.text);
|
|
31338
31393
|
ts6.forEachChild(node, visit);
|
|
31339
31394
|
};
|
|
31340
31395
|
visit(sourceFile);
|
|
@@ -31517,87 +31572,58 @@ Renamed ${oldName} \u2192 ${newName}`));
|
|
|
31517
31572
|
}
|
|
31518
31573
|
|
|
31519
31574
|
// src/commands/refactor/restructure/index.ts
|
|
31520
|
-
import
|
|
31575
|
+
import fs39 from "fs";
|
|
31576
|
+
import path73 from "path";
|
|
31521
31577
|
import chalk217 from "chalk";
|
|
31522
31578
|
|
|
31523
|
-
// src/commands/refactor/restructure/
|
|
31579
|
+
// src/commands/refactor/restructure/displayPlan.ts
|
|
31580
|
+
import path64 from "path";
|
|
31581
|
+
import chalk215 from "chalk";
|
|
31582
|
+
|
|
31583
|
+
// src/commands/refactor/restructure/computeDepthStats.ts
|
|
31524
31584
|
import path62 from "path";
|
|
31525
|
-
function
|
|
31526
|
-
const
|
|
31527
|
-
|
|
31528
|
-
|
|
31529
|
-
const
|
|
31530
|
-
|
|
31531
|
-
|
|
31532
|
-
|
|
31533
|
-
if (!dirImportedBy.has(targetDir)) dirImportedBy.set(targetDir, existing);
|
|
31534
|
-
existing.add(sourceDir);
|
|
31535
|
-
}
|
|
31536
|
-
const clusters = /* @__PURE__ */ new Map();
|
|
31537
|
-
for (const [dir, importers] of dirImportedBy) {
|
|
31538
|
-
if (importers.size !== 1) continue;
|
|
31539
|
-
const parentDir = [...importers][0];
|
|
31540
|
-
if (isAncestor(dir, parentDir)) continue;
|
|
31541
|
-
if (isAncestor(parentDir, dir)) continue;
|
|
31542
|
-
const cluster = clusters.get(parentDir) ?? [];
|
|
31543
|
-
if (!clusters.has(parentDir)) clusters.set(parentDir, cluster);
|
|
31544
|
-
cluster.push(dir);
|
|
31545
|
-
}
|
|
31546
|
-
for (const [parentDir, children] of clusters) {
|
|
31547
|
-
const filtered = children.filter((child) => !clusters.has(child));
|
|
31548
|
-
if (filtered.length === 0) {
|
|
31549
|
-
clusters.delete(parentDir);
|
|
31550
|
-
} else {
|
|
31551
|
-
clusters.set(parentDir, filtered);
|
|
31552
|
-
}
|
|
31585
|
+
function computeDepthStats(targets, scopeRoot) {
|
|
31586
|
+
const distribution = /* @__PURE__ */ new Map();
|
|
31587
|
+
let max = 0;
|
|
31588
|
+
for (const target of targets) {
|
|
31589
|
+
const dir = path62.relative(scopeRoot, path62.dirname(target));
|
|
31590
|
+
const depth = dir === "" ? 0 : dir.split(path62.sep).length;
|
|
31591
|
+
distribution.set(depth, (distribution.get(depth) ?? 0) + 1);
|
|
31592
|
+
max = Math.max(max, depth);
|
|
31553
31593
|
}
|
|
31554
|
-
return
|
|
31555
|
-
}
|
|
31556
|
-
function isAncestor(ancestor, descendant) {
|
|
31557
|
-
const rel = path62.relative(ancestor, descendant);
|
|
31558
|
-
return !rel.startsWith("..") && rel !== "";
|
|
31594
|
+
return { max, distribution };
|
|
31559
31595
|
}
|
|
31560
31596
|
|
|
31561
|
-
// src/commands/refactor/restructure/
|
|
31597
|
+
// src/commands/refactor/restructure/formatTree.ts
|
|
31562
31598
|
import path63 from "path";
|
|
31563
|
-
function
|
|
31564
|
-
|
|
31565
|
-
|
|
31566
|
-
|
|
31567
|
-
|
|
31568
|
-
|
|
31569
|
-
|
|
31570
|
-
|
|
31571
|
-
|
|
31572
|
-
|
|
31573
|
-
|
|
31574
|
-
|
|
31575
|
-
|
|
31576
|
-
const
|
|
31577
|
-
|
|
31578
|
-
|
|
31579
|
-
|
|
31580
|
-
|
|
31581
|
-
|
|
31582
|
-
|
|
31583
|
-
|
|
31584
|
-
|
|
31585
|
-
|
|
31586
|
-
|
|
31587
|
-
|
|
31588
|
-
if (parentBasename === "index") continue;
|
|
31589
|
-
const root = findRootParent(parent, graph.importedBy, /* @__PURE__ */ new Set([file]));
|
|
31590
|
-
if (!root || root === file) continue;
|
|
31591
|
-
const cluster = clusters.get(root) ?? [];
|
|
31592
|
-
if (!clusters.has(root)) clusters.set(root, cluster);
|
|
31593
|
-
cluster.push(file);
|
|
31594
|
-
}
|
|
31595
|
-
return clusters;
|
|
31599
|
+
function insert(root2, parts) {
|
|
31600
|
+
let node = root2;
|
|
31601
|
+
for (const part of parts) {
|
|
31602
|
+
const child = node.get(part) ?? /* @__PURE__ */ new Map();
|
|
31603
|
+
node.set(part, child);
|
|
31604
|
+
node = child;
|
|
31605
|
+
}
|
|
31606
|
+
}
|
|
31607
|
+
function render(node, indent3, lines2) {
|
|
31608
|
+
const entries = [...node].sort(([a, ca], [b, cb]) => {
|
|
31609
|
+
const dirFirst = Number(cb.size > 0) - Number(ca.size > 0);
|
|
31610
|
+
return dirFirst || a.localeCompare(b);
|
|
31611
|
+
});
|
|
31612
|
+
for (const [name, child] of entries) {
|
|
31613
|
+
lines2.push(`${indent3}${name}${child.size > 0 ? "/" : ""}`);
|
|
31614
|
+
render(child, `${indent3} `, lines2);
|
|
31615
|
+
}
|
|
31616
|
+
}
|
|
31617
|
+
function formatTree(files, scopeRoot) {
|
|
31618
|
+
const root2 = /* @__PURE__ */ new Map();
|
|
31619
|
+
for (const file of files)
|
|
31620
|
+
insert(root2, path63.relative(scopeRoot, file).split(path63.sep));
|
|
31621
|
+
const lines2 = [];
|
|
31622
|
+
render(root2, "", lines2);
|
|
31623
|
+
return lines2;
|
|
31596
31624
|
}
|
|
31597
31625
|
|
|
31598
31626
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
31599
|
-
import path64 from "path";
|
|
31600
|
-
import chalk215 from "chalk";
|
|
31601
31627
|
function relPath(filePath) {
|
|
31602
31628
|
return path64.relative(process.cwd(), filePath);
|
|
31603
31629
|
}
|
|
@@ -31611,38 +31637,39 @@ function displayMoves(plan2) {
|
|
|
31611
31637
|
console.log(chalk215.dim(` ${move2.reason}`));
|
|
31612
31638
|
}
|
|
31613
31639
|
}
|
|
31614
|
-
function
|
|
31615
|
-
|
|
31616
|
-
|
|
31640
|
+
function displayTree(plan2) {
|
|
31641
|
+
console.log(
|
|
31642
|
+
chalk215.bold(`
|
|
31643
|
+
Resulting tree (${relPath(plan2.scopeRoot) || "."}/):`)
|
|
31644
|
+
);
|
|
31645
|
+
for (const line of formatTree(plan2.targets.values(), plan2.scopeRoot))
|
|
31646
|
+
console.log(` ${line}`);
|
|
31647
|
+
}
|
|
31648
|
+
function displayDepthStats(plan2) {
|
|
31649
|
+
const { max, distribution } = computeDepthStats(
|
|
31650
|
+
plan2.targets.values(),
|
|
31651
|
+
plan2.scopeRoot
|
|
31652
|
+
);
|
|
31617
31653
|
console.log(chalk215.bold(`
|
|
31618
|
-
|
|
31619
|
-
for (const
|
|
31620
|
-
console.log(` ${
|
|
31621
|
-
|
|
31622
|
-
|
|
31623
|
-
|
|
31624
|
-
|
|
31625
|
-
|
|
31626
|
-
);
|
|
31627
|
-
}
|
|
31628
|
-
}
|
|
31654
|
+
Depth (max ${max}):`));
|
|
31655
|
+
for (const depth of [...distribution.keys()].sort((a, b) => a - b))
|
|
31656
|
+
console.log(` ${depth}: ${distribution.get(depth)} file(s)`);
|
|
31657
|
+
}
|
|
31658
|
+
function displayErrors(errors) {
|
|
31659
|
+
if (errors.length === 0) return;
|
|
31660
|
+
console.log(chalk215.red("\nErrors:"));
|
|
31661
|
+
for (const error of errors) console.log(chalk215.red(` ${error}`));
|
|
31629
31662
|
}
|
|
31630
31663
|
function displayPlan2(plan2) {
|
|
31631
|
-
if (plan2.warnings.length > 0) {
|
|
31632
|
-
console.log(chalk215.yellow("\nWarnings:"));
|
|
31633
|
-
for (const w of plan2.warnings) console.log(chalk215.yellow(` ${w}`));
|
|
31634
|
-
}
|
|
31635
|
-
if (plan2.newDirectories.length > 0) {
|
|
31636
|
-
console.log(chalk215.bold("\nNew directories:"));
|
|
31637
|
-
for (const dir of plan2.newDirectories)
|
|
31638
|
-
console.log(chalk215.green(` ${dir}/`));
|
|
31639
|
-
}
|
|
31640
31664
|
displayMoves(plan2);
|
|
31641
|
-
|
|
31665
|
+
displayTree(plan2);
|
|
31666
|
+
displayDepthStats(plan2);
|
|
31667
|
+
displayErrors(plan2.errors);
|
|
31668
|
+
const rewrittenFiles = new Set(plan2.rewrites.map((r) => r.file)).size;
|
|
31642
31669
|
console.log(
|
|
31643
31670
|
chalk215.dim(
|
|
31644
31671
|
`
|
|
31645
|
-
Summary: ${plan2.moves.length} file(s) moved, ${plan2.rewrites.length} imports rewritten`
|
|
31672
|
+
Summary: ${plan2.moves.length} file(s) moved, ${plan2.rewrites.length} imports rewritten across ${rewrittenFiles} file(s), ${plan2.errors.length} error(s)`
|
|
31646
31673
|
)
|
|
31647
31674
|
);
|
|
31648
31675
|
}
|
|
@@ -31659,10 +31686,6 @@ function executePlan(plan2) {
|
|
|
31659
31686
|
chalk216.cyan(` Rewrote imports in ${path65.relative(process.cwd(), file)}`)
|
|
31660
31687
|
);
|
|
31661
31688
|
}
|
|
31662
|
-
for (const dir of plan2.newDirectories) {
|
|
31663
|
-
fs38.mkdirSync(dir, { recursive: true });
|
|
31664
|
-
console.log(chalk216.green(` Created ${path65.relative(process.cwd(), dir)}/`));
|
|
31665
|
-
}
|
|
31666
31689
|
for (const move2 of plan2.moves) {
|
|
31667
31690
|
const targetDir = path65.dirname(move2.to);
|
|
31668
31691
|
if (!fs38.existsSync(targetDir)) {
|
|
@@ -31693,148 +31716,299 @@ function removeEmptyDirectories(dirs) {
|
|
|
31693
31716
|
}
|
|
31694
31717
|
}
|
|
31695
31718
|
|
|
31696
|
-
// src/commands/refactor/restructure/
|
|
31697
|
-
import
|
|
31719
|
+
// src/commands/refactor/restructure/planRestructure/index.ts
|
|
31720
|
+
import path72 from "path";
|
|
31698
31721
|
|
|
31699
|
-
// src/commands/refactor/restructure/
|
|
31700
|
-
import
|
|
31701
|
-
function emptyResult() {
|
|
31702
|
-
return { moves: [], directories: [], warnings: [] };
|
|
31703
|
-
}
|
|
31704
|
-
function checkDirConflict(result, label2, dir) {
|
|
31705
|
-
if (!fs39.existsSync(dir)) return false;
|
|
31706
|
-
result.warnings.push(`Skipping ${label2}: directory ${dir} already exists`);
|
|
31707
|
-
return true;
|
|
31708
|
-
}
|
|
31722
|
+
// src/commands/refactor/restructure/planRestructure/collectAnchors.ts
|
|
31723
|
+
import path68 from "path";
|
|
31709
31724
|
|
|
31710
|
-
// src/commands/refactor/restructure/
|
|
31711
|
-
import fs40 from "fs";
|
|
31725
|
+
// src/commands/refactor/restructure/planRestructure/isTestFile.ts
|
|
31712
31726
|
import path66 from "path";
|
|
31713
|
-
|
|
31714
|
-
|
|
31715
|
-
|
|
31716
|
-
results.push(...items2);
|
|
31717
|
-
}
|
|
31718
|
-
function listFilesRecursive(dir) {
|
|
31719
|
-
if (!fs40.existsSync(dir)) return [];
|
|
31720
|
-
const results = [];
|
|
31721
|
-
for (const entry of fs40.readdirSync(dir, { withFileTypes: true })) {
|
|
31722
|
-
collectEntry2(results, dir, entry);
|
|
31723
|
-
}
|
|
31724
|
-
return results;
|
|
31725
|
-
}
|
|
31726
|
-
function addDirectoryFileMoves(moves, childDir, newLocation, reason4) {
|
|
31727
|
-
for (const file of listFilesRecursive(childDir)) {
|
|
31728
|
-
const rel = path66.relative(childDir, file);
|
|
31729
|
-
moves.push({ from: file, to: path66.join(newLocation, rel), reason: reason4 });
|
|
31730
|
-
}
|
|
31727
|
+
var TEST_SUFFIX = /\.test\.tsx?$/;
|
|
31728
|
+
function isTestFile(file) {
|
|
31729
|
+
return TEST_SUFFIX.test(file);
|
|
31731
31730
|
}
|
|
31732
|
-
function
|
|
31733
|
-
return path66.
|
|
31731
|
+
function testStem(file) {
|
|
31732
|
+
return path66.basename(file).replace(TEST_SUFFIX, "");
|
|
31734
31733
|
}
|
|
31735
|
-
|
|
31736
|
-
|
|
31734
|
+
|
|
31735
|
+
// src/commands/refactor/restructure/planRestructure/moduleStem.ts
|
|
31736
|
+
import path67 from "path";
|
|
31737
|
+
function moduleStem(file) {
|
|
31738
|
+
return path67.basename(file).replace(/\.tsx?$/, "");
|
|
31737
31739
|
}
|
|
31738
|
-
|
|
31739
|
-
|
|
31740
|
-
|
|
31741
|
-
|
|
31740
|
+
|
|
31741
|
+
// src/commands/refactor/restructure/planRestructure/collectAnchors.ts
|
|
31742
|
+
function sorted(set) {
|
|
31743
|
+
return [...set ?? []].sort();
|
|
31742
31744
|
}
|
|
31743
|
-
function
|
|
31744
|
-
|
|
31745
|
-
if (checkDirConflict(result, childDir, dest)) return;
|
|
31746
|
-
registerDirectoryMove(result, childDir, dest, parentDir);
|
|
31745
|
+
function names(files) {
|
|
31746
|
+
return files.map((f) => path68.basename(f)).join(", ");
|
|
31747
31747
|
}
|
|
31748
|
-
function
|
|
31749
|
-
|
|
31750
|
-
planChildDirectoryMove(result, parentDir, childDir);
|
|
31748
|
+
function anchorsOf(files, mode) {
|
|
31749
|
+
return files.map((file) => ({ file, mode }));
|
|
31751
31750
|
}
|
|
31752
|
-
function
|
|
31753
|
-
|
|
31754
|
-
for (const [parentDir, childDirs] of clusters)
|
|
31755
|
-
processDirectoryCluster(result, parentDir, childDirs);
|
|
31756
|
-
return result;
|
|
31751
|
+
function root(reason4) {
|
|
31752
|
+
return { root: true, anchors: [], reason: reason4 };
|
|
31757
31753
|
}
|
|
31758
|
-
|
|
31759
|
-
|
|
31760
|
-
|
|
31761
|
-
const
|
|
31762
|
-
|
|
31754
|
+
function anchorTest(file, index3) {
|
|
31755
|
+
const imported = sorted(index3.imports.get(file));
|
|
31756
|
+
if (imported.length === 0) return root("test with no subject in scope");
|
|
31757
|
+
const stem = testStem(file);
|
|
31758
|
+
const subjects = imported.filter(
|
|
31759
|
+
(f) => !isTestFile(f) && moduleStem(f) === stem
|
|
31760
|
+
);
|
|
31761
|
+
const anchors = subjects.length > 0 ? subjects : imported;
|
|
31762
|
+
return {
|
|
31763
|
+
root: false,
|
|
31764
|
+
anchors: anchorsOf(anchors, "sibling"),
|
|
31765
|
+
reason: `test of ${names(anchors)}`
|
|
31766
|
+
};
|
|
31763
31767
|
}
|
|
31764
|
-
function
|
|
31765
|
-
|
|
31766
|
-
|
|
31768
|
+
function anchorModule(file, index3) {
|
|
31769
|
+
if (index3.external.has(file)) return root("imported from outside scope");
|
|
31770
|
+
const importers = sorted(index3.importers.get(file));
|
|
31771
|
+
if (importers.length > 0)
|
|
31772
|
+
return {
|
|
31773
|
+
root: false,
|
|
31774
|
+
anchors: anchorsOf(importers, "child"),
|
|
31775
|
+
reason: importers.length === 1 ? `imported only by ${names(importers)}` : `shared by ${names(importers)}`
|
|
31776
|
+
};
|
|
31777
|
+
const tests = sorted(index3.testImporters.get(file));
|
|
31778
|
+
if (tests.length > 0)
|
|
31779
|
+
return {
|
|
31780
|
+
root: false,
|
|
31781
|
+
anchors: anchorsOf(tests, "sibling"),
|
|
31782
|
+
reason: `used only by tests ${names(tests)}`
|
|
31783
|
+
};
|
|
31784
|
+
return root("no importers in scope");
|
|
31767
31785
|
}
|
|
31768
|
-
function
|
|
31769
|
-
|
|
31786
|
+
function collectAnchors(files, index3) {
|
|
31787
|
+
const anchorings = /* @__PURE__ */ new Map();
|
|
31788
|
+
for (const file of files)
|
|
31789
|
+
anchorings.set(
|
|
31790
|
+
file,
|
|
31791
|
+
isTestFile(file) ? anchorTest(file, index3) : anchorModule(file, index3)
|
|
31792
|
+
);
|
|
31793
|
+
return anchorings;
|
|
31770
31794
|
}
|
|
31771
|
-
|
|
31772
|
-
|
|
31795
|
+
|
|
31796
|
+
// src/commands/refactor/restructure/planRestructure/findCollisions.ts
|
|
31797
|
+
import path69 from "path";
|
|
31798
|
+
function findCollisions(targets, scopeRoot) {
|
|
31799
|
+
const byModule = /* @__PURE__ */ new Map();
|
|
31800
|
+
for (const [file, target] of targets) {
|
|
31801
|
+
const key = path69.join(path69.dirname(target), moduleStem(target));
|
|
31802
|
+
byModule.set(key, [...byModule.get(key) ?? [], file]);
|
|
31803
|
+
}
|
|
31804
|
+
return [...byModule].filter(([, files]) => files.length > 1).map(([key, files]) => {
|
|
31805
|
+
const where = path69.relative(scopeRoot, path69.dirname(key)) || ".";
|
|
31806
|
+
const sources = files.sort().map((f) => path69.relative(scopeRoot, f));
|
|
31807
|
+
return `Basename collision in ${where}/: ${sources.join(", ")}`;
|
|
31808
|
+
}).sort();
|
|
31809
|
+
}
|
|
31810
|
+
|
|
31811
|
+
// src/commands/refactor/restructure/planRestructure/indexEdges.ts
|
|
31812
|
+
function add3(map, key, value) {
|
|
31813
|
+
const set = map.get(key) ?? /* @__PURE__ */ new Set();
|
|
31814
|
+
set.add(value);
|
|
31815
|
+
map.set(key, set);
|
|
31816
|
+
}
|
|
31817
|
+
function indexEdges(scope, edges) {
|
|
31818
|
+
const index3 = {
|
|
31819
|
+
importers: /* @__PURE__ */ new Map(),
|
|
31820
|
+
testImporters: /* @__PURE__ */ new Map(),
|
|
31821
|
+
imports: /* @__PURE__ */ new Map(),
|
|
31822
|
+
external: /* @__PURE__ */ new Set()
|
|
31823
|
+
};
|
|
31824
|
+
for (const { source, target } of edges) {
|
|
31825
|
+
if (!scope.has(target) || source === target) continue;
|
|
31826
|
+
const test = isTestFile(source);
|
|
31827
|
+
if (!scope.has(source)) {
|
|
31828
|
+
if (!test) index3.external.add(target);
|
|
31829
|
+
continue;
|
|
31830
|
+
}
|
|
31831
|
+
add3(index3.imports, source, target);
|
|
31832
|
+
add3(test ? index3.testImporters : index3.importers, target, source);
|
|
31833
|
+
}
|
|
31834
|
+
return index3;
|
|
31773
31835
|
}
|
|
31774
|
-
|
|
31775
|
-
|
|
31776
|
-
|
|
31777
|
-
|
|
31778
|
-
|
|
31836
|
+
|
|
31837
|
+
// src/commands/refactor/restructure/planRestructure/placeComponents.ts
|
|
31838
|
+
import path71 from "path";
|
|
31839
|
+
|
|
31840
|
+
// src/commands/refactor/restructure/planRestructure/findStronglyConnectedComponents.ts
|
|
31841
|
+
function push(state, frames, node) {
|
|
31842
|
+
const i = state.index.size;
|
|
31843
|
+
state.index.set(node, i);
|
|
31844
|
+
state.low.set(node, i);
|
|
31845
|
+
state.stack.push(node);
|
|
31846
|
+
state.onStack.add(node);
|
|
31847
|
+
frames.push({ node, next: 0 });
|
|
31848
|
+
}
|
|
31849
|
+
function popComponent(state, node) {
|
|
31850
|
+
const component = [];
|
|
31851
|
+
let member;
|
|
31852
|
+
do {
|
|
31853
|
+
member = state.stack.pop();
|
|
31854
|
+
state.onStack.delete(member);
|
|
31855
|
+
component.push(member);
|
|
31856
|
+
} while (member !== node);
|
|
31857
|
+
state.components.push(component.sort());
|
|
31858
|
+
}
|
|
31859
|
+
function lowerTo(state, node, value) {
|
|
31860
|
+
state.low.set(node, Math.min(state.low.get(node), value));
|
|
31861
|
+
}
|
|
31862
|
+
function finish(state, frames, node) {
|
|
31863
|
+
frames.pop();
|
|
31864
|
+
const parent = frames.at(-1);
|
|
31865
|
+
if (parent) lowerTo(state, parent.node, state.low.get(node));
|
|
31866
|
+
if (state.low.get(node) === state.index.get(node)) popComponent(state, node);
|
|
31867
|
+
}
|
|
31868
|
+
function step2(state, frames, successors) {
|
|
31869
|
+
const frame = frames.at(-1);
|
|
31870
|
+
const next3 = successors(frame.node)[frame.next++];
|
|
31871
|
+
if (next3 === void 0) finish(state, frames, frame.node);
|
|
31872
|
+
else if (!state.index.has(next3)) push(state, frames, next3);
|
|
31873
|
+
else if (state.onStack.has(next3))
|
|
31874
|
+
lowerTo(state, frame.node, state.index.get(next3));
|
|
31875
|
+
}
|
|
31876
|
+
function findStronglyConnectedComponents(nodes, successors) {
|
|
31877
|
+
const state = {
|
|
31878
|
+
index: /* @__PURE__ */ new Map(),
|
|
31879
|
+
low: /* @__PURE__ */ new Map(),
|
|
31880
|
+
stack: [],
|
|
31881
|
+
onStack: /* @__PURE__ */ new Set(),
|
|
31882
|
+
components: []
|
|
31779
31883
|
};
|
|
31884
|
+
for (const start3 of nodes) {
|
|
31885
|
+
if (state.index.has(start3)) continue;
|
|
31886
|
+
const frames = [];
|
|
31887
|
+
push(state, frames, start3);
|
|
31888
|
+
while (frames.length > 0) step2(state, frames, successors);
|
|
31889
|
+
}
|
|
31890
|
+
return state.components;
|
|
31780
31891
|
}
|
|
31781
|
-
|
|
31782
|
-
|
|
31783
|
-
|
|
31784
|
-
|
|
31892
|
+
|
|
31893
|
+
// src/commands/refactor/restructure/planRestructure/lowestCommonAncestor.ts
|
|
31894
|
+
import path70 from "path";
|
|
31895
|
+
function lowestCommonAncestor(dirs) {
|
|
31896
|
+
const [first, ...rest] = dirs.map((d) => d.split(path70.sep));
|
|
31897
|
+
let common = first;
|
|
31898
|
+
for (const parts of rest) {
|
|
31899
|
+
let i = 0;
|
|
31900
|
+
while (i < common.length && i < parts.length && common[i] === parts[i]) i++;
|
|
31901
|
+
common = common.slice(0, i);
|
|
31902
|
+
}
|
|
31903
|
+
return common.join(path70.sep) || path70.sep;
|
|
31904
|
+
}
|
|
31905
|
+
|
|
31906
|
+
// src/commands/refactor/restructure/planRestructure/placeComponents.ts
|
|
31907
|
+
function anchorFolder(anchor, dirs) {
|
|
31908
|
+
const dir = dirs.get(anchor.file);
|
|
31909
|
+
return anchor.mode === "child" ? path71.join(dir, moduleStem(anchor.file)) : dir;
|
|
31910
|
+
}
|
|
31911
|
+
function externalAnchors(component, anchorings) {
|
|
31912
|
+
const members = new Set(component);
|
|
31913
|
+
return component.flatMap(
|
|
31914
|
+
(file) => anchorings.get(file).anchors.filter(
|
|
31915
|
+
(a) => !members.has(a.file)
|
|
31916
|
+
)
|
|
31917
|
+
);
|
|
31785
31918
|
}
|
|
31786
|
-
function
|
|
31787
|
-
|
|
31788
|
-
|
|
31789
|
-
|
|
31919
|
+
function componentDir(component, anchorings, dirs, scopeRoot) {
|
|
31920
|
+
if (component.some((f) => anchorings.get(f).root))
|
|
31921
|
+
return scopeRoot;
|
|
31922
|
+
const anchors = externalAnchors(component, anchorings);
|
|
31923
|
+
if (anchors.length === 0) return scopeRoot;
|
|
31924
|
+
return lowestCommonAncestor(anchors.map((a) => anchorFolder(a, dirs)));
|
|
31925
|
+
}
|
|
31926
|
+
function componentReason(file, component, base) {
|
|
31927
|
+
if (component.length === 1) return base;
|
|
31928
|
+
const others = component.filter((f) => f !== file).map((f) => path71.basename(f));
|
|
31929
|
+
return `${base}; cycle with ${others.join(", ")}`;
|
|
31930
|
+
}
|
|
31931
|
+
function placeComponents(files, anchorings, scopeRoot) {
|
|
31932
|
+
const successors = (file) => anchorings.get(file).anchors.map((a) => a.file);
|
|
31933
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
31934
|
+
const placements = /* @__PURE__ */ new Map();
|
|
31935
|
+
for (const component of findStronglyConnectedComponents(files, successors)) {
|
|
31936
|
+
const dir = componentDir(component, anchorings, dirs, scopeRoot);
|
|
31937
|
+
for (const file of component) {
|
|
31938
|
+
dirs.set(file, dir);
|
|
31939
|
+
const base = anchorings.get(file).reason;
|
|
31940
|
+
placements.set(file, {
|
|
31941
|
+
dir,
|
|
31942
|
+
reason: componentReason(file, component, base)
|
|
31943
|
+
});
|
|
31944
|
+
}
|
|
31945
|
+
}
|
|
31946
|
+
return placements;
|
|
31790
31947
|
}
|
|
31791
|
-
|
|
31792
|
-
|
|
31793
|
-
|
|
31794
|
-
|
|
31948
|
+
|
|
31949
|
+
// src/commands/refactor/restructure/planRestructure/index.ts
|
|
31950
|
+
function planRestructure(input) {
|
|
31951
|
+
const scopeRoot = path72.resolve(input.scopeRoot);
|
|
31952
|
+
const files = [...new Set(input.files)].sort();
|
|
31953
|
+
const index3 = indexEdges(new Set(files), input.edges);
|
|
31954
|
+
const anchorings = collectAnchors(files, index3);
|
|
31955
|
+
const placements = placeComponents(files, anchorings, scopeRoot);
|
|
31956
|
+
const targets = /* @__PURE__ */ new Map();
|
|
31957
|
+
const moves = [];
|
|
31958
|
+
for (const file of files) {
|
|
31959
|
+
const { dir, reason: reason4 } = placements.get(file);
|
|
31960
|
+
const to = path72.join(dir, path72.basename(file));
|
|
31961
|
+
targets.set(file, to);
|
|
31962
|
+
if (to !== file) moves.push({ from: file, to, reason: reason4 });
|
|
31795
31963
|
}
|
|
31796
|
-
return
|
|
31964
|
+
return { targets, moves, errors: findCollisions(targets, scopeRoot) };
|
|
31797
31965
|
}
|
|
31798
31966
|
|
|
31799
|
-
// src/commands/refactor/restructure/
|
|
31800
|
-
function buildPlan3(
|
|
31801
|
-
const
|
|
31802
|
-
const
|
|
31967
|
+
// src/commands/refactor/restructure/buildPlan.ts
|
|
31968
|
+
function buildPlan3(scopeRoot, files) {
|
|
31969
|
+
const graph = buildImportGraph(new Set(files), findTsConfig(files[0]));
|
|
31970
|
+
const { targets, moves, errors } = planRestructure({
|
|
31971
|
+
scopeRoot,
|
|
31972
|
+
files,
|
|
31973
|
+
edges: graph.edges
|
|
31974
|
+
});
|
|
31803
31975
|
const allProjectFiles = /* @__PURE__ */ new Set([
|
|
31804
31976
|
...graph.importedBy.keys(),
|
|
31805
31977
|
...graph.imports.keys()
|
|
31806
31978
|
]);
|
|
31807
|
-
const fileClusters = clusterFiles(graph);
|
|
31808
|
-
const dirClusters = clusterDirectories(graph);
|
|
31809
|
-
const fileResult = planFileMoves(fileClusters);
|
|
31810
|
-
const dirResult = planDirectoryMoves(dirClusters);
|
|
31811
|
-
const moves = [...fileResult.moves, ...dirResult.moves];
|
|
31812
|
-
const directories = [...fileResult.directories, ...dirResult.directories];
|
|
31813
|
-
const warnings = [...fileResult.warnings, ...dirResult.warnings];
|
|
31814
31979
|
const rewrites = computeRewrites(moves, graph.edges, allProjectFiles);
|
|
31815
|
-
return {
|
|
31980
|
+
return { scopeRoot, targets, moves, rewrites, errors };
|
|
31816
31981
|
}
|
|
31817
|
-
|
|
31818
|
-
|
|
31819
|
-
|
|
31982
|
+
|
|
31983
|
+
// src/commands/refactor/restructure/index.ts
|
|
31984
|
+
async function restructure(root2, options2 = {}) {
|
|
31985
|
+
const scopeRoot = path73.resolve(root2 ?? "src");
|
|
31986
|
+
if (!fs39.existsSync(scopeRoot) || !fs39.statSync(scopeRoot).isDirectory()) {
|
|
31987
|
+
console.log(chalk217.red(`Not a directory: ${root2 ?? "src"}`));
|
|
31988
|
+
process.exit(1);
|
|
31989
|
+
}
|
|
31990
|
+
const files = findSourceFiles(root2 ?? "src").map((f) => path73.resolve(f));
|
|
31820
31991
|
if (files.length === 0) {
|
|
31821
|
-
console.log(chalk217.yellow("No files found
|
|
31992
|
+
console.log(chalk217.yellow("No files found under root"));
|
|
31822
31993
|
return;
|
|
31823
31994
|
}
|
|
31824
|
-
const
|
|
31825
|
-
|
|
31995
|
+
const plan2 = buildPlan3(scopeRoot, files);
|
|
31996
|
+
displayPlan2(plan2);
|
|
31826
31997
|
if (plan2.moves.length === 0) {
|
|
31827
31998
|
console.log(chalk217.green("No restructuring needed"));
|
|
31828
31999
|
return;
|
|
31829
32000
|
}
|
|
31830
|
-
|
|
31831
|
-
if (options2.apply) {
|
|
31832
|
-
console.log(chalk217.bold("\nApplying changes..."));
|
|
31833
|
-
executePlan(plan2);
|
|
31834
|
-
console.log(chalk217.green("\nRestructuring complete"));
|
|
31835
|
-
} else {
|
|
32001
|
+
if (!options2.apply) {
|
|
31836
32002
|
console.log(chalk217.dim("\nDry run. Use --apply to execute."));
|
|
32003
|
+
return;
|
|
32004
|
+
}
|
|
32005
|
+
if (plan2.errors.length > 0) {
|
|
32006
|
+
console.log(chalk217.red("\nResolve the errors above before applying."));
|
|
32007
|
+
process.exit(1);
|
|
31837
32008
|
}
|
|
32009
|
+
console.log(chalk217.bold("\nApplying changes..."));
|
|
32010
|
+
executePlan(plan2);
|
|
32011
|
+
console.log(chalk217.green("\nRestructuring complete"));
|
|
31838
32012
|
}
|
|
31839
32013
|
|
|
31840
32014
|
// src/commands/registerRefactor.ts
|
|
@@ -31853,13 +32027,9 @@ function registerRename(parent) {
|
|
|
31853
32027
|
).option("--apply", "Execute the rename (default: dry-run)").action(renameSymbol);
|
|
31854
32028
|
}
|
|
31855
32029
|
function registerRestructure(parent) {
|
|
31856
|
-
const restructureCommand = parent.command("restructure [
|
|
31857
|
-
"
|
|
31858
|
-
).option("--apply", "Execute the restructuring (default: dry-run)").
|
|
31859
|
-
"--max-depth <number>",
|
|
31860
|
-
"Maximum nesting iterations (default: 3)",
|
|
31861
|
-
Number.parseInt
|
|
31862
|
-
).action(restructure);
|
|
32030
|
+
const restructureCommand = parent.command("restructure [root]").description(
|
|
32031
|
+
"Place every file under root by its import graph: single-importer files nest under their importer, shared files sit at their importers' lowest common folder"
|
|
32032
|
+
).option("--apply", "Execute the restructuring (default: dry-run)").action(restructure);
|
|
31863
32033
|
configHelp(restructureCommand, refactorConfigHelp);
|
|
31864
32034
|
}
|
|
31865
32035
|
function registerRefactor(program2) {
|
|
@@ -32189,10 +32359,10 @@ var emptyDirectoryGroup = () => ({
|
|
|
32189
32359
|
dirs: /* @__PURE__ */ new Map(),
|
|
32190
32360
|
files: []
|
|
32191
32361
|
});
|
|
32192
|
-
function place(
|
|
32362
|
+
function place(root2, file) {
|
|
32193
32363
|
const segments = file.path.split("/").filter(Boolean);
|
|
32194
32364
|
segments.pop();
|
|
32195
|
-
let at2 =
|
|
32365
|
+
let at2 = root2;
|
|
32196
32366
|
for (const segment of segments) {
|
|
32197
32367
|
const next3 = at2.dirs.get(segment) ?? emptyDirectoryGroup();
|
|
32198
32368
|
at2.dirs.set(segment, next3);
|
|
@@ -32201,14 +32371,14 @@ function place(root, file) {
|
|
|
32201
32371
|
at2.files.push(file);
|
|
32202
32372
|
}
|
|
32203
32373
|
function groupFilesByDirectory(files) {
|
|
32204
|
-
const
|
|
32205
|
-
for (const file of files) place(
|
|
32206
|
-
return
|
|
32374
|
+
const root2 = emptyDirectoryGroup();
|
|
32375
|
+
for (const file of files) place(root2, file);
|
|
32376
|
+
return root2;
|
|
32207
32377
|
}
|
|
32208
32378
|
|
|
32209
32379
|
// src/commands/review/highLevel/buildHighLevelTree.ts
|
|
32210
|
-
function basename20(
|
|
32211
|
-
return
|
|
32380
|
+
function basename20(path96) {
|
|
32381
|
+
return path96.slice(path96.lastIndexOf("/") + 1);
|
|
32212
32382
|
}
|
|
32213
32383
|
function sum(nodes, key) {
|
|
32214
32384
|
return nodes.reduce((total, node) => total + node[key], 0);
|
|
@@ -32231,19 +32401,19 @@ function nodesOf(at2, prefix2) {
|
|
|
32231
32401
|
}
|
|
32232
32402
|
function collapsedDirNode(name, at2, prefix2) {
|
|
32233
32403
|
let label2 = name;
|
|
32234
|
-
let
|
|
32404
|
+
let path96 = prefix2 ? `${prefix2}/${name}` : name;
|
|
32235
32405
|
let node = at2;
|
|
32236
32406
|
while (node.files.length === 0 && node.dirs.size === 1) {
|
|
32237
32407
|
const [childName, child] = [...node.dirs][0];
|
|
32238
32408
|
label2 = `${label2}/${childName}`;
|
|
32239
|
-
|
|
32409
|
+
path96 = `${path96}/${childName}`;
|
|
32240
32410
|
node = child;
|
|
32241
32411
|
}
|
|
32242
|
-
const children = nodesOf(node,
|
|
32412
|
+
const children = nodesOf(node, path96);
|
|
32243
32413
|
return {
|
|
32244
32414
|
kind: "dir",
|
|
32245
32415
|
name: label2,
|
|
32246
|
-
path:
|
|
32416
|
+
path: path96,
|
|
32247
32417
|
additions: sum(children, "additions"),
|
|
32248
32418
|
deletions: sum(children, "deletions"),
|
|
32249
32419
|
children
|
|
@@ -32501,8 +32671,8 @@ function toStatus(status3) {
|
|
|
32501
32671
|
if (status3 === "removed") return "removed";
|
|
32502
32672
|
return "modified";
|
|
32503
32673
|
}
|
|
32504
|
-
function diffUrl(repo, prNumber,
|
|
32505
|
-
const anchor = createHash3("sha256").update(
|
|
32674
|
+
function diffUrl(repo, prNumber, path96) {
|
|
32675
|
+
const anchor = createHash3("sha256").update(path96).digest("hex");
|
|
32506
32676
|
return `https://github.com/${repo}/pull/${prNumber}/files#diff-${anchor}`;
|
|
32507
32677
|
}
|
|
32508
32678
|
function fetchHighLevelFiles(prNumber, repo) {
|
|
@@ -32558,10 +32728,10 @@ function highLevelReviewPath(repo, headRef, headSha) {
|
|
|
32558
32728
|
|
|
32559
32729
|
// src/commands/review/highLevel/loadHighLevelReview.ts
|
|
32560
32730
|
function loadHighLevelReview(repo, headRef, headSha) {
|
|
32561
|
-
const
|
|
32562
|
-
if (!existsSync64(
|
|
32731
|
+
const path96 = highLevelReviewPath(repo, headRef, headSha);
|
|
32732
|
+
if (!existsSync64(path96)) return void 0;
|
|
32563
32733
|
try {
|
|
32564
|
-
return JSON.parse(readFileSync49(
|
|
32734
|
+
return JSON.parse(readFileSync49(path96, "utf8"));
|
|
32565
32735
|
} catch {
|
|
32566
32736
|
return void 0;
|
|
32567
32737
|
}
|
|
@@ -32572,8 +32742,8 @@ import { minimatch as minimatch9 } from "minimatch";
|
|
|
32572
32742
|
function selectCriticalDiffs(files, criticalPaths) {
|
|
32573
32743
|
if (criticalPaths.length === 0) return [];
|
|
32574
32744
|
return files.filter((file) => criticalPaths.some((glob) => minimatch9(file.path, glob))).map(
|
|
32575
|
-
({ path:
|
|
32576
|
-
path:
|
|
32745
|
+
({ path: path96, status: status3, additions, deletions, diffUrl: diffUrl2, patch: patch2, truncated }) => ({
|
|
32746
|
+
path: path96,
|
|
32577
32747
|
status: status3,
|
|
32578
32748
|
additions,
|
|
32579
32749
|
deletions,
|
|
@@ -32688,11 +32858,11 @@ function highLevelPreviewPayload(subject) {
|
|
|
32688
32858
|
import { mkdirSync as mkdirSync22, writeFileSync as writeFileSync39 } from "fs";
|
|
32689
32859
|
import { dirname as dirname35 } from "path";
|
|
32690
32860
|
function saveHighLevelReview(record) {
|
|
32691
|
-
const
|
|
32692
|
-
mkdirSync22(dirname35(
|
|
32693
|
-
writeFileSync39(
|
|
32861
|
+
const path96 = highLevelReviewPath(record.repo, record.headRef, record.headSha);
|
|
32862
|
+
mkdirSync22(dirname35(path96), { recursive: true });
|
|
32863
|
+
writeFileSync39(path96, `${JSON.stringify(record, null, 2)}
|
|
32694
32864
|
`);
|
|
32695
|
-
return
|
|
32865
|
+
return path96;
|
|
32696
32866
|
}
|
|
32697
32867
|
|
|
32698
32868
|
// src/commands/review/highLevel/openHighLevelOverlay.ts
|
|
@@ -32711,9 +32881,9 @@ async function openHighLevelOverlay(sessionId, subject) {
|
|
|
32711
32881
|
{ rejectIsOutcome: true }
|
|
32712
32882
|
);
|
|
32713
32883
|
const record = buildHighLevelRecord(subject, decision);
|
|
32714
|
-
const
|
|
32884
|
+
const path96 = saveHighLevelReview(record);
|
|
32715
32885
|
console.log(`Verdict: ${record.verdict}`);
|
|
32716
|
-
console.log(`Saved ${
|
|
32886
|
+
console.log(`Saved ${path96}`);
|
|
32717
32887
|
console.log("Nothing was posted to GitHub.");
|
|
32718
32888
|
return record;
|
|
32719
32889
|
}
|
|
@@ -33728,8 +33898,8 @@ async function handlePostSynthesis(synthesisPath, prInfo, options2) {
|
|
|
33728
33898
|
// src/commands/review/prepareReviewDir.ts
|
|
33729
33899
|
import { existsSync as existsSync65, mkdirSync as mkdirSync23, unlinkSync as unlinkSync18, writeFileSync as writeFileSync40 } from "fs";
|
|
33730
33900
|
function clearReviewFiles(paths) {
|
|
33731
|
-
for (const
|
|
33732
|
-
if (existsSync65(
|
|
33901
|
+
for (const path96 of [paths.claudePath, paths.codexPath, paths.synthesisPath]) {
|
|
33902
|
+
if (existsSync65(path96)) unlinkSync18(path96);
|
|
33733
33903
|
}
|
|
33734
33904
|
}
|
|
33735
33905
|
function prepareReviewDir(paths, requestBody, force) {
|
|
@@ -33774,11 +33944,11 @@ function refreshElapsedText(entry) {
|
|
|
33774
33944
|
entry.text = `${entry.elapsedPrefix ?? "elapsed"}: ${seconds}s`;
|
|
33775
33945
|
}
|
|
33776
33946
|
function renderEntries(entries, frame) {
|
|
33777
|
-
const
|
|
33947
|
+
const sorted2 = [...entries].sort(
|
|
33778
33948
|
(a, b) => Number(Boolean(a.footer)) - Number(Boolean(b.footer))
|
|
33779
33949
|
);
|
|
33780
|
-
for (const entry of
|
|
33781
|
-
return
|
|
33950
|
+
for (const entry of sorted2) refreshElapsedText(entry);
|
|
33951
|
+
return sorted2.map((e) => renderEntry(e, frame)).join("\n");
|
|
33782
33952
|
}
|
|
33783
33953
|
function renderEntry(entry, frame) {
|
|
33784
33954
|
if (entry.state === "succeeded") return `\u2714 ${entry.text}`;
|
|
@@ -34967,7 +35137,7 @@ function registerReview(program2) {
|
|
|
34967
35137
|
|
|
34968
35138
|
// src/commands/rules/addRule.ts
|
|
34969
35139
|
import { existsSync as existsSync70, readFileSync as readFileSync55, writeFileSync as writeFileSync43 } from "fs";
|
|
34970
|
-
import
|
|
35140
|
+
import path78 from "path";
|
|
34971
35141
|
import chalk229 from "chalk";
|
|
34972
35142
|
|
|
34973
35143
|
// src/commands/rules/insertRuleBullet.ts
|
|
@@ -34995,7 +35165,7 @@ import { readFileSync as readFileSync52 } from "fs";
|
|
|
34995
35165
|
|
|
34996
35166
|
// src/commands/rules/findClaudeFiles.ts
|
|
34997
35167
|
import { readdirSync as readdirSync14 } from "fs";
|
|
34998
|
-
import
|
|
35168
|
+
import path74 from "path";
|
|
34999
35169
|
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set(["node_modules", "dist", "build", "coverage"]);
|
|
35000
35170
|
function findClaudeFiles(dir) {
|
|
35001
35171
|
const results = [];
|
|
@@ -35003,9 +35173,9 @@ function findClaudeFiles(dir) {
|
|
|
35003
35173
|
if (entry.isDirectory()) {
|
|
35004
35174
|
if (entry.name.startsWith(".") || SKIP_DIRECTORIES.has(entry.name))
|
|
35005
35175
|
continue;
|
|
35006
|
-
results.push(...findClaudeFiles(
|
|
35176
|
+
results.push(...findClaudeFiles(path74.join(dir, entry.name)));
|
|
35007
35177
|
} else if (entry.name === "CLAUDE.md") {
|
|
35008
|
-
results.push(
|
|
35178
|
+
results.push(path74.join(dir, entry.name));
|
|
35009
35179
|
}
|
|
35010
35180
|
}
|
|
35011
35181
|
return results;
|
|
@@ -35013,8 +35183,8 @@ function findClaudeFiles(dir) {
|
|
|
35013
35183
|
|
|
35014
35184
|
// src/commands/rules/nextRuleCode.ts
|
|
35015
35185
|
var CODE_PREFIX = "R";
|
|
35016
|
-
function nextRuleCode(
|
|
35017
|
-
const numbers = findClaudeFiles(
|
|
35186
|
+
function nextRuleCode(root2) {
|
|
35187
|
+
const numbers = findClaudeFiles(root2).flatMap(
|
|
35018
35188
|
(file) => parseRulesSection(readFileSync52(file, "utf8")).map(
|
|
35019
35189
|
(rule) => Number(/(\d+)\s*$/.exec(rule.code)?.[1] ?? 0)
|
|
35020
35190
|
)
|
|
@@ -35024,34 +35194,34 @@ function nextRuleCode(root) {
|
|
|
35024
35194
|
|
|
35025
35195
|
// src/commands/rules/resolveRuleScope.ts
|
|
35026
35196
|
import { existsSync as existsSync68 } from "fs";
|
|
35027
|
-
import
|
|
35197
|
+
import path75 from "path";
|
|
35028
35198
|
function resolveRuleScope(target) {
|
|
35029
|
-
const resolved =
|
|
35030
|
-
if (
|
|
35199
|
+
const resolved = path75.resolve(target);
|
|
35200
|
+
if (path75.basename(resolved) === "CLAUDE.md") return resolved;
|
|
35031
35201
|
const startDir = scopeDirectory(resolved);
|
|
35032
|
-
const
|
|
35202
|
+
const root2 = findRepoRoot(startDir) ?? startDir;
|
|
35033
35203
|
let current = startDir;
|
|
35034
35204
|
while (true) {
|
|
35035
|
-
const candidate =
|
|
35205
|
+
const candidate = path75.join(current, "CLAUDE.md");
|
|
35036
35206
|
if (existsSync68(candidate)) return candidate;
|
|
35037
|
-
if (current ===
|
|
35038
|
-
current =
|
|
35207
|
+
if (current === root2 || current === path75.dirname(current)) break;
|
|
35208
|
+
current = path75.dirname(current);
|
|
35039
35209
|
}
|
|
35040
|
-
return
|
|
35210
|
+
return path75.join(root2, "CLAUDE.md");
|
|
35041
35211
|
}
|
|
35042
35212
|
|
|
35043
35213
|
// src/commands/rules/updateScopedRulesIndex.ts
|
|
35044
35214
|
import { existsSync as existsSync69, readFileSync as readFileSync54, writeFileSync as writeFileSync42 } from "fs";
|
|
35045
|
-
import
|
|
35215
|
+
import path77 from "path";
|
|
35046
35216
|
|
|
35047
35217
|
// src/commands/rules/scopedRuleDirectories.ts
|
|
35048
35218
|
import { readFileSync as readFileSync53 } from "fs";
|
|
35049
|
-
import
|
|
35050
|
-
function scopedRuleDirectories(
|
|
35051
|
-
return findClaudeFiles(
|
|
35052
|
-
(file) =>
|
|
35219
|
+
import path76 from "path";
|
|
35220
|
+
function scopedRuleDirectories(root2) {
|
|
35221
|
+
return findClaudeFiles(root2).filter(
|
|
35222
|
+
(file) => path76.dirname(file) !== root2 && parseRulesSection(readFileSync53(file, "utf8")).length > 0
|
|
35053
35223
|
).map(
|
|
35054
|
-
(file) => `${
|
|
35224
|
+
(file) => `${path76.relative(root2, path76.dirname(file)).split(path76.sep).join("/")}/`
|
|
35055
35225
|
).sort();
|
|
35056
35226
|
}
|
|
35057
35227
|
|
|
@@ -35088,9 +35258,9 @@ function upsertScopedRulesPointer(content, directories) {
|
|
|
35088
35258
|
}
|
|
35089
35259
|
|
|
35090
35260
|
// src/commands/rules/updateScopedRulesIndex.ts
|
|
35091
|
-
function updateScopedRulesIndex(
|
|
35092
|
-
const directories = scopedRuleDirectories(
|
|
35093
|
-
const rootFile =
|
|
35261
|
+
function updateScopedRulesIndex(root2) {
|
|
35262
|
+
const directories = scopedRuleDirectories(root2);
|
|
35263
|
+
const rootFile = path77.join(root2, "CLAUDE.md");
|
|
35094
35264
|
const before = existsSync69(rootFile) ? readFileSync54(rootFile, "utf8") : "";
|
|
35095
35265
|
const after = upsertScopedRulesPointer(before, directories);
|
|
35096
35266
|
if (after !== before) writeFileSync42(rootFile, after);
|
|
@@ -35109,9 +35279,9 @@ function addRule(text18, options2) {
|
|
|
35109
35279
|
return;
|
|
35110
35280
|
}
|
|
35111
35281
|
const target = resolveRuleScope(options2.scope ?? process.cwd());
|
|
35112
|
-
const targetDir =
|
|
35113
|
-
const
|
|
35114
|
-
const code = nextRuleCode(
|
|
35282
|
+
const targetDir = path78.dirname(target);
|
|
35283
|
+
const root2 = findRepoRoot(targetDir) ?? targetDir;
|
|
35284
|
+
const code = nextRuleCode(root2);
|
|
35115
35285
|
writeFileSync43(
|
|
35116
35286
|
target,
|
|
35117
35287
|
insertRuleBullet(read2(target), {
|
|
@@ -35120,23 +35290,23 @@ function addRule(text18, options2) {
|
|
|
35120
35290
|
text: rule
|
|
35121
35291
|
})
|
|
35122
35292
|
);
|
|
35123
|
-
updateScopedRulesIndex(
|
|
35293
|
+
updateScopedRulesIndex(root2);
|
|
35124
35294
|
console.log(
|
|
35125
|
-
`Added ${chalk229.cyan(code)} to ${
|
|
35295
|
+
`Added ${chalk229.cyan(code)} to ${path78.relative(process.cwd(), target) || target}`
|
|
35126
35296
|
);
|
|
35127
35297
|
}
|
|
35128
35298
|
|
|
35129
35299
|
// src/commands/rules/indexRules.ts
|
|
35130
|
-
import
|
|
35300
|
+
import path79 from "path";
|
|
35131
35301
|
import chalk230 from "chalk";
|
|
35132
35302
|
function indexRules() {
|
|
35133
35303
|
const startDir = scopeDirectory(process.cwd());
|
|
35134
|
-
const
|
|
35135
|
-
const directories = updateScopedRulesIndex(
|
|
35136
|
-
const rootFile =
|
|
35304
|
+
const root2 = findRepoRoot(startDir) ?? startDir;
|
|
35305
|
+
const directories = updateScopedRulesIndex(root2);
|
|
35306
|
+
const rootFile = path79.relative(process.cwd(), path79.join(root2, "CLAUDE.md"));
|
|
35137
35307
|
if (directories.length === 0) {
|
|
35138
35308
|
console.log(
|
|
35139
|
-
chalk230.gray(`No directories carry their own \`## Rules\` under ${
|
|
35309
|
+
chalk230.gray(`No directories carry their own \`## Rules\` under ${root2}`)
|
|
35140
35310
|
);
|
|
35141
35311
|
return;
|
|
35142
35312
|
}
|
|
@@ -35146,13 +35316,13 @@ function indexRules() {
|
|
|
35146
35316
|
}
|
|
35147
35317
|
|
|
35148
35318
|
// src/commands/rules/listRules.ts
|
|
35149
|
-
import
|
|
35319
|
+
import path80 from "path";
|
|
35150
35320
|
import chalk231 from "chalk";
|
|
35151
35321
|
function listRules(target, options2 = {}) {
|
|
35152
|
-
const resolved =
|
|
35322
|
+
const resolved = path80.resolve(target ?? process.cwd());
|
|
35153
35323
|
const rules3 = readScopedRules(resolved);
|
|
35154
35324
|
if (rules3.length === 0) {
|
|
35155
|
-
const label2 =
|
|
35325
|
+
const label2 = path80.relative(process.cwd(), resolved) || ".";
|
|
35156
35326
|
console.log(chalk231.gray(`No rules in scope for ${label2}`));
|
|
35157
35327
|
return;
|
|
35158
35328
|
}
|
|
@@ -35163,7 +35333,7 @@ function listRules(target, options2 = {}) {
|
|
|
35163
35333
|
if (rule.source !== shown) {
|
|
35164
35334
|
shown = rule.source;
|
|
35165
35335
|
console.log(
|
|
35166
|
-
chalk231.dim(base ?
|
|
35336
|
+
chalk231.dim(base ? path80.relative(base, rule.source) : rule.source)
|
|
35167
35337
|
);
|
|
35168
35338
|
}
|
|
35169
35339
|
console.log(
|
|
@@ -35259,8 +35429,8 @@ import chalk237 from "chalk";
|
|
|
35259
35429
|
|
|
35260
35430
|
// src/commands/seq/fetchSeq.ts
|
|
35261
35431
|
import chalk234 from "chalk";
|
|
35262
|
-
async function fetchSeq(conn,
|
|
35263
|
-
const url = `${conn.url}${
|
|
35432
|
+
async function fetchSeq(conn, path96, params) {
|
|
35433
|
+
const url = `${conn.url}${path96}?${params}`;
|
|
35264
35434
|
const response = await fetch(url, {
|
|
35265
35435
|
headers: {
|
|
35266
35436
|
Accept: "application/json",
|
|
@@ -35641,7 +35811,7 @@ async function previewSlackThreadParts({
|
|
|
35641
35811
|
`Approved for ${target}. The ${bodies.length} bodies to post, in thread order, are at:`
|
|
35642
35812
|
);
|
|
35643
35813
|
paths.forEach(
|
|
35644
|
-
(
|
|
35814
|
+
(path96, index3) => console.log(`${index3 + 1}/${paths.length} ${path96}`)
|
|
35645
35815
|
);
|
|
35646
35816
|
console.log(
|
|
35647
35817
|
threadTs ? `Post every part as a reply with thread_ts ${threadTs}.` : `Post 1/${paths.length} to ${channel}, then the rest with the thread_ts it returns.`
|
|
@@ -35982,17 +36152,17 @@ function registerSql(program2) {
|
|
|
35982
36152
|
}
|
|
35983
36153
|
|
|
35984
36154
|
// src/commands/sync.ts
|
|
35985
|
-
import * as
|
|
36155
|
+
import * as fs48 from "fs";
|
|
35986
36156
|
import * as os5 from "os";
|
|
35987
|
-
import * as
|
|
36157
|
+
import * as path91 from "path";
|
|
35988
36158
|
import { fileURLToPath as fileURLToPath9 } from "url";
|
|
35989
36159
|
|
|
35990
36160
|
// src/commands/sync/pruneCommands.ts
|
|
35991
|
-
import * as
|
|
36161
|
+
import * as path82 from "path";
|
|
35992
36162
|
|
|
35993
36163
|
// src/commands/sync/pruneTarget.ts
|
|
35994
|
-
import * as
|
|
35995
|
-
import * as
|
|
36164
|
+
import * as fs40 from "fs";
|
|
36165
|
+
import * as path81 from "path";
|
|
35996
36166
|
function pruneTarget(targetDir, keepNames, shape, options2) {
|
|
35997
36167
|
const result = {
|
|
35998
36168
|
orphans: [],
|
|
@@ -36000,9 +36170,9 @@ function pruneTarget(targetDir, keepNames, shape, options2) {
|
|
|
36000
36170
|
skipped: [],
|
|
36001
36171
|
unmanaged: []
|
|
36002
36172
|
};
|
|
36003
|
-
if (!
|
|
36173
|
+
if (!fs40.existsSync(targetDir)) return result;
|
|
36004
36174
|
const keep = new Set(keepNames);
|
|
36005
|
-
for (const entry of
|
|
36175
|
+
for (const entry of fs40.readdirSync(targetDir, { withFileTypes: true })) {
|
|
36006
36176
|
const name = shape.nameOf(entry);
|
|
36007
36177
|
if (name === void 0) {
|
|
36008
36178
|
result.unmanaged.push(entry.name);
|
|
@@ -36010,14 +36180,14 @@ function pruneTarget(targetDir, keepNames, shape, options2) {
|
|
|
36010
36180
|
}
|
|
36011
36181
|
if (keep.has(name)) continue;
|
|
36012
36182
|
result.orphans.push(entry.name);
|
|
36013
|
-
const entryPath =
|
|
36183
|
+
const entryPath = path81.join(targetDir, entry.name);
|
|
36014
36184
|
const reason4 = shape.blockedBy?.(entryPath);
|
|
36015
36185
|
if (reason4) {
|
|
36016
36186
|
result.skipped.push({ name: entry.name, reason: reason4 });
|
|
36017
36187
|
continue;
|
|
36018
36188
|
}
|
|
36019
36189
|
if (options2.force) {
|
|
36020
|
-
|
|
36190
|
+
fs40.rmSync(entryPath, { recursive: true });
|
|
36021
36191
|
result.removed.push(entry.name);
|
|
36022
36192
|
}
|
|
36023
36193
|
}
|
|
@@ -36030,7 +36200,7 @@ function pruneCommands(targetDir, commandNames, options2) {
|
|
|
36030
36200
|
targetDir,
|
|
36031
36201
|
commandNames,
|
|
36032
36202
|
{
|
|
36033
|
-
nameOf: (entry) => entry.isFile() && entry.name.endsWith(".md") ?
|
|
36203
|
+
nameOf: (entry) => entry.isFile() && entry.name.endsWith(".md") ? path82.basename(entry.name, ".md") : void 0
|
|
36034
36204
|
},
|
|
36035
36205
|
options2
|
|
36036
36206
|
);
|
|
@@ -36064,15 +36234,15 @@ function reportPrune(label2, result, force) {
|
|
|
36064
36234
|
}
|
|
36065
36235
|
|
|
36066
36236
|
// src/commands/sync/reportRetiredAgentsFiles.ts
|
|
36067
|
-
import * as
|
|
36068
|
-
import * as
|
|
36237
|
+
import * as fs41 from "fs";
|
|
36238
|
+
import * as path83 from "path";
|
|
36069
36239
|
var retired = [
|
|
36070
|
-
|
|
36071
|
-
|
|
36072
|
-
|
|
36240
|
+
path83.join(harnesses.claude.homeDir, "CLAUDE.md"),
|
|
36241
|
+
path83.join(harnesses.codex.homeDir, "AGENTS.md"),
|
|
36242
|
+
path83.join(harnesses.pi.homeDir, "AGENTS.md")
|
|
36073
36243
|
];
|
|
36074
36244
|
function reportRetiredAgentsFiles() {
|
|
36075
|
-
const leftovers = retired.filter((file) =>
|
|
36245
|
+
const leftovers = retired.filter((file) => fs41.existsSync(file));
|
|
36076
36246
|
if (leftovers.length === 0) return;
|
|
36077
36247
|
console.log(
|
|
36078
36248
|
"No longer written by sync \u2014 each harness now composes its own advice at session start:"
|
|
@@ -36084,31 +36254,31 @@ function reportRetiredAgentsFiles() {
|
|
|
36084
36254
|
}
|
|
36085
36255
|
|
|
36086
36256
|
// src/commands/sync/syncCodex.ts
|
|
36087
|
-
import * as
|
|
36257
|
+
import * as path86 from "path";
|
|
36088
36258
|
|
|
36089
36259
|
// src/commands/sync/installHarnessCommands.ts
|
|
36090
|
-
import * as
|
|
36091
|
-
import * as
|
|
36260
|
+
import * as fs42 from "fs";
|
|
36261
|
+
import * as path84 from "path";
|
|
36092
36262
|
function installHarnessCommands(claudeDir, harness, transform) {
|
|
36093
|
-
const commandsSource =
|
|
36094
|
-
const files =
|
|
36095
|
-
const
|
|
36263
|
+
const commandsSource = path84.join(claudeDir, "commands");
|
|
36264
|
+
const files = fs42.readdirSync(commandsSource);
|
|
36265
|
+
const names2 = [];
|
|
36096
36266
|
let synced = 0;
|
|
36097
36267
|
for (const file of files) {
|
|
36098
36268
|
if (!file.endsWith(".md")) continue;
|
|
36099
36269
|
const name = file.replace(/\.md$/, "");
|
|
36100
|
-
|
|
36101
|
-
const content =
|
|
36102
|
-
const target =
|
|
36103
|
-
|
|
36104
|
-
|
|
36270
|
+
names2.push(name);
|
|
36271
|
+
const content = fs42.readFileSync(path84.join(commandsSource, file), "utf8");
|
|
36272
|
+
const target = path84.join(harness.homeDir, harness.sync.commandDest(name));
|
|
36273
|
+
fs42.mkdirSync(path84.dirname(target), { recursive: true });
|
|
36274
|
+
fs42.writeFileSync(target, transform(name, content));
|
|
36105
36275
|
synced++;
|
|
36106
36276
|
}
|
|
36107
|
-
return { total: files.length, synced, names };
|
|
36277
|
+
return { total: files.length, synced, names: names2 };
|
|
36108
36278
|
}
|
|
36109
36279
|
|
|
36110
36280
|
// src/commands/sync/pruneSkills.ts
|
|
36111
|
-
import * as
|
|
36281
|
+
import * as fs43 from "fs";
|
|
36112
36282
|
function pruneSkills(targetDir, skillNames, options2) {
|
|
36113
36283
|
return pruneTarget(
|
|
36114
36284
|
targetDir,
|
|
@@ -36121,15 +36291,15 @@ function pruneSkills(targetDir, skillNames, options2) {
|
|
|
36121
36291
|
);
|
|
36122
36292
|
}
|
|
36123
36293
|
function unexpectedContent(skillDir) {
|
|
36124
|
-
const entries =
|
|
36294
|
+
const entries = fs43.readdirSync(skillDir);
|
|
36125
36295
|
const others = entries.filter((entry) => entry !== "SKILL.md");
|
|
36126
36296
|
if (others.length > 0) return `contains ${others.sort().join(", ")}`;
|
|
36127
36297
|
return entries.length === 0 ? "no SKILL.md" : void 0;
|
|
36128
36298
|
}
|
|
36129
36299
|
|
|
36130
36300
|
// src/commands/sync/syncCodexHooks.ts
|
|
36131
|
-
import * as
|
|
36132
|
-
import * as
|
|
36301
|
+
import * as fs44 from "fs";
|
|
36302
|
+
import * as path85 from "path";
|
|
36133
36303
|
var BEGIN = "# >>> assist codex hooks (managed) \u2014 do not edit >>>";
|
|
36134
36304
|
var END = "# <<< assist codex hooks (managed) <<<";
|
|
36135
36305
|
function upsertManagedBlock(existing, body) {
|
|
@@ -36159,11 +36329,11 @@ ${rest}
|
|
|
36159
36329
|
`;
|
|
36160
36330
|
}
|
|
36161
36331
|
function syncCodexHooks(sourcePath) {
|
|
36162
|
-
const body =
|
|
36163
|
-
const configPath =
|
|
36164
|
-
const existing =
|
|
36165
|
-
|
|
36166
|
-
|
|
36332
|
+
const body = fs44.readFileSync(sourcePath, "utf8");
|
|
36333
|
+
const configPath = path85.join(harnesses.codex.homeDir, "config.toml");
|
|
36334
|
+
const existing = fs44.existsSync(configPath) ? fs44.readFileSync(configPath, "utf8") : "";
|
|
36335
|
+
fs44.mkdirSync(path85.dirname(configPath), { recursive: true });
|
|
36336
|
+
fs44.writeFileSync(configPath, upsertManagedBlock(existing, body));
|
|
36167
36337
|
console.log(
|
|
36168
36338
|
"Registered assist codex-hook in ~/.codex/config.toml (SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, PermissionRequest, Stop)"
|
|
36169
36339
|
);
|
|
@@ -36189,62 +36359,62 @@ description: ${quoteYaml(description)}
|
|
|
36189
36359
|
}
|
|
36190
36360
|
function syncCodex(claudeDir, options2) {
|
|
36191
36361
|
if (!isHarnessAvailable("codex")) return;
|
|
36192
|
-
const { total, names } = installHarnessCommands(
|
|
36362
|
+
const { total, names: names2 } = installHarnessCommands(
|
|
36193
36363
|
claudeDir,
|
|
36194
36364
|
harnesses.codex,
|
|
36195
36365
|
commandToSkill
|
|
36196
36366
|
);
|
|
36197
|
-
syncCodexHooks(
|
|
36367
|
+
syncCodexHooks(path86.join(claudeDir, "..", "codex", "config.toml"));
|
|
36198
36368
|
console.log(`Synced ${total} skill(s) to ~/.codex/skills`);
|
|
36199
36369
|
if (!options2?.prune) return;
|
|
36200
36370
|
const force = options2.force ?? false;
|
|
36201
36371
|
reportPrune(
|
|
36202
36372
|
"~/.codex/skills",
|
|
36203
|
-
pruneSkills(
|
|
36373
|
+
pruneSkills(path86.join(harnesses.codex.homeDir, "skills"), names2, { force }),
|
|
36204
36374
|
force
|
|
36205
36375
|
);
|
|
36206
36376
|
}
|
|
36207
36377
|
|
|
36208
36378
|
// src/commands/sync/syncDesign.ts
|
|
36209
|
-
import * as
|
|
36210
|
-
import * as
|
|
36379
|
+
import * as fs45 from "fs";
|
|
36380
|
+
import * as path87 from "path";
|
|
36211
36381
|
function syncDesign(claudeDir, targetBase) {
|
|
36212
|
-
const systemPromptSource =
|
|
36213
|
-
const systemPromptTarget =
|
|
36214
|
-
|
|
36382
|
+
const systemPromptSource = path87.join(claudeDir, "design-system-prompt.md");
|
|
36383
|
+
const systemPromptTarget = path87.join(targetBase, "design-system-prompt.md");
|
|
36384
|
+
fs45.copyFileSync(systemPromptSource, systemPromptTarget);
|
|
36215
36385
|
console.log(
|
|
36216
36386
|
"Copied design-system-prompt.md to ~/.claude/design-system-prompt.md"
|
|
36217
36387
|
);
|
|
36218
|
-
const skillsSource =
|
|
36219
|
-
const skillsTarget =
|
|
36220
|
-
|
|
36221
|
-
const files =
|
|
36388
|
+
const skillsSource = path87.join(claudeDir, "skills");
|
|
36389
|
+
const skillsTarget = path87.join(targetBase, "skills");
|
|
36390
|
+
fs45.mkdirSync(skillsTarget, { recursive: true });
|
|
36391
|
+
const files = fs45.readdirSync(skillsSource);
|
|
36222
36392
|
for (const file of files) {
|
|
36223
|
-
|
|
36224
|
-
|
|
36225
|
-
|
|
36393
|
+
fs45.copyFileSync(
|
|
36394
|
+
path87.join(skillsSource, file),
|
|
36395
|
+
path87.join(skillsTarget, file)
|
|
36226
36396
|
);
|
|
36227
36397
|
}
|
|
36228
36398
|
console.log(`Synced ${files.length} design skill(s) to ~/.claude/skills`);
|
|
36229
36399
|
}
|
|
36230
36400
|
|
|
36231
36401
|
// src/commands/sync/syncPi.ts
|
|
36232
|
-
import * as
|
|
36402
|
+
import * as path89 from "path";
|
|
36233
36403
|
|
|
36234
36404
|
// src/commands/sync/syncPiHooks.ts
|
|
36235
|
-
import * as
|
|
36236
|
-
import * as
|
|
36405
|
+
import * as fs46 from "fs";
|
|
36406
|
+
import * as path88 from "path";
|
|
36237
36407
|
function piExtensionsDir() {
|
|
36238
|
-
return
|
|
36408
|
+
return path88.join(harnesses.pi.homeDir, "extensions");
|
|
36239
36409
|
}
|
|
36240
36410
|
function syncPiHooks(sourceDir) {
|
|
36241
36411
|
const target = piExtensionsDir();
|
|
36242
|
-
|
|
36243
|
-
const files =
|
|
36412
|
+
fs46.mkdirSync(target, { recursive: true });
|
|
36413
|
+
const files = fs46.readdirSync(sourceDir).filter((f) => f.endsWith(".ts"));
|
|
36244
36414
|
for (const file of files) {
|
|
36245
|
-
|
|
36246
|
-
|
|
36247
|
-
|
|
36415
|
+
fs46.copyFileSync(
|
|
36416
|
+
path88.join(sourceDir, file),
|
|
36417
|
+
path88.join(target, `assist-${file}`)
|
|
36248
36418
|
);
|
|
36249
36419
|
}
|
|
36250
36420
|
console.log(
|
|
@@ -36276,33 +36446,33 @@ function commandToPrompt(name, content) {
|
|
|
36276
36446
|
}
|
|
36277
36447
|
function syncPi(claudeDir, options2) {
|
|
36278
36448
|
if (!isHarnessAvailable("pi")) return;
|
|
36279
|
-
const { synced, names } = installHarnessCommands(
|
|
36449
|
+
const { synced, names: names2 } = installHarnessCommands(
|
|
36280
36450
|
claudeDir,
|
|
36281
36451
|
harnesses.pi,
|
|
36282
36452
|
commandToPrompt
|
|
36283
36453
|
);
|
|
36284
|
-
syncPiHooks(
|
|
36454
|
+
syncPiHooks(path89.join(claudeDir, "..", "pi"));
|
|
36285
36455
|
console.log(`Synced ${synced} prompt(s) to ~/.pi/agent/prompts`);
|
|
36286
36456
|
if (!options2?.prune) return;
|
|
36287
36457
|
const force = options2.force ?? false;
|
|
36288
36458
|
reportPrune(
|
|
36289
36459
|
"~/.pi/agent/prompts",
|
|
36290
|
-
pruneCommands(
|
|
36460
|
+
pruneCommands(path89.join(harnesses.pi.homeDir, "prompts"), names2, { force }),
|
|
36291
36461
|
force
|
|
36292
36462
|
);
|
|
36293
36463
|
}
|
|
36294
36464
|
|
|
36295
36465
|
// src/commands/sync/syncSettings.ts
|
|
36296
|
-
import * as
|
|
36297
|
-
import * as
|
|
36466
|
+
import * as fs47 from "fs";
|
|
36467
|
+
import * as path90 from "path";
|
|
36298
36468
|
import chalk244 from "chalk";
|
|
36299
36469
|
async function syncSettings(claudeDir, targetBase, options2) {
|
|
36300
|
-
const source =
|
|
36301
|
-
const target =
|
|
36302
|
-
const sourceContent =
|
|
36470
|
+
const source = path90.join(claudeDir, "settings.json");
|
|
36471
|
+
const target = path90.join(targetBase, "settings.json");
|
|
36472
|
+
const sourceContent = fs47.readFileSync(source, "utf8");
|
|
36303
36473
|
const sourceSettings = JSON.parse(sourceContent);
|
|
36304
|
-
const targetExists =
|
|
36305
|
-
const targetContent = targetExists ?
|
|
36474
|
+
const targetExists = fs47.existsSync(target);
|
|
36475
|
+
const targetContent = targetExists ? fs47.readFileSync(target, "utf8") : "";
|
|
36306
36476
|
const preservedUserSettings = targetExists ? JSON.parse(targetContent) : {};
|
|
36307
36477
|
const mergedContent = JSON.stringify(
|
|
36308
36478
|
{ ...preservedUserSettings, ...sourceSettings },
|
|
@@ -36332,19 +36502,19 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
36332
36502
|
}
|
|
36333
36503
|
}
|
|
36334
36504
|
}
|
|
36335
|
-
|
|
36505
|
+
fs47.writeFileSync(target, mergedContent);
|
|
36336
36506
|
console.log("Copied settings.json to ~/.claude/settings.json");
|
|
36337
36507
|
}
|
|
36338
36508
|
|
|
36339
36509
|
// src/commands/sync.ts
|
|
36340
36510
|
var __filename4 = fileURLToPath9(import.meta.url);
|
|
36341
|
-
var __dirname5 =
|
|
36511
|
+
var __dirname5 = path91.dirname(__filename4);
|
|
36342
36512
|
async function sync(options2) {
|
|
36343
36513
|
const config = loadConfig();
|
|
36344
36514
|
const yes = options2?.yes ?? config.sync.autoConfirm;
|
|
36345
36515
|
const prune = { prune: options2?.prune, force: options2?.force };
|
|
36346
|
-
const claudeDir =
|
|
36347
|
-
const targetBase =
|
|
36516
|
+
const claudeDir = path91.join(__dirname5, "..", "claude");
|
|
36517
|
+
const targetBase = path91.join(os5.homedir(), ".claude");
|
|
36348
36518
|
const commandFiles = syncCommands(claudeDir, targetBase);
|
|
36349
36519
|
syncDesign(claudeDir, targetBase);
|
|
36350
36520
|
await syncSettings(claudeDir, targetBase, { yes });
|
|
@@ -36352,21 +36522,21 @@ async function sync(options2) {
|
|
|
36352
36522
|
syncPi(claudeDir, prune);
|
|
36353
36523
|
reportRetiredAgentsFiles();
|
|
36354
36524
|
if (!options2?.prune) return;
|
|
36355
|
-
const commandNames = commandFiles.filter((file) => file.endsWith(".md")).map((file) =>
|
|
36525
|
+
const commandNames = commandFiles.filter((file) => file.endsWith(".md")).map((file) => path91.basename(file, ".md"));
|
|
36356
36526
|
const force = options2.force ?? false;
|
|
36357
36527
|
reportPrune(
|
|
36358
36528
|
"~/.claude/commands",
|
|
36359
|
-
pruneCommands(
|
|
36529
|
+
pruneCommands(path91.join(targetBase, "commands"), commandNames, { force }),
|
|
36360
36530
|
force
|
|
36361
36531
|
);
|
|
36362
36532
|
}
|
|
36363
36533
|
function syncCommands(claudeDir, targetBase) {
|
|
36364
|
-
const sourceDir =
|
|
36365
|
-
const targetDir =
|
|
36366
|
-
|
|
36367
|
-
const files =
|
|
36534
|
+
const sourceDir = path91.join(claudeDir, "commands");
|
|
36535
|
+
const targetDir = path91.join(targetBase, "commands");
|
|
36536
|
+
fs48.mkdirSync(targetDir, { recursive: true });
|
|
36537
|
+
const files = fs48.readdirSync(sourceDir);
|
|
36368
36538
|
for (const file of files) {
|
|
36369
|
-
|
|
36539
|
+
fs48.copyFileSync(path91.join(sourceDir, file), path91.join(targetDir, file));
|
|
36370
36540
|
console.log(`Copied ${file} to ${targetDir}`);
|
|
36371
36541
|
}
|
|
36372
36542
|
console.log(`Synced ${files.length} command(s) to ~/.claude/commands`);
|
|
@@ -36514,8 +36684,8 @@ function mergeOverlappingCues(cues) {
|
|
|
36514
36684
|
}
|
|
36515
36685
|
function deduplicateCues(cues) {
|
|
36516
36686
|
if (cues.length === 0) return [];
|
|
36517
|
-
const
|
|
36518
|
-
const withoutSubstrings = removeSubstringDuplicates(
|
|
36687
|
+
const sorted2 = [...cues].sort((a, b) => a.startMs - b.startMs);
|
|
36688
|
+
const withoutSubstrings = removeSubstringDuplicates(sorted2);
|
|
36519
36689
|
const merged = mergeOverlappingCues(withoutSubstrings);
|
|
36520
36690
|
return merged.map((cue) => ({
|
|
36521
36691
|
...cue,
|
|
@@ -37432,8 +37602,8 @@ function changedPaths(from, cwd) {
|
|
|
37432
37602
|
import { join as join98 } from "path";
|
|
37433
37603
|
function readBuiltVersion(cwd) {
|
|
37434
37604
|
try {
|
|
37435
|
-
const
|
|
37436
|
-
return readPackageJson(join98(
|
|
37605
|
+
const root2 = runGit3(["rev-parse", "--show-toplevel"], cwd);
|
|
37606
|
+
return readPackageJson(join98(root2, "package.json")).version ?? "unknown";
|
|
37437
37607
|
} catch {
|
|
37438
37608
|
return "unknown";
|
|
37439
37609
|
}
|
|
@@ -37490,11 +37660,11 @@ var webUiPrefix = "src/commands/sessions/web/ui/";
|
|
|
37490
37660
|
var sessionsPrefix = "src/commands/sessions/";
|
|
37491
37661
|
var rules = [
|
|
37492
37662
|
{
|
|
37493
|
-
matches: (
|
|
37663
|
+
matches: (path96) => path96.startsWith(webUiPrefix),
|
|
37494
37664
|
advice: "restart the web server, then hard-reload the browser tab"
|
|
37495
37665
|
},
|
|
37496
37666
|
{
|
|
37497
|
-
matches: (
|
|
37667
|
+
matches: (path96) => path96.startsWith(sessionsPrefix) && !path96.startsWith(webUiPrefix),
|
|
37498
37668
|
advice: "restart the daemon"
|
|
37499
37669
|
}
|
|
37500
37670
|
];
|
|
@@ -37505,27 +37675,27 @@ function restartAdvice(paths) {
|
|
|
37505
37675
|
// src/commands/watch/syncAdvice.ts
|
|
37506
37676
|
var rules2 = [
|
|
37507
37677
|
{
|
|
37508
|
-
matches: (
|
|
37678
|
+
matches: (path96) => path96.startsWith("claude/commands/"),
|
|
37509
37679
|
reason: "claude/commands changed"
|
|
37510
37680
|
},
|
|
37511
37681
|
{
|
|
37512
|
-
matches: (
|
|
37682
|
+
matches: (path96) => path96.startsWith("claude/skills/"),
|
|
37513
37683
|
reason: "claude/skills changed"
|
|
37514
37684
|
},
|
|
37515
37685
|
{
|
|
37516
|
-
matches: (
|
|
37686
|
+
matches: (path96) => path96 === "claude/settings.json",
|
|
37517
37687
|
reason: "claude/settings.json changed"
|
|
37518
37688
|
},
|
|
37519
37689
|
{
|
|
37520
|
-
matches: (
|
|
37690
|
+
matches: (path96) => path96 === "claude/design-system-prompt.md",
|
|
37521
37691
|
reason: "claude/design-system-prompt.md changed"
|
|
37522
37692
|
},
|
|
37523
37693
|
{
|
|
37524
|
-
matches: (
|
|
37694
|
+
matches: (path96) => path96.startsWith("codex/"),
|
|
37525
37695
|
reason: "codex sources changed"
|
|
37526
37696
|
},
|
|
37527
37697
|
{
|
|
37528
|
-
matches: (
|
|
37698
|
+
matches: (path96) => path96.startsWith("pi/"),
|
|
37529
37699
|
reason: "pi sources changed"
|
|
37530
37700
|
}
|
|
37531
37701
|
];
|
|
@@ -37671,11 +37841,11 @@ function stashDirtyTree(cwd) {
|
|
|
37671
37841
|
return { ok: false, reason: gitFailureReason(error) };
|
|
37672
37842
|
}
|
|
37673
37843
|
if (!dirty) return { ok: true, stashed: false };
|
|
37674
|
-
const
|
|
37844
|
+
const push2 = attemptGit(
|
|
37675
37845
|
["stash", "push", "--include-untracked", "--message", STASH_MESSAGE],
|
|
37676
37846
|
cwd
|
|
37677
37847
|
);
|
|
37678
|
-
return
|
|
37848
|
+
return push2.ok ? { ok: true, stashed: true } : push2;
|
|
37679
37849
|
}
|
|
37680
37850
|
function mergeBehindBranch(cwd) {
|
|
37681
37851
|
const stash = stashDirtyTree(cwd);
|
|
@@ -37757,8 +37927,8 @@ function resolveParams(params, cliArgs) {
|
|
|
37757
37927
|
}
|
|
37758
37928
|
if (missing.length > 0) {
|
|
37759
37929
|
const s = missing.length > 1 ? "s" : "";
|
|
37760
|
-
const
|
|
37761
|
-
console.error(`Missing required param${s}: ${
|
|
37930
|
+
const names2 = missing.map((n) => `"${n}"`).join(", ");
|
|
37931
|
+
console.error(`Missing required param${s}: ${names2}`);
|
|
37762
37932
|
process.exit(1);
|
|
37763
37933
|
}
|
|
37764
37934
|
resolved.push(...cliArgs.slice(params.length));
|
|
@@ -37953,7 +38123,7 @@ function pollForMovement(options2) {
|
|
|
37953
38123
|
const { upstream, intervalMs, timeoutMs, timeout, cwd } = options2;
|
|
37954
38124
|
return new Promise((resolve25) => {
|
|
37955
38125
|
let settled = false;
|
|
37956
|
-
const
|
|
38126
|
+
const finish2 = (outcome) => {
|
|
37957
38127
|
if (settled) return;
|
|
37958
38128
|
settled = true;
|
|
37959
38129
|
clearInterval(ticker);
|
|
@@ -37961,14 +38131,14 @@ function pollForMovement(options2) {
|
|
|
37961
38131
|
process.off("SIGINT", onInterrupt);
|
|
37962
38132
|
resolve25(outcome);
|
|
37963
38133
|
};
|
|
37964
|
-
const onInterrupt = () =>
|
|
38134
|
+
const onInterrupt = () => finish2({ kind: "interrupted" });
|
|
37965
38135
|
const ticker = setInterval(() => {
|
|
37966
38136
|
fetchQuietly(cwd, intervalMs);
|
|
37967
38137
|
const found = readMovement(cwd);
|
|
37968
|
-
if (found)
|
|
38138
|
+
if (found) finish2({ kind: "moved", upstream, ...found });
|
|
37969
38139
|
}, intervalMs);
|
|
37970
38140
|
const deadline = timeoutMs === void 0 ? void 0 : setTimeout(
|
|
37971
|
-
() =>
|
|
38141
|
+
() => finish2({ kind: "timeout", upstream, timeout }),
|
|
37972
38142
|
timeoutMs
|
|
37973
38143
|
);
|
|
37974
38144
|
process.on("SIGINT", onInterrupt);
|
|
@@ -38233,9 +38403,9 @@ function findPortFile(roamDir) {
|
|
|
38233
38403
|
return void 0;
|
|
38234
38404
|
}
|
|
38235
38405
|
const candidates = entries.filter((name) => /^roam-local-api(-[^.]+)?\.port$/.test(name)).map((name) => {
|
|
38236
|
-
const
|
|
38406
|
+
const path96 = join100(roamDir, name);
|
|
38237
38407
|
try {
|
|
38238
|
-
return { path:
|
|
38408
|
+
return { path: path96, mtimeMs: statSync13(path96).mtimeMs };
|
|
38239
38409
|
} catch {
|
|
38240
38410
|
return void 0;
|
|
38241
38411
|
}
|
|
@@ -38306,10 +38476,10 @@ function formatConfiguredCommands() {
|
|
|
38306
38476
|
const { run: entries } = loadConfig();
|
|
38307
38477
|
const configs = resolveRunConfigs(entries, runConfigBaseDir());
|
|
38308
38478
|
if (configs.length === 0) return "\nNo configured commands";
|
|
38309
|
-
const
|
|
38479
|
+
const names2 = configs.map((r) => ` ${r.name}`).join("\n");
|
|
38310
38480
|
return `
|
|
38311
38481
|
Configured commands:
|
|
38312
|
-
${
|
|
38482
|
+
${names2}`;
|
|
38313
38483
|
}
|
|
38314
38484
|
|
|
38315
38485
|
// src/commands/run/spawnRunCommand.ts
|
|
@@ -38459,7 +38629,7 @@ Run \`assist run ${name} $ARGUMENTS 2>&1\`.
|
|
|
38459
38629
|
writeFileSync53(filePath, content);
|
|
38460
38630
|
console.log(`Created command file: ${filePath}`);
|
|
38461
38631
|
}
|
|
38462
|
-
function
|
|
38632
|
+
function add4() {
|
|
38463
38633
|
const { name, command, args, cwd } = requireParsedArgs();
|
|
38464
38634
|
saveNewRunConfig(name, command, args, cwd);
|
|
38465
38635
|
if (!name.startsWith("verify:")) {
|
|
@@ -38479,11 +38649,11 @@ function findLinkIndex() {
|
|
|
38479
38649
|
function parseLinkArgs() {
|
|
38480
38650
|
const idx = findLinkIndex();
|
|
38481
38651
|
if (idx === -1) return null;
|
|
38482
|
-
const
|
|
38652
|
+
const path96 = process.argv[idx + 1];
|
|
38483
38653
|
const rest = process.argv.slice(idx + 2);
|
|
38484
38654
|
const { value: prefix2 } = extractOption(rest, "--prefix");
|
|
38485
38655
|
if (!prefix2) return null;
|
|
38486
|
-
return { path:
|
|
38656
|
+
return { path: path96, prefix: prefix2 };
|
|
38487
38657
|
}
|
|
38488
38658
|
function hasDuplicateLink(runList, linkPath) {
|
|
38489
38659
|
return runList.some(
|
|
@@ -38556,7 +38726,7 @@ function registerRunSubcommands(runCommand) {
|
|
|
38556
38726
|
).addHelpText(
|
|
38557
38727
|
"after",
|
|
38558
38728
|
'\nPositional params can be added to the config manually:\n params:\n - name: env # assist run deploy prod \u2192 appends "prod"\n required: true\n - name: tag\n default: latest'
|
|
38559
|
-
).allowUnknownOption().allowExcessArguments().action(() =>
|
|
38729
|
+
).allowUnknownOption().allowExcessArguments().action(() => add4());
|
|
38560
38730
|
runCommand.command("link").description("Link run configurations from another project's assist.yml").argument("<path>", "Relative path to the linked project").requiredOption("--prefix <prefix>", "Namespace prefix for linked commands").allowUnknownOption().action(() => link2());
|
|
38561
38731
|
runCommand.command("remove").description("Remove a run configuration from assist.yml").argument("<name>", "Name of the run configuration to remove").action(() => remove());
|
|
38562
38732
|
}
|
|
@@ -38699,16 +38869,16 @@ function clearPersistedSessionsOnDrain() {
|
|
|
38699
38869
|
// src/commands/sessions/daemon/readDaemonMessage.ts
|
|
38700
38870
|
function readDaemonMessage(lines2, timeoutMs, fallback, match) {
|
|
38701
38871
|
return new Promise((resolve25) => {
|
|
38702
|
-
const
|
|
38872
|
+
const finish2 = (value) => {
|
|
38703
38873
|
clearTimeout(timer);
|
|
38704
38874
|
lines2.off("line", onLine);
|
|
38705
38875
|
resolve25(value);
|
|
38706
38876
|
};
|
|
38707
|
-
const timer = setTimeout(() =>
|
|
38877
|
+
const timer = setTimeout(() => finish2(fallback), timeoutMs);
|
|
38708
38878
|
const onLine = (line) => {
|
|
38709
38879
|
try {
|
|
38710
38880
|
const matched = match(JSON.parse(line));
|
|
38711
|
-
if (matched !== void 0)
|
|
38881
|
+
if (matched !== void 0) finish2(matched);
|
|
38712
38882
|
} catch {
|
|
38713
38883
|
}
|
|
38714
38884
|
};
|
|
@@ -38964,33 +39134,40 @@ function broadcastSessions(sessions, clients, windowsSessions = [], active) {
|
|
|
38964
39134
|
}
|
|
38965
39135
|
|
|
38966
39136
|
// src/shared/activeWindows.ts
|
|
38967
|
-
|
|
38968
|
-
function activeWindows(rateLimits) {
|
|
39137
|
+
function activeWindows(rateLimits, harness) {
|
|
38969
39138
|
if (!rateLimits) return [];
|
|
38970
39139
|
const out = [];
|
|
38971
|
-
for (const window of
|
|
39140
|
+
for (const window of RATE_LIMIT_WINDOWS) {
|
|
38972
39141
|
const resetsAt = rateLimits[window]?.resets_at;
|
|
38973
|
-
if (typeof resetsAt === "number")
|
|
39142
|
+
if (typeof resetsAt === "number")
|
|
39143
|
+
out.push({ window: usageWindowKey(harness, window), resetsAt });
|
|
38974
39144
|
}
|
|
38975
39145
|
return out;
|
|
38976
39146
|
}
|
|
38977
39147
|
|
|
38978
39148
|
// src/shared/db/recordUsagePeak.ts
|
|
38979
|
-
|
|
38980
|
-
|
|
38981
|
-
for (const window of WINDOWS2) {
|
|
39149
|
+
async function recordUsagePeak(db, rateLimits, now = Math.floor(Date.now() / 1e3), harness) {
|
|
39150
|
+
for (const window of RATE_LIMIT_WINDOWS) {
|
|
38982
39151
|
const w = rateLimits[window];
|
|
38983
39152
|
if (!w || typeof w.resets_at !== "number" || typeof w.used_percentage !== "number")
|
|
38984
39153
|
continue;
|
|
38985
|
-
await recordWindowPeak(
|
|
39154
|
+
await recordWindowPeak(
|
|
39155
|
+
db,
|
|
39156
|
+
usageWindowKey(harness, window),
|
|
39157
|
+
w.resets_at,
|
|
39158
|
+
w.used_percentage,
|
|
39159
|
+
now
|
|
39160
|
+
);
|
|
38986
39161
|
}
|
|
38987
39162
|
}
|
|
38988
39163
|
|
|
38989
39164
|
// src/commands/sessions/daemon/persistUsagePeak.ts
|
|
38990
|
-
async function persistUsagePeak(rateLimits) {
|
|
39165
|
+
async function persistUsagePeak(rateLimits, harness) {
|
|
38991
39166
|
try {
|
|
38992
39167
|
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) return;
|
|
38993
|
-
|
|
39168
|
+
const db = await getDb();
|
|
39169
|
+
if (harness) await recordUsagePeak(db, rateLimits, void 0, harness);
|
|
39170
|
+
else await recordUsagePeak(db, rateLimits);
|
|
38994
39171
|
} catch (error) {
|
|
38995
39172
|
daemonLog(`usage-peak persist failed: ${String(error)}`);
|
|
38996
39173
|
}
|
|
@@ -39004,6 +39181,7 @@ var ClientHub = class extends Set {
|
|
|
39004
39181
|
this.persistPeak = persistPeak;
|
|
39005
39182
|
}
|
|
39006
39183
|
latestLimits;
|
|
39184
|
+
harnessLimits = /* @__PURE__ */ new Map();
|
|
39007
39185
|
// why: log delivery is opt-in so browser tabs aren't spammed; only connections that ask via subscribe-logs receive daemonLog lines.
|
|
39008
39186
|
logSubscribers = /* @__PURE__ */ new Set();
|
|
39009
39187
|
updateLimits(rateLimits) {
|
|
@@ -39011,13 +39189,26 @@ var ClientHub = class extends Set {
|
|
|
39011
39189
|
broadcast(this, { type: "limits", rateLimits });
|
|
39012
39190
|
this.persistPeak?.(rateLimits);
|
|
39013
39191
|
}
|
|
39014
|
-
|
|
39015
|
-
|
|
39192
|
+
updateHarnessLimits(harness, rateLimits) {
|
|
39193
|
+
if (harness === "claude") {
|
|
39194
|
+
this.updateLimits(rateLimits);
|
|
39195
|
+
return;
|
|
39196
|
+
}
|
|
39197
|
+
this.harnessLimits.set(harness, rateLimits);
|
|
39198
|
+
broadcast(this, { type: "limits", harness, rateLimits });
|
|
39199
|
+
this.persistPeak?.(rateLimits, harness);
|
|
39200
|
+
}
|
|
39201
|
+
currentWindows(harness) {
|
|
39202
|
+
if (!harness || harness === "claude")
|
|
39203
|
+
return activeWindows(this.latestLimits);
|
|
39204
|
+
return activeWindows(this.harnessLimits.get(harness), harness);
|
|
39016
39205
|
}
|
|
39017
39206
|
greet(client) {
|
|
39018
39207
|
if (this.latestLimits) {
|
|
39019
39208
|
sendTo(client, { type: "limits", rateLimits: this.latestLimits });
|
|
39020
39209
|
}
|
|
39210
|
+
for (const [harness, rateLimits] of this.harnessLimits)
|
|
39211
|
+
sendTo(client, { type: "limits", harness, rateLimits });
|
|
39021
39212
|
}
|
|
39022
39213
|
subscribeLogs(client, replay = true) {
|
|
39023
39214
|
if (replay) {
|
|
@@ -39064,14 +39255,14 @@ import * as pty from "node-pty";
|
|
|
39064
39255
|
// src/commands/sessions/daemon/ensureSpawnHelperExecutable.ts
|
|
39065
39256
|
import { chmodSync, existsSync as existsSync88, statSync as statSync14 } from "fs";
|
|
39066
39257
|
import { createRequire as createRequire3 } from "module";
|
|
39067
|
-
import
|
|
39258
|
+
import path92 from "path";
|
|
39068
39259
|
var require4 = createRequire3(import.meta.url);
|
|
39069
39260
|
var ensured = false;
|
|
39070
39261
|
function ensureSpawnHelperExecutable() {
|
|
39071
39262
|
if (ensured || process.platform !== "darwin") return;
|
|
39072
39263
|
ensured = true;
|
|
39073
|
-
const ptyRoot =
|
|
39074
|
-
const helper =
|
|
39264
|
+
const ptyRoot = path92.join(path92.dirname(require4.resolve("node-pty")), "..");
|
|
39265
|
+
const helper = path92.join(
|
|
39075
39266
|
ptyRoot,
|
|
39076
39267
|
"prebuilds",
|
|
39077
39268
|
`${process.platform}-${process.arch}`,
|
|
@@ -39201,19 +39392,19 @@ function serverRunMeta(runName, cwd) {
|
|
|
39201
39392
|
}
|
|
39202
39393
|
|
|
39203
39394
|
// src/commands/sessions/daemon/readDesignSystemPrompt.ts
|
|
39204
|
-
import * as
|
|
39205
|
-
import * as
|
|
39395
|
+
import * as fs49 from "fs";
|
|
39396
|
+
import * as path93 from "path";
|
|
39206
39397
|
import { fileURLToPath as fileURLToPath11 } from "url";
|
|
39207
39398
|
var __filename5 = fileURLToPath11(import.meta.url);
|
|
39208
|
-
var __dirname7 =
|
|
39399
|
+
var __dirname7 = path93.dirname(__filename5);
|
|
39209
39400
|
function readDesignSystemPrompt() {
|
|
39210
|
-
const promptPath =
|
|
39401
|
+
const promptPath = path93.join(
|
|
39211
39402
|
__dirname7,
|
|
39212
39403
|
"..",
|
|
39213
39404
|
"claude",
|
|
39214
39405
|
"design-system-prompt.md"
|
|
39215
39406
|
);
|
|
39216
|
-
return
|
|
39407
|
+
return fs49.readFileSync(promptPath, "utf8");
|
|
39217
39408
|
}
|
|
39218
39409
|
|
|
39219
39410
|
// src/commands/sessions/daemon/spawnClaude.ts
|
|
@@ -40238,8 +40429,8 @@ async function seedRunningMsFromUsage(session, notify2) {
|
|
|
40238
40429
|
var DEBOUNCE_MS2 = 50;
|
|
40239
40430
|
function watchActivity(session, notify2, onClaudeSessionId) {
|
|
40240
40431
|
if (session.commandType !== "assist" || !session.cwd) return;
|
|
40241
|
-
const
|
|
40242
|
-
const dir = dirname42(
|
|
40432
|
+
const path96 = activityPath(session.id);
|
|
40433
|
+
const dir = dirname42(path96);
|
|
40243
40434
|
try {
|
|
40244
40435
|
mkdirSync37(dir, { recursive: true });
|
|
40245
40436
|
} catch {
|
|
@@ -40249,7 +40440,7 @@ function watchActivity(session, notify2, onClaudeSessionId) {
|
|
|
40249
40440
|
let timer = null;
|
|
40250
40441
|
const read3 = () => {
|
|
40251
40442
|
timer = null;
|
|
40252
|
-
const activity2 = readActivity(
|
|
40443
|
+
const activity2 = readActivity(path96);
|
|
40253
40444
|
if (!activity2) return;
|
|
40254
40445
|
applyActivityToSession(session, activity2);
|
|
40255
40446
|
if (activity2.claudeSessionId) onClaudeSessionId?.(session);
|
|
@@ -40258,11 +40449,11 @@ function watchActivity(session, notify2, onClaudeSessionId) {
|
|
|
40258
40449
|
notify2();
|
|
40259
40450
|
};
|
|
40260
40451
|
session.activityWatcher = watch2(dir, (_event, filename) => {
|
|
40261
|
-
if (filename && !
|
|
40452
|
+
if (filename && !path96.endsWith(filename)) return;
|
|
40262
40453
|
if (timer) clearTimeout(timer);
|
|
40263
40454
|
timer = setTimeout(read3, DEBOUNCE_MS2);
|
|
40264
40455
|
});
|
|
40265
|
-
if (existsSync94(
|
|
40456
|
+
if (existsSync94(path96)) read3();
|
|
40266
40457
|
}
|
|
40267
40458
|
function refreshActivity(session) {
|
|
40268
40459
|
if (session.commandType !== "assist" || !session.cwd) return;
|
|
@@ -40341,7 +40532,7 @@ function reportSilentFailure(session, clients) {
|
|
|
40341
40532
|
}
|
|
40342
40533
|
|
|
40343
40534
|
// src/commands/sessions/shared/codex/resolveCodexSessionId.ts
|
|
40344
|
-
import * as
|
|
40535
|
+
import * as fs50 from "fs";
|
|
40345
40536
|
var META_LINES = 5;
|
|
40346
40537
|
async function resolveCodexSessionId(cwd, sinceMs) {
|
|
40347
40538
|
if (!cwd) return null;
|
|
@@ -40370,7 +40561,7 @@ async function startedIn(file, cwd, sinceMs) {
|
|
|
40370
40561
|
}
|
|
40371
40562
|
async function touchedSince(file, sinceMs) {
|
|
40372
40563
|
try {
|
|
40373
|
-
return (await
|
|
40564
|
+
return (await fs50.promises.stat(file)).mtimeMs >= sinceMs;
|
|
40374
40565
|
} catch {
|
|
40375
40566
|
return false;
|
|
40376
40567
|
}
|
|
@@ -40404,42 +40595,42 @@ function bindCodexSession(session, notify2) {
|
|
|
40404
40595
|
import { watch as watch3 } from "fs";
|
|
40405
40596
|
|
|
40406
40597
|
// src/commands/sessions/shared/findTranscriptPathSync.ts
|
|
40407
|
-
import * as
|
|
40408
|
-
import * as
|
|
40598
|
+
import * as fs51 from "fs";
|
|
40599
|
+
import * as path94 from "path";
|
|
40409
40600
|
function projectDirForCwd(cwd) {
|
|
40410
|
-
return
|
|
40601
|
+
return path94.join(claudeProjectsRoot(), projectSlug(cwd));
|
|
40411
40602
|
}
|
|
40412
40603
|
function transcriptPathFor(cwd, claudeSessionId) {
|
|
40413
|
-
return
|
|
40604
|
+
return path94.join(projectDirForCwd(cwd), `${claudeSessionId}.jsonl`);
|
|
40414
40605
|
}
|
|
40415
40606
|
function findTranscriptPathSync(cwd, claudeSessionId) {
|
|
40416
40607
|
const direct = transcriptPathFor(cwd, claudeSessionId);
|
|
40417
|
-
if (
|
|
40608
|
+
if (fs51.existsSync(direct)) return direct;
|
|
40418
40609
|
const dir = projectDirForCwd(cwd);
|
|
40419
40610
|
let files;
|
|
40420
40611
|
try {
|
|
40421
|
-
files =
|
|
40612
|
+
files = fs51.readdirSync(dir);
|
|
40422
40613
|
} catch {
|
|
40423
40614
|
return null;
|
|
40424
40615
|
}
|
|
40425
40616
|
for (const file of files) {
|
|
40426
40617
|
if (!file.endsWith(".jsonl")) continue;
|
|
40427
|
-
if (headContainsSessionId(
|
|
40428
|
-
return
|
|
40618
|
+
if (headContainsSessionId(path94.join(dir, file), claudeSessionId))
|
|
40619
|
+
return path94.join(dir, file);
|
|
40429
40620
|
}
|
|
40430
40621
|
return null;
|
|
40431
40622
|
}
|
|
40432
40623
|
function headContainsSessionId(filePath, claudeSessionId) {
|
|
40433
40624
|
let fd;
|
|
40434
40625
|
try {
|
|
40435
|
-
fd =
|
|
40626
|
+
fd = fs51.openSync(filePath, "r");
|
|
40436
40627
|
const buf = Buffer.alloc(16384);
|
|
40437
|
-
const bytesRead =
|
|
40628
|
+
const bytesRead = fs51.readSync(fd, buf, 0, buf.length, 0);
|
|
40438
40629
|
return buf.toString("utf8", 0, bytesRead).includes(claudeSessionId);
|
|
40439
40630
|
} catch {
|
|
40440
40631
|
return false;
|
|
40441
40632
|
} finally {
|
|
40442
|
-
if (fd !== void 0)
|
|
40633
|
+
if (fd !== void 0) fs51.closeSync(fd);
|
|
40443
40634
|
}
|
|
40444
40635
|
}
|
|
40445
40636
|
|
|
@@ -40609,7 +40800,7 @@ function asRecord3(value) {
|
|
|
40609
40800
|
}
|
|
40610
40801
|
|
|
40611
40802
|
// src/commands/sessions/shared/readTranscriptTail.ts
|
|
40612
|
-
import * as
|
|
40803
|
+
import * as fs52 from "fs";
|
|
40613
40804
|
var DEFAULT_MAX_BYTES = 256 * 1024;
|
|
40614
40805
|
function parseTailEntries(raw) {
|
|
40615
40806
|
const entries = [];
|
|
@@ -40633,7 +40824,7 @@ function dropPartialFirstLine(raw, sliced) {
|
|
|
40633
40824
|
async function readTranscriptTail(filePath, maxBytes = DEFAULT_MAX_BYTES) {
|
|
40634
40825
|
let handle;
|
|
40635
40826
|
try {
|
|
40636
|
-
handle = await
|
|
40827
|
+
handle = await fs52.promises.open(filePath, "r");
|
|
40637
40828
|
const { size } = await handle.stat();
|
|
40638
40829
|
const start3 = Math.max(0, size - maxBytes);
|
|
40639
40830
|
const length = size - start3;
|
|
@@ -40652,20 +40843,20 @@ async function readTranscriptTail(filePath, maxBytes = DEFAULT_MAX_BYTES) {
|
|
|
40652
40843
|
function readTranscriptTailSync(filePath, maxBytes = DEFAULT_MAX_BYTES) {
|
|
40653
40844
|
let fd;
|
|
40654
40845
|
try {
|
|
40655
|
-
fd =
|
|
40656
|
-
const { size } =
|
|
40846
|
+
fd = fs52.openSync(filePath, "r");
|
|
40847
|
+
const { size } = fs52.fstatSync(fd);
|
|
40657
40848
|
const start3 = Math.max(0, size - maxBytes);
|
|
40658
40849
|
const length = size - start3;
|
|
40659
40850
|
if (length === 0) return [];
|
|
40660
40851
|
const buf = Buffer.alloc(length);
|
|
40661
|
-
|
|
40852
|
+
fs52.readSync(fd, buf, 0, length, start3);
|
|
40662
40853
|
return parseTailEntries(
|
|
40663
40854
|
dropPartialFirstLine(buf.toString("utf8"), start3 > 0)
|
|
40664
40855
|
);
|
|
40665
40856
|
} catch {
|
|
40666
40857
|
return [];
|
|
40667
40858
|
} finally {
|
|
40668
|
-
if (fd !== void 0)
|
|
40859
|
+
if (fd !== void 0) fs52.closeSync(fd);
|
|
40669
40860
|
}
|
|
40670
40861
|
}
|
|
40671
40862
|
|
|
@@ -40970,6 +41161,35 @@ function makeSessionSpawner(sessions, clients, counter, onStatusChange, notify2)
|
|
|
40970
41161
|
};
|
|
40971
41162
|
}
|
|
40972
41163
|
|
|
41164
|
+
// src/commands/sessions/shared/transcriptUsage.ts
|
|
41165
|
+
import * as fs53 from "fs";
|
|
41166
|
+
function transcriptUsage(lines2) {
|
|
41167
|
+
const byId = /* @__PURE__ */ new Map();
|
|
41168
|
+
for (const line of lines2) {
|
|
41169
|
+
if (!line.trim()) continue;
|
|
41170
|
+
let entry;
|
|
41171
|
+
try {
|
|
41172
|
+
entry = JSON.parse(line);
|
|
41173
|
+
} catch {
|
|
41174
|
+
continue;
|
|
41175
|
+
}
|
|
41176
|
+
if (entry.type !== "assistant") continue;
|
|
41177
|
+
const id = entry.message?.id;
|
|
41178
|
+
const usage = entry.message?.usage;
|
|
41179
|
+
if (!id || !usage) continue;
|
|
41180
|
+
byId.set(id, {
|
|
41181
|
+
messageId: id,
|
|
41182
|
+
inputTokens: usage.input_tokens ?? 0,
|
|
41183
|
+
outputTokens: usage.output_tokens ?? 0
|
|
41184
|
+
});
|
|
41185
|
+
}
|
|
41186
|
+
return [...byId.values()];
|
|
41187
|
+
}
|
|
41188
|
+
async function readTranscriptUsage(transcriptPath2) {
|
|
41189
|
+
const content = await fs53.promises.readFile(transcriptPath2, "utf8");
|
|
41190
|
+
return transcriptUsage(content.split("\n"));
|
|
41191
|
+
}
|
|
41192
|
+
|
|
40973
41193
|
// src/shared/db/recordPhaseCycleContext.ts
|
|
40974
41194
|
import { sql as sql25 } from "drizzle-orm";
|
|
40975
41195
|
async function recordPhaseCycleContext(db, itemId2, phaseIdx, window, resetsAt, pct) {
|
|
@@ -41043,37 +41263,8 @@ async function recordWindowTokens(db, window, resetsAt, tokensUp, tokensDown) {
|
|
|
41043
41263
|
);
|
|
41044
41264
|
}
|
|
41045
41265
|
|
|
41046
|
-
// src/commands/sessions/shared/transcriptUsage.ts
|
|
41047
|
-
import * as fs54 from "fs";
|
|
41048
|
-
function transcriptUsage(lines2) {
|
|
41049
|
-
const byId = /* @__PURE__ */ new Map();
|
|
41050
|
-
for (const line of lines2) {
|
|
41051
|
-
if (!line.trim()) continue;
|
|
41052
|
-
let entry;
|
|
41053
|
-
try {
|
|
41054
|
-
entry = JSON.parse(line);
|
|
41055
|
-
} catch {
|
|
41056
|
-
continue;
|
|
41057
|
-
}
|
|
41058
|
-
if (entry.type !== "assistant") continue;
|
|
41059
|
-
const id = entry.message?.id;
|
|
41060
|
-
const usage = entry.message?.usage;
|
|
41061
|
-
if (!id || !usage) continue;
|
|
41062
|
-
byId.set(id, {
|
|
41063
|
-
messageId: id,
|
|
41064
|
-
inputTokens: usage.input_tokens ?? 0,
|
|
41065
|
-
outputTokens: usage.output_tokens ?? 0
|
|
41066
|
-
});
|
|
41067
|
-
}
|
|
41068
|
-
return [...byId.values()];
|
|
41069
|
-
}
|
|
41070
|
-
async function readTranscriptUsage(transcriptPath2) {
|
|
41071
|
-
const content = await fs54.promises.readFile(transcriptPath2, "utf8");
|
|
41072
|
-
return transcriptUsage(content.split("\n"));
|
|
41073
|
-
}
|
|
41074
|
-
|
|
41075
41266
|
// src/commands/sessions/daemon/persistPhaseTokens.ts
|
|
41076
|
-
async function persistPhaseTokens(itemId2, phaseIdx,
|
|
41267
|
+
async function persistPhaseTokens(itemId2, phaseIdx, loadResponses, usedPct, windows) {
|
|
41077
41268
|
try {
|
|
41078
41269
|
if (!process.env.ASSIST_DATABASE_URL && !loadConfig().database.url) return;
|
|
41079
41270
|
const db = await getDb();
|
|
@@ -41090,7 +41281,7 @@ async function persistPhaseTokens(itemId2, phaseIdx, transcriptPath2, usedPct, w
|
|
|
41090
41281
|
);
|
|
41091
41282
|
}
|
|
41092
41283
|
}
|
|
41093
|
-
const responses = await
|
|
41284
|
+
const responses = await loadResponses();
|
|
41094
41285
|
if (responses.length === 0) return;
|
|
41095
41286
|
const { tokensUp, tokensDown } = await recordPhaseTranscriptUsage(
|
|
41096
41287
|
db,
|
|
@@ -41116,7 +41307,7 @@ function recordSessionUsage(sessions, claudeSessionId, transcriptPath2, usedPct,
|
|
|
41116
41307
|
void persistPhaseTokens(
|
|
41117
41308
|
phase.itemId,
|
|
41118
41309
|
phase.phaseIdx,
|
|
41119
|
-
transcriptPath2,
|
|
41310
|
+
() => readTranscriptUsage(transcriptPath2),
|
|
41120
41311
|
usedPct,
|
|
41121
41312
|
windows
|
|
41122
41313
|
);
|
|
@@ -41599,9 +41790,9 @@ function tempRoots() {
|
|
|
41599
41790
|
}
|
|
41600
41791
|
return [...roots];
|
|
41601
41792
|
}
|
|
41602
|
-
function underTempRoot(
|
|
41793
|
+
function underTempRoot(path96) {
|
|
41603
41794
|
return tempRoots().some(
|
|
41604
|
-
(
|
|
41795
|
+
(root2) => path96.startsWith(root2.endsWith(sep3) ? root2 : root2 + sep3)
|
|
41605
41796
|
);
|
|
41606
41797
|
}
|
|
41607
41798
|
|
|
@@ -41946,7 +42137,7 @@ function restoreAll(spawner, sessions) {
|
|
|
41946
42137
|
const persisted = dropTempRootedSessions(loadPersistedSessions());
|
|
41947
42138
|
const cap2 = sessionLimits.maxRestore();
|
|
41948
42139
|
const restoredIds = /* @__PURE__ */ new Map();
|
|
41949
|
-
const
|
|
42140
|
+
const names2 = persisted.slice(0, cap2).map((entry) => {
|
|
41950
42141
|
const id = restoreOne(entry, spawner, sessions);
|
|
41951
42142
|
if (entry.id != null && id != null) restoredIds.set(entry.id, id);
|
|
41952
42143
|
return entry.name;
|
|
@@ -41954,7 +42145,7 @@ function restoreAll(spawner, sessions) {
|
|
|
41954
42145
|
for (const over of persisted.slice(cap2))
|
|
41955
42146
|
deferOne(over, spawner.recoveryCard, cap2);
|
|
41956
42147
|
remapLaunchedFrom(sessions, restoredIds);
|
|
41957
|
-
return
|
|
42148
|
+
return names2;
|
|
41958
42149
|
}
|
|
41959
42150
|
function deferOne(persisted, spawnRecoveryCard, cap2) {
|
|
41960
42151
|
try {
|
|
@@ -41994,8 +42185,8 @@ function accountedTrees(sessions) {
|
|
|
41994
42185
|
const account = (cwd) => {
|
|
41995
42186
|
if (!cwd) return;
|
|
41996
42187
|
accounted.add(cwd);
|
|
41997
|
-
const
|
|
41998
|
-
if (
|
|
42188
|
+
const root2 = findRepoRoot(cwd);
|
|
42189
|
+
if (root2) accounted.add(root2);
|
|
41999
42190
|
};
|
|
42000
42191
|
for (const s of sessions.values()) {
|
|
42001
42192
|
account(s.cwd);
|
|
@@ -42043,15 +42234,15 @@ function bindResumedWorktree(session, cwd, notify2) {
|
|
|
42043
42234
|
import { existsSync as existsSync96 } from "fs";
|
|
42044
42235
|
async function reclaimVanishedWorktrees(clone, paths) {
|
|
42045
42236
|
if (!existsSync96(clone)) {
|
|
42046
|
-
for (const { path:
|
|
42237
|
+
for (const { path: path96 } of paths) forgetWorktree(path96);
|
|
42047
42238
|
daemonLog(
|
|
42048
42239
|
`clone ${clone} is gone; forgot ${paths.length} worktree record(s) it owned`
|
|
42049
42240
|
);
|
|
42050
42241
|
return;
|
|
42051
42242
|
}
|
|
42052
42243
|
await pruneBookkeeping2(clone);
|
|
42053
|
-
for (const { path:
|
|
42054
|
-
if (await reclaimBranch(clone, branch2)) forgetWorktree(
|
|
42244
|
+
for (const { path: path96, branch: branch2 } of paths)
|
|
42245
|
+
if (await reclaimBranch(clone, branch2)) forgetWorktree(path96);
|
|
42055
42246
|
}
|
|
42056
42247
|
async function pruneBookkeeping2(clone) {
|
|
42057
42248
|
try {
|
|
@@ -42078,37 +42269,37 @@ async function reclaimBranch(clone, branch2) {
|
|
|
42078
42269
|
}
|
|
42079
42270
|
|
|
42080
42271
|
// src/commands/sessions/daemon/worktree/logVanishedTree.ts
|
|
42081
|
-
function logVanishedTree(sessions,
|
|
42272
|
+
function logVanishedTree(sessions, path96) {
|
|
42082
42273
|
const claimants = [...sessions.values()].filter(
|
|
42083
|
-
(s) => s.cwd ===
|
|
42274
|
+
(s) => s.cwd === path96 || s.worktree?.path === path96
|
|
42084
42275
|
);
|
|
42085
42276
|
if (claimants.length === 0) {
|
|
42086
|
-
daemonLog(`worktree ${
|
|
42277
|
+
daemonLog(`worktree ${path96} gone from disk and unclaimed; reclaiming it`);
|
|
42087
42278
|
return;
|
|
42088
42279
|
}
|
|
42089
42280
|
for (const s of claimants)
|
|
42090
42281
|
daemonLog(
|
|
42091
|
-
`session ${s.id} ("${s.name}") claims worktree ${
|
|
42282
|
+
`session ${s.id} ("${s.name}") claims worktree ${path96}, which is gone from disk; reclaiming it`
|
|
42092
42283
|
);
|
|
42093
42284
|
}
|
|
42094
42285
|
|
|
42095
42286
|
// src/commands/sessions/daemon/worktree/describeHeldWork.ts
|
|
42096
42287
|
var MAX_ITEMS = 20;
|
|
42097
|
-
async function describeHeldWork(
|
|
42098
|
-
if (reason4.startsWith("uncommitted")) return await changedFiles(
|
|
42099
|
-
if (reason4.startsWith("unpushed")) return await unpushedCommits(
|
|
42288
|
+
async function describeHeldWork(path96, reason4) {
|
|
42289
|
+
if (reason4.startsWith("uncommitted")) return await changedFiles(path96);
|
|
42290
|
+
if (reason4.startsWith("unpushed")) return await unpushedCommits(path96, reason4);
|
|
42100
42291
|
return { summary: reason4, items: [] };
|
|
42101
42292
|
}
|
|
42102
|
-
async function changedFiles(
|
|
42103
|
-
const status3 = await gitResult(
|
|
42293
|
+
async function changedFiles(path96) {
|
|
42294
|
+
const status3 = await gitResult(path96, ["status", "--porcelain"]);
|
|
42104
42295
|
const lines2 = status3.ok ? nonEmptyLines(status3.out) : [];
|
|
42105
42296
|
return {
|
|
42106
42297
|
summary: `${lines2.length} uncommitted ${lines2.length === 1 ? "file" : "files"}`,
|
|
42107
42298
|
items: capped2(lines2)
|
|
42108
42299
|
};
|
|
42109
42300
|
}
|
|
42110
|
-
async function unpushedCommits(
|
|
42111
|
-
const log2 = await gitResult(
|
|
42301
|
+
async function unpushedCommits(path96, reason4) {
|
|
42302
|
+
const log2 = await gitResult(path96, ["log", "--oneline", "@{upstream}..HEAD"]);
|
|
42112
42303
|
if (!log2.ok) return { summary: reason4, items: [] };
|
|
42113
42304
|
const lines2 = nonEmptyLines(log2.out);
|
|
42114
42305
|
return {
|
|
@@ -42200,24 +42391,24 @@ function reconcileWorktreesOnRestore(sessions, spawnWith, notify2) {
|
|
|
42200
42391
|
async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
|
|
42201
42392
|
const accounted = accountedTrees(sessions);
|
|
42202
42393
|
const vanished = /* @__PURE__ */ new Map();
|
|
42203
|
-
for (const { path:
|
|
42204
|
-
if (underTempRoot(
|
|
42205
|
-
forgetWorktree(
|
|
42394
|
+
for (const { path: path96, clone } of readWorktreeRegistry()) {
|
|
42395
|
+
if (underTempRoot(path96)) {
|
|
42396
|
+
forgetWorktree(path96);
|
|
42206
42397
|
daemonLog(
|
|
42207
|
-
`worktree ${
|
|
42398
|
+
`worktree ${path96} lies outside any project root; pruned from the registry rather than recovered`
|
|
42208
42399
|
);
|
|
42209
42400
|
continue;
|
|
42210
42401
|
}
|
|
42211
|
-
if (!existsSync97(
|
|
42212
|
-
logVanishedTree(sessions,
|
|
42402
|
+
if (!existsSync97(path96)) {
|
|
42403
|
+
logVanishedTree(sessions, path96);
|
|
42213
42404
|
vanished.set(clone, [
|
|
42214
42405
|
...vanished.get(clone) ?? [],
|
|
42215
|
-
{ path:
|
|
42406
|
+
{ path: path96, branch: basename28(path96) }
|
|
42216
42407
|
]);
|
|
42217
42408
|
continue;
|
|
42218
42409
|
}
|
|
42219
|
-
if (accounted.has(
|
|
42220
|
-
await recoverOrphan(sessions, spawnWith, { path:
|
|
42410
|
+
if (accounted.has(path96)) continue;
|
|
42411
|
+
await recoverOrphan(sessions, spawnWith, { path: path96, clone }, notify2);
|
|
42221
42412
|
}
|
|
42222
42413
|
for (const [clone, paths] of vanished)
|
|
42223
42414
|
await reclaimVanishedWorktrees(clone, paths);
|
|
@@ -42225,10 +42416,10 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
|
|
|
42225
42416
|
|
|
42226
42417
|
// src/commands/sessions/daemon/restoreAllSessions.ts
|
|
42227
42418
|
function restoreAllSessions(spawner, sessions, notify2) {
|
|
42228
|
-
const
|
|
42419
|
+
const names2 = restoreAll(spawner, sessions);
|
|
42229
42420
|
reconcileWorktreesOnRestore(sessions, spawner.recoveryCard, notify2);
|
|
42230
42421
|
rearmStoppedSessions(sessions, notify2);
|
|
42231
|
-
return
|
|
42422
|
+
return names2;
|
|
42232
42423
|
}
|
|
42233
42424
|
|
|
42234
42425
|
// src/commands/sessions/daemon/retrySession.ts
|
|
@@ -42409,8 +42600,8 @@ function boundTreeRoots(sessions, exclude) {
|
|
|
42409
42600
|
const roots = /* @__PURE__ */ new Set();
|
|
42410
42601
|
for (const session of sessions.values()) {
|
|
42411
42602
|
if (session === exclude) continue;
|
|
42412
|
-
const
|
|
42413
|
-
if (
|
|
42603
|
+
const root2 = treeRootOf(session);
|
|
42604
|
+
if (root2 && !roots.has(root2) && holdsTree(session, root2)) roots.add(root2);
|
|
42414
42605
|
}
|
|
42415
42606
|
return roots;
|
|
42416
42607
|
}
|
|
@@ -42418,12 +42609,12 @@ function treeRootOf(session) {
|
|
|
42418
42609
|
if (!session.cwd) return void 0;
|
|
42419
42610
|
return canonicalTreePath(findRepoRoot(session.cwd) ?? session.cwd);
|
|
42420
42611
|
}
|
|
42421
|
-
function holdsTree(session,
|
|
42612
|
+
function holdsTree(session, root2) {
|
|
42422
42613
|
if (session.closing) return true;
|
|
42423
42614
|
if (session.status !== "done" && session.status !== "error") return true;
|
|
42424
|
-
if (!worktreeConfigFor(
|
|
42425
|
-
const durability = checkDurabilitySync(
|
|
42426
|
-
daemonLog(`tree ${
|
|
42615
|
+
if (!worktreeConfigFor(root2).enabled) return true;
|
|
42616
|
+
const durability = checkDurabilitySync(root2);
|
|
42617
|
+
daemonLog(`tree ${root2} ${releaseReason(durability, session)}`);
|
|
42427
42618
|
return !durability.durable;
|
|
42428
42619
|
}
|
|
42429
42620
|
function releaseReason(durability, session) {
|
|
@@ -43916,6 +44107,119 @@ function creator(isNew, spawn13) {
|
|
|
43916
44107
|
};
|
|
43917
44108
|
}
|
|
43918
44109
|
|
|
44110
|
+
// src/commands/sessions/shared/codex/codexRolloutUsage.ts
|
|
44111
|
+
import * as fs54 from "fs";
|
|
44112
|
+
|
|
44113
|
+
// src/commands/sessions/shared/codex/applyTokenInfo.ts
|
|
44114
|
+
function applyTokenInfo(usage, byId, conversationId, rawInfo) {
|
|
44115
|
+
if (!rawInfo || typeof rawInfo !== "object") return;
|
|
44116
|
+
const info = rawInfo;
|
|
44117
|
+
const last = info.last_token_usage;
|
|
44118
|
+
const cumulative = info.total_token_usage?.total_tokens;
|
|
44119
|
+
if (!last || typeof cumulative !== "number") return;
|
|
44120
|
+
const messageId = `codex:${conversationId}:${cumulative}`;
|
|
44121
|
+
byId.set(messageId, {
|
|
44122
|
+
messageId,
|
|
44123
|
+
inputTokens: Math.max(
|
|
44124
|
+
0,
|
|
44125
|
+
(last.input_tokens ?? 0) - (last.cached_input_tokens ?? 0)
|
|
44126
|
+
),
|
|
44127
|
+
outputTokens: last.output_tokens ?? 0
|
|
44128
|
+
});
|
|
44129
|
+
const contextWindow = info.model_context_window;
|
|
44130
|
+
if (contextWindow && typeof last.total_tokens === "number")
|
|
44131
|
+
usage.usedPct = Math.min(100, last.total_tokens / contextWindow * 100);
|
|
44132
|
+
}
|
|
44133
|
+
|
|
44134
|
+
// src/commands/sessions/shared/codex/toRateLimits.ts
|
|
44135
|
+
var WINDOW_BY_MINUTES = {
|
|
44136
|
+
300: "five_hour",
|
|
44137
|
+
10080: "seven_day"
|
|
44138
|
+
};
|
|
44139
|
+
function toRateLimits(raw) {
|
|
44140
|
+
if (!raw || typeof raw !== "object") return void 0;
|
|
44141
|
+
const { primary, secondary } = raw;
|
|
44142
|
+
const rateLimits = {};
|
|
44143
|
+
for (const candidate of [primary, secondary]) {
|
|
44144
|
+
if (!candidate || typeof candidate !== "object") continue;
|
|
44145
|
+
const limit = candidate;
|
|
44146
|
+
const window = WINDOW_BY_MINUTES[limit.window_minutes ?? 0];
|
|
44147
|
+
if (!window || typeof limit.used_percent !== "number") continue;
|
|
44148
|
+
rateLimits[window] = {
|
|
44149
|
+
used_percentage: limit.used_percent,
|
|
44150
|
+
resets_at: limit.resets_at
|
|
44151
|
+
};
|
|
44152
|
+
}
|
|
44153
|
+
return Object.keys(rateLimits).length > 0 ? rateLimits : void 0;
|
|
44154
|
+
}
|
|
44155
|
+
|
|
44156
|
+
// src/commands/sessions/shared/codex/codexRolloutUsage.ts
|
|
44157
|
+
function codexRolloutUsage(lines2) {
|
|
44158
|
+
const usage = { responses: [] };
|
|
44159
|
+
const byId = /* @__PURE__ */ new Map();
|
|
44160
|
+
let conversationId = "";
|
|
44161
|
+
for (const line of lines2) {
|
|
44162
|
+
const entry = parseRolloutEntry(line);
|
|
44163
|
+
if (!entry) continue;
|
|
44164
|
+
conversationId ||= sessionMetaId(entry);
|
|
44165
|
+
const payload = tokenCountPayload(entry);
|
|
44166
|
+
if (!payload) continue;
|
|
44167
|
+
applyTokenInfo(usage, byId, conversationId, payload.info);
|
|
44168
|
+
usage.rateLimits = toRateLimits(payload.rate_limits) ?? usage.rateLimits;
|
|
44169
|
+
}
|
|
44170
|
+
usage.responses = [...byId.values()];
|
|
44171
|
+
return usage;
|
|
44172
|
+
}
|
|
44173
|
+
async function readCodexRolloutUsage(rolloutPath) {
|
|
44174
|
+
const content = await fs54.promises.readFile(rolloutPath, "utf8");
|
|
44175
|
+
return codexRolloutUsage(content.split("\n"));
|
|
44176
|
+
}
|
|
44177
|
+
function sessionMetaId(entry) {
|
|
44178
|
+
if (entry.type !== "session_meta") return "";
|
|
44179
|
+
return rolloutString(rolloutPayload(entry).session_id);
|
|
44180
|
+
}
|
|
44181
|
+
function tokenCountPayload(entry) {
|
|
44182
|
+
if (entry.type !== "event_msg") return void 0;
|
|
44183
|
+
const payload = rolloutPayload(entry);
|
|
44184
|
+
return payload.type === "token_count" ? payload : void 0;
|
|
44185
|
+
}
|
|
44186
|
+
|
|
44187
|
+
// src/commands/sessions/daemon/applyCodexUsage.ts
|
|
44188
|
+
function applyCodexUsage(sessions, sessionId, usage, windows) {
|
|
44189
|
+
const session = sessions.get(sessionId);
|
|
44190
|
+
if (!session) return false;
|
|
44191
|
+
if (usage.usedPct !== void 0) session.usedPct = usage.usedPct;
|
|
44192
|
+
const phase = sessionBacklogPhase(session);
|
|
44193
|
+
if (phase)
|
|
44194
|
+
void persistPhaseTokens(
|
|
44195
|
+
phase.itemId,
|
|
44196
|
+
phase.phaseIdx,
|
|
44197
|
+
async () => usage.responses,
|
|
44198
|
+
usage.usedPct,
|
|
44199
|
+
windows
|
|
44200
|
+
);
|
|
44201
|
+
void flushPhaseActiveMs(session);
|
|
44202
|
+
return true;
|
|
44203
|
+
}
|
|
44204
|
+
|
|
44205
|
+
// src/commands/sessions/daemon/handleCodexUsage.ts
|
|
44206
|
+
var handleCodexUsage = (client, m, d) => {
|
|
44207
|
+
if (m.windowsProxy.route(client, d)) return;
|
|
44208
|
+
const sessionId = d.sessionId;
|
|
44209
|
+
if (d.ack) sendTo(client, { type: "ack", sessionId });
|
|
44210
|
+
void readCodexRolloutUsage(d.transcriptPath).then(
|
|
44211
|
+
(usage) => {
|
|
44212
|
+
if (usage.rateLimits)
|
|
44213
|
+
m.clients.updateHarnessLimits("codex", usage.rateLimits);
|
|
44214
|
+
const windows = m.clients.currentWindows("codex");
|
|
44215
|
+
m.update(
|
|
44216
|
+
(sessions) => applyCodexUsage(sessions, sessionId, usage, windows)
|
|
44217
|
+
);
|
|
44218
|
+
},
|
|
44219
|
+
(error) => daemonLog(`codex-usage read failed: ${String(error)}`)
|
|
44220
|
+
);
|
|
44221
|
+
};
|
|
44222
|
+
|
|
43919
44223
|
// src/commands/sessions/daemon/spawnContextFrom.ts
|
|
43920
44224
|
function spawnContextFrom(d) {
|
|
43921
44225
|
return {
|
|
@@ -43979,12 +44283,12 @@ function handleSetStatus(client, m, d) {
|
|
|
43979
44283
|
import * as fs55 from "fs";
|
|
43980
44284
|
|
|
43981
44285
|
// src/commands/sessions/shared/codex/findCodexRolloutPath.ts
|
|
43982
|
-
import * as
|
|
44286
|
+
import * as path95 from "path";
|
|
43983
44287
|
async function findCodexRolloutPath(sessionId) {
|
|
43984
44288
|
if (!sessionId) return null;
|
|
43985
44289
|
const paths = await discoverCodexRolloutPaths();
|
|
43986
44290
|
const suffix = `-${sessionId}.jsonl`;
|
|
43987
|
-
return paths.find((file) =>
|
|
44291
|
+
return paths.find((file) => path95.basename(file).endsWith(suffix)) ?? null;
|
|
43988
44292
|
}
|
|
43989
44293
|
|
|
43990
44294
|
// src/commands/sessions/shared/codex/codexToolTarget.ts
|
|
@@ -44253,6 +44557,7 @@ var messageHandlers = {
|
|
|
44253
44557
|
d.transcriptPath,
|
|
44254
44558
|
d.usedPct
|
|
44255
44559
|
),
|
|
44560
|
+
"codex-usage": handleCodexUsage,
|
|
44256
44561
|
input: routed(
|
|
44257
44562
|
(_client, m, d) => m.writeToSession(d.sessionId, d.data)
|
|
44258
44563
|
),
|