@paigy/mcp 0.35.0 → 0.36.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.
@@ -1,16 +1,113 @@
1
1
  // ../../packages/schema/dist/index.js
2
+ import { z as z2 } from "zod";
2
3
  import { z } from "zod";
3
- var ContextSchema = z.object({
4
- title: z.string().min(1).describe("One-line headline of what you need (required, non-empty)."),
5
- description: z.array(z.string().min(1)).describe(
4
+ import { zodToJsonSchema } from "zod-to-json-schema";
5
+ var OPTIONS_MIN = 2;
6
+ var OPTIONS_MAX = 6;
7
+ var MISSED_CALL_PLAN = {
8
+ retry_10m: { kind: "every", minutes: 10 },
9
+ retry_30m: { kind: "every", minutes: 30 },
10
+ retry_60m: { kind: "every", minutes: 60 },
11
+ backoff_gentle: { kind: "at", minutes: [30, 120, 360] },
12
+ backoff_standard: { kind: "at", minutes: [10, 30, 120] },
13
+ backoff_aggressive: { kind: "at", minutes: [5, 15, 45] },
14
+ inbox: { kind: "once" },
15
+ dismiss: { kind: "grace", minutes: 2 }
16
+ };
17
+ function draft2020(node) {
18
+ if (Array.isArray(node)) return node.map(draft2020);
19
+ if (node && typeof node === "object") {
20
+ const o = node;
21
+ for (const [excl, lim] of [["exclusiveMinimum", "minimum"], ["exclusiveMaximum", "maximum"]]) {
22
+ if (typeof o[excl] === "boolean") {
23
+ if (o[excl] === true && typeof o[lim] === "number") {
24
+ o[excl] = o[lim];
25
+ delete o[lim];
26
+ } else delete o[excl];
27
+ }
28
+ }
29
+ for (const k of Object.keys(o)) o[k] = draft2020(o[k]);
30
+ return o;
31
+ }
32
+ return node;
33
+ }
34
+ function mcpInputSchema(s) {
35
+ const schema = zodToJsonSchema(s, { target: "jsonSchema2019-09", $refStrategy: "none" });
36
+ delete schema.$schema;
37
+ return draft2020(schema);
38
+ }
39
+ var CreateGoalSchema = z.object({
40
+ outcome: z.string().trim().min(1).max(1e4),
41
+ ownerParticipant: z.string().trim().min(1).optional(),
42
+ idempotencyKey: z.string().trim().min(1).max(200)
43
+ });
44
+ var CREATE_GOAL_DESCRIPTION = "Create a durable root Goal for an outcome. Admission only: claim it before doing work, then update its state as it advances. Use a stable idempotencyKey so retries do not create duplicates. Returns goalId, state, revision, ownerParticipant, and next claim_goal.";
45
+ var fmtMin = (m) => m >= 60 ? `${m / 60} hr` : `${m} min`;
46
+ var STANDARD_MEANS = (() => {
47
+ const plan = MISSED_CALL_PLAN.backoff_standard;
48
+ const mins = plan.kind === "at" ? plan.minutes : [];
49
+ const parts = mins.map(fmtMin);
50
+ const list = parts.length > 1 ? `${parts.slice(0, -1).join(", ")} and ${parts[parts.length - 1]}` : parts[0] ?? "";
51
+ return `Rings again ${list} after the missed call, then leaves it in your inbox`;
52
+ })();
53
+ function contactSchemaFrom(fields) {
54
+ const surface = z.object({
55
+ ask: fields.ask.describe(
56
+ `What to tell the user, or what you need to find out from them. Plain prose \u2014 as long as it needs to be (up to 10k characters); Paigy splits it into topics and reads back a few sentences at a time, so do NOT compress a briefing into one line. May be spoken aloud on a call, so write natural speech and name things (not IDs). Contact at exactly two moments: BLOCKED on a decision only they can make, or DONE (one short report \u2014 what shipped, how you verified it, what you flagged). DONE IS SAID ONCE: "all set", "nothing open on my end", "that thread is complete" are the same report in new words, and each one reaches them separately (live 2026-08-12: three of them in three minutes). After the first, you are finished speaking; if they acknowledge it, stop rather than confirming the acknowledgement. Progress is never a contact: set_work_state carries it, and working narration stays in your own terminal \u2014 the user sees you're working without being interrupted by it.`
57
+ ),
58
+ waiting: fields.waiting.describe(
59
+ "What happens to your work while you wait. 'none': you're just informing them. 'soft': you'd like an answer but can keep working. 'hard': you are STOPPED until they answer \u2014 reaches them urgently and escalates to a real phone call if unanswered."
60
+ ),
61
+ options: fields.options.describe(
62
+ `The choices the user picks from, when you have them \u2014 ${OPTIONS_MIN} to ${OPTIONS_MAX}, drawn from your own sentence.`
63
+ ),
64
+ channel: fields.channel.describe(
65
+ "Relay how the user explicitly said to reach them ('call me' \u2192 'call', 'just message/text me' \u2192 'message'), or use 'call' when promoting the same quiet ask after it becomes a substantial blocker. Omit otherwise; Paigy picks."
66
+ ),
67
+ parentId: fields.parentId.describe(
68
+ "To continue an earlier conversation, pass the parentId a previous contact or reply returned. Omit to start a new one."
69
+ ),
70
+ workId: fields.workId.describe(
71
+ "The durable Work this contact advances. Pass the workId from check_replies or a prior reply when asking for a decision that blocks that work."
72
+ )
73
+ });
74
+ const out = mcpInputSchema(surface);
75
+ out.required = ["ask"];
76
+ return out;
77
+ }
78
+ var CONTACT_DESCRIPTION = `Reach the user through Paigy \u2014 tell them something, or ask and get their answer. State what you need in \`ask\`, say what happens to your work while you wait in \`waiting\`, and Paigy handles the rest (channel, phrasing, answer format). If the user explicitly asks you to CALL them, send waiting:'hard' and say so in the ask. Returns { notificationId, parentId, workId?, decisionId? } \u2014 pass notificationId to the reply path named by the returned \`message\`, and parentId to a later contact to continue the conversation. When it rang, the reply also carries { ifMissed: { mode, means } }: what the user's own policy does with a call they don't take ("${STANDARD_MEANS}"), so a no-answer tells you how long to wait before coming back. THREADING REPLACES: a threaded follow-up SUPERSEDES your earlier pending items on that thread \u2014 right for updates to one ask, WRONG for a checklist (send independent to-dos un-threaded). A threaded re-send with IDENTICAL content escalates the pending ask in place. If a reply comes back as {kind:'clarify', chunks:[...]}, the user wants more detail \u2014 contact again on the SAME parentId with an expanded ask. BLOCKED ON A DECISION for existing work? Pass that work's \`workId\`; the reply returns the same workId plus a decisionId, so the answer resumes the right outcome. ONE ASK, ONE ROW: never restate a still-pending ask's question inside a NEW contact (e.g. weaving it into a briefing) \u2014 the whole answer settles on the new row and the original can never receive it. Keep waiting on the original (a live call reads every pending ask out separately, each answer routes to its own row), and use \`needs\` for a genuinely multi-part NEW ask. ANSWERABLE, NOT JUST ASKED: when the reply comes back carrying \`plan.units[].needs\`, that unit asked for something it gave the user no way to answer \u2014 'options' means it posed a choice with nothing to choose from, 'visuals' means it asked about something to look at with nothing to look at. Send it again on the SAME parentId with ${OPTIONS_MIN}-${OPTIONS_MAX} options (or the image), drawn from your own sentence. Paigy will not add them for you: a shape it guessed wrong cannot be undone, and you are the one who knows what the real alternatives are. \`units\` reports WHAT BECAME OF YOUR PROSE \u2014 { kept, raw, why }: how many topics Paigy compressed for delivery, how many kept your exact words, and the reason when it kept them (e.g. 'no_output' = compression produced nothing usable, so the user got your raw sentence). It needs no action and is not an error \u2014 read it only when the delivered wording matters to you; a high \`raw\` count means the user is hearing you verbatim.`;
79
+ var CHECK_REPLIES_DESCRIPTION = "The catch-up sweep for everything outstanding \u2014 a PURE read, takes no arguments, safe to call as often as you like: nothing here is consumed by reading it. Returns `replies` (answers to notifications you sent), `work` \u2014 durable outcomes currently owned by you \u2014 plus your still-pending notifications and `requests`, requests the user started toward you (each { notificationId, parentId, workId?, text }); replies tied to Work carry workId and decisionId too. Pass workId back to contact when a new decision blocks that outcome. A REQUEST keeps reappearing until you engage with it \u2014 call set_work_state with its workId, or notificationId once when workId is absent, to claim it \u2014 because human-initiated work must never be silently dropped just because you read the list. A REPLY is different: it is acknowledged by being delivered to you, and needs no set_work_state to stop resurfacing \u2014 report state on it only when it starts real follow-up work. Also returns `threads` \u2014 the SAME replies + requests grouped by conversation, oldest thread first, each with a `busy` flag and its `items` in arrival order. WORK ONE THREAD AT A TIME: take the oldest thread whose `busy` is false, handle ALL of its items together in a single turn (one set_work_state), then go to the next \u2014 don't interleave threads item-by-item. A `busy` thread already has a turn in progress; leave it and let its new items ride the next turn. Use check_replies when booting up / starting a session, or when you've been waiting a long time on something else. To wait on an answer to a contact call you just made, use await_reply instead. Also returns owedCallbacks: callbacks now due that you promised \u2014 fulfill each with contact on its parentId. EVERY Paigy reply \u2014 this one, await_reply's, and contact's \u2014 may carry `also`: work assigned to you that no wake could reach, handed to you because you happened to be here. It is NOT what you asked about and it is never urgent: FINISH what you came for first, then take it up. Each entry has a `noteId` and the owner's own words; report on its `parentId` thread when it has one, and call set_work_state with its noteId as the bootstrap notificationId. Ignoring it costs nothing \u2014 it rides your next reply too. Also returns `stalled`: work (either direction) you reported in_progress via set_work_state a while ago and never reported completed \u2014 likely left half-done by this session or a prior one that crashed or went idle. For each, either continue the work and report a real state, or investigate why it stalled. Also returns `you` \u2014 WHICH IDENTITY you are speaking as ({ name, device, tokenId }), the same name and device the user sees on their Agents screen. This is the only safe way to find out (calling `pair` can MINT a new identity instead of telling you about the current one). Use it when the user asks who you are, and to tell whether work addressed to a name is addressed to you. A request may also carry `stranded`: it was addressed to ANOTHER agent on this account (that name) which has not been seen since it landed, so nobody came for it and it is handed to you because you are the session that is here. Take it exactly like your own \u2014 set_work_state claims it, reply with contact on its parentId \u2014 and say whose it was, because the user picked that agent on purpose. Replies may carry `intents`/`transcript`/`covered` (call-mapped answers) \u2014 handle intents exactly as await_reply's description says (defer \u2192 schedule_callback now; delegate \u2192 decide and say so; channel \u2192 honor next contact), and treat a `covered` list missing one of your declared points as that part still unanswered.";
80
+ var SCHEDULE_CALLBACK_DESCRIPTION = "Promise the user a follow-up you'll keep even if you go idle. Use it when they ask you to report back: trigger 'on_done' (when you finish \u2014 fires when you call set_work_state completed), 'on_blocked' (if you hit a blocker \u2014 fires on set_work_state needs_input), or 'scheduled' with dueInSeconds (e.g. 'remind me in 10 min'). Pass the parentId of the conversation and a short note. Fulfill it by calling contact on that parentId; check_replies re-lists due callbacks until you do.";
81
+ var SEARCH_THREADS_DESCRIPTION = `Search your PAST conversations before asking \u2014 "have we discussed this before?". Full-text over your own threads (the asks you sent + the user's answers); returns ranked threads with highlighted snippets, NOT rows: { hits: [{ parentId, at, agentLabel, matches: [{ notificationId, role, snippet }] }] }. The loop this exists for: search first \u2192 get_thread the best hit to rehydrate it \u2192 THEN continue or contact, so you answer with receipts ("last week you said ship it") instead of re-asking. Read-only, safe to call anytime; scoped to your own account's threads.`;
82
+ var SET_WORK_STATE_DESCRIPTION = "Report progress on durable Work. Use workId from check_replies, contact, or a reply. For a new assigned request that has only notificationId, pass that once; the result returns its workId and every later report uses workId. States: in_progress (you started or resumed it), completed (done), or needs_input (you need a human decision \u2014 follow with contact carrying the returned workId). This changes Work progress only; reply delivery and acknowledgement stay on await_reply/check_replies.";
83
+ function serverInstructions(opts) {
84
+ const waits = opts.waits;
85
+ return "On startup, call check_replies once to pick up any replies or pending work you missed while away. A check_replies request whose parentId you don't recognize, or one carrying a contextParentId, means the user is resuming or seeding a past conversation \u2014 call get_thread on it FIRST and treat the transcript as prior conversation, not new input. " + (waits ? "Follow contact's returned message. An inbox delivery is asynchronous: keep working and collect the answer later through check_replies. A call is live: call await_reply with that notificationId; it is scoped, so replies never cross. If a quiet ask later blocks substantial work, resend contact with the same parentId and channel:'call'. " : "You are wake-driven: you cannot wait for an answer in-context. Inbox and call answers return through check_replies. When a reply is handed to you it is LEASED \u2014 act on it, then call ack_reply with its leaseId so it is not handed to you again; a reply you never acknowledge comes back on your next wake. ") + // WHO IS ASKING, AND WHERE ARE THEY (field report, 2026-08-28 — eleven days of total
86
+ // silence on a live pairing). "Never end a turn that still needs the user without
87
+ // contact" is correct for an unattended agent and says NOTHING about the case that
88
+ // actually dominates: the user sitting at the terminal, where ending the turn with the
89
+ // question ALREADY reaches them. So the rule collapsed into two readings — fire on every
90
+ // clarifying question (phone spam, they unpair) or never fire at all — and every session
91
+ // after install day independently chose the second. Sessions start cold, so the same
92
+ // default got re-derived daily with no memory that yesterday did the same, and no session
93
+ // ever thought to ask the user which they wanted. Zero notifications for eleven days,
94
+ // with no error anywhere: indistinguishable from a healthy account having a quiet week.
95
+ //
96
+ // The carve-out is stated rather than left to per-session judgment, because judgment
97
+ // exercised cold, once per session, is not judgment — it is a coin landing the same way.
98
+ "Never end a turn that still needs the user without contact + await_reply \u2014 WHEN THEY ARE NOT THERE TO ASK. In an interactive session with the user at the terminal, the prompt IS the channel: ending your turn with the question already reaches them, faster and richer than a push, so do NOT send one for an ordinary blocked-or-done moment. Reach for Paigy exactly when the terminal is not enough \u2014 work that will run more than a few minutes unattended (a long build, a deploy, a background job, a cloud session), anything you finish or get stuck on while they are away, or when they have said they are stepping out. If you cannot tell which situation you are in, ask them once, in passing, how they want to be reached, and follow that for the rest of the session. When you need a decision or input, WRITE THE QUESTION and Paigy derives the answer shape from it \u2014 there is no shape parameter to set, and passing one is an error. Ask a yes/no question and they get yes/no; ask them to approve an action and they get approve/deny; ask them to pick, and to pick several, and to rank, and each gets the control it needs. So phrase the ask precisely: 'which of these should I do first' and 'should I do this' are different questions and become different answers. The one thing the prose can't supply is the CHOICES themselves \u2014 when you're asking them to pick between concrete alternatives, pass `options` (${OPTIONS_MIN}-${OPTIONS_MAX} of them, drawn from your own sentence), because Paigy will not invent alternatives it can't know. On a { kind: 'clarify' } reply, see contact's own description for how to respond. When you send waiting:'hard' (or the user asked you to call), remember the ask may be spoken aloud \u2014 write it short and conversational, and name things instead of using IDs (e.g. 'the pull request about the agents page', not 'PR #235'). When the user asks you to follow up later \u2014 when you're done, if you're blocked, or at a set time \u2014 record it with schedule_callback so you don't drop it if you go idle. If you're about to start a genuinely long-running or blocking piece of work \u2014 one where the user would otherwise sit and wait \u2014 mention ONCE, in passing, that you can reach them when it's done or if you hit a blocker, instead of them needing to babysit the terminal. Don't offer this for quick tasks, and don't repeat the offer if they've already said yes or no earlier in the conversation. NEVER go quietly idle while something might still be pending for you: whenever you end a turn with any Paigy notification unanswered (or any chance the user replied through the app while you worked), schedule your own ~2-minute wake-up (harness ScheduleWakeup or equivalent) and call check_replies when it fires; if still nothing, re-schedule and keep looping until resolved or the user says stop. For legibility, always use this exact wording \u2014 reason: 'Paigy idle check \u2014 waiting on <thing>', wake-up prompt: 'Paigy idle check: call check_replies and engage with anything unacknowledged; if idle, re-schedule (~2min).' \u2014 so the user can recognize every idle check at a glance. This self-polling in your own live session (full context intact) is the PRIMARY mechanism; the plugin's Stop hooks are only the dead-session safety net.";
99
+ }
100
+ var ContextSchema = z2.object({
101
+ title: z2.string().min(1).describe("One-line headline of what you need (required, non-empty)."),
102
+ description: z2.array(z2.string().min(1)).describe(
6
103
  "Semantic chunks of detail (each a standalone, non-empty piece). The user can select chunks to ask you to expand. MAY BE EMPTY: a claim whose whole content is its heading \u2014 a single sentence \u2014 has no body, and saying so beats repeating the heading underneath itself. That repeat is what `min(1)` used to force, at 2x the storage, with every reader subtracting it back out at render time."
7
104
  )
8
105
  });
9
- var ParticipantSchema = z.object({
10
- kind: z.enum(["human", "agent"]),
11
- id: z.string()
106
+ var ParticipantSchema = z2.object({
107
+ kind: z2.enum(["human", "agent"]),
108
+ id: z2.string()
12
109
  });
13
- var TransformSchema = z.enum([
110
+ var TransformSchema = z2.enum([
14
111
  "structure",
15
112
  // shape intent into an answer contract; pick channel/urgency — broker `ask`, `select` shapes, `points`
16
113
  "request_more",
@@ -26,25 +123,25 @@ var TransformSchema = z.enum([
26
123
  "summarize"
27
124
  // reduce volume, keep decision value — 30-turn cap, spoken briefing
28
125
  ]);
29
- var OptionSchema = z.object({
30
- id: z.string(),
31
- label: z.string(),
126
+ var OptionSchema = z2.object({
127
+ id: z2.string(),
128
+ label: z2.string(),
32
129
  // .describe() flows into the MCP contact JSON schema (zodToJsonSchema), so
33
130
  // the constraints below are what an agent reads when deciding to use these.
34
- html: z.string().max(16384).describe(
131
+ html: z2.string().max(16384).describe(
35
132
  "Optional sandboxed HTML/CSS preview for a visual 'pick one' (shown in the option card). Untrusted-sandboxed: NO JavaScript, NO external network or images \u2014 inline CSS and data: URIs only; <=16KB. Use for layout/CSS mockups, tables, diffs. For a hosted image use `image` instead."
36
133
  ).optional(),
37
- image: z.string().url().describe(
134
+ image: z2.string().url().describe(
38
135
  "Optional image URL rendered as the option's preview (plain image, not sandboxed). For agent-generated HTML/CSS mockups, use `html` instead."
39
136
  ).optional()
40
137
  });
41
- var VisualSchema = z.object({
42
- url: z.string().url(),
43
- label: z.string().optional()
138
+ var VisualSchema = z2.object({
139
+ url: z2.string().url(),
140
+ label: z2.string().optional()
44
141
  });
45
- var NotifyLevelSchema = z.enum(["inbox", "push", "banner", "call"]);
46
- var SelectShapeSchema = z.enum(["one", "many", "rank", "confirm", "text"]);
47
- var ReceiptEventSchema = z.enum([
142
+ var NotifyLevelSchema = z2.enum(["inbox", "push", "banner", "call"]);
143
+ var SelectShapeSchema = z2.enum(["one", "many", "rank", "confirm", "text"]);
144
+ var ReceiptEventSchema = z2.enum([
48
145
  "delivered",
49
146
  // the bundle reached the recipient at some level
50
147
  "seen",
@@ -74,41 +171,44 @@ var ReceiptEventSchema = z.enum([
74
171
  // be rewound by a writer that forgot to advance it.
75
172
  "restarted"
76
173
  ]);
77
- var AttentionSchema = z.object({
174
+ var AttentionSchema = z2.object({
78
175
  urgency: NotifyLevelSchema,
79
176
  /** The required answer shape, or null for a plain notify that asks nothing back. */
80
177
  select: SelectShapeSchema.nullable(),
81
178
  /** Coverage contract (#396) — points the answer must address; null = none declared. */
82
- points: z.array(z.string()).nullable(),
179
+ points: z2.array(z2.string()).nullable(),
83
180
  /** Whether the ask blocks the sender — what lets arbitration escalate it on silence. */
84
- blocking: z.boolean(),
181
+ blocking: z2.boolean(),
85
182
  /** Reserved (MODEL.md lists it): a response deadline. No row column yet — a later Phase 2
86
183
  * slice wires it; optional so today's rows/callers project cleanly. */
87
- deadline: z.string().datetime().nullable().optional()
184
+ deadline: z2.string().datetime().nullable().optional()
88
185
  });
89
- var NotifyRequestSchema = z.object({
186
+ var NotifyRequestFields = z2.object({
90
187
  /** Plaintext message content. Present on the plaintext path (today's shape);
91
188
  * ABSENT on the E2EE path, where the sealed `envelope` below carries it. The
92
189
  * superRefine at the bottom enforces exactly one of the two. */
93
190
  context: ContextSchema.optional(),
94
- options: z.array(OptionSchema.omit({ id: true })).min(1).optional().describe(
191
+ options: z2.array(OptionSchema.omit({ id: true })).min(OPTIONS_MIN).max(OPTIONS_MAX).optional().describe(
95
192
  "The choices, in order \u2014 required when select is 'one'/'many'/'rank', omitted otherwise. Ids are assigned automatically by position ('1', '2', \u2026); the user's answer references them as optionId(s)."
96
193
  ),
97
- points: z.array(z.string().min(1)).optional().describe(
194
+ points: z2.array(z2.string().min(1)).optional().describe(
98
195
  "The distinct things you need answered, each a short phrase \u2014 on a call the broker keeps the conversation going until each is addressed, and the reply reports which were covered, so a half-answer is never silently returned as final. Omit for single-part asks."
99
196
  ),
100
- visuals: z.array(VisualSchema).optional().describe(
197
+ visuals: z2.array(VisualSchema).optional().describe(
101
198
  "Images attached to the message itself \u2014 context for the whole question (a screenshot, a chart). For a preview on one selectable choice, use that option's `html`/`image` instead."
102
199
  ),
103
200
  /** Git repo the agent is working in ("owner/name"). Local MCP fills this from the checkout — omit unless overriding. */
104
- repo: z.string().optional(),
201
+ repo: z2.string().optional(),
105
202
  /** Git branch the agent is on. Local MCP fills this from the checkout — omit unless overriding. */
106
- branch: z.string().optional(),
203
+ branch: z2.string().optional(),
107
204
  /** Continue an existing conversation — the id of any notification in it (its root
108
205
  * is the conversation's identity). Omitted = start a new conversation. Renamed
109
206
  * from `parentId` (2026-08-03): one linkage system, the parent; the API edge
110
207
  * still accepts the old name from older clients. */
111
- parentId: z.string().uuid().optional(),
208
+ parentId: z2.string().uuid().optional(),
209
+ /** The durable outcome this contact advances. Optional during the notification-to-Work
210
+ * migration; when present, a blocking ask creates a DecisionNeed for this Work. */
211
+ workId: z2.string().uuid().optional(),
112
212
  urgency: NotifyLevelSchema.default("inbox").describe(
113
213
  "The level you're requesting \u2014 the user's account permissions + session mode can lower it. 'inbox' (default) = sits silently in the inbox for the user to get to. 'push' = a quiet passive push (lands in Notification Center, no sound) \u2014 a gentle heads-up. 'banner' = a time-sensitive banner/lock-screen push with sound (a 'paige') they tap to open \u2014 use when you need them soon-ish but it's not worth ringing them. 'call' = rings the user's phone now (a CallKit voice call) \u2014 use only when you genuinely need them in the moment (blocked and waiting, time-sensitive). context.title is what they see on the banner/ring, so make it specific."
114
214
  ),
@@ -116,7 +216,7 @@ var NotifyRequestSchema = z.object({
116
216
  * visible and marks it needs_input. Renamed from the old `parentId` (2026-08-03)
117
217
  * when `parentId` became the conversation handle: `parentId` says WHERE, this
118
218
  * says HOW. */
119
- clarifies: z.string().optional(),
219
+ clarifies: z2.string().optional(),
120
220
  /** E2EE (text lane): when the pairing is E2EE, the sealed replacements for the
121
221
  * plaintext content fields, keyed by field name. FINALIZED wire shape (was
122
222
  * provisional in the storage PR): a per-field map `{ context?, options?,
@@ -129,10 +229,10 @@ var NotifyRequestSchema = z.object({
129
229
  * notifications.envelope and relays it blindly; it never decrypts. Absent =
130
230
  * today's plaintext path (context/options/visuals carry the cleartext).
131
231
  * z.lazy because EnvelopeSchema is declared further down (E2EE section). */
132
- envelope: z.object({
133
- context: z.lazy(() => EnvelopeSchema).optional(),
134
- options: z.lazy(() => EnvelopeSchema).optional(),
135
- visuals: z.lazy(() => EnvelopeSchema).optional()
232
+ envelope: z2.object({
233
+ context: z2.lazy(() => EnvelopeSchema).optional(),
234
+ options: z2.lazy(() => EnvelopeSchema).optional(),
235
+ visuals: z2.lazy(() => EnvelopeSchema).optional()
136
236
  }).optional(),
137
237
  select: SelectShapeSchema.optional().describe(
138
238
  "How the user answers \u2014 required on the fully-shaped form, pick the shape that fits the question: 'one' = pick one option, 'many' = pick several, 'rank' = pick & order (each needs `options`); 'confirm' = yes/no or approve/deny; 'text' = free-form reply only (status updates, open questions). 'confirm' and 'text' take no options. Omit only when sending the simplified `ask` form \u2014 the broker picks the shape."
@@ -147,20 +247,20 @@ var NotifyRequestSchema = z.object({
147
247
  // (broker/agenda-design.md) — not by a wire cap the agent has to pre-summarize under.
148
248
  // Owner, 2026-07-28: "our actual limitation on how long something is to the user should
149
249
  // come from the broker splitting and summarizing." The cap that remains is a size guard.
150
- ask: z.string().min(1).max(1e4).optional().describe(
250
+ ask: z2.string().min(1).max(1e4).optional().describe(
151
251
  'SIMPLIFIED FORM \u2014 state in plain prose what you need to learn from the user and why it matters now (e.g. "I need to know whether to deploy the auth fix \u2014 tests are green, staging verified"). Write as much as the situation needs (up to 10k characters) \u2014 Paigy breaks it into topics and reads it back a few sentences at a time; do NOT pre-summarize it into one line. Paigy derives the title, answer shape, options, and delivery channel for you. Mutually exclusive with context/select/options \u2014 send one form or the other.'
152
252
  ),
153
- needs: z.array(z.string().min(1)).optional().describe(
253
+ needs: z2.array(z2.string().min(1)).optional().describe(
154
254
  "With `ask` only: the distinct things you need answered when the ask is multi-part \u2014 becomes the coverage contract (`points`), so a half-answer is never silently final."
155
255
  ),
156
- urgencyHint: z.enum(["whenever", "soon", "now"]).optional().describe(
256
+ urgencyHint: z2.enum(["whenever", "soon", "now"]).optional().describe(
157
257
  "With `ask` only: how urgently you need the answer \u2014 'whenever' (inbox), 'soon' (worth a heads-up), 'now' (you're blocked this minute). A hint, not a command: the user's settings still have the final word."
158
258
  ),
159
259
  /** #575: the ONE self-report that replaces urgencyHint + blocking — what happens
160
260
  * to the agent's work while it waits. Normalized server-side into those two
161
261
  * fields (normalizeWaiting) so everything downstream is untouched; explicit
162
262
  * urgencyHint/blocking win when both are sent. */
163
- waiting: z.enum(["none", "soft", "hard"]).optional().describe(
263
+ waiting: z2.enum(["none", "soft", "hard"]).optional().describe(
164
264
  "With `ask`: what happens to your work while you wait. 'none' = you're just informing the user. 'soft' = you'd like an answer but can keep working. 'hard' = you are stopped until they answer (reaches them urgently and escalates to a real phone call if unanswered). Replaces urgencyHint + blocking \u2014 send this one field."
165
265
  ),
166
266
  /** Δ9b (#895): HOLD this claim so the sender can correct the plan before anyone is
@@ -168,113 +268,123 @@ var NotifyRequestSchema = z.object({
168
268
  * holding by default would charge every quiet claim that minute before any agent could
169
269
  * correct anything. Ignored for `waiting: 'hard'`: a blocking ask rings on what we have,
170
270
  * and the enrichment can still land mid-call (#781 re-plans the unspoken tail). */
171
- confirm: z.boolean().optional().describe(
271
+ confirm: z2.boolean().optional().describe(
172
272
  "Hold this one so you can correct the plan before the user is interrupted. The response comes back with `held: true` and the plan; POST the confirm route to release it (with options/visuals/urgency corrections, or nothing at all). If you never do, it is announced anyway a couple of minutes later. Ignored when waiting is 'hard'."
173
273
  ),
174
274
  /** #575: a RELAY of the user's explicitly stated preference, never the agent's
175
275
  * choice. Outranks waiting in both directions: 'call' rings even for a
176
276
  * waiting:'none' "call me when it's done"; 'message' never rings even for
177
277
  * waiting:'hard'. */
178
- channel: z.enum(["call", "message"]).optional().describe(
278
+ channel: z2.enum(["call", "message"]).optional().describe(
179
279
  "Only if the user explicitly said how to reach them \u2014 'call me' \u2192 'call', 'just message/text me' \u2192 'message'. Omit otherwise; Paigy picks."
180
280
  ),
181
- confirmStyle: z.enum(["yesno", "approve"]).default("yesno").describe(
281
+ confirmStyle: z2.enum(["yesno", "approve"]).default("yesno").describe(
182
282
  "Labels for a select:'confirm' paige \u2014 'yesno' (Yes/No) or 'approve' (Approve/Deny). Ignored unless select is 'confirm'."
183
283
  ),
184
- blocking: z.boolean().default(false).describe(
284
+ blocking: z2.boolean().default(false).describe(
185
285
  "Set true when real downstream work is stuck behind this specific decision \u2014 you can't make meaningful progress until it's answered. This is the real signal for how urgently the user should be reached; it's what the premier use case (an agent that stays unblocked instead of going idle) depends on. Independent of `urgency`: a `banner`-level question can still be `blocking` (something IS stuck, just not time-critical enough to ring for immediately) \u2014 if it goes unanswered a while, Paigy escalates it to a real call using this flag rather than guessing from how many other things happen to be pending. Leave false for anything you could work around, defer, or where other useful work exists meanwhile."
186
286
  )
187
- }).superRefine((r, ctx) => {
287
+ });
288
+ var NotifyRequestSchema = NotifyRequestFields.superRefine((r, ctx) => {
188
289
  const sealed = !!r.envelope;
189
290
  if (sealed) {
190
291
  if (!r.envelope?.context)
191
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
292
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["envelope", "context"], message: "sealed request must include envelope.context" });
192
293
  for (const f of ["context", "options", "visuals"]) {
193
294
  if (r[f] !== void 0)
194
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
295
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: [f], message: `E2EE request must not carry plaintext ${f} \u2014 it's sealed in envelope.${f}` });
195
296
  }
196
297
  if (r.points !== void 0)
197
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
298
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["points"], message: "E2EE request must not carry plaintext points" });
198
299
  if (r.ask !== void 0)
199
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
300
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["ask"], message: "E2EE request must not carry a plaintext ask \u2014 derive the shape agent-side and seal it" });
200
301
  if (r.needs !== void 0)
201
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
302
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["needs"], message: "E2EE request must not carry plaintext needs" });
202
303
  return;
203
304
  }
204
305
  if (r.ask !== void 0) {
205
306
  for (const f of ["context", "select", "points"]) {
206
307
  if (r[f] !== void 0)
207
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: [f], message: `the simplified \`ask\` form takes no ${f} \u2014 the broker derives the answer shape from your prose. Drop ${f} and say it in \`ask\` instead ("should I\u2026" for approve/deny, "which of these\u2026" for a pick), passing \`options\` when you're offering concrete alternatives.` });
308
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: [f], message: `the simplified \`ask\` form takes no ${f} \u2014 the broker derives the answer shape from your prose. Drop ${f} and say it in \`ask\` instead ("should I\u2026" for approve/deny, "which of these\u2026" for a pick), passing \`options\` when you're offering concrete alternatives.` });
208
309
  }
209
310
  return;
210
311
  }
211
312
  if (r.needs !== void 0 || r.urgencyHint !== void 0)
212
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["needs"], message: "needs/urgencyHint belong to the simplified `ask` form \u2014 with a shaped request use points/urgency" });
313
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["needs"], message: "needs/urgencyHint belong to the simplified `ask` form \u2014 with a shaped request use points/urgency" });
213
314
  if (!r.context)
214
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["context"], message: "context is required (plaintext path)" });
315
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["context"], message: "context is required (plaintext path)" });
215
316
  if (!r.select)
216
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["select"], message: "select is required on the shaped form" });
317
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["select"], message: "select is required on the shaped form" });
217
318
  const needsOptions = r.select === "one" || r.select === "many" || r.select === "rank";
218
319
  if (needsOptions && !r.options?.length)
219
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' requires options` });
320
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' requires options` });
220
321
  if (!needsOptions && r.options?.length)
221
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' takes no options` });
322
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["options"], message: `select:'${r.select}' takes no options` });
323
+ });
324
+ var NotifyStatusSchema = z2.enum(["pending", "answered", "ignored"]);
325
+ var AgentStateSchema = z2.enum(["idle", "in_progress", "completed", "needs_input"]);
326
+ var SetTaskStateSchema = z2.object({
327
+ state: z2.enum(["in_progress", "completed", "needs_input"])
222
328
  });
223
- var NotifyStatusSchema = z.enum(["pending", "answered", "ignored"]);
224
- var AgentStateSchema = z.enum(["idle", "in_progress", "completed", "needs_input"]);
225
- var SetTaskStateSchema = z.object({
226
- state: z.enum(["in_progress", "completed", "needs_input"])
329
+ var SetWorkStateSchema = z2.object({
330
+ workId: z2.string().uuid().optional(),
331
+ notificationId: z2.string().optional(),
332
+ state: SetTaskStateSchema.shape.state
333
+ }).refine((value) => Number(Boolean(value.workId)) + Number(Boolean(value.notificationId)) === 1, {
334
+ message: "exactly one of workId or notificationId is required"
227
335
  });
228
- var TurnSchema = z.object({
229
- prompt: z.string(),
230
- reply: z.string()
336
+ var TurnSchema = z2.object({
337
+ prompt: z2.string(),
338
+ reply: z2.string()
231
339
  });
232
- var UserAnswerSchema = z.discriminatedUnion("kind", [
233
- z.object({ kind: z.literal("option"), optionId: z.string(), label: z.string().optional() }),
234
- z.object({ kind: z.literal("text"), text: z.string() }),
235
- z.object({ kind: z.literal("ignored") }),
236
- z.object({ kind: z.literal("multi"), optionIds: z.array(z.string()), labels: z.array(z.string()).optional() }),
237
- z.object({ kind: z.literal("ranked"), optionIds: z.array(z.string()), labels: z.array(z.string()).optional() }),
238
- z.object({ kind: z.literal("clarify"), chunks: z.array(z.string()).min(1) }),
239
- z.object({ kind: z.literal("confirm"), approved: z.boolean() }),
240
- z.object({ kind: z.literal("turns"), turns: z.array(TurnSchema).min(1) }),
340
+ var UserAnswerSchema = z2.discriminatedUnion("kind", [
341
+ z2.object({ kind: z2.literal("option"), optionId: z2.string(), label: z2.string().optional() }),
342
+ z2.object({ kind: z2.literal("text"), text: z2.string() }),
343
+ z2.object({ kind: z2.literal("ignored") }),
344
+ z2.object({ kind: z2.literal("multi"), optionIds: z2.array(z2.string()), labels: z2.array(z2.string()).optional() }),
345
+ z2.object({ kind: z2.literal("ranked"), optionIds: z2.array(z2.string()), labels: z2.array(z2.string()).optional() }),
346
+ z2.object({ kind: z2.literal("clarify"), chunks: z2.array(z2.string()).min(1) }),
347
+ z2.object({ kind: z2.literal("confirm"), approved: z2.boolean() }),
348
+ z2.object({ kind: z2.literal("turns"), turns: z2.array(TurnSchema).min(1) }),
241
349
  /** An auto-answer derived from the user's PAST decisions (broker/precedent-design.md §2):
242
350
  * delivered through the same settle/await path as a human answer, carrying the judge's
243
351
  * derivation and the precedent ids it grew from. Always paired with a visible trail
244
352
  * card the user can reply to — the broker never overrides the user. */
245
- z.object({ kind: z.literal("precedent"), answer: z.string(), derivation: z.string(), sources: z.array(z.string()).min(1) })
353
+ z2.object({ kind: z2.literal("precedent"), answer: z2.string(), derivation: z2.string(), sources: z2.array(z2.string()).min(1) })
246
354
  ]);
247
- var IntentSchema = z.object({
355
+ var IntentSchema = z2.object({
248
356
  // The full vocabulary the bot's mapper emits (mapper.INTENT_KINDS) — the schema lagged
249
357
  // it by two ("detail", "feedback"), and because the settle handler parsed the array
250
358
  // all-or-nothing, ONE feedback act silently dropped EVERY intent on the call,
251
359
  // questions included. Found auditing five calls' stored feedback, 2026-08-01.
252
- kind: z.enum(["defer", "delegate", "channel", "question", "detail", "feedback", "command", "control"]),
253
- detail: z.string(),
360
+ kind: z2.enum(["defer", "delegate", "channel", "question", "detail", "feedback", "command", "control"]),
361
+ detail: z2.string(),
254
362
  /** Defer only: seconds until the callback the caller asked for, when something upstream
255
363
  * already read the time. Nothing sets it today (#397 documented an MCP parser that was
256
364
  * never written) — the API reads the defer's `detail` itself with `notes/when.ts`
257
365
  * (`parseDelay`, #1292), and a value here simply wins over that reading. */
258
- dueInSeconds: z.number().int().positive().optional(),
366
+ dueInSeconds: z2.number().int().positive().optional(),
259
367
  /** Feedback only (#812): WHICH failure the complaint names — typed by the mapper that
260
368
  * already read the utterance, so `feedback_from_call.kind` stops defaulting to
261
369
  * 'other' on every row. A table that records that something was wrong and nothing
262
370
  * about what cannot answer "is the bot looping less this week?". */
263
- fault: z.enum(["loop", "unanswered", "overridden", "misheard", "slow", "other"]).optional()
371
+ fault: z2.enum(["loop", "unanswered", "overridden", "misheard", "slow", "other"]).optional()
264
372
  });
265
- var RideAlongSchema = z.object({
373
+ var RideAlongSchema = z2.object({
266
374
  /** The note this came from — assign/clarify/close it through /api/notes/:id. */
267
- noteId: z.string(),
375
+ noteId: z2.string(),
268
376
  /** What to do, in the owner's own words (the note's headline). Never model-rewritten. */
269
- text: z.string(),
377
+ text: z2.string(),
270
378
  /** The thread to report back on, when the note was dispatched over the request rail. */
271
- parentId: z.string().nullable()
379
+ parentId: z2.string().nullable()
272
380
  });
273
- var AwaitItemSchema = z.discriminatedUnion("type", [
274
- z.object({
275
- type: z.literal("reply"),
276
- parentId: z.string(),
277
- notificationId: z.string(),
381
+ var AwaitItemSchema = z2.discriminatedUnion("type", [
382
+ z2.object({
383
+ type: z2.literal("reply"),
384
+ parentId: z2.string(),
385
+ notificationId: z2.string(),
386
+ workId: z2.string().uuid().optional(),
387
+ decisionId: z2.string().uuid().optional(),
278
388
  answer: UserAnswerSchema,
279
389
  /** E2EE: present when the answer is sealed. The server relays the opaque answer
280
390
  * envelope + the plaintext `ignored` status hint; the receiving agent OPENS it
@@ -282,126 +392,146 @@ var AwaitItemSchema = z.discriminatedUnion("type", [
282
392
  * against `ignored` as tampering. Absent = today's plaintext answer (in `answer`).
283
393
  * On a sealed reply the plaintext `answer` is a placeholder (kind reflects only
284
394
  * the `ignored` bit) — never the real content, which stays sealed. */
285
- sealed: z.lazy(() => SealedAnswerSchema).optional(),
286
- /** Broker extras (#381), present when the answer was mapped from a call: next
287
- * steps the user attached ("call me after lunch" → defer — act on it via
288
- * schedule_callback) and the raw words the shaped answer was mapped from. */
289
- intents: z.array(IntentSchema).optional(),
290
- transcript: z.string().optional(),
395
+ sealed: z2.lazy(() => SealedAnswerSchema).optional(),
396
+ /** WHAT THE AGENT CANNOT KNOW FROM THE FIELDS BESIDE IT (owner, 2026-09-04, issue
397
+ * #1537). One line, built from the record: the ask and the caller's reply VERBATIM,
398
+ * the notification they belong to, and the `contact` call that reaches the person
399
+ * again, spelled with its real arguments. It restates nothing — deleting the brain's
400
+ * acts deleted the paraphrase, and this is not it coming back: an agent that reads
401
+ * "call me back after you merge" in their own words decides for itself what to do,
402
+ * and now knows exactly which call to make. Absent when either half is missing —
403
+ * a sentence with a hole in it is worse than no sentence. */
404
+ note: z2.string().optional(),
405
+ /** The call record rendered for THIS agent (`voice/record-design.md`): the words the
406
+ * shaped answer was mapped from, filtered to its own claims. There is no second list
407
+ * of labels beside it — the acts went 2026-09-04 and `intents` went with them (owner,
408
+ * 2026-09-04): the agent reads the sentence and decides. */
409
+ transcript: z2.string().optional(),
291
410
  /** Coverage report (#396), when the ask declared `points`: which of them this
292
411
  * answer addressed. Missing points = re-ask or proceed knowingly partial. */
293
- covered: z.array(z.string()).optional(),
412
+ covered: z2.array(z2.string()).optional(),
294
413
  /** Ride-alongs (RideAlongSchema) — pending work for you, attached to the moment you
295
414
  * became free. Only `reply` and `idle` carry it: those are the two outcomes that
296
415
  * END a wait. `remind`, `superseded` and `turn` are mid-flight, and handing an
297
416
  * agent a side-quest while it is still holding the line is how the main thing gets
298
417
  * dropped. Absent/empty = nothing owed. */
299
- also: z.array(RideAlongSchema).optional()
418
+ also: z2.array(RideAlongSchema).optional()
300
419
  }),
301
- z.object({
302
- type: z.literal("remind"),
303
- parentId: z.string(),
304
- notificationId: z.string(),
305
- remindAt: z.string().datetime({ offset: true }),
420
+ z2.object({
421
+ type: z2.literal("remind"),
422
+ parentId: z2.string(),
423
+ notificationId: z2.string(),
424
+ remindAt: z2.string().datetime({ offset: true }),
306
425
  /** Seconds until remindAt, server-computed — pass straight to ScheduleWakeup. */
307
- remindInSeconds: z.number()
426
+ remindInSeconds: z2.number()
308
427
  }),
309
428
  /** The awaited ask was REPLACED by a newer notification on its thread (e.g. a
310
429
  * post-feedback revision, #633) — the user will never answer this id. Stop
311
430
  * awaiting it; the live ask is the thread's newest turn (await that one, or
312
431
  * re-orient via get_thread / check_replies). */
313
- z.object({
314
- type: z.literal("superseded"),
315
- parentId: z.string(),
316
- notificationId: z.string()
432
+ z2.object({
433
+ type: z2.literal("superseded"),
434
+ parentId: z2.string(),
435
+ notificationId: z2.string()
317
436
  }),
318
437
  /** A LIVE call's turn, streamed as it lands (#783). PROVISIONAL: the user can still
319
438
  * revise any of these until the final reply arrives — partial = intelligence,
320
439
  * settled = authorization. Use it to PREPARE (fetch, draft, warm), never to act
321
440
  * irreversibly. If `acts` carries a question aimed at you and you know the answer,
322
441
  * contact on the same thread right away — the caller hears it on the same call. */
323
- z.object({
324
- type: z.literal("partial"),
325
- notificationId: z.string(),
326
- inFlight: z.literal(true),
327
- turn: z.object({
328
- idx: z.number(),
329
- prompt: z.string(),
330
- reply: z.string(),
331
- acts: z.array(IntentSchema).nullable().optional()
442
+ z2.object({
443
+ type: z2.literal("partial"),
444
+ notificationId: z2.string(),
445
+ inFlight: z2.literal(true),
446
+ turn: z2.object({
447
+ idx: z2.number(),
448
+ prompt: z2.string(),
449
+ reply: z2.string(),
450
+ acts: z2.array(IntentSchema).nullable().optional()
332
451
  })
333
452
  }),
334
- z.object({ type: z.literal("idle"), also: z.array(RideAlongSchema).optional() })
453
+ z2.object({ type: z2.literal("idle"), also: z2.array(RideAlongSchema).optional() })
335
454
  ]);
336
- var CallbackTriggerSchema = z.enum(["on_done", "on_blocked", "scheduled"]);
337
- var ScheduleCallbackSchema = z.object({
338
- parentId: z.string().describe("The thread to call back on (from a prior contact / reply / request)."),
455
+ var CallbackTriggerSchema = z2.enum(["on_done", "on_blocked", "scheduled"]);
456
+ var ScheduleCallbackSchema = z2.object({
457
+ parentId: z2.string().describe("The thread to call back on (from a prior contact / reply / request)."),
339
458
  trigger: CallbackTriggerSchema,
340
- dueInSeconds: z.number().int().positive().optional().describe("For 'scheduled' only: how many seconds from now to fire."),
341
- note: z.string().optional().describe("What to tell the user when you follow up.")
459
+ dueInSeconds: z2.number().int().positive().optional().describe("For 'scheduled' only: how many seconds from now to fire."),
460
+ note: z2.string().optional().describe("What to tell the user when you follow up.")
342
461
  });
343
- var PendingRepliesSchema = z.object({
344
- replies: z.array(
345
- z.object({
346
- parentId: z.string(),
347
- notificationId: z.string(),
462
+ var PendingRepliesSchema = z2.object({
463
+ replies: z2.array(
464
+ z2.object({
465
+ parentId: z2.string(),
466
+ notificationId: z2.string(),
467
+ workId: z2.string().uuid().optional(),
468
+ decisionId: z2.string().uuid().optional(),
348
469
  answer: UserAnswerSchema,
349
470
  /** E2EE: the sealed answer (opaque envelope + plaintext `ignored` hint) when the
350
471
  * pairing is E2EE — the agent opens it and re-derives the real answer. Absent =
351
472
  * plaintext answer (in `answer`). See AwaitItemSchema's reply variant. */
352
- sealed: z.lazy(() => SealedAnswerSchema).optional(),
353
- /** Broker extras (#381): next steps the user attached to a call-mapped answer
354
- * ("call me after lunch" → defer — act on it via schedule_callback) and the
355
- * raw words the shaped answer was mapped from. */
356
- intents: z.array(IntentSchema).optional(),
357
- transcript: z.string().optional(),
473
+ sealed: z2.lazy(() => SealedAnswerSchema).optional(),
474
+ /** The call record rendered for THIS agent: the raw words the shaped answer was
475
+ * mapped from, filtered to its own claims. See AwaitItemSchema's reply variant. */
476
+ transcript: z2.string().optional(),
358
477
  /** Coverage report (#396): which declared `points` this answer addressed. */
359
- covered: z.array(z.string()).optional()
478
+ covered: z2.array(z2.string()).optional()
360
479
  })
361
480
  ),
362
- pending: z.array(
363
- z.object({ parentId: z.string(), notificationId: z.string(), createdAt: z.string() })
481
+ pending: z2.array(
482
+ z2.object({ parentId: z2.string(), notificationId: z2.string(), createdAt: z2.string() })
364
483
  ),
365
484
  /** WHO YOU ARE on this account (field report 2026-08-28): the name and device the user
366
485
  * sees for this session's identity. From inside a session there was no way to find out —
367
486
  * `pair` with no arguments can HATCH a fresh identity, so it is not a safe probe — and an
368
487
  * agent that cannot tell which agent it is cannot tell whether work addressed to
369
488
  * "Reta" was addressed to it. Absent only for a token with no pairing behind it. */
370
- you: z.object({ name: z.string(), device: z.string().nullable(), tokenId: z.string() }).optional(),
489
+ you: z2.object({ name: z2.string(), device: z2.string().nullable(), tokenId: z2.string() }).optional(),
371
490
  /** User-initiated requests addressed to this agent; act on them and reply via
372
491
  * contact on the same parentId. Keeps reappearing until you call
373
- * set_task_state on its notificationId. */
374
- requests: z.array(
375
- z.object({
376
- parentId: z.string(),
377
- notificationId: z.string(),
378
- text: z.string(),
379
- createdAt: z.string(),
492
+ * set_work_state on its workId (or notificationId once while bootstrapping). */
493
+ requests: z2.array(
494
+ z2.object({
495
+ parentId: z2.string(),
496
+ notificationId: z2.string(),
497
+ workId: z2.string().uuid().optional(),
498
+ text: z2.string(),
499
+ createdAt: z2.string(),
380
500
  /** The user seeded this request with a past conversation — call get_thread on it
381
501
  * FIRST and treat the transcript as prior context (#57/#251). */
382
- contextParentId: z.string().optional(),
502
+ contextParentId: z2.string().optional(),
383
503
  /** STRANDED (field report 2026-08-28): this request was addressed to ANOTHER agent on
384
504
  * the account — the name here — which has not been seen since it landed, so nobody
385
505
  * came for it. Handed to you because you are the session that is here. Take it like
386
- * any request (set_task_state claims it, reply with contact on its parentId), and say
506
+ * any request (set_work_state claims it, reply with contact on its parentId), and say
387
507
  * whose it was, because the user chose that agent on purpose. */
388
- stranded: z.string().optional()
508
+ stranded: z2.string().optional()
389
509
  })
390
510
  ),
511
+ /** Durable outcomes currently owned by this agent. This is the Work-native queue; flat
512
+ * notification lists remain during migration so old clients keep their existing view. */
513
+ work: z2.array(z2.object({
514
+ workId: z2.string().uuid(),
515
+ parentId: z2.string().optional(),
516
+ objective: z2.string().nullable(),
517
+ state: z2.enum(["active", "blocked", "waiting_external"]),
518
+ blockedOn: z2.array(z2.string().uuid()),
519
+ updatedAt: z2.string()
520
+ })).optional(),
391
521
  /** Callbacks you owe the user that are now DUE (you said you'd follow up when done,
392
522
  * if blocked, or at a time that has passed). Re-surfaced every sweep until you
393
523
  * fulfill one by calling contact on its parentId. */
394
524
  /** Ride-alongs (RideAlongSchema): notes assigned to this agent that no wake could
395
525
  * reach. Same array the contact/await replies carry — one queue, every carrier. */
396
- also: z.array(RideAlongSchema).optional(),
397
- owedCallbacks: z.array(
398
- z.object({ parentId: z.string(), trigger: CallbackTriggerSchema, note: z.string() })
526
+ also: z2.array(RideAlongSchema).optional(),
527
+ owedCallbacks: z2.array(
528
+ z2.object({ parentId: z2.string(), trigger: CallbackTriggerSchema, note: z2.string() })
399
529
  ),
400
530
  /** Work (either direction) you reported in_progress a while ago and never reported
401
531
  * completed — likely left half-done by this session or a prior one that crashed or
402
- * went idle. Report a real state (set_task_state) or continue the work. */
403
- stalled: z.array(
404
- z.object({ parentId: z.string(), notificationId: z.string(), title: z.string().nullable(), startedAt: z.string() })
532
+ * went idle. Report a real state (set_work_state) or continue the work. */
533
+ stalled: z2.array(
534
+ z2.object({ parentId: z2.string(), notificationId: z2.string(), title: z2.string().nullable(), startedAt: z2.string() })
405
535
  ),
406
536
  /** The queue rail (#614, pending/design.md): the same replies + requests, grouped by
407
537
  * thread and ordered oldest-thread-first, so you work ONE thread at a time — fold all of
@@ -410,123 +540,125 @@ var PendingRepliesSchema = z.object({
410
540
  * ride the next turn. `items` are that thread's replies/requests in arrival order; the
411
541
  * full payload for each is in the flat `replies`/`requests` arrays (matched by
412
542
  * notificationId). Derived, never stored — a crashed agent recomputes it exactly. */
413
- threads: z.array(
414
- z.object({
415
- parentId: z.string(),
416
- busy: z.boolean(),
417
- items: z.array(
418
- z.object({
419
- kind: z.enum(["reply", "request"]),
420
- notificationId: z.string(),
421
- at: z.string()
543
+ threads: z2.array(
544
+ z2.object({
545
+ parentId: z2.string(),
546
+ busy: z2.boolean(),
547
+ items: z2.array(
548
+ z2.object({
549
+ kind: z2.enum(["reply", "request"]),
550
+ notificationId: z2.string(),
551
+ at: z2.string()
422
552
  })
423
553
  )
424
554
  })
425
555
  )
426
556
  });
427
- var NotifyResponseSchema = z.object({
428
- notificationId: z.string(),
557
+ var NotifyResponseSchema = z2.object({
558
+ notificationId: z2.string(),
559
+ workId: z2.string().uuid().optional(),
560
+ decisionId: z2.string().uuid().optional(),
429
561
  status: NotifyStatusSchema,
430
- createdAt: z.string().datetime(),
562
+ createdAt: z2.string().datetime(),
431
563
  answer: UserAnswerSchema.optional(),
432
- answeredAt: z.string().datetime().optional(),
564
+ answeredAt: z2.string().datetime().optional(),
433
565
  /** Ride-alongs for THIS agent — pending work it should pick up when it's done with
434
566
  * what it came for. Present on any reply, because an unwakeable agent's only
435
567
  * reliable moment is one it initiated. Absent/empty = nothing owed. */
436
- also: z.array(RideAlongSchema).optional()
568
+ also: z2.array(RideAlongSchema).optional()
437
569
  });
438
- var NotifyPlanUnitSchema = z.object({
439
- notificationId: z.string(),
570
+ var NotifyPlanUnitSchema = z2.object({
571
+ notificationId: z2.string(),
440
572
  /** The unit's own heading, so the agent can tell which of its paragraphs this became. */
441
- title: z.string(),
573
+ title: z2.string(),
442
574
  /** How loudly this unit was arbitrated to arrive — per unit, which is the point of units. */
443
575
  level: NotifyLevelSchema,
444
576
  /** Answered from something the user already decided: nobody is interrupted, and a trail card
445
577
  * says so. The agent should not wait on this one. */
446
- settled: z.literal(true).optional(),
578
+ settled: z2.literal(true).optional(),
447
579
  /** What this unit would need to be answerable and does not carry (#894). A PROPOSAL to the
448
580
  * agent — nothing here changed the ask, and ignoring it costs nothing. */
449
- needs: z.array(z.enum(["options", "visuals"])).optional(),
581
+ needs: z2.array(z2.enum(["options", "visuals"])).optional(),
450
582
  /** The SHAPE the broker would give this unit, for the agent to ratify (#886/#894). The
451
583
  * split layer reads prose and can see that a paragraph is a yes/no or a pick-one — but a
452
584
  * broker that DECIDES that destroys the only fact separating a statement from a real ask
453
585
  * (#731), so it is offered, never applied: the unit is stored `text` until the agent
454
586
  * confirms the shape (POST /notify/:id/confirm). Ignoring it costs nothing. */
455
- proposal: z.object({
587
+ proposal: z2.object({
456
588
  select: SelectShapeSchema,
457
- options: z.array(z.object({ label: z.string().min(1) })).optional()
589
+ options: z2.array(z2.object({ label: z2.string().min(1) })).optional()
458
590
  }).optional(),
459
591
  /** What the broker READ this unit as wanting from the human (#952 layer 2): a `decision`
460
592
  * between alternatives, an `approval` the agent is blocked on, or `knowledge` it just
461
593
  * needs to know. Reported so the agent can correct a misread the same way it ratifies a
462
594
  * shape — the read RAISES (a decision always asks) and never silences a question the
463
595
  * agent declared (#731, #923). */
464
- wants: z.enum(["decision", "approval", "knowledge"]).optional()
596
+ wants: z2.enum(["decision", "approval", "knowledge"]).optional()
465
597
  });
466
- var NotifyPlanSchema = z.object({
467
- units: z.array(NotifyPlanUnitSchema),
598
+ var NotifyPlanSchema = z2.object({
599
+ units: z2.array(NotifyPlanUnitSchema),
468
600
  /** Which unit is this arrival's ONE interruption (units-design.md D23). Absent means nobody
469
601
  * was interrupted — every unit was either settled or quiet enough to sit in the inbox. */
470
- speaks: z.string().optional()
602
+ speaks: z2.string().optional()
471
603
  });
472
- var UserResponseSchema = z.object({
473
- requestId: z.string(),
604
+ var UserResponseSchema = z2.object({
605
+ requestId: z2.string(),
474
606
  answer: UserAnswerSchema,
475
- answeredAt: z.string().datetime(),
476
- intents: z.array(IntentSchema).optional(),
477
- transcript: z.string().optional(),
607
+ answeredAt: z2.string().datetime(),
608
+ transcript: z2.string().optional(),
478
609
  /** E2EE: the sealed answer (opaque envelope + plaintext `ignored` hint) when the item was
479
610
  * E2EE-sealed. Present → the server persists it opaquely and branches status on `ignored`;
480
611
  * the plaintext `answer` is a placeholder (`{ kind: "ignored" }`) the server ignores for a
481
612
  * sealed row. Absent = today's plaintext answer, unchanged. */
482
- sealed: z.lazy(() => SealedAnswerSchema).optional(),
613
+ sealed: z2.lazy(() => SealedAnswerSchema).optional(),
483
614
  /** Coverage report (#396): which of the ask's declared `points` were addressed. */
484
- covered: z.array(z.string()).optional()
615
+ covered: z2.array(z2.string()).optional()
485
616
  });
486
- var VoiceKeySchema = z.enum(["rachel", "george", "jessica", "brian", "lily"]);
487
- var AgendaTurnSchema = z.object({
617
+ var VoiceKeySchema = z2.enum(["rachel", "george", "jessica", "brian", "lily"]);
618
+ var AgendaTurnSchema = z2.object({
488
619
  /** Twin coverage (#1089): sibling claim ids this asking turn's answer ALSO settles —
489
620
  * the planner declares duplicates instead of asking them twice. */
490
- coveredIds: z.array(z.string()).optional(),
621
+ coveredIds: z2.array(z2.string()).optional(),
491
622
  /** At most three short spoken sentences. Capped because a turn is a breath: a 1031-char
492
623
  * line went out on 2026-07-28 and the caller could not answer it at all. */
493
- info: z.array(z.string().min(1)).max(3).default([]),
494
- question: z.string().min(1).nullable(),
624
+ info: z2.array(z2.string().min(1)).max(3).default([]),
625
+ question: z2.string().min(1).nullable(),
495
626
  /** True on the one turn carrying the agent's own declared question. */
496
- asks: z.boolean().optional(),
627
+ asks: z2.boolean().optional(),
497
628
  /** The claim this turn belongs to (#781) — the RETURN identity: answers route by it.
498
629
  * Absent on a single-claim plan (the session's own claim) and on shared context turns,
499
630
  * which route nothing. */
500
- claimId: z.string().optional(),
631
+ claimId: z2.string().optional(),
501
632
  /** The claim's voice key (#462) — the OUTBOUND identity, audible who-is-asking. */
502
- voice: z.string().optional(),
633
+ voice: z2.string().optional(),
503
634
  /** The claim's AGENT NAME (#838) — the spoken identity. A voice alone doesn't say
504
635
  * whose request this is: an item that folded in from another agent arrived as a bare
505
636
  * non-sequitur ("First real production sign-in is yours to make whenever you want.")
506
637
  * and the owner answered "What?". The bot names the agent before its first turn. */
507
- agent: z.string().optional(),
638
+ agent: z2.string().optional(),
639
+ /** The claim's agent by ID — the pairing's connection id (`notifications.token_id`), the
640
+ * same id a face is minted from. A name is not an identity: two pairings may be called
641
+ * "Claude", and a name cannot be joined on. The record's entries carry it (`agent_id`)
642
+ * so "who said that" survives the call, and it rides PER TURN because a coalesced call
643
+ * speaks for several agents — the turn is the only place that knows which. */
644
+ agentId: z2.string().optional(),
508
645
  select: SelectShapeSchema.optional(),
509
- options: z.array(OptionSchema.omit({ id: true })).optional(),
510
- /** The seat was satisfied by the call's own ACCOUNT (replan-design.md, user_info): the
511
- * caller already answered this claim in an earlier utterance, quoted here VERBATIM —
512
- * the bot speaks the turn's short confirmation, posts these words as the claim's
513
- * answer, and never re-asks. Grounded at parse time: an invented settle is #796. */
514
- settle: z.string().optional(),
646
+ options: z2.array(OptionSchema.omit({ id: true })).optional(),
515
647
  /** Pacing (#826, owner 2026-08-03: "how fast we move through them ... are parameters"):
516
648
  * seconds the floor stays open after this turn speaks. Absent = the bot's defaults
517
649
  * (the beat for context, the answer window for asks). Clamped bot-side. */
518
- pace: z.number().positive().optional(),
650
+ pace: z2.number().positive().optional(),
519
651
  /** Whether the walk WAITS for an answer before moving on. Absent = derived as today
520
652
  * (a question blocks, context flows). blocking:false on a question = ask and move
521
653
  * on, the claim stays pending; blocking:true on context = hold for a reply. */
522
- blocking: z.boolean().optional()
654
+ blocking: z2.boolean().optional()
523
655
  });
524
656
  var CLAIM_STALE_MS = 30 * 6e4;
525
- var InboxItemSchema = z.object({
526
- id: z.string(),
657
+ var InboxItemSchema = z2.object({
658
+ id: z2.string(),
527
659
  /** The conversation thread + connection this item lives on. Present on the replied
528
660
  * detail — they power History's "Continue" / "New session from this" (#57/#251). */
529
- parentId: z.string().optional(),
661
+ parentId: z2.string().optional(),
530
662
  /** THE ARRIVAL this row is one unit of (`notifications.ask_id` → `asks`). A claim is one
531
663
  * arrival and its units are N rows of it, so this — not `parentId` — is what makes a
532
664
  * multi-part notification one thing on screen. The thread is the whole CONVERSATION: it
@@ -534,13 +666,13 @@ var InboxItemSchema = z.object({
534
666
  * unrelated updates as a single "12-part request". Absent on rows written before the
535
667
  * `asks` table, and on anything that never went through `notify` — both fall back to the
536
668
  * thread, which is what the client did for all rows until now. */
537
- askId: z.string().optional(),
669
+ askId: z2.string().optional(),
538
670
  /** WHERE this unit sat in the message it was cut from (`notifications.seq`). The batch
539
671
  * shares one `created_at` to the microsecond, so without it the author's order is
540
672
  * unrecoverable client-side — a four-paragraph briefing rendered opening-paragraph-last
541
673
  * (live 2026-08-10, D35). The API already orders by it; this lets a reader that
542
674
  * re-sorts (grouping, filtering) put an arrival back in the order it was written. */
543
- seq: z.number().int().optional(),
675
+ seq: z2.number().int().optional(),
544
676
  /** HOW MANY units the arrival was cut into. A device reads a LENS, never the arrival —
545
677
  * `/api/inbox` serves `open`, so the units already settled are gone from it — and a client
546
678
  * counting what it can see is counting what is LEFT. Walking a three-unit ask on the answer
@@ -549,13 +681,13 @@ var InboxItemSchema = z.object({
549
681
  * server that can still see every row states it. Absent on any row with no `askId`: a
550
682
  * unit knows WHICH ask it came from and WHERE it sat in it, and how many there were is
551
683
  * the one part of its own arrival a single row cannot answer. */
552
- units: z.number().int().positive().optional(),
553
- tokenId: z.string().optional(),
684
+ units: z2.number().int().positive().optional(),
685
+ tokenId: z2.string().optional(),
554
686
  status: NotifyStatusSchema,
555
687
  context: ContextSchema,
556
- options: z.array(OptionSchema).optional(),
688
+ options: z2.array(OptionSchema).optional(),
557
689
  /** The ask's declared coverage points (#396), when the agent sent them. */
558
- points: z.array(z.string()).optional(),
690
+ points: z2.array(z2.string()).optional(),
559
691
  /** The call's AGENDA (broker/agenda-design.md): the ordered turns it is made of, built at
560
692
  * ring/enqueue time. Replaces the condensed line + index-aligned phrased points, which
561
693
  * between them could not express a call as a sequence. `question: null` is a real turn —
@@ -564,12 +696,12 @@ var InboxItemSchema = z.object({
564
696
  * `requestAsks` — the agent's own declaration, not a guess. `false` is what earns a card
565
697
  * its acknowledge affordance: without it a status update offers a text box and a dismiss,
566
698
  * and neither of those is "got it" (owner, 2026-08-10). */
567
- asks: z.boolean().optional(),
699
+ asks: z2.boolean().optional(),
568
700
  /** When a live process last pulsed for this row's agent — the liveness input for
569
701
  * "working requires a pulse" (#928): the list said "Working…" from agent_state alone
570
702
  * while the party called the same dead claim stalled. Absent = no token/no data,
571
703
  * which must never CLAIM stalled. */
572
- lastSeenAt: z.string().optional(),
704
+ lastSeenAt: z2.string().optional(),
573
705
  /** WHEN THE AGENT LAST SAID ANYTHING ABOUT THIS CLAIM — the newest `agent_state` row in
574
706
  * the `notification_events` ledger (trigger-written since 20260621010000, so every row a
575
707
  * user can see has one). The age input for `CLAIM_STALE_MS`, and it has to be this rather
@@ -579,56 +711,53 @@ var InboxItemSchema = z.object({
579
711
  * work. Reading the row's birth as the claim's age brands that "No update in 8h" the
580
712
  * instant the agent picks it up (#997). Absent = pre-trigger row; fall back to
581
713
  * `createdAt`. */
582
- agentStateAt: z.string().datetime().optional(),
583
- agenda: z.array(AgendaTurnSchema).optional(),
584
- /** On a replied detail (#397): the next steps the user attached to the answer
585
- * ("call back after lunch") — shown so they can see the commitment was captured. */
586
- intents: z.array(IntentSchema).optional(),
587
- visuals: z.array(VisualSchema).optional(),
714
+ agentStateAt: z2.string().datetime().optional(),
715
+ agenda: z2.array(AgendaTurnSchema).optional(),
716
+ visuals: z2.array(VisualSchema).optional(),
588
717
  /** The connected agent's name (the single pairing name — user-typed, or the
589
718
  * agent's suggestion, or a default silly name). */
590
- name: z.string(),
719
+ name: z2.string(),
591
720
  /** The pairing's assigned voice (#462); absent = the default voice. */
592
721
  voice: VoiceKeySchema.optional(),
593
- repo: z.string().optional(),
594
- branch: z.string().optional(),
595
- createdAt: z.string().datetime(),
596
- snoozedUntil: z.string().datetime().optional(),
722
+ repo: z2.string().optional(),
723
+ branch: z2.string().optional(),
724
+ createdAt: z2.string().datetime(),
725
+ snoozedUntil: z2.string().datetime().optional(),
597
726
  agentState: AgentStateSchema.default("idle"),
598
727
  /** Whose action the item is waiting on: "you" = an agent asked you (the default,
599
728
  * every agent→user notification); "agent" = you sent a request and it's awaiting the
600
729
  * agent (held in the inbox until the agent replies on the thread). */
601
- turn: z.enum(["you", "agent"]).default("you"),
730
+ turn: z2.enum(["you", "agent"]).default("you"),
602
731
  /** Hard error reason on an awaiting request (turn="agent") — the wake failed to reach
603
732
  * the agent (provider-agnostic; set server-side). Absent = no hard error, though the
604
733
  * client may still flag a stall by age. Drives the inbox error badge + Retry. */
605
- error: z.string().optional(),
606
- clarifies: z.string().optional(),
734
+ error: z2.string().optional(),
735
+ clarifies: z2.string().optional(),
607
736
  /** The ring ladder ran out while this was still pending — we tried to reach you and
608
737
  * STOPPED trying (`arbitration/arbitrate.ts` `nextRing` → `stop`). Distinct from an
609
738
  * agent with nothing to say, which the roster drew identically until now: "nothing to
610
739
  * say" and "gave up saying it" are opposite situations wearing the same face
611
740
  * (navigation-design.md, gap 1). False for anything that never rang. */
612
- gaveUp: z.boolean().default(false),
741
+ gaveUp: z2.boolean().default(false),
613
742
  /** Why this arrived the way it did, read back off the delivery receipt (`notify/why.ts`).
614
743
  * Absent for anything never delivered through a push, and for older rows written before
615
744
  * the reason was recorded. Deliberately a debug affordance, shown small (owner,
616
745
  * 2026-08-07) — its real job is to give "this didn't need a call" something to be
617
746
  * feedback ABOUT. */
618
- why: z.object({
747
+ why: z2.object({
619
748
  asked: NotifyLevelSchema,
620
749
  got: NotifyLevelSchema,
621
- because: z.enum(["unresponsive", "dismissed", "not_permitted", "silent", "coalesced", "agent_capped", "unplanned", "learned_raise"]).optional(),
622
- line: z.string()
750
+ because: z2.enum(["unresponsive", "dismissed", "not_permitted", "silent", "coalesced", "agent_capped", "unplanned", "learned_raise"]).optional(),
751
+ line: z2.string()
623
752
  }).optional(),
624
- select: z.enum(["one", "many", "rank", "confirm", "text"]).default("one"),
625
- confirmStyle: z.enum(["yesno", "approve"]).default("yesno").describe(
753
+ select: z2.enum(["one", "many", "rank", "confirm", "text"]).default("one"),
754
+ confirmStyle: z2.enum(["yesno", "approve"]).default("yesno").describe(
626
755
  "Labels for a select:'confirm' paige \u2014 'yesno' (Yes/No) or 'approve' (Approve/Deny). Ignored unless select is 'confirm'."
627
756
  ),
628
757
  /** Real downstream work is stuck behind this one — set by the agent, independent of
629
758
  * urgency (see the main README's "premier use case" + notify/states.md). Drives the
630
759
  * inbox's blocking badge and the extra confirm step before dismissing it. */
631
- blocking: z.boolean().default(false),
760
+ blocking: z2.boolean().default(false),
632
761
  /** The user's locked-in answer; present only for replied items (GET /api/replied/:id). */
633
762
  answer: UserAnswerSchema.optional(),
634
763
  /** E2EE (text lane): the sealed content this item carries when the pairing is E2EE, in
@@ -637,39 +766,39 @@ var InboxItemSchema = z.object({
637
766
  * NotifyRequest.envelope. The native app decrypts it locally via openNotification;
638
767
  * web / an un-enrolled device can't and renders a locked placeholder. Absent = today's
639
768
  * plaintext item (context carries the cleartext), so plaintext items are unchanged. */
640
- envelope: z.object({
641
- context: z.lazy(() => EnvelopeSchema).optional(),
642
- options: z.lazy(() => EnvelopeSchema).optional(),
643
- visuals: z.lazy(() => EnvelopeSchema).optional()
769
+ envelope: z2.object({
770
+ context: z2.lazy(() => EnvelopeSchema).optional(),
771
+ options: z2.lazy(() => EnvelopeSchema).optional(),
772
+ visuals: z2.lazy(() => EnvelopeSchema).optional()
644
773
  }).optional(),
645
774
  /** E2EE: the agent's device X25519 public key to seal the user's answer BACK to (the
646
775
  * sender the phone replies to). Sourced server-side from this item's pairing credential.
647
776
  * Present only alongside `envelope`; the phone seals via sealAnswer(answer, this, id). */
648
- agentX25519: z.string().optional()
777
+ agentX25519: z2.string().optional()
649
778
  });
650
- var SnoozeRequestSchema = z.object({
651
- requestId: z.string(),
652
- until: z.string().datetime()
779
+ var SnoozeRequestSchema = z2.object({
780
+ requestId: z2.string(),
781
+ until: z2.string().datetime()
653
782
  });
654
783
  var APNS_TOKEN_RE = /^[0-9a-fA-F]{64}$/;
655
- var PushTokenSchema = z.object({
656
- voipToken: z.string().min(1).optional(),
657
- alertToken: z.string().min(1).optional(),
658
- fcmToken: z.string().min(1).optional(),
659
- platform: z.enum(["ios", "android"])
784
+ var PushTokenSchema = z2.object({
785
+ voipToken: z2.string().min(1).optional(),
786
+ alertToken: z2.string().min(1).optional(),
787
+ fcmToken: z2.string().min(1).optional(),
788
+ platform: z2.enum(["ios", "android"])
660
789
  }).superRefine((v, ctx) => {
661
790
  if (v.platform !== "ios") return;
662
791
  for (const field of ["voipToken", "alertToken"]) {
663
792
  const token = v[field];
664
793
  if (token === void 0 || APNS_TOKEN_RE.test(token)) continue;
665
794
  ctx.addIssue({
666
- code: z.ZodIssueCode.custom,
795
+ code: z2.ZodIssueCode.custom,
667
796
  path: [field],
668
797
  message: `not an APNs device token (want 64 hex chars, got ${token.length})`
669
798
  });
670
799
  }
671
800
  });
672
- var MissedCallSchema = z.enum([
801
+ var MissedCallSchema = z2.enum([
673
802
  "retry_10m",
674
803
  "retry_30m",
675
804
  "retry_60m",
@@ -679,42 +808,32 @@ var MissedCallSchema = z.enum([
679
808
  "inbox",
680
809
  "dismiss"
681
810
  ]);
682
- var MISSED_CALL_PLAN = {
683
- retry_10m: { kind: "every", minutes: 10 },
684
- retry_30m: { kind: "every", minutes: 30 },
685
- retry_60m: { kind: "every", minutes: 60 },
686
- backoff_gentle: { kind: "at", minutes: [30, 120, 360] },
687
- backoff_standard: { kind: "at", minutes: [10, 30, 120] },
688
- backoff_aggressive: { kind: "at", minutes: [5, 15, 45] },
689
- inbox: { kind: "once" },
690
- dismiss: { kind: "grace", minutes: 2 }
691
- };
692
- var BrokerTuningSchema = z.object({
811
+ var BrokerTuningSchema = z2.object({
693
812
  /** 'none' = skip the spoken ack after a mapped answer (power users find it slow). */
694
- ackVerbosity: z.enum(["normal", "none"]).optional(),
813
+ ackVerbosity: z2.enum(["normal", "none"]).optional(),
695
814
  /** How readily the mapper asks its one clarification: 'low' = only when truly
696
815
  * uninterpretable, 'high' = whenever not fully certain. */
697
- clarifyEagerness: z.enum(["low", "normal", "high"]).optional(),
816
+ clarifyEagerness: z2.enum(["low", "normal", "high"]).optional(),
698
817
  /** The user's own shorthand: when they say `say`, they mean `mean`. */
699
- phrasebook: z.array(z.object({ say: z.string().min(1).max(60), mean: z.string().min(1).max(120) })).max(24).optional(),
818
+ phrasebook: z2.array(z2.object({ say: z2.string().min(1).max(60), mean: z2.string().min(1).max(120) })).max(24).optional(),
700
819
  /** The language calls are PLANNED in, when the account has chosen one (#1272). Absent —
701
820
  * which is every account today — means the agent's own words decide, per ask: a call
702
821
  * about an English ask opens in English. This is the only thing that overrides that,
703
822
  * and a live caller who switches language mid-call still outranks it (broker/lang.ts).
704
823
  * Set per user (no UI yet), like `voiceTuning`. */
705
- language: z.enum(["en", "es"]).optional()
824
+ language: z2.enum(["en", "es"]).optional()
706
825
  });
707
- var UserSettingsSchema = z.object({
708
- permissions: z.object({
709
- call: z.boolean(),
710
- banner: z.boolean(),
711
- push: z.boolean()
826
+ var UserSettingsSchema = z2.object({
827
+ permissions: z2.object({
828
+ call: z2.boolean(),
829
+ banner: z2.boolean(),
830
+ push: z2.boolean()
712
831
  }),
713
- sessionMode: z.enum(["default", "all_calls", "silent"]),
714
- silentPush: z.boolean(),
715
- autoCallback: z.boolean(),
832
+ sessionMode: z2.enum(["default", "all_calls", "silent"]),
833
+ silentPush: z2.boolean(),
834
+ autoCallback: z2.boolean(),
716
835
  /** Opt-in (default false) to using your content to improve Paigy and train models. */
717
- improveConsent: z.boolean(),
836
+ improveConsent: z2.boolean(),
718
837
  missedCall: MissedCallSchema.default("backoff_standard"),
719
838
  /** Where voice audio is processed. 'hosted' (default) = Paigy's voice services
720
839
  * (ElevenLabs TTS, faster-whisper STT, the call bot); 'on_device' = the phone
@@ -722,7 +841,7 @@ var UserSettingsSchema = z.object({
722
841
  * Optional, NOT defaulted: a stale client PATCHing the full settings object
723
842
  * must not silently reset this privacy choice. Absent = leave unchanged on
724
843
  * write, 'hosted' on read (see store.ts). */
725
- voiceMode: z.enum(["hosted", "on_device"]).optional(),
844
+ voiceMode: z2.enum(["hosted", "on_device"]).optional(),
726
845
  /** Per-user ring budget (#603): calls per rolling day before further calls
727
846
  * degrade to banner. Absent = the global default (25). A number, never a
728
847
  * bypass — every account keeps a ceiling. No UI; set per user for testing. */
@@ -730,10 +849,10 @@ var UserSettingsSchema = z.object({
730
849
  * payload['tuning'] (e.g. { silence_s: 3.5 } — a longer pause window for a
731
850
  * slower speaker). No API-side semantics; the bot resolves each key with its
732
851
  * own defaults. Set per user (no UI yet); absent = bot defaults. */
733
- voiceTuning: z.record(z.string(), z.union([z.number(), z.string()])).optional(),
852
+ voiceTuning: z2.record(z2.string(), z2.union([z2.number(), z2.string()])).optional(),
734
853
  /** Opt-in to real-phone (PSTN) calls when the app can't ring. Optional, not
735
854
  * defaulted — an older client PATCHing the full object must not clobber it. */
736
- pstnCalls: z.boolean().optional(),
855
+ pstnCalls: z2.boolean().optional(),
737
856
  /** The user's IANA timezone (e.g. "America/Bogota"), recorded by the app — it is the
738
857
  * only party that knows it. REMINDERS are why it exists: "remind me at ten" becomes
739
858
  * an absolute `due_at` only if we know whose ten. Optional and never defaulted, for
@@ -742,50 +861,50 @@ var UserSettingsSchema = z.object({
742
861
  * that failure reads as the reminder rail being unreliable rather than as a missing
743
862
  * setting. Absent = a spoken time can't be landed, so the reminder rides the next
744
863
  * call — honest about what we know. */
745
- timezone: z.string().min(1).max(64).optional(),
864
+ timezone: z2.string().min(1).max(64).optional(),
746
865
  /** Account E2EE state (text lane): 'off' (default) = today's plaintext; 'on' =
747
866
  * content is sealed end-to-end between the local agent and the phone. Like
748
867
  * voiceMode, OPTIONAL and NOT defaulted so a stale client PATCHing the full
749
868
  * settings object without it can't silently flip the account's E2EE state.
750
869
  * Absent = leave unchanged on write, 'off' on read (see store.ts). The demo
751
870
  * account is plaintext by construction and refuses any non-'off' value. */
752
- e2eeMode: z.enum(["off", "on"]).optional(),
871
+ e2eeMode: z2.enum(["off", "on"]).optional(),
753
872
  /** Rung-2 broker tuning (#381). Optional and NOT defaulted, same stale-client
754
873
  * clobber guard as voiceMode: absent = leave unchanged on write. */
755
874
  broker: BrokerTuningSchema.optional()
756
875
  });
757
- var HistoryItemSchema = z.object({
758
- id: z.string(),
759
- parentId: z.string(),
876
+ var HistoryItemSchema = z2.object({
877
+ id: z2.string(),
878
+ parentId: z2.string(),
760
879
  /** 'user' = a request you sent; 'agent' = a notification an agent sent you. */
761
- initiator: z.enum(["user", "agent"]),
762
- title: z.string(),
880
+ initiator: z2.enum(["user", "agent"]),
881
+ title: z2.string(),
763
882
  /** The agent on the other end (its name). */
764
- name: z.string(),
765
- createdAt: z.string(),
883
+ name: z2.string(),
884
+ createdAt: z2.string(),
766
885
  /** When the agent fetched your request (user→agent only). */
767
- agentAckedAt: z.string().nullable(),
886
+ agentAckedAt: z2.string().nullable(),
768
887
  /** When you answered the agent's notification (agent→user only). */
769
- humanAckedAt: z.string().nullable()
888
+ humanAckedAt: z2.string().nullable()
770
889
  });
771
890
  var ACTIVITY_LINES = 2;
772
891
  var ACTIVITY_LINE_MAX = 80;
773
- var AgentActivitySchema = z.object({
892
+ var AgentActivitySchema = z2.object({
774
893
  /** Oldest first, so the newest line is last — the one that replaces in place. */
775
- lines: z.array(z.string().max(ACTIVITY_LINE_MAX)).max(ACTIVITY_LINES),
894
+ lines: z2.array(z2.string().max(ACTIVITY_LINE_MAX)).max(ACTIVITY_LINES),
776
895
  /** When the harness observed this tail. Its own timestamp, not the heartbeat's: a beat
777
896
  * that carries an UNCHANGED tail must not make a stalled agent look like it just moved. */
778
- at: z.string().datetime()
897
+ at: z2.string().datetime()
779
898
  });
780
- var ConnectionSummarySchema = z.object({
899
+ var ConnectionSummarySchema = z2.object({
781
900
  /** The connection = the agent's token id (used to address a request). */
782
- id: z.string(),
783
- device: z.string().nullable(),
901
+ id: z2.string(),
902
+ device: z2.string().nullable(),
784
903
  /** The agent's display name (the single pairing name). */
785
- name: z.string(),
904
+ name: z2.string(),
786
905
  /** For a managed connection, the provider key (e.g. "cma") that agentOrigin maps to a
787
906
  * label; null for a local connection. Sourced from the token's provider, not the name. */
788
- provider: z.string().nullable(),
907
+ provider: z2.string().nullable(),
789
908
  /** The pairing's assigned voice (#462); null = the default voice. */
790
909
  voice: VoiceKeySchema.nullable(),
791
910
  /** The LOUDEST this agent may ever reach you — a ceiling on `NOTIFY_LADDER`, set by the
@@ -796,19 +915,19 @@ var ConnectionSummarySchema = z.object({
796
915
  * every surface at once and outranks even `sessionMode: all_calls` — a mode the user
797
916
  * set once must not overrule a rule they set about one agent. */
798
917
  reach: NotifyLevelSchema.nullable().optional(),
799
- createdAt: z.string().datetime(),
918
+ createdAt: z2.string().datetime(),
800
919
  /** Most recent notification on this connection, either direction. Null = no contact yet.
801
920
  * Drives the agents-page recency grouping (Today / This week / …). */
802
- lastContactAt: z.string().datetime().nullable(),
921
+ lastContactAt: z2.string().datetime().nullable(),
803
922
  /** Last presence heartbeat from a running agent process (POST /api/presence) — the
804
923
  * desktop app while open. Null = never seen; stale = offline. */
805
- lastSeenAt: z.string().datetime().nullable().optional(),
924
+ lastSeenAt: z2.string().datetime().nullable().optional(),
806
925
  /** What a live desktop can run (companion.md §2.2), advertised on its heartbeat:
807
926
  * harness availabilities + granted workspaces — the option set the phone's
808
927
  * "new session" sheet offers. Absent for ordinary MCP agents. */
809
- runtime: z.object({
810
- harnesses: z.array(z.object({ name: z.string(), label: z.string(), status: z.string() })).optional(),
811
- workspaces: z.array(z.string()).optional()
928
+ runtime: z2.object({
929
+ harnesses: z2.array(z2.object({ name: z2.string(), label: z2.string(), status: z2.string() })).optional(),
930
+ workspaces: z2.array(z2.string()).optional()
812
931
  }).optional(),
813
932
  /** The tail of this agent's working log, when a harness is driving it — the agent page's
814
933
  * live strip. Absent for anything the desktop harness isn't running (a hatched identity
@@ -817,98 +936,103 @@ var ConnectionSummarySchema = z.object({
817
936
  activity: AgentActivitySchema.optional(),
818
937
  /** True = a provider-managed agent running in the provider's cloud (e.g. Anthropic CMA);
819
938
  * false = a local MCP connection running on the user's computer (Claude Code/Codex/…). */
820
- managed: z.boolean()
939
+ managed: z2.boolean()
821
940
  });
822
- var MoveRingSchema = z.enum(["home", "travels", "retired", "quarantined"]);
823
- var MoveSchema = z.object({
824
- id: z.string(),
941
+ var MoveRingSchema = z2.enum(["home", "travels", "retired", "quarantined"]);
942
+ var MoveSchema = z2.object({
943
+ id: z2.string(),
825
944
  /** The reusable question, as distill normalized it. */
826
- question: z.string(),
945
+ question: z2.string(),
827
946
  /** The operative ruling. Editable by the user (PATCH) — which resets the ledger. */
828
- answer: z.string(),
947
+ answer: z2.string(),
829
948
  /** The user's stated reason, when they gave one. Null = inherently narrow: the judge is
830
949
  * told so, and the ruling only derives essentially the same question in the same scope. */
831
- rationale: z.string().nullable(),
950
+ rationale: z2.string().nullable(),
832
951
  /** Where the ruling lives: a repo/workspace, or 'global'. */
833
- scope: z.string(),
952
+ scope: z2.string(),
834
953
  ring: MoveRingSchema,
835
954
  /** True = the user pinned it with `always` (travel granted by hand, not by evidence). */
836
- pinned: z.boolean(),
955
+ pinned: z2.boolean(),
837
956
  /** True = a pin the user placed was BROKEN by later counter-evidence. Surfaced so the
838
957
  * break is visible instead of a pin silently disappearing. */
839
- pinBroken: z.boolean(),
958
+ pinBroken: z2.boolean(),
840
959
  /** When the ruling was distilled. */
841
- learnedAt: z.string(),
960
+ learnedAt: z2.string(),
842
961
  /** Last time it answered an ask. Null = never fired. */
843
- lastUsedAt: z.string().nullable(),
962
+ lastUsedAt: z2.string().nullable(),
844
963
  /** How many asks it has answered. Instrumentation — deliberately NOT an input to the
845
964
  * evidence curve: firing says the question keeps arising, not that the ruling is right. */
846
- usedCount: z.number(),
965
+ usedCount: z2.number(),
847
966
  /** Ledger: outcomes that said it held up. Saturating — the tenth is worth almost nothing. */
848
- confirms: z.number(),
967
+ confirms: z2.number(),
849
968
  /** Ledger: contradictions, in signal units (a full override = 1, weaker signals less).
850
969
  * Linear and priced above the entire confirmation budget, so any full counter wins. */
851
- counters: z.number(),
970
+ counters: z2.number(),
852
971
  /** The agent that asked the question this move came from, when known. Null for a move
853
972
  * distilled from a clarify ruling (those carry no agent) or one whose source rows are gone. */
854
- learnedFrom: z.object({ id: z.string(), name: z.string() }).nullable()
973
+ learnedFrom: z2.object({ id: z2.string(), name: z2.string() }).nullable()
855
974
  });
856
- var CreateRequestSchema = z.object({
975
+ var CreateRequestSchema = z2.object({
857
976
  /** The connection (token id) to send to, from GET /api/tokens. */
858
- tokenId: z.string(),
977
+ tokenId: z2.string(),
859
978
  /** The user's message to the agent. */
860
- text: z.string().min(1),
979
+ text: z2.string().min(1),
861
980
  /** Land the request on an existing conversation thread (History → "Continue")
862
981
  * instead of minting a fresh one. Must belong to the requesting user. */
863
- parentId: z.string().optional(),
982
+ parentId: z2.string().optional(),
864
983
  /** Point the agent at a past conversation (possibly with a different agent) as
865
984
  * starting context (History → "New session from this"). A reference, not a copy —
866
985
  * the agent reads it via get_thread. Must belong to the requesting user. */
867
- contextParentId: z.string().optional()
986
+ contextParentId: z2.string().optional()
868
987
  });
869
- var HandoffSchema = z.object({
988
+ var HandoffSchema = z2.object({
989
+ /** Move this existing outcome to `target` without reminting it. Requires `target`. */
990
+ workId: z2.string().uuid().optional(),
870
991
  /** Land the note on an existing thread; omitted mints a fresh one. */
871
- parentId: z.string().uuid().optional(),
992
+ parentId: z2.string().uuid().optional(),
872
993
  /** One-line headline of the working context handed off. */
873
- title: z.string().min(1),
994
+ title: z2.string().min(1),
874
995
  /** The brief — standalone notes the successor reads (what was done, what's left, links). */
875
- notes: z.array(z.string().min(1)).min(1),
996
+ notes: z2.array(z2.string().min(1)).min(1),
876
997
  /** A sibling connection to dispatch directly to (token id or agent nickname). Same-account
877
998
  * only; omit to leave the thread for the user to hand off in the app. */
878
- target: z.string().optional(),
999
+ target: z2.string().optional(),
879
1000
  /** Write the note as a RECAP (kind:'recap', #617): a summary turn that supersedes the
880
1001
  * thread's earlier turns for rehydration — get_thread returns the latest recap + only
881
1002
  * the turns after it. Handoff-to-a-successor and handoff-to-yourself-later are the
882
1003
  * same primitive; a recap is one whose audience includes you. */
883
- recap: z.boolean().optional()
1004
+ recap: z2.boolean().optional()
1005
+ }).refine((value) => !value.workId || Boolean(value.target), {
1006
+ message: "target is required when handing off Work",
1007
+ path: ["target"]
884
1008
  });
885
- var NoteSourceSchema = z.enum(["app", "call"]);
886
- var NoteStatusSchema = z.enum(["open", "assigned", "in_progress", "done"]);
887
- var NoteRepeatSchema = z.enum(["once", "until_done"]);
888
- var DecisionSchema = z.object({
889
- id: z.string(),
1009
+ var NoteSourceSchema = z2.enum(["app", "call"]);
1010
+ var NoteStatusSchema = z2.enum(["open", "assigned", "in_progress", "done"]);
1011
+ var NoteRepeatSchema = z2.enum(["once", "until_done"]);
1012
+ var DecisionSchema = z2.object({
1013
+ id: z2.string(),
890
1014
  /** The note this decision refines; null = recorded on a bare thread (the
891
1015
  * extensibility seam — any conversation can accrue decisions). */
892
- noteId: z.string().nullable(),
1016
+ noteId: z2.string().nullable(),
893
1017
  /** What was ambiguous — the broker's (or the user's own) question. */
894
- question: z.string(),
1018
+ question: z2.string(),
895
1019
  /** The user's ruling; null while the question is open. */
896
- answer: z.string().nullable(),
897
- decidedAt: z.string().nullable(),
898
- createdAt: z.string()
1020
+ answer: z2.string().nullable(),
1021
+ decidedAt: z2.string().nullable(),
1022
+ createdAt: z2.string()
899
1023
  });
900
- var NoteSchema = z.object({
901
- id: z.string(),
1024
+ var NoteSchema = z2.object({
1025
+ id: z2.string(),
902
1026
  /** One-line headline (broker-titled; deterministic floor). */
903
- title: z.string(),
1027
+ title: z2.string(),
904
1028
  /** The original intent, verbatim — assignees always see the user's own words. */
905
- intent: z.string(),
1029
+ intent: z2.string(),
906
1030
  source: NoteSourceSchema,
907
1031
  status: NoteStatusSchema,
908
1032
  /** Who it was assigned to (a participant ref, 'agent:<tokenId>'); null = unassigned. */
909
- assignee: z.string().nullable(),
1033
+ assignee: z2.string().nullable(),
910
1034
  /** The request thread minted at assignment; null until assigned. */
911
- parentId: z.string().nullable(),
1035
+ parentId: z2.string().nullable(),
912
1036
  /** REMINDERS (reminders-design.md): the NOT-BEFORE this becomes eligible to ride a
913
1037
  * call — never a deadline. It only ever comes from the user's own words, so when it
914
1038
  * passes Paigy rings ONCE (#1293, owner 2026-08-26: a time said out loud is consent to
@@ -917,202 +1041,202 @@ var NoteSchema = z.object({
917
1041
  // Defaulted, not required: a Note from an API deploy older than the reminders
918
1042
  // migration has none of these, and the defaults ARE what it means — no not-before,
919
1043
  // one ride, never ridden. Parsing must not fail across a rolling deploy.
920
- dueAt: z.string().nullable().default(null),
1044
+ dueAt: z2.string().nullable().default(null),
921
1045
  repeat: NoteRepeatSchema.default("once"),
922
1046
  /** How many calls have already carried it — the fatigue cap counts rides, not days. */
923
- rides: z.number().int().default(0),
924
- lastRideAt: z.string().nullable().default(null),
925
- createdAt: z.string()
1047
+ rides: z2.number().int().default(0),
1048
+ lastRideAt: z2.string().nullable().default(null),
1049
+ createdAt: z2.string()
926
1050
  });
927
- var CreateNoteSchema = z.object({
1051
+ var CreateNoteSchema = z2.object({
928
1052
  /** The intent, in the user's own words. Stored verbatim; the broker only titles it. */
929
- text: z.string().min(1).max(4e3),
1053
+ text: z2.string().min(1).max(4e3),
930
1054
  /** Capture it as a REMINDER — a note assigned to the user themselves, which rides
931
1055
  * their next call instead of being handed to an agent. Everything else about the
932
1056
  * note is identical; this is the one parameter that separates the two. */
933
- forMe: z.boolean().optional(),
1057
+ forMe: z2.boolean().optional(),
934
1058
  /** The not-before, when the user already said one. Absent = the very next call. */
935
- dueAt: z.string().datetime().optional(),
1059
+ dueAt: z2.string().datetime().optional(),
936
1060
  repeat: NoteRepeatSchema.optional()
937
1061
  });
938
- var RecordDecisionSchema = z.object({
1062
+ var RecordDecisionSchema = z2.object({
939
1063
  /** An open decision (from /clarify) to answer. */
940
- decisionId: z.string().optional(),
1064
+ decisionId: z2.string().optional(),
941
1065
  /** For an ad-hoc decision: what was ambiguous. Required without `decisionId`. */
942
- question: z.string().min(1).max(500).optional(),
1066
+ question: z2.string().min(1).max(500).optional(),
943
1067
  /** The ruling. */
944
- answer: z.string().min(1).max(2e3)
1068
+ answer: z2.string().min(1).max(2e3)
945
1069
  }).refine((d) => d.decisionId || d.question, { message: "decisionId or question required" });
946
- var AssignNoteSchema = z.object({
1070
+ var AssignNoteSchema = z2.object({
947
1071
  /** An EXISTING agent: token id or nickname. Omit when spawning fresh. */
948
- target: z.string().min(1).optional(),
1072
+ target: z2.string().min(1).optional(),
949
1073
  /** Spawn a NEW session for this note (companion.md §2.2): the assignee doesn't
950
1074
  * exist yet — mint it on a live desktop that advertises the harness+workspace,
951
1075
  * named after the note. The brief arrives as its opening request. */
952
- spawn: z.object({
953
- hostTokenId: z.string().uuid(),
954
- harness: z.string().min(1),
955
- workspace: z.string().min(1)
1076
+ spawn: z2.object({
1077
+ hostTokenId: z2.string().uuid(),
1078
+ harness: z2.string().min(1),
1079
+ workspace: z2.string().min(1)
956
1080
  }).optional()
957
1081
  }).refine((a) => !!a.target !== !!a.spawn, { message: "exactly one of target or spawn" });
958
- var TriageVerdictSchema = z.enum(["keep", "stale", "close", "assign"]);
959
- var TriageItemSchema = z.object({
960
- noteId: z.string(),
1082
+ var TriageVerdictSchema = z2.enum(["keep", "stale", "close", "assign"]);
1083
+ var TriageItemSchema = z2.object({
1084
+ noteId: z2.string(),
961
1085
  /** The note's headline at run time. */
962
- title: z.string(),
1086
+ title: z2.string(),
963
1087
  /** WHY, in one short human line, evidence first — this is read on a phone underneath
964
1088
  * the note's title: "no movement in 34 days", "worked 3 notes in this repo this week".
965
1089
  * Never a model's reasoning transcript, never an id. */
966
- why: z.string()
1090
+ why: z2.string()
967
1091
  });
968
- var TriageAssignmentSchema = z.object({
1092
+ var TriageAssignmentSchema = z2.object({
969
1093
  /** The agent's token id — what `dispatchNote` resolves and what a request is addressed to. */
970
- agent: z.string(),
1094
+ agent: z2.string(),
971
1095
  /** Its display name at run time (the name on the hatchling's card). Denormalized for the
972
1096
  * same reason as `title`: the card must render from the proposal alone. */
973
- agentName: z.string(),
974
- notes: z.array(TriageItemSchema)
1097
+ agentName: z2.string(),
1098
+ notes: z2.array(TriageItemSchema)
975
1099
  });
976
- var TriageStatusSchema = z.enum(["open", "superseded", "dismissed"]);
977
- var SubmitTriageSchema = z.object({
1100
+ var TriageStatusSchema = z2.enum(["open", "superseded", "dismissed"]);
1101
+ var SubmitTriageSchema = z2.object({
978
1102
  /** Which runtime judged: "ollama" (inference never left the machine) or a harness the
979
1103
  * user already runs under their own credentials ("claude" / "codex" / "agy"). Recorded
980
1104
  * so the phone can say where the content went — an unattributed privacy claim is worth
981
1105
  * nothing, and #1106's promise is precisely "Paigy's servers never see this". */
982
- provider: z.string().min(1).max(60),
1106
+ provider: z2.string().min(1).max(60),
983
1107
  /** The concrete model when the provider names one (an ollama tag); null otherwise. */
984
- model: z.string().max(200).nullable().optional(),
1108
+ model: z2.string().max(200).nullable().optional(),
985
1109
  /** How many open notes the run actually looked at — the denominator on the phone
986
1110
  * ("6 of 50"), and the honest answer to "did it read the whole queue?". */
987
- reviewed: z.number().int().min(0).max(1e4).default(0),
988
- close: z.array(TriageItemSchema).max(200).default([]),
989
- stale: z.array(TriageItemSchema).max(200).default([]),
990
- assign: z.array(TriageAssignmentSchema).max(50).default([])
1111
+ reviewed: z2.number().int().min(0).max(1e4).default(0),
1112
+ close: z2.array(TriageItemSchema).max(200).default([]),
1113
+ stale: z2.array(TriageItemSchema).max(200).default([]),
1114
+ assign: z2.array(TriageAssignmentSchema).max(50).default([])
991
1115
  });
992
1116
  var TriageProposalSchema = SubmitTriageSchema.extend({
993
- id: z.string(),
994
- runAt: z.string(),
1117
+ id: z2.string(),
1118
+ runAt: z2.string(),
995
1119
  status: TriageStatusSchema,
996
- model: z.string().nullable().default(null)
1120
+ model: z2.string().nullable().default(null)
997
1121
  });
998
- var AcceptTriageSchema = z.discriminatedUnion("group", [
999
- z.object({ group: z.literal("close"), noteIds: z.array(z.string()).max(200).optional() }),
1000
- z.object({ group: z.literal("stale"), noteIds: z.array(z.string()).max(200).optional() }),
1001
- z.object({
1002
- group: z.literal("assign"),
1003
- agent: z.string().min(1),
1004
- noteIds: z.array(z.string()).max(200).optional()
1122
+ var AcceptTriageSchema = z2.discriminatedUnion("group", [
1123
+ z2.object({ group: z2.literal("close"), noteIds: z2.array(z2.string()).max(200).optional() }),
1124
+ z2.object({ group: z2.literal("stale"), noteIds: z2.array(z2.string()).max(200).optional() }),
1125
+ z2.object({
1126
+ group: z2.literal("assign"),
1127
+ agent: z2.string().min(1),
1128
+ noteIds: z2.array(z2.string()).max(200).optional()
1005
1129
  })
1006
1130
  ]);
1007
- var AcceptTriageResultSchema = z.object({
1008
- accepted: z.array(z.string()),
1009
- failed: z.array(z.object({ noteId: z.string(), reason: z.string() }))
1131
+ var AcceptTriageResultSchema = z2.object({
1132
+ accepted: z2.array(z2.string()),
1133
+ failed: z2.array(z2.object({ noteId: z2.string(), reason: z2.string() }))
1010
1134
  });
1011
- var DeliveryModeSchema = z.enum(["poll", "self_hosted"]);
1135
+ var DeliveryModeSchema = z2.enum(["poll", "self_hosted"]);
1012
1136
  var WAKE_EVENT = "wake";
1013
1137
  var wakeChannel = (tokenId) => `wake:${tokenId}`;
1014
- var RegisterDeliverySchema = z.object({ mode: DeliveryModeSchema });
1015
- var OAuthStartSchema = z.object({
1016
- provider: z.enum(["cma"]),
1017
- returnTo: z.string().min(1)
1138
+ var RegisterDeliverySchema = z2.object({ mode: DeliveryModeSchema });
1139
+ var OAuthStartSchema = z2.object({
1140
+ provider: z2.enum(["cma"]),
1141
+ returnTo: z2.string().min(1)
1018
1142
  });
1019
- var DeliveryConfigSchema = z.object({
1020
- tokenId: z.string(),
1143
+ var DeliveryConfigSchema = z2.object({
1144
+ tokenId: z2.string(),
1021
1145
  mode: DeliveryModeSchema,
1022
1146
  /** null when the server has no SUPABASE_ANON_KEY set — the listener then falls
1023
1147
  * back to its own PAIGY_SUPABASE_URL / PAIGY_SUPABASE_ANON_KEY env. */
1024
- realtime: z.object({ url: z.string(), anonKey: z.string() }).nullable()
1148
+ realtime: z2.object({ url: z2.string(), anonKey: z2.string() }).nullable()
1025
1149
  });
1026
- var StatusSchema = z.object({
1027
- name: z.string(),
1028
- sessionMode: z.enum(["default", "all_calls", "silent"]),
1150
+ var StatusSchema = z2.object({
1151
+ name: z2.string(),
1152
+ sessionMode: z2.enum(["default", "all_calls", "silent"]),
1029
1153
  /** A phone is registered for push/ring (any push token on the account). */
1030
- phone: z.boolean()
1154
+ phone: z2.boolean()
1031
1155
  });
1032
- var EnvelopeRecipientSchema = z.object({
1033
- keyId: z.string(),
1034
- epk: z.string(),
1035
- wnonce: z.string(),
1036
- wrap: z.string()
1156
+ var EnvelopeRecipientSchema = z2.object({
1157
+ keyId: z2.string(),
1158
+ epk: z2.string(),
1159
+ wnonce: z2.string(),
1160
+ wrap: z2.string()
1037
1161
  });
1038
- var EnvelopeHeaderSchema = z.object({
1039
- field: z.enum(["context", "options", "visuals", "answer"]),
1040
- kind: z.string(),
1041
- senderRole: z.enum(["agent", "user"]),
1042
- recipientKeyIds: z.array(z.string()),
1043
- seq: z.number().int().nonnegative()
1162
+ var EnvelopeHeaderSchema = z2.object({
1163
+ field: z2.enum(["context", "options", "visuals", "answer"]),
1164
+ kind: z2.string(),
1165
+ senderRole: z2.enum(["agent", "user"]),
1166
+ recipientKeyIds: z2.array(z2.string()),
1167
+ seq: z2.number().int().nonnegative()
1044
1168
  });
1045
- var EnvelopeSchema = z.object({
1046
- v: z.literal(1),
1047
- alg: z.literal("x25519-xsalsa20poly1305"),
1048
- msgId: z.string(),
1169
+ var EnvelopeSchema = z2.object({
1170
+ v: z2.literal(1),
1171
+ alg: z2.literal("x25519-xsalsa20poly1305"),
1172
+ msgId: z2.string(),
1049
1173
  hdr: EnvelopeHeaderSchema,
1050
- recipients: z.array(EnvelopeRecipientSchema).min(1),
1051
- nonce: z.string(),
1052
- ct: z.string()
1174
+ recipients: z2.array(EnvelopeRecipientSchema).min(1),
1175
+ nonce: z2.string(),
1176
+ ct: z2.string()
1053
1177
  });
1054
- var SealedAnswerSchema = z.object({
1055
- ignored: z.boolean(),
1178
+ var SealedAnswerSchema = z2.object({
1179
+ ignored: z2.boolean(),
1056
1180
  envelope: EnvelopeSchema
1057
1181
  });
1058
- var DeviceCredentialSchema = z.object({
1059
- deviceId: z.string(),
1060
- kind: z.enum(["phone", "web", "agent"]),
1061
- x25519Pub: z.string(),
1062
- ed25519Pub: z.string(),
1063
- sig: z.string()
1182
+ var DeviceCredentialSchema = z2.object({
1183
+ deviceId: z2.string(),
1184
+ kind: z2.enum(["phone", "web", "agent"]),
1185
+ x25519Pub: z2.string(),
1186
+ ed25519Pub: z2.string(),
1187
+ sig: z2.string()
1064
1188
  });
1065
- var DeviceRosterSchema = z.object({
1066
- uikPub: z.string(),
1067
- devices: z.array(DeviceCredentialSchema)
1189
+ var DeviceRosterSchema = z2.object({
1190
+ uikPub: z2.string(),
1191
+ devices: z2.array(DeviceCredentialSchema)
1068
1192
  });
1069
- var WakeNudgeSchema = z.object({
1070
- kind: z.enum(["reply", "request", "callback"]),
1071
- notificationId: z.string().optional(),
1072
- parentId: z.string()
1193
+ var WakeNudgeSchema = z2.object({
1194
+ kind: z2.enum(["reply", "request", "callback"]),
1195
+ notificationId: z2.string().optional(),
1196
+ parentId: z2.string()
1073
1197
  });
1074
- var PairingStatusSchema = z.enum(["pending", "approved", "denied", "expired"]);
1075
- var PairingRevealSchema = z.object({
1076
- x25519: z.string(),
1077
- ed25519: z.string(),
1078
- nonce: z.string()
1198
+ var PairingStatusSchema = z2.enum(["pending", "approved", "denied", "expired"]);
1199
+ var PairingRevealSchema = z2.object({
1200
+ x25519: z2.string(),
1201
+ ed25519: z2.string(),
1202
+ nonce: z2.string()
1079
1203
  });
1080
- var DeviceCodeRequestSchema = z.object({
1204
+ var DeviceCodeRequestSchema = z2.object({
1081
1205
  /** The agent's suggested name for the pairing — the human sees it pre-filled at
1082
1206
  * approval and can override. Optional; blank → a default silly name server-side. */
1083
- suggestedName: z.string().optional(),
1207
+ suggestedName: z2.string().optional(),
1084
1208
  /** Legacy alias for suggestedName (older MCPs sent `agent`). Accepted for
1085
1209
  * back-compat; `suggestedName` wins when both are present. ponytail: drop once no
1086
1210
  * pre-`name` MCP is in the wild. */
1087
- agent: z.union([z.string(), z.object({ name: z.string().optional() })]).optional(),
1088
- device: z.string().optional(),
1089
- proto: z.string().optional(),
1211
+ agent: z2.union([z2.string(), z2.object({ name: z2.string().optional() })]).optional(),
1212
+ device: z2.string().optional(),
1213
+ proto: z2.string().optional(),
1090
1214
  // compiled-in tag, e.g. "paigy-pair-v2|sas=24"
1091
- commitment: z.string().optional()
1215
+ commitment: z2.string().optional()
1092
1216
  // agent's Ca
1093
1217
  });
1094
- var DeviceCodeSchema = z.object({
1095
- device_code: z.string(),
1096
- user_code: z.string(),
1097
- verification_uri: z.string().url(),
1098
- verification_uri_complete: z.string().url(),
1099
- interval: z.number(),
1100
- expires_in: z.number()
1218
+ var DeviceCodeSchema = z2.object({
1219
+ device_code: z2.string(),
1220
+ user_code: z2.string(),
1221
+ verification_uri: z2.string().url(),
1222
+ verification_uri_complete: z2.string().url(),
1223
+ interval: z2.number(),
1224
+ expires_in: z2.number()
1101
1225
  });
1102
- var DeviceInfoSchema = z.object({
1103
- code: z.string(),
1226
+ var DeviceInfoSchema = z2.object({
1227
+ code: z2.string(),
1104
1228
  /** The agent's suggested name (from /device/code) — shown on the approval screen,
1105
1229
  * pre-filling the name field the human can edit. */
1106
- name: z.string(),
1230
+ name: z2.string(),
1107
1231
  /** @deprecated Legacy alias of `name` for the pre-#531 embedded bundle in App Store
1108
1232
  * build 35, whose DeviceFlow renders `info.agent.slice(0, 2)` — without this a FRESH
1109
1233
  * install crashes on the pairing screen on first launch, before the OTA lands
1110
1234
  * (seen live: PAIGY-5T, 2026-07-21). Remove once a newer binary is the floor. */
1111
- agent: z.string().optional(),
1112
- device: z.string().nullable(),
1235
+ agent: z2.string().optional(),
1236
+ device: z2.string().nullable(),
1113
1237
  status: PairingStatusSchema,
1114
- proto: z.string().nullable().optional(),
1115
- agent_commitment: z.string().nullable().optional(),
1238
+ proto: z2.string().nullable().optional(),
1239
+ agent_commitment: z2.string().nullable().optional(),
1116
1240
  // Ca
1117
1241
  agent_reveal: PairingRevealSchema.nullable().optional(),
1118
1242
  // present once the agent reveals
@@ -1122,48 +1246,48 @@ var DeviceInfoSchema = z.object({
1122
1246
  // withheld until e2ee=true) can compute the SAS WITHOUT a token. Public keys — same safety
1123
1247
  // class as agent_reveal above. Present only once the phone reveals; null otherwise.
1124
1248
  phone_reveal: PairingRevealSchema.nullable().optional(),
1125
- uik_pub: z.string().nullable().optional()
1249
+ uik_pub: z2.string().nullable().optional()
1126
1250
  });
1127
- var DeviceTokenRequestSchema = z.object({
1128
- device_code: z.string(),
1251
+ var DeviceTokenRequestSchema = z2.object({
1252
+ device_code: z2.string(),
1129
1253
  reveal: PairingRevealSchema.optional()
1130
1254
  // agent's reveal {x25519, ed25519, nonce}
1131
1255
  });
1132
- var DeviceTokenSchema = z.object({
1133
- access_token: z.string(),
1256
+ var DeviceTokenSchema = z2.object({
1257
+ access_token: z2.string(),
1134
1258
  /** The pairing's single name (user-typed at approval, the agent's suggestion, or
1135
1259
  * a default silly name). */
1136
- name: z.string(),
1137
- device: z.string().nullable(),
1260
+ name: z2.string(),
1261
+ device: z2.string().nullable(),
1138
1262
  /** The pairing's assigned voice, cached so the desktop can seed the SAME face the phone
1139
1263
  * draws — voice is the third ingredient of a hatchling's build (party/traits.ts). */
1140
- voice: z.string().nullable().optional(),
1264
+ voice: z2.string().nullable().optional(),
1141
1265
  /** The token's server-side id — the face's COLOUR anchor, and the only seed ingredient
1142
1266
  * that survives a rename. Cached by the host's identity beat. */
1143
- token_id: z.string().nullable().optional(),
1267
+ token_id: z2.string().nullable().optional(),
1144
1268
  /** WHERE this identity works — the folder a wake should land it in. Written by the host
1145
1269
  * at spawn and by `paigy-harness handoff` from a live terminal. Without it every wake
1146
1270
  * landed in the FIRST granted workspace and the agent rediscovered its own repo from
1147
1271
  * the thread each time (host.ts, live catch 2026-08-06 — prompt-papered until now). */
1148
- workspace: z.string().nullable().optional(),
1272
+ workspace: z2.string().nullable().optional(),
1149
1273
  phone_reveal: PairingRevealSchema.nullable().optional(),
1150
1274
  // present once the phone reveals
1151
- uik_pub: z.string().nullable().optional()
1275
+ uik_pub: z2.string().nullable().optional()
1152
1276
  });
1153
- var DeviceCommitRequestSchema = z.object({
1154
- code: z.string(),
1155
- commitment: z.string()
1277
+ var DeviceCommitRequestSchema = z2.object({
1278
+ code: z2.string(),
1279
+ commitment: z2.string()
1156
1280
  // Cb
1157
1281
  });
1158
- var DevicePeerCommitSchema = z.object({
1159
- commitment: z.string().nullable()
1282
+ var DevicePeerCommitSchema = z2.object({
1283
+ commitment: z2.string().nullable()
1160
1284
  });
1161
- var SupportRequestSchema = z.object({
1162
- email: z.string().email().max(320),
1163
- message: z.string().trim().min(1).max(5e3),
1164
- name: z.string().trim().max(120).optional()
1285
+ var SupportRequestSchema = z2.object({
1286
+ email: z2.string().email().max(320),
1287
+ message: z2.string().trim().min(1).max(5e3),
1288
+ name: z2.string().trim().max(120).optional()
1165
1289
  });
1166
- var NotificationFeedbackKindSchema = z.enum([
1290
+ var NotificationFeedbackKindSchema = z2.enum([
1167
1291
  "break_down",
1168
1292
  // "This should be more than one ask — break it down."
1169
1293
  "regenerate_options",
@@ -1177,26 +1301,46 @@ var NotificationFeedbackKindSchema = z.enum([
1177
1301
  "other"
1178
1302
  // anything else — the note carries it.
1179
1303
  ]);
1180
- var NotificationFeedbackSchema = z.object({
1181
- notificationId: z.string(),
1304
+ var NotificationFeedbackSchema = z2.object({
1305
+ notificationId: z2.string(),
1182
1306
  kind: NotificationFeedbackKindSchema,
1183
1307
  /** Optional free-text elaboration for a preset; required (non-empty) for 'other'. */
1184
- note: z.string().trim().max(2e3).optional()
1308
+ note: z2.string().trim().max(2e3).optional()
1185
1309
  }).superRefine((r, ctx) => {
1186
1310
  if (r.kind === "other" && !r.note)
1187
- ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["note"], message: "note is required for 'other' feedback" });
1311
+ ctx.addIssue({ code: z2.ZodIssueCode.custom, path: ["note"], message: "note is required for 'other' feedback" });
1188
1312
  });
1189
- var FeedbackResolutionSchema = z.enum(["broker_fixed", "sent_to_agent"]);
1190
- var FeedbackOutcomeSchema = z.object({
1313
+ var FeedbackResolutionSchema = z2.enum(["broker_fixed", "sent_to_agent"]);
1314
+ var FeedbackOutcomeSchema = z2.object({
1191
1315
  resolution: FeedbackResolutionSchema,
1192
1316
  transform: TransformSchema,
1193
- message: z.string(),
1194
- childIds: z.array(z.string()).optional()
1317
+ message: z2.string(),
1318
+ childIds: z2.array(z2.string()).optional()
1319
+ });
1320
+ var CONTACT_SCHEMA = contactSchemaFrom({
1321
+ ask: NotifyRequestFields.shape.ask,
1322
+ waiting: NotifyRequestFields.shape.waiting,
1323
+ options: NotifyRequestFields.shape.options,
1324
+ channel: NotifyRequestFields.shape.channel,
1325
+ parentId: NotifyRequestFields.shape.parentId,
1326
+ workId: NotifyRequestFields.shape.workId
1195
1327
  });
1196
1328
 
1197
1329
  export {
1198
- MISSED_CALL_PLAN,
1330
+ mcpInputSchema,
1331
+ CreateGoalSchema,
1332
+ CREATE_GOAL_DESCRIPTION,
1333
+ CONTACT_DESCRIPTION,
1334
+ CHECK_REPLIES_DESCRIPTION,
1335
+ SCHEDULE_CALLBACK_DESCRIPTION,
1336
+ SEARCH_THREADS_DESCRIPTION,
1337
+ SET_WORK_STATE_DESCRIPTION,
1338
+ serverInstructions,
1339
+ SetTaskStateSchema,
1340
+ SetWorkStateSchema,
1341
+ ScheduleCallbackSchema,
1199
1342
  HandoffSchema,
1200
1343
  WAKE_EVENT,
1201
- wakeChannel
1344
+ wakeChannel,
1345
+ CONTACT_SCHEMA
1202
1346
  };