@cotal-ai/workspace 0.137.0 → 0.138.1

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
@@ -3,7 +3,7 @@
3
3
  "platform": "darwin",
4
4
  "arch": "arm64",
5
5
  "nodeApi": 8,
6
- "source": "9b79c9bb966a4f5d694d098918026086487e8b57",
6
+ "source": "dff59f3dd8cc2e710abc49d1d5a988945e3e906e",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "darwin",
4
4
  "arch": "x64",
5
5
  "nodeApi": 8,
6
- "source": "9b79c9bb966a4f5d694d098918026086487e8b57",
6
+ "source": "dff59f3dd8cc2e710abc49d1d5a988945e3e906e",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "win32",
4
4
  "arch": "arm64",
5
5
  "nodeApi": 8,
6
- "source": "9b79c9bb966a4f5d694d098918026086487e8b57",
6
+ "source": "dff59f3dd8cc2e710abc49d1d5a988945e3e906e",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -3,7 +3,7 @@
3
3
  "platform": "win32",
4
4
  "arch": "x64",
5
5
  "nodeApi": 8,
6
- "source": "9b79c9bb966a4f5d694d098918026086487e8b57",
6
+ "source": "dff59f3dd8cc2e710abc49d1d5a988945e3e906e",
7
7
  "sourceHashes": {
8
8
  "native/win32-process.c": "889b215135b60dd3a45096737a3219ce114bc424e4b6cce42624f0913f8447dc",
9
9
  "native/win32-system-id.cpp": "2dd51f24425e8239aeac1aae01e67f43264f04f09cd9097a12d288be7a84e074",
@@ -0,0 +1,120 @@
1
+ import type { NatsConnection } from "@nats-io/transport-node";
2
+ import { type SessionGrant } from "@cotal-ai/core";
3
+ /**
4
+ * The detach key — Ctrl-] (0x1d) by default, as in telnet/ssh escape conventions. The `detach-key`
5
+ * preference rebinds it to another control key when Ctrl-] clashes with a keybinding inside the
6
+ * agent's TUI: `COTAL_DETACH_KEY`, then the saved preference (`cotal config set detach-key`). Both
7
+ * accept `ctrl-<char>` or `^<char>` (e.g. `ctrl-b`, `^_`). An unparseable `COTAL_DETACH_KEY` —
8
+ * including a set-but-empty or whitespace-only one — throws (named), never silently falling back;
9
+ * the caller turns that into a loud exit. A saved value was validated when it was written.
10
+ */
11
+ export declare function detachKey(): {
12
+ byte: number;
13
+ label: string;
14
+ overridden: boolean;
15
+ from: string;
16
+ };
17
+ /**
18
+ * Whether a whole chunk `d` is exactly one press of the detach key `byte`, in any of three
19
+ * encodings: the legacy single control byte; the kitty keyboard protocol's `CSI <codepoint> ;
20
+ * <mods> u`; or xterm `modifyOtherKeys`'s `CSI 27 ; <mods> ; <codepoint> ~`. `<codepoint>` is the
21
+ * decimal codepoint kitty/xterm report for the unshifted key: `byte | 0x40` for the control
22
+ * punctuation (`@ [ \ ] ^ _`) and `byte | 0x60` for a letter (kitty reports the lowercase key even
23
+ * though Ctrl was held). `<mods>` is 1 + the modifier bitmask and must carry the Ctrl bit
24
+ * (`(mods - 1) & 4`), so plain Ctrl (5) and Ctrl+Shift (6) match but a modifier field without Ctrl
25
+ * does not, and a field of 0, which neither protocol emits, is not a press either (the test needs
26
+ * that floor: `(0 - 1) & 4` is 4 in ToInt32 arithmetic, so 0 would otherwise read as Ctrl). The match is on the WHOLE chunk:
27
+ * a sequence with company (a paste, a second keystroke, a trailing byte) is not a press, which is
28
+ * the same paste-safety property the one-byte test already had. This assumes one press arrives in
29
+ * one read, as measured on a pty (issue #598); a sequence split across two reads is not buffered
30
+ * and is not recognised. A kitty `CSI u` with an alternate-key `<codepoint>:<shifted>:<base>` triple
31
+ * is accepted by matching only the leading codepoint before an optional `:...` group; no other
32
+ * kitty event type (release, repeat) is recognised.
33
+ */
34
+ export declare function isDetachPress(d: Buffer, byte: number): boolean;
35
+ /**
36
+ * A transport-agnostic terminal session. {@link attachClient} drives the terminal through this
37
+ * interface, so the SAME raw-mode / alt-screen / detach handling serves the mesh §13.6 session
38
+ * ({@link meshSessionTransport}). (The legacy loopback `ws://.../attach/` transport was removed with
39
+ * the P2 item 6 no-127.0.0.1 sweep.)
40
+ */
41
+ export interface TerminalTransport {
42
+ /** Fires once the transport is connected and ready to carry the terminal. */
43
+ onReady(cb: () => void): void;
44
+ /** Remote → local: terminal output bytes. The transport awaits an async consumer before returning
45
+ * credit, so a slow local stdout applies real backpressure instead of acknowledging unread bytes. */
46
+ onData(cb: (bytes: Buffer) => void | Promise<void>): void;
47
+ /** The session ended: `err` on a transport error (rejects), else a clean detach/close (resolves),
48
+ * with the peer's distinct end `reason` when it sent one. */
49
+ onEnd(cb: (err?: Error, reason?: string) => void): void;
50
+ /** Local → remote: keystroke bytes. */
51
+ send(bytes: Buffer): void;
52
+ /** Local → remote: terminal resize. */
53
+ resize(cols: number, rows: number): void;
54
+ /** Detach: signal the remote and stop locally. */
55
+ close(): void;
56
+ }
57
+ /**
58
+ * The operator's terminal, held ACROSS attach attempts. A reconnect re-establishes the SESSION,
59
+ * not the terminal: restoring raw mode and leaving the child's alternate screen between attempts
60
+ * would flash the shell's screen back and then repaint over it, which is exactly the garble the
61
+ * reconnect is supposed to spare the operator. So the two facts that outlive one session — the
62
+ * mode the terminal was in before we touched it, and whether the child has us in its alternate
63
+ * screen — live here, and the undo runs exactly once, when the attach really ends.
64
+ *
65
+ * `attachClient` creates its own when no hold is passed, which is the one-shot behaviour: enter on
66
+ * ready, undo on end.
67
+ */
68
+ export interface TerminalHold {
69
+ /** Raw mode on, remembering what we found. Idempotent across reconnects. */
70
+ enterRaw(): void;
71
+ /** Is the child in its alternate screen right now? Carried across reconnects so the final undo
72
+ * leaves that buffer exactly when the child put us there. */
73
+ altScreen: boolean;
74
+ /** Undo every mode we changed, leave the alternate screen if the child put us there, and give
75
+ * the terminal back the raw mode it had. Idempotent. */
76
+ restore(): void;
77
+ }
78
+ export declare function holdTerminal(): TerminalHold;
79
+ /**
80
+ * Why a session ended, as {@link attachClient} resolves it. The reason is the peer's distinct `end`
81
+ * reason, the transport's own (`detached`, `peer-closed`, `connection-closed`), or the broken
82
+ * rail's protocol-fault name. `error` is set when the end was a fault rather than a clean close;
83
+ * it is DATA here rather than a rejection, because a caller that reconnects has to read the reason
84
+ * to decide, and an exception carries it only as prose.
85
+ */
86
+ export interface AttachOutcome {
87
+ readonly reason: string;
88
+ readonly error?: Error;
89
+ /** Did any seat output actually reach the terminal? The manager replays its backlog snapshot on
90
+ * every open, so a session that carried nothing never got that far — which is how a caller that
91
+ * reconnects tells a session that worked from one that died on the way up. */
92
+ readonly carried: boolean;
93
+ }
94
+ /** Did the session end because the LINK broke (so re-establishing is the honest response)? */
95
+ export declare function isTransportEnd(reason: string): boolean;
96
+ /** A line the attach tells the operator while it runs. A `status` line is the loop's own progress;
97
+ * a `warning` is something about the operator's setup worth a look. */
98
+ export type AttachNotice = {
99
+ tone: "status" | "warning";
100
+ text: string;
101
+ };
102
+ /** The default notice sink: stderr, with a status line dimmed. */
103
+ export declare function writeNotice(notice: AttachNotice): void;
104
+ /**
105
+ * Drive a manager's attach session from the terminal: raw-mode stdin streams to the remote PTY,
106
+ * PTY output streams to stdout, and SIGWINCH-style resizes are forwarded. The detach key (Ctrl-]
107
+ * by default, {@link detachKey}) detaches without killing the agent. Transport-agnostic over the
108
+ * mesh §13.6 session. `notice` receives the line naming a rebound detach key.
109
+ */
110
+ export declare function attachClient(transport: TerminalTransport, hold?: TerminalHold, takeStdin?: () => boolean, notice?: (notice: AttachNotice) => void): Promise<AttachOutcome>;
111
+ /**
112
+ * The mesh §13.6 SESSION transport: the item-6 replacement for the loopback WebSocket. Given a
113
+ * connection scoped to the session's eps rails and the redeemed grant, it opens the caller rail,
114
+ * asks the serving side to replay the reconstructed backlog (the `ready` handshake — PR #158 over
115
+ * the mesh), and speaks the core terminal-session frame codec. A `drop` frame is surfaced INLINE
116
+ * (never a silent loss); a peer `end`/close or a protocol fault ends the session with the distinct
117
+ * reason. No `127.0.0.1`, no bearer URL — the grant is holder-bound.
118
+ */
119
+ export declare function meshSessionTransport(nc: NatsConnection, grant: SessionGrant): TerminalTransport;
120
+ //# sourceMappingURL=attach-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attach-client.d.ts","sourceRoot":"","sources":["../../src/attach/attach-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAgF,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAIjI;;;;;;;GAOG;AACH,wBAAgB,SAAS,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAW9F;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAmB9D;AA4DD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,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