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
25 changes: 21 additions & 4 deletions .github/actions/setup-bun/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,33 @@ runs:
shell: bash

- name: Install dependencies
shell: bash
run: |
# Workaround for patched peer variants
# e.g. ./patches/ for standard-openapi
# https://github.com/oven-sh/bun/issues/28147
if [ "$RUNNER_OS" = "Windows" ]; then
bun install --linker hoisted ${{ inputs.install-flags }}
else
if [ "$RUNNER_OS" != "Windows" ]; then
bun install ${{ inputs.install-flags }}
exit $?
fi
shell: bash

# On Windows, `bun install --linker hoisted` occasionally fails to apply
# a patchfile with "ENOTEMPTY: ... Directory not empty" while renaming the
# patched package into a cache dir (e.g. @ai-sdk/openai-compatible). This is
# a bun-Windows race with the dependency cache, not a code defect: the leftover
# half-written dir makes the rename collide on the next attempt. Retry by
# clearing the bun package cache first so the reinstall starts from a clean dir.
for attempt in 1 2 3; do
echo "bun install attempt $attempt (--linker hoisted)"
if bun install --linker hoisted ${{ inputs.install-flags }}; then
exit 0
fi
echo "bun install failed on attempt $attempt; clearing bun cache and retrying"
bun pm cache rm 2>/dev/null || rm -rf "$(bun pm cache)"
echo "cleared bun package cache"
done
echo "bun install failed after 3 attempts"
exit 1

- name: Save Bun dependencies
if: steps.bun-cache.outputs.cache-hit != 'true' && github.event_name != 'pull_request' && github.event_name != 'pull_request_target'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/nix-eval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: nix-eval

on:
push:
branches: [dev]
branches: [main, dev]
pull_request:
branches: [dev]
branches: [main, dev]
workflow_dispatch:

concurrency:
Expand All @@ -16,7 +16,7 @@ permissions:

jobs:
nix-eval:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-management.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
check-duplicates:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: typecheck

on:
push:
branches: [dev]
branches: [main, dev]
pull_request:
branches: [dev]
branches: [main, dev]
workflow_dispatch:

jobs:
typecheck:
runs-on: blacksmith-4vcpu-ubuntu-2404
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
Expand Down
32 changes: 32 additions & 0 deletions UPSTREAM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Upstream Tracking

This file records the relationship between this fork and the upstream OpenCode
repository, per the OC Kit integration plan (Phase 0: upstream freeze & audit).

## Upstream

- Repository: `https://github.com/anomalyco/opencode`
- License: MIT

## Fork status

- Local fork: `vibecoder880/opencode`
- Local `packages/opencode/package.json` version: `1.18.18`
- Upstream main has moved beyond this line (upstream exposes a `2.0` branch);
this fork is a snapshot of the `1.18.x` line and does NOT track upstream main.

## Divergence policy

- OC Kit is designed to extend OpenCode through existing extension points
(skills, agents, commands, plugins, config, tools) rather than invasive core
patches.
- We do not re-pin to upstream in Phase 0/1. Re-evaluate upstream sync when a
concrete merge target is agreed.
- Custom patches to core OpenCode files are documented inline at each patch
site and summarized in this file.

## Commit conventions

- Conventional commit style: `type(scope): summary`.
- Commit author email: `cavangcute478@gmail.com`.
- Verified via GitHub Actions CI (`test.yml`, `typecheck.yml`) on PRs into `main`.
9 changes: 8 additions & 1 deletion packages/core/src/ripgrep/binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ export namespace RipgrepBinary {

if (config.extension === "zip") {
const shell = (yield* Effect.sync(() => which("powershell.exe") ?? which("pwsh.exe"))) ?? "powershell.exe"
// `Expand-Archive` (PowerShell 5.1) hangs indefinitely on shared Windows
// CI runners while staging files (observed SIGTERM at 5/30/60s test
// timeouts). `[IO.Compression.ZipFile]::ExtractToDirectory` is the same
// .NET BCL the setup-bun action uses to extract a comparable zip in
// under 1s on the same runner. Key differences: Add-Type is unconditional
// (progress bars are off by default in -NonInteractive), and the
// destination is a scoped temp dir so no :Delete\:\*:\* flags are needed.
const result = yield* run(shell, [
"-NoProfile",
"-NonInteractive",
"-Command",
`$global:ProgressPreference = 'SilentlyContinue'; Expand-Archive -LiteralPath '${archive.replaceAll("'", "''")}' -DestinationPath '${dir.replaceAll("'", "''")}' -Force`,
`Add-Type -AssemblyName System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::ExtractToDirectory('${archive.replaceAll("'", "''")}', '${dir.replaceAll("'", "''")}')`,
])
if (result.code !== 0)
throw new Error(
Expand Down
20 changes: 20 additions & 0 deletions packages/core/src/v1/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ export const Info = Schema.Struct({
}),
}),
),
oc_kit: Schema.optional(
Schema.Struct({
enabled: Schema.optional(Schema.Boolean).annotate({ description: "Enable OC Kit" }),
default_kit: Schema.optional(Schema.String).annotate({ description: "Kit used by default" }),
default_mode: Schema.optional(Schema.Literals(["fast", "normal", "deep", "autonomous"])).annotate({
description: "Default OC Kit workflow mode",
}),
auto_workflow: Schema.optional(Schema.Boolean).annotate({
description: "Auto-select a workflow from a task description",
}),
auto_review: Schema.optional(Schema.Boolean).annotate({ description: "Review after implementation" }),
auto_test: Schema.optional(Schema.Boolean).annotate({ description: "Test after implementation" }),
checkpoint: Schema.optional(Schema.Boolean).annotate({
description: "Snapshot managed files before risky kit updates",
}),
telemetry: Schema.optional(Schema.Boolean).annotate({
description: "Send anonymous operational metrics (default: off)",
}),
}),
).annotate({ description: "OC Kit workflow/agent engineering layer configuration" }),
}).annotate({ identifier: "Config" })

export type Info = DeepMutable<Schema.Schema.Type<typeof Info>>
2 changes: 2 additions & 0 deletions packages/core/test/filesystem/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("Ripgrep", () => {
expect(result.map((item) => item.path)).toEqual([RelativePath.make("src/match.ts")])
}),
),
30_000, // bun per-test timeout (defaults to 5000); cold ripgrep binary install on Windows CI is slow
)

it.live("greps files with include filtering", () =>
Expand All @@ -40,5 +41,6 @@ describe("Ripgrep", () => {
expect(result[0]?.submatches[0]?.text).toBe("needle")
}),
),
30_000, // bun per-test timeout (defaults to 5000); cold ripgrep binary install on Windows CI is slow
)
})
6 changes: 6 additions & 0 deletions packages/core/test/repository-cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("RepositoryCache", () => {
expect(yield* read(path.join(localPath, "README.md"))).toBe("one\n")
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)

it.live("serializes concurrent materialization for the same checkout", () =>
Expand All @@ -46,6 +47,7 @@ describe("RepositoryCache", () => {
expect(results[0].localPath).toBe(results[1].localPath)
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)

it.live("replaces an existing checkout whose origin does not match", () =>
Expand All @@ -64,6 +66,7 @@ describe("RepositoryCache", () => {
expect(yield* exists(path.join(replaced.localPath, "stale.txt"))).toBe(false)
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)

it.live("keeps branch checkouts isolated from branchless refreshes", () =>
Expand All @@ -86,6 +89,7 @@ describe("RepositoryCache", () => {
expect(yield* read(path.join(cached.localPath, "README.md"))).toBe("two\n")
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)

it.live("does not mistake an enclosing repository for the cache checkout", () =>
Expand All @@ -99,6 +103,7 @@ describe("RepositoryCache", () => {
expect(yield* read(path.join(result.localPath, "README.md"))).toBe("one\n")
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)

it.live("returns typed validation and clone failures", () =>
Expand All @@ -119,6 +124,7 @@ describe("RepositoryCache", () => {
expect(cloneFailure).toBeInstanceOf(RepositoryCache.CloneFailedError)
}).pipe(Effect.provide(cacheLayer(fixture.root))),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on CI
)
})

Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/ripgrep.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("Ripgrep", () => {
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
60_000, // bun per-test timeout (defaults to 5000); cold ripgrep binary download + Expand-Archive on Windows CI can exceed 30s
)

it.live("never includes git metadata", () =>
Expand Down Expand Up @@ -61,6 +62,7 @@ describe("Ripgrep", () => {
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
60_000, // bun per-test timeout (defaults to 5000); cold ripgrep binary download + Expand-Archive on Windows CI can exceed 30s
)
it.live("does not split surrogate pairs in oversized line previews", () =>
Effect.acquireUseRelease(
Expand All @@ -81,5 +83,6 @@ describe("Ripgrep", () => {
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
60_000, // bun per-test timeout (defaults to 5000); cold ripgrep binary download + Expand-Archive on Windows CI can exceed 30s
)
})
1 change: 1 addition & 0 deletions packages/core/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe("Snapshot", () => {
}),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
),
30_000, // bun per-test timeout (defaults to 5000); real git subprocesses need headroom on Windows CI
)

testEffect(Layer.empty).live("treats capture outside Git as unavailable", () =>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/util/effect-flock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ describe("util.effect-flock", () => {
const proc = spawnWorker({ key: "eflock:crash", dir, ready, holdMs: 120_000 })

try {
await waitForFile(ready, 5_000)
await waitForFile(ready, 15_000)
await stopWorker(proc)

// Backdate lock files so they're past STALE_MS (60s)
Expand Down
72 changes: 72 additions & 0 deletions packages/opencode/src/ockit/checkpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// OC Kit checkpoints: a snapshot of managed files taken before a
// risky operation (kit install/update/rollback). Each checkpoint records the
// kit version, operation, timestamp, and per-file sha256 so the operation can
// be rolled back to a known-good state.

import { Effect, Schema } from "effect"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Hash } from "@opencode-ai/core/util/hash"
import { Checkpoint } from "./types"

/** Default directory where checkpoint snapshots are stored. */
export const CHECKPOINT_DIR = ".oc/state/checkpoints"

export class CheckpointError extends Schema.TaggedErrorClass<CheckpointError>()("OCKitCheckpointError", {
path: Schema.String,
message: Schema.optional(Schema.String),
}) {
override get message(): string {
return `OC Kit checkpoint: ${this.path}${this.message ? ` — ${this.message}` : ""}`
}
}

/** Write a checkpoint file for the given operation + managed files. */
export const create = Effect.fn("OCKit.checkpoint.create")(function* (input: {
root: string
kit: string
kitVersion: string
operation: string
session?: string
workflow?: string
files: Record<string, string>
}) {
const fs = yield* FSUtil.Service
const id = `${Date.now()}-${input.kit}-${input.operation}`
const checkpoint: Checkpoint = {
kit: input.kit,
kit_version: input.kitVersion,
operation: input.operation,
timestamp: new Date().toISOString(),
session: input.session,
workflow: input.workflow,
files: Object.fromEntries(Object.entries(input.files).map(([file, content]) => [file, Hash.sha256(content)])),
}
const path = `${input.root}/${CHECKPOINT_DIR}/${id}.json`
yield* fs.writeWithDirs(path, JSON.stringify(checkpoint, null, 2))
return path
})

/** List checkpoint ids for a kit/operation, newest first. */
export const list = Effect.fn("OCKit.checkpoint.list")(function* (root: string, kit?: string) {
const fs = yield* FSUtil.Service
const dir = `${root}/${CHECKPOINT_DIR}`
if (!(yield* fs.isDir(dir))) return [] as string[]
const entries = yield* fs.readDirectoryEntries(dir)
const files = entries.filter((entry) => entry.type === "file" && entry.name.endsWith(".json"))
const ids = files.map((entry) => entry.name.replace(/\.json$/, ""))
return kit ? ids.filter((id) => id.includes(`-${kit}-`)).toReversed() : ids.toReversed()
Comment on lines +54 to +57
})

/** Read a single checkpoint by id. */
export const read = Effect.fn("OCKit.checkpoint.read")(function* (root: string, id: string) {
const fs = yield* FSUtil.Service
const path = `${root}/${CHECKPOINT_DIR}/${id}.json`
const raw = yield* fs.readFileStringSafe(path)
if (raw === undefined) return yield* new CheckpointError({ path, message: `No checkpoint "${id}"` })
const decoded = yield* Schema.decodeUnknownEffect(Checkpoint)(JSON.parse(raw)).pipe(
Effect.mapError((err) => new CheckpointError({ path, message: String(err) })),
)
return decoded
})

export * as Checkpoint from "./checkpoint"
37 changes: 37 additions & 0 deletions packages/opencode/src/ockit/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// OC Kit config access. The `oc_kit` section lives in opencode.json under
// ConfigV1.Info (schema in packages/core/src/v1/config/config.ts). This module
// exposes typed accessors so OC Kit runtime code reads its settings through the
// existing Config service instead of a parallel config system.

import { Effect, Option, Schema } from "effect"
import { Config } from "@/config/config"
import { OCKitConfig, type OCKitConfig as OCKitConfigType } from "./types"

export const defaults: OCKitConfigType = {
enabled: true,
default_kit: "engineer",
default_mode: "normal",
auto_workflow: true,
auto_review: true,
auto_test: true,
checkpoint: true,
telemetry: false,
}

/** Read the effective OC Kit config, applying defaults over the user's values. */
export const read = Effect.fn("OCKit.config")(function* () {
const config = yield* Config.Service
const cfg = yield* config.get()
const user = cfg.oc_kit ?? {}
return { ...defaults, ...user }
})

/** True when OC Kit is enabled in the current project config. */
export const enabled = Effect.fn("OCKit.config.enabled")(function* () {
return (yield* read()).enabled === true
})

/** Validate a raw `oc_kit` value structurally (used when parsing config). */
export function validate(input: unknown): OCKitConfigType | undefined {
return Option.getOrUndefined(Schema.decodeUnknownOption(OCKitConfig)(input))
}
Loading
Loading