@wirecat/cli-core 0.560.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,37 @@ 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
+
10
41
  ## 0.560.0 — 02.11.2026
11
42
 
12
43
  ### Changed — may break callers
@@ -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)
@@ -107,6 +107,7 @@ const OTHERS = [
107
107
  ["meetings.index-pending", "not_found", "some stored meetings are not indexed by person yet"],
108
108
  ["profile.locked", "permission_error", "a profile lock pins this process to its own account"],
109
109
  ["busy.offline", "permission_error", "calendars busy asks the provider; --offline was given"],
110
+ ["busy.unanswered", "provider_error", "the provider gave no busy times for a calendar or person that was asked"],
110
111
  validation("busy.no-calendars", "no calendar syncs and no person was named, so there is nobody to ask"),
111
112
  ["search.offline", "permission_error", "search --backend server asks the provider; --offline was given"],
112
113
  validation("search.no-calendars", "no calendar of this profile syncs yet, so the provider has nothing to search"),
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
38
38
  max_read_bytes?: undefined;
39
39
  cursor?: undefined;
40
40
  } | {
41
+ limit?: undefined;
41
42
  event_id?: undefined;
42
43
  series_id?: undefined;
43
44
  page?: undefined;
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
53
54
  format?: undefined;
54
55
  transcript_id?: undefined;
55
56
  query?: undefined;
56
- limit?: undefined;
57
57
  scan_limit?: undefined;
58
58
  max_read_bytes?: undefined;
59
59
  cursor?: undefined;
60
60
  } | {
61
+ limit?: undefined;
61
62
  event_id?: undefined;
62
63
  series_id?: undefined;
63
64
  page?: undefined;
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
75
76
  format?: undefined;
76
77
  transcript_id?: undefined;
77
78
  query?: undefined;
78
- limit?: undefined;
79
79
  scan_limit?: undefined;
80
80
  max_read_bytes?: undefined;
81
81
  cursor?: undefined;
82
82
  } | {
83
+ limit?: undefined;
83
84
  event_id?: undefined;
84
85
  series_id?: undefined;
85
86
  page?: undefined;
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
101
102
  minimum: number;
102
103
  };
103
104
  query?: undefined;
104
- limit?: undefined;
105
105
  scan_limit?: undefined;
106
106
  max_read_bytes?: undefined;
107
107
  cursor?: undefined;
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
188
188
  max_read_bytes?: undefined;
189
189
  cursor?: undefined;
190
190
  } | {
191
+ limit?: undefined;
191
192
  event_id?: undefined;
192
193
  series_id?: undefined;
193
194
  page?: undefined;
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
203
204
  format?: undefined;
204
205
  transcript_id?: undefined;
205
206
  query?: undefined;
206
- limit?: undefined;
207
207
  scan_limit?: undefined;
208
208
  max_read_bytes?: undefined;
209
209
  cursor?: undefined;
210
210
  } | {
211
+ limit?: undefined;
211
212
  event_id?: undefined;
212
213
  series_id?: undefined;
213
214
  page?: undefined;
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
225
226
  format?: undefined;
226
227
  transcript_id?: undefined;
227
228
  query?: undefined;
228
- limit?: undefined;
229
229
  scan_limit?: undefined;
230
230
  max_read_bytes?: undefined;
231
231
  cursor?: undefined;
232
232
  } | {
233
+ limit?: undefined;
233
234
  event_id?: undefined;
234
235
  series_id?: undefined;
235
236
  page?: undefined;
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
251
252
  minimum: number;
252
253
  };
253
254
  query?: undefined;
254
- limit?: undefined;
255
255
  scan_limit?: undefined;
256
256
  max_read_bytes?: undefined;
257
257
  cursor?: undefined;
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
338
338
  max_read_bytes?: undefined;
339
339
  cursor?: undefined;
340
340
  } | {
341
+ limit?: undefined;
341
342
  event_id?: undefined;
342
343
  series_id?: undefined;
343
344
  page?: undefined;
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
353
354
  format?: undefined;
354
355
  transcript_id?: undefined;
355
356
  query?: undefined;
356
- limit?: undefined;
357
357
  scan_limit?: undefined;
358
358
  max_read_bytes?: undefined;
359
359
  cursor?: undefined;
360
360
  } | {
361
+ limit?: undefined;
361
362
  event_id?: undefined;
362
363
  series_id?: undefined;
363
364
  page?: undefined;
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
375
376
  format?: undefined;
376
377
  transcript_id?: undefined;
377
378
  query?: undefined;
378
- limit?: undefined;
379
379
  scan_limit?: undefined;
380
380
  max_read_bytes?: undefined;
381
381
  cursor?: undefined;
382
382
  } | {
383
+ limit?: undefined;
383
384
  event_id?: undefined;
384
385
  series_id?: undefined;
385
386
  page?: undefined;
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
401
402
  minimum: number;
402
403
  };
403
404
  query?: undefined;
404
- limit?: undefined;
405
405
  scan_limit?: undefined;
406
406
  max_read_bytes?: undefined;
407
407
  cursor?: undefined;
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
488
488
  max_read_bytes?: undefined;
489
489
  cursor?: undefined;
490
490
  } | {
491
+ limit?: undefined;
491
492
  event_id?: undefined;
492
493
  series_id?: undefined;
493
494
  page?: undefined;
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
503
504
  format?: undefined;
504
505
  transcript_id?: undefined;
505
506
  query?: undefined;
506
- limit?: undefined;
507
507
  scan_limit?: undefined;
508
508
  max_read_bytes?: undefined;
509
509
  cursor?: undefined;
510
510
  } | {
511
+ limit?: undefined;
511
512
  event_id?: undefined;
512
513
  series_id?: undefined;
513
514
  page?: undefined;
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
525
526
  format?: undefined;
526
527
  transcript_id?: undefined;
527
528
  query?: undefined;
528
- limit?: undefined;
529
529
  scan_limit?: undefined;
530
530
  max_read_bytes?: undefined;
531
531
  cursor?: undefined;
532
532
  } | {
533
+ limit?: undefined;
533
534
  event_id?: undefined;
534
535
  series_id?: undefined;
535
536
  page?: undefined;
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
551
552
  minimum: number;
552
553
  };
553
554
  query?: undefined;
554
- limit?: undefined;
555
555
  scan_limit?: undefined;
556
556
  max_read_bytes?: undefined;
557
557
  cursor?: undefined;
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
638
638
  max_read_bytes?: undefined;
639
639
  cursor?: undefined;
640
640
  } | {
641
+ limit?: undefined;
641
642
  event_id?: undefined;
642
643
  series_id?: undefined;
643
644
  page?: undefined;
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
653
654
  format?: undefined;
654
655
  transcript_id?: undefined;
655
656
  query?: undefined;
656
- limit?: undefined;
657
657
  scan_limit?: undefined;
658
658
  max_read_bytes?: undefined;
659
659
  cursor?: undefined;
660
660
  } | {
661
+ limit?: undefined;
661
662
  event_id?: undefined;
662
663
  series_id?: undefined;
663
664
  page?: undefined;
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
675
676
  format?: undefined;
676
677
  transcript_id?: undefined;
677
678
  query?: undefined;
678
- limit?: undefined;
679
679
  scan_limit?: undefined;
680
680
  max_read_bytes?: undefined;
681
681
  cursor?: undefined;
682
682
  } | {
683
+ limit?: undefined;
683
684
  event_id?: undefined;
684
685
  series_id?: undefined;
685
686
  page?: undefined;
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
701
702
  minimum: number;
702
703
  };
703
704
  query?: undefined;
704
- limit?: undefined;
705
705
  scan_limit?: undefined;
706
706
  max_read_bytes?: undefined;
707
707
  cursor?: undefined;
@@ -3,6 +3,7 @@ export { type FloodDeadline, FloodMemory, type FloodState, FROZEN_HOLD_MS, flood
3
3
  export { type Asker, type GuardRequest, guardFor, type SendGuard, type SendGuardOptions, sendGuard, sharedJournal, } from "./guard.js";
4
4
  export { currentOperation, guardedWrite, type Operated } from "./guarded.js";
5
5
  export { type AccountAction, type ChatAction, type SendEntry, SendJournal, type SendKind, type SendOutcome, sendsPathFor, } from "./journal.js";
6
+ export { type KeyedGuard, keyedGuard } from "./keyed-guard.js";
6
7
  export { DEFAULT_PACE, type PaceRate, Pacer, pacePathFor } from "./pace.js";
7
8
  export { assertOverridesTighten, CEILING_KEY, COMMAND_PATH_KEY, DEFAULT_PERMISSIONS, keyForCommand, keyForWrite, LEVELS, type Level, layerPermissions, levelFor, type PermissionKey, permissionOverrides, readKeysForCommand, skipFlagFor, WRITE_KEYS, } from "./permissions.js";
8
9
  export { type Recipient, RecipientList, recipientsPathFor } from "./recipients.js";
@@ -2,6 +2,7 @@ export { FloodMemory, FROZEN_HOLD_MS, floodPathFor, LIMITED_HOLD_MS, } from "./f
2
2
  export { guardFor, sendGuard, sharedJournal, } from "./guard.js";
3
3
  export { currentOperation, guardedWrite } from "./guarded.js";
4
4
  export { SendJournal, sendsPathFor, } from "./journal.js";
5
+ export { keyedGuard } from "./keyed-guard.js";
5
6
  export { DEFAULT_PACE, Pacer, pacePathFor } from "./pace.js";
6
7
  export { assertOverridesTighten, CEILING_KEY, COMMAND_PATH_KEY, DEFAULT_PERMISSIONS, keyForCommand, keyForWrite, LEVELS, layerPermissions, levelFor, permissionOverrides, readKeysForCommand, skipFlagFor, WRITE_KEYS, } from "./permissions.js";
7
8
  export { RecipientList, recipientsPathFor } from "./recipients.js";
@@ -0,0 +1,12 @@
1
+ import type { Asker, GuardRequest, SendGuard } from "./guard.js";
2
+ import type { Level, PermissionKey } from "./permissions.js";
3
+ export type KeyedGuard = SendGuard & {
4
+ /** Refuses the write when one of its keys denies it or is read-only; asks nothing. */
5
+ refuse(request: GuardRequest): void;
6
+ };
7
+ /**
8
+ * A guard over a write's main key and its extra keys. A key that refuses refuses before anything is asked, so nobody
9
+ * answers yes to a write that a stricter key then stops, and one question names every key at `ask`. The extra keys are
10
+ * probed as reads, never journaled or counted: the write itself holds the one journal line.
11
+ */
12
+ export declare const keyedGuard: (build: (ask: Asker) => SendGuard, ask: Asker, levelOf: (key: PermissionKey) => Level, extra: readonly PermissionKey[]) => KeyedGuard;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * A guard over a write's main key and its extra keys. A key that refuses refuses before anything is asked, so nobody
3
+ * answers yes to a write that a stricter key then stops, and one question names every key at `ask`. The extra keys are
4
+ * probed as reads, never journaled or counted: the write itself holds the one journal line.
5
+ */
6
+ export const keyedGuard = (build, ask, levelOf, extra) => {
7
+ let question;
8
+ let answered = false;
9
+ const guard = build(async (key, request) => {
10
+ if (answered)
11
+ return;
12
+ await ask(question || key, request);
13
+ answered = true;
14
+ });
15
+ const probes = new WeakMap();
16
+ const all = (request) => {
17
+ let found = probes.get(request);
18
+ if (!found) {
19
+ found = extra.map((key) => ({ chatId: null, kind: "read", key }));
20
+ probes.set(request, found);
21
+ }
22
+ return [request, ...found];
23
+ };
24
+ const levelOfRequest = ({ key }) => levelOf(key ?? "");
25
+ const refuse = (request) => {
26
+ const refused = all(request).find((one) => ["deny", "readonly"].includes(levelOfRequest(one)));
27
+ if (refused)
28
+ guard.check(refused, { reserve: false });
29
+ };
30
+ return {
31
+ refuse,
32
+ ask: async (request) => {
33
+ refuse(request);
34
+ question = all(request)
35
+ .filter((one) => levelOfRequest(one) === "ask")
36
+ .map(({ key }) => key)
37
+ .join(" and ");
38
+ for (const one of all(request))
39
+ await guard.ask?.(one);
40
+ },
41
+ check: (request, options) => {
42
+ for (const one of all(request).slice(1))
43
+ guard.check(one, { reserve: false });
44
+ guard.check(request, options);
45
+ },
46
+ ...(guard.reserve ? { reserve: guard.reserve } : {}),
47
+ record: (entry) => guard.record(entry),
48
+ };
49
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wirecat/cli-core",
3
- "version": "0.560.0",
3
+ "version": "0.561.0",
4
4
  "description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Viacheslav Ptsarev",