CI & Build / TypeScript typecheck (push) Successful in 35s
CI & Build / Plugin hooks (push) Failing after 19s
CI & Build / Python lint (push) Successful in 2s
CI & Build / Python tests (push) Successful in 2m31s
CI & Build / integration (push) Successful in 2m18s
CI & Build / Build & push image (push) Canceled after 27s
Rules 2, 4, 10 and 153 are set to hold and mounted on work.deliver. A push to dev therefore stopped four times in a row, once for each of them, although none of them governs a push to dev: their triggers (git push origin main, git tag, pytest, pull_request_write) name the acts they do govern. A rule that has triggers now stops an act only when one of them matched it. Reached by its moment alone, it is a line beside the work. A rule with no triggers still holds wherever it is mounted, because the mount is all that says where it applies. A mounted rule whose unscoped trigger also matched now counts as reached by the trigger, so it ranks as triggered and may stop the act. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
156 lines
6.0 KiB
Vue
156 lines
6.0 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";
|
|
|
|
/**
|
|
* 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; a rule with triggers
|
|
holds or refuses only the acts they match, and elsewhere it is a line.
|
|
</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" />
|