Skip to content

Commit f014f42

Browse files
committed
ci(guardrails): enforce opencode boundary checks on pointer updates
1 parent 0ef3b43 commit f014f42

6 files changed

Lines changed: 72 additions & 7 deletions

File tree

.githooks/pre-push

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
./scripts/check-opencode-submodule-published.sh
4+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
ZERO_SHA="0000000000000000000000000000000000000000"
6+
7+
"$REPO_ROOT"/scripts/check-opencode-submodule-published.sh
8+
9+
needs_guardrails=0
10+
11+
while read -r local_ref local_sha remote_ref remote_sha; do
12+
[ -z "${local_ref:-}" ] && continue
13+
[ "${local_sha:-$ZERO_SHA}" = "$ZERO_SHA" ] && continue
14+
15+
if [ "${remote_sha:-$ZERO_SHA}" = "$ZERO_SHA" ]; then
16+
revs="$(git -C "$REPO_ROOT" rev-list "$local_sha" --not --all)"
17+
else
18+
if git -C "$REPO_ROOT" cat-file -e "${remote_sha}^{commit}" 2>/dev/null; then
19+
revs="$(git -C "$REPO_ROOT" rev-list "${remote_sha}..${local_sha}")"
20+
else
21+
echo "Remote base commit ${remote_sha} is not available locally; running strict opencode guardrails conservatively..."
22+
needs_guardrails=1
23+
break
24+
fi
25+
fi
26+
27+
[ -z "$revs" ] && continue
28+
29+
if git -C "$REPO_ROOT" diff-tree --stdin --no-commit-id --name-only -r <<<"$revs" | rg -q '^packages/opencode$'; then
30+
needs_guardrails=1
31+
break
32+
fi
33+
done
34+
35+
if [ "$needs_guardrails" -eq 1 ]; then
36+
echo "Detected outgoing packages/opencode pointer update; running strict opencode guardrails..."
37+
(cd "$REPO_ROOT" && just check-opencode-guardrails)
38+
fi

AGENTS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Only proceed with the commit if it passes. If it fails, fix the issues first.
1010

1111
`just pre-commit` intentionally runs generation and formatting steps that may modify files you did not edit directly (including markdown). Treat these diffs as expected outputs of the check pipeline.
1212

13+
`just pre-commit` also runs `just check-opencode-guardrails-autofix`, which may auto-sync fork-boundary manifest drift in `packages/opencode/docs/upstream-sync/fork-boundary-manifest.json` when drift is the only issue.
14+
1315
If those diffs are mechanical (generation/format/lint output only), they should be committed with the related change. Do not treat them as noise and do not leave them uncommitted.
1416

1517
Common expected examples (non-exhaustive):
@@ -79,7 +81,7 @@ Setup reference:
7981
This repo uses git hooks (wired via `git config core.hooksPath .githooks`, set up by `just setup`):
8082

8183
- **pre-commit** — Syncs README to npm packages, guards against unpublished submodule pins, runs cfn-lint on CloudFormation changes.
82-
- **pre-push** — Validates the opencode submodule commit is published.
84+
- **pre-push** — Validates the opencode submodule commit is published. When outgoing commits update the `packages/opencode` gitlink, it also runs strict opencode guardrails (`just check-opencode-guardrails`) before push.
8385
- **post-merge** — After every `git pull`, automatically syncs the submodule and runs `bun install`. No manual action needed.
8486

8587
## README Badge Sync
@@ -159,6 +161,16 @@ The submodule should always be detached at the superproject-pinned commit. If `g
159161
git submodule update --recursive
160162
```
161163

164+
### Fork Boundary Checks in Detached Submodules
165+
166+
`packages/opencode/script/check-fork-boundary.ts` and `packages/opencode/script/sync-fork-boundary-manifest.ts` resolve target refs as:
167+
168+
1. `FORK_BOUNDARY_TARGET_REF` (when explicitly set)
169+
2. Current symbolic branch name
170+
3. `HEAD` fallback when detached
171+
172+
This branch-or-HEAD behavior prevents false passes from stale local `dev` refs in detached submodule states.
173+
162174
### Fixing stale `core.worktree` errors
163175

164176
If you see errors like "cannot be used without a working tree" or submodule commands fail mysteriously, the submodule's `core.worktree` config is pointing to a wrong or deleted worktree path. Fix from the affected worktree:

CLAUDE.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Only proceed with the commit if it passes. If it fails, fix the issues first.
1010

1111
`just pre-commit` intentionally runs generation and formatting steps that may modify files you did not edit directly (including markdown). Treat these diffs as expected outputs of the check pipeline.
1212

13+
`just pre-commit` also runs `just check-opencode-guardrails-autofix`, which may auto-sync fork-boundary manifest drift in `packages/opencode/docs/upstream-sync/fork-boundary-manifest.json` when drift is the only issue.
14+
1315
If those diffs are mechanical (generation/format/lint output only), they should be committed with the related change. Do not treat them as noise and do not leave them uncommitted.
1416

1517
Common expected examples (non-exhaustive):
@@ -79,7 +81,7 @@ Setup reference:
7981
This repo uses git hooks (wired via `git config core.hooksPath .githooks`, set up by `just setup`):
8082

8183
- **pre-commit** — Syncs README to npm packages, guards against unpublished submodule pins, runs cfn-lint on CloudFormation changes.
82-
- **pre-push** — Validates the opencode submodule commit is published.
84+
- **pre-push** — Validates the opencode submodule commit is published. When outgoing commits update the `packages/opencode` gitlink, it also runs strict opencode guardrails (`just check-opencode-guardrails`) before push.
8385
- **post-merge** — After every `git pull`, automatically syncs the submodule and runs `bun install`. No manual action needed.
8486

8587
## README Badge Sync
@@ -159,6 +161,16 @@ The submodule should always be detached at the superproject-pinned commit. If `g
159161
git submodule update --recursive
160162
```
161163

164+
### Fork Boundary Checks in Detached Submodules
165+
166+
`packages/opencode/script/check-fork-boundary.ts` and `packages/opencode/script/sync-fork-boundary-manifest.ts` resolve target refs as:
167+
168+
1. `FORK_BOUNDARY_TARGET_REF` (when explicitly set)
169+
2. Current symbolic branch name
170+
3. `HEAD` fallback when detached
171+
172+
This branch-or-HEAD behavior prevents false passes from stale local `dev` refs in detached submodule states.
173+
162174
### Fixing stale `core.worktree` errors
163175

164176
If you see errors like "cannot be used without a working tree" or submodule commands fail mysteriously, the submodule's `core.worktree` config is pointing to a wrong or deleted worktree path. Fix from the affected worktree:

justfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ check-opencode-guardrails: opencode-install-if-needed
118118
bun run --cwd packages/opencode sdk:parity:check
119119
bun run --cwd packages/opencode fork:boundary:check
120120

121+
# Run opencode guardrails with safe local autofix for boundary manifest drift.
122+
# Intended for local pre-commit paths only; CI/pre-push must stay strict.
123+
check-opencode-guardrails-autofix: opencode-install-if-needed
124+
bun run --cwd packages/opencode rules:parity:check
125+
bun run --cwd packages/opencode sdk:parity:check
126+
FORK_BOUNDARY_AUTOFIX=1 bun run --cwd packages/opencode fork:boundary:check
127+
121128
# Typecheck opencode workspace
122129
# Keep scripts.typecheck defined in each fork-* package so Turbo executes its task.
123130
lint-opencode: opencode-install-if-needed check-fork-typecheck-wiring
@@ -361,7 +368,7 @@ do-marketplace-build:
361368

362369
# Pre-commit checks with conditional Docker stage build for Docker-risk changes.
363370
# This keeps routine commits fast while still catching Docker context regressions.
364-
pre-commit: check-opencode-submodule-published sync-opencode-sdk check-opencode-guardrails fmt lint build test-all-fast
371+
pre-commit: check-opencode-submodule-published sync-opencode-sdk check-opencode-guardrails-autofix fmt lint build test-all-fast
365372
@PLAYWRIGHT_WORKERS="${PLAYWRIGHT_WORKERS:-1}" \
366373
OPENCODE_E2E_CLEAN_SESSION_STATE="${OPENCODE_E2E_CLEAN_SESSION_STATE:-0}" \
367374
just e2e
@@ -373,7 +380,7 @@ pre-commit: check-opencode-submodule-published sync-opencode-sdk check-opencode-
373380
fi
374381

375382
# Pre-commit checks including Docker build (requires Docker)
376-
pre-commit-full: check-opencode-submodule-published sync-opencode-sdk check-opencode-guardrails fmt lint build test-all-fast build-docker
383+
pre-commit-full: check-opencode-submodule-published sync-opencode-sdk check-opencode-guardrails-autofix fmt lint build test-all-fast build-docker
377384
@PLAYWRIGHT_WORKERS="${PLAYWRIGHT_WORKERS:-1}" \
378385
OPENCODE_E2E_CLEAN_SESSION_STATE="${OPENCODE_E2E_CLEAN_SESSION_STATE:-0}" \
379386
just e2e

packages/core/src/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ COPY --chown=opencoder:opencoder packages/opencode /tmp/opencode-local
556556
# Update it by running: ./scripts/update-opencode-commit.sh
557557
RUN set -eux; \
558558
OPENCODE_COMMIT_OVERRIDE="${OPENCODE_COMMIT:-}"; \
559-
OPENCODE_COMMIT="65d53d330955a759cca6bac50039a2a923da7fb9"; \
559+
OPENCODE_COMMIT="d5432b5dbce9bf11d422cc2516119260ab156859"; \
560560
if [ -n "${OPENCODE_COMMIT_OVERRIDE}" ]; then OPENCODE_COMMIT="${OPENCODE_COMMIT_OVERRIDE}"; fi; \
561561
rm -rf /tmp/opencode-repo; \
562562
if [ "${OPENCODE_SOURCE}" = "local" ]; then \

0 commit comments

Comments
 (0)