@wirecat/cli-core 0.621.0 → 0.623.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 (56) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/background/budget.d.ts +2 -0
  3. package/dist/background/daily-archive-timer.d.ts +1 -1
  4. package/dist/background/schedules.d.ts +2 -9
  5. package/dist/background/schedules.js +10 -15
  6. package/dist/background/when.d.ts +28 -0
  7. package/dist/background/when.js +40 -0
  8. package/dist/calendar/mcp/index.d.ts +12 -12
  9. package/dist/cli/command-server-argv.d.ts +7 -0
  10. package/dist/cli/command-server-argv.js +7 -0
  11. package/dist/cli/command-server-entry.d.ts +12 -0
  12. package/dist/cli/command-server-entry.js +122 -0
  13. package/dist/cli/command-server.d.ts +29 -0
  14. package/dist/cli/command-server.js +100 -0
  15. package/dist/cli/entry.d.ts +2 -0
  16. package/dist/cli/entry.js +24 -18
  17. package/dist/cli/messenger/messages-search-command.js +4 -0
  18. package/dist/cli/program.js +8 -3
  19. package/dist/cli/schedule/schedule-command.js +14 -8
  20. package/dist/domain/display-names.d.ts +16 -0
  21. package/dist/domain/display-names.js +50 -0
  22. package/dist/errors/reasons.js +1 -0
  23. package/dist/index.d.ts +1 -0
  24. package/dist/index.js +1 -0
  25. package/dist/meetings/mcp/index.d.ts +15 -15
  26. package/dist/search/lucene/resolved.d.ts +1 -0
  27. package/dist/search/lucene/types.d.ts +8 -0
  28. package/dist/search/lucene/types.js +7 -0
  29. package/dist/services/messages-combined.js +3 -2
  30. package/dist/services/messages-discovery.js +3 -2
  31. package/dist/services/messages-search.js +1 -0
  32. package/dist/services/messages.d.ts +2 -0
  33. package/dist/services/people.js +1 -1
  34. package/dist/store/driver.d.ts +5 -1
  35. package/dist/store/driver.js +5 -0
  36. package/dist/store/identity-links.d.ts +3 -3
  37. package/dist/store/identity-links.js +3 -3
  38. package/dist/store/index.d.ts +2 -0
  39. package/dist/store/index.js +1 -0
  40. package/dist/store/people.d.ts +21 -2
  41. package/dist/store/people.js +35 -15
  42. package/dist/store/sqlite/lucene.js +12 -11
  43. package/dist/store/sqlite/manifest.js +1 -0
  44. package/dist/store/sqlite/migrations.generated.js +7 -0
  45. package/dist/store/sqlite/name-traces.d.ts +17 -0
  46. package/dist/store/sqlite/name-traces.js +112 -0
  47. package/dist/store/sqlite/notes.js +6 -3
  48. package/dist/store/sqlite/people-list.d.ts +44 -0
  49. package/dist/store/sqlite/people-list.js +151 -0
  50. package/dist/store/sqlite/person-match-scan.js +33 -0
  51. package/dist/store/sqlite/person-ties.d.ts +14 -0
  52. package/dist/store/sqlite/person-ties.js +66 -0
  53. package/dist/store/sqlite/ref-accounts.js +6 -3
  54. package/dist/store/sqlite/schema.d.ts +16 -0
  55. package/dist/store/sqlite/schema.js +3 -0
  56. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,66 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
5
5
  minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
6
6
  shape of this file.
7
7
 
8
+ ## 0.623.0 — 09.11.2026
9
+
10
+ ### Added
11
+
12
+ - `store.people.list({ query, all, sort, limit, offset })`: people a page at a time, with `total` and `hidden`, each
13
+ with a cleaned `displayName` (no wrapping quotes or spaces; a name with no letter or digit shows the username, phone
14
+ or email), the first username, phone and email, and `ties`. By default it lists only people with a tie to the
15
+ owner: a one-to-one chat, a group of at most 10 (`SMALL_GROUP_MEMBERS`; a group of unknown size counts as large),
16
+ mail the owner wrote to them, a meeting or calendar entry, a CRM, or the address book. The owner, people added by
17
+ hand and anyone assigned a task are always listed; `all` adds the rest. Ties are read on every call; on a synthetic
18
+ store of 51,000 identities a first page takes about 100 ms
19
+ ([cli-testing `performance/people/ties`](https://github.com/WireCatLabs/cli-testing/tree/main/performance/people/ties)).
20
+ - `store.people.similar(name, { limit })`: people whose name has a word starting with each typed word, in any order,
21
+ the same name first (`sameName`), for a form that adds a person.
22
+ - `store.people.saveAddressBook`: `contacts sync` now marks who is in the account's address book, and unmarks who left
23
+ it (`account_identities.address_book`, store version 61). Sync contacts once after upgrading: until then nobody has
24
+ the address-book tie.
25
+ - The people matcher proposes two people with one name (case, quotes, punctuation and word order set aside) who share
26
+ a phone, an address, a chat or a company's mail domain, as an `identity_link` with signal `name`. It never joins
27
+ them; a free mailbox's domain (gmail.com) or a role address (`info@`) is no trace, and a name more than six people
28
+ have is skipped.
29
+ - `store.people.ties(refs)`: why each person is shown, as the list gives it.
30
+ - `displayName` and `nameKey` from the package root.
31
+ - `schedule … --at 'mon 09:00'`: a weekday before the time makes a weekly run (systemd
32
+ `OnCalendar=Mon *-*-* 09:00:00`, launchd `Weekday`, Task Scheduler's weekly trigger). With `--every` it is refused.
33
+ - **`search messages --timeout 30s` may search for up to about 29 seconds.** A search stopped at 2 seconds whatever
34
+ time its caller gave the run, so a valid query over a large store failed in WireCat Desktop. With an explicit
35
+ `--timeout` (or `<PREFIX>_TIMEOUT`) the search uses that time less a second to answer; the error's `limit_ms` names
36
+ the limit that applied. Without one it stays 2 seconds, for agents and MCP too.
37
+
38
+ ### Changed — may break callers
39
+
40
+ - `IDENTITY_LINK_SIGNALS` gains `name`, and a schedule's `When` gains `{ weekly, on }`: code that switches over every
41
+ signal or every `When` needs the new case. `AccountPeople` and `PeopleStore` gain `saveAddressBook`, `list`,
42
+ `similar` and `ties`, so a hand-written fake of either needs them.
43
+
44
+ ### Fixed
45
+
46
+ - **A file's link that a program guessed waits for review again.** Since 0.621.0 every unconfirmed relationship a
47
+ file wrote became reported by the file's account, a guess (`provenance: "scan"`) included. Only a link whose
48
+ provenance names the file's own source, such as Drive's owner and last editor (`google-drive:files.get`), is
49
+ reported now.
50
+
51
+ ## 0.622.0 — 09.11.2026
52
+
53
+ ### Added
54
+
55
+ - `<cli> commands --serve`, in every CLI that starts through `startCli`: one long-running process that runs command
56
+ after command, so WireCat Desktop no longer starts Node for each read on a page. One JSON request per line on stdin
57
+ (`{"id","argv"}`), one answer per line on stdout (`{"id","code","stdout","stderr"}`, what a spawned run would have
58
+ printed). Requests run one at a time; each is recorded as its own run, reads settings and keys again and leaves the
59
+ store closed. A command that runs until stopped, waits on a person or reads stdin is refused with code 2. The
60
+ server ends when stdin closes or after 10 minutes without a request. It is in no help, `commands --json` or MCP.
61
+
62
+ ### Fixed
63
+
64
+ - The store's write-ahead file (`wirecat.db-wal`) no longer stays at the size of the biggest write it ever held: every
65
+ connection sets a 64 MiB journal size limit, so SQLite cuts the file back after a checkpoint. One large CRM sync had
66
+ left a 2.2 GB file behind.
67
+
8
68
  ## 0.621.0 — 09.11.2026
9
69
 
10
70
  ### Added
@@ -4,6 +4,8 @@ export type BudgetStop = "requests" | "deadline" | "cancelled";
4
4
  export interface Deadline {
5
5
  endsAt: number;
6
6
  ms: number;
7
+ /** A person or a script set it (`--timeout`, `<PREFIX>_TIMEOUT`), not the command's default. */
8
+ explicit?: true;
7
9
  }
8
10
  /**
9
11
  * A sync asks it before each request to the source, so the run stops on its own, saves where it is, and says
@@ -24,12 +24,12 @@ export interface DailyArchiveTimerInput {
24
24
  }
25
25
  export declare const dailyArchiveTimer: (input: DailyArchiveTimerInput) => DailyArchiveTimer;
26
26
  export declare const manageDailyArchiveTimer: (plan: DailyArchiveTimer, action: "install" | "start" | "stop" | "status" | "uninstall", system: Pick<ServerSystem, "platform" | "run">, env: NodeJS.ProcessEnv, signal?: AbortSignal) => Promise<{
27
+ action?: undefined;
27
28
  name: string;
28
29
  installed: boolean;
29
30
  active: boolean;
30
31
  servicePath: string;
31
32
  timerPath: string;
32
- action?: undefined;
33
33
  } | {
34
34
  active?: undefined;
35
35
  name: string;
@@ -2,14 +2,8 @@ import { type AppIdentity } from "../ports/app.js";
2
2
  import { type Delivery } from "./deliver.js";
3
3
  import { type ReportRun, type StoredTemplates } from "./report/render.js";
4
4
  import type { ServerSystem } from "./system.js";
5
- /** Minutes between runs, a daily local time, or one local moment. */
6
- export type When = {
7
- every: number;
8
- } | {
9
- daily: string;
10
- } | {
11
- once: string;
12
- };
5
+ import { type When } from "./when.js";
6
+ export { describeWhen, WEEKDAYS, type Weekday, type When } from "./when.js";
13
7
  export interface Schedule {
14
8
  name: string;
15
9
  kind: "command" | "agent";
@@ -144,7 +138,6 @@ export declare const scheduledRuns: (state: string) => {
144
138
  last: LastRun | undefined;
145
139
  }[];
146
140
  export declare const listSchedules: (state: string, filter?: Partial<Pick<Schedule, "name" | "kind">>) => Schedule[];
147
- export declare const describeWhen: (when: When) => string;
148
141
  /** How one operating system starts `argv` at the schedule's times. Every timer runs the same thing: `<cli> schedule exec <file>`. */
149
142
  export interface Timer {
150
143
  install: (schedule: Schedule, argv: string[]) => Promise<void>;
@@ -12,6 +12,8 @@ import { readSharedSection, sharedConfigPath } from "../store/shared-config.js";
12
12
  import { deliver } from "./deliver.js";
13
13
  import { causeOf, gapsView, noticeView, weeklyGapsOf } from "./report/messages.js";
14
14
  import { prepareMessage, prepareReport, } from "./report/render.js";
15
+ import { clockOf, describeWhen, localStamp, onCalendar, WEEKDAYS, WINDOWS_DAYS } from "./when.js";
16
+ export { describeWhen, WEEKDAYS } from "./when.js";
15
17
  export const NOTIFY_WHEN = ["always", "failures", "never"];
16
18
  /** A repeating agent would otherwise notify on every tick; any other schedule runs rarely enough to say each result. */
17
19
  export const notifyOf = (schedule) => schedule.notify ?? (schedule.kind === "agent" && "every" in schedule.when ? "failures" : "always");
@@ -186,17 +188,6 @@ export const listSchedules = (state, filter = {}) => existsSync(schedulesDir(sta
186
188
  (filter.kind === undefined || schedule.kind === filter.kind))
187
189
  .sort((a, b) => a.name.localeCompare(b.name))
188
190
  : [];
189
- export const describeWhen = (when) => "every" in when
190
- ? `every ${when.every % 1440 === 0 ? `${when.every / 1440}d` : when.every % 60 === 0 ? `${when.every / 60}h` : `${when.every}m`}`
191
- : "daily" in when
192
- ? `daily at ${when.daily}`
193
- : `once at ${when.once}`;
194
- /** A local wall-clock time, as both systemd's `OnCalendar=` and PowerShell's parser take it. */
195
- const localStamp = (iso) => {
196
- const at = new Date(iso);
197
- const two = (n) => String(n).padStart(2, "0");
198
- return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}:${two(at.getSeconds())}`;
199
- };
200
191
  const systemdQuote = (value) => `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"').replaceAll("%", "%%").replaceAll("$", "$$$$")}"`;
201
192
  const xml = (value) => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
202
193
  const checked = async (system, env, argv, allowFailure = false) => {
@@ -231,7 +222,7 @@ export const systemdTimer = (app, system, env, home) => {
231
222
  ? // From when a run ends: counted from its start, a run longer than the interval left no next run.
232
223
  [`OnActiveSec=${when.every}min`, `OnUnitInactiveSec=${when.every}min`]
233
224
  : // Persistent: a run missed while the machine slept happens when it wakes.
234
- [`OnCalendar=${"daily" in when ? `*-*-* ${when.daily}:00` : localStamp(when.once)}`, "Persistent=true"]),
225
+ [`OnCalendar=${onCalendar(when)}`, "Persistent=true"]),
235
226
  "",
236
227
  "[Install]",
237
228
  "WantedBy=timers.target",
@@ -256,7 +247,7 @@ export const launchdTimer = (app, system, env, home) => {
256
247
  const calendar = (when) => {
257
248
  if ("every" in when)
258
249
  return [` <key>StartInterval</key><integer>${when.every * 60}</integer>`];
259
- const [hour, minute] = ("daily" in when ? when.daily : localStamp(when.once).slice(11, 16)).split(":").map(Number);
250
+ const [hour, minute] = ("once" in when ? localStamp(when.once).slice(11, 16) : clockOf(when)).split(":").map(Number);
260
251
  const once = "once" in when ? new Date(when.once) : undefined;
261
252
  return [
262
253
  " <key>StartCalendarInterval</key>",
@@ -268,6 +259,8 @@ export const launchdTimer = (app, system, env, home) => {
268
259
  ` <key>Day</key><integer>${once.getDate()}</integer>`,
269
260
  ]
270
261
  : []),
262
+ // launchd counts Sunday as 0.
263
+ ...("weekly" in when ? [` <key>Weekday</key><integer>${(WEEKDAYS.indexOf(when.on) + 1) % 7}</integer>`] : []),
271
264
  ` <key>Hour</key><integer>${hour}</integer>`,
272
265
  ` <key>Minute</key><integer>${minute}</integer>`,
273
266
  " </dict>",
@@ -318,6 +311,7 @@ export const windowsTimer = (app, system, env) => {
318
311
  "$trigger = switch ($env:WIRECAT_KIND) {",
319
312
  " 'every' { New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes ([int]$env:WIRECAT_MINUTES)) }",
320
313
  " 'daily' { New-ScheduledTaskTrigger -Daily -At $env:WIRECAT_AT }",
314
+ " 'weekly' { New-ScheduledTaskTrigger -Weekly -DaysOfWeek $env:WIRECAT_DAY -At $env:WIRECAT_AT }",
321
315
  " 'once' { New-ScheduledTaskTrigger -Once -At ([datetime]::ParseExact($env:WIRECAT_AT, 'yyyy-MM-dd HH:mm:ss', $null)) }",
322
316
  "}",
323
317
  "$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -MultipleInstances IgnoreNew",
@@ -325,9 +319,10 @@ export const windowsTimer = (app, system, env) => {
325
319
  ].join("\n"), {
326
320
  WIRECAT_EXE: exe,
327
321
  WIRECAT_ARGS: args.map((word) => `"${word.replaceAll('"', '\\"')}"`).join(" "),
328
- WIRECAT_KIND: "every" in when ? "every" : "daily" in when ? "daily" : "once",
322
+ WIRECAT_KIND: "every" in when ? "every" : "daily" in when ? "daily" : "weekly" in when ? "weekly" : "once",
329
323
  WIRECAT_MINUTES: "every" in when ? String(when.every) : "",
330
- WIRECAT_AT: "daily" in when ? when.daily : "once" in when ? localStamp(when.once) : "",
324
+ WIRECAT_AT: "every" in when ? "" : "once" in when ? localStamp(when.once) : clockOf(when),
325
+ WIRECAT_DAY: "weekly" in when ? WINDOWS_DAYS[when.on] : "",
331
326
  WIRECAT_NAME: schedule.name,
332
327
  WIRECAT_PATH: path,
333
328
  });
@@ -0,0 +1,28 @@
1
+ /** The days `--on` takes, Monday first. */
2
+ export declare const WEEKDAYS: readonly ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
3
+ export type Weekday = (typeof WEEKDAYS)[number];
4
+ /** Minutes between runs, a daily local time, a weekday's local time, or one local moment. */
5
+ export type When = {
6
+ every: number;
7
+ } | {
8
+ daily: string;
9
+ } | {
10
+ weekly: string;
11
+ on: Weekday;
12
+ } | {
13
+ once: string;
14
+ };
15
+ export declare const WINDOWS_DAYS: Record<Weekday, string>;
16
+ /** The local time of a calendar schedule, `HH:MM`. */
17
+ export declare const clockOf: (when: {
18
+ daily: string;
19
+ } | {
20
+ weekly: string;
21
+ on: Weekday;
22
+ }) => string;
23
+ export declare const describeWhen: (when: When) => string;
24
+ export declare const onCalendar: (when: Exclude<When, {
25
+ every: number;
26
+ }>) => string;
27
+ /** A local wall-clock time, as both systemd's `OnCalendar=` and PowerShell's parser take it. */
28
+ export declare const localStamp: (iso: string) => string;
@@ -0,0 +1,40 @@
1
+ /** The days `--on` takes, Monday first. */
2
+ export const WEEKDAYS = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
3
+ const SYSTEMD_DAYS = {
4
+ mon: "Mon",
5
+ tue: "Tue",
6
+ wed: "Wed",
7
+ thu: "Thu",
8
+ fri: "Fri",
9
+ sat: "Sat",
10
+ sun: "Sun",
11
+ };
12
+ export const WINDOWS_DAYS = {
13
+ mon: "Monday",
14
+ tue: "Tuesday",
15
+ wed: "Wednesday",
16
+ thu: "Thursday",
17
+ fri: "Friday",
18
+ sat: "Saturday",
19
+ sun: "Sunday",
20
+ };
21
+ /** The local time of a calendar schedule, `HH:MM`. */
22
+ export const clockOf = (when) => "daily" in when ? when.daily : when.weekly;
23
+ export const describeWhen = (when) => "every" in when
24
+ ? `every ${when.every % 1440 === 0 ? `${when.every / 1440}d` : when.every % 60 === 0 ? `${when.every / 60}h` : `${when.every}m`}`
25
+ : "daily" in when
26
+ ? `daily at ${when.daily}`
27
+ : "weekly" in when
28
+ ? `weekly on ${SYSTEMD_DAYS[when.on]} at ${when.weekly}`
29
+ : `once at ${when.once}`;
30
+ export const onCalendar = (when) => "once" in when
31
+ ? localStamp(when.once)
32
+ : "weekly" in when
33
+ ? `${SYSTEMD_DAYS[when.on]} *-*-* ${when.weekly}:00`
34
+ : `*-*-* ${when.daily}:00`;
35
+ /** A local wall-clock time, as both systemd's `OnCalendar=` and PowerShell's parser take it. */
36
+ export const localStamp = (iso) => {
37
+ const at = new Date(iso);
38
+ const two = (n) => String(n).padStart(2, "0");
39
+ return `${at.getFullYear()}-${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}:${two(at.getSeconds())}`;
40
+ };
@@ -10,13 +10,13 @@ export declare const calendarTools: ({
10
10
  inputSchema: {
11
11
  type: string;
12
12
  properties: {
13
- limit?: undefined;
14
13
  account_id: {
15
14
  type: string;
16
15
  minimum: number;
17
16
  };
18
17
  query?: undefined;
19
18
  timezone?: undefined;
19
+ limit?: undefined;
20
20
  page?: undefined;
21
21
  event?: undefined;
22
22
  } | {
@@ -45,9 +45,9 @@ export declare const calendarTools: ({
45
45
  };
46
46
  event?: undefined;
47
47
  } | {
48
- limit?: undefined;
49
48
  query?: undefined;
50
49
  timezone?: undefined;
50
+ limit?: undefined;
51
51
  page?: undefined;
52
52
  event: {
53
53
  type: string;
@@ -58,9 +58,9 @@ export declare const calendarTools: ({
58
58
  minimum: number;
59
59
  };
60
60
  } | {
61
- limit?: undefined;
62
61
  query?: undefined;
63
62
  timezone?: undefined;
63
+ limit?: undefined;
64
64
  page?: undefined;
65
65
  event?: undefined;
66
66
  account_id?: undefined;
@@ -80,13 +80,13 @@ export declare const calendarTools: ({
80
80
  inputSchema: {
81
81
  type: string;
82
82
  properties: {
83
- limit?: undefined;
84
83
  account_id: {
85
84
  type: string;
86
85
  minimum: number;
87
86
  };
88
87
  query?: undefined;
89
88
  timezone?: undefined;
89
+ limit?: undefined;
90
90
  page?: undefined;
91
91
  event?: undefined;
92
92
  } | {
@@ -115,9 +115,9 @@ export declare const calendarTools: ({
115
115
  };
116
116
  event?: undefined;
117
117
  } | {
118
- limit?: undefined;
119
118
  query?: undefined;
120
119
  timezone?: undefined;
120
+ limit?: undefined;
121
121
  page?: undefined;
122
122
  event: {
123
123
  type: string;
@@ -128,9 +128,9 @@ export declare const calendarTools: ({
128
128
  minimum: number;
129
129
  };
130
130
  } | {
131
- limit?: undefined;
132
131
  query?: undefined;
133
132
  timezone?: undefined;
133
+ limit?: undefined;
134
134
  page?: undefined;
135
135
  event?: undefined;
136
136
  account_id?: undefined;
@@ -150,13 +150,13 @@ export declare const calendarTools: ({
150
150
  inputSchema: {
151
151
  type: string;
152
152
  properties: {
153
- limit?: undefined;
154
153
  account_id: {
155
154
  type: string;
156
155
  minimum: number;
157
156
  };
158
157
  query?: undefined;
159
158
  timezone?: undefined;
159
+ limit?: undefined;
160
160
  page?: undefined;
161
161
  event?: undefined;
162
162
  } | {
@@ -185,9 +185,9 @@ export declare const calendarTools: ({
185
185
  };
186
186
  event?: undefined;
187
187
  } | {
188
- limit?: undefined;
189
188
  query?: undefined;
190
189
  timezone?: undefined;
190
+ limit?: undefined;
191
191
  page?: undefined;
192
192
  event: {
193
193
  type: string;
@@ -198,9 +198,9 @@ export declare const calendarTools: ({
198
198
  minimum: number;
199
199
  };
200
200
  } | {
201
- limit?: undefined;
202
201
  query?: undefined;
203
202
  timezone?: undefined;
203
+ limit?: undefined;
204
204
  page?: undefined;
205
205
  event?: undefined;
206
206
  account_id?: undefined;
@@ -220,13 +220,13 @@ export declare const calendarTools: ({
220
220
  inputSchema: {
221
221
  type: string;
222
222
  properties: {
223
- limit?: undefined;
224
223
  account_id: {
225
224
  type: string;
226
225
  minimum: number;
227
226
  };
228
227
  query?: undefined;
229
228
  timezone?: undefined;
229
+ limit?: undefined;
230
230
  page?: undefined;
231
231
  event?: undefined;
232
232
  } | {
@@ -255,9 +255,9 @@ export declare const calendarTools: ({
255
255
  };
256
256
  event?: undefined;
257
257
  } | {
258
- limit?: undefined;
259
258
  query?: undefined;
260
259
  timezone?: undefined;
260
+ limit?: undefined;
261
261
  page?: undefined;
262
262
  event: {
263
263
  type: string;
@@ -268,9 +268,9 @@ export declare const calendarTools: ({
268
268
  minimum: number;
269
269
  };
270
270
  } | {
271
- limit?: undefined;
272
271
  query?: undefined;
273
272
  timezone?: undefined;
273
+ limit?: undefined;
274
274
  page?: undefined;
275
275
  event?: undefined;
276
276
  account_id?: undefined;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `<cli> commands --serve`: one process that runs command after command for WireCat Desktop, which otherwise pays a
3
+ * whole Node start for each read on a page. Matched before the program loads, so it is in no help, no `commands`
4
+ * document and no MCP catalogue — and a flag, because `commands <path>` already describes every top-level word.
5
+ */
6
+ export declare const COMMAND_SERVER_ARGV: readonly string[];
7
+ export declare const isCommandServer: (args: readonly string[]) => boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `<cli> commands --serve`: one process that runs command after command for WireCat Desktop, which otherwise pays a
3
+ * whole Node start for each read on a page. Matched before the program loads, so it is in no help, no `commands`
4
+ * document and no MCP catalogue — and a flag, because `commands <path>` already describes every top-level word.
5
+ */
6
+ export const COMMAND_SERVER_ARGV = ["commands", "--serve"];
7
+ export const isCommandServer = (args) => args.length === COMMAND_SERVER_ARGV.length && COMMAND_SERVER_ARGV.every((word, at) => args[at] === word);
@@ -0,0 +1,12 @@
1
+ import type { CliEntry, EntryIo, firstRunAt } from "./entry.js";
2
+ /** What `startCli` already has, handed in so the two modules do not import each other. */
3
+ export interface EntryParts {
4
+ firstRunAt: typeof firstRunAt;
5
+ commanderExit: (error: unknown) => number | undefined;
6
+ }
7
+ /**
8
+ * `startCli` for `<cli> commands --serve`: each request runs the CLI's own `run` as a spawned process would, and its
9
+ * output, which the process's streams would have carried, comes back in the answer. Between requests nothing reaches
10
+ * stdout but the protocol; a late write goes to stderr.
11
+ */
12
+ export declare const serveEntry: (entry: CliEntry, io: EntryIo, { firstRunAt, commanderExit }: EntryParts) => Promise<void>;
@@ -0,0 +1,122 @@
1
+ import { PassThrough } from "node:stream";
2
+ import { CliError, catchCrashes } from "@wirecat/cli-base";
3
+ import { useAsProcessRun } from "../runs/scope.js";
4
+ import { ensureSqlite } from "../sqlite-runtime.js";
5
+ import { inCommandServerRequest, refuseInCommandServer, serveCommands } from "./command-server.js";
6
+ /**
7
+ * Every write to the process's stream goes to `sink()`. The stream's `write` is replaced, not the stream: the global
8
+ * console keeps the stream it first wrote to, and `complete` prints through it.
9
+ */
10
+ const route = (stream, sink) => {
11
+ const original = stream.write;
12
+ stream.write = ((chunk, encoding, callback) => {
13
+ sink()(typeof chunk === "string"
14
+ ? Buffer.from(chunk, typeof encoding === "string" ? encoding : "utf8")
15
+ : Buffer.from(chunk));
16
+ const done = typeof encoding === "function" ? encoding : callback;
17
+ if (done)
18
+ process.nextTick(done);
19
+ return true;
20
+ });
21
+ return () => {
22
+ stream.write = original;
23
+ };
24
+ };
25
+ // As a spawned run that Desktop gave no input: anything that reads stdin sees it end at once.
26
+ const closedStdin = () => {
27
+ const stdin = new PassThrough();
28
+ stdin.end();
29
+ return stdin;
30
+ };
31
+ const useStdin = (stdin) => Object.defineProperty(process, "stdin", { value: stdin, configurable: true, enumerable: true, writable: true });
32
+ /**
33
+ * `startCli` for `<cli> commands --serve`: each request runs the CLI's own `run` as a spawned process would, and its
34
+ * output, which the process's streams would have carried, comes back in the answer. Between requests nothing reaches
35
+ * stdout but the protocol; a late write goes to stderr.
36
+ */
37
+ export const serveEntry = async (entry, io, { firstRunAt, commanderExit }) => {
38
+ const release = catchCrashes({
39
+ cli: entry.app.command,
40
+ interactive: false,
41
+ ...(entry.reasons ? { reasons: entry.reasons } : {}),
42
+ target: io.signals,
43
+ });
44
+ const stopper = new AbortController();
45
+ const stop = () => stopper.abort(new CliError("cancelled", "the command server was stopped", { retryable: false }));
46
+ const protocol = io.stdout.write.bind(io.stdout);
47
+ const ownStderr = io.stderr.write.bind(io.stderr);
48
+ const toStderr = (chunk) => {
49
+ ownStderr(chunk);
50
+ };
51
+ let current;
52
+ const unrouteOut = route(process.stdout, () => (current ? (chunk) => current?.stdout.push(chunk) : toStderr));
53
+ const unrouteErr = route(process.stderr, () => (current ? (chunk) => current?.stderr.push(chunk) : toStderr));
54
+ const stdin = Object.getOwnPropertyDescriptor(process, "stdin");
55
+ const requests = io.stdin;
56
+ useStdin(closedStdin());
57
+ io.signals.on("SIGINT", stop).on("SIGTERM", stop);
58
+ io.stdout.on("error", stop);
59
+ const run = async (argv) => {
60
+ const stdout = [];
61
+ const stderr = [];
62
+ current = { stdout, stderr };
63
+ process.exitCode = undefined;
64
+ // Lines written outside a run name the process's run; each request is a process of its own.
65
+ useAsProcessRun(undefined);
66
+ const input = closedStdin();
67
+ useStdin(input);
68
+ const requestIo = { ...io, argv: [...io.argv.slice(0, 2), ...argv], stdin: input };
69
+ const context = {
70
+ args: argv,
71
+ env: io.env,
72
+ tty: false,
73
+ signal: stopper.signal,
74
+ atStart: async (command) => {
75
+ refuseInCommandServer(command, entry.app.command);
76
+ await firstRunAt(entry, requestIo, () => true)(command);
77
+ },
78
+ ask: async () => false,
79
+ openBrowser: async () => undefined,
80
+ outputClosed: () => false,
81
+ };
82
+ let code;
83
+ try {
84
+ code = await inCommandServerRequest(async () => {
85
+ try {
86
+ const returned = await entry.run(context);
87
+ return typeof returned === "number" ? returned : Number(process.exitCode ?? 0);
88
+ }
89
+ catch (error) {
90
+ return commanderExit(error) ?? entry.fail(error, context);
91
+ }
92
+ });
93
+ }
94
+ finally {
95
+ current = undefined;
96
+ process.exitCode = undefined;
97
+ }
98
+ return { code, stdout: Buffer.concat(stdout).toString("utf8"), stderr: Buffer.concat(stderr).toString("utf8") };
99
+ };
100
+ try {
101
+ if (entry.sqlite)
102
+ await ensureSqlite();
103
+ await serveCommands({
104
+ input: requests,
105
+ write: (line) => new Promise((resolve) => (protocol(line) ? resolve() : io.stdout.once("drain", resolve))),
106
+ run,
107
+ cli: entry.app.command,
108
+ version: entry.app.version,
109
+ signal: stopper.signal,
110
+ });
111
+ io.setExitCode(0);
112
+ }
113
+ finally {
114
+ io.signals.off("SIGINT", stop).off("SIGTERM", stop);
115
+ unrouteOut();
116
+ unrouteErr();
117
+ if (stdin)
118
+ Object.defineProperty(process, "stdin", stdin);
119
+ requests.destroy?.();
120
+ release();
121
+ }
122
+ };
@@ -0,0 +1,29 @@
1
+ import type { Command } from "commander";
2
+ export declare const COMMAND_SERVER_PROTOCOL = 1;
3
+ /** An updated tool's old code must not answer for long. */
4
+ export declare const COMMAND_SERVER_IDLE_MS: number;
5
+ export declare const inCommandServerRequest: <T>(work: () => T) => T;
6
+ /** A command the server cannot answer like a spawned run: one that never returns, waits on a person, or reads stdin. */
7
+ export declare const refuseInCommandServer: (command: Command, cli: string) => void;
8
+ export interface CommandAnswer {
9
+ code: number;
10
+ stdout: string;
11
+ stderr: string;
12
+ }
13
+ export interface ServeOptions {
14
+ input: NodeJS.ReadableStream;
15
+ /** One protocol line, the newline included; resolves once it may be written again. */
16
+ write: (line: string) => Promise<void>;
17
+ run: (argv: string[]) => Promise<CommandAnswer>;
18
+ cli: string;
19
+ version: string;
20
+ idleMs?: number;
21
+ /** Ends the server after the request under way. */
22
+ signal?: AbortSignal;
23
+ }
24
+ /**
25
+ * Says it is ready, then answers each line of `input` in order, one at a time: two runs at once in one process would
26
+ * open the store twice, and closing either descriptor drops the other's locks (BUG-557). Resolves with 0 when the
27
+ * input ends or nothing came for `idleMs`.
28
+ */
29
+ export declare const serveCommands: ({ input, write, run, cli, version, idleMs, signal, }: ServeOptions) => Promise<number>;