feat(7732): a pass weighs each rule — enforcement, salience and triggers proposed from its text and delivery history, confirmed by the operator
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m9s
CI & Build / Build & push image (push) Skipped
CI & Build / Python lint (push) Successful in 2s
CI & Build / Plugin hooks (push) Successful in 15s
CI & Build / TypeScript typecheck (push) Successful in 34s
CI & Build / Python tests (push) Failing after 1m41s
CI & Build / integration (push) Successful in 2m9s
CI & Build / Build & push image (push) Skipped
Adds rule_field_judgments (migration 0132), the rules_to_weigh / propose_rule_weights / rule_weight_proposals / judge_rule_weights tools, the routes and the Settings › Moments panel that confirms them. A value equal to the rule's own is recorded as agreed; a different one waits; enforce is refused for a rule no act reaches; a direct edit answers a waiting suggestion. Backup v30 carries the judgments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
<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";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const toast = useToastStore();
|
||||
|
||||
const data = ref<WeightProposalsPayload | null>(null);
|
||||
const failed = ref(false);
|
||||
const busy = ref<string | null>(null);
|
||||
|
||||
const rules = computed<RuleWeightProposals[]>(() => data.value?.rules ?? []);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
</p>
|
||||
<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>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped src="@/assets/rule-proposals.css" />
|
||||
|
||||
<style src="@/assets/moments-shared.css" />
|
||||
Reference in New Issue
Block a user