agents-can-communicate 0.1.18 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +78 -70
  2. package/SECURITY.md +31 -0
  3. package/bin/acc-hook.mjs +94 -12
  4. package/bin/acc-mcp.mjs +6 -2
  5. package/bin/acc.mjs +6 -1
  6. package/docs/ADAPTER_AUTHORING.md +172 -0
  7. package/docs/ARCHITECTURE.md +131 -0
  8. package/docs/CAPABILITIES.md +102 -214
  9. package/docs/CLI.md +157 -0
  10. package/docs/CONCEPTS.md +134 -0
  11. package/docs/CONFIGURATION.md +143 -0
  12. package/docs/DESIGN_DECISIONS.md +89 -0
  13. package/docs/GETTING_STARTED.md +145 -0
  14. package/docs/GLOSSARY.md +26 -0
  15. package/docs/MCP.md +94 -0
  16. package/docs/PROTOCOL.md +200 -0
  17. package/docs/RELEASING.md +109 -0
  18. package/docs/SECURITY_MODEL.md +131 -0
  19. package/docs/TROUBLESHOOTING.md +102 -0
  20. package/docs/WHY_ACC.md +61 -0
  21. package/docs/index.md +42 -0
  22. package/node_modules/@agents-can-communicate/adapter-claude-code/certification.json +78 -0
  23. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/PreToolUse-Edit.json +19 -0
  24. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/PreToolUse.json +17 -0
  25. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/SessionEnd.json +8 -0
  26. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/SessionStart.json +7 -0
  27. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/UserPromptSubmit.json +9 -0
  28. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/certification-provenance.json +77 -0
  29. package/node_modules/@agents-can-communicate/adapter-claude-code/fixtures/delivery/claude-code-2.1.252.json +19 -0
  30. package/node_modules/@agents-can-communicate/adapter-claude-code/package.json +9 -1
  31. package/node_modules/@agents-can-communicate/adapter-claude-code/plugin/skills/acc/SKILL.md +20 -22
  32. package/node_modules/@agents-can-communicate/adapter-claude-code/src/adapter.mjs +12 -4
  33. package/node_modules/@agents-can-communicate/adapter-codex/certification.json +117 -0
  34. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/PreToolUse.json +14 -0
  35. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/SessionEnd.json +7 -0
  36. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/SessionStart.json +9 -0
  37. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/UserPromptSubmit.json +10 -0
  38. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/certification-provenance.json +66 -0
  39. package/node_modules/@agents-can-communicate/adapter-codex/fixtures/delivery/codex-cli-0.152.0.json +19 -0
  40. package/node_modules/@agents-can-communicate/adapter-codex/package.json +8 -1
  41. package/node_modules/@agents-can-communicate/adapter-codex/plugin/.codex-plugin/plugin.json +1 -1
  42. package/node_modules/@agents-can-communicate/adapter-codex/plugin/skills/acc/SKILL.md +20 -22
  43. package/node_modules/@agents-can-communicate/adapter-codex/src/adapter.mjs +18 -11
  44. package/node_modules/@agents-can-communicate/adapter-gemini-cli/certification.json +52 -0
  45. package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/gemini-extension.json +1 -1
  46. package/node_modules/@agents-can-communicate/adapter-gemini-cli/extension/skills/acc/SKILL.md +20 -22
  47. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/BeforeAgent.json +8 -0
  48. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/BeforeTool-shell.json +12 -0
  49. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/BeforeTool.json +12 -0
  50. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/SessionEnd.json +8 -0
  51. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/SessionStart.json +8 -0
  52. package/node_modules/@agents-can-communicate/adapter-gemini-cli/fixtures/certification-provenance.json +66 -0
  53. package/node_modules/@agents-can-communicate/adapter-gemini-cli/package.json +8 -1
  54. package/node_modules/@agents-can-communicate/adapter-gemini-cli/src/adapter.mjs +7 -3
  55. package/node_modules/@agents-can-communicate/adapter-gemini-cli/src/install.mjs +4 -2
  56. package/node_modules/@agents-can-communicate/adapter-grok/certification.json +3 -0
  57. package/node_modules/@agents-can-communicate/adapter-grok/package.json +2 -1
  58. package/node_modules/@agents-can-communicate/adapter-grok/plugin/skills/acc/SKILL.md +20 -22
  59. package/node_modules/@agents-can-communicate/adapter-grok/src/adapter.mjs +9 -9
  60. package/node_modules/@agents-can-communicate/adapter-kimi/certification.json +52 -0
  61. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/PreToolUse-Bash.json +12 -0
  62. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/PreToolUse-Write.json +12 -0
  63. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/SessionHeartbeat.json +7 -0
  64. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/SessionStart.json +9 -0
  65. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/UserPromptSubmit.json +8 -0
  66. package/node_modules/@agents-can-communicate/adapter-kimi/fixtures/certification-provenance.json +66 -0
  67. package/node_modules/@agents-can-communicate/adapter-kimi/package.json +8 -1
  68. package/node_modules/@agents-can-communicate/adapter-kimi/plugin/skills/acc/SKILL.md +20 -22
  69. package/node_modules/@agents-can-communicate/adapter-kimi/src/adapter.mjs +7 -3
  70. package/node_modules/@agents-can-communicate/adapter-sdk/package.json +1 -1
  71. package/node_modules/@agents-can-communicate/adapter-sdk/src/capabilities.mjs +34 -18
  72. package/node_modules/@agents-can-communicate/adapter-sdk/src/certification.mjs +158 -0
  73. package/node_modules/@agents-can-communicate/adapter-sdk/src/context-projector.mjs +36 -17
  74. package/node_modules/@agents-can-communicate/adapter-sdk/src/hook-shim.mjs +7 -1
  75. package/node_modules/@agents-can-communicate/adapter-sdk/src/index.mjs +1 -0
  76. package/node_modules/@agents-can-communicate/adapter-sdk/src/session-binding.mjs +13 -4
  77. package/node_modules/@agents-can-communicate/cli/package.json +1 -1
  78. package/node_modules/@agents-can-communicate/cli/src/args.mjs +11 -30
  79. package/node_modules/@agents-can-communicate/cli/src/doctor-command.mjs +3 -0
  80. package/node_modules/@agents-can-communicate/cli/src/help.mjs +2 -5
  81. package/node_modules/@agents-can-communicate/cli/src/install-command.mjs +9 -2
  82. package/node_modules/@agents-can-communicate/cli/src/main.mjs +100 -121
  83. package/node_modules/@agents-can-communicate/core/package.json +1 -1
  84. package/node_modules/@agents-can-communicate/core/src/attention.mjs +106 -0
  85. package/node_modules/@agents-can-communicate/core/src/conversations.mjs +276 -0
  86. package/node_modules/@agents-can-communicate/core/src/delivery-bindings.mjs +81 -0
  87. package/node_modules/@agents-can-communicate/core/src/finish-retries.mjs +97 -0
  88. package/node_modules/@agents-can-communicate/core/src/inbox.mjs +91 -107
  89. package/node_modules/@agents-can-communicate/core/src/index.mjs +3 -3
  90. package/node_modules/@agents-can-communicate/core/src/intents.mjs +0 -1
  91. package/node_modules/@agents-can-communicate/core/src/ports.mjs +2 -1
  92. package/node_modules/@agents-can-communicate/core/src/receipts.mjs +109 -0
  93. package/node_modules/@agents-can-communicate/core/src/service.mjs +11 -10
  94. package/node_modules/@agents-can-communicate/core/src/sessions.mjs +22 -20
  95. package/node_modules/@agents-can-communicate/core/src/status.mjs +11 -9
  96. package/node_modules/@agents-can-communicate/core/src/sync.mjs +3 -294
  97. package/node_modules/@agents-can-communicate/delivery-router/package.json +12 -0
  98. package/node_modules/@agents-can-communicate/delivery-router/src/index.mjs +1 -0
  99. package/node_modules/@agents-can-communicate/delivery-router/src/router.mjs +117 -0
  100. package/node_modules/@agents-can-communicate/hook-runner/package.json +1 -1
  101. package/node_modules/@agents-can-communicate/hook-runner/src/client-version.mjs +20 -0
  102. package/node_modules/@agents-can-communicate/hook-runner/src/runner.mjs +115 -63
  103. package/node_modules/@agents-can-communicate/installer/package.json +1 -1
  104. package/node_modules/@agents-can-communicate/installer/src/apply.mjs +23 -7
  105. package/node_modules/@agents-can-communicate/installer/src/detect.mjs +20 -5
  106. package/node_modules/@agents-can-communicate/installer/src/index.mjs +3 -2
  107. package/node_modules/@agents-can-communicate/installer/src/ownership.mjs +108 -12
  108. package/node_modules/@agents-can-communicate/installer/src/plan.mjs +19 -2
  109. package/node_modules/@agents-can-communicate/mcp-server/package.json +1 -1
  110. package/node_modules/@agents-can-communicate/mcp-server/src/input-validator.mjs +79 -0
  111. package/node_modules/@agents-can-communicate/mcp-server/src/resources.mjs +23 -28
  112. package/node_modules/@agents-can-communicate/mcp-server/src/server.mjs +102 -72
  113. package/node_modules/@agents-can-communicate/mcp-server/src/tools.mjs +54 -97
  114. package/node_modules/@agents-can-communicate/protocol/package.json +1 -1
  115. package/node_modules/@agents-can-communicate/protocol/src/config.mjs +1 -1
  116. package/node_modules/@agents-can-communicate/protocol/src/conversations.mjs +64 -0
  117. package/node_modules/@agents-can-communicate/protocol/src/index.mjs +4 -1
  118. package/node_modules/@agents-can-communicate/protocol/src/schema.mjs +49 -90
  119. package/node_modules/@agents-can-communicate/protocol/src/states.mjs +13 -40
  120. package/node_modules/@agents-can-communicate/storage-filesystem/package.json +1 -1
  121. package/node_modules/@agents-can-communicate/storage-filesystem/src/active-journal.mjs +230 -0
  122. package/node_modules/@agents-can-communicate/storage-filesystem/src/atomic-json.mjs +77 -28
  123. package/node_modules/@agents-can-communicate/storage-filesystem/src/identity.mjs +1 -1
  124. package/node_modules/@agents-can-communicate/storage-filesystem/src/journal.mjs +83 -35
  125. package/node_modules/@agents-can-communicate/storage-filesystem/src/retention.mjs +112 -0
  126. package/node_modules/@agents-can-communicate/storage-filesystem/src/safe-file.mjs +18 -8
  127. package/node_modules/@agents-can-communicate/storage-filesystem/src/store.mjs +68 -26
  128. package/node_modules/@agents-can-communicate/storage-filesystem/src/writer-mutex.mjs +113 -35
  129. package/package.json +19 -1
  130. package/node_modules/@agents-can-communicate/core/src/communication.mjs +0 -334
  131. package/node_modules/@agents-can-communicate/core/src/message-signals.mjs +0 -41
  132. package/node_modules/@agents-can-communicate/core/src/notify.mjs +0 -95
  133. package/node_modules/@agents-can-communicate/core/src/tasks.mjs +0 -244
  134. package/node_modules/@agents-can-communicate/core/src/workstreams.mjs +0 -109
@@ -1,334 +0,0 @@
1
- import { AccError, EXIT, SCHEMA_VERSION, advanceDelivery, createId, validateRecord }
2
- from "@agents-can-communicate/protocol";
3
-
4
- import { ensureMaterialised } from "./materialisation.mjs";
5
- import { assertKnownParticipants } from "./participants.mjs";
6
- import { writeTask } from "./tasks.mjs";
7
-
8
- const receiptId = (messageId, recipient) => `${messageId}--${recipient}`;
9
-
10
- // Peer content is data, never authority. Messages carry attribution and a
11
- // typed intent; nothing in a body can change policy or promote a proposal.
12
- export function createCommunicationService(ports, sessions, claims) {
13
- const { store, clock, ids } = ports;
14
-
15
- async function requireOpenSession(input, action) {
16
- const existing = await sessions.locateSession(input.sessionId, input.workspaceId);
17
- if (existing === null || existing.record.state !== "open"
18
- || existing.record.generation !== input.generation) {
19
- throw new AccError(EXIT.CONFLICT, `cannot ${action} from this session generation`,
20
- { sessionId: input.sessionId });
21
- }
22
- return existing.record;
23
- }
24
-
25
- async function sendMessage(input) {
26
- const session = await requireOpenSession(input, "send a message");
27
- const workspaceId = session.workspaceId;
28
- await ensureMaterialised(ports, { workspaceId, descriptor: input.descriptor,
29
- reason: "durable_object" });
30
- const now = clock.now();
31
- const messageId = createId("message");
32
- const recipients = input.toParticipantIds ?? [];
33
- if (recipients.length === 0) {
34
- throw new AccError(EXIT.USAGE, "a message needs at least one recipient", { messageId });
35
- }
36
- const record = validateRecord("message", {
37
- schemaVersion: SCHEMA_VERSION,
38
- messageId,
39
- workspaceId,
40
- fromSessionId: session.sessionId,
41
- fromParticipantId: session.participantId,
42
- toParticipantIds: recipients,
43
- type: input.type,
44
- subject: input.subject,
45
- body: input.body,
46
- priority: input.priority ?? "normal",
47
- workstreamId: input.workstreamId ?? null,
48
- taskId: input.taskId ?? null,
49
- inReplyTo: input.inReplyTo ?? null,
50
- requiresAck: input.requiresAck === true,
51
- artifacts: input.artifacts ?? [],
52
- sentAt: now,
53
- });
54
- // After the record is validated, so a body carrying control characters is
55
- // refused for what it is rather than for who it was addressed to.
56
- await assertKnownParticipants(store, workspaceId, recipients);
57
-
58
- await store.transaction(async tx => {
59
- tx.put("message", messageId, record);
60
- // One receipt per recipient: a receipt from one recipient can never move
61
- // another recipient's state.
62
- for (const recipient of recipients) {
63
- tx.put("receipt", receiptId(messageId, recipient), validateRecord("receipt", {
64
- schemaVersion: SCHEMA_VERSION,
65
- messageId,
66
- workspaceId,
67
- recipientParticipantId: recipient,
68
- state: "queued",
69
- updatedAt: now,
70
- }));
71
- }
72
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"), workspaceId,
73
- actorSessionId: session.sessionId, type: "message.sent", occurredAt: now,
74
- payload: { messageId, type: record.type, recipients } });
75
- }, { kinds: ["message", "receipt"] });
76
- return record;
77
- }
78
-
79
- async function markDelivery(input) {
80
- const session = await requireOpenSession(input, "update delivery");
81
- // Your own receipt, unless you say otherwise and mean it. A session
82
- // advancing another participant's receipt would be reporting that someone
83
- // else had read something.
84
- const recipient = input.recipientParticipantId ?? session.participantId;
85
- if (recipient !== session.participantId) {
86
- throw new AccError(EXIT.CONFLICT, "a session can only mark its own receipt",
87
- { recipient, participantId: session.participantId });
88
- }
89
- const now = clock.now();
90
- let record = null;
91
- await store.transaction(async tx => {
92
- const id = receiptId(input.messageId, recipient);
93
- const existing = tx.get("receipt", id);
94
- if (existing === null) {
95
- throw new AccError(EXIT.DATA, "no receipt exists for that recipient", { id });
96
- }
97
- // Monotonic by construction: the protocol state machine refuses to move
98
- // backwards, so an acknowledgement can never be downgraded to seen.
99
- record = { ...existing, state: advanceDelivery(existing.state, input.state),
100
- updatedAt: now };
101
- tx.put("receipt", id, record, tx.generationOf("receipt", id));
102
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"),
103
- workspaceId: existing.workspaceId, actorSessionId: session.sessionId,
104
- type: `message.${record.state}`, occurredAt: now,
105
- payload: { messageId: input.messageId,
106
- recipientParticipantId: recipient } });
107
- }, { kinds: ["receipt"] });
108
- return record;
109
- }
110
-
111
- async function recordDecision(input) {
112
- const session = await requireOpenSession(input, "record a decision");
113
- const workspaceId = session.workspaceId;
114
- await ensureMaterialised(ports, { workspaceId, reason: "durable_object" });
115
- // A peer proposal never becomes a human-authority decision on its own.
116
- if (input.authority === "human" && input.humanConfirmed !== true) {
117
- throw new AccError(EXIT.CONFLICT,
118
- "human authority requires an explicit human confirmation", { authority: "human" });
119
- }
120
- const now = clock.now();
121
- const decisionId = createId("decision");
122
- const record = validateRecord("decision", {
123
- schemaVersion: SCHEMA_VERSION,
124
- decisionId,
125
- workspaceId,
126
- workstreamId: input.workstreamId ?? null,
127
- title: input.title,
128
- outcome: input.outcome,
129
- authority: input.authority,
130
- decidedBy: input.decidedBy ?? [session.participantId],
131
- evidence: input.evidence ?? [],
132
- supersedes: input.supersedes ?? null,
133
- decidedAt: now,
134
- });
135
- await store.transaction(async tx => {
136
- if (record.supersedes !== null && tx.get("decision", record.supersedes) === null) {
137
- throw new AccError(EXIT.DATA, "the superseded decision does not exist",
138
- { supersedes: record.supersedes });
139
- }
140
- tx.put("decision", decisionId, record);
141
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"), workspaceId,
142
- actorSessionId: session.sessionId, type: "decision.recorded", occurredAt: now,
143
- payload: { decisionId, authority: record.authority } });
144
- }, { kinds: ["decision"] });
145
- return record;
146
- }
147
-
148
- /**
149
- * Produce a handoff and release what this session owned. The semantic summary
150
- * is written while the model is still active; session end only closes
151
- * lifecycle ownership.
152
- */
153
- /**
154
- * What the successor needs, in the order they need it: what this was for, how
155
- * far it got, what is left, and what is in the way.
156
- */
157
- function describeHandoff(record) {
158
- const section = (label, items) => (items.length === 0
159
- ? [] : [`${label}:`, ...items.map(item => `- ${item}`)]);
160
- return [
161
- // The goal is the subject; repeating it here costs a line of everyone's
162
- // turn to say the same thing twice.
163
- record.status,
164
- ...section("done", record.completed),
165
- // Not "left": the status line above already uses that word for how far
166
- // this got, and the two meanings sat one line apart.
167
- ...section("still to do", record.remaining),
168
- ...section("in the way", record.blockers),
169
- ...section("released", record.claimsToRelease),
170
- ].join("\n");
171
- }
172
-
173
- async function finishSession(input) {
174
- const session = await requireOpenSession(input, "finish");
175
- const workspaceId = session.workspaceId;
176
- await ensureMaterialised(ports, { workspaceId, reason: "durable_object" });
177
- const now = clock.now();
178
- const handoffId = createId("handoff");
179
- const owned = (await store.snapshot(workspaceId, { kinds: ["claim"] })).claims
180
- .filter(claim => claim.ownerSessionId === session.sessionId);
181
- const successor = input.toParticipantId ?? null;
182
- // The same rule as addressing anything else: handing your work to a name
183
- // nobody has is a typo, and the summary is the last thing this session will
184
- // ever say.
185
- if (successor !== null) await assertKnownParticipants(store, workspaceId, [successor]);
186
- const record = validateRecord("handoff", {
187
- schemaVersion: SCHEMA_VERSION,
188
- handoffId,
189
- workspaceId,
190
- fromSessionId: session.sessionId,
191
- toParticipantId: successor,
192
- goal: input.goal,
193
- status: input.status ?? "partial",
194
- completed: input.completed ?? [],
195
- remaining: input.remaining ?? [],
196
- blockers: input.blockers ?? [],
197
- claimsToRelease: owned.map(claim => claim.resource),
198
- verification: input.verification ?? [],
199
- artifacts: input.artifacts ?? [],
200
- createdAt: now,
201
- });
202
-
203
- await store.transaction(async tx => {
204
- tx.put("handoff", handoffId, record);
205
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"), workspaceId,
206
- actorSessionId: session.sessionId, type: "handoff.created", occurredAt: now,
207
- payload: { handoffId, released: record.claimsToRelease } });
208
- }, { kinds: ["handoff"] });
209
-
210
- // A handoff nobody is told about is a note to the store. Written, durable,
211
- // and reaching the agent it names through nothing at all: not their turn,
212
- // not their attention, not `acc status` - only a full snapshot they would
213
- // have to scan for their own name. The message type for this has been in the
214
- // schema all along, and this is the half that was never built.
215
- if (successor !== null) {
216
- await sendMessage({
217
- sessionId: session.sessionId, generation: input.generation,
218
- toParticipantIds: [successor], type: "handoff",
219
- subject: `handing over: ${record.goal}`,
220
- body: describeHandoff(record),
221
- descriptor: input.descriptor,
222
- });
223
- }
224
-
225
- for (const claim of owned) {
226
- await claims.releaseClaim({ claimId: claim.claimId, sessionId: session.sessionId,
227
- generation: session.generation, workspaceId });
228
- }
229
- return record;
230
- }
231
-
232
- /**
233
- * Messages addressed to this participant that nothing has shown a model yet.
234
- *
235
- * `queued` is where `sendMessage` leaves a receipt. Anything further along has
236
- * already been put in front of the recipient, and delivery states only move
237
- * forward - so re-injecting would misreport what happened rather than repeat
238
- * harmlessly.
239
- *
240
- * A session never receives its own message back. Another session of the same
241
- * participant does, because it is a different reader.
242
- */
243
- async function pendingMessages(input = {}) {
244
- const participantId = input.participantId;
245
- if (typeof participantId !== "string" || participantId === "") return [];
246
- const workspaceId = input.workspaceId ?? store.workspaceId;
247
- // Messages and receipts are the two unbounded kinds and this read needs
248
- // both. Nothing else, though, and it runs in front of every turn.
249
- const snapshot = await store.snapshot(workspaceId,
250
- { kinds: ["message", "receipt"] });
251
- const waiting = new Set((snapshot.receipts ?? [])
252
- .filter(receipt => receipt.recipientParticipantId === participantId
253
- && (receipt.state === "queued" || receipt.state === "recorded"))
254
- .map(receipt => receipt.messageId));
255
- return (snapshot.messages ?? [])
256
- .filter(message => waiting.has(message.messageId)
257
- && message.fromSessionId !== input.exceptSessionId)
258
- // Oldest first, and the id breaks ties so two messages sent in the same
259
- // millisecond still project in a stable order.
260
- .sort((left, right) => left.sentAt.localeCompare(right.sentAt)
261
- || left.messageId.localeCompare(right.messageId));
262
- }
263
-
264
- /**
265
- * Ask another agent to do something.
266
- *
267
- * One write, because the two halves are useless apart. A task addressed to
268
- * someone who was never told about it is work nobody knows exists, and a
269
- * message describing work that was never recorded is a request with nothing
270
- * to point at.
271
- *
272
- * The recipient learns about it twice over, and both paths already existed:
273
- * the task raises a `task_unblocked` attention item for the participant it
274
- * names, and the message reaches their turn as quoted peer text.
275
- */
276
- async function requestWork(input) {
277
- const session = await requireOpenSession(input, "request work");
278
- const workspaceId = session.workspaceId;
279
- const recipient = input.toParticipantId;
280
- if (typeof recipient !== "string" || recipient === "") {
281
- throw new AccError(EXIT.USAGE, "a request needs a recipient participant");
282
- }
283
- await ensureMaterialised(ports, { workspaceId, descriptor: input.descriptor,
284
- reason: "durable_object" });
285
- await assertKnownParticipants(store, workspaceId, [recipient]);
286
- const now = clock.now();
287
- const messageId = createId("message");
288
- let task = null;
289
- let message = null;
290
-
291
- await store.transaction(async tx => {
292
- task = writeTask(tx, { session, workspaceId, now, ids,
293
- input: { ...input, assigneeParticipantId: recipient,
294
- requestedByParticipantId: session.participantId } });
295
- message = validateRecord("message", {
296
- schemaVersion: SCHEMA_VERSION,
297
- messageId,
298
- workspaceId,
299
- fromSessionId: session.sessionId,
300
- fromParticipantId: session.participantId,
301
- toParticipantIds: [recipient],
302
- type: "work_request",
303
- subject: input.title,
304
- body: input.detail ?? input.title,
305
- priority: input.priority ?? "normal",
306
- workstreamId: task.workstreamId,
307
- taskId: task.taskId,
308
- inReplyTo: input.inReplyTo ?? null,
309
- // A request is a question, so the sender is entitled to know whether it
310
- // was taken up. Silence and refusal are different answers.
311
- requiresAck: true,
312
- artifacts: input.artifacts ?? [],
313
- sentAt: now,
314
- });
315
- tx.put("message", messageId, message);
316
- tx.put("receipt", receiptId(messageId, recipient), validateRecord("receipt", {
317
- schemaVersion: SCHEMA_VERSION,
318
- messageId,
319
- workspaceId,
320
- recipientParticipantId: recipient,
321
- state: "queued",
322
- updatedAt: now,
323
- }));
324
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"), workspaceId,
325
- actorSessionId: session.sessionId, type: "work.requested", occurredAt: now,
326
- payload: { taskId: task.taskId, messageId, recipient } });
327
- // `writeTask` runs on this handle, so what it reads is read here.
328
- }, { kinds: ["message", "receipt", "session", "task", "workstream"] });
329
- return { task, message };
330
- }
331
-
332
- return { sendMessage, markDelivery, pendingMessages, requestWork, recordDecision,
333
- finishSession };
334
- }
@@ -1,41 +0,0 @@
1
- // A note is fire-and-forget: shown to the recipient once, no acknowledgement
2
- // owed, no standing reminder. Agents put decisions and warnings in notes anyway
3
- // - in one measured session a note carrying a merge decision was lost for three
4
- // hours - so this is the send-time tell that a note is waiting on a reply and
5
- // should have gone out as a question (`--requires-ack`) or a decision.
6
- //
7
- // A nudge, never a block, and deliberately not a keyword list: keyword lists
8
- // only fire in the language they were written in, and the agents here write in
9
- // several. A question mark marks a question in every script, and the warning
10
- // sign is the one glyph a peer reaches for when something must not be missed.
11
- const QUESTION = /[??]/u;
12
- const WARNING = /⚠/u;
13
-
14
- /**
15
- * Does this note read like it needs a response from the recipient?
16
- *
17
- * Pure and total: a missing subject or body is empty text, not an error, so the
18
- * caller can hand it a message record without pre-checking its shape.
19
- */
20
- export function looksConsequential({ subject = "", body = "" } = {}) {
21
- const text = `${subject}\n${body}`;
22
- return QUESTION.test(text) || WARNING.test(text);
23
- }
24
-
25
- const NUDGE = "this note reads like it needs a reply, but a note is fire-and-forget: "
26
- + "the recipient sees it once and owes no response. Re-send with --requires-ack "
27
- + "for an answer, or record it with `acc decide`.";
28
-
29
- /**
30
- * The send-time advisory for a note that looks like it is waiting on a reply,
31
- * or null when there is nothing to say.
32
- *
33
- * Only notes, and only ones the sender did not already mark `requiresAck`: a
34
- * question already keeps a standing reminder, and nudging it would be noise.
35
- * A nudge, never a block - the send has already happened; this only tells the
36
- * sender the shape it chose does not carry the weight the words do.
37
- */
38
- export function noteNudge(message) {
39
- return message?.type === "note" && message?.requiresAck !== true
40
- && looksConsequential(message ?? {}) ? NUDGE : null;
41
- }
@@ -1,95 +0,0 @@
1
- import { SCHEMA_VERSION, advanceDelivery, createId, validateRecord }
2
- from "@agents-can-communicate/protocol";
3
-
4
- const receiptId = (messageId, recipient) => `${messageId}--${recipient}`;
5
-
6
- /**
7
- * Tell whoever asked for a task what became of it.
8
- *
9
- * A request is a question, so it deserves an answer: taken up, declined, or
10
- * finished. Before this the task recorded who it was for and not who was
11
- * waiting, so nothing could be said back and the asker had to poll and diff
12
- * task states to find out.
13
- *
14
- * It is a message rather than an attention rule on purpose. Messages carry
15
- * delivery state, so the answer is put in front of the asker exactly once
16
- * instead of repeating in every turn until they act on it.
17
- *
18
- * Written into the caller's transaction: an accepted task whose acceptance was
19
- * never sent is the same silence this exists to remove.
20
- */
21
- export function writeWorkResponse(tx, { task, actor, workspaceId, now, ids, outcome,
22
- reason = null }) {
23
- const asker = task.requestedByParticipantId;
24
- // Nobody asked, or the asker is doing it themselves - there is no one to tell.
25
- if (asker === null || asker === undefined || asker === actor.participantId) return null;
26
-
27
- const messageId = createId("message");
28
- // The subject already carries the outcome and the title. The body says who
29
- // and which task, so the asker can follow it up without going and looking.
30
- const head = `${outcome} by ${actor.participantId} (task ${task.taskId})`;
31
- const body = reason === null ? head : `${head}\n\n${reason}`;
32
- const record = validateRecord("message", {
33
- schemaVersion: SCHEMA_VERSION,
34
- messageId,
35
- workspaceId,
36
- fromSessionId: actor.sessionId,
37
- fromParticipantId: actor.participantId,
38
- toParticipantIds: [asker],
39
- type: "work_response",
40
- subject: `${outcome}: ${task.title}`,
41
- body,
42
- priority: "normal",
43
- workstreamId: task.workstreamId,
44
- taskId: task.taskId,
45
- inReplyTo: null,
46
- // The asker is being told, not asked. Requiring an acknowledgement here
47
- // would leave every finished request sitting in someone's attention list.
48
- requiresAck: false,
49
- artifacts: [],
50
- sentAt: now,
51
- });
52
- tx.put("message", messageId, record);
53
- tx.put("receipt", receiptId(messageId, asker), validateRecord("receipt", {
54
- schemaVersion: SCHEMA_VERSION,
55
- messageId,
56
- workspaceId,
57
- recipientParticipantId: asker,
58
- state: "queued",
59
- updatedAt: now,
60
- }));
61
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"), workspaceId,
62
- actorSessionId: actor.sessionId, type: `work.${outcome}`, occurredAt: now,
63
- payload: { taskId: task.taskId, messageId, asker } });
64
- return record;
65
- }
66
-
67
- /**
68
- * Close the request a task came from, once it has been answered.
69
- *
70
- * `acc request` marks its message as needing an acknowledgement, which raises a
71
- * `direct_request` attention item for the recipient. Finishing the work did not
72
- * clear it, and nothing else could: the operation existed in the core and was
73
- * reachable from no surface. So every completed request left a line repeating in
74
- * the doer's turn for good.
75
- *
76
- * Doing the work is the acknowledgement. An explicit `acc ack` exists for
77
- * messages that are not tied to a task.
78
- */
79
- export function closeRequestReceipt(tx, { task, actor, now, ids }) {
80
- for (const message of tx.list("message")) {
81
- if (message.taskId !== task.taskId || message.type !== "work_request") continue;
82
- if (!message.toParticipantIds.includes(actor.participantId)) continue;
83
- const id = `${message.messageId}--${actor.participantId}`;
84
- const existing = tx.get("receipt", id);
85
- if (existing === null || existing.state === "acknowledged") continue;
86
- const record = { ...existing, state: advanceDelivery(existing.state, "acknowledged"),
87
- updatedAt: now };
88
- tx.put("receipt", id, record, tx.generationOf("receipt", id));
89
- tx.append({ schemaVersion: SCHEMA_VERSION, eventId: ids.next("event"),
90
- workspaceId: existing.workspaceId, actorSessionId: actor.sessionId,
91
- type: "message.acknowledged", occurredAt: now,
92
- payload: { messageId: message.messageId,
93
- recipientParticipantId: actor.participantId } });
94
- }
95
- }