xonecas.io
64875
Mc

mini-coder / commit fb8c98d

fix: tag todo reminders as system reminders

xonecas2026-04-17 fb8c98d7e310e899eccba52c1c7e0550518dc79d parent ce6cb0f

3 files changed

spec.md+1−1
@@ -244,7 +244,7 @@ The core runtime. Streaming is the default behavior throughout the turn: user-vi
244244 - After all tool results are appended, if queued steering messages exist go to step 6; otherwise loop back to step 2 (re-stream with the updated context).
245245
246246 5. **Todo reminders** — when the assistant tries to stop while incomplete todo items still exist:
247- - Inject a model-visible reminder listing the current `pending` and `in_progress` items, then loop back to step 2.
247+ - Inject a model-visible reminder listing the current `pending` and `in_progress` items as a synthetic user message whose content is wrapped in `<system_reminder>...</system_reminder>`, then loop back to step 2.
248248 - Reminders are ephemeral: they are included in model context for the follow-up request but are not rendered in the conversation pane and are not persisted to the session DB.
249249 - If the exact same incomplete-todo set was already reminded during the current run, do not inject a duplicate reminder. In that case the turn ends normally instead of looping forever.
250250
src/agent.test.ts+96−0
@@ -5,6 +5,7 @@ import { tmpdir } from "node:os";
55 import { join } from "node:path";
66 import type {
77 AssistantMessage,
8+ Context,
89 Message,
910 Model,
1011 Tool,
@@ -1596,6 +1597,101 @@ describe("agent loop", () => {
15961597 ]);
15971598 });
15981599
1600+ test("wraps injected todo reminders in a system_reminder block", async () => {
1601+ const api = "todo-reminder-tag-test";
1602+ const sourceId = "todo-reminder-tag-test-source";
1603+ const model: Model<string> = {
1604+ id: "todo-reminder-tag-model",
1605+ name: "Todo Reminder Tag Model",
1606+ api,
1607+ provider: "test",
1608+ baseUrl: "http://localhost:0",
1609+ reasoning: false,
1610+ input: ["text"],
1611+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
1612+ contextWindow: 128000,
1613+ maxTokens: 4096,
1614+ };
1615+ const requestMessages: Message[][] = [];
1616+ let callCount = 0;
1617+
1618+ const buildProviderStream = (context: Context) => {
1619+ requestMessages.push(structuredClone(context.messages));
1620+ const stream = createAssistantMessageEventStream();
1621+ const finalMessage = fauxAssistantMessage(
1622+ callCount === 0 ? "All done." : "I still need to keep working.",
1623+ );
1624+ callCount += 1;
1625+
1626+ queueMicrotask(() => {
1627+ stream.push({
1628+ type: "done",
1629+ reason: "stop",
1630+ message: finalMessage,
1631+ });
1632+ stream.end(finalMessage);
1633+ });
1634+
1635+ return stream;
1636+ };
1637+
1638+ registerApiProvider(
1639+ {
1640+ api,
1641+ stream: (_model, context) => buildProviderStream(context),
1642+ streamSimple: (_model, context) => buildProviderStream(context),
1643+ },
1644+ sourceId,
1645+ );
1646+
1647+ try {
1648+ const session = createSession(db, { cwd: tmp });
1649+ const userMsg = makeUser("finish the task");
1650+ const turn = appendMessage(db, session.id, userMsg);
1651+ const messages: Message[] = [
1652+ makeTodoSnapshotMessage([
1653+ { content: "Run the test suite", status: "pending" },
1654+ { content: "Summarize the verified changes", status: "in_progress" },
1655+ ]),
1656+ userMsg,
1657+ ];
1658+
1659+ const result = await runAgentLoop({
1660+ db,
1661+ sessionId: session.id,
1662+ turn,
1663+ model,
1664+ systemPrompt: "Test",
1665+ tools: builtinToolDefs(),
1666+ toolHandlers: builtinToolHandlers(messages),
1667+ messages,
1668+ cwd: tmp,
1669+ });
1670+
1671+ expect(result.stopReason).toBe("stop");
1672+ expect(requestMessages).toHaveLength(2);
1673+ const reminder = requestMessages[1]?.at(-1);
1674+ if (!reminder || reminder.role !== "user") {
1675+ throw new Error("Expected the injected reminder to be a user message");
1676+ }
1677+ if (typeof reminder.content !== "string") {
1678+ throw new Error("Expected the injected reminder content to be text");
1679+ }
1680+
1681+ expect(reminder.content).toStartWith("<system_reminder>\n");
1682+ expect(reminder.content).toEndWith("\n</system_reminder>");
1683+ expect(reminder.content).toContain(
1684+ "You have pending todo items that must be completed before finishing the task:",
1685+ );
1686+ expect(reminder.content).toContain("- [PENDING] Run the test suite");
1687+ expect(reminder.content).toContain(
1688+ "- [IN_PROGRESS] Summarize the verified changes",
1689+ );
1690+ } finally {
1691+ unregisterApiProviders(sourceId);
1692+ }
1693+ });
1694+
15991695 test("does not inject duplicate todo reminders for the same pending set", async () => {
16001696 faux.setResponses([
16011697 fauxAssistantMessage("All done."),
src/agent.ts+5−1
@@ -623,6 +623,10 @@ function getTodoReminderSignature(
623623 );
624624 }
625625
626+function wrapSystemReminder(content: string): string {
627+ return `<system_reminder>\n${content}\n</system_reminder>`;
628+}
629+
626630 function createTodoReminderMessage(
627631 messages: readonly Message[],
628632 remindedTodoSignatures: Set<string>,
@@ -651,7 +655,7 @@ function createTodoReminderMessage(
651655
652656 return {
653657 role: "user",
654- content: lines.join("\n"),
658+ content: wrapSystemReminder(lines.join("\n")),
655659 timestamp: Date.now(),
656660 };
657661 }