oc-harness-setup 0.3.2 → 0.4.0

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 (136) hide show
  1. package/.docs/unwired-routing.md +16 -15
  2. package/AGENTS.md +105 -68
  3. package/CHANGELOG.md +91 -0
  4. package/GLOSSARY.md +46 -0
  5. package/LICENSE +1 -1
  6. package/README.md +48 -61
  7. package/agents/cleaner.md +86 -0
  8. package/agents/critic.md +79 -0
  9. package/agents/historian.md +92 -0
  10. package/agents/maintainer.md +106 -0
  11. package/agents/ops.md +69 -0
  12. package/agents/orchestrator.md +48 -18
  13. package/agents/researcher.md +72 -0
  14. package/agents/verifier.md +84 -0
  15. package/agents/worker.md +87 -0
  16. package/bin/cli.js +349 -133
  17. package/commands/close.md +11 -0
  18. package/commands/evolve.md +11 -0
  19. package/commands/fast.md +11 -0
  20. package/commands/goal.md +11 -0
  21. package/commands/search.md +11 -0
  22. package/commands/swarm.md +11 -0
  23. package/opencode.jsonc +42 -80
  24. package/package.json +13 -6
  25. package/reference/README.md +12 -14
  26. package/reference/canon.md +71 -0
  27. package/reference/context.md +35 -0
  28. package/reference/enforcement.md +6 -0
  29. package/reference/flow.md +19 -0
  30. package/reference/gates.md +23 -0
  31. package/reference/harness.md +15 -0
  32. package/reference/hygiene.md +13 -0
  33. package/reference/memory.md +13 -0
  34. package/reference/models.md +19 -24
  35. package/reference/phases.md +23 -0
  36. package/reference/repos.md +49 -0
  37. package/reference/tools.md +35 -0
  38. package/scripts/harness-doctor.ps1 +83 -0
  39. package/skills/close/SKILL.md +36 -0
  40. package/skills/evolve/SKILL.md +76 -0
  41. package/skills/fast/SKILL.md +36 -0
  42. package/skills/goal/SKILL.md +65 -0
  43. package/skills/search/SKILL.md +68 -0
  44. package/skills/swarm/SKILL.md +69 -0
  45. package/state-seed/lessons.md +22 -0
  46. package/state-seed/template.md +12 -0
  47. package/agents/build.md +0 -20
  48. package/agents/explore.md +0 -26
  49. package/agents/general.md +0 -19
  50. package/agents/plan.md +0 -29
  51. package/agents/reviewer.md +0 -22
  52. package/agents/vault.md +0 -73
  53. package/commands/build.md +0 -7
  54. package/commands/checkpoint.md +0 -7
  55. package/commands/code-simplify.md +0 -7
  56. package/commands/gauntlet.md +0 -7
  57. package/commands/handoff.md +0 -7
  58. package/commands/keeper.md +0 -7
  59. package/commands/kill.md +0 -11
  60. package/commands/plan.md +0 -7
  61. package/commands/retro.md +0 -15
  62. package/commands/review.md +0 -7
  63. package/commands/ship.md +0 -7
  64. package/commands/spec.md +0 -7
  65. package/commands/test.md +0 -7
  66. package/commands/webperf.md +0 -7
  67. package/reference/auto-mandate.md +0 -11
  68. package/reference/backup-convention.md +0 -9
  69. package/reference/clean-mandate.md +0 -13
  70. package/reference/editor-parity.md +0 -7
  71. package/reference/gc-scripts.md +0 -8
  72. package/reference/intent-routing.md +0 -14
  73. package/reference/lifecycle.md +0 -15
  74. package/reference/model-keeper.md +0 -46
  75. package/reference/model-test.md +0 -176
  76. package/reference/oc-source-map.md +0 -162
  77. package/reference/owner-pin.md +0 -31
  78. package/reference/roster.md +0 -15
  79. package/reference/session-scope.md +0 -9
  80. package/reference/session-state.md +0 -13
  81. package/reference/swarm.md +0 -32
  82. package/scripts/backup-config.ps1 +0 -42
  83. package/scripts/gc-branch.ps1 +0 -196
  84. package/scripts/gc-bump.ps1 +0 -198
  85. package/scripts/gc-clean.ps1 +0 -648
  86. package/scripts/gc-commit.ps1 +0 -143
  87. package/scripts/gc-merge.ps1 +0 -272
  88. package/scripts/gc-pr.ps1 +0 -190
  89. package/scripts/gc-push.ps1 +0 -111
  90. package/scripts/gc-read.ps1 +0 -150
  91. package/scripts/gc-rebase.ps1 +0 -162
  92. package/scripts/gc-release.ps1 +0 -225
  93. package/scripts/gc-stage.ps1 +0 -103
  94. package/scripts/gc-status.ps1 +0 -127
  95. package/scripts/gc-sync.ps1 +0 -65
  96. package/scripts/gc.core.ps1 +0 -715
  97. package/scripts/gc.smoke.ps1 +0 -779
  98. package/scripts/interrupt-session.ps1 +0 -65
  99. package/scripts/logbook/README.md +0 -108
  100. package/scripts/logbook/logbook.test.ts +0 -440
  101. package/scripts/logbook/logbook.ts +0 -797
  102. package/scripts/pirep/README.md +0 -147
  103. package/scripts/pirep/pirep.test.ts +0 -735
  104. package/scripts/pirep/pirep.ts +0 -836
  105. package/scripts/testflight/README.md +0 -112
  106. package/scripts/testflight/testflight.test.ts +0 -512
  107. package/scripts/testflight/testflight.ts +0 -806
  108. package/skills/_shared/SOURCES.md +0 -26
  109. package/skills/_shared/references/accessibility-checklist.md +0 -160
  110. package/skills/_shared/references/definition-of-done.md +0 -67
  111. package/skills/_shared/references/observability-checklist.md +0 -92
  112. package/skills/_shared/references/orchestration-patterns.md +0 -155
  113. package/skills/_shared/references/performance-checklist.md +0 -236
  114. package/skills/_shared/references/security-checklist.md +0 -245
  115. package/skills/_shared/references/testing-patterns.md +0 -235
  116. package/skills/api-and-interface-design/SKILL.md +0 -14
  117. package/skills/browser-testing-with-devtools/SKILL.md +0 -303
  118. package/skills/code-simplification/SKILL.md +0 -14
  119. package/skills/creative-writing/SKILL.md +0 -96
  120. package/skills/debugging-and-error-recovery/SKILL.md +0 -15
  121. package/skills/flight-deck/SKILL.md +0 -17
  122. package/skills/frontend-ui-engineering/SKILL.md +0 -16
  123. package/skills/gauntlet/SKILL.md +0 -21
  124. package/skills/git-ceremony/SKILL.md +0 -27
  125. package/skills/grilling/SKILL.md +0 -18
  126. package/skills/observability-and-instrumentation/SKILL.md +0 -18
  127. package/skills/performance-optimization/SKILL.md +0 -16
  128. package/skills/pilot-report/SKILL.md +0 -18
  129. package/skills/planning-and-task-breakdown/SKILL.md +0 -16
  130. package/skills/security-and-hardening/SKILL.md +0 -18
  131. package/skills/source-driven-development/SKILL.md +0 -16
  132. package/skills/spec-driven-development/SKILL.md +0 -26
  133. package/skills/test-driven-development/SKILL.md +0 -18
  134. package/skills/test-flight/SKILL.md +0 -14
  135. package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
  136. package/skills/writing-for-agents/SKILL.md +0 -89
@@ -1,143 +0,0 @@
1
- #Requires -Version 7.0
2
- <#
3
- .SYNOPSIS
4
- Commit the staged content with a ceremony-validated message. No editor, no
5
- prompts, no human in the middle.
6
-
7
- .DESCRIPTION
8
- git-ceremony §3 as a script. Validates the subject
9
- (`type(scope): imperative summary`, ≤72 chars, no trailing period, lowercase
10
- start — `fix: cap retry backoff at 30s`), caps the body at three plain
11
- bullets, puts issue refs in the body (never the subject), refuses to commit
12
- on every default-branch commit. Direct-default fallback is outside this
13
- script only, after all §11b predicates are verified; unknown predicates
14
- require stopping and escalating. Re-runs the secret
15
- scan over the staged diff (the last gate), prints the staged diff stat for
16
- review, then commits the staged content exactly.
17
-
18
- Nothing staged fails with a remediation (run gc-stage or -All) — exit 2.
19
- A repo without user.name/user.email fails with the fix — exit 2.
20
-
21
- Repo rules win: if the repo documents its own convention (commit-lint,
22
- sign-off, DCO), follow that instead of this script.
23
-
24
- .PARAMETER Type
25
- One of: feat, fix, chore, docs, refactor, test, perf, hotfix, wt.
26
- .PARAMETER Scope
27
- Optional kebab-case scope, e.g. api — renders as type(scope): summary.
28
- .PARAMETER Summary
29
- Imperative summary, lowercase first char, no trailing period.
30
- .PARAMETER Body
31
- Up to 3 plain lines; rendered as bullets under the subject. Bullets are
32
- newline-separated: pwsh -File callers pass ONE argument with embedded `n
33
- characters (repeated -Body and comma lists do NOT become arrays under
34
- pwsh -File — a comma list lands as one literal bullet).
35
- Do NOT prefix a body line with `-`: a leading dash collides with the
36
- [string[]] binder and fails with the misleading "Missing an argument for
37
- parameter 'Body'".
38
- .PARAMETER Issue
39
- Issue ref (#123 or ABC-123) — goes in the body, never the subject (§3).
40
- .PARAMETER All
41
- Stage everything first (git add -A, with the same gates as gc-stage).
42
- .PARAMETER RepoRoot
43
- Repository path (defaults to the current directory); git is always pinned
44
- with git -C.
45
- .PARAMETER Detailed
46
- Restore the step narration, ok/info lines, git/gh relay, and the staged-diff
47
- stat the terse default hides. Never affects the RESULT line, warnings,
48
- failures, or the security/remediation lines.
49
- .PARAMETER Quiet
50
- Accepted for compatibility and now a no-op: the default is already terse.
51
- -Quiet forces the gate closed and so wins if passed with -Detailed.
52
-
53
- .EXAMPLE
54
- pwsh -File scripts\gc-commit.ps1 -Type fix -Scope api -Summary 'cap retry backoff at 30s' `
55
- -Body 'unbounded backoff stalled the queue ~9 min' -Issue #4821
56
- #>
57
- param(
58
- [string]$Type,
59
- [string]$Scope,
60
- [Parameter(Mandatory)][string]$Summary,
61
- [string[]]$Body,
62
- [string]$Issue,
63
- [switch]$All,
64
- [string]$RepoRoot = (Get-Location).Path,
65
- [switch]$Detailed,
66
- [switch]$Quiet
67
- )
68
- Set-StrictMode -Version Latest
69
- $ErrorActionPreference = 'Stop'
70
- . (Join-Path $PSScriptRoot 'gc.core.ps1')
71
- if ($Detailed) { $script:GcQuiet = $false }
72
- if ($Quiet) { $script:GcQuiet = $true }
73
-
74
- try {
75
- $root = Resolve-GcRoot -Path $RepoRoot
76
- Write-GcInfo "repo: $root"
77
-
78
- # branch only — targeted rev-parse; the cached state this would build is
79
- # dropped by the `git add -A` below before Get-GcStagedNames reads it.
80
- $cur = Get-GcCurrentBranch -Root $root -Targeted
81
- $default = Get-GcDefaultBranch -Root $root
82
- if ($cur -eq $default) {
83
- throw [GcException]::new("intentionally refusing to commit on the default branch ($default). Direct-default fallback applies only when review state is absent (no remote collaborators, default-branch CI, branch protection, CODEOWNERS, or releases/tags), the change is R1 bounded/reversible/local, and gc-stage's secret gate has run. If every predicate is verified, documented §11b permits direct commit for snapshot/derived targets; see skills/git-ceremony §11b and reference/gc-scripts.md. If any condition is unknown or disputed, stop and escalate to the operator; do not retry with raw git.", $script:GcExitPre)
84
- }
85
-
86
- if ($Scope -and $Scope -cnotmatch '^[a-z0-9-]+$') {
87
- throw [GcException]::new("scope '$Scope' must be kebab-case — stray positional argument? pass every parameter by name", $script:GcExitPre)
88
- }
89
- $subject = if ($Scope) { "${Type}($Scope): $Summary" } else { "${Type}: $Summary" }
90
- Write-GcInfo "subject: $subject"
91
- $parts = Get-GcSubjectParts -Subject $subject # throws Pre with the fix on any violation
92
- if ($parts.Summary -cmatch '#[0-9]+' -or $parts.Summary -cmatch '(?<![A-Za-z0-9])[A-Z]{3,}-[0-9]{2,}(?![A-Za-z0-9])') {
93
- throw [GcException]::new("issue refs go in the body via -Issue, never the subject (§3) — '$($parts.Summary)' looks like a ref", $script:GcExitPre)
94
- }
95
-
96
- $bullets = @()
97
- foreach ($b in (@($Body) | ForEach-Object { $_ -split "`n" } | Where-Object { $_ -and $_.Trim() })) {
98
- $bullets += ($b.Trim() -replace '^-+\s*','')
99
- if ($bullets.Count -gt 3) {
100
- throw [GcException]::new('body is capped at 3 plain bullets (§3)', $script:GcExitPre)
101
- }
102
- }
103
- if ($Issue) {
104
- if ($Issue -notmatch '^[A-Za-z0-9#_.-]+$') {
105
- throw [GcException]::new("issue ref '$Issue' must be a bare ref like #123 or ABC-123", $script:GcExitPre)
106
- }
107
- $bullets += "refs $Issue"
108
- if ($bullets.Count -gt 3) {
109
- throw [GcException]::new('body plus issue ref is capped at 3 bullets (§3)', $script:GcExitPre)
110
- }
111
- }
112
-
113
- Assert-GcIdentity -Root $root
114
-
115
- if ($All) {
116
- Invoke-GcGit -Root $root -Argv @('add','-A')
117
- Write-GcOk 'staged all changes (-All)'
118
- }
119
-
120
- # last gate: the staged diff (ceremony §3) — content plus secret scan
121
- if (-not (Get-GcStagedNames -Root $root)) {
122
- throw [GcException]::new('nothing staged — run gc-stage with the paths, or pass -All', $script:GcExitPre)
123
- }
124
- Stop-GcOnSecrets -Root $root
125
- $stat = Get-GcGit -Root $root -Argv @('diff','--cached','--stat')
126
- Write-GcInfo 'staged diff (review before the commit lands):'
127
- Write-GcNote (($stat -join "`n"))
128
-
129
- $argv = @('commit','-m',$subject)
130
- if ($bullets.Count -gt 0) { $argv += @('-m', ($bullets -join "`n")) }
131
- Invoke-GcGit -Root $root -Argv $argv
132
-
133
- $log = (Get-GcGit -Root $root -Argv @('log','-1','--format=%h%x09%s') | Select-Object -First 1).Trim()
134
- $files = @(Get-GcGit -Root $root -Argv @('show','--format=','--name-only','-r','HEAD') | Where-Object { $_ }).Count
135
- Write-GcOk "committed: $log"
136
- Write-GcResult -Props @{ sha = ($log -split "`t")[0]; subject = ($log -split "`t")[1]; files = $files; action = 'committed' }
137
- } catch [GcException] {
138
- Write-GcFail $_.Exception.Message
139
- Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
140
- } catch {
141
- Write-GcFail "unexpected: $($_.Exception.Message)"
142
- Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
143
- }
@@ -1,272 +0,0 @@
1
- #Requires -Version 7.0
2
- <#
3
- .SYNOPSIS
4
- Merge a branch through its PR — squash by default, only when the checks are
5
- green (main stays green, §6). Then delete the branch, local and remote, and
6
- prune. No human in the middle.
7
-
8
- .DESCRIPTION
9
- git-ceremony §6 as a script. Refuses to merge while any check is failing or
10
- (beyond -CheckTimeoutSec) still pending; a PR whose status rollup shows NO
11
- checks proceeds with a warning — required-check enforcement is gh's own
12
- backstop (gh refuses to merge a blocked PR). If the PR is a draft it is
13
- marked ready first. The merge is verified (state == MERGED) before ANY
14
- cleanup; the local branch is deleted only when it provably matches the
15
- merged PR head (no guesswork, no unguarded -D), and the remote branch only
16
- when the remote ref still exists. Re-runs after a completed merge are clean
17
- no-ops that finish leftover cleanup (self-healing, idempotent).
18
-
19
- Repo rules win: repos that dictate merge commits or rebase get -Mode
20
- merge|rebase; a repo's own documented convention always beats this script.
21
-
22
- .PARAMETER Branch
23
- Head branch to merge. Defaults to the current branch. Ref-shaped and
24
- validated (a leading dash is rejected outright).
25
- .PARAMETER PR
26
- Explicit PR number; defaults to the open PR for the branch.
27
- .PARAMETER Mode
28
- Merge method: squash (default), merge, or rebase.
29
- .PARAMETER CheckTimeoutSec
30
- How long to wait for pending checks before refusing (default 300; 0 = do
31
- not wait — refuse while pending).
32
- .PARAMETER NoDeleteBranch
33
- Keep the branch after merge (ceremony deletes it; repos that want it kept
34
- pass this).
35
- .PARAMETER RepoRoot
36
- Repository path (defaults to the current directory); git pinned with git -C,
37
- gh run from the repo root.
38
- .PARAMETER Detailed
39
- Restore the step narration, ok/info lines, and raw git/gh relay the terse
40
- default hides. Never affects the RESULT line, warnings, failures, or the
41
- security/remediation lines.
42
- .PARAMETER Quiet
43
- Accepted for compatibility and now a no-op: the default is already terse.
44
- -Quiet forces the gate closed and so wins if passed with -Detailed.
45
-
46
- .EXAMPLE
47
- pwsh -File scripts\gc-merge.ps1
48
-
49
- .EXAMPLE
50
- pwsh -File scripts\gc-merge.ps1 -Mode merge -CheckTimeoutSec 600
51
- #>
52
- param(
53
- [string]$Branch,
54
- [int]$PR,
55
- [ValidateSet('squash','merge','rebase')][string]$Mode = 'squash',
56
- [int]$CheckTimeoutSec = 300,
57
- [switch]$AllowNoChecks,
58
- [switch]$NoDeleteBranch,
59
- [string]$RepoRoot = (Get-Location).Path,
60
- [switch]$Detailed,
61
- [switch]$Quiet
62
- )
63
- Set-StrictMode -Version Latest
64
- $ErrorActionPreference = 'Stop'
65
- . (Join-Path $PSScriptRoot 'gc.core.ps1')
66
- if ($Detailed) { $script:GcQuiet = $false }
67
- if ($Quiet) { $script:GcQuiet = $true }
68
-
69
- function Get-GcChecksRollup {
70
- param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][int]$Number)
71
- $raw = @(Get-GcGhJson -Root $Root -Argv @('pr','view',"$Number",'--json','statusCheckRollup','--jq','.statusCheckRollup'))
72
- if (-not $raw -or ($raw.Count -eq 1 -and $null -eq $raw[0])) { return @() }
73
- return $raw
74
- }
75
-
76
- function Get-GcChecksVerdict {
77
- <#
78
- 'pass' | 'pending' | 'fail' | 'unknown'. Handles BOTH rollup shapes under
79
- StrictMode: CheckRun items (status/conclusion) and legacy StatusContext
80
- items (state only) — property access is guarded via PSObject.Properties so
81
- a missing property can never throw. 'unknown' = rollup empty (no checks
82
- reported — gh required-check enforcement remains the backstop).
83
- #>
84
- param($Rollup)
85
- if (-not $Rollup) { return 'unknown' }
86
- foreach ($c in $Rollup) {
87
- if ($null -eq $c) { continue } # a null rollup item must not crash the loop
88
- if ($c.PSObject.Properties['status'] -and $c.status -in @('QUEUED','IN_PROGRESS')) { return 'pending' }
89
- if ($c.PSObject.Properties['state'] -and $c.state -in @('FAILURE','ERROR')) { return 'fail' }
90
- if ($c.PSObject.Properties['state'] -and $c.state -in @('PENDING','EXPECTED')) { return 'pending' }
91
- if ($c.PSObject.Properties['conclusion'] -and $c.conclusion -and $c.conclusion -notin @('SUCCESS','NEUTRAL','SKIPPED')) { return 'fail' }
92
- }
93
- return 'pass'
94
- }
95
-
96
- try {
97
- $root = Resolve-GcRoot -Path $RepoRoot
98
- Write-GcInfo "repo: $root"
99
-
100
- $head = if ($Branch) { $Branch } else { Get-GcCurrentBranch -Root $root }
101
- if ($Branch) { Assert-GcRefValue -Name '-Branch' -Value $head }
102
- $default = Get-GcDefaultBranch -Root $root
103
- if ($head -eq $default) {
104
- throw [GcException]::new("you are on the default branch ($default) — nothing to merge; pass -Branch <head> to finish an already-merged PR or gc-branch a new unit of work", $script:GcExitPre)
105
- }
106
-
107
- Assert-GcGh
108
-
109
- # resolve the PR ONCE — statusCheckRollup rides along, so the checks verdict
110
- # costs no second gh call (was: 2x pr view, plus a re-poll per wait tick)
111
- $prFields = 'number,state,headRefName,headRefOid,baseRefName,isDraft,mergeCommit,statusCheckRollup'
112
- $prInfo = $null
113
- if ($PR) {
114
- try { $prInfo = Get-GcGhJson -Root $root -Argv @('pr','view',"$PR",'--json',$prFields) }
115
- catch { throw [GcException]::new("no PR #$PR — $($_.Exception.Message)", $script:GcExitPre) }
116
- if ($prInfo.headRefName -ne $head) {
117
- throw [GcException]::new("PR #$PR is for branch $($prInfo.headRefName), not $head", $script:GcExitPre)
118
- }
119
- } else {
120
- try {
121
- $prInfo = Get-GcGhJson -Root $root -Argv @('pr','view',$head,'--json',$prFields)
122
- } catch {
123
- if ($_.Exception.Message -match 'no pull requests found') {
124
- throw [GcException]::new("no open PR for $head — create one with gc-pr", $script:GcExitPre)
125
- }
126
- throw
127
- }
128
- }
129
-
130
- $n = $prInfo.number
131
- $base = $prInfo.baseRefName
132
- Assert-GcRefValue -Name 'base branch' -Value $base # hostile gh data is validated too
133
- if ($base -ne $default) {
134
- throw [GcException]::new("PR #$n targets base '$base', not the default branch '$default' — mis-targeted PR; retarget it (gh pr edit --base) or merge by hand", $script:GcExitPre)
135
- }
136
- Write-GcInfo "PR #$n : $head -> $base (state $($prInfo.state))"
137
-
138
- if ($prInfo.state -eq 'MERGED') {
139
- Write-GcOk "PR #$n already merged — finishing leftover cleanup"
140
- # truthful method label comes from the merge commit itself (gh exposes
141
- # no message) — resolved after the cleanup fetches it (freshMerged=false).
142
- $mergedSha = if ($prInfo.mergeCommit) { $prInfo.mergeCommit.oid } else { '' }
143
- $freshMerged = $false
144
- # fall through to cleanup only
145
- } elseif ($prInfo.state -eq 'CLOSED') {
146
- throw [GcException]::new("PR #$n is closed — re-open or create a new PR before merging", $script:GcExitPre)
147
- } else {
148
- # main stays green (§6): refuse failing, wait bounded for pending
149
- $verdict = Get-GcChecksVerdict -Rollup @($prInfo.statusCheckRollup | Where-Object { $null -ne $_ })
150
- if ($verdict -eq 'fail') {
151
- throw [GcException]::new('checks are FAILING — main stays green; fix, push, and re-run', $script:GcExitPre)
152
- }
153
- if ($verdict -eq 'unknown' -and -not $AllowNoChecks) {
154
- throw [GcException]::new('no checks visible in the status rollup — refusing; re-run with -AllowNoChecks only when the repository intentionally has no CI checks', $script:GcExitPre)
155
- }
156
- if ($verdict -eq 'unknown') {
157
- Write-GcWarn 'no checks visible; proceeding only because -AllowNoChecks was explicit'
158
- }
159
- if ($verdict -eq 'pending') {
160
- if ($CheckTimeoutSec -le 0) {
161
- throw [GcException]::new('checks still pending and -CheckTimeoutSec 0 — re-run gc-merge when they finish', $script:GcExitPre)
162
- }
163
- # ungated: with chatter off a silent 15s-poll wait looked hung for up
164
- # to 5 minutes. One phase line + one per tick, no change to interval.
165
- Write-GcNotice "checks pending — waiting up to ${CheckTimeoutSec}s (poll every 15s)"
166
- $sw = [System.Diagnostics.Stopwatch]::StartNew()
167
- while ($verdict -eq 'pending' -and $sw.Elapsed.TotalSeconds -lt $CheckTimeoutSec) {
168
- Start-Sleep -Seconds 15
169
- $verdict = Get-GcChecksVerdict -Rollup (Get-GcChecksRollup -Root $root -Number $n)
170
- if ($verdict -eq 'pending') { Write-GcNotice " still waiting: $([int]$sw.Elapsed.TotalSeconds)s elapsed of ${CheckTimeoutSec}s" }
171
- }
172
- if ($verdict -eq 'fail') {
173
- throw [GcException]::new('checks turned FAILING while waiting — main stays green; fix, push, and re-run', $script:GcExitPre)
174
- }
175
- if ($verdict -eq 'pending') {
176
- throw [GcException]::new("checks still pending after ${CheckTimeoutSec}s — re-run gc-merge when they finish", $script:GcExitPre)
177
- }
178
- }
179
- if ($prInfo.isDraft) {
180
- Invoke-GcGh -Root $root -Argv @('pr','ready',"$n")
181
- Write-GcInfo "PR #$n marked ready"
182
- }
183
- $method = Convert-GcMergeMode -Mode $Mode
184
- Write-GcInfo "merging PR #$n with $Mode..."
185
- Invoke-GcGh -Root $root -Argv @('pr','merge',"$n",$method)
186
- $st = Get-GcGhJson -Root $root -Argv @('pr','view',"$n",'--json','state,mergeStateStatus,mergeCommit')
187
- if ($st.state -ne 'MERGED') {
188
- throw [GcException]::new("merge did not land — gh reports mergeStateStatus '$($st.mergeStateStatus)' — likely conflicts: rebase on $default, gc-push -Force (lease), re-run", $script:GcExitPre)
189
- }
190
- $mergedSha = $st.mergeCommit.oid
191
- $freshMerged = $true
192
- Write-GcOk "PR #$n merged ($Mode) @ $mergedSha"
193
- }
194
-
195
- # ----- cleanup: branch deletion, local and remote, verified ------------
196
- $deletedLocal = $false; $deletedRemote = $false; $syncSkipped = $false
197
- $cleanupWarn = $null; $keptWarn = $null
198
- if (-not $NoDeleteBranch) {
199
- try {
200
- Invoke-GcGit -Root $root -Argv @('switch',$base) # cannot delete the branch we are on
201
- if ((Test-GcRef -Root $root -Ref "refs/heads/$head") -and $head -ne (Get-GcCurrentBranch -Root $root)) {
202
- $localNow = (Get-GcGit -Root $root -Argv @('rev-parse',$head) | Select-Object -First 1).Trim()
203
- if ($localNow -eq $prInfo.headRefOid) {
204
- Invoke-GcGit -Root $root -Argv @('branch','-D',$head)
205
- $deletedLocal = $true
206
- } else {
207
- $keptWarn = "local $head moved after merge ($localNow != merged $($prInfo.headRefOid)) — left intact (name re-used?)"
208
- }
209
- }
210
- $remote = $null
211
- try { $remote = Get-GcRemote -Root $root } catch { }
212
- if ($remote) {
213
- $remoteHeads = @(Get-GcGit -Root $root -Argv @('ls-remote','--heads',$remote,$head))
214
- if ($remoteHeads) {
215
- # remote delete is oid-gated like the local one: a post-merge
216
- # push or a re-used name must never be wiped.
217
- $remoteSha = ($remoteHeads[0] -split "`t")[0].Trim()
218
- if ($remoteSha -eq $prInfo.headRefOid) {
219
- Invoke-GcGit -Root $root -Argv @('push',$remote,'--delete',$head)
220
- $deletedRemote = $true
221
- } else {
222
- $keptWarn = "remote $head moved after merge ($remoteSha != merged $($prInfo.headRefOid)) — remote left intact"
223
- }
224
- }
225
- }
226
- $remotes = @(Get-GcGit -Root $root -Argv @('remote'))
227
- if ($remotes -contains 'origin') {
228
- Invoke-GcGit -Root $root -Argv @('fetch','--prune','origin')
229
- }
230
- } catch {
231
- $cleanupWarn = "cleanup incomplete: $($_.Exception.Message)"
232
- }
233
- # post-merge sync is best-effort: a dirty tree or stray untracked files
234
- # must never fail an already-landed merge — warn instead, self-heal later.
235
- try {
236
- $null = Sync-GcDefaultBranch -Root $root -Default $base -CurrentBranch (Get-GcCurrentBranch -Root $root)
237
- } catch {
238
- $syncSkipped = $true
239
- Write-GcWarn "post-merge sync skipped: $($_.Exception.Message)"
240
- }
241
- if ($cleanupWarn) { Write-GcWarn $cleanupWarn }
242
- if ($keptWarn) { Write-GcWarn $keptWarn }
243
- }
244
-
245
- # truthful merge-method label: our own run knows it; an already-merged PR's
246
- # method is read from the merge commit itself (now fetched by the cleanup)
247
- $modeOut = if ($freshMerged) { $Mode } else { Get-GcMergedMethod -Root $root -Sha $mergedSha }
248
-
249
- $props = @{
250
- number = $n
251
- mode = $modeOut
252
- sha = $mergedSha
253
- branch = $head
254
- branch_deleted_local = $deletedLocal
255
- branch_deleted_remote = $deletedRemote
256
- sync_skipped = $syncSkipped
257
- }
258
- if ($keptWarn) { $props.branch_kept = $keptWarn }
259
- if ($cleanupWarn) {
260
- $props.cleanup = $cleanupWarn
261
- Write-GcFail "merged but cleanup incomplete: $cleanupWarn — re-run gc-merge to finish it"
262
- Write-GcResult -Code $script:GcExitFail -Props $props
263
- }
264
- Write-GcOk "PR #$n merged ($modeOut) — branch cleanup done"
265
- Write-GcResult -Props $props
266
- } catch [GcException] {
267
- Write-GcFail $_.Exception.Message
268
- Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
269
- } catch {
270
- Write-GcFail "unexpected: $($_.Exception.Message)"
271
- Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
272
- }
package/scripts/gc-pr.ps1 DELETED
@@ -1,190 +0,0 @@
1
- #Requires -Version 7.0
2
- <#
3
- .SYNOPSIS
4
- Open (or update) the pull request with the ceremony body. No editor, no
5
- prompts, no human in the middle.
6
-
7
- .DESCRIPTION
8
- git-ceremony §4 as a script. Title defaults to the branch head commit subject
9
- ("Title = the commit subject"). Body is exactly the fixed shape:
10
-
11
- What: <one line>
12
- Why: <one line, omitted when obvious>
13
- Check: <the single command that proves it, or n/a>
14
- Risk: <one line, or low>
15
-
16
- Self-healing: an existing open PR for the branch is updated in place; a
17
- closed PR is reopened and updated; an already-merged PR is a clean no-op.
18
- Requires gh (exit 3 when missing or unauthenticated).
19
-
20
- Repo rules win (§0): a repo with its own established PR structure — a
21
- .github/PULL_REQUEST_TEMPLATE.md, or a consistent sibling-PR style — supplies
22
- its body verbatim with -BodyFile (or -Body). The fixed shape above is the
23
- FALLBACK ceremony for a repo that is silent.
24
-
25
- .PARAMETER Title
26
- PR title. Defaults to the branch head commit subject; validated with the
27
- same rule as the commit subject.
28
- .PARAMETER What
29
- One line: what this PR does. Required unless -Body/-BodyFile supplies the
30
- repo's own body.
31
- .PARAMETER Why
32
- One line: why it exists. Omit (leave empty) when obvious.
33
- .PARAMETER Check
34
- The single command that proves it. Defaults to n/a.
35
- .PARAMETER Risk
36
- One line risk. Defaults to low.
37
- .PARAMETER Body
38
- The repo's own PR body, verbatim, for a repo with an established structure.
39
- Mutually exclusive with -BodyFile.
40
- .PARAMETER BodyFile
41
- Path to a file holding the repo's own PR body, used verbatim. A missing,
42
- unreadable or empty file is a loud stop (exit 2) — never a silent empty body.
43
- .PARAMETER Base
44
- Base branch. Defaults to the repo default branch.
45
- .PARAMETER Draft
46
- Open as a draft (ready only when the check passes, §4).
47
- .PARAMETER RepoRoot
48
- Repository path (defaults to the current directory); gh is run from the repo
49
- root.
50
- .PARAMETER Detailed
51
- Restore the step narration, ok/info lines, and raw git/gh relay the terse
52
- default hides. Never affects the RESULT line, warnings, failures, or the
53
- security/remediation lines.
54
- .PARAMETER Quiet
55
- Accepted for compatibility and now a no-op: the default is already terse.
56
- -Quiet forces the gate closed and so wins if passed with -Detailed.
57
-
58
- .EXAMPLE
59
- pwsh -File scripts\gc-pr.ps1 -What 'Cap retry backoff at 30s' `
60
- -Check 'dotnet test' -Risk 'low' -Draft
61
-
62
- .EXAMPLE
63
- # the repo has its own PR structure (§0): hand it over verbatim
64
- pwsh -File scripts\gc-pr.ps1 -BodyFile .\.docs\pr-body.md
65
- #>
66
- param(
67
- [string]$Title,
68
- [string]$What,
69
- [string]$Why,
70
- [string]$Check,
71
- [string]$Risk,
72
- [string]$Body,
73
- [string]$BodyFile,
74
- [string]$Base,
75
- [switch]$Draft,
76
- [string]$RepoRoot = (Get-Location).Path,
77
- [switch]$Detailed,
78
- [switch]$Quiet
79
- )
80
- Set-StrictMode -Version Latest
81
- $ErrorActionPreference = 'Stop'
82
- . (Join-Path $PSScriptRoot 'gc.core.ps1')
83
- if ($Detailed) { $script:GcQuiet = $false }
84
- if ($Quiet) { $script:GcQuiet = $true }
85
-
86
- try {
87
- $root = Resolve-GcRoot -Path $RepoRoot
88
- Write-GcInfo "repo: $root"
89
-
90
- $cur = Get-GcCurrentBranch -Root $root
91
- $default = Get-GcDefaultBranch -Root $root
92
- $base = if ($Base) { $Base } else { $default }
93
- if ($Base) { Assert-GcRefValue -Name '-Base' -Value $base }
94
- Write-GcInfo "head: $cur base: $base"
95
-
96
- # precondition, before gh: the head must already exist on the remote
97
- # (§4 flow: push first). A forgotten gc-push must say so, not fail deep in gh.
98
- $remote = Get-GcRemote -Root $root
99
- if (-not @(Get-GcGit -Root $root -Argv @('ls-remote','--heads',$remote,$cur))) {
100
- throw [GcException]::new("$cur is not on $remote — run gc-push first", $script:GcExitPre)
101
- }
102
- Assert-GcGh
103
-
104
- # title defaults to the commit subject, and is validated like one (§4)
105
- if (-not $Title) { $Title = (Get-GcGit -Root $root -Argv @('log','-1','--format=%s') | Select-Object -First 1).Trim() }
106
- Get-GcSubjectParts -Subject $Title | Out-Null # throws Pre with the fix on any violation
107
-
108
- # body (§0 precedence): a repo with its own established PR structure
109
- # supplies it verbatim via -Body/-BodyFile; the fixed What/Why/Check/Risk
110
- # shape is the FALLBACK for a repo that is silent. An override that is
111
- # missing, unreadable or empty is a loud stop — a silently empty PR body is
112
- # worse than a failed run.
113
- $hasBody = $PSBoundParameters.ContainsKey('Body')
114
- $hasBodyFile = $PSBoundParameters.ContainsKey('BodyFile')
115
- if ($hasBody -and $hasBodyFile) {
116
- throw [GcException]::new('-Body and -BodyFile are mutually exclusive — pass one body', $script:GcExitPre)
117
- }
118
- if ($hasBodyFile) {
119
- if (-not $BodyFile -or -not (Test-Path -LiteralPath $BodyFile -PathType Leaf)) {
120
- throw [GcException]::new("-BodyFile not found (or not a file): '$BodyFile' — pass the path to an existing PR body file", $script:GcExitPre)
121
- }
122
- try { $body = Get-Content -LiteralPath $BodyFile -Raw }
123
- catch { throw [GcException]::new("-BodyFile could not be read: '$BodyFile' — $($_.Exception.Message)", $script:GcExitPre) }
124
- if (-not $body -or -not $body.Trim()) {
125
- throw [GcException]::new("-BodyFile is empty: '$BodyFile' — the PR body must not be blank", $script:GcExitPre)
126
- }
127
- if ($What -or $Why -or $Check -or $Risk) {
128
- Write-GcWarn '-What/-Why/-Check/-Risk are ignored when -BodyFile supplies the body'
129
- }
130
- } elseif ($hasBody) {
131
- if (-not $Body -or -not $Body.Trim()) {
132
- throw [GcException]::new('-Body is empty — drop it to get the fixed What/Why/Check/Risk body', $script:GcExitPre)
133
- }
134
- $body = $Body
135
- } else {
136
- # fallback: exactly the fixed shape, one line per field
137
- foreach ($v in @($What, $Why, $Check, $Risk)) {
138
- if ($v -and ($v -match '\r?\n')) { throw [GcException]::new('body fields must be one line each — What/Why/Check/Risk', $script:GcExitPre) }
139
- }
140
- if (-not $What) { throw [GcException]::new('-What is required (or supply -Body/-BodyFile)', $script:GcExitPre) }
141
- $body = Format-GcPrBody -What $What -Why $Why -Check $Check -Risk $Risk
142
- }
143
-
144
- # self-heal: reuse an existing PR for this branch — but a merged PR is a
145
- # no-op ONLY when its head still matches local (a recreated/re-pushed
146
- # branch with new commits must get a FRESH PR, never a false no-op).
147
- $exists = $null
148
- try {
149
- $exists = Get-GcGhJson -Root $root -Argv @('pr','view',$cur,'--json','number,state,headRefOid')
150
- } catch {
151
- if ($_.Exception.Message -notmatch 'no pull requests found') { throw }
152
- }
153
-
154
- if ($exists) {
155
- if ($exists.state -eq 'MERGED') {
156
- $localHead = (Get-GcGit -Root $root -Argv @('rev-parse',$cur) | Select-Object -First 1).Trim()
157
- if ($localHead -eq $exists.headRefOid) {
158
- Write-GcOk "PR #$($exists.number) for $cur is already merged (head unchanged)"
159
- Write-GcResult -Props @{ number = $exists.number; action = 'no-op'; state = 'merged' }
160
- }
161
- Write-GcWarn "PR #$($exists.number) is merged but $cur has moved on ($($localHead.Substring(0,[Math]::Min(7,$localHead.Length))) != $($exists.headRefOid.Substring(0,7))) — creating a fresh PR"
162
- $exists = $null # fresh PR for the new commits
163
- } elseif ($exists.state -eq 'CLOSED') {
164
- Invoke-GcGh -Root $root -Argv @('pr','reopen',"$($exists.number)")
165
- Write-GcInfo "reopened PR #$($exists.number)"
166
- }
167
- if ($exists) {
168
- $argv = @('pr','edit',"$($exists.number)",'--title',$Title,'--body',$body)
169
- # draft is set at create only — gh pr edit has no --draft (cannot be toggled on update)
170
- Invoke-GcGh -Root $root -Argv $argv
171
- $action = if ($exists.state -eq 'CLOSED') { 'reopened' } else { 'updated' }
172
- Write-GcOk "PR #$($exists.number) $action"
173
- $r = Get-GcGhJson -Root $root -Argv @('pr','view',"$($exists.number)",'--json','number,url')
174
- Write-GcResult -Props @{ number = $r.number; url = $r.url; action = $action }
175
- }
176
- }
177
-
178
- $argv = @('pr','create','--base',$base,'--head',$cur,'--title',$Title,'--body',$body)
179
- if ($Draft) { $argv += '--draft' }
180
- Invoke-GcGh -Root $root -Argv $argv
181
- $r = Get-GcGhJson -Root $root -Argv @('pr','view',$cur,'--json','number,url,isDraft')
182
- Write-GcOk "PR #$($r.number) created ($(if ($r.isDraft) { 'draft' } else { 'ready' }))"
183
- Write-GcResult -Props @{ number = $r.number; url = $r.url; action = 'created'; draft = $r.isDraft }
184
- } catch [GcException] {
185
- Write-GcFail $_.Exception.Message
186
- Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
187
- } catch {
188
- Write-GcFail "unexpected: $($_.Exception.Message)"
189
- Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
190
- }