@staff0rd/assist 0.149.0 → 0.149.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/index.js +140 -120
- 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.149.
|
|
9
|
+
version: "0.149.2",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -91,10 +91,10 @@ import { stringify as stringifyYaml } from "yaml";
|
|
|
91
91
|
// src/shared/loadRawYaml.ts
|
|
92
92
|
import { existsSync, readFileSync } from "fs";
|
|
93
93
|
import { parse as parseYaml } from "yaml";
|
|
94
|
-
function loadRawYaml(
|
|
95
|
-
if (!existsSync(
|
|
94
|
+
function loadRawYaml(path50) {
|
|
95
|
+
if (!existsSync(path50)) return {};
|
|
96
96
|
try {
|
|
97
|
-
const content = readFileSync(
|
|
97
|
+
const content = readFileSync(path50, "utf-8");
|
|
98
98
|
return parseYaml(content) || {};
|
|
99
99
|
} catch {
|
|
100
100
|
return {};
|
|
@@ -371,9 +371,9 @@ function isTraversable(value) {
|
|
|
371
371
|
function stepInto(current, key) {
|
|
372
372
|
return isTraversable(current) ? current[key] : void 0;
|
|
373
373
|
}
|
|
374
|
-
function getNestedValue(obj,
|
|
374
|
+
function getNestedValue(obj, path50) {
|
|
375
375
|
let current = obj;
|
|
376
|
-
for (const key of
|
|
376
|
+
for (const key of path50.split(".")) current = stepInto(current, key);
|
|
377
377
|
return current;
|
|
378
378
|
}
|
|
379
379
|
|
|
@@ -414,8 +414,8 @@ function stepIntoNested(container, key, nextKey) {
|
|
|
414
414
|
}
|
|
415
415
|
return ensureObject(container, resolved);
|
|
416
416
|
}
|
|
417
|
-
function setNestedValue(obj,
|
|
418
|
-
const keys =
|
|
417
|
+
function setNestedValue(obj, path50, value) {
|
|
418
|
+
const keys = path50.split(".");
|
|
419
419
|
const result = { ...obj };
|
|
420
420
|
let current = result;
|
|
421
421
|
for (let i = 0; i < keys.length - 1; i++) {
|
|
@@ -3190,11 +3190,11 @@ function registerPlanCommands(cmd) {
|
|
|
3190
3190
|
cmd.command("phase-done <id> <phase>").description("Signal that a plan phase is complete").action(phaseDone);
|
|
3191
3191
|
}
|
|
3192
3192
|
function registerRunCommands(cmd) {
|
|
3193
|
-
cmd.command("next").description("Pick and run the next backlog item, or open /draft if none").option("--
|
|
3194
|
-
(opts) => next({ allowEdits: opts.
|
|
3193
|
+
cmd.command("next").description("Pick and run the next backlog item, or open /draft if none").option("-w, --write", "Run Claude with acceptEdits permission mode").action(
|
|
3194
|
+
(opts) => next({ allowEdits: opts.write })
|
|
3195
3195
|
);
|
|
3196
|
-
cmd.command("run <id>").description("Run a backlog item's plan phase-by-phase with Claude").option("--
|
|
3197
|
-
(id, opts) => run2(id, { allowEdits: opts.
|
|
3196
|
+
cmd.command("run <id>").description("Run a backlog item's plan phase-by-phase with Claude").option("-w, --write", "Run Claude with acceptEdits permission mode").action(
|
|
3197
|
+
(id, opts) => run2(id, { allowEdits: opts.write })
|
|
3198
3198
|
);
|
|
3199
3199
|
}
|
|
3200
3200
|
function registerBacklog(program2) {
|
|
@@ -3298,12 +3298,12 @@ function getCliReadsPath() {
|
|
|
3298
3298
|
var cachedLines;
|
|
3299
3299
|
function getCliReadsLines() {
|
|
3300
3300
|
if (cachedLines) return cachedLines;
|
|
3301
|
-
const
|
|
3302
|
-
if (!existsSync18(
|
|
3301
|
+
const path50 = getCliReadsPath();
|
|
3302
|
+
if (!existsSync18(path50)) {
|
|
3303
3303
|
cachedLines = [];
|
|
3304
3304
|
return cachedLines;
|
|
3305
3305
|
}
|
|
3306
|
-
cachedLines = readFileSync13(
|
|
3306
|
+
cachedLines = readFileSync13(path50, "utf-8").split("\n").filter((line) => line.trim() !== "");
|
|
3307
3307
|
return cachedLines;
|
|
3308
3308
|
}
|
|
3309
3309
|
function loadCliReads() {
|
|
@@ -3658,14 +3658,14 @@ function showProgress(p, label2) {
|
|
|
3658
3658
|
const pct = Math.round(p.done / p.total * 100);
|
|
3659
3659
|
process.stderr.write(`\r\x1B[K[${pct}%] Scanning ${label2}...`);
|
|
3660
3660
|
}
|
|
3661
|
-
async function resolveCommand(cli,
|
|
3662
|
-
showProgress(p,
|
|
3663
|
-
const subHelp = await runHelp([cli, ...
|
|
3661
|
+
async function resolveCommand(cli, path50, description, depth, p) {
|
|
3662
|
+
showProgress(p, path50.join(" "));
|
|
3663
|
+
const subHelp = await runHelp([cli, ...path50]);
|
|
3664
3664
|
if (!subHelp || !hasSubcommands(subHelp)) {
|
|
3665
|
-
return [{ path:
|
|
3665
|
+
return [{ path: path50, description }];
|
|
3666
3666
|
}
|
|
3667
|
-
const children = await discoverAt(cli,
|
|
3668
|
-
return children.length > 0 ? children : [{ path:
|
|
3667
|
+
const children = await discoverAt(cli, path50, depth + 1, p);
|
|
3668
|
+
return children.length > 0 ? children : [{ path: path50, description }];
|
|
3669
3669
|
}
|
|
3670
3670
|
async function discoverAt(cli, parentPath, depth, p) {
|
|
3671
3671
|
if (depth > SAFETY_DEPTH) return [];
|
|
@@ -3813,9 +3813,9 @@ function logPath(cli) {
|
|
|
3813
3813
|
return join13(homedir4(), ".assist", `cli-discover-${safeName}.log`);
|
|
3814
3814
|
}
|
|
3815
3815
|
function readCache(cli) {
|
|
3816
|
-
const
|
|
3817
|
-
if (!existsSync20(
|
|
3818
|
-
return readFileSync15(
|
|
3816
|
+
const path50 = logPath(cli);
|
|
3817
|
+
if (!existsSync20(path50)) return void 0;
|
|
3818
|
+
return readFileSync15(path50, "utf-8");
|
|
3819
3819
|
}
|
|
3820
3820
|
function writeCache(cli, output) {
|
|
3821
3821
|
const dir = join13(homedir4(), ".assist");
|
|
@@ -5646,10 +5646,10 @@ function getStorePath(filename) {
|
|
|
5646
5646
|
return join19(getStoreDir(), filename);
|
|
5647
5647
|
}
|
|
5648
5648
|
function loadJson(filename) {
|
|
5649
|
-
const
|
|
5650
|
-
if (existsSync26(
|
|
5649
|
+
const path50 = getStorePath(filename);
|
|
5650
|
+
if (existsSync26(path50)) {
|
|
5651
5651
|
try {
|
|
5652
|
-
return JSON.parse(readFileSync21(
|
|
5652
|
+
return JSON.parse(readFileSync21(path50, "utf-8"));
|
|
5653
5653
|
} catch {
|
|
5654
5654
|
return {};
|
|
5655
5655
|
}
|
|
@@ -6042,7 +6042,7 @@ function validateLine(line) {
|
|
|
6042
6042
|
process.exit(1);
|
|
6043
6043
|
}
|
|
6044
6044
|
}
|
|
6045
|
-
function comment(
|
|
6045
|
+
function comment(path50, line, body) {
|
|
6046
6046
|
validateBody(body);
|
|
6047
6047
|
validateLine(line);
|
|
6048
6048
|
try {
|
|
@@ -6062,7 +6062,7 @@ function comment(path49, line, body) {
|
|
|
6062
6062
|
"-f",
|
|
6063
6063
|
`body=${body}`,
|
|
6064
6064
|
"-f",
|
|
6065
|
-
`path=${
|
|
6065
|
+
`path=${path50}`,
|
|
6066
6066
|
"-F",
|
|
6067
6067
|
`line=${line}`
|
|
6068
6068
|
],
|
|
@@ -6071,7 +6071,7 @@ function comment(path49, line, body) {
|
|
|
6071
6071
|
if (result.status !== 0) {
|
|
6072
6072
|
throw new Error(result.stderr || result.stdout);
|
|
6073
6073
|
}
|
|
6074
|
-
console.log(`Added review comment on ${
|
|
6074
|
+
console.log(`Added review comment on ${path50}:${line}`);
|
|
6075
6075
|
} finally {
|
|
6076
6076
|
unlinkSync5(queryFile);
|
|
6077
6077
|
}
|
|
@@ -6570,8 +6570,8 @@ function registerPrs(program2) {
|
|
|
6570
6570
|
prsCommand.command("wontfix <comment-id> <reason>").description("Reply with reason and resolve thread").action((commentId, reason) => {
|
|
6571
6571
|
wontfix(Number.parseInt(commentId, 10), reason);
|
|
6572
6572
|
});
|
|
6573
|
-
prsCommand.command("comment <path> <line> <body>").description("Add a line comment to the pending review").action((
|
|
6574
|
-
comment(
|
|
6573
|
+
prsCommand.command("comment <path> <line> <body>").description("Add a line comment to the pending review").action((path50, line, body) => {
|
|
6574
|
+
comment(path50, Number.parseInt(line, 10), body);
|
|
6575
6575
|
});
|
|
6576
6576
|
}
|
|
6577
6577
|
|
|
@@ -6823,10 +6823,10 @@ function resolveOpSecret(reference) {
|
|
|
6823
6823
|
}
|
|
6824
6824
|
|
|
6825
6825
|
// src/commands/ravendb/ravenFetch.ts
|
|
6826
|
-
async function ravenFetch(connection,
|
|
6826
|
+
async function ravenFetch(connection, path50) {
|
|
6827
6827
|
const apiKey = resolveOpSecret(connection.apiKeyRef);
|
|
6828
6828
|
let accessToken = await getAccessToken(apiKey);
|
|
6829
|
-
const url = `${connection.url}${
|
|
6829
|
+
const url = `${connection.url}${path50}`;
|
|
6830
6830
|
const headers = {
|
|
6831
6831
|
Authorization: `Bearer ${accessToken}`,
|
|
6832
6832
|
"Content-Type": "application/json"
|
|
@@ -6916,16 +6916,16 @@ import chalk82 from "chalk";
|
|
|
6916
6916
|
// src/commands/ravendb/buildQueryPath.ts
|
|
6917
6917
|
function buildQueryPath(opts) {
|
|
6918
6918
|
const db = encodeURIComponent(opts.db);
|
|
6919
|
-
let
|
|
6919
|
+
let path50;
|
|
6920
6920
|
if (opts.collection) {
|
|
6921
|
-
|
|
6921
|
+
path50 = `/databases/${db}/indexes/dynamic/${encodeURIComponent(opts.collection)}?start=${opts.start}&pageSize=${opts.pageSize}&sort=${encodeURIComponent(opts.sort)}`;
|
|
6922
6922
|
} else {
|
|
6923
|
-
|
|
6923
|
+
path50 = `/databases/${db}/queries?start=${opts.start}&pageSize=${opts.pageSize}`;
|
|
6924
6924
|
}
|
|
6925
6925
|
if (opts.query) {
|
|
6926
|
-
|
|
6926
|
+
path50 += `&query=${encodeURIComponent(opts.query)}`;
|
|
6927
6927
|
}
|
|
6928
|
-
return
|
|
6928
|
+
return path50;
|
|
6929
6929
|
}
|
|
6930
6930
|
|
|
6931
6931
|
// src/commands/ravendb/fetchAllPages.ts
|
|
@@ -6934,7 +6934,7 @@ async function fetchAllPages(connection, opts) {
|
|
|
6934
6934
|
let start3 = 0;
|
|
6935
6935
|
while (true) {
|
|
6936
6936
|
const effectivePageSize = opts.limit !== void 0 ? Math.min(opts.pageSize, opts.limit - allResults.length) : opts.pageSize;
|
|
6937
|
-
const
|
|
6937
|
+
const path50 = buildQueryPath({
|
|
6938
6938
|
db: connection.database,
|
|
6939
6939
|
collection: opts.collection,
|
|
6940
6940
|
start: start3,
|
|
@@ -6942,7 +6942,7 @@ async function fetchAllPages(connection, opts) {
|
|
|
6942
6942
|
sort: opts.sort,
|
|
6943
6943
|
query: opts.query
|
|
6944
6944
|
});
|
|
6945
|
-
const data = await ravenFetch(connection,
|
|
6945
|
+
const data = await ravenFetch(connection, path50);
|
|
6946
6946
|
const results = data.Results ?? [];
|
|
6947
6947
|
const totalResults = data.TotalResults ?? 0;
|
|
6948
6948
|
if (results.length === 0) break;
|
|
@@ -7202,7 +7202,7 @@ async function check(pattern2, options2) {
|
|
|
7202
7202
|
}
|
|
7203
7203
|
|
|
7204
7204
|
// src/commands/refactor/extract/index.ts
|
|
7205
|
-
import
|
|
7205
|
+
import path33 from "path";
|
|
7206
7206
|
import chalk87 from "chalk";
|
|
7207
7207
|
|
|
7208
7208
|
// src/commands/refactor/extract/applyExtraction.ts
|
|
@@ -7651,6 +7651,21 @@ function resolveBarrel(functionName, sourcePath, destPath, project) {
|
|
|
7651
7651
|
};
|
|
7652
7652
|
}
|
|
7653
7653
|
|
|
7654
|
+
// src/commands/refactor/extract/rewriteImportPaths.ts
|
|
7655
|
+
import path30 from "path";
|
|
7656
|
+
function rewriteImportPaths(imports, sourcePath, destPath) {
|
|
7657
|
+
const sourceDir = path30.dirname(sourcePath);
|
|
7658
|
+
const destDir = path30.dirname(destPath);
|
|
7659
|
+
return imports.map((imp) => {
|
|
7660
|
+
if (!imp.moduleSpecifier.startsWith(".")) return imp;
|
|
7661
|
+
const absolute = path30.resolve(sourceDir, imp.moduleSpecifier);
|
|
7662
|
+
let rel = path30.relative(destDir, absolute).replace(/\\/g, "/");
|
|
7663
|
+
if (rel === "") rel = `../${path30.basename(absolute)}`;
|
|
7664
|
+
else if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
7665
|
+
return { ...imp, moduleSpecifier: rel };
|
|
7666
|
+
});
|
|
7667
|
+
}
|
|
7668
|
+
|
|
7654
7669
|
// src/commands/refactor/extract/sourceReferencesName.ts
|
|
7655
7670
|
import { SyntaxKind as SyntaxKind10 } from "ts-morph";
|
|
7656
7671
|
var DECLARATION_KINDS = /* @__PURE__ */ new Set([
|
|
@@ -7686,12 +7701,17 @@ function sourceReferencesName(sourceFile, functionName, extractedNames) {
|
|
|
7686
7701
|
function buildPlan(functionName, sourceFile, sourcePath, destPath, project) {
|
|
7687
7702
|
const analysis = analyseTarget(sourceFile, functionName);
|
|
7688
7703
|
const sourceRelPath = getRelativeImportPath(destPath, sourcePath);
|
|
7704
|
+
const rewrittenImports = rewriteImportPaths(
|
|
7705
|
+
analysis.imports,
|
|
7706
|
+
sourcePath,
|
|
7707
|
+
destPath
|
|
7708
|
+
);
|
|
7689
7709
|
const { functionTexts: _, ...planFields } = analysis;
|
|
7690
7710
|
return {
|
|
7691
7711
|
...planFields,
|
|
7692
7712
|
destContent: buildDestinationContent(
|
|
7693
7713
|
analysis.functionTexts,
|
|
7694
|
-
|
|
7714
|
+
rewrittenImports,
|
|
7695
7715
|
sourceRelPath,
|
|
7696
7716
|
analysis.exportedDeps
|
|
7697
7717
|
),
|
|
@@ -7708,7 +7728,7 @@ function buildPlan(functionName, sourceFile, sourcePath, destPath, project) {
|
|
|
7708
7728
|
}
|
|
7709
7729
|
|
|
7710
7730
|
// src/commands/refactor/extract/displayPlan.ts
|
|
7711
|
-
import
|
|
7731
|
+
import path31 from "path";
|
|
7712
7732
|
import chalk85 from "chalk";
|
|
7713
7733
|
function section(title) {
|
|
7714
7734
|
return `
|
|
@@ -7718,7 +7738,7 @@ function displayImporters(plan2, cwd) {
|
|
|
7718
7738
|
if (plan2.importersToUpdate.length === 0) return;
|
|
7719
7739
|
console.log(section("Update importers:"));
|
|
7720
7740
|
for (const imp of plan2.importersToUpdate) {
|
|
7721
|
-
const rel =
|
|
7741
|
+
const rel = path31.relative(cwd, imp.file.getFilePath());
|
|
7722
7742
|
console.log(` ${chalk85.dim(rel)}: \u2192 import from "${imp.relPath}"`);
|
|
7723
7743
|
}
|
|
7724
7744
|
}
|
|
@@ -7759,11 +7779,11 @@ function displayPlan(functionName, relDest, plan2, cwd) {
|
|
|
7759
7779
|
|
|
7760
7780
|
// src/commands/refactor/extract/loadProjectFile.ts
|
|
7761
7781
|
import fs17 from "fs";
|
|
7762
|
-
import
|
|
7782
|
+
import path32 from "path";
|
|
7763
7783
|
import chalk86 from "chalk";
|
|
7764
7784
|
import { Project as Project2 } from "ts-morph";
|
|
7765
7785
|
function findTsConfig(sourcePath) {
|
|
7766
|
-
const rootConfig =
|
|
7786
|
+
const rootConfig = path32.resolve("tsconfig.json");
|
|
7767
7787
|
if (!fs17.existsSync(rootConfig)) return rootConfig;
|
|
7768
7788
|
const raw = fs17.readFileSync(rootConfig, "utf-8");
|
|
7769
7789
|
const stripped = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
@@ -7775,8 +7795,8 @@ function findTsConfig(sourcePath) {
|
|
|
7775
7795
|
}
|
|
7776
7796
|
if (!parsed.references?.length) return rootConfig;
|
|
7777
7797
|
for (const ref of parsed.references) {
|
|
7778
|
-
const refPath =
|
|
7779
|
-
const configPath = fs17.statSync(refPath, { throwIfNoEntry: false })?.isDirectory() ?
|
|
7798
|
+
const refPath = path32.resolve(ref.path);
|
|
7799
|
+
const configPath = fs17.statSync(refPath, { throwIfNoEntry: false })?.isDirectory() ? path32.join(refPath, "tsconfig.json") : refPath;
|
|
7780
7800
|
if (!fs17.existsSync(configPath)) continue;
|
|
7781
7801
|
const project = new Project2({ tsConfigFilePath: configPath });
|
|
7782
7802
|
if (project.getSourceFile(sourcePath)) return configPath;
|
|
@@ -7784,7 +7804,7 @@ function findTsConfig(sourcePath) {
|
|
|
7784
7804
|
return rootConfig;
|
|
7785
7805
|
}
|
|
7786
7806
|
function loadProjectFile(file) {
|
|
7787
|
-
const sourcePath =
|
|
7807
|
+
const sourcePath = path32.resolve(file);
|
|
7788
7808
|
const tsConfigPath = findTsConfig(sourcePath);
|
|
7789
7809
|
const project = new Project2({
|
|
7790
7810
|
tsConfigFilePath: tsConfigPath
|
|
@@ -7799,10 +7819,10 @@ function loadProjectFile(file) {
|
|
|
7799
7819
|
|
|
7800
7820
|
// src/commands/refactor/extract/index.ts
|
|
7801
7821
|
async function extract(file, functionName, destination, options2 = {}) {
|
|
7802
|
-
const sourcePath =
|
|
7803
|
-
const destPath =
|
|
7822
|
+
const sourcePath = path33.resolve(file);
|
|
7823
|
+
const destPath = path33.resolve(destination);
|
|
7804
7824
|
const cwd = process.cwd();
|
|
7805
|
-
const relDest =
|
|
7825
|
+
const relDest = path33.relative(cwd, destPath);
|
|
7806
7826
|
const { project, sourceFile } = loadProjectFile(file);
|
|
7807
7827
|
const plan2 = buildPlan(
|
|
7808
7828
|
functionName,
|
|
@@ -7849,13 +7869,13 @@ function ignore(file) {
|
|
|
7849
7869
|
}
|
|
7850
7870
|
|
|
7851
7871
|
// src/commands/refactor/rename/index.ts
|
|
7852
|
-
import
|
|
7872
|
+
import path34 from "path";
|
|
7853
7873
|
import chalk89 from "chalk";
|
|
7854
7874
|
async function rename(source, destination, options2 = {}) {
|
|
7855
|
-
const destPath =
|
|
7875
|
+
const destPath = path34.resolve(destination);
|
|
7856
7876
|
const cwd = process.cwd();
|
|
7857
|
-
const relSource =
|
|
7858
|
-
const relDest =
|
|
7877
|
+
const relSource = path34.relative(cwd, path34.resolve(source));
|
|
7878
|
+
const relDest = path34.relative(cwd, destPath);
|
|
7859
7879
|
const { project, sourceFile } = loadProjectFile(source);
|
|
7860
7880
|
console.log(chalk89.bold(`Rename: ${relSource} \u2192 ${relDest}`));
|
|
7861
7881
|
if (options2.apply) {
|
|
@@ -7868,7 +7888,7 @@ async function rename(source, destination, options2 = {}) {
|
|
|
7868
7888
|
}
|
|
7869
7889
|
|
|
7870
7890
|
// src/commands/refactor/renameSymbol/index.ts
|
|
7871
|
-
import
|
|
7891
|
+
import path36 from "path";
|
|
7872
7892
|
import chalk90 from "chalk";
|
|
7873
7893
|
import { Project as Project3 } from "ts-morph";
|
|
7874
7894
|
|
|
@@ -7897,12 +7917,12 @@ function findSymbol(sourceFile, symbolName) {
|
|
|
7897
7917
|
}
|
|
7898
7918
|
|
|
7899
7919
|
// src/commands/refactor/renameSymbol/groupReferences.ts
|
|
7900
|
-
import
|
|
7920
|
+
import path35 from "path";
|
|
7901
7921
|
function groupReferences(symbol, cwd) {
|
|
7902
7922
|
const refs = symbol.findReferencesAsNodes();
|
|
7903
7923
|
const grouped = /* @__PURE__ */ new Map();
|
|
7904
7924
|
for (const ref of refs) {
|
|
7905
|
-
const refFile =
|
|
7925
|
+
const refFile = path35.relative(cwd, ref.getSourceFile().getFilePath());
|
|
7906
7926
|
const lines = grouped.get(refFile) ?? [];
|
|
7907
7927
|
if (!grouped.has(refFile)) grouped.set(refFile, lines);
|
|
7908
7928
|
lines.push(ref.getStartLineNumber());
|
|
@@ -7912,8 +7932,8 @@ function groupReferences(symbol, cwd) {
|
|
|
7912
7932
|
|
|
7913
7933
|
// src/commands/refactor/renameSymbol/index.ts
|
|
7914
7934
|
async function renameSymbol(file, oldName, newName, options2 = {}) {
|
|
7915
|
-
const filePath =
|
|
7916
|
-
const tsConfigPath =
|
|
7935
|
+
const filePath = path36.resolve(file);
|
|
7936
|
+
const tsConfigPath = path36.resolve("tsconfig.json");
|
|
7917
7937
|
const cwd = process.cwd();
|
|
7918
7938
|
const project = new Project3({ tsConfigFilePath: tsConfigPath });
|
|
7919
7939
|
const sourceFile = project.getSourceFile(filePath);
|
|
@@ -7948,11 +7968,11 @@ Renamed ${oldName} \u2192 ${newName}`));
|
|
|
7948
7968
|
}
|
|
7949
7969
|
|
|
7950
7970
|
// src/commands/refactor/restructure/index.ts
|
|
7951
|
-
import
|
|
7971
|
+
import path45 from "path";
|
|
7952
7972
|
import chalk93 from "chalk";
|
|
7953
7973
|
|
|
7954
7974
|
// src/commands/refactor/restructure/buildImportGraph/index.ts
|
|
7955
|
-
import
|
|
7975
|
+
import path37 from "path";
|
|
7956
7976
|
import ts7 from "typescript";
|
|
7957
7977
|
|
|
7958
7978
|
// src/commands/refactor/restructure/buildImportGraph/getImportSpecifiers.ts
|
|
@@ -7979,7 +7999,7 @@ function loadParsedConfig(tsConfigPath) {
|
|
|
7979
7999
|
return ts7.parseJsonConfigFileContent(
|
|
7980
8000
|
configFile.config,
|
|
7981
8001
|
ts7.sys,
|
|
7982
|
-
|
|
8002
|
+
path37.dirname(tsConfigPath)
|
|
7983
8003
|
);
|
|
7984
8004
|
}
|
|
7985
8005
|
function addToSetMap(map, key, value) {
|
|
@@ -7995,7 +8015,7 @@ function resolveImport(specifier, filePath, options2) {
|
|
|
7995
8015
|
const resolved = ts7.resolveModuleName(specifier, filePath, options2, ts7.sys);
|
|
7996
8016
|
const resolvedPath = resolved.resolvedModule?.resolvedFileName;
|
|
7997
8017
|
if (!resolvedPath || resolvedPath.includes("node_modules")) return null;
|
|
7998
|
-
return
|
|
8018
|
+
return path37.resolve(resolvedPath);
|
|
7999
8019
|
}
|
|
8000
8020
|
function buildImportGraph(candidateFiles, tsConfigPath) {
|
|
8001
8021
|
const parsed = loadParsedConfig(tsConfigPath);
|
|
@@ -8004,7 +8024,7 @@ function buildImportGraph(candidateFiles, tsConfigPath) {
|
|
|
8004
8024
|
const importedBy = /* @__PURE__ */ new Map();
|
|
8005
8025
|
const imports = /* @__PURE__ */ new Map();
|
|
8006
8026
|
for (const sourceFile of program2.getSourceFiles()) {
|
|
8007
|
-
const filePath =
|
|
8027
|
+
const filePath = path37.resolve(sourceFile.fileName);
|
|
8008
8028
|
if (filePath.includes("node_modules")) continue;
|
|
8009
8029
|
for (const specifier of getImportSpecifiers(sourceFile)) {
|
|
8010
8030
|
const absTarget = resolveImport(specifier, filePath, parsed.options);
|
|
@@ -8018,12 +8038,12 @@ function buildImportGraph(candidateFiles, tsConfigPath) {
|
|
|
8018
8038
|
}
|
|
8019
8039
|
|
|
8020
8040
|
// src/commands/refactor/restructure/clusterDirectories.ts
|
|
8021
|
-
import
|
|
8041
|
+
import path38 from "path";
|
|
8022
8042
|
function clusterDirectories(graph) {
|
|
8023
8043
|
const dirImportedBy = /* @__PURE__ */ new Map();
|
|
8024
8044
|
for (const edge of graph.edges) {
|
|
8025
|
-
const sourceDir =
|
|
8026
|
-
const targetDir =
|
|
8045
|
+
const sourceDir = path38.dirname(edge.source);
|
|
8046
|
+
const targetDir = path38.dirname(edge.target);
|
|
8027
8047
|
if (sourceDir === targetDir) continue;
|
|
8028
8048
|
if (!graph.files.has(edge.target)) continue;
|
|
8029
8049
|
const existing = dirImportedBy.get(targetDir) ?? /* @__PURE__ */ new Set();
|
|
@@ -8051,20 +8071,20 @@ function clusterDirectories(graph) {
|
|
|
8051
8071
|
return clusters;
|
|
8052
8072
|
}
|
|
8053
8073
|
function isAncestor(ancestor, descendant) {
|
|
8054
|
-
const rel =
|
|
8074
|
+
const rel = path38.relative(ancestor, descendant);
|
|
8055
8075
|
return !rel.startsWith("..") && rel !== "";
|
|
8056
8076
|
}
|
|
8057
8077
|
|
|
8058
8078
|
// src/commands/refactor/restructure/clusterFiles.ts
|
|
8059
|
-
import
|
|
8079
|
+
import path39 from "path";
|
|
8060
8080
|
function findRootParent(file, importedBy, visited) {
|
|
8061
8081
|
const importers = importedBy.get(file);
|
|
8062
8082
|
if (!importers || importers.size !== 1) return file;
|
|
8063
8083
|
const parent = [...importers][0];
|
|
8064
|
-
const parentDir =
|
|
8065
|
-
const fileDir =
|
|
8084
|
+
const parentDir = path39.dirname(parent);
|
|
8085
|
+
const fileDir = path39.dirname(file);
|
|
8066
8086
|
if (parentDir !== fileDir) return file;
|
|
8067
|
-
if (
|
|
8087
|
+
if (path39.basename(parent, path39.extname(parent)) === "index") return file;
|
|
8068
8088
|
if (visited.has(parent)) return file;
|
|
8069
8089
|
visited.add(parent);
|
|
8070
8090
|
return findRootParent(parent, importedBy, visited);
|
|
@@ -8072,16 +8092,16 @@ function findRootParent(file, importedBy, visited) {
|
|
|
8072
8092
|
function clusterFiles(graph) {
|
|
8073
8093
|
const clusters = /* @__PURE__ */ new Map();
|
|
8074
8094
|
for (const file of graph.files) {
|
|
8075
|
-
const basename7 =
|
|
8095
|
+
const basename7 = path39.basename(file, path39.extname(file));
|
|
8076
8096
|
if (basename7 === "index") continue;
|
|
8077
8097
|
const importers = graph.importedBy.get(file);
|
|
8078
8098
|
if (!importers || importers.size !== 1) continue;
|
|
8079
8099
|
const parent = [...importers][0];
|
|
8080
8100
|
if (!graph.files.has(parent)) continue;
|
|
8081
|
-
const parentDir =
|
|
8082
|
-
const fileDir =
|
|
8101
|
+
const parentDir = path39.dirname(parent);
|
|
8102
|
+
const fileDir = path39.dirname(file);
|
|
8083
8103
|
if (parentDir !== fileDir) continue;
|
|
8084
|
-
const parentBasename =
|
|
8104
|
+
const parentBasename = path39.basename(parent, path39.extname(parent));
|
|
8085
8105
|
if (parentBasename === "index") continue;
|
|
8086
8106
|
const root = findRootParent(parent, graph.importedBy, /* @__PURE__ */ new Set([file]));
|
|
8087
8107
|
if (!root || root === file) continue;
|
|
@@ -8093,7 +8113,7 @@ function clusterFiles(graph) {
|
|
|
8093
8113
|
}
|
|
8094
8114
|
|
|
8095
8115
|
// src/commands/refactor/restructure/computeRewrites/index.ts
|
|
8096
|
-
import
|
|
8116
|
+
import path40 from "path";
|
|
8097
8117
|
|
|
8098
8118
|
// src/commands/refactor/restructure/computeRewrites/applyRewrites.ts
|
|
8099
8119
|
import fs19 from "fs";
|
|
@@ -8147,7 +8167,7 @@ function normalizeSpecifier(rel) {
|
|
|
8147
8167
|
);
|
|
8148
8168
|
}
|
|
8149
8169
|
function computeSpecifier(fromFile, toFile) {
|
|
8150
|
-
return normalizeSpecifier(
|
|
8170
|
+
return normalizeSpecifier(path40.relative(path40.dirname(fromFile), toFile));
|
|
8151
8171
|
}
|
|
8152
8172
|
function isAffected(edge, moveMap) {
|
|
8153
8173
|
return moveMap.has(edge.target) || moveMap.has(edge.source);
|
|
@@ -8191,10 +8211,10 @@ function computeRewrites(moves, edges, allProjectFiles) {
|
|
|
8191
8211
|
}
|
|
8192
8212
|
|
|
8193
8213
|
// src/commands/refactor/restructure/displayPlan.ts
|
|
8194
|
-
import
|
|
8214
|
+
import path41 from "path";
|
|
8195
8215
|
import chalk91 from "chalk";
|
|
8196
8216
|
function relPath(filePath) {
|
|
8197
|
-
return
|
|
8217
|
+
return path41.relative(process.cwd(), filePath);
|
|
8198
8218
|
}
|
|
8199
8219
|
function displayMoves(plan2) {
|
|
8200
8220
|
if (plan2.moves.length === 0) return;
|
|
@@ -8244,33 +8264,33 @@ Summary: ${plan2.moves.length} file(s) moved, ${plan2.rewrites.length} imports r
|
|
|
8244
8264
|
|
|
8245
8265
|
// src/commands/refactor/restructure/executePlan.ts
|
|
8246
8266
|
import fs20 from "fs";
|
|
8247
|
-
import
|
|
8267
|
+
import path42 from "path";
|
|
8248
8268
|
import chalk92 from "chalk";
|
|
8249
8269
|
function executePlan(plan2) {
|
|
8250
8270
|
const updatedContents = applyRewrites(plan2.rewrites);
|
|
8251
8271
|
for (const [file, content] of updatedContents) {
|
|
8252
8272
|
fs20.writeFileSync(file, content, "utf-8");
|
|
8253
8273
|
console.log(
|
|
8254
|
-
chalk92.cyan(` Rewrote imports in ${
|
|
8274
|
+
chalk92.cyan(` Rewrote imports in ${path42.relative(process.cwd(), file)}`)
|
|
8255
8275
|
);
|
|
8256
8276
|
}
|
|
8257
8277
|
for (const dir of plan2.newDirectories) {
|
|
8258
8278
|
fs20.mkdirSync(dir, { recursive: true });
|
|
8259
|
-
console.log(chalk92.green(` Created ${
|
|
8279
|
+
console.log(chalk92.green(` Created ${path42.relative(process.cwd(), dir)}/`));
|
|
8260
8280
|
}
|
|
8261
8281
|
for (const move of plan2.moves) {
|
|
8262
|
-
const targetDir =
|
|
8282
|
+
const targetDir = path42.dirname(move.to);
|
|
8263
8283
|
if (!fs20.existsSync(targetDir)) {
|
|
8264
8284
|
fs20.mkdirSync(targetDir, { recursive: true });
|
|
8265
8285
|
}
|
|
8266
8286
|
fs20.renameSync(move.from, move.to);
|
|
8267
8287
|
console.log(
|
|
8268
8288
|
chalk92.white(
|
|
8269
|
-
` Moved ${
|
|
8289
|
+
` Moved ${path42.relative(process.cwd(), move.from)} \u2192 ${path42.relative(process.cwd(), move.to)}`
|
|
8270
8290
|
)
|
|
8271
8291
|
);
|
|
8272
8292
|
}
|
|
8273
|
-
removeEmptyDirectories(plan2.moves.map((m) =>
|
|
8293
|
+
removeEmptyDirectories(plan2.moves.map((m) => path42.dirname(m.from)));
|
|
8274
8294
|
}
|
|
8275
8295
|
function removeEmptyDirectories(dirs) {
|
|
8276
8296
|
const unique = [...new Set(dirs)];
|
|
@@ -8281,7 +8301,7 @@ function removeEmptyDirectories(dirs) {
|
|
|
8281
8301
|
fs20.rmdirSync(dir);
|
|
8282
8302
|
console.log(
|
|
8283
8303
|
chalk92.dim(
|
|
8284
|
-
` Removed empty directory ${
|
|
8304
|
+
` Removed empty directory ${path42.relative(process.cwd(), dir)}`
|
|
8285
8305
|
)
|
|
8286
8306
|
);
|
|
8287
8307
|
}
|
|
@@ -8289,7 +8309,7 @@ function removeEmptyDirectories(dirs) {
|
|
|
8289
8309
|
}
|
|
8290
8310
|
|
|
8291
8311
|
// src/commands/refactor/restructure/planFileMoves/index.ts
|
|
8292
|
-
import
|
|
8312
|
+
import path44 from "path";
|
|
8293
8313
|
|
|
8294
8314
|
// src/commands/refactor/restructure/planFileMoves/shared.ts
|
|
8295
8315
|
import fs21 from "fs";
|
|
@@ -8304,9 +8324,9 @@ function checkDirConflict(result, label2, dir) {
|
|
|
8304
8324
|
|
|
8305
8325
|
// src/commands/refactor/restructure/planFileMoves/planDirectoryMoves.ts
|
|
8306
8326
|
import fs22 from "fs";
|
|
8307
|
-
import
|
|
8327
|
+
import path43 from "path";
|
|
8308
8328
|
function collectEntry(results, dir, entry) {
|
|
8309
|
-
const full =
|
|
8329
|
+
const full = path43.join(dir, entry.name);
|
|
8310
8330
|
const items = entry.isDirectory() ? listFilesRecursive(full) : [full];
|
|
8311
8331
|
results.push(...items);
|
|
8312
8332
|
}
|
|
@@ -8320,15 +8340,15 @@ function listFilesRecursive(dir) {
|
|
|
8320
8340
|
}
|
|
8321
8341
|
function addDirectoryFileMoves(moves, childDir, newLocation, reason) {
|
|
8322
8342
|
for (const file of listFilesRecursive(childDir)) {
|
|
8323
|
-
const rel =
|
|
8324
|
-
moves.push({ from: file, to:
|
|
8343
|
+
const rel = path43.relative(childDir, file);
|
|
8344
|
+
moves.push({ from: file, to: path43.join(newLocation, rel), reason });
|
|
8325
8345
|
}
|
|
8326
8346
|
}
|
|
8327
8347
|
function resolveChildDest(parentDir, childDir) {
|
|
8328
|
-
return
|
|
8348
|
+
return path43.join(parentDir, path43.basename(childDir));
|
|
8329
8349
|
}
|
|
8330
8350
|
function childMoveReason(parentDir) {
|
|
8331
|
-
return `Directory only imported from ${
|
|
8351
|
+
return `Directory only imported from ${path43.basename(parentDir)}/`;
|
|
8332
8352
|
}
|
|
8333
8353
|
function registerDirectoryMove(result, childDir, dest, parentDir) {
|
|
8334
8354
|
result.directories.push(dest);
|
|
@@ -8353,7 +8373,7 @@ function planDirectoryMoves(clusters) {
|
|
|
8353
8373
|
|
|
8354
8374
|
// src/commands/refactor/restructure/planFileMoves/index.ts
|
|
8355
8375
|
function childMoveData(child, newDir, parentBase) {
|
|
8356
|
-
const to =
|
|
8376
|
+
const to = path44.join(newDir, path44.basename(child));
|
|
8357
8377
|
return { from: child, to, reason: `Only imported by ${parentBase}` };
|
|
8358
8378
|
}
|
|
8359
8379
|
function addChildMoves(moves, children, newDir, parentBase) {
|
|
@@ -8361,15 +8381,15 @@ function addChildMoves(moves, children, newDir, parentBase) {
|
|
|
8361
8381
|
moves.push(childMoveData(child, newDir, parentBase));
|
|
8362
8382
|
}
|
|
8363
8383
|
function getBaseName(filePath) {
|
|
8364
|
-
return
|
|
8384
|
+
return path44.basename(filePath, path44.extname(filePath));
|
|
8365
8385
|
}
|
|
8366
8386
|
function resolveClusterDir(parent) {
|
|
8367
|
-
return
|
|
8387
|
+
return path44.join(path44.dirname(parent), getBaseName(parent));
|
|
8368
8388
|
}
|
|
8369
8389
|
function createParentMove(parent, newDir) {
|
|
8370
8390
|
return {
|
|
8371
8391
|
from: parent,
|
|
8372
|
-
to:
|
|
8392
|
+
to: path44.join(newDir, `index${path44.extname(parent)}`),
|
|
8373
8393
|
reason: `Main module of new ${getBaseName(parent)}/ directory`
|
|
8374
8394
|
};
|
|
8375
8395
|
}
|
|
@@ -8393,7 +8413,7 @@ function planFileMoves(clusters) {
|
|
|
8393
8413
|
|
|
8394
8414
|
// src/commands/refactor/restructure/index.ts
|
|
8395
8415
|
function buildPlan2(candidateFiles, tsConfigPath) {
|
|
8396
|
-
const candidates = new Set(candidateFiles.map((f) =>
|
|
8416
|
+
const candidates = new Set(candidateFiles.map((f) => path45.resolve(f)));
|
|
8397
8417
|
const graph = buildImportGraph(candidates, tsConfigPath);
|
|
8398
8418
|
const allProjectFiles = /* @__PURE__ */ new Set([
|
|
8399
8419
|
...graph.importedBy.keys(),
|
|
@@ -8416,7 +8436,7 @@ async function restructure(pattern2, options2 = {}) {
|
|
|
8416
8436
|
console.log(chalk93.yellow("No files found matching pattern"));
|
|
8417
8437
|
return;
|
|
8418
8438
|
}
|
|
8419
|
-
const tsConfigPath =
|
|
8439
|
+
const tsConfigPath = path45.resolve("tsconfig.json");
|
|
8420
8440
|
const plan2 = buildPlan2(files, tsConfigPath);
|
|
8421
8441
|
if (plan2.moves.length === 0) {
|
|
8422
8442
|
console.log(chalk93.green("No restructuring needed"));
|
|
@@ -10263,16 +10283,16 @@ async function statusLine() {
|
|
|
10263
10283
|
// src/commands/sync.ts
|
|
10264
10284
|
import * as fs25 from "fs";
|
|
10265
10285
|
import * as os from "os";
|
|
10266
|
-
import * as
|
|
10286
|
+
import * as path48 from "path";
|
|
10267
10287
|
import { fileURLToPath as fileURLToPath7 } from "url";
|
|
10268
10288
|
|
|
10269
10289
|
// src/commands/sync/syncClaudeMd.ts
|
|
10270
10290
|
import * as fs23 from "fs";
|
|
10271
|
-
import * as
|
|
10291
|
+
import * as path46 from "path";
|
|
10272
10292
|
import chalk105 from "chalk";
|
|
10273
10293
|
async function syncClaudeMd(claudeDir, targetBase, options2) {
|
|
10274
|
-
const source =
|
|
10275
|
-
const target =
|
|
10294
|
+
const source = path46.join(claudeDir, "CLAUDE.md");
|
|
10295
|
+
const target = path46.join(targetBase, "CLAUDE.md");
|
|
10276
10296
|
const sourceContent = fs23.readFileSync(source, "utf-8");
|
|
10277
10297
|
if (fs23.existsSync(target)) {
|
|
10278
10298
|
const targetContent = fs23.readFileSync(target, "utf-8");
|
|
@@ -10298,11 +10318,11 @@ async function syncClaudeMd(claudeDir, targetBase, options2) {
|
|
|
10298
10318
|
|
|
10299
10319
|
// src/commands/sync/syncSettings.ts
|
|
10300
10320
|
import * as fs24 from "fs";
|
|
10301
|
-
import * as
|
|
10321
|
+
import * as path47 from "path";
|
|
10302
10322
|
import chalk106 from "chalk";
|
|
10303
10323
|
async function syncSettings(claudeDir, targetBase, options2) {
|
|
10304
|
-
const source =
|
|
10305
|
-
const target =
|
|
10324
|
+
const source = path47.join(claudeDir, "settings.json");
|
|
10325
|
+
const target = path47.join(targetBase, "settings.json");
|
|
10306
10326
|
const sourceContent = fs24.readFileSync(source, "utf-8");
|
|
10307
10327
|
const mergedContent = JSON.stringify(JSON.parse(sourceContent), null, " ");
|
|
10308
10328
|
if (fs24.existsSync(target)) {
|
|
@@ -10338,21 +10358,21 @@ async function syncSettings(claudeDir, targetBase, options2) {
|
|
|
10338
10358
|
|
|
10339
10359
|
// src/commands/sync.ts
|
|
10340
10360
|
var __filename4 = fileURLToPath7(import.meta.url);
|
|
10341
|
-
var __dirname7 =
|
|
10361
|
+
var __dirname7 = path48.dirname(__filename4);
|
|
10342
10362
|
async function sync(options2) {
|
|
10343
|
-
const claudeDir =
|
|
10344
|
-
const targetBase =
|
|
10363
|
+
const claudeDir = path48.join(__dirname7, "..", "claude");
|
|
10364
|
+
const targetBase = path48.join(os.homedir(), ".claude");
|
|
10345
10365
|
syncCommands(claudeDir, targetBase);
|
|
10346
10366
|
await syncSettings(claudeDir, targetBase, { yes: options2?.yes });
|
|
10347
10367
|
await syncClaudeMd(claudeDir, targetBase, { yes: options2?.yes });
|
|
10348
10368
|
}
|
|
10349
10369
|
function syncCommands(claudeDir, targetBase) {
|
|
10350
|
-
const sourceDir =
|
|
10351
|
-
const targetDir =
|
|
10370
|
+
const sourceDir = path48.join(claudeDir, "commands");
|
|
10371
|
+
const targetDir = path48.join(targetBase, "commands");
|
|
10352
10372
|
fs25.mkdirSync(targetDir, { recursive: true });
|
|
10353
10373
|
const files = fs25.readdirSync(sourceDir);
|
|
10354
10374
|
for (const file of files) {
|
|
10355
|
-
fs25.copyFileSync(
|
|
10375
|
+
fs25.copyFileSync(path48.join(sourceDir, file), path48.join(targetDir, file));
|
|
10356
10376
|
console.log(`Copied ${file} to ${targetDir}`);
|
|
10357
10377
|
}
|
|
10358
10378
|
console.log(`Synced ${files.length} command(s) to ~/.claude/commands`);
|
|
@@ -10360,15 +10380,15 @@ function syncCommands(claudeDir, targetBase) {
|
|
|
10360
10380
|
|
|
10361
10381
|
// src/commands/update.ts
|
|
10362
10382
|
import { execSync as execSync40 } from "child_process";
|
|
10363
|
-
import * as
|
|
10383
|
+
import * as path49 from "path";
|
|
10364
10384
|
function isGlobalNpmInstall(dir) {
|
|
10365
10385
|
try {
|
|
10366
|
-
const resolved =
|
|
10367
|
-
if (resolved.split(
|
|
10386
|
+
const resolved = path49.resolve(dir);
|
|
10387
|
+
if (resolved.split(path49.sep).includes("node_modules")) {
|
|
10368
10388
|
return true;
|
|
10369
10389
|
}
|
|
10370
10390
|
const globalPrefix = execSync40("npm prefix -g", { stdio: "pipe" }).toString().trim();
|
|
10371
|
-
return resolved.toLowerCase().startsWith(
|
|
10391
|
+
return resolved.toLowerCase().startsWith(path49.resolve(globalPrefix).toLowerCase());
|
|
10372
10392
|
} catch {
|
|
10373
10393
|
return false;
|
|
10374
10394
|
}
|