Adherence per rule and per moment; Apply all; quoted text and heredocs are not commands; the instruction surfaces teach enforcement and salience #228
@@ -3,6 +3,7 @@
|
|||||||
Loaded scoped by each, so these class names stay local to the panels. */
|
Loaded scoped by each, so these class names stay local to the panels. */
|
||||||
.proposals { display: flex; flex-direction: column; gap: var(--fs-space-2); }
|
.proposals { display: flex; flex-direction: column; gap: var(--fs-space-2); }
|
||||||
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
|
.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-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); }
|
||||||
.proposal-rule {
|
.proposal-rule {
|
||||||
padding: var(--fs-space-3);
|
padding: var(--fs-space-3);
|
||||||
|
|||||||
@@ -7,22 +7,41 @@ import type {
|
|||||||
import type { RuleTrigger } from "@/api/rulebooks";
|
import type { RuleTrigger } from "@/api/rulebooks";
|
||||||
import { apiErrorMessage } from "@/api/client";
|
import { apiErrorMessage } from "@/api/client";
|
||||||
import { useToastStore } from "@/stores/toast";
|
import { useToastStore } from "@/stores/toast";
|
||||||
|
import ConfirmDialog from "@/components/ConfirmDialog.vue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Suggestions for how strongly a rule arrives and what reaches it, waiting on
|
* 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
|
* a person. A pass read each rule beside what happened when it reached
|
||||||
* sessions, and proposed its enforcement (inform, hold, enforce), its salience,
|
* sessions, and proposed its enforcement (inform, hold, enforce), its salience,
|
||||||
* or a typed trigger. Nothing changes until "Apply" is pressed; "Not this"
|
* or a typed trigger. Nothing changes until "Apply" is pressed; "Not this"
|
||||||
* keeps the value from being proposed again. The same judgment
|
* keeps the value from being proposed again. "Apply all" confirms every
|
||||||
* `judge_rule_weights` makes in a session, through the same service.
|
* 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 toast = useToastStore();
|
||||||
|
|
||||||
const data = ref<WeightProposalsPayload | null>(null);
|
const data = ref<WeightProposalsPayload | null>(null);
|
||||||
const failed = ref(false);
|
const failed = ref(false);
|
||||||
const busy = ref<string | null>(null);
|
const busy = ref<string | null>(null);
|
||||||
|
const confirmingAll = ref(false);
|
||||||
|
|
||||||
const rules = computed<RuleWeightProposals[]>(() => data.value?.rules ?? []);
|
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,
|
// What each enforcement does when the rule arrives — said beside the change,
|
||||||
// since "hold" and "enforce" stop work and the person applying one should
|
// 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);
|
onMounted(load);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -102,6 +146,13 @@ onMounted(load);
|
|||||||
rule exactly, by the tool, path, command or word the act carries; a rule with triggers
|
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.
|
holds or refuses only the acts they match, and elsewhere it is a line.
|
||||||
</p>
|
</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">
|
<ul class="proposal-list">
|
||||||
<li v-for="rule in rules" :key="rule.id" class="proposal-rule">
|
<li v-for="rule in rules" :key="rule.id" class="proposal-rule">
|
||||||
<div class="rule-head">
|
<div class="rule-head">
|
||||||
@@ -147,6 +198,15 @@ onMounted(load);
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</template>
|
</template>
|
||||||
|
<ConfirmDialog
|
||||||
|
v-if="confirmingAll"
|
||||||
|
title="Apply every suggestion?"
|
||||||
|
:message="allSummary"
|
||||||
|
confirm-label="Apply all"
|
||||||
|
:danger="false"
|
||||||
|
@confirm="applyAll"
|
||||||
|
@cancel="confirmingAll = false"
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user