Public Beta
Not set

Experience

Changes how pages explain things, never what you can do.

More

Experience

Changes how pages explain things, never what you can do.

Sign inGet started

Personal Productivity v0.1.2 · generic

Archive SHA-256 a60f0d4435477cdd1283b89508dd4fecd555b4e30577796e13eebf8ab7f717ec · 37.8 KB · built Nov 27, 2026

tests/personal-productivity.test.ts

import { describe, it, expect, vi } from "vitest";
// @ts-expect-error -- plain JavaScript agent module without type declarations
import agentModule, { handleMcpMessage, makeContext, manifest, validateManifest } from "../src/index.js";

const agent: any = agentModule;
const now = () => new Date("2026-11-25T12:00:00Z");

const TASKS = [
  "# Work",
  "- [ ] Write Q4 report due:2026-11-26 !high ~90m #work",
  "- [ ] Book flights @due(2026-11-27) ~20m",
  "  - [ ] Check passport",
  "- [x] Send invoice done:2026-11-24",
  "- [ ] Learn Rust !high",
  "- [ ] Tidy desk",
  "- [ ] (B) Call bank #urgent ~15m",
  "* [ ] Refactor auth priority:low due:2026-12-20 ~2h #waiting",
  "- [ ] Bad date due:2026-02-30",
  "",
  "## Personal",
  "1. [ ] Renew domain due:2026-11-20 [#A] est:10m",
  "- [-] Old idea",
  "```",
  "- [ ] not a task inside a code fence",
  "```",
].join("\n");

const byTitle = (list: any[], title: string) => list.find((t: any) => t.title === title);

describe("personal-productivity: manifest", () => {
  it("passes validateManifest and is fully offline", async () => {
    expect(validateManifest(manifest)).toEqual([]);
    expect(manifest.id).toBe("agentrove.personal-productivity");
    expect(manifest.permissions).toMatchObject({ filesystem: "none", network: [], credentials: [] });
    expect(manifest.tools.every((t: any) => t.side_effects === "none")).toBe(true);
    expect(manifest.io.inputs.find((p: any) => p.name === "slots").type).toBe("time_slots");
    const fetch = vi.fn();
    await expect(makeContext(manifest, { fetch }).fetch("https://example.com/")).rejects.toMatchObject({ code: "network_denied" });
    expect(fetch).not.toHaveBeenCalled();
  });
});

describe("personal-productivity: parse_tasks", () => {
  it("parses checkboxes, tags, sections, subtasks and skips code fences", async () => {
    const out = await agent.call("parse_tasks", { markdown: TASKS, today: "2026-11-25" });
    expect(out.counts).toEqual({ total: 11, open: 9, done: 2 });
    const report = byTitle(out.tasks, "Write Q4 report");
    expect(report).toMatchObject({ id: "L2", due: "2026-11-26", priority: "high", effort_minutes: 90, tags: ["work"], section: "Work", done: false });
    expect(byTitle(out.tasks, "Check passport").parent_id).toBe("L3");
    expect(byTitle(out.tasks, "Send invoice")).toMatchObject({ done: true, done_date: "2026-11-24" });
    expect(byTitle(out.tasks, "Call bank")).toMatchObject({ priority: "medium", urgent: true, effort_minutes: 15 });
    expect(byTitle(out.tasks, "Refactor auth")).toMatchObject({ priority: "low", due: "2026-12-20", effort_minutes: 120, waiting: true });
    expect(byTitle(out.tasks, "Renew domain")).toMatchObject({ priority: "high", due: "2026-11-20", effort_minutes: 10, section: "Personal" });
    expect(byTitle(out.tasks, "Old idea")).toMatchObject({ done: true, tags: ["cancelled"] });
    expect(byTitle(out.tasks, "Bad date").due).toBeNull();
    expect(out.warnings.join(" ")).toMatch(/line 10: "2026-02-30" is not a real calendar date/);
    expect(out.tasks.some((t: any) => t.title.includes("code fence"))).toBe(false);
  });

  it("understands Obsidian Tasks emoji, relative dates and duration forms", async () => {
    const md = ["- [ ] Pay rent \u{1F4C5} 2026-11-30 \u23eb", "- [ ] Stretch due:today ~1h30m", "- [ ] Plan trip due:tomorrow ~1.5h \u{1F53D}", "- [ ] Too long ~99999h"].join("\n");
    const out = await agent.call("parse_tasks", { markdown: md, timezone: "Pacific/Auckland" }, { now });
    // 2026-11-25T12:00Z is already 2026-11-26 in Auckland.
    expect(out.tasks.map((t: any) => [t.title, t.due, t.priority, t.effort_minutes])).toEqual([
      ["Pay rent", "2026-11-30", "high", null],
      ["Stretch", "2026-11-26", null, 90],
      ["Plan trip", "2026-11-27", "low", 90],
      ["Too long", null, null, null],
    ]);
    expect(out.warnings.join(" ")).toMatch(/out of range/);
  });

  it("rejects invalid input", async () => {
    await expect(agent.call("parse_tasks", {})).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("parse_tasks", { markdown: "- [ ] a", timezone: "Nowhere/Land" })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("parse_tasks", { markdown: "- [ ] a", today: "2026-13-01" })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("classify_eisenhower", { markdown: "- [ ] a", tasks: [] })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("classify_eisenhower", { tasks: [{ id: "a", title: "x" }, { id: "a", title: "y" }] })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("classify_eisenhower", { tasks: [{ id: "a", title: "x", due: "soon" }] })).rejects.toMatchObject({ code: "invalid_input" });
    const empty = await agent.call("parse_tasks", { markdown: "just prose" }, { now });
    expect(empty.warnings[0]).toMatch(/No Markdown checkboxes/);
  });
});

describe("personal-productivity: classify_eisenhower", () => {
  it("places tasks in quadrants with reasons and leaves signal-free tasks unsorted", async () => {
    const out = await agent.call("classify_eisenhower", { markdown: TASKS, today: "2026-11-25" });
    const ids = (q: string) => out.quadrants[q].map((t: any) => t.title);
    expect(ids("do")).toEqual(["Renew domain", "Write Q4 report"]);
    // Refactor auth has priority low but a real due date: it is scheduled, never "eliminated".
    expect(ids("schedule")).toEqual(["Refactor auth", "Learn Rust"]);
    expect(byTitle(out.quadrants.schedule, "Refactor auth").reasons.join("; ")).toMatch(/has a due date \(2026-12-20\), so it is scheduled before then instead of eliminated/);
    expect(ids("delegate")).toEqual(["Book flights", "Call bank"]);
    expect(ids("eliminate")).toEqual([]);
    expect(ids("unsorted")).toEqual(["Check passport", "Tidy desk", "Bad date"]);
    expect(out.quadrants.do[0].reasons).toEqual(["overdue by 5 day(s) (due 2026-11-20)", "priority high"]);
    expect(out.quadrants.delegate[0].reasons.join("; ")).toMatch(/no priority: treated as not important/);
    expect(byTitle(out.quadrants.schedule, "Learn Rust").effort_minutes).toBeNull();
    expect(out.counts).toEqual({ do: 2, schedule: 2, delegate: 2, eliminate: 0, unsorted: 3 });
    expect(out.markdown).toContain("## Do first (urgent and important)");
    expect(out.notes.join(" ")).toMatch(/have no effort estimate; none was invented/);
    const wide = await agent.call("classify_eisenhower", { markdown: TASKS, today: "2026-11-25", urgent_within_days: 0, important_priorities: ["high", "medium"] });
    expect(wide.quadrants.do.map((t: any) => t.title)).toEqual(["Renew domain", "Call bank"]);
    expect(wide.quadrants.schedule.map((t: any) => t.title)).toEqual(["Write Q4 report", "Book flights", "Refactor auth", "Learn Rust"]);
  });

  it("accepts structured tasks (parse_tasks output) as input", async () => {
    const out = await agent.call("classify_eisenhower", { tasks: [{ id: "a", title: "Ship", due: "2026-11-25", important: true }, { id: "b", title: "Read", priority: "low" }], today: "2026-11-25" });
    expect(out.quadrants.do[0]).toMatchObject({ id: "a", reasons: ["due today (2026-11-25)", "tagged important"] });
    expect(out.quadrants.eliminate[0].id).toBe("b");
  });
});

describe("personal-productivity: plan_time_blocks", () => {
  const slots = [
    { start: "2026-11-26T09:00:00Z", end: "2026-11-26T10:00:00Z", local_start: "2026-11-26T09:00+00:00" },
    { start: "2026-11-26T13:00:00Z", end: "2026-11-26T15:00:00Z" },
  ];

  it("blocks do/schedule tasks into calendar-assistant slots using only written effort", async () => {
    const out = await agent.call("plan_time_blocks", { markdown: TASKS, slots, timezone: "Europe/London", today: "2026-11-25" }, { now });
    expect(out.blocks.map((b: any) => [b.title, b.start, b.end])).toEqual([
      ["Renew domain", "2026-11-26T09:00:00Z", "2026-11-26T09:10:00Z"],
      ["Write Q4 report", "2026-11-26T13:00:00Z", "2026-11-26T14:30:00Z"],
    ]);
    expect(out.at_risk).toEqual([{ task_id: "L13", title: "Renew domain", reason: "Already overdue (due 2026-11-20)." }]);
    expect(byTitle(out.unscheduled.map((u: any) => ({ ...u, title: u.title })), "Learn Rust").reason).toMatch(/No effort estimate/);
    expect(byTitle(out.unscheduled, "Book flights").reason).toMatch(/Delegate quadrant/);
    expect(out.summary).toEqual({ available_minutes: 180, planned_minutes: 100, tasks_planned: 2 });
    expect(out.remaining_slots).toEqual([
      { start: "2026-11-26T09:10:00Z", end: "2026-11-26T10:00:00Z" },
      { start: "2026-11-26T14:30:00Z", end: "2026-11-26T15:00:00Z" },
    ]);
    expect(out.events[1]).toMatchObject({ summary: "Focus: Write Q4 report", start: "2026-11-26T13:00:00Z", timezone: "Europe/London" });
    expect(out.events[1].uid).toMatch(/@agentrove\.personal-productivity$/);
    expect(out.warnings.join(" ")).toMatch(/Nothing was added to any calendar/);
  });

  it("fills leftover free time with dated and estimated unsorted tasks by default, never with guessed effort", async () => {
    // Runtime finding: only the 30-minute do-first task was planned in ~5.5 free hours.
    const md = [
      "- [ ] Send board update due:2026-12-01 !high ~30m",
      "- [ ] Draft blog outline ~90m",
      "- [ ] Renew domain due:2026-12-15 ~10m",
      "- [ ] Tidy desk",
      "- [ ] Chase vendor quote #waiting due:2026-12-02 !high ~20m",
    ].join("\n");
    const free = [{ start: "2026-12-01T09:00:00Z", end: "2026-12-01T12:00:00Z" }, { start: "2026-12-01T13:00:00Z", end: "2026-12-01T15:30:00Z" }];
    const out = await agent.call("plan_time_blocks", { markdown: md, slots: free, timezone: "UTC", today: "2026-12-01" }, { now: () => new Date("2026-12-01T08:00:00Z") });
    expect(out.blocks.map((b: any) => [b.title, b.quadrant, b.start, b.end])).toEqual([
      ["Send board update", "do", "2026-12-01T09:00:00Z", "2026-12-01T09:30:00Z"],
      ["Renew domain", "schedule", "2026-12-01T09:30:00Z", "2026-12-01T09:40:00Z"],
      ["Draft blog outline", "unsorted", "2026-12-01T09:40:00Z", "2026-12-01T11:10:00Z"],
    ]);
    expect(byTitle(out.unscheduled, "Tidy desk").reason).toMatch(/no effort estimate.*None was invented/);
    expect(byTitle(out.unscheduled, "Chase vendor quote").reason).toMatch(/Tagged waiting\/delegate/);
    expect(out.warnings.join(" ")).toMatch(/1 unsorted task\(s\) with a written effort estimate were used to fill free time/);
    // An explicit include_quadrants list is followed exactly (no fill).
    const only = await agent.call("plan_time_blocks", { markdown: md, slots: free, timezone: "UTC", today: "2026-12-01", include_quadrants: ["do"] }, { now: () => new Date("2026-12-01T08:00:00Z") });
    expect(only.blocks.map((b: any) => b.title)).toEqual(["Send board update"]);
    expect(byTitle(only.unscheduled, "Draft blog outline").reason).toMatch(/not included \(include_quadrants\)/);
  });

  it("splits long tasks across slots, honours breaks and default_block_minutes, and flags due-date risk", async () => {
    const md = "- [ ] Deep work due:2026-11-26 !high ~150m\n- [ ] Inbox !high\n- [ ] Huge !high ~10h";
    const out = await agent.call("plan_time_blocks", { markdown: md, slots, timezone: "UTC", today: "2026-11-25", default_block_minutes: 30, break_minutes: 5 }, { now });
    expect(out.blocks.map((b: any) => [b.title, b.start, b.end, b.part, b.parts])).toEqual([
      ["Deep work", "2026-11-26T09:00:00Z", "2026-11-26T10:00:00Z", 1, 2],
      ["Deep work", "2026-11-26T13:00:00Z", "2026-11-26T14:30:00Z", 2, 2],
    ]);
    expect(out.events[0].summary).toBe("Focus: Deep work (part 1/2)");
    // After the 5-minute break only 14:35-15:00 (25 min) is left: too little for Inbox's 30-minute default block.
    expect(byTitle(out.unscheduled, "Inbox").reason).toMatch(/Not enough free time: needs 30 min.*25 min of free time left/);
    expect(byTitle(out.unscheduled, "Huge").reason).toMatch(/needs 600 min/);
    expect(out.remaining_slots).toEqual([{ start: "2026-11-26T14:35:00Z", end: "2026-11-26T15:00:00Z" }]);
    const strict = await agent.call("plan_time_blocks", { markdown: "- [ ] Deep work !high ~150m", slots, today: "2026-11-25", allow_split: false }, { now });
    expect(strict.unscheduled[0].reason).toMatch(/allow_split is false/);
    const late = await agent.call("plan_time_blocks", { markdown: "- [ ] Late !high due:2026-11-25 ~30m", slots, today: "2026-11-25" }, { now });
    expect(late.at_risk[0].reason).toMatch(/after its due date 2026-11-25/);
  });

  it("builds free time from working hours minus busy time across the US DST change", async () => {
    const md = "- [ ] Big !high ~120m\n- [ ] Next !high ~60m";
    const out = await agent.call(
      "plan_time_blocks",
      { markdown: md, working_hours: { timezone: "America/New_York", start: "09:00", end: "12:00", days: ["MO", "FR"] }, date_from: "2027-03-12", date_to: "2027-03-15", busy: [{ start: "2027-03-12T14:00:00Z", end: "2027-03-12T15:00:00Z" }], today: "2027-03-11" },
      { now },
    );
    expect(out.timezone).toBe("America/New_York");
    expect(out.blocks.map((b: any) => [b.title, b.start, b.end, b.local_start])).toEqual([
      ["Big", "2027-03-12T15:00:00Z", "2027-03-12T17:00:00Z", "2027-03-12T10:00-05:00"],
      ["Next", "2027-03-15T13:00:00Z", "2027-03-15T14:00:00Z", "2027-03-15T09:00-04:00"],
    ]);
    expect(out.summary.available_minutes).toBe(300);
  });

  it("validates time inputs", async () => {
    await expect(agent.call("plan_time_blocks", { markdown: "- [ ] a ~5m !high" }, { now })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("plan_time_blocks", { markdown: "- [ ] a", slots: [{ start: "2026-11-26T09:00", end: "2026-11-26T10:00" }] }, { now })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("plan_time_blocks", { markdown: "- [ ] a", slots: [{ start: "2026-11-26T10:00:00Z", end: "2026-11-26T09:00:00Z" }] }, { now })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("plan_time_blocks", { markdown: "- [ ] a", working_hours: { timezone: "UTC", start: "09:00", end: "17:00" }, date_from: "2027-01-01", date_to: "2027-03-01" }, { now })).rejects.toMatchObject({ code: "invalid_input" });
    await expect(agent.call("plan_time_blocks", { markdown: "- [ ] a", slots: [], working_hours: { timezone: "UTC", start: "09:00", end: "17:00" } }, { now })).rejects.toMatchObject({ code: "invalid_input" });
    const past = await agent.call("plan_time_blocks", { markdown: "- [ ] a !high ~30m", slots: [{ start: "2026-01-01T09:00:00Z", end: "2026-01-01T10:00:00Z" }] }, { now });
    expect(past.blocks).toEqual([]);
    expect(past.warnings.join(" ")).toMatch(/No free time/);
  });
});

describe("personal-productivity: review_checklist", () => {
  it("builds a daily checklist and escapes task titles", async () => {
    const md = `${TASKS}\n- [ ] <img src=x onerror=alert(1)> [click](javascript:x) due:2026-11-25 !high`;
    const out = await agent.call("review_checklist", { markdown: md, kind: "daily", today: "2026-11-25" });
    const titles = out.sections.map((s: any) => s.title);
    expect(titles).toEqual(["Overdue", "Due today", "Do first (urgent and important)", "Inbox: unsorted tasks to clarify", "Daily prompts"]);
    expect(out.sections[0].items[0]).toMatch(/^Renew domain/);
    expect(out.markdown).toContain("# Daily review: 2026-11-25");
    expect(out.markdown).not.toContain("<img");
    expect(out.markdown).toContain("&lt;img src=x onerror=alert(1)&gt; \\[click\\](javascript:x)");
    expect(out.markdown.split("\n").filter((l: string) => l.startsWith("- [ ] ")).length).toBeGreaterThan(8);
  });

  it("builds a weekly checklist with completed, waiting and undated high-priority sections", async () => {
    const out = await agent.call("review_checklist", { markdown: TASKS, kind: "weekly", today: "2026-11-25" });
    const s = Object.fromEntries(out.sections.map((x: any) => [x.title, x]));
    expect(s["Completed in the last 7 days"].items).toEqual(["Send invoice"]);
    expect(out.markdown).toContain("- [x] Send invoice");
    // "- [-] Old idea" is cancelled, not done, so it is not reported as undated completed work.
    expect(s["Done without a completion date"]).toBeUndefined();
    expect(s["Waiting for / delegated"].items.map((i: string) => i.split(" (")[0])).toEqual(["Refactor auth"]);
    expect(s["Delegate candidates (urgent, not important)"].items.map((i: string) => i.split(" (")[0])).toEqual(["Book flights", "Call bank"]);
    const undated = await agent.call("review_checklist", { markdown: "- [x] Filed taxes\n- [-] Dropped plan", kind: "weekly", today: "2026-11-25" });
    expect(undated.sections.find((x: any) => x.title === "Done without a completion date").total).toBe(1);
    expect(s["High priority without a due date (give it a date)"].items).toEqual(["Learn Rust (priority high)"]);
    expect(s["Due in the next 7 days"].items.map((i: string) => i.split(" (")[0])).toEqual(["Write Q4 report", "Book flights"]);
    expect(s["Weekly prompts"].items.length).toBe(8);
  });
});

describe("personal-productivity: MCP", () => {
  it("lists and calls tools over JSON-RPC", async () => {
    const list = await handleMcpMessage(agent, { jsonrpc: "2.0", id: 1, method: "tools/list" });
    expect(list.result.tools.map((t: any) => t.name)).toEqual(["parse_tasks", "classify_eisenhower", "plan_time_blocks", "review_checklist"]);
    const call = await handleMcpMessage(agent, { jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: "classify_eisenhower", arguments: { markdown: TASKS, today: "2026-11-25" } } });
    expect(call.result.isError).toBe(false);
    expect(call.result.structuredContent.counts.do).toBe(2);
    const bad = await handleMcpMessage(agent, { jsonrpc: "2.0", id: 3, method: "tools/call", params: { name: "review_checklist", arguments: { markdown: TASKS, kind: "monthly" } } });
    expect(bad.result.isError).toBe(true);
    expect(bad.result.content[0].text).toMatch(/^invalid_input: /);
  });
});

Find an agent

Do not include passwords, keys, customer data or other confidential details.
Rule-based matching is free during the public beta (fair use).