@farero-ai/agent-runner 0.0.0-stage → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +170 -2
- package/dist/index.d.ts +1417 -0
- package/dist/index.js +69 -0
- package/package.json +27 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adluna AS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,171 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Agent runner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Claude Code and Codex chats for a desktop app. Each transcript stays in a SQLite file on the person's computer. Farero runs its own Claude and Codex chats with these drivers. Other apps install the published build, `@farero-ai/agent-runner`.
|
|
4
|
+
|
|
5
|
+
From the Farero checkout, `yarn pack:agent-runner` writes `output/farero-ai-agent-runner-<version>.tgz`. A push to Farero's main branch that changes the packed files publishes the next patch release to npm. A change that breaks callers raises the minor version in this package's `package.json`. The package needs Node 22.13 or later, or an Electron main process with that Node.
|
|
6
|
+
|
|
7
|
+
## Start the runtime
|
|
8
|
+
|
|
9
|
+
Open one runtime in the main process and close it when the app quits.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import path from 'node:path'
|
|
13
|
+
import { app } from 'electron'
|
|
14
|
+
import { AgentRuntime } from '@farero-ai/agent-runner'
|
|
15
|
+
|
|
16
|
+
const runtime = await AgentRuntime.open({
|
|
17
|
+
directory: path.join(app.getPath('userData'), 'agents'),
|
|
18
|
+
harness: { claude: { permissionMode: 'default' } }
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
app.on('will-quit', () => {
|
|
22
|
+
void runtime.close()
|
|
23
|
+
})
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The runtime keeps its store in `directory/agent-runner.sqlite`, with file mode 0600. A chat without a `cwd` works in `directory/workspace`. The runtime sends transcripts nowhere else. It refuses a store file that another store wrote, such as an earlier app transcript database with other tables.
|
|
27
|
+
|
|
28
|
+
By default the runtime finds `claude` and `codex` on PATH and in the usual install folders: Homebrew, `~/.local/bin`, nvm, Volta and Codex.app. For Claude Code it also tries the binary that ships with `@anthropic-ai/claude-agent-sdk`, from `app.asar.unpacked` in a packaged Electron app. The provider gets a minimal environment. Pass `envKeys` in a provider's harness settings to let a variable such as `ANTHROPIC_API_KEY` through.
|
|
29
|
+
|
|
30
|
+
The harness defaults ask the person before tools run: Claude Code starts in `default` permission mode, and Codex in the `workspace-write` sandbox with `on-request` approvals. A setting you pass replaces its default. A setting you leave out, or pass as `undefined`, keeps it. Claude Code's web search and web fetch run without asking, as they do in Farero. List them in `disallowedTools` to turn them off.
|
|
31
|
+
|
|
32
|
+
## Run a chat
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const chat = await runtime.start({
|
|
36
|
+
provider: 'claude',
|
|
37
|
+
title: 'Release notes',
|
|
38
|
+
prompt: 'Summarise the last ten commits'
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
await runtime.send(chat.id, 'Make it shorter')
|
|
42
|
+
await runtime.stop(chat.id)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`start` stores the chat with its first prompt and returns. The reply arrives as changes. `send` refuses while a turn runs. `stop` asks the provider to stop the turn. When the provider does not stop within two seconds, the runtime closes its process.
|
|
46
|
+
|
|
47
|
+
`list()` returns the chats, the one with the newest activity first. Each chat has a `status`: `idle`, `running`, `waiting` while the provider waits for an answer, or `error`. Its `error` holds the reason.
|
|
48
|
+
|
|
49
|
+
The runtime keeps one provider process for each open chat and resumes the chat's provider thread when it starts a new one. A process that sits idle for ten minutes closes.
|
|
50
|
+
|
|
51
|
+
## Follow a chat's changes
|
|
52
|
+
|
|
53
|
+
Every write to the store takes the next value of one store-wide counter and stamps it on each chat and entry it changes. A chat's revision is the newest of those stamps.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
let revision = 0
|
|
57
|
+
let entries = new Map<string, TranscriptEntry>()
|
|
58
|
+
|
|
59
|
+
function load(chatId: string) {
|
|
60
|
+
const read = runtime.read(chatId)
|
|
61
|
+
if (!read) return
|
|
62
|
+
entries = new Map(read.entries.map(entry => [entry.id, entry]))
|
|
63
|
+
revision = read.revision
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
runtime.subscribe(change => {
|
|
67
|
+
if (change.chatId !== openChatId || change.revision <= revision) return
|
|
68
|
+
const changed = runtime.changes(openChatId, revision)
|
|
69
|
+
if (!changed) return
|
|
70
|
+
for (const entry of changed.entries) entries.set(entry.id, entry)
|
|
71
|
+
for (const id of changed.removed) entries.delete(id)
|
|
72
|
+
revision = changed.revision
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- `read(chatId)` returns `{ chat, entries, interactions, revision }` from one read transaction.
|
|
77
|
+
- `changes(chatId, after)` returns the chat when it changed after `after`, the listed entries that changed after it in the order they changed, the ids in `removed` of entries that are no longer listed, and the new `revision`. A page that kept a revision catches up after a reload with one call.
|
|
78
|
+
- `subscribe(listener)` calls the listener with `{ chatId, revision }` after each write commits, in commit order. A page that reads during the call sees the change. A listener that throws stops neither the turn nor the other listeners.
|
|
79
|
+
|
|
80
|
+
Entries are Farero's `TranscriptEntry` rows, keyed by `id`. `rowid` is a stable anchor and `revision` counts the writes to the row. `@farero-ai/ui` draws them with `ReadOnlyTranscript`. The store applies Farero's entry rules: tool text has a budget of 1 MiB, provider bookkeeping stays out of the list, and a stream item that the provider replaced stays out of the list.
|
|
81
|
+
|
|
82
|
+
When the app opens a runtime after a crash, a chat that was running opens with status `error` and an interrupted message. Its open draft and tool rows close. The runtime never sends a prompt again by itself: a provider may already have taken it in. The person decides whether to send it again.
|
|
83
|
+
|
|
84
|
+
## Approvals and questions
|
|
85
|
+
|
|
86
|
+
A provider that asks for an approval or a question adds it to the chat's `interactions`, and the chat's status becomes `waiting`. Show them to the person and answer with `answer`:
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
await runtime.answer(chat.id, interaction.id, { decision: 'accept' })
|
|
90
|
+
await runtime.answer(chat.id, question.id, { answers: { [question.questions[0].id]: ['Ship it'] } })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
An approval lists its `decisions`, for example `accept` and `decline`. A question lists its `questions`, and the answer maps the `id` of each question to the chosen options.
|
|
94
|
+
|
|
95
|
+
To answer some requests without the person, pass `decide`. Return `undefined` to leave a request for the person. The signal aborts when the request closes another way.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
const runtime = await AgentRuntime.open({
|
|
99
|
+
directory,
|
|
100
|
+
decide: async (chatId, interaction, signal) =>
|
|
101
|
+
interaction.kind === 'approval' && allowedTool(interaction) ? { decision: 'accept' } : undefined
|
|
102
|
+
})
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Give the agent your tools
|
|
106
|
+
|
|
107
|
+
`serveTools` serves your tools as an MCP server on 127.0.0.1. Hand it to each chat through `connection`:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { AgentRuntime, serveTools } from '@farero-ai/agent-runner'
|
|
111
|
+
|
|
112
|
+
const tools = await serveTools({
|
|
113
|
+
tools: [
|
|
114
|
+
{
|
|
115
|
+
name: 'post_message',
|
|
116
|
+
description: 'Post a message to a Team channel',
|
|
117
|
+
inputSchema: {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: { channel_id: { type: 'string' }, body: { type: 'string' }, client_id: { type: 'string' } },
|
|
120
|
+
required: ['channel_id', 'body', 'client_id']
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
call: async ({ chatId, name, args, signal }) => ({
|
|
125
|
+
content: [{ type: 'text', text: JSON.stringify(await team.call(chatId, name, args, signal)) }]
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const runtime = await AgentRuntime.open({
|
|
130
|
+
directory,
|
|
131
|
+
connection: chatId => ({
|
|
132
|
+
mcpServers: { spool_team: { url: tools.url, headers: tools.headers(chatId) } }
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
`headers(chatId)` gives each chat its own bearer token, so `call` learns which chat called and one chat cannot act as another. Close the server with `tools.close()` after the runtime.
|
|
138
|
+
|
|
139
|
+
A tool with side effects needs an idempotency argument, as Farero's own tools take `client_id`. A provider can repeat a call after a lost reply. The same id must return the first result and not do the work again.
|
|
140
|
+
|
|
141
|
+
`connection` can also return `localMcpServers` for stdio servers, `instructions` for the agent's system prompt and `toolEnvironment` for variables that every tool command sees. The runtime reads it each time a chat's provider starts.
|
|
142
|
+
|
|
143
|
+
## Connection status
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
const status = await runtime.connectionStatus('claude')
|
|
147
|
+
// { state: 'ready', message: 'Claude Code is signed in.', method: 'claude.ai' }
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`state` is `ready`, `missing`, `sign-in` or `unavailable`, and `message` is one sentence for the person. `method` says how the person signed in, so an app can require a plan sign-in instead of an API key.
|
|
151
|
+
|
|
152
|
+
## A host of your own
|
|
153
|
+
|
|
154
|
+
The drivers reach the computer through a `DriverHost`. `localHost()` is the default. Pass `host` to `AgentRuntime.open` to change how a provider is found and started:
|
|
155
|
+
|
|
156
|
+
```ts
|
|
157
|
+
import { localHost } from '@farero-ai/agent-runner'
|
|
158
|
+
|
|
159
|
+
const runtime = await AgentRuntime.open({
|
|
160
|
+
directory,
|
|
161
|
+
host: localHost({ searchPaths: [path.join(process.resourcesPath, 'bin')] })
|
|
162
|
+
})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
A host has `launch(provider, settings)`, which returns the command and the executable it found, `notInstalled(provider, source)`, `environment({ provider, workspaceEnv, accountHome, envKeys })`, `mcpStartupMs` and `clientInfo`, the name Codex's app-server gets for the app. Pass `localHost({ clientInfo: { name: 'spool', title: 'Spool', version } })` to keep your app's name. Pass `drivers` to run a provider with another `NativeDriverFactory`.
|
|
166
|
+
|
|
167
|
+
## Work on the package in Farero
|
|
168
|
+
|
|
169
|
+
Farero imports the TypeScript source through `@farero/agent-runner/<path>`, for example `@farero/agent-runner/providers/claude`. Its runtime passes Farero's own host, `src/host/driver-host.ts`, and its Docker sandboxes satisfy `ClaudeSandbox` and `CodexSandbox`. `yarn build:node` compiles the package into Farero's bundles.
|
|
170
|
+
|
|
171
|
+
The package reads Farero's protocol modules in `src/` and nothing from `src/host/` or `web/`. It holds no Farero app state: Farero's store stays in Farero, because it commits transcript rows in the same transaction as delivery receipts. `yarn check:imports` enforces the boundary. The tarball holds one ESM entry and its bundled types, with Farero's protocol modules compiled in. Its npm dependencies keep Farero's versions.
|