oc-harness-setup 0.2.0 → 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 +27 -23
- 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 +32 -3
- 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 +11 -6
- 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 -70
- 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 -19
- package/commands/ponytail-audit.md +0 -7
- package/commands/ponytail-debt.md +0 -14
- package/commands/report.md +0 -13
- package/scripts/harness-report.ps1 +0 -695
- 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,196 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Start a unit of work from truth: sync the default branch, then create <type>/<slug>.
|
|
5
|
+
|
|
6
|
+
.DESCRIPTION
|
|
7
|
+
git-ceremony §1-§2 as a script. Fetches origin, fast-forwards the default
|
|
8
|
+
branch (never manufactures a merge, refuses to branch from a stale or
|
|
9
|
+
diverged default), validates the branch name, and creates the branch from the
|
|
10
|
+
synced default HEAD. Idempotent: already on the branch is a no-op; -Reuse
|
|
11
|
+
switches to an existing branch instead of failing.
|
|
12
|
+
|
|
13
|
+
Dynamic content in (type + slug), fixed ceremony out. Repo rules win: if the
|
|
14
|
+
repo documents its own convention, follow that instead of this script.
|
|
15
|
+
|
|
16
|
+
.PARAMETER Type
|
|
17
|
+
One of: feat, fix, chore, docs, refactor, test, perf, hotfix, wt.
|
|
18
|
+
.PARAMETER Slug
|
|
19
|
+
Kebab-case 2-5 words, letters/digits only; describes the change, not the
|
|
20
|
+
author or the date.
|
|
21
|
+
.PARAMETER Branch
|
|
22
|
+
Full <type>/<slug> name; alternative to passing Type + Slug.
|
|
23
|
+
.PARAMETER Reuse
|
|
24
|
+
Switch to the branch when it already exists instead of failing.
|
|
25
|
+
.PARAMETER Delete
|
|
26
|
+
Delete a branch instead of creating one: local delete, plus remote when
|
|
27
|
+
-DeleteRemote is given. Never the default branch, never the current branch,
|
|
28
|
+
never with a dirty tree; an unmerged branch is refused without -Force
|
|
29
|
+
(squash-merged branches legitimately need -Force — the commit lives in the
|
|
30
|
+
default branch, not in branch ancestry).
|
|
31
|
+
.PARAMETER DeleteRemote
|
|
32
|
+
With -Delete: also delete <branch> on the remote (origin by default,
|
|
33
|
+
verified to exist first — never a blind push --delete).
|
|
34
|
+
.PARAMETER Force
|
|
35
|
+
With -Delete: allow deleting an unmerged branch (its commits are not in the
|
|
36
|
+
default branch's history — loud warning).
|
|
37
|
+
.PARAMETER SkipSync
|
|
38
|
+
Skip fetch + fast-forward of the default branch. Only when you just synced;
|
|
39
|
+
the ceremony default is to sync.
|
|
40
|
+
.PARAMETER RepoRoot
|
|
41
|
+
Repository path (defaults to the current directory). Every git call is pinned
|
|
42
|
+
with git -C, so the ambient shell cwd never matters (worktree rails, §10).
|
|
43
|
+
.PARAMETER Detailed
|
|
44
|
+
Restore the step narration, ok/info lines, and raw git/gh relay the terse
|
|
45
|
+
default hides. Never affects the RESULT line, warnings, failures, or the
|
|
46
|
+
security/remediation lines.
|
|
47
|
+
.PARAMETER Quiet
|
|
48
|
+
Accepted for compatibility and now a no-op: the default is already terse.
|
|
49
|
+
-Quiet forces the gate closed and so wins if passed with -Detailed.
|
|
50
|
+
|
|
51
|
+
.EXAMPLE
|
|
52
|
+
pwsh -File scripts\gc-branch.ps1 -Type feat -Slug token-refresh
|
|
53
|
+
|
|
54
|
+
.EXAMPLE
|
|
55
|
+
pwsh -File scripts\gc-branch.ps1 -Branch 'fix/login-timeout' -Reuse
|
|
56
|
+
|
|
57
|
+
.EXAMPLE
|
|
58
|
+
pwsh -File scripts\gc-branch.ps1 -Delete 'feat/token-refresh' -DeleteRemote -Force
|
|
59
|
+
#>
|
|
60
|
+
param(
|
|
61
|
+
[string]$Type,
|
|
62
|
+
[string]$Slug,
|
|
63
|
+
[string]$Branch,
|
|
64
|
+
[string]$Delete,
|
|
65
|
+
[switch]$DeleteRemote,
|
|
66
|
+
[switch]$Force,
|
|
67
|
+
[switch]$Reuse,
|
|
68
|
+
[switch]$SkipSync,
|
|
69
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
70
|
+
[switch]$Detailed,
|
|
71
|
+
[switch]$Quiet
|
|
72
|
+
)
|
|
73
|
+
Set-StrictMode -Version Latest
|
|
74
|
+
$ErrorActionPreference = 'Stop'
|
|
75
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
76
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
77
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
81
|
+
Write-GcInfo "repo: $root"
|
|
82
|
+
$default = Get-GcDefaultBranch -Root $root
|
|
83
|
+
Write-GcInfo "default branch: $default"
|
|
84
|
+
$cur = try { Get-GcCurrentBranch -Root $root } catch { $null }
|
|
85
|
+
|
|
86
|
+
# -------- delete verb ---------------------------------------------------
|
|
87
|
+
if ($Delete) {
|
|
88
|
+
$del = $Delete
|
|
89
|
+
Assert-GcRefValue -Name '-Delete' -Value $del
|
|
90
|
+
if ($del -eq $default) {
|
|
91
|
+
throw [GcException]::new("never delete the default branch ($default)", $script:GcExitPre)
|
|
92
|
+
}
|
|
93
|
+
if ($del -eq $cur) {
|
|
94
|
+
throw [GcException]::new("cannot delete the current branch — switch away first (gc-branch -Reuse <branch>)", $script:GcExitPre)
|
|
95
|
+
}
|
|
96
|
+
$localExists = Test-GcRef -Root $root -Ref "refs/heads/$del"
|
|
97
|
+
$remote = $null
|
|
98
|
+
if ($DeleteRemote) {
|
|
99
|
+
try { $remote = Get-GcRemote -Root $root } catch { throw [GcException]::new("no remote — cannot delete $del remotely", $script:GcExitPre) }
|
|
100
|
+
}
|
|
101
|
+
$remoteExists = $false
|
|
102
|
+
if ($remote) { $remoteExists = [bool]@(Get-GcGit -Root $root -Argv @('ls-remote','--heads',$remote,$del)) }
|
|
103
|
+
if (-not $localExists -and -not $remoteExists) {
|
|
104
|
+
throw [GcException]::new("branch '$del' does not exist (local or $remote)", $script:GcExitPre)
|
|
105
|
+
}
|
|
106
|
+
if (-not (Test-GcCleanTree -Root $root)) {
|
|
107
|
+
throw [GcException]::new('tree is dirty — commit or stash before deleting a branch', $script:GcExitPre)
|
|
108
|
+
}
|
|
109
|
+
$deletedLocal = $false; $deletedRemote = $false
|
|
110
|
+
$localShaBefore = $null
|
|
111
|
+
if ($localExists) {
|
|
112
|
+
$merged = $false
|
|
113
|
+
try { Get-GcGit -Root $root -Argv @('merge-base','--is-ancestor',$del,$default) | Out-Null; $merged = $true } catch { }
|
|
114
|
+
if (-not $merged -and -not $Force) {
|
|
115
|
+
throw [GcException]::new("branch '$del' is unmerged into $default — deletion discards its commits; pass -Force to delete anyway (squash-merged branches legitimately need -Force: the commit lives in $default, not in branch ancestry)", $script:GcExitPre)
|
|
116
|
+
}
|
|
117
|
+
if (-not $merged -and $Force) { Write-GcWarn "deleting unmerged branch '$del' with -Force — its commits are NOT in $default's history" }
|
|
118
|
+
$localShaBefore = (Get-GcGit -Root $root -Argv @('rev-parse',$del) | Select-Object -First 1).Trim()
|
|
119
|
+
Invoke-GcGit -Root $root -Argv @('branch', $(if ($merged) { '-d' } else { '-D' }), $del)
|
|
120
|
+
$deletedLocal = $true
|
|
121
|
+
}
|
|
122
|
+
if ($remote -and $remoteExists) {
|
|
123
|
+
# remote gate mirrors the local one (adv-L1): fetch, then oid-compare
|
|
124
|
+
# when local existed, and the merged/-Force gate when remote-only.
|
|
125
|
+
Invoke-GcGit -Root $root -Argv @('fetch',$remote)
|
|
126
|
+
$remoteFetched = Test-GcRef -Root $root -Ref "refs/remotes/$remote/$del"
|
|
127
|
+
if ($remoteFetched) {
|
|
128
|
+
if ($localShaBefore) {
|
|
129
|
+
$remoteSha = (Get-GcGit -Root $root -Argv @('rev-parse',"$remote/$del") | Select-Object -First 1).Trim()
|
|
130
|
+
if ($remoteSha -ne $localShaBefore) {
|
|
131
|
+
throw [GcException]::new("remote $del ($remoteSha) differs from local ($localShaBefore) — verify before deleting", $script:GcExitPre)
|
|
132
|
+
}
|
|
133
|
+
} else {
|
|
134
|
+
$remoteMerged = $false
|
|
135
|
+
try { Get-GcGit -Root $root -Argv @('merge-base','--is-ancestor',"$remote/$del",$default) | Out-Null; $remoteMerged = $true } catch { }
|
|
136
|
+
if (-not $remoteMerged -and -not $Force) {
|
|
137
|
+
throw [GcException]::new("remote branch '$del' is unmerged into $default — pass -Force to delete it", $script:GcExitPre)
|
|
138
|
+
}
|
|
139
|
+
if (-not $remoteMerged -and $Force) { Write-GcWarn "deleting unmerged remote branch '$del' with -Force" }
|
|
140
|
+
}
|
|
141
|
+
Invoke-GcGit -Root $root -Argv @('push',$remote,'--delete',$del)
|
|
142
|
+
$deletedRemote = $true
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
Write-GcOk "deleted $del (local=$deletedLocal remote=$deletedRemote)"
|
|
146
|
+
Write-GcResult -Props @{ branch = $del; deleted_local = $deletedLocal; deleted_remote = $deletedRemote; force = [bool]$Force; action = 'deleted' }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
$name = if ($Branch) { $Branch }
|
|
150
|
+
elseif ($Type -and $Slug) { "$Type/$Slug" }
|
|
151
|
+
else { throw [GcException]::new('give -Branch ''<type>/<slug>'' or -Type + -Slug', $script:GcExitPre) }
|
|
152
|
+
if (-not (Test-GcBranchName -Branch $name)) {
|
|
153
|
+
throw [GcException]::new("branch name rejected: $name", $script:GcExitPre)
|
|
154
|
+
}
|
|
155
|
+
if ($cur -eq $name) {
|
|
156
|
+
Write-GcOk "already on $name"
|
|
157
|
+
Write-GcResult -Props @{ branch = $name; action = 'no-op' }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
$exists = Test-GcRef -Root $root -Ref "refs/heads/$name"
|
|
161
|
+
if (-not $exists -and $Reuse) {
|
|
162
|
+
throw [GcException]::new("branch '$name' does not exist — -Reuse cannot create it; never reuse a merged branch name (§2); gc-branch a fresh <type>/<slug>", $script:GcExitPre)
|
|
163
|
+
}
|
|
164
|
+
if ($exists -and -not $Reuse) {
|
|
165
|
+
throw [GcException]::new("branch '$name' exists — pass -Reuse to switch to it", $script:GcExitPre)
|
|
166
|
+
}
|
|
167
|
+
if ($exists) {
|
|
168
|
+
Invoke-GcGit -Root $root -Argv @('switch',$name)
|
|
169
|
+
Write-GcOk "switched to existing $name"
|
|
170
|
+
Write-GcResult -Props @{ branch = $name; action = 'reused' }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (-not $SkipSync) {
|
|
174
|
+
$null = Sync-GcDefaultBranch -Root $root -Default $default -CurrentBranch $cur
|
|
175
|
+
} else {
|
|
176
|
+
Write-GcInfo 'sync skipped (-SkipSync)'
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (Test-GcRef -Root $root -Ref "refs/heads/$default") {
|
|
180
|
+
Invoke-GcGit -Root $root -Argv @('switch','-c',$name,$default)
|
|
181
|
+
} else {
|
|
182
|
+
# unborn default (fresh repo, zero commits): create from current HEAD
|
|
183
|
+
Invoke-GcGit -Root $root -Argv @('switch','-c',$name)
|
|
184
|
+
Write-GcWarn "default branch '$default' is unborn — created $name from the current unborn HEAD"
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
$sha = (Get-GcGit -Root $root -Argv @('rev-parse','--short',"$name") | Select-Object -First 1).Trim()
|
|
188
|
+
Write-GcOk "created $name from $default @ $sha"
|
|
189
|
+
Write-GcResult -Props @{ branch = $name; base = $default; base_sha = $sha; action = 'created' }
|
|
190
|
+
} catch [GcException] {
|
|
191
|
+
Write-GcFail $_.Exception.Message
|
|
192
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
193
|
+
} catch {
|
|
194
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
195
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
196
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#Requires -Version 7.0
|
|
2
|
+
<#
|
|
3
|
+
.SYNOPSIS
|
|
4
|
+
Version bump per ceremony §8: detect the repo's single manifest, apply the
|
|
5
|
+
bump table, justify it, and land the bump as its own commit. No tags, no
|
|
6
|
+
release body, no human in the middle.
|
|
7
|
+
|
|
8
|
+
.DESCRIPTION
|
|
9
|
+
git-ceremony §8 as a script. Rules enforced:
|
|
10
|
+
- one source of truth: exactly one manifest (package.json, pyproject.toml,
|
|
11
|
+
Cargo.toml, or a VERSION file) may exist — two is a repo defect, stop.
|
|
12
|
+
- repo-declared format wins: only 3-part MAJOR.MINOR.PATCH is auto-bumped;
|
|
13
|
+
CalVer, 4-part, or build numbers are refused (repo convention wins, bump
|
|
14
|
+
by hand).
|
|
15
|
+
- the bump table: -Major resets MINOR and PATCH to 0; -Minor resets PATCH
|
|
16
|
+
to 0; -Patch increments PATCH. -Set forces an explicit version.
|
|
17
|
+
- never bump downward, never reuse a version (§8).
|
|
18
|
+
- every bump is justified: -Reason (one line) lands in the bump commit.
|
|
19
|
+
- the bump is its own commit: `chore(release): <old> -> <new>`; a dirty
|
|
20
|
+
tree is refused, and the bump refuses to commit on the default branch
|
|
21
|
+
(the release commit ships through a PR, §6/§11b).
|
|
22
|
+
Write-back is text-preserving (only the version value changes), verified by
|
|
23
|
+
re-reading the manifest before the commit.
|
|
24
|
+
|
|
25
|
+
.PARAMETER Major
|
|
26
|
+
Breaking API or behavior change (resets MINOR, PATCH).
|
|
27
|
+
.PARAMETER Minor
|
|
28
|
+
New backward-compatible capability (resets PATCH).
|
|
29
|
+
.PARAMETER Patch
|
|
30
|
+
Bug fix, no new surface.
|
|
31
|
+
.PARAMETER Set
|
|
32
|
+
Explicit target version MAJOR.MINOR.PATCH (still justified, still no
|
|
33
|
+
downward moves).
|
|
34
|
+
.PARAMETER Reason
|
|
35
|
+
Required one-line justification — what kind of change forced which digit.
|
|
36
|
+
.PARAMETER RepoRoot
|
|
37
|
+
Repository path (defaults to the current directory); git is always pinned
|
|
38
|
+
with git -C.
|
|
39
|
+
.PARAMETER Detailed
|
|
40
|
+
Restore the step narration, ok/info lines, and raw git/gh relay the terse
|
|
41
|
+
default hides. Never affects the RESULT line, warnings, failures, or the
|
|
42
|
+
security/remediation lines.
|
|
43
|
+
.PARAMETER Quiet
|
|
44
|
+
Accepted for compatibility and now a no-op: the default is already terse.
|
|
45
|
+
-Quiet forces the gate closed and so wins if passed with -Detailed.
|
|
46
|
+
|
|
47
|
+
.EXAMPLE
|
|
48
|
+
pwsh -File scripts\gc-bump.ps1 -Minor -Reason 'adds token refresh endpoint (backward compatible)'
|
|
49
|
+
#>
|
|
50
|
+
param(
|
|
51
|
+
[switch]$Major,
|
|
52
|
+
[switch]$Minor,
|
|
53
|
+
[switch]$Patch,
|
|
54
|
+
[string]$Set,
|
|
55
|
+
[Parameter(Mandatory)][string]$Reason,
|
|
56
|
+
[string]$RepoRoot = (Get-Location).Path,
|
|
57
|
+
[switch]$Detailed,
|
|
58
|
+
[switch]$Quiet
|
|
59
|
+
)
|
|
60
|
+
Set-StrictMode -Version Latest
|
|
61
|
+
$ErrorActionPreference = 'Stop'
|
|
62
|
+
. (Join-Path $PSScriptRoot 'gc.core.ps1')
|
|
63
|
+
if ($Detailed) { $script:GcQuiet = $false }
|
|
64
|
+
if ($Quiet) { $script:GcQuiet = $true }
|
|
65
|
+
|
|
66
|
+
function Get-GcManifestEncoding {
|
|
67
|
+
<# detect the manifest's byte-encoding (BOM/UTF-16) so write-back preserves
|
|
68
|
+
it — the "only the version value changes" promise must survive. #>
|
|
69
|
+
param([Parameter(Mandatory)][string]$Path)
|
|
70
|
+
$bytes = [System.IO.File]::ReadAllBytes($Path)
|
|
71
|
+
if ($bytes.Length -ge 3 -and $bytes[0] -eq 0xEF -and $bytes[1] -eq 0xBB -and $bytes[2] -eq 0xBF) { return @{ Enc = [System.Text.UTF8Encoding]::new($true); Name = 'utf8-bom' } }
|
|
72
|
+
if ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) { return @{ Enc = [System.Text.UnicodeEncoding]::new($false, $true); Name = 'utf16-le' } }
|
|
73
|
+
if ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFE -and $bytes[1] -eq 0xFF) { return @{ Enc = [System.Text.UnicodeEncoding]::new($true, $true); Name = 'utf16-be' } }
|
|
74
|
+
return @{ Enc = [System.Text.UTF8Encoding]::new($false); Name = 'utf8' }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function Read-GcVersion {
|
|
78
|
+
param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$Manifest, [Parameter(Mandatory)][hashtable]$Encoding)
|
|
79
|
+
$abs = Join-Path $Root $Manifest
|
|
80
|
+
$enc = $Encoding.Enc
|
|
81
|
+
$content = $enc.GetString([System.IO.File]::ReadAllBytes($abs))
|
|
82
|
+
switch -Regex ($Manifest) {
|
|
83
|
+
'package\.json$' {
|
|
84
|
+
if ($content -notmatch '"version"\s*:\s*"([^"]+)"') { throw [GcException]::new("package.json has no version field — repo defect", $script:GcExitPre) }
|
|
85
|
+
return $Matches[1]
|
|
86
|
+
}
|
|
87
|
+
'\.toml$' {
|
|
88
|
+
if ($content -notmatch '(?m)^version\s*=\s*"([^"]+)"') { throw [GcException]::new("$Manifest has no top-level version entry — repo defect", $script:GcExitPre) }
|
|
89
|
+
return $Matches[1]
|
|
90
|
+
}
|
|
91
|
+
'^VERSION$' {
|
|
92
|
+
$v = $content.Trim()
|
|
93
|
+
if (-not $v) { throw [GcException]::new('VERSION file is empty — repo defect', $script:GcExitPre) }
|
|
94
|
+
return $v
|
|
95
|
+
}
|
|
96
|
+
default { throw [GcException]::new("unsupported manifest: $Manifest", $script:GcExitPre) }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function Write-GcVersion {
|
|
101
|
+
param([Parameter(Mandatory)][string]$Root, [Parameter(Mandatory)][string]$Manifest, [Parameter(Mandatory)][string]$Old, [Parameter(Mandatory)][string]$New, [Parameter(Mandatory)][hashtable]$Encoding)
|
|
102
|
+
$abs = Join-Path $Root $Manifest
|
|
103
|
+
$enc = $Encoding.Enc
|
|
104
|
+
$content = $enc.GetString([System.IO.File]::ReadAllBytes($abs))
|
|
105
|
+
switch -Regex ($Manifest) {
|
|
106
|
+
'package\.json$' {
|
|
107
|
+
$content = $content -replace '("version"\s*:\s*")[^"]+(")', "`${1}$New`${2}"
|
|
108
|
+
}
|
|
109
|
+
'\.toml$' {
|
|
110
|
+
$content = $content -replace '(?m)^(version\s*=\s*")[^"]+(")', "`${1}$New`${2}"
|
|
111
|
+
}
|
|
112
|
+
'^VERSION$' {
|
|
113
|
+
$content = $New + "`n"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
[System.IO.File]::WriteAllBytes($abs, $enc.GetBytes($content))
|
|
117
|
+
# verify the write-back, never trust the replace
|
|
118
|
+
$readBack = Read-GcVersion -Root $Root -Manifest $Manifest -Encoding $Encoding
|
|
119
|
+
if ($readBack -ne $New) {
|
|
120
|
+
throw [GcException]::new("write-back verification failed — manifest reads '$readBack', expected '$New'; nothing was committed", $script:GcExitFail)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
$root = Resolve-GcRoot -Path $RepoRoot
|
|
126
|
+
Write-GcInfo "repo: $root"
|
|
127
|
+
|
|
128
|
+
$cur = Get-GcCurrentBranch -Root $root
|
|
129
|
+
$default = Get-GcDefaultBranch -Root $root
|
|
130
|
+
if ($cur -eq $default) {
|
|
131
|
+
throw [GcException]::new("refusing to bump on the default branch ($default) — the release commit ships through a PR (§6/§11b); gc-branch first", $script:GcExitPre)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# exactly one bump direction
|
|
135
|
+
$flags = @([bool]$Major, [bool]$Minor, [bool]$Patch)
|
|
136
|
+
$given = @($flags | Where-Object { $_ }).Count + $(if ($Set) { 1 } else { 0 })
|
|
137
|
+
if ($given -ne 1) {
|
|
138
|
+
throw [GcException]::new('pick exactly one: -Major, -Minor, -Patch, or -Set <version>', $script:GcExitPre)
|
|
139
|
+
}
|
|
140
|
+
if ($Reason -match '\r?\n' -or $Reason.Length -gt 200) {
|
|
141
|
+
throw [GcException]::new('-Reason must be one line, ≤200 chars', $script:GcExitPre)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
# one source of truth (§8)
|
|
145
|
+
$manifests = @(@('package.json','pyproject.toml','Cargo.toml','VERSION') | Where-Object { Test-Path -LiteralPath (Join-Path $root $_) })
|
|
146
|
+
if (-not $manifests) {
|
|
147
|
+
throw [GcException]::new('no version manifest found — expected package.json, pyproject.toml, Cargo.toml, or a VERSION file', $script:GcExitPre)
|
|
148
|
+
}
|
|
149
|
+
if (@($manifests).Count -gt 1) {
|
|
150
|
+
throw [GcException]::new("multiple manifests ($($manifests -join ', ')) — two sources of truth; fix before bumping (§8)", $script:GcExitPre)
|
|
151
|
+
}
|
|
152
|
+
$manifest = $manifests[0]
|
|
153
|
+
|
|
154
|
+
$manifestAbs = Join-Path $root $manifest
|
|
155
|
+
$manifestEnc = Get-GcManifestEncoding -Path $manifestAbs
|
|
156
|
+
$old = Read-GcVersion -Root $root -Manifest $manifest -Encoding $manifestEnc
|
|
157
|
+
if ($old -notmatch '^\d+\.\d+\.\d+$') {
|
|
158
|
+
throw [GcException]::new("repo version '$old' is not MAJOR.MINOR.PATCH — repo-declared format wins; bump it by hand (§8)", $script:GcExitPre)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
$maj, $min, $pat = $old -split '\.' | ForEach-Object { [int]$_ }
|
|
162
|
+
if ($Set) {
|
|
163
|
+
if ($Set -notmatch '^\d+\.\d+\.\d+$') { throw [GcException]::new("-Set must be MAJOR.MINOR.PATCH", $script:GcExitPre) }
|
|
164
|
+
$new = $Set; $kind = 'set'
|
|
165
|
+
} elseif ($Major) { $maj++; $new = "$maj.0.0"; $kind = 'major' }
|
|
166
|
+
elseif ($Minor) { $min++; $new = "$maj.$min.0"; $kind = 'minor' }
|
|
167
|
+
else { $pat++; $new = "$maj.$min.$pat"; $kind = 'patch' }
|
|
168
|
+
|
|
169
|
+
if ([version]$new -le [version]$old) {
|
|
170
|
+
throw [GcException]::new("$new is not above $old — never bump downward, never reuse a version (§8)", $script:GcExitPre)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
# the bump is its own commit — a dirty tree is refused, not mixed in
|
|
174
|
+
if (-not (Test-GcCleanTree -Root $root)) {
|
|
175
|
+
throw [GcException]::new('tree is not clean — the bump must be its own commit; commit or stash the feature work first (§8)', $script:GcExitPre)
|
|
176
|
+
}
|
|
177
|
+
Assert-GcIdentity -Root $root
|
|
178
|
+
|
|
179
|
+
Write-GcInfo "bumping ${manifest}: $old -> $new ($kind)"
|
|
180
|
+
Write-GcVersion -Root $root -Manifest $manifest -Old $old -New $new -Encoding $manifestEnc
|
|
181
|
+
|
|
182
|
+
$subject = "chore(release): $old -> $new"
|
|
183
|
+
Get-GcSubjectParts -Subject $subject | Out-Null # ceremony-valid message
|
|
184
|
+
$argv = @('commit','-m',$subject,'-m',"-${kind}: $Reason")
|
|
185
|
+
Invoke-GcGit -Root $root -Argv (@('add','--',$manifest))
|
|
186
|
+
Stop-GcOnSecrets -Root $root # same gate as gc-commit — a manifest must never smuggle a secret
|
|
187
|
+
Invoke-GcGit -Root $root -Argv $argv
|
|
188
|
+
|
|
189
|
+
$sha = (Get-GcGit -Root $root -Argv @('rev-parse','--short','HEAD') | Select-Object -First 1).Trim()
|
|
190
|
+
Write-GcOk "$subject @ $sha"
|
|
191
|
+
Write-GcResult -Props @{ manifest = $manifest; old = $old; new = $new; kind = $kind; reason = $Reason; sha = $sha; action = 'bumped' }
|
|
192
|
+
} catch [GcException] {
|
|
193
|
+
Write-GcFail $_.Exception.Message
|
|
194
|
+
Write-GcResult -Code $_.Exception.Code -Props @{ message = $_.Exception.Message }
|
|
195
|
+
} catch {
|
|
196
|
+
Write-GcFail "unexpected: $($_.Exception.Message)"
|
|
197
|
+
Write-GcResult -Code $script:GcExitFail -Props @{ message = $_.Exception.Message }
|
|
198
|
+
}
|