@paradow/ledge 0.3.3 → 0.5.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.
- package/README.md +1 -1
- package/dist/cli/{attach-YBGTDBQI.js → attach-CUKFTN63.js} +6 -6
- package/dist/cli/bridge-R6DKTSYF.js +60 -0
- package/dist/cli/{chunk-W5XAZ5IS.js → chunk-5HVWJTTJ.js} +1 -1
- package/dist/cli/{chunk-XDRYMOVF.js → chunk-HGNMPXXR.js} +40 -14
- package/dist/cli/chunk-IUBEGKBP.js +6 -0
- package/dist/cli/chunk-OLLQBK6N.js +41 -0
- package/dist/cli/{chunk-6ZTCETRG.js → chunk-P2SHPHAN.js} +13 -2
- package/dist/cli/{chunk-Y44XZY6I.js → chunk-QHDPDZOJ.js} +9 -9
- package/dist/cli/{chunk-ZPF5I3LS.js → chunk-SMA4Z3N2.js} +9 -5
- package/dist/cli/{chunk-OUIDBDIH.js → chunk-U4A4XKDM.js} +2 -13
- package/dist/cli/{chunk-7ICDC2LK.js → chunk-XZMLFV6H.js} +2 -4
- package/dist/cli/chunk-Y4ODVTTN.js +438 -0
- package/dist/cli/{daemon-D5YDWUHB.js → daemon-6UFCIFQF.js} +897 -141
- package/dist/cli/{hook-HP23ZISG.js → hook-KFSK75QH.js} +62 -20
- package/dist/cli/index.js +14 -8
- package/dist/cli/{launch-DFB54ANN.js → launch-YKYPT6BU.js} +6 -6
- package/dist/cli/{setup-KUWSQLVG.js → setup-EXA6OG5W.js} +3 -2
- package/dist/cli/{status-IW2FESH4.js → status-I7FHW6ZM.js} +2 -2
- package/dist/cli/{uninstall-5GHUYN7P.js → uninstall-34TVL5BP.js} +3 -2
- package/dist/cli/{version-3DLAAFBS.js → version-IWGIZJJV.js} +1 -1
- package/package.json +3 -3
- package/dist/cli/chunk-6GMDFIGB.js +0 -306
- package/dist/cli/chunk-HDZVQH6J.js +0 -6
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
// ../protocol/src/messages.ts
|
|
2
|
+
import { z as z7 } from "zod";
|
|
3
|
+
|
|
4
|
+
// ../protocol/src/session.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var ToolSchema = z.enum(["claude", "codex", "cursor"]);
|
|
7
|
+
var SessionStateSchema = z.enum(["starting", "working", "waiting_input", "waiting_permission", "idle", "exited", "error"]);
|
|
8
|
+
var PendingSchema = z.object({
|
|
9
|
+
kind: z.enum(["question", "permission", "plan", "diff"]),
|
|
10
|
+
text: z.string(),
|
|
11
|
+
tool: z.string().optional(),
|
|
12
|
+
options: z.array(z.string()).optional(),
|
|
13
|
+
/** Each option's description, by index ('' when it has none); left out when no option has one. */
|
|
14
|
+
optionDetails: z.array(z.string()).optional(),
|
|
15
|
+
source: z.enum(["hook", "pane"]),
|
|
16
|
+
/** Set when the request comes from a helper (subagent): it is routed through its parent. */
|
|
17
|
+
helperId: z.string().optional(),
|
|
18
|
+
/** For a helper-routed request: the state the parent returns to once it is answered (main thread may stop meanwhile). */
|
|
19
|
+
parentState: SessionStateSchema.optional()
|
|
20
|
+
});
|
|
21
|
+
var ReplySchema = z.object({
|
|
22
|
+
text: z.string(),
|
|
23
|
+
at: z.string().datetime()
|
|
24
|
+
});
|
|
25
|
+
var HelperSchema = z.object({
|
|
26
|
+
id: z.string(),
|
|
27
|
+
kind: z.string(),
|
|
28
|
+
task: z.string(),
|
|
29
|
+
state: SessionStateSchema
|
|
30
|
+
});
|
|
31
|
+
var TopicSourceSchema = z.enum(["user", "pane", "prompt"]);
|
|
32
|
+
var SessionSchema = z.object({
|
|
33
|
+
/** Origin is annotated by the overlay, never used as an unqualified session id on the wire. */
|
|
34
|
+
machineId: z.string().optional(),
|
|
35
|
+
machineName: z.string().optional(),
|
|
36
|
+
repoId: z.string().optional(),
|
|
37
|
+
id: z.string().min(1),
|
|
38
|
+
name: z.string().min(1),
|
|
39
|
+
tool: ToolSchema,
|
|
40
|
+
cwd: z.string(),
|
|
41
|
+
project: z.string(),
|
|
42
|
+
title: z.string(),
|
|
43
|
+
/** One line saying what the session is about (spec 2026-10-11 §3). */
|
|
44
|
+
topic: z.string().optional(),
|
|
45
|
+
topicSource: TopicSourceSchema.optional(),
|
|
46
|
+
/** The repository (its main worktree's folder name and absolute path), the checked-out branch, and whether `cwd` is a linked worktree (§4). */
|
|
47
|
+
repo: z.string().optional(),
|
|
48
|
+
repoPath: z.string().optional(),
|
|
49
|
+
branch: z.string().optional(),
|
|
50
|
+
worktree: z.boolean().optional(),
|
|
51
|
+
tmuxSession: z.string().nullable(),
|
|
52
|
+
state: SessionStateSchema,
|
|
53
|
+
pending: PendingSchema.optional(),
|
|
54
|
+
helpers: z.array(HelperSchema).default([]),
|
|
55
|
+
lastReply: ReplySchema.optional(),
|
|
56
|
+
startedAt: z.string().datetime(),
|
|
57
|
+
lastActivityAt: z.string().datetime(),
|
|
58
|
+
lastHookAt: z.string().datetime().optional(),
|
|
59
|
+
exitCode: z.number().int().nullable().optional(),
|
|
60
|
+
exitedAt: z.string().datetime().optional(),
|
|
61
|
+
lastError: z.string().optional(),
|
|
62
|
+
source: z.enum(["launcher", "hook_only"])
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ../protocol/src/chat.ts
|
|
66
|
+
import { z as z2 } from "zod";
|
|
67
|
+
var ChatStepSchema = z2.object({
|
|
68
|
+
kind: z2.enum(["sessions", "pane", "reply", "git", "repo"]),
|
|
69
|
+
id: z2.string().optional(),
|
|
70
|
+
name: z2.string().optional(),
|
|
71
|
+
path: z2.string().optional()
|
|
72
|
+
});
|
|
73
|
+
var ChatProposalSchema = z2.object({
|
|
74
|
+
cwd: z2.string().min(1),
|
|
75
|
+
project: z2.string(),
|
|
76
|
+
prompt: z2.string().optional(),
|
|
77
|
+
tool: ToolSchema,
|
|
78
|
+
launchedId: z2.string().optional(),
|
|
79
|
+
error: z2.string().optional()
|
|
80
|
+
});
|
|
81
|
+
var ChatRelaySchema = z2.object({
|
|
82
|
+
id: z2.string().min(1),
|
|
83
|
+
name: z2.string(),
|
|
84
|
+
tool: ToolSchema,
|
|
85
|
+
text: z2.string().min(1),
|
|
86
|
+
status: z2.enum(["queued", "sent"]).optional(),
|
|
87
|
+
sentAt: z2.string().datetime().optional(),
|
|
88
|
+
error: z2.string().optional()
|
|
89
|
+
});
|
|
90
|
+
var ChatTurnSchema = z2.object({
|
|
91
|
+
machineId: z2.string().optional(),
|
|
92
|
+
machineName: z2.string().optional(),
|
|
93
|
+
choices: z2.array(z2.object({ id: z2.string(), label: z2.string() })).optional(),
|
|
94
|
+
qid: z2.string().min(1),
|
|
95
|
+
question: z2.string(),
|
|
96
|
+
askedAt: z2.string().datetime(),
|
|
97
|
+
steps: z2.array(ChatStepSchema),
|
|
98
|
+
answer: z2.string().optional(),
|
|
99
|
+
answeredAt: z2.string().datetime().optional(),
|
|
100
|
+
error: z2.string().optional(),
|
|
101
|
+
proposal: ChatProposalSchema.optional(),
|
|
102
|
+
relay: ChatRelaySchema.optional()
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ../protocol/src/documents.ts
|
|
106
|
+
import { z as z3 } from "zod";
|
|
107
|
+
var DOCUMENT_MAX_BYTES = 1048576;
|
|
108
|
+
var path = z3.string().min(1).max(4096);
|
|
109
|
+
var requestId = z3.string().min(1);
|
|
110
|
+
var DocumentReadSchema = z3.object({
|
|
111
|
+
type: z3.literal("document.read"),
|
|
112
|
+
requestId,
|
|
113
|
+
path,
|
|
114
|
+
machineId: z3.string().optional(),
|
|
115
|
+
sessionId: z3.string().min(1).optional(),
|
|
116
|
+
basePath: path.optional()
|
|
117
|
+
});
|
|
118
|
+
var DocumentContentSchema = z3.object({
|
|
119
|
+
type: z3.literal("document.content"),
|
|
120
|
+
requestId,
|
|
121
|
+
path,
|
|
122
|
+
text: z3.string(),
|
|
123
|
+
bytes: z3.number().int().nonnegative(),
|
|
124
|
+
modifiedAt: z3.string().datetime()
|
|
125
|
+
});
|
|
126
|
+
var DocumentErrorCodeSchema = z3.enum([
|
|
127
|
+
"not_found",
|
|
128
|
+
"not_file",
|
|
129
|
+
"unsupported_path",
|
|
130
|
+
"unsupported_type",
|
|
131
|
+
"permission_denied",
|
|
132
|
+
"too_large",
|
|
133
|
+
"invalid_utf8",
|
|
134
|
+
"ambiguous_path",
|
|
135
|
+
"session_missing",
|
|
136
|
+
"read_failed"
|
|
137
|
+
]);
|
|
138
|
+
var DocumentErrorSchema = z3.object({
|
|
139
|
+
type: z3.literal("document.error"),
|
|
140
|
+
requestId,
|
|
141
|
+
path,
|
|
142
|
+
code: DocumentErrorCodeSchema
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// ../protocol/src/routing.ts
|
|
146
|
+
import { z as z4 } from "zod";
|
|
147
|
+
var MachineInventorySchema = z4.object({
|
|
148
|
+
id: z4.string().min(1).max(80),
|
|
149
|
+
label: z4.string().min(1).max(120),
|
|
150
|
+
online: z4.boolean(),
|
|
151
|
+
local: z4.boolean(),
|
|
152
|
+
sessions: z4.array(z4.object({ id: z4.string(), name: z4.string(), project: z4.string(), cwd: z4.string(), topic: z4.string().optional(), state: z4.string(), readOnly: z4.boolean() })).max(500),
|
|
153
|
+
folders: z4.array(z4.object({ project: z4.string(), cwd: z4.string() })).max(100)
|
|
154
|
+
});
|
|
155
|
+
var RoutingContextSchema = z4.object({
|
|
156
|
+
machines: z4.array(MachineInventorySchema).min(1).max(20),
|
|
157
|
+
history: z4.array(z4.object({ question: z4.string().max(2e4), answer: z4.string().max(2e4).optional(), machineId: z4.string().optional() })).max(50)
|
|
158
|
+
});
|
|
159
|
+
var RouteResultSchema = z4.object({
|
|
160
|
+
/** Null means an answer or a clarification, never an implicit local destination. */
|
|
161
|
+
machineId: z4.string().nullable(),
|
|
162
|
+
text: z4.string().min(1).max(2e4),
|
|
163
|
+
choices: z4.array(z4.string()).max(20).optional()
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ../protocol/src/ssh.ts
|
|
167
|
+
import { z as z5 } from "zod";
|
|
168
|
+
var SshAliasSchema = z5.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,127}$/);
|
|
169
|
+
|
|
170
|
+
// ../protocol/src/thread.ts
|
|
171
|
+
import { z as z6 } from "zod";
|
|
172
|
+
var ToolStatusSchema = z6.enum(["running", "success", "failed", "unknown"]);
|
|
173
|
+
var FileChangeSchema = z6.object({ path: z6.string().min(1), change: z6.enum(["add", "edit", "delete", "write"]), diff: z6.string().optional() });
|
|
174
|
+
var base = { id: z6.string().min(1), at: z6.string().datetime(), turn: z6.number().int().nonnegative(), helperId: z6.string().optional() };
|
|
175
|
+
var ThreadItemSchema = z6.discriminatedUnion("kind", [
|
|
176
|
+
z6.object({ kind: z6.literal("prompt"), ...base, text: z6.string() }),
|
|
177
|
+
z6.object({ kind: z6.literal("message"), ...base, text: z6.string() }),
|
|
178
|
+
/** `id` is the harness's tool_use_id when it gives one, so the result updates the same row. */
|
|
179
|
+
z6.object({ kind: z6.literal("tool"), ...base, tool: z6.string(), label: z6.string(), input: z6.string().optional(), output: z6.string().optional(), error: z6.string().optional(), status: ToolStatusSchema, durationMs: z6.number().nonnegative().optional(), files: z6.array(FileChangeSchema).default([]) }),
|
|
180
|
+
/** `unknown`: answered in the terminal, the daemon only saw the prompt go away. */
|
|
181
|
+
z6.object({ kind: z6.literal("permission"), ...base, tool: z6.string(), text: z6.string(), decision: z6.enum(["accept", "deny", "unknown"]).optional() }),
|
|
182
|
+
z6.object({ kind: z6.literal("reply"), ...base, text: z6.string() }),
|
|
183
|
+
z6.object({ kind: z6.literal("helper"), ...base, task: z6.string(), agentType: z6.string().optional(), state: z6.enum(["working", "exited"]) })
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
// ../protocol/src/messages.ts
|
|
187
|
+
var PROTOCOL_PORT = 47831;
|
|
188
|
+
var SessionEventSchema = z7.object({
|
|
189
|
+
name: z7.enum(["SessionStart", "UserPromptSubmit", "PreToolUse", "PermissionRequest", "Notification", "Stop", "SessionEnd", "PaneChanged", "PaneGone", "PanePrompt", "PaneIdle", "InjectFailed", "Decided", "PostToolUse", "PostToolUseFailure", "StopFailure", "SubagentStart", "SubagentStop", "PaneTitle", "Renamed"]),
|
|
190
|
+
at: z7.string().datetime(),
|
|
191
|
+
source: z7.enum(["hook", "pane", "daemon"]),
|
|
192
|
+
tool: z7.string().optional(),
|
|
193
|
+
text: z7.string().optional(),
|
|
194
|
+
options: z7.array(z7.string()).optional(),
|
|
195
|
+
/** Each option's description, by index ('' when it has none); left out when no option has one. */
|
|
196
|
+
optionDetails: z7.array(z7.string()).optional(),
|
|
197
|
+
kind: z7.enum(["question", "permission", "plan", "diff"]).optional(),
|
|
198
|
+
exitCode: z7.number().int().nullable().optional(),
|
|
199
|
+
helperId: z7.string().optional(),
|
|
200
|
+
/** The helper's description, once known (Claude Code: its `.meta.json`, written after SubagentStart). */
|
|
201
|
+
task: z7.string().optional(),
|
|
202
|
+
/** PostToolUseFailure: the user interrupted the turn (Esc); Claude then waits for input with no Stop. */
|
|
203
|
+
interrupt: z7.boolean().optional(),
|
|
204
|
+
/** Native tracking (spec 2026-10-13 §2): the harness's id of the tool call, so its result lands on the same row. */
|
|
205
|
+
toolUseId: z7.string().optional(),
|
|
206
|
+
/** The tool's input as the harness gave it, every string capped by the hook. */
|
|
207
|
+
toolInput: z7.record(z7.string(), z7.unknown()).optional(),
|
|
208
|
+
/** PostToolUse: the result as text; SubagentStop: nothing (the report travels in `text`). */
|
|
209
|
+
output: z7.string().optional(),
|
|
210
|
+
durationMs: z7.number().nonnegative().optional(),
|
|
211
|
+
/** PostToolUseFailure: the harness's error message. */
|
|
212
|
+
error: z7.string().optional(),
|
|
213
|
+
/** The session's transcript, or the helper's on SubagentStop; the daemon reads its tail for the agent's messages. */
|
|
214
|
+
transcriptPath: z7.string().optional(),
|
|
215
|
+
/** Decided: what was chosen when the daemon knows it. */
|
|
216
|
+
decision: z7.enum(["accept", "deny"]).optional()
|
|
217
|
+
});
|
|
218
|
+
var RecentSchema = z7.object({ cwd: z7.string().min(1), project: z7.string().min(1), lastAt: z7.string().datetime() });
|
|
219
|
+
var SEMVER = /^\d+\.\d+\.\d+$/;
|
|
220
|
+
var DaemonInfoSchema = z7.object({ version: z7.string(), install: z7.enum(["npm", "git", "unknown"]), systemd: z7.boolean(), manual: z7.string().optional(), routing: z7.boolean().optional() });
|
|
221
|
+
var UpdateFailureSchema = z7.enum(["git-install", "no-systemd", "sessions-at-risk", "npm-failed", "busy"]);
|
|
222
|
+
var ServerMessageSchema = z7.discriminatedUnion("type", [
|
|
223
|
+
z7.object({ type: z7.literal("chat.routed"), qid: z7.string(), result: RouteResultSchema }),
|
|
224
|
+
DocumentContentSchema,
|
|
225
|
+
DocumentErrorSchema,
|
|
226
|
+
/** `recents`: the folders of past sessions, most recent first. `launcher`: the command that runs `ledge` inside WSL
|
|
227
|
+
* (`[node, cli]`), so the overlay can attach a terminal to a session with `<launcher> attach <id>`. `daemon`: absent
|
|
228
|
+
* from daemons older than the auto-update. */
|
|
229
|
+
z7.object({ type: z7.literal("snapshot"), sessions: z7.array(SessionSchema), recents: z7.array(RecentSchema).optional(), launcher: z7.array(z7.string()).optional(), daemon: DaemonInfoSchema.optional(), sshAlias: SshAliasSchema.optional() }),
|
|
230
|
+
z7.object({ type: z7.literal("session.updated"), session: SessionSchema }),
|
|
231
|
+
z7.object({ type: z7.literal("session.removed"), id: z7.string() }),
|
|
232
|
+
z7.object({ type: z7.literal("session.preview"), id: z7.string(), lines: z7.array(z7.string()) }),
|
|
233
|
+
/** A session's thread, on request (spec 2026-10-13 §5); then each created or updated item, broadcast. */
|
|
234
|
+
z7.object({ type: z7.literal("session.thread"), id: z7.string(), items: z7.array(ThreadItemSchema) }),
|
|
235
|
+
z7.object({ type: z7.literal("session.thread.item"), id: z7.string(), item: ThreadItemSchema }),
|
|
236
|
+
/** Answer to the requester of a `session.launch`: the session exists (its `session.updated` is broadcast as usual). */
|
|
237
|
+
z7.object({ type: z7.literal("session.launched"), id: z7.string() }),
|
|
238
|
+
z7.object({ type: z7.literal("recents"), recents: z7.array(RecentSchema) }),
|
|
239
|
+
/** Answer to the requester of a `folder.list` or `folder.create`: `path` resolved (`~` expanded), `parent` null at the
|
|
240
|
+
* root, `entries` its subfolders by name (hidden ones left out). A failure keeps the asked path and says why in `error`,
|
|
241
|
+
* never in an `error` message, which the launch form reads as a failed launch. */
|
|
242
|
+
z7.object({ type: z7.literal("folder.listing"), path: z7.string(), parent: z7.string().nullable(), entries: z7.array(z7.string()), error: z7.string().optional() }),
|
|
243
|
+
/** The chat (spec 2026-10-11 §5): what Ledge reads, its words as they come, the final text, or why it stopped; the day's turns after each snapshot. */
|
|
244
|
+
z7.object({ type: z7.literal("chat.step"), qid: z7.string(), step: ChatStepSchema }),
|
|
245
|
+
z7.object({ type: z7.literal("chat.delta"), qid: z7.string(), text: z7.string() }),
|
|
246
|
+
z7.object({ type: z7.literal("chat.done"), qid: z7.string(), text: z7.string(), at: z7.string().datetime(), proposal: ChatProposalSchema.optional(), relay: ChatRelaySchema.optional() }),
|
|
247
|
+
z7.object({ type: z7.literal("chat.error"), qid: z7.string(), message: z7.string() }),
|
|
248
|
+
z7.object({ type: z7.literal("chat.history"), turns: z7.array(ChatTurnSchema) }),
|
|
249
|
+
/** The daemon updating itself: npm is running, then the service restarts (the socket closes right after). */
|
|
250
|
+
z7.object({ type: z7.literal("update.progress"), version: z7.string(), step: z7.enum(["installing", "restarting"]) }),
|
|
251
|
+
/** Nothing was changed. `detail`: the useful end of npm's output; `command`: what the person can run instead. */
|
|
252
|
+
z7.object({ type: z7.literal("update.failed"), version: z7.string(), reason: UpdateFailureSchema, detail: z7.string().optional(), command: z7.string().optional() }),
|
|
253
|
+
z7.object({ type: z7.literal("error"), message: z7.string(), id: z7.string().optional() })
|
|
254
|
+
]);
|
|
255
|
+
var ClientMessageSchema = z7.discriminatedUnion("type", [
|
|
256
|
+
z7.object({ type: z7.literal("chat.route"), qid: z7.string().min(1).max(100), text: z7.string().min(1).max(2e4), tool: ToolSchema.optional(), context: RoutingContextSchema }),
|
|
257
|
+
DocumentReadSchema,
|
|
258
|
+
/** The overlay starts a session: `cwd` is a WSL path (`~` allowed), `name` a preferred bot name (the daemon picks a
|
|
259
|
+
* free one otherwise), `prompt` the agent's first instruction, `continue` resumes the folder's last conversation.
|
|
260
|
+
* With `qid` it is the chat card of that turn: the daemon launches the turn's proposal and ignores the other fields. */
|
|
261
|
+
z7.object({ type: z7.literal("session.launch"), tool: ToolSchema, cwd: z7.string().min(1), name: z7.string().optional(), prompt: z7.string().optional(), continue: z7.boolean().optional(), qid: z7.string().min(1).optional() }),
|
|
262
|
+
/** The launch form's folder browser: list a folder's subfolders (home when no `path`), or make `name` inside `parent`
|
|
263
|
+
* and list it. Both are answered with a `folder.listing`. */
|
|
264
|
+
z7.object({ type: z7.literal("folder.list"), path: z7.string().optional() }),
|
|
265
|
+
z7.object({ type: z7.literal("folder.create"), parent: z7.string().min(1), name: z7.string().min(1) }),
|
|
266
|
+
z7.object({ type: z7.literal("session.reply"), id: z7.string(), text: z7.string().min(1) }),
|
|
267
|
+
/** The chat card's instruction (spec 2026-10-12 relay §4): sent now if the session is free, else queued until it is. */
|
|
268
|
+
z7.object({ type: z7.literal("session.relay"), qid: z7.string().min(1) }),
|
|
269
|
+
/** Takes the card's queued instruction back out of the queue. */
|
|
270
|
+
z7.object({ type: z7.literal("session.relay.cancel"), qid: z7.string().min(1) }),
|
|
271
|
+
z7.object({ type: z7.literal("session.decide"), id: z7.string(), decision: z7.enum(["accept", "deny"]) }),
|
|
272
|
+
z7.object({ type: z7.literal("session.focus"), id: z7.string() }),
|
|
273
|
+
z7.object({ type: z7.literal("session.kill"), id: z7.string() }),
|
|
274
|
+
z7.object({ type: z7.literal("session.interrupt"), id: z7.string() }),
|
|
275
|
+
/** Removes a finished (exited) or read-only (hook_only) session from the list; refused for a live launcher session. */
|
|
276
|
+
z7.object({ type: z7.literal("session.dismiss"), id: z7.string() }),
|
|
277
|
+
/** The user names the session's topic from the overlay (500 characters at most, the hook's prompt cap); an empty topic hands back to the automatic sources. */
|
|
278
|
+
z7.object({ type: z7.literal("session.rename"), id: z7.string(), topic: z7.string().max(500) }),
|
|
279
|
+
z7.object({ type: z7.literal("session.thread"), id: z7.string() }),
|
|
280
|
+
z7.object({ type: z7.literal("session.register"), session: SessionSchema }),
|
|
281
|
+
/** `agent` and `cwd` describe the session when the daemon does not know it yet (a hook from an agent started without ledge). */
|
|
282
|
+
z7.object({ type: z7.literal("session.event"), id: z7.string(), event: SessionEventSchema, agent: ToolSchema.optional(), cwd: z7.string().optional() }),
|
|
283
|
+
z7.object({ type: z7.literal("session.unregister"), id: z7.string(), exitCode: z7.number().int().nullable() }),
|
|
284
|
+
z7.object({ type: z7.literal("snapshot.request") }),
|
|
285
|
+
z7.object({ type: z7.literal("chat.ask"), qid: z7.string().min(1), text: z7.string().min(1), tool: ToolSchema.optional() }),
|
|
286
|
+
z7.object({ type: z7.literal("chat.cancel"), qid: z7.string().min(1) }),
|
|
287
|
+
/** Starts a new conversation with Ledge: the day's turns are cleared and the next question opens a new harness session. */
|
|
288
|
+
z7.object({ type: z7.literal("chat.reset") }),
|
|
289
|
+
/** Installs `@paradow/ledge@version` and restarts the service (spec 2026-10-12 auto-update §6). */
|
|
290
|
+
z7.object({ type: z7.literal("update.daemon"), version: z7.string().regex(SEMVER) })
|
|
291
|
+
]);
|
|
292
|
+
function parseClientMessage(raw) {
|
|
293
|
+
return ClientMessageSchema.parse(raw);
|
|
294
|
+
}
|
|
295
|
+
function parseServerMessage(raw) {
|
|
296
|
+
return ServerMessageSchema.parse(raw);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// ../protocol/src/names.ts
|
|
300
|
+
var NAMES = [
|
|
301
|
+
"Otto",
|
|
302
|
+
"Pim",
|
|
303
|
+
"Nova",
|
|
304
|
+
"Bix",
|
|
305
|
+
"Lu",
|
|
306
|
+
"Max",
|
|
307
|
+
"Ida",
|
|
308
|
+
"Rex",
|
|
309
|
+
"Zoe",
|
|
310
|
+
"Kit",
|
|
311
|
+
"Ari",
|
|
312
|
+
"Bo",
|
|
313
|
+
"Cal",
|
|
314
|
+
"Dee",
|
|
315
|
+
"Eli",
|
|
316
|
+
"Fay",
|
|
317
|
+
"Gus",
|
|
318
|
+
"Hal",
|
|
319
|
+
"Ivy",
|
|
320
|
+
"Jax",
|
|
321
|
+
"Kai",
|
|
322
|
+
"Lio",
|
|
323
|
+
"Mo",
|
|
324
|
+
"Nia",
|
|
325
|
+
"Oz",
|
|
326
|
+
"Pax",
|
|
327
|
+
"Quin",
|
|
328
|
+
"Rae",
|
|
329
|
+
"Sol",
|
|
330
|
+
"Tad",
|
|
331
|
+
"Uma",
|
|
332
|
+
"Vic",
|
|
333
|
+
"Wyn",
|
|
334
|
+
"Xen",
|
|
335
|
+
"Yan",
|
|
336
|
+
"Zia",
|
|
337
|
+
"Abe",
|
|
338
|
+
"Bea",
|
|
339
|
+
"Cy",
|
|
340
|
+
"Dot",
|
|
341
|
+
"Eva",
|
|
342
|
+
"Fin",
|
|
343
|
+
"Gil",
|
|
344
|
+
"Hen",
|
|
345
|
+
"Iro",
|
|
346
|
+
"Jo",
|
|
347
|
+
"Kip",
|
|
348
|
+
"Lex",
|
|
349
|
+
"Mia",
|
|
350
|
+
"Ned",
|
|
351
|
+
"Ola",
|
|
352
|
+
"Pat",
|
|
353
|
+
"Rio",
|
|
354
|
+
"Sam",
|
|
355
|
+
"Tia",
|
|
356
|
+
"Ulf",
|
|
357
|
+
"Val",
|
|
358
|
+
"Wes",
|
|
359
|
+
"Yui",
|
|
360
|
+
"Zed",
|
|
361
|
+
"Ash",
|
|
362
|
+
"Bry",
|
|
363
|
+
"Cleo",
|
|
364
|
+
"Dax"
|
|
365
|
+
];
|
|
366
|
+
var cap = (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
|
367
|
+
function pickName(taken, preferred) {
|
|
368
|
+
const used = new Set(taken);
|
|
369
|
+
const free = (n) => !used.has(n);
|
|
370
|
+
const wanted = preferred?.trim();
|
|
371
|
+
if (wanted) {
|
|
372
|
+
const base2 = cap(wanted);
|
|
373
|
+
if (free(base2)) return base2;
|
|
374
|
+
for (let i = 2; ; i++) if (free(`${base2}-${i}`)) return `${base2}-${i}`;
|
|
375
|
+
}
|
|
376
|
+
const first = NAMES.find(free);
|
|
377
|
+
if (first) return first;
|
|
378
|
+
for (let i = 2; ; i++) if (free(`${NAMES[0]}-${i}`)) return `${NAMES[0]}-${i}`;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// ../protocol/src/proposal.ts
|
|
382
|
+
import { z as z8 } from "zod";
|
|
383
|
+
var ProposalBlockSchema = z8.object({ cwd: z8.string().trim().min(1), prompt: z8.string().optional() });
|
|
384
|
+
var RelayBlockSchema = z8.object({ session: z8.string().trim().min(1), text: z8.string().trim().min(1) });
|
|
385
|
+
var BLOCK = /```ledge-(session|relay)[ \t]*\n?([\s\S]*?)(?:```|$)/g;
|
|
386
|
+
function extractProposal(answer) {
|
|
387
|
+
const found = [];
|
|
388
|
+
const text = answer.replace(BLOCK, (_m, kind, body) => {
|
|
389
|
+
found.push({ kind, raw: body.trim() });
|
|
390
|
+
return "";
|
|
391
|
+
});
|
|
392
|
+
const last = found.at(-1);
|
|
393
|
+
return last ? { text: text.replace(/\n{3,}/g, "\n\n").trim(), kind: last.kind, raw: last.raw } : { text: answer, kind: null, raw: null };
|
|
394
|
+
}
|
|
395
|
+
function parseProposalBlock(raw) {
|
|
396
|
+
try {
|
|
397
|
+
const r = ProposalBlockSchema.safeParse(JSON.parse(raw));
|
|
398
|
+
return r.success ? r.data : null;
|
|
399
|
+
} catch {
|
|
400
|
+
return null;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
function parseRelayBlock(raw) {
|
|
404
|
+
try {
|
|
405
|
+
const r = RelayBlockSchema.safeParse(JSON.parse(raw));
|
|
406
|
+
return r.success ? r.data : null;
|
|
407
|
+
} catch {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// ../protocol/src/topic.ts
|
|
413
|
+
var TOPIC_MAX = 80;
|
|
414
|
+
function cleanTopic(text) {
|
|
415
|
+
const line = text.split(/\r?\n/).map((l) => l.trim()).find((l) => l.length > 0) ?? "";
|
|
416
|
+
const flat = line.replace(/\s+/g, " ");
|
|
417
|
+
return flat.length > TOPIC_MAX ? `${flat.slice(0, TOPIC_MAX - 1).trimEnd()}\u2026` : flat;
|
|
418
|
+
}
|
|
419
|
+
function sessionTitle(s) {
|
|
420
|
+
return `${s.name} \xB7 ${s.topic || s.project}`;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export {
|
|
424
|
+
SessionSchema,
|
|
425
|
+
DOCUMENT_MAX_BYTES,
|
|
426
|
+
RouteResultSchema,
|
|
427
|
+
SshAliasSchema,
|
|
428
|
+
PROTOCOL_PORT,
|
|
429
|
+
RecentSchema,
|
|
430
|
+
parseClientMessage,
|
|
431
|
+
parseServerMessage,
|
|
432
|
+
pickName,
|
|
433
|
+
extractProposal,
|
|
434
|
+
parseProposalBlock,
|
|
435
|
+
parseRelayBlock,
|
|
436
|
+
cleanTopic,
|
|
437
|
+
sessionTitle
|
|
438
|
+
};
|