Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .opencode/commands/uf.agent-brief.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,18 @@ Insert this verbatim:
```markdown
## Specification Workflow

All non-trivial changes MUST be preceded by a spec workflow.
Every change follows a workflow tier chosen for that change's
scope and risk — no single tier is mandatory. `/uf.unleash`
picks the tier automatically through the `tier-routing` skill
when a change starts on `main` or an unrecognized branch (a
tier-named branch missing its artifacts stops instead); agents
working by hand apply the same rubric.

| Tier | Tool | When | Artifacts |
|------|------|------|-----------|
| Strategic | Speckit | >= 3 stories, cross-repo | `specs/NNN-*/` |
| Tactical | OpenSpec | < 3 stories, single-repo | `openspec/changes/*/` |
| Quick | `/uf.unleash` routing | trivial fixes, chores, docs | `quick/<name>` branch |

Pipeline: `constitution → specify → clarify → plan → tasks →
analyze → checklist → implement`
Expand All @@ -220,19 +226,21 @@ before tasks. Tasks before implementation. Spec artifacts MUST
be committed/pushed before implementation begins.

**Branches**: Speckit: `NNN-<name>`. OpenSpec: `opsx/<name>`.
Quick: `quick/<name>` (no spec artifacts, full quality gates).

**Task bookkeeping**: Mark checkboxes `[x]` immediately on
completion. `[P]` marks parallel-eligible tasks.

**When in doubt**: Start with OpenSpec. Escalate to Speckit if
scope grows beyond 3 stories or crosses repo boundaries.
**When in doubt**: Choose the heavier of two adjacent tiers.
Escalate OpenSpec to Speckit if scope grows beyond 3 stories or
crosses repo boundaries.

**What requires a spec**: New features, refactoring that changes
signatures, test additions across multiple functions, agent
changes, CI changes, data model changes.
**Risk floors** (escalate only): security-sensitive code,
authentication/authorization flows, data-loss paths, or a
public API break MUST use OpenSpec at minimum — never Quick.

**Exempt**: Constitution amendments, typo fixes, emergency
hotfixes (retroactively documented).
**Quality gates apply to every tier**: Quick skips spec
artifacts, not review — CI and code review still gate merge.
```

#### Section 8: Knowledge Retrieval (verbatim template, conditional)
Expand Down
76 changes: 70 additions & 6 deletions .opencode/commands/uf.review-council.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,66 @@ Review the current codebase for compliance with the Behavioral Constraints in `A

1. **Run local quality gates before delegating to
council agents.** This step has three phases that
MUST execute in order. All three phases apply only
to Code Review Mode -- Spec Review Mode skips them.
MUST execute in order, preceded for PR input by the
Phase 1 head root block. All of it applies only to
Code Review Mode -- Spec Review Mode skips it.

#### Phase 1 head root (PR input only)

When the resolved input context is `kind: pr`, the local
gates in Phases 1a and 1b MUST judge the PR's frozen head,
never the agent's own checkout (issue #1204). Before Phase
1a, call the `review_head_root` plugin tool once:
`{action: "prepare", pr_number: <pr_number>, base_sha: <base_sha>, head_sha: <head_sha>}`.
It reuses the current checkout when it is a clean
checkout of `head_sha`, and otherwise adds a detached
worktree at `head_sha` under `.uf/review-head/`. It never
switches, stashes, or modifies the user's branch, index,
or working tree. A success looks like:

```json
{"status":"ok","data":{"root":"/repo/.uf/review-head/k3v9x2qa","head_sha":"<40-hex>","base_sha":"<40-hex>","method":"worktree","created":true,"config_sha":"<40-hex>","config_dirty":false,"provenance_line":"Gates ran at: <40-hex> (worktree); config from <40-hex>","gaze_skip_note":"Gaze skipped: the PR head is in a temporary worktree and gaze-reporter has no root argument","changed_files":["internal/a.go"]}}
```

On `status: "error"`, do NOT run local gates anywhere.
Phase 1a stays mandatory, so every code takes the Phase
1a FAIL path (step c below) even though no pre-flight
verdict exists: report the code and message as a
CRITICAL finding, skip Phases 1a, 1b, and 1c, dispatch
no reviewer children, and run only the non-child
planning and finalization portions of the shared
protocol to record coverage `FAIL`, terminal skipped
runs, and failing `INCONCLUSIVE`. Then stop. The codes:
- `UNTRUSTED_HEAD`: a fork PR whose author lacks write
access. Its code is not fetched or run. The message
names the opt-in: check out the head yourself
(`gh pr checkout <N>`) and re-run, which takes the
reuse path.
- `HEAD_MOVED`: the PR's head is no longer the frozen
`head_sha` (it was pushed since); re-run the council.
- `HEAD_UNAVAILABLE`: no remote names the base
repository, or a fetch or `gh` lookup failed.
- `WORKTREE_FAILED`: `git worktree add` failed; the
message carries git's error.
- `REVIEW_HEAD_ROOT_ERROR`: an unexpected tool error; the
message carries the detail.

On success, pass the whole prepare result to Phase 1a. After Phase 1b (or on any
STOP after a successful prepare), call `review_head_root`
once with `{action: "release", root: <root>}`. No later
step reads the root. A release failure is a warning in
the final report and never changes the verdict.

Local and uncommitted input skips this block: Phases 1a
and 1b run in the current checkout, as before.

#### Phase 1a -- Pre-flight Checks (mandatory, soft gate)

Load the `pre-flight` skill and run in `soft-gate`
mode:
mode, passing the whole prepare result (`root`,
`changed_files`, `base_sha`, and the provenance fields
`head_sha`, `method`, `config_sha`, `config_dirty`) when
the Phase 1 head root block prepared it:

a. Invoke the `skill` tool with name `pre-flight` to
load the shared pre-flight check instructions.
Expand All @@ -638,15 +691,17 @@ Review the current codebase for compliance with the Behavioral Constraints in `A
tools in soft-gate mode (do NOT stop on first
failure; record all results)
5. Baseline Establishment (Phase 4a) — if any
tools failed, establish a baseline for `main`
using the two-tier strategy (CI API first,
tools failed, establish a baseline for the base
(the PR's `base_sha` in PR mode, else the default
branch) using the two-tier strategy (CI API first,
worktree fallback)
6. Causality Classification (Phase 4b) — classify
each failure as branch-caused, pre-existing,
or unknown

c. **If the pre-flight verdict is FAIL
(branch-caused)**: **STOP immediately.** Report
(branch-caused), or the Phase 1 head root prepare
returned `status: "error"`**: **STOP immediately.** Report
each branch-caused failure as a CRITICAL finding
with the full error output. Do NOT proceed to
Phase 1b, Phase 1c, or child delegation.
Expand All @@ -667,6 +722,15 @@ Review the current codebase for compliance with the Behavioral Constraints in `A

#### Phase 1b -- Gaze Quality Analysis (conditional)

For PR input whose prepare result carries a
`gaze_skip_note` (method `worktree`), skip this phase
with that rendered note verbatim — "Gaze skipped: the
PR head is in a temporary worktree and gaze-reporter
has no root argument" — and proceed. Running Gaze from
the agent's checkout would score the wrong code. With
`method: "checkout"` (or local input), `gaze_skip_note`
is null; continue below.

a. Check if `gaze` is available:
```bash
which gaze
Expand Down
65 changes: 56 additions & 9 deletions .opencode/commands/uf.review-pr.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,47 @@ This is the reviewed diff. Pass it to every child agent prompt.

### 3.7. Pre-flight Checks (ci-aware, soft gate)

Load the `pre-flight` skill and run in `ci-aware` mode:

1. Invoke the `skill` tool with name `pre-flight` to
load the shared pre-flight check instructions.
Local gates run against the PR's frozen head commit, never
the agent's own checkout (issue #1203).

1. **Prepare the head root.** Call the `review_head_root`
plugin tool once:
`{action: "prepare", pr_number: <PR_NUMBER>, base_sha: <base_sha>, head_sha: <head_sha>}`.
It reuses the current checkout when it is a clean
checkout of `head_sha`, and otherwise adds a detached
worktree at `head_sha` under `.uf/review-head/`. It never
switches, stashes, or modifies the user's branch, index,
or working tree. A success looks like:

```json
{"status":"ok","data":{"root":"/repo/.uf/review-head/k3v9x2qa","head_sha":"<40-hex>","base_sha":"<40-hex>","method":"worktree","created":true,"config_sha":"<40-hex>","config_dirty":false,"provenance_line":"Gates ran at: <40-hex> (worktree); config from <40-hex>","gaze_skip_note":"Gaze skipped: the PR head is in a temporary worktree and gaze-reporter has no root argument","changed_files":["internal/a.go"]}}
```

2. Execute the pre-flight skill's phases in order:
On `status: "error"`, do NOT run local tools anywhere.
Record the failure envelope's rendered `not_run_line`
verbatim as the Step 3.7 result (e.g. `Local gates: not
run (<code>): <message>`), skip items 2-3, and continue
with CI evidence only:
- `UNTRUSTED_HEAD`: a fork PR whose author lacks write
access. Its code is not fetched or run. The message
names the opt-in (check out the head yourself and
re-run).
- `HEAD_MOVED`: the PR's head is no longer the
`head_sha` Step 2 froze (it was pushed since); re-running
the review picks up the new head.
- `HEAD_UNAVAILABLE`: no remote names the base
repository, or a fetch or `gh` lookup failed.
- `WORKTREE_FAILED`: `git worktree add` failed; the
message carries git's error.
- `REVIEW_HEAD_ROOT_ERROR`: an unexpected tool error; the
message carries the detail.

2. **Run pre-flight.** Invoke the `skill` tool with name
`pre-flight`, in `ci-aware` mode, passing the whole
prepare result (`root`, `changed_files`, `base_sha`, and
the provenance fields `head_sha`, `method`, `config_sha`,
`config_dirty`). Execute
its phases in order:
a. CI Workflow Parsing — discover commands from `.github/workflows/`
b. Local Tool Detection — check for config files and verify binary availability
c. CI Coverage Matrix — build the matrix using the CI check results from Step 3. Apply ci-aware decision rules:
Expand All @@ -267,9 +302,21 @@ Load the `pre-flight` skill and run in `ci-aware` mode:
- No CI checks at all → MUST run ALL detected local tools
d. Execution — run only tools marked "Yes" in the coverage matrix. Do NOT stop on first failure.

3. **Record results**: CI Coverage Matrix, Execution Results, Verdict.
If tools pass, skip those categories in the AI review.
If tools fail, include the failure output as context.
3. **Release the head root.** Call `review_head_root` once
with `{action: "release", root: <root>}` as soon as item 2
finishes, and before any STOP after a successful
prepare. No later step reads the root: the light check
and the reviewers read the PR diff through `gh`. A
release failure is a warning in the report and never
changes the verdict.

**Record results**: the prepare result's rendered
`provenance_line` (or the failure envelope's rendered
`not_run_line`, which ends in `: <message>`), verbatim, CI
Coverage Matrix,
Execution Results, and Verdict. If tools pass, skip those
categories in the AI review. If tools fail, include the
failure output as context.

### 3.8. Discover Review Context

Expand Down Expand Up @@ -710,7 +757,7 @@ Present the findings in this structured format:
| <name> | PASS/FAIL | PR-caused / Pre-existing / N/A |

### Local Tool Results
<Table showing which tools ran, pass/fail status, and summary of failures if any>
<provenance_line from the prepare result, or its not_run_line from the failure envelope, verbatim; then a table showing which tools ran, pass/fail status, and summary of failures if any>

### Walkthrough
| File | Change | Focus |
Expand Down
30 changes: 25 additions & 5 deletions .opencode/lib/agent-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ export interface InvokeAgentResult {
* length policy to non-empty (truncated) runs (RD-FR-060).
*/
readonly finish_reason?: string | null
/**
* Name of the child's message error (for example
* `MessageAbortedError`), present only on `child_message_error`
* failures (delegate-abort-recovery D2, DAR-FR-002). The executor's
* own `retryable` value is unchanged; callers that can read durable
* state decide whether the abort is resumable.
*/
readonly message_error_name?: string
}

/** Injected dependencies for the shared executor's child session lifecycle. */
Expand Down Expand Up @@ -372,7 +380,19 @@ export function errorText(error: unknown): string {
* @returns A bounded message safe to retain in invocation provenance.
*/
export function sanitizeInvocationError(message: string): string {
const sanitized = message
return redactInvocationText(message).slice(0, MAX_ERROR_LENGTH)
}

/**
* Redacts credentials, bearer values, URL queries, and absolute home
* paths without bounding the length (delegate-abort-recovery D4): the
* shared redaction behind sanitizeInvocationError, for callers that apply
* their own bound.
* @param message Untrusted provider, runtime, or child-session text.
* @returns The redacted text, unbounded.
*/
export function redactInvocationText(message: string): string {
return message
.replace(/\bBearer\s+[^\s,;"']+/gi, "Bearer [REDACTED]")
.replace(
/\b(api[-_ ]?key|access[-_ ]?token|refresh[-_ ]?token|token|secret|password|credential)s?\b(\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;"']+)/gi,
Expand All @@ -381,7 +401,6 @@ export function sanitizeInvocationError(message: string): string {
.replace(/(https?:\/\/[^\s?#]+)\?[^\s#]*/gi, "$1?[REDACTED]")
.replace(/(?:\/Users|\/home)\/[^/\s]+(?:\/[^\s,;:"']*)?/g, "~/[REDACTED]")
.replace(/[A-Za-z]:\\+Users\\+[^\\\s]+(?:\\+[^\s,;:"']*)?/g, "~\\[REDACTED]")
return sanitized.slice(0, MAX_ERROR_LENGTH)
}

export function responseFailure(label: string, response: ResponseErrorLike): string {
Expand Down Expand Up @@ -913,8 +932,8 @@ export async function executeAgentSession(
const finishReason = responseFinishReason(prompted.data.parts)

if (prompted.data.info.error !== undefined) {
return withChild(
failedResult(
return withChild({
...failedResult(
provenance,
"child_message_error",
errorText(prompted.data.info.error),
Expand All @@ -925,7 +944,8 @@ export async function executeAgentSession(
text,
usage,
),
)
message_error_name: prompted.data.info.error.name,
})
}
// Fail-closed guard (RD-FR-059, design D1): a child whose final text is
// empty after trimming did not complete its response — including the
Expand Down
Loading
Loading