-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cli): codemap rename alias for homonym-safe renames #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7416338
feat(cli): add codemap rename alias for homonym-safe renames
SutuSebastian 609b140
fix(cli): preserve missing --params operand in rename alias
SutuSebastian 172278a
fix(cli): harden rename alias parsing and docs
SutuSebastian ffc6568
fix(cli): polish rename alias edge cases and docs
SutuSebastian 36718fb
fix(cli): improve stray-arg error after complete rename params
SutuSebastian bba068b
test(cli): cover stray positional after rename --params
SutuSebastian 97ade6b
fix(cli): preserve state on trailing bare --params in rename
SutuSebastian 7ff7d8f
fix(cli): reject flag tokens as --params operands in rename
SutuSebastian a0ef0de
fix(cli): strip redundant bare --params from rename rewrite
SutuSebastian 6f70740
fix(cli): reject flag tokens as scoped-flag operands in rename
SutuSebastian d427c3a
fix(cli): harden rename alias flag parsing and help guards
SutuSebastian ce8ddd4
fix(cli): reject flag tokens as --commit/--max-passes operands
SutuSebastian 7b0ce69
docs(cli): use generic paths in rename alias examples
SutuSebastian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Scoped rename (`define_in`) — plan | ||
|
|
||
| > **Status:** ready to delete · **Priority:** P1 · **Effort:** S (alias slice) + M (shipped in [#165](https://github.com/stainless-code/codemap/pull/165)) | ||
| > | ||
| > **Motivator:** Homonymous symbol names make bare `rename-preview` union every `symbols.name` match. Agents need the same definition anchor `find-symbol-references` uses (`file_path` of the definition). | ||
| > | ||
| > **Roadmap:** [§ Backlog — Agent & indexing ops](../roadmap.md#agent--indexing-ops) | ||
|
|
||
| --- | ||
|
|
||
| ## Pre-locked decisions | ||
|
|
||
| | # | Decision | Source | | ||
| | --- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | | ||
| | R.1 | **`define_in` scopes `target_symbols`** to `symbols.file_path = define_in`; binding-resolved `call_rows` / JSX CTEs filter when set. | Moat B — substrate | | ||
| | R.2 | **`in_file` stays output-only** — prefix filter on result row paths; does not pick which homonym is the rename target. | [rename-preview.md](../../templates/recipes/rename-preview.md) | | ||
| | R.3 | **Moat A preserved** — no new verdict engine; optional `codemap rename` is a **thin alias** → `apply rename-preview` (same as outcome aliases → query). | [architecture § Apply](../architecture.md#apply--input-modes-transport-and-policy) | | ||
| | R.4 | **Golden + apply e2e** — `rename-preview-homonym-scoped` / `rename-preview-homonym-unscoped` in `fixtures/golden/minimal/`. | [testing-coverage.md](../testing-coverage.md) | | ||
|
|
||
| --- | ||
|
|
||
| ## Shipped ([#165](https://github.com/stainless-code/codemap/pull/165)) | ||
|
|
||
| - [x] `define_in` recipe param on `rename-preview` (`templates/recipes/rename-preview.{sql,md}`) | ||
| - [x] Binding-scoped `call_rows` + `jsx_element_rows` / `jsx_closing_rows` when `define_in` set | ||
| - [x] Golden `rename-preview-homonym-scoped` + homonym fixtures under `fixtures/minimal/src/bench/` | ||
| - [x] `cmd-apply.test.ts` homonym apply e2e | ||
| - [x] Agent surfaces: README, skill, MCP instructions, `find-symbol-references` action template | ||
|
|
||
| --- | ||
|
|
||
| ## Remaining slice (this PR) | ||
|
|
||
| - [x] **`codemap rename` CLI alias** — rewrite to `codemap apply rename-preview` with full apply flag pass-through | ||
| - [x] Positional ergonomics: `codemap rename <old> <new> [--define-in path] [--in-file prefix] [--kind k]` | ||
| - [x] `rename-alias.test.ts` + integration via `cmd-apply.test.ts` | ||
| - [x] `bootstrap.ts` help line; roadmap checkbox for alias | ||
|
|
||
| **Non-goals (unchanged):** global rename verb with new semantics; MCP `rename` tool; AST apply engine. | ||
|
|
||
| --- | ||
|
|
||
| ## Acceptance | ||
|
|
||
| - [x] Scoped golden matches binding-resolved call sites only for anchored homonym | ||
| - [x] Unscoped golden unions both homonyms | ||
| - [x] `codemap rename helper worker --define-in src/bench/homonym-helper-a.ts --yes` ≡ apply recipe path | ||
| - [x] `codemap rename --help` documents alias + `define_in` vs `in_file` | ||
|
|
||
| --- | ||
|
|
||
| ## Delete trigger | ||
|
|
||
| Delete this plan when the alias slice merges and roadmap item is fully checked — lift one-liner to [architecture § Homonym-safe rename](../architecture.md#apply--input-modes-transport-and-policy). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
|
|
||
| import { formatParamsCli, resolveRenameAlias } from "./rename-alias.js"; | ||
|
|
||
| describe("resolveRenameAlias", () => { | ||
| it("rewrites positional old/new with scoped flags", () => { | ||
| expect( | ||
| resolveRenameAlias([ | ||
| "rename", | ||
| "helper", | ||
| "worker", | ||
| "--define-in", | ||
| "src/a.ts", | ||
| "--yes", | ||
| ]), | ||
| ).toEqual([ | ||
| "apply", | ||
| "rename-preview", | ||
| "--params", | ||
| "define_in=src/a.ts,new=worker,old=helper", | ||
| "--yes", | ||
| ]); | ||
| }); | ||
|
|
||
| it("rewrites --params form", () => { | ||
| expect( | ||
| resolveRenameAlias([ | ||
| "rename", | ||
| "--params", | ||
| "old=foo,new=bar,define_in=src/x.ts", | ||
| "--dry-run", | ||
| ]), | ||
| ).toEqual([ | ||
| "apply", | ||
| "rename-preview", | ||
| "--params", | ||
| "define_in=src/x.ts,new=bar,old=foo", | ||
| "--dry-run", | ||
| ]); | ||
| }); | ||
|
|
||
| it("merges --params with positional when both present", () => { | ||
| expect( | ||
| resolveRenameAlias([ | ||
| "rename", | ||
| "a", | ||
| "b", | ||
| "--params", | ||
| "kind=function", | ||
| "--dry-run", | ||
| ]), | ||
| ).toEqual([ | ||
| "apply", | ||
| "rename-preview", | ||
| "--params", | ||
| "kind=function,new=b,old=a", | ||
| "--dry-run", | ||
| ]); | ||
| }); | ||
|
|
||
| it("maps --in-file and --kind to recipe params", () => { | ||
| expect( | ||
| resolveRenameAlias([ | ||
| "rename", | ||
| "Foo", | ||
| "Bar", | ||
| "--in-file", | ||
| "src/lib/", | ||
| "--kind", | ||
| "function", | ||
| ]), | ||
| ).toEqual([ | ||
| "apply", | ||
| "rename-preview", | ||
| "--params", | ||
| "in_file=src/lib/,kind=function,new=Bar,old=Foo", | ||
| ]); | ||
| }); | ||
|
|
||
| it("returns null for non-rename commands", () => { | ||
| expect(resolveRenameAlias(["apply", "rename-preview"])).toBeNull(); | ||
| }); | ||
|
|
||
| it("returns null when help is requested", () => { | ||
| expect(resolveRenameAlias(["rename", "--help"])).toBeNull(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatParamsCli", () => { | ||
| it("serializes key=value pairs", () => { | ||
| expect(formatParamsCli({ old: "a", new: "b", define_in: "src/x.ts" })).toBe( | ||
| "define_in=src/x.ts,new=b,old=a", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import { mergeParams, parseParamsCli } from "../application/recipe-params.js"; | ||
| import type { RecipeParamValues } from "../application/recipe-params.js"; | ||
|
|
||
| const RENAME_RECIPE_ID = "rename-preview"; | ||
|
|
||
| /** Serialize a param map for `codemap apply --params` (stable key order). */ | ||
| export function formatParamsCli(params: RecipeParamValues): string { | ||
| return Object.keys(params) | ||
| .sort() | ||
| .map((key) => `${key}=${String(params[key])}`) | ||
| .join(","); | ||
| } | ||
|
|
||
| /** | ||
| * Thin alias: `codemap rename` → `codemap apply rename-preview`. | ||
| * Moat A — no new write verb semantics; same recipe + policy gates as `apply`. | ||
| */ | ||
| export function resolveRenameAlias(rest: string[]): string[] | null { | ||
| if (rest[0] !== "rename") return null; | ||
|
|
||
| const tail = rest.slice(1); | ||
| if (tail.includes("--help") || tail.includes("-h")) { | ||
| return null; | ||
| } | ||
|
|
||
| let params: RecipeParamValues | undefined; | ||
| const passthrough: string[] = []; | ||
| let i = 0; | ||
|
|
||
| while (i < tail.length) { | ||
| const a = tail[i]!; | ||
| if (a === "--params") { | ||
| const next = tail[i + 1]; | ||
| if (next === undefined) { | ||
| return ["apply", RENAME_RECIPE_ID, "--params", ""]; | ||
| } | ||
| params = mergeParams(params, parseParamsCli(next)); | ||
| i += 2; | ||
| continue; | ||
| } | ||
| if (a === "--define-in") { | ||
| const next = tail[i + 1]; | ||
| if (next === undefined) { | ||
| return ["apply", RENAME_RECIPE_ID, "--define-in"]; | ||
| } | ||
| params = mergeParams(params, { define_in: next }); | ||
| i += 2; | ||
| continue; | ||
| } | ||
| if (a === "--in-file") { | ||
| const next = tail[i + 1]; | ||
| if (next === undefined) { | ||
| return ["apply", RENAME_RECIPE_ID, "--in-file"]; | ||
| } | ||
| params = mergeParams(params, { in_file: next }); | ||
| i += 2; | ||
| continue; | ||
| } | ||
| if (a === "--kind") { | ||
| const next = tail[i + 1]; | ||
| if (next === undefined) { | ||
| return ["apply", RENAME_RECIPE_ID, "--kind"]; | ||
| } | ||
| params = mergeParams(params, { kind: next }); | ||
| i += 2; | ||
| continue; | ||
| } | ||
| passthrough.push(a); | ||
| i++; | ||
| } | ||
|
|
||
| const head = passthrough[0]; | ||
| const second = passthrough[1]; | ||
| if ( | ||
| head !== undefined && | ||
| second !== undefined && | ||
| !head.startsWith("-") && | ||
| !second.startsWith("-") | ||
| ) { | ||
| params = mergeParams(params, { old: head, new: second }); | ||
| const applyTail = passthrough.slice(2); | ||
| if (params && Object.keys(params).length > 0) { | ||
| return [ | ||
| "apply", | ||
| RENAME_RECIPE_ID, | ||
| "--params", | ||
| formatParamsCli(params), | ||
| ...applyTail, | ||
| ]; | ||
| } | ||
| return ["apply", RENAME_RECIPE_ID, ...applyTail]; | ||
| } | ||
|
|
||
| if (params && Object.keys(params).length > 0) { | ||
| return [ | ||
| "apply", | ||
| RENAME_RECIPE_ID, | ||
| "--params", | ||
| formatParamsCli(params), | ||
| ...passthrough, | ||
| ]; | ||
| } | ||
|
|
||
| return ["apply", RENAME_RECIPE_ID, ...passthrough]; | ||
| } | ||
|
|
||
| export function printRenameAliasHelp(): void { | ||
| console.log(`Usage: | ||
| codemap rename <old> <new> [--define-in <file_path>] [--in-file <prefix>] [--kind <k>] [apply flags...] | ||
| codemap rename --params old=<old>,new=<new>[,define_in=<file_path>] [apply flags...] | ||
|
|
||
| Alias for \`codemap apply rename-preview\` — homonym-safe renames pass \`--define-in\` | ||
| (definition \`symbols.file_path\` anchor). \`--in-file\` only narrows output row paths. | ||
|
|
||
| Apply flags pass through: --dry-run, --yes, --force, --json, --until-empty, | ||
| --max-passes N, --commit "<msg>". | ||
|
|
||
| Examples: | ||
| codemap rename usePermissions useAccess --kind function --dry-run | ||
| codemap rename helper worker --define-in src/bench/homonym-helper-a.ts --yes | ||
| codemap rename --params old=foo,new=bar,define_in=src/a.ts --dry-run | ||
|
|
||
| Run \`codemap apply --help\` for executor details.`); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.