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
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:
@@ -17,6 +17,7 @@ from scribe.services import moment_delivery as moment_delivery_svc
|
||||
from scribe.services import plugin_context as plugin_ctx_svc
|
||||
from scribe.services import repo_bindings as repo_bindings_svc
|
||||
from scribe.services import report_check as report_check_svc
|
||||
from scribe.services import rule_moment_judgments as judgments_svc
|
||||
from scribe.services import shape_check as shape_check_svc
|
||||
from scribe.services import task_claims as task_claims_svc
|
||||
from scribe.services.embeddings import memoized_query_embeddings
|
||||
@@ -294,6 +295,35 @@ async def moment():
|
||||
})
|
||||
|
||||
|
||||
@plugin_bp.post("/rule-opened")
|
||||
@login_required
|
||||
async def rule_opened():
|
||||
"""A session opened a rule shortly after these acts (milestone 458 step 7).
|
||||
|
||||
Body: `{"rule_id", "session_id", "acts": [<PreToolUse event>, ...]}` —
|
||||
the calls the plugin saw in the window before the `get_rule`. Each is
|
||||
resolved to its moments, and the open is counted as evidence that the
|
||||
rule belongs on them; once a pair has repeated across enough distinct
|
||||
sessions, `context` carries the line asking the reader to offer the
|
||||
mount. Nothing is mounted here. `repo` / `project_id` scope the evidence.
|
||||
"""
|
||||
data = await request.get_json(silent=True) or {}
|
||||
if not isinstance(data, dict):
|
||||
return jsonify({"moments": [], "context": ""})
|
||||
try:
|
||||
rule_id = int(data.get("rule_id") or 0)
|
||||
except (TypeError, ValueError):
|
||||
rule_id = 0
|
||||
acts = data.get("acts")
|
||||
if rule_id <= 0 or not isinstance(acts, list):
|
||||
return jsonify({"moments": [], "context": ""})
|
||||
project_id, _repo, _unbound = await _project_scope()
|
||||
return jsonify(await judgments_svc.opened_after(
|
||||
g.user.id, rule_id, acts, session_id=str(data.get("session_id") or ""),
|
||||
project_id=project_id or None,
|
||||
))
|
||||
|
||||
|
||||
@plugin_bp.post("/reply-rules")
|
||||
@login_required
|
||||
@memoized_query_embeddings
|
||||
|
||||
@@ -20,6 +20,7 @@ from quart import Blueprint, jsonify, request
|
||||
from scribe.auth import get_current_user_id, login_required
|
||||
from scribe.services import moment_actions as moment_actions_svc
|
||||
from scribe.services import moments as moments_svc
|
||||
from scribe.services import rule_moment_judgments as judgments_svc
|
||||
from scribe.services import rulebooks as rulebooks_svc
|
||||
from scribe.services.retrieval_telemetry import moment_usage
|
||||
from scribe.services.retrieval_tuning import set_dial, current_settings, tuning_history
|
||||
@@ -177,3 +178,27 @@ async def map_action_route():
|
||||
@login_required
|
||||
async def unmap_action_route():
|
||||
return await _mapping_change(moment_actions_svc.unmap_action)
|
||||
|
||||
|
||||
@retrieval_bp.route("/moments/proposals", methods=["GET"])
|
||||
@login_required
|
||||
async def moment_proposals_route():
|
||||
"""The moment proposals waiting on a judgment (milestone 458 step 7) —
|
||||
`rule_moment_proposals`' payload, from the same service. `?rule_id=`
|
||||
narrows to one rule, for the rule editor."""
|
||||
try:
|
||||
rule_id = int(request.args.get("rule_id") or 0)
|
||||
except ValueError:
|
||||
return jsonify({"error": "rule_id must be a whole number"}), 400
|
||||
return jsonify(await judgments_svc.pending(get_current_user_id(), rule_id=rule_id or None))
|
||||
|
||||
|
||||
@retrieval_bp.route("/moments/proposals/judge", methods=["POST"])
|
||||
@login_required
|
||||
async def judge_moment_proposals_route():
|
||||
"""Confirm or reject proposals: `{"judgments": [{rule_id, moment, verdict,
|
||||
note}]}` — `judge_rule_moments` from the browser. A confirm mounts."""
|
||||
data = await request.get_json(silent=True)
|
||||
if not isinstance(data, dict) or not isinstance(data.get("judgments"), list):
|
||||
return jsonify({"error": "Expected {\"judgments\": [...]}"}), 400
|
||||
return jsonify(await judgments_svc.judge(get_current_user_id(), data["judgments"]))
|
||||
|
||||
Reference in New Issue
Block a user