@wirecat/cli-core 0.661.0 → 0.662.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 +21 -0
- package/dist/cli/ai-model-command.js +3 -3
- package/dist/cli/command-availability.d.ts +1 -1
- package/dist/cli/command-availability.js +4 -4
- package/dist/cli/dry-run-guard.js +7 -5
- package/dist/cli/early-refusal.d.ts +1 -1
- package/dist/cli/early-refusal.js +2 -2
- package/dist/cli/effects.d.ts +9 -2
- package/dist/cli/effects.js +16 -4
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/messenger/admin-moderation-command.js +2 -2
- package/dist/cli/messenger/archive-commands.js +2 -2
- package/dist/cli/messenger/context.d.ts +2 -2
- package/dist/cli/messenger/context.js +5 -3
- package/dist/cli/messenger/tasks-command.js +2 -1
- package/dist/cli/preview.js +3 -5
- package/dist/cli/program.js +2 -2
- package/dist/cli/shadowed-options.d.ts +7 -0
- package/dist/cli/shadowed-options.js +26 -0
- package/dist/crm/cli/index.js +4 -2
- package/dist/kit/sync-after-install.d.ts +10 -1
- package/dist/kit/sync-after-install.js +35 -11
- package/dist/mail/server-search.js +3 -3
- package/dist/mcp/server.js +4 -4
- package/dist/mcp/tool.js +3 -3
- package/dist/meetings/mcp/index.d.ts +15 -15
- package/dist/sends/guard.js +4 -20
- package/dist/sends/keyed-guard.d.ts +1 -1
- package/dist/sends/keyed-guard.js +2 -1
- package/dist/sends/permissions.d.ts +14 -0
- package/dist/sends/permissions.js +32 -0
- package/dist/services/server-search.js +1 -1
- package/package.json +1 -1
- package/parity.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ 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.662.0 — 14.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **`writesOwnerFiles(command)`** marks a command that writes the owner's files outside the store through a folder it
|
|
13
|
+
does not take as an option, such as a saved job's folder. It stays a write that `readonly` stops.
|
|
14
|
+
- **`syncAfterInstallCases` takes `profileLevels`** (`{ variable, keys }`): for each key, the sync must run with the
|
|
15
|
+
profile's own level at `readonly` and be refused at `deny`.
|
|
16
|
+
|
|
17
|
+
### Changed — may break callers
|
|
18
|
+
|
|
19
|
+
- **A `readonly` level no longer stops a sync.** A command that only fetches from the service into the local store
|
|
20
|
+
(`fetchesOnly`: `sync`, `messages sync`, `contacts sync`, `metadata sync`, `store gaps repair`,
|
|
21
|
+
`stats messages counters sync`) runs under any `readonly` level: the profile's own key, a group key such as
|
|
22
|
+
`messages`, or setup's "read only" answer. This holds on the command line, in `--dry-run` previews, in help and
|
|
23
|
+
over MCP. `--sync-first` and a server search run at `readonly` too. `deny` still refuses them. A profile that
|
|
24
|
+
relied on `readonly` to stop syncing now syncs; set the key to `deny` to stop it.
|
|
25
|
+
- **An MCP server no longer offers a sign-in through its read tool.** A command marked `logsInOrOut` that fetches
|
|
26
|
+
(`session start`) counts as a write over MCP. On the command line nothing changes.
|
|
27
|
+
- **`models ai check` is marked as reaching another service**, so `readonly` stops its paid request.
|
|
28
|
+
|
|
8
29
|
## 0.661.0 — 14.11.2026
|
|
9
30
|
|
|
10
31
|
### Added
|
|
@@ -6,7 +6,7 @@ import { localOnly, localOnlyRefusal } from "../models/local-only.js";
|
|
|
6
6
|
import { agentOf } from "../runs/run-context.js";
|
|
7
7
|
import { readSecret } from "../terminal/prompt.js";
|
|
8
8
|
import { environmentOf } from "./context.js";
|
|
9
|
-
import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS } from "./effects.js";
|
|
9
|
+
import { FETCH, grantsAuthority, LOCAL_READ, LOCAL_WRITE, NO_EFFECTS, reachesOtherService } from "./effects.js";
|
|
10
10
|
import { itemOf } from "./envelope.js";
|
|
11
11
|
const imagesNote = (setting) => `images you add to memory are sent to ${new URL(aiBaseUrl(setting)).host} to be read${setting.provider === "ollama" ? " (on this computer)" : ", so they leave this computer"}`;
|
|
12
12
|
const view = (app, options, setting) => {
|
|
@@ -175,12 +175,12 @@ export const aiModelCommand = (app, options) => {
|
|
|
175
175
|
writeAiSetting(path, kept);
|
|
176
176
|
options.output(itemOf({ ...view(app, options, kept), changed: images !== undefined }), this);
|
|
177
177
|
});
|
|
178
|
-
annotate(ai.command("check"), {
|
|
178
|
+
reachesOtherService(annotate(ai.command("check"), {
|
|
179
179
|
effects: FETCH,
|
|
180
180
|
mcp: false,
|
|
181
181
|
output: { entity: "ai_model_check" },
|
|
182
182
|
examples: [`${app.command} models ai check`],
|
|
183
|
-
})
|
|
183
|
+
}))
|
|
184
184
|
.summary("send one short paid request and say what is wrong")
|
|
185
185
|
.description("send one short request (billed by the provider, usually under a cent) and say what is wrong")
|
|
186
186
|
.option("--from-app", "you did this in WireCat Desktop")
|
|
@@ -16,5 +16,5 @@ export interface CommandAvailability {
|
|
|
16
16
|
}
|
|
17
17
|
/** Discovery and execution use the same permission decision. */
|
|
18
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`):
|
|
19
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): a `readonly` level lets it run. */
|
|
20
20
|
fetches?: (path: readonly string[]) => boolean) => CommandAvailability;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { writes } from "@wirecat/cli-base/standards";
|
|
2
|
-
import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed,
|
|
2
|
+
import { AUTHORITY_KEY, authorityAllowed, BOT_API_KEY, botApiAllowed, 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
5
|
export const commandAvailability = (info, levels, keyOf, authority, readOnly = false, mcp = true, declared,
|
|
6
|
-
/** Whether a command only fetches into the store (`fetchesOnlyAt`):
|
|
6
|
+
/** Whether a command only fetches into the store (`fetchesOnlyAt`): a `readonly` level lets it run. */
|
|
7
7
|
fetches) => {
|
|
8
8
|
const declaredKey = declared?.keyOf(info.path);
|
|
9
9
|
const key = declared ? declaredKey : (keyOf?.(info.path) ?? keyForCommand(info.path));
|
|
10
|
-
const { level
|
|
10
|
+
const { level } = key ? levelFor(levels, key, declared?.defaults) : { level: "allow" };
|
|
11
11
|
const judged = { ...(key ? { permission: key } : {}), level };
|
|
12
12
|
const blocked = (reason, permission) => ({
|
|
13
13
|
available: false,
|
|
@@ -27,7 +27,7 @@ fetches) => {
|
|
|
27
27
|
return blocked(`the profile requires ${BOT_API_KEY}: allow`, BOT_API_KEY);
|
|
28
28
|
if (level === "deny")
|
|
29
29
|
return blocked(`the profile denies ${key}`);
|
|
30
|
-
if (level === "readonly" && writes(info.effects) &&
|
|
30
|
+
if (level === "readonly" && writes(info.effects) && fetches?.(info.path) !== true)
|
|
31
31
|
return blocked(`${key} is readonly in this profile`);
|
|
32
32
|
const denied = (declared ? [] : readKeysForCommand(info.path)).find((read) => levelFor(levels, read).level === "deny");
|
|
33
33
|
return denied ? blocked(`the profile denies ${denied}`, denied) : { available: true, ...judged };
|
|
@@ -5,6 +5,7 @@ import { outputFor } from "./context.js";
|
|
|
5
5
|
import { changesAuthority } from "./effects.js";
|
|
6
6
|
import { itemOf, renderAnswer, snakeKeys } from "./envelope.js";
|
|
7
7
|
import { previewBody } from "./preview.js";
|
|
8
|
+
import { shareShadowedOptions } from "./shadowed-options.js";
|
|
8
9
|
const descendants = (command, into = new Set()) => {
|
|
9
10
|
into.add(command);
|
|
10
11
|
for (const child of command.commands)
|
|
@@ -18,13 +19,14 @@ const descendants = (command, into = new Set()) => {
|
|
|
18
19
|
*/
|
|
19
20
|
const previewWrites = (messenger) => (hooked, action) => {
|
|
20
21
|
// Each command carries its own hook, so one a CLI moves under its own group keeps it.
|
|
21
|
-
if (hooked !== action
|
|
22
|
+
if (hooked !== action)
|
|
22
23
|
return;
|
|
23
|
-
// `run` hands
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
// `run` hands a global flag to the command's own option of that name; another host's program does not.
|
|
25
|
+
shareShadowedOptions(action);
|
|
26
|
+
if (action.optsWithGlobals().dryRun !== true)
|
|
27
|
+
return;
|
|
28
|
+
if (action.options.some((option) => option.long === "--dry-run"))
|
|
26
29
|
return;
|
|
27
|
-
}
|
|
28
30
|
if (!writes(metaOf(action).effects) && !changesAuthority(action))
|
|
29
31
|
return;
|
|
30
32
|
// Commander reads the handler after the hooks, so swapping it here stops the write; each run builds its program anew.
|
|
@@ -30,7 +30,7 @@ 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
|
|
33
|
+
* `deny` stops it, `readonly` stops a write but lets a fetch into the store run, whichever key set it, and
|
|
34
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
35
|
* guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
|
|
36
36
|
* housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
|
|
@@ -96,7 +96,7 @@ 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
|
|
99
|
+
* `deny` stops it, `readonly` stops a write but lets a fetch into the store run, whichever key set it, and
|
|
100
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
101
|
* guard, which can put the question. A saved or `--permission` key that names no command stops every keyed command;
|
|
102
102
|
* housekeeping still runs, so `config unset` can remove it. Under the lock a non-messenger CLI still previews a
|
|
@@ -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) && !fetchesOnly(action))
|
|
130
130
|
throw levelRefusal({
|
|
131
131
|
profile: settings.profile,
|
|
132
132
|
command: app.command,
|
package/dist/cli/effects.d.ts
CHANGED
|
@@ -61,11 +61,18 @@ export declare const narrowsUnderLock: <T extends Command>(command: T) => T;
|
|
|
61
61
|
export declare const admittedUnderLock: (command: Command) => boolean;
|
|
62
62
|
/** A local edit remains an edit even when it first fetches metadata from the messenger. */
|
|
63
63
|
export declare const changesStore: <T extends Command>(command: T) => T;
|
|
64
|
+
/**
|
|
65
|
+
* Marks a command that writes the owner's files outside the store through a folder it does not take as an option, a
|
|
66
|
+
* saved job's folder say: it stays a write, which a `readonly` level stops.
|
|
67
|
+
*/
|
|
68
|
+
export declare const writesOwnerFiles: <T extends Command>(command: T) => T;
|
|
64
69
|
/**
|
|
65
70
|
* Reads the provider and only keeps what it read in the owner's store — a sync, a list that refreshes it. An MCP server
|
|
66
71
|
* offers it through the read tool (owner ruling, 2026-10-27; WC-CMD-17): it changes nothing at the provider or for
|
|
67
|
-
* other people. A local edit (`changesStore`), an authority change, a call to another service
|
|
68
|
-
* a model download) and a command that saves files (a download, a folder to write into
|
|
72
|
+
* other people. A local edit (`changesStore`), an authority change, a call to another service
|
|
73
|
+
* (`reachesOtherService`, a model download) and a command that saves files (a download, a folder to write into,
|
|
74
|
+
* `writesOwnerFiles`) stay writes. A sign-in (`logsInOrOut`) counts as a fetch, so a `readonly` level lets the owner
|
|
75
|
+
* sign in, but no MCP server runs one through its read tool.
|
|
69
76
|
*/
|
|
70
77
|
export declare const fetchesOnly: (command: Command) => boolean;
|
|
71
78
|
/** `fetchesOnly` by command path under `root`, as an MCP catalogue asks it; an unknown path is not one. */
|
package/dist/cli/effects.js
CHANGED
|
@@ -104,16 +104,28 @@ export const changesStore = (command) => {
|
|
|
104
104
|
STORE_WRITES.add(command);
|
|
105
105
|
return command;
|
|
106
106
|
};
|
|
107
|
+
const OWNER_FILES = new WeakSet();
|
|
108
|
+
/**
|
|
109
|
+
* Marks a command that writes the owner's files outside the store through a folder it does not take as an option, a
|
|
110
|
+
* saved job's folder say: it stays a write, which a `readonly` level stops.
|
|
111
|
+
*/
|
|
112
|
+
export const writesOwnerFiles = (command) => {
|
|
113
|
+
OWNER_FILES.add(command);
|
|
114
|
+
return command;
|
|
115
|
+
};
|
|
107
116
|
/** A download or a folder to write into: files outside the store, which the owner places, not an agent. */
|
|
108
|
-
const savesFiles = (command) =>
|
|
117
|
+
const savesFiles = (command) => OWNER_FILES.has(command) ||
|
|
118
|
+
command.name() === "download" ||
|
|
109
119
|
[...command.options.map((option) => option.attributeName()), ...command.registeredArguments.map((one) => one.name())]
|
|
110
120
|
.map((name) => name.toLowerCase())
|
|
111
121
|
.some((name) => name === "dir" || name.endsWith("dir") || name === "output");
|
|
112
122
|
/**
|
|
113
123
|
* Reads the provider and only keeps what it read in the owner's store — a sync, a list that refreshes it. An MCP server
|
|
114
124
|
* offers it through the read tool (owner ruling, 2026-10-27; WC-CMD-17): it changes nothing at the provider or for
|
|
115
|
-
* other people. A local edit (`changesStore`), an authority change, a call to another service
|
|
116
|
-
* a model download) and a command that saves files (a download, a folder to write into
|
|
125
|
+
* other people. A local edit (`changesStore`), an authority change, a call to another service
|
|
126
|
+
* (`reachesOtherService`, a model download) and a command that saves files (a download, a folder to write into,
|
|
127
|
+
* `writesOwnerFiles`) stay writes. A sign-in (`logsInOrOut`) counts as a fetch, so a `readonly` level lets the owner
|
|
128
|
+
* sign in, but no MCP server runs one through its read tool.
|
|
117
129
|
*/
|
|
118
130
|
export const fetchesOnly = (command) => {
|
|
119
131
|
const effects = metaOf(command).effects;
|
|
@@ -160,7 +172,7 @@ const writesFileNow = (command) => {
|
|
|
160
172
|
* What an MCP server runs through `read`: a command that only fetches into the store (`fetchesOnly`), and one whose
|
|
161
173
|
* only write is a file the tool cannot name (`writesFileOnlyWith`).
|
|
162
174
|
*/
|
|
163
|
-
export const readsOverMcp = (command) => fetchesOnly(command) || FILE_OPTION.has(command);
|
|
175
|
+
export const readsOverMcp = (command) => (fetchesOnly(command) && !LOGIN.has(command)) || FILE_OPTION.has(command);
|
|
164
176
|
/** `readsOverMcp` by command path under `root`, as an MCP catalogue asks it; an unknown path is not one. */
|
|
165
177
|
export const readsOverMcpAt = (root) => (path) => {
|
|
166
178
|
let at = root;
|
package/dist/cli/index.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
|
|
|
85
85
|
export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
|
|
86
86
|
export { type DoctorReportsSource, doctorReportsCommand } from "./doctor-reports-command.js";
|
|
87
87
|
export { refuseOffline } from "./early-refusal.js";
|
|
88
|
-
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, } from "./effects.js";
|
|
88
|
+
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, writesOwnerFiles, } from "./effects.js";
|
|
89
89
|
export { type CliEntry, type EntryContext, type EntryIo, openBrowser, startCli } from "./entry.js";
|
|
90
90
|
export { type AnswerOutput, answerSchema, type Body, type ItemBody, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, type ListBody, type ListInput, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
|
|
91
91
|
export { withAbort } from "./execution.js";
|
package/dist/cli/index.js
CHANGED
|
@@ -76,7 +76,7 @@ export { DEFAULT_CONFIG, ensureDefaultConfig } from "./default-config.js";
|
|
|
76
76
|
export { DISCOVERY_DESCRIPTIONS } from "./discovery-descriptions.js";
|
|
77
77
|
export { doctorReportsCommand } from "./doctor-reports-command.js";
|
|
78
78
|
export { refuseOffline } from "./early-refusal.js";
|
|
79
|
-
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, } from "./effects.js";
|
|
79
|
+
export { admittedUnderLock, changesAuthority, changesAuthorityAt, changesAuthorityNow, destroysNothing, FETCH, fetchesOnly, fetchesOnlyAt, grantsAuthority, isLogin, isOtherServiceCall, isProposal, isStoreChange, judgedEffects, judgedTargets, LOCAL_READ, LOCAL_WRITE, LOCKED_AUTHORITY_COMMANDS, logsInOrOut, NO_EFFECTS, narrowsUnderLock, ownerOnlyOption, PROPOSE_COMMANDS, previewFlag, proposesOnly, REMOTE_READ, REMOTE_WRITE, reachesOtherService, readsOverMcp, readsOverMcpAt, refuseUnderReadOnly, storeChangeRefusal, writesFileOnlyWith, writesNewFileOnlyWith, writesOwnerFiles, } from "./effects.js";
|
|
80
80
|
export { openBrowser, startCli } from "./entry.js";
|
|
81
81
|
export { answerSchema, isBody, itemAnswer, itemOf, jsonlRecords, judgedAnswer, listOf, metaNow, printItem, renderAnswer, sealed, snakeKeys, snakeKeysKeeping, } from "./envelope.js";
|
|
82
82
|
export { withAbort } from "./execution.js";
|
|
@@ -4,7 +4,7 @@ import { Command } from "commander";
|
|
|
4
4
|
import { describe, MAX_ACTIONS } from "../../moderation/check.js";
|
|
5
5
|
import { RULE_KEYS } from "../../moderation/rules.js";
|
|
6
6
|
import { dateWindow } from "../../services/moment.js";
|
|
7
|
-
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, REMOTE_WRITE } from "../effects.js";
|
|
7
|
+
import { grantsAuthority, LOCAL_READ, LOCAL_WRITE, ownerOnlyOption, REMOTE_WRITE } from "../effects.js";
|
|
8
8
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
9
9
|
import { answerOf } from "./ask.js";
|
|
10
10
|
import { renderItem } from "./chat-answers.js";
|
|
@@ -48,7 +48,7 @@ export const moderateCommand = (messenger) => annotate(new Command("moderate"),
|
|
|
48
48
|
.argument("<chat>", messenger.chatArgument)
|
|
49
49
|
.option("--since-time <time>", "judge what came after this ISO 8601 time, or 2h / 1d ago; the saved point stays")
|
|
50
50
|
.option("--dry-run", "judge and plan; do nothing")
|
|
51
|
-
.
|
|
51
|
+
.addOption(ownerOnlyOption("--allow-dangerous", "yes to every action whose level in the group's rules is ask"))
|
|
52
52
|
.option("--max-actions <n>", `at most this many actions in one run; ${MAX_ACTIONS} if not given`)
|
|
53
53
|
.action(async function (chat) {
|
|
54
54
|
const context = messengerContext(this, messenger);
|
|
@@ -10,7 +10,7 @@ import { seal } from "../../sealed.js";
|
|
|
10
10
|
import { CHAT_KINDS } from "../../services/chats.js";
|
|
11
11
|
import { kindsOf } from "../../services/inbox.js";
|
|
12
12
|
import { dateWindow } from "../../services/moment.js";
|
|
13
|
-
import { destroysNothing, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
13
|
+
import { destroysNothing, LOCAL_READ, LOCAL_WRITE, ownerOnlyOption } from "../effects.js";
|
|
14
14
|
import { itemOf, listOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
15
15
|
import { commandAt, lineOf } from "../steps.js";
|
|
16
16
|
import { jobsCommand } from "./backfill-command.js";
|
|
@@ -123,7 +123,7 @@ const leftLines = (left) => {
|
|
|
123
123
|
const clearCommand = (messenger) => annotate(new Command("clear"), { output: { entity: "store_clear" }, effects: LOCAL_WRITE })
|
|
124
124
|
.description("delete from the store the chats this account has left, with their messages")
|
|
125
125
|
.option("--left", "the chats this account has left — the only thing this clears")
|
|
126
|
-
.
|
|
126
|
+
.addOption(ownerOnlyOption("--allow-dangerous", "yes, delete — it cannot be undone, and a chat you left cannot be fetched again"))
|
|
127
127
|
.option("--dry-run", "list the chats it would delete, and delete nothing")
|
|
128
128
|
.action(async function () {
|
|
129
129
|
const { left, allowDangerous, dryRun } = this.opts();
|
|
@@ -286,8 +286,8 @@ export declare const connectedFor: (command: Command, messenger: Pick<Messenger,
|
|
|
286
286
|
export declare const markedProfile: (messenger: Messenger, profile: string, env: NodeJS.ProcessEnv) => string;
|
|
287
287
|
/**
|
|
288
288
|
* A write to the local store alone. `deny` already stopped the command (`messengerContext`); `readonly`
|
|
289
|
-
* stops this write too
|
|
290
|
-
* writing unasked.
|
|
289
|
+
* stops this write too, unless it only fetches from the messenger (`fetchesUnder`). There is no
|
|
290
|
+
* question to put to the owner here, so `ask` refuses rather than writing unasked.
|
|
291
291
|
*/
|
|
292
292
|
export declare const refuseLocalWrite: (context: MessengerContext, command: string, permission: PermissionKey) => void;
|
|
293
293
|
export declare const messengerContext: (command: Command, messenger: Messenger, resolving?: Pick<ResolveOptions, "needsProfile">) => MessengerContext;
|
|
@@ -3,7 +3,7 @@ import { servingProfiles } from "../../background/lock.js";
|
|
|
3
3
|
import { FloodMemory, floodPathFor } from "../../sends/flood.js";
|
|
4
4
|
import { ceilingRefusal, guardFor } from "../../sends/guard.js";
|
|
5
5
|
import { DEFAULT_PACE, Pacer, pacePathFor } from "../../sends/pace.js";
|
|
6
|
-
import { CEILING_KEY, levelFor, readKeysForCommand } from "../../sends/permissions.js";
|
|
6
|
+
import { CEILING_KEY, fetchesUnder, levelFor, readKeysForCommand } from "../../sends/permissions.js";
|
|
7
7
|
import { RecipientList, recipientsPathFor } from "../../sends/recipients.js";
|
|
8
8
|
import { OFFLINE, servicesFor } from "../../services/index.js";
|
|
9
9
|
import { openStore } from "../../store/store.js";
|
|
@@ -344,14 +344,16 @@ const refuseDenied = (command, settings) => {
|
|
|
344
344
|
};
|
|
345
345
|
/**
|
|
346
346
|
* A write to the local store alone. `deny` already stopped the command (`messengerContext`); `readonly`
|
|
347
|
-
* stops this write too
|
|
348
|
-
* writing unasked.
|
|
347
|
+
* stops this write too, unless it only fetches from the messenger (`fetchesUnder`). There is no
|
|
348
|
+
* question to put to the owner here, so `ask` refuses rather than writing unasked.
|
|
349
349
|
*/
|
|
350
350
|
export const refuseLocalWrite = (context, command, permission) => {
|
|
351
351
|
const { settings } = context;
|
|
352
352
|
const { level, key } = levelFor(settings.permissions, permission);
|
|
353
353
|
if (level === "allow" || (level === "ask" && context.agent))
|
|
354
354
|
return;
|
|
355
|
+
if (fetchesUnder(level, permission))
|
|
356
|
+
return;
|
|
355
357
|
if (key === CEILING_KEY)
|
|
356
358
|
throw ceilingRefusal(permission, command);
|
|
357
359
|
throw new CliError(level === "ask" ? "confirmation_required" : "permission_error", `profile ${settings.profile} does not let ${permission} write (permissions.${key} is ${level}, from the ` +
|
|
@@ -441,9 +441,10 @@ export const tasksCommand = (messenger) => {
|
|
|
441
441
|
"Reads only the local store")
|
|
442
442
|
.argument("<chat...>", messenger.chatArgument)
|
|
443
443
|
.option("--last <n>", `read the newest n stored messages of each chat (default ${ARRIVAL_WINDOW}, at most 1000)`, positiveCount("--last"))
|
|
444
|
+
.option("--yes", "open and close the tasks it lists; otherwise only list them")
|
|
444
445
|
.action(async function (chats) {
|
|
445
446
|
const context = messengerContext(this, messenger);
|
|
446
|
-
const { last, yes = false } = this.
|
|
447
|
+
const { last, yes = false } = this.opts();
|
|
447
448
|
if (yes)
|
|
448
449
|
refuseLocalWrite(context, messenger.app.command, "tasks.scan");
|
|
449
450
|
const passes = await context.withStore(async (store, account) => {
|
package/dist/cli/preview.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
4
|
+
import { keyForCommand, levelFor, readKeysForCommand, WRITE_KEYS } from "../sends/permissions.js";
|
|
5
5
|
import { commandPathOf } from "./command-contract.js";
|
|
6
6
|
import { fetchesOnly } from "./effects.js";
|
|
7
7
|
import { refuseUnknownPermissionKeys } from "./permission-keys.js";
|
|
@@ -14,9 +14,7 @@ export const preview = (command, settings, tool, keys, messenger = true) => {
|
|
|
14
14
|
const keyOf = typeof keys === "object" ? keys.keyOf : keys;
|
|
15
15
|
refuseUnknownPermissionKeys(command, settings, tool, declared ?? (keyOf && ((one) => keyOf(commandPathOf(one)))));
|
|
16
16
|
const key = declared ? declared.keyOf(path) : (keyOf?.(path) ?? keyForCommand(path));
|
|
17
|
-
const { level, key:
|
|
18
|
-
? levelFor(permissions, key, declared?.defaults)
|
|
19
|
-
: { level: "allow", key: null };
|
|
17
|
+
const { level } = key ? levelFor(permissions, key, declared?.defaults) : { level: "allow" };
|
|
20
18
|
for (const source of declared ? [] : readKeysForCommand(path)) {
|
|
21
19
|
if (levelFor(permissions, source).level === "deny")
|
|
22
20
|
throw new CliError("permission_error", `this profile does not permit ${source}`, { permission: source });
|
|
@@ -24,7 +22,7 @@ export const preview = (command, settings, tool, keys, messenger = true) => {
|
|
|
24
22
|
const meta = metaOf(command);
|
|
25
23
|
const writes = ((meta.effects !== undefined && writesAnything(meta.effects)) ||
|
|
26
24
|
(!declared && key !== null && key !== undefined && WRITE_KEYS.includes(key))) &&
|
|
27
|
-
!
|
|
25
|
+
!fetchesOnly(command);
|
|
28
26
|
if (level === "deny" || (writes && level === "readonly"))
|
|
29
27
|
throw new CliError("permission_error", `this profile does not permit ${path.join(" ")}`, { permission: key });
|
|
30
28
|
const also = (declared?.alsoChecks?.(path) ?? []).map((one) => {
|
package/dist/cli/program.js
CHANGED
|
@@ -38,6 +38,7 @@ import { PreviewComplete, preview } from "./preview.js";
|
|
|
38
38
|
import { commandWords, isProfileName, liftProfile, sampleCommand, takesProfile, valuedOptions } from "./profile.js";
|
|
39
39
|
import { absolutePaths, relayTarget } from "./relay-route.js";
|
|
40
40
|
import { NoProfileHere, namedProfile, settingsFor, } from "./settings.js";
|
|
41
|
+
import { shareShadowedOptions } from "./shadowed-options.js";
|
|
41
42
|
import { assertSharedContracts } from "./shared-contracts.js";
|
|
42
43
|
import { skillSourceOf } from "./skill-command.js";
|
|
43
44
|
import { refreshSkills, skipsSkillRefresh } from "./skill-refresh.js";
|
|
@@ -330,8 +331,7 @@ const runOnce = async (argv, definition, options) => {
|
|
|
330
331
|
if (flags.input === false || (headless && !options.answer))
|
|
331
332
|
environment.answer = () => null;
|
|
332
333
|
const localPreview = action.options.some((option) => option.long === "--dry-run");
|
|
333
|
-
|
|
334
|
-
action.setOptionValue("dryRun", true);
|
|
334
|
+
shareShadowedOptions(action);
|
|
335
335
|
refuseOfflineCommand(action, definition.app, flags.offline === true, flags.dryRun === true && localPreview);
|
|
336
336
|
const path = commandPathOf(action);
|
|
337
337
|
await enterCommandServer(action, command);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* commander gives a flag that the root and the command both declare (`--yes`, `--timeout`, `--dry-run`) to the root,
|
|
4
|
+
* so the command's own option stays empty (BUG-760). The value goes to the command's option too, through its own
|
|
5
|
+
* parser, so `--timeout 2m` on an option that takes seconds still arrives as seconds.
|
|
6
|
+
*/
|
|
7
|
+
export declare const shareShadowedOptions: (action: Command) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const GIVEN = new Set(["cli", "env", "config"]);
|
|
2
|
+
/**
|
|
3
|
+
* commander gives a flag that the root and the command both declare (`--yes`, `--timeout`, `--dry-run`) to the root,
|
|
4
|
+
* so the command's own option stays empty (BUG-760). The value goes to the command's option too, through its own
|
|
5
|
+
* parser, so `--timeout 2m` on an option that takes seconds still arrives as seconds.
|
|
6
|
+
*/
|
|
7
|
+
export const shareShadowedOptions = (action) => {
|
|
8
|
+
const ancestors = [];
|
|
9
|
+
for (let at = action.parent; at; at = at.parent)
|
|
10
|
+
ancestors.push(at);
|
|
11
|
+
for (const option of action.options) {
|
|
12
|
+
const key = option.attributeName();
|
|
13
|
+
if (GIVEN.has(action.getOptionValueSource(key) ?? ""))
|
|
14
|
+
continue;
|
|
15
|
+
const holder = ancestors.find((one) => GIVEN.has(one.getOptionValueSource(key) ?? ""));
|
|
16
|
+
if (!holder)
|
|
17
|
+
continue;
|
|
18
|
+
const value = holder.getOptionValue(key);
|
|
19
|
+
const takesValue = option.required || option.optional;
|
|
20
|
+
if (typeof value === "boolean" && !takesValue)
|
|
21
|
+
action.setOptionValueWithSource(key, value, "cli");
|
|
22
|
+
// commander's own handler parses and validates it, as when typed; its types leave out that a Command is an emitter.
|
|
23
|
+
else if (typeof value === "string" && takesValue)
|
|
24
|
+
action.emit(`option:${option.name()}`, value);
|
|
25
|
+
}
|
|
26
|
+
};
|
package/dist/crm/cli/index.js
CHANGED
|
@@ -280,8 +280,10 @@ const addCrmCommandsDefinition = (program, options) => {
|
|
|
280
280
|
});
|
|
281
281
|
example(answerEntity(annotate(store.command("apply"), { effects: LOCAL_WRITE }), "crm_contacts_removed", crmContactsApplied).description("apply scope mine to the contacts already stored: remove those no deal or lead of the chosen users and no " +
|
|
282
282
|
"kept company names, and the people they leave empty; counts only unless --yes, under scope all too. A " +
|
|
283
|
-
"sync that narrows the scope, or sync --rescan under mine, does this itself"), "store apply", "store apply --yes")
|
|
284
|
-
|
|
283
|
+
"sync that narrows the scope, or sync --rescan under mine, does this itself"), "store apply", "store apply --yes")
|
|
284
|
+
.option("--yes", "remove the contacts it counts; otherwise only count them")
|
|
285
|
+
.action(async (opts, command) => {
|
|
286
|
+
const yes = opts.yes === true;
|
|
285
287
|
await within(command, async (run) => {
|
|
286
288
|
const scope = crmSettingKey(run.account, "scope");
|
|
287
289
|
if (yes && (await run.store.crm.scope(run.account)).mode !== "mine")
|
|
@@ -15,8 +15,17 @@ export interface SyncAfterInstallOptions {
|
|
|
15
15
|
err: string;
|
|
16
16
|
out?: string;
|
|
17
17
|
}>;
|
|
18
|
-
/** Words of a
|
|
18
|
+
/** Words of a change that a `readonly` level must still refuse, as a check it opens no more. */
|
|
19
19
|
refusedUnderReadOnly?: readonly string[];
|
|
20
|
+
/**
|
|
21
|
+
* The profile's own levels, set in a config of its own: `variable` names the CLI's config folder
|
|
22
|
+
* (`TG_CONFIG_DIR`), and each of `keys` (`messages`, the key the sync's command names) is set to `readonly`, which
|
|
23
|
+
* the sync must pass, and to `deny`, which must refuse it.
|
|
24
|
+
*/
|
|
25
|
+
profileLevels?: {
|
|
26
|
+
variable: string;
|
|
27
|
+
keys: readonly string[];
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
31
|
* Cases that a CLI's sync runs right after install, whatever state the shared config is in. The kit points
|
|
@@ -4,7 +4,8 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
/**
|
|
6
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
|
|
7
|
+
* "read only" answer limits a tool, and even then a sync runs: it only reads the service (owner rulings, 2026-11-13
|
|
8
|
+
* and 2026-11-14, which extends it to a profile's own `readonly`).
|
|
8
9
|
* A slip with one reading is mended in place (2026-11-14), so only `broken` states may fail a step.
|
|
9
10
|
*/
|
|
10
11
|
const SHARED_CONFIGS = [
|
|
@@ -51,15 +52,32 @@ const errorCodeOf = (text) => {
|
|
|
51
52
|
* the CLI's own harness gives.
|
|
52
53
|
*/
|
|
53
54
|
export const syncAfterInstallCases = (options) => {
|
|
54
|
-
const { sync, refusedUnderReadOnly } = options;
|
|
55
|
-
const
|
|
55
|
+
const { sync, refusedUnderReadOnly, profileLevels } = options;
|
|
56
|
+
const profile = sync[0];
|
|
57
|
+
const cli = async (argv, shared, levels) => {
|
|
56
58
|
const configDir = mkdtempSync(join(tmpdir(), "sync-after-install-"));
|
|
57
59
|
shared.write?.(configDir);
|
|
60
|
+
const own = {};
|
|
61
|
+
if (levels && profileLevels) {
|
|
62
|
+
const dir = mkdtempSync(join(tmpdir(), "sync-after-install-own-"));
|
|
63
|
+
writeFileSync(join(dir, "config.json"), JSON.stringify({ profiles: { [profile]: { permissions: levels } } }));
|
|
64
|
+
own[profileLevels.variable] = dir;
|
|
65
|
+
}
|
|
58
66
|
const ran = await options.run(argv.includes("--json") ? [...argv] : [...argv, "--json"], {
|
|
59
67
|
WIRECAT_CONFIG_DIR: configDir,
|
|
68
|
+
...own,
|
|
60
69
|
});
|
|
61
70
|
return { code: ran.code, out: ran.out ?? "", err: ran.err };
|
|
62
71
|
};
|
|
72
|
+
const fresh = SHARED_CONFIGS[0];
|
|
73
|
+
const readOnly = SHARED_CONFIGS.find((one) => one.readOnly);
|
|
74
|
+
const refused = (name, argv, shared, levels) => ({
|
|
75
|
+
name,
|
|
76
|
+
run: async () => {
|
|
77
|
+
const ran = await cli(argv, shared, levels);
|
|
78
|
+
assert.equal(errorCodeOf(ran.err), "permission_error", `it was not refused: ${ran.out}${ran.err}`);
|
|
79
|
+
},
|
|
80
|
+
});
|
|
63
81
|
return [
|
|
64
82
|
...SHARED_CONFIGS.map((shared) => ({
|
|
65
83
|
name: `${sync.join(" ")} runs with ${shared.state}`,
|
|
@@ -71,16 +89,22 @@ export const syncAfterInstallCases = (options) => {
|
|
|
71
89
|
assert.equal(ran.code, 0, `sync exited ${ran.code}: ${ran.out}${ran.err}`);
|
|
72
90
|
},
|
|
73
91
|
})),
|
|
92
|
+
...(profileLevels?.keys ?? []).flatMap((key) => [
|
|
93
|
+
{
|
|
94
|
+
name: `${sync.join(" ")} runs with permissions.${key} readonly in the profile`,
|
|
95
|
+
run: async () => {
|
|
96
|
+
const ran = await cli(sync, fresh, { [key]: "readonly" });
|
|
97
|
+
assert.notEqual(errorCodeOf(ran.err), "permission_error", `sync was refused: ${ran.err}`);
|
|
98
|
+
assert.equal(ran.code, 0, `sync exited ${ran.code}: ${ran.out}${ran.err}`);
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
refused(`${sync.join(" ")} is refused with permissions.${key} deny in the profile`, sync, fresh, {
|
|
102
|
+
[key]: "deny",
|
|
103
|
+
}),
|
|
104
|
+
]),
|
|
74
105
|
...(refusedUnderReadOnly
|
|
75
106
|
? [
|
|
76
|
-
{
|
|
77
|
-
name: `${refusedUnderReadOnly.join(" ")} is still refused under the explicit "read only" answer`,
|
|
78
|
-
run: async () => {
|
|
79
|
-
const readOnly = SHARED_CONFIGS.find((one) => one.readOnly);
|
|
80
|
-
const ran = await cli(refusedUnderReadOnly, readOnly);
|
|
81
|
-
assert.equal(errorCodeOf(ran.err), "permission_error", `it was not refused: ${ran.out}${ran.err}`);
|
|
82
|
-
},
|
|
83
|
-
},
|
|
107
|
+
refused(`${refusedUnderReadOnly.join(" ")} is still refused under the explicit "read only" answer`, refusedUnderReadOnly, readOnly),
|
|
84
108
|
]
|
|
85
109
|
: []),
|
|
86
110
|
];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
2
|
import { importEngine } from "../attachments/extract.js";
|
|
3
3
|
import { deadlineMargin } from "../background/budget.js";
|
|
4
|
-
import { levelFor } from "../sends/permissions.js";
|
|
4
|
+
import { fetchesAt, levelFor } from "../sends/permissions.js";
|
|
5
5
|
import { DEFAULT_BACKEND, SERVER_BOUNDS, SERVER_SEARCH_KEY, sourceKey, } from "../services/server-search.js";
|
|
6
6
|
import { MAX_ATTACHMENT_CHARS, readAttachments } from "./attachments.js";
|
|
7
7
|
import { bulkBox } from "./bulk.js";
|
|
@@ -60,8 +60,8 @@ export const searchMailServer = async (store, mailbox, access, request) => {
|
|
|
60
60
|
};
|
|
61
61
|
if (access.offline)
|
|
62
62
|
return skip("offline");
|
|
63
|
-
// As tg's: `ask`
|
|
64
|
-
if (access.readOnly || levelFor(access.permissions, SERVER_SEARCH_KEY, access.defaults).level
|
|
63
|
+
// As tg's: `ask` gives the archive's answer, since nobody is asked before a search; `readonly` still reads the server.
|
|
64
|
+
if (access.readOnly || !fetchesAt(levelFor(access.permissions, SERVER_SEARCH_KEY, access.defaults).level))
|
|
65
65
|
return skip("not_allowed");
|
|
66
66
|
const { branches, partial } = mailCriteriaOf(request.text, {
|
|
67
67
|
...(request.exact ? { exact: true } : {}),
|
package/dist/mcp/server.js
CHANGED
|
@@ -22,7 +22,7 @@ import { warmEmbedders } from "../embeddings/embed.js";
|
|
|
22
22
|
import { mcpUrlOf } from "../http/public-url.js";
|
|
23
23
|
import { readOnlyLockOf } from "../ports/app.js";
|
|
24
24
|
import { guardFor } from "../sends/guard.js";
|
|
25
|
-
import { levelFor, readKeysForCommand } from "../sends/permissions.js";
|
|
25
|
+
import { fetchesAt, levelFor, readKeysForCommand } from "../sends/permissions.js";
|
|
26
26
|
import { openStore } from "../store/store.js";
|
|
27
27
|
import { runCommandForAgent, toolsFromCommands } from "./agent.js";
|
|
28
28
|
import { agentLog } from "./agent-log.js";
|
|
@@ -114,8 +114,8 @@ export const createServer = (command, context, messenger, sessionOptions) => {
|
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
116
|
const syncAllowed = (path) => syncsFirst(messenger) &&
|
|
117
|
-
levelOf("messages.sync-first")
|
|
118
|
-
(path[0] !== "stats" || levelOf(`${path.join(".")}.sync-first`)
|
|
117
|
+
fetchesAt(levelOf("messages.sync-first")) &&
|
|
118
|
+
(path[0] !== "stats" || fetchesAt(levelOf(`${path.join(".")}.sync-first`)));
|
|
119
119
|
// Discovery stays complete while availability follows changes to the profile.
|
|
120
120
|
const generated = toolsFromCommands(program.commands, {
|
|
121
121
|
includeUnavailable: true,
|
|
@@ -317,7 +317,7 @@ export const createServer = (command, context, messenger, sessionOptions) => {
|
|
|
317
317
|
spawnJob: sessionOptions.spawnJob,
|
|
318
318
|
limit: settings.limit,
|
|
319
319
|
get syncAllowed() {
|
|
320
|
-
return syncsFirst(messenger) && levelOf("messages.sync-first")
|
|
320
|
+
return syncsFirst(messenger) && fetchesAt(levelOf("messages.sync-first"));
|
|
321
321
|
},
|
|
322
322
|
guard,
|
|
323
323
|
settings,
|
package/dist/mcp/tool.js
CHANGED
|
@@ -14,7 +14,7 @@ import { startRecording } from "../runs/recording.js";
|
|
|
14
14
|
import { newRunId } from "../runs/run.js";
|
|
15
15
|
import { keepsSuccess, runContextOf } from "../runs/run-context.js";
|
|
16
16
|
import { inRun } from "../runs/scope.js";
|
|
17
|
-
import { keyForCommand, levelFor, readKeysForCommand } from "../sends/permissions.js";
|
|
17
|
+
import { fetchesAt, keyForCommand, levelFor, readKeysForCommand } from "../sends/permissions.js";
|
|
18
18
|
import { onlineDeps, storeModeDeps } from "../services/deps.js";
|
|
19
19
|
import { servicesFor } from "../services/index.js";
|
|
20
20
|
import { callerOf, currentCaller, withCaller } from "./caller.js";
|
|
@@ -94,9 +94,9 @@ export const inputOf = (definition, syncAllowed) => v.strictObject(syncAllowed |
|
|
|
94
94
|
/** Whether a profile may sync before answering this entry. */
|
|
95
95
|
export const syncAllowedFor = (key, defaults) => {
|
|
96
96
|
const permissions = defaults.settings.permissions ?? {};
|
|
97
|
-
const shared = defaults.syncAllowed ?? levelFor(permissions, "messages.sync-first").level
|
|
97
|
+
const shared = defaults.syncAllowed ?? fetchesAt(levelFor(permissions, "messages.sync-first").level);
|
|
98
98
|
return (shared &&
|
|
99
|
-
(!key.startsWith("stats_") || levelFor(permissions, `${key.replaceAll("_", ".")}.sync-first`).level
|
|
99
|
+
(!key.startsWith("stats_") || fetchesAt(levelFor(permissions, `${key.replaceAll("_", ".")}.sync-first`).level)));
|
|
100
100
|
};
|
|
101
101
|
export const entryRunner = (registration) => {
|
|
102
102
|
const run = callRunner(registration);
|
|
@@ -38,7 +38,6 @@ export declare const meetingTools: ({
|
|
|
38
38
|
max_read_bytes?: undefined;
|
|
39
39
|
cursor?: undefined;
|
|
40
40
|
} | {
|
|
41
|
-
limit?: undefined;
|
|
42
41
|
event_id?: undefined;
|
|
43
42
|
series_id?: undefined;
|
|
44
43
|
page?: undefined;
|
|
@@ -54,11 +53,11 @@ export declare const meetingTools: ({
|
|
|
54
53
|
format?: undefined;
|
|
55
54
|
transcript_id?: undefined;
|
|
56
55
|
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;
|
|
62
61
|
event_id?: undefined;
|
|
63
62
|
series_id?: undefined;
|
|
64
63
|
page?: undefined;
|
|
@@ -76,11 +75,11 @@ export declare const meetingTools: ({
|
|
|
76
75
|
format?: undefined;
|
|
77
76
|
transcript_id?: undefined;
|
|
78
77
|
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;
|
|
84
83
|
event_id?: undefined;
|
|
85
84
|
series_id?: undefined;
|
|
86
85
|
page?: undefined;
|
|
@@ -102,6 +101,7 @@ export declare const meetingTools: ({
|
|
|
102
101
|
minimum: number;
|
|
103
102
|
};
|
|
104
103
|
query?: undefined;
|
|
104
|
+
limit?: undefined;
|
|
105
105
|
scan_limit?: undefined;
|
|
106
106
|
max_read_bytes?: undefined;
|
|
107
107
|
cursor?: undefined;
|
|
@@ -188,7 +188,6 @@ export declare const meetingTools: ({
|
|
|
188
188
|
max_read_bytes?: undefined;
|
|
189
189
|
cursor?: undefined;
|
|
190
190
|
} | {
|
|
191
|
-
limit?: undefined;
|
|
192
191
|
event_id?: undefined;
|
|
193
192
|
series_id?: undefined;
|
|
194
193
|
page?: undefined;
|
|
@@ -204,11 +203,11 @@ export declare const meetingTools: ({
|
|
|
204
203
|
format?: undefined;
|
|
205
204
|
transcript_id?: undefined;
|
|
206
205
|
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;
|
|
212
211
|
event_id?: undefined;
|
|
213
212
|
series_id?: undefined;
|
|
214
213
|
page?: undefined;
|
|
@@ -226,11 +225,11 @@ export declare const meetingTools: ({
|
|
|
226
225
|
format?: undefined;
|
|
227
226
|
transcript_id?: undefined;
|
|
228
227
|
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;
|
|
234
233
|
event_id?: undefined;
|
|
235
234
|
series_id?: undefined;
|
|
236
235
|
page?: undefined;
|
|
@@ -252,6 +251,7 @@ export declare const meetingTools: ({
|
|
|
252
251
|
minimum: number;
|
|
253
252
|
};
|
|
254
253
|
query?: undefined;
|
|
254
|
+
limit?: undefined;
|
|
255
255
|
scan_limit?: undefined;
|
|
256
256
|
max_read_bytes?: undefined;
|
|
257
257
|
cursor?: undefined;
|
|
@@ -338,7 +338,6 @@ export declare const meetingTools: ({
|
|
|
338
338
|
max_read_bytes?: undefined;
|
|
339
339
|
cursor?: undefined;
|
|
340
340
|
} | {
|
|
341
|
-
limit?: undefined;
|
|
342
341
|
event_id?: undefined;
|
|
343
342
|
series_id?: undefined;
|
|
344
343
|
page?: undefined;
|
|
@@ -354,11 +353,11 @@ export declare const meetingTools: ({
|
|
|
354
353
|
format?: undefined;
|
|
355
354
|
transcript_id?: undefined;
|
|
356
355
|
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;
|
|
362
361
|
event_id?: undefined;
|
|
363
362
|
series_id?: undefined;
|
|
364
363
|
page?: undefined;
|
|
@@ -376,11 +375,11 @@ export declare const meetingTools: ({
|
|
|
376
375
|
format?: undefined;
|
|
377
376
|
transcript_id?: undefined;
|
|
378
377
|
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;
|
|
384
383
|
event_id?: undefined;
|
|
385
384
|
series_id?: undefined;
|
|
386
385
|
page?: undefined;
|
|
@@ -402,6 +401,7 @@ export declare const meetingTools: ({
|
|
|
402
401
|
minimum: number;
|
|
403
402
|
};
|
|
404
403
|
query?: undefined;
|
|
404
|
+
limit?: undefined;
|
|
405
405
|
scan_limit?: undefined;
|
|
406
406
|
max_read_bytes?: undefined;
|
|
407
407
|
cursor?: undefined;
|
|
@@ -488,7 +488,6 @@ export declare const meetingTools: ({
|
|
|
488
488
|
max_read_bytes?: undefined;
|
|
489
489
|
cursor?: undefined;
|
|
490
490
|
} | {
|
|
491
|
-
limit?: undefined;
|
|
492
491
|
event_id?: undefined;
|
|
493
492
|
series_id?: undefined;
|
|
494
493
|
page?: undefined;
|
|
@@ -504,11 +503,11 @@ export declare const meetingTools: ({
|
|
|
504
503
|
format?: undefined;
|
|
505
504
|
transcript_id?: undefined;
|
|
506
505
|
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;
|
|
512
511
|
event_id?: undefined;
|
|
513
512
|
series_id?: undefined;
|
|
514
513
|
page?: undefined;
|
|
@@ -526,11 +525,11 @@ export declare const meetingTools: ({
|
|
|
526
525
|
format?: undefined;
|
|
527
526
|
transcript_id?: undefined;
|
|
528
527
|
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;
|
|
534
533
|
event_id?: undefined;
|
|
535
534
|
series_id?: undefined;
|
|
536
535
|
page?: undefined;
|
|
@@ -552,6 +551,7 @@ export declare const meetingTools: ({
|
|
|
552
551
|
minimum: number;
|
|
553
552
|
};
|
|
554
553
|
query?: undefined;
|
|
554
|
+
limit?: undefined;
|
|
555
555
|
scan_limit?: undefined;
|
|
556
556
|
max_read_bytes?: undefined;
|
|
557
557
|
cursor?: undefined;
|
|
@@ -638,7 +638,6 @@ export declare const meetingTools: ({
|
|
|
638
638
|
max_read_bytes?: undefined;
|
|
639
639
|
cursor?: undefined;
|
|
640
640
|
} | {
|
|
641
|
-
limit?: undefined;
|
|
642
641
|
event_id?: undefined;
|
|
643
642
|
series_id?: undefined;
|
|
644
643
|
page?: undefined;
|
|
@@ -654,11 +653,11 @@ export declare const meetingTools: ({
|
|
|
654
653
|
format?: undefined;
|
|
655
654
|
transcript_id?: undefined;
|
|
656
655
|
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;
|
|
662
661
|
event_id?: undefined;
|
|
663
662
|
series_id?: undefined;
|
|
664
663
|
page?: undefined;
|
|
@@ -676,11 +675,11 @@ export declare const meetingTools: ({
|
|
|
676
675
|
format?: undefined;
|
|
677
676
|
transcript_id?: undefined;
|
|
678
677
|
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;
|
|
684
683
|
event_id?: undefined;
|
|
685
684
|
series_id?: undefined;
|
|
686
685
|
page?: undefined;
|
|
@@ -702,6 +701,7 @@ export declare const meetingTools: ({
|
|
|
702
701
|
minimum: number;
|
|
703
702
|
};
|
|
704
703
|
query?: undefined;
|
|
704
|
+
limit?: undefined;
|
|
705
705
|
scan_limit?: undefined;
|
|
706
706
|
max_read_bytes?: undefined;
|
|
707
707
|
cursor?: undefined;
|
package/dist/sends/guard.js
CHANGED
|
@@ -3,25 +3,9 @@ import { CliError } from "@wirecat/cli-base";
|
|
|
3
3
|
import { MESSENGER_CHANGE_REFUSAL, readOnlyRefusal } from "../ports/app.js";
|
|
4
4
|
import { FloodMemory, floodPathFor, holdEnd } from "./flood.js";
|
|
5
5
|
import { SendJournal, sendsPathFor, } from "./journal.js";
|
|
6
|
-
import { CEILING_KEY, keyForWrite, levelFor, skipFlagFor } from "./permissions.js";
|
|
6
|
+
import { CEILING_KEY, keyForWrite, levelFor, STORE_ONLY_KEYS, skipFlagFor, stops, } from "./permissions.js";
|
|
7
7
|
import { RecipientList, recipientsPathFor } from "./recipients.js";
|
|
8
8
|
const HOUR_MS = 60 * 60 * 1000;
|
|
9
|
-
/**
|
|
10
|
-
* Asked of the guard for their permission level, yet they only read from the messenger or work here: reads go on
|
|
11
|
-
* during a hold and under the read-only lock, which promises reads and syncs.
|
|
12
|
-
*/
|
|
13
|
-
const READS = new Set([
|
|
14
|
-
"attachments.extract",
|
|
15
|
-
"conversations.embeddings",
|
|
16
|
-
"conversations.links",
|
|
17
|
-
"messages.server-search",
|
|
18
|
-
"messages.sync-first",
|
|
19
|
-
"stats.contacts.top.sync-first",
|
|
20
|
-
"stats.messages.counters.sync",
|
|
21
|
-
"stats.messages.show.sync-first",
|
|
22
|
-
"stats.messages.top.sync-first",
|
|
23
|
-
"store.gaps.repair",
|
|
24
|
-
]);
|
|
25
9
|
/**
|
|
26
10
|
* What puts something in front of somebody (max-cli `NEED-168`, widened by `NEED-282`). A message, a
|
|
27
11
|
* forward, an edit, a pin that notifies, a new group and people added to one all do. A reaction,
|
|
@@ -72,14 +56,14 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
72
56
|
let reservation;
|
|
73
57
|
const answered = new WeakSet();
|
|
74
58
|
const refuseReadOnly = ({ key }) => {
|
|
75
|
-
if (key !== undefined &&
|
|
59
|
+
if (key !== undefined && STORE_ONLY_KEYS.has(key))
|
|
76
60
|
return;
|
|
77
61
|
if (readOnlyLock)
|
|
78
62
|
throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
|
|
79
63
|
};
|
|
80
64
|
// Every write, counted or not: a reaction or a read receipt sent through a ban is what makes the ban stick.
|
|
81
65
|
const refuseHeld = ({ key }) => {
|
|
82
|
-
if (key !== undefined &&
|
|
66
|
+
if (key !== undefined && STORE_ONLY_KEYS.has(key))
|
|
83
67
|
return;
|
|
84
68
|
const block = flood?.sendBlock();
|
|
85
69
|
if (!block)
|
|
@@ -95,7 +79,7 @@ export const sendGuard = ({ profile, recipients, command = recipients.command, r
|
|
|
95
79
|
if (levels !== undefined) {
|
|
96
80
|
const key = request.key ?? keyForWrite(kind, action);
|
|
97
81
|
const { level, key: named } = levelFor(levels, key, permissionDefaults);
|
|
98
|
-
if (level
|
|
82
|
+
if (stops(level, key))
|
|
99
83
|
throw levelRefusal({ profile, command, key, level, named, permissionSources }, permissionFix?.(request, key));
|
|
100
84
|
if (level === "ask" && !answered.has(request)) {
|
|
101
85
|
throw new CliError("confirmation_required", `${key} asks before it acts, and it was not asked`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Asker, GuardRequest, SendGuard } from "./guard.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type Level, type PermissionKey } from "./permissions.js";
|
|
3
3
|
export type KeyedGuard = SendGuard & {
|
|
4
4
|
/** Refuses the write when one of its keys denies it or is read-only; asks nothing. */
|
|
5
5
|
refuse(request: GuardRequest): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stops } from "./permissions.js";
|
|
1
2
|
/**
|
|
2
3
|
* A guard over a write's main key and its extra keys. A key that refuses refuses before anything is asked, so nobody
|
|
3
4
|
* answers yes to a write that a stricter key then stops, and one question names every key at `ask`. The extra keys are
|
|
@@ -23,7 +24,7 @@ export const keyedGuard = (build, ask, levelOf, extra) => {
|
|
|
23
24
|
};
|
|
24
25
|
const levelOfRequest = ({ key }) => levelOf(key ?? "");
|
|
25
26
|
const refuse = (request) => {
|
|
26
|
-
const refused = all(request).find((one) =>
|
|
27
|
+
const refused = all(request).find((one) => stops(levelOfRequest(one), one.key ?? ""));
|
|
27
28
|
if (refused)
|
|
28
29
|
guard.check(refused, { reserve: false });
|
|
29
30
|
};
|
|
@@ -39,6 +39,20 @@ export declare const layerPermissions: (layers: readonly [string, Readonly<Recor
|
|
|
39
39
|
* at a terminal writes it, so an agent cannot lift it with `config set`.
|
|
40
40
|
*/
|
|
41
41
|
export declare const CEILING_KEY = "*";
|
|
42
|
+
/**
|
|
43
|
+
* Asked of the guard for their permission level, yet they only read from the messenger or work here: reads go on
|
|
44
|
+
* during a hold and under the read-only lock, which promises reads and syncs.
|
|
45
|
+
*/
|
|
46
|
+
export declare const STORE_ONLY_KEYS: Set<string>;
|
|
47
|
+
/** Whether `level` lets a key that only fetches into the store run: `readonly` does, `deny` and `ask` decide alone. */
|
|
48
|
+
export declare const fetchesUnder: (level: Level, key: PermissionKey) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a fetch a read adds on its own (a sync first, a server search) runs at `level`: it is never asked, so `ask`
|
|
51
|
+
* does not, and `readonly` still fetches.
|
|
52
|
+
*/
|
|
53
|
+
export declare const fetchesAt: (level: Level) => boolean;
|
|
54
|
+
/** Whether `level` stops a write under `key` outright: `deny` always, `readonly` unless the key only fetches. */
|
|
55
|
+
export declare const stops: (level: Level, key: PermissionKey) => boolean;
|
|
42
56
|
/**
|
|
43
57
|
* The most specific key the owner set wins. A built-in default (`DEFAULT_PERMISSIONS`) only ever
|
|
44
58
|
* tightens: against a broader key of the owner's, the stricter of the two holds — so
|
|
@@ -121,6 +121,38 @@ export const layerPermissions = (layers) => {
|
|
|
121
121
|
* at a terminal writes it, so an agent cannot lift it with `config set`.
|
|
122
122
|
*/
|
|
123
123
|
export const CEILING_KEY = "*";
|
|
124
|
+
/**
|
|
125
|
+
* Asked of the guard for their permission level, yet they only read from the messenger or work here: reads go on
|
|
126
|
+
* during a hold and under the read-only lock, which promises reads and syncs.
|
|
127
|
+
*/
|
|
128
|
+
export const STORE_ONLY_KEYS = new Set([
|
|
129
|
+
"attachments.extract",
|
|
130
|
+
"conversations.embeddings",
|
|
131
|
+
"conversations.links",
|
|
132
|
+
"messages.server-search",
|
|
133
|
+
"messages.sync-first",
|
|
134
|
+
"metadata.sync",
|
|
135
|
+
"stats.contacts.top.sync-first",
|
|
136
|
+
"stats.messages.counters.sync",
|
|
137
|
+
"stats.messages.show.sync-first",
|
|
138
|
+
"stats.messages.top.sync-first",
|
|
139
|
+
"store.gaps.repair",
|
|
140
|
+
]);
|
|
141
|
+
/**
|
|
142
|
+
* Those of `STORE_ONLY_KEYS` that only fetch from the messenger into the store: a `readonly` level lets them run, as it
|
|
143
|
+
* lets a sync (owner ruling, 2026-11-14). Work done here on what is stored, such as a file's text or a link between
|
|
144
|
+
* conversations, stays a write that `readonly` stops.
|
|
145
|
+
*/
|
|
146
|
+
const FETCH_KEYS = new Set([...STORE_ONLY_KEYS].filter((key) => !["attachments.extract", "conversations.embeddings", "conversations.links"].includes(key)));
|
|
147
|
+
/** Whether `level` lets a key that only fetches into the store run: `readonly` does, `deny` and `ask` decide alone. */
|
|
148
|
+
export const fetchesUnder = (level, key) => level === "readonly" && FETCH_KEYS.has(key);
|
|
149
|
+
/**
|
|
150
|
+
* Whether a fetch a read adds on its own (a sync first, a server search) runs at `level`: it is never asked, so `ask`
|
|
151
|
+
* does not, and `readonly` still fetches.
|
|
152
|
+
*/
|
|
153
|
+
export const fetchesAt = (level) => level === "allow" || level === "readonly";
|
|
154
|
+
/** Whether `level` stops a write under `key` outright: `deny` always, `readonly` unless the key only fetches. */
|
|
155
|
+
export const stops = (level, key) => level === "deny" || (level === "readonly" && !FETCH_KEYS.has(key));
|
|
124
156
|
const ALLOWED = { level: "allow", key: null };
|
|
125
157
|
const ORDER = { deny: 0, readonly: 1, ask: 2, allow: 3 };
|
|
126
158
|
const nearest = (levels, key) => {
|
|
@@ -110,7 +110,7 @@ export const searchServer = async (deps, request) => {
|
|
|
110
110
|
if (deps.offline)
|
|
111
111
|
return skip("offline");
|
|
112
112
|
const guardRequest = { chatId: null, kind: "reaction", key: SERVER_SEARCH_KEY };
|
|
113
|
-
// Never asked, as sync-first: over MCP an `ask` goes ahead, and the server search needs `allow`.
|
|
113
|
+
// Never asked, as sync-first: over MCP an `ask` goes ahead, and the server search needs `allow` or `readonly`.
|
|
114
114
|
try {
|
|
115
115
|
deps.guard.check(guardRequest, { reserve: false });
|
|
116
116
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.662.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",
|