Architecture

From Kanevry/session-orchestrator · View interactive version

Architecture is an AI agent skill from the GitHub repository Kanevry/session-orchestrator. Use when the user asks to improve architecture, find refactoring opportunities, surface deepening opportunities, consolidate tightly-coupled modules, or make a codebase more testable and AI-navigable. Surfaces shallow modules and hypothetical seams using a precise vocabulary (Module / Interface / Im

How to use this skill

Skill file

Improve Codebase Architecture

Surface architectural friction and propose deepening opportunities — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.

Glossary

Use these terms exactly in every suggestion. Consistent language is the point — don't drift into "component," "service," "API," or "boundary." Full definitions in LANGUAGE.md.

Key principles (see LANGUAGE.md for the full list):

This skill is _informed_ by the project's domain model — CONTEXT.md and any docs/adr/. The domain language gives names to good seams; ADRs record decisions the skill should not re-litigate. See references/CONTEXT-FORMAT.md and references/ADR-FORMAT.md.

When to load references/domain-model.md: before this skill's first pass on a repo with no CONTEXT.md yet, or one too thin to name the seams below — run its grilling interview to establish the domain vocabulary first. Skip it once CONTEXT.md already reflects the domain.

Process

1. Explore

Read existing documentation first:

If any of these files don't exist, proceed silently — don't flag their absence or suggest creating them upfront.

Optional pre-pass — export inventory injection (mapper-supported projects only):

Before dispatching the Explore subagent, read each known entry-point file (e.g. index.ts, src/index.ts, the main export barrel) and pass its contents to extractSemanticSlices(filePath, content) from scripts/lib/language-mappers/index.mjs. The signature is (filePath, content, options?) — the second argument is the raw file text, not an options object, and there is no slice-kind filter parameter. It resolves to an array of SemanticSlice records ({ kind, name, exported, … }); keep the ones with exported === true, format them as structured context, and inject that into the Explore subagent prompt. This gives the subagent an immediate map of the codebase's public surface without requiring it to grep manually.

## Export inventory (auto-generated)
- src/lib/foo.ts: exports `createFoo`, `FooConfig`, `FooError`
- src/lib/bar.ts: exports `processBar`

This pre-pass is OPTIONAL — only activate when the entry-point file is mapper-supported (.ts, .tsx, .js, .jsx, .mjs, .cjs, .md, .mdx, .swift, .py — the EXT_TO_LANG map in index.mjs is the source of truth). For any other extension extractSemanticSlices throws rather than returning an empty array, so wrap the call in a try/catch and skip the pre-pass silently on failure. Never block Explore dispatch on a mapper error.

Then use the Agent tool with subagent_type=Explore to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:

Apply the deletion test to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.

2. Present candidates

Present a numbered list of deepening opportunities. For each candidate:

Use CONTEXT.md vocabulary for the domain, and LANGUAGE.md vocabulary for the architecture. If CONTEXT.md defines "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."

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?"

3. Grilling loop

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.

Side effects happen inline as decisions crystallize:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.