Skip to content

Commit 7582b1d

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents 39321db + 66ba73a commit 7582b1d

794 files changed

Lines changed: 28695 additions & 21217 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.

‎.opencode/skills/app-e2e-tests/SKILL.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: app-e2e-tests
3-
description: Use when writing, changing, reviewing, or debugging Playwright e2e tests in packages/app/e2e (regression keepers and user stories). Covers the mocked opencode server harness and the Bun static server, per-test isolation, page-load and route cost, the suite-wide service-worker block, races with first mount, hover, measurement, clock, dialogs and shortcuts, projects, shards and worker scheduling, rehearsing Windows timing locally, and diagnosing a CI flake from its artifacts. Not for component tests (stories mounted on packages/stories) or e2e/performance benchmarks.
3+
description: Use when writing, changing, reviewing, or debugging Playwright e2e tests in packages/app/e2e (regression keepers and user stories). Covers the mocked opencode server harness and the Bun static server, per-test isolation, page-load and route cost, the suite-wide service-worker block, races with first mount, hover, measurement, clock, dialogs and shortcuts, projects, shards and worker scheduling, rehearsing Windows timing locally, and diagnosing a CI flake from its artifacts. Not for component tests (stories mounted on packages/stories) or the strobe benchmarks in packages/app/perf.
44
---
55

66
# App e2e tests
@@ -12,7 +12,7 @@ All paths below are relative to `packages/app` unless they start with `packages/
1212
## What a test runs against
1313

1414
- **No opencode backend.** Each shard leg runs `bun --cwd packages/app test:e2e:built --shard=<n>/2` (`check-test.yml:287-292`). It builds once and starts one Bun static server, `e2e/utils/serve.ts`, on `127.0.0.1:${PLAYWRIGHT_PORT ?? 3000}`. All 5 workers share it (`playwright.config.ts:23-27`).
15-
- `serve.ts` keeps vite preview's SPA fallback rules. Do not move built e2e back to vite preview. On case-insensitive file systems it synchronously reads the whole `dist/_assets` directory (about 3,100 files) for every asset request, so every worker's page loads wait in line. The `e2e/performance` configs still use it to keep their baselines comparable.
15+
- `serve.ts` keeps vite preview's SPA fallback rules. Do not move built e2e back to vite preview. On case-insensitive file systems it synchronously reads the whole `dist/_assets` directory (about 3,100 files) for every asset request, so every worker's page loads wait in line.
1616
- **The API is an in-memory mock per page,** running in the test worker. `mockOpenCodeServer` (`e2e/utils/mock-server.ts:202`):
1717
- answers `page.route("**/api/**")` with an Effect HttpApi handler;
1818
- fakes `/api/event` SSE with an init-script `fetch` override;
@@ -54,7 +54,7 @@ All paths below are relative to `packages/app` unless they start with `packages/
5454
- **Real-time waits cost their full length on every run and retry** (`settings-wsl.spec.ts:268-276` waits out a 10 s health check). Prefer `page.clock`:
5555
- install it before the `goto` or `reload` whose timers you need (`timeline-stream.spec.ts:1700`);
5656
- keep fast-forwards under the client's 45 s event-stream idle timeout (`packages/client/src/solid/connection.ts:35`).
57-
- **Leave benchmark pacing out of regression tests.** The `sendAll` delays and `messageDelay` exist for benchmarks (`timeline.ts:306`, `mock-server.ts:82`). Hold message pages with `beforeMessagesResponse` instead.
57+
- **Leave pacing out of regression tests.** The `sendAll` delays (`timeline.ts:326`) pace workloads; tests wait for the resulting UI state. Hold message pages with `beforeMessagesResponse` instead.
5858

5959
## Wait for state, not time: races CI found
6060

@@ -118,7 +118,7 @@ Run from `packages/app`:
118118
- [ ] Check the cost on a noisy machine. Other agents add load, and local A/Bs at a load average of 20-35 were inconclusive.
119119
- Compare the medians of interleaved before/after runs at `--workers=5`, or the step durations in the report (`bun run test:e2e:report`).
120120
- Count every `goto` and `reload` you added.
121-
- [ ] `bun run typecheck:e2e` reports 4 existing errors: `timeline-stream.spec.ts:1822`, `:1825`, and two `e2e/performance` probes. Add none. If you changed `playwright.config.ts`, update `test-browser/playwright-config.test.ts`.
121+
- [ ] `bun run typecheck:e2e` reports 2 existing errors: `timeline-stream.spec.ts:1822` and `:1825`. Add none. If you changed `playwright.config.ts`, update `test-browser/playwright-config.test.ts`.
122122

123123
## When CI flakes
124124

‎bun.lock‎

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bunfig.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
exact = true
33
# Only install newly resolved package versions published at least 3 days ago.
44
minimumReleaseAge = 259200
5-
minimumReleaseAgeExcludes = ["@ai-sdk/amazon-bedrock", "@ai-sdk/anthropic", "@brendonovich/vite-plugin-opencode", "@kitlangton/knobs", "@kitlangton/solid-motion", "@opencode/sdk", "@opencode/pty", "@opencode/pty-darwin-arm64", "@opencode/pty-darwin-x64", "@opencode/pty-linux-arm64-gnu", "@opencode/pty-linux-arm64-musl", "@opencode/pty-linux-x64-gnu", "@opencode/pty-linux-x64-musl", "@opencode/pty-win32-arm64", "@opencode/pty-win32-x64", "@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-arm64-musl", "@opentui/core-linux-x64", "@opentui/core-linux-x64-musl", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "@opentunnel/client", "@opentunnel/protocol", "gitlab-ai-provider", "opencode-gitlab-auth", "@ff-labs/fff-node", "@ff-labs/fff-bun", "@ff-labs/fff-bin-darwin-arm64", "@ff-labs/fff-bin-darwin-x64", "@ff-labs/fff-bin-linux-arm64-gnu", "@ff-labs/fff-bin-linux-arm64-musl", "@ff-labs/fff-bin-linux-x64-gnu", "@ff-labs/fff-bin-linux-x64-musl", "@ff-labs/fff-bin-win32-arm64", "@ff-labs/fff-bin-win32-x64", "@pierre/diffs", "@pierre/highlights", "@pierre/theming", "app-builder-lib", "dmg-builder", "electron", "electron-builder", "electron-publish", "blume", "pele", "bun-types", "typescript@7.1.0-beta"]
5+
minimumReleaseAgeExcludes = ["@ai-sdk/amazon-bedrock", "@ai-sdk/anthropic", "@brendonovich/vite-plugin-opencode", "@hona/strobe", "@hona/strobe-darwin-arm64", "@hona/strobe-darwin-x64", "@hona/strobe-linux-arm64", "@hona/strobe-linux-x64", "@hona/strobe-win32-x64", "@kitlangton/knobs", "@kitlangton/solid-motion", "@opencode/sdk", "@opencode/pty", "@opencode/pty-darwin-arm64", "@opencode/pty-darwin-x64", "@opencode/pty-linux-arm64-gnu", "@opencode/pty-linux-arm64-musl", "@opencode/pty-linux-x64-gnu", "@opencode/pty-linux-x64-musl", "@opencode/pty-win32-arm64", "@opencode/pty-win32-x64", "@opentui/core", "@opentui/core-darwin-arm64", "@opentui/core-darwin-x64", "@opentui/core-linux-arm64", "@opentui/core-linux-arm64-musl", "@opentui/core-linux-x64", "@opentui/core-linux-x64-musl", "@opentui/core-win32-arm64", "@opentui/core-win32-x64", "@opentui/keymap", "@opentui/solid", "@opentunnel/client", "@opentunnel/protocol", "gitlab-ai-provider", "opencode-gitlab-auth", "@ff-labs/fff-node", "@ff-labs/fff-bun", "@ff-labs/fff-bin-darwin-arm64", "@ff-labs/fff-bin-darwin-x64", "@ff-labs/fff-bin-linux-arm64-gnu", "@ff-labs/fff-bin-linux-arm64-musl", "@ff-labs/fff-bin-linux-x64-gnu", "@ff-labs/fff-bin-linux-x64-musl", "@ff-labs/fff-bin-win32-arm64", "@ff-labs/fff-bin-win32-x64", "@pierre/diffs", "@pierre/highlights", "@pierre/theming", "app-builder-lib", "dmg-builder", "electron", "electron-builder", "electron-publish", "blume", "pele", "bun-types", "typescript@7.1.0-beta"]
66

77
[test]
88
root = "./do-not-run-tests-from-root"

‎infra/stage.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const domain = (() => {
66

77
export const zoneID = "430ba34c138cfb5360826c4909f99be8"
88
export const awsStage = $app.stage === "production" ? "production" : "dev"
9-
export const deployAws = $app.stage === awsStage
9+
export const deployStats = $app.stage === awsStage
1010

1111
if ($app.stage === "production") {
1212
new cloudflare.DnsRecord("TrustCenter", {

‎infra/stats.ts‎

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { EMAILOCTOPUS_API_KEY } from "./app"
22
import { domain } from "./stage"
33

4-
// Keep the deployed names and arguments: the R2 stats sync still uses this VPC
5-
// and cluster after the legacy lake is removed.
6-
const lakeVpc = new sst.aws.Vpc("LakeVpc")
7-
const lakeCluster = new sst.aws.Cluster("LakeCluster", { vpc: lakeVpc })
8-
94
////////////////
105
// DATABASE
116
////////////////
@@ -101,25 +96,46 @@ const r2Sql = new sst.Linkable("R2Sql", {
10196
},
10297
})
10398

104-
export const statSync = new sst.aws.Service("StatsSyncService", {
105-
cluster: lakeCluster,
106-
architecture: "arm64",
107-
cpu: "0.25 vCPU",
108-
// 0.5 GB caused an OOM crash loop: every restart immediately re-ran the 4 Athena
109-
// stats queries (~$5/pass) every ~5 minutes instead of hourly.
110-
memory: "2 GB",
111-
image: {
112-
context: ".",
113-
dockerfile: "packages/stats/server/Dockerfile",
114-
},
115-
command: ["bun", "src/stat-sync.ts"],
99+
// One instance per run: a plan step, then one step per stat period and retention
100+
// cohort. See packages/stats/README.md for triggering a run by hand.
101+
export const statsSyncWorkflow = new sst.cloudflare.Workflow("StatsSyncWorkflow", {
102+
handler: "packages/stats/server/src/workflow.ts",
103+
className: "StatsSyncWorkflow",
116104
link: [database, r2Sql, r2SqlAuthToken, statsHiddenModels, statsSyncConfig],
117-
scaling: {
118-
min: 1,
119-
max: 1,
105+
transform: {
106+
worker: {
107+
transform: {
108+
worker: (args) => {
109+
// Raise CPU time from the 30-second default to the 5-minute maximum for
110+
// ranking a full week of geo rows.
111+
args.limits = { cpuMs: 300_000 }
112+
args.observability = { enabled: true }
113+
},
114+
},
115+
},
120116
},
117+
})
118+
119+
// Schedules must match packages/stats/server/src/schedule.ts, which maps the
120+
// daily one to a history run.
121+
if (!$dev)
122+
new sst.cloudflare.Cron("StatsSyncCron", {
123+
schedules: ["5 * * * *", "20 3 * * *"],
124+
worker: {
125+
handler: "packages/stats/server/src/cron.ts",
126+
link: [statsSyncWorkflow],
127+
transform: {
128+
worker: (args) => {
129+
args.observability = { enabled: true }
130+
},
131+
},
132+
},
133+
})
134+
135+
new sst.x.DevCommand("StatsSync", {
136+
link: [database, r2Sql, r2SqlAuthToken, statsHiddenModels, statsSyncConfig],
121137
dev: {
122-
command: "bun src/stat-sync.ts",
138+
command: "bun src/sync.ts",
123139
directory: "packages/stats/server",
124140
autostart: false,
125141
},

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"dev:console": "ulimit -n 10240 2>/dev/null; bun run --cwd packages/console/app dev",
1717
"dev:stats": "bun sst shell --stage=production -- bun run --cwd packages/stats/app dev",
1818
"dev:www": "bun run --cwd services/www dev",
19-
"bench:devex": "bun run --cwd packages/app test:bench:devex",
2019
"lint": "oxlint && ast-grep scan -c script/ast-grep/gui-plugins/sgconfig.yml && bun script/sdk-docs.ts",
2120
"lint:changed": "bun script/lint-changed.ts",
2221
"lint:effect-patterns": "ast-grep scan -c script/ast-grep/sgconfig.yml packages/util/src packages/core/src packages/server/src packages/protocol/src packages/cli/src",
@@ -52,6 +51,7 @@
5251
"@effect/sql-sqlite-node": "4.1.0",
5352
"@npmcli/arborist": "9.4.0",
5453
"@types/bun": "1.4.3",
54+
"@hona/strobe": "0.6.0",
5555
"@types/cross-spawn": "6.0.6",
5656
"@octokit/rest": "22.0.0",
5757
"@opentui/core": "0.8.1",
@@ -114,6 +114,7 @@
114114
},
115115
"devDependencies": {
116116
"@ast-grep/cli": "0.44.0",
117+
"@hona/strobe": "catalog:",
117118
"@opencode/client": "workspace:*",
118119
"@oxlint/plugins": "1.60.0",
119120
"@tsconfig/bun": "catalog:",

‎packages/ai/README.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,20 @@ edits endpoint, so input images go to `/images/generations` as `input_references
744744
asset into owned bytes before the provider URL expires. Construct assets with `Media.bytes`, `Media.base64`,
745745
`Media.url`, `Media.ref(provider, id)`, `Media.fromDataUrl`, or `Media.file(path)`.
746746

747+
File inputs (message `media` parts, image `images`, decision `media` parts) also take plain data: a `Uint8Array`,
748+
`ArrayBuffer`, `URL`, or a string holding a data URL, an http(s) URL or base64. Bytes and base64 are sniffed from
749+
magic bytes; pass `mediaType` when that fails:
750+
751+
```ts
752+
ai.request({
753+
model,
754+
prompt: [
755+
{ type: "text", text: "Summarize this report" },
756+
{ type: "media", media: pdfBase64, mediaType: "application/pdf" },
757+
],
758+
})
759+
```
760+
747761
Pass ordered image inputs to the same method for editing, composition, or image-conditioned generation:
748762

749763
```ts
@@ -765,8 +779,8 @@ const composed = Effect.gen(function* () {
765779

766780
`Media.ref(provider, id)` represents provider file handles such as OpenAI file IDs or Gemini Files URIs; routes
767781
only forward refs that belong to their own provider (OpenAI, xAI, and Gemini images accept them). No shipped route
768-
returns a ref yet, and `asset.bytes()` / `materialize()` on a ref fail by design. Raw strings are not accepted as
769-
image inputs, avoiding ambiguity between base64, URLs, and provider IDs. Empty or omitted `images` uses text-to-image generation; a
782+
returns a ref yet, and `asset.bytes()` / `materialize()` on a ref fail by design. Empty or omitted `images` uses
783+
text-to-image generation; a
770784
non-empty array selects the provider's edit behavior (see the table above for routes that limit the count). OpenAI
771785
uses multipart for byte/data-URL edits and its JSON reference body for URL or file-ID edits. Inpainting is a
772786
provider option on the routes that support it (OpenAI):

‎packages/ai/example/tutorial.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const FakeProtocol = Protocol.make<FakeBody, string, string, void>({
184184
Effect.succeed({
185185
model: request.model.id,
186186
input: request.messages
187-
.flatMap((message) => message.content)
187+
.flatMap((message) => [...message.content])
188188
.filter((part) => part.type === "text")
189189
.map((part) => part.text)
190190
.join("\n"),

‎packages/ai/src/cache-policy.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
// Manual `cache: CacheHint` placements on individual parts are preserved and
1212
// count against the four-breakpoint budget; auto only fills remaining slots.
1313
import { CacheHint, type CachePolicy, type CachePolicyObject, type CacheTTL } from "./schema/options.js"
14-
import { type LLMRequest, Message, ToolDefinition, type ContentPart, type ToolEntry } from "./schema/messages.js"
14+
import {
15+
AssistantMessage,
16+
type LLMRequest,
17+
type Message,
18+
SystemMessage,
19+
ToolDefinition,
20+
ToolMessage,
21+
UserMessage,
22+
type ContentPart,
23+
type ToolEntry,
24+
} from "./schema/messages.js"
1525
import { effortUpdate } from "./effort-updates.js"
1626

1727
const AUTO: CachePolicyObject = {
@@ -141,8 +151,7 @@ const markMessageAt = (
141151
const existing = target.content[markAt]
142152
if (!existing || !isCacheablePart(existing) || existing.cache || budget.remaining === 0) return messages
143153
budget.remaining -= 1
144-
const nextContent = target.content.map((part, i) => (i === markAt ? { ...existing, cache: hint } : part))
145-
const next = new Message({ ...target, content: nextContent })
154+
const next = cachePartAt(target, markAt, hint)
146155
// Single pass over `messages`, substituting the one updated entry. Long
147156
// conversations call this on every request, so avoid `.map()` here — its
148157
// closure dispatch and identity copies show up in profiling.
@@ -151,6 +160,22 @@ const markMessageAt = (
151160
return result
152161
}
153162

163+
const cachePartAt = (message: Message, index: number, hint: CacheHint): Message => {
164+
switch (message.role) {
165+
case "system":
166+
return new SystemMessage({ ...message, content: cacheContentAt(message.content, index, hint) })
167+
case "user":
168+
return new UserMessage({ ...message, content: cacheContentAt(message.content, index, hint) })
169+
case "assistant":
170+
return new AssistantMessage({ ...message, content: cacheContentAt(message.content, index, hint) })
171+
case "tool":
172+
return new ToolMessage({ ...message, content: cacheContentAt(message.content, index, hint) })
173+
}
174+
}
175+
176+
const cacheContentAt = <Part extends ContentPart>(content: ReadonlyArray<Part>, index: number, hint: CacheHint) =>
177+
content.map((part, i) => (i === index ? { ...part, cache: hint } : part))
178+
154179
const markMessages = (
155180
messages: ReadonlyArray<Message>,
156181
strategy: NonNullable<CachePolicyObject["messages"]>,

0 commit comments

Comments
 (0)