@wirecat/cli-core 0.615.0 → 0.617.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/background/report/messages.d.ts +108 -0
  3. package/dist/background/report/messages.js +230 -0
  4. package/dist/background/report/render.d.ts +26 -4
  5. package/dist/background/report/render.js +56 -7
  6. package/dist/background/report/schema.d.ts +7 -1
  7. package/dist/background/report/schema.js +9 -3
  8. package/dist/background/report/stored-templates.d.ts +21 -19
  9. package/dist/background/report/stored-templates.js +20 -15
  10. package/dist/background/report/templates/morning-digest.email.en.liquid +3 -0
  11. package/dist/background/report/templates/morning-digest.email.ru.liquid +3 -0
  12. package/dist/background/report/templates/morning-digest.sample.json +8 -1
  13. package/dist/background/report/templates/morning-digest.telegram.en.liquid +3 -0
  14. package/dist/background/report/templates/morning-digest.telegram.ru.liquid +3 -0
  15. package/dist/background/report/templates/morning-digest.text.en.liquid +3 -0
  16. package/dist/background/report/templates/morning-digest.text.ru.liquid +3 -0
  17. package/dist/background/report/templates/schedule-failed.email.en.liquid +12 -0
  18. package/dist/background/report/templates/schedule-failed.email.ru.liquid +12 -0
  19. package/dist/background/report/templates/schedule-failed.sample.json +10 -0
  20. package/dist/background/report/templates/schedule-failed.telegram.en.liquid +9 -0
  21. package/dist/background/report/templates/schedule-failed.telegram.ru.liquid +9 -0
  22. package/dist/background/report/templates/schedule-failed.text.en.liquid +9 -0
  23. package/dist/background/report/templates/schedule-failed.text.ru.liquid +9 -0
  24. package/dist/background/report/templates/weekly-gaps.email.en.liquid +19 -0
  25. package/dist/background/report/templates/weekly-gaps.email.ru.liquid +19 -0
  26. package/dist/background/report/templates/weekly-gaps.sample.json +33 -0
  27. package/dist/background/report/templates/weekly-gaps.telegram.en.liquid +15 -0
  28. package/dist/background/report/templates/weekly-gaps.telegram.ru.liquid +15 -0
  29. package/dist/background/report/templates/weekly-gaps.text.en.liquid +14 -0
  30. package/dist/background/report/templates/weekly-gaps.text.ru.liquid +14 -0
  31. package/dist/background/report/view.d.ts +5 -0
  32. package/dist/background/report/view.js +9 -1
  33. package/dist/background/schedules.d.ts +10 -1
  34. package/dist/background/schedules.js +127 -30
  35. package/dist/cli/help/sections.js +1 -0
  36. package/dist/cli/schedule/schedule-command.js +3 -2
  37. package/dist/cli/templates-command.js +43 -20
  38. package/dist/domain/links.d.ts +1 -1
  39. package/dist/domain/links.js +1 -1
  40. package/dist/domain/models.d.ts +6 -0
  41. package/dist/entities/fact.d.ts +4 -0
  42. package/dist/entities/fact.js +2 -1
  43. package/dist/entities/fields.d.ts +5 -0
  44. package/dist/entities/fields.js +3 -0
  45. package/dist/entities/index.d.ts +21 -1
  46. package/dist/entities/index.js +3 -1
  47. package/dist/entities/list-results.d.ts +4 -2
  48. package/dist/entities/list-results.js +4 -2
  49. package/dist/entities/memory.d.ts +4 -0
  50. package/dist/entities/memory.js +2 -1
  51. package/dist/entities/template.d.ts +11 -0
  52. package/dist/entities/template.js +12 -0
  53. package/dist/errors/reasons.js +6 -0
  54. package/dist/meetings/mcp/index.d.ts +15 -15
  55. package/dist/store/exports.d.ts +1 -0
  56. package/dist/store/exports.js +1 -0
  57. package/dist/store/index.d.ts +3 -2
  58. package/dist/store/index.js +1 -0
  59. package/dist/store/people.d.ts +7 -0
  60. package/dist/store/people.js +4 -0
  61. package/dist/store/source-review.d.ts +21 -0
  62. package/dist/store/sqlite/accounts.d.ts +3 -1
  63. package/dist/store/sqlite/accounts.js +10 -3
  64. package/dist/store/sqlite/added-sources.d.ts +16 -0
  65. package/dist/store/sqlite/added-sources.js +22 -0
  66. package/dist/store/sqlite/bot-tokens.d.ts +11 -0
  67. package/dist/store/sqlite/bot-tokens.js +57 -0
  68. package/dist/store/sqlite/chats.js +2 -0
  69. package/dist/store/sqlite/facts.js +3 -2
  70. package/dist/store/sqlite/imported-documents.js +3 -2
  71. package/dist/store/sqlite/knowledge.js +6 -4
  72. package/dist/store/sqlite/memories.js +5 -4
  73. package/dist/store/sqlite/mention-drain.js +9 -1
  74. package/dist/store/sqlite/merged-persons.d.ts +24 -0
  75. package/dist/store/sqlite/merged-persons.js +59 -0
  76. package/dist/store/sqlite/messages.d.ts +1 -1
  77. package/dist/store/sqlite/messages.js +3 -1
  78. package/dist/store/sqlite/notes.js +5 -4
  79. package/dist/store/sqlite/open-store.js +2 -0
  80. package/dist/store/sqlite/person-links.d.ts +10 -1
  81. package/dist/store/sqlite/person-links.js +14 -6
  82. package/dist/store/sqlite/person-merges.d.ts +39 -0
  83. package/dist/store/sqlite/person-merges.js +136 -0
  84. package/dist/store/sqlite/person-preparation.js +11 -8
  85. package/dist/store/sqlite/person-resolution.js +2 -1
  86. package/dist/store/sqlite/person-scope.js +2 -1
  87. package/dist/store/sqlite/relation-list.js +3 -2
  88. package/dist/store/sqlite/reported-relations.js +6 -3
  89. package/dist/store/sqlite/source-review.d.ts +20 -1
  90. package/dist/store/sqlite/source-review.js +74 -3
  91. package/dist/store/sqlite/task-board.d.ts +6 -1
  92. package/dist/store/sqlite/task-board.js +22 -4
  93. package/dist/store/sqlite/work-tasks.js +8 -9
  94. package/dist/store/types.d.ts +2 -0
  95. package/package.json +2 -2
  96. package/parity.json +19 -0
@@ -1,15 +1,17 @@
1
1
  import { spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
2
3
  import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
4
  import { basename, join } from "node:path";
4
5
  import { CliError, errorCodes, writeSecurely } from "@wirecat/cli-base";
5
- import { linkConfigOf } from "../domain/links.js";
6
+ import { linkConfigOf, linkFor } from "../domain/links.js";
6
7
  import { mailHolderVariable, readOnlyLockOf } from "../ports/app.js";
7
8
  import { recordLogFor } from "../runs/record-log.js";
8
9
  import { childTrace } from "../runs/scope.js";
9
10
  import { storePath } from "../store/path.js";
10
11
  import { readSharedSection, sharedConfigPath } from "../store/shared-config.js";
11
12
  import { deliver } from "./deliver.js";
12
- import { prepareReport } from "./report/render.js";
13
+ import { causeOf, gapsView, noticeView, weeklyGapsOf } from "./report/messages.js";
14
+ import { prepareMessage, prepareReport, } from "./report/render.js";
13
15
  export const NOTIFY_WHEN = ["always", "failures", "never"];
14
16
  /** A repeating agent would otherwise notify on every tick; any other schedule runs rarely enough to say each result. */
15
17
  export const notifyOf = (schedule) => schedule.notify ?? (schedule.kind === "agent" && "every" in schedule.when ? "failures" : "always");
@@ -67,6 +69,7 @@ export const SKIP_REASONS = {
67
69
  costDayCap: "cost.day-cap",
68
70
  mailNone: "mail.none-new",
69
71
  mailBelowThreshold: "mail.below-threshold",
72
+ mailSameInput: "mail.same-input",
70
73
  };
71
74
  const REASON_ID = /^[a-z0-9][a-z0-9.-]{0,79}$/;
72
75
  /**
@@ -354,6 +357,23 @@ const sharedLinks = (env) => {
354
357
  return linkConfigOf(undefined);
355
358
  }
356
359
  };
360
+ /**
361
+ * WireCat Desktop, while it runs, writes `<state>/schedules/desktop.json` with its pid and the schedules whose new
362
+ * runs it announces itself; a marker whose pid is gone (a crash) announces nothing.
363
+ */
364
+ const announcedByDesktop = (schedulesFolder, name) => {
365
+ try {
366
+ const { pid, announces } = JSON.parse(readFileSync(join(schedulesFolder, "desktop.json"), "utf8"));
367
+ if (!Number.isInteger(pid) || !Array.isArray(announces) || !announces.includes(name))
368
+ return false;
369
+ process.kill(pid, 0);
370
+ return true;
371
+ }
372
+ catch (error) {
373
+ // EPERM: the process is there, under another user.
374
+ return error.code === "EPERM";
375
+ }
376
+ };
357
377
  /** A desktop notification; a machine without one loses only the notice, never the run. */
358
378
  export const notify = async (system, env, title, body) => {
359
379
  const argv = system.platform === "linux"
@@ -443,7 +463,7 @@ const pause = (ms, signal) => new Promise((resolve) => {
443
463
  * keyring, so a run that fails for that reason is tried again, a minute then up to 15 minutes apart, for up to
444
464
  * 12 hours. A schedule that repeats every few minutes is left to its next tick; a run by hand fails at once.
445
465
  */
446
- export const runSchedule = async (app, system, env, file, { now = () => new Date(), timer, signal, killAfterMs = KILL_AFTER_MS, untilUnlocked = false, wait = pause, agentRuns = [], agentInput, ownerLanguage = async () => "ru", reportTemplates, } = {}) => {
466
+ export const runSchedule = async (app, system, env, file, { now = () => new Date(), timer, signal, killAfterMs = KILL_AFTER_MS, untilUnlocked = false, wait = pause, agentRuns = [], agentInput, ownerLanguage = async () => "ru", reportTemplates, skipRepeatedInput = false, } = {}) => {
447
467
  const schedule = readSchedule(file);
448
468
  const folder = join(file, "..");
449
469
  const runs = join(folder, "runs");
@@ -451,24 +471,33 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
451
471
  const agent = schedule.kind === "agent";
452
472
  const retries = untilUnlocked && !("every" in schedule.when);
453
473
  const firstAt = now().getTime();
454
- let last = await attemptSchedule(app, system, env, schedule, folder, {
474
+ const first = await attemptSchedule(app, system, env, schedule, folder, {
455
475
  now,
456
476
  signal,
457
477
  killAfterMs,
458
478
  agentRuns,
459
479
  agentInput,
480
+ skipRepeatedInput,
460
481
  });
482
+ if ("repeated" in first) {
483
+ recordSkip(file, "the input is the same as the last run's, which moved no mark; it runs again once new mail comes", SKIP_REASONS.mailSameInput, now());
484
+ return lastRun(file) ?? first.repeated;
485
+ }
486
+ let last = first;
461
487
  for (let delay = LOCKED_FIRST_WAIT_MS; retries && lockedOut(last) && !signal?.aborted && now().getTime() - firstAt + delay <= LOCKED_GIVE_UP_MS; delay = Math.min(delay * 2, LOCKED_LONGEST_WAIT_MS)) {
462
488
  await wait(delay, signal);
463
489
  if (signal?.aborted)
464
490
  break;
465
- last = await attemptSchedule(app, system, env, schedule, folder, {
491
+ const again = await attemptSchedule(app, system, env, schedule, folder, {
466
492
  now,
467
493
  signal,
468
494
  killAfterMs,
469
495
  agentRuns,
470
496
  agentInput,
471
497
  });
498
+ if ("repeated" in again)
499
+ break;
500
+ last = again;
472
501
  }
473
502
  const { exitCode, output } = last;
474
503
  const errors = agent ? output.replace(/\.md$/, ".log") : output;
@@ -500,43 +529,65 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
500
529
  rmSync(join(runs, file), { force: true });
501
530
  const title = `${app.command} ${schedule.name}`;
502
531
  const mode = notifyOf(schedule);
503
- if (prepared && mode === "always") {
504
- await notify(system, env, title, `${prepared.notice.slice(0, 180)}\n${latestText}`);
505
- }
506
- else if (agent && exitCode === 0 && mode === "always") {
507
- const first = readFileSync(output, "utf8")
508
- .split("\n")
509
- .find((line) => line.trim()) ?? "report ready";
510
- await notify(system, env, title, `${first.trim().slice(0, 180)}\n${join(folder, "latest.md")}`);
532
+ if (agent && exitCode === 0) {
533
+ if (mode === "always" && !announcedByDesktop(join(folder, ".."), schedule.name)) {
534
+ const first = readFileSync(output, "utf8")
535
+ .split("\n")
536
+ .find((line) => line.trim()) ?? "report ready";
537
+ await notify(system, env, title, prepared
538
+ ? `${prepared.notice.slice(0, 180)}\n${latestText}`
539
+ : `${first.trim().slice(0, 180)}\n${join(folder, "latest.md")}`);
540
+ }
511
541
  }
512
542
  else if (exitCode !== 0 && mode !== "never") {
513
543
  await notify(system, env, title, `failed (exit ${exitCode}) — ${errors}`);
514
544
  }
515
545
  const routes = schedule.to ?? [];
516
- if (routes.length > 0 && (exitCode === 0 ? mode === "always" : mode !== "never")) {
517
- const at = shortTime(last.at);
518
- const locked = readOnlyLockOf(app, runEnv);
519
- const deliveries = await deliver(system, runEnv, routes, exitCode === 0
520
- ? {
521
- title: `${title} · ${at}`,
522
- file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${agent ? "md" : "txt"}` },
523
- ...(prepared ? { rendered: prepared } : {}),
524
- }
525
- : {
526
- title: `${title} failed · ${at}`,
527
- line: `${title} failed at ${at} (exit ${exitCode}` +
528
- `${last.failures && last.failures > 1 ? `, ${last.failures} runs in a row` : ""})` +
529
- `${last.reason ? `: ${last.reason}` : ""} — ${errors}`,
530
- }, {
546
+ const locked = readOnlyLockOf(app, runEnv);
547
+ const sendAlong = async (parcel) => {
548
+ const deliveries = await deliver(system, runEnv, routes, parcel, {
531
549
  find: (name, on) => findProgram(name, on, system.platform),
532
550
  errorOf: reasonOf,
533
551
  ...(locked ? { locked } : {}),
534
552
  });
535
- last = rewriteRun(join(folder, "last.json"), { ...last, deliveries });
536
553
  const lost = deliveries.filter((one) => !one.ok);
537
554
  if (lost.length > 0 && mode !== "never") {
538
555
  await notify(system, env, title, lost.map((one) => `not delivered to ${one.to}: ${one.reason}`).join("\n"));
539
556
  }
557
+ return deliveries;
558
+ };
559
+ const messageOptions = async () => ({
560
+ language: await ownerLanguage(runEnv).catch(() => "ru"),
561
+ linkOf: (ref) => linkFor(ref, { form: "web", config: sharedLinks(runEnv), env: runEnv }),
562
+ ...(reportTemplates ? { templates: reportTemplates(runEnv) } : {}),
563
+ });
564
+ if (routes.length > 0 && (exitCode === 0 ? mode === "always" : mode !== "never")) {
565
+ const at = shortTime(last.at);
566
+ const notice = exitCode === 0 ? undefined : await failureNotice(app, schedule, last, now(), await messageOptions());
567
+ const deliveries = await sendAlong(exitCode === 0
568
+ ? {
569
+ title: `${title} · ${at}`,
570
+ file: { path: output, name: `${schedule.name}-${at.replace(/[ :]/g, "-")}.${agent ? "md" : "txt"}` },
571
+ ...(prepared ? { rendered: prepared } : {}),
572
+ }
573
+ : notice
574
+ ? { title: notice.subject, rendered: notice }
575
+ : {
576
+ title: `${title} failed · ${at}`,
577
+ line: `${title} failed at ${at} (exit ${exitCode}` +
578
+ `${last.failures && last.failures > 1 ? `, ${last.failures} runs in a row` : ""})` +
579
+ `${last.reason ? `: ${last.reason}` : ""} — ${errors}`,
580
+ });
581
+ last = rewriteRun(join(folder, "last.json"), { ...last, deliveries });
582
+ }
583
+ if (routes.length > 0 && mode === "always" && prepared && !prepared.invalid && gapsDue(folder, now())) {
584
+ const gaps = weeklyGapsOf(runs, now().getTime());
585
+ const options = await messageOptions();
586
+ const message = gaps.gaps.length === 0
587
+ ? undefined
588
+ : await prepareMessage("weekly-gaps", (language) => gapsView(gaps, { language, now: now().getTime(), linkOf: options.linkOf }), options).catch(() => undefined);
589
+ const deliveries = message ? await sendAlong({ title: message.subject, rendered: message }) : [];
590
+ writeSecurely(join(folder, WEEKLY_GAPS_FILE), `${JSON.stringify({ at: now().toISOString(), gaps: gaps.gaps.length, runs: gaps.runs, deliveries }, null, 2)}\n`, 0o600);
540
591
  }
541
592
  if ("once" in schedule.when) {
542
593
  await timer?.remove(schedule.name);
@@ -544,6 +595,44 @@ export const runSchedule = async (app, system, env, file, { now = () => new Date
544
595
  }
545
596
  return last;
546
597
  };
598
+ /**
599
+ * The rendered notice of a failed run: which schedule, since when, the cause, and one link to the tool's sync
600
+ * screen; undefined when even the shipped template fails, and the run's one line goes instead.
601
+ */
602
+ const failureNotice = async (app, schedule, last, at, options) => {
603
+ const failure = {
604
+ kind: "schedule-failed",
605
+ tool: app.command,
606
+ schedule: schedule.name,
607
+ at: last.at,
608
+ since: last.failingSince ?? last.at,
609
+ failures: last.failures ?? 1,
610
+ cause: lockedOut(last) ? "locked" : causeOf(last.errorCode, last.exitCode),
611
+ refs: [`sync:${app.command}`],
612
+ };
613
+ return prepareMessage("schedule-failed", (language) => noticeView(failure, { language, now: at.getTime(), linkOf: options.linkOf }), options).catch(() => undefined);
614
+ };
615
+ /** When the weekly gaps went last, how many, and along which routes. */
616
+ const WEEKLY_GAPS_FILE = "weekly-gaps.json";
617
+ /** Monday 00:00, local time, of the week `at` falls in. */
618
+ const weekStart = (at) => {
619
+ const day = new Date(at);
620
+ day.setHours(0, 0, 0, 0);
621
+ day.setDate(day.getDate() - ((day.getDay() + 6) % 7));
622
+ return day.getTime();
623
+ };
624
+ /**
625
+ * Whether this digest run also sends the week's gaps: on a Monday, or on the first run of a week whose Monday run
626
+ * did not send them. A schedule that never sent any waits for its first Monday, so it never sends one day's gaps.
627
+ */
628
+ const gapsDue = (folder, now) => {
629
+ let sent;
630
+ try {
631
+ sent = Date.parse(JSON.parse(readFileSync(join(folder, WEEKLY_GAPS_FILE), "utf8")).at);
632
+ }
633
+ catch { }
634
+ return sent === undefined || Number.isNaN(sent) ? now.getDay() === 1 : sent < weekStart(now);
635
+ };
547
636
  /** The agent's input, or none: a host read that fails leaves the agent to fetch what it needs itself. */
548
637
  const inputOf = async (agentInput, system, env, schedule, log) => {
549
638
  try {
@@ -561,7 +650,7 @@ const inputOf = async (agentInput, system, env, schedule, log) => {
561
650
  }
562
651
  };
563
652
  /** One run of the schedule's command or agent: its output in `runs/`, its result in `last.json`. */
564
- const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, }) => {
653
+ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal, killAfterMs, agentRuns, agentInput, skipRepeatedInput = false, }) => {
565
654
  const runs = join(folder, "runs");
566
655
  const stamp = now()
567
656
  .toISOString()
@@ -594,6 +683,13 @@ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal
594
683
  const began = now().getTime();
595
684
  log.info({ event: "schedule.start", ...facts });
596
685
  const input = agent && agentInput ? await inputOf(agentInput, system, childEnv, schedule, log) : undefined;
686
+ const inputHash = input === undefined || !schedule.onNewMail ? undefined : createHash("sha256").update(input).digest("hex");
687
+ const before = skipRepeatedInput && inputHash !== undefined ? readRun(join(folder, "last.json")) : undefined;
688
+ if (before?.exitCode === 0 && before.inputHash === inputHash) {
689
+ // A skip every few minutes would otherwise push the kept runs' files out of runs/.
690
+ rmSync(join(runs, `${stamp}.jsonl`), { force: true });
691
+ return { repeated: before };
692
+ }
597
693
  let costUsd;
598
694
  const exitCode = await new Promise((resolve) => {
599
695
  const child = spawn(program, args, { env: childEnv, cwd: folder, stdio: ["pipe", "pipe", "pipe"] });
@@ -646,6 +742,7 @@ const attemptSchedule = async (app, system, env, schedule, folder, { now, signal
646
742
  output,
647
743
  traceId: trace.traceId,
648
744
  ...(costUsd === undefined ? {} : { costUsd }),
745
+ ...(inputHash === undefined ? {} : { inputHash }),
649
746
  ...(exitCode === 0 ? {} : failureOf(readFileSync(errors, "utf8"), exitCode)),
650
747
  });
651
748
  };
@@ -57,6 +57,7 @@ const CORE_SECTIONS = {
57
57
  replies: "automate",
58
58
  runs: "automate",
59
59
  schedule: "automate",
60
+ templates: "automate",
60
61
  serve: "automate",
61
62
  server: "automate",
62
63
  account: "setup",
@@ -5,7 +5,7 @@ import { annotate } from "@wirecat/cli-base/commands";
5
5
  import { Argument, Command, Option } from "commander";
6
6
  import { parseRoute, ROUTE_HELP, routeText } from "../../background/deliver.js";
7
7
  import { REPORT_CHANNELS } from "../../background/report/render.js";
8
- import { reportKeyOf } from "../../background/report/stored-templates.js";
8
+ import { keyOfKind } from "../../background/report/stored-templates.js";
9
9
  import { describeWhen, findProgram, lastRun, listSchedules, NOTIFY_WHEN, notifyOf, readSchedule, recordSkip, runSchedule, SCHEDULE_DEFAULTS, SKIP_REASONS, scheduleFile, scheduleName, spentToday, timerFor, } from "../../background/schedules.js";
10
10
  import { thisMachine } from "../../background/system.js";
11
11
  import { locationVariables } from "../../background/units.js";
@@ -179,7 +179,7 @@ const reportTemplatesOf = (env) => async (kind, language) => {
179
179
  return {};
180
180
  const database = await openCache(path);
181
181
  try {
182
- const bodies = storedTemplateBodies(database, reportKeyOf(kind), language);
182
+ const bodies = storedTemplateBodies(database, keyOfKind(kind), language);
183
183
  return Object.fromEntries(REPORT_CHANNELS.flatMap((channel) => (channel in bodies ? [[channel, bodies[channel]]] : [])));
184
184
  }
185
185
  finally {
@@ -503,6 +503,7 @@ export const scheduleCommandFor = ({ app, context: contextOf, newMail, agentInpu
503
503
  reportTemplates: reportTemplatesOf,
504
504
  ...(agentInput ? { agentInput } : {}),
505
505
  untilUnlocked: true,
506
+ skipRepeatedInput: true,
506
507
  ...(signal ? { signal } : {}),
507
508
  }));
508
509
  if (last.exitCode !== 0)
@@ -4,13 +4,16 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { CliError, resolvePaths } from "@wirecat/cli-base";
6
6
  import { annotate } from "@wirecat/cli-base/commands";
7
+ import { queryFieldsOf } from "@wirecat/cli-base/query";
7
8
  import { Command, Option } from "commander";
8
9
  import { checkTemplate, defaultTemplate, REPORT_CHANNELS, renderReport, } from "../background/report/render.js";
9
10
  import { checkTemplateSave, previewView, shippedLanguages, TEMPLATE_KEYS, templateKeyOf, } from "../background/report/stored-templates.js";
11
+ import { template } from "../entities/index.js";
10
12
  import { agentOf } from "../runs/run-context.js";
11
13
  import { openStore } from "../store/store.js";
12
14
  import { grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "./effects.js";
13
15
  import { itemOf, listOf } from "./envelope.js";
16
+ import { queryTerms, withQuery } from "./list-query.js";
14
17
  import { ownerLanguageOf } from "./schedule/schedule-command.js";
15
18
  const withStore = async (env, work) => {
16
19
  const store = await openStore({ env });
@@ -35,17 +38,28 @@ const systemEditor = (path, env) => {
35
38
  const channelOption = () => new Option("--channel <channel>", "telegram (Bot API HTML), email (HTML with inline styles) or text")
36
39
  .choices(REPORT_CHANNELS)
37
40
  .makeOptionMandatory();
38
- const languageOption = () => new Option("--language <code>", "the template's language, ISO 639-1; the owner's first language if not given");
39
- /** The key, its report kind and the language, refused when nothing renders the key or cli-core ships no such language. */
41
+ const localeOption = () => new Option("--locale <code>", "the template's language, ISO 639-1; the owner's first language if not given");
42
+ const TEMPLATES_QUERY = {
43
+ entity: "template",
44
+ backend: "native",
45
+ fields: queryFieldsOf(template, {
46
+ native: ["key", "channel", "language", "source"],
47
+ exclude: ["about", "renders", "updated_at", "updated_by"],
48
+ examples: { key: 'key:"report/morning-digest"', channel: "channel:telegram", language: "language:en" },
49
+ }).map((field) => ({
50
+ ...field,
51
+ operators: field.operators.filter((operator) => operator === "term" || operator === "phrase"),
52
+ })),
53
+ };
54
+ const matching = (rows, terms) => rows.filter((row) => [...terms].every(([field, value]) => String(row[field]).toLowerCase() === value.toLowerCase()));
55
+ /** The key, its message kind and the language, refused when cli-core ships no template in that language. */
40
56
  const addressOf = async (key, given, env) => {
41
57
  const known = templateKeyOf(key);
42
58
  if (!known)
43
59
  throw new CliError("validation_error", `no template ${key}; the keys are ${TEMPLATE_KEYS.map((one) => one.key).join(", ")}`, {
44
60
  reason: "template.unknown-key",
45
61
  });
46
- if (known.kind === null)
47
- throw new CliError("validation_error", `nothing renders ${key} yet (${known.about}), so a template for it cannot be checked or saved`, { reason: "template.no-renderer" });
48
- const language = (given.language ?? (await ownerLanguageOf(env))).trim().toLowerCase();
62
+ const language = (given.locale ?? (await ownerLanguageOf(env))).trim().toLowerCase();
49
63
  const languages = shippedLanguages(known.kind);
50
64
  if (!languages.includes(language))
51
65
  throw new CliError("validation_error", `${key} has templates in ${languages.join(", ")}; a ${language} one would never be used`, { reason: "template.unknown-language" });
@@ -73,38 +87,44 @@ const historyOf = (store, address) => store.templates.history(address).map((entr
73
87
  */
74
88
  export const templatesCommand = (app, options) => {
75
89
  const editor = options.editor ?? systemEditor;
76
- const templates = annotate(new Command("templates"), { effects: LOCAL_READ }).description("the templates of the digest and the other messages sent to you, per channel and language; edit, preview, reset");
77
- annotate(templates.command("list"), {
90
+ const templates = annotate(new Command("templates"), { effects: LOCAL_READ })
91
+ .summary("the templates of the messages sent to you; edit, preview, reset")
92
+ .description("the templates of the digest and the other messages sent to you, per channel and language; edit, preview, reset");
93
+ withQuery(annotate(templates.command("list"), {
78
94
  effects: LOCAL_READ,
79
- examples: [`${app.command} templates list`],
80
- })
95
+ examples: [`${app.command} templates list`, `${app.command} templates list channel:telegram language:en`],
96
+ }), TEMPLATES_QUERY)
97
+ .summary("every template, and whether yours or the shipped one applies")
81
98
  .description("every template key, channel and language, and whether yours or the shipped one applies")
82
- .action(async function () {
99
+ .action(async function (words) {
100
+ const terms = queryTerms(words, TEMPLATES_QUERY, "templates list");
83
101
  const env = options.env();
84
102
  const stored = await withStore(env, (store) => store.templates.list());
85
- const items = TEMPLATE_KEYS.flatMap((known) => REPORT_CHANNELS.flatMap((channel) => (known.kind === null ? [null] : shippedLanguages(known.kind)).map((language) => {
103
+ const items = TEMPLATE_KEYS.flatMap((known) => REPORT_CHANNELS.flatMap((channel) => shippedLanguages(known.kind).map((language) => {
86
104
  const row = stored.find((one) => one.key === known.key && one.channel === channel && one.language === language);
87
105
  return {
88
106
  key: known.key,
89
107
  channel,
90
108
  language,
91
109
  about: known.about,
92
- renders: known.kind !== null,
93
- source: row ? "stored" : known.kind === null ? "none" : "default",
110
+ renders: true,
111
+ source: row ? "stored" : "default",
94
112
  updated_at: row ? new Date(row.updatedAt).toISOString() : null,
95
113
  updated_by: row?.updatedBy ?? null,
96
114
  };
97
115
  })));
98
- options.output(listOf("templates list", { items, limit: items.length, has_more: false }), this);
116
+ const found = matching(items, terms);
117
+ options.output(listOf("templates list", { items: found, limit: found.length, has_more: false }), this);
99
118
  });
100
119
  annotate(templates.command("show"), {
101
120
  effects: LOCAL_READ,
102
121
  examples: [`${app.command} templates show report/morning-digest --channel telegram`],
103
122
  })
123
+ .summary("the template that applies, and the bodies your changes replaced")
104
124
  .description("the template that applies, yours or the shipped one, and the bodies your changes replaced")
105
125
  .argument("<key>", "the template, such as report/morning-digest")
106
126
  .addOption(channelOption())
107
- .addOption(languageOption())
127
+ .addOption(localeOption())
108
128
  .action(async function (key, given) {
109
129
  const env = options.env();
110
130
  const { address, kind, channel } = await addressOf(key, given, env);
@@ -129,11 +149,12 @@ export const templatesCommand = (app, options) => {
129
149
  `${app.command} templates edit report/morning-digest --channel telegram --undo`,
130
150
  ],
131
151
  }))
152
+ .summary("change a template in $EDITOR or from --file; checked before it is saved")
132
153
  .description("change a template in $EDITOR or from --file; it is checked first, and a failed check saves nothing and says why")
133
154
  .argument("<key>", "the template, such as report/morning-digest")
134
155
  .addOption(channelOption())
135
- .addOption(languageOption())
136
- .option("--file <path>", "take the new template from this file instead of opening an editor")
156
+ .addOption(localeOption())
157
+ .option("--file <file>", "take the new template from this file instead of opening an editor")
137
158
  .addOption(new Option("--undo", "put back the body your last change replaced; twice is back where you were").conflicts("file"))
138
159
  .action(async function (key, given) {
139
160
  const env = options.env();
@@ -199,11 +220,12 @@ export const templatesCommand = (app, options) => {
199
220
  `${app.command} templates preview report/morning-digest --channel email --file draft.liquid`,
200
221
  ],
201
222
  })
223
+ .summary("what would be sent on that channel; saves nothing")
202
224
  .description("what would be sent on that channel, from the last real report or a synthetic one when there is none; saves nothing")
203
225
  .argument("<key>", "the template, such as report/morning-digest")
204
226
  .addOption(channelOption())
205
- .addOption(languageOption())
206
- .option("--file <path>", "preview this draft instead of the template that applies")
227
+ .addOption(localeOption())
228
+ .option("--file <file>", "preview this draft instead of the template that applies")
207
229
  .action(async function (key, given) {
208
230
  const env = options.env();
209
231
  const { address, kind, channel } = await addressOf(key, given, env);
@@ -225,10 +247,11 @@ export const templatesCommand = (app, options) => {
225
247
  effects: LOCAL_WRITE,
226
248
  examples: [`${app.command} templates reset report/morning-digest --channel telegram`],
227
249
  }))
250
+ .summary("go back to the shipped template; edit --undo brings yours back")
228
251
  .description("go back to the shipped template; yours is kept in the history, and edit --undo brings it back")
229
252
  .argument("<key>", "the template, such as report/morning-digest")
230
253
  .addOption(channelOption())
231
- .addOption(languageOption())
254
+ .addOption(localeOption())
232
255
  .action(async function (key, given) {
233
256
  const env = options.env();
234
257
  refuseAgent(env);
@@ -18,7 +18,7 @@ export type DeepLinkTarget = {
18
18
  id: string;
19
19
  } | {
20
20
  type: "tasks";
21
- filter: "overdue" | "today" | "tomorrow";
21
+ filter: "overdue" | "today" | "tomorrow" | "undated";
22
22
  } | {
23
23
  type: "tasks";
24
24
  filter: "new";
@@ -4,7 +4,7 @@ export const DEFAULT_LINK_CONFIG = { base: "https://wirecat.dev/o", enabled: tru
4
4
  const APP_PREFIX = "wirecat://open";
5
5
  const MAX_PATH = 512;
6
6
  const MAX_SEGMENTS = 6;
7
- const TASK_FILTERS = ["overdue", "today", "tomorrow"];
7
+ const TASK_FILTERS = ["overdue", "today", "tomorrow", "undated"];
8
8
  const DATE = /^\d{4}-\d{2}-\d{2}$/;
9
9
  const DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/;
10
10
  const isMoment = (text, pattern) => pattern.test(text) && !Number.isNaN(Date.parse(text));
@@ -22,6 +22,12 @@ export interface Chat {
22
22
  /** Saving a chat: absent keeps the stored parent, `null` clears it. */
23
23
  parentChatId?: Id | null;
24
24
  scope?: "personal" | "work";
25
+ /**
26
+ * Saving a chat: `false` keeps it out of search over all chats, as a chat whose messages hold credentials
27
+ * (Telegram's BotFather) should be; a read that names the chat still sees it. Absent keeps the stored
28
+ * mark, and nothing a messenger saves unhides a chat.
29
+ */
30
+ searchable?: false;
25
31
  id: Id;
26
32
  title: string | null;
27
33
  kind: ChatKind;
@@ -40,6 +40,10 @@ export declare const fact: v.StrictObjectSchema<{
40
40
  readonly tool: v.NullableSchema<v.StringSchema<undefined>, undefined>;
41
41
  readonly missing: v.BooleanSchema<undefined>;
42
42
  }, undefined>, undefined>, undefined>;
43
+ readonly source_review: v.OptionalSchema<v.NullableSchema<v.StrictObjectSchema<{
44
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
45
+ readonly cause: v.PicklistSchema<readonly ["changed", "outdated", "deleted", "contradicted"], undefined>;
46
+ }, undefined>, undefined>, undefined>;
43
47
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
44
48
  readonly updated_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
45
49
  }, undefined>;
@@ -1,6 +1,6 @@
1
1
  import * as v from "valibot";
2
2
  import { FACT_STATUSES, FACT_TYPES, MEMORY_SCOPES } from "../domain/knowledge.js";
3
- import { author, evidenceSource, id, reference, text, time } from "./fields.js";
3
+ import { author, evidenceSource, id, reference, sourceReview, text, time } from "./fields.js";
4
4
  export const fact = v.strictObject({
5
5
  ref: reference,
6
6
  id,
@@ -26,6 +26,7 @@ export const fact = v.strictObject({
26
26
  evidence: v.array(reference),
27
27
  /** With `--sources`: each piece of evidence read back. */
28
28
  sources: v.optional(v.array(evidenceSource)),
29
+ source_review: v.optional(sourceReview),
29
30
  created_at: time,
30
31
  updated_at: time,
31
32
  });
@@ -21,6 +21,11 @@ export declare const evidenceSource: v.StrictObjectSchema<{
21
21
  readonly tool: v.NullableSchema<v.StringSchema<undefined>, undefined>;
22
22
  readonly missing: v.BooleanSchema<undefined>;
23
23
  }, undefined>;
24
+ /** The open review of a memory's or fact's sources, when one waits for the owner (`memory_source_review`). */
25
+ export declare const sourceReview: v.NullableSchema<v.StrictObjectSchema<{
26
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
27
+ readonly cause: v.PicklistSchema<readonly ["changed", "outdated", "deleted", "contradicted"], undefined>;
28
+ }, undefined>, undefined>;
24
29
  export declare const author: v.StrictObjectSchema<{
25
30
  readonly type: v.PicklistSchema<["person", "bot"], undefined>;
26
31
  readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
@@ -1,5 +1,6 @@
1
1
  import { isoTime, reference } from "@wirecat/cli-base/standards";
2
2
  import * as v from "valibot";
3
+ import { SOURCE_REVIEW_CAUSES } from "../store/source-review.js";
3
4
  export { reference };
4
5
  export const text = v.string();
5
6
  export const id = v.pipe(v.string(), v.minLength(1));
@@ -21,6 +22,8 @@ export const evidenceSource = v.strictObject({
21
22
  tool: v.nullable(text),
22
23
  missing: v.boolean(),
23
24
  });
25
+ /** The open review of a memory's or fact's sources, when one waits for the owner (`memory_source_review`). */
26
+ export const sourceReview = v.nullable(v.strictObject({ id, cause: v.picklist(SOURCE_REVIEW_CAUSES) }));
24
27
  export const author = v.strictObject({
25
28
  type: v.picklist(["person", "bot"]),
26
29
  id,
@@ -84,13 +84,14 @@ import { tagging } from "./tagging.js";
84
84
  import { task } from "./task.js";
85
85
  import { taskPair } from "./task-pair.js";
86
86
  import { taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskScan, taskSimilar, taskUnmerge } from "./task-results.js";
87
+ import { template } from "./template.js";
87
88
  import { topic } from "./topic.js";
88
89
  /**
89
90
  * One schema per thing a command can answer with. A command returns an entity or one of its views — a
90
91
  * subset of its fields, never a renamed one. Commands move onto these one by one; until then, a schema
91
92
  * is the target, not a description of today's output.
92
93
  */
93
- export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
94
+ export { account, accountChange, accountPrivacy, accountPrivacyChange, accountProfile, accountSession, adminReport, agenda, analysisConsent, analysisConsentRevocation, attachment, attachmentBytes, attachmentExtraction, attachmentTextChange, automaticTags, botAdmin, botMenuEntry, botProfile, botSeenChat, botTemplate, botWebhook, cachedChatMetadata, callRecord, chart, chat, chatAdminChange, chatArchive, chatCoverage, chatEvent, chatFolderChange, chatFolderOrder, chatFolderRemoval, chatGroupChange, chatInspection, chatInvite, chatInviteChange, chatMembersChange, chatMembersFetch, chatMetadata, chatMetadataRefresh, chatModeration, chatMuting, chatPin, chatRead, chatRemoval, chatRequestChange, chatRules, chatSender, chatStats, chatTracking, chatUnread, contact, contactActivity, contactAlias, contactCheck, contactContext, contactImport, contactLookup, contactNote, contactNoteRemoval, contactPreparation, contactStateChange, contactSync, contactUpdate, conversation, conversationBatch, conversationBatchStatus, conversationBuildResult, conversationChange, conversationDetails, conversationEmbedding, conversationEmbeddingStatus, conversationHit, conversationPreparation, conversationReadiness, counterRefresh, counters, document, documentLink, endedAccountSessions, evidence, evidencePacket, fact, folder, hit, identity, imageEmbedding, inviteLink, job, joinRequest, linkedPerson, mailCounts, mediaArchive, mediaArchiveCheck, mediaArchiveMove, mediaArchiveTimer, meeting, meetingProjectCandidates, meetingSeriesInventory, member, memory, mention, mentionDecision, mentionDetails, mentionDomain, mentionRebuild, message, messageContext, messageCounts, messageDeletion, messageDownload, messageEvent, messageLink, messageLinks, messagePin, messageStar, messageSync, messageTranscript, messageWrite, model, modelKey, note, officialStats, organization, person, place, poll, pollChange, pollVote, project, ranking, reaction, reactionChange, recipient, recipientAdded, recipientChange, recipientOff, recipientRemoved, recordedRun, reference, relationship, reminder, removedModelKey, responseTimes, retention, runDetails, runHit, runLocation, savedSearch, scheduledJob, searchHistoryClear, sendAttempt, serveSummary, stickerInventory, storeBackup, storeChatStatus, storeCheck, storeClear, storeCopyRemoval, storeDecrypt, storedModelKey, storeExport, storeGapPlan, storeGapRepair, storeInfo, storeJobCancel, storeJobClear, storeJobDetails, storeJobRetry, storeMigration, storeReindex, storeRepair, storeReset, storeRestore, storeTable, tagChange, tagging, task, taskAnalysis, taskAnalysisMark, taskCard, taskCategories, taskClosed, taskCreated, taskLinks, taskMerge, taskPair, taskScan, taskSimilar, taskStats, taskUnmerge, template, topic, topicIcon, trackedChat, trackedChatHistory, waitingChats, watchedMessage, watchItem, };
94
95
  export declare const ENTITIES: {
95
96
  readonly meeting_ingestion: v.StrictObjectSchema<{
96
97
  readonly meetings: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -4189,6 +4190,7 @@ export declare const ENTITIES: {
4189
4190
  readonly failing_since: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
4190
4191
  readonly failures: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
4191
4192
  readonly cost_usd: v.OptionalSchema<v.NumberSchema<undefined>, undefined>;
4193
+ readonly input_hash: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
4192
4194
  readonly skipped: v.OptionalSchema<v.StrictObjectSchema<{
4193
4195
  readonly at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
4194
4196
  readonly why: v.StringSchema<undefined>;
@@ -5291,6 +5293,10 @@ export declare const ENTITIES: {
5291
5293
  readonly tool: v.NullableSchema<v.StringSchema<undefined>, undefined>;
5292
5294
  readonly missing: v.BooleanSchema<undefined>;
5293
5295
  }, undefined>, undefined>, undefined>;
5296
+ readonly source_review: v.OptionalSchema<v.NullableSchema<v.StrictObjectSchema<{
5297
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
5298
+ readonly cause: v.PicklistSchema<readonly ["changed", "outdated", "deleted", "contradicted"], undefined>;
5299
+ }, undefined>, undefined>, undefined>;
5294
5300
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
5295
5301
  readonly updated_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
5296
5302
  }, undefined>;
@@ -5326,6 +5332,10 @@ export declare const ENTITIES: {
5326
5332
  readonly missing: v.BooleanSchema<undefined>;
5327
5333
  }, undefined>, undefined>, undefined>;
5328
5334
  readonly last_verified_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
5335
+ readonly source_review: v.OptionalSchema<v.NullableSchema<v.StrictObjectSchema<{
5336
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
5337
+ readonly cause: v.PicklistSchema<readonly ["changed", "outdated", "deleted", "contradicted"], undefined>;
5338
+ }, undefined>, undefined>, undefined>;
5329
5339
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
5330
5340
  readonly updated_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
5331
5341
  }, undefined>;
@@ -11897,6 +11907,16 @@ export declare const ENTITIES: {
11897
11907
  readonly mean_open_age_ms: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
11898
11908
  }, undefined>, undefined>;
11899
11909
  }, undefined>;
11910
+ readonly template: v.StrictObjectSchema<{
11911
+ readonly key: v.StringSchema<undefined>;
11912
+ readonly channel: v.PicklistSchema<["telegram", "email", "text"], undefined>;
11913
+ readonly language: v.StringSchema<undefined>;
11914
+ readonly about: v.StringSchema<undefined>;
11915
+ readonly renders: v.BooleanSchema<undefined>;
11916
+ readonly source: v.PicklistSchema<["stored", "default"], undefined>;
11917
+ readonly updated_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
11918
+ readonly updated_by: v.NullableSchema<v.StringSchema<undefined>, undefined>;
11919
+ }, undefined>;
11900
11920
  };
11901
11921
  export type EntityName = keyof typeof ENTITIES;
11902
11922
  /** Every entity as a JSON Schema 2020-12 `$defs` entry, for bundling into an MCP tool's `outputSchema`. */