/harlan-agent-kit:improve-ts-pkg-architecturefrom harlan-agent-kit
Reviews TypeScript package architecture for refactoring opportunities, focusing on exports, workspaces, module boundaries, and testability in libraries, CLIs, or pnpm monorepos.
Ships in harlan-agent-kit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Surface architectural friction in a TypeScript package (library, CLI, or pnpm monorepo) and propose deepening opportunities — refactors that turn shallow modules into deep ones, using the package's own publishable surface as the seam. The aim is testability and AI-navigability.
Vocabulary, principles, and forbidden patterns live in their canonical files; this file references them. Use the terms in LANGUAGE.md exactly. This skill is informed by the project's domain model (GLOSSARY.md, docs/arch/, docs/adr/).
Before any edit, read and follow the worktree isolation contract.
Keep mutation in a task-owned wt worktree with a live claim. Keep the primary checkout read only.
packages/*), testing strategy.exports, conditional exports, packages/*, catalogs, bin, hookable, unplugin, citty).Read the published surface and the requested boundary first. Use scoped inspection to resolve a specific uncertainty.
Read the installed ripast Skill before using RipIDE. Prefer a supplied launcher and preserve its version.
Use RipIDE for supported mechanical operations. Design new contracts with direct edits.
Before a cross-package move, check destination dependencies and exported entry points.
Support architectural claims with the relevant exports, imports, call sites, or semantic tool evidence.
Text matches and classified scan occurrences do not establish unique semantic consumers.
State the evidence's scope and limits. Do not run every discovery command merely to establish tool usage.
In examples, ripide means the supplied or prepared launcher.
Pass --tsconfig only to commands that accept it. scan, tree, and unused do not accept it.
Scope discovery with a relevant --glob, such as 'packages/core/src/**'. Expand only when needed.
Choose an inspection only when it can change the next decision:
| Command | What it surfaces |
|---|---|
ripide unused --glob 'packages/core/src/**' --exports local | Top-level declarations with zero project references → deletion-test slam-dunks |
ripide tree --glob 'packages/core/src/**' --exports exported | Public surface per file → shallow modules + leaks (anything exported that isn't in the exports map is a confessed private leak) |
ripide tree --glob 'packages/core/src/**' --exports local | Internals per file → locality opportunities |
Per-candidate, before listing (scan is rg-driven — use --glob here):
| Command | What it surfaces |
|---|---|
ripide scan <symbol> --glob ... | Caller count + kind classification → drives deletion test + §2 thresholds |
ripide scan <symbol> --kind identifier-reference,import-specifier --glob ... | Same, minus string-literal noise |
ripide scan <symbol> --graph mermaid --glob ... | Importer graph → cross-package leaks (graph spanning packages/a/src/ + packages/b/src/ via deep import) |
Cite supported numbers when presenting. Otherwise describe the verified relationship without an invented count. Save full output as an artifact. Read relevant names, locations, and short context into the model. Batch independent reads. Keep dependent mutations and checks sequential.
Read package.json exports, bin, peerDependencies, sideEffects, and engines. The exports map is the contract.
Then read GLOSSARY.md, docs/arch/, and docs/adr/ when present.
Orient on the package shape:
bin field), a plugin (peer-dep on rollup/vite/eslint/etc.), or a pnpm monorepo with packages/*?types/import/node/browser/workerd), packages/*, catalog: versions, hookable hooks, unplugin/factory shape, citty subcommands, c12 config loading?EventEmitter, a custom plugin registry, ad-hoc env reads) instead of using one the ecosystem provides?Then use the Agent tool with subagent_type=Explore to walk the codebase. Note friction signals:
new a class, utils that wrap one-liners. Spot via tree --exports exported.scan <symbol> --graph mermaid spanning 10+ directories.process.env deep inside, singletons at import, side effects on import.exports map. Detect with scan <symbol> --graph mermaid straddling two packages/*. See TS-PKG-SEAMS.md Workspace packages.exports map leaks — deep paths (pkg/dist/internal/foo) instead of declared subpaths. Either expose a subpath or stop the leak.hookable is the answer. Detect via two-way edges in scan --graph mermaid.pnpm dlx publint && pnpm dlx @arethetypeswrong/cli --pack . plus du -sh dist/.Present a numbered list of deepening opportunities. For each candidate:
src/index.ts, src/cli.ts, packages/core/src/foo.ts, package.json exports, pnpm-workspace.yaml)createPipeline(opts) factory exported from a new ./pipeline subpath; the existing files become private implementation under src/pipeline/, and the factory exposes a hookable hook bus for the three current extension points")Use GLOSSARY.md for the domain, LANGUAGE.md for the architecture, TS-PKG-SEAMS.md for the framework seam, and the relevant convention section from PKG-CONVENTIONS.md when the candidate is a convention gap. Example phrasings: "the Order intake module exposed as a ./intake subpath", "establish PKG-CONVENTIONS.md §Hook bus for the build pipeline" — not "the FooBarHandler", not "the Order service".
Reject before listing. Validate consumer relationships from resolved imports and call sites; no guesswork.
Use scan <symbol> --kind identifier-reference,import-specifier to locate candidates, then inspect their identity.
packages/* ≥2 independent consumers AND zero coupling back to the host; factory ≥2 callers OR real branching/options; pure value/type mapping ≥4 callers.scan <import-specifier> --kind import-specifier.Forbidden patterns (always flag, never propose) — full list in PKG-CONVENTIONS.md §"Forbidden patterns".
ADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly (e.g. "contradicts ADR-0007 — but worth reopening because…"). Don't list every theoretical refactor an ADR forbids.
Do NOT propose interfaces yet. Ask the user: "Which of these would you like to explore?"
Once the user picks a candidate, drop into a grilling conversation. Walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive. For TS-pkg candidates, also walk: which runtimes it must work in (node / browser / workerd / edge / bun), whether it appears in the exports map (and at which subpath / conditional), whether it lives in src/ or a workspace packages/*, what the treeshake / sideEffects story is.
Side effects happen inline as decisions crystallize:
Naming a deepened module after a concept not in GLOSSARY.md? Read the installed Brundlefly glossary Skill and add the term there: the term, one sentence of meaning in this codebase, and where it lives.
Sharpening a fuzzy term during the conversation? Update GLOSSARY.md right there.
User rejects the candidate with a load-bearing reason? Offer an ADR, framed as: "Want me to record this as an ADR so future architecture reviews don't re-suggest it?" Only offer when the reason would actually be needed by a future explorer to avoid re-suggesting the same thing — skip ephemeral reasons ("not worth it right now") and self-evident ones. Write it to docs/adr/NNNN-slug.md with context, decision, and consequences.
Want to explore alternative interfaces for the deepened module? See INTERFACE-DESIGN.md. Sub-agents are pre-seeded with TS-pkg-native shapes (single factory, factory + hook bus, subpath-exposed surface, ports & adapters) so the design space is grounded in what the ecosystem already offers.
Need to know the true blast radius of a rename/move before committing? ripide scan <symbol> (counts) or ripide scan <symbol> --graph mermaid (importer graph). Quote numbers before promising scope.
Decision crystallized into a concrete refactor? Execute through ripast, not Edit. Pick the primitive:
Pass --tsconfig tsconfig.json (or the per-package one) on rename, move, and rename-file so all callers are rewritten.
| Refactor | Command |
|---|---|
| Rename a symbol across files | ripide rename <from> <to> --tsconfig tsconfig.json --apply (add --scope <file> if multi-declared) |
| Move an exported declaration | ripide move <symbol> --from <a> --to <b> --tsconfig tsconfig.json --apply |
Move a file (e.g. src/utils/foo.ts → src/pipeline/foo.ts to close a leak) | ripide rename-file <old> <new> --tsconfig tsconfig.json --apply |
Use the installed ripast Skill's operation and verification guidance.
Keep verification enabled. Recover complete diagnostics before classifying an apparent false positive.
Design new APIs and behavior with direct edits. Use supported semantic commands for their mechanical changes.
If public types or exports change, rebuild affected declarations before downstream typechecks.
Repair a failed check, then run the focused proving check before broad verification.
Keep meaningful failing-first tests. Do not repeat unchanged failing lint commands.
Repeat passed checks only after relevant edits or new evidence. Run required final checks on the submitted tree.
The refactor changes the exports map? Update package.json exports in the same pass. If a subpath is added or removed, the change is a SemVer-visible event — note it for the next release.
What SKILL.md sets; muted values are Claude Code's defaults
highThree short reads, in order
35 skills in this plugin
/adversarial-reviewReview one pull request adversarially, hand permitted defects to Repair, verify the remote head, and publish the Harlan Agent Kit bot status. Use for rigorous pre-merge PR review./agent-feedbackImprove one Agent skill from explicit Review feedback. Use only for the agent-feedback Routine./agent-retroWeekly retro of Harlan GitHub Agent sessions. Group transcripts by goal, find repeated and wasted work, and rank fixes to the controller, prompts, skills, or model. Use for agent retro, session review, agent efficiency, or self-improvement runs.npx claudepluginhub harlan-zw/harlan-agent-kit --plugin harlan-agent-kitOther plugins' skills for the same job