invar-tools 1.7.1__py3-none-any.whl → 1.10.0__py3-none-any.whl

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 (113) hide show
  1. invar/__init__.py +8 -0
  2. invar/core/language.py +88 -0
  3. invar/core/models.py +106 -0
  4. invar/core/patterns/detector.py +6 -1
  5. invar/core/patterns/p0_exhaustive.py +15 -3
  6. invar/core/patterns/p0_literal.py +15 -3
  7. invar/core/patterns/p0_newtype.py +15 -3
  8. invar/core/patterns/p0_nonempty.py +15 -3
  9. invar/core/patterns/p0_validation.py +15 -3
  10. invar/core/patterns/registry.py +5 -1
  11. invar/core/patterns/types.py +5 -1
  12. invar/core/property_gen.py +4 -0
  13. invar/core/rules.py +84 -18
  14. invar/core/sync_helpers.py +27 -1
  15. invar/core/template_helpers.py +32 -0
  16. invar/core/ts_parsers.py +286 -0
  17. invar/core/ts_sig_parser.py +307 -0
  18. invar/node_tools/MANIFEST +7 -0
  19. invar/node_tools/__init__.py +51 -0
  20. invar/node_tools/fc-runner/cli.js +77 -0
  21. invar/node_tools/quick-check/cli.js +28 -0
  22. invar/node_tools/ts-analyzer/cli.js +480 -0
  23. invar/shell/claude_hooks.py +35 -12
  24. invar/shell/commands/guard.py +36 -1
  25. invar/shell/commands/init.py +133 -7
  26. invar/shell/commands/perception.py +157 -33
  27. invar/shell/commands/skill.py +187 -0
  28. invar/shell/commands/template_sync.py +65 -13
  29. invar/shell/commands/uninstall.py +77 -12
  30. invar/shell/commands/update.py +6 -14
  31. invar/shell/contract_coverage.py +1 -0
  32. invar/shell/fs.py +66 -13
  33. invar/shell/pi_hooks.py +213 -0
  34. invar/shell/prove/guard_ts.py +899 -0
  35. invar/shell/skill_manager.py +353 -0
  36. invar/shell/template_engine.py +28 -4
  37. invar/shell/templates.py +4 -4
  38. invar/templates/claude-md/python/critical-rules.md +33 -0
  39. invar/templates/claude-md/python/quick-reference.md +24 -0
  40. invar/templates/claude-md/typescript/critical-rules.md +40 -0
  41. invar/templates/claude-md/typescript/quick-reference.md +24 -0
  42. invar/templates/claude-md/universal/check-in.md +25 -0
  43. invar/templates/claude-md/universal/skills.md +73 -0
  44. invar/templates/claude-md/universal/workflow.md +55 -0
  45. invar/templates/commands/{audit.md → audit.md.jinja} +18 -1
  46. invar/templates/config/AGENT.md.jinja +256 -0
  47. invar/templates/config/CLAUDE.md.jinja +16 -209
  48. invar/templates/config/context.md.jinja +19 -0
  49. invar/templates/examples/{README.md → python/README.md} +2 -0
  50. invar/templates/examples/{conftest.py → python/conftest.py} +1 -1
  51. invar/templates/examples/{contracts.py → python/contracts.py} +81 -4
  52. invar/templates/examples/python/core_shell.py +227 -0
  53. invar/templates/examples/python/functional.py +613 -0
  54. invar/templates/examples/typescript/README.md +31 -0
  55. invar/templates/examples/typescript/contracts.ts +163 -0
  56. invar/templates/examples/typescript/core_shell.ts +374 -0
  57. invar/templates/examples/typescript/functional.ts +601 -0
  58. invar/templates/examples/typescript/workflow.md +95 -0
  59. invar/templates/hooks/PostToolUse.sh.jinja +10 -1
  60. invar/templates/hooks/PreToolUse.sh.jinja +38 -0
  61. invar/templates/hooks/Stop.sh.jinja +1 -1
  62. invar/templates/hooks/UserPromptSubmit.sh.jinja +7 -0
  63. invar/templates/hooks/pi/invar.ts.jinja +82 -0
  64. invar/templates/manifest.toml +8 -6
  65. invar/templates/onboard/assessment.md.jinja +214 -0
  66. invar/templates/onboard/patterns/python.md +347 -0
  67. invar/templates/onboard/patterns/typescript.md +452 -0
  68. invar/templates/onboard/roadmap.md.jinja +168 -0
  69. invar/templates/protocol/INVAR.md.jinja +51 -0
  70. invar/templates/protocol/python/architecture-examples.md +41 -0
  71. invar/templates/protocol/python/contracts-syntax.md +56 -0
  72. invar/templates/protocol/python/markers.md +44 -0
  73. invar/templates/protocol/python/tools.md +24 -0
  74. invar/templates/protocol/python/troubleshooting.md +38 -0
  75. invar/templates/protocol/typescript/architecture-examples.md +52 -0
  76. invar/templates/protocol/typescript/contracts-syntax.md +73 -0
  77. invar/templates/protocol/typescript/markers.md +48 -0
  78. invar/templates/protocol/typescript/tools.md +65 -0
  79. invar/templates/protocol/typescript/troubleshooting.md +104 -0
  80. invar/templates/protocol/universal/architecture.md +36 -0
  81. invar/templates/protocol/universal/completion.md +14 -0
  82. invar/templates/protocol/universal/contracts-concept.md +37 -0
  83. invar/templates/protocol/universal/header.md +17 -0
  84. invar/templates/protocol/universal/session.md +17 -0
  85. invar/templates/protocol/universal/six-laws.md +10 -0
  86. invar/templates/protocol/universal/usbv.md +14 -0
  87. invar/templates/protocol/universal/visible-workflow.md +25 -0
  88. invar/templates/skills/develop/SKILL.md.jinja +98 -3
  89. invar/templates/skills/extensions/_registry.yaml +93 -0
  90. invar/templates/skills/extensions/acceptance/SKILL.md +383 -0
  91. invar/templates/skills/extensions/invar-onboard/SKILL.md +448 -0
  92. invar/templates/skills/extensions/invar-onboard/patterns/python.md +347 -0
  93. invar/templates/skills/extensions/invar-onboard/patterns/typescript.md +452 -0
  94. invar/templates/skills/extensions/invar-onboard/templates/assessment.md.jinja +214 -0
  95. invar/templates/skills/extensions/invar-onboard/templates/roadmap.md.jinja +168 -0
  96. invar/templates/skills/extensions/security/SKILL.md +382 -0
  97. invar/templates/skills/extensions/security/patterns/_common.yaml +126 -0
  98. invar/templates/skills/extensions/security/patterns/python.yaml +155 -0
  99. invar/templates/skills/extensions/security/patterns/typescript.yaml +194 -0
  100. invar/templates/skills/investigate/SKILL.md.jinja +15 -0
  101. invar/templates/skills/propose/SKILL.md.jinja +33 -0
  102. invar/templates/skills/review/SKILL.md.jinja +346 -71
  103. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/METADATA +326 -19
  104. invar_tools-1.10.0.dist-info/RECORD +173 -0
  105. invar/templates/examples/core_shell.py +0 -127
  106. invar/templates/protocol/INVAR.md +0 -310
  107. invar_tools-1.7.1.dist-info/RECORD +0 -112
  108. /invar/templates/examples/{workflow.md → python/workflow.md} +0 -0
  109. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/WHEEL +0 -0
  110. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/entry_points.txt +0 -0
  111. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/LICENSE +0 -0
  112. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/LICENSE-GPL +0 -0
  113. {invar_tools-1.7.1.dist-info → invar_tools-1.10.0.dist-info}/licenses/NOTICE +0 -0
@@ -0,0 +1,55 @@
1
+ ## Documentation Structure
2
+
3
+ | File | Owner | Edit? | Purpose |
4
+ |------|-------|-------|---------|
5
+ | INVAR.md | Invar | No | Protocol (`invar update` to sync) |
6
+ | CLAUDE.md | User | Yes | Project customization (this file) |
7
+ | .invar/context.md | User | Yes | Project state, lessons learned |
8
+ | .invar/project-additions.md | User | Yes | Project rules → injected into CLAUDE.md |
9
+ | .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns, workflow |
10
+
11
+ > **Before writing code:** Check Task Router in `.invar/context.md`
12
+
13
+ ## Visible Workflow (DX-30)
14
+
15
+ For complex tasks (3+ functions), show 3 checkpoints in TodoList:
16
+
17
+ ```
18
+ □ [UNDERSTAND] Task description, codebase context, constraints
19
+ □ [SPECIFY] Contracts and design decomposition
20
+ □ [VALIDATE] Guard results, Review Gate status, integration status
21
+ ```
22
+
23
+ **BUILD is internal work** — not shown in TodoList.
24
+
25
+ **Show contracts before code.** See `.invar/examples/workflow.md` for full example.
26
+
27
+ ## Phase Visibility (DX-51)
28
+
29
+ Each USBV phase transition requires a visible header:
30
+
31
+ ```
32
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
33
+ 📍 /develop → SPECIFY (2/4)
34
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
35
+ ```
36
+
37
+ **Three-layer visibility:**
38
+ - **Skill** (`/develop`) — Routing announcement
39
+ - **Phase** (`SPECIFY 2/4`) — Phase header (this section)
40
+ - **Tasks** — TodoWrite items
41
+
42
+ Phase headers are SEPARATE from TodoWrite. Phase = where you are; TodoWrite = what to do.
43
+
44
+ ---
45
+
46
+ ## Context Management (DX-54)
47
+
48
+ Re-read `.invar/context.md` when:
49
+ 1. Entering any workflow (/develop, /review, etc.)
50
+ 2. Completing a TodoWrite task (before moving to next)
51
+ 3. Conversation exceeds ~15-20 exchanges
52
+ 4. Unsure about project rules or patterns
53
+
54
+ **Refresh is transparent** — do not announce "I'm refreshing context."
55
+ Only show routing announcements when entering workflows.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  _invar:
3
- version: "5.0"
3
+ version: "{{ version }}"
4
4
  type: command
5
5
  ---
6
6
 
@@ -51,12 +51,21 @@ You ARE here to:
51
51
  > **Principle:** Only items requiring semantic judgment. Mechanical checks are excluded (see bottom).
52
52
 
53
53
  ### A. Contract Semantic Value
54
+ {% if language == "python" %}
54
55
  - [ ] Does @pre constrain inputs beyond type checking?
55
56
  - Bad: `@pre(lambda x: isinstance(x, int))`
56
57
  - Good: `@pre(lambda x: x > 0 and x < MAX_VALUE)`
57
58
  - [ ] Does @post verify meaningful output properties?
58
59
  - Bad: `@post(lambda result: result is not None)`
59
60
  - Good: `@post(lambda result: len(result) == len(input))`
61
+ {% elif language == "typescript" %}
62
+ - [ ] Does Zod schema constrain inputs beyond type checking?
63
+ - Bad: `z.number()` (type only)
64
+ - Good: `z.number().positive().max(MAX_VALUE)` (semantic constraints)
65
+ - [ ] Does output schema verify meaningful properties?
66
+ - Bad: `z.string()` (type only)
67
+ - Good: `z.string().min(1).max(100)` (semantic constraints)
68
+ {% endif %}
60
69
  - [ ] Could someone implement correctly from contracts alone?
61
70
  - [ ] Are boundary conditions explicit in contracts?
62
71
 
@@ -100,7 +109,11 @@ You ARE here to:
100
109
 
101
110
  These are checked by Guard or linters - don't duplicate:
102
111
  - Core/Shell separation → Guard (forbidden_import, impure_call)
112
+ {% if language == "python" -%}
103
113
  - Shell returns Result[T,E] → Guard (shell_result)
114
+ {% elif language == "typescript" -%}
115
+ - Shell returns Result<T,E> → Guard (shell_result)
116
+ {% endif -%}
104
117
  - Missing contracts → Guard (missing_contract)
105
118
  - File/function size limits → Guard (file_size, function_size)
106
119
  - Entry point thickness → Guard (entry_point_too_thick)
@@ -121,7 +134,11 @@ For each issue found, use severity levels:
121
134
  ```markdown
122
135
  ### [CRITICAL/MAJOR/MINOR] Issue Title
123
136
 
137
+ {% if language == "python" -%}
124
138
  **Location:** file.py:line_number
139
+ {% elif language == "typescript" -%}
140
+ **Location:** file.ts:line_number
141
+ {% endif -%}
125
142
  **Category:** contract_quality | logic_error | security | escape_hatch | code_smell
126
143
  **Problem:** What's wrong
127
144
  **Suggestion:** How to fix (but don't implement)
@@ -0,0 +1,256 @@
1
+ <!--invar:critical-->
2
+ ## ⚡ Critical Rules
3
+
4
+ | Always | Remember |
5
+ |--------|----------|
6
+ {% if syntax == "mcp" -%}
7
+ | **Verify** | `invar_guard` — NOT pytest, NOT crosshair |
8
+ {% else -%}
9
+ | **Verify** | `invar guard` — NOT pytest, NOT crosshair |
10
+ {% endif -%}
11
+ {% if language == "python" -%}
12
+ | **Core** | `@pre/@post` + doctests, NO I/O imports |
13
+ | **Shell** | Returns `Result[T, E]` from `returns` library |
14
+ {% elif language == "typescript" -%}
15
+ | **Core** | Zod schemas + JSDoc examples, NO I/O imports |
16
+ | **Shell** | Returns `Result<T, E>` from `neverthrow` library |
17
+ {% endif -%}
18
+ | **Flow** | USBV: Understand → Specify → Build → Validate |
19
+
20
+ ### Contract Rules (CRITICAL)
21
+
22
+ {% if language == "python" -%}
23
+ ```python
24
+ # ❌ WRONG: Lambda must include ALL parameters
25
+ @pre(lambda x: x >= 0)
26
+ def calc(x: int, y: int = 0): ...
27
+
28
+ # ✅ CORRECT: Include defaults too
29
+ @pre(lambda x, y=0: x >= 0)
30
+ def calc(x: int, y: int = 0): ...
31
+
32
+ # ❌ WRONG: @post cannot access parameters
33
+ @post(lambda result: result > x) # 'x' not available!
34
+
35
+ # ✅ CORRECT: @post only sees 'result'
36
+ @post(lambda result: result >= 0)
37
+ ```
38
+ {% elif language == "typescript" -%}
39
+ ```typescript
40
+ // ❌ WRONG: Type-only validation (no semantic value)
41
+ const Input = z.number();
42
+
43
+ // ✅ CORRECT: Semantic constraints
44
+ const Input = z.number().nonnegative().max(100);
45
+
46
+ // ❌ WRONG: Output schema cannot reference input
47
+ const Output = z.number().min(x); // 'x' not available!
48
+
49
+ // ✅ CORRECT: Output schema only validates result
50
+ const Output = z.number().nonnegative();
51
+ ```
52
+ {% endif -%}
53
+
54
+ <!--/invar:critical-->
55
+
56
+ <!--invar:managed version="{{ version }}"-->
57
+ # Project Development Guide
58
+
59
+ > **Protocol:** Follow [INVAR.md](./INVAR.md) — includes Check-In, USBV workflow, and Task Completion requirements.
60
+
61
+ ## Check-In
62
+
63
+ > See [INVAR.md#check-in](./INVAR.md#check-in-required) for full protocol.
64
+
65
+ **Your first message MUST display:** `✓ Check-In: [project] | [branch] | [clean/dirty]`
66
+
67
+ **Actions:** Read `.invar/context.md`, then show status. Do NOT run guard at Check-In.
68
+
69
+ ---
70
+
71
+ ## Final
72
+
73
+ Your last message for an implementation task MUST display:
74
+
75
+ ```
76
+ ✓ Final: guard PASS | 0 errors, 2 warnings
77
+ ```
78
+
79
+ {% if syntax == "mcp" -%}
80
+ Execute `invar_guard()` and show this one-line summary.
81
+ {% else -%}
82
+ Execute `invar guard` and show this one-line summary.
83
+ {% endif %}
84
+
85
+ This is your sign-out. Completes the Check-In/Final pair.
86
+
87
+ ---
88
+
89
+ ## Project Structure
90
+
91
+ {% if language == "python" -%}
92
+ ```
93
+ src/{project}/
94
+ ├── core/ # Pure logic (@pre/@post, doctests, no I/O)
95
+ └── shell/ # I/O operations (Result[T, E] return type)
96
+ ```
97
+ {% elif language == "typescript" -%}
98
+ ```
99
+ src/
100
+ ├── core/ # Pure logic (Zod schemas, JSDoc examples, no I/O)
101
+ └── shell/ # I/O operations (Result<T, E> return type)
102
+ ```
103
+ {% endif -%}
104
+
105
+ **Key insight:** Core receives data (strings), Shell handles I/O (paths, files).
106
+
107
+ ## Quick Reference
108
+
109
+ | Zone | Requirements |
110
+ |------|-------------|
111
+ {% if language == "python" -%}
112
+ | Core | `@pre`/`@post` + doctests, pure (no I/O) |
113
+ | Shell | Returns `Result[T, E]` from `returns` library |
114
+ {% elif language == "typescript" -%}
115
+ | Core | Zod schemas + JSDoc examples, pure (no I/O) |
116
+ | Shell | Returns `Result<T, E>` from `neverthrow` library |
117
+ {% endif -%}
118
+
119
+ ### Core vs Shell (Edge Cases)
120
+
121
+ - File/network/env vars → **Shell**
122
+ - `datetime.now()`, `random` → **Inject param** OR Shell
123
+ - Pure logic → **Core**
124
+
125
+ > Full decision tree: [INVAR.md#core-shell](./INVAR.md#decision-tree-core-vs-shell)
126
+
127
+ ## Documentation Structure
128
+
129
+ | File | Owner | Edit? | Purpose |
130
+ |------|-------|-------|---------|
131
+ | INVAR.md | Invar | No | Protocol (`invar update` to sync) |
132
+ | AGENT.md | User | Yes | Project customization (this file) |
133
+ | .invar/context.md | User | Yes | Project state, lessons learned |
134
+ | .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns, workflow |
135
+
136
+ > **Before writing code:** Check Task Router in `.invar/context.md`
137
+
138
+ ## USBV Workflow
139
+
140
+ For complex tasks (3+ functions), follow these phases:
141
+
142
+ ### 1. UNDERSTAND
143
+
144
+ - **Intent:** What exactly needs to be done?
145
+ {% if syntax == "mcp" -%}
146
+ - **Inspect:** Use `invar_sig` to see existing contracts
147
+ {% else -%}
148
+ - **Inspect:** Use `invar sig` to see existing contracts
149
+ {% endif -%}
150
+ - **Context:** Read relevant code, understand patterns
151
+ - **Constraints:** What must NOT change?
152
+
153
+ ### 2. SPECIFY
154
+
155
+ {% if language == "python" -%}
156
+ - **Contracts FIRST:** Write `@pre`/`@post` before implementation
157
+ - **Doctests:** Add examples for expected behavior
158
+ {% elif language == "typescript" -%}
159
+ - **Contracts FIRST:** Write Zod schemas before implementation
160
+ - **JSDoc Examples:** Add `@example` for expected behavior
161
+ {% endif -%}
162
+ - **Design:** Decompose complex tasks into sub-functions
163
+
164
+ {% if language == "python" -%}
165
+ ```python
166
+ # SPECIFY before BUILD:
167
+ @pre(lambda x: x > 0)
168
+ @post(lambda result: result >= 0)
169
+ def calculate(x: int) -> int:
170
+ """
171
+ >>> calculate(10)
172
+ 100
173
+ """
174
+ ... # Implementation comes in BUILD
175
+ ```
176
+ {% elif language == "typescript" -%}
177
+ ```typescript
178
+ // SPECIFY before BUILD:
179
+ import { z } from 'zod';
180
+
181
+ const CalculateInput = z.number().positive();
182
+ const CalculateOutput = z.number().nonnegative();
183
+
184
+ /**
185
+ * @example calculate(10) // => 100
186
+ */
187
+ function calculate(x: number): number {
188
+ const validated = CalculateInput.parse(x);
189
+ // Implementation comes in BUILD
190
+ return CalculateOutput.parse(result);
191
+ }
192
+ ```
193
+ {% endif -%}
194
+
195
+ ### 3. BUILD
196
+
197
+ - Follow the contracts written in SPECIFY
198
+ {% if syntax == "mcp" -%}
199
+ - Run `invar_guard(changed=true)` frequently
200
+ {% else -%}
201
+ - Run `invar guard --changed` frequently
202
+ {% endif -%}
203
+ - Commit after each logical unit
204
+
205
+ ### 4. VALIDATE
206
+
207
+ {% if syntax == "mcp" -%}
208
+ - Run `invar_guard()` (full verification)
209
+ {% else -%}
210
+ - Run `invar guard` (full verification)
211
+ {% endif -%}
212
+ - Integration works (if applicable)
213
+
214
+ ---
215
+
216
+ ## Tool Selection
217
+
218
+ | I want to... | Use |
219
+ |--------------|-----|
220
+ {% if syntax == "mcp" -%}
221
+ | See contracts | `invar_sig(target="<file>")` |
222
+ | Find entry points | `invar_map(top=10)` |
223
+ | Verify code | `invar_guard()` |
224
+ {% else -%}
225
+ | See contracts | `invar sig <file>` |
226
+ | Find entry points | `invar map --top 10` |
227
+ | Verify code | `invar guard` |
228
+ {% endif -%}
229
+
230
+ ---
231
+
232
+ ## Task Completion
233
+
234
+ A task is complete only when ALL conditions are met:
235
+ - Check-In displayed: `✓ Check-In: [project] | [branch] | [clean/dirty]`
236
+ - Intent explicitly stated
237
+ - Contract written before implementation
238
+ - Final displayed: `✓ Final: guard PASS | <errors>, <warnings>`
239
+ - User requirement satisfied
240
+
241
+ **Missing any = Task incomplete.**
242
+
243
+ <!--/invar:managed-->
244
+ <!--invar:project-->
245
+ <!--/invar:project-->
246
+ <!--invar:user-->
247
+ <!-- ========================================================================
248
+ USER REGION - EDITABLE
249
+ Add your team conventions and project-specific rules below.
250
+ This section is preserved across `invar update` and `invar dev sync`.
251
+ ======================================================================== -->
252
+ <!--/invar:user-->
253
+
254
+ ---
255
+
256
+ *Generated by `invar init` v{{ version }}. Customize the user section freely.*
@@ -1,226 +1,33 @@
1
- <!--invar:critical-->
2
- ## Critical Rules
3
-
4
- | Always | Remember |
5
- |--------|----------|
6
- {% if syntax == "mcp" -%}
7
- | **Verify** | `invar_guard` NOT pytest, NOT crosshair |
8
- {% else -%}
9
- | **Verify** | `invar guard` — NOT pytest, NOT crosshair |
10
- {% endif -%}
11
- | **Core** | `@pre/@post` + doctests, NO I/O imports |
12
- | **Shell** | Returns `Result[T, E]` from `returns` library |
13
- | **Flow** | USBV: Understand → Specify → Build → Validate |
14
-
15
- ### Contract Rules (CRITICAL)
16
-
17
- ```python
18
- # ❌ WRONG: Lambda must include ALL parameters
19
- @pre(lambda x: x >= 0)
20
- def calc(x: int, y: int = 0): ...
21
-
22
- # ✅ CORRECT: Include defaults too
23
- @pre(lambda x, y=0: x >= 0)
24
- def calc(x: int, y: int = 0): ...
25
-
26
- # ❌ WRONG: @post cannot access parameters
27
- @post(lambda result: result > x) # 'x' not available!
28
-
29
- # ✅ CORRECT: @post only sees 'result'
30
- @post(lambda result: result >= 0)
31
- ```
32
-
33
- <!--/invar:critical-->
1
+ {# CLAUDE.md Composition Template
2
+ Composes universal workflow + language-specific rules
3
+ Variables: language (python|typescript), syntax (mcp|cli), version
4
+ #}
5
+ {% if language == "python" %}
6
+ {% include "claude-md/python/critical-rules.md" %}
7
+ {% elif language == "typescript" %}
8
+ {% include "claude-md/typescript/critical-rules.md" %}
9
+ {% endif %}
34
10
 
35
11
  <!--invar:managed version="{{ version }}"-->
36
12
  # Project Development Guide
37
13
 
38
14
  > **Protocol:** Follow [INVAR.md](./INVAR.md) — includes Check-In, USBV workflow, and Task Completion requirements.
39
15
 
40
- ## Check-In
41
-
42
- > See [INVAR.md#check-in](./INVAR.md#check-in-required) for full protocol.
43
-
44
- **Your first message MUST display:** `✓ Check-In: [project] | [branch] | [clean/dirty]`
45
-
46
- **Actions:** Read `.invar/context.md`, then show status. Do NOT run guard at Check-In.
16
+ {% include "claude-md/universal/check-in.md" %}
47
17
 
48
18
  ---
49
19
 
50
- ## Final
51
-
52
- Your last message for an implementation task MUST display:
53
-
54
- ```
55
- ✓ Final: guard PASS | 0 errors, 2 warnings
56
- ```
57
-
58
- {% if syntax == "mcp" -%}
59
- Execute `invar_guard()` and show this one-line summary.
60
- {% else -%}
61
- Execute `invar guard` and show this one-line summary.
20
+ {% if language == "python" %}
21
+ {% include "claude-md/python/quick-reference.md" %}
22
+ {% elif language == "typescript" %}
23
+ {% include "claude-md/typescript/quick-reference.md" %}
62
24
  {% endif %}
63
25
 
64
- This is your sign-out. Completes the Check-In/Final pair.
26
+ {% include "claude-md/universal/workflow.md" %}
65
27
 
66
28
  ---
67
29
 
68
- ## Project Structure
69
-
70
- ```
71
- src/{project}/
72
- ├── core/ # Pure logic (@pre/@post, doctests, no I/O)
73
- └── shell/ # I/O operations (Result[T, E] return type)
74
- ```
75
-
76
- **Key insight:** Core receives data (strings), Shell handles I/O (paths, files).
77
-
78
- ## Quick Reference
79
-
80
- | Zone | Requirements |
81
- |------|-------------|
82
- | Core | `@pre`/`@post` + doctests, pure (no I/O) |
83
- | Shell | Returns `Result[T, E]` from `returns` library |
84
-
85
- ### Core vs Shell (Edge Cases)
86
-
87
- - File/network/env vars → **Shell**
88
- - `datetime.now()`, `random` → **Inject param** OR Shell
89
- - Pure logic → **Core**
90
-
91
- > Full decision tree: [INVAR.md#core-shell](./INVAR.md#decision-tree-core-vs-shell)
92
-
93
- ## Documentation Structure
94
-
95
- | File | Owner | Edit? | Purpose |
96
- |------|-------|-------|---------|
97
- | INVAR.md | Invar | No | Protocol (`invar update` to sync) |
98
- | CLAUDE.md | User | Yes | Project customization (this file) |
99
- | .invar/context.md | User | Yes | Project state, lessons learned |
100
- | .invar/project-additions.md | User | Yes | Project rules → injected into CLAUDE.md |
101
- | .invar/examples/ | Invar | No | **Must read:** Core/Shell patterns, workflow |
102
-
103
- > **Before writing code:** Check Task Router in `.invar/context.md`
104
-
105
- ## Visible Workflow (DX-30)
106
-
107
- For complex tasks (3+ functions), show 3 checkpoints in TodoList:
108
-
109
- ```
110
- □ [UNDERSTAND] Task description, codebase context, constraints
111
- □ [SPECIFY] Contracts (@pre/@post) and design decomposition
112
- □ [VALIDATE] Guard results, Review Gate status, integration status
113
- ```
114
-
115
- **BUILD is internal work** — not shown in TodoList.
116
-
117
- **Show contracts before code.** See `.invar/examples/workflow.md` for full example.
118
-
119
- ## Phase Visibility (DX-51)
120
-
121
- Each USBV phase transition requires a visible header:
122
-
123
- ```
124
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
125
- 📍 /develop → SPECIFY (2/4)
126
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
127
- ```
128
-
129
- **Three-layer visibility:**
130
- - **Skill** (`/develop`) — Routing announcement
131
- - **Phase** (`SPECIFY 2/4`) — Phase header (this section)
132
- - **Tasks** — TodoWrite items
133
-
134
- Phase headers are SEPARATE from TodoWrite. Phase = where you are; TodoWrite = what to do.
135
-
136
- ---
137
-
138
- ## Context Management (DX-54)
139
-
140
- Re-read `.invar/context.md` when:
141
- 1. Entering any workflow (/develop, /review, etc.)
142
- 2. Completing a TodoWrite task (before moving to next)
143
- 3. Conversation exceeds ~15-20 exchanges
144
- 4. Unsure about project rules or patterns
145
-
146
- **Refresh is transparent** — do not announce "I'm refreshing context."
147
- Only show routing announcements when entering workflows.
148
-
149
- ---
150
-
151
- ## Commands (User-Invokable)
152
-
153
- | Command | Purpose |
154
- |---------|---------|
155
- | `/audit` | Read-only code review (reports issues, no fixes) |
156
- | `/guard` | Run Invar verification (reports results) |
157
-
158
- ## Skills (Agent-Invoked)
159
-
160
- | Skill | Triggers | Purpose |
161
- |-------|----------|---------|
162
- | `/investigate` | "why", "explain", vague tasks | Research mode, no code changes |
163
- | `/propose` | "should we", "compare" | Decision facilitation |
164
- | `/develop` | "add", "fix", "implement" | USBV implementation workflow |
165
- | `/review` | After /develop, `review_suggested` | Adversarial review with fix loop |
166
-
167
- **Note:** Skills are invoked by agent based on context. Use `/audit` for user-initiated review.
168
-
169
- Guard triggers `review_suggested` for: security-sensitive files, escape hatches >= 3, contract coverage < 50%.
170
-
171
- ---
172
-
173
- ## Workflow Routing (MANDATORY)
174
-
175
- When user message contains these triggers, you MUST use the **Skill tool** to invoke the skill:
176
-
177
- | Trigger Words | Skill Tool Call | Notes |
178
- |---------------|-----------------|-------|
179
- | "review", "review and fix" | `Skill(skill="review")` | Adversarial review with fix loop |
180
- | "implement", "add", "fix", "update" | `Skill(skill="develop")` | Unless in review context |
181
- | "why", "explain", "investigate" | `Skill(skill="investigate")` | Research mode, no code changes |
182
- | "compare", "should we", "design" | `Skill(skill="propose")` | Decision facilitation |
183
-
184
- **⚠️ CRITICAL: You must call the Skill tool, not just follow the workflow mentally.**
185
-
186
- The Skill tool reads `.claude/skills/<skill>/SKILL.md` which contains:
187
- - Detailed phase instructions (USBV breakdown)
188
- - Error handling rules
189
- - Timeout policies
190
- - Incremental development patterns (DX-63)
191
-
192
- **Violation check (before writing ANY code):**
193
- - "Did I call `Skill(skill="...")`?"
194
- - "Am I following the SKILL.md instructions?"
195
-
196
- ---
197
-
198
- ## Routing Control (DX-42)
199
-
200
- Agent announces routing decision before entering any workflow:
201
-
202
- ```
203
- 📍 Routing: /[skill] — [trigger or reason]
204
- Task: [summary]
205
- ```
206
-
207
- **User can redirect with natural language:**
208
- - "wait" / "stop" — pause and ask for direction
209
- - "just do it" — proceed with /develop
210
- - "let's discuss" — switch to /propose
211
- - "explain first" — switch to /investigate
212
-
213
- **Simple task optimization:** For simple tasks (single file, clear target, <50 lines), agent may offer:
214
-
215
- ```
216
- 📊 Simple task. Auto-orchestrate? [Y/N]
217
- ```
218
-
219
- - Y → Full cycle without intermediate confirmations
220
- - N → Normal step-by-step workflow
221
-
222
- **Auto-review (DX-41):** When Guard outputs `review_suggested`, agent automatically
223
- enters /review. Say "skip" to bypass.
30
+ {% include "claude-md/universal/skills.md" %}
224
31
  <!--/invar:managed-->
225
32
 
226
33
  <!--invar:project-->
@@ -13,8 +13,13 @@
13
13
  <!-- DX-54: Rules summary for long conversation resilience -->
14
14
 
15
15
  ### Core/Shell Separation
16
+ {% if language == "python" -%}
16
17
  - **Core** (`**/core/**`): @pre/@post + doctests, NO I/O imports
17
18
  - **Shell** (`**/shell/**`): Result[T, E] return type
19
+ {% elif language == "typescript" -%}
20
+ - **Core** (`**/core/**`): Contract comments (@pre/@post), no side effects
21
+ - **Shell** (`**/shell/**`): Result<T, E> return type
22
+ {% endif -%}
18
23
 
19
24
  ### USBV Workflow
20
25
  1. Understand → 2. Specify (contracts first) → 3. Build → 4. Validate
@@ -31,6 +36,7 @@
31
36
 
32
37
  <!-- Before writing code, check this table -->
33
38
 
39
+ {% if language == "python" %}
34
40
  | If you are about to... | STOP and read first |
35
41
  |------------------------|---------------------|
36
42
  | Write code in `core/` | `.invar/examples/contracts.py` |
@@ -38,6 +44,15 @@
38
44
  | Add `@pre`/`@post` contracts | `.invar/examples/contracts.py` |
39
45
  | Use functional patterns | `.invar/examples/functional.py` |
40
46
  | Implement a feature | `.invar/examples/workflow.md` |
47
+ {% elif language == "typescript" %}
48
+ | If you are about to... | STOP and read first |
49
+ |------------------------|---------------------|
50
+ | Write code in `core/` | `.invar/examples/contracts.ts` |
51
+ | Write code in `shell/` | `.invar/examples/core_shell.ts` |
52
+ | Add contract comments | `.invar/examples/contracts.ts` |
53
+ | Use functional patterns | `.invar/examples/functional.ts` |
54
+ | Implement a feature | `.invar/examples/workflow.md` |
55
+ {% endif %}
41
56
 
42
57
  **Rule:** Match found above? Read the file BEFORE writing code.
43
58
 
@@ -53,7 +68,11 @@
53
68
 
54
69
  **Quick rule check:**
55
70
  - Am I in Core or Shell?
71
+ {% if language == "python" -%}
56
72
  - Do I have @pre/@post contracts?
73
+ {% elif language == "typescript" -%}
74
+ - Do I have contract comments (@pre/@post)?
75
+ {% endif -%}
57
76
  - Am I following USBV workflow?
58
77
  - Did I run guard before claiming "done"?
59
78
 
@@ -8,6 +8,7 @@ Reference examples for the Invar Protocol. These are managed by Invar.
8
8
  |------|---------|
9
9
  | [contracts.py](contracts.py) | @pre/@post patterns, doctest best practices |
10
10
  | [core_shell.py](core_shell.py) | Core/Shell separation patterns |
11
+ | [functional.py](functional.py) | Functional patterns (NewType, Validation, NonEmpty, Literal) |
11
12
  | [workflow.md](workflow.md) | Visible USBV workflow example |
12
13
 
13
14
  ## Usage
@@ -16,6 +17,7 @@ Read these when you need:
16
17
  - Contract pattern reference
17
18
  - Core vs Shell decision guidance
18
19
  - Doctest formatting examples
20
+ - Functional pattern suggestions
19
21
  - USBV workflow example
20
22
 
21
23
  ---
@@ -1,3 +1,3 @@
1
1
  # Skip pytest collection for example files
2
2
  # These are reference examples, not tests.
3
- collect_ignore = ["contracts.py", "core_shell.py", "workflow.md"]
3
+ collect_ignore = ["contracts.py", "core_shell.py", "functional.py", "workflow.md"]