summaryrefslogtreecommitdiff
path: root/plugins/code-modernization/hooks/sign.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/sign.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/sign.ts')
-rw-r--r--plugins/code-modernization/hooks/sign.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/plugins/code-modernization/hooks/sign.ts b/plugins/code-modernization/hooks/sign.ts
new file mode 100644
index 00000000..3eeb6157
--- /dev/null
+++ b/plugins/code-modernization/hooks/sign.ts
@@ -0,0 +1,77 @@
+/**
+ * Writing a person's signature into the brief's approval block. The block
+ * comes in a few shapes (one line or several, checkboxes or a choice in
+ * words); each is filled in where it stands, and nothing else is touched.
+ */
+
+const COVER_WORDS = { 'phase-1': 'Phase 1 only', full: 'Full plan' } as const
+
+/**
+ * The brief with its approval block signed; null when it has no `Approved by:` line.
+ *
+ * @param text the brief
+ * @param name who approves
+ * @param date `YYYY-MM-DD`
+ * @param covers what the approval covers
+ */
+export function signBrief(
+ text: string,
+ name: string,
+ date: string,
+ covers: 'phase-1' | 'full',
+): string | null {
+ const lines = text.split('\n')
+ const at = lines.findIndex(line => /^\s*Approved by\s*:/i.test(line))
+
+ if (at < 0) {
+ return null
+ }
+
+ const who = name.replace(/\s+/g, ' ').trim()
+ const line = lines[at] ?? ''
+ const indent = /^\s*/.exec(line)?.[0] ?? ''
+ const hasInlineDate = /\bDate\s*:/i.test(line)
+
+ lines[at] = hasInlineDate ? `${indent}Approved by: ${who} Date: ${date}` : `${indent}Approved by: ${who}`
+
+ // The block ends at a blank-line-separated heading or code fence; look a short way down.
+ const end = Math.min(lines.length, at + 12)
+
+ if (!hasInlineDate) {
+ const dateAt = lines.findIndex((candidate, index) => index > at && index < end && /^\s*Date\s*:/i.test(candidate))
+
+ if (dateAt >= 0) {
+ const head = /^(\s*Date\s*:\s*)/i.exec(lines[dateAt] ?? '')?.[1] ?? 'Date: '
+
+ lines[dateAt] = `${head}${date}`
+ } else {
+ lines.splice(at + 1, 0, `${indent}Date: ${date}`)
+ }
+ }
+
+ const coversAt = lines.findIndex(
+ (candidate, index) => index >= at && index < end + 1 && /Approval covers\s*:/i.test(candidate),
+ )
+
+ if (coversAt >= 0) {
+ const current = lines[coversAt] ?? ''
+
+ if (/\[[ xX]?\]/.test(current)) {
+ lines[coversAt] = current.replace(/\[[ xX]?\](\s*)([^[\]|]+)/g, (_match, gap: string, label: string) => {
+ const isFull = /full/i.test(label)
+ const isPhase = /phase\s*1/i.test(label)
+ const isChosen = covers === 'full' ? isFull : isPhase
+
+ return `[${isChosen ? 'X' : ' '}]${gap}${label}`
+ })
+ } else {
+ const head = /^(.*Approval covers\s*:\s*)/i.exec(current)?.[1] ?? 'Approval covers: '
+
+ lines[coversAt] = `${head}${COVER_WORDS[covers]}`
+ }
+ } else {
+ lines.splice(at + (hasInlineDate ? 1 : 2), 0, `${indent}Approval covers: ${COVER_WORDS[covers]}`)
+ }
+
+ return lines.join('\n')
+}