oc-harness-setup 0.2.0 → 0.3.1

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 (115) hide show
  1. package/.docs/unwired-routing.md +14 -9
  2. package/.gitignore +14 -1
  3. package/AGENTS.md +70 -106
  4. package/README.md +55 -24
  5. package/agents/build.md +10 -12
  6. package/agents/explore.md +14 -8
  7. package/agents/general.md +7 -9
  8. package/agents/orchestrator.md +38 -0
  9. package/agents/plan.md +10 -13
  10. package/agents/reviewer.md +9 -14
  11. package/agents/vault.md +44 -35
  12. package/bin/cli.js +32 -3
  13. package/commands/build.md +2 -8
  14. package/commands/checkpoint.md +3 -1
  15. package/commands/code-simplify.md +3 -9
  16. package/commands/gauntlet.md +7 -0
  17. package/commands/handoff.md +3 -1
  18. package/commands/keeper.md +3 -3
  19. package/commands/kill.md +11 -0
  20. package/commands/plan.md +2 -13
  21. package/commands/retro.md +15 -0
  22. package/commands/review.md +1 -1
  23. package/commands/ship.md +3 -27
  24. package/commands/spec.md +3 -11
  25. package/commands/test.md +2 -9
  26. package/commands/webperf.md +7 -0
  27. package/opencode.jsonc +23 -8
  28. package/package.json +5 -4
  29. package/reference/README.md +14 -14
  30. package/reference/auto-mandate.md +11 -0
  31. package/reference/backup-convention.md +9 -0
  32. package/reference/clean-mandate.md +13 -0
  33. package/reference/editor-parity.md +7 -0
  34. package/reference/gc-scripts.md +8 -0
  35. package/reference/intent-routing.md +14 -0
  36. package/reference/lifecycle.md +15 -0
  37. package/reference/model-keeper.md +30 -10
  38. package/reference/model-test.md +11 -6
  39. package/reference/models.md +25 -14
  40. package/reference/oc-source-map.md +162 -0
  41. package/reference/owner-pin.md +31 -0
  42. package/reference/roster.md +15 -0
  43. package/reference/session-scope.md +9 -0
  44. package/reference/session-state.md +13 -0
  45. package/reference/swarm.md +32 -0
  46. package/scripts/backup-config.ps1 +42 -0
  47. package/scripts/gc-branch.ps1 +196 -0
  48. package/scripts/gc-bump.ps1 +198 -0
  49. package/scripts/gc-clean.ps1 +648 -0
  50. package/scripts/gc-commit.ps1 +143 -0
  51. package/scripts/gc-merge.ps1 +272 -0
  52. package/scripts/gc-pr.ps1 +190 -0
  53. package/scripts/gc-push.ps1 +111 -0
  54. package/scripts/gc-read.ps1 +150 -0
  55. package/scripts/gc-rebase.ps1 +162 -0
  56. package/scripts/gc-release.ps1 +225 -0
  57. package/scripts/gc-stage.ps1 +103 -0
  58. package/scripts/gc-status.ps1 +127 -0
  59. package/scripts/gc-sync.ps1 +65 -0
  60. package/scripts/gc.core.ps1 +715 -0
  61. package/scripts/gc.smoke.ps1 +779 -0
  62. package/scripts/harness-doctor.ps1 +11 -9
  63. package/scripts/interrupt-session.ps1 +65 -0
  64. package/scripts/logbook/README.md +108 -0
  65. package/scripts/logbook/logbook.test.ts +440 -0
  66. package/scripts/logbook/logbook.ts +797 -0
  67. package/scripts/pirep/README.md +147 -0
  68. package/scripts/pirep/pirep.test.ts +735 -0
  69. package/scripts/pirep/pirep.ts +836 -0
  70. package/scripts/testflight/README.md +112 -0
  71. package/scripts/testflight/testflight.test.ts +512 -0
  72. package/scripts/testflight/testflight.ts +806 -0
  73. package/skills/_shared/SOURCES.md +7 -7
  74. package/skills/_shared/references/definition-of-done.md +2 -2
  75. package/skills/_shared/references/orchestration-patterns.md +1 -2
  76. package/skills/_shared/references/security-checklist.md +2 -2
  77. package/skills/api-and-interface-design/SKILL.md +7 -360
  78. package/skills/browser-testing-with-devtools/SKILL.md +303 -0
  79. package/skills/code-simplification/SKILL.md +7 -364
  80. package/skills/creative-writing/SKILL.md +1 -1
  81. package/skills/debugging-and-error-recovery/SKILL.md +8 -309
  82. package/skills/flight-deck/SKILL.md +17 -0
  83. package/skills/frontend-ui-engineering/SKILL.md +8 -320
  84. package/skills/gauntlet/SKILL.md +21 -0
  85. package/skills/git-ceremony/SKILL.md +16 -318
  86. package/skills/grilling/SKILL.md +10 -30
  87. package/skills/observability-and-instrumentation/SKILL.md +9 -229
  88. package/skills/performance-optimization/SKILL.md +8 -488
  89. package/skills/pilot-report/SKILL.md +18 -0
  90. package/skills/planning-and-task-breakdown/SKILL.md +8 -249
  91. package/skills/security-and-hardening/SKILL.md +9 -490
  92. package/skills/source-driven-development/SKILL.md +8 -208
  93. package/skills/spec-driven-development/SKILL.md +15 -234
  94. package/skills/test-driven-development/SKILL.md +8 -388
  95. package/skills/test-flight/SKILL.md +14 -0
  96. package/skills/writing-for-agents/SKILL-MECHANICS.md +3 -3
  97. package/skills/writing-for-agents/SKILL.md +7 -1
  98. package/agents/coder.md +0 -19
  99. package/agents/documenter.md +0 -28
  100. package/agents/keeper.md +0 -22
  101. package/agents/master.md +0 -70
  102. package/agents/researcher.md +0 -21
  103. package/agents/security-auditor.md +0 -20
  104. package/agents/test-engineer.md +0 -20
  105. package/agents/web-performance-auditor.md +0 -19
  106. package/commands/council.md +0 -24
  107. package/commands/doctor.md +0 -19
  108. package/commands/ponytail-audit.md +0 -7
  109. package/commands/ponytail-debt.md +0 -14
  110. package/commands/report.md +0 -13
  111. package/scripts/harness-report.ps1 +0 -695
  112. package/scripts/panic/panic.ts +0 -240
  113. package/skills/code-review-and-quality/SKILL.md +0 -396
  114. package/skills/incremental-implementation/SKILL.md +0 -249
  115. package/skills/swarm-orchestration/SKILL.md +0 -54
@@ -1,695 +0,0 @@
1
- <#
2
- .SYNOPSIS
3
- Redacted harness report + prefilled issue URL: self-doctor, self-report, human gate.
4
-
5
- .DESCRIPTION
6
- Runs the sibling harness-doctor.ps1, then renders a shareable report with the
7
- identity and findings a maintainer needs. Redaction is ENFORCED IN CODE, not
8
- promised in prose: every field that reaches the body passes one chokepoint
9
- (Redact-Text -> Test-DropText), so a new field cannot bypass it by accident.
10
-
11
- What the report is FOR: an installed agent that can self-doctor and self-report.
12
- The doctor grades the local harness; this script turns that grade into (a) a
13
- markdown issue body, (b) the prefilled URL, and (c) a JSON envelope for tooling.
14
- Filing is the human's call - this script NEVER files anything and never calls a
15
- forge CLI.
16
-
17
- Redaction rules (applied to root, laws[].detail, regressions, drift, timestamp,
18
- identity - every field):
19
- - $env:USERPROFILE, C:\Users\<name>, /home/<name>, /Users/<name>, and the
20
- absolute config path all become ~.
21
- - the manifest backupPath value becomes ~/.opencode-backup/<ts>; the real
22
- value is never emitted.
23
- - diagnostic STRUCTURE is never dropped for containing a keyword. Law
24
- identifiers, law names, PASS/FAIL/DRIFT results, evidence, proposals, and
25
- the summary counts survive even when they contain words like "secret" or
26
- "credential" - Law 10 is literally named "...secret-like property names in
27
- opencode.jsonc" and Law 11's evidence says "credential denies hold", so
28
- the old whole-line blocklist rendered exactly those failures as empty
29
- entries and could hide a real product defect.
30
- - secret-like VALUES are redacted IN PLACE: when a name that looks
31
- secret-like is followed by a value (`apiKey: sk-...`, `"token": "..."`,
32
- `password = ...`), the name is kept and the value becomes <redacted>. The
33
- same holds for a JSON property whose NAME is secret-like - key kept, value
34
- replaced. A boolean-valued secret-named property is exempt because a
35
- boolean cannot carry a credential (the doctor's own `secretGuard` flag is
36
- read downstream).
37
- - a line is DROPPED whole only when it cannot be kept safely: a {file:...}
38
- pointer target, a path into a secret store, or a bare credential-looking
39
- literal (known key prefix, JWT shape, or a long unbroken high-entropy
40
- token).
41
- - BOTH counters are reported - removed lines AND redacted values - so the
42
- reader sees exactly how the body was transformed instead of silently
43
- getting a thinner report.
44
- - ses_<id> -> <session>; machine hostnames -> <host>; usernames -> <user>.
45
-
46
- Hard rules baked into the code:
47
- - never invokes `gh` (nor any forge CLI), and never files anything;
48
- - never reads .secrets, .env, or any credential path - the one file read
49
- (the installer's manifest) goes through Get-SafeText, which refuses those
50
- paths outright;
51
- - the target repository is a constant below, never derived from doctor
52
- output or from the local environment. No labels are prefilled: guessing a
53
- label that does not exist upstream only makes the forge warn.
54
-
55
- Exit codes: 0 reported; 1 -SelfTest failed (treat the redactor as untrusted);
56
- 3 the sibling doctor is missing (nothing to report on).
57
-
58
- -SelfTest proves the redactor keeps a "secret"-named law line verbatim,
59
- redacts a secret-like value in place while keeping its line, drops a
60
- {file:...} pointer and a secret-store path, and still collapses Windows and
61
- POSIX user paths, session ids, and the manifest backup path. Run it before
62
- trusting any body this script prints.
63
-
64
- .EXAMPLE
65
- pwsh -File scripts\harness-report.ps1
66
-
67
- .EXAMPLE
68
- pwsh -File scripts\harness-report.ps1 -Json
69
-
70
- .EXAMPLE
71
- pwsh -File scripts\harness-report.ps1 -SelfTest
72
-
73
- .EXAMPLE
74
- pwsh -File scripts\harness-report.ps1 -OutFile .\report.md -ConfigDir D:\config\opencode
75
-
76
- .PARAMETER Json
77
- Emit {url, body, identity} as JSON instead of the rendered markdown.
78
-
79
- .PARAMETER SelfTest
80
- Assert the redactor's guarantees and exit 0 (pass) or 1 (fail). Touches
81
- nothing on disk and does not run the doctor.
82
-
83
- .PARAMETER OutFile
84
- Also write the markdown body to this path (UTF-8, no BOM).
85
-
86
- .PARAMETER ConfigDir
87
- Config directory to grade; passed straight through to the doctor. Defaults to
88
- the doctor's own default (~/.config/opencode).
89
- #>
90
- #Requires -Version 7.0
91
- [CmdletBinding()]
92
- param(
93
- [switch]$Json,
94
- [switch]$SelfTest,
95
- [string]$OutFile,
96
- [string]$ConfigDir
97
- )
98
-
99
- $ErrorActionPreference = 'Stop'
100
- Set-StrictMode -Version Latest
101
- $OutputEncoding = [System.Text.Encoding]::UTF8
102
- [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
103
-
104
- # ---------- constants (never derived from doctor output or the environment) ----------
105
- $targetRepo = 'https://github.com/nathwn12/oc-harness-setup'
106
- $manifestFile = 'oc-harness-setup.manifest.json'
107
- $backupPlaceholder = '~/.opencode-backup/<ts>'
108
-
109
- # ---------- redaction state ----------
110
- $script:ConfigRootLiteral = ''
111
- $script:BackupPathLiteral = ''
112
- $script:HostNames = @()
113
- $script:UserNames = @()
114
- $script:DroppedCount = 0
115
- $script:RedactedCount = 0
116
- $script:BodyLines = [System.Collections.Generic.List[string]]::new()
117
- $script:RedactedValue = '<redacted>'
118
- # A NAME that looks secret-like, in either naming convention. Substring match on
119
- # purpose: over-matching a name only costs a redacted value, never structure.
120
- # Non-capturing group so the outer group in the composed patterns stays $1.
121
- $script:SecretNamePattern = '(?i)(?:api[_-]?key|passwd|password|bearer|token|credential|secret)s?'
122
- # The value half of a `name: value` pair, guarded so an already-redacted value is
123
- # left alone (the two passes below must not fight over the same fragment).
124
- $script:SecretValuePart = '(?!["'']?' + [regex]::Escape($script:RedactedValue) + ')(?:"[^"\r\n]*"?|''[^''\r\n]*''?|\S+)'
125
- # `"apiKey": "sk-..."` inside an embedded JSON fragment: name kept (quotes and
126
- # all), value replaced. Runs first so quoted JSON keeps its shape.
127
- $script:SecretJsonPropertyPattern = '(?i)"(' + $script:SecretNamePattern + ')"\s*:\s*("[^"]*"|\{[^}]*\}|\[[^\]]*\]|[^,}\s]+)'
128
- # `apiKey: sk-...`, `password = ...`, `token: '...'` - name kept, value gone.
129
- $script:SecretAssignPattern = '(?i)"?(' + $script:SecretNamePattern + ')"?\s*[:=]\s*' + $script:SecretValuePart
130
-
131
- # ---------- readers ----------
132
- function Get-SafeText {
133
- # The one file reader in this script. Refuses secret-bearing paths outright,
134
- # so no code path here can read secret-store or .env contents.
135
- param([string]$Path)
136
- $normalized = ([string]$Path).Replace('\', '/')
137
- if ($normalized -match '(^|/)([.]secrets|\.env)(/|$)|(^|/)[^/]*\.env(\.|$)') {
138
- throw "refused to read secret-bearing path: $Path"
139
- }
140
- return (Get-Content -LiteralPath $Path -Raw -Encoding utf8)
141
- }
142
-
143
- function Get-EnvValue {
144
- # Environment lookup that cannot throw under StrictMode.
145
- param([string]$Name)
146
- return [string]([System.Environment]::GetEnvironmentVariable($Name))
147
- }
148
-
149
- function Get-ReportField {
150
- # Safe property read on the doctor's JSON: a shape change degrades to ''
151
- # instead of an unhandled PropertyNotFoundException under StrictMode.
152
- param([AllowNull()]$Node, [string]$Name)
153
- if ($null -eq $Node) { return '' }
154
- $property = $Node.PSObject.Properties[$Name]
155
- if ($null -eq $property -or $null -eq $property.Value) { return '' }
156
- return [string]$property.Value
157
- }
158
-
159
- function Get-ReportItems {
160
- # Safe property read that always yields an array, so a missing or single
161
- # -valued section never turns into a one-iteration null loop.
162
- param([AllowNull()]$Node, [string]$Name)
163
- if ($null -eq $Node) { return @() }
164
- $property = $Node.PSObject.Properties[$Name]
165
- if ($null -eq $property -or $null -eq $property.Value) { return @() }
166
- return @($property.Value)
167
- }
168
-
169
- # ---------- the redaction chokepoint ----------
170
- function Hide-SecretValues {
171
- # Redact secret-like VALUES in place; the surrounding line always survives.
172
- # Every replacement is counted so the report can state what it did.
173
- param([AllowNull()][string]$Text)
174
- if ($null -eq $Text) { return $Text }
175
- $s = [string]$Text
176
- foreach ($pattern in @($script:SecretJsonPropertyPattern, $script:SecretAssignPattern)) {
177
- $found = [regex]::Matches($s, $pattern)
178
- if ($found.Count -eq 0) { continue }
179
- $script:RedactedCount += $found.Count
180
- $replacement = if ($pattern -eq $script:SecretAssignPattern) { '$1: ' + $script:RedactedValue } else { '"$1": "' + $script:RedactedValue + '"' }
181
- $s = [regex]::Replace($s, $pattern, $replacement)
182
- }
183
- return $s
184
- }
185
-
186
- function Hide-SecretPropertyValues {
187
- # A parsed JSON property whose NAME is secret-like keeps its name and loses
188
- # its VALUE: {apiKey: 'sk-...'} -> {apiKey: '<redacted>'}. Recurses through
189
- # nested objects and arrays. A boolean is exempt because a boolean cannot
190
- # carry a credential, and the doctor's own `secretGuard` flag is consumed
191
- # downstream as a diagnostic.
192
- param([AllowNull()]$Node)
193
- if ($null -eq $Node) { return }
194
- if ($Node -is [System.Collections.IEnumerable] -and $Node -isnot [string]) {
195
- foreach ($item in @($Node)) { Hide-SecretPropertyValues -Node $item }
196
- return
197
- }
198
- if ($Node -isnot [pscustomobject]) { return }
199
- foreach ($property in @($Node.PSObject.Properties)) {
200
- if ($property.Name -match $script:SecretNamePattern) {
201
- if ($property.Value -isnot [bool]) {
202
- $property.Value = $script:RedactedValue
203
- $script:RedactedCount++
204
- }
205
- continue
206
- }
207
- Hide-SecretPropertyValues -Node $property.Value
208
- }
209
- }
210
-
211
- function Redact-Text {
212
- # Replace identifying strings with stable placeholders and redact secret-like
213
- # values in place. Never returns secret content: the drop test (Test-DropText)
214
- # runs afterwards on this output.
215
- param([AllowNull()][string]$Text)
216
- if ($null -eq $Text) { return $null }
217
- $s = [string]$Text
218
-
219
- # The absolute config path first, so its home prefix collapses to a bare ~.
220
- if ($script:ConfigRootLiteral) {
221
- $s = $s.Replace($script:ConfigRootLiteral, '~')
222
- $s = $s.Replace($script:ConfigRootLiteral.Replace('\', '/'), '~')
223
- }
224
- $userProfile = Get-EnvValue 'USERPROFILE'
225
- if ($userProfile) { $s = $s.Replace($userProfile, '~') }
226
-
227
- # Home-directory shapes for every platform, in case the path was normalized.
228
- $s = [regex]::Replace($s, '(?i)(?<![A-Za-z0-9])[A-Za-z]:[\\/]Users[\\/][^\s\\/<>|]+', '~')
229
- $s = [regex]::Replace($s, '(?i)(?<![A-Za-z0-9])/(?:home|Users)/[^\s\\/<>|]+', '~')
230
-
231
- # The installer's backup pointer: the real value never leaves this machine.
232
- if ($script:BackupPathLiteral) { $s = $s.Replace($script:BackupPathLiteral, $backupPlaceholder) }
233
- $s = [regex]::Replace($s, '(?i)\S*\.opencode-backup[\\/][^\s<>|]+', $backupPlaceholder)
234
-
235
- # Session ids, hostnames, usernames. Hostnames first: a hostname that
236
- # contains the username would otherwise be split by the username pass.
237
- $s = [regex]::Replace($s, '\bses_[A-Za-z0-9]+', '<session>')
238
- foreach ($hostName in $script:HostNames) {
239
- if ($hostName) { $s = [regex]::Replace($s, [regex]::Escape($hostName), '<host>', 'IgnoreCase') }
240
- }
241
- foreach ($user in $script:UserNames) {
242
- if ($user) { $s = [regex]::Replace($s, '(?<![A-Za-z0-9])' + [regex]::Escape($user) + '(?![A-Za-z0-9])', '<user>', 'IgnoreCase') }
243
- }
244
-
245
- # Last: the values. Names (and therefore lines) survive; values do not.
246
- return (Hide-SecretValues -Text $s)
247
- }
248
-
249
- function Test-BareCredentialLiteral {
250
- # A credential-looking literal with no name to key the redactor off: a known
251
- # key prefix, a JWT shape, or a long unbroken high-entropy token. Deliberately
252
- # narrow - a short word, a lowercase hex SHA, or a repo path is NOT a
253
- # credential, and dropping an honest line is the failure mode being fixed.
254
- param([AllowNull()][string]$Text)
255
- if ([string]::IsNullOrWhiteSpace($Text)) { return $false }
256
- if ($Text -match '(?i)(?<![A-Za-z0-9])(?:sk|pk|rk)-[A-Za-z0-9_-]{16,}') { return $true }
257
- if ($Text -match '(?i)(?<![A-Za-z0-9])(?:ghp|gho|ghs|ghr|github_pat)_[A-Za-z0-9_]{16,}') { return $true }
258
- if ($Text -match '(?i)(?<![A-Za-z0-9])xox[baprs]-[A-Za-z0-9-]{10,}') { return $true }
259
- if ($Text -match '(?<![A-Za-z0-9])AKIA[0-9A-Z]{16}(?![A-Za-z0-9])') { return $true }
260
- if ($Text -match '(?<![A-Za-z0-9])AIza[0-9A-Za-z_-]{35}(?![A-Za-z0-9])') { return $true }
261
- if ($Text -match '(?<![A-Za-z0-9_])eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.') { return $true }
262
- if ($Text -match '(?<![A-Za-z0-9+/=_-])[A-Za-z0-9+/=_-]{32,}(?![A-Za-z0-9+/=_-])') {
263
- $token = $Matches[0]
264
- $classes = 0
265
- if ($token -cmatch '[a-z]') { $classes++ }
266
- if ($token -cmatch '[A-Z]') { $classes++ }
267
- if ($token -cmatch '[0-9]') { $classes++ }
268
- if ($token -cmatch '[+/=_-]') { $classes++ }
269
- if ($classes -ge 3) { return $true }
270
- }
271
- return $false
272
- }
273
-
274
- function Test-DropText {
275
- # The drop list is now only what cannot be kept safely: a {file:...} pointer
276
- # target, a path INTO a secret store, or a bare credential literal. A line is
277
- # never dropped merely for containing a keyword - that used to delete Law 10
278
- # (named "...secret-like property names...") and Law 11's "credential denies
279
- # hold" evidence, i.e. exactly the failures worth reporting.
280
- param([AllowNull()][string]$Text)
281
- if ([string]::IsNullOrWhiteSpace($Text)) { return $false }
282
- if ($Text -match '\{file:[^}]*\}') { return $true }
283
- if ($Text -match '(?i)(?<![A-Za-z0-9._-])\.(?:secrets|env)(?:[\\/.]|$)') { return $true }
284
- if (Test-BareCredentialLiteral -Text $Text) { return $true }
285
- return $false
286
- }
287
-
288
- function Add-RedactedLine {
289
- # The ONLY way a line reaches the body. Redact, then drop-or-keep.
290
- param([AllowNull()][string]$Text)
291
- if ($null -eq $Text) { return }
292
- $clean = Redact-Text -Text $Text
293
- if (Test-DropText -Text $clean) { $script:DroppedCount++; return }
294
- $script:BodyLines.Add($clean)
295
- }
296
-
297
- # ---------- self-test ----------
298
- if ($SelfTest) {
299
- $failures = [System.Collections.Generic.List[string]]::new()
300
-
301
- function Assert-That {
302
- param([string]$Name, [bool]$Condition, [string]$Note)
303
- if ($Condition) {
304
- " [PASS] $Name"
305
- } else {
306
- " [FAIL] $Name - $Note"
307
- $failures.Add($Name)
308
- }
309
- }
310
-
311
- function Get-RenderedBodyLine {
312
- # Render ONE line through the real chokepoint and return what the body got
313
- # ('' means the line was dropped). Clears BodyLines: nothing else runs here.
314
- param([string]$Text)
315
- $script:BodyLines = [System.Collections.Generic.List[string]]::new()
316
- Add-RedactedLine -Text $Text
317
- return ($script:BodyLines -join "`n")
318
- }
319
-
320
- 'Self-test: redactor guarantees'
321
- # Probe tokens are assembled at runtime so a repo scan does not trip on them.
322
- $secretValue = 'sk-live-' + 'ABC123def456GHI789jkl'
323
- $assignProbe = 'apiKey: ' + $secretValue
324
- $jsonProbe = '{"apiKey": "' + $secretValue + '", "keep": 1}'
325
- $secretProbe = ('api' + 'key') + ': "' + 'sk-test-' + 'not-a-real-value' + '"'
326
- $pointerProbe = '{' + 'file:' + 'C:\Users\someone\notes.md}'
327
- $storePointerProbe = '{' + 'file:' + '~/.secrets/openai-key}'
328
- $winPathProbe = 'C:\Users\' + 'someone' + '\AppData\Local\opencode'
329
- $posixPathProbe = '/home/' + 'someone' + '/.config/opencode'
330
- $macPathProbe = '/Users/' + 'someone' + '/Library/Application Support'
331
- $sessionProbe = 'ses_' + 'abc123DEF456'
332
- $script:BackupPathLiteral = 'C:\Users\' + 'someone' + '\.opencode-backup\20260922-130500-deadbeef'
333
- $script:ConfigRootLiteral = 'C:\Users\' + 'someone' + '\.config\opencode'
334
- $script:HostNames = @('DESKTOP-REPORTTEST')
335
- $script:UserNames = @('someone')
336
-
337
- # --- structure survives: the bug this change fixes ---
338
- $lawNameLine = '### no secret-like property names in opencode.jsonc'
339
- $rendered = Get-RenderedBodyLine -Text $lawNameLine
340
- Assert-That 'keeps a law line whose NAME contains "secret" (Law 10)' ($rendered -eq $lawNameLine) "got '$rendered'"
341
-
342
- $credEvidenceLine = '- evidence: disk-destroy and credential denies hold (deny survives --auto)'
343
- $rendered = Get-RenderedBodyLine -Text $credEvidenceLine
344
- Assert-That 'keeps a law evidence line containing "credential" (Law 11)' ($rendered -eq $credEvidenceLine) "got '$rendered'"
345
-
346
- $summaryLine = '- PASS - no secret-like property names in opencode.jsonc'
347
- $rendered = Get-RenderedBodyLine -Text $summaryLine
348
- Assert-That 'keeps a laws-evaluated line with a "secret"-named law' ($rendered -eq $summaryLine) "got '$rendered'"
349
-
350
- # --- values are redacted IN PLACE, and the line survives ---
351
- $redactedBefore = $script:RedactedCount
352
- $rendered = Get-RenderedBodyLine -Text $assignProbe
353
- Assert-That 'keeps a secret-valued line, redacts only the value' ($rendered -match '^(?i)apikey: <redacted>$') "got '$rendered'"
354
- Assert-That 'the secret value never reaches the body' (-not $rendered.Contains('sk-live')) "got '$rendered'"
355
- Assert-That 'counts the redacted value' ($script:RedactedCount -gt $redactedBefore) "redacted count did not move from $redactedBefore"
356
-
357
- $rendered = Get-RenderedBodyLine -Text $secretProbe
358
- Assert-That 'keeps the quoted-secret probe line, redacts its value' ((-not $rendered.Contains('not-a-real-value')) -and ($rendered -match '(?i)apikey')) "got '$rendered'"
359
-
360
- $jsonOut = Redact-Text -Text $jsonProbe
361
- Assert-That 'redacts a secret-named JSON property VALUE, keeps key and siblings' `
362
- (($jsonOut -match '"apiKey": "<redacted>"') -and ($jsonOut -match '"keep": 1') -and (-not $jsonOut.Contains('sk-live'))) "got '$jsonOut'"
363
-
364
- $node = [pscustomobject]@{
365
- apiKey = $secretValue
366
- password = 'hunter2'
367
- secretGuard = $true
368
- nested = [pscustomobject]@{ token = 'abc123' }
369
- keep = 'visible'
370
- }
371
- Hide-SecretPropertyValues -Node $node
372
- Assert-That 'nulls a secret-named JSON property value (key kept)' `
373
- (($null -ne $node.PSObject.Properties['apiKey']) -and ($node.apiKey -eq '<redacted>') -and ($node.password -eq '<redacted>')) "got '$($node.apiKey)'/'$($node.password)'"
374
- Assert-That 'reaches nested secret-named properties' ($node.nested.token -eq '<redacted>') "got '$($node.nested.token)'"
375
- Assert-That 'leaves a boolean flag intact (a boolean cannot carry a credential)' ($node.secretGuard -eq $true) "got '$($node.secretGuard)'"
376
- Assert-That 'leaves non-secret properties alone' ($node.keep -eq 'visible') "got '$($node.keep)'"
377
-
378
- # --- the drop list is only what cannot be kept safely ---
379
- $dropProbe = '{' + 'file:' + '~/.secrets/openai-key}'
380
- $dropsBefore = $script:DroppedCount
381
- $rendered = Get-RenderedBodyLine -Text $dropProbe
382
- Assert-That 'DROPS a {file:...} pointer into a secret store' (($rendered -eq '') -and ($script:DroppedCount -eq $dropsBefore + 1)) "got '$rendered' / dropped $($script:DroppedCount - $dropsBefore)"
383
-
384
- $pointerOut = Redact-Text -Text $pointerProbe
385
- Assert-That 'drops a {file:...} pointer' (Test-DropText -Text $pointerOut) 'the pointer survived the drop list'
386
-
387
- Assert-That 'drops a path into a secret store' (Test-DropText -Text ('- evidence: read ~/' + '.secrets/openai-key')) 'the secret-store path survived the drop list'
388
- Assert-That 'drops a bare credential literal with no name' (Test-DropText -Text ('header = ' + $secretValue)) 'the bare literal survived the drop list'
389
- Assert-That 'KEEPS a lowercase hex SHA (not a credential)' (-not (Test-DropText -Text 'commit 4f2a1b9c8d7e6f5a4b3c2d1e0f9a8b7c6d5e4f3a')) 'an honest hex id was dropped'
390
- Assert-That 'KEEPS a plain path that is not a secret store' (-not (Test-DropText -Text ('note: ' + $winPathProbe))) 'an honest path was dropped'
391
-
392
- # --- identity redaction is unchanged ---
393
- $winOut = Redact-Text -Text $winPathProbe
394
- Assert-That 'redacts a Windows user path' ($winOut -notmatch '(?i)users' -and $winOut.StartsWith('~')) "got '$winOut'"
395
-
396
- $posixOut = Redact-Text -Text $posixPathProbe
397
- Assert-That 'redacts a POSIX user path' ($posixOut -notmatch '(?i)/home/' -and $posixOut.StartsWith('~')) "got '$posixOut'"
398
-
399
- $macOut = Redact-Text -Text $macPathProbe
400
- Assert-That 'redacts a macOS user path' ($macOut -notmatch '(?i)/Users/' -and $macOut.StartsWith('~')) "got '$macOut'"
401
-
402
- $sessionOut = Redact-Text -Text $sessionProbe
403
- Assert-That 'strips a session id' (-not $sessionOut.Contains('ses_') -and $sessionOut.Contains('<session>')) "got '$sessionOut'"
404
-
405
- $backupOut = Redact-Text -Text "backup: $($script:BackupPathLiteral)"
406
- Assert-That 'never emits the manifest backup path' ((-not $backupOut.Contains('20260922-130500')) -and $backupOut.Contains($backupPlaceholder)) "got '$backupOut'"
407
-
408
- $configOut = Redact-Text -Text $script:ConfigRootLiteral
409
- Assert-That 'redacts the absolute config path' ($configOut -eq '~') "got '$configOut'"
410
-
411
- $hostOut = Redact-Text -Text 'ran on DESKTOP-REPORTTEST'
412
- Assert-That 'redacts the machine hostname' (-not $hostOut.Contains('DESKTOP-REPORTTEST') -and $hostOut.Contains('<host>')) "got '$hostOut'"
413
-
414
- $userOut = Redact-Text -Text 'owner: someone'
415
- Assert-That 'redacts the username' (-not $userOut.Contains('someone') -and $userOut.Contains('<user>')) "got '$userOut'"
416
-
417
- ''
418
- if ($failures.Count -eq 0) {
419
- "Self-test: PASS ($($script:DroppedCount) line(s) dropped, $($script:RedactedCount) value(s) redacted during the probes)"
420
- exit 0
421
- }
422
- "Self-test: FAIL - $($failures.Count) assertion(s) failed: $($failures -join ', ')"
423
- exit 1
424
- }
425
-
426
- # ---------- context ----------
427
- $root = if ($ConfigDir) { $ConfigDir } else { Join-Path (Get-EnvValue 'USERPROFILE') '.config\opencode' }
428
- $script:ConfigRootLiteral = [string]$root
429
- $script:HostNames = @(
430
- (Get-EnvValue 'COMPUTERNAME'),
431
- (Get-EnvValue 'HOSTNAME')
432
- ) | Where-Object { $_ }
433
- try {
434
- $dnsName = [System.Net.Dns]::GetHostName()
435
- if ($dnsName) { $script:HostNames = @($script:HostNames) + $dnsName }
436
- } catch {
437
- # offline or unresolvable host: the other names still cover the common case
438
- }
439
- $profileLeaf = if (Get-EnvValue 'USERPROFILE') { Split-Path -Leaf (Get-EnvValue 'USERPROFILE') } else { '' }
440
- $homeLeaf = if (Get-EnvValue 'HOME') { Split-Path -Leaf (Get-EnvValue 'HOME') } else { '' }
441
- $script:UserNames = @((Get-EnvValue 'USERNAME'), (Get-EnvValue 'USER'), $profileLeaf, $homeLeaf) |
442
- Where-Object { $_ -and $_ -ne 'root' } | Select-Object -Unique
443
-
444
- $doctorPath = Join-Path $PSScriptRoot 'harness-doctor.ps1'
445
- if (-not (Test-Path -LiteralPath $doctorPath -PathType Leaf)) {
446
- Write-Error "harness-doctor.ps1 is missing from <scripts-dir> (expected beside harness-report.ps1). Nothing to report on: re-run the installer (npx oc-harness-setup setup) so scripts\ lands beside this file, then retry." -ErrorAction Continue
447
- exit 3
448
- }
449
-
450
- # ---------- run the sibling doctor (exit 0/1/2 are all normal outcomes) ----------
451
- # The parameters are written LITERALLY: an array splat (@('-Json')) binds
452
- # positionally and hands the script the string '-Json' as its first value
453
- # instead of the switch (verified on PS 7.6), which silently grades the wrong
454
- # directory. Do not "tidy" this into a splat.
455
- $doctorExit = -1
456
- $doctorOut = @()
457
- $doctorFailure = ''
458
- $previousEap = $ErrorActionPreference
459
- $ErrorActionPreference = 'Continue'
460
- try {
461
- if ($ConfigDir) {
462
- $doctorOut = @(& $doctorPath -Json -ConfigDir $ConfigDir 2>&1)
463
- } else {
464
- $doctorOut = @(& $doctorPath -Json 2>&1)
465
- }
466
- $doctorExit = $LASTEXITCODE
467
- } catch {
468
- $doctorFailure = $_.Exception.Message
469
- } finally {
470
- $ErrorActionPreference = $previousEap
471
- }
472
-
473
- $doctorText = (@($doctorOut) | ForEach-Object { [string]$_ }) -join "`n"
474
- $doctorData = $null
475
- try {
476
- $doctorData = $doctorText | ConvertFrom-Json
477
- # Doctor text is untrusted data: any parsed property whose NAME is
478
- # secret-like loses its VALUE before a single field is read from it.
479
- Hide-SecretPropertyValues -Node $doctorData
480
- } catch {
481
- if (-not $doctorFailure) { $doctorFailure = "doctor output was not parseable JSON: $($_.Exception.Message)" }
482
- }
483
-
484
- $verdictWord = switch ($doctorExit) {
485
- 0 { 'clean' }
486
- 1 { 'regressions' }
487
- 2 { 'drift' }
488
- default { "unknown (exit $doctorExit)" }
489
- }
490
-
491
- # ---------- identity ----------
492
- $packageName = 'unknown'
493
- $harnessVersion = 'unknown'
494
- $manifestPath = Join-Path $root $manifestFile
495
- if (Test-Path -LiteralPath $manifestPath -PathType Leaf) {
496
- try {
497
- $manifest = Get-SafeText -Path $manifestPath | ConvertFrom-Json
498
- $packageProperty = $manifest.PSObject.Properties['package']
499
- if ($null -ne $packageProperty -and $packageProperty.Value) { $packageName = [string]$packageProperty.Value }
500
- $versionProperty = $manifest.PSObject.Properties['version']
501
- if ($null -ne $versionProperty -and $versionProperty.Value) { $harnessVersion = [string]$versionProperty.Value }
502
- $backupProperty = $manifest.PSObject.Properties['backupPath']
503
- if ($null -ne $backupProperty -and $backupProperty.Value) { $script:BackupPathLiteral = [string]$backupProperty.Value }
504
- } catch {
505
- # a missing or unreadable manifest degrades to the fallback, never to a throw
506
- }
507
- }
508
-
509
- $opencodeVersion = 'unknown'
510
- $cli = Get-Command opencode -ErrorAction SilentlyContinue
511
- if ($cli) {
512
- $ErrorActionPreference = 'Continue'
513
- try {
514
- $cliOut = @(& opencode --version 2>&1)
515
- $cliFirst = @($cliOut | Where-Object { $_ -and ([string]$_).Trim() -ne '' })[0]
516
- if ($cliFirst) { $opencodeVersion = ([string]$cliFirst).Trim() }
517
- } catch {
518
- # keep the fallback
519
- } finally {
520
- $ErrorActionPreference = $previousEap
521
- }
522
- }
523
-
524
- $osName = if ($IsWindows) { 'Windows' } elseif ($IsMacOS) { 'macOS' } elseif ($IsLinux) { 'Linux' } else { 'unknown' }
525
- $psVersion = [string]$PSVersionTable.PSVersion
526
-
527
- $doctorTimestamp = ''
528
- if ($null -ne $doctorData) {
529
- $tsProperty = $doctorData.PSObject.Properties['timestamp']
530
- if ($null -ne $tsProperty -and $tsProperty.Value) {
531
- # ConvertFrom-Json turns the doctor's ISO-8601 string into [datetime];
532
- # render it back as ISO rather than the machine's culture format.
533
- $tsValue = $tsProperty.Value
534
- $doctorTimestamp = if ($tsValue -is [datetime]) { $tsValue.ToString('o') } else { [string]$tsValue }
535
- }
536
- }
537
- if (-not $doctorTimestamp) { $doctorTimestamp = (Get-Date).ToString('o') }
538
-
539
- $summaryPass = 0
540
- $summaryFail = 0
541
- $summaryDrift = 0
542
- $doctorSecretGuard = $null
543
- if ($null -ne $doctorData) {
544
- $summaryProperty = $doctorData.PSObject.Properties['summary']
545
- if ($null -ne $summaryProperty -and $null -ne $summaryProperty.Value) {
546
- foreach ($field in @('pass', 'fail', 'drift')) {
547
- $p = $summaryProperty.Value.PSObject.Properties[$field]
548
- if ($null -eq $p) { continue }
549
- if ($field -eq 'pass') { $summaryPass = [int]$p.Value }
550
- if ($field -eq 'fail') { $summaryFail = [int]$p.Value }
551
- if ($field -eq 'drift') { $summaryDrift = [int]$p.Value }
552
- }
553
- }
554
- $guardProperty = $doctorData.PSObject.Properties['secretGuard']
555
- if ($null -ne $guardProperty) { $doctorSecretGuard = [bool]$guardProperty.Value }
556
- }
557
-
558
- # ---------- body ----------
559
- $reportTitle = "[doctor] $summaryFail regression(s), $summaryDrift drift - $packageName $harnessVersion on $osName"
560
- $reportTitle = [string](Redact-Text -Text $reportTitle)
561
-
562
- Add-RedactedLine '<!-- harness report: generated by scripts/harness-report.ps1, redacted before it left the machine. Review, then edit freely. -->'
563
- Add-RedactedLine ''
564
- Add-RedactedLine '## Summary'
565
- Add-RedactedLine ''
566
- Add-RedactedLine '| field | value |'
567
- Add-RedactedLine '| --- | --- |'
568
- Add-RedactedLine "| harness | $packageName $harnessVersion |"
569
- Add-RedactedLine "| opencode | $opencodeVersion |"
570
- Add-RedactedLine "| os | $osName |"
571
- Add-RedactedLine "| powershell | $psVersion |"
572
- Add-RedactedLine "| doctor exit | $doctorExit ($verdictWord) |"
573
- Add-RedactedLine "| laws | $summaryPass PASS / $summaryFail FAIL / $summaryDrift DRIFT |"
574
- Add-RedactedLine "| config root | $root |"
575
- Add-RedactedLine "| doctor timestamp | $doctorTimestamp |"
576
- Add-RedactedLine ''
577
-
578
- if ($null -eq $doctorData) {
579
- Add-RedactedLine '## Doctor output could not be parsed'
580
- Add-RedactedLine ''
581
- Add-RedactedLine "The doctor ran with exit $doctorExit but its JSON could not be parsed: $doctorFailure"
582
- Add-RedactedLine ''
583
- Add-RedactedLine 'Raw doctor output follows (redacted, first 20 lines).'
584
- Add-RedactedLine ''
585
- Add-RedactedLine '```text'
586
- foreach ($line in @($doctorOut | Select-Object -First 20)) { Add-RedactedLine ([string]$line) }
587
- Add-RedactedLine '```'
588
- } else {
589
- $regressions = @(Get-ReportItems -Node $doctorData -Name 'regressions')
590
- $drift = @(Get-ReportItems -Node $doctorData -Name 'drift')
591
-
592
- Add-RedactedLine '## Regressions (an evaluated law FAILED - the harness actually broke)'
593
- Add-RedactedLine ''
594
- if ($regressions.Count -eq 0) {
595
- Add-RedactedLine 'None.'
596
- } else {
597
- foreach ($item in $regressions) {
598
- $law = Get-ReportField -Node $item -Name 'law'
599
- $evidence = Get-ReportField -Node $item -Name 'evidence'
600
- $proposal = Get-ReportField -Node $item -Name 'proposal'
601
- Add-RedactedLine "### $law"
602
- Add-RedactedLine ''
603
- Add-RedactedLine "- evidence: $evidence"
604
- if ($proposal) { Add-RedactedLine "- proposal: $proposal" }
605
- Add-RedactedLine ''
606
- }
607
- }
608
- Add-RedactedLine ''
609
-
610
- Add-RedactedLine '## Drift (the instrument could not derive an expectation)'
611
- Add-RedactedLine ''
612
- if ($drift.Count -eq 0) {
613
- Add-RedactedLine 'None.'
614
- } else {
615
- foreach ($item in $drift) {
616
- $law = Get-ReportField -Node $item -Name 'law'
617
- $evidence = Get-ReportField -Node $item -Name 'evidence'
618
- $ownerAction = Get-ReportField -Node $item -Name 'ownerAction'
619
- Add-RedactedLine "### $law"
620
- Add-RedactedLine ''
621
- Add-RedactedLine "- evidence: $evidence"
622
- if ($ownerAction) { Add-RedactedLine "- owner action: $ownerAction" }
623
- Add-RedactedLine ''
624
- }
625
- }
626
- Add-RedactedLine ''
627
-
628
- Add-RedactedLine '## Laws evaluated'
629
- Add-RedactedLine ''
630
- $laws = @(Get-ReportItems -Node $doctorData -Name 'laws')
631
- if ($laws.Count -eq 0) {
632
- Add-RedactedLine 'The doctor reported no laws.'
633
- } else {
634
- foreach ($law in $laws) {
635
- Add-RedactedLine "- $(Get-ReportField -Node $law -Name 'result') - $(Get-ReportField -Node $law -Name 'law')"
636
- }
637
- }
638
- }
639
-
640
- Add-RedactedLine ''
641
- Add-RedactedLine '## Notes'
642
- Add-RedactedLine ''
643
- Add-RedactedLine "- The redactor removed $($script:DroppedCount) line(s) it could not keep safely (a pointer target, a secret-store path, or a bare credential literal) and redacted $($script:RedactedCount) secret-like value(s) in place."
644
- Add-RedactedLine "- Law identifiers, law names, PASS/FAIL/DRIFT results and the summary counts are kept verbatim, including laws whose names carry a keyword such as 'secret' or 'credential'."
645
- Add-RedactedLine "- Identity is redacted to placeholders: ~ for the home/config path, <session>, <host>, <user>."
646
- Add-RedactedLine "- Guard self-test in the doctor: $(if ($null -eq $doctorSecretGuard) { 'not reported' } else { [string]$doctorSecretGuard })"
647
-
648
- $body = ($script:BodyLines -join "`n")
649
- if (-not $body.EndsWith("`n")) { $body += "`n" }
650
-
651
- # Built after the body so the counters reflect the whole rendered report.
652
- $identity = [pscustomobject]@{
653
- package = Redact-Text -Text $packageName
654
- version = Redact-Text -Text $harnessVersion
655
- opencode = Redact-Text -Text $opencodeVersion
656
- os = $osName
657
- powershell = $psVersion
658
- root = Redact-Text -Text $root
659
- doctorExit = $doctorExit
660
- doctorVerdict = $verdictWord
661
- timestamp = Redact-Text -Text $doctorTimestamp
662
- droppedLines = $script:DroppedCount
663
- redactedValues = $script:RedactedCount
664
- }
665
-
666
- # No labels: a label that does not exist upstream only makes the forge warn.
667
- $query = 'title=' + [System.Uri]::EscapeDataString($reportTitle) +
668
- '&body=' + [System.Uri]::EscapeDataString($body)
669
- $url = "$targetRepo/issues/new?$query"
670
-
671
- if ($OutFile) {
672
- $outPath = if ([System.IO.Path]::IsPathRooted($OutFile)) { $OutFile } else { Join-Path (Get-Location).Path $OutFile }
673
- $outDir = Split-Path -Parent $outPath
674
- if ($outDir -and -not (Test-Path -LiteralPath $outDir -PathType Container)) {
675
- New-Item -ItemType Directory -Path $outDir -Force | Out-Null
676
- }
677
- Set-Content -LiteralPath $outPath -Value $body -Encoding utf8 -NoNewline
678
- }
679
-
680
- if ($Json) {
681
- [pscustomobject]@{
682
- url = $url
683
- body = $body
684
- identity = $identity
685
- } | ConvertTo-Json -Depth 6
686
- exit 0
687
- }
688
-
689
- $body
690
- ''
691
- '---'
692
- "Prefilled issue URL (nothing is filed until you submit it):"
693
- $url
694
- if ($OutFile) { "Body also written to: $OutFile" }
695
- exit 0