@concord-ai/concord-mcp 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -28
- package/dist/artifacts/work-state-view.d.ts +8 -0
- package/dist/artifacts/work-state-view.js +19 -0
- package/dist/artifacts/work-state-view.js.map +1 -1
- package/dist/cli/commands/doctor.js +7 -0
- package/dist/cli/commands/doctor.js.map +1 -1
- package/dist/cli/commands/setup.d.ts +21 -0
- package/dist/cli/commands/setup.js +117 -0
- package/dist/cli/commands/setup.js.map +1 -0
- package/dist/cli/index.js +2 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/db/index.d.ts +7 -1
- package/dist/db/index.js +4 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/repositories/agent-endpoints.d.ts +22 -0
- package/dist/db/repositories/agent-endpoints.js +87 -0
- package/dist/db/repositories/agent-endpoints.js.map +1 -0
- package/dist/db/repositories/agent-messages.d.ts +25 -0
- package/dist/db/repositories/agent-messages.js +151 -0
- package/dist/db/repositories/agent-messages.js.map +1 -0
- package/dist/db/rows.d.ts +51 -0
- package/dist/db/rows.js +104 -0
- package/dist/db/rows.js.map +1 -1
- package/dist/db/schema.js +64 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/domain/operations.d.ts +1 -1
- package/dist/domain/schemas.d.ts +9 -2
- package/dist/domain/schemas.js +21 -2
- package/dist/domain/schemas.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/install/agent-communications.d.ts +28 -0
- package/dist/install/agent-communications.js +61 -0
- package/dist/install/agent-communications.js.map +1 -0
- package/dist/install/instructions.d.ts +3 -3
- package/dist/install/instructions.js +5 -4
- package/dist/install/instructions.js.map +1 -1
- package/dist/install/mcp-config.d.ts +1 -1
- package/dist/install/mcp-config.js +9 -3
- package/dist/install/mcp-config.js.map +1 -1
- package/dist/relay/adapters.d.ts +33 -0
- package/dist/relay/adapters.js +70 -0
- package/dist/relay/adapters.js.map +1 -0
- package/dist/relay/index.d.ts +4 -0
- package/dist/relay/index.js +5 -0
- package/dist/relay/index.js.map +1 -0
- package/dist/relay/protocol.d.ts +64 -0
- package/dist/relay/protocol.js +38 -0
- package/dist/relay/protocol.js.map +1 -0
- package/dist/relay/server.d.ts +40 -0
- package/dist/relay/server.js +196 -0
- package/dist/relay/server.js.map +1 -0
- package/dist/relay/socket-dispatcher.d.ts +9 -0
- package/dist/relay/socket-dispatcher.js +74 -0
- package/dist/relay/socket-dispatcher.js.map +1 -0
- package/dist/server.d.ts +4 -1
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tools/agent-messages.d.ts +45 -0
- package/dist/tools/agent-messages.js +158 -0
- package/dist/tools/agent-messages.js.map +1 -0
- package/dist/tools/get-task-context.d.ts +2 -1
- package/dist/tools/get-task-context.js +1 -0
- package/dist/tools/get-task-context.js.map +1 -1
- package/dist/tools/workflow.d.ts +11 -2
- package/dist/tools/workflow.js +152 -30
- package/dist/tools/workflow.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/workspaces/manager.js +6 -0
- package/dist/workspaces/manager.js.map +1 -1
- package/package.json +7 -1
- package/dist/cli/commands/init.d.ts +0 -6
- package/dist/cli/commands/init.js +0 -33
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/install.d.ts +0 -2
- package/dist/cli/commands/install.js +0 -44
- package/dist/cli/commands/install.js.map +0 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { delimiter, join } from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const communicationProviderValues = ['codex', 'claude', 'cursor'];
|
|
5
|
+
const configSchema = z.object({
|
|
6
|
+
version: z.literal(1),
|
|
7
|
+
approved: z.boolean(),
|
|
8
|
+
providers: z.array(z.enum(communicationProviderValues)),
|
|
9
|
+
transport: z.literal('local-socket'),
|
|
10
|
+
});
|
|
11
|
+
export const AGENT_COMMUNICATION_CONFIG = 'agent-integrations.json';
|
|
12
|
+
export function agentCommunicationConfigPath(concordPath) {
|
|
13
|
+
return join(concordPath, AGENT_COMMUNICATION_CONFIG);
|
|
14
|
+
}
|
|
15
|
+
function executableExists(name, env) {
|
|
16
|
+
const path = env['PATH'];
|
|
17
|
+
if (path === undefined)
|
|
18
|
+
return false;
|
|
19
|
+
const suffixes = process.platform === 'win32' ? ['', '.exe', '.cmd', '.bat'] : [''];
|
|
20
|
+
return path
|
|
21
|
+
.split(delimiter)
|
|
22
|
+
.some((directory) => suffixes.some((suffix) => existsSync(join(directory, `${name}${suffix}`))));
|
|
23
|
+
}
|
|
24
|
+
/** Detect supported clients without executing them or mutating client state. */
|
|
25
|
+
export function detectCommunicationProviders(repoRoot, env = process.env) {
|
|
26
|
+
const detected = [];
|
|
27
|
+
if (executableExists('codex', env) || existsSync(join(repoRoot, '.codex')))
|
|
28
|
+
detected.push('codex');
|
|
29
|
+
if (executableExists('claude', env) || existsSync(join(repoRoot, '.claude'))) {
|
|
30
|
+
detected.push('claude');
|
|
31
|
+
}
|
|
32
|
+
if (executableExists('cursor', env) || existsSync(join(repoRoot, '.cursor'))) {
|
|
33
|
+
detected.push('cursor');
|
|
34
|
+
}
|
|
35
|
+
return detected;
|
|
36
|
+
}
|
|
37
|
+
export function readAgentCommunicationConfig(concordPath) {
|
|
38
|
+
const path = agentCommunicationConfigPath(concordPath);
|
|
39
|
+
if (!existsSync(path))
|
|
40
|
+
return undefined;
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
43
|
+
return configSchema.parse(parsed);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Persist the user's one-time integration decision in ignored local state. */
|
|
50
|
+
export function writeAgentCommunicationConfig(concordPath, approved, providers) {
|
|
51
|
+
const path = agentCommunicationConfigPath(concordPath);
|
|
52
|
+
const config = {
|
|
53
|
+
version: 1,
|
|
54
|
+
approved,
|
|
55
|
+
providers: approved ? [...providers] : [],
|
|
56
|
+
transport: 'local-socket',
|
|
57
|
+
};
|
|
58
|
+
writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, { mode: 0o600 });
|
|
59
|
+
return path;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=agent-communications.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-communications.js","sourceRoot":"","sources":["../../src/install/agent-communications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAGlF,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACrB,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE;IACrB,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IACvD,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;CACrC,CAAC,CAAC;AAGH,MAAM,CAAC,MAAM,0BAA0B,GAAG,yBAAyB,CAAC;AAEpE,MAAM,UAAU,4BAA4B,CAAC,WAAmB;IAC9D,OAAO,IAAI,CAAC,WAAW,EAAE,0BAA0B,CAAC,CAAC;AACvD,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY,EAAE,GAAsB;IAC5D,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;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B,MAAM,IAAI,GAAG,4BAA4B,CAAC,WAAW,CAAC,CAAC;IACvD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,SAAS,CAAC;IACxC,IAAI,CAAC;QACH,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/D,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,6BAA6B,CAC3C,WAAmB,EACnB,QAAiB,EACjB,SAA2C;IAE3C,MAAM,IAAI,GAAG,4BAA4B,CAAC,WAAW,CAAC,CAAC;IACvD,MAAM,MAAM,GAA6B;QACvC,OAAO,EAAE,CAAC;QACV,QAAQ;QACR,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE;QACzC,SAAS,EAAE,cAAc;KAC1B,CAAC;IACF,aAAa,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Version of the generated agent workflow contract. */
|
|
2
|
-
export declare const CONCORD_INSTRUCTION_VERSION = "
|
|
2
|
+
export declare const CONCORD_INSTRUCTION_VERSION = "2";
|
|
3
3
|
/** Concise MCP-native guidance, versioned with the running server. */
|
|
4
|
-
export declare const CONCORD_SERVER_INSTRUCTIONS = "Concord coordinates coding agents through five workflow tools.\n- Call start_work before editing. It registers your agent, claims or accepts the task, and reports overlaps.\n- Use inspect_work to read workspace or
|
|
4
|
+
export declare const CONCORD_SERVER_INSTRUCTIONS = "Concord coordinates coding agents through five workflow tools.\n- Call start_work before editing. It registers your agent, claims or accepts the task, and reports overlaps.\n- Use inspect_work to read workspace, task, agent, or message context. Use update_work for durable progress or to prompt/reply to another promptable workspace agent, including while that agent is busy.\n- Use transfer_work for assignment, acceptance, decline, release, reassignment, evidence-bearing handoff offers, and reopening.\n- Call finish_work before finishing, review, or closure with changed files, tests, assumptions, decisions, risks, and provenance.\nKeep claims small and resolve reported overlaps before editing.";
|
|
5
5
|
/** Canonical fallback block written into supported client instruction files. */
|
|
6
|
-
export declare const CONCORD_INSTRUCTIONS = "## Concord \u2014 shared work-state for coding agents\n\n<!-- concord:workflow-version=
|
|
6
|
+
export declare const CONCORD_INSTRUCTIONS = "## Concord \u2014 shared work-state for coding agents\n\n<!-- concord:workflow-version=2 -->\n\nThis project uses Concord MCP. Keep coordination to the five workflow tools:\n\n- **Before editing**, call `start_work` with the task, your agent kind/id, and\n expected files or modules. It registers presence, accepts assigned work when\n appropriate, claims the scope, and returns overlap warnings.\n- Use `inspect_work` to read the workspace, one task, one agent, or one message\n thread. Use `update_work` for durable progress and for live prompts/replies\n to another promptable workspace agent, including while that agent is busy.\n- Use `transfer_work` for assignment, acceptance, decline, release,\n reassignment, evidence-bearing handoff offers, and reopening.\n- **Before finishing**, call `finish_work` once with the outcome, changed\n files, tests, assumptions, decisions, risks, guardrails, and provenance. It\n records evidence and can mark work review-ready or terminal.\n\nKeep each claim small and resolve reported overlaps before editing. Concord\nregenerates human-readable review artifacts in `.concord/`.\n\nEnforcement remains client-dependent. `concord doctor` reports setup and\nworkflow adoption; optional hooks can block exact-file collisions.";
|
|
7
7
|
/** MDC frontmatter used when creating a fresh Cursor rules file. */
|
|
8
8
|
export declare const CURSOR_MDC_HEADER = "---\ndescription: Concord shared work-state tools for coding agents\nalwaysApply: true\n---\n";
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Version of the generated agent workflow contract. */
|
|
2
|
-
export const CONCORD_INSTRUCTION_VERSION = '
|
|
2
|
+
export const CONCORD_INSTRUCTION_VERSION = '2';
|
|
3
3
|
/** Concise MCP-native guidance, versioned with the running server. */
|
|
4
4
|
export const CONCORD_SERVER_INSTRUCTIONS = `Concord coordinates coding agents through five workflow tools.
|
|
5
5
|
- Call start_work before editing. It registers your agent, claims or accepts the task, and reports overlaps.
|
|
6
|
-
- Use inspect_work to read workspace or
|
|
6
|
+
- Use inspect_work to read workspace, task, agent, or message context. Use update_work for durable progress or to prompt/reply to another promptable workspace agent, including while that agent is busy.
|
|
7
7
|
- Use transfer_work for assignment, acceptance, decline, release, reassignment, evidence-bearing handoff offers, and reopening.
|
|
8
8
|
- Call finish_work before finishing, review, or closure with changed files, tests, assumptions, decisions, risks, and provenance.
|
|
9
9
|
Keep claims small and resolve reported overlaps before editing.`;
|
|
@@ -17,8 +17,9 @@ This project uses Concord MCP. Keep coordination to the five workflow tools:
|
|
|
17
17
|
- **Before editing**, call \`start_work\` with the task, your agent kind/id, and
|
|
18
18
|
expected files or modules. It registers presence, accepts assigned work when
|
|
19
19
|
appropriate, claims the scope, and returns overlap warnings.
|
|
20
|
-
- Use \`inspect_work\` to read the workspace
|
|
21
|
-
|
|
20
|
+
- Use \`inspect_work\` to read the workspace, one task, one agent, or one message
|
|
21
|
+
thread. Use \`update_work\` for durable progress and for live prompts/replies
|
|
22
|
+
to another promptable workspace agent, including while that agent is busy.
|
|
22
23
|
- Use \`transfer_work\` for assignment, acceptance, decline, release,
|
|
23
24
|
reassignment, evidence-bearing handoff offers, and reopening.
|
|
24
25
|
- **Before finishing**, call \`finish_work\` once with the outcome, changed
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/install/instructions.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C,sEAAsE;AACtE,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;gEAKqB,CAAC;AAEjE,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;gCAEJ,2BAA2B
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/install/instructions.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AAE/C,sEAAsE;AACtE,MAAM,CAAC,MAAM,2BAA2B,GAAG;;;;;gEAKqB,CAAC;AAEjE,gFAAgF;AAChF,MAAM,CAAC,MAAM,oBAAoB,GAAG;;gCAEJ,2BAA2B;;;;;;;;;;;;;;;;;;;;mEAoBQ,CAAC;AAEpE,oEAAoE;AACpE,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;CAIhC,CAAC"}
|
|
@@ -15,7 +15,7 @@ export declare class McpConfigParseError extends Error {
|
|
|
15
15
|
* Every other server and every unrelated top-level key is preserved, and
|
|
16
16
|
* passing the previous output back in is a no-op.
|
|
17
17
|
*/
|
|
18
|
-
export declare function upsertMcpServer(existing: string | undefined): string;
|
|
18
|
+
export declare function upsertMcpServer(existing: string | undefined, repoRoot: string): string;
|
|
19
19
|
/**
|
|
20
20
|
* Register Concord in every JSON-shaped client config under `repoRoot`
|
|
21
21
|
* (Claude Code's `.mcp.json` and Cursor's `.cursor/mcp.json`), creating each
|
|
@@ -25,13 +25,19 @@ export class McpConfigParseError extends Error {
|
|
|
25
25
|
* Every other server and every unrelated top-level key is preserved, and
|
|
26
26
|
* passing the previous output back in is a no-op.
|
|
27
27
|
*/
|
|
28
|
-
export function upsertMcpServer(existing) {
|
|
28
|
+
export function upsertMcpServer(existing, repoRoot) {
|
|
29
29
|
const source = existing === undefined || existing.trim() === '' ? {} : JSON.parse(existing);
|
|
30
30
|
const config = mcpConfigSchema.parse(source);
|
|
31
31
|
const servers = config.mcpServers ?? {};
|
|
32
32
|
const next = {
|
|
33
33
|
...config,
|
|
34
|
-
mcpServers: {
|
|
34
|
+
mcpServers: {
|
|
35
|
+
...servers,
|
|
36
|
+
[CONCORD_SERVER_KEY]: {
|
|
37
|
+
command: CONCORD_SERVER_COMMAND,
|
|
38
|
+
env: { CONCORD_REPO_ROOT: repoRoot },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
35
41
|
};
|
|
36
42
|
return `${JSON.stringify(next, null, 2)}\n`;
|
|
37
43
|
}
|
|
@@ -40,7 +46,7 @@ function writeMcpConfig(repoRoot, relPath) {
|
|
|
40
46
|
const existing = existsSync(fullPath) ? readFileSync(fullPath, 'utf8') : undefined;
|
|
41
47
|
let updated;
|
|
42
48
|
try {
|
|
43
|
-
updated = upsertMcpServer(existing);
|
|
49
|
+
updated = upsertMcpServer(existing, repoRoot);
|
|
44
50
|
}
|
|
45
51
|
catch {
|
|
46
52
|
throw new McpConfigParseError(relPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-config.js","sourceRoot":"","sources":["../../src/install/mcp-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,qEAAqE;AACrE,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAC5C,4DAA4D;AAC5D,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAAC;AAEpD,yEAAyE;AACzE,MAAM,YAAY,GAAsB,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC;AAEnF,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AAEjG;;;GAGG;AACH,MAA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;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IAChD,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AgentSessionAdapter, AgentSessionDelivery } from './server.js';
|
|
2
|
+
export interface CodexAppServerClient {
|
|
3
|
+
request(method: 'turn/steer' | 'turn/start', params: Record<string, unknown>): Promise<unknown>;
|
|
4
|
+
}
|
|
5
|
+
/** Codex app-server adapter: an active turn is steered; idle starts a new turn. */
|
|
6
|
+
export declare class CodexAppServerAdapter implements AgentSessionAdapter {
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly threadId;
|
|
9
|
+
private readonly currentTurnId;
|
|
10
|
+
readonly provider = "codex";
|
|
11
|
+
constructor(client: CodexAppServerClient, threadId: string, currentTurnId: () => string | undefined);
|
|
12
|
+
steer(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
13
|
+
startTurn(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
14
|
+
}
|
|
15
|
+
export interface PushPromptSession {
|
|
16
|
+
pushPrompt(content: string, mode: 'steer' | 'start'): Promise<string | undefined>;
|
|
17
|
+
}
|
|
18
|
+
/** Claude managed-session adapter using its streaming-input prompt channel. */
|
|
19
|
+
export declare class ClaudeStreamingAdapter implements AgentSessionAdapter {
|
|
20
|
+
private readonly session;
|
|
21
|
+
readonly provider = "claude";
|
|
22
|
+
constructor(session: PushPromptSession);
|
|
23
|
+
steer(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
24
|
+
startTurn(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
25
|
+
}
|
|
26
|
+
/** Cursor adapter for a client integration that exposes immediate follow-up injection. */
|
|
27
|
+
export declare class CursorSessionAdapter implements AgentSessionAdapter {
|
|
28
|
+
private readonly session;
|
|
29
|
+
readonly provider = "cursor";
|
|
30
|
+
constructor(session: PushPromptSession);
|
|
31
|
+
steer(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
32
|
+
startTurn(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Codex app-server adapter: an active turn is steered; idle starts a new turn. */
|
|
3
|
+
export class CodexAppServerAdapter {
|
|
4
|
+
client;
|
|
5
|
+
threadId;
|
|
6
|
+
currentTurnId;
|
|
7
|
+
provider = 'codex';
|
|
8
|
+
constructor(client, threadId, currentTurnId) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
this.threadId = threadId;
|
|
11
|
+
this.currentTurnId = currentTurnId;
|
|
12
|
+
}
|
|
13
|
+
async steer(delivery) {
|
|
14
|
+
const turnId = this.currentTurnId();
|
|
15
|
+
if (turnId === undefined)
|
|
16
|
+
throw new Error('Codex session has no active turn to steer.');
|
|
17
|
+
await this.client.request('turn/steer', {
|
|
18
|
+
threadId: this.threadId,
|
|
19
|
+
turnId,
|
|
20
|
+
input: [{ type: 'text', text: delivery.content }],
|
|
21
|
+
});
|
|
22
|
+
return turnId;
|
|
23
|
+
}
|
|
24
|
+
async startTurn(delivery) {
|
|
25
|
+
const result = await this.client.request('turn/start', {
|
|
26
|
+
threadId: this.threadId,
|
|
27
|
+
input: [{ type: 'text', text: delivery.content }],
|
|
28
|
+
});
|
|
29
|
+
return receiptFrom(result);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Claude managed-session adapter using its streaming-input prompt channel. */
|
|
33
|
+
export class ClaudeStreamingAdapter {
|
|
34
|
+
session;
|
|
35
|
+
provider = 'claude';
|
|
36
|
+
constructor(session) {
|
|
37
|
+
this.session = session;
|
|
38
|
+
}
|
|
39
|
+
steer(delivery) {
|
|
40
|
+
return this.session.pushPrompt(delivery.content, 'steer');
|
|
41
|
+
}
|
|
42
|
+
startTurn(delivery) {
|
|
43
|
+
return this.session.pushPrompt(delivery.content, 'start');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** Cursor adapter for a client integration that exposes immediate follow-up injection. */
|
|
47
|
+
export class CursorSessionAdapter {
|
|
48
|
+
session;
|
|
49
|
+
provider = 'cursor';
|
|
50
|
+
constructor(session) {
|
|
51
|
+
this.session = session;
|
|
52
|
+
}
|
|
53
|
+
steer(delivery) {
|
|
54
|
+
return this.session.pushPrompt(delivery.content, 'steer');
|
|
55
|
+
}
|
|
56
|
+
startTurn(delivery) {
|
|
57
|
+
return this.session.pushPrompt(delivery.content, 'start');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function receiptFrom(value) {
|
|
61
|
+
const parsed = z.record(z.unknown()).safeParse(value);
|
|
62
|
+
if (!parsed.success)
|
|
63
|
+
return undefined;
|
|
64
|
+
for (const key of ['turnId', 'turn_id', 'id']) {
|
|
65
|
+
if (typeof parsed.data[key] === 'string')
|
|
66
|
+
return parsed.data[key];
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../../src/relay/adapters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,mFAAmF;AACnF,MAAM,OAAO,qBAAqB;IAIb;IACA;IACA;IALV,QAAQ,GAAG,OAAO,CAAC;IAE5B,YACmB,MAA4B,EAC5B,QAAgB,EAChB,aAAuC;QAFvC,WAAM,GAAN,MAAM,CAAsB;QAC5B,aAAQ,GAAR,QAAQ,CAAQ;QAChB,kBAAa,GAAb,aAAa,CAA0B;IACvD,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,QAA8B;QACxC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QACpC,IAAI,MAAM,KAAK,SAAS;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AO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;IACD,SAAS,CAAC,QAA8B;QACtC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC5D,CAAC;CACF;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,MAAM,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,CAAC;QAC9C,IAAI,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,QAAQ;YAAE,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ClaudeStreamingAdapter, CodexAppServerAdapter, CursorSessionAdapter, type CodexAppServerClient, type PushPromptSession, } from './adapters.js';
|
|
2
|
+
export { MAX_RELAY_FRAME_BYTES, RELAY_PROTOCOL_VERSION, type RelayDelivery, type RelayResponse, } from './protocol.js';
|
|
3
|
+
export { startAgentRelay, startWorkspaceAgentRelay, type AgentRelayServerOptions, type AgentSessionAdapter, type AgentSessionDelivery, type RunningAgentRelay, type WorkspaceAgentRelayServerOptions, } from './server.js';
|
|
4
|
+
export { SocketAgentMessageDispatcher } from './socket-dispatcher.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ClaudeStreamingAdapter, CodexAppServerAdapter, CursorSessionAdapter, } from './adapters.js';
|
|
2
|
+
export { MAX_RELAY_FRAME_BYTES, RELAY_PROTOCOL_VERSION, } from './protocol.js';
|
|
3
|
+
export { startAgentRelay, startWorkspaceAgentRelay, } from './server.js';
|
|
4
|
+
export { SocketAgentMessageDispatcher } from './socket-dispatcher.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/relay/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GAGvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,wBAAwB,GAMzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const RELAY_PROTOCOL_VERSION = 1;
|
|
3
|
+
export declare const relayDeliverySchema: z.ZodObject<{
|
|
4
|
+
version: z.ZodLiteral<1>;
|
|
5
|
+
type: z.ZodLiteral<"deliver">;
|
|
6
|
+
messageId: z.ZodString;
|
|
7
|
+
senderAgentId: z.ZodString;
|
|
8
|
+
recipientAgentId: z.ZodString;
|
|
9
|
+
credentialProof: z.ZodString;
|
|
10
|
+
content: z.ZodString;
|
|
11
|
+
activeTurn: z.ZodBoolean;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
type: "deliver";
|
|
14
|
+
version: 1;
|
|
15
|
+
content: string;
|
|
16
|
+
recipientAgentId: string;
|
|
17
|
+
messageId: string;
|
|
18
|
+
senderAgentId: string;
|
|
19
|
+
credentialProof: string;
|
|
20
|
+
activeTurn: boolean;
|
|
21
|
+
}, {
|
|
22
|
+
type: "deliver";
|
|
23
|
+
version: 1;
|
|
24
|
+
content: string;
|
|
25
|
+
recipientAgentId: string;
|
|
26
|
+
messageId: string;
|
|
27
|
+
senderAgentId: string;
|
|
28
|
+
credentialProof: string;
|
|
29
|
+
activeTurn: boolean;
|
|
30
|
+
}>;
|
|
31
|
+
export type RelayDelivery = z.infer<typeof relayDeliverySchema>;
|
|
32
|
+
export declare const relayResponseSchema: z.ZodDiscriminatedUnion<"ok", [z.ZodObject<{
|
|
33
|
+
version: z.ZodLiteral<1>;
|
|
34
|
+
ok: z.ZodLiteral<true>;
|
|
35
|
+
provider: z.ZodString;
|
|
36
|
+
receipt: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
version: 1;
|
|
39
|
+
provider: string;
|
|
40
|
+
ok: true;
|
|
41
|
+
receipt?: string | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
version: 1;
|
|
44
|
+
provider: string;
|
|
45
|
+
ok: true;
|
|
46
|
+
receipt?: string | undefined;
|
|
47
|
+
}>, z.ZodObject<{
|
|
48
|
+
version: z.ZodLiteral<1>;
|
|
49
|
+
ok: z.ZodLiteral<false>;
|
|
50
|
+
error: z.ZodString;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
error: string;
|
|
53
|
+
version: 1;
|
|
54
|
+
ok: false;
|
|
55
|
+
}, {
|
|
56
|
+
error: string;
|
|
57
|
+
version: 1;
|
|
58
|
+
ok: false;
|
|
59
|
+
}>]>;
|
|
60
|
+
export type RelayResponse = z.infer<typeof relayResponseSchema>;
|
|
61
|
+
export declare const MAX_RELAY_FRAME_BYTES: number;
|
|
62
|
+
export declare function encodeRelayFrame(value: RelayDelivery | RelayResponse): string;
|
|
63
|
+
export declare function decodeRelayDelivery(frame: string): RelayDelivery;
|
|
64
|
+
export declare function decodeRelayResponse(frame: string): RelayResponse;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const RELAY_PROTOCOL_VERSION = 1;
|
|
3
|
+
export const relayDeliverySchema = z.object({
|
|
4
|
+
version: z.literal(RELAY_PROTOCOL_VERSION),
|
|
5
|
+
type: z.literal('deliver'),
|
|
6
|
+
messageId: z.string().min(1),
|
|
7
|
+
senderAgentId: z.string().min(1),
|
|
8
|
+
recipientAgentId: z.string().min(1),
|
|
9
|
+
credentialProof: z.string().min(1),
|
|
10
|
+
content: z.string().min(1),
|
|
11
|
+
activeTurn: z.boolean(),
|
|
12
|
+
});
|
|
13
|
+
export const relayResponseSchema = z.discriminatedUnion('ok', [
|
|
14
|
+
z.object({
|
|
15
|
+
version: z.literal(RELAY_PROTOCOL_VERSION),
|
|
16
|
+
ok: z.literal(true),
|
|
17
|
+
provider: z.string().min(1),
|
|
18
|
+
receipt: z.string().optional(),
|
|
19
|
+
}),
|
|
20
|
+
z.object({
|
|
21
|
+
version: z.literal(RELAY_PROTOCOL_VERSION),
|
|
22
|
+
ok: z.literal(false),
|
|
23
|
+
error: z.string().min(1),
|
|
24
|
+
}),
|
|
25
|
+
]);
|
|
26
|
+
export const MAX_RELAY_FRAME_BYTES = 256 * 1024;
|
|
27
|
+
export function encodeRelayFrame(value) {
|
|
28
|
+
return `${JSON.stringify(value)}\n`;
|
|
29
|
+
}
|
|
30
|
+
export function decodeRelayDelivery(frame) {
|
|
31
|
+
const parsed = JSON.parse(frame);
|
|
32
|
+
return relayDeliverySchema.parse(parsed);
|
|
33
|
+
}
|
|
34
|
+
export function decodeRelayResponse(frame) {
|
|
35
|
+
const parsed = JSON.parse(frame);
|
|
36
|
+
return relayResponseSchema.parse(parsed);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/relay/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OA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AC,KAAoC;IACnE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Repositories } from '../db/index.js';
|
|
2
|
+
import { type RelayDelivery } from './protocol.js';
|
|
3
|
+
export interface AgentSessionAdapter {
|
|
4
|
+
readonly provider: string;
|
|
5
|
+
/** Inject into the current turn. Called only when the endpoint reports an active turn. */
|
|
6
|
+
steer(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
7
|
+
/** Start a new turn immediately when the endpoint is idle. */
|
|
8
|
+
startTurn(delivery: AgentSessionDelivery): Promise<string | undefined>;
|
|
9
|
+
}
|
|
10
|
+
export type AgentSessionDelivery = Omit<RelayDelivery, 'credentialProof'>;
|
|
11
|
+
export interface AgentRelayServerOptions {
|
|
12
|
+
repos: Repositories;
|
|
13
|
+
agentId: string;
|
|
14
|
+
address: string;
|
|
15
|
+
adapter: AgentSessionAdapter;
|
|
16
|
+
/** Dynamic state supplied by the client integration, not inferred from agent liveness. */
|
|
17
|
+
hasActiveTurn: () => boolean;
|
|
18
|
+
ttlMs?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface RunningAgentRelay {
|
|
21
|
+
endpointId: string;
|
|
22
|
+
credential: string;
|
|
23
|
+
address: string;
|
|
24
|
+
close(): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface WorkspaceAgentRelayServerOptions extends Omit<AgentRelayServerOptions, 'repos'> {
|
|
27
|
+
repoRoot: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Host a local, one-frame relay for a live client session. The integration that
|
|
31
|
+
* owns the session supplies the provider adapter, so busy-turn steering happens
|
|
32
|
+
* through the provider's supported in-process/app-server API.
|
|
33
|
+
*/
|
|
34
|
+
export declare function startAgentRelay(options: AgentRelayServerOptions): Promise<RunningAgentRelay>;
|
|
35
|
+
/**
|
|
36
|
+
* Public package entry point for client integrations. It binds the relay to a
|
|
37
|
+
* repository's Concord database and owns that connection for the relay's
|
|
38
|
+
* lifetime, so an installed host does not need Concord's internal repositories.
|
|
39
|
+
*/
|
|
40
|
+
export declare function startWorkspaceAgentRelay(options: WorkspaceAgentRelayServerOptions): Promise<RunningAgentRelay>;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { createHash, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import { chmodSync, existsSync, lstatSync, unlinkSync } from 'node:fs';
|
|
3
|
+
import { createServer } from 'node:net';
|
|
4
|
+
import { openRepositories } from '../db/index.js';
|
|
5
|
+
import { databasePath, resolveExplicitRepoRoot } from '../config/paths.js';
|
|
6
|
+
import { decodeRelayDelivery, encodeRelayFrame, MAX_RELAY_FRAME_BYTES, RELAY_PROTOCOL_VERSION, } from './protocol.js';
|
|
7
|
+
function respond(socket, response) {
|
|
8
|
+
socket.end(encodeRelayFrame(response));
|
|
9
|
+
}
|
|
10
|
+
function removeUnixSocket(address) {
|
|
11
|
+
if (process.platform === 'win32' || !existsSync(address))
|
|
12
|
+
return;
|
|
13
|
+
if (!lstatSync(address).isSocket()) {
|
|
14
|
+
throw new Error(`Refusing to replace non-socket relay path: ${address}`);
|
|
15
|
+
}
|
|
16
|
+
unlinkSync(address);
|
|
17
|
+
}
|
|
18
|
+
function listen(server, address) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
server.once('error', reject);
|
|
21
|
+
server.listen(address, () => {
|
|
22
|
+
server.off('error', reject);
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function toSessionDelivery(delivery) {
|
|
28
|
+
return {
|
|
29
|
+
version: delivery.version,
|
|
30
|
+
type: delivery.type,
|
|
31
|
+
messageId: delivery.messageId,
|
|
32
|
+
senderAgentId: delivery.senderAgentId,
|
|
33
|
+
recipientAgentId: delivery.recipientAgentId,
|
|
34
|
+
content: delivery.content,
|
|
35
|
+
activeTurn: delivery.activeTurn,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Host a local, one-frame relay for a live client session. The integration that
|
|
40
|
+
* owns the session supplies the provider adapter, so busy-turn steering happens
|
|
41
|
+
* through the provider's supported in-process/app-server API.
|
|
42
|
+
*/
|
|
43
|
+
export async function startAgentRelay(options) {
|
|
44
|
+
const agent = options.repos.agents.get(options.agentId);
|
|
45
|
+
if (agent === undefined)
|
|
46
|
+
throw new Error(`Agent ${options.agentId} is not registered.`);
|
|
47
|
+
removeUnixSocket(options.address);
|
|
48
|
+
const ttlMs = options.ttlMs ?? 15_000;
|
|
49
|
+
const endpointId = randomUUID();
|
|
50
|
+
const credential = randomBytes(32).toString('base64url');
|
|
51
|
+
const credentialHash = createHash('sha256').update(credential).digest('hex');
|
|
52
|
+
let closed = false;
|
|
53
|
+
const server = createServer((socket) => {
|
|
54
|
+
let buffer = '';
|
|
55
|
+
socket.on('data', (chunk) => {
|
|
56
|
+
buffer += chunk.toString('utf8');
|
|
57
|
+
if (Buffer.byteLength(buffer, 'utf8') > MAX_RELAY_FRAME_BYTES) {
|
|
58
|
+
respond(socket, {
|
|
59
|
+
version: RELAY_PROTOCOL_VERSION,
|
|
60
|
+
ok: false,
|
|
61
|
+
error: 'relay request exceeded maximum frame size',
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const newline = buffer.indexOf('\n');
|
|
66
|
+
if (newline < 0)
|
|
67
|
+
return;
|
|
68
|
+
socket.removeAllListeners('data');
|
|
69
|
+
void (async () => {
|
|
70
|
+
try {
|
|
71
|
+
const delivery = decodeRelayDelivery(buffer.slice(0, newline));
|
|
72
|
+
const suppliedProof = Buffer.from(delivery.credentialProof, 'utf8');
|
|
73
|
+
const expectedProof = Buffer.from(credentialHash, 'utf8');
|
|
74
|
+
if (suppliedProof.length !== expectedProof.length ||
|
|
75
|
+
!timingSafeEqual(suppliedProof, expectedProof)) {
|
|
76
|
+
throw new Error('Relay credential was rejected.');
|
|
77
|
+
}
|
|
78
|
+
if (delivery.recipientAgentId !== options.agentId) {
|
|
79
|
+
throw new Error(`Relay endpoint belongs to ${options.agentId}.`);
|
|
80
|
+
}
|
|
81
|
+
const sessionDelivery = toSessionDelivery(delivery);
|
|
82
|
+
const activeTurn = options.hasActiveTurn();
|
|
83
|
+
const receipt = activeTurn
|
|
84
|
+
? await options.adapter.steer({ ...sessionDelivery, activeTurn })
|
|
85
|
+
: await options.adapter.startTurn({ ...sessionDelivery, activeTurn });
|
|
86
|
+
respond(socket, {
|
|
87
|
+
version: RELAY_PROTOCOL_VERSION,
|
|
88
|
+
ok: true,
|
|
89
|
+
provider: options.adapter.provider,
|
|
90
|
+
...(receipt === undefined ? {} : { receipt }),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
respond(socket, {
|
|
95
|
+
version: RELAY_PROTOCOL_VERSION,
|
|
96
|
+
ok: false,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
await listen(server, options.address);
|
|
104
|
+
if (process.platform !== 'win32')
|
|
105
|
+
chmodSync(options.address, 0o600);
|
|
106
|
+
const expiresAt = () => new Date(Date.now() + ttlMs).toISOString();
|
|
107
|
+
const capabilities = () => [
|
|
108
|
+
'steer',
|
|
109
|
+
'start-turn',
|
|
110
|
+
...(options.hasActiveTurn() ? ['active-turn'] : []),
|
|
111
|
+
];
|
|
112
|
+
options.repos.agentEndpoints.upsert({
|
|
113
|
+
endpointId,
|
|
114
|
+
agentId: options.agentId,
|
|
115
|
+
provider: options.adapter.provider,
|
|
116
|
+
transport: 'local-socket',
|
|
117
|
+
capabilities: capabilities(),
|
|
118
|
+
address: options.address,
|
|
119
|
+
credentialHash,
|
|
120
|
+
expiresAt: expiresAt(),
|
|
121
|
+
});
|
|
122
|
+
const heartbeat = setInterval(() => {
|
|
123
|
+
if (closed)
|
|
124
|
+
return;
|
|
125
|
+
const current = options.repos.agentEndpoints.get(endpointId);
|
|
126
|
+
if (current === undefined)
|
|
127
|
+
return;
|
|
128
|
+
options.repos.agentEndpoints.upsert({
|
|
129
|
+
endpointId,
|
|
130
|
+
agentId: options.agentId,
|
|
131
|
+
provider: options.adapter.provider,
|
|
132
|
+
transport: 'local-socket',
|
|
133
|
+
capabilities: capabilities(),
|
|
134
|
+
address: options.address,
|
|
135
|
+
credentialHash: current.credentialHash,
|
|
136
|
+
expiresAt: expiresAt(),
|
|
137
|
+
});
|
|
138
|
+
}, Math.max(1_000, Math.floor(ttlMs / 3)));
|
|
139
|
+
heartbeat.unref();
|
|
140
|
+
return {
|
|
141
|
+
endpointId,
|
|
142
|
+
credential,
|
|
143
|
+
address: options.address,
|
|
144
|
+
close: async () => {
|
|
145
|
+
if (closed)
|
|
146
|
+
return;
|
|
147
|
+
closed = true;
|
|
148
|
+
clearInterval(heartbeat);
|
|
149
|
+
options.repos.agentEndpoints.disconnect(endpointId);
|
|
150
|
+
await new Promise((resolve, reject) => {
|
|
151
|
+
server.close((error) => {
|
|
152
|
+
if (error === undefined)
|
|
153
|
+
resolve();
|
|
154
|
+
else
|
|
155
|
+
reject(error);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
removeUnixSocket(options.address);
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Public package entry point for client integrations. It binds the relay to a
|
|
164
|
+
* repository's Concord database and owns that connection for the relay's
|
|
165
|
+
* lifetime, so an installed host does not need Concord's internal repositories.
|
|
166
|
+
*/
|
|
167
|
+
export async function startWorkspaceAgentRelay(options) {
|
|
168
|
+
const { repoRoot, ...relayOptions } = options;
|
|
169
|
+
const repos = openRepositories(databasePath(resolveExplicitRepoRoot(repoRoot)));
|
|
170
|
+
let relay;
|
|
171
|
+
try {
|
|
172
|
+
relay = await startAgentRelay({ ...relayOptions, repos });
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
repos.db.close();
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
let closed = false;
|
|
179
|
+
return {
|
|
180
|
+
endpointId: relay.endpointId,
|
|
181
|
+
credential: relay.credential,
|
|
182
|
+
address: relay.address,
|
|
183
|
+
close: async () => {
|
|
184
|
+
if (closed)
|
|
185
|
+
return;
|
|
186
|
+
closed = true;
|
|
187
|
+
try {
|
|
188
|
+
await relay.close();
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
repos.db.close();
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=server.js.map
|