@bitcobblers/wod-wiki-engine 0.61.2259 → 0.62.2261
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/dist/agent.cjs +1929 -587
- package/dist/agent.cjs.map +1 -1
- package/dist/agent.d.cts +135 -10
- package/dist/agent.d.ts +135 -10
- package/dist/agent.mjs +433 -97
- package/dist/agent.mjs.map +1 -1
- package/dist/{chunk-C2WDXQZH.mjs → chunk-OMZHUD6T.mjs} +2045 -269
- package/dist/chunk-OMZHUD6T.mjs.map +1 -0
- package/dist/index.cjs +2083 -268
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +136 -22
- package/dist/index.d.ts +136 -22
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/dist/ir-fqQyyX01.d.cts +685 -0
- package/dist/ir-fqQyyX01.d.ts +685 -0
- package/package.json +5 -5
- package/dist/chunk-C2WDXQZH.mjs.map +0 -1
- package/dist/ir-B46Q9icI.d.cts +0 -402
- package/dist/ir-B46Q9icI.d.ts +0 -402
package/dist/agent.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { buildQueryServiceStoresFromStorage, extractNoteIdentity, extractTypedTags, makeNotebookLinkId, resolveScopedPropertyCatalog, effortToMarkdown, equipmentToMarkdown, saveScopedPropertyOverride, listFeedSubscriptionsHeadless, seedMetaKey, subscribeFeedSourceHeadless, unsubscribeFeedSourceHeadless, deleteFeedSourceHeadless, checkUnpublishedFeedChanges, MemoryFeedTree, publishFeedFromStorage, ingestPortableFilesIntoStorage, exportPortableFilesFromStorage, readFrontmatterMeta, createUserNotebookLanding, setNotebookPublic, promoteNoteToNotebooks, removeNoteFromNotebook, getNoteNotebooks, resolveUpstreamProvenance, getNotePublicationSummary, composeNoteMarkdown, buildNoteProvenance, buildStatementTree, prepareJournalSessionRun, setSessionPublic } from './chunk-
|
|
2
|
-
import { BUILTIN_NOTEBOOKS, parseDocumentSections, KNOWN_SECTION_WIDGETS, isNoteEditable, reconcileNoteBlocks, validateNoteBlocks, toNotebookId, blockContentId, MetricType, orderPlacements, isSystemReadOnlyNotebook, notebookSlugFromId, isNonPublishableNotebook } from '@bitcobblers/wod-wiki-core';
|
|
1
|
+
import { buildQueryServiceStoresFromStorage, extractNoteIdentity, extractTypedTags, noteHasRecordedSessionsInTx, snapshotNoteRevisionIfHasSessionsInTx, makeNotebookLinkId, resolveScopedPropertyCatalog, effortToMarkdown, equipmentToMarkdown, saveScopedPropertyOverride, listFeedSubscriptionsHeadless, seedMetaKey, subscribeFeedSourceHeadless, unsubscribeFeedSourceHeadless, deleteFeedSourceHeadless, checkUnpublishedFeedChanges, MemoryFeedTree, publishFeedFromStorage, ingestPortableFilesIntoStorage, exportPortableFilesFromStorage, getJournalDayOverlay, readFrontmatterMeta, createUserNotebookLanding, setNotebookPublic, promoteNoteToNotebooks, removeNoteFromNotebook, deleteUserNotebook, getNoteNotebooks, resolveUpstreamProvenance, getNotePublicationSummary, listScheduleItemsForNote, listNoteRevisions, composeNoteMarkdown, buildNoteProvenance, listScheduleItemsByDateRange, scheduleNoteOnDate, batchScheduleNotes, updateScheduleItem, removeScheduleItem, buildStatementTree, prepareJournalSessionRun, localCivilDateKey, setSessionPublic, attributeSession } from './chunk-OMZHUD6T.mjs';
|
|
2
|
+
import { BUILTIN_NOTEBOOKS, parseDocumentSections, KNOWN_SECTION_WIDGETS, isNoteEditable, reconcileNoteBlocks, validateNoteBlocks, toNotebookId, blockContentId, MetricType, orderPlacements, countNotesByNotebook, isSystemReadOnlyNotebook, isNotebookLanding, notebookSlugFromId, isNonPublishableNotebook } from '@bitcobblers/wod-wiki-core';
|
|
3
3
|
import { bundledEfforts, createReferenceIndex, parseScript, extractStatementRefs, createParser, findUnresolvedChoices, createMockClock, RuntimeStack, EventBus, frozenNow, ScriptRuntime, createCompiler, createAnalyticsEngineForBlock, StartSessionAction, NextEvent, toStoredOutputStatement } from '@bitcobblers/wod-wiki-lang';
|
|
4
4
|
import { rowsEqual, userDeletedSeedKey } from '@bitcobblers/wod-wiki-storage';
|
|
5
5
|
import { QueryService, notebookOriginOfItem, notebookOfItem, notebooksOfItem, toEventRows, toSummaryEventRows, parseQuery, isPipelineQuery, isFindQuery, isAggregateQuery, WQL_ROLLUP_PERIODS, WQL_AGGREGATORS, WQL_FIND_TARGETS, wqlGroupingDimensions, wqlFilterKeys, normalizeWql, WQL_COMPARISON_OPS, CONTENT_GROUPING_DIMENSIONS, WQL_VIRTUAL_DIMS, WQL_TAG_KEYS, WQL_TYPED_TAG_KEYS, WQL_METRIC_AGGREGATES, WQL_METRIC_FAMILIES } from '@bitcobblers/wod-wiki-wql';
|
|
@@ -132,6 +132,7 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
132
132
|
[
|
|
133
133
|
"notes",
|
|
134
134
|
"block_revisions",
|
|
135
|
+
"note_revisions",
|
|
135
136
|
"block_index",
|
|
136
137
|
"block_efforts",
|
|
137
138
|
"block_equipment",
|
|
@@ -141,6 +142,8 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
141
142
|
"note_tags",
|
|
142
143
|
"page",
|
|
143
144
|
"page_notes",
|
|
145
|
+
"schedule_items",
|
|
146
|
+
"sessions",
|
|
144
147
|
"notebook_links"
|
|
145
148
|
],
|
|
146
149
|
"readwrite",
|
|
@@ -209,13 +212,19 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
209
212
|
}
|
|
210
213
|
const resolvedTitle = input.title ?? stampedIdentity?.title ?? extractHeadingTitleFromMarkdown(input.rawContent) ?? existing?.title ?? "Untitled Workout";
|
|
211
214
|
const targetNotebookId = input.notebookId ? toNotebookId(input.notebookId) : existing?.notebookId;
|
|
212
|
-
const notebookIds = Array.from(
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
const notebookIds = targetNotebookId ? Array.from(/* @__PURE__ */ new Set([...existing?.notebookIds ?? [], targetNotebookId])) : existing ? [...existing.notebookIds ?? []] : [];
|
|
216
|
+
const nextTagLabels = extractedTags.map((t) => t.label);
|
|
217
|
+
const nextNoteType = input.type ?? existing?.type ?? (input.journalDate ? "journal" : "note");
|
|
218
|
+
if (existing) {
|
|
219
|
+
const meaningfulChange = existing.rawContent !== input.rawContent || existing.title !== resolvedTitle || existing.type !== nextNoteType || !rowsEqual(existing.blocks, blocks) || !rowsEqual(existing.tags ?? [], nextTagLabels);
|
|
220
|
+
if (meaningfulChange && await noteHasRecordedSessionsInTx(tx, noteId)) {
|
|
221
|
+
await snapshotNoteRevisionIfHasSessionsInTx(tx, existing, now);
|
|
222
|
+
if (sourceRevision <= existing.sourceRevision) {
|
|
223
|
+
sourceRevision = existing.sourceRevision + 1;
|
|
224
|
+
for (const block of Object.values(blocks)) block.sourceRevision = sourceRevision;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
219
228
|
const dateMs = input.journalDate ? Date.parse(`${civilDateKey(input.journalDate, now)}T12:00:00Z`) : existing?.date ?? now;
|
|
220
229
|
const note = {
|
|
221
230
|
...existing ?? {},
|
|
@@ -224,12 +233,12 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
224
233
|
rawContent: input.rawContent,
|
|
225
234
|
sourceRevision,
|
|
226
235
|
blocks,
|
|
227
|
-
type:
|
|
236
|
+
type: nextNoteType,
|
|
228
237
|
date: dateMs,
|
|
229
238
|
createdAt: existing?.createdAt ?? now,
|
|
230
239
|
notebookIds,
|
|
231
240
|
...targetNotebookId && targetNotebookId !== "notebook/journal" ? { notebookId: targetNotebookId } : {},
|
|
232
|
-
tags:
|
|
241
|
+
tags: nextTagLabels,
|
|
233
242
|
seedOrigin: "user"
|
|
234
243
|
};
|
|
235
244
|
const storedEfforts = await tx.readonly("efforts").getAll();
|
|
@@ -356,6 +365,7 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
356
365
|
if (links.length > 0) {
|
|
357
366
|
await tx.readwrite("notebook_links").putMany(links);
|
|
358
367
|
}
|
|
368
|
+
let scheduleItemId;
|
|
359
369
|
if (input.journalDate) {
|
|
360
370
|
const dateKey = civilDateKey(input.journalDate, now);
|
|
361
371
|
let pages;
|
|
@@ -388,6 +398,33 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
388
398
|
createdAt: now
|
|
389
399
|
});
|
|
390
400
|
}
|
|
401
|
+
try {
|
|
402
|
+
const existingSchedules = await tx.readonly("schedule_items").getAllFromIndex("by-date", dateKey);
|
|
403
|
+
const matchedSched = existingSchedules.find((s) => s.noteId === noteId);
|
|
404
|
+
if (matchedSched) {
|
|
405
|
+
scheduleItemId = matchedSched.id;
|
|
406
|
+
} else {
|
|
407
|
+
const maxSchedPos = existingSchedules.reduce(
|
|
408
|
+
(m, s) => typeof s.position === "number" && s.position > m ? s.position : m,
|
|
409
|
+
-1
|
|
410
|
+
);
|
|
411
|
+
const nextSchedId = mintAgentUuid();
|
|
412
|
+
await tx.readwrite("schedule_items").put({
|
|
413
|
+
id: nextSchedId,
|
|
414
|
+
date: dateKey,
|
|
415
|
+
noteId,
|
|
416
|
+
pageId: targetPage.id,
|
|
417
|
+
...note.notebookId ? { sourceNotebookId: note.notebookId } : {},
|
|
418
|
+
fallbackTitle: note.title,
|
|
419
|
+
position: maxSchedPos + 1,
|
|
420
|
+
status: "planned",
|
|
421
|
+
createdAt: now,
|
|
422
|
+
updatedAt: now
|
|
423
|
+
});
|
|
424
|
+
scheduleItemId = nextSchedId;
|
|
425
|
+
}
|
|
426
|
+
} catch {
|
|
427
|
+
}
|
|
391
428
|
}
|
|
392
429
|
return {
|
|
393
430
|
note,
|
|
@@ -395,7 +432,8 @@ async function upsertNoteInStorage(storage, input) {
|
|
|
395
432
|
blockCount: nextRows.length,
|
|
396
433
|
effortSlugs: [...allEffortSlugs],
|
|
397
434
|
equipmentSlugs: [...allEquipSlugs],
|
|
398
|
-
tagLabels: extractedTags.map((t) => t.label)
|
|
435
|
+
tagLabels: extractedTags.map((t) => t.label),
|
|
436
|
+
...scheduleItemId ? { scheduleItemId } : {}
|
|
399
437
|
};
|
|
400
438
|
}
|
|
401
439
|
);
|
|
@@ -410,6 +448,7 @@ async function deleteNoteFromStorage(storage, noteId) {
|
|
|
410
448
|
"block_efforts",
|
|
411
449
|
"block_equipment",
|
|
412
450
|
"page_notes",
|
|
451
|
+
"schedule_items",
|
|
413
452
|
"notebook_links",
|
|
414
453
|
"meta"
|
|
415
454
|
],
|
|
@@ -436,6 +475,12 @@ async function deleteNoteFromStorage(storage, noteId) {
|
|
|
436
475
|
for (const pn of await tx.readonly("page_notes").getAllFromIndex("by-note", noteId)) {
|
|
437
476
|
await tx.readwrite("page_notes").delete(pn.id);
|
|
438
477
|
}
|
|
478
|
+
try {
|
|
479
|
+
for (const sched of await tx.readonly("schedule_items").getAllFromIndex("by-note", noteId)) {
|
|
480
|
+
await tx.readwrite("schedule_items").delete(sched.id);
|
|
481
|
+
}
|
|
482
|
+
} catch {
|
|
483
|
+
}
|
|
439
484
|
try {
|
|
440
485
|
for (const nl of await tx.readonly("notebook_links").getAllFromIndex("by-note", noteId)) {
|
|
441
486
|
await tx.readwrite("notebook_links").delete(nl.id);
|
|
@@ -728,13 +773,16 @@ var wodFeedManageTool = defineAgentTool({
|
|
|
728
773
|
const obj = row;
|
|
729
774
|
if (typeof obj.key === "string" && obj.key.startsWith("seed:") && obj.key !== seedMetaKey("user")) {
|
|
730
775
|
const sourceId = obj.key.slice("seed:".length);
|
|
776
|
+
const sub = subscriptions[sourceId];
|
|
731
777
|
installedFeeds.push({
|
|
732
778
|
sourceId,
|
|
733
779
|
seedVersion: obj.seedVersion,
|
|
734
780
|
builtAt: obj.builtAt,
|
|
735
781
|
importedAt: obj.importedAt,
|
|
736
782
|
chunkCount: Object.keys(obj.chunks ?? {}).length,
|
|
737
|
-
subscribed:
|
|
783
|
+
subscribed: sub?.subscribed ?? true,
|
|
784
|
+
offlinePolicy: sub?.offlinePolicy ?? (sourceId === "core" ? "offline-full" : "index-only"),
|
|
785
|
+
autoSync: sub?.autoSync ?? sourceId === "core"
|
|
738
786
|
});
|
|
739
787
|
}
|
|
740
788
|
}
|
|
@@ -968,6 +1016,7 @@ var wodJournalDayTool = defineAgentTool({
|
|
|
968
1016
|
cliEquivalent: "wod journal [today|YYYY-MM-DD] --json",
|
|
969
1017
|
async execute(args, ctx) {
|
|
970
1018
|
const dateKey = civilDateKey(args.date);
|
|
1019
|
+
const overlay = await getJournalDayOverlay(ctx.storage, dateKey);
|
|
971
1020
|
const dayStart = Date.parse(`${dateKey}T00:00:00Z`);
|
|
972
1021
|
const dayEnd = Date.parse(`${dateKey}T23:59:59.999Z`);
|
|
973
1022
|
let pages;
|
|
@@ -986,16 +1035,20 @@ var wodJournalDayTool = defineAgentTool({
|
|
|
986
1035
|
if (!placedNoteIds.includes(link.noteId)) placedNoteIds.push(link.noteId);
|
|
987
1036
|
}
|
|
988
1037
|
}
|
|
989
|
-
const
|
|
990
|
-
ctx.storage.readonly("notes").getAll(),
|
|
991
|
-
ctx.storage.readonly("sessions").getAll()
|
|
992
|
-
]);
|
|
1038
|
+
const allNotes = await ctx.storage.readonly("notes").getAll();
|
|
993
1039
|
const notesById = new Map(allNotes.map((n) => [n.id, n]));
|
|
994
1040
|
const dayNotes = [];
|
|
995
1041
|
const seenIds = /* @__PURE__ */ new Set();
|
|
1042
|
+
for (const { item, note } of overlay.planned) {
|
|
1043
|
+
const resolved = note ?? notesById.get(item.noteId);
|
|
1044
|
+
if (resolved && !seenIds.has(resolved.id)) {
|
|
1045
|
+
dayNotes.push(resolved);
|
|
1046
|
+
seenIds.add(resolved.id);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
996
1049
|
for (const id of placedNoteIds) {
|
|
997
1050
|
const n = notesById.get(id);
|
|
998
|
-
if (n) {
|
|
1051
|
+
if (n && !seenIds.has(n.id)) {
|
|
999
1052
|
dayNotes.push(n);
|
|
1000
1053
|
seenIds.add(n.id);
|
|
1001
1054
|
}
|
|
@@ -1010,16 +1063,50 @@ var wodJournalDayTool = defineAgentTool({
|
|
|
1010
1063
|
seenIds.add(n.id);
|
|
1011
1064
|
}
|
|
1012
1065
|
}
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1066
|
+
const overlaySessionsById = /* @__PURE__ */ new Map();
|
|
1067
|
+
for (const p of overlay.planned) {
|
|
1068
|
+
for (const s of p.pairedSessions) overlaySessionsById.set(s.id, s);
|
|
1069
|
+
}
|
|
1070
|
+
for (const a of overlay.adhocSessions) {
|
|
1071
|
+
overlaySessionsById.set(a.session.id, a.session);
|
|
1072
|
+
}
|
|
1073
|
+
const daySessions = Array.from(overlaySessionsById.values()).sort(
|
|
1074
|
+
(a, b) => a.startTime - b.startTime
|
|
1075
|
+
);
|
|
1076
|
+
for (const s of daySessions) {
|
|
1077
|
+
if (seenIds.has(s.noteId)) continue;
|
|
1078
|
+
const n = notesById.get(s.noteId);
|
|
1079
|
+
if (n) {
|
|
1080
|
+
dayNotes.push(n);
|
|
1081
|
+
seenIds.add(n.id);
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1018
1084
|
const prefix = (ctx.baseUrl ?? "").replace(/\/+$/, "");
|
|
1019
1085
|
return {
|
|
1020
1086
|
date: dateKey,
|
|
1021
|
-
url: `${prefix}/
|
|
1087
|
+
url: `${prefix}/day/${dateKey}`,
|
|
1022
1088
|
pageId: page?.id ?? null,
|
|
1089
|
+
plannedCount: overlay.planned.length,
|
|
1090
|
+
planned: overlay.planned.map(({ item, note, pairedSessions }) => ({
|
|
1091
|
+
scheduleItemId: item.id,
|
|
1092
|
+
noteId: item.noteId,
|
|
1093
|
+
noteTitle: note?.title ?? item.noteId,
|
|
1094
|
+
status: pairedSessions.length > 0 ? "completed" : item.status,
|
|
1095
|
+
...item.slot ? { slot: item.slot } : {},
|
|
1096
|
+
...item.notes ? { notes: item.notes } : {},
|
|
1097
|
+
pairedSessionIds: pairedSessions.map((s) => s.id)
|
|
1098
|
+
})),
|
|
1099
|
+
adhocSessionCount: overlay.adhocSessions.length,
|
|
1100
|
+
adhocSessions: overlay.adhocSessions.map(({ session: s, note }) => ({
|
|
1101
|
+
id: s.id,
|
|
1102
|
+
noteId: s.noteId,
|
|
1103
|
+
noteTitle: note?.title ?? s.noteId,
|
|
1104
|
+
status: s.status,
|
|
1105
|
+
completed: s.completed,
|
|
1106
|
+
duration: s.duration,
|
|
1107
|
+
startTime: s.startTime,
|
|
1108
|
+
...s.noteSourceRevision ? { noteSourceRevision: s.noteSourceRevision } : {}
|
|
1109
|
+
})),
|
|
1023
1110
|
noteCount: dayNotes.length,
|
|
1024
1111
|
notes: dayNotes.map((n) => ({
|
|
1025
1112
|
id: n.id,
|
|
@@ -1038,7 +1125,10 @@ var wodJournalDayTool = defineAgentTool({
|
|
|
1038
1125
|
status: s.status,
|
|
1039
1126
|
completed: s.completed,
|
|
1040
1127
|
duration: s.duration,
|
|
1041
|
-
startTime: s.startTime
|
|
1128
|
+
startTime: s.startTime,
|
|
1129
|
+
...s.scheduleItemId ? { scheduleItemId: s.scheduleItemId } : {},
|
|
1130
|
+
...s.sessionDate ? { sessionDate: s.sessionDate } : {},
|
|
1131
|
+
...s.noteSourceRevision ? { noteSourceRevision: s.noteSourceRevision } : {}
|
|
1042
1132
|
}))
|
|
1043
1133
|
};
|
|
1044
1134
|
}
|
|
@@ -1048,12 +1138,12 @@ var journalAddInputSchema = z.strictObject({
|
|
|
1048
1138
|
title: z.string().optional().describe("Workout title (defaults to # H1 heading or date)."),
|
|
1049
1139
|
content: z.string().min(1).describe("Markdown workout note or bare Whiteboard Script to schedule onto the Journal day."),
|
|
1050
1140
|
sport: z.string().optional().describe("Optional sport fence tag when passing bare Whiteboard Script."),
|
|
1051
|
-
notebookId: z.string().optional().describe("Optional
|
|
1141
|
+
notebookId: z.string().optional().describe("Optional user Notebook ID to assign this Note into (omit to keep unfiled on Journal).")
|
|
1052
1142
|
});
|
|
1053
1143
|
var wodJournalAddTool = defineAgentTool({
|
|
1054
1144
|
name: "wod_journal_add",
|
|
1055
1145
|
title: "Add Workout to Journal Day",
|
|
1056
|
-
description: "Create a
|
|
1146
|
+
description: "Create a lightweight workout Note (unfiled unless `notebookId` is given) and schedule it onto the specified calendar day via a `ScheduleItem`.",
|
|
1057
1147
|
tier: 1,
|
|
1058
1148
|
domain: "journal",
|
|
1059
1149
|
annotations: {
|
|
@@ -1084,13 +1174,15 @@ var wodJournalAddTool = defineAgentTool({
|
|
|
1084
1174
|
"block_equipment",
|
|
1085
1175
|
"page",
|
|
1086
1176
|
"page_notes",
|
|
1087
|
-
"notebook_links"
|
|
1177
|
+
"notebook_links",
|
|
1178
|
+
"schedule_items"
|
|
1088
1179
|
]);
|
|
1089
1180
|
const prefix = (ctx.baseUrl ?? "").replace(/\/+$/, "");
|
|
1090
1181
|
return {
|
|
1091
1182
|
date: dateKey,
|
|
1092
1183
|
noteId: saved.note.id,
|
|
1093
|
-
|
|
1184
|
+
...saved.scheduleItemId ? { scheduleItemId: saved.scheduleItemId } : {},
|
|
1185
|
+
journalUrl: `${prefix}/day/${dateKey}`,
|
|
1094
1186
|
note: {
|
|
1095
1187
|
id: saved.note.id,
|
|
1096
1188
|
title: saved.note.title,
|
|
@@ -1103,9 +1195,6 @@ var wodJournalAddTool = defineAgentTool({
|
|
|
1103
1195
|
}
|
|
1104
1196
|
});
|
|
1105
1197
|
var JOURNAL_AGENT_TOOLS = [wodJournalDayTool, wodJournalAddTool];
|
|
1106
|
-
function isLandingNote(note) {
|
|
1107
|
-
return note.id.startsWith("notebook/") && note.notebookId === note.id;
|
|
1108
|
-
}
|
|
1109
1198
|
var RESERVED_SLUGS = new Set(BUILTIN_NOTEBOOKS.map((b) => b.slug));
|
|
1110
1199
|
var notebookListInputSchema = z.strictObject({
|
|
1111
1200
|
origin: z.enum(["all", "default", "user", "feed"]).optional().describe('Filter notebooks by origin (default "all").')
|
|
@@ -1130,22 +1219,7 @@ var wodNotebookListTool = defineAgentTool({
|
|
|
1130
1219
|
ctx.storage.readonly("notes").getAll(),
|
|
1131
1220
|
ctx.storage.readonly("notebook_links").getAll().catch(() => [])
|
|
1132
1221
|
]);
|
|
1133
|
-
const counts =
|
|
1134
|
-
const countedPairs = /* @__PURE__ */ new Set();
|
|
1135
|
-
const bump = (nbId, noteId) => {
|
|
1136
|
-
const key = `${nbId}\0${noteId}`;
|
|
1137
|
-
if (countedPairs.has(key)) return;
|
|
1138
|
-
countedPairs.add(key);
|
|
1139
|
-
counts.set(nbId, (counts.get(nbId) ?? 0) + 1);
|
|
1140
|
-
};
|
|
1141
|
-
for (const link of allLinks) {
|
|
1142
|
-
if (link.targetKind === "note") bump(toNotebookId(link.notebookId), link.noteId);
|
|
1143
|
-
}
|
|
1144
|
-
for (const n of allNotes) {
|
|
1145
|
-
for (const nbId of notebooksOfItem(n)) {
|
|
1146
|
-
bump(toNotebookId(nbId), n.id);
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1222
|
+
const counts = countNotesByNotebook(allNotes, allLinks, notebooksOfItem);
|
|
1149
1223
|
const byId = /* @__PURE__ */ new Map();
|
|
1150
1224
|
for (const spec of BUILTIN_NOTEBOOKS) {
|
|
1151
1225
|
byId.set(spec.notebookId, {
|
|
@@ -1161,7 +1235,7 @@ var wodNotebookListTool = defineAgentTool({
|
|
|
1161
1235
|
});
|
|
1162
1236
|
}
|
|
1163
1237
|
for (const n of allNotes) {
|
|
1164
|
-
if (!
|
|
1238
|
+
if (!isNotebookLanding(n)) continue;
|
|
1165
1239
|
const slug = notebookSlugFromId(n.id);
|
|
1166
1240
|
const fm = readFrontmatterMeta(n.rawContent);
|
|
1167
1241
|
const description = typeof fm["description"] === "string" ? fm["description"].replace(/^"|"$/g, "") : "";
|
|
@@ -1177,7 +1251,7 @@ var wodNotebookListTool = defineAgentTool({
|
|
|
1177
1251
|
origin: existing?.origin ?? (isFeed ? "feed" : "user"),
|
|
1178
1252
|
writable: !isSystemReadOnlyNotebook(n.id) && !isFeed,
|
|
1179
1253
|
public: n.public === true,
|
|
1180
|
-
noteCount: counts.get(n.id) ?? 0
|
|
1254
|
+
noteCount: counts.get(toNotebookId(n.id)) ?? 0
|
|
1181
1255
|
});
|
|
1182
1256
|
}
|
|
1183
1257
|
const filterOrigin = args.origin ?? "all";
|
|
@@ -1357,32 +1431,9 @@ var wodNotebookDeleteTool = defineAgentTool({
|
|
|
1357
1431
|
},
|
|
1358
1432
|
matchedConfirm
|
|
1359
1433
|
);
|
|
1360
|
-
const
|
|
1361
|
-
for (const note of allNotes) {
|
|
1362
|
-
if (isLandingNote(note)) continue;
|
|
1363
|
-
if (note.notebookId === nbId || (note.notebookIds ?? []).includes(nbId)) {
|
|
1364
|
-
const remaining = (note.notebookIds ?? ["notebook/journal"]).map((id) => toNotebookId(id)).filter((id) => id !== nbId);
|
|
1365
|
-
const primaryUser = remaining.find(
|
|
1366
|
-
(id) => id !== "notebook/journal" && id !== "notebook/playground"
|
|
1367
|
-
);
|
|
1368
|
-
const { notebookId: _oldSingle, ...rest } = note;
|
|
1369
|
-
await ctx.storage.readwrite("notes").put({
|
|
1370
|
-
...rest,
|
|
1371
|
-
notebookIds: remaining.length > 0 ? remaining : ["notebook/journal"],
|
|
1372
|
-
...primaryUser ? { notebookId: primaryUser } : {}
|
|
1373
|
-
});
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
try {
|
|
1377
|
-
const links = await ctx.storage.readonly("notebook_links").getAllFromIndex("by-notebook", nbId);
|
|
1378
|
-
for (const link of links) {
|
|
1379
|
-
await ctx.storage.readwrite("notebook_links").delete(link.id);
|
|
1380
|
-
}
|
|
1381
|
-
} catch {
|
|
1382
|
-
}
|
|
1383
|
-
const deleted = await deleteNoteFromStorage(ctx.storage, nbId);
|
|
1434
|
+
const result = await deleteUserNotebook(ctx.storage, nbId);
|
|
1384
1435
|
await ctx.onMutated?.(["notes", "notebook_links"]);
|
|
1385
|
-
return
|
|
1436
|
+
return result;
|
|
1386
1437
|
}
|
|
1387
1438
|
});
|
|
1388
1439
|
var NOTEBOOK_AGENT_TOOLS = [
|
|
@@ -1390,14 +1441,16 @@ var NOTEBOOK_AGENT_TOOLS = [
|
|
|
1390
1441
|
wodNotebookSaveTool,
|
|
1391
1442
|
wodNotebookDeleteTool
|
|
1392
1443
|
];
|
|
1393
|
-
function
|
|
1444
|
+
function isLandingNote(note) {
|
|
1394
1445
|
return note.id.startsWith("notebook/") && note.notebookId === note.id;
|
|
1395
1446
|
}
|
|
1396
1447
|
var noteListInputSchema = z.strictObject({
|
|
1397
1448
|
notebookId: z.string().optional().describe('Filter by notebook ID or slug (e.g. "journal", "custom", "guides", "notebook/strength").'),
|
|
1398
1449
|
search: z.string().optional().describe("Case-insensitive substring filter over title and Markdown content."),
|
|
1399
1450
|
tag: z.string().optional().describe("Filter to Notes carrying this tag label."),
|
|
1400
|
-
|
|
1451
|
+
origin: z.enum(["all", "user", "feed", "seed"]).optional().describe('Filter by Note origin ("user", "feed", "seed", or "all"; defaults to "all").'),
|
|
1452
|
+
includeSeed: z.boolean().optional().describe("Include read-only Seed/Feed notes (default true; pass false for user-authored notes only)."),
|
|
1453
|
+
orphanedOnly: z.boolean().optional().describe("When true, return only user Notes not belonging to any Notebook (equivalent to `:note{!notebook:*}`)."),
|
|
1401
1454
|
limit: z.number().int().min(1).max(200).optional().describe("Max notes to return (default 50).")
|
|
1402
1455
|
});
|
|
1403
1456
|
var wodNoteListTool = defineAgentTool({
|
|
@@ -1417,32 +1470,50 @@ var wodNoteListTool = defineAgentTool({
|
|
|
1417
1470
|
cliEquivalent: "wod note list --json",
|
|
1418
1471
|
async execute(args, ctx) {
|
|
1419
1472
|
const targetNb = args.notebookId ? toNotebookId(args.notebookId) : void 0;
|
|
1420
|
-
const includeSeed = args.includeSeed ??
|
|
1473
|
+
const includeSeed = args.includeSeed ?? true;
|
|
1474
|
+
const origin = args.origin ?? "all";
|
|
1475
|
+
const orphanedOnly = args.orphanedOnly === true;
|
|
1421
1476
|
const searchLower = args.search?.trim().toLowerCase();
|
|
1422
1477
|
const tagLower = args.tag?.trim().toLowerCase();
|
|
1423
1478
|
const limit = args.limit ?? 50;
|
|
1424
|
-
const { allNotes, linkedNoteIdsForNb } = await ctx.storage.transaction(
|
|
1479
|
+
const { allNotes, linkedNoteIdsForNb, noteIdsWithLinks } = await ctx.storage.transaction(
|
|
1425
1480
|
["notes", "notebook_links"],
|
|
1426
1481
|
"readonly",
|
|
1427
1482
|
async (tx) => {
|
|
1428
1483
|
const notes = await tx.readonly("notes").getAll();
|
|
1429
1484
|
let linkedIds;
|
|
1430
|
-
|
|
1431
|
-
|
|
1485
|
+
const withLinks = /* @__PURE__ */ new Set();
|
|
1486
|
+
try {
|
|
1487
|
+
if (targetNb) {
|
|
1432
1488
|
const links = await tx.readonly("notebook_links").getAllFromIndex("by-notebook", targetNb);
|
|
1433
1489
|
linkedIds = new Set(
|
|
1434
1490
|
links.filter((l) => l.targetKind === "note").map((l) => l.noteId)
|
|
1435
1491
|
);
|
|
1436
|
-
} catch {
|
|
1437
|
-
linkedIds = /* @__PURE__ */ new Set();
|
|
1438
1492
|
}
|
|
1493
|
+
if (orphanedOnly) {
|
|
1494
|
+
const allLinks = await tx.readonly("notebook_links").getAll();
|
|
1495
|
+
for (const link of allLinks) {
|
|
1496
|
+
if (link.targetKind === "note") withLinks.add(link.noteId);
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
} catch {
|
|
1500
|
+
linkedIds = /* @__PURE__ */ new Set();
|
|
1439
1501
|
}
|
|
1440
|
-
return { allNotes: notes, linkedNoteIdsForNb: linkedIds };
|
|
1502
|
+
return { allNotes: notes, linkedNoteIdsForNb: linkedIds, noteIdsWithLinks: withLinks };
|
|
1441
1503
|
}
|
|
1442
1504
|
);
|
|
1443
1505
|
const filtered = allNotes.filter((n) => {
|
|
1444
|
-
if (
|
|
1445
|
-
|
|
1506
|
+
if (isLandingNote(n)) return false;
|
|
1507
|
+
const isSeedOrFeed = n.seedOrigin === "seed" || n.feedOrigin === "feed";
|
|
1508
|
+
if (origin === "user" && isSeedOrFeed) return false;
|
|
1509
|
+
if (origin === "feed" && n.feedOrigin !== "feed") return false;
|
|
1510
|
+
if (origin === "seed" && n.seedOrigin !== "seed") return false;
|
|
1511
|
+
if (!includeSeed && isSeedOrFeed) return false;
|
|
1512
|
+
if (orphanedOnly) {
|
|
1513
|
+
if (isSeedOrFeed) return false;
|
|
1514
|
+
if (noteIdsWithLinks.has(n.id)) return false;
|
|
1515
|
+
if (notebooksOfItem(n).length > 0) return false;
|
|
1516
|
+
}
|
|
1446
1517
|
if (targetNb) {
|
|
1447
1518
|
const inNb = linkedNoteIdsForNb?.has(n.id) || n.notebookId === targetNb || (n.notebookIds ?? []).includes(targetNb) || notebooksOfItem(n).includes(targetNb);
|
|
1448
1519
|
if (!inNb) return false;
|
|
@@ -1502,13 +1573,15 @@ var wodNoteGetTool = defineAgentTool({
|
|
|
1502
1573
|
const nbOrigin = notebookOriginOfItem(note);
|
|
1503
1574
|
const resolvedNb = notebookOfItem(note);
|
|
1504
1575
|
const editable = isNoteEditable(note, nbOrigin, resolvedNb);
|
|
1505
|
-
const [notebooks, provenance, visibility, sessions] = await Promise.all([
|
|
1576
|
+
const [notebooks, provenance, visibility, sessions, scheduleItems, revisions] = await Promise.all([
|
|
1506
1577
|
getNoteNotebooks(ctx.storage, note.id),
|
|
1507
1578
|
resolveUpstreamProvenance(ctx.storage, note),
|
|
1508
1579
|
getNotePublicationSummary(ctx.storage, note.id),
|
|
1509
1580
|
ctx.storage.readonly("sessions").getAllFromIndex("by-note", note.id).catch(
|
|
1510
1581
|
async () => (await ctx.storage.readonly("sessions").getAll()).filter((s) => s.noteId === note.id)
|
|
1511
|
-
)
|
|
1582
|
+
),
|
|
1583
|
+
listScheduleItemsForNote(ctx.storage, note.id).catch(() => []),
|
|
1584
|
+
listNoteRevisions(ctx.storage, note.id).catch(() => [])
|
|
1512
1585
|
]);
|
|
1513
1586
|
const sections = parseDocumentSections(note.rawContent, {
|
|
1514
1587
|
registeredWidgets: KNOWN_SECTION_WIDGETS
|
|
@@ -1535,6 +1608,9 @@ var wodNoteGetTool = defineAgentTool({
|
|
|
1535
1608
|
createdAt: note.createdAt,
|
|
1536
1609
|
tags: note.tags ?? [],
|
|
1537
1610
|
notebooks: notebooks.map((id) => ({ id, slug: notebookSlugFromId(id) })),
|
|
1611
|
+
scheduleCount: scheduleItems.length,
|
|
1612
|
+
scheduleItems,
|
|
1613
|
+
revisionCount: revisions.length,
|
|
1538
1614
|
blocks,
|
|
1539
1615
|
sessionCount: sessions.length,
|
|
1540
1616
|
recentSessions: sessions.sort((a, b) => b.startTime - a.startTime).slice(0, 10).map((s) => ({
|
|
@@ -1558,7 +1634,7 @@ var noteUpsertInputSchema = z.strictObject({
|
|
|
1558
1634
|
content: z.string().min(1).describe("Full Markdown document or Whiteboard Script body."),
|
|
1559
1635
|
sport: z.string().optional().describe("Optional sport fence tag when passing bare Whiteboard Script."),
|
|
1560
1636
|
expectedSourceRevision: z.number().int().min(0).optional().describe("Optimistic concurrency guard: pass the current sourceRevision from wod_note_get when updating."),
|
|
1561
|
-
notebookId: z.string().optional().describe("Optional user Notebook ID/slug to
|
|
1637
|
+
notebookId: z.string().optional().describe("Optional user Notebook ID/slug to assign this Note into (omit for unfiled/existing memberships)."),
|
|
1562
1638
|
journalDate: z.string().optional().describe('Optional YYYY-MM-DD or "today" to place the Note on that Journal calendar day.')
|
|
1563
1639
|
});
|
|
1564
1640
|
var wodNoteUpsertTool = defineAgentTool({
|
|
@@ -1735,6 +1811,204 @@ var NOTE_AGENT_TOOLS = [
|
|
|
1735
1811
|
wodNoteCloneTool,
|
|
1736
1812
|
wodNoteDeleteTool
|
|
1737
1813
|
];
|
|
1814
|
+
var scheduleListInputSchema = z.strictObject({
|
|
1815
|
+
from: z.string().optional().describe('Start date in YYYY-MM-DD format (inclusive, or "today").'),
|
|
1816
|
+
to: z.string().optional().describe('End date in YYYY-MM-DD format (inclusive, or "today").'),
|
|
1817
|
+
noteId: z.string().optional().describe("Optional Note ID to list scheduled dates for one workout.")
|
|
1818
|
+
});
|
|
1819
|
+
var wodScheduleListTool = defineAgentTool({
|
|
1820
|
+
name: "wod_schedule_list",
|
|
1821
|
+
title: "List Scheduled Workouts",
|
|
1822
|
+
description: "List M:N ScheduleItem instances by date range (`from`/`to`) or for a specific Note ID.",
|
|
1823
|
+
tier: 0,
|
|
1824
|
+
domain: "journal",
|
|
1825
|
+
annotations: {
|
|
1826
|
+
title: "List Scheduled Workouts",
|
|
1827
|
+
readOnlyHint: true,
|
|
1828
|
+
destructiveHint: false,
|
|
1829
|
+
idempotentHint: true,
|
|
1830
|
+
openWorldHint: false
|
|
1831
|
+
},
|
|
1832
|
+
inputSchema: scheduleListInputSchema,
|
|
1833
|
+
cliEquivalent: "wod schedule list --json",
|
|
1834
|
+
async execute(args, ctx) {
|
|
1835
|
+
let items;
|
|
1836
|
+
if (args.noteId) {
|
|
1837
|
+
items = await listScheduleItemsForNote(ctx.storage, args.noteId);
|
|
1838
|
+
if (args.from) {
|
|
1839
|
+
const fromKey = civilDateKey(args.from);
|
|
1840
|
+
items = items.filter((i) => i.date >= fromKey);
|
|
1841
|
+
}
|
|
1842
|
+
if (args.to) {
|
|
1843
|
+
const toKey = civilDateKey(args.to);
|
|
1844
|
+
items = items.filter((i) => i.date <= toKey);
|
|
1845
|
+
}
|
|
1846
|
+
} else if (args.from || args.to) {
|
|
1847
|
+
const fromKey = civilDateKey(args.from ?? args.to);
|
|
1848
|
+
const toKey = civilDateKey(args.to ?? args.from);
|
|
1849
|
+
items = await listScheduleItemsByDateRange(ctx.storage, fromKey, toKey);
|
|
1850
|
+
} else {
|
|
1851
|
+
items = (await ctx.storage.readonly("schedule_items").getAll()).sort(
|
|
1852
|
+
(a, b) => a.date.localeCompare(b.date) || (a.position ?? 0) - (b.position ?? 0)
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
const noteIds = [...new Set(items.map((i) => i.noteId))];
|
|
1856
|
+
const notes = await ctx.storage.readonly("notes").getMany(noteIds);
|
|
1857
|
+
const titleById = /* @__PURE__ */ new Map();
|
|
1858
|
+
notes.forEach((n, idx) => {
|
|
1859
|
+
if (n) titleById.set(noteIds[idx], n.title);
|
|
1860
|
+
});
|
|
1861
|
+
return {
|
|
1862
|
+
totalCount: items.length,
|
|
1863
|
+
items: items.map((item) => ({
|
|
1864
|
+
...item,
|
|
1865
|
+
noteTitle: titleById.get(item.noteId) ?? item.noteId
|
|
1866
|
+
}))
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
});
|
|
1870
|
+
var scheduleAddInputSchema = z.strictObject({
|
|
1871
|
+
noteId: z.string().min(1).describe("Canonical Note ID to schedule onto a calendar day."),
|
|
1872
|
+
date: z.string().optional().describe('Calendar date YYYY-MM-DD or "today" (defaults to "today").'),
|
|
1873
|
+
slot: z.string().optional().describe('Optional slot badge such as "AM", "PM", or "Warmup".'),
|
|
1874
|
+
position: z.number().int().optional().describe("Optional ordering index within the day."),
|
|
1875
|
+
notes: z.string().optional().describe("Optional scaling or session intent notes for this scheduled instance.")
|
|
1876
|
+
});
|
|
1877
|
+
var wodScheduleAddTool = defineAgentTool({
|
|
1878
|
+
name: "wod_schedule_add",
|
|
1879
|
+
title: "Schedule Workout onto Day",
|
|
1880
|
+
description: "Link an existing Note onto a Journal calendar date via a ScheduleItem (M:N link-first scheduling without cloning user Notes or forcing notebook/journal).",
|
|
1881
|
+
tier: 1,
|
|
1882
|
+
domain: "journal",
|
|
1883
|
+
annotations: {
|
|
1884
|
+
title: "Schedule Workout",
|
|
1885
|
+
readOnlyHint: false,
|
|
1886
|
+
destructiveHint: false,
|
|
1887
|
+
idempotentHint: false,
|
|
1888
|
+
openWorldHint: false
|
|
1889
|
+
},
|
|
1890
|
+
inputSchema: scheduleAddInputSchema,
|
|
1891
|
+
cliEquivalent: "wod schedule add <noteId> --date YYYY-MM-DD --json",
|
|
1892
|
+
async execute(args, ctx) {
|
|
1893
|
+
const dateKey = civilDateKey(args.date);
|
|
1894
|
+
const item = await scheduleNoteOnDate(ctx.storage, {
|
|
1895
|
+
noteId: args.noteId,
|
|
1896
|
+
date: dateKey,
|
|
1897
|
+
...args.slot !== void 0 ? { slot: args.slot } : {},
|
|
1898
|
+
...args.position !== void 0 ? { position: args.position } : {},
|
|
1899
|
+
...args.notes !== void 0 ? { notes: args.notes } : {}
|
|
1900
|
+
});
|
|
1901
|
+
await ctx.onMutated?.(["schedule_items", "notes"]);
|
|
1902
|
+
return { item };
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
var scheduleBatchInputSchema = z.strictObject({
|
|
1906
|
+
items: z.array(
|
|
1907
|
+
z.strictObject({
|
|
1908
|
+
noteId: z.string().min(1),
|
|
1909
|
+
date: z.string().describe('Calendar date YYYY-MM-DD or "today".'),
|
|
1910
|
+
slot: z.string().optional(),
|
|
1911
|
+
position: z.number().int().optional(),
|
|
1912
|
+
notes: z.string().optional()
|
|
1913
|
+
})
|
|
1914
|
+
).min(1).describe("List of Note + date pairs to schedule atomically.")
|
|
1915
|
+
});
|
|
1916
|
+
var wodScheduleBatchTool = defineAgentTool({
|
|
1917
|
+
name: "wod_schedule_batch",
|
|
1918
|
+
title: "Batch Schedule Workouts",
|
|
1919
|
+
description: "Schedule one or more existing Notes across target calendar dates atomically via ScheduleItem links.",
|
|
1920
|
+
tier: 1,
|
|
1921
|
+
domain: "journal",
|
|
1922
|
+
annotations: {
|
|
1923
|
+
title: "Batch Schedule Workouts",
|
|
1924
|
+
readOnlyHint: false,
|
|
1925
|
+
destructiveHint: false,
|
|
1926
|
+
idempotentHint: false,
|
|
1927
|
+
openWorldHint: false
|
|
1928
|
+
},
|
|
1929
|
+
inputSchema: scheduleBatchInputSchema,
|
|
1930
|
+
cliEquivalent: "wod schedule batch --json",
|
|
1931
|
+
async execute(args, ctx) {
|
|
1932
|
+
const created = await batchScheduleNotes(
|
|
1933
|
+
ctx.storage,
|
|
1934
|
+
args.items.map((item) => ({
|
|
1935
|
+
noteId: item.noteId,
|
|
1936
|
+
date: civilDateKey(item.date),
|
|
1937
|
+
...item.slot !== void 0 ? { slot: item.slot } : {},
|
|
1938
|
+
...item.position !== void 0 ? { position: item.position } : {},
|
|
1939
|
+
...item.notes !== void 0 ? { notes: item.notes } : {}
|
|
1940
|
+
}))
|
|
1941
|
+
);
|
|
1942
|
+
await ctx.onMutated?.(["schedule_items", "notes"]);
|
|
1943
|
+
return { scheduledCount: created.length, items: created };
|
|
1944
|
+
}
|
|
1945
|
+
});
|
|
1946
|
+
var scheduleUpdateInputSchema = z.strictObject({
|
|
1947
|
+
scheduleItemId: z.string().min(1).describe("ScheduleItem ID to update."),
|
|
1948
|
+
date: z.string().optional().describe('New calendar date YYYY-MM-DD or "today".'),
|
|
1949
|
+
status: z.enum(["planned", "completed", "moved", "skipped"]).optional().describe("Updated schedule status."),
|
|
1950
|
+
slot: z.string().optional().describe("Updated slot label."),
|
|
1951
|
+
position: z.number().int().optional().describe("Updated intra-day ordering index."),
|
|
1952
|
+
notes: z.string().optional().describe("Updated intent or scaling notes.")
|
|
1953
|
+
});
|
|
1954
|
+
var wodScheduleUpdateTool = defineAgentTool({
|
|
1955
|
+
name: "wod_schedule_update",
|
|
1956
|
+
title: "Update Scheduled Workout",
|
|
1957
|
+
description: "Reschedule, reorder, or update status (`planned`, `completed`, `moved`, `skipped`) on a ScheduleItem.",
|
|
1958
|
+
tier: 1,
|
|
1959
|
+
domain: "journal",
|
|
1960
|
+
annotations: {
|
|
1961
|
+
title: "Update Scheduled Workout",
|
|
1962
|
+
readOnlyHint: false,
|
|
1963
|
+
destructiveHint: false,
|
|
1964
|
+
idempotentHint: true,
|
|
1965
|
+
openWorldHint: false
|
|
1966
|
+
},
|
|
1967
|
+
inputSchema: scheduleUpdateInputSchema,
|
|
1968
|
+
cliEquivalent: "wod schedule update <scheduleItemId> --json",
|
|
1969
|
+
async execute(args, ctx) {
|
|
1970
|
+
const updated = await updateScheduleItem(ctx.storage, args.scheduleItemId, {
|
|
1971
|
+
...args.date !== void 0 ? { date: civilDateKey(args.date) } : {},
|
|
1972
|
+
...args.status !== void 0 ? { status: args.status } : {},
|
|
1973
|
+
...args.slot !== void 0 ? { slot: args.slot } : {},
|
|
1974
|
+
...args.position !== void 0 ? { position: args.position } : {},
|
|
1975
|
+
...args.notes !== void 0 ? { notes: args.notes } : {}
|
|
1976
|
+
});
|
|
1977
|
+
await ctx.onMutated?.(["schedule_items"]);
|
|
1978
|
+
return { item: updated };
|
|
1979
|
+
}
|
|
1980
|
+
});
|
|
1981
|
+
var scheduleRemoveInputSchema = z.strictObject({
|
|
1982
|
+
scheduleItemId: z.string().min(1).describe("ScheduleItem ID to remove from the calendar.")
|
|
1983
|
+
});
|
|
1984
|
+
var wodScheduleRemoveTool = defineAgentTool({
|
|
1985
|
+
name: "wod_schedule_remove",
|
|
1986
|
+
title: "Unschedule Workout Instance",
|
|
1987
|
+
description: "Remove a single ScheduleItem from a calendar day while leaving the canonical Note and recorded Sessions intact.",
|
|
1988
|
+
tier: 1,
|
|
1989
|
+
domain: "journal",
|
|
1990
|
+
annotations: {
|
|
1991
|
+
title: "Unschedule Workout",
|
|
1992
|
+
readOnlyHint: false,
|
|
1993
|
+
destructiveHint: false,
|
|
1994
|
+
idempotentHint: true,
|
|
1995
|
+
openWorldHint: false
|
|
1996
|
+
},
|
|
1997
|
+
inputSchema: scheduleRemoveInputSchema,
|
|
1998
|
+
cliEquivalent: "wod schedule remove <scheduleItemId> --json",
|
|
1999
|
+
async execute(args, ctx) {
|
|
2000
|
+
await removeScheduleItem(ctx.storage, args.scheduleItemId);
|
|
2001
|
+
await ctx.onMutated?.(["schedule_items"]);
|
|
2002
|
+
return { removed: true, scheduleItemId: args.scheduleItemId };
|
|
2003
|
+
}
|
|
2004
|
+
});
|
|
2005
|
+
var SCHEDULE_AGENT_TOOLS = [
|
|
2006
|
+
wodScheduleListTool,
|
|
2007
|
+
wodScheduleAddTool,
|
|
2008
|
+
wodScheduleBatchTool,
|
|
2009
|
+
wodScheduleUpdateTool,
|
|
2010
|
+
wodScheduleRemoveTool
|
|
2011
|
+
];
|
|
1738
2012
|
function collectCollectibles(node, out = []) {
|
|
1739
2013
|
for (const metric of node.metrics ?? []) {
|
|
1740
2014
|
if (metric.value === "?" || metric.origin === "collectible") {
|
|
@@ -1865,12 +2139,13 @@ function applyCollectibleOverrides(body, overrides) {
|
|
|
1865
2139
|
return updated;
|
|
1866
2140
|
}
|
|
1867
2141
|
var sessionRunHeadlessInputSchema = z.strictObject({
|
|
1868
|
-
noteId: z.string().optional().describe("Existing Note ID to execute (read-only Seed/Feed Notes
|
|
2142
|
+
noteId: z.string().optional().describe("Existing Note ID to execute (read-only Seed/Feed Notes pin one immutable copy on first run)."),
|
|
1869
2143
|
blockId: z.string().optional().describe("Optional workout block ID on `noteId` (defaults to first wod block)."),
|
|
1870
2144
|
source: z.string().optional().describe("Inline Whiteboard Script or Markdown to persist & run when `noteId` is not supplied."),
|
|
1871
2145
|
title: z.string().optional().describe("Optional Note title when running inline `source`."),
|
|
1872
2146
|
sport: z.string().optional().describe("Optional sport dialect override."),
|
|
1873
|
-
journalDate: z.string().optional().describe('Optional YYYY-MM-DD or "today"
|
|
2147
|
+
journalDate: z.string().optional().describe('Optional YYYY-MM-DD or "today" attributed Session calendar date.'),
|
|
2148
|
+
scheduleItemId: z.string().optional().describe("Optional ScheduleItem ID that triggered this workout run."),
|
|
1874
2149
|
collectibles: z.record(z.string(), z.union([z.string(), z.number()])).optional().describe('Optional values for collectible `?` metrics (e.g. `{ "lb": 185, "reps": 12 }`).'),
|
|
1875
2150
|
stepAdvanceMs: z.number().int().min(100).max(36e5).optional().describe("Simulated clock advance per step in milliseconds (default 10000)."),
|
|
1876
2151
|
maxSteps: z.number().int().min(1).max(5e3).optional().describe("Safety cap on execution steps (default 500)."),
|
|
@@ -1911,6 +2186,7 @@ var wodSessionRunHeadlessTool = defineAgentTool({
|
|
|
1911
2186
|
noteId: targetNoteId,
|
|
1912
2187
|
blockId: args.blockId,
|
|
1913
2188
|
journalDate: args.journalDate,
|
|
2189
|
+
...args.scheduleItemId ? { scheduleItemId: args.scheduleItemId } : {},
|
|
1914
2190
|
startedAt
|
|
1915
2191
|
});
|
|
1916
2192
|
const sec = parseDocumentSections(intake.revision.rawContent, {
|
|
@@ -1990,18 +2266,45 @@ var wodSessionRunHeadlessTool = defineAgentTool({
|
|
|
1990
2266
|
const allEvents = [...eventRows, ...summaryRows];
|
|
1991
2267
|
const finalizedSession = {
|
|
1992
2268
|
...intake.session,
|
|
2269
|
+
sessionDate: intake.session.sessionDate ?? localCivilDateKey(startedAt),
|
|
1993
2270
|
status: completed ? "completed" : "in-progress",
|
|
1994
2271
|
endTime,
|
|
1995
2272
|
duration: Math.max(0, endTime - startedAt),
|
|
1996
2273
|
completed,
|
|
1997
2274
|
...args.public !== void 0 ? { public: args.public } : {}
|
|
1998
2275
|
};
|
|
1999
|
-
await ctx.storage.transaction(
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2276
|
+
await ctx.storage.transaction(
|
|
2277
|
+
["sessions", "events", "notebook_links", "schedule_items"],
|
|
2278
|
+
"readwrite",
|
|
2279
|
+
async (tx) => {
|
|
2280
|
+
await tx.readwrite("sessions").put(finalizedSession);
|
|
2281
|
+
const nbIds = finalizedSession.notebookIds ?? [];
|
|
2282
|
+
const links = nbIds.map((nbId) => ({
|
|
2283
|
+
id: makeNotebookLinkId(toNotebookId(nbId), "session", finalizedSession.id),
|
|
2284
|
+
notebookId: toNotebookId(nbId),
|
|
2285
|
+
targetKind: "session",
|
|
2286
|
+
targetId: finalizedSession.id,
|
|
2287
|
+
noteId: finalizedSession.noteId,
|
|
2288
|
+
createdAt: finalizedSession.createdAt
|
|
2289
|
+
}));
|
|
2290
|
+
if (links.length > 0) {
|
|
2291
|
+
await tx.readwrite("notebook_links").putMany(links);
|
|
2292
|
+
}
|
|
2293
|
+
if (finalizedSession.scheduleItemId) {
|
|
2294
|
+
try {
|
|
2295
|
+
const schedStore = tx.readwrite("schedule_items");
|
|
2296
|
+
const item = await schedStore.get(finalizedSession.scheduleItemId);
|
|
2297
|
+
if (item && item.status !== "completed") {
|
|
2298
|
+
await schedStore.put({ ...item, status: "completed", updatedAt: endTime });
|
|
2299
|
+
}
|
|
2300
|
+
} catch {
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
if (allEvents.length > 0) {
|
|
2304
|
+
await tx.readwrite("events").putMany(allEvents);
|
|
2305
|
+
}
|
|
2003
2306
|
}
|
|
2004
|
-
|
|
2307
|
+
);
|
|
2005
2308
|
if (args.public !== void 0) {
|
|
2006
2309
|
await setSessionPublic(ctx.storage, finalizedSession.id, args.public);
|
|
2007
2310
|
}
|
|
@@ -2012,6 +2315,7 @@ var wodSessionRunHeadlessTool = defineAgentTool({
|
|
|
2012
2315
|
blockId: finalizedSession.blockId,
|
|
2013
2316
|
blockVersion: finalizedSession.blockVersion,
|
|
2014
2317
|
clonedFromReadOnly: intake.clonedFromReadOnly,
|
|
2318
|
+
pinnedExternalWorkout: intake.pinnedExternalWorkout,
|
|
2015
2319
|
...intake.upstreamNoteId ? { upstreamNoteId: intake.upstreamNoteId } : {},
|
|
2016
2320
|
completed,
|
|
2017
2321
|
stepsExecuted: steps,
|
|
@@ -2162,10 +2466,41 @@ var wodSessionDeleteTool = defineAgentTool({
|
|
|
2162
2466
|
return { deleted, sessionId: args.sessionId };
|
|
2163
2467
|
}
|
|
2164
2468
|
});
|
|
2469
|
+
var sessionAttributeInputSchema = z.strictObject({
|
|
2470
|
+
sessionId: z.string().min(1).describe("Session ID to attribute to a calendar date or ScheduleItem."),
|
|
2471
|
+
sessionDate: z.string().optional().describe("Attributed Journal date (YYYY-MM-DD)."),
|
|
2472
|
+
scheduleItemId: z.string().nullable().optional().describe("ScheduleItem ID to link this Session with, or null to unlink into an ad-hoc Session.")
|
|
2473
|
+
});
|
|
2474
|
+
var wodSessionAttributeTool = defineAgentTool({
|
|
2475
|
+
name: "wod_session_attribute",
|
|
2476
|
+
title: "Attribute Session to Day or Plan",
|
|
2477
|
+
description: "Associate a recorded workout Session with a specific Journal civil date and/or pair or unlink it with a planned ScheduleItem.",
|
|
2478
|
+
tier: 1,
|
|
2479
|
+
domain: "session",
|
|
2480
|
+
annotations: {
|
|
2481
|
+
title: "Attribute Session",
|
|
2482
|
+
readOnlyHint: false,
|
|
2483
|
+
destructiveHint: false,
|
|
2484
|
+
idempotentHint: true,
|
|
2485
|
+
openWorldHint: false
|
|
2486
|
+
},
|
|
2487
|
+
inputSchema: sessionAttributeInputSchema,
|
|
2488
|
+
cliEquivalent: "wod session attribute <sessionId> --json",
|
|
2489
|
+
async execute(args, ctx) {
|
|
2490
|
+
const updated = await attributeSession(ctx.storage, {
|
|
2491
|
+
sessionId: args.sessionId,
|
|
2492
|
+
...args.sessionDate !== void 0 ? { sessionDate: args.sessionDate } : {},
|
|
2493
|
+
...args.scheduleItemId !== void 0 ? { scheduleItemId: args.scheduleItemId } : {}
|
|
2494
|
+
});
|
|
2495
|
+
await ctx.onMutated?.(["sessions", "schedule_items"]);
|
|
2496
|
+
return { session: updated };
|
|
2497
|
+
}
|
|
2498
|
+
});
|
|
2165
2499
|
var SESSION_AGENT_TOOLS = [
|
|
2166
2500
|
wodSessionRunHeadlessTool,
|
|
2167
2501
|
wodSessionListTool,
|
|
2168
2502
|
wodSessionGetTool,
|
|
2503
|
+
wodSessionAttributeTool,
|
|
2169
2504
|
wodSessionDeleteTool
|
|
2170
2505
|
];
|
|
2171
2506
|
var validateWqlInputSchema = z.strictObject({
|
|
@@ -2317,6 +2652,7 @@ var DOMAIN_AGENT_TOOLS = [
|
|
|
2317
2652
|
...WQL_AGENT_TOOLS,
|
|
2318
2653
|
...NOTE_AGENT_TOOLS,
|
|
2319
2654
|
...JOURNAL_AGENT_TOOLS,
|
|
2655
|
+
...SCHEDULE_AGENT_TOOLS,
|
|
2320
2656
|
...NOTEBOOK_AGENT_TOOLS,
|
|
2321
2657
|
...SESSION_AGENT_TOOLS,
|
|
2322
2658
|
...CATALOG_AGENT_TOOLS,
|
|
@@ -2655,6 +2991,6 @@ function exportAgentCapabilitiesManifest(options) {
|
|
|
2655
2991
|
};
|
|
2656
2992
|
}
|
|
2657
2993
|
|
|
2658
|
-
export { AGENT_PROMPTS, AGENT_RESOURCE_TEMPLATES, AGENT_STATIC_RESOURCES, AgentConfirmationRequiredError, DOMAIN_AGENT_TOOLS, DOMAIN_AGENT_TOOLS_BY_NAME, WHITEBOARD_SCRIPT_REFERENCE_MARKDOWN, buildWqlReferenceObject, civilDateKey, createQueryServiceForStorage, defineAgentTool, deleteNoteFromStorage, deleteSessionFromStorage, exportAgentCapabilitiesManifest, normalizeMarkdownOrBareScript, noteDeepLink, readAgentResource, renderAgentPrompt, requireDestructiveConfirmation, upsertNoteInStorage, wodCatalogLookupTool, wodCatalogUpsertTool, wodExportBundleTool, wodFeedManageTool, wodJournalAddTool, wodJournalDayTool, wodNoteCloneTool, wodNoteDeleteTool, wodNoteGetTool, wodNoteListTool, wodNoteUpsertTool, wodNotebookDeleteTool, wodNotebookListTool, wodNotebookSaveTool, wodParseScriptTool, wodQueryWqlTool, wodResetStorageTool, wodSessionDeleteTool, wodSessionGetTool, wodSessionListTool, wodSessionRunHeadlessTool, wodValidateWqlTool, zodSchemaToJsonSchema };
|
|
2994
|
+
export { AGENT_PROMPTS, AGENT_RESOURCE_TEMPLATES, AGENT_STATIC_RESOURCES, AgentConfirmationRequiredError, DOMAIN_AGENT_TOOLS, DOMAIN_AGENT_TOOLS_BY_NAME, WHITEBOARD_SCRIPT_REFERENCE_MARKDOWN, buildWqlReferenceObject, civilDateKey, createQueryServiceForStorage, defineAgentTool, deleteNoteFromStorage, deleteSessionFromStorage, exportAgentCapabilitiesManifest, normalizeMarkdownOrBareScript, noteDeepLink, readAgentResource, renderAgentPrompt, requireDestructiveConfirmation, upsertNoteInStorage, wodCatalogLookupTool, wodCatalogUpsertTool, wodExportBundleTool, wodFeedManageTool, wodJournalAddTool, wodJournalDayTool, wodNoteCloneTool, wodNoteDeleteTool, wodNoteGetTool, wodNoteListTool, wodNoteUpsertTool, wodNotebookDeleteTool, wodNotebookListTool, wodNotebookSaveTool, wodParseScriptTool, wodQueryWqlTool, wodResetStorageTool, wodScheduleAddTool, wodScheduleBatchTool, wodScheduleListTool, wodScheduleRemoveTool, wodScheduleUpdateTool, wodSessionAttributeTool, wodSessionDeleteTool, wodSessionGetTool, wodSessionListTool, wodSessionRunHeadlessTool, wodValidateWqlTool, zodSchemaToJsonSchema };
|
|
2659
2995
|
//# sourceMappingURL=agent.mjs.map
|
|
2660
2996
|
//# sourceMappingURL=agent.mjs.map
|