Files
FabledGrimoire/frontend/src/components/GateStops.vue
T
bvandeusenandClaude Opus 5.5 65f1be80b6 feat(8141): every gate that stops a tool call is recorded, with what followed
A rule set to enforce or hold, the act checkpoint and the project fence
stopped work and left no record. The hook that makes each stop now reports
it to POST /api/plugin/gate-stop; the hook decides, not the server, because
the per-rule and per-session caps are kept in the plugin.

- gate_stops table (migration 0138): gate, outcome (stopped / let_through /
  asked), rule, where it was reached, tool, target project, call id.
- An open of the rule stamps the stop as cleared (rule-opened). A fenced
  call that then runs stamps ran: grimoire_fence_ran.sh, a PostToolUse on
  the fenced tools, matches the call id the fence left pending. That is
  the operator's yes.
- A hold or checkpoint the spent session budget lets through is reported
  as let_through; the per-rule once is not.
- The readout: by gate and by rule, stops, cleared by a read, misfired
  (rule_misfired after it), let through by the cap, ran. In
  retrieval_telemetry as `gates`, at /api/retrieval/gate-stops, and on the
  Moments settings page ("When a rule stopped the work").
- act_decision carries `at`, the moment the deciding rule was reached at.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 14:12:14 -05:00

122 lines
5.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed } from "vue";
import type { GateCounts, GateName, GateStopsPayload } from "@/api/moments";
import { fmtDate } from "@/utils/dateFormat";
/**
* Every time Grimoire stood in front of a tool call instead of commenting
* beside it: a rule set to enforce or hold, the checkpoint on a command, or
* the project fence asking the operator. Per gate and per rule, how often it
* stopped work and what followed — the rule opened (the stop cleared the way
* it is meant to), the rule reported as a misfire (a stop at the wrong
* moment), or a hold let through because the session's stop budget was
* spent.
*/
const props = defineProps<{
data: GateStopsPayload | null;
failed: boolean;
}>();
const emit = defineEmits<{ retry: [] }>();
const GATES: [GateName, string][] = [
["enforce", "Refused (enforce)"],
["hold", "Held for a read (hold)"],
["checkpoint", "Command checkpoint"],
["fence", "Project fence"],
];
const any = computed(() =>
!!props.data && GATES.some(([g]) => (props.data!.by_gate[g]?.stops ?? 0) + (props.data!.by_gate[g]?.let_through ?? 0) > 0),
);
function gateText(gate: GateName, c: GateCounts): string[] {
if (gate === "fence") return [`asked ${c.stops}`, `approved ${c.ran}`];
const parts = [`stopped ${c.stops}`, `cleared by a read ${c.cleared}`, `misfired ${c.misfired}`];
if (gate !== "enforce") parts.push(`let through by the cap ${c.let_through}`);
return parts;
}
</script>
<template>
<section class="gates" aria-labelledby="gates-title">
<h3 id="gates-title" class="sub-title">When a rule stopped the work</h3>
<p v-if="failed" class="error-msg">
Gate stops could not be loaded.
<button type="button" class="btn-text" @click="emit('retry')">Try again</button>
</p>
<p v-else-if="!data" class="empty-msg">Loading gate stops…</p>
<p v-else-if="!any" class="empty-msg">
No gate stopped a tool call in the last {{ data.days }} days.
<template v-if="data.complete_from === null">
None has ever been recorded: a session reports its stops once its plugin is updated.
</template>
</p>
<template v-else>
<p class="field-hint">
Over the last {{ data.days }} days. “Cleared by a read” means the session opened the rule
after the stop; “misfired” means it then reported the rule as not applying there; “let
through by the cap” counts calls a hold would have stopped once the session’s budget of
stops was spent.
<template v-if="data.covers_window === false">
Recording began {{ fmtDate(data.complete_from!) }}, so earlier days are missing, not quiet.
</template>
</p>
<ul class="gate-list">
<li v-for="[gate, label] in GATES" :key="gate" class="gate-row">
<span class="gate-title">{{ label }}</span>
<span class="gate-counts" :class="{ 'way-none': !data.by_gate[gate]?.stops && !data.by_gate[gate]?.let_through }">
<span v-for="t in gateText(gate, data.by_gate[gate])" :key="t">{{ t }}</span>
</span>
</li>
</ul>
<details v-if="data.by_rule.length" class="gate-detail">
<summary>By rule</summary>
<ul class="gate-list">
<li v-for="r in data.by_rule" :key="`${r.rule_id}:${r.gate}:${r.at}`" class="gate-row">
<span class="gate-title">
Rule {{ r.rule_id }}<template v-if="r.title"> “{{ r.title }}”</template>
</span>
<code class="moment-name">{{ r.gate }}<template v-if="r.at"> · {{ r.at }}</template></code>
<span class="gate-counts">
<span v-for="t in gateText(r.gate, r)" :key="t">{{ t }}</span>
<span>{{ r.sessions }} {{ r.sessions === 1 ? "session" : "sessions" }}</span>
<span v-if="r.last_stopped_at" class="stat-when">last {{ fmtDate(r.last_stopped_at) }}</span>
</span>
</li>
</ul>
</details>
<details v-if="data.fence.length" class="gate-detail">
<summary>Fence asks by tool</summary>
<ul class="gate-list">
<li v-for="f in data.fence" :key="`${f.tool}:${f.target}`" class="gate-row">
<code class="moment-name">{{ f.tool }}</code>
<span v-if="f.target" class="gate-title">into project {{ f.target }}</span>
<span class="gate-counts">
<span>asked {{ f.asks }}</span>
<span>approved {{ f.ran }}</span>
</span>
</li>
</ul>
</details>
</template>
</section>
</template>
<style scoped>
.gates { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
.gate-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-1); }
.gate-detail .gate-list { margin: var(--fs-space-1) 0 var(--fs-space-2) var(--fs-space-4); }
.gate-detail summary { cursor: pointer; font-size: var(--fs-size-body-sm); color: var(--fs-text-secondary); }
.gate-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); }
.gate-title { font-size: var(--fs-size-body-sm); color: var(--fs-text-primary); }
.gate-counts {
display: inline-flex; flex-wrap: wrap; gap: var(--fs-space-2); margin-left: auto; justify-content: flex-end;
font-size: var(--fs-size-tiny); color: var(--fs-text-secondary); font-variant-numeric: tabular-nums;
}
/* A gate that stopped nothing is a gap, not a zero to read. */
.way-none { color: var(--fs-text-tertiary); }
</style>
<style src="@/assets/moments-shared.css" />