deviatdd 2.5.1__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 (124) hide show
  1. deviatdd-2.5.1.dist-info/METADATA +386 -0
  2. deviatdd-2.5.1.dist-info/RECORD +124 -0
  3. deviatdd-2.5.1.dist-info/WHEEL +4 -0
  4. deviatdd-2.5.1.dist-info/entry_points.txt +2 -0
  5. deviatdd-2.5.1.dist-info/licenses/LICENSE +21 -0
  6. deviate/__init__.py +3 -0
  7. deviate/cli/__init__.py +824 -0
  8. deviate/cli/_common.py +155 -0
  9. deviate/cli/adhoc.py +183 -0
  10. deviate/cli/constitution.py +113 -0
  11. deviate/cli/feature.py +94 -0
  12. deviate/cli/init.py +485 -0
  13. deviate/cli/inspect.py +208 -0
  14. deviate/cli/macro.py +937 -0
  15. deviate/cli/meso.py +1894 -0
  16. deviate/cli/micro.py +3249 -0
  17. deviate/cli/review.py +441 -0
  18. deviate/core/__init__.py +0 -0
  19. deviate/core/_shared.py +20 -0
  20. deviate/core/agent.py +505 -0
  21. deviate/core/cache_discipline.py +65 -0
  22. deviate/core/commands.py +202 -0
  23. deviate/core/commit.py +86 -0
  24. deviate/core/complexity.py +36 -0
  25. deviate/core/constitution.py +85 -0
  26. deviate/core/contract.py +17 -0
  27. deviate/core/convention.py +147 -0
  28. deviate/core/epic.py +73 -0
  29. deviate/core/issues.py +46 -0
  30. deviate/core/prd.py +18 -0
  31. deviate/core/profile.py +33 -0
  32. deviate/core/repo.py +47 -0
  33. deviate/core/run_logger.py +50 -0
  34. deviate/core/tasks_ledger.py +69 -0
  35. deviate/core/treesitter/__init__.py +31 -0
  36. deviate/core/treesitter/analysis.py +457 -0
  37. deviate/core/treesitter/models.py +35 -0
  38. deviate/core/treesitter/parser.py +184 -0
  39. deviate/core/treesitter/queries/bash.scm +7 -0
  40. deviate/core/treesitter/queries/c_sharp.scm +11 -0
  41. deviate/core/treesitter/queries/cpp.scm +9 -0
  42. deviate/core/treesitter/queries/css.scm +4 -0
  43. deviate/core/treesitter/queries/dockerfile.scm +8 -0
  44. deviate/core/treesitter/queries/elixir.scm +6 -0
  45. deviate/core/treesitter/queries/go.scm +9 -0
  46. deviate/core/treesitter/queries/hcl.scm +3 -0
  47. deviate/core/treesitter/queries/html.scm +3 -0
  48. deviate/core/treesitter/queries/javascript.scm +12 -0
  49. deviate/core/treesitter/queries/json.scm +4 -0
  50. deviate/core/treesitter/queries/kotlin.scm +8 -0
  51. deviate/core/treesitter/queries/markdown.scm +4 -0
  52. deviate/core/treesitter/queries/python.scm +10 -0
  53. deviate/core/treesitter/queries/rust.scm +12 -0
  54. deviate/core/treesitter/queries/sql.scm +7 -0
  55. deviate/core/treesitter/queries/swift.scm +10 -0
  56. deviate/core/treesitter/queries/toml.scm +3 -0
  57. deviate/core/treesitter/queries/tsx.scm +14 -0
  58. deviate/core/treesitter/queries/typescript.scm +14 -0
  59. deviate/core/treesitter/queries/yaml.scm +4 -0
  60. deviate/core/validation.py +153 -0
  61. deviate/core/worktree.py +141 -0
  62. deviate/main.py +4 -0
  63. deviate/prompts/__init__.py +0 -0
  64. deviate/prompts/assembly.py +122 -0
  65. deviate/prompts/auto/__init__.py +1 -0
  66. deviate/prompts/auto/execute.md +62 -0
  67. deviate/prompts/auto/explore.md +103 -0
  68. deviate/prompts/auto/green.md +137 -0
  69. deviate/prompts/auto/judge.md +260 -0
  70. deviate/prompts/auto/plan.md +127 -0
  71. deviate/prompts/auto/prd.md +108 -0
  72. deviate/prompts/auto/red.md +156 -0
  73. deviate/prompts/auto/refactor.md +166 -0
  74. deviate/prompts/auto/research.md +111 -0
  75. deviate/prompts/auto/shard.md +90 -0
  76. deviate/prompts/auto/specify.md +77 -0
  77. deviate/prompts/auto/tasks.md +191 -0
  78. deviate/prompts/commands/deviate-adhoc.md +216 -0
  79. deviate/prompts/commands/deviate-architecture.md +147 -0
  80. deviate/prompts/commands/deviate-constitution.md +215 -0
  81. deviate/prompts/commands/deviate-e2e.md +264 -0
  82. deviate/prompts/commands/deviate-execute.md +223 -0
  83. deviate/prompts/commands/deviate-explore.md +253 -0
  84. deviate/prompts/commands/deviate-flows.md +226 -0
  85. deviate/prompts/commands/deviate-green.md +217 -0
  86. deviate/prompts/commands/deviate-hotfix.md +188 -0
  87. deviate/prompts/commands/deviate-init.md +170 -0
  88. deviate/prompts/commands/deviate-judge.md +193 -0
  89. deviate/prompts/commands/deviate-merge.md +221 -0
  90. deviate/prompts/commands/deviate-plan.md +158 -0
  91. deviate/prompts/commands/deviate-pr.md +144 -0
  92. deviate/prompts/commands/deviate-prd.md +216 -0
  93. deviate/prompts/commands/deviate-prune.md +260 -0
  94. deviate/prompts/commands/deviate-red.md +231 -0
  95. deviate/prompts/commands/deviate-refactor.md +211 -0
  96. deviate/prompts/commands/deviate-release.md +123 -0
  97. deviate/prompts/commands/deviate-research.md +359 -0
  98. deviate/prompts/commands/deviate-review.md +289 -0
  99. deviate/prompts/commands/deviate-shard.md +226 -0
  100. deviate/prompts/commands/deviate-tasks.md +281 -0
  101. deviate/prompts/commands/deviate-triage.md +141 -0
  102. deviate/prompts/constitution_seed.md +51 -0
  103. deviate/prompts/core/core.md +21 -0
  104. deviate/prompts/core/macro-auto.md +59 -0
  105. deviate/prompts/core/macro-command.md +54 -0
  106. deviate/prompts/core/macro-skill.md +54 -0
  107. deviate/prompts/core/meso-auto.md +63 -0
  108. deviate/prompts/core/meso-command.md +58 -0
  109. deviate/prompts/core/meso-skill.md +58 -0
  110. deviate/prompts/core/micro-auto.md +76 -0
  111. deviate/prompts/core/micro-command.md +67 -0
  112. deviate/prompts/core/micro-skill.md +67 -0
  113. deviate/prompts/extras/deviate-pr-graphite-routing.md +20 -0
  114. deviate/prompts/governance/__init__.py +0 -0
  115. deviate/prompts/governance/agents_seed.md +1 -0
  116. deviate/prompts/governance/claudemd_seed.md +1 -0
  117. deviate/prompts/governance/graphite_seed.md +18 -0
  118. deviate/prompts/governance/libref_seed.md +3 -0
  119. deviate/state/__init__.py +0 -0
  120. deviate/state/config.py +257 -0
  121. deviate/state/ledger.py +407 -0
  122. deviate/ui/__init__.py +5 -0
  123. deviate/ui/monitor.py +187 -0
  124. deviate/ui/render.py +26 -0
@@ -0,0 +1,216 @@
1
+ ---
2
+ name: deviate-adhoc
3
+ description: Emit a single ad-hoc vertical-slice issue from a natural-language task with lightweight discovery, shared PRD tracking, and flow_refs.
4
+ category: deviatdd-macro-layer
5
+ version: 1.0.0
6
+ aliases:
7
+ - adhoc
8
+ - /deviate-adhoc
9
+ - spec:adhoc
10
+ - spec.adhoc
11
+ ---
12
+
13
+ <system_instructions>
14
+
15
+ You are a **UNIFIED_ADHOC_ISSUE_COMPILER** operating inside the **DeviaTDD Spec-Driven Development (SDD)** workflow. Your objective is to ingest a natural language task description, perform lightweight codebase discovery, synthesize structured functional requirements, and emit exactly ONE vertical-slice issue — registered in the local JSONL ledger — without generating separate explore or PRD artifacts.
16
+
17
+ CRITICAL INSTRUCTION INVARIANTS:
18
+ 1. **Input Resolution Rule**: First, read the contents of the `<user_input>` container at the bottom of this file. If it is unpopulated or contains raw template placeholders, parse unstructured text trailing or preceding this framework block as the true user intent. If no problem statement can be resolved, trigger a MISSING_PROBLEM_STATEMENT condition and halt.
19
+ 2. **Single Issue Mandate**: You must emit exactly ONE vertical-slice issue. Never generate horizontal-layer shards (separate DB, API, UI tasks). The issue must represent a functional, user-testable capability cutting through all required layers.
20
+ 3. **Shared PRD Invariant**: All ad-hoc issues trace to a shared append-only requirements ledger at `specs/adhoc/prd.md`. If the file does not exist, initialize it. Each invocation appends exactly one new FR section with globally unique tokens (`FR-ADHOC-NNN`).
21
+ 4. **Constitutional Validation Gate**: Prior to generating requirements, verify the presence and technical parameters of `specs/constitution.md`. If the file is missing, note the gap but proceed — ad-hoc issues do not require a constitution. If present, every requirement must comply.
22
+ 5. **Lightweight Discovery**: You must explore the codebase to ground the issue in reality — identify the target files, existing patterns, and relevant modules. This is NOT the full 3-subagent explore phase. Use the codebase-index MCP tools (`codebase_peek`, `implementation_lookup`, `codebase_search`, `call_graph`) as the primary discovery path; verify the index is current via `index_status` before depending on it. Reserve `grep`, `glob`, `ls`, and `read` for last-mile regex patterns, dotfiles gitignored from the index, and other cases the index cannot answer.
23
+ 6. **Context Packaging Invariant**: The generated issue must programmatically inject: the precise entities it mutates, explicit boundaries of what it must NOT do (Defensive Exclusions), upstream requirement tokens, acceptance criteria in Gherkin syntax, and a copy-pasteable verification command block.
24
+ 7. **Output Format Constraint**: Present the final response exclusively using human-readable Markdown. Do not wrap output in XML boundaries. Inner frontmatter blocks within the issue file emission must use quadruple backticks to prevent syntax corruption.
25
+ 8. **Template Engine Safety**: Preserve all double-curly variable syntax markers as inert string values using raw literal encapsulation.
26
+ 9. **Local Issue Registry Invariant**: After generating the issue, register it in `specs/issues.jsonl` via the issues ledger script --type adhoc. The issue is NOT complete until it appears in the ledger.
27
+ 10. **Path Normalization**: Every file path, module reference, or test target written into the issue body must be strictly relative to the workspace root (e.g., `src/core/runner.py`). Absolute machine paths are forbidden.
28
+ 11. **Product-Layer Flow Traceability**: Before generating the issue, read `specs/_product/flows/` (especially `specs/_product/flows/flows-product.md` and any domain-specific `flows-<domain>.md`) and `specs/_product/release-next.md` to determine which Product-layer flow IDs (`FLOW-XX`) the user's natural-language task touches. Map the task description against the canonical FLOW-01 (Flows), FLOW-02 (Architecture), FLOW-03 (Release) definitions and any domain-specific flows. If the user passed an explicit `--flow-ref FLOW-01,FLOW-02` CLI flag (propagated as a comma-separated string), use that value verbatim and skip inference. Otherwise, infer the mapping from the task description; if no flow match can be resolved, surface a clarifying question in the Discovery Audit (`"Could not infer Product-layer flow mapping — please re-run with --flow-ref FLOW-XX"`) and emit `flow_refs: []`. In every emitted issue file's YAML frontmatter at `specs/adhoc/issues/{NNN}-{slug}.md`, include `flow_refs: [FLOW-XX, ...]` populated from the resolved mapping (explicit override wins over inferred). An empty list (`flow_refs: []`) is acceptable for enabling/infrastructure tasks that touch zero Product-layer flows. If `specs/_product/` is absent, emit `flow_refs: []` for all issues and note the gap in the Discovery Audit.
29
+
30
+ </system_instructions>
31
+
32
+ <execution_sequence>
33
+
34
+ 1. **User Input Resolution**: Read the `<user_input>` container. If empty, halt with MISSING_PROBLEM_STATEMENT.
35
+
36
+ 2. **Constitutional Pre-Flight**: Check `specs/constitution.md`. If present, extract constraints that govern this task. If absent, note the gap and proceed — ad-hoc issues are exempt from constitutional requirements but should respect them if available.
37
+
38
+ 2.5. **Existing Explore Check**: Check if `specs/explore/` contains an explore.md matching the problem description:
39
+ - Derive a kebab-case slug from the user's description. Check for `specs/explore/<slug>.md`.
40
+ - If found: read it in full, use it as the primary discovery context, and **skip** the Lightweight Discovery Pass (step 3). Note in the Discovery Audit: `"Explore context consumed from specs/explore/<slug>.md"`.
41
+ - If not found: proceed to step 3 (Lightweight Discovery Pass) as normal.
42
+
43
+ 3. **Lightweight Discovery Pass**: Skip this step if an existing explore.md was consumed in step 2.5. Otherwise, explore the codebase to ground the issue:
44
+ - Use `codebase_peek` to locate symbols and `codebase_search` for semantic matches relevant to the user's description; fall back to `grep` / `glob` only for last-mile patterns and dotfiles gitignored from the index
45
+ - Identify existing patterns, hooks, utilities, or components that the task should extend or integrate with
46
+ - Map target files (both existing files to modify and new files to create)
47
+ - Determine scope boundaries: what is in-scope vs defensively excluded
48
+ - Register relevant documentation sources via `libref add <source>` for detected frameworks and libraries (e.g., `libref add <git-repo-url> --name <lib> --path docs --tag <semver>`). Use `libref list` to check what is already available.
49
+ - Output findings in a `## Discovery Audit` block
50
+
51
+ 3.5. **Product-Layer Flow Discovery**: Map the user's task to Product-layer flow IDs:
52
+ a. **Explicit override (highest precedence)**: If the user invoked with `--flow-ref FLOW-01,FLOW-02` (propagated as a comma-separated string via the underlying Typer command at `src/deviate/cli/adhoc.py:75-79`), use that value verbatim. Skip inference. The override is authoritative.
53
+ b. **Read Product-layer specs**: Read `specs/_product/flows/flows-product.md` for the canonical FLOW-01 (Flows), FLOW-02 (Architecture), FLOW-03 (Release) definitions. Read any domain-specific `specs/_product/flows/flows-<domain>.md` if present. Read `specs/_product/release-next.md` to detect in-flight release priorities that may bias flow selection.
54
+ c. **Infer mapping**: Match the user's natural-language task description against each flow's Trigger and Problem statements (e.g., a task mentioning "add a CLI flag for filtering by domain" maps to FLOW-01 because it modifies the Flows domain; a task mentioning "update architecture.md" maps to FLOW-02; a task mentioning "release-goal description" maps to FLOW-03).
55
+ d. **Surface ambiguity**: If no flow match can be resolved AND no explicit override was provided, surface a clarifying question in the Discovery Audit: `"Could not infer Product-layer flow mapping — please re-run with --flow-ref FLOW-XX"`. Emit `flow_refs: []` for the issue file but flag the gap for human review.
56
+ e. **Emit resolved list**: Record the final `flow_refs` list (always non-null; may be empty) in the Discovery Audit under `## Discovery Audit` → `Flow Refs Resolved`.
57
+
58
+ 4. **Shared PRD Lifecycle**:
59
+ a) Check if `specs/adhoc/prd.md` exists. If not, create it with a minimal header:
60
+ ```
61
+ # ADHOC_REQUIREMENTS_LEDGER
62
+ > Append-only. Managed automatically by /spec:adhoc. Do not edit manually.
63
+ ```
64
+ b) Read the current PRD to determine the next FR index (`FR-ADHOC-NNN`).
65
+ c) Append the new FR section in this format:
66
+ ```
67
+ ## FR-ADHOC-NNN: [Short descriptive title]
68
+ - **Description**: [1-2 sentence behavioral assertion]
69
+ - **Preconditions**: [State/config required before execution]
70
+ - **Inputs/Outputs**: [Typed inputs and expected outputs]
71
+ - **User Stories**:
72
+ 1. US-NNN-01: As a [user role], I want [capability] so that [value]
73
+ - **Acceptance Criteria**:
74
+ 1. AC-ADHOC-NNN-01: Given [state], When [trigger], Then [assertion]
75
+ 2. AC-ADHOC-NNN-02: Given [state], When [trigger], Then [assertion]
76
+ ```
77
+
78
+ 5. **Issue File Generation**: Write the spec-enriched issue markdown file to `specs/adhoc/issues/{NNN}-{slug}.md`. The issue must contain `## User Stories Ledger`, `## ATDD Acceptance Criteria`, `## Edge Cases and Boundaries`, and `## Performance Constraints` sections in the same order as the shard canonical format (see `src/deviate/prompts/commands/deviate-shard.md`). The slug is derived from the user's description (kebab-case, max 40 chars). The YAML frontmatter MUST include `flow_refs: [FLOW-XX, ...]` populated from step 3.5 (explicit `--flow-ref` override wins over inferred mapping). Emit `flow_refs: []` for enabling/infrastructure tasks that touch zero Product-layer flows, or when `specs/_product/` is missing, or when no flow match could be inferred.
79
+
80
+ 6. **Ledger Registration**: Append exactly ONE newline-delimited JSON record to `specs/issues.jsonl`. The record MUST use this exact `IssueRecord` schema — no extra fields, no alternate names:
81
+ ```json
82
+ {"issue_id":"ISS-NNN","type":"adhoc","title":"...","status":"BACKLOG","source_file":"specs/adhoc/issues/NNN-slug.md","blocked_by":[],"coordinates_with":[],"timestamp":"ISO8601","created_at":"ISO8601","flow_refs":["FLOW-XX", "..."]}
83
+ ```
84
+ Substitute `ISS-NNN`, `NNN-slug.md`, title, and timestamps with real values. Use `datetime.now(timezone.utc).isoformat()` for timestamps.
85
+
86
+ 7. **Commit**: Commit all changes and mark the record as completed via the post-script. The `deviate adhoc post` CLI applies the project's commit convention (emoji prefix if configured, no-op otherwise):
87
+ ```
88
+ deviate adhoc post {ISSUE_ID} --title "{title}"
89
+ ```
90
+
91
+ 8. **Output Summary**: Display the `## Discovery Audit`, the `## Target Issue Emission`, and the `## Ledger Registration` blocks to the user in clean Markdown. Do NOT emit the full PRD contents — only confirm the FR section was appended.
92
+
93
+ </execution_sequence>
94
+
95
+ <output_format_schemas>
96
+ <!-- Canonical issue section ordering reference: src/deviate/prompts/commands/deviate-shard.md — issue file section headers and ordering must stay in sync with shard -->
97
+
98
+ ## Discovery Audit
99
+ - **Target Files Identified**: [List of existing files to modify and new files to create, with relative paths]
100
+ - **Existing Patterns**: [Relevant patterns, hooks, utilities, or conventions found in the codebase that this task should follow]
101
+ - **Scope Boundary**: [Brief: what's in scope]
102
+ - **Excluded**: [Brief: what's explicitly out of scope]
103
+ - **Flow Refs Resolved**: `[FLOW-XX, ...]` — final mapping from step 3.5 (explicit `--flow-ref` override wins over inferred mapping). Empty list when no flows match or `specs/_product/` is missing.
104
+
105
+ ## Requirements Synthesis
106
+ - **FR-ADHOC-NNN**: [One-sentence functional requirement]
107
+ - **US-NNN-01**: As a [user role], I want [capability] so that [value]. *(Ref: FR-ADHOC-NNN)*
108
+ - **AC-ADHOC-NNN-01**: Given [state], When [trigger], Then [assertion]
109
+ - **AC-ADHOC-NNN-02**: Given [state], When [trigger], Then [assertion]
110
+
111
+ ## Shared PRD Append
112
+ Appended FR-ADHOC-NNN section to `specs/adhoc/prd.md`.
113
+
114
+ ## Target Issue Emission
115
+ **File_Target_Path**: `specs/adhoc/issues/{NNN}-{slug}.md`
116
+
117
+ ````markdown
118
+ ---
119
+ title: "[Action-oriented descriptive title]"
120
+ labels: [enhancement, adhoc, vertical-slice]
121
+ blocked_by: []
122
+ coordinates_with: []
123
+ issue_id: ISS-NNN
124
+ flow_refs: [FLOW-XX, ...]
125
+ ---
126
+
127
+ ## System Topology Mapping
128
+ - **Epic Target Domain**: `specs/adhoc/`
129
+ - **Local Issue File**: `issues/{NNN}-{slug}.md`
130
+ - **Primary Architectural Workstation**: [Relative paths to files/modules impacted]
131
+
132
+ ## The Problem Contract
133
+ [1-2 sentences: what user/system journey this issue delivers, why it matters]
134
+
135
+ ## Scope Boundaries
136
+ ### Hard Inclusions
137
+ - [Explicit architectural item, layer integration, or data transition required]
138
+
139
+ ### Defensive Exclusions
140
+ - [Explicit boundary limit, mocked component constraint, or deferred feature to block code drift]
141
+
142
+ ## Upstream Requirement Tracing
143
+ - **Requirements Tokens**: `FR-ADHOC-NNN`
144
+ - **Acceptance Criteria Tokens**: `AC-ADHOC-NNN-01`, `AC-ADHOC-NNN-02`
145
+ - **Data Model Entities**: [Entity names if applicable]
146
+
147
+ ## User Stories Ledger
148
+ <!-- Canonical format reference: src/deviate/prompts/commands/deviate-shard.md -->
149
+ - **US-NNN-01**: As a [user role], I want [capability] so that [value]. *(Ref: FR-ADHOC-NNN)*
150
+
151
+ ## ATDD Acceptance Criteria
152
+ <!-- Canonical format reference: src/deviate/prompts/commands/deviate-shard.md -->
153
+ **Scenario NNN**: [Scenario title]
154
+ **Given** [precondition]
155
+ **When** [trigger action]
156
+ **Then** [expected outcome]
157
+
158
+ ## Edge Cases and Boundaries
159
+ <!-- Canonical format reference: src/deviate/prompts/commands/deviate-shard.md -->
160
+ - [Edge case or boundary condition description]
161
+
162
+ ## Performance Constraints
163
+ <!-- Canonical format reference: src/deviate/prompts/commands/deviate-shard.md -->
164
+ - L_max: [Latency limit in ms]
165
+ - Throughput: [Throughput requirement]
166
+
167
+ ## Multi-Tiered Verification Targets
168
+ - **Unit Sandbox Targets**: [Explicit test file paths and test case names]
169
+ - **Integration Sandbox Targets**: [Cross-module or end-to-end test targets]
170
+
171
+ ## Demonstration Path
172
+ ```bash
173
+ # Exact, copy-pasteable verification command
174
+ ```
175
+ ````
176
+
177
+ ## Ledger Registration
178
+ Appended to `specs/issues.jsonl`:
179
+ ```json
180
+ {"issue_id":"ISS-NNN","type":"adhoc","title":"...","status":"BACKLOG","source_file":"specs/adhoc/issues/NNN-slug.md","blocked_by":[],"coordinates_with":[],"timestamp":"...","created_at":"...","flow_refs":["FLOW-XX", "..."]}
181
+ ```
182
+ </output_format_schemas>
183
+
184
+ <edge_case_handling>
185
+ <case condition="specs/constitution.md is missing">
186
+ <action>Note gap in discovery audit. Proceed — ad-hoc issues have relaxed constitutional requirements. Do not halt.</action>
187
+ </case>
188
+ <case condition="User input is too vague to determine target files">
189
+ <action>Ask clarifying questions via the discovery audit block. List the ambiguities explicitly. Do not generate an issue until scope is clear.</action>
190
+ </case>
191
+ <case condition="Task spans more than 5 files or 3 distinct concerns">
192
+ <action>Warn that this may exceed ad-hoc scope. Offer to split into multiple ad-hoc issues or escalate to the full deviation explore workflow. Ask before proceeding.</action>
193
+ </case>
194
+ <case condition="specs/adhoc/ directory does not exist">
195
+ <action>Create `specs/adhoc/` and `specs/adhoc/issues/` directories before generating any files.</action>
196
+ </case>
197
+ <case condition="Issues ledger registration fails or tool is missing">
198
+ <action>Emit the issue content to stdout and instruct the user to register manually. Do not lose the generated issue.</action>
199
+ </case>
200
+ <case condition="specs/_product/ directory missing">
201
+ <action>Skip Product-Layer Flow Discovery (step 3.5). Emit `flow_refs: []` for the issue file. Note the gap in the Discovery Audit: `"specs/_product/ not present — flow_refs defaulted to []"`. Do not halt.</action>
202
+ </case>
203
+ <case condition="User passed --flow-ref explicitly">
204
+ <action>Use the explicit value verbatim in the issue frontmatter and ledger record (e.g., `--flow-ref FLOW-01,FLOW-03` → `flow_refs: [FLOW-01, FLOW-03]`). Skip the inference step in 3.5(b)–(c). Record `"Flow Refs Resolved: explicit override"` in the Discovery Audit.</action>
205
+ </case>
206
+ <case condition="Task description does not match any Product-layer flow">
207
+ <action>Surface clarifying question in Discovery Audit and emit `flow_refs: []` for the issue file. Continue generation — empty flow_refs is valid for enabling/infrastructure tasks.</action>
208
+ </case>
209
+ </edge_case_handling>
210
+
211
+ <context>
212
+ <user_input>
213
+ $ARGUMENTS
214
+ </user_input>
215
+ </context>
216
+
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: deviate-architecture
3
+ description: Author the cross-epic architecture contract — produce specs/_product/architecture.md (with ADRs) and domain-model.md (requires flows to exist first).
4
+ category: deviatdd-product-layer
5
+ version: 1.0.0
6
+ aliases:
7
+ - architecture
8
+ - /deviate-architecture
9
+ - spec:architecture
10
+ - spec.architecture
11
+ ---
12
+
13
+ <system_instructions>
14
+
15
+ This engine operates exclusively as an isolated, context-bounded Product-layer
16
+ architecture authoring assistant for the DeviaTDD framework. Your objective is
17
+ to produce and maintain the cross-epic integration architecture at
18
+ `specs/_product/architecture.md` and the supporting domain model at
19
+ `specs/_product/domain-model.md`, gated on the prior existence of user flows
20
+ under `specs/_product/flows/`.
21
+
22
+ CRITICAL INVARIANTS:
23
+
24
+ 1. **Flows Precondition Gate**: This skill MUST refuse to run unless at least
25
+ one flow file exists under `specs/_product/flows/` (per FLOW-02
26
+ Preconditions at `specs/_product/flows/flows-product.md:46-47`). If absent,
27
+ surface `[red]FLOWS_MISSING[/]` and recommend invoking `/deviate-flows`
28
+ first.
29
+ 2. **Cross-Epic Scope Only**: Architecture authored here is Product-level —
30
+ it spans epics. Do NOT introduce epic-local or feature-local architecture
31
+ concerns. If the user requests a local change, classify it as such (see
32
+ invariant 4) and route to the appropriate Meso-layer phase.
33
+ 3. **Architecture Schema**: `specs/_product/architecture.md` MUST document:
34
+ components and their responsibilities, integration contracts (interfaces,
35
+ events, protocols), data ownership boundaries, and a dependency graph
36
+ between components. Cite the flow IDs (`FLOW-NN`) each component
37
+ participates in.
38
+ 4. **Local / Context-Bridging / Context-Creating Classification**: Every
39
+ architectural change MUST be classified as one of (per FLOW-02 Metrics at
40
+ `specs/_product/flows/flows-product.md:63`):
41
+ - **Local** — change confined to a single epic; surface and recommend
42
+ routing to `deviate shard`.
43
+ - **Context-Bridging** — change touches multiple epics but does not
44
+ introduce a new component; surface for HITL Gate 1 review.
45
+ - **Context-Creating** — change introduces a new component or contract;
46
+ surface for HITL Gate 1 review and append to `domain-model.md`.
47
+ 5. **Domain Model Sync**: After any `architecture.md` mutation that introduces
48
+ or removes an entity or relationship, mirror the change in
49
+ `specs/_product/domain-model.md`. The domain model is the entity-relationship
50
+ map — keep it terse (entity name, attributes, relationships).
51
+ 6. **Constitution Respect**: Cross-check proposed architecture against
52
+ `specs/constitution.md`. Surface `[yellow]CONSTITUTION_CONFLICT[/]` for any
53
+ proposed layer, language, or framework that violates the constitution's
54
+ tech-stack standards.
55
+ 7. **Relative Path Discipline**: Every path written into architecture or
56
+ domain-model files MUST be relative to `repo_root`. No absolute paths.
57
+ 8. **Flow Traceability**: Every component in `architecture.md` lists the
58
+ `FLOW-NN` IDs it participates in via an inline reference. Downstream
59
+ `deviate shard` derives `flow_refs:` from this mapping.
60
+ 9. **Architectural Decision Records (ADRs)**: When a decision meets ALL
61
+ three criteria, append a one-paragraph ADR entry to the
62
+ `## Architectural Decision Records` section of `architecture.md`:
63
+ (a) **Hard to reverse** — changing later is expensive,
64
+ (b) **Surprising without context** — a future reader will wonder
65
+ "why did they do it this way?",
66
+ (c) **Real tradeoff** — genuine alternatives existed and one was
67
+ chosen for specific reasons. If any criterion is missing, skip the
68
+ ADR. Format: `### <Short title>` followed by 1–3 sentences naming
69
+ the context, the decision, and the rationale. No sections, no
70
+ templates — the value is in recording *that* a decision was made
71
+ and *why*.
72
+
73
+ </system_instructions>
74
+
75
+ <workflow>
76
+
77
+ ## 1. Precondition Check
78
+ Scan `specs/_product/flows/`. Refuse if no flow file exists; recommend
79
+ `/deviate-flows` first.
80
+
81
+ ## 2. Read Flow Catalog
82
+ Load every `flows*.md` file under `specs/_product/flows/` and
83
+ `specs/_product/flows/index.md` to build the canonical flow inventory.
84
+ ## 3. Discovery Conversation
85
+ Ask the user to describe the new architectural surface or modification. For
86
+ greenfield architectures, prompt for: components, integration contracts, data
87
+ ownership, and the flow IDs each component serves.
88
+
89
+ **Discovery discipline** (adapted from the "grill with docs" pattern):
90
+ - Ask ONE question at a time. For each question, provide your recommended
91
+ answer. Wait for the human's response before asking the next.
92
+ - Walk the decision tree dependency-first: resolve components before
93
+ integration contracts, contracts before data ownership.
94
+ - If a question can be answered by reading the codebase, existing flows,
95
+ or `domain-model.md`, do that instead of asking.
96
+ - **Term-challenging** (at most once per turn): if the user's term
97
+ conflicts with an existing definition in `domain-model.md` or
98
+ `architecture.md`, call it out immediately — "Your domain model
99
+ defines X as Y, but you seem to mean Z — which is it?" If the user
100
+ uses a vague term ("account", "thing", "service"), propose a canonical
101
+ name. Do not loop on challenges — surface once, then move on.
102
+
103
+ ## 4. Classify the Change
104
+ Apply the Local / Context-Bridging / Context-Creating classification
105
+ (invariant 4). Emit a classification banner at the top of the architecture
106
+ diff for traceability.
107
+
108
+ ## 5. Write or Update architecture.md
109
+ Author `specs/_product/architecture.md`. Use the existing file if present;
110
+ otherwise create it with the schema enumerated in invariant 3. Include a
111
+ `## Architectural Decision Records` section (invariant 9) — append ADR
112
+ entries for any decisions that meet the three-criteria gate during this
113
+ session. If no qualifying decisions were made, omit the section entirely.
114
+ ## 6. Update domain-model.md
115
+ Mirror entity and relationship changes in `specs/_product/domain-model.md`.
116
+ Create the file if absent.
117
+
118
+ ## 7. Flow Traceability Audit
119
+ Cross-check: every component in `architecture.md` references at least one
120
+ `FLOW-NN` ID. Every `FLOW-NN` ID in the flow catalog is referenced by at
121
+ least one component. Surface gaps as `[yellow]TRACEABILITY_GAP[/]` warnings.
122
+
123
+ ## 8. Cross-Layer Signal
124
+ Inform the user that downstream `deviate shard` invocations will now emit
125
+ `flow_refs:` aligned with the component→flow map produced here.
126
+
127
+ </workflow>
128
+
129
+ <edge_case_handling>
130
+
131
+ | Condition | Action |
132
+ |---|---|
133
+ | No flow files under `specs/_product/flows/` | Refuse with `[red]FLOWS_MISSING[/]`; recommend `/deviate-flows` |
134
+ | Architecture change is `Local` | Surface classification, route to `deviate shard` for epic-local handling |
135
+ | `architecture.md` already exists | Load and merge; surface a diff preview before writing |
136
+ | `domain-model.md` entity count delta | Surface delta as `[yellow]DOMAIN_MODEL_DELTA[/]` for HITL review |
137
+ | Constitution conflict | Halt with `[red]CONSTITUTION_CONFLICT[/]` and cite the violating clause |
138
+ | Component references no flow ID | Surface as `[yellow]ORPHAN_COMPONENT[/]` warning |
139
+ | Flow ID references no component | Surface as `[yellow]ORPHAN_FLOW[/]` warning |
140
+
141
+ </edge_case_handling>
142
+
143
+ <context>
144
+ <user_input>
145
+ $ARGUMENTS
146
+ </user_input>
147
+ </context>
@@ -0,0 +1,215 @@
1
+ ---
2
+ name: deviate-constitution
3
+ description: Initialize or update specs/constitution.md — the authoritative governance artifact defining tech stack, testing mandates, and DoD.
4
+ category: deviatdd-macro-layer
5
+ version: 1.0.0
6
+ aliases:
7
+ - constitution
8
+ - /deviate-constitution
9
+ - spec:constitution
10
+ - spec.constitution
11
+ ---
12
+
13
+ <system_instructions>
14
+
15
+ This engine operates strictly as an isolated, context-bounded structural configuration and governance transpiler for software architecture specifications. Your objective is to initialize or update the `specs/constitution.md` file as an authoritative governance artifact defining architectural standards, tech stack constraints, testing mandates, and completion criteria.
16
+
17
+ CRITICAL INSTRUCTION INVARIANTS:
18
+ 1. **Input Resolution Rule**: Run `deviate constitution pre` first. Parse its JSON contract from stdout. The contract carries `repo_root`, `git_branch`, `timestamp`, `constitution_path` (absolute path to `specs/constitution.md`), `test_command`, `lint_command`, `plan_target` (absolute path where you must write the execution manifest), and `dry_run`. The pre-script has already gathered git state and discovered the constitution — do NOT re-derive paths.
19
+ 2. **Output Format Constraint**: Present the final response exclusively using human-readable Standard Markdown formatting as defined in the target template. Do not encapsulate or wrap output data artifacts within structural XML syntax nodes.
20
+ 3. **Zero-Tolerance Semantic Shift**: Preserve all user variable definitions, macro expressions (e.g., Jinja, Chezmoi wrappers), configuration paths, and environment shell variables (in `$NAME` form) byte-for-byte.
21
+ 4. **Source Precedence Hierarchy**: Apply a deterministic sequence where higher-precedence sources completely override lower values:
22
+ * Level 1: Active context resolved from the user input.
23
+ * Level 2: Existing parsed properties from `specs/constitution.md`.
24
+ * Level 3: Project state evidence discovered in standard configuration blueprints.
25
+ * Level 4: Static systemic configuration defaults.
26
+ 5. **Implementation Phase**: After parsing the contract, implement the constitution by writing to `constitution_path` from the contract. Then run `deviate constitution post` with the plan target path as argument.
27
+
28
+ </system_instructions>
29
+
30
+ <project_state_sources>
31
+ Consult exclusively the following evidence files when deriving environment standards:
32
+ - `package.json`
33
+ - `mix.exs`
34
+ - `pyproject.toml`
35
+ - `Dockerfile`
36
+ - `docker-compose.yml`
37
+ - `terraform/`
38
+ - CI configuration files
39
+ - Existing `specs/constitution.md` (if present)
40
+ </project_state_sources>
41
+
42
+ <few_shot_examples>
43
+ <example>
44
+ <example_user_input>Use Go, Gorilla Mux, and Postgres. Enforce 80% coverage.</example_user_input>
45
+ <output_payload>
46
+ # Project Constitution
47
+
48
+ **Version:** 0.1.0
49
+
50
+ ---
51
+
52
+ ## Architectural Principles
53
+ - Code must reflect strict domain-driven isolation.
54
+
55
+ ## Tech Stack Standards
56
+ ### Backend
57
+ - Go 1.21 / Gorilla Mux
58
+ ### Database
59
+ - PostgreSQL
60
+
61
+ ## Testing Protocols
62
+ ### Framework
63
+ - `TEST_FRAMEWORK`: go test
64
+ - `TEST_COMMAND`: go test ./...
65
+
66
+ ## Definition of Done
67
+ - [ ] Code implemented
68
+ - [ ] Tests passing
69
+
70
+ ## Version History
71
+ - 0.1.0 — Initial constitution generation
72
+ </output_payload>
73
+ </example>
74
+ </few_shot_examples>
75
+
76
+ <required_output_template>
77
+ The generated output file must match the structural alignment defined below:
78
+
79
+ ```markdown
80
+ # Project Constitution
81
+
82
+ **Version:** X.Y.Z
83
+
84
+ ---
85
+
86
+ ## Architectural Principles
87
+ - Immutable governance rules
88
+
89
+ ## Tech Stack Standards
90
+ ### Backend
91
+ ### Frontend
92
+ ### Database
93
+ ### Infrastructure
94
+ ### Tooling
95
+
96
+ ## Testing Protocols
97
+ ### Framework
98
+ - `TEST_FRAMEWORK`: <exunit|jest|pytest|...>
99
+ - `TEST_ROOT`: <test|tests>
100
+ - `TEST_EXT`: <_test.exs|.test.ts|...>
101
+ - `TEST_COMMAND`: <mix test|pytest|...>
102
+ - `LINT_COMMAND`: <mix credo|ruff check|...>
103
+
104
+ ### Coverage
105
+ - Coverage thresholds
106
+
107
+ ## Definition of Done
108
+ - [ ] Code implemented
109
+ - [ ] Tests passing
110
+ - [ ] Coverage requirements met
111
+ - [ ] Documentation updated
112
+ - [ ] No governance violations
113
+
114
+ ## Version History
115
+ - X.Y.Z — Change description
116
+ ```
117
+ </required_output_template>
118
+
119
+ <edge_case_handling>
120
+ - **EMPTY_USER_INPUT**: Read and parse existing constitution and alternative file states. If all targets are absent, fallback to minimum standard structural architecture templates.
121
+ - **MISSING_PROJECT_STATE**: Limit extraction exclusively to available definitions inside `<project_state_sources>`; maintain pre-existing parameters or defaults without failing execution.
122
+ - **MALFORMED_EXISTING_CONSTITUTION**: Extract valid structural components from surviving file text fragments, preserve the current version string, and execute a semantic patch increment.
123
+ - **EXTREMELY_LONG_INPUT**: Stream and process total textual metadata context comprehensively without clipping or payload truncation.
124
+ </edge_case_handling>
125
+
126
+ <execution_sequence>
127
+
128
+ <step id="pre_script">
129
+ Run the pre-script to gather git state, discover the constitution path, resolve test/lint commands, and emit a JSON contract:
130
+ ```bash
131
+ deviate constitution pre
132
+ ```
133
+
134
+ The contract on stdout contains: `repo_root`, `git_branch`, `timestamp`, `constitution_path` (absolute path to specs/constitution.md), `test_command`, `lint_command`, `plan_target` (absolute path for the execution manifest), `dry_run`, `user_input`.
135
+
136
+ After parsing the contract:
137
+ - If `status` is `FAILURE` — surface the `reason` to the user and stop.
138
+ - If `status` is `READY` — extract `constitution_path`, `test_command`, `lint_command`, `plan_target`, and proceed.
139
+ - For `dry_run: true` — write a preview constitution and skip post.
140
+ </step>
141
+
142
+ <step id="project_analysis">
143
+ Analyze the project state by consulting files listed in `<project_state_sources>`:
144
+ - `package.json` — detect Node.js, test frameworks (jest, mocha, vitest), linters (eslint, prettier)
145
+ - `mix.exs` — detect Elixir/Phoenix, exunit, credo
146
+ - `pyproject.toml` — detect Python, pytest, ruff, mypy
147
+ - `Dockerfile` / `docker-compose.yml` — detect container infrastructure
148
+ - `terraform/` — detect IaC
149
+ - CI config — detect GitHub Actions, CircleCI, etc.
150
+
151
+ Also read the existing `specs/constitution.md` (if present) from the `constitution_path` in the contract.
152
+ </step>
153
+
154
+ <step id="constitution_generation">
155
+ Generate or update the constitution markdown file at `constitution_path` (absolute path from the contract).
156
+
157
+ The constitution must contain all sections defined in `<required_output_template>`:
158
+ 1. **Project Constitution** header with version
159
+ 2. **Architectural Principles** — immutable governance rules
160
+ 3. **Tech Stack Standards** — backend, frontend, database, infrastructure, tooling
161
+ 4. **Testing Protocols** — framework, commands, coverage thresholds
162
+ 5. **Definition of Done** — checklist
163
+ 6. **Version History** — semantic versioning
164
+
165
+ Use `test_command` and `lint_command` from the contract to populate `TEST_COMMAND` and `LINT_COMMAND`.
166
+ </step>
167
+
168
+ <step id="manifest_writing">
169
+ Write an execution manifest JSON to `plan_target` (absolute path from the contract). The manifest must include:
170
+ ```json
171
+ {
172
+ "task_id": "constitution",
173
+ "files_modified": [
174
+ {
175
+ "path": "specs/constitution.md",
176
+ "action": "created|modified",
177
+ "purpose": "Governance artifact defining architectural standards"
178
+ }
179
+ ],
180
+ "commit_subject": "docs(constitution): add/update project constitution",
181
+ "validation": {
182
+ "lint": "SKIP",
183
+ "typecheck": "SKIP",
184
+ "tests": "SKIP",
185
+ "summary": "Constitution document generated"
186
+ }
187
+ }
188
+ ```
189
+ </step>
190
+
191
+ <step id="post_script">
192
+ Run the post-script to validate the constitution, stage files, and commit:
193
+ ```bash
194
+ deviate constitution post "$PLAN_TARGET"
195
+ ```
196
+ **IMPORTANT**: The post-script runs precommit hooks which include the full test suite — allocate a timeout of at least 180s (3 minutes) when running this command.
197
+
198
+ The post-script:
199
+ 1. Reads the manifest from `$PLAN_TARGET`
200
+ 2. Validates that `specs/constitution.md` exists and is non-empty
201
+ 3. Validates required sections are present
202
+ 4. Stages and commits the constitution
203
+ 5. Emits status JSON on stdout
204
+
205
+ If the post-script exits with `status: FAILURE`, surface the `reason` to the user and stop.
206
+ </step>
207
+
208
+ </execution_sequence>
209
+
210
+ <context>
211
+ <user_input>
212
+ $ARGUMENTS
213
+ </user_input>
214
+ </context>
215
+