doc-and-modernize

软件研发 工程通用 3 文件 EN 原文

Two related workflows for a locally-cloned codeb

Two related workflows for a locally-cloned codebase, in one skill. Documentation mode produces a single, comprehensive, verifiable architecture document primarily by reading files on disk (local-first) — use it whenever the user wants to understand, map, document, research, or onboard onto a codebase ("research this repo", "write up the architecture", "do an architecture deep dive", "document how this codebase works", "map the system design", "create an onboarding doc"). Modernization mode generates a phased plan to modernize, migrate, upgrade, or rewrite a legacy system ("modernize this", "plan the migration", "how would we rewrite this", "how do we get off this legacy stack"); if no architecture document exists yet it first runs Documentation mode, then continues straight through to the plan. It assumes the legacy stack may be dead, runs a time-boxed feasibility spike, and picks the highest achievable rung on a safety ladder instead of demanding a fully-green legacy CI gate up front.

说明语言:英文

来源githubawesome-copilot ↗ 查看原文件 ↗版权归原作者,请遵循原仓库许可
安装
npx skills add https://github.com/github/awesome-copilot --skill doc-and-modernize

需要已安装 skills CLI。也可以直接从源仓库 clone。

在星云中查看 ↗
SKILL.md 原文

name: doc-and-modernize description: >- Two related workflows for a locally-cloned codebase, in one skill. Documentation mode produces a single, comprehensive, verifiable architecture document primarily by reading files on disk (local-first) — use it whenever the user wants to understand, map, document, research, or onboard onto a codebase ("research this repo", "write up the architecture", "do an architecture deep dive", "document how this codebase works", "map the system design", "create an onboarding doc"). Modernization mode generates a phased plan to modernize, migrate, upgrade, or rewrite a legacy system ("modernize this", "plan the migration", "how would we rewrite this", "how do we get off this legacy stack"); if no architecture document exists yet it first runs Documentation mode, then continues straight through to the plan. It assumes the legacy stack may be dead, runs a time-boxed feasibility spike, and picks the highest achievable rung on a safety ladder instead of demanding a fully-green legacy CI gate up front. ---

Documentation & Modernization

Two complementary workflows for a repository the user already has checked out locally, bundled as one skill:

Mode selection

When in doubt, produce the architecture document first — it is the audited evidence base both modes rely on.

Documentation mode

Generate one definitive, cited architecture document for a repository the user already has checked out locally. The goal is a writeup someone could hand to a new engineer as their onboarding reference — broad enough to cover the whole system, deep enough on the hard parts to be useful, and trustworthy because every claim traces back to a file on disk.

Why local-first

Reading from the local checkout (not the GitHub API or the web) is the deliberate default. It is faster, free, avoids rate limits, and — most importantly — it describes the exact code in front of you rather than whatever main happens to look like remotely. The one tradeoff is that remote-only facts (star counts, full CI run history, sibling repos) aren't visible. That's fine: state those as out-of-scope or mark them [UNVERIFIED] rather than guessing.

Local-first is not local-never-remote: a web/API lookup is a deliberate last-resort fallback, reserved for a fact that genuinely cannot be determined from disk and that materially matters to the document. When you do reach for it, flag the result clearly (e.g. [UNVERIFIED] / sourced-remotely) so the reader knows it didn't come from the checkout, and never let it become the easy path that displaces reading the code on disk.

Workflow

  1. Establish identity first. Run git remote -v, git branch --show-current, and git log -1 so the document is anchored to a specific remote, branch, and commit. A reader must be able to tell which snapshot this describes. Remote URLs can contain embedded credentials (e.g. https://<token>@github.com/...) — redact any credentials/tokens from the URL before recording it in the document.
  2. Detect, don't assume. Read the real manifests (go.mod, package.json, Cargo.toml, pyproject.toml, pom.xml, etc.), the Makefile/task runner, CI config, and any repo-specific agent or contributor docs (AGENTS.md, CONTRIBUTING, README, docs/). These are the source of truth for the tech stack and commands — prefer them over your prior knowledge of the framework.
  3. Map breadth, then drill into depth. First build the whole-repo map (the three lenses below), then pick the 2-3 hardest subsystems and go deep on them.
  4. Verify as you go. Open the files you cite. If you reference a line number, you should have actually read that line. Unsupported claims are worse than omissions here — the whole value of this document is that it can be trusted.

Output structure

Produce a single Markdown file with the sections below, in this order. Adapt the headings to the actual project (a CLI tool has no "frontend" lens — fold that slot into whatever matters for that repo), but keep the three-lens shape and the verification discipline.

Part 1 — Whole-repo technical deep-dive

Part 2 — Context & ecosystem

Part 3 — Architectural blueprint

Subsystem deep-dives

Identify the 2-3 most complex or architecturally significant subsystems — the parts a new engineer would most struggle with, such as an evaluation/scheduling engine, a plugin loader pipeline, a state machine, or a rendering/migration framework. For each, add a dedicated subsection covering its internal structure, lifecycle or state machine, key types, and data flow, with local file+line citations and a small Mermaid diagram where it clarifies the flow. This is what separates a useful onboarding doc from a directory listing — spend real effort here.

Confidence assessment

A table of the major claim areas rated High / Inferred / Unverified, so a reader knows exactly which parts to trust outright and which to double-check.

Footnotes — local file citations

A list of the key local files the document relies on, each with a one-line note on what it establishes.

Conventions that make the document trustworthy

These are the habits that distinguish this skill's output from a generic overview. They matter because the document's entire value is that a reader can rely on it without re-deriving everything.

Scope control

Keep the document grounded in the checkout. It's easy to drift outward into the project's wider ecosystem (related products, README marketing, satellite repos) — resist that unless it's visible on disk, and clearly label anything that comes from outside the local tree. The reader asked for this codebase, documented faithfully.

Modernization mode

Generate a complete, actionable modernization plan for a legacy codebase. This skill focuses on the forward-looking work — what to modernize, why, in what order, and how — but it is self-sufficient: it ensures an architecture document exists first, producing one via Documentation mode when needed.

Assume dead-by-default. People reach for modernization precisely because the old stack is hard or impossible to upgrade — EOL runtimes, uncompilable native modules, retired package mirrors, abandoned frameworks. So this skill does not assume you can resurrect the legacy toolchain and stand up a fully-green CI gate before touching anything. That "freeze-then-lift" approach is the lucky case, not the default. Instead the skill runs a time-boxed feasibility spike, then picks a migration strategy and a safety strategy matched to how alive the system actually is. On a truly dead app, building a green legacy gate is itself a modernization project — a circular trap this skill is designed to avoid.

Three ideas drive the whole plan and are introduced below: the Testability Milestone (when — per component — the system can actually build, run, and pass a test again), the safety ladder (the highest rung of regression safety you can actually reach, with a downgrade treated as a blessed outcome, not a failure), and the CI Milestone (which phase first stands up CI — and the reminder that enforcing CI as a required check is a manual human step, not something the agent can do).

Prerequisites

This skill needs an understanding of the system's architecture before it can plan. Resolve that as follows:

  1. If an architecture document already exists — produced by Documentation mode above, or a README / ARCHITECTURE.md the user points to, or enough prior conversation context — use it and skip to the workflow below.
  2. If none exists, run the Documentation mode workflow above first to generate a cited architecture document, then continue straight through to Phase 1 below in the same pass. Do not stop to ask the user to run it separately, and do not pause for review between the two documents.

The result is two artifacts: the architecture document (the audited evidence base) and this modernization plan (the forward-looking action set).

Before planning, confirm a Commands & Verification Inventory exists. Exit criteria are only worth anything if they are runnable, so the plan must be able to cite the project's canonical build / run / test / lint / typecheck / e2e / contract commands and CI gate(s). Documentation mode produces this inventory in Part 1; if you're working from a README or prior context that lacks it, detect and record those commands yourself (per-ecosystem — npm/yarn/pnpm, make, just, cargo, go, poetry/tox/nox, gradle/mvn, etc.) before writing exit criteria. Never invent a command you haven't verified against the task runner / manifests / CI config.

Workflow

Phase 1: Assess Current State (from existing docs)

Read the architecture document and extract:

  1. Tech stack inventory — languages, frameworks, runtimes, dependencies with versions where visible
  2. Feature/domain map — the major functional areas of the system
  3. Pain points already identified — tech debt, concerns, deprecated deps, architectural violations noted in the existing docs
  4. Deployment and infrastructure — how it runs today

Do NOT re-read every source file. Trust the architecture doc. Only open specific files if a modernization question requires verifying a detail (e.g., "is this dependency actually used or just declared?").

Phase 2: Feasibility Spike, Strategy Fork & Safety Ladder

This is the pivot of the whole plan. Do it before recommending a target architecture or writing any phases. Its job is to answer, quickly and honestly: how alive is this system, what migration shape fits, and how much regression safety can we actually achieve?

2a. Run a time-boxed feasibility spike

Put a hard time box on it (e.g. one day). The spike's question is NOT "can we make CI green?" — it is **"can we get this to run even once to capture its behavior?"** Probe, per component / deployable unit:

Record what you actually observed — including partial success (common in monorepos: one service installs and tests green while another can't compile). Do not sink two sprints resurrecting a corpse to discover it's unresurrectable. When the time box expires, decide with the evidence you have.

2b. Locate the Testability Milestone (per component)

**"Testable" is not a precondition you can satisfy on a dead app — for a dead app it is an output of modernization, not an input. So every plan must name, up front, its Testability Milestone: the specific phase at which the system (or a given component) first satisfies all four** conditions at once:

  1. Runs on a supported (non-EOL) runtime.
  2. Dependencies install from a lockfile without hand-patching.
  3. Native / build steps succeed on the current toolchain.
  4. The test runner executes and ≥1 meaningful test passes in CI.

Assess this per component — as the reference Nylas run showed, a near-modern cloud service can cross the line immediately while a legacy Electron client doesn't cross it until several phases later. This milestone is the single most important marker in the plan. State where it lands for each component, out loud.

2c. Label every phase pre- or post-testability

The Testability Milestone splits the effort into two regimes with different safety rules:

Rule: never require an automated test gate on a component before that component crosses its own testability line.

2d. Choose the migration strategy — the A/B fork

The spike decides which of two shapes fits (this is a per-component call in a monorepo):

If a component can't be built or run at all, characterization tests on the old stack are impossible by definition — invert the approach: **stop trying to net the corpse and build the net on the target stack incrementally**, using the old code/output as the reference oracle.

2e. Pick the highest achievable rung on the safety ladder

Regression safety is a ladder, not a binary. Choose the highest rung you can actually reach per component; a downgrade to a lower rung is a blessed, first-class outcome — not a failure — provided the residual risk is named.

Safety is not only tests. There are at least five sources, and on dead apps 2–4 often outweigh 1:

  1. Tests (characterization / unit / e2e) — strongest, often unachievable on dead apps.
  2. Reversibility — tiny commits, branch-per-change, trivial rollback.
  3. Isolation — feature flags, strangler-fig, run old + new in parallel and diff outputs.
  4. The running old system as an oracle — record/replay real I/O to characterize behavior without a test harness.
  5. Human review + domain knowledge.

**Anchor safety at the behavioral seams, not the unit.** The durable, stack-agnostic contracts of any app are its externally observable behaviors: HTTP endpoints, DB schema/queries, file/wire formats, CLI output, protocols. Pin those as golden-master / approval snapshots — they survive the rewrite; unit tests on dead legacy code get deleted the moment you replace the module. Get an oracle, ranked by what's available:

2f. Feed an economic/oracle triage into the choice

Weigh regression cost when picking a rung: Is the app in production? Does it have real users? Is the old system still runnable as a reference? An abandoned app with zero users has near-zero regression cost — an expensive gate there is over-engineering. A production system with users justifies a higher rung and a real oracle.

2g. Locate the CI Milestone (name the phase that stands up CI)

Just as the Testability Milestone names when a component can first run and be tested, the CI Milestone names when continuous integration is first stood up — and it must be stated out loud in the roadmap, not buried in a phase body. A common failure of modernization plans is leaving the reader unable to tell which phase introduces CI; name it explicitly.

**Rule: CI is stood up in the first lit phase — at or immediately after the component crosses its Testability Milestone — never before.** CI cannot be green on a component that cannot yet build/run, so wiring a CI gate during the dark regime is the same category error as demanding a test gate there. (Trivial scaffolding — a lint-only or build-only workflow — may appear earlier, but the authoritative test gate lands at the CI Milestone.)

CI is two distinct steps, and the second is human-only — call both out:

  1. Author the CI workflow file (e.g. .github/workflows/*.yml, .gitlab-ci.yml, Azure Pipelines) that runs the gate. An agent can do this.
  2. **Make that workflow an enforced gate — a required status check / branch-protection rule / merge-request approval rule. This is a manual platform-UI / admin step (GitHub → Settings → Branches; GitLab protected branches + MR settings; etc.) that an agent cannot perform.** Until a human configures it, CI runs on PRs but does not block merges.

Because step 2 is outside the agent's reach, every plan that stands up CI must emit it as an explicit user action item (in the phase's exit criteria and in §9 Open questions / decisions needed from stakeholders), so the reader knows the gate is not self-enforcing until they turn it on.

Output of Phase 2: for each component — the spike result, the chosen strategy (A or B), the located Testability Milestone, the pre/post label, and the target safety-ladder rung with any residual risk named — plus the plan-wide CI Milestone (which phase stands up CI) and the reminder that enforcing it is a manual human step. Everything downstream depends on these.

Phase 2.5: Red-team every phase against the hazard catalog (mandatory)

The strategic scaffolding above (testability, safety ladder, CI milestone) is necessary but not sufficient. Modernization plans also fail on tactical, ecosystem-predictable hazards — an incomplete quarantine set, a forgotten namespace codemod, a runtime bump that leaves the base images behind, a stateful data-store major treated as an image bump, an edge rewrite that drops the anonymous route class. These are so recurring that they have their own catalog: references/migration-hazards.md (H1–H8).

Rule: before any phase is implemented, red-team its plan against every hazard in references/migration-hazards.md. For each hazard, ask "does this phase trigger it?", run the hazard's detection probe against the real repo, and fold its plan action into the phase's tasks/exit criteria before writing code. A hazard caught in planning is a task; caught in review it's rework; caught in prod it's an incident. Record hazards you checked and cleared, not just the ones that fired — a silent skip is indistinguishable from a miss.

This is the institutionalized form of an independent-critic pass. Do it yourself by walking the catalog, and — where an independent second opinion is available (e.g. a rubber-duck / critique agent) — use it: on the reference PiggyMetrics run such a pass caught a blocking plan gap in every single phase, and each gap was an instance of an H1–H8 class. Bake the outcome into each phase's "Decisions made" and exit criteria so the executing agent inherits the cleared checklist rather than re-discovering the hazard.

Phase 3: Recommend Target Architecture

Decision framework — always evaluate in this order:

For each component/dependency, work through these levels from least-disruptive to most-disruptive. Stop at the first level that solves the problem:

  1. Upgrade in place — Can you bump the major version and fix breakages? (e.g., Node 14→22, Python 2→3, React 16→19, Rails 5→7). This is the default answer. Only reject it if the upgrade path is officially unsupported, the breaking changes are so extensive they exceed rewrite cost, or the framework itself is abandoned/EOL.
  1. Swap the dependency — If the specific library is dead but the pattern is fine, can you swap to a maintained alternative with the same interface shape? (e.g., Moment.js → date-fns, Request → got/fetch, CoffeeScript → TypeScript with decaffeinate). Prefer drop-in or mechanical migration tools when they exist.
  1. Wrap/adapt (Strangler Fig) — If the component's interface is sound but internals are unmaintainable, can you put a clean interface in front and incrementally replace internals behind it? This works when coupling is manageable and the system can run with old and new coexisting.
  1. Rewrite — Only when: the framework is abandoned with no upgrade path, the architecture fundamentally cannot support required new capabilities (e.g., synchronous-only design that must become real-time), or honest estimation shows upgrade cost exceeds rewrite cost. Require explicit justification for every rewrite recommendation — "it's old" is not sufficient.
  1. Remove — Dead code, features with zero usage, deprecated capabilities superseded by other systems. Verify usage claims before recommending removal.

Bias toward conservatism. The cheapest migration is the one you don't do. Every level of disruption adds risk, timeline, and cost. A working system on an older framework is better than a half-finished rewrite on a new one.

Mechanical-migration riders (apply whenever a recommendation is an upgrade, swap, or removal). These are the parts of a target-architecture decision that first-draft plans routinely drop; each maps to a hazard class in references/migration-hazards.md:

Produce a Target Architecture section that includes:

For each recommendation, write an inline ADR:

#### ADR: [Decision Title]
- **Context:** [Why this decision is needed]
- **Decision:** [What we chose and which decision framework level it falls under]
- **Alternatives considered:** [What else was evaluated and why it lost]
- **Consequences:** [Tradeoffs accepted]

Phase 4: Per-Feature Migration Analysis

For each major feature/domain identified in the architecture doc, produce a section covering:

  1. Current implementation — one paragraph summary with file references
  2. Migration strategy — the A/B choice from Phase 2 for this component (Freeze-then-lift vs. Beachhead/walking-skeleton), plus the tactic: Strangler Fig, Big Bang rewrite, Lift & Shift, Incremental Refactor, or Leave In Place
  3. Testability status — where this component's Testability Milestone lands, and its safety-ladder rung (L0–L4) with residual risk named
  4. Dependencies and coupling — what else breaks or must move with it
  5. Effort estimate — T-shirt size (XS/S/M/L/XL) with justification
  6. Risk assessment — what can go wrong, data migration concerns, user impact
  7. Acceptance criteria — how you know the migration succeeded (expressed against the chosen oracle/seam contracts, not against a not-yet-alive test suite)

Phase 5: Phased Implementation Plan

Produce an ordered, phased plan. Each phase should be independently deployable (no half-migrated states that can't run in production).

Phase gating is regime-aware (applies to every phase). State this rule at the top of the phased plan and honor it in every phase's exit criteria. A phase is not complete until its Verification & Exit Criteria pass. Those criteria must be (a) objectively verifiable; (b) actually executed and recorded before the next phase starts; and (c) gated — do not advance to phase N+1 until phase N's criteria are demonstrably met. But which criteria are valid depends on the component's regime (Phase 2c):

Report to the user any phase whose pass/fail is unknown rather than assuming it passed.

**The first phase establishes maximum achievable safety — not a fixed "green legacy gate."** Do not hard-code "resurrect everything and make CI green." Shape the first phase from the Phase 2 outputs, per component:

Only after the first phase's criteria are met (at whatever rung) do the subsequent infrastructure and feature phases begin.

Structure each phase as:

### Phase N: [Name] (T-shirt size: M)

**Goal:** [One sentence]
**Regime:** [pre-testability ("dark") | post-testability ("lit")] — per component
**Safety rung:** [L0–L4, with residual risk named if below L4]
**Prerequisites:** [Which phases must complete first]
**Duration estimate:** [Relative, not calendar — e.g., "2-4 sprints"]

#### Tasks
| ID | Task | Component | Blocked by |
|----|------|-----------|------------|
| N.1 | ... | ... | — |
| N.2 | ... | ... | N.1 |

#### Risks & Mitigations
- **Risk:** ... → **Mitigation:** ...

#### Decisions made
- [Every sub-decision this phase depends on, resolved and documented here so the
  phase can be implemented without further user input. State "dropped" vs
  "deferred" explicitly for anything cut.]

#### Verification & Exit Criteria (Definition of Done)
- [ ] [Regime-appropriate criterion. For LIT phases: a runnable command / green
      CI check, citing the actual command from the Commands & Verification
      Inventory. For DARK phases: the achievable safety-ladder rung's evidence —
      captured seam/oracle snapshots, reversibility proven, smoke checklist
      passed — NOT a green test suite the component can't yet run.]
- [ ] [Include a parity/characterization check against the chosen oracle whenever
      the change is meant to preserve behavior.]
- [ ] [If purely additive, assert it: "no behavior/dependency/logic changed."]
- [ ] [If exiting below L4, state the residual risk and which later phase closes
      it (e.g., "client test gate deferred to the client-migration phase").]

Ordering principles:

Phase 6: Execution Governance

Modernization plans fail in execution, not on paper. Bake in the governance that keeps each phase honest and reversible (generic across any ecosystem):

Phase 7: Migration Safety Net

Document the operational guardrails needed:

Output Structure

Produce a primary Markdown file named MODERNIZATION_PLAN.md with:

  1. Executive summary (one paragraph: what, why, rough scope)
  2. Current state assessment (from architecture doc)
  3. Feasibility spike result & strategy — per component: spike findings, the A/B migration strategy, the located Testability Milestone, the target safety-ladder rung, and a residual-risk register for anything below L4; plus the plan-wide CI Milestone (which phase stands up CI) with a note that enforcing it is a manual human step
  4. Target architecture with ADRs
  5. Per-feature migration analysis (with testability status + safety rung)
  6. Phased implementation plan — first phase establishes the highest achievable safety rung (not a fixed green legacy gate); every phase is labeled pre/post-testability and carries regime-appropriate, gated exit criteria; the CI Milestone phase is named explicitly and lists "enable branch protection / required status checks" as a manual user action
  7. Execution governance (branch-per-phase, regime-aware gate, living-plan status)
  8. Migration safety net (oracle & seam contracts, flags, rollback, observability)
  9. Open questions / decisions needed from stakeholders — including any manual platform-configuration handoffs the agent cannot perform (e.g. enabling required status checks / branch protection to make CI an enforced gate)

Also emit a companion .github/copilot-instructions.md (the path GitHub Copilot auto-loads; create .github/ if absent) from references/copilot-instructions.template.md, populated with the project's canonical commands and phase-gating / branch rules, for whoever executes the plan to edit and adopt. Never overwrite an existing .github/copilot-instructions.md — merge into it or write a sibling .github/copilot-instructions.modernization.md and flag it for the user.

Conventions

同类技能
acreadiness-assessacreadiness-generate-instructionsacreadiness-policyad-campaign-analyzeradd-educational-commentsai-readyai-research-exploreai-research-reproduction
本页内容来自开源项目 github, 版权归原作者所有。
本站仅作技能索引与分享,所有 Skill 版权归其原作者所有。