one CRUD, three callers — the browser and the agent stop writing iCalendar

the skill told an agent how to hand-write a .ics: escape the commas, fold at 75
octets, CRLF, DTSTAMP is required, and DTEND is the day after. all true, all
silent when wrong, and the browser had learned the same lesson separately in its
own copy of the code. this makes the sidecar the only thing that knows the
format, and gives everyone else fields.

WHAT WAS MISSING BEFORE THE SKILL COULD CHANGE. reading was already JSON, and
create-event landed this morning. this adds PATCH /_officer/item — change some
fields of an event or a card — and POST /_officer/contact. delete already worked.
with those the skill has no reason left to mention iCalendar, so it does not.

PATCH IS READ-PATCH-PUT, SERVER SIDE. it reads the stored text, replaces only the
lines it owns, and puts the whole thing back, so alarms, attendees, RRULEs and
every X- property a phone invented survive an edit made from a form that cannot
show them. that logic came out of the browser, where it had needed a duplicate of
the escaping and folding rules to live; the agent would have been a third copy in
bash. the web bundle now contains no iCalendar literals at all.

AND LIVE TESTING FOUND THE BUG THAT MATTERS. an event with a TZID is stored with
a VTIMEZONE block beside it, and that block has DTSTART lines of its own — the
rule for when summer time starts. taking the first DTSTART in the file rewrote
the TIMEZONE DEFINITION, left the event where it was, and answered ok. the
calendar showed the old time and the file was quietly corrupt. every write is now
confined to the first VEVENT or VCARD, and the file that caught it is a test.

three more traps handled rather than documented: a patch that reuses an all-day
event's stored DTEND must subtract the exclusive day first or the holiday drifts
every time the title is edited; moving a timed event must DROP a stale TZID
rather than preserve it, because a TZID and a Z together are a contradiction
clients resolve by moving the event; and a move bumps SEQUENCE, which is how a
phone tells an update from a duplicate.

contacts got the create form the calendar had, so both screens now do all four.
editing a card sends the other emails and phones back untouched — the form shows
the first of each, and sending only that would delete the rest.

47 tests across the writer and the patcher. verified live against a real event
carrying an alarm, an attendee, an RRULE and an X- property: all four intact
after a rename, a relocation and a move to a different day.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Officer-Session: 656f5c85-e49a-4f1f-b9f3-042a04b4d043
This commit is contained in:
2026-08-27 10:51:22 +00:00
co-authored by Claude Opus 5
parent 25c8502c4b
commit 43cb531dc2
10 changed files with 871 additions and 348 deletions
+28 -1
View File
@@ -1,4 +1,13 @@
import { buildEvent, parseContacts, parseEvents, type CalendarEvent, type Contact, type NewEvent } from './ical';
import {
buildContact,
buildEvent,
parseContacts,
parseEvents,
type CalendarEvent,
type Contact,
type NewContact,
type NewEvent,
} from './ical';
// The JSON door: what Officer's own web UI reads.
//
@@ -180,3 +189,21 @@ export async function createEvent(fetcher: Fetcher, collection: string, event: N
if (!res.ok) throw new Error(`radicale answered ${res.status}`);
return { href };
}
/** The same contract as `createEvent`, for a card. */
export async function createContact(
fetcher: Fetcher,
collection: string,
contact: NewContact,
): Promise<{ href: string }> {
const uid = crypto.randomUUID();
const href = `${collection.replace(/\/$/, '')}/${uid}.vcf`;
const res = await fetcher(href, {
method: 'PUT',
headers: { 'Content-Type': 'text/vcard; charset=utf-8', 'If-None-Match': '*' },
body: buildContact(uid, contact),
});
if (!res.ok) throw new Error(`radicale answered ${res.status}`);
return { href };
}