@everyai/cli 0.6.2 → 0.6.4

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/README.md CHANGED
@@ -41,7 +41,7 @@ Codex's repo-scoped marketplace location is `.agents/plugins/marketplace.json`.
41
41
  The CLI talks to the same Every MCP server (`admin-mcp.every.ai`) and inherits its full tool surface automatically — new tools appear with no CLI upgrade. What the CLI adds:
42
42
 
43
43
  - **Portability** — one install + one login covers every agent and machine context; remote-MCP config is per-host, per-format, and often impossible in CI.
44
- - **Safety gates** — reads run freely; writes require `--yes`; destructive actions (sends, deletes, voids, payments) additionally require `--allow-destructive`; `--read-only` (or `EVERY_READ_ONLY=1`) locks everything else out. Classifications are enforced locally — including for tools whose server annotations are too optimistic.
44
+ - **Safety gates** — reads run freely; writes require `--yes`; destructive actions (sends, deletes, voids, payments) additionally require `--allow-destructive`; `--read-only` (or `EVERY_READ_ONLY=1`) locks everything else out. Classifications are enforced locally — including for tools whose server annotations are too optimistic. When trusted MCP metadata asks for an ordinary-write text confirmation, the CLI forwards the server's exact phrase and retries once.
45
45
  - **Deterministic output** — a stable `--json` envelope and exit-code taxonomy an agent can parse and branch on.
46
46
 
47
47
  ## Commands
@@ -87,6 +87,10 @@ Every command supports `--json`: exactly one JSON document on stdout, nothing el
87
87
 
88
88
  Exit codes: `0` ok · `1` tool/generic error · `2` usage · `3` auth (run `every login`) · `4` permission/confirmation needed · `5` rate-limited · `6` not found · `7` network/timeout.
89
89
 
90
+ Server-side human approvals never trigger an automatic destructive retry. If Every shows a pending approval after a destructive call returns or times out, approve it there and then re-run the identical command. The CLI sends one `tools/call` per invocation for a human-approval-gated action, and a still-valid approval can be consumed by that later invocation.
91
+
92
+ In `--json` mode, a server approval response uses exit `4` and includes a structured `error.mcp_gate` object. After local `--yes` or interactive consent, `type: "text_confirmation"` is retried once automatically; `type: "human_approval"` is returned to the caller without retrying.
93
+
90
94
  ## Headless / CI
91
95
 
92
96
  Set `EVERY_TOKEN` to a valid access token to skip the browser flow entirely. `login` requires a TTY by design and fails fast (exit `3`) without one.
@@ -44,9 +44,10 @@ export function conventionsBlock() {
44
44
  '',
45
45
  'Safety tiers:',
46
46
  ' read: runs without confirmation',
47
- ' write: requires y/N interactively or --yes non-interactively',
47
+ ' write: requires y/N interactively or --yes non-interactively; server text confirmation retries once',
48
48
  ' destructive: requires typed confirmation interactively or --yes --allow-destructive non-interactively',
49
49
  ' ai-mediated: server-enforced read-only, but gated because it routes through Every AI; prefer deterministic tools',
50
+ ' human approval: never auto-retries; approve in Every, then re-run the identical command',
50
51
  '',
51
52
  'Argument forms:',
52
53
  ' every tool call <name> --arg k=v --arg count=2',
@@ -8,6 +8,7 @@ import { classify, promptForTool, requirementDescription, requirementFor, } from
8
8
  import { getToken } from '../lib/auth/tokens.js';
9
9
  import { fetchUserInfo } from '../lib/auth/userinfo.js';
10
10
  import { maybeShowSkillHint } from '../lib/hints.js';
11
+ import { parseMcpGateMetadata, SERVER_CONFIRMATION_ARG, withoutMcpGateMarker, } from '../lib/mcp-gate.js';
11
12
  function emitCommand(data, human, opts) {
12
13
  if (opts.json)
13
14
  emit(data, { json: true, staging: opts.staging });
@@ -159,6 +160,17 @@ function timeoutMs(value) {
159
160
  }
160
161
  return Math.round(seconds * 1000);
161
162
  }
163
+ function destructiveTimeoutError(err, toolName) {
164
+ if (!(err instanceof CliError) ||
165
+ err.code !== 'network' ||
166
+ !err.message.startsWith('Timed out reaching ')) {
167
+ return undefined;
168
+ }
169
+ return new CliError(`${err.message}. The CLI made no automatic call after this timeout for ${toolName}. ` +
170
+ 'If Every shows a pending ' +
171
+ 'approval, approve it and re-run the identical command; the server can consume ' +
172
+ 'that still-valid approval on the later call.', err.exitCode, err.code, err.details);
173
+ }
162
174
  function textBlocks(content) {
163
175
  if (!Array.isArray(content))
164
176
  return [];
@@ -233,17 +245,43 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
233
245
  const environment = environmentNameForBaseUrl(baseUrl);
234
246
  const userinfo = gated ? await resolveWriteTarget(baseUrl) : undefined;
235
247
  const target = gated ? targetLabel(userinfo, environment) : undefined;
248
+ let locallyConfirmed = opts.yes === true;
236
249
  if (requirement.prompt) {
237
250
  const confirmed = await promptForTool(name, classification.level, requirement.prompt, target);
238
251
  if (!confirmed) {
239
252
  throw new CliError('Tool call cancelled.', ExitCode.PERMISSION, 'permission');
240
253
  }
254
+ locallyConfirmed = true;
241
255
  }
242
256
  if (gated && !opts.json && target) {
243
257
  process.stderr.write(`→ ${target}\n`);
244
258
  }
245
259
  const args = await argsFactory();
246
- const result = await callTool(baseUrl, token, name, args, { timeoutMs: timeoutMs(opts.timeout) });
260
+ const callTimeoutMs = timeoutMs(opts.timeout);
261
+ const invokeOnce = async (callArgs) => {
262
+ try {
263
+ return await callTool(baseUrl, token, name, callArgs, { timeoutMs: callTimeoutMs });
264
+ }
265
+ catch (err) {
266
+ if (classification.level === 'destructive') {
267
+ const timeout = destructiveTimeoutError(err, name);
268
+ if (timeout)
269
+ throw timeout;
270
+ }
271
+ throw err;
272
+ }
273
+ };
274
+ let result = await invokeOnce(args);
275
+ const firstGate = result.isError ? parseMcpGateMetadata(result._meta) : undefined;
276
+ if (firstGate?.type === 'text_confirmation' && locallyConfirmed) {
277
+ // The server is authoritative for the phrase because it validates/coerces
278
+ // arguments before constructing it. Retry this ordinary write at most once.
279
+ const confirmedArgs = {
280
+ ...args,
281
+ [SERVER_CONFIRMATION_ARG]: firstGate.confirmation,
282
+ };
283
+ result = await invokeOnce(confirmedArgs);
284
+ }
247
285
  const data = {
248
286
  tool: name,
249
287
  is_error: result.isError,
@@ -252,8 +290,17 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
252
290
  ...(gated ? { org: orgLabel(userinfo) } : {}),
253
291
  };
254
292
  if (result.isError) {
255
- const message = contentAsText(result.content) || 'Tool returned an error.';
256
- throw new CliError(message, ExitCode.GENERIC, 'generic');
293
+ const rawMessage = contentAsText(result.content) || 'Tool returned an error.';
294
+ const marker = parseMcpGateMetadata(result._meta);
295
+ if (marker) {
296
+ const message = withoutMcpGateMarker(rawMessage) || (marker.type === 'human_approval'
297
+ ? `${name} requires approval in Every.`
298
+ : `${name} text confirmation was rejected.`);
299
+ throw new CliError(message, ExitCode.PERMISSION, 'permission', {
300
+ mcp_gate: marker,
301
+ });
302
+ }
303
+ throw new CliError(rawMessage, ExitCode.GENERIC, 'generic');
257
304
  }
258
305
  return data;
259
306
  }
@@ -0,0 +1,128 @@
1
+ export const MCP_GATE_MARKER_PREFIX = 'EVERY_MCP_GATE:';
2
+ export const MCP_GATE_META_KEY = 'everyai/mcp_gate';
3
+ export const SERVER_CONFIRMATION_ARG = 'confirmation';
4
+ function isObject(value) {
5
+ return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
6
+ }
7
+ /**
8
+ * Return the first complete JSON object beginning at `start`. A balanced scan
9
+ * handles escaped quotes and braces inside confirmation text without relying
10
+ * on a phrase-shaped regex.
11
+ */
12
+ function jsonObjectAt(text, start) {
13
+ if (text[start] !== '{')
14
+ return undefined;
15
+ let depth = 0;
16
+ let inString = false;
17
+ let escaped = false;
18
+ for (let index = start; index < text.length; index += 1) {
19
+ const char = text[index];
20
+ if (inString) {
21
+ if (escaped) {
22
+ escaped = false;
23
+ }
24
+ else if (char === '\\') {
25
+ escaped = true;
26
+ }
27
+ else if (char === '"') {
28
+ inString = false;
29
+ }
30
+ continue;
31
+ }
32
+ if (char === '"') {
33
+ inString = true;
34
+ continue;
35
+ }
36
+ if (char === '{')
37
+ depth += 1;
38
+ if (char === '}') {
39
+ depth -= 1;
40
+ if (depth === 0)
41
+ return text.slice(start, index + 1);
42
+ }
43
+ }
44
+ return undefined;
45
+ }
46
+ function validatedMarker(value) {
47
+ if (!isObject(value) || value.version !== 1 || typeof value.type !== 'string') {
48
+ return undefined;
49
+ }
50
+ if (value.type === 'text_confirmation' &&
51
+ typeof value.confirmation === 'string' &&
52
+ value.confirmation.trim().length > 0) {
53
+ return {
54
+ version: 1,
55
+ type: 'text_confirmation',
56
+ confirmation: value.confirmation,
57
+ };
58
+ }
59
+ if (value.type === 'human_approval' &&
60
+ typeof value.status === 'string' &&
61
+ value.status.trim().length > 0) {
62
+ const marker = {
63
+ version: 1,
64
+ type: 'human_approval',
65
+ status: value.status,
66
+ };
67
+ if (typeof value.request_id === 'string')
68
+ marker.request_id = value.request_id;
69
+ if (typeof value.expires_at === 'string')
70
+ marker.expires_at = value.expires_at;
71
+ return marker;
72
+ }
73
+ return undefined;
74
+ }
75
+ /**
76
+ * Read the trusted gate contract from MCP result metadata. Only this path may
77
+ * authorize a retry or classify a result as permission-related.
78
+ */
79
+ export function parseMcpGateMetadata(meta) {
80
+ if (!isObject(meta))
81
+ return undefined;
82
+ return validatedMarker(meta[MCP_GATE_META_KEY]);
83
+ }
84
+ /**
85
+ * Parse the server's text marker for display cleanup only. Never use prose to
86
+ * authorize a retry: tool output may include attacker-controlled text after a
87
+ * partial side effect.
88
+ */
89
+ function locateMcpGateMarker(text) {
90
+ let searchFrom = 0;
91
+ while (searchFrom < text.length) {
92
+ const markerAt = text.indexOf(MCP_GATE_MARKER_PREFIX, searchFrom);
93
+ if (markerAt === -1)
94
+ return undefined;
95
+ const jsonAt = markerAt + MCP_GATE_MARKER_PREFIX.length;
96
+ const raw = jsonObjectAt(text, jsonAt);
97
+ if (raw) {
98
+ try {
99
+ const marker = validatedMarker(JSON.parse(raw));
100
+ if (marker) {
101
+ return {
102
+ marker,
103
+ start: markerAt,
104
+ end: jsonAt + raw.length,
105
+ };
106
+ }
107
+ }
108
+ catch {
109
+ // Keep looking: a malformed occurrence must not hide a later valid one.
110
+ }
111
+ }
112
+ searchFrom = jsonAt + 1;
113
+ }
114
+ return undefined;
115
+ }
116
+ /** Parse the prose copy for display cleanup and tests, never authorization. */
117
+ export function parseMcpGateMarker(text) {
118
+ return locateMcpGateMarker(text)?.marker;
119
+ }
120
+ /** Remove the machine marker from human-facing error copy. */
121
+ export function withoutMcpGateMarker(text) {
122
+ const located = locateMcpGateMarker(text);
123
+ if (!located)
124
+ return text;
125
+ return `${text.slice(0, located.start)}${text.slice(located.end)}`
126
+ .replace(/\n{3,}/g, '\n\n')
127
+ .trim();
128
+ }
package/dist/lib/mcp.js CHANGED
@@ -209,6 +209,7 @@ export async function callTool(baseUrl, token, name, args, { timeoutMs = DEFAULT
209
209
  return {
210
210
  content: result?.content ?? [],
211
211
  structuredContent: result?.structuredContent,
212
+ _meta: result?._meta,
212
213
  isError: result?.isError === true,
213
214
  };
214
215
  }
@@ -58,6 +58,37 @@ function overrideClassification(name) {
58
58
  reason: 'approve_pending_deal activates a deal and queues its plan; hard to undo, so pin write tier regardless of server annotation drift.',
59
59
  };
60
60
  }
61
+ // Client-deal tools (admin MCP, shipped 2026-09-03). None match the
62
+ // send_/delete_/void_/cancel_ name patterns, so without these entries their
63
+ // tier would rest entirely on server annotations.
64
+ if (name === 'create_client_deal') {
65
+ return {
66
+ level: 'write',
67
+ source: 'override',
68
+ reason: 'create_client_deal opens a new won deal for a client and makes the caller its delivery lead; pin write tier regardless of server annotation drift.',
69
+ };
70
+ }
71
+ if (name === 'set_deal_title') {
72
+ return {
73
+ level: 'write',
74
+ source: 'override',
75
+ reason: 'set_deal_title renames a deal, or clears the name back to the system default; pin write tier regardless of server annotation drift.',
76
+ };
77
+ }
78
+ if (name === 'link_deal_item') {
79
+ return {
80
+ level: 'write',
81
+ source: 'override',
82
+ reason: 'link_deal_item attaches an invoice or proposal to a deal and can change how that deal is valued; pin write tier regardless of server annotation drift.',
83
+ };
84
+ }
85
+ if (name === 'unlink_deal_item') {
86
+ return {
87
+ level: 'destructive',
88
+ source: 'override',
89
+ reason: 'unlink_deal_item detaches an invoice or proposal from a deal and the automatic matcher never re-links it, so the relationship is gone for good; same destructive tier as unlink_contact_from_client.',
90
+ };
91
+ }
61
92
  return undefined;
62
93
  }
63
94
  export function classify(tool) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everyai/cli",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Every-AI-Inc/everyai-cli.git"
@@ -37,7 +37,7 @@ Check process exit codes:
37
37
  - `1`: tool or generic error. Read the error message before deciding whether to retry.
38
38
  - `2`: usage error. Fix the command or arguments.
39
39
  - `3`: auth error. Tell the user to run `every login`.
40
- - `4`: permission or confirmation needed. Ask before adding confirmation flags.
40
+ - `4`: permission or confirmation needed. If present, inspect `error.mcp_gate`. A repeated `text_confirmation` means the CLI's one safe retry was still rejected; stop and report it. For `human_approval`, do not retry until the user approves in Every. Without `mcp_gate`, do not add confirmation flags unless the user authorized the action.
41
41
  - `5`: rate limited. Back off and retry later.
42
42
  - `6`: not found. Re-list records and verify the ID.
43
43
  - `7`: network error. Retry after checking connectivity.
@@ -59,6 +59,10 @@ For WRITE tools, add `--yes` only when the human explicitly asked for the change
59
59
 
60
60
  For DESTRUCTIVE tools, including sends, deletes, voids, and payments, add both `--yes` and `--allow-destructive` only when the human explicitly asked for that external or irreversible action. Never add `--allow-destructive` unprompted.
61
61
 
62
+ `--yes` also lets the CLI satisfy the server's ordinary-write text gate: the first rejected call carries a phrase in trusted MCP metadata, and the CLI forwards it in exactly one retry. Never construct or pass `confirmation` yourself.
63
+
64
+ Out-of-band actions use human approval instead. The CLI never automatically retries a `human_approval` response. If Every shows a pending approval after a destructive call returns or times out, wait for the user to approve it there, then repeat the exact same command once. Do not alter the arguments, and do not assume a timeout means the action ran.
65
+
62
66
  Use `every whoami --json` to verify the authenticated user, org, environment, base URL, and tool count. Write results echo the target org; confirm the blast radius before trusting them. In automation, prefer `--read-only` unless writes were requested.
63
67
 
64
68
  `ask_assistant` is a server-enforced read-only analytical fallback; prefer deterministic tools for actions.