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

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:
2026-11-23 13:05:38 -05:00
co-authored by Claude Opus 5.5
parent 78c945e7c3
commit 619612732f
20 changed files with 1320 additions and 34 deletions
+75
View File
@@ -1,4 +1,5 @@
import { apiGet, apiPost, apiDelete } from "@/api/client";
import type { RuleEnforcement, RuleSalience, RuleTrigger } from "@/api/rulebooks";
/**
* The moments of work rules mount on, and the actions that
@@ -180,3 +181,77 @@ export function getProposals(ruleId?: number): Promise<ProposalsPayload> {
export function judgeProposals(judgments: MomentJudgment[]): Promise<JudgeResult> {
return apiPost("/api/retrieval/moments/proposals/judge", { judgments });
}
/**
* Suggestions for how strongly a rule arrives (`enforcement`, `salience`) and
* which typed triggers reach it, from a pass that read the rule beside its
* delivery history. Nothing changes until a person confirms one.
* `GET /api/retrieval/weights/proposals`, the payload the
* `rule_weight_proposals` MCP tool returns.
*/
export type WeightField = "enforcement" | "salience" | "trigger";
/** What happened when the rule reached a session, over `days`. */
export interface WeightEvidence {
days?: number;
delivered?: number;
opened?: number;
places?: { at: string; delivered: number; opened: number }[];
pulled?: number;
applied?: number;
departed?: number;
misfire_days?: number;
}
export interface WeightProposal {
field: WeightField;
/** The enforcement or salience name; for a trigger, its stored form. */
value: string;
trigger?: RuleTrigger;
why: string;
source: "pass" | "edit";
evidence: WeightEvidence;
created_at: string | null;
}
export interface RuleWeightProposals {
id: number;
title: string;
kind: string;
statement: string;
when_to_apply: string;
home: "global" | "project";
enforcement: RuleEnforcement;
salience: RuleSalience;
mounted: string[];
triggers: RuleTrigger[];
proposals: WeightProposal[];
}
export interface WeightProposalsPayload {
rules: RuleWeightProposals[];
total: number;
}
export interface WeightJudgment {
rule_id: number;
field: WeightField;
value: string | RuleTrigger;
verdict: Verdict;
note?: string;
}
export interface WeightJudgeResult {
judged: { rule_id: number; field: WeightField; value: string; state: string }[];
refused: { rule_id: number; field?: string; error: string }[];
}
export function getWeightProposals(ruleId?: number): Promise<WeightProposalsPayload> {
return apiGet(`/api/retrieval/weights/proposals${ruleId ? `?rule_id=${ruleId}` : ""}`);
}
/** A confirm sets the field on the rule (a trigger is added beside its
* others); a reject stops that value being proposed again. */
export function judgeWeightProposals(judgments: WeightJudgment[]): Promise<WeightJudgeResult> {
return apiPost("/api/retrieval/weights/proposals/judge", { judgments });
}
+29
View File
@@ -0,0 +1,29 @@
/* A proposal about a rule waiting on a person — the panels under
Settings › Moments that list mount proposals and weight suggestions.
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); }
.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);
background: var(--fs-surface-page);
border: 1px dashed var(--fs-border-color);
border-radius: var(--fs-radius-md);
}
.rule-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); }
.rule-title { font-size: var(--fs-size-body-sm); color: var(--fs-text-primary); font-weight: var(--fs-weight-medium); }
.rule-mounted { display: inline-flex; flex-wrap: wrap; gap: var(--fs-space-1); font-size: var(--fs-size-tiny); color: var(--fs-text-tertiary); }
.rule-statement { margin: var(--fs-space-1) 0 var(--fs-space-2); font-size: var(--fs-size-body-sm); color: var(--fs-text-secondary); line-height: var(--fs-leading-body); }
.proposal-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); }
.proposal-item { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); font-size: var(--fs-size-body-sm); }
.proposal-why { flex: 1 1 16rem; color: var(--fs-text-secondary); }
.proposal-source { color: var(--fs-text-tertiary); font-size: var(--fs-size-tiny); }
.proposal-actions { display: inline-flex; gap: var(--fs-space-2); margin-left: auto; }
.proposal-kind { font-size: var(--fs-size-tiny); color: var(--fs-text-tertiary); }
.proposal-reasons {
flex-basis: 100%;
margin: 0;
padding-left: var(--fs-space-4);
font-size: var(--fs-size-tiny);
color: var(--fs-text-tertiary);
}
+1 -28
View File
@@ -158,33 +158,6 @@ onMounted(load);
</section>
</template>
<style scoped>
.proposals { display: flex; flex-direction: column; gap: var(--fs-space-2); }
.sub-title { margin: 0; font-size: 0.95rem; color: var(--fs-text-primary); }
.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);
background: var(--fs-surface-page);
border: 1px dashed var(--fs-border-color);
border-radius: var(--fs-radius-md);
}
.rule-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); }
.rule-title { font-size: var(--fs-size-body-sm); color: var(--fs-text-primary); font-weight: var(--fs-weight-medium); }
.rule-mounted { display: inline-flex; flex-wrap: wrap; gap: var(--fs-space-1); font-size: var(--fs-size-tiny); color: var(--fs-text-tertiary); }
.rule-statement { margin: var(--fs-space-1) 0 var(--fs-space-2); font-size: var(--fs-size-body-sm); color: var(--fs-text-secondary); line-height: var(--fs-leading-body); }
.proposal-items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--fs-space-2); }
.proposal-item { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--fs-space-2); font-size: var(--fs-size-body-sm); }
.proposal-why { flex: 1 1 16rem; color: var(--fs-text-secondary); }
.proposal-source { color: var(--fs-text-tertiary); font-size: var(--fs-size-tiny); }
.proposal-actions { display: inline-flex; gap: var(--fs-space-2); margin-left: auto; }
.proposal-kind { font-size: var(--fs-size-tiny); color: var(--fs-text-tertiary); }
.proposal-reasons {
flex-basis: 100%;
margin: 0;
padding-left: var(--fs-space-4);
font-size: var(--fs-size-tiny);
color: var(--fs-text-tertiary);
}
</style>
<style scoped src="@/assets/rule-proposals.css" />
<style src="@/assets/moments-shared.css" />
@@ -3,6 +3,7 @@ import { computed, onMounted, ref } from "vue";
import { useMomentsStore } from "@/stores/moments";
import MomentProposals from "@/components/MomentProposals.vue";
import MomentRuleUsage from "@/components/MomentRuleUsage.vue";
import WeightProposals from "@/components/WeightProposals.vue";
import type { MomentAction, MomentUsage } from "@/api/moments";
import { fmtDate } from "@/utils/dateFormat";
@@ -126,6 +127,7 @@ onMounted(() => store.load(true));
</p>
<MomentProposals />
<WeightProposals />
<ul class="moment-list">
<li v-for="m in catalog" :key="m.name" class="moment-row">
+154
View File
@@ -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" />