@wirecat/cli-core 0.652.0 → 0.654.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 +35 -0
- package/dist/cli/bot/mcp.js +2 -1
- package/dist/cli/command-availability.d.ts +3 -1
- package/dist/cli/command-availability.js +6 -4
- package/dist/cli/early-refusal.d.ts +5 -5
- package/dist/cli/early-refusal.js +7 -7
- package/dist/cli/preview.js +8 -4
- package/dist/cli/program.js +3 -7
- package/dist/cli/setup-answers.d.ts +3 -2
- package/dist/cli/setup-answers.js +5 -6
- package/dist/domain/providers.js +3 -0
- package/dist/kit/index.d.ts +1 -0
- package/dist/kit/index.js +1 -0
- package/dist/kit/sync-after-install.d.ts +26 -0
- package/dist/kit/sync-after-install.js +72 -0
- package/dist/mail/index.d.ts +1 -0
- package/dist/mail/index.js +1 -0
- package/dist/mail/meeting-notes.d.ts +50 -0
- package/dist/mail/meeting-notes.js +198 -0
- package/dist/mail/rule-input.d.ts +1 -0
- package/dist/mail/rule-input.js +1 -0
- package/dist/mail/rule-stored.js +2 -0
- package/dist/mail/rules.d.ts +2 -0
- package/dist/mail/sync-types.d.ts +3 -0
- package/dist/mail/sync.js +12 -0
- package/dist/mcp/agent.d.ts +3 -0
- package/dist/mcp/agent.js +5 -4
- package/dist/mcp/app-server.js +4 -1
- package/dist/mcp/bot/server.d.ts +2 -0
- package/dist/mcp/bot/server.js +2 -0
- package/dist/mcp/server.js +4 -1
- package/dist/meetings/events.d.ts +3 -1
- package/dist/meetings/events.js +3 -1
- package/dist/meetings/pull.js +1 -1
- package/dist/meetings/source.d.ts +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,41 @@ 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.654.0 — 13.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`syncAfterInstallCases` in `/testing`**: a CLI's sync, run as its own tests run it, with no shared config, a
|
|
13
|
+
broken one, a byte-order mark, a folder, an older `setup` shape and the "read only" answer; each must succeed, and
|
|
14
|
+
an optional local-only write must still be refused under "read only". The kit points `WIRECAT_CONFIG_DIR` at a
|
|
15
|
+
folder of its own, so the owner's config cannot hide the failure.
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- **A fresh install syncs: only the owner's own "read only" answer limits a tool.** A shared config
|
|
20
|
+
(`~/.config/WireCat/config.json`) that is not JSON, starts with a byte-order mark, is a folder or holds a
|
|
21
|
+
`setup` section in an older shape no longer makes every WireCat tool read-only; each profile's permissions apply.
|
|
22
|
+
Before, such a file refused `sync` with "setup's answer keeps every WireCat tool read-only".
|
|
23
|
+
- **Setup's "read only" answer lets a sync run.** A command that only fetches from the service into the local store
|
|
24
|
+
(`fetchesOnly`) is no longer refused by that answer, on the command line, in `--dry-run` previews and over MCP. A
|
|
25
|
+
profile's own `readonly` level still refuses it, and every other write stays refused under the answer.
|
|
26
|
+
|
|
27
|
+
## 0.653.0 — 13.11.2026
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **Mail can be a meeting's notes.** A mail rule's `meeting_notes: "<provider>"` saves each email it matches as a
|
|
32
|
+
meeting of that provider too, in the account named by the mailbox's address, once at the end of every mail sync;
|
|
33
|
+
`saveMeetingNotes(store, address, rules, { since })` reads mail stored earlier the same way, and a provider that
|
|
34
|
+
fails is a warning, never a failed sync. The first provider is `telemost`: Yandex Telemost mails its notes from
|
|
35
|
+
`keeper@telemost.yandex.ru` (`MEETING_NOTES`). The notes give the day, not the hours, so the meeting takes its times
|
|
36
|
+
from the event it is linked to, or from the owner's one calendar entry in the same room that day (in Moscow's zone
|
|
37
|
+
or the computer's); otherwise it starts at the day's start with `metadata.time_precision: "day"`, and no event is
|
|
38
|
+
made for it. The saved notes are cleaned as calendar text is: links without their queries, passcode lines dropped.
|
|
39
|
+
- **`MeetingSource.createsEvents: false`** links a source's meetings to an event the owner already has and never
|
|
40
|
+
makes one; `linkEvent` takes `{ create: false }` for it.
|
|
41
|
+
- **`telemost` is a provider** (kind `meetings`).
|
|
42
|
+
|
|
8
43
|
## 0.652.0 — 13.11.2026
|
|
9
44
|
|
|
10
45
|
### Added
|
package/dist/cli/bot/mcp.js
CHANGED
|
@@ -3,7 +3,7 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
3
3
|
import { annotate, describeProgram } from "@wirecat/cli-base/commands";
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
import { environmentOf } from "../context.js";
|
|
6
|
-
import { changesAuthorityAt, LOCAL_READ, REMOTE_WRITE, readsOverMcpAt } from "../effects.js";
|
|
6
|
+
import { changesAuthorityAt, fetchesOnlyAt, LOCAL_READ, REMOTE_WRITE, readsOverMcpAt } from "../effects.js";
|
|
7
7
|
import { itemOf, renderAnswer } from "../envelope.js";
|
|
8
8
|
import { serverEntry } from "../messenger/mcp-command.js";
|
|
9
9
|
import { nextStep, rootOf } from "../steps.js";
|
|
@@ -38,6 +38,7 @@ export const botMcpCommand = (bot) => {
|
|
|
38
38
|
program: { run, commands: describeProgram(rootOf(this)) },
|
|
39
39
|
authority: changesAuthorityAt(rootOf(this)),
|
|
40
40
|
fetchOnly: readsOverMcpAt(rootOf(this)),
|
|
41
|
+
fetches: fetchesOnlyAt(rootOf(this)),
|
|
41
42
|
settings: context.settings,
|
|
42
43
|
levels: () => bot.resolveSettings(this.optsWithGlobals(), { env: context.env, kind: "bot" }).permissions,
|
|
43
44
|
env: context.env,
|
|
@@ -15,4 +15,6 @@ export interface CommandAvailability {
|
|
|
15
15
|
level?: Level;
|
|
16
16
|
}
|
|
17
17
|
/** Discovery and execution use the same permission decision. */
|
|
18
|
-
export declare const commandAvailability: (info: AvailabilityCommand, levels: Readonly<Record<PermissionKey, Level>>, keyOf?: (path: readonly string[]) => PermissionKey | null | undefined, authority?: (path: readonly string[]) => boolean, readOnly?: boolean, mcp?: boolean, declared?: CommandPermissions
|
|
18
|
+
export declare const commandAvailability: (info: AvailabilityCommand, levels: Readonly<Record<PermissionKey, Level>>, keyOf?: (path: readonly string[]) => PermissionKey | null | undefined, authority?: (path: readonly string[]) => boolean, readOnly?: boolean, mcp?: boolean, declared?: CommandPermissions,
|
|
19
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
|
|
20
|
+
fetches?: (path: readonly string[]) => boolean) => CommandAvailability;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { writes } from "@wirecat/cli-base/standards";
|
|
2
|
-
import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed, isBotApi, keyForCommand, levelFor, readKeysForCommand, } from "../sends/permissions.js";
|
|
2
|
+
import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed, CEILING_KEY, isBotApi, keyForCommand, levelFor, readKeysForCommand, } from "../sends/permissions.js";
|
|
3
3
|
import { changesMessenger } from "./effects.js";
|
|
4
4
|
/** Discovery and execution use the same permission decision. */
|
|
5
|
-
export const commandAvailability = (info, levels, keyOf, authority, readOnly = false, mcp = true, declared
|
|
5
|
+
export const commandAvailability = (info, levels, keyOf, authority, readOnly = false, mcp = true, declared,
|
|
6
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
|
|
7
|
+
fetches) => {
|
|
6
8
|
const declaredKey = declared?.keyOf(info.path);
|
|
7
9
|
const key = declared ? declaredKey : (keyOf?.(info.path) ?? keyForCommand(info.path));
|
|
8
|
-
const level = key ? levelFor(levels, key, declared?.defaults)
|
|
10
|
+
const { level, key: named } = key ? levelFor(levels, key, declared?.defaults) : { level: "allow", key: null };
|
|
9
11
|
const judged = { ...(key ? { permission: key } : {}), level };
|
|
10
12
|
const blocked = (reason, permission) => ({
|
|
11
13
|
available: false,
|
|
@@ -25,7 +27,7 @@ export const commandAvailability = (info, levels, keyOf, authority, readOnly = f
|
|
|
25
27
|
return blocked(`the profile requires ${BOT_API_KEY}: allow`, BOT_API_KEY);
|
|
26
28
|
if (level === "deny")
|
|
27
29
|
return blocked(`the profile denies ${key}`);
|
|
28
|
-
if (level === "readonly" && writes(info.effects))
|
|
30
|
+
if (level === "readonly" && writes(info.effects) && !(named === CEILING_KEY && fetches?.(info.path) === true))
|
|
29
31
|
return blocked(`${key} is readonly in this profile`);
|
|
30
32
|
const denied = (declared ? [] : readKeysForCommand(info.path)).find((read) => levelFor(levels, read).level === "deny");
|
|
31
33
|
return denied ? blocked(`the profile denies ${denied}`, denied) : { available: true, ...judged };
|
|
@@ -30,11 +30,11 @@ export declare const refuseWriteBeforeConnecting: (action: Command, { app, env,
|
|
|
30
30
|
}) => void;
|
|
31
31
|
/**
|
|
32
32
|
* A command of a CLI that declares its own keys (`commandPermissions`), refused by its key before anything connects:
|
|
33
|
-
* `deny` stops it, `readonly` stops a write
|
|
34
|
-
* declares no effects counts as both. `ask` is left to the write
|
|
35
|
-
* `--permission` key that names no command stops every keyed command;
|
|
36
|
-
* remove it. Under the lock a non-messenger CLI still previews a
|
|
37
|
-
* messenger's preview stays refused (SEC-65).
|
|
33
|
+
* `deny` stops it, `readonly` stops a write (setup's "read only" answer still lets a fetch into the store run), and
|
|
34
|
+
* the read-only lock stops a write to the service; a command that declares no effects counts as both. `ask` is left to the write
|
|
35
|
+
* guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
|
|
36
|
+
* housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
|
|
37
|
+
* `--dry-run`, which sends nothing (WC-PERM-12); a messenger's preview stays refused (SEC-65).
|
|
38
38
|
*/
|
|
39
39
|
export declare const refuseByCommandPermissions: (action: Command, permissions: CommandPermissions, { app, env, dryRun, resolve }: {
|
|
40
40
|
app: AppIdentity;
|
|
@@ -8,7 +8,7 @@ import { CEILING_KEY, keyForCommand, levelFor, writeOfKey } from "../sends/permi
|
|
|
8
8
|
import { newOperationId } from "../sends/send-id.js";
|
|
9
9
|
import { commandPathOf } from "./command-contract.js";
|
|
10
10
|
import { withAgentLevels } from "./context.js";
|
|
11
|
-
import { changesMessenger } from "./effects.js";
|
|
11
|
+
import { changesMessenger, fetchesOnly } from "./effects.js";
|
|
12
12
|
import { refuseUnknownPermissionKeys } from "./permission-keys.js";
|
|
13
13
|
import { NONE_NAMED, settingsFor } from "./settings.js";
|
|
14
14
|
/**
|
|
@@ -96,11 +96,11 @@ export const refuseWriteBeforeConnecting = (action, { app, env, dryRun, resolve
|
|
|
96
96
|
};
|
|
97
97
|
/**
|
|
98
98
|
* A command of a CLI that declares its own keys (`commandPermissions`), refused by its key before anything connects:
|
|
99
|
-
* `deny` stops it, `readonly` stops a write
|
|
100
|
-
* declares no effects counts as both. `ask` is left to the write
|
|
101
|
-
* `--permission` key that names no command stops every keyed command;
|
|
102
|
-
* remove it. Under the lock a non-messenger CLI still previews a
|
|
103
|
-
* messenger's preview stays refused (SEC-65).
|
|
99
|
+
* `deny` stops it, `readonly` stops a write (setup's "read only" answer still lets a fetch into the store run), and
|
|
100
|
+
* the read-only lock stops a write to the service; a command that declares no effects counts as both. `ask` is left to the write
|
|
101
|
+
* guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
|
|
102
|
+
* housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
|
|
103
|
+
* `--dry-run`, which sends nothing (WC-PERM-12); a messenger's preview stays refused (SEC-65).
|
|
104
104
|
*/
|
|
105
105
|
export const refuseByCommandPermissions = (action, permissions, { app, env, dryRun, resolve }) => {
|
|
106
106
|
const key = permissions.keyOf(commandPathOf(action));
|
|
@@ -126,7 +126,7 @@ export const refuseByCommandPermissions = (action, permissions, { app, env, dryR
|
|
|
126
126
|
throw new CliError("permission_error", `profile ${settings.profile} denies ${key} (permissions.${named} is deny, from the ` +
|
|
127
127
|
`${settings.permissionSources[named ?? ""] ?? "default"})`, { permission: key });
|
|
128
128
|
}
|
|
129
|
-
if (level === "readonly" && writes(effects))
|
|
129
|
+
if (level === "readonly" && writes(effects) && !(named === CEILING_KEY && fetchesOnly(action)))
|
|
130
130
|
throw levelRefusal({
|
|
131
131
|
profile: settings.profile,
|
|
132
132
|
command: app.command,
|
package/dist/cli/preview.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { metaOf } from "@wirecat/cli-base/commands";
|
|
3
3
|
import { writes as writesAnything } from "@wirecat/cli-base/standards";
|
|
4
|
-
import { keyForCommand, levelFor, readKeysForCommand, WRITE_KEYS } from "../sends/permissions.js";
|
|
4
|
+
import { CEILING_KEY, keyForCommand, levelFor, readKeysForCommand, WRITE_KEYS, } from "../sends/permissions.js";
|
|
5
5
|
import { commandPathOf } from "./command-contract.js";
|
|
6
|
+
import { fetchesOnly } from "./effects.js";
|
|
6
7
|
import { refuseUnknownPermissionKeys } from "./permission-keys.js";
|
|
7
8
|
export class PreviewComplete extends Error {
|
|
8
9
|
}
|
|
@@ -13,14 +14,17 @@ export const preview = (command, settings, tool, keys, messenger = true) => {
|
|
|
13
14
|
const keyOf = typeof keys === "object" ? keys.keyOf : keys;
|
|
14
15
|
refuseUnknownPermissionKeys(command, settings, tool, declared ?? (keyOf && ((one) => keyOf(commandPathOf(one)))));
|
|
15
16
|
const key = declared ? declared.keyOf(path) : (keyOf?.(path) ?? keyForCommand(path));
|
|
16
|
-
const level
|
|
17
|
+
const { level, key: named } = key
|
|
18
|
+
? levelFor(permissions, key, declared?.defaults)
|
|
19
|
+
: { level: "allow", key: null };
|
|
17
20
|
for (const source of declared ? [] : readKeysForCommand(path)) {
|
|
18
21
|
if (levelFor(permissions, source).level === "deny")
|
|
19
22
|
throw new CliError("permission_error", `this profile does not permit ${source}`, { permission: source });
|
|
20
23
|
}
|
|
21
24
|
const meta = metaOf(command);
|
|
22
|
-
const writes = (meta.effects !== undefined && writesAnything(meta.effects)) ||
|
|
23
|
-
(!declared && key !== null && key !== undefined && WRITE_KEYS.includes(key))
|
|
25
|
+
const writes = ((meta.effects !== undefined && writesAnything(meta.effects)) ||
|
|
26
|
+
(!declared && key !== null && key !== undefined && WRITE_KEYS.includes(key))) &&
|
|
27
|
+
!(named === CEILING_KEY && fetchesOnly(command));
|
|
24
28
|
if (level === "deny" || (writes && level === "readonly"))
|
|
25
29
|
throw new CliError("permission_error", `this profile does not permit ${path.join(" ")}`, { permission: key });
|
|
26
30
|
const also = (declared?.alsoChecks?.(path) ?? []).map((one) => {
|
package/dist/cli/program.js
CHANGED
|
@@ -24,7 +24,7 @@ import { exitCodeSet } from "./command-server-request.js";
|
|
|
24
24
|
import { entityRows } from "./compact.js";
|
|
25
25
|
import { outputFor, provide } from "./context.js";
|
|
26
26
|
import { refuseByCommandPermissions, refuseOfflineCommand, refuseWriteBeforeConnecting } from "./early-refusal.js";
|
|
27
|
-
import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, fileOptionOf, isLogin, isStoreChange, judgedEffects, judgedTargets, storeChangeRefusal, } from "./effects.js";
|
|
27
|
+
import { admittedUnderLock, changesAuthorityAt, changesAuthorityNow, fetchesOnlyAt, fileOptionOf, isLogin, isStoreChange, judgedEffects, judgedTargets, storeChangeRefusal, } from "./effects.js";
|
|
28
28
|
import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
|
|
29
29
|
import { byteCount, DEFAULT_AGENT_COOPERATIVE_MS, DEFAULT_COMMAND_MS, DEFAULT_COOPERATIVE_MS, DEFAULT_OUTPUT_BYTES, DEFAULT_SYNC_MS, execution, } from "./execution.js";
|
|
30
30
|
import { setupAtStart } from "./first-run.js";
|
|
@@ -277,14 +277,10 @@ const runOnce = async (argv, definition, options) => {
|
|
|
277
277
|
return undefined;
|
|
278
278
|
try {
|
|
279
279
|
const overrides = options.agent?.overrides ?? [];
|
|
280
|
-
const settings = (definition.configuration ?? settingsFor(definition.app)).resolveSettings(overrides.length ? { ...flags, permission: [...overrides, ...(flags.permission ?? [])] } : flags, {
|
|
281
|
-
env,
|
|
282
|
-
needsProfile: false,
|
|
283
|
-
kind: info.path[0] === "bot" || flags.bot ? "bot" : "personal",
|
|
284
|
-
});
|
|
280
|
+
const settings = (definition.configuration ?? settingsFor(definition.app)).resolveSettings(overrides.length ? { ...flags, permission: [...overrides, ...(flags.permission ?? [])] } : flags, { env, needsProfile: false, kind: info.path[0] === "bot" || flags.bot ? "bot" : "personal" });
|
|
285
281
|
if (!settings.permissions)
|
|
286
282
|
return undefined;
|
|
287
|
-
return commandAvailability(info, settings.permissions, definition.configuration?.permissionKey ?? definition.configuration?.permissions?.keyOf, changesAuthorityAt(program), readOnlyLockOf(definition.app, env) !== undefined, options.agent !== undefined, definition.configuration?.permissions);
|
|
283
|
+
return commandAvailability(info, settings.permissions, definition.configuration?.permissionKey ?? definition.configuration?.permissions?.keyOf, changesAuthorityAt(program), readOnlyLockOf(definition.app, env) !== undefined, options.agent !== undefined, definition.configuration?.permissions, fetchesOnlyAt(program));
|
|
288
284
|
}
|
|
289
285
|
catch {
|
|
290
286
|
// Help must still work when the configuration needs repair.
|
|
@@ -18,8 +18,9 @@ export declare const unanswered: (answers: SetupAnswers) => Question[];
|
|
|
18
18
|
/** A section written wrongly is replaced; a file that is not JSON at all still refuses, naming itself. */
|
|
19
19
|
export declare const writeSetupAnswers: (path: string, answers: SetupAnswers) => void;
|
|
20
20
|
/**
|
|
21
|
-
* The level no command of any WireCat tool goes above, or `undefined` when the owner
|
|
22
|
-
*
|
|
21
|
+
* The level no command of any WireCat tool goes above, or `undefined` when the owner did not choose "read only".
|
|
22
|
+
* Only that explicit answer limits: a missing, unreadable or malformed file leaves every tool as each profile
|
|
23
|
+
* allows, so a fresh install syncs (owner ruling, 2026-11-13).
|
|
23
24
|
*/
|
|
24
25
|
export declare const permissionCeiling: (path: string) => Level | undefined;
|
|
25
26
|
/** `permissionCeiling` of this machine's shared config, for a tool that keeps its own levels: add it as `CEILING_KEY`. */
|
|
@@ -33,18 +33,17 @@ export const writeSetupAnswers = (path, answers) => {
|
|
|
33
33
|
writeSharedSection(path, SECTION, { ...kept, ...answers });
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
|
-
* The level no command of any WireCat tool goes above, or `undefined` when the owner
|
|
37
|
-
*
|
|
36
|
+
* The level no command of any WireCat tool goes above, or `undefined` when the owner did not choose "read only".
|
|
37
|
+
* Only that explicit answer limits: a missing, unreadable or malformed file leaves every tool as each profile
|
|
38
|
+
* allows, so a fresh install syncs (owner ruling, 2026-11-13).
|
|
38
39
|
*/
|
|
39
40
|
export const permissionCeiling = (path) => {
|
|
40
|
-
let answer;
|
|
41
41
|
try {
|
|
42
|
-
|
|
42
|
+
return readSetupAnswers(path).permissions === "readonly" ? "readonly" : undefined;
|
|
43
43
|
}
|
|
44
44
|
catch {
|
|
45
|
-
return
|
|
45
|
+
return undefined;
|
|
46
46
|
}
|
|
47
|
-
return answer === "allow" ? undefined : answer;
|
|
48
47
|
};
|
|
49
48
|
/** `permissionCeiling` of this machine's shared config, for a tool that keeps its own levels: add it as `CEILING_KEY`. */
|
|
50
49
|
export const setupPermissionCeiling = (env = process.env) => permissionCeiling(sharedConfigPath(storePath(env), env));
|
package/dist/domain/providers.js
CHANGED
|
@@ -19,6 +19,8 @@ export const PROVIDERS = [
|
|
|
19
19
|
{ name: "obsidian", kind: "notes", aliases: [] },
|
|
20
20
|
{ name: "added", kind: "notes", aliases: [] },
|
|
21
21
|
{ name: "zoom", kind: "meetings", aliases: [] },
|
|
22
|
+
// Its meetings come from the notes Telemost mails (`keeper@telemost.yandex.ru`), read by a mail rule.
|
|
23
|
+
{ name: "telemost", kind: "meetings", aliases: [] },
|
|
22
24
|
// A phone export's records: its SMS and its calls in the one account the import names.
|
|
23
25
|
{ name: "phone", kind: "messages", kinds: ["messages", "events"], aliases: [], imported: true },
|
|
24
26
|
// Any other import: a folder of notes, a CRM's export, a script's records, under `import:<what it is>`.
|
|
@@ -34,6 +36,7 @@ const LABELS = {
|
|
|
34
36
|
"google-drive": "Google Drive",
|
|
35
37
|
added: "added by hand",
|
|
36
38
|
email: "mail",
|
|
39
|
+
telemost: "Telemost",
|
|
37
40
|
};
|
|
38
41
|
/** How a text names a provider to a person: `MAX`, not `max`. */
|
|
39
42
|
export const providerLabel = (provider) => LABELS[provider] ?? provider;
|
package/dist/kit/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export { ownCatalogue } from "./own-catalogue.js";
|
|
|
6
6
|
export { neverAnswers, type RunScopeCase, type RunScopeOptions, runScopeCases } from "./run-scope.js";
|
|
7
7
|
export { type SearchRecipes, searchRecipes, seedSearchRecipes } from "./search-recipes.js";
|
|
8
8
|
export { BUSY_PAGE, contractSeed, digitIds, type IdKind, type IdMaker, type Seed, wordIds } from "./seed.js";
|
|
9
|
+
export { type SyncAfterInstallCase, type SyncAfterInstallOptions, syncAfterInstallCases } from "./sync-after-install.js";
|
package/dist/kit/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { ownCatalogue } from "./own-catalogue.js";
|
|
|
6
6
|
export { neverAnswers, runScopeCases } from "./run-scope.js";
|
|
7
7
|
export { searchRecipes, seedSearchRecipes } from "./search-recipes.js";
|
|
8
8
|
export { BUSY_PAGE, contractSeed, digitIds, wordIds } from "./seed.js";
|
|
9
|
+
export { syncAfterInstallCases } from "./sync-after-install.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface SyncAfterInstallCase {
|
|
2
|
+
name: string;
|
|
3
|
+
/** Throws an `AssertionError` when the command is refused or fails. */
|
|
4
|
+
run(): Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
export interface SyncAfterInstallOptions {
|
|
7
|
+
/** The words that sync a signed-in profile against the CLI's fake service: `["work", "sync"]`. */
|
|
8
|
+
sync: readonly string[];
|
|
9
|
+
/**
|
|
10
|
+
* Runs the CLI as its own tests do, against its fake service, with `env` laid over the test's environment. A CLI
|
|
11
|
+
* on cli-core's program passes `run(argv, definition, { ...fakes, env: { ...process.env, ...env } })`.
|
|
12
|
+
*/
|
|
13
|
+
run: (argv: string[], env: NodeJS.ProcessEnv) => Promise<{
|
|
14
|
+
code: number;
|
|
15
|
+
err: string;
|
|
16
|
+
out?: string;
|
|
17
|
+
}>;
|
|
18
|
+
/** Words of a local-only change that the "read only" answer must still refuse, as a check it opens no more. */
|
|
19
|
+
refusedUnderReadOnly?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Cases that a CLI's sync runs right after install, whatever state the shared config is in. The kit points
|
|
23
|
+
* `WIRECAT_CONFIG_DIR` at a folder of its own, so the owner's config never hides the failure; the store is the one
|
|
24
|
+
* the CLI's own harness gives.
|
|
25
|
+
*/
|
|
26
|
+
export declare const syncAfterInstallCases: (options: SyncAfterInstallOptions) => SyncAfterInstallCase[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
/**
|
|
6
|
+
* The shared config (`~/.config/WireCat/config.json`) as a fresh or damaged machine has it. Only an explicit
|
|
7
|
+
* "read only" answer limits a tool, and even then a sync runs: it only reads the service (owner ruling, 2026-11-13).
|
|
8
|
+
*/
|
|
9
|
+
const SHARED_CONFIGS = [
|
|
10
|
+
{ state: "no shared config, as on a fresh install" },
|
|
11
|
+
{ state: "a shared config that is not JSON", write: (dir) => writeFileSync(join(dir, "config.json"), "{ setup: ") },
|
|
12
|
+
{
|
|
13
|
+
state: "a shared config with a byte-order mark",
|
|
14
|
+
write: (dir) => writeFileSync(join(dir, "config.json"), '{"setup":{"permissions":"allow"}}'),
|
|
15
|
+
},
|
|
16
|
+
{ state: "a folder where the shared config should be", write: (dir) => mkdirSync(join(dir, "config.json")) },
|
|
17
|
+
{
|
|
18
|
+
state: "a setup section in a shape this version does not take",
|
|
19
|
+
write: (dir) => writeFileSync(join(dir, "config.json"), JSON.stringify({ setup: { languages: ["en"], permissions: "ask" } })),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
state: 'the explicit "read only" answer',
|
|
23
|
+
write: (dir) => writeFileSync(join(dir, "config.json"), JSON.stringify({ setup: { permissions: "readonly" } })),
|
|
24
|
+
readOnly: true,
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
const errorCodeOf = (text) => {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(text.trim()).error?.code;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Cases that a CLI's sync runs right after install, whatever state the shared config is in. The kit points
|
|
37
|
+
* `WIRECAT_CONFIG_DIR` at a folder of its own, so the owner's config never hides the failure; the store is the one
|
|
38
|
+
* the CLI's own harness gives.
|
|
39
|
+
*/
|
|
40
|
+
export const syncAfterInstallCases = (options) => {
|
|
41
|
+
const { sync, refusedUnderReadOnly } = options;
|
|
42
|
+
const cli = async (argv, shared) => {
|
|
43
|
+
const configDir = mkdtempSync(join(tmpdir(), "sync-after-install-"));
|
|
44
|
+
shared.write?.(configDir);
|
|
45
|
+
const ran = await options.run(argv.includes("--json") ? [...argv] : [...argv, "--json"], {
|
|
46
|
+
WIRECAT_CONFIG_DIR: configDir,
|
|
47
|
+
});
|
|
48
|
+
return { code: ran.code, out: ran.out ?? "", err: ran.err };
|
|
49
|
+
};
|
|
50
|
+
return [
|
|
51
|
+
...SHARED_CONFIGS.map((shared) => ({
|
|
52
|
+
name: `${sync.join(" ")} runs with ${shared.state}`,
|
|
53
|
+
run: async () => {
|
|
54
|
+
const ran = await cli(sync, shared);
|
|
55
|
+
assert.notEqual(errorCodeOf(ran.err), "permission_error", `sync was refused: ${ran.err}`);
|
|
56
|
+
assert.equal(ran.code, 0, `sync exited ${ran.code}: ${ran.out}${ran.err}`);
|
|
57
|
+
},
|
|
58
|
+
})),
|
|
59
|
+
...(refusedUnderReadOnly
|
|
60
|
+
? [
|
|
61
|
+
{
|
|
62
|
+
name: `${refusedUnderReadOnly.join(" ")} is still refused under the explicit "read only" answer`,
|
|
63
|
+
run: async () => {
|
|
64
|
+
const readOnly = SHARED_CONFIGS.find((one) => one.readOnly);
|
|
65
|
+
const ran = await cli(refusedUnderReadOnly, readOnly);
|
|
66
|
+
assert.equal(errorCodeOf(ran.err), "permission_error", `it was not refused: ${ran.out}${ran.err}`);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
]
|
|
70
|
+
: []),
|
|
71
|
+
];
|
|
72
|
+
};
|
package/dist/mail/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { type AuthVerdicts, HEADER_FIELDS, headersOf, type MailHeaders, mailHead
|
|
|
10
10
|
export { type MailIdsInput, mailIds } from "./ids.js";
|
|
11
11
|
export { decodedLabelName, decodeMailboxName, labelName, systemLabel } from "./labels.js";
|
|
12
12
|
export { acknowledgeMark, advancePastSkipped, type BulkExcerpt, cursorOf, HOLD_PARTIAL_MS, HOLDER, MARK_BATCH, type MailMark, type MailWaiting, type MarkedHit, type MarkRead, type MarkRewind, mailWaiting, markOf, marksOf, type RewoundMark, readPastMark, rewindMark, type SkipReason, } from "./marks.js";
|
|
13
|
+
export { MEETING_NOTES, MEETING_NOTES_PROVIDERS, mailMeetingSource, notesOf, saveMeetingNotes, } from "./meeting-notes.js";
|
|
13
14
|
export { BULK_TRIAGE_DEFAULTS, type BulkSorted, type BulkTriage, excerptOf, NEWSLETTER_DEFAULTS, NEWSLETTER_SENDERS, NEWSLETTER_WORDS, type NewsletterCues, newsletterSorter, ORDER_WORDS, } from "./newsletter.js";
|
|
14
15
|
export { type MailTurn, mailTurn } from "./owed.js";
|
|
15
16
|
export { type Address, htmlToText, looksLikeHtml, MAX_ATTACHMENTS, MAX_BODY_CHARS, type ParsedMail, parseMail, } from "./parse.js";
|
package/dist/mail/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export { HEADER_FIELDS, headersOf, mailHeadersOf } from "./headers.js";
|
|
|
10
10
|
export { mailIds } from "./ids.js";
|
|
11
11
|
export { decodedLabelName, decodeMailboxName, labelName, systemLabel } from "./labels.js";
|
|
12
12
|
export { acknowledgeMark, advancePastSkipped, cursorOf, HOLD_PARTIAL_MS, HOLDER, MARK_BATCH, mailWaiting, markOf, marksOf, readPastMark, rewindMark, } from "./marks.js";
|
|
13
|
+
export { MEETING_NOTES, MEETING_NOTES_PROVIDERS, mailMeetingSource, notesOf, saveMeetingNotes, } from "./meeting-notes.js";
|
|
13
14
|
export { BULK_TRIAGE_DEFAULTS, excerptOf, NEWSLETTER_DEFAULTS, NEWSLETTER_SENDERS, NEWSLETTER_WORDS, newsletterSorter, ORDER_WORDS, } from "./newsletter.js";
|
|
14
15
|
export { mailTurn } from "./owed.js";
|
|
15
16
|
export { htmlToText, looksLikeHtml, MAX_ATTACHMENTS, MAX_BODY_CHARS, parseMail, } from "./parse.js";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type MeetingSource, type MeetingStore, type RunReport, type SummaryContent } from "../meetings/index.js";
|
|
2
|
+
import type { MessageStore } from "../store/index.js";
|
|
3
|
+
import { type MailRule } from "./rules.js";
|
|
4
|
+
interface NotesKind {
|
|
5
|
+
/** Who mails them: what `rules add --meeting-notes <provider>` matches when no sender is given. */
|
|
6
|
+
senders: readonly string[];
|
|
7
|
+
/** The meeting's day, from the subject; null when the subject does not say. */
|
|
8
|
+
day(subject: string): {
|
|
9
|
+
year: number;
|
|
10
|
+
month: number;
|
|
11
|
+
day: number;
|
|
12
|
+
} | null;
|
|
13
|
+
/**
|
|
14
|
+
* The UTC offsets, in hours, the subject's day may be written in. The day window spans all of them and the
|
|
15
|
+
* computer's own zone, so a meeting just after midnight in one is still found.
|
|
16
|
+
*/
|
|
17
|
+
offsets: readonly number[];
|
|
18
|
+
/** The headings the notes are split under, in the case they are written. */
|
|
19
|
+
headings: readonly string[];
|
|
20
|
+
overview: string;
|
|
21
|
+
}
|
|
22
|
+
/** The meeting-notes mail each provider sends. A provider not here cannot be named by a rule. */
|
|
23
|
+
export declare const MEETING_NOTES: Readonly<Record<string, NotesKind>>;
|
|
24
|
+
export declare const MEETING_NOTES_PROVIDERS: string[];
|
|
25
|
+
/** The notes cut at their headings; text before the first heading stays only in `content`. */
|
|
26
|
+
export declare const notesOf: (text: string, kind: Pick<NotesKind, "headings" | "overview">) => SummaryContent;
|
|
27
|
+
/**
|
|
28
|
+
* Meetings read from stored mail a meeting-notes rule matches, for `pull`. The notes give the day, not the hours:
|
|
29
|
+
* the event the meeting is already linked to, or the one event in the same room that day, gives its times; otherwise
|
|
30
|
+
* it starts at the day's start, says so in `metadata.time_precision`, and no event is made for it.
|
|
31
|
+
*/
|
|
32
|
+
export declare const mailMeetingSource: ({ store, meetings, address, rules, provider, accountId, }: {
|
|
33
|
+
store: MessageStore;
|
|
34
|
+
meetings: Pick<MeetingStore, "eventCandidates" | "meetings" | "events">;
|
|
35
|
+
address: string;
|
|
36
|
+
rules: readonly MailRule[];
|
|
37
|
+
provider: string;
|
|
38
|
+
/** The provider's account the meetings are saved in; absent before its first save. */
|
|
39
|
+
accountId?: number;
|
|
40
|
+
}) => MeetingSource;
|
|
41
|
+
/**
|
|
42
|
+
* Saves as meetings the stored mail each meeting-notes rule matches, from `since`, into the provider's account named
|
|
43
|
+
* by the mailbox's address. Mail stored before the rule was made is read the same way, with an early `since`. A
|
|
44
|
+
* provider that fails is a warning in its report: the mail it was read from is already saved.
|
|
45
|
+
*/
|
|
46
|
+
export declare const saveMeetingNotes: (store: MessageStore, address: string, rules: readonly MailRule[], { since, now }: {
|
|
47
|
+
since: string;
|
|
48
|
+
now?: number;
|
|
49
|
+
}) => Promise<Record<string, RunReport>>;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { calendarText, joinKeyOf, pull, } from "../meetings/index.js";
|
|
3
|
+
import { mailAccountKey } from "./account-key.js";
|
|
4
|
+
import { factsOf } from "./facts.js";
|
|
5
|
+
import { matches } from "./rules.js";
|
|
6
|
+
import { listedOf } from "./stored.js";
|
|
7
|
+
const HOUR_MS = 3_600_000;
|
|
8
|
+
const DAY_MS = 24 * HOUR_MS;
|
|
9
|
+
/** The meeting-notes mail each provider sends. A provider not here cannot be named by a rule. */
|
|
10
|
+
export const MEETING_NOTES = {
|
|
11
|
+
telemost: {
|
|
12
|
+
senders: ["keeper@telemost.yandex.ru"],
|
|
13
|
+
day: (subject) => {
|
|
14
|
+
const found = /(\d{2})\.(\d{2})\.(\d{4})/u.exec(subject);
|
|
15
|
+
return found ? { day: Number(found[1]), month: Number(found[2]), year: Number(found[3]) } : null;
|
|
16
|
+
},
|
|
17
|
+
// Moscow, Yandex's default; the zone of the owner's Yandex account is not known here.
|
|
18
|
+
offsets: [3],
|
|
19
|
+
headings: ["Итоги", "Что обсудили", "Задачи", "Открытые вопросы", "Следующая встреча"],
|
|
20
|
+
overview: "Итоги",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
export const MEETING_NOTES_PROVIDERS = Object.keys(MEETING_NOTES);
|
|
24
|
+
const LINK = /https?:\/\/[^\s<>"')\]]+/giu;
|
|
25
|
+
const textOf = (email) => calendarText(email.bodyText?.trim() ? email.bodyText : email.bodyHtml)?.replace(/\r\n?/gu, "\n") ?? "";
|
|
26
|
+
const headingOf = (line, headings) => {
|
|
27
|
+
const plain = line
|
|
28
|
+
.replace(/^(?:[\s#*>-]|\p{Extended_Pictographic}|️)+/u, "")
|
|
29
|
+
.replace(/[\s:*]+$/u, "")
|
|
30
|
+
.toLowerCase();
|
|
31
|
+
return headings.find((heading) => heading.toLowerCase() === plain);
|
|
32
|
+
};
|
|
33
|
+
/** The notes cut at their headings; text before the first heading stays only in `content`. */
|
|
34
|
+
export const notesOf = (text, kind) => {
|
|
35
|
+
const parts = [];
|
|
36
|
+
for (const line of text.split("\n")) {
|
|
37
|
+
const heading = headingOf(line, kind.headings);
|
|
38
|
+
if (heading !== undefined)
|
|
39
|
+
parts.push({ label: heading, lines: [] });
|
|
40
|
+
else
|
|
41
|
+
parts.at(-1)?.lines.push(line);
|
|
42
|
+
}
|
|
43
|
+
const sections = parts
|
|
44
|
+
.map(({ label, lines }) => ({ label, text: lines.join("\n").trim() }))
|
|
45
|
+
.filter(({ text }) => text !== "");
|
|
46
|
+
return {
|
|
47
|
+
title: null,
|
|
48
|
+
overview: sections.find(({ label }) => label === kind.overview)?.text ?? null,
|
|
49
|
+
sections: sections.filter(({ label }) => label !== kind.overview),
|
|
50
|
+
nextSteps: [],
|
|
51
|
+
content: text.trim() || null,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** The first link in the notes that names a meeting room, as `joinKeyOf` reads it: never a plain page link. */
|
|
55
|
+
const roomOf = (text) => {
|
|
56
|
+
for (const [url] of text.matchAll(LINK))
|
|
57
|
+
if (/\/j\/[^/]+$/u.test(url) && joinKeyOf(url))
|
|
58
|
+
return url;
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
/** The day as a window: from its first midnight in any of the zones to its last. */
|
|
62
|
+
const dayWindow = (kind, date) => {
|
|
63
|
+
const local = new Date(date.year, date.month - 1, date.day).getTime();
|
|
64
|
+
const utc = Date.UTC(date.year, date.month - 1, date.day);
|
|
65
|
+
const starts = [local, ...kind.offsets.map((offset) => utc - offset * HOUR_MS)];
|
|
66
|
+
const start = starts.reduce((low, at) => Math.min(low, at));
|
|
67
|
+
const end = starts.reduce((high, at) => Math.max(high, at)) + DAY_MS;
|
|
68
|
+
return { start, end, local };
|
|
69
|
+
};
|
|
70
|
+
/** The stored mail the rules can be matching: by sender when every rule names one, else the whole window. */
|
|
71
|
+
const candidateFacts = async (store, accountId, since, rules) => {
|
|
72
|
+
const senders = rules.map(({ match }) => match.from);
|
|
73
|
+
if (senders.some((sender) => sender === undefined))
|
|
74
|
+
return store.mail.emailFacts({ accountId, since });
|
|
75
|
+
const found = new Map();
|
|
76
|
+
for (const sender of new Set(senders))
|
|
77
|
+
for (const facts of await store.mail.emailFacts({ accountId, since, participant: sender }))
|
|
78
|
+
found.set(facts.externalId, facts);
|
|
79
|
+
return [...found.values()];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Meetings read from stored mail a meeting-notes rule matches, for `pull`. The notes give the day, not the hours:
|
|
83
|
+
* the event the meeting is already linked to, or the one event in the same room that day, gives its times; otherwise
|
|
84
|
+
* it starts at the day's start, says so in `metadata.time_precision`, and no event is made for it.
|
|
85
|
+
*/
|
|
86
|
+
export const mailMeetingSource = ({ store, meetings, address, rules, provider, accountId, }) => {
|
|
87
|
+
const kind = MEETING_NOTES[provider];
|
|
88
|
+
const ruling = rules.filter((rule) => rule.meeting_notes === provider);
|
|
89
|
+
const notes = new Map();
|
|
90
|
+
const none = async () => null;
|
|
91
|
+
return {
|
|
92
|
+
provider,
|
|
93
|
+
name: "mail",
|
|
94
|
+
createsEvents: false,
|
|
95
|
+
async meetings(since) {
|
|
96
|
+
if (kind === undefined || ruling.length === 0)
|
|
97
|
+
return [];
|
|
98
|
+
const stored = await store.accounts.storedAccount(mailAccountKey(address)).catch((error) => {
|
|
99
|
+
if (error instanceof CliError && error.code === "not_found")
|
|
100
|
+
return null;
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
if (stored === null)
|
|
104
|
+
return [];
|
|
105
|
+
const listed = (await candidateFacts(store, stored.id, Date.parse(since), ruling)).map(listedOf);
|
|
106
|
+
const factsFor = factsOf(listed, ruling);
|
|
107
|
+
const saved = accountId === undefined ? [] : await meetings.meetings({ accountId, includeDeleted: true });
|
|
108
|
+
const linked = new Map(saved.flatMap(({ externalId, eventId }) => (eventId === null ? [] : [[externalId, eventId]])));
|
|
109
|
+
const events = new Map(linked.size ? (await meetings.events()).map((event) => [event.id, event]) : []);
|
|
110
|
+
const found = [];
|
|
111
|
+
for (const item of listed) {
|
|
112
|
+
if (!ruling.some((rule) => matches(rule.match, factsFor(item))))
|
|
113
|
+
continue;
|
|
114
|
+
const email = await store.mail.email(stored.id, item.messageId);
|
|
115
|
+
if (email === null || email.deletedAt !== null)
|
|
116
|
+
continue;
|
|
117
|
+
const subject = email.subject ?? "";
|
|
118
|
+
const sent = email.sentAt ?? email.receivedAt;
|
|
119
|
+
const date = kind.day(subject) ??
|
|
120
|
+
(sent === null
|
|
121
|
+
? null
|
|
122
|
+
: {
|
|
123
|
+
year: new Date(sent).getFullYear(),
|
|
124
|
+
month: new Date(sent).getMonth() + 1,
|
|
125
|
+
day: new Date(sent).getDate(),
|
|
126
|
+
});
|
|
127
|
+
if (date === null)
|
|
128
|
+
continue;
|
|
129
|
+
const window = dayWindow(kind, date);
|
|
130
|
+
if (!Number.isFinite(window.local))
|
|
131
|
+
continue;
|
|
132
|
+
const text = textOf(email);
|
|
133
|
+
const joinUrl = roomOf(text);
|
|
134
|
+
const linkedId = linked.get(email.externalId);
|
|
135
|
+
const linkedEvent = linkedId === undefined ? undefined : events.get(linkedId);
|
|
136
|
+
const candidates = linkedEvent !== undefined || joinUrl === null
|
|
137
|
+
? []
|
|
138
|
+
: await meetings.eventCandidates({
|
|
139
|
+
meetingSeriesId: null,
|
|
140
|
+
joinUrl,
|
|
141
|
+
startsAt: window.start,
|
|
142
|
+
endsAt: window.end,
|
|
143
|
+
});
|
|
144
|
+
const timed = linkedEvent ?? (candidates.length === 1 ? candidates[0] : undefined);
|
|
145
|
+
const startsAt = timed?.startsAt ?? null;
|
|
146
|
+
const meeting = {
|
|
147
|
+
joinUrl,
|
|
148
|
+
metadata: { email: email.externalId, time_precision: startsAt === null ? "day" : "event" },
|
|
149
|
+
series: null,
|
|
150
|
+
occurrence: {
|
|
151
|
+
id: email.externalId,
|
|
152
|
+
seriesId: email.externalId,
|
|
153
|
+
title: timed?.title ?? (subject || null),
|
|
154
|
+
startedAt: new Date(startsAt ?? window.local).toISOString(),
|
|
155
|
+
endedAt: startsAt === null || timed?.endsAt == null ? null : new Date(timed.endsAt).toISOString(),
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
notes.set(email.externalId, { meeting, summary: notesOf(text, kind) });
|
|
159
|
+
found.push(meeting);
|
|
160
|
+
}
|
|
161
|
+
return found;
|
|
162
|
+
},
|
|
163
|
+
participants: none,
|
|
164
|
+
transcript: none,
|
|
165
|
+
chat: none,
|
|
166
|
+
summary: async (id) => notes.get(id)?.summary ?? null,
|
|
167
|
+
files: none,
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Saves as meetings the stored mail each meeting-notes rule matches, from `since`, into the provider's account named
|
|
172
|
+
* by the mailbox's address. Mail stored before the rule was made is read the same way, with an early `since`. A
|
|
173
|
+
* provider that fails is a warning in its report: the mail it was read from is already saved.
|
|
174
|
+
*/
|
|
175
|
+
export const saveMeetingNotes = async (store, address, rules, { since, now = Date.now() }) => {
|
|
176
|
+
const reports = {};
|
|
177
|
+
for (const provider of new Set(rules.flatMap(({ meeting_notes }) => (meeting_notes ? [meeting_notes] : [])))) {
|
|
178
|
+
if (MEETING_NOTES[provider] === undefined)
|
|
179
|
+
continue;
|
|
180
|
+
try {
|
|
181
|
+
const key = { provider, account: address.toLowerCase() };
|
|
182
|
+
const accountId = await store.accounts.saveAccount(key, { name: address.toLowerCase() });
|
|
183
|
+
const source = mailMeetingSource({ store, meetings: store.meetings, address, rules, provider, accountId });
|
|
184
|
+
reports[provider] = await pull(source, store.meetings, { accountId, since, now });
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
const message = error instanceof Error ? error.message : "meeting notes could not be saved";
|
|
188
|
+
reports[provider] = {
|
|
189
|
+
meetings: 0,
|
|
190
|
+
participants: 0,
|
|
191
|
+
transcriptRows: 0,
|
|
192
|
+
summaries: 0,
|
|
193
|
+
warnings: [{ externalId: "", message }],
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return reports;
|
|
198
|
+
};
|
package/dist/mail/rule-input.js
CHANGED
|
@@ -24,6 +24,7 @@ export const ruleInput = (rule, source = rule.source ?? "owner") => ({
|
|
|
24
24
|
store: STORE_ACTION[rule.action],
|
|
25
25
|
...(rule.tags?.length ? { tags: rule.tags } : {}),
|
|
26
26
|
...(rule.tags_skipped && Object.keys(rule.tags_skipped).length ? { tags_skipped: rule.tags_skipped } : {}),
|
|
27
|
+
...(rule.meeting_notes ? { meeting_notes: rule.meeting_notes } : {}),
|
|
27
28
|
},
|
|
28
29
|
protected: rule.protected === true,
|
|
29
30
|
source,
|
package/dist/mail/rule-stored.js
CHANGED
|
@@ -41,11 +41,13 @@ export const storedMailRule = (stored) => {
|
|
|
41
41
|
const tagsSkipped = skipped !== null && typeof skipped === "object" && !Array.isArray(skipped)
|
|
42
42
|
? Object.fromEntries(Object.entries(skipped).filter(([, why]) => typeof why === "string"))
|
|
43
43
|
: {};
|
|
44
|
+
const meetingNotes = stored.actions.meeting_notes;
|
|
44
45
|
return {
|
|
45
46
|
id: stored.id,
|
|
46
47
|
match: Object.fromEntries(entries),
|
|
47
48
|
action,
|
|
48
49
|
...(tags.length ? { tags: tags } : {}),
|
|
50
|
+
...(typeof meetingNotes === "string" && meetingNotes ? { meeting_notes: meetingNotes } : {}),
|
|
49
51
|
...(Object.keys(tagsSkipped).length ? { tags_skipped: tagsSkipped } : {}),
|
|
50
52
|
...(stored.reason === null ? {} : { reason: stored.reason }),
|
|
51
53
|
...(stored.protected ? { protected: true } : {}),
|
package/dist/mail/rules.d.ts
CHANGED
|
@@ -39,6 +39,8 @@ export interface MailRule {
|
|
|
39
39
|
reason?: string;
|
|
40
40
|
/** Stored in full, and no cleanup may cut, archive or trash it, whatever other rules or presets say. */
|
|
41
41
|
protected?: boolean;
|
|
42
|
+
/** The mail is a meeting's notes from this provider (`telemost`): each email it matches is saved as a meeting too. */
|
|
43
|
+
meeting_notes?: string;
|
|
42
44
|
/** owner, preset:<name>, probe or gmail-filter. */
|
|
43
45
|
source?: string;
|
|
44
46
|
decided_at: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BudgetStop, RunBudget } from "../background/budget.js";
|
|
2
|
+
import type { RunReport } from "../meetings/index.js";
|
|
2
3
|
import type { LoadEngine } from "../readers/types.js";
|
|
3
4
|
import type { AccountKey, MessageStore } from "../store/index.js";
|
|
4
5
|
import type { MailAttachmentPolicy } from "./attachments.js";
|
|
@@ -78,6 +79,8 @@ export interface MailSyncResult {
|
|
|
78
79
|
stillFailed: number;
|
|
79
80
|
missing: number;
|
|
80
81
|
};
|
|
82
|
+
/** Per provider, the meetings saved from mail a meeting-notes rule matches. */
|
|
83
|
+
meetingNotes?: Record<string, RunReport>;
|
|
81
84
|
}
|
|
82
85
|
export interface MailSyncOptions {
|
|
83
86
|
account: MailAccount;
|
package/dist/mail/sync.js
CHANGED
|
@@ -11,6 +11,7 @@ import { GMAIL_ALL_MAIL, mailFolders } from "./folders.js";
|
|
|
11
11
|
import { dropMissing, tooManyGone } from "./gone.js";
|
|
12
12
|
import { mailHeadersOf } from "./headers.js";
|
|
13
13
|
import { flagsToRefresh, proveByLocation } from "./locations.js";
|
|
14
|
+
import { saveMeetingNotes } from "./meeting-notes.js";
|
|
14
15
|
import { MAX_BODY_CHARS, parseMail } from "./parse.js";
|
|
15
16
|
import { completePartial } from "./partial.js";
|
|
16
17
|
import { FETCH_SLICE, keyOf, readQuick } from "./quick.js";
|
|
@@ -36,6 +37,17 @@ const LIST_SLICE = 200;
|
|
|
36
37
|
const STORE_BUSY_TRIES = 5;
|
|
37
38
|
const STORE_BUSY_WAIT_MS = 2_000;
|
|
38
39
|
export const syncMail = async (source, store, options) => {
|
|
40
|
+
const result = await syncAndComplete(source, store, options);
|
|
41
|
+
const rules = options.account.rules ?? [];
|
|
42
|
+
if (!rules.some(({ meeting_notes }) => meeting_notes) || options.signal?.aborted)
|
|
43
|
+
return result;
|
|
44
|
+
const now = (options.now ?? Date.now)();
|
|
45
|
+
return {
|
|
46
|
+
...result,
|
|
47
|
+
meetingNotes: await saveMeetingNotes(store, options.account.address, rules, { since: result.since, now }),
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const syncAndComplete = async (source, store, options) => {
|
|
39
51
|
const result = await syncRounds(source, store, options);
|
|
40
52
|
if (options.completePartial === false || options.retryAttachments || options.account.mode === "mbox")
|
|
41
53
|
return result;
|
package/dist/mcp/agent.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface AgentContext {
|
|
|
27
27
|
/** A declared CLI's keys and defaults (`configuration.permissions`); in place of `keyOf`. */
|
|
28
28
|
permissions?: CommandPermissions | undefined;
|
|
29
29
|
authority?: CatalogueOptions["authority"];
|
|
30
|
+
fetches?: CatalogueOptions["fetches"];
|
|
30
31
|
/** The server's one open connection. The command borrows it: it cannot close it, and never opens its own. */
|
|
31
32
|
connection?: () => Promise<MessengerAdapter>;
|
|
32
33
|
/** What a command reads on stdin, as the field an agent gives it in. */
|
|
@@ -74,6 +75,8 @@ export interface CatalogueOptions {
|
|
|
74
75
|
authority?: (path: readonly string[]) => boolean;
|
|
75
76
|
/** Whether a command only fetches into this machine (`fetchesOnlyAt`): offered as a read. Unset, every write stays one. */
|
|
76
77
|
fetchOnly?: (path: readonly string[]) => boolean;
|
|
78
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
|
|
79
|
+
fetches?: (path: readonly string[]) => boolean;
|
|
77
80
|
/** Arguments left out of every tool, by name. */
|
|
78
81
|
omit?: readonly string[];
|
|
79
82
|
/** Offer `offline` on commands that read the messenger: answer from the copy on this machine. */
|
package/dist/mcp/agent.js
CHANGED
|
@@ -148,7 +148,7 @@ const keywordsOf = (examples) => [
|
|
|
148
148
|
...new Set(examples.flatMap((example) => example.split(/\s+/u).filter((word) => word !== "" && !word.startsWith("-")))),
|
|
149
149
|
];
|
|
150
150
|
export const toolsFromCommands = (commands, options = {}) => {
|
|
151
|
-
const { root = [], exclude = [], levels, keyOf, authority, readOnly = false, permissions } = options;
|
|
151
|
+
const { root = [], exclude = [], levels, keyOf, authority, readOnly = false, permissions, fetches } = options;
|
|
152
152
|
return flatten(commands)
|
|
153
153
|
.filter((info) =>
|
|
154
154
|
// A group is offered only when it runs on its own; without an action it only prints its help.
|
|
@@ -162,9 +162,10 @@ export const toolsFromCommands = (commands, options = {}) => {
|
|
|
162
162
|
(!(readOnly && (changesMessenger(info) || authority?.(info.path))) &&
|
|
163
163
|
(levels === undefined && !(readOnly && permissions)
|
|
164
164
|
? true
|
|
165
|
-
: commandAvailability(info, levels ?? {}, keyOf, authority, readOnly, true, permissions)
|
|
165
|
+
: commandAvailability(info, levels ?? {}, keyOf, authority, readOnly, true, permissions, fetches)
|
|
166
|
+
.available))))
|
|
166
167
|
.map((info) => ({
|
|
167
|
-
availability: () => commandAvailability(info, options.currentLevels?.() ?? levels ?? {}, keyOf, authority, readOnly, true, permissions),
|
|
168
|
+
availability: () => commandAvailability(info, options.currentLevels?.() ?? levels ?? {}, keyOf, authority, readOnly, true, permissions, fetches),
|
|
168
169
|
command: info.path.slice(root.length).join(" "),
|
|
169
170
|
path: info.path,
|
|
170
171
|
title: info.summary ?? info.description,
|
|
@@ -217,7 +218,7 @@ export const runCommandForAgent = async (program, path, input, ctx) => {
|
|
|
217
218
|
throw new CliError("validation_error", `"${path.join(" ")}" runs until it is stopped; an agent call must return`);
|
|
218
219
|
const levels = ctx.levels?.();
|
|
219
220
|
const availability = (levels || ctx.readOnly || ctx.permissions) &&
|
|
220
|
-
commandAvailability(info, levels ?? {}, ctx.keyOf, ctx.authority, ctx.readOnly, true, ctx.permissions);
|
|
221
|
+
commandAvailability(info, levels ?? {}, ctx.keyOf, ctx.authority, ctx.readOnly, true, ctx.permissions, ctx.fetches);
|
|
221
222
|
if (availability && !availability.available)
|
|
222
223
|
throw new CliError("permission_error", `${path.join(" ")}: ${availability.reason}`, {
|
|
223
224
|
sent: false,
|
package/dist/mcp/app-server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { CliError, mcpErrorResult } from "@wirecat/cli-base";
|
|
|
4
4
|
import { describeProgram } from "@wirecat/cli-base/commands";
|
|
5
5
|
import { skillResource } from "@wirecat/cli-base/skill";
|
|
6
6
|
import { environmentOf } from "../cli/context.js";
|
|
7
|
-
import { changesAuthorityAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
|
|
7
|
+
import { changesAuthorityAt, fetchesOnlyAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
|
|
8
8
|
import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
|
|
9
9
|
import { rootOf } from "../cli/steps.js";
|
|
10
10
|
import { mcpUrlOf } from "../http/public-url.js";
|
|
@@ -45,6 +45,7 @@ export const createAppServer = (command, context, options) => {
|
|
|
45
45
|
const levels = () => options.resolveSettings(flags, { env: context.env }).permissions;
|
|
46
46
|
const readOnly = () => readOnlyLockOf(app, context.env) !== undefined;
|
|
47
47
|
const authority = changesAuthorityAt(root);
|
|
48
|
+
const fetches = fetchesOnlyAt(root);
|
|
48
49
|
const targets = judgedTargets(root);
|
|
49
50
|
const passed = Object.fromEntries(Object.entries(environment).filter(([key]) => !PER_RUN.has(key)));
|
|
50
51
|
const tools = toolsFromCommands(program.commands, {
|
|
@@ -55,6 +56,7 @@ export const createAppServer = (command, context, options) => {
|
|
|
55
56
|
readOnly: readOnly(),
|
|
56
57
|
authority,
|
|
57
58
|
fetchOnly: readsOverMcpAt(root),
|
|
59
|
+
fetches,
|
|
58
60
|
permissions: options.permissions,
|
|
59
61
|
});
|
|
60
62
|
const availability = (one) => () => {
|
|
@@ -88,6 +90,7 @@ export const createAppServer = (command, context, options) => {
|
|
|
88
90
|
levels,
|
|
89
91
|
overrides,
|
|
90
92
|
authority,
|
|
93
|
+
fetches,
|
|
91
94
|
permissions: options.permissions,
|
|
92
95
|
environment: passed,
|
|
93
96
|
});
|
package/dist/mcp/bot/server.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export interface BotServerOptions {
|
|
|
18
18
|
authority?: (path: readonly string[]) => boolean;
|
|
19
19
|
/** Whether a command only fetches into this machine (`fetchesOnlyAt`): offered through the read tool. */
|
|
20
20
|
fetchOnly?: (path: readonly string[]) => boolean;
|
|
21
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): setup's "read only" answer lets it run. */
|
|
22
|
+
fetches?: (path: readonly string[]) => boolean;
|
|
21
23
|
env: NodeJS.ProcessEnv;
|
|
22
24
|
skill?: URL;
|
|
23
25
|
}
|
package/dist/mcp/bot/server.js
CHANGED
|
@@ -34,6 +34,7 @@ export const createBotServer = (options) => {
|
|
|
34
34
|
...(options.keyOf ? { keyOf: options.keyOf } : {}),
|
|
35
35
|
authority,
|
|
36
36
|
...(options.fetchOnly ? { fetchOnly: options.fetchOnly } : {}),
|
|
37
|
+
...(options.fetches ? { fetches: options.fetches } : {}),
|
|
37
38
|
offline: true,
|
|
38
39
|
// Another bot's copy is this bot's to read only where `read_other_bots` says so.
|
|
39
40
|
...(settings.readOtherBots ? {} : { omit: ["all_bots", "bots"] }),
|
|
@@ -59,6 +60,7 @@ export const createBotServer = (options) => {
|
|
|
59
60
|
levels,
|
|
60
61
|
...(options.keyOf ? { keyOf: options.keyOf } : {}),
|
|
61
62
|
authority,
|
|
63
|
+
...(options.fetches ? { fetches: options.fetches } : {}),
|
|
62
64
|
...(caller ? { caller } : {}),
|
|
63
65
|
}));
|
|
64
66
|
queue = next.catch(() => undefined);
|
package/dist/mcp/server.js
CHANGED
|
@@ -8,7 +8,7 @@ import * as v from "valibot";
|
|
|
8
8
|
import { findCommand } from "../cli/command-contract.js";
|
|
9
9
|
import { environmentOf } from "../cli/context.js";
|
|
10
10
|
import { refuseWriteBeforeConnecting } from "../cli/early-refusal.js";
|
|
11
|
-
import { changesAuthorityAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
|
|
11
|
+
import { changesAuthorityAt, fetchesOnlyAt, judgedTargets, readsOverMcpAt } from "../cli/effects.js";
|
|
12
12
|
import { itemOf } from "../cli/envelope.js";
|
|
13
13
|
import { DEFAULT_OUTPUT_BYTES } from "../cli/execution.js";
|
|
14
14
|
import { recalledAccount } from "../cli/messenger/accounts.js";
|
|
@@ -104,6 +104,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
const authority = changesAuthorityAt(root);
|
|
107
|
+
const fetches = fetchesOnlyAt(root);
|
|
107
108
|
const stdin = (path) => {
|
|
108
109
|
try {
|
|
109
110
|
return stdinFieldOf(findCommand(root, path));
|
|
@@ -128,6 +129,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
|
|
|
128
129
|
keyOf,
|
|
129
130
|
authority,
|
|
130
131
|
fetchOnly: readsOverMcpAt(root),
|
|
132
|
+
fetches,
|
|
131
133
|
offline: true,
|
|
132
134
|
stdin,
|
|
133
135
|
}).map((one) => "sync_first" in one.input.entries && !syncAllowed(one.path)
|
|
@@ -219,6 +221,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
|
|
|
219
221
|
overrides,
|
|
220
222
|
keyOf,
|
|
221
223
|
authority,
|
|
224
|
+
fetches,
|
|
222
225
|
stdin,
|
|
223
226
|
connection,
|
|
224
227
|
environment: agentEnvironment,
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Event } from "./model.js";
|
|
2
2
|
import type { MeetingDetails, MeetingStore } from "./store.js";
|
|
3
|
-
export declare const linkEvent: (store: MeetingStore, details: MeetingDetails, now?: number
|
|
3
|
+
export declare const linkEvent: (store: MeetingStore, details: MeetingDetails, now?: number, { create }?: {
|
|
4
|
+
create?: boolean;
|
|
5
|
+
}) => Promise<Event | null>;
|
package/dist/meetings/events.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const linkEvent = async (store, details, now = Date.now()) => {
|
|
1
|
+
export const linkEvent = async (store, details, now = Date.now(), { create = true } = {}) => {
|
|
2
2
|
const current = await store.meeting(details.meeting.id);
|
|
3
3
|
if (!current)
|
|
4
4
|
return null;
|
|
@@ -18,6 +18,8 @@ export const linkEvent = async (store, details, now = Date.now()) => {
|
|
|
18
18
|
return null;
|
|
19
19
|
}
|
|
20
20
|
let event = candidates[0];
|
|
21
|
+
if (!event && !create)
|
|
22
|
+
return null;
|
|
21
23
|
if (!event) {
|
|
22
24
|
let eventSeriesId = series?.eventSeriesId ?? null;
|
|
23
25
|
if (series?.kind === "recurring" && eventSeriesId === null) {
|
package/dist/meetings/pull.js
CHANGED
|
@@ -173,7 +173,7 @@ export const pull = async (source, store, options) => {
|
|
|
173
173
|
transcripts: [await transcriptInput(lines, [], source.name, `${JSON.stringify(lines)}\nunlinked`, format)],
|
|
174
174
|
now,
|
|
175
175
|
});
|
|
176
|
-
await linkEvent(store, details, now);
|
|
176
|
+
await linkEvent(store, details, now, { create: source.createsEvents !== false });
|
|
177
177
|
for (const p of participants)
|
|
178
178
|
if (p.identity.phone)
|
|
179
179
|
callers.add(p.identity.externalId);
|
|
@@ -27,6 +27,11 @@ export interface MeetingSource {
|
|
|
27
27
|
* meeting only once it has ended, or adds its recording later, sets it. 0 when absent; `--lookback-days` widens it.
|
|
28
28
|
*/
|
|
29
29
|
readonly overlapMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* False for a source that knows a meeting's day but not its hours, such as meeting notes from mail: its meetings
|
|
32
|
+
* link to an event the owner already has and never make one. True when absent.
|
|
33
|
+
*/
|
|
34
|
+
readonly createsEvents?: boolean;
|
|
30
35
|
meetings(since: string): Promise<SourceMeeting[]>;
|
|
31
36
|
participants(occurrenceId: string): Promise<SourceParticipant[] | null>;
|
|
32
37
|
transcript(occurrenceId: string): Promise<TranscriptLine[] | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.654.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|