module-init
Starts Segmently Modules from an existing codebase that has no module registry yet. Maps the code into candidate modules and stops for the user to confirm them, has one writer per module document its code (subagents, or itself one module at a time), reconciles the registry, measures how well tasks route, and stops again before anything lands in the repository. Use when the user asks to set up, bootstrap or generate module docs for an existing repository, or to continue an interrupted init.
- License 许可
- MIT
- 最近更新
- 2026-10-21
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- module-init
- description
- Starts Segmently Modules from an existing codebase that has no module registry yet. Maps the code into candidate modules and stops for the user to confirm them, has one writer per module document its code (subagents, or itself one module at a time), reconciles the registry, measures how well tasks route, and stops again before anything lands in the repository. Use when the user asks to set up, bootstrap or generate module docs for an existing repository, or to continue an interrupted init.
02 资源文件 1
- 参考文档references/phases.md4.9 KB
03 SKILL.md 正文
module-init
Take a repository that has code but no module registry to a working setup — a registry, one doc
set per module, code routing rules, the agents' block — through Segmently Modules' init. The engine keeps
the state in <config_dir>/init/; this skill supplies the judgement and the two stops where the
user decides.
When to use
- The repository has code and no modules yet, and the user wants module docs for it.
- An init was started earlier (by a person, a pipeline or another session) and the user says "continue", "resume" or "finish the init".
When not to use
- The repository already has a registry and module docs written by other tooling: use
module-adopt. - One new module in a repository that already has modules: use
module-create. - An oversized module must become children: use
module-split.
Scope
Writes: the proposal at gate 3 (only the edits the user asked for), the work items' staging
docs through its writers, the staging registry's keywords, and — after the user's yes at gate 7
— what the finish step writes (the module docs, the registry, the code-map rules, the
agents' block). It never edits code, never edits a *.legacy.md file, never touches a module
that was already in the registry, and never commits: the user reviews and commits.
If segmently-modules is not found, tell the user how to install it — the segmently-modules plugin for Claude Code, uv tool install git+https://github.com/segmently-ai/segmently-modules.git, or pipx install git+https://github.com/segmently-ai/segmently-modules.git — and stop until it runs.
Steps
-
Where are we? Run
segmently-modules init status --jsonfirst and continue from the recorded phase (itsnextnames the step). Without a state, start at step 2. A module already in the registry when the fan-out ran shows asdone (existing): it is kept as it is. -
Map the code.
segmently-modules init map --jsonIt writes
<config_dir>/init/proposal.json. Present the candidates in a short table — name, paths, confidence, the rationale in a few words — then thehints(merge,split; asplitwithchildren: offer them, grouped by feature) and theunassignedcode files. The seed keywords are already filtered (no npm scope, no token of 3 characters or fewer). -
STOP — gate 3. Ask the user which candidates to keep, merge, split, rename or exclude. Apply exactly those merges, splits, renames and exclusions to
proposal.json(include,name,paths), nothing else, then confirm:segmently-modules init confirm --jsonExit 2 lists every problem at once (a name that breaks the rule, a glob that matches no file, two candidates claiming one file): fix them with the user and confirm again. After the fan-out starts, the module set is fixed (only
segmently-modules init map --restart --jsonstarts over). -
Write the work items.
segmently-modules init fanout --jsonOne work item per confirmed module in
<config_dir>/init/work/<module>.json, each with thepromptits writer follows.init statusshows each module's status. -
Have every module written. Claim items with
segmently-modules init next --json— never dispatch an item you did not claim. With subagents: claim at mostmax_parallelitems ([init] max_parallel, 4 by default) and dispatch one subagent per item, each given its work item path (pathin the result) and told to follow the item'spromptand write only into itsstaging_dir; claim the next item as one finishes. Without subagents, loop yourself: claim, read the module's code, write its files, check, claim the next. After each writer:segmently-modules init done <module> --jsonExit 1 names each problem of the staging output (a missing doc, an unfilled placeholder, a path that does not exist, a symbol not in its row's file, too few keywords, an edge to an unknown module): have the same writer fix them while it has the context, then check again. A claim whose
itemhasprevious_problems(an earlier attempt was refused) goes to the writer with them: give a subagent those problems together with its work item path — the work item file does not hold them — and tell it to fix them first; without subagents, the claim result'sitem.promptalready ends with them. An item that stays wrong: tell the user. The detailed rules for writers are inreferences/phases.md. -
Reconcile.
segmently-modules init reconcile --jsonIt adds the import edges, gives a keyword several new modules share to the one with the most files and removes it only from the modules whose code never mentions it (no negative keyword), drops a keyword no holder's code mentions (
dropped: show them in one line), and lists thejudgementitems it will not decide. Ask the user about each keyword tie (whether one module owns the word) and each keyword that could not be removed without dropping a module below the keyword minimum; report the duplicate names with their file:line (the user decides later whether code moves). By default a tied keyword stays on every module that holds it, since routing ranks the modules by their other words too; only when the user names one owner, remove the word from the other modules'keywords— never as a negative keyword. Apply the user's keyword answers to<config_dir>/init/staging/registry.json. -
Measure routing. Get the task writer's prompt:
segmently-modules eval routing --prompt --jsonHave a subagent that never shows the keywords — it gets only this prompt — write the tasks as JSON into
<config_dir>/init/routing-tasks.json. Without subagents, write them yourself from the prompt alone, before you look at any keyword. Then verify:segmently-modules init verify --json -
Fix what verify found. Lint findings: fix the staging docs or the staging registry. Invented components (a path that does not exist, a symbol not in its file): remove or correct them in the staging docs.
keywordsrows (too many words, a generic word): trim them in the staging registry,unused_keywordsfirst. Routing misses below the threshold: change keywords, never the tasks — at most 2 rounds; after that, report the remaining misses. Each round, in this order:- First, a missed module that was already in the registry (
done (existing)): it is never changed in the staging registry — the finish step refuses that. Ask the user, change it in the registry itself, then runsegmently-modules init reconcile --force --json. It rebuilds the staging registry from the writers' files, so a keyword edit made there before it is lost. - Then improve the keywords of the missed NEW modules in the staging registry (the words the missed tasks used).
- Then verify again.
- First, a missed module that was already in the registry (
-
STOP — gate 7. Show the verify summary: lint counts, invented components, the hit rate and its misses, the first-place rate, the judgement items still open. End that message with one direct yes/no question — "Shall I run segmently-modules init finish now?" — and wait for the answer: naming the next command is not asking. Only on a yes:
segmently-modules init finish --jsonIt moves the docs into place, writes the registry, the code-map rules and the agents' block. Show its
git_addline and ask the user to review and commit. Never commit yourself.
Gates
- Gate 3 (step 3): nothing is written into
work/before the user confirmed the candidates. - Gate 7 (step 9): nothing lands in the modules dir, the registry or the config before the user's yes.
- The finish step refuses a verify that has not passed, or a staging tree changed since:
run
segmently-modules init verify --jsonagain; use--forceonly when the user asks for it.
Exit codes
0 ok · 1 findings: init done problems, a verify or eval that did not pass — fix and run
again · 2 a refused step (the wrong phase, a bad proposal, a conflict): read stderr, it names
the step to run.
04 同仓库更多 Skills
${skill}
${description}
designer
Designs user interface work and reviews it against the designer docs of the modules it touches. Prototype — a brief and standalone HTML mocks from the team's tokens, then it waits for approval before any code; rework-audit — an existing flow's dead ends and what must survive, before a redesign; review — screenshots of the running app checked against every UX invariant and the flow patterns, always written with a PASS or BLOCKED verdict. Use for any task that adds or changes screens, dialogs, layouts or styling, or when the user asks for a mockup, prototype, design, UI or UX review.
qa-acceptance
Writes the acceptance criteria of one task before any code is written. Finds the touched modules with discover, reads their qa and qa_acceptance docs, flags problems in the task itself, splits it into sub-tasks, applies equivalence partitioning, boundary values, decision tables or state transitions, and writes prerequisites PRE-NNN and criteria AC-NNN in Given, When, Then form, reusing existing baseline criteria by id. Shows them in the conversation; a file only at a path the user names. Use when the user asks for acceptance criteria, a test plan or a definition of done for a task.
qa-acceptance-baseline
Creates or refreshes a module's acceptance baseline, the qa_acceptance role doc that says what must never break, as P0, P1 and P2 criteria with stable AC-NNN ids in Given, When, Then form. Reads every doc and the code of the module through Segmently Modules, confirms its understanding, the requirements and the criteria with the user block by block, continues from the highest existing id and never renumbers. Use when the user asks for a module's acceptance baseline, regression criteria, or to refresh them after the module changed.
module-sync
Brings module docs and registry fields in line with a work session — what it decided, rejected, discovered and changed. Takes the session's knowledge first and the code change second, asks sync-instructions which docs to update, prints findings and a proposal per module, edits docs, keywords and links, runs the sync hooks and checks with ci. Autonomous, it asks only in four ambiguous cases and never commits. Use at the end of a session that changed module code or revealed module knowledge, when the user says "sync the session", "sync the docs", or a CI drift check fails.
module-split
Splits an oversized module into two to six child modules. Analyses the module's docs section by section, proposes the children with a section-to-child table per doc and what stays in the parent, and stops for confirmation. Then freezes each split doc as a legacy copy, creates the children with create, moves the sections word for word, rewrites the parent as an index, routes the code and validates with lint. Use when lint reports a module doc over its size budget, or the user says "split this module", "too big", "break X into submodules".