@cohortapp/agent-sdk 2.18.24 → 2.18.27
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/bin/maestro.mjs +39 -4
- package/lib/assurance/first-reply.mjs +84 -0
- package/lib/comms/receipts.mjs +184 -3
- package/lib/comms/send-gate.mjs +91 -2
- package/lib/org/tool-surface.mjs +72 -14
- package/package.json +1 -1
- package/scripts/daemon/assurance.mjs +177 -6
- package/scripts/daemon/deliver.mjs +101 -6
- package/scripts/daemon/prompt-builder.mjs +14 -1
- package/scripts/hooks/block-mcp-cohort-send.sh +14 -5
- package/scripts/org/send-cohort-message.mjs +190 -0
- package/scripts/record-no-send.sh +132 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# record-no-send.sh — witness a reply that did NOT go out, and say which kind of
|
|
3
|
+
# not-going-out it was.
|
|
4
|
+
#
|
|
5
|
+
# WHY THIS EXISTS
|
|
6
|
+
#
|
|
7
|
+
# `record-receipt.sh` is the positive half: it proves a session spoke. Its
|
|
8
|
+
# absence was being read as one thing — "the session finished and its reply
|
|
9
|
+
# never sent" — and on 2026-09-30 that reading put 188 recovery notices into the
|
|
10
|
+
# org in a day. Of the 46 seed notices that day, 32 carried the session's own
|
|
11
|
+
# words saying it had DECIDED, correctly, that no reply was owed ("Logged and
|
|
12
|
+
# archived — no response needed." "I marked it processed and sent no reply,
|
|
13
|
+
# since it closes the thread."). The other 14 carried a real composed answer
|
|
14
|
+
# that never got out, and four notices in the window named their own blocked
|
|
15
|
+
# send lane in prose because they had no other way to report it.
|
|
16
|
+
#
|
|
17
|
+
# Silence has two causes and they need opposite treatment:
|
|
18
|
+
#
|
|
19
|
+
# declined — nothing tried to send, because nothing was owed. Close quietly.
|
|
20
|
+
# Say nothing. This is the design working.
|
|
21
|
+
# refused — something tried and was stopped: the outbound gate, a transport
|
|
22
|
+
# error, an ACL, a pre-tool hook with no fallback lane. The work is
|
|
23
|
+
# done and the human has nothing. This is a fault, it should be
|
|
24
|
+
# NAMED, and where the cause is transient it should be retried.
|
|
25
|
+
#
|
|
26
|
+
# Nothing downstream can tell those apart from an absence, so whoever makes the
|
|
27
|
+
# decision records it, at the moment it is made.
|
|
28
|
+
#
|
|
29
|
+
# ── EXIT CODES, AND WHY THIS SCRIPT IS NOT "ALWAYS 0" ────────────────────────
|
|
30
|
+
#
|
|
31
|
+
# The first cut exited 0 on every path including a misspelt decision, a missing
|
|
32
|
+
# node and a missing receipts module, writing nothing and printing nothing. A
|
|
33
|
+
# session following the documented invocation exactly could believe it had
|
|
34
|
+
# recorded a reason that no reader would ever find — which is the same class of
|
|
35
|
+
# defect as the one this script exists to fix, one layer down.
|
|
36
|
+
#
|
|
37
|
+
# `record-receipt.sh` is right to swallow everything: it runs AFTER a successful
|
|
38
|
+
# send and a non-zero there could be read as a failed send. Here the send has
|
|
39
|
+
# already not happened, so there is nothing left to break and a loud failure is
|
|
40
|
+
# strictly better than a quiet one.
|
|
41
|
+
#
|
|
42
|
+
# 0 the row was written, and a reader can attribute it
|
|
43
|
+
# 3 the row was written but NOTHING DOWNSTREAM CAN READ IT — no obligation
|
|
44
|
+
# attribution was available (see below). Fix the caller, not this script.
|
|
45
|
+
# 4 the recorder could not run at all (no node, no receipts module, node
|
|
46
|
+
# exited non-zero). Environment, not your invocation.
|
|
47
|
+
# 64 your invocation was wrong (EX_USAGE). Nothing was written.
|
|
48
|
+
#
|
|
49
|
+
# ── ATTRIBUTION ─────────────────────────────────────────────────────────────
|
|
50
|
+
#
|
|
51
|
+
# A row is found by `noSendFor` only if it carries this obligation's key or this
|
|
52
|
+
# obligation's session id; a row with neither is invisible to every reader, by
|
|
53
|
+
# design (borrowing another debt's row would silence a real fault). The values
|
|
54
|
+
# ride in on the env the dispatcher stamps on the child —
|
|
55
|
+
# MAESTRO_OBLIGATION_KEY / MAESTRO_SESSION_ID — exactly as they do for a
|
|
56
|
+
# receipt, and are passed explicitly below so that the case where they are
|
|
57
|
+
# ABSENT is visible instead of silently producing a dead row.
|
|
58
|
+
#
|
|
59
|
+
# Usage: record-no-send.sh <declined|refused> <service> <channel> [reason] [code]
|
|
60
|
+
set +e
|
|
61
|
+
|
|
62
|
+
say() { printf 'record-no-send: %s\n' "$1" >&2; }
|
|
63
|
+
|
|
64
|
+
usage() {
|
|
65
|
+
say "$1"
|
|
66
|
+
say "usage: record-no-send.sh <declined|refused> <service> <channel> [reason] [code]"
|
|
67
|
+
exit 64
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
DECISION="$1"
|
|
71
|
+
SERVICE="$2"
|
|
72
|
+
CHANNEL="$3"
|
|
73
|
+
REASON="${4:-}"
|
|
74
|
+
CODE="${5:-}"
|
|
75
|
+
|
|
76
|
+
case "$DECISION" in
|
|
77
|
+
declined|refused) ;;
|
|
78
|
+
"") usage "no decision given — nothing was recorded" ;;
|
|
79
|
+
*) usage "unknown decision '$DECISION' — it must be exactly 'declined' or 'refused'; nothing was recorded" ;;
|
|
80
|
+
esac
|
|
81
|
+
[ -n "$SERVICE" ] || usage "no service given (cohort, gmail, slack, …) — nothing was recorded"
|
|
82
|
+
[ -n "$CHANNEL" ] || usage "no channel given — nothing was recorded"
|
|
83
|
+
|
|
84
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
85
|
+
|
|
86
|
+
# Two different roots, deliberately kept apart — see record-receipt.sh for why
|
|
87
|
+
# collapsing them silently writes nothing whenever an agent's root is not also a
|
|
88
|
+
# maestro checkout.
|
|
89
|
+
CODE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
90
|
+
AGENT_REPO_DIR="${AGENT_DIR:-$CODE_DIR}"
|
|
91
|
+
|
|
92
|
+
RECEIPTS=""
|
|
93
|
+
for CAND in \
|
|
94
|
+
"$CODE_DIR/lib/comms/receipts.mjs" \
|
|
95
|
+
"$AGENT_REPO_DIR/lib/comms/receipts.mjs" \
|
|
96
|
+
"$AGENT_REPO_DIR/node_modules/@cohortapp/agent-sdk/lib/comms/receipts.mjs"
|
|
97
|
+
do
|
|
98
|
+
if [ -f "$CAND" ]; then RECEIPTS="$CAND"; break; fi
|
|
99
|
+
done
|
|
100
|
+
if [ -z "$RECEIPTS" ]; then
|
|
101
|
+
say "cannot find lib/comms/receipts.mjs under $CODE_DIR or $AGENT_REPO_DIR — nothing was recorded"
|
|
102
|
+
exit 4
|
|
103
|
+
fi
|
|
104
|
+
|
|
105
|
+
NODE_BIN="${MAESTRO_NODE_BIN:-/opt/homebrew/bin/node}"
|
|
106
|
+
command -v "$NODE_BIN" >/dev/null 2>&1 || NODE_BIN="node"
|
|
107
|
+
if ! command -v "$NODE_BIN" >/dev/null 2>&1; then
|
|
108
|
+
say "no usable node on PATH (tried ${MAESTRO_NODE_BIN:-/opt/homebrew/bin/node} and node) — nothing was recorded"
|
|
109
|
+
exit 4
|
|
110
|
+
fi
|
|
111
|
+
|
|
112
|
+
OBLIGATION_KEY="${MAESTRO_OBLIGATION_KEY:-}"
|
|
113
|
+
SESSION_ID="${MAESTRO_SESSION_ID:-${AGENT_SESSION_ID:-}}"
|
|
114
|
+
|
|
115
|
+
AGENT_DIR="$AGENT_REPO_DIR" "$NODE_BIN" "$RECEIPTS" no-send \
|
|
116
|
+
--decision "$DECISION" --service "$SERVICE" --channel "$CHANNEL" \
|
|
117
|
+
${REASON:+--reason "$REASON"} ${CODE:+--code "$CODE"} \
|
|
118
|
+
${OBLIGATION_KEY:+--obligation-key "$OBLIGATION_KEY"} \
|
|
119
|
+
${SESSION_ID:+--session-id "$SESSION_ID"} \
|
|
120
|
+
--surface session --agent-root "$AGENT_REPO_DIR" >/dev/null 2>&1
|
|
121
|
+
RC=$?
|
|
122
|
+
if [ "$RC" -ne 0 ]; then
|
|
123
|
+
say "the recorder exited $RC — nothing was recorded"
|
|
124
|
+
exit 4
|
|
125
|
+
fi
|
|
126
|
+
|
|
127
|
+
if [ -z "$OBLIGATION_KEY" ] && [ -z "$SESSION_ID" ]; then
|
|
128
|
+
say "recorded, but with NO OBLIGATION ATTRIBUTION: neither MAESTRO_OBLIGATION_KEY nor MAESTRO_SESSION_ID is set in this environment, so no reader can match this row to the ask it belongs to. If you are in a dispatched session this is a bug worth reporting; if you started this session by hand, export MAESTRO_OBLIGATION_KEY and run it again."
|
|
129
|
+
exit 3
|
|
130
|
+
fi
|
|
131
|
+
|
|
132
|
+
exit 0
|