@cotal-ai/cli 0.133.11 → 0.133.13

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 (163) hide show
  1. package/README.md +2 -2
  2. package/dist/chat/engine.d.ts +1 -1
  3. package/dist/chat/engine.d.ts.map +1 -1
  4. package/dist/chat/engine.js +1 -1
  5. package/dist/chat/engine.js.map +1 -1
  6. package/dist/chat/static-session.d.ts +1 -1
  7. package/dist/chat/static-session.d.ts.map +1 -1
  8. package/dist/chat/static-session.js +3 -2
  9. package/dist/chat/static-session.js.map +1 -1
  10. package/dist/chat/stdio.js +1 -1
  11. package/dist/command.d.ts.map +1 -1
  12. package/dist/command.js +2 -2
  13. package/dist/command.js.map +1 -1
  14. package/dist/commands/agents.d.ts +1 -117
  15. package/dist/commands/agents.d.ts.map +1 -1
  16. package/dist/commands/agents.js +14 -179
  17. package/dist/commands/agents.js.map +1 -1
  18. package/dist/commands/console.d.ts +1 -1
  19. package/dist/commands/console.d.ts.map +1 -1
  20. package/dist/commands/console.js +7 -10
  21. package/dist/commands/console.js.map +1 -1
  22. package/dist/commands/down.d.ts.map +1 -1
  23. package/dist/commands/down.js +8 -7
  24. package/dist/commands/down.js.map +1 -1
  25. package/dist/commands/models.d.ts.map +1 -1
  26. package/dist/commands/models.js +4 -3
  27. package/dist/commands/models.js.map +1 -1
  28. package/dist/commands/persona-remote.js +1 -2
  29. package/dist/commands/persona-remote.js.map +1 -1
  30. package/dist/commands/setup.js +7 -7
  31. package/dist/commands/spawn.d.ts +1 -37
  32. package/dist/commands/spawn.d.ts.map +1 -1
  33. package/dist/commands/spawn.js +24 -43
  34. package/dist/commands/spawn.js.map +1 -1
  35. package/dist/commands/status.d.ts.map +1 -1
  36. package/dist/commands/status.js +4 -3
  37. package/dist/commands/status.js.map +1 -1
  38. package/dist/commands/team-agent-apply.d.ts.map +1 -1
  39. package/dist/commands/team-agent-apply.js +6 -5
  40. package/dist/commands/team-agent-apply.js.map +1 -1
  41. package/dist/commands/team-agent-remove.d.ts.map +1 -1
  42. package/dist/commands/team-agent-remove.js +6 -5
  43. package/dist/commands/team-agent-remove.js.map +1 -1
  44. package/dist/commands/team-deploy-apply.d.ts.map +1 -1
  45. package/dist/commands/team-deploy-apply.js +1 -2
  46. package/dist/commands/team-deploy-apply.js.map +1 -1
  47. package/dist/commands/telemetry.d.ts +1 -1
  48. package/dist/commands/telemetry.d.ts.map +1 -1
  49. package/dist/commands/up.d.ts.map +1 -1
  50. package/dist/commands/up.js +7 -6
  51. package/dist/commands/up.js.map +1 -1
  52. package/dist/commands/update.d.ts.map +1 -1
  53. package/dist/commands/update.js +5 -4
  54. package/dist/commands/update.js.map +1 -1
  55. package/dist/commands/watch.d.ts.map +1 -1
  56. package/dist/commands/watch.js +5 -17
  57. package/dist/commands/watch.js.map +1 -1
  58. package/dist/commands/who.d.ts.map +1 -1
  59. package/dist/commands/who.js +1 -1
  60. package/dist/commands/who.js.map +1 -1
  61. package/dist/console/app.d.ts +1 -1
  62. package/dist/console/app.d.ts.map +1 -1
  63. package/dist/console/app.js +6 -5
  64. package/dist/console/app.js.map +1 -1
  65. package/dist/console/commands.d.ts +2 -3
  66. package/dist/console/commands.d.ts.map +1 -1
  67. package/dist/console/commands.js.map +1 -1
  68. package/dist/console/launch.d.ts +1 -1
  69. package/dist/console/launch.d.ts.map +1 -1
  70. package/dist/console/mesh.d.ts +2 -2
  71. package/dist/console/mesh.d.ts.map +1 -1
  72. package/dist/console/mesh.js +3 -3
  73. package/dist/console/mesh.js.map +1 -1
  74. package/dist/console/root.d.ts +2 -16
  75. package/dist/console/root.d.ts.map +1 -1
  76. package/dist/console/root.js +6 -30
  77. package/dist/console/root.js.map +1 -1
  78. package/dist/console/ui/CommandPalette.d.ts +2 -2
  79. package/dist/console/ui/CommandPalette.d.ts.map +1 -1
  80. package/dist/console/ui/CommandPalette.js.map +1 -1
  81. package/dist/console/ui/Dm.d.ts +1 -1
  82. package/dist/console/ui/Dm.d.ts.map +1 -1
  83. package/dist/console/ui/SpacePicker.d.ts +1 -1
  84. package/dist/console/ui/SpacePicker.d.ts.map +1 -1
  85. package/dist/console/ui/SpacePicker.js +1 -1
  86. package/dist/console/ui/SpacePicker.js.map +1 -1
  87. package/dist/console/ui/Tiles.d.ts +1 -1
  88. package/dist/console/ui/Tiles.d.ts.map +1 -1
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +1 -1
  92. package/dist/index.js.map +1 -1
  93. package/dist/lib/control.d.ts +5 -280
  94. package/dist/lib/control.d.ts.map +1 -1
  95. package/dist/lib/control.js +24 -782
  96. package/dist/lib/control.js.map +1 -1
  97. package/dist/lib/controller-preserve.d.ts.map +1 -1
  98. package/dist/lib/controller-preserve.js +5 -4
  99. package/dist/lib/controller-preserve.js.map +1 -1
  100. package/dist/lib/endpoint-errors.d.ts +1 -3
  101. package/dist/lib/endpoint-errors.d.ts.map +1 -1
  102. package/dist/lib/endpoint-errors.js +1 -6
  103. package/dist/lib/endpoint-errors.js.map +1 -1
  104. package/dist/lib/endpoint-scatter.d.ts.map +1 -1
  105. package/dist/lib/endpoint-scatter.js +1 -2
  106. package/dist/lib/endpoint-scatter.js.map +1 -1
  107. package/dist/lib/manager-choice.d.ts +2 -31
  108. package/dist/lib/manager-choice.d.ts.map +1 -1
  109. package/dist/lib/manager-choice.js +11 -62
  110. package/dist/lib/manager-choice.js.map +1 -1
  111. package/dist/lib/manifest/live.js +1 -1
  112. package/dist/lib/manifest/live.js.map +1 -1
  113. package/dist/lib/service-census.d.ts +10 -10
  114. package/dist/lib/service-install-intent.d.ts +2 -2
  115. package/dist/lib/service-instances.d.ts +1 -1
  116. package/dist/lib/service-process.js +1 -1
  117. package/dist/lib/service-process.js.map +1 -1
  118. package/dist/lib/service-supervision.d.ts +1 -1
  119. package/dist/lib/service-systemd-attempt-read.d.ts +3 -3
  120. package/dist/lib/service-uninstall-intent.d.ts +3 -3
  121. package/dist/lib/space-schema-report.d.ts +5 -5
  122. package/dist/lib/stack-runs.d.ts.map +1 -1
  123. package/dist/lib/stack-runs.js +4 -3
  124. package/dist/lib/stack-runs.js.map +1 -1
  125. package/dist/lib/systemd-supervision.js +1 -1
  126. package/dist/lib/systemd-supervision.js.map +1 -1
  127. package/dist/lib/team-retained.d.ts.map +1 -1
  128. package/dist/lib/team-retained.js +4 -3
  129. package/dist/lib/team-retained.js.map +1 -1
  130. package/dist/lib/teardown-spare.d.ts.map +1 -1
  131. package/dist/lib/teardown-spare.js +4 -3
  132. package/dist/lib/teardown-spare.js.map +1 -1
  133. package/dist/lib/transient.js +1 -1
  134. package/dist/lib/transient.js.map +1 -1
  135. package/dist/render.js +1 -1
  136. package/dist/render.js.map +1 -1
  137. package/dist/telemetry.d.ts +1 -1
  138. package/dist/telemetry.js +1 -1
  139. package/dist/ui.d.ts +0 -7
  140. package/dist/ui.d.ts.map +1 -1
  141. package/dist/ui.js +1 -24
  142. package/dist/ui.js.map +1 -1
  143. package/dist/watch-data.d.ts +1 -1
  144. package/dist/watch-data.d.ts.map +1 -1
  145. package/dist/watch-json.js +1 -1
  146. package/dist/watch-json.js.map +1 -1
  147. package/dist/watch-view.d.ts +1 -1
  148. package/dist/watch-view.d.ts.map +1 -1
  149. package/dist/watch-view.js +1 -1
  150. package/dist/watch-view.js.map +1 -1
  151. package/package.json +5 -6
  152. package/dist/console/control.d.ts +0 -141
  153. package/dist/console/control.d.ts.map +0 -1
  154. package/dist/console/control.js +0 -191
  155. package/dist/console/control.js.map +0 -1
  156. package/dist/lib/dial-retry.d.ts +0 -33
  157. package/dist/lib/dial-retry.d.ts.map +0 -1
  158. package/dist/lib/dial-retry.js +0 -70
  159. package/dist/lib/dial-retry.js.map +0 -1
  160. package/dist/view/mesh-view.d.ts +0 -213
  161. package/dist/view/mesh-view.d.ts.map +0 -1
  162. package/dist/view/mesh-view.js +0 -533
  163. package/dist/view/mesh-view.js.map +0 -1
@@ -1,191 +0,0 @@
1
- // The console's control door: every operator action (kill / spawn / purge / status) is ONE call
2
- // through the CLI's own per-action path (`ps` is the scatter below, one call per manager) — `resolveControlTarget` resolves
3
- // the mesh and mints a one-shot instrument (or connects bare on an open mesh), `askManager` rides
4
- // the ep rails, and nothing survives the call. The observer endpoint the console watches through
5
- // never carries control, and the console never holds a seed or a standing instrument: the only
6
- // thing it keeps is the `--space` / `--server` / `--creds` triple the CLI's control commands take.
7
- //
8
- // Every refusal comes back as a `{ok:false, error}` the status line can show. The THROWING resolve
9
- // form is used throughout (`onRefusal: "throw"`): the CLI commands' default prints a sentence and
10
- // exits the process, which inside a TUI would blank the screen mid-session.
11
- import { assertValidChannel, clearChannel, isConcreteChannel } from "@cotal-ai/core";
12
- import { askManager, resolveControlTarget, scatterManager, START_TIMEOUT_MS } from "../lib/control.js";
13
- import { connectOrThrow, userViewAuth } from "../lib/connect.js";
14
- import { locateSeat, seatMissRefusal, seatNotFoundMessage } from "../commands/agents.js";
15
- /** The manager ops the console drives, each with the instrument profile the matching CLI command
16
- * mints and whether the op names a seat (a targeted op resolves seat locality first, so it is
17
- * served by the manager actually hosting the seat). */
18
- const OPS = {
19
- // `status` is `inspect` on the manager that HOSTS the seat: a multi-manager space answers a
20
- // class-queue call from whichever manager is quickest, which may not be the host, and reports a
21
- // false miss. Located and pinned like `stop`.
22
- status: { profile: "control-caller-privileged", targeted: true },
23
- start: { profile: "control-caller-privileged", targeted: false, timeoutMs: START_TIMEOUT_MS },
24
- purge: { profile: "control-caller-admin", targeted: false },
25
- stop: { profile: "control-caller-admin", targeted: true },
26
- };
27
- /** Delete one channel: its retained history (a filtered purge) and its registry entry, through
28
- * core's `clearChannel`, the operation the web dashboard's delete button runs, with the same
29
- * per-action authority: a static-auth mesh mints a one-shot `channel-purger` credential from the
30
- * resolved mesh's seed, a user mesh asks for a `channel-purger` view (a fresh ledger check per
31
- * click), an open mesh connects bare. No manager involved. The name must be the one the mesh
32
- * uses, concrete and valid: a wildcard is refused (it would purge channels the operator did not
33
- * name) and a name the wire would rewrite is refused rather than quietly rewritten. */
34
- export async function deleteChannel(ctx, channel) {
35
- try {
36
- assertValidChannel(channel);
37
- if (!isConcreteChannel(channel))
38
- return { ok: false, error: `"${channel}" is a wildcard, not a deletable channel` };
39
- const conn = await connectOrThrow(ctx, "channel-purger");
40
- const r = conn.bearer
41
- ? await userViewAuth(conn, "channel-purger").then((p) => clearChannel({ servers: conn.server, space: conn.space, channel, bearer: p.bearer, sentinelCreds: p.sentinelCreds }))
42
- : await clearChannel({ servers: conn.server, space: conn.space, channel, creds: conn.creds });
43
- return { ok: true, purged: r.purged };
44
- }
45
- catch (e) {
46
- return { ok: false, error: e.message };
47
- }
48
- }
49
- /** One control call. A targeted op names its seat in `args.name`; the alias is resolved to the
50
- * incarnation triple inside `askManager` (the manager's `inspect` read), so the wire never carries
51
- * a name as a target. Reach is `owner` on a user mesh (the bearer's one path; the manager decides
52
- * by ledger scope) and `any` on a static or open mesh (the admin instrument's cross-agent row). */
53
- export async function control(ctx, op, args) {
54
- const spec = OPS[op];
55
- try {
56
- let on;
57
- if (spec.targeted) {
58
- const name = String(args?.name ?? "").trim();
59
- if (!name)
60
- return { ok: false, error: `${op} requires a name` };
61
- const loc = await locateSeat(ctx, name, { onRefusal: "throw" });
62
- if (loc.kind === "absent")
63
- return { ok: false, error: seatNotFoundMessage(loc, name) };
64
- if (loc.kind === "several")
65
- return { ok: false, error: seatMissRefusal(name, `cotal ${op}`, loc) };
66
- if (loc.kind === "pin")
67
- on = loc.instanceId;
68
- }
69
- const t = await resolveControlTarget(ctx, spec.profile, on, { onRefusal: "throw" });
70
- const reach = t.auth.bearer ? "owner" : "any";
71
- const timeoutMs = "timeoutMs" in spec ? spec.timeoutMs : undefined;
72
- // `args` goes through as given: a void-input command is refused by the manager's schema when it
73
- // is handed `{}` instead of nothing, so no default is filled in here.
74
- return await askManager(t.space, t.server, op, args, t.auth, reach, timeoutMs, spec.targeted ? { instanceId: on } : undefined);
75
- }
76
- catch (e) {
77
- return { ok: false, error: e.message };
78
- }
79
- }
80
- /** The single manager a user-mesh bearer reaches, which has no scatter and therefore no instance
81
- * id of its own. A caller keeping rows per instance needs one key for it. */
82
- const BEARER_INSTANCE = "owner";
83
- /** Fold one ps answer into the rows held per manager instance, which is the only shape that can
84
- * both DROP a despawned seat and KEEP a quiet manager's seats.
85
- *
86
- * An instance that answered has its rows replaced wholesale, so a seat it no longer lists is gone
87
- * on that tick. An instance that was asked and stayed silent keeps what it last said, because a
88
- * seat is not gone just because nobody could be reached to ask about it. An instance that is
89
- * neither has left the registry, and its rows leave with it.
90
- *
91
- * A flat merge across instances cannot express the first of those: it can add and overwrite but
92
- * never delete, so one silent registration, which can persist indefinitely when a manager's host
93
- * dies without deregistering, would freeze every other manager's seats in place forever. A flat
94
- * rebuild is the opposite error, emptying a quiet manager's seats off the display. */
95
- export function foldManagedRows(prev, reply) {
96
- const next = new Map(prev);
97
- for (const id of [...next.keys()])
98
- if (!reply.answered.some((a) => a.instanceId === id) && !reply.silent.includes(id))
99
- next.delete(id);
100
- for (const a of reply.answered)
101
- next.set(a.instanceId, a.rows);
102
- return next;
103
- }
104
- /** The per-instance rows flattened to the id-keyed harness facts the roster and detail card read. */
105
- export function managedById(byInstance) {
106
- const flat = new Map();
107
- for (const rows of byInstance.values())
108
- for (const a of rows)
109
- flat.set(a.id, { agent: a.agent, mode: a.mode });
110
- return flat;
111
- }
112
- /** The managed-row poll, SINGLE FLIGHT. One read may outlast the interval that scheduled it: the
113
- * scatter alone budgets a service resolve, a gather and a reconcile, and the resolve and mint in
114
- * front of it are additional. Left unguarded, two reads overlap and are applied in COMPLETION
115
- * order rather than request order, so an older answer can land after a newer one and restore the
116
- * very rows the newer one retired. That is the fold's own guarantee undone one layer up, and no
117
- * test of the fold can see it.
118
- *
119
- * A tick while a read is in flight is therefore skipped outright rather than queued: the state is
120
- * a snapshot of the whole space, so a skipped tick loses nothing that the next one will not carry,
121
- * and skipping also bounds how much control traffic a slow mesh can accumulate. Being single
122
- * flight is also what keeps a STALE FAILURE from stopping the poll after a newer success, since
123
- * there can be no newer success in flight to race.
124
- *
125
- * Stopping on a failed read is deliberate and reported by the caller: an open mesh with no
126
- * supervisor must not knock every tick. */
127
- export function createManagedPoller(read, on) {
128
- let byInstance = new Map();
129
- let inFlight = false;
130
- let stopped = false;
131
- let announcedPartial = "";
132
- return {
133
- async tick() {
134
- if (stopped)
135
- return "stopped";
136
- if (inFlight)
137
- return "skipped";
138
- inFlight = true;
139
- try {
140
- const r = await read();
141
- if (!r.ok) {
142
- stopped = true;
143
- on.stopped(r.error);
144
- return "stopped";
145
- }
146
- const partialKey = JSON.stringify({ silent: r.silent, failed: r.failed });
147
- if ((r.silent.length || r.failed.length) && partialKey !== announcedPartial) {
148
- announcedPartial = partialKey;
149
- on.partial(r.silent, r.failed);
150
- }
151
- if (!r.silent.length && !r.failed.length)
152
- announcedPartial = "";
153
- byInstance = foldManagedRows(byInstance, r);
154
- on.rows(managedById(byInstance));
155
- return "applied";
156
- }
157
- finally {
158
- inFlight = false;
159
- }
160
- },
161
- };
162
- }
163
- export async function controlPs(ctx) {
164
- try {
165
- const t = await resolveControlTarget(ctx, "control-caller-privileged", undefined, { onRefusal: "throw" });
166
- if (t.auth.bearer) {
167
- const r = await askManager(t.space, t.server, "ps", undefined, t.auth, "owner", undefined, {});
168
- if (!r.ok)
169
- return { ok: false, error: r.error ?? "error" };
170
- const rows = r.data ?? [];
171
- return { ok: true, rows, silent: [], failed: [], answered: [{ instanceId: BEARER_INSTANCE, rows }] };
172
- }
173
- const s = await scatterManager(t.space, t.server, "ps", t.auth, t.spaceAuth);
174
- if (!s.ok)
175
- return s;
176
- const answered = s.instances
177
- .filter((i) => i.reachable && !i.error)
178
- .map((i) => ({ instanceId: i.instanceId, rows: (i.data ?? []) }));
179
- return {
180
- ok: true,
181
- rows: answered.flatMap((i) => i.rows),
182
- silent: s.instances.filter((i) => !i.reachable).map((i) => i.instanceId),
183
- failed: s.instances.filter((i) => i.reachable && i.error).map((i) => ({ instanceId: i.instanceId, error: i.error })),
184
- answered,
185
- };
186
- }
187
- catch (e) {
188
- return { ok: false, error: e.message };
189
- }
190
- }
191
- //# sourceMappingURL=control.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"control.js","sourceRoot":"","sources":["../../src/console/control.ts"],"names":[],"mappings":"AAAA,gGAAgG;AAChG,4HAA4H;AAC5H,kGAAkG;AAClG,iGAAiG;AACjG,+FAA+F;AAC/F,mGAAmG;AACnG,EAAE;AACF,mGAAmG;AACnG,kGAAkG;AAClG,4EAA4E;AAC5E,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,cAAc,EAAE,gBAAgB,EAAqB,MAAM,mBAAmB,CAAC;AAC1H,OAAO,EAAE,cAAc,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AACpF,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAMzF;;wDAEwD;AACxD,MAAM,GAAG,GAAG;IACV,4FAA4F;IAC5F,gGAAgG;IAChG,8CAA8C;IAC9C,MAAM,EAAE,EAAE,OAAO,EAAE,2BAA2B,EAAE,QAAQ,EAAE,IAAI,EAAE;IAChE,KAAK,EAAE,EAAE,OAAO,EAAE,2BAA2B,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE;IAC7F,KAAK,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC3D,IAAI,EAAE,EAAE,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,IAAI,EAAE;CACjD,CAAC;AAGX;;;;;;wFAMwF;AACxF,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,GAAe,EAAE,OAAe;IAClE,IAAI,CAAC;QACH,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAC5B,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AC,CAAC,EAAE;YAAE,OAAO,CAAC,CAAC;QACpB,MAAM,QAAQ,GAAG,CAAC,CAAC,SAAS;aACzB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,CAAE,CAAC,CAAC,IAAqB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACtF,OAAO;YACL,EAAE,EAAE,IAAI;YACR,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YACrC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC;YACxE,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,KAAM,EAAE,CAAC,CAAC;YACrH,QAAQ;SACT,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC;IACpD,CAAC;AACH,CAAC"}
@@ -1,33 +0,0 @@
1
- import { ConnectRefusal } from "@cotal-ai/workspace";
2
- /** Attempts a refused or timed-out connect gets, the first included. Nothing is published on a
3
- * connection that never opened, so trying it again repeats nothing. */
4
- export declare const DIAL_ATTEMPTS = 4;
5
- /** The fixed wait between those attempts, in milliseconds. */
6
- export declare const DIAL_RETRY_WAIT_MS = 1000;
7
- /** How long one connect may take, in milliseconds. A connect that is admitted finishes well inside
8
- * it; a broker waiting on an auth service that does not answer would otherwise hold it for the
9
- * transport's 20 seconds. */
10
- export declare const DIAL_TIMEOUT_MS = 5000;
11
- /** How a connect that never opened ended: the broker refused the credential, or the connection did
12
- * not open in time. */
13
- export type DialStage = "refused" | "timeout";
14
- /** The stage a failed connect ended at, or undefined for any other failure, which is not retried. */
15
- export declare function dialStage(e: unknown): DialStage | undefined;
16
- /** Every attempt at a connect ended at the same boundary, so nothing was sent on any of them. */
17
- export declare class DialNotAdmitted extends Error {
18
- readonly stage: DialStage;
19
- readonly attempts: number;
20
- readonly last: unknown;
21
- constructor(stage: DialStage, attempts: number, last: unknown);
22
- }
23
- /** Run `dial` until it opens, trying again after a refused or timed-out attempt, up to
24
- * {@link DIAL_ATTEMPTS}. Throws {@link DialNotAdmitted} when every attempt ended that way, and any
25
- * other failure at once. `dial` builds its connection afresh each time. */
26
- export declare function dialWithRetry<T>(dial: () => Promise<T>): Promise<T>;
27
- /** A connection the broker did not admit on any attempt, as a refusal at the connect stage: `to` is
28
- * what the command connects to and `unsent` what it therefore did not send. It says how the
29
- * attempts ended in plain words; the broker's own words stay in the native detail. On a user-auth
30
- * mesh the auth service decides admission at connect, as the view exchange decides it before; a
31
- * refused view is transient there, so this refusal is transient too. */
32
- export declare function notAdmittedRefusal(e: DialNotAdmitted, to: string, unsent: string, target: Record<string, unknown>, userAuth: boolean): ConnectRefusal;
33
- //# sourceMappingURL=dial-retry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dial-retry.d.ts","sourceRoot":"","sources":["../../src/lib/dial-retry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;wEACwE;AACxE,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,8DAA8D;AAC9D,eAAO,MAAM,kBAAkB,OAAQ,CAAC;AACxC;;8BAE8B;AAC9B,eAAO,MAAM,eAAe,OAAQ,CAAC;AAErC;wBACwB;AACxB,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAE9C,qGAAqG;AACrG,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,CAI3D;AAED,iGAAiG;AACjG,qBAAa,eAAgB,SAAQ,KAAK;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO;gBAAnE,KAAK,EAAE,SAAS,EAAW,QAAQ,EAAE,MAAM,EAAW,IAAI,EAAE,OAAO;CAIzF;AAED;;4EAE4E;AAC5E,wBAAsB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAWzE;AAED;;;;yEAIyE;AACzE,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,GAAG,cAAc,CAWrJ"}
@@ -1,70 +0,0 @@
1
- import { setTimeout as delay } from "node:timers/promises";
2
- import { TimeoutError } from "@nats-io/transport-node";
3
- import { isAuthRejection } from "@cotal-ai/core";
4
- import { ConnectRefusal } from "@cotal-ai/workspace";
5
- /** Attempts a refused or timed-out connect gets, the first included. Nothing is published on a
6
- * connection that never opened, so trying it again repeats nothing. */
7
- export const DIAL_ATTEMPTS = 4;
8
- /** The fixed wait between those attempts, in milliseconds. */
9
- export const DIAL_RETRY_WAIT_MS = 1_000;
10
- /** How long one connect may take, in milliseconds. A connect that is admitted finishes well inside
11
- * it; a broker waiting on an auth service that does not answer would otherwise hold it for the
12
- * transport's 20 seconds. */
13
- export const DIAL_TIMEOUT_MS = 5_000;
14
- /** The stage a failed connect ended at, or undefined for any other failure, which is not retried. */
15
- export function dialStage(e) {
16
- if (isAuthRejection(e))
17
- return "refused";
18
- if (e instanceof TimeoutError)
19
- return "timeout";
20
- return undefined;
21
- }
22
- /** Every attempt at a connect ended at the same boundary, so nothing was sent on any of them. */
23
- export class DialNotAdmitted extends Error {
24
- stage;
25
- attempts;
26
- last;
27
- constructor(stage, attempts, last) {
28
- super(last instanceof Error ? last.message : String(last), { cause: last });
29
- this.stage = stage;
30
- this.attempts = attempts;
31
- this.last = last;
32
- this.name = "DialNotAdmitted";
33
- }
34
- }
35
- /** Run `dial` until it opens, trying again after a refused or timed-out attempt, up to
36
- * {@link DIAL_ATTEMPTS}. Throws {@link DialNotAdmitted} when every attempt ended that way, and any
37
- * other failure at once. `dial` builds its connection afresh each time. */
38
- export async function dialWithRetry(dial) {
39
- for (let attempt = 1;; attempt++) {
40
- try {
41
- return await dial();
42
- }
43
- catch (e) {
44
- const stage = dialStage(e);
45
- if (!stage)
46
- throw e;
47
- if (attempt >= DIAL_ATTEMPTS)
48
- throw new DialNotAdmitted(stage, attempt, e);
49
- await delay(DIAL_RETRY_WAIT_MS);
50
- }
51
- }
52
- }
53
- /** A connection the broker did not admit on any attempt, as a refusal at the connect stage: `to` is
54
- * what the command connects to and `unsent` what it therefore did not send. It says how the
55
- * attempts ended in plain words; the broker's own words stay in the native detail. On a user-auth
56
- * mesh the auth service decides admission at connect, as the view exchange decides it before; a
57
- * refused view is transient there, so this refusal is transient too. */
58
- export function notAdmittedRefusal(e, to, unsent, target, userAuth) {
59
- const how = e.stage === "refused" ? `the broker refused all ${e.attempts} attempts` : `none of ${e.attempts} attempts opened within ${DIAL_TIMEOUT_MS / 1000} seconds`;
60
- const message = `could not connect to ${to}: ${how}, so ${unsent}`;
61
- const remedy = e.stage === "refused"
62
- ? userAuth ? "the space's auth service logs why it refused this connection" : undefined
63
- : "nothing was sent, so the command can be run again once the broker admits connections";
64
- return new ConnectRefusal(remedy ? `✗ ${message} - ${remedy}` : `✗ ${message}`, undefined, {
65
- cause: e, kind: "transient", code: e.stage === "refused" ? "PERMISSION_DENIED" : "TARGET_UNAVAILABLE",
66
- ...(remedy ? { parts: { message, remedy } } : {}), target,
67
- native: { code: `connect-${e.stage}`, detail: { stage: "connect", attempts: e.attempts, reason: e.message } },
68
- });
69
- }
70
- //# sourceMappingURL=dial-retry.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dial-retry.js","sourceRoot":"","sources":["../../src/lib/dial-retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;wEACwE;AACxE,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAC/B,8DAA8D;AAC9D,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACxC;;8BAE8B;AAC9B,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAC;AAMrC,qGAAqG;AACrG,MAAM,UAAU,SAAS,CAAC,CAAU;IAClC,IAAI,eAAe,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzC,IAAI,CAAC,YAAY,YAAY;QAAE,OAAO,SAAS,CAAC;IAChD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,iGAAiG;AACjG,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACnB;IAA2B;IAA2B;IAA3E,YAAqB,KAAgB,EAAW,QAAgB,EAAW,IAAa;QACtF,KAAK,CAAC,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO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DAA8D,CAAC,CAAC,CAAC,SAAS;QACvF,CAAC,CAAC,sFAAsF,CAAC;IAC3F,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,OAAO,MAAM,MAAM,EAAE,CAAC,CAAC,CAAC,KAAK,OAAO,EAAE,EAAE,SAAS,EAAE;QACzF,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,oBAAoB;QACrG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM;QACzD,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;KAC9G,CAAC,CAAC;AACL,CAAC"}
@@ -1,213 +0,0 @@
1
- import { EventEmitter } from "node:events";
2
- import type { CotalEndpoint, EndpointRef, MembershipSnapshot, Presence, PresenceStatus } from "@cotal-ai/core";
3
- export type FeedDelivery = "multicast" | "unicast" | "anycast";
4
- /** One feed row. A same-sender/same-text unicast burst coalesces into a single entry with a
5
- * deterministic id (the first message's) and ts (the earliest), so a history prefill and the
6
- * live tap dedupe-by-id and order correctly. `text` is plain — the surface colors it. */
7
- export interface FeedEntry {
8
- id: string;
9
- ts: number;
10
- from: EndpointRef;
11
- delivery: FeedDelivery;
12
- channel?: string;
13
- toService?: string;
14
- toIds?: string[];
15
- toNames?: string[];
16
- count?: number;
17
- /** This row arrived on an agent's structured-event channel rather than a chat channel.
18
- *
19
- * DERIVED ONCE, HERE, because the header's rule is that a surface lays this model out and never
20
- * re-derives it. Every surface that wanted to tell event traffic from chat would otherwise
21
- * re-spell the convention locally, and three copies of a classifier is three chances to disagree
22
- * about one channel. Absent on unicast and anycast rows, which carry no channel at all. */
23
- events?: boolean;
24
- text: string;
25
- }
26
- export interface StatusCounts {
27
- working: number;
28
- waiting: number;
29
- idle: number;
30
- offline: number;
31
- }
32
- /** One message inside a DM thread (un-coalesced). */
33
- export interface DmMessage {
34
- ts: number;
35
- from: string;
36
- to: string;
37
- text: string;
38
- }
39
- /** A conversation between a peer and one counterparty. */
40
- export interface DmThread {
41
- with: string;
42
- role?: string;
43
- status: PresenceStatus;
44
- lastTs: number;
45
- messages: DmMessage[];
46
- }
47
- /** A peer's whole DM footprint — every counterparty it has talked to. */
48
- export interface DmPeer {
49
- name: string;
50
- role?: string;
51
- status: PresenceStatus;
52
- lastTs: number;
53
- conversations: DmThread[];
54
- }
55
- /** Derived operator signals — golden-signal counts, who needs attention, the DM roll-up. */
56
- export interface MeshSignals {
57
- counts: StatusCounts;
58
- /** Agents blocked / needing input, name-ordered. NOT age-ordered: presence carries no
59
- * status-transition time, so how long a peer has been blocked is not knowable from the wire. */
60
- waiting: Presence[];
61
- /** Oldest heartbeat among LIVE agents — a liveness signal ("is anyone going quiet?"), NOT a
62
- * blocked-duration. {@link Presence.ts} is republished every heartbeat, so it can never say how
63
- * long an agent has been waiting. Undefined when no agent is live. */
64
- stalestLiveTs?: number;
65
- dms: DmPeer[];
66
- }
67
- /** The broker-authoritative membership feed as THIS viewer last saw it. Two facts, kept apart so a
68
- * failed read can never be mistaken for an empty feed: `snapshot` is the last successful read;
69
- * `unreadable` is the reason the most recent read or watch attempt failed (a fact about the
70
- * viewer, cleared by the next successful read). A feed that does not exist (no delivery daemon:
71
- * the bucket is absent, or it was never written) is a snapshot with no `asOf` and no members, which
72
- * renders as traffic-only: a fact about the mesh, and a different one. */
73
- export interface MembershipView {
74
- snapshot?: MembershipSnapshot;
75
- unreadable?: string;
76
- }
77
- export interface MeshSnapshot {
78
- agents: Presence[];
79
- endpoints: Presence[];
80
- /** `messages`: the broker's retained count (capped per sender, so it can stop climbing under
81
- * live traffic). `arrivals`: messages this viewer saw ARRIVE on the live tap since it started,
82
- * monotonic, dropped with the channel: the honest base for an unread badge. */
83
- channels: {
84
- channel: string;
85
- messages: number;
86
- arrivals: number;
87
- }[];
88
- feed: FeedEntry[];
89
- /** Broker-authoritative channel membership (the delivery daemon's CONNZ view plus the durable
90
- * registry), as last read; the topology lens overlays it to show silent subscribers. */
91
- membership: MembershipView;
92
- /** `msgsPerSec`: the rolling 1 s rate. `activity`: a fixed 15-bucket message-volume series over
93
- * the last 60 s (one ~4 s bucket each), oldest→newest, raw counts: the status bar's sparkline. */
94
- rates: {
95
- msgsPerSec: number;
96
- activity: number[];
97
- };
98
- status: {
99
- connected: boolean;
100
- space: string;
101
- dmVisible: boolean;
102
- error?: string;
103
- warning?: string;
104
- };
105
- signals: MeshSignals;
106
- nameOf: (id: string) => string;
107
- }
108
- export interface MeshViewOptions {
109
- /** Feed cap, in entries. Default 300. */
110
- window?: number;
111
- /** The read-only tap subject. `chatWildcard(space)` narrows to multicast (auth — DMs/anycast
112
- * stay confidential); `spaceWildcard(space)` or undefined taps the whole space (god-view). */
113
- tapSubject?: string;
114
- }
115
- /**
116
- * Events:
117
- * - `"entry"` `(e: FeedEntry)` — one live feed row, as it lands (for the stream renderer).
118
- * - `"presence"` `(ev: PresenceEvent)` — forwarded presence change (join/update/offline).
119
- * - `"warning"` `(e: Error)` — a recoverable endpoint notice for the stream renderer.
120
- * - `"change"` `(s: MeshSnapshot)` — a batched snapshot every ~75ms (for dashboards).
121
- */
122
- export declare class MeshView extends EventEmitter {
123
- private readonly ep;
124
- private roster;
125
- private byId;
126
- private channelCounts;
127
- private arrivals;
128
- private feed;
129
- private seen;
130
- private pending;
131
- private dmLog;
132
- private recentTs;
133
- private msgsPerSec;
134
- private bucketCounts;
135
- private bucketEpoch;
136
- private connected;
137
- private error?;
138
- private presenceCurrent;
139
- private errorWhilePresenceStale;
140
- private warning?;
141
- private dirty;
142
- private membership;
143
- private membershipWatch?;
144
- private membershipTimer?;
145
- private readonly window;
146
- private readonly tapSubject?;
147
- private readonly chatOnly;
148
- private timers;
149
- private readonly onRoster;
150
- private readonly onPresence;
151
- private readonly onError;
152
- /** A broker restart reconnects the transport without a new `connection`, and its errors (the
153
- * presence stream missing until the space is provisioned again) arrive while the presence view
154
- * is stale. When that view is current again the outage is over, so its error clears with it
155
- * (AGENT-2889). An error raised while the view was current stays until the next connection. */
156
- private readonly onPresenceView;
157
- /** A rebuilt connection clears the fault that dropped the old one, so the view reports itself
158
- * connected again instead of keeping that error for good. */
159
- private readonly onConnection;
160
- private readonly onWarning;
161
- constructor(ep: CotalEndpoint, opts?: MeshViewOptions);
162
- start(): Promise<void>;
163
- stop(): Promise<void>;
164
- /** Read the broker-authoritative membership feed and follow it. A membership fault is never
165
- * a connection fault: it lands on `membership.unreadable` (with its reason), not on
166
- * `status.error`, because the mesh is fine and only this viewer's read of one feed is not. */
167
- private startMembership;
168
- /** A heartbeat moves only `asOf`, so it is copied into the last snapshot instead of costing a
169
- * bucket re-read (#4904); a member change is read back in full, and a heartbeat that arrives
170
- * while the last read failed is the retry. */
171
- private onMembershipChange;
172
- private scheduleMembership;
173
- /** One read of the feed. Three outcomes, kept distinct: a snapshot (readable, whatever it holds),
174
- * an absent feed (readable in the sense that the mesh has no daemon writing one: an empty
175
- * snapshot, traffic-only), and a failed read (`unreadable`, reason kept, last snapshot kept so
176
- * the reason is shown against what was last known rather than against nothing). */
177
- private loadMembership;
178
- snapshot(): MeshSnapshot;
179
- nameOf: (id: string) => string;
180
- private setRoster;
181
- /** Live read-only tap. Drops control/presence/trace frames (deliveryOf → null). A payload
182
- * from.name is sender-chosen display text, not identity (#1399): the roster is the only writer
183
- * of id→name, so a spoofed name can never re-key a thread or a label. */
184
- private ingest;
185
- /** Group a same-sender/same-text unicast burst into one feed entry over BURST_MS, and retain
186
- * each raw message for the DM roll-up. */
187
- private coalesce;
188
- private flushBurst;
189
- /** Append to the feed, dedupe by id, keep it windowed, and notify stream consumers. */
190
- private push;
191
- private trim;
192
- private recordDm;
193
- /** One-shot backlog: prefill each channel's history (multicast), plus the DM backlog when DMs
194
- * are visible (god-view — `dmHistory` needs an admin cred), deduped by id, oldest-first. */
195
- private prefill;
196
- /** Best-effort DM backlog for the roll-up — only meaningful for a god-view cred; a non-admin
197
- * observer's `dmHistory` throws (ACL), which just leaves the DM lens live-only. A history
198
- * row's from.name is payload text, never an id→name source (#1399). */
199
- private prefillDms;
200
- private refreshChannels;
201
- private signals;
202
- /** Group raw DMs into per-peer rows; each peer lists its counterparties (conversations).
203
- * Only pairs that actually talked — never the n² cross-product. Conversations key on the two
204
- * AUTHENTICATED ids; display names, roles and statuses resolve through the roster by id, so a
205
- * payload `from.name` cannot move a line into another peer's thread (#1399). */
206
- private rollupDms;
207
- /** Advance the activity ring to `now`: shift past buckets out the left, fill the gap with zeros,
208
- * so idle time decays the series. The newest (last) bucket is always the current ~4s window. */
209
- private roll;
210
- /** The single batch point: recompute the rolling rate, then emit one snapshot if dirty. */
211
- private flush;
212
- }
213
- //# sourceMappingURL=mesh-view.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mesh-view.d.ts","sourceRoot":"","sources":["../../src/view/mesh-view.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAgB,WAAW,EAAoB,kBAAkB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAK/I,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,SAAS,CAAC;AAE/D;;0FAE0F;AAC1F,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAA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