Files
FabledScribe/frontend/src/views/RulesView.vue
T
bvandeusenandClaude Opus 5 7038e41ec7
CI & Build / Python lint (push) Successful in 3s
CI & Build / Plugin hooks (push) Successful in 11s
CI & Build / integration (push) Successful in 52s
CI & Build / TypeScript typecheck (push) Successful in 53s
CI & Build / Python tests (push) Successful in 1m32s
CI & Build / Build & push image (push) Successful in 34s
feat(rules): preferences are writable, and their drift arrives (#3895)
Milestone 399 step 5. Steps 1-4 put preferences into the backend: a kind
column, an inverted write path, a third register in the injected block, a
delivery slot. Nothing the operator could touch. Rule 27 forbids leaving it
there, and here it matters more than usual, because the UI is the only
guard against the risk the milestone named up front — an agent misreads one
session, rewrites a preference, and follows the rewritten version forever
while the operator never sees the moment it changed.

Four things ship.

A preference is DISTINGUISHABLE. `kind` reaches the client (the server has
always sent it in rule_brief) and a preference carries a chip. Force is the
one thing a list of instructions must not leave the reader to infer, and a
row that renders identically to a rule teaches the opposite of both facts
about a preference: it does not bind, and a session may rewrite it.

A preference is WRITABLE. The editor gains the kind as a first-class choice
with the test beside it — what happens when someone does not do this — and
says plainly, when preference is chosen, that sessions rewrite these
without asking and every rewrite is kept.

DRIFT ARRIVES. `GET /api/rules/drift` returns one row per rewritten
preference carrying its latest rewrite: what it said, what it says now, and
the record named by `arose_from_id` that taught the change. Both texts ride
along so the list shows the diff without a call per row. The new pane sits
beside the staleness sweep, because drift belongs to no one rulebook, and
it answers a question the operator would not have thought to ask.

REVERSION IS ONE ACTION, and this is the carve-out worth arguing with.
Milestone 323 refused a one-click restore for rules — "a binding
instruction should not be revertible in one click", because a silent revert
erases the only record of why the rewrite happened. That reasoning turns on
the rewrite being the operator's own decision. A preference's is not: the
agent makes it mid-work without asking, so reverting is a veto over someone
else's edit rather than an undo of your own, and a veto costing more than a
shrug is not supervision. The route refuses anything but a preference (409),
and nothing is erased: the restore goes through update_rule, so it snapshots
too and the history GAINS the revert. An integration test pins that, because
it is the whole basis for the exception.

Tested against real Postgres — every claim is about which rows come back
and in what order, which a stand-in session cannot judge.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01821k5B3Ysecp9fNYs92Kuy
2026-09-18 12:39:13 -04:00

148 lines
4.8 KiB
Vue

<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useRulebooksStore } from "@/stores/rulebooks";
import RulebookListPane from "@/components/rules/RulebookListPane.vue";
import RulebookDetailPane from "@/components/rules/RulebookDetailPane.vue";
import RuleListPane from "@/components/rules/RuleListPane.vue";
import RuleEditorSlideOver from "@/components/rules/RuleEditorSlideOver.vue";
import RuleSweepPane from "@/components/rules/RuleSweepPane.vue";
import PreferenceDriftPane from "@/components/rules/PreferenceDriftPane.vue";
const store = useRulebooksStore();
const route = useRoute();
const router = useRouter();
const selectedRulebookId = ref<number | null>(null);
const selectedTopicId = ref<number | null>(null);
const editingRuleId = ref<number | null>(null);
const creatingRuleForTopic = ref<number | null>(null);
const sweepActive = ref(false);
const driftActive = ref(false);
function syncFromRoute() {
const rb = route.query.rb ? Number(route.query.rb) : null;
const topic = route.query.topic ? Number(route.query.topic) : null;
const rule = route.query.rule ? Number(route.query.rule) : null;
selectedRulebookId.value = rb;
selectedTopicId.value = topic;
editingRuleId.value = rule;
sweepActive.value = route.query.view === "due";
driftActive.value = route.query.view === "drift";
}
/** The two cross-cutting views share one `view` query key, so entering either
* leaves the other — and keeps `?rule=…` so an open editor survives the
* switch, the way the sweep already did. */
function selectCrossCutting(view: "due" | "drift") {
sweepActive.value = view === "due";
driftActive.value = view === "drift";
const { rb, topic, ...rest } = route.query;
void rb; void topic;
router.replace({ query: { ...rest, view } });
}
function selectRulebook(id: number) {
sweepActive.value = false;
driftActive.value = false;
selectedRulebookId.value = id;
selectedTopicId.value = null;
router.replace({ query: { rb: String(id) } });
store.fetchTopics(id);
}
function selectTopic(id: number) {
selectedTopicId.value = id;
router.replace({ query: { ...route.query, topic: String(id) } });
store.fetchRules(id);
}
function openRule(id: number) {
editingRuleId.value = id;
router.replace({ query: { ...route.query, rule: String(id) } });
}
function closeRuleEditor() {
editingRuleId.value = null;
creatingRuleForTopic.value = null;
const { rule, ...rest } = route.query;
void rule;
router.replace({ query: rest });
}
function startCreatingRule(topicId: number) {
creatingRuleForTopic.value = topicId;
}
onMounted(async () => {
await store.fetchRulebooks();
syncFromRoute();
if (selectedRulebookId.value) await store.fetchTopics(selectedRulebookId.value);
if (selectedTopicId.value) await store.fetchRules(selectedTopicId.value);
});
watch(() => route.query, syncFromRoute);
</script>
<template>
<div class="rules-view">
<RulebookListPane
:rulebooks="store.rulebooks"
:selected-id="selectedRulebookId"
:sweep-active="sweepActive"
:drift-active="driftActive"
@select="selectRulebook"
@select-sweep="selectCrossCutting('due')"
@select-drift="selectCrossCutting('drift')"
/>
<RuleSweepPane v-if="sweepActive" class="sweep-span" @open-rule="openRule" />
<PreferenceDriftPane v-else-if="driftActive" class="sweep-span" @open-rule="openRule" />
<RulebookDetailPane
v-else-if="selectedRulebookId !== null"
:rulebook-id="selectedRulebookId"
:topics="store.topicsByRulebook[selectedRulebookId] || []"
:selected-topic-id="selectedTopicId"
@select-topic="selectTopic"
/>
<div v-else class="pane empty">
<p>Select a rulebook to view its topics.</p>
</div>
<RuleListPane
v-if="!sweepActive && !driftActive && selectedTopicId !== null"
:topic-id="selectedTopicId"
:rules="store.rulesByTopic[selectedTopicId] || []"
@open-rule="openRule"
@create-rule="startCreatingRule"
/>
<div v-else-if="!sweepActive && !driftActive" class="pane empty">
<p>Select a topic to view its rules.</p>
</div>
<RuleEditorSlideOver
v-if="editingRuleId !== null || creatingRuleForTopic !== null"
:rule-id="editingRuleId"
:topic-id="creatingRuleForTopic"
@close="closeRuleEditor"
/>
</div>
</template>
<style scoped>
.rules-view {
display: grid;
grid-template-columns: 280px 300px 1fr;
height: 100vh;
gap: 1px;
background: var(--fs-border-color);
}
/* A cross-cutting pane — the sweep, or recent changes — takes the width the
rulebook + topic panes would have used rather than being squeezed into one
column. */
.sweep-span { grid-column: 2 / -1; }
.pane.empty {
background: var(--fs-surface-hover);
padding: 1rem;
opacity: 0.6;
font-style: italic;
}
</style>