@stringsync/splates 0.0.0-stage → 0.0.45

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 (251) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +308 -2
  3. package/acp-extensions.d.ts +82 -0
  4. package/add.d.ts +53 -0
  5. package/adherence.d.ts +49 -0
  6. package/age.d.ts +2 -0
  7. package/agent-connection.d.ts +171 -0
  8. package/agent-errors.d.ts +2 -0
  9. package/agent-process.d.ts +65 -0
  10. package/agent-stream.d.ts +91 -0
  11. package/agents.d.ts +15 -0
  12. package/artifact-room.d.ts +47 -0
  13. package/artifact-viewers.d.ts +6 -0
  14. package/artifact.d.ts +30 -0
  15. package/artifacts.d.ts +161 -0
  16. package/asked.d.ts +146 -0
  17. package/asked.js +7 -0
  18. package/assumed.d.ts +34 -0
  19. package/attach.d.ts +30 -0
  20. package/attachments.d.ts +43 -0
  21. package/baselines.d.ts +55 -0
  22. package/claim.d.ts +17 -0
  23. package/cloudflare-api.d.ts +25 -0
  24. package/cloudflare-error.d.ts +5 -0
  25. package/cloudflared-tunnel-provider.d.ts +27 -0
  26. package/codex-limits.d.ts +19 -0
  27. package/compaction.d.ts +17 -0
  28. package/config-source.d.ts +13 -0
  29. package/config.d.ts +98 -0
  30. package/config.js +7 -0
  31. package/conversation-archive.d.ts +6 -0
  32. package/conversation-background.d.ts +21 -0
  33. package/conversation-choice.d.ts +4 -0
  34. package/conversation-files.d.ts +51 -0
  35. package/conversation-given.d.ts +8 -0
  36. package/conversation-host.d.ts +102 -0
  37. package/conversation-listing.d.ts +15 -0
  38. package/conversation-log.d.ts +301 -0
  39. package/conversation-messages.d.ts +18 -0
  40. package/conversation-name.d.ts +28 -0
  41. package/conversation-options.d.ts +73 -0
  42. package/conversation-reference.d.ts +2 -0
  43. package/conversation-state.d.ts +472 -0
  44. package/conversation-turns.d.ts +115 -0
  45. package/conversation.d.ts +209 -0
  46. package/conversations.d.ts +140 -0
  47. package/coordinator-state.d.ts +28 -0
  48. package/creds.d.ts +123 -0
  49. package/darwin-temperature.d.ts +7 -0
  50. package/decided.d.ts +18 -0
  51. package/demo.d.ts +29 -0
  52. package/dev/api.d.ts +209 -0
  53. package/dev/assets.d.ts +24 -0
  54. package/dev/conversation-address.d.ts +47 -0
  55. package/dev/conversation-feed.d.ts +166 -0
  56. package/dev/live-stream.d.ts +29 -0
  57. package/dev/worker.d.ts +33 -0
  58. package/dev-access.d.ts +61 -0
  59. package/dev-artifacts.d.ts +22 -0
  60. package/dev-budgets.d.ts +18 -0
  61. package/dev-conversation-events.d.ts +39 -0
  62. package/dev-conversation-routes.d.ts +90 -0
  63. package/dev-creds.d.ts +17 -0
  64. package/dev-dictation-connection.d.ts +18 -0
  65. package/dev-dictation.d.ts +17 -0
  66. package/dev-http.d.ts +76 -0
  67. package/dev-open.d.ts +15 -0
  68. package/dev-options.d.ts +133 -0
  69. package/dev-outcomes.d.ts +21 -0
  70. package/dev-pages.d.ts +16 -0
  71. package/dev-picker.d.ts +57 -0
  72. package/dev-port-socket.d.ts +26 -0
  73. package/dev-ports.d.ts +11 -0
  74. package/dev-project-watch.d.ts +44 -0
  75. package/dev-project.d.ts +168 -0
  76. package/dev-push.d.ts +59 -0
  77. package/dev-restart.d.ts +141 -0
  78. package/dev-servers.d.ts +30 -0
  79. package/dev-setup-native.d.ts +23 -0
  80. package/dev-setup-opencode.d.ts +29 -0
  81. package/dev-setup.d.ts +16 -0
  82. package/dev-shell.d.ts +70 -0
  83. package/dev-slot.d.ts +28 -0
  84. package/dev-sockets.d.ts +13 -0
  85. package/dev-task-ports.d.ts +73 -0
  86. package/dev-tasks.d.ts +20 -0
  87. package/dev-terminal-connection.d.ts +19 -0
  88. package/dev-terminal.d.ts +42 -0
  89. package/dev-todos.d.ts +35 -0
  90. package/dev-transcriber.d.ts +15 -0
  91. package/dev-tunnel.d.ts +38 -0
  92. package/dev-versions.d.ts +53 -0
  93. package/dev-workers.d.ts +55 -0
  94. package/dev.d.ts +24 -0
  95. package/diff.d.ts +29 -0
  96. package/dispatched.d.ts +16 -0
  97. package/editors.d.ts +22 -0
  98. package/escalate.d.ts +27 -0
  99. package/events.d.ts +311 -0
  100. package/everywhere.d.ts +41 -0
  101. package/exhibit.d.ts +21 -0
  102. package/exit.d.ts +54 -0
  103. package/fact-todos.d.ts +18 -0
  104. package/fake-agent.d.ts +107 -0
  105. package/fake-agent.js +284 -0
  106. package/finding-facts.d.ts +38 -0
  107. package/findings.d.ts +84 -0
  108. package/fold.d.ts +43 -0
  109. package/follow.d.ts +41 -0
  110. package/format.d.ts +68 -0
  111. package/git.d.ts +112 -0
  112. package/handed-out.d.ts +79 -0
  113. package/handoff.d.ts +23 -0
  114. package/heavy-run.d.ts +12 -0
  115. package/heavy.d.ts +28 -0
  116. package/heavy.js +16 -0
  117. package/held.d.ts +22 -0
  118. package/index-0tfvy823.js +272 -0
  119. package/index-43pq33n4.js +157 -0
  120. package/index-4776671w.js +698 -0
  121. package/index-d4hjrzaq.js +464 -0
  122. package/index-gcfq7awr.js +740 -0
  123. package/index-k73tsw5g.js +101 -0
  124. package/index-kaa44k7q.js +59 -0
  125. package/index-vcv9m93e.js +1265 -0
  126. package/index-xmfmy729.js +249 -0
  127. package/index.d.ts +2 -0
  128. package/index.js +26928 -0
  129. package/init.d.ts +28 -0
  130. package/journal.d.ts +57 -0
  131. package/landed.d.ts +14 -0
  132. package/lane-todos.d.ts +44 -0
  133. package/lane.d.ts +55 -0
  134. package/lanes-from-tags.d.ts +17 -0
  135. package/lanes.d.ts +96 -0
  136. package/legacy-names.d.ts +70 -0
  137. package/legacy-ps.d.ts +31 -0
  138. package/limits.d.ts +32 -0
  139. package/list.d.ts +18 -0
  140. package/load-config.d.ts +44 -0
  141. package/log.d.ts +14 -0
  142. package/machine.d.ts +42 -0
  143. package/merge.d.ts +35 -0
  144. package/migrate-config.d.ts +31 -0
  145. package/models.d.ts +24 -0
  146. package/needs.d.ts +115 -0
  147. package/notices.d.ts +39 -0
  148. package/offered.d.ts +39 -0
  149. package/opencode-usage.d.ts +37 -0
  150. package/outcomes.d.ts +114 -0
  151. package/package.json +74 -5
  152. package/path.d.ts +13 -0
  153. package/plan.d.ts +236 -0
  154. package/port-forward.d.ts +22 -0
  155. package/port-pipe.d.ts +36 -0
  156. package/ports-list.d.ts +19 -0
  157. package/probe-runtime.d.ts +5 -0
  158. package/probe-runtime.js +13 -0
  159. package/project-reaches.d.ts +23 -0
  160. package/projects.d.ts +136 -0
  161. package/prompts.d.ts +128 -0
  162. package/pty.d.ts +39 -0
  163. package/pulse.d.ts +8 -0
  164. package/recommend.d.ts +31 -0
  165. package/release.d.ts +41 -0
  166. package/remote-process.d.ts +26 -0
  167. package/remote-pty.d.ts +29 -0
  168. package/remote-worker.d.ts +77 -0
  169. package/remove.d.ts +31 -0
  170. package/repository.d.ts +91 -0
  171. package/retry.d.ts +34 -0
  172. package/roster.d.ts +63 -0
  173. package/saved-ports-host.d.ts +25 -0
  174. package/saved-tunnel.d.ts +44 -0
  175. package/server-worker-socket.d.ts +21 -0
  176. package/setup-areas.d.ts +7 -0
  177. package/setup-opencode-model-error.d.ts +3 -0
  178. package/setup-opencode-models.d.ts +54 -0
  179. package/setup-opencode-recipe.d.ts +26 -0
  180. package/setup-opencode.d.ts +46 -0
  181. package/setup.d.ts +102 -0
  182. package/shared-browser.d.ts +50 -0
  183. package/shell.d.ts +17 -0
  184. package/show.d.ts +106 -0
  185. package/skill-checks.d.ts +73 -0
  186. package/skill-checks.js +10 -0
  187. package/skills.d.ts +16 -0
  188. package/slot-tunnel.d.ts +27 -0
  189. package/slots.d.ts +135 -0
  190. package/snapshot.d.ts +75 -0
  191. package/splates-artifact.d.ts +3 -0
  192. package/splates-creds.d.ts +3 -0
  193. package/splates-dev.d.ts +22 -0
  194. package/splates-flags.d.ts +34 -0
  195. package/splates-lane.d.ts +3 -0
  196. package/splates-projects.d.ts +3 -0
  197. package/splates-setup.d.ts +17 -0
  198. package/splates-slots.d.ts +3 -0
  199. package/splates-todo.d.ts +3 -0
  200. package/splates-tunnel.d.ts +3 -0
  201. package/splates-worker.d.ts +3 -0
  202. package/splates.d.ts +28 -0
  203. package/stats.d.ts +186 -0
  204. package/supervise.d.ts +50 -0
  205. package/system-changes.d.ts +67 -0
  206. package/system.d.ts +28 -0
  207. package/systems.d.ts +119 -0
  208. package/systems.js +21 -0
  209. package/table.d.ts +5 -0
  210. package/task-log.d.ts +35 -0
  211. package/task-ports.d.ts +25 -0
  212. package/tell.d.ts +47 -0
  213. package/todo-edit.d.ts +60 -0
  214. package/todo-file.d.ts +6 -0
  215. package/todo-lanes.d.ts +82 -0
  216. package/todo-list.d.ts +26 -0
  217. package/todo-take.d.ts +27 -0
  218. package/todo.d.ts +146 -0
  219. package/todos.d.ts +157 -0
  220. package/tool-calls.d.ts +18 -0
  221. package/tunnel-provider.d.ts +37 -0
  222. package/tunnel-provider.js +0 -0
  223. package/tunnel-remove.d.ts +28 -0
  224. package/tunnel-setup.d.ts +104 -0
  225. package/unix-worker-listener.d.ts +23 -0
  226. package/unix-worker-socket.d.ts +30 -0
  227. package/update.d.ts +29 -0
  228. package/update.js +10 -0
  229. package/vocabulary.d.ts +9 -0
  230. package/wait.d.ts +36 -0
  231. package/watch.d.ts +46 -0
  232. package/watched.d.ts +43 -0
  233. package/websocket-worker-socket.d.ts +18 -0
  234. package/worker-call-host.d.ts +51 -0
  235. package/worker-channel.d.ts +83 -0
  236. package/worker-connection.d.ts +24 -0
  237. package/worker-daemon.d.ts +64 -0
  238. package/worker-git.d.ts +18 -0
  239. package/worker-list.d.ts +49 -0
  240. package/worker-machine.d.ts +34 -0
  241. package/worker-port-host.d.ts +21 -0
  242. package/worker-process-host.d.ts +29 -0
  243. package/worker-protocol.d.ts +104 -0
  244. package/worker-pty-host.d.ts +34 -0
  245. package/worker-registry.d.ts +68 -0
  246. package/worker-replay.d.ts +25 -0
  247. package/worker-run.d.ts +20 -0
  248. package/worker-session.d.ts +189 -0
  249. package/worker-socket.d.ts +15 -0
  250. package/worktree-service.d.ts +113 -0
  251. package/worktree.d.ts +232 -0
@@ -0,0 +1,171 @@
1
+ import * as acp from "@agentclientprotocol/sdk";
2
+ import type { Agent, AgentProcess, ProcessHandle } from "./agent-process.js";
3
+ import type { ConversationDeps, ConversationHost } from "./conversation-host.js";
4
+ import type { Live } from "./conversation-log.js";
5
+ import type { Answer, Setting } from "./conversation-state.js";
6
+ /**
7
+ * A conversation's side of ACP: the agent's process and the connection to
8
+ * it, what the agent asks of this side, routed to the person, and the calls
9
+ * the conversation makes on it. Opened anew each time the agent starts or
10
+ * comes back, with the same session, or reattached to a process a worker
11
+ * kept running while the coordinator restarted.
12
+ */
13
+ export declare class AgentConnection {
14
+ private readonly host;
15
+ private readonly deps;
16
+ private connection;
17
+ private process;
18
+ private stream;
19
+ /** What listens on the stream and the log while they are up. */
20
+ private listening;
21
+ /** How many times `open` has run, so a start that fails late knows it is still the latest. */
22
+ private opens;
23
+ /** The agent's session, once it has opened one. */
24
+ private session;
25
+ /** Settles the agent's pending ask with the person's answer. */
26
+ private settle;
27
+ /** Whether the agent takes a prompt into its running turn. */
28
+ private steering;
29
+ /**
30
+ * Whether the running turn is on its final answer: a prompt steered in
31
+ * now may find it ended, and the agent start a turn of its own for it.
32
+ */
33
+ private finishing;
34
+ /** Whether the agent takes images in a prompt. */
35
+ private seeing;
36
+ /** Whether the turn running is one the agent started, with no prompt to end it. */
37
+ private unprompted;
38
+ /** Whether the agent has said a turn ended, as Claude does, so one it starts can end. */
39
+ private tells;
40
+ /** Whether the agent says on its session list when a turn ends, as Codex does. */
41
+ private follows;
42
+ /**
43
+ * The turn the agent started for a steer, as Codex does when its turn
44
+ * ended on the way: when splates heard of it, in ms, and whether the
45
+ * session list has said since that it runs.
46
+ */
47
+ private following;
48
+ /** Settles once the agent has answered the last steer, which may have started a turn of its own. */
49
+ private steered;
50
+ /** The commands running, by tool call, each watched since it started. */
51
+ private readonly watching;
52
+ /** Whether the next open loads the session, replaying it, rather than resuming it. */
53
+ private loading;
54
+ /** The person's words the replay has said so far, not yet logged as a prompt. */
55
+ private heard;
56
+ /** Recovery loads replay history already in the log. */
57
+ private suppressReplay;
58
+ /** Settings picked before the session opened, set once it has. */
59
+ private picks;
60
+ /** The model asked for before the session opened, picked once it has. */
61
+ private model;
62
+ private sessionCwd;
63
+ constructor(host: ConversationHost, deps: ConversationDeps, { session, loading, picks, model, sessionCwd, }?: {
64
+ session?: string | null;
65
+ /** Whether the first open loads `session`, replaying it, rather than resuming it. */
66
+ loading?: boolean;
67
+ picks?: Record<string, string>;
68
+ model?: string | null;
69
+ sessionCwd?: string | null;
70
+ });
71
+ /** The agent's pid while it runs, for the commands it left running. */
72
+ get pid(): number | null;
73
+ /** What takes the agent's process back after a restart; null while none could. */
74
+ get handle(): ProcessHandle | null;
75
+ get sessionId(): string | null;
76
+ /** Whether the agent's process is up and speaking ACP. */
77
+ get connected(): boolean;
78
+ /** Whether the agent takes a prompt into its running turn, as it stands. */
79
+ get canSteer(): boolean;
80
+ /** Whether the agent takes images in a prompt. */
81
+ get sees(): boolean;
82
+ /** Whether the agent is waiting on the person for an answer. */
83
+ get asking(): boolean;
84
+ /**
85
+ * Runs the agent and opens a session with it: the one this conversation
86
+ * had, when there was one, else a new one.
87
+ */
88
+ open(agent: Agent, cwd: string): Promise<void>;
89
+ /**
90
+ * Speaks ACP again to `process`, which a worker kept running while the
91
+ * coordinator restarted, where the log left off: `live` says what was in
92
+ * flight. A late answer to the prompt it was on ends the turn, and the
93
+ * question it was asking is answered on the request it came in.
94
+ */
95
+ reattach(agent: Agent, process: AgentProcess, live: Live): void;
96
+ /**
97
+ * Releases the running agent for the next coordinator to reconnect.
98
+ * Flush the conversation log after awaiting this before shutting down.
99
+ */
100
+ detach(): Promise<void>;
101
+ /**
102
+ * Opens ACP over `process`, which from here is the one this conversation
103
+ * runs: its frames stamp the log, its exit closes the conversation, and
104
+ * the worker is acked for each frame once the log holds it.
105
+ */
106
+ private attach;
107
+ /** What `process` said on stderr if it exits within `DEATH_WAIT`, else null. */
108
+ private diedSaying;
109
+ /**
110
+ * Waits for no other agent to be starting, answering with what lets the
111
+ * next one start: once this one's process is up, has died, or has had
112
+ * `START_WAIT` to answer, so one that hangs holds up no other for long.
113
+ */
114
+ private startAlone;
115
+ /** Says `prompt` to the agent as a turn, settling with what it answered once the turn ends. */
116
+ prompt(prompt: acp.ContentBlock[]): Promise<acp.PromptResponse | undefined>;
117
+ /** Whether the agent runs a turn it started for a steer, which no prompt's answer ends. */
118
+ get detached(): boolean;
119
+ /** A stale or substituted choice must never reach a prompt or steering call. */
120
+ private validateModel;
121
+ /**
122
+ * Says `prompt` into the turn the agent is running, answering with what
123
+ * came of it: `injected`, `startedNewTurn`, or `promptRequired` when the
124
+ * turn ended on the way.
125
+ */
126
+ steer(prompt: acp.ContentBlock[]): Promise<string | undefined>;
127
+ private steerInto;
128
+ /** Shows the turn the agent started for a steer as running, until it ends. */
129
+ private follow;
130
+ /**
131
+ * Ends the turn being followed once the session list says it no longer
132
+ * runs. A row read before it started can come after `startedNewTurn`,
133
+ * saying the turn before it ended: it counts only once a row has said the
134
+ * turn runs, or when it ended past the second splates heard it start in,
135
+ * since the agent says when in whole seconds.
136
+ */
137
+ private listed;
138
+ /** Stops the agent's turn, if it is connected. */
139
+ cancel(): Promise<void>;
140
+ /** Stops background command `id`; the agent says it ended as it does. */
141
+ stopTask(id: string): Promise<void>;
142
+ /**
143
+ * Sets `setting` to `value`, answering with the session's settings as the
144
+ * agent then offers them: at once while it is connected, or, while it is
145
+ * not, as picked for when it next opens.
146
+ */
147
+ choose(setting: Setting, value: string): Promise<Setting[]>;
148
+ /** Settles the agent's pending ask, if `id` is still the one it is on. */
149
+ answer(id: string, answer: Answer): void;
150
+ /** Ends the process, dismissing whatever the agent was asking. */
151
+ close(): void;
152
+ /** What the agent may ask of this side, all of it routed to the person. */
153
+ private client;
154
+ /**
155
+ * Watches each command the agent runs from when it starts, and keeps what
156
+ * it did to git that it should not have once it ends.
157
+ */
158
+ private watchCommand;
159
+ /** Logs the person's words the replay has said, as one prompt. */
160
+ private logHeard;
161
+ /** Keeps how the person answered the permission asked for tool call `id`. */
162
+ private decided;
163
+ /**
164
+ * Holds `asked` until the person answers it, or the turn is cancelled,
165
+ * logged with the request it came in, so a coordinator started again can
166
+ * answer it there.
167
+ */
168
+ private ask;
169
+ /** Settles the pending ask, if any, with `answer`, and logs that it is answered. */
170
+ private settled;
171
+ }
@@ -0,0 +1,2 @@
1
+ /** Redacts common credential-bearing diagnostics before persistence or display. */
2
+ export declare function agentError(message: string): string;
@@ -0,0 +1,65 @@
1
+ import { type Timer } from "webappwiz/time";
2
+ /** An agent splates can hold a conversation with over ACP, and how to start it. */
3
+ export interface Agent {
4
+ id: string;
5
+ name: string;
6
+ argv: string[];
7
+ }
8
+ /** What a process wrote to stdout, numbered from 1 so a restart can say what it holds. */
9
+ export interface AgentFrame {
10
+ bytes: Uint8Array;
11
+ seq: number;
12
+ }
13
+ /** What finds a process again after a restart: the worker it runs on and its channel there. */
14
+ export interface ProcessHandle {
15
+ worker: string;
16
+ channel: number;
17
+ }
18
+ /** A running agent: bytes in, frames out, and a way to stop it. */
19
+ export interface AgentProcess {
20
+ /** Its pid, for what runs under it; null for one that never started. */
21
+ pid: number | null;
22
+ input: WritableStream<Uint8Array>;
23
+ output: ReadableStream<AgentFrame>;
24
+ /**
25
+ * Says everything up to frame `seq` is written down, so a restart replays
26
+ * from past it; nothing to do for a process that ends with this one.
27
+ */
28
+ ack(seq: number): void;
29
+ /** What takes it back after a restart; null for one that ends with this process. */
30
+ handle: ProcessHandle | null;
31
+ /** What it last wrote to stderr, for when it dies before saying why. */
32
+ stderr(): string;
33
+ exited: Promise<number>;
34
+ kill(): void;
35
+ }
36
+ /** `bytes` as frames, numbered from 1 as they come. */
37
+ export declare function framed(bytes: ReadableStream<Uint8Array>): ReadableStream<AgentFrame>;
38
+ /** Starts `argv` in `cwd`, with `env` added to its own, its stdio piped. */
39
+ export type Launch = (argv: string[], cwd: string, env: Record<string, string>) => AgentProcess;
40
+ /** What starts a conversation's agent, and takes one back after a restart. */
41
+ export interface Launcher {
42
+ launch: Launch;
43
+ /**
44
+ * The process `handle` names, kept running while this coordinator was
45
+ * away, its output carrying on from past frame `held`, the last one the
46
+ * log holds. Throws when nothing here can take it back.
47
+ */
48
+ resume(handle: ProcessHandle, held: number): AgentProcess;
49
+ }
50
+ /** `launch` alone, for a process that ends with this one: nothing takes one back. */
51
+ export declare function launcherOf(launch: Launch): Launcher;
52
+ export declare const launch: Launch;
53
+ /** A session an agent holds that splates could bring in. */
54
+ export interface Session {
55
+ agent: string;
56
+ session: string;
57
+ title: string | null;
58
+ /** When it was last active, as the agent says; null when it does not. */
59
+ updatedAt: string | null;
60
+ }
61
+ /**
62
+ * The sessions `agent` holds in `cwd`, asked of a process of its own that
63
+ * stops once it answers; none when it cannot both list and load them.
64
+ */
65
+ export declare function listSessions(agent: Agent, cwd: string, run: Launch, timer: Timer): Promise<Session[]>;
@@ -0,0 +1,91 @@
1
+ import type * as acp from "@agentclientprotocol/sdk";
2
+ import { type Eventful } from "webappwiz/events";
3
+ import type { AgentProcess } from "./agent-process.js";
4
+ /** What an `AgentStream` says beyond the messages it carries. */
5
+ export interface AgentStreamEvents extends Record<string, unknown> {
6
+ /** A message of the frame with this seq is being handed over. */
7
+ handling: number;
8
+ /** Every message of the frame with this seq has been dispatched. */
9
+ dispatched: number;
10
+ /** A response to a request sent before this stream, by an id under its base. */
11
+ stale: acp.AnyResponse;
12
+ /** A request this side sent, by the id it went out with. */
13
+ request: {
14
+ id: number;
15
+ method: string;
16
+ };
17
+ }
18
+ export interface AgentStreamOptions {
19
+ /**
20
+ * Where this side's request ids start: after a restart, give one past the
21
+ * highest id the log holds, so a late answer to an old request comes
22
+ * back as `stale` rather than as an answer to a new one.
23
+ */
24
+ base?: number;
25
+ }
26
+ /**
27
+ * ACP over an agent's frames, for the SDK's connection to read and write. It
28
+ * hands over one message at a time and waits for the connection to have
29
+ * handled it before the next, so `seq` names the frame of the message being
30
+ * handled while its handler runs. Lines are held until a frame ends on a
31
+ * newline, so a replay from past `dispatched` starts at a line and repeats
32
+ * none.
33
+ */
34
+ export declare class AgentStream implements acp.Stream, Eventful<AgentStreamEvents> {
35
+ private readonly process;
36
+ readonly readable: ReadableStream<acp.AnyMessage>;
37
+ readonly writable: WritableStream<acp.AnyMessage>;
38
+ private readonly dispatcher;
39
+ readonly events: import("webappwiz/events").Events<AgentStreamEvents>;
40
+ /** Added to every request id sent. */
41
+ readonly base: number;
42
+ private readonly frames;
43
+ private more;
44
+ private ended;
45
+ /** Text since the last frame that ended on a newline. */
46
+ private partial;
47
+ private _seq;
48
+ private _dispatched;
49
+ private _lastId;
50
+ private _asking;
51
+ /** Whether a frame has been handed over in part, which `detach` lets finish. */
52
+ private midFrame;
53
+ private detaching;
54
+ private writer;
55
+ private writing;
56
+ constructor(process: AgentProcess, { base }?: AgentStreamOptions);
57
+ /** The seq of the frame the message being handled came in, 0 before the first. */
58
+ get seq(): number;
59
+ /** The highest seq every message of whose frame has been handled. */
60
+ get dispatched(): number;
61
+ /** The id the last request this side sent went out with; null before the first. */
62
+ get lastId(): number | null;
63
+ /**
64
+ * The id of the agent's request being handled, for a handler to log
65
+ * what it is answering; null while the message being handled is not one.
66
+ */
67
+ get asking(): acp.JsonRpcId | null;
68
+ /**
69
+ * Stops handing messages over at the end of the frame being handled, so
70
+ * a log flushed after this holds whole frames only, and settles once it
71
+ * has: the frames after it stay with the process for the next stream.
72
+ */
73
+ detach(): Promise<void>;
74
+ /**
75
+ * Answers request `id` of the agent's as it was on the wire, for one a
76
+ * log holds from before this stream, which the connection never heard.
77
+ */
78
+ respond(id: acp.JsonRpcId, answer: {
79
+ result: unknown;
80
+ } | {
81
+ error: acp.ErrorResponse;
82
+ }): Promise<void>;
83
+ private read;
84
+ private pull;
85
+ private finish;
86
+ /** A response to this side's request, with the id it asked by; or null for one handed back as stale. */
87
+ private incoming;
88
+ private outgoing;
89
+ private send;
90
+ private input;
91
+ }
package/agents.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { type Logger } from "webappwiz/log";
2
+ import type { Roster } from "./roster.js";
3
+ export interface AgentsOptions {
4
+ /** Print the roster as JSON instead of tables. */
5
+ json?: boolean;
6
+ }
7
+ /**
8
+ * The roster: each agent, how it starts, and its models with what each is
9
+ * good at and costs, for an orchestrator choosing whom to delegate to. Writes
10
+ * the defaults first when there is none, and says where, so they can be edited.
11
+ */
12
+ export declare function agents({ roster, log }: {
13
+ roster: Roster;
14
+ log: Logger;
15
+ }, { json }?: AgentsOptions): Promise<void>;
@@ -0,0 +1,47 @@
1
+ import type { Fs } from "webappwiz/system";
2
+ import { type Artifacts, type ArtifactVersion } from "./artifacts.js";
3
+ /**
4
+ * Room for artifacts across a project, which every conversation's store
5
+ * makes its adds through, one at a time. An add past the project's capacity
6
+ * first evicts the bytes of other versions, in `evictionOrder`, keeping
7
+ * their records as placeholders; when even all of them would not make room,
8
+ * it is refused and nothing goes. Files attached to conversations count
9
+ * toward the capacity but are never evicted: they serve the questions that
10
+ * show them.
11
+ */
12
+ export declare class ArtifactRoom {
13
+ private readonly deps;
14
+ private queue;
15
+ constructor(deps: {
16
+ fs: Fs;
17
+ /** Where every conversation of the project keeps its files. */
18
+ dir: string;
19
+ /** How many bytes every conversation may keep together. */
20
+ capacity: number;
21
+ /** Every conversation's store, and whether it is archived. */
22
+ shelves: () => ArtifactShelf[];
23
+ });
24
+ /** Runs `work` once every add before it has finished. */
25
+ hold<T>(work: () => Promise<T>): Promise<T>;
26
+ /**
27
+ * Evicts what it must for `bytes` more of the artifact `name` to fit, or
28
+ * refuses `too_large`, evicting nothing, when it cannot.
29
+ */
30
+ make(bytes: number, name: string): Promise<void>;
31
+ }
32
+ /** One conversation's store, as the room sees it. */
33
+ export interface ArtifactShelf {
34
+ store: Artifacts;
35
+ archived: boolean;
36
+ }
37
+ /**
38
+ * Every version whose bytes are kept, in the order eviction takes them:
39
+ * removed and superseded ones of any conversation first, then the shown ones
40
+ * of archived conversations, then those of live ones; oldest first within
41
+ * each.
42
+ */
43
+ export declare function evictionOrder(shelves: ArtifactShelf[]): {
44
+ store: Artifacts;
45
+ name: string;
46
+ version: ArtifactVersion;
47
+ }[];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * How the page shows an artifact of `mimeType`: an image or a recording in
3
+ * the lightbox, a page in a sandboxed frame, or null for one it only offers
4
+ * as a download, which the server sends as an attachment to match.
5
+ */
6
+ export declare function viewerOf(mimeType: string): "image" | "video" | "page" | null;
package/artifact.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { type Logger } from "webappwiz/log";
2
+ import type { Fs, Ps } from "webappwiz/system";
3
+ import { type ArtifactVersion } from "./artifacts.js";
4
+ import type { WorktreeService } from "./worktree-service.js";
5
+ /** What `fetch` is used for here, so a test can stand in for it. */
6
+ type Send = (url: string, init: RequestInit) => Promise<Response>;
7
+ export interface ArtifactDeps {
8
+ service: WorktreeService;
9
+ log: Logger;
10
+ fs: Fs;
11
+ ps: Ps;
12
+ send?: Send;
13
+ }
14
+ /**
15
+ * Keeps `file` as the next version of the artifact of that name in the
16
+ * conversation `id`, through the `splates server` serving this repository when
17
+ * the agent has one in its env, so the page hears of it, else straight into
18
+ * the conversation's log.
19
+ */
20
+ export declare function addArtifact(deps: ArtifactDeps, id: string, file: {
21
+ name: string;
22
+ bytes: Uint8Array;
23
+ }): Promise<ArtifactVersion>;
24
+ /** Marks the artifact `name` of conversation `id` removed; answers the version that was current. */
25
+ export declare function removeArtifact(deps: ArtifactDeps, id: string, name: string): Promise<number>;
26
+ /** Prints what the conversation `id` holds, or, given a `name`, that artifact's versions. */
27
+ export declare function listArtifacts(deps: ArtifactDeps, id: string, name?: string): Promise<void>;
28
+ /** The media type `name`'s extension says, else plain bytes. */
29
+ export declare function mimeTypeOf(name: string): string;
30
+ export {};
package/artifacts.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import { type IdProvider } from "webappwiz/id";
2
+ import type { Fs } from "webappwiz/system";
3
+ import type { ArtifactRoom } from "./artifact-room.js";
4
+ import type { Config } from "./config.js";
5
+ /**
6
+ * A conversation's artifacts: their bytes, in `artifacts/` beside its log's
7
+ * other files, and their record, `held`, which each change goes to through
8
+ * `record` (the log, then the state) once its bytes are in place. One change
9
+ * at a time, so two adds of one name never take the same version.
10
+ */
11
+ export declare class Artifacts {
12
+ private readonly deps;
13
+ /** Where the bytes are kept. */
14
+ readonly dir: string;
15
+ /** Where every conversation of the project keeps its files. */
16
+ private readonly conversations;
17
+ private readonly ids;
18
+ private queue;
19
+ constructor(
20
+ /** The conversation's log, whose files directory holds the artifacts. */
21
+ log: string, deps: {
22
+ fs: Fs;
23
+ now: () => string;
24
+ limits: ArtifactLimits;
25
+ ids?: IdProvider;
26
+ /** The record as it stands. */
27
+ held: () => Artifact[];
28
+ /** Keeps `change`, folding it into `held`. */
29
+ record: (change: ArtifactChange) => Promise<void>;
30
+ /**
31
+ * The project's room, which evicts what other versions it must
32
+ * for an add past the project's capacity; without it, as for a
33
+ * CLI that reaches no `splates server`, such an add is refused.
34
+ */
35
+ room?: ArtifactRoom;
36
+ });
37
+ /** The record as it stands. */
38
+ get held(): Artifact[];
39
+ /**
40
+ * Keeps `file` as the next version of the artifact named for it, listing
41
+ * it again if it was removed. Past the project's capacity, its room evicts
42
+ * what it can first; refuses one past any limit still `too_large`,
43
+ * changing nothing.
44
+ */
45
+ add(file: ArtifactFile): Promise<ArtifactVersion>;
46
+ /** Marks the artifact `name` removed, keeping every version's bytes for cleanup. */
47
+ remove(name: string): Promise<void>;
48
+ /**
49
+ * Deletes the bytes of `version` of the artifact `name`, saying `why`,
50
+ * and keeps its record, so it shows as a placeholder.
51
+ */
52
+ delete(name: string, version: number, why: ArtifactGone): Promise<void>;
53
+ /**
54
+ * Deletes the bytes of every version no longer shown, those of removed
55
+ * artifacts and those a later one superseded, as its conversation is
56
+ * archived: what stays is what its panel still lists.
57
+ */
58
+ archive(): Promise<void>;
59
+ /**
60
+ * The bytes and media type of `version` of the artifact `name`, its
61
+ * current one by default; null when there is no such version or its
62
+ * bytes are gone.
63
+ */
64
+ read(name: string, version?: number): Promise<{
65
+ bytes: Uint8Array;
66
+ mimeType: string;
67
+ } | null>;
68
+ /**
69
+ * Refuses `file` when it has no name, or when it or this conversation
70
+ * would pass its limit; its size when it fits.
71
+ */
72
+ private admit;
73
+ /** Writes `file`'s bytes and records them as its name's next version. */
74
+ private keep;
75
+ /** Deletes `version`'s bytes and records that they went, and why. */
76
+ private drop;
77
+ /** The artifact `name`, refusing `not_found` when there is none. */
78
+ private find;
79
+ private serially;
80
+ }
81
+ /**
82
+ * A file an agent made as an output of its conversation, such as a
83
+ * screenshot, a recording or an HTML page, kept by name for the life of the
84
+ * conversation, whatever task it was made in. Adding the name again makes its
85
+ * next version. Its record stays for good, so one whose bytes went still
86
+ * shows as a placeholder.
87
+ */
88
+ export interface Artifact {
89
+ name: string;
90
+ /** The `version` of the one shown; the newest, as added. */
91
+ current: number;
92
+ /** Every version, oldest first, numbered from 1. */
93
+ versions: ArtifactVersion[];
94
+ /** When it was removed, its versions kept until cleanup takes them; null while listed. */
95
+ removedAt: string | null;
96
+ }
97
+ /** One version of an artifact: what was added under its name at once. */
98
+ export interface ArtifactVersion {
99
+ version: number;
100
+ /** Its file in the conversation's artifacts directory, named so none collide. */
101
+ file: string;
102
+ mimeType: string;
103
+ /** Its size. */
104
+ bytes: number;
105
+ addedAt: string;
106
+ /** When and why its bytes were deleted, its record kept; null while they are kept. */
107
+ gone: {
108
+ at: string;
109
+ why: ArtifactGone;
110
+ } | null;
111
+ }
112
+ /**
113
+ * Why a version's bytes went: its conversation was archived, the project ran
114
+ * past its cap, or the person deleted it.
115
+ */
116
+ export type ArtifactGone = "archived" | "evicted" | "deleted";
117
+ /** A change to a conversation's artifacts, as its log keeps it. */
118
+ export type ArtifactChange = ({
119
+ type: "add";
120
+ name: string;
121
+ } & Omit<ArtifactVersion, "version" | "gone">) | {
122
+ type: "remove";
123
+ name: string;
124
+ at: string;
125
+ } | {
126
+ type: "gone";
127
+ name: string;
128
+ version: number;
129
+ at: string;
130
+ why: ArtifactGone;
131
+ };
132
+ /** A file to keep as an artifact, as the agent hands it over. */
133
+ export interface ArtifactFile {
134
+ name: string;
135
+ mimeType: string;
136
+ bytes: Uint8Array;
137
+ }
138
+ /** How many bytes artifacts may take, each past which an add is refused. */
139
+ export interface ArtifactLimits {
140
+ /** One file. */
141
+ file: number;
142
+ /** Every version one conversation keeps the bytes of. */
143
+ conversation: number;
144
+ /** Every version every conversation in the project keeps the bytes of. */
145
+ project: number;
146
+ }
147
+ /** What `splates.config.ts` leaves the limits at unless it says otherwise. */
148
+ export declare const ARTIFACT_LIMITS: ArtifactLimits;
149
+ /** The limits `config` sets. */
150
+ export declare function artifactLimits(config: Pick<Config, "artifactFileCapacity" | "artifactConversationCapacity" | "artifactProjectCapacity">): ArtifactLimits;
151
+ /** Folds `change` into `artifacts`, as live and as a log is read back. */
152
+ export declare function applyArtifact(artifacts: Artifact[], change: ArtifactChange): void;
153
+ /** Whether `version` is the one its artifact's panel shows: its current, while listed. */
154
+ export declare function shown(artifact: Artifact, version: ArtifactVersion): boolean;
155
+ /**
156
+ * How many bytes every conversation under `dir` keeps, read from disk: its
157
+ * artifacts' and the files attached to it.
158
+ */
159
+ export declare function projectBytes(fs: Fs, dir: string): Promise<number>;
160
+ /** Refuses an add that would have `what` hold `bytes`, past its `capacity`. */
161
+ export declare function tooLarge(what: string, name: string, bytes: number, capacity: number): never;