Files
loki/scripts/test/widget-saved-notes.ts
CatoandClaude Opus 5.5 44def109a9 feat(widget): a spoken walk read as a list, whole sentences, talk from the launcher, per-page builds (#1302)
* feat(widget): one Talk bar, status header, read-back, per-page builds

- One Talk to Loki bar above a one-line message box; the box shows its
  tools only once used. The second Talk button in the thread is gone.
- The owner's header is the status (Watching / 2 to look at), Pause, close:
  no second logo, no page line. Opening on a phone no longer raises the
  keyboard.
- A spoken note is read back as a list per part of the page, with Read it
  back (speech) and Edit.
- Build all starts saved notes as one build per page (dispatchFeedbackBatch,
  shared with the project batch route).
- Regex literals use \u escapes; a test fails on non-ASCII in the bundle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E1qoQ9syUYXCRNbyrpqPGa

* feat(widget): a walk read as a list, whole sentences, talk from the launcher

- Loki's read of a spoken note is a list: one change or question per line,
  with where it applies, editable, ✕ to drop. The part on screen is
  background; a line names a part only when it was pointed at.
- Save files each change as its own note, with only the moments it came
  from, on the page it was said on. Questions stay on the card for Ask.
- Whisper's segments are joined into whole sentences before they are placed
  under a heading, so a sentence is never cut across two parts.
- The owner can start talking from a microphone beside the launcher without
  opening the panel (widget/quick-talk.ts).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E1qoQ9syUYXCRNbyrpqPGa

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-18 10:34:38 +02:00

74 lines
2.5 KiB
TypeScript

// "Build them": which saved notes one tap starts.
// Run: npx tsx scripts/test/widget-saved-notes.ts
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import {
groupNotesByPage,
notePage,
SAVED_NOTES_BUILD_MAX,
savedNotesToBuild,
} from "../../src/lib/feedback/saved-notes";
import { FEEDBACK_WORK_PHASE } from "../../src/lib/feedback/work-phase";
const note = (id: string, over: Partial<Parameters<typeof savedNotesToBuild>[0][number]> = {}) => ({
id,
source: "owner" as string | null,
requiresReview: true,
createdAt: new Date(Number(id.replace(/\D/g, "")) * 1000),
work: {
phase:
FEEDBACK_WORK_PHASE.NOT_STARTED as (typeof FEEDBACK_WORK_PHASE)[keyof typeof FEEDBACK_WORK_PHASE],
},
...over,
});
const picked = savedNotesToBuild([
note("n3"),
note("n1"),
note("n2", { requiresReview: false }),
note("n4", { source: "visitor" }),
note("n5", { work: { phase: FEEDBACK_WORK_PHASE.QUEUED } }),
note("n6", { source: null }),
]);
assert.deepEqual(
picked.map((n) => n.id),
["n1", "n3"],
"the owner's saved notes that have not started, oldest first",
);
assert.equal(
savedNotesToBuild(Array.from({ length: 25 }, (_, i) => note(`n${i + 1}`))).length,
SAVED_NOTES_BUILD_MAX,
"one tap starts a bounded number",
);
// Group by page: one build per page, in the order the pages were first spoken about.
{
const at = (id: string, page: string | null, url: string | null = null) => ({ id, page, url });
const groups = groupNotesByPage([
at("a", "/pricing"),
at("b", "/"),
at("c", "/pricing"),
at("d", null, "https://site.ch/pricing?x=1"),
at("e", null, "not a url"),
]);
assert.deepEqual(
groups.map((g) => g.map((n) => n.id)),
[["a", "c", "d"], ["b"], ["e"]],
"a note without a page joins its URL's page",
);
assert.equal(notePage({ page: " /about " }), "/about");
assert.equal(notePage({}), "");
}
// The route builds per page: one lone build, or one batch for several.
{
const route = readFileSync("src/app/api/widget/owner/build/route.ts", "utf8");
assert.match(route, /groupNotesByPage\(notes\)/);
assert.match(route, /group\.length === 1\s*\?\s*await startOwnerBuild/);
assert.match(route, /startOwnerBatchBuild\(token\.userId, token\.projectId, group\)/);
// …and the inbox's "Implement all as one" uses the same batch dispatch.
assert.match(
readFileSync("src/app/api/projects/[id]/feedback/dispatch-batch/route.ts", "utf8"),
/dispatchFeedbackBatch\(/,
);
}
console.log("✓ widget-saved-notes: ok");