mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 17:47:39 +01:00
* feat(approvals): standing approvals + one-tap decisions from Telegram
Asking Loki in Telegram to put an appointment in the calendar did not put an
appointment in the calendar. It sent you to a website.
Three separate causes, all fixed here:
1. THE CHAT HAD NO ROAD TO THE CALENDAR AT ALL. `gog calendar create` is
blocked on the box by the safety shim, and the fleetcrown skill could only
decide drafts that already existed — it had no way to create one. So the
agent hit the shim, read "route it through the approval queue", and passed
that on as advice. Adds `fc.sh book`, which proposes a structured event
through /api/actions/propose, and rewrites the shim's refusal to name it.
The shim still blocks every external Google write; unattended agents have
gained nothing.
2. THE GATE WAS ON THE WRONG SIDE OF THE REVERSIBILITY LINE. The queue enforced
"nothing runs that the operator did not TAP", which is stricter than the rule
it stands for ("nothing runs that the operator did not APPROVE"). For an
event in your own calendar — private, self-only, undone by deleting it — the
difference was pure latency (2026-08-04: proposed 14:15, booked 21:02).
Standing approvals let that yes be given once, in advance, with three rails
in code rather than in a docblock: eligibility is hard-coded (calendar events
and commitments only — never anything that reaches another person), the
payload is re-checked at decision time (guests mean invitations, so those go
back to the queue), and unknown is never yes (no resolvable time, or a slot
already past, queues). Default on for calendar events; toggle at /approvals.
3. THE NOTIFICATION HANDED BACK A CHORE. "2 actions are waiting… <url>" states
a problem and leaves the answer behind a login. Decisions now arrive as a
card carrying what/when/where plus one-tap Approve / Reject / Edit buttons,
backed by HMAC links scoped to one action and one verb — so a decision needs
no session and works when the gateway is down. Still two messages and only
two: one when a decision is owed, one when the effect really happened.
Also fixes a real data bug: propose_action had no event date fields, so the WHEN
of an appointment had nowhere to go and arrived as prose in `body`, which a Groq
pass then had to guess back — a model re-deriving a value the model one step
earlier knew exactly.
Behaviour that did NOT change: emails, messages, dispatches, and person-book
writes still require a per-item yes, and always will — they are ineligible in
code, and a preference row naming one authorises nothing. Every auto-approval is
audited with `via: standing-rule` and announced, so nothing is done in the
operator's name silently.
Tests pin the parts that must not be trusted: 37 cases on the standing-approval
rails (asserted from the side that hurts — a false `auto: true`), 21 on token
forgery and tampering.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(chat-skill): the chat's whole Loki skill was dead, and unversioned
Found while testing the previous commit end-to-end, and it is the largest of
the reasons appointments never got added.
On 2026-09-14 the product was renamed to Loki and `calendar-drain.env`'s keys
were renamed with it. The chat agent's skill script, which reads that file, was
not — because it lived only on the box, where no gate in this repo could see
it. Since then every command it offers has aborted on its first line:
line 14: <OLD>_AGENT_TOKEN: <OLD>_AGENT_TOKEN missing in calendar-drain.env
Verified live on bitbaum just now. So from Telegram the operator could not list
the approval queue, could not approve or reject anything, and could not
dispatch — silently, because a skill that errors just makes the agent talk
about something else instead. The only surviving route to a decision was the
website. That is the complaint, and it had a cause older than the UX.
Fixes:
- Renames the skill to `loki` (the retired product name is forbidden in this
repo by scripts/hetzner/test-no-retired-name.sh — which caught this commit,
correctly, when the box files were first imported verbatim) and reads the
env keys the file actually has.
- The installer REMOVES the superseded skill directory rather than leaving it.
Two skills claiming the same job, one of which cannot run, is how the agent
kept choosing the broken one.
- The installer now runs `loki.sh pending` as the openclaw user and fails if it
cannot authenticate. That is the check which would have caught the rename on
the day it happened: run the thing, as the user who runs it, and require real
output. Every other verification in that script only asserted that files
exist, and files existing is exactly what was true throughout the outage.
Also closes a gap in the previous commit: an auto-approved COMMITMENT executed
without telling anyone, while the comments claimed every auto-approval is
announced. Calendar events are announced from where gog succeeds (asynchronous,
on the box); everything else finishes inside enqueueAction, so that is the only
place that knows it finished at all. A standing approval nobody is told about
is not a standing rule, it is a silent one.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(install): keep the gog shim parseable, and prove the block still fires
The replacement text I substituted into the shim carried double quotes. It
lands inside `block(){ echo "…" >&2; }` — a double-quoted bash string — so a
quote in the middle of it closes that string early and leaves the shim a
syntax error. Every gog call on the box would then fail, reads included, and
the calendar drain's real bookings with them: an install step meant to improve
an error message would have taken out the calendar entirely.
Caught by tracing the sed against the shim's actual text rather than running
it. Two checks added so the next one is caught by the machine:
- `bash -n` on the shim after the edit — it is a shell script we just modified
in place, so prove it still parses before trusting anything else about it.
- Actually attempt a calendar write as the openclaw user and require it to be
REFUSED. The old check grepped for the rule's text, and a rule you can read
in a file is not a rule you have seen refuse anything.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(ui): use tokens this design system actually defines
The new approvals control and decision page reached for `text-brand`,
`accent-brand`, `bg-surface-hover` and `rounded-card`. None of those exist in
globals.css — the real names are `accent-text`, `surface-raised` and the
`radius-*` scale. Tailwind emits nothing for an unknown utility and reports no
error, so the checkbox would have rendered browser-default blue and the hover
state simply would not have happened, on a page whose entire job is to be
tapped once and trusted.
The design check passes either way: it forbids arbitrary values (`bg-[#fff]`),
which is a different failure from naming a token that was never defined. Caught
by grepping whether any other component uses these names — none did, which is
the tell.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
186 lines
6.4 KiB
TypeScript
186 lines
6.4 KiB
TypeScript
// Pins the rails on standing approvals — the rule that lets Loki act without
|
|
// asking.
|
|
//
|
|
// Why it earns a test: this is the only code in the app that can turn a
|
|
// proposal into a real-world effect with no human in the loop. Every other
|
|
// guard in the action queue fails safe by doing nothing; this one fails by
|
|
// DOING something. The dangerous direction is a false `auto: true`, so the
|
|
// three rails are asserted from the side that hurts:
|
|
//
|
|
// 1. an ineligible type can never be authorised, even by a stored preference
|
|
// that names it — a database row must not be able to widen the set;
|
|
// 2. an event with guests goes back to the queue, because guests mean
|
|
// invitations, which are outbound and not undoable;
|
|
// 3. "we don't know when" is not "yes" — an unresolvable or past slot queues.
|
|
//
|
|
// The negative cases are the point. A test that only proved the happy path
|
|
// would pass just as happily on a version that returned `{auto:true}` for
|
|
// everything.
|
|
import {
|
|
STANDING_APPROVAL_ELIGIBLE,
|
|
isStandingApprovalEligible,
|
|
sanitizeStandingApprovals,
|
|
standingApprovalVerdict,
|
|
} from "@/lib/actions/standing-approval";
|
|
import { ACTION_TYPE } from "@/lib/constants/statuses";
|
|
|
|
const NOW = Date.parse("2026-09-17T10:00:00Z");
|
|
const SOON = { eventStart: "2026-09-19T14:00:00+02:00", eventEnd: "2026-09-19T15:00:00+02:00" };
|
|
const ALL = [ACTION_TYPE.CREATE_EVENT, ACTION_TYPE.CREATE_COMMITMENT];
|
|
|
|
let pass = 0;
|
|
const cases: Array<[string, boolean]> = [];
|
|
const check = (name: string, cond: boolean) => {
|
|
cases.push([name, cond]);
|
|
if (cond) pass++;
|
|
};
|
|
|
|
const auto = (args: Parameters<typeof standingApprovalVerdict>[0]) =>
|
|
standingApprovalVerdict({ now: NOW, ...args }).auto;
|
|
|
|
// ── RAIL 1: eligibility is code, not data ───────────────────────────────────
|
|
check(
|
|
"eligible set is exactly create_event + create_commitment",
|
|
STANDING_APPROVAL_ELIGIBLE.length === 2 &&
|
|
STANDING_APPROVAL_ELIGIBLE.includes(ACTION_TYPE.CREATE_EVENT) &&
|
|
STANDING_APPROVAL_ELIGIBLE.includes(ACTION_TYPE.CREATE_COMMITMENT),
|
|
);
|
|
for (const type of [
|
|
ACTION_TYPE.SEND_EMAIL,
|
|
ACTION_TYPE.SEND_MESSAGE,
|
|
ACTION_TYPE.DISPATCH_PROMPT,
|
|
ACTION_TYPE.IMPORT_PERSON,
|
|
ACTION_TYPE.ENRICH_PERSON,
|
|
ACTION_TYPE.MERGE_PEOPLE,
|
|
ACTION_TYPE.FOLLOW_UP,
|
|
ACTION_TYPE.OTHER,
|
|
] as const) {
|
|
check(`${type} is NOT eligible`, !isStandingApprovalEligible(type));
|
|
// The nasty one: a preference row that explicitly names an outbound type.
|
|
check(
|
|
`${type} is refused even when the stored preference names it`,
|
|
!auto({ type, payload: { to: "someone@example.com", body: "hi" }, standingApprovals: [type] }),
|
|
);
|
|
}
|
|
check(
|
|
"sanitize drops ineligible and unknown values",
|
|
JSON.stringify(
|
|
sanitizeStandingApprovals(["send_email", "create_event", "nonsense", "merge_people"]),
|
|
) === JSON.stringify([ACTION_TYPE.CREATE_EVENT]),
|
|
);
|
|
check("sanitize of null is empty", sanitizeStandingApprovals(null).length === 0);
|
|
check(
|
|
"sanitize dedupes repeats",
|
|
sanitizeStandingApprovals(["create_event", "create_event"]).length === 1,
|
|
);
|
|
|
|
// ── The rule has to actually work, or it is just a stricter queue ───────────
|
|
check(
|
|
"event with a real slot and a rule ⇒ auto",
|
|
auto({ type: ACTION_TYPE.CREATE_EVENT, payload: SOON, standingApprovals: ALL }),
|
|
);
|
|
check(
|
|
"all-day event ⇒ auto",
|
|
auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { eventDate: "2026-09-20", allDay: true },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"commitment with a rule ⇒ auto",
|
|
auto({
|
|
type: ACTION_TYPE.CREATE_COMMITMENT,
|
|
payload: { commitment: "call the landlord" },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"no rule set ⇒ queues (this is the default for a user who never opted in)",
|
|
!auto({ type: ACTION_TYPE.CREATE_EVENT, payload: SOON, standingApprovals: [] }),
|
|
);
|
|
check(
|
|
"a rule for the OTHER eligible type does not cover this one",
|
|
!auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: SOON,
|
|
standingApprovals: [ACTION_TYPE.CREATE_COMMITMENT],
|
|
}),
|
|
);
|
|
|
|
// ── RAIL 2: guests mean invitations, which are outbound ─────────────────────
|
|
for (const [name, payload] of [
|
|
["attendees array", { ...SOON, attendees: ["ana@example.com"] }],
|
|
["attendees string", { ...SOON, attendees: "ana@example.com" }],
|
|
["guests field", { ...SOON, guests: ["ana@example.com"] }],
|
|
["invitees field", { ...SOON, invitees: ["ana@example.com"] }],
|
|
["eventAttendees field", { ...SOON, eventAttendees: ["ana@example.com"] }],
|
|
] as const) {
|
|
check(
|
|
`event with ${name} ⇒ queues despite the rule`,
|
|
!auto({ type: ACTION_TYPE.CREATE_EVENT, payload, standingApprovals: ALL }),
|
|
);
|
|
}
|
|
check(
|
|
"an EMPTY attendees array is not guests",
|
|
auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { ...SOON, attendees: [] },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"a blank attendees string is not guests",
|
|
auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { ...SOON, attendees: " " },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
|
|
// ── RAIL 3: unknown is not yes ──────────────────────────────────────────────
|
|
check(
|
|
"event with no resolvable time ⇒ queues",
|
|
!auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { body: "sometime next week probably" },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"event with an unparseable time ⇒ queues",
|
|
!auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { eventStart: "next tuesday" },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"null payload ⇒ queues",
|
|
!auto({ type: ACTION_TYPE.CREATE_EVENT, payload: null, standingApprovals: ALL }),
|
|
);
|
|
check(
|
|
"event whose slot already passed ⇒ queues (never books into the past)",
|
|
!auto({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { eventStart: "2026-09-16T09:00:00Z", eventEnd: "2026-09-16T10:00:00Z" },
|
|
standingApprovals: ALL,
|
|
}),
|
|
);
|
|
check(
|
|
"a declined event says WHY, so the rule never looks broken",
|
|
(() => {
|
|
const v = standingApprovalVerdict({
|
|
type: ACTION_TYPE.CREATE_EVENT,
|
|
payload: { ...SOON, attendees: ["ana@example.com"] },
|
|
standingApprovals: ALL,
|
|
now: NOW,
|
|
});
|
|
return !v.auto && v.reason.includes("guests");
|
|
})(),
|
|
);
|
|
|
|
for (const [name, ok] of cases) console.log(`${ok ? "✓" : "✗"} ${name}`);
|
|
console.log(`\n${pass}/${cases.length} passed`);
|
|
if (pass !== cases.length) process.exit(1);
|