@intentic/sandbox-contract 1.432.0 → 1.433.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/README.md +15 -0
  2. package/dist/contracts/agent.contract.d.ts +252 -72
  3. package/dist/contracts/agent.contract.d.ts.map +1 -1
  4. package/dist/contracts/agents.contract.d.ts +67 -0
  5. package/dist/contracts/agents.contract.d.ts.map +1 -1
  6. package/dist/contracts/approvals.contract.d.ts +35 -0
  7. package/dist/contracts/approvals.contract.d.ts.map +1 -1
  8. package/dist/contracts/approvals.contract.js +13 -3
  9. package/dist/contracts/approvals.contract.js.map +1 -1
  10. package/dist/contracts/automations.contract.d.ts +1 -0
  11. package/dist/contracts/automations.contract.d.ts.map +1 -1
  12. package/dist/contracts/capabilities.contract.d.ts +3 -0
  13. package/dist/contracts/capabilities.contract.d.ts.map +1 -1
  14. package/dist/contracts/extensions.contract.d.ts +4 -0
  15. package/dist/contracts/extensions.contract.d.ts.map +1 -1
  16. package/dist/contracts/needs.contract.d.ts +198 -0
  17. package/dist/contracts/needs.contract.d.ts.map +1 -1
  18. package/dist/contracts/runner.contract.d.ts +156 -36
  19. package/dist/contracts/runner.contract.d.ts.map +1 -1
  20. package/dist/contracts/seal.contract.d.ts +5 -0
  21. package/dist/contracts/seal.contract.d.ts.map +1 -1
  22. package/dist/contracts/sessions.contract.d.ts +22 -0
  23. package/dist/contracts/sessions.contract.d.ts.map +1 -1
  24. package/dist/contracts/settings.contract.d.ts +16 -0
  25. package/dist/contracts/settings.contract.d.ts.map +1 -1
  26. package/dist/contracts/stack-grants.contract.d.ts +22 -0
  27. package/dist/contracts/stack-grants.contract.d.ts.map +1 -1
  28. package/dist/contracts/system.contract.d.ts +7 -4
  29. package/dist/contracts/system.contract.d.ts.map +1 -1
  30. package/dist/events/agent-events.d.ts +88 -0
  31. package/dist/events/agent-events.d.ts.map +1 -1
  32. package/dist/events/agent-transcript.d.ts +22 -0
  33. package/dist/events/agent-transcript.d.ts.map +1 -1
  34. package/dist/events/system-events.d.ts +4 -0
  35. package/dist/events/system-events.d.ts.map +1 -1
  36. package/dist/events/transcript.d.ts +110 -0
  37. package/dist/events/transcript.d.ts.map +1 -1
  38. package/dist/ids/conversation-ids.d.ts.map +1 -1
  39. package/dist/ids/conversation-ids.js.map +1 -1
  40. package/dist/protocol/raw/extension-protocol.d.ts +116 -0
  41. package/dist/protocol/raw/extension-protocol.d.ts.map +1 -1
  42. package/dist/protocol/raw/extension-protocol.js +17 -1
  43. package/dist/protocol/raw/extension-protocol.js.map +1 -1
  44. package/dist/protocol/raw/raw-json-routes.d.ts +2974 -0
  45. package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
  46. package/dist/protocol/raw/raw-json-routes.js +39 -0
  47. package/dist/protocol/raw/raw-json-routes.js.map +1 -1
  48. package/dist/protocol/raw/raw-routes.d.ts +179 -0
  49. package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
  50. package/dist/protocol/raw/raw-routes.js +41 -0
  51. package/dist/protocol/raw/raw-routes.js.map +1 -1
  52. package/dist/protocol/s2s/address.d.ts +53 -0
  53. package/dist/protocol/s2s/address.d.ts.map +1 -0
  54. package/dist/protocol/s2s/address.js +111 -0
  55. package/dist/protocol/s2s/address.js.map +1 -0
  56. package/dist/protocol/s2s/attestation.d.ts +41 -0
  57. package/dist/protocol/s2s/attestation.d.ts.map +1 -0
  58. package/dist/protocol/s2s/attestation.js +96 -0
  59. package/dist/protocol/s2s/attestation.js.map +1 -0
  60. package/dist/protocol/s2s/canonical.d.ts +10 -0
  61. package/dist/protocol/s2s/canonical.d.ts.map +1 -0
  62. package/dist/protocol/s2s/canonical.js +94 -0
  63. package/dist/protocol/s2s/canonical.js.map +1 -0
  64. package/dist/protocol/s2s/envelope.d.ts +40 -0
  65. package/dist/protocol/s2s/envelope.d.ts.map +1 -0
  66. package/dist/protocol/s2s/envelope.js +116 -0
  67. package/dist/protocol/s2s/envelope.js.map +1 -0
  68. package/dist/protocol/s2s/extension-sign.d.ts +21 -0
  69. package/dist/protocol/s2s/extension-sign.d.ts.map +1 -0
  70. package/dist/protocol/s2s/extension-sign.js +41 -0
  71. package/dist/protocol/s2s/extension-sign.js.map +1 -0
  72. package/dist/protocol/s2s/identity-doc.d.ts +50 -0
  73. package/dist/protocol/s2s/identity-doc.d.ts.map +1 -0
  74. package/dist/protocol/s2s/identity-doc.js +89 -0
  75. package/dist/protocol/s2s/identity-doc.js.map +1 -0
  76. package/dist/protocol/s2s/index.d.ts +12 -0
  77. package/dist/protocol/s2s/index.d.ts.map +1 -0
  78. package/dist/protocol/s2s/index.js +12 -0
  79. package/dist/protocol/s2s/index.js.map +1 -0
  80. package/dist/protocol/s2s/kem.d.ts +15 -0
  81. package/dist/protocol/s2s/kem.d.ts.map +1 -0
  82. package/dist/protocol/s2s/kem.js +34 -0
  83. package/dist/protocol/s2s/kem.js.map +1 -0
  84. package/dist/protocol/s2s/keys.d.ts +34 -0
  85. package/dist/protocol/s2s/keys.d.ts.map +1 -0
  86. package/dist/protocol/s2s/keys.js +81 -0
  87. package/dist/protocol/s2s/keys.js.map +1 -0
  88. package/dist/protocol/s2s/passkey-cosign.d.ts +44 -0
  89. package/dist/protocol/s2s/passkey-cosign.d.ts.map +1 -0
  90. package/dist/protocol/s2s/passkey-cosign.js +139 -0
  91. package/dist/protocol/s2s/passkey-cosign.js.map +1 -0
  92. package/dist/protocol/s2s/session.d.ts +61 -0
  93. package/dist/protocol/s2s/session.d.ts.map +1 -0
  94. package/dist/protocol/s2s/session.js +98 -0
  95. package/dist/protocol/s2s/session.js.map +1 -0
  96. package/dist/protocol/s2s/sign.d.ts +12 -0
  97. package/dist/protocol/s2s/sign.d.ts.map +1 -0
  98. package/dist/protocol/s2s/sign.js +33 -0
  99. package/dist/protocol/s2s/sign.js.map +1 -0
  100. package/dist/schemas/agents-list.d.ts +2 -0
  101. package/dist/schemas/agents-list.d.ts.map +1 -1
  102. package/dist/schemas/agents.d.ts +4 -0
  103. package/dist/schemas/agents.d.ts.map +1 -1
  104. package/dist/schemas/approvals.d.ts +100 -0
  105. package/dist/schemas/approvals.d.ts.map +1 -1
  106. package/dist/schemas/approvals.js +21 -0
  107. package/dist/schemas/approvals.js.map +1 -1
  108. package/dist/schemas/automations.d.ts +2 -0
  109. package/dist/schemas/automations.d.ts.map +1 -1
  110. package/dist/schemas/automations.js +1 -1
  111. package/dist/schemas/automations.js.map +1 -1
  112. package/dist/schemas/capabilities.d.ts +1 -0
  113. package/dist/schemas/capabilities.d.ts.map +1 -1
  114. package/dist/schemas/command-admission.d.ts +6 -0
  115. package/dist/schemas/command-admission.d.ts.map +1 -1
  116. package/dist/schemas/command-admission.js +2 -1
  117. package/dist/schemas/command-admission.js.map +1 -1
  118. package/dist/schemas/contact-need.d.ts +50 -0
  119. package/dist/schemas/contact-need.d.ts.map +1 -0
  120. package/dist/schemas/contact-need.js +19 -0
  121. package/dist/schemas/contact-need.js.map +1 -0
  122. package/dist/schemas/contacts-settings.d.ts +5 -0
  123. package/dist/schemas/contacts-settings.d.ts.map +1 -0
  124. package/dist/schemas/contacts-settings.js +11 -0
  125. package/dist/schemas/contacts-settings.js.map +1 -0
  126. package/dist/schemas/extension-updates.d.ts +8 -0
  127. package/dist/schemas/extension-updates.d.ts.map +1 -1
  128. package/dist/schemas/issues.d.ts +2 -0
  129. package/dist/schemas/issues.d.ts.map +1 -1
  130. package/dist/schemas/issues.js +1 -0
  131. package/dist/schemas/issues.js.map +1 -1
  132. package/dist/schemas/links.d.ts +8 -0
  133. package/dist/schemas/links.d.ts.map +1 -1
  134. package/dist/schemas/links.js +4 -0
  135. package/dist/schemas/links.js.map +1 -1
  136. package/dist/schemas/need-kinds.d.ts +2 -1
  137. package/dist/schemas/need-kinds.d.ts.map +1 -1
  138. package/dist/schemas/need-kinds.js +2 -2
  139. package/dist/schemas/need-kinds.js.map +1 -1
  140. package/dist/schemas/needs.d.ts +156 -13
  141. package/dist/schemas/needs.d.ts.map +1 -1
  142. package/dist/schemas/needs.js +5 -12
  143. package/dist/schemas/needs.js.map +1 -1
  144. package/dist/schemas/redirect-need.d.ts +15 -0
  145. package/dist/schemas/redirect-need.d.ts.map +1 -0
  146. package/dist/schemas/redirect-need.js +14 -0
  147. package/dist/schemas/redirect-need.js.map +1 -0
  148. package/dist/schemas/s2s-identity.d.ts +521 -0
  149. package/dist/schemas/s2s-identity.d.ts.map +1 -0
  150. package/dist/schemas/s2s-identity.js +208 -0
  151. package/dist/schemas/s2s-identity.js.map +1 -0
  152. package/dist/schemas/s2s-views.d.ts +2127 -0
  153. package/dist/schemas/s2s-views.d.ts.map +1 -0
  154. package/dist/schemas/s2s-views.js +217 -0
  155. package/dist/schemas/s2s-views.js.map +1 -0
  156. package/dist/schemas/s2s-wire.d.ts +1616 -0
  157. package/dist/schemas/s2s-wire.d.ts.map +1 -0
  158. package/dist/schemas/s2s-wire.js +276 -0
  159. package/dist/schemas/s2s-wire.js.map +1 -0
  160. package/dist/schemas/s2s.d.ts +5 -0
  161. package/dist/schemas/s2s.d.ts.map +1 -0
  162. package/dist/schemas/s2s.js +5 -0
  163. package/dist/schemas/s2s.js.map +1 -0
  164. package/dist/schemas/settings.d.ts +16 -0
  165. package/dist/schemas/settings.d.ts.map +1 -1
  166. package/dist/schemas/settings.js +2 -0
  167. package/dist/schemas/settings.js.map +1 -1
  168. package/dist/schemas/terminal.d.ts +2 -0
  169. package/dist/schemas/terminal.d.ts.map +1 -1
  170. package/dist/schemas/terminal.js +4 -0
  171. package/dist/schemas/terminal.js.map +1 -1
  172. package/dist/schemas/vpn.d.ts +4 -0
  173. package/dist/schemas/vpn.d.ts.map +1 -1
  174. package/dist/schemas/vpn.js +9 -0
  175. package/dist/schemas/vpn.js.map +1 -1
  176. package/dist/state/auth-state.d.ts.map +1 -1
  177. package/dist/state/auth-state.js +6 -0
  178. package/dist/state/auth-state.js.map +1 -1
  179. package/dist/state/definition.d.ts +18 -0
  180. package/dist/state/definition.d.ts.map +1 -1
  181. package/package.json +20 -5
  182. package/src/contracts/approvals.contract.ts +24 -3
  183. package/src/ids/conversation-ids.test.ts +22 -3
  184. package/src/ids/conversation-ids.ts +5 -7
  185. package/src/protocol/ingress-contract.fixture.json +6 -1
  186. package/src/protocol/raw/extension-protocol.ts +45 -1
  187. package/src/protocol/raw/raw-json-routes.ts +85 -0
  188. package/src/protocol/raw/raw-routes.ts +66 -3
  189. package/src/protocol/s2s/address.test.ts +157 -0
  190. package/src/protocol/s2s/address.ts +193 -0
  191. package/src/protocol/s2s/attestation.test.ts +262 -0
  192. package/src/protocol/s2s/attestation.ts +173 -0
  193. package/src/protocol/s2s/canonical.test.ts +70 -0
  194. package/src/protocol/s2s/canonical.ts +119 -0
  195. package/src/protocol/s2s/envelope.test.ts +162 -0
  196. package/src/protocol/s2s/envelope.ts +194 -0
  197. package/src/protocol/s2s/extension-sign.test.ts +117 -0
  198. package/src/protocol/s2s/extension-sign.ts +76 -0
  199. package/src/protocol/s2s/identity-doc.test.ts +187 -0
  200. package/src/protocol/s2s/identity-doc.ts +169 -0
  201. package/src/protocol/s2s/index.ts +15 -0
  202. package/src/protocol/s2s/kem.ts +62 -0
  203. package/src/protocol/s2s/keys.test.ts +76 -0
  204. package/src/protocol/s2s/keys.ts +155 -0
  205. package/src/protocol/s2s/passkey-cosign.test.ts +98 -0
  206. package/src/protocol/s2s/passkey-cosign.testing.ts +86 -0
  207. package/src/protocol/s2s/passkey-cosign.ts +192 -0
  208. package/src/protocol/s2s/s2s.testing.ts +22 -0
  209. package/src/protocol/s2s/session.test.ts +133 -0
  210. package/src/protocol/s2s/session.ts +179 -0
  211. package/src/protocol/s2s/sign.test.ts +66 -0
  212. package/src/protocol/s2s/sign.ts +53 -0
  213. package/src/schemas/approvals.ts +41 -0
  214. package/src/schemas/automations.ts +4 -3
  215. package/src/schemas/command-admission.ts +4 -1
  216. package/src/schemas/contact-need.ts +26 -0
  217. package/src/schemas/contacts-settings.ts +16 -0
  218. package/src/schemas/issues.ts +1 -0
  219. package/src/schemas/links.ts +4 -0
  220. package/src/schemas/need-kinds.ts +2 -2
  221. package/src/schemas/needs.ts +5 -18
  222. package/src/schemas/redirect-need.ts +19 -0
  223. package/src/schemas/s2s-identity.ts +329 -0
  224. package/src/schemas/s2s-views.ts +326 -0
  225. package/src/schemas/s2s-wire.ts +401 -0
  226. package/src/schemas/s2s.test.ts +175 -0
  227. package/src/schemas/s2s.ts +9 -0
  228. package/src/schemas/settings.ts +2 -0
  229. package/src/schemas/terminal.ts +6 -0
  230. package/src/schemas/version-seam.test.ts +9 -0
  231. package/src/schemas/vpn.ts +13 -0
  232. package/src/state/auth-state.ts +10 -0
@@ -0,0 +1,179 @@
1
+ import { gcm } from "@noble/ciphers/aes.js";
2
+ import { hmac } from "@noble/hashes/hmac.js";
3
+ import { sha256 } from "@noble/hashes/sha2.js";
4
+ import { randomBytes } from "@noble/hashes/utils.js";
5
+ import { S2S_INFO, type S2sPublicKeys, type S2sSigningKeys } from "../../schemas/s2s-identity.js";
6
+ import { S2S_CALL_SKEW_MS, type S2sCallMethod, type S2sCallSealed, type S2sSessionOpen } from "../../schemas/s2s-wire.js";
7
+ import { canonicalBytes, equalBytes, fromBase64Url, fromUtf8, toBase64Url, utf8 } from "./canonical.js";
8
+ import { decapsulate, deriveKey, encapsulate } from "./kem.js";
9
+ import { fingerprintOf, type RandomBytes, type S2sKeySet, secretKeysOf } from "./keys.js";
10
+ import { hybridSign, hybridVerify } from "./sign.js";
11
+
12
+ // CALL SESSIONS (docs/architecture/messages.md, "Calls"): records and operating are request and response, so one hybrid
13
+ // key agreement, signed by the caller, opens a session whose key then seals every call and answer for an hour. A call
14
+ // costs a symmetric seal, never a signature, and carries a fresh nonce and a timestamp the callee holds to its replay
15
+ // window, so a call replayed or held back is refused.
16
+
17
+ const SESSION_INFO = `${S2S_INFO} session`;
18
+
19
+ // The session key both sides derive: 32 bytes, held in memory only.
20
+ export type SessionKey = Uint8Array;
21
+
22
+ const unsignedOf = (request: S2sSessionOpen): Omit<S2sSessionOpen, "sig"> => {
23
+ const { sig: _sig, ...rest } = request;
24
+ return rest;
25
+ };
26
+
27
+ const keyFor = (secret: Uint8Array, request: S2sSessionOpen): SessionKey => deriveKey(secret, sha256(canonicalBytes(unsignedOf(request))), SESSION_INFO);
28
+
29
+ export interface SessionOpenInput {
30
+ readonly from: string;
31
+ readonly to: string;
32
+ readonly as?: string | undefined;
33
+ readonly caller: S2sKeySet;
34
+ readonly callee: S2sPublicKeys;
35
+ readonly now: number;
36
+ readonly random?: RandomBytes;
37
+ }
38
+
39
+ // What the caller posts to POST /s2s/session, and the key it holds for the session's calls.
40
+ export interface SessionOpening {
41
+ readonly request: S2sSessionOpen;
42
+ readonly key: SessionKey;
43
+ }
44
+
45
+ // The caller's half: a fresh agreement to the callee's key set, signed.
46
+ export const openSession = ({ from, to, as, caller, callee, now, random = randomBytes }: SessionOpenInput): SessionOpening => {
47
+ const agreement = encapsulate(callee, random);
48
+ const unsigned: Omit<S2sSessionOpen, "sig"> = {
49
+ v: 1,
50
+ from,
51
+ fromFp: caller.fingerprint,
52
+ to,
53
+ toFp: fingerprintOf(callee),
54
+ at: now,
55
+ nonce: toBase64Url(random(16)),
56
+ enc: agreement.enc,
57
+ };
58
+ if (as !== undefined) {
59
+ unsigned.as = as;
60
+ }
61
+ const request: S2sSessionOpen = { ...unsigned, sig: hybridSign("session", canonicalBytes(unsigned), secretKeysOf(caller.secret)) };
62
+ return { request, key: keyFor(agreement.secret, request) };
63
+ };
64
+
65
+ export interface SessionAcceptInput {
66
+ // The pinned caller's public signing keys.
67
+ readonly caller: S2sSigningKeys;
68
+ // Every key set this sandbox can open with.
69
+ readonly keys: readonly S2sKeySet[];
70
+ readonly now: number;
71
+ readonly skewMs?: number;
72
+ }
73
+
74
+ // `signature`: the caller's keys did not sign it. `stale`: its time is outside the skew. `recipient`: sealed to no key
75
+ // set offered. `malformed`: its key agreement cannot be decapsulated.
76
+ export type SessionAccepted =
77
+ | { readonly ok: true; readonly key: SessionKey }
78
+ | { readonly ok: false; readonly reason: "signature" | "stale" | "recipient" | "malformed" };
79
+
80
+ // The callee's half: verify, check the clock, and derive the same key. A replayed request is the caller's replay
81
+ // window's to refuse (createReplayWindow, keyed by the request's nonce).
82
+ export const acceptSession = (request: S2sSessionOpen, { caller, keys, now, skewMs = S2S_CALL_SKEW_MS }: SessionAcceptInput): SessionAccepted => {
83
+ if (!hybridVerify("session", canonicalBytes(unsignedOf(request)), request.sig, caller)) {
84
+ return { ok: false, reason: "signature" };
85
+ }
86
+ if (Math.abs(now - request.at) > skewMs) {
87
+ return { ok: false, reason: "stale" };
88
+ }
89
+ const keySet = keys.find((candidate) => candidate.fingerprint === request.toFp);
90
+ if (keySet === undefined) {
91
+ return { ok: false, reason: "recipient" };
92
+ }
93
+ const secret = decapsulate(request.enc, secretKeysOf(keySet.secret));
94
+ return secret === undefined ? { ok: false, reason: "malformed" } : { ok: true, key: keyFor(secret, request) };
95
+ };
96
+
97
+ // The callee's proof it derived the same key: HMAC-SHA256 under it over the session id (S2sSessionAnswer `confirm`).
98
+ export const sessionConfirm = (key: SessionKey, session: string): string => toBase64Url(hmac(sha256, key, utf8(`${SESSION_INFO} confirm ${session}`)));
99
+
100
+ export const confirmsSession = (key: SessionKey, session: string, confirm: string): boolean => {
101
+ const given = fromBase64Url(confirm);
102
+ return given !== undefined && equalBytes(given, hmac(sha256, key, utf8(`${SESSION_INFO} confirm ${session}`)));
103
+ };
104
+
105
+ // Which way a sealed body travels. An answer is bound to the call it answers by that call's nonce (`re`), so no answer
106
+ // can be handed back for another call.
107
+ export type CallLeg = { readonly direction: "call" } | { readonly direction: "answer"; readonly re: string };
108
+
109
+ export interface CallContext {
110
+ readonly session: string;
111
+ readonly method: S2sCallMethod;
112
+ readonly leg: CallLeg;
113
+ }
114
+
115
+ const aadOf = ({ session, method, leg }: CallContext, at: number, nonce: string): Uint8Array =>
116
+ canonicalBytes(leg.direction === "call" ? { session, method, direction: "call", at, nonce } : { session, method, direction: "answer", re: leg.re, at, nonce });
117
+
118
+ // Seals a call's input or its answer, as JSON, under the session key.
119
+ export const sealCall = <T>(key: SessionKey, context: CallContext, payload: T, now: number, random: RandomBytes = randomBytes): S2sCallSealed => {
120
+ const nonceBytes = random(12);
121
+ const nonce = toBase64Url(nonceBytes);
122
+ const body = gcm(key, nonceBytes, aadOf(context, now, nonce)).encrypt(utf8(JSON.stringify(payload)));
123
+ return { at: now, nonce, body: toBase64Url(body) };
124
+ };
125
+
126
+ // The answer to admitting one nonce: fresh, outside the clock skew, or seen before.
127
+ export type ReplayVerdict = "fresh" | "stale" | "replay";
128
+
129
+ export interface ReplayWindow {
130
+ // Admits a nonce made at `at`, remembering it until it would be stale anyway.
131
+ readonly admit: (nonce: string, at: number, now: number) => ReplayVerdict;
132
+ readonly size: () => number;
133
+ }
134
+
135
+ // One session's (or one caller's session requests') nonces: a time outside `skewMs` of now is stale, a nonce seen within
136
+ // the window is a replay, and nothing older than the window is kept, since it would be refused as stale.
137
+ export const createReplayWindow = (skewMs: number = S2S_CALL_SKEW_MS): ReplayWindow => {
138
+ const seen = new Map<string, number>();
139
+ return {
140
+ admit: (nonce, at, now) => {
141
+ for (const [known, when] of seen) {
142
+ if (when < now - skewMs) {
143
+ seen.delete(known);
144
+ }
145
+ }
146
+ if (Math.abs(now - at) > skewMs) {
147
+ return "stale";
148
+ }
149
+ if (seen.has(nonce)) {
150
+ return "replay";
151
+ }
152
+ seen.set(nonce, at);
153
+ return "fresh";
154
+ },
155
+ size: () => seen.size,
156
+ };
157
+ };
158
+
159
+ export type CallOpened = { readonly ok: true; readonly json: string } | { readonly ok: false; readonly reason: "stale" | "replay" | "decrypt" };
160
+
161
+ // Opens a sealed call or answer: its time within the window, its nonce never seen, its body sealed under this key for
162
+ // this session, method and leg. Answers the JSON text, for the method's own schema to parse (S2S_CALLS).
163
+ export const openCall = (key: SessionKey, context: CallContext, sealed: S2sCallSealed, now: number, replay: ReplayWindow): CallOpened => {
164
+ const nonceBytes = fromBase64Url(sealed.nonce);
165
+ const body = fromBase64Url(sealed.body);
166
+ if (nonceBytes?.length !== 12 || body === undefined) {
167
+ return { ok: false, reason: "decrypt" };
168
+ }
169
+ let json: string;
170
+ try {
171
+ json = fromUtf8(gcm(key, nonceBytes, aadOf(context, sealed.at, sealed.nonce)).decrypt(body));
172
+ } catch {
173
+ // allow(silent-catch): a tag that does not verify is a tampered body, another session's, or another call's.
174
+ return { ok: false, reason: "decrypt" };
175
+ }
176
+ // After the tag, so a forged nonce cannot fill the window.
177
+ const verdict = replay.admit(sealed.nonce, sealed.at, now);
178
+ return verdict === "fresh" ? { ok: true, json } : { ok: false, reason: verdict };
179
+ };
@@ -0,0 +1,66 @@
1
+ import { fromBase64Url, toBase64Url, utf8 } from "./canonical.js";
2
+ import { secretKeysOf } from "./keys.js";
3
+ import { keySetFor } from "./s2s.testing.js";
4
+ import { hybridSign, hybridVerify, signedBytes } from "./sign.js";
5
+
6
+ const set = keySetFor(`ops`);
7
+ const other = keySetFor(`other`);
8
+ const message = utf8(`the bytes that matter`);
9
+ const sig = hybridSign(`envelope`, message, secretKeysOf(set.secret));
10
+
11
+ // The signature with one byte of one half changed.
12
+ const flipped = (half: string, at: number): string => {
13
+ const bytes = fromBase64Url(half) ?? new Uint8Array();
14
+ bytes[at] = (bytes[at] ?? 0) ^ 0x01;
15
+ return toBase64Url(bytes);
16
+ };
17
+
18
+ describe("a hybrid signature", () => {
19
+ it("verifies with the signer's keys over the same domain and bytes", () => {
20
+ expect(fromBase64Url(sig.ed25519)?.length).toBe(64);
21
+ expect(fromBase64Url(sig.mldsa65)?.length).toBe(3309);
22
+ expect(hybridVerify(`envelope`, message, sig, set.public)).toBe(true);
23
+ });
24
+
25
+ it("binds the domain, so a signature over an envelope is none over an identity", () => {
26
+ expect(hybridVerify(`identity`, message, sig, set.public)).toBe(false);
27
+ expect(signedBytes(`session`, utf8(`x`))).toEqual(utf8(`intentic-s2s/1 session\nx`));
28
+ });
29
+
30
+ it("does not verify with another key set", () => {
31
+ expect(hybridVerify(`envelope`, message, sig, other.public)).toBe(false);
32
+ expect(hybridVerify(`envelope`, message, sig, { ed25519: set.public.ed25519, mldsa65: other.public.mldsa65 })).toBe(false);
33
+ expect(hybridVerify(`envelope`, message, sig, { ed25519: other.public.ed25519, mldsa65: set.public.mldsa65 })).toBe(false);
34
+ });
35
+
36
+ it("does not verify on either algorithm's half alone: the other half from another signer fails it", () => {
37
+ const theirs = hybridSign(`envelope`, message, secretKeysOf(other.secret));
38
+ expect(hybridVerify(`envelope`, message, { ed25519: sig.ed25519, mldsa65: theirs.mldsa65 }, set.public)).toBe(false);
39
+ expect(hybridVerify(`envelope`, message, { ed25519: theirs.ed25519, mldsa65: sig.mldsa65 }, set.public)).toBe(false);
40
+ expect(hybridVerify(`envelope`, message, { ed25519: sig.ed25519, mldsa65: `` }, set.public)).toBe(false);
41
+ expect(hybridVerify(`envelope`, message, { ed25519: ``, mldsa65: sig.mldsa65 }, set.public)).toBe(false);
42
+ });
43
+
44
+ it("fails for any changed byte of the message", () => {
45
+ for (let at = 0; at < message.length; at++) {
46
+ const changed = message.slice();
47
+ changed[at] = (changed[at] ?? 0) ^ 0x80;
48
+ expect(hybridVerify(`envelope`, changed, sig, set.public)).toBe(false);
49
+ }
50
+ });
51
+
52
+ it("fails for any changed byte of the Ed25519 half, and for changed bytes across the ML-DSA half", () => {
53
+ for (let at = 0; at < 64; at++) {
54
+ expect(hybridVerify(`envelope`, message, { ...sig, ed25519: flipped(sig.ed25519, at) }, set.public)).toBe(false);
55
+ }
56
+ for (const at of [0, 1, 640, 1500, 2420, 3000, 3307, 3308]) {
57
+ expect(hybridVerify(`envelope`, message, { ...sig, mldsa65: flipped(sig.mldsa65, at) }, set.public)).toBe(false);
58
+ }
59
+ });
60
+
61
+ it("answers false, never throws, for halves and keys that are not base64url or of the wrong length", () => {
62
+ expect(hybridVerify(`envelope`, message, { ...sig, ed25519: `not base64!` }, set.public)).toBe(false);
63
+ expect(hybridVerify(`envelope`, message, { ...sig, mldsa65: sig.mldsa65.slice(0, 100) }, set.public)).toBe(false);
64
+ expect(hybridVerify(`envelope`, message, sig, { ...set.public, ed25519: set.public.ed25519.slice(0, 20) })).toBe(false);
65
+ });
66
+ });
@@ -0,0 +1,53 @@
1
+ import { ed25519 } from "@noble/curves/ed25519.js";
2
+ import { ml_dsa65 } from "@noble/post-quantum/ml-dsa.js";
3
+ import { type HybridSig, S2S_INFO, type S2sSigningKeys } from "../../schemas/s2s-identity.js";
4
+ import { concatBytes, fromBase64Url, toBase64Url, utf8 } from "./canonical.js";
5
+ import type { ExtensionSignDomain } from "./extension-sign.js";
6
+
7
+ // Hybrid signatures: Ed25519 and ML-DSA-65 over the same bytes, and a signature verifies only when both halves do, so it
8
+ // holds while either family does. Every signature names what it is for (its domain), so one made over an identity
9
+ // document can never be passed off as one over an envelope or a session.
10
+
11
+ export const SIGN_DOMAINS = ["identity", "identity-prev", "envelope", "session", "attestation"] as const;
12
+ export type SignDomain = (typeof SIGN_DOMAINS)[number];
13
+
14
+ // The secret signing keys, raw: an Ed25519 seed and an expanded ML-DSA-65 secret key (keys.ts secretKeysOf, or a
15
+ // recovery key).
16
+ export interface SigningSecret {
17
+ readonly ed25519: Uint8Array;
18
+ readonly mldsa65: Uint8Array;
19
+ }
20
+
21
+ // What is actually signed: the protocol, the domain and a newline, then the message.
22
+ export const signedBytes = (domain: SignDomain | ExtensionSignDomain, message: Uint8Array): Uint8Array => concatBytes(utf8(`${S2S_INFO} ${domain}\n`), message);
23
+
24
+ export const hybridSign = (domain: SignDomain | ExtensionSignDomain, message: Uint8Array, secret: SigningSecret): HybridSig => {
25
+ const bytes = signedBytes(domain, message);
26
+ return { ed25519: toBase64Url(ed25519.sign(bytes, secret.ed25519)), mldsa65: toBase64Url(ml_dsa65.sign(bytes, secret.mldsa65)) };
27
+ };
28
+
29
+ const verifiesWith = (verify: () => boolean): boolean => {
30
+ try {
31
+ return verify();
32
+ } catch {
33
+ // allow(silent-catch): a key or signature of the wrong length throws in the library; it verifies nothing.
34
+ return false;
35
+ }
36
+ };
37
+
38
+ // True only when both halves verify over the domain's bytes with these public keys; any malformed part is false.
39
+ export const hybridVerify = (domain: SignDomain | ExtensionSignDomain, message: Uint8Array, sig: HybridSig, keys: S2sSigningKeys): boolean => {
40
+ const parts = {
41
+ edSig: fromBase64Url(sig.ed25519),
42
+ dsaSig: fromBase64Url(sig.mldsa65),
43
+ edKey: fromBase64Url(keys.ed25519),
44
+ dsaKey: fromBase64Url(keys.mldsa65),
45
+ };
46
+ const { edSig, dsaSig, edKey, dsaKey } = parts;
47
+ if (edSig === undefined || dsaSig === undefined || edKey === undefined || dsaKey === undefined) {
48
+ return false;
49
+ }
50
+ const bytes = signedBytes(domain, message);
51
+ // RFC 8032's strict reading, not ZIP 215's: one signature per message and key, no other encodings of it.
52
+ return verifiesWith(() => ed25519.verify(edSig, bytes, edKey, { zip215: false })) && verifiesWith(() => ml_dsa65.verify(dsaSig, bytes, dsaKey));
53
+ };
@@ -1,6 +1,8 @@
1
1
  // approvals: things the agent prepared and may not do until the owner says yes (.intentic/config/approvals/<id>.json)
2
2
  import { z } from "zod";
3
+ import { PasskeyCosignSchema } from "../protocol/s2s/passkey-cosign.js";
3
4
  import { entryId } from "./internal.js";
5
+ import { AuthenticationResponseSchema } from "./system.js";
4
6
 
5
7
  // One queue for anything that needs a yes-click before a machine carries it out and records the outcome: an envelope
6
8
  // (who, when, status, result) plus a kind-specific payload, a discriminated union. Excludes a facts inbox and a hold a
@@ -108,6 +110,15 @@ export const ActionApprovalSchema = z.object({
108
110
  .describe(
109
111
  "Who carries this out instead of an agent turn: once you approve it, the sandbox hands it to that extension's backend, which acts only if what it holds still matches the digest. Written by the extension's own command when it holds an act; an item written by hand never needs one.",
110
112
  ),
113
+ // (2026-11-28) Written by whoever files the item (the performer extension), never by hand, and part of what the yes
114
+ // pins. The daemon refuses a `required` item approved without a passkey; the performer re-checks what it is handed
115
+ // (`ApprovedAction.cosign`), since a turn can write this file before anyone approves it.
116
+ cosign: z
117
+ .enum(["offered", "required"])
118
+ .optional()
119
+ .describe(
120
+ "Whether approving it with a passkey is offered, or required: the sandbox then keeps the passkey's signature over exactly what is approved and hands it to the extension carrying it out, which anyone can check later. Only an item naming a `performer` takes one.",
121
+ ),
111
122
  ...envelope,
112
123
  });
113
124
  export type ActionApproval = z.infer<typeof ActionApprovalSchema>;
@@ -125,6 +136,36 @@ export type ActionApprovalSummary = z.infer<typeof ActionApprovalSummarySchema>;
125
136
  export const ApprovalSummarySchema = z.discriminatedUnion("kind", [PostApprovalSummarySchema, ActionApprovalSummarySchema]);
126
137
  export type ApprovalSummary = z.infer<typeof ApprovalSummarySchema>;
127
138
 
139
+ // (2026-11-28) What `upsert` takes: an item as the owner wants it, and for an action being approved, optionally the
140
+ // passkey assertion that co-signs the yes (the browser's `PublicKeyCredential.toJSON()` over the challenge
141
+ // `passkeyOptions` answered). Never written into the item: the daemon verifies it, and keeps the co-signature
142
+ // (PasskeyCosignSchema) with the recorded yes, off the workspace.
143
+ export const ApprovalUpsertSchema = z.discriminatedUnion("kind", [
144
+ PostApprovalSummarySchema,
145
+ ActionApprovalSummarySchema.extend({
146
+ passkey: AuthenticationResponseSchema.optional().describe(
147
+ "Your passkey's assertion over this item's challenge (POST /approvals/{id}/passkey), when approving it with a passkey. Required for an item whose `cosign` is `required`.",
148
+ ),
149
+ }),
150
+ ]);
151
+ export type ApprovalUpsert = z.infer<typeof ApprovalUpsertSchema>;
152
+
153
+ // (2026-11-28) The WebAuthn request options for co-signing one action with a passkey, in the JSON form
154
+ // `PublicKeyCredential.parseRequestOptionsFromJSON` takes: the challenge is the approval's own
155
+ // (protocol/s2s/passkey-cosign.ts `cosignChallenge`), and only the signed-in person's own passkeys are allowed.
156
+ export const ApprovalPasskeyOptionsSchema = z.object({
157
+ rpId: z.string(),
158
+ challenge: z.string().describe("base64url of SHA-256 over this sandbox, this item and its performer's digest."),
159
+ timeout: z.number(),
160
+ userVerification: z.literal("required"),
161
+ allowCredentials: z.array(z.object({ type: z.literal("public-key"), id: z.string(), transports: z.array(z.string()).optional() })),
162
+ available: z.boolean().describe("Whether you hold a passkey on this sandbox to answer with; false means add one first, from Access."),
163
+ });
164
+ export type ApprovalPasskeyOptions = z.infer<typeof ApprovalPasskeyOptionsSchema>;
165
+
166
+ // (2026-11-28) The co-signature a yes was given with, as the sandbox keeps it and hands it on.
167
+ export { PasskeyCosignSchema };
168
+
128
169
  // Filenames that failed to parse; agent-written files are a trust boundary, so these are surfaced, not silently
129
170
  // dropped.
130
171
  export const ApprovalsListSchema = z.object({
@@ -586,9 +586,10 @@ export const TriggerSourceSchema = z.object({
586
586
  // The provider owns the payload vocabulary, so it owns the first prompt that explains that payload.
587
587
  starterPrompt: z.string().min(1).optional(),
588
588
  // (2026-11-26) Set on a source anyone on the internet reaches (a listener's `strangers`), naming which of the owner's
589
- // admission floors its wakes answer to: `visitor` (a website visitor's), `report` (a bug report's). Absent: a source
590
- // whose senders the owner connected, held to the team chat floor.
591
- strangers: z.enum(["visitor", "report"]).optional(),
589
+ // admission floors its wakes answer to: `visitor` (a website visitor's), `report` (a bug report's), and (2026-11-27)
590
+ // `contact` (a contact request from a sandbox that is not a contact yet). Absent: a source whose senders the owner
591
+ // connected, held to the team chat floor.
592
+ strangers: z.enum(["visitor", "report", "contact"]).optional(),
592
593
  // Any one connected capability is enough; computed client-side, since capability facts are pushed live and a served
593
594
  // boolean would go stale between polls.
594
595
  requires: z.array(z.string().min(1)).default([]),
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
 
3
3
  // The class of thing asking to start a session, the admission policy's key space; derived daemon-side, never sent by a
4
4
  // client. Chat and loops are absent since both begin with the owner's own click.
5
- export const WakeSourceSchema = z.enum(["schedule", "event", "listener", "webchat", "issues", "workspace", "workflow"]);
5
+ export const WakeSourceSchema = z.enum(["schedule", "event", "listener", "webchat", "issues", "contact", "workspace", "workflow"]);
6
6
  export type WakeSource = z.infer<typeof WakeSourceSchema>;
7
7
  // One admission verdict the owner can configure: let it run, hold it for approval, or refuse it outright.
8
8
  export const AdmissionRuleSchema = z.enum(["allow", "hold", "deny"]);
@@ -51,6 +51,9 @@ export const AdmissionPolicySchema = z.object({
51
51
  // Defaults to hold, unlike the others: a bug-report wake has full repo powers and a stranger's stack trace as its
52
52
  // brief.
53
53
  issues: AdmissionRuleSchema.default("hold"),
54
+ // (2026-11-27) Held by default too, like `issues`: a contact request comes from a sandbox nobody here accepted yet,
55
+ // and the brief of the work it starts is that stranger's request and note.
56
+ contact: AdmissionRuleSchema.default("hold"),
54
57
  workspace: AdmissionRuleSchema.default("allow"),
55
58
  workflow: z.enum(["allow", "deny"]).default("allow"),
56
59
  });
@@ -0,0 +1,26 @@
1
+ import { z } from "zod";
2
+ import { S2S_NOTE_MAX, S2sAddressSchema, S2sGrantsSchema, S2sRefSchema } from "./s2s-identity.js";
3
+
4
+ // The `contact` need (schemas/needs.ts, docs/architecture/messages.md): an agent never makes or accepts a contact itself,
5
+ // it raises a card a person presses. Its own module, importing only the identity shapes, since needs.ts is imported by
6
+ // modules the s2s wire shapes import in turn. Re-exported from schemas/s2s.ts.
7
+
8
+ export const ContactNeedSchema = z.object({
9
+ kind: z.literal("contact"),
10
+ address: S2sAddressSchema.describe("The sandbox to add, or the one whose request to accept."),
11
+ action: z.enum(["add", "accept"]),
12
+ contactId: S2sRefSchema.optional().describe("The waiting request's contact, for an accept."),
13
+ grants: S2sGrantsSchema.describe("What this sandbox would let it do here."),
14
+ note: z.string().max(S2S_NOTE_MAX).optional().describe("The note the request carries, for an add."),
15
+ });
16
+ export type ContactNeed = z.infer<typeof ContactNeedSchema>;
17
+ // What the agent may send: the address (or the waiting contact) and the grants it proposes; the daemon resolves the rest.
18
+ export const ContactNeedAskSchema = z.object({
19
+ kind: z.literal("contact"),
20
+ action: z.enum(["add", "accept"]),
21
+ address: z.string().trim().min(1).max(300).optional().describe("The sandbox to add, as the agent has it."),
22
+ contactId: S2sRefSchema.optional().describe("The waiting request to accept."),
23
+ grants: S2sGrantsSchema.prefault({}).describe("What it proposes the contact may do here; messages only when left out."),
24
+ note: z.string().max(S2S_NOTE_MAX).optional(),
25
+ });
26
+ export type ContactNeedAsk = z.infer<typeof ContactNeedAskSchema>;
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+
3
+ // (2026-11-27) How this sandbox takes contacts, read by the daemon's contacts (s2s/, docs/architecture/messages.md) when an
4
+ // agent accepts a contact request. Off by default: an agent never makes or accepts a contact on its own, it raises a card
5
+ // for a person.
6
+ export const ContactsSettingsSchema = z
7
+ .object({
8
+ agentMayAccept: z
9
+ .boolean()
10
+ .default(false)
11
+ .describe(
12
+ "Let an automation's agent accept a contact request by itself, giving it messages only. Off, every accept waits for a person's press on a card.",
13
+ ),
14
+ })
15
+ .prefault({})
16
+ .describe("How this sandbox takes contacts, the other sandboxes it exchanges messages with.");
@@ -77,6 +77,7 @@ export type IssueIngest = z.infer<typeof IssueIngestSchema>;
77
77
  export const IssueSenderSchema = z.object({
78
78
  sandboxId: z.string().max(40).describe("The reporting sandbox's id."),
79
79
  sandboxName: z.string().max(120).describe("Its name on your account."),
80
+ address: z.string().max(300).optional().describe("Its address, when the report came as a message from a contact (docs/architecture/messages.md)."),
80
81
  project: z.string().max(200).describe("The project it reported about, as this sandbox claims it."),
81
82
  conversationId: z.string().max(120).optional().describe("The conversation over there that reported it."),
82
83
  person: z
@@ -94,6 +94,10 @@ export const InboundLinkSummarySchema = z.object({
94
94
  lastUsedAt: z.number().optional().describe("The last time it was used, coarse on purpose; absent means never."),
95
95
  conversations: z.number().int().nonnegative().describe("How many conversations it has opened here."),
96
96
  requests: z.array(LinkRequestSchema).describe("Tasks waiting for the owner's yes, oldest first."),
97
+ upgraded: z
98
+ .object({ contact: z.string(), at: z.number() })
99
+ .optional()
100
+ .describe("Set once both sandboxes spoke s2s/1 and the link became a contact (its id here, and when): its token works nowhere any more."),
97
101
  });
98
102
  export type InboundLinkSummary = z.infer<typeof InboundLinkSummarySchema>;
99
103
  export const InboundLinksListSchema = z.object({ links: z.array(InboundLinkSummarySchema) });
@@ -4,10 +4,10 @@ import { z } from "zod";
4
4
  // need's in stack-grants.ts. Its own module so the list can grow without pushing needs.ts past its size.
5
5
 
6
6
  const FIRST_KINDS = ["capability", "secret", "grant", "release", "environment", "automation", "instruction", "host-power"] as const;
7
- export const NEED_KINDS = [...FIRST_KINDS, "claim", "route", "redirect", "deploy", "wsl-memory"] as const;
7
+ export const NEED_KINDS = [...FIRST_KINDS, "claim", "route", "redirect", "deploy", "wsl-memory", "contact"] as const;
8
8
  export const NeedKindSchema = z
9
9
  .enum(NEED_KINDS)
10
10
  .describe(
11
- "What is being asked for: a connection, a secret's value, wider reach, a gated credential, a tool in the image, an automation to run unattended, a standing rule written into an AGENTS.md, power settings changed on the computer this sandbox runs on, a project claimed for this sandbox so the owner's other sandboxes report its problems here, a person's leave for this sandbox to act as them in another, a person's message sent on to the sandbox it was meant for, a managed stack let receive the secrets its manifest reads, or a smaller WSL VM for the PC this sandbox runs on.",
11
+ "What is being asked for: a connection, a secret's value, wider reach, a gated credential, a tool in the image, an automation to run unattended, a standing rule written into an AGENTS.md, power settings changed on the computer this sandbox runs on, a project claimed for this sandbox so the owner's other sandboxes report its problems here, a person's leave for this sandbox to act as them in another, a person's message sent on to the sandbox it was meant for, a managed stack let receive the secrets its manifest reads, a smaller WSL VM for the PC this sandbox runs on, or another sandbox added or accepted as a contact.",
12
12
  );
13
13
  export type NeedKind = z.infer<typeof NeedKindSchema>;
@@ -5,6 +5,8 @@ import { AutomationSchema, WatchKindSchema } from "./automations.js";
5
5
  import { DeployNeedAskSchema, DeployNeedSchema } from "./stack-grants.js";
6
6
  import { HostPowerFindingSchema } from "./host-power.js";
7
7
  import { WslMemoryNeedSchema } from "./wsl-memory.js";
8
+ import { RedirectNeedSchema } from "./redirect-need.js";
9
+ import { ContactNeedAskSchema, ContactNeedSchema } from "./contact-need.js";
8
10
  import { entryId } from "./internal.js";
9
11
  import { PASS_SCOPES } from "../protocol/doors/pass-scopes.js";
10
12
  import { SECRET_HOSTS_MAX } from "../policy/secret-hosts.js";
@@ -16,6 +18,7 @@ import { SecretHostSchema } from "./secrets.js";
16
18
  // (docs/architecture/needs.md). Every word on a need is the daemon's except `why`, the agent's own case.
17
19
 
18
20
  export { NEED_KINDS, type NeedKind, NeedKindSchema } from "./need-kinds.js";
21
+ export { REDIRECT_WORDS_MAX, type RedirectNeed, RedirectNeedSchema } from "./redirect-need.js";
19
22
 
20
23
  // `working` is a yes still being carried out: a connection whose form is open, an overlay approved but not yet built.
21
24
  export const NeedStatusSchema = z
@@ -242,24 +245,6 @@ export const RouteNeedSchema = z.object({
242
245
  });
243
246
  export type RouteNeed = z.infer<typeof RouteNeedSchema>;
244
247
 
245
- // A person's message that reached the wrong sandbox, offered to the one it was meant for (account-routing.md, 2026-11-25).
246
- // The words are the daemon's copy of what the person opened a turn with, never the agent's retelling, and only that
247
- // person can press it: their editor, signed in to both, opens a chat in the target and sends the words there as they
248
- // would by hand. No pass and no pairing travel. The platform only found the target among the sandboxes they are in.
249
- export const REDIRECT_WORDS_MAX = 20_000;
250
- export const RedirectNeedSchema = z.object({
251
- kind: z.literal("redirect"),
252
- target: z.string().min(1).max(40).describe("The target sandbox's tunnel id."),
253
- targetName: z.string().max(120).describe("Its name, as the platform gave it."),
254
- address: z.string().max(400).optional().describe("The target's address, as the platform gave it, which the card finds it by."),
255
- person: z.string().min(1).max(254).describe("Whose words they are, and the only one who can send them on."),
256
- words: z.string().max(REDIRECT_WORDS_MAX).describe("The message, exactly as the person sent it here."),
257
- clipped: z.boolean().optional().describe("The message was longer than the card carries, so only its head goes."),
258
- attachments: z.number().int().min(0).optional().describe("How many files went with it, which stay here."),
259
- project: z.string().max(400).optional().describe("The project the target was found by, when it was found by its claim."),
260
- });
261
- export type RedirectNeed = z.infer<typeof RedirectNeedSchema>;
262
-
263
248
  export const NeedSubjectSchema = z
264
249
  .discriminatedUnion("kind", [
265
250
  CapabilityNeedSchema,
@@ -275,6 +260,7 @@ export const NeedSubjectSchema = z
275
260
  RouteNeedSchema,
276
261
  RedirectNeedSchema,
277
262
  DeployNeedSchema,
263
+ ContactNeedSchema,
278
264
  ])
279
265
  .describe("What exactly is asked for.");
280
266
  export type NeedSubject = z.infer<typeof NeedSubjectSchema>;
@@ -357,6 +343,7 @@ export const NeedAskSchema = z.discriminatedUnion("kind", [
357
343
  project: z.string().trim().min(1).max(400).optional().describe("Or the project it is about: the sandbox claiming it is the target."),
358
344
  }),
359
345
  DeployNeedAskSchema,
346
+ ContactNeedAskSchema,
360
347
  ]);
361
348
  export type NeedAsk = z.infer<typeof NeedAskSchema>;
362
349
 
@@ -0,0 +1,19 @@
1
+ import { z } from "zod";
2
+
3
+ // A person's message that reached the wrong sandbox, offered to the one it was meant for (account-routing.md, 2026-11-25).
4
+ // The words are the daemon's copy of what the person opened a turn with, never the agent's retelling, and only that
5
+ // person can press it: their editor, signed in to both, opens a chat in the target and sends the words there as they
6
+ // would by hand. No pass and no pairing travel. The platform only found the target among the sandboxes they are in.
7
+ export const REDIRECT_WORDS_MAX = 20_000;
8
+ export const RedirectNeedSchema = z.object({
9
+ kind: z.literal("redirect"),
10
+ target: z.string().min(1).max(40).describe("The target sandbox's tunnel id."),
11
+ targetName: z.string().max(120).describe("Its name, as the platform gave it."),
12
+ address: z.string().max(400).optional().describe("The target's address, as the platform gave it, which the card finds it by."),
13
+ person: z.string().min(1).max(254).describe("Whose words they are, and the only one who can send them on."),
14
+ words: z.string().max(REDIRECT_WORDS_MAX).describe("The message, exactly as the person sent it here."),
15
+ clipped: z.boolean().optional().describe("The message was longer than the card carries, so only its head goes."),
16
+ attachments: z.number().int().min(0).optional().describe("How many files went with it, which stay here."),
17
+ project: z.string().max(400).optional().describe("The project the target was found by, when it was found by its claim."),
18
+ });
19
+ export type RedirectNeed = z.infer<typeof RedirectNeedSchema>;