@zvada/agent-server 0.3.26 → 0.3.28

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 (262) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +7 -5
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/account.js +111 -0
  6. package/dist/core/agents/acp/acp-agent.js +247 -158
  7. package/dist/core/agents/acp/adapter.js +103 -34
  8. package/dist/core/agents/acp/client.js +169 -42
  9. package/dist/core/agents/acp/known-agents.js +12 -5
  10. package/dist/core/agents/acp/mappings.js +84 -20
  11. package/dist/core/agents/acp/models.js +59 -0
  12. package/dist/core/agents/acp/profile.js +36 -0
  13. package/dist/core/agents/acp/prompts.js +248 -0
  14. package/dist/core/agents/acp/requests.js +4 -4
  15. package/dist/core/agents/claude-code/approvals.js +1 -1
  16. package/dist/core/agents/claude-code/login.js +4 -1
  17. package/dist/core/agents/claude-code/session.js +38 -10
  18. package/dist/core/agents/claude-code/spawn.js +0 -26
  19. package/dist/core/agents/codex-app-server/client.js +12 -13
  20. package/dist/core/agents/codex-app-server/login.js +4 -1
  21. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  22. package/dist/core/agents/gemini/failures.js +133 -0
  23. package/dist/core/agents/gemini/login.js +173 -0
  24. package/dist/core/agents/gemini/profile.js +137 -0
  25. package/dist/core/agents/gemini/tools.js +91 -0
  26. package/dist/core/agents/login.js +8 -6
  27. package/dist/core/agents/scripted/scripted-agent.js +30 -3
  28. package/dist/core/agents/stderr-tail.js +5 -2
  29. package/dist/core/presets.js +17 -1
  30. package/dist/core/processes/native-processes.js +23 -1
  31. package/dist/core/provision/install-build.js +70 -26
  32. package/dist/core/provision/pins.js +5 -0
  33. package/dist/core/provision/provisioner.js +39 -16
  34. package/dist/core/provision/releases.js +39 -1
  35. package/dist/core/provision/tools.js +87 -28
  36. package/dist/core/runtime/agent-runtime.js +15 -5
  37. package/dist/core/runtime/event-processor.js +13 -8
  38. package/dist/core/runtime/origin-line.js +42 -0
  39. package/dist/core/runtime/request-broker.js +2 -1
  40. package/dist/core/runtime/steering.js +4 -3
  41. package/dist/core/runtime/turn.js +6 -4
  42. package/dist/operator/errors.js +97 -0
  43. package/dist/operator/index.js +10 -5
  44. package/dist/operator/mcp.js +7 -12
  45. package/dist/operator/operator.js +1431 -378
  46. package/dist/operator/refs.js +59 -0
  47. package/dist/operator/render.js +199 -94
  48. package/dist/operator/session-tools.js +88 -0
  49. package/dist/operator/types.js +30 -0
  50. package/dist/operator/view.js +82 -27
  51. package/dist/protocol/account.js +5 -1
  52. package/dist/protocol/auth.js +5 -1
  53. package/dist/protocol/config.js +12 -5
  54. package/dist/protocol/conversation.js +3 -0
  55. package/dist/protocol/credentials.js +9 -1
  56. package/dist/protocol/harness.js +9 -1
  57. package/dist/protocol/history.js +2 -1
  58. package/dist/protocol/index.js +1 -0
  59. package/dist/protocol/lifecycle.js +19 -0
  60. package/dist/protocol/origin.js +39 -0
  61. package/dist/protocol/reduce.js +2 -0
  62. package/dist/protocol/wire.js +17 -0
  63. package/dist/server/bin.js +22 -7
  64. package/dist/server/install.js +6 -4
  65. package/dist/server/routes.js +15 -5
  66. package/dist/types/client/client.d.ts.map +1 -1
  67. package/dist/types/client/connection.d.ts +14 -2
  68. package/dist/types/client/connection.d.ts.map +1 -1
  69. package/dist/types/client/turns.d.ts +2 -2
  70. package/dist/types/client/turns.d.ts.map +1 -1
  71. package/dist/types/core/agents/acp/account.d.ts +55 -0
  72. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  73. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  74. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  76. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  77. package/dist/types/core/agents/acp/client.d.ts +66 -4
  78. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  79. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  80. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  81. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  82. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  83. package/dist/types/core/agents/acp/models.d.ts +22 -0
  84. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  85. package/dist/types/core/agents/acp/profile.d.ts +92 -0
  86. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  87. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  88. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  89. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  90. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  91. package/dist/types/core/agents/base.d.ts +2 -0
  92. package/dist/types/core/agents/base.d.ts.map +1 -1
  93. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  94. package/dist/types/core/agents/claude-code/session.d.ts +3 -0
  95. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  96. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  97. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  98. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  100. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  101. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  102. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  103. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  104. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  105. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  106. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  107. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  108. package/dist/types/core/agents/login.d.ts +15 -5
  109. package/dist/types/core/agents/login.d.ts.map +1 -1
  110. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  111. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  112. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  113. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  114. package/dist/types/core/presets.d.ts +2 -2
  115. package/dist/types/core/presets.d.ts.map +1 -1
  116. package/dist/types/core/processes/native-processes.d.ts +6 -0
  117. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  118. package/dist/types/core/provision/checksums.d.ts +7 -1
  119. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  120. package/dist/types/core/provision/install-build.d.ts +32 -6
  121. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  122. package/dist/types/core/provision/pins.d.ts +4 -0
  123. package/dist/types/core/provision/pins.d.ts.map +1 -1
  124. package/dist/types/core/provision/provisioner.d.ts +18 -7
  125. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  126. package/dist/types/core/provision/releases.d.ts +2 -1
  127. package/dist/types/core/provision/releases.d.ts.map +1 -1
  128. package/dist/types/core/provision/tools.d.ts +36 -7
  129. package/dist/types/core/provision/tools.d.ts.map +1 -1
  130. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  131. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  132. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  133. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  134. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  135. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  136. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  137. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  138. package/dist/types/core/runtime/steering.d.ts +7 -4
  139. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  140. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  141. package/dist/types/operator/errors.d.ts +87 -0
  142. package/dist/types/operator/errors.d.ts.map +1 -0
  143. package/dist/types/operator/index.d.ts +10 -5
  144. package/dist/types/operator/index.d.ts.map +1 -1
  145. package/dist/types/operator/mcp.d.ts +1 -1
  146. package/dist/types/operator/mcp.d.ts.map +1 -1
  147. package/dist/types/operator/operator.d.ts +15 -197
  148. package/dist/types/operator/operator.d.ts.map +1 -1
  149. package/dist/types/operator/refs.d.ts +25 -0
  150. package/dist/types/operator/refs.d.ts.map +1 -0
  151. package/dist/types/operator/render.d.ts +67 -22
  152. package/dist/types/operator/render.d.ts.map +1 -1
  153. package/dist/types/operator/session-tools.d.ts +61 -0
  154. package/dist/types/operator/session-tools.d.ts.map +1 -0
  155. package/dist/types/operator/types.d.ts +442 -0
  156. package/dist/types/operator/types.d.ts.map +1 -0
  157. package/dist/types/operator/view.d.ts +19 -29
  158. package/dist/types/operator/view.d.ts.map +1 -1
  159. package/dist/types/protocol/account.d.ts +4 -2
  160. package/dist/types/protocol/account.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +10 -7
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +4 -3
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +22 -5
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +47 -6
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +8 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +1 -1
  172. package/dist/types/protocol/harness.d.ts +5 -2
  173. package/dist/types/protocol/harness.d.ts.map +1 -1
  174. package/dist/types/protocol/history.d.ts +1 -1
  175. package/dist/types/protocol/history.d.ts.map +1 -1
  176. package/dist/types/protocol/index.d.ts +1 -0
  177. package/dist/types/protocol/index.d.ts.map +1 -1
  178. package/dist/types/protocol/lifecycle.d.ts +48 -10
  179. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  180. package/dist/types/protocol/models.d.ts +3 -0
  181. package/dist/types/protocol/models.d.ts.map +1 -1
  182. package/dist/types/protocol/origin.d.ts +49 -0
  183. package/dist/types/protocol/origin.d.ts.map +1 -0
  184. package/dist/types/protocol/reduce.d.ts.map +1 -1
  185. package/dist/types/protocol/wire-api.d.ts +78 -30
  186. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  187. package/dist/types/protocol/wire.d.ts +78 -12
  188. package/dist/types/protocol/wire.d.ts.map +1 -1
  189. package/dist/types/server/install.d.ts +2 -1
  190. package/dist/types/server/install.d.ts.map +1 -1
  191. package/dist/types/server/routes.d.ts.map +1 -1
  192. package/docs/consuming.md +62 -121
  193. package/docs/deploy.md +17 -8
  194. package/docs/harnesses.md +166 -44
  195. package/docs/sync-history.md +2 -1
  196. package/package.json +1 -1
  197. package/src/client/client.ts +36 -9
  198. package/src/client/connection.ts +31 -1
  199. package/src/client/turns.ts +2 -1
  200. package/src/core/agents/acp/account.ts +158 -0
  201. package/src/core/agents/acp/acp-agent.ts +288 -178
  202. package/src/core/agents/acp/adapter.ts +126 -35
  203. package/src/core/agents/acp/client.ts +196 -49
  204. package/src/core/agents/acp/known-agents.ts +14 -5
  205. package/src/core/agents/acp/mappings.ts +112 -21
  206. package/src/core/agents/acp/models.ts +72 -0
  207. package/src/core/agents/acp/profile.ts +127 -0
  208. package/src/core/agents/acp/prompts.ts +287 -0
  209. package/src/core/agents/acp/requests.ts +16 -9
  210. package/src/core/agents/base.ts +2 -0
  211. package/src/core/agents/claude-code/approvals.ts +2 -2
  212. package/src/core/agents/claude-code/login.ts +4 -1
  213. package/src/core/agents/claude-code/session.ts +38 -8
  214. package/src/core/agents/claude-code/spawn.ts +0 -26
  215. package/src/core/agents/codex-app-server/client.ts +11 -18
  216. package/src/core/agents/codex-app-server/login.ts +4 -5
  217. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  218. package/src/core/agents/gemini/failures.ts +148 -0
  219. package/src/core/agents/gemini/login.ts +188 -0
  220. package/src/core/agents/gemini/profile.ts +162 -0
  221. package/src/core/agents/gemini/tools.ts +99 -0
  222. package/src/core/agents/login.ts +14 -8
  223. package/src/core/agents/scripted/scripted-agent.ts +42 -3
  224. package/src/core/agents/stderr-tail.ts +5 -2
  225. package/src/core/presets.ts +19 -3
  226. package/src/core/processes/native-processes.ts +32 -1
  227. package/src/core/provision/checksums.ts +12 -2
  228. package/src/core/provision/install-build.ts +122 -55
  229. package/src/core/provision/pins.ts +5 -0
  230. package/src/core/provision/provisioner.ts +62 -27
  231. package/src/core/provision/releases.ts +47 -1
  232. package/src/core/provision/tools.ts +124 -31
  233. package/src/core/runtime/agent-runtime.ts +31 -7
  234. package/src/core/runtime/event-processor.ts +13 -6
  235. package/src/core/runtime/origin-line.ts +43 -0
  236. package/src/core/runtime/request-broker.ts +2 -0
  237. package/src/core/runtime/steering.ts +8 -4
  238. package/src/core/runtime/turn.ts +11 -4
  239. package/src/operator/errors.ts +221 -0
  240. package/src/operator/index.ts +18 -23
  241. package/src/operator/mcp.ts +7 -16
  242. package/src/operator/operator.ts +1684 -610
  243. package/src/operator/refs.ts +75 -0
  244. package/src/operator/render.ts +260 -118
  245. package/src/operator/session-tools.ts +127 -0
  246. package/src/operator/types.ts +506 -0
  247. package/src/operator/view.ts +93 -42
  248. package/src/protocol/account.ts +5 -2
  249. package/src/protocol/auth.ts +5 -1
  250. package/src/protocol/config.ts +14 -6
  251. package/src/protocol/conversation.ts +3 -0
  252. package/src/protocol/credentials.ts +11 -2
  253. package/src/protocol/harness.ts +9 -1
  254. package/src/protocol/history.ts +2 -1
  255. package/src/protocol/index.ts +1 -0
  256. package/src/protocol/lifecycle.ts +21 -0
  257. package/src/protocol/origin.ts +47 -0
  258. package/src/protocol/reduce.ts +4 -0
  259. package/src/protocol/wire.ts +18 -0
  260. package/src/server/bin.ts +20 -6
  261. package/src/server/install.ts +6 -3
  262. package/src/server/routes.ts +16 -5
@@ -0,0 +1,221 @@
1
+ /**
2
+ * The refusals: a closed set of codes (`OPERATOR_ERROR_CODES`), each with its
3
+ * sentence. A refusal reads `refused (<code>): <sentence>`, then the host's
4
+ * words, then the next call, which names only a tool that is installed.
5
+ */
6
+
7
+ // @ref LLP 0019#errors — one sentence per code, and a next call that exists
8
+
9
+ import { json } from "./render.ts";
10
+ import type { OperatorErrorCode, Refusal } from "./types.ts";
11
+
12
+ /**
13
+ * A host's refusal at its own commit (`start`, `archive`, `send`): the code
14
+ * and the sessions it is about, by id; the package words it as its own
15
+ * refusal of that code, naming the sessions as the caller sees them.
16
+ */
17
+ export class Refused extends Error {
18
+ override name = "Refused";
19
+ constructor(readonly refusal: Refusal) {
20
+ super(`refused (${refusal.code})`);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * What can be archived, as `archive` takes it: a chat on its own, or, for a
26
+ * chat that is its workspace's only one, the workspace (a host may refuse
27
+ * archiving a workspace's last chat on its own).
28
+ */
29
+ export interface Archivable {
30
+ sessions: readonly string[];
31
+ workspaces: readonly string[];
32
+ }
33
+
34
+ const archiveHint = (hint: Hint, { sessions, workspaces }: Archivable) =>
35
+ sessions.length || workspaces.length
36
+ ? hint("archive", {
37
+ ...(sessions.length ? { sessions } : {}),
38
+ ...(workspaces.length ? { workspaces } : {}),
39
+ })
40
+ : undefined;
41
+
42
+ /** A refusal a model can act on. Anything else a tool throws is `failed`. */
43
+ export class OperatorError extends Error {
44
+ override name = "OperatorError";
45
+ constructor(
46
+ readonly code: OperatorErrorCode,
47
+ sentence: string,
48
+ readonly extra: {
49
+ /** The host's words: trusted, one line, said after the sentence. */
50
+ detail?: string;
51
+ /** The next call, already built from the installed tools. */
52
+ next?: string;
53
+ retryAfter?: number;
54
+ /** What was done before the refusal, when something was. */
55
+ done?: string;
56
+ } = {},
57
+ ) {
58
+ const done = extra.done ? `${extra.done} ` : "";
59
+ const detail = extra.detail ? ` ${extra.detail}` : "";
60
+ const next = extra.next ? `\n ${extra.next}` : "";
61
+ super(`refused (${code}): ${done}${sentence}${detail}${next}`);
62
+ }
63
+ get retryAfter(): number | undefined {
64
+ return this.extra.retryAfter;
65
+ }
66
+
67
+ /** A refusal whose words are already built (a batch whose every item was refused). */
68
+ static said(code: OperatorErrorCode, text: string): OperatorError {
69
+ const error = new OperatorError(code, "");
70
+ error.message = text;
71
+ return error;
72
+ }
73
+ }
74
+
75
+ /** Build a hint for a call, or nothing when that tool is not installed. */
76
+ export type Hint = (tool: string, args?: Record<string, unknown>) => string | undefined;
77
+
78
+ const NOTHING = "Nothing was done.";
79
+ /** Every value a refusal names: one JSON line, nothing raw (a repository's name, a setup's error). */
80
+ const q = (text: string) => json(text);
81
+ const list = (refs: readonly string[]) => refs.map(q).join(", ") || "(none)";
82
+
83
+ /**
84
+ * Every refusal, by code. Each takes what its sentence names and the `hint`
85
+ * of the operator that refuses, so its next call is one the caller has.
86
+ */
87
+ export const refuse = {
88
+ invalidInput: (tool: string, field: string, problem: string) =>
89
+ new OperatorError("invalid_input", `${tool}: ${field}: ${problem}. ${NOTHING}`),
90
+ notFound: (hint: Hint, ref: string, known: readonly string[]) =>
91
+ new OperatorError(
92
+ "not_found",
93
+ `No session, workspace or project ${q(ref)}. Known: ${list(known)}. ${NOTHING}`,
94
+ { next: hint("list_sessions") },
95
+ ),
96
+ ambiguous: (ref: string, refs: readonly string[]) =>
97
+ new OperatorError(
98
+ "ambiguous",
99
+ `${q(ref)} names several: ${list(refs)}. Use one of them. ${NOTHING}`,
100
+ ),
101
+ archived: (hint: Hint, ref: string, project?: string) =>
102
+ new OperatorError("archived", `${q(ref)} is archived, so nothing was done.`, {
103
+ next: project ? hint("start_session", { project, message: "<the task>" }) : undefined,
104
+ }),
105
+ self: (what: "session" | "workspace") =>
106
+ new OperatorError(
107
+ "self",
108
+ `That is your own ${what}: a session cannot send to, stop, answer or archive itself. ${NOTHING}`,
109
+ ),
110
+ readOnly: () =>
111
+ new OperatorError(
112
+ "read_only",
113
+ `You are in plan mode, so you may only list, read and wait. ${NOTHING} Put this step in your plan.`,
114
+ ),
115
+ access: (detail?: string) =>
116
+ new OperatorError("access", `You may not do this here. ${NOTHING}`, { detail }),
117
+ notYoursArchive: (ref: string, busy: readonly string[]) =>
118
+ new OperatorError(
119
+ "not_yours",
120
+ `${q(ref)} has sessions you did not start working or waiting (${list(busy)}). Nothing was archived. Ask the person.`,
121
+ ),
122
+ notYoursAnswer: (ref: string) =>
123
+ new OperatorError(
124
+ "not_yours",
125
+ `${q(ref)} was not started by you or a session you started, so its answer is the person's. Nothing was sent. Tell the person what it waits on.`,
126
+ ),
127
+ notYoursPermission: () =>
128
+ new OperatorError(
129
+ "not_yours",
130
+ "Only a session with full access answers a permission. Nothing was sent. Tell the person.",
131
+ ),
132
+ hasChildren: (hint: Hint, ref: string, children: readonly string[], archive: Archivable) =>
133
+ new OperatorError(
134
+ "has_children",
135
+ `${q(ref)} started sessions that are not archived (${list(children)}). Nothing was archived. Archive those first.`,
136
+ { next: archiveHint(hint, archive) },
137
+ ),
138
+ busy: (
139
+ hint: Hint,
140
+ ref: string,
141
+ state: "working" | "waiting on an answer" | "being set up",
142
+ undone: "archived" | "started in it" | "sent",
143
+ ) =>
144
+ new OperatorError("busy", `${q(ref)} is ${state}, so nothing was ${undone}.`, {
145
+ next:
146
+ state === "being set up"
147
+ ? hint("wait_for_sessions", { sessions: [ref] })
148
+ : hint("stop_sessions", { sessions: [ref] }),
149
+ }),
150
+ notWaiting: (hint: Hint, ref: string, status: string, current?: string) =>
151
+ new OperatorError(
152
+ "not_waiting",
153
+ `${q(ref)} is not waiting on that request (status: ${status}). Nothing was sent.${current ? ` It waits on request ${q(current)}.` : ""}`,
154
+ {
155
+ next: current
156
+ ? hint("answer_request", { session: ref, request: current, answer: "<your answer>" })
157
+ : hint("send_message", { session: ref, message: "<your answer>" }),
158
+ },
159
+ ),
160
+ personOnly: (ref: string, why: string) =>
161
+ new OperatorError(
162
+ "person_only",
163
+ `${q(ref)} waits on something only the person can answer, where the session runs (${why}). Nothing was sent. Tell the person.`,
164
+ ),
165
+ setupFailed: (hint: Hint, ref: string, reason: string, done?: string) =>
166
+ new OperatorError(
167
+ "setup_failed",
168
+ `${q(ref)} could not be set up: ${q(reason)}. Nothing was sent.`,
169
+ {
170
+ next: hint("archive", { workspaces: [ref] }),
171
+ done,
172
+ },
173
+ ),
174
+ limitDepth: (depth: number) =>
175
+ new OperatorError(
176
+ "limit_depth",
177
+ `You were started by a chain of ${depth} sessions, the most allowed, so you cannot start another. Nothing was started. Do the work yourself, or tell the person.`,
178
+ ),
179
+ limitSessions: (hint: Hint, count: number, settled: Archivable) =>
180
+ new OperatorError(
181
+ "limit_sessions",
182
+ `You have ${count} sessions you started that are not archived (the limit). Nothing was started. Archive the ones whose work is done.`,
183
+ { next: archiveHint(hint, settled) },
184
+ ),
185
+ limitSettingUp: (retryAfter: number, detail?: string) =>
186
+ new OperatorError(
187
+ "limit_setting_up",
188
+ `As many workspaces as this host sets up at once are being set up. Nothing was started. Try again in about ${retryAfter}s.`,
189
+ { detail, retryAfter },
190
+ ),
191
+ limitRate: (count: number, retryAfter: number) =>
192
+ new OperatorError(
193
+ "limit_rate",
194
+ `You started ${count} sessions in the last minute (the limit). Nothing was started. Try again in ${retryAfter}s.`,
195
+ { retryAfter },
196
+ ),
197
+ limitResources: (retryAfter: number | undefined, detail?: string) =>
198
+ new OperatorError(
199
+ "limit_resources",
200
+ `This computer cannot take another session now. Nothing was started.${retryAfter ? ` Try again in ${retryAfter}s.` : ""}`,
201
+ { detail, retryAfter },
202
+ ),
203
+ staleCursor: (hint: Hint, ref: string, selection?: { after: string } | { last: number }) =>
204
+ new OperatorError(
205
+ "stale_cursor",
206
+ `That cursor no longer points into ${q(ref)}. Nothing was read.`,
207
+ {
208
+ next: hint(
209
+ "read_session",
210
+ selection ? { session: ref, ...selection, full: true } : { session: ref },
211
+ ),
212
+ },
213
+ ),
214
+ unsupported: (detail?: string) =>
215
+ new OperatorError("unsupported", `This cannot be done here. ${NOTHING}`, { detail }),
216
+ failed: () =>
217
+ new OperatorError(
218
+ "failed",
219
+ "The tool failed; nothing more is known. Try again, or tell the person.",
220
+ ),
221
+ };
@@ -1,40 +1,35 @@
1
1
  /**
2
- * `@zvada/agent-server/operator`: the session tools an outside agent operates a
3
- * product's coding agents with, and their MCP binding. Imports only the
4
- * protocol and zod; the product is the `OperatorHost` (LLP 0014).
2
+ * `@zvada/agent-server/operator`: the session tools an outside agent, or a
3
+ * product's own session, operates a product's coding agents with, and their
4
+ * MCP binding. Imports only the protocol and zod; the product is the
5
+ * `OperatorHost` (LLP 0014, LLP 0019).
5
6
  */
6
7
  export { PLAN_OPTIONS, PLAN_TITLE } from "../protocol/plan.ts";
8
+ export { type Archivable, type Hint, OperatorError, Refused, refuse } from "./errors.ts";
7
9
  export {
8
10
  type McpHandler,
9
11
  type McpServerInfo,
10
12
  type ToolSource,
11
13
  createMcpHandler,
12
14
  } from "./mcp.ts";
15
+ export { DEFAULT_LIMITS, DEFAULT_WAITS, createOperator, tool } from "./operator.ts";
16
+ export { refOf } from "./refs.ts";
13
17
  export {
14
- type Operator,
15
- type OperatorClock,
16
- type OperatorHost,
17
- type OperatorOptions,
18
- type SendOptions,
19
- type SendResult,
20
- type SessionEntry,
21
- type StartInput,
22
- type StartResult,
23
- type Tool,
24
- type ToolInfo,
25
- type ViewOptions,
26
- OperatorError,
27
- createOperator,
28
- tool,
29
- } from "./operator.ts";
18
+ OPERATOR_GUIDANCE,
19
+ type SessionTool,
20
+ type SessionToolCaller,
21
+ type SessionToolContent,
22
+ type SessionToolSource,
23
+ operatorSessionTools,
24
+ } from "./session-tools.ts";
30
25
  export { type Answer, callHint, oneLine, quote, quoted } from "./render.ts";
26
+ export * from "./types.ts";
31
27
  export {
32
28
  type DecisionRequest,
33
- type Phase,
34
29
  type QuestionRequest,
35
- type SessionView,
36
30
  type ViewMessage,
37
- type Waiting,
38
- phaseOf,
31
+ settledStatus,
32
+ turnOf,
39
33
  viewOf,
34
+ waitingOf,
40
35
  } from "./view.ts";
@@ -11,8 +11,8 @@
11
11
 
12
12
  // @ref LLP 0014#the-mcp-binding — the engine answers MCP's tool methods; the route, its authentication and its caller are the host's
13
13
 
14
- import { OperatorError, type ToolInfo } from "./operator.ts";
15
- import { quoted } from "./render.ts";
14
+ import { OperatorError, refuse } from "./errors.ts";
15
+ import type { ToolInfo } from "./types.ts";
16
16
 
17
17
  /** Anything that lists and runs tools: an operator, or a host's wrapper around one. */
18
18
  export interface ToolSource<Caller> {
@@ -115,8 +115,9 @@ export function createMcpHandler<Caller>(
115
115
  },
116
116
  })),
117
117
  });
118
- } catch (error) {
119
- return fail(id, -32603, messageOf(error));
118
+ } catch {
119
+ // Its text may be anyone's: a fixed sentence instead.
120
+ return fail(id, -32603, "The tool list could not be read.");
120
121
  }
121
122
  }
122
123
  case "tools/call": {
@@ -127,16 +128,10 @@ export function createMcpHandler<Caller>(
127
128
  return ok(id, text(await source.call(params.name, params.arguments ?? {}, caller)));
128
129
  } catch (error) {
129
130
  // The model reads the reason and can act on it; a JSON-RPC error it would not see.
130
- // A refusal's words are meant for it; any other failure's may be an agent's or a
131
- // repository's, so it is one quoted line, never a line that reads as a hint.
132
131
  return ok(
133
132
  id,
134
- text(
135
- error instanceof OperatorError
136
- ? error.message
137
- : `The tool failed: ${quoted(messageOf(error))}`,
138
- true,
139
- ),
133
+ // Any other failure's text may be an agent's or a repository's: never said.
134
+ text(error instanceof OperatorError ? error.message : refuse.failed().message, true),
140
135
  );
141
136
  }
142
137
  }
@@ -165,7 +160,3 @@ function idOf(message: Record<string, unknown>): Id {
165
160
  const id = message.id;
166
161
  return typeof id === "string" || typeof id === "number" ? id : null;
167
162
  }
168
-
169
- function messageOf(error: unknown): string {
170
- return error instanceof Error ? error.message : String(error);
171
- }