@wirecat/cli-core 0.559.0 → 0.561.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 (89) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/dist/background/schedules.d.ts +2 -0
  3. package/dist/calendar/busy.d.ts +11 -0
  4. package/dist/calendar/busy.js +14 -1
  5. package/dist/calendar/cli/index.d.ts +9 -3
  6. package/dist/calendar/cli/index.js +14 -7
  7. package/dist/calendar/cli/local-times.d.ts +5 -0
  8. package/dist/calendar/cli/local-times.js +39 -0
  9. package/dist/calendar/mcp/index.js +1 -1
  10. package/dist/calendar/reads.d.ts +11 -2
  11. package/dist/calendar/reads.js +34 -18
  12. package/dist/calendar/writes.js +3 -44
  13. package/dist/cli/effects.d.ts +13 -2
  14. package/dist/cli/effects.js +23 -2
  15. package/dist/cli/index.d.ts +2 -2
  16. package/dist/cli/index.js +2 -2
  17. package/dist/cli/meeting-findings-input.d.ts +3 -0
  18. package/dist/cli/meeting-findings-input.js +4 -0
  19. package/dist/cli/messenger/conversation-answers.d.ts +3 -0
  20. package/dist/cli/messenger/message-answers.d.ts +3 -0
  21. package/dist/cli/messenger/message-writes.d.ts +6 -0
  22. package/dist/cli/schedule/schedule-command.d.ts +6 -1
  23. package/dist/cli/schedule/schedule-command.js +24 -2
  24. package/dist/entities/contact-context.d.ts +6 -0
  25. package/dist/entities/conversation-results.d.ts +6 -0
  26. package/dist/entities/evidence.d.ts +24 -0
  27. package/dist/entities/index.d.ts +190 -0
  28. package/dist/entities/index.js +3 -0
  29. package/dist/entities/listener.d.ts +12 -0
  30. package/dist/entities/mail-findings.d.ts +116 -0
  31. package/dist/entities/mail-findings.js +68 -0
  32. package/dist/entities/message-context.d.ts +9 -0
  33. package/dist/entities/message-write.d.ts +12 -0
  34. package/dist/entities/message.d.ts +6 -0
  35. package/dist/entities/message.js +6 -0
  36. package/dist/entities/store-records.d.ts +3 -0
  37. package/dist/errors/reasons.js +3 -0
  38. package/dist/mail/cli/marks.d.ts +1 -0
  39. package/dist/mail/cli/marks.js +11 -4
  40. package/dist/mail/cli/review.js +10 -2
  41. package/dist/mail/findings.d.ts +55 -0
  42. package/dist/mail/findings.js +140 -0
  43. package/dist/mail/index.d.ts +2 -1
  44. package/dist/mail/index.js +2 -1
  45. package/dist/mail/marks.d.ts +10 -3
  46. package/dist/mail/marks.js +34 -5
  47. package/dist/meetings/findings-rules.d.ts +24 -0
  48. package/dist/meetings/findings-rules.js +136 -116
  49. package/dist/meetings/index.d.ts +2 -1
  50. package/dist/meetings/index.js +2 -1
  51. package/dist/sends/index.d.ts +1 -0
  52. package/dist/sends/index.js +1 -0
  53. package/dist/sends/keyed-guard.d.ts +12 -0
  54. package/dist/sends/keyed-guard.js +49 -0
  55. package/dist/services/proposals/kinds/mail-findings.d.ts +8 -0
  56. package/dist/services/proposals/kinds/mail-findings.js +87 -0
  57. package/dist/services/proposals/registry.js +3 -1
  58. package/dist/services/proposals/types.d.ts +2 -0
  59. package/dist/store/decisions.d.ts +1 -1
  60. package/dist/store/decisions.js +1 -1
  61. package/dist/store/index.d.ts +1 -0
  62. package/dist/store/index.js +1 -0
  63. package/dist/store/mail-findings.d.ts +51 -0
  64. package/dist/store/mail-findings.js +1 -0
  65. package/dist/store/path.d.ts +2 -0
  66. package/dist/store/path.js +21 -1
  67. package/dist/store/sqlite/email-activity.d.ts +8 -0
  68. package/dist/store/sqlite/email-activity.js +31 -5
  69. package/dist/store/sqlite/findings-core.d.ts +1 -0
  70. package/dist/store/sqlite/findings-core.js +1 -1
  71. package/dist/store/sqlite/mail-findings.d.ts +3 -0
  72. package/dist/store/sqlite/mail-findings.js +333 -0
  73. package/dist/store/sqlite/manifest.js +1 -0
  74. package/dist/store/sqlite/memories.d.ts +4 -1
  75. package/dist/store/sqlite/memories.js +48 -43
  76. package/dist/store/sqlite/migrations.generated.js +6 -0
  77. package/dist/store/sqlite/open-store.d.ts +1 -1
  78. package/dist/store/sqlite/open-store.js +4 -1
  79. package/dist/store/sqlite/open.js +2 -1
  80. package/dist/store/sqlite/proposed-actions.js +2 -1
  81. package/dist/store/sqlite/tasks.d.ts +2 -0
  82. package/dist/store/sqlite/tasks.js +26 -24
  83. package/dist/store/sqlite/test-accounts.d.ts +8 -0
  84. package/dist/store/sqlite/test-accounts.js +31 -0
  85. package/dist/store/sqlite/work-tasks.d.ts +1 -0
  86. package/dist/store/sqlite/work-tasks.js +6 -0
  87. package/dist/store/store.d.ts +3 -0
  88. package/dist/store/store.js +5 -0
  89. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,80 @@ shape of this file.
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.561.0 — 03.11.2026
11
+
12
+ ### Changed — may break callers
13
+
14
+ - **`links review` under a profile lock lists only the profile's own link choices.** With `deps.locked`, or without
15
+ `deps.messages`, only choices about the account's own copies are listed, and a candidate event the account holds no
16
+ copy of shows its ref alone, so no other account's titles. Unlocked it still lists every account's and names them
17
+ in `meta.accounts` (WC-ACCT-9); the top-level `accounts: "all"` is gone. Over MCP, `event_links_review` lists only
18
+ the served accounts' choices. `reviewsAnswer(store, accountIds?)` takes the scope; `calendarAccountNames` names the
19
+ store's calendar accounts.
20
+
21
+ ### Added
22
+
23
+ - **`keyedGuard` in `@wirecat/cli-core/sends`:** the guard over a write's main key and its extra keys that the
24
+ calendar writes use — a key that refuses refuses before anything is asked, one question names every key at `ask`,
25
+ and `refuse(request)` checks without asking. A CLI's own API writes can now share it instead of a copy.
26
+ - **Calendar times at a terminal are in the zone in use, and the zone is named (WC-TIME-4).** Every shared calendar
27
+ command hands its host a `view` that prints each time on the zone's wall clock (an all-day event by its dates) and
28
+ ends with `times in <zone>`. JSON, JSONL and `--compact` are unchanged. `CalendarCommandDeps.write`'s `view` now
29
+ takes the host's body, which `renderAnswer` passes.
30
+
31
+ ### Fixed
32
+
33
+ - **`calendars busy` says when the provider did not answer for a calendar or person.** `meta.complete` is false
34
+ with a `busy.unanswered` issue each (`calendar:<id>` or `person:<email>`), with or without `--duration-minutes`,
35
+ so free stretches are no longer shown as whole. The command is `partial`, so it still exits 0. `meta` also has
36
+ `now`, `now_local` and `timezone` (WC-TIME-7).
37
+ - **`events list`'s first help example runs.** It named `starts_at` twice, which the query refuses; it is now
38
+ `'starts_at:[2026-11-02 TO 2026-11-07}'`, quoted, as are `events export`'s, so zsh does not read the brackets. A
39
+ test runs every calendar help example with a query.
40
+
41
+ ## 0.560.0 — 02.11.2026
42
+
43
+ ### Changed — may break callers
44
+
45
+ - **Agents no longer decide for the owner by default; the owner turns it on.**
46
+ `DEFAULT_DECISION_POLICY.agentDecisions` is now `false`, so a store opened without `decisions` refuses every agent
47
+ confirm or reject with `proposals.agent-decisions-off`; before, an agent with a reason could decide facts, memories,
48
+ links and project findings. A host turns it back on only from the owner's explicit config, `"agent_decisions": true`,
49
+ passed as `openStore({ decisions: { ...DEFAULT_DECISION_POLICY, agentDecisions: true } })`. Owner-only proposals
50
+ (mail and meeting findings, task close suggestions) stay refused either way.
51
+
52
+ ### Added
53
+
54
+ - **A `propose` tier under `<PREFIX>_READ_ONLY`.** `proposesOnly(command)` marks a command that only stages
55
+ something for the owner or moves its caller's own mark; the lock lets it run only when its path also ends with one
56
+ of `PROPOSE_COMMANDS` — `messages acknowledge` and `mail findings add` — a closed list. `isStoreChange` applies it,
57
+ so every host's lock does. `messages acknowledge` moved from `destroysNothing` to this tier.
58
+ - **Mail findings for the owner** (`mail_findings` in `proposed_actions`, no schema change): `store.mailFindings`
59
+ stages one batch per mailbox and run (`key` `<holder>:<through_id>`), of up to 30 findings — `task`,
60
+ `task_update` (close, due, detail), `fact`, `memory`, `link` (address → person, person → organization, thread →
61
+ project) and `new_contact` — each citing 1–8 `msg:email/…` emails by fingerprint, at most five per sender. Changed
62
+ or partial mail refuses the batch. Only the owner decides one, whatever `agent_decisions` says; the registry kind
63
+ `mail_findings` is owner-only too (`ProposalKind.ownerOnly`). `parseMailFindingsJson` reads the file;
64
+ the `mail_findings` entity describes it.
65
+ - **Mail `review` items carry what a pipeline cites and checks:** each email's evidence `fingerprint`, `new_sender`
66
+ (no earlier stored email from the address) and `sender_identities`. `review --holder` also leaves out senders whose
67
+ score is demoted, counted as `suspicious` in the mark.
68
+ - **`schedule agent --on-new-mail <holder>`,** where the host passes `newMail` (`holderHasMail`): the agent starts
69
+ only when mail is stored past the holder's mark, and may check every 5 minutes; a run with nothing new costs no
70
+ model call and records nothing. Mail that is only skipped moves the holder's mark without the agent.
71
+
72
+ ### Fixed
73
+
74
+ - **A test can no longer open the owner's real store.** Under vitest, opening a file in the owner's WireCat folder
75
+ (found from the account's home, not `HOME`) throws, read-only or not. This holds in every CLI's tests that open the
76
+ store through cli-core. cli-core's own suite now refuses vitest's threads pool. There a test env without `HOME`
77
+ reached the real home folder: on 2026-10-18 a `--pool=threads` run wrote test rows into the real store.
78
+ - **The test rows that leaked into a real store are removed (store version 48).** A store that holds an account of
79
+ the test messenger `chat` gets a mark from the migration. The next writable open then removes every such account
80
+ with all it holds, as `cache clear` removes one, so the search and vector indexes stay in step. A store without
81
+ one is unchanged. If the removal fails, the store still opens: a warning names the error and the next open tries
82
+ again.
83
+
10
84
  ## 0.559.0 — 02.11.2026
11
85
 
12
86
  ### Added
@@ -17,6 +17,8 @@ export interface Schedule {
17
17
  /** The variables the run gets on top of the timer's: the profile, where the files are, PATH. Never a credential. */
18
18
  environment: Record<string, string>;
19
19
  createdAt: string;
20
+ /** A holder whose mark gates the run: it starts only when mail is stored past that mark. */
21
+ onNewMail?: string;
20
22
  }
21
23
  export interface LastRun {
22
24
  at: string;
@@ -72,4 +72,15 @@ export declare const busyAnswer: (source: CalendarSource, query: BusyQuery, opti
72
72
  end: string;
73
73
  }[] | undefined;
74
74
  unknown?: string[] | undefined;
75
+ meta: {
76
+ now: string;
77
+ now_local: string;
78
+ timezone: string;
79
+ complete: boolean;
80
+ issues?: {
81
+ code: "authentication_error" | "cancelled" | "configuration_error" | "confirmation_required" | "invalid_response" | "network_error" | "not_found" | "outcome_unknown" | "permission_error" | "provider_error" | "provider_unavailable" | "rate_limited" | "timeout" | "validation_error";
82
+ reason?: string | undefined;
83
+ source: string;
84
+ }[] | undefined;
85
+ };
75
86
  }>;
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { dayBoundary, queryError, queryFieldsOf, zonedMoment, } from "@wirecat/cli-base/query";
3
+ import { clockMeta } from "@wirecat/cli-base/standards";
3
4
  import { LIST_QUERY_GUIDE, listQuery, nativeTermLists, typedQuery } from "../cli/list-query.js";
4
5
  import { calendarBusy } from "./cli/answers.js";
5
6
  import { isFeedCalendar } from "./feeds.js";
@@ -153,7 +154,13 @@ export const busyAnswer = async (source, query, options) => {
153
154
  ...query.calendars.map((calendar) => ({ calendar: String(calendar.id), ...missing(calendar.externalId) })),
154
155
  ...query.people.map((person) => ({ person, ...missing(person) })),
155
156
  ];
156
- const unknown = rows.filter(({ error }) => error !== undefined).map(({ id }) => id);
157
+ const failed = rows.filter(({ error }) => error !== undefined);
158
+ const unknown = failed.map(({ id }) => id);
159
+ const issues = failed.map((row) => ({
160
+ code: "provider_error",
161
+ reason: "busy.unanswered",
162
+ source: "person" in row ? `person:${row.person}` : `calendar:${row.calendar}`,
163
+ }));
157
164
  return {
158
165
  ...times(query.window),
159
166
  timezone: options.zone,
@@ -169,5 +176,11 @@ export const busyAnswer = async (source, query, options) => {
169
176
  ...(unknown.length ? { unknown } : {}),
170
177
  }
171
178
  : {}),
179
+ // Busy times missing for one calendar or person make every free stretch a guess, slots or not.
180
+ meta: {
181
+ complete: issues.length === 0,
182
+ ...(issues.length ? { issues } : {}),
183
+ ...clockMeta(options.now, options.zone),
184
+ },
172
185
  };
173
186
  };
@@ -40,8 +40,11 @@ export interface CalendarCommandDeps {
40
40
  embedded: number;
41
41
  left: boolean;
42
42
  }>;
43
- /** `view` is the text a person reads in place of the default rendering, where a command has one. */
44
- write: (value: unknown, format: "json" | "jsonl" | "text", view?: () => string) => void;
43
+ /**
44
+ * `view` is the text a person reads in place of the default rendering: the times on the zone's wall clock, and the
45
+ * zone named. It takes the host's own body (`renderAnswer` passes it) or, without one, renders `value`.
46
+ */
47
+ write: (value: unknown, format: "json" | "jsonl" | "text", view?: (body?: unknown) => string) => void;
45
48
  /** A line for the person beside the answer, never in it: which accounts `search all` read and which it skipped. */
46
49
  note?: (text: string) => void;
47
50
  /**
@@ -58,7 +61,10 @@ export interface CalendarCommandDeps {
58
61
  writeFile?: (path: string, content: string) => Promise<void>;
59
62
  /** Reads `events import`'s file; without it, and the writer's `import`, there is no `events import`. */
60
63
  readFile?: (path: string) => Promise<string>;
61
- /** A profile lock pins the process (WC-ACCT-5): `events list --source` may then read only the profile's account. */
64
+ /**
65
+ * A profile lock pins the process (WC-ACCT-5): `events list --source` may then read only the profile's account, and
66
+ * `links review` lists only its choices.
67
+ */
62
68
  locked?: boolean;
63
69
  }
64
70
  export declare const addCalendarCommands: (program: Command, deps: CalendarCommandDeps) => void;
@@ -16,12 +16,13 @@ import { linkPeople } from "../../services/people.js";
16
16
  import { BUSY_QUERY, BUSY_QUERY_NOTE, busyAnswer, busyQuery, workingHoursOf } from "../busy.js";
17
17
  import { isFeedCalendar, isPlainHttp, syncWithFeeds } from "../feeds.js";
18
18
  import { eventPreparation, nextMeeting, PREPARE_MESSAGES } from "../prepare.js";
19
- import { accountsMeta, CALENDAR_UNTRUSTED_FIELDS, calendarIn, calendarItem, EVENTS_QUERY, EVENTS_QUERY_NOTE, EXPORT_MAX, eventAnswer, eventIdOf, eventOf, eventsAnswer, eventsFilter, eventsIcs, peopleAnswer, resolveAnswer, reviewsAnswer, sourceAccounts, weekFilter, } from "../reads.js";
19
+ import { accountsMeta, CALENDAR_UNTRUSTED_FIELDS, calendarAccountNames, calendarIn, calendarItem, EVENTS_QUERY, EVENTS_QUERY_NOTE, EXPORT_MAX, eventAnswer, eventIdOf, eventOf, eventsAnswer, eventsFilter, eventsIcs, peopleAnswer, resolveAnswer, reviewsAnswer, sourceAccounts, weekFilter, } from "../reads.js";
20
20
  import { REPEAT_HELP } from "../recurrence.js";
21
21
  import { bothSearchAnswer, serverSearchAnswer } from "../server-search.js";
22
22
  import { calendarStatus } from "../sync.js";
23
23
  import { createEvent, createEventFromText, deleteEvent, EVENT_RESPONSES, IMPORT_MAX, importEvents, moveEvent, respondToEvent, updateEvent, } from "../writes.js";
24
24
  import { CALENDARS_QUERY, declareCalendarAnswers, PEOPLE_QUERY } from "./answers.js";
25
+ import { localTimesView } from "./local-times.js";
25
26
  import { addRemind } from "./remind.js";
26
27
  import { addSearchAll } from "./search-all.js";
27
28
  const LOCAL_READ = { remote: "none", local: "read" };
@@ -69,7 +70,7 @@ const addCalendarCommandsDefinition = (program, deps) => {
69
70
  const zone = () => timezoneOf(deps.timezone);
70
71
  const print = (value, command) => {
71
72
  const opts = command.optsWithGlobals();
72
- deps.write(value, opts.json ? "json" : opts.jsonl ? "jsonl" : "text");
73
+ deps.write(value, opts.json ? "json" : opts.jsonl ? "jsonl" : "text", (body) => localTimesView(body ?? value, zone(), outputFor(command).color));
73
74
  };
74
75
  const messages = (what) => {
75
76
  if (!deps.messages)
@@ -154,7 +155,7 @@ const addCalendarCommandsDefinition = (program, deps) => {
154
155
  });
155
156
  }
156
157
  if (deps.freeBusy)
157
- example(withQuery(annotate(calendars.command("busy"), { effects: REMOTE_READ, offline: false }).description("when calendars and people are taken, asked of the provider and not stored; with --duration-minutes, " +
158
+ example(withQuery(annotate(calendars.command("busy"), { effects: REMOTE_READ, offline: false, partial: true }).description("when calendars and people are taken, asked of the provider and not stored; with --duration-minutes, " +
158
159
  "the free stretches they share"), BUSY_QUERY).addHelpText("after", BUSY_QUERY_NOTE), "calendars busy person:ana@example.com --json", "calendars busy start>=2026-11-02 end<=2026-11-06 person:ana@example.com --duration-minutes 30 " +
159
160
  "--hours 10:00-16:00")
160
161
  .option("--duration-minutes <minutes>", "find free stretches at least this long, 5–1440", minutes)
@@ -256,7 +257,7 @@ const addCalendarCommandsDefinition = (program, deps) => {
256
257
  }), command);
257
258
  });
258
259
  const events = annotate(program.command("events").description("the account's stored events"), { effects: GROUP });
259
- example(withQuery(annotate(events.command("list"), { effects: LOCAL_READ, partial: true }).description("list stored events, earliest first; --source reads several accounts as one list"), EVENTS_QUERY).addHelpText("after", EVENTS_QUERY_NOTE), "events list starts_at>=2026-11-02 starts_at<2026-11-07 --json", "events list ends_at>=today person:ana@example.com", "events list overlapping:true --source all")
260
+ example(withQuery(annotate(events.command("list"), { effects: LOCAL_READ, partial: true }).description("list stored events, earliest first; --source reads several accounts as one list"), EVENTS_QUERY).addHelpText("after", EVENTS_QUERY_NOTE), "events list 'starts_at:[2026-11-02 TO 2026-11-07}' --json", "events list ends_at>=today person:ana@example.com", "events list overlapping:true --source all")
260
261
  .option("--limit <n>", "events per page, 1–1000", integer, 100)
261
262
  .option("--page <n>", "which page, starting at 1", integer, 1)
262
263
  .option("--source <accounts>", "calendar accounts held in the store to read as one list: all, a provider, or a list such as " +
@@ -285,9 +286,9 @@ const addCalendarCommandsDefinition = (program, deps) => {
285
286
  "finds; each occurrence of a repeating event as an event of its own"), EVENTS_QUERY).addHelpText("after", EVENTS_QUERY_NOTE), ...(deps.writeFile
286
287
  ? [
287
288
  "events export id:42 --output planning.ics",
288
- "events export starts_at:[2026-11-02 TO 2026-11-09} NOT event_type:birthday --output week.ics",
289
+ "events export 'starts_at:[2026-11-02 TO 2026-11-09}' NOT event_type:birthday --output week.ics",
289
290
  ]
290
- : ["events export id:42", "events export starts_at:[2026-11-02 TO 2026-11-09} NOT event_type:birthday"]));
291
+ : ["events export id:42", "events export 'starts_at:[2026-11-02 TO 2026-11-09}' NOT event_type:birthday"]));
291
292
  // Not over MCP: an agent would choose where on the owner's disk to write. It gets the text in the answer.
292
293
  if (deps.writeFile)
293
294
  writesFileOnlyWith(exporter.addOption(ownerOnlyOption("--output <file>", "the file to write; printed in the answer when absent")), "output");
@@ -440,7 +441,13 @@ const addCalendarCommandsDefinition = (program, deps) => {
440
441
  effects: GROUP,
441
442
  });
442
443
  example(annotate(links.command("review"), { effects: LOCAL_READ }).description("copies that fit two or more events equally well, waiting for the owner's choice"), "links review --json").action(async (_opts, command) => {
443
- print(eachMarked(await reviewsAnswer(deps.store), REVIEW_UNTRUSTED), command);
444
+ // Locked to a profile (WC-ACCT-5), or with no shared store to name the others by, only the profile's own account.
445
+ const own = deps.locked || !deps.messages;
446
+ const answer = await reviewsAnswer(deps.store, own ? [deps.accountId] : undefined);
447
+ const accounts = own
448
+ ? [`${deps.account.provider}:${deps.account.account}`]
449
+ : await calendarAccountNames(deps.store, messages("links review"), deps.account);
450
+ print({ ...eachMarked(answer, REVIEW_UNTRUSTED), meta: { accounts, complete: true } }, command);
444
451
  });
445
452
  example(annotate(links.command("resolve"), { effects: LOCAL_WRITE })
446
453
  .description("join a copy to the event you choose, or keep it apart")
@@ -0,0 +1,5 @@
1
+ /**
2
+ * A calendar answer as a person reads it at a terminal (WC-TIME-4): each UTC time on the wall clock of `zone`, an
3
+ * all-day event's times as its local dates, and a last line naming the zone. JSON keeps the UTC times.
4
+ */
5
+ export declare const localTimesView: (value: unknown, zone: string, color: boolean) => string;
@@ -0,0 +1,39 @@
1
+ import { renderPretty } from "@wirecat/cli-base";
2
+ const UTC_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/u;
3
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
4
+ /**
5
+ * A calendar answer as a person reads it at a terminal (WC-TIME-4): each UTC time on the wall clock of `zone`, an
6
+ * all-day event's times as its local dates, and a last line naming the zone. JSON keeps the UTC times.
7
+ */
8
+ export const localTimesView = (value, zone, color) => {
9
+ const clock = new Intl.DateTimeFormat("en-CA", {
10
+ timeZone: zone,
11
+ year: "numeric",
12
+ month: "2-digit",
13
+ day: "2-digit",
14
+ hour: "2-digit",
15
+ minute: "2-digit",
16
+ hourCycle: "h23",
17
+ });
18
+ let shown = false;
19
+ const local = (text, dateOnly) => {
20
+ const part = Object.fromEntries(clock.formatToParts(Date.parse(text)).map(({ type, value }) => [type, value]));
21
+ shown = true;
22
+ const date = `${part.year}-${part.month}-${part.day}`;
23
+ return dateOnly ? date : `${date} ${part.hour}:${part.minute}`;
24
+ };
25
+ const walk = (one, allDay = false) => {
26
+ if (typeof one === "string")
27
+ return UTC_TIME.test(one) ? local(one, allDay) : one;
28
+ if (Array.isArray(one))
29
+ return one.map((item) => walk(item));
30
+ if (!isRecord(one))
31
+ return one;
32
+ const dates = one.all_day === true || one.allDay === true;
33
+ return Object.fromEntries(Object.entries(one).map(([key, item]) => [key, walk(item, dates && /^(starts|ends)_?at$/iu.test(key))]));
34
+ };
35
+ const { meta: _meta, ...rest } = isRecord(value) ? value : { value };
36
+ const body = isRecord(value) ? (Array.isArray(rest.items) ? rest.items : "item" in rest ? rest.item : rest) : value;
37
+ const text = renderPretty(walk(body), { color });
38
+ return shown ? `${text}\n\ntimes in ${zone}` : text;
39
+ };
@@ -256,7 +256,7 @@ export const callCalendarTool = async (store, name, input, { accountIds, failure
256
256
  break;
257
257
  }
258
258
  default:
259
- answer = await reviewsAnswer(store);
259
+ answer = await reviewsAnswer(store, accounts);
260
260
  }
261
261
  const result = { accounts, ...answer, untrusted: CALENDAR_UNTRUSTED_FIELDS };
262
262
  return agentResult({
@@ -168,7 +168,12 @@ export declare const peopleAnswer: (store: EventStore, accountId: number, option
168
168
  };
169
169
  }>;
170
170
  /** Open link choices, with each candidate event's title and time so the owner can pick. */
171
- export declare const reviewsAnswer: (store: EventStore) => Promise<{
171
+ /**
172
+ * Open link choices on calendar copies. Link choices are kept per store, so without `accountIds` every account's are
173
+ * listed; with them, only choices about those accounts' copies, and a candidate event none of them holds a copy of is
174
+ * shown by its ref alone.
175
+ */
176
+ export declare const reviewsAnswer: (store: EventStore, accountIds?: readonly number[]) => Promise<{
172
177
  limit: number;
173
178
  hasMore: boolean;
174
179
  items: {
@@ -182,8 +187,12 @@ export declare const reviewsAnswer: (store: EventStore) => Promise<{
182
187
  }[];
183
188
  }[];
184
189
  page: number;
185
- accounts: string;
186
190
  }>;
191
+ /**
192
+ * The calendar accounts the store holds, by `provider:account`: the stored accounts with a calendar, and the running
193
+ * one. What `links review` names when it reads every account (WC-ACCT-9).
194
+ */
195
+ export declare const calendarAccountNames: (store: EventStore, messages: MessageStore, running: AccountKey) => Promise<string[]>;
187
196
  export declare const resolveAnswer: (store: EventStore, accountId: number, review: string, choice: string, now: number) => Promise<{
188
197
  id: string;
189
198
  status: "apart" | "linked" | "open";
@@ -348,25 +348,41 @@ export const peopleAnswer = async (store, accountId, options) => {
348
348
  return hasMore ? { ...answer, meta: { complete: true, truncated: true } } : answer;
349
349
  };
350
350
  /** Open link choices, with each candidate event's title and time so the owner can pick. */
351
- export const reviewsAnswer = async (store) => {
352
- const open = (await store.reviews({ status: "open" })).filter(({ linkableType }) => linkableType === "calendar_entry");
353
- return {
354
- ...listed(await Promise.all(open.map(async (review) => ({
355
- id: String(review.id),
356
- entry_id: String(review.linkableId),
357
- reason: review.reason,
358
- candidates: await Promise.all(review.candidates.map(async (id) => {
359
- const event = review.entityType === "event" ? (await store.event(id))?.event : undefined;
360
- return {
361
- ref: `event:${id}`,
362
- title: event?.title ?? null,
363
- starts_at: iso(event?.startsAt ?? null),
364
- };
365
- })),
366
- })))),
367
- // Link choices are kept per store, not per account, so every calendar account's are listed.
368
- accounts: "all",
351
+ /**
352
+ * Open link choices on calendar copies. Link choices are kept per store, so without `accountIds` every account's are
353
+ * listed; with them, only choices about those accounts' copies, and a candidate event none of them holds a copy of is
354
+ * shown by its ref alone.
355
+ */
356
+ export const reviewsAnswer = async (store, accountIds) => {
357
+ const scope = accountIds &&
358
+ new Set((await Promise.all(accountIds.map((id) => calendarIds(store, id)))).flatMap((ids) => [...ids]));
359
+ const open = (await store.reviews({ status: "open" })).filter(({ linkableType, calendarId }) => linkableType === "calendar_entry" && (!scope || (calendarId !== null && scope.has(calendarId))));
360
+ const shown = async (review, id) => {
361
+ const details = review.entityType === "event" ? await store.event(id) : undefined;
362
+ if (!details || (scope && !details.entries.some(({ calendarId }) => scope.has(calendarId))))
363
+ return undefined;
364
+ return details.event;
369
365
  };
366
+ return listed(await Promise.all(open.map(async (review) => ({
367
+ id: String(review.id),
368
+ entry_id: String(review.linkableId),
369
+ reason: review.reason,
370
+ candidates: await Promise.all(review.candidates.map(async (id) => {
371
+ const event = await shown(review, id);
372
+ return { ref: `event:${id}`, title: event?.title ?? null, starts_at: iso(event?.startsAt ?? null) };
373
+ })),
374
+ }))));
375
+ };
376
+ /**
377
+ * The calendar accounts the store holds, by `provider:account`: the stored accounts with a calendar, and the running
378
+ * one. What `links review` names when it reads every account (WC-ACCT-9).
379
+ */
380
+ export const calendarAccountNames = async (store, messages, running) => {
381
+ const names = new Set([nameOf(running)]);
382
+ for (const one of await messages.accounts.storedAccounts())
383
+ if ((await store.calendars(one.id)).length)
384
+ names.add(nameOf(one));
385
+ return [...names];
370
386
  };
371
387
  export const resolveAnswer = async (store, accountId, review, choice, now) => {
372
388
  if (!/^[1-9]\d*$/u.test(review))
@@ -3,6 +3,7 @@ import { CliError, isCliError } from "@wirecat/cli-base";
3
3
  import { zonedMoment } from "@wirecat/cli-base/query";
4
4
  import { guardFor } from "../sends/guard.js";
5
5
  import { guardedWrite } from "../sends/guarded.js";
6
+ import { keyedGuard } from "../sends/keyed-guard.js";
6
7
  import { DEFAULT_PERMISSIONS, levelFor } from "../sends/permissions.js";
7
8
  import { newOperationId } from "../sends/send-id.js";
8
9
  import { isFeedCalendar } from "./feeds.js";
@@ -85,53 +86,11 @@ export const draftOf = (fields, zone, { whole, allDay = false }) => {
85
86
  throw new CliError("validation_error", "nothing to change");
86
87
  return patch;
87
88
  };
88
- /**
89
- * Over the profile's guard, the write's other keys are checked too. A key that refuses is refused before anything is
90
- * asked, so nobody answers yes to a write that a stricter key then stops, and one answer covers every key of a write.
91
- */
89
+ /** The profile's guard over the write's main key and its other keys (`keyedGuard`). */
92
90
  const writeGuard = (context, extra) => {
93
91
  const settings = context.writes.settings();
94
92
  const defaults = { ...DEFAULT_PERMISSIONS, ...CALENDAR_WRITE_DEFAULTS, ...settings.permissionDefaults };
95
- let question;
96
- let answered = false;
97
- const guard = guardFor(context.writes.app, { ...settings, permissionDefaults: defaults }, context.writes.warn ?? (() => { }), context.writes.env, async (key, request) => {
98
- if (answered)
99
- return;
100
- await context.ask(question ?? key, request);
101
- answered = true;
102
- });
103
- const probes = new WeakMap();
104
- // A probe is checked and never journaled or counted: the write itself holds the one journal line.
105
- const all = (request) => {
106
- let found = probes.get(request);
107
- if (!found) {
108
- found = extra.map((key) => ({ chatId: null, kind: "read", key }));
109
- probes.set(request, found);
110
- }
111
- return [request, ...found];
112
- };
113
- return {
114
- ask: async (request) => {
115
- const levelOf = ({ key }) => levelFor(settings.permissions, key, defaults).level;
116
- const refused = all(request).find((one) => ["deny", "readonly"].includes(levelOf(one)));
117
- if (refused)
118
- guard.check(refused, { reserve: false });
119
- // The one question names every key that asks, so a yes to the write is never a silent yes to mailing people.
120
- question = all(request)
121
- .filter((one) => levelOf(one) === "ask")
122
- .map(({ key }) => key)
123
- .join(" and ");
124
- for (const one of all(request))
125
- await guard.ask?.(one);
126
- },
127
- check: (request, options) => {
128
- for (const one of all(request).slice(1))
129
- guard.check(one, { reserve: false });
130
- guard.check(request, options);
131
- },
132
- ...(guard.reserve ? { reserve: guard.reserve } : {}),
133
- record: (entry) => guard.record(entry),
134
- };
93
+ return keyedGuard((ask) => guardFor(context.writes.app, { ...settings, permissionDefaults: defaults }, context.writes.warn ?? (() => { }), context.writes.env, ask), context.ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
135
94
  };
136
95
  const notifyOf = (context, choice, others) => {
137
96
  if (choice !== undefined)
@@ -39,6 +39,16 @@ export declare const isLogin: (command: Command) => boolean;
39
39
  * (merge/unmerge, claim/release) or keeps the old value in the task's history; under the lock a close only suggests.
40
40
  */
41
41
  export declare const destroysNothing: <T extends Command>(command: T) => T;
42
+ /**
43
+ * The `propose` tier, a closed list: the only commands `<PREFIX>_READ_ONLY` lets stage something for the owner. Each
44
+ * appends a proposal the owner decides or moves its caller's own processing mark, and nothing else. A command must
45
+ * be marked `proposesOnly` **and** end with one of these paths; adding a path widens what a read-only agent can
46
+ * write, so it needs its own review.
47
+ */
48
+ export declare const PROPOSE_COMMANDS: readonly ["messages acknowledge", "mail findings add"];
49
+ /** Marks a command of the `propose` tier; the lock lets it through only when its path is in `PROPOSE_COMMANDS`. */
50
+ export declare const proposesOnly: <T extends Command>(command: T) => T;
51
+ export declare const isProposal: (command: Command) => boolean;
42
52
  /** A local edit remains an edit even when it first fetches metadata from the messenger. */
43
53
  export declare const changesStore: <T extends Command>(command: T) => T;
44
54
  /**
@@ -66,8 +76,9 @@ export declare const readsOverMcp: (command: Command) => boolean;
66
76
  export declare const readsOverMcpAt: (root: Command) => (path: readonly string[]) => boolean;
67
77
  /**
68
78
  * Whether `<PREFIX>_READ_ONLY` refuses the command as a change to the store. Every write that stays on this machine
69
- * is refused unless `destroysNothing` marks it, so a new one fails closed (WC-PERM-12). A fetch (`remote: "read"`)
70
- * keeps receiving, a remote write is `changesMessenger`'s, and an authority change has its own refusal.
79
+ * is refused unless `destroysNothing` marks it or it is of the `propose` tier, so a new one fails closed
80
+ * (WC-PERM-12). A fetch (`remote: "read"`) keeps receiving, a remote write is `changesMessenger`'s, and an authority
81
+ * change has its own refusal.
71
82
  */
72
83
  export declare const isStoreChange: (command: Command) => boolean;
73
84
  export declare const STORE_CHANGE_REFUSAL = "change the message store";
@@ -60,6 +60,25 @@ export const destroysNothing = (command) => {
60
60
  KEPT_UNDER_LOCK.add(command);
61
61
  return command;
62
62
  };
63
+ /**
64
+ * The `propose` tier, a closed list: the only commands `<PREFIX>_READ_ONLY` lets stage something for the owner. Each
65
+ * appends a proposal the owner decides or moves its caller's own processing mark, and nothing else. A command must
66
+ * be marked `proposesOnly` **and** end with one of these paths; adding a path widens what a read-only agent can
67
+ * write, so it needs its own review.
68
+ */
69
+ export const PROPOSE_COMMANDS = ["messages acknowledge", "mail findings add"];
70
+ const PROPOSES = new WeakSet();
71
+ /** Marks a command of the `propose` tier; the lock lets it through only when its path is in `PROPOSE_COMMANDS`. */
72
+ export const proposesOnly = (command) => {
73
+ PROPOSES.add(command);
74
+ return command;
75
+ };
76
+ export const isProposal = (command) => {
77
+ if (!PROPOSES.has(command))
78
+ return false;
79
+ const path = pathOf(command).join(" ");
80
+ return PROPOSE_COMMANDS.some((listed) => path === listed || path.endsWith(` ${listed}`));
81
+ };
63
82
  const STORE_WRITES = new WeakSet();
64
83
  /** A local edit remains an edit even when it first fetches metadata from the messenger. */
65
84
  export const changesStore = (command) => {
@@ -125,14 +144,16 @@ export const readsOverMcpAt = (root) => (path) => {
125
144
  };
126
145
  /**
127
146
  * Whether `<PREFIX>_READ_ONLY` refuses the command as a change to the store. Every write that stays on this machine
128
- * is refused unless `destroysNothing` marks it, so a new one fails closed (WC-PERM-12). A fetch (`remote: "read"`)
129
- * keeps receiving, a remote write is `changesMessenger`'s, and an authority change has its own refusal.
147
+ * is refused unless `destroysNothing` marks it or it is of the `propose` tier, so a new one fails closed
148
+ * (WC-PERM-12). A fetch (`remote: "read"`) keeps receiving, a remote write is `changesMessenger`'s, and an authority
149
+ * change has its own refusal.
130
150
  */
131
151
  export const isStoreChange = (command) => {
132
152
  const effects = metaOf(command).effects;
133
153
  return ((effects?.remote === "none" || STORE_WRITES.has(command)) &&
134
154
  effects?.local === "write" &&
135
155
  !KEPT_UNDER_LOCK.has(command) &&
156
+ !isProposal(command) &&
136
157
  !changesAuthority(command) &&
137
158
  writesFileNow(command));
138
159
  };
@@ -69,7 +69,7 @@ export { sharedCommandTemplate } from "./contract-templates.js";
69
69
  export { type Closeable, withDeadline } from "./deadline.js";
70
70
  export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
71
71
  export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
72
- export { changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, logsInOrOut, NO_EFFECTS, ownerOnlyOption, previewFlag, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, } from "./effects.js";
72
+ export { changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, logsInOrOut, NO_EFFECTS, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, } from "./effects.js";
73
73
  export { type CliEntry, type EntryContext, type EntryIo, openBrowser, startCli } from "./entry.js";
74
74
  export { type AnswerOutput, answerSchema, type Body, type ItemBody, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, type ListBody, type ListInput, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
75
75
  export { withAbort } from "./execution.js";
@@ -85,7 +85,7 @@ export { commandPath, LIST_QUERY_GUIDE, listQuery, nativeField, nativeTermLists,
85
85
  export { MCP_HTTP_DEFAULT_PORT, type McpServerOptions, type McpServerTarget, mcpServerCommand, } from "./mcp-server-command.js";
86
86
  export { formatMeetingBatch, prepareMeetingBatch } from "./meeting-batch.js";
87
87
  export { meetingEvidenceItem, meetingPersonContextItem } from "./meeting-evidence-answer.js";
88
- export { parseEvidenceFindingsJson, parseMeetingFindingsJson } from "./meeting-findings-input.js";
88
+ export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, } from "./meeting-findings-input.js";
89
89
  export { meetingPreparationAnswer } from "./meeting-preparation-answer.js";
90
90
  export { type MeetingPreparationReader, meetingPreparationInput, readMeetingPreparation, } from "./meeting-preparation-read.js";
91
91
  export { readMeetingProjectCandidates } from "./meeting-project-candidates-read.js";
package/dist/cli/index.js CHANGED
@@ -61,7 +61,7 @@ export { sharedCommandTemplate } from "./contract-templates.js";
61
61
  export { withDeadline } from "./deadline.js";
62
62
  export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
63
63
  export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
64
- export { changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, logsInOrOut, NO_EFFECTS, ownerOnlyOption, previewFlag, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, } from "./effects.js";
64
+ export { changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, logsInOrOut, NO_EFFECTS, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, } from "./effects.js";
65
65
  export { openBrowser, startCli } from "./entry.js";
66
66
  export { answerSchema, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
67
67
  export { withAbort } from "./execution.js";
@@ -77,7 +77,7 @@ export { commandPath, LIST_QUERY_GUIDE, listQuery, nativeField, nativeTermLists,
77
77
  export { MCP_HTTP_DEFAULT_PORT, mcpServerCommand, } from "./mcp-server-command.js";
78
78
  export { formatMeetingBatch, prepareMeetingBatch } from "./meeting-batch.js";
79
79
  export { meetingEvidenceItem, meetingPersonContextItem } from "./meeting-evidence-answer.js";
80
- export { parseEvidenceFindingsJson, parseMeetingFindingsJson } from "./meeting-findings-input.js";
80
+ export { parseEvidenceFindingsJson, parseMailFindingsJson, parseMeetingFindingsJson, } from "./meeting-findings-input.js";
81
81
  export { meetingPreparationAnswer } from "./meeting-preparation-answer.js";
82
82
  export { meetingPreparationInput, readMeetingPreparation, } from "./meeting-preparation-read.js";
83
83
  export { readMeetingProjectCandidates } from "./meeting-project-candidates-read.js";
@@ -1,3 +1,6 @@
1
+ import { type MailFindingsInput } from "../mail/findings.js";
1
2
  import { type FindingsInput, type MeetingFindingsInput } from "../meetings/index.js";
2
3
  export declare const parseMeetingFindingsJson: (text: string) => MeetingFindingsInput;
3
4
  export declare const parseEvidenceFindingsJson: (text: string) => FindingsInput;
5
+ /** A mail findings batch as `mail findings add` reads it: snake_case JSON, checked for shape before the store. */
6
+ export declare const parseMailFindingsJson: (text: string) => MailFindingsInput;
@@ -1,4 +1,5 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
+ import { validateMailFindings } from "../mail/findings.js";
2
3
  import { validateMeetingFindings } from "../meetings/index.js";
3
4
  import { validateEvidenceFindings } from "../store/evidence-findings.js";
4
5
  const keys = {
@@ -6,6 +7,7 @@ const keys = {
6
7
  due_at: "dueAt",
7
8
  due_evidence: "dueEvidence",
8
9
  assignee_evidence: "assigneeEvidence",
10
+ memory_kind: "memoryKind",
9
11
  };
10
12
  const parseFindingsJson = (text, label, validate) => {
11
13
  if (Buffer.byteLength(text, "utf8") > 65536)
@@ -40,3 +42,5 @@ const parseFindingsJson = (text, label, validate) => {
40
42
  };
41
43
  export const parseMeetingFindingsJson = (text) => parseFindingsJson(text, "meeting findings", validateMeetingFindings);
42
44
  export const parseEvidenceFindingsJson = (text) => parseFindingsJson(text, "evidence findings", validateEvidenceFindings);
45
+ /** A mail findings batch as `mail findings add` reads it: snake_case JSON, checked for shape before the store. */
46
+ export const parseMailFindingsJson = (text) => parseFindingsJson(text, "mail findings", validateMailFindings);
@@ -251,6 +251,9 @@ export declare const conversationShown: (account: AccountKey, { summary, message
251
251
  bulk?: boolean | undefined;
252
252
  list_id?: string | null | undefined;
253
253
  rule_id?: number | null | undefined;
254
+ fingerprint?: string | undefined;
255
+ new_sender?: boolean | undefined;
256
+ sender_identities?: number | undefined;
254
257
  } | undefined;
255
258
  provider_metadata?: {
256
259
  [x: string]: unknown;
@@ -228,6 +228,9 @@ export declare const threadAnswer: ({ items, ...thread }: ThreadContext, reader:
228
228
  bulk?: boolean | undefined;
229
229
  list_id?: string | null | undefined;
230
230
  rule_id?: number | null | undefined;
231
+ fingerprint?: string | undefined;
232
+ new_sender?: boolean | undefined;
233
+ sender_identities?: number | undefined;
231
234
  } | undefined;
232
235
  provider_metadata?: {
233
236
  [x: string]: unknown;