@wirecat/cli-core 0.666.0 → 0.668.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 +88 -0
  2. package/dist/calendar/cli/conference.d.ts +3 -0
  3. package/dist/calendar/cli/conference.js +7 -0
  4. package/dist/calendar/cli/index.d.ts +1 -0
  5. package/dist/calendar/cli/index.js +4 -2
  6. package/dist/calendar/mcp/index.d.ts +2944 -171
  7. package/dist/calendar/mcp/index.js +22 -3
  8. package/dist/calendar/testing/writer-contract.js +34 -0
  9. package/dist/calendar/testing/writer.d.ts +3 -0
  10. package/dist/calendar/testing/writer.js +9 -1
  11. package/dist/calendar/writer.d.ts +13 -0
  12. package/dist/calendar/writes.d.ts +3 -0
  13. package/dist/calendar/writes.js +21 -1
  14. package/dist/cli/documents/words.d.ts +1 -1
  15. package/dist/cli/meeting-batch.js +2 -2
  16. package/dist/domain/providers.js +2 -1
  17. package/dist/entities/index.d.ts +7 -0
  18. package/dist/errors/reasons.js +2 -0
  19. package/dist/meetings/answers.d.ts +12 -0
  20. package/dist/meetings/answers.js +27 -1
  21. package/dist/meetings/cli/index.d.ts +2 -0
  22. package/dist/meetings/cli/index.js +7 -3
  23. package/dist/meetings/cli/management.d.ts +3 -1
  24. package/dist/meetings/cli/management.js +73 -26
  25. package/dist/meetings/cli/passage.js +2 -2
  26. package/dist/meetings/export.d.ts +2 -0
  27. package/dist/meetings/export.js +1 -0
  28. package/dist/meetings/index.d.ts +3 -3
  29. package/dist/meetings/index.js +3 -3
  30. package/dist/meetings/mcp/passage.js +2 -2
  31. package/dist/meetings/meeting-management.d.ts +68 -3
  32. package/dist/meetings/meeting-management.js +134 -17
  33. package/dist/meetings/passage.d.ts +5 -0
  34. package/dist/meetings/passage.js +10 -0
  35. package/dist/meetings/read-answers.d.ts +3 -0
  36. package/dist/meetings/read-answers.js +3 -0
  37. package/dist/meetings/read-through.d.ts +1 -1
  38. package/dist/meetings/read-through.js +4 -0
  39. package/dist/meetings/reads.d.ts +16 -3
  40. package/dist/meetings/reads.js +12 -2
  41. package/dist/meetings/result-items.d.ts +3 -0
  42. package/dist/meetings/result-items.js +9 -1
  43. package/dist/meetings/store.d.ts +6 -0
  44. package/dist/meetings/store.js +13 -0
  45. package/dist/meetings/testing/management-contract.js +27 -5
  46. package/dist/store/sqlite/meeting-listing.js +28 -7
  47. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { annotate } from "@wirecat/cli-base/commands";
3
3
  import { InvalidArgumentError, Option } from "commander";
4
+ import { MEETING_FIELD_KEYS, MEETING_FIELDS, meetingFieldFlag, SNAKE_CASE, } from "../meeting-management.js";
4
5
  const REMOTE_READ = { remote: "read", local: "read" };
5
6
  const REMOTE_WRITE = { remote: "write", local: "write" };
6
7
  const minutes = (text) => {
@@ -8,14 +9,56 @@ const minutes = (text) => {
8
9
  throw new InvalidArgumentError("expected whole minutes");
9
10
  return Number(text);
10
11
  };
11
- const changeOptions = (command) => command
12
- .option("--title <title>", "the meeting's title")
13
- .addOption(new Option("--kind <kind>", "an instant or a scheduled meeting").choices(["instant", "scheduled"]))
14
- .option("--start-time <time>", "when it starts: an ISO time with its offset, 2026-11-20T10:00:00+01:00")
15
- .option("--duration-minutes <minutes>", "how long it lasts, 1–1440", minutes)
16
- .option("--timezone <zone>", "its IANA time zone, Europe/Madrid")
17
- .option("--agenda <text>", "its agenda");
18
- const changeOf = (flags) => Object.fromEntries(["title", "kind", "startTime", "durationMinutes", "timezone", "agenda"].flatMap((key) => flags[key] === undefined ? [] : [[key, flags[key]]]));
12
+ const setting = (text, previous = []) => {
13
+ const at = text.indexOf("=");
14
+ const name = text.slice(0, at);
15
+ if (at < 1 || !SNAKE_CASE.test(name))
16
+ throw new InvalidArgumentError("expected name=value with a snake_case name, such as access_type=trusted");
17
+ return [...previous, [name, text.slice(at + 1)]];
18
+ };
19
+ const valuesOf = (one) => one.type === "choice" ? one.values.join("|") : one.type === "boolean" ? "true|false" : "<text>";
20
+ /** The same options in every meetings tool; what this service takes is in `--setting`'s description and the help. */
21
+ const changeOptions = (command, declared, create) => {
22
+ const settings = declared.settings.length
23
+ ? declared.settings.map((one) => `${one.name}=${valuesOf(one)}`).join(", ")
24
+ : "this service has none";
25
+ const takes = declared.fields.map(meetingFieldFlag).join(", ") || "none of the options above";
26
+ const schedules = declared.fields.includes("startTime");
27
+ const start = !create
28
+ ? ""
29
+ : !schedules
30
+ ? "; this service takes none, its meetings start now"
31
+ : declared.fields.includes("kind")
32
+ ? "; for a meeting that starts now, give --kind instant instead"
33
+ : "";
34
+ return command
35
+ .option("--title <title>", "the meeting's title")
36
+ .addOption(new Option("--kind <kind>", "an instant or a scheduled meeting").choices(["instant", "scheduled"]))
37
+ .option("--start-time <time>", `when it starts: an ISO time with its offset, 2026-11-20T10:00:00+01:00${start}`)
38
+ .option("--duration-minutes <minutes>", "how long it lasts, 1–1440", minutes)
39
+ .option("--timezone <zone>", "its IANA time zone, Europe/Madrid")
40
+ .option("--agenda <text>", "its agenda")
41
+ .option("--setting <name=value>", `a setting of this service; repeat it for more: ${settings}`, setting)
42
+ .addHelpText("after", [
43
+ "",
44
+ `This service takes ${takes}.`,
45
+ ...(declared.settings.length
46
+ ? ["Its settings:", ...declared.settings.map((one) => ` ${one.name}=${valuesOf(one)} ${one.description}`)]
47
+ : []),
48
+ ].join("\n"));
49
+ };
50
+ const changeOf = (flags) => {
51
+ const change = Object.fromEntries(MEETING_FIELDS.flatMap((key) => (flags[key] === undefined ? [] : [[key, flags[key]]])));
52
+ if (!flags.setting)
53
+ return change;
54
+ const settings = new Map();
55
+ for (const [name, value] of flags.setting) {
56
+ if (settings.has(name))
57
+ throw new CliError("validation_error", `--setting ${name} is given twice`);
58
+ settings.set(name, value);
59
+ }
60
+ return { ...change, settings: Object.fromEntries(settings) };
61
+ };
19
62
  const meetingOf = (one) => ({
20
63
  id: one.id,
21
64
  title: one.title,
@@ -37,17 +80,15 @@ const receiptItem = (receipt) => {
37
80
  ...(change
38
81
  ? {
39
82
  change: {
40
- ...(change.title === undefined ? {} : { title: change.title }),
41
- ...(change.kind === undefined ? {} : { kind: change.kind }),
42
- ...(change.startTime === undefined ? {} : { start_time: change.startTime }),
43
- ...(change.durationMinutes === undefined ? {} : { duration_minutes: change.durationMinutes }),
44
- ...(change.timezone === undefined ? {} : { timezone: change.timezone }),
45
- ...(change.agenda === undefined ? {} : { agenda: change.agenda }),
83
+ ...Object.fromEntries(MEETING_FIELDS.flatMap((key) => change[key] === undefined ? [] : [[MEETING_FIELD_KEYS[key], change[key]]])),
84
+ ...(change.settings === undefined ? {} : { settings: { ...change.settings } }),
46
85
  },
47
86
  }
48
87
  : {}),
49
88
  applied: receipt.applied,
50
- ...(receipt.meeting ? { meeting: meetingOf(receipt.meeting) } : {}),
89
+ ...(receipt.meeting
90
+ ? { meeting: meetingOf(receipt.meeting), untrusted: ["meeting.title", "meeting.agenda", "meeting.join_url"] }
91
+ : {}),
51
92
  };
52
93
  };
53
94
  /**
@@ -57,27 +98,33 @@ const receiptItem = (receipt) => {
57
98
  */
58
99
  export const addMeetingManagementCommands = (group, deps) => {
59
100
  const { management, print, output, inRun, askFirst } = deps;
101
+ const signalled = () => {
102
+ const signal = deps.signal?.();
103
+ return signal ? { signal } : {};
104
+ };
60
105
  const has = (name) => management.capabilities.includes(name);
61
- // A write the owner could not be asked about never goes: a host that forgets the question gets a refusal.
62
- const mutation = async (command) => {
63
- const dryRun = command.optsWithGlobals().dryRun === true;
64
- if (!dryRun) {
106
+ // The question comes after validation, so a change the service cannot take is refused without asking. A write the
107
+ // owner could not be asked about never goes: a host that forgets the question gets a refusal.
108
+ const mutation = (command) => ({
109
+ apply: true,
110
+ dryRun: command.optsWithGlobals().dryRun === true,
111
+ ...signalled(),
112
+ confirm: async () => {
65
113
  if (!askFirst)
66
114
  throw new CliError("configuration_error", "this tool cannot ask before it changes a meeting on the service");
67
115
  await askFirst(command);
68
- }
69
- return { apply: true, dryRun };
70
- };
116
+ },
117
+ });
71
118
  const write = (name) => annotate(group.command(name), { effects: REMOTE_WRITE, offline: false, output: { entity: "meeting_change" } });
72
119
  const target = (command) => command.argument("<meeting>", "the service's id of the meeting");
73
120
  if (has("create"))
74
- output(changeOptions(write("create").description("create a meeting on the service"))).action(async (flags, command) => inRun(command, async () => print({ item: receiptItem(await management.create(changeOf(flags), await mutation(command))) }, command)));
121
+ output(changeOptions(write("create").description("create a meeting on the service"), management.fields.create, true)).action(async (flags, command) => inRun(command, async () => print({ item: receiptItem(await management.create(changeOf(flags), mutation(command))) }, command)));
75
122
  if (has("update"))
76
- output(changeOptions(target(write("update").description("change a meeting on the service")))).action(async (id, flags, command) => inRun(command, async () => print({ item: receiptItem(await management.update(id, changeOf(flags), await mutation(command))) }, command)));
123
+ output(changeOptions(target(write("update").description("change a meeting on the service")), management.fields.update, false)).action(async (id, flags, command) => inRun(command, async () => print({ item: receiptItem(await management.update(id, changeOf(flags), mutation(command))) }, command)));
77
124
  if (has("cancel"))
78
125
  output(target(write("cancel").description("cancel a meeting on the service")).option("--occurrence-id <id>", "cancel only this occurrence of a repeating meeting")).action(async (id, flags, command) => inRun(command, async () => print({
79
126
  item: receiptItem(await management.cancel(id, {
80
- ...(await mutation(command)),
127
+ ...mutation(command),
81
128
  ...(flags.occurrenceId === undefined ? {} : { occurrenceId: flags.occurrenceId }),
82
129
  })),
83
130
  }, command)));
@@ -86,5 +133,5 @@ export const addMeetingManagementCommands = (group, deps) => {
86
133
  effects: REMOTE_READ,
87
134
  offline: false,
88
135
  output: { entity: "meeting_invitation" },
89
- }).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)));
90
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
  });
@@ -11,6 +11,8 @@ export interface MeetingExport {
11
11
  format: MeetingExportFormat;
12
12
  filename: string;
13
13
  content: string;
14
+ /** The content is what people said and wrote. */
15
+ untrusted: string[];
14
16
  }
15
17
  export declare const serializeVtt: (lines: readonly TranscriptLine[]) => string;
16
18
  export declare const exportMeeting: (store: MeetingStore, id: number, options: MeetingExportOptions) => Promise<MeetingExport>;
@@ -93,5 +93,6 @@ export const exportMeeting = async (store, id, options) => {
93
93
  format: options.format,
94
94
  filename: `meeting-${details.meeting.id}${options.transcriptId === undefined ? "" : `-transcript-${options.transcriptId}`}.${options.format === "markdown" ? "md" : "vtt"}`,
95
95
  content,
96
+ untrusted: ["content"],
96
97
  };
97
98
  };
@@ -21,10 +21,10 @@ export { joinKeyOf, joinUrlWithoutQuery } from "./join-key.js";
21
21
  export { transcriptLanguage } from "./language.js";
22
22
  export { CHAT_MESSAGES_READ, type MeetingChatLine, type MeetingChatLinesInput, type MeetingChatLinesStore, type MeetingLink, } from "./links.js";
23
23
  export { createMeetingContext, type MeetingContextAction, type MeetingContextChange, type MeetingContextOperation, type MeetingContextPorts, type MeetingContextReceipt, validateMeetingContextChange, } from "./meeting-context.js";
24
- export { createMeetingManagement, dispatchMeetingMutation, type ManagedMeeting, type ManagedMeetingChange, type MeetingManagement, type MeetingManagementPorts, type MeetingMutationOptions, type MeetingMutationProposal, type MeetingMutationReceipt, type MeetingOperationOptions, type MeetingProviderContext, validateMeetingChange, } from "./meeting-management.js";
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";
@@ -18,9 +18,9 @@ export { joinKeyOf, joinUrlWithoutQuery } from "./join-key.js";
18
18
  export { transcriptLanguage } from "./language.js";
19
19
  export { CHAT_MESSAGES_READ, } from "./links.js";
20
20
  export { createMeetingContext, validateMeetingContextChange, } from "./meeting-context.js";
21
- export { createMeetingManagement, dispatchMeetingMutation, validateMeetingChange, } from "./meeting-management.js";
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
  }
@@ -16,6 +16,42 @@ export interface ManagedMeetingChange {
16
16
  durationMinutes?: number;
17
17
  timezone?: string;
18
18
  agenda?: string;
19
+ /** The service's own settings by their declared names (`MeetingSetting`). */
20
+ settings?: Readonly<Record<string, string | boolean>>;
21
+ }
22
+ /** A field every meetings service may take; each port declares the ones its service reads. */
23
+ export type MeetingField = "title" | "kind" | "startTime" | "durationMinutes" | "timezone" | "agenda";
24
+ /** Each field's key in an answer; its option is the key with dashes, `--start-time`. */
25
+ export declare const MEETING_FIELD_KEYS: Readonly<Record<MeetingField, string>>;
26
+ export declare const MEETING_FIELDS: readonly MeetingField[];
27
+ export declare const meetingFieldFlag: (field: MeetingField) => string;
28
+ /** A setting only this service has, given as `--setting <name>=<value>`; the name is snake_case. */
29
+ export type MeetingSetting = {
30
+ name: string;
31
+ description: string;
32
+ type: "choice";
33
+ values: readonly string[];
34
+ } | {
35
+ name: string;
36
+ description: string;
37
+ type: "boolean";
38
+ }
39
+ /** Blank text is refused unless `clearable`: then `""` clears the setting on the service. */
40
+ | {
41
+ name: string;
42
+ description: string;
43
+ type: "text";
44
+ clearable?: boolean;
45
+ };
46
+ /** What one write port reads. A port that declares nothing reads every `MEETING_FIELDS` entry and no setting. */
47
+ export interface MeetingFields {
48
+ fields?: readonly MeetingField[];
49
+ settings?: readonly MeetingSetting[];
50
+ }
51
+ /** A declaration with its defaults filled in, as `createMeetingManagement` exposes it. */
52
+ export interface DeclaredMeetingFields {
53
+ readonly fields: readonly MeetingField[];
54
+ readonly settings: readonly MeetingSetting[];
19
55
  }
20
56
  export interface MeetingOperationOptions {
21
57
  signal?: AbortSignal;
@@ -24,6 +60,8 @@ export interface MeetingMutationOptions extends MeetingOperationOptions {
24
60
  apply?: boolean;
25
61
  dryRun?: boolean;
26
62
  occurrenceId?: string;
63
+ /** Runs after the change is validated and before it is dispatched, only when it will be: the owner's question. */
64
+ confirm?: () => Promise<void>;
27
65
  }
28
66
  export interface MeetingProviderContext extends MeetingOperationOptions {
29
67
  readonly scope: Readonly<MeetingProviderScope>;
@@ -40,6 +78,11 @@ export interface MeetingManagementPorts {
40
78
  cancel?(id: string, context: MeetingProviderContext & {
41
79
  occurrenceId?: string;
42
80
  }): Promise<void>;
81
+ /** What `create` and `update` read; see `MeetingFields`. */
82
+ fields?: {
83
+ create?: MeetingFields;
84
+ update?: MeetingFields;
85
+ };
43
86
  }
44
87
  export interface MeetingMutationProposal {
45
88
  action: "create" | "update" | "cancel";
@@ -52,15 +95,37 @@ export interface MeetingMutationReceipt extends MeetingMutationProposal {
52
95
  applied: boolean;
53
96
  meeting?: ManagedMeeting;
54
97
  }
55
- /** Returns a detached, canonical change; provider-specific extensions stay in adapters. */
56
- export declare const validateMeetingChange: (change: ManagedMeetingChange, create: boolean) => Readonly<ManagedMeetingChange>;
98
+ export declare const SNAKE_CASE: RegExp;
99
+ /**
100
+ * Checks a port's declaration once, when the management is made: a bad one is the host's mistake, not the owner's.
101
+ * A create that declares `kind` without `startTime` could never schedule, so it is refused.
102
+ */
103
+ export declare const declareMeetingFields: (declared?: MeetingFields, action?: "create" | "update") => DeclaredMeetingFields;
104
+ export interface MeetingChangeRules {
105
+ /** What the port reads; `declareMeetingFields()` (every portable field, no setting) when absent. */
106
+ declared?: DeclaredMeetingFields;
107
+ }
108
+ /**
109
+ * Returns a detached, canonical change with only what the port declared; a create always carries `kind`. A service
110
+ * that cannot schedule (no `startTime` declared) only makes meetings that start now. One that can needs a start or
111
+ * an explicit `kind: "instant"`: over MCP an agent is not asked first, so a forgotten start must be an error, not a
112
+ * live meeting. An instant create gets its `startTime` when it is dispatched (`createMeetingManagement`).
113
+ */
114
+ export declare const validateMeetingChange: (change: ManagedMeetingChange, create: boolean, rules?: MeetingChangeRules) => Readonly<ManagedMeetingChange>;
57
115
  /** Dispatches at most once. An adapter owns acknowledgement and uncertain-outcome errors. */
58
116
  export declare const dispatchMeetingMutation: <T>(options: MeetingMutationOptions, dispatch: (signal?: AbortSignal) => Promise<T>) => Promise<{
59
117
  applied: boolean;
60
118
  value?: T;
61
119
  }>;
62
- export declare const createMeetingManagement: (scope: MeetingProviderScope, ports: MeetingManagementPorts) => {
120
+ export declare const createMeetingManagement: (scope: MeetingProviderScope, ports: MeetingManagementPorts, options?: {
121
+ now?: () => number;
122
+ }) => {
63
123
  scope: Readonly<MeetingProviderScope>;
124
+ /** What `create` and `update` take, with the defaults filled in. */
125
+ fields: Readonly<{
126
+ create: DeclaredMeetingFields;
127
+ update: DeclaredMeetingFields;
128
+ }>;
64
129
  capabilities: readonly string[];
65
130
  list(options?: MeetingOperationOptions): Promise<ManagedMeeting[]>;
66
131
  get(id: string, options?: MeetingOperationOptions): Promise<ManagedMeeting>;
@@ -1,23 +1,115 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { snapshotMeetingScope } from "./provider.js";
3
3
  import { meetingTimestamp } from "./timestamp.js";
4
+ /** Each field's key in an answer; its option is the key with dashes, `--start-time`. */
5
+ export const MEETING_FIELD_KEYS = Object.freeze({
6
+ title: "title",
7
+ kind: "kind",
8
+ startTime: "start_time",
9
+ durationMinutes: "duration_minutes",
10
+ timezone: "timezone",
11
+ agenda: "agenda",
12
+ });
13
+ export const MEETING_FIELDS = Object.freeze(Object.keys(MEETING_FIELD_KEYS));
14
+ export const meetingFieldFlag = (field) => `--${MEETING_FIELD_KEYS[field].replaceAll("_", "-")}`;
4
15
  const nonempty = (value, name) => {
5
16
  if (typeof value !== "string" || !value.trim())
6
17
  throw new CliError("validation_error", `${name} must be nonempty`);
7
18
  return value;
8
19
  };
9
- /** Returns a detached, canonical change; provider-specific extensions stay in adapters. */
10
- export const validateMeetingChange = (change, create) => {
11
- if (!change ||
12
- typeof change !== "object" ||
13
- Array.isArray(change) ||
14
- Object.keys(change).some((key) => !["title", "kind", "startTime", "durationMinutes", "timezone", "agenda"].includes(key)))
15
- throw new CliError("validation_error", "unsupported meeting change field");
20
+ export const SNAKE_CASE = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/;
21
+ const isField = (key) => Object.hasOwn(MEETING_FIELD_KEYS, key);
22
+ /**
23
+ * Checks a port's declaration once, when the management is made: a bad one is the host's mistake, not the owner's.
24
+ * A create that declares `kind` without `startTime` could never schedule, so it is refused.
25
+ */
26
+ export const declareMeetingFields = (declared = {}, action = "create") => {
27
+ const wrong = (why) => new CliError("configuration_error", `meeting fields: ${why}`);
28
+ const fields = declared.fields ?? MEETING_FIELDS;
29
+ for (const field of fields)
30
+ if (!isField(String(field)))
31
+ throw wrong(`unknown field ${String(field)}`);
32
+ if (action === "create" && fields.includes("kind") && !fields.includes("startTime"))
33
+ throw wrong("create declares kind without startTime, so a scheduled meeting could never get its start");
34
+ const names = new Set();
35
+ const settings = (declared.settings ?? []).map((setting) => {
36
+ const name = setting?.name;
37
+ if (typeof name !== "string" || !SNAKE_CASE.test(name))
38
+ throw wrong(`setting name ${String(name)} is not snake_case`);
39
+ if (names.has(name))
40
+ throw wrong(`setting ${name} is declared twice`);
41
+ names.add(name);
42
+ if (typeof setting.description !== "string" || !setting.description.trim())
43
+ throw wrong(`setting ${name} has no description`);
44
+ if (setting.type === "choice") {
45
+ const values = setting.values;
46
+ if (!Array.isArray(values) || !values.length || values.some((value) => typeof value !== "string" || !value))
47
+ throw wrong(`setting ${name} lists no values`);
48
+ return Object.freeze({ ...setting, values: Object.freeze([...new Set(values)]) });
49
+ }
50
+ if (setting.type !== "boolean" && setting.type !== "text")
51
+ throw wrong(`setting ${name} has an unknown type`);
52
+ return Object.freeze({ ...setting });
53
+ });
54
+ return Object.freeze({ fields: Object.freeze([...new Set(fields)]), settings: Object.freeze(settings) });
55
+ };
56
+ const settingNamed = (declared, name) => declared.settings.find((setting) => setting.name === name);
57
+ const supportedList = (declared) => {
58
+ const all = [
59
+ ...declared.fields.map(meetingFieldFlag),
60
+ ...declared.settings.map((setting) => `--setting ${setting.name}`),
61
+ ];
62
+ return all.length ? all.join(", ") : "nothing";
63
+ };
64
+ const settingValue = (setting, value) => {
65
+ const refuse = (expected) => new CliError("validation_error", `meeting setting ${setting.name} must be ${expected}`);
66
+ if (setting.type === "boolean") {
67
+ if (typeof value === "boolean")
68
+ return value;
69
+ if (value === "true" || value === "false")
70
+ return value === "true";
71
+ throw refuse("true or false");
72
+ }
73
+ if (typeof value !== "string")
74
+ throw refuse(setting.type === "choice" ? setting.values.join(", ") : "text");
75
+ if (setting.type === "choice" && !setting.values.includes(value))
76
+ throw refuse(`one of ${setting.values.join(", ")}`);
77
+ if (setting.type === "text" && !value.trim()) {
78
+ if (!setting.clearable)
79
+ throw refuse("nonempty text: this service cannot clear it");
80
+ return "";
81
+ }
82
+ return value;
83
+ };
84
+ /**
85
+ * Returns a detached, canonical change with only what the port declared; a create always carries `kind`. A service
86
+ * that cannot schedule (no `startTime` declared) only makes meetings that start now. One that can needs a start or
87
+ * an explicit `kind: "instant"`: over MCP an agent is not asked first, so a forgotten start must be an error, not a
88
+ * live meeting. An instant create gets its `startTime` when it is dispatched (`createMeetingManagement`).
89
+ */
90
+ export const validateMeetingChange = (change, create, rules = {}) => {
91
+ const declared = rules.declared ?? declareMeetingFields();
92
+ const action = create ? "create" : "update";
93
+ if (!change || typeof change !== "object" || Array.isArray(change))
94
+ throw new CliError("validation_error", "a meeting change must be an object");
95
+ const undeclared = Object.keys(change).flatMap((key) => change[key] === undefined || key === "settings"
96
+ ? []
97
+ : isField(key)
98
+ ? declared.fields.includes(key)
99
+ ? []
100
+ : [meetingFieldFlag(key)]
101
+ : [key]);
102
+ const given = change.settings ?? {};
103
+ if (typeof given !== "object" || Array.isArray(given) || given === null)
104
+ throw new CliError("validation_error", "meeting settings must be an object of name and value");
105
+ for (const name of Object.keys(given))
106
+ if (!settingNamed(declared, name))
107
+ undeclared.push(`--setting ${name}`);
108
+ if (undeclared.length)
109
+ throw new CliError("validation_error", `this service does not take ${undeclared.join(", ")} on ${action}; it takes ${supportedList(declared)}`);
16
110
  const result = {};
17
111
  if (change.title !== undefined)
18
112
  result.title = nonempty(change.title, "meeting title");
19
- if (create && result.title === undefined)
20
- throw new CliError("validation_error", "meeting title is required");
21
113
  if (change.kind !== undefined) {
22
114
  if (change.kind !== "instant" && change.kind !== "scheduled")
23
115
  throw new CliError("validation_error", "only instant or scheduled meeting kinds are supported");
@@ -47,10 +139,18 @@ export const validateMeetingChange = (change, create) => {
47
139
  throw new CliError("validation_error", "meeting agenda must be text");
48
140
  result.agenda = change.agenda;
49
141
  }
142
+ const settings = Object.entries(given).map(([name, value]) => [name, settingValue(settingNamed(declared, name), value)]);
143
+ if (settings.length)
144
+ result.settings = Object.freeze(Object.fromEntries(settings));
50
145
  if (create) {
51
- result.kind ??= "scheduled";
146
+ const schedules = declared.fields.includes("startTime");
147
+ result.kind ??= result.startTime !== undefined ? "scheduled" : schedules ? undefined : "instant";
148
+ if (result.kind === undefined)
149
+ throw new CliError("validation_error", declared.fields.includes("kind")
150
+ ? "give --start-time, or --kind instant for a meeting that starts now"
151
+ : "give --start-time: this service has no meeting that starts now");
52
152
  if (result.kind === "scheduled" && result.startTime === undefined)
53
- throw new CliError("validation_error", "scheduled meeting start is required");
153
+ throw new CliError("validation_error", "a scheduled meeting needs --start-time");
54
154
  }
55
155
  else if (!Object.keys(result).length)
56
156
  throw new CliError("validation_error", "at least one meeting change is required");
@@ -66,14 +166,23 @@ const checkCancelled = (signal) => {
66
166
  };
67
167
  /** Dispatches at most once. An adapter owns acknowledgement and uncertain-outcome errors. */
68
168
  export const dispatchMeetingMutation = async (options, dispatch) => {
69
- const { apply, dryRun, signal } = options;
169
+ const { apply, dryRun, signal, confirm } = options;
70
170
  checkCancelled(signal);
71
171
  if (apply !== true || dryRun)
72
172
  return { applied: false };
173
+ if (confirm) {
174
+ await confirm();
175
+ checkCancelled(signal);
176
+ }
73
177
  return { applied: true, value: await dispatch(signal) };
74
178
  };
75
- export const createMeetingManagement = (scope, ports) => {
179
+ export const createMeetingManagement = (scope, ports, options = {}) => {
76
180
  const fixed = snapshotMeetingScope(scope);
181
+ const fields = Object.freeze({
182
+ create: declareMeetingFields(ports.fields?.create, "create"),
183
+ update: declareMeetingFields(ports.fields?.update, "update"),
184
+ });
185
+ const now = options.now ?? Date.now;
77
186
  const capabilities = {};
78
187
  for (const name of ["list", "get", "invitation", "create", "update", "cancel"]) {
79
188
  const port = ports[name];
@@ -94,6 +203,8 @@ export const createMeetingManagement = (scope, ports) => {
94
203
  };
95
204
  return {
96
205
  scope: fixed,
206
+ /** What `create` and `update` take, with the defaults filled in. */
207
+ fields,
97
208
  capabilities: Object.freeze(Object.keys(capabilities).filter((name) => typeof capabilities[name] === "function")),
98
209
  list(options = {}) {
99
210
  return capability("list")(context(options));
@@ -106,13 +217,19 @@ export const createMeetingManagement = (scope, ports) => {
106
217
  },
107
218
  async create(change, options = {}) {
108
219
  const port = capability("create");
109
- const validated = validateMeetingChange(change, true);
220
+ const validated = validateMeetingChange(change, true, { declared: fields.create });
110
221
  const ctx = context(options);
111
- const outcome = await dispatchMeetingMutation(options, () => port(validated, ctx));
222
+ let sent = validated;
223
+ // "Now" is when it goes, after the owner's question, not when the command started.
224
+ const outcome = await dispatchMeetingMutation(options, () => {
225
+ if (sent.startTime === undefined)
226
+ sent = Object.freeze({ ...validated, startTime: new Date(now()).toISOString() });
227
+ return port(sent, ctx);
228
+ });
112
229
  return {
113
230
  action: "create",
114
231
  scope: fixed,
115
- change: validated,
232
+ change: sent,
116
233
  applied: outcome.applied,
117
234
  ...(outcome.value ? { meeting: outcome.value } : {}),
118
235
  };
@@ -120,7 +237,7 @@ export const createMeetingManagement = (scope, ports) => {
120
237
  async update(id, change, options = {}) {
121
238
  const port = capability("update");
122
239
  const validatedId = nonempty(id, "meeting id");
123
- const validated = validateMeetingChange(change, false);
240
+ const validated = validateMeetingChange(change, false, { declared: fields.update });
124
241
  const ctx = context(options);
125
242
  const outcome = await dispatchMeetingMutation(options, () => port(validatedId, validated, ctx));
126
243
  return { action: "update", scope: fixed, id: validatedId, change: validated, applied: outcome.applied };
@@ -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" ||
@@ -128,6 +128,7 @@ export declare const meetingParticipants: v.StrictObjectSchema<{
128
128
  readonly ref: v.StringSchema<undefined>;
129
129
  readonly name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
130
130
  }, undefined>, undefined>;
131
+ readonly untrusted: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
131
132
  }, undefined>, undefined>;
132
133
  /** Several identities on one page are observations, never speaker attribution or person links. */
133
134
  readonly ambiguity: v.StrictObjectSchema<{
@@ -189,6 +190,8 @@ export declare const meetingPassage: v.StrictObjectSchema<{
189
190
  readonly speaker_name: v.NullableSchema<v.StringSchema<undefined>, undefined>;
190
191
  readonly text: v.StringSchema<undefined>;
191
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>;
192
195
  }, undefined>, undefined>;
193
196
  }, undefined>;
194
197
  /** A stored event a meeting belongs to; `id` is what `meetings update --event-id` takes. */