Skip to content

Commit 83c638e

Browse files
chore: generate
1 parent cb93114 commit 83c638e

20 files changed

Lines changed: 2137 additions & 1207 deletions

‎packages/codemode/README.md‎

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ The package is currently private to this workspace. Its API is designed around t
88

99
```ts
1010
// One execution
11-
yield* CodeMode.execute({ tools, code })
11+
yield * CodeMode.execute({ tools, code })
1212

1313
// A reusable runtime
1414
const runtime = CodeMode.make({ tools, limits })
15-
yield* runtime.execute(code)
15+
yield * runtime.execute(code)
1616

1717
// One agent-facing code tool
1818
const codeTool = runtime.agentTool()
@@ -55,7 +55,9 @@ const runtime = CodeMode.make({
5555
},
5656
})
5757

58-
const result = yield* runtime.execute(`
58+
const result =
59+
yield *
60+
runtime.execute(`
5961
const order = await tools.orders.lookup({ id: "order_42" })
6062
return { id: order.id, needsAttention: order.status !== "complete" }
6163
`)
@@ -72,8 +74,8 @@ Successful result values are JSON-safe data. A program that returns `undefined`,
7274
```ts
7375
const tool = Tool.make({
7476
description,
75-
input, // Effect Schema (validating) or JSON Schema (render-only)
76-
output, // optional; same choice
77+
input, // Effect Schema (validating) or JSON Schema (render-only)
78+
output, // optional; same choice
7779
run,
7880
})
7981
```
@@ -89,13 +91,15 @@ The description and schemas are part of the model-visible tool contract. Keep de
8991
Use `CodeMode.execute` for a single execution:
9092

9193
```ts
92-
const result = yield* CodeMode.execute({
93-
tools: { orders: { lookup: lookupOrder } },
94-
code: `return await tools.orders.lookup({ id: "order_42" })`,
95-
limits: { maxToolCalls: 10 },
96-
onToolCallStart: (call) => Effect.logDebug("CodeMode tool started", call),
97-
onToolCallEnd: (call) => Effect.logDebug("CodeMode tool settled", call),
98-
})
94+
const result =
95+
yield *
96+
CodeMode.execute({
97+
tools: { orders: { lookup: lookupOrder } },
98+
code: `return await tools.orders.lookup({ id: "order_42" })`,
99+
limits: { maxToolCalls: 10 },
100+
onToolCallStart: (call) => Effect.logDebug("CodeMode tool started", call),
101+
onToolCallEnd: (call) => Effect.logDebug("CodeMode tool settled", call),
102+
})
99103
```
100104

101105
The Effect environment is inferred from the supplied tools. CodeMode does not erase service requirements introduced by tool implementations.
@@ -110,10 +114,10 @@ const runtime = CodeMode.make({
110114
limits: { timeoutMs: 30_000 },
111115
})
112116

113-
runtime.catalog() // structured tool descriptions
114-
runtime.instructions() // model-facing syntax and tool guide
117+
runtime.catalog() // structured tool descriptions
118+
runtime.instructions() // model-facing syntax and tool guide
115119
runtime.execute(source) // ExecuteResult
116-
runtime.agentTool() // { name, description, input, output, execute }
120+
runtime.agentTool() // { name, description, input, output, execute }
117121
```
118122

119123
`catalog`, `instructions`, and `agentTool` are projections of the same configured tool tree. `agentTool().description` is exactly `instructions()`.
@@ -222,10 +226,10 @@ CodeMode is an orchestration language, not a general JavaScript runtime.
222226

223227
The limits are exactly three knobs:
224228

225-
| Limit | Default | Bounds |
226-
| --- | ---: | --- |
227-
| `timeoutMs` | none — no timeout | Wall-clock execution time. |
228-
| `maxToolCalls` | none — unlimited | Tool calls admitted during the execution. |
229+
| Limit | Default | Bounds |
230+
| ---------------- | -------------------: | -------------------------------------------------------------------- |
231+
| `timeoutMs` | none — no timeout | Wall-clock execution time. |
232+
| `maxToolCalls` | none — unlimited | Tool calls admitted during the execution. |
229233
| `maxOutputBytes` | none — no truncation | Model-facing output: the serialized result value plus captured logs. |
230234

231235
No limit has a default, on purpose: execution budgets are host policy, not library policy — a host that wants a bound sets one; a host that can interrupt the execution fiber (as OpenCode does on user cancel) may set no timeout, and a host with its own tool-output truncation (as OpenCode has) may leave `maxOutputBytes` unset. A host with neither should set `maxOutputBytes`, or oversized results silently flood model context.
@@ -254,28 +258,25 @@ Two interpreter internals are fixed constants rather than knobs: at most 8 tool
254258

255259
Failures are data:
256260

257-
| Kind | Meaning |
258-
| --- | --- |
259-
| `ParseError` | Source is empty or cannot be parsed. |
260-
| `UnsupportedSyntax` | Parsed JavaScript is outside the supported subset. |
261-
| `UnknownTool` | A program referenced a tool the host did not provide. |
262-
| `InvalidToolInput` | Tool input failed schema decoding or safe-data copying. |
263-
| `InvalidToolOutput` | Tool output failed schema decoding or safe-data copying. |
264-
| `InvalidDataValue` | Program data violated the plain-data contract (depth, circularity, blocked properties, non-data values). |
265-
| `ToolCallLimitExceeded` | Calls exceeded `maxToolCalls`. |
266-
| `TimeoutExceeded` | Execution exceeded `timeoutMs`. |
267-
| `ToolFailure` | A tool refused or failed. |
268-
| `ExecutionFailure` | The program threw or another execution error occurred. |
261+
| Kind | Meaning |
262+
| ----------------------- | -------------------------------------------------------------------------------------------------------- |
263+
| `ParseError` | Source is empty or cannot be parsed. |
264+
| `UnsupportedSyntax` | Parsed JavaScript is outside the supported subset. |
265+
| `UnknownTool` | A program referenced a tool the host did not provide. |
266+
| `InvalidToolInput` | Tool input failed schema decoding or safe-data copying. |
267+
| `InvalidToolOutput` | Tool output failed schema decoding or safe-data copying. |
268+
| `InvalidDataValue` | Program data violated the plain-data contract (depth, circularity, blocked properties, non-data values). |
269+
| `ToolCallLimitExceeded` | Calls exceeded `maxToolCalls`. |
270+
| `TimeoutExceeded` | Execution exceeded `timeoutMs`. |
271+
| `ToolFailure` | A tool refused or failed. |
272+
| `ExecutionFailure` | The program threw or another execution error occurred. |
269273

270274
Unknown host failures, defects, invalid outputs, and copying failures are sanitized. To return a safe operational refusal, fail with `toolError`:
271275

272276
```ts
273277
import { toolError } from "@opencode-ai/codemode"
274278

275-
run: ({ id }) =>
276-
authorized(id)
277-
? loadOrder(id)
278-
: Effect.fail(toolError("Order is unavailable"))
279+
run: ({ id }) => (authorized(id) ? loadOrder(id) : Effect.fail(toolError("Order is unavailable")))
279280
```
280281

281282
Only the supplied message is model-visible. The optional cause is never returned in `ExecuteResult`; hosts should perform any required internal logging before crossing this boundary.

0 commit comments

Comments
 (0)