@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.
- package/CHANGELOG.md +60 -0
- package/dist/background/budget.d.ts +2 -0
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/background/schedules.d.ts +2 -9
- package/dist/background/schedules.js +10 -15
- package/dist/background/when.d.ts +28 -0
- package/dist/background/when.js +40 -0
- package/dist/calendar/mcp/index.d.ts +12 -12
- package/dist/cli/command-server-argv.d.ts +7 -0
- package/dist/cli/command-server-argv.js +7 -0
- package/dist/cli/command-server-entry.d.ts +12 -0
- package/dist/cli/command-server-entry.js +122 -0
- package/dist/cli/command-server.d.ts +29 -0
- package/dist/cli/command-server.js +100 -0
- package/dist/cli/entry.d.ts +2 -0
- package/dist/cli/entry.js +24 -18
- package/dist/cli/messenger/messages-search-command.js +4 -0
- package/dist/cli/program.js +8 -3
- package/dist/cli/schedule/schedule-command.js +14 -8
- package/dist/domain/display-names.d.ts +16 -0
- package/dist/domain/display-names.js +50 -0
- package/dist/errors/reasons.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/search/lucene/resolved.d.ts +1 -0
- package/dist/search/lucene/types.d.ts +8 -0
- package/dist/search/lucene/types.js +7 -0
- package/dist/services/messages-combined.js +3 -2
- package/dist/services/messages-discovery.js +3 -2
- package/dist/services/messages-search.js +1 -0
- package/dist/services/messages.d.ts +2 -0
- package/dist/services/people.js +1 -1
- package/dist/store/driver.d.ts +5 -1
- package/dist/store/driver.js +5 -0
- package/dist/store/identity-links.d.ts +3 -3
- package/dist/store/identity-links.js +3 -3
- package/dist/store/index.d.ts +2 -0
- package/dist/store/index.js +1 -0
- package/dist/store/people.d.ts +21 -2
- package/dist/store/people.js +35 -15
- package/dist/store/sqlite/lucene.js +12 -11
- package/dist/store/sqlite/manifest.js +1 -0
- package/dist/store/sqlite/migrations.generated.js +7 -0
- package/dist/store/sqlite/name-traces.d.ts +17 -0
- package/dist/store/sqlite/name-traces.js +112 -0
- package/dist/store/sqlite/notes.js +6 -3
- package/dist/store/sqlite/people-list.d.ts +44 -0
- package/dist/store/sqlite/people-list.js +151 -0
- package/dist/store/sqlite/person-match-scan.js +33 -0
- package/dist/store/sqlite/person-ties.d.ts +14 -0
- package/dist/store/sqlite/person-ties.js +66 -0
- package/dist/store/sqlite/ref-accounts.js +6 -3
- package/dist/store/sqlite/schema.d.ts +16 -0
- package/dist/store/sqlite/schema.js +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createInterface } from "node:readline";
|
|
3
|
+
import { CliError, errorObjectOf, renderError } from "@wirecat/cli-base";
|
|
4
|
+
import { metaOf } from "@wirecat/cli-base/commands";
|
|
5
|
+
import { commandPathOf } from "./command-contract.js";
|
|
6
|
+
import { isCommandServer } from "./command-server-argv.js";
|
|
7
|
+
import { stdinFieldOf } from "./stdin-field.js";
|
|
8
|
+
export const COMMAND_SERVER_PROTOCOL = 1;
|
|
9
|
+
/** An updated tool's old code must not answer for long. */
|
|
10
|
+
export const COMMAND_SERVER_IDLE_MS = 10 * 60_000;
|
|
11
|
+
const requests = new AsyncLocalStorage();
|
|
12
|
+
export const inCommandServerRequest = (work) => requests.run(true, work);
|
|
13
|
+
/** A command the server cannot answer like a spawned run: one that never returns, waits on a person, or reads stdin. */
|
|
14
|
+
export const refuseInCommandServer = (command, cli) => {
|
|
15
|
+
if (requests.getStore() !== true)
|
|
16
|
+
return;
|
|
17
|
+
const typed = [cli, ...commandPathOf(command)].join(" ");
|
|
18
|
+
const { lifetime } = metaOf(command);
|
|
19
|
+
if (lifetime)
|
|
20
|
+
throw new CliError("validation_error", `\`${typed}\` ${lifetime === "persistent" ? "runs until it is stopped" : "waits on a person"}; ` +
|
|
21
|
+
"the command server runs only commands that return — start it as a process of its own");
|
|
22
|
+
if (stdinFieldOf(command))
|
|
23
|
+
throw new CliError("validation_error", `\`${typed}\` reads its input on stdin, which the command server does not pass on — start it as a process of its own`);
|
|
24
|
+
};
|
|
25
|
+
const refusal = (cli, message) => `${renderError(errorObjectOf(new CliError("validation_error", message)), { cli, interactive: false })}\n`;
|
|
26
|
+
const requestOf = (line, cli) => {
|
|
27
|
+
let parsed;
|
|
28
|
+
try {
|
|
29
|
+
parsed = JSON.parse(line);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return { id: null, error: "a request is one JSON object per line" };
|
|
33
|
+
}
|
|
34
|
+
const { id, argv } = (parsed ?? {});
|
|
35
|
+
// A request whose id is readable is answered under it, so the client never waits on it.
|
|
36
|
+
const known = typeof id === "number" && Number.isFinite(id) ? id : null;
|
|
37
|
+
if (known === null)
|
|
38
|
+
return { id: null, error: 'a request needs a numeric "id"' };
|
|
39
|
+
if (!Array.isArray(argv) || !argv.every((word) => typeof word === "string"))
|
|
40
|
+
return { id: known, error: '"argv" is a list of strings' };
|
|
41
|
+
if (isCommandServer(argv))
|
|
42
|
+
return { id: known, error: `\`${cli} commands --serve\` cannot run inside itself` };
|
|
43
|
+
return { id: known, argv };
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Says it is ready, then answers each line of `input` in order, one at a time: two runs at once in one process would
|
|
47
|
+
* open the store twice, and closing either descriptor drops the other's locks (BUG-557). Resolves with 0 when the
|
|
48
|
+
* input ends or nothing came for `idleMs`.
|
|
49
|
+
*/
|
|
50
|
+
export const serveCommands = async ({ input, write, run, cli, version, idleMs = COMMAND_SERVER_IDLE_MS, signal, }) => {
|
|
51
|
+
const send = (value) => write(`${JSON.stringify(value)}\n`);
|
|
52
|
+
await send({ ready: true, protocol: COMMAND_SERVER_PROTOCOL, version });
|
|
53
|
+
const lines = createInterface({ input, crlfDelay: Number.POSITIVE_INFINITY });
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
let queue = Promise.resolve();
|
|
56
|
+
let waiting = 0;
|
|
57
|
+
let timer;
|
|
58
|
+
let done = false;
|
|
59
|
+
const finish = () => {
|
|
60
|
+
if (done)
|
|
61
|
+
return;
|
|
62
|
+
done = true;
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
lines.close();
|
|
65
|
+
resolve(0);
|
|
66
|
+
};
|
|
67
|
+
const idle = () => {
|
|
68
|
+
clearTimeout(timer);
|
|
69
|
+
timer = setTimeout(finish, idleMs);
|
|
70
|
+
};
|
|
71
|
+
const answer = async (line) => {
|
|
72
|
+
const request = requestOf(line, cli);
|
|
73
|
+
if ("error" in request)
|
|
74
|
+
return send({ id: request.id, code: 2, stdout: "", stderr: refusal(cli, request.error) });
|
|
75
|
+
const answered = await run(request.argv);
|
|
76
|
+
return send({ id: request.id, ...answered });
|
|
77
|
+
};
|
|
78
|
+
lines.on("line", (line) => {
|
|
79
|
+
if (done || line.trim() === "")
|
|
80
|
+
return;
|
|
81
|
+
waiting += 1;
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
queue = queue
|
|
84
|
+
.then(() => answer(line))
|
|
85
|
+
.catch(finish)
|
|
86
|
+
.then(() => {
|
|
87
|
+
waiting -= 1;
|
|
88
|
+
if (waiting === 0 && !done)
|
|
89
|
+
idle();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
lines.on("close", () => {
|
|
93
|
+
queue = queue.then(finish);
|
|
94
|
+
});
|
|
95
|
+
if (signal?.aborted)
|
|
96
|
+
finish();
|
|
97
|
+
signal?.addEventListener("abort", () => (queue = queue.then(finish)), { once: true });
|
|
98
|
+
idle();
|
|
99
|
+
});
|
|
100
|
+
};
|
package/dist/cli/entry.d.ts
CHANGED
|
@@ -62,5 +62,7 @@ export interface CliEntry {
|
|
|
62
62
|
* output still flushes.
|
|
63
63
|
*/
|
|
64
64
|
export declare const startCli: (entry: CliEntry) => Promise<void>;
|
|
65
|
+
/** The first-run questions, before the command acts. A dry run writes nothing, and these write the shared config. */
|
|
66
|
+
export declare const firstRunAt: (entry: CliEntry, io: EntryIo, headless: (command: Command) => boolean) => (command: Command) => Promise<void>;
|
|
65
67
|
/** Opens `url` in the system browser, or in `browser` when given; resolves once the browser has started. */
|
|
66
68
|
export declare const openBrowser: (url: string, browser?: string, io?: Pick<EntryIo, "platform" | "spawn">) => Promise<void>;
|
package/dist/cli/entry.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CliError, catchCrashes } from "@wirecat/cli-base";
|
|
|
3
3
|
import { envName, readOnlyLockOf } from "../ports/app.js";
|
|
4
4
|
import { ensureSqlite } from "../sqlite-runtime.js";
|
|
5
5
|
import { logVersion } from "./argv-log.js";
|
|
6
|
+
import { isCommandServer } from "./command-server-argv.js";
|
|
6
7
|
const processIo = () => ({
|
|
7
8
|
argv: process.argv,
|
|
8
9
|
env: process.env,
|
|
@@ -26,6 +27,10 @@ export const startCli = async (entry) => {
|
|
|
26
27
|
const args = io.argv.slice(2);
|
|
27
28
|
if (args.length === 1 && (args[0] === "--version" || args[0] === "-V"))
|
|
28
29
|
return printVersion(entry.app, io);
|
|
30
|
+
if (isCommandServer(args)) {
|
|
31
|
+
const { serveEntry } = await import("./command-server-entry.js");
|
|
32
|
+
return serveEntry(entry, io, { firstRunAt, commanderExit });
|
|
33
|
+
}
|
|
29
34
|
const tty = io.stdout.isTTY === true;
|
|
30
35
|
const release = catchCrashes({
|
|
31
36
|
cli: entry.app.command,
|
|
@@ -58,24 +63,7 @@ export const startCli = async (entry) => {
|
|
|
58
63
|
env: io.env,
|
|
59
64
|
tty,
|
|
60
65
|
signal: controller.signal,
|
|
61
|
-
atStart:
|
|
62
|
-
// The first-run questions write the shared config; a dry run writes nothing.
|
|
63
|
-
if (command.optsWithGlobals().dryRun === true)
|
|
64
|
-
return;
|
|
65
|
-
const [{ setupAtStart }, { commandPathOf }] = await Promise.all([
|
|
66
|
-
import("./first-run.js"),
|
|
67
|
-
import("./command-contract.js"),
|
|
68
|
-
]);
|
|
69
|
-
await setupAtStart({
|
|
70
|
-
command: entry.app.command,
|
|
71
|
-
env: io.env,
|
|
72
|
-
contentLanguages: entry.app.contentLanguages,
|
|
73
|
-
path: commandPathOf(command),
|
|
74
|
-
headless: headless(command),
|
|
75
|
-
readOnlyLock: readOnlyLockOf(entry.app, io.env),
|
|
76
|
-
input: io.stdin,
|
|
77
|
-
});
|
|
78
|
-
},
|
|
66
|
+
atStart: firstRunAt(entry, io, headless),
|
|
79
67
|
ask: async (question, command) => {
|
|
80
68
|
if (headless(command) || io.stdin.isTTY !== true)
|
|
81
69
|
return false;
|
|
@@ -120,6 +108,24 @@ export const startCli = async (entry) => {
|
|
|
120
108
|
else if (code !== undefined)
|
|
121
109
|
io.setExitCode(code);
|
|
122
110
|
};
|
|
111
|
+
/** The first-run questions, before the command acts. A dry run writes nothing, and these write the shared config. */
|
|
112
|
+
export const firstRunAt = (entry, io, headless) => async (command) => {
|
|
113
|
+
if (command.optsWithGlobals().dryRun === true)
|
|
114
|
+
return;
|
|
115
|
+
const [{ setupAtStart }, { commandPathOf }] = await Promise.all([
|
|
116
|
+
import("./first-run.js"),
|
|
117
|
+
import("./command-contract.js"),
|
|
118
|
+
]);
|
|
119
|
+
await setupAtStart({
|
|
120
|
+
command: entry.app.command,
|
|
121
|
+
env: io.env,
|
|
122
|
+
contentLanguages: entry.app.contentLanguages,
|
|
123
|
+
path: commandPathOf(command),
|
|
124
|
+
headless: headless(command),
|
|
125
|
+
readOnlyLock: readOnlyLockOf(entry.app, io.env),
|
|
126
|
+
input: io.stdin,
|
|
127
|
+
});
|
|
128
|
+
};
|
|
123
129
|
/**
|
|
124
130
|
* Answered before the program loads, which is most of a start: an agent asks for the version to learn whether the
|
|
125
131
|
* tool is there at all. Only the bare flag — anything else on the line goes through the program as before.
|
|
@@ -6,6 +6,7 @@ import { SAVE_HELP } from "../../meetings/index.js";
|
|
|
6
6
|
import { syncsOneChat } from "../../ports/traits.js";
|
|
7
7
|
import { renderMessages } from "../../render/messages.js";
|
|
8
8
|
import { renderThreadLinks } from "../../render/thread-context.js";
|
|
9
|
+
import { searchTimeLimit } from "../../search/lucene/types.js";
|
|
9
10
|
import { environmentOf } from "../context.js";
|
|
10
11
|
import { REMOTE_READ } from "../effects.js";
|
|
11
12
|
import { renderAnswer } from "../envelope.js";
|
|
@@ -69,6 +70,7 @@ const searchAction = (messenger) => async function (given) {
|
|
|
69
70
|
context.track({ close: async () => controller.abort() });
|
|
70
71
|
const external = environmentOf(this).signal;
|
|
71
72
|
const signal = external ? AbortSignal.any([external, controller.signal]) : controller.signal;
|
|
73
|
+
const timeLimitMs = searchTimeLimit(environmentOf(this).deadline?.());
|
|
72
74
|
const typed = {
|
|
73
75
|
...(source === undefined ? {} : { source }),
|
|
74
76
|
...(discover === undefined ? {} : { discover }),
|
|
@@ -91,6 +93,7 @@ const searchAction = (messenger) => async function (given) {
|
|
|
91
93
|
limit,
|
|
92
94
|
...withOffset(page, limit),
|
|
93
95
|
signal,
|
|
96
|
+
...(timeLimitMs === undefined ? {} : { timeLimitMs }),
|
|
94
97
|
newest: newest === true,
|
|
95
98
|
context: around ?? (context.format === "pretty" ? 2 : 0),
|
|
96
99
|
});
|
|
@@ -110,6 +113,7 @@ const searchAction = (messenger) => async function (given) {
|
|
|
110
113
|
limit,
|
|
111
114
|
...withOffset(page, limit),
|
|
112
115
|
signal,
|
|
116
|
+
...(timeLimitMs === undefined ? {} : { timeLimitMs }),
|
|
113
117
|
newest: params.newest === true,
|
|
114
118
|
...(params.discover === undefined ? {} : { discover: params.discover }),
|
|
115
119
|
...(params.exact ? { exact: true } : {}),
|
package/dist/cli/program.js
CHANGED
|
@@ -18,6 +18,7 @@ import { liftOptionsAfterDashes } from "./after-dashes.js";
|
|
|
18
18
|
import { logParsedArgv, logVersion } from "./argv-log.js";
|
|
19
19
|
import { commandAvailability } from "./command-availability.js";
|
|
20
20
|
import { commandPathOf } from "./command-contract.js";
|
|
21
|
+
import { refuseInCommandServer } from "./command-server.js";
|
|
21
22
|
import { entityRows } from "./compact.js";
|
|
22
23
|
import { outputFor, provide } from "./context.js";
|
|
23
24
|
import { refuseByCommandPermissions, refuseOfflineCommand, refuseWriteBeforeConnecting } from "./early-refusal.js";
|
|
@@ -169,7 +170,10 @@ const runOnce = async (argv, definition, options) => {
|
|
|
169
170
|
let afterPhase;
|
|
170
171
|
let running;
|
|
171
172
|
const startDeadline = (ms) => {
|
|
172
|
-
running =
|
|
173
|
+
running =
|
|
174
|
+
ms === undefined
|
|
175
|
+
? undefined
|
|
176
|
+
: { endsAt: Date.now() + ms, ms, ...(explicitEnd === undefined ? {} : { explicit: true }) };
|
|
173
177
|
control.start(ms);
|
|
174
178
|
};
|
|
175
179
|
let finished = false;
|
|
@@ -308,6 +312,7 @@ const runOnce = async (argv, definition, options) => {
|
|
|
308
312
|
action.setOptionValue("dryRun", true);
|
|
309
313
|
refuseOfflineCommand(action, definition.app, flags.offline === true, flags.dryRun === true && localPreview);
|
|
310
314
|
const path = commandPathOf(action);
|
|
315
|
+
refuseInCommandServer(action, command);
|
|
311
316
|
const lock = readOnlyLockOf(definition.app, commandEnv);
|
|
312
317
|
const input = options.stdin ?? process.stdin;
|
|
313
318
|
// The first-run questions write the shared config; a dry run writes nothing.
|
|
@@ -416,11 +421,11 @@ const runOnce = async (argv, definition, options) => {
|
|
|
416
421
|
});
|
|
417
422
|
throw new Relayed(code);
|
|
418
423
|
}
|
|
424
|
+
if (timeout !== undefined && deadline !== undefined)
|
|
425
|
+
explicitEnd = Date.now() + deadline;
|
|
419
426
|
startDeadline(deadline);
|
|
420
427
|
oneShot = deadline;
|
|
421
428
|
afterPhase = timeout !== undefined || persistent || job || interactiveLogin ? deadline : DEFAULT_COMMAND_MS;
|
|
422
|
-
if (timeout !== undefined && deadline !== undefined)
|
|
423
|
-
explicitEnd = Date.now() + deadline;
|
|
424
429
|
// An agent's run shares this process's directory; a chat folder's name is not a path to resolve.
|
|
425
430
|
if (options.relayed && !options.agent)
|
|
426
431
|
absolutePaths(action, options.relayed.cwd);
|
|
@@ -7,7 +7,7 @@ import { backfillSchedule } from "../../background/backfill.js";
|
|
|
7
7
|
import { parseRoute, ROUTE_HELP, routeText } from "../../background/deliver.js";
|
|
8
8
|
import { REPORT_CHANNELS } from "../../background/report/render.js";
|
|
9
9
|
import { keyOfKind } from "../../background/report/stored-templates.js";
|
|
10
|
-
import { describeWhen, findProgram, lastRun, listSchedules, NOTIFY_WHEN, notifyOf, readSchedule, recordSkip, runSchedule, SCHEDULE_DEFAULTS, SKIP_REASONS, scheduleFile, scheduleName, spentToday, timerFor, } from "../../background/schedules.js";
|
|
10
|
+
import { describeWhen, findProgram, lastRun, listSchedules, NOTIFY_WHEN, notifyOf, readSchedule, recordSkip, runSchedule, SCHEDULE_DEFAULTS, SKIP_REASONS, scheduleFile, scheduleName, spentToday, timerFor, WEEKDAYS, } from "../../background/schedules.js";
|
|
11
11
|
import { thisMachine } from "../../background/system.js";
|
|
12
12
|
import { locationVariables } from "../../background/units.js";
|
|
13
13
|
import { parseDuration } from "../../domain/duration.js";
|
|
@@ -40,7 +40,7 @@ const isModel = (model) => /^([A-Za-z0-9][\w.:/@[\]-]*)?$/.test(model);
|
|
|
40
40
|
const LEAN_CLAUDE = ["--tools", "Bash", "--strict-mcp-config", "--disable-slash-commands", "--setting-sources", ""];
|
|
41
41
|
const whenOf = ({ every, at, atTime }, minimum) => {
|
|
42
42
|
if ([every ?? at, atTime].filter(Boolean).length !== 1) {
|
|
43
|
-
throw new CliError("validation_error", "say when: --every <30m|2h|1d>, --at HH:MM (daily), or --at-time <30m|2d|ISO time>");
|
|
43
|
+
throw new CliError("validation_error", "say when: --every <30m|2h|1d>, --at HH:MM (daily) or --at 'mon HH:MM' (weekly), or --at-time <30m|2d|ISO time>");
|
|
44
44
|
}
|
|
45
45
|
if (atTime) {
|
|
46
46
|
const time = aheadOf(atTime, "--at-time");
|
|
@@ -49,12 +49,18 @@ const whenOf = ({ every, at, atTime }, minimum) => {
|
|
|
49
49
|
return { once: new Date(time).toISOString() };
|
|
50
50
|
}
|
|
51
51
|
if (at) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const [, word, clock = ""] = /^\s*(?:([a-z]+)\s+)?(\S+)\s*$/i.exec(at) ?? [];
|
|
53
|
+
if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(clock))
|
|
54
|
+
throw new CliError("validation_error", `--at takes HH:MM, or a weekday and HH:MM such as 'mon 09:00'; not "${at}"`);
|
|
55
|
+
const day = word?.toLowerCase().slice(0, 3);
|
|
56
|
+
if (word !== undefined && !WEEKDAYS.includes(day ?? ""))
|
|
57
|
+
throw new CliError("validation_error", `--at takes a weekday, ${WEEKDAYS.join(", ")}; not "${word}"`);
|
|
58
|
+
if (every && (day !== undefined || parseDuration(every, "--every") !== 86_400_000)) {
|
|
59
|
+
throw new CliError("validation_error", day === undefined
|
|
60
|
+
? "--at runs once a day; leave out --every, or use --every 1d"
|
|
61
|
+
: "a weekday in --at runs once a week; leave out --every");
|
|
56
62
|
}
|
|
57
|
-
return { daily:
|
|
63
|
+
return day === undefined ? { daily: clock } : { weekly: clock, on: day };
|
|
58
64
|
}
|
|
59
65
|
const minutes = parseDuration(every ?? "", "--every") / 60_000;
|
|
60
66
|
if (!Number.isInteger(minutes) || minutes < minimum) {
|
|
@@ -86,7 +92,7 @@ const scheduleAnswer = ({ environment, createdAt, to, ...schedule }, extra) => (
|
|
|
86
92
|
});
|
|
87
93
|
const withWhen = (command) => command
|
|
88
94
|
.option("--every <duration>", "repeat: 30m, 2h, 1d")
|
|
89
|
-
.option("--at <HH:MM>",
|
|
95
|
+
.option("--at <HH:MM>", `every day at this local time; 'mon 09:00' once a week (${WEEKDAYS.join(", ")})`)
|
|
90
96
|
.option("--at-time <time>", "one run: 30m, 2d from now, or an ISO time; the schedule removes itself after it")
|
|
91
97
|
.addOption(new Option("--notify-on <when>", "desktop notice after a run (default failures for an agent that repeats with --every, else always)").choices(NOTIFY_WHEN))
|
|
92
98
|
.option("--deliver-to <route>", `also send the result, when --notify-on says so, by the owner's own tg or mail: ${ROUTE_HELP}; repeat it for more`, (route, routes = []) => [...routes, routeText(parseRoute(route))]);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** What a person can be shown as when their name has nothing to read. */
|
|
2
|
+
export interface NameFallbacks {
|
|
3
|
+
username?: string | null;
|
|
4
|
+
phone?: string | null;
|
|
5
|
+
email?: string | null;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`) gives
|
|
9
|
+
* way to the username, then the phone, then the email; the stored name stays as it came.
|
|
10
|
+
*/
|
|
11
|
+
export declare const displayName: (name: string | null | undefined, fallbacks?: NameFallbacks) => string | null;
|
|
12
|
+
/**
|
|
13
|
+
* The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
|
|
14
|
+
* `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
|
|
15
|
+
*/
|
|
16
|
+
export declare const nameKey: (name: string | null | undefined) => string | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { foldName } from "../resolve.js";
|
|
2
|
+
const QUOTES = [
|
|
3
|
+
['"', '"'],
|
|
4
|
+
["'", "'"],
|
|
5
|
+
["«", "»"],
|
|
6
|
+
["“", "”"],
|
|
7
|
+
["„", "“"],
|
|
8
|
+
["‘", "’"],
|
|
9
|
+
["`", "`"],
|
|
10
|
+
];
|
|
11
|
+
const READABLE = /[\p{L}\p{N}]/u;
|
|
12
|
+
const unquoted = (text) => {
|
|
13
|
+
let at = text.replace(/\s+/gu, " ").trim();
|
|
14
|
+
for (;;) {
|
|
15
|
+
const pair = QUOTES.find(([open, close]) => at.length >= 2 && at.startsWith(open) && at.endsWith(close));
|
|
16
|
+
if (pair === undefined)
|
|
17
|
+
return at;
|
|
18
|
+
at = at.slice(pair[0].length, at.length - pair[1].length).trim();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const given = (value) => {
|
|
22
|
+
const text = typeof value === "string" ? value.trim() : "";
|
|
23
|
+
return text === "" ? undefined : text;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A name as it is shown: no wrapping quotes, no repeated or edge spaces. One with no letter or digit (`!`, `!$`) gives
|
|
27
|
+
* way to the username, then the phone, then the email; the stored name stays as it came.
|
|
28
|
+
*/
|
|
29
|
+
export const displayName = (name, fallbacks = {}) => {
|
|
30
|
+
const cleaned = typeof name === "string" ? unquoted(name) : "";
|
|
31
|
+
if (READABLE.test(cleaned))
|
|
32
|
+
return cleaned;
|
|
33
|
+
const username = given(fallbacks.username);
|
|
34
|
+
return ((username === undefined ? undefined : username.startsWith("@") ? username : `@${username}`) ??
|
|
35
|
+
given(fallbacks.phone) ??
|
|
36
|
+
given(fallbacks.email) ??
|
|
37
|
+
(cleaned === "" ? null : cleaned));
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The name two people share when case, quotes, punctuation and word order are ignored: `"Ivanov Ivan"` and
|
|
41
|
+
* `ivan IVANOV` give one key. `null` for a name with no letter or digit, which matches nobody.
|
|
42
|
+
*/
|
|
43
|
+
export const nameKey = (name) => {
|
|
44
|
+
if (typeof name !== "string")
|
|
45
|
+
return null;
|
|
46
|
+
const words = foldName(unquoted(name))
|
|
47
|
+
.split(/[^\p{L}\p{N}]+/u)
|
|
48
|
+
.filter((word) => word !== "");
|
|
49
|
+
return words.length === 0 ? null : words.sort().join(" ");
|
|
50
|
+
};
|
package/dist/errors/reasons.js
CHANGED
|
@@ -381,6 +381,7 @@ const OTHERS = [
|
|
|
381
381
|
],
|
|
382
382
|
validation("identity.same", "the two identities are one person already"),
|
|
383
383
|
validation("identity.shared-phone", "more than six people share the phone number, so it proposes no one"),
|
|
384
|
+
validation("identity.common-name", "more than six people have the name, so it proposes no one"),
|
|
384
385
|
validation("identity.shared-email", "more than six people share the address, so it proposes no one"),
|
|
385
386
|
validation("identity-link.dedicated-review", "an identity link is staged and decided through the people review"),
|
|
386
387
|
["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type { CounterField, CounterObservation, CounterObservations, CounterStat
|
|
|
5
5
|
export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
|
|
6
6
|
export { CRM_KINDS, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmRecords, type CrmScope, type CrmScopeSetting, type CrmStage, type CrmUser, type CrmValue, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
|
|
7
7
|
export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, type DealKind, type DealRole, type DealStatus, STAGE_OUTCOMES, type StageOutcome, } from "./domain/deals.js";
|
|
8
|
+
export { displayName, type NameFallbacks, nameKey } from "./domain/display-names.js";
|
|
8
9
|
export { FINANCE_REVIEWS, type FinanceReview, INVOICE_DIRECTIONS, INVOICE_STATUSES, type InvoiceDirection, type InvoiceStatus, MONEY_DIRECTIONS, type MoneyDirection, } from "./domain/finance.js";
|
|
9
10
|
export { type FormattedText, type HtmlFormatting, type MarkdownFormatting, type TextSpan, validateFormattedText, } from "./domain/formatting.js";
|
|
10
11
|
export { DEFAULT_LINK_CONFIG, type DeepLinkTarget, formatLink, LINK_VERSION, type LinkConfig, type LinkForm, linkConfigOf, linkFor, linkTargetOf, parseLink, refsForLink, } from "./domain/links.js";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { bareCheck, checkWords } from "./domain/checks.js";
|
|
|
4
4
|
export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
|
|
5
5
|
export { CRM_KINDS, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
|
|
6
6
|
export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, STAGE_OUTCOMES, } from "./domain/deals.js";
|
|
7
|
+
export { displayName, nameKey } from "./domain/display-names.js";
|
|
7
8
|
export { FINANCE_REVIEWS, INVOICE_DIRECTIONS, INVOICE_STATUSES, MONEY_DIRECTIONS, } from "./domain/finance.js";
|
|
8
9
|
export { validateFormattedText, } from "./domain/formatting.js";
|
|
9
10
|
export { DEFAULT_LINK_CONFIG, formatLink, LINK_VERSION, linkConfigOf, linkFor, linkTargetOf, parseLink, refsForLink, } from "./domain/links.js";
|
|
@@ -38,6 +38,7 @@ export declare const meetingTools: ({
|
|
|
38
38
|
max_read_bytes?: undefined;
|
|
39
39
|
cursor?: undefined;
|
|
40
40
|
} | {
|
|
41
|
+
limit?: undefined;
|
|
41
42
|
event_id?: undefined;
|
|
42
43
|
series_id?: undefined;
|
|
43
44
|
page?: undefined;
|
|
@@ -53,11 +54,11 @@ export declare const meetingTools: ({
|
|
|
53
54
|
format?: undefined;
|
|
54
55
|
transcript_id?: undefined;
|
|
55
56
|
query?: undefined;
|
|
56
|
-
limit?: undefined;
|
|
57
57
|
scan_limit?: undefined;
|
|
58
58
|
max_read_bytes?: undefined;
|
|
59
59
|
cursor?: undefined;
|
|
60
60
|
} | {
|
|
61
|
+
limit?: undefined;
|
|
61
62
|
event_id?: undefined;
|
|
62
63
|
series_id?: undefined;
|
|
63
64
|
page?: undefined;
|
|
@@ -75,11 +76,11 @@ export declare const meetingTools: ({
|
|
|
75
76
|
format?: undefined;
|
|
76
77
|
transcript_id?: undefined;
|
|
77
78
|
query?: undefined;
|
|
78
|
-
limit?: undefined;
|
|
79
79
|
scan_limit?: undefined;
|
|
80
80
|
max_read_bytes?: undefined;
|
|
81
81
|
cursor?: undefined;
|
|
82
82
|
} | {
|
|
83
|
+
limit?: undefined;
|
|
83
84
|
event_id?: undefined;
|
|
84
85
|
series_id?: undefined;
|
|
85
86
|
page?: undefined;
|
|
@@ -101,7 +102,6 @@ export declare const meetingTools: ({
|
|
|
101
102
|
minimum: number;
|
|
102
103
|
};
|
|
103
104
|
query?: undefined;
|
|
104
|
-
limit?: undefined;
|
|
105
105
|
scan_limit?: undefined;
|
|
106
106
|
max_read_bytes?: undefined;
|
|
107
107
|
cursor?: undefined;
|
|
@@ -188,6 +188,7 @@ export declare const meetingTools: ({
|
|
|
188
188
|
max_read_bytes?: undefined;
|
|
189
189
|
cursor?: undefined;
|
|
190
190
|
} | {
|
|
191
|
+
limit?: undefined;
|
|
191
192
|
event_id?: undefined;
|
|
192
193
|
series_id?: undefined;
|
|
193
194
|
page?: undefined;
|
|
@@ -203,11 +204,11 @@ export declare const meetingTools: ({
|
|
|
203
204
|
format?: undefined;
|
|
204
205
|
transcript_id?: undefined;
|
|
205
206
|
query?: undefined;
|
|
206
|
-
limit?: undefined;
|
|
207
207
|
scan_limit?: undefined;
|
|
208
208
|
max_read_bytes?: undefined;
|
|
209
209
|
cursor?: undefined;
|
|
210
210
|
} | {
|
|
211
|
+
limit?: undefined;
|
|
211
212
|
event_id?: undefined;
|
|
212
213
|
series_id?: undefined;
|
|
213
214
|
page?: undefined;
|
|
@@ -225,11 +226,11 @@ export declare const meetingTools: ({
|
|
|
225
226
|
format?: undefined;
|
|
226
227
|
transcript_id?: undefined;
|
|
227
228
|
query?: undefined;
|
|
228
|
-
limit?: undefined;
|
|
229
229
|
scan_limit?: undefined;
|
|
230
230
|
max_read_bytes?: undefined;
|
|
231
231
|
cursor?: undefined;
|
|
232
232
|
} | {
|
|
233
|
+
limit?: undefined;
|
|
233
234
|
event_id?: undefined;
|
|
234
235
|
series_id?: undefined;
|
|
235
236
|
page?: undefined;
|
|
@@ -251,7 +252,6 @@ export declare const meetingTools: ({
|
|
|
251
252
|
minimum: number;
|
|
252
253
|
};
|
|
253
254
|
query?: undefined;
|
|
254
|
-
limit?: undefined;
|
|
255
255
|
scan_limit?: undefined;
|
|
256
256
|
max_read_bytes?: undefined;
|
|
257
257
|
cursor?: undefined;
|
|
@@ -338,6 +338,7 @@ export declare const meetingTools: ({
|
|
|
338
338
|
max_read_bytes?: undefined;
|
|
339
339
|
cursor?: undefined;
|
|
340
340
|
} | {
|
|
341
|
+
limit?: undefined;
|
|
341
342
|
event_id?: undefined;
|
|
342
343
|
series_id?: undefined;
|
|
343
344
|
page?: undefined;
|
|
@@ -353,11 +354,11 @@ export declare const meetingTools: ({
|
|
|
353
354
|
format?: undefined;
|
|
354
355
|
transcript_id?: undefined;
|
|
355
356
|
query?: undefined;
|
|
356
|
-
limit?: undefined;
|
|
357
357
|
scan_limit?: undefined;
|
|
358
358
|
max_read_bytes?: undefined;
|
|
359
359
|
cursor?: undefined;
|
|
360
360
|
} | {
|
|
361
|
+
limit?: undefined;
|
|
361
362
|
event_id?: undefined;
|
|
362
363
|
series_id?: undefined;
|
|
363
364
|
page?: undefined;
|
|
@@ -375,11 +376,11 @@ export declare const meetingTools: ({
|
|
|
375
376
|
format?: undefined;
|
|
376
377
|
transcript_id?: undefined;
|
|
377
378
|
query?: undefined;
|
|
378
|
-
limit?: undefined;
|
|
379
379
|
scan_limit?: undefined;
|
|
380
380
|
max_read_bytes?: undefined;
|
|
381
381
|
cursor?: undefined;
|
|
382
382
|
} | {
|
|
383
|
+
limit?: undefined;
|
|
383
384
|
event_id?: undefined;
|
|
384
385
|
series_id?: undefined;
|
|
385
386
|
page?: undefined;
|
|
@@ -401,7 +402,6 @@ export declare const meetingTools: ({
|
|
|
401
402
|
minimum: number;
|
|
402
403
|
};
|
|
403
404
|
query?: undefined;
|
|
404
|
-
limit?: undefined;
|
|
405
405
|
scan_limit?: undefined;
|
|
406
406
|
max_read_bytes?: undefined;
|
|
407
407
|
cursor?: undefined;
|
|
@@ -488,6 +488,7 @@ export declare const meetingTools: ({
|
|
|
488
488
|
max_read_bytes?: undefined;
|
|
489
489
|
cursor?: undefined;
|
|
490
490
|
} | {
|
|
491
|
+
limit?: undefined;
|
|
491
492
|
event_id?: undefined;
|
|
492
493
|
series_id?: undefined;
|
|
493
494
|
page?: undefined;
|
|
@@ -503,11 +504,11 @@ export declare const meetingTools: ({
|
|
|
503
504
|
format?: undefined;
|
|
504
505
|
transcript_id?: undefined;
|
|
505
506
|
query?: undefined;
|
|
506
|
-
limit?: undefined;
|
|
507
507
|
scan_limit?: undefined;
|
|
508
508
|
max_read_bytes?: undefined;
|
|
509
509
|
cursor?: undefined;
|
|
510
510
|
} | {
|
|
511
|
+
limit?: undefined;
|
|
511
512
|
event_id?: undefined;
|
|
512
513
|
series_id?: undefined;
|
|
513
514
|
page?: undefined;
|
|
@@ -525,11 +526,11 @@ export declare const meetingTools: ({
|
|
|
525
526
|
format?: undefined;
|
|
526
527
|
transcript_id?: undefined;
|
|
527
528
|
query?: undefined;
|
|
528
|
-
limit?: undefined;
|
|
529
529
|
scan_limit?: undefined;
|
|
530
530
|
max_read_bytes?: undefined;
|
|
531
531
|
cursor?: undefined;
|
|
532
532
|
} | {
|
|
533
|
+
limit?: undefined;
|
|
533
534
|
event_id?: undefined;
|
|
534
535
|
series_id?: undefined;
|
|
535
536
|
page?: undefined;
|
|
@@ -551,7 +552,6 @@ export declare const meetingTools: ({
|
|
|
551
552
|
minimum: number;
|
|
552
553
|
};
|
|
553
554
|
query?: undefined;
|
|
554
|
-
limit?: undefined;
|
|
555
555
|
scan_limit?: undefined;
|
|
556
556
|
max_read_bytes?: undefined;
|
|
557
557
|
cursor?: undefined;
|
|
@@ -638,6 +638,7 @@ export declare const meetingTools: ({
|
|
|
638
638
|
max_read_bytes?: undefined;
|
|
639
639
|
cursor?: undefined;
|
|
640
640
|
} | {
|
|
641
|
+
limit?: undefined;
|
|
641
642
|
event_id?: undefined;
|
|
642
643
|
series_id?: undefined;
|
|
643
644
|
page?: undefined;
|
|
@@ -653,11 +654,11 @@ export declare const meetingTools: ({
|
|
|
653
654
|
format?: undefined;
|
|
654
655
|
transcript_id?: undefined;
|
|
655
656
|
query?: undefined;
|
|
656
|
-
limit?: undefined;
|
|
657
657
|
scan_limit?: undefined;
|
|
658
658
|
max_read_bytes?: undefined;
|
|
659
659
|
cursor?: undefined;
|
|
660
660
|
} | {
|
|
661
|
+
limit?: undefined;
|
|
661
662
|
event_id?: undefined;
|
|
662
663
|
series_id?: undefined;
|
|
663
664
|
page?: undefined;
|
|
@@ -675,11 +676,11 @@ export declare const meetingTools: ({
|
|
|
675
676
|
format?: undefined;
|
|
676
677
|
transcript_id?: undefined;
|
|
677
678
|
query?: undefined;
|
|
678
|
-
limit?: undefined;
|
|
679
679
|
scan_limit?: undefined;
|
|
680
680
|
max_read_bytes?: undefined;
|
|
681
681
|
cursor?: undefined;
|
|
682
682
|
} | {
|
|
683
|
+
limit?: undefined;
|
|
683
684
|
event_id?: undefined;
|
|
684
685
|
series_id?: undefined;
|
|
685
686
|
page?: undefined;
|
|
@@ -701,7 +702,6 @@ export declare const meetingTools: ({
|
|
|
701
702
|
minimum: number;
|
|
702
703
|
};
|
|
703
704
|
query?: undefined;
|
|
704
|
-
limit?: undefined;
|
|
705
705
|
scan_limit?: undefined;
|
|
706
706
|
max_read_bytes?: undefined;
|
|
707
707
|
cursor?: undefined;
|
|
@@ -22,6 +22,14 @@ export declare const MESSAGE_PARSING: {
|
|
|
22
22
|
/** Further apart than this, two words are rarely about one thing, even in a long message. */
|
|
23
23
|
export declare const MOST_WORDS_APART = 50;
|
|
24
24
|
export declare function searchError(reason: string, span: Span, alternative?: string): never;
|
|
25
|
+
/**
|
|
26
|
+
* A search's time limit: the default keeps agents and MCP to 2 s; a run whose caller set a time limit itself
|
|
27
|
+
* (Desktop's `--timeout 30s`) may use it, less the time to answer.
|
|
28
|
+
*/
|
|
29
|
+
export declare const searchTimeLimit: (deadline: {
|
|
30
|
+
endsAt: number;
|
|
31
|
+
explicit?: true;
|
|
32
|
+
} | undefined, now?: number) => number | undefined;
|
|
25
33
|
/**
|
|
26
34
|
* The search ran out of time, not the query out of bounds: a valid query over a large store. `timeout`, so a caller
|
|
27
35
|
* does not tell the person to fix what they typed.
|
|
@@ -22,6 +22,13 @@ export const MOST_WORDS_APART = 50;
|
|
|
22
22
|
export function searchError(reason, span, alternative) {
|
|
23
23
|
queryError(reason, span, alternative, SEARCH_QUERY);
|
|
24
24
|
}
|
|
25
|
+
/** Time to print a search's own time-limit answer before the run's deadline cuts it. */
|
|
26
|
+
const ANSWER_MS = 1000;
|
|
27
|
+
/**
|
|
28
|
+
* A search's time limit: the default keeps agents and MCP to 2 s; a run whose caller set a time limit itself
|
|
29
|
+
* (Desktop's `--timeout 30s`) may use it, less the time to answer.
|
|
30
|
+
*/
|
|
31
|
+
export const searchTimeLimit = (deadline, now = Date.now()) => deadline?.explicit ? Math.max(QUERY_LIMITS.milliseconds, deadline.endsAt - now - ANSWER_MS) : undefined;
|
|
25
32
|
/**
|
|
26
33
|
* The search ran out of time, not the query out of bounds: a valid query over a large store. `timeout`, so a caller
|
|
27
34
|
* does not tell the person to fix what they typed.
|
|
@@ -30,8 +30,9 @@ export const searchCombined = async (store, account, request, messenger = {}, op
|
|
|
30
30
|
const check = () => {
|
|
31
31
|
if (request.signal?.aborted)
|
|
32
32
|
throw new CliError("validation_error", "search was aborted", { reason: "query.aborted", complete: false });
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
const limitMs = request.timeLimitMs ?? QUERY_LIMITS.milliseconds;
|
|
34
|
+
if (performance.now() - started > limitMs)
|
|
35
|
+
outOfTime(limitMs);
|
|
35
36
|
};
|
|
36
37
|
check();
|
|
37
38
|
const spans = request.ast === undefined && !request.exact && request.text !== undefined
|