CI & Build / Python lint (push) Successful in 1s
CI & Build / Plugin hooks (push) Successful in 12s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Successful in 1m59s
CI & Build / integration (push) Successful in 2m15s
CI & Build / Build & push image (push) Successful in 35s
The dialog names how many changes across how many rules, and how many of those rules will start holding or refusing the acts they govern. A refused item is reported in a toast; the rest still apply. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
216 lines
8.2 KiB
Vue
216 lines
8.2 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { getWeightProposals, judgeWeightProposals } from "@/api/moments";
|
|
import type {
|
|
RuleWeightProposals, Verdict, WeightEvidence, WeightProposal, WeightProposalsPayload,
|
|
} from "@/api/moments";
|
|
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. "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
|
|
// know how.
|
|
const FORCE: Record<string, string> = {
|
|
inform: "a line beside the work",
|
|
hold: "the act or reply waits until it has been read once",
|
|
enforce: "the act it governs is refused, every time",
|
|
};
|
|
|
|
async function load() {
|
|
try {
|
|
data.value = await getWeightProposals();
|
|
failed.value = false;
|
|
} catch {
|
|
failed.value = true;
|
|
}
|
|
}
|
|
|
|
function key(rule: RuleWeightProposals, p: WeightProposal): string {
|
|
return `${rule.id}:${p.field}:${p.value}`;
|
|
}
|
|
|
|
function triggerText(t: RuleTrigger): string {
|
|
return `${t.kind} ${t.pattern}${t.moment ? ` at ${t.moment}` : ""}`;
|
|
}
|
|
|
|
function change(rule: RuleWeightProposals, p: WeightProposal): string {
|
|
if (p.field === "trigger" && p.trigger) return `add trigger ${triggerText(p.trigger)}`;
|
|
const from = p.field === "enforcement" ? rule.enforcement : rule.salience;
|
|
return `${p.field} ${from} → ${p.value}`;
|
|
}
|
|
|
|
function history(e: WeightEvidence): string {
|
|
if (!e || e.delivered === undefined) return "";
|
|
const parts = [`delivered ${e.delivered}`, `opened ${e.opened ?? 0}`];
|
|
if (e.applied) parts.push(`applied ${e.applied}`);
|
|
if (e.departed) parts.push(`departed ${e.departed}`);
|
|
if (e.misfire_days) parts.push(`misfired on ${e.misfire_days} days`);
|
|
return `${parts.join(" · ")} in ${e.days ?? 90} days`;
|
|
}
|
|
|
|
async function decide(rule: RuleWeightProposals, p: WeightProposal, verdict: Verdict) {
|
|
busy.value = key(rule, p);
|
|
try {
|
|
const out = await judgeWeightProposals([{
|
|
rule_id: rule.id, field: p.field, value: p.trigger ?? p.value, verdict,
|
|
note: verdict === "confirm" ? "Applied in Settings." : "Declined in Settings.",
|
|
}]);
|
|
if (out.refused.length) {
|
|
toast.show(out.refused[0].error, "error");
|
|
return;
|
|
}
|
|
await load();
|
|
} catch (e) {
|
|
toast.show(apiErrorMessage(e, "Could not record that"), "error");
|
|
} finally {
|
|
busy.value = null;
|
|
}
|
|
}
|
|
|
|
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>
|
|
|
|
<template>
|
|
<section v-if="failed || rules.length" class="proposals" aria-labelledby="weights-title">
|
|
<h3 id="weights-title" class="sub-title">How strongly rules arrive — waiting on you</h3>
|
|
<p v-if="failed" class="error-msg">
|
|
The suggestions could not be loaded.
|
|
<button type="button" class="btn-text" @click="load">Try again</button>
|
|
</p>
|
|
<template v-else>
|
|
<p class="field-hint">
|
|
Suggested from each rule's text and what happened when it reached sessions. Inform is a
|
|
line beside the work; hold makes the act or reply wait until the rule has been read once
|
|
(file edits are never held); enforce refuses the act it governs. A trigger reaches the
|
|
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">
|
|
<span class="rule-title">#{{ rule.id }} {{ rule.title }}</span>
|
|
<span class="rule-mounted">
|
|
{{ rule.enforcement }} · {{ rule.salience }}
|
|
<template v-if="rule.mounted.length">
|
|
· on <code v-for="m in rule.mounted" :key="m" class="moment-name">{{ m }}</code>
|
|
</template>
|
|
<template v-if="rule.triggers.length">
|
|
· triggered by
|
|
<code v-for="t in rule.triggers" :key="triggerText(t)" class="moment-name">{{ triggerText(t) }}</code>
|
|
</template>
|
|
</span>
|
|
</div>
|
|
<p class="rule-statement">{{ rule.statement }}</p>
|
|
<ul class="proposal-items">
|
|
<li v-for="p in rule.proposals" :key="key(rule, p)" class="proposal-item">
|
|
<code class="moment-name">{{ change(rule, p) }}</code>
|
|
<span class="proposal-why">
|
|
{{ p.why }}
|
|
<span v-if="p.field === 'enforcement'" class="proposal-source">
|
|
· {{ FORCE[p.value] }}
|
|
</span>
|
|
<span v-if="history(p.evidence)" class="proposal-source">
|
|
· {{ history(p.evidence) }}
|
|
</span>
|
|
</span>
|
|
<span class="proposal-actions">
|
|
<button
|
|
type="button" class="btn-primary btn-sm"
|
|
:disabled="busy !== null"
|
|
@click="decide(rule, p, 'confirm')"
|
|
>Apply</button>
|
|
<button
|
|
type="button" class="btn-text"
|
|
:disabled="busy !== null"
|
|
@click="decide(rule, p, 'reject')"
|
|
>Not this</button>
|
|
</span>
|
|
</li>
|
|
</ul>
|
|
</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>
|
|
|
|
<style scoped src="@/assets/rule-proposals.css" />
|
|
|
|
<style src="@/assets/moments-shared.css" />
|