agents-can-communicate 0.3.0 → 0.4.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.
- package/README.md +112 -91
- package/SECURITY.md +8 -5
- package/bin/acc-bootstrap.mjs +5 -54
- package/bin/acc-claude-channel.mjs +8 -175
- package/bin/acc-hook.mjs +4 -133
- package/bin/acc-mcp.mjs +4 -59
- package/bin/acc-update-worker.mjs +8 -0
- package/bin/acc.mjs +5 -39
- package/bin/entrypoints/acc-bootstrap.mjs +47 -0
- package/bin/entrypoints/acc-claude-channel.mjs +149 -0
- package/bin/entrypoints/acc-hook.mjs +58 -0
- package/bin/entrypoints/acc-mcp.mjs +70 -0
- package/bin/entrypoints/acc.mjs +51 -0
- package/bin/entrypoints/claude-channel-stdio.mjs +29 -0
- package/bin/entrypoints/hook-output.mjs +73 -0
- package/docs/ADAPTER_AUTHORING.md +62 -24
- package/docs/ARCHITECTURE.md +79 -20
- package/docs/CAPABILITIES.md +52 -30
- package/docs/CLI.md +164 -35
- package/docs/CONCEPTS.md +97 -93
- package/docs/CONFIGURATION.md +66 -45
- package/docs/DESIGN_DECISIONS.md +24 -15
- package/docs/GETTING_STARTED.md +124 -118
- package/docs/GLOSSARY.md +12 -6
- package/docs/HOW_IT_WORKS.md +136 -229
- package/docs/MCP.md +98 -31
- package/docs/PROTOCOL.md +76 -14
- package/docs/RELEASING.md +128 -86
- package/docs/SECURITY_MODEL.md +52 -15
- package/docs/TROUBLESHOOTING.md +88 -18
- package/docs/UPGRADING.md +119 -0
- package/docs/WHY_ACC.md +19 -16
- package/docs/index.md +40 -24
- package/node_modules/@agents-can-communicate/adapter-claude-code/package.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-claude-code/plugin/skills/acc/SKILL.md +112 -9
- package/node_modules/@agents-can-communicate/adapter-claude-code/src/install.mjs +6 -6
- package/node_modules/@agents-can-communicate/adapter-claude-code/src/native-delivery.mjs +2 -1
- package/node_modules/@agents-can-communicate/adapter-codex/certification.json +38 -13
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/certification-provenance.json +220 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-current-binding-product-evidence.json +1549 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-current-binding-product.json +27 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-product-evidence.json +1549 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-product.json +27 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-transport-evidence.json +259 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-transport.json +21 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-current-binding-product-evidence.json +1549 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-current-binding-product.json +27 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-product-evidence.json +1549 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-product.json +27 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-transport-evidence.json +259 -0
- package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-transport.json +21 -0
- package/node_modules/@agents-can-communicate/adapter-codex/package.json +14 -2
- package/node_modules/@agents-can-communicate/adapter-codex/plugin/skills/acc/SKILL.md +111 -8
- package/node_modules/@agents-can-communicate/adapter-codex/src/adapter.mjs +26 -44
- package/node_modules/@agents-can-communicate/adapter-codex/src/app-server-client.mjs +70 -17
- package/node_modules/@agents-can-communicate/adapter-codex/src/config-block.mjs +231 -0
- package/node_modules/@agents-can-communicate/adapter-codex/src/hooks.mjs +1 -1
- package/node_modules/@agents-can-communicate/adapter-codex/src/install.mjs +71 -63
- package/node_modules/@agents-can-communicate/adapter-codex/src/native-delivery.mjs +107 -103
- package/node_modules/@agents-can-communicate/adapter-codex/src/native-endpoint.mjs +96 -0
- package/node_modules/@agents-can-communicate/adapter-codex/src/ws-json-rpc.mjs +3 -2
- package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/gemini-extension.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/skills/acc/SKILL.md +111 -8
- package/node_modules/@agents-can-communicate/adapter-gemini-cli/package.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-gemini-cli/src/install.mjs +2 -2
- package/node_modules/@agents-can-communicate/adapter-grok/package.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-grok/plugin/skills/acc/SKILL.md +111 -8
- package/node_modules/@agents-can-communicate/adapter-grok/src/install.mjs +2 -2
- package/node_modules/@agents-can-communicate/adapter-kimi/package.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-kimi/plugin/skills/acc/SKILL.md +111 -8
- package/node_modules/@agents-can-communicate/adapter-kimi/src/hooks.mjs +1 -1
- package/node_modules/@agents-can-communicate/adapter-kimi/src/install.mjs +2 -2
- package/node_modules/@agents-can-communicate/adapter-sdk/package.json +1 -1
- package/node_modules/@agents-can-communicate/adapter-sdk/src/capabilities.mjs +5 -0
- package/node_modules/@agents-can-communicate/adapter-sdk/src/context-projector.mjs +26 -4
- package/node_modules/@agents-can-communicate/adapter-sdk/src/decision-text.mjs +19 -0
- package/node_modules/@agents-can-communicate/adapter-sdk/src/hook-shim.mjs +5 -3
- package/node_modules/@agents-can-communicate/adapter-sdk/src/index.mjs +1 -0
- package/node_modules/@agents-can-communicate/adapter-sdk/src/native-delivery.mjs +9 -2
- package/node_modules/@agents-can-communicate/adapter-sdk/src/native-vocabulary.mjs +2 -6
- package/node_modules/@agents-can-communicate/adapter-sdk/src/session-binding.mjs +29 -9
- package/node_modules/@agents-can-communicate/adapter-sdk/src/toml-block.mjs +8 -6
- package/node_modules/@agents-can-communicate/cli/package.json +4 -2
- package/node_modules/@agents-can-communicate/cli/src/args.mjs +49 -22
- package/node_modules/@agents-can-communicate/cli/src/doctor-command.mjs +11 -4
- package/node_modules/@agents-can-communicate/cli/src/git-probe.mjs +9 -3
- package/node_modules/@agents-can-communicate/cli/src/help.mjs +109 -14
- package/node_modules/@agents-can-communicate/cli/src/install-command.mjs +66 -18
- package/node_modules/@agents-can-communicate/cli/src/main.mjs +35 -12
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/activation.mjs +110 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/command.mjs +63 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/download.mjs +71 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/entry.mjs +110 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/generation.mjs +167 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/install.mjs +73 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/launchers.mjs +60 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/leases.mjs +60 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/location.mjs +55 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/mutex.mjs +145 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/policy.mjs +4 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/refresh.mjs +40 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/schedule.mjs +21 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/state.mjs +122 -0
- package/node_modules/@agents-can-communicate/cli/src/managed-runtime/worker.mjs +65 -0
- package/node_modules/@agents-can-communicate/cli/src/session-owner.mjs +33 -108
- package/node_modules/@agents-can-communicate/cli/src/update-command.mjs +25 -7
- package/node_modules/@agents-can-communicate/core/package.json +1 -1
- package/node_modules/@agents-can-communicate/core/src/attention.mjs +3 -0
- package/node_modules/@agents-can-communicate/core/src/claims.mjs +13 -8
- package/node_modules/@agents-can-communicate/core/src/conversations.mjs +48 -24
- package/node_modules/@agents-can-communicate/core/src/decision-changes.mjs +36 -0
- package/node_modules/@agents-can-communicate/core/src/decision-state.mjs +42 -0
- package/node_modules/@agents-can-communicate/core/src/delivery-bindings.mjs +11 -4
- package/node_modules/@agents-can-communicate/core/src/inbox.mjs +48 -17
- package/node_modules/@agents-can-communicate/core/src/intents.mjs +35 -15
- package/node_modules/@agents-can-communicate/core/src/materialisation.mjs +7 -5
- package/node_modules/@agents-can-communicate/core/src/message-pages.mjs +75 -0
- package/node_modules/@agents-can-communicate/core/src/next-turn-delivery.mjs +31 -0
- package/node_modules/@agents-can-communicate/core/src/session-opening.mjs +128 -0
- package/node_modules/@agents-can-communicate/core/src/sessions.mjs +58 -132
- package/node_modules/@agents-can-communicate/core/src/sync.mjs +31 -2
- package/node_modules/@agents-can-communicate/delivery-router/package.json +1 -1
- package/node_modules/@agents-can-communicate/delivery-router/src/refresh-binding.mjs +38 -0
- package/node_modules/@agents-can-communicate/delivery-router/src/router.mjs +86 -10
- package/node_modules/@agents-can-communicate/hook-runner/package.json +1 -1
- package/node_modules/@agents-can-communicate/hook-runner/src/client-version.mjs +1 -0
- package/node_modules/@agents-can-communicate/hook-runner/src/native-binding.mjs +6 -4
- package/node_modules/@agents-can-communicate/hook-runner/src/native-retirement.mjs +48 -0
- package/node_modules/@agents-can-communicate/hook-runner/src/process-table.mjs +1 -1
- package/node_modules/@agents-can-communicate/hook-runner/src/runner.mjs +175 -67
- package/node_modules/@agents-can-communicate/hook-runner/src/session-lifecycle.mjs +13 -0
- package/node_modules/@agents-can-communicate/installer/package.json +4 -2
- package/node_modules/@agents-can-communicate/installer/src/apply.mjs +17 -2
- package/node_modules/@agents-can-communicate/installer/src/bootstrap-runtime.mjs +11 -5
- package/node_modules/@agents-can-communicate/installer/src/detect.mjs +1 -1
- package/node_modules/@agents-can-communicate/installer/src/index.mjs +1 -0
- package/node_modules/@agents-can-communicate/installer/src/live-policy.mjs +21 -0
- package/node_modules/@agents-can-communicate/installer/src/native-activation.mjs +20 -6
- package/node_modules/@agents-can-communicate/installer/src/ownership.mjs +10 -4
- package/node_modules/@agents-can-communicate/installer/src/plan.mjs +3 -3
- package/node_modules/@agents-can-communicate/mcp-server/package.json +1 -1
- package/node_modules/@agents-can-communicate/mcp-server/src/protocol.mjs +85 -0
- package/node_modules/@agents-can-communicate/mcp-server/src/resources.mjs +3 -2
- package/node_modules/@agents-can-communicate/mcp-server/src/server.mjs +59 -57
- package/node_modules/@agents-can-communicate/mcp-server/src/tools.mjs +47 -33
- package/node_modules/@agents-can-communicate/protocol/package.json +1 -1
- package/node_modules/@agents-can-communicate/protocol/src/conversations.mjs +3 -0
- package/node_modules/@agents-can-communicate/protocol/src/decision-changes.mjs +15 -0
- package/node_modules/@agents-can-communicate/protocol/src/index.mjs +3 -1
- package/node_modules/@agents-can-communicate/protocol/src/schema.mjs +14 -5
- package/node_modules/@agents-can-communicate/storage-filesystem/package.json +1 -1
- package/node_modules/@agents-can-communicate/storage-filesystem/src/atomic-json.mjs +5 -1
- package/node_modules/@agents-can-communicate/storage-filesystem/src/deadline.mjs +7 -0
- package/node_modules/@agents-can-communicate/storage-filesystem/src/index.mjs +2 -0
- package/node_modules/@agents-can-communicate/storage-filesystem/src/session-read.mjs +25 -0
- package/node_modules/@agents-can-communicate/storage-filesystem/src/store.mjs +28 -25
- package/package.json +2 -1
package/bin/acc-hook.mjs
CHANGED
|
@@ -1,137 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Hook entry point: `acc-hook <adapter-id> <kind>`, payload on stdin.
|
|
3
|
-
//
|
|
4
|
-
// Every harness runs this as a short-lived child process in front of the user's
|
|
5
|
-
// turn. The one rule that overrides all others here: never be the reason
|
|
6
|
-
// someone's session stops working. Unknown adapter, malformed payload, broken
|
|
7
|
-
// store, missing binding - all of them end in "allow, exit 0".
|
|
8
|
-
import { randomBytes } from "node:crypto";
|
|
9
|
-
import { realpathSync } from "node:fs";
|
|
10
2
|
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { invokedDirectly, runEntry } from "@agents-can-communicate/cli/managed-entry";
|
|
4
|
+
export { writeOutput, completeHookOutput } from "./entrypoints/hook-output.mjs";
|
|
11
5
|
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { createClaudeCodeAdapter } from "@agents-can-communicate/adapter-claude-code";
|
|
16
|
-
import { createCodexAdapter } from "@agents-can-communicate/adapter-codex";
|
|
17
|
-
import { createGeminiCliAdapter } from "@agents-can-communicate/adapter-gemini-cli";
|
|
18
|
-
import { createGrokAdapter } from "@agents-can-communicate/adapter-grok";
|
|
19
|
-
import { createKimiAdapter } from "@agents-can-communicate/adapter-kimi";
|
|
20
|
-
|
|
21
|
-
const adapters = {
|
|
22
|
-
claude_code: createClaudeCodeAdapter(),
|
|
23
|
-
codex: createCodexAdapter(),
|
|
24
|
-
gemini_cli: createGeminiCliAdapter(),
|
|
25
|
-
grok: createGrokAdapter(),
|
|
26
|
-
kimi: createKimiAdapter(),
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const readStdin = () => new Promise(resolve => {
|
|
30
|
-
// A hook is always given its payload on stdin, but a client that closes it
|
|
31
|
-
// without writing must not leave this process hanging in front of a turn.
|
|
32
|
-
if (process.stdin.isTTY) return resolve("");
|
|
33
|
-
let raw = "";
|
|
34
|
-
process.stdin.setEncoding("utf8");
|
|
35
|
-
process.stdin.on("data", chunk => { raw += chunk; });
|
|
36
|
-
process.stdin.on("end", () => resolve(raw));
|
|
37
|
-
process.stdin.on("error", () => resolve(""));
|
|
38
|
-
return undefined;
|
|
6
|
+
if (invokedDirectly(import.meta.url)) await runEntry({
|
|
7
|
+
kind: "acc-hook", packageRoot: fileURLToPath(new URL("..", import.meta.url)),
|
|
39
8
|
});
|
|
40
|
-
|
|
41
|
-
export const writeOutput = (stream, output, { deadlineAt } = {}) => {
|
|
42
|
-
if (output === "") return Promise.resolve();
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
let settled = false;
|
|
45
|
-
let timer;
|
|
46
|
-
const finish = error => {
|
|
47
|
-
if (settled) return;
|
|
48
|
-
settled = true;
|
|
49
|
-
if (timer !== undefined) clearTimeout(timer);
|
|
50
|
-
if (error === undefined || error === null) resolve();
|
|
51
|
-
else reject(error);
|
|
52
|
-
};
|
|
53
|
-
if (deadlineAt !== undefined) {
|
|
54
|
-
const remaining = deadlineAt - Date.now();
|
|
55
|
-
if (remaining <= 0) {
|
|
56
|
-
finish(new Error("hook budget exhausted before stdout write"));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
timer = setTimeout(() => finish(
|
|
60
|
-
new Error("hook budget exhausted waiting for stdout callback")), remaining);
|
|
61
|
-
}
|
|
62
|
-
try {
|
|
63
|
-
stream.write(output, finish);
|
|
64
|
-
} catch (error) {
|
|
65
|
-
finish(error);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const DIAGNOSTIC_BYTES = 512;
|
|
71
|
-
|
|
72
|
-
function boundedDiagnostic(label, error) {
|
|
73
|
-
const detail = String(error?.message ?? error).replace(/[\u0000-\u001f\u007f]/g, " ");
|
|
74
|
-
let line = `acc: ${label}: ${detail}`;
|
|
75
|
-
while (Buffer.byteLength(`${line}\n`, "utf8") > DIAGNOSTIC_BYTES && line.length > 0) {
|
|
76
|
-
line = line.slice(0, -1);
|
|
77
|
-
}
|
|
78
|
-
return `${line}\n`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function tryWrite(stream, output) {
|
|
82
|
-
if (output === "") return;
|
|
83
|
-
try {
|
|
84
|
-
stream.write(output, () => {});
|
|
85
|
-
} catch {
|
|
86
|
-
// A broken diagnostic stream must not turn a failed-open hook into a crash.
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export async function completeHookOutput(result,
|
|
91
|
-
{ stdout = process.stdout, stderr = process.stderr } = {}) {
|
|
92
|
-
try {
|
|
93
|
-
await writeOutput(stdout, result.stdout ?? "", { deadlineAt: result.deadlineAt });
|
|
94
|
-
} catch (error) {
|
|
95
|
-
tryWrite(stderr, boundedDiagnostic("stdout write failed", error));
|
|
96
|
-
return { exitCode: 0, wroteStdout: false, committedOffers: false };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
let committedOffers = true;
|
|
100
|
-
try {
|
|
101
|
-
await result.commitOffers?.();
|
|
102
|
-
} catch (error) {
|
|
103
|
-
committedOffers = false;
|
|
104
|
-
tryWrite(stderr, boundedDiagnostic("offer commit failed", error));
|
|
105
|
-
}
|
|
106
|
-
if (result.stderr) tryWrite(stderr, `${result.stderr}\n`);
|
|
107
|
-
return { exitCode: 0, wroteStdout: true, committedOffers };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function main() {
|
|
111
|
-
const [adapterId] = process.argv.slice(2);
|
|
112
|
-
|
|
113
|
-
let payload = null;
|
|
114
|
-
try {
|
|
115
|
-
payload = JSON.parse(await readStdin());
|
|
116
|
-
} catch {
|
|
117
|
-
payload = null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const result = await runHook({ adapterId, payload, adapters,
|
|
121
|
-
runtime: { clock: { now: () => new Date().toISOString() },
|
|
122
|
-
ids: { next: kind => createId(kind, randomBytes) } },
|
|
123
|
-
env: process.env });
|
|
124
|
-
|
|
125
|
-
const completed = await completeHookOutput(result);
|
|
126
|
-
process.exitCode = result.exitCode ?? completed.exitCode;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
let isMain = false;
|
|
130
|
-
try {
|
|
131
|
-
isMain = process.argv[1] !== undefined
|
|
132
|
-
&& realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
133
|
-
} catch {
|
|
134
|
-
isMain = false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (isMain) await main();
|
package/bin/acc-mcp.mjs
CHANGED
|
@@ -1,62 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { invokedDirectly, runEntry } from "@agents-can-communicate/cli/managed-entry";
|
|
3
4
|
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { createDeliveryRouter } from "@agents-can-communicate/delivery-router";
|
|
7
|
-
import { openFilesystemStore } from "@agents-can-communicate/storage-filesystem";
|
|
8
|
-
import { ALL_ADAPTERS, createGitProbe, discoverWorkspace, platformDataHome, runtimePaths }
|
|
9
|
-
from "@agents-can-communicate/cli";
|
|
10
|
-
import { serve } from "@agents-can-communicate/mcp-server";
|
|
11
|
-
|
|
12
|
-
// The composition root is the only place allowed to reach for ambient time and
|
|
13
|
-
// randomness. The participant name comes from configuration, never from the
|
|
14
|
-
// client: the protocol says clientInfo is self-reported and must not drive
|
|
15
|
-
// behaviour, and the session is derived from this configuration alone.
|
|
16
|
-
// Nothing is read from the command line, so nothing may be passed on it. It
|
|
17
|
-
// used to accept and ignore anything: writing `acc-mcp --cwd <project>` - the
|
|
18
|
-
// habit `acc` teaches - started a server rooted wherever the client happened to
|
|
19
|
-
// launch it, alone in a workspace nobody else was in, with no warning at all.
|
|
20
|
-
if (process.argv.length > 2) {
|
|
21
|
-
process.stderr.write("acc-mcp takes no arguments. It is configured by environment:\n"
|
|
22
|
-
+ " ACC_MCP_PARTICIPANT who this server takes part as (default: mcp)\n"
|
|
23
|
-
+ " ACC_MCP_WORKSPACE the project it joins (default: the working directory)\n"
|
|
24
|
-
+ `refusing: ${process.argv.slice(2).join(" ")}\n`);
|
|
25
|
-
process.exit(EXIT.USAGE);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const participantId = process.env.ACC_MCP_PARTICIPANT ?? "mcp";
|
|
29
|
-
const clock = { now: () => new Date().toISOString() };
|
|
30
|
-
const ids = { next: kind => createId(kind, randomBytes) };
|
|
31
|
-
|
|
32
|
-
const descriptor = await discoverWorkspace({
|
|
33
|
-
cwd: process.env.ACC_MCP_WORKSPACE ?? process.cwd(),
|
|
34
|
-
env: process.env,
|
|
35
|
-
gitProbe: createGitProbe(),
|
|
36
|
-
});
|
|
37
|
-
const paths = runtimePaths({
|
|
38
|
-
dataHome: platformDataHome({ platform: process.platform, env: process.env }),
|
|
39
|
-
workspaceId: descriptor.id,
|
|
40
|
-
workspaceRoots: descriptor.roots,
|
|
5
|
+
if (invokedDirectly(import.meta.url)) await runEntry({
|
|
6
|
+
kind: "acc-mcp", packageRoot: fileURLToPath(new URL("..", import.meta.url)),
|
|
41
7
|
});
|
|
42
|
-
const store = await openFilesystemStore({ root: paths.root, clock, ids,
|
|
43
|
-
workspaceId: descriptor.id });
|
|
44
|
-
const service = createCoordinationService({ store, clock, ids });
|
|
45
|
-
const adapters = Object.fromEntries(ALL_ADAPTERS().map(adapter => [adapter.id, adapter]));
|
|
46
|
-
|
|
47
|
-
await serve({
|
|
48
|
-
input: process.stdin,
|
|
49
|
-
output: process.stdout,
|
|
50
|
-
log: message => process.stderr.write(`acc-mcp: ${message}\n`),
|
|
51
|
-
context: {
|
|
52
|
-
service,
|
|
53
|
-
deliveryRouter: createDeliveryRouter({ service, adapters, clock }),
|
|
54
|
-
workspaceId: descriptor.id,
|
|
55
|
-
participantId,
|
|
56
|
-
descriptor,
|
|
57
|
-
runtimeDir: paths.root,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// Exiting on stdin EOF is the only portable graceful shutdown in this binding.
|
|
62
|
-
process.exitCode = 0;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Private detached updater. It never opens workspace state or runs a model.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { runWorker, recordWorkerFailure } from "@agents-can-communicate/cli/managed-worker";
|
|
5
|
+
const [root, ...extra] = process.argv.slice(2);
|
|
6
|
+
if (typeof root === "string" && path.isAbsolute(root) && extra.length === 0) {
|
|
7
|
+
await runWorker(root, { wait: true }).catch(error => recordWorkerFailure(root, error));
|
|
8
|
+
}
|
package/bin/acc.mjs
CHANGED
|
@@ -1,41 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { invokedDirectly, runEntry } from "@agents-can-communicate/cli/managed-entry";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const adapters = Object.fromEntries(ALL_ADAPTERS().map(adapter => [adapter.id, adapter]));
|
|
10
|
-
|
|
11
|
-
// The composition root is the only place allowed to reach for ambient time and
|
|
12
|
-
// randomness; everything below it receives them as ports.
|
|
13
|
-
const runtime = {
|
|
14
|
-
cwd: process.cwd(),
|
|
15
|
-
env: process.env,
|
|
16
|
-
platform: process.platform,
|
|
17
|
-
stdout: process.stdout,
|
|
18
|
-
stderr: process.stderr,
|
|
19
|
-
clock: { now: () => new Date().toISOString() },
|
|
20
|
-
ids: { next: kind => createId(kind, randomBytes) },
|
|
21
|
-
createDeliveryRouter: ({ service, clock }) =>
|
|
22
|
-
createDeliveryRouter({ service, adapters, clock }),
|
|
23
|
-
// Asked only by `acc config init`, and only when stdout is a terminal. There
|
|
24
|
-
// was no port here at all, so the question went to the fallback that always
|
|
25
|
-
// answers no: in a real terminal the command printed "not written" and never
|
|
26
|
-
// said why, and `--yes` - the flag documented for runs with nobody to ask -
|
|
27
|
-
// was the only way to write the file.
|
|
28
|
-
confirm: (question, io = { input: process.stdin, output: process.stdout }) =>
|
|
29
|
-
askConfirmation(question, io),
|
|
30
|
-
// The two streams and the fact that a person is at both ends, for the
|
|
31
|
-
// per-client native delivery question `acc install` asks only interactively.
|
|
32
|
-
input: process.stdin,
|
|
33
|
-
output: process.stdout,
|
|
34
|
-
isInteractive: () => process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
35
|
-
// Asked for only by `acc version`, so a package missing its own manifest
|
|
36
|
-
// fails that one command rather than every command.
|
|
37
|
-
version: async () => JSON.parse(
|
|
38
|
-
await readFile(new URL("../package.json", import.meta.url), "utf8")).version,
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
process.exitCode = await main(process.argv.slice(2), runtime);
|
|
5
|
+
if (invokedDirectly(import.meta.url)) await runEntry({
|
|
6
|
+
kind: "acc", packageRoot: fileURLToPath(new URL("..", import.meta.url)),
|
|
7
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Internal entry point behind an ACC-owned shell shim: is this exact vendor
|
|
3
|
+
// executable eligible for native delivery right now? Exit 0 means yes and the
|
|
4
|
+
// shim exports its owned policy before `exec`; any other exit - including a
|
|
5
|
+
// crash, a missing adapter, or a damaged install - means the shim launches the
|
|
6
|
+
// vendor command untouched. Nothing is ever written to stdout, and stderr stays
|
|
7
|
+
// empty unless ACC_BOOTSTRAP_DEBUG=1 asks for one safe line.
|
|
8
|
+
import { checkNativeBootstrap } from "@agents-can-communicate/installer";
|
|
9
|
+
|
|
10
|
+
import { createClaudeCodeAdapter } from "@agents-can-communicate/adapter-claude-code";
|
|
11
|
+
import { createCodexAdapter } from "@agents-can-communicate/adapter-codex";
|
|
12
|
+
import { createGeminiCliAdapter } from "@agents-can-communicate/adapter-gemini-cli";
|
|
13
|
+
import { createGrokAdapter } from "@agents-can-communicate/adapter-grok";
|
|
14
|
+
import { createKimiAdapter } from "@agents-can-communicate/adapter-kimi";
|
|
15
|
+
|
|
16
|
+
import { parseBootstrapOptions } from "@agents-can-communicate/cli/managed-entry";
|
|
17
|
+
|
|
18
|
+
function debug(line) {
|
|
19
|
+
if (process.env.ACC_BOOTSTRAP_DEBUG === "1") process.stderr.write(`acc-bootstrap: ${line}\n`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function main() {
|
|
23
|
+
try {
|
|
24
|
+
const options = parseBootstrapOptions(process.argv.slice(2));
|
|
25
|
+
if (options === null) {
|
|
26
|
+
debug("usage: --adapter <id> --real-executable <path> --data-home <path>");
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
29
|
+
const registry = {
|
|
30
|
+
claude_code: createClaudeCodeAdapter, codex: createCodexAdapter,
|
|
31
|
+
gemini_cli: createGeminiCliAdapter, grok: createGrokAdapter, kimi: createKimiAdapter,
|
|
32
|
+
};
|
|
33
|
+
const adapter = registry[options.adapter]?.();
|
|
34
|
+
if (adapter === undefined) {
|
|
35
|
+
debug(`${options.adapter}: unknown adapter`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const result = await checkNativeBootstrap({ adapter, realExecutable: options.realExecutable,
|
|
39
|
+
platform: `${process.platform}-${process.arch}`, dataHome: options.dataHome, timeoutMs: 750 });
|
|
40
|
+
debug(`${options.adapter}: ${result.supported ? "supported" : result.reasonCode}`);
|
|
41
|
+
process.exit(result.supported ? 0 : 1);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
debug(`failed: ${String(error?.code ?? error?.name ?? "error")}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The ACC Channel binary Claude Code spawns as a stdio MCP child. It composes
|
|
3
|
+
// the same workspace discovery, session binding, core service, and local
|
|
4
|
+
// data-home rules as acc-hook, opens a session-scoped endpoint for the delivery
|
|
5
|
+
// router, and turns the model's explicit acc_reply / acc_ack into real ACC
|
|
6
|
+
// records. It never collects a transcript or runs a model, and it fails open:
|
|
7
|
+
// any composition error leaves Claude a plain MCP server that simply offers no
|
|
8
|
+
// tools rather than crashing the session.
|
|
9
|
+
import { randomBytes } from "node:crypto";
|
|
10
|
+
|
|
11
|
+
import { createClaudeCodeAdapter } from "@agents-can-communicate/adapter-claude-code";
|
|
12
|
+
import { listSessionBindings } from "@agents-can-communicate/adapter-sdk";
|
|
13
|
+
import { createCoordinationService } from "@agents-can-communicate/core";
|
|
14
|
+
import { resolveClientPid } from "@agents-can-communicate/hook-runner/client-pid";
|
|
15
|
+
import { readProcessTable } from "@agents-can-communicate/hook-runner/process-table";
|
|
16
|
+
import { createId } from "@agents-can-communicate/protocol";
|
|
17
|
+
import { openFilesystemStore } from "@agents-can-communicate/storage-filesystem";
|
|
18
|
+
import { createGitProbe, discoverWorkspace, platformDataHome, runtimePaths }
|
|
19
|
+
from "@agents-can-communicate/cli";
|
|
20
|
+
|
|
21
|
+
import { createAccChannel, endpointDir, routeAck, routeReply }
|
|
22
|
+
from "@agents-can-communicate/adapter-claude-code/channel";
|
|
23
|
+
|
|
24
|
+
import { pump, startInertChannel } from "./claude-channel-stdio.mjs";
|
|
25
|
+
|
|
26
|
+
const clock = { now: () => new Date().toISOString() };
|
|
27
|
+
const ids = { next: kind => createId(kind, randomBytes) };
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The ACC session this Claude process opened - decided by which client process
|
|
31
|
+
* this Channel is running under, never by how many sessions happen to be
|
|
32
|
+
* visible.
|
|
33
|
+
*
|
|
34
|
+
* There used to be a fallback here: if exactly one session was live, it was
|
|
35
|
+
* taken to be this one. On a single-session machine that looked safe, and with
|
|
36
|
+
* two sessions it silently handed one client the other's identity. The Channel
|
|
37
|
+
* starts while its own SessionStart hook is still writing its binding, so the
|
|
38
|
+
* only binding a second client can see at that moment is the *first* client's -
|
|
39
|
+
* and the wait that was added to survive that race then locks the wrong answer
|
|
40
|
+
* in on the first attempt, because it is a complete, live, plausible binding.
|
|
41
|
+
*
|
|
42
|
+
* Measured on two real 2.1.259 sessions: both Channels registered an endpoint
|
|
43
|
+
* under the first client's pid. `bindNativeSession` refuses two registrations
|
|
44
|
+
* for one pid, so the session that had been receiving live messages dropped
|
|
45
|
+
* back to the durable inbox - and an `acc_reply` from the second window would
|
|
46
|
+
* have been recorded as the first session's answer, which is a false record
|
|
47
|
+
* rather than a lost message.
|
|
48
|
+
*
|
|
49
|
+
* This process was spawned by its client, so its own ancestry names that
|
|
50
|
+
* client, and no race can change that. Ownership is decided by it.
|
|
51
|
+
*/
|
|
52
|
+
export async function resolveSession({ runtimeDir, service, env, ownClientPid,
|
|
53
|
+
listBindings = listSessionBindings }) {
|
|
54
|
+
if (!Number.isInteger(ownClientPid)) return null;
|
|
55
|
+
const bindings = await listBindings({ runtimeDir });
|
|
56
|
+
if (bindings.length === 0) return null;
|
|
57
|
+
const status = await service.collectStatus({});
|
|
58
|
+
const live = new Set(status.participants
|
|
59
|
+
.filter(participant => participant.presence !== "offline")
|
|
60
|
+
.map(participant => participant.sessionId));
|
|
61
|
+
const mine = bindings.filter(binding => live.has(binding.accSessionId)
|
|
62
|
+
&& binding.clientPid === ownClientPid);
|
|
63
|
+
// One client process can outlive a session and open another, so the pid alone
|
|
64
|
+
// can still name two. The harness session id the client exports separates
|
|
65
|
+
// them; with nothing to separate them the answer is nobody, as before.
|
|
66
|
+
const exported = new Set(Object.values(env ?? {}).filter(value => typeof value === "string"));
|
|
67
|
+
const matched = mine.filter(binding => exported.has(binding.harnessSessionId));
|
|
68
|
+
const chosen = mine.length === 1 ? mine[0] : matched.length === 1 ? matched[0] : null;
|
|
69
|
+
return chosen === null ? null
|
|
70
|
+
: { sessionId: chosen.accSessionId, generation: chosen.generation, clientPid: chosen.clientPid };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The client process this Channel was spawned by, or null when nobody knows. */
|
|
74
|
+
export async function ownClient({ table = null, from = process.pid,
|
|
75
|
+
command = createClaudeCodeAdapter().client.command } = {}) {
|
|
76
|
+
return resolveClientPid({ table: table ?? await readProcessTable(), from, command });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// How long the Channel will wait for the hook to publish this session's
|
|
80
|
+
// binding. Claude spawns this child while SessionStart is still running - both
|
|
81
|
+
// landed in the same second on a real 2.1.259 launch - and a single lookup
|
|
82
|
+
// loses that race often enough to make native delivery activate or not per
|
|
83
|
+
// launch. Bounded, because a session with no ACC binding must still be answered.
|
|
84
|
+
const BINDING_WAIT_MS = 5_000;
|
|
85
|
+
const BINDING_POLL_MS = 100;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The session binding, once it exists - or null when the wait runs out.
|
|
89
|
+
*
|
|
90
|
+
* A binding with no `clientPid` names no process, and the Channel binds an
|
|
91
|
+
* exact one, so it does not count as resolved: the hook writes the identity
|
|
92
|
+
* first and the certified facts after, and reading in between must keep waiting
|
|
93
|
+
* rather than settle for the half-written answer.
|
|
94
|
+
*/
|
|
95
|
+
export async function resolveWithin({ resolve, deadline, intervalMs = BINDING_POLL_MS,
|
|
96
|
+
now = () => Date.now(), sleep = ms => new Promise(resolve_ => setTimeout(resolve_, ms)) }) {
|
|
97
|
+
for (;;) {
|
|
98
|
+
const session = await resolve();
|
|
99
|
+
if (session !== null && Number.isInteger(session?.clientPid)) return session;
|
|
100
|
+
if (now() >= deadline) return null;
|
|
101
|
+
await sleep(intervalMs);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function compose() {
|
|
106
|
+
const descriptor = await discoverWorkspace({ cwd: process.cwd(), env: process.env,
|
|
107
|
+
gitProbe: createGitProbe() });
|
|
108
|
+
const paths = runtimePaths({ dataHome: platformDataHome({ platform: process.platform,
|
|
109
|
+
env: process.env }), workspaceId: descriptor.id, workspaceRoots: descriptor.roots });
|
|
110
|
+
const store = await openFilesystemStore({ root: paths.root, clock, ids,
|
|
111
|
+
workspaceId: descriptor.id });
|
|
112
|
+
const service = createCoordinationService({ store, clock, ids });
|
|
113
|
+
const write = payload => process.stdout.write(`${JSON.stringify(payload)}\n`);
|
|
114
|
+
// Read once: the ancestry that decides ownership cannot change while this
|
|
115
|
+
// process runs, and re-reading it on every poll would spawn `ps` in a loop.
|
|
116
|
+
const clientPid = await ownClient();
|
|
117
|
+
const session = await resolveWithin({
|
|
118
|
+
resolve: () => resolveSession({ runtimeDir: paths.root, service, env: process.env,
|
|
119
|
+
ownClientPid: clientPid }),
|
|
120
|
+
deadline: Date.now() + BINDING_WAIT_MS });
|
|
121
|
+
// No binding to serve - but Claude is already speaking MCP to this child, and
|
|
122
|
+
// returning here left the event loop empty: the process exited in 75ms
|
|
123
|
+
// without answering `initialize`, and Claude reported the server as failed to
|
|
124
|
+
// connect on every session that enables the plugin without ACC's shim.
|
|
125
|
+
if (session === null || !Number.isInteger(session.clientPid)) {
|
|
126
|
+
return startInertChannel({ write });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const channel = createAccChannel({
|
|
130
|
+
endpointDir: endpointDir(paths.root),
|
|
131
|
+
clientPid: session.clientPid,
|
|
132
|
+
write,
|
|
133
|
+
routeReply: ({ messageId, body }) => routeReply({ service, session, messageId, body }),
|
|
134
|
+
routeAck: ({ messageId }) => routeAck({ service, session, messageId }),
|
|
135
|
+
// This process is the only party that knows the endpoint is still being
|
|
136
|
+
// served, and Claude publishes no heartbeat, so nothing else would move
|
|
137
|
+
// ACC's lease while the session sits idle - which is when live delivery is
|
|
138
|
+
// worth having.
|
|
139
|
+
refreshBinding: leaseUntil => service.refreshDeliveryBinding({
|
|
140
|
+
sessionId: session.sessionId, generation: session.generation, leaseUntil }),
|
|
141
|
+
});
|
|
142
|
+
await channel.listen();
|
|
143
|
+
pump(channel.handleLine, () => { channel.close(); process.exit(0); });
|
|
144
|
+
return channel;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function main() {
|
|
148
|
+
await compose().catch(() => startInertChannel());
|
|
149
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Hook entry point: `acc-hook <adapter-id> <kind>`, payload on stdin.
|
|
3
|
+
//
|
|
4
|
+
// Every harness runs this as a short-lived child process in front of the user's
|
|
5
|
+
// turn. The one rule that overrides all others here: never be the reason
|
|
6
|
+
// someone's session stops working. Unknown adapter, malformed payload, broken
|
|
7
|
+
// store, missing binding - all of them end in "allow, exit 0".
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
|
|
10
|
+
import { createId } from "@agents-can-communicate/protocol";
|
|
11
|
+
import { runHook } from "@agents-can-communicate/hook-runner";
|
|
12
|
+
|
|
13
|
+
import { createClaudeCodeAdapter } from "@agents-can-communicate/adapter-claude-code";
|
|
14
|
+
import { createCodexAdapter } from "@agents-can-communicate/adapter-codex";
|
|
15
|
+
import { createGeminiCliAdapter } from "@agents-can-communicate/adapter-gemini-cli";
|
|
16
|
+
import { createGrokAdapter } from "@agents-can-communicate/adapter-grok";
|
|
17
|
+
import { createKimiAdapter } from "@agents-can-communicate/adapter-kimi";
|
|
18
|
+
|
|
19
|
+
const adapters = {
|
|
20
|
+
claude_code: createClaudeCodeAdapter(),
|
|
21
|
+
codex: createCodexAdapter(),
|
|
22
|
+
gemini_cli: createGeminiCliAdapter(),
|
|
23
|
+
grok: createGrokAdapter(),
|
|
24
|
+
kimi: createKimiAdapter(),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const readStdin = () => new Promise(resolve => {
|
|
28
|
+
// A hook is always given its payload on stdin, but a client that closes it
|
|
29
|
+
// without writing must not leave this process hanging in front of a turn.
|
|
30
|
+
if (process.stdin.isTTY) return resolve("");
|
|
31
|
+
let raw = "";
|
|
32
|
+
process.stdin.setEncoding("utf8");
|
|
33
|
+
process.stdin.on("data", chunk => { raw += chunk; });
|
|
34
|
+
process.stdin.on("end", () => resolve(raw));
|
|
35
|
+
process.stdin.on("error", () => resolve(""));
|
|
36
|
+
return undefined;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
import { completeHookOutput } from "./hook-output.mjs";
|
|
40
|
+
|
|
41
|
+
export async function main() {
|
|
42
|
+
const [adapterId] = process.argv.slice(2);
|
|
43
|
+
|
|
44
|
+
let payload = null;
|
|
45
|
+
try {
|
|
46
|
+
payload = JSON.parse(await readStdin());
|
|
47
|
+
} catch {
|
|
48
|
+
payload = null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const result = await runHook({ adapterId, payload, adapters,
|
|
52
|
+
runtime: { clock: { now: () => new Date().toISOString() },
|
|
53
|
+
ids: { next: kind => createId(kind, randomBytes) } },
|
|
54
|
+
env: process.env });
|
|
55
|
+
|
|
56
|
+
const completed = await completeHookOutput(result);
|
|
57
|
+
process.exitCode = result.exitCode ?? completed.exitCode;
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
|
|
4
|
+
import { EXIT, createId } from "@agents-can-communicate/protocol";
|
|
5
|
+
import { createCoordinationService } from "@agents-can-communicate/core";
|
|
6
|
+
import { readInstalledLivePolicy } from "@agents-can-communicate/installer";
|
|
7
|
+
import { createDeliveryRouter } from "@agents-can-communicate/delivery-router";
|
|
8
|
+
import { openFilesystemStore } from "@agents-can-communicate/storage-filesystem";
|
|
9
|
+
import { ALL_ADAPTERS, createGitProbe, discoverWorkspace, platformDataHome, runtimePaths }
|
|
10
|
+
from "@agents-can-communicate/cli";
|
|
11
|
+
import { serve } from "@agents-can-communicate/mcp-server";
|
|
12
|
+
|
|
13
|
+
export async function main({ managerRoot = null, packageRoot } = {}) {
|
|
14
|
+
// The composition root is the only place allowed to reach for ambient time and
|
|
15
|
+
// randomness. The participant name comes from configuration, never from the
|
|
16
|
+
// client: the protocol says clientInfo is self-reported and must not drive
|
|
17
|
+
// behaviour, and the session is derived from this configuration alone.
|
|
18
|
+
// Nothing is read from the command line, so nothing may be passed on it. It
|
|
19
|
+
// used to accept and ignore anything: writing `acc-mcp --cwd <project>` - the
|
|
20
|
+
// habit `acc` teaches - started a server rooted wherever the client happened to
|
|
21
|
+
// launch it, alone in a workspace nobody else was in, with no warning at all.
|
|
22
|
+
if (process.argv.length > 2) {
|
|
23
|
+
process.stderr.write("acc-mcp takes no arguments. It is configured by environment:\n"
|
|
24
|
+
+ " ACC_MCP_PARTICIPANT who this server takes part as (default: mcp)\n"
|
|
25
|
+
+ " ACC_MCP_WORKSPACE the project it joins (default: the working directory)\n"
|
|
26
|
+
+ `refusing: ${process.argv.slice(2).join(" ")}\n`);
|
|
27
|
+
process.exit(EXIT.USAGE);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const participantId = process.env.ACC_MCP_PARTICIPANT ?? "mcp";
|
|
31
|
+
const clock = { now: () => new Date().toISOString() };
|
|
32
|
+
const ids = { next: kind => createId(kind, randomBytes) };
|
|
33
|
+
|
|
34
|
+
const descriptor = await discoverWorkspace({
|
|
35
|
+
cwd: process.env.ACC_MCP_WORKSPACE ?? process.cwd(),
|
|
36
|
+
env: process.env,
|
|
37
|
+
gitProbe: createGitProbe(),
|
|
38
|
+
});
|
|
39
|
+
const dataHome = platformDataHome({ platform: process.platform, env: process.env });
|
|
40
|
+
const paths = runtimePaths({
|
|
41
|
+
dataHome,
|
|
42
|
+
workspaceId: descriptor.id,
|
|
43
|
+
workspaceRoots: descriptor.roots,
|
|
44
|
+
});
|
|
45
|
+
const store = await openFilesystemStore({ root: paths.root, clock, ids,
|
|
46
|
+
workspaceId: descriptor.id });
|
|
47
|
+
const service = createCoordinationService({ store, clock, ids });
|
|
48
|
+
const adapters = Object.fromEntries(ALL_ADAPTERS().map(adapter => [adapter.id, adapter]));
|
|
49
|
+
|
|
50
|
+
await serve({
|
|
51
|
+
input: process.stdin,
|
|
52
|
+
output: process.stdout,
|
|
53
|
+
log: message => process.stderr.write(`acc-mcp: ${message}\n`),
|
|
54
|
+
context: {
|
|
55
|
+
service,
|
|
56
|
+
deliveryRouter: createDeliveryRouter({ service, adapters, clock,
|
|
57
|
+
platform: `${process.platform}-${process.arch}`,
|
|
58
|
+
readLivePolicy: ({ adapter }) => readInstalledLivePolicy({ dataHome,
|
|
59
|
+
adapterId: adapter.id }) }),
|
|
60
|
+
workspaceId: descriptor.id,
|
|
61
|
+
participantId,
|
|
62
|
+
descriptor,
|
|
63
|
+
runtimeDir: paths.root,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Exiting on stdin EOF is the only portable graceful shutdown in this binding.
|
|
68
|
+
process.exitCode = 0;
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { randomBytes } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
import { createId } from "@agents-can-communicate/protocol";
|
|
6
|
+
import { readInstalledLivePolicy } from "@agents-can-communicate/installer";
|
|
7
|
+
import { createDeliveryRouter } from "@agents-can-communicate/delivery-router";
|
|
8
|
+
import { ALL_ADAPTERS, askConfirmation, main as runCli } from "@agents-can-communicate/cli";
|
|
9
|
+
|
|
10
|
+
export async function main({ managerRoot = null, packageRoot, managementOnly = false } = {}) {
|
|
11
|
+
const adapters = Object.fromEntries(ALL_ADAPTERS().map(adapter => [adapter.id, adapter]));
|
|
12
|
+
|
|
13
|
+
// The composition root is the only place allowed to reach for ambient time and
|
|
14
|
+
// randomness; everything below it receives them as ports.
|
|
15
|
+
const runtime = {
|
|
16
|
+
cwd: process.cwd(),
|
|
17
|
+
managerRoot,
|
|
18
|
+
managementOnly,
|
|
19
|
+
packageRoot,
|
|
20
|
+
env: process.env,
|
|
21
|
+
platform: process.platform,
|
|
22
|
+
stdout: process.stdout,
|
|
23
|
+
stderr: process.stderr,
|
|
24
|
+
clock: { now: () => new Date().toISOString() },
|
|
25
|
+
ids: { next: kind => createId(kind, randomBytes) },
|
|
26
|
+
createDeliveryRouter: ({ service, clock, dataHome }) =>
|
|
27
|
+
createDeliveryRouter({ service, adapters, clock,
|
|
28
|
+
platform: `${process.platform}-${process.arch}`,
|
|
29
|
+
readLivePolicy: ({ adapter }) => readInstalledLivePolicy({ dataHome,
|
|
30
|
+
adapterId: adapter.id }) }),
|
|
31
|
+
// Asked only by `acc config init`, and only when stdout is a terminal. There
|
|
32
|
+
// was no port here at all, so the question went to the fallback that always
|
|
33
|
+
// answers no: in a real terminal the command printed "not written" and never
|
|
34
|
+
// said why, and `--yes` - the flag documented for runs with nobody to ask -
|
|
35
|
+
// was the only way to write the file.
|
|
36
|
+
confirm: (question, io = { input: process.stdin, output: process.stdout }) =>
|
|
37
|
+
askConfirmation(question, io),
|
|
38
|
+
// The two streams and the fact that a person is at both ends, for the
|
|
39
|
+
// per-client native delivery question `acc install` asks only interactively.
|
|
40
|
+
input: process.stdin,
|
|
41
|
+
output: process.stdout,
|
|
42
|
+
isInteractive: () => process.stdin.isTTY === true && process.stdout.isTTY === true,
|
|
43
|
+
// Asked for only by `acc version`, so a package missing its own manifest
|
|
44
|
+
// fails that one command rather than every command.
|
|
45
|
+
version: async () => JSON.parse(
|
|
46
|
+
await readFile(new URL("../../package.json", import.meta.url), "utf8")).version,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
process.exitCode = await runCli(process.argv.slice(2), runtime);
|
|
50
|
+
|
|
51
|
+
}
|