@rawsql-ts/ztd-cli 0.14.2 → 0.14.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rawsql-ts/ztd-cli",
3
- "version": "0.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "DB-agnostic scaffolding and DDL helpers for Zero Table Dependency projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -25,8 +25,8 @@
25
25
  "chokidar": "^5.0.0",
26
26
  "commander": "^12.0.0",
27
27
  "diff": "^5.1.0",
28
- "@rawsql-ts/testkit-core": "0.14.2",
29
- "rawsql-ts": "0.14.2"
28
+ "@rawsql-ts/testkit-core": "0.14.3",
29
+ "rawsql-ts": "0.14.3"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/diff": "^5.0.1",
@@ -1,14 +1,22 @@
1
1
  # Appendix: Development Workflow Using Zero Table Dependency (ZTD)
2
2
 
3
- This application uses **Zero Table Dependency (ZTD)** as an internal development workflow for writing, testing, and maintaining SQL logic.
3
+ This application uses **Zero Table Dependency (ZTD)** as an internal development workflow for writing, testing, and maintaining SQL logic.
4
4
  ZTD is not part of the application's runtime behavior; rather, it provides a framework for:
5
5
 
6
- - Maintaining consistent SQL across the project
7
- - Keeping schema, domain specifications, and enums synchronized
8
- - Ensuring deterministic SQL unit tests
9
- - Enabling structured collaboration between humans and AI
6
+ - Maintaining consistent SQL across the project
7
+ - Keeping schema, domain specifications, and enums synchronized
8
+ - Ensuring deterministic SQL unit tests
9
+ - Enabling structured collaboration between humans and AI
10
10
 
11
- This section documents how ZTD is used *inside this repository* as a development methodology.
11
+ This section documents how ZTD is used inside this repository as a development methodology.
12
+
13
+ ---
14
+
15
+ ## Defaults (important)
16
+
17
+ - This project adopts **ZTD as the default development and testing methodology**.
18
+ - ZTD is assumed unless explicitly stated otherwise.
19
+ - Detailed rules about test execution modes are defined in `templates/tests/AGENTS.md`.
12
20
 
13
21
  ---
14
22
 
@@ -61,14 +69,14 @@ The `src/` directory should contain pure TypeScript logic that operates on the r
61
69
  ### Sequence / identity column policy (important)
62
70
 
63
71
  - Sequence / identity columns (auto-generated IDs) are infrastructure concerns.
64
- - Do **not** explicitly assign values to sequence / identity columns in `INSERT` statements unless explicitly instructed.
72
+ - Do not explicitly assign values to sequence / identity columns in `INSERT` statements unless explicitly instructed.
65
73
  - Repository method inputs should omit sequence / identity columns by default.
66
74
  - Only treat an ID as input data when it represents a business rule (e.g. natural keys, externally assigned IDs).
67
75
 
68
76
  ### No test-driven fallbacks in production code (important)
69
77
 
70
- - **Do not add fallbacks in `src/` that exist only to accommodate ZTD/testkit/rewriter limitations.**
71
- - If a query fails to be rewritten into ZTD form (e.g. rawsql-ts parsing/rewrite failure), **do not paper over it** by changing runtime behavior, adding `max(id)+1`, or introducing alternative logic paths.
78
+ - Do not add fallbacks in `src/` that exist only to accommodate ZTD/testkit/rewriter limitations.
79
+ - If a query fails to be rewritten into ZTD form (e.g. rawsql-ts parsing/rewrite failure), do not paper over it by changing runtime behavior, adding `max(id)+1`, or introducing alternative logic paths.
72
80
  - Instead, stop and report the issue with evidence:
73
81
  - The exact SQL that fails
74
82
  - The error message / symptoms
@@ -81,51 +89,11 @@ Rationale: Production code must not diverge from the intended SQL semantics due
81
89
 
82
90
  ## ZTD Test Guide (tests/)
83
91
 
84
- Fixtures come from the `ztd/ddl/` definitions and power `pg-testkit`. Always import table types from `tests/generated/ztd-row-map.generated.ts` when constructing scenarios, and rerun `npx ztd ztd-config` whenever schema changes to keep the fixtures and row map synchronized.
85
-
86
- If you are working inside this repository's `ztd-playground`, regenerate the generated artifacts with `pnpm --filter ztd-playground exec ztd ztd-config`.
87
-
88
- - Set `ZTD_EXECUTION_MODE=traditional` or pass `{ mode: 'traditional', traditional: { isolation: 'schema', cleanup: 'drop_schema' } }` to `createTestkitClient()` when you must exercise real Postgres semantics (locks, isolation, constraints). Traditional mode still runs the DDL inside `ztd/ddl/`, seeds the fixtures, executes any optional `setupSql`, and honors the configured `cleanup` strategy (`drop_schema` by default, `custom_sql`, or `none` for debugging) so the environment stays tidy. Use `isolation: 'none'` when your queries explicitly reference an existing schema and you cannot rely on schema-based isolation.
89
-
90
-
91
- ### Tests: What to Care About
92
-
93
- #### Test Intent
94
- - Each test should have a single clear observation point.
95
- - Decide whether the test verifies:
96
- - Query semantics (input to output behavior), or
97
- - Structural properties (ordering, filtering, boundary cases).
98
-
99
- #### Fixtures
100
- - Keep fixtures minimal and intention-revealing.
101
- - Prefer small datasets over large ones.
102
- - Avoid adding rows or columns that are not directly related to the test intent.
103
-
104
- #### Assertions
105
- - Assert only on relevant columns and values.
106
- - Do not rely on implicit ordering; if order matters, make it explicit in SQL and assertions.
107
- - Avoid custom verification logic; rely on query results and straightforward assertions.
108
-
109
- #### Relationship to Repositories
110
- - Tests for repositories should focus on observable behavior, not internal implementation details.
111
- - Avoid duplicating repository logic inside tests.
112
-
113
- ### Notes
114
- - These guidelines are intentionally lightweight.
115
- - They are expected to evolve based on actual usage and failure cases.
116
- - If user instructions conflict with these guidelines, follow user instructions.
117
-
118
- ### ID expectations in tests (important)
119
-
120
- - Do not assert auto-generated ID values (sequence / identity), such as "the next id is 11".
121
- - When creating rows, assert only that an ID exists and has the correct type, or that it differs from known existing IDs.
122
- - Only assert specific ID values when the ID is part of a business rule (not infrastructure), e.g. a natural key or a fixed, meaningful identifier.
92
+ Testing under ZTD follows dedicated, directory-scoped rules.
123
93
 
124
- ## Parallel test policy (important)
125
-
126
- - ZTD tests should be safe to run in parallel against a single Postgres instance because pg-testkit rewrites CRUD into fixture-backed SELECT queries (no physical schema changes).
127
- - Do not start multiple Postgres instances per test file/worker, and do not isolate tests by creating per-test databases or schemas. This is unnecessary for ZTD and adds failure modes.
128
- - Prefer one shared Postgres instance + multiple connections, limited only by your DB resources.
94
+ - Test design, execution mode selection, and constraints are defined in:
95
+ - `templates/tests/AGENTS.md`
96
+ - This file intentionally avoids duplicating test-specific operational rules to prevent divergence.
129
97
 
130
98
  ---
131
99
 
@@ -153,25 +121,40 @@ The file `tests/generated/ztd-layout.generated.ts` ensures ZTD CLI always points
153
121
 
154
122
  ---
155
123
 
124
+ # Protected directories and edit ownership (important)
125
+
126
+ - DDL editing is human-led: `ztd/ddl/`
127
+ - Domain specs editing is human-led: `ztd/domain-specs/`
128
+ - Enums editing is human-led: `ztd/enums/`
129
+ - Application code is shared ownership: `src/`
130
+ - Tests are shared ownership: `tests/`
131
+ - Detailed test constraints live in `templates/tests/AGENTS.md`.
132
+
133
+ Additionally:
134
+ - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction.
135
+ - When changes are required in human-led directories, prefer proposing a patch and explaining the impact before applying it.
136
+
137
+ ---
138
+
156
139
  # Principles of ZTD in This Repository
157
140
 
158
- ### 1. Humans own the **definitions**
141
+ ### 1. Humans own the definitions
159
142
  - Physical schema (DDL)
160
143
  - Domain semantics (domain-specs)
161
144
  - Enumerations (enums)
162
145
  - Repository interfaces
163
146
 
164
- ### 2. AI assists with **implementation**
147
+ ### 2. AI assists with implementation
165
148
  - Generating repository SQL
166
149
  - Updating fixtures
167
150
  - Producing intermediate TypeScript structures
168
151
  - Ensuring SQL adheres to DDL, enums, and domain-specs
169
152
 
170
- ### 3. ZTD enforces **consistency**
153
+ ### 3. ZTD enforces consistency
171
154
  ZTD tests verify that:
172
- - SQL logic matches DDL shapes
173
- - SQL semantics match domain-specs
174
- - SQL values match enumerations
155
+ - SQL logic matches DDL shapes
156
+ - SQL semantics match domain-specs
157
+ - SQL values match enumerations
175
158
 
176
159
  If anything diverges, ZTD failures surface immediately and deterministically.
177
160
 
@@ -183,27 +166,20 @@ Different types of changes start from different entry points. Use the workflow a
183
166
 
184
167
  ---
185
168
 
186
- # Workflow A Starting From *DDL Changes*
169
+ # Workflow A - Starting From DDL Changes
187
170
  Modifying tables, columns, constraints, indexes.
188
171
 
189
172
  1. Edit DDL files in `ztd/ddl/`.
190
- 2. Run:
191
-
192
- ```bash
193
- npx ztd ztd-config
194
- ```
195
-
196
- This regenerates `tests/generated/ztd-row-map.generated.ts` from the updated schema.
197
-
173
+ 2. Run `npx ztd ztd-config`.
198
174
  3. Update repository SQL to match the new schema.
199
175
  4. Update fixtures if result shapes changed.
200
176
  5. Run tests.
201
177
 
202
- **Flow:** DDL -> Repository SQL -> Fixtures/Tests -> Application
178
+ Flow: DDL to Repository SQL to Fixtures and Tests to Application
203
179
 
204
180
  ---
205
181
 
206
- # Workflow B Starting From *Repository Interface Changes*
182
+ # Workflow B - Starting From Repository Interface Changes
207
183
  Changing method signatures, adding new repository methods, etc.
208
184
 
209
185
  1. Modify the repository interface or implementation in `/src`.
@@ -212,11 +188,11 @@ Changing method signatures, adding new repository methods, etc.
212
188
  4. Run ZTD tests.
213
189
  5. Regenerate config if SQL output shape changed.
214
190
 
215
- **Flow:** Interface -> SQL -> Specs (if needed) -> Tests
191
+ Flow: Interface to SQL to Specs (if needed) to Tests
216
192
 
217
193
  ---
218
194
 
219
- # Workflow C Starting From *Repository SQL Logic Changes*
195
+ # Workflow C - Starting From Repository SQL Logic Changes
220
196
  Bug fixes, refactoring, rewriting queries.
221
197
 
222
198
  1. Edit SQL inside the repository.
@@ -225,46 +201,27 @@ Bug fixes, refactoring, rewriting queries.
225
201
  4. Update fixtures as needed.
226
202
  5. Regenerate config if result shape changed.
227
203
 
228
- **Flow:** SQL -> Domain-specs -> Tests
204
+ Flow: SQL to Domain-specs to Tests
229
205
 
230
206
  ---
231
207
 
232
- # Workflow D Starting From *Enum or Domain Specification Changes*
208
+ # Workflow D - Starting From Enum or Domain Specification Changes
233
209
  Business rule changes or conceptual model updates.
234
210
 
235
- ## Editing enums:
236
-
237
- 1. Update the relevant `.md` file under `ztd/enums/`.
238
- 2. Run:
239
-
240
- ```bash
241
- npx ztd ztd-config
242
- ```
243
-
244
- 3. Update repository SQL referencing enum values.
245
- 4. Update fixtures/tests.
246
-
247
- ## Editing domain-specs:
248
-
249
- 1. Update the relevant `.md` file under `ztd/domain-specs/`.
250
- 2. Update repository SQL to reflect the new semantics.
251
- 3. Update or add tests.
252
- 4. Update DDL only if the new rules require schema changes.
253
-
254
- **Flow:** Specs/Enums -> SQL -> Tests -> (DDL if required)
211
+ Flow: Specs or Enums to SQL to Tests to (DDL if required)
255
212
 
256
213
  ---
257
214
 
258
215
  # Combined Real-World Examples
259
216
 
260
- - Adding a new contract state:
261
- enums -> domain-spec -> SQL -> config -> tests
217
+ - Adding a new contract state:
218
+ enums to domain-spec to SQL to config to tests
262
219
 
263
- - Adding a new table:
264
- DDL -> config -> SQL -> fixtures -> tests
220
+ - Adding a new table:
221
+ DDL to config to SQL to fixtures to tests
265
222
 
266
- - Fixing business logic:
267
- SQL -> domain-spec -> tests
223
+ - Fixing business logic:
224
+ SQL to domain-spec to tests
268
225
 
269
226
  ZTD ensures the development always converges into a consistent, validated workflow.
270
227
 
@@ -278,9 +235,9 @@ Humans maintain:
278
235
  - Domain logic definitions (`ztd/domain-specs`)
279
236
  - Domain enumerations (`ztd/enums`)
280
237
  - Repository interfaces and architectural decisions
281
- - Acceptance/review of AI-generated patches
238
+ - Acceptance and review of AI-generated patches
282
239
 
283
- Humans decide **what is correct**.
240
+ Humans decide what is correct.
284
241
 
285
242
  ---
286
243
 
@@ -288,14 +245,14 @@ Humans decide **what is correct**.
288
245
 
289
246
  AI must:
290
247
 
291
- - Use domain-specs as the semantic source of truth
292
- - Use enums as the canonical vocabulary source
293
- - Use DDL as the physical structure constraint
294
- - Generate SQL consistent with all definitions
295
- - Update fixtures when needed
296
- - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction
248
+ - Use domain-specs as the semantic source of truth
249
+ - Use enums as the canonical vocabulary source
250
+ - Use DDL as the physical structure constraint
251
+ - Generate SQL consistent with all definitions
252
+ - Update fixtures when needed
253
+ - Never modify `ztd/AGENTS.md` or `ztd/README.md` without explicit instruction
297
254
 
298
- AI decides **how to implement**, but not **what is correct**.
255
+ AI decides how to implement, but not what is correct.
299
256
 
300
257
  ---
301
258
 
@@ -303,10 +260,10 @@ AI decides **how to implement**, but not **what is correct**.
303
260
 
304
261
  ZTD CLI:
305
262
 
306
- - Parses DDL to compute schema shapes
307
- - Rewrites SQL via CTE shadowing for testing
308
- - Generates `ztd-row-map.generated.ts`
309
- - Enables deterministic, parallel SQL unit tests
263
+ - Parses DDL to compute schema shapes
264
+ - Rewrites SQL via CTE shadowing for testing
265
+ - Generates `ztd-row-map.generated.ts`
266
+ - Enables deterministic, parallel SQL unit tests
310
267
 
311
268
  ZTD is the verification engine that validates correctness beyond static typing.
312
269
 
@@ -314,13 +271,13 @@ ZTD is the verification engine that validates correctness beyond static typing.
314
271
 
315
272
  # Summary
316
273
 
317
- This appendix documents how ZTD is used strictly as an **internal implementation and maintenance guide**.
318
- It does not affect the runtime behavior of the application.
274
+ This appendix documents how ZTD is used strictly as an internal implementation and maintenance guide.
275
+ It does not affect the runtime behavior of the application.
319
276
  Its purpose is ensuring:
320
277
 
321
- - Schema integrity
322
- - SQL correctness
323
- - Domain consistency
324
- - Reliable AI-assisted development
278
+ - Schema integrity
279
+ - SQL correctness
280
+ - Domain consistency
281
+ - Reliable AI-assisted development
325
282
 
326
- With ZTD, **humans define the meaning**, **AI writes the implementation**, and **tests guarantee correctness**.
283
+ With ZTD, humans define the meaning, AI writes the implementation, and tests guarantee correctness.
@@ -0,0 +1,116 @@
1
+ # AGENTS: ZTD Test Guidelines
2
+
3
+ This file defines **rules and boundaries for writing tests under `tests/`**.
4
+ Tests are a shared workspace for humans and AI, but must respect ZTD-specific constraints.
5
+
6
+ ---
7
+
8
+ ## Default execution mode (important)
9
+
10
+ - The default execution mode for tests is **ZTD**.
11
+ - Do not switch to Traditional mode unless explicitly instructed by a human.
12
+ - Do not set `ZTD_EXECUTION_MODE=traditional` or pass `{ mode: "traditional" }` to `createTestkitClient()` without explicit instruction.
13
+ - If instructions are ambiguous, assume ZTD mode and proceed.
14
+
15
+ ---
16
+
17
+ ## Use generated types only (important)
18
+
19
+ - Do **not** define ad-hoc or duplicate test models.
20
+ - For table-shaped rows, always import types from:
21
+ - `tests/generated/ztd-row-map.generated.ts`
22
+ - For application-facing return values:
23
+ - Use DTO or domain model types already defined in `src/`.
24
+
25
+ Forbidden example:
26
+
27
+ ```typescript
28
+ type CategoryTestRow = {
29
+ category_id: number;
30
+ parent_id: number | null;
31
+ name: string;
32
+ };
33
+ ```
34
+
35
+ If a required type is missing:
36
+ - Regenerate generated artifacts (`npx ztd ztd-config`), or
37
+ - Export the correct type from `src/`.
38
+
39
+ Do not invent substitute models.
40
+
41
+ ---
42
+
43
+ ## Stateless test design (important)
44
+
45
+ - ZTD tests are **stateless by design**.
46
+ - Do not write tests that depend on state accumulating across multiple repository calls.
47
+
48
+ Forbidden patterns include:
49
+ - Updating the same record in multiple steps and verifying later state
50
+ - Calling multiple repository methods assuming earlier calls affected the database
51
+
52
+ Preferred patterns:
53
+ - Verify results returned by a single statement
54
+ - Verify `RETURNING` values
55
+ - Verify affected row counts
56
+ - Verify query output produced by the same call being tested
57
+
58
+ If behavior depends on transactions, isolation, or shared mutable state:
59
+ - That test does not belong in ZTD unit tests.
60
+ - Move it to an integration test and explicitly request Traditional mode.
61
+
62
+ ---
63
+
64
+ ## Fixtures (important)
65
+
66
+ - Fixtures originate from `ztd/ddl/`.
67
+ - Keep fixtures minimal and intention-revealing.
68
+ - Do not add rows or columns unrelated to the test intent.
69
+ - Do not simulate application-side logic in fixtures.
70
+
71
+ ---
72
+
73
+ ## Assertions (important)
74
+
75
+ - Assert only on relevant fields.
76
+ - Do not assert implicit ordering.
77
+ - Do not assert specific values of auto-generated IDs.
78
+ - Assert existence, type, or relative differences instead.
79
+
80
+ ---
81
+
82
+ ## Repository boundaries
83
+
84
+ - Tests should verify observable behavior of repository methods.
85
+ - Do not duplicate SQL logic or business rules inside tests.
86
+ - Do not test internal helper functions or private implementation details.
87
+
88
+ ---
89
+
90
+ ## Edit boundaries
91
+
92
+ - Tests are shared ownership: humans and AI may both edit.
93
+ - However:
94
+ - Do not redefine models.
95
+ - Do not change schema assumptions.
96
+ - Do not edit `ztd/ddl`, `ztd/domain-specs`, or `ztd/enums` from tests.
97
+
98
+ ---
99
+
100
+ ## Conflict resolution
101
+
102
+ - If test requirements conflict with ZTD constraints:
103
+ - Stop and ask for clarification.
104
+ - Do not silently switch modes or weaken assertions.
105
+
106
+ ---
107
+
108
+ ## Guiding principle
109
+
110
+ ZTD tests exist to validate **SQL semantics in isolation**.
111
+ They are not integration tests, migration tests, or transaction tests.
112
+
113
+ Prefer:
114
+ - Clear intent
115
+ - Single observation point
116
+ - Deterministic outcomes
@@ -1,103 +1,149 @@
1
1
  # AGENTS: Zero Table Dependency Definitions
2
2
 
3
+ This file defines **protected, human-led domains** under the `ztd/` directory.
4
+ AI must treat these directories as authoritative sources of truth and must not modify them without explicit instruction.
5
+
6
+ ---
7
+
3
8
  ## Generated files (important)
4
9
 
5
10
  - `tests/generated/` is auto-generated and must never be committed.
6
11
  - After cloning the repository (or in a clean environment), run `npx ztd ztd-config`.
7
12
  - If TypeScript reports missing modules or type errors because `tests/generated/` is missing, run `npx ztd ztd-config`.
8
13
 
9
- ## DDL Specifications
14
+ ---
10
15
 
11
- You are an AI assistant responsible for reading and respecting the contents of this /ztd/ddl directory.
16
+ ## DDL Specifications (`ztd/ddl/`)
17
+
18
+ You are an AI assistant responsible for **reading and respecting** the contents of this directory.
12
19
 
13
20
  ### Purpose
14
21
 
15
- This directory contains all canonical definitions of database structure, including CREATE TABLE, ALTER TABLE, constraints, and indexes. It is considered the **single source of truth** for database schema as interpreted by the ztd-cli.
22
+ This directory contains all canonical definitions of database structure, including:
16
23
 
17
- ### Behavior Rules
24
+ - CREATE TABLE
25
+ - ALTER TABLE
26
+ - Constraints
27
+ - Indexes
18
28
 
19
- - **Never modify files in this folder unless explicitly instructed by a human.**
20
- - You may propose edits, reviews, or new DDL structures when asked, but you must preserve all human-authored structure, naming, and intent.
21
- - All DDL statements **must be semicolon-terminated** and valid PostgreSQL syntax.
22
- - You must not reorder statements arbitrarily; semantic meaning and dependency order must be preserved.
23
- - Respect formatting conventions, identifier styles, and comments written by humans.
24
- - When generating new tables or columns, infer types and constraints based on other schema examples or enums (if available).
25
- - Maintain consistency in column ordering, naming style, and constraint patterns.
26
- - When adding to existing definitions, do not remove human-authored comments unless told to.
27
- - Do not introduce structural changes that conflict with domain-specs or enums.
29
+ It is the **single source of truth** for the physical database schema as interpreted by ztd-cli.
28
30
 
29
- ### Interaction with Other Sources
31
+ ### Behavior Rules (strict)
30
32
 
31
- - Refer to /ztd/domain-specs for domain logic and behavioral definitions. These dictate *what* should exist in the schema.
32
- - Refer to /ztd/enums for allowable value sets when defining enum-like columns or constraints.
33
- - Always use those definitions as context when writing or editing this schema.
33
+ - **Never modify files in this directory unless explicitly instructed by a human.**
34
+ - Do not apply “helpful” refactors, cleanups, or formatting changes on your own.
35
+ - You may propose edits or review changes when asked, but you must not apply them without approval.
36
+ - All DDL statements must be:
37
+ - Valid PostgreSQL syntax
38
+ - Explicitly semicolon-terminated
39
+ - Do not reorder statements; dependency and execution order matters.
40
+ - Preserve all human-authored:
41
+ - Naming
42
+ - Formatting
43
+ - Comments
44
+ - Structural intent
45
+ - When asked to extend existing definitions:
46
+ - Do not remove or rewrite existing columns or comments unless explicitly told.
47
+ - Maintain column order and constraint style.
48
+ - Do not introduce schema changes that conflict with:
49
+ - `ztd/domain-specs`
50
+ - `ztd/enums`
34
51
 
35
- If uncertain, defer to human authorship and request clarification.
52
+ If there is uncertainty, stop and request clarification instead of guessing.
36
53
 
37
- ## Domain Specifications
54
+ ---
38
55
 
39
- You are an AI agent reading this directory to interpret domain logic.
56
+ ## Domain Specifications (`ztd/domain-specs/`)
40
57
 
41
- ### Instructions
58
+ You are an AI agent that **reads** domain specifications to understand business semantics.
59
+
60
+ ### Purpose
61
+
62
+ Each file in this directory defines **one domain behavior**.
63
+ These files explain *what the data means*, not how the application is implemented.
42
64
 
43
- - Treat each Markdown file as defining **one domain behavior**.
44
- - Use the embedded SQL block (`sql ... `) as the **reference SELECT**.
45
- - Only the first top-level SELECT block should be considered executable logic.
46
- - Parameters may be written in :named format (e.g., :as_of). You must bind them as positional placeholders (e.g., $1, $2, ?) in generated code.
47
- - Do not generate or modify files in this directory unless explicitly asked.
65
+ ### Instructions
48
66
 
49
- ### Assumptions
67
+ - Treat each Markdown file as defining exactly **one behavior**.
68
+ - Use the embedded SQL block as the **reference SELECT**.
69
+ - Only the first top-level SQL block is executable logic.
70
+ - Parameters may be written as `:named` placeholders.
71
+ - When generating executable SQL, bind them as positional placeholders (`$1`, `$2`, `?`).
72
+ - **Never modify files in this directory unless explicitly instructed.**
50
73
 
51
- - `ztd-config` parses only DDL (`ztd/ddl/**/*.sql`) to generate row shapes.
52
- - These specifications are for **humans and AI consumption** (documentation + reference SQL).
53
- - Comments and descriptions exist to help you interpret logic correctly.
74
+ ### Rules (strict)
54
75
 
55
- ### Rules
76
+ - Never ignore the human-written explanation above the SQL block.
77
+ - Keep exactly one executable SQL block per file.
78
+ - Do not reorder, optimize, or “simplify” SQL unless explicitly instructed.
79
+ - Preserve the exact semantics described by humans.
80
+ - This directory defines **what is correct behavior**.
81
+ - Your role is to reproduce that behavior elsewhere (`src/`, `tests/`), not reinterpret it.
56
82
 
57
- - Never ignore the human-written description above the SQL block.
58
- - Keep exactly one executable SQL block per file (one file = one behavior).
59
- - Do not reorder or optimize the SQL unless explicitly instructed.
60
- - Preserve the semantic meaning as given in the specification.
61
- - This folder defines **what** logic means. Your job is to reproduce that logic elsewhere (e.g., in src/ or tests).
83
+ If meaning is ambiguous, defer to human judgment and ask.
62
84
 
63
- If in doubt, ask for clarification or defer to human judgment.
85
+ ---
64
86
 
65
- ## Domain Enums
87
+ ## Domain Enums (`ztd/enums/`)
66
88
 
67
- You are an AI assistant responsible for reading domain enum definitions from this folder.
89
+ You are an AI assistant responsible for **reading and using** domain enum definitions.
68
90
 
69
91
  ### Purpose
70
92
 
71
- This directory defines canonical value sets (enums) such as status codes and plan tiers. These definitions inform your code generation logic, constraint enforcement, and vocabulary use.
93
+ This directory defines canonical value sets such as:
94
+
95
+ - Status codes
96
+ - Category types
97
+ - Plan tiers
72
98
 
73
- ### Behavior Guidelines
99
+ These enums are the **only allowed vocabulary** for such concepts.
74
100
 
75
- - Read from the Markdown file containing SQL select ... from (values ...) blocks.
76
- - Never invent magic numbers or enum values. Always use those explicitly defined here.
77
- - Do not modify or append new enums unless explicitly instructed by a human.
101
+ ### Behavior Guidelines (strict)
102
+
103
+ - Never invent enum values.
104
+ - Never hardcode magic numbers or strings.
105
+ - Never modify or add enum definitions unless explicitly instructed by a human.
78
106
 
79
107
  ### SQL Rules
80
108
 
81
- - Each SQL block defines an enum set.
82
- - Keep exactly one executable SQL block per file (one file = one enum set).
83
- - All blocks follow the form:
109
+ - Each file contains exactly one executable SQL block.
110
+ - Enum definitions follow this canonical pattern:
84
111
 
85
- `sql
112
+ ```sql
86
113
  select v.*
87
114
  from (
88
115
  values
89
116
  (1, 'some_code', 'some_label')
90
117
  ) v(key, value, display_name);
91
- `
118
+ ```
92
119
 
93
- - You must extract key and value pairs as the authoritative mapping.
94
- - display_name,
95
- ranking, or other metadata may be used where helpful (e.g., UI rendering or sorting).
120
+ - `key` and `value` are authoritative.
121
+ - Additional columns (e.g. `display_name`, `ranking`) may be used for:
122
+ - UI display
123
+ - Sorting
124
+ - Documentation
96
125
 
97
126
  ### Use in Code Generation
98
127
 
99
- - Use these enums when generating SQL WHERE clauses, conditionals, or constants.
100
- - When translating logic from /ztd/domain-specs, map references like :status__established to corresponding values here.
101
- - Maintain full consistency with enum names and intent.
128
+ - Always reference enums when generating:
129
+ - SQL WHERE conditions
130
+ - Constants
131
+ - Conditional logic
132
+ - When translating logic from `ztd/domain-specs`, resolve enum references through this directory.
133
+ - Maintain full consistency with naming and intent.
134
+
135
+ If a required enum does not exist, stop and ask for human clarification.
136
+
137
+ ---
138
+
139
+ ## Absolute Restrictions (important)
140
+
141
+ - AI must not modify anything under `ztd/` by default.
142
+ - DDL, domain-specs, and enums are **human-led artifacts**.
143
+ - AI may assist by:
144
+ - Reading
145
+ - Explaining
146
+ - Proposing diffs
147
+ - AI may apply changes **only** with explicit instruction.
102
148
 
103
- If a required enum is missing, raise an error or ask for human clarification.
149
+ Violation of these rules leads to silent corruption of domain meaning and is unacceptable.