agents-can-communicate 0.3.1 → 0.4.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.
Files changed (161) hide show
  1. package/README.md +95 -52
  2. package/SECURITY.md +1 -1
  3. package/bin/acc-bootstrap.mjs +5 -54
  4. package/bin/acc-claude-channel.mjs +8 -175
  5. package/bin/acc-hook.mjs +4 -133
  6. package/bin/acc-mcp.mjs +4 -59
  7. package/bin/acc-update-worker.mjs +8 -0
  8. package/bin/acc.mjs +5 -39
  9. package/bin/entrypoints/acc-bootstrap.mjs +47 -0
  10. package/bin/entrypoints/acc-claude-channel.mjs +149 -0
  11. package/bin/entrypoints/acc-hook.mjs +58 -0
  12. package/bin/entrypoints/acc-mcp.mjs +70 -0
  13. package/bin/entrypoints/acc.mjs +51 -0
  14. package/bin/entrypoints/claude-channel-stdio.mjs +29 -0
  15. package/bin/entrypoints/hook-output.mjs +77 -0
  16. package/docs/ADAPTER_AUTHORING.md +52 -8
  17. package/docs/ARCHITECTURE.md +64 -11
  18. package/docs/CAPABILITIES.md +41 -37
  19. package/docs/CLI.md +145 -25
  20. package/docs/CONCEPTS.md +13 -6
  21. package/docs/CONFIGURATION.md +37 -22
  22. package/docs/DESIGN_DECISIONS.md +16 -11
  23. package/docs/GETTING_STARTED.md +41 -7
  24. package/docs/GLOSSARY.md +9 -3
  25. package/docs/HOW_IT_WORKS.md +32 -11
  26. package/docs/MCP.md +91 -24
  27. package/docs/PROTOCOL.md +69 -12
  28. package/docs/RELEASING.md +28 -10
  29. package/docs/SECURITY_MODEL.md +47 -13
  30. package/docs/TROUBLESHOOTING.md +102 -20
  31. package/docs/UPGRADING.md +154 -0
  32. package/docs/WHY_ACC.md +5 -4
  33. package/docs/index.md +8 -0
  34. package/node_modules/@agents-can-communicate/adapter-claude-code/package.json +1 -1
  35. package/node_modules/@agents-can-communicate/adapter-claude-code/plugin/skills/acc/SKILL.md +106 -5
  36. package/node_modules/@agents-can-communicate/adapter-claude-code/src/install.mjs +6 -6
  37. package/node_modules/@agents-can-communicate/adapter-claude-code/src/native-delivery.mjs +2 -1
  38. package/node_modules/@agents-can-communicate/adapter-codex/certification.json +38 -13
  39. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/certification-provenance.json +220 -0
  40. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-current-binding-product-evidence.json +1549 -0
  41. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-current-binding-product.json +27 -0
  42. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-product-evidence.json +1549 -0
  43. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-product.json +27 -0
  44. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-transport-evidence.json +259 -0
  45. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.1-local-daemon-transport.json +21 -0
  46. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-current-binding-product-evidence.json +1549 -0
  47. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-current-binding-product.json +27 -0
  48. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-product-evidence.json +1549 -0
  49. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-product.json +27 -0
  50. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-transport-evidence.json +259 -0
  51. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.153.4-local-daemon-transport.json +21 -0
  52. package/node_modules/@agents-can-communicate/adapter-codex/package.json +14 -2
  53. package/node_modules/@agents-can-communicate/adapter-codex/plugin/skills/acc/SKILL.md +106 -5
  54. package/node_modules/@agents-can-communicate/adapter-codex/src/adapter.mjs +26 -44
  55. package/node_modules/@agents-can-communicate/adapter-codex/src/app-server-client.mjs +70 -17
  56. package/node_modules/@agents-can-communicate/adapter-codex/src/config-block.mjs +231 -0
  57. package/node_modules/@agents-can-communicate/adapter-codex/src/hooks.mjs +1 -1
  58. package/node_modules/@agents-can-communicate/adapter-codex/src/install.mjs +71 -63
  59. package/node_modules/@agents-can-communicate/adapter-codex/src/native-delivery.mjs +107 -103
  60. package/node_modules/@agents-can-communicate/adapter-codex/src/native-endpoint.mjs +96 -0
  61. package/node_modules/@agents-can-communicate/adapter-codex/src/ws-json-rpc.mjs +3 -2
  62. package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/gemini-extension.json +1 -1
  63. package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/skills/acc/SKILL.md +106 -5
  64. package/node_modules/@agents-can-communicate/adapter-gemini-cli/package.json +1 -1
  65. package/node_modules/@agents-can-communicate/adapter-gemini-cli/src/install.mjs +2 -2
  66. package/node_modules/@agents-can-communicate/adapter-grok/package.json +1 -1
  67. package/node_modules/@agents-can-communicate/adapter-grok/plugin/skills/acc/SKILL.md +122 -8
  68. package/node_modules/@agents-can-communicate/adapter-grok/src/adapter.mjs +5 -3
  69. package/node_modules/@agents-can-communicate/adapter-grok/src/hooks.mjs +9 -0
  70. package/node_modules/@agents-can-communicate/adapter-grok/src/install.mjs +2 -2
  71. package/node_modules/@agents-can-communicate/adapter-kimi/package.json +1 -1
  72. package/node_modules/@agents-can-communicate/adapter-kimi/plugin/skills/acc/SKILL.md +106 -5
  73. package/node_modules/@agents-can-communicate/adapter-kimi/src/hooks.mjs +1 -1
  74. package/node_modules/@agents-can-communicate/adapter-kimi/src/install.mjs +2 -2
  75. package/node_modules/@agents-can-communicate/adapter-sdk/package.json +1 -1
  76. package/node_modules/@agents-can-communicate/adapter-sdk/src/capabilities.mjs +5 -0
  77. package/node_modules/@agents-can-communicate/adapter-sdk/src/context-projector.mjs +26 -4
  78. package/node_modules/@agents-can-communicate/adapter-sdk/src/decision-text.mjs +19 -0
  79. package/node_modules/@agents-can-communicate/adapter-sdk/src/hook-shim.mjs +5 -3
  80. package/node_modules/@agents-can-communicate/adapter-sdk/src/index.mjs +1 -0
  81. package/node_modules/@agents-can-communicate/adapter-sdk/src/native-delivery.mjs +9 -2
  82. package/node_modules/@agents-can-communicate/adapter-sdk/src/native-vocabulary.mjs +2 -6
  83. package/node_modules/@agents-can-communicate/adapter-sdk/src/session-binding.mjs +29 -9
  84. package/node_modules/@agents-can-communicate/adapter-sdk/src/toml-block.mjs +8 -6
  85. package/node_modules/@agents-can-communicate/cli/package.json +4 -2
  86. package/node_modules/@agents-can-communicate/cli/src/args.mjs +49 -22
  87. package/node_modules/@agents-can-communicate/cli/src/doctor-command.mjs +11 -4
  88. package/node_modules/@agents-can-communicate/cli/src/git-probe.mjs +9 -3
  89. package/node_modules/@agents-can-communicate/cli/src/help.mjs +109 -14
  90. package/node_modules/@agents-can-communicate/cli/src/install-command.mjs +24 -5
  91. package/node_modules/@agents-can-communicate/cli/src/main.mjs +35 -12
  92. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/activation.mjs +110 -0
  93. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/command.mjs +64 -0
  94. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/download.mjs +71 -0
  95. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/entry.mjs +110 -0
  96. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/generation.mjs +167 -0
  97. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/install.mjs +78 -0
  98. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/launchers.mjs +60 -0
  99. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/leases.mjs +60 -0
  100. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/location.mjs +55 -0
  101. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/mutex.mjs +145 -0
  102. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/policy.mjs +4 -0
  103. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/refresh.mjs +40 -0
  104. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/schedule.mjs +21 -0
  105. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/state.mjs +123 -0
  106. package/node_modules/@agents-can-communicate/cli/src/managed-runtime/worker.mjs +65 -0
  107. package/node_modules/@agents-can-communicate/cli/src/runtime-paths.mjs +1 -1
  108. package/node_modules/@agents-can-communicate/cli/src/session-owner.mjs +33 -108
  109. package/node_modules/@agents-can-communicate/cli/src/update-command.mjs +25 -7
  110. package/node_modules/@agents-can-communicate/core/package.json +1 -1
  111. package/node_modules/@agents-can-communicate/core/src/attention.mjs +3 -0
  112. package/node_modules/@agents-can-communicate/core/src/claims.mjs +13 -8
  113. package/node_modules/@agents-can-communicate/core/src/conversations.mjs +9 -25
  114. package/node_modules/@agents-can-communicate/core/src/decision-changes.mjs +36 -0
  115. package/node_modules/@agents-can-communicate/core/src/decision-state.mjs +42 -0
  116. package/node_modules/@agents-can-communicate/core/src/delivery-bindings.mjs +11 -4
  117. package/node_modules/@agents-can-communicate/core/src/inbox.mjs +48 -17
  118. package/node_modules/@agents-can-communicate/core/src/intents.mjs +35 -15
  119. package/node_modules/@agents-can-communicate/core/src/materialisation.mjs +7 -5
  120. package/node_modules/@agents-can-communicate/core/src/message-pages.mjs +75 -0
  121. package/node_modules/@agents-can-communicate/core/src/next-turn-delivery.mjs +31 -0
  122. package/node_modules/@agents-can-communicate/core/src/session-opening.mjs +128 -0
  123. package/node_modules/@agents-can-communicate/core/src/sessions.mjs +58 -132
  124. package/node_modules/@agents-can-communicate/core/src/sync.mjs +31 -2
  125. package/node_modules/@agents-can-communicate/delivery-router/package.json +1 -1
  126. package/node_modules/@agents-can-communicate/delivery-router/src/refresh-binding.mjs +38 -0
  127. package/node_modules/@agents-can-communicate/delivery-router/src/router.mjs +86 -10
  128. package/node_modules/@agents-can-communicate/hook-runner/package.json +1 -1
  129. package/node_modules/@agents-can-communicate/hook-runner/src/client-version.mjs +1 -0
  130. package/node_modules/@agents-can-communicate/hook-runner/src/native-binding.mjs +6 -4
  131. package/node_modules/@agents-can-communicate/hook-runner/src/native-retirement.mjs +48 -0
  132. package/node_modules/@agents-can-communicate/hook-runner/src/owner-context.mjs +30 -0
  133. package/node_modules/@agents-can-communicate/hook-runner/src/process-table.mjs +1 -1
  134. package/node_modules/@agents-can-communicate/hook-runner/src/runner.mjs +172 -67
  135. package/node_modules/@agents-can-communicate/hook-runner/src/session-lifecycle.mjs +13 -0
  136. package/node_modules/@agents-can-communicate/installer/package.json +1 -1
  137. package/node_modules/@agents-can-communicate/installer/src/apply.mjs +17 -2
  138. package/node_modules/@agents-can-communicate/installer/src/bootstrap-runtime.mjs +11 -5
  139. package/node_modules/@agents-can-communicate/installer/src/detect.mjs +1 -1
  140. package/node_modules/@agents-can-communicate/installer/src/index.mjs +1 -0
  141. package/node_modules/@agents-can-communicate/installer/src/live-policy.mjs +21 -0
  142. package/node_modules/@agents-can-communicate/installer/src/native-activation.mjs +20 -6
  143. package/node_modules/@agents-can-communicate/installer/src/ownership.mjs +10 -4
  144. package/node_modules/@agents-can-communicate/installer/src/plan.mjs +3 -3
  145. package/node_modules/@agents-can-communicate/mcp-server/package.json +1 -1
  146. package/node_modules/@agents-can-communicate/mcp-server/src/protocol.mjs +85 -0
  147. package/node_modules/@agents-can-communicate/mcp-server/src/resources.mjs +3 -2
  148. package/node_modules/@agents-can-communicate/mcp-server/src/server.mjs +59 -57
  149. package/node_modules/@agents-can-communicate/mcp-server/src/tools.mjs +47 -33
  150. package/node_modules/@agents-can-communicate/protocol/package.json +1 -1
  151. package/node_modules/@agents-can-communicate/protocol/src/conversations.mjs +3 -0
  152. package/node_modules/@agents-can-communicate/protocol/src/decision-changes.mjs +15 -0
  153. package/node_modules/@agents-can-communicate/protocol/src/index.mjs +3 -1
  154. package/node_modules/@agents-can-communicate/protocol/src/schema.mjs +14 -5
  155. package/node_modules/@agents-can-communicate/storage-filesystem/package.json +1 -1
  156. package/node_modules/@agents-can-communicate/storage-filesystem/src/atomic-json.mjs +5 -1
  157. package/node_modules/@agents-can-communicate/storage-filesystem/src/deadline.mjs +7 -0
  158. package/node_modules/@agents-can-communicate/storage-filesystem/src/index.mjs +2 -0
  159. package/node_modules/@agents-can-communicate/storage-filesystem/src/session-read.mjs +25 -0
  160. package/node_modules/@agents-can-communicate/storage-filesystem/src/store.mjs +28 -25
  161. package/package.json +2 -1
package/bin/acc-mcp.mjs CHANGED
@@ -1,62 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import { randomBytes } from "node:crypto";
2
+ import { fileURLToPath } from "node:url";
3
+ import { invokedDirectly, runEntry } from "@agents-can-communicate/cli/managed-entry";
3
4
 
4
- import { EXIT, createId } from "@agents-can-communicate/protocol";
5
- import { createCoordinationService } from "@agents-can-communicate/core";
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 { randomBytes } from "node:crypto";
3
- import { readFile } from "node:fs/promises";
2
+ import { fileURLToPath } from "node:url";
3
+ import { invokedDirectly, runEntry } from "@agents-can-communicate/cli/managed-entry";
4
4
 
5
- import { createId } from "@agents-can-communicate/protocol";
6
- import { createDeliveryRouter } from "@agents-can-communicate/delivery-router";
7
- import { ALL_ADAPTERS, askConfirmation, main } from "@agents-can-communicate/cli";
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
+ }
@@ -0,0 +1,29 @@
1
+ // Workspace-free MCP fallback shared by composition and managed admission failure.
2
+ import { createInertChannel } from "@agents-can-communicate/adapter-claude-code/channel";
3
+
4
+ export function startInertChannel({ write = payload => process.stdout.write(JSON.stringify(payload) + "\n") } = {}) {
5
+ const inert = createInertChannel({ write });
6
+ pump(inert.handleLine, () => process.exit(0));
7
+ return inert;
8
+ }
9
+
10
+ /** One line-delimited JSON pump, for the bound server and the unbound one alike. */
11
+ export function pump(handleLine, shutdown) {
12
+ let buffer = "";
13
+ process.stdin.setEncoding("utf8");
14
+ process.stdin.on("data", async chunk => {
15
+ buffer += chunk;
16
+ let newline = buffer.indexOf("\n");
17
+ while (newline !== -1) {
18
+ const line = buffer.slice(0, newline).trim();
19
+ buffer = buffer.slice(newline + 1);
20
+ newline = buffer.indexOf("\n");
21
+ if (line !== "") await handleLine(line);
22
+ }
23
+ });
24
+ process.stdin.on("end", shutdown);
25
+ process.once("SIGTERM", shutdown);
26
+ process.once("SIGINT", shutdown);
27
+ // Keeps the child answerable for as long as Claude holds the transport open.
28
+ process.stdin.resume();
29
+ }
@@ -0,0 +1,77 @@
1
+ export const writeOutput = (stream, output, { deadlineAt } = {}) => {
2
+ if (output === "") return Promise.resolve();
3
+ return new Promise((resolve, reject) => {
4
+ let settled = false;
5
+ let timer;
6
+ const finish = error => {
7
+ if (settled) return;
8
+ settled = true;
9
+ if (timer !== undefined) clearTimeout(timer);
10
+ if (error === undefined || error === null) resolve();
11
+ else reject(error);
12
+ };
13
+ if (deadlineAt !== undefined) {
14
+ const remaining = deadlineAt - Date.now();
15
+ if (remaining <= 0) {
16
+ finish(new Error("hook budget exhausted before stdout write"));
17
+ return;
18
+ }
19
+ timer = setTimeout(() => finish(
20
+ new Error("hook budget exhausted waiting for stdout callback")), remaining);
21
+ }
22
+ try {
23
+ stream.write(output, finish);
24
+ } catch (error) {
25
+ finish(error);
26
+ }
27
+ });
28
+ };
29
+
30
+ const DIAGNOSTIC_BYTES = 512;
31
+
32
+ function boundedDiagnostic(label, error) {
33
+ const detail = String(error?.message ?? error).replace(/[\u0000-\u001f\u007f]/g, " ");
34
+ let line = `acc: ${label}: ${detail}`;
35
+ while (Buffer.byteLength(`${line}\n`, "utf8") > DIAGNOSTIC_BYTES && line.length > 0) {
36
+ line = line.slice(0, -1);
37
+ }
38
+ return `${line}\n`;
39
+ }
40
+
41
+ function tryWrite(stream, output) {
42
+ if (output === "") return;
43
+ try {
44
+ stream.write(output, () => {});
45
+ } catch {
46
+ // A broken diagnostic stream must not turn a failed-open hook into a crash.
47
+ }
48
+ }
49
+
50
+ export async function completeHookOutput(result,
51
+ { stdout = process.stdout, stderr = process.stderr } = {}) {
52
+ if (result.failed || result.timedOut) {
53
+ // Only a known code selects static recovery advice. Arbitrary payload or
54
+ // filesystem error text must never become client-visible instructions.
55
+ const recovery = result.failureCode === "workspace_contains_runtime"
56
+ ? ": workspace contains ACC runtime state; open a project directory and restart the client"
57
+ + " (or set ACC_DATA_HOME outside the workspace)"
58
+ : "";
59
+ tryWrite(stderr, `acc: coordination unavailable${recovery}; hook continued without context\n`);
60
+ }
61
+ try {
62
+ await writeOutput(stdout, result.stdout ?? "", { deadlineAt: result.deadlineAt });
63
+ } catch (error) {
64
+ tryWrite(stderr, boundedDiagnostic("stdout write failed", error));
65
+ return { exitCode: 0, wroteStdout: false, committedOffers: false };
66
+ }
67
+
68
+ let committedOffers = true;
69
+ try {
70
+ await result.commitOffers?.();
71
+ } catch (error) {
72
+ committedOffers = false;
73
+ tryWrite(stderr, boundedDiagnostic("offer commit failed", error));
74
+ }
75
+ if (result.stderr) tryWrite(stderr, `${result.stderr}\n`);
76
+ return { exitCode: 0, wroteStdout: true, committedOffers };
77
+ }