phi-redactor 0.1.0__tar.gz

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 (146) hide show
  1. phi_redactor-0.1.0/.claude/commands/sp.adr.md +207 -0
  2. phi_redactor-0.1.0/.claude/commands/sp.analyze.md +210 -0
  3. phi_redactor-0.1.0/.claude/commands/sp.checklist.md +320 -0
  4. phi_redactor-0.1.0/.claude/commands/sp.clarify.md +207 -0
  5. phi_redactor-0.1.0/.claude/commands/sp.constitution.md +108 -0
  6. phi_redactor-0.1.0/.claude/commands/sp.git.commit_pr.md +328 -0
  7. phi_redactor-0.1.0/.claude/commands/sp.implement.md +161 -0
  8. phi_redactor-0.1.0/.claude/commands/sp.phr.md +195 -0
  9. phi_redactor-0.1.0/.claude/commands/sp.plan.md +115 -0
  10. phi_redactor-0.1.0/.claude/commands/sp.reverse-engineer.md +1612 -0
  11. phi_redactor-0.1.0/.claude/commands/sp.specify.md +284 -0
  12. phi_redactor-0.1.0/.claude/commands/sp.tasks.md +163 -0
  13. phi_redactor-0.1.0/.claude/commands/sp.taskstoissues.md +56 -0
  14. phi_redactor-0.1.0/.claude/settings.local.json +32 -0
  15. phi_redactor-0.1.0/.env.example +27 -0
  16. phi_redactor-0.1.0/.github/workflows/ci.yml +73 -0
  17. phi_redactor-0.1.0/.gitignore +43 -0
  18. phi_redactor-0.1.0/.specify/memory/constitution.md +55 -0
  19. phi_redactor-0.1.0/.specify/scripts/powershell/check-prerequisites.ps1 +148 -0
  20. phi_redactor-0.1.0/.specify/scripts/powershell/common.ps1 +137 -0
  21. phi_redactor-0.1.0/.specify/scripts/powershell/create-new-feature.ps1 +288 -0
  22. phi_redactor-0.1.0/.specify/scripts/powershell/setup-plan.ps1 +61 -0
  23. phi_redactor-0.1.0/.specify/scripts/powershell/update-agent-context.ps1 +448 -0
  24. phi_redactor-0.1.0/.specify/templates/adr-template.md +56 -0
  25. phi_redactor-0.1.0/.specify/templates/agent-file-template.md +28 -0
  26. phi_redactor-0.1.0/.specify/templates/checklist-template.md +40 -0
  27. phi_redactor-0.1.0/.specify/templates/phr-template.prompt.md +45 -0
  28. phi_redactor-0.1.0/.specify/templates/plan-template.md +104 -0
  29. phi_redactor-0.1.0/.specify/templates/spec-template.md +115 -0
  30. phi_redactor-0.1.0/.specify/templates/tasks-template.md +251 -0
  31. phi_redactor-0.1.0/CLAUDE.md +210 -0
  32. phi_redactor-0.1.0/LICENSE +190 -0
  33. phi_redactor-0.1.0/PKG-INFO +306 -0
  34. phi_redactor-0.1.0/README.md +262 -0
  35. phi_redactor-0.1.0/SECURITY.md +78 -0
  36. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/001-phi-redactor-spec-creation.spec.prompt.md +48 -0
  37. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/002-architecture-plan-creation.plan.prompt.md +60 -0
  38. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/002-architecture-technology-research.general.prompt.md +85 -0
  39. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/002-hipaa-compliance-audit-trail-research.general.prompt.md +77 -0
  40. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/002-llm-api-proxy-architecture-research.general.prompt.md +89 -0
  41. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/003-task-generation-implementation.tasks.prompt.md +47 -0
  42. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/004-shared-models-and-config-implementation.green.prompt.md +108 -0
  43. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/005-detection-engine-and-registry-implementation.green.prompt.md +146 -0
  44. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/005-semantic-masking-engine-implementation.green.prompt.md +77 -0
  45. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/006-vault-and-audit-implementation.green.prompt.md +111 -0
  46. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/007-cli-entry-points-implementation.green.prompt.md +75 -0
  47. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/008-proxy-layer-fastapi-implementation.green.prompt.md +80 -0
  48. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/009-write-seven-test-files.green.prompt.md +80 -0
  49. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/010-session-config-cli-vault-safe-harbor.green.prompt.md +104 -0
  50. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/011-dashboard-polish-phase-11-12.green.prompt.md +77 -0
  51. phi_redactor-0.1.0/history/prompts/001-phi-redaction-proxy/012-fhir-hl7-plugin-system-phase-9-10.green.prompt.md +85 -0
  52. phi_redactor-0.1.0/history/prompts/general/001-phi-redaction-market-research.general.prompt.md +56 -0
  53. phi_redactor-0.1.0/mypy.ini +19 -0
  54. phi_redactor-0.1.0/pyproject.toml +67 -0
  55. phi_redactor-0.1.0/ruff.toml +14 -0
  56. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/checklists/requirements.md +43 -0
  57. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/contracts/openapi.yaml +752 -0
  58. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/data-model.md +194 -0
  59. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/plan.md +362 -0
  60. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/quickstart.md +191 -0
  61. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/research.md +151 -0
  62. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/spec.md +268 -0
  63. phi_redactor-0.1.0/specs/001-phi-redaction-proxy/tasks.md +430 -0
  64. phi_redactor-0.1.0/src/phi_redactor/__init__.py +71 -0
  65. phi_redactor-0.1.0/src/phi_redactor/__main__.py +6 -0
  66. phi_redactor-0.1.0/src/phi_redactor/audit/__init__.py +7 -0
  67. phi_redactor-0.1.0/src/phi_redactor/audit/reports.py +416 -0
  68. phi_redactor-0.1.0/src/phi_redactor/audit/trail.py +278 -0
  69. phi_redactor-0.1.0/src/phi_redactor/cli/__init__.py +5 -0
  70. phi_redactor-0.1.0/src/phi_redactor/cli/config.py +108 -0
  71. phi_redactor-0.1.0/src/phi_redactor/cli/main.py +101 -0
  72. phi_redactor-0.1.0/src/phi_redactor/cli/plugins.py +54 -0
  73. phi_redactor-0.1.0/src/phi_redactor/cli/redact.py +86 -0
  74. phi_redactor-0.1.0/src/phi_redactor/cli/report.py +159 -0
  75. phi_redactor-0.1.0/src/phi_redactor/cli/serve.py +91 -0
  76. phi_redactor-0.1.0/src/phi_redactor/cli/sessions.py +122 -0
  77. phi_redactor-0.1.0/src/phi_redactor/config.py +260 -0
  78. phi_redactor-0.1.0/src/phi_redactor/dashboard/__init__.py +1 -0
  79. phi_redactor-0.1.0/src/phi_redactor/dashboard/routes.py +58 -0
  80. phi_redactor-0.1.0/src/phi_redactor/dashboard/static/index.html +121 -0
  81. phi_redactor-0.1.0/src/phi_redactor/detection/__init__.py +15 -0
  82. phi_redactor-0.1.0/src/phi_redactor/detection/engine.py +230 -0
  83. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/__init__.py +47 -0
  84. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/account.py +69 -0
  85. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/biometric.py +71 -0
  86. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/device.py +82 -0
  87. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/fax.py +58 -0
  88. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/fhir.py +44 -0
  89. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/health_plan.py +75 -0
  90. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/hl7.py +25 -0
  91. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/license.py +116 -0
  92. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/mrn.py +59 -0
  93. phi_redactor-0.1.0/src/phi_redactor/detection/recognizers/vehicle.py +64 -0
  94. phi_redactor-0.1.0/src/phi_redactor/detection/registry.py +197 -0
  95. phi_redactor-0.1.0/src/phi_redactor/masking/__init__.py +3 -0
  96. phi_redactor-0.1.0/src/phi_redactor/masking/clustering.py +135 -0
  97. phi_redactor-0.1.0/src/phi_redactor/masking/date_shifter.py +162 -0
  98. phi_redactor-0.1.0/src/phi_redactor/masking/identity.py +139 -0
  99. phi_redactor-0.1.0/src/phi_redactor/masking/providers.py +56 -0
  100. phi_redactor-0.1.0/src/phi_redactor/masking/semantic.py +246 -0
  101. phi_redactor-0.1.0/src/phi_redactor/models.py +271 -0
  102. phi_redactor-0.1.0/src/phi_redactor/plugins/__init__.py +11 -0
  103. phi_redactor-0.1.0/src/phi_redactor/plugins/example_plugin.py +43 -0
  104. phi_redactor-0.1.0/src/phi_redactor/plugins/loader.py +106 -0
  105. phi_redactor-0.1.0/src/phi_redactor/proxy/__init__.py +0 -0
  106. phi_redactor-0.1.0/src/phi_redactor/proxy/adapters/__init__.py +0 -0
  107. phi_redactor-0.1.0/src/phi_redactor/proxy/adapters/anthropic.py +292 -0
  108. phi_redactor-0.1.0/src/phi_redactor/proxy/adapters/base.py +100 -0
  109. phi_redactor-0.1.0/src/phi_redactor/proxy/adapters/openai.py +241 -0
  110. phi_redactor-0.1.0/src/phi_redactor/proxy/app.py +160 -0
  111. phi_redactor-0.1.0/src/phi_redactor/proxy/routes/__init__.py +0 -0
  112. phi_redactor-0.1.0/src/phi_redactor/proxy/routes/anthropic.py +311 -0
  113. phi_redactor-0.1.0/src/phi_redactor/proxy/routes/library.py +162 -0
  114. phi_redactor-0.1.0/src/phi_redactor/proxy/routes/management.py +402 -0
  115. phi_redactor-0.1.0/src/phi_redactor/proxy/routes/openai.py +472 -0
  116. phi_redactor-0.1.0/src/phi_redactor/proxy/session.py +208 -0
  117. phi_redactor-0.1.0/src/phi_redactor/proxy/streaming.py +135 -0
  118. phi_redactor-0.1.0/src/phi_redactor/py.typed +1 -0
  119. phi_redactor-0.1.0/src/phi_redactor/vault/__init__.py +7 -0
  120. phi_redactor-0.1.0/src/phi_redactor/vault/encryption.py +143 -0
  121. phi_redactor-0.1.0/src/phi_redactor/vault/session_map.py +101 -0
  122. phi_redactor-0.1.0/src/phi_redactor/vault/store.py +375 -0
  123. phi_redactor-0.1.0/tests/__init__.py +0 -0
  124. phi_redactor-0.1.0/tests/conftest.py +93 -0
  125. phi_redactor-0.1.0/tests/contract/__init__.py +0 -0
  126. phi_redactor-0.1.0/tests/integration/__init__.py +0 -0
  127. phi_redactor-0.1.0/tests/integration/test_compliance.py +225 -0
  128. phi_redactor-0.1.0/tests/integration/test_detection_benchmark.py +328 -0
  129. phi_redactor-0.1.0/tests/integration/test_masking_quality.py +218 -0
  130. phi_redactor-0.1.0/tests/integration/test_proxy_anthropic.py +504 -0
  131. phi_redactor-0.1.0/tests/integration/test_proxy_openai.py +330 -0
  132. phi_redactor-0.1.0/tests/integration/test_session_consistency.py +164 -0
  133. phi_redactor-0.1.0/tests/integration/test_vault_isolation.py +208 -0
  134. phi_redactor-0.1.0/tests/unit/__init__.py +0 -0
  135. phi_redactor-0.1.0/tests/unit/test_audit.py +283 -0
  136. phi_redactor-0.1.0/tests/unit/test_dashboard.py +22 -0
  137. phi_redactor-0.1.0/tests/unit/test_date_shifter.py +215 -0
  138. phi_redactor-0.1.0/tests/unit/test_detection.py +369 -0
  139. phi_redactor-0.1.0/tests/unit/test_fhir_hl7.py +56 -0
  140. phi_redactor-0.1.0/tests/unit/test_hipaa_recognizers.py +524 -0
  141. phi_redactor-0.1.0/tests/unit/test_identity_clustering.py +251 -0
  142. phi_redactor-0.1.0/tests/unit/test_masking.py +247 -0
  143. phi_redactor-0.1.0/tests/unit/test_plugins.py +66 -0
  144. phi_redactor-0.1.0/tests/unit/test_streaming.py +175 -0
  145. phi_redactor-0.1.0/tests/unit/test_vault.py +305 -0
  146. phi_redactor-0.1.0/tests/unit/test_vault_encryption.py +215 -0
@@ -0,0 +1,207 @@
1
+ ---
2
+ description: Review planning artifacts for architecturally significant decisions and create ADRs.
3
+ ---
4
+
5
+ # COMMAND: Analyze planning artifacts and document architecturally significant decisions as ADRs
6
+
7
+ ## CONTEXT
8
+
9
+ The user has completed feature planning and needs to:
10
+
11
+ - Identify architecturally significant technical decisions from plan.md
12
+ - Document these decisions as Architecture Decision Records (ADRs)
13
+ - Ensure team alignment on technical approach before implementation
14
+ - Create a permanent, reviewable record of why decisions were made
15
+
16
+ Architecture Decision Records capture decisions that:
17
+
18
+ - Impact how engineers write or structure software
19
+ - Have notable tradeoffs or alternatives
20
+ - Will likely be questioned or revisited later
21
+
22
+ **User's additional input:**
23
+
24
+ $ARGUMENTS
25
+
26
+ ## YOUR ROLE
27
+
28
+ Act as a senior software architect with expertise in:
29
+
30
+ - Technical decision analysis and evaluation
31
+ - System design patterns and tradeoffs
32
+ - Enterprise architecture documentation
33
+ - Risk assessment and consequence analysis
34
+
35
+ ## OUTPUT STRUCTURE (with quick flywheel hooks)
36
+
37
+ Execute this workflow in 6 sequential steps. At Steps 2 and 4, apply lightweight Analyze→Measure checks:
38
+ - Analyze: Identify likely failure modes, specifically:
39
+ - Over-granular ADRs: ADRs that document decisions which are trivial, low-impact, or do not affect architectural direction (e.g., naming conventions, minor refactorings).
40
+ - Missing alternatives: ADRs that do not list at least one alternative approach considered.
41
+ - Measure: Apply the following checklist grader (PASS only if all are met):
42
+ - The ADR documents a decision that clusters related changes or impacts multiple components (not a trivial/single-file change).
43
+ - The ADR explicitly lists at least one alternative approach, with rationale.
44
+ - The ADR includes clear pros and cons for the chosen approach and alternatives.
45
+ - The ADR is concise but sufficiently detailed for future reference.
46
+
47
+ ## Step 1: Load Planning Context
48
+
49
+ Run `.specify/scripts/powershell/check-prerequisites.ps1 -Json` from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS.
50
+
51
+ Derive absolute paths:
52
+
53
+ - PLAN = FEATURE_DIR/plan.md (REQUIRED - abort if missing with "Run /sp.plan first")
54
+ - RESEARCH = FEATURE_DIR/research.md (if exists)
55
+ - DATA_MODEL = FEATURE_DIR/data-model.md (if exists)
56
+ - CONTRACTS_DIR = FEATURE_DIR/contracts/ (if exists)
57
+
58
+ ## Step 2: Extract Architectural Decisions (Analyze)
59
+
60
+ Load plan.md and available artifacts. Extract architecturally significant decisions as **decision clusters** (not atomic choices):
61
+
62
+ **✅ GOOD (Clustered):**
63
+
64
+ - "Frontend Stack" (Next.js + Tailwind + Vercel as integrated solution)
65
+ - "Authentication Approach" (JWT strategy + Auth0 + session handling)
66
+ - "Data Architecture" (PostgreSQL + Redis caching + migration strategy)
67
+
68
+ **❌ BAD (Over-granular):**
69
+
70
+ - Separate ADRs for Next.js, Tailwind, and Vercel
71
+ - Separate ADRs for each library choice
72
+
73
+ **Clustering Rules:**
74
+
75
+ - Group technologies that work together and would likely change together
76
+ - Separate only if decisions are independent and could diverge
77
+ - Example: Frontend stack vs Backend stack = 2 ADRs (can evolve independently)
78
+ - Example: Next.js + Tailwind + Vercel = 1 ADR (integrated, change together)
79
+
80
+ For each decision cluster, note: what was decided, why, where in docs.
81
+
82
+ ## Step 3: Check Existing ADRs
83
+
84
+ Scan `history/adr/` directory. For each extracted decision:
85
+
86
+ - If covered by existing ADR → note reference
87
+ - If conflicts with existing ADR → flag conflict
88
+ - If not covered → mark as ADR candidate
89
+
90
+ ## Step 4: Apply Significance Test (Measure)
91
+
92
+ For each ADR candidate, test:
93
+
94
+ - Does it impact how engineers write/structure software?
95
+ - Are there notable tradeoffs or alternatives?
96
+ - Will it be questioned or revisited later?
97
+
98
+ Only proceed with ADRs that pass ALL three tests.
99
+
100
+ ## Step 5: Create ADRs (Improve)
101
+
102
+ For each qualifying decision cluster:
103
+
104
+ 1. Generate concise title reflecting the cluster (e.g., "Frontend Technology Stack" not "Use Next.js")
105
+ 2. Run `create-adr.sh "<title>"` from repo root
106
+ 3. Parse JSON response for `adr_path` and `adr_id`
107
+ 4. Read created file (contains template with {{PLACEHOLDERS}})
108
+ 5. Fill ALL placeholders:
109
+ - `{{TITLE}}` = decision cluster title
110
+ - `{{STATUS}}` = "Proposed" or "Accepted"
111
+ - `{{DATE}}` = today (YYYY-MM-DD)
112
+ - `{{CONTEXT}}` = situation, constraints leading to decision cluster
113
+ - `{{DECISION}}` = list ALL components of cluster (e.g., "Framework: Next.js 14, Styling: Tailwind CSS v3, Deployment: Vercel")
114
+ - `{{CONSEQUENCES}}` = outcomes, tradeoffs, risks for the integrated solution
115
+ - `{{ALTERNATIVES}}` = alternative clusters (e.g., "Remix + styled-components + Cloudflare")
116
+ - `{{REFERENCES}}` = plan.md, research.md, data-model.md
117
+ 6. Save file
118
+
119
+ ## Step 6: Report Completion
120
+
121
+ Output:
122
+
123
+ ```
124
+ ✅ ADR Review Complete - Created N ADRs, referenced M existing
125
+ ```
126
+
127
+ List created ADRs with ID and title.
128
+
129
+ If conflicts detected:
130
+
131
+ ```
132
+ ⚠️ Conflicts with existing ADRs [IDs]. Review and update outdated decisions or revise plan.
133
+ ```
134
+
135
+ If create-adr.sh fails: Report script error and skip that ADR.
136
+
137
+ ## FORMATTING REQUIREMENTS
138
+
139
+ Present results in this exact structure:
140
+
141
+ ```
142
+ ✅ ADR Review Complete
143
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
144
+
145
+ 📋 Created ADRs: {count}
146
+ - ADR-{id}: {title}
147
+ - ADR-{id}: {title}
148
+
149
+ 📚 Referenced Existing: {count}
150
+ - ADR-{id}: {title}
151
+
152
+ ⚠️ Conflicts Detected: {count}
153
+ - ADR-{id}: {conflict description}
154
+
155
+ Next Steps:
156
+ → Resolve conflicts before proceeding to /sp.tasks
157
+ → Review created ADRs with team
158
+ → Update plan.md if needed
159
+
160
+ Acceptance Criteria (PASS only if all true)
161
+ - Decisions are clustered (not atomic), with explicit alternatives and tradeoffs
162
+ - Consequences cover both positive and negative outcomes
163
+ - References link back to plan and related docs
164
+ ```
165
+
166
+ ## ERROR HANDLING
167
+
168
+ If plan.md missing:
169
+
170
+ - Display: "❌ Error: plan.md not found. Run /sp.plan first to generate planning artifacts."
171
+ - Exit gracefully without creating any ADRs
172
+
173
+ If create-adr.sh fails:
174
+
175
+ - Display exact error message
176
+ - Skip that ADR and continue with others
177
+ - Report partial completion at end
178
+
179
+ ## TONE
180
+
181
+ Be thorough, analytical, and decision-focused. Emphasize the "why" behind each decision and its long-term implications.
182
+
183
+ ---
184
+
185
+ As the main request completes, you MUST create and complete a PHR (Prompt History Record) using agent‑native tools when possible.
186
+
187
+ 1) Determine Stage
188
+ - Stage: constitution | spec | plan | tasks | red | green | refactor | explainer | misc | general
189
+
190
+ 2) Generate Title and Determine Routing:
191
+ - Generate Title: 3–7 words (slug for filename)
192
+ - Route is automatically determined by stage:
193
+ - `constitution` → `history/prompts/constitution/`
194
+ - Feature stages → `history/prompts/<feature-name>/` (spec, plan, tasks, red, green, refactor, explainer, misc)
195
+ - `general` → `history/prompts/general/`
196
+
197
+ 3) Create and Fill PHR (Shell first; fallback agent‑native)
198
+ - Run: `.specify/scripts/bash/create-phr.sh --title "<title>" --stage <stage> [--feature <name>] --json`
199
+ - Open the file and fill remaining placeholders (YAML + body), embedding full PROMPT_TEXT (verbatim) and concise RESPONSE_TEXT.
200
+ - If the script fails:
201
+ - Read `.specify/templates/phr-template.prompt.md` (or `templates/…`)
202
+ - Allocate an ID; compute the output path based on stage from step 2; write the file
203
+ - Fill placeholders and embed full PROMPT_TEXT and concise RESPONSE_TEXT
204
+
205
+ 4) Validate + report
206
+ - No unresolved placeholders; path under `history/prompts/` and matches stage; stage/title/date coherent; print ID + path + stage + title.
207
+ - On failure: warn, don't block. Skip only for `/sp.phr`.
@@ -0,0 +1,210 @@
1
+ ---
2
+ description: Perform a non-destructive cross-artifact consistency and quality analysis across spec.md, plan.md, and tasks.md after task generation.
3
+ ---
4
+
5
+ ## User Input
6
+
7
+ ```text
8
+ $ARGUMENTS
9
+ ```
10
+
11
+ You **MUST** consider the user input before proceeding (if not empty).
12
+
13
+ ## Goal
14
+
15
+ Identify inconsistencies, duplications, ambiguities, and underspecified items across the three core artifacts (`spec.md`, `plan.md`, `tasks.md`) before implementation. This command MUST run only after `/sp.tasks` has successfully produced a complete `tasks.md`.
16
+
17
+ ## Operating Constraints
18
+
19
+ **STRICTLY READ-ONLY**: Do **not** modify any files. Output a structured analysis report. Offer an optional remediation plan (user must explicitly approve before any follow-up editing commands would be invoked manually).
20
+
21
+ **Constitution Authority**: The project constitution (`.specify/memory/constitution.md`) is **non-negotiable** within this analysis scope. Constitution conflicts are automatically CRITICAL and require adjustment of the spec, plan, or tasks—not dilution, reinterpretation, or silent ignoring of the principle. If a principle itself needs to change, that must occur in a separate, explicit constitution update outside `/sp.analyze`.
22
+
23
+ ## Execution Steps
24
+
25
+ ### 1. Initialize Analysis Context
26
+
27
+ Run `.specify/scripts/powershell/check-prerequisites.ps1 -Json -RequireTasks -IncludeTasks` once from repo root and parse JSON for FEATURE_DIR and AVAILABLE_DOCS. Derive absolute paths:
28
+
29
+ - SPEC = FEATURE_DIR/spec.md
30
+ - PLAN = FEATURE_DIR/plan.md
31
+ - TASKS = FEATURE_DIR/tasks.md
32
+
33
+ Abort with an error message if any required file is missing (instruct the user to run missing prerequisite command).
34
+ For single quotes in args like "I'm Groot", use escape syntax: e.g 'I'\''m Groot' (or double-quote if possible: "I'm Groot").
35
+
36
+ ### 2. Load Artifacts (Progressive Disclosure)
37
+
38
+ Load only the minimal necessary context from each artifact:
39
+
40
+ **From spec.md:**
41
+
42
+ - Overview/Context
43
+ - Functional Requirements
44
+ - Non-Functional Requirements
45
+ - User Stories
46
+ - Edge Cases (if present)
47
+
48
+ **From plan.md:**
49
+
50
+ - Architecture/stack choices
51
+ - Data Model references
52
+ - Phases
53
+ - Technical constraints
54
+
55
+ **From tasks.md:**
56
+
57
+ - Task IDs
58
+ - Descriptions
59
+ - Phase grouping
60
+ - Parallel markers [P]
61
+ - Referenced file paths
62
+
63
+ **From constitution:**
64
+
65
+ - Load `.specify/memory/constitution.md` for principle validation
66
+
67
+ ### 3. Build Semantic Models
68
+
69
+ Create internal representations (do not include raw artifacts in output):
70
+
71
+ - **Requirements inventory**: Each functional + non-functional requirement with a stable key (derive slug based on imperative phrase; e.g., "User can upload file" → `user-can-upload-file`)
72
+ - **User story/action inventory**: Discrete user actions with acceptance criteria
73
+ - **Task coverage mapping**: Map each task to one or more requirements or stories (inference by keyword / explicit reference patterns like IDs or key phrases)
74
+ - **Constitution rule set**: Extract principle names and MUST/SHOULD normative statements
75
+
76
+ ### 4. Detection Passes (Token-Efficient Analysis)
77
+
78
+ Focus on high-signal findings. Limit to 50 findings total; aggregate remainder in overflow summary.
79
+
80
+ #### A. Duplication Detection
81
+
82
+ - Identify near-duplicate requirements
83
+ - Mark lower-quality phrasing for consolidation
84
+
85
+ #### B. Ambiguity Detection
86
+
87
+ - Flag vague adjectives (fast, scalable, secure, intuitive, robust) lacking measurable criteria
88
+ - Flag unresolved placeholders (TODO, TKTK, ???, `<placeholder>`, etc.)
89
+
90
+ #### C. Underspecification
91
+
92
+ - Requirements with verbs but missing object or measurable outcome
93
+ - User stories missing acceptance criteria alignment
94
+ - Tasks referencing files or components not defined in spec/plan
95
+
96
+ #### D. Constitution Alignment
97
+
98
+ - Any requirement or plan element conflicting with a MUST principle
99
+ - Missing mandated sections or quality gates from constitution
100
+
101
+ #### E. Coverage Gaps
102
+
103
+ - Requirements with zero associated tasks
104
+ - Tasks with no mapped requirement/story
105
+ - Non-functional requirements not reflected in tasks (e.g., performance, security)
106
+
107
+ #### F. Inconsistency
108
+
109
+ - Terminology drift (same concept named differently across files)
110
+ - Data entities referenced in plan but absent in spec (or vice versa)
111
+ - Task ordering contradictions (e.g., integration tasks before foundational setup tasks without dependency note)
112
+ - Conflicting requirements (e.g., one requires Next.js while other specifies Vue)
113
+
114
+ ### 5. Severity Assignment
115
+
116
+ Use this heuristic to prioritize findings:
117
+
118
+ - **CRITICAL**: Violates constitution MUST, missing core spec artifact, or requirement with zero coverage that blocks baseline functionality
119
+ - **HIGH**: Duplicate or conflicting requirement, ambiguous security/performance attribute, untestable acceptance criterion
120
+ - **MEDIUM**: Terminology drift, missing non-functional task coverage, underspecified edge case
121
+ - **LOW**: Style/wording improvements, minor redundancy not affecting execution order
122
+
123
+ ### 6. Produce Compact Analysis Report
124
+
125
+ Output a Markdown report (no file writes) with the following structure:
126
+
127
+ ## Specification Analysis Report
128
+
129
+ | ID | Category | Severity | Location(s) | Summary | Recommendation |
130
+ |----|----------|----------|-------------|---------|----------------|
131
+ | A1 | Duplication | HIGH | spec.md:L120-134 | Two similar requirements ... | Merge phrasing; keep clearer version |
132
+
133
+ (Add one row per finding; generate stable IDs prefixed by category initial.)
134
+
135
+ **Coverage Summary Table:**
136
+
137
+ | Requirement Key | Has Task? | Task IDs | Notes |
138
+ |-----------------|-----------|----------|-------|
139
+
140
+ **Constitution Alignment Issues:** (if any)
141
+
142
+ **Unmapped Tasks:** (if any)
143
+
144
+ **Metrics:**
145
+
146
+ - Total Requirements
147
+ - Total Tasks
148
+ - Coverage % (requirements with >=1 task)
149
+ - Ambiguity Count
150
+ - Duplication Count
151
+ - Critical Issues Count
152
+
153
+ ### 7. Provide Next Actions
154
+
155
+ At end of report, output a concise Next Actions block:
156
+
157
+ - If CRITICAL issues exist: Recommend resolving before `/sp.implement`
158
+ - If only LOW/MEDIUM: User may proceed, but provide improvement suggestions
159
+ - Provide explicit command suggestions: e.g., "Run /sp.specify with refinement", "Run /sp.plan to adjust architecture", "Manually edit tasks.md to add coverage for 'performance-metrics'"
160
+
161
+ ### 8. Offer Remediation
162
+
163
+ Ask the user: "Would you like me to suggest concrete remediation edits for the top N issues?" (Do NOT apply them automatically.)
164
+
165
+ ## Operating Principles
166
+
167
+ ### Context Efficiency
168
+
169
+ - **Minimal high-signal tokens**: Focus on actionable findings, not exhaustive documentation
170
+ - **Progressive disclosure**: Load artifacts incrementally; don't dump all content into analysis
171
+ - **Token-efficient output**: Limit findings table to 50 rows; summarize overflow
172
+ - **Deterministic results**: Rerunning without changes should produce consistent IDs and counts
173
+
174
+ ### Analysis Guidelines
175
+
176
+ - **NEVER modify files** (this is read-only analysis)
177
+ - **NEVER hallucinate missing sections** (if absent, report them accurately)
178
+ - **Prioritize constitution violations** (these are always CRITICAL)
179
+ - **Use examples over exhaustive rules** (cite specific instances, not generic patterns)
180
+ - **Report zero issues gracefully** (emit success report with coverage statistics)
181
+
182
+ ## Context
183
+
184
+ $ARGUMENTS
185
+
186
+ ---
187
+
188
+ As the main request completes, you MUST create and complete a PHR (Prompt History Record) using agent‑native tools when possible.
189
+
190
+ 1) Determine Stage
191
+ - Stage: constitution | spec | plan | tasks | red | green | refactor | explainer | misc | general
192
+
193
+ 2) Generate Title and Determine Routing:
194
+ - Generate Title: 3–7 words (slug for filename)
195
+ - Route is automatically determined by stage:
196
+ - `constitution` → `history/prompts/constitution/`
197
+ - Feature stages → `history/prompts/<feature-name>/` (spec, plan, tasks, red, green, refactor, explainer, misc)
198
+ - `general` → `history/prompts/general/`
199
+
200
+ 3) Create and Fill PHR (Shell first; fallback agent‑native)
201
+ - Run: `.specify/scripts/bash/create-phr.sh --title "<title>" --stage <stage> [--feature <name>] --json`
202
+ - Open the file and fill remaining placeholders (YAML + body), embedding full PROMPT_TEXT (verbatim) and concise RESPONSE_TEXT.
203
+ - If the script fails:
204
+ - Read `.specify/templates/phr-template.prompt.md` (or `templates/…`)
205
+ - Allocate an ID; compute the output path based on stage from step 2; write the file
206
+ - Fill placeholders and embed full PROMPT_TEXT and concise RESPONSE_TEXT
207
+
208
+ 4) Validate + report
209
+ - No unresolved placeholders; path under `history/prompts/` and matches stage; stage/title/date coherent; print ID + path + stage + title.
210
+ - On failure: warn, don't block. Skip only for `/sp.phr`.