oc-harness-setup 0.1.1 → 0.3.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.
- package/.docs/unwired-routing.md +14 -9
- package/.gitignore +14 -1
- package/AGENTS.md +70 -106
- package/README.md +31 -27
- package/agents/build.md +10 -12
- package/agents/explore.md +14 -8
- package/agents/general.md +7 -9
- package/agents/orchestrator.md +38 -0
- package/agents/plan.md +10 -13
- package/agents/reviewer.md +9 -14
- package/agents/vault.md +44 -35
- package/bin/cli.js +323 -81
- package/commands/build.md +2 -8
- package/commands/checkpoint.md +3 -1
- package/commands/code-simplify.md +3 -9
- package/commands/gauntlet.md +7 -0
- package/commands/handoff.md +3 -1
- package/commands/keeper.md +3 -3
- package/commands/kill.md +11 -0
- package/commands/plan.md +2 -13
- package/commands/retro.md +15 -0
- package/commands/review.md +1 -1
- package/commands/ship.md +3 -27
- package/commands/spec.md +3 -11
- package/commands/test.md +2 -9
- package/commands/webperf.md +7 -0
- package/opencode.jsonc +23 -8
- package/package.json +3 -3
- package/reference/README.md +14 -14
- package/reference/auto-mandate.md +11 -0
- package/reference/backup-convention.md +9 -0
- package/reference/clean-mandate.md +13 -0
- package/reference/editor-parity.md +7 -0
- package/reference/gc-scripts.md +8 -0
- package/reference/intent-routing.md +14 -0
- package/reference/lifecycle.md +15 -0
- package/reference/model-keeper.md +30 -10
- package/reference/model-test.md +13 -8
- package/reference/models.md +25 -14
- package/reference/oc-source-map.md +162 -0
- package/reference/owner-pin.md +31 -0
- package/reference/roster.md +15 -0
- package/reference/session-scope.md +9 -0
- package/reference/session-state.md +13 -0
- package/reference/swarm.md +32 -0
- package/scripts/backup-config.ps1 +42 -0
- package/scripts/gc-branch.ps1 +196 -0
- package/scripts/gc-bump.ps1 +198 -0
- package/scripts/gc-clean.ps1 +648 -0
- package/scripts/gc-commit.ps1 +143 -0
- package/scripts/gc-merge.ps1 +272 -0
- package/scripts/gc-pr.ps1 +190 -0
- package/scripts/gc-push.ps1 +111 -0
- package/scripts/gc-read.ps1 +150 -0
- package/scripts/gc-rebase.ps1 +162 -0
- package/scripts/gc-release.ps1 +225 -0
- package/scripts/gc-stage.ps1 +103 -0
- package/scripts/gc-status.ps1 +127 -0
- package/scripts/gc-sync.ps1 +65 -0
- package/scripts/gc.core.ps1 +715 -0
- package/scripts/gc.smoke.ps1 +779 -0
- package/scripts/harness-doctor.ps1 +11 -9
- package/scripts/interrupt-session.ps1 +65 -0
- package/scripts/logbook/README.md +108 -0
- package/scripts/logbook/logbook.test.ts +440 -0
- package/scripts/logbook/logbook.ts +797 -0
- package/scripts/pirep/README.md +147 -0
- package/scripts/pirep/pirep.test.ts +735 -0
- package/scripts/pirep/pirep.ts +836 -0
- package/scripts/testflight/README.md +112 -0
- package/scripts/testflight/testflight.test.ts +512 -0
- package/scripts/testflight/testflight.ts +806 -0
- package/skills/_shared/SOURCES.md +7 -7
- package/skills/_shared/references/definition-of-done.md +2 -2
- package/skills/_shared/references/orchestration-patterns.md +1 -2
- package/skills/_shared/references/security-checklist.md +2 -2
- package/skills/api-and-interface-design/SKILL.md +7 -360
- package/skills/browser-testing-with-devtools/SKILL.md +303 -0
- package/skills/code-simplification/SKILL.md +7 -364
- package/skills/creative-writing/SKILL.md +1 -1
- package/skills/debugging-and-error-recovery/SKILL.md +8 -309
- package/skills/flight-deck/SKILL.md +17 -0
- package/skills/frontend-ui-engineering/SKILL.md +8 -320
- package/skills/gauntlet/SKILL.md +21 -0
- package/skills/git-ceremony/SKILL.md +16 -318
- package/skills/grilling/SKILL.md +10 -30
- package/skills/observability-and-instrumentation/SKILL.md +9 -229
- package/skills/performance-optimization/SKILL.md +8 -488
- package/skills/pilot-report/SKILL.md +18 -0
- package/skills/planning-and-task-breakdown/SKILL.md +8 -249
- package/skills/security-and-hardening/SKILL.md +9 -490
- package/skills/source-driven-development/SKILL.md +8 -208
- package/skills/spec-driven-development/SKILL.md +15 -234
- package/skills/test-driven-development/SKILL.md +8 -388
- package/skills/test-flight/SKILL.md +14 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +3 -3
- package/skills/writing-for-agents/SKILL.md +7 -1
- package/agents/coder.md +0 -19
- package/agents/documenter.md +0 -28
- package/agents/keeper.md +0 -22
- package/agents/master.md +0 -65
- package/agents/researcher.md +0 -21
- package/agents/security-auditor.md +0 -20
- package/agents/test-engineer.md +0 -20
- package/agents/web-performance-auditor.md +0 -19
- package/commands/council.md +0 -24
- package/commands/doctor.md +0 -18
- package/commands/ponytail-audit.md +0 -7
- package/commands/ponytail-debt.md +0 -14
- package/reference/models.md.example +0 -21
- package/scripts/panic/panic.ts +0 -240
- package/skills/code-review-and-quality/SKILL.md +0 -396
- package/skills/incremental-implementation/SKILL.md +0 -249
- package/skills/swarm-orchestration/SKILL.md +0 -54
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Push the current branch. Self-healing upstream: a branch with no upstream is
|
|
5
|
+
pushed with -u automatically; a rejected push needs a rebase, or -Force
|
|
6
|
+
which retries with --force-with-lease only.
|
|
7
|
+
|
|
8
|
+
.DESCRIPTION
|
|
9
|
+
git-ceremony §4/§6 push rails as a script. Always pins git -C and pushes an
|
|
10
|
+
explicit ref — never the ambient branch. Force-push is lease-only and is
|
|
11
|
+
REFUSED outright on the default branch (never force-push a shared branch).
|
|
12
|
+
Local-only repos (no remote) fail cleanly with exit 2.
|
|
13
|
+
|
|
14
|
+
Repo rules win: if the repo's branch protection dictates push behavior,
|
|
15
|
+
follow that instead of this script.
|
|
16
|
+
|
|
17
|
+
.PARAMETER Remote
|
|
18
|
+
Remote name; defaults to origin, else the sole remote when unambiguous.
|
|
19
|
+
.PARAMETER Force
|
|
20
|
+
Retry a rejected push with --force-with-lease — never plain --force. Only
|
|
21
|
+
meaningful on your own PR branch.
|
|
22
|
+
.PARAMETER RepoRoot
|
|
23
|
+
Repository path (defaults to the current directory); git is always pinned
|
|
24
|
+
with git -C.
|
|
25
|
+
.PARAMETER Detailed
|
|
26
|
+
Restore the step narration, ok/info lines, and raw git/gh relay the terse
|
|
27
|
+
default hides. Never affects the RESULT line, warnings, failures, or the
|
|
28
|
+
security/remediation lines.
|
|
29
|
+
.PARAMETER Quiet
|
|
30
|
+
Accepted for compatibility and now a no-op: the default is already terse.
|
|
31
|
+
-Quiet forces the gate closed and so wins if passed with -Detailed.
|
|
32
|
+
|
|
33
|
+
.EXAMPLE
|
|
34
|
+
pwsh -File scripts\gc-push.ps1
|
|
35
|
+
|
|
36
|
+
.EXAMPLE
|
|
37
|
+
pwsh -File scripts\gc-push.ps1 -Force
|
|
38
|
+
#>
|
|
39
|
+
param(
|
|
40
|
+
[string]$Remote,
|
|
41
|
+
[switch]$Force,
|
|
42
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
43
|
+
[switch]$Detailed,
|
|
44
|
+
[switch]$Quiet
|
|
45
|
+
)
|
|
46
|
+
Set-StrictMode -Version Latest
|
|
47
|
+
$ErrorActionPreference = 'Stop'
|
|
48
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
49
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
50
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
54
|
+
Write-GcInfo "repo: $root"
|
|
55
|
+
|
|
56
|
+
# push needs the branch name and nothing else — a targeted rev-parse, not a
|
|
57
|
+
# full worktree walk (the walk cost scales with the repo; this is the path
|
|
58
|
+
# the old twelve-call preamble kept cheap).
|
|
59
|
+
$cur = Get-GcCurrentBranch -Root $root -Targeted
|
|
60
|
+
$default = Get-GcDefaultBranch -Root $root
|
|
61
|
+
if ($Force) {
|
|
62
|
+
if ($cur -eq $default) {
|
|
63
|
+
throw [GcException]::new("refusing to force-push the default branch ($default) — §6: never force-push a shared branch", $script:GcExitPre)
|
|
64
|
+
}
|
|
65
|
+
# §6: force-push only your own PR branch — a type/slug branch.
|
|
66
|
+
if ($cur -cnotmatch '^[a-z]+(/[a-z0-9-]+)+$') {
|
|
67
|
+
throw [GcException]::new("force-push only your own PR branch (§6) — '$cur' is not a <type>/<slug> branch; never force a shared branch", $script:GcExitPre)
|
|
68
|
+
}
|
|
69
|
+
Write-GcWarn 'lease-only: protects against a stale tracking ref, but a fresh fetch right after a teammate push can defeat it — verify you own this branch'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
$remote = if ($Remote) {
|
|
73
|
+
if (-not (@(Get-GcGit -Root $root -Argv @('remote')) -contains $Remote)) {
|
|
74
|
+
throw [GcException]::new("remote '$Remote' does not exist", $script:GcExitPre)
|
|
75
|
+
}
|
|
76
|
+
$Remote
|
|
77
|
+
} else { Get-GcRemote -Root $root }
|
|
78
|
+
|
|
79
|
+
$hasUpstream = $true
|
|
80
|
+
try { Get-GcGit -Root $root -Argv @('rev-parse','--abbrev-ref','--symbolic-full-name',"${cur}@{upstream}") | Out-Null } catch { $hasUpstream = $false }
|
|
81
|
+
|
|
82
|
+
$argv = if ($hasUpstream) { @('push',$remote,$cur) } else { @('push','-u',$remote,$cur) }
|
|
83
|
+
$FAILED_REMOTE_RE = 'rejected|non-fast-forward|fetch first|not fast-forward|stale info'
|
|
84
|
+
$usedForce = $false
|
|
85
|
+
try {
|
|
86
|
+
Invoke-GcGit -Root $root -Argv $argv
|
|
87
|
+
} catch {
|
|
88
|
+
$isRemoteReject = $_.Exception.Message -match $FAILED_REMOTE_RE
|
|
89
|
+
if ($isRemoteReject -and $Force) {
|
|
90
|
+
Write-GcWarn 'push rejected — retrying with --force-with-lease'
|
|
91
|
+
Invoke-GcGit -Root $root -Argv @('push','--force-with-lease',$remote,$cur)
|
|
92
|
+
$usedForce = $true
|
|
93
|
+
} elseif ($isRemoteReject) {
|
|
94
|
+
throw [GcException]::new("push rejected (non-fast-forward) — rebase on $remote/$cur first, or retry with -Force (--force-with-lease only)", $script:GcExitPre)
|
|
95
|
+
} else {
|
|
96
|
+
throw # network/auth/other — original error
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
$sha = (Get-GcGit -Root $root -Argv @('rev-parse',$cur) | Select-Object -First 1).Trim()
|
|
101
|
+
$short = (Get-GcGit -Root $root -Argv @('rev-parse','--short',$cur) | Select-Object -First 1).Trim()
|
|
102
|
+
$action = if ($usedForce) { 'forced' } elseif (-not $hasUpstream) { 'pushed-with-upstream' } else { 'pushed' }
|
|
103
|
+
Write-GcOk "pushed $cur -> $remote/$cur @ $short"
|
|
104
|
+
Write-GcResult -Props @{ branch = $cur; remote = $remote; sha = $sha; action = $action }
|
|
105
|
+
} catch [GcException] {
|
|
106
|
+
Write-GcFail $_.Exception.Message
|
|
107
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
108
|
+
} catch {
|
|
109
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
110
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
111
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Read-only git surface for the git-ceremony toolset — one selector, six reads,
|
|
5
|
+
zero writes.
|
|
6
|
+
|
|
7
|
+
.DESCRIPTION
|
|
8
|
+
The ceremony scripts cover mutation; this covers inspection, so an
|
|
9
|
+
MCP-routed agent never has to drop to raw git to review the staged diff
|
|
10
|
+
(git-ceremony §3's last gate) or to look at history. Every read is pinned
|
|
11
|
+
`git -C <root>` and drawn from a fixed, read-only subcommand set — there is
|
|
12
|
+
no code path here that can touch the index, the working tree, a ref, or a
|
|
13
|
+
remote.
|
|
14
|
+
|
|
15
|
+
Selectors (-What):
|
|
16
|
+
diff-staged git diff --staged (the §3 pre-commit gate)
|
|
17
|
+
diff git diff (unstaged changes)
|
|
18
|
+
log git log --oneline-like (newest -Limit, default 20)
|
|
19
|
+
show git show --stat (needs -Rev)
|
|
20
|
+
branch-list local branches + upstream + head sha
|
|
21
|
+
status delegates to gc-status.ps1 (reuse, not reimplementation)
|
|
22
|
+
|
|
23
|
+
Output is the standard contract: exactly one stdout line `RESULT: <json>`
|
|
24
|
+
(see gc.core.ps1). Text payloads (diff/show) are relayed verbatim in the
|
|
25
|
+
RESULT — reads are free, so nothing is truncated here; scope a diff with
|
|
26
|
+
-Path and cap history with -Limit instead.
|
|
27
|
+
|
|
28
|
+
.PARAMETER What
|
|
29
|
+
One of: diff-staged · diff · log · show · branch-list · status.
|
|
30
|
+
.PARAMETER Path
|
|
31
|
+
Optional single pathspec to scope -What diff-staged / diff.
|
|
32
|
+
.PARAMETER Rev
|
|
33
|
+
Revision for -What show (required there); ref-shaped and validated.
|
|
34
|
+
.PARAMETER Limit
|
|
35
|
+
Maximum commits for -What log (default 20; must be >= 1).
|
|
36
|
+
.PARAMETER RepoRoot
|
|
37
|
+
Repository path (defaults to the current directory).
|
|
38
|
+
.PARAMETER Detailed
|
|
39
|
+
Restore the step narration, ok/info lines, and raw git/gh relay the terse
|
|
40
|
+
default hides. gc-read's payload (diff/show/log) is data and is always in the
|
|
41
|
+
RESULT line, so -Detailed never gates it.
|
|
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-read.ps1 -What diff-staged
|
|
48
|
+
.EXAMPLE
|
|
49
|
+
pwsh -File scripts\gc-read.ps1 -What log -Limit 5
|
|
50
|
+
.EXAMPLE
|
|
51
|
+
pwsh -File scripts\gc-read.ps1 -What show -Rev HEAD
|
|
52
|
+
#>
|
|
53
|
+
param(
|
|
54
|
+
[Parameter(Mandatory)][string]$What,
|
|
55
|
+
[string]$Path,
|
|
56
|
+
[string]$Rev,
|
|
57
|
+
[int]$Limit = 20,
|
|
58
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
59
|
+
[switch]$Detailed,
|
|
60
|
+
[switch]$Quiet
|
|
61
|
+
)
|
|
62
|
+
Set-StrictMode -Version Latest
|
|
63
|
+
$ErrorActionPreference = 'Stop'
|
|
64
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
65
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
66
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
67
|
+
|
|
68
|
+
$script:GcReadSelectors = @('diff-staged','diff','log','show','branch-list','status')
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
# validated in-body (not a ValidateSet) so a bad selector still emits the
|
|
72
|
+
# contract RESULT line and exit 2, never a bare pwsh binder failure.
|
|
73
|
+
if ($script:GcReadSelectors -cnotcontains $What) {
|
|
74
|
+
throw [GcException]::new("-What '$What' is not one of: $($script:GcReadSelectors -join ', ')", $script:GcExitPre)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if ($What -eq 'status') {
|
|
78
|
+
# reuse the existing read surface: run gc-status.ps1 and relay its single
|
|
79
|
+
# RESULT line + exit code byte-for-byte. No reimplementation, no second
|
|
80
|
+
# source of truth for the snapshot shape. Delegated BEFORE resolving the
|
|
81
|
+
# root: the child runs the same `rev-parse --show-toplevel` itself, so
|
|
82
|
+
# resolving here first would be a second, wasted spawn.
|
|
83
|
+
$pwsh = (Get-Process -Id $PID).Path
|
|
84
|
+
if (-not $pwsh) { $pwsh = 'pwsh' }
|
|
85
|
+
$child = & $pwsh -NoProfile -NonInteractive -File (Join-Path $PSScriptRoot 'gc-status.ps1') -RepoRoot $RepoRoot -Quiet 2>&1
|
|
86
|
+
$code = $LASTEXITCODE
|
|
87
|
+
$res = @($child | ForEach-Object { "$_" } | Where-Object { $_ -match '^RESULT: ' } | Select-Object -Last 1)
|
|
88
|
+
if ($res.Count -eq 1) { Write-Output $res[0]; exit $code }
|
|
89
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = 'gc-read: status relay produced no RESULT line' }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
93
|
+
|
|
94
|
+
$branch = try { Get-GcCurrentBranch -Root $root } catch { '(detached)' }
|
|
95
|
+
|
|
96
|
+
switch ($What) {
|
|
97
|
+
'diff-staged' {
|
|
98
|
+
$argv = @('diff','--staged','--no-color')
|
|
99
|
+
if ($Path) { $argv += @('--',$Path) }
|
|
100
|
+
$text = (@(Get-GcGit -Root $root -Argv $argv) -join "`n")
|
|
101
|
+
Write-GcResult -Props @{ what = $What; repo = $root; branch = $branch; empty = [string]::IsNullOrEmpty($text); diff = $text }
|
|
102
|
+
}
|
|
103
|
+
'diff' {
|
|
104
|
+
$argv = @('diff','--no-color')
|
|
105
|
+
if ($Path) { $argv += @('--',$Path) }
|
|
106
|
+
$text = (@(Get-GcGit -Root $root -Argv $argv) -join "`n")
|
|
107
|
+
Write-GcResult -Props @{ what = $What; repo = $root; branch = $branch; empty = [string]::IsNullOrEmpty($text); diff = $text }
|
|
108
|
+
}
|
|
109
|
+
'log' {
|
|
110
|
+
if ($Limit -le 0) { throw [GcException]::new('-Limit must be >= 1', $script:GcExitPre) }
|
|
111
|
+
$raw = @(Get-GcGit -Root $root -Argv @('log','-n',"$Limit",'--no-color','--pretty=format:%h%x09%s'))
|
|
112
|
+
$commits = @($raw | Where-Object { $_ } | ForEach-Object {
|
|
113
|
+
$parts = "$_" -split "`t", 2
|
|
114
|
+
[pscustomobject]@{ sha = $parts[0]; subject = if ($parts.Count -gt 1) { $parts[1] } else { '' } }
|
|
115
|
+
})
|
|
116
|
+
Write-GcResult -Props @{ what = $What; repo = $root; branch = $branch; count = $commits.Count; commits = $commits }
|
|
117
|
+
}
|
|
118
|
+
'show' {
|
|
119
|
+
if (-not $Rev) { throw [GcException]::new('-What show needs -Rev <ref> — e.g. -Rev HEAD', $script:GcExitPre) }
|
|
120
|
+
Assert-GcRefValue -Name '-Rev' -Value $Rev
|
|
121
|
+
$text = (@(Get-GcGit -Root $root -Argv @('show','--no-color','--stat','--format=fuller',$Rev)) -join "`n")
|
|
122
|
+
Write-GcResult -Props @{ what = $What; repo = $root; branch = $branch; rev = $Rev; text = $text }
|
|
123
|
+
}
|
|
124
|
+
'branch-list' {
|
|
125
|
+
# literal tab, not %x09: `git branch --format` does not expand %xNN
|
|
126
|
+
# (it prints it verbatim), so the separator is a real tab character.
|
|
127
|
+
$tab = [char]9
|
|
128
|
+
$fmt = '%(HEAD)' + $tab + '%(refname:short)' + $tab + '%(upstream:short)' + $tab + '%(objectname:short)'
|
|
129
|
+
$raw = @(Get-GcGit -Root $root -Argv @('branch','--no-color',"--format=$fmt"))
|
|
130
|
+
$branches = @($raw | Where-Object { $_ } | ForEach-Object {
|
|
131
|
+
$p = "$_" -split "`t"
|
|
132
|
+
[pscustomobject]@{
|
|
133
|
+
current = ($p[0].Trim() -eq '*')
|
|
134
|
+
name = if ($p.Count -gt 1) { $p[1] } else { '' }
|
|
135
|
+
upstream = if ($p.Count -gt 2) { $p[2] } else { '' }
|
|
136
|
+
sha = if ($p.Count -gt 3) { $p[3] } else { '' }
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
$cur = $branches | Where-Object { $_.current } | Select-Object -First 1
|
|
140
|
+
$current = if ($cur) { $cur.name } else { $null }
|
|
141
|
+
Write-GcResult -Props @{ what = $What; repo = $root; branch = $branch; current = $current; count = $branches.Count; branches = $branches }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
} catch [GcException] {
|
|
145
|
+
Write-GcFail $_.Exception.Message
|
|
146
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
147
|
+
} catch {
|
|
148
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
149
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
150
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Rebase the current branch onto a target ref (default: the synced default
|
|
5
|
+
branch). Conflict-aware: a conflict leaves the rebase in progress and exits
|
|
6
|
+
2 (agent-fixable stop) with state=conflict; the agent resolves, then
|
|
7
|
+
-Continue; or -Abort to roll back cleanly. No editor, no prompts, no human
|
|
8
|
+
in the middle.
|
|
9
|
+
|
|
10
|
+
.DESCRIPTION
|
|
11
|
+
The rebase rail of ceremony §6 as a script: if main moved, rebase your
|
|
12
|
+
branch on it and resolve THERE — never on main. This script:
|
|
13
|
+
- syncs the default branch first (-NoSync to skip; the base is then whatever
|
|
14
|
+
the target ref points at),
|
|
15
|
+
- runs `git rebase <target>` — a conflict stops it in place (never aborts
|
|
16
|
+
on its own), exits 2 with state=conflict and clear next steps; -Onto is
|
|
17
|
+
ref-validated (a leading dash is rejected, no option injection),
|
|
18
|
+
- -Continue resumes after resolution (GIT_EDITOR forced to true so a
|
|
19
|
+
pending editor prompt can never block an agent),
|
|
20
|
+
- -Abort returns to the pre-rebase branch exactly — refused while resolved
|
|
21
|
+
files exist, because abort would silently discard them,
|
|
22
|
+
- refuses to run while another rebase is in progress (use -Continue/-Abort).
|
|
23
|
+
After a successful rebase, push with gc-push -Force (--force-with-lease).
|
|
24
|
+
Repo rules win: if the repo documents its own convention, follow that
|
|
25
|
+
instead of this script.
|
|
26
|
+
|
|
27
|
+
.PARAMETER Onto
|
|
28
|
+
Rebase target ref. Defaults to the repo default branch.
|
|
29
|
+
.PARAMETER Continue
|
|
30
|
+
Resume a stopped rebase after conflict resolution.
|
|
31
|
+
.PARAMETER Abort
|
|
32
|
+
Cancel a stopped rebase and restore the pre-rebase state.
|
|
33
|
+
.PARAMETER NoSync
|
|
34
|
+
Skip the default-branch sync before rebasing.
|
|
35
|
+
.PARAMETER RepoRoot
|
|
36
|
+
Repository path (defaults to the current directory); git is always pinned
|
|
37
|
+
with git -C.
|
|
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-rebase.ps1
|
|
48
|
+
|
|
49
|
+
.EXAMPLE
|
|
50
|
+
pwsh -File scripts\gc-rebase.ps1 -Onto origin/main
|
|
51
|
+
#>
|
|
52
|
+
param(
|
|
53
|
+
[string]$Onto,
|
|
54
|
+
[switch]$Continue,
|
|
55
|
+
[switch]$Abort,
|
|
56
|
+
[switch]$NoSync,
|
|
57
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
58
|
+
[switch]$Detailed,
|
|
59
|
+
[switch]$Quiet
|
|
60
|
+
)
|
|
61
|
+
Set-StrictMode -Version Latest
|
|
62
|
+
$ErrorActionPreference = 'Stop'
|
|
63
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
64
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
65
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
69
|
+
Write-GcInfo "repo: $root"
|
|
70
|
+
|
|
71
|
+
if ($Continue -and $Abort) {
|
|
72
|
+
throw [GcException]::new('-Continue and -Abort are mutually exclusive', $script:GcExitPre)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
$inProgress = Test-GcRebaseInProgress -Root $root
|
|
76
|
+
|
|
77
|
+
if ($Abort) {
|
|
78
|
+
# a rebase runs on a DETACHED HEAD, so no branch insight is needed here
|
|
79
|
+
if (-not $inProgress) { throw [GcException]::new('no rebase in progress — nothing to abort', $script:GcExitPre) }
|
|
80
|
+
# M2: never discard resolution work silently — abort is refused while
|
|
81
|
+
# resolved/staged changes exist beyond the unmerged markers, AND while
|
|
82
|
+
# any unmerged path's WORKTREE copy no longer contains conflict markers
|
|
83
|
+
# (unstaged manual resolution is invisible to porcelain).
|
|
84
|
+
$unmergedPat = '^(UU|AA|DD|AU|UA|DU|UD) '
|
|
85
|
+
$resolvedWork = @(Get-GcGit -Root $root -Argv @('status','--porcelain') |
|
|
86
|
+
ForEach-Object { "$_" } | Where-Object { $_ -cnotmatch $unmergedPat -and $_ -cnotmatch '^\?\?' })
|
|
87
|
+
$unmergedPaths = @()
|
|
88
|
+
try { $unmergedPaths = Get-GcGit -Root $root -Argv @('diff','--name-only','--diff-filter=U') } catch { }
|
|
89
|
+
$editedUnmerged = @()
|
|
90
|
+
foreach ($p in $unmergedPaths) {
|
|
91
|
+
$abs = Join-Path $root $p
|
|
92
|
+
if (-not (Test-Path -LiteralPath $abs)) { continue }
|
|
93
|
+
try { $text = [System.IO.File]::ReadAllText($abs) } catch { continue }
|
|
94
|
+
if ($text -notmatch '<<<<<<<') { $editedUnmerged += $p } # markers gone → real resolution
|
|
95
|
+
}
|
|
96
|
+
if (@($resolvedWork).Count -gt 0 -or @($editedUnmerged).Count -gt 0) {
|
|
97
|
+
$why = @()
|
|
98
|
+
if (@($resolvedWork).Count -gt 0) { $why += "$($resolvedWork.Count) resolved file(s) [$($resolvedWork -join ', ')]" }
|
|
99
|
+
if (@($editedUnmerged).Count -gt 0) { $why += "unstaged manual resolution in [$($editedUnmerged -join ', ')]" }
|
|
100
|
+
throw [GcException]::new("abort would discard: $($why -join '; ') — abort refused; resolve fully and -Continue, or reset those paths yourself", $script:GcExitPre)
|
|
101
|
+
}
|
|
102
|
+
Invoke-GcGit -Root $root -Argv @('rebase','--abort')
|
|
103
|
+
$b = Get-GcCurrentBranch -Root $root
|
|
104
|
+
Write-GcOk "rebase aborted — back on $b, no resolutions were lost (nothing was resolved)"
|
|
105
|
+
Write-GcResult -Props @{ branch = $b; action = 'aborted' }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if ($Continue) {
|
|
109
|
+
if (-not $inProgress) { throw [GcException]::new('no rebase in progress — nothing to continue', $script:GcExitPre) }
|
|
110
|
+
Assert-GcIdentity -Root $root
|
|
111
|
+
# marker gate: staged or worktree conflict markers must never be
|
|
112
|
+
# committed by --continue (battery live finding: markers were)
|
|
113
|
+
$markers = @()
|
|
114
|
+
try { $markers += Get-GcGit -Root $root -Argv @('grep','-n','-E','^(<<<<<<<|>>>>>>>)( |$)') } catch { }
|
|
115
|
+
try { $markers += Get-GcGit -Root $root -Argv @('grep','-n','--cached','-E','^(<<<<<<<|>>>>>>>)( |$)') } catch { }
|
|
116
|
+
if ($markers) {
|
|
117
|
+
Write-GcFail "conflict markers still present ($(@($markers).Count) hit(s)) — resolve them first"
|
|
118
|
+
Write-GcResult -Code $script:GcExitPre -Props @{ action = 'conflict'; message = 'conflict markers still present — resolve them, then gc-rebase -Continue again, or gc-rebase -Abort' }
|
|
119
|
+
}
|
|
120
|
+
$env:GIT_EDITOR = 'true' # a pending editor prompt must never block an agent
|
|
121
|
+
try {
|
|
122
|
+
Invoke-GcGit -Root $root -Argv @('rebase','--continue')
|
|
123
|
+
} finally { Remove-Item Env:\GIT_EDITOR -ErrorAction SilentlyContinue }
|
|
124
|
+
if (Test-GcRebaseInProgress -Root $root) {
|
|
125
|
+
Write-GcFail 'rebase is still conflicted after --continue'
|
|
126
|
+
Write-GcResult -Code $script:GcExitPre -Props @{ action = 'conflict'; message = 'resolve the remaining conflicts, then gc-rebase -Continue again, or gc-rebase -Abort' }
|
|
127
|
+
}
|
|
128
|
+
$b = Get-GcCurrentBranch -Root $root # re-attached once the rebase finished
|
|
129
|
+
$sha = (Get-GcGit -Root $root -Argv @('rev-parse','--short','HEAD') | Select-Object -First 1).Trim()
|
|
130
|
+
Write-GcOk "rebase continued — $b @ $sha"
|
|
131
|
+
Write-GcResult -Props @{ branch = $b; sha = $sha; action = 'continued' }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
$cur = Get-GcCurrentBranch -Root $root # fresh rebase requires a real branch (throws Pre when detached)
|
|
135
|
+
$default = Get-GcDefaultBranch -Root $root
|
|
136
|
+
$onto = if ($Onto) { $Onto } else { $default }
|
|
137
|
+
Assert-GcRefValue -Name '-Onto' -Value $onto # H1: no option injection into git rebase
|
|
138
|
+
if (-not $NoSync) { $null = Sync-GcDefaultBranch -Root $root -Default $default -CurrentBranch $cur }
|
|
139
|
+
Write-GcInfo "rebasing $cur onto $onto..."
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
Invoke-GcGit -Root $root -Argv @('rebase',$onto)
|
|
143
|
+
} catch {
|
|
144
|
+
if (Test-GcRebaseInProgress -Root $root) {
|
|
145
|
+
# deliberate stop, state preserved — never abort on our own
|
|
146
|
+
Write-GcFail "rebase stopped on a conflict ($($_.Exception.Message))"
|
|
147
|
+
Write-GcResult -Code $script:GcExitPre -Props @{ branch = $cur; onto = $onto; action = 'conflict'; message = 'resolve the conflicts, then gc-rebase -Continue, or gc-rebase -Abort' }
|
|
148
|
+
}
|
|
149
|
+
throw # not a conflict stop — original error
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
$count = (Get-GcGit -Root $root -Argv @('rev-list','--count',"$onto..HEAD") | Select-Object -First 1).Trim()
|
|
153
|
+
$sha = (Get-GcGit -Root $root -Argv @('rev-parse','--short','HEAD') | Select-Object -First 1).Trim()
|
|
154
|
+
Write-GcOk "rebased $cur onto $onto — $count commit(s) replayed, HEAD @ $sha"
|
|
155
|
+
Write-GcResult -Props @{ branch = $cur; onto = $onto; commits = [int]$count; sha = $sha; action = 'rebased' }
|
|
156
|
+
} catch [GcException] {
|
|
157
|
+
Write-GcFail $_.Exception.Message
|
|
158
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
159
|
+
} catch {
|
|
160
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
161
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
162
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
§9 single-release machinery: ONE moving `latest` tag, ONE release entry whose
|
|
5
|
+
body is rendered from CHANGELOG.md. Never a second entry.
|
|
6
|
+
|
|
7
|
+
.DESCRIPTION
|
|
8
|
+
git-ceremony §9 as a script. Invariants enforced:
|
|
9
|
+
- AT MOST ONE release entry, permanently. An existing `latest` release is
|
|
10
|
+
EDITED, never duplicated; zero release entries → exactly one is created;
|
|
11
|
+
any other shape (more than one entry, or a single entry under a foreign
|
|
12
|
+
tag, draft or prerelease) is REFUSED loudly, before anything moves.
|
|
13
|
+
- ONE moving tag: `latest` is a pointer, not a version tag —
|
|
14
|
+
git tag -f latest <head-sha>
|
|
15
|
+
git push --force origin latest
|
|
16
|
+
The bare force is deliberate and documented (the §6 lease-only rule
|
|
17
|
+
reserves plain --force for exactly this pointer); never per-version tags.
|
|
18
|
+
- body rendered from CHANGELOG.md: the version comes from package.json (the
|
|
19
|
+
npm manifest — one source of truth, §8) and its section from the
|
|
20
|
+
changelog; the number is never hardcoded in two places.
|
|
21
|
+
- the pointer tags the REMOTE default-branch head: the checkout must BE the
|
|
22
|
+
default branch (detached/other-branch refused), the tree must be clean,
|
|
23
|
+
the branch is synced first (fetch + ff-only, §1) and refused when local
|
|
24
|
+
head ≠ remote head — a stale or unpushed head is never tagged.
|
|
25
|
+
- npm gate: refuses a version npm does not have; a release entry for an
|
|
26
|
+
unpublished version is a lie. npm missing or unreachable → exit 3.
|
|
27
|
+
- idempotent: a second run moves the pointer and rewrites the body, and
|
|
28
|
+
never creates a second release.
|
|
29
|
+
Repo rules win (§0): a repo with its own release process is not migrated by
|
|
30
|
+
force; the repo's process stays the answer.
|
|
31
|
+
|
|
32
|
+
.PARAMETER RepoRoot
|
|
33
|
+
Repository path (defaults to the current directory); git is always pinned
|
|
34
|
+
with git -C.
|
|
35
|
+
.PARAMETER MovingLatest
|
|
36
|
+
Required explicit opt-in. This wrapper implements a nonstandard single moving
|
|
37
|
+
`latest` release and must only be used when repository policy declares it.
|
|
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 -NoProfile -File scripts\gc-release.ps1 -MovingLatest -RepoRoot <repo-path>
|
|
48
|
+
#>
|
|
49
|
+
param(
|
|
50
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
51
|
+
[switch]$MovingLatest,
|
|
52
|
+
[switch]$Detailed,
|
|
53
|
+
[switch]$Quiet
|
|
54
|
+
)
|
|
55
|
+
Set-StrictMode -Version Latest
|
|
56
|
+
$ErrorActionPreference = 'Stop'
|
|
57
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
58
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
59
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
60
|
+
|
|
61
|
+
function Read-GcPackageIdentity {
|
|
62
|
+
<#
|
|
63
|
+
package.json name + version: the npm identity and the §8 one source of
|
|
64
|
+
truth for the version. Pre failures name the fix; a private package is
|
|
65
|
+
refused (nothing is published, so an entry would be a lie).
|
|
66
|
+
#>
|
|
67
|
+
param([Parameter(Mandatory)][string]$Root)
|
|
68
|
+
$abs = Join-Path $Root 'package.json'
|
|
69
|
+
if (-not (Test-Path -LiteralPath $abs)) {
|
|
70
|
+
throw [GcException]::new('package.json not found — gc-release cuts npm releases; this repo has no npm manifest', $script:GcExitPre)
|
|
71
|
+
}
|
|
72
|
+
try { $pkg = Get-Content -LiteralPath $abs -Raw | ConvertFrom-Json }
|
|
73
|
+
catch { throw [GcException]::new("package.json does not parse: $($_.Exception.Message)", $script:GcExitPre) }
|
|
74
|
+
if ($pkg.PSObject.Properties.Name -contains 'private' -and $pkg.private) {
|
|
75
|
+
throw [GcException]::new('package.json is private — nothing is published to npm, so a release entry would be a lie', $script:GcExitPre)
|
|
76
|
+
}
|
|
77
|
+
$name = if ($pkg.PSObject.Properties.Name -contains 'name') { "$($pkg.name)".Trim() } else { '' }
|
|
78
|
+
$version = if ($pkg.PSObject.Properties.Name -contains 'version') { "$($pkg.version)".Trim() } else { '' }
|
|
79
|
+
if (-not $name -or -not $version) {
|
|
80
|
+
throw [GcException]::new('package.json is missing name or version — repo defect', $script:GcExitPre)
|
|
81
|
+
}
|
|
82
|
+
return [pscustomobject]@{ Name = $name; Version = $version }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function Assert-GcNpmVersionPublished {
|
|
86
|
+
<#
|
|
87
|
+
The npm gate, explicit and loud: a version npm does not have is refused
|
|
88
|
+
with the fix named (a release entry for an unpublished version is a lie).
|
|
89
|
+
npm absent, or a query failure that is NOT "version absent", is a
|
|
90
|
+
dependency stop (exit 3) — the check must never be skipped silently.
|
|
91
|
+
#>
|
|
92
|
+
param([Parameter(Mandatory)][string]$Name, [Parameter(Mandatory)][string]$Version)
|
|
93
|
+
if (-not (Get-Command npm -ErrorAction SilentlyContinue)) {
|
|
94
|
+
throw [GcException]::new('npm is not installed or not on PATH — cannot verify the published version; install Node/npm and re-run', $script:GcExitDep)
|
|
95
|
+
}
|
|
96
|
+
$query = "$Name@$Version"
|
|
97
|
+
$out = & npm view $query version 2>&1
|
|
98
|
+
$code = $LASTEXITCODE
|
|
99
|
+
$text = if ($null -eq $out) { '' } else { (@($out) -join "`n") }
|
|
100
|
+
if ($code -ne 0) {
|
|
101
|
+
if ($text -match 'E404|ETARGET|No match found|No matching version|not found') {
|
|
102
|
+
throw [GcException]::new("npm does not have $query — publish it first (npm publish), then cut the release; a release entry for an unpublished version is a lie", $script:GcExitPre)
|
|
103
|
+
}
|
|
104
|
+
throw [GcException]::new("npm view $query failed (exit $code): $($text.Trim()) — cannot verify the published version", $script:GcExitDep)
|
|
105
|
+
}
|
|
106
|
+
$reported = @($text -split "`r?`n" | ForEach-Object { $_.Trim().Trim('"') } | Where-Object { $_ -eq $Version })
|
|
107
|
+
if ($reported.Count -lt 1) {
|
|
108
|
+
throw [GcException]::new("npm did not report $query as published (saw: $($text.Trim())) — refusing; a release entry for an unpublished version is a lie", $script:GcExitPre)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function Get-GcReleases {
|
|
113
|
+
<# `gh release list` as an Object[] — empty when none. ALWAYS an array, so
|
|
114
|
+
every caller's .Count / [0] works under Set-StrictMode: a bare `return
|
|
115
|
+
@($raw)` unwraps at the function boundary (empty → $null, one → scalar),
|
|
116
|
+
which crashed the one-entry read before anything was moved. #>
|
|
117
|
+
param([Parameter(Mandatory)][string]$Root)
|
|
118
|
+
$raw = Get-GcGhJson -Root $Root -Argv @('release','list','--limit','5','--json','tagName,isDraft,isPrerelease,isLatest')
|
|
119
|
+
if ($null -eq $raw) { $raw = @() }
|
|
120
|
+
return ,[Object[]]$raw
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
if (-not $MovingLatest) {
|
|
125
|
+
throw [GcException]::new('gc-release implements the nonstandard moving-latest scheme; repository policy must require it and the caller must pass -MovingLatest', $script:GcExitPre)
|
|
126
|
+
}
|
|
127
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
128
|
+
Write-GcInfo "repo: $root"
|
|
129
|
+
|
|
130
|
+
# --- the head that will be tagged: default branch, clean, synced, remote ---
|
|
131
|
+
$cur = Get-GcCurrentBranch -Root $root
|
|
132
|
+
$default = Get-GcDefaultBranch -Root $root
|
|
133
|
+
if ($cur -ne $default) {
|
|
134
|
+
throw [GcException]::new("refusing to release from '$cur' — the pointer tags the default-branch head; switch to '$default' first", $script:GcExitPre)
|
|
135
|
+
}
|
|
136
|
+
if (-not (Test-GcCleanTree -Root $root)) {
|
|
137
|
+
throw [GcException]::new('tree is not clean — commit or stash first; the pointer tags the exact published tree', $script:GcExitPre)
|
|
138
|
+
}
|
|
139
|
+
$remote = Get-GcRemote -Root $root
|
|
140
|
+
if ($remote -ne 'origin') { Invoke-GcGit -Root $root -Argv @('fetch','--prune',$remote) }
|
|
141
|
+
Sync-GcDefaultBranch -Root $root -Default $default -CurrentBranch $cur | Out-Null
|
|
142
|
+
$remoteRef = "refs/remotes/$remote/$default"
|
|
143
|
+
if (-not (Test-GcRef -Root $root -Ref $remoteRef)) {
|
|
144
|
+
throw [GcException]::new("$remote/$default has no remote head — push the default branch first", $script:GcExitPre)
|
|
145
|
+
}
|
|
146
|
+
$head = ((Get-GcGit -Root $root -Argv @('rev-parse','HEAD') | Select-Object -First 1) -split '\s+')[0]
|
|
147
|
+
$rhead = ((Get-GcGit -Root $root -Argv @('rev-parse',$remoteRef) | Select-Object -First 1) -split '\s+')[0]
|
|
148
|
+
if ($head -ne $rhead) {
|
|
149
|
+
throw [GcException]::new("local $default is not at $remote/$default ($($head.Substring(0,7)) vs $($rhead.Substring(0,7))) — the pointer must tag the remote head; sync or push the default branch first, then re-run", $script:GcExitPre)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# --- identity, body (§8/§9), npm gate --------------------------------------
|
|
153
|
+
$pkg = Read-GcPackageIdentity -Root $root
|
|
154
|
+
$section = Get-GcChangelogSection -Root $root -Version $pkg.Version
|
|
155
|
+
$body = Format-GcReleaseBody -Version $pkg.Version -Lines $section
|
|
156
|
+
Write-GcInfo "rendered $(@($section).Count) changelog line(s) for $($pkg.Name)@$($pkg.Version)"
|
|
157
|
+
Assert-GcNpmVersionPublished -Name $pkg.Name -Version $pkg.Version
|
|
158
|
+
Write-GcOk "npm has $($pkg.Name)@$($pkg.Version)"
|
|
159
|
+
|
|
160
|
+
# --- one-entry invariant: read BEFORE anything moves -----------------------
|
|
161
|
+
Assert-GcGh
|
|
162
|
+
$entries = Get-GcReleases -Root $root
|
|
163
|
+
if ($entries.Count -eq 0) {
|
|
164
|
+
$action = 'created'
|
|
165
|
+
} elseif ($entries.Count -eq 1 -and $entries[0].tagName -eq 'latest') {
|
|
166
|
+
if ($entries[0].isDraft -or $entries[0].isPrerelease) {
|
|
167
|
+
throw [GcException]::new("the 'latest' release entry is a draft or prerelease — §9 keeps one live normal entry; publish or normalize it first", $script:GcExitPre)
|
|
168
|
+
}
|
|
169
|
+
$action = 'updated'
|
|
170
|
+
} else {
|
|
171
|
+
$tags = @($entries | ForEach-Object { $_.tagName }) -join ', '
|
|
172
|
+
throw [GcException]::new("refusing: release entries beyond the single 'latest' pointer exist ($tags) — §9 allows at most one entry, permanently; delete or reconcile the strays first", $script:GcExitPre)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# --- the pointer: deliberate bare force, documented above ------------------
|
|
176
|
+
Invoke-GcGit -Root $root -Argv @('tag','-f','latest',$head)
|
|
177
|
+
Invoke-GcGit -Root $root -Argv @('push','--force',$remote,'refs/tags/latest')
|
|
178
|
+
Write-GcOk "latest -> $($head.Substring(0,7)) (pointer moved; force is deliberate)"
|
|
179
|
+
|
|
180
|
+
# --- the one entry: edit when it exists, create only when none does --------
|
|
181
|
+
$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("gc-release-body-" + [guid]::NewGuid().ToString('N') + ".md")
|
|
182
|
+
try {
|
|
183
|
+
Set-Content -LiteralPath $tmp -Value $body -NoNewline
|
|
184
|
+
if ($action -eq 'created') {
|
|
185
|
+
Invoke-GcGh -Root $root -Argv @('release','create','latest','--title',$pkg.Name,'--notes-file',$tmp,'--verify-tag','--latest')
|
|
186
|
+
} else {
|
|
187
|
+
Invoke-GcGh -Root $root -Argv @('release','edit','latest','--title',$pkg.Name,'--notes-file',$tmp,'--latest')
|
|
188
|
+
}
|
|
189
|
+
} finally {
|
|
190
|
+
Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# --- verify, never trust ----------------------------------------------------
|
|
194
|
+
$view = Get-GcGhJson -Root $root -Argv @('release','view','latest','--json','tagName,name,url')
|
|
195
|
+
if ($view.tagName -ne 'latest') {
|
|
196
|
+
throw [GcException]::new("release verification failed — gh reports tag '$($view.tagName)', expected 'latest'", $script:GcExitFail)
|
|
197
|
+
}
|
|
198
|
+
$final = Get-GcReleases -Root $root
|
|
199
|
+
if ($final.Count -ne 1 -or $final[0].tagName -ne 'latest' -or -not $final[0].isLatest) {
|
|
200
|
+
throw [GcException]::new("release verification failed — expected exactly one entry for 'latest' marked latest; got $(@($final | ForEach-Object { "$($_.tagName)(latest=$($_.isLatest))" }) -join ', ')", $script:GcExitFail)
|
|
201
|
+
}
|
|
202
|
+
$lsLine = @(Get-GcGit -Root $root -Argv @('ls-remote',$remote,'refs/tags/latest') | Select-Object -First 1)[0]
|
|
203
|
+
$remoteSha = if ($lsLine) { ($lsLine -split '\s+')[0] } else { '' }
|
|
204
|
+
if ($remoteSha -ne $head) {
|
|
205
|
+
throw [GcException]::new("remote '$remote' latest tag is '$remoteSha', expected '$head' — pointer verification failed", $script:GcExitFail)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
Write-GcOk "release ${action}: $($pkg.Name) v$($pkg.Version) @ latest ($($view.url))"
|
|
209
|
+
Write-GcResult -Props @{
|
|
210
|
+
action = $action
|
|
211
|
+
name = $pkg.Name
|
|
212
|
+
version = $pkg.Version
|
|
213
|
+
tag = 'latest'
|
|
214
|
+
sha = $head
|
|
215
|
+
url = $view.url
|
|
216
|
+
is_latest = [bool]$final[0].isLatest
|
|
217
|
+
remote = $remote
|
|
218
|
+
}
|
|
219
|
+
} catch [GcException] {
|
|
220
|
+
Write-GcFail $_.Exception.Message
|
|
221
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
222
|
+
} catch {
|
|
223
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
224
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
225
|
+
}
|