Skip to content

W4: @opencomputer/flue CF-native scaffolding - #490

Merged
ZIJ merged 3 commits into
flue-nativefrom
flue-native-w4
Jul 7, 2026
Merged

W4: @opencomputer/flue CF-native scaffolding#490
ZIJ merged 3 commits into
flue-nativefrom
flue-native-w4

Conversation

@ZIJ

@ZIJ ZIJ commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

W4 (Scaffolding) — the package that makes a stock Flue app OpenComputer-native, into the flue-native evergreen (#489). Draft; never merge (Igor).

What's here (sdks/flue, @opencomputer/flue 0.2.0)

Replaces the serveOC/brain-box shape with the CF-native shape (design 013 §4/§5):

  • useOcGateway(ctx) + DEFAULT_MODEL (claude-haiku-4.5, prompt-caching-safe) — point managed anthropic at env.OC_GATEWAY, called inside the defineAgent initializer (top-level is tree-shaken).
  • route — HTTP-transport opt-in (every OC agent must export { route }).
  • ocSandbox(env) — durable OC-fleet SandboxApi (files/exec over the OC sandbox HTTP API; stat/mkdir/rm via shell, mirroring cloudflareSandbox).
  • ocRepoTools(env)publish_pull_request (repo plane; W10).
  • @opencomputer/flue/app (default hosting app: flue() + /health + observe→OC_INGEST) and /wire (telemetry-only side-effect).

Verified

tsc + build clean vs @flue/runtime@1.0.0-beta.9. End-to-end: the re-scaffolded oc-flue-starter (separate PR) flue build --target cloudflares zero hand-editing, and the wiring (useOcGateway/registerProvider, ocSandbox, /health, haiku model) is present in the bundle — not tree-shaken.

🔴 TOKEN SEAM — needs your decision

The buildout's seam (a) ("per-turn token → Flue's getApiKey(providerId) callback") is not achievable: registerProvider takes only a static apiKey; its internal getApiKey(providerId) gets no request/turn context; and the provider registry is module(isolate)-scoped, shared across co-located DO instances — so a per-session apiKey/headers/baseUrl set via registerProvider races across sessions in one isolate. Seam (b)'s per-instance X-OC-Session header has the same race (registration is isolate-global).

→ Robust per-session attribution needs the upstream ask: a per-request headers(ctx) hook on registerProvider (already in the buildout "Upstream asks"). Interim buildable shape wired here: static env.OC_SESSION_TOKEN (works one-session-per-isolate) metered by token.sub. Please confirm the direction (pursue the upstream hook / accept per-deploy metering / assume low co-location).

Seams flagged for other lanes

ocSandbox resolves the session's sandbox via OC_SANDBOX_ID or a POST {OC_SANDBOX_API}/flue/session-sandbox?session= seam (W1/W5 pin it); ocRepoTools posts to {OC_REPO_API}/publish (W10 pins it).

🤖 Generated with Claude Code

Replaces the serveOC/brain-box package with the Flue CF-native shape (design 013
§4/§5). A stock `flue build --target cloudflare` app opts into OC via:

- useOcGateway(ctx) + DEFAULT_MODEL (claude-haiku-4.5, prompt-caching-safe): point
  managed anthropic at env.OC_GATEWAY. Called INSIDE the defineAgent initializer
  (top-level is tree-shaken — 1a).
- route: the HTTP-transport opt-in every OC agent must export.
- ocSandbox(env): a durable OC-fleet SandboxApi (files/exec over the OC sandbox
  HTTP API; stat/mkdir/rm via shell, mirroring cloudflareSandbox).
- ocRepoTools(env): publish_pull_request (repo plane, used by W10).
- ./app: default hosting app (flue() + /health + observe→OC_INGEST). ./wire:
  telemetry-only side-effect for apps with their own app.ts.

Builds + typechecks clean against @flue/runtime@1.0.0-beta.9. Verified end-to-end:
the re-scaffolded oc-flue-starter `flue build --target cloudflare`s with zero
hand-editing and the wiring (useOcGateway/registerProvider, ocSandbox, /health,
haiku model) is present in the bundle (not tree-shaken).

TOKEN SEAM — OPEN, needs orchestrator decision (see gateway.ts): Flue's
registerProvider takes only a static apiKey and its getApiKey(providerId) callback
gets no request context, and the provider registry is isolate-global (shared across
co-located DO instances) — so a per-SESSION token/header/baseUrl via registerProvider
RACES. Wired the buildable env shape; robust per-session attribution needs the
upstream `headers(ctx)` ask.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@socket-security

socket-security Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​flue/​runtime@​1.0.0-beta.9781009496100
Addednpm/​vitest@​3.2.7981007999100
Addednpm/​@​types/​node@​22.20.01001008196100
Addednpm/​valibot@​1.4.21001009991100
Addednpm/​hono@​4.12.28991009796100

View full report

@socket-security

socket-security Bot commented Jul 5, 2026

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn High
Obfuscated code: npm just-bash is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/@flue/runtime@1.0.0-beta.9npm/just-bash@3.0.2

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/just-bash@3.0.2. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm strtok3 is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/@flue/runtime@1.0.0-beta.9npm/strtok3@10.3.5

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/strtok3@10.3.5. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
Obfuscated code: npm typebox is 90.0% likely obfuscated

Confidence: 0.90

Location: Package overview

From: ?npm/@flue/runtime@1.0.0-beta.9npm/typebox@1.1.38

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/typebox@1.1.38. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

ZIJ and others added 2 commits July 7, 2026 20:57
W6 live bring-up hit three defects W4's bundle-grep acceptance missed.
Fixed at the package layer so the scaffolded starter needs no workarounds.

1. DEFAULT_MODEL dot->dash. `anthropic/claude-haiku-4.5` is absent from
   pi-ai's model catalog, so pi-ai can't derive max output tokens and
   defaults max_tokens=1 -> empty completions. Use the catalog id
   `anthropic/claude-haiku-4-5` (dashes; OpenRouter routes it too).

2. ctx.env empty on the CF build. On `flue build --target cloudflare`
   the real Worker bindings live on the ambient `cloudflare:workers`
   env, not the per-agent `ctx.env` Flue threads in (that is empty for
   OC bindings), so OC_GATEWAY was unset -> the anthropic provider never
   registered ("Unknown model specifier"). New cf-env.ts reads the
   ambient env via a guarded lazy import (falls back to the passed env
   for local dev / node); useOcGateway + ocSandbox read through it.

3. Default `@opencomputer/flue/app` 500s. app.ts mounted flue() from
   `@flue/runtime/routing`; the generated CF entry seeds the runtime via
   configureFlueRuntime from `@flue/runtime/internal` and its no-app.ts
   path builds the app with createDefaultFlueApp() from that same entry.
   Compose via createDefaultFlueApp() so flue()'s module-scoped
   runtimeConfig is the instance the build configures (+ keep /health and
   installOcObserver) -> no "flue() route invoked before runtime was
   configured".

Verified: scaffolded starter `flue build --target cloudflare` + wrangler
dev -> GET /health 200; POST /agents turn 202 -> model call reaches the
gateway with model=claude-haiku-4-5, max_tokens=64000 (not 1); full turn
settles completed with a non-empty agent message.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ZIJ
ZIJ merged commit f2406d3 into flue-native Jul 7, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant