@wirecat/cli-core 0.667.0 → 0.669.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 (47) hide show
  1. package/CHANGELOG.md +92 -0
  2. package/dist/calendar/mcp/index.d.ts +2909 -186
  3. package/dist/calendar/mcp/index.js +20 -7
  4. package/dist/calendar/testing/writer-contract.js +33 -0
  5. package/dist/cli/documents/catalog.js +3 -14
  6. package/dist/cli/documents/sync.d.ts +21 -5
  7. package/dist/cli/documents/sync.js +39 -8
  8. package/dist/cli/documents/testing/source-contract.d.ts +9 -0
  9. package/dist/cli/documents/testing/source-contract.js +12 -0
  10. package/dist/cli/meeting-batch.js +2 -2
  11. package/dist/documents/model.d.ts +4 -0
  12. package/dist/entities/index.d.ts +1 -0
  13. package/dist/errors/reasons.js +1 -0
  14. package/dist/meetings/answers.d.ts +2 -0
  15. package/dist/meetings/answers.js +3 -0
  16. package/dist/meetings/cli/index.d.ts +2 -0
  17. package/dist/meetings/cli/index.js +4 -1
  18. package/dist/meetings/cli/management.d.ts +2 -0
  19. package/dist/meetings/cli/management.js +6 -1
  20. package/dist/meetings/cli/passage.js +2 -2
  21. package/dist/meetings/index.d.ts +2 -2
  22. package/dist/meetings/index.js +2 -2
  23. package/dist/meetings/mcp/passage.js +2 -2
  24. package/dist/meetings/passage.d.ts +5 -0
  25. package/dist/meetings/passage.js +10 -0
  26. package/dist/meetings/read-answers.d.ts +2 -0
  27. package/dist/meetings/read-answers.js +2 -0
  28. package/dist/meetings/read-through.d.ts +1 -1
  29. package/dist/meetings/read-through.js +4 -0
  30. package/dist/meetings/reads.d.ts +3 -17
  31. package/dist/meetings/reads.js +10 -1
  32. package/dist/meetings/store.d.ts +6 -0
  33. package/dist/meetings/store.js +13 -0
  34. package/dist/services/documents/ingestion.d.ts +3 -0
  35. package/dist/services/documents/ingestion.js +9 -2
  36. package/dist/services/documents/plan.d.ts +16 -1
  37. package/dist/services/documents/plan.js +163 -103
  38. package/dist/services/documents/ports.d.ts +13 -0
  39. package/dist/services/documents/sync.d.ts +11 -0
  40. package/dist/services/documents/sync.js +41 -3
  41. package/dist/services/metadata.d.ts +1 -1
  42. package/dist/store/sqlite/catalog.d.ts +2 -1
  43. package/dist/store/sqlite/catalog.js +4 -1
  44. package/dist/store/sqlite/meeting-listing.js +28 -7
  45. package/dist/store/sqlite/note-search.d.ts +10 -1
  46. package/dist/store/sqlite/note-search.js +35 -1
  47. package/package.json +3 -3
@@ -92,11 +92,16 @@ const fields = {
92
92
  description: { ...anyText, description: "empty clears it" },
93
93
  attendees: { type: "array", items: text, description: "email addresses; on a change, the whole new list" },
94
94
  repeat: { ...text, description: `how it repeats: ${REPEAT_HELP}; on a change, only with series` },
95
- conference: {
96
- ...text,
97
- description: "a meeting service to make a new meeting link with, one the calendar offers; never replaces a link",
98
- },
99
95
  };
96
+ const conferenceOf = (services) => services.length
97
+ ? {
98
+ conference: {
99
+ ...text,
100
+ enum: [...services],
101
+ description: "a meeting service to make a new meeting link with; never replaces a link",
102
+ },
103
+ }
104
+ : {};
100
105
  const target = {
101
106
  account_id: integer,
102
107
  event: text,
@@ -104,9 +109,10 @@ const target = {
104
109
  };
105
110
  /**
106
111
  * The calendar writes, offered only by a host that has a writer. Over MCP `ask` goes ahead (WC-MCP-7); `deny`,
107
- * `readonly`, `events.notify` and the extra keys still refuse.
112
+ * `readonly`, `events.notify` and the extra keys still refuse. `conference` is offered only with the services the
113
+ * writer declares (`CalendarWriter.conferences`).
108
114
  */
109
- export const calendarWriteTools = [
115
+ export const calendarWriteToolsFor = (conferences = []) => [
110
116
  {
111
117
  name: "event_create",
112
118
  description: "add an event to a calendar, one that repeats with repeat",
@@ -114,6 +120,7 @@ export const calendarWriteTools = [
114
120
  account_id: integer,
115
121
  calendar: text,
116
122
  ...fields,
123
+ ...conferenceOf(conferences),
117
124
  notify,
118
125
  operation_id: operationId("the operation_id a create that ended in outcome_unknown named: a retry finds that event"),
119
126
  },
@@ -127,6 +134,7 @@ export const calendarWriteTools = [
127
134
  properties: {
128
135
  ...target,
129
136
  ...fields,
137
+ ...conferenceOf(conferences),
130
138
  series: flag,
131
139
  following,
132
140
  notify,
@@ -168,9 +176,13 @@ export const calendarWriteTools = [
168
176
  inputSchema: { type: "object", properties, required, additionalProperties: false },
169
177
  annotations: { readOnlyHint: false, destructiveHint: destructive, idempotentHint: false, openWorldHint: true },
170
178
  }));
179
+ /** The write tools of a writer that makes no meeting links. */
180
+ export const calendarWriteTools = calendarWriteToolsFor();
181
+ // Any host's call may name a conference; the account's writer refuses a service it does not offer.
182
+ const ACCEPTED_WRITES = calendarWriteToolsFor(["any"]);
171
183
  const WRITES = new Set(calendarWriteTools.map(({ name }) => name));
172
184
  const argumentsOf = (name, input) => {
173
- const tool = calendarTools.find((one) => one.name === name) ?? calendarWriteTools.find((one) => one.name === name);
185
+ const tool = calendarTools.find((one) => one.name === name) ?? ACCEPTED_WRITES.find((one) => one.name === name);
174
186
  if (!tool)
175
187
  throw new CliError("validation_error", "unknown calendar tool");
176
188
  if (typeof input !== "object" || input === null || Array.isArray(input))
@@ -201,6 +213,7 @@ const argumentsOf = (name, input) => {
201
213
  "operation_id",
202
214
  "repeat",
203
215
  "to_calendar",
216
+ "conference",
204
217
  ].includes(key) &&
205
218
  (typeof value !== "string" || !value.trim()))
206
219
  throw new CliError("validation_error", `${key} must not be empty`);
@@ -1,4 +1,5 @@
1
1
  import assert from "node:assert/strict";
2
+ import { randomUUID } from "node:crypto";
2
3
  import { mkdtempSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join } from "node:path";
@@ -260,9 +261,41 @@ export const calendarWriterContract = (fixture) => {
260
261
  },
261
262
  },
262
263
  ...moveCases(fixture),
264
+ ...conferenceCases(fixture, draft),
263
265
  ];
264
266
  return cases;
265
267
  };
268
+ /** A writer that declares `conferences` returns the new meeting link on the event; its cases are skipped without. */
269
+ const conferenceCases = (fixture, draft) => {
270
+ const ready = async () => {
271
+ const f = await fixture();
272
+ const provider = f.writer.conferences?.[0];
273
+ return provider ? { ...f, provider } : undefined;
274
+ };
275
+ return [
276
+ {
277
+ name: "conference: a create with a meeting service returns the event with its new link",
278
+ run: async () => {
279
+ const f = await ready();
280
+ if (!f)
281
+ return;
282
+ const made = await f.writer.create(f.calendar, { ...draft(f.at), conference: { provider: f.provider, requestId: randomUUID() } }, { id: ID, notify: false });
283
+ assert.match(made.joinUrl ?? "", /^https:\/\//);
284
+ },
285
+ },
286
+ {
287
+ name: "conference: a change that adds one returns the event with its new link and a new etag",
288
+ run: async () => {
289
+ const f = await ready();
290
+ if (!f)
291
+ return;
292
+ const changed = await f.writer.update(f.calendar, f.existing.externalId, { conference: { provider: f.provider, requestId: randomUUID() } }, { scope: "this", etag: f.existing.etag, notify: false });
293
+ assert.match(changed.joinUrl ?? "", /^https:\/\//);
294
+ assert.notEqual(changed.etag, f.existing.etag);
295
+ },
296
+ },
297
+ ];
298
+ };
266
299
  const moveCases = (fixture) => {
267
300
  const ready = async () => {
268
301
  const f = await fixture();
@@ -11,29 +11,18 @@ import { allOf, examples, nonnegative, positive, wordsOf } from "./words.js";
11
11
  export const CATALOG_TREE_LIMIT = 10_000;
12
12
  const CATALOG_PAGE = 1000;
13
13
  const PARENT_BATCH = 200;
14
- /** `parent:a OR parent:b …` over ids as they are: the values go into a parsed template, so none needs escaping. */
15
- const anyParent = (ids) => {
16
- const ast = parseLucene(Array.from({ length: Math.max(2, ids.length) }, () => "parent:x").join(" OR "), {
17
- defaultField: "none",
18
- });
19
- const clauses = ast.root.clauses;
20
- clauses.forEach((clause, i) => {
21
- clause.node.value = ids[Math.min(i, ids.length - 1)];
22
- });
23
- return validateQuery(ast, CATALOG_QUERY);
24
- };
25
14
  /** The tree's reads through the CLI's catalog, which takes ids without the `.md` the store's entries carry. */
26
15
  export const catalogSource = (catalog, principal) => ({
27
16
  get: (externalId) => catalog.get(principal, catalogId({ externalId })),
28
17
  children: (externalId, page) => catalog.list(principal, { parent: catalogId({ externalId }), ...page }),
29
- // Each read scans the account's catalog, so the branches cut at the depth are asked about 200 at a time.
18
+ // Each read scans the account's catalog, so the branches cut at the depth are asked about 200 at a time, in one read.
30
19
  withChildren: async (externalIds) => {
31
20
  const found = new Set();
32
21
  for (let start = 0; start < externalIds.length; start += PARENT_BATCH) {
33
22
  const batch = new Set(externalIds.slice(start, start + PARENT_BATCH));
34
- const ast = anyParent([...batch].map((externalId) => catalogId({ externalId })));
23
+ const parent = [...batch].map((externalId) => catalogId({ externalId }));
35
24
  for (let offset = 0;; offset += CATALOG_PAGE) {
36
- const page = await catalog.list(principal, { ast, limit: CATALOG_PAGE, offset });
25
+ const page = await catalog.list(principal, { parent, limit: CATALOG_PAGE, offset });
37
26
  for (const item of page.items)
38
27
  for (const parent of item.parents)
39
28
  if (batch.delete(parent))
@@ -1,4 +1,5 @@
1
1
  import type { Command } from "commander";
2
+ import type { Deadline, RunBudget } from "../../background/budget.js";
2
3
  import { type Body } from "../envelope.js";
3
4
  import { type DocumentWords } from "./words.js";
4
5
  export interface DocumentSyncArgs {
@@ -6,6 +7,24 @@ export interface DocumentSyncArgs {
6
7
  rescan?: boolean;
7
8
  /** Also index pending text for meaning search, with a model already downloaded. */
8
9
  embed?: boolean;
10
+ /** Sized to the run's deadline; pass it to `syncDocuments` so a sync stops in time and says how to go on. */
11
+ budget?: RunBudget;
12
+ /** The run's hard limit; pass it to `syncDocuments` so its last step, the word index, ends before it. */
13
+ deadline?: Deadline;
14
+ }
15
+ export interface DocumentSyncAnswer {
16
+ errors: unknown[];
17
+ pending: number;
18
+ /** `false` while the pass is unfinished: a folder walk or operations are left for the next sync. */
19
+ complete?: boolean;
20
+ walk?: {
21
+ folders_left: number;
22
+ listed: number;
23
+ };
24
+ saved?: number;
25
+ names_only?: number;
26
+ removed?: number;
27
+ unchanged?: number;
9
28
  }
10
29
  export interface DocumentSyncCommands {
11
30
  words: DocumentWords;
@@ -14,16 +33,13 @@ export interface DocumentSyncCommands {
14
33
  diagnostic(text: string): void;
15
34
  /** The selected profile, as `sync again` names it. */
16
35
  profile(): string;
17
- /** The most entries one sync reads under the chosen folders, as `sync --help` says. */
36
+ /** The entries one sync walks under the chosen folders before it stops and saves, as `sync --help` says. */
18
37
  maxEntries: number;
19
38
  /**
20
39
  * Syncs the selected profile into the shared store under the lock the CLI's writes take. `errors` are the failed
21
40
  * operations still pending; `pending` counts every operation left for the next sync.
22
41
  */
23
- sync(args: DocumentSyncArgs): Promise<{
24
- errors: unknown[];
25
- pending: number;
26
- }>;
42
+ sync(args: DocumentSyncArgs): Promise<DocumentSyncAnswer>;
27
43
  /** What `status` answers: the last sync, imported documents and pending work, from local files only. */
28
44
  status(): object | Promise<object>;
29
45
  }
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
3
+ import { environmentOf, runBudgetOf } from "../context.js";
3
4
  import { honoursDryRun } from "../dry-run-guard.js";
4
5
  import { FETCH, LOCAL_READ } from "../effects.js";
5
6
  import { itemOf } from "../envelope.js";
@@ -8,25 +9,55 @@ const addDocumentSyncCommandsDefinition = (program, helpers) => {
8
9
  const { output } = helpers;
9
10
  const wording = wordsOf(helpers.words);
10
11
  const { prefix, text } = wording;
11
- const sync = examples(annotate(program.command("sync"), { effects: FETCH })
12
+ const sync = examples(annotate(program.command("sync"), { effects: FETCH, partial: true })
12
13
  .summary("import what changed in the chosen folders, and finish an unfinished sync")
13
14
  .description("import what changed in the chosen folders, and finish an unfinished sync; " +
14
- `one sync reads at most ${helpers.maxEntries} entries under the chosen folders, and as many changes`), [`${prefix} sync`, `${prefix} sync --rescan --limit 500`])
15
+ `one sync walks about ${helpers.maxEntries} entries under the chosen folders, saves where it stopped, and ` +
16
+ "the next sync goes on from there"), [`${prefix} sync`, `${prefix} sync --rescan --limit 500`])
15
17
  .option("--limit <n>", text.syncLimit, positive, 200)
16
- .option("--rescan", "read every chosen folder again instead of only what changed")
18
+ .option("--rescan", "read every chosen folder again instead of only what changed; each --rescan starts the walk over, so run it " +
19
+ "once and continue with a plain sync")
17
20
  .option("--embed", "also index pending text for meaning search, with a model already downloaded")
18
- .action(async (args) => {
19
- const result = await helpers.sync(args);
21
+ .action(async (args, command) => {
22
+ const deadline = environmentOf(command).deadline?.();
23
+ const result = await helpers.sync({ ...args, budget: runBudgetOf(command), ...(deadline ? { deadline } : {}) });
24
+ const unfinished = result.complete === false || result.pending > 0;
25
+ const moved = (result.walk?.listed ?? 0) > 0 ||
26
+ [result.saved, result.names_only, result.removed, result.unchanged].some((count) => (count ?? 0) > 0);
27
+ const again = `${wording.app} ${helpers.profile()} sync`;
28
+ const timeout = command.optsWithGlobals().timeout;
29
+ // The same sync again, never --rescan, which would start the pass over; a run that moved nothing gets no step.
30
+ const next = unfinished && !result.errors.length && moved
31
+ ? [
32
+ {
33
+ kind: "command",
34
+ step: "sync.run",
35
+ command: "sync",
36
+ args: {
37
+ limit: args.limit,
38
+ ...(timeout === undefined ? {} : { timeout }),
39
+ ...(args.embed ? { embed: true } : {}),
40
+ },
41
+ why: "the sync stopped before the end of its pass; running it again goes on from there",
42
+ safe_to_auto_execute: true,
43
+ },
44
+ ]
45
+ : [];
20
46
  output(itemOf(result, {
21
47
  meta: result.errors.length
22
48
  ? {
23
49
  complete: false,
24
50
  issues: [{ code: "provider_error", reason: "sync.partial", source: wording.source }],
25
51
  }
26
- : {},
52
+ : unfinished
53
+ ? { complete: false }
54
+ : {},
55
+ next,
27
56
  }));
28
- if (result.errors.length || result.pending)
29
- helpers.diagnostic(`${result.pending} source operations remain; run ${wording.app} ${helpers.profile()} sync again\n`);
57
+ if (result.walk)
58
+ helpers.diagnostic(`${result.walk.folders_left} folders remain to list; run ${again} again\n`);
59
+ else if (result.errors.length || result.pending)
60
+ helpers.diagnostic(`${result.pending} source operations remain; run ${again} again\n`);
30
61
  if (result.errors.length)
31
62
  throw new CliError("provider_error", "sync completed partially; failed operations remain pending", {
32
63
  reason: "sync.partial",
@@ -11,6 +11,15 @@ export interface DocumentSourceFixture<M extends SourceFile = SourceFile> {
11
11
  isDocument?(file: M): boolean;
12
12
  /** Makes a change on the provider's side (a new or edited file) for the change feed to list; absent skips that check. */
13
13
  change?(): Promise<void>;
14
+ /**
15
+ * Adds a file inside a folder two levels below the root on the provider's side, and names both. A round of changes
16
+ * lists only the direct children of a folder the feed names, so the feed must name the new file or its own folder;
17
+ * absent skips that case.
18
+ */
19
+ addNested?(): Promise<{
20
+ file: string;
21
+ folder: string;
22
+ }>;
14
23
  /** An id the provider does not know; absent skips that case. */
15
24
  missing?: string;
16
25
  }
@@ -99,6 +99,18 @@ export const documentSourceContract = (make) => {
99
99
  },
100
100
  },
101
101
  ];
102
+ cases.push({
103
+ name: "changes: a file added deep in the tree is named in the feed, itself or by its own folder",
104
+ async run() {
105
+ const { source, addNested } = await make();
106
+ if (!addNested)
107
+ return;
108
+ const token = await source.startToken();
109
+ const { file, folder } = await addNested();
110
+ const named = new Set((await source.changes(token)).items.map((item) => item.id));
111
+ assert.ok(named.has(file) || named.has(folder), `the feed names ${file} or its folder ${folder}`);
112
+ },
113
+ });
102
114
  cases.push({
103
115
  name: "metadata: an id the provider does not know is not_found",
104
116
  async run() {
@@ -6,7 +6,7 @@ import * as v from "valibot";
6
6
  import { ENTITIES } from "../entities/index.js";
7
7
  import { failureContext } from "../errors/reasons.js";
8
8
  import { createMeetingPassageCommand, createMeetingSearchCommand, meetingHitSearchRequest, meetingPassageRequest, meetingSearchArguments, meetingSearchMeta, } from "../meetings/cli/index.js";
9
- import { meetingHitsList, parseMeetingReference, } from "../meetings/index.js";
9
+ import { markedPassage, meetingHitsList, parseMeetingReference, } from "../meetings/index.js";
10
10
  import { formatMeetingEvidenceText, formatMeetingPassage } from "../services/meeting-passage-format.js";
11
11
  import { answerEntity } from "./answer-entity.js";
12
12
  import { destroysNothing } from "./effects.js";
@@ -81,7 +81,7 @@ const handlers = (reader, meta, limit) => {
81
81
  return {
82
82
  run: async (ctx) => {
83
83
  ctx.reserveReadBytes(request.max_read_bytes ?? 4194304);
84
- const result = await reader.passage(reference, { ...request, signal: ctx.signal });
84
+ const result = markedPassage(await reader.passage(reference, { ...request, signal: ctx.signal }));
85
85
  const complete = result.packet.coverage.truncated_by === null;
86
86
  return {
87
87
  answer: {
@@ -107,6 +107,10 @@ export interface SourceIndex<M extends SourceFile = SourceFile> {
107
107
  save(principal: string, content: SourceContent<M>, hash: string): Promise<string>;
108
108
  remove(principal: string, id: string): Promise<void>;
109
109
  openPictures(): Promise<PictureWriter>;
110
+ /** Indexes what the sync saved for word search, until `until` says stop; the rest waits for the next search. */
111
+ settle?(options: {
112
+ until: () => boolean;
113
+ }): Promise<unknown>;
110
114
  }
111
115
  export interface SourceStatePort<M extends SourceFile = SourceFile> {
112
116
  read(): SourceState<M>;
@@ -6797,6 +6797,7 @@ export declare const ENTITIES: {
6797
6797
  readonly speaker_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
6798
6798
  readonly text: v.StringSchema<undefined>;
6799
6799
  readonly revision: v.PicklistSchema<["current", "superseded"], undefined>;
6800
+ readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
6800
6801
  }, undefined>, undefined>;
6801
6802
  }, undefined>;
6802
6803
  readonly meeting_task_proposal: v.StrictObjectSchema<{
@@ -280,6 +280,7 @@ const OTHERS = [
280
280
  ["meetings.server-unreachable", "network_error", "the meetings service could not be reached"],
281
281
  ["meetings.server-signed-out", "authentication_error", "the meetings service needs a sign-in"],
282
282
  ["meetings.server-refused", "permission_error", "the meetings service refused the request"],
283
+ ["meetings.server-rate-limited", "rate_limited", "the meetings service asked to wait before more requests"],
283
284
  ["meetings.server-failed", "provider_error", "the meetings service could not be read, or what it returned kept"],
284
285
  [
285
286
  "meetings.server-capped",
@@ -155,6 +155,8 @@ declare const meetingDetailsEntries: {
155
155
  readonly mime: v.NullableSchema<v.StringSchema<undefined>, undefined>;
156
156
  readonly size: v.NullableSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
157
157
  readonly url: v.NullableSchema<v.StringSchema<undefined>, undefined>;
158
+ /** The file on this computer; `null` when it stays on the service or the phone system (pbx over SFTP). */
159
+ readonly local_path: v.NullableSchema<v.StringSchema<undefined>, undefined>;
158
160
  }, undefined>, undefined>;
159
161
  /**
160
162
  * The Drive files the meeting service saved for it, by role. `document` is the stored document (`document:<id>`) once
@@ -101,6 +101,8 @@ const meetingDetailsEntries = {
101
101
  mime: v.nullable(text),
102
102
  size: v.nullable(count),
103
103
  url: v.nullable(text),
104
+ /** The file on this computer; `null` when it stays on the service or the phone system (pbx over SFTP). */
105
+ local_path: v.nullable(text),
104
106
  })),
105
107
  /**
106
108
  * The Drive files the meeting service saved for it, by role. `document` is the stored document (`document:<id>`) once
@@ -210,6 +212,7 @@ export const meetingDetailsItem = (details, owner) => {
210
212
  mime: one.mime,
211
213
  size: one.size,
212
214
  url: one.url,
215
+ local_path: one.localPath,
213
216
  })),
214
217
  documents: (details.documents ?? []).map((one) => ({
215
218
  file_id: one.fileId,
@@ -52,6 +52,8 @@ export interface MeetingCommandDeps {
52
52
  * asks when the command's key is at `ask` and refuses when nobody can answer. Without it the writes refuse.
53
53
  */
54
54
  askFirst?: (command: Command) => Promise<void>;
55
+ /** The run's stop signal; the meeting writes and `meetings invitation` pass it to the service. */
56
+ signal?: () => AbortSignal | undefined;
55
57
  }
56
58
  export { addMeetingPassageCommand, createMeetingPassageCommand, type MeetingPassageFlags, meetingPassageRequest, } from "./passage.js";
57
59
  export { addMeetingProjectEvidenceCommand } from "./project-evidence.js";
@@ -14,6 +14,8 @@ import { listed, MEETING_QUERY_GUIDE, MeetingError, meetingDetailsBody, meetingP
14
14
  import { SAVE_HELP } from "../save-hints.js";
15
15
  import { addMeetingManagementCommands } from "./management.js";
16
16
  import { queryWordsAfterOptions } from "./query-options.js";
17
+ // Whoever sent the invitation wrote these, as on a calendar CLI's `events list`.
18
+ const EVENT_UNTRUSTED = ["title", "description", "location"];
17
19
  const integer = (text) => {
18
20
  if (!/^[1-9]\d*$/.test(text) || !Number.isSafeInteger(Number(text)))
19
21
  throw new InvalidArgumentError("expected a positive integer");
@@ -211,6 +213,7 @@ const addMeetingCommandsDefinition = (program, deps) => {
211
213
  output,
212
214
  inRun: deps.inRun,
213
215
  ...(deps.askFirst ? { askFirst: deps.askFirst } : {}),
216
+ ...(deps.signal ? { signal: deps.signal } : {}),
214
217
  });
215
218
  const eventList = queryWordsAfterOptions(annotate(program.command("events").description("the owner's stored events"), {
216
219
  effects: { remote: "none", local: "none" },
@@ -228,7 +231,7 @@ const addMeetingCommandsDefinition = (program, deps) => {
228
231
  if (query && !deps.store.queryEvents)
229
232
  throw new MeetingError("validation_error", "this store cannot filter events");
230
233
  const events = query ? await deps.store.queryEvents?.(query) : await deps.store.events();
231
- print(listed((events ?? []).map(eventItem)), command);
234
+ print(listed((events ?? []).map((one) => ({ ...eventItem(one), untrusted: [...EVENT_UNTRUSTED] }))), command);
232
235
  });
233
236
  };
234
237
  export { addMeetingPassageCommand, createMeetingPassageCommand, meetingPassageRequest, } from "./passage.js";
@@ -7,6 +7,8 @@ export interface MeetingManagementCommandDeps {
7
7
  inRun: <T>(command: Command, body: () => Promise<T>) => Promise<T>;
8
8
  /** The profile's question before a write reaches the service (`MeetingCommandDeps.askFirst`). */
9
9
  askFirst?: (command: Command) => Promise<void>;
10
+ /** The run's stop signal (`MeetingCommandDeps.signal`), passed to the service so `--timeout` and Ctrl-C end a call. */
11
+ signal?: () => AbortSignal | undefined;
10
12
  }
11
13
  /**
12
14
  * `meetings create|update|cancel|invitation` for a service that lets the owner change its meetings: each mounted only
@@ -98,12 +98,17 @@ const receiptItem = (receipt) => {
98
98
  */
99
99
  export const addMeetingManagementCommands = (group, deps) => {
100
100
  const { management, print, output, inRun, askFirst } = deps;
101
+ const signalled = () => {
102
+ const signal = deps.signal?.();
103
+ return signal ? { signal } : {};
104
+ };
101
105
  const has = (name) => management.capabilities.includes(name);
102
106
  // The question comes after validation, so a change the service cannot take is refused without asking. A write the
103
107
  // owner could not be asked about never goes: a host that forgets the question gets a refusal.
104
108
  const mutation = (command) => ({
105
109
  apply: true,
106
110
  dryRun: command.optsWithGlobals().dryRun === true,
111
+ ...signalled(),
107
112
  confirm: async () => {
108
113
  if (!askFirst)
109
114
  throw new CliError("configuration_error", "this tool cannot ask before it changes a meeting on the service");
@@ -128,5 +133,5 @@ export const addMeetingManagementCommands = (group, deps) => {
128
133
  effects: REMOTE_READ,
129
134
  offline: false,
130
135
  output: { entity: "meeting_invitation" },
131
- }).description("the invitation text the service writes for a meeting"))).action(async (id, _flags, command) => inRun(command, async () => print({ item: { ...(await management.invitation(id)), untrusted: ["invitation"] } }, command)));
136
+ }).description("the invitation text the service writes for a meeting"))).action(async (id, _flags, command) => inRun(command, async () => print({ item: { ...(await management.invitation(id, signalled())), untrusted: ["invitation"] } }, command)));
132
137
  };
@@ -1,7 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate, sharedCommand } from "@wirecat/cli-base/commands";
3
3
  import { Option } from "commander";
4
- import { validateMeetingPassage, } from "../passage.js";
4
+ import { markedPassage, validateMeetingPassage, } from "../passage.js";
5
5
  const count = (value) => {
6
6
  if (!/^(0|[1-9]\d*)$/.test(value) || !Number.isSafeInteger(Number(value)))
7
7
  throw new CliError("validation_error", "expected a nonnegative safe integer");
@@ -48,7 +48,7 @@ const addMeetingPassageCommandDefinition = (program, deps) => createMeetingPassa
48
48
  const globals = command.optsWithGlobals();
49
49
  const format = globals.json || globals.jsonl ? "json" : (options.format ?? "text");
50
50
  const input = meetingPassageRequest(reference, { ...options, format }, deps.signal());
51
- const result = await deps.read(reference, input);
51
+ const result = markedPassage(await deps.read(reference, input));
52
52
  input.signal?.throwIfAborted();
53
53
  deps.output(result, format);
54
54
  });
@@ -24,7 +24,7 @@ export { createMeetingContext, type MeetingContextAction, type MeetingContextCha
24
24
  export { createMeetingManagement, type DeclaredMeetingFields, declareMeetingFields, dispatchMeetingMutation, type ManagedMeeting, type ManagedMeetingChange, MEETING_FIELD_KEYS, MEETING_FIELDS, type MeetingChangeRules, type MeetingField, type MeetingFields, type MeetingManagement, type MeetingManagementPorts, type MeetingMutationOptions, type MeetingMutationProposal, type MeetingMutationReceipt, type MeetingOperationOptions, type MeetingProviderContext, type MeetingSetting, meetingFieldFlag, validateMeetingChange, } from "./meeting-management.js";
25
25
  export type { Attachment, ChatLine, Event, EventSeries, JsonValue, Meeting, MeetingSeries, Metadata, Occurrence, Participant, RecordTimes, SourceChatLine, SourceMeeting, Summary, SummaryContent, Transcript, TranscriptLine, TranscriptRow, } from "./model.js";
26
26
  export { type MeetingParticipantCandidate, type MeetingParticipantPage, type MeetingParticipantReader, type MeetingParticipantSearchOptions, type MeetingParticipantSearchStore, normalizeMeetingParticipantQuery, validateMeetingParticipantSearch, } from "./participant-search.js";
27
- export { type MeetingContextCue, type MeetingHitContextOptions, type MeetingHitContextPacket, type MeetingPassageOutputFormat, type MeetingPassageReader, type MeetingPassageRequest, type MeetingPassageResult, meetingHitContextLimits, validateMeetingPassage, } from "./passage.js";
27
+ export { MEETING_CUE_UNTRUSTED, type MeetingContextCue, type MeetingHitContextOptions, type MeetingHitContextPacket, type MeetingPassageOutputFormat, type MeetingPassageReader, type MeetingPassageRequest, type MeetingPassageResult, markedPassage, meetingHitContextLimits, validateMeetingPassage, } from "./passage.js";
28
28
  export { FACT_TYPES, PAYMENT_DIRECTIONS, PAYMENT_STATES, type Payment, paymentTitle, validatePayment, } from "./payment.js";
29
29
  export { type MeetingPreparationContext, type MeetingPreparationContextRequest, type MeetingPreparationContextStore, type PreparationPage, validateMeetingPreparationContext, } from "./preparation-context.js";
30
30
  export type { MeetingPreparationFact, MeetingPreparationKnowledgeRequest, MeetingPreparationKnowledgeStore, } from "./preparation-knowledge.js";
@@ -58,7 +58,7 @@ export { validateMeetingSeriesInventoryCursor } from "./series-inventory-validat
58
58
  export type { FoundMeeting, FoundMeetings, FullMeeting, MeetingFinds, MeetingSource, MeetingTerm, MeetingWindow, SourceParticipant, } from "./source.js";
59
59
  export { aggregateMeetingCounts, aggregateMeetingStats, MEETING_COUNTS_GROUPINGS, type MeetingCounts, type MeetingCountsGrouping, type MeetingCountsInput, type MeetingCountsMeeting, type MeetingCountsRow, type MeetingSpeakerStats, type MeetingStats, type MeetingStatsInput, type MeetingStatsRow, type MeetingStatsSelection, type MeetingStatsStore, type MeetingWeekStats, NO_SERIES, } from "./stats.js";
60
60
  export type { ChatInput, ContractCase, EventCandidateFilter, IdentityInput, MeetingDetails, MeetingDocument, MeetingDocumentInput, MeetingDocumentRole, MeetingFilter, MeetingHitSource, MeetingInput, MeetingParticipant, MeetingSave, MeetingStore, NewRecord, ParticipantInput, SearchHit, TranscriptInput, TranscriptLanguageFill, TranscriptRowInput, } from "./store.js";
61
- export { MEETING_DOCUMENT_ROLES, READ_BUDGET_EXCEEDED } from "./store.js";
61
+ export { MEETING_DOCUMENT_ROLES, READ_BUDGET_EXCEEDED, TRANSCRIPT_WORDS } from "./store.js";
62
62
  export { type MeetingTagChange, type MeetingTagChangeItem, type MeetingTagged, type MeetingTaggingItem, meetingTagChange, meetingTagChangeItem, meetingTagging, meetingTaggingItem, } from "./tag-answers.js";
63
63
  export { meetingTimestamp } from "./timestamp.js";
64
64
  export type { DocumentMeeting, MeetingTranscriptDocumentStore, MeetingTranscriptReceiptStore, MeetingTranscriptStore, TranscriptAppend, TranscriptAppendReceipt, UnlinkedTranscriptInput, } from "./transcript-store.js";
@@ -20,7 +20,7 @@ export { CHAT_MESSAGES_READ, } from "./links.js";
20
20
  export { createMeetingContext, validateMeetingContextChange, } from "./meeting-context.js";
21
21
  export { createMeetingManagement, declareMeetingFields, dispatchMeetingMutation, MEETING_FIELD_KEYS, MEETING_FIELDS, meetingFieldFlag, validateMeetingChange, } from "./meeting-management.js";
22
22
  export { normalizeMeetingParticipantQuery, validateMeetingParticipantSearch, } from "./participant-search.js";
23
- export { meetingHitContextLimits, validateMeetingPassage, } from "./passage.js";
23
+ export { MEETING_CUE_UNTRUSTED, markedPassage, meetingHitContextLimits, validateMeetingPassage, } from "./passage.js";
24
24
  export { FACT_TYPES, PAYMENT_DIRECTIONS, PAYMENT_STATES, paymentTitle, validatePayment, } from "./payment.js";
25
25
  export { validateMeetingPreparationContext, } from "./preparation-context.js";
26
26
  export { readMeetingProjectEvidence } from "./project-evidence.js";
@@ -44,7 +44,7 @@ export { validateMeetingSeriesHistory, } from "./series-history.js";
44
44
  export { createMeetingSeriesInventoryReader } from "./series-inventory.js";
45
45
  export { validateMeetingSeriesInventoryCursor } from "./series-inventory-validation.js";
46
46
  export { aggregateMeetingCounts, aggregateMeetingStats, MEETING_COUNTS_GROUPINGS, NO_SERIES, } from "./stats.js";
47
- export { MEETING_DOCUMENT_ROLES, READ_BUDGET_EXCEEDED } from "./store.js";
47
+ export { MEETING_DOCUMENT_ROLES, READ_BUDGET_EXCEEDED, TRANSCRIPT_WORDS } from "./store.js";
48
48
  export { meetingTagChange, meetingTagChangeItem, meetingTagging, meetingTaggingItem, } from "./tag-answers.js";
49
49
  export { meetingTimestamp } from "./timestamp.js";
50
50
  export { parseTranscriptText, TranscriptTextError } from "./transcript-text.js";
@@ -1,5 +1,5 @@
1
1
  import { CliError, errorObjectOf, isCliError, mcpErrorResult } from "@wirecat/cli-base";
2
- import { validateMeetingPassage } from "../passage.js";
2
+ import { markedPassage, validateMeetingPassage } from "../passage.js";
3
3
  import { agentResult, UNTRUSTED_NEUTRAL } from "./agent-text.js";
4
4
  const count = { type: "integer", minimum: 0, maximum: 999 };
5
5
  export const meetingPassageTool = {
@@ -40,7 +40,7 @@ export const callMeetingPassageTool = async (read, input, signal, failure = {})
40
40
  const reference = args.reference;
41
41
  validateMeetingPassage(reference, options);
42
42
  signal?.throwIfAborted();
43
- const result = await read(reference, options);
43
+ const result = markedPassage(await read(reference, options));
44
44
  signal?.throwIfAborted();
45
45
  return agentResult({ content: [{ type: "text", text: result.content }], structuredContent: result.packet });
46
46
  }
@@ -18,6 +18,7 @@ export interface MeetingContextCue {
18
18
  speaker_name: string | null;
19
19
  text: string;
20
20
  revision: "current" | "superseded";
21
+ untrusted?: string[];
21
22
  }
22
23
  export declare const meetingHitContextLimits: (options?: MeetingHitContextOptions) => {
23
24
  before: number;
@@ -63,5 +64,9 @@ export interface MeetingPassageResult {
63
64
  packet: MeetingHitContextPacket;
64
65
  content: string;
65
66
  }
67
+ /** The cues' speaker names and lines are what people said: each cue names them, as every meeting read does. */
68
+ export declare const MEETING_CUE_UNTRUSTED: string[];
69
+ /** The passage as a command or tool answers it, its cues marked; the reader's own packet stays as its bytes counted. */
70
+ export declare const markedPassage: (result: MeetingPassageResult) => MeetingPassageResult;
66
71
  export type MeetingPassageReader = (reference: string, options: MeetingPassageRequest) => Promise<MeetingPassageResult>;
67
72
  export declare const validateMeetingPassage: (reference: string, options: MeetingPassageRequest) => void;
@@ -14,6 +14,16 @@ export const meetingHitContextLimits = (options = {}) => {
14
14
  throw new CliError("validation_error", "context takes 0–999 surrounding cues, 2–4194304 output bytes and a bounded read budget");
15
15
  return { before, after, bytes, max_read_bytes };
16
16
  };
17
+ /** The cues' speaker names and lines are what people said: each cue names them, as every meeting read does. */
18
+ export const MEETING_CUE_UNTRUSTED = ["speaker_name", "text"];
19
+ /** The passage as a command or tool answers it, its cues marked; the reader's own packet stays as its bytes counted. */
20
+ export const markedPassage = (result) => ({
21
+ ...result,
22
+ packet: {
23
+ ...result.packet,
24
+ items: result.packet.items.map((cue) => ({ ...cue, untrusted: [...MEETING_CUE_UNTRUSTED] })),
25
+ },
26
+ });
17
27
  export const validateMeetingPassage = (reference, options) => {
18
28
  meetingHitContextLimits(options);
19
29
  if (typeof reference !== "string" ||
@@ -190,6 +190,8 @@ export declare const meetingPassage: v.StrictObjectSchema<{
190
190
  readonly speaker_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
191
191
  readonly text: v.StringSchema<undefined>;
192
192
  readonly revision: v.PicklistSchema<["current", "superseded"], undefined>;
193
+ /** What people said: `speaker_name` and `text`. */
194
+ readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
193
195
  }, undefined>, undefined>;
194
196
  }, undefined>;
195
197
  /** A stored event a meeting belongs to; `id` is what `meetings update --event-id` takes. */
@@ -219,6 +219,8 @@ export const meetingPassage = v.strictObject({
219
219
  speaker_name: v.nullable(text),
220
220
  text,
221
221
  revision,
222
+ /** What people said: `speaker_name` and `text`. */
223
+ untrusted: v.optional(v.array(text)),
222
224
  })),
223
225
  });
224
226
  /** A stored event a meeting belongs to; `id` is what `meetings update --event-id` takes. */
@@ -13,7 +13,7 @@ export declare const MEETING_SERVER_BOUNDS: {
13
13
  calls: number;
14
14
  pages: number;
15
15
  };
16
- export type MeetingServerSkip = "unsupported" | "offline" | "unreachable" | "not_signed_in" | "refused" | "failed" | "no_upcoming";
16
+ export type MeetingServerSkip = "unsupported" | "offline" | "unreachable" | "not_signed_in" | "refused" | "rate_limited" | "failed" | "no_upcoming";
17
17
  /** What asking the service did, as messages search's `server` says it. */
18
18
  export interface MeetingServerReport {
19
19
  backend: "server" | "both";
@@ -16,6 +16,7 @@ const ISSUES = {
16
16
  unreachable: ["network_error", "meetings.server-unreachable"],
17
17
  not_signed_in: ["authentication_error", "meetings.server-signed-out"],
18
18
  refused: ["permission_error", "meetings.server-refused"],
19
+ rate_limited: ["rate_limited", "meetings.server-rate-limited"],
19
20
  failed: ["provider_error", "meetings.server-failed"],
20
21
  };
21
22
  const metaOf = (reason, provider) => {
@@ -28,6 +29,7 @@ const WHY = {
28
29
  unreachable: (provider) => `${provider} could not be reached — the answer is the store's`,
29
30
  not_signed_in: (provider) => `not signed in to ${provider} — the answer is the store's`,
30
31
  refused: (provider) => `${provider} refused the request — the answer is the store's`,
32
+ rate_limited: (provider) => `${provider} asked to wait before more requests — the answer is the store's`,
31
33
  failed: (provider) => `${provider} could not be read — the answer is the store's`,
32
34
  no_upcoming: (provider) => `${provider} lists no meeting before it starts — upcoming ones are not in the answer`,
33
35
  };
@@ -39,6 +41,8 @@ const reasonOf = (error) => {
39
41
  return "refused";
40
42
  if (code === "network_error")
41
43
  return "unreachable";
44
+ if (code === "rate_limited")
45
+ return "rate_limited";
42
46
  return "failed";
43
47
  };
44
48
  const refusal = (reason, provider, error) => error ??