@markusylisiurunen/tau 0.3.111 → 0.3.113

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 (200) hide show
  1. package/dist/code_mode/command.d.ts +1 -1
  2. package/dist/code_mode/command.js +2 -28
  3. package/dist/code_mode/command.js.map +1 -1
  4. package/dist/code_mode/errors.d.ts +3 -0
  5. package/dist/code_mode/errors.js +4 -0
  6. package/dist/code_mode/errors.js.map +1 -0
  7. package/dist/code_mode/images.js +10 -2
  8. package/dist/code_mode/images.js.map +1 -1
  9. package/dist/code_mode/index.d.ts +2 -2
  10. package/dist/code_mode/index.js +1 -1
  11. package/dist/code_mode/index.js.map +1 -1
  12. package/dist/code_mode/runtime.d.ts +40 -18
  13. package/dist/code_mode/runtime.js +139 -162
  14. package/dist/code_mode/runtime.js.map +1 -1
  15. package/dist/code_mode/wire.d.ts +2 -0
  16. package/dist/code_mode/wire.js +64 -0
  17. package/dist/code_mode/wire.js.map +1 -0
  18. package/dist/core/agent/capabilities.js +68 -0
  19. package/dist/core/agent/capabilities.js.map +1 -0
  20. package/dist/core/agent/notification_inbox.js +6 -6
  21. package/dist/core/agent/notification_inbox.js.map +1 -1
  22. package/dist/core/code_mode/agents.js +104 -477
  23. package/dist/core/code_mode/agents.js.map +1 -1
  24. package/dist/core/code_mode/bash.js +49 -238
  25. package/dist/core/code_mode/bash.js.map +1 -1
  26. package/dist/core/code_mode/files.js +66 -0
  27. package/dist/core/code_mode/files.js.map +1 -0
  28. package/dist/core/code_mode/history.js +7 -38
  29. package/dist/core/code_mode/history.js.map +1 -1
  30. package/dist/core/code_mode/mcp.js +59 -110
  31. package/dist/core/code_mode/mcp.js.map +1 -1
  32. package/dist/core/code_mode/models.js +87 -269
  33. package/dist/core/code_mode/models.js.map +1 -1
  34. package/dist/core/code_mode/notifications.js +20 -0
  35. package/dist/core/code_mode/notifications.js.map +1 -0
  36. package/dist/core/code_mode/package.js +37 -0
  37. package/dist/core/code_mode/package.js.map +1 -0
  38. package/dist/core/code_mode/web.js +50 -140
  39. package/dist/core/code_mode/web.js.map +1 -1
  40. package/dist/core/config/content_loader.js +5 -76
  41. package/dist/core/config/content_loader.js.map +1 -1
  42. package/dist/core/config/index.js +1 -1
  43. package/dist/core/config/index.js.map +1 -1
  44. package/dist/core/config/schema.js +3 -0
  45. package/dist/core/config/schema.js.map +1 -1
  46. package/dist/core/debug.js +11 -16
  47. package/dist/core/debug.js.map +1 -1
  48. package/dist/core/diff_review/review_instructions.js +1 -1
  49. package/dist/core/diff_review/review_instructions.js.map +1 -1
  50. package/dist/core/mcp/manager.js.map +1 -1
  51. package/dist/core/models/openrouter.js +33 -12
  52. package/dist/core/models/openrouter.js.map +1 -1
  53. package/dist/core/modes/run.js +1 -0
  54. package/dist/core/modes/run.js.map +1 -1
  55. package/dist/core/personas.js +112 -53
  56. package/dist/core/personas.js.map +1 -1
  57. package/dist/core/runtime/chat_runtime.js +16 -1
  58. package/dist/core/runtime/chat_runtime.js.map +1 -1
  59. package/dist/core/runtime/model_prompt_notes.js +1 -1
  60. package/dist/core/runtime/model_prompt_notes.js.map +1 -1
  61. package/dist/core/runtime/session_prompt_composer.js +20 -12
  62. package/dist/core/runtime/session_prompt_composer.js.map +1 -1
  63. package/dist/core/static/code_mode/docs/agents.md +131 -0
  64. package/dist/core/static/code_mode/docs/bash.md +74 -0
  65. package/dist/core/static/code_mode/docs/core.md +67 -0
  66. package/dist/core/static/code_mode/docs/examples.md +135 -0
  67. package/dist/core/static/code_mode/docs/files.md +38 -0
  68. package/dist/core/static/code_mode/docs/history.md +104 -0
  69. package/dist/core/static/code_mode/docs/mcp.md +109 -0
  70. package/dist/core/static/code_mode/docs/models.md +104 -0
  71. package/dist/core/static/code_mode/docs/notifications.md +29 -0
  72. package/dist/core/static/code_mode/docs/web.md +100 -0
  73. package/dist/core/static/code_mode/modules.mjs +67 -0
  74. package/dist/core/static/code_mode/sandbox_runner.mjs +66 -121
  75. package/dist/core/static/index.js +3 -3
  76. package/dist/core/static/index.js.map +1 -1
  77. package/dist/core/static/prompts/subagent-prefix.md +1 -1
  78. package/dist/core/static/tau_docs/client-tools.md +1 -1
  79. package/dist/core/static/tau_docs/code-mode.md +16 -124
  80. package/dist/core/static/tau_docs/history.md +2 -2
  81. package/dist/core/static/tau_docs/index.md +1 -1
  82. package/dist/core/static/tau_docs/mcp.md +1 -1
  83. package/dist/core/static/tau_docs/models-and-credentials.md +1 -1
  84. package/dist/core/static/tau_docs/personas.md +3 -15
  85. package/dist/core/static/tau_docs/sdk.md +7 -2
  86. package/dist/core/static/tau_docs/sessions.md +1 -1
  87. package/dist/core/static/tau_docs/subagents.md +7 -20
  88. package/dist/core/static/tau_docs/tools.md +8 -18
  89. package/dist/core/static/tau_docs/troubleshooting.md +1 -1
  90. package/dist/core/subagents/agent_supervisor.js +11 -10
  91. package/dist/core/subagents/agent_supervisor.js.map +1 -1
  92. package/dist/core/subagents/claude_code_models.js +10 -0
  93. package/dist/core/subagents/claude_code_models.js.map +1 -1
  94. package/dist/core/subagents/claude_code_protocol.js +1 -1
  95. package/dist/core/subagents/claude_code_protocol.js.map +1 -1
  96. package/dist/core/subagents/claude_code_runner.js +26 -26
  97. package/dist/core/subagents/claude_code_runner.js.map +1 -1
  98. package/dist/core/subagents/claude_code_runner.mjs +76 -74
  99. package/dist/core/subagents/claude_code_runtime.js +1 -1
  100. package/dist/core/subagents/format.js +1 -1
  101. package/dist/core/subagents/format.js.map +1 -1
  102. package/dist/core/subagents/native_subagent_runtime.js +30 -14
  103. package/dist/core/subagents/native_subagent_runtime.js.map +1 -1
  104. package/dist/core/subagents/prompt.js.map +1 -1
  105. package/dist/core/subagents/registry.js +6 -41
  106. package/dist/core/subagents/registry.js.map +1 -1
  107. package/dist/core/subagents/runtime.js.map +1 -1
  108. package/dist/core/subagents/trace.js +6 -4
  109. package/dist/core/subagents/trace.js.map +1 -1
  110. package/dist/core/subagents/types.js +1 -12
  111. package/dist/core/subagents/types.js.map +1 -1
  112. package/dist/core/tool/openrouter.js +9 -2
  113. package/dist/core/tool/openrouter.js.map +1 -1
  114. package/dist/core/tools/background_jobs.js +1 -1
  115. package/dist/core/tools/background_jobs.js.map +1 -1
  116. package/dist/core/tools/bash_jobs.js +11 -0
  117. package/dist/core/tools/bash_jobs.js.map +1 -1
  118. package/dist/core/tools/catalog.js +24 -40
  119. package/dist/core/tools/catalog.js.map +1 -1
  120. package/dist/core/tools/code.js +96 -108
  121. package/dist/core/tools/code.js.map +1 -1
  122. package/dist/core/tools/code_jobs.js +5 -5
  123. package/dist/core/tools/code_jobs.js.map +1 -1
  124. package/dist/core/tools/code_mode.js +79 -108
  125. package/dist/core/tools/code_mode.js.map +1 -1
  126. package/dist/core/tools/code_mode_worker.js +14 -42
  127. package/dist/core/tools/code_mode_worker.js.map +1 -1
  128. package/dist/core/tools/code_modules.js +21 -0
  129. package/dist/core/tools/code_modules.js.map +1 -0
  130. package/dist/core/tools/edit.js +6 -24
  131. package/dist/core/tools/edit.js.map +1 -1
  132. package/dist/core/tools/execution_backend.js +13 -6
  133. package/dist/core/tools/execution_backend.js.map +1 -1
  134. package/dist/core/tools/file_edits.js +17 -0
  135. package/dist/core/tools/file_edits.js.map +1 -0
  136. package/dist/core/tools/tool_names.js +2 -12
  137. package/dist/core/tools/tool_names.js.map +1 -1
  138. package/dist/core/tools/wait_for_agents.js +8 -2
  139. package/dist/core/tools/wait_for_agents.js.map +1 -1
  140. package/dist/core/types.js.map +1 -1
  141. package/dist/core/utils/context.js +1 -1
  142. package/dist/core/utils/context.js.map +1 -1
  143. package/dist/core/utils/context_builder.js +16 -2
  144. package/dist/core/utils/context_builder.js.map +1 -1
  145. package/dist/core/version.js +1 -1
  146. package/dist/diff_tool/app/dist/assets/{core-D5eeuYMf.js → core-BfpRGcqe.js} +1 -1
  147. package/dist/diff_tool/app/dist/assets/engine-oniguruma-D_AXpl2k.js +1 -0
  148. package/dist/diff_tool/app/dist/assets/{highlights-6TYlERwf.js → highlights-CLc_g6m8.js} +1 -1
  149. package/dist/diff_tool/app/dist/assets/{index-DHhgT2Y7.js → index-bu2WOD1Y.js} +37 -37
  150. package/dist/diff_tool/app/dist/assets/langs-DO7BJV2U.js +1 -0
  151. package/dist/diff_tool/app/dist/assets/{shiki-CNf9g2mc.js → shiki-r9Q4gIo6.js} +2 -2
  152. package/dist/diff_tool/app/dist/assets/{stream-tokenizer-0Xi4Io-I.js → stream-tokenizer-bgeDT4xc.js} +1 -1
  153. package/dist/diff_tool/app/dist/assets/{themes-QMIFS5bl.js → themes-h4OE3MIe.js} +2 -2
  154. package/dist/diff_tool/app/dist/index.html +1 -1
  155. package/dist/execution/fly_sprite_execution_environment.js +17 -13
  156. package/dist/execution/fly_sprite_execution_environment.js.map +1 -1
  157. package/dist/host/execution_runtime.js +4 -3
  158. package/dist/host/execution_runtime.js.map +1 -1
  159. package/dist/host/hosted_ephemeral_agent_session.js +24 -4
  160. package/dist/host/hosted_ephemeral_agent_session.js.map +1 -1
  161. package/dist/host/local_session_host.js +20 -15
  162. package/dist/host/local_session_host.js.map +1 -1
  163. package/dist/host/session_protocol_handler.js +0 -1
  164. package/dist/host/session_protocol_handler.js.map +1 -1
  165. package/dist/protocol/index.d.ts +1 -1
  166. package/dist/protocol/index.js.map +1 -1
  167. package/dist/protocol/session_protocol.d.ts +0 -3
  168. package/dist/protocol/session_protocol.js +3 -14
  169. package/dist/protocol/session_protocol.js.map +1 -1
  170. package/dist/sdk/code_mode.d.ts +6 -0
  171. package/dist/sdk/code_mode.js +16 -7
  172. package/dist/sdk/code_mode.js.map +1 -1
  173. package/dist/sdk/diff_review.js +0 -1
  174. package/dist/sdk/diff_review.js.map +1 -1
  175. package/dist/sdk/index.d.ts +1 -1
  176. package/dist/sdk/index.js.map +1 -1
  177. package/dist/sdk/session.js +3 -1
  178. package/dist/sdk/session.js.map +1 -1
  179. package/dist/sdk/session_tool_execution_backend.d.ts +1 -1
  180. package/dist/sdk/session_tool_execution_backend.js +11 -2
  181. package/dist/sdk/session_tool_execution_backend.js.map +1 -1
  182. package/dist/sdk/types.d.ts +1 -3
  183. package/dist/store/session_snapshot_migrations.js +3 -23
  184. package/dist/store/session_snapshot_migrations.js.map +1 -1
  185. package/dist/tui/session_chat_controller.js +0 -1
  186. package/dist/tui/session_chat_controller.js.map +1 -1
  187. package/package.json +7 -7
  188. package/dist/core/code_mode/capability.js +0 -2
  189. package/dist/core/code_mode/capability.js.map +0 -1
  190. package/dist/core/code_mode/sdk.js +0 -60
  191. package/dist/core/code_mode/sdk.js.map +0 -1
  192. package/dist/core/static/code_mode/history/documentation.md +0 -154
  193. package/dist/core/static/code_mode/mcp/documentation.md +0 -281
  194. package/dist/core/static/code_mode/web/documentation.md +0 -161
  195. package/dist/core/tools/code_preloads.js +0 -94
  196. package/dist/core/tools/code_preloads.js.map +0 -1
  197. package/dist/core/tools/notifications.js +0 -87
  198. package/dist/core/tools/notifications.js.map +0 -1
  199. package/dist/diff_tool/app/dist/assets/engine-oniguruma-GMuLvN-e.js +0 -1
  200. package/dist/diff_tool/app/dist/assets/langs-7ebL77Wr.js +0 -1
@@ -1,12 +1,14 @@
1
1
  import { resolve } from "node:path";
2
2
  import { z } from "zod";
3
+ import { requireCapability, } from "../agent/capabilities.js";
3
4
  import { getEffectiveAutoCompactThresholdTokens } from "../session/auto_compaction_threshold.js";
5
+ import { opusPreset } from "../subagents/claude_code_models.js";
4
6
  import { AgentRequestError } from "../subagents/errors.js";
5
7
  import { parseSubagentLaunchModel } from "../subagents/launch_model.js";
6
8
  import { describeSubagentLaunchChoices, resolveSubagentEffectiveSettings, } from "../subagents/registry.js";
9
+ import { definePackage, method } from "./package.js";
7
10
  const id = z.string().min(1).max(256);
8
- const idOptions = z.strictObject({ id });
9
- const message = z
11
+ const workerMessage = z
10
12
  .string()
11
13
  .trim()
12
14
  .min(1)
@@ -18,16 +20,15 @@ const spawnOptions = z.strictObject({
18
20
  .min(1)
19
21
  .max(512)
20
22
  .regex(/^[^\r\n]+$/),
21
- prompt: message,
22
23
  model: z.string().min(1).optional(),
23
24
  workingDirectory: z
24
25
  .string()
25
26
  .min(1)
26
27
  .regex(/^[^\r\n]+$/)
27
28
  .optional(),
29
+ notifyOnCompletion: z.boolean().optional(),
28
30
  });
29
31
  const traceOptions = z.strictObject({
30
- id,
31
32
  kinds: z
32
33
  .array(z.enum(["input", "assistant", "tool_call", "tool_result", "notice", "status"]))
33
34
  .max(6)
@@ -36,392 +37,69 @@ const traceOptions = z.strictObject({
36
37
  limit: z.number().int().min(1).max(50).optional(),
37
38
  cursor: z.string().max(4096).optional(),
38
39
  });
39
- export const agentsCapabilityMetadata = {
40
- name: "agents",
41
- description: "Inspect allowed launch models and capacity, start delegated workers, send them queued or steering input, interrupt and wait for them, and read selected parts of their conversations. Access covers the workers you started and the workers they started. Follow the delegation policy in your instructions. Workers keep running when a program ends or is cancelled.",
42
- documentation: `# tau.agents
43
-
44
- Start general-purpose workers, send them more input, and read what they did. Start workers only when the user or active instructions explicitly ask for delegation.
45
-
46
- A worker has one conversation that grows with every input you send. Workers belong to the current session. They keep running when the program that started them ends or is cancelled, and they are lost when the session ends or Tau restarts. Results you need later must reach your conversation or a file before then.
47
-
48
- Reading data into the program does not add it to your conversation. Only what you print does, so select and print the parts you need.
49
-
50
- ## Worker levels and access
51
-
52
- Workers can go two levels below the main agent. A worker that the main agent starts has depth 1, and a worker started by a depth 1 worker has depth 2. Depth 2 workers and Claude Code workers cannot start workers, so they have no \`tau.agents\`.
53
-
54
- \`\`\`text
55
- main
56
- ├── A (depth 1)
57
- │ ├── B (depth 2)
58
- │ └── C (depth 2)
59
- └── D (depth 1)
60
- \`\`\`
61
-
62
- Every method covers your descendants: the workers you started and the workers they started. Here the main agent can reach all four workers, A can reach B and C, and D can reach none of them. Any other ID fails with \`unknown_agent\`. That includes your own ID and the IDs of siblings and ancestors.
63
-
64
- A worker's tools let it delegate, but it should start workers only when it is asked to. If you want a worker to delegate, say so in its prompt.
65
-
66
- ## Interface
67
-
68
- \`\`\`ts
69
- type AgentsApi = {
70
- launchOptions(): Promise<AgentLaunchOptions>;
71
- spawn(options: SpawnOptions): Promise<AgentState>;
72
- list(): Promise<ListResult>;
73
- read(options: { id: string }): Promise<AgentState>;
74
- sendInput(options: SendInputOptions): Promise<AgentState>;
75
- interrupt(options: InterruptOptions): Promise<AgentState>;
76
- waitUntilIdle(options: { id: string }): Promise<AgentState>;
77
- trace(options: TraceOptions): Promise<TracePage>;
78
- readContent(options: ReadContentOptions): Promise<ContentPage>;
79
- readText(options: ReadTextOptions): Promise<ReadTextResult>;
80
- };
81
- \`\`\`
82
-
83
- ## Worker state
84
-
85
- \`\`\`ts
86
- type AgentState = {
87
- id: string;
88
- parentId: string; // the agent that started this worker
89
- depth: number; // 1 or 2, counted from the main agent whoever reads it
90
- title: string;
91
- model: string; // provider/model:effort
92
- workingDirectory: string;
93
- pending: { queue: number; steer: number };
94
- usage: {
95
- input: number;
96
- output: number;
97
- cacheRead: number;
98
- cacheWrite: number;
99
- contextTokens: number;
100
- contextWindow: number;
101
- cost: number;
102
- };
103
- } & (
104
- | { status: "working" | "stopping" }
105
- | { status: "idle"; reason: "completed" | "interrupted" }
106
- | { status: "idle"; reason: "failed"; error: { code: string; message: string } }
107
- );
108
- \`\`\`
109
-
110
- A worker is idle when it has no active turn and no pending input. \`reason\` tells how its latest turn ended. \`completed\` means the turn ended normally. It does not mean the task succeeded, so read the worker's answer before relying on it. A failed or interrupted turn may leave only a partial answer, or none.
111
-
112
- \`pending\` counts input awaiting delivery by Tau. Delivery to a runtime does not confirm that the worker has read it. Token counts and \`cost\` are totals for the whole conversation. \`contextTokens\` estimates the current context size.
113
-
114
- ## \`tau.agents.launchOptions()\`
115
-
116
- Takes no arguments and returns the calling agent's effective launch choices without starting a worker:
117
-
118
- \`\`\`ts
119
- type AgentLaunchOptions = {
120
- inherited: { model: string }; // provider/model:effort
121
- overrides: Array<{ model: string }>; // exact provider/model:effort strings accepted by spawn
122
- capacity: { running: number; limit: number };
123
- };
124
- \`\`\`
125
-
126
- \`inherited.model\` is used when \`spawn\` omits \`model\`; each \`overrides\` entry contains an exact model string \`spawn\` accepts. Listing does not check credentials, provider availability, or quota.
127
-
128
- \`capacity\` covers the whole session, just as in \`list()\`. It is a snapshot, not a reservation; another worker may take the last slot before you launch.
129
-
130
- ## \`tau.agents.spawn(options)\`
131
-
132
- \`\`\`ts
133
- type SpawnOptions = {
134
- title: string;
135
- prompt: string;
136
- model?: string;
137
- workingDirectory?: string;
138
- };
139
- \`\`\`
140
-
141
- - \`title\`: required single line, 1–512 characters.
142
- - \`prompt\`: required first message, at most 262,144 characters. The worker cannot see your conversation, so include everything it needs.
143
- - \`model\`: omit it to use your own model and settings. Set it only when the user or active instructions ask for a specific model; it must exactly match an allowed override from your instructions.
144
- - \`workingDirectory\`: absolute, or relative to your working directory. Defaults to your working directory.
145
-
146
- You become the new worker's parent; the options cannot choose another parent or depth. Returns as soon as the worker starts.
147
-
148
- At most 16 workers can be working at once across the whole session, at both levels. A parent waiting for its own workers counts if its turn is still active. Idle workers and the main agent do not count. When the limit is reached, the call fails right away instead of queueing, so wait for existing work or do the task yourself.
149
-
150
- ## \`tau.agents.list()\`
151
-
152
- \`\`\`ts
153
- type ListResult = {
154
- agents: AgentState[];
155
- capacity: { running: number; limit: number };
156
- };
157
- \`\`\`
158
-
159
- Lists all your descendants as a flat list, including idle ones. Use \`parentId\` and \`depth\` to see how they relate. \`capacity\` covers the whole session, so \`running\` can include workers you cannot reach.
160
-
161
- ## \`tau.agents.read(options)\`
162
-
163
- Returns one worker's current state.
164
-
165
- ## \`tau.agents.sendInput(options)\`
166
-
167
- \`\`\`ts
168
- type SendInputOptions = {
169
- id: string;
170
- message: string;
171
- mode: "queue" | "steer";
172
- };
173
- \`\`\`
174
-
175
- \`mode\` is required:
176
-
177
- - \`queue\`: the worker finishes its current work first, then handles the message as a separate turn. Queued messages run in the order you send them.
178
- - \`steer\`: the worker takes the message into account as soon as possible during its current turn. Use it to correct or narrow work in progress. Steering does not stop a running tool; use \`interrupt\` for that.
179
-
180
- Either mode starts a new turn right away when the worker is idle. A steering message that arrives too late for the current turn is handled in a later turn. The worker keeps its conversation, model, tools, and working directory.
181
-
182
- The call returns when the input is accepted, before the worker reads it. It fails while the worker is stopping, when 64 inputs are already pending, or when the worker is idle and 16 workers are already working.
183
-
184
- ## \`tau.agents.interrupt(options)\`
185
-
186
- \`\`\`ts
187
- type InterruptOptions = { id: string; wait?: boolean; scope?: "agent" | "subtree" };
188
- \`\`\`
189
-
190
- Stops the current turn and discards all pending input, so the worker does not continue with queued work.
191
-
192
- - \`scope: "agent"\` (default): stops only the selected worker. Its descendants keep running. Interrupting an idle worker only returns its state.
193
- - \`scope: "subtree"\`: stops the selected worker and all its descendants, even when the selected worker is already idle. Until they have all stopped, those workers refuse new input, and any worker they were starting fails to launch.
194
-
195
- With the default \`wait: true\`, the call returns after every targeted turn has ended. With \`wait: false\`, it returns right away, and the status may still be \`stopping\`. If the program's deadline passes first, the workers still stop, but the call does not confirm it. The result is the selected worker's state only; read or list the others to see theirs.
196
-
197
- Background Bash and code jobs that the workers started keep running. The workers stay available for more input.
198
-
199
- ## \`tau.agents.waitUntilIdle(options)\`
200
-
201
- Waits until the worker has no active turn and no pending input, then returns its state. This includes queued messages. It returns immediately for an idle worker. A failed or interrupted worker returns idle state; the call does not throw for it. The wait does not include background jobs the worker started or the worker's descendants, so a parent can be idle while its own workers are still working. Wait for those by ID if you need them.
202
-
203
- Cancelling the wait, for example when the program stops, leaves the worker running. Wait for several workers with \`Promise.all\`. The call returns state only; read the answer with \`trace\` and \`readText\`. Outside a program, use the \`wait_for_agents\` tool, which also returns each idle worker's latest answer.
204
-
205
- An idle state is an observation at one moment. Another caller can send the worker new input afterwards.
206
-
207
- ## \`tau.agents.trace(options)\`
208
-
209
- Reads a page of the worker's conversation.
210
-
211
- \`\`\`ts
212
- type TraceOptions = {
213
- id: string;
214
- kinds?: TraceKind[];
215
- toolName?: string;
216
- limit?: number;
217
- cursor?: string;
218
- };
219
-
220
- type TracePage = {
221
- entries: TraceEntry[];
222
- nextCursor: string | null;
223
- historyEvicted: boolean;
224
- };
225
-
226
- type TraceEntry = { seq: number; timestamp: number } & (
227
- | { kind: "input"; mode: "initial" | "queue" | "steer"; content: Content }
228
- | { kind: "assistant"; content: Content }
229
- | { kind: "tool_call"; callId: string; toolName: string; arguments: Content }
230
- | {
231
- kind: "tool_result";
232
- callId: string;
233
- toolName: string;
234
- outcome: "succeeded" | "failed" | "blocked" | "cancelled";
235
- content: Content;
236
- }
237
- | { kind: "notice"; code: string; content: Content }
238
- | {
239
- kind: "status";
240
- status: "working" | "stopping" | "idle";
241
- reason?: "completed" | "failed" | "interrupted";
242
- }
243
- );
244
-
245
- type TraceKind = TraceEntry["kind"];
246
-
247
- type Content =
248
- | { kind: "inline"; blocks: ContentBlock[] }
249
- | { kind: "reference"; ref: string; bytes: number };
250
-
251
- type ContentBlock =
252
- | { type: "text"; text: string }
253
- | { type: "json"; value: unknown }
254
- | { type: "image"; mimeType: string; data: string } // base64
255
- | { type: "unavailable"; reason: string };
256
- \`\`\`
257
-
258
- - \`kinds\`: only entries of these kinds. Omit for all kinds.
259
- - \`toolName\`: only tool calls and results of this tool. Tool names are the worker's own, such as \`bash\` for a Tau worker or \`Bash\` for a Claude Code worker.
260
- - \`limit\`: integer 1–50, default 20.
261
- - \`cursor\`: \`nextCursor\` from an earlier page. Keep \`kinds\` and \`toolName\` unchanged.
262
-
263
- The first page holds the newest matching entries, in chronological order. \`nextCursor\` leads to older entries. A cursor keeps its starting point, so new activity does not shift the pages. Call without a cursor to see the latest entries again. \`seq\` increases with every entry and identifies it for \`readText\`.
264
-
265
- The trace contains:
266
-
267
- - \`input\`: each message the worker was sent, recorded when it was accepted.
268
- - \`assistant\`: the worker's message text. Reasoning is not included.
269
- - \`tool_call\`: the tool and its arguments as one JSON block.
270
- - \`tool_result\`: the result exactly as the worker received it. Output that the tool itself shortened stays shortened.
271
- - \`notice\`: events with a machine-readable \`code\`. \`input.discarded\` means an interrupt dropped pending input. \`compaction.compacted\`, \`compaction.skipped\`, \`compaction.aborted\`, and \`compaction.failed\` report context compaction. A failed turn adds a notice whose \`code\` matches the state's \`error.code\`.
272
- - \`status\`: the worker started working, began stopping, or became idle.
273
-
274
- System prompts are not included.
275
-
276
- Content is inline when it is at most 4,096 bytes as JSON and has no images. Otherwise the entry holds a \`reference\`; read it with \`readText\` or \`readContent\`. A single content value larger than 6 MiB is replaced by an \`unavailable\` block.
277
-
278
- Each worker keeps its newest 4,096 entries, up to 64 MiB in total. Older entries and their references are then removed, and \`historyEvicted\` is \`true\`.
279
-
280
- A trace ends with its worker. If \`tau.history\` is available and your request calls for past transcripts, you can read a worker's saved conversation with \`tau.history.read\`, using the worker's ID as \`sessionId\`.
281
-
282
- ## \`tau.agents.readText(options)\`
283
-
284
- \`\`\`ts
285
- type ReadTextOptions = { id: string; seq: number; maxChars?: number };
286
- type ReadTextResult = { text: string; complete: boolean };
287
- \`\`\`
288
-
289
- Returns the text of one \`assistant\` or \`tool_result\` entry, whether it is inline or a reference. \`maxChars\` is 1–100,000 UTF-16 code units, default 30,000. \`complete\` is \`false\` when the text was cut at \`maxChars\` or the content contains an \`unavailable\` block. It does not detect output that the tool itself shortened. Content with JSON or images fails; use \`readContent\` for it.
290
-
291
- ## \`tau.agents.readContent(options)\`
292
-
293
- \`\`\`ts
294
- type ReadContentOptions = { id: string; ref: string; cursor?: string };
295
- type ContentPage = { blocks: ContentBlock[]; nextCursor: string | null };
296
- \`\`\`
297
-
298
- Reads referenced content one block per page. Long text arrives in chunks of at most 16,384 UTF-16 code units; join the chunks to get the exact text. JSON and image blocks arrive whole. Pass \`nextCursor\` to read the next page, until it is \`null\`.
299
-
300
- An image reaches your conversation only if you pass it to \`printImage\`.
301
-
302
- ## Errors
303
-
304
- A failed call throws an error with a \`code\` and a \`message\`:
305
-
306
- | \`code\` | Meaning |
307
- | --- | --- |
308
- | \`invalid_arguments\` | The options do not match the interface. |
309
- | \`unknown_agent\` | The ID does not belong to one of your descendants. |
310
- | \`invalid_cursor\` | The cursor is malformed, belongs to another query or reference, or comes from another worker. |
311
- | \`expired_content\` | The entry or reference was removed by retention, or never existed. |
312
- | \`content_type\` | \`readText\` was used on an entry of another kind, or on content with JSON or images. |
313
- | \`operation_failed\` | The request was refused, for example at the capacity or pending-input limit, or because you are being interrupted. |
314
- | \`cancelled\` | The program was cancelled during the call. |
315
-
316
- A worker's failure is part of its state and trace, not an error from these calls. No call is retried automatically.
317
-
318
- ## Examples
319
-
320
- Start a worker, wait for it, and print its answer:
321
-
322
- \`\`\`js
323
- const worker = await tau.agents.spawn({
324
- title: "review authentication",
325
- prompt: "Review the authentication changes in src/auth. Do not edit files. Report findings.",
326
- });
327
- const state = await tau.agents.waitUntilIdle({ id: worker.id });
328
- if (state.status !== "idle" || state.reason !== "completed")
329
- throw new Error(\`worker did not complete: \${JSON.stringify(state)}\`);
330
- const page = await tau.agents.trace({ id: worker.id, kinds: ["assistant"], limit: 1 });
331
- const answer = page.entries[0];
332
- if (!answer) throw new Error("worker gave no answer");
333
- const report = await tau.agents.readText({ id: worker.id, seq: answer.seq });
334
- printText(report.text);
335
- if (!report.complete) printText("(answer incomplete)");
336
- \`\`\`
337
-
338
- Redirect work in progress, then queue a separate task. Here and below, \`id\` is the ID of an earlier worker:
339
-
340
- \`\`\`js
341
- await tau.agents.sendInput({ id, mode: "steer", message: "Focus on expired sessions only." });
342
- await tau.agents.sendInput({ id, mode: "queue", message: "Then review the logout flow." });
343
- \`\`\`
344
-
345
- List the main agent's whole tree, then stop one branch:
346
-
347
- \`\`\`js
348
- const { agents, capacity } = await tau.agents.list();
349
- for (const agent of agents)
350
- printText(\`\${agent.depth} \${agent.id} parent=\${agent.parentId} \${agent.status}\`);
351
- printText(\`\${capacity.running}/\${capacity.limit} working\`);
352
- await tau.agents.interrupt({ id, scope: "subtree" });
353
- \`\`\`
354
-
355
- Print the beginning of each recent failed Bash result:
356
-
357
- \`\`\`js
358
- const page = await tau.agents.trace({ id, kinds: ["tool_result"], toolName: "bash", limit: 10 });
359
- for (const entry of page.entries) {
360
- if (entry.outcome === "succeeded") continue;
361
- const { text, complete } = await tau.agents.readText({ id, seq: entry.seq, maxChars: 2000 });
362
- printText(\`#\${entry.seq}\${complete ? "" : " (shortened)"}: \${text}\`);
40
+ export const agentsPackageDescription = "Start, steer, and wait for worker agents, and read what they did.";
41
+ const AGENTS_FUNCTIONS = [
42
+ "launchOptions",
43
+ "spawn",
44
+ "list",
45
+ "read",
46
+ "sendInput",
47
+ "interrupt",
48
+ "waitUntilIdle",
49
+ "readResponse",
50
+ "trace",
51
+ "readContent",
52
+ "readText",
53
+ "setCompletionNotification",
54
+ ];
55
+ const DELEGATION = "Starting and managing subagents";
56
+ const COMPLETION_NOTIFICATIONS = "Completion notifications";
57
+ /** `@tau/agents` for an agent without delegation: the same exports, each failing with the reason. */
58
+ export function createUnavailableAgentsPackage(delegation) {
59
+ const methods = Object.fromEntries(AGENTS_FUNCTIONS.map((name) => [
60
+ name,
61
+ method(z.tuple([]).rest(z.unknown()), () => requireCapability(delegation, DELEGATION)),
62
+ ]));
63
+ return definePackage("agents", agentsPackageDescription, methods);
363
64
  }
364
- \`\`\`
365
- `,
366
- };
367
- const mainNotificationsDocumentation = `
368
- ## Completion notifications
369
-
370
- As the main agent, you get a notification each time a worker you started goes from working to idle, including after follow-up input. Stopping a worker yourself does not notify you, and workers started by your workers never notify you.
371
-
372
- While workers run and you have nothing else to do, tell the user in a sentence what is running and end your turn. Needing a worker's result is not a reason to wait for it: if you are idle when a notification arrives, Tau starts a turn for you, so you continue with the result, and the user can talk to you in the meantime. Wait with \`wait_for_agents\` only when the user asks you to, or when a worker's task is short and you need its result to finish what you are doing in this turn.
373
-
374
- A notification names the worker and its status, not what it found. Read the notification as usual, then get the worker's answer with \`wait_for_agents\`, which returns at once for an idle worker, or with \`trace\` and \`readText\`.
375
-
376
- Notifications are on by default, and waiting for a worker does not turn them off. If you will wait for a worker's result anyway, turn its notifications off so the same completion does not reach you twice:
377
-
378
- \`\`\`ts
379
- type MainSpawnOptions = SpawnOptions & { notifyOnCompletion?: boolean }; // default true
380
-
381
- type MainAgentsApi = AgentsApi & {
382
- setCompletionNotification(options: { id: string; enabled: boolean }): Promise<AgentState>;
383
- };
384
- \`\`\`
385
-
386
- \`setCompletionNotification\` works only for workers you started yourself and applies to their later completions.
387
- `;
388
- export function createAgentsCapability(options, originHistoryEntryId) {
65
+ export function createAgentsPackage(options, capabilities, originHistoryEntryId) {
389
66
  const supervisor = options.supervisor.scope(options.callerId);
390
- const notifiesCaller = options.callerId === options.supervisor.mainAgentId && options.notifications !== undefined;
391
- const callerSpawnOptions = notifiesCaller
392
- ? spawnOptions.extend({ notifyOnCompletion: z.boolean().default(true) })
393
- : spawnOptions.transform((input) => ({ ...input, notifyOnCompletion: false }));
67
+ const notifications = capabilities.completionNotifications;
68
+ const message = opusPreset(options.persona)
69
+ ? z
70
+ .string()
71
+ .max(256 * 1024)
72
+ .regex(/\S/)
73
+ : workerMessage;
394
74
  const parseAllowedLaunchModel = (model) => {
395
- const parsed = parseSubagentLaunchModel(model, { resolveModel: options.modelResolver });
396
- if (!parsed.launchModel ||
397
- !options.persona.subagentLaunchModels.includes(parsed.launchModel.normalized))
398
- return { error: parsed.error ?? "Subagent launch model is not allowed" };
399
- return parsed;
75
+ const { launchModel, error } = parseSubagentLaunchModel(model, {
76
+ resolveModel: options.modelResolver,
77
+ });
78
+ if (!launchModel || !options.persona.subagentLaunchModels.includes(launchModel.normalized))
79
+ throw new AgentRequestError("operation_failed", error ?? "Subagent launch model is not allowed");
80
+ return launchModel;
400
81
  };
401
- const api = {
402
- launchOptions: (args) => {
403
- z.tuple([]).parse(args);
82
+ const methods = {
83
+ launchOptions: method(z.tuple([]), () => {
404
84
  const choices = describeSubagentLaunchChoices(options.persona);
405
85
  return {
406
86
  inherited: { model: choices.inherited },
407
87
  overrides: choices.overrides.flatMap((model) => {
408
- const { launchModel } = parseAllowedLaunchModel(model);
409
- return launchModel ? [{ model: launchModel.normalized }] : [];
88
+ try {
89
+ return [{ model: parseAllowedLaunchModel(model).normalized }];
90
+ }
91
+ catch {
92
+ return [];
93
+ }
410
94
  }),
411
95
  capacity: supervisor.getCapacity(),
412
96
  };
413
- },
414
- spawn: async (args, context) => {
415
- const [input] = z.tuple([callerSpawnOptions]).parse(args);
416
- context.signal.throwIfAborted();
97
+ }),
98
+ spawn: method(z.tuple([message, spawnOptions]), async ([prompt, input], context) => {
99
+ if (input.notifyOnCompletion)
100
+ requireCapability(notifications, COMPLETION_NOTIFICATIONS);
417
101
  const launchEpoch = supervisor.prepareSpawn();
418
- let launchModel;
419
- if (input.model) {
420
- const parsed = parseAllowedLaunchModel(input.model);
421
- if (!parsed.launchModel)
422
- throw new Error(parsed.error);
423
- launchModel = parsed.launchModel;
424
- }
102
+ const launchModel = input.model ? parseAllowedLaunchModel(input.model) : undefined;
425
103
  const settings = resolveSubagentEffectiveSettings({
426
104
  persona: options.persona,
427
105
  launchModel,
@@ -449,113 +127,62 @@ export function createAgentsCapability(options, originHistoryEntryId) {
449
127
  return supervisor.spawn({
450
128
  ...options,
451
129
  runtimeConfig,
452
- notifyOnCompletion: input.notifyOnCompletion,
130
+ notifyOnCompletion: input.notifyOnCompletion ?? notifications.available,
453
131
  launchEpoch,
454
132
  agents: options,
455
- prompt: input.prompt,
133
+ prompt,
456
134
  title: input.title,
457
135
  originHistoryEntryId,
458
136
  personaId: options.persona.id,
459
137
  });
460
- },
461
- list: (args) => {
462
- z.tuple([]).parse(args);
463
- return {
464
- agents: supervisor.list(),
465
- capacity: supervisor.getCapacity(),
466
- };
467
- },
468
- read: (args) => {
469
- const [input] = z.tuple([idOptions]).parse(args);
470
- return supervisor.read(input.id);
471
- },
472
- sendInput: (args, context) => {
473
- const [input] = z
474
- .tuple([z.strictObject({ id, message, mode: z.enum(["queue", "steer"]) })])
475
- .parse(args);
476
- context.signal.throwIfAborted();
477
- return supervisor.sendInput({
478
- id: input.id,
479
- prompt: input.message,
480
- mode: input.mode,
481
- });
482
- },
483
- interrupt: async (args, context) => {
484
- const [input] = z
485
- .tuple([
486
- z.strictObject({
487
- id,
488
- wait: z.boolean().optional(),
489
- scope: z.enum(["agent", "subtree"]).optional(),
490
- }),
491
- ])
492
- .parse(args);
493
- context.signal.throwIfAborted();
494
- return await supervisor.interrupt(input.id, context.signal, input.wait ?? true, input.scope ?? "agent");
495
- },
496
- waitUntilIdle: async (args, context) => {
497
- const [input] = z.tuple([idOptions]).parse(args);
498
- const [state] = await supervisor.waitForAgents([input.id], context.signal);
138
+ }),
139
+ list: method(z.tuple([]), () => ({
140
+ agents: supervisor.list(),
141
+ capacity: supervisor.getCapacity(),
142
+ })),
143
+ read: method(z.tuple([id]), ([agentId]) => supervisor.read(agentId)),
144
+ sendInput: method(z.tuple([id, message, z.strictObject({ mode: z.enum(["queue", "steer"]) })]), ([agentId, prompt, { mode }]) => supervisor.sendInput({ id: agentId, prompt, mode })),
145
+ interrupt: method(z.tuple([
146
+ id,
147
+ z
148
+ .strictObject({
149
+ wait: z.boolean().optional(),
150
+ scope: z.enum(["agent", "subtree"]).optional(),
151
+ })
152
+ .optional(),
153
+ ]), ([agentId, settings], { signal }) => supervisor.interrupt(agentId, signal, settings?.wait ?? true, settings?.scope ?? "agent")),
154
+ waitUntilIdle: method(z.tuple([id]), async ([agentId], { signal }) => {
155
+ const [state] = await supervisor.waitForAgents([agentId], signal);
499
156
  return state;
500
- },
501
- trace: (args) => {
502
- const [input] = z.tuple([traceOptions]).parse(args);
503
- return supervisor.getTrace(input.id).trace(input);
504
- },
505
- readContent: (args) => {
506
- const [input] = z
507
- .tuple([
508
- z.strictObject({
509
- id,
510
- ref: z.string().min(1).max(256),
511
- cursor: z.string().max(4096).optional(),
512
- }),
513
- ])
514
- .parse(args);
515
- return supervisor.getTrace(input.id).readContent(input);
516
- },
517
- readText: (args) => {
518
- const [input] = z
519
- .tuple([
520
- z.strictObject({
521
- id,
522
- seq: z.number().int().positive(),
523
- maxChars: z.number().int().min(1).max(100000).optional(),
524
- }),
525
- ])
526
- .parse(args);
527
- return supervisor.getTrace(input.id).readText(input.seq, input.maxChars);
528
- },
529
- };
530
- if (notifiesCaller) {
531
- api.setCompletionNotification = (args) => {
532
- const [input] = z.tuple([z.strictObject({ id, enabled: z.boolean() })]).parse(args);
533
- supervisor.setCompletionNotification(input.id, input.enabled);
534
- return supervisor.read(input.id);
535
- };
536
- }
537
- for (const [name, handler] of Object.entries(api)) {
538
- api[name] = async (args, context) => {
539
- try {
540
- context.signal.throwIfAborted();
541
- return await handler(args, context);
542
- }
543
- catch (error) {
544
- if (error instanceof AgentRequestError)
545
- throw error;
546
- throw new AgentRequestError(context.signal.aborted
547
- ? "cancelled"
548
- : error instanceof z.ZodError
549
- ? "invalid_arguments"
550
- : "operation_failed", error instanceof Error ? error.message : String(error));
157
+ }),
158
+ readResponse: method(z.tuple([id]), ([agentId]) => {
159
+ const state = supervisor.read(agentId);
160
+ if (state.status !== "idle" || state.reason !== "completed") {
161
+ throw new AgentRequestError("operation_failed", "The latest worker turn did not complete normally");
551
162
  }
552
- };
553
- }
554
- return {
555
- ...agentsCapabilityMetadata,
556
- documentation: agentsCapabilityMetadata.documentation +
557
- (notifiesCaller ? mainNotificationsDocumentation : ""),
558
- api,
163
+ const response = supervisor.getLastResponse(agentId);
164
+ if (!response?.complete)
165
+ throw new AgentRequestError("expired_content", "No complete worker response is available");
166
+ return response.text;
167
+ }),
168
+ trace: method(z.tuple([id, traceOptions.optional()]), ([agentId, filters]) => supervisor.getTrace(agentId).trace(filters ?? {})),
169
+ readContent: method(z.tuple([
170
+ id,
171
+ z.string().min(1).max(256),
172
+ z.strictObject({ cursor: z.string().max(4096).optional() }).optional(),
173
+ ]), ([agentId, ref, settings]) => supervisor.getTrace(agentId).readContent({ ref, cursor: settings?.cursor })),
174
+ readText: method(z.tuple([id, z.number().int().positive()]), ([agentId, seq]) => {
175
+ const result = supervisor.getTrace(agentId).readText(seq, Infinity);
176
+ if (!result.complete)
177
+ throw new AgentRequestError("expired_content", "The full trace text is unavailable");
178
+ return result.text;
179
+ }),
180
+ setCompletionNotification: method(z.tuple([id, z.boolean()]), ([agentId, enabled]) => {
181
+ requireCapability(notifications, COMPLETION_NOTIFICATIONS);
182
+ supervisor.setCompletionNotification(agentId, enabled);
183
+ return supervisor.read(agentId);
184
+ }),
559
185
  };
186
+ return definePackage("agents", agentsPackageDescription, methods);
560
187
  }
561
188
  //# sourceMappingURL=agents.js.map