Skip to content

Commit 8a9c3b6

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feat/workflows
2 parents dcb3901 + a136caa commit 8a9c3b6

1,126 files changed

Lines changed: 93207 additions & 25731 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitattributes‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages/core/migration/**/snapshot.json linguist-generated
2+
packages/core/src/database/migration.gen.ts linguist-generated

‎.github/workflows/publish.yml‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
id: build
9191
run: |
9292
./packages/opencode/script/build.ts ${{ (github.ref_name == 'beta' && '--sourcemaps') || '' }}
93+
./packages/cli/script/build.ts ${{ (github.ref_name == 'beta' && '--sourcemaps') || '' }}
9394
env:
9495
OPENCODE_VERSION: ${{ needs.version.outputs.version }}
9596
OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
@@ -107,6 +108,12 @@ jobs:
107108
with:
108109
name: opencode-cli-windows
109110
path: packages/opencode/dist/opencode-windows*
111+
112+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
113+
with:
114+
name: opencode-preview-cli
115+
path: packages/cli/dist/cli-*
116+
110117
outputs:
111118
version: ${{ needs.version.outputs.version }}
112119

@@ -446,6 +453,11 @@ jobs:
446453
name: opencode-cli-signed-windows
447454
path: packages/opencode/dist
448455

456+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
457+
with:
458+
name: opencode-preview-cli
459+
path: packages/cli/dist
460+
449461
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
450462
if: needs.version.outputs.release
451463
with:

‎.github/workflows/sync-zed-extension.yml‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ jobs:
6464
turbo-${{ runner.os }}-
6565
6666
- name: Run unit tests
67-
run: bun turbo test:ci
67+
timeout-minutes: 20
68+
run: bun turbo test:ci --log-order=stream --log-prefix=task
6869
env:
6970
OPENCODE_EXPERIMENTAL_DISABLE_FILEWATCHER: ${{ runner.os == 'Windows' && 'true' || 'false' }}
7071

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ ts-dist
1515
.turbo
1616
**/.serena
1717
.serena/
18+
**/.omo
19+
.omo/
1820
/result
1921
refs
2022
Session.vim

‎.opencode/command/translate.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: translate English to other languages
3-
model: opencode/claude-opus-4-7
3+
model: opencode/claude-opus-4-8
44
---
55

66
run git diff and translate changed english doc and UI copy files to other international languages. Translate all languages in parallel to save time.

‎AGENTS.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const { a, b } = obj
5252
- Never alias imports. Do not use `import { foo as bar } from "..."` or renamed imports like `resolve as pathResolve`.
5353
- Never use star imports. Do not use `import * as Foo from "..."` or `import type * as Foo from "..."`.
5454
- If a namespace-style value is needed, import the module's own exported namespace by name, for example `import { Project } from "@opencode-ai/core/project"`, then reference `Project.ID`.
55+
- Prefer dynamic imports for heavy modules that are only needed in selected code paths, especially in startup-sensitive entrypoints. Destructure dynamic import bindings near the top of the narrowest scope that needs them so they read like normal imports. Avoid inline chains such as `await import("./module").then((mod) => mod.value())` or `(await import("./module")).value()`. Keep branch-specific imports inside the branch that needs them to preserve lazy loading.
5556

5657
### Variables
5758

@@ -137,3 +138,14 @@ const table = sqliteTable("session", {
137138
## Type Checking
138139

139140
- Always run `bun typecheck` from package directories (e.g., `packages/opencode`), never `tsc` directly.
141+
142+
## V2 Session Core
143+
144+
- Keep durable prompt admission separate from model execution. `SessionV2.prompt(...)` admits one durable `session_input` row before scheduling advisory `SessionExecution.wake(sessionID)` unless `resume: false` requests admit-only behavior. The serialized runner promotes admitted inputs into visible user messages at safe boundaries.
145+
- Reusing a Session ID adopts the existing Session. Reusing a prompt message ID reconciles an exact retry only when Session, prompt, and delivery mode match; conflicting reuse fails. Historical projected prompts lazily synthesize promoted inbox records during exact retry.
146+
- Keep `SessionExecution` process-global and Session-ID based. It discovers placement through the read-side `SessionStore` and `LocationServiceMap.get(session.location)`; no layer should take a Session ID.
147+
- Keep `SessionRunner`, model resolution, tool registry, permissions, and filesystem Location-scoped. Omitted `Location.workspaceID` means implicit-local placement; explicit workspace identity remains reserved for future placement semantics.
148+
- Preserve one explicit `llm.stream(request)` call per provider turn and reload projected history before durable continuation. Do not bridge through legacy `SessionPrompt.loop(...)` or delegate orchestration to an in-memory tool loop.
149+
- Keep local Session drains process-local until clustering is implemented. `SessionRunCoordinator` joins explicit same-Session resumes, coalesces prompt wakeups, and allows different Sessions to run concurrently. Advisory wakes drain eligible durable inbox rows only; post-crash activity recovery requires a separate explicit design before it may retry provider work.
150+
- Keep delivery vocabulary explicit. Prompts steer by default and coalesce into the active activity at the next safe provider-turn boundary. Explicit `queue` inputs open FIFO future activities one at a time after the active activity settles.
151+
- Keep EventV2 replay owner claims separate from clustered Session execution ownership.

‎CONTEXT.md‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# OpenCode Session Runtime
2+
3+
OpenCode sessions preserve durable conversational history while assembling the runtime context an agent needs to act correctly in its current environment.
4+
5+
## Language
6+
7+
**System Context**:
8+
The structured collection of contextual facts presented to the model as initial instructions and chronological updates.
9+
_Avoid_: System prompt
10+
11+
**Context Source**:
12+
One independently observed typed value within the **System Context**, represented by a stable key, JSON codec, infallible loader, pure baseline/update renderers, and an optional removal renderer for dynamic sources.
13+
_Avoid_: Prompt fragment
14+
15+
**System Context Registry**:
16+
The Location-scoped registry of ordered, scoped producers that contribute to the current **System Context**.
17+
18+
**Mid-Conversation System Message**:
19+
A durable chronological instruction that tells the model the newly effective state of a changed **Context Source**.
20+
_Avoid_: System update, system notification, raw text diff
21+
22+
**Context Epoch**:
23+
The span during which one initially rendered **System Context** remains immutable, ending at compaction or another baseline-replacing transition.
24+
25+
**Baseline System Context**:
26+
The full **System Context** rendered at the start of a **Context Epoch**.
27+
_Avoid_: Live system prompt
28+
29+
**Context Snapshot**:
30+
The overwriteable model-hidden JSON state used to compare each **Context Source** with the value last admitted to a provider turn.
31+
32+
**Unavailable Context**:
33+
An expected temporary inability to observe a **Context Source** value; the runtime retains its prior effective state and emits no update, or omits it until first successfully loaded.
34+
35+
**Safe Provider-Turn Boundary**:
36+
The point immediately before a provider call, after durable input promotion and any required tool settlement, where context changes may be admitted chronologically.
37+
38+
## Relationships
39+
40+
- A **System Context** is an opaque carrier composed from zero or more **Context Sources**.
41+
- The **System Context Registry** uses stable-keyed scoped contributions to assemble the current **System Context**; contributor removal naturally removes its sources at the next **Safe Provider-Turn Boundary**.
42+
- A changed **Context Source** may produce one **Mid-Conversation System Message** containing its newly effective state.
43+
- A **Mid-Conversation System Message** persists the exact combined rendered text sent to the model.
44+
- The current **Context Snapshot** advances atomically with the corresponding durable **Mid-Conversation System Message**.
45+
- A **Context Snapshot** stores one codec-encoded JSON value and, for removable dynamic sources, a pre-rendered removal message per stable **Context Source** key.
46+
- Changes from multiple **Context Sources** admitted at one safe boundary combine into one **Mid-Conversation System Message**.
47+
- Context changes are sampled and admitted lazily at a **Safe Provider-Turn Boundary**, never pushed asynchronously when their source changes.
48+
- At a **Safe Provider-Turn Boundary**, newly promoted user input or settled tool results precede any combined **Mid-Conversation System Message**.
49+
- The first provider turn renders the latest complete **Baseline System Context** and initializes its **Context Snapshot** without emitting a redundant **Mid-Conversation System Message**; unavailable initial context blocks the turn instead of persisting an incomplete baseline.
50+
- Initial **System Context** preparation precedes the first durable input promotion so an unavailable baseline leaves that input pending and retryable; ordinary reconciliation remains after promotion.
51+
- Compaction starts a new **Context Epoch** with a freshly rendered **Baseline System Context** and **Context Snapshot**; prior **Mid-Conversation System Messages** remain durable audit history but leave projected model history.
52+
- A newly registered core or plugin-defined **Context Source** absent from the current snapshot emits its baseline rendering once at the next **Safe Provider-Turn Boundary**.
53+
- **Context Source** keys are stable and namespaced; duplicate keys fail composition. `SystemContext.combine(...)` preserves caller order; the **System Context Registry** evaluates producers concurrently and combines them in stable contribution-key order so rendered context remains deterministic.
54+
- Each **Context Source** loader returns one coherent typed value. `SystemContext.make(...)` hides that value type so differently typed sources compose uniformly. Its codec compares and stores that value; its pure renderers produce model-visible baseline, update, and removal text only when needed.
55+
- `SystemContext.initialize(...)` observes a composed **System Context** once and produces a fresh **Baseline System Context** with its **Context Snapshot**.
56+
- `SystemContext.reconcile(...)` observes a composed **System Context** once and returns exactly one next action: unchanged, updated, replacement ready, or replacement blocked.
57+
- `SystemContext.replace(...)` represents an explicit baseline-replacing transition such as compaction or model/provider switch; it either produces a fresh generation or reports that replacement is blocked by unavailable admitted context.
58+
- Context Epoch preparation retries until stable after optimistic revision mismatches so concurrent replacement requests cannot terminate an otherwise valid safe-boundary run.
59+
- **Unavailable Context** uses stale-while-revalidate semantics and is distinct from a successfully loaded absence, which may emit removal text.
60+
- Ordinary **Context Source** loaders return values directly; loaders that intentionally use stale-while-revalidate may explicitly return **Unavailable Context**.
61+
- Nested project instruction discovery after successful reads remains a follow-up; when implemented, discovered instructions must be admitted durably at the next **Safe Provider-Turn Boundary**.
62+
- Location-scoped services naturally re-resolve effective context when a moved session next runs in its destination location.
63+
- Moving a Session clears its active **Context Epoch**, so the destination must initialize a complete baseline before another prompt can promote.
64+
- Context Epoch initialization is fenced against the authoritative Session Location, so an old-Location runner cannot recreate source context after a concurrent move.
65+
- Instruction discovery, source identity, persistence, and file loading belong to the instruction service; the **System Context** abstraction only composes effectful producers and renders loaded values.
66+
- The first instruction-service slice observes global and upward project `AGENTS.md` files as one ordered aggregate **Context Source** at each **Safe Provider-Turn Boundary**.
67+
- Built-in and instruction context producers register through the **System Context Registry** with stable contribution keys. Plugin-defined context registration and hot-reload lifecycle remain a follow-up built on the same scoped registry seam.
68+
- Context source changes never wake idle sessions; the next naturally scheduled **Safe Provider-Turn Boundary** loads and compares current values lazily.
69+
- Once admitted, a **Mid-Conversation System Message** remains durable even if the following provider attempt fails and is replayed unchanged on retry.
70+
- **Mid-Conversation System Messages** remain durable Session-message history; normal user-facing transcript surfaces may hide them.
71+
- The date **Context Source** initially preserves host-local calendar-date behavior; a configured user timezone may replace that default later.
72+
- A **Context Epoch** begins with one immutable **Baseline System Context**.
73+
- A **Baseline System Context** is stored durably and reused verbatim across process restarts within its **Context Epoch**.
74+
- A **Baseline System Context** durably preserves the exact joined text used for the active provider-cache prefix.
75+
- Compaction or a model/provider switch starts a new **Context Epoch** because the baseline can be replaced without preserving the prior provider cache.
76+
- A model/provider switch always starts a new **Context Epoch** while preserving chronological conversation history.
77+
- A **Mid-Conversation System Message** lowers to the provider's native chronological instruction role when supported and to a wrapped chronological fallback otherwise.
78+
- When the effective aggregate instruction set changes, its **Mid-Conversation System Message** includes the complete current ordered set and supersedes the prior aggregate value; when no ambient instructions remain, the message states that previously loaded instructions no longer apply.
79+
- Ambient project instruction discovery honors `OPENCODE_DISABLE_PROJECT_CONFIG`; global instructions remain eligible.
80+
81+
## Example dialogue
82+
83+
> **Dev:** "The date changed while the session was active. Should the **Mid-Conversation System Message** say what the old date was?"
84+
> **Domain expert:** "No. Emit the newly effective date so the agent can act on the current **System Context**."
85+
86+
## Flagged ambiguities
87+
88+
- Legacy `experimental.chat.system.transform` can mutate the assembled baseline system prompt arbitrarily, but V2 plugins do not yet expose an equivalent hook. Decide separately whether to port it, replace dynamic uses with plugin-defined **Context Sources**, or narrow its semantics.

0 commit comments

Comments
 (0)