mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 19:47:25 +01:00
Every dispatch this fleet sends opens with the operator's goals and
deadlines, under the instruction "align your priorities" — and on
2026-09-20 the two it listed were:
The operator's near-term commitments/deadlines (be mindful of these):
- Get a $50 signup bonus when you spend $100 within 30 days of getting
a new Coinbase One Card — due 2026-05-03
- You can unpause your project from the dashboard within 90 days. After
this period, the project cannot be restore — due 2026-07-03
Four and a half months and eleven weeks gone, handed to every agent on
every project as something to aim at. Filed as #584 on 2026-09-10 after
the same block reached Heidi; it has shipped in every dispatch since,
including the one that produced this commit.
Two separate defects, and the interesting one is not the label.
listUpcomingCommitments takes everything active due before now+14d with
no floor, which is deliberate and documented — "overdue included, those
are the most urgent" — but it then ordered by due_date ASC and capped at
8. Ascending order over a set that reaches backwards means the OLDEST
rows sort first and take the whole cap, so the least recoverable items
crowd out the ones still worth doing. "Soonest first" and "most urgent
first" read as the same sentence and are opposites here. Distance from
today is what urgent actually means, so that is what the ORDER BY says
now; verified against the live table, where it flips the two rows into
the right order.
The label is the half that changes today's prompt. Overdue rows still
belong in this block — a commitment someone missed is exactly what an
agent should know — they just have to arrive marked as missed:
- ... — was due 2026-07-03 (OVERDUE)
- Reduce Monthly Burn (40%) — target 2026-06-30 (PAST, not met)
and the heading no longer calls the list "near-term" while carrying rows
that are not.
isOverdue lands in lib/dates.ts as the one definition, deliberately not
`isPast`: that is instant-granular and would call a 09:00 deadline missed
by lunchtime. It compares PRINTED dates — the same toLocalDateStr the
block renders with — so the word and the date beside it cannot disagree,
which an instant boundary computed in a different timezone from the
formatter can and does.
The same predicate goes into the daily brief, whose entire premise is
handing the model settled answers instead of rows to filter. It asked
"commitments due inside 3 days" and described its own SQL as
`due_date <= now()+3d`, both true of the code and neither true of the
rows: overdue ones were in the answer, unlabelled. Its dateLabel also
printed a UTC day next to a word now decided on the local one, so both
now go through toLocalDateStr.
The format test moves out of the source file into scripts/test/, where
test-unit.ts actually globs it — as an inline `--self-test` nothing ever
ran it. Extended to pin the boundaries, built from local calendar parts
rather than UTC instants (green under UTC, Zurich, Kolkata, New York,
Kiritimati and Midway).
Not touched: getGoalsDueSoon and getEventsDueSoon share the missing
floor, but /today's GoalsDueCard and EventsDueCard render them and are
meant to show overdue items to the human. Their `method` strings now
state that honestly instead of being made to lie less.
verify: 214/214 unit tests, tsc clean, lint 0 errors (2 pre-existing
warnings).
Refs #584
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
164 lines
6.8 KiB
TypeScript
164 lines
6.8 KiB
TypeScript
/**
|
|
* The operator goals & deadlines block that prefixes every dispatch.
|
|
*
|
|
* These checks lived inside the source file as an inline `--self-test`, which
|
|
* nothing invoked: scripts/test-unit.ts globs THIS directory, so a check that
|
|
* sits anywhere else is coverage nobody runs. Moved here, where it does.
|
|
*
|
|
* The dates half exists because of #584: dispatches on 2026-09-20 announced
|
|
* "near-term commitments/deadlines" and then listed a bonus window that closed
|
|
* 2026-05-03 and a restore window that closed 2026-07-03 — the two OLDEST rows
|
|
* in the table, which had taken the whole cap because "soonest first" sorts
|
|
* ascending and overdue rows are deliberately in scope. Nothing threw; the
|
|
* prompt read as ordinary prose and told the agent to prioritise by it.
|
|
*
|
|
* Run: npx tsx scripts/test/operator-context-format.ts
|
|
*/
|
|
import {
|
|
formatOperatorContextBlock,
|
|
OPERATOR_CONTEXT_HEADING,
|
|
} from "@/lib/dispatch-operator-context-format";
|
|
import { isOverdue, toLocalDateStr } from "@/lib/dates";
|
|
|
|
let failures = 0;
|
|
function check(name: string, cond: boolean, detail = "") {
|
|
if (cond) {
|
|
console.log(` ✓ ${name}`);
|
|
} else {
|
|
failures++;
|
|
console.log(` ✗ ${name}${detail ? `\n ${detail}` : ""}`);
|
|
}
|
|
}
|
|
|
|
// A fixed "today" so every case below is a statement about the data, not about
|
|
// the day the suite happens to run.
|
|
const NOW = new Date("2026-09-20T12:00:00Z");
|
|
const PAST = new Date("2026-05-03T00:00:00Z");
|
|
const FUTURE = new Date("2026-09-30T00:00:00Z");
|
|
const TODAY = new Date("2026-09-20T23:00:00Z");
|
|
|
|
// ── layout ───────────────────────────────────────────────────────────────────
|
|
check("empty in ⇒ empty string", formatOperatorContextBlock([], [], NOW) === "");
|
|
|
|
const goalsOnly = formatOperatorContextBlock(
|
|
[{ title: "Ship paid tier", progress: 40, targetDate: FUTURE }],
|
|
[],
|
|
NOW,
|
|
);
|
|
check("goals header present", goalsOnly.includes("top-level goals"));
|
|
check("goal progress rendered", goalsOnly.includes("(40%)"));
|
|
check("goal target date rendered", goalsOnly.includes(`target ${toLocalDateStr(FUTURE)}`));
|
|
check("no commitments header when none", !goalsOnly.includes("commitments/deadlines"));
|
|
|
|
const commitsOnly = formatOperatorContextBlock(
|
|
[],
|
|
[{ description: "Investor demo", dueDate: FUTURE }],
|
|
NOW,
|
|
);
|
|
check("commitments header present", commitsOnly.includes("commitments/deadlines"));
|
|
check("commitment due rendered", commitsOnly.includes(`due ${toLocalDateStr(FUTURE)}`));
|
|
|
|
const nulls = formatOperatorContextBlock(
|
|
[{ title: "G", progress: null, targetDate: null }],
|
|
[{ description: "C", dueDate: null }],
|
|
NOW,
|
|
);
|
|
check("no progress % when null", !nulls.split("\n")[1].includes("%"));
|
|
check("no target when null goal date", !nulls.split("\n")[1].includes("target"));
|
|
check("blank line separates the two sections", nulls.includes("\n\n"));
|
|
|
|
// ── dates tell the truth (#584) ──────────────────────────────────────────────
|
|
const overdue = formatOperatorContextBlock(
|
|
[],
|
|
[{ description: "Coinbase card bonus", dueDate: PAST }],
|
|
NOW,
|
|
);
|
|
check("a past due date is marked OVERDUE", overdue.includes("(OVERDUE)"), overdue);
|
|
check("a past due date does not read as upcoming", !/ — due /.test(overdue), overdue);
|
|
check(
|
|
"the overdue row keeps its date",
|
|
overdue.includes(`was due ${toLocalDateStr(PAST)}`),
|
|
overdue,
|
|
);
|
|
|
|
const upcoming = formatOperatorContextBlock(
|
|
[],
|
|
[{ description: "Investor demo", dueDate: FUTURE }],
|
|
NOW,
|
|
);
|
|
check("a future due date is NOT marked overdue", !upcoming.includes("OVERDUE"), upcoming);
|
|
|
|
// Day granularity: something still due later today has not been missed.
|
|
const dueToday = formatOperatorContextBlock(
|
|
[],
|
|
[{ description: "Call the bank", dueDate: TODAY }],
|
|
NOW,
|
|
);
|
|
check("due later today is not overdue", !dueToday.includes("OVERDUE"), dueToday);
|
|
|
|
const pastGoal = formatOperatorContextBlock(
|
|
[{ title: "Reduce Monthly Burn", progress: 40, targetDate: PAST }],
|
|
[],
|
|
NOW,
|
|
);
|
|
check("a missed goal target says so", pastGoal.includes("(PAST, not met)"), pastGoal);
|
|
|
|
const futureGoal = formatOperatorContextBlock(
|
|
[{ title: "Ship paid tier", progress: 40, targetDate: FUTURE }],
|
|
[],
|
|
NOW,
|
|
);
|
|
check("a live goal target is left alone", !futureGoal.includes("PAST"), futureGoal);
|
|
|
|
// The heading is what the strip patterns in lib/activity-status.ts anchor on.
|
|
check(
|
|
"heading still frames the block as background",
|
|
OPERATOR_CONTEXT_HEADING.startsWith("## ") && OPERATOR_CONTEXT_HEADING.includes("background"),
|
|
);
|
|
|
|
// A row the operator never has to guess about: no bare date without a word.
|
|
const both = formatOperatorContextBlock(
|
|
[{ title: "G", progress: null, targetDate: PAST }],
|
|
[
|
|
{ description: "old", dueDate: PAST },
|
|
{ description: "new", dueDate: FUTURE },
|
|
],
|
|
NOW,
|
|
);
|
|
for (const line of both
|
|
.split("\n")
|
|
.filter((l) => l.startsWith("- ") && /\d{4}-\d{2}-\d{2}/.test(l))) {
|
|
check(
|
|
`dated row states whether it has passed: ${line.slice(0, 48)}`,
|
|
/OVERDUE|PAST, not met|— due /.test(line),
|
|
line,
|
|
);
|
|
}
|
|
|
|
// ── the predicate itself ─────────────────────────────────────────────────────
|
|
// Day boundaries, because that is the only place this can be wrong: a due date
|
|
// is obviously past or obviously ahead everywhere else.
|
|
// Built from LOCAL calendar parts, not UTC instants: the predicate answers a
|
|
// question about calendar days, so a case written as "2026-09-19T23:59:59Z" is
|
|
// asking about a different day in half the world's timezones (it is already
|
|
// the 20th in Zurich) and would fail for being right.
|
|
const localDay = (y: number, m: number, d: number, h = 12) => new Date(y, m - 1, d, h);
|
|
const TODAY_NOON = localDay(2026, 9, 20);
|
|
check("yesterday is overdue", isOverdue(localDay(2026, 9, 19, 23), TODAY_NOON));
|
|
check("today at midnight is NOT overdue", !isOverdue(localDay(2026, 9, 20, 0), TODAY_NOON));
|
|
check("today at 23:59 is NOT overdue", !isOverdue(localDay(2026, 9, 20, 23), TODAY_NOON));
|
|
check("tomorrow is NOT overdue", !isOverdue(localDay(2026, 9, 21, 0), TODAY_NOON));
|
|
check("no date is not overdue", !isOverdue(null, NOW) && !isOverdue(undefined, NOW));
|
|
check("an unparseable date is not overdue", !isOverdue("not a date", NOW));
|
|
check("accepts an ISO string", isOverdue("2026-05-03T00:00:00Z", NOW));
|
|
// The invariant the whole fix rests on: the word never contradicts the date
|
|
// printed beside it.
|
|
check(
|
|
"overdue ⇔ the printed date is before today's printed date",
|
|
isOverdue(PAST, NOW) === toLocalDateStr(PAST) < toLocalDateStr(NOW) &&
|
|
isOverdue(FUTURE, NOW) === toLocalDateStr(FUTURE) < toLocalDateStr(NOW),
|
|
);
|
|
|
|
console.log(failures === 0 ? "\n✓ operator context format" : `\n✗ ${failures} failed`);
|
|
process.exit(failures ? 1 : 0);
|