summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/hooks/reader/tracks.ts
diff options
context:
space:
mode:
authorMorgan Lunt <morganl@anthropic.com>2026-09-24 18:07:14 -0700
committerMorgan Lunt <morganl@anthropic.com>2026-09-24 18:11:07 -0700
commitc9e990089c6c87cb96e227e998edbada1df82861 (patch)
tree623eb2b217930fd1e56558946443cd2ddeb5b849 /plugins/code-modernization/hooks/reader/tracks.ts
parent70caddcb673ac8995d6a5191e02ac51de579d6c3 (diff)
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.
Diffstat (limited to 'plugins/code-modernization/hooks/reader/tracks.ts')
-rw-r--r--plugins/code-modernization/hooks/reader/tracks.ts86
1 files changed, 86 insertions, 0 deletions
diff --git a/plugins/code-modernization/hooks/reader/tracks.ts b/plugins/code-modernization/hooks/reader/tracks.ts
new file mode 100644
index 00000000..8ce75985
--- /dev/null
+++ b/plugins/code-modernization/hooks/reader/tracks.ts
@@ -0,0 +1,86 @@
+/**
+ * The three ways the plugin's commands work on a system, and what each leaves behind. The pane follows
+ * whichever one the artifacts on disk say is under way, so a same-stack version uplift or a greenfield
+ * rebuild is followed as closely as a rewrite is.
+ */
+
+export type TrackKey = 'transform' | 'uplift' | 'reimagine'
+
+export const TRACK_LABELS: Record<TrackKey, string> = {
+ transform: 'rewrite',
+ uplift: 'uplift',
+ reimagine: 'reimagine',
+}
+
+/** The unit of work in each track, as the pane names a list of them. */
+export const TRACK_UNITS: Record<TrackKey, { one: string; many: string }> = {
+ transform: { one: 'module', many: 'Modules' },
+ uplift: { one: 'module', many: 'Modules' },
+ reimagine: { one: 'service', many: 'Services' },
+}
+
+/** What each state of a unit of work is called, by track: the same colors, worded for what the work is. */
+export const STATE_WORDS_BY_TRACK: Record<TrackKey, Record<string, string>> = {
+ transform: {
+ untouched: 'untouched',
+ scaffolded: 'scaffolded',
+ 'tests-written': 'tests written',
+ 'tests-red': 'tests red',
+ 'tests-green': 'tests green',
+ reviewed: 'reviewed',
+ ported: 'ported',
+ switched: 'switched',
+ },
+ uplift: {
+ untouched: 'not migrated',
+ scaffolded: 'changed',
+ 'tests-written': 'tests written',
+ 'tests-red': 'worse than baseline',
+ 'tests-green': 'tests pass',
+ reviewed: 'matches baseline',
+ ported: 'ported',
+ switched: 'switched',
+ },
+ reimagine: {
+ untouched: 'legacy',
+ scaffolded: 'scaffolded',
+ 'tests-written': 'tests written',
+ 'tests-red': 'tests red',
+ 'tests-green': 'tests green',
+ reviewed: 'reviewed',
+ ported: 'ported',
+ switched: 'switched',
+ },
+}
+
+/** Times (ms) of the artifacts that mark each track as under way; null where the artifact is absent. */
+export type TrackFacts = {
+ transformAt: number | null
+ upliftAt: number | null
+ reimagineAt: number | null
+}
+
+/**
+ * The track under way: the one whose own artifacts were written last. The discovery artifacts (preflight,
+ * assess, map, rules, brief) feed all three and decide nothing. With no track's own artifacts a system
+ * is at the start of the rewrite path, which is where the plugin's commands begin.
+ */
+export function pickTrack(option: TrackKey | 'auto', facts: TrackFacts): TrackKey {
+ if (option !== 'auto') {
+ return option
+ }
+
+ const ranked = (
+ [
+ ['transform', facts.transformAt],
+ ['reimagine', facts.reimagineAt],
+ ['uplift', facts.upliftAt],
+ ] as const
+ ).filter((entry): entry is readonly [TrackKey, number] => entry[1] !== null)
+
+ if (ranked.length === 0) {
+ return 'transform'
+ }
+
+ return ranked.reduce((best, entry) => (entry[1] > best[1] ? entry : best))[0]
+}