From c9e990089c6c87cb96e227e998edbada1df82861 Mon Sep 17 00:00:00 2001 From: Morgan Lunt Date: Thu, 24 Sep 2026 18:07:14 -0700 Subject: code-modernization: add an optional live progress pane Adds a hooks module, off unless the CLI's early-access function hooks are enabled, that draws a pane beside the transcript while the commands run: the system, which steps are done, a map of its code, each unit of work and where it stands, what needs attention, and the next command. It reads only the artifacts the commands write and the legacy tree, so it works for any language and for a rewrite, a same-stack uplift or a greenfield rebuild. The map comes from topology.json when there is one and from the source tree when there is not. In an uplift each module is set against the baseline; tests are read from JUnit XML, .trx reports or the runs a session sees; a button shows and hides the pane, and /modernize-panel does the same from the keyboard. The same module adds x-ray context on legacy reads, a review deck for business rules (/modernize-review), a sign-off dialog (/modernize-sign) and a fleet view that spots one failure repeating across agents. It only watches: it never blocks, rewrites or restores an edit, and it runs no program inside the trees it reads. An uplift's changed modules are found by comparing the working copy with the tree by file name and size through the file API. Its options are the plugin's userConfig. Without the flag nothing loads and the commands, agents and workflows behave as before. 91 tests in tests/ run with "claude plugin test"; plugin validate passes on the release build with the flag on and off. --- plugins/code-modernization/hooks/reader/fs.ts | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 plugins/code-modernization/hooks/reader/fs.ts (limited to 'plugins/code-modernization/hooks/reader/fs.ts') diff --git a/plugins/code-modernization/hooks/reader/fs.ts b/plugins/code-modernization/hooks/reader/fs.ts new file mode 100644 index 00000000..44b570ed --- /dev/null +++ b/plugins/code-modernization/hooks/reader/fs.ts @@ -0,0 +1,54 @@ +/** + * The file access the reader needs, narrow enough that `$.fs` and a test's + * in-memory tree both satisfy it. Paths are relative to the session's + * working directory or absolute, as `$.fs` takes them. + */ +export type ReaderFs = { + read: (path: string) => Promise + list: (path: string) => Promise<{ name: string; kind: 'file' | 'dir' | 'other'; size: number }[]> + exists: (path: string) => Promise + stat: (path: string) => Promise<{ kind: 'file' | 'dir' | 'other'; size: number; mtimeMs: number }> +} + +/** `read`, or null when the file is missing, unreadable or over the size cap. */ +export async function readOrNull(fs: ReaderFs, path: string): Promise { + try { + // `exists` never rejects; asking first keeps a missing optional file out of the error log. + if (!(await fs.exists(path))) { + return null + } + + return await fs.read(path) + } catch { + return null + } +} + +/** `list`, or an empty list when the directory is missing. */ +export async function listOrEmpty( + fs: ReaderFs, + path: string, +): Promise<{ name: string; kind: 'file' | 'dir' | 'other'; size: number }[]> { + try { + if (!(await fs.exists(path))) { + return [] + } + + return await fs.list(path) + } catch { + return [] + } +} + +/** `stat`'s mtime, or null when the path is missing. */ +export async function mtimeOrNull(fs: ReaderFs, path: string): Promise { + try { + if (!(await fs.exists(path))) { + return null + } + + return (await fs.stat(path)).mtimeMs + } catch { + return null + } +} -- cgit From 51b1ae9e20486d62b839ed9f37e1cfc7d55bf85c Mon Sep 17 00:00:00 2001 From: Morgan Lunt Date: Thu, 24 Sep 2026 20:52:27 -0700 Subject: code-modernization: make the live pane work below 144 columns and show the proof Found by exercising the pane against the real outputs of finished runs: - Below 144 columns the engine holds an unasked pane back; the pane ignored that, so it drew no pane, no show bar, and the panel command "hid" a pane that was never there. - A symlinked legacy/ lists as another kind of entry, so the source link that preflight now creates was never recognized as a system. - Uplift and reimagine next steps were placeholders with no button. - The refresh debounce was starved while agents ran, so the map froze. - Hostile lines in the brief, rules and baseline could take seconds to match; lines are now capped. The rule-review ledger is validated on read and merged on save, and keeps a reviewer's note. - A baseline with no row read as "the baseline had 0"; one-module baseline totals now count as that module's row. New: a verdict chip with words on every built module, a verify-first next step, and a readable palette that follows the terminal theme. 140 engine tests pass and the type check is clean. --- plugins/code-modernization/hooks/reader/fs.ts | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'plugins/code-modernization/hooks/reader/fs.ts') diff --git a/plugins/code-modernization/hooks/reader/fs.ts b/plugins/code-modernization/hooks/reader/fs.ts index 44b570ed..1d8e9f6d 100644 --- a/plugins/code-modernization/hooks/reader/fs.ts +++ b/plugins/code-modernization/hooks/reader/fs.ts @@ -5,7 +5,8 @@ */ export type ReaderFs = { read: (path: string) => Promise - list: (path: string) => Promise<{ name: string; kind: 'file' | 'dir' | 'other'; size: number }[]> + /** An entry as it stands: a symbolic link is `other` (with `isLink`), whatever it leads to. `stat` says what that is. */ + list: (path: string) => Promise<{ name: string; kind: 'file' | 'dir' | 'other'; size: number; isLink?: boolean }[]> exists: (path: string) => Promise stat: (path: string) => Promise<{ kind: 'file' | 'dir' | 'other'; size: number; mtimeMs: number }> } @@ -28,7 +29,7 @@ export async function readOrNull(fs: ReaderFs, path: string): Promise { +): Promise<{ name: string; kind: 'file' | 'dir' | 'other'; size: number; isLink?: boolean }[]> { try { if (!(await fs.exists(path))) { return [] @@ -52,3 +53,27 @@ export async function mtimeOrNull(fs: ReaderFs, path: string): Promise { + const names: string[] = [] + + for (const entry of await listOrEmpty(fs, path)) { + if (entry.kind === 'dir') { + names.push(entry.name) + } else if (entry.kind === 'other') { + try { + if ((await fs.stat(`${path}/${entry.name}`)).kind === 'dir') { + names.push(entry.name) + } + } catch { + // a link that leads nowhere is not a system + } + } + } + + return names +} -- cgit