legacymaxxing 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 openclaw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # legacymaxxing
2
+
3
+ **A loop CLI that guides an AI agent through the code-modernization lifecycle.**
4
+
5
+ Instead of a human typing modernization commands at an agent one phase at a time,
6
+ legacymaxxing inverts the control: a deterministic, gated state-machine drives the
7
+ agent. It emits the next phase's prompt, runs the agent (Codex first) against a
8
+ legacy system, validates the artifacts the agent wrote, records the result, and
9
+ advances — pausing only at the human approval gate.
10
+
11
+ > **Status: early (v0.1).** Codex is the only real provider wired up; a Claude
12
+ > provider is planned via the same adapter. There is **no auto-commit / auto-PR**:
13
+ > legacymaxxing writes files and state, you land them. The `codex` provider path is
14
+ > not yet exercised in CI — the `mock` provider covers the pipeline. Treat the
15
+ > exact `codex exec` flags as needing a tune against your installed version.
16
+
17
+ It is the [`code-modernization` plugin](https://github.com/anthropics/claude-plugins-official/tree/main/plugins/code-modernization)
18
+ turned inside-out: the same `assess → map → extract → brief → transform/reimagine
19
+ → harden` lifecycle, but as a resumable CLI an agent can be looped against.
20
+
21
+ ## The lifecycle
22
+
23
+ ```
24
+ assess ─▶ map ─────▶ brief ──[human gate]──▶ transform ─┐ (mutating, --apply)
25
+ └────▶ extract ──▶ │ ├─▶ modernized/
26
+ └────────────────────────▶ reimagine (mutating)
27
+ assess ─▶ harden ─▶ security_remediation.patch (generated, never applied)
28
+ ```
29
+
30
+ - **assess / map / extract / brief** are read-only: the agent writes analysis docs
31
+ into `analysis/<system>/`. `brief` produces a plan and then **waits for you**.
32
+ - **transform / reimagine** are mutating: they write new code into
33
+ `modernized/<system>/` and require an approved brief, an explicit `--apply`, and
34
+ a clean git worktree.
35
+ - **harden** scans the legacy system and produces a reviewable patch — it is never
36
+ applied, and `legacy/` is never edited.
37
+
38
+ ## Quickstart
39
+
40
+ ```bash
41
+ legacymaxxing init --system billing --legacy legacy/billing # register + write state
42
+ legacymaxxing loop # run discovery, stop at brief gate
43
+ legacymaxxing report # see what was produced
44
+ legacymaxxing gate brief --approve # human approves the plan
45
+ legacymaxxing run transform --module interest-calc --apply # one strangler-fig rewrite
46
+ ```
47
+
48
+ Want to drive the agent yourself? `legacymaxxing next` prints the exact prompt for
49
+ the next runnable phase (no model call) so you can paste it into any agent.
50
+
51
+ ## CLI contract
52
+
53
+ - `stdout` is the result (`--json` for the stable machine shape; markdown body
54
+ otherwise); `stderr` is progress/diagnostics. `--quiet` mutes stderr.
55
+ - **Exit codes:** `0` ok · `1` runtime · `2` invalid usage · `3` dirty worktree ·
56
+ `4` provider auth · `5` provider quota · `6` validation/gate failed ·
57
+ `7` lock conflict / external-CLI failure · `8` malformed model output.
58
+ - State lives in `.legacymaxxing/` (runtime subdirs gitignored). Every run, phase,
59
+ and gate decision is a JSON record; reruns are deterministic and resumable.
60
+
61
+ See [`SPEC.md`](SPEC.md) for the full contract and [`AGENTS.md`](AGENTS.md) for
62
+ contributor guidelines. MIT licensed.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { type Flags } from "./context.js";
3
+ type ParsedArgs = {
4
+ command: string;
5
+ positionals: string[];
6
+ flags: Flags;
7
+ };
8
+ export declare function parseArgs(argv: string[]): ParsedArgs;
9
+ export declare function validateCommandFlags(command: string, flags: Flags): void;
10
+ export declare function main(argv: string[]): Promise<void>;
11
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync, realpathSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { ToolError } from "./errors.js";
6
+ import { makeContext, resolveGlobalOptions } from "./context.js";
7
+ import { cleanLocksCommand, doctorCommand, gateCommand, initCommand, loopCommand, nextCommand, reportCommand, revalidateCommand, runCommand, statusCommand, } from "./commands.js";
8
+ const here = dirname(fileURLToPath(import.meta.url));
9
+ const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
10
+ // Per-command flag whitelist (global flags are allowed everywhere). Validated
11
+ // BEFORE any side effect; an unknown flag is exit 2, never silently ignored.
12
+ const commandFlags = {
13
+ init: new Set(["system", "legacy", "force"]),
14
+ status: new Set([]),
15
+ next: new Set(["module", "vision"]),
16
+ run: new Set(["phase", "module", "vision", "apply", "yes"]),
17
+ loop: new Set(["until"]),
18
+ gate: new Set(["phase", "approve", "reject", "note"]),
19
+ report: new Set([]),
20
+ revalidate: new Set(["phase"]),
21
+ doctor: new Set([]),
22
+ "clean-locks": new Set([]),
23
+ };
24
+ const globalFlags = new Set([
25
+ "root",
26
+ "stateDir",
27
+ "config",
28
+ "system",
29
+ "provider",
30
+ "model",
31
+ "json",
32
+ "plain",
33
+ "quiet",
34
+ "verbose",
35
+ "debug",
36
+ "noColor",
37
+ "noInput",
38
+ ]);
39
+ const booleanFlags = new Set([
40
+ "force",
41
+ "apply",
42
+ "yes",
43
+ "approve",
44
+ "reject",
45
+ "json",
46
+ "plain",
47
+ "quiet",
48
+ "verbose",
49
+ "debug",
50
+ "noColor",
51
+ "noInput",
52
+ "help",
53
+ "version",
54
+ ]);
55
+ const shortFlags = {
56
+ q: "quiet",
57
+ v: "verbose",
58
+ h: "help",
59
+ };
60
+ function camel(value) {
61
+ return value.replace(/-([a-z])/gu, (_, char) => char.toUpperCase());
62
+ }
63
+ function dash(value) {
64
+ return value.replace(/[A-Z]/gu, (char) => `-${char.toLowerCase()}`);
65
+ }
66
+ export function parseArgs(argv) {
67
+ const flags = {};
68
+ const positionals = [];
69
+ let command = "";
70
+ for (let index = 0; index < argv.length; index += 1) {
71
+ const token = argv[index];
72
+ if (token === undefined)
73
+ break;
74
+ if (token.startsWith("--")) {
75
+ const body = token.slice(2);
76
+ const eq = body.indexOf("=");
77
+ if (eq !== -1) {
78
+ flags[camel(body.slice(0, eq))] = body.slice(eq + 1);
79
+ continue;
80
+ }
81
+ const key = camel(body);
82
+ if (booleanFlags.has(key)) {
83
+ flags[key] = true;
84
+ continue;
85
+ }
86
+ const next = argv[index + 1];
87
+ if (next !== undefined && !next.startsWith("-")) {
88
+ flags[key] = next;
89
+ index += 1;
90
+ }
91
+ else {
92
+ flags[key] = true;
93
+ }
94
+ continue;
95
+ }
96
+ if (token.startsWith("-") && token.length > 1) {
97
+ for (const char of token.slice(1))
98
+ flags[shortFlags[char] ?? char] = true;
99
+ continue;
100
+ }
101
+ if (!command)
102
+ command = token;
103
+ else
104
+ positionals.push(token);
105
+ }
106
+ return { command, positionals, flags };
107
+ }
108
+ export function validateCommandFlags(command, flags) {
109
+ const allowed = commandFlags[command];
110
+ if (!allowed)
111
+ throw new ToolError(`unknown command: ${command}`, 2, "invalid-usage");
112
+ for (const key of Object.keys(flags)) {
113
+ if (globalFlags.has(key) || allowed.has(key))
114
+ continue;
115
+ throw new ToolError(`unknown flag for ${command}: --${dash(key)}`, 2, "invalid-usage");
116
+ }
117
+ }
118
+ async function dispatch(ctx, command, flags) {
119
+ switch (command) {
120
+ case "init":
121
+ return initCommand(ctx, flags);
122
+ case "status":
123
+ return statusCommand(ctx, flags);
124
+ case "next":
125
+ return nextCommand(ctx, flags);
126
+ case "run":
127
+ return runCommand(ctx, flags);
128
+ case "loop":
129
+ return loopCommand(ctx, flags);
130
+ case "gate":
131
+ return gateCommand(ctx, flags);
132
+ case "report":
133
+ return reportCommand(ctx, flags);
134
+ case "revalidate":
135
+ return revalidateCommand(ctx, flags);
136
+ case "doctor":
137
+ return doctorCommand(ctx, flags);
138
+ case "clean-locks":
139
+ return cleanLocksCommand(ctx, flags);
140
+ default:
141
+ throw new ToolError(`unknown command: ${command}`, 2, "invalid-usage");
142
+ }
143
+ }
144
+ // The ONLY function that writes results to stdout.
145
+ function writeResult(result, json, plain) {
146
+ if (json) {
147
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
148
+ return;
149
+ }
150
+ if (result && typeof result === "object" && "markdown" in result && !plain) {
151
+ process.stdout.write(String(result.markdown));
152
+ return;
153
+ }
154
+ if (result && typeof result === "object") {
155
+ for (const [key, value] of Object.entries(result)) {
156
+ if (value === null || typeof value === "object")
157
+ continue;
158
+ process.stdout.write(`${key}: ${String(value)}\n`);
159
+ }
160
+ }
161
+ }
162
+ function isRecord(value) {
163
+ return typeof value === "object" && value !== null;
164
+ }
165
+ function helpText() {
166
+ return [
167
+ `legacymaxxing ${pkg.version} — guide an agent through the code-modernization lifecycle`,
168
+ "",
169
+ "Usage: legacymaxxing <command> [flags]",
170
+ "",
171
+ "Commands:",
172
+ " init --system <name> --legacy <path> register a legacy system + write state",
173
+ " status phase table for a system",
174
+ " next print the next runnable phase's prompt (no model call)",
175
+ " run <phase> [--module m] [--apply] run one phase via the provider",
176
+ " loop [--until <phase>] run read-only phases until a gate blocks",
177
+ " gate <phase> --approve|--reject record a human gate decision",
178
+ " report markdown summary of all phases",
179
+ " revalidate <phase> re-check a phase's artifacts on disk",
180
+ " doctor check provider + optional tools + state",
181
+ " clean-locks remove lock files",
182
+ "",
183
+ `Phases: assess → map → extract → brief [gate] → transform/reimagine → harden`,
184
+ "",
185
+ "Global flags: --root --state-dir --config --system --provider --model",
186
+ " --json --plain -q/--quiet -v/--verbose --debug --no-color --no-input",
187
+ "",
188
+ ].join("\n");
189
+ }
190
+ export async function main(argv) {
191
+ if (argv.includes("--version")) {
192
+ process.stdout.write(`${pkg.version}\n`);
193
+ return;
194
+ }
195
+ if (argv.length === 0 || argv.includes("--help") || argv.includes("-h")) {
196
+ process.stdout.write(helpText());
197
+ return;
198
+ }
199
+ const { command, positionals, flags } = parseArgs(argv);
200
+ if (!command) {
201
+ process.stdout.write(helpText());
202
+ return;
203
+ }
204
+ if ((command === "run" || command === "gate" || command === "revalidate") &&
205
+ positionals[0] !== undefined &&
206
+ flags["phase"] === undefined) {
207
+ flags["phase"] = positionals[0];
208
+ }
209
+ validateCommandFlags(command, flags);
210
+ const options = resolveGlobalOptions(flags, process.env);
211
+ const ctx = makeContext(options);
212
+ const result = await dispatch(ctx, command, flags);
213
+ writeResult(result, options.json, options.plain);
214
+ if (command === "doctor" && isRecord(result) && result["ready"] === false) {
215
+ process.exitCode = 2;
216
+ }
217
+ }
218
+ function invokedDirectly() {
219
+ const entry = process.argv[1];
220
+ if (!entry)
221
+ return false;
222
+ try {
223
+ return realpathSync(entry) === realpathSync(fileURLToPath(import.meta.url));
224
+ }
225
+ catch {
226
+ return false;
227
+ }
228
+ }
229
+ if (invokedDirectly()) {
230
+ main(process.argv.slice(2)).catch((error) => {
231
+ if (error instanceof ToolError) {
232
+ process.stderr.write(`error: ${error.message}\n`);
233
+ process.exitCode = error.exitCode;
234
+ return;
235
+ }
236
+ process.stderr.write(`error: ${error instanceof Error ? error.message : String(error)}\n`);
237
+ process.exitCode = 1;
238
+ });
239
+ }
@@ -0,0 +1,11 @@
1
+ import type { Context, Flags } from "./context.js";
2
+ export declare function initCommand(ctx: Context, flags: Flags): Promise<unknown>;
3
+ export declare function statusCommand(ctx: Context, flags: Flags): Promise<unknown>;
4
+ export declare function nextCommand(ctx: Context, flags: Flags): Promise<unknown>;
5
+ export declare function runCommand(ctx: Context, flags: Flags): Promise<unknown>;
6
+ export declare function loopCommand(ctx: Context, flags: Flags): Promise<unknown>;
7
+ export declare function gateCommand(ctx: Context, flags: Flags): Promise<unknown>;
8
+ export declare function reportCommand(ctx: Context, flags: Flags): Promise<unknown>;
9
+ export declare function revalidateCommand(ctx: Context, flags: Flags): Promise<unknown>;
10
+ export declare function doctorCommand(ctx: Context, _flags: Flags): Promise<unknown>;
11
+ export declare function cleanLocksCommand(ctx: Context, _flags: Flags): Promise<unknown>;