@sha3/code 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +75 -0
- package/README.md +554 -0
- package/ai/adapters/codex.md +7 -0
- package/ai/adapters/copilot.md +7 -0
- package/ai/adapters/cursor.md +7 -0
- package/ai/adapters/windsurf.md +8 -0
- package/ai/constitution.md +12 -0
- package/bin/code-standards.mjs +47 -0
- package/biome.json +37 -0
- package/index.mjs +11 -0
- package/lib/cli/parse-args.mjs +416 -0
- package/lib/cli/post-run-guidance.mjs +43 -0
- package/lib/cli/run-init.mjs +123 -0
- package/lib/cli/run-profile.mjs +46 -0
- package/lib/cli/run-refactor.mjs +152 -0
- package/lib/cli/run-verify.mjs +67 -0
- package/lib/constants.mjs +167 -0
- package/lib/contract/load-rule-catalog.mjs +12 -0
- package/lib/contract/render-agents.mjs +79 -0
- package/lib/contract/render-contract-json.mjs +7 -0
- package/lib/contract/resolve-contract.mjs +52 -0
- package/lib/paths.mjs +50 -0
- package/lib/profile.mjs +108 -0
- package/lib/project/ai-instructions.mjs +28 -0
- package/lib/project/biome-ignore.mjs +14 -0
- package/lib/project/managed-files.mjs +105 -0
- package/lib/project/package-metadata.mjs +132 -0
- package/lib/project/prompt-files.mjs +111 -0
- package/lib/project/template-resolution.mjs +70 -0
- package/lib/refactor/materialize-refactor-context.mjs +106 -0
- package/lib/refactor/preservation-questions.mjs +33 -0
- package/lib/refactor/public-contract-extractor.mjs +22 -0
- package/lib/refactor/render-analysis-summary.mjs +50 -0
- package/lib/refactor/source-analysis.mjs +74 -0
- package/lib/utils/fs.mjs +220 -0
- package/lib/utils/prompts.mjs +63 -0
- package/lib/utils/text.mjs +43 -0
- package/lib/verify/change-audit-verifier.mjs +140 -0
- package/lib/verify/change-context.mjs +36 -0
- package/lib/verify/error-handling-verifier.mjs +164 -0
- package/lib/verify/explain-rule.mjs +54 -0
- package/lib/verify/issue-helpers.mjs +132 -0
- package/lib/verify/project-layout-verifier.mjs +259 -0
- package/lib/verify/project-verifier.mjs +267 -0
- package/lib/verify/readme-public-api.mjs +237 -0
- package/lib/verify/readme-verifier.mjs +216 -0
- package/lib/verify/render-json-report.mjs +3 -0
- package/lib/verify/render-text-report.mjs +34 -0
- package/lib/verify/source-analysis.mjs +126 -0
- package/lib/verify/source-rule-verifier.mjs +453 -0
- package/lib/verify/testing-verifier.mjs +113 -0
- package/lib/verify/tooling-verifier.mjs +82 -0
- package/lib/verify/typescript-style-verifier.mjs +407 -0
- package/package.json +55 -0
- package/profiles/default.profile.json +40 -0
- package/profiles/schema.json +96 -0
- package/prompts/init-contract.md +25 -0
- package/prompts/init-phase-2-implement.md +25 -0
- package/prompts/init-phase-3-verify.md +23 -0
- package/prompts/init.prompt.md +24 -0
- package/prompts/refactor-contract.md +26 -0
- package/prompts/refactor-phase-2-rebuild.md +25 -0
- package/prompts/refactor-phase-3-verify.md +24 -0
- package/prompts/refactor.prompt.md +26 -0
- package/resources/ai/AGENTS.md +18 -0
- package/resources/ai/adapters/codex.md +5 -0
- package/resources/ai/adapters/copilot.md +5 -0
- package/resources/ai/adapters/cursor.md +5 -0
- package/resources/ai/adapters/windsurf.md +5 -0
- package/resources/ai/contract.schema.json +68 -0
- package/resources/ai/rule-catalog.json +878 -0
- package/resources/ai/rule-catalog.schema.json +66 -0
- package/resources/ai/templates/adapters/codex.template.md +7 -0
- package/resources/ai/templates/adapters/copilot.template.md +7 -0
- package/resources/ai/templates/adapters/cursor.template.md +7 -0
- package/resources/ai/templates/adapters/windsurf.template.md +7 -0
- package/resources/ai/templates/agents.project.template.md +141 -0
- package/resources/ai/templates/examples/demo/src/billing/billing.service.ts +73 -0
- package/resources/ai/templates/examples/demo/src/config.ts +3 -0
- package/resources/ai/templates/examples/demo/src/invoice/invoice.errors.ts +51 -0
- package/resources/ai/templates/examples/demo/src/invoice/invoice.service.ts +96 -0
- package/resources/ai/templates/examples/demo/src/invoice/invoice.types.ts +9 -0
- package/resources/ai/templates/examples/rules/async-bad.ts +52 -0
- package/resources/ai/templates/examples/rules/async-good.ts +56 -0
- package/resources/ai/templates/examples/rules/class-first-bad.ts +36 -0
- package/resources/ai/templates/examples/rules/class-first-good.ts +74 -0
- package/resources/ai/templates/examples/rules/constructor-bad.ts +68 -0
- package/resources/ai/templates/examples/rules/constructor-good.ts +71 -0
- package/resources/ai/templates/examples/rules/control-flow-bad.ts +31 -0
- package/resources/ai/templates/examples/rules/control-flow-good.ts +54 -0
- package/resources/ai/templates/examples/rules/errors-bad.ts +42 -0
- package/resources/ai/templates/examples/rules/errors-good.ts +23 -0
- package/resources/ai/templates/examples/rules/functions-bad.ts +48 -0
- package/resources/ai/templates/examples/rules/functions-good.ts +58 -0
- package/resources/ai/templates/examples/rules/returns-bad.ts +38 -0
- package/resources/ai/templates/examples/rules/returns-good.ts +44 -0
- package/resources/ai/templates/examples/rules/testing-bad.ts +34 -0
- package/resources/ai/templates/examples/rules/testing-good.ts +54 -0
- package/resources/ai/templates/rules/architecture.md +41 -0
- package/resources/ai/templates/rules/async.md +13 -0
- package/resources/ai/templates/rules/class-first.md +45 -0
- package/resources/ai/templates/rules/control-flow.md +13 -0
- package/resources/ai/templates/rules/errors.md +18 -0
- package/resources/ai/templates/rules/functions.md +29 -0
- package/resources/ai/templates/rules/naming.md +13 -0
- package/resources/ai/templates/rules/readme.md +36 -0
- package/resources/ai/templates/rules/returns.md +13 -0
- package/resources/ai/templates/rules/testing.md +18 -0
- package/resources/ai/templates/rules.project.template.md +66 -0
- package/resources/ai/templates/skills/change-synchronization/SKILL.md +42 -0
- package/resources/ai/templates/skills/feature-shaping/SKILL.md +45 -0
- package/resources/ai/templates/skills/http-api-conventions/SKILL.md +171 -0
- package/resources/ai/templates/skills/init-workflow/SKILL.md +52 -0
- package/resources/ai/templates/skills/readme-authoring/SKILL.md +51 -0
- package/resources/ai/templates/skills/refactor-workflow/SKILL.md +50 -0
- package/resources/ai/templates/skills/simplicity-audit/SKILL.md +41 -0
- package/resources/ai/templates/skills/test-scope-selection/SKILL.md +50 -0
- package/resources/ai/templates/skills.index.template.md +25 -0
- package/standards/architecture.md +72 -0
- package/standards/changelog-policy.md +12 -0
- package/standards/manifest.json +36 -0
- package/standards/readme.md +56 -0
- package/standards/schema.json +124 -0
- package/standards/style.md +106 -0
- package/standards/testing.md +20 -0
- package/standards/tooling.md +38 -0
- package/templates/node-lib/.biomeignore +10 -0
- package/templates/node-lib/.vscode/extensions.json +1 -0
- package/templates/node-lib/.vscode/settings.json +9 -0
- package/templates/node-lib/README.md +172 -0
- package/templates/node-lib/biome.json +37 -0
- package/templates/node-lib/gitignore +6 -0
- package/templates/node-lib/package.json +32 -0
- package/templates/node-lib/scripts/release-publish.mjs +106 -0
- package/templates/node-lib/scripts/run-tests.mjs +65 -0
- package/templates/node-lib/src/config.ts +3 -0
- package/templates/node-lib/src/index.ts +2 -0
- package/templates/node-lib/src/logger.ts +7 -0
- package/templates/node-lib/src/package-info/package-info.service.ts +47 -0
- package/templates/node-lib/test/package-info.test.ts +10 -0
- package/templates/node-lib/tsconfig.build.json +1 -0
- package/templates/node-lib/tsconfig.json +5 -0
- package/templates/node-service/.biomeignore +10 -0
- package/templates/node-service/.vscode/extensions.json +1 -0
- package/templates/node-service/.vscode/settings.json +9 -0
- package/templates/node-service/README.md +244 -0
- package/templates/node-service/biome.json +37 -0
- package/templates/node-service/ecosystem.config.cjs +3 -0
- package/templates/node-service/gitignore +6 -0
- package/templates/node-service/package.json +42 -0
- package/templates/node-service/scripts/release-publish.mjs +106 -0
- package/templates/node-service/scripts/run-tests.mjs +65 -0
- package/templates/node-service/src/app/service-runtime.service.ts +57 -0
- package/templates/node-service/src/app-info/app-info.service.ts +47 -0
- package/templates/node-service/src/config.ts +11 -0
- package/templates/node-service/src/http/http-server.service.ts +66 -0
- package/templates/node-service/src/index.ts +2 -0
- package/templates/node-service/src/logger.ts +7 -0
- package/templates/node-service/src/main.ts +5 -0
- package/templates/node-service/test/service-runtime.test.ts +13 -0
- package/templates/node-service/tsconfig.build.json +1 -0
- package/templates/node-service/tsconfig.json +5 -0
- package/tsconfig/base.json +16 -0
- package/tsconfig/node-lib.json +5 -0
- package/tsconfig/node-service.json +1 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Agent Entry Point
|
|
2
|
+
|
|
3
|
+
This repository is AI-first. Always consume standards in this order:
|
|
4
|
+
|
|
5
|
+
1. `standards/manifest.json` (source of truth)
|
|
6
|
+
2. `standards/*.md` guides
|
|
7
|
+
3. `profiles/default.profile.json`
|
|
8
|
+
4. `resources/ai/templates/*` templates
|
|
9
|
+
5. `ai/constitution.md`
|
|
10
|
+
6. Assistant-specific adapter in `ai/adapters/`
|
|
11
|
+
|
|
12
|
+
## Mandatory Rules
|
|
13
|
+
|
|
14
|
+
- Follow `npm run check` before considering work complete.
|
|
15
|
+
- Follow `profiles/schema.json` when updating style profiles.
|
|
16
|
+
- Keep generated projects aligned with `@sha3/code` exports.
|
|
17
|
+
- Use `code-standards profile` to maintain the default AI style profile.
|
|
18
|
+
- Treat generated project-level `AGENTS.md` as blocking policy.
|
|
19
|
+
- Follow `standards/readme.md` when creating or updating README files.
|
|
20
|
+
- Require all generated content to be written in English, including code comments, README files, documentation, examples, and AI instruction files.
|
|
21
|
+
- Treat simplicity as a mandatory rule: no speculative abstractions, no gratuitous indirection, no extra files/layers/wrappers unless they solve a real current problem.
|
|
22
|
+
- Simplicity does not justify removing valid boundaries; keep distinct current responsibilities separated when they serve a real purpose.
|
|
23
|
+
- Let Biome decide the final line wrapping and formatting shape.
|
|
24
|
+
- Keep code compact when writing or refactoring, but do not fight Biome by forcing single-line objects, callbacks, or other constructs that the formatter intentionally keeps multiline.
|
|
25
|
+
|
|
26
|
+
## Section Ordering
|
|
27
|
+
|
|
28
|
+
For class-first files, `comment_section_blocks` is not illustrative. Its listed order is the required order for declared `@section` blocks.
|
|
29
|
+
|
|
30
|
+
Minimal order reference:
|
|
31
|
+
|
|
32
|
+
1. `imports:externals`
|
|
33
|
+
2. `imports:internals`
|
|
34
|
+
3. `consts`
|
|
35
|
+
4. `types`
|
|
36
|
+
5. `class`
|
|
37
|
+
6. `private:attributes`
|
|
38
|
+
7. `protected:attributes`
|
|
39
|
+
8. `public:properties`
|
|
40
|
+
9. `constructor`
|
|
41
|
+
10. `static:properties`
|
|
42
|
+
11. `factory`
|
|
43
|
+
12. `private:methods`
|
|
44
|
+
13. `protected:methods`
|
|
45
|
+
14. `public:methods`
|
|
46
|
+
15. `static:methods`
|
|
47
|
+
|
|
48
|
+
Minimal example:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
/**
|
|
52
|
+
* @section types
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
type UserServiceOptions = { isEnabled: boolean };
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @section class
|
|
59
|
+
*/
|
|
60
|
+
export class UserService {
|
|
61
|
+
/**
|
|
62
|
+
* @section constructor
|
|
63
|
+
*/
|
|
64
|
+
public constructor(private readonly options: UserServiceOptions) {}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @section public:methods
|
|
68
|
+
*/
|
|
69
|
+
public readStatus(): boolean {
|
|
70
|
+
return this.options.isEnabled;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`@section class` must be immediately followed by the exported class declaration. Do not place JSDoc, block comments, or line comments between them.
|
package/README.md
ADDED
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
# @sha3/code
|
|
2
|
+
|
|
3
|
+
Scaffold TypeScript projects, rebuild them with `refactor`, and enforce repository policy with `verify`.
|
|
4
|
+
|
|
5
|
+
## TL;DR
|
|
6
|
+
|
|
7
|
+
Create a new project:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @sha3/code init --template node-service --yes
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Realign an existing repo:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx @sha3/code refactor --yes
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Run verification for humans:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx @sha3/code verify
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run verification for automation:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx @sha3/code verify --report json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Explain a deterministic rule:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx @sha3/code verify --explain single-return
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Use it directly with `npx`:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx @sha3/code --help
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Or install it in a repo:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm install -D @sha3/code
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Compatibility
|
|
52
|
+
|
|
53
|
+
- Node.js 20.11+
|
|
54
|
+
- ESM package runtime
|
|
55
|
+
- TypeScript-first projects
|
|
56
|
+
- Biome as the baseline formatter and linter
|
|
57
|
+
|
|
58
|
+
## What It Does
|
|
59
|
+
|
|
60
|
+
`@sha3/code` manages 3 different concerns:
|
|
61
|
+
|
|
62
|
+
- `init`: creates a standards-managed TypeScript scaffold
|
|
63
|
+
- `refactor`: snapshots an existing repo and rebuilds it onto the managed scaffold
|
|
64
|
+
- `verify`: enforces repository policy that generic tooling does not cover well
|
|
65
|
+
|
|
66
|
+
That last part matters: `verify` is not another formatter or typechecker. It is the package-specific policy engine for generated repos.
|
|
67
|
+
Generated scaffolds are also expected to ship package-grade README files rather than placeholder docs.
|
|
68
|
+
|
|
69
|
+
## Non-Negotiables
|
|
70
|
+
|
|
71
|
+
Simplicity is mandatory.
|
|
72
|
+
|
|
73
|
+
- choose the simplest correct implementation for the current requirement
|
|
74
|
+
- avoid speculative abstractions, helper layers, wrappers, and extension points without immediate need
|
|
75
|
+
- if two solutions are both correct, prefer the smaller and more direct one
|
|
76
|
+
- do not remove valid responsibility boundaries in the name of simplicity
|
|
77
|
+
- simplicity means avoiding gratuitous complexity, not reducing structure blindly
|
|
78
|
+
- let Biome decide final wrapping; prefer compact code, but do not force single-line layouts that the formatter keeps multiline
|
|
79
|
+
|
|
80
|
+
## Public API
|
|
81
|
+
|
|
82
|
+
### CLI commands
|
|
83
|
+
|
|
84
|
+
```txt
|
|
85
|
+
code-standards init
|
|
86
|
+
code-standards refactor
|
|
87
|
+
code-standards profile
|
|
88
|
+
code-standards verify
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Package exports
|
|
92
|
+
|
|
93
|
+
```txt
|
|
94
|
+
@sha3/code/biome
|
|
95
|
+
@sha3/code/tsconfig/base.json
|
|
96
|
+
@sha3/code/tsconfig/node-lib.json
|
|
97
|
+
@sha3/code/tsconfig/node-service.json
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### `verify` options
|
|
101
|
+
|
|
102
|
+
```txt
|
|
103
|
+
code-standards verify [--report text|json] [--only <rule-id[,rule-id...]>] [--files <path[,path...]>] [--strict]
|
|
104
|
+
code-standards verify --explain <rule-id>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Behavior notes:
|
|
108
|
+
|
|
109
|
+
- `init` always works in the current directory and creates a fresh scaffold.
|
|
110
|
+
- `refactor` always works in the current directory and never accepts a remote or local source argument.
|
|
111
|
+
- `refactor` snapshots the previous repo state under `.code-standards/refactor-source/` before rebuilding managed files.
|
|
112
|
+
- `verify` is the project-policy checker. It complements Biome and TypeScript instead of replacing them.
|
|
113
|
+
- `verify --report json` is intended for CI, PR automation, and scripts.
|
|
114
|
+
- default `verify` fails only on `error` severity; `--strict` also fails on `warning`.
|
|
115
|
+
- `verify --explain <rule-id>` prints operational documentation for a rule without checking the repo.
|
|
116
|
+
- `code-standards verify --help` prints the same option surface shown above.
|
|
117
|
+
|
|
118
|
+
### What `verify` checks
|
|
119
|
+
|
|
120
|
+
`verify` covers project policy that is specific to `@sha3/code`, including:
|
|
121
|
+
|
|
122
|
+
- contract presence and validity for `AGENTS.md` and `ai/contract.json`
|
|
123
|
+
- metadata sync between `package.json.codeStandards` and `ai/contract.json`
|
|
124
|
+
- required managed files from the active template
|
|
125
|
+
- required README sections
|
|
126
|
+
- README documentation for public exports and public class methods
|
|
127
|
+
- HTTP API documentation for service templates
|
|
128
|
+
- TypeScript-only source policy in `src/` and `test/`
|
|
129
|
+
- deterministic AST rules such as `single-return`, `async-await-only`, `canonical-config-import`, and file naming rules
|
|
130
|
+
- `single-return` stays strict in `src/` except for `src/http/**`, where transport handlers may use early returns when that keeps request flow clearer
|
|
131
|
+
|
|
132
|
+
### What `verify` does not check
|
|
133
|
+
|
|
134
|
+
`verify` does not replace the generic toolchain:
|
|
135
|
+
|
|
136
|
+
- formatting, line wrapping, and generic lint rules stay in Biome
|
|
137
|
+
- type correctness stays in TypeScript
|
|
138
|
+
- runtime behavior stays in tests
|
|
139
|
+
|
|
140
|
+
### When to use `verify`
|
|
141
|
+
|
|
142
|
+
Use the tools together, not interchangeably:
|
|
143
|
+
|
|
144
|
+
- run Biome when you want style, formatting, and baseline lint feedback
|
|
145
|
+
- run TypeScript when you want type-safety feedback
|
|
146
|
+
- run `verify` when you want to enforce repository contract, scaffold integrity, and project-policy rules
|
|
147
|
+
|
|
148
|
+
## Integration Guide
|
|
149
|
+
|
|
150
|
+
### Create a new project
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
mkdir my-service
|
|
154
|
+
cd my-service
|
|
155
|
+
npx @sha3/code init --template node-service --yes
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### `init` step by step
|
|
159
|
+
|
|
160
|
+
Use `init` when you are starting a new repo from the managed scaffold.
|
|
161
|
+
|
|
162
|
+
1. Create and enter the target directory.
|
|
163
|
+
2. Run `init` with the template you want.
|
|
164
|
+
3. Review the generated contract files before asking an LLM to write code.
|
|
165
|
+
4. Fill `PROMPT.md` and give only that file to the LLM.
|
|
166
|
+
5. Make the LLM execute `npm run check` itself and fix any failures before it finishes.
|
|
167
|
+
|
|
168
|
+
Minimal flow:
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
mkdir my-service
|
|
172
|
+
cd my-service
|
|
173
|
+
npx @sha3/code init --template node-service --yes
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
What `init` generates for you:
|
|
177
|
+
|
|
178
|
+
- `AGENTS.md` as the repo policy entrypoint
|
|
179
|
+
- `SKILLS.md` as the index of specialized workflows that should only be loaded when relevant
|
|
180
|
+
- `ai/contract.json` as the deterministic standards contract
|
|
181
|
+
- `ai/rules.md` as the concise human-readable implementation rules file for the LLM
|
|
182
|
+
- `skills/*` workflow guides such as init, refactor, feature shaping, simplicity audit, change synchronization, test scope selection, HTTP API conventions, and README authoring
|
|
183
|
+
- `ai/<assistant>.md` adapter files when AI adapters are enabled
|
|
184
|
+
- `PROMPT.md` in the project root as the single user-authored request file and LLM entrypoint
|
|
185
|
+
- `prompts/init.prompt.md`, `prompts/init-phase-2-implement.md`, and `prompts/init-phase-3-verify.md` as internal workflow prompts the LLM should load by itself
|
|
186
|
+
- the managed `src/`, `test/`, config, and package surface for the selected template
|
|
187
|
+
- a README scaffold that is meant to be rewritten into package-grade integration documentation once real behavior exists
|
|
188
|
+
- a root `SCAFFOLD-FEEDBACK.md` handoff requirement in the generated workflow so the LLM leaves scaffold/process feedback after implementation
|
|
189
|
+
|
|
190
|
+
The CLI also prints the minimal next step after `init`, so the user does not have to infer the LLM workflow manually.
|
|
191
|
+
|
|
192
|
+
Recommended LLM workflow after `init`:
|
|
193
|
+
|
|
194
|
+
1. Open `PROMPT.md`.
|
|
195
|
+
2. Complete the final `User Request` section.
|
|
196
|
+
3. Paste only `PROMPT.md` into the LLM.
|
|
197
|
+
4. Let the LLM read `prompts/init.prompt.md`, `prompts/init-phase-2-implement.md`, and `prompts/init-phase-3-verify.md` by itself.
|
|
198
|
+
5. Let the LLM load optional skills only when the workflow actually triggers them.
|
|
199
|
+
|
|
200
|
+
Minimal request example for `PROMPT.md`:
|
|
201
|
+
|
|
202
|
+
```txt
|
|
203
|
+
Task:
|
|
204
|
+
- Build the first HTTP endpoint for service health.
|
|
205
|
+
- Keep the generated scaffold structure intact.
|
|
206
|
+
- Add tests for the new behavior.
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
The final phase must explicitly require the LLM to execute:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
npm run check
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
The 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`.
|
|
216
|
+
|
|
217
|
+
### Regenerate an existing repo
|
|
218
|
+
|
|
219
|
+
Run this from the project root:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npx @sha3/code refactor --yes
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
`refactor` will:
|
|
226
|
+
|
|
227
|
+
1. analyze the current repository
|
|
228
|
+
2. capture preservation decisions
|
|
229
|
+
3. write `.code-standards/refactor-source/latest/`
|
|
230
|
+
4. write `public-contract.json`, `preservation.json`, and `analysis-summary.md`
|
|
231
|
+
5. rebuild the managed scaffold
|
|
232
|
+
6. generate the LLM workflow pack, with `PROMPT.md` as the single user entrypoint
|
|
233
|
+
|
|
234
|
+
### `refactor` step by step
|
|
235
|
+
|
|
236
|
+
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.
|
|
237
|
+
|
|
238
|
+
1. Go to the root of the existing project.
|
|
239
|
+
2. Run `refactor`.
|
|
240
|
+
3. Answer the preservation questions if you are in interactive mode.
|
|
241
|
+
4. Let the command move the legacy code into `.code-standards/refactor-source/latest/` and rebuild the managed surface.
|
|
242
|
+
5. Open `PROMPT.md` and complete the request section.
|
|
243
|
+
6. Paste only `PROMPT.md` into the LLM and let it load the refactor artifacts and phase prompts itself.
|
|
244
|
+
7. Require the LLM to execute `npm run check` itself and fix any failures before it finishes.
|
|
245
|
+
8. Require the LLM to finish by creating or updating `SCAFFOLD-FEEDBACK.md` with concrete scaffold/process feedback.
|
|
246
|
+
|
|
247
|
+
Typical command:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
npx @sha3/code refactor --yes
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
If you want dependencies installed as part of the run:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
npx @sha3/code refactor --yes --install
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
After `refactor`, these files matter most:
|
|
260
|
+
|
|
261
|
+
- `PROMPT.md`
|
|
262
|
+
- `AGENTS.md`
|
|
263
|
+
- `SKILLS.md`
|
|
264
|
+
- `skills/feature-shaping/SKILL.md`
|
|
265
|
+
- `skills/simplicity-audit/SKILL.md`
|
|
266
|
+
- `skills/change-synchronization/SKILL.md`
|
|
267
|
+
- `skills/test-scope-selection/SKILL.md`
|
|
268
|
+
- `skills/http-api-conventions/SKILL.md`
|
|
269
|
+
- `ai/contract.json`
|
|
270
|
+
- `ai/rules.md`
|
|
271
|
+
- `skills/refactor-workflow/SKILL.md`
|
|
272
|
+
- `.code-standards/refactor-source/public-contract.json`
|
|
273
|
+
- `.code-standards/refactor-source/preservation.json`
|
|
274
|
+
- `.code-standards/refactor-source/analysis-summary.md`
|
|
275
|
+
- `.code-standards/refactor-source/latest/`
|
|
276
|
+
- `prompts/refactor.prompt.md`
|
|
277
|
+
- `prompts/refactor-phase-2-rebuild.md`
|
|
278
|
+
- `prompts/refactor-phase-3-verify.md`
|
|
279
|
+
|
|
280
|
+
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.
|
|
281
|
+
|
|
282
|
+
Important behavior note:
|
|
283
|
+
|
|
284
|
+
- `refactor` does not run `npm run fix` or `npm run check` against the intermediate refactor state.
|
|
285
|
+
- `refactor` does not run the final `npm run check` against the pre-refactor codebase.
|
|
286
|
+
- The old implementation is moved to `.code-standards/refactor-source/latest/` as reference material.
|
|
287
|
+
- The final validation belongs to the rewritten `src/` and `test/` produced after the LLM handoff.
|
|
288
|
+
|
|
289
|
+
Recommended LLM workflow after `refactor`:
|
|
290
|
+
|
|
291
|
+
1. Run `refactor` and wait for it to complete.
|
|
292
|
+
2. Open `PROMPT.md` and complete the `User Request` section.
|
|
293
|
+
3. Paste only `PROMPT.md` into the LLM.
|
|
294
|
+
4. Let the LLM read `prompts/refactor.prompt.md`, `prompts/refactor-phase-2-rebuild.md`, and `prompts/refactor-phase-3-verify.md` by itself.
|
|
295
|
+
5. Let the LLM rebuild, verify, and close the task end to end.
|
|
296
|
+
|
|
297
|
+
Minimal request example for `PROMPT.md`:
|
|
298
|
+
|
|
299
|
+
```txt
|
|
300
|
+
Task:
|
|
301
|
+
- Rebuild the application behavior inside the fresh scaffold under src/ and test/.
|
|
302
|
+
- Preserve the public API and HTTP contracts captured in the refactor artifacts.
|
|
303
|
+
- Do not edit managed files unless a standards update is explicitly required.
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
6. Make the final phase rewrite `README.md` as package-grade integration documentation for the rebuilt public API and runtime behavior when needed.
|
|
307
|
+
7. In the final phase, explicitly require the LLM to execute:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
npm run check
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
8. Require the LLM to fix any failing checks and rerun the command until it passes.
|
|
314
|
+
|
|
315
|
+
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.
|
|
316
|
+
|
|
317
|
+
### Verify a project
|
|
318
|
+
|
|
319
|
+
Human-readable verification:
|
|
320
|
+
|
|
321
|
+
```bash
|
|
322
|
+
npx @sha3/code verify
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Machine-readable verification:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
npx @sha3/code verify --report json
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Focused verification by rule:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
npx @sha3/code verify --only single-return,canonical-config-import
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Focused verification by files:
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
npx @sha3/code verify --files src/user/user.service.ts,test/user.test.ts
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Strict verification:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
npx @sha3/code verify --strict
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Combined scope control:
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
npx @sha3/code verify --report json --only single-return --files src/user/user.service.ts
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
Rule explanation:
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
npx @sha3/code verify --explain single-return
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
`verify` is the command generated projects use behind `npm run standards:check`.
|
|
362
|
+
|
|
363
|
+
## Configuration
|
|
364
|
+
|
|
365
|
+
Generated projects centralize runtime constants in `src/config.ts`.
|
|
366
|
+
|
|
367
|
+
This package centralizes standards through:
|
|
368
|
+
|
|
369
|
+
- [`standards/manifest.json`](/Users/jc/Documents/GitHub/code-standards/standards/manifest.json) as the canonical standards manifest
|
|
370
|
+
- [`profiles/default.profile.json`](/Users/jc/Documents/GitHub/code-standards/profiles/default.profile.json) as the default AI profile
|
|
371
|
+
- [`biome.json`](/Users/jc/Documents/GitHub/code-standards/biome.json) as the shared Biome config export
|
|
372
|
+
|
|
373
|
+
Profile-driven behavior can be customized with:
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
npx @sha3/code profile --profile ./profiles/team.profile.json
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Then applied during `init` or `refactor` with `--profile`.
|
|
380
|
+
|
|
381
|
+
## Scripts
|
|
382
|
+
|
|
383
|
+
Repository-level scripts:
|
|
384
|
+
|
|
385
|
+
- `npm run check`: standards validation, profile validation, AI resource validation, Biome lint, Biome format check, typecheck, tests
|
|
386
|
+
- `npm run fix`: Biome write + format write
|
|
387
|
+
- `npm run lint`: `biome check .`
|
|
388
|
+
- `npm run format:check`: `biome format .`
|
|
389
|
+
- `npm run typecheck`: TypeScript validation
|
|
390
|
+
- `npm run test`: smoke fixtures plus Node test runner
|
|
391
|
+
|
|
392
|
+
Generated project scripts:
|
|
393
|
+
|
|
394
|
+
- `npm run standards:check`: `code-standards verify`
|
|
395
|
+
- `npm run check`: standards + lint + format + typecheck + tests
|
|
396
|
+
- `npm run fix`: Biome autofix + format write
|
|
397
|
+
|
|
398
|
+
## Structure
|
|
399
|
+
|
|
400
|
+
Key repository paths:
|
|
401
|
+
|
|
402
|
+
- `bin/code-standards.mjs`: CLI entrypoint
|
|
403
|
+
- `lib/cli/run-init.mjs`: project initialization flow
|
|
404
|
+
- `lib/cli/run-refactor.mjs`: in-place refactor flow
|
|
405
|
+
- `lib/cli/run-verify.mjs`: deterministic verification flow
|
|
406
|
+
- `lib/verify/`: issue model, explain mode, renderers, project checks, and AST-level source rules
|
|
407
|
+
- `templates/`: `node-lib` and `node-service` managed scaffolds
|
|
408
|
+
- `prompts/`: starter prompts for `init` and `refactor`
|
|
409
|
+
- `resources/ai/`: AI contract templates, adapters, examples, and rule catalog
|
|
410
|
+
|
|
411
|
+
## Troubleshooting
|
|
412
|
+
|
|
413
|
+
### `biome: command not found`
|
|
414
|
+
|
|
415
|
+
Install dependencies in the current workspace:
|
|
416
|
+
|
|
417
|
+
```bash
|
|
418
|
+
npm install
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
### `refactor` says `package.json` was not found
|
|
422
|
+
|
|
423
|
+
Run `code-standards refactor` from the root of the target project.
|
|
424
|
+
|
|
425
|
+
### Verify Modes
|
|
426
|
+
|
|
427
|
+
`verify` has 5 useful modes:
|
|
428
|
+
|
|
429
|
+
- default text mode: human-readable errors to `stderr`
|
|
430
|
+
- `--report json`: structured output to `stdout`
|
|
431
|
+
- `--only`: execute only selected rule ids
|
|
432
|
+
- `--files`: limit file-oriented checks to a subset of files
|
|
433
|
+
- `--strict`: fail on warnings as well as errors
|
|
434
|
+
- `--explain`: print documentation for one rule instead of verifying the repo
|
|
435
|
+
|
|
436
|
+
Important behavior:
|
|
437
|
+
|
|
438
|
+
- project-wide contract checks still run even when `--files` is used
|
|
439
|
+
- file-oriented checks such as AST source rules and TypeScript-only checks are scoped by `--files`
|
|
440
|
+
- `--explain` cannot be combined with `--report`, `--only`, or `--files`
|
|
441
|
+
- `text` remains the default output mode to preserve human-friendly local usage
|
|
442
|
+
|
|
443
|
+
### Verify Output
|
|
444
|
+
|
|
445
|
+
Example text output:
|
|
446
|
+
|
|
447
|
+
```txt
|
|
448
|
+
- ERROR [single-return] src/user/user.service.ts: functions and methods outside src/http/ must use a single return statement
|
|
449
|
+
- WARNING [large-class-heuristic/heuristic] src/user/user.service.ts: very large classes should be decomposed into smaller cohesive units
|
|
450
|
+
Verification failed with 1 error(s) and 1 warning(s).
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Example JSON output:
|
|
454
|
+
|
|
455
|
+
```json
|
|
456
|
+
{
|
|
457
|
+
"ok": false,
|
|
458
|
+
"hasWarnings": true,
|
|
459
|
+
"issues": [
|
|
460
|
+
{
|
|
461
|
+
"ruleId": "single-return",
|
|
462
|
+
"category": "source-rule",
|
|
463
|
+
"severity": "error",
|
|
464
|
+
"message": "functions and methods outside src/http/ must use a single return statement",
|
|
465
|
+
"relativePath": "src/user/user.service.ts",
|
|
466
|
+
"enforcedBy": "verify"
|
|
467
|
+
}
|
|
468
|
+
],
|
|
469
|
+
"summary": {
|
|
470
|
+
"issueCount": 1,
|
|
471
|
+
"errorCount": 1,
|
|
472
|
+
"warningCount": 0,
|
|
473
|
+
"auditCount": 0,
|
|
474
|
+
"checkedRuleIds": ["single-return"],
|
|
475
|
+
"checkedFiles": ["src/user/user.service.ts"]
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
Exit code behavior:
|
|
481
|
+
|
|
482
|
+
- exit code `0`: verification passed at the requested severity threshold
|
|
483
|
+
- exit code non-zero: verification found blocking severities for the current mode or arguments were invalid
|
|
484
|
+
|
|
485
|
+
### Using verify in CI
|
|
486
|
+
|
|
487
|
+
Save a structured report:
|
|
488
|
+
|
|
489
|
+
```bash
|
|
490
|
+
npx @sha3/code verify --report json > verify-report.json
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
Fail a script based on the result:
|
|
494
|
+
|
|
495
|
+
```bash
|
|
496
|
+
node -e 'const fs=require("node:fs"); const report=JSON.parse(fs.readFileSync("verify-report.json","utf8")); if(!report.ok) process.exit(1)'
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
Run a targeted CI check for a narrow rule:
|
|
500
|
+
|
|
501
|
+
```bash
|
|
502
|
+
npx @sha3/code verify --report json --only single-return
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### Troubleshooting verify
|
|
506
|
+
|
|
507
|
+
If `verify` fails, first decide what kind of failure it is:
|
|
508
|
+
|
|
509
|
+
- contract/metadata/layout problem: check `AGENTS.md`, `ai/contract.json`, `package.json.codeStandards`, or missing scaffold files
|
|
510
|
+
- source-rule problem: use the reported `ruleId`, file path, and `verify --explain <rule-id>`
|
|
511
|
+
- README problem: restore the required sections
|
|
512
|
+
|
|
513
|
+
Common cases:
|
|
514
|
+
|
|
515
|
+
- unknown rule id in `--only`: use `code-standards verify --explain <rule-id>` or inspect `resources/ai/rule-catalog.json`
|
|
516
|
+
- too much output: narrow the run with `--only` or `--files`
|
|
517
|
+
- Biome and TypeScript pass but `verify` fails: expected, because `verify` checks product policy and contract rules that generic tooling does not cover, but line-wrapping disputes should now be treated as Biome territory
|
|
518
|
+
|
|
519
|
+
### Required README headings in generated projects
|
|
520
|
+
|
|
521
|
+
Keep these headings in generated projects, at minimum:
|
|
522
|
+
|
|
523
|
+
- for both templates: `## TL;DR`, `## Why`, `## Main Capabilities`, `## Installation`, `## Usage`, `## Examples`, `## Public API`, `## Configuration`, `## Compatibility`, `## Scripts`, `## Structure`, `## Troubleshooting`, `## AI Workflow`
|
|
524
|
+
- for `node-service` also: `## Running Locally` and `## HTTP API`
|
|
525
|
+
|
|
526
|
+
### VS Code formatting conflicts
|
|
527
|
+
|
|
528
|
+
Use the `biomejs.biome` extension as the default formatter for generated projects.
|
|
529
|
+
|
|
530
|
+
## AI Workflow
|
|
531
|
+
|
|
532
|
+
Generated projects treat these files as the local AI contract:
|
|
533
|
+
|
|
534
|
+
1. `ai/contract.json`
|
|
535
|
+
2. `AGENTS.md`
|
|
536
|
+
3. `SKILLS.md`
|
|
537
|
+
4. `skills/*`
|
|
538
|
+
5. `ai/rules.md`
|
|
539
|
+
6. `ai/<assistant>.md`
|
|
540
|
+
|
|
541
|
+
Recommended bootstrap prompt:
|
|
542
|
+
|
|
543
|
+
```txt
|
|
544
|
+
Before generating code:
|
|
545
|
+
- Read AGENTS.md, SKILLS.md, ai/contract.json, ai/rules.md, and ai/<assistant>.md.
|
|
546
|
+
- 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.
|
|
547
|
+
- 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.
|
|
548
|
+
- 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.
|
|
549
|
+
- Summarize the `error` rules and the `warning` rules you will review carefully.
|
|
550
|
+
- Implement the task without editing managed files unless this is a standards update.
|
|
551
|
+
- Run npm run check and fix all failures before finishing.
|
|
552
|
+
```
|
|
553
|
+
|
|
554
|
+
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.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Codex Adapter
|
|
2
|
+
|
|
3
|
+
- Read `AGENTS.md` first.
|
|
4
|
+
- Use `npm run check` as the final quality gate.
|
|
5
|
+
- Fix `error` rules first and treat `warning` rules as review signals, not blind rewrite orders.
|
|
6
|
+
- Prefer implementation over speculative planning when execution is requested.
|
|
7
|
+
- If `npm run check` reports TypeScript errors, fix code and rerun checks.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# GitHub Copilot Adapter
|
|
2
|
+
|
|
3
|
+
- Keep generated snippets aligned with `@sha3/code` tooling exports.
|
|
4
|
+
- Use ESM imports/exports by default.
|
|
5
|
+
- Include tests under `test/` for new behavior.
|
|
6
|
+
- Do not overcorrect warnings into more complex code when a simpler implementation already satisfies the contract.
|
|
7
|
+
- If TypeScript fails in `npm run check`, update code and rerun checks.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Cursor Adapter
|
|
2
|
+
|
|
3
|
+
- Load `standards/manifest.json` before generating code.
|
|
4
|
+
- Favor direct edits to existing files instead of broad rewrites.
|
|
5
|
+
- Respect Biome as the only authority for final code layout.
|
|
6
|
+
- Run `npm run check` locally after modifications.
|
|
7
|
+
- Fix TypeScript errors before considering work complete.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Windsurf Adapter
|
|
2
|
+
|
|
3
|
+
- Treat this repo as an AI policy package plus reusable tooling.
|
|
4
|
+
- Use `npx @sha3/code init` for new project bootstraps.
|
|
5
|
+
- Prefer local deterministic checks (`npm run check`) over remote assumptions.
|
|
6
|
+
- Treat Biome as the final authority for formatting and layout.
|
|
7
|
+
- Generate assistant files (`AGENTS.md`, `ai/*.md`) unless explicitly disabled.
|
|
8
|
+
- If TypeScript fails in `npm run check`, fix code and rerun checks.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# AI Constitution
|
|
2
|
+
|
|
3
|
+
These rules apply to all assistants using this repository.
|
|
4
|
+
|
|
5
|
+
- Treat `standards/manifest.json` as normative.
|
|
6
|
+
- Prefer deterministic and repeatable commands.
|
|
7
|
+
- Keep changes small, explicit, and testable.
|
|
8
|
+
- Let Biome decide the final line wrapping. Keep code compact, but do not fight formatter-preserved multiline layouts.
|
|
9
|
+
- Do not turn formatter preferences into verifier failures.
|
|
10
|
+
- Treat warnings as review signals, not mandatory rewrites, unless the user explicitly asks for a stricter pass.
|
|
11
|
+
- Run `npm run check` before finalizing edits.
|
|
12
|
+
- Use project templates for new projects unless explicitly overridden.
|