@sha3/code-standards 0.1.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 +19 -0
- package/README.md +368 -0
- package/ai/adapters/codex.md +5 -0
- package/ai/adapters/copilot.md +5 -0
- package/ai/adapters/cursor.md +5 -0
- package/ai/adapters/windsurf.md +6 -0
- package/ai/constitution.md +9 -0
- package/bin/code-standards.mjs +1010 -0
- package/eslint/base.mjs +36 -0
- package/eslint/node.mjs +14 -0
- package/eslint/test.mjs +19 -0
- package/index.mjs +19 -0
- package/package.json +64 -0
- package/prettier/index.cjs +10 -0
- package/profiles/default.profile.json +38 -0
- package/profiles/schema.json +159 -0
- package/resources/ai/AGENTS.md +16 -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/templates/adapters/codex.template.md +6 -0
- package/resources/ai/templates/adapters/copilot.template.md +6 -0
- package/resources/ai/templates/adapters/cursor.template.md +6 -0
- package/resources/ai/templates/adapters/windsurf.template.md +6 -0
- package/resources/ai/templates/agents.project.template.md +33 -0
- package/resources/ai/templates/rules/architecture.md +26 -0
- package/resources/ai/templates/rules/async.md +23 -0
- package/resources/ai/templates/rules/class-first.md +96 -0
- package/resources/ai/templates/rules/control-flow.md +19 -0
- package/resources/ai/templates/rules/errors.md +22 -0
- package/resources/ai/templates/rules/functions.md +27 -0
- package/resources/ai/templates/rules/readme.md +25 -0
- package/resources/ai/templates/rules/returns.md +33 -0
- package/resources/ai/templates/rules/testing.md +26 -0
- package/standards/architecture.md +24 -0
- package/standards/changelog-policy.md +12 -0
- package/standards/manifest.json +47 -0
- package/standards/readme.md +25 -0
- package/standards/schema.json +122 -0
- package/standards/style.md +48 -0
- package/standards/testing.md +18 -0
- package/standards/tooling.md +32 -0
- package/templates/node-lib/eslint.config.mjs +4 -0
- package/templates/node-lib/package.json +30 -0
- package/templates/node-lib/prettier.config.cjs +9 -0
- package/templates/node-lib/src/index.ts +3 -0
- package/templates/node-lib/test/smoke.test.ts +8 -0
- package/templates/node-lib/tsconfig.build.json +7 -0
- package/templates/node-lib/tsconfig.json +7 -0
- package/templates/node-service/eslint.config.mjs +4 -0
- package/templates/node-service/package.json +25 -0
- package/templates/node-service/prettier.config.cjs +9 -0
- package/templates/node-service/src/index.ts +17 -0
- package/templates/node-service/test/smoke.test.ts +37 -0
- package/templates/node-service/tsconfig.json +7 -0
- package/tsconfig/base.json +16 -0
- package/tsconfig/node-lib.json +12 -0
- package/tsconfig/node-service.json +10 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
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-standards` 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.
|
package/README.md
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @sha3/code-standards
|
|
4
|
+
|
|
5
|
+
**Scaffold TypeScript projects + enforce how AI writes code.**
|
|
6
|
+
|
|
7
|
+
[](./.nvmrc)
|
|
8
|
+
[](./package.json)
|
|
9
|
+
[](./standards/tooling.md)
|
|
10
|
+
[](./profiles/schema.json)
|
|
11
|
+
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## TL;DR
|
|
17
|
+
|
|
18
|
+
If you just want to start now:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx @sha3/code-standards init my-api --template node-service --yes
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then in your AI chat, paste this:
|
|
25
|
+
|
|
26
|
+
```txt
|
|
27
|
+
Before writing code:
|
|
28
|
+
1) Read AGENTS.md and ai/<assistant>.md in this repo.
|
|
29
|
+
2) List the blocking rules you will follow.
|
|
30
|
+
3) Implement the task following those rules.
|
|
31
|
+
4) Run npm run check and fix all issues.
|
|
32
|
+
5) Return changed files and which AGENTS rules were applied.
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`profile` is optional. Use it only when you want to customize AI behavior.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## What This Tool Actually Does
|
|
40
|
+
|
|
41
|
+
This package combines 3 things in one:
|
|
42
|
+
|
|
43
|
+
1. Project scaffolding (`init`) for `node-lib` and `node-service`.
|
|
44
|
+
2. Shared tooling exports (`eslint`, `prettier`, `tsconfig`).
|
|
45
|
+
3. AI behavior contract generation (`AGENTS.md` + `ai/*.md`) based on a style profile.
|
|
46
|
+
|
|
47
|
+
So it is not only formatting/linting. It also defines **how AI should think and generate code**.
|
|
48
|
+
|
|
49
|
+
Default generated contract includes structural class/file blocks such as:
|
|
50
|
+
|
|
51
|
+
- `imports:externals`
|
|
52
|
+
- `imports:internals`
|
|
53
|
+
- `consts`
|
|
54
|
+
- `types`
|
|
55
|
+
- `private:attributes`
|
|
56
|
+
- `private:properties`
|
|
57
|
+
- `public:properties`
|
|
58
|
+
- `constructor`
|
|
59
|
+
- `static:properties`
|
|
60
|
+
- `factory`
|
|
61
|
+
- `private:methods`
|
|
62
|
+
- `public:methods`
|
|
63
|
+
- `static:methods`
|
|
64
|
+
|
|
65
|
+
Section marker format is fixed to:
|
|
66
|
+
|
|
67
|
+
- `/** @section <block-name> */`
|
|
68
|
+
|
|
69
|
+
All blocks MUST exist even when empty (`// empty`).
|
|
70
|
+
|
|
71
|
+
Additional blocking defaults:
|
|
72
|
+
|
|
73
|
+
- `if`/`else`/loop statements MUST always use braces.
|
|
74
|
+
- README updates MUST follow a top-tier quality standard (see `standards/readme.md`).
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Do I Need `profile` First?
|
|
79
|
+
|
|
80
|
+
No.
|
|
81
|
+
|
|
82
|
+
- If you run `init` without profile flags, it uses the bundled default profile.
|
|
83
|
+
- If you want your custom coding preferences, create a profile and pass it to `init`.
|
|
84
|
+
|
|
85
|
+
Default flow (no profile setup):
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npx @sha3/code-standards init my-app --template node-service --yes
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Custom profile flow:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npx @sha3/code-standards profile --profile ./profiles/team.profile.json
|
|
95
|
+
npx @sha3/code-standards init my-app --template node-service --yes --profile ./profiles/team.profile.json
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## What Happens After `init`
|
|
101
|
+
|
|
102
|
+
After `init`, your new repo contains:
|
|
103
|
+
|
|
104
|
+
- `AGENTS.md` (blocking rules for AI)
|
|
105
|
+
- `ai/codex.md`, `ai/cursor.md`, `ai/copilot.md`, `ai/windsurf.md`
|
|
106
|
+
- lint/format/typecheck/test-ready project template
|
|
107
|
+
|
|
108
|
+
That means the next step is **not** configuring tools. The next step is telling your assistant to obey `AGENTS.md` before coding.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## How To Use With AI (Copy/Paste)
|
|
113
|
+
|
|
114
|
+
## Universal bootstrap prompt
|
|
115
|
+
|
|
116
|
+
Use this as your first message in any coding session:
|
|
117
|
+
|
|
118
|
+
```txt
|
|
119
|
+
Before generating code:
|
|
120
|
+
- Read AGENTS.md and ai/<assistant>.md.
|
|
121
|
+
- Summarize the blocking rules you must follow.
|
|
122
|
+
- Implement the task with those rules.
|
|
123
|
+
- Run npm run check and fix issues until it passes.
|
|
124
|
+
- Return changed files + a short compliance checklist.
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Task prompt template
|
|
128
|
+
|
|
129
|
+
```txt
|
|
130
|
+
Task: <describe task>
|
|
131
|
+
Constraints:
|
|
132
|
+
- Follow AGENTS.md and ai/<assistant>.md strictly.
|
|
133
|
+
- Keep architecture and naming conventions intact.
|
|
134
|
+
- Add/update tests for behavior changes.
|
|
135
|
+
- Run npm run check at the end.
|
|
136
|
+
Output:
|
|
137
|
+
- What changed
|
|
138
|
+
- Why
|
|
139
|
+
- Proof checks passed
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Replace `<assistant>` with:
|
|
143
|
+
|
|
144
|
+
- `codex`
|
|
145
|
+
- `cursor`
|
|
146
|
+
- `copilot`
|
|
147
|
+
- `windsurf`
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Assistant-Specific Start Commands
|
|
152
|
+
|
|
153
|
+
Use these prompts depending on tool:
|
|
154
|
+
|
|
155
|
+
### Codex
|
|
156
|
+
|
|
157
|
+
```txt
|
|
158
|
+
Read AGENTS.md and ai/codex.md first. Do not start implementation until you summarize blocking rules.
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Cursor
|
|
162
|
+
|
|
163
|
+
```txt
|
|
164
|
+
Read AGENTS.md and ai/cursor.md. Enforce rules while implementing and keep edits compliant.
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### GitHub Copilot Chat
|
|
168
|
+
|
|
169
|
+
```txt
|
|
170
|
+
Use AGENTS.md and ai/copilot.md as mandatory coding rules for this task.
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Windsurf
|
|
174
|
+
|
|
175
|
+
```txt
|
|
176
|
+
Read AGENTS.md and ai/windsurf.md and treat them as non-negotiable constraints.
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Quick Start (Step by Step)
|
|
182
|
+
|
|
183
|
+
### 1) Create profile (optional)
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
npx @sha3/code-standards profile
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Non-interactive:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
npx @sha3/code-standards profile \
|
|
193
|
+
--non-interactive \
|
|
194
|
+
--profile ./profiles/team.profile.json \
|
|
195
|
+
--force-profile
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 2) Scaffold project
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npx @sha3/code-standards init my-api --template node-service --yes
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
With explicit profile:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
npx @sha3/code-standards init my-lib \
|
|
208
|
+
--template node-lib \
|
|
209
|
+
--yes \
|
|
210
|
+
--no-install \
|
|
211
|
+
--profile ./profiles/team.profile.json
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Skip AI files when needed:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
npx @sha3/code-standards init my-lib --template node-lib --yes --no-ai-adapters
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 3) Work loop inside generated project
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
npm install
|
|
224
|
+
npm run check
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Then use the prompts above in your AI tool.
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## CLI Reference
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
code-standards <command> [options]
|
|
235
|
+
|
|
236
|
+
Commands:
|
|
237
|
+
init [project-name] Initialize a project from templates
|
|
238
|
+
profile Create or update the AI style profile
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### `init` options
|
|
242
|
+
|
|
243
|
+
- `--template <node-lib|node-service>`
|
|
244
|
+
- `--yes`
|
|
245
|
+
- `--target <dir>`
|
|
246
|
+
- `--no-install`
|
|
247
|
+
- `--force`
|
|
248
|
+
- `--with-ai-adapters`
|
|
249
|
+
- `--no-ai-adapters`
|
|
250
|
+
- `--profile <path>`
|
|
251
|
+
|
|
252
|
+
### `profile` options
|
|
253
|
+
|
|
254
|
+
- `--profile <path>`
|
|
255
|
+
- `--non-interactive`
|
|
256
|
+
- `--force-profile`
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Package Exports
|
|
261
|
+
|
|
262
|
+
### ESLint
|
|
263
|
+
|
|
264
|
+
```js
|
|
265
|
+
// eslint.config.mjs
|
|
266
|
+
import nodeConfig from "@sha3/code-standards/eslint/node";
|
|
267
|
+
import testConfig from "@sha3/code-standards/eslint/test";
|
|
268
|
+
|
|
269
|
+
export default [...nodeConfig, ...testConfig];
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Prettier
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
// prettier.config.cjs
|
|
276
|
+
module.exports = require("@sha3/code-standards/prettier");
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### TSConfig
|
|
280
|
+
|
|
281
|
+
```json
|
|
282
|
+
{
|
|
283
|
+
"extends": "@sha3/code-standards/tsconfig/node-lib.json"
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Local Quality Gates
|
|
290
|
+
|
|
291
|
+
Main gate:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
npm run check
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Includes:
|
|
298
|
+
|
|
299
|
+
- standards schema validation
|
|
300
|
+
- profile schema validation
|
|
301
|
+
- lint
|
|
302
|
+
- format check
|
|
303
|
+
- typecheck
|
|
304
|
+
- smoke tests + CLI tests
|
|
305
|
+
|
|
306
|
+
Other scripts:
|
|
307
|
+
|
|
308
|
+
- `npm run fix`
|
|
309
|
+
- `npm run standards:validate`
|
|
310
|
+
- `npm run profile:validate`
|
|
311
|
+
- `npm run release:check`
|
|
312
|
+
- `npm run release:publish -- --dry-run`
|
|
313
|
+
- `npm run release:publish`
|
|
314
|
+
- `npm run hooks:install`
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## FAQ
|
|
319
|
+
|
|
320
|
+
### “I ran `init`. How do I force AI to follow rules?”
|
|
321
|
+
|
|
322
|
+
Always start with a bootstrap prompt that says:
|
|
323
|
+
|
|
324
|
+
1. read `AGENTS.md` and `ai/<assistant>.md`
|
|
325
|
+
2. summarize blocking rules
|
|
326
|
+
3. implement
|
|
327
|
+
4. run `npm run check`
|
|
328
|
+
|
|
329
|
+
### “AI ignored my standards.”
|
|
330
|
+
|
|
331
|
+
Use stricter prompt wording:
|
|
332
|
+
|
|
333
|
+
```txt
|
|
334
|
+
Treat AGENTS.md as hard constraints. If any rule conflicts with your default behavior, AGENTS.md wins.
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### “Do I need to repeat the rules every task?”
|
|
338
|
+
|
|
339
|
+
Yes, practically you should restate that AGENTS is mandatory at each task boundary. Keep the prompt short and consistent.
|
|
340
|
+
|
|
341
|
+
### “Can I use this without AI files?”
|
|
342
|
+
|
|
343
|
+
Yes, with `--no-ai-adapters`. You still get scaffold + tooling exports.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Repository Layout
|
|
348
|
+
|
|
349
|
+
```text
|
|
350
|
+
.
|
|
351
|
+
├── bin/ # CLI entrypoint
|
|
352
|
+
├── profiles/ # AI style profile schema + defaults
|
|
353
|
+
├── resources/ai/ # templates for generated AGENTS/adapters
|
|
354
|
+
├── standards/ # canonical standards docs + manifest/schema
|
|
355
|
+
├── templates/ # project scaffolds (node-lib, node-service)
|
|
356
|
+
├── eslint/ # exported eslint configs
|
|
357
|
+
├── prettier/ # exported prettier config
|
|
358
|
+
└── tsconfig/ # exported tsconfig presets
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## Publishing
|
|
364
|
+
|
|
365
|
+
```bash
|
|
366
|
+
npm run release:check
|
|
367
|
+
npm run release:publish
|
|
368
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Windsurf Adapter
|
|
2
|
+
|
|
3
|
+
- Treat this repo as an AI policy package plus reusable tooling.
|
|
4
|
+
- Use `npx @sha3/code-standards init` for new project bootstraps.
|
|
5
|
+
- Prefer local deterministic checks (`npm run check`) over remote assumptions.
|
|
6
|
+
- Generate assistant files (`AGENTS.md`, `ai/*.md`) unless explicitly disabled.
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
- Run `npm run check` before finalizing edits.
|
|
9
|
+
- Use project templates for new projects unless explicitly overridden.
|