Scaffold TypeScript projects, rebuild them with refactor, and enforce repository policy with verify.
Create a new project:
npx @sha3/code init --template node-service --yesRealign an existing repo:
npx @sha3/code refactor --yesRun verification for humans:
npx @sha3/code verifyRun verification for automation:
npx @sha3/code verify --report jsonExplain a deterministic rule:
npx @sha3/code verify --explain single-returnUse it directly with npx:
npx @sha3/code --helpOr install it in a repo:
npm install -D @sha3/code- Node.js 20.11+
- ESM package runtime
- TypeScript-first projects
- Biome as the baseline formatter and linter
@sha3/code manages 3 different concerns:
init: creates a standards-managed TypeScript scaffoldrefactor: snapshots an existing repo and rebuilds it onto the managed scaffoldverify: enforces repository policy that generic tooling does not cover well
That last part matters: verify is not another formatter or typechecker. It is the package-specific policy engine for generated repos.
Generated scaffolds are also expected to ship package-grade README files rather than placeholder docs.
Simplicity is mandatory.
- choose the simplest correct implementation for the current requirement
- avoid speculative abstractions, helper layers, wrappers, and extension points without immediate need
- if two solutions are both correct, prefer the smaller and more direct one
- do not remove valid responsibility boundaries in the name of simplicity
- simplicity means avoiding gratuitous complexity, not reducing structure blindly
- let Biome decide final wrapping; prefer compact code, but do not force single-line layouts that the formatter keeps multiline
code-standards init
code-standards refactor
code-standards profile
code-standards verify@sha3/code/biome
@sha3/code/tsconfig/base.json
@sha3/code/tsconfig/node-lib.json
@sha3/code/tsconfig/node-service.jsoncode-standards verify [--report text|json] [--only <rule-id[,rule-id...]>] [--files <path[,path...]>] [--strict]
code-standards verify --explain <rule-id>Behavior notes:
initalways works in the current directory and creates a fresh scaffold.refactoralways works in the current directory and never accepts a remote or local source argument.refactorsnapshots the previous repo state under.code-standards/refactor-source/before rebuilding managed files.verifyis the project-policy checker. It complements Biome and TypeScript instead of replacing them.verify --report jsonis intended for CI, PR automation, and scripts.- default
verifyfails only onerrorseverity;--strictalso fails onwarning. verify --explain <rule-id>prints operational documentation for a rule without checking the repo.code-standards verify --helpprints the same option surface shown above.
verify covers project policy that is specific to @sha3/code, including:
- contract presence and validity for
AGENTS.mdandai/contract.json - metadata sync between
package.json.codeStandardsandai/contract.json - required managed files from the active template
- required README sections
- README documentation for public exports and public class methods
- HTTP API documentation for service templates
- TypeScript-only source policy in
src/andtest/ - deterministic AST rules such as
single-return,async-await-only,canonical-config-import, and file naming rules single-returnstays strict insrc/except forsrc/http/**, where transport handlers may use early returns when that keeps request flow clearer
verify does not replace the generic toolchain:
- formatting, line wrapping, and generic lint rules stay in Biome
- type correctness stays in TypeScript
- runtime behavior stays in tests
Use the tools together, not interchangeably:
- run Biome when you want style, formatting, and baseline lint feedback
- run TypeScript when you want type-safety feedback
- run
verifywhen you want to enforce repository contract, scaffold integrity, and project-policy rules
mkdir my-service
cd my-service
npx @sha3/code init --template node-service --yesUse init when you are starting a new repo from the managed scaffold.
- Create and enter the target directory.
- Run
initwith the template you want. - Review the generated contract files before asking an LLM to write code.
- Fill
PROMPT.mdand give only that file to the LLM. - Make the LLM execute
npm run checkitself and fix any failures before it finishes.
Minimal flow:
mkdir my-service
cd my-service
npx @sha3/code init --template node-service --yesWhat init generates for you:
AGENTS.mdas the repo policy entrypointSKILLS.mdas the index of specialized workflows that should only be loaded when relevantai/contract.jsonas the deterministic standards contractai/rules.mdas the concise human-readable implementation rules file for the LLMskills/*workflow guides such as init, refactor, feature shaping, simplicity audit, change synchronization, test scope selection, HTTP API conventions, and README authoringai/<assistant>.mdadapter files when AI adapters are enabledPROMPT.mdin the project root as the single user-authored request file and LLM entrypointprompts/init.prompt.md,prompts/init-phase-2-implement.md, andprompts/init-phase-3-verify.mdas internal workflow prompts the LLM should load by itself- the managed
src/,test/, config, and package surface for the selected template - a README scaffold that is meant to be rewritten into package-grade integration documentation once real behavior exists
- a root
SCAFFOLD-FEEDBACK.mdhandoff requirement in the generated workflow so the LLM leaves scaffold/process feedback after implementation
The CLI also prints the minimal next step after init, so the user does not have to infer the LLM workflow manually.
Recommended LLM workflow after init:
- Open
PROMPT.md. - Complete the final
User Requestsection. - Paste only
PROMPT.mdinto the LLM. - Let the LLM read
prompts/init.prompt.md,prompts/init-phase-2-implement.md, andprompts/init-phase-3-verify.mdby itself. - Let the LLM load optional skills only when the workflow actually triggers them.
Minimal request example for PROMPT.md:
Task:
- Build the first HTTP endpoint for service health.
- Keep the generated scaffold structure intact.
- Add tests for the new behavior.The final phase must explicitly require the LLM to execute:
npm run checkThe final phase must also require the LLM to fix any failing checks, rewrite README.md when behavior changes, and create or update SCAFFOLD-FEEDBACK.md.
Run this from the project root:
npx @sha3/code refactor --yesrefactor will:
- analyze the current repository
- capture preservation decisions
- write
.code-standards/refactor-source/latest/ - write
public-contract.json,preservation.json, andanalysis-summary.md - rebuild the managed scaffold
- generate the LLM workflow pack, with
PROMPT.mdas the single user entrypoint
Use refactor when you already have a repo and want to rebuild it onto the managed scaffold without losing the contracts you choose to preserve.
- Go to the root of the existing project.
- Run
refactor. - Answer the preservation questions if you are in interactive mode.
- Let the command move the legacy code into
.code-standards/refactor-source/latest/and rebuild the managed surface. - Open
PROMPT.mdand complete the request section. - Paste only
PROMPT.mdinto the LLM and let it load the refactor artifacts and phase prompts itself. - Require the LLM to execute
npm run checkitself and fix any failures before it finishes. - Require the LLM to finish by creating or updating
SCAFFOLD-FEEDBACK.mdwith concrete scaffold/process feedback.
Typical command:
npx @sha3/code refactor --yesIf you want dependencies installed as part of the run:
npx @sha3/code refactor --yes --installAfter refactor, these files matter most:
PROMPT.mdAGENTS.mdSKILLS.mdskills/feature-shaping/SKILL.mdskills/simplicity-audit/SKILL.mdskills/change-synchronization/SKILL.mdskills/test-scope-selection/SKILL.mdskills/http-api-conventions/SKILL.mdai/contract.jsonai/rules.mdskills/refactor-workflow/SKILL.md.code-standards/refactor-source/public-contract.json.code-standards/refactor-source/preservation.json.code-standards/refactor-source/analysis-summary.md.code-standards/refactor-source/latest/prompts/refactor.prompt.mdprompts/refactor-phase-2-rebuild.mdprompts/refactor-phase-3-verify.md
The CLI prints the single LLM entry file after refactor completes. The normal flow is: run refactor, complete PROMPT.md, and give only that file to the LLM.
Important behavior note:
refactordoes not runnpm run fixornpm run checkagainst the intermediate refactor state.refactordoes not run the finalnpm run checkagainst the pre-refactor codebase.- The old implementation is moved to
.code-standards/refactor-source/latest/as reference material. - The final validation belongs to the rewritten
src/andtest/produced after the LLM handoff.
Recommended LLM workflow after refactor:
- Run
refactorand wait for it to complete. - Open
PROMPT.mdand complete theUser Requestsection. - Paste only
PROMPT.mdinto the LLM. - Let the LLM read
prompts/refactor.prompt.md,prompts/refactor-phase-2-rebuild.md, andprompts/refactor-phase-3-verify.mdby itself. - Let the LLM rebuild, verify, and close the task end to end.
Minimal request example for PROMPT.md:
Task:
- Rebuild the application behavior inside the fresh scaffold under src/ and test/.
- Preserve the public API and HTTP contracts captured in the refactor artifacts.
- Do not edit managed files unless a standards update is explicitly required.- Make the final phase rewrite
README.mdas package-grade integration documentation for the rebuilt public API and runtime behavior when needed. - In the final phase, explicitly require the LLM to execute:
npm run check- Require the LLM to fix any failing checks and rerun the command until it passes.
Practical rule: refactor prepares the repo and the context pack; the user only fills PROMPT.md, and the LLM consumes the rest of the workflow pack autonomously.
Human-readable verification:
npx @sha3/code verifyMachine-readable verification:
npx @sha3/code verify --report jsonFocused verification by rule:
npx @sha3/code verify --only single-return,canonical-config-importFocused verification by files:
npx @sha3/code verify --files src/user/user.service.ts,test/user.test.tsStrict verification:
npx @sha3/code verify --strictCombined scope control:
npx @sha3/code verify --report json --only single-return --files src/user/user.service.tsRule explanation:
npx @sha3/code verify --explain single-returnverify is the command generated projects use behind npm run standards:check.
Generated projects centralize runtime constants in src/config.ts.
This package centralizes standards through:
standards/manifest.jsonas the canonical standards manifestprofiles/default.profile.jsonas the default AI profilebiome.jsonas the shared Biome config export
Profile-driven behavior can be customized with:
npx @sha3/code profile --profile ./profiles/team.profile.jsonThen applied during init or refactor with --profile.
Repository-level scripts:
npm run check: standards validation, profile validation, AI resource validation, Biome lint, Biome format check, typecheck, testsnpm run fix: Biome write + format writenpm run lint:biome check .npm run format:check:biome format .npm run typecheck: TypeScript validationnpm run test: smoke fixtures plus Node test runner
Generated project scripts:
npm run standards:check:code-standards verifynpm run check: standards + lint + format + typecheck + testsnpm run fix: Biome autofix + format write
Key repository paths:
bin/code-standards.mjs: CLI entrypointlib/cli/run-init.mjs: project initialization flowlib/cli/run-refactor.mjs: in-place refactor flowlib/cli/run-verify.mjs: deterministic verification flowlib/verify/: issue model, explain mode, renderers, project checks, and AST-level source rulestemplates/:node-libandnode-servicemanaged scaffoldsprompts/: starter prompts forinitandrefactorresources/ai/: AI contract templates, adapters, examples, and rule catalog
Install dependencies in the current workspace:
npm installRun code-standards refactor from the root of the target project.
verify has 5 useful modes:
- default text mode: human-readable errors to
stderr --report json: structured output tostdout--only: execute only selected rule ids--files: limit file-oriented checks to a subset of files--strict: fail on warnings as well as errors--explain: print documentation for one rule instead of verifying the repo
Important behavior:
- project-wide contract checks still run even when
--filesis used - file-oriented checks such as AST source rules and TypeScript-only checks are scoped by
--files --explaincannot be combined with--report,--only, or--filestextremains the default output mode to preserve human-friendly local usage
Example text output:
- ERROR [single-return] src/user/user.service.ts: functions and methods outside src/http/ must use a single return statement
- WARNING [large-class-heuristic/heuristic] src/user/user.service.ts: very large classes should be decomposed into smaller cohesive units
Verification failed with 1 error(s) and 1 warning(s).Example JSON output:
{
"ok": false,
"hasWarnings": true,
"issues": [
{
"ruleId": "single-return",
"category": "source-rule",
"severity": "error",
"message": "functions and methods outside src/http/ must use a single return statement",
"relativePath": "src/user/user.service.ts",
"enforcedBy": "verify"
}
],
"summary": {
"issueCount": 1,
"errorCount": 1,
"warningCount": 0,
"auditCount": 0,
"checkedRuleIds": ["single-return"],
"checkedFiles": ["src/user/user.service.ts"]
}
}Exit code behavior:
- exit code
0: verification passed at the requested severity threshold - exit code non-zero: verification found blocking severities for the current mode or arguments were invalid
Save a structured report:
npx @sha3/code verify --report json > verify-report.jsonFail a script based on the result:
node -e 'const fs=require("node:fs"); const report=JSON.parse(fs.readFileSync("verify-report.json","utf8")); if(!report.ok) process.exit(1)'Run a targeted CI check for a narrow rule:
npx @sha3/code verify --report json --only single-returnIf verify fails, first decide what kind of failure it is:
- contract/metadata/layout problem: check
AGENTS.md,ai/contract.json,package.json.codeStandards, or missing scaffold files - source-rule problem: use the reported
ruleId, file path, andverify --explain <rule-id> - README problem: restore the required sections
Common cases:
- unknown rule id in
--only: usecode-standards verify --explain <rule-id>or inspectresources/ai/rule-catalog.json - too much output: narrow the run with
--onlyor--files - Biome and TypeScript pass but
verifyfails: expected, becauseverifychecks product policy and contract rules that generic tooling does not cover, but line-wrapping disputes should now be treated as Biome territory
Keep these headings in generated projects, at minimum:
- for both templates:
## TL;DR,## Why,## Main Capabilities,## Installation,## Usage,## Examples,## Public API,## Configuration,## Compatibility,## Scripts,## Structure,## Troubleshooting,## AI Workflow - for
node-servicealso:## Running Locallyand## HTTP API
Use the biomejs.biome extension as the default formatter for generated projects.
Generated projects treat these files as the local AI contract:
ai/contract.jsonAGENTS.mdSKILLS.mdskills/*ai/rules.mdai/<assistant>.md
Recommended bootstrap prompt:
Before generating code:
- Read AGENTS.md, SKILLS.md, ai/contract.json, ai/rules.md, and ai/<assistant>.md.
- Load `skills/init-workflow/SKILL.md`, `skills/feature-shaping/SKILL.md`, `skills/simplicity-audit/SKILL.md`, and `skills/change-synchronization/SKILL.md` for init-based implementation.
- Load `skills/refactor-workflow/SKILL.md`, `skills/feature-shaping/SKILL.md`, `skills/simplicity-audit/SKILL.md`, and `skills/change-synchronization/SKILL.md` for refactor work.
- Load `skills/test-scope-selection/SKILL.md` for meaningful behavior changes, `skills/readme-authoring/SKILL.md` whenever README changes, and `skills/http-api-conventions/SKILL.md` whenever HTTP endpoints exist or change.
- Summarize the `error` rules and the `warning` rules you will review carefully.
- Implement the task without editing managed files unless this is a standards update.
- Run npm run check and fix all failures before finishing.For a standards migration on an existing repo, run refactor first and then use the generated files under .code-standards/refactor-source/ as reference context for the rewrite.