sdtk-spec-kit 0.3.14 → 0.3.16

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 (49) hide show
  1. package/assets/manifest/toolkit-bundle.manifest.json +69 -134
  2. package/assets/manifest/toolkit-bundle.sha256.txt +33 -46
  3. package/assets/toolkit/toolkit/AGENTS.md +17 -15
  4. package/assets/toolkit/toolkit/SDTK_TOOLKIT.md +10 -6
  5. package/assets/toolkit/toolkit/install.ps1 +60 -50
  6. package/assets/toolkit/toolkit/runtimes/claude/CLAUDE_TEMPLATE.md +2 -2
  7. package/assets/toolkit/toolkit/scripts/agents/run-claude-task.ps1 +332 -111
  8. package/assets/toolkit/toolkit/scripts/agents/run-codex-task.ps1 +618 -103
  9. package/assets/toolkit/toolkit/scripts/install-claude-skills.ps1 +179 -169
  10. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/SKILL.md +111 -84
  11. package/assets/toolkit/toolkit/skills/sdtk-api-doc/SKILL.md +46 -10
  12. package/assets/toolkit/toolkit/skills/sdtk-arch/SKILL.md +85 -85
  13. package/assets/toolkit/toolkit/skills/sdtk-design-layout/SKILL.md +42 -3
  14. package/assets/toolkit/toolkit/skills/sdtk-dev-backend/SKILL.md +61 -5
  15. package/assets/toolkit/toolkit/skills/sdtk-dev-frontend/SKILL.md +63 -5
  16. package/assets/toolkit/toolkit/skills/sdtk-mailbox-dispatch/SKILL.md +73 -71
  17. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/SKILL.md +53 -33
  18. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/SKILL.md +60 -24
  19. package/assets/toolkit/toolkit/skills/skills.catalog.yaml +9 -9
  20. package/assets/toolkit/toolkit/skills-claude/api-design-spec/SKILL.md +116 -90
  21. package/assets/toolkit/toolkit/skills-claude/api-doc/SKILL.md +49 -9
  22. package/assets/toolkit/toolkit/skills-claude/arch/SKILL.md +3 -3
  23. package/assets/toolkit/toolkit/skills-claude/design-layout/SKILL.md +36 -2
  24. package/assets/toolkit/toolkit/skills-claude/dev-backend/SKILL.md +58 -5
  25. package/assets/toolkit/toolkit/skills-claude/dev-frontend/SKILL.md +60 -5
  26. package/assets/toolkit/toolkit/skills-claude/mailbox-dispatch/SKILL.md +73 -71
  27. package/assets/toolkit/toolkit/skills-claude/screen-design-spec/SKILL.md +49 -27
  28. package/assets/toolkit/toolkit/skills-claude/test-case-spec/SKILL.md +74 -20
  29. package/assets/toolkit/toolkit/templates/README.md +5 -1
  30. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_CREATION_RULES.md +1 -2
  31. package/assets/toolkit/toolkit/templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md +468 -468
  32. package/assets/toolkit/toolkit/templates/docs/api/FLOWCHART_CREATION_RULES.md +3 -3
  33. package/assets/toolkit/toolkit/templates/docs/api/YAML_CREATION_RULES.md +128 -128
  34. package/assets/toolkit/toolkit/templates/mailbox/AGENT_REPORT_TEMPLATE.md +62 -49
  35. package/assets/toolkit/toolkit/templates/mailbox/AGENT_TASK_TEMPLATE.md +23 -10
  36. package/package.json +48 -48
  37. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/references/API_DESIGN_CREATION_RULES.md +0 -22
  38. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/references/API_DESIGN_FLOWCHART_CREATION_RULES.md +0 -468
  39. package/assets/toolkit/toolkit/skills/sdtk-api-design-spec/references/FLOWCHART_CREATION_RULES.md +0 -20
  40. package/assets/toolkit/toolkit/skills/sdtk-api-doc/references/API_DESIGN_FLOWCHART_CREATION_RULES.md +0 -468
  41. package/assets/toolkit/toolkit/skills/sdtk-api-doc/references/FLOWCHART_CREATION_RULES.md +0 -20
  42. package/assets/toolkit/toolkit/skills/sdtk-api-doc/references/YAML_CREATION_RULES.md +0 -128
  43. package/assets/toolkit/toolkit/skills/sdtk-arch/references/API_DESIGN_CREATION_RULES.md +0 -22
  44. package/assets/toolkit/toolkit/skills/sdtk-arch/references/API_DESIGN_FLOWCHART_CREATION_RULES.md +0 -468
  45. package/assets/toolkit/toolkit/skills/sdtk-arch/references/FLOWCHART_CREATION_RULES.md +0 -20
  46. package/assets/toolkit/toolkit/skills/sdtk-arch/references/FLOW_ACTION_SPEC_CREATION_RULES.md +0 -220
  47. package/assets/toolkit/toolkit/skills/sdtk-arch/references/YAML_CREATION_RULES.md +0 -128
  48. package/assets/toolkit/toolkit/skills/sdtk-screen-design-spec/references/FLOW_ACTION_SPEC_CREATION_RULES.md +0 -220
  49. package/assets/toolkit/toolkit/skills/sdtk-test-case-spec/references/TEST_CASE_CREATION_RULES.md +0 -129
@@ -58,6 +58,37 @@ function Copy-File {
58
58
  Copy-Item -LiteralPath $SourcePath -Destination $DestinationPath -Force
59
59
  }
60
60
 
61
+ function Get-ClaudeManagedReferenceSources {
62
+ param(
63
+ [Parameter(Mandatory = $true)][string]$SkillName
64
+ )
65
+
66
+ switch ($SkillName) {
67
+ 'api-doc' { return @(
68
+ 'templates/docs/api/YAML_CREATION_RULES.md',
69
+ 'templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md'
70
+ ) }
71
+ 'api-design-spec' { return @(
72
+ 'templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md'
73
+ ) }
74
+ 'arch' { return @(
75
+ 'templates/docs/api/YAML_CREATION_RULES.md',
76
+ 'templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md',
77
+ 'templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md'
78
+ ) }
79
+ 'screen-design-spec' { return @(
80
+ 'templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md',
81
+ 'skills/sdtk-screen-design-spec/references/numbering-rules.md',
82
+ 'skills/sdtk-screen-design-spec/references/figma-mcp.md',
83
+ 'skills/sdtk-screen-design-spec/references/excel-image-export.md'
84
+ ) }
85
+ 'test-case-spec' { return @(
86
+ 'templates/docs/qa/TEST_CASE_CREATION_RULES.md'
87
+ ) }
88
+ default { return @() }
89
+ }
90
+ }
91
+
61
92
  function Install-ClaudeSkillDirectory {
62
93
  param(
63
94
  [Parameter(Mandatory = $true)][System.IO.DirectoryInfo]$SkillDir,
@@ -95,6 +126,21 @@ function Install-ClaudeSkillDirectory {
95
126
  Copy-Item -LiteralPath $srcSubDir -Destination $destSubDir -Recurse -Force
96
127
  }
97
128
 
129
+ $referenceSources = @(Get-ClaudeManagedReferenceSources -SkillName $SkillDir.Name)
130
+ if ($referenceSources.Count -gt 0) {
131
+ $destRefDir = Join-Path $destDir 'references'
132
+ if (Test-Path -LiteralPath $destRefDir) {
133
+ Remove-Item -LiteralPath $destRefDir -Recurse -Force
134
+ }
135
+ New-Item -ItemType Directory -Force -Path $destRefDir | Out-Null
136
+
137
+ foreach ($relativeSource in $referenceSources) {
138
+ $srcRefPath = Join-Path $ToolkitRoot $relativeSource
139
+ $destRefPath = Join-Path $destRefDir ([System.IO.Path]::GetFileName($relativeSource))
140
+ Copy-File -SourcePath $srcRefPath -DestinationPath $destRefPath -Overwrite $true
141
+ }
142
+ }
143
+
98
144
  return $true
99
145
  }
100
146
 
@@ -147,68 +193,32 @@ function Install-ClaudeSkills {
147
193
  }
148
194
  }
149
195
 
150
- # Install reference files
151
- $refDest = Join-Path $skillsDest 'references'
152
- if (-not (Test-Path -LiteralPath $refDest)) {
153
- New-Item -ItemType Directory -Force -Path $refDest | Out-Null
154
- }
155
-
156
- $refCount = 0
157
- $missingRefs = @()
158
-
159
- # 6 files from toolkit/templates/docs/
160
- $templateRefs = @(
161
- @{ Src = 'templates/docs/api/YAML_CREATION_RULES.md' },
162
- @{ Src = 'templates/docs/api/API_DESIGN_FLOWCHART_CREATION_RULES.md' },
163
- @{ Src = 'templates/docs/api/FLOWCHART_CREATION_RULES.md' },
164
- @{ Src = 'templates/docs/api/API_DESIGN_CREATION_RULES.md' },
165
- @{ Src = 'templates/docs/specs/FLOW_ACTION_SPEC_CREATION_RULES.md' },
166
- @{ Src = 'templates/docs/qa/TEST_CASE_CREATION_RULES.md' }
167
- )
168
-
169
- foreach ($ref in $templateRefs) {
170
- $srcPath = Join-Path $ToolkitRoot $ref.Src
171
- $fileName = Split-Path -Leaf $srcPath
172
- $destPath = Join-Path $refDest $fileName
173
- if (Test-Path -LiteralPath $srcPath) {
174
- Copy-File -SourcePath $srcPath -DestinationPath $destPath -Overwrite $Overwrite
175
- $refCount++
176
- } else {
177
- $missingRefs += $srcPath
178
- }
196
+ # Remove obsolete shared Claude specialist reference catch-all if it exists
197
+ $legacyRefDest = Join-Path $skillsDest 'references'
198
+ if (Test-Path -LiteralPath $legacyRefDest) {
199
+ Remove-Item -LiteralPath $legacyRefDest -Recurse -Force
179
200
  }
180
201
 
181
- # 3 files from toolkit/skills/sdtk-screen-design-spec/references/
182
- $screenRefs = @('numbering-rules.md', 'figma-mcp.md', 'excel-image-export.md')
183
- foreach ($fileName in $screenRefs) {
184
- $srcPath = Join-Path $ToolkitRoot "skills/sdtk-screen-design-spec/references/$fileName"
185
- $destPath = Join-Path $refDest $fileName
186
- if (Test-Path -LiteralPath $srcPath) {
187
- Copy-File -SourcePath $srcPath -DestinationPath $destPath -Overwrite $Overwrite
188
- $refCount++
189
- } else {
190
- $missingRefs += $srcPath
202
+ $managedRefCount = 0
203
+ foreach ($skillName in @('arch', 'api-doc', 'api-design-spec', 'screen-design-spec', 'test-case-spec')) {
204
+ $refDir = Join-Path $skillsDest "$skillName/references"
205
+ if (Test-Path -LiteralPath $refDir) {
206
+ $managedRefCount += @(Get-ChildItem -LiteralPath $refDir -File).Count
191
207
  }
192
208
  }
193
209
 
194
- # Fail-fast: abort if any reference files are missing
195
- if ($missingRefs.Count -gt 0) {
196
- $list = ($missingRefs | ForEach-Object { " - $_" }) -join "`n"
197
- throw "Claude install failed. Missing reference files:`n$list"
198
- }
199
-
200
210
  # Strict count assertions
201
- $expectedSkills = 13
202
- $expectedRefs = 9
211
+ $expectedSkills = 14
212
+ $expectedManagedRefs = 11
203
213
  if ($skillCount -ne $expectedSkills) {
204
214
  throw "Claude install failed. Expected $expectedSkills skills but installed $skillCount."
205
215
  }
206
- if ($refCount -ne $expectedRefs) {
207
- throw "Claude install failed. Expected $expectedRefs reference files but installed $refCount."
216
+ if ($managedRefCount -ne $expectedManagedRefs) {
217
+ throw "Claude install failed. Expected $expectedManagedRefs specialist reference files but installed $managedRefCount."
208
218
  }
209
219
 
210
220
  Write-Host " Skills installed: $skillCount"
211
- Write-Host " Reference files : $refCount"
221
+ Write-Host " Specialist refs : $managedRefCount"
212
222
  }
213
223
 
214
224
  function Test-IsMaintainerRoot {
@@ -47,8 +47,8 @@ Skills are installed at `.claude/skills/` and provide slash commands:
47
47
  | `/dev-backend` | Backend code conventions |
48
48
  | `/dev-frontend` | Frontend code conventions |
49
49
 
50
- Rule reference files are installed at `.claude/skills/references/`.
50
+ Specialist rule reference files are installed inside each skill directory when that skill needs them (for example `.claude/skills/api-doc/references/`).
51
51
 
52
52
  ## 5) References
53
53
  - `sdtk-spec.config.json`
54
- - `.claude/skills/references/` (rule files)
54
+ - `.claude/skills/<skill>/references/` (skill-local rule files when required)
@@ -1,111 +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
-
17
- function Get-TaskBulletValue([string[]] $Lines, [string] $Heading) {
18
- for ($i = 0; $i -lt $Lines.Length; $i++) {
19
- if ($Lines[$i].Trim() -eq $Heading) {
20
- for ($j = $i + 1; $j -lt $Lines.Length; $j++) {
21
- $candidate = $Lines[$j].Trim()
22
- if (-not $candidate) { continue }
23
- if ($candidate.StartsWith('- ')) {
24
- return $candidate.Substring(2).Trim()
25
- }
26
- break
27
- }
28
- }
29
- }
30
- return ''
31
- }
32
-
33
- function Resolve-RepoPath([string] $RepoRootPath, [string] $CandidatePath) {
34
- if ([string]::IsNullOrWhiteSpace($CandidatePath)) { return '' }
35
- if ([System.IO.Path]::IsPathRooted($CandidatePath)) { return $CandidatePath }
36
- return Join-Path $RepoRootPath $CandidatePath
37
- }
38
-
39
- function Append-FileText([string] $Path, [string] $Text) {
40
- if ([string]::IsNullOrWhiteSpace($Text)) { return }
41
- [System.IO.File]::AppendAllText($Path, [Environment]::NewLine + $Text, $Utf8NoBom)
42
- }
43
-
44
- function Invoke-PhaseArtifactValidation([string[]] $TaskLines, [string] $RepoRootPath, [string] $ReportPath, [string] $LogPath, [string] $ValidatorPath) {
45
- $phase = Get-TaskBulletValue $TaskLines 'Phase:'
46
- if ($ReviewPhases -notcontains $phase) { return }
47
-
48
- $artifactValue = Get-TaskBulletValue $TaskLines 'Primary Formal Artifact:'
49
- if ([string]::IsNullOrWhiteSpace($artifactValue)) { return }
50
- if (-not (Test-Path $ValidatorPath)) { return }
51
-
52
- $artifactPath = Resolve-RepoPath $RepoRootPath $artifactValue
53
- if (-not (Test-Path $artifactPath)) {
54
- $skip = "[MAILBOX PHASE VALIDATION] skipped: primary formal artifact not found at $artifactPath"
55
- Append-FileText $ReportPath $skip
56
- if ($LogPath) { Append-FileText $LogPath $skip }
57
- return
58
- }
59
-
60
- $validationOutput = (& python $ValidatorPath --phase $phase --artifact $artifactPath 2>&1 | Out-String).TrimEnd()
61
- $validationBlock = "[MAILBOX PHASE VALIDATION]`n$validationOutput"
62
- Append-FileText $ReportPath $validationBlock
63
- if ($LogPath) { Append-FileText $LogPath $validationBlock }
64
-
65
- if ($LASTEXITCODE -ne 0) {
66
- throw "Mailbox phase artifact validation failed for $artifactPath"
67
- }
68
- }
69
-
70
- if (-not (Test-Path $RepoRoot)) { throw "RepoRoot not found: $RepoRoot" }
71
- if (-not (Test-Path $TaskFile)) { throw "TaskFile not found: $TaskFile" }
72
-
73
- $taskLines = Get-Content $TaskFile -Encoding UTF8
74
- $prompt = [string]($taskLines | Out-String)
75
- New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($ReportFile)) | Out-Null
76
- if ($LogFile) {
77
- New-Item -ItemType Directory -Force -Path ([System.IO.Path]::GetDirectoryName($LogFile)) | Out-Null
78
- }
79
-
80
- $cliArgs = @('-p', '--output-format', 'text', '--no-session-persistence', '--add-dir', $RepoRoot, '--permission-mode', $PermissionMode, '--effort', $Effort)
81
- if ($SessionName) { $cliArgs += @('--name', $SessionName) }
82
- if ($Model) { $cliArgs += @('--model', $Model) }
83
- $cliArgs += $prompt
84
-
85
- if ($DryRun) {
86
- $safeArgs = @('-p', '--output-format', 'text', '--no-session-persistence', '--add-dir', $RepoRoot, '--permission-mode', $PermissionMode, '--effort', $Effort)
87
- if ($SessionName) { $safeArgs += @('--name', $SessionName) }
88
- if ($Model) { $safeArgs += @('--model', $Model) }
89
- [pscustomobject]@{
90
- Cli = 'claude'
91
- RepoRoot = $RepoRoot
92
- TaskFile = $TaskFile
93
- ReportFile = $ReportFile
94
- LogFile = $LogFile
95
- Args = $safeArgs
96
- PromptLength = $prompt.Length
97
- PromptPreview = if ($prompt.Length -gt 240) { $prompt.Substring(0, 240) } else { $prompt }
98
- } | ConvertTo-Json -Depth 4
99
- exit 0
100
- }
101
-
102
- $output = & claude @cliArgs 2>&1
103
- $outputText = ($output | Out-String)
104
- [System.IO.File]::WriteAllText($ReportFile, $outputText, $Utf8NoBom)
105
- if ($LogFile) {
106
- [System.IO.File]::WriteAllText($LogFile, $outputText, $Utf8NoBom)
107
- }
108
-
109
- $validatorPath = Join-Path $PSScriptRoot 'validate-mailbox-formal-artifact.py'
110
- Invoke-PhaseArtifactValidation -TaskLines $taskLines -RepoRootPath $RepoRoot -ReportPath $ReportFile -LogPath $LogFile -ValidatorPath $validatorPath
111
- 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"