@staff0rd/assist 0.721.1 → 0.721.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/sessions/web/bundle.js +1 -1
- package/dist/index.js +346 -342
- 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.721.
|
|
9
|
+
version: "0.721.2",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -31500,101 +31500,38 @@ Renamed ${oldName} \u2192 ${newName}`));
|
|
|
31500
31500
|
// src/commands/refactor/restructure.ts
|
|
31501
31501
|
import fs38 from "fs";
|
|
31502
31502
|
import path80 from "path";
|
|
31503
|
-
import
|
|
31504
|
-
|
|
31505
|
-
// src/commands/refactor/restructure/applyPlan.ts
|
|
31506
|
-
import chalk216 from "chalk";
|
|
31507
|
-
|
|
31508
|
-
// src/commands/refactor/restructure/executePlan.ts
|
|
31509
|
-
import fs37 from "fs";
|
|
31510
|
-
import path62 from "path";
|
|
31511
|
-
import chalk215 from "chalk";
|
|
31512
|
-
function relPath(file) {
|
|
31513
|
-
return path62.relative(process.cwd(), file);
|
|
31514
|
-
}
|
|
31515
|
-
function stagingPath(move2, index3) {
|
|
31516
|
-
return `${move2.from}.restructure-${process.pid}-${index3}`;
|
|
31517
|
-
}
|
|
31518
|
-
function moveFiles(moves) {
|
|
31519
|
-
const staged = moves.map((move2, i) => {
|
|
31520
|
-
const staging = stagingPath(move2, i);
|
|
31521
|
-
fs37.renameSync(move2.from, staging);
|
|
31522
|
-
return { move: move2, staging };
|
|
31523
|
-
});
|
|
31524
|
-
for (const { move: move2, staging } of staged) {
|
|
31525
|
-
fs37.mkdirSync(path62.dirname(move2.to), { recursive: true });
|
|
31526
|
-
fs37.renameSync(staging, move2.to);
|
|
31527
|
-
console.log(
|
|
31528
|
-
chalk215.white(` Moved ${relPath(move2.from)} \u2192 ${relPath(move2.to)}`)
|
|
31529
|
-
);
|
|
31530
|
-
}
|
|
31531
|
-
}
|
|
31532
|
-
function removeIfEmpty(dir) {
|
|
31533
|
-
if (!fs37.existsSync(dir) || fs37.readdirSync(dir).length > 0) return false;
|
|
31534
|
-
fs37.rmdirSync(dir);
|
|
31535
|
-
console.log(chalk215.dim(` Removed empty directory ${relPath(dir)}`));
|
|
31536
|
-
return true;
|
|
31537
|
-
}
|
|
31538
|
-
function removeEmptyDirectories(dirs, scopeRoot) {
|
|
31539
|
-
const deepestFirst = [...new Set(dirs)].sort((a, b) => b.length - a.length);
|
|
31540
|
-
for (let dir of deepestFirst) {
|
|
31541
|
-
while (dir.startsWith(`${scopeRoot}${path62.sep}`) && removeIfEmpty(dir))
|
|
31542
|
-
dir = path62.dirname(dir);
|
|
31543
|
-
}
|
|
31544
|
-
}
|
|
31545
|
-
function executePlan(plan2) {
|
|
31546
|
-
for (const [file, content] of applyRewrites(plan2.rewrites)) {
|
|
31547
|
-
fs37.writeFileSync(file, content, "utf8");
|
|
31548
|
-
console.log(chalk215.cyan(` Rewrote imports in ${relPath(file)}`));
|
|
31549
|
-
}
|
|
31550
|
-
moveFiles(plan2.moves);
|
|
31551
|
-
removeEmptyDirectories(
|
|
31552
|
-
plan2.moves.map((m) => path62.dirname(m.from)),
|
|
31553
|
-
plan2.scopeRoot
|
|
31554
|
-
);
|
|
31555
|
-
}
|
|
31556
|
-
|
|
31557
|
-
// src/commands/refactor/restructure/applyPlan.ts
|
|
31558
|
-
function applyPlan(plan2) {
|
|
31559
|
-
if (plan2.errors.length > 0) {
|
|
31560
|
-
console.log(chalk216.red("\nResolve the errors above before applying."));
|
|
31561
|
-
process.exit(1);
|
|
31562
|
-
}
|
|
31563
|
-
console.log(chalk216.bold("\nApplying changes..."));
|
|
31564
|
-
executePlan(plan2);
|
|
31565
|
-
console.log(chalk216.green("\nRestructuring complete"));
|
|
31566
|
-
}
|
|
31503
|
+
import chalk222 from "chalk";
|
|
31567
31504
|
|
|
31568
31505
|
// src/commands/refactor/restructure/buildPlan.ts
|
|
31569
|
-
import
|
|
31506
|
+
import path71 from "path";
|
|
31570
31507
|
|
|
31571
31508
|
// src/commands/refactor/restructure/planRestructure.ts
|
|
31572
|
-
import
|
|
31509
|
+
import path70 from "path";
|
|
31573
31510
|
|
|
31574
31511
|
// src/commands/refactor/restructure/planRestructure/anchored.ts
|
|
31575
|
-
import
|
|
31512
|
+
import path62 from "path";
|
|
31576
31513
|
function anchored(files, mode, reasonPrefix) {
|
|
31577
31514
|
return {
|
|
31578
31515
|
root: false,
|
|
31579
31516
|
anchors: files.map((file) => ({ file, mode })),
|
|
31580
|
-
reason: `${reasonPrefix} ${files.map((f) =>
|
|
31517
|
+
reason: `${reasonPrefix} ${files.map((f) => path62.basename(f)).join(", ")}`
|
|
31581
31518
|
};
|
|
31582
31519
|
}
|
|
31583
31520
|
|
|
31584
31521
|
// src/commands/refactor/restructure/planRestructure/isTestFile.ts
|
|
31585
|
-
import
|
|
31522
|
+
import path63 from "path";
|
|
31586
31523
|
var TEST_SUFFIX = /\.test\.tsx?$/;
|
|
31587
31524
|
function isTestFile(file) {
|
|
31588
31525
|
return TEST_SUFFIX.test(file);
|
|
31589
31526
|
}
|
|
31590
31527
|
function testStem(file) {
|
|
31591
|
-
return
|
|
31528
|
+
return path63.basename(file).replace(TEST_SUFFIX, "");
|
|
31592
31529
|
}
|
|
31593
31530
|
|
|
31594
31531
|
// src/commands/refactor/restructure/planRestructure/moduleStem.ts
|
|
31595
|
-
import
|
|
31532
|
+
import path64 from "path";
|
|
31596
31533
|
function moduleStem(file) {
|
|
31597
|
-
return
|
|
31534
|
+
return path64.basename(file).replace(/\.tsx?$/, "");
|
|
31598
31535
|
}
|
|
31599
31536
|
|
|
31600
31537
|
// src/commands/refactor/restructure/planRestructure/collectAnchors.ts
|
|
@@ -31644,16 +31581,16 @@ function collectAnchors(files, index3, pinned) {
|
|
|
31644
31581
|
}
|
|
31645
31582
|
|
|
31646
31583
|
// src/commands/refactor/restructure/planRestructure/findCollisions.ts
|
|
31647
|
-
import
|
|
31584
|
+
import path65 from "path";
|
|
31648
31585
|
function findCollisions(targets, scopeRoot) {
|
|
31649
31586
|
const byModule = /* @__PURE__ */ new Map();
|
|
31650
31587
|
for (const [file, target] of targets) {
|
|
31651
|
-
const key =
|
|
31588
|
+
const key = path65.join(path65.dirname(target), moduleStem(target));
|
|
31652
31589
|
byModule.set(key, [...byModule.get(key) ?? [], file]);
|
|
31653
31590
|
}
|
|
31654
31591
|
return [...byModule].filter(([, files]) => files.length > 1).map(([key, files]) => {
|
|
31655
|
-
const where =
|
|
31656
|
-
const sources = files.sort().map((f) =>
|
|
31592
|
+
const where = path65.relative(scopeRoot, path65.dirname(key)) || ".";
|
|
31593
|
+
const sources = files.sort().map((f) => path65.relative(scopeRoot, f));
|
|
31657
31594
|
return `Basename collision in ${where}/: ${sources.join(", ")}`;
|
|
31658
31595
|
}).sort();
|
|
31659
31596
|
}
|
|
@@ -31685,38 +31622,38 @@ function indexEdges(scope, edges) {
|
|
|
31685
31622
|
}
|
|
31686
31623
|
|
|
31687
31624
|
// src/commands/refactor/restructure/planRestructure/placeComponents.ts
|
|
31688
|
-
import
|
|
31625
|
+
import path69 from "path";
|
|
31689
31626
|
|
|
31690
31627
|
// src/commands/refactor/restructure/planRestructure/componentDir.ts
|
|
31691
|
-
import
|
|
31628
|
+
import path68 from "path";
|
|
31692
31629
|
|
|
31693
31630
|
// src/commands/refactor/restructure/planRestructure/liftToPinFolder.ts
|
|
31694
|
-
import
|
|
31631
|
+
import path66 from "path";
|
|
31695
31632
|
function liftToPinFolder(dir, pinFolders, scopeRoot) {
|
|
31696
31633
|
let lifted = scopeRoot;
|
|
31697
31634
|
for (const folder of pinFolders)
|
|
31698
|
-
if ((dir === folder || dir.startsWith(folder +
|
|
31635
|
+
if ((dir === folder || dir.startsWith(folder + path66.sep)) && folder.length > lifted.length)
|
|
31699
31636
|
lifted = folder;
|
|
31700
31637
|
return lifted;
|
|
31701
31638
|
}
|
|
31702
31639
|
|
|
31703
31640
|
// src/commands/refactor/restructure/planRestructure/lowestCommonAncestor.ts
|
|
31704
|
-
import
|
|
31641
|
+
import path67 from "path";
|
|
31705
31642
|
function lowestCommonAncestor(dirs) {
|
|
31706
|
-
const [first, ...rest] = dirs.map((d) => d.split(
|
|
31643
|
+
const [first, ...rest] = dirs.map((d) => d.split(path67.sep));
|
|
31707
31644
|
let common = first;
|
|
31708
31645
|
for (const parts of rest) {
|
|
31709
31646
|
let i = 0;
|
|
31710
31647
|
while (i < common.length && i < parts.length && common[i] === parts[i]) i++;
|
|
31711
31648
|
common = common.slice(0, i);
|
|
31712
31649
|
}
|
|
31713
|
-
return common.join(
|
|
31650
|
+
return common.join(path67.sep) || path67.sep;
|
|
31714
31651
|
}
|
|
31715
31652
|
|
|
31716
31653
|
// src/commands/refactor/restructure/planRestructure/componentDir.ts
|
|
31717
31654
|
function anchorFolder(anchor, dirs) {
|
|
31718
31655
|
const dir = dirs.get(anchor.file);
|
|
31719
|
-
return anchor.mode === "child" ?
|
|
31656
|
+
return anchor.mode === "child" ? path68.join(dir, moduleStem(anchor.file)) : dir;
|
|
31720
31657
|
}
|
|
31721
31658
|
function externalAnchors(component, anchorings) {
|
|
31722
31659
|
const members = new Set(component);
|
|
@@ -31798,7 +31735,7 @@ function isPinFolderOwner(anchoring) {
|
|
|
31798
31735
|
}
|
|
31799
31736
|
function componentReason(file, component, base) {
|
|
31800
31737
|
if (component.length === 1) return base;
|
|
31801
|
-
const others = component.filter((f) => f !== file).map((f) =>
|
|
31738
|
+
const others = component.filter((f) => f !== file).map((f) => path69.basename(f));
|
|
31802
31739
|
return `${base}; cycle with ${others.join(", ")}`;
|
|
31803
31740
|
}
|
|
31804
31741
|
function placeComponents(files, anchorings, scopeRoot) {
|
|
@@ -31811,7 +31748,7 @@ function placeComponents(files, anchorings, scopeRoot) {
|
|
|
31811
31748
|
const anchoring = anchorings.get(file);
|
|
31812
31749
|
layout.dirs.set(file, dir);
|
|
31813
31750
|
if (isPinFolderOwner(anchoring))
|
|
31814
|
-
layout.pinFolders.add(
|
|
31751
|
+
layout.pinFolders.add(path69.join(dir, moduleStem(file)));
|
|
31815
31752
|
placements.set(file, {
|
|
31816
31753
|
dir,
|
|
31817
31754
|
reason: componentReason(file, component, anchoring.reason)
|
|
@@ -31823,7 +31760,7 @@ function placeComponents(files, anchorings, scopeRoot) {
|
|
|
31823
31760
|
|
|
31824
31761
|
// src/commands/refactor/restructure/planRestructure.ts
|
|
31825
31762
|
function planRestructure(input) {
|
|
31826
|
-
const scopeRoot =
|
|
31763
|
+
const scopeRoot = path70.resolve(input.scopeRoot);
|
|
31827
31764
|
const files = [...new Set(input.files)].sort();
|
|
31828
31765
|
const index3 = indexEdges(new Set(files), input.edges);
|
|
31829
31766
|
const anchorings = collectAnchors(files, index3, new Set(input.pinnedModules));
|
|
@@ -31832,7 +31769,7 @@ function planRestructure(input) {
|
|
|
31832
31769
|
const moves = [];
|
|
31833
31770
|
for (const file of files) {
|
|
31834
31771
|
const { dir, reason: reason4 } = placements.get(file);
|
|
31835
|
-
const to =
|
|
31772
|
+
const to = path70.join(dir, path70.basename(file));
|
|
31836
31773
|
targets.set(file, to);
|
|
31837
31774
|
if (to !== file) moves.push({ from: file, to, reason: reason4 });
|
|
31838
31775
|
}
|
|
@@ -31841,14 +31778,14 @@ function planRestructure(input) {
|
|
|
31841
31778
|
|
|
31842
31779
|
// src/commands/refactor/restructure/buildPlan.ts
|
|
31843
31780
|
function moduleKey(file) {
|
|
31844
|
-
return
|
|
31781
|
+
return path71.join(path71.dirname(file), moduleStem(file));
|
|
31845
31782
|
}
|
|
31846
31783
|
function findIgnoredOccupants(moves, ignored, scopeRoot) {
|
|
31847
31784
|
const occupants = new Map(ignored.map((f) => [moduleKey(f), f]));
|
|
31848
31785
|
return moves.flatMap((move2) => {
|
|
31849
31786
|
const occupant = occupants.get(moduleKey(move2.to));
|
|
31850
31787
|
if (!occupant) return [];
|
|
31851
|
-
const rel = (f) =>
|
|
31788
|
+
const rel = (f) => path71.relative(scopeRoot, f);
|
|
31852
31789
|
return [
|
|
31853
31790
|
`Target of ${rel(move2.from)} is occupied by ignored file ${rel(occupant)}`
|
|
31854
31791
|
];
|
|
@@ -31879,55 +31816,63 @@ function buildPlan3(scopeRoot, files, ignored = [], pinnedModules = []) {
|
|
|
31879
31816
|
}
|
|
31880
31817
|
|
|
31881
31818
|
// src/commands/refactor/restructure/checkPlan.ts
|
|
31882
|
-
import
|
|
31883
|
-
|
|
31819
|
+
import chalk217 from "chalk";
|
|
31820
|
+
|
|
31821
|
+
// src/commands/refactor/restructure/applyCommand.ts
|
|
31822
|
+
import path72 from "path";
|
|
31823
|
+
function applyCommand(scopeRoot) {
|
|
31824
|
+
const root2 = path72.relative(process.cwd(), scopeRoot) || ".";
|
|
31825
|
+
return `assist refactor restructure ${root2} --apply`;
|
|
31826
|
+
}
|
|
31884
31827
|
|
|
31885
31828
|
// src/commands/refactor/restructure/displayDeepChains.ts
|
|
31886
|
-
import
|
|
31829
|
+
import chalk215 from "chalk";
|
|
31887
31830
|
var shownChains = 10;
|
|
31888
|
-
|
|
31889
|
-
|
|
31890
|
-
|
|
31891
|
-
|
|
31892
|
-
|
|
31893
|
-
|
|
31894
|
-
|
|
31895
|
-
|
|
31831
|
+
function pinSteps(apply) {
|
|
31832
|
+
return [
|
|
31833
|
+
"Pin feature modules until this check passes:",
|
|
31834
|
+
"1. On each chain, pick the highest module that is a feature boundary: a route, view, page, panel, dialog or card. Never a hook, utility, style file or helper.",
|
|
31835
|
+
"2. Add it to restructure.pin in assist.yml yourself (basename without extension). One pin at a time: one feature pin often fixes several chains.",
|
|
31836
|
+
"3. Re-run this command. Repeat until the plan is within the limit.",
|
|
31837
|
+
"4. If a chain has no sensible feature boundary, or a pin leaves one folder holding far more files than the rest, stop and report it.",
|
|
31838
|
+
`Then run \`${apply}\`.`
|
|
31839
|
+
];
|
|
31840
|
+
}
|
|
31896
31841
|
function formatChain(chain2) {
|
|
31897
31842
|
const folders = chain2.folders.map((f) => `${f.name} (${f.files})`).join(" > ");
|
|
31898
31843
|
return ` ${folders} > \u2026 [${chain2.tooDeep} file(s) too deep, down to depth ${chain2.deepest}]`;
|
|
31899
31844
|
}
|
|
31900
|
-
function displayDeepChains(chains, maxDepth) {
|
|
31845
|
+
function displayDeepChains(chains, maxDepth, apply) {
|
|
31901
31846
|
if (chains.length === 0) return;
|
|
31902
31847
|
const tooDeep = chains.reduce((sum3, c) => sum3 + c.tooDeep, 0);
|
|
31903
31848
|
console.log(
|
|
31904
|
-
|
|
31849
|
+
chalk215.red(
|
|
31905
31850
|
`
|
|
31906
31851
|
Plan exceeds restructure.maxDepth ${maxDepth}: ${tooDeep} file(s) deeper.`
|
|
31907
31852
|
)
|
|
31908
31853
|
);
|
|
31909
31854
|
console.log(
|
|
31910
|
-
|
|
31855
|
+
chalk215.bold(
|
|
31911
31856
|
"Deep chains, as folder (files beneath), most files too deep first:"
|
|
31912
31857
|
)
|
|
31913
31858
|
);
|
|
31914
31859
|
for (const chain2 of chains.slice(0, shownChains))
|
|
31915
31860
|
console.log(formatChain(chain2));
|
|
31916
31861
|
if (chains.length > shownChains)
|
|
31917
|
-
console.log(
|
|
31862
|
+
console.log(chalk215.dim(` \u2026and ${chains.length - shownChains} more`));
|
|
31918
31863
|
console.log("");
|
|
31919
|
-
for (const line of
|
|
31864
|
+
for (const line of pinSteps(apply)) console.log(chalk215.yellow(line));
|
|
31920
31865
|
}
|
|
31921
31866
|
|
|
31922
31867
|
// src/commands/refactor/restructure/displayDrift.ts
|
|
31923
31868
|
import path73 from "path";
|
|
31924
|
-
import
|
|
31869
|
+
import chalk216 from "chalk";
|
|
31925
31870
|
var shownMoves = 20;
|
|
31926
31871
|
function displayDrift(plan2, listMoves) {
|
|
31927
31872
|
const rel = (file) => path73.relative(process.cwd(), file);
|
|
31928
31873
|
if (plan2.moves.length > 0) {
|
|
31929
31874
|
console.log(
|
|
31930
|
-
|
|
31875
|
+
chalk216.red(
|
|
31931
31876
|
`${plan2.moves.length} file(s) drift from the plan${listMoves ? ":" : "."}`
|
|
31932
31877
|
)
|
|
31933
31878
|
);
|
|
@@ -31935,54 +31880,158 @@ function displayDrift(plan2, listMoves) {
|
|
|
31935
31880
|
for (const move2 of plan2.moves.slice(0, shownMoves))
|
|
31936
31881
|
console.log(` ${rel(move2.from)} \u2192 ${rel(move2.to)}`);
|
|
31937
31882
|
if (plan2.moves.length > shownMoves)
|
|
31938
|
-
console.log(
|
|
31883
|
+
console.log(chalk216.dim(` \u2026and ${plan2.moves.length - shownMoves} more`));
|
|
31939
31884
|
}
|
|
31940
31885
|
}
|
|
31941
|
-
for (const error of plan2.errors) console.log(
|
|
31886
|
+
for (const error of plan2.errors) console.log(chalk216.red(error));
|
|
31942
31887
|
}
|
|
31943
31888
|
|
|
31944
31889
|
// src/commands/refactor/restructure/checkPlan.ts
|
|
31945
|
-
function applyCommand(plan2) {
|
|
31946
|
-
const root2 = path74.relative(process.cwd(), plan2.scopeRoot) || ".";
|
|
31947
|
-
return `assist refactor restructure ${root2} --apply`;
|
|
31948
|
-
}
|
|
31949
31890
|
function checkPlan(plan2, chains, maxDepth) {
|
|
31891
|
+
const apply = applyCommand(plan2.scopeRoot);
|
|
31950
31892
|
displayDrift(plan2, chains.length === 0);
|
|
31951
|
-
displayDeepChains(chains, maxDepth);
|
|
31952
|
-
if (chains.length > 0)
|
|
31893
|
+
displayDeepChains(chains, maxDepth, apply);
|
|
31894
|
+
if (chains.length > 0 || plan2.errors.length > 0) process.exit(1);
|
|
31895
|
+
if (plan2.moves.length > 0) {
|
|
31953
31896
|
console.log(
|
|
31954
|
-
|
|
31897
|
+
chalk217.yellow(
|
|
31955
31898
|
`
|
|
31956
|
-
|
|
31899
|
+
Run \`${apply}\` to move the files and rewrite their imports.`
|
|
31957
31900
|
)
|
|
31958
31901
|
);
|
|
31959
31902
|
process.exit(1);
|
|
31960
31903
|
}
|
|
31961
|
-
|
|
31962
|
-
|
|
31904
|
+
console.log(chalk217.green("Layout matches the restructure plan"));
|
|
31905
|
+
}
|
|
31906
|
+
|
|
31907
|
+
// src/commands/refactor/restructure/findDeepChains.ts
|
|
31908
|
+
import path74 from "path";
|
|
31909
|
+
function dirSegments(target, scopeRoot) {
|
|
31910
|
+
const dir = path74.relative(scopeRoot, path74.dirname(target));
|
|
31911
|
+
return dir === "" ? [] : dir.split(path74.sep);
|
|
31912
|
+
}
|
|
31913
|
+
function countSubtrees(segmentLists) {
|
|
31914
|
+
const counts2 = /* @__PURE__ */ new Map();
|
|
31915
|
+
for (const segments of segmentLists)
|
|
31916
|
+
for (let i = 1; i <= segments.length; i++) {
|
|
31917
|
+
const key = segments.slice(0, i).join("/");
|
|
31918
|
+
counts2.set(key, (counts2.get(key) ?? 0) + 1);
|
|
31919
|
+
}
|
|
31920
|
+
return counts2;
|
|
31921
|
+
}
|
|
31922
|
+
function findDeepChains(targets, scopeRoot, maxDepth) {
|
|
31923
|
+
const segmentLists = [...targets].map((t) => dirSegments(t, scopeRoot));
|
|
31924
|
+
const subtreeFiles = countSubtrees(segmentLists);
|
|
31925
|
+
const chains = /* @__PURE__ */ new Map();
|
|
31926
|
+
for (const segments of segmentLists) {
|
|
31927
|
+
if (segments.length <= maxDepth) continue;
|
|
31928
|
+
const head = segments.slice(0, maxDepth + 1);
|
|
31929
|
+
const key = head.join("/");
|
|
31930
|
+
const chain2 = chains.get(key) ?? {
|
|
31931
|
+
folders: head.map((name, i) => ({
|
|
31932
|
+
name,
|
|
31933
|
+
files: subtreeFiles.get(head.slice(0, i + 1).join("/")) ?? 0
|
|
31934
|
+
})),
|
|
31935
|
+
tooDeep: 0,
|
|
31936
|
+
deepest: 0
|
|
31937
|
+
};
|
|
31938
|
+
chain2.tooDeep += 1;
|
|
31939
|
+
chain2.deepest = Math.max(chain2.deepest, segments.length);
|
|
31940
|
+
chains.set(key, chain2);
|
|
31941
|
+
}
|
|
31942
|
+
return [...chains.entries()].sort(([ka, a], [kb, b]) => b.tooDeep - a.tooDeep || ka.localeCompare(kb)).map(([, chain2]) => chain2);
|
|
31943
|
+
}
|
|
31944
|
+
|
|
31945
|
+
// src/commands/refactor/restructure/partitionIgnored.ts
|
|
31946
|
+
import path75 from "path";
|
|
31947
|
+
import { minimatch as minimatch4 } from "minimatch";
|
|
31948
|
+
function partitionIgnored(files) {
|
|
31949
|
+
const globs = loadConfig().restructure?.ignore ?? [];
|
|
31950
|
+
const isIgnored = (file) => globs.some((glob) => minimatch4(path75.relative(process.cwd(), file), glob));
|
|
31951
|
+
return {
|
|
31952
|
+
scoped: files.filter((f) => !isIgnored(f)),
|
|
31953
|
+
ignored: files.filter(isIgnored)
|
|
31954
|
+
};
|
|
31955
|
+
}
|
|
31956
|
+
|
|
31957
|
+
// src/commands/refactor/restructure/runPlan.ts
|
|
31958
|
+
import chalk221 from "chalk";
|
|
31959
|
+
|
|
31960
|
+
// src/commands/refactor/restructure/applyPlan.ts
|
|
31961
|
+
import chalk219 from "chalk";
|
|
31962
|
+
|
|
31963
|
+
// src/commands/refactor/restructure/executePlan.ts
|
|
31964
|
+
import fs37 from "fs";
|
|
31965
|
+
import path76 from "path";
|
|
31966
|
+
import chalk218 from "chalk";
|
|
31967
|
+
function relPath(file) {
|
|
31968
|
+
return path76.relative(process.cwd(), file);
|
|
31969
|
+
}
|
|
31970
|
+
function stagingPath(move2, index3) {
|
|
31971
|
+
return `${move2.from}.restructure-${process.pid}-${index3}`;
|
|
31972
|
+
}
|
|
31973
|
+
function moveFiles(moves) {
|
|
31974
|
+
const staged = moves.map((move2, i) => {
|
|
31975
|
+
const staging = stagingPath(move2, i);
|
|
31976
|
+
fs37.renameSync(move2.from, staging);
|
|
31977
|
+
return { move: move2, staging };
|
|
31978
|
+
});
|
|
31979
|
+
for (const { move: move2, staging } of staged) {
|
|
31980
|
+
fs37.mkdirSync(path76.dirname(move2.to), { recursive: true });
|
|
31981
|
+
fs37.renameSync(staging, move2.to);
|
|
31963
31982
|
console.log(
|
|
31964
|
-
|
|
31965
|
-
`
|
|
31966
|
-
Run \`${applyCommand(plan2)}\` to move the files and rewrite their imports.`
|
|
31967
|
-
)
|
|
31983
|
+
chalk218.white(` Moved ${relPath(move2.from)} \u2192 ${relPath(move2.to)}`)
|
|
31968
31984
|
);
|
|
31985
|
+
}
|
|
31986
|
+
}
|
|
31987
|
+
function removeIfEmpty(dir) {
|
|
31988
|
+
if (!fs37.existsSync(dir) || fs37.readdirSync(dir).length > 0) return false;
|
|
31989
|
+
fs37.rmdirSync(dir);
|
|
31990
|
+
console.log(chalk218.dim(` Removed empty directory ${relPath(dir)}`));
|
|
31991
|
+
return true;
|
|
31992
|
+
}
|
|
31993
|
+
function removeEmptyDirectories(dirs, scopeRoot) {
|
|
31994
|
+
const deepestFirst = [...new Set(dirs)].sort((a, b) => b.length - a.length);
|
|
31995
|
+
for (let dir of deepestFirst) {
|
|
31996
|
+
while (dir.startsWith(`${scopeRoot}${path76.sep}`) && removeIfEmpty(dir))
|
|
31997
|
+
dir = path76.dirname(dir);
|
|
31998
|
+
}
|
|
31999
|
+
}
|
|
32000
|
+
function executePlan(plan2) {
|
|
32001
|
+
for (const [file, content] of applyRewrites(plan2.rewrites)) {
|
|
32002
|
+
fs37.writeFileSync(file, content, "utf8");
|
|
32003
|
+
console.log(chalk218.cyan(` Rewrote imports in ${relPath(file)}`));
|
|
32004
|
+
}
|
|
32005
|
+
moveFiles(plan2.moves);
|
|
32006
|
+
removeEmptyDirectories(
|
|
32007
|
+
plan2.moves.map((m) => path76.dirname(m.from)),
|
|
32008
|
+
plan2.scopeRoot
|
|
32009
|
+
);
|
|
32010
|
+
}
|
|
32011
|
+
|
|
32012
|
+
// src/commands/refactor/restructure/applyPlan.ts
|
|
32013
|
+
function applyPlan(plan2) {
|
|
32014
|
+
if (plan2.errors.length > 0) {
|
|
32015
|
+
console.log(chalk219.red("\nResolve the errors above before applying."));
|
|
31969
32016
|
process.exit(1);
|
|
31970
32017
|
}
|
|
31971
|
-
console.log(chalk219.
|
|
32018
|
+
console.log(chalk219.bold("\nApplying changes..."));
|
|
32019
|
+
executePlan(plan2);
|
|
32020
|
+
console.log(chalk219.green("\nRestructuring complete"));
|
|
31972
32021
|
}
|
|
31973
32022
|
|
|
31974
32023
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
31975
|
-
import
|
|
32024
|
+
import path79 from "path";
|
|
31976
32025
|
import chalk220 from "chalk";
|
|
31977
32026
|
|
|
31978
32027
|
// src/commands/refactor/restructure/computeDepthStats.ts
|
|
31979
|
-
import
|
|
32028
|
+
import path77 from "path";
|
|
31980
32029
|
function computeDepthStats(targets, scopeRoot) {
|
|
31981
32030
|
const distribution = /* @__PURE__ */ new Map();
|
|
31982
32031
|
let max = 0;
|
|
31983
32032
|
for (const target of targets) {
|
|
31984
|
-
const dir =
|
|
31985
|
-
const depth = dir === "" ? 0 : dir.split(
|
|
32033
|
+
const dir = path77.relative(scopeRoot, path77.dirname(target));
|
|
32034
|
+
const depth = dir === "" ? 0 : dir.split(path77.sep).length;
|
|
31986
32035
|
distribution.set(depth, (distribution.get(depth) ?? 0) + 1);
|
|
31987
32036
|
max = Math.max(max, depth);
|
|
31988
32037
|
}
|
|
@@ -31990,7 +32039,7 @@ function computeDepthStats(targets, scopeRoot) {
|
|
|
31990
32039
|
}
|
|
31991
32040
|
|
|
31992
32041
|
// src/commands/refactor/restructure/formatTree.ts
|
|
31993
|
-
import
|
|
32042
|
+
import path78 from "path";
|
|
31994
32043
|
function insert(root2, parts) {
|
|
31995
32044
|
let node = root2;
|
|
31996
32045
|
for (const part of parts) {
|
|
@@ -32012,7 +32061,7 @@ function render(node, indent3, lines2) {
|
|
|
32012
32061
|
function formatTree(files, scopeRoot) {
|
|
32013
32062
|
const root2 = /* @__PURE__ */ new Map();
|
|
32014
32063
|
for (const file of files)
|
|
32015
|
-
insert(root2,
|
|
32064
|
+
insert(root2, path78.relative(scopeRoot, file).split(path78.sep));
|
|
32016
32065
|
const lines2 = [];
|
|
32017
32066
|
render(root2, "", lines2);
|
|
32018
32067
|
return lines2;
|
|
@@ -32020,7 +32069,7 @@ function formatTree(files, scopeRoot) {
|
|
|
32020
32069
|
|
|
32021
32070
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
32022
32071
|
function relPath2(filePath) {
|
|
32023
|
-
return
|
|
32072
|
+
return path79.relative(process.cwd(), filePath);
|
|
32024
32073
|
}
|
|
32025
32074
|
function displayMoves(plan2) {
|
|
32026
32075
|
if (plan2.moves.length === 0) return;
|
|
@@ -32069,85 +32118,40 @@ Summary: ${plan2.moves.length} file(s) moved, ${plan2.rewrites.length} imports r
|
|
|
32069
32118
|
);
|
|
32070
32119
|
}
|
|
32071
32120
|
|
|
32072
|
-
// src/commands/refactor/restructure/
|
|
32073
|
-
|
|
32074
|
-
|
|
32075
|
-
|
|
32076
|
-
|
|
32077
|
-
|
|
32078
|
-
|
|
32079
|
-
const counts2 = /* @__PURE__ */ new Map();
|
|
32080
|
-
for (const segments of segmentLists)
|
|
32081
|
-
for (let i = 1; i <= segments.length; i++) {
|
|
32082
|
-
const key = segments.slice(0, i).join("/");
|
|
32083
|
-
counts2.set(key, (counts2.get(key) ?? 0) + 1);
|
|
32084
|
-
}
|
|
32085
|
-
return counts2;
|
|
32086
|
-
}
|
|
32087
|
-
function findDeepChains(targets, scopeRoot, maxDepth) {
|
|
32088
|
-
const segmentLists = [...targets].map((t) => dirSegments(t, scopeRoot));
|
|
32089
|
-
const subtreeFiles = countSubtrees(segmentLists);
|
|
32090
|
-
const chains = /* @__PURE__ */ new Map();
|
|
32091
|
-
for (const segments of segmentLists) {
|
|
32092
|
-
if (segments.length <= maxDepth) continue;
|
|
32093
|
-
const head = segments.slice(0, maxDepth + 1);
|
|
32094
|
-
const key = head.join("/");
|
|
32095
|
-
const chain2 = chains.get(key) ?? {
|
|
32096
|
-
folders: head.map((name, i) => ({
|
|
32097
|
-
name,
|
|
32098
|
-
files: subtreeFiles.get(head.slice(0, i + 1).join("/")) ?? 0
|
|
32099
|
-
})),
|
|
32100
|
-
tooDeep: 0,
|
|
32101
|
-
deepest: 0
|
|
32102
|
-
};
|
|
32103
|
-
chain2.tooDeep += 1;
|
|
32104
|
-
chain2.deepest = Math.max(chain2.deepest, segments.length);
|
|
32105
|
-
chains.set(key, chain2);
|
|
32121
|
+
// src/commands/refactor/restructure/runPlan.ts
|
|
32122
|
+
function runPlan(plan2, chains, maxDepth, apply) {
|
|
32123
|
+
displayPlan2(plan2);
|
|
32124
|
+
displayDeepChains(chains, maxDepth, applyCommand(plan2.scopeRoot));
|
|
32125
|
+
if (plan2.moves.length === 0 && plan2.errors.length === 0) {
|
|
32126
|
+
console.log(chalk221.green("No restructuring needed"));
|
|
32127
|
+
return;
|
|
32106
32128
|
}
|
|
32107
|
-
|
|
32108
|
-
|
|
32109
|
-
|
|
32110
|
-
|
|
32111
|
-
|
|
32112
|
-
import { minimatch as minimatch4 } from "minimatch";
|
|
32113
|
-
function partitionIgnored(files) {
|
|
32114
|
-
const globs = loadConfig().restructure?.ignore ?? [];
|
|
32115
|
-
const isIgnored = (file) => globs.some((glob) => minimatch4(path79.relative(process.cwd(), file), glob));
|
|
32116
|
-
return {
|
|
32117
|
-
scoped: files.filter((f) => !isIgnored(f)),
|
|
32118
|
-
ignored: files.filter(isIgnored)
|
|
32119
|
-
};
|
|
32129
|
+
if (!apply) {
|
|
32130
|
+
console.log(chalk221.dim("\nDry run. Use --apply to execute."));
|
|
32131
|
+
return;
|
|
32132
|
+
}
|
|
32133
|
+
applyPlan(plan2);
|
|
32120
32134
|
}
|
|
32121
32135
|
|
|
32122
32136
|
// src/commands/refactor/restructure.ts
|
|
32123
32137
|
async function restructure(root2, options2 = {}) {
|
|
32124
32138
|
const scopeRoot = path80.resolve(root2 ?? "src");
|
|
32125
32139
|
if (!fs38.existsSync(scopeRoot) || !fs38.statSync(scopeRoot).isDirectory()) {
|
|
32126
|
-
console.log(
|
|
32140
|
+
console.log(chalk222.red(`Not a directory: ${root2 ?? "src"}`));
|
|
32127
32141
|
process.exit(1);
|
|
32128
32142
|
}
|
|
32129
32143
|
const found = [];
|
|
32130
32144
|
walkSourceFiles(scopeRoot, found);
|
|
32131
32145
|
const { scoped, ignored } = partitionIgnored(found);
|
|
32132
32146
|
if (scoped.length === 0) {
|
|
32133
|
-
console.log(
|
|
32147
|
+
console.log(chalk222.yellow("No files found under root"));
|
|
32134
32148
|
return;
|
|
32135
32149
|
}
|
|
32136
32150
|
const { pin: pin2 = [], maxDepth = 10 } = loadConfig().restructure ?? {};
|
|
32137
32151
|
const plan2 = buildPlan3(scopeRoot, scoped, ignored, pin2);
|
|
32138
32152
|
const chains = findDeepChains(plan2.targets.values(), scopeRoot, maxDepth);
|
|
32139
32153
|
if (options2.check) return checkPlan(plan2, chains, maxDepth);
|
|
32140
|
-
|
|
32141
|
-
displayDeepChains(chains, maxDepth);
|
|
32142
|
-
if (plan2.moves.length === 0 && plan2.errors.length === 0) {
|
|
32143
|
-
console.log(chalk221.green("No restructuring needed"));
|
|
32144
|
-
return;
|
|
32145
|
-
}
|
|
32146
|
-
if (!options2.apply) {
|
|
32147
|
-
console.log(chalk221.dim("\nDry run. Use --apply to execute."));
|
|
32148
|
-
return;
|
|
32149
|
-
}
|
|
32150
|
-
applyPlan(plan2);
|
|
32154
|
+
runPlan(plan2, chains, maxDepth, options2.apply === true);
|
|
32151
32155
|
}
|
|
32152
32156
|
|
|
32153
32157
|
// src/commands/registerRefactor.ts
|
|
@@ -32202,7 +32206,7 @@ async function checkoutOnlySession(number) {
|
|
|
32202
32206
|
}
|
|
32203
32207
|
|
|
32204
32208
|
// src/commands/review/highLevel/configureHighLevelReview.ts
|
|
32205
|
-
import
|
|
32209
|
+
import chalk226 from "chalk";
|
|
32206
32210
|
|
|
32207
32211
|
// src/commands/config/promptConfigScope.ts
|
|
32208
32212
|
import Enquirer3 from "enquirer";
|
|
@@ -32228,7 +32232,7 @@ async function promptConfigScope() {
|
|
|
32228
32232
|
}
|
|
32229
32233
|
|
|
32230
32234
|
// src/commands/config/resolveConfigKeyAnswer.ts
|
|
32231
|
-
import
|
|
32235
|
+
import chalk223 from "chalk";
|
|
32232
32236
|
async function resolveConfigKeyAnswer(question, supplied) {
|
|
32233
32237
|
if (supplied !== void 0) return coerceSupplied(question.key, supplied);
|
|
32234
32238
|
for (; ; ) {
|
|
@@ -32236,7 +32240,7 @@ async function resolveConfigKeyAnswer(question, supplied) {
|
|
|
32236
32240
|
if (answer === "") return void 0;
|
|
32237
32241
|
const coercion = coerceCliConfigValue(question.key, answer);
|
|
32238
32242
|
if (coercion.ok) return coercion.value;
|
|
32239
|
-
console.error(
|
|
32243
|
+
console.error(chalk223.red(coercion.error));
|
|
32240
32244
|
}
|
|
32241
32245
|
}
|
|
32242
32246
|
function coerceSupplied(key, supplied) {
|
|
@@ -32297,7 +32301,7 @@ function suggestGlobs(current, proposed) {
|
|
|
32297
32301
|
}
|
|
32298
32302
|
|
|
32299
32303
|
// src/commands/review/highLevel/parseConfigureAnswers.ts
|
|
32300
|
-
import
|
|
32304
|
+
import chalk224 from "chalk";
|
|
32301
32305
|
function parseConfigureAnswers(answers) {
|
|
32302
32306
|
const known = Object.values(highLevelConfigKeys);
|
|
32303
32307
|
const parsed = {};
|
|
@@ -32315,13 +32319,13 @@ function answersCoverEveryKey(answers) {
|
|
|
32315
32319
|
return Object.values(highLevelConfigKeys).every((key) => key in answers);
|
|
32316
32320
|
}
|
|
32317
32321
|
function exitWith(message3) {
|
|
32318
|
-
console.error(
|
|
32322
|
+
console.error(chalk224.red(`Error: ${message3}.`));
|
|
32319
32323
|
process.exit(1);
|
|
32320
32324
|
}
|
|
32321
32325
|
|
|
32322
32326
|
// src/commands/review/highLevel/proposeHighLevelGlobs.ts
|
|
32323
32327
|
import { execFileSync as execFileSync20 } from "child_process";
|
|
32324
|
-
import
|
|
32328
|
+
import chalk225 from "chalk";
|
|
32325
32329
|
|
|
32326
32330
|
// src/commands/review/highLevel/buildGlobProposalPrompt.ts
|
|
32327
32331
|
function buildGlobProposalPrompt(tree) {
|
|
@@ -32414,12 +32418,12 @@ function proposeHighLevelGlobs(cwd = process.cwd()) {
|
|
|
32414
32418
|
const tree = summariseRepoTree(cwd);
|
|
32415
32419
|
if (tree === "") return NOTHING_PROPOSED;
|
|
32416
32420
|
console.log(
|
|
32417
|
-
|
|
32421
|
+
chalk225.dim("Asking Claude to propose globs from the repo's own tree...")
|
|
32418
32422
|
);
|
|
32419
32423
|
const output = askClaude(buildGlobProposalPrompt(tree), cwd);
|
|
32420
32424
|
if (output === void 0) {
|
|
32421
32425
|
console.log(
|
|
32422
|
-
|
|
32426
|
+
chalk225.yellow(
|
|
32423
32427
|
"Claude proposed nothing; answer each key from its current value."
|
|
32424
32428
|
)
|
|
32425
32429
|
);
|
|
@@ -32475,25 +32479,25 @@ function asConfigKeyScope(value) {
|
|
|
32475
32479
|
function reportConfigured(result) {
|
|
32476
32480
|
for (const write of result.written)
|
|
32477
32481
|
console.log(
|
|
32478
|
-
|
|
32482
|
+
chalk226.green(`Set ${write.key} = ${JSON.stringify(write.value)}`)
|
|
32479
32483
|
);
|
|
32480
|
-
for (const key of result.skipped) console.log(
|
|
32481
|
-
console.log(
|
|
32484
|
+
for (const key of result.skipped) console.log(chalk226.dim(`Left ${key} unset`));
|
|
32485
|
+
console.log(chalk226.dim(`Written to ${result.target}`));
|
|
32482
32486
|
}
|
|
32483
32487
|
|
|
32484
32488
|
// src/commands/review/highLevel/announceSavedReview.ts
|
|
32485
|
-
import
|
|
32489
|
+
import chalk227 from "chalk";
|
|
32486
32490
|
function announceSavedReview(subject, force) {
|
|
32487
32491
|
const head = subject.headSha.slice(0, 7);
|
|
32488
32492
|
if (subject.saved)
|
|
32489
32493
|
console.log(
|
|
32490
|
-
|
|
32494
|
+
chalk227.dim(
|
|
32491
32495
|
`Reopening the review saved for ${head} at ${subject.saved.reviewedAt} (${subject.saved.verdict}); pass --force to start fresh.`
|
|
32492
32496
|
)
|
|
32493
32497
|
);
|
|
32494
32498
|
else if (force)
|
|
32495
32499
|
console.log(
|
|
32496
|
-
|
|
32500
|
+
chalk227.dim(
|
|
32497
32501
|
`Discarding any review saved for ${head} and starting fresh (--force).`
|
|
32498
32502
|
)
|
|
32499
32503
|
);
|
|
@@ -33034,55 +33038,55 @@ async function openHighLevelOverlay(sessionId, subject) {
|
|
|
33034
33038
|
}
|
|
33035
33039
|
|
|
33036
33040
|
// src/commands/review/highLevel/printHighLevelChecklist.ts
|
|
33037
|
-
import
|
|
33041
|
+
import chalk231 from "chalk";
|
|
33038
33042
|
|
|
33039
33043
|
// src/commands/review/highLevel/formatCriticalDiffs.ts
|
|
33040
|
-
import
|
|
33044
|
+
import chalk228 from "chalk";
|
|
33041
33045
|
var PATCH_LINE_COLOURS = {
|
|
33042
|
-
"+":
|
|
33043
|
-
"-":
|
|
33044
|
-
"@":
|
|
33046
|
+
"+": chalk228.green,
|
|
33047
|
+
"-": chalk228.red,
|
|
33048
|
+
"@": chalk228.cyan
|
|
33045
33049
|
};
|
|
33046
33050
|
function formatPatch(patch2) {
|
|
33047
33051
|
return patch2.split("\n").map(
|
|
33048
|
-
(line) => ` ${(PATCH_LINE_COLOURS[line[0] ?? ""] ??
|
|
33052
|
+
(line) => ` ${(PATCH_LINE_COLOURS[line[0] ?? ""] ?? chalk228.dim)(line)}`
|
|
33049
33053
|
);
|
|
33050
33054
|
}
|
|
33051
33055
|
function formatDiff(diff3) {
|
|
33052
33056
|
return [
|
|
33053
33057
|
"",
|
|
33054
|
-
` ${
|
|
33055
|
-
...diff3.patch === null ? [` ${
|
|
33058
|
+
` ${chalk228.bold(diff3.path)} ${chalk228.dim(`(${diff3.status})`)} ${chalk228.green(`+${diff3.additions}`)} ${chalk228.red(`-${diff3.deletions}`)}`,
|
|
33059
|
+
...diff3.patch === null ? [` ${chalk228.dim(`no diff available; see ${diff3.diffUrl}`)}`] : formatPatch(diff3.patch)
|
|
33056
33060
|
];
|
|
33057
33061
|
}
|
|
33058
33062
|
function formatCriticalDiffs(diffs, criticalPaths) {
|
|
33059
33063
|
if (criticalPaths.length === 0)
|
|
33060
|
-
return `${
|
|
33061
|
-
${
|
|
33064
|
+
return `${chalk228.bold.underline("Critical diffs")}
|
|
33065
|
+
${chalk228.dim("review.highLevel.criticalPaths is unset, so no diffs are shown")}`;
|
|
33062
33066
|
if (diffs.length === 0)
|
|
33063
|
-
return `${
|
|
33064
|
-
${
|
|
33067
|
+
return `${chalk228.bold.underline("Critical diffs")}
|
|
33068
|
+
${chalk228.dim(`no changed file matches ${criticalPaths.join(", ")}`)}`;
|
|
33065
33069
|
return [
|
|
33066
|
-
|
|
33070
|
+
chalk228.bold.underline("Critical diffs"),
|
|
33067
33071
|
...diffs.flatMap(formatDiff)
|
|
33068
33072
|
].join("\n");
|
|
33069
33073
|
}
|
|
33070
33074
|
|
|
33071
33075
|
// src/commands/review/highLevel/formatHighLevelChecklist.ts
|
|
33072
|
-
import
|
|
33076
|
+
import chalk229 from "chalk";
|
|
33073
33077
|
var MARKERS = {
|
|
33074
|
-
pass: () =>
|
|
33075
|
-
fail: () =>
|
|
33076
|
-
manual: () =>
|
|
33078
|
+
pass: () => chalk229.green("\u2714"),
|
|
33079
|
+
fail: () => chalk229.red("\u2718"),
|
|
33080
|
+
manual: () => chalk229.yellow("\u25A1")
|
|
33077
33081
|
};
|
|
33078
33082
|
function formatCheck(check2) {
|
|
33079
|
-
const title = check2.status === "fail" ?
|
|
33083
|
+
const title = check2.status === "fail" ? chalk229.red(check2.title) : chalk229.bold(check2.title);
|
|
33080
33084
|
return ` ${MARKERS[check2.status]()} ${title}
|
|
33081
|
-
${
|
|
33085
|
+
${chalk229.dim(check2.reason)}`;
|
|
33082
33086
|
}
|
|
33083
33087
|
function formatGroup(heading2, checks2) {
|
|
33084
33088
|
if (checks2.length === 0) return [];
|
|
33085
|
-
return ["",
|
|
33089
|
+
return ["", chalk229.bold.underline(heading2), ...checks2.map(formatCheck)];
|
|
33086
33090
|
}
|
|
33087
33091
|
function formatHighLevelChecklist(checks2) {
|
|
33088
33092
|
const deterministic = checks2.filter(
|
|
@@ -33091,7 +33095,7 @@ function formatHighLevelChecklist(checks2) {
|
|
|
33091
33095
|
const failed3 = deterministic.filter(
|
|
33092
33096
|
(check2) => check2.status === "fail"
|
|
33093
33097
|
).length;
|
|
33094
|
-
const summary = failed3 === 0 ?
|
|
33098
|
+
const summary = failed3 === 0 ? chalk229.green(`All ${deterministic.length} deterministic checks pass`) : chalk229.red(
|
|
33095
33099
|
`${failed3} of ${deterministic.length} deterministic checks fail`
|
|
33096
33100
|
);
|
|
33097
33101
|
return [
|
|
@@ -33106,30 +33110,30 @@ function formatHighLevelChecklist(checks2) {
|
|
|
33106
33110
|
}
|
|
33107
33111
|
|
|
33108
33112
|
// src/commands/review/highLevel/formatHighLevelStructure.ts
|
|
33109
|
-
import
|
|
33113
|
+
import chalk230 from "chalk";
|
|
33110
33114
|
var STATUS_MARKERS = {
|
|
33111
|
-
added: () =>
|
|
33112
|
-
removed: () =>
|
|
33113
|
-
modified: () =>
|
|
33115
|
+
added: () => chalk230.green("A"),
|
|
33116
|
+
removed: () => chalk230.red("D"),
|
|
33117
|
+
modified: () => chalk230.yellow("M")
|
|
33114
33118
|
};
|
|
33115
33119
|
function counts(additions, deletions) {
|
|
33116
|
-
return `${
|
|
33120
|
+
return `${chalk230.green(`+${additions}`)} ${chalk230.red(`-${deletions}`)}`;
|
|
33117
33121
|
}
|
|
33118
33122
|
function formatNode(node, indent3) {
|
|
33119
33123
|
if (node.kind === "file")
|
|
33120
33124
|
return [
|
|
33121
|
-
`${indent3}${STATUS_MARKERS[node.status]()} ${node.name} ${
|
|
33125
|
+
`${indent3}${STATUS_MARKERS[node.status]()} ${node.name} ${chalk230.dim(counts(node.additions, node.deletions))}`
|
|
33122
33126
|
];
|
|
33123
33127
|
const dir = node;
|
|
33124
33128
|
return [
|
|
33125
|
-
`${indent3}${
|
|
33129
|
+
`${indent3}${chalk230.bold(`${dir.name}/`)} ${chalk230.dim(counts(dir.additions, dir.deletions))}`,
|
|
33126
33130
|
...dir.children.flatMap((child) => formatNode(child, `${indent3} `))
|
|
33127
33131
|
];
|
|
33128
33132
|
}
|
|
33129
33133
|
function formatHighLevelStructure(structure) {
|
|
33130
33134
|
const summary = `${structure.added} added \xB7 ${structure.removed} deleted \xB7 ${structure.modified} modified \xB7 ${counts(structure.additions, structure.deletions)}`;
|
|
33131
33135
|
return [
|
|
33132
|
-
|
|
33136
|
+
chalk230.bold.underline("Structure"),
|
|
33133
33137
|
` ${summary}`,
|
|
33134
33138
|
...structure.tree.flatMap((node) => formatNode(node, " "))
|
|
33135
33139
|
].join("\n");
|
|
@@ -33138,10 +33142,10 @@ function formatHighLevelStructure(structure) {
|
|
|
33138
33142
|
// src/commands/review/highLevel/printHighLevelChecklist.ts
|
|
33139
33143
|
function printHighLevelChecklist(subject) {
|
|
33140
33144
|
console.log(
|
|
33141
|
-
|
|
33145
|
+
chalk231.bold(
|
|
33142
33146
|
`High-level review of ${subject.repo}#${subject.prNumber} \u2014 ${subject.title}`
|
|
33143
33147
|
),
|
|
33144
|
-
|
|
33148
|
+
chalk231.dim(
|
|
33145
33149
|
`\xB7 ${highLevelChangedFileCount(subject.structure)} changed files`
|
|
33146
33150
|
)
|
|
33147
33151
|
);
|
|
@@ -33153,12 +33157,12 @@ function printHighLevelChecklist(subject) {
|
|
|
33153
33157
|
formatCriticalDiffs(subject.criticalDiffs, subject.criticalPaths)
|
|
33154
33158
|
);
|
|
33155
33159
|
console.log(
|
|
33156
|
-
|
|
33160
|
+
chalk231.dim(
|
|
33157
33161
|
"\nManual items are for the reviewer to judge; see docs/high-level-review.md."
|
|
33158
33162
|
)
|
|
33159
33163
|
);
|
|
33160
33164
|
console.log(
|
|
33161
|
-
|
|
33165
|
+
chalk231.dim(
|
|
33162
33166
|
"Run this inside an assist session to step through the checklist in the web overlay."
|
|
33163
33167
|
)
|
|
33164
33168
|
);
|
|
@@ -33792,18 +33796,18 @@ function partitionFindingsByDiff(findings, index3) {
|
|
|
33792
33796
|
}
|
|
33793
33797
|
|
|
33794
33798
|
// src/commands/review/warnOutOfDiff.ts
|
|
33795
|
-
import
|
|
33799
|
+
import chalk232 from "chalk";
|
|
33796
33800
|
function warnOutOfDiff(outOfDiff) {
|
|
33797
33801
|
if (outOfDiff.length === 0) return;
|
|
33798
33802
|
console.warn(
|
|
33799
|
-
|
|
33803
|
+
chalk232.yellow(
|
|
33800
33804
|
`Moved ${outOfDiff.length} finding(s) whose lines fall outside the PR diff into the review body (GitHub cannot anchor a comment on these):`
|
|
33801
33805
|
)
|
|
33802
33806
|
);
|
|
33803
33807
|
for (const finding of outOfDiff) {
|
|
33804
33808
|
const range = finding.startLine !== void 0 ? `${finding.startLine}-${finding.line}` : `${finding.line}`;
|
|
33805
33809
|
console.warn(
|
|
33806
|
-
` ${
|
|
33810
|
+
` ${chalk232.yellow("\xB7")} ${finding.title} ${chalk232.dim(
|
|
33807
33811
|
`(${finding.file}:${range})`
|
|
33808
33812
|
)}`
|
|
33809
33813
|
);
|
|
@@ -33827,18 +33831,18 @@ function selectInDiffFindings(lineBound, prDiff) {
|
|
|
33827
33831
|
}
|
|
33828
33832
|
|
|
33829
33833
|
// src/commands/review/warnUnlocated.ts
|
|
33830
|
-
import
|
|
33834
|
+
import chalk233 from "chalk";
|
|
33831
33835
|
function warnUnlocated(unlocated) {
|
|
33832
33836
|
if (unlocated.length === 0) return;
|
|
33833
33837
|
console.warn(
|
|
33834
|
-
|
|
33838
|
+
chalk233.yellow(
|
|
33835
33839
|
`Moved ${unlocated.length} finding(s) without a parseable file:line into the review body:`
|
|
33836
33840
|
)
|
|
33837
33841
|
);
|
|
33838
33842
|
for (const finding of unlocated) {
|
|
33839
|
-
const where = finding.location ||
|
|
33843
|
+
const where = finding.location || chalk233.dim("missing");
|
|
33840
33844
|
console.warn(
|
|
33841
|
-
` ${
|
|
33845
|
+
` ${chalk233.yellow("\xB7")} ${finding.title} ${chalk233.dim(`(${where})`)}`
|
|
33842
33846
|
);
|
|
33843
33847
|
}
|
|
33844
33848
|
}
|
|
@@ -35283,7 +35287,7 @@ function registerReview(program2) {
|
|
|
35283
35287
|
// src/commands/rules/addRule.ts
|
|
35284
35288
|
import { existsSync as existsSync70, readFileSync as readFileSync53, writeFileSync as writeFileSync43 } from "fs";
|
|
35285
35289
|
import path85 from "path";
|
|
35286
|
-
import
|
|
35290
|
+
import chalk234 from "chalk";
|
|
35287
35291
|
|
|
35288
35292
|
// src/commands/rules/insertRuleBullet.ts
|
|
35289
35293
|
function ruleBullet({ code, title, text: text18 }) {
|
|
@@ -35419,7 +35423,7 @@ function read2(file) {
|
|
|
35419
35423
|
function addRule(text18, options2) {
|
|
35420
35424
|
const rule = text18.trim();
|
|
35421
35425
|
if (rule === "") {
|
|
35422
|
-
console.error(
|
|
35426
|
+
console.error(chalk234.red("Rule text is required"));
|
|
35423
35427
|
process.exitCode = 1;
|
|
35424
35428
|
return;
|
|
35425
35429
|
}
|
|
@@ -35437,13 +35441,13 @@ function addRule(text18, options2) {
|
|
|
35437
35441
|
);
|
|
35438
35442
|
updateScopedRulesIndex(root2);
|
|
35439
35443
|
console.log(
|
|
35440
|
-
`Added ${
|
|
35444
|
+
`Added ${chalk234.cyan(code)} to ${path85.relative(process.cwd(), target) || target}`
|
|
35441
35445
|
);
|
|
35442
35446
|
}
|
|
35443
35447
|
|
|
35444
35448
|
// src/commands/rules/indexRules.ts
|
|
35445
35449
|
import path86 from "path";
|
|
35446
|
-
import
|
|
35450
|
+
import chalk235 from "chalk";
|
|
35447
35451
|
function indexRules() {
|
|
35448
35452
|
const startDir = scopeDirectory(process.cwd());
|
|
35449
35453
|
const root2 = findRepoRoot(startDir) ?? startDir;
|
|
@@ -35451,24 +35455,24 @@ function indexRules() {
|
|
|
35451
35455
|
const rootFile = path86.relative(process.cwd(), path86.join(root2, "CLAUDE.md"));
|
|
35452
35456
|
if (directories.length === 0) {
|
|
35453
35457
|
console.log(
|
|
35454
|
-
|
|
35458
|
+
chalk235.gray(`No directories carry their own \`## Rules\` under ${root2}`)
|
|
35455
35459
|
);
|
|
35456
35460
|
return;
|
|
35457
35461
|
}
|
|
35458
35462
|
console.log(`Recorded in ${rootFile || "CLAUDE.md"}`);
|
|
35459
35463
|
for (const directory of directories)
|
|
35460
|
-
console.log(` ${
|
|
35464
|
+
console.log(` ${chalk235.cyan(directory)}`);
|
|
35461
35465
|
}
|
|
35462
35466
|
|
|
35463
35467
|
// src/commands/rules/listRules.ts
|
|
35464
35468
|
import path87 from "path";
|
|
35465
|
-
import
|
|
35469
|
+
import chalk236 from "chalk";
|
|
35466
35470
|
function listRules(target, options2 = {}) {
|
|
35467
35471
|
const resolved = path87.resolve(target ?? process.cwd());
|
|
35468
35472
|
const rules3 = readScopedRules(resolved);
|
|
35469
35473
|
if (rules3.length === 0) {
|
|
35470
35474
|
const label2 = path87.relative(process.cwd(), resolved) || ".";
|
|
35471
|
-
console.log(
|
|
35475
|
+
console.log(chalk236.gray(`No rules in scope for ${label2}`));
|
|
35472
35476
|
return;
|
|
35473
35477
|
}
|
|
35474
35478
|
const base = findRepoRoot(scopeDirectory(resolved));
|
|
@@ -35478,14 +35482,14 @@ function listRules(target, options2 = {}) {
|
|
|
35478
35482
|
if (rule.source !== shown) {
|
|
35479
35483
|
shown = rule.source;
|
|
35480
35484
|
console.log(
|
|
35481
|
-
|
|
35485
|
+
chalk236.dim(base ? path87.relative(base, rule.source) : rule.source)
|
|
35482
35486
|
);
|
|
35483
35487
|
}
|
|
35484
35488
|
console.log(
|
|
35485
|
-
` ${
|
|
35489
|
+
` ${chalk236.cyan(rule.code.padEnd(width))} ${rule.title ?? rule.text}`
|
|
35486
35490
|
);
|
|
35487
35491
|
if (options2.full && rule.title)
|
|
35488
|
-
console.log(` ${" ".repeat(width)} ${
|
|
35492
|
+
console.log(` ${" ".repeat(width)} ${chalk236.dim(rule.text)}`);
|
|
35489
35493
|
}
|
|
35490
35494
|
}
|
|
35491
35495
|
|
|
@@ -35514,7 +35518,7 @@ function registerRules(program2) {
|
|
|
35514
35518
|
}
|
|
35515
35519
|
|
|
35516
35520
|
// src/commands/seq/seqAuth.ts
|
|
35517
|
-
import
|
|
35521
|
+
import chalk238 from "chalk";
|
|
35518
35522
|
|
|
35519
35523
|
// src/commands/seq/loadConnections.ts
|
|
35520
35524
|
function loadConnections2() {
|
|
@@ -35543,10 +35547,10 @@ function setDefaultConnection(name) {
|
|
|
35543
35547
|
}
|
|
35544
35548
|
|
|
35545
35549
|
// src/shared/assertUniqueName.ts
|
|
35546
|
-
import
|
|
35550
|
+
import chalk237 from "chalk";
|
|
35547
35551
|
function assertUniqueName(existingNames, name) {
|
|
35548
35552
|
if (existingNames.includes(name)) {
|
|
35549
|
-
console.error(
|
|
35553
|
+
console.error(chalk237.red(`Connection "${name}" already exists.`));
|
|
35550
35554
|
process.exit(1);
|
|
35551
35555
|
}
|
|
35552
35556
|
}
|
|
@@ -35564,16 +35568,16 @@ async function promptConnection2(existingNames) {
|
|
|
35564
35568
|
var seqAuth = createConnectionAuth({
|
|
35565
35569
|
load: loadConnections2,
|
|
35566
35570
|
save: saveConnections2,
|
|
35567
|
-
format: (c) => `${
|
|
35571
|
+
format: (c) => `${chalk238.bold(c.name)} ${c.url}`,
|
|
35568
35572
|
promptNew: promptConnection2,
|
|
35569
35573
|
onFirst: (c) => setDefaultConnection(c.name)
|
|
35570
35574
|
});
|
|
35571
35575
|
|
|
35572
35576
|
// src/commands/seq/seqQuery.ts
|
|
35573
|
-
import
|
|
35577
|
+
import chalk242 from "chalk";
|
|
35574
35578
|
|
|
35575
35579
|
// src/commands/seq/fetchSeq.ts
|
|
35576
|
-
import
|
|
35580
|
+
import chalk239 from "chalk";
|
|
35577
35581
|
async function fetchSeq(conn, path106, params) {
|
|
35578
35582
|
const url = `${conn.url}${path106}?${params}`;
|
|
35579
35583
|
const response = await fetch(url, {
|
|
@@ -35584,7 +35588,7 @@ async function fetchSeq(conn, path106, params) {
|
|
|
35584
35588
|
});
|
|
35585
35589
|
if (!response.ok) {
|
|
35586
35590
|
const body = await response.text();
|
|
35587
|
-
console.error(
|
|
35591
|
+
console.error(chalk239.red(`Seq returned ${response.status}: ${body}`));
|
|
35588
35592
|
process.exit(1);
|
|
35589
35593
|
}
|
|
35590
35594
|
return response;
|
|
@@ -35643,23 +35647,23 @@ async function fetchSeqEvents(conn, params) {
|
|
|
35643
35647
|
}
|
|
35644
35648
|
|
|
35645
35649
|
// src/commands/seq/formatEvent.ts
|
|
35646
|
-
import
|
|
35650
|
+
import chalk240 from "chalk";
|
|
35647
35651
|
function levelColor(level) {
|
|
35648
35652
|
switch (level) {
|
|
35649
35653
|
case "Fatal":
|
|
35650
|
-
return
|
|
35654
|
+
return chalk240.bgRed.white;
|
|
35651
35655
|
case "Error":
|
|
35652
|
-
return
|
|
35656
|
+
return chalk240.red;
|
|
35653
35657
|
case "Warning":
|
|
35654
|
-
return
|
|
35658
|
+
return chalk240.yellow;
|
|
35655
35659
|
case "Information":
|
|
35656
|
-
return
|
|
35660
|
+
return chalk240.cyan;
|
|
35657
35661
|
case "Debug":
|
|
35658
|
-
return
|
|
35662
|
+
return chalk240.gray;
|
|
35659
35663
|
case "Verbose":
|
|
35660
|
-
return
|
|
35664
|
+
return chalk240.dim;
|
|
35661
35665
|
default:
|
|
35662
|
-
return
|
|
35666
|
+
return chalk240.white;
|
|
35663
35667
|
}
|
|
35664
35668
|
}
|
|
35665
35669
|
function levelAbbrev(level) {
|
|
@@ -35700,12 +35704,12 @@ function formatTimestamp(iso) {
|
|
|
35700
35704
|
function formatEvent(event) {
|
|
35701
35705
|
const color = levelColor(event.Level);
|
|
35702
35706
|
const abbrev = levelAbbrev(event.Level);
|
|
35703
|
-
const ts10 =
|
|
35707
|
+
const ts10 = chalk240.dim(formatTimestamp(event.Timestamp));
|
|
35704
35708
|
const msg = renderMessage(event);
|
|
35705
35709
|
const lines2 = [`${ts10} ${color(`[${abbrev}]`)} ${msg}`];
|
|
35706
35710
|
if (event.Exception) {
|
|
35707
35711
|
for (const line of event.Exception.split("\n")) {
|
|
35708
|
-
lines2.push(
|
|
35712
|
+
lines2.push(chalk240.red(` ${line}`));
|
|
35709
35713
|
}
|
|
35710
35714
|
}
|
|
35711
35715
|
return lines2.join("\n");
|
|
@@ -35738,11 +35742,11 @@ function rejectTimestampFilter(filter) {
|
|
|
35738
35742
|
}
|
|
35739
35743
|
|
|
35740
35744
|
// src/shared/resolveNamedConnection.ts
|
|
35741
|
-
import
|
|
35745
|
+
import chalk241 from "chalk";
|
|
35742
35746
|
function resolveNamedConnection(connections, requested, defaultName, kind, authCommand) {
|
|
35743
35747
|
if (connections.length === 0) {
|
|
35744
35748
|
console.error(
|
|
35745
|
-
|
|
35749
|
+
chalk241.red(
|
|
35746
35750
|
`No ${kind} connections configured. Run '${authCommand}' first.`
|
|
35747
35751
|
)
|
|
35748
35752
|
);
|
|
@@ -35751,7 +35755,7 @@ function resolveNamedConnection(connections, requested, defaultName, kind, authC
|
|
|
35751
35755
|
const target = requested ?? defaultName ?? connections[0].name;
|
|
35752
35756
|
const connection = connections.find((c) => c.name === target);
|
|
35753
35757
|
if (!connection) {
|
|
35754
|
-
console.error(
|
|
35758
|
+
console.error(chalk241.red(`${kind} connection "${target}" not found.`));
|
|
35755
35759
|
process.exit(1);
|
|
35756
35760
|
}
|
|
35757
35761
|
return connection;
|
|
@@ -35780,7 +35784,7 @@ async function seqQuery(filter, options2) {
|
|
|
35780
35784
|
new URLSearchParams({ filter, count: String(count8) })
|
|
35781
35785
|
);
|
|
35782
35786
|
if (events.length === 0) {
|
|
35783
|
-
console.log(
|
|
35787
|
+
console.log(chalk242.yellow("No events found."));
|
|
35784
35788
|
return;
|
|
35785
35789
|
}
|
|
35786
35790
|
if (options2.json) {
|
|
@@ -35791,11 +35795,11 @@ async function seqQuery(filter, options2) {
|
|
|
35791
35795
|
for (const event of chronological) {
|
|
35792
35796
|
console.log(formatEvent(event));
|
|
35793
35797
|
}
|
|
35794
|
-
console.log(
|
|
35798
|
+
console.log(chalk242.dim(`
|
|
35795
35799
|
${events.length} events`));
|
|
35796
35800
|
if (events.length >= count8) {
|
|
35797
35801
|
console.log(
|
|
35798
|
-
|
|
35802
|
+
chalk242.yellow(
|
|
35799
35803
|
`Results limited to ${count8}. Use --count to retrieve more.`
|
|
35800
35804
|
)
|
|
35801
35805
|
);
|
|
@@ -35803,10 +35807,10 @@ ${events.length} events`));
|
|
|
35803
35807
|
}
|
|
35804
35808
|
|
|
35805
35809
|
// src/shared/setNamedDefaultConnection.ts
|
|
35806
|
-
import
|
|
35810
|
+
import chalk243 from "chalk";
|
|
35807
35811
|
function setNamedDefaultConnection(connections, name, setDefault, kind) {
|
|
35808
35812
|
if (!connections.find((c) => c.name === name)) {
|
|
35809
|
-
console.error(
|
|
35813
|
+
console.error(chalk243.red(`Connection "${name}" not found.`));
|
|
35810
35814
|
process.exit(1);
|
|
35811
35815
|
}
|
|
35812
35816
|
setDefault(name);
|
|
@@ -36027,7 +36031,7 @@ function registerSlack(program2) {
|
|
|
36027
36031
|
}
|
|
36028
36032
|
|
|
36029
36033
|
// src/commands/sql/sqlAuth.ts
|
|
36030
|
-
import
|
|
36034
|
+
import chalk245 from "chalk";
|
|
36031
36035
|
|
|
36032
36036
|
// src/commands/sql/loadConnections.ts
|
|
36033
36037
|
function loadConnections3() {
|
|
@@ -36056,7 +36060,7 @@ function setDefaultConnection2(name) {
|
|
|
36056
36060
|
}
|
|
36057
36061
|
|
|
36058
36062
|
// src/commands/sql/promptConnection.ts
|
|
36059
|
-
import
|
|
36063
|
+
import chalk244 from "chalk";
|
|
36060
36064
|
async function promptConnection3(existingNames) {
|
|
36061
36065
|
const name = await promptInput("name", "Connection name:", "default");
|
|
36062
36066
|
assertUniqueName(existingNames, name);
|
|
@@ -36064,7 +36068,7 @@ async function promptConnection3(existingNames) {
|
|
|
36064
36068
|
const portStr = await promptInput("port", "Port:", "1433");
|
|
36065
36069
|
const port = Number.parseInt(portStr, 10);
|
|
36066
36070
|
if (!Number.isFinite(port)) {
|
|
36067
|
-
console.error(
|
|
36071
|
+
console.error(chalk244.red(`Invalid port "${portStr}".`));
|
|
36068
36072
|
process.exit(1);
|
|
36069
36073
|
}
|
|
36070
36074
|
const user = await promptInput("user", "User:");
|
|
@@ -36077,13 +36081,13 @@ async function promptConnection3(existingNames) {
|
|
|
36077
36081
|
var sqlAuth = createConnectionAuth({
|
|
36078
36082
|
load: loadConnections3,
|
|
36079
36083
|
save: saveConnections3,
|
|
36080
|
-
format: (c) => `${
|
|
36084
|
+
format: (c) => `${chalk245.bold(c.name)} ${c.server}:${c.port}/${c.database} (${c.user})`,
|
|
36081
36085
|
promptNew: promptConnection3,
|
|
36082
36086
|
onFirst: (c) => setDefaultConnection2(c.name)
|
|
36083
36087
|
});
|
|
36084
36088
|
|
|
36085
36089
|
// src/commands/sql/printTable.ts
|
|
36086
|
-
import
|
|
36090
|
+
import chalk246 from "chalk";
|
|
36087
36091
|
function formatCell(value) {
|
|
36088
36092
|
if (value === null || value === void 0) return "";
|
|
36089
36093
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -36092,7 +36096,7 @@ function formatCell(value) {
|
|
|
36092
36096
|
}
|
|
36093
36097
|
function printTable(rows) {
|
|
36094
36098
|
if (rows.length === 0) {
|
|
36095
|
-
console.log(
|
|
36099
|
+
console.log(chalk246.yellow("(no rows)"));
|
|
36096
36100
|
return;
|
|
36097
36101
|
}
|
|
36098
36102
|
const columns = Object.keys(rows[0]);
|
|
@@ -36100,13 +36104,13 @@ function printTable(rows) {
|
|
|
36100
36104
|
(col) => Math.max(col.length, ...rows.map((r) => formatCell(r[col]).length))
|
|
36101
36105
|
);
|
|
36102
36106
|
const header = columns.map((c, i) => c.padEnd(widths[i])).join(" ");
|
|
36103
|
-
console.log(
|
|
36104
|
-
console.log(
|
|
36107
|
+
console.log(chalk246.dim(header));
|
|
36108
|
+
console.log(chalk246.dim("-".repeat(header.length)));
|
|
36105
36109
|
for (const row of rows) {
|
|
36106
36110
|
const line = columns.map((c, i) => formatCell(row[c]).padEnd(widths[i])).join(" ");
|
|
36107
36111
|
console.log(line);
|
|
36108
36112
|
}
|
|
36109
|
-
console.log(
|
|
36113
|
+
console.log(chalk246.dim(`
|
|
36110
36114
|
${rows.length} row${rows.length === 1 ? "" : "s"}`));
|
|
36111
36115
|
}
|
|
36112
36116
|
|
|
@@ -36166,7 +36170,7 @@ async function sqlColumns(table, connectionName) {
|
|
|
36166
36170
|
}
|
|
36167
36171
|
|
|
36168
36172
|
// src/commands/sql/sqlMutate.ts
|
|
36169
|
-
import
|
|
36173
|
+
import chalk247 from "chalk";
|
|
36170
36174
|
|
|
36171
36175
|
// src/commands/sql/isMutation.ts
|
|
36172
36176
|
var MUTATION_KEYWORDS = [
|
|
@@ -36200,7 +36204,7 @@ function isMutation(sql29) {
|
|
|
36200
36204
|
async function sqlMutate(query, connectionName) {
|
|
36201
36205
|
if (!isMutation(query)) {
|
|
36202
36206
|
console.error(
|
|
36203
|
-
|
|
36207
|
+
chalk247.red(
|
|
36204
36208
|
"assist sql mutate refuses non-mutating statements. Use `assist sql query` instead."
|
|
36205
36209
|
)
|
|
36206
36210
|
);
|
|
@@ -36210,18 +36214,18 @@ async function sqlMutate(query, connectionName) {
|
|
|
36210
36214
|
const pool = await sqlConnect(conn);
|
|
36211
36215
|
try {
|
|
36212
36216
|
const result = await pool.request().query(query);
|
|
36213
|
-
console.log(
|
|
36217
|
+
console.log(chalk247.dim(`${result.rowsAffected.join(", ")} row(s) affected`));
|
|
36214
36218
|
} finally {
|
|
36215
36219
|
await pool.close();
|
|
36216
36220
|
}
|
|
36217
36221
|
}
|
|
36218
36222
|
|
|
36219
36223
|
// src/commands/sql/sqlQuery.ts
|
|
36220
|
-
import
|
|
36224
|
+
import chalk248 from "chalk";
|
|
36221
36225
|
async function sqlQuery(query, connectionName) {
|
|
36222
36226
|
if (isMutation(query)) {
|
|
36223
36227
|
console.error(
|
|
36224
|
-
|
|
36228
|
+
chalk248.red(
|
|
36225
36229
|
"assist sql query refuses mutating statements. Use `assist sql mutate` instead."
|
|
36226
36230
|
)
|
|
36227
36231
|
);
|
|
@@ -36236,7 +36240,7 @@ async function sqlQuery(query, connectionName) {
|
|
|
36236
36240
|
printTable(rows);
|
|
36237
36241
|
} else {
|
|
36238
36242
|
console.log(
|
|
36239
|
-
|
|
36243
|
+
chalk248.dim(`${result.rowsAffected.join(", ")} row(s) affected`)
|
|
36240
36244
|
);
|
|
36241
36245
|
}
|
|
36242
36246
|
} finally {
|
|
@@ -36653,7 +36657,7 @@ function syncPi(claudeDir, options2) {
|
|
|
36653
36657
|
// src/commands/sync/syncSettings.ts
|
|
36654
36658
|
import * as fs47 from "fs";
|
|
36655
36659
|
import * as path98 from "path";
|
|
36656
|
-
import
|
|
36660
|
+
import chalk249 from "chalk";
|
|
36657
36661
|
async function syncSettings(claudeDir, targetBase, options2) {
|
|
36658
36662
|
const source = path98.join(claudeDir, "settings.json");
|
|
36659
36663
|
const target = path98.join(targetBase, "settings.json");
|
|
@@ -36672,7 +36676,7 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
36672
36676
|
if (mergedContent !== normalizedTarget) {
|
|
36673
36677
|
if (!options2?.yes) {
|
|
36674
36678
|
console.log(
|
|
36675
|
-
|
|
36679
|
+
chalk249.yellow(
|
|
36676
36680
|
"\n\u26A0\uFE0F Warning: settings.json differs from existing file"
|
|
36677
36681
|
)
|
|
36678
36682
|
);
|
|
@@ -36680,7 +36684,7 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
36680
36684
|
printDiff(targetContent, mergedContent);
|
|
36681
36685
|
printAutoConfirmHint();
|
|
36682
36686
|
const confirm = await promptConfirm(
|
|
36683
|
-
|
|
36687
|
+
chalk249.red("Overwrite existing settings.json?"),
|
|
36684
36688
|
false
|
|
36685
36689
|
);
|
|
36686
36690
|
if (!confirm) {
|
|
@@ -39070,7 +39074,7 @@ function registerWatch(program2) {
|
|
|
39070
39074
|
|
|
39071
39075
|
// src/commands/roam/auth.ts
|
|
39072
39076
|
import { randomBytes } from "crypto";
|
|
39073
|
-
import
|
|
39077
|
+
import chalk250 from "chalk";
|
|
39074
39078
|
|
|
39075
39079
|
// src/commands/roam/waitForCallback.ts
|
|
39076
39080
|
import { createServer as createServer3 } from "http";
|
|
@@ -39201,13 +39205,13 @@ async function auth() {
|
|
|
39201
39205
|
saveGlobalConfig(config);
|
|
39202
39206
|
const state = randomBytes(16).toString("hex");
|
|
39203
39207
|
console.log(
|
|
39204
|
-
|
|
39208
|
+
chalk250.yellow("\nEnsure this Redirect URI is set in your Roam OAuth app:")
|
|
39205
39209
|
);
|
|
39206
|
-
console.log(
|
|
39207
|
-
console.log(
|
|
39208
|
-
console.log(
|
|
39210
|
+
console.log(chalk250.white("http://localhost:14523/callback\n"));
|
|
39211
|
+
console.log(chalk250.blue("Opening browser for authorization..."));
|
|
39212
|
+
console.log(chalk250.dim("Waiting for authorization callback..."));
|
|
39209
39213
|
const { code, redirectUri } = await authorizeInBrowser(clientId, state);
|
|
39210
|
-
console.log(
|
|
39214
|
+
console.log(chalk250.dim("Exchanging code for tokens..."));
|
|
39211
39215
|
const tokens = await exchangeToken({
|
|
39212
39216
|
code,
|
|
39213
39217
|
clientId,
|
|
@@ -39223,7 +39227,7 @@ async function auth() {
|
|
|
39223
39227
|
};
|
|
39224
39228
|
saveGlobalConfig(config);
|
|
39225
39229
|
console.log(
|
|
39226
|
-
|
|
39230
|
+
chalk250.green("Roam credentials and tokens saved to ~/.assist.yml")
|
|
39227
39231
|
);
|
|
39228
39232
|
}
|
|
39229
39233
|
|
|
@@ -39578,7 +39582,7 @@ function registerRun(program2) {
|
|
|
39578
39582
|
}
|
|
39579
39583
|
|
|
39580
39584
|
// src/commands/sessions/nodes/formatLink.ts
|
|
39581
|
-
import
|
|
39585
|
+
import chalk251 from "chalk";
|
|
39582
39586
|
|
|
39583
39587
|
// src/commands/sessions/daemon/links/describeTarget.ts
|
|
39584
39588
|
function describeTarget({ url, ssh }) {
|
|
@@ -39588,16 +39592,16 @@ function describeTarget({ url, ssh }) {
|
|
|
39588
39592
|
|
|
39589
39593
|
// src/commands/sessions/nodes/formatLink.ts
|
|
39590
39594
|
var STATE_COLOURS = {
|
|
39591
|
-
connected:
|
|
39592
|
-
connecting:
|
|
39593
|
-
disconnected:
|
|
39594
|
-
"version-blocked":
|
|
39595
|
+
connected: chalk251.green,
|
|
39596
|
+
connecting: chalk251.yellow,
|
|
39597
|
+
disconnected: chalk251.red,
|
|
39598
|
+
"version-blocked": chalk251.red
|
|
39595
39599
|
};
|
|
39596
39600
|
function formatLink(link3) {
|
|
39597
|
-
const colour = STATE_COLOURS[link3.state] ??
|
|
39601
|
+
const colour = STATE_COLOURS[link3.state] ?? chalk251.white;
|
|
39598
39602
|
const peer = link3.peerVersion ? ` peer ${link3.peerVersion}` : "";
|
|
39599
39603
|
const error = link3.error ? `
|
|
39600
|
-
${
|
|
39604
|
+
${chalk251.dim(`last error${link3.errorAt ? ` ${link3.errorAt}` : ""}: ${link3.error}`)}` : "";
|
|
39601
39605
|
return ` ${link3.name} ${colour(link3.state)} ${describeTarget(link3)}${peer}${error}`;
|
|
39602
39606
|
}
|
|
39603
39607
|
|
|
@@ -46345,7 +46349,7 @@ async function probeSshAgent(alias) {
|
|
|
46345
46349
|
}
|
|
46346
46350
|
|
|
46347
46351
|
// src/commands/sessions/nodes/printReport.ts
|
|
46348
|
-
import
|
|
46352
|
+
import chalk252 from "chalk";
|
|
46349
46353
|
function printReport(report2) {
|
|
46350
46354
|
if (report2.links.length === 0) {
|
|
46351
46355
|
console.log(`${report2.local} has no links`);
|
|
@@ -46359,11 +46363,11 @@ function printReport(report2) {
|
|
|
46359
46363
|
for (const diagnosis of report2.links) printDiagnosis(diagnosis);
|
|
46360
46364
|
}
|
|
46361
46365
|
function printDiagnosis(diagnosis) {
|
|
46362
|
-
console.log(`${
|
|
46366
|
+
console.log(`${chalk252.bold(diagnosis.name)} ${chalk252.dim(diagnosis.url)}`);
|
|
46363
46367
|
for (const hop of diagnosis.hops) {
|
|
46364
|
-
const mark = hop.ok ?
|
|
46368
|
+
const mark = hop.ok ? chalk252.green("\u2713") : chalk252.red("\u2717");
|
|
46365
46369
|
console.log(` ${mark} ${hop.hop.padEnd(6)} ${hop.detail ?? hop.error}`);
|
|
46366
|
-
if (hop.remediation) console.log(` ${
|
|
46370
|
+
if (hop.remediation) console.log(` ${chalk252.yellow(hop.remediation)}`);
|
|
46367
46371
|
}
|
|
46368
46372
|
}
|
|
46369
46373
|
|
|
@@ -46396,14 +46400,14 @@ async function doctorNodes(name, options2) {
|
|
|
46396
46400
|
}
|
|
46397
46401
|
|
|
46398
46402
|
// src/commands/sessions/nodes/linkNode.ts
|
|
46399
|
-
import
|
|
46403
|
+
import chalk254 from "chalk";
|
|
46400
46404
|
|
|
46401
46405
|
// src/commands/sessions/nodes/notifyDaemonLinks.ts
|
|
46402
|
-
import
|
|
46406
|
+
import chalk253 from "chalk";
|
|
46403
46407
|
async function notifyDaemonLinks() {
|
|
46404
46408
|
if (!await isDaemonRunning()) {
|
|
46405
46409
|
console.log(
|
|
46406
|
-
|
|
46410
|
+
chalk253.yellow(
|
|
46407
46411
|
"The sessions daemon is not running; it loads the links when it starts."
|
|
46408
46412
|
)
|
|
46409
46413
|
);
|
|
@@ -46411,11 +46415,11 @@ async function notifyDaemonLinks() {
|
|
|
46411
46415
|
}
|
|
46412
46416
|
try {
|
|
46413
46417
|
await sendToDaemonAwaitAck({ type: "reload-links" });
|
|
46414
|
-
console.log(
|
|
46418
|
+
console.log(chalk253.dim("The sessions daemon reloaded its links."));
|
|
46415
46419
|
} catch (error) {
|
|
46416
46420
|
const message3 = error instanceof Error ? error.message : String(error);
|
|
46417
46421
|
console.log(
|
|
46418
|
-
|
|
46422
|
+
chalk253.yellow(
|
|
46419
46423
|
`Could not notify the sessions daemon (${message3}); run \`assist daemon restart\` to apply the change.`
|
|
46420
46424
|
)
|
|
46421
46425
|
);
|
|
@@ -46475,13 +46479,13 @@ async function linkNode(name, url, options2) {
|
|
|
46475
46479
|
const link3 = buildLink(name, url, options2, others);
|
|
46476
46480
|
await writeLinks([...others, link3]);
|
|
46477
46481
|
console.log(
|
|
46478
|
-
|
|
46482
|
+
chalk254.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
|
|
46479
46483
|
);
|
|
46480
46484
|
await notifyDaemonLinks();
|
|
46481
46485
|
}
|
|
46482
46486
|
|
|
46483
46487
|
// src/commands/sessions/nodes/listNodes.ts
|
|
46484
|
-
import
|
|
46488
|
+
import chalk255 from "chalk";
|
|
46485
46489
|
async function nodesReport() {
|
|
46486
46490
|
const live = await queryNodes();
|
|
46487
46491
|
if (live)
|
|
@@ -46498,10 +46502,10 @@ async function listNodes(options2) {
|
|
|
46498
46502
|
console.log(JSON.stringify(report2, null, 2));
|
|
46499
46503
|
return;
|
|
46500
46504
|
}
|
|
46501
|
-
console.log(`${report2.local} ${
|
|
46505
|
+
console.log(`${report2.local} ${chalk255.dim("(this node)")}`);
|
|
46502
46506
|
if (!report2.daemonRunning)
|
|
46503
|
-
console.log(
|
|
46504
|
-
if (report2.links.length === 0) console.log(
|
|
46507
|
+
console.log(chalk255.dim(" daemon not running; showing configured links"));
|
|
46508
|
+
if (report2.links.length === 0) console.log(chalk255.dim(" no links"));
|
|
46505
46509
|
for (const link3 of report2.links) console.log(formatLink(link3));
|
|
46506
46510
|
}
|
|
46507
46511
|
|
|
@@ -46540,16 +46544,16 @@ async function nodeLogs(name, options2) {
|
|
|
46540
46544
|
}
|
|
46541
46545
|
|
|
46542
46546
|
// src/commands/sessions/nodes/unlinkNode.ts
|
|
46543
|
-
import
|
|
46547
|
+
import chalk256 from "chalk";
|
|
46544
46548
|
async function unlinkNode(name) {
|
|
46545
46549
|
const links2 = readLinks();
|
|
46546
46550
|
const remaining = links2.filter((link3) => link3.name !== name);
|
|
46547
46551
|
if (remaining.length === links2.length) {
|
|
46548
|
-
console.log(
|
|
46552
|
+
console.log(chalk256.yellow(`No link named ${name}`));
|
|
46549
46553
|
return;
|
|
46550
46554
|
}
|
|
46551
46555
|
await writeLinks(remaining);
|
|
46552
|
-
console.log(
|
|
46556
|
+
console.log(chalk256.green(`Unlinked ${name}`));
|
|
46553
46557
|
await notifyDaemonLinks();
|
|
46554
46558
|
}
|
|
46555
46559
|
|
|
@@ -46688,7 +46692,7 @@ async function renameSession(title) {
|
|
|
46688
46692
|
|
|
46689
46693
|
// src/commands/sessions/summarise.ts
|
|
46690
46694
|
import * as fs58 from "fs";
|
|
46691
|
-
import
|
|
46695
|
+
import chalk257 from "chalk";
|
|
46692
46696
|
|
|
46693
46697
|
// src/commands/sessions/summarise/shared.ts
|
|
46694
46698
|
import * as fs57 from "fs";
|
|
@@ -46747,22 +46751,22 @@ ${firstMessage}`);
|
|
|
46747
46751
|
async function summarise2(options2) {
|
|
46748
46752
|
const files = await discoverSessionFiles();
|
|
46749
46753
|
if (files.length === 0) {
|
|
46750
|
-
console.log(
|
|
46754
|
+
console.log(chalk257.yellow("No sessions found."));
|
|
46751
46755
|
return;
|
|
46752
46756
|
}
|
|
46753
46757
|
const toProcess = selectCandidates(files, options2);
|
|
46754
46758
|
if (toProcess.length === 0) {
|
|
46755
|
-
console.log(
|
|
46759
|
+
console.log(chalk257.green("All sessions already summarised."));
|
|
46756
46760
|
return;
|
|
46757
46761
|
}
|
|
46758
46762
|
console.log(
|
|
46759
|
-
|
|
46763
|
+
chalk257.cyan(
|
|
46760
46764
|
`Summarising ${toProcess.length} session(s) (${files.length} total)\u2026`
|
|
46761
46765
|
)
|
|
46762
46766
|
);
|
|
46763
46767
|
const { succeeded, failed: failed3 } = processSessions(toProcess);
|
|
46764
46768
|
console.log(
|
|
46765
|
-
|
|
46769
|
+
chalk257.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk257.yellow(`, ${failed3} skipped`) : "")
|
|
46766
46770
|
);
|
|
46767
46771
|
}
|
|
46768
46772
|
function selectCandidates(files, options2) {
|
|
@@ -46782,16 +46786,16 @@ function processSessions(files) {
|
|
|
46782
46786
|
let failed3 = 0;
|
|
46783
46787
|
for (let i = 0; i < files.length; i++) {
|
|
46784
46788
|
const file = files[i];
|
|
46785
|
-
process.stdout.write(
|
|
46789
|
+
process.stdout.write(chalk257.dim(` [${i + 1}/${files.length}] `));
|
|
46786
46790
|
const summary = summariseSession(file);
|
|
46787
46791
|
if (summary) {
|
|
46788
46792
|
writeSummary(file, summary);
|
|
46789
46793
|
succeeded++;
|
|
46790
|
-
process.stdout.write(`${
|
|
46794
|
+
process.stdout.write(`${chalk257.green("\u2713")} ${summary}
|
|
46791
46795
|
`);
|
|
46792
46796
|
} else {
|
|
46793
46797
|
failed3++;
|
|
46794
|
-
process.stdout.write(` ${
|
|
46798
|
+
process.stdout.write(` ${chalk257.yellow("skip")}
|
|
46795
46799
|
`);
|
|
46796
46800
|
}
|
|
46797
46801
|
}
|
|
@@ -46820,10 +46824,10 @@ function registerSessions(program2) {
|
|
|
46820
46824
|
}
|
|
46821
46825
|
|
|
46822
46826
|
// src/reportCliError.ts
|
|
46823
|
-
import
|
|
46827
|
+
import chalk258 from "chalk";
|
|
46824
46828
|
function reportCliError(error) {
|
|
46825
46829
|
if (error instanceof InvalidItemIdError || error instanceof AmbiguousRepoConfigError || error instanceof UnknownRepoConfigError || error instanceof MissingRunCwdError || error instanceof MiroExtractError) {
|
|
46826
|
-
console.error(
|
|
46830
|
+
console.error(chalk258.red(error.message));
|
|
46827
46831
|
} else {
|
|
46828
46832
|
console.error(error);
|
|
46829
46833
|
}
|