@markusylisiurunen/tau 0.3.102 → 0.3.103
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/README.md +18 -23
- package/dist/core/history/migrations.js +40 -0
- package/dist/core/history/migrations.js.map +1 -1
- package/dist/core/history/setup.js +24 -7
- package/dist/core/history/setup.js.map +1 -1
- package/dist/core/mcp/cli.js +1 -1
- package/dist/core/mcp/cli.js.map +1 -1
- package/dist/core/static/tau_docs/client-tools.md +46 -385
- package/dist/core/static/tau_docs/code-mode.md +104 -43
- package/dist/core/static/tau_docs/configuration.md +77 -171
- package/dist/core/static/tau_docs/getting-started.md +25 -96
- package/dist/core/static/tau_docs/history.md +30 -228
- package/dist/core/static/tau_docs/how-tau-works.md +53 -0
- package/dist/core/static/tau_docs/image-generation.md +15 -107
- package/dist/core/static/tau_docs/index.md +46 -46
- package/dist/core/static/tau_docs/instructions-and-skills.md +81 -0
- package/dist/core/static/tau_docs/manifest.json +15 -21
- package/dist/core/static/tau_docs/mcp.md +77 -0
- package/dist/core/static/tau_docs/models-and-credentials.md +67 -0
- package/dist/core/static/tau_docs/openrouter.md +31 -129
- package/dist/core/static/tau_docs/pdf-unpacking.md +8 -21
- package/dist/core/static/tau_docs/personas.md +48 -144
- package/dist/core/static/tau_docs/remote-sessions.md +33 -170
- package/dist/core/static/tau_docs/sdk.md +150 -0
- package/dist/core/static/tau_docs/security.md +6 -193
- package/dist/core/static/tau_docs/session-protocol.md +84 -246
- package/dist/core/static/tau_docs/sessions.md +41 -205
- package/dist/core/static/tau_docs/speech-generation.md +16 -129
- package/dist/core/static/tau_docs/subagents.md +57 -229
- package/dist/core/static/tau_docs/telegram.md +152 -192
- package/dist/core/static/tau_docs/tools.md +44 -167
- package/dist/core/static/tau_docs/troubleshooting.md +23 -217
- package/dist/core/static/tau_docs/tui.md +42 -282
- package/dist/core/version.js +1 -1
- package/dist/history/worker/index.js +16 -22
- package/dist/history/worker/index.js.map +1 -1
- package/dist/history/worker/migrations/0005_external_content.sql +58 -0
- package/dist/history/worker/migrations/0006_external_content_cutover.sql +44 -0
- package/package.json +2 -2
- package/dist/core/static/tau_docs/config-reference.md +0 -367
- package/dist/core/static/tau_docs/credentials.md +0 -165
- package/dist/core/static/tau_docs/models.md +0 -57
- package/dist/core/static/tau_docs/node-sdk.md +0 -430
- package/dist/core/static/tau_docs/ownership-and-scope.md +0 -107
- package/dist/core/static/tau_docs/prompts-and-project-context.md +0 -147
- package/dist/core/static/tau_docs/sdk-diff-review.md +0 -92
- package/dist/core/static/tau_docs/session-protocol-methods.md +0 -655
- package/dist/core/static/tau_docs/skills.md +0 -135
- package/dist/core/static/tau_docs/telegram-commands.md +0 -55
- package/dist/core/static/tau_docs/telegram-projects.md +0 -197
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
# Node SDK
|
|
2
|
-
|
|
3
|
-
Tau's Node SDK is a typed client for creating, observing, and controlling sessions without handling the wire protocol yourself. Use the in-process client when your application should run the host itself, the WebSocket client to connect to a long-running `tau serve` host, or the transport adapter to bring your own connection.
|
|
4
|
-
|
|
5
|
-
The SDK speaks the same [session protocol](session-protocol.md) as the TUI, so sessions behave the same in local applications, remote integrations, and the terminal.
|
|
6
|
-
|
|
7
|
-
## Install and import
|
|
8
|
-
|
|
9
|
-
Tau requires Node.js 24 or later.
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install @markusylisiurunen/tau
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Import the SDK from its package entry point:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { createTauSdkClient } from "@markusylisiurunen/tau/sdk";
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
Tau is an ES module package.
|
|
22
|
-
|
|
23
|
-
## Choose a client
|
|
24
|
-
|
|
25
|
-
### Own an in-process host
|
|
26
|
-
|
|
27
|
-
`createTauSdkClient()` creates a local host and connects through an in-process transport:
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
const client = await createTauSdkClient({
|
|
31
|
-
persona: "gpt-6.1-sol-coder:high",
|
|
32
|
-
});
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
The host uses the current user's Tau session store and history database. The `cwd` option decides which configuration the host reads at startup, for host-wide services, and defaults to `process.cwd()`. Each session reads its own configuration and content from the execution environment and `cwd` passed to `client.sessions.create()`.
|
|
36
|
-
|
|
37
|
-
The in-process options are:
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
type TauSdkClientOptions = {
|
|
41
|
-
cwd?: string;
|
|
42
|
-
persona?: string;
|
|
43
|
-
reasoning?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
|
|
44
|
-
noAgentContextFiles?: boolean;
|
|
45
|
-
refreshModelCatalog?: boolean;
|
|
46
|
-
onDiagnostic?: (diagnostic: TauSdkHostDiagnostic) => void;
|
|
47
|
-
connectTimeoutMs?: number;
|
|
48
|
-
initialize?: { client: { name: string; version: string } };
|
|
49
|
-
clientTools?: TauSdkClientTool[];
|
|
50
|
-
};
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
`persona`, `reasoning`, and `noAgentContextFiles` apply to sessions created by this host. `persona` (an ID, optionally with `:<reasoning>`) must exist in the new session's directory, or creation fails. Recovered sessions keep their saved settings. `connectTimeoutMs` defaults to 5,000 ms. Default initialization metadata is `{ client: { name: "tau-sdk", version: "1" } }`.
|
|
54
|
-
|
|
55
|
-
The in-process host never writes background diagnostics to stdout or stderr. `onDiagnostic` receives them as structured objects. `history_recording` reports delayed, dropped, or recovered local recording, with a session ID and pending operation and byte counts. `history_replication_failed` reports remote delivery failures. Neither stops agent work; see [history](history.md) for retries and durability limits. `session_config_warnings` reports `cwd` and `warnings` when the host loads a session with invalid configuration or content. The session still starts, and an error thrown by `onDiagnostic` does not block it.
|
|
56
|
-
|
|
57
|
-
By default, an in-process client starts one background model catalog check against `pi.dev`. Each session keeps the catalog it started with until `session.reload()`. Set `refreshModelCatalog: false` to skip this client's check, or `TAU_OFFLINE` to skip automatic checks for the whole process. See [models](models.md) and [security](security.md).
|
|
58
|
-
|
|
59
|
-
Closing this client saves live sessions, shuts down its host, and cancels and waits for its catalog refresh. A refresh shared with another in-process client continues until the last of them closes.
|
|
60
|
-
|
|
61
|
-
### Connect to `tau serve`
|
|
62
|
-
|
|
63
|
-
`createTauSdkWebSocketClient()` connects to a long-running WebSocket host:
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
import { createTauSdkWebSocketClient } from "@markusylisiurunen/tau/sdk";
|
|
67
|
-
|
|
68
|
-
const client = await createTauSdkWebSocketClient({
|
|
69
|
-
url: "wss://tau.example.com",
|
|
70
|
-
authToken: process.env.TAU_WS_AUTH_TOKEN,
|
|
71
|
-
initialize: {
|
|
72
|
-
client: { name: "acme-automation", version: "1.0.0" },
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
Options are `url`, optional `authToken`, `connectTimeoutMs`, `initialize`, `clientTools`, and an optional `webSocketFactory` for runtimes that need their own WebSocket implementation. Closing the client closes only its connection; the sessions stay on the server.
|
|
78
|
-
|
|
79
|
-
The WebSocket token gives full access to all sessions. See [remote sessions](remote-sessions.md) for deployment and TLS, and [security](security.md) for the trust model.
|
|
80
|
-
|
|
81
|
-
### Supply a protocol transport
|
|
82
|
-
|
|
83
|
-
`createTauSdkClientFromTransport(transport, options?)` builds the same client on top of any `SessionProtocolTransport`, so you can use another transport with the same session behavior.
|
|
84
|
-
|
|
85
|
-
A custom transport implements:
|
|
86
|
-
|
|
87
|
-
```ts
|
|
88
|
-
type SessionProtocolTransport = {
|
|
89
|
-
readonly ready: SessionProtocolReadyMessage;
|
|
90
|
-
connect(initializeParams, timeoutMs): Promise<void>;
|
|
91
|
-
request(method, params): Promise<unknown>;
|
|
92
|
-
onDelta(listener): () => void;
|
|
93
|
-
onEphemeral(listener): () => void;
|
|
94
|
-
onPendingUserMessages(listener): () => void;
|
|
95
|
-
onSubagentActivities(listener): () => void;
|
|
96
|
-
onClientTool(listener): () => void;
|
|
97
|
-
onFailure(listener): () => void;
|
|
98
|
-
close(): Promise<void>;
|
|
99
|
-
};
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
When the transport fails for good, it must call the `onFailure` listeners, so the SDK can abort client tools and reject open requests.
|
|
103
|
-
|
|
104
|
-
## Create and run a session
|
|
105
|
-
|
|
106
|
-
A typical integration creates a session (which also observes it), listens for updates, submits work, and closes cleanly:
|
|
107
|
-
|
|
108
|
-
```ts
|
|
109
|
-
import {
|
|
110
|
-
TauSessionProtocolResponseError,
|
|
111
|
-
TauTransportError,
|
|
112
|
-
createTauSdkClient,
|
|
113
|
-
} from "@markusylisiurunen/tau/sdk";
|
|
114
|
-
|
|
115
|
-
const client = await createTauSdkClient();
|
|
116
|
-
const session = await client.sessions.create({
|
|
117
|
-
executionEnvironment: {
|
|
118
|
-
kind: "local",
|
|
119
|
-
cwd: process.cwd(),
|
|
120
|
-
},
|
|
121
|
-
attributes: {
|
|
122
|
-
source: "sdk",
|
|
123
|
-
repository: "github.com/example/atlas",
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const unsubscribe = session.onDelta((delta) => {
|
|
128
|
-
console.log(delta.sessionId, delta.fromRevision, delta.toRevision);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
const result = await session.submit("Summarize the current changes.");
|
|
133
|
-
const snapshot = await session.snapshot();
|
|
134
|
-
console.log(result.userHistoryEntryId, result.turn.status, snapshot.revision);
|
|
135
|
-
} catch (error) {
|
|
136
|
-
if (error instanceof TauSessionProtocolResponseError) {
|
|
137
|
-
console.error(error.code, error.message);
|
|
138
|
-
} else if (error instanceof TauTransportError) {
|
|
139
|
-
console.error(error.message);
|
|
140
|
-
} else {
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
} finally {
|
|
144
|
-
unsubscribe();
|
|
145
|
-
await session.unobserve();
|
|
146
|
-
await client.close();
|
|
147
|
-
}
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Creating a session requires the full execution environment and the creation attributes, which never change afterward. Tau sets the `machine` and `cwd` attributes itself and replaces any values you send for them. The `cwd` of the execution environment must be absolute and is a path in the chosen environment, which may not be where the SDK runs. A Fly Sprite session refers to an existing Sprite that the host is configured to reach. See [sessions](sessions.md) for creation attributes and [ownership and scope](ownership-and-scope.md) for which machine owns which paths.
|
|
151
|
-
|
|
152
|
-
To set the main conversation's automatic-compaction threshold at creation, pass `autoCompactThresholdTokens` as a safe integer of at least 50,000. Omit it or pass `null` to use the persona default, falling back to the model's context window minus 16,384 tokens. Applying a persona resets the threshold to `null`, even when reapplying the same persona, unless the call supplies a new threshold. The effective threshold cannot exceed this model-based limit.
|
|
153
|
-
|
|
154
|
-
Use `session.setAutoCompactThreshold(50000)` to change the threshold from the next logical turn, or `session.setAutoCompactThreshold(null)` to restore the default. Snapshot `settings` contain both `autoCompactThresholdTokens` (the configured value) and `effectiveAutoCompactThresholdTokens` (the trigger for the selected model). See [automatic compaction](sessions.md#automatic-compaction) for timing, limits, and costs.
|
|
155
|
-
|
|
156
|
-
`session.unobserve()` stops observing, and that `TauSdkSession` object can no longer be used. The session itself is not deleted. `client.close()` closes the whole client and is safe to call more than once.
|
|
157
|
-
|
|
158
|
-
The connected `TauSdkClient` exposes:
|
|
159
|
-
|
|
160
|
-
| Member | Purpose |
|
|
161
|
-
| --- | --- |
|
|
162
|
-
| `ready` | The validated server `ready` message and advertised methods. |
|
|
163
|
-
| `sessions.create(input)` | Create and observe a session, and return its object. |
|
|
164
|
-
| `sessions.list()` | List each session's `{ sessionId, lifecycle }`. |
|
|
165
|
-
| `sessions.setRetention(id, durationMs)` | [Keep a session loaded without clients](session-protocol.md#keep-a-session-loaded-without-clients), or clear with `null`. |
|
|
166
|
-
| `sessions.collect(id)` | Unload a session if nothing holds it, and return `{ disposed }`. |
|
|
167
|
-
| `sessions.observe(sessionId)` | Observe an existing session and return its object. |
|
|
168
|
-
| `subscribe(listener)` | Receive deltas for every observed session on this connection. |
|
|
169
|
-
| `subscribePendingUserMessages(listener)` | Receive pending-state replacements across observed sessions. |
|
|
170
|
-
| `subscribeSubagentActivities(listener)` | Receive subagent-activity changes across observed sessions. |
|
|
171
|
-
| `subscribeEphemeral(listener)` | Receive ephemeral events, which are not guaranteed, across observed sessions. |
|
|
172
|
-
| `close()` | Close the client and everything it owns. |
|
|
173
|
-
|
|
174
|
-
Each subscription returns an unsubscribe function.
|
|
175
|
-
|
|
176
|
-
## Use the session object
|
|
177
|
-
|
|
178
|
-
`TauSdkSession.id` is the session's ID. Each method corresponds to a protocol method; the [method reference](session-protocol-methods.md) gives exact results, turn outcomes, and when a call returns `busy` or interrupts work.
|
|
179
|
-
|
|
180
|
-
| SDK method | Purpose |
|
|
181
|
-
| --- | --- |
|
|
182
|
-
| `record(text, options?)` | Append user text without running a turn. |
|
|
183
|
-
| `submit(text, options?)` | Append user text and run an idle session turn. |
|
|
184
|
-
| `queue(text, options?)` | Run now, or after the running turn. |
|
|
185
|
-
| `steer(text)` | Change the running turn's direction at its next safe point. |
|
|
186
|
-
| `cancelPendingMessages()` | Cancel all queued messages and steering not yet applied. |
|
|
187
|
-
| `retry()` | Run from current history without appending user text. |
|
|
188
|
-
| `exec(command, options?)` | Run a command in a login Bash in the execution environment. |
|
|
189
|
-
| `sample({ context, options })` | Run a standalone model call without changing the session. |
|
|
190
|
-
| `interrupt()` | Ask the session's running work to stop. |
|
|
191
|
-
| `snapshot()` | Read the complete current snapshot. |
|
|
192
|
-
| `setAutoCompactThreshold(thresholdTokens)` | Set or reset automatic compaction, starting with the next logical turn. |
|
|
193
|
-
| `setReasoning(reasoning)` | Set reasoning, starting with the next turn. |
|
|
194
|
-
| `setPersona(personaId, overrides?)` | Atomically apply a persona, with optional `{ reasoning, autoCompactThresholdTokens }` overrides, and return the updated snapshot. Pass `null` without overrides to apply the workspace default. |
|
|
195
|
-
| `resolvePrompt(promptId)` | Load a current prompt body from the execution environment. |
|
|
196
|
-
| `autocompletePaths({ query, limit })` | Get a limited list of path suggestions from the execution environment. |
|
|
197
|
-
| `reload()` | Reload the session's configuration and content. |
|
|
198
|
-
| `compact(mode, options?)` | Manually compact model context. |
|
|
199
|
-
| `rewindToHistoryEntryId(id)` | Rewind from one user history entry while idle. |
|
|
200
|
-
| `interruptSubagent(subagentId)` | Interrupt one live subagent run. |
|
|
201
|
-
| `createEphemeralContext(options)` | Create an agent context on the host that is not saved. |
|
|
202
|
-
| `submitEphemeralThread(options)` | Run or continue one ephemeral thread. |
|
|
203
|
-
| `closeEphemeralContext(contextId)` | Close an ephemeral context and its threads. |
|
|
204
|
-
| `unobserve()` | Stop observing. |
|
|
205
|
-
|
|
206
|
-
`submit`, `queue`, and `record` accept `{ historyEntryId?: string }`; without it, Tau generates the ID. Use `getTauSdkSessionTurnRecord(snapshot, id)` to tell whether an accepted turn is unknown, running, or finished, or `getTauSdkSessionTurnOutcome(snapshot, id)` when you only need the final outcome.
|
|
207
|
-
|
|
208
|
-
`createEphemeralContext` accepts an optional `workingDirectory` for project instructions, skills, and tool defaults. Relative paths resolve against the session directory; omitting it uses the session directory. This does not change the main session.
|
|
209
|
-
|
|
210
|
-
`createEphemeralContext` and `submitEphemeralThread` accept an optional `reasoning` effort. Without it, a new context uses the session's current effort. On submission, the given effort becomes the thread's effort before the turn runs. A fork copies the source thread's effort, then applies any given effort.
|
|
211
|
-
|
|
212
|
-
### Execute a command
|
|
213
|
-
|
|
214
|
-
`exec` generates a unique execution ID for you. It supports exact positional arguments, environment variables other than `HOME`, binary stdin, a starting `cwd`, a timeout, a capture limit, and a cancellation signal:
|
|
215
|
-
|
|
216
|
-
```ts
|
|
217
|
-
const controller = new AbortController();
|
|
218
|
-
const result = await session.exec('exec "$0" "$@"', {
|
|
219
|
-
args: ["git", "status", "--short"],
|
|
220
|
-
cwd: "/srv/workspaces/atlas",
|
|
221
|
-
timeoutMs: 10_000,
|
|
222
|
-
maxCaptureBytes: 256 * 1024,
|
|
223
|
-
signal: controller.signal,
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
console.log(result.exitCode, result.output);
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
Aborting the signal cancels only this command, with `session.cancelExec`, and rejects the call. Turns and other commands keep running. The command is never added to the conversation.
|
|
230
|
-
|
|
231
|
-
### Sample a model
|
|
232
|
-
|
|
233
|
-
`sample` uses the session's current model and credentials, but only the context you supply, in Tau's provider-independent format:
|
|
234
|
-
|
|
235
|
-
```ts
|
|
236
|
-
const sampled = await session.sample({
|
|
237
|
-
context: {
|
|
238
|
-
systemPrompt: "Classify the request in one word.",
|
|
239
|
-
messages: [
|
|
240
|
-
{
|
|
241
|
-
role: "user",
|
|
242
|
-
content: [{ type: "text", text: "I cannot log in." }],
|
|
243
|
-
timestamp: Date.now(),
|
|
244
|
-
},
|
|
245
|
-
],
|
|
246
|
-
},
|
|
247
|
-
options: { reasoning: "low", maxTokens: 100 },
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
console.log(sampled.message.content);
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
You can reuse the returned assistant message in a later sample's context. If you pass tool schemas, the model may return tool calls, but Tau never runs them. Sampling sends no deltas, changes neither the snapshot revision nor the cost, and adds nothing to the conversation.
|
|
254
|
-
|
|
255
|
-
## Consume streamed state
|
|
256
|
-
|
|
257
|
-
`TauSdkClient` has subscriptions for all sessions on the connection, and `TauSdkSession` has subscriptions for one session. Prefer the session's own unless one component handles several sessions.
|
|
258
|
-
|
|
259
|
-
### Snapshot deltas
|
|
260
|
-
|
|
261
|
-
`session.onDelta(listener)` receives only that session's `TauSdkDelta` messages. Deltas that arrive before the first listener is added are kept and delivered to it. Apply them to your snapshot with `applySessionProtocolDelta`. If a revision is missing or a change is invalid, fetch a fresh copy with `session.snapshot()`.
|
|
262
|
-
|
|
263
|
-
Methods that return a full snapshot, such as reload, compact, rewind, and persona change, let the session object drop the kept deltas up to that revision. Do not replay UI effects from those dropped deltas.
|
|
264
|
-
|
|
265
|
-
### Pending input
|
|
266
|
-
|
|
267
|
-
`session.pendingUserMessages()` returns a copy of the full pending-message state. `session.onPendingUserMessages(listener)` sends the current state right away, then each newer full replacement. Its revision is separate from the snapshot's.
|
|
268
|
-
|
|
269
|
-
```ts
|
|
270
|
-
const stopPending = session.onPendingUserMessages(({ state }) => {
|
|
271
|
-
console.log(state.messages.map((message) => [message.mode, message.text]));
|
|
272
|
-
});
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
All clients observing the live session share pending input. It is empty after recovery.
|
|
276
|
-
|
|
277
|
-
### Subagent activity
|
|
278
|
-
|
|
279
|
-
`session.subagentActivities()` returns the current live activity. `session.onSubagentActivities(listener)` sends the current subagents right away as `agent.set` changes, then later replacements and removals for each subagent.
|
|
280
|
-
|
|
281
|
-
To keep your own copy, use `applySessionProtocolSubagentActivitiesMessage`. This channel has its own revision and does not replace the saved `snapshot.agents`.
|
|
282
|
-
|
|
283
|
-
### Ephemeral events
|
|
284
|
-
|
|
285
|
-
`session.onEphemeral(listener)` receives footer notices, ephemeral thread progress, and timeline notices that are not saved. Delivery is not guaranteed, and these events are never replayed or included in `session.snapshot()`.
|
|
286
|
-
|
|
287
|
-
If you show `timeline.item` events, accept only the current epoch and place each by its sequence number. Compaction and rewind causes decide which of these items you keep. The [session protocol](session-protocol.md) gives the application rules.
|
|
288
|
-
|
|
289
|
-
## Host a browser diff review
|
|
290
|
-
|
|
291
|
-
`startTauSdkDiffReview()` starts the built-in browser review UI for an observed session, without the TUI and without opening a browser. Your application can put it behind its own reverse proxy, store review state, restore earlier conversations, and receive the submitted review once through a callback.
|
|
292
|
-
|
|
293
|
-
See [SDK browser diff review](sdk-diff-review.md) for startup, storage, submission, and lifecycle.
|
|
294
|
-
|
|
295
|
-
## Provide client tools
|
|
296
|
-
|
|
297
|
-
Pass `TauSdkClientTool` entries in `clientTools` to give the model tools that run in your process:
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
import {
|
|
301
|
-
createTauSdkClient,
|
|
302
|
-
truncateTauClientToolText,
|
|
303
|
-
} from "@markusylisiurunen/tau/sdk";
|
|
304
|
-
|
|
305
|
-
const client = await createTauSdkClient({
|
|
306
|
-
clientTools: [
|
|
307
|
-
{
|
|
308
|
-
schema: {
|
|
309
|
-
name: "local_picker",
|
|
310
|
-
description: "Choose one item from the user's local workspace.",
|
|
311
|
-
parameters: {
|
|
312
|
-
type: "object",
|
|
313
|
-
properties: {
|
|
314
|
-
choice: { type: "string" },
|
|
315
|
-
},
|
|
316
|
-
required: ["choice"],
|
|
317
|
-
additionalProperties: false,
|
|
318
|
-
},
|
|
319
|
-
executionTimeoutMs: 60_000,
|
|
320
|
-
},
|
|
321
|
-
describe: (args) => {
|
|
322
|
-
const input = args as { choice: string };
|
|
323
|
-
return {
|
|
324
|
-
subject: truncateTauClientToolText(input.choice),
|
|
325
|
-
};
|
|
326
|
-
},
|
|
327
|
-
execute: async (args, context) => {
|
|
328
|
-
const input = args as { choice: string };
|
|
329
|
-
context.signal.throwIfAborted();
|
|
330
|
-
const status = await context.executionEnvironment.exec(
|
|
331
|
-
"git status --short",
|
|
332
|
-
{
|
|
333
|
-
signal: context.signal,
|
|
334
|
-
},
|
|
335
|
-
);
|
|
336
|
-
return {
|
|
337
|
-
content: status.output || "Working tree is clean.",
|
|
338
|
-
presentation: {
|
|
339
|
-
subject: truncateTauClientToolText(input.choice),
|
|
340
|
-
},
|
|
341
|
-
};
|
|
342
|
-
},
|
|
343
|
-
},
|
|
344
|
-
],
|
|
345
|
-
});
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
The handler receives `sessionId`, the calling `agentId`, `callId`, an `AbortSignal`, and the execution-environment API. The handler runs on the client machine, while `context.executionEnvironment.exec()` runs commands in the session's execution environment.
|
|
349
|
-
|
|
350
|
-
`describe` is optional. If present, the SDK calls it before accepting the call, with the arguments and a smaller context of `sessionId`, `agentId`, `callId`, and `signal`, without execution-environment access. It may return a partial presentation for the running card, with `subject`, `subjectWrap`, `details`, or `metadata`. Tau sets the action and operation, fills in omitted fields, and acknowledges with the result before calling `execute`.
|
|
351
|
-
|
|
352
|
-
The execution result may include the same partial shape for the finished card. Return a string or `{ content, presentation? }` for success, or `{ ok: false, error, presentation? }` for a handled failure. `content` may be a string, sent as one text block, or an ordered array of text and image blocks. Omitted presentation fields get Tau's defaults, and an empty `details` or `metadata` array hides that default. If `describe` throws, the SDK reports a preparation error and does not call `execute`. If no result is returned, because of cancellation, timeout, detach, or another failure, the host shows a complete default card.
|
|
353
|
-
|
|
354
|
-
Tau keeps every presentation field you set, up to the protocol limits, without truncating or normalizing it. `truncateTauClientToolText` truncates text for you by lines and characters, keeping the start or the middle. Use its result directly as a subject. For a block of detail text, split the result on `\n` and make each line one `details` entry; use `maxLines: 1` when the result goes into a single entry. The helper does not replace protocol validation. The SDK aborts handlers when the host cancels, the client closes, or the transport fails, and `client.close()` waits for running handlers to finish.
|
|
355
|
-
|
|
356
|
-
Each assistant turn keeps the tool definitions it started with. Client tools are not affected by the persona's tool list. Names must not match host tools or tools of another observing client. See [client tools](client-tools.md) for authority, limits, command-backed tools, and disconnect behavior.
|
|
357
|
-
|
|
358
|
-
### Build a code-mode tool
|
|
359
|
-
|
|
360
|
-
`createTauCodeModeClientTool()` turns an API you define into a client tool that runs one-off JavaScript programs against it:
|
|
361
|
-
|
|
362
|
-
```ts
|
|
363
|
-
import {
|
|
364
|
-
buildTauCodeModeToolDescription,
|
|
365
|
-
createTauCodeModeClientTool,
|
|
366
|
-
} from "@markusylisiurunen/tau/sdk";
|
|
367
|
-
|
|
368
|
-
const name = "tickets";
|
|
369
|
-
const tickets = createTauCodeModeClientTool({
|
|
370
|
-
name,
|
|
371
|
-
description: buildTauCodeModeToolDescription({
|
|
372
|
-
name,
|
|
373
|
-
description: "Read support tickets.",
|
|
374
|
-
}),
|
|
375
|
-
documentation: "# Tickets API\n\nUse `tickets.get(id)` to read one ticket.",
|
|
376
|
-
api: {
|
|
377
|
-
get: async ([id], { signal }) => ticketClient.get(String(id), { signal }),
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
Pass `tickets` in `clientTools`. The model's code receives your API namespace, `docs` (read on demand), `printText`, the async `printImage`, `truncate` and `truncateLines`, and the real `Date` and `Math`. API calls pass through a size-limited JSON bridge. The submitted code, truncated and wrapped, is the subject of the running and finished tool cards. You write the description; the description builder is optional.
|
|
383
|
-
|
|
384
|
-
Use `await printImage({ data, mimeType })` to return a base64 image. Results contain an ordered `content` array of text and image blocks, and SDK client tools keep that order: consecutive text output forms one block, and each image splits the text before and after it. The helper validates and prepares JPEG, PNG, or WebP images outside the sandbox, creates no files, and uses the limits described in [tools](tools.md).
|
|
385
|
-
|
|
386
|
-
Each program must finish within the definition's `timeoutMs`, which defaults to 60,000 ms and includes time spent waiting for API calls. The helper appends this deadline to the tool description so the model can see it, and uses the same value as the tool's `executionTimeoutMs`.
|
|
387
|
-
|
|
388
|
-
Code-mode calls and standalone runs accept an optional `maxOutputTokens` (1 through 65,536), with a default text budget of 8,192 tokens. Saving output to files is off unless the definition provides a `persistOutput` callback.
|
|
389
|
-
|
|
390
|
-
The SDK also exports `executeTauCodeMode` for standalone runs. The separate `@markusylisiurunen/tau/code-mode` entry point also exports `runTauClientToolCommand` and `runTauCodeModeCommand` for command tools. Use these helpers instead of implementing the protocol yourself.
|
|
391
|
-
|
|
392
|
-
## Cancel and close deliberately
|
|
393
|
-
|
|
394
|
-
Most turn and session-changing methods do not accept an `AbortSignal`. Call `session.interrupt()` to stop running work on the host. `session.exec()` is the exception: its optional signal cancels only that command.
|
|
395
|
-
|
|
396
|
-
`client.close()` ends the connection: it rejects open requests, aborts client tool handlers, waits for them to finish, and closes the transport. For the default in-process client, it also saves sessions and shuts down the host.
|
|
397
|
-
|
|
398
|
-
Always close clients in `finally`. Never use a client after `close()`.
|
|
399
|
-
|
|
400
|
-
## Handle errors
|
|
401
|
-
|
|
402
|
-
All exported SDK and transport errors extend `TauSessionClientError`:
|
|
403
|
-
|
|
404
|
-
- `TauSessionProtocolResponseError` means the host returned a protocol error. It exposes `code`, `message`, `requestId`, and optional `data`.
|
|
405
|
-
- `TauTransportError` means the connection failed: during setup, framing, version checks, a timeout, closing, or another fatal transport error.
|
|
406
|
-
|
|
407
|
-
Branch on a protocol error's `code`, not its message. A successful request can still return a failed, aborted, or blocked turn outcome, so inspect `result.turn.status` separately.
|
|
408
|
-
|
|
409
|
-
An exception in one listener does not stop delivery to others. Handle errors inside your listeners, and keep state updates deterministic.
|
|
410
|
-
|
|
411
|
-
## Use the public types and helpers
|
|
412
|
-
|
|
413
|
-
The SDK entry point exports every type an integration needs, so you never import from internal modules:
|
|
414
|
-
|
|
415
|
-
- `TauSdkClient`, `TauSdkSession`, client option types, session summaries, and request and result aliases;
|
|
416
|
-
- `TauSdkDelta`, `SessionProtocolSnapshot`, pending-message types, subagent-activity types, and ephemeral event types;
|
|
417
|
-
- `TauSdkClientTool`, its execution context and execution-environment API, and code-mode definition and result types;
|
|
418
|
-
- `SessionProtocolTransport`, listener types, WebSocket options, and transport errors.
|
|
419
|
-
|
|
420
|
-
It also exports `applySessionProtocolDelta`, `applySessionProtocolSubagentActivitiesMessage`, the turn-ledger helpers, and user-text projection helpers:
|
|
421
|
-
|
|
422
|
-
```ts
|
|
423
|
-
import {
|
|
424
|
-
getTauUserDisplayText,
|
|
425
|
-
getTauUserModelText,
|
|
426
|
-
projectTauUserText,
|
|
427
|
-
} from "@markusylisiurunen/tau/sdk";
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
Use `getTauUserDisplayText` before showing user text from a snapshot. It removes Tau metadata and leading hidden `<system>` blocks. `getTauUserModelText` removes Tau metadata but keeps the hidden blocks the model sees. `projectTauUserText` returns both. These helpers are for user messages only.
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# Ownership and scope
|
|
2
|
-
|
|
3
|
-
Tau splits a session into three parts: the terminal or other interface you use, the host that runs the session, and the machine the agent works on. They stay separate even when all three run in one process. Know which part owns a path or setting before you change it. In an attached session, “local” can mean any of three machines.
|
|
4
|
-
|
|
5
|
-
## The four operating roles
|
|
6
|
-
|
|
7
|
-
### Client
|
|
8
|
-
|
|
9
|
-
The **client** is the interface attached to a session host. The terminal client owns the TUI, editor state, terminal colors, active theme, local speech commands, the diff-review process, and configured command client tools. An SDK program or Telegram adapter can also be a client.
|
|
10
|
-
|
|
11
|
-
Client tools run on the client machine, which may differ from the machine where the agent's Bash tool runs. Client configuration is found from the client's startup working directory and home.
|
|
12
|
-
|
|
13
|
-
### Host
|
|
14
|
-
|
|
15
|
-
The **host** creates, observes, persists, and recovers sessions. It owns model calls, credentials, session orchestration, tool binding, history storage, and execution-environment lifecycle. Local `tau` creates an in-process host. `tau serve` is the standalone host entry point.
|
|
16
|
-
|
|
17
|
-
Session snapshots, authentication storage, usage logs, and the local history database live in the host user's home. Manage them with Tau commands and session operations. Do not edit their files directly.
|
|
18
|
-
|
|
19
|
-
MCP connections belong to the hosted session and end when the host unloads it. Stdio servers run on the host, with the host's credentials and access to the host's resources. They do not run in the session's execution environment. A session on a local execution environment reads its server definitions from the global and project configuration of its working directory. A session on a remote execution environment has no MCP servers.
|
|
20
|
-
|
|
21
|
-
The built-in `tau_docs` tool also belongs to the host. It reads the documentation installed with the host's Tau version.
|
|
22
|
-
|
|
23
|
-
### Execution environment
|
|
24
|
-
|
|
25
|
-
The **execution environment** is the machine the agent can act on. It owns the agent-visible working directory (`cwd`), home, platform, environment, filesystem, processes, project repository, project configuration and content, `AGENTS.md` files, skills, and command resolution.
|
|
26
|
-
|
|
27
|
-
[Claude Code subagents](subagents.md#claude-code-subagents) run their model calls here and keep their subscription login and conversation files here. The host starts, observes, and stops these workers through the execution environment. Their credentials remain with Claude Code.
|
|
28
|
-
|
|
29
|
-
Tau reads files and runs commands through the execution environment, even when it is on the same machine as the host. Each session has exactly one execution environment. Paths shown to the agent and paths passed to its tools are always paths on that environment.
|
|
30
|
-
|
|
31
|
-
### Telegram runner
|
|
32
|
-
|
|
33
|
-
The **Telegram runner** owns Telegram polling, chat routing, attachments, outbound messages, project selection, and Telegram-specific persisted runner state. It is a client of in-process Tau sessions and starts their host on the runner machine.
|
|
34
|
-
|
|
35
|
-
For repository and composite projects it prepares managed workspaces. A persistent-directory project reuses the configured directory. Each workspace becomes the local execution environment of its session. The file passed to `tau telegram --config-file` is runner configuration. It is not one of Tau's `config.json` levels.
|
|
36
|
-
|
|
37
|
-
## Where each mode runs
|
|
38
|
-
|
|
39
|
-
| Mode | Client | Host | Execution environment |
|
|
40
|
-
| --- | --- | --- | --- |
|
|
41
|
-
| `tau` | Local TUI process | In-process on the same machine | Local `cwd` where Tau started |
|
|
42
|
-
| `tau attach … ws://…` | Machine running `tau attach` | Machine running `tau serve` | Environment selected or restored by that host |
|
|
43
|
-
| `tau serve` | A separate protocol client | The server process | Local or configured hosted environment chosen by the client |
|
|
44
|
-
| Default Node SDK client | SDK caller | In-process with the SDK caller | Usually a local environment supplied at session creation |
|
|
45
|
-
| SDK over WebSocket | SDK caller | Remote server | Environment selected or restored by that host |
|
|
46
|
-
| `tau telegram` | Telegram runner | In-process on the runner machine | Prepared project workspace or persistent directory |
|
|
47
|
-
|
|
48
|
-
A Fly Sprite puts the execution environment on another machine while the host stays on its own. The host keeps the provider credentials and runs the session. The Sprite owns its paths and commands.
|
|
49
|
-
|
|
50
|
-
## Who owns common paths and behavior
|
|
51
|
-
|
|
52
|
-
| Resource or behavior | Owner | Consequence |
|
|
53
|
-
| --- | --- | --- |
|
|
54
|
-
| Agent `cwd`, home, repository, files, and commands | Execution environment | Use target paths in prompts, `session.create`, and agent tool calls. |
|
|
55
|
-
| `.tau/config.json`, personas, prompts, skills, and `AGENTS.md` used by a session | Execution environment | Edit them on the target and relative to the session `cwd`. |
|
|
56
|
-
| Global runtime content for a session | Execution-environment home | `~/.config/tau` is the target user's home when runtime content is collected. |
|
|
57
|
-
| MCP servers | Host, for local sessions | Define them in the session's project or global configuration. They run on the host with host credentials. Sessions on a remote execution environment have none. See [security](security.md#trust-mcp-servers). |
|
|
58
|
-
| Model and host-tool credentials | Host | Set environment secrets where the host process runs. API keys come from the host environment or private global host configuration. |
|
|
59
|
-
| Codex OAuth accounts | Host home | Run `tau auth …` on the host machine. Do not edit auth storage. |
|
|
60
|
-
| Session snapshots | Host home | Local defaults live under the host's Tau config directory. Do not edit session files. |
|
|
61
|
-
| Local transcript history and remote history outbox | Host home | History follows the host, not an attached TUI or execution target. |
|
|
62
|
-
| Terminal theme and `/theme` | TUI client | An attached client selects from Tau’s built-in themes. Themes are not session state. |
|
|
63
|
-
| `/diff` process | TUI client | Tau’s built-in browser tool runs on the client machine. Repository capture still runs through the session execution environment. |
|
|
64
|
-
| Configured command client tools | Owning client | Commands and their environment are on the client. File access they make on behalf of the session goes to the execution environment. |
|
|
65
|
-
| `/listen` and `/speak` capture or playback | TUI client | Required programs, devices, and media credentials belong on the client machine. |
|
|
66
|
-
| Speech vocabulary | Session, plus client global terms | Project terms come from the session's working directory. The transcribing client adds terms from its own global configuration. |
|
|
67
|
-
| Host execution-environment targets | Host startup | Fly Sprite connection settings must be in the host's configuration before it accepts sessions that use them. |
|
|
68
|
-
| Telegram bot token, bot environment, routing, workspaces, and generated runner state | Telegram runner | Manage these through the Telegram config and runner commands, not project `config.json`. |
|
|
69
|
-
|
|
70
|
-
## Decide where to edit configuration
|
|
71
|
-
|
|
72
|
-
Start from the behavior that consumes the setting:
|
|
73
|
-
|
|
74
|
-
1. If it changes what the agent sees or can do in the project, or the project's speech vocabulary, edit configuration or content in the execution environment's discovery path.
|
|
75
|
-
2. If it changes the TUI's theme, voice, recording shortcut, personal speech vocabulary, or command client tools, edit the TUI client's configuration and restart that client.
|
|
76
|
-
3. If it changes credentials, session storage, remote history, or hosted execution environment connections, set it for the host process and restart the host when required.
|
|
77
|
-
4. If it changes Telegram routing, bot startup settings, bot environments, presets, or workspace preparation, edit the runner's `--config-file` on the runner machine.
|
|
78
|
-
|
|
79
|
-
For a local `tau` session these locations are often the same home and repository. Following the ownership rule anyway means the configuration still works when the session becomes remote.
|
|
80
|
-
|
|
81
|
-
## A remote configuration example
|
|
82
|
-
|
|
83
|
-
Suppose a laptop runs:
|
|
84
|
-
|
|
85
|
-
```sh
|
|
86
|
-
tau attach --new --cwd /srv/ledger ws://devbox.example:8787
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
The host and its local execution environment resolve `/srv/ledger`. Project personas and `.tau/config.json` are read from `/srv/ledger` and its parent directories on `devbox.example`. The laptop's current directory has no effect on the session.
|
|
90
|
-
|
|
91
|
-
The laptop still loads its own theme and command client tools before attaching. `/diff` launches Tau’s built-in browser tool on the laptop. Git snapshot commands for the review run through the session and therefore see `/srv/ledger` on the execution environment.
|
|
92
|
-
|
|
93
|
-
The host on `devbox.example` makes the model calls, so it needs the provider credential. Export the provider's environment variable for `tau serve` there, or put the key in that host's global configuration. Setting it only in the laptop shell does not reach the remote host.
|
|
94
|
-
|
|
95
|
-
## Home has a boundary too
|
|
96
|
-
|
|
97
|
-
Tau includes global configuration only when the relevant `cwd` is the home directory or inside it. For session configuration, both the `cwd` and the home are on the execution environment. For client startup configuration, both are on the client.
|
|
98
|
-
|
|
99
|
-
This matters when a remote or hosted environment uses a project outside its home. Tau then reads project levels up to the filesystem root but does not add `~/.config/tau`, from that machine or any other.
|
|
100
|
-
|
|
101
|
-
## What `tau_docs` can and cannot tell you
|
|
102
|
-
|
|
103
|
-
`tau_docs` reads the documentation installed with the host. It can explain valid fields, paths, precedence, and supported behavior for that host's Tau version.
|
|
104
|
-
|
|
105
|
-
It cannot see effective configuration, environment variables, loaded client tools, the active TUI theme, the versions of attached clients, or files on a client machine. An attached client can run a different Tau version from the host. For client questions, use client commands and look on the client machine. For questions about the running session, use the warnings the session reports or inspect the host.
|
|
106
|
-
|
|
107
|
-
See [configuration](configuration.md) for level discovery and change boundaries, [remote sessions](remote-sessions.md) for attach and server operation, and [security](security.md) for trust implications.
|