@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,174 @@
1
+ import { standaloneConnectOpts, type SpaceAuth } from "@cotal-ai/core";
2
+ import { type ControlClient, type ManagerPin } from "../control/manager.js";
3
+ import { type AttachNotice } from "./attach-client.js";
4
+ /** Race a link round trip against a deadline, and answer `no` if the deadline wins. The timer is
5
+ * deliberately NOT unref'd: it is the only thing keeping the process alive while we wait on a
6
+ * socket that will never answer, and an unref'd one lets node empty its loop and abort the whole
7
+ * command on a pending await instead of finishing the wait and printing why. It is cleared as soon
8
+ * as either side settles, so a healthy link is never held open for the remainder of the deadline. */
9
+ export declare const withDeadline: (work: Promise<boolean>, ms: number) => Promise<boolean>;
10
+ /** What a caller should DO about a manager refusal. `denied` will not change by asking again;
11
+ * `gone` is the seat the manager no longer knows, so there is nothing left to attach to; anything
12
+ * else is worth another attempt. */
13
+ export type AttachRefusal = "denied" | "gone" | "transient";
14
+ /**
15
+ * Classify a refusal on the manager's structured error, never on its wording. The wording is
16
+ * operator copy and changes; the code and namespaced detail are the contract. Getting this wrong in
17
+ * either direction is a real failure: reading `permission-denied` as transient turns a refusal into
18
+ * an infinite retry loop against a manager that has already said no, and reading `not-found` or an
19
+ * `inspect` static-slot observation as transient does the same to a seat that no longer exists.
20
+ * Other `failed-precondition` refusals remain transient, including the session ceiling.
21
+ */
22
+ export declare function attachRefusal(code: string | undefined, details?: Array<{
23
+ kind: string;
24
+ }>): AttachRefusal;
25
+ /**
26
+ * What a re-establishment TELLS the operator while it keeps trying, and what it keeps to itself.
27
+ * Returns the line to print, or undefined for silence.
28
+ *
29
+ * Only the MANAGER's own refusal is relayed, and only when it changes. An operator watching
30
+ * `reconnecting` for ten minutes cannot otherwise tell a sleeping laptop from a manager that is at
31
+ * its session ceiling, and the ceiling is the one a person can act on. Repeating a steady refusal
32
+ * on every attempt would bury it.
33
+ *
34
+ * A LOCAL failure to reach anything is deliberately silent: it is already what `connection lost,
35
+ * reconnecting` says, and the copy on this path is written for someone who just typed a command
36
+ * ("no mesh running at X - run `cotal up`"), which is the wrong thing to tell someone whose wifi
37
+ * dropped.
38
+ */
39
+ export declare function reconnectNotice(est: {
40
+ fromManager?: true;
41
+ message: string;
42
+ }, alreadySaid: string): string | undefined;
43
+ /**
44
+ * The line an exit owes an operator about sessions this attach could not hand back, or nothing.
45
+ *
46
+ * Suppressed on `gone`, and that is not tidiness. That verdict exists only when the manager proves
47
+ * the live seat is absent: either `not-found`, or the namespaced durable static-slot observation
48
+ * after its process is gone. Freeing a seat ends every session bound to it (`freeSlot` into
49
+ * `endForTarget`, on despawn, self-stop, reap and natural exit alike). The sessions this would name
50
+ * have already been collected, so naming them would be inventing work for someone who is about to
51
+ * close their terminal.
52
+ */
53
+ export declare function heldSessionNotice(pending: number, verdict: AttachVerdict["kind"]): string | undefined;
54
+ /** The mesh contract that decides how attach redeems a session grant. The mode is the REGISTERED
55
+ * one (`MeshTarget.mode`), carried forward from the resolve. It is the only input to the decision:
56
+ * `spaceAuth` says whether a SEALED mesh's seed is present, and is never consulted to decide which
57
+ * kind of mesh this is. */
58
+ export type AttachSessionTarget = {
59
+ space: string;
60
+ server: string;
61
+ root?: string;
62
+ spaceAuth?: SpaceAuth;
63
+ mode?: "auth" | "open" | "user";
64
+ auth: {
65
+ bearer?: unknown;
66
+ };
67
+ };
68
+ /**
69
+ * HOW this mesh's session grant is redeemed, as a closed union with no optional credential.
70
+ *
71
+ * `bare` and `session-caller` are structurally distinct rather than "session-caller, but the creds
72
+ * may be missing". That distinction is the whole fix for #1205. An optional `creds?: string` on the
73
+ * redeem path invites exactly one question at every call site — "is the seed there?" — and answering
74
+ * it with `!creds` is the defect: an OPEN mesh has no seed BY DESIGN, so absence means "bare",
75
+ * while on a SEALED mesh the same absence means "refuse". One field cannot carry both meanings, so
76
+ * the mode is named and the compiler makes every consumer read the name.
77
+ */
78
+ export type RedeemLink = {
79
+ mode: "bare";
80
+ tls: boolean;
81
+ } | {
82
+ mode: "session-caller";
83
+ tls: boolean;
84
+ creds: string;
85
+ } | {
86
+ mode: "session-bearer";
87
+ tls: boolean;
88
+ bearer: string;
89
+ sentinelCreds: string;
90
+ };
91
+ /** The ONE place a {@link RedeemLink} becomes NATS connect options. Both connections on the redeem
92
+ * path (the session link and the abandoned-session hand-back) go through here, so neither can
93
+ * invent a credential for an open mesh or drop one on a sealed mesh, and a third caller gets the
94
+ * same two arms for free. */
95
+ export declare function redeemConnectOpts(link: RedeemLink): ReturnType<typeof standaloneConnectOpts>;
96
+ /**
97
+ * Which redeem contract this target gets: a bare open-mesh connection, a seed-backed mint, or a
98
+ * loud refusal. Graded by `smoke:attach-open-mode`, whose mutations flip each arm in turn.
99
+ *
100
+ * EXHAUSTIVE over the three recorded modes on purpose, with `user` named rather than reached by
101
+ * fallthrough. A `user` entry holds no local seed by design and its two-step redemption is not
102
+ * wired, so it must refuse even on the day a user-mode root happens to carry static material on
103
+ * disk; letting it fall through to the seed test would silently mint on the wrong identity plane.
104
+ * An UNRECORDED mode (a raw off-registry connection) is the conservative arm: it is not known to be
105
+ * open, so it takes the sealed test and refuses without a seed.
106
+ */
107
+ export declare function attachSessionMaterial(t: AttachSessionTarget): {
108
+ kind: "bare";
109
+ } | {
110
+ kind: "mint";
111
+ auth: SpaceAuth;
112
+ } | {
113
+ kind: "redeem";
114
+ } | {
115
+ kind: "fatal";
116
+ message: string;
117
+ };
118
+ /** How the attach finished, decided inside the loop and acted on outside it — so the terminal is
119
+ * always given back before anything prints or exits. A failure the manager refused carries that
120
+ * refusal's code and whether it bore the manager's marker that the seat's runtime streams no
121
+ * terminal, so a caller can act on it without reading the wording. */
122
+ export type AttachVerdict = {
123
+ kind: "ended";
124
+ reason: string;
125
+ } | {
126
+ kind: "gone";
127
+ } | {
128
+ kind: "failed";
129
+ message: string;
130
+ refusal?: {
131
+ code?: string;
132
+ noTerminal: boolean;
133
+ };
134
+ };
135
+ /** What an attach needs to know: the mesh coordinates the control commands take, plus the seat.
136
+ * `expectedTarget` pins the incarnation a picker chose; `asSeat` attaches with the launching seat's
137
+ * own caller instead of an operator identity. */
138
+ export type AttachTarget = {
139
+ space?: string;
140
+ server?: string;
141
+ creds?: string;
142
+ name: string;
143
+ expectedTarget?: ManagerPin["expectedTarget"];
144
+ asSeat?: boolean;
145
+ };
146
+ /** What only the caller of an attach knows. `onRefusal` chooses what an unresolvable mesh or an
147
+ * absent seat does on the first attempt: `exit` prints and exits as a command does, `throw` returns
148
+ * a verdict, which a TUI needs because an exit inside it blanks the screen. `verb` is the command a
149
+ * seat-miss refusal names. `noTerminalRemedy` renders the remedy for a seat whose runtime streams no
150
+ * terminal; without it that refusal carries none. `notice` receives every line the attach says while
151
+ * it runs, and defaults to stderr. */
152
+ export interface AttachCaller {
153
+ readonly control: ControlClient;
154
+ readonly onRefusal: "exit" | "throw";
155
+ readonly verb: string;
156
+ readonly noTerminalRemedy?: (seat: {
157
+ space: string;
158
+ name: string;
159
+ }) => string;
160
+ readonly notice?: (notice: AttachNotice) => void;
161
+ }
162
+ /**
163
+ * The whole attach, as one call: seat locality, the establish-redeem-drive loop with its reconnect,
164
+ * end-reason classification and abandoned-session hand-back, and the terminal given back before
165
+ * the verdict is returned. `cotal attach` and the console's `a` / `:attach` both run THIS, so the
166
+ * console can never drift into a lesser attach. The pin `on`, when the caller already knows it, is
167
+ * honoured. Otherwise a `throw` caller has the seat located the way `stop` locates it, and an `exit`
168
+ * caller has already located it in its own words, since that step prints and exits.
169
+ */
170
+ export declare function attachSeat(v: AttachTarget, opts: AttachCaller & {
171
+ reconnect: boolean;
172
+ on?: string;
173
+ }): Promise<AttachVerdict>;
174
+ //# sourceMappingURL=attach-seat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attach-seat.d.ts","sourceRoot":"","sources":["../../src/attach/attach-seat.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,qBAAqB,EAAqB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKvJ,OAAO,EAA8B,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMxG,OAAO,EAA2G,KAAK,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AAenL;;;;sGAIsG;AACtG,eAAO,MAAM,YAAY,GAAU,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,MAAM,KAAG,OAAO,CAAC,OAAO,CAItF,CAAC;AA+BF;;qCAEqC;AACrC,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAY5D;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,CAAC,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAChC,aAAa,CASf;AAuBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE;IAAE,WAAW,CAAC,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGrH;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAIrG;AA2JD;;;4BAG4B;AAC5B,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,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