@mulmoclaude/core 5.1.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/helps/error-recovery.md +78 -0
- package/assets/helps/google-calendar-collection.md +92 -12
- package/dist/collection/core/schemaZ.d.ts +15 -2
- package/dist/collection/core/viewChatPolicy.d.ts +6 -3
- package/dist/collection/index.cjs +6 -3
- package/dist/collection/index.cjs.map +1 -1
- package/dist/collection/index.js +6 -3
- package/dist/collection/index.js.map +1 -1
- package/dist/collection/registry/server/index.cjs +2 -2
- package/dist/collection/registry/server/index.js +2 -2
- package/dist/collection/server/index.cjs +2 -2
- package/dist/collection/server/index.js +2 -2
- package/dist/collection-watchers/index.cjs +2 -2
- package/dist/collection-watchers/index.js +2 -2
- package/dist/{discovery-CBjI1lx9.js → discovery-B_64PBZU.js} +14 -3
- package/dist/{discovery-CBjI1lx9.js.map → discovery-B_64PBZU.js.map} +1 -1
- package/dist/{discovery-DCMW05Bp.cjs → discovery-CDXYswtw.cjs} +14 -3
- package/dist/{discovery-DCMW05Bp.cjs.map → discovery-CDXYswtw.cjs.map} +1 -1
- package/dist/feeds/server/index.cjs +2 -2
- package/dist/feeds/server/index.js +2 -2
- package/dist/google/calendar.d.ts +24 -0
- package/dist/google/collectionPush.d.ts +45 -2
- package/dist/google/deletePlan.d.ts +32 -0
- package/dist/google/eventDerived.d.ts +19 -0
- package/dist/google/index.cjs +179 -18
- package/dist/google/index.cjs.map +1 -1
- package/dist/google/index.d.ts +4 -2
- package/dist/google/index.js +174 -19
- package/dist/google/index.js.map +1 -1
- package/dist/remote-view/index.cjs +7 -7
- package/dist/remote-view/index.cjs.map +1 -1
- package/dist/remote-view/index.d.ts +3 -3
- package/dist/remote-view/index.js +7 -7
- package/dist/remote-view/index.js.map +1 -1
- package/dist/{server-BMZ_BcPH.js → server-7POrhHKv.js} +2 -2
- package/dist/{server-BMZ_BcPH.js.map → server-7POrhHKv.js.map} +1 -1
- package/dist/{server-rA9FSkl2.cjs → server-DfYwSX8b.cjs} +2 -2
- package/dist/{server-rA9FSkl2.cjs.map → server-DfYwSX8b.cjs.map} +1 -1
- package/package.json +1 -1
|
@@ -657,6 +657,84 @@ workspace is already on a real filesystem and a conflict still will not
|
|
|
657
657
|
clear, that is a new bug — report it with the calendar id and the
|
|
658
658
|
record.
|
|
659
659
|
|
|
660
|
+
## Push skips a record: "the record id cannot be used as a Google event id"
|
|
661
|
+
|
|
662
|
+
### Symptoms
|
|
663
|
+
|
|
664
|
+
Push reports a record as skipped and names its id. It never reaches
|
|
665
|
+
Google, however many times the user presses the button. Editing the
|
|
666
|
+
record's other fields changes nothing.
|
|
667
|
+
|
|
668
|
+
### Cause
|
|
669
|
+
|
|
670
|
+
A push CREATES the Google event with the record's own primary-key value
|
|
671
|
+
as the event id, so a record keeps its identity across the round trip.
|
|
672
|
+
Google constrains an event id to **lower-case base32hex**: 5-1024
|
|
673
|
+
characters from `0-9a-v` only. So no `w`, `x`, `y` or `z`, no upper
|
|
674
|
+
case, no hyphen, no underscore, no dot.
|
|
675
|
+
|
|
676
|
+
A semantic id anyone would reach for — `team-standup`, `Weekly_Sync`,
|
|
677
|
+
`2026-07-17` — breaks the rule on the hyphen, the case or the letters.
|
|
678
|
+
Records created through the collection UI get a generated id that
|
|
679
|
+
satisfies it; only a primary key someone typed or imported can fail.
|
|
680
|
+
|
|
681
|
+
### Fix
|
|
682
|
+
|
|
683
|
+
Recreate the record without setting the primary field, and let the UI
|
|
684
|
+
generate the id. If the id has to be meaningful, it can be — as long as
|
|
685
|
+
every character is a digit or a letter `a` through `v` and there are at
|
|
686
|
+
least five of them (`teamstandup` passes, `team-standup` does not).
|
|
687
|
+
|
|
688
|
+
Renaming the primary key of an EXISTING record means deleting it and
|
|
689
|
+
adding it again: the primary key is the record's identity, so nothing
|
|
690
|
+
else reassigns it.
|
|
691
|
+
|
|
692
|
+
## A record keeps showing as "edited" and the same push repeats forever
|
|
693
|
+
|
|
694
|
+
### Symptoms
|
|
695
|
+
|
|
696
|
+
The same record is pushed on every cycle with content that never
|
|
697
|
+
changes, and the Google event's `updated` moves each time. No conflict
|
|
698
|
+
is reported and no data is lost — the calendar just receives the same
|
|
699
|
+
write over and over.
|
|
700
|
+
|
|
701
|
+
### Cause
|
|
702
|
+
|
|
703
|
+
The push compares the record against the BASELINE in
|
|
704
|
+
`<workspace>/data/calendar/.push-state.json`, and the baseline advances
|
|
705
|
+
only when a PULL reports the event as changed. If a write reaches Google
|
|
706
|
+
but does NOT change the event's stored value — Google normalising the
|
|
707
|
+
value it was sent, or a write of the value the event already held — then
|
|
708
|
+
Google reports no change, the pull never sees the event, and the
|
|
709
|
+
baseline stays behind. The next push sees the same difference again.
|
|
710
|
+
|
|
711
|
+
This was checked on a live calendar and the Events API did **not**
|
|
712
|
+
normalise `description` HTML (empty `<div>`, `style` attributes and all
|
|
713
|
+
survived a round trip byte-for-byte), so it is not the common case. It
|
|
714
|
+
is written down because the SYMPTOM is indistinguishable from a real
|
|
715
|
+
repeated edit, and the two are told apart the same way.
|
|
716
|
+
|
|
717
|
+
### Fix
|
|
718
|
+
|
|
719
|
+
Look at the baseline, not at the record. Read the event's entry in
|
|
720
|
+
`.push-state.json` and compare it with what `google` (`kind:
|
|
721
|
+
"calendarListEvents"`) reports for that event id:
|
|
722
|
+
|
|
723
|
+
- **Baseline matches Google, record differs** — an ordinary unpushed
|
|
724
|
+
edit. Nothing is wrong; the next push sends it.
|
|
725
|
+
- **Baseline differs from Google** — the baseline is stale. `autoPush`
|
|
726
|
+
does NOT fix this one: it converges only when the push actually
|
|
727
|
+
changed the stored value, because only then does the pull carry the
|
|
728
|
+
event. Press Sync to force a pull; if the event is still not reported,
|
|
729
|
+
the value Google holds is already what the push keeps sending, and the
|
|
730
|
+
baseline has to be rebuilt.
|
|
731
|
+
|
|
732
|
+
Rebuilding: delete the calendar's entry from `.push-state.json` (or the
|
|
733
|
+
file, if it covers only that calendar) and press Sync. The next pull
|
|
734
|
+
writes a fresh baseline from Google's current values. Tell the user
|
|
735
|
+
first — until that pull lands, a genuine unpushed local edit would be
|
|
736
|
+
indistinguishable from a mirrored one.
|
|
737
|
+
|
|
660
738
|
## A calendar collection only ever holds a handful of records
|
|
661
739
|
|
|
662
740
|
### Symptoms
|
|
@@ -17,6 +17,7 @@ author the schema when the user asks for one.
|
|
|
17
17
|
| Google → collection | the `googleCalendar` block | hourly, on creation, and on the **Sync** button |
|
|
18
18
|
| collection → Google | the **Push to Google** button | whenever the user clicks it |
|
|
19
19
|
| collection → Google | `"autoPush": true` in the block | hourly, immediately before each pull |
|
|
20
|
+
| collection → Google, deletions | `"propagateDeletes": true` in the block | with every push. Off by default; see "Deleting" |
|
|
20
21
|
|
|
21
22
|
When a user asks for "two-way sync", `autoPush` is the answer: set it and each
|
|
22
23
|
scheduled run pushes local edits up and then pulls Google's changes down, as one
|
|
@@ -66,6 +67,9 @@ it isn't, sync silently does nothing until they link it in settings.
|
|
|
66
67
|
would see rows with no content.
|
|
67
68
|
- `autoPush` — push local edits on the sync schedule, just before each pull.
|
|
68
69
|
Omit it (the default) and the push stays a button. See "Both directions".
|
|
70
|
+
- `propagateDeletes` — delete the Google event when its record is deleted here.
|
|
71
|
+
Omit it (the default) and a local deletion is reported and nothing else. See
|
|
72
|
+
"Deleting".
|
|
69
73
|
|
|
70
74
|
Mappable event fields, two-way first: `summary`, `start`, `end`, `description`,
|
|
71
75
|
`location`, `colorId`.
|
|
@@ -78,15 +82,56 @@ time),
|
|
|
78
82
|
`transparency` (`"transparent"` when the event does not consume the attendee's
|
|
79
83
|
time; `""` means opaque), `eventType` (all six Google returns: `default` / `birthday` / `focusTime` /
|
|
80
84
|
`fromGmail` / `outOfOffice` / `workingLocation`), `hangoutLink` (the Meet URL),
|
|
81
|
-
`recurringEventId` and
|
|
85
|
+
`recurringEventId`, `originalStartTime`, `selfResponseStatus` and
|
|
86
|
+
`conferenceVideoUri`.
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
expand recurrences, so a weekly meeting arrives
|
|
85
|
-
`recurringEventId` names the series each occurrence
|
|
86
|
-
one-off), and `originalStartTime` is the slot the
|
|
87
|
-
dragged it — so a moved occurrence reads as a move
|
|
88
|
-
plus a new event. Map them when the user asks why one
|
|
89
|
-
large batch of record changes.
|
|
88
|
+
`recurringEventId` and `originalStartTime` are how a recurring series stays
|
|
89
|
+
legible. The sync asks Google to expand recurrences, so a weekly meeting arrives
|
|
90
|
+
as one event per occurrence; `recurringEventId` names the series each occurrence
|
|
91
|
+
came from (`""` for a one-off), and `originalStartTime` is the slot the
|
|
92
|
+
occurrence held before anyone dragged it — so a moved occurrence reads as a move
|
|
93
|
+
rather than as a deletion plus a new event. Map them when the user asks why one
|
|
94
|
+
calendar edit produced a large batch of record changes.
|
|
95
|
+
|
|
96
|
+
### `selfResponseStatus` and `conferenceVideoUri`
|
|
97
|
+
|
|
98
|
+
These two are not Google field names. Google answers `attendees` as an ARRAY and
|
|
99
|
+
`conferenceData` as an array inside an object, and a collection field holds one
|
|
100
|
+
value — so each is folded down to the single scalar the collection asks it for.
|
|
101
|
+
The rest of those structures is dropped; there is no way to map the attendee
|
|
102
|
+
list itself.
|
|
103
|
+
|
|
104
|
+
**`selfResponseStatus`** — the signed-in user's own `responseStatus`:
|
|
105
|
+
`needsAction`, `declined`, `tentative` or `accepted`.
|
|
106
|
+
|
|
107
|
+
`""` means Google reported none, and that is the COMMON case, not an edge one:
|
|
108
|
+
an event with no attendees has no entry to mark as the user, which is most of a
|
|
109
|
+
personal calendar. So it reads as "nothing said", never as "not going".
|
|
110
|
+
|
|
111
|
+
Filter with **`!= "declined"`**, never with `== "accepted"` — the second hides
|
|
112
|
+
every solo event too. A `flag` field is the usual way:
|
|
113
|
+
|
|
114
|
+
```jsonc
|
|
115
|
+
"fields": {
|
|
116
|
+
"rsvp": { "type": "string", "label": "RSVP" },
|
|
117
|
+
"onMySchedule": {
|
|
118
|
+
"type": "flag",
|
|
119
|
+
"label": "Mine",
|
|
120
|
+
"where": [{ "field": "rsvp", "op": "ne", "value": "declined" }]
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"googleCalendar": { "map": { "rsvp": "selfResponseStatus" } }
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**`conferenceVideoUri`** — the URL that joins the meeting, taken from the
|
|
127
|
+
`video` entry point. `""` when the event has no conference, and also when its
|
|
128
|
+
only entry points are a phone number or a dial-in page: a column named for
|
|
129
|
+
joining that sometimes held `tel:` would be worse than one the caller can see is
|
|
130
|
+
empty.
|
|
131
|
+
|
|
132
|
+
`hangoutLink` already carries this for Google Meet. `conferenceVideoUri` is what
|
|
133
|
+
reaches a calendar whose meetings are Zoom or Teams. A Meet event fills both, so
|
|
134
|
+
map whichever the user's calendar actually uses.
|
|
90
135
|
|
|
91
136
|
`description` is the event body, and Google stores limited **HTML** in it. It is
|
|
92
137
|
kept verbatim — mirroring it through a plain-text field and pushing it back would
|
|
@@ -190,10 +235,9 @@ What the button does and deliberately does not do:
|
|
|
190
235
|
- **Creates** an event for a record that never came from a sync.
|
|
191
236
|
- **Updates** only the fields the user actually changed, so attendees,
|
|
192
237
|
reminders and recurrence rules stay untouched.
|
|
193
|
-
- **Never deletes
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
the `google` tool's `calendarDeleteEvent`, after confirming with them.
|
|
238
|
+
- **Never deletes, unless the collection asked it to.** See "Deleting" below;
|
|
239
|
+
without `propagateDeletes` a record deleted locally leaves its Google event
|
|
240
|
+
alone and the count is reported so the user knows.
|
|
197
241
|
- **Skips a record edited on both sides** and reports it, rather than picking a
|
|
198
242
|
winner. The user resolves it by editing one side to match. Under `autoPush`
|
|
199
243
|
the pull that follows leaves that record alone too, so the local edit is not
|
|
@@ -225,6 +269,42 @@ reach by id but has not added to their calendar list has no role to check, so
|
|
|
225
269
|
the push goes ahead and reports Google's own refusal if the write turns out not
|
|
226
270
|
to be allowed — being unlisted is not treated as being read-only.
|
|
227
271
|
|
|
272
|
+
## Deleting
|
|
273
|
+
|
|
274
|
+
By default, a record deleted in the collection leaves its Google event alone.
|
|
275
|
+
The push reports the count and does nothing else, and the next sync brings the
|
|
276
|
+
record back — which is correct for a calendar Google owns, and wrong for one
|
|
277
|
+
where the collection is the primary copy.
|
|
278
|
+
|
|
279
|
+
`"propagateDeletes": true` in the `googleCalendar` block makes the push delete
|
|
280
|
+
those events too. **Ask the user before adding it**, the same as `autoPush` and
|
|
281
|
+
for a stronger reason: `autoPush` changes WHEN a write happens, this makes a
|
|
282
|
+
write irreversible.
|
|
283
|
+
|
|
284
|
+
Even on, the push **refuses an event that carries attendees** and reports it
|
|
285
|
+
instead. Deleting an invited event withdraws it from the guests' calendars,
|
|
286
|
+
which is a different act from tidying your own. **Any** attendee entry refuses,
|
|
287
|
+
including the one Google adds for the organiser — so an event only the user was
|
|
288
|
+
ever on is refused too, deliberately: telling the two apart means deciding which
|
|
289
|
+
entry is the user from a payload that may not say, and being wrong there
|
|
290
|
+
withdraws a real invitation. Either way, an event the user actually wants gone
|
|
291
|
+
is deleted with the `google` tool's `calendarDeleteEvent`, after confirming with
|
|
292
|
+
them.
|
|
293
|
+
|
|
294
|
+
The delete also carries the version the check was made against, so an attendee
|
|
295
|
+
added while the push was running makes Google refuse it rather than letting a
|
|
296
|
+
decision taken a moment earlier stand. That is reported like any other refusal;
|
|
297
|
+
pressing Push again re-checks.
|
|
298
|
+
|
|
299
|
+
There is no undo here and this app keeps no copy of what it deleted. Google
|
|
300
|
+
Calendar's own Trash holds a deleted event for a while, and that is where a
|
|
301
|
+
mistake is recovered from.
|
|
302
|
+
|
|
303
|
+
A deletion that carried stops being reported, because its baseline entry goes
|
|
304
|
+
with it. A deletion that was REFUSED keeps being reported on every push — the
|
|
305
|
+
event is still standing in Google, and the report is the only thing that says
|
|
306
|
+
so.
|
|
307
|
+
|
|
228
308
|
## Not for this
|
|
229
309
|
|
|
230
310
|
A `dataSource` (CSV-backed) collection is read-only and cannot declare
|
|
@@ -513,8 +513,12 @@ export declare const AgentIngestZ: z.ZodObject<{
|
|
|
513
513
|
* limitation: `transparency` is writable and `eventType` is writable at
|
|
514
514
|
* creation, yet neither is sent. That is also why
|
|
515
515
|
* widening this enum needs no `.push-state.json` migration: the push baseline
|
|
516
|
-
* (`ShadowEvent`) is keyed off the pushable list, not off this one.
|
|
517
|
-
|
|
516
|
+
* (`ShadowEvent`) is keyed off the pushable list, not off this one.
|
|
517
|
+
*
|
|
518
|
+
* The last two are not Google field names but DERIVED scalars
|
|
519
|
+
* (`google/eventDerived.ts`): the structures they come from are arrays, and a
|
|
520
|
+
* collection field holds one value. */
|
|
521
|
+
export declare const GOOGLE_CALENDAR_SOURCE_FIELDS: readonly ["summary", "start", "end", "description", "location", "colorId", "htmlLink", "status", "recurringEventId", "originalStartTime", "updated", "transparency", "eventType", "hangoutLink", "selfResponseStatus", "conferenceVideoUri"];
|
|
518
522
|
/** Marks a collection as the destination of the LLM-free Google Calendar
|
|
519
523
|
* sync (#2095). `map` is collectionField → Google event field, so the user's
|
|
520
524
|
* collection keeps whatever field names it already uses. */
|
|
@@ -535,8 +539,11 @@ export declare const GoogleCalendarSyncZ: z.ZodObject<{
|
|
|
535
539
|
transparency: "transparency";
|
|
536
540
|
eventType: "eventType";
|
|
537
541
|
hangoutLink: "hangoutLink";
|
|
542
|
+
selfResponseStatus: "selfResponseStatus";
|
|
543
|
+
conferenceVideoUri: "conferenceVideoUri";
|
|
538
544
|
}>>;
|
|
539
545
|
autoPush: z.ZodOptional<z.ZodBoolean>;
|
|
546
|
+
propagateDeletes: z.ZodOptional<z.ZodBoolean>;
|
|
540
547
|
}, z.core.$strip>;
|
|
541
548
|
/** `ingest` is a discriminated union on `kind`: the three declarative
|
|
542
549
|
* retrievers fetch-and-map; `agent` dispatches a hidden worker. Optional on
|
|
@@ -1148,8 +1155,11 @@ declare const CollectionObjectZ: z.ZodObject<{
|
|
|
1148
1155
|
transparency: "transparency";
|
|
1149
1156
|
eventType: "eventType";
|
|
1150
1157
|
hangoutLink: "hangoutLink";
|
|
1158
|
+
selfResponseStatus: "selfResponseStatus";
|
|
1159
|
+
conferenceVideoUri: "conferenceVideoUri";
|
|
1151
1160
|
}>>;
|
|
1152
1161
|
autoPush: z.ZodOptional<z.ZodBoolean>;
|
|
1162
|
+
propagateDeletes: z.ZodOptional<z.ZodBoolean>;
|
|
1153
1163
|
}, z.core.$strip>>;
|
|
1154
1164
|
dynamicIcon: z.ZodOptional<z.ZodObject<{
|
|
1155
1165
|
source: z.ZodObject<{
|
|
@@ -1646,8 +1656,11 @@ export declare const CollectionSchemaZ: z.ZodPreprocess<z.ZodObject<{
|
|
|
1646
1656
|
transparency: "transparency";
|
|
1647
1657
|
eventType: "eventType";
|
|
1648
1658
|
hangoutLink: "hangoutLink";
|
|
1659
|
+
selfResponseStatus: "selfResponseStatus";
|
|
1660
|
+
conferenceVideoUri: "conferenceVideoUri";
|
|
1649
1661
|
}>>;
|
|
1650
1662
|
autoPush: z.ZodOptional<z.ZodBoolean>;
|
|
1663
|
+
propagateDeletes: z.ZodOptional<z.ZodBoolean>;
|
|
1651
1664
|
}, z.core.$strip>>;
|
|
1652
1665
|
dynamicIcon: z.ZodOptional<z.ZodObject<{
|
|
1653
1666
|
source: z.ZodObject<{
|
|
@@ -7,7 +7,10 @@ import { CollectionCustomView } from './schema';
|
|
|
7
7
|
* code composes the prompt text; letting it also decide whether that text runs
|
|
8
8
|
* would put both halves of the decision inside the sandbox.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* no Enter key
|
|
12
|
-
*
|
|
10
|
+
* EVERY surface consults this, the phone included. The phone once always sent,
|
|
11
|
+
* on the grounds that it has no Enter key to press — but that made the same
|
|
12
|
+
* view behave differently depending on where it was opened, and it silently
|
|
13
|
+
* overrode default-deny on a device the author never tested. The phone is
|
|
14
|
+
* served the resolved flag in its view payload rather than re-reading the
|
|
15
|
+
* schema, because it never sees the schema. */
|
|
13
16
|
export declare function customViewSendsChat(view: Pick<CollectionCustomView, "allowSendChat">): boolean;
|
|
@@ -368,9 +368,12 @@ function firstMissingRequiredField(draft, schema) {
|
|
|
368
368
|
* code composes the prompt text; letting it also decide whether that text runs
|
|
369
369
|
* would put both halves of the decision inside the sandbox.
|
|
370
370
|
*
|
|
371
|
-
*
|
|
372
|
-
* no Enter key
|
|
373
|
-
*
|
|
371
|
+
* EVERY surface consults this, the phone included. The phone once always sent,
|
|
372
|
+
* on the grounds that it has no Enter key to press — but that made the same
|
|
373
|
+
* view behave differently depending on where it was opened, and it silently
|
|
374
|
+
* overrode default-deny on a device the author never tested. The phone is
|
|
375
|
+
* served the resolved flag in its view payload rather than re-reading the
|
|
376
|
+
* schema, because it never sees the schema. */
|
|
374
377
|
function customViewSendsChat(view) {
|
|
375
378
|
return view.allowSendChat === true;
|
|
376
379
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/collection/core/presentCollection.ts","../../src/collection/core/enumColors.ts","../../src/collection/core/draft.ts","../../src/collection/core/viewChatPolicy.ts","../../src/collection/core/chatSeed.ts","../../src/collection/core/shortcutInfo.ts","../../src/collection/core/sortItems.ts","../../src/collection/core/sortValueOf.ts","../../src/collection/core/textSearch.ts","../../src/collection/core/recordKeys.ts","../../src/collection/core/itemLabel.ts","../../src/collection/core/ontologyGraph.ts"],"sourcesContent":["// presentCollection tool — definition + pure server-side executor.\n//\n// Isomorphic (no Vue, no Node): bundled to the browser as the plugin's\n// `execute`, and run server-side via the host's plugin dispatch route. The\n// executor only validates + echoes the addressing; the live schema + items\n// are fetched client-side by the View through the host's /api/collections\n// routes, so a bad slug surfaces as the View's \"not found\" state.\n\nimport type { ToolContext, ToolDefinition, ToolResult } from \"gui-chat-protocol\";\n\nexport const TOOL_NAME = \"presentCollection\";\n\n/** Render payload carried in the tool result's `data` field; the View mounts\n * off these. Same shape as the tool args. */\nexport interface PresentCollectionData {\n /** Slug of the collection to display (e.g. \"clients\", \"invoices\"). */\n collectionSlug: string;\n /** Optional primary-key value of a single item to open on mount. */\n itemId?: string | undefined;\n /** Which ROOT this card's collection lives in, as a host-opaque scope token.\n *\n * A collection's identity is `(root, slug)`, but a card payload named only\n * the slug — so the host re-resolved it through whatever binding was current\n * when the card RENDERED, which in a multi-root host may be a different\n * project than the one the card was made in. A card built in project A could\n * then read project B's data.\n *\n * **Stamped by the HOST, never accepted from tool arguments.** The tool args\n * are a model-controlled channel: a model that could name the scope could\n * name another project's, and the card — and any token minted for it — would\n * address a project the user never opened in this conversation. So\n * `executePresentCollection` DROPS any `scope` it is handed, and a host adds\n * its own with {@link withCardScope} when it applies the result, where it\n * already knows which binding produced the call.\n *\n * Host-opaque: pass an opaque project id, NEVER an absolute path — this\n * payload reaches the browser and, through a view, an LLM-authored iframe.\n *\n * Absent — the single-workspace case — the payload and every reconciliation\n * decision are exactly what they were before this field existed. */\n scope?: string | undefined;\n}\n\n/** Stamp a host's opaque project scope onto a card payload. The ONLY way a\n * scope gets in: the executor refuses to take one from tool arguments (see\n * `PresentCollectionData.scope`). `undefined` returns the payload untouched,\n * so a single-workspace host calling this unconditionally still produces a\n * payload with no `scope` property at all. */\nexport function withCardScope(data: PresentCollectionData, scope: string | undefined): PresentCollectionData {\n const trimmed = typeof scope === \"string\" ? scope.trim() : \"\";\n return trimmed.length > 0 ? { ...data, scope: trimmed } : data;\n}\n\n/** A card's identity for reconciliation. Two cards match only when they name\n * the same collection IN THE SAME SCOPE, so two projects' `tasks` cards stay\n * two cards. With no scope on either side this is the slug, unchanged. */\nexport function collectionCardKey(data: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">): string {\n return data.scope === undefined ? data.collectionSlug : `${data.scope}\\u0000${data.collectionSlug}`;\n}\n\n/** Do two card payloads address the same card? The reconciliation predicate a\n * host should use instead of comparing slugs. */\nexport function sameCollectionCard(\n one: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">,\n other: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">,\n): boolean {\n return collectionCardKey(one) === collectionCardKey(other);\n}\n\nexport type PresentCollectionArgs = PresentCollectionData;\n\nexport const TOOL_DEFINITION: ToolDefinition = {\n type: \"function\",\n name: TOOL_NAME,\n description:\n \"Display a schema-driven collection inline in the chat as an interactive, editable card. Shows the collection's list of records. Pass `itemId` to open one specific record on mount.\",\n parameters: {\n type: \"object\",\n properties: {\n collectionSlug: {\n type: \"string\",\n description: \"The slug of the collection to display (e.g. 'clients', 'invoices', 'contacts').\",\n },\n itemId: {\n type: \"string\",\n description: \"Optional primary-key value of a single record to open in detail view on mount. Omit to show the full list.\",\n },\n },\n required: [\"collectionSlug\"],\n },\n prompt: `After making changes to schema-driven collections, use ${TOOL_NAME} to present either the collection or the item`,\n};\n\n/** A trimmed non-empty string, or undefined. The tool's args arrive from an\n * LLM (and `scope` from the host), so every field is validated the same way\n * rather than trusted. */\nconst cleaned = (value: unknown): string | undefined => (typeof value === \"string\" && value.trim().length > 0 ? value.trim() : undefined);\n\n/** Normalise the tool args into the card payload, or `null` when the required\n * slug is missing. Pure and exported so the addressing rules are testable\n * without going through a `ToolResult`.\n *\n * `scope` is deliberately NOT read from the args — see\n * `PresentCollectionData.scope`. Everything here comes from a model-controlled\n * channel, and the scope decides which project the card reads; a host stamps\n * it afterwards with `withCardScope`.\n *\n * Keys are added one at a time rather than spread with `undefined` values, so\n * a payload with no `itemId` OMITS the property entirely — which is what keeps\n * a single-workspace card byte-identical to what it has always been, in both\n * `deepEqual` and JSON. */\nexport const toPresentCollectionData = (args: PresentCollectionArgs): PresentCollectionData | null => {\n const collectionSlug = cleaned(args?.collectionSlug);\n if (!collectionSlug) return null;\n const itemId = cleaned(args.itemId);\n return { collectionSlug, ...(itemId ? { itemId } : {}) };\n};\n\nexport const executePresentCollection = async (\n _context: ToolContext,\n args: PresentCollectionArgs,\n): Promise<ToolResult<PresentCollectionData, PresentCollectionData>> => {\n const data = toPresentCollectionData(args);\n if (!data) {\n return {\n message: \"presentCollection error: collectionSlug is required\",\n instructions: \"Tell the user you couldn't display the collection because no collection was specified, and ask which collection they mean.\",\n };\n }\n const { collectionSlug, itemId } = data;\n const target = itemId ? `${collectionSlug} / ${itemId}` : collectionSlug;\n return {\n message: `Presented collection ${target}`,\n // `data` is the view's source (also the host's render-eligibility signal);\n // `jsonData` is what the LLM sees. Same payload, two audiences.\n data,\n jsonData: data,\n // Phrased to stay correct for BOTH storage kinds without loading the\n // schema (this executor is deliberately pure/isomorphic): a writable\n // collection offers edit/create/delete in the card; a read-only\n // `dataSource` collection hides those and changes flow through its\n // data file instead.\n instructions:\n \"The collection has been presented to the user as an interactive card. They can browse and open records directly; on a writable collection they can also edit, create, and delete (a read-only dataSource collection shows no edit controls — its records change by editing the backing data file). No further action is needed unless they ask.\",\n };\n};\n","// A standard, ordered colour palette for `enum` field values, shared by every\n// collection surface (list, calendar, kanban). Each value in an\n// enum's `values` array is assigned the palette entry at its index — cycling\n// when an enum declares more values than the palette holds — so colouring is\n// automatic and consistent without any per-value schema config.\n//\n// Tailwind only detects class names that appear as complete string literals,\n// so every surface's classes are spelled out per colour below rather than\n// built from a colour name at runtime.\n//\n// One enum is special: the field a schema's `notifyWhen` targets (the\n// \"notification enum\"). Its flagged values read the notification severity\n// colours — the first flagged value (most urgent) red, the rest amber — and\n// every other value reads neutral grey, mirroring the notification bell\n// (red = urgent, amber = nudge) rather than the rotating palette.\n// `resolveEnumColor` encapsulates that rule.\n\nimport { fieldText, fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionSchema } from \"./schema\";\n\nexport interface EnumColorClasses {\n /** Stat-card style: border + fill + text + hover. */\n card: string;\n /** Small status dot (kanban column header). */\n dot: string;\n /** Pill / badge / inline `<select>` fill + text (no border width). */\n badge: string;\n /** Border colour, paired with a `border` width class by the caller. */\n border: string;\n}\n\n// The palette deliberately EXCLUDES the warm warning band (red / orange /\n// amber): those are reserved for the notification-enum severity colours\n// (`ENUM_ALERT` red, `ENUM_NUDGE` amber), so a normal enum value can never\n// draw a colour that reads like a notification. Eight well-separated cool /\n// green / magenta hues keep enough variety for wide enums.\nconst PALETTE: readonly EnumColorClasses[] = [\n {\n card: \"border-indigo-200 bg-indigo-50 text-indigo-600 hover:bg-indigo-100\",\n dot: \"bg-indigo-500\",\n badge: \"bg-indigo-100 text-indigo-700\",\n border: \"border-indigo-200\",\n },\n { card: \"border-sky-200 bg-sky-50 text-sky-600 hover:bg-sky-100\", dot: \"bg-sky-500\", badge: \"bg-sky-100 text-sky-700\", border: \"border-sky-200\" },\n { card: \"border-cyan-200 bg-cyan-50 text-cyan-600 hover:bg-cyan-100\", dot: \"bg-cyan-500\", badge: \"bg-cyan-100 text-cyan-700\", border: \"border-cyan-200\" },\n { card: \"border-teal-200 bg-teal-50 text-teal-600 hover:bg-teal-100\", dot: \"bg-teal-500\", badge: \"bg-teal-100 text-teal-700\", border: \"border-teal-200\" },\n {\n card: \"border-emerald-200 bg-emerald-50 text-emerald-600 hover:bg-emerald-100\",\n dot: \"bg-emerald-500\",\n badge: \"bg-emerald-100 text-emerald-700\",\n border: \"border-emerald-200\",\n },\n { card: \"border-lime-200 bg-lime-50 text-lime-600 hover:bg-lime-100\", dot: \"bg-lime-500\", badge: \"bg-lime-100 text-lime-700\", border: \"border-lime-200\" },\n {\n card: \"border-violet-200 bg-violet-50 text-violet-600 hover:bg-violet-100\",\n dot: \"bg-violet-500\",\n badge: \"bg-violet-100 text-violet-700\",\n border: \"border-violet-200\",\n },\n {\n card: \"border-fuchsia-200 bg-fuchsia-50 text-fuchsia-600 hover:bg-fuchsia-100\",\n dot: \"bg-fuchsia-500\",\n badge: \"bg-fuchsia-100 text-fuchsia-700\",\n border: \"border-fuchsia-200\",\n },\n];\n\n/** Neutral styling for the empty / Uncategorized bucket — never a palette\n * colour, so an unset or unknown value reads grey across every surface. */\nexport const ENUM_NEUTRAL: EnumColorClasses = {\n card: \"border-slate-200 bg-slate-50 text-slate-500 hover:bg-slate-100\",\n dot: \"bg-slate-300\",\n badge: \"bg-slate-100 text-slate-500\",\n border: \"border-slate-200\",\n};\n\n/** The urgent notification colour (red), matching the bell's `urgent`\n * severity. The first value a schema's `notifyWhen` flags reads this. */\nexport const ENUM_ALERT: EnumColorClasses = {\n card: \"border-red-200 bg-red-50 text-red-600 hover:bg-red-100\",\n dot: \"bg-red-500\",\n badge: \"bg-red-100 text-red-700\",\n border: \"border-red-200\",\n};\n\n/** The nudge notification colour (amber), matching the bell's `nudge`\n * severity. Flagged `notifyWhen` values after the first read this. */\nexport const ENUM_NUDGE: EnumColorClasses = {\n card: \"border-amber-200 bg-amber-50 text-amber-600 hover:bg-amber-100\",\n dot: \"bg-amber-500\",\n badge: \"bg-amber-100 text-amber-700\",\n border: \"border-amber-200\",\n};\n\n/** Classes for the enum value at `index` in its field's `values` array. A\n * negative index (value unset or not among the declared values) reads\n * neutral. */\nexport function enumColorClasses(index: number): EnumColorClasses {\n if (index < 0) return ENUM_NEUTRAL;\n return PALETTE[index % PALETTE.length] ?? ENUM_NEUTRAL;\n}\n\n/** Index of `value` within an enum field's declared `values`, or -1 when the\n * value is empty / unknown (→ neutral). */\nexport function enumValueIndex(values: readonly string[] | undefined, value: unknown): number {\n // No text form (array/object) means no enum member — \"[object Object]\" must\n // not index into the palette.\n const text = fieldTextOrNull(value);\n if (text === null || text === \"\") return -1;\n return values?.indexOf(text) ?? -1;\n}\n\n/** The flagged values when `fieldKey` is the schema's `notifyWhen` target (the\n * \"notification enum\"); undefined for every other field. */\nfunction notifyValuesFor(schema: CollectionSchema, fieldKey: string): readonly string[] | undefined {\n const spec = schema.notifyWhen;\n return spec && spec.field === fieldKey ? spec.in : undefined;\n}\n\n/** Resolve a value's colour for enum field `fieldKey`:\n * - Notification enum (`notifyWhen` targets it): the first flagged value (in\n * `notifyWhen.in` order, the most urgent) reads notification red, the rest\n * amber, and every non-flagged value neutral grey.\n * - Any other enum: the standard palette by the value's declared index. */\nexport function resolveEnumColor(schema: CollectionSchema, fieldKey: string, value: unknown): EnumColorClasses {\n const notifyValues = notifyValuesFor(schema, fieldKey);\n if (notifyValues) {\n const str = fieldText(value);\n const rank = notifyValues.indexOf(str);\n if (rank < 0) return ENUM_NEUTRAL;\n return rank === 0 ? ENUM_ALERT : ENUM_NUDGE;\n }\n const spec = schema.fields[fieldKey];\n return enumColorClasses(enumValueIndex(spec?.type === \"enum\" ? spec.values : undefined, value));\n}\n","// Pure edit-draft logic for the collection record form, extracted from\n// CollectionView.vue so the parent (build draft / save / validate) and\n// the extracted CollectionRecordPanel (per-row table mutators) share one\n// implementation. No Vue, no I/O — every function maps a draft + schema\n// to a value, so the omission/validation semantics are unit-testable.\n\nimport { fieldText } from \"./fieldText\";\nimport { fieldVisible } from \"./actionVisible\";\nimport { COMPUTED_TYPES } from \"./schema\";\nimport type { CollectionFieldSpec as FieldSpec, CollectionFieldType as FieldType, CollectionItem, CollectionSchema } from \"./schema\";\nimport type { EditState, TableRowDraft } from \"./uiTypes\";\n\n/** Build a row draft, reading each sub-field's persisted value via\n * `readSub`. An empty row passes a reader that always returns\n * `undefined`; a row-from-item reads the source record. Boolean\n * presence uses `typeof raw === \"boolean\"` so an existing explicit\n * `false` is recorded as present and round-trips on a no-op save. */\nfunction buildTableRowDraft(subFields: Record<string, FieldSpec>, readSub: (subKey: string) => unknown): TableRowDraft {\n const text: Record<string, string> = {};\n const bool: Record<string, boolean> = {};\n const boolOriginallyPresent: Record<string, boolean> = {};\n const boolTouched: Record<string, boolean> = {};\n for (const [subKey, subField] of Object.entries(subFields)) {\n const raw = readSub(subKey);\n if (subField.type === \"boolean\") {\n bool[subKey] = raw === true;\n boolOriginallyPresent[subKey] = typeof raw === \"boolean\";\n boolTouched[subKey] = false;\n } else {\n text[subKey] = fieldText(raw);\n }\n }\n return { text, bool, boolOriginallyPresent, boolTouched };\n}\n\n/** A fresh, empty row draft for a `table` field's sub-schema. */\nexport function emptyRow(subFields: Record<string, FieldSpec>): TableRowDraft {\n return buildTableRowDraft(subFields, () => undefined);\n}\n\n/** Build a row draft from an existing persisted row. */\nexport function rowFromItem(item: Record<string, unknown>, subFields: Record<string, FieldSpec>): TableRowDraft {\n return buildTableRowDraft(subFields, (subKey) => item[subKey]);\n}\n\n/** Own-property boolean read: a field named `toString` / `constructor` /\n * `__proto__` must read `false` here, not inherit a truthy Object.prototype\n * member and force an untouched boolean into every saved record. */\nfunction ownFlag(flags: Record<string, boolean>, key: string): boolean {\n return Object.hasOwn(flags, key) && flags[key] === true;\n}\n\n/** Decide whether a boolean field's draft value should be emitted (vs.\n * omitted so a downstream default applies). */\nfunction shouldEmitBoolean(state: EditState, key: string, field: FieldSpec): boolean {\n return ownFlag(state.boolOriginallyPresent, key) || ownFlag(state.boolTouched, key) || Boolean(field.required);\n}\n\n/** Convert a scalar draft slot to its persisted form. `undefined` = omit. */\nfunction scalarDraftToValue(raw: string | undefined, fieldType: FieldType): unknown {\n if (raw === undefined || raw === \"\") return undefined;\n if (fieldType === \"number\" || fieldType === \"money\") {\n const num = Number(raw);\n return Number.isFinite(num) ? num : raw;\n }\n return raw;\n}\n\n/** Convert one table row draft to its persisted record. */\nfunction rowDraftToRecord(rowDraft: TableRowDraft, subFields: Record<string, FieldSpec>): Record<string, unknown> {\n const row: Record<string, unknown> = {};\n for (const [subKey, subField] of Object.entries(subFields)) {\n if (subField.type === \"boolean\") {\n const value = ownFlag(rowDraft.bool, subKey);\n if (ownFlag(rowDraft.boolOriginallyPresent, subKey) || ownFlag(rowDraft.boolTouched, subKey) || value || subField.required) row[subKey] = value;\n continue;\n }\n const value = scalarDraftToValue(rowDraft.text[subKey], subField.type);\n if (value !== undefined) row[subKey] = value;\n }\n return row;\n}\n\n/** Convert a full edit draft to the record to persist.\n *\n * Collected as entries rather than assigned into an accumulator: a field may\n * be named `__proto__` (JSON.parse hands that over as an own key, so it\n * reaches here like any other), and `record[key] = value` would run the\n * prototype setter for that one name — the user's value would vanish between\n * the form and the save, with nothing to see. `fromEntries` defines an own\n * property whatever the name is. The read side of this file already guards the\n * same hazard with `ownFlag` (Codex review on #2910). */\nexport function draftToRecord(state: EditState, schema: CollectionSchema): CollectionItem {\n const entries: [string, unknown][] = [];\n for (const [key, field] of Object.entries(schema.fields)) {\n if (COMPUTED_TYPES.has(field.type)) continue; // never persisted (toggle projects an enum field)\n if (field.type === \"boolean\") {\n if (shouldEmitBoolean(state, key, field)) entries.push([key, ownFlag(state.bool, key)]);\n continue;\n }\n if (field.type === \"table\" && field.of) {\n const subFields = field.of;\n entries.push([key, (state.table[key] ?? []).map((rowDraft) => rowDraftToRecord(rowDraft, subFields))]);\n continue;\n }\n const value = scalarDraftToValue(state.text[key], field.type);\n if (value !== undefined) entries.push([key, value]);\n }\n return Object.fromEntries(entries);\n}\n\n/** Normalise a raw inline-edit input (table-cell checkbox/select) to its\n * persisted form. Mirrors `draftToRecord`'s boolean strictness; an empty\n * enum selection (the placeholder option) clears the field via `undefined`. */\nexport function coerceInlineValue(field: FieldSpec, raw: boolean | string): unknown {\n if (field.type === \"boolean\") return raw === true;\n return raw === \"\" ? undefined : raw;\n}\n\n/** Build the full record to PUT for a single-cell inline edit, without\n * mutating `item`. A `undefined` value omits the key (enum cleared),\n * matching `draftToRecord`'s omission semantics. */\nexport function buildUpdatedRecord(item: CollectionItem, key: string, value: unknown): CollectionItem {\n if (value === undefined) {\n const { [key]: __omit, ...rest } = item;\n return rest;\n }\n return { ...item, [key]: value };\n}\n\n/** Empty for required-field validation — NOT a truthiness check (a\n * numeric `0` is a filled value). */\nfunction isMissingDraftValue(value: unknown): boolean {\n return value === undefined || value === null || value === \"\";\n}\n\n/** Label of the first required table sub-field empty in any row, else null. */\nfunction firstMissingTableSubField(field: FieldSpec, rows: TableRowDraft[] | undefined): string | null {\n if (field.type !== \"table\" || !rows) return null;\n for (const [rowIdx, row] of rows.entries()) {\n for (const [subKey, subField] of Object.entries(field.of)) {\n if (!subField.required || subField.type === \"boolean\") continue;\n if (isMissingDraftValue(row.text[subKey])) return `${field.label} #${rowIdx + 1}: ${subField.label}`;\n }\n }\n return null;\n}\n\n/** Field types the required check never flags: booleans always hold a\n * value, and the computed/projected kinds (COMPUTED_TYPES — the shared\n * set, so a future computed type can't drift past this check) have no\n * draft input at all. */\nconst NEVER_MISSING_TYPES: ReadonlySet<FieldType> = new Set<FieldType>([\"boolean\", ...COMPUTED_TYPES]);\n\nfunction validateOneField(key: string, field: FieldSpec, draft: EditState, record: CollectionItem): string | null {\n // A `when`-hidden field has no input the user can fill — never missing.\n if (!fieldVisible(field, record)) return null;\n if (field.type === \"table\" && field.of) {\n const rows = draft.table[key];\n if (field.required && (!rows || rows.length === 0)) return field.label;\n return firstMissingTableSubField(field, rows);\n }\n if (!field.required) return null;\n if (draft.mode === \"create\" && field.primary === true) return null; // server auto-generates id\n if (NEVER_MISSING_TYPES.has(field.type)) return null;\n return isMissingDraftValue(draft.text[key]) ? field.label : null;\n}\n\n/** Human-readable label of the first missing required field, or null. */\nexport function firstMissingRequiredField(draft: EditState, schema: CollectionSchema): string | null {\n const record = draftToRecord(draft, schema);\n for (const [key, field] of Object.entries(schema.fields)) {\n const missing = validateOneField(key, field, draft, record);\n if (missing) return missing;\n }\n return null;\n}\n","// Whether a custom view's `__MC_VIEW.startChat` RUNS the prompt or leaves it as\n// an editable draft (#3062). Pure + its own module so the one reading of the\n// declaration is shared by every surface that renders a view, and is pinned by\n// unit tests rather than by driving an iframe.\n\nimport type { CollectionCustomView } from \"./schema\";\n\n/** True when this view's `startChat` should send. Default-deny: a view that does\n * not declare `allowSendChat` drafts, so upgrading the host can never turn an\n * already-shipped view's buttons into unreviewed agent turns.\n *\n * Read from the SCHEMA — never from the message the iframe posts up. The view's\n * code composes the prompt text; letting it also decide whether that text runs\n * would put both halves of the decision inside the sandbox.\n *\n * The phone runtime does not consult this: it always sends, because a phone has\n * no Enter key for the user to press (receptron/mulmoterminal#1253). The flag\n * governs the desktop custom view and the desktop phone-frame preview. */\nexport function customViewSendsChat(view: Pick<CollectionCustomView, \"allowSendChat\">): boolean {\n return view.allowSendChat === true;\n}\n","// The slash-command chat seed a collection view sends to the agent when the\n// user starts a chat from a skill-backed collection or one of its records.\n// Skill-backed collections have a `/<slug>` command, so seed that. (Feeds are\n// skill-less and seeded differently; that branch stays in the view because it\n// is i18n-driven.)\n\n/** `/<slug> <message>`, or `/<slug> id=<itemId> <message>` when a specific\n * record is addressed. The `id=` selector goes BEFORE the free-text message so\n * the skill's argument parser reads it as a flag rather than as prose. */\nexport function skillCommandSeed(slug: string, message: string, itemId?: string): string {\n return itemId ? `/${slug} id=${itemId} ${message}` : `/${slug} ${message}`;\n}\n","// The one place an index row becomes the `{slug,title,icon,color}` a pinned\n// shortcut reconciles against.\n//\n// Both the collections index and the feeds index did this inline, and the\n// awkward part is identical in each: `color` must be ADDED only when there is\n// one, never assigned as `undefined` — the shortcut shapes declare it narrow\n// (see `CollectionSummary.color`) because the remote-host handlers pass them\n// through `Jsonify`, which drops `undefined` from a member union. Writing that\n// out twice is how the two copies drift.\n\nimport type { CollectionShortcutInfo } from \"./uiTypes\";\n\n/** The fields an index row supplies. Both `CollectionSummary` and\n * `FeedSummary` satisfy it; `icon` is optional because a feed row may carry\n * an empty one and rely on the surface's default. */\nexport interface ShortcutInfoSource {\n slug: string;\n title: string;\n icon?: string | undefined;\n color?: string | undefined;\n}\n\n/** An index row as shortcut-reconcile input. `fallbackIcon` stands in when the\n * row names no icon (feeds do this); `color` is omitted entirely rather than\n * set to `undefined` when the row has none. */\nexport function toShortcutInfo(row: ShortcutInfoSource, fallbackIcon: string): CollectionShortcutInfo {\n return {\n slug: row.slug,\n title: row.title,\n icon: row.icon && row.icon.length > 0 ? row.icon : fallbackIcon,\n ...(row.color === undefined ? {} : { color: row.color }),\n };\n}\n","// Sorting for the collection list table. The header sort toggle (next to\n// each field title) cycles a single active column through none → asc →\n// desc → none; this module turns that state plus a per-field value\n// extractor into an ordered copy of the rows.\n//\n// Two invariants the comparator guarantees:\n// 1. Rows with an empty/missing value for the sorted field always sink\n// to the bottom, regardless of direction.\n// 2. Ties (and the empty group) keep their original order — the sort is\n// stable via the captured source index.\n//\n// Field-type → comparable mapping (see `isSortableField`):\n// string/text/email → string · number/money → numeric ·\n// date/datetime → epoch-ms · enum → declared-index · boolean/toggle/flag →\n// false<true · ref → display label · derived → its display type.\n// markdown/table/image/file/embed get no sort button.\n\nimport { fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionItem, CollectionFieldSpec, CollectionFieldType } from \"./schema\";\n\nexport type SortDirection = \"asc\" | \"desc\";\n\nexport interface SortState {\n /** Field key of the single active sort column. */\n field: string;\n direction: SortDirection;\n}\n\n/** A row's comparable value for the active field. Exactly one of `num` /\n * `str` is set when not empty; `empty` rows always sort last. */\nexport interface SortValue {\n empty: boolean;\n num?: number;\n str?: string;\n}\n\nconst EMPTY: SortValue = { empty: true };\n\n/** Field types that render no value text in the table, so offer no sort. */\nconst NON_SORTABLE: ReadonlySet<CollectionFieldType> = new Set<CollectionFieldType>([\"markdown\", \"table\", \"image\", \"file\", \"embed\", \"backlinks\", \"rollup\"]);\n\nexport function isSortableField(field: CollectionFieldSpec): boolean {\n return !NON_SORTABLE.has(field.type);\n}\n\n/** Cycle one column's state: none → asc → desc → none. */\nexport function nextSortDirection(current: SortDirection | null): SortDirection | null {\n if (current === null) return \"asc\";\n if (current === \"asc\") return \"desc\";\n return null;\n}\n\n// ── SortValue constructors (one per comparable kind) ────────────────\n\nexport function numericSortValue(raw: unknown): SortValue {\n if (raw == null || raw === \"\") return EMPTY;\n const num = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(num) ? { empty: false, num } : EMPTY;\n}\n\nexport function stringSortValue(raw: unknown): SortValue {\n // An array/object has no sort key — treat it as empty (sorts last) instead of\n // grouping every such record together under \"[object Object]\".\n const str = fieldTextOrNull(raw);\n if (str === null) return EMPTY;\n return str.trim() === \"\" ? EMPTY : { empty: false, str };\n}\n\nexport function dateSortValue(raw: unknown): SortValue {\n const text = fieldTextOrNull(raw);\n if (text === null || text === \"\") return EMPTY;\n const epoch = Date.parse(text);\n // Unparseable dates fall back to a lexical compare rather than vanishing.\n return Number.isNaN(epoch) ? stringSortValue(raw) : { empty: false, num: epoch };\n}\n\n/** Enum sorts by the value's index in the declared `values` list. A value\n * outside the list (or unset) is treated as empty → last. */\nexport function enumSortValue(values: readonly string[] | undefined, raw: unknown): SortValue {\n const text = fieldTextOrNull(raw);\n if (text === null || text === \"\") return EMPTY;\n const idx = values ? values.indexOf(text) : -1;\n return idx < 0 ? EMPTY : { empty: false, num: idx };\n}\n\n/** Boolean / toggle: false < true, never empty (unset reads as false). */\nexport function boolSortValue(checked: boolean): SortValue {\n return { empty: false, num: checked ? 1 : 0 };\n}\n\n// ── Comparator + driver ─────────────────────────────────────────────\n\nexport function compareSortValues(left: SortValue, right: SortValue): number {\n if (left.num !== undefined && right.num !== undefined) return left.num - right.num;\n const leftStr = left.str ?? String(left.num ?? \"\");\n const rightStr = right.str ?? String(right.num ?? \"\");\n return leftStr.localeCompare(rightStr);\n}\n\n/** Stable sort of `items` by `valueOf`. Empties always last; ties hold\n * source order. Returns a new array (does not mutate `items`). */\nexport function sortItems(items: readonly CollectionItem[], direction: SortDirection, valueOf: (item: CollectionItem) => SortValue): CollectionItem[] {\n const dir = direction === \"asc\" ? 1 : -1;\n return items\n .map((item, index) => ({ item, index, sv: valueOf(item) }))\n .sort((left, right) => {\n if (left.sv.empty || right.sv.empty) {\n if (left.sv.empty && right.sv.empty) return left.index - right.index;\n return left.sv.empty ? 1 : -1;\n }\n const base = compareSortValues(left.sv, right.sv);\n return base !== 0 ? base * dir : left.index - right.index;\n })\n .map((decorated) => decorated.item);\n}\n","// Field-type → comparable value for the collection list-table sort. Splits\n// the header sort's per-row value extraction out of the Vue view so the\n// dispatch (which field type maps to which SortValue constructor) is testable\n// on its own. The comparators live in `./sortItems`; this module only routes.\n//\n// A few field kinds can't be sorted from the raw cell alone — `toggle` and\n// `flag` are projected booleans, `derived` is a formula, and `ref` sorts by\n// its resolved display label. Those readers live in the view's rendering\n// composable, so they are passed in (dependency injection) rather than\n// imported, keeping this module pure and framework-free.\n\nimport { numericSortValue, stringSortValue, dateSortValue, enumSortValue, boolSortValue, type SortValue } from \"./sortItems\";\nimport type { CollectionItem, CollectionFieldSpec as FieldSpec } from \"./schema\";\n\n/** Resolve a `ref` cell to its human display label (target slug + item id). */\nexport type RefDisplayResolver = (targetSlug: string, itemSlug: string) => string;\n\n/** The row readers the view supplies for the field kinds that can't sort off\n * the raw cell value. All come from the rendering composable. */\nexport interface SortValueDeps {\n toggleChecked: (item: CollectionItem, field: FieldSpec) => boolean;\n flagValueOf: (key: string, item: CollectionItem) => boolean;\n evaluateDerived: (field: FieldSpec, key: string, item: CollectionItem) => number | null;\n deriveRecord: (item: CollectionItem) => CollectionItem;\n resolveRefDisplay: RefDisplayResolver;\n}\n\n/** Comparable value for scalar fields that key off the raw cell value. */\nexport function scalarSortValue(field: FieldSpec, raw: unknown, resolveRefDisplay: RefDisplayResolver): SortValue {\n switch (field.type) {\n case \"number\":\n case \"money\":\n return numericSortValue(raw);\n case \"date\":\n case \"datetime\":\n return dateSortValue(raw);\n case \"enum\":\n return enumSortValue(field.values, raw);\n case \"boolean\":\n return boolSortValue(raw === true);\n case \"ref\":\n return field.to && typeof raw === \"string\" && raw ? stringSortValue(resolveRefDisplay(field.to, raw)) : stringSortValue(raw);\n default:\n return stringSortValue(raw);\n }\n}\n\n/** Derived rows sort by their display type: money/number → numeric,\n * date → epoch, anything else → the enriched value as a string. */\nexport function derivedSortValue(\n field: FieldSpec,\n key: string,\n item: CollectionItem,\n deps: Pick<SortValueDeps, \"evaluateDerived\" | \"deriveRecord\">,\n): SortValue {\n const display = field.type === \"derived\" ? field.display : undefined;\n if (display === undefined || display === \"number\" || display === \"money\") {\n return numericSortValue(deps.evaluateDerived(field, key, item));\n }\n const enriched = deps.deriveRecord(item);\n if (display === \"date\") return dateSortValue(enriched[key]);\n return stringSortValue(enriched[key]);\n}\n\n/** Comparable value for one row under the active field. Toggle, flag, and\n * derived need the whole record; every other type keys off the raw cell. */\nexport function sortValueOf(field: FieldSpec, key: string, item: CollectionItem, deps: SortValueDeps): SortValue {\n if (field.type === \"toggle\") return boolSortValue(deps.toggleChecked(item, field));\n if (field.type === \"flag\") return boolSortValue(deps.flagValueOf(key, item));\n if (field.type === \"derived\") return derivedSortValue(field, key, item, deps);\n return scalarSortValue(field, item[key], deps.resolveRefDisplay);\n}\n","// Free-text record matching for the collection list search box. Pure and\n// framework-free so the view's `filteredItems` computed just calls it.\n\nimport { fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionItem } from \"./schema\";\n\n/** Case-insensitive substring match across an item's scalar fields.\n * Object/array-valued fields (table rows, nested records) have no text\n * form (`fieldTextOrNull` → `null`) and are skipped — they don't render as\n * searchable text in the list table.\n *\n * `query` is matched against each cell's lower-cased text but is NOT\n * lower-cased here: callers pass an already-normalised (trimmed +\n * lower-cased) query, so an upper-case `query` intentionally matches\n * nothing. Keeping the normalisation at the call site avoids re-lowering\n * the same query once per row. */\nexport function itemMatchesQuery(item: CollectionItem, query: string): boolean {\n // An empty query matches every record — otherwise a row whose only fields are\n // object/array-valued (no scalar cell reaches `includes(\"\")`) would vanish\n // when the search box is cleared. The list caller already short-circuits the\n // empty case, so this only guards a future caller that doesn't.\n if (query === \"\") return true;\n return Object.values(item).some((value) => {\n const text = fieldTextOrNull(value);\n return text !== null && text.toLowerCase().includes(query);\n });\n}\n","// Composite cell keys for the list table's per-cell state maps, plus the\n// load-time \"which enum cells were empty\" snapshot the inline enum dropdown\n// reads. Pure and framework-free so the view keeps only the reactive refs.\n\nimport { fieldText } from \"./fieldText\";\nimport type { CollectionItem } from \"./schema\";\n\n/** The schema slice `snapshotEmptyEnums` reads — minimal structural shape so\n * both the client and server collection-schema types satisfy it as-is. */\nexport interface EnumSnapshotSchema {\n fields: Record<string, { type: string }>;\n primaryKey: string;\n}\n\n/** Stable key for one cell (`<rowId>:<fieldKey>`) in the per-cell state maps. */\nexport function cellKey(rowId: string, fieldKey: string): string {\n return `${rowId}:${fieldKey}`;\n}\n\n/** A row's stable identity: the primary-key value as text (`\"\"` when the schema\n * has no primary key, or the value is absent). Every per-row / per-cell state\n * map keys off this, and it is the SAME derivation `snapshotEmptyEnums` uses\n * for its record ids (`fieldText`), so `cellKey(rowIdOf(...), field)` and the\n * empty-enum snapshot always agree. A real primary key is a scalar, so this\n * matches its plain string form. */\nexport function rowIdOf(primaryKey: string | undefined, item: CollectionItem): string {\n return primaryKey ? fieldText(item[primaryKey]) : \"\";\n}\n\n/** The set of enum cells that were empty in the freshly-fetched records — the\n * only cells whose inline dropdown offers an empty option. */\nexport function snapshotEmptyEnums(schema: EnumSnapshotSchema, records: CollectionItem[]): Set<string> {\n const empty = new Set<string>();\n const enumKeys = Object.entries(schema.fields)\n .filter(([, field]) => field.type === \"enum\")\n .map(([fieldKey]) => fieldKey);\n if (enumKeys.length === 0) return empty;\n for (const record of records) {\n const recordId = fieldText(record[schema.primaryKey]);\n for (const fieldKey of enumKeys) {\n if (record[fieldKey] == null || record[fieldKey] === \"\") empty.add(cellKey(recordId, fieldKey));\n }\n }\n return empty;\n}\n","// Shared chip/label resolution for the collection calendar surfaces (month\n// grid + day view), so both label a record identically. Pure, type-only\n// dependency on the schema shape.\n\nimport { fieldText } from \"./fieldText\";\nimport type { CollectionItem, CollectionSchema } from \"./schema\";\n\n// Text-like field types that make a sensible human-readable label.\nconst LABEL_FIELD_TYPES = new Set([\"string\", \"text\", \"markdown\", \"email\"]);\n\n/** Which field labels a record: the schema's explicit `displayField`, else the\n * first non-primary text-like field (so a collection without a displayField\n * shows e.g. the title rather than the opaque primaryKey), else null → the\n * caller falls back to the primary-key value. */\nexport function labelFieldFor(schema: CollectionSchema): string | null {\n if (schema.displayField) return schema.displayField;\n for (const [key, spec] of Object.entries(schema.fields)) {\n if (key !== schema.primaryKey && LABEL_FIELD_TYPES.has(spec.type)) return key;\n }\n return null;\n}\n\n/** A record's primary-key value as a string. */\nexport function itemIdOf(item: CollectionItem, schema: CollectionSchema): string {\n return fieldText(item[schema.primaryKey]);\n}\n\n/** A record's display label: the resolved `labelField` value, else the\n * primary key. Pass the result of `labelFieldFor(schema)` as `labelField`\n * (compute it once per render rather than per item). */\nexport function itemLabelOf(item: CollectionItem, schema: CollectionSchema, labelField: string | null): string {\n if (labelField) {\n const value = item[labelField];\n // Accept any primitive (string / number / boolean) so a numeric or boolean\n // display field still labels the record; objects/arrays fall through to the\n // id rather than rendering as \"[object Object]\".\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n const text = String(value);\n if (text.length > 0) return text;\n }\n }\n return itemIdOf(item, schema);\n}\n","// Pure builder for the workspace ontology graph — the `/collections` Map\n// panel (phase 2 of plans/done/collection-ontology.md step ①; plan:\n// plans/done/feat-collection-ontology-graph.md). Consumes the per-collection\n// ontology entries `buildWorkspaceOntology` derives server-side and turns\n// them into a node/edge structure a graph view can render directly.\n// Browser-safe (no `node:*` imports) so the Vue plugin builds the same\n// graph from the raw entries — same parity discipline as `deriveAll` and\n// the sibling `wiki/graph.ts`.\n\n/** One relationship a schema declares: a `ref` (the record stores the\n * target's primaryKey slug) or `embed` (display-only pull) pointing at\n * collection `to`, or `backlinks` / `rollup` (display-only REVERSE\n * refs — `to` is the relation's source collection, i.e. its `from`,\n * and `via` names the exact ref field there being reversed).\n * A `ref` column inside a `table` field is reported with a dotted path\n * (`lines.clientId`). Whether `to` exists is NOT checked — resolution\n * is fail-soft at render. */\nexport interface OntologyRelation {\n field: string;\n kind: \"ref\" | \"embed\" | \"backlinks\" | \"rollup\";\n to: string;\n via?: string;\n}\n\nexport interface CollectionOntologyEntry {\n slug: string;\n title: string;\n icon: string;\n primaryKey: string;\n /** The effective display field: the schema's `displayField`, falling\n * back to the primaryKey exactly as render-time labelling does. */\n displayField: string;\n /** Records in the collection, or `null` when the backend couldn't be\n * reached to count them (an engine that failed to load, a closed\n * session). Deliberately not 0: an unreachable collection reported as\n * empty invites \"restoring\" data that is intact but out of reach. */\n recordCount: number | null;\n relations: OntologyRelation[];\n}\n\nexport interface OntologyGraphNode {\n slug: string;\n title: string;\n icon: string;\n recordCount: number | null;\n /** No discovered collection has this slug — the node exists only\n * because a relation points at it. Rendered as a ghost so the graph\n * doubles as a broken-ref lint surface (lint, not lock). */\n missing?: boolean;\n}\n\nexport interface OntologyGraphEdge {\n /** Tail: the collection whose records store (`ref`) or pull (`embed`)\n * the link — or, for an uncollapsed reverse relation, the collection\n * whose refs the `backlinks`/`rollup` field aggregates. */\n from: string;\n /** Head: the collection the link points at. */\n to: string;\n /** Field declaring the relation — on `from` for `ref`/`embed`, on\n * `to` for an uncollapsed `backlinks`/`rollup`. */\n field: string;\n kind: OntologyRelation[\"kind\"];\n /** `backlinks`/`rollup` field names on `to` that declare the reverse\n * of this `ref` edge, collapsed here so one link never draws twice. */\n reverseFields?: string[];\n}\n\nexport interface OntologyGraph {\n nodes: OntologyGraphNode[];\n edges: OntologyGraphEdge[];\n}\n\nconst isForwardKind = (kind: OntologyRelation[\"kind\"]): boolean => kind === \"ref\" || kind === \"embed\";\n\n/** Fold a reverse relation (`backlinks`/`rollup` declared on `owner`)\n * into the edge list: collapse onto the forward `ref` edge whose field\n * is the relation's declared `via` (several refs can link the same\n * pair — matches.homeTeam vs matches.awayTeam — so the pair alone is\n * ambiguous), else emit its own edge oriented in true data direction\n * (refs' source → owner). A `via` naming no forward edge stays\n * uncollapsed — fail-soft, like every other dangling reference. */\nconst addReverseRelation = (edges: OntologyGraphEdge[], owner: string, rel: OntologyRelation): void => {\n const forward = edges.find((edge) => edge.kind === \"ref\" && edge.from === rel.to && edge.to === owner && (rel.via === undefined || edge.field === rel.via));\n if (forward) {\n forward.reverseFields = [...(forward.reverseFields ?? []), rel.field];\n return;\n }\n edges.push({ from: rel.to, to: owner, field: rel.field, kind: rel.kind });\n};\n\n/** Two passes so every forward `ref` edge exists before any reverse\n * relation tries to collapse onto one — entry order must not matter. */\nconst collectEdges = (entries: CollectionOntologyEntry[]): OntologyGraphEdge[] => {\n const edges: OntologyGraphEdge[] = [];\n for (const entry of entries) {\n for (const rel of entry.relations) {\n if (isForwardKind(rel.kind)) edges.push({ from: entry.slug, to: rel.to, field: rel.field, kind: rel.kind });\n }\n }\n for (const entry of entries) {\n for (const rel of entry.relations) {\n if (!isForwardKind(rel.kind)) addReverseRelation(edges, entry.slug, rel);\n }\n }\n return edges;\n};\n\n/** Slugs referenced by an edge endpoint but backed by no discovered\n * collection, slug-sorted for deterministic node order. */\nconst ghostSlugs = (edges: OntologyGraphEdge[], known: ReadonlySet<string>): string[] => {\n const ghosts = new Set<string>();\n for (const edge of edges) {\n if (!known.has(edge.from)) ghosts.add(edge.from);\n if (!known.has(edge.to)) ghosts.add(edge.to);\n }\n return [...ghosts].sort();\n};\n\n/** Build the renderable graph: one node per discovered collection (in\n * the entries' slug-sorted order) plus ghost nodes for dangling\n * targets, one edge per underlying link. */\nexport const buildOntologyGraph = (entries: CollectionOntologyEntry[]): OntologyGraph => {\n const edges = collectEdges(entries);\n const known = new Set(entries.map((entry) => entry.slug));\n const nodes: OntologyGraphNode[] = entries.map(({ slug, title, icon, recordCount }) => ({ slug, title, icon, recordCount }));\n for (const slug of ghostSlugs(edges, known)) {\n // A ghost node has no collection behind it at all, so it genuinely holds\n // no records — 0, not the \"couldn't count\" null.\n nodes.push({ slug, title: slug, icon: \"\", recordCount: 0, missing: true });\n }\n return { nodes, edges };\n};\n"],"mappings":";;;;;;;;AAUA,IAAa,YAAY;;;;;;AAsCzB,SAAgB,cAAc,MAA6B,OAAkD;CAC3G,MAAM,UAAU,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;CAC3D,OAAO,QAAQ,SAAS,IAAI;EAAE,GAAG;EAAM,OAAO;CAAQ,IAAI;AAC5D;;;;AAKA,SAAgB,kBAAkB,MAAuE;CACvG,OAAO,KAAK,UAAU,KAAA,IAAY,KAAK,iBAAiB,GAAG,KAAK,MAAM,QAAQ,KAAK;AACrF;;;AAIA,SAAgB,mBACd,KACA,OACS;CACT,OAAO,kBAAkB,GAAG,MAAM,kBAA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E;CAC7C;CACA,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK;AAC1B;;;;AAKA,IAAa,sBAAsB,YAAsD;CACvF,MAAM,QAAQ,aAAa,OAAO;CAClC,MAAM,QAAQ,IAAI,IAAI,QAAQ,KAAK,UAAU,MAAM,IAAI,CAAC;CACxD,MAAM,QAA6B,QAAQ,KAAK,EAAE,MAAM,OAAO,MAAM,mBAAmB;EAAE;EAAM;EAAO;EAAM;CAAY,EAAE;CAC3H,KAAK,MAAM,QAAQ,WAAW,OAAO,KAAK,GAGxC,MAAM,KAAK;EAAE;EAAM,OAAO;EAAM,MAAM;EAAI,aAAa;EAAG,SAAS;CAAK,CAAC;CAE3E,OAAO;EAAE;EAAO;CAAM;AACxB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/collection/core/presentCollection.ts","../../src/collection/core/enumColors.ts","../../src/collection/core/draft.ts","../../src/collection/core/viewChatPolicy.ts","../../src/collection/core/chatSeed.ts","../../src/collection/core/shortcutInfo.ts","../../src/collection/core/sortItems.ts","../../src/collection/core/sortValueOf.ts","../../src/collection/core/textSearch.ts","../../src/collection/core/recordKeys.ts","../../src/collection/core/itemLabel.ts","../../src/collection/core/ontologyGraph.ts"],"sourcesContent":["// presentCollection tool — definition + pure server-side executor.\n//\n// Isomorphic (no Vue, no Node): bundled to the browser as the plugin's\n// `execute`, and run server-side via the host's plugin dispatch route. The\n// executor only validates + echoes the addressing; the live schema + items\n// are fetched client-side by the View through the host's /api/collections\n// routes, so a bad slug surfaces as the View's \"not found\" state.\n\nimport type { ToolContext, ToolDefinition, ToolResult } from \"gui-chat-protocol\";\n\nexport const TOOL_NAME = \"presentCollection\";\n\n/** Render payload carried in the tool result's `data` field; the View mounts\n * off these. Same shape as the tool args. */\nexport interface PresentCollectionData {\n /** Slug of the collection to display (e.g. \"clients\", \"invoices\"). */\n collectionSlug: string;\n /** Optional primary-key value of a single item to open on mount. */\n itemId?: string | undefined;\n /** Which ROOT this card's collection lives in, as a host-opaque scope token.\n *\n * A collection's identity is `(root, slug)`, but a card payload named only\n * the slug — so the host re-resolved it through whatever binding was current\n * when the card RENDERED, which in a multi-root host may be a different\n * project than the one the card was made in. A card built in project A could\n * then read project B's data.\n *\n * **Stamped by the HOST, never accepted from tool arguments.** The tool args\n * are a model-controlled channel: a model that could name the scope could\n * name another project's, and the card — and any token minted for it — would\n * address a project the user never opened in this conversation. So\n * `executePresentCollection` DROPS any `scope` it is handed, and a host adds\n * its own with {@link withCardScope} when it applies the result, where it\n * already knows which binding produced the call.\n *\n * Host-opaque: pass an opaque project id, NEVER an absolute path — this\n * payload reaches the browser and, through a view, an LLM-authored iframe.\n *\n * Absent — the single-workspace case — the payload and every reconciliation\n * decision are exactly what they were before this field existed. */\n scope?: string | undefined;\n}\n\n/** Stamp a host's opaque project scope onto a card payload. The ONLY way a\n * scope gets in: the executor refuses to take one from tool arguments (see\n * `PresentCollectionData.scope`). `undefined` returns the payload untouched,\n * so a single-workspace host calling this unconditionally still produces a\n * payload with no `scope` property at all. */\nexport function withCardScope(data: PresentCollectionData, scope: string | undefined): PresentCollectionData {\n const trimmed = typeof scope === \"string\" ? scope.trim() : \"\";\n return trimmed.length > 0 ? { ...data, scope: trimmed } : data;\n}\n\n/** A card's identity for reconciliation. Two cards match only when they name\n * the same collection IN THE SAME SCOPE, so two projects' `tasks` cards stay\n * two cards. With no scope on either side this is the slug, unchanged. */\nexport function collectionCardKey(data: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">): string {\n return data.scope === undefined ? data.collectionSlug : `${data.scope}\\u0000${data.collectionSlug}`;\n}\n\n/** Do two card payloads address the same card? The reconciliation predicate a\n * host should use instead of comparing slugs. */\nexport function sameCollectionCard(\n one: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">,\n other: Pick<PresentCollectionData, \"collectionSlug\" | \"scope\">,\n): boolean {\n return collectionCardKey(one) === collectionCardKey(other);\n}\n\nexport type PresentCollectionArgs = PresentCollectionData;\n\nexport const TOOL_DEFINITION: ToolDefinition = {\n type: \"function\",\n name: TOOL_NAME,\n description:\n \"Display a schema-driven collection inline in the chat as an interactive, editable card. Shows the collection's list of records. Pass `itemId` to open one specific record on mount.\",\n parameters: {\n type: \"object\",\n properties: {\n collectionSlug: {\n type: \"string\",\n description: \"The slug of the collection to display (e.g. 'clients', 'invoices', 'contacts').\",\n },\n itemId: {\n type: \"string\",\n description: \"Optional primary-key value of a single record to open in detail view on mount. Omit to show the full list.\",\n },\n },\n required: [\"collectionSlug\"],\n },\n prompt: `After making changes to schema-driven collections, use ${TOOL_NAME} to present either the collection or the item`,\n};\n\n/** A trimmed non-empty string, or undefined. The tool's args arrive from an\n * LLM (and `scope` from the host), so every field is validated the same way\n * rather than trusted. */\nconst cleaned = (value: unknown): string | undefined => (typeof value === \"string\" && value.trim().length > 0 ? value.trim() : undefined);\n\n/** Normalise the tool args into the card payload, or `null` when the required\n * slug is missing. Pure and exported so the addressing rules are testable\n * without going through a `ToolResult`.\n *\n * `scope` is deliberately NOT read from the args — see\n * `PresentCollectionData.scope`. Everything here comes from a model-controlled\n * channel, and the scope decides which project the card reads; a host stamps\n * it afterwards with `withCardScope`.\n *\n * Keys are added one at a time rather than spread with `undefined` values, so\n * a payload with no `itemId` OMITS the property entirely — which is what keeps\n * a single-workspace card byte-identical to what it has always been, in both\n * `deepEqual` and JSON. */\nexport const toPresentCollectionData = (args: PresentCollectionArgs): PresentCollectionData | null => {\n const collectionSlug = cleaned(args?.collectionSlug);\n if (!collectionSlug) return null;\n const itemId = cleaned(args.itemId);\n return { collectionSlug, ...(itemId ? { itemId } : {}) };\n};\n\nexport const executePresentCollection = async (\n _context: ToolContext,\n args: PresentCollectionArgs,\n): Promise<ToolResult<PresentCollectionData, PresentCollectionData>> => {\n const data = toPresentCollectionData(args);\n if (!data) {\n return {\n message: \"presentCollection error: collectionSlug is required\",\n instructions: \"Tell the user you couldn't display the collection because no collection was specified, and ask which collection they mean.\",\n };\n }\n const { collectionSlug, itemId } = data;\n const target = itemId ? `${collectionSlug} / ${itemId}` : collectionSlug;\n return {\n message: `Presented collection ${target}`,\n // `data` is the view's source (also the host's render-eligibility signal);\n // `jsonData` is what the LLM sees. Same payload, two audiences.\n data,\n jsonData: data,\n // Phrased to stay correct for BOTH storage kinds without loading the\n // schema (this executor is deliberately pure/isomorphic): a writable\n // collection offers edit/create/delete in the card; a read-only\n // `dataSource` collection hides those and changes flow through its\n // data file instead.\n instructions:\n \"The collection has been presented to the user as an interactive card. They can browse and open records directly; on a writable collection they can also edit, create, and delete (a read-only dataSource collection shows no edit controls — its records change by editing the backing data file). No further action is needed unless they ask.\",\n };\n};\n","// A standard, ordered colour palette for `enum` field values, shared by every\n// collection surface (list, calendar, kanban). Each value in an\n// enum's `values` array is assigned the palette entry at its index — cycling\n// when an enum declares more values than the palette holds — so colouring is\n// automatic and consistent without any per-value schema config.\n//\n// Tailwind only detects class names that appear as complete string literals,\n// so every surface's classes are spelled out per colour below rather than\n// built from a colour name at runtime.\n//\n// One enum is special: the field a schema's `notifyWhen` targets (the\n// \"notification enum\"). Its flagged values read the notification severity\n// colours — the first flagged value (most urgent) red, the rest amber — and\n// every other value reads neutral grey, mirroring the notification bell\n// (red = urgent, amber = nudge) rather than the rotating palette.\n// `resolveEnumColor` encapsulates that rule.\n\nimport { fieldText, fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionSchema } from \"./schema\";\n\nexport interface EnumColorClasses {\n /** Stat-card style: border + fill + text + hover. */\n card: string;\n /** Small status dot (kanban column header). */\n dot: string;\n /** Pill / badge / inline `<select>` fill + text (no border width). */\n badge: string;\n /** Border colour, paired with a `border` width class by the caller. */\n border: string;\n}\n\n// The palette deliberately EXCLUDES the warm warning band (red / orange /\n// amber): those are reserved for the notification-enum severity colours\n// (`ENUM_ALERT` red, `ENUM_NUDGE` amber), so a normal enum value can never\n// draw a colour that reads like a notification. Eight well-separated cool /\n// green / magenta hues keep enough variety for wide enums.\nconst PALETTE: readonly EnumColorClasses[] = [\n {\n card: \"border-indigo-200 bg-indigo-50 text-indigo-600 hover:bg-indigo-100\",\n dot: \"bg-indigo-500\",\n badge: \"bg-indigo-100 text-indigo-700\",\n border: \"border-indigo-200\",\n },\n { card: \"border-sky-200 bg-sky-50 text-sky-600 hover:bg-sky-100\", dot: \"bg-sky-500\", badge: \"bg-sky-100 text-sky-700\", border: \"border-sky-200\" },\n { card: \"border-cyan-200 bg-cyan-50 text-cyan-600 hover:bg-cyan-100\", dot: \"bg-cyan-500\", badge: \"bg-cyan-100 text-cyan-700\", border: \"border-cyan-200\" },\n { card: \"border-teal-200 bg-teal-50 text-teal-600 hover:bg-teal-100\", dot: \"bg-teal-500\", badge: \"bg-teal-100 text-teal-700\", border: \"border-teal-200\" },\n {\n card: \"border-emerald-200 bg-emerald-50 text-emerald-600 hover:bg-emerald-100\",\n dot: \"bg-emerald-500\",\n badge: \"bg-emerald-100 text-emerald-700\",\n border: \"border-emerald-200\",\n },\n { card: \"border-lime-200 bg-lime-50 text-lime-600 hover:bg-lime-100\", dot: \"bg-lime-500\", badge: \"bg-lime-100 text-lime-700\", border: \"border-lime-200\" },\n {\n card: \"border-violet-200 bg-violet-50 text-violet-600 hover:bg-violet-100\",\n dot: \"bg-violet-500\",\n badge: \"bg-violet-100 text-violet-700\",\n border: \"border-violet-200\",\n },\n {\n card: \"border-fuchsia-200 bg-fuchsia-50 text-fuchsia-600 hover:bg-fuchsia-100\",\n dot: \"bg-fuchsia-500\",\n badge: \"bg-fuchsia-100 text-fuchsia-700\",\n border: \"border-fuchsia-200\",\n },\n];\n\n/** Neutral styling for the empty / Uncategorized bucket — never a palette\n * colour, so an unset or unknown value reads grey across every surface. */\nexport const ENUM_NEUTRAL: EnumColorClasses = {\n card: \"border-slate-200 bg-slate-50 text-slate-500 hover:bg-slate-100\",\n dot: \"bg-slate-300\",\n badge: \"bg-slate-100 text-slate-500\",\n border: \"border-slate-200\",\n};\n\n/** The urgent notification colour (red), matching the bell's `urgent`\n * severity. The first value a schema's `notifyWhen` flags reads this. */\nexport const ENUM_ALERT: EnumColorClasses = {\n card: \"border-red-200 bg-red-50 text-red-600 hover:bg-red-100\",\n dot: \"bg-red-500\",\n badge: \"bg-red-100 text-red-700\",\n border: \"border-red-200\",\n};\n\n/** The nudge notification colour (amber), matching the bell's `nudge`\n * severity. Flagged `notifyWhen` values after the first read this. */\nexport const ENUM_NUDGE: EnumColorClasses = {\n card: \"border-amber-200 bg-amber-50 text-amber-600 hover:bg-amber-100\",\n dot: \"bg-amber-500\",\n badge: \"bg-amber-100 text-amber-700\",\n border: \"border-amber-200\",\n};\n\n/** Classes for the enum value at `index` in its field's `values` array. A\n * negative index (value unset or not among the declared values) reads\n * neutral. */\nexport function enumColorClasses(index: number): EnumColorClasses {\n if (index < 0) return ENUM_NEUTRAL;\n return PALETTE[index % PALETTE.length] ?? ENUM_NEUTRAL;\n}\n\n/** Index of `value` within an enum field's declared `values`, or -1 when the\n * value is empty / unknown (→ neutral). */\nexport function enumValueIndex(values: readonly string[] | undefined, value: unknown): number {\n // No text form (array/object) means no enum member — \"[object Object]\" must\n // not index into the palette.\n const text = fieldTextOrNull(value);\n if (text === null || text === \"\") return -1;\n return values?.indexOf(text) ?? -1;\n}\n\n/** The flagged values when `fieldKey` is the schema's `notifyWhen` target (the\n * \"notification enum\"); undefined for every other field. */\nfunction notifyValuesFor(schema: CollectionSchema, fieldKey: string): readonly string[] | undefined {\n const spec = schema.notifyWhen;\n return spec && spec.field === fieldKey ? spec.in : undefined;\n}\n\n/** Resolve a value's colour for enum field `fieldKey`:\n * - Notification enum (`notifyWhen` targets it): the first flagged value (in\n * `notifyWhen.in` order, the most urgent) reads notification red, the rest\n * amber, and every non-flagged value neutral grey.\n * - Any other enum: the standard palette by the value's declared index. */\nexport function resolveEnumColor(schema: CollectionSchema, fieldKey: string, value: unknown): EnumColorClasses {\n const notifyValues = notifyValuesFor(schema, fieldKey);\n if (notifyValues) {\n const str = fieldText(value);\n const rank = notifyValues.indexOf(str);\n if (rank < 0) return ENUM_NEUTRAL;\n return rank === 0 ? ENUM_ALERT : ENUM_NUDGE;\n }\n const spec = schema.fields[fieldKey];\n return enumColorClasses(enumValueIndex(spec?.type === \"enum\" ? spec.values : undefined, value));\n}\n","// Pure edit-draft logic for the collection record form, extracted from\n// CollectionView.vue so the parent (build draft / save / validate) and\n// the extracted CollectionRecordPanel (per-row table mutators) share one\n// implementation. No Vue, no I/O — every function maps a draft + schema\n// to a value, so the omission/validation semantics are unit-testable.\n\nimport { fieldText } from \"./fieldText\";\nimport { fieldVisible } from \"./actionVisible\";\nimport { COMPUTED_TYPES } from \"./schema\";\nimport type { CollectionFieldSpec as FieldSpec, CollectionFieldType as FieldType, CollectionItem, CollectionSchema } from \"./schema\";\nimport type { EditState, TableRowDraft } from \"./uiTypes\";\n\n/** Build a row draft, reading each sub-field's persisted value via\n * `readSub`. An empty row passes a reader that always returns\n * `undefined`; a row-from-item reads the source record. Boolean\n * presence uses `typeof raw === \"boolean\"` so an existing explicit\n * `false` is recorded as present and round-trips on a no-op save. */\nfunction buildTableRowDraft(subFields: Record<string, FieldSpec>, readSub: (subKey: string) => unknown): TableRowDraft {\n const text: Record<string, string> = {};\n const bool: Record<string, boolean> = {};\n const boolOriginallyPresent: Record<string, boolean> = {};\n const boolTouched: Record<string, boolean> = {};\n for (const [subKey, subField] of Object.entries(subFields)) {\n const raw = readSub(subKey);\n if (subField.type === \"boolean\") {\n bool[subKey] = raw === true;\n boolOriginallyPresent[subKey] = typeof raw === \"boolean\";\n boolTouched[subKey] = false;\n } else {\n text[subKey] = fieldText(raw);\n }\n }\n return { text, bool, boolOriginallyPresent, boolTouched };\n}\n\n/** A fresh, empty row draft for a `table` field's sub-schema. */\nexport function emptyRow(subFields: Record<string, FieldSpec>): TableRowDraft {\n return buildTableRowDraft(subFields, () => undefined);\n}\n\n/** Build a row draft from an existing persisted row. */\nexport function rowFromItem(item: Record<string, unknown>, subFields: Record<string, FieldSpec>): TableRowDraft {\n return buildTableRowDraft(subFields, (subKey) => item[subKey]);\n}\n\n/** Own-property boolean read: a field named `toString` / `constructor` /\n * `__proto__` must read `false` here, not inherit a truthy Object.prototype\n * member and force an untouched boolean into every saved record. */\nfunction ownFlag(flags: Record<string, boolean>, key: string): boolean {\n return Object.hasOwn(flags, key) && flags[key] === true;\n}\n\n/** Decide whether a boolean field's draft value should be emitted (vs.\n * omitted so a downstream default applies). */\nfunction shouldEmitBoolean(state: EditState, key: string, field: FieldSpec): boolean {\n return ownFlag(state.boolOriginallyPresent, key) || ownFlag(state.boolTouched, key) || Boolean(field.required);\n}\n\n/** Convert a scalar draft slot to its persisted form. `undefined` = omit. */\nfunction scalarDraftToValue(raw: string | undefined, fieldType: FieldType): unknown {\n if (raw === undefined || raw === \"\") return undefined;\n if (fieldType === \"number\" || fieldType === \"money\") {\n const num = Number(raw);\n return Number.isFinite(num) ? num : raw;\n }\n return raw;\n}\n\n/** Convert one table row draft to its persisted record. */\nfunction rowDraftToRecord(rowDraft: TableRowDraft, subFields: Record<string, FieldSpec>): Record<string, unknown> {\n const row: Record<string, unknown> = {};\n for (const [subKey, subField] of Object.entries(subFields)) {\n if (subField.type === \"boolean\") {\n const value = ownFlag(rowDraft.bool, subKey);\n if (ownFlag(rowDraft.boolOriginallyPresent, subKey) || ownFlag(rowDraft.boolTouched, subKey) || value || subField.required) row[subKey] = value;\n continue;\n }\n const value = scalarDraftToValue(rowDraft.text[subKey], subField.type);\n if (value !== undefined) row[subKey] = value;\n }\n return row;\n}\n\n/** Convert a full edit draft to the record to persist.\n *\n * Collected as entries rather than assigned into an accumulator: a field may\n * be named `__proto__` (JSON.parse hands that over as an own key, so it\n * reaches here like any other), and `record[key] = value` would run the\n * prototype setter for that one name — the user's value would vanish between\n * the form and the save, with nothing to see. `fromEntries` defines an own\n * property whatever the name is. The read side of this file already guards the\n * same hazard with `ownFlag` (Codex review on #2910). */\nexport function draftToRecord(state: EditState, schema: CollectionSchema): CollectionItem {\n const entries: [string, unknown][] = [];\n for (const [key, field] of Object.entries(schema.fields)) {\n if (COMPUTED_TYPES.has(field.type)) continue; // never persisted (toggle projects an enum field)\n if (field.type === \"boolean\") {\n if (shouldEmitBoolean(state, key, field)) entries.push([key, ownFlag(state.bool, key)]);\n continue;\n }\n if (field.type === \"table\" && field.of) {\n const subFields = field.of;\n entries.push([key, (state.table[key] ?? []).map((rowDraft) => rowDraftToRecord(rowDraft, subFields))]);\n continue;\n }\n const value = scalarDraftToValue(state.text[key], field.type);\n if (value !== undefined) entries.push([key, value]);\n }\n return Object.fromEntries(entries);\n}\n\n/** Normalise a raw inline-edit input (table-cell checkbox/select) to its\n * persisted form. Mirrors `draftToRecord`'s boolean strictness; an empty\n * enum selection (the placeholder option) clears the field via `undefined`. */\nexport function coerceInlineValue(field: FieldSpec, raw: boolean | string): unknown {\n if (field.type === \"boolean\") return raw === true;\n return raw === \"\" ? undefined : raw;\n}\n\n/** Build the full record to PUT for a single-cell inline edit, without\n * mutating `item`. A `undefined` value omits the key (enum cleared),\n * matching `draftToRecord`'s omission semantics. */\nexport function buildUpdatedRecord(item: CollectionItem, key: string, value: unknown): CollectionItem {\n if (value === undefined) {\n const { [key]: __omit, ...rest } = item;\n return rest;\n }\n return { ...item, [key]: value };\n}\n\n/** Empty for required-field validation — NOT a truthiness check (a\n * numeric `0` is a filled value). */\nfunction isMissingDraftValue(value: unknown): boolean {\n return value === undefined || value === null || value === \"\";\n}\n\n/** Label of the first required table sub-field empty in any row, else null. */\nfunction firstMissingTableSubField(field: FieldSpec, rows: TableRowDraft[] | undefined): string | null {\n if (field.type !== \"table\" || !rows) return null;\n for (const [rowIdx, row] of rows.entries()) {\n for (const [subKey, subField] of Object.entries(field.of)) {\n if (!subField.required || subField.type === \"boolean\") continue;\n if (isMissingDraftValue(row.text[subKey])) return `${field.label} #${rowIdx + 1}: ${subField.label}`;\n }\n }\n return null;\n}\n\n/** Field types the required check never flags: booleans always hold a\n * value, and the computed/projected kinds (COMPUTED_TYPES — the shared\n * set, so a future computed type can't drift past this check) have no\n * draft input at all. */\nconst NEVER_MISSING_TYPES: ReadonlySet<FieldType> = new Set<FieldType>([\"boolean\", ...COMPUTED_TYPES]);\n\nfunction validateOneField(key: string, field: FieldSpec, draft: EditState, record: CollectionItem): string | null {\n // A `when`-hidden field has no input the user can fill — never missing.\n if (!fieldVisible(field, record)) return null;\n if (field.type === \"table\" && field.of) {\n const rows = draft.table[key];\n if (field.required && (!rows || rows.length === 0)) return field.label;\n return firstMissingTableSubField(field, rows);\n }\n if (!field.required) return null;\n if (draft.mode === \"create\" && field.primary === true) return null; // server auto-generates id\n if (NEVER_MISSING_TYPES.has(field.type)) return null;\n return isMissingDraftValue(draft.text[key]) ? field.label : null;\n}\n\n/** Human-readable label of the first missing required field, or null. */\nexport function firstMissingRequiredField(draft: EditState, schema: CollectionSchema): string | null {\n const record = draftToRecord(draft, schema);\n for (const [key, field] of Object.entries(schema.fields)) {\n const missing = validateOneField(key, field, draft, record);\n if (missing) return missing;\n }\n return null;\n}\n","// Whether a custom view's `__MC_VIEW.startChat` RUNS the prompt or leaves it as\n// an editable draft (#3062). Pure + its own module so the one reading of the\n// declaration is shared by every surface that renders a view, and is pinned by\n// unit tests rather than by driving an iframe.\n\nimport type { CollectionCustomView } from \"./schema\";\n\n/** True when this view's `startChat` should send. Default-deny: a view that does\n * not declare `allowSendChat` drafts, so upgrading the host can never turn an\n * already-shipped view's buttons into unreviewed agent turns.\n *\n * Read from the SCHEMA — never from the message the iframe posts up. The view's\n * code composes the prompt text; letting it also decide whether that text runs\n * would put both halves of the decision inside the sandbox.\n *\n * EVERY surface consults this, the phone included. The phone once always sent,\n * on the grounds that it has no Enter key to press — but that made the same\n * view behave differently depending on where it was opened, and it silently\n * overrode default-deny on a device the author never tested. The phone is\n * served the resolved flag in its view payload rather than re-reading the\n * schema, because it never sees the schema. */\nexport function customViewSendsChat(view: Pick<CollectionCustomView, \"allowSendChat\">): boolean {\n return view.allowSendChat === true;\n}\n","// The slash-command chat seed a collection view sends to the agent when the\n// user starts a chat from a skill-backed collection or one of its records.\n// Skill-backed collections have a `/<slug>` command, so seed that. (Feeds are\n// skill-less and seeded differently; that branch stays in the view because it\n// is i18n-driven.)\n\n/** `/<slug> <message>`, or `/<slug> id=<itemId> <message>` when a specific\n * record is addressed. The `id=` selector goes BEFORE the free-text message so\n * the skill's argument parser reads it as a flag rather than as prose. */\nexport function skillCommandSeed(slug: string, message: string, itemId?: string): string {\n return itemId ? `/${slug} id=${itemId} ${message}` : `/${slug} ${message}`;\n}\n","// The one place an index row becomes the `{slug,title,icon,color}` a pinned\n// shortcut reconciles against.\n//\n// Both the collections index and the feeds index did this inline, and the\n// awkward part is identical in each: `color` must be ADDED only when there is\n// one, never assigned as `undefined` — the shortcut shapes declare it narrow\n// (see `CollectionSummary.color`) because the remote-host handlers pass them\n// through `Jsonify`, which drops `undefined` from a member union. Writing that\n// out twice is how the two copies drift.\n\nimport type { CollectionShortcutInfo } from \"./uiTypes\";\n\n/** The fields an index row supplies. Both `CollectionSummary` and\n * `FeedSummary` satisfy it; `icon` is optional because a feed row may carry\n * an empty one and rely on the surface's default. */\nexport interface ShortcutInfoSource {\n slug: string;\n title: string;\n icon?: string | undefined;\n color?: string | undefined;\n}\n\n/** An index row as shortcut-reconcile input. `fallbackIcon` stands in when the\n * row names no icon (feeds do this); `color` is omitted entirely rather than\n * set to `undefined` when the row has none. */\nexport function toShortcutInfo(row: ShortcutInfoSource, fallbackIcon: string): CollectionShortcutInfo {\n return {\n slug: row.slug,\n title: row.title,\n icon: row.icon && row.icon.length > 0 ? row.icon : fallbackIcon,\n ...(row.color === undefined ? {} : { color: row.color }),\n };\n}\n","// Sorting for the collection list table. The header sort toggle (next to\n// each field title) cycles a single active column through none → asc →\n// desc → none; this module turns that state plus a per-field value\n// extractor into an ordered copy of the rows.\n//\n// Two invariants the comparator guarantees:\n// 1. Rows with an empty/missing value for the sorted field always sink\n// to the bottom, regardless of direction.\n// 2. Ties (and the empty group) keep their original order — the sort is\n// stable via the captured source index.\n//\n// Field-type → comparable mapping (see `isSortableField`):\n// string/text/email → string · number/money → numeric ·\n// date/datetime → epoch-ms · enum → declared-index · boolean/toggle/flag →\n// false<true · ref → display label · derived → its display type.\n// markdown/table/image/file/embed get no sort button.\n\nimport { fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionItem, CollectionFieldSpec, CollectionFieldType } from \"./schema\";\n\nexport type SortDirection = \"asc\" | \"desc\";\n\nexport interface SortState {\n /** Field key of the single active sort column. */\n field: string;\n direction: SortDirection;\n}\n\n/** A row's comparable value for the active field. Exactly one of `num` /\n * `str` is set when not empty; `empty` rows always sort last. */\nexport interface SortValue {\n empty: boolean;\n num?: number;\n str?: string;\n}\n\nconst EMPTY: SortValue = { empty: true };\n\n/** Field types that render no value text in the table, so offer no sort. */\nconst NON_SORTABLE: ReadonlySet<CollectionFieldType> = new Set<CollectionFieldType>([\"markdown\", \"table\", \"image\", \"file\", \"embed\", \"backlinks\", \"rollup\"]);\n\nexport function isSortableField(field: CollectionFieldSpec): boolean {\n return !NON_SORTABLE.has(field.type);\n}\n\n/** Cycle one column's state: none → asc → desc → none. */\nexport function nextSortDirection(current: SortDirection | null): SortDirection | null {\n if (current === null) return \"asc\";\n if (current === \"asc\") return \"desc\";\n return null;\n}\n\n// ── SortValue constructors (one per comparable kind) ────────────────\n\nexport function numericSortValue(raw: unknown): SortValue {\n if (raw == null || raw === \"\") return EMPTY;\n const num = typeof raw === \"number\" ? raw : Number(raw);\n return Number.isFinite(num) ? { empty: false, num } : EMPTY;\n}\n\nexport function stringSortValue(raw: unknown): SortValue {\n // An array/object has no sort key — treat it as empty (sorts last) instead of\n // grouping every such record together under \"[object Object]\".\n const str = fieldTextOrNull(raw);\n if (str === null) return EMPTY;\n return str.trim() === \"\" ? EMPTY : { empty: false, str };\n}\n\nexport function dateSortValue(raw: unknown): SortValue {\n const text = fieldTextOrNull(raw);\n if (text === null || text === \"\") return EMPTY;\n const epoch = Date.parse(text);\n // Unparseable dates fall back to a lexical compare rather than vanishing.\n return Number.isNaN(epoch) ? stringSortValue(raw) : { empty: false, num: epoch };\n}\n\n/** Enum sorts by the value's index in the declared `values` list. A value\n * outside the list (or unset) is treated as empty → last. */\nexport function enumSortValue(values: readonly string[] | undefined, raw: unknown): SortValue {\n const text = fieldTextOrNull(raw);\n if (text === null || text === \"\") return EMPTY;\n const idx = values ? values.indexOf(text) : -1;\n return idx < 0 ? EMPTY : { empty: false, num: idx };\n}\n\n/** Boolean / toggle: false < true, never empty (unset reads as false). */\nexport function boolSortValue(checked: boolean): SortValue {\n return { empty: false, num: checked ? 1 : 0 };\n}\n\n// ── Comparator + driver ─────────────────────────────────────────────\n\nexport function compareSortValues(left: SortValue, right: SortValue): number {\n if (left.num !== undefined && right.num !== undefined) return left.num - right.num;\n const leftStr = left.str ?? String(left.num ?? \"\");\n const rightStr = right.str ?? String(right.num ?? \"\");\n return leftStr.localeCompare(rightStr);\n}\n\n/** Stable sort of `items` by `valueOf`. Empties always last; ties hold\n * source order. Returns a new array (does not mutate `items`). */\nexport function sortItems(items: readonly CollectionItem[], direction: SortDirection, valueOf: (item: CollectionItem) => SortValue): CollectionItem[] {\n const dir = direction === \"asc\" ? 1 : -1;\n return items\n .map((item, index) => ({ item, index, sv: valueOf(item) }))\n .sort((left, right) => {\n if (left.sv.empty || right.sv.empty) {\n if (left.sv.empty && right.sv.empty) return left.index - right.index;\n return left.sv.empty ? 1 : -1;\n }\n const base = compareSortValues(left.sv, right.sv);\n return base !== 0 ? base * dir : left.index - right.index;\n })\n .map((decorated) => decorated.item);\n}\n","// Field-type → comparable value for the collection list-table sort. Splits\n// the header sort's per-row value extraction out of the Vue view so the\n// dispatch (which field type maps to which SortValue constructor) is testable\n// on its own. The comparators live in `./sortItems`; this module only routes.\n//\n// A few field kinds can't be sorted from the raw cell alone — `toggle` and\n// `flag` are projected booleans, `derived` is a formula, and `ref` sorts by\n// its resolved display label. Those readers live in the view's rendering\n// composable, so they are passed in (dependency injection) rather than\n// imported, keeping this module pure and framework-free.\n\nimport { numericSortValue, stringSortValue, dateSortValue, enumSortValue, boolSortValue, type SortValue } from \"./sortItems\";\nimport type { CollectionItem, CollectionFieldSpec as FieldSpec } from \"./schema\";\n\n/** Resolve a `ref` cell to its human display label (target slug + item id). */\nexport type RefDisplayResolver = (targetSlug: string, itemSlug: string) => string;\n\n/** The row readers the view supplies for the field kinds that can't sort off\n * the raw cell value. All come from the rendering composable. */\nexport interface SortValueDeps {\n toggleChecked: (item: CollectionItem, field: FieldSpec) => boolean;\n flagValueOf: (key: string, item: CollectionItem) => boolean;\n evaluateDerived: (field: FieldSpec, key: string, item: CollectionItem) => number | null;\n deriveRecord: (item: CollectionItem) => CollectionItem;\n resolveRefDisplay: RefDisplayResolver;\n}\n\n/** Comparable value for scalar fields that key off the raw cell value. */\nexport function scalarSortValue(field: FieldSpec, raw: unknown, resolveRefDisplay: RefDisplayResolver): SortValue {\n switch (field.type) {\n case \"number\":\n case \"money\":\n return numericSortValue(raw);\n case \"date\":\n case \"datetime\":\n return dateSortValue(raw);\n case \"enum\":\n return enumSortValue(field.values, raw);\n case \"boolean\":\n return boolSortValue(raw === true);\n case \"ref\":\n return field.to && typeof raw === \"string\" && raw ? stringSortValue(resolveRefDisplay(field.to, raw)) : stringSortValue(raw);\n default:\n return stringSortValue(raw);\n }\n}\n\n/** Derived rows sort by their display type: money/number → numeric,\n * date → epoch, anything else → the enriched value as a string. */\nexport function derivedSortValue(\n field: FieldSpec,\n key: string,\n item: CollectionItem,\n deps: Pick<SortValueDeps, \"evaluateDerived\" | \"deriveRecord\">,\n): SortValue {\n const display = field.type === \"derived\" ? field.display : undefined;\n if (display === undefined || display === \"number\" || display === \"money\") {\n return numericSortValue(deps.evaluateDerived(field, key, item));\n }\n const enriched = deps.deriveRecord(item);\n if (display === \"date\") return dateSortValue(enriched[key]);\n return stringSortValue(enriched[key]);\n}\n\n/** Comparable value for one row under the active field. Toggle, flag, and\n * derived need the whole record; every other type keys off the raw cell. */\nexport function sortValueOf(field: FieldSpec, key: string, item: CollectionItem, deps: SortValueDeps): SortValue {\n if (field.type === \"toggle\") return boolSortValue(deps.toggleChecked(item, field));\n if (field.type === \"flag\") return boolSortValue(deps.flagValueOf(key, item));\n if (field.type === \"derived\") return derivedSortValue(field, key, item, deps);\n return scalarSortValue(field, item[key], deps.resolveRefDisplay);\n}\n","// Free-text record matching for the collection list search box. Pure and\n// framework-free so the view's `filteredItems` computed just calls it.\n\nimport { fieldTextOrNull } from \"./fieldText\";\nimport type { CollectionItem } from \"./schema\";\n\n/** Case-insensitive substring match across an item's scalar fields.\n * Object/array-valued fields (table rows, nested records) have no text\n * form (`fieldTextOrNull` → `null`) and are skipped — they don't render as\n * searchable text in the list table.\n *\n * `query` is matched against each cell's lower-cased text but is NOT\n * lower-cased here: callers pass an already-normalised (trimmed +\n * lower-cased) query, so an upper-case `query` intentionally matches\n * nothing. Keeping the normalisation at the call site avoids re-lowering\n * the same query once per row. */\nexport function itemMatchesQuery(item: CollectionItem, query: string): boolean {\n // An empty query matches every record — otherwise a row whose only fields are\n // object/array-valued (no scalar cell reaches `includes(\"\")`) would vanish\n // when the search box is cleared. The list caller already short-circuits the\n // empty case, so this only guards a future caller that doesn't.\n if (query === \"\") return true;\n return Object.values(item).some((value) => {\n const text = fieldTextOrNull(value);\n return text !== null && text.toLowerCase().includes(query);\n });\n}\n","// Composite cell keys for the list table's per-cell state maps, plus the\n// load-time \"which enum cells were empty\" snapshot the inline enum dropdown\n// reads. Pure and framework-free so the view keeps only the reactive refs.\n\nimport { fieldText } from \"./fieldText\";\nimport type { CollectionItem } from \"./schema\";\n\n/** The schema slice `snapshotEmptyEnums` reads — minimal structural shape so\n * both the client and server collection-schema types satisfy it as-is. */\nexport interface EnumSnapshotSchema {\n fields: Record<string, { type: string }>;\n primaryKey: string;\n}\n\n/** Stable key for one cell (`<rowId>:<fieldKey>`) in the per-cell state maps. */\nexport function cellKey(rowId: string, fieldKey: string): string {\n return `${rowId}:${fieldKey}`;\n}\n\n/** A row's stable identity: the primary-key value as text (`\"\"` when the schema\n * has no primary key, or the value is absent). Every per-row / per-cell state\n * map keys off this, and it is the SAME derivation `snapshotEmptyEnums` uses\n * for its record ids (`fieldText`), so `cellKey(rowIdOf(...), field)` and the\n * empty-enum snapshot always agree. A real primary key is a scalar, so this\n * matches its plain string form. */\nexport function rowIdOf(primaryKey: string | undefined, item: CollectionItem): string {\n return primaryKey ? fieldText(item[primaryKey]) : \"\";\n}\n\n/** The set of enum cells that were empty in the freshly-fetched records — the\n * only cells whose inline dropdown offers an empty option. */\nexport function snapshotEmptyEnums(schema: EnumSnapshotSchema, records: CollectionItem[]): Set<string> {\n const empty = new Set<string>();\n const enumKeys = Object.entries(schema.fields)\n .filter(([, field]) => field.type === \"enum\")\n .map(([fieldKey]) => fieldKey);\n if (enumKeys.length === 0) return empty;\n for (const record of records) {\n const recordId = fieldText(record[schema.primaryKey]);\n for (const fieldKey of enumKeys) {\n if (record[fieldKey] == null || record[fieldKey] === \"\") empty.add(cellKey(recordId, fieldKey));\n }\n }\n return empty;\n}\n","// Shared chip/label resolution for the collection calendar surfaces (month\n// grid + day view), so both label a record identically. Pure, type-only\n// dependency on the schema shape.\n\nimport { fieldText } from \"./fieldText\";\nimport type { CollectionItem, CollectionSchema } from \"./schema\";\n\n// Text-like field types that make a sensible human-readable label.\nconst LABEL_FIELD_TYPES = new Set([\"string\", \"text\", \"markdown\", \"email\"]);\n\n/** Which field labels a record: the schema's explicit `displayField`, else the\n * first non-primary text-like field (so a collection without a displayField\n * shows e.g. the title rather than the opaque primaryKey), else null → the\n * caller falls back to the primary-key value. */\nexport function labelFieldFor(schema: CollectionSchema): string | null {\n if (schema.displayField) return schema.displayField;\n for (const [key, spec] of Object.entries(schema.fields)) {\n if (key !== schema.primaryKey && LABEL_FIELD_TYPES.has(spec.type)) return key;\n }\n return null;\n}\n\n/** A record's primary-key value as a string. */\nexport function itemIdOf(item: CollectionItem, schema: CollectionSchema): string {\n return fieldText(item[schema.primaryKey]);\n}\n\n/** A record's display label: the resolved `labelField` value, else the\n * primary key. Pass the result of `labelFieldFor(schema)` as `labelField`\n * (compute it once per render rather than per item). */\nexport function itemLabelOf(item: CollectionItem, schema: CollectionSchema, labelField: string | null): string {\n if (labelField) {\n const value = item[labelField];\n // Accept any primitive (string / number / boolean) so a numeric or boolean\n // display field still labels the record; objects/arrays fall through to the\n // id rather than rendering as \"[object Object]\".\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n const text = String(value);\n if (text.length > 0) return text;\n }\n }\n return itemIdOf(item, schema);\n}\n","// Pure builder for the workspace ontology graph — the `/collections` Map\n// panel (phase 2 of plans/done/collection-ontology.md step ①; plan:\n// plans/done/feat-collection-ontology-graph.md). Consumes the per-collection\n// ontology entries `buildWorkspaceOntology` derives server-side and turns\n// them into a node/edge structure a graph view can render directly.\n// Browser-safe (no `node:*` imports) so the Vue plugin builds the same\n// graph from the raw entries — same parity discipline as `deriveAll` and\n// the sibling `wiki/graph.ts`.\n\n/** One relationship a schema declares: a `ref` (the record stores the\n * target's primaryKey slug) or `embed` (display-only pull) pointing at\n * collection `to`, or `backlinks` / `rollup` (display-only REVERSE\n * refs — `to` is the relation's source collection, i.e. its `from`,\n * and `via` names the exact ref field there being reversed).\n * A `ref` column inside a `table` field is reported with a dotted path\n * (`lines.clientId`). Whether `to` exists is NOT checked — resolution\n * is fail-soft at render. */\nexport interface OntologyRelation {\n field: string;\n kind: \"ref\" | \"embed\" | \"backlinks\" | \"rollup\";\n to: string;\n via?: string;\n}\n\nexport interface CollectionOntologyEntry {\n slug: string;\n title: string;\n icon: string;\n primaryKey: string;\n /** The effective display field: the schema's `displayField`, falling\n * back to the primaryKey exactly as render-time labelling does. */\n displayField: string;\n /** Records in the collection, or `null` when the backend couldn't be\n * reached to count them (an engine that failed to load, a closed\n * session). Deliberately not 0: an unreachable collection reported as\n * empty invites \"restoring\" data that is intact but out of reach. */\n recordCount: number | null;\n relations: OntologyRelation[];\n}\n\nexport interface OntologyGraphNode {\n slug: string;\n title: string;\n icon: string;\n recordCount: number | null;\n /** No discovered collection has this slug — the node exists only\n * because a relation points at it. Rendered as a ghost so the graph\n * doubles as a broken-ref lint surface (lint, not lock). */\n missing?: boolean;\n}\n\nexport interface OntologyGraphEdge {\n /** Tail: the collection whose records store (`ref`) or pull (`embed`)\n * the link — or, for an uncollapsed reverse relation, the collection\n * whose refs the `backlinks`/`rollup` field aggregates. */\n from: string;\n /** Head: the collection the link points at. */\n to: string;\n /** Field declaring the relation — on `from` for `ref`/`embed`, on\n * `to` for an uncollapsed `backlinks`/`rollup`. */\n field: string;\n kind: OntologyRelation[\"kind\"];\n /** `backlinks`/`rollup` field names on `to` that declare the reverse\n * of this `ref` edge, collapsed here so one link never draws twice. */\n reverseFields?: string[];\n}\n\nexport interface OntologyGraph {\n nodes: OntologyGraphNode[];\n edges: OntologyGraphEdge[];\n}\n\nconst isForwardKind = (kind: OntologyRelation[\"kind\"]): boolean => kind === \"ref\" || kind === \"embed\";\n\n/** Fold a reverse relation (`backlinks`/`rollup` declared on `owner`)\n * into the edge list: collapse onto the forward `ref` edge whose field\n * is the relation's declared `via` (several refs can link the same\n * pair — matches.homeTeam vs matches.awayTeam — so the pair alone is\n * ambiguous), else emit its own edge oriented in true data direction\n * (refs' source → owner). A `via` naming no forward edge stays\n * uncollapsed — fail-soft, like every other dangling reference. */\nconst addReverseRelation = (edges: OntologyGraphEdge[], owner: string, rel: OntologyRelation): void => {\n const forward = edges.find((edge) => edge.kind === \"ref\" && edge.from === rel.to && edge.to === owner && (rel.via === undefined || edge.field === rel.via));\n if (forward) {\n forward.reverseFields = [...(forward.reverseFields ?? []), rel.field];\n return;\n }\n edges.push({ from: rel.to, to: owner, field: rel.field, kind: rel.kind });\n};\n\n/** Two passes so every forward `ref` edge exists before any reverse\n * relation tries to collapse onto one — entry order must not matter. */\nconst collectEdges = (entries: CollectionOntologyEntry[]): OntologyGraphEdge[] => {\n const edges: OntologyGraphEdge[] = [];\n for (const entry of entries) {\n for (const rel of entry.relations) {\n if (isForwardKind(rel.kind)) edges.push({ from: entry.slug, to: rel.to, field: rel.field, kind: rel.kind });\n }\n }\n for (const entry of entries) {\n for (const rel of entry.relations) {\n if (!isForwardKind(rel.kind)) addReverseRelation(edges, entry.slug, rel);\n }\n }\n return edges;\n};\n\n/** Slugs referenced by an edge endpoint but backed by no discovered\n * collection, slug-sorted for deterministic node order. */\nconst ghostSlugs = (edges: OntologyGraphEdge[], known: ReadonlySet<string>): string[] => {\n const ghosts = new Set<string>();\n for (const edge of edges) {\n if (!known.has(edge.from)) ghosts.add(edge.from);\n if (!known.has(edge.to)) ghosts.add(edge.to);\n }\n return [...ghosts].sort();\n};\n\n/** Build the renderable graph: one node per discovered collection (in\n * the entries' slug-sorted order) plus ghost nodes for dangling\n * targets, one edge per underlying link. */\nexport const buildOntologyGraph = (entries: CollectionOntologyEntry[]): OntologyGraph => {\n const edges = collectEdges(entries);\n const known = new Set(entries.map((entry) => entry.slug));\n const nodes: OntologyGraphNode[] = entries.map(({ slug, title, icon, recordCount }) => ({ slug, title, icon, recordCount }));\n for (const slug of ghostSlugs(edges, known)) {\n // A ghost node has no collection behind it at all, so it genuinely holds\n // no records — 0, not the \"couldn't count\" null.\n nodes.push({ slug, title: slug, icon: \"\", recordCount: 0, missing: true });\n }\n return { nodes, edges };\n};\n"],"mappings":";;;;;;;;AAUA,IAAa,YAAY;;;;;;AAsCzB,SAAgB,cAAc,MAA6B,OAAkD;CAC3G,MAAM,UAAU,OAAO,UAAU,WAAW,MAAM,KAAK,IAAI;CAC3D,OAAO,QAAQ,SAAS,IAAI;EAAE,GAAG;EAAM,OAAO;CAAQ,IAAI;AAC5D;;;;AAKA,SAAgB,kBAAkB,MAAuE;CACvG,OAAO,KAAK,UAAU,KAAA,IAAY,KAAK,iBAAiB,GAAG,KAAK,MAAM,QAAQ,KAAK;AACrF;;;AAIA,SAAgB,mBACd,KACA,OACS;CACT,OAAO,kBAAkB,GAAG,MAAM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