@cohortapp/agent-sdk 2.18.29 → 2.18.30

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cohortapp/agent-sdk",
3
- "version": "2.18.29",
3
+ "version": "2.18.30",
4
4
  "description": "Cohort Agent SDK — autonomous AI colleague runtime. Deploy senior AI colleagues on dedicated Mac minis, wired to the Cohort operating surface.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -54,7 +54,7 @@
54
54
  import { appendFileSync, mkdirSync, readdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "fs";
55
55
  import { spawn } from "child_process";
56
56
  import { join } from "path";
57
- import { deliver, deliverWithRetry, replyTargetOf, canDeliverTo, canReactTo, deliverReaction } from "./deliver.mjs";
57
+ import { deliver, deliverWithRetry, replyTargetOf, canDeliverTo, canReactTo, deliverReaction, cohortReplyRoute } from "./deliver.mjs";
58
58
  import { spokeFor, spokeSince, noSendFor, NON_ANSWER_KINDS } from "../../lib/comms/receipts.mjs";
59
59
  import { resultTextFromStdout } from "./session-outcomes.mjs";
60
60
  // The ack generator funnels through `claude --print` like every other daemon
@@ -1388,6 +1388,56 @@ export function composeRefusedSend(rec, o = {}) {
1388
1388
  * @param {object} rec the obligation record; its `item.direct_reason` is read
1389
1389
  * @returns {boolean}
1390
1390
  */
1391
+ /**
1392
+ * Is this obligation's reply surface a DOCUMENT rather than a conversation?
1393
+ *
1394
+ * A doc or file comment is not a request for work. Nobody asked the seat for
1395
+ * anything by commenting on a document it can see, so there is no one waiting
1396
+ * for a notice about work that did not finish — and posting one is actively
1397
+ * harmful, because a comment fans out as an inbound to every seat the document
1398
+ * is shared with.
1399
+ *
1400
+ * MEASURED, 2026-10-01 on one shared alerting doc: 11 of its 14 comments were
1401
+ * assurance notices, alternating between two seats every ~10 minutes from
1402
+ * 02:53Z to 04:57Z, burying the three substantive comments a colleague had
1403
+ * written. The mechanism is a closed loop: seat A's notice lands as a comment,
1404
+ * the comment arrives as an inbound at seat B, B's session fails on it, B posts
1405
+ * its own notice, which arrives as an inbound at A. A human recipient of the
1406
+ * document saw every one.
1407
+ *
1408
+ * WHY THIS IS A SURFACE TEST AND NOT A REASON TEST. `isAmbientSurface` already
1409
+ * withholds the silent-success narration on a membership-proved surface, and a
1410
+ * shared document is exactly that — but only until the first notice. The
1411
+ * directedness reasons include `commenter` ("I SPOKE there"), which is NOT a
1412
+ * membership reason, so a seat that posts one notice becomes a commenter and the
1413
+ * surface flips to identity-shaped for every notice after it. The notice
1414
+ * manufactures its own audience, which is why the loop sustains for hours
1415
+ * instead of stopping. A test on the SURFACE cannot be flipped by anything the
1416
+ * seat itself does.
1417
+ *
1418
+ * Scoped to documents on purpose. `task_comment` and `decision` are NOT included:
1419
+ * a board comment can carry an assignment and a decision thread can carry a
1420
+ * request, so a person there may genuinely be waiting. Those keep the existing
1421
+ * reason-based treatment.
1422
+ *
1423
+ * @param {object} rec the obligation record
1424
+ * @returns {boolean}
1425
+ */
1426
+ const DOCUMENT_SURFACES = Object.freeze(["doc_comment", "file_comment"]);
1427
+ function isDocumentSurface(rec) {
1428
+ const item = rec && rec.item;
1429
+ if (!item) return false;
1430
+ try {
1431
+ const route = cohortReplyRoute(item);
1432
+ return DOCUMENT_SURFACES.includes(String(route && route.surface));
1433
+ } catch {
1434
+ // Unresolvable route → fall back to the reason-based treatment rather than
1435
+ // inventing silence. Failing open here costs a notice; failing closed could
1436
+ // swallow one a person is waiting on.
1437
+ return false;
1438
+ }
1439
+ }
1440
+
1391
1441
  function isAmbientSurface(rec) {
1392
1442
  const reason = String((rec && rec.item && rec.item.direct_reason) || "");
1393
1443
  if (!reason) return false; // unknown provenance → treat as a DM, narrate
@@ -2101,7 +2151,10 @@ export async function settleSession(a = {}) {
2101
2151
  // close silently to avoid. The debt is still discharged (silent is not
2102
2152
  // un-closed); only the narration is withheld. `direct_reason` reaches here
2103
2153
  // through `itemSnapshot`, and the guard fails open to narrating.
2104
- if (isAmbientSurface(rec)) {
2154
+ // `isDocumentSurface` as well as the reason test: a document stops being
2155
+ // membership-proved the moment this seat comments on it (reason `commenter`),
2156
+ // so the reason alone cannot hold the line across more than one notice.
2157
+ if (isAmbientSurface(rec) || isDocumentSurface(rec)) {
2105
2158
  closeObligation(a.key, {
2106
2159
  outcome: "answered",
2107
2160
  now,
@@ -2167,6 +2220,20 @@ export async function settleSession(a = {}) {
2167
2220
  rec.lastFailureAt = now;
2168
2221
  writeRecord(rec);
2169
2222
 
2223
+ // A DOCUMENT IS NOT A REQUEST FOR WORK, SO IT GETS NO FAILURE NOTICE.
2224
+ //
2225
+ // The silent-success branch above already withholds narration on an ambient
2226
+ // surface; this branch never asked the same question, and that asymmetry is
2227
+ // what produced the measured loop (see isDocumentSurface). The debt is closed
2228
+ // and escalated exactly as an undeliverable one is, so an operator still has
2229
+ // the trace — what is withheld is only the comment.
2230
+ if (isDocumentSurface(rec)) {
2231
+ escalate(rec, { failure, now, told: false });
2232
+ closeObligation(a.key, { outcome: "failed", now, note: `${failure.label}; document surface, notice withheld` });
2233
+ counters.bump("assurance.failure_notice_withheld_document", { service: rec.service });
2234
+ return { spoke: false, text: null, verdict: `failed:${failure.label}`, willRetry: false };
2235
+ }
2236
+
2170
2237
  // GENERATED, not stamped. `generateFailureNotice` always returns text — the
2171
2238
  // degraded path is a plainer sentence, never silence — so the guarantee the
2172
2239
  // deterministic composer bought is intact while the words are this ask's own.