@cotal-ai/manager 0.29.2 → 0.30.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.
@@ -0,0 +1,22 @@
1
+ import { type Identity, type RemoteManagerAuthorityMaterial, type RemoteManagerAuthorityRequest } from "@cotal-ai/core";
2
+ interface RemoteManagerIdentityState {
3
+ v: 1;
4
+ space: string;
5
+ instanceId: string;
6
+ lifecycleUid: string;
7
+ identities: {
8
+ supervisor: Identity;
9
+ executor: Identity;
10
+ serve: Identity;
11
+ goalWriter: Identity;
12
+ sessionLedger: Identity;
13
+ };
14
+ }
15
+ /** Load or create one participant-owned manager lifecycle identity. Private seeds never leave it. */
16
+ export declare function loadOrCreateRemoteManagerIdentity(root: string, space: string): RemoteManagerIdentityState;
17
+ export declare function remoteManagerAuthorityRequest(state: RemoteManagerIdentityState, actor: string, operation: RemoteManagerAuthorityRequest["operation"], registrationProof?: string, contractArtifacts?: unknown[], session?: RemoteManagerAuthorityRequest["session"]): RemoteManagerAuthorityRequest;
18
+ /** Combine a host-signed JWT with the participant's private seed, after exact identity checks. */
19
+ export declare function materialCredential(material: RemoteManagerAuthorityMaterial, name: keyof RemoteManagerAuthorityMaterial["credentials"], identity: Identity): string;
20
+ export declare function expectedRemoteManagerActors(state: RemoteManagerIdentityState): import("@cotal-ai/core").RemoteManagerActors;
21
+ export {};
22
+ //# sourceMappingURL=remote-authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-authority.d.ts","sourceRoot":"","sources":["../src/remote-authority.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,KAAK,QAAQ,EACb,KAAK,8BAA8B,EACnC,KAAK,6BAA6B,EACnC,MAAM,gBAAgB,CAAC;AAExB,UAAU,0BAA0B;IAClC,CAAC,EAAE,CAAC,CAAC;IACL,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE;QACV,UAAU,EAAE,QAAQ,CAAC;QACrB,QAAQ,EAAE,QAAQ,CAAC;QACnB,KAAK,EAAE,QAAQ,CAAC;QAChB,UAAU,EAAE,QAAQ,CAAC;QACrB,aAAa,EAAE,QAAQ,CAAC;KACzB,CAAC;CACH;AAgBD,qGAAqG;AACrG,wBAAgB,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,0BAA0B,CAoCzG;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,0BAA0B,EACjC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,6BAA6B,CAAC,WAAW,CAAC,EACrD,iBAAiB,CAAC,EAAE,MAAM,EAC1B,iBAAiB,CAAC,EAAE,OAAO,EAAE,EAC7B,OAAO,CAAC,EAAE,6BAA6B,CAAC,SAAS,CAAC,GACjD,6BAA6B,CAsB/B;AAED,kGAAkG;AAClG,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,8BAA8B,EACxC,IAAI,EAAE,MAAM,8BAA8B,CAAC,aAAa,CAAC,EACzD,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAUR;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,0BAA0B,gDAE5E"}
@@ -0,0 +1,102 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { credsFromJwt, mintLifecycleUid, newIdentity, remoteManagerActors, writeSecretFileAtomic, } from "@cotal-ai/core";
4
+ function stateFile(root, space) {
5
+ return join(root, ".cotal", `remote-manager.${Buffer.from(space, "utf8").toString("hex")}.json`);
6
+ }
7
+ function parseIdentity(v, what) {
8
+ const o = v;
9
+ if (o === null || typeof o !== "object" || typeof o.id !== "string" || typeof o.seed !== "string")
10
+ throw new Error(`${what} is malformed`);
11
+ const identity = { id: o.id, seed: o.seed };
12
+ // A synthetic JWT subject check is unnecessary here; credsFromJwt validates the seed when the
13
+ // host-signed generation is materialized, before any connect.
14
+ return identity;
15
+ }
16
+ /** Load or create one participant-owned manager lifecycle identity. Private seeds never leave it. */
17
+ export function loadOrCreateRemoteManagerIdentity(root, space) {
18
+ const path = stateFile(root, space);
19
+ if (existsSync(path)) {
20
+ let raw;
21
+ try {
22
+ raw = JSON.parse(readFileSync(path, "utf8"));
23
+ }
24
+ catch (e) {
25
+ throw new Error(`${path}: remote manager authority state does not parse (${e.message}); refusing to rotate over it`);
26
+ }
27
+ const o = raw;
28
+ if (o.v !== 1 || o.space !== space || typeof o.instanceId !== "string" || typeof o.lifecycleUid !== "string" || !o.identities)
29
+ throw new Error(`${path}: remote manager authority state is malformed; refusing to mint a fresh instance over it`);
30
+ const state = {
31
+ v: 1, space, instanceId: o.instanceId, lifecycleUid: o.lifecycleUid,
32
+ identities: {
33
+ supervisor: parseIdentity(o.identities.supervisor, "supervisor identity"),
34
+ executor: parseIdentity(o.identities.executor, "executor identity"),
35
+ serve: parseIdentity(o.identities.serve, "serve identity"),
36
+ goalWriter: parseIdentity(o.identities.goalWriter, "goal-writer identity"),
37
+ sessionLedger: parseIdentity(o.identities.sessionLedger, "session-ledger identity"),
38
+ },
39
+ };
40
+ return state;
41
+ }
42
+ const state = {
43
+ v: 1,
44
+ space,
45
+ instanceId: mintLifecycleUid(),
46
+ lifecycleUid: mintLifecycleUid(),
47
+ identities: {
48
+ supervisor: newIdentity(),
49
+ executor: newIdentity(),
50
+ serve: newIdentity(),
51
+ goalWriter: newIdentity(),
52
+ sessionLedger: newIdentity(),
53
+ },
54
+ };
55
+ writeSecretFileAtomic(path, JSON.stringify(state, null, 2));
56
+ return state;
57
+ }
58
+ export function remoteManagerAuthorityRequest(state, actor, operation, registrationProof, contractArtifacts, session) {
59
+ const requestId = `${operation}${mintLifecycleUid()}`;
60
+ return {
61
+ v: 1,
62
+ kind: "manager-service-authority",
63
+ operation,
64
+ space: state.space,
65
+ actor,
66
+ instanceId: state.instanceId,
67
+ managerLifecycleUid: state.lifecycleUid,
68
+ requestId,
69
+ ...(registrationProof ? { registrationProof } : {}),
70
+ ...(contractArtifacts ? { contractArtifacts } : {}),
71
+ ...(session ? { session } : {}),
72
+ identities: {
73
+ supervisor: { id: state.identities.supervisor.id },
74
+ executor: { id: state.identities.executor.id },
75
+ serve: { id: state.identities.serve.id },
76
+ goalWriter: { id: state.identities.goalWriter.id },
77
+ sessionLedger: { id: state.identities.sessionLedger.id },
78
+ },
79
+ };
80
+ }
81
+ /** Combine a host-signed JWT with the participant's private seed, after exact identity checks. */
82
+ export function materialCredential(material, name, identity) {
83
+ const credential = material.credentials[name];
84
+ if (!credential)
85
+ throw new Error(`manager-service ${material.operation} returned no ${name} credential`);
86
+ let claims;
87
+ try {
88
+ claims = JSON.parse(Buffer.from(credential.jwt.split(".")[1] ?? "", "base64url").toString("utf8"));
89
+ }
90
+ catch {
91
+ throw new Error(`manager-service ${name} credential is not a JWT`);
92
+ }
93
+ if (claims.sub !== identity.id)
94
+ throw new Error(`manager-service ${name} JWT is for ${String(claims.sub)}, not the requested identity ${identity.id}`);
95
+ if (claims.exp !== credential.exp || credential.exp * 1000 > material.expiresAt + 1)
96
+ throw new Error(`manager-service ${name} expiry does not match the material envelope`);
97
+ return credsFromJwt(credential.jwt, identity);
98
+ }
99
+ export function expectedRemoteManagerActors(state) {
100
+ return remoteManagerActors(state.instanceId);
101
+ }
102
+ //# sourceMappingURL=remote-authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-authority.js","sourceRoot":"","sources":["../src/remote-authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,mBAAmB,EACnB,qBAAqB,GAItB,MAAM,gBAAgB,CAAC;AAgBxB,SAAS,SAAS,CAAC,IAAY,EAAE,KAAa;IAC5C,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,EAA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IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,SAAS,gBAAgB,IAAI,aAAa,CAAC,CAAC;IACzG,IAAI,MAAwC,CAAC;IAC7C,IAAI,CAAC;QAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAqC,CAAC;IAAC,CAAC;IAC/I,MAAM,CAAC;QAAC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,0BAA0B,CAAC,CAAC;IAAC,CAAC;IAC7E,IAAI,MAAM,CAAC,GAAG,KAAK,QAAQ,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,eAAe,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,gCAAgC,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IACvJ,IAAI,MAAM,CAAC,GAAG,KAAK,UAAU,CAAC,GAAG,IAAI,UAAU,CAAC,GAAG,GAAG,IAAI,GAAG,QAAQ,CAAC,SAAS,GAAG,CAAC;QACjF,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,8CAA8C,CAAC,CAAC;IACzF,OAAO,YAAY,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,KAAiC;IAC3E,OAAO,mBAAmB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { authorizeServeGrant } from "@cotal-ai/core";
2
+ /**
3
+ * Run the registration half with the host-issued prepare credential. The credential is pinned to
4
+ * one manager instance's epgate/epcred/svc/govern/contract surface, so the participant can neither
5
+ * register another endpoint nor publish outside the public content-addressed contract store.
6
+ */
7
+ export declare function registerRemoteManagerAuthority(args: {
8
+ space: string;
9
+ server: string;
10
+ owner: string;
11
+ instanceId: string;
12
+ serveActor: string;
13
+ prepareCreds: string;
14
+ }): Promise<{
15
+ registrationRevision: number;
16
+ processEpoch: number;
17
+ serveGrant: Awaited<ReturnType<typeof authorizeServeGrant>>;
18
+ }>;
19
+ //# sourceMappingURL=remote-register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-register.d.ts","sourceRoot":"","sources":["../src/remote-register.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EAapB,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,wBAAsB,8BAA8B,CAAC,IAAI,EAAE;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC;IAAE,oBAAoB,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAA;CAAE,CAAC,CAyD/H"}
@@ -0,0 +1,73 @@
1
+ import { connect } from "@nats-io/transport-node";
2
+ import { jetstreamManager } from "@nats-io/jetstream";
3
+ import { Kvm } from "@nats-io/kv";
4
+ import { authorizeServeGrant, contractArtifactCanonicalBytes, contractStoreContext, endpointRegistrationBarrier, epAuthBucket, fetchContractArtifact, provisionEndpointGateOpen, publishContractArtifact, recordsBucket, registerServiceInstance, serveIssuanceGateKv, standaloneConnectOpts, } from "@cotal-ai/core";
5
+ import { MANAGER_ENDPOINT, managerAuthorityContractSource, managerClusterArtifacts } from "./manager-service-contract.js";
6
+ /**
7
+ * Run the registration half with the host-issued prepare credential. The credential is pinned to
8
+ * one manager instance's epgate/epcred/svc/govern/contract surface, so the participant can neither
9
+ * register another endpoint nor publish outside the public content-addressed contract store.
10
+ */
11
+ export async function registerRemoteManagerAuthority(args) {
12
+ const nc = await connect({
13
+ servers: args.server,
14
+ ...standaloneConnectOpts({ creds: args.prepareCreds, tls: false }),
15
+ maxReconnectAttempts: 0,
16
+ });
17
+ try {
18
+ const kvm = new Kvm(nc);
19
+ const recordsKv = await kvm.open(recordsBucket(args.space));
20
+ const authKv = await kvm.open(epAuthBucket(args.space));
21
+ const store = await contractStoreContext(nc, args.space);
22
+ const artifacts = managerClusterArtifacts();
23
+ const all = [...managerAuthorityContractSource().artifacts, artifacts.document, artifacts.manifest];
24
+ for (const value of all)
25
+ await publishContractArtifact(store, contractArtifactCanonicalBytes(value));
26
+ const readClusterArtifact = async (digest) => {
27
+ const bytes = await fetchContractArtifact(store, digest);
28
+ return bytes ? JSON.parse(new TextDecoder().decode(bytes)) : undefined;
29
+ };
30
+ const principal = `${args.owner}.${args.serveActor}`;
31
+ const fence = serveIssuanceGateKv(authKv, args.space, { endpoint: MANAGER_ENDPOINT, instanceId: args.instanceId });
32
+ if ((await fence.observe()) === null)
33
+ await provisionEndpointGateOpen(authKv, { endpoint: MANAGER_ENDPOINT, instanceId: args.instanceId, principal });
34
+ const authority = { authorize: (endpoint, owner) => ({ authorized: endpoint === MANAGER_ENDPOINT && owner === args.owner, revision: 0 }) };
35
+ const barrier = endpointRegistrationBarrier(authKv, args.space, {
36
+ endpoint: MANAGER_ENDPOINT,
37
+ instanceId: args.instanceId,
38
+ opId: args.instanceId,
39
+ });
40
+ await registerServiceInstance(recordsKv, {
41
+ space: args.space,
42
+ spec: { endpoint: MANAGER_ENDPOINT, owner: args.owner, clusterDigests: [artifacts.closureDigest], protocol: { v: 1 } },
43
+ instanceId: args.instanceId,
44
+ registrant: { owner: args.owner },
45
+ authority,
46
+ barrier,
47
+ readClusterArtifact,
48
+ });
49
+ const observed = await fence.observe();
50
+ if (observed === null)
51
+ throw new Error("remote manager issuance gate vanished after registration");
52
+ const serveGrant = await authorizeServeGrant(recordsKv, {
53
+ space: args.space,
54
+ endpoint: MANAGER_ENDPOINT,
55
+ instanceId: args.instanceId,
56
+ epoch: observed.processEpoch,
57
+ holder: { owner: args.owner },
58
+ authority,
59
+ readProcessEpoch: async () => {
60
+ const current = await fence.observe();
61
+ if (!current)
62
+ throw new Error("remote manager issuance gate vanished");
63
+ return current.processEpoch;
64
+ },
65
+ readClusterArtifact,
66
+ });
67
+ return { registrationRevision: observed.registrationRevision, processEpoch: observed.processEpoch, serveGrant };
68
+ }
69
+ finally {
70
+ await nc.drain().catch(() => nc.close());
71
+ }
72
+ }
73
+ //# sourceMappingURL=remote-register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote-register.js","sourceRoot":"","sources":["../src/remote-register.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,mBAAmB,EACnB,8BAA8B,EAC9B,oBAAoB,EACpB,2BAA2B,EAC3B,YAAY,EACZ,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,aAAa,EACb,uBAAuB,EACvB,mBAAmB,EACnB,qBAAqB,GAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAE1H;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAAC,IAOpD;IACC,MAAM,EAAE,GAAG,MAAM,OAAO,CAAC;QACvB,OAAO,EAAE,IAAI,CAAC,MAAM;QACpB,GAAG,qBAAqB,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;QAClE,oBAAoB,EAAE,CAAC;KACxB,CAAC,CAA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,gBAAgB;YAC1B,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,KAAK,EAAE,QAAQ,CAAC,YAAY;YAC5B,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE;YAC7B,SAAS;YACT,gBAAgB,EAAE,KAAK,IAAI,EAAE;gBAC3B,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC;gBACtC,IAAI,CAAC,OAAO;oBAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;gBACvE,OAAO,OAAO,CAAC,YAAY,CAAC;YAC9B,CAAC;YACD,mBAAmB;SACpB,CAAC,CAAC;QACH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,UAAU,EAAE,CAAC;IAClH,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pty.d.ts","sourceRoot":"","sources":["../../src/runtime/pty.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAiB,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAoBtF;;;;;GAKG;AACH,qBAAa,UAAW,YAAW,OAAO;IACxC,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAE/B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW;CAuKhE"}
1
+ {"version":3,"file":"pty.d.ts","sourceRoot":"","sources":["../../src/runtime/pty.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAiB,UAAU,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAoBtF;;;;;GAKG;AACH,qBAAa,UAAW,YAAW,OAAO;IACxC,QAAQ,CAAC,IAAI,EAAG,KAAK,CAAU;IAE/B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW;CAgLhE"}
@@ -60,6 +60,11 @@ export class PtyRuntime {
60
60
  let alive = true;
61
61
  let cols = DEFAULT_COLS;
62
62
  let rows = DEFAULT_ROWS;
63
+ // node-pty hands us the child's exit code and killing signal exactly once, and this runtime
64
+ // used to drop them on the floor — leaving the manager unable to say why any seat had died.
65
+ // Retained here so `exitInfo` can answer after the fact; stays undefined while the child lives,
66
+ // because "not exited yet" and "exited cleanly" must never read the same.
67
+ let exit;
63
68
  // Clear Claude's startup gates (workspace-trust, dev-channels warning) by pressing Enter on a
64
69
  // timer during the startup window — see CONFIRM_INTERVAL_MS for why this is blind, not output-
65
70
  // driven. A spawn that opts in sets `spec.confirm` truthy.
@@ -81,8 +86,11 @@ export class PtyRuntime {
81
86
  for (const fn of dataSubs)
82
87
  fn(b);
83
88
  });
84
- proc.onExit(() => {
89
+ proc.onExit(({ exitCode, signal }) => {
85
90
  alive = false;
91
+ // `signal` is absent on an ordinary exit and 0 is a real exit code, so both are recorded as
92
+ // present-or-absent rather than coalesced into one number.
93
+ exit = { code: exitCode, ...(signal === undefined ? {} : { signal }) };
86
94
  if (confirmTimer)
87
95
  clearInterval(confirmTimer);
88
96
  for (const fn of exitSubs)
@@ -93,6 +101,7 @@ export class PtyRuntime {
93
101
  kind: "pty",
94
102
  pid: proc.pid,
95
103
  status: () => (alive ? "running" : "exited"),
104
+ exitInfo: () => exit,
96
105
  stop: (opts) => {
97
106
  if (!alive)
98
107
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"pty.js","sourceRoot":"","sources":["../../src/runtime/pty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,kBAAkB,CAAC;AACxC,OAAO,QAAQ,MAAM,iBAAiB,CAA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M,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC/B,CAAC;aACF,CAAC;SACH,CAAC;IACJ,CAAC;CACF"}
@@ -7,14 +7,13 @@
7
7
  * then sends `ready`; the bridge replays the pty's byte-exact backlog snapshot (which can rebuild
8
8
  * a full-screen TUI's alternate-screen buffer) and only then streams live output — so a late or
9
9
  * third attach paints correctly without the child having to repaint. Live output that arrives
10
- * while the snapshot is being built is buffered and flushed after it, in order (no chunk slips
11
- * ahead of, or is lost before, the image);
12
- * - duplex byte flow: pty output → `b` frames (serving → caller); caller `b` frames → pty
13
- * keystrokes; `resize` frames → pty geometry;
10
+ * after the snapshot boundary is buffered within a hard cap and flushed after it, in order;
11
+ * - duplex byte flow: pty output → bounded, coalesced `b` frames (serving → caller); caller `b`
12
+ * frames pty keystrokes; `resize` frames → pty geometry;
14
13
  * - BACKPRESSURE (item-6 pin: never silent loss): the core rail's window is bounded and refuses
15
14
  * (`resource-exhausted`) rather than buffer; on refusal the bridge DROPS the chunk, accumulates
16
- * the dropped-byte count, and prepends an explicit `drop` notice to the next frame the reopened
17
- * window accepts the caller always learns output was lost;
15
+ * the dropped-byte count, retries an explicit `drop` notice when credit reopens, and the caller
16
+ * automatically requests a fresh canonical snapshot so a full-screen TUI cannot stay corrupt;
18
17
  * - TERMINATION (item-6 pin 4): every teardown surfaces a DISTINCT end reason (`process-exit` /
19
18
  * `closed` / `expired` / `target-despawn` / `manager-restart`) as an `end` frame before the rail
20
19
  * closes, so the client can tell "the agent exited" from "you were detached" from "the manager
@@ -41,6 +40,10 @@ export interface ServeSessionBridgeOpts {
41
40
  /** Passthrough rail timer knobs (testability). */
42
41
  idleCreditMs?: number;
43
42
  stallTimeoutMs?: number;
43
+ /** Output coalescing knobs. Production defaults batch one display frame up to 64 KiB; smokes use
44
+ * the byte ceiling to force deterministic frame-window overflow. */
45
+ outputBatchMs?: number;
46
+ outputBatchBytes?: number;
44
47
  }
45
48
  export interface SessionBridge {
46
49
  /** Terminate the session with a distinct reason (target despawn / manager restart / expiry): the
@@ -56,7 +59,9 @@ export interface SessionBridge {
56
59
  inFlight: number;
57
60
  droppedBytes: number;
58
61
  droppedFrames: number;
62
+ queuedBytes: number;
59
63
  live: boolean;
64
+ repainting: boolean;
60
65
  };
61
66
  }
62
67
  export declare function serveSessionBridge(opts: ServeSessionBridgeOpts): SessionBridge;
@@ -1 +1 @@
1
- {"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/session/bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAEL,KAAK,YAAY,EAAoB,KAAK,aAAa,EACxD,MAAM,gBAAgB,CAAC;AAExB;;;;wFAIwF;AACxF,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG,QAAQ,GAAG,SAAS,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAE3G,MAAM,WAAW,sBAAsB;IACrC;gGAC4F;IAC5F,EAAE,EAAE,cAAc,CAAC;IACnB,qGAAqG;IACrG,KAAK,EAAE,YAAY,CAAC;IACpB,8BAA8B;IAC9B,OAAO,EAAE,aAAa,CAAC;IACvB,yFAAyF;IACzF,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACtC,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,aAAa;IAC5B;yGACqG;IACrG,GAAG,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IACnC;;kDAE8C;IAC9C,KAAK,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAA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