sdtk-spec-kit 0.4.11 → 0.4.14

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 (143) hide show
  1. package/README.md +353 -353
  2. package/assets/atlas/build_atlas.py +880 -880
  3. package/assets/atlas/doc_atlas_viewer_template.html +3796 -3796
  4. package/assets/atlas/vendor/mermaid.min.js +2029 -2029
  5. package/assets/keys/spec-entitlement-public.pem +9 -9
  6. package/assets/manifest/toolkit-bundle.manifest.json +496 -496
  7. package/assets/manifest/toolkit-bundle.sha256.txt +97 -97
  8. package/assets/toolkit/toolkit/AGENTS.md +157 -241
  9. package/assets/toolkit/toolkit/README.md +51 -51
  10. package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +206 -206
  11. package/assets/toolkit/toolkit/install.ps1 +362 -362
  12. package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +95 -91
  13. package/assets/toolkit/toolkit/runtimes/codex/CODEX_TEMPLATE.md +70 -69
  14. package/assets/toolkit/toolkit/scripts/agents/run-claude-task.ps1 +332 -332
  15. package/assets/toolkit/toolkit/scripts/agents/run-codex-task.ps1 +618 -618
  16. package/assets/toolkit/toolkit/scripts/agents/validate-mailbox-formal-artifact.py +87 -87
  17. package/assets/toolkit/toolkit/scripts/generate-code-handoff.ps1 +317 -317
  18. package/assets/toolkit/toolkit/scripts/init-feature.ps1 +262 -262
  19. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +180 -180
  20. package/assets/toolkit/toolkit/scripts/install-codex-skills.ps1 +209 -209
  21. package/assets/toolkit/toolkit/scripts/uninstall-claude-skills.ps1 +139 -139
  22. package/assets/toolkit/toolkit/scripts/uninstall-codex-skills.ps1 +143 -143
  23. package/assets/toolkit/toolkit/sdtk-spec.config.json +28 -28
  24. package/assets/toolkit/toolkit/sdtk-spec.config.profiles.example.json +50 -50
  25. package/assets/toolkit/toolkit/session/SDTK_ACTIVE_BOOTSTRAP.md +46 -46
  26. package/assets/toolkit/toolkit/session/SDTK_AGENT_WORKING_RULES.md +48 -48
  27. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/SKILL.md +111 -111
  28. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/scripts/generate_api_design_detail.py +732 -732
  29. package/assets/toolkit/toolkit/skills/sdtk-api-doc/SKILL.md +79 -79
  30. package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +85 -85
  31. package/assets/toolkit/toolkit/skills/sdtk-ba/SKILL.md +46 -46
  32. package/assets/toolkit/toolkit/skills/sdtk-design-layout/SKILL.md +91 -91
  33. package/assets/toolkit/toolkit/skills/sdtk-design-layout/scripts/render_design_layout_images.py +246 -246
  34. package/assets/toolkit/toolkit/skills/sdtk-dev/SKILL.md +133 -133
  35. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/code-quality-reviewer.md +34 -34
  36. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/implementer.md +60 -60
  37. package/assets/toolkit/toolkit/skills/sdtk-dev/prompts/spec-reviewer.md +41 -41
  38. package/assets/toolkit/toolkit/skills/sdtk-dev-backend/SKILL.md +80 -80
  39. package/assets/toolkit/toolkit/skills/sdtk-dev-frontend/SKILL.md +80 -80
  40. package/assets/toolkit/toolkit/skills/sdtk-mailbox-dispatch/SKILL.md +73 -73
  41. package/assets/toolkit/toolkit/skills/sdtk-orchestrator/SKILL.md +176 -108
  42. package/assets/toolkit/toolkit/skills/sdtk-pm/SKILL.md +74 -74
  43. package/assets/toolkit/toolkit/skills/sdtk-qa/SKILL.md +75 -75
  44. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/SKILL.md +108 -107
  45. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/excel-image-export.md +51 -51
  46. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/figma-mcp.md +54 -54
  47. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/numbering-rules.md +28 -28
  48. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/scripts/renumber_flow_action_spec_global.py +136 -136
  49. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/scripts/validate_flow_action_spec_numbering.py +414 -414
  50. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/SKILL.md +110 -110
  51. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/scripts/validate_test_case_spec.py +97 -97
  52. package/assets/toolkit/toolkit/skills/skills.catalog.yaml +330 -330
  53. package/assets/toolkit/toolkit/skills-claude/api-design-spec/SKILL.md +116 -116
  54. package/assets/toolkit/toolkit/skills-claude/api-doc/SKILL.md +87 -87
  55. package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +59 -59
  56. package/assets/toolkit/toolkit/skills-claude/ba/SKILL.md +67 -67
  57. package/assets/toolkit/toolkit/skills-claude/design-layout/SKILL.md +91 -91
  58. package/assets/toolkit/toolkit/skills-claude/dev/SKILL.md +59 -59
  59. package/assets/toolkit/toolkit/skills-claude/dev-backend/SKILL.md +73 -73
  60. package/assets/toolkit/toolkit/skills-claude/dev-frontend/SKILL.md +73 -73
  61. package/assets/toolkit/toolkit/skills-claude/mailbox-dispatch/SKILL.md +73 -73
  62. package/assets/toolkit/toolkit/skills-claude/orchestrator/SKILL.md +88 -42
  63. package/assets/toolkit/toolkit/skills-claude/pm/SKILL.md +88 -88
  64. package/assets/toolkit/toolkit/skills-claude/qa/SKILL.md +58 -58
  65. package/assets/toolkit/toolkit/skills-claude/screen-design-spec/SKILL.md +113 -112
  66. package/assets/toolkit/toolkit/skills-claude/test-case-spec/SKILL.md +115 -115
  67. package/assets/toolkit/toolkit/templates/QUALITY_CHECKLIST.md +124 -124
  68. package/assets/toolkit/toolkit/templates/README.md +68 -68
  69. package/assets/toolkit/toolkit/templates/SHARED_PLANNING.md +81 -81
  70. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_CREATION_RULES.md +21 -21
  71. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_DETAIL_TEMPLATE.md +67 -67
  72. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md +468 -468
  73. package/assets/toolkit/toolkit/templates/docs/api/API_ENDPOINTS_TEMPLATE.md +229 -229
  74. package/assets/toolkit/toolkit/templates/docs/api/FEATURE_API_TEMPLATE.yaml +20 -20
  75. package/assets/toolkit/toolkit/templates/docs/api/FLOWCHART_CREATION_RULES.md +20 -20
  76. package/assets/toolkit/toolkit/templates/docs/api/YAML_CREATION_RULES.md +128 -128
  77. package/assets/toolkit/toolkit/templates/docs/api/feature_api_flow_list_TEMPLATE.txt +12 -12
  78. package/assets/toolkit/toolkit/templates/docs/architecture/ARCH_DESIGN_TEMPLATE.md +109 -109
  79. package/assets/toolkit/toolkit/templates/docs/database/DATABASE_SPEC_TEMPLATE.md +175 -175
  80. package/assets/toolkit/toolkit/templates/docs/design/DESIGN_LAYOUT_TEMPLATE.md +60 -60
  81. package/assets/toolkit/toolkit/templates/docs/dev/FEATURE_IMPL_PLAN_TEMPLATE.md +117 -117
  82. package/assets/toolkit/toolkit/templates/docs/dev/OPS_HANDOFF_CREATION_RULES.md +369 -369
  83. package/assets/toolkit/toolkit/templates/docs/discovery/REQUIREMENT_TEMPLATE.md +155 -155
  84. package/assets/toolkit/toolkit/templates/docs/product/BACKLOG_TEMPLATE.md +50 -50
  85. package/assets/toolkit/toolkit/templates/docs/product/CONDENSED_UPSTREAM_INPUT_TEMPLATE.md +276 -276
  86. package/assets/toolkit/toolkit/templates/docs/product/PRD_TEMPLATE.md +66 -66
  87. package/assets/toolkit/toolkit/templates/docs/product/PROJECT_INITIATION_TEMPLATE.md +98 -98
  88. package/assets/toolkit/toolkit/templates/docs/qa/CONTROLLER_ACCEPTANCE_TEMPLATE.md +90 -90
  89. package/assets/toolkit/toolkit/templates/docs/qa/QA_RELEASE_REPORT_TEMPLATE.md +162 -162
  90. package/assets/toolkit/toolkit/templates/docs/qa/TEST_CASE_CREATION_RULES.md +129 -129
  91. package/assets/toolkit/toolkit/templates/docs/qa/TEST_CASE_TEMPLATE.md +104 -104
  92. package/assets/toolkit/toolkit/templates/docs/specs/BA_SPEC_TEMPLATE.md +139 -139
  93. package/assets/toolkit/toolkit/templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md +220 -220
  94. package/assets/toolkit/toolkit/templates/docs/specs/FLOW_ACTION_SPEC_TEMPLATE.md +197 -197
  95. package/assets/toolkit/toolkit/templates/handoffs/ARCH_TO_DEV.md +31 -31
  96. package/assets/toolkit/toolkit/templates/handoffs/BA_TO_ARCH.md +28 -28
  97. package/assets/toolkit/toolkit/templates/handoffs/DEV_STAGE1_SPEC_REVIEW.md +26 -26
  98. package/assets/toolkit/toolkit/templates/handoffs/DEV_STAGE2_CODE_QUALITY_REVIEW.md +20 -20
  99. package/assets/toolkit/toolkit/templates/handoffs/DEV_TO_QA.md +33 -33
  100. package/assets/toolkit/toolkit/templates/handoffs/DEV_TO_SDTK_CODE.md +60 -60
  101. package/assets/toolkit/toolkit/templates/handoffs/PM_TO_BA.md +30 -30
  102. package/assets/toolkit/toolkit/templates/handoffs/QA_RELEASE_DECISION.md +26 -26
  103. package/assets/toolkit/toolkit/templates/mailbox/AGENT_REPORT_TEMPLATE.md +63 -63
  104. package/assets/toolkit/toolkit/templates/mailbox/AGENT_TASK_TEMPLATE.md +76 -76
  105. package/bin/sdtk.js +15 -15
  106. package/package.json +48 -48
  107. package/src/commands/activate.js +94 -94
  108. package/src/commands/atlas.js +339 -339
  109. package/src/commands/auth.js +85 -85
  110. package/src/commands/entitlement.js +170 -170
  111. package/src/commands/generate.js +191 -170
  112. package/src/commands/help.js +248 -246
  113. package/src/commands/init.js +117 -117
  114. package/src/commands/project.js +51 -51
  115. package/src/commands/runtime.js +239 -239
  116. package/src/commands/update.js +11 -11
  117. package/src/index.js +68 -68
  118. package/src/lib/activation-state.js +68 -68
  119. package/src/lib/args.js +116 -116
  120. package/src/lib/atlas-config.js +200 -200
  121. package/src/lib/atlas-runner.js +435 -435
  122. package/src/lib/browser-open.js +39 -39
  123. package/src/lib/capabilities.js +89 -89
  124. package/src/lib/entitlements.js +245 -245
  125. package/src/lib/errors.js +41 -41
  126. package/src/lib/github-access.js +143 -143
  127. package/src/lib/legacy-auth-migration.js +56 -56
  128. package/src/lib/license-activation.js +386 -386
  129. package/src/lib/powershell.js +85 -85
  130. package/src/lib/premium-loader.js +124 -124
  131. package/src/lib/premium-packs.js +333 -333
  132. package/src/lib/premium-sync.js +235 -235
  133. package/src/lib/project-audit.js +332 -332
  134. package/src/lib/project-config.js +108 -108
  135. package/src/lib/project-ingest.js +450 -450
  136. package/src/lib/project-refresh.js +666 -666
  137. package/src/lib/project-target-guard.js +79 -79
  138. package/src/lib/requirement-analysis.js +14 -4
  139. package/src/lib/scope.js +83 -83
  140. package/src/lib/state.js +74 -74
  141. package/src/lib/suite-state.js +70 -70
  142. package/src/lib/toolkit-payload.js +99 -99
  143. package/src/lib/update.js +333 -333
@@ -1,332 +1,332 @@
1
- param(
2
- [Parameter(Mandatory = $true)] [string] $RepoRoot,
3
- [Parameter(Mandatory = $true)] [string] $TaskFile,
4
- [Parameter(Mandatory = $true)] [string] $ReportFile,
5
- [string] $LogFile = '',
6
- [string] $SessionName = '',
7
- [string] $Model = '',
8
- [ValidateSet('default','dontAsk','acceptEdits','auto','bypassPermissions','plan')] [string] $PermissionMode = 'dontAsk',
9
- [ValidateSet('low','medium','high','max')] [string] $Effort = 'medium',
10
- [switch] $DryRun
11
- )
12
-
13
- $ErrorActionPreference = 'Stop'
14
- $Utf8NoBom = [System.Text.UTF8Encoding]::new($false)
15
- $ReviewPhases = @('controller-dev-review', 'qa-review', 'controller-acceptance')
16
- $ReadOnlyPermissionMode = 'read-only'
17
- $WritablePermissionMode = 'workspace-write-approved'
18
- $NotRequiredApprovalStatus = 'not-required'
19
- $HumanApprovedStatus = 'human-approved'
20
- $WritableClaudeModes = @('acceptEdits', 'auto', 'bypassPermissions')
21
-
22
- function Get-TaskBulletValue([string[]] $Lines, [string] $Heading) {
23
- for ($i = 0; $i -lt $Lines.Length; $i++) {
24
- if ($Lines[$i].Trim() -eq $Heading) {
25
- for ($j = $i + 1; $j -lt $Lines.Length; $j++) {
26
- $candidate = $Lines[$j].Trim()
27
- if (-not $candidate) { continue }
28
- if ($candidate.StartsWith('- ')) {
29
- return $candidate.Substring(2).Trim()
30
- }
31
- break
32
- }
33
- }
34
- }
35
- return ''
36
- }
37
-
38
-
39
- function Get-TaskListValues([string[]] $Lines, [string] $Heading) {
40
- $values = New-Object System.Collections.Generic.List[string]
41
- $foundHeading = $false
42
- for ($i = 0; $i -lt $Lines.Length; $i++) {
43
- $trimmed = $Lines[$i].Trim()
44
- if (-not $foundHeading) {
45
- if ($trimmed -eq $Heading) {
46
- $foundHeading = $true
47
- }
48
- continue
49
- }
50
-
51
- if (-not $trimmed) {
52
- if ($values.Count -gt 0) { break }
53
- continue
54
- }
55
-
56
- $headingMatch = [regex]::Match($trimmed, '^[A-Za-z].*:$')
57
- if ($headingMatch.Success) { break }
58
-
59
- $listMatch = [regex]::Match($trimmed, '^(?:-|\d+\.)\s+(?<value>.+)$')
60
- if ($listMatch.Success) {
61
- $values.Add($listMatch.Groups['value'].Value.Trim())
62
- continue
63
- }
64
-
65
- if ($values.Count -gt 0) { break }
66
- }
67
- return $values.ToArray()
68
- }
69
-
70
- function Resolve-RepoPath([string] $RepoRootPath, [string] $CandidatePath) {
71
- if ([string]::IsNullOrWhiteSpace($CandidatePath)) { return '' }
72
- if ([System.IO.Path]::IsPathRooted($CandidatePath)) { return $CandidatePath }
73
- return Join-Path $RepoRootPath $CandidatePath
74
- }
75
-
76
- function Append-FileText([string] $Path, [string] $Text) {
77
- if ([string]::IsNullOrWhiteSpace($Text)) { return }
78
- [System.IO.File]::AppendAllText($Path, [Environment]::NewLine + $Text, $Utf8NoBom)
79
- }
80
-
81
- function Normalize-TaskValue([string] $Value, [string] $Default = '') {
82
- if ([string]::IsNullOrWhiteSpace($Value)) { return $Default }
83
- return $Value.Trim()
84
- }
85
-
86
-
87
- function Convert-ToBulletBlock([string[]] $Items) {
88
- if ($null -eq $Items -or $Items.Count -eq 0) {
89
- return '- (none declared)'
90
- }
91
- return (($Items | ForEach-Object { "- $_" }) -join [Environment]::NewLine)
92
- }
93
-
94
- function New-BoundedExecutionPrompt([string[]] $TaskLines) {
95
- $phase = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Phase:') 'other'
96
- $objective = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Objective:') 'n/a'
97
- $boundaryMode = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Boundary Mode:') 'n/a'
98
- $inputs = Get-TaskListValues $TaskLines 'Inputs:'
99
- $includeBoundary = Get-TaskListValues $TaskLines 'Include Boundary:'
100
- $excludeBoundary = Get-TaskListValues $TaskLines 'Exclude Boundary:'
101
- $verification = Get-TaskListValues $TaskLines 'Required Verification:'
102
- $taskBody = [string]($TaskLines | Out-String)
103
-
104
- $envelope = @"
105
- [MAILBOX BOUNDED EXECUTION MODE]
106
- You are running under controller-enforced bounded execution mode.
107
-
108
- Phase: $phase
109
- Objective: $objective
110
- Boundary Mode: $boundaryMode
111
-
112
- Execution Discipline:
113
- 1. Read every listed input first and treat the `Inputs:` section as the authoritative starting source set.
114
- 2. Do not run broad repo-wide or directory-wide discovery before you have read the listed inputs.
115
- 3. Only inspect additional files when they are directly required to modify an included path or execute a required verification command.
116
- 4. Any additional inspection must stay inside the include boundary and must not cross the exclude boundary.
117
- 5. Do not mine `governance/ai/reviews/shared/` or similar directories for examples unless a specific file is already listed in `Inputs:`.
118
- 6. If the listed inputs are insufficient, stop and report the exact missing dependency instead of broad scanning.
119
- 7. Deliver the bounded patch and formal artifact before optional example-hunting or style exploration.
120
-
121
- Authoritative Inputs:
122
- $(Convert-ToBulletBlock $inputs)
123
-
124
- Include Boundary:
125
- $(Convert-ToBulletBlock $includeBoundary)
126
-
127
- Exclude Boundary:
128
- $(Convert-ToBulletBlock $excludeBoundary)
129
-
130
- Required Verification:
131
- $(Convert-ToBulletBlock $verification)
132
-
133
- [ORIGINAL TASK PACKET]
134
- "@
135
-
136
- return $envelope.TrimEnd() + [Environment]::NewLine + [Environment]::NewLine + $taskBody
137
- }
138
-
139
- function Test-PlaceholderValue([string] $Value) {
140
- $normalized = Normalize-TaskValue $Value
141
- if ([string]::IsNullOrWhiteSpace($normalized)) { return $true }
142
- return @('n/a', 'na', 'none', 'not-applicable') -contains $normalized.ToLowerInvariant()
143
- }
144
-
145
- function New-PermissionAuditBlock(
146
- [string] $DeclaredPermission,
147
- [string] $EffectiveMode,
148
- [string] $ApprovalStatus,
149
- [string] $ApprovedBy,
150
- [string] $ApprovalReason,
151
- [string] $ApprovedScope,
152
- [string] $ApprovalReference,
153
- [string] $DecisionSummary
154
- ) {
155
- return @"
156
- [MAILBOX EXECUTION PERMISSION AUDIT]
157
- - Declared Execution Permission: $DeclaredPermission
158
- - Effective Runtime Permission Mode: $EffectiveMode
159
- - Permission Approval Status: $ApprovalStatus
160
- - Approved By: $ApprovedBy
161
- - Approval Reason: $ApprovalReason
162
- - Approved Writable Scope: $ApprovedScope
163
- - Approval Reference: $ApprovalReference
164
- - Launcher Decision Summary: $DecisionSummary
165
- "@.TrimEnd()
166
- }
167
-
168
- function Write-PermissionFailure(
169
- [string] $ReportPath,
170
- [string] $LogPath,
171
- [string] $AuditBlock,
172
- [string] $Message
173
- ) {
174
- Append-FileText $ReportPath $AuditBlock
175
- Append-FileText $ReportPath "[MAILBOX PERMISSION VALIDATION] failed: $Message"
176
- if ($LogPath) {
177
- Append-FileText $LogPath $AuditBlock
178
- Append-FileText $LogPath "[MAILBOX PERMISSION VALIDATION] failed: $Message"
179
- }
180
- throw $Message
181
- }
182
-
183
- function Invoke-PhaseArtifactValidation([string[]] $TaskLines, [string] $RepoRootPath, [string] $ReportPath, [string] $LogPath, [string] $ValidatorPath) {
184
- $phase = Get-TaskBulletValue $TaskLines 'Phase:'
185
- if ($ReviewPhases -notcontains $phase) { return }
186
-
187
- $artifactValue = Get-TaskBulletValue $TaskLines 'Primary Formal Artifact:'
188
- if ([string]::IsNullOrWhiteSpace($artifactValue)) { return }
189
- if (-not (Test-Path $ValidatorPath)) { return }
190
-
191
- $artifactPath = Resolve-RepoPath $RepoRootPath $artifactValue
192
- if (-not (Test-Path $artifactPath)) {
193
- $skip = "[MAILBOX PHASE VALIDATION] skipped: primary formal artifact not found at $artifactPath"
194
- Append-FileText $ReportPath $skip
195
- if ($LogPath) { Append-FileText $LogPath $skip }
196
- return
197
- }
198
-
199
- $validationOutput = (& python $ValidatorPath --phase $phase --artifact $artifactPath 2>&1 | Out-String).TrimEnd()
200
- $validationBlock = "[MAILBOX PHASE VALIDATION]`n$validationOutput"
201
- Append-FileText $ReportPath $validationBlock
202
- if ($LogPath) { Append-FileText $LogPath $validationBlock }
203
-
204
- if ($LASTEXITCODE -ne 0) {
205
- throw "Mailbox phase artifact validation failed for $artifactPath"
206
- }
207
- }
208
-
209
- if (-not (Test-Path $RepoRoot)) { throw "RepoRoot not found: $RepoRoot" }
210
- if (-not (Test-Path $TaskFile)) { throw "TaskFile not found: $TaskFile" }
211
-
212
- $taskLines = Get-Content $TaskFile -Encoding UTF8
213
- $phase = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Phase:')
214
- $declaredPermission = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Execution Permission:') $ReadOnlyPermissionMode
215
- $approvalStatus = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Permission Approval Status:') $NotRequiredApprovalStatus
216
- $approvedBy = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approved By:') 'n/a'
217
- $approvalReason = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approval Reason:') 'n/a'
218
- $approvedScope = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approved Writable Scope:') 'n/a'
219
- $approvalReference = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approval Reference:') 'n/a'
220
- $prompt = New-BoundedExecutionPrompt $taskLines
221
- New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($ReportFile)) | Out-Null
222
- if ($LogFile) {
223
- New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($LogFile)) | Out-Null
224
- }
225
-
226
- $effectiveMode = $PermissionMode
227
- $decisionSummary = ''
228
- $approvalFieldsArePlaceholder = (Test-PlaceholderValue $approvedBy) -and (Test-PlaceholderValue $approvalReason) -and (Test-PlaceholderValue $approvedScope)
229
- $isWritableClaudeMode = $WritableClaudeModes -contains $PermissionMode
230
-
231
- if ($ReviewPhases -contains $phase) {
232
- if ($declaredPermission -ne $ReadOnlyPermissionMode) {
233
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase attempted writable permission and was rejected before launch'
234
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Review-phase mailbox runs must declare 'Execution Permission: read-only'."
235
- }
236
- if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
237
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase approval metadata was inconsistent for a read-only run'
238
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only review phases must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
239
- }
240
- if ($isWritableClaudeMode) {
241
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase requested writable Claude permission mode and was rejected before launch'
242
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
243
- }
244
- $decisionSummary = 'review phase allowed only non-writable Claude permission mode'
245
- } elseif ($phase -eq 'implementation') {
246
- if ($declaredPermission -eq $WritablePermissionMode) {
247
- if ($approvalStatus -ne $HumanApprovedStatus) {
248
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without human-approved status'
249
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Writable implementation runs require 'Permission Approval Status: human-approved'."
250
- }
251
- if ((Test-PlaceholderValue $approvedBy) -or (Test-PlaceholderValue $approvalReason) -or (Test-PlaceholderValue $approvedScope)) {
252
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without complete approval metadata'
253
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Writable implementation runs require Approved By, Approval Reason, and Approved Writable Scope.'
254
- }
255
- if (-not $isWritableClaudeMode) {
256
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without explicit writable Claude permission mode'
257
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Writable Claude implementation runs require an explicit writable permission mode such as acceptEdits, auto, or bypassPermissions.'
258
- }
259
- $decisionSummary = 'writable Claude implementation run approved and enabled from task-packet approval record'
260
- } elseif ($declaredPermission -eq $ReadOnlyPermissionMode) {
261
- if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
262
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'read-only implementation run carried contradictory writable approval metadata'
263
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only implementation runs must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
264
- }
265
- if ($isWritableClaudeMode) {
266
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'read-only implementation run requested writable Claude permission mode and was rejected before launch'
267
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
268
- }
269
- $decisionSummary = 'implementation run remained non-writable because no writable approval was declared'
270
- } else {
271
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'unknown execution permission rejected before launch'
272
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Unknown execution permission mode '$declaredPermission'."
273
- }
274
- } else {
275
- if ($declaredPermission -ne $ReadOnlyPermissionMode) {
276
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase attempted writable permission and was rejected before launch'
277
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Only implementation-phase mailbox runs may request writable execution.'
278
- }
279
- if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
280
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase approval metadata was inconsistent for a read-only run'
281
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Non-implementation read-only runs must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
282
- }
283
- if ($isWritableClaudeMode) {
284
- $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase requested writable Claude permission mode and was rejected before launch'
285
- Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
286
- }
287
- $decisionSummary = 'non-implementation phase allowed only non-writable Claude permission mode'
288
- }
289
-
290
- $permissionAuditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary $decisionSummary
291
- $cliArgs = @('-p', '--output-format', 'text', '--no-session-persistence', '--add-dir', $RepoRoot, '--permission-mode', $PermissionMode, '--effort', $Effort)
292
- if ($SessionName) { $cliArgs += @('--name', $SessionName) }
293
- if ($Model) { $cliArgs += @('--model', $Model) }
294
- $cliArgs += $prompt
295
-
296
- if ($DryRun) {
297
- [pscustomobject]@{
298
- Cli = 'claude'
299
- RepoRoot = $RepoRoot
300
- TaskFile = $TaskFile
301
- ReportFile = $ReportFile
302
- LogFile = $LogFile
303
- Args = $cliArgs
304
- PromptLength = $prompt.Length
305
- PromptPreview = if ($prompt.Length -gt 2000) { $prompt.Substring(0, 2000) } else { $prompt }
306
- DeclaredExecutionPermission = $declaredPermission
307
- EffectiveRuntimePermissionMode = $PermissionMode
308
- PermissionApprovalStatus = $approvalStatus
309
- ApprovedBy = $approvedBy
310
- ApprovalReason = $approvalReason
311
- ApprovedWritableScope = $approvedScope
312
- ApprovalReference = $approvalReference
313
- LauncherDecisionSummary = $decisionSummary
314
- } | ConvertTo-Json -Depth 4
315
- exit 0
316
- }
317
-
318
- $output = & claude @cliArgs 2>&1
319
- $outputText = ($output | Out-String)
320
- [System.IO.File]::WriteAllText($ReportFile, $outputText, $Utf8NoBom)
321
- if ($LogFile) {
322
- [System.IO.File]::WriteAllText($LogFile, $outputText, $Utf8NoBom)
323
- }
324
-
325
- Append-FileText $ReportFile $permissionAuditBlock
326
- if ($LogFile) {
327
- Append-FileText $LogFile $permissionAuditBlock
328
- }
329
-
330
- $validatorPath = Join-Path $PSScriptRoot 'validate-mailbox-formal-artifact.py'
331
- Invoke-PhaseArtifactValidation -TaskLines $taskLines -RepoRootPath $RepoRoot -ReportPath $ReportFile -LogPath $LogFile -ValidatorPath $validatorPath
332
- Write-Host "Claude report written to: $ReportFile"
1
+ param(
2
+ [Parameter(Mandatory = $true)] [string] $RepoRoot,
3
+ [Parameter(Mandatory = $true)] [string] $TaskFile,
4
+ [Parameter(Mandatory = $true)] [string] $ReportFile,
5
+ [string] $LogFile = '',
6
+ [string] $SessionName = '',
7
+ [string] $Model = '',
8
+ [ValidateSet('default','dontAsk','acceptEdits','auto','bypassPermissions','plan')] [string] $PermissionMode = 'dontAsk',
9
+ [ValidateSet('low','medium','high','max')] [string] $Effort = 'medium',
10
+ [switch] $DryRun
11
+ )
12
+
13
+ $ErrorActionPreference = 'Stop'
14
+ $Utf8NoBom = [System.Text.UTF8Encoding]::new($false)
15
+ $ReviewPhases = @('controller-dev-review', 'qa-review', 'controller-acceptance')
16
+ $ReadOnlyPermissionMode = 'read-only'
17
+ $WritablePermissionMode = 'workspace-write-approved'
18
+ $NotRequiredApprovalStatus = 'not-required'
19
+ $HumanApprovedStatus = 'human-approved'
20
+ $WritableClaudeModes = @('acceptEdits', 'auto', 'bypassPermissions')
21
+
22
+ function Get-TaskBulletValue([string[]] $Lines, [string] $Heading) {
23
+ for ($i = 0; $i -lt $Lines.Length; $i++) {
24
+ if ($Lines[$i].Trim() -eq $Heading) {
25
+ for ($j = $i + 1; $j -lt $Lines.Length; $j++) {
26
+ $candidate = $Lines[$j].Trim()
27
+ if (-not $candidate) { continue }
28
+ if ($candidate.StartsWith('- ')) {
29
+ return $candidate.Substring(2).Trim()
30
+ }
31
+ break
32
+ }
33
+ }
34
+ }
35
+ return ''
36
+ }
37
+
38
+
39
+ function Get-TaskListValues([string[]] $Lines, [string] $Heading) {
40
+ $values = New-Object System.Collections.Generic.List[string]
41
+ $foundHeading = $false
42
+ for ($i = 0; $i -lt $Lines.Length; $i++) {
43
+ $trimmed = $Lines[$i].Trim()
44
+ if (-not $foundHeading) {
45
+ if ($trimmed -eq $Heading) {
46
+ $foundHeading = $true
47
+ }
48
+ continue
49
+ }
50
+
51
+ if (-not $trimmed) {
52
+ if ($values.Count -gt 0) { break }
53
+ continue
54
+ }
55
+
56
+ $headingMatch = [regex]::Match($trimmed, '^[A-Za-z].*:$')
57
+ if ($headingMatch.Success) { break }
58
+
59
+ $listMatch = [regex]::Match($trimmed, '^(?:-|\d+\.)\s+(?<value>.+)$')
60
+ if ($listMatch.Success) {
61
+ $values.Add($listMatch.Groups['value'].Value.Trim())
62
+ continue
63
+ }
64
+
65
+ if ($values.Count -gt 0) { break }
66
+ }
67
+ return $values.ToArray()
68
+ }
69
+
70
+ function Resolve-RepoPath([string] $RepoRootPath, [string] $CandidatePath) {
71
+ if ([string]::IsNullOrWhiteSpace($CandidatePath)) { return '' }
72
+ if ([System.IO.Path]::IsPathRooted($CandidatePath)) { return $CandidatePath }
73
+ return Join-Path $RepoRootPath $CandidatePath
74
+ }
75
+
76
+ function Append-FileText([string] $Path, [string] $Text) {
77
+ if ([string]::IsNullOrWhiteSpace($Text)) { return }
78
+ [System.IO.File]::AppendAllText($Path, [Environment]::NewLine + $Text, $Utf8NoBom)
79
+ }
80
+
81
+ function Normalize-TaskValue([string] $Value, [string] $Default = '') {
82
+ if ([string]::IsNullOrWhiteSpace($Value)) { return $Default }
83
+ return $Value.Trim()
84
+ }
85
+
86
+
87
+ function Convert-ToBulletBlock([string[]] $Items) {
88
+ if ($null -eq $Items -or $Items.Count -eq 0) {
89
+ return '- (none declared)'
90
+ }
91
+ return (($Items | ForEach-Object { "- $_" }) -join [Environment]::NewLine)
92
+ }
93
+
94
+ function New-BoundedExecutionPrompt([string[]] $TaskLines) {
95
+ $phase = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Phase:') 'other'
96
+ $objective = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Objective:') 'n/a'
97
+ $boundaryMode = Normalize-TaskValue (Get-TaskBulletValue $TaskLines 'Boundary Mode:') 'n/a'
98
+ $inputs = Get-TaskListValues $TaskLines 'Inputs:'
99
+ $includeBoundary = Get-TaskListValues $TaskLines 'Include Boundary:'
100
+ $excludeBoundary = Get-TaskListValues $TaskLines 'Exclude Boundary:'
101
+ $verification = Get-TaskListValues $TaskLines 'Required Verification:'
102
+ $taskBody = [string]($TaskLines | Out-String)
103
+
104
+ $envelope = @"
105
+ [MAILBOX BOUNDED EXECUTION MODE]
106
+ You are running under controller-enforced bounded execution mode.
107
+
108
+ Phase: $phase
109
+ Objective: $objective
110
+ Boundary Mode: $boundaryMode
111
+
112
+ Execution Discipline:
113
+ 1. Read every listed input first and treat the `Inputs:` section as the authoritative starting source set.
114
+ 2. Do not run broad repo-wide or directory-wide discovery before you have read the listed inputs.
115
+ 3. Only inspect additional files when they are directly required to modify an included path or execute a required verification command.
116
+ 4. Any additional inspection must stay inside the include boundary and must not cross the exclude boundary.
117
+ 5. Do not mine `governance/ai/reviews/shared/` or similar directories for examples unless a specific file is already listed in `Inputs:`.
118
+ 6. If the listed inputs are insufficient, stop and report the exact missing dependency instead of broad scanning.
119
+ 7. Deliver the bounded patch and formal artifact before optional example-hunting or style exploration.
120
+
121
+ Authoritative Inputs:
122
+ $(Convert-ToBulletBlock $inputs)
123
+
124
+ Include Boundary:
125
+ $(Convert-ToBulletBlock $includeBoundary)
126
+
127
+ Exclude Boundary:
128
+ $(Convert-ToBulletBlock $excludeBoundary)
129
+
130
+ Required Verification:
131
+ $(Convert-ToBulletBlock $verification)
132
+
133
+ [ORIGINAL TASK PACKET]
134
+ "@
135
+
136
+ return $envelope.TrimEnd() + [Environment]::NewLine + [Environment]::NewLine + $taskBody
137
+ }
138
+
139
+ function Test-PlaceholderValue([string] $Value) {
140
+ $normalized = Normalize-TaskValue $Value
141
+ if ([string]::IsNullOrWhiteSpace($normalized)) { return $true }
142
+ return @('n/a', 'na', 'none', 'not-applicable') -contains $normalized.ToLowerInvariant()
143
+ }
144
+
145
+ function New-PermissionAuditBlock(
146
+ [string] $DeclaredPermission,
147
+ [string] $EffectiveMode,
148
+ [string] $ApprovalStatus,
149
+ [string] $ApprovedBy,
150
+ [string] $ApprovalReason,
151
+ [string] $ApprovedScope,
152
+ [string] $ApprovalReference,
153
+ [string] $DecisionSummary
154
+ ) {
155
+ return @"
156
+ [MAILBOX EXECUTION PERMISSION AUDIT]
157
+ - Declared Execution Permission: $DeclaredPermission
158
+ - Effective Runtime Permission Mode: $EffectiveMode
159
+ - Permission Approval Status: $ApprovalStatus
160
+ - Approved By: $ApprovedBy
161
+ - Approval Reason: $ApprovalReason
162
+ - Approved Writable Scope: $ApprovedScope
163
+ - Approval Reference: $ApprovalReference
164
+ - Launcher Decision Summary: $DecisionSummary
165
+ "@.TrimEnd()
166
+ }
167
+
168
+ function Write-PermissionFailure(
169
+ [string] $ReportPath,
170
+ [string] $LogPath,
171
+ [string] $AuditBlock,
172
+ [string] $Message
173
+ ) {
174
+ Append-FileText $ReportPath $AuditBlock
175
+ Append-FileText $ReportPath "[MAILBOX PERMISSION VALIDATION] failed: $Message"
176
+ if ($LogPath) {
177
+ Append-FileText $LogPath $AuditBlock
178
+ Append-FileText $LogPath "[MAILBOX PERMISSION VALIDATION] failed: $Message"
179
+ }
180
+ throw $Message
181
+ }
182
+
183
+ function Invoke-PhaseArtifactValidation([string[]] $TaskLines, [string] $RepoRootPath, [string] $ReportPath, [string] $LogPath, [string] $ValidatorPath) {
184
+ $phase = Get-TaskBulletValue $TaskLines 'Phase:'
185
+ if ($ReviewPhases -notcontains $phase) { return }
186
+
187
+ $artifactValue = Get-TaskBulletValue $TaskLines 'Primary Formal Artifact:'
188
+ if ([string]::IsNullOrWhiteSpace($artifactValue)) { return }
189
+ if (-not (Test-Path $ValidatorPath)) { return }
190
+
191
+ $artifactPath = Resolve-RepoPath $RepoRootPath $artifactValue
192
+ if (-not (Test-Path $artifactPath)) {
193
+ $skip = "[MAILBOX PHASE VALIDATION] skipped: primary formal artifact not found at $artifactPath"
194
+ Append-FileText $ReportPath $skip
195
+ if ($LogPath) { Append-FileText $LogPath $skip }
196
+ return
197
+ }
198
+
199
+ $validationOutput = (& python $ValidatorPath --phase $phase --artifact $artifactPath 2>&1 | Out-String).TrimEnd()
200
+ $validationBlock = "[MAILBOX PHASE VALIDATION]`n$validationOutput"
201
+ Append-FileText $ReportPath $validationBlock
202
+ if ($LogPath) { Append-FileText $LogPath $validationBlock }
203
+
204
+ if ($LASTEXITCODE -ne 0) {
205
+ throw "Mailbox phase artifact validation failed for $artifactPath"
206
+ }
207
+ }
208
+
209
+ if (-not (Test-Path $RepoRoot)) { throw "RepoRoot not found: $RepoRoot" }
210
+ if (-not (Test-Path $TaskFile)) { throw "TaskFile not found: $TaskFile" }
211
+
212
+ $taskLines = Get-Content $TaskFile -Encoding UTF8
213
+ $phase = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Phase:')
214
+ $declaredPermission = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Execution Permission:') $ReadOnlyPermissionMode
215
+ $approvalStatus = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Permission Approval Status:') $NotRequiredApprovalStatus
216
+ $approvedBy = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approved By:') 'n/a'
217
+ $approvalReason = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approval Reason:') 'n/a'
218
+ $approvedScope = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approved Writable Scope:') 'n/a'
219
+ $approvalReference = Normalize-TaskValue (Get-TaskBulletValue $taskLines 'Approval Reference:') 'n/a'
220
+ $prompt = New-BoundedExecutionPrompt $taskLines
221
+ New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($ReportFile)) | Out-Null
222
+ if ($LogFile) {
223
+ New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($LogFile)) | Out-Null
224
+ }
225
+
226
+ $effectiveMode = $PermissionMode
227
+ $decisionSummary = ''
228
+ $approvalFieldsArePlaceholder = (Test-PlaceholderValue $approvedBy) -and (Test-PlaceholderValue $approvalReason) -and (Test-PlaceholderValue $approvedScope)
229
+ $isWritableClaudeMode = $WritableClaudeModes -contains $PermissionMode
230
+
231
+ if ($ReviewPhases -contains $phase) {
232
+ if ($declaredPermission -ne $ReadOnlyPermissionMode) {
233
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase attempted writable permission and was rejected before launch'
234
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Review-phase mailbox runs must declare 'Execution Permission: read-only'."
235
+ }
236
+ if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
237
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase approval metadata was inconsistent for a read-only run'
238
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only review phases must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
239
+ }
240
+ if ($isWritableClaudeMode) {
241
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'review phase requested writable Claude permission mode and was rejected before launch'
242
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
243
+ }
244
+ $decisionSummary = 'review phase allowed only non-writable Claude permission mode'
245
+ } elseif ($phase -eq 'implementation') {
246
+ if ($declaredPermission -eq $WritablePermissionMode) {
247
+ if ($approvalStatus -ne $HumanApprovedStatus) {
248
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without human-approved status'
249
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Writable implementation runs require 'Permission Approval Status: human-approved'."
250
+ }
251
+ if ((Test-PlaceholderValue $approvedBy) -or (Test-PlaceholderValue $approvalReason) -or (Test-PlaceholderValue $approvedScope)) {
252
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without complete approval metadata'
253
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Writable implementation runs require Approved By, Approval Reason, and Approved Writable Scope.'
254
+ }
255
+ if (-not $isWritableClaudeMode) {
256
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'writable Claude implementation requested without explicit writable Claude permission mode'
257
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Writable Claude implementation runs require an explicit writable permission mode such as acceptEdits, auto, or bypassPermissions.'
258
+ }
259
+ $decisionSummary = 'writable Claude implementation run approved and enabled from task-packet approval record'
260
+ } elseif ($declaredPermission -eq $ReadOnlyPermissionMode) {
261
+ if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
262
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'read-only implementation run carried contradictory writable approval metadata'
263
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only implementation runs must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
264
+ }
265
+ if ($isWritableClaudeMode) {
266
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'read-only implementation run requested writable Claude permission mode and was rejected before launch'
267
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
268
+ }
269
+ $decisionSummary = 'implementation run remained non-writable because no writable approval was declared'
270
+ } else {
271
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'unknown execution permission rejected before launch'
272
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Unknown execution permission mode '$declaredPermission'."
273
+ }
274
+ } else {
275
+ if ($declaredPermission -ne $ReadOnlyPermissionMode) {
276
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase attempted writable permission and was rejected before launch'
277
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message 'Only implementation-phase mailbox runs may request writable execution.'
278
+ }
279
+ if ($approvalStatus -ne $NotRequiredApprovalStatus -or -not $approvalFieldsArePlaceholder) {
280
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase approval metadata was inconsistent for a read-only run'
281
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Non-implementation read-only runs must use 'Permission Approval Status: not-required' and leave writable approval fields as 'n/a'."
282
+ }
283
+ if ($isWritableClaudeMode) {
284
+ $auditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary 'non-implementation phase requested writable Claude permission mode and was rejected before launch'
285
+ Write-PermissionFailure -ReportPath $ReportFile -LogPath $LogFile -AuditBlock $auditBlock -Message "Read-only mailbox tasks may not use writable Claude permission modes such as acceptEdits, auto, or bypassPermissions."
286
+ }
287
+ $decisionSummary = 'non-implementation phase allowed only non-writable Claude permission mode'
288
+ }
289
+
290
+ $permissionAuditBlock = New-PermissionAuditBlock -DeclaredPermission $declaredPermission -EffectiveMode $PermissionMode -ApprovalStatus $approvalStatus -ApprovedBy $approvedBy -ApprovalReason $approvalReason -ApprovedScope $approvedScope -ApprovalReference $approvalReference -DecisionSummary $decisionSummary
291
+ $cliArgs = @('-p', '--output-format', 'text', '--no-session-persistence', '--add-dir', $RepoRoot, '--permission-mode', $PermissionMode, '--effort', $Effort)
292
+ if ($SessionName) { $cliArgs += @('--name', $SessionName) }
293
+ if ($Model) { $cliArgs += @('--model', $Model) }
294
+ $cliArgs += $prompt
295
+
296
+ if ($DryRun) {
297
+ [pscustomobject]@{
298
+ Cli = 'claude'
299
+ RepoRoot = $RepoRoot
300
+ TaskFile = $TaskFile
301
+ ReportFile = $ReportFile
302
+ LogFile = $LogFile
303
+ Args = $cliArgs
304
+ PromptLength = $prompt.Length
305
+ PromptPreview = if ($prompt.Length -gt 2000) { $prompt.Substring(0, 2000) } else { $prompt }
306
+ DeclaredExecutionPermission = $declaredPermission
307
+ EffectiveRuntimePermissionMode = $PermissionMode
308
+ PermissionApprovalStatus = $approvalStatus
309
+ ApprovedBy = $approvedBy
310
+ ApprovalReason = $approvalReason
311
+ ApprovedWritableScope = $approvedScope
312
+ ApprovalReference = $approvalReference
313
+ LauncherDecisionSummary = $decisionSummary
314
+ } | ConvertTo-Json -Depth 4
315
+ exit 0
316
+ }
317
+
318
+ $output = & claude @cliArgs 2>&1
319
+ $outputText = ($output | Out-String)
320
+ [System.IO.File]::WriteAllText($ReportFile, $outputText, $Utf8NoBom)
321
+ if ($LogFile) {
322
+ [System.IO.File]::WriteAllText($LogFile, $outputText, $Utf8NoBom)
323
+ }
324
+
325
+ Append-FileText $ReportFile $permissionAuditBlock
326
+ if ($LogFile) {
327
+ Append-FileText $LogFile $permissionAuditBlock
328
+ }
329
+
330
+ $validatorPath = Join-Path $PSScriptRoot 'validate-mailbox-formal-artifact.py'
331
+ Invoke-PhaseArtifactValidation -TaskLines $taskLines -RepoRootPath $RepoRoot -ReportPath $ReportFile -LogPath $LogFile -ValidatorPath $validatorPath
332
+ Write-Host "Claude report written to: $ReportFile"