@aloth/olcli 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -3
- package/dist/cli.js +231 -14
- package/dist/cli.js.map +1 -1
- package/dist/client.d.ts +18 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +46 -18
- package/dist/client.js.map +1 -1
- package/dist/mcp.js +71 -9
- package/dist/mcp.js.map +1 -1
- package/dist/paths.d.ts +28 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +64 -0
- package/dist/paths.js.map +1 -0
- package/dist/rename-plan.d.ts +46 -0
- package/dist/rename-plan.d.ts.map +1 -0
- package/dist/rename-plan.js +81 -0
- package/dist/rename-plan.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure planning logic for bulk project renames.
|
|
3
|
+
*
|
|
4
|
+
* Lives apart from the CLI so the MCP surface can compute and inspect the same
|
|
5
|
+
* plan without going through argument parsing. Two copies of these rules would
|
|
6
|
+
* drift, and the collision check is exactly the part that must not.
|
|
7
|
+
*/
|
|
8
|
+
export interface RenameCandidate {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
}
|
|
12
|
+
export interface PlannedRename {
|
|
13
|
+
id: string;
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SkippedRename {
|
|
18
|
+
name: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
}
|
|
21
|
+
export interface RenamePlanOptions {
|
|
22
|
+
/** Only consider projects whose name matches this regex source. */
|
|
23
|
+
match?: string;
|
|
24
|
+
/** Literal substring to replace. Takes precedence over regex replacement. */
|
|
25
|
+
search?: string;
|
|
26
|
+
/** Replacement text. Supports $1/$2 backrefs when used with `match`. */
|
|
27
|
+
replace?: string;
|
|
28
|
+
prefix?: string;
|
|
29
|
+
suffix?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface RenamePlan {
|
|
32
|
+
planned: PlannedRename[];
|
|
33
|
+
skipped: SkippedRename[];
|
|
34
|
+
/** Human-readable collision descriptions. Non-empty means: do not apply. */
|
|
35
|
+
collisions: string[];
|
|
36
|
+
}
|
|
37
|
+
export declare class RenamePlanError extends Error {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build the rename plan. Never performs I/O and never mutates its input.
|
|
41
|
+
*
|
|
42
|
+
* Throws RenamePlanError for operator mistakes (no transform, bad regex) so the
|
|
43
|
+
* caller can surface them before anything touches the network.
|
|
44
|
+
*/
|
|
45
|
+
export declare function planProjectRenames(projects: RenameCandidate[], options: RenamePlanOptions): RenamePlan;
|
|
46
|
+
//# sourceMappingURL=rename-plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-plan.d.ts","sourceRoot":"","sources":["../src/rename-plan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,4EAA4E;IAC5E,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,qBAAa,eAAgB,SAAQ,KAAK;CAAG;AAE7C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,eAAe,EAAE,EAC3B,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAqEZ"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure planning logic for bulk project renames.
|
|
3
|
+
*
|
|
4
|
+
* Lives apart from the CLI so the MCP surface can compute and inspect the same
|
|
5
|
+
* plan without going through argument parsing. Two copies of these rules would
|
|
6
|
+
* drift, and the collision check is exactly the part that must not.
|
|
7
|
+
*/
|
|
8
|
+
export class RenamePlanError extends Error {
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Build the rename plan. Never performs I/O and never mutates its input.
|
|
12
|
+
*
|
|
13
|
+
* Throws RenamePlanError for operator mistakes (no transform, bad regex) so the
|
|
14
|
+
* caller can surface them before anything touches the network.
|
|
15
|
+
*/
|
|
16
|
+
export function planProjectRenames(projects, options) {
|
|
17
|
+
const hasTransform = options.replace !== undefined || Boolean(options.prefix) || Boolean(options.suffix);
|
|
18
|
+
if (!hasTransform) {
|
|
19
|
+
throw new RenamePlanError('Nothing to do: pass replace, prefix or suffix.');
|
|
20
|
+
}
|
|
21
|
+
if (options.replace !== undefined && !options.search && !options.match) {
|
|
22
|
+
throw new RenamePlanError('replace needs either search (literal) or match (regex).');
|
|
23
|
+
}
|
|
24
|
+
let matcher;
|
|
25
|
+
if (options.match) {
|
|
26
|
+
try {
|
|
27
|
+
matcher = new RegExp(options.match);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
throw new RenamePlanError(`Invalid match regex: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const planned = [];
|
|
34
|
+
const skipped = [];
|
|
35
|
+
for (const p of projects) {
|
|
36
|
+
if (matcher && !matcher.test(p.name))
|
|
37
|
+
continue;
|
|
38
|
+
let next = p.name;
|
|
39
|
+
if (options.replace !== undefined) {
|
|
40
|
+
if (options.search) {
|
|
41
|
+
// split/join rather than replaceAll so the needle is always literal:
|
|
42
|
+
// project names routinely contain regex metacharacters like . ( ) [ ]
|
|
43
|
+
next = next.split(options.search).join(options.replace);
|
|
44
|
+
}
|
|
45
|
+
else if (matcher) {
|
|
46
|
+
next = next.replace(matcher, options.replace);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (options.prefix)
|
|
50
|
+
next = `${options.prefix}${next}`;
|
|
51
|
+
if (options.suffix)
|
|
52
|
+
next = `${next}${options.suffix}`;
|
|
53
|
+
next = next.trim();
|
|
54
|
+
if (!next) {
|
|
55
|
+
skipped.push({ name: p.name, reason: 'result would be empty' });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (next === p.name)
|
|
59
|
+
continue;
|
|
60
|
+
planned.push({ id: p.id, from: p.name, to: next });
|
|
61
|
+
}
|
|
62
|
+
// Overleaf tolerates duplicate project names, which makes a collision worse
|
|
63
|
+
// rather than harmless: nothing fails, and afterwards two projects are
|
|
64
|
+
// indistinguishable in every listing and in `olcli list`.
|
|
65
|
+
const targetCounts = new Map();
|
|
66
|
+
for (const p of planned)
|
|
67
|
+
targetCounts.set(p.to, (targetCounts.get(p.to) ?? 0) + 1);
|
|
68
|
+
const existing = new Set(projects.map((p) => p.name));
|
|
69
|
+
const renamedAway = new Set(planned.map((p) => p.from));
|
|
70
|
+
const collisions = [];
|
|
71
|
+
for (const [name, count] of targetCounts) {
|
|
72
|
+
if (count > 1) {
|
|
73
|
+
collisions.push(`${name} (${count} projects map to it)`);
|
|
74
|
+
}
|
|
75
|
+
else if (existing.has(name) && !renamedAway.has(name)) {
|
|
76
|
+
collisions.push(`${name} (an untouched project already has this name)`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { planned, skipped, collisions };
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=rename-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rename-plan.js","sourceRoot":"","sources":["../src/rename-plan.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoCH,MAAM,OAAO,eAAgB,SAAQ,KAAK;CAAG;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAA2B,EAC3B,OAA0B;IAE1B,MAAM,YAAY,GAChB,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtF,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,eAAe,CAAC,gDAAgD,CAAC,CAAC;IAC9E,CAAC;IACD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACvE,MAAM,IAAI,eAAe,CAAC,yDAAyD,CAAC,CAAC;IACvF,CAAC;IAED,IAAI,OAA2B,CAAC;IAChC,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAClB,IAAI,CAAC;YACH,OAAO,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,GAAY,EAAE,CAAC;YACtB,MAAM,IAAI,eAAe,CACvB,wBAAwB,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAoB,EAAE,CAAC;IACpC,MAAM,OAAO,GAAoB,EAAE,CAAC;IAEpC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,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