@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.
Files changed (165) hide show
  1. package/AGENTS.md +75 -0
  2. package/README.md +554 -0
  3. package/ai/adapters/codex.md +7 -0
  4. package/ai/adapters/copilot.md +7 -0
  5. package/ai/adapters/cursor.md +7 -0
  6. package/ai/adapters/windsurf.md +8 -0
  7. package/ai/constitution.md +12 -0
  8. package/bin/code-standards.mjs +47 -0
  9. package/biome.json +37 -0
  10. package/index.mjs +11 -0
  11. package/lib/cli/parse-args.mjs +416 -0
  12. package/lib/cli/post-run-guidance.mjs +43 -0
  13. package/lib/cli/run-init.mjs +123 -0
  14. package/lib/cli/run-profile.mjs +46 -0
  15. package/lib/cli/run-refactor.mjs +152 -0
  16. package/lib/cli/run-verify.mjs +67 -0
  17. package/lib/constants.mjs +167 -0
  18. package/lib/contract/load-rule-catalog.mjs +12 -0
  19. package/lib/contract/render-agents.mjs +79 -0
  20. package/lib/contract/render-contract-json.mjs +7 -0
  21. package/lib/contract/resolve-contract.mjs +52 -0
  22. package/lib/paths.mjs +50 -0
  23. package/lib/profile.mjs +108 -0
  24. package/lib/project/ai-instructions.mjs +28 -0
  25. package/lib/project/biome-ignore.mjs +14 -0
  26. package/lib/project/managed-files.mjs +105 -0
  27. package/lib/project/package-metadata.mjs +132 -0
  28. package/lib/project/prompt-files.mjs +111 -0
  29. package/lib/project/template-resolution.mjs +70 -0
  30. package/lib/refactor/materialize-refactor-context.mjs +106 -0
  31. package/lib/refactor/preservation-questions.mjs +33 -0
  32. package/lib/refactor/public-contract-extractor.mjs +22 -0
  33. package/lib/refactor/render-analysis-summary.mjs +50 -0
  34. package/lib/refactor/source-analysis.mjs +74 -0
  35. package/lib/utils/fs.mjs +220 -0
  36. package/lib/utils/prompts.mjs +63 -0
  37. package/lib/utils/text.mjs +43 -0
  38. package/lib/verify/change-audit-verifier.mjs +140 -0
  39. package/lib/verify/change-context.mjs +36 -0
  40. package/lib/verify/error-handling-verifier.mjs +164 -0
  41. package/lib/verify/explain-rule.mjs +54 -0
  42. package/lib/verify/issue-helpers.mjs +132 -0
  43. package/lib/verify/project-layout-verifier.mjs +259 -0
  44. package/lib/verify/project-verifier.mjs +267 -0
  45. package/lib/verify/readme-public-api.mjs +237 -0
  46. package/lib/verify/readme-verifier.mjs +216 -0
  47. package/lib/verify/render-json-report.mjs +3 -0
  48. package/lib/verify/render-text-report.mjs +34 -0
  49. package/lib/verify/source-analysis.mjs +126 -0
  50. package/lib/verify/source-rule-verifier.mjs +453 -0
  51. package/lib/verify/testing-verifier.mjs +113 -0
  52. package/lib/verify/tooling-verifier.mjs +82 -0
  53. package/lib/verify/typescript-style-verifier.mjs +407 -0
  54. package/package.json +55 -0
  55. package/profiles/default.profile.json +40 -0
  56. package/profiles/schema.json +96 -0
  57. package/prompts/init-contract.md +25 -0
  58. package/prompts/init-phase-2-implement.md +25 -0
  59. package/prompts/init-phase-3-verify.md +23 -0
  60. package/prompts/init.prompt.md +24 -0
  61. package/prompts/refactor-contract.md +26 -0
  62. package/prompts/refactor-phase-2-rebuild.md +25 -0
  63. package/prompts/refactor-phase-3-verify.md +24 -0
  64. package/prompts/refactor.prompt.md +26 -0
  65. package/resources/ai/AGENTS.md +18 -0
  66. package/resources/ai/adapters/codex.md +5 -0
  67. package/resources/ai/adapters/copilot.md +5 -0
  68. package/resources/ai/adapters/cursor.md +5 -0
  69. package/resources/ai/adapters/windsurf.md +5 -0
  70. package/resources/ai/contract.schema.json +68 -0
  71. package/resources/ai/rule-catalog.json +878 -0
  72. package/resources/ai/rule-catalog.schema.json +66 -0
  73. package/resources/ai/templates/adapters/codex.template.md +7 -0
  74. package/resources/ai/templates/adapters/copilot.template.md +7 -0
  75. package/resources/ai/templates/adapters/cursor.template.md +7 -0
  76. package/resources/ai/templates/adapters/windsurf.template.md +7 -0
  77. package/resources/ai/templates/agents.project.template.md +141 -0
  78. package/resources/ai/templates/examples/demo/src/billing/billing.service.ts +73 -0
  79. package/resources/ai/templates/examples/demo/src/config.ts +3 -0
  80. package/resources/ai/templates/examples/demo/src/invoice/invoice.errors.ts +51 -0
  81. package/resources/ai/templates/examples/demo/src/invoice/invoice.service.ts +96 -0
  82. package/resources/ai/templates/examples/demo/src/invoice/invoice.types.ts +9 -0
  83. package/resources/ai/templates/examples/rules/async-bad.ts +52 -0
  84. package/resources/ai/templates/examples/rules/async-good.ts +56 -0
  85. package/resources/ai/templates/examples/rules/class-first-bad.ts +36 -0
  86. package/resources/ai/templates/examples/rules/class-first-good.ts +74 -0
  87. package/resources/ai/templates/examples/rules/constructor-bad.ts +68 -0
  88. package/resources/ai/templates/examples/rules/constructor-good.ts +71 -0
  89. package/resources/ai/templates/examples/rules/control-flow-bad.ts +31 -0
  90. package/resources/ai/templates/examples/rules/control-flow-good.ts +54 -0
  91. package/resources/ai/templates/examples/rules/errors-bad.ts +42 -0
  92. package/resources/ai/templates/examples/rules/errors-good.ts +23 -0
  93. package/resources/ai/templates/examples/rules/functions-bad.ts +48 -0
  94. package/resources/ai/templates/examples/rules/functions-good.ts +58 -0
  95. package/resources/ai/templates/examples/rules/returns-bad.ts +38 -0
  96. package/resources/ai/templates/examples/rules/returns-good.ts +44 -0
  97. package/resources/ai/templates/examples/rules/testing-bad.ts +34 -0
  98. package/resources/ai/templates/examples/rules/testing-good.ts +54 -0
  99. package/resources/ai/templates/rules/architecture.md +41 -0
  100. package/resources/ai/templates/rules/async.md +13 -0
  101. package/resources/ai/templates/rules/class-first.md +45 -0
  102. package/resources/ai/templates/rules/control-flow.md +13 -0
  103. package/resources/ai/templates/rules/errors.md +18 -0
  104. package/resources/ai/templates/rules/functions.md +29 -0
  105. package/resources/ai/templates/rules/naming.md +13 -0
  106. package/resources/ai/templates/rules/readme.md +36 -0
  107. package/resources/ai/templates/rules/returns.md +13 -0
  108. package/resources/ai/templates/rules/testing.md +18 -0
  109. package/resources/ai/templates/rules.project.template.md +66 -0
  110. package/resources/ai/templates/skills/change-synchronization/SKILL.md +42 -0
  111. package/resources/ai/templates/skills/feature-shaping/SKILL.md +45 -0
  112. package/resources/ai/templates/skills/http-api-conventions/SKILL.md +171 -0
  113. package/resources/ai/templates/skills/init-workflow/SKILL.md +52 -0
  114. package/resources/ai/templates/skills/readme-authoring/SKILL.md +51 -0
  115. package/resources/ai/templates/skills/refactor-workflow/SKILL.md +50 -0
  116. package/resources/ai/templates/skills/simplicity-audit/SKILL.md +41 -0
  117. package/resources/ai/templates/skills/test-scope-selection/SKILL.md +50 -0
  118. package/resources/ai/templates/skills.index.template.md +25 -0
  119. package/standards/architecture.md +72 -0
  120. package/standards/changelog-policy.md +12 -0
  121. package/standards/manifest.json +36 -0
  122. package/standards/readme.md +56 -0
  123. package/standards/schema.json +124 -0
  124. package/standards/style.md +106 -0
  125. package/standards/testing.md +20 -0
  126. package/standards/tooling.md +38 -0
  127. package/templates/node-lib/.biomeignore +10 -0
  128. package/templates/node-lib/.vscode/extensions.json +1 -0
  129. package/templates/node-lib/.vscode/settings.json +9 -0
  130. package/templates/node-lib/README.md +172 -0
  131. package/templates/node-lib/biome.json +37 -0
  132. package/templates/node-lib/gitignore +6 -0
  133. package/templates/node-lib/package.json +32 -0
  134. package/templates/node-lib/scripts/release-publish.mjs +106 -0
  135. package/templates/node-lib/scripts/run-tests.mjs +65 -0
  136. package/templates/node-lib/src/config.ts +3 -0
  137. package/templates/node-lib/src/index.ts +2 -0
  138. package/templates/node-lib/src/logger.ts +7 -0
  139. package/templates/node-lib/src/package-info/package-info.service.ts +47 -0
  140. package/templates/node-lib/test/package-info.test.ts +10 -0
  141. package/templates/node-lib/tsconfig.build.json +1 -0
  142. package/templates/node-lib/tsconfig.json +5 -0
  143. package/templates/node-service/.biomeignore +10 -0
  144. package/templates/node-service/.vscode/extensions.json +1 -0
  145. package/templates/node-service/.vscode/settings.json +9 -0
  146. package/templates/node-service/README.md +244 -0
  147. package/templates/node-service/biome.json +37 -0
  148. package/templates/node-service/ecosystem.config.cjs +3 -0
  149. package/templates/node-service/gitignore +6 -0
  150. package/templates/node-service/package.json +42 -0
  151. package/templates/node-service/scripts/release-publish.mjs +106 -0
  152. package/templates/node-service/scripts/run-tests.mjs +65 -0
  153. package/templates/node-service/src/app/service-runtime.service.ts +57 -0
  154. package/templates/node-service/src/app-info/app-info.service.ts +47 -0
  155. package/templates/node-service/src/config.ts +11 -0
  156. package/templates/node-service/src/http/http-server.service.ts +66 -0
  157. package/templates/node-service/src/index.ts +2 -0
  158. package/templates/node-service/src/logger.ts +7 -0
  159. package/templates/node-service/src/main.ts +5 -0
  160. package/templates/node-service/test/service-runtime.test.ts +13 -0
  161. package/templates/node-service/tsconfig.build.json +1 -0
  162. package/templates/node-service/tsconfig.json +5 -0
  163. package/tsconfig/base.json +16 -0
  164. package/tsconfig/node-lib.json +5 -0
  165. package/tsconfig/node-service.json +1 -0
@@ -0,0 +1,24 @@
1
+ This is phase 1 of the init workflow. Plan first, then continue yourself into phase 2 unless you are blocked.
2
+
3
+ Read only the minimum context needed to produce an execution plan:
4
+
5
+ - `PROMPT.md`
6
+ - `AGENTS.md`
7
+ - `ai/contract.json`
8
+ - `ai/rules.md`
9
+ - `skills/init-workflow/SKILL.md`
10
+ - `skills/feature-shaping/SKILL.md`
11
+ - `skills/simplicity-audit/SKILL.md`
12
+ - `skills/change-synchronization/SKILL.md`
13
+ - the assistant-specific adapter in `ai/`, if present
14
+
15
+ Load optional skills only if the request in `PROMPT.md` triggers them:
16
+
17
+ - `skills/test-scope-selection/SKILL.md` for meaningful behavior changes
18
+ - `skills/readme-authoring/SKILL.md` when `README.md` must change
19
+ - `skills/http-api-conventions/SKILL.md` for `node-service` projects or HTTP endpoint work
20
+
21
+ Produce a compact internal implementation plan with the minimum files that need inspection next, note any assumptions that could change the design, and keep the read set small.
22
+
23
+ Do not edit files in this phase, do not run verification yet, and do not restate the full contract.
24
+ After planning, continue directly into `prompts/init-phase-2-implement.md` without waiting for the user unless a real blocker remains.
@@ -0,0 +1,26 @@
1
+ ## Refactor Contract
2
+
3
+ Use this contract during rebuild and verification phases, not as phase-1 analysis input unless the plan proves it is necessary.
4
+
5
+ This workflow is a refactor, not a migration-by-copy. You MUST load `skills/refactor-workflow/SKILL.md` and follow it as the primary procedural guide for execution order, prohibitions, and reporting.
6
+ You MUST also load `skills/feature-shaping/SKILL.md`, `skills/simplicity-audit/SKILL.md`, and `skills/change-synchronization/SKILL.md` as part of the default refactor workflow.
7
+
8
+ ## Requirements
9
+
10
+ - You MUST preserve only the contracts explicitly marked for preservation.
11
+ - You MUST use the snapshot under `.code-standards/refactor-source/latest/` as reference, not as a structure to copy blindly.
12
+ - You MUST treat the freshly regenerated managed files in the project root as authoritative.
13
+ - If the refactor changes meaningful behavior, you MUST load `skills/test-scope-selection/SKILL.md`.
14
+ - If the refactor rebuilds or documents HTTP transport behavior, you MUST load `skills/http-api-conventions/SKILL.md`.
15
+ - If the refactor rewrites `README.md`, you MUST load `skills/readme-authoring/SKILL.md`.
16
+ - You MUST execute `npm run check` yourself before finishing.
17
+ - If `npm run check` fails, you MUST fix the issues and rerun it until it passes.
18
+ - As the final step, you MUST create or update `SCAFFOLD-FEEDBACK.md` in the project root with concrete feedback about scaffold problems, unclear instructions, friction, missing patterns, and suggested improvements.
19
+
20
+ Finish with:
21
+
22
+ - changed files
23
+ - preserved contracts checklist
24
+ - intentionally broken or non-preserved items, if any
25
+ - proof that `npm run check` passed
26
+ - confirmation that `SCAFFOLD-FEEDBACK.md` was created or updated
@@ -0,0 +1,25 @@
1
+ This is phase 2 of the refactor workflow. Rebuild the domain code now.
2
+
3
+ Read only:
4
+
5
+ - `PROMPT.md`
6
+ - `prompts/refactor-contract.md`
7
+ - the plan you produced in phase 1
8
+ - the files you identified as necessary during phase 1
9
+
10
+ Load optional skills only if they are actually needed for the approved plan:
11
+
12
+ - `skills/test-scope-selection/SKILL.md` for meaningful behavior changes
13
+ - `skills/http-api-conventions/SKILL.md` when transport behavior is being preserved or rebuilt
14
+ - `skills/readme-authoring/SKILL.md` when `README.md` changes
15
+
16
+ Execution rules:
17
+
18
+ - Follow `prompts/refactor-contract.md` and `skills/refactor-workflow/SKILL.md`.
19
+ - Preserve only the explicit contracts and preservation decisions.
20
+ - Use `.code-standards/refactor-source/latest/` as reference material, not as a structure to copy.
21
+ - Keep the fresh scaffold authoritative and simplify where preservation does not require legacy complexity.
22
+ - Rewrite `README.md` only after behavior is stable.
23
+ - Do not stop at the end of this phase unless blocked.
24
+
25
+ At the end of this phase, summarize internally what was rebuilt, note any preserved contracts still at risk, and continue directly into `prompts/refactor-phase-3-verify.md`.
@@ -0,0 +1,24 @@
1
+ This is phase 3 of the refactor workflow. Verify and close the task.
2
+
3
+ Read only:
4
+
5
+ - `PROMPT.md`
6
+ - `prompts/refactor-contract.md`
7
+ - your phase 2 rebuild summary
8
+ - the files changed during the rebuild
9
+ - the latest command output that shows current verification status
10
+
11
+ Execution rules:
12
+
13
+ - Run the remaining required verification, including `npm run check`.
14
+ - If verification fails, fix the issues and rerun until it passes.
15
+ - Create or update `SCAFFOLD-FEEDBACK.md` as the final project artifact.
16
+ - Keep the final response concise and evidence-based.
17
+
18
+ Your final response must include:
19
+
20
+ 1. Changed files.
21
+ 2. The preserved contracts checklist.
22
+ 3. Intentionally non-preserved items, if any.
23
+ 4. Proof that `npm run check` passed.
24
+ 5. Confirmation that `SCAFFOLD-FEEDBACK.md` was created or updated.
@@ -0,0 +1,26 @@
1
+ This is phase 1 of the refactor workflow. Analyze first, then continue yourself into phase 2 unless you are blocked.
2
+
3
+ Read only the minimum context needed to plan the rewrite:
4
+
5
+ - `PROMPT.md`
6
+ - `AGENTS.md`
7
+ - `ai/contract.json`
8
+ - `ai/rules.md`
9
+ - `skills/refactor-workflow/SKILL.md`
10
+ - `skills/feature-shaping/SKILL.md`
11
+ - `skills/simplicity-audit/SKILL.md`
12
+ - `skills/change-synchronization/SKILL.md`
13
+ - `.code-standards/refactor-source/public-contract.json`
14
+ - `.code-standards/refactor-source/preservation.json`
15
+ - `.code-standards/refactor-source/analysis-summary.md`
16
+
17
+ Load optional skills only if the request in `PROMPT.md` triggers them:
18
+
19
+ - `skills/test-scope-selection/SKILL.md` for meaningful behavior changes
20
+ - `skills/http-api-conventions/SKILL.md` when transport behavior is being preserved or rebuilt
21
+ - `skills/readme-authoring/SKILL.md` when `README.md` must change
22
+
23
+ Produce an internal summary of the preserved contracts and rewrite risks, create a compact rebuild plan with the minimum legacy files worth opening next, and keep the read set small.
24
+
25
+ Do not edit files in this phase, do not run final verification yet, and do not restate the full contract.
26
+ After planning, continue directly into `prompts/refactor-phase-2-rebuild.md` without waiting for the user unless a real blocker remains.
@@ -0,0 +1,18 @@
1
+ # AI Template System Entry Point
2
+
3
+ This directory stores profile-aware templates used by `code-standards init`.
4
+
5
+ Template resolution order:
6
+
7
+ 1. `resources/ai/templates/agents.project.template.md`
8
+ 2. `resources/ai/templates/skills.index.template.md`
9
+ 3. `resources/ai/templates/skills/*/SKILL.md`
10
+ 4. `resources/ai/templates/rules/*.md`
11
+ 5. `resources/ai/templates/adapters/*.template.md`
12
+
13
+ Rendering rules:
14
+
15
+ - Render from validated profile data (`profiles/schema.json`).
16
+ - Use deterministic token replacement.
17
+ - Preserve stable section order in generated `AGENTS.md`.
18
+ - Keep assistant adapters aligned with the generated project contract.
@@ -0,0 +1,5 @@
1
+ # Codex Adapter
2
+
3
+ - Implement directly and keep changes minimal.
4
+ - Prefer deterministic commands and explicit validation.
5
+ - Use `npm run check` as the completion gate.
@@ -0,0 +1,5 @@
1
+ # Copilot Adapter
2
+
3
+ - Generate ESM-first TypeScript code.
4
+ - Prefer small composable functions.
5
+ - Add or update tests for behavioral changes.
@@ -0,0 +1,5 @@
1
+ # Cursor Adapter
2
+
3
+ - Use project-local configs as the primary source of style truth.
4
+ - Avoid introducing structure that does not match `src/` and `test/` layout.
5
+ - Validate with `npm run check`.
@@ -0,0 +1,5 @@
1
+ # Windsurf Adapter
2
+
3
+ - Keep edits aligned with @sha3/code exports.
4
+ - Run local enforcement scripts instead of relying on remote CI.
5
+ - Preserve assistant files (`AGENTS.md`, `ai/*.md`) unless explicitly removed by user.
@@ -0,0 +1,68 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://sha3.dev/code/contract.schema.json",
4
+ "title": "Generated AI Contract",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "required": ["formatVersion", "generatedByVersion", "project", "profile", "managedFiles", "rules"],
8
+ "properties": {
9
+ "formatVersion": { "type": "string", "const": "v2" },
10
+ "generatedByVersion": { "type": "string", "minLength": 1 },
11
+ "project": {
12
+ "type": "object",
13
+ "additionalProperties": false,
14
+ "required": ["name", "template", "withAiAdapters"],
15
+ "properties": {
16
+ "name": { "type": "string", "minLength": 1 },
17
+ "template": { "type": "string", "enum": ["node-lib", "node-service"] },
18
+ "withAiAdapters": { "type": "boolean" }
19
+ }
20
+ },
21
+ "profile": { "type": "object" },
22
+ "managedFiles": { "type": "array", "minItems": 2, "items": { "type": "string" } },
23
+ "rules": {
24
+ "type": "array",
25
+ "items": {
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": [
29
+ "id",
30
+ "title",
31
+ "summary",
32
+ "severity",
33
+ "kind",
34
+ "deterministic",
35
+ "verificationMode",
36
+ "verificationSource",
37
+ "implementedBy",
38
+ "requiresContext",
39
+ "confidence",
40
+ "appliesTo",
41
+ "enforcedBy",
42
+ "examples"
43
+ ],
44
+ "properties": {
45
+ "id": { "type": "string" },
46
+ "title": { "type": "string" },
47
+ "summary": { "type": "string" },
48
+ "severity": { "type": "string", "enum": ["error", "warning", "audit"] },
49
+ "kind": { "type": "string" },
50
+ "deterministic": { "type": "boolean" },
51
+ "verificationMode": { "type": "string", "enum": ["deterministic", "heuristic", "audit"] },
52
+ "verificationSource": { "type": "string", "enum": ["ast", "text", "filesystem", "package-json", "readme", "git-diff", "combined"] },
53
+ "implementedBy": { "type": "array", "items": { "type": "string" } },
54
+ "requiresContext": { "type": "string", "enum": ["none", "changed-files", "full-project"] },
55
+ "confidence": { "type": "string", "enum": ["high", "medium"] },
56
+ "appliesTo": { "type": "array", "items": { "type": "string" } },
57
+ "enforcedBy": { "type": "array", "items": { "type": "string" } },
58
+ "examples": {
59
+ "type": "object",
60
+ "additionalProperties": false,
61
+ "required": ["good", "bad"],
62
+ "properties": { "good": { "type": "array", "items": { "type": "string" } }, "bad": { "type": "array", "items": { "type": "string" } } }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ }
68
+ }