@cotal-ai/workspace 0.136.8 → 0.138.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 (49) hide show
  1. package/build/Release/darwin-arm64/build.json +1 -1
  2. package/build/Release/darwin-x64/build.json +1 -1
  3. package/build/Release/win32-arm64/build.json +1 -1
  4. package/build/Release/win32-x64/build.json +1 -1
  5. package/dist/attach/attach-client.d.ts +120 -0
  6. package/dist/attach/attach-client.d.ts.map +1 -0
  7. package/dist/attach/attach-client.js +525 -0
  8. package/dist/attach/attach-client.js.map +1 -0
  9. package/dist/attach/attach-seat.d.ts +174 -0
  10. package/dist/attach/attach-seat.d.ts.map +1 -0
  11. package/dist/attach/attach-seat.js +732 -0
  12. package/dist/attach/attach-seat.js.map +1 -0
  13. package/dist/attach/index.d.ts +3 -0
  14. package/dist/attach/index.d.ts.map +1 -0
  15. package/dist/attach/index.js +3 -0
  16. package/dist/attach/index.js.map +1 -0
  17. package/dist/chat/admission.d.ts +34 -0
  18. package/dist/chat/admission.d.ts.map +1 -0
  19. package/dist/chat/admission.js +18 -0
  20. package/dist/chat/admission.js.map +1 -0
  21. package/dist/chat/engine.d.ts +111 -0
  22. package/dist/chat/engine.d.ts.map +1 -0
  23. package/dist/chat/engine.js +225 -0
  24. package/dist/chat/engine.js.map +1 -0
  25. package/dist/chat/index.d.ts +8 -0
  26. package/dist/chat/index.d.ts.map +1 -0
  27. package/dist/chat/index.js +8 -0
  28. package/dist/chat/index.js.map +1 -0
  29. package/dist/chat/native-session.d.ts +120 -0
  30. package/dist/chat/native-session.d.ts.map +1 -0
  31. package/dist/chat/native-session.js +487 -0
  32. package/dist/chat/native-session.js.map +1 -0
  33. package/dist/chat/open-session.d.ts +9 -0
  34. package/dist/chat/open-session.d.ts.map +1 -0
  35. package/dist/chat/open-session.js +120 -0
  36. package/dist/chat/open-session.js.map +1 -0
  37. package/dist/chat/session.d.ts +230 -0
  38. package/dist/chat/session.d.ts.map +1 -0
  39. package/dist/chat/session.js +2 -0
  40. package/dist/chat/session.js.map +1 -0
  41. package/dist/chat/static-session.d.ts +63 -0
  42. package/dist/chat/static-session.d.ts.map +1 -0
  43. package/dist/chat/static-session.js +237 -0
  44. package/dist/chat/static-session.js.map +1 -0
  45. package/dist/chat/user-session.d.ts +22 -0
  46. package/dist/chat/user-session.d.ts.map +1 -0
  47. package/dist/chat/user-session.js +182 -0
  48. package/dist/chat/user-session.js.map +1 -0
  49. package/package.json +12 -4
@@ -0,0 +1,237 @@
1
+ /**
2
+ * The static-mode chat admission adapter. On a static-auth mesh the local manager admits the
3
+ * session (`chat-session-open`): it draws the `chat_` alias and a fresh nkey identity and mints the
4
+ * session's own leaf. This adapter runs one real `CotalEndpoint` under that leaf and ends the
5
+ * session with `chat-session-retire` at the same manager instance that admitted it, on close or at
6
+ * the leaf's expiry. `cotal chat` opens it for a static-auth target.
7
+ *
8
+ * The leaf never crosses the wire in the clear. The adapter sends a one-time curve key as
9
+ * `sealTo`, and the manager seals the leaf to it, bound to the space, the admitting instance and
10
+ * every reply field; a generic invoke, an agent tool or a browser sees only that ciphertext. The
11
+ * adapter opens it once, checks every bound field, keeps the leaf in memory, and never writes it to
12
+ * a file, a receipt, a log or any output record. Its retire path never sees it.
13
+ *
14
+ * The caller resolves the mesh once, into `target`. Every manager call mints its one-shot
15
+ * instrument from a copy of that target's server, TLS requirement and trust material, so a later
16
+ * `cotal use` or registry change cannot move the retirement to another mesh.
17
+ */
18
+ import { CotalEndpoint, DEV_OWNER, EP_UNANSWERED, SealRecipient, assertLifecycleToken, assertValidChannel, idFromCreds, isCurvePublicKey, principalKey, resolveReadAcl, } from "@cotal-ai/core";
19
+ import { isConnectRefusal, mintControlInstrument, preflightOrThrow } from "../connect.js";
20
+ import { askManager, managerFailure, refuseWithoutLiveManager } from "../control/manager.js";
21
+ import { CommandFailure } from "../output.js";
22
+ import { NativeChatSession } from "./native-session.js";
23
+ /** The leaf's whole life. The manager caps `ttl` here and never renews it. */
24
+ export const STATIC_CHAT_TTL_SEC = 900;
25
+ /** How long `chat-session-retire` may take to answer. The manager answers once its static terminal
26
+ * settles, and that terminal waits up to 15 seconds for the delivery daemon's verified eviction so
27
+ * a daemon that is reconnecting can still finish it. The window outlives that wait and the
28
+ * footprint cleanup after a late eviction; a reply that still does not come is reported unknown. */
29
+ const STATIC_CHAT_RETIRE_TIMEOUT_MS = 30_000;
30
+ /** Every key the manager seals and no other, sorted and joined for one comparison. */
31
+ const SEALED_KEYS = ["v", "space", "managerInstanceId", "alias", "actor", "lifecycleUid", "expiresAt", "sealTo", "creds"].sort().join();
32
+ /** Open and check one `chat-session-open` reply. The outer reply must have its contract shape;
33
+ * the sealed payload must open with `recipient`, which it uses up, must carry exactly the sealed
34
+ * keys, and must bind the expected space and responding instance, this recipient's own key and
35
+ * the outer alias, actor, uid and expiry; and its credential must be the identity it names.
36
+ * Undefined when any part does not hold; the caller never uses a reply that fails here. */
37
+ export function readAdmission(data, recipient, expected) {
38
+ const sealTo = recipient.publicKey;
39
+ // A reply refused before the open still uses the key up, so it never opens a later one.
40
+ const refuse = () => {
41
+ recipient.clear();
42
+ return undefined;
43
+ };
44
+ if (typeof data !== "object" || data === null)
45
+ return refuse();
46
+ const d = data;
47
+ if (typeof d.alias !== "string" || !/^chat_[a-z2-7]{26}$/.test(d.alias))
48
+ return refuse();
49
+ if (typeof d.actor !== "string" || typeof d.lifecycleUid !== "string" || typeof d.sealed !== "string")
50
+ return refuse();
51
+ if (typeof d.sealer !== "string" || !isCurvePublicKey(d.sealer))
52
+ return refuse();
53
+ if (typeof d.expiresAt !== "number" || !Number.isSafeInteger(d.expiresAt))
54
+ return refuse();
55
+ if ("creds" in d)
56
+ return refuse();
57
+ const opened = recipient.openJson(d.sealed, d.sealer);
58
+ if (typeof opened !== "object" || opened === null)
59
+ return undefined;
60
+ const p = opened;
61
+ if (Object.keys(p).sort().join() !== SEALED_KEYS)
62
+ return undefined;
63
+ if (p.v !== 1 || p.space !== expected.space || p.managerInstanceId !== expected.managerInstanceId || p.sealTo !== sealTo)
64
+ return undefined;
65
+ if (p.alias !== d.alias || p.actor !== d.actor || p.lifecycleUid !== d.lifecycleUid || p.expiresAt !== d.expiresAt)
66
+ return undefined;
67
+ if (typeof p.creds !== "string")
68
+ return undefined;
69
+ try {
70
+ assertLifecycleToken(d.lifecycleUid);
71
+ principalKey(DEV_OWNER, d.actor);
72
+ if (idFromCreds(p.creds) !== d.actor)
73
+ return undefined;
74
+ }
75
+ catch {
76
+ return undefined;
77
+ }
78
+ return { alias: d.alias, actor: d.actor, lifecycleUid: d.lifecycleUid, creds: p.creds, expiresAt: d.expiresAt };
79
+ }
80
+ /** The close report for a `chat-session-retire` reply. The adapter asks only after its own
81
+ * endpoint stopped, so `connectionClosed` is that observed stop, and `NativeChatSession`
82
+ * downgrades it when the stop failed. The retirement outcome is reported apart from it and never
83
+ * changes it. A static mesh has no broker-side revocation, so no outcome here ends the leaf at
84
+ * the broker: a copy of it still authenticates until `validUntil`. */
85
+ export function retireReport(reply, managerInstanceId, validUntil) {
86
+ const base = { connectionClosed: "confirmed", credentialValidUntil: validUntil };
87
+ const valid = `The broker accepts the session's credential until ${new Date(validUntil).toISOString()}; a static mesh cannot revoke it sooner.`;
88
+ if (!reply.ok) {
89
+ const failure = managerFailure(reply, "chat-session-retire", null);
90
+ return failure.outcome === "refused"
91
+ ? { ...base, retirement: "requested", message: `Manager ${managerInstanceId} refused the retirement; the session is not retired: ${reply.error ?? failure.message}. ${valid}` }
92
+ : { ...base, retirement: "unknown", message: `${failure.message}. The session may still be admitted at manager ${managerInstanceId}. ${valid}` };
93
+ }
94
+ const data = reply.data;
95
+ if (data?.outcome === "retired")
96
+ return { ...base, retirement: "retired", message: `Static session retired at manager ${managerInstanceId}: its slot is retired, its credential row is marked revoked, and its principal had no broker connection left when it retired. ${valid}` };
97
+ if (data?.outcome === "alreadyRetired")
98
+ return { ...base, retirement: "retired", message: `Static session was already retired at manager ${managerInstanceId}. ${valid}` };
99
+ if (data?.outcome === "failed")
100
+ return { ...base, retirement: "requested", message: `Manager ${managerInstanceId} did not finish the retirement: ${typeof data.reason === "string" ? data.reason : "retirement pending"}. ${valid}` };
101
+ return { ...base, retirement: "unknown", message: `Manager ${managerInstanceId} answered the retirement without a recognized outcome. ${valid}` };
102
+ }
103
+ /** Ask the pinned mesh's manager `op` under a fresh one-shot instrument minted from the pinned
104
+ * trust material. When the mint or the dial throws, nothing reached the manager, and a read-only
105
+ * preflight of the same target classifies the cause as `connectOrThrow` does; it prunes nothing.
106
+ * With `purpose`, an unpinned call on a space whose registry lists no live manager is refused
107
+ * before `op` is sent, as the run verbs refuse it, rather than after it has waited out its deadline.
108
+ * `timeoutMs` is the reply window for `op` itself; absent, it is `askManager`'s default. */
109
+ async function askPinned(control, mesh, op, args, instanceId, purpose, timeoutMs) {
110
+ try {
111
+ const auth = { ...await mintControlInstrument(mesh, "privileged", instanceId), tls: mesh.tlsRequired };
112
+ if (purpose !== undefined && instanceId === undefined)
113
+ await refuseWithoutLiveManager(mesh.space, mesh.server, auth, { space: mesh.space }, purpose);
114
+ return await askManager(control, mesh.space, mesh.server, op, args, auth, "owner", timeoutMs, instanceId !== undefined ? { instanceId } : undefined);
115
+ }
116
+ catch (e) {
117
+ if (e instanceof CommandFailure)
118
+ throw e;
119
+ await preflightOrThrow(mesh, undefined, true);
120
+ throw e;
121
+ }
122
+ }
123
+ /** Open one static chat session on `target`, which the caller resolved once. The three lists are
124
+ * a spawn's, under its rules: `subscribe` the initial channels, `allowSubscribe` the read ceiling
125
+ * (empty means `subscribe`), `allowPublish` the post list (empty means none). `instanceId`
126
+ * (`--on`) chooses the admitting manager; retirement always goes to the instance that answered
127
+ * the open. `control` asks the manager both at the open and at the retirement. */
128
+ export async function openStaticChatSession(target, options) {
129
+ if (target.mode !== "auth" || !target.auth)
130
+ throw new CommandFailure("refused", "UNSUPPORTED", "the static chat adapter requires a recorded static-auth target with its trust material; no other admission was attempted", { target: { space: target.space } });
131
+ const subscribe = [...(options.subscribe ?? [])];
132
+ const allowPublish = [...(options.allowPublish ?? [])];
133
+ let allowSubscribe;
134
+ try {
135
+ if (!options.label || options.label.length > 128)
136
+ throw new Error("the label must be 1 to 128 characters");
137
+ for (const channel of [...subscribe, ...(options.allowSubscribe ?? []), ...allowPublish])
138
+ assertValidChannel(channel);
139
+ allowSubscribe = resolveReadAcl(subscribe, [...(options.allowSubscribe ?? [])]);
140
+ }
141
+ catch (e) {
142
+ throw new CommandFailure("refused", "USAGE_INVALID", `chat could not be opened: ${e.message}`);
143
+ }
144
+ const mesh = Object.freeze({ ...target, auth: target.auth });
145
+ const control = options.control;
146
+ // The one-time key the leaf is sealed to. Its private half stays in this object and is cleared
147
+ // once the reply is opened or the open fails.
148
+ const recipient = new SealRecipient();
149
+ let reply;
150
+ try {
151
+ reply = await askPinned(control, mesh, "chatSessionOpen", {
152
+ subscribe, allowSubscribe: [...(options.allowSubscribe ?? [])], allowPublish, label: options.label, ttl: STATIC_CHAT_TTL_SEC, sealTo: recipient.publicKey,
153
+ }, options.instanceId, "admit a chat session");
154
+ }
155
+ catch (e) {
156
+ recipient.clear();
157
+ if (e instanceof CommandFailure)
158
+ throw e;
159
+ if (isConnectRefusal(e))
160
+ throw e.failure();
161
+ throw new CommandFailure("refused", "DEPENDENCY_UNAVAILABLE", `the control instrument could not be minted or connected, so chat-session-open was not sent: ${e.message}`, { target: { space: mesh.space } });
162
+ }
163
+ if (!reply.ok) {
164
+ recipient.clear();
165
+ // A describe that drew no answer means chat-session-open was never sent, so this is a refusal,
166
+ // as the run verbs give it, and not an unknown outcome.
167
+ if (reply.details?.some((detail) => detail.kind === EP_UNANSWERED && detail.command === "describe"))
168
+ throw new CommandFailure("refused", "TARGET_UNAVAILABLE", `chat-session-open was not sent: ${reply.error}`, {
169
+ target: { space: mesh.space },
170
+ native: { code: reply.code },
171
+ remedy: "cotal status shows whether this space's manager answers; a stack manager that runs but does not answer is named there with its pid and the way to end it",
172
+ });
173
+ throw managerFailure(reply, "chat-session-open", { space: mesh.space });
174
+ }
175
+ const managerInstanceId = reply.managerInstanceId;
176
+ const admission = managerInstanceId === undefined ? undefined : readAdmission(reply.data, recipient, { space: mesh.space, managerInstanceId });
177
+ if (admission === undefined || managerInstanceId === undefined) {
178
+ recipient.clear();
179
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the manager answered chat-session-open with a reply this CLI could not open or verify; the session was not used and could not be retired from here", {
180
+ target: { space: mesh.space },
181
+ native: { outcome: "unknown", detail: { managerInstanceId: managerInstanceId ?? null } },
182
+ remedy: "list the manager's slots with `cotal ps --slots`; the admitting manager retires an unretired chat_ slot at its expiry, at its stop, or at its next start",
183
+ });
184
+ }
185
+ // The retire path never sees the credential bytes.
186
+ const { creds, ...slot } = admission;
187
+ const identity = {
188
+ mode: "static", space: mesh.space, principal: principalKey(DEV_OWNER, slot.actor).key, lifecycleUid: slot.lifecycleUid, label: options.label,
189
+ allowSubscribe, allowPublish, expiresAt: slot.expiresAt,
190
+ };
191
+ const retire = async () => {
192
+ let answer;
193
+ try {
194
+ answer = await askPinned(control, mesh, "chatSessionRetire", { alias: slot.alias, actor: slot.actor, lifecycleUid: slot.lifecycleUid }, managerInstanceId, undefined, STATIC_CHAT_RETIRE_TIMEOUT_MS);
195
+ }
196
+ catch (e) {
197
+ const cause = isConnectRefusal(e) ? e.failure().message : e.message;
198
+ return { retirement: "unknown", connectionClosed: "confirmed", credentialValidUntil: slot.expiresAt, message: `The retire request was not sent to manager ${managerInstanceId}: ${cause}. That manager retires the session at its expiry or its stop if it is still running.` };
199
+ }
200
+ return retireReport(answer, managerInstanceId, slot.expiresAt);
201
+ };
202
+ const endpoint = new CotalEndpoint({
203
+ space: mesh.space,
204
+ servers: mesh.server,
205
+ tls: mesh.tlsRequired,
206
+ creds,
207
+ card: { owner: DEV_OWNER, actor: slot.actor, name: options.label, kind: "endpoint", meta: { sessionKind: "chat" } },
208
+ lifecycleUid: slot.lifecycleUid,
209
+ // A copy: the endpoint edits its list on /leave and /join, and the read grant may be this array.
210
+ channels: [...subscribe],
211
+ });
212
+ // The participant listeners are installed here, before the endpoint starts.
213
+ const session = new NativeChatSession({ endpoint, identity, retire, reopen: options.reopen });
214
+ if (slot.expiresAt <= Date.now()) {
215
+ const close = await session.close();
216
+ throw new CommandFailure("failed", "OPERATION_FAILED", "the admitted session had already expired when its reply arrived, so it was closed without connecting", {
217
+ target: { space: mesh.space, principal: identity.principal, lifecycleUid: slot.lifecycleUid },
218
+ native: { detail: { close } },
219
+ });
220
+ }
221
+ try {
222
+ await endpoint.start();
223
+ // The leaf is never renewed, so the session ends at its expiry. Closing is memoized, so an
224
+ // earlier close by the front end makes this a no-op.
225
+ setTimeout(() => void session.close(), Math.max(0, slot.expiresAt - Date.now())).unref();
226
+ return session;
227
+ }
228
+ catch {
229
+ const close = await session.close();
230
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", "the static chat opening did not finish; no automatic retry was made", {
231
+ target: { space: mesh.space, principal: identity.principal, lifecycleUid: slot.lifecycleUid },
232
+ native: { outcome: "unknown", detail: { close } },
233
+ remedy: "the close report in the error cause says whether the session was retired; the admitting manager retires an unretired chat_ slot at its expiry, at its stop, or at its next start",
234
+ });
235
+ }
236
+ }
237
+ //# sourceMappingURL=static-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-session.js","sourceRoot":"","sources":["../../src/chat/static-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EACL,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,WAAW,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,GAE9J,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,wBAAwB,EAAyC,MAAM,uBA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AC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;QACzF,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,mBAAmB,EAAE,qEAAqE,EAAE;YAC9H,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,CAAC,YAAY,EAAE;YAC7F,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;YACjD,MAAM,EAAE,kLAAkL;SAC3L,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { MeshTarget } from "../mesh-target.js";
2
+ import { NativeChatSession } from "./native-session.js";
3
+ /**
4
+ * User mode: each opening is its own principal `<owner>.chat_<…>` at a fresh lifecycle UID, which the
5
+ * space's auth service draws and admits under the signed-in human's own `cli` grant, confined to the
6
+ * given read and post lists and to `ttlSec`. No `cli`, managed or other borrowed identity connects.
7
+ *
8
+ * The holder secret lives in this process's memory only: admission receives its SHA-256, and each
9
+ * bearer exchange and the retirement present the secret itself. No bearer, sentinel or holder secret
10
+ * is returned, printed or written. Mode, server, TLS and space come from the one resolved target,
11
+ * and the open names that target's IdP and exchange position so the provider cannot follow a
12
+ * re-registered entry; the session's later requests reuse the route its open resolved.
13
+ */
14
+ export declare function openUserChatSession(target: MeshTarget, options: {
15
+ readonly label: string;
16
+ readonly channels: readonly string[];
17
+ readonly read: readonly string[];
18
+ readonly post: readonly string[];
19
+ readonly ttlSec: number;
20
+ readonly reopen: (channel: string) => string;
21
+ }): Promise<NativeChatSession>;
22
+ //# sourceMappingURL=user-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-session.d.ts","sourceRoot":"","sources":["../../src/chat/user-session.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AA8CxD;;;;;;;;;;GAUG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE;IACrE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CAC9C,GAAG,OAAO,CAAC,iBAAiB,CAAC,CA0H7B"}
@@ -0,0 +1,182 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { CotalEndpoint, EpEnvelopeError, channelInAllow, isConcreteChannel, registry, } from "@cotal-ai/core";
3
+ import { userAuthStateDir } from "../auth-paths.js";
4
+ import { CommandFailure } from "../output.js";
5
+ import { workspaceSecretStore } from "../secret-store-fs.js";
6
+ import { NativeChatSession } from "./native-session.js";
7
+ /** Native refusal codes the auth service answers before any effect. */
8
+ const REFUSED = {
9
+ "bad-request": "USAGE_INVALID",
10
+ "unauthenticated": "AUTH_REQUIRED",
11
+ "permission-denied": "PERMISSION_DENIED",
12
+ "not-found": "TARGET_NOT_FOUND",
13
+ "failed-precondition": "LIFECYCLE_BLOCKED",
14
+ "unimplemented": "UNSUPPORTED",
15
+ "unavailable": "TARGET_UNAVAILABLE",
16
+ "conflict": "CONFLICT",
17
+ "resource-exhausted": "TARGET_UNAVAILABLE",
18
+ };
19
+ /** A provider failure as the command's outcome, by the effect outcome the service stated: a
20
+ * `not-executed` refusal keeps its code, an `executed` one failed after writing, and anything else
21
+ * is unknown and never retried here. A plain provider error was raised before the request left this
22
+ * machine (sign-in, discovery, transport setup). */
23
+ function providerFailure(e, target) {
24
+ const message = e instanceof Error ? e.message : String(e);
25
+ if (e instanceof EpEnvelopeError) {
26
+ const native = { code: e.code, outcome: e.outcome ?? "unknown" };
27
+ if (e.outcome === "not-executed")
28
+ return new CommandFailure("refused", REFUSED[e.code] ?? "DEPENDENCY_UNAVAILABLE", message, { target, native });
29
+ if (e.outcome === "executed")
30
+ return new CommandFailure("failed", "OPERATION_FAILED", message, { target, native });
31
+ return new CommandFailure("unknown", "OPERATION_UNKNOWN", message, {
32
+ target,
33
+ native,
34
+ remedy: "no automatic retry was made; an admission that landed without an answer is reclaimed by the auth service's sweep",
35
+ });
36
+ }
37
+ const credential = e?.code;
38
+ return new CommandFailure("refused", credential === "signed-out" ? "AUTH_REQUIRED" : credential === "refused" ? "PERMISSION_DENIED" : "DEPENDENCY_UNAVAILABLE", message, { target });
39
+ }
40
+ /** The principal a minted bearer names, read without verification (the broker verifies). */
41
+ function bearerPrincipal(bearer) {
42
+ const payload = JSON.parse(Buffer.from(bearer.split(".")[1] ?? "", "base64url").toString("utf8"));
43
+ if (typeof payload.sub !== "string" || typeof payload.act?.actor !== "string" || typeof payload.act.lifecycleUid !== "string")
44
+ throw new Error("the chat bearer does not name a principal and lifecycle");
45
+ return { owner: payload.sub, actor: payload.act.actor, lifecycleUid: payload.act.lifecycleUid };
46
+ }
47
+ /**
48
+ * User mode: each opening is its own principal `<owner>.chat_<…>` at a fresh lifecycle UID, which the
49
+ * space's auth service draws and admits under the signed-in human's own `cli` grant, confined to the
50
+ * given read and post lists and to `ttlSec`. No `cli`, managed or other borrowed identity connects.
51
+ *
52
+ * The holder secret lives in this process's memory only: admission receives its SHA-256, and each
53
+ * bearer exchange and the retirement present the secret itself. No bearer, sentinel or holder secret
54
+ * is returned, printed or written. Mode, server, TLS and space come from the one resolved target,
55
+ * and the open names that target's IdP and exchange position so the provider cannot follow a
56
+ * re-registered entry; the session's later requests reuse the route its open resolved.
57
+ */
58
+ export async function openUserChatSession(target, options) {
59
+ const space = target.space;
60
+ if (target.mode !== "user" || target.userAuth === undefined)
61
+ throw new CommandFailure("refused", "UNSUPPORTED", "the user-mode chat adapter requires a recorded user-auth target; no other authentication was attempted", { target: { space } });
62
+ if (!options.label || options.label.length > 128 || options.channels.some((channel) => !isConcreteChannel(channel)))
63
+ throw new CommandFailure("refused", "USAGE_INVALID", "chat requires a label of 1 to 128 characters and concrete initial channels");
64
+ if (options.channels.some((channel) => !channelInAllow([...options.read], channel)))
65
+ throw new CommandFailure("refused", "USAGE_INVALID", "every initial channel must sit within the session's read list");
66
+ if (!Number.isSafeInteger(options.ttlSec) || options.ttlSec <= 0)
67
+ throw new CommandFailure("refused", "USAGE_INVALID", "a chat session lifetime is a positive whole number of seconds");
68
+ const userAuth = target.userAuth;
69
+ const providerName = userAuth.provider;
70
+ let provider;
71
+ try {
72
+ provider = registry.resolve("auth-provider", providerName);
73
+ }
74
+ catch {
75
+ throw new CommandFailure("refused", "UNSUPPORTED", `space "${space}" uses the "${providerName}" auth provider, which this build does not register`, { target: { space } });
76
+ }
77
+ const openChat = provider.openChatSession?.bind(provider);
78
+ const bearerFor = provider.chatSessionBearer?.bind(provider);
79
+ const retireChat = provider.retireChatSession?.bind(provider);
80
+ if (!openChat || !bearerFor || !retireChat)
81
+ throw new CommandFailure("refused", "UNSUPPORTED", `the "${providerName}" auth provider cannot serve user-mode chat; no other identity or auth mode was tried`, { target: { space } });
82
+ const auth = { store: workspaceSecretStore(target.root), dir: userAuthStateDir(target.root, space), space };
83
+ const holderProof = randomBytes(32).toString("base64url");
84
+ const holderHash = createHash("sha256").update(holderProof, "utf8").digest("hex");
85
+ let opened;
86
+ try {
87
+ // The provider refuses before sending anything when its own resolution is not this target's.
88
+ const exchangeUrl = userAuth.remote === true ? userAuth.endpoints?.url : undefined;
89
+ const expect = { idpUrl: userAuth.idp.url, ...(exchangeUrl !== undefined ? { exchangeUrl } : {}) };
90
+ opened = await openChat({ ...auth, holderHash, label: options.label, read: [...options.read], post: [...options.post], ttlSec: options.ttlSec, expect });
91
+ }
92
+ catch (e) {
93
+ throw providerFailure(e, { space });
94
+ }
95
+ const { actor, lifecycleUid } = opened;
96
+ const expiresAtMs = opened.expiresAt * 1000;
97
+ // The last bearer this process received: it stays broker-valid until its expiry unless the
98
+ // retirement's eviction completes.
99
+ let credentialValidUntil = 0;
100
+ let expiry;
101
+ const validUntil = () => (credentialValidUntil > 0 ? { credentialValidUntil } : {});
102
+ const retire = async () => {
103
+ clearTimeout(expiry);
104
+ try {
105
+ const r = await retireChat({ ...auth, actor, lifecycleUid, holderProof });
106
+ if (r.outcome === "failed")
107
+ return { retirement: "requested", connectionClosed: "not-confirmed", ...validUntil(), message: `Chat session retirement is pending: ${r.pending ?? "the authority gave no reason"}. Its last bearer stays usable until its expiry unless eviction completes.` };
108
+ const what = r.outcome === "alreadyRetired" ? "was already retired" : r.outcome === "notStarted" ? "had nothing left to retire" : "retired";
109
+ return { retirement: "retired", connectionClosed: "confirmed", message: `Chat session ${what}; its connections were evicted and no bearer can be minted for it.` };
110
+ }
111
+ catch (e) {
112
+ const unknown = !(e instanceof EpEnvelopeError) || (e.outcome !== "not-executed" && e.outcome !== "executed");
113
+ return {
114
+ retirement: unknown ? "unknown" : "requested",
115
+ connectionClosed: "not-confirmed",
116
+ ...validUntil(),
117
+ message: `Chat session retirement was not confirmed (${e instanceof Error ? e.message : String(e)}). The auth service retires it at its expiry; its last bearer stays usable until then unless evicted.`,
118
+ };
119
+ }
120
+ };
121
+ let first;
122
+ let owner;
123
+ try {
124
+ first = await bearerFor({ ...auth, actor, holderProof });
125
+ const principal = bearerPrincipal(first.bearer);
126
+ if (principal.actor !== actor || principal.lifecycleUid !== lifecycleUid)
127
+ throw new Error("the chat bearer names another session than the one admitted");
128
+ owner = principal.owner;
129
+ }
130
+ catch (e) {
131
+ const close = await retire();
132
+ const f = providerFailure(e, { space, actor, lifecycleUid });
133
+ throw new CommandFailure(f.outcome, f.code, f.message, { target: { space, actor, lifecycleUid }, native: { ...(f.native ?? {}), detail: { close } }, ...(f.remedy ? { remedy: f.remedy } : {}) });
134
+ }
135
+ credentialValidUntil = first.exp * 1000;
136
+ let prefetched = first.bearer;
137
+ // Each renewal is a fresh holder-proof exchange; the service re-checks the parent pin and the
138
+ // holder index for every one, and refuses once the session has expired or been retired.
139
+ const bearerSource = async () => {
140
+ if (prefetched !== undefined) {
141
+ const bearer = prefetched;
142
+ prefetched = undefined;
143
+ return bearer;
144
+ }
145
+ const next = await bearerFor({ ...auth, actor, holderProof });
146
+ credentialValidUntil = Math.max(credentialValidUntil, next.exp * 1000);
147
+ return next.bearer;
148
+ };
149
+ const endpoint = new CotalEndpoint({
150
+ space,
151
+ servers: target.server,
152
+ tls: target.tlsRequired,
153
+ card: { owner, actor, name: options.label, kind: "endpoint", meta: { sessionKind: "chat" } },
154
+ lifecycleUid,
155
+ channels: [...options.channels],
156
+ bearer: bearerSource,
157
+ sentinelCreds: first.sentinelCreds,
158
+ });
159
+ const identity = {
160
+ mode: "user", space, principal: `${owner}.${actor}`, lifecycleUid, label: options.label,
161
+ allowSubscribe: [...options.read], allowPublish: [...options.post], expiresAt: expiresAtMs,
162
+ };
163
+ // Register the participant listeners before the endpoint starts; the session owns them until close.
164
+ const session = new NativeChatSession({ endpoint, identity, retire, reopen: options.reopen });
165
+ try {
166
+ await endpoint.start();
167
+ }
168
+ catch (e) {
169
+ const close = await session.close();
170
+ throw new CommandFailure("unknown", "OPERATION_UNKNOWN", `the user-mode chat session was admitted but did not connect (${e instanceof Error ? e.message : String(e)}); no automatic retry was made`, {
171
+ target: { space, principal: identity.principal, lifecycleUid },
172
+ native: { outcome: "unknown", detail: { close } },
173
+ remedy: "open a new session; this one was asked to retire",
174
+ });
175
+ }
176
+ // The session ends at its admitted expiry: the authority refuses every later bearer, so close
177
+ // here rather than let the connection lapse silently.
178
+ expiry = setTimeout(() => void session.close(), Math.max(0, expiresAtMs - Date.now()));
179
+ expiry.unref?.();
180
+ return session;
181
+ }
182
+ //# sourceMappingURL=user-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-session.js","sourceRoot":"","sources":["../../src/chat/user-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EACL,aAAa,EACb,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,QAAQ,GAGT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAoB,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,uEAAuE;AACvE,MAAM,OAAO,GAA0C;IACrD,aAAa,EAAE,eAAe;IAC9B,iBAAiB,EAAE,eAAe;IAClC,mBAAmB,EAAE,mBAAmB;IACxC,WAAW,EAAE,kBAAkB;IAC/B,qBAAqB,EAAE,mBAAmB;IAC1C,eAAe,EAAE,aAAa;IAC9B,aAAa,EAAE,oBAAoB;IACnC,UAAU,EAAE,UAAU;IACtB,oBAAoB,EAAE,oBAAoB;CAC3C,CAAC;AAEF;;;qDAGqD;AACrD,SAAS,eAAe,CAAC,CAAU,EAAE,MAAe;IAClD,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,IAAI,CAAC,YAAY,eAAe,EAAE,CAAC;QAC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AO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC9F,IAAI,CAAC;QACH,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,IAAI,cAAc,CAAC,SAAS,EAAE,mBAAmB,EAAE,gEAAgE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,gCAAgC,EAAE;YACnM,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE;YAC9D,MAAM,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE;YACjD,MAAM,EAAE,kDAAkD;SAC3D,CAAC,CAAC;IACL,CAAC;IACD,8FAA8F;IAC9F,sDAAsD;IACtD,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACvF,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;IACjB,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cotal-ai/workspace",
3
- "description": "Cotal machine-local operator and client-surface layer: the ~/.cotal mesh registry, target resolution, preflight, on-disk auth-path I/O, the command-copy renderer, and the live space model (`MeshView`), observer, manager control calls and managed-launch request that terminal surfaces share — operator concerns over a local checkout, kept separate from the wire protocol in @cotal-ai/core.",
4
- "version": "0.136.8",
3
+ "description": "Cotal machine-local operator and client-surface layer: the ~/.cotal mesh registry, target resolution, preflight, on-disk auth-path I/O, the command-copy renderer, and the live space model (`MeshView`), observer, manager control calls, managed-launch request, chat session and terminal attach that terminal surfaces share — operator concerns over a local checkout, kept separate from the wire protocol in @cotal-ai/core.",
4
+ "version": "0.138.0",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -31,10 +31,18 @@
31
31
  "./launch": {
32
32
  "types": "./dist/launch.d.ts",
33
33
  "import": "./dist/launch.js"
34
+ },
35
+ "./chat": {
36
+ "types": "./dist/chat/index.d.ts",
37
+ "import": "./dist/chat/index.js"
38
+ },
39
+ "./attach": {
40
+ "types": "./dist/attach/index.d.ts",
41
+ "import": "./dist/attach/index.js"
34
42
  }
35
43
  },
36
44
  "dependencies": {
37
- "@cotal-ai/core": "0.136.8",
45
+ "@cotal-ai/core": "0.138.0",
38
46
  "@nats-io/jetstream": "^3.4.0",
39
47
  "@nats-io/transport-node": "^3.4.0",
40
48
  "ajv": "^8.20.0",
@@ -58,6 +66,6 @@
58
66
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.smoke.json",
59
67
  "build": "node scripts/build-native.mjs && tsc -p tsconfig.json",
60
68
  "build:native": "node scripts/build-native.mjs",
61
- "test": "tsx smoke/preflight.smoke.ts && tsx smoke/maintenance.smoke.ts && tsx smoke/manager-shutdown.smoke.ts && tsx smoke/console-managed-rows.smoke.ts"
69
+ "test": "tsx smoke/preflight.smoke.ts && tsx smoke/maintenance.smoke.ts && tsx smoke/manager-shutdown.smoke.ts && tsx smoke/console-managed-rows.smoke.ts && tsx smoke/chat-user-session.smoke.ts"
62
70
  }
63
71
  }