You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 205a953
Browse filesBrowse the repository at this point in the historyBrowse files
* chore(hygiene): [#1052 D8] pre-push scan for internal-tracker refs
Public repo hardening: catch tracker-adjacent references before they land in
commits, branches, or file content. The exact patterns live in the RULES
array in `script/check-tracker-leaks.ts` — read there for the canonical list.
- `script/check-tracker-leaks.ts` — bun script that scans branch name +
commit messages + added-lines diff vs `origin/main`. Silent on clean;
exits 1 with per-source report on hit. Bypass via `SKIP_TRACKER_CHECK=1`.
- `.husky/pre-push` — invokes the script after existing typecheck.
- `CONTRIBUTING.md` — one-line note pointing at the hook + how to bypass.
CI-side mirror deferred to a follow-up PR (needs a `workflow`-scoped token
to add `.github/workflows/*` and this session's token doesn't have it). The
D8 issue calls out both local + CI as needed — local hook is the primary
guard; CI is the backstop for contributors who never ran
`git config core.hooksPath .husky` or who used the bypass env var.
The scan is diff-based: existing tracker-adjacent strings in main
(a handful in comments) are grandfathered and won't trigger on unrelated
PRs. Only NEW added lines are checked, so touching a file with a legacy
reference is safe as long as the reference itself doesn't appear in the
diff's `+` lines.
* test(build): [#1052 D10] stamp-based staleness guard for the smoke test
The m5 guard walked `src/` + `script/` mtimes for the newest touched file.
Correct for the common case but blind to changes in CHANGELOG.md, migrations,
bundled skills, models-snapshot.ts, the opentui parser worker, and the
per-platform altimate-core prebuild — any of which can change the compiled
binary's shape without touching a `.ts` file.
- `packages/opencode/script/build.ts` — emit `dist/<target>/bin/build-inputs.json`
at the end of each per-target build. JSON lists every embedded input's
sha256 plus an aggregate hash over the sorted pairs. Paths are relative to
`packages/opencode` so the read side can resolve them without env plumbing.
- `packages/opencode/test/install/smoke-test-binary.test.ts` — new
`isBinaryStaleFromStamp()` rehashes each listed input and reports stale on
any mismatch. Falls back to the old mtime walk when the stamp is missing
(older `bun run build:local` runs, or targets built before this landed).
- Explicit `no-stamp` sentinel routes cleanly to the fallback without
conflating "no binary" with "no stamp" — both surface as skips, but for
different messages.
* test(harness): [#1052 D11] idempotent retry in cli-process.run()
The `database is locked` retry re-spawns `opencode run` against the same
XDG_DATA_HOME. If the first attempt got as far as opening SQLite and taking
a partial write before the WAL/checkpoint collision fired, a naive retry
would either see partial state or double-write on top of it — exactly the
non-idempotent behavior the CodeRabbit review on PR #1053 flagged.
Fix: before the retry, delete `opencode*.db{,-wal,-shm}` under the fixture's
isolated data dir. The retry then boots into a clean SQLite state. Other
fixture content (config file, home files, extra test setup) is preserved —
tests that inject state into `home` still see it.
This is deliberately narrower than "reset the whole fixture" (option b in
the deferral): scrubbing DB files only preserves any state a caller wrote
before invoking `run()`, which some tests rely on.
* test(tui): [#1052 D12] deterministic regression test for phaseLabel()
Replaces the deleted `phase-label.tui-e2e.test.ts` (was `test.skip` under
`CI=true` because a PTY poll-interval race made it flaky). The published
chain — `publishPhase → Bus → sync.tsx handler → store → render` — is now
covered in three deterministic layers:
1. Server-side publish + subscribe wiring: existing fork-feature-guards
string-shape assertions in `test/upstream/fork-feature-guards.test.ts`.
2. Store-mutation handler in `context/sync.tsx` case "session.phase":
same fork-feature-guards test.
3. Last-mile label lookup — THIS FILE. If `phase-label.ts` PHASE_LABELS
drifts from the span names `SessionPrompt.traceSpan` emits, users see
the "Thinking..." fallback silently. This test catches that.
Full component-level synthetic-event coverage remains a future extension of
D12; the event-injection scaffolding does not exist as a reusable fixture
yet and is not gated on this file.
* fix(models): [#1052 D14] drop eager import-time ModelsDev.refresh()
Previously `setTimeout(() => ModelsDev.refresh(), 0)` fired a fetch to
https://models.dev/api.json at module import. Its `AbortSignal.timeout(10000)`
cannot cancel a synchronous `getaddrinfo()`; under Linux `unshare --net`
(Verdaccio sanity Phase 3 [10/10] on Ubuntu CI runners) DNS blocked long
enough that the pending fetch held the event loop past command completion
and SIGTERM landed before any bytes flushed. That blocked the v0.9.4 release
and forced the SKIP that ships in `test/sanity/phases/resilience.sh` today.
Fix: no eager fetch. Callers use `ModelsDev.Data()` which resolves via
(1) local disk cache → (2) bundled `models-snapshot.ts` (always present
in release binaries, regenerated at build time) → (3) fetch only if both
absent. The bundled snapshot means release-binary users always have model
metadata even on a completely offline cold start. Long-running processes
(TUI, serve) still receive updates via the hourly `setInterval` below,
`.unref()`'d so it never blocks exit. Short-lived commands rely on the
snapshot's release-time freshness.
Trade-off: models added to models.dev between releases don't appear in
short-lived commands until the next release rebuild. Bounded by release
cadence. Acceptable given the release-blocker this closes.
Follow-up (not in this PR): re-enable the `[10/10] no-internet graceful
handling` sanity test once this fix has soaked through one release.
* fix(hygiene): [#1052 D8 review-fix M1] catch suffix-adjacent tracker leaks + self-test
Consensus review flagged the D8 scanner's Jira-key regex as its strongest
finding — the trailing word-boundary requires a non-word char after the
digits, which fails when a letter, digit, or underscore immediately follows.
Exactly the class of typo and paste-through the scrubber exists to prevent.
Naïve fixes (negative lookahead over word chars) don't help: the regex
engine backtracks the digit run, but every position still has a digit as
the "next char" so the lookahead keeps failing. Correct fix is to drop the
trailing boundary entirely — the pattern matches greedily through the
digits, stops at the first non-digit, and reports the prefix regardless of
what follows.
Known blind spot documented + tested: pastes with no separator before the
prefix (no leading word-boundary) are not caught. Realistic leak surface
(branches, commit messages, path fragments, doc text) is delimited so this
does not hit in practice.
Also: gate the scanner's `main()` behind `import.meta.main` so RULES can be
imported by the self-test without triggering a scanner run at test
collection time.
`packages/opencode/test/skill/tracker-leak-check.test.ts` — 28 test cases
pinning positive / negative / blind-spot behaviour for both regexes. Runs
under `bun test`. If the regex regresses, this test catches it before the
local push hook or CI misses a leak.
* test(build): [#1052 D10 review-fix M2] widen stamp to workspace packages + lockfile
Consensus review flagged that the D10 stamp (from `b22861e091`) only walks
`packages/opencode/src` and `packages/opencode/script`, but Bun.build follows
imports into every workspace package (`@opencode-ai/core`, `@opencode-ai/tui`,
`@opencode-ai/util`, `@opencode-ai/plugin`, `@altimateai/dbt-tools`, …) and
bundles them into the binary. Edits under those packages, or a `bun install`
that bumps a bundled dep, left the stamp reporting fresh — exactly the
false-negative pattern the guard was meant to close.
Changes:
- `packages/opencode/script/build.ts` — enumerate `packages/*/src` at build
time and walk each (opencode/ is already walked directly). Also hash every
workspace `packages/*/package.json`, the workspace-root `package.json`, and
`bun.lock`. Enumerating rather than hard-coding lets new workspace packages
get covered automatically.
- Stamp paths are now REPO_ROOT-relative (not packages/opencode-relative) so
entries like `packages/tui/src/util/record.ts` resolve without munging.
- `packages/opencode/test/install/smoke-test-binary.test.ts` — resolve stamp
entries against `REPO_ROOT` instead of `PKG_DIR`. Fallback to the mtime walk
is unchanged (still works for older builds without a stamp).
Verified: typecheck clean; existing D12 phase-label test still passes; smoke
test skips cleanly when no binary is present (unchanged behaviour). A build
+ tampering with a workspace-package file will now flip the stamp; a build +
stale binary + edit to `packages/tui/src/...` will trigger the skip that the
old walk missed.
* fix(models): [#1052 D14 review-fix M3] don't crash on non-JSON error body + fire refresh at boot
Two consensus-review findings on the D14 commit (`248eaaf86c`):
1. Pre-existing crash: `ModelsDev.Data()`'s `Flock.withLock` branch calls
`JSON.parse(result2.text)` unconditionally after `fetchApi()` returns —
even when `result2.ok === false` and the body is an HTML 5xx error page.
That throws `SyntaxError` and blocks model initialization. Bug existed
before D14 but was rarely exposed because the eager import-time refresh()
warmed the disk cache first, so most subsequent `Data()` calls returned via
`readJson`. Post-D14 more first-calls fall through to fetch, so the crash
window widens. Fix: return `{}` when `!result2.ok` — callers already tolerate
an empty catalog (Provider.state produces no models.dev-derived entries,
same UX as `OPENCODE_DISABLE_MODELS_FETCH=1`).
2. Reintroduce a boot-time refresh without holding the event loop: 4/6
reviewers flagged the loss of "fresh at boot" as a real regression for
short-lived commands. Fix: `Promise.resolve().then(() => refresh().catch())`.
A microtask can't itself keep Bun alive, and if the fetch it schedules is
still in flight at process-exit the snapshot covers callers on the next
run. Preserves the load-bearing part of the D14 fix (no `setTimeout` keeping
the loop alive) while restoring near-immediate cache warming. If this ever
reintroduces the unshare-net sanity hang on CI, drop the Promise.then line —
the snapshot alone keeps release binaries functional offline.
Also fixes the misleading comment "always have model metadata even on a
cold-start with no network" — accurate for release binaries but false in
dev-mode where the snapshot isn't embedded. Reworded to say so.
Verified: typecheck clean; `--version` exits in ~1s cleanly; existing D12
phase-label test still passes.
* fix(hygiene): [#1052 D8 review-fix follow-up] scrub example strings from scanner source
The consensus review-fix for D8 (commit 0ffc42db97) added concrete tracker-
key literals to the scanner's own test file and doc comments — e.g. inside
`test.each([...])` fixtures, in the block comment above `RULES`, and in the
pre-push hook comment. Those are the exact strings the scanner is meant to
catch, so a pre-push run flagged them on this branch. That defeats the
purpose: no example strings should appear as grep-visible literals in a repo
whose whole rule is "don't put those literals here."
Fix:
- Test fixtures now build the strings at runtime from split prefix + digits
(`const PREFIX = "A" + "I"`, `key(1234, "foo")` etc). The regex still sees
what it needs to test; a source grep for the pattern finds nothing.
- Scanner source comment loses its verbatim example strings — the intent is
clear from the code + tests.
- `.husky/pre-push` comment stops naming a specific pattern host; the
scanner's own RULES are the source of truth.
- Path-allowlist added in the same commit is no longer needed and dropped —
keeps the guard strict for everyone.
Verified: `bun test packages/opencode/test/skill/tracker-leak-check.test.ts`
still 28/28 pass; scanner reports clean on the working tree.
* fix(hygiene): [#1052 bot-review round] harden scanner + stamp + models.dev cache
Addresses the actionable findings from the CodeRabbit + cubic-ai + kilo-code
bot reviews on PR #1085 (Claude review skipped — not @Claude-Review'd). Only
real issues; noisy or already-documented findings are noted in the PR reply.
Scanner (`script/check-tracker-leaks.ts`):
- **Cubic P1 (security):** the `--base` arg used to be embedded in `sh -c
"${cmd}"`, which the shell then re-parsed — a caller could smuggle
arbitrary shell via `--base=$(...)`. Replace with a shell-free
`git(args[])` helper using Bun.$ tagged templates (each arg becomes one
argv element, no shell). Belt-and-braces: reject `--base` values that
don't look like a git ref (`^[A-Za-z0-9/_.@{}~^-]+$`) before running any
git command, so a bad value fails loud instead of silently.
- **Cubic P1 (correctness):** `shOK` used to `catch { return "" }`, so a
real git failure (missing binary, corrupt index) reported as a clean
scan. New helper `git()` fails loud with exit code 2 on unexpected
errors; only `merge-base` (which legitimately returns empty on diverged
history) opts into the silent path.
- **CodeRabbit Major:** the diff parser's `!startsWith("+++")` filter
dropped legitimate content lines starting with `++` (e.g. an added
an added line whose text starts with two plus signs renders as `+++...` in unified-diff). Match the file
header exactly (`+++ ` or `+++\t`) so a content line whose prefix happens to look like `+++<text>` still gets scanned.
Build stamp (`packages/opencode/script/build.ts`):
- **Kilo suggestion:** `_stampRoot` and `REPO_ROOT` computed the same
value twice. Consolidated to one `REPO_ROOT` at the top of the block.
- **Kilo suggestion:** stale comment claimed paths were "relative to the
workspace root (dir = packages/opencode)" — post-M2 they're REPO_ROOT-
relative. Corrected.
- **Cubic P2:** `tsconfig.json` changes can flip target / moduleResolution
and change the compiled output shape without editing any `.ts` file.
Added `packages/opencode/tsconfig.json` to the stamp.
models.dev cache (`packages/opencode/src/provider/models.ts`):
- **CodeRabbit Minor:** a 2xx response can still carry HTML (proxies,
error pages that respond 200) or truncated JSON. The old code wrote
`result2.text` to the disk cache BEFORE the parse, so a bad body
poisoned the cache for the next run + crashed on the current call. Now
parses first; only caches + returns on success. On parse failure, log
with a body preview and return an empty catalog (same graceful path as
the non-2xx branch).
Not addressed (deferred / disagreed / duplicated with known caveats):
- Cubic P1 "cold-cache CLI still starts fetchApi → recreates D14 blocker"
and kilo warning on the same line — these identify the trade-off the
D14 review-fix commit explicitly documents; no change.
- Cubic P1 "hook doesn't wire to `bun run script/check-tracker-leaks.ts`"
— false positive; `.husky/pre-push` does invoke it.
- CodeRabbit + cubic P2 "new files added post-build not detected" —
real limitation, orthogonal fix, deferred to a follow-up (adding a
walk at read-time would double the cost of every test run).
Verified: typecheck 13/13; scanner self-test 28/28; scanner clean on this
branch; scanner rejects `--base=$(...)` with exit 2; `--version` still
exits in ~1s cleanly.
* fix(hygiene): [#1052 bot-review round 2] address open bot findings
Round 1 fixed 10 of the 22 bot comments; this covers the rest, plus two the
round-1 fixes introduced.
models.dev (coderabbit Major + kilo + cubic P1 — all three flagged it):
- Remove the import-time `Promise.resolve().then(() => ModelsDev.refresh())`.
The comment defending it argued a microtask cannot keep Bun alive. The
microtask cannot, but the `fetch()` it starts can — and on a cold cache
`refresh()` reaches `fetchApi()`, whose `AbortSignal.timeout` still cannot
cancel a blocking `getaddrinfo()`. That is the D14 release-blocker shape, so
the eager refresh is gone rather than rescheduled. Snapshot + on-demand load +
the unref'd hourly interval remain.
- Reject JSON that parses but is not a catalog object (`null`, `[]`, scalars —
what a misconfigured proxy returns with a JSON content-type) before writing
the disk cache, so the "don't poison the cache" intent holds for
structured-but-wrong bodies too.
Build stamp (cubic P2 x2, coderabbit Major, coderabbit Minor):
- Stamp `packages/opencode/package.json`. The workspace walk skips `opencode`,
so its own manifest was unstamped while a comment claimed otherwise.
- Extract the input walk to `script/stamp-inputs.ts` so the smoke-test guard can
re-enumerate with identical rules. Rehashing recorded inputs only catches
CHANGED and DELETED files; a file ADDED after the build left every hash
matching while the binary was stale. The stamp now records the walked roots
and the guard treats an unrecorded file under them as stale.
- Validate the stamp shape at runtime. `as BuildStamp` is a compile-time claim:
`{"inputs":"x"}` passed the old length check and then threw in the loop.
Tracker scanner (cubic P1 x2, cubic P2, cubic P3, coderabbit Major):
- Scan the refs actually being pushed, read from the pre-push stdin, instead of
always scanning HEAD. `git push origin dirty:other` previously approved a ref
nobody had looked at.
- A deletion-only push now scans nothing rather than falling back to HEAD.
Found by the new end-to-end tests, not by a reviewer.
- An unborn HEAD (`git init`, zero commits) no longer exits 2. That regression
came from round 1's `failOnError: true` default and contradicted the
documented brand-new-repo path.
- A missing base ref says so on stderr instead of exiting silently, so a guard
that has disabled itself is visible.
Test harness (coderabbit Major):
- `cli-process` SQLite scrub rethrows anything that is not ENOENT, so a
permission or removal failure no longer lets the retry start on half-written
state — the exact condition the scrub exists to prevent.
Verification: 5 end-to-end tests drive the real script against throwaway
repositories, including two real `git push` runs through an installed pre-push
hook (clean branch pushes; a branch carrying a tracker ref is blocked). Three of
them fail against the pre-fix scanner. Suites: 33 scanner, 580 provider, 218
install, 13/13 typecheck; lint warnings down from 15 to 13; markers verified
"All blocks properly closed" repo-wide.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
* fix(hygiene): [#1052 bot-review round 3] ref names, cache paths, stamp roots
Round-3 findings, all on code round 2 introduced.
Tracker scanner (coderabbit Major + cubic P1):
- Scan the ref NAMES being pushed, both ends. Round 2 started scanning pushed
ref CONTENT but still only ever scanned the checked-out branch's name, so
`git push origin main:refs/heads/<tracker-key>` published a tracker-shaped
branch while `main` and every line of its content were clean. The destination
ref is the one that becomes public and need not match the source; tags go the
same way. The checked-out branch name is now scanned only in the no-stdin
fallback.
models.dev cache (cubic P1 x2):
- `refresh()` wrote 2xx bodies straight to the cache with no validation at all,
so the hourly refresh could poison a cache the cold-fetch path was careful to
protect. Both paths now share one validator, as does the disk-cache READ, so
an entry poisoned by an older build is not trusted either.
- That validator no longer accepts any object. An object-shaped error payload
(`{"error": "rate limited"}`) passed the round-2 check. At least one value
must now parse as a `Provider`. Deliberately "at least one" rather than "all":
requiring all would let a single new upstream field empty the catalog, which
is a worse failure than the one being prevented.
Build stamp (coderabbit Minor x2, cubic P2, cubic P3):
- Include `.mp3` in the shared input extensions. packages/tui imports its
attention sounds with `{ type: "file" }`, so they are embedded in the binary,
but the extension filter excluded them and a changed sound left the stamp
fresh.
- Record `packages/*/src` as a glob alongside the concrete roots. Concrete roots
only describe packages that existed during the build, so a package added later
was invisible to the guard.
- Validate `roots`/`rootGlobs` like `inputs`. A non-array value threw a
TypeError at module load inside `describe()`, failing the whole file instead
of degrading to the mtime fallback — the opposite of the hardening round 2
added for `inputs`.
Tests (cubic P3):
- Remove the throwaway git repositories in `afterAll`. They carry tracker-key
fixtures, so leaving them in tmp is worse than ordinary litter.
- New end-to-end case for the destination-ref hole; it fails against the round-2
scanner.
Verification: 7-case e2e matrix against real repositories (unborn HEAD, clean,
content leak, pushed-ref content, no-stdin fallback, deletion-only push,
tracker-shaped destination ref) all as expected; 34 scanner + 799 provider and
install tests pass; 13/13 typecheck; no new lint warnings; markers balanced;
scanner clean against its own diff.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
* fix(models): [#1052] structural catalog validation, not the zod schema
Fixes a regression I introduced in round 3, caught by CI.
Round 3 gated the models.dev cache on `Provider.safeParse`, as a review
suggested. It looked right and was wrong: the schema requires a `Model.options`
record that real models.dev entries do not carry, so it rejects 0 of the 144
providers in our own bundled snapshot. Nothing was ever cached, and every load
fell through to a network fetch — which hangs in a sandboxed environment. The
only signal was an unrelated CLI smoke test timing out at 60s
("fresh-DB production path adopts the core schema"). Bisected to round 3, then
to this file.
The validator is now structural: a non-empty map whose values are provider
objects carrying a `models` map. That still rejects everything the reviewers
were worried about — `null`, `[]`, scalars, and object-shaped error payloads
like `{"error": "rate limited"}` — without coupling cache acceptance to a schema
that does not match the payload.
It moved to `provider/models-catalog.ts` (flat exports + self-reexport per
AGENTS.md) so it is directly testable. Trying to cover it through
`ModelsDev.get()` did not work: `Flag.OPENCODE_MODELS_PATH` is captured at
module load, so a test cannot redirect the cache path afterwards.
12 new tests pin the behaviour, and the first one is the guard that was
missing: the real bundled catalog must be accepted. `output-hygiene` is back to
3/3; provider, scanner and install suites total 811 pass.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
---------
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
`bun install` sets up the pre-push hook via `husky` — subsequent `git push` runs a bun-version check, `bun typecheck`, and a scan for internal-tracker references. If the tracker scan blocks you legitimately (extremely unlikely on this public repo), bypass with `SKIP_TRACKER_CHECK=1 git push`.
43
+
42
44
### Running against a different directory
43
45
44
46
By default, `bun dev` runs Altimate Code in the `packages/opencode` directory. To run it against a different directory or repository:
0 commit comments