@bitcobblers/wod-wiki-engine 0.59.2236 → 0.59.2238

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 CHANGED
@@ -1031,6 +1031,24 @@ async function getNoteNotebooks(storage, noteId) {
1031
1031
  var SEED_SCHEMA = 9;
1032
1032
  var SEED_REGISTERED_WIDGETS = wodWikiCore.KNOWN_SECTION_WIDGETS;
1033
1033
  var SEED_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
1034
+ var SEED_PRECEDENCE_RANK = {
1035
+ core: 0,
1036
+ community: 1,
1037
+ imported: 2,
1038
+ user: 3
1039
+ };
1040
+ function seedSourceTier(sourceIdOrMetaKey, explicitTier) {
1041
+ if (explicitTier) return explicitTier;
1042
+ if (!sourceIdOrMetaKey) return "core";
1043
+ if (sourceIdOrMetaKey === "user") return "user";
1044
+ const id = sourceIdOrMetaKey.startsWith("seed:") ? sourceIdOrMetaKey.slice(5) : sourceIdOrMetaKey;
1045
+ if (id === "core" || id === "efforts" || id === "equipment") return "core";
1046
+ if (id === "community" || id.startsWith("community-") || id === "common") return "community";
1047
+ return "imported";
1048
+ }
1049
+ function seedPrecedenceRank(sourceIdOrMetaKey, explicitTier) {
1050
+ return SEED_PRECEDENCE_RANK[seedSourceTier(sourceIdOrMetaKey, explicitTier)];
1051
+ }
1034
1052
  var EFFORTS_CHUNK_ID = "efforts";
1035
1053
  var EQUIPMENT_CHUNK_ID = "equipment";
1036
1054
  function seedMetaKey(sourceId) {
@@ -2028,7 +2046,7 @@ async function promoteReferencedOverridesToNotebook(storage, input) {
2028
2046
  }
2029
2047
 
2030
2048
  // src/agent/tools/catalogTools.ts
2031
- var catalogLookupInputSchema = zod.z.object({
2049
+ var catalogLookupInputSchema = zod.z.strictObject({
2032
2050
  kind: zod.z.enum(["effort", "equipment", "tag", "tag-type"]).describe("Catalog family to search or inspect."),
2033
2051
  search: zod.z.string().optional().describe("Case-insensitive slug, label, or alias filter."),
2034
2052
  slug: zod.z.string().optional().describe("Exact canonical slug/name to look up."),
@@ -2128,7 +2146,7 @@ var wodCatalogLookupTool = defineAgentTool({
2128
2146
  };
2129
2147
  }
2130
2148
  });
2131
- var catalogUpsertInputSchema = zod.z.object({
2149
+ var catalogUpsertInputSchema = zod.z.strictObject({
2132
2150
  kind: zod.z.enum(["effort", "equipment", "tag", "tag-type"]).describe("Property definition family to create or override."),
2133
2151
  slug: zod.z.string().min(1).describe('Canonical kebab-case slug (e.g. "kettlebell-swing", "barbell").'),
2134
2152
  label: zod.z.string().optional().describe("Human-readable display label."),
@@ -2240,6 +2258,208 @@ var wodCatalogUpsertTool = defineAgentTool({
2240
2258
  }
2241
2259
  });
2242
2260
  var CATALOG_AGENT_TOOLS = [wodCatalogLookupTool, wodCatalogUpsertTool];
2261
+ var FEED_SUBSCRIPTIONS_META_KEY = "feed:subscriptions";
2262
+ async function removeSeedSourceContent(storage, meta) {
2263
+ return await storage.transaction(
2264
+ [
2265
+ "notes",
2266
+ "attachments",
2267
+ "tags",
2268
+ "note_tags",
2269
+ "block_index",
2270
+ "block_efforts",
2271
+ "block_equipment",
2272
+ "page_notes",
2273
+ "efforts",
2274
+ "equipment",
2275
+ "property_overrides",
2276
+ "meta"
2277
+ ],
2278
+ "readwrite",
2279
+ async (tx) => {
2280
+ const targetIds = /* @__PURE__ */ new Set();
2281
+ const legacyChunks = [];
2282
+ for (const [chunkId, chunk] of Object.entries(meta.chunks)) {
2283
+ if (chunk.noteIds?.length) {
2284
+ for (const id of chunk.noteIds) targetIds.add(id);
2285
+ } else {
2286
+ legacyChunks.push(chunkId);
2287
+ }
2288
+ }
2289
+ if (legacyChunks.length) {
2290
+ for (const note of await tx.readwrite("notes").getAll()) {
2291
+ if (note.seedOrigin === "seed" && note.seedChunkId && legacyChunks.includes(note.seedChunkId)) {
2292
+ targetIds.add(note.id);
2293
+ }
2294
+ }
2295
+ }
2296
+ const metaStore = tx.readwrite("meta");
2297
+ const otherCheckpoints = [];
2298
+ for (const row of await metaStore.getAll()) {
2299
+ const other = row;
2300
+ if (!other || typeof other.key !== "string" || !other.key.startsWith("seed:") || other.key === meta.key) {
2301
+ continue;
2302
+ }
2303
+ const noteIds = /* @__PURE__ */ new Set();
2304
+ for (const chunk of Object.values(other.chunks ?? {})) {
2305
+ for (const id of chunk.noteIds ?? []) noteIds.add(id);
2306
+ }
2307
+ otherCheckpoints.push({
2308
+ key: other.key,
2309
+ sourceId: other.key.slice(5),
2310
+ rank: seedPrecedenceRank(other.key, other.tier),
2311
+ meta: other,
2312
+ noteIds
2313
+ });
2314
+ }
2315
+ otherCheckpoints.sort((a, b) => b.rank - a.rank);
2316
+ const isClaimedByOther = (noteId) => otherCheckpoints.some((cp) => cp.noteIds.has(noteId));
2317
+ const removedSourceId = meta.key.startsWith("seed:") ? meta.key.slice(5) : meta.key;
2318
+ const notes = tx.readwrite("notes");
2319
+ const noteTags = tx.readwrite("note_tags");
2320
+ let deleted = 0;
2321
+ const removedPaths = /* @__PURE__ */ new Set();
2322
+ const touchedTagIds = /* @__PURE__ */ new Set();
2323
+ for (const id of targetIds) {
2324
+ if (isClaimedByOther(id)) continue;
2325
+ const note = await notes.get(id);
2326
+ if (!note || note.seedOrigin !== "seed") continue;
2327
+ if (note.seedChunkId && !meta.chunks[note.seedChunkId]) continue;
2328
+ if (note.sourcePath) removedPaths.add(note.sourcePath);
2329
+ await notes.delete(id);
2330
+ const attachments = tx.readwrite("attachments");
2331
+ for (const attachment of await attachments.getAllFromIndex("by-note", id)) {
2332
+ await attachments.delete(attachment.id);
2333
+ }
2334
+ for (const link of await noteTags.getAllFromIndex("by-note", id)) {
2335
+ touchedTagIds.add(link.tagId);
2336
+ await noteTags.delete(link.id);
2337
+ }
2338
+ const blockIndex = tx.readwrite("block_index");
2339
+ for (const row of await blockIndex.getAllFromIndex("by-note", id)) await blockIndex.delete(row.id);
2340
+ const blockEfforts = tx.readwrite("block_efforts");
2341
+ for (const row of await blockEfforts.getAllFromIndex("by-note", id)) await blockEfforts.delete(row.id);
2342
+ const blockEquipment = tx.readwrite("block_equipment");
2343
+ for (const row of await blockEquipment.getAllFromIndex("by-note", id)) await blockEquipment.delete(row.id);
2344
+ const pageNotes = tx.readwrite("page_notes");
2345
+ for (const link of await pageNotes.getAllFromIndex("by-note", id)) await pageNotes.delete(link.id);
2346
+ deleted++;
2347
+ }
2348
+ if (touchedTagIds.size > 0) {
2349
+ const tagsStore = tx.readwrite("tags");
2350
+ for (const tagId of touchedTagIds) {
2351
+ const remainingLinks = await noteTags.countFromIndex("by-tag", tagId);
2352
+ if (remainingLinks > 0) continue;
2353
+ const tag = await tagsStore.get(tagId);
2354
+ if (!tag) continue;
2355
+ if (tag.contributions && tag.contributions.length > 0) continue;
2356
+ const refNote = await notes.get(`t/${tag.type ?? "tag"}/${tag.label}`);
2357
+ if (refNote) continue;
2358
+ await tagsStore.delete(tagId);
2359
+ }
2360
+ }
2361
+ const defFamilies = [
2362
+ { storeName: "efforts", familyPathPrefix: "markdown/efforts/", parse: wodWikiLang.parseEffortFile },
2363
+ { storeName: "equipment", familyPathPrefix: "markdown/equipment/", parse: wodWikiLang.parseEquipmentFile }
2364
+ ];
2365
+ for (const { storeName, familyPathPrefix, parse } of defFamilies) {
2366
+ const store = tx.readwrite(storeName);
2367
+ for (const row of await store.getAll()) {
2368
+ if (row.registrySource !== "bundled") continue;
2369
+ const owned = row.sourceId === removedSourceId || row.ownerNoteId !== void 0 && targetIds.has(row.ownerNoteId) && (!row.sourceId || row.sourceId === storeName) || row.sourcePath !== void 0 && row.sourcePath.startsWith(familyPathPrefix) && removedPaths.has(row.sourcePath);
2370
+ if (!owned) continue;
2371
+ let restored = false;
2372
+ for (const cp of otherCheckpoints) {
2373
+ const candidateIds = cp.meta.chunks?.[storeName]?.noteIds ?? [];
2374
+ for (const candidateId of candidateIds) {
2375
+ const candidateNote = await notes.get(candidateId);
2376
+ if (!candidateNote || candidateNote.seedOrigin !== "seed") continue;
2377
+ const parsed = parse(candidateNote.rawContent);
2378
+ if (parsed && parsed.slug === row.slug) {
2379
+ await store.put({
2380
+ ...parsed,
2381
+ registrySource: "bundled",
2382
+ ownerNoteId: candidateNote.id,
2383
+ sourceId: cp.sourceId,
2384
+ feedSourceId: cp.sourceId,
2385
+ sourcePath: candidateNote.sourcePath ?? ""
2386
+ });
2387
+ restored = true;
2388
+ break;
2389
+ }
2390
+ }
2391
+ if (restored) break;
2392
+ }
2393
+ if (!restored) await store.delete(row.slug);
2394
+ }
2395
+ }
2396
+ try {
2397
+ const overrideStore = tx.readwrite("property_overrides");
2398
+ for (const ov of await overrideStore.getAll()) {
2399
+ if (ov.seedOrigin === "seed" && ov.feedSourceId === removedSourceId) {
2400
+ await overrideStore.delete(ov.id);
2401
+ }
2402
+ }
2403
+ } catch {
2404
+ }
2405
+ await metaStore.delete(meta.key);
2406
+ return deleted;
2407
+ }
2408
+ );
2409
+ }
2410
+ async function readFeedSubscriptionsMap(storage) {
2411
+ const row = await storage.readonly("meta").get(FEED_SUBSCRIPTIONS_META_KEY);
2412
+ return { ...row?.entries ?? {} };
2413
+ }
2414
+ async function writeFeedSubscriptionEntry(storage, sourceId, entry) {
2415
+ await storage.transaction(["meta"], "readwrite", async (tx) => {
2416
+ const metaStore = tx.readwrite("meta");
2417
+ const existing = await metaStore.get(FEED_SUBSCRIPTIONS_META_KEY);
2418
+ const entries = { ...existing?.entries ?? {}, [sourceId]: entry };
2419
+ await metaStore.put({ key: FEED_SUBSCRIPTIONS_META_KEY, entries });
2420
+ });
2421
+ }
2422
+ async function listFeedSubscriptionsHeadless(storage) {
2423
+ return readFeedSubscriptionsMap(storage);
2424
+ }
2425
+ async function subscribeFeedSourceHeadless(storage, sourceId, options) {
2426
+ const notebookIds = options?.notebookIds && options.notebookIds.length > 0 ? options.notebookIds : null;
2427
+ await writeFeedSubscriptionEntry(storage, sourceId, {
2428
+ subscribed: true,
2429
+ notebookIds,
2430
+ hidden: false,
2431
+ ...options?.url ? { url: options.url } : {},
2432
+ ...options?.name ? { name: options.name } : {},
2433
+ updatedAt: Date.now()
2434
+ });
2435
+ return { sourceId, subscribed: true, notebookIds };
2436
+ }
2437
+ async function unsubscribeFeedSourceHeadless(storage, sourceId) {
2438
+ if (sourceId === "core") {
2439
+ throw new Error("Core feed cannot be unsubscribed.");
2440
+ }
2441
+ const meta = await storage.readonly("meta").get(seedMetaKey(sourceId));
2442
+ const deletedNotes = meta ? await removeSeedSourceContent(storage, meta) : 0;
2443
+ await writeFeedSubscriptionEntry(storage, sourceId, {
2444
+ subscribed: false,
2445
+ hidden: false,
2446
+ updatedAt: Date.now()
2447
+ });
2448
+ return { sourceId, unsubscribed: true, deletedNotes };
2449
+ }
2450
+ async function deleteFeedSourceHeadless(storage, sourceId) {
2451
+ if (sourceId === "core") {
2452
+ throw new Error("Core feed cannot be deleted.");
2453
+ }
2454
+ const meta = await storage.readonly("meta").get(seedMetaKey(sourceId));
2455
+ const deletedNotes = meta ? await removeSeedSourceContent(storage, meta) : 0;
2456
+ await writeFeedSubscriptionEntry(storage, sourceId, {
2457
+ subscribed: false,
2458
+ hidden: true,
2459
+ updatedAt: Date.now()
2460
+ });
2461
+ return { sourceId, deleted: true, deletedNotes };
2462
+ }
2243
2463
  function object(value) {
2244
2464
  return typeof value === "object" && value !== null && !Array.isArray(value);
2245
2465
  }
@@ -2843,7 +3063,7 @@ async function ingestPortableFilesIntoStorage(storage, files, options = {}) {
2843
3063
  }
2844
3064
 
2845
3065
  // src/version.ts
2846
- var VERSION = "0.59.2236";
3066
+ var VERSION = "0.59.2238";
2847
3067
 
2848
3068
  // src/feed/qr.ts
2849
3069
  var APP_ORIGIN = "https://wod.wiki";
@@ -3778,10 +3998,26 @@ async function collectPublicStorageState(storage, options = {}) {
3778
3998
  storedCheckpoint
3779
3999
  };
3780
4000
  }
4001
+ async function recordPublishedFeedCheckpoint(storage, report) {
4002
+ const chunkShas = {};
4003
+ for (const c of report.manifest.chunks) chunkShas[c.id] = c.sha256;
4004
+ const cp = {
4005
+ key: PUBLISHED_FEED_META_KEY,
4006
+ version: report.manifest.version,
4007
+ builtAt: report.manifest.builtAt,
4008
+ manifestSha256: report.manifestSha256,
4009
+ chunkShas
4010
+ };
4011
+ await storage.transaction(["meta"], "readwrite", async (tx) => {
4012
+ await tx.readwrite("meta").put(cp);
4013
+ });
4014
+ }
3781
4015
  async function publishFeedFromStorage(storage, tree, options = {}) {
4016
+ options.signal?.throwIfAborted();
3782
4017
  const t0 = Date.now();
3783
4018
  const layout = options.layout ?? "feed";
3784
4019
  const state = await collectPublicStorageState(storage, options);
4020
+ options.signal?.throwIfAborted();
3785
4021
  if (state.notebooks.size === 0) {
3786
4022
  throw new Error("No public notebooks found to publish. Mark at least one user-owned notebook as Public first.");
3787
4023
  }
@@ -4069,28 +4305,19 @@ ${group.description ?? ""}
4069
4305
  const manifestBytes = encodeUtf8(JSON.stringify(manifest, null, 2) + "\n");
4070
4306
  const manifestSha256 = await sha256HexAsync(manifestBytes);
4071
4307
  await tree.write(`${artifactPrefix}manifest.json`, manifestBytes);
4072
- const shouldCheckpoint = options.recordCheckpoint ?? (layout === "feed" && !options.notebookSlug);
4073
- if (shouldCheckpoint) {
4074
- const chunkShas = {};
4075
- for (const c of manifestChunks) chunkShas[c.id] = c.sha256;
4076
- const cp = {
4077
- key: PUBLISHED_FEED_META_KEY,
4078
- version: nextVersion,
4079
- builtAt,
4080
- manifestSha256,
4081
- chunkShas
4082
- };
4083
- await storage.transaction(["meta"], "readwrite", async (tx) => {
4084
- await tx.readwrite("meta").put(cp);
4085
- });
4086
- }
4087
- return {
4308
+ const report = {
4088
4309
  manifest,
4089
4310
  notebooks: sortedSlugs,
4090
4311
  totalNotes,
4091
4312
  totalPublicSessions,
4092
4313
  manifestSha256
4093
4314
  };
4315
+ const shouldCheckpoint = options.recordCheckpoint ?? (layout === "feed" && !options.notebookSlug);
4316
+ if (shouldCheckpoint) {
4317
+ options.signal?.throwIfAborted();
4318
+ await recordPublishedFeedCheckpoint(storage, report);
4319
+ }
4320
+ return report;
4094
4321
  }
4095
4322
  async function checkUnpublishedFeedChanges(storage, currentTree, options = {}) {
4096
4323
  const state = await collectPublicStorageState(storage, options);
@@ -4178,13 +4405,17 @@ async function checkUnpublishedFeedChanges(storage, currentTree, options = {}) {
4178
4405
  }
4179
4406
 
4180
4407
  // src/agent/tools/feedTools.ts
4181
- var feedManageInputSchema = zod.z.object({
4182
- action: zod.z.enum(["list", "status", "publish", "import-bundle"]).describe("Feed or portability operation to run."),
4408
+ var feedManageInputSchema = zod.z.strictObject({
4409
+ action: zod.z.enum(["list", "status", "publish", "import-bundle", "subscribe", "unsubscribe", "delete"]).describe("Feed or portability operation to run."),
4410
+ sourceId: zod.z.string().min(1).optional().describe('Target Feed source ID when action is "subscribe", "unsubscribe", or "delete".'),
4411
+ notebookIds: zod.z.array(zod.z.string().min(1)).optional().describe('Optional subset of Notebook IDs when action="subscribe".'),
4412
+ url: zod.z.string().min(1).optional().describe("Optional Feed manifest URL when subscribing to a custom source."),
4413
+ confirmId: zod.z.string().optional().describe("Confirmation token (must match sourceId) for non-interactive unsubscribe/delete calls."),
4183
4414
  notebookSlug: zod.z.string().optional().describe("Optional Notebook slug filter when publishing."),
4184
- name: zod.z.string().optional().describe("Optional Feed display name when publishing."),
4415
+ name: zod.z.string().optional().describe("Optional Feed display name when publishing or subscribing."),
4185
4416
  description: zod.z.string().optional().describe("Optional Feed description when publishing."),
4186
4417
  files: zod.z.array(
4187
- zod.z.object({
4418
+ zod.z.strictObject({
4188
4419
  path: zod.z.string().min(1),
4189
4420
  content: zod.z.string()
4190
4421
  })
@@ -4193,7 +4424,7 @@ var feedManageInputSchema = zod.z.object({
4193
4424
  var wodFeedManageTool = defineAgentTool({
4194
4425
  name: "wod_feed_manage",
4195
4426
  title: "Manage Feeds & Portability",
4196
- description: "Inspect installed Seed/Feed sources (`list`), check unpublished public Notebook changes (`status`), compile and publish public Notebooks (`publish`), or import portable Markdown + JSONL/CSV files (`import-bundle`).",
4427
+ description: "Inspect installed Seed/Feed sources (`list`), check unpublished public Notebook changes (`status`), compile and publish public Notebooks (`publish`), import portable Markdown + JSONL/CSV files (`import-bundle`), or subscribe/unsubscribe/delete a Feed source.",
4197
4428
  tier: 1,
4198
4429
  domain: "feed",
4199
4430
  annotations: {
@@ -4204,27 +4435,120 @@ var wodFeedManageTool = defineAgentTool({
4204
4435
  openWorldHint: false
4205
4436
  },
4206
4437
  inputSchema: feedManageInputSchema,
4207
- cliEquivalent: "wod feed <list|status|publish> --json",
4438
+ cliEquivalent: "wod feed <list|status|publish|subscribe|unsubscribe|delete> --json",
4208
4439
  async execute(args, ctx) {
4209
4440
  if (args.action === "list") {
4210
4441
  const metaRows = await ctx.storage.readonly("meta").getAll();
4442
+ const subscriptions = await listFeedSubscriptionsHeadless(ctx.storage);
4211
4443
  const installedFeeds = [];
4212
4444
  for (const row of metaRows) {
4213
4445
  const obj = row;
4214
4446
  if (typeof obj.key === "string" && obj.key.startsWith("seed:") && obj.key !== seedMetaKey("user")) {
4447
+ const sourceId = obj.key.slice("seed:".length);
4215
4448
  installedFeeds.push({
4216
- sourceId: obj.key.slice("seed:".length),
4449
+ sourceId,
4217
4450
  seedVersion: obj.seedVersion,
4218
4451
  builtAt: obj.builtAt,
4219
4452
  importedAt: obj.importedAt,
4220
- chunkCount: Object.keys(obj.chunks ?? {}).length
4453
+ chunkCount: Object.keys(obj.chunks ?? {}).length,
4454
+ subscribed: subscriptions[sourceId]?.subscribed ?? true
4221
4455
  });
4222
4456
  }
4223
4457
  }
4224
4458
  return {
4225
4459
  action: "list",
4226
4460
  installedCount: installedFeeds.length,
4227
- feeds: installedFeeds
4461
+ feeds: installedFeeds,
4462
+ subscriptions
4463
+ };
4464
+ }
4465
+ if (args.action === "subscribe") {
4466
+ if (!args.sourceId) {
4467
+ throw new Error('Provide `sourceId` when action="subscribe".');
4468
+ }
4469
+ const res = ctx.feedLifecycle?.subscribe ? await ctx.feedLifecycle.subscribe(args.sourceId, {
4470
+ notebookIds: args.notebookIds,
4471
+ url: args.url,
4472
+ name: args.name
4473
+ }) : await subscribeFeedSourceHeadless(ctx.storage, args.sourceId, {
4474
+ notebookIds: args.notebookIds,
4475
+ url: args.url,
4476
+ name: args.name
4477
+ });
4478
+ await ctx.onMutated?.(["meta", "notes"]);
4479
+ return {
4480
+ action: "subscribe",
4481
+ ...res
4482
+ };
4483
+ }
4484
+ if (args.action === "unsubscribe") {
4485
+ if (!args.sourceId) {
4486
+ throw new Error('Provide `sourceId` when action="unsubscribe".');
4487
+ }
4488
+ if (args.sourceId === "core") {
4489
+ throw new Error("Core feed cannot be unsubscribed.");
4490
+ }
4491
+ await requireDestructiveConfirmation(
4492
+ ctx,
4493
+ {
4494
+ action: "wod_feed_manage:unsubscribe",
4495
+ targetId: args.sourceId,
4496
+ summary: `Unsubscribe from feed '${args.sourceId}' and purge its imported notes`
4497
+ },
4498
+ args.confirmId
4499
+ );
4500
+ const res = ctx.feedLifecycle?.unsubscribe ? await ctx.feedLifecycle.unsubscribe(args.sourceId) : await unsubscribeFeedSourceHeadless(ctx.storage, args.sourceId);
4501
+ await ctx.onMutated?.([
4502
+ "meta",
4503
+ "notes",
4504
+ "tags",
4505
+ "note_tags",
4506
+ "block_index",
4507
+ "block_efforts",
4508
+ "block_equipment",
4509
+ "page_notes",
4510
+ "efforts",
4511
+ "equipment",
4512
+ "property_overrides"
4513
+ ]);
4514
+ return {
4515
+ action: "unsubscribe",
4516
+ ...res
4517
+ };
4518
+ }
4519
+ if (args.action === "delete") {
4520
+ if (!args.sourceId) {
4521
+ throw new Error('Provide `sourceId` when action="delete".');
4522
+ }
4523
+ if (args.sourceId === "core") {
4524
+ throw new Error("Core feed cannot be deleted.");
4525
+ }
4526
+ await requireDestructiveConfirmation(
4527
+ ctx,
4528
+ {
4529
+ action: "wod_feed_manage:delete",
4530
+ targetId: args.sourceId,
4531
+ summary: `Delete feed source '${args.sourceId}' and purge all of its imported notes`
4532
+ },
4533
+ args.confirmId
4534
+ );
4535
+ const res = ctx.feedLifecycle?.delete ? await ctx.feedLifecycle.delete(args.sourceId) : await deleteFeedSourceHeadless(ctx.storage, args.sourceId);
4536
+ await ctx.onMutated?.([
4537
+ "meta",
4538
+ "notes",
4539
+ "tags",
4540
+ "note_tags",
4541
+ "block_index",
4542
+ "block_efforts",
4543
+ "block_equipment",
4544
+ "page_notes",
4545
+ "efforts",
4546
+ "equipment",
4547
+ "property_overrides"
4548
+ ]);
4549
+ return {
4550
+ action: "delete",
4551
+ ...res
4228
4552
  };
4229
4553
  }
4230
4554
  if (args.action === "status") {
@@ -4273,7 +4597,7 @@ var wodFeedManageTool = defineAgentTool({
4273
4597
  };
4274
4598
  }
4275
4599
  });
4276
- var exportBundleInputSchema = zod.z.object({
4600
+ var exportBundleInputSchema = zod.z.strictObject({
4277
4601
  noteIds: zod.z.array(zod.z.string()).optional().describe("Optional Note IDs to export (defaults to all user-owned Notes)."),
4278
4602
  telemetryFormat: zod.z.enum(["jsonl", "csv", "both"]).optional().describe('Format for companion Session/Event telemetry files (default "jsonl").')
4279
4603
  });
@@ -4303,7 +4627,7 @@ var wodExportBundleTool = defineAgentTool({
4303
4627
  };
4304
4628
  }
4305
4629
  });
4306
- var resetStorageInputSchema = zod.z.object({
4630
+ var resetStorageInputSchema = zod.z.strictObject({
4307
4631
  confirmToken: zod.z.string().optional().describe('For non-interactive MCP/CLI calls, pass confirmToken="WIPE_STORAGE" to confirm wiping user storage.')
4308
4632
  });
4309
4633
  var wodResetStorageTool = defineAgentTool({
@@ -4341,7 +4665,7 @@ var FEED_AGENT_TOOLS = [
4341
4665
  wodExportBundleTool,
4342
4666
  wodResetStorageTool
4343
4667
  ];
4344
- var journalDayInputSchema = zod.z.object({
4668
+ var journalDayInputSchema = zod.z.strictObject({
4345
4669
  date: zod.z.string().optional().describe('Calendar date in YYYY-MM-DD format, or "today" (defaults to "today").')
4346
4670
  });
4347
4671
  var wodJournalDayTool = defineAgentTool({
@@ -4436,7 +4760,7 @@ var wodJournalDayTool = defineAgentTool({
4436
4760
  };
4437
4761
  }
4438
4762
  });
4439
- var journalAddInputSchema = zod.z.object({
4763
+ var journalAddInputSchema = zod.z.strictObject({
4440
4764
  date: zod.z.string().optional().describe('Target Journal date in YYYY-MM-DD format or "today" (defaults to "today").'),
4441
4765
  title: zod.z.string().optional().describe("Workout title (defaults to # H1 heading or date)."),
4442
4766
  content: zod.z.string().min(1).describe("Markdown workout note or bare Whiteboard Script to schedule onto the Journal day."),
@@ -4500,7 +4824,7 @@ function isLandingNote(note) {
4500
4824
  return note.id.startsWith("notebook/") && note.notebookId === note.id;
4501
4825
  }
4502
4826
  var RESERVED_SLUGS = new Set(wodWikiCore.BUILTIN_NOTEBOOKS.map((b) => b.slug));
4503
- var notebookListInputSchema = zod.z.object({
4827
+ var notebookListInputSchema = zod.z.strictObject({
4504
4828
  origin: zod.z.enum(["all", "default", "user", "feed"]).optional().describe('Filter notebooks by origin (default "all").')
4505
4829
  });
4506
4830
  var wodNotebookListTool = defineAgentTool({
@@ -4587,7 +4911,7 @@ var wodNotebookListTool = defineAgentTool({
4587
4911
  };
4588
4912
  }
4589
4913
  });
4590
- var notebookSaveInputSchema = zod.z.object({
4914
+ var notebookSaveInputSchema = zod.z.strictObject({
4591
4915
  action: zod.z.enum(["create", "update", "promote", "detach", "set-public"]).describe("Operation to perform on a user Notebook."),
4592
4916
  notebookId: zod.z.string().optional().describe("Target Notebook slug or ID (required for update, promote, detach, set-public)."),
4593
4917
  name: zod.z.string().optional().describe("Display name when creating or renaming a Notebook."),
@@ -4716,7 +5040,7 @@ icon: ${JSON.stringify(nextIcon)}
4716
5040
  };
4717
5041
  }
4718
5042
  });
4719
- var notebookDeleteInputSchema = zod.z.object({
5043
+ var notebookDeleteInputSchema = zod.z.strictObject({
4720
5044
  notebookId: zod.z.string().min(1).describe("User Notebook ID or slug to delete (member Notes stay safe in notebook/journal)."),
4721
5045
  confirmId: zod.z.string().optional().describe("For non-interactive MCP/CLI calls, repeat the exact notebookId or slug to confirm deletion.")
4722
5046
  });
@@ -5087,7 +5411,7 @@ function buildNoteProvenance(sourceNote, sourceNotebookId, clonedAt) {
5087
5411
  function isLandingNote2(note) {
5088
5412
  return note.id.startsWith("notebook/") && note.notebookId === note.id;
5089
5413
  }
5090
- var noteListInputSchema = zod.z.object({
5414
+ var noteListInputSchema = zod.z.strictObject({
5091
5415
  notebookId: zod.z.string().optional().describe('Filter by notebook ID or slug (e.g. "journal", "custom", "guides", "notebook/strength").'),
5092
5416
  search: zod.z.string().optional().describe("Case-insensitive substring filter over title and Markdown content."),
5093
5417
  tag: zod.z.string().optional().describe("Filter to Notes carrying this tag label."),
@@ -5110,23 +5434,30 @@ var wodNoteListTool = defineAgentTool({
5110
5434
  inputSchema: noteListInputSchema,
5111
5435
  cliEquivalent: "wod note list --json",
5112
5436
  async execute(args, ctx) {
5113
- const allNotes = await ctx.storage.readonly("notes").getAll();
5114
5437
  const targetNb = args.notebookId ? wodWikiCore.toNotebookId(args.notebookId) : void 0;
5115
5438
  const includeSeed = args.includeSeed ?? Boolean(targetNb);
5116
5439
  const searchLower = args.search?.trim().toLowerCase();
5117
5440
  const tagLower = args.tag?.trim().toLowerCase();
5118
5441
  const limit = args.limit ?? 50;
5119
- let linkedNoteIdsForNb;
5120
- if (targetNb) {
5121
- try {
5122
- const links = await ctx.storage.readonly("notebook_links").getAllFromIndex("by-notebook", targetNb);
5123
- linkedNoteIdsForNb = new Set(
5124
- links.filter((l) => l.targetKind === "note").map((l) => l.noteId)
5125
- );
5126
- } catch {
5127
- linkedNoteIdsForNb = /* @__PURE__ */ new Set();
5442
+ const { allNotes, linkedNoteIdsForNb } = await ctx.storage.transaction(
5443
+ ["notes", "notebook_links"],
5444
+ "readonly",
5445
+ async (tx) => {
5446
+ const notes = await tx.readonly("notes").getAll();
5447
+ let linkedIds;
5448
+ if (targetNb) {
5449
+ try {
5450
+ const links = await tx.readonly("notebook_links").getAllFromIndex("by-notebook", targetNb);
5451
+ linkedIds = new Set(
5452
+ links.filter((l) => l.targetKind === "note").map((l) => l.noteId)
5453
+ );
5454
+ } catch {
5455
+ linkedIds = /* @__PURE__ */ new Set();
5456
+ }
5457
+ }
5458
+ return { allNotes: notes, linkedNoteIdsForNb: linkedIds };
5128
5459
  }
5129
- }
5460
+ );
5130
5461
  const filtered = allNotes.filter((n) => {
5131
5462
  if (isLandingNote2(n)) return false;
5132
5463
  if (!includeSeed && (n.seedOrigin === "seed" || n.feedOrigin === "feed")) return false;
@@ -5163,7 +5494,7 @@ var wodNoteListTool = defineAgentTool({
5163
5494
  };
5164
5495
  }
5165
5496
  });
5166
- var noteGetInputSchema = zod.z.object({
5497
+ var noteGetInputSchema = zod.z.strictObject({
5167
5498
  noteId: zod.z.string().min(1).describe("Unique Note ID (UUID or seed route ID).")
5168
5499
  });
5169
5500
  var wodNoteGetTool = defineAgentTool({
@@ -5239,7 +5570,7 @@ var wodNoteGetTool = defineAgentTool({
5239
5570
  };
5240
5571
  }
5241
5572
  });
5242
- var noteUpsertInputSchema = zod.z.object({
5573
+ var noteUpsertInputSchema = zod.z.strictObject({
5243
5574
  noteId: zod.z.string().optional().describe("Existing Note ID to update, or omit to create a new Note."),
5244
5575
  title: zod.z.string().optional().describe("Note title (defaults to # H1 heading in content)."),
5245
5576
  content: zod.z.string().min(1).describe("Full Markdown document or Whiteboard Script body."),
@@ -5299,7 +5630,7 @@ var wodNoteUpsertTool = defineAgentTool({
5299
5630
  };
5300
5631
  }
5301
5632
  });
5302
- var noteCloneInputSchema = zod.z.object({
5633
+ var noteCloneInputSchema = zod.z.strictObject({
5303
5634
  sourceNoteId: zod.z.string().min(1).describe("Source Note ID (including read-only Seed/Feed Notes) to clone."),
5304
5635
  targetNotebookId: zod.z.string().optional().describe('Target writable user Notebook ID/slug (defaults to "notebook/journal").'),
5305
5636
  title: zod.z.string().optional().describe("Optional title override for the cloned Note."),
@@ -5366,7 +5697,7 @@ var wodNoteCloneTool = defineAgentTool({
5366
5697
  };
5367
5698
  }
5368
5699
  });
5369
- var noteDeleteInputSchema = zod.z.object({
5700
+ var noteDeleteInputSchema = zod.z.strictObject({
5370
5701
  noteId: zod.z.string().min(1).describe("ID of the Note to delete."),
5371
5702
  confirmId: zod.z.string().optional().describe("For non-interactive MCP/CLI calls, repeat the exact noteId to confirm deletion.")
5372
5703
  });
@@ -5483,7 +5814,7 @@ function collectCollectibles(node, out = []) {
5483
5814
  }
5484
5815
  return out;
5485
5816
  }
5486
- var parseScriptInputSchema = zod.z.object({
5817
+ var parseScriptInputSchema = zod.z.strictObject({
5487
5818
  source: zod.z.string().min(1).describe("Whiteboard Script body OR full Markdown document containing ```time / ```wod blocks."),
5488
5819
  sport: zod.z.string().optional().describe('Optional sport fence dialect override (e.g. "crossfit", "climbing", "running").'),
5489
5820
  save: zod.z.boolean().optional().describe("Default false (dry-run syntax & metric inspection). Set true to persist as a Note."),
@@ -5597,7 +5928,7 @@ function applyCollectibleOverrides(body, overrides) {
5597
5928
  }
5598
5929
  return updated;
5599
5930
  }
5600
- var sessionRunHeadlessInputSchema = zod.z.object({
5931
+ var sessionRunHeadlessInputSchema = zod.z.strictObject({
5601
5932
  noteId: zod.z.string().optional().describe("Existing Note ID to execute (read-only Seed/Feed Notes are automatically cloned to notebook/journal)."),
5602
5933
  blockId: zod.z.string().optional().describe("Optional workout block ID on `noteId` (defaults to first wod block)."),
5603
5934
  source: zod.z.string().optional().describe("Inline Whiteboard Script or Markdown to persist & run when `noteId` is not supplied."),
@@ -5751,7 +6082,7 @@ var wodSessionRunHeadlessTool = defineAgentTool({
5751
6082
  };
5752
6083
  }
5753
6084
  });
5754
- var sessionListInputSchema = zod.z.object({
6085
+ var sessionListInputSchema = zod.z.strictObject({
5755
6086
  noteId: zod.z.string().optional().describe("Filter Sessions by owning Note ID."),
5756
6087
  completedOnly: zod.z.boolean().optional().describe("Filter to completed Sessions only."),
5757
6088
  limit: zod.z.number().int().min(1).max(200).optional().describe("Max Sessions to return (default 50).")
@@ -5813,7 +6144,7 @@ var wodSessionListTool = defineAgentTool({
5813
6144
  };
5814
6145
  }
5815
6146
  });
5816
- var sessionGetInputSchema = zod.z.object({
6147
+ var sessionGetInputSchema = zod.z.strictObject({
5817
6148
  sessionId: zod.z.string().min(1).describe("Session ID to inspect.")
5818
6149
  });
5819
6150
  var wodSessionGetTool = defineAgentTool({
@@ -5852,7 +6183,7 @@ var wodSessionGetTool = defineAgentTool({
5852
6183
  };
5853
6184
  }
5854
6185
  });
5855
- var sessionDeleteInputSchema = zod.z.object({
6186
+ var sessionDeleteInputSchema = zod.z.strictObject({
5856
6187
  sessionId: zod.z.string().min(1).describe("Session ID to delete."),
5857
6188
  confirmId: zod.z.string().optional().describe("For non-interactive MCP/CLI calls, repeat the exact sessionId to confirm deletion.")
5858
6189
  });
@@ -5898,7 +6229,7 @@ var SESSION_AGENT_TOOLS = [
5898
6229
  wodSessionGetTool,
5899
6230
  wodSessionDeleteTool
5900
6231
  ];
5901
- var validateWqlInputSchema = zod.z.object({
6232
+ var validateWqlInputSchema = zod.z.strictObject({
5902
6233
  query: zod.z.string().describe('WQL query string to validate and inspect (e.g. ":note{notebook:journal} last 7d" or "sum:volume by {effort}").'),
5903
6234
  targetHint: zod.z.string().optional().describe("Optional target plane to list valid filter keys & grouping dimensions for (note, session, effort, equipment, tag, feed, block, event).")
5904
6235
  });
@@ -5937,7 +6268,7 @@ var wodValidateWqlTool = defineAgentTool({
5937
6268
  };
5938
6269
  }
5939
6270
  });
5940
- var queryWqlInputSchema = zod.z.object({
6271
+ var queryWqlInputSchema = zod.z.strictObject({
5941
6272
  query: zod.z.string().min(1).describe('WQL query expression (e.g. ":note{notebook:journal}", ":session last 30d", "sum:volume by {week}").'),
5942
6273
  preferredUnit: zod.z.string().optional().describe('Optional display unit conversion preference (e.g. "lb", "kg", "m", "mi").'),
5943
6274
  limit: zod.z.number().int().min(1).max(500).optional().describe("Maximum rows/items to return in the response payload (default 100).")
@@ -6323,6 +6654,7 @@ function zodSchemaToJsonSchema(schema) {
6323
6654
  return zod.z.toJSONSchema(schema, { target: "draft-2020-12" });
6324
6655
  }
6325
6656
  function exportAgentCapabilitiesManifest(options) {
6657
+ const isStatic = options?.deploymentTarget === "static";
6326
6658
  return {
6327
6659
  schemaVersion: "1.0.0",
6328
6660
  name: "WOD Wiki Agent Surface",
@@ -6333,7 +6665,12 @@ function exportAgentCapabilitiesManifest(options) {
6333
6665
  globalNamespace: "navigator.modelContext",
6334
6666
  library: "@mcp-b/react-webmcp"
6335
6667
  },
6336
- mcp: {
6668
+ mcp: isStatic ? {
6669
+ httpEndpoint: null,
6670
+ stdioCommand: "wod mcp",
6671
+ sdk: "@modelcontextprotocol/sdk",
6672
+ deploymentNote: "HTTP /api/mcp is only mounted on self-hosted `wod server` deployments, not on static hosting."
6673
+ } : {
6337
6674
  httpEndpoint: "/api/mcp",
6338
6675
  stdioCommand: "wod mcp",
6339
6676
  sdk: "@modelcontextprotocol/sdk"