1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# basemind UserPromptSubmit hook: surface NEW agent-comms messages to the model.
#
# Reads this agent's inbox (front-matter ONLY — never message bodies) from the broker daemon
# and injects any messages newer than the last turn as additionalContext. A per-session
# high-water timestamp (keyed by the host's session_id) makes it idempotent: each message is
# injected once, and the first turn only baselines (SessionStart already showed recent history).
#
# Hard rule: this must NEVER block or fail the user's turn. Every step is time-boxed and
# fail-open — any error (no daemon, no jq, no messages) exits 0 with no output.
SCRIPT_DIR=""
PLUGIN_ROOT=""
# jq is required to parse the inbox JSON; without it, stay silent.
||
STDIN_JSON=""
SID=""
[ || SID="default"
HWM_FILE="/basemind-comms-hwm-"
# Pull recent inbox front-matter (across auto-joined rooms). mark_read stays false so the hook
# never consumes the agent's own inbox state — its own cursor is the hwm file below.
INBOX_JSON="" ||
[ ||
MAXTS=""
[ || MAXTS=0
# First turn this session: baseline the high-water mark, do not replay history.
if [; then
||
fi
HWM=""
[ || HWM=0
NEW_LINES=""
[ ||
# Advance the high-water mark so these messages are not re-injected next turn.
||
CONTEXT="New basemind agent-comms message(s) since your last turn (front-matter only — call message_get with an id to read a body):
Reply with room_post {room, subject, body, reply_to:<id>} if a response is warranted."
# Escape for JSON embedding (single-pass parameter substitutions; mirrors session-start).
CTX=""
# Emit the field the current harness consumes (same tri-format branch as session-start).
if [; then
elif [ && [; then
else
fi