@cotal-ai/core 0.5.0 → 0.7.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 (47) hide show
  1. package/dist/acls.d.ts +45 -0
  2. package/dist/acls.d.ts.map +1 -0
  3. package/dist/acls.js +86 -0
  4. package/dist/acls.js.map +1 -0
  5. package/dist/command.d.ts +3 -0
  6. package/dist/command.d.ts.map +1 -1
  7. package/dist/connector.d.ts +10 -0
  8. package/dist/connector.d.ts.map +1 -1
  9. package/dist/endpoint.d.ts +197 -54
  10. package/dist/endpoint.d.ts.map +1 -1
  11. package/dist/endpoint.js +443 -100
  12. package/dist/endpoint.js.map +1 -1
  13. package/dist/index.d.ts +5 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/lease.d.ts +40 -0
  18. package/dist/lease.d.ts.map +1 -0
  19. package/dist/lease.js +64 -0
  20. package/dist/lease.js.map +1 -0
  21. package/dist/membership-feed.d.ts +30 -0
  22. package/dist/membership-feed.d.ts.map +1 -0
  23. package/dist/membership-feed.js +315 -0
  24. package/dist/membership-feed.js.map +1 -0
  25. package/dist/mesh-registry.d.ts +45 -0
  26. package/dist/mesh-registry.d.ts.map +1 -0
  27. package/dist/mesh-registry.js +78 -0
  28. package/dist/mesh-registry.js.map +1 -0
  29. package/dist/mesh-target.d.ts +42 -0
  30. package/dist/mesh-target.d.ts.map +1 -0
  31. package/dist/mesh-target.js +95 -0
  32. package/dist/mesh-target.js.map +1 -0
  33. package/dist/provision.d.ts +45 -21
  34. package/dist/provision.d.ts.map +1 -1
  35. package/dist/provision.js +177 -15
  36. package/dist/provision.js.map +1 -1
  37. package/dist/streams.d.ts +16 -0
  38. package/dist/streams.d.ts.map +1 -1
  39. package/dist/streams.js +29 -5
  40. package/dist/streams.js.map +1 -1
  41. package/dist/subjects.d.ts +89 -2
  42. package/dist/subjects.d.ts.map +1 -1
  43. package/dist/subjects.js +132 -3
  44. package/dist/subjects.js.map +1 -1
  45. package/dist/types.d.ts +52 -0
  46. package/dist/types.d.ts.map +1 -1
  47. package/package.json +1 -1
package/dist/acls.d.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Durable read-ACL registry — read/write helpers over the per-space ACL KV bucket
3
+ * (`cotal_acl_<space>`). One {@link AclRecord} per OWNER under {@link aclKey}, holding that owner's
4
+ * current read ACL (`allowSubscribe`). This is the **keystone** that lets the Plane-3 trusted reader
5
+ * run in a stateless, server-side **delivery daemon**: the reader re-authorizes every durable entry
6
+ * against the owner's ACL read FRESH from here (not the manager's in-memory ledger), so a daemon
7
+ * restart re-reads the truth instead of nak-looping every unknown owner to `term()`.
8
+ *
9
+ * Writes are **privileged** — the manager records an agent's ACL at mint time (the same act as baking
10
+ * it into the JWT); agent-authored ACLs are forbidden (they would self-authorize reads). Every write
11
+ * is a single ATOMIC CAS put of the whole value, so a present record is always complete: a present
12
+ * `allowSubscribe: []` is a known "reads nothing" policy (the reader DROPS), distinct from an ABSENT
13
+ * record (a genuinely-unknown owner — the reader DEFERS, never drops).
14
+ */
15
+ import { type KV } from "@nats-io/kv";
16
+ import type { AclRecord } from "./types.js";
17
+ /** Open the ACL registry bucket. Auth mode OPENs the bucket pre-created at `cotal up`; a privileged
18
+ * caller may pass `{ create: true }` to lazily CREATE it. Mirrors {@link openMembersRegistry}. */
19
+ export declare function openAclRegistry(nc: import("@nats-io/transport-node").NatsConnection, space: string, opts?: {
20
+ create?: boolean;
21
+ }): Promise<KV>;
22
+ /**
23
+ * Read one owner's read-ACL record, or `undefined` if there is NO usable record — absent, deleted,
24
+ * undecodable, or missing the `allowSubscribe` array. The reader maps that `undefined` to DEFER (an
25
+ * unknown owner, e.g. a pre-provision race — never dropped). A PRESENT record returns its
26
+ * `allowSubscribe` as-is, **including `[]`** (a known no-read policy → DROP). The CAS revision is
27
+ * returned alongside for a read-modify-write.
28
+ */
29
+ export declare function readAcl(kv: KV, owner: string): Promise<{
30
+ record: AclRecord;
31
+ revision: number;
32
+ } | undefined>;
33
+ /**
34
+ * Record (set) an owner's read ACL — a single ATOMIC CAS put of the full value, never
35
+ * create-then-populate, so a present record is always complete and `[]` always means "no-read", never
36
+ * "not yet written". Bumps `revision`. Retries a revision conflict by re-reading. Idempotent in
37
+ * effect: writing the same `allowSubscribe` is harmless. Use `allowSubscribe: []` to revoke all reads
38
+ * (the reader then DROPS the owner's entries) — distinct from {@link deleteAcl}, which removes the row.
39
+ */
40
+ export declare function commitAcl(kv: KV, owner: string, allowSubscribe: string[]): Promise<AclRecord>;
41
+ /** Permanently remove an owner's ACL row (GC / footprint deletion — revocation deletes the footprint
42
+ * AFTER invalidating creds). Distinct from a `commitAcl(kv, owner, [])` write, which keeps a present
43
+ * "no-read" record so the reader DROPS (vs. DEFER for an absent owner). */
44
+ export declare function deleteAcl(kv: KV, owner: string): Promise<void>;
45
+ //# sourceMappingURL=acls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acls.d.ts","sourceRoot":"","sources":["../src/acls.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAO,KAAK,EAAE,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;mGACmG;AACnG,wBAAsB,eAAe,CACnC,EAAE,EAAE,OAAO,yBAAyB,EAAE,cAAc,EACpD,KAAK,EAAE,MAAM,EACb,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9B,OAAO,CAAC,EAAE,CAAC,CAGb;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,EAAE,EACN,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAAC,CAU9D;AAED;;;;;;GAMG;AACH,wBAAsB,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CA0BnG;AAED;;4EAE4E;AAC5E,wBAAsB,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpE"}
package/dist/acls.js ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Durable read-ACL registry — read/write helpers over the per-space ACL KV bucket
3
+ * (`cotal_acl_<space>`). One {@link AclRecord} per OWNER under {@link aclKey}, holding that owner's
4
+ * current read ACL (`allowSubscribe`). This is the **keystone** that lets the Plane-3 trusted reader
5
+ * run in a stateless, server-side **delivery daemon**: the reader re-authorizes every durable entry
6
+ * against the owner's ACL read FRESH from here (not the manager's in-memory ledger), so a daemon
7
+ * restart re-reads the truth instead of nak-looping every unknown owner to `term()`.
8
+ *
9
+ * Writes are **privileged** — the manager records an agent's ACL at mint time (the same act as baking
10
+ * it into the JWT); agent-authored ACLs are forbidden (they would self-authorize reads). Every write
11
+ * is a single ATOMIC CAS put of the whole value, so a present record is always complete: a present
12
+ * `allowSubscribe: []` is a known "reads nothing" policy (the reader DROPS), distinct from an ABSENT
13
+ * record (a genuinely-unknown owner — the reader DEFERS, never drops).
14
+ */
15
+ import { Kvm } from "@nats-io/kv";
16
+ import { aclBucket, aclKey } from "./subjects.js";
17
+ /** Open the ACL registry bucket. Auth mode OPENs the bucket pre-created at `cotal up`; a privileged
18
+ * caller may pass `{ create: true }` to lazily CREATE it. Mirrors {@link openMembersRegistry}. */
19
+ export async function openAclRegistry(nc, space, opts = {}) {
20
+ const kvm = new Kvm(nc);
21
+ return opts.create ? kvm.create(aclBucket(space)) : kvm.open(aclBucket(space));
22
+ }
23
+ /**
24
+ * Read one owner's read-ACL record, or `undefined` if there is NO usable record — absent, deleted,
25
+ * undecodable, or missing the `allowSubscribe` array. The reader maps that `undefined` to DEFER (an
26
+ * unknown owner, e.g. a pre-provision race — never dropped). A PRESENT record returns its
27
+ * `allowSubscribe` as-is, **including `[]`** (a known no-read policy → DROP). The CAS revision is
28
+ * returned alongside for a read-modify-write.
29
+ */
30
+ export async function readAcl(kv, owner) {
31
+ const e = await kv.get(aclKey(owner));
32
+ if (!e || e.operation === "DEL" || e.operation === "PURGE")
33
+ return undefined;
34
+ try {
35
+ const record = e.json();
36
+ if (!Array.isArray(record.allowSubscribe))
37
+ return undefined; // half/garbled — treat as unknown (DEFER)
38
+ return { record, revision: e.revision };
39
+ }
40
+ catch {
41
+ return undefined;
42
+ }
43
+ }
44
+ /**
45
+ * Record (set) an owner's read ACL — a single ATOMIC CAS put of the full value, never
46
+ * create-then-populate, so a present record is always complete and `[]` always means "no-read", never
47
+ * "not yet written". Bumps `revision`. Retries a revision conflict by re-reading. Idempotent in
48
+ * effect: writing the same `allowSubscribe` is harmless. Use `allowSubscribe: []` to revoke all reads
49
+ * (the reader then DROPS the owner's entries) — distinct from {@link deleteAcl}, which removes the row.
50
+ */
51
+ export async function commitAcl(kv, owner, allowSubscribe) {
52
+ const key = aclKey(owner);
53
+ for (let attempt = 0; attempt < 5; attempt++) {
54
+ const cur = await readAcl(kv, owner);
55
+ const next = {
56
+ allowSubscribe: [...allowSubscribe],
57
+ revision: (cur?.record.revision ?? 0) + 1,
58
+ updatedAt: Date.now(),
59
+ };
60
+ const data = new TextEncoder().encode(JSON.stringify(next));
61
+ if (!cur) {
62
+ try {
63
+ await kv.create(key, data);
64
+ return next;
65
+ }
66
+ catch {
67
+ continue; // lost the create race — re-read and try as an update
68
+ }
69
+ }
70
+ try {
71
+ await kv.update(key, data, cur.revision);
72
+ return next;
73
+ }
74
+ catch {
75
+ continue; // revision moved under us — re-read and retry
76
+ }
77
+ }
78
+ throw new Error(`acl CAS exhausted retries for ${owner}`);
79
+ }
80
+ /** Permanently remove an owner's ACL row (GC / footprint deletion — revocation deletes the footprint
81
+ * AFTER invalidating creds). Distinct from a `commitAcl(kv, owner, [])` write, which keeps a present
82
+ * "no-read" record so the reader DROPS (vs. DEFER for an absent owner). */
83
+ export async function deleteAcl(kv, owner) {
84
+ await kv.purge(aclKey(owner));
85
+ }
86
+ //# sourceMappingURL=acls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acls.js","sourceRoot":"","sources":["../src/acls.ts"],"names":[],"mappings":"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"}
package/dist/command.d.ts CHANGED
@@ -28,6 +28,9 @@ export interface Command extends Extension {
28
28
  /** One-line usage shown by `cotal <cmd> --help` and on an invalid-argument error.
29
29
  * Falls back to `summary` when unset. */
30
30
  readonly usage?: string;
31
+ /** Hide from the top-level help listing while keeping it runnable — for dev/test aids
32
+ * (e.g. `demo`) that clutter the surface but stay documented and invocable. */
33
+ readonly hidden?: boolean;
31
34
  run(argv: string[]): Promise<void>;
32
35
  /** Optional shell-completion provider, owned by the command exactly as `run` is. Given the
33
36
  * args typed so far (everything after the command name; the last element is the word being
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;0FAC0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;uFAIuF;AACvF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACxC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;8CAC0C;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC;;;;2FAIuF;IACvF,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACzE"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../src/command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;0FAC0F;AAC1F,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;uFAIuF;AACvF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;CAC/C;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAQ,SAAQ,SAAS;IACxC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;8CAC0C;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;oFACgF;IAChF,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC;;;;2FAIuF;IACvF,QAAQ,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACzE"}
@@ -17,6 +17,10 @@ export interface LaunchOpts {
17
17
  * passes it through (`COTAL_AGENT_FILE`) so the joined session reads its own
18
18
  * card from it, and applies the file's persona/model at launch. */
19
19
  configPath?: string;
20
+ /** Explicit model override — the `cotal start --model <m>` flag. Takes precedence over the
21
+ * agent file's `model:` and is applied even when no agent file is present. Each connector
22
+ * renders it in its host form (Claude `--model`, OpenCode `config.model`, Hermes `HERMES_MODEL`). */
23
+ model?: string;
20
24
  /** An initial message for the session to act on the moment it starts. Connectors
21
25
  * that support an auto-submitted first prompt (Claude Code) deliver it; others
22
26
  * ignore it. Used to make a driving session greet the operator on launch. */
@@ -54,6 +58,12 @@ export interface Connector extends Extension {
54
58
  readonly kind: "connector";
55
59
  readonly name: string;
56
60
  buildLaunch(opts: LaunchOpts): LaunchSpec;
61
+ /** External executables this connector invokes beyond `LaunchSpec.command` (e.g. the
62
+ * `claude` / `opencode` CLI). A preflight PATH hint, not a full environment validator: the
63
+ * manager checks each is on PATH before spawning and fails with a clear error naming the
64
+ * missing one, instead of an obscure process-spawn failure. Optional — omit for connectors
65
+ * whose harness runs in-process. */
66
+ readonly requires?: readonly string[];
57
67
  /** Directory of installable editor-plugin assets shipped with the connector
58
68
  * (e.g. a Claude Code plugin dir), when the agent type needs a one-time
59
69
  * plugin install. Consumers (like `cotal setup`) resolve it via the registry
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;8EAE0E;IAC1E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;mDAC+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;wEAEoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;kFAE8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;yFAEqF;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;qEAIiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC5C;AAED,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;;+CAG2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAU,SAAQ,SAAS;IAC1C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC1C;;;+DAG2D;IAC3D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;8EAE0E;IAC1E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;mDAC+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;wEAEoE;IACpE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;0GAEsG;IACtG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;kFAE8E;IAC9E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;yFAEqF;IACrF,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;;qEAIiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC5C;AAED,oFAAoF;AACpF,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;;+CAG2C;IAC3C,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAU,SAAQ,SAAS;IAC1C,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC;IAC1C;;;;yCAIqC;IACrC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC;;;+DAG2D;IAC3D,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B"}
@@ -1,5 +1,6 @@
1
1
  import { EventEmitter } from "node:events";
2
- import type { AgentCard, ChannelConfig, ControlReply, ControlRequest, ControlRequestInit, EndpointRef, Part, Presence, PresenceStatus, AttentionMode, ChannelMode, CotalMessage } from "./types.js";
2
+ import type { AgentCard, ChannelConfig, ControlReply, ControlRequest, ControlRequestInit, EndpointRef, Part, Presence, PresenceStatus, AttentionMode, ChannelMode, CotalMessage, DeliveryClass, MembershipSnapshot } from "./types.js";
3
+ import { type DeliveryLeaseInfo } from "./lease.js";
3
4
  export declare const DEFAULT_SERVER = "nats://127.0.0.1:4222";
4
5
  /** Space joined when none is given on the CLI (the `cotal-<space>` cmux tab, etc.). */
5
6
  export declare const DEFAULT_SPACE = "main";
@@ -50,6 +51,9 @@ export interface ChannelMember {
50
51
  role?: string;
51
52
  live: boolean;
52
53
  }
54
+ /** A value or a promise of it — the Plane-3 `aclFor` reads the durable ACL registry FRESH per entry
55
+ * (async), so the reader/fan-out call sites await it. */
56
+ type MaybePromise<T> = T | Promise<T>;
53
57
  export declare class CotalEndpoint extends EventEmitter {
54
58
  readonly card: AgentCard;
55
59
  readonly space: string;
@@ -72,10 +76,18 @@ export declare class CotalEndpoint extends EventEmitter {
72
76
  private jsm?;
73
77
  private kv?;
74
78
  private channelKv?;
75
- /** Plane-3 durable-membership registry KV — lazily opened by the privileged (manager) endpoint. */
79
+ /** Plane-3 durable-membership registry KV — lazily opened by the privileged delivery daemon (or a
80
+ * short-lived provisioner). */
76
81
  private membersKv?;
77
- /** When set, this endpoint hosts the Plane-3 fan-out writer + trusted reader (the manager). `aclFor`
78
- * maps an owner id to its current read ACL (`allowSubscribe`) for the reader's re-authorization. */
82
+ private aclKv?;
83
+ private deliveryKv?;
84
+ private membershipKv?;
85
+ /** The live `ctl.delivery` serve subscription (delivery daemon) — re-created on every (re)connect by
86
+ * {@link armDeliveryControl}; tracked so the stale one is dropped on reconnect. */
87
+ private deliveryServeSub?;
88
+ /** When set, this endpoint hosts the Plane-3 fan-out writer + trusted reader (the server-side delivery
89
+ * daemon). `aclFor` maps an owner id to its current read ACL (`allowSubscribe`) for the reader's
90
+ * re-authorization — read FRESH per entry from the durable ACL registry KV, hence async. */
79
91
  private plane3?;
80
92
  /** Live local cache of the channel registry (key = channel token), kept by a KV watch. */
81
93
  private readonly channelConfigs;
@@ -111,6 +123,12 @@ export declare class CotalEndpoint extends EventEmitter {
111
123
  * {@link pendingDurableLeaves} (the connector shows it in `cotal_channels`, never as ordinary
112
124
  * absence). Persists across reconnect; cleared on tombstone success or full stop. */
113
125
  private readonly pendingDurableLeave;
126
+ /** Boot durable channels whose self-join hasn't yet established a membership (daemon down/absent at
127
+ * first connect, or a transient `durable:false`). {@link reconcileBootJoin} retries with capped
128
+ * backoff until the membership exists or the channel is left — so a first-connect daemon outage
129
+ * self-heals on recovery instead of leaving the channel silently live-only. Surfaced to the connector
130
+ * via {@link hasDurableMembership} (a joined durable channel NOT yet a member renders degraded). */
131
+ private readonly pendingBootJoins;
114
132
  /** Chat-join subjects currently being broker-confirmed. An out-of-ACL subscribe among these trips an
115
133
  * EXPECTED async permission violation that joinChannel turns into a clean throw, so watchStatus
116
134
  * suppresses it rather than surfacing a spurious connection error. */
@@ -221,10 +239,26 @@ export declare class CotalEndpoint extends EventEmitter {
221
239
  tap(handler: (subject: string, msg: CotalMessage | undefined) => void, opts?: {
222
240
  subject?: string;
223
241
  }): void;
224
- /** Serve control requests for a service (manager side). */
225
- serveControl(service: string, handler: (req: ControlRequest) => Promise<ControlReply> | ControlReply): void;
242
+ /** Serve control requests for a service. Returns the subscription so a caller that re-registers on
243
+ * reconnect (the delivery daemon) can drop the stale one. `boundReply` is REQUIRED for any service
244
+ * whose responder holds a wildcard publish grant over the service subtree (the delivery daemon's
245
+ * `ctl.delivery.*.reply.>`): without it, an authenticated caller could set its reply target to a
246
+ * PEER's reply lane (`ctl.delivery.<victim>.reply.<n>`) and turn the responder into a confused
247
+ * deputy — the broker does NOT permission-check the requester's embedded reply subject. With it, a
248
+ * reply is published only when `m.reply` is under the AUTHENTICATED request subject
249
+ * (`${m.subject}.reply.…`), binding the reply to the broker-policed sender token. (The manager's
250
+ * tiers reply into the per-id `_INBOX` and leave it off.) */
251
+ serveControl(service: string, handler: (req: ControlRequest) => Promise<ControlReply> | ControlReply, opts?: {
252
+ boundReply?: boolean;
253
+ }): import("@nats-io/transport-node").Subscription;
226
254
  /** Send a control request to a service and await its reply (client side). */
227
255
  requestControl(service: string, req: ControlRequestInit, timeoutMs?: number): Promise<ControlReply>;
256
+ /** Send a durable-membership request to the SERVER-SIDE delivery daemon (`ctl.delivery`) and await its
257
+ * reply. Unlike {@link requestControl}, the reply rides a subject UNDER `ctl.delivery.<id>.>` (not the
258
+ * per-id `_INBOX`), so the scoped delivery cred can answer without broad inbox-publish — see
259
+ * CONTROL_DELIVERY. `noMux` lets us name the reply subject while keeping NoResponders detection (so a
260
+ * caller can fail-closed vs. degrade to live-only when no daemon is present). */
261
+ private requestDelivery;
228
262
  getRoster(): Presence[];
229
263
  setActivity(activity: string): Promise<void>;
230
264
  setStatus(status: PresenceStatus): Promise<void>;
@@ -245,14 +279,19 @@ export declare class CotalEndpoint extends EventEmitter {
245
279
  /** Effective replay-on-join policy for a channel: per-channel override ?? space default ??
246
280
  * true. Reads the live cache, so it reflects runtime registry edits. */
247
281
  channelReplay(channel: string): boolean;
282
+ /** Effective delivery class for a channel (per-channel override ?? space default ?? "durable"),
283
+ * from the live watch cache — drives the non-gating delivery-health surface (only durable-class
284
+ * channels have a Plane-3 backstop to report on). */
285
+ channelDeliveryClass(channel: string): DeliveryClass;
248
286
  /** The channels this endpoint is currently subscribed to (live — reflects join/leave). */
249
287
  joinedChannels(): string[];
250
288
  /**
251
289
  * Join a channel mid-session: open a native core subscription (manager-free live read, broker-
252
290
  * confirmed against `sub.allow`), capture the stream frontier as the join watermark, backfill its
253
- * history if replay is on, and — for a `durable`-class channel under a manager request a Plane-3
254
- * durable backstop. Idempotent: re-joining is a no-op (no re-backfill). Returns the backfill count +
255
- * whether the durable backstop is active (+ a `reason` when a durable channel couldn't get one).
291
+ * history if replay is on, and — for a `durable`-class channel when a delivery daemon is present
292
+ * request a Plane-3 durable backstop (via `ctl.delivery`). Idempotent: re-joining is a no-op (no
293
+ * re-backfill). Returns the backfill count + whether the durable backstop is active (+ a `reason`
294
+ * when a durable channel couldn't get one).
256
295
  */
257
296
  joinChannel(channel: string): Promise<{
258
297
  joined: boolean;
@@ -290,6 +329,24 @@ export declare class CotalEndpoint extends EventEmitter {
290
329
  */
291
330
  channelMembers(channel: string): Promise<ChannelMember[]>;
292
331
  channelMembers(): Promise<Map<string, ChannelMember[]>>;
332
+ /** Lazily open the derived membership feed KV (admin/observer read; the delivery daemon writes it).
333
+ * Read-only here — the dashboard consumes it; agents hold no grant and never call this. */
334
+ private membershipRegistry;
335
+ /**
336
+ * Snapshot the broker-sourced channel-membership feed (admin/observer read): every agent's
337
+ * `{live, durable}` record plus `asOf` — the feed's freshness heartbeat (epoch ms of the daemon's last
338
+ * successful poll, from the reserved {@link MEMBERSHIP_FEED_KEY}). `live` patterns are kept as-is
339
+ * (wildcards preserved); the consumer expands them against the channel registry. `asOf` is undefined
340
+ * when the feed has never been written (no daemon → the dashboard degrades to traffic-only).
341
+ */
342
+ readMembership(): Promise<MembershipSnapshot>;
343
+ /** Watch the membership feed for changes (admin/observer): `onChange` fires on every KV entry,
344
+ * including the initial replay — the caller debounces + re-reads {@link readMembership}. Returns a
345
+ * stop handle. Best-effort: a feed the cred can't read (or absent) surfaces as an `error` event and
346
+ * the dashboard keeps its last snapshot. */
347
+ watchMembership(onChange: () => void): Promise<{
348
+ stop(): void;
349
+ }>;
293
350
  /** Fetch recent messages from a channel's JetStream backlog. */
294
351
  channelHistory(channel: string, opts?: {
295
352
  limit?: number;
@@ -322,20 +379,6 @@ export declare class CotalEndpoint extends EventEmitter {
322
379
  /** Create the three backing streams for this space (idempotent). Open-mode lazy create;
323
380
  * the same definitions are used by `cotal up` at privileged setup. */
324
381
  private ensureStreams;
325
- /**
326
- * Privileged: write an agent's BOOT durable membership — each `durable`-class channel in its boot
327
- * subscribe set gets a Plane-3 durable-active record (via {@link durableJoinFor}: cursor capture +
328
- * activation catch-up), so it receives durable backstop copies from boot exactly like a runtime
329
- * `durableJoin`. `live`-class (and non-concrete) channels are skipped. Idempotent.
330
- *
331
- * Writes the durable RECORDS with the caller's privileged creds — it does NOT require this endpoint
332
- * to host the runtime fan-out/reader loops (a space-level manager service), so EVERY auth launcher
333
- * provisions identically: the manager AND the short-lived `cotal spawn` provisioner both write boot
334
- * records, which the space's manager then delivers (no silent no-op — that would hide a boot
335
- * membership; AGENTS.md "no fallbacks"). A space running no manager is live-only for everyone (the
336
- * records exist; nothing delivers them until a manager hosts the loops).
337
- */
338
- provisionMembership(targetId: string, channels: string[]): Promise<void>;
339
382
  /**
340
383
  * Privileged: pre-create an agent's DM inbox durable (auth mode), so the agent can BIND
341
384
  * it without holding CONSUMER.CREATE on DM_<space>. The creator sets the filter to
@@ -359,13 +402,51 @@ export declare class CotalEndpoint extends EventEmitter {
359
402
  * Idempotent per role. The caller must be permissive on TASK_<space>.
360
403
  */
361
404
  provisionTaskQueue(role: string): Promise<void>;
362
- /** Lazily open the privileged members registry KV (manager / open-mode self). */
405
+ /** Lazily open the privileged members registry KV (delivery daemon / open-mode self). */
363
406
  private membersRegistry;
407
+ /** Lazily open the durable read-ACL registry KV. Privileged write (the manager records an agent's
408
+ * ACL at mint); the delivery daemon reads it fresh per durable entry to re-authorize. */
409
+ private aclRegistry;
410
+ /** Privileged ({@link DurableProvisioner}): record an agent's read ACL in the durable registry at
411
+ * provision/mint time — the same act as baking it into the JWT, persisted so the server-side
412
+ * delivery daemon can re-authorize the agent's durable entries and validate its runtime
413
+ * durable-joins without holding any in-memory ledger. Written ATOMICALLY ({@link writeAclRecord}),
414
+ * so a present record is always complete (`[]` = known no-read, never a half-write). */
415
+ commitAcl(targetId: string, allowSubscribe: string[]): Promise<void>;
416
+ /** The server-side delivery daemon's fresh-per-entry ACL read: an owner's CURRENT read ACL
417
+ * (`allowSubscribe`) from the durable registry, or `undefined` if no record (an unknown owner — the
418
+ * reader DEFERS, never drops). A present `[]` (known no-read) returns `[]` (the reader DROPS). */
419
+ aclForOwner(owner: string): Promise<string[] | undefined>;
420
+ /** Lazily open the delivery lease/readiness KV (pre-created at `cotal up`; bind, never create). */
421
+ private deliveryRegistry;
422
+ private encodeLease;
423
+ /** Acquire the single-flight delivery lease for a shard via an ATOMIC CAS create, marked NOT-ready.
424
+ * THROWS if a live lease exists — a loud refusal-to-bind (the daemon exits), never a retry, so two
425
+ * daemons can't split a durable's delivery. A crashed holder's lease auto-expires (bucket TTL),
426
+ * freeing a re-acquire. Acquired BEFORE binding (single-flight gate); {@link markDeliveryLeaseReady}
427
+ * flips it ready AFTER the loops + `ctl.delivery` are bound. Returns the lease revision. */
428
+ acquireDeliveryLease(shardIndex: number): Promise<number>;
429
+ /** Flip the held lease to READY (CAS `kv.update`) AFTER `startPlane3` has bound the loops + the
430
+ * `ctl.delivery` responder — so "lease ready" proves the responder is up, not just that the slot was
431
+ * claimed. Returns the new revision. */
432
+ markDeliveryLeaseReady(shardIndex: number, revision: number): Promise<number>;
433
+ /** Renew the held lease (CAS `kv.update` against `revision`, keeping `ready:true`) to refresh it before
434
+ * the bucket TTL expires it. Returns the new revision. Throws if the revision moved (lost the lease —
435
+ * the daemon should exit). */
436
+ renewDeliveryLease(shardIndex: number, revision: number): Promise<number>;
437
+ /** Release the held lease on clean shutdown so a replacement daemon re-acquires immediately (best
438
+ * effort — a crash just lets the bucket TTL expire it). */
439
+ releaseDeliveryLease(shardIndex: number): Promise<void>;
440
+ /** Read a shard's delivery lease (the daemon-availability signal), or `undefined` if none is live.
441
+ * READ-ONLY surface — drives Component 6's `cotal_channels` delivery-health field (an agent reads it
442
+ * under its own cred, which holds lease-bucket read but no write). */
443
+ readDeliveryLease(shardIndex: number): Promise<DeliveryLeaseInfo | undefined>;
364
444
  /** Privileged: one owner's NON-TOMBSTONED durable memberships as `{channel, generation, activated}` —
365
- * the manager serves this to a connecting agent (via the `listMemberships` self-service op). The agent
366
- * hydrates its leave mirror from the ACTIVATED ones (the confirmed backstops), but the non-activated
367
- * ones are returned too so `leaveChannel` can discover + close a record that still routes under the
368
- * pure-interval predicate (a crash-stuck pending activation) — without reading the privileged KV. */
445
+ * the server-side delivery daemon serves this to a connecting agent (the `listMemberships` op on
446
+ * `ctl.delivery`). The agent seeds its leave mirror from the ACTIVATED ones (the confirmed backstops),
447
+ * but the non-activated ones are returned too so `leaveChannel` can discover + close a record that
448
+ * still routes under the pure-interval predicate (a crash-stuck pending activation) — without reading
449
+ * the privileged KV itself. */
369
450
  ownerMemberships(owner: string): Promise<{
370
451
  channel: string;
371
452
  generation: number;
@@ -385,16 +466,15 @@ export declare class CotalEndpoint extends EventEmitter {
385
466
  * BLOCKER-1: the shared fan-out cursor advances independently of the stream frontier). */
386
467
  private fanoutDeliveredSeq;
387
468
  /**
388
- * Privileged durable-JOIN write (the manager calls this after validating channel ⊆ allowSubscribe;
389
- * {@link provisionMembership} calls it at provision time for boot channels): capture `joinCursor`,
390
- * commit a `durable-active` record (CAS + generation bump), then ACTIVATION CATCH-UP idempotently
391
- * copies `(joinCursor, fence]` into the owner inbox where `fence = max(frontier, fanoutDelivered)` —
392
- * fan-out owns `seq > fence`. Idempotent against a timeout-retry (an already-activated membership
393
- * no-ops). Returns `{durable:false}` (honest degrade) only if the catch-up window was evicted.
469
+ * Privileged durable-JOIN write (v3: the delivery daemon calls this from its `ctl.delivery` handler
470
+ * after validating channel the caller's read ACL): capture `joinCursor`, commit a `durable-active`
471
+ * record (CAS + generation bump), then ACTIVATION CATCH-UP idempotently copies `(joinCursor, fence]`
472
+ * into the owner inbox where `fence = max(frontier, fanoutDelivered)` — fan-out owns `seq > fence`.
473
+ * Idempotent against a timeout-retry (an already-activated membership no-ops). Returns `{durable:false}`
474
+ * (honest degrade) only if the catch-up window was evicted.
394
475
  *
395
- * This writes durable KV + dinbox state with the caller's privileged creds; it does NOT require THIS
396
- * endpoint to host the fan-out/reader loops (those are a space-level manager service). So a
397
- * short-lived provisioner can write a boot membership a separate long-lived manager then delivers.
476
+ * Runs on the daemon (which hosts the fan-out/reader loops + the members KV), so catch-up + the
477
+ * activation fence read are in-process no cross-process cursor read.
398
478
  */
399
479
  durableJoinFor(owner: string, channel: string): Promise<{
400
480
  durable: boolean;
@@ -409,16 +489,45 @@ export declare class CotalEndpoint extends EventEmitter {
409
489
  * `chathist_<id>`/`histLock` — red-team HIGH-8). `evicted` ⇒ the oldest eligible seq aged out under
410
490
  * `discard=Old` (the start seq could not be served), a durable shortfall the caller surfaces. */
411
491
  private catchupCopy;
412
- /** Start the Plane-3 fan-out writer + trusted reader on THIS (privileged) endpoint. `aclFor` maps an
413
- * owner id to its current read ACL for the reader's re-authorization (the manager passes its managed
414
- * set). Call once after connect; idempotent durable creation lets it resume on a manager restart. */
415
- startPlane3(aclFor: (owner: string) => string[] | undefined): Promise<void>;
492
+ /** Start the Plane-3 fan-out writer + trusted reader on THIS (privileged, server-side delivery-daemon)
493
+ * endpoint, AND serve the `ctl.delivery` control service (runtime durable join/leave/list). `aclFor`
494
+ * maps an owner id to its current read ACL for the reader's re-authorization read FRESH per entry
495
+ * from the durable ACL registry (async). Call once after connect; idempotent durable creation lets it
496
+ * resume on a daemon restart. Both the JS loops AND the `ctl.delivery` subscription are (re)bound by
497
+ * {@link armPlane3} on EVERY (re)connect — a reconnect drains the old connection, so re-binding both
498
+ * is required, not optional (the responder would otherwise be lost on a broker blip). */
499
+ startPlane3(aclFor: (owner: string) => MaybePromise<string[] | undefined>): Promise<void>;
500
+ /** Serve one runtime durable-membership control request (the server-side delivery daemon). The caller
501
+ * id is the authenticated subject sender ({@link serveControl} fail-closes on a mismatch). Validation
502
+ * is against the durable ACL registry — the SAME KV the reader re-auths against (single source of
503
+ * truth, no in-memory ledger to drift). */
504
+ private handleDeliveryControl;
505
+ /** Validate the channel ARG shape only — non-blank, valid, concrete (NO ACL check, that is op-specific).
506
+ * Returns the channel on success or a ControlReply error to short-circuit. */
507
+ private checkDurableChannelArg;
508
+ /** JOIN requires the channel be within the caller's CURRENT read ACL (you can't durable-subscribe a
509
+ * channel you may not read). */
510
+ private deliveryJoin;
511
+ /** LEAVE must NOT require current-ACL coverage. Leave fires precisely when the ACL was narrowed/revoked
512
+ * (a refused live sub → {@link closeRefusedMembership}); gating the tombstone on the current ACL would
513
+ * loop forever and leave the SPEC §7 boundary open (the membership could resume if the ACL is later
514
+ * restored). The guards are: authenticated caller (serveControl), concrete channel, a finite generation
515
+ * (the join epoch — without it a stale/replayed leave could tombstone a newer rejoin), and an EXISTING
516
+ * own membership; `durableLeaveFor` → `tombstoneMember` then enforces the generation match. */
517
+ private deliveryLeave;
416
518
  /** (Re)bind the Plane-3 fan-out writer + trusted reader. Idempotent — the durables resume from their
417
519
  * cursor. Called by {@link startPlane3} once AND by {@link connectAndBind} on every (re)connect, so
418
- * a manager-endpoint reconnect RE-ARMS the backstop. Without this, a broker blip would silently kill
520
+ * the delivery daemon's reconnect RE-ARMS the backstop + the ctl.delivery responder. Without this, a broker blip would silently kill
419
521
  * the loops while `durableJoinFor` kept reporting `durable:true` (the impl-review's BLOCKER-1). No-op
420
522
  * unless this endpoint hosts Plane-3 (`this.plane3` set). */
421
523
  private armPlane3;
524
+ /** (Re)register the `ctl.delivery` control responder on the CURRENT connection. A reconnect drains the
525
+ * old connection (the old sub is dead and `clearConnectionScoped` leaves caller-owned subs alone), so
526
+ * this MUST run on every arm — otherwise durable join/leave/list silently lose their responder after a
527
+ * broker blip. The stale sub is dropped (unsubscribed + removed from `this.subs`) before re-creating.
528
+ * `boundReply` is essential here: the daemon holds a wildcard reply-publish grant, so the serve path
529
+ * must reject any reply target outside the authenticated sender's own subtree (confused-deputy fix). */
530
+ private armDeliveryControl;
422
531
  /** Fan-out loop: bind the privileged `fanout` durable on CHAT and route each message (routing only —
423
532
  * the trusted reader is the auth gate). */
424
533
  private runFanout;
@@ -434,13 +543,13 @@ export declare class CotalEndpoint extends EventEmitter {
434
543
  * has moved to DLV — an §8 equivalent per-member at-least-once mechanism). The agent acks DLV. */
435
544
  private readerHandle;
436
545
  /** Agent-side: bind + pump our pre-created Plane-3 DELIVER durable (`dlv_<id>`). Every message here is
437
- * manager-written (DLV is manager-write-only, broker-enforced) and is a CHANNEL message by contract
546
+ * delivery-daemon-written (DLV is delivery-write-only, broker-enforced) and is a CHANNEL message by contract
438
547
  * (the backstop never carries DMs), so `kind=channel` is path-derived (SPEC §4) and the body is
439
548
  * trusted (no spoof-guard). `durable:true` — real JetStream ack, coalesced with the core-sub live
440
549
  * copy by `MeshAgent.ingest`. No-op when the durable isn't present (open mode / not provisioned). */
441
550
  private pumpDlv;
442
- /** Agent-side: request a Plane-3 durable backstop for a channel via the manager (ctl.self). Throws
443
- * when no privileged writer is present (open / manager-less). 30s timeout — activation catch-up may
551
+ /** Agent-side: request a Plane-3 durable backstop for a channel via the server-side delivery daemon (ctl.delivery). Throws
552
+ * when no privileged writer is present (open / no delivery daemon). 30s timeout — activation catch-up may
444
553
  * run before the reply (the window is small, but a busy channel can take more than the 5s default). */
445
554
  durableJoinChannel(channel: string): Promise<{
446
555
  durable: boolean;
@@ -448,7 +557,7 @@ export declare class CotalEndpoint extends EventEmitter {
448
557
  generation?: number;
449
558
  }>;
450
559
  /** Agent-side: release a Plane-3 durable backstop (tombstone membership at the leave cursor). Passes
451
- * the join generation so a stale leave can't tombstone a newer rejoin (the manager validates it). */
560
+ * the join generation so a stale leave can't tombstone a newer rejoin (the delivery daemon validates it). */
452
561
  durableLeaveChannel(channel: string, generation?: number): Promise<void>;
453
562
  /** Fail-closed async cleanup for a channel forced out by a LATE sub.allow refusal (the broker revoked
454
563
  * the live read). The sync sub callback can't await, so this RETRIES the Plane-3 tombstone with capped
@@ -456,7 +565,7 @@ export declare class CotalEndpoint extends EventEmitter {
456
565
  * is reachable, never a silent give-up. While pending, the channel is tracked in
457
566
  * {@link pendingDurableLeave} and surfaced via {@link pendingDurableLeaves} (the connector shows it in
458
567
  * `cotal_channels` as `durable-unclosed`, never ordinary absence). The generation is kept the whole
459
- * time. Authoritative closure of a revoked membership is also the manager's job (revocation). */
568
+ * time. Authoritative closure of a revoked membership is also handled by revocation (rotate creds + tear down). */
460
569
  private closeRefusedMembership;
461
570
  /** Channels with a Plane-3 durable membership whose §7 tombstone is still pending after a refused live
462
571
  * sub (see {@link closeRefusedMembership}) — surfaced by the connector as a `durable-unclosed` state so
@@ -468,15 +577,29 @@ export declare class CotalEndpoint extends EventEmitter {
468
577
  private isNoResponders;
469
578
  /** Agent-side: this session's CURRENT durable memberships (channel + join generation) from the
470
579
  * manager — the agent holds no read on the privileged members KV. `undefined` ⇒ NO control responder
471
- * (open / manager-less, so there is no Plane-3 and no memberships). THROWS on a responder-present RPC
580
+ * (open / no delivery daemon, so there is no Plane-3 and no memberships). THROWS on a responder-present RPC
472
581
  * failure, so a caller can FAIL-CLOSED rather than mistaking a transient error for "no membership". */
473
582
  private fetchMemberships;
474
- /** Agent-side: seed `plane3Channels` with this session's boot durable memberships + generations on
475
- * first connect (the agent holds no read on the privileged members KV). A best-effort OPTIMIZATION: it
476
- * pre-fills the leave-generation mirror + the durable-state surface. If it can't (a transient manager
477
- * error), {@link leaveChannel} re-resolves the generation on demand and fails closed there so a
478
- * missed hydration never silently leaves a boot durable channel untombstonable. */
479
- private hydrateMemberships;
583
+ /** Agent-side, first connect (auth): SELF-JOIN this session's durable boot channels via the
584
+ * server-side delivery daemon replacing the old manager-written boot membership. Each concrete
585
+ * `durable`-class boot channel gets a `durableJoin` whose returned generation seeds the leave mirror
586
+ * + durable-state surface; an already-active membership (a relaunch) is idempotent (no re-catch-up).
587
+ * If the daemon is down/absent at first connect (or reports a transient `durable:false`), the channel
588
+ * is handed to {@link reconcileBootJoin} for capped-backoff retry — so the backstop is RESTORED once
589
+ * the daemon recovers, not left silently live-only. Until a membership exists the channel renders
590
+ * degraded in `cotal_channels` ({@link hasDurableMembership}). */
591
+ private armBootDurableMemberships;
592
+ /** Retry a boot durable self-join with capped backoff until a membership EXISTS (success → seed
593
+ * `plane3Channels`) or the channel is left / the endpoint stops. Mirrors {@link closeRefusedMembership}:
594
+ * a one-shot first-connect attempt that swallowed a daemon outage would leave the boot channel live-only
595
+ * forever after the daemon recovers (and the lease-based health could then read "active" with no owner
596
+ * membership). This loop is the reconcile that closes that gap. Idempotent — a channel already pending
597
+ * is not double-driven; survives reconnect (it re-issues `durableJoinChannel` on the current connection). */
598
+ private reconcileBootJoin;
599
+ /** True if this session holds an established Plane-3 durable membership for `channel` (in `plane3Channels`).
600
+ * Drives the membership-aware delivery-health surface: a joined durable channel that is NOT yet a member
601
+ * (boot self-join pending / daemon down) must render degraded, never "active" off a live lease alone. */
602
+ hasDurableMembership(channel: string): boolean;
480
603
  /** Lazily obtain a JetStream manager — so a non-consuming endpoint (e.g. the supervisor,
481
604
  * consume:false) can still pre-create others' durables. */
482
605
  private manager;
@@ -604,5 +727,25 @@ export declare function isPermissionDenied(e: unknown): boolean;
604
727
  export declare function isReachable(servers?: string, opts?: AuthOpts & {
605
728
  timeoutMs?: number;
606
729
  }): Promise<boolean>;
730
+ /** What a connect attempt told us about the server — the distinction {@link isReachable} flattens.
731
+ * `auth-required` means a server answered but rejected these creds (so it IS up); `unreachable`
732
+ * means nothing answered (refused / timeout / a stale registry entry). */
733
+ export type ProbeResult = {
734
+ ok: true;
735
+ } | {
736
+ ok: false;
737
+ reason: "auth-required";
738
+ } | {
739
+ ok: false;
740
+ reason: "unreachable";
741
+ };
742
+ /** Like {@link isReachable}, but distinguishes "up but won't take these creds" from "nothing there".
743
+ * `spawn` needs the difference: auth-required → name the trust dir + next step; unreachable → the
744
+ * mesh is down (prune the stale entry, tell the user to `cotal up`). Pass `creds` to confirm a
745
+ * specific identity is accepted (`ok`); omit them to probe mere liveness (an auth broker answers
746
+ * `auth-required`, which still proves it's up). */
747
+ export declare function probeConnect(server?: string, opts?: AuthOpts & {
748
+ timeoutMs?: number;
749
+ }): Promise<ProbeResult>;
607
750
  export {};
608
751
  //# sourceMappingURL=endpoint.d.ts.map