@cogitator-ai/bridge 0.0.0-stage → 0.2.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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +182 -2
  3. package/dist/client.d.ts +74 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +202 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/dispatcher.d.ts +246 -0
  8. package/dist/dispatcher.d.ts.map +1 -0
  9. package/dist/dispatcher.js +1301 -0
  10. package/dist/dispatcher.js.map +1 -0
  11. package/dist/errors.d.ts +10 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +16 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/guards.d.ts +36 -0
  16. package/dist/guards.d.ts.map +1 -0
  17. package/dist/guards.js +85 -0
  18. package/dist/guards.js.map +1 -0
  19. package/dist/host.d.ts +49 -0
  20. package/dist/host.d.ts.map +1 -0
  21. package/dist/host.js +150 -0
  22. package/dist/host.js.map +1 -0
  23. package/dist/index.d.ts +39 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +26 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inputs.d.ts +145 -0
  28. package/dist/inputs.d.ts.map +1 -0
  29. package/dist/inputs.js +93 -0
  30. package/dist/inputs.js.map +1 -0
  31. package/dist/job-record.d.ts +47 -0
  32. package/dist/job-record.d.ts.map +1 -0
  33. package/dist/job-record.js +65 -0
  34. package/dist/job-record.js.map +1 -0
  35. package/dist/letters.d.ts +49 -0
  36. package/dist/letters.d.ts.map +1 -0
  37. package/dist/letters.js +96 -0
  38. package/dist/letters.js.map +1 -0
  39. package/dist/paths.d.ts +32 -0
  40. package/dist/paths.d.ts.map +1 -0
  41. package/dist/paths.js +130 -0
  42. package/dist/paths.js.map +1 -0
  43. package/dist/protocol.d.ts +78 -0
  44. package/dist/protocol.d.ts.map +1 -0
  45. package/dist/protocol.js +66 -0
  46. package/dist/protocol.js.map +1 -0
  47. package/dist/registry.d.ts +62 -0
  48. package/dist/registry.d.ts.map +1 -0
  49. package/dist/registry.js +185 -0
  50. package/dist/registry.js.map +1 -0
  51. package/dist/server.d.ts +31 -0
  52. package/dist/server.d.ts.map +1 -0
  53. package/dist/server.js +249 -0
  54. package/dist/server.js.map +1 -0
  55. package/dist/store/sqlite.d.ts +56 -0
  56. package/dist/store/sqlite.d.ts.map +1 -0
  57. package/dist/store/sqlite.js +737 -0
  58. package/dist/store/sqlite.js.map +1 -0
  59. package/dist/store/store.d.ts +128 -0
  60. package/dist/store/store.d.ts.map +1 -0
  61. package/dist/store/store.js +2 -0
  62. package/dist/store/store.js.map +1 -0
  63. package/dist/types.d.ts +322 -0
  64. package/dist/types.d.ts.map +1 -0
  65. package/dist/types.js +130 -0
  66. package/dist/types.js.map +1 -0
  67. package/package.json +70 -3
package/dist/paths.js ADDED
@@ -0,0 +1,130 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync, realpathSync, statSync } from 'node:fs';
3
+ import { homedir, userInfo } from 'node:os';
4
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ /** The longest path a unix socket takes on macOS, the tighter of the platforms, less the NUL */
6
+ const MAX_SOCKET_PATH = 103;
7
+ function userName() {
8
+ try {
9
+ return userInfo().username;
10
+ }
11
+ catch {
12
+ return 'user';
13
+ }
14
+ }
15
+ function pipeName(home) {
16
+ const tag = createHash('sha256').update(`${userName()}\0${home}`).digest('hex').slice(0, 16);
17
+ return `\\\\.\\pipe\\cogitator-bridge-${tag}`;
18
+ }
19
+ /**
20
+ * The files of the bridge: one folder per machine, shared by every project, so the sessions of
21
+ * all of them meet in one place.
22
+ */
23
+ export function bridgePaths(options = {}) {
24
+ const env = options.env ?? process.env;
25
+ const platform = options.platform ?? process.platform;
26
+ const configured = options.home ?? env.COGITATOR_BRIDGE_HOME?.trim();
27
+ const home = configured ? resolve(configured) : join(homedir(), '.cogitator', 'bridge');
28
+ const socket = platform === 'win32' ? pipeName(home) : join(home, 'bridge.sock');
29
+ if (platform !== 'win32' && Buffer.byteLength(socket) > MAX_SOCKET_PATH) {
30
+ throw new Error(`The bridge socket path is too long for a unix socket (${Buffer.byteLength(socket)} bytes, ` +
31
+ `the limit is ${MAX_SOCKET_PATH}): ${socket}. Set COGITATOR_BRIDGE_HOME to a shorter folder`);
32
+ }
33
+ return { home, database: join(home, 'bridge.db'), socket };
34
+ }
35
+ /** A `.git` file is a line or two. Anything larger is not one, and is not read. */
36
+ const MAX_GIT_FILE_BYTES = 4096;
37
+ function gitEntry(dir) {
38
+ try {
39
+ const stat = statSync(join(dir, '.git'));
40
+ if (stat.isDirectory())
41
+ return 'dir';
42
+ return stat.isFile() && stat.size <= MAX_GIT_FILE_BYTES ? 'file' : undefined;
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ /** The text of a small plain file, or undefined: a pipe, a device or a large file is not read. */
49
+ function readSmallFile(path) {
50
+ try {
51
+ const stat = statSync(path);
52
+ if (!stat.isFile() || stat.size > MAX_GIT_FILE_BYTES)
53
+ return undefined;
54
+ return readFileSync(path, 'utf-8');
55
+ }
56
+ catch {
57
+ return undefined;
58
+ }
59
+ }
60
+ function samePath(a, b) {
61
+ try {
62
+ return realpathSync(a) === realpathSync(b);
63
+ }
64
+ catch {
65
+ return resolve(a) === resolve(b);
66
+ }
67
+ }
68
+ /**
69
+ * The main checkout a linked worktree belongs to, read from its `.git` file
70
+ * (`gitdir: <main>/.git/worktrees/<name>`), or undefined when the file says something else, as
71
+ * the `.git` file of a submodule does, or when the main checkout does not name this folder as
72
+ * its worktree: a folder cannot join a project by claiming it.
73
+ */
74
+ function mainCheckoutOf(worktree) {
75
+ const content = readSmallFile(join(worktree, '.git'));
76
+ const match = content === undefined ? null : /^gitdir:\s*(.+)$/m.exec(content);
77
+ if (!match)
78
+ return undefined;
79
+ const named = match[1].trim();
80
+ const gitDir = isAbsolute(named) ? named : resolve(worktree, named);
81
+ const worktrees = dirname(gitDir);
82
+ if (basename(worktrees) !== 'worktrees')
83
+ return undefined;
84
+ const commonDir = dirname(worktrees);
85
+ if (basename(commonDir) !== '.git')
86
+ return undefined;
87
+ const back = readSmallFile(join(gitDir, 'gitdir'))?.trim();
88
+ if (!back)
89
+ return undefined;
90
+ const claimed = isAbsolute(back) ? back : resolve(gitDir, back);
91
+ return samePath(claimed, join(worktree, '.git')) ? dirname(commonDir) : undefined;
92
+ }
93
+ /** Whether `path` is `folder` or lies inside it. */
94
+ export function isInside(folder, path) {
95
+ const inner = relative(resolve(folder), resolve(path));
96
+ if (inner === '')
97
+ return true;
98
+ return inner !== '..' && !inner.startsWith(`..${sep}`) && !isAbsolute(inner);
99
+ }
100
+ /**
101
+ * The checkout `cwd` is in: the nearest folder up the tree with a `.git`, the main checkout or a
102
+ * linked worktree alike. `cwd` itself when no folder up the tree is a repository.
103
+ */
104
+ export function findCheckoutRoot(cwd) {
105
+ const start = resolve(cwd);
106
+ for (let dir = start;; dir = dirname(dir)) {
107
+ if (gitEntry(dir))
108
+ return dir;
109
+ if (dirname(dir) === dir)
110
+ return start;
111
+ }
112
+ }
113
+ /**
114
+ * The root of the project `cwd` is in: the nearest folder up the tree with a `.git`, and for a
115
+ * linked git worktree the main checkout it belongs to, so every worktree of a repository is one
116
+ * project. `cwd` itself when no folder up the tree is a repository.
117
+ */
118
+ export function findProjectRoot(cwd) {
119
+ const start = resolve(cwd);
120
+ for (let dir = start;; dir = dirname(dir)) {
121
+ const entry = gitEntry(dir);
122
+ if (entry === 'dir')
123
+ return dir;
124
+ if (entry === 'file')
125
+ return mainCheckoutOf(dir) ?? dir;
126
+ if (dirname(dir) === dir)
127
+ return start;
128
+ }
129
+ }
130
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAA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,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,KAAK,KAAK,KAAK;YAAE,OAAO,GAAG,CAAC;QAChC,IAAI,KAAK,KAAK,MAAM;YAAE,OAAO,cAAc,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;QACxD,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;IACzC,CAAC;AACH,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { z } from 'zod';
2
+ import { type JsonRpcError } from '@cogitator-ai/server-shared';
3
+ import { BridgeError } from './errors.js';
4
+ import { type AgentRecord } from './types.js';
5
+ import type { DispatcherStatus } from './dispatcher.js';
6
+ /** The version of the protocol the dispatcher speaks on its socket. */
7
+ export declare const BRIDGE_PROTOCOL_VERSION = 1;
8
+ /** The JSON-RPC methods of the dispatcher. */
9
+ export declare const BRIDGE_METHODS: {
10
+ readonly hello: "bridge/hello";
11
+ readonly status: "bridge/status";
12
+ readonly createJob: "jobs/create";
13
+ readonly getJob: "jobs/get";
14
+ readonly listJobs: "jobs/list";
15
+ readonly cancelJob: "jobs/cancel";
16
+ readonly send: "letters/send";
17
+ readonly inbox: "letters/inbox";
18
+ readonly acknowledge: "letters/acknowledge";
19
+ readonly listLetters: "letters/list";
20
+ readonly listAgents: "agents/list";
21
+ readonly readJournal: "journal/read";
22
+ readonly subscribeJournal: "journal/subscribe";
23
+ readonly unsubscribeJournal: "journal/unsubscribe";
24
+ };
25
+ /** What the dispatcher sends without being asked. */
26
+ export declare const BRIDGE_NOTIFICATIONS: {
27
+ /** An entry of the journal, to a connection that subscribed */
28
+ readonly journalEntry: "journal/entry";
29
+ };
30
+ /** The JSON-RPC error code of every refusal of the bridge. Which one it is lies in `data.code`. */
31
+ export declare const BRIDGE_ERROR_CODE = -32001;
32
+ export declare const HelloParamsSchema: z.ZodObject<{
33
+ caller: z.ZodOptional<z.ZodObject<{
34
+ harness: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
35
+ sessionId: z.ZodString;
36
+ cwd: z.ZodString;
37
+ project: z.ZodOptional<z.ZodString>;
38
+ sessionName: z.ZodOptional<z.ZodString>;
39
+ agentName: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strict>>;
41
+ protocol: z.ZodOptional<z.ZodNumber>;
42
+ }, z.core.$strip>;
43
+ export declare const JobNumberParamsSchema: z.ZodObject<{
44
+ job: z.ZodNumber;
45
+ }, z.core.$strip>;
46
+ export declare const CancelJobParamsSchema: z.ZodObject<{
47
+ job: z.ZodNumber;
48
+ reason: z.ZodOptional<z.ZodString>;
49
+ }, z.core.$strip>;
50
+ export declare const AcknowledgeParamsSchema: z.ZodObject<{
51
+ letter: z.ZodString;
52
+ }, z.core.$strip>;
53
+ export declare const SubscribeJournalParamsSchema: z.ZodObject<{
54
+ job: z.ZodOptional<z.ZodNumber>;
55
+ }, z.core.$strip>;
56
+ /** The dispatcher a connection reached. */
57
+ export interface DispatcherInfo {
58
+ pid: number;
59
+ version: string;
60
+ protocol: number;
61
+ /** ISO 8601 */
62
+ startedAt: string;
63
+ socket: string;
64
+ database: string;
65
+ }
66
+ export interface HelloResult {
67
+ dispatcher: DispatcherInfo;
68
+ /** The agent the connection acts as, when it said who is calling */
69
+ agent?: AgentRecord;
70
+ }
71
+ export interface BridgeStatus extends DispatcherStatus {
72
+ dispatcher: DispatcherInfo;
73
+ }
74
+ /** A refusal of the bridge as it travels over JSON-RPC. */
75
+ export declare function toJsonRpcError(error: BridgeError): JsonRpcError;
76
+ /** The refusal a JSON-RPC error carries, or the error itself when it is something else. */
77
+ export declare function fromJsonRpcError(error: unknown): unknown;
78
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAoB,KAAK,YAAY,EAAE,MAAM,6BAA6B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-0,0 +1,66 @@
1
+ import { z } from 'zod';
2
+ import { JsonRpcCallError } from '@cogitator-ai/server-shared';
3
+ import { BridgeError } from './errors.js';
4
+ import { CallerIdentitySchema } from './types.js';
5
+ /** The version of the protocol the dispatcher speaks on its socket. */
6
+ export const BRIDGE_PROTOCOL_VERSION = 1;
7
+ /** The JSON-RPC methods of the dispatcher. */
8
+ export const BRIDGE_METHODS = {
9
+ hello: 'bridge/hello',
10
+ status: 'bridge/status',
11
+ createJob: 'jobs/create',
12
+ getJob: 'jobs/get',
13
+ listJobs: 'jobs/list',
14
+ cancelJob: 'jobs/cancel',
15
+ send: 'letters/send',
16
+ inbox: 'letters/inbox',
17
+ acknowledge: 'letters/acknowledge',
18
+ listLetters: 'letters/list',
19
+ listAgents: 'agents/list',
20
+ readJournal: 'journal/read',
21
+ subscribeJournal: 'journal/subscribe',
22
+ unsubscribeJournal: 'journal/unsubscribe',
23
+ };
24
+ /** What the dispatcher sends without being asked. */
25
+ export const BRIDGE_NOTIFICATIONS = {
26
+ /** An entry of the journal, to a connection that subscribed */
27
+ journalEntry: 'journal/entry',
28
+ };
29
+ /** The JSON-RPC error code of every refusal of the bridge. Which one it is lies in `data.code`. */
30
+ export const BRIDGE_ERROR_CODE = -32001;
31
+ export const HelloParamsSchema = z.object({
32
+ /** The session calling. Without it the connection can read, and cannot act as an agent */
33
+ caller: CallerIdentitySchema.optional(),
34
+ protocol: z.number().int().positive().optional(),
35
+ });
36
+ export const JobNumberParamsSchema = z.object({ job: z.number().int().positive() });
37
+ export const CancelJobParamsSchema = z.object({
38
+ job: z.number().int().positive(),
39
+ reason: z.string().max(2000).optional(),
40
+ });
41
+ export const AcknowledgeParamsSchema = z.object({ letter: z.string().min(1).max(128) });
42
+ export const SubscribeJournalParamsSchema = z.object({
43
+ /** Only the entries of one job */
44
+ job: z.number().int().positive().optional(),
45
+ });
46
+ /** A refusal of the bridge as it travels over JSON-RPC. */
47
+ export function toJsonRpcError(error) {
48
+ return {
49
+ code: BRIDGE_ERROR_CODE,
50
+ message: error.message,
51
+ data: { ...error.data, code: error.code },
52
+ };
53
+ }
54
+ /** The refusal a JSON-RPC error carries, or the error itself when it is something else. */
55
+ export function fromJsonRpcError(error) {
56
+ if (!(error instanceof JsonRpcCallError) || error.code !== BRIDGE_ERROR_CODE)
57
+ return error;
58
+ const data = error.data;
59
+ if (typeof data !== 'object' || data === null || !('code' in data))
60
+ return error;
61
+ const { code, ...rest } = data;
62
+ if (typeof code !== 'string')
63
+ return error;
64
+ return new BridgeError(code, error.message, Object.keys(rest).length > 0 ? rest : undefined);
65
+ }
66
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAqB,MAAM,6BAA6B,CAAC;AAClF,OAAO,EAAE,WAAW,EAAwB,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAoB,MAAM,YAAY,CAAC;AAGpE,uEAAuE;AACvE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,8CAA8C;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,cAAc;IACrB,MAAM,EAAE,eAAe;IACvB,SAAS,EAAE,aAAa;IACxB,MAAM,EAAE,UAAU;IAClB,QAAQ,EAAE,WAAW;IACrB,SAAS,EAAE,aAAa;IACxB,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,eAAe;IACtB,WAAW,EAAE,qBAAqB;IAClC,WAAW,EAAE,cAAc;IAC3B,UAAU,EAAE,aAAa;IACzB,WAAW,EAAE,cAAc;IAC3B,gBAAgB,EAAE,mBAAmB;IACrC,kBAAkB,EAAE,qBAAqB;CACjC,CAAC;AAEX,qDAAqD;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,+DAA+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AiB;QACvB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,IAAI,EAAE,EAAE,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE;KAC1C,CAAC;AACJ,CAAC;AAED,2FAA2F;AAC3F,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC7C,IAAI,CAAC,CAAC,KAAK,YAAY,gBAAgB,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;QAAE,OAAO,KAAK,CAAC;IAC3F,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;IACxB,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACjF,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,IAAmD,CAAC;IAC9E,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,IAAI,WAAW,CACpB,IAAuB,EACvB,KAAK,CAAC,OAAO,EACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAChD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,62 @@
1
+ import type { BridgeStore } from './store/store.js';
2
+ import { type AgentRecord, type CallerIdentity } from './types.js';
3
+ /** The environment variable each harness tells its session id in. */
4
+ export declare const HARNESS_SESSION_ENV: ReadonlyArray<{
5
+ harness: string;
6
+ variable: string;
7
+ }>;
8
+ /** Says which harness is calling when the environment names more than one session. */
9
+ export declare const HARNESS_ENV = "COGITATOR_BRIDGE_HARNESS";
10
+ /** The name the bridge gave a session it started, set in that session's environment. */
11
+ export declare const AGENT_NAME_ENV = "COGITATOR_BRIDGE_AGENT";
12
+ /** What a person calls the session, when the harness or its adapter tells. */
13
+ export declare const SESSION_NAME_ENV = "COGITATOR_BRIDGE_SESSION_NAME";
14
+ /** Asks for a fresh session in an address: `codex:new`. */
15
+ export declare const NEW_SESSION = "new";
16
+ /** The harness an address names: `claude` is `claude-code`, any other word is itself. */
17
+ export declare function harnessOfAlias(alias: string): string;
18
+ /** The short word a harness goes by in agent names: `claude-code` is `claude`. */
19
+ export declare function aliasOfHarness(harness: string): string;
20
+ /** The project's folder name, made safe for an agent name: no spaces, `@` or `:`. */
21
+ export declare function projectLabel(project: string): string;
22
+ /**
23
+ * Who calls the bridge, from the environment its harness gave it: the session id of Claude Code
24
+ * (`CLAUDE_CODE_SESSION_ID`) or Codex (`CODEX_THREAD_ID`). Undefined when the environment names
25
+ * no session, as in a person's own shell.
26
+ *
27
+ * @throws BridgeError `not_registered` when the environment names sessions of several harnesses
28
+ * (one runs inside the other) and `COGITATOR_BRIDGE_HARNESS` does not say which one is calling
29
+ */
30
+ export declare function callerFromEnv(env: NodeJS.ProcessEnv, cwd: string): CallerIdentity | undefined;
31
+ /** A name nobody in the book has: `codex@demo`, then `codex-2@demo`, `codex-3@demo`. */
32
+ export declare function allocateAgentName(store: BridgeStore, harness: string, project: string): string;
33
+ /** Who an address reaches: a session in the book, or one the bridge has to start. */
34
+ export type AddressResolution = {
35
+ kind: 'agent';
36
+ agent: AgentRecord;
37
+ } | {
38
+ kind: 'spawn';
39
+ harness: string;
40
+ sessionName?: string;
41
+ };
42
+ export interface ResolveAddressContext {
43
+ /** The project of the caller: a harness word reaches the sessions of this project */
44
+ project: string;
45
+ /** The caller, never a candidate itself */
46
+ caller: string;
47
+ /** Whether the bridge can start a session of the harness */
48
+ canSpawn: (harness: string) => boolean;
49
+ /** Ms since the epoch, to say how long ago each of several sessions was heard from */
50
+ now?: number;
51
+ }
52
+ /**
53
+ * Finds who an address means. An address is an agent's name (`codex-2@demo`), or a harness word
54
+ * (`codex`, `claude`) that reaches the sessions of that harness in the caller's project: the
55
+ * only one there is, or the one named after a colon by its session name or id (`codex:reviewer`),
56
+ * or a new one when there is none or `codex:new` asks for it.
57
+ *
58
+ * @throws BridgeError `unknown_agent` for a name nobody has, `ambiguous_agent` when several
59
+ * sessions fit, `no_session` when a session would have to be started and the bridge cannot
60
+ */
61
+ export declare function resolveAddress(store: BridgeStore, address: string, context: ResolveAddressContext): AddressResolution;
62
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAa,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAE9E,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAGpF,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,WAAW,6BAA6B,CAAC;AAEtD,wFAAwF;AACxF,eAAO,MAAM,cAAc,2BAA2B,CAAC;AAEvD,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,kCAAkC,CAAC;AAMhE,2DAA2D;AAC3D,eAAO,MAAM,WAAW,QAAQ,CAAC;AAKjC,yFAAyF;AACzF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGpD;AAED,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtD;AAED,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAKpD;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAuC7F;AAED,wFAAwF;AACxF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAO9F;AAED,qFAAqF;AACrF,MAAM,MAAM,iBAAiB,GAC3B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnG,MAAM,WAAW,qBAAqB;IACpC,qFAAqF;IACrF,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACvC,sFAAsF;IACtF,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAgCD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,qBAAqB,GAC7B,iBAAiB,CA0EnB"}
@@ -0,0 +1,185 @@
1
+ import { basename, resolve } from 'node:path';
2
+ import { BridgeError } from './errors.js';
3
+ import { findProjectRoot } from './paths.js';
4
+ import { HARNESSES } from './types.js';
5
+ /** The environment variable each harness tells its session id in. */
6
+ export const HARNESS_SESSION_ENV = [
7
+ { harness: HARNESSES.claudeCode, variable: 'CLAUDE_CODE_SESSION_ID' },
8
+ { harness: HARNESSES.codex, variable: 'CODEX_THREAD_ID' },
9
+ ];
10
+ /** Says which harness is calling when the environment names more than one session. */
11
+ export const HARNESS_ENV = 'COGITATOR_BRIDGE_HARNESS';
12
+ /** The name the bridge gave a session it started, set in that session's environment. */
13
+ export const AGENT_NAME_ENV = 'COGITATOR_BRIDGE_AGENT';
14
+ /** What a person calls the session, when the harness or its adapter tells. */
15
+ export const SESSION_NAME_ENV = 'COGITATOR_BRIDGE_SESSION_NAME';
16
+ const ALIASES = {
17
+ claude: HARNESSES.claudeCode,
18
+ };
19
+ /** Asks for a fresh session in an address: `codex:new`. */
20
+ export const NEW_SESSION = 'new';
21
+ /** The shortest piece of a session id an address may name it by. */
22
+ const MIN_ID_PREFIX = 4;
23
+ /** The harness an address names: `claude` is `claude-code`, any other word is itself. */
24
+ export function harnessOfAlias(alias) {
25
+ const key = alias.trim().toLowerCase();
26
+ return ALIASES[key] ?? key;
27
+ }
28
+ /** The short word a harness goes by in agent names: `claude-code` is `claude`. */
29
+ export function aliasOfHarness(harness) {
30
+ const alias = Object.entries(ALIASES).find(([, name]) => name === harness)?.[0];
31
+ return alias ?? harness;
32
+ }
33
+ /** The project's folder name, made safe for an agent name: no spaces, `@` or `:`. */
34
+ export function projectLabel(project) {
35
+ const label = basename(project)
36
+ .replace(/[^\p{L}\p{N}._-]+/gu, '-')
37
+ .replace(/^-+|-+$/g, '');
38
+ return label || 'project';
39
+ }
40
+ /**
41
+ * Who calls the bridge, from the environment its harness gave it: the session id of Claude Code
42
+ * (`CLAUDE_CODE_SESSION_ID`) or Codex (`CODEX_THREAD_ID`). Undefined when the environment names
43
+ * no session, as in a person's own shell.
44
+ *
45
+ * @throws BridgeError `not_registered` when the environment names sessions of several harnesses
46
+ * (one runs inside the other) and `COGITATOR_BRIDGE_HARNESS` does not say which one is calling
47
+ */
48
+ export function callerFromEnv(env, cwd) {
49
+ const present = HARNESS_SESSION_ENV.flatMap(({ harness, variable }) => {
50
+ const sessionId = env[variable]?.trim();
51
+ return sessionId ? [{ harness, variable, sessionId }] : [];
52
+ });
53
+ if (present.length === 0)
54
+ return undefined;
55
+ const chosen = env[HARNESS_ENV]?.trim();
56
+ let session = present[0];
57
+ if (chosen) {
58
+ const harness = harnessOfAlias(chosen);
59
+ const match = present.find((candidate) => candidate.harness === harness);
60
+ if (!match) {
61
+ throw new BridgeError('not_registered', `${HARNESS_ENV} is "${chosen}", but the environment has no session id of that harness`);
62
+ }
63
+ session = match;
64
+ }
65
+ else if (present.length > 1) {
66
+ throw new BridgeError('not_registered', `The environment names sessions of several harnesses (${present.map((p) => p.variable).join(', ')}): ` +
67
+ `one runs inside the other. Set ${HARNESS_ENV} to the one that is calling`, { harnesses: present.map((p) => p.harness) });
68
+ }
69
+ const agentName = env[AGENT_NAME_ENV]?.trim();
70
+ const sessionName = env[SESSION_NAME_ENV]?.trim();
71
+ const folder = resolve(cwd);
72
+ return {
73
+ harness: session.harness,
74
+ sessionId: session.sessionId,
75
+ cwd: folder,
76
+ project: findProjectRoot(folder),
77
+ ...(sessionName && { sessionName }),
78
+ ...(agentName && { agentName }),
79
+ };
80
+ }
81
+ /** A name nobody in the book has: `codex@demo`, then `codex-2@demo`, `codex-3@demo`. */
82
+ export function allocateAgentName(store, harness, project) {
83
+ const alias = aliasOfHarness(harness);
84
+ const label = projectLabel(project);
85
+ for (let index = 1;; index += 1) {
86
+ const name = index === 1 ? `${alias}@${label}` : `${alias}-${index}@${label}`;
87
+ if (!store.getAgent(name))
88
+ return name;
89
+ }
90
+ }
91
+ function heardFrom(agent, now) {
92
+ if (agent.status === 'starting')
93
+ return 'starting';
94
+ if (now === undefined)
95
+ return undefined;
96
+ const minutes = Math.max(0, Math.round((now - Date.parse(agent.lastSeenAt)) / 60_000));
97
+ if (minutes < 1)
98
+ return 'heard from just now';
99
+ if (minutes < 90)
100
+ return `heard from ${minutes} min ago`;
101
+ return `heard from ${Math.round(minutes / 60)} h ago`;
102
+ }
103
+ function describe(agent, now) {
104
+ const details = [
105
+ agent.sessionName ? `"${agent.sessionName}"` : undefined,
106
+ heardFrom(agent, now),
107
+ ].filter((detail) => detail !== undefined);
108
+ return details.length > 0 ? `${agent.name} (${details.join(', ')})` : agent.name;
109
+ }
110
+ function matchSession(candidates, wanted) {
111
+ const needle = wanted.toLowerCase();
112
+ const byName = candidates.filter((agent) => agent.sessionName?.toLowerCase() === needle);
113
+ if (byName.length > 0)
114
+ return byName;
115
+ const byId = candidates.filter((agent) => agent.sessionId === wanted);
116
+ if (byId.length > 0)
117
+ return byId;
118
+ return candidates.filter((agent) => agent.sessionName?.toLowerCase().startsWith(needle) === true ||
119
+ (wanted.length >= MIN_ID_PREFIX && agent.sessionId.startsWith(wanted)));
120
+ }
121
+ /**
122
+ * Finds who an address means. An address is an agent's name (`codex-2@demo`), or a harness word
123
+ * (`codex`, `claude`) that reaches the sessions of that harness in the caller's project: the
124
+ * only one there is, or the one named after a colon by its session name or id (`codex:reviewer`),
125
+ * or a new one when there is none or `codex:new` asks for it.
126
+ *
127
+ * @throws BridgeError `unknown_agent` for a name nobody has, `ambiguous_agent` when several
128
+ * sessions fit, `no_session` when a session would have to be started and the bridge cannot
129
+ */
130
+ export function resolveAddress(store, address, context) {
131
+ const text = address.trim();
132
+ if (!text)
133
+ throw new BridgeError('invalid_input', 'The address is empty');
134
+ if (text.includes('@')) {
135
+ const agent = store.getAgent(text);
136
+ if (!agent) {
137
+ throw new BridgeError('unknown_agent', `There is no agent ${text}`, { address: text });
138
+ }
139
+ if (agent.status === 'gone') {
140
+ throw new BridgeError('unknown_agent', `${text} is gone: its session could not be started, or has not called the bridge for a long time. It is back as soon as it calls again`, { address: text });
141
+ }
142
+ if (agent.name === context.caller) {
143
+ throw new BridgeError('invalid_input', 'An agent cannot hand a job to itself');
144
+ }
145
+ return { kind: 'agent', agent };
146
+ }
147
+ const colon = text.indexOf(':');
148
+ const harness = harnessOfAlias(colon === -1 ? text : text.slice(0, colon));
149
+ const wanted = colon === -1 ? undefined : text.slice(colon + 1).trim();
150
+ if (wanted === '') {
151
+ throw new BridgeError('invalid_input', `The address "${text}" names no session after the colon`);
152
+ }
153
+ if (wanted?.startsWith('-')) {
154
+ throw new BridgeError('invalid_input', `A session name does not start with "-": "${wanted}" would read as an option of the command that starts it`);
155
+ }
156
+ const candidates = store
157
+ .listAgents({ project: context.project, harness, statuses: ['active', 'starting'] })
158
+ .filter((agent) => agent.name !== context.caller);
159
+ const spawn = (sessionName) => {
160
+ if (context.canSpawn(harness)) {
161
+ return { kind: 'spawn', harness, ...(sessionName && { sessionName }) };
162
+ }
163
+ const known = candidates.map((agent) => describe(agent, context.now));
164
+ throw new BridgeError('no_session', known.length > 0
165
+ ? `No ${harness} session "${sessionName}" works in this project, and the bridge cannot start one. Sessions here: ${known.join(', ')}`
166
+ : `No ${harness} session works in this project, and the bridge cannot start one. Open one and let it call the bridge once`, { harness, sessions: candidates.map((agent) => agent.name) });
167
+ };
168
+ if (wanted?.toLowerCase() === NEW_SESSION)
169
+ return spawn();
170
+ if (wanted !== undefined) {
171
+ const matches = matchSession(candidates, wanted);
172
+ if (matches.length === 1)
173
+ return { kind: 'agent', agent: matches[0] };
174
+ if (matches.length === 0)
175
+ return spawn(wanted);
176
+ throw new BridgeError('ambiguous_agent', `"${wanted}" fits several ${harness} sessions: ${matches.map((agent) => describe(agent, context.now)).join(', ')}. Use the agent's name`, { harness, sessions: matches.map((agent) => agent.name) });
177
+ }
178
+ if (candidates.length === 1)
179
+ return { kind: 'agent', agent: candidates[0] };
180
+ if (candidates.length === 0)
181
+ return spawn();
182
+ throw new BridgeError('ambiguous_agent', `Several ${harness} sessions work in this project: ${candidates.map((agent) => describe(agent, context.now)).join(', ')}. ` +
183
+ `Name one (${text}:<session name> or its agent name), or ask for a fresh one with ${text}:${NEW_SESSION}`, { harness, sessions: candidates.map((agent) => agent.name) });
184
+ }
185
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAyC,MAAM,YAAY,CAAC;AAE9E,qEAAqE;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAyD;IACvF,EAAE,OAAO,EAAE,SAAS,CAAC,UAAU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AC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAC1D,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5E,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,EAAE,CAAC;IAC5C,MAAM,IAAI,WAAW,CACnB,iBAAiB,EACjB,WAAW,OAAO,mCAAmC,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACzH,aAAa,IAAI,mEAAmE,IAAI,IAAI,WAAW,EAAE,EAC3G,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAC7D,CAAC;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { BridgeDispatcher } from './dispatcher.js';
2
+ import { type DispatcherInfo } from './protocol.js';
3
+ export interface BridgeServerOptions {
4
+ dispatcher: BridgeDispatcher;
5
+ /** A unix socket path, or a named pipe on Windows */
6
+ socketPath: string;
7
+ info: DispatcherInfo;
8
+ /** Hears what went wrong on a connection outside a call */
9
+ onError?: (error: Error) => void;
10
+ }
11
+ export interface BridgeServer {
12
+ /** How many connections are open */
13
+ readonly connections: number;
14
+ /**
15
+ * Ends every connection and stops listening, which removes the socket file. With `abandon`
16
+ * the file is left alone: a dispatcher that was replaced must not remove the socket its
17
+ * successor now listens on at the same path, so it only stops serving
18
+ */
19
+ close(options?: {
20
+ abandon?: boolean;
21
+ }): Promise<void>;
22
+ }
23
+ /**
24
+ * Serves a dispatcher on a socket of this machine: JSON-RPC 2.0, one message per line. A
25
+ * connection says which session is calling with `bridge/hello`, and acts as that agent from then
26
+ * on. The calls of one connection are handled in the order they were written, one at a time, so
27
+ * a call written right behind the hello already acts as the agent. Whoever serves must hold the dispatcher's lease: a socket file left by a dispatcher that
28
+ * died is removed.
29
+ */
30
+ export declare function serveBridge(options: BridgeServerOptions): Promise<BridgeServer>;
31
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAWL,KAAK,cAAc,EAEpB,MAAM,eAAe,CAAC;AASvB,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,gBAAgB,CAAC;IAC7B,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,cAAc,CAAC;IACrB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B;;;;OAIG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAwMD;;;;;;GAMG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAuDrF"}