Skip to content

✨ feat(bots): resolve and show Bot icons from their rules (#692) - #347

Merged
notFrost merged 4 commits into
feat/bot-icon-timelinefrom
feat/bot-icon-timeline-display
Dec 1, 2026
Merged

notFrost merged 4 commits into
feat/bot-icon-timelinefrom
feat/bot-icon-timeline-display

Conversation

@notFrost

@notFrost notFrost commented Dec 1, 2026

Copy link
Copy Markdown

Part of https://github.com/notFrost/sophie/issues/692 (phase 3, display). Stacked on feat/bot-icon-timeline-server.

Problem

A Bot's icon rules (image timelines and rule shapes) exist in the contract, but nothing on the client turns them into the icon you see.

Change

  • Evaluator (client-runtime/botIconRules.ts): resolveBotIcon picks a timeline image, a rule shape or the Default Icon, and returns nextChangeAtMs, the next moment the result can change. It's pure and walks the Bot's own order. Short or empty stored orders work.
    • botIconInputs turns the roster entry and the Bot thread's shell into each rule's minute 0.
    • botLeftForYouSinceMs and isUnreadSinceVisit compute the unread check. hasUnreadResult in the Bot list now uses the same check, so the icon and the list always agree.
  • Duration helpers (botIconDuration.ts): parse 15m, 16h or 2d and format back. Nothing uses them yet; they are for the editor in phase 4.
  • Roster: workingSince, deliveredAt and erroredAt now reach ScopedBotEntry. BotsIndex exposes botByKey.
  • Web BotAvatar: when it knows the Bot (owner), it shows the rule's glyph in the one slot (D6).
    • It reads a narrow per-Bot atom (botIconStateAtom) that holds through changes that leave the rules and start times alone.
    • It re-resolves once at nextChangeAtMs through useNowAfter, converting server clock to client clock. There is no tick.
    • It prefetches the upcoming timeline image (upcomingBotIconImage), and a stored image stays up until the next one has loaded.
    • Muted Bots keep the Default Icon and get grayscale on top of opacity-70 (D29).
    • A new defaultIconOnly prop keeps the Default Icon in the Profile preview and the identity picker.

Scope

  • lastCalled reads the quiet shell's updatedAt, which can lag by up to one run while the Bot streams.
  • Out of scope: editor UI (phase 4), mobile, contracts and server.
    • The only mobile change is a test fixture, which now needs the three roster fields.
  • Until stage 2 the server sends the roster timestamps as null and doesn't store iconRules. So workDuration and leftOnDelivered (from deliveries and errors) can't apply yet, and no Bot has rules yet.
  • This worktree sits inside another repo, so vp lint found the wrong oxlint up the tree. A local junction to the worktree's pinned oxlint fixed it; the junction is not committed.

Verification

$ vp run typecheck (repo root)
vp run: 44/44 cache hit (100%), 44/44 successful
exit=0
$ vp test run (client-runtime) src/botIconRules.test.ts src/botIconDuration.test.ts src/state/bots.test.ts src/botForm.test.ts src/botAvatarShapeIds.test.ts
 Test Files  5 passed (5)
      Tests  85 passed (85)
$ vp test run (web) src/components/bots/BotAvatar.browser.test.tsx src/components/bots/BotDetailsPanel.browser.test.tsx src/components/bots/sidebarMode.logic.test.ts src/components/bots/botAvatarPaint.test.ts
 Test Files  4 passed (4)
      Tests  16 passed (16)
$ vp test run (mobile) src/features/threads/use-composer-command-menu.select.test.tsx
 Test Files  1 passed (1)
      Tests  3 passed (3)
$ vp lint --report-unused-disable-directives <13 changed files>
exit=0
$ vp run knip:check
exit=0

The browser tests ran with NODE_ENV unset, because this shell exports NODE_ENV=production and React's production build has no act.

Desktop run: skipped. The base branch's BotStore has no iconRules column, and BotService.update keeps the stored value. So neither an API call nor SQL against an isolated database can give a Bot rules without server changes. Until stage 2, BotAvatar.browser.test.tsx covers the integrated behaviour:

  • with fake timers, a lastCalled timeline at 0m and 1m shows the first image, then swaps exactly at the minute, with one timer and no tick;
  • a rule shape replaces a shape Default Icon;
  • muted and defaultIconOnly keep the Default Icon, with grayscale when muted.

Model: Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code

notFrost and others added 4 commits November 30, 2026 23:28
Add resolveBotIcon, a pure evaluator that picks a Bot's timeline image or
rule shape from its icon rules, with the next moment the result can change,
and botLeftForYouSinceMs for the leftOnDelivered minute 0. Add the start
time parser and short formatter for the editor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A thread never visited now counts as read for leftOnDelivered, through the
same unread check the Bot list uses. resolveBotIcon no longer takes the
Bot's status, since each rule's start time already says whether it applies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed time (pingdotgg#692)

A stored rule order can hold fewer than three rules, or none, and the
lastCalled shape time can be 0. Pin that only rules in the order are used,
an empty order shows the Default Icon, and a 0 time holds at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BotAvatar now resolves a Bot's icon rules wherever it knows the Bot: a
timeline image or rule shape replaces the Default Icon in the one slot,
re-resolved once at each boundary instead of on a tick. The next timeline
image loads ahead, and a stored image stays up until the next one loads.
Muted Bots keep their Default Icon, now grayed out. Editors opt out.

The roster's workingSince, deliveredAt and erroredAt now reach the client
through ScopedBotEntry, and botIconInputs turns them and the Bot thread's
shell into each rule's minute 0. The evaluator uses the contract types.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@notFrost
notFrost changed the base branch from feat/bot-icon-timeline-server to feat/bot-icon-timeline December 1, 2026 18:58

@notFrost notFrost left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review (Lukas, lead engineer): approved, merging into feat/bot-icon-timeline. Posted as a comment because this account can't formally approve. I retargeted this PR from feat/bot-icon-timeline-server after #348 merged.

Checked against issue pingdotgg#692 and phase3-contract.md §2–3:

  • Evaluator (resolveBotIcon):
    • Muted shows the Default Icon (D29).
    • The mode follows the Default Icon's kind (D28).
    • Image mode walks the order and skips empty timelines and rules before their first entry (D10/D27).
    • Shape mode skips unset shapes, and a shape equal to the default (D32). lastCalled waits for lastCalledShapeAfterMinutes.
    • nextChangeAtMs is computed from the holding rule and the rules ahead of it.
    • Short or empty order and a zero threshold are pinned by tests.
  • Times:
    • workingSince, deliveredAt and erroredAt pass through ScopedBotEntry, which is now BotRosterEntry & { environmentId }.
    • leftOnDelivered minute 0 is the oldest blocking request, or an unread delivery or error. It uses isUnreadSinceVisit, now shared with the sidebar's hasUnreadResult, so a null visit counts as read and the two can't disagree.
    • lastCalled comes from shell.updatedAt (D20).
  • Display:
    • The avatar re-resolves once per boundary through useNowAfter, with no tick (AGENTS.md:156). It uses server-clock offsets.
    • Only the next image is prefetched.
    • The last loaded image is held to avoid a flash.
    • Muted adds grayscale.
    • Editors opt out with defaultIconOnly.
  • Scope: 15 files. The mobile change is a test fixture only, needed by the widened ScopedBotEntry, which is acceptable.

Run locally on a merge of 5fe331a564 into feat/bot-icon-timeline @ fd9ccfe750 (Windows):

vp run typecheck                                  → 44/44 successful, exit 0
vp lint --report-unused-disable-directives <15 changed files> → exit 0
vp run knip:check                                 → exit 0
client-runtime: vp test run (full package)        → 206 files, 3042 tests passed
web: vp test run src/components/bots src/state    → 31 files, 137 tests passed
web (env -u NODE_ENV): BotAvatar.browser, BotDetailsPanel.browser,
  sidebarMode.logic, botAvatarPaint               → 4 files, 16 tests passed
mobile: use-composer-command-menu.select          → 1 file, 3 tests passed

Not blocking, noted for phase 4 / QA:

  • Stale image. StoredBotImage keeps the last loaded src when the new reference's URL resolves to null, so an image that disappears keeps showing until remount instead of falling back. Worth a look when the editor can delete timeline images.
  • No desktop run yet. That was blocked until #348 stored iconRules. It's the next step, on the integration branch.

@notFrost
notFrost merged commit 6850954 into feat/bot-icon-timeline Dec 1, 2026
@notFrost

notFrost commented Dec 1, 2026

Copy link
Copy Markdown
Author

E2E: Bot icon rules (pingdotgg#692) on feat/bot-icon-timeline @ 6850954be7

Real server plus web UI (Vite dev), driven in T3's built-in browser (incognito), not Electron. State was isolated: vp run dev --home-dir <fresh temp dir> --no-seed. Bots ran on Claude Haiku 5.5.

How rules were set: a throwaway Effect RpcClient script (gitignored, not committed) called bots.create / bots.update over the real WebSocket, so validation and image storage ran for real. Timeline images went in as data:image/png;base64,…, which BotIconImageInput accepts, and came back stored as avatar:<sha256>.png. Runs were started with t3 thread send from the CLI, so no Bot thread got visited by accident. The avatar shown was checked from the DOM each time (which <img> was rendered, and whether grayscale was set).

# Case Result
1 Image mode, lastCalled at 0m and 1m PASS
2 workDuration while working, then fallback PASS
3 leftOnDelivered after a real reply, cleared by a visit PASS
4 Shape mode rule shape, plus D32 PASS
5 Muted shows the Default Icon in grayscale PASS
6 GIF in a timeline is refused PASS

1. Image mode: lastCalled [0m: A, 1m: B], Default Icon "D"

Bot created 19:16:08Z. At 19:16:52 the DOM showed A. At 19:17:38 it showed B, with the same page-load marker, so there was no reload.

0m 1m

2. workDuration [0m: W]

Run started 19:26:48. Mid-run read-back: status: working, workingSince: 2026-12-01T19:26:48.378Z, and the sidebar showed W. The run ended with workingSince: null and deliveredAt: 19:28:33.895Z, and by 19:28:53 the sidebar was back to the Default Icon.

working ended

3. leftOnDelivered [0m: L]

The Deliverer thread was visited once at 19:21:27, then left. The reply landed with deliveredAt: 19:24:54.322Z. Viewed from a different thread at 19:25:56, the sidebar showed L. At 19:26:11, after opening the Deliverer thread, it showed the Default Icon.

delivered, unvisited after visit

Bonus (D23): an earlier run that failed, with erroredAt: 19:22:35.662Z and the thread unvisited, also showed L:

4. Shape mode

Default Icon circle, ruleShapes.lastCalled: "star", lastCalledShapeAfterMinutes: 1. The star showed once that minute had passed.

D32: an update with ruleShapes.workDuration: "circle" (the Default Icon's shape) was stored as null:

bots.update response  icon: circle  ruleShapes: {"workDuration":null,"leftOnDelivered":null,"lastCalled":"star"}
bots.get read-back    icon: circle  ruleShapes: {"workDuration":null,"leftOnDelivered":null,"lastCalled":"star"}

5. Muted

After bots.update {muted: true}, Imagey showed its Default Icon D with opacity-70 grayscale, even though its timeline would otherwise show B. The read-back kept both lastCalled entries.

6. GIF refused

The typed RPC client refuses before sending (Schema validation failed). Sent raw over the WebSocket, the server refuses it too:

{"_tag":"Exit","requestId":"1","exit":{"_tag":"Failure","cause":[{"_tag":"Die","defect":
"Expected a string matching the RegExp ^avatar:[\da-f]{64}\.(?:webp|png|jpeg|gif)$
  at ["iconRules"]["timelines"]["workDuration"][0]["image"]
Expected a string matching the RegExp ^data:image\/(?:png|jpeg|webp);base64,
  at ["iconRules"]["timelines"]["workDuration"][0]["image"]"}]}}

A read-back afterwards showed the Bot's rules unchanged. The refusal comes back as a payload-decode Die, not a typed BotRpcError. That is how Effect RPC handles a bad payload, and the client schema blocks it first, so this is not a bug.

No bugs found.

🤖 Generated with Claude Code

@notFrost

notFrost commented Dec 1, 2026

Copy link
Copy Markdown
Author

Verification note (Lukas): I checked the E2E screenshots from e9be2cad0e myself. They match the table above:

  • Case 1: image A changes to image B with no reload.
  • Case 3: the leftOnDelivered image appears together with the sidebar's unread dot, and both clear on visit, so the shared unread rule holds.
  • Case 4: the star rule shape replaces the circle default.
  • Case 5: the muted Default Icon is shown in grayscale while Worker's work image still shows.

I accept the GIF refusal arriving as a payload-decode failure: the typed client blocks it first, and the server refuses it and leaves the rules unchanged. An Electron-shell pass is deferred to the final integrated check before the custom-nightly PR (vp run build:desktop plus a desktop run). Phase 3 is verified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant