feat(moments): mount the corpus by proposal - a pass and an open-after-moment signal, both stopping at the operator (milestone 458 step 7, #4925)
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 19s
CI & Build / integration (push) Failing after 43s
CI & Build / Python tests (push) Failing after 46s
CI & Build / TypeScript typecheck (push) Successful in 55s
CI & Build / Build & push image (push) Skipped

A rule written before moments existed is mounted on nothing. Step 7 records,
per (rule, moment), whether it belongs there and who said so:

- rule_moment_judgments (migration 0118, backup v23): suggested / confirmed /
  rejected, from a pass, the signal, or an edit. Moment "" is "no moment fits".
- The pass: rules_to_mount lists unjudged rules; propose_rule_moments records
  suggestions that mount nothing; rule_moment_proposals and
  judge_rule_moments put them to the operator. A confirm mounts, a reject is
  kept so the pair is never proposed again. Same service behind REST and a
  "Waiting on you" panel in Settings > Moments.
- Edits are judgments: set_rule_moments, the one mount write path, confirms
  what was added and rejects what was removed in the same transaction.
- The signal: scribe_moment.sh keeps a per-session acts ledger; when a rule
  is opened, scribe_record_opened.sh sends the last three minutes of it to
  /api/plugin/rule-opened. The acts resolve through the install's mappings;
  work.run and work.change are not evidence. Counted per distinct session
  with lesson_rules' evidence model, and once due the open returns one line
  asking the reader to offer the mount.
- scribe_session_end.sh removes the session's scribe-moment files.

Plugin 2026.10.05.2003.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-05 16:03:53 -04:00
co-authored by Claude Opus 5.5
parent 5bcc603310
commit dfcf4df2e9
24 changed files with 1619 additions and 31 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "scribe",
"description": "Scribe for Claude Code: connects the scribe MCP server, adds the hooks that deliver live project state and relevant records at the right moment, ships the shared client-neutral Scribe skills (using-scribe, writing-plans, reporting-back, systematic-debugging, verification, brainstorming, reusing-code, shape-accounting), and syncs your saved Scribe Processes as skills (/scribe:sync).",
"version": "2026.10.05.1823",
"version": "2026.10.05.2003",
"author": {
"name": "Bryan Van Deusen"
},
+41 -13
View File
@@ -16,10 +16,10 @@
# other tool costs one file read. An install that has mounted nothing gets an
# empty list and never sends a moment request at all.
#
# SCRIBE'S OWN TOOLS ARE SKIPPED. Closing a task or recording a lesson reaches
# its moment through the tool's own response (`moment_rules`), which works for
# a client without this plugin too; delivering it here as well would say it
# twice.
# SCRIBE'S OWN TOOLS ARE SKIPPED for delivery. Closing a task or recording a
# lesson reaches its moment through the tool's own response (`moment_rules`),
# which works for a client without this plugin too; delivering it here as well
# would say it twice. They are still written to the acts ledger below.
#
# SILENT ON OUTAGE, like scribe_tool_rules.sh and for its reason: this fires
# before many calls, and an outage line before each is noise. A failed list
@@ -42,10 +42,6 @@ event_cwd=$(scribe_json_pick "$event_flat" '.cwd')
[ -n "$tool_name" ] && [ -n "$session_id" ] || exit 0
case "$tool_name" in
mcp__*scribe*__*) exit 0 ;;
esac
scribe_config || exit 0
# The tool's KEY, as the server writes mappings: no MCP server prefix, lowercase.
@@ -56,16 +52,48 @@ state_dir="${TMPDIR:-/tmp}/scribe-priorart"
mkdir -p "$state_dir" 2>/dev/null || true
safe_sid=$(printf '%s' "$session_id" | tr -c 'A-Za-z0-9._-' '_')
# Its own directory, outside SCRIBE_LEDGER_DIRS, so a compaction does not
# sweep it: what is kept here describes the install and what the session
# DID, not what its context holds. scribe_session_end.sh removes it.
cache_dir="${TMPDIR:-/tmp}/scribe-moment"
mkdir -p "$cache_dir" 2>/dev/null || true
now=$(date +%s 2>/dev/null) || now=0
# ── The acts ledger (milestone 458 step 7) ────────────────────────────────
#
# Every call, before any filter: `epoch<TAB>event`, one line each. When the
# session then opens a rule, scribe_record_opened.sh sends the last few
# minutes of these, and the server counts the open as evidence the rule
# belongs on the moments they reached — which is how a rule nobody mounted
# gets proposed for one. Recorded whether or not anything is mounted, since
# an unmounted moment is exactly what the evidence is for, and including
# Scribe's own tools (closing a task is a moment too). The open itself is
# not an act. A large event (a file write) is kept as its tool name alone.
if [ "$now" -gt 0 ] && [ "$tool_key" != "get_rule" ]; then
acts_file="$cache_dir/${safe_sid}.acts"
act=$(printf '%s' "$event" | tr -d '\n\r')
if [ "${#act}" -gt 16384 ]; then
esc=$(printf '%s' "$tool_name" | scribe_json_escape) || esc=""
act="{\"tool_name\":\"${esc}\",\"tool_input\":{}}"
fi
printf '%s\t%s\n' "$now" "$act" >> "$acts_file" 2>/dev/null || true
# Kept short: only the last few minutes are ever read.
size=$(wc -c < "$acts_file" 2>/dev/null) || size=0
if [ "${size:-0}" -gt 262144 ]; then
tail -n 50 "$acts_file" > "$acts_file.tmp" 2>/dev/null \
&& mv -f "$acts_file.tmp" "$acts_file" 2>/dev/null
fi
fi
case "$tool_name" in
mcp__*scribe*__*) exit 0 ;;
esac
# ── Which tools can reach a mounted rule: cached, first line a timestamp ──
#
# Five minutes. A mount or a mapping made in this session reaches the hook
# within that window; the MCP door delivers Scribe's own moments at once.
# Its own directory, outside SCRIBE_LEDGER_DIRS, so a compaction does not
# sweep it: it describes the install, not what this context holds.
cache_dir="${TMPDIR:-/tmp}/scribe-moment"
mkdir -p "$cache_dir" 2>/dev/null || true
tools_file="$cache_dir/${safe_sid}.tools"
now=$(date +%s 2>/dev/null) || now=0
stamp=""
[ -f "$tools_file" ] && stamp=$(head -n 1 "$tools_file" 2>/dev/null)
case "$stamp" in ''|*[!0-9]*) stamp=0 ;; esac
+35
View File
@@ -33,6 +33,10 @@
# claim it supports is only ever "you opened this, pull it again if you no
# longer hold it", which stays true in every case and carries its own remedy.
#
# SINCE MILESTONE 458 STEP 7 it also reports the open, with the calls that
# came just before it, so the server can learn which moments a rule belongs
# on (below). Silent on outage, like every arm that fires per call.
#
# EXIT 0, ALWAYS. This decorates a ledger; a bookkeeping failure must never
# turn a successful tool call into a hook error. Worst case the id is missed
# and the reader is offered a rule it already read — the cost of a wrong guess
@@ -68,4 +72,35 @@ safe_sid=$(printf '%s' "$session_id" | tr -c 'A-Za-z0-9._-' '_')
# Stamped and append-only, exactly like the naming ledger — so the same reader
# (`scribe_rules_live`) ages both, and the last entry for an id wins.
printf '%s\n' "$rule_id" | scribe_rules_append "$state_dir/${safe_sid}.opened.ids"
# ── What came just before the open (milestone 458 step 7) ─────────────────
#
# scribe_moment.sh writes every call to `scribe-moment/<sid>.acts`. The ones
# from the last three minutes go to the server with this rule's id: a rule
# opened just after a moment fired is evidence it belongs on that moment, and
# once that repeats across sessions the server answers with one line asking
# the reader to offer the operator the mount. Nothing is mounted by this.
command -v curl >/dev/null 2>&1 || exit 0
scribe_config || exit 0
acts_file="${TMPDIR:-/tmp}/scribe-moment/${safe_sid}.acts"
[ -f "$acts_file" ] || exit 0
now=$(date +%s 2>/dev/null) || exit 0
acts=$(awk -F '\t' -v since=$((now - 180)) \
'$1 + 0 >= since { sub(/^[^\t]*\t/, ""); print }' "$acts_file" 2>/dev/null \
| tail -n 30 | paste -sd ',' - 2>/dev/null)
[ -n "$acts" ] || exit 0
sid_esc=$(printf '%s' "$session_id" | scribe_json_escape) || exit 0
event_cwd=$(scribe_json_pick "$event_flat" '.cwd')
scope=$(scribe_scope_query "${event_cwd:-${CLAUDE_PROJECT_DIR:-$PWD}}")
body=$(printf '{"rule_id":%s,"session_id":"%s","acts":[%s]}' "$rule_id" "$sid_esc" "$acts" \
| curl -fsS --max-time 3 \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json" \
--data-binary @- \
"${url%/}/api/plugin/rule-opened${scope:+?$scope}" 2>/dev/null) || exit 0
context=$(scribe_json_pick "$(printf '%s' "$body" | scribe_json_flat)" '.context')
[ -n "$context" ] || exit 0
scribe_json_out PostToolUse "$context"
exit 0
+11 -5
View File
@@ -24,18 +24,24 @@ set -uo pipefail
# shellcheck source=plugin/hooks/scribe_defs.sh
. "$(dirname "${BASH_SOURCE[0]}")/scribe_defs.sh"
command -v curl >/dev/null 2>&1 || exit 0
scribe_config || exit 0
event=$(cat 2>/dev/null || true)
[ -n "$event" ] || exit 0
event_flat=$(printf '%s' "$event" | scribe_json_flat)
session_id=$(scribe_json_pick "$event_flat" '.session_id')
[ -n "$session_id" ] || exit 0
# The moment arm's per-session files (its tool cache and the acts ledger,
# milestone 458) describe a session that is over, on any exit — a clear
# included, since the next conversation is a new session id.
safe_sid=$(printf '%s' "$session_id" | tr -c 'A-Za-z0-9._-' '_')
rm -f "${TMPDIR:-/tmp}/scribe-moment/${safe_sid}".* 2>/dev/null || true
reason=$(scribe_json_pick "$event_flat" '.reason')
[ "$reason" = "clear" ] && exit 0
session_id=$(scribe_json_pick "$event_flat" '.session_id')
[ -n "$session_id" ] || exit 0
command -v curl >/dev/null 2>&1 || exit 0
scribe_config || exit 0
sid_enc=$(printf '%s' "$session_id" | scribe_urlenc) || exit 0
curl -fsS --max-time 4 \