@staff0rd/assist 0.721.0 → 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 +358 -345
- 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,101 +31816,222 @@ 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
|
|
31925
|
-
|
|
31869
|
+
import chalk216 from "chalk";
|
|
31870
|
+
var shownMoves = 20;
|
|
31871
|
+
function displayDrift(plan2, listMoves) {
|
|
31926
31872
|
const rel = (file) => path73.relative(process.cwd(), file);
|
|
31927
31873
|
if (plan2.moves.length > 0) {
|
|
31928
|
-
console.log(
|
|
31929
|
-
|
|
31930
|
-
|
|
31874
|
+
console.log(
|
|
31875
|
+
chalk216.red(
|
|
31876
|
+
`${plan2.moves.length} file(s) drift from the plan${listMoves ? ":" : "."}`
|
|
31877
|
+
)
|
|
31878
|
+
);
|
|
31879
|
+
if (listMoves) {
|
|
31880
|
+
for (const move2 of plan2.moves.slice(0, shownMoves))
|
|
31881
|
+
console.log(` ${rel(move2.from)} \u2192 ${rel(move2.to)}`);
|
|
31882
|
+
if (plan2.moves.length > shownMoves)
|
|
31883
|
+
console.log(chalk216.dim(` \u2026and ${plan2.moves.length - shownMoves} more`));
|
|
31884
|
+
}
|
|
31931
31885
|
}
|
|
31932
|
-
for (const error of plan2.errors) console.log(
|
|
31886
|
+
for (const error of plan2.errors) console.log(chalk216.red(error));
|
|
31933
31887
|
}
|
|
31934
31888
|
|
|
31935
31889
|
// src/commands/refactor/restructure/checkPlan.ts
|
|
31936
|
-
function applyCommand(plan2) {
|
|
31937
|
-
const root2 = path74.relative(process.cwd(), plan2.scopeRoot) || ".";
|
|
31938
|
-
return `assist refactor restructure ${root2} --apply`;
|
|
31939
|
-
}
|
|
31940
31890
|
function checkPlan(plan2, chains, maxDepth) {
|
|
31941
|
-
|
|
31942
|
-
|
|
31943
|
-
|
|
31891
|
+
const apply = applyCommand(plan2.scopeRoot);
|
|
31892
|
+
displayDrift(plan2, 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) {
|
|
31944
31896
|
console.log(
|
|
31945
|
-
|
|
31897
|
+
chalk217.yellow(
|
|
31946
31898
|
`
|
|
31947
|
-
|
|
31899
|
+
Run \`${apply}\` to move the files and rewrite their imports.`
|
|
31948
31900
|
)
|
|
31949
31901
|
);
|
|
31950
31902
|
process.exit(1);
|
|
31951
31903
|
}
|
|
31952
|
-
|
|
31953
|
-
|
|
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);
|
|
31954
31982
|
console.log(
|
|
31955
|
-
|
|
31956
|
-
`
|
|
31957
|
-
Run \`${applyCommand(plan2)}\` to move the files and rewrite their imports.`
|
|
31958
|
-
)
|
|
31983
|
+
chalk218.white(` Moved ${relPath(move2.from)} \u2192 ${relPath(move2.to)}`)
|
|
31959
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."));
|
|
31960
32016
|
process.exit(1);
|
|
31961
32017
|
}
|
|
31962
|
-
console.log(chalk219.
|
|
32018
|
+
console.log(chalk219.bold("\nApplying changes..."));
|
|
32019
|
+
executePlan(plan2);
|
|
32020
|
+
console.log(chalk219.green("\nRestructuring complete"));
|
|
31963
32021
|
}
|
|
31964
32022
|
|
|
31965
32023
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
31966
|
-
import
|
|
32024
|
+
import path79 from "path";
|
|
31967
32025
|
import chalk220 from "chalk";
|
|
31968
32026
|
|
|
31969
32027
|
// src/commands/refactor/restructure/computeDepthStats.ts
|
|
31970
|
-
import
|
|
32028
|
+
import path77 from "path";
|
|
31971
32029
|
function computeDepthStats(targets, scopeRoot) {
|
|
31972
32030
|
const distribution = /* @__PURE__ */ new Map();
|
|
31973
32031
|
let max = 0;
|
|
31974
32032
|
for (const target of targets) {
|
|
31975
|
-
const dir =
|
|
31976
|
-
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;
|
|
31977
32035
|
distribution.set(depth, (distribution.get(depth) ?? 0) + 1);
|
|
31978
32036
|
max = Math.max(max, depth);
|
|
31979
32037
|
}
|
|
@@ -31981,7 +32039,7 @@ function computeDepthStats(targets, scopeRoot) {
|
|
|
31981
32039
|
}
|
|
31982
32040
|
|
|
31983
32041
|
// src/commands/refactor/restructure/formatTree.ts
|
|
31984
|
-
import
|
|
32042
|
+
import path78 from "path";
|
|
31985
32043
|
function insert(root2, parts) {
|
|
31986
32044
|
let node = root2;
|
|
31987
32045
|
for (const part of parts) {
|
|
@@ -32003,7 +32061,7 @@ function render(node, indent3, lines2) {
|
|
|
32003
32061
|
function formatTree(files, scopeRoot) {
|
|
32004
32062
|
const root2 = /* @__PURE__ */ new Map();
|
|
32005
32063
|
for (const file of files)
|
|
32006
|
-
insert(root2,
|
|
32064
|
+
insert(root2, path78.relative(scopeRoot, file).split(path78.sep));
|
|
32007
32065
|
const lines2 = [];
|
|
32008
32066
|
render(root2, "", lines2);
|
|
32009
32067
|
return lines2;
|
|
@@ -32011,7 +32069,7 @@ function formatTree(files, scopeRoot) {
|
|
|
32011
32069
|
|
|
32012
32070
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
32013
32071
|
function relPath2(filePath) {
|
|
32014
|
-
return
|
|
32072
|
+
return path79.relative(process.cwd(), filePath);
|
|
32015
32073
|
}
|
|
32016
32074
|
function displayMoves(plan2) {
|
|
32017
32075
|
if (plan2.moves.length === 0) return;
|
|
@@ -32060,85 +32118,40 @@ Summary: ${plan2.moves.length} file(s) moved, ${plan2.rewrites.length} imports r
|
|
|
32060
32118
|
);
|
|
32061
32119
|
}
|
|
32062
32120
|
|
|
32063
|
-
// src/commands/refactor/restructure/
|
|
32064
|
-
|
|
32065
|
-
|
|
32066
|
-
|
|
32067
|
-
|
|
32068
|
-
|
|
32069
|
-
|
|
32070
|
-
const counts2 = /* @__PURE__ */ new Map();
|
|
32071
|
-
for (const segments of segmentLists)
|
|
32072
|
-
for (let i = 1; i <= segments.length; i++) {
|
|
32073
|
-
const key = segments.slice(0, i).join("/");
|
|
32074
|
-
counts2.set(key, (counts2.get(key) ?? 0) + 1);
|
|
32075
|
-
}
|
|
32076
|
-
return counts2;
|
|
32077
|
-
}
|
|
32078
|
-
function findDeepChains(targets, scopeRoot, maxDepth) {
|
|
32079
|
-
const segmentLists = [...targets].map((t) => dirSegments(t, scopeRoot));
|
|
32080
|
-
const subtreeFiles = countSubtrees(segmentLists);
|
|
32081
|
-
const chains = /* @__PURE__ */ new Map();
|
|
32082
|
-
for (const segments of segmentLists) {
|
|
32083
|
-
if (segments.length <= maxDepth) continue;
|
|
32084
|
-
const head = segments.slice(0, maxDepth + 1);
|
|
32085
|
-
const key = head.join("/");
|
|
32086
|
-
const chain2 = chains.get(key) ?? {
|
|
32087
|
-
folders: head.map((name, i) => ({
|
|
32088
|
-
name,
|
|
32089
|
-
files: subtreeFiles.get(head.slice(0, i + 1).join("/")) ?? 0
|
|
32090
|
-
})),
|
|
32091
|
-
tooDeep: 0,
|
|
32092
|
-
deepest: 0
|
|
32093
|
-
};
|
|
32094
|
-
chain2.tooDeep += 1;
|
|
32095
|
-
chain2.deepest = Math.max(chain2.deepest, segments.length);
|
|
32096
|
-
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;
|
|
32097
32128
|
}
|
|
32098
|
-
|
|
32099
|
-
|
|
32100
|
-
|
|
32101
|
-
|
|
32102
|
-
|
|
32103
|
-
import { minimatch as minimatch4 } from "minimatch";
|
|
32104
|
-
function partitionIgnored(files) {
|
|
32105
|
-
const globs = loadConfig().restructure?.ignore ?? [];
|
|
32106
|
-
const isIgnored = (file) => globs.some((glob) => minimatch4(path79.relative(process.cwd(), file), glob));
|
|
32107
|
-
return {
|
|
32108
|
-
scoped: files.filter((f) => !isIgnored(f)),
|
|
32109
|
-
ignored: files.filter(isIgnored)
|
|
32110
|
-
};
|
|
32129
|
+
if (!apply) {
|
|
32130
|
+
console.log(chalk221.dim("\nDry run. Use --apply to execute."));
|
|
32131
|
+
return;
|
|
32132
|
+
}
|
|
32133
|
+
applyPlan(plan2);
|
|
32111
32134
|
}
|
|
32112
32135
|
|
|
32113
32136
|
// src/commands/refactor/restructure.ts
|
|
32114
32137
|
async function restructure(root2, options2 = {}) {
|
|
32115
32138
|
const scopeRoot = path80.resolve(root2 ?? "src");
|
|
32116
32139
|
if (!fs38.existsSync(scopeRoot) || !fs38.statSync(scopeRoot).isDirectory()) {
|
|
32117
|
-
console.log(
|
|
32140
|
+
console.log(chalk222.red(`Not a directory: ${root2 ?? "src"}`));
|
|
32118
32141
|
process.exit(1);
|
|
32119
32142
|
}
|
|
32120
32143
|
const found = [];
|
|
32121
32144
|
walkSourceFiles(scopeRoot, found);
|
|
32122
32145
|
const { scoped, ignored } = partitionIgnored(found);
|
|
32123
32146
|
if (scoped.length === 0) {
|
|
32124
|
-
console.log(
|
|
32147
|
+
console.log(chalk222.yellow("No files found under root"));
|
|
32125
32148
|
return;
|
|
32126
32149
|
}
|
|
32127
32150
|
const { pin: pin2 = [], maxDepth = 10 } = loadConfig().restructure ?? {};
|
|
32128
32151
|
const plan2 = buildPlan3(scopeRoot, scoped, ignored, pin2);
|
|
32129
32152
|
const chains = findDeepChains(plan2.targets.values(), scopeRoot, maxDepth);
|
|
32130
32153
|
if (options2.check) return checkPlan(plan2, chains, maxDepth);
|
|
32131
|
-
|
|
32132
|
-
displayDeepChains(chains, maxDepth);
|
|
32133
|
-
if (plan2.moves.length === 0 && plan2.errors.length === 0) {
|
|
32134
|
-
console.log(chalk221.green("No restructuring needed"));
|
|
32135
|
-
return;
|
|
32136
|
-
}
|
|
32137
|
-
if (!options2.apply) {
|
|
32138
|
-
console.log(chalk221.dim("\nDry run. Use --apply to execute."));
|
|
32139
|
-
return;
|
|
32140
|
-
}
|
|
32141
|
-
applyPlan(plan2);
|
|
32154
|
+
runPlan(plan2, chains, maxDepth, options2.apply === true);
|
|
32142
32155
|
}
|
|
32143
32156
|
|
|
32144
32157
|
// src/commands/registerRefactor.ts
|
|
@@ -32193,7 +32206,7 @@ async function checkoutOnlySession(number) {
|
|
|
32193
32206
|
}
|
|
32194
32207
|
|
|
32195
32208
|
// src/commands/review/highLevel/configureHighLevelReview.ts
|
|
32196
|
-
import
|
|
32209
|
+
import chalk226 from "chalk";
|
|
32197
32210
|
|
|
32198
32211
|
// src/commands/config/promptConfigScope.ts
|
|
32199
32212
|
import Enquirer3 from "enquirer";
|
|
@@ -32219,7 +32232,7 @@ async function promptConfigScope() {
|
|
|
32219
32232
|
}
|
|
32220
32233
|
|
|
32221
32234
|
// src/commands/config/resolveConfigKeyAnswer.ts
|
|
32222
|
-
import
|
|
32235
|
+
import chalk223 from "chalk";
|
|
32223
32236
|
async function resolveConfigKeyAnswer(question, supplied) {
|
|
32224
32237
|
if (supplied !== void 0) return coerceSupplied(question.key, supplied);
|
|
32225
32238
|
for (; ; ) {
|
|
@@ -32227,7 +32240,7 @@ async function resolveConfigKeyAnswer(question, supplied) {
|
|
|
32227
32240
|
if (answer === "") return void 0;
|
|
32228
32241
|
const coercion = coerceCliConfigValue(question.key, answer);
|
|
32229
32242
|
if (coercion.ok) return coercion.value;
|
|
32230
|
-
console.error(
|
|
32243
|
+
console.error(chalk223.red(coercion.error));
|
|
32231
32244
|
}
|
|
32232
32245
|
}
|
|
32233
32246
|
function coerceSupplied(key, supplied) {
|
|
@@ -32288,7 +32301,7 @@ function suggestGlobs(current, proposed) {
|
|
|
32288
32301
|
}
|
|
32289
32302
|
|
|
32290
32303
|
// src/commands/review/highLevel/parseConfigureAnswers.ts
|
|
32291
|
-
import
|
|
32304
|
+
import chalk224 from "chalk";
|
|
32292
32305
|
function parseConfigureAnswers(answers) {
|
|
32293
32306
|
const known = Object.values(highLevelConfigKeys);
|
|
32294
32307
|
const parsed = {};
|
|
@@ -32306,13 +32319,13 @@ function answersCoverEveryKey(answers) {
|
|
|
32306
32319
|
return Object.values(highLevelConfigKeys).every((key) => key in answers);
|
|
32307
32320
|
}
|
|
32308
32321
|
function exitWith(message3) {
|
|
32309
|
-
console.error(
|
|
32322
|
+
console.error(chalk224.red(`Error: ${message3}.`));
|
|
32310
32323
|
process.exit(1);
|
|
32311
32324
|
}
|
|
32312
32325
|
|
|
32313
32326
|
// src/commands/review/highLevel/proposeHighLevelGlobs.ts
|
|
32314
32327
|
import { execFileSync as execFileSync20 } from "child_process";
|
|
32315
|
-
import
|
|
32328
|
+
import chalk225 from "chalk";
|
|
32316
32329
|
|
|
32317
32330
|
// src/commands/review/highLevel/buildGlobProposalPrompt.ts
|
|
32318
32331
|
function buildGlobProposalPrompt(tree) {
|
|
@@ -32405,12 +32418,12 @@ function proposeHighLevelGlobs(cwd = process.cwd()) {
|
|
|
32405
32418
|
const tree = summariseRepoTree(cwd);
|
|
32406
32419
|
if (tree === "") return NOTHING_PROPOSED;
|
|
32407
32420
|
console.log(
|
|
32408
|
-
|
|
32421
|
+
chalk225.dim("Asking Claude to propose globs from the repo's own tree...")
|
|
32409
32422
|
);
|
|
32410
32423
|
const output = askClaude(buildGlobProposalPrompt(tree), cwd);
|
|
32411
32424
|
if (output === void 0) {
|
|
32412
32425
|
console.log(
|
|
32413
|
-
|
|
32426
|
+
chalk225.yellow(
|
|
32414
32427
|
"Claude proposed nothing; answer each key from its current value."
|
|
32415
32428
|
)
|
|
32416
32429
|
);
|
|
@@ -32466,25 +32479,25 @@ function asConfigKeyScope(value) {
|
|
|
32466
32479
|
function reportConfigured(result) {
|
|
32467
32480
|
for (const write of result.written)
|
|
32468
32481
|
console.log(
|
|
32469
|
-
|
|
32482
|
+
chalk226.green(`Set ${write.key} = ${JSON.stringify(write.value)}`)
|
|
32470
32483
|
);
|
|
32471
|
-
for (const key of result.skipped) console.log(
|
|
32472
|
-
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}`));
|
|
32473
32486
|
}
|
|
32474
32487
|
|
|
32475
32488
|
// src/commands/review/highLevel/announceSavedReview.ts
|
|
32476
|
-
import
|
|
32489
|
+
import chalk227 from "chalk";
|
|
32477
32490
|
function announceSavedReview(subject, force) {
|
|
32478
32491
|
const head = subject.headSha.slice(0, 7);
|
|
32479
32492
|
if (subject.saved)
|
|
32480
32493
|
console.log(
|
|
32481
|
-
|
|
32494
|
+
chalk227.dim(
|
|
32482
32495
|
`Reopening the review saved for ${head} at ${subject.saved.reviewedAt} (${subject.saved.verdict}); pass --force to start fresh.`
|
|
32483
32496
|
)
|
|
32484
32497
|
);
|
|
32485
32498
|
else if (force)
|
|
32486
32499
|
console.log(
|
|
32487
|
-
|
|
32500
|
+
chalk227.dim(
|
|
32488
32501
|
`Discarding any review saved for ${head} and starting fresh (--force).`
|
|
32489
32502
|
)
|
|
32490
32503
|
);
|
|
@@ -33025,55 +33038,55 @@ async function openHighLevelOverlay(sessionId, subject) {
|
|
|
33025
33038
|
}
|
|
33026
33039
|
|
|
33027
33040
|
// src/commands/review/highLevel/printHighLevelChecklist.ts
|
|
33028
|
-
import
|
|
33041
|
+
import chalk231 from "chalk";
|
|
33029
33042
|
|
|
33030
33043
|
// src/commands/review/highLevel/formatCriticalDiffs.ts
|
|
33031
|
-
import
|
|
33044
|
+
import chalk228 from "chalk";
|
|
33032
33045
|
var PATCH_LINE_COLOURS = {
|
|
33033
|
-
"+":
|
|
33034
|
-
"-":
|
|
33035
|
-
"@":
|
|
33046
|
+
"+": chalk228.green,
|
|
33047
|
+
"-": chalk228.red,
|
|
33048
|
+
"@": chalk228.cyan
|
|
33036
33049
|
};
|
|
33037
33050
|
function formatPatch(patch2) {
|
|
33038
33051
|
return patch2.split("\n").map(
|
|
33039
|
-
(line) => ` ${(PATCH_LINE_COLOURS[line[0] ?? ""] ??
|
|
33052
|
+
(line) => ` ${(PATCH_LINE_COLOURS[line[0] ?? ""] ?? chalk228.dim)(line)}`
|
|
33040
33053
|
);
|
|
33041
33054
|
}
|
|
33042
33055
|
function formatDiff(diff3) {
|
|
33043
33056
|
return [
|
|
33044
33057
|
"",
|
|
33045
|
-
` ${
|
|
33046
|
-
...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)
|
|
33047
33060
|
];
|
|
33048
33061
|
}
|
|
33049
33062
|
function formatCriticalDiffs(diffs, criticalPaths) {
|
|
33050
33063
|
if (criticalPaths.length === 0)
|
|
33051
|
-
return `${
|
|
33052
|
-
${
|
|
33064
|
+
return `${chalk228.bold.underline("Critical diffs")}
|
|
33065
|
+
${chalk228.dim("review.highLevel.criticalPaths is unset, so no diffs are shown")}`;
|
|
33053
33066
|
if (diffs.length === 0)
|
|
33054
|
-
return `${
|
|
33055
|
-
${
|
|
33067
|
+
return `${chalk228.bold.underline("Critical diffs")}
|
|
33068
|
+
${chalk228.dim(`no changed file matches ${criticalPaths.join(", ")}`)}`;
|
|
33056
33069
|
return [
|
|
33057
|
-
|
|
33070
|
+
chalk228.bold.underline("Critical diffs"),
|
|
33058
33071
|
...diffs.flatMap(formatDiff)
|
|
33059
33072
|
].join("\n");
|
|
33060
33073
|
}
|
|
33061
33074
|
|
|
33062
33075
|
// src/commands/review/highLevel/formatHighLevelChecklist.ts
|
|
33063
|
-
import
|
|
33076
|
+
import chalk229 from "chalk";
|
|
33064
33077
|
var MARKERS = {
|
|
33065
|
-
pass: () =>
|
|
33066
|
-
fail: () =>
|
|
33067
|
-
manual: () =>
|
|
33078
|
+
pass: () => chalk229.green("\u2714"),
|
|
33079
|
+
fail: () => chalk229.red("\u2718"),
|
|
33080
|
+
manual: () => chalk229.yellow("\u25A1")
|
|
33068
33081
|
};
|
|
33069
33082
|
function formatCheck(check2) {
|
|
33070
|
-
const title = check2.status === "fail" ?
|
|
33083
|
+
const title = check2.status === "fail" ? chalk229.red(check2.title) : chalk229.bold(check2.title);
|
|
33071
33084
|
return ` ${MARKERS[check2.status]()} ${title}
|
|
33072
|
-
${
|
|
33085
|
+
${chalk229.dim(check2.reason)}`;
|
|
33073
33086
|
}
|
|
33074
33087
|
function formatGroup(heading2, checks2) {
|
|
33075
33088
|
if (checks2.length === 0) return [];
|
|
33076
|
-
return ["",
|
|
33089
|
+
return ["", chalk229.bold.underline(heading2), ...checks2.map(formatCheck)];
|
|
33077
33090
|
}
|
|
33078
33091
|
function formatHighLevelChecklist(checks2) {
|
|
33079
33092
|
const deterministic = checks2.filter(
|
|
@@ -33082,7 +33095,7 @@ function formatHighLevelChecklist(checks2) {
|
|
|
33082
33095
|
const failed3 = deterministic.filter(
|
|
33083
33096
|
(check2) => check2.status === "fail"
|
|
33084
33097
|
).length;
|
|
33085
|
-
const summary = failed3 === 0 ?
|
|
33098
|
+
const summary = failed3 === 0 ? chalk229.green(`All ${deterministic.length} deterministic checks pass`) : chalk229.red(
|
|
33086
33099
|
`${failed3} of ${deterministic.length} deterministic checks fail`
|
|
33087
33100
|
);
|
|
33088
33101
|
return [
|
|
@@ -33097,30 +33110,30 @@ function formatHighLevelChecklist(checks2) {
|
|
|
33097
33110
|
}
|
|
33098
33111
|
|
|
33099
33112
|
// src/commands/review/highLevel/formatHighLevelStructure.ts
|
|
33100
|
-
import
|
|
33113
|
+
import chalk230 from "chalk";
|
|
33101
33114
|
var STATUS_MARKERS = {
|
|
33102
|
-
added: () =>
|
|
33103
|
-
removed: () =>
|
|
33104
|
-
modified: () =>
|
|
33115
|
+
added: () => chalk230.green("A"),
|
|
33116
|
+
removed: () => chalk230.red("D"),
|
|
33117
|
+
modified: () => chalk230.yellow("M")
|
|
33105
33118
|
};
|
|
33106
33119
|
function counts(additions, deletions) {
|
|
33107
|
-
return `${
|
|
33120
|
+
return `${chalk230.green(`+${additions}`)} ${chalk230.red(`-${deletions}`)}`;
|
|
33108
33121
|
}
|
|
33109
33122
|
function formatNode(node, indent3) {
|
|
33110
33123
|
if (node.kind === "file")
|
|
33111
33124
|
return [
|
|
33112
|
-
`${indent3}${STATUS_MARKERS[node.status]()} ${node.name} ${
|
|
33125
|
+
`${indent3}${STATUS_MARKERS[node.status]()} ${node.name} ${chalk230.dim(counts(node.additions, node.deletions))}`
|
|
33113
33126
|
];
|
|
33114
33127
|
const dir = node;
|
|
33115
33128
|
return [
|
|
33116
|
-
`${indent3}${
|
|
33129
|
+
`${indent3}${chalk230.bold(`${dir.name}/`)} ${chalk230.dim(counts(dir.additions, dir.deletions))}`,
|
|
33117
33130
|
...dir.children.flatMap((child) => formatNode(child, `${indent3} `))
|
|
33118
33131
|
];
|
|
33119
33132
|
}
|
|
33120
33133
|
function formatHighLevelStructure(structure) {
|
|
33121
33134
|
const summary = `${structure.added} added \xB7 ${structure.removed} deleted \xB7 ${structure.modified} modified \xB7 ${counts(structure.additions, structure.deletions)}`;
|
|
33122
33135
|
return [
|
|
33123
|
-
|
|
33136
|
+
chalk230.bold.underline("Structure"),
|
|
33124
33137
|
` ${summary}`,
|
|
33125
33138
|
...structure.tree.flatMap((node) => formatNode(node, " "))
|
|
33126
33139
|
].join("\n");
|
|
@@ -33129,10 +33142,10 @@ function formatHighLevelStructure(structure) {
|
|
|
33129
33142
|
// src/commands/review/highLevel/printHighLevelChecklist.ts
|
|
33130
33143
|
function printHighLevelChecklist(subject) {
|
|
33131
33144
|
console.log(
|
|
33132
|
-
|
|
33145
|
+
chalk231.bold(
|
|
33133
33146
|
`High-level review of ${subject.repo}#${subject.prNumber} \u2014 ${subject.title}`
|
|
33134
33147
|
),
|
|
33135
|
-
|
|
33148
|
+
chalk231.dim(
|
|
33136
33149
|
`\xB7 ${highLevelChangedFileCount(subject.structure)} changed files`
|
|
33137
33150
|
)
|
|
33138
33151
|
);
|
|
@@ -33144,12 +33157,12 @@ function printHighLevelChecklist(subject) {
|
|
|
33144
33157
|
formatCriticalDiffs(subject.criticalDiffs, subject.criticalPaths)
|
|
33145
33158
|
);
|
|
33146
33159
|
console.log(
|
|
33147
|
-
|
|
33160
|
+
chalk231.dim(
|
|
33148
33161
|
"\nManual items are for the reviewer to judge; see docs/high-level-review.md."
|
|
33149
33162
|
)
|
|
33150
33163
|
);
|
|
33151
33164
|
console.log(
|
|
33152
|
-
|
|
33165
|
+
chalk231.dim(
|
|
33153
33166
|
"Run this inside an assist session to step through the checklist in the web overlay."
|
|
33154
33167
|
)
|
|
33155
33168
|
);
|
|
@@ -33783,18 +33796,18 @@ function partitionFindingsByDiff(findings, index3) {
|
|
|
33783
33796
|
}
|
|
33784
33797
|
|
|
33785
33798
|
// src/commands/review/warnOutOfDiff.ts
|
|
33786
|
-
import
|
|
33799
|
+
import chalk232 from "chalk";
|
|
33787
33800
|
function warnOutOfDiff(outOfDiff) {
|
|
33788
33801
|
if (outOfDiff.length === 0) return;
|
|
33789
33802
|
console.warn(
|
|
33790
|
-
|
|
33803
|
+
chalk232.yellow(
|
|
33791
33804
|
`Moved ${outOfDiff.length} finding(s) whose lines fall outside the PR diff into the review body (GitHub cannot anchor a comment on these):`
|
|
33792
33805
|
)
|
|
33793
33806
|
);
|
|
33794
33807
|
for (const finding of outOfDiff) {
|
|
33795
33808
|
const range = finding.startLine !== void 0 ? `${finding.startLine}-${finding.line}` : `${finding.line}`;
|
|
33796
33809
|
console.warn(
|
|
33797
|
-
` ${
|
|
33810
|
+
` ${chalk232.yellow("\xB7")} ${finding.title} ${chalk232.dim(
|
|
33798
33811
|
`(${finding.file}:${range})`
|
|
33799
33812
|
)}`
|
|
33800
33813
|
);
|
|
@@ -33818,18 +33831,18 @@ function selectInDiffFindings(lineBound, prDiff) {
|
|
|
33818
33831
|
}
|
|
33819
33832
|
|
|
33820
33833
|
// src/commands/review/warnUnlocated.ts
|
|
33821
|
-
import
|
|
33834
|
+
import chalk233 from "chalk";
|
|
33822
33835
|
function warnUnlocated(unlocated) {
|
|
33823
33836
|
if (unlocated.length === 0) return;
|
|
33824
33837
|
console.warn(
|
|
33825
|
-
|
|
33838
|
+
chalk233.yellow(
|
|
33826
33839
|
`Moved ${unlocated.length} finding(s) without a parseable file:line into the review body:`
|
|
33827
33840
|
)
|
|
33828
33841
|
);
|
|
33829
33842
|
for (const finding of unlocated) {
|
|
33830
|
-
const where = finding.location ||
|
|
33843
|
+
const where = finding.location || chalk233.dim("missing");
|
|
33831
33844
|
console.warn(
|
|
33832
|
-
` ${
|
|
33845
|
+
` ${chalk233.yellow("\xB7")} ${finding.title} ${chalk233.dim(`(${where})`)}`
|
|
33833
33846
|
);
|
|
33834
33847
|
}
|
|
33835
33848
|
}
|
|
@@ -35274,7 +35287,7 @@ function registerReview(program2) {
|
|
|
35274
35287
|
// src/commands/rules/addRule.ts
|
|
35275
35288
|
import { existsSync as existsSync70, readFileSync as readFileSync53, writeFileSync as writeFileSync43 } from "fs";
|
|
35276
35289
|
import path85 from "path";
|
|
35277
|
-
import
|
|
35290
|
+
import chalk234 from "chalk";
|
|
35278
35291
|
|
|
35279
35292
|
// src/commands/rules/insertRuleBullet.ts
|
|
35280
35293
|
function ruleBullet({ code, title, text: text18 }) {
|
|
@@ -35410,7 +35423,7 @@ function read2(file) {
|
|
|
35410
35423
|
function addRule(text18, options2) {
|
|
35411
35424
|
const rule = text18.trim();
|
|
35412
35425
|
if (rule === "") {
|
|
35413
|
-
console.error(
|
|
35426
|
+
console.error(chalk234.red("Rule text is required"));
|
|
35414
35427
|
process.exitCode = 1;
|
|
35415
35428
|
return;
|
|
35416
35429
|
}
|
|
@@ -35428,13 +35441,13 @@ function addRule(text18, options2) {
|
|
|
35428
35441
|
);
|
|
35429
35442
|
updateScopedRulesIndex(root2);
|
|
35430
35443
|
console.log(
|
|
35431
|
-
`Added ${
|
|
35444
|
+
`Added ${chalk234.cyan(code)} to ${path85.relative(process.cwd(), target) || target}`
|
|
35432
35445
|
);
|
|
35433
35446
|
}
|
|
35434
35447
|
|
|
35435
35448
|
// src/commands/rules/indexRules.ts
|
|
35436
35449
|
import path86 from "path";
|
|
35437
|
-
import
|
|
35450
|
+
import chalk235 from "chalk";
|
|
35438
35451
|
function indexRules() {
|
|
35439
35452
|
const startDir = scopeDirectory(process.cwd());
|
|
35440
35453
|
const root2 = findRepoRoot(startDir) ?? startDir;
|
|
@@ -35442,24 +35455,24 @@ function indexRules() {
|
|
|
35442
35455
|
const rootFile = path86.relative(process.cwd(), path86.join(root2, "CLAUDE.md"));
|
|
35443
35456
|
if (directories.length === 0) {
|
|
35444
35457
|
console.log(
|
|
35445
|
-
|
|
35458
|
+
chalk235.gray(`No directories carry their own \`## Rules\` under ${root2}`)
|
|
35446
35459
|
);
|
|
35447
35460
|
return;
|
|
35448
35461
|
}
|
|
35449
35462
|
console.log(`Recorded in ${rootFile || "CLAUDE.md"}`);
|
|
35450
35463
|
for (const directory of directories)
|
|
35451
|
-
console.log(` ${
|
|
35464
|
+
console.log(` ${chalk235.cyan(directory)}`);
|
|
35452
35465
|
}
|
|
35453
35466
|
|
|
35454
35467
|
// src/commands/rules/listRules.ts
|
|
35455
35468
|
import path87 from "path";
|
|
35456
|
-
import
|
|
35469
|
+
import chalk236 from "chalk";
|
|
35457
35470
|
function listRules(target, options2 = {}) {
|
|
35458
35471
|
const resolved = path87.resolve(target ?? process.cwd());
|
|
35459
35472
|
const rules3 = readScopedRules(resolved);
|
|
35460
35473
|
if (rules3.length === 0) {
|
|
35461
35474
|
const label2 = path87.relative(process.cwd(), resolved) || ".";
|
|
35462
|
-
console.log(
|
|
35475
|
+
console.log(chalk236.gray(`No rules in scope for ${label2}`));
|
|
35463
35476
|
return;
|
|
35464
35477
|
}
|
|
35465
35478
|
const base = findRepoRoot(scopeDirectory(resolved));
|
|
@@ -35469,14 +35482,14 @@ function listRules(target, options2 = {}) {
|
|
|
35469
35482
|
if (rule.source !== shown) {
|
|
35470
35483
|
shown = rule.source;
|
|
35471
35484
|
console.log(
|
|
35472
|
-
|
|
35485
|
+
chalk236.dim(base ? path87.relative(base, rule.source) : rule.source)
|
|
35473
35486
|
);
|
|
35474
35487
|
}
|
|
35475
35488
|
console.log(
|
|
35476
|
-
` ${
|
|
35489
|
+
` ${chalk236.cyan(rule.code.padEnd(width))} ${rule.title ?? rule.text}`
|
|
35477
35490
|
);
|
|
35478
35491
|
if (options2.full && rule.title)
|
|
35479
|
-
console.log(` ${" ".repeat(width)} ${
|
|
35492
|
+
console.log(` ${" ".repeat(width)} ${chalk236.dim(rule.text)}`);
|
|
35480
35493
|
}
|
|
35481
35494
|
}
|
|
35482
35495
|
|
|
@@ -35505,7 +35518,7 @@ function registerRules(program2) {
|
|
|
35505
35518
|
}
|
|
35506
35519
|
|
|
35507
35520
|
// src/commands/seq/seqAuth.ts
|
|
35508
|
-
import
|
|
35521
|
+
import chalk238 from "chalk";
|
|
35509
35522
|
|
|
35510
35523
|
// src/commands/seq/loadConnections.ts
|
|
35511
35524
|
function loadConnections2() {
|
|
@@ -35534,10 +35547,10 @@ function setDefaultConnection(name) {
|
|
|
35534
35547
|
}
|
|
35535
35548
|
|
|
35536
35549
|
// src/shared/assertUniqueName.ts
|
|
35537
|
-
import
|
|
35550
|
+
import chalk237 from "chalk";
|
|
35538
35551
|
function assertUniqueName(existingNames, name) {
|
|
35539
35552
|
if (existingNames.includes(name)) {
|
|
35540
|
-
console.error(
|
|
35553
|
+
console.error(chalk237.red(`Connection "${name}" already exists.`));
|
|
35541
35554
|
process.exit(1);
|
|
35542
35555
|
}
|
|
35543
35556
|
}
|
|
@@ -35555,16 +35568,16 @@ async function promptConnection2(existingNames) {
|
|
|
35555
35568
|
var seqAuth = createConnectionAuth({
|
|
35556
35569
|
load: loadConnections2,
|
|
35557
35570
|
save: saveConnections2,
|
|
35558
|
-
format: (c) => `${
|
|
35571
|
+
format: (c) => `${chalk238.bold(c.name)} ${c.url}`,
|
|
35559
35572
|
promptNew: promptConnection2,
|
|
35560
35573
|
onFirst: (c) => setDefaultConnection(c.name)
|
|
35561
35574
|
});
|
|
35562
35575
|
|
|
35563
35576
|
// src/commands/seq/seqQuery.ts
|
|
35564
|
-
import
|
|
35577
|
+
import chalk242 from "chalk";
|
|
35565
35578
|
|
|
35566
35579
|
// src/commands/seq/fetchSeq.ts
|
|
35567
|
-
import
|
|
35580
|
+
import chalk239 from "chalk";
|
|
35568
35581
|
async function fetchSeq(conn, path106, params) {
|
|
35569
35582
|
const url = `${conn.url}${path106}?${params}`;
|
|
35570
35583
|
const response = await fetch(url, {
|
|
@@ -35575,7 +35588,7 @@ async function fetchSeq(conn, path106, params) {
|
|
|
35575
35588
|
});
|
|
35576
35589
|
if (!response.ok) {
|
|
35577
35590
|
const body = await response.text();
|
|
35578
|
-
console.error(
|
|
35591
|
+
console.error(chalk239.red(`Seq returned ${response.status}: ${body}`));
|
|
35579
35592
|
process.exit(1);
|
|
35580
35593
|
}
|
|
35581
35594
|
return response;
|
|
@@ -35634,23 +35647,23 @@ async function fetchSeqEvents(conn, params) {
|
|
|
35634
35647
|
}
|
|
35635
35648
|
|
|
35636
35649
|
// src/commands/seq/formatEvent.ts
|
|
35637
|
-
import
|
|
35650
|
+
import chalk240 from "chalk";
|
|
35638
35651
|
function levelColor(level) {
|
|
35639
35652
|
switch (level) {
|
|
35640
35653
|
case "Fatal":
|
|
35641
|
-
return
|
|
35654
|
+
return chalk240.bgRed.white;
|
|
35642
35655
|
case "Error":
|
|
35643
|
-
return
|
|
35656
|
+
return chalk240.red;
|
|
35644
35657
|
case "Warning":
|
|
35645
|
-
return
|
|
35658
|
+
return chalk240.yellow;
|
|
35646
35659
|
case "Information":
|
|
35647
|
-
return
|
|
35660
|
+
return chalk240.cyan;
|
|
35648
35661
|
case "Debug":
|
|
35649
|
-
return
|
|
35662
|
+
return chalk240.gray;
|
|
35650
35663
|
case "Verbose":
|
|
35651
|
-
return
|
|
35664
|
+
return chalk240.dim;
|
|
35652
35665
|
default:
|
|
35653
|
-
return
|
|
35666
|
+
return chalk240.white;
|
|
35654
35667
|
}
|
|
35655
35668
|
}
|
|
35656
35669
|
function levelAbbrev(level) {
|
|
@@ -35691,12 +35704,12 @@ function formatTimestamp(iso) {
|
|
|
35691
35704
|
function formatEvent(event) {
|
|
35692
35705
|
const color = levelColor(event.Level);
|
|
35693
35706
|
const abbrev = levelAbbrev(event.Level);
|
|
35694
|
-
const ts10 =
|
|
35707
|
+
const ts10 = chalk240.dim(formatTimestamp(event.Timestamp));
|
|
35695
35708
|
const msg = renderMessage(event);
|
|
35696
35709
|
const lines2 = [`${ts10} ${color(`[${abbrev}]`)} ${msg}`];
|
|
35697
35710
|
if (event.Exception) {
|
|
35698
35711
|
for (const line of event.Exception.split("\n")) {
|
|
35699
|
-
lines2.push(
|
|
35712
|
+
lines2.push(chalk240.red(` ${line}`));
|
|
35700
35713
|
}
|
|
35701
35714
|
}
|
|
35702
35715
|
return lines2.join("\n");
|
|
@@ -35729,11 +35742,11 @@ function rejectTimestampFilter(filter) {
|
|
|
35729
35742
|
}
|
|
35730
35743
|
|
|
35731
35744
|
// src/shared/resolveNamedConnection.ts
|
|
35732
|
-
import
|
|
35745
|
+
import chalk241 from "chalk";
|
|
35733
35746
|
function resolveNamedConnection(connections, requested, defaultName, kind, authCommand) {
|
|
35734
35747
|
if (connections.length === 0) {
|
|
35735
35748
|
console.error(
|
|
35736
|
-
|
|
35749
|
+
chalk241.red(
|
|
35737
35750
|
`No ${kind} connections configured. Run '${authCommand}' first.`
|
|
35738
35751
|
)
|
|
35739
35752
|
);
|
|
@@ -35742,7 +35755,7 @@ function resolveNamedConnection(connections, requested, defaultName, kind, authC
|
|
|
35742
35755
|
const target = requested ?? defaultName ?? connections[0].name;
|
|
35743
35756
|
const connection = connections.find((c) => c.name === target);
|
|
35744
35757
|
if (!connection) {
|
|
35745
|
-
console.error(
|
|
35758
|
+
console.error(chalk241.red(`${kind} connection "${target}" not found.`));
|
|
35746
35759
|
process.exit(1);
|
|
35747
35760
|
}
|
|
35748
35761
|
return connection;
|
|
@@ -35771,7 +35784,7 @@ async function seqQuery(filter, options2) {
|
|
|
35771
35784
|
new URLSearchParams({ filter, count: String(count8) })
|
|
35772
35785
|
);
|
|
35773
35786
|
if (events.length === 0) {
|
|
35774
|
-
console.log(
|
|
35787
|
+
console.log(chalk242.yellow("No events found."));
|
|
35775
35788
|
return;
|
|
35776
35789
|
}
|
|
35777
35790
|
if (options2.json) {
|
|
@@ -35782,11 +35795,11 @@ async function seqQuery(filter, options2) {
|
|
|
35782
35795
|
for (const event of chronological) {
|
|
35783
35796
|
console.log(formatEvent(event));
|
|
35784
35797
|
}
|
|
35785
|
-
console.log(
|
|
35798
|
+
console.log(chalk242.dim(`
|
|
35786
35799
|
${events.length} events`));
|
|
35787
35800
|
if (events.length >= count8) {
|
|
35788
35801
|
console.log(
|
|
35789
|
-
|
|
35802
|
+
chalk242.yellow(
|
|
35790
35803
|
`Results limited to ${count8}. Use --count to retrieve more.`
|
|
35791
35804
|
)
|
|
35792
35805
|
);
|
|
@@ -35794,10 +35807,10 @@ ${events.length} events`));
|
|
|
35794
35807
|
}
|
|
35795
35808
|
|
|
35796
35809
|
// src/shared/setNamedDefaultConnection.ts
|
|
35797
|
-
import
|
|
35810
|
+
import chalk243 from "chalk";
|
|
35798
35811
|
function setNamedDefaultConnection(connections, name, setDefault, kind) {
|
|
35799
35812
|
if (!connections.find((c) => c.name === name)) {
|
|
35800
|
-
console.error(
|
|
35813
|
+
console.error(chalk243.red(`Connection "${name}" not found.`));
|
|
35801
35814
|
process.exit(1);
|
|
35802
35815
|
}
|
|
35803
35816
|
setDefault(name);
|
|
@@ -36018,7 +36031,7 @@ function registerSlack(program2) {
|
|
|
36018
36031
|
}
|
|
36019
36032
|
|
|
36020
36033
|
// src/commands/sql/sqlAuth.ts
|
|
36021
|
-
import
|
|
36034
|
+
import chalk245 from "chalk";
|
|
36022
36035
|
|
|
36023
36036
|
// src/commands/sql/loadConnections.ts
|
|
36024
36037
|
function loadConnections3() {
|
|
@@ -36047,7 +36060,7 @@ function setDefaultConnection2(name) {
|
|
|
36047
36060
|
}
|
|
36048
36061
|
|
|
36049
36062
|
// src/commands/sql/promptConnection.ts
|
|
36050
|
-
import
|
|
36063
|
+
import chalk244 from "chalk";
|
|
36051
36064
|
async function promptConnection3(existingNames) {
|
|
36052
36065
|
const name = await promptInput("name", "Connection name:", "default");
|
|
36053
36066
|
assertUniqueName(existingNames, name);
|
|
@@ -36055,7 +36068,7 @@ async function promptConnection3(existingNames) {
|
|
|
36055
36068
|
const portStr = await promptInput("port", "Port:", "1433");
|
|
36056
36069
|
const port = Number.parseInt(portStr, 10);
|
|
36057
36070
|
if (!Number.isFinite(port)) {
|
|
36058
|
-
console.error(
|
|
36071
|
+
console.error(chalk244.red(`Invalid port "${portStr}".`));
|
|
36059
36072
|
process.exit(1);
|
|
36060
36073
|
}
|
|
36061
36074
|
const user = await promptInput("user", "User:");
|
|
@@ -36068,13 +36081,13 @@ async function promptConnection3(existingNames) {
|
|
|
36068
36081
|
var sqlAuth = createConnectionAuth({
|
|
36069
36082
|
load: loadConnections3,
|
|
36070
36083
|
save: saveConnections3,
|
|
36071
|
-
format: (c) => `${
|
|
36084
|
+
format: (c) => `${chalk245.bold(c.name)} ${c.server}:${c.port}/${c.database} (${c.user})`,
|
|
36072
36085
|
promptNew: promptConnection3,
|
|
36073
36086
|
onFirst: (c) => setDefaultConnection2(c.name)
|
|
36074
36087
|
});
|
|
36075
36088
|
|
|
36076
36089
|
// src/commands/sql/printTable.ts
|
|
36077
|
-
import
|
|
36090
|
+
import chalk246 from "chalk";
|
|
36078
36091
|
function formatCell(value) {
|
|
36079
36092
|
if (value === null || value === void 0) return "";
|
|
36080
36093
|
if (value instanceof Date) return value.toISOString();
|
|
@@ -36083,7 +36096,7 @@ function formatCell(value) {
|
|
|
36083
36096
|
}
|
|
36084
36097
|
function printTable(rows) {
|
|
36085
36098
|
if (rows.length === 0) {
|
|
36086
|
-
console.log(
|
|
36099
|
+
console.log(chalk246.yellow("(no rows)"));
|
|
36087
36100
|
return;
|
|
36088
36101
|
}
|
|
36089
36102
|
const columns = Object.keys(rows[0]);
|
|
@@ -36091,13 +36104,13 @@ function printTable(rows) {
|
|
|
36091
36104
|
(col) => Math.max(col.length, ...rows.map((r) => formatCell(r[col]).length))
|
|
36092
36105
|
);
|
|
36093
36106
|
const header = columns.map((c, i) => c.padEnd(widths[i])).join(" ");
|
|
36094
|
-
console.log(
|
|
36095
|
-
console.log(
|
|
36107
|
+
console.log(chalk246.dim(header));
|
|
36108
|
+
console.log(chalk246.dim("-".repeat(header.length)));
|
|
36096
36109
|
for (const row of rows) {
|
|
36097
36110
|
const line = columns.map((c, i) => formatCell(row[c]).padEnd(widths[i])).join(" ");
|
|
36098
36111
|
console.log(line);
|
|
36099
36112
|
}
|
|
36100
|
-
console.log(
|
|
36113
|
+
console.log(chalk246.dim(`
|
|
36101
36114
|
${rows.length} row${rows.length === 1 ? "" : "s"}`));
|
|
36102
36115
|
}
|
|
36103
36116
|
|
|
@@ -36157,7 +36170,7 @@ async function sqlColumns(table, connectionName) {
|
|
|
36157
36170
|
}
|
|
36158
36171
|
|
|
36159
36172
|
// src/commands/sql/sqlMutate.ts
|
|
36160
|
-
import
|
|
36173
|
+
import chalk247 from "chalk";
|
|
36161
36174
|
|
|
36162
36175
|
// src/commands/sql/isMutation.ts
|
|
36163
36176
|
var MUTATION_KEYWORDS = [
|
|
@@ -36191,7 +36204,7 @@ function isMutation(sql29) {
|
|
|
36191
36204
|
async function sqlMutate(query, connectionName) {
|
|
36192
36205
|
if (!isMutation(query)) {
|
|
36193
36206
|
console.error(
|
|
36194
|
-
|
|
36207
|
+
chalk247.red(
|
|
36195
36208
|
"assist sql mutate refuses non-mutating statements. Use `assist sql query` instead."
|
|
36196
36209
|
)
|
|
36197
36210
|
);
|
|
@@ -36201,18 +36214,18 @@ async function sqlMutate(query, connectionName) {
|
|
|
36201
36214
|
const pool = await sqlConnect(conn);
|
|
36202
36215
|
try {
|
|
36203
36216
|
const result = await pool.request().query(query);
|
|
36204
|
-
console.log(
|
|
36217
|
+
console.log(chalk247.dim(`${result.rowsAffected.join(", ")} row(s) affected`));
|
|
36205
36218
|
} finally {
|
|
36206
36219
|
await pool.close();
|
|
36207
36220
|
}
|
|
36208
36221
|
}
|
|
36209
36222
|
|
|
36210
36223
|
// src/commands/sql/sqlQuery.ts
|
|
36211
|
-
import
|
|
36224
|
+
import chalk248 from "chalk";
|
|
36212
36225
|
async function sqlQuery(query, connectionName) {
|
|
36213
36226
|
if (isMutation(query)) {
|
|
36214
36227
|
console.error(
|
|
36215
|
-
|
|
36228
|
+
chalk248.red(
|
|
36216
36229
|
"assist sql query refuses mutating statements. Use `assist sql mutate` instead."
|
|
36217
36230
|
)
|
|
36218
36231
|
);
|
|
@@ -36227,7 +36240,7 @@ async function sqlQuery(query, connectionName) {
|
|
|
36227
36240
|
printTable(rows);
|
|
36228
36241
|
} else {
|
|
36229
36242
|
console.log(
|
|
36230
|
-
|
|
36243
|
+
chalk248.dim(`${result.rowsAffected.join(", ")} row(s) affected`)
|
|
36231
36244
|
);
|
|
36232
36245
|
}
|
|
36233
36246
|
} finally {
|
|
@@ -36644,7 +36657,7 @@ function syncPi(claudeDir, options2) {
|
|
|
36644
36657
|
// src/commands/sync/syncSettings.ts
|
|
36645
36658
|
import * as fs47 from "fs";
|
|
36646
36659
|
import * as path98 from "path";
|
|
36647
|
-
import
|
|
36660
|
+
import chalk249 from "chalk";
|
|
36648
36661
|
async function syncSettings(claudeDir, targetBase, options2) {
|
|
36649
36662
|
const source = path98.join(claudeDir, "settings.json");
|
|
36650
36663
|
const target = path98.join(targetBase, "settings.json");
|
|
@@ -36663,7 +36676,7 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
36663
36676
|
if (mergedContent !== normalizedTarget) {
|
|
36664
36677
|
if (!options2?.yes) {
|
|
36665
36678
|
console.log(
|
|
36666
|
-
|
|
36679
|
+
chalk249.yellow(
|
|
36667
36680
|
"\n\u26A0\uFE0F Warning: settings.json differs from existing file"
|
|
36668
36681
|
)
|
|
36669
36682
|
);
|
|
@@ -36671,7 +36684,7 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
36671
36684
|
printDiff(targetContent, mergedContent);
|
|
36672
36685
|
printAutoConfirmHint();
|
|
36673
36686
|
const confirm = await promptConfirm(
|
|
36674
|
-
|
|
36687
|
+
chalk249.red("Overwrite existing settings.json?"),
|
|
36675
36688
|
false
|
|
36676
36689
|
);
|
|
36677
36690
|
if (!confirm) {
|
|
@@ -39061,7 +39074,7 @@ function registerWatch(program2) {
|
|
|
39061
39074
|
|
|
39062
39075
|
// src/commands/roam/auth.ts
|
|
39063
39076
|
import { randomBytes } from "crypto";
|
|
39064
|
-
import
|
|
39077
|
+
import chalk250 from "chalk";
|
|
39065
39078
|
|
|
39066
39079
|
// src/commands/roam/waitForCallback.ts
|
|
39067
39080
|
import { createServer as createServer3 } from "http";
|
|
@@ -39192,13 +39205,13 @@ async function auth() {
|
|
|
39192
39205
|
saveGlobalConfig(config);
|
|
39193
39206
|
const state = randomBytes(16).toString("hex");
|
|
39194
39207
|
console.log(
|
|
39195
|
-
|
|
39208
|
+
chalk250.yellow("\nEnsure this Redirect URI is set in your Roam OAuth app:")
|
|
39196
39209
|
);
|
|
39197
|
-
console.log(
|
|
39198
|
-
console.log(
|
|
39199
|
-
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..."));
|
|
39200
39213
|
const { code, redirectUri } = await authorizeInBrowser(clientId, state);
|
|
39201
|
-
console.log(
|
|
39214
|
+
console.log(chalk250.dim("Exchanging code for tokens..."));
|
|
39202
39215
|
const tokens = await exchangeToken({
|
|
39203
39216
|
code,
|
|
39204
39217
|
clientId,
|
|
@@ -39214,7 +39227,7 @@ async function auth() {
|
|
|
39214
39227
|
};
|
|
39215
39228
|
saveGlobalConfig(config);
|
|
39216
39229
|
console.log(
|
|
39217
|
-
|
|
39230
|
+
chalk250.green("Roam credentials and tokens saved to ~/.assist.yml")
|
|
39218
39231
|
);
|
|
39219
39232
|
}
|
|
39220
39233
|
|
|
@@ -39569,7 +39582,7 @@ function registerRun(program2) {
|
|
|
39569
39582
|
}
|
|
39570
39583
|
|
|
39571
39584
|
// src/commands/sessions/nodes/formatLink.ts
|
|
39572
|
-
import
|
|
39585
|
+
import chalk251 from "chalk";
|
|
39573
39586
|
|
|
39574
39587
|
// src/commands/sessions/daemon/links/describeTarget.ts
|
|
39575
39588
|
function describeTarget({ url, ssh }) {
|
|
@@ -39579,16 +39592,16 @@ function describeTarget({ url, ssh }) {
|
|
|
39579
39592
|
|
|
39580
39593
|
// src/commands/sessions/nodes/formatLink.ts
|
|
39581
39594
|
var STATE_COLOURS = {
|
|
39582
|
-
connected:
|
|
39583
|
-
connecting:
|
|
39584
|
-
disconnected:
|
|
39585
|
-
"version-blocked":
|
|
39595
|
+
connected: chalk251.green,
|
|
39596
|
+
connecting: chalk251.yellow,
|
|
39597
|
+
disconnected: chalk251.red,
|
|
39598
|
+
"version-blocked": chalk251.red
|
|
39586
39599
|
};
|
|
39587
39600
|
function formatLink(link3) {
|
|
39588
|
-
const colour = STATE_COLOURS[link3.state] ??
|
|
39601
|
+
const colour = STATE_COLOURS[link3.state] ?? chalk251.white;
|
|
39589
39602
|
const peer = link3.peerVersion ? ` peer ${link3.peerVersion}` : "";
|
|
39590
39603
|
const error = link3.error ? `
|
|
39591
|
-
${
|
|
39604
|
+
${chalk251.dim(`last error${link3.errorAt ? ` ${link3.errorAt}` : ""}: ${link3.error}`)}` : "";
|
|
39592
39605
|
return ` ${link3.name} ${colour(link3.state)} ${describeTarget(link3)}${peer}${error}`;
|
|
39593
39606
|
}
|
|
39594
39607
|
|
|
@@ -46336,7 +46349,7 @@ async function probeSshAgent(alias) {
|
|
|
46336
46349
|
}
|
|
46337
46350
|
|
|
46338
46351
|
// src/commands/sessions/nodes/printReport.ts
|
|
46339
|
-
import
|
|
46352
|
+
import chalk252 from "chalk";
|
|
46340
46353
|
function printReport(report2) {
|
|
46341
46354
|
if (report2.links.length === 0) {
|
|
46342
46355
|
console.log(`${report2.local} has no links`);
|
|
@@ -46350,11 +46363,11 @@ function printReport(report2) {
|
|
|
46350
46363
|
for (const diagnosis of report2.links) printDiagnosis(diagnosis);
|
|
46351
46364
|
}
|
|
46352
46365
|
function printDiagnosis(diagnosis) {
|
|
46353
|
-
console.log(`${
|
|
46366
|
+
console.log(`${chalk252.bold(diagnosis.name)} ${chalk252.dim(diagnosis.url)}`);
|
|
46354
46367
|
for (const hop of diagnosis.hops) {
|
|
46355
|
-
const mark = hop.ok ?
|
|
46368
|
+
const mark = hop.ok ? chalk252.green("\u2713") : chalk252.red("\u2717");
|
|
46356
46369
|
console.log(` ${mark} ${hop.hop.padEnd(6)} ${hop.detail ?? hop.error}`);
|
|
46357
|
-
if (hop.remediation) console.log(` ${
|
|
46370
|
+
if (hop.remediation) console.log(` ${chalk252.yellow(hop.remediation)}`);
|
|
46358
46371
|
}
|
|
46359
46372
|
}
|
|
46360
46373
|
|
|
@@ -46387,14 +46400,14 @@ async function doctorNodes(name, options2) {
|
|
|
46387
46400
|
}
|
|
46388
46401
|
|
|
46389
46402
|
// src/commands/sessions/nodes/linkNode.ts
|
|
46390
|
-
import
|
|
46403
|
+
import chalk254 from "chalk";
|
|
46391
46404
|
|
|
46392
46405
|
// src/commands/sessions/nodes/notifyDaemonLinks.ts
|
|
46393
|
-
import
|
|
46406
|
+
import chalk253 from "chalk";
|
|
46394
46407
|
async function notifyDaemonLinks() {
|
|
46395
46408
|
if (!await isDaemonRunning()) {
|
|
46396
46409
|
console.log(
|
|
46397
|
-
|
|
46410
|
+
chalk253.yellow(
|
|
46398
46411
|
"The sessions daemon is not running; it loads the links when it starts."
|
|
46399
46412
|
)
|
|
46400
46413
|
);
|
|
@@ -46402,11 +46415,11 @@ async function notifyDaemonLinks() {
|
|
|
46402
46415
|
}
|
|
46403
46416
|
try {
|
|
46404
46417
|
await sendToDaemonAwaitAck({ type: "reload-links" });
|
|
46405
|
-
console.log(
|
|
46418
|
+
console.log(chalk253.dim("The sessions daemon reloaded its links."));
|
|
46406
46419
|
} catch (error) {
|
|
46407
46420
|
const message3 = error instanceof Error ? error.message : String(error);
|
|
46408
46421
|
console.log(
|
|
46409
|
-
|
|
46422
|
+
chalk253.yellow(
|
|
46410
46423
|
`Could not notify the sessions daemon (${message3}); run \`assist daemon restart\` to apply the change.`
|
|
46411
46424
|
)
|
|
46412
46425
|
);
|
|
@@ -46466,13 +46479,13 @@ async function linkNode(name, url, options2) {
|
|
|
46466
46479
|
const link3 = buildLink(name, url, options2, others);
|
|
46467
46480
|
await writeLinks([...others, link3]);
|
|
46468
46481
|
console.log(
|
|
46469
|
-
|
|
46482
|
+
chalk254.green(`Linked ${name} (${describeTarget(toLinkSpec(link3))})`)
|
|
46470
46483
|
);
|
|
46471
46484
|
await notifyDaemonLinks();
|
|
46472
46485
|
}
|
|
46473
46486
|
|
|
46474
46487
|
// src/commands/sessions/nodes/listNodes.ts
|
|
46475
|
-
import
|
|
46488
|
+
import chalk255 from "chalk";
|
|
46476
46489
|
async function nodesReport() {
|
|
46477
46490
|
const live = await queryNodes();
|
|
46478
46491
|
if (live)
|
|
@@ -46489,10 +46502,10 @@ async function listNodes(options2) {
|
|
|
46489
46502
|
console.log(JSON.stringify(report2, null, 2));
|
|
46490
46503
|
return;
|
|
46491
46504
|
}
|
|
46492
|
-
console.log(`${report2.local} ${
|
|
46505
|
+
console.log(`${report2.local} ${chalk255.dim("(this node)")}`);
|
|
46493
46506
|
if (!report2.daemonRunning)
|
|
46494
|
-
console.log(
|
|
46495
|
-
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"));
|
|
46496
46509
|
for (const link3 of report2.links) console.log(formatLink(link3));
|
|
46497
46510
|
}
|
|
46498
46511
|
|
|
@@ -46531,16 +46544,16 @@ async function nodeLogs(name, options2) {
|
|
|
46531
46544
|
}
|
|
46532
46545
|
|
|
46533
46546
|
// src/commands/sessions/nodes/unlinkNode.ts
|
|
46534
|
-
import
|
|
46547
|
+
import chalk256 from "chalk";
|
|
46535
46548
|
async function unlinkNode(name) {
|
|
46536
46549
|
const links2 = readLinks();
|
|
46537
46550
|
const remaining = links2.filter((link3) => link3.name !== name);
|
|
46538
46551
|
if (remaining.length === links2.length) {
|
|
46539
|
-
console.log(
|
|
46552
|
+
console.log(chalk256.yellow(`No link named ${name}`));
|
|
46540
46553
|
return;
|
|
46541
46554
|
}
|
|
46542
46555
|
await writeLinks(remaining);
|
|
46543
|
-
console.log(
|
|
46556
|
+
console.log(chalk256.green(`Unlinked ${name}`));
|
|
46544
46557
|
await notifyDaemonLinks();
|
|
46545
46558
|
}
|
|
46546
46559
|
|
|
@@ -46679,7 +46692,7 @@ async function renameSession(title) {
|
|
|
46679
46692
|
|
|
46680
46693
|
// src/commands/sessions/summarise.ts
|
|
46681
46694
|
import * as fs58 from "fs";
|
|
46682
|
-
import
|
|
46695
|
+
import chalk257 from "chalk";
|
|
46683
46696
|
|
|
46684
46697
|
// src/commands/sessions/summarise/shared.ts
|
|
46685
46698
|
import * as fs57 from "fs";
|
|
@@ -46738,22 +46751,22 @@ ${firstMessage}`);
|
|
|
46738
46751
|
async function summarise2(options2) {
|
|
46739
46752
|
const files = await discoverSessionFiles();
|
|
46740
46753
|
if (files.length === 0) {
|
|
46741
|
-
console.log(
|
|
46754
|
+
console.log(chalk257.yellow("No sessions found."));
|
|
46742
46755
|
return;
|
|
46743
46756
|
}
|
|
46744
46757
|
const toProcess = selectCandidates(files, options2);
|
|
46745
46758
|
if (toProcess.length === 0) {
|
|
46746
|
-
console.log(
|
|
46759
|
+
console.log(chalk257.green("All sessions already summarised."));
|
|
46747
46760
|
return;
|
|
46748
46761
|
}
|
|
46749
46762
|
console.log(
|
|
46750
|
-
|
|
46763
|
+
chalk257.cyan(
|
|
46751
46764
|
`Summarising ${toProcess.length} session(s) (${files.length} total)\u2026`
|
|
46752
46765
|
)
|
|
46753
46766
|
);
|
|
46754
46767
|
const { succeeded, failed: failed3 } = processSessions(toProcess);
|
|
46755
46768
|
console.log(
|
|
46756
|
-
|
|
46769
|
+
chalk257.green(`Done: ${succeeded} summarised`) + (failed3 > 0 ? chalk257.yellow(`, ${failed3} skipped`) : "")
|
|
46757
46770
|
);
|
|
46758
46771
|
}
|
|
46759
46772
|
function selectCandidates(files, options2) {
|
|
@@ -46773,16 +46786,16 @@ function processSessions(files) {
|
|
|
46773
46786
|
let failed3 = 0;
|
|
46774
46787
|
for (let i = 0; i < files.length; i++) {
|
|
46775
46788
|
const file = files[i];
|
|
46776
|
-
process.stdout.write(
|
|
46789
|
+
process.stdout.write(chalk257.dim(` [${i + 1}/${files.length}] `));
|
|
46777
46790
|
const summary = summariseSession(file);
|
|
46778
46791
|
if (summary) {
|
|
46779
46792
|
writeSummary(file, summary);
|
|
46780
46793
|
succeeded++;
|
|
46781
|
-
process.stdout.write(`${
|
|
46794
|
+
process.stdout.write(`${chalk257.green("\u2713")} ${summary}
|
|
46782
46795
|
`);
|
|
46783
46796
|
} else {
|
|
46784
46797
|
failed3++;
|
|
46785
|
-
process.stdout.write(` ${
|
|
46798
|
+
process.stdout.write(` ${chalk257.yellow("skip")}
|
|
46786
46799
|
`);
|
|
46787
46800
|
}
|
|
46788
46801
|
}
|
|
@@ -46811,10 +46824,10 @@ function registerSessions(program2) {
|
|
|
46811
46824
|
}
|
|
46812
46825
|
|
|
46813
46826
|
// src/reportCliError.ts
|
|
46814
|
-
import
|
|
46827
|
+
import chalk258 from "chalk";
|
|
46815
46828
|
function reportCliError(error) {
|
|
46816
46829
|
if (error instanceof InvalidItemIdError || error instanceof AmbiguousRepoConfigError || error instanceof UnknownRepoConfigError || error instanceof MissingRunCwdError || error instanceof MiroExtractError) {
|
|
46817
|
-
console.error(
|
|
46830
|
+
console.error(chalk258.red(error.message));
|
|
46818
46831
|
} else {
|
|
46819
46832
|
console.error(error);
|
|
46820
46833
|
}
|