@wheatley-ai/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/LICENSE +15 -0
  2. package/bin/wheatley.js +2 -0
  3. package/dist/approvals/gate.js +278 -0
  4. package/dist/approvals/module.js +21 -0
  5. package/dist/approvals/policy.js +30 -0
  6. package/dist/approvals/preview.js +17 -0
  7. package/dist/approvals/prompt.js +98 -0
  8. package/dist/approvals/rpc.js +16 -0
  9. package/dist/approvals/store.js +159 -0
  10. package/dist/cli/ask.js +94 -0
  11. package/dist/cli/chat.js +178 -0
  12. package/dist/cli/client.js +104 -0
  13. package/dist/cli/daemon.js +35 -0
  14. package/dist/cli/init.js +72 -0
  15. package/dist/cli/io.js +45 -0
  16. package/dist/cli/main.js +206 -0
  17. package/dist/cli/session.js +86 -0
  18. package/dist/cli/status.js +46 -0
  19. package/dist/contracts/approval-gate.js +1 -0
  20. package/dist/contracts/config-store.js +1 -0
  21. package/dist/contracts/delivery-outbox.js +1 -0
  22. package/dist/contracts/errors.js +28 -0
  23. package/dist/contracts/extension-catalog.js +1 -0
  24. package/dist/contracts/maintenance-runner.js +1 -0
  25. package/dist/contracts/memory-store.js +1 -0
  26. package/dist/contracts/module.js +7 -0
  27. package/dist/contracts/tool-names.js +43 -0
  28. package/dist/contracts/trigger-runtime.js +1 -0
  29. package/dist/contracts/webhook-ingress.js +2 -0
  30. package/dist/core/agent/agent-store.js +300 -0
  31. package/dist/core/agent/agent.js +1033 -0
  32. package/dist/core/agent/gated-models.js +89 -0
  33. package/dist/core/agent/pi-adapter.js +401 -0
  34. package/dist/core/agent/policy-gate.js +44 -0
  35. package/dist/core/builtin-catalog.js +20 -0
  36. package/dist/core/concurrency-gate.js +87 -0
  37. package/dist/core/config/atomic-file.js +72 -0
  38. package/dist/core/config/config-store.js +138 -0
  39. package/dist/core/config/pending-restart.js +53 -0
  40. package/dist/core/config/secret-references.js +69 -0
  41. package/dist/core/config/secret-store.js +147 -0
  42. package/dist/core/config/validate.js +55 -0
  43. package/dist/core/config/yaml-patch.js +57 -0
  44. package/dist/core/daemon-socket.js +96 -0
  45. package/dist/core/daemon.js +97 -0
  46. package/dist/core/deployment.js +379 -0
  47. package/dist/core/error-message.js +4 -0
  48. package/dist/core/events.js +25 -0
  49. package/dist/core/logger.js +81 -0
  50. package/dist/core/models.js +27 -0
  51. package/dist/core/module.js +42 -0
  52. package/dist/core/rpc/agent-handlers.js +82 -0
  53. package/dist/core/rpc/deployment-handlers.js +63 -0
  54. package/dist/core/rpc/router.js +96 -0
  55. package/dist/core/server/connection.js +170 -0
  56. package/dist/core/server/control-server.js +152 -0
  57. package/dist/core/server/static-files.js +79 -0
  58. package/dist/core/supervisor.js +215 -0
  59. package/dist/core/tool-routing.js +41 -0
  60. package/dist/dashboard/assets/index-C9Rul5vE.css +2 -0
  61. package/dist/dashboard/assets/index-DXzGGAxQ.js +11 -0
  62. package/dist/dashboard/assets/sheet-presentation-DMljN0LW.js +1 -0
  63. package/dist/dashboard/index.html +18 -0
  64. package/dist/db/database.js +16 -0
  65. package/dist/db/migrations.js +184 -0
  66. package/dist/frontends/discord/approvals.js +199 -0
  67. package/dist/frontends/discord/attachments.js +115 -0
  68. package/dist/frontends/discord/binding.js +489 -0
  69. package/dist/frontends/discord/config.js +107 -0
  70. package/dist/frontends/discord/discord-runtime.js +52 -0
  71. package/dist/frontends/discord/errors.js +61 -0
  72. package/dist/frontends/discord/live-runs.js +189 -0
  73. package/dist/frontends/discord/module.js +39 -0
  74. package/dist/frontends/discord/recent-ids.js +20 -0
  75. package/dist/frontends/slack/approval-blocks.js +98 -0
  76. package/dist/frontends/slack/attachments.js +102 -0
  77. package/dist/frontends/slack/background-tasks.js +20 -0
  78. package/dist/frontends/slack/binding.js +405 -0
  79. package/dist/frontends/slack/bounded.js +9 -0
  80. package/dist/frontends/slack/chat-id.js +17 -0
  81. package/dist/frontends/slack/config.js +80 -0
  82. package/dist/frontends/slack/delivery-errors.js +81 -0
  83. package/dist/frontends/slack/inbound.js +76 -0
  84. package/dist/frontends/slack/live-progress.js +190 -0
  85. package/dist/frontends/slack/manifest.js +66 -0
  86. package/dist/frontends/slack/outbound.js +160 -0
  87. package/dist/frontends/slack/schemas.js +99 -0
  88. package/dist/frontends/slack/signature.js +30 -0
  89. package/dist/frontends/slack/slack-client.js +60 -0
  90. package/dist/frontends/slack/slack-frontend.js +38 -0
  91. package/dist/frontends/slack/state-store.js +112 -0
  92. package/dist/frontends/telegram/approvals.js +134 -0
  93. package/dist/frontends/telegram/attachments.js +126 -0
  94. package/dist/frontends/telegram/binding.js +144 -0
  95. package/dist/frontends/telegram/chat-key.js +43 -0
  96. package/dist/frontends/telegram/client.js +88 -0
  97. package/dist/frontends/telegram/config.js +93 -0
  98. package/dist/frontends/telegram/delivery.js +215 -0
  99. package/dist/frontends/telegram/frontend.js +42 -0
  100. package/dist/frontends/telegram/grammy-client.js +122 -0
  101. package/dist/frontends/telegram/http-status.js +6 -0
  102. package/dist/frontends/telegram/inbound.js +149 -0
  103. package/dist/frontends/telegram/live.js +182 -0
  104. package/dist/frontends/telegram/markdown.js +103 -0
  105. package/dist/frontends/telegram/recent-set.js +18 -0
  106. package/dist/frontends/telegram/serial-queue.js +23 -0
  107. package/dist/index.js +7 -0
  108. package/dist/mcp/content.js +61 -0
  109. package/dist/mcp/mcp-module.js +35 -0
  110. package/dist/mcp/mcp-tool-provider.js +93 -0
  111. package/dist/mcp/server-connection.js +297 -0
  112. package/dist/memory/consolidation.js +260 -0
  113. package/dist/memory/format.js +5 -0
  114. package/dist/memory/migrations.js +76 -0
  115. package/dist/memory/module.js +69 -0
  116. package/dist/memory/names.js +20 -0
  117. package/dist/memory/rows.js +22 -0
  118. package/dist/memory/rpc.js +49 -0
  119. package/dist/memory/snapshots.js +12 -0
  120. package/dist/memory/store.js +281 -0
  121. package/dist/memory/tools.js +158 -0
  122. package/dist/node_modules/@wheatley-ai/protocol/dist/config.d.ts +262 -0
  123. package/dist/node_modules/@wheatley-ai/protocol/dist/config.js +120 -0
  124. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.d.ts +512 -0
  125. package/dist/node_modules/@wheatley-ai/protocol/dist/domain.js +441 -0
  126. package/dist/node_modules/@wheatley-ai/protocol/dist/duration.d.ts +8 -0
  127. package/dist/node_modules/@wheatley-ai/protocol/dist/duration.js +28 -0
  128. package/dist/node_modules/@wheatley-ai/protocol/dist/events.d.ts +234 -0
  129. package/dist/node_modules/@wheatley-ai/protocol/dist/events.js +124 -0
  130. package/dist/node_modules/@wheatley-ai/protocol/dist/index.d.ts +11 -0
  131. package/dist/node_modules/@wheatley-ai/protocol/dist/index.js +11 -0
  132. package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.d.ts +81 -0
  133. package/dist/node_modules/@wheatley-ai/protocol/dist/json-rpc.js +157 -0
  134. package/dist/node_modules/@wheatley-ai/protocol/dist/json.d.ts +14 -0
  135. package/dist/node_modules/@wheatley-ai/protocol/dist/json.js +23 -0
  136. package/dist/node_modules/@wheatley-ai/protocol/dist/limits.d.ts +17 -0
  137. package/dist/node_modules/@wheatley-ai/protocol/dist/limits.js +17 -0
  138. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.d.ts +1107 -0
  139. package/dist/node_modules/@wheatley-ai/protocol/dist/methods.js +201 -0
  140. package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.d.ts +45 -0
  141. package/dist/node_modules/@wheatley-ai/protocol/dist/rpc-error.js +44 -0
  142. package/dist/node_modules/@wheatley-ai/protocol/dist/validation.d.ts +20 -0
  143. package/dist/node_modules/@wheatley-ai/protocol/dist/validation.js +11 -0
  144. package/dist/node_modules/@wheatley-ai/protocol/package.json +14 -0
  145. package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.d.ts +11 -0
  146. package/dist/node_modules/@wheatley-ai/sdk/dist/chunk.js +162 -0
  147. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.d.ts +48 -0
  148. package/dist/node_modules/@wheatley-ai/sdk/dist/commands.js +39 -0
  149. package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.d.ts +29 -0
  150. package/dist/node_modules/@wheatley-ai/sdk/dist/delivery-error.js +27 -0
  151. package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.d.ts +236 -0
  152. package/dist/node_modules/@wheatley-ai/sdk/dist/frontend.js +2 -0
  153. package/dist/node_modules/@wheatley-ai/sdk/dist/index.d.ts +10 -0
  154. package/dist/node_modules/@wheatley-ai/sdk/dist/index.js +7 -0
  155. package/dist/node_modules/@wheatley-ai/sdk/dist/json.d.ts +9 -0
  156. package/dist/node_modules/@wheatley-ai/sdk/dist/json.js +2 -0
  157. package/dist/node_modules/@wheatley-ai/sdk/dist/logger.d.ts +18 -0
  158. package/dist/node_modules/@wheatley-ai/sdk/dist/logger.js +2 -0
  159. package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.d.ts +48 -0
  160. package/dist/node_modules/@wheatley-ai/sdk/dist/plugin.js +5 -0
  161. package/dist/node_modules/@wheatley-ai/sdk/dist/schema.d.ts +69 -0
  162. package/dist/node_modules/@wheatley-ai/sdk/dist/schema.js +3 -0
  163. package/dist/node_modules/@wheatley-ai/sdk/dist/tool.d.ts +69 -0
  164. package/dist/node_modules/@wheatley-ai/sdk/dist/tool.js +3 -0
  165. package/dist/node_modules/@wheatley-ai/sdk/package.json +11 -0
  166. package/dist/ops/backup.js +185 -0
  167. package/dist/ops/cli.js +194 -0
  168. package/dist/ops/command-runner.js +34 -0
  169. package/dist/ops/dashboard-assets.js +37 -0
  170. package/dist/ops/migrate.js +63 -0
  171. package/dist/ops/module.js +47 -0
  172. package/dist/ops/paths.js +55 -0
  173. package/dist/ops/service.js +376 -0
  174. package/dist/ops/update.js +145 -0
  175. package/dist/plugins/contributions.js +89 -0
  176. package/dist/plugins/guards.js +111 -0
  177. package/dist/plugins/load.js +76 -0
  178. package/dist/plugins/module.js +31 -0
  179. package/dist/plugins/provider.js +349 -0
  180. package/dist/plugins/schema.js +69 -0
  181. package/dist/skills/disclosure.js +142 -0
  182. package/dist/skills/discovery.js +120 -0
  183. package/dist/skills/fs-errors.js +8 -0
  184. package/dist/skills/read-skill-tool.js +3 -0
  185. package/dist/skills/skill-file.js +90 -0
  186. package/dist/skills/skills.js +140 -0
  187. package/dist/tools/builtin-tools.js +61 -0
  188. package/dist/tools/input.js +45 -0
  189. package/dist/tools/paths.js +6 -0
  190. package/dist/tools/read-file.js +65 -0
  191. package/dist/tools/shell.js +156 -0
  192. package/dist/tools/write-file.js +58 -0
  193. package/dist/triggers/delivery-codec.js +99 -0
  194. package/dist/triggers/delivery-outbox.js +313 -0
  195. package/dist/triggers/due-timer.js +14 -0
  196. package/dist/triggers/errors.js +2 -0
  197. package/dist/triggers/migrations.js +91 -0
  198. package/dist/triggers/module.js +106 -0
  199. package/dist/triggers/rpc.js +35 -0
  200. package/dist/triggers/schedule.js +52 -0
  201. package/dist/triggers/sql-row.js +59 -0
  202. package/dist/triggers/trigger-runtime.js +445 -0
  203. package/dist/triggers/trigger-tools.js +210 -0
  204. package/dist/triggers/webhook-ingress.js +212 -0
  205. package/dist/wiring/agent-services.js +151 -0
  206. package/dist/wiring/catalog.js +81 -0
  207. package/dist/wiring/daemon.js +83 -0
  208. package/dist/wiring/frontend-host.js +268 -0
  209. package/package.json +50 -3
  210. package/README.md +0 -3
@@ -0,0 +1,201 @@
1
+ import { Type } from "typebox";
2
+ import { AgentConfigSchema, DeploymentConfigSchema } from "./config.js";
3
+ import { AgentHealthSchema, AgentNameSchema, AgentStateSchema, ApprovalResolutionSchema, AttachmentUploadSchema, BindingStatusSchema, ChatMessageSchema, CommandNameSchema, ConfigIssueSchema, ConsolidationLogEntrySchema, Count, DaemonStatusSchema, ExtensionStatusSchema, FailedDeliverySchema, IdSchema, LogLevelSchema, LogRecordSchema, MemoryBudgetSchema, MemoryFileSchema, MemoryNameSchema, MemorySearchHitSchema, MemorySearchScopeSchema, PendingApprovalSchema, PendingRestartSchema, RunSummarySchema, RunTimelineItemSchema, SecretInfoSchema, SecretNameSchema, SecretSourceSchema, SkillInfoSchema, ToolInfoSchema, TriggerSchema, TriggerInputSchema, TriggerPatchSchema, } from "./domain.js";
4
+ import { EventTopicSchema } from "./events.js";
5
+ import { DISPLAY_NAME_MAX_LENGTH } from "./limits.js";
6
+ /** The protocol version of this package. The CLI and dashboard compare it in `system.hello`. */
7
+ export const PROTOCOL_VERSION = 1;
8
+ const MAX_PAGE = 500;
9
+ /** A params object that rejects unknown fields, so typos fail with `invalid_params`. */
10
+ const params = (properties) => Type.Object(properties, { additionalProperties: false });
11
+ /** Defines one method: its params schema and its result schema. */
12
+ const method = (paramsSchema, resultSchema) => ({ params: paramsSchema, result: resultSchema });
13
+ const agentParams = params({ agent: AgentNameSchema });
14
+ const limit = Type.Optional(Type.Integer({ maximum: MAX_PAGE, minimum: 1 }));
15
+ const revision = Type.String({ minLength: 1 });
16
+ /**
17
+ * Every v1 JSON-RPC method that the CLI and dashboard call (ADR 0005).
18
+ *
19
+ * A method with an `agent` param acts on that Agent only. Within protocol version 1, methods and result fields are
20
+ * only added, never removed or changed.
21
+ */
22
+ export const methods = {
23
+ "agents.create": method(params({
24
+ agent: AgentNameSchema,
25
+ config: AgentConfigSchema,
26
+ expectedRevision: revision,
27
+ }), Type.Object({ revision })),
28
+ "agents.delete": method(params({
29
+ agent: AgentNameSchema,
30
+ /** What happens to `agents/<name>/`: keep it, move it to an archive folder, or delete it. */
31
+ data: Type.Union([
32
+ Type.Literal("keep"),
33
+ Type.Literal("archive"),
34
+ Type.Literal("delete"),
35
+ ]),
36
+ expectedRevision: revision,
37
+ }), Type.Object({ revision })),
38
+ "agents.get": method(agentParams, AgentHealthSchema),
39
+ "agents.list": method(params({}), Type.Object({ agents: Type.Array(AgentHealthSchema) })),
40
+ "agents.rename": method(params({
41
+ agent: AgentNameSchema,
42
+ expectedRevision: revision,
43
+ newName: AgentNameSchema,
44
+ }), Type.Object({ revision })),
45
+ "agents.restart": method(agentParams, Type.Object({ state: AgentStateSchema })),
46
+ "agents.start": method(agentParams, Type.Object({ state: AgentStateSchema })),
47
+ "agents.stop": method(agentParams, Type.Object({ state: AgentStateSchema })),
48
+ "approvals.decide": method(params({
49
+ agent: AgentNameSchema,
50
+ approvalId: IdSchema,
51
+ resolution: ApprovalResolutionSchema,
52
+ }),
53
+ /** `accepted` is false if another decision won or the Approval ended. */
54
+ Type.Object({ accepted: Type.Boolean() })),
55
+ "approvals.list": method(params({ agent: Type.Optional(AgentNameSchema) }), Type.Object({ approvals: Type.Array(PendingApprovalSchema) })),
56
+ /**
57
+ * Sends a one-shot prompt for `wheatley ask`. Resolves once the Agent stored the message and its Run. The Run uses
58
+ * the CLI Chat's current Conversation (`cli` binding, Chat `default`), as `chat.send` does, so the dashboard shows it.
59
+ *
60
+ * `interactive: false` (for a CLI without a TTY) makes the gate deny every `ask` Tool without a prompt (ADR 0011).
61
+ * The client matches the reply by `runId`: the `chat.message` event with that `runId`, then `run.finished`.
62
+ */
63
+ "chat.ask": method(params({
64
+ agent: AgentNameSchema,
65
+ attachments: Type.Optional(Type.Array(AttachmentUploadSchema)),
66
+ interactive: Type.Boolean(),
67
+ senderDisplayName: Type.Optional(Type.String({ maxLength: DISPLAY_NAME_MAX_LENGTH })),
68
+ text: Type.String({ minLength: 1 }),
69
+ }), Type.Object({
70
+ conversationId: IdSchema,
71
+ messageId: IdSchema,
72
+ runId: IdSchema,
73
+ })),
74
+ "chat.command": method(params({
75
+ agent: AgentNameSchema,
76
+ args: Type.Optional(Type.String()),
77
+ name: CommandNameSchema,
78
+ }), Type.Object({ accepted: Type.Boolean() })),
79
+ "chat.history": method(params({ agent: AgentNameSchema, before: Type.Optional(IdSchema), limit }), Type.Object({
80
+ conversationId: IdSchema,
81
+ hasMore: Type.Boolean(),
82
+ messages: Type.Array(ChatMessageSchema),
83
+ })),
84
+ /** Sends a message to the Agent's CLI Chat (`cli` binding, Chat `default`), which the dashboard shares. */
85
+ "chat.send": method(params({
86
+ agent: AgentNameSchema,
87
+ attachments: Type.Optional(Type.Array(AttachmentUploadSchema)),
88
+ senderDisplayName: Type.Optional(Type.String({ maxLength: DISPLAY_NAME_MAX_LENGTH })),
89
+ text: Type.String(),
90
+ }), Type.Object({ messageId: IdSchema })),
91
+ "config.get": method(params({}), Type.Object({
92
+ config: DeploymentConfigSchema,
93
+ pendingRestart: Type.Array(PendingRestartSchema),
94
+ raw: Type.String(),
95
+ revision,
96
+ })),
97
+ /** Saves raw YAML or a structured config. The Config Store keeps YAML comments in both cases (ADR 0004). */
98
+ "config.save": method(Type.Union([
99
+ params({
100
+ expectedRevision: revision,
101
+ raw: Type.String(),
102
+ restart: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("affected")])),
103
+ }),
104
+ params({
105
+ config: DeploymentConfigSchema,
106
+ expectedRevision: revision,
107
+ restart: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("affected")])),
108
+ }),
109
+ ]), Type.Object({ pendingRestart: Type.Array(PendingRestartSchema), revision })),
110
+ "config.validate": method(params({ raw: Type.String() }), Type.Object({
111
+ issues: Type.Array(ConfigIssueSchema),
112
+ valid: Type.Boolean(),
113
+ })),
114
+ "deliveries.dismiss": method(params({ agent: AgentNameSchema, deliveryId: IdSchema }), Type.Object({ dismissed: Type.Boolean() })),
115
+ "deliveries.listFailed": method(params({ agent: Type.Optional(AgentNameSchema) }), Type.Object({ deliveries: Type.Array(FailedDeliverySchema) })),
116
+ "deliveries.retry": method(params({ agent: AgentNameSchema, deliveryId: IdSchema }), Type.Object({ requeued: Type.Boolean() })),
117
+ "events.subscribe": method(params({
118
+ /** Omitted: the events of every Agent. */
119
+ agents: Type.Optional(Type.Array(AgentNameSchema)),
120
+ /** Omitted: every topic. */
121
+ topics: Type.Optional(Type.Array(EventTopicSchema)),
122
+ }), Type.Object({ subscriptionId: IdSchema })),
123
+ "events.unsubscribe": method(params({ subscriptionId: IdSchema }), Type.Object({ removed: Type.Boolean() })),
124
+ "extensions.list": method(agentParams, Type.Object({
125
+ frontends: Type.Array(BindingStatusSchema),
126
+ mcpServers: Type.Array(ExtensionStatusSchema),
127
+ plugins: Type.Array(ExtensionStatusSchema),
128
+ skills: Type.Array(SkillInfoSchema),
129
+ tools: Type.Array(ToolInfoSchema),
130
+ })),
131
+ "logs.tail": method(params({
132
+ agent: Type.Optional(AgentNameSchema),
133
+ level: Type.Optional(LogLevelSchema),
134
+ limit,
135
+ module: Type.Optional(Type.String()),
136
+ }), Type.Object({ records: Type.Array(LogRecordSchema) })),
137
+ "memory.consolidate": method(agentParams, Type.Object({ runId: IdSchema })),
138
+ "memory.consolidationLog": method(params({ agent: AgentNameSchema, limit }), Type.Object({ entries: Type.Array(ConsolidationLogEntrySchema) })),
139
+ "memory.delete": method(params({ agent: AgentNameSchema, name: MemoryNameSchema }), Type.Object({ deleted: Type.Boolean() })),
140
+ "memory.list": method(agentParams, Type.Object({
141
+ budget: MemoryBudgetSchema,
142
+ files: Type.Array(MemoryFileSchema),
143
+ })),
144
+ "memory.purgeConversation": method(params({ agent: AgentNameSchema, conversationId: IdSchema }), Type.Object({ purgedMessages: Count })),
145
+ "memory.read": method(params({ agent: AgentNameSchema, name: MemoryNameSchema }), Type.Object({ content: Type.String(), name: MemoryNameSchema })),
146
+ "memory.reindex": method(agentParams, Type.Object({ files: Count })),
147
+ "memory.search": method(params({
148
+ agent: AgentNameSchema,
149
+ limit,
150
+ query: Type.String({ minLength: 1 }),
151
+ scope: Type.Optional(MemorySearchScopeSchema),
152
+ }), Type.Object({ hits: Type.Array(MemorySearchHitSchema) })),
153
+ /** Rejects with `memory_budget_exceeded` if a `MEMORY.md` write exceeds the character cap. */
154
+ "memory.write": method(params({
155
+ agent: AgentNameSchema,
156
+ content: Type.String(),
157
+ mode: Type.Optional(Type.Union([Type.Literal("replace"), Type.Literal("append")])),
158
+ name: MemoryNameSchema,
159
+ }), Type.Object({ file: MemoryFileSchema })),
160
+ "runs.get": method(params({ agent: AgentNameSchema, runId: IdSchema }), Type.Object({
161
+ run: RunSummarySchema,
162
+ timeline: Type.Array(RunTimelineItemSchema),
163
+ })),
164
+ "runs.list": method(params({
165
+ agent: Type.Optional(AgentNameSchema),
166
+ before: Type.Optional(IdSchema),
167
+ limit,
168
+ status: Type.Optional(Type.Union([Type.Literal("active"), Type.Literal("all")])),
169
+ }), Type.Object({ hasMore: Type.Boolean(), runs: Type.Array(RunSummarySchema) })),
170
+ "runs.stop": method(params({ agent: AgentNameSchema, runId: IdSchema }), Type.Object({ stopped: Type.Boolean() })),
171
+ "secrets.delete": method(params({ name: SecretNameSchema }), Type.Object({ deleted: Type.Boolean() })),
172
+ "secrets.list": method(params({}), Type.Object({ secrets: Type.Array(SecretInfoSchema) })),
173
+ /** Returns one plaintext secret value. Wheatley never logs it. */
174
+ "secrets.reveal": method(params({ name: SecretNameSchema }), Type.Object({ value: Type.String() })),
175
+ /** Adds or rotates a secret in `secrets.yaml`. */
176
+ "secrets.set": method(params({ name: SecretNameSchema, value: Type.String({ minLength: 1 }) }), Type.Object({ source: SecretSourceSchema })),
177
+ /** The first request of every connection. Fails with `protocol_mismatch` for another protocol version. */
178
+ "system.hello": method(params({
179
+ client: Type.Object({ name: Type.String(), version: Type.String() }),
180
+ protocolVersion: Type.Integer({ minimum: 1 }),
181
+ }), Type.Object({
182
+ protocolVersion: Type.Integer({ minimum: 1 }),
183
+ wheatleyVersion: Type.String(),
184
+ })),
185
+ "system.status": method(params({}), DaemonStatusSchema),
186
+ "triggers.create": method(params({ agent: AgentNameSchema, trigger: TriggerInputSchema }), Type.Object({ trigger: TriggerSchema })),
187
+ "triggers.delete": method(params({ agent: AgentNameSchema, triggerId: IdSchema }), Type.Object({ deleted: Type.Boolean() })),
188
+ /** Fires a TriggerSchema now, outside its schedule. */
189
+ "triggers.fire": method(params({ agent: AgentNameSchema, triggerId: IdSchema }), Type.Object({ runId: IdSchema })),
190
+ "triggers.list": method(agentParams, Type.Object({ triggers: Type.Array(TriggerSchema) })),
191
+ "triggers.update": method(params({
192
+ agent: AgentNameSchema,
193
+ patch: TriggerPatchSchema,
194
+ triggerId: IdSchema,
195
+ }), Type.Object({ trigger: TriggerSchema })),
196
+ };
197
+ /** Returns true if `name` is a v1 method. */
198
+ export const isMethodName = (name) => Object.hasOwn(methods, name);
199
+ /** The names of all v1 methods. */
200
+ export const METHOD_NAMES = Object.keys(methods).filter(isMethodName);
201
+ //# sourceMappingURL=methods.js.map
@@ -0,0 +1,45 @@
1
+ import type { JsonValue } from "./json.js";
2
+ /** JSON-RPC 2.0 error codes, plus Wheatley codes in the server error range. */
3
+ export declare const RpcErrorCode: {
4
+ /** An Agent is stopped or degraded. */
5
+ readonly AgentUnavailable: -32002;
6
+ readonly AgentNotFound: -32001;
7
+ /** The config is invalid. `data.issues` lists `ConfigIssue` values. */
8
+ readonly ConfigInvalid: -32005;
9
+ /** The target already exists or is busy, for example `agents.create` for an existing name. */
10
+ readonly Conflict: -32007;
11
+ readonly InternalError: -32603;
12
+ readonly InvalidParams: -32602;
13
+ readonly InvalidRequest: -32600;
14
+ /** A `MEMORY.md` write exceeds the character cap. */
15
+ readonly MemoryBudgetExceeded: -32006;
16
+ readonly MethodNotFound: -32601;
17
+ /** An Approval, Run, Trigger, Memory file, secret, or delivery does not exist. */
18
+ readonly NotFound: -32004;
19
+ readonly ParseError: -32700;
20
+ /** The client and daemon speak different protocol versions. */
21
+ readonly ProtocolMismatch: -32000;
22
+ /** `expectedRevision` does not match the current `config.yaml`. `data.revision` is the current revision. */
23
+ readonly RevisionConflict: -32003;
24
+ };
25
+ /** A JSON-RPC error code. */
26
+ export type RpcErrorCodeValue = (typeof RpcErrorCode)[keyof typeof RpcErrorCode];
27
+ /** The `error` member of a JSON-RPC error response. */
28
+ export interface RpcErrorObject {
29
+ readonly code: RpcErrorCodeValue;
30
+ readonly message: string;
31
+ readonly data?: JsonValue;
32
+ }
33
+ /**
34
+ * An error that a JSON-RPC handler throws to send a specific error response. The router sends any other thrown error
35
+ * as `InternalError` without its message.
36
+ */
37
+ export declare class RpcError extends Error {
38
+ readonly name = "RpcError";
39
+ readonly code: RpcErrorCodeValue;
40
+ readonly data: JsonValue | undefined;
41
+ constructor(code: RpcErrorCodeValue, message: string, data?: JsonValue);
42
+ /** The error as a JSON-RPC `error` member. */
43
+ toObject(): RpcErrorObject;
44
+ }
45
+ //# sourceMappingURL=rpc-error.d.ts.map
@@ -0,0 +1,44 @@
1
+ /** JSON-RPC 2.0 error codes, plus Wheatley codes in the server error range. */
2
+ export const RpcErrorCode = {
3
+ /** An Agent is stopped or degraded. */
4
+ AgentUnavailable: -32_002,
5
+ AgentNotFound: -32_001,
6
+ /** The config is invalid. `data.issues` lists `ConfigIssue` values. */
7
+ ConfigInvalid: -32_005,
8
+ /** The target already exists or is busy, for example `agents.create` for an existing name. */
9
+ Conflict: -32_007,
10
+ InternalError: -32_603,
11
+ InvalidParams: -32_602,
12
+ InvalidRequest: -32_600,
13
+ /** A `MEMORY.md` write exceeds the character cap. */
14
+ MemoryBudgetExceeded: -32_006,
15
+ MethodNotFound: -32_601,
16
+ /** An Approval, Run, Trigger, Memory file, secret, or delivery does not exist. */
17
+ NotFound: -32_004,
18
+ ParseError: -32_700,
19
+ /** The client and daemon speak different protocol versions. */
20
+ ProtocolMismatch: -32_000,
21
+ /** `expectedRevision` does not match the current `config.yaml`. `data.revision` is the current revision. */
22
+ RevisionConflict: -32_003,
23
+ };
24
+ /**
25
+ * An error that a JSON-RPC handler throws to send a specific error response. The router sends any other thrown error
26
+ * as `InternalError` without its message.
27
+ */
28
+ export class RpcError extends Error {
29
+ name = "RpcError";
30
+ code;
31
+ data;
32
+ constructor(code, message, data) {
33
+ super(message);
34
+ this.code = code;
35
+ this.data = data;
36
+ }
37
+ /** The error as a JSON-RPC `error` member. */
38
+ toObject() {
39
+ return this.data === undefined
40
+ ? { code: this.code, message: this.message }
41
+ : { code: this.code, data: this.data, message: this.message };
42
+ }
43
+ }
44
+ //# sourceMappingURL=rpc-error.js.map
@@ -0,0 +1,20 @@
1
+ import type { Static, TSchema } from "typebox";
2
+ import type { JsonValue } from "./json.js";
3
+ /** One validation problem. `path` is a JSON Pointer into the value, for example `/agents/home/model`. */
4
+ export interface ValidationIssue {
5
+ readonly path: string;
6
+ readonly message: string;
7
+ }
8
+ /** The result of `decode`. */
9
+ export type Decoded<T> = {
10
+ readonly ok: true;
11
+ readonly value: T;
12
+ } | {
13
+ readonly ok: false;
14
+ readonly issues: readonly ValidationIssue[];
15
+ };
16
+ /** Lists the problems of `value` against `schema`. Returns an empty list for a valid value. */
17
+ export declare const validationIssues: (schema: TSchema, value: JsonValue) => ValidationIssue[];
18
+ /** Checks `value` against a protocol schema and returns it typed, or the validation issues. */
19
+ export declare const decode: <Schema extends TSchema>(schema: Schema, value: JsonValue) => Decoded<Static<Schema>>;
20
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { Value } from "typebox/value";
2
+ /** Lists the problems of `value` against `schema`. Returns an empty list for a valid value. */
3
+ export const validationIssues = (schema, value) => Value.Errors(schema, value).map((error) => ({
4
+ message: error.message,
5
+ path: error.instancePath === "" ? "/" : error.instancePath,
6
+ }));
7
+ /** Checks `value` against a protocol schema and returns it typed, or the validation issues. */
8
+ export const decode = (schema, value) => Value.Check(schema, value)
9
+ ? { ok: true, value }
10
+ : { issues: validationIssues(schema, value), ok: false };
11
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1,14 @@
1
+ {
2
+ "dependencies": {
3
+ "typebox": "1.4.7"
4
+ },
5
+ "exports": {
6
+ ".": {
7
+ "default": "./dist/index.js",
8
+ "types": "./dist/index.d.ts"
9
+ }
10
+ },
11
+ "name": "@wheatley-ai/protocol",
12
+ "type": "module",
13
+ "version": "0.0.0"
14
+ }
@@ -0,0 +1,11 @@
1
+ /** The smallest `maxLength` that `chunkMarkdown` accepts. Smaller limits leave no room for code fences. */
2
+ export declare const MIN_CHUNK_LENGTH = 32;
3
+ /**
4
+ * Splits Markdown into chunks of at most `maxLength` UTF-16 code units for platform message limits.
5
+ *
6
+ * Breaks between paragraphs first, then between lines, then at spaces. A fenced code block that does not fit is
7
+ * closed at the end of one chunk and reopened with the same info string at the start of the next. Returns `[text]` if
8
+ * the text fits. Throws a `RangeError` if `maxLength` is not an integer of at least `MIN_CHUNK_LENGTH`.
9
+ */
10
+ export declare const chunkMarkdown: (text: string, maxLength: number) => string[];
11
+ //# sourceMappingURL=chunk.d.ts.map
@@ -0,0 +1,162 @@
1
+ /** The smallest `maxLength` that `chunkMarkdown` accepts. Smaller limits leave no room for code fences. */
2
+ export const MIN_CHUNK_LENGTH = 32;
3
+ const FENCE_OPEN = /^ {0,3}(?<marker>`{3,}|~{3,})/u;
4
+ const BLANK_LINE = /^\s*$/u;
5
+ const MAX_BMP_CODE_POINT = 0xff_ff;
6
+ /** Below this many code units per chunk for code lines, a fence costs more than it helps. */
7
+ const MIN_CODE_BUDGET = 8;
8
+ const isFenceClose = (line, marker) => {
9
+ const trimmed = line.trim();
10
+ const fenceCharacter = marker.charAt(0);
11
+ return (trimmed.length >= marker.length &&
12
+ trimmed.replaceAll(fenceCharacter, "") === "");
13
+ };
14
+ const renderBlock = (block) => block.kind === "text"
15
+ ? block.lines.join("\n")
16
+ : [
17
+ block.opener,
18
+ ...block.lines,
19
+ ...(block.closer === "" ? [] : [block.closer]),
20
+ ].join("\n");
21
+ const parseBlocks = (text) => {
22
+ const blocks = [];
23
+ const lines = text.split("\n");
24
+ let paragraph = [];
25
+ let index = 0;
26
+ const endParagraph = () => {
27
+ if (paragraph.length > 0) {
28
+ blocks.push({ kind: "text", lines: paragraph });
29
+ paragraph = [];
30
+ }
31
+ };
32
+ while (index < lines.length) {
33
+ const line = lines[index] ?? "";
34
+ const marker = FENCE_OPEN.exec(line)?.groups?.marker;
35
+ if (marker !== undefined) {
36
+ endParagraph();
37
+ const body = [];
38
+ let closer = "";
39
+ index += 1;
40
+ while (index < lines.length) {
41
+ const inner = lines[index] ?? "";
42
+ index += 1;
43
+ if (isFenceClose(inner, marker)) {
44
+ closer = inner;
45
+ break;
46
+ }
47
+ body.push(inner);
48
+ }
49
+ blocks.push({ closer, kind: "code", lines: body, opener: line });
50
+ }
51
+ else if (BLANK_LINE.test(line)) {
52
+ endParagraph();
53
+ index += 1;
54
+ }
55
+ else {
56
+ paragraph.push(line);
57
+ index += 1;
58
+ }
59
+ }
60
+ endParagraph();
61
+ return blocks;
62
+ };
63
+ /** Cuts at `limit` code units, one earlier if the cut would split a surrogate pair. */
64
+ const safeCut = (text, limit) => {
65
+ const splitsPair = (text.codePointAt(limit - 1) ?? 0) > MAX_BMP_CODE_POINT;
66
+ return splitsPair && limit > 1 ? limit - 1 : limit;
67
+ };
68
+ /** Splits one line into pieces of at most `limit` code units, at the last space when possible. */
69
+ const splitLine = (line, limit) => {
70
+ const pieces = [];
71
+ let rest = line;
72
+ while (rest.length > limit) {
73
+ const space = rest.lastIndexOf(" ", limit);
74
+ const cut = space > 0 ? space : safeCut(rest, limit);
75
+ pieces.push(rest.slice(0, cut));
76
+ rest = space > 0 ? rest.slice(cut + 1) : rest.slice(cut);
77
+ }
78
+ pieces.push(rest);
79
+ return pieces;
80
+ };
81
+ /** Packs lines into groups whose newline-joined length is at most `limit`. */
82
+ const packLines = (lines, limit) => {
83
+ const groups = [];
84
+ let group = [];
85
+ let groupLength = 0;
86
+ for (const line of lines.flatMap((entry) => splitLine(entry, limit))) {
87
+ const added = group.length === 0 ? line.length : groupLength + 1 + line.length;
88
+ if (added > limit && group.length > 0) {
89
+ groups.push(group);
90
+ group = [line];
91
+ groupLength = line.length;
92
+ }
93
+ else {
94
+ group.push(line);
95
+ groupLength = added;
96
+ }
97
+ }
98
+ if (group.length > 0) {
99
+ groups.push(group);
100
+ }
101
+ return groups;
102
+ };
103
+ const splitBlock = (block, maxLength) => {
104
+ if (block.kind === "text") {
105
+ return packLines(block.lines, maxLength).map((group) => group.join("\n"));
106
+ }
107
+ const marker = FENCE_OPEN.exec(block.opener)?.groups?.marker ?? "```";
108
+ const budget = maxLength - block.opener.length - marker.length - 2;
109
+ if (budget < MIN_CODE_BUDGET) {
110
+ return splitBlock({ kind: "text", lines: renderBlock(block).split("\n") }, maxLength);
111
+ }
112
+ const groups = packLines(block.lines, budget);
113
+ return groups.map((group, position) => {
114
+ const isLast = position === groups.length - 1;
115
+ const closer = isLast ? block.closer : marker;
116
+ return renderBlock({
117
+ closer,
118
+ kind: "code",
119
+ lines: group,
120
+ opener: block.opener,
121
+ });
122
+ });
123
+ };
124
+ /**
125
+ * Splits Markdown into chunks of at most `maxLength` UTF-16 code units for platform message limits.
126
+ *
127
+ * Breaks between paragraphs first, then between lines, then at spaces. A fenced code block that does not fit is
128
+ * closed at the end of one chunk and reopened with the same info string at the start of the next. Returns `[text]` if
129
+ * the text fits. Throws a `RangeError` if `maxLength` is not an integer of at least `MIN_CHUNK_LENGTH`.
130
+ */
131
+ export const chunkMarkdown = (text, maxLength) => {
132
+ if (!Number.isInteger(maxLength) || maxLength < MIN_CHUNK_LENGTH) {
133
+ throw new RangeError(`maxLength must be an integer of at least ${MIN_CHUNK_LENGTH}`);
134
+ }
135
+ if (text.length <= maxLength) {
136
+ return [text];
137
+ }
138
+ const chunks = [];
139
+ let current = "";
140
+ for (const block of parseBlocks(text)) {
141
+ const rendered = renderBlock(block);
142
+ const joined = current === "" ? rendered : `${current}\n\n${rendered}`;
143
+ if (joined.length <= maxLength) {
144
+ current = joined;
145
+ }
146
+ else {
147
+ if (current !== "") {
148
+ chunks.push(current);
149
+ }
150
+ const pieces = rendered.length <= maxLength
151
+ ? [rendered]
152
+ : splitBlock(block, maxLength);
153
+ chunks.push(...pieces.slice(0, -1));
154
+ current = pieces.at(-1) ?? "";
155
+ }
156
+ }
157
+ if (current !== "") {
158
+ chunks.push(current);
159
+ }
160
+ return chunks;
161
+ };
162
+ //# sourceMappingURL=chunk.js.map
@@ -0,0 +1,48 @@
1
+ /** The built-in Chat commands, without the leading slash (ADR 0007). */
2
+ export type CommandName = "new" | "model" | "compact" | "stop" | "goal" | "status" | "restart";
3
+ /** A built-in Chat command. Frontend Bindings register these as native platform commands. */
4
+ export interface CommandSpec {
5
+ readonly name: CommandName;
6
+ readonly description: string;
7
+ /** A short hint for the argument, for example `<model-id>`. Absent if the command takes no argument. */
8
+ readonly argument?: string;
9
+ }
10
+ /** The seven built-in Chat commands, in menu order. */
11
+ export declare const BUILTIN_COMMANDS: readonly [{
12
+ readonly description: "Start a new Conversation in this Chat";
13
+ readonly name: "new";
14
+ }, {
15
+ readonly argument: "<model-id>";
16
+ readonly description: "Use another model for this Conversation";
17
+ readonly name: "model";
18
+ }, {
19
+ readonly description: "Compact the current Conversation";
20
+ readonly name: "compact";
21
+ }, {
22
+ readonly description: "Stop the active Run in this Chat";
23
+ readonly name: "stop";
24
+ }, {
25
+ readonly argument: "<objective>";
26
+ readonly description: "Start a long-running autonomous Run";
27
+ readonly name: "goal";
28
+ }, {
29
+ readonly description: "Show the Conversation, Run, model, and Agent health";
30
+ readonly name: "status";
31
+ }, {
32
+ readonly description: "Restart this Agent";
33
+ readonly name: "restart";
34
+ }];
35
+ /** A Chat command parsed from message text. */
36
+ export interface ParsedCommand {
37
+ readonly name: CommandName;
38
+ /** The trimmed text after the command, or `undefined` if none follows. */
39
+ readonly args: string | undefined;
40
+ }
41
+ /**
42
+ * Parses `/name args` into a built-in command.
43
+ *
44
+ * Accepts a Telegram-style bot suffix (`/new@my_bot`). Returns `undefined` if the text is not a built-in command, so
45
+ * the Frontend Binding sends it as a normal message.
46
+ */
47
+ export declare const parseCommandText: (text: string) => ParsedCommand | undefined;
48
+ //# sourceMappingURL=commands.d.ts.map
@@ -0,0 +1,39 @@
1
+ /** The seven built-in Chat commands, in menu order. */
2
+ export const BUILTIN_COMMANDS = [
3
+ { description: "Start a new Conversation in this Chat", name: "new" },
4
+ {
5
+ argument: "<model-id>",
6
+ description: "Use another model for this Conversation",
7
+ name: "model",
8
+ },
9
+ { description: "Compact the current Conversation", name: "compact" },
10
+ { description: "Stop the active Run in this Chat", name: "stop" },
11
+ {
12
+ argument: "<objective>",
13
+ description: "Start a long-running autonomous Run",
14
+ name: "goal",
15
+ },
16
+ {
17
+ description: "Show the Conversation, Run, model, and Agent health",
18
+ name: "status",
19
+ },
20
+ { description: "Restart this Agent", name: "restart" },
21
+ ];
22
+ const COMMAND_TEXT = /^\/(?<name>[a-z]+)(?:@\S+)?(?:\s+(?<args>[\s\S]*))?$/u;
23
+ const isCommandName = (name) => BUILTIN_COMMANDS.some((command) => command.name === name);
24
+ /**
25
+ * Parses `/name args` into a built-in command.
26
+ *
27
+ * Accepts a Telegram-style bot suffix (`/new@my_bot`). Returns `undefined` if the text is not a built-in command, so
28
+ * the Frontend Binding sends it as a normal message.
29
+ */
30
+ export const parseCommandText = (text) => {
31
+ const match = COMMAND_TEXT.exec(text.trim());
32
+ const name = match?.groups?.name;
33
+ if (name === undefined || !isCommandName(name)) {
34
+ return undefined;
35
+ }
36
+ const args = match?.groups?.args?.trim();
37
+ return { args: args === undefined || args === "" ? undefined : args, name };
38
+ };
39
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1,29 @@
1
+ /** How the outbox treats a failed delivery. */
2
+ export type DeliveryFailureKind = "retryable" | "permanent";
3
+ /** Options for a `DeliveryError`. */
4
+ export interface DeliveryErrorOptions {
5
+ readonly kind: DeliveryFailureKind;
6
+ /** The platform's requested wait before a retry, for example from HTTP 429 `Retry-After`. */
7
+ readonly retryAfterMs?: number;
8
+ readonly cause?: unknown;
9
+ }
10
+ /**
11
+ * The error that `FrontendBinding.deliver` rejects with.
12
+ *
13
+ * `permanent` errors (deleted Chat, removed bot) fail the delivery at once. `retryable` errors (network error, HTTP
14
+ * 5xx or 429, binding restart) retry with backoff (ADR 0010).
15
+ */
16
+ export declare class DeliveryError extends Error {
17
+ readonly name = "DeliveryError";
18
+ readonly kind: DeliveryFailureKind;
19
+ readonly retryAfterMs: number | undefined;
20
+ constructor(message: string, options: DeliveryErrorOptions);
21
+ }
22
+ /**
23
+ * Returns true if `cause` is a `DeliveryError`.
24
+ *
25
+ * Checks the name and fields instead of `instanceof`, so errors from a Plugin that bundles its own copy of
26
+ * `@wheatley-ai/sdk` also match.
27
+ */
28
+ export declare const isDeliveryError: (cause: unknown) => cause is DeliveryError;
29
+ //# sourceMappingURL=delivery-error.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The error that `FrontendBinding.deliver` rejects with.
3
+ *
4
+ * `permanent` errors (deleted Chat, removed bot) fail the delivery at once. `retryable` errors (network error, HTTP
5
+ * 5xx or 429, binding restart) retry with backoff (ADR 0010).
6
+ */
7
+ export class DeliveryError extends Error {
8
+ name = "DeliveryError";
9
+ kind;
10
+ retryAfterMs;
11
+ constructor(message, options) {
12
+ super(message, { cause: options.cause });
13
+ this.kind = options.kind;
14
+ this.retryAfterMs = options.retryAfterMs;
15
+ }
16
+ }
17
+ /**
18
+ * Returns true if `cause` is a `DeliveryError`.
19
+ *
20
+ * Checks the name and fields instead of `instanceof`, so errors from a Plugin that bundles its own copy of
21
+ * `@wheatley-ai/sdk` also match.
22
+ */
23
+ export const isDeliveryError = (cause) => cause instanceof Error &&
24
+ cause.name === "DeliveryError" &&
25
+ "kind" in cause &&
26
+ (cause.kind === "retryable" || cause.kind === "permanent");
27
+ //# sourceMappingURL=delivery-error.js.map