Adherence per rule and per moment; Apply all; quoted text and heredocs are not commands; the instruction surfaces teach enforcement and salience #228

Merged
bvandeusen merged 6 commits from dev into main 2026-11-23 18:21:44 -05:00
2 changed files with 63 additions and 2 deletions
Showing only changes of commit e70b2c2c00 - Show all commits
+1
View File
@@ -3,6 +3,7 @@
Loaded scoped by each, so these class names stay local to the panels. */
.proposals { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
.proposals-bar { display: flex; justify-content: flex-end; }
.proposal-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); }
.proposal-rule {
padding: var(--fs-space-3);
+62 -2
View File
@@ -7,22 +7,41 @@ import type {
import type { RuleTrigger } from "@/api/rulebooks";
import { apiErrorMessage } from "@/api/client";
import { useToastStore } from "@/stores/toast";
import ConfirmDialog from "@/components/ConfirmDialog.vue";
/**
* Suggestions for how strongly a rule arrives and what reaches it, waiting on
* a person. A pass read each rule beside what happened when it reached
* sessions, and proposed its enforcement (inform, hold, enforce), its salience,
* or a typed trigger. Nothing changes until "Apply" is pressed; "Not this"
* keeps the value from being proposed again. The same judgment
* `judge_rule_weights` makes in a session, through the same service.
* keeps the value from being proposed again. "Apply all" confirms every
* listed suggestion at once, after a dialog that counts what changes. The
* same judgment `judge_rule_weights` makes in a session, through the same
* service.
*/
const toast = useToastStore();
const data = ref<WeightProposalsPayload | null>(null);
const failed = ref(false);
const busy = ref<string | null>(null);
const confirmingAll = ref(false);
const rules = computed<RuleWeightProposals[]>(() => data.value?.rules ?? []);
const proposalCount = computed(() => rules.value.reduce((n, r) => n + r.proposals.length, 0));
// The dialog names how many rules would start stopping work, since a hold or
// an enforce is the change a person notices in their next session.
const allSummary = computed(() => {
const stopping = rules.value.filter((r) => r.proposals.some(
(p) => p.field === "enforcement" && p.value !== "inform",
)).length;
const changes = `${proposalCount.value} change${proposalCount.value === 1 ? "" : "s"}`;
const across = `${rules.value.length} rule${rules.value.length === 1 ? "" : "s"}`;
const stops = stopping
? ` ${stopping} of them will hold or refuse the acts they govern.`
: "";
return `${changes} across ${across} take effect at once.${stops}`;
});
// What each enforcement does when the rule arrives — said beside the change,
// since "hold" and "enforce" stop work and the person applying one should
@@ -84,6 +103,31 @@ async function decide(rule: RuleWeightProposals, p: WeightProposal, verdict: Ver
}
}
async function applyAll() {
confirmingAll.value = false;
busy.value = "all";
try {
const out = await judgeWeightProposals(rules.value.flatMap((rule) => rule.proposals.map((p) => ({
rule_id: rule.id, field: p.field, value: p.trigger ?? p.value,
verdict: "confirm" as Verdict, note: "Applied with Apply all in Settings.",
}))));
if (out.refused.length) {
const first = out.refused[0];
toast.show(
`${out.judged.length} applied; ${out.refused.length} refused — #${first.rule_id}: ${first.error}`,
"error",
);
} else {
toast.show(`${out.judged.length} applied.`, "success");
}
await load();
} catch (e) {
toast.show(apiErrorMessage(e, "Could not apply the suggestions"), "error");
} finally {
busy.value = null;
}
}
onMounted(load);
</script>
@@ -102,6 +146,13 @@ onMounted(load);
rule exactly, by the tool, path, command or word the act carries; a rule with triggers
holds or refuses only the acts they match, and elsewhere it is a line.
</p>
<div class="proposals-bar">
<button
type="button" class="btn-primary btn-sm"
:disabled="busy !== null"
@click="confirmingAll = true"
>Apply all {{ proposalCount }}</button>
</div>
<ul class="proposal-list">
<li v-for="rule in rules" :key="rule.id" class="proposal-rule">
<div class="rule-head">
@@ -147,6 +198,15 @@ onMounted(load);
</li>
</ul>
</template>
<ConfirmDialog
v-if="confirmingAll"
title="Apply every suggestion?"
:message="allSummary"
confirm-label="Apply all"
:danger="false"
@confirm="applyAll"
@cancel="confirmingAll = false"
/>
</section>
</template>