@stonerzju/opencode 1.2.17 → 1.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/bin/opencode +29 -157
  2. package/package.json +29 -29
  3. package/src/acp/agent.ts +4 -4
  4. package/src/acp/session.ts +1 -1
  5. package/src/agent/agent.ts +3 -3
  6. package/src/bun/index.ts +2 -2
  7. package/src/cli/cmd/acp.ts +3 -3
  8. package/src/cli/cmd/debug/file.ts +1 -1
  9. package/src/cli/cmd/github.ts +2 -2
  10. package/src/cli/cmd/pr.ts +1 -1
  11. package/src/cli/cmd/tui/app.tsx +24 -24
  12. package/src/cli/cmd/tui/attach.ts +3 -3
  13. package/src/cli/cmd/tui/component/dialog-agent.tsx +3 -3
  14. package/src/cli/cmd/tui/component/dialog-command.tsx +3 -3
  15. package/src/cli/cmd/tui/component/dialog-mcp.tsx +5 -5
  16. package/src/cli/cmd/tui/component/dialog-model.tsx +4 -4
  17. package/src/cli/cmd/tui/component/dialog-provider.tsx +4 -4
  18. package/src/cli/cmd/tui/component/dialog-session-list.tsx +5 -5
  19. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +3 -3
  20. package/src/cli/cmd/tui/component/dialog-skill.tsx +3 -3
  21. package/src/cli/cmd/tui/component/dialog-stash.tsx +3 -3
  22. package/src/cli/cmd/tui/component/dialog-status.tsx +2 -2
  23. package/src/cli/cmd/tui/component/dialog-tag.tsx +3 -3
  24. package/src/cli/cmd/tui/component/logo.tsx +2 -2
  25. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +6 -6
  26. package/src/cli/cmd/tui/component/prompt/frecency.tsx +2 -2
  27. package/src/cli/cmd/tui/component/prompt/history.tsx +2 -2
  28. package/src/cli/cmd/tui/component/prompt/index.tsx +14 -14
  29. package/src/cli/cmd/tui/component/prompt/stash.tsx +2 -2
  30. package/src/cli/cmd/tui/component/textarea-keybindings.ts +1 -1
  31. package/src/cli/cmd/tui/component/tips.tsx +1 -1
  32. package/src/cli/cmd/tui/context/directory.ts +1 -1
  33. package/src/cli/cmd/tui/context/exit.tsx +1 -1
  34. package/src/cli/cmd/tui/context/keybind.tsx +2 -2
  35. package/src/cli/cmd/tui/context/kv.tsx +2 -2
  36. package/src/cli/cmd/tui/context/local.tsx +6 -6
  37. package/src/cli/cmd/tui/context/sync.tsx +4 -4
  38. package/src/cli/cmd/tui/context/theme/opencode.json +245 -0
  39. package/src/cli/cmd/tui/context/theme.tsx +2 -2
  40. package/src/cli/cmd/tui/context/tui-config.tsx +1 -1
  41. package/src/cli/cmd/tui/event.ts +2 -2
  42. package/src/cli/cmd/tui/routes/home.tsx +6 -6
  43. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +6 -6
  44. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +6 -6
  45. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +2 -2
  46. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +3 -3
  47. package/src/cli/cmd/tui/routes/session/header.tsx +5 -5
  48. package/src/cli/cmd/tui/routes/session/index.tsx +32 -32
  49. package/src/cli/cmd/tui/routes/session/permission.tsx +4 -4
  50. package/src/cli/cmd/tui/routes/session/sidebar.tsx +4 -4
  51. package/src/cli/cmd/tui/thread.ts +9 -9
  52. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +1 -1
  53. package/src/cli/cmd/tui/ui/dialog-help.tsx +2 -2
  54. package/src/cli/cmd/tui/ui/dialog-select.tsx +5 -5
  55. package/src/cli/cmd/tui/ui/dialog.tsx +3 -3
  56. package/src/cli/cmd/tui/ui/toast.tsx +1 -1
  57. package/src/cli/cmd/tui/util/editor.ts +3 -3
  58. package/src/cli/cmd/tui/util/transcript.ts +1 -1
  59. package/src/cli/cmd/tui/worker.ts +10 -10
  60. package/src/cli/error.ts +1 -1
  61. package/src/cli/ui.ts +1 -1
  62. package/src/cli/upgrade.ts +4 -4
  63. package/src/command/index.ts +1 -1
  64. package/src/config/config.ts +10 -10
  65. package/src/config/markdown.ts +1 -1
  66. package/src/config/migrate-tui-config.ts +5 -5
  67. package/src/config/paths.ts +4 -4
  68. package/src/config/tui.ts +4 -4
  69. package/src/control/control.sql.ts +1 -1
  70. package/src/control/index.ts +1 -1
  71. package/src/control-plane/adaptors/worktree.ts +1 -1
  72. package/src/control-plane/session-proxy-middleware.ts +1 -1
  73. package/src/control-plane/workspace.sql.ts +1 -1
  74. package/src/control-plane/workspace.ts +7 -7
  75. package/src/file/index.ts +1 -1
  76. package/src/file/ripgrep.ts +2 -2
  77. package/src/file/watcher.ts +5 -5
  78. package/src/format/formatter.ts +1 -1
  79. package/src/ide/index.ts +3 -3
  80. package/src/index.ts +1 -1
  81. package/src/installation/index.ts +3 -3
  82. package/src/lsp/client.ts +3 -3
  83. package/src/lsp/index.ts +3 -3
  84. package/src/mcp/index.ts +4 -4
  85. package/src/permission/index.ts +2 -2
  86. package/src/permission/next.ts +10 -10
  87. package/src/plugin/codex.ts +1 -1
  88. package/src/plugin/copilot.ts +2 -2
  89. package/src/plugin/index.ts +1 -1
  90. package/src/project/bootstrap.ts +2 -2
  91. package/src/project/instance.ts +4 -4
  92. package/src/project/project.sql.ts +1 -1
  93. package/src/project/project.ts +5 -5
  94. package/src/project/state.ts +1 -1
  95. package/src/project/vcs.ts +4 -4
  96. package/src/provider/auth.ts +4 -4
  97. package/src/provider/error.ts +1 -1
  98. package/src/provider/models-snapshot.ts +2 -0
  99. package/src/provider/models.ts +1 -1
  100. package/src/provider/provider.ts +2 -2
  101. package/src/provider/transform.ts +2 -2
  102. package/src/pty/index.ts +5 -5
  103. package/src/question/index.ts +5 -5
  104. package/src/server/event.ts +1 -1
  105. package/src/server/mdns.ts +1 -1
  106. package/src/server/routes/global.ts +3 -3
  107. package/src/server/routes/permission.ts +1 -1
  108. package/src/server/routes/pty.ts +1 -1
  109. package/src/server/routes/session.ts +4 -4
  110. package/src/server/routes/tui.ts +1 -1
  111. package/src/server/server.ts +3 -3
  112. package/src/session/compaction.ts +7 -7
  113. package/src/session/index.ts +10 -10
  114. package/src/session/instruction.ts +1 -1
  115. package/src/session/llm.ts +11 -11
  116. package/src/session/message-v2.ts +10 -10
  117. package/src/session/message.ts +1 -1
  118. package/src/session/processor.ts +10 -10
  119. package/src/session/prompt.ts +8 -8
  120. package/src/session/retry.ts +2 -2
  121. package/src/session/revert.ts +1 -1
  122. package/src/session/session.sql.ts +3 -3
  123. package/src/session/status.ts +3 -3
  124. package/src/session/summary.ts +5 -5
  125. package/src/session/system.ts +1 -1
  126. package/src/session/todo.ts +2 -2
  127. package/src/share/share-next.ts +7 -7
  128. package/src/share/share.sql.ts +1 -1
  129. package/src/shell/shell.ts +3 -3
  130. package/src/skill/skill.ts +6 -6
  131. package/src/storage/db.ts +1 -1
  132. package/src/storage/storage.ts +1 -1
  133. package/src/tool/bash.ts +6 -6
  134. package/src/tool/edit.ts +1 -1
  135. package/src/tool/registry.ts +2 -2
  136. package/src/tool/skill.ts +1 -1
  137. package/src/tool/task.ts +3 -3
  138. package/src/util/array.ts +10 -0
  139. package/src/util/binary.ts +41 -0
  140. package/src/util/encode.ts +51 -0
  141. package/src/util/error.ts +54 -0
  142. package/src/util/identifier.ts +48 -0
  143. package/src/util/lazy.ts +4 -16
  144. package/src/util/path.ts +37 -0
  145. package/src/util/retry.ts +41 -0
  146. package/src/util/slug.ts +74 -0
  147. package/src/worktree/index.ts +3 -3
  148. package/AGENTS.md +0 -10
  149. package/BUN_SHELL_MIGRATION_PLAN.md +0 -136
  150. package/Dockerfile +0 -18
  151. package/README.md +0 -15
  152. package/bunfig.toml +0 -7
  153. package/drizzle.config.ts +0 -10
  154. package/script/build.ts +0 -224
  155. package/script/check-migrations.ts +0 -16
  156. package/script/postinstall.mjs +0 -131
  157. package/script/publish.ts +0 -181
  158. package/script/schema.ts +0 -63
  159. package/script/seed-e2e.ts +0 -50
  160. package/sst-env.d.ts +0 -10
  161. package/test/AGENTS.md +0 -81
  162. package/test/acp/agent-interface.test.ts +0 -51
  163. package/test/acp/event-subscription.test.ts +0 -683
  164. package/test/agent/agent.test.ts +0 -689
  165. package/test/bun.test.ts +0 -53
  166. package/test/cli/github-action.test.ts +0 -197
  167. package/test/cli/github-remote.test.ts +0 -80
  168. package/test/cli/import.test.ts +0 -38
  169. package/test/cli/plugin-auth-picker.test.ts +0 -120
  170. package/test/cli/tui/transcript.test.ts +0 -322
  171. package/test/config/agent-color.test.ts +0 -71
  172. package/test/config/config.test.ts +0 -1886
  173. package/test/config/fixtures/empty-frontmatter.md +0 -4
  174. package/test/config/fixtures/frontmatter.md +0 -28
  175. package/test/config/fixtures/markdown-header.md +0 -11
  176. package/test/config/fixtures/no-frontmatter.md +0 -1
  177. package/test/config/fixtures/weird-model-id.md +0 -13
  178. package/test/config/markdown.test.ts +0 -228
  179. package/test/config/tui.test.ts +0 -510
  180. package/test/control-plane/session-proxy-middleware.test.ts +0 -147
  181. package/test/control-plane/sse.test.ts +0 -56
  182. package/test/control-plane/workspace-server-sse.test.ts +0 -65
  183. package/test/control-plane/workspace-sync.test.ts +0 -97
  184. package/test/file/ignore.test.ts +0 -10
  185. package/test/file/index.test.ts +0 -394
  186. package/test/file/path-traversal.test.ts +0 -198
  187. package/test/file/ripgrep.test.ts +0 -39
  188. package/test/file/time.test.ts +0 -361
  189. package/test/fixture/db.ts +0 -11
  190. package/test/fixture/fixture.ts +0 -45
  191. package/test/fixture/lsp/fake-lsp-server.js +0 -77
  192. package/test/fixture/skills/agents-sdk/SKILL.md +0 -152
  193. package/test/fixture/skills/agents-sdk/references/callable.md +0 -92
  194. package/test/fixture/skills/cloudflare/SKILL.md +0 -211
  195. package/test/fixture/skills/index.json +0 -6
  196. package/test/ide/ide.test.ts +0 -82
  197. package/test/keybind.test.ts +0 -421
  198. package/test/lsp/client.test.ts +0 -95
  199. package/test/mcp/headers.test.ts +0 -153
  200. package/test/mcp/oauth-browser.test.ts +0 -249
  201. package/test/memory/abort-leak.test.ts +0 -136
  202. package/test/patch/patch.test.ts +0 -348
  203. package/test/permission/arity.test.ts +0 -33
  204. package/test/permission/next.test.ts +0 -689
  205. package/test/permission-task.test.ts +0 -319
  206. package/test/plugin/auth-override.test.ts +0 -44
  207. package/test/plugin/codex.test.ts +0 -123
  208. package/test/preload.ts +0 -80
  209. package/test/project/project.test.ts +0 -348
  210. package/test/project/worktree-remove.test.ts +0 -65
  211. package/test/provider/amazon-bedrock.test.ts +0 -446
  212. package/test/provider/copilot/convert-to-copilot-messages.test.ts +0 -523
  213. package/test/provider/copilot/copilot-chat-model.test.ts +0 -592
  214. package/test/provider/gitlab-duo.test.ts +0 -262
  215. package/test/provider/provider.test.ts +0 -2220
  216. package/test/provider/transform.test.ts +0 -2353
  217. package/test/pty/pty-output-isolation.test.ts +0 -140
  218. package/test/question/question.test.ts +0 -300
  219. package/test/scheduler.test.ts +0 -73
  220. package/test/server/global-session-list.test.ts +0 -89
  221. package/test/server/session-list.test.ts +0 -90
  222. package/test/server/session-select.test.ts +0 -78
  223. package/test/session/compaction.test.ts +0 -423
  224. package/test/session/instruction.test.ts +0 -170
  225. package/test/session/llm.test.ts +0 -667
  226. package/test/session/message-v2.test.ts +0 -924
  227. package/test/session/prompt.test.ts +0 -211
  228. package/test/session/retry.test.ts +0 -188
  229. package/test/session/revert-compact.test.ts +0 -285
  230. package/test/session/session.test.ts +0 -71
  231. package/test/session/structured-output-integration.test.ts +0 -233
  232. package/test/session/structured-output.test.ts +0 -385
  233. package/test/skill/discovery.test.ts +0 -110
  234. package/test/skill/skill.test.ts +0 -388
  235. package/test/snapshot/snapshot.test.ts +0 -1180
  236. package/test/storage/json-migration.test.ts +0 -846
  237. package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
  238. package/test/tool/apply_patch.test.ts +0 -566
  239. package/test/tool/bash.test.ts +0 -402
  240. package/test/tool/edit.test.ts +0 -496
  241. package/test/tool/external-directory.test.ts +0 -127
  242. package/test/tool/fixtures/large-image.png +0 -0
  243. package/test/tool/fixtures/models-api.json +0 -38413
  244. package/test/tool/grep.test.ts +0 -110
  245. package/test/tool/question.test.ts +0 -107
  246. package/test/tool/read.test.ts +0 -504
  247. package/test/tool/registry.test.ts +0 -122
  248. package/test/tool/skill.test.ts +0 -112
  249. package/test/tool/truncation.test.ts +0 -160
  250. package/test/tool/webfetch.test.ts +0 -100
  251. package/test/tool/write.test.ts +0 -348
  252. package/test/util/filesystem.test.ts +0 -443
  253. package/test/util/format.test.ts +0 -59
  254. package/test/util/glob.test.ts +0 -164
  255. package/test/util/iife.test.ts +0 -36
  256. package/test/util/lazy.test.ts +0 -50
  257. package/test/util/lock.test.ts +0 -72
  258. package/test/util/process.test.ts +0 -59
  259. package/test/util/timeout.test.ts +0 -21
  260. package/test/util/wildcard.test.ts +0 -90
  261. package/tsconfig.json +0 -16
@@ -1,77 +0,0 @@
1
- // Simple JSON-RPC 2.0 LSP-like fake server over stdio
2
- // Implements a minimal LSP handshake and triggers a request upon notification
3
-
4
- const net = require("net")
5
-
6
- let nextId = 1
7
-
8
- function encode(message) {
9
- const json = JSON.stringify(message)
10
- const header = `Content-Length: ${Buffer.byteLength(json, "utf8")}\r\n\r\n`
11
- return Buffer.concat([Buffer.from(header, "utf8"), Buffer.from(json, "utf8")])
12
- }
13
-
14
- function decodeFrames(buffer) {
15
- const results = []
16
- let idx
17
- while ((idx = buffer.indexOf("\r\n\r\n")) !== -1) {
18
- const header = buffer.slice(0, idx).toString("utf8")
19
- const m = /Content-Length:\s*(\d+)/i.exec(header)
20
- const len = m ? parseInt(m[1], 10) : 0
21
- const bodyStart = idx + 4
22
- const bodyEnd = bodyStart + len
23
- if (buffer.length < bodyEnd) break
24
- const body = buffer.slice(bodyStart, bodyEnd).toString("utf8")
25
- results.push(body)
26
- buffer = buffer.slice(bodyEnd)
27
- }
28
- return { messages: results, rest: buffer }
29
- }
30
-
31
- let readBuffer = Buffer.alloc(0)
32
-
33
- process.stdin.on("data", (chunk) => {
34
- readBuffer = Buffer.concat([readBuffer, chunk])
35
- const { messages, rest } = decodeFrames(readBuffer)
36
- readBuffer = rest
37
- for (const m of messages) handle(m)
38
- })
39
-
40
- function send(msg) {
41
- process.stdout.write(encode(msg))
42
- }
43
-
44
- function sendRequest(method, params) {
45
- const id = nextId++
46
- send({ jsonrpc: "2.0", id, method, params })
47
- return id
48
- }
49
-
50
- function handle(raw) {
51
- let data
52
- try {
53
- data = JSON.parse(raw)
54
- } catch {
55
- return
56
- }
57
- if (data.method === "initialize") {
58
- send({ jsonrpc: "2.0", id: data.id, result: { capabilities: {} } })
59
- return
60
- }
61
- if (data.method === "initialized") {
62
- return
63
- }
64
- if (data.method === "workspace/didChangeConfiguration") {
65
- return
66
- }
67
- if (data.method === "test/trigger") {
68
- const method = data.params && data.params.method
69
- if (method) sendRequest(method, {})
70
- return
71
- }
72
- if (typeof data.id !== "undefined") {
73
- // Respond OK to any request from client to keep transport flowing
74
- send({ jsonrpc: "2.0", id: data.id, result: null })
75
- return
76
- }
77
- }
@@ -1,152 +0,0 @@
1
- ---
2
- name: agents-sdk
3
- description: Build AI agents on Cloudflare Workers using the Agents SDK. Load when creating stateful agents, durable workflows, real-time WebSocket apps, scheduled tasks, MCP servers, or chat applications. Covers Agent class, state management, callable RPC, Workflows integration, and React hooks.
4
- ---
5
-
6
- # Cloudflare Agents SDK
7
-
8
- **STOP.** Your knowledge of the Agents SDK may be outdated. Prefer retrieval over pre-training for any Agents SDK task.
9
-
10
- ## Documentation
11
-
12
- Fetch current docs from `https://github.com/cloudflare/agents/tree/main/docs` before implementing.
13
-
14
- | Topic | Doc | Use for |
15
- | ------------------- | ----------------------------- | ---------------------------------------------- |
16
- | Getting started | `docs/getting-started.md` | First agent, project setup |
17
- | State | `docs/state.md` | `setState`, `validateStateChange`, persistence |
18
- | Routing | `docs/routing.md` | URL patterns, `routeAgentRequest`, `basePath` |
19
- | Callable methods | `docs/callable-methods.md` | `@callable`, RPC, streaming, timeouts |
20
- | Scheduling | `docs/scheduling.md` | `schedule()`, `scheduleEvery()`, cron |
21
- | Workflows | `docs/workflows.md` | `AgentWorkflow`, durable multi-step tasks |
22
- | HTTP/WebSockets | `docs/http-websockets.md` | Lifecycle hooks, hibernation |
23
- | Email | `docs/email.md` | Email routing, secure reply resolver |
24
- | MCP client | `docs/mcp-client.md` | Connecting to MCP servers |
25
- | MCP server | `docs/mcp-servers.md` | Building MCP servers with `McpAgent` |
26
- | Client SDK | `docs/client-sdk.md` | `useAgent`, `useAgentChat`, React hooks |
27
- | Human-in-the-loop | `docs/human-in-the-loop.md` | Approval flows, pausing workflows |
28
- | Resumable streaming | `docs/resumable-streaming.md` | Stream recovery on disconnect |
29
-
30
- Cloudflare docs: https://developers.cloudflare.com/agents/
31
-
32
- ## Capabilities
33
-
34
- The Agents SDK provides:
35
-
36
- - **Persistent state** - SQLite-backed, auto-synced to clients
37
- - **Callable RPC** - `@callable()` methods invoked over WebSocket
38
- - **Scheduling** - One-time, recurring (`scheduleEvery`), and cron tasks
39
- - **Workflows** - Durable multi-step background processing via `AgentWorkflow`
40
- - **MCP integration** - Connect to MCP servers or build your own with `McpAgent`
41
- - **Email handling** - Receive and reply to emails with secure routing
42
- - **Streaming chat** - `AIChatAgent` with resumable streams
43
- - **React hooks** - `useAgent`, `useAgentChat` for client apps
44
-
45
- ## FIRST: Verify Installation
46
-
47
- ```bash
48
- npm ls agents # Should show agents package
49
- ```
50
-
51
- If not installed:
52
-
53
- ```bash
54
- npm install agents
55
- ```
56
-
57
- ## Wrangler Configuration
58
-
59
- ```jsonc
60
- {
61
- "durable_objects": {
62
- "bindings": [{ "name": "MyAgent", "class_name": "MyAgent" }],
63
- },
64
- "migrations": [{ "tag": "v1", "new_sqlite_classes": ["MyAgent"] }],
65
- }
66
- ```
67
-
68
- ## Agent Class
69
-
70
- ```typescript
71
- import { Agent, routeAgentRequest, callable } from "agents"
72
-
73
- type State = { count: number }
74
-
75
- export class Counter extends Agent<Env, State> {
76
- initialState = { count: 0 }
77
-
78
- // Validation hook - runs before state persists (sync, throwing rejects the update)
79
- validateStateChange(nextState: State, source: Connection | "server") {
80
- if (nextState.count < 0) throw new Error("Count cannot be negative")
81
- }
82
-
83
- // Notification hook - runs after state persists (async, non-blocking)
84
- onStateUpdate(state: State, source: Connection | "server") {
85
- console.log("State updated:", state)
86
- }
87
-
88
- @callable()
89
- increment() {
90
- this.setState({ count: this.state.count + 1 })
91
- return this.state.count
92
- }
93
- }
94
-
95
- export default {
96
- fetch: (req, env) => routeAgentRequest(req, env) ?? new Response("Not found", { status: 404 }),
97
- }
98
- ```
99
-
100
- ## Routing
101
-
102
- Requests route to `/agents/{agent-name}/{instance-name}`:
103
-
104
- | Class | URL |
105
- | ---------- | -------------------------- |
106
- | `Counter` | `/agents/counter/user-123` |
107
- | `ChatRoom` | `/agents/chat-room/lobby` |
108
-
109
- Client: `useAgent({ agent: "Counter", name: "user-123" })`
110
-
111
- ## Core APIs
112
-
113
- | Task | API |
114
- | ------------------- | ------------------------------------------------------ |
115
- | Read state | `this.state.count` |
116
- | Write state | `this.setState({ count: 1 })` |
117
- | SQL query | `` this.sql`SELECT * FROM users WHERE id = ${id}` `` |
118
- | Schedule (delay) | `await this.schedule(60, "task", payload)` |
119
- | Schedule (cron) | `await this.schedule("0 * * * *", "task", payload)` |
120
- | Schedule (interval) | `await this.scheduleEvery(30, "poll")` |
121
- | RPC method | `@callable() myMethod() { ... }` |
122
- | Streaming RPC | `@callable({ streaming: true }) stream(res) { ... }` |
123
- | Start workflow | `await this.runWorkflow("ProcessingWorkflow", params)` |
124
-
125
- ## React Client
126
-
127
- ```tsx
128
- import { useAgent } from "agents/react"
129
-
130
- function App() {
131
- const [state, setLocalState] = useState({ count: 0 })
132
-
133
- const agent = useAgent({
134
- agent: "Counter",
135
- name: "my-instance",
136
- onStateUpdate: (newState) => setLocalState(newState),
137
- onIdentity: (name, agentType) => console.log(`Connected to ${name}`),
138
- })
139
-
140
- return <button onClick={() => agent.setState({ count: state.count + 1 })}>Count: {state.count}</button>
141
- }
142
- ```
143
-
144
- ## References
145
-
146
- - **[references/workflows.md](references/workflows.md)** - Durable Workflows integration
147
- - **[references/callable.md](references/callable.md)** - RPC methods, streaming, timeouts
148
- - **[references/state-scheduling.md](references/state-scheduling.md)** - State persistence, scheduling
149
- - **[references/streaming-chat.md](references/streaming-chat.md)** - AIChatAgent, resumable streams
150
- - **[references/mcp.md](references/mcp.md)** - MCP server integration
151
- - **[references/email.md](references/email.md)** - Email routing and handling
152
- - **[references/codemode.md](references/codemode.md)** - Code Mode (experimental)
@@ -1,92 +0,0 @@
1
- # Callable Methods
2
-
3
- Fetch `docs/callable-methods.md` from `https://github.com/cloudflare/agents/tree/main/docs` for complete documentation.
4
-
5
- ## Overview
6
-
7
- `@callable()` exposes agent methods to clients via WebSocket RPC.
8
-
9
- ```typescript
10
- import { Agent, callable } from "agents"
11
-
12
- export class MyAgent extends Agent<Env, State> {
13
- @callable()
14
- async greet(name: string): Promise<string> {
15
- return `Hello, ${name}!`
16
- }
17
-
18
- @callable()
19
- async processData(data: unknown): Promise<Result> {
20
- // Long-running work
21
- return result
22
- }
23
- }
24
- ```
25
-
26
- ## Client Usage
27
-
28
- ```typescript
29
- // Basic call
30
- const greeting = await agent.call("greet", ["World"])
31
-
32
- // With timeout
33
- const result = await agent.call("processData", [data], {
34
- timeout: 5000, // 5 second timeout
35
- })
36
- ```
37
-
38
- ## Streaming Responses
39
-
40
- ```typescript
41
- import { Agent, callable, StreamingResponse } from "agents"
42
-
43
- export class MyAgent extends Agent<Env, State> {
44
- @callable({ streaming: true })
45
- async streamResults(stream: StreamingResponse, query: string) {
46
- for await (const item of fetchResults(query)) {
47
- stream.send(JSON.stringify(item))
48
- }
49
- stream.close()
50
- }
51
-
52
- @callable({ streaming: true })
53
- async streamWithError(stream: StreamingResponse) {
54
- try {
55
- // ... work
56
- } catch (error) {
57
- stream.error(error.message) // Signal error to client
58
- return
59
- }
60
- stream.close()
61
- }
62
- }
63
- ```
64
-
65
- Client with streaming:
66
-
67
- ```typescript
68
- await agent.call("streamResults", ["search term"], {
69
- stream: {
70
- onChunk: (data) => console.log("Chunk:", data),
71
- onDone: () => console.log("Complete"),
72
- onError: (error) => console.error("Error:", error),
73
- },
74
- })
75
- ```
76
-
77
- ## Introspection
78
-
79
- ```typescript
80
- // Get list of callable methods on an agent
81
- const methods = await agent.call("getCallableMethods", [])
82
- // Returns: ["greet", "processData", "streamResults", ...]
83
- ```
84
-
85
- ## When to Use
86
-
87
- | Scenario | Use |
88
- | ------------------------------------ | --------------------------- |
89
- | Browser/mobile calling agent | `@callable()` |
90
- | External service calling agent | `@callable()` |
91
- | Worker calling agent (same codebase) | DO RPC directly |
92
- | Agent calling another agent | `getAgentByName()` + DO RPC |
@@ -1,211 +0,0 @@
1
- ---
2
- name: cloudflare
3
- description: Comprehensive Cloudflare platform skill covering Workers, Pages, storage (KV, D1, R2), AI (Workers AI, Vectorize, Agents SDK), networking (Tunnel, Spectrum), security (WAF, DDoS), and infrastructure-as-code (Terraform, Pulumi). Use for any Cloudflare development task.
4
- references:
5
- - workers
6
- - pages
7
- - d1
8
- - durable-objects
9
- - workers-ai
10
- ---
11
-
12
- # Cloudflare Platform Skill
13
-
14
- Consolidated skill for building on the Cloudflare platform. Use decision trees below to find the right product, then load detailed references.
15
-
16
- ## Quick Decision Trees
17
-
18
- ### "I need to run code"
19
-
20
- ```
21
- Need to run code?
22
- ├─ Serverless functions at the edge → workers/
23
- ├─ Full-stack web app with Git deploys → pages/
24
- ├─ Stateful coordination/real-time → durable-objects/
25
- ├─ Long-running multi-step jobs → workflows/
26
- ├─ Run containers → containers/
27
- ├─ Multi-tenant (customers deploy code) → workers-for-platforms/
28
- ├─ Scheduled tasks (cron) → cron-triggers/
29
- ├─ Lightweight edge logic (modify HTTP) → snippets/
30
- ├─ Process Worker execution events (logs/observability) → tail-workers/
31
- └─ Optimize latency to backend infrastructure → smart-placement/
32
- ```
33
-
34
- ### "I need to store data"
35
-
36
- ```
37
- Need storage?
38
- ├─ Key-value (config, sessions, cache) → kv/
39
- ├─ Relational SQL → d1/ (SQLite) or hyperdrive/ (existing Postgres/MySQL)
40
- ├─ Object/file storage (S3-compatible) → r2/
41
- ├─ Message queue (async processing) → queues/
42
- ├─ Vector embeddings (AI/semantic search) → vectorize/
43
- ├─ Strongly-consistent per-entity state → durable-objects/ (DO storage)
44
- ├─ Secrets management → secrets-store/
45
- ├─ Streaming ETL to R2 → pipelines/
46
- └─ Persistent cache (long-term retention) → cache-reserve/
47
- ```
48
-
49
- ### "I need AI/ML"
50
-
51
- ```
52
- Need AI?
53
- ├─ Run inference (LLMs, embeddings, images) → workers-ai/
54
- ├─ Vector database for RAG/search → vectorize/
55
- ├─ Build stateful AI agents → agents-sdk/
56
- ├─ Gateway for any AI provider (caching, routing) → ai-gateway/
57
- └─ AI-powered search widget → ai-search/
58
- ```
59
-
60
- ### "I need networking/connectivity"
61
-
62
- ```
63
- Need networking?
64
- ├─ Expose local service to internet → tunnel/
65
- ├─ TCP/UDP proxy (non-HTTP) → spectrum/
66
- ├─ WebRTC TURN server → turn/
67
- ├─ Private network connectivity → network-interconnect/
68
- ├─ Optimize routing → argo-smart-routing/
69
- ├─ Optimize latency to backend (not user) → smart-placement/
70
- └─ Real-time video/audio → realtimekit/ or realtime-sfu/
71
- ```
72
-
73
- ### "I need security"
74
-
75
- ```
76
- Need security?
77
- ├─ Web Application Firewall → waf/
78
- ├─ DDoS protection → ddos/
79
- ├─ Bot detection/management → bot-management/
80
- ├─ API protection → api-shield/
81
- ├─ CAPTCHA alternative → turnstile/
82
- └─ Credential leak detection → waf/ (managed ruleset)
83
- ```
84
-
85
- ### "I need media/content"
86
-
87
- ```
88
- Need media?
89
- ├─ Image optimization/transformation → images/
90
- ├─ Video streaming/encoding → stream/
91
- ├─ Browser automation/screenshots → browser-rendering/
92
- └─ Third-party script management → zaraz/
93
- ```
94
-
95
- ### "I need infrastructure-as-code"
96
-
97
- ```
98
- Need IaC? → pulumi/ (Pulumi), terraform/ (Terraform), or api/ (REST API)
99
- ```
100
-
101
- ## Product Index
102
-
103
- ### Compute & Runtime
104
-
105
- | Product | Reference |
106
- | --------------------- | ----------------------------------- |
107
- | Workers | `references/workers/` |
108
- | Pages | `references/pages/` |
109
- | Pages Functions | `references/pages-functions/` |
110
- | Durable Objects | `references/durable-objects/` |
111
- | Workflows | `references/workflows/` |
112
- | Containers | `references/containers/` |
113
- | Workers for Platforms | `references/workers-for-platforms/` |
114
- | Cron Triggers | `references/cron-triggers/` |
115
- | Tail Workers | `references/tail-workers/` |
116
- | Snippets | `references/snippets/` |
117
- | Smart Placement | `references/smart-placement/` |
118
-
119
- ### Storage & Data
120
-
121
- | Product | Reference |
122
- | --------------- | ----------------------------- |
123
- | KV | `references/kv/` |
124
- | D1 | `references/d1/` |
125
- | R2 | `references/r2/` |
126
- | Queues | `references/queues/` |
127
- | Hyperdrive | `references/hyperdrive/` |
128
- | DO Storage | `references/do-storage/` |
129
- | Secrets Store | `references/secrets-store/` |
130
- | Pipelines | `references/pipelines/` |
131
- | R2 Data Catalog | `references/r2-data-catalog/` |
132
- | R2 SQL | `references/r2-sql/` |
133
-
134
- ### AI & Machine Learning
135
-
136
- | Product | Reference |
137
- | ---------- | ------------------------ |
138
- | Workers AI | `references/workers-ai/` |
139
- | Vectorize | `references/vectorize/` |
140
- | Agents SDK | `references/agents-sdk/` |
141
- | AI Gateway | `references/ai-gateway/` |
142
- | AI Search | `references/ai-search/` |
143
-
144
- ### Networking & Connectivity
145
-
146
- | Product | Reference |
147
- | -------------------- | ---------------------------------- |
148
- | Tunnel | `references/tunnel/` |
149
- | Spectrum | `references/spectrum/` |
150
- | TURN | `references/turn/` |
151
- | Network Interconnect | `references/network-interconnect/` |
152
- | Argo Smart Routing | `references/argo-smart-routing/` |
153
- | Workers VPC | `references/workers-vpc/` |
154
-
155
- ### Security
156
-
157
- | Product | Reference |
158
- | --------------- | ---------------------------- |
159
- | WAF | `references/waf/` |
160
- | DDoS Protection | `references/ddos/` |
161
- | Bot Management | `references/bot-management/` |
162
- | API Shield | `references/api-shield/` |
163
- | Turnstile | `references/turnstile/` |
164
-
165
- ### Media & Content
166
-
167
- | Product | Reference |
168
- | ----------------- | ------------------------------- |
169
- | Images | `references/images/` |
170
- | Stream | `references/stream/` |
171
- | Browser Rendering | `references/browser-rendering/` |
172
- | Zaraz | `references/zaraz/` |
173
-
174
- ### Real-Time Communication
175
-
176
- | Product | Reference |
177
- | ------------ | -------------------------- |
178
- | RealtimeKit | `references/realtimekit/` |
179
- | Realtime SFU | `references/realtime-sfu/` |
180
-
181
- ### Developer Tools
182
-
183
- | Product | Reference |
184
- | ------------------ | -------------------------------- |
185
- | Wrangler | `references/wrangler/` |
186
- | Miniflare | `references/miniflare/` |
187
- | C3 | `references/c3/` |
188
- | Observability | `references/observability/` |
189
- | Analytics Engine | `references/analytics-engine/` |
190
- | Web Analytics | `references/web-analytics/` |
191
- | Sandbox | `references/sandbox/` |
192
- | Workerd | `references/workerd/` |
193
- | Workers Playground | `references/workers-playground/` |
194
-
195
- ### Infrastructure as Code
196
-
197
- | Product | Reference |
198
- | --------- | ----------------------- |
199
- | Pulumi | `references/pulumi/` |
200
- | Terraform | `references/terraform/` |
201
- | API | `references/api/` |
202
-
203
- ### Other Services
204
-
205
- | Product | Reference |
206
- | ------------- | --------------------------- |
207
- | Email Routing | `references/email-routing/` |
208
- | Email Workers | `references/email-workers/` |
209
- | Static Assets | `references/static-assets/` |
210
- | Bindings | `references/bindings/` |
211
- | Cache Reserve | `references/cache-reserve/` |
@@ -1,6 +0,0 @@
1
- {
2
- "skills": [
3
- { "name": "agents-sdk", "description": "Cloudflare Agents SDK", "files": ["SKILL.md", "references/callable.md"] },
4
- { "name": "cloudflare", "description": "Cloudflare Platform Skill", "files": ["SKILL.md"] }
5
- ]
6
- }
@@ -1,82 +0,0 @@
1
- import { describe, expect, test, afterEach } from "bun:test"
2
- import { Ide } from "../../src/ide"
3
-
4
- describe("ide", () => {
5
- const original = { ...process.env }
6
-
7
- afterEach(() => {
8
- Object.keys(process.env).forEach((key) => {
9
- delete process.env[key]
10
- })
11
- Object.assign(process.env, original)
12
- })
13
-
14
- test("should detect Visual Studio Code", () => {
15
- process.env["TERM_PROGRAM"] = "vscode"
16
- process.env["GIT_ASKPASS"] = "/path/to/Visual Studio Code.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
17
-
18
- expect(Ide.ide()).toBe("Visual Studio Code")
19
- })
20
-
21
- test("should detect Visual Studio Code Insiders", () => {
22
- process.env["TERM_PROGRAM"] = "vscode"
23
- process.env["GIT_ASKPASS"] =
24
- "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
25
-
26
- expect(Ide.ide()).toBe("Visual Studio Code - Insiders")
27
- })
28
-
29
- test("should detect Cursor", () => {
30
- process.env["TERM_PROGRAM"] = "vscode"
31
- process.env["GIT_ASKPASS"] = "/path/to/Cursor.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
32
-
33
- expect(Ide.ide()).toBe("Cursor")
34
- })
35
-
36
- test("should detect VSCodium", () => {
37
- process.env["TERM_PROGRAM"] = "vscode"
38
- process.env["GIT_ASKPASS"] = "/path/to/VSCodium.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
39
-
40
- expect(Ide.ide()).toBe("VSCodium")
41
- })
42
-
43
- test("should detect Windsurf", () => {
44
- process.env["TERM_PROGRAM"] = "vscode"
45
- process.env["GIT_ASKPASS"] = "/path/to/Windsurf.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
46
-
47
- expect(Ide.ide()).toBe("Windsurf")
48
- })
49
-
50
- test("should return unknown when TERM_PROGRAM is not vscode", () => {
51
- process.env["TERM_PROGRAM"] = "iTerm2"
52
- process.env["GIT_ASKPASS"] =
53
- "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/git/dist/askpass.sh"
54
-
55
- expect(Ide.ide()).toBe("unknown")
56
- })
57
-
58
- test("should return unknown when GIT_ASKPASS does not contain IDE name", () => {
59
- process.env["TERM_PROGRAM"] = "vscode"
60
- process.env["GIT_ASKPASS"] = "/path/to/unknown/askpass.sh"
61
-
62
- expect(Ide.ide()).toBe("unknown")
63
- })
64
-
65
- test("should recognize vscode-insiders OPENCODE_CALLER", () => {
66
- process.env["OPENCODE_CALLER"] = "vscode-insiders"
67
-
68
- expect(Ide.alreadyInstalled()).toBe(true)
69
- })
70
-
71
- test("should recognize vscode OPENCODE_CALLER", () => {
72
- process.env["OPENCODE_CALLER"] = "vscode"
73
-
74
- expect(Ide.alreadyInstalled()).toBe(true)
75
- })
76
-
77
- test("should return false for unknown OPENCODE_CALLER", () => {
78
- process.env["OPENCODE_CALLER"] = "unknown"
79
-
80
- expect(Ide.alreadyInstalled()).toBe(false)
81
- })
82
- })