@everyai/cli 0.8.1 → 0.10.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/README.md +35 -5
- package/dist/commands/aliases.js +329 -17
- package/dist/commands/crm.js +453 -0
- package/dist/commands/docs.js +6 -0
- package/dist/commands/policy.js +4 -1
- package/dist/commands/tools.js +44 -8
- package/dist/index.js +260 -9
- package/dist/lib/config.js +9 -0
- package/dist/lib/mcp.js +43 -2
- package/dist/lib/policy.js +39 -0
- package/dist/lib/recipients.js +60 -0
- package/dist/lib/table.js +41 -0
- package/package.json +1 -1
- package/skills/use-every/SKILL.md +159 -10
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. When trusted MCP metadata asks for an ordinary-write text confirmation, the CLI forwards the server's exact phrase and retries once.
|
|
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. `every tool call deal_outreach` is destructive for all of its actions because it can send a deal's message. The short commands gate by action: `every deal outreach edit` and `cancel` are writes, and `every deal outreach send` is destructive. `update_deal` is a write. 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
|
|
@@ -65,14 +65,40 @@ every policy explain <name> # classification + exactly what running it requir
|
|
|
65
65
|
# Run any tool
|
|
66
66
|
every tool call <name> [--args file.json|-] [--arg k=v ...] [--yes] [--allow-destructive] [--read-only]
|
|
67
67
|
|
|
68
|
-
#
|
|
68
|
+
# Short commands (same gates, nicer flags; each calls one tool)
|
|
69
69
|
every invoice list [--status <s>] [--search <q>] [--limit <n>]
|
|
70
70
|
every invoice create (--company <name> | --person <name> | --company-id <id> | --person-id <id>) --amount <n>
|
|
71
71
|
# write: needs --yes
|
|
72
|
-
every invoice send <invoice_id> #
|
|
73
|
-
every
|
|
74
|
-
every
|
|
72
|
+
every invoice send <invoice_id> # shows the recipients, then needs --yes
|
|
73
|
+
every proposal send <proposal_id> # shows the recipients, then needs --yes
|
|
74
|
+
every recipients get|set <party> --kind invoice|proposal
|
|
75
|
+
every company list [--search <q>] [--limit <n>]
|
|
76
|
+
every company view <company_id>
|
|
77
|
+
every company create --name <name> [--email] [--phone] [--website] [--industry] [--address] [--lead-source] [--notes]
|
|
78
|
+
# write: needs --yes
|
|
75
79
|
every person list [--search <q>] # People
|
|
80
|
+
every person view <person_id>
|
|
81
|
+
every person create --name <name> [--email] [--phone] [--job-title] [--company] [--location] [--headline] [--industry] [--address] [--notes]
|
|
82
|
+
# write: needs --yes
|
|
83
|
+
every deal stages # this workspace's stages: label, key, role, criteria
|
|
84
|
+
every deal list [--stage <s>] [--search <q>] [--limit <n>] # <s>: a stage key or label
|
|
85
|
+
[--attention needs_reply,step_due,draft_ready,stale] [--stale-days <n>]
|
|
86
|
+
[--owner <me|email|id> | --mine] [--since <iso time>] [--sort last_activity_at]
|
|
87
|
+
every deal view <deal_id> [--plan] [--draft] [--auto-sends]
|
|
88
|
+
every deal create (--person-id <id> | --company-id <id> | --name <name> [--email <email>])
|
|
89
|
+
[--stage <s>] [--deal-name <name>] [--value <n>] [--owner <owner>] [--goal <text>]
|
|
90
|
+
# write: needs --yes
|
|
91
|
+
every deal update <deal_id> [--name <name>] [--value <n>] [--owner <owner>]
|
|
92
|
+
[--person-id <id> | --company-id <id>] [--add-member <id> ...] [--remove-member <id> ...]
|
|
93
|
+
# write: needs --yes; a flag you leave out does not change
|
|
94
|
+
every deal move <deal_id> <stage> # write: needs --yes; stage = key or label
|
|
95
|
+
every deal outreach edit <deal_id> [--subject <text>] [--body <text> | --body-file <path>]
|
|
96
|
+
[--recipient <email>] [--thread <id|new>] # write: needs --yes
|
|
97
|
+
every deal outreach send <deal_id> [--draft-version <v>]
|
|
98
|
+
# destructive: needs --yes --allow-destructive;
|
|
99
|
+
# the owner then approves the send in Every
|
|
100
|
+
every deal outreach cancel <deal_id> --send-id <id> # write: needs --yes
|
|
101
|
+
every approvals [--all] # requests that wait in Every: Settings > Approvals
|
|
76
102
|
|
|
77
103
|
# Teach your coding agent to use all of this well
|
|
78
104
|
every skills install claude # → .claude/skills/use-every/
|
|
@@ -118,6 +144,10 @@ Server-side human approvals never trigger an automatic destructive retry. If Eve
|
|
|
118
144
|
|
|
119
145
|
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.
|
|
120
146
|
|
|
147
|
+
## Scheduled agent runs
|
|
148
|
+
|
|
149
|
+
The bundled `use-every` skill has an **Agent automation** part: the routine for an agent that runs the owner's deals and prospects on a schedule (start-of-run priorities and pending approvals, the attention sweep, follow-ups through `deal_outreach`, plan steps, stage moves, prune and restore, prospect triage). The server returns the same text from `get_started` with `topic=automation`. A send waits for the owner in Every → Settings → Approvals for up to 24 hours; the next run repeats the identical command.
|
|
150
|
+
|
|
121
151
|
## Headless / CI
|
|
122
152
|
|
|
123
153
|
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; `signup` does not need one.
|
package/dist/commands/aliases.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { CliError } from '../lib/errors.js';
|
|
3
3
|
import { ExitCode } from '../lib/exit-codes.js';
|
|
4
|
-
import {
|
|
4
|
+
import { emit } from '../lib/output.js';
|
|
5
|
+
import { documentKind, preservedExclusions, record, recipientBinding, recipientLines } from '../lib/recipients.js';
|
|
6
|
+
import { renderTable, shortTime } from '../lib/table.js';
|
|
7
|
+
import { executeToolCall, invokeToolCall, toolCallHuman, } from './tools.js';
|
|
5
8
|
const INVOICE_STATUSES = new Set(['draft', 'issued', 'void']);
|
|
6
9
|
const PAYMENT_STATUSES = new Set(['unpaid', 'paid', 'overdue', 'partial']);
|
|
7
|
-
const DEAL_STAGES = new Set(['lead', 'opportunity', 'won', 'lost']);
|
|
8
10
|
// list_companies/list_people (the live People/Companies search tools) take a
|
|
9
11
|
// free-text `query` param — the retired list_clients/list_contacts tools took `name`.
|
|
10
12
|
const NETWORK_SEARCH_QUERY_PARAM = 'query';
|
|
@@ -30,12 +32,7 @@ function parseLimit(value) {
|
|
|
30
32
|
}
|
|
31
33
|
return limit;
|
|
32
34
|
}
|
|
33
|
-
function
|
|
34
|
-
if (!DEAL_STAGES.has(stage)) {
|
|
35
|
-
throw new CliError(`stage must be one of: ${Array.from(DEAL_STAGES).join(', ')}`, ExitCode.USAGE, 'usage');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function addLimit(args, value) {
|
|
35
|
+
export function addLimit(args, value) {
|
|
39
36
|
const limit = parseLimit(value);
|
|
40
37
|
if (limit !== undefined)
|
|
41
38
|
args.limit = limit;
|
|
@@ -66,7 +63,7 @@ function parsePositiveNumber(value, flag) {
|
|
|
66
63
|
}
|
|
67
64
|
return parsed;
|
|
68
65
|
}
|
|
69
|
-
function nonEmpty(value) {
|
|
66
|
+
export function nonEmpty(value) {
|
|
70
67
|
const trimmed = value?.trim();
|
|
71
68
|
return trimmed ? trimmed : undefined;
|
|
72
69
|
}
|
|
@@ -231,7 +228,7 @@ function selectPartyId(opts) {
|
|
|
231
228
|
}
|
|
232
229
|
return given[0];
|
|
233
230
|
}
|
|
234
|
-
async function resolveClient(opts) {
|
|
231
|
+
async function resolveClient(opts, partyName) {
|
|
235
232
|
const partyId = selectPartyId(opts);
|
|
236
233
|
const selector = selectParty(opts);
|
|
237
234
|
if (partyId) {
|
|
@@ -245,6 +242,21 @@ async function resolveClient(opts) {
|
|
|
245
242
|
};
|
|
246
243
|
}
|
|
247
244
|
if (!selector) {
|
|
245
|
+
if (partyName) {
|
|
246
|
+
const matches = [];
|
|
247
|
+
for (const kind of ['company', 'person']) {
|
|
248
|
+
const tool = kind === 'company' ? 'list_companies' : 'list_people';
|
|
249
|
+
const result = await invokeToolCall(tool, opts, async () => ({ query: partyName }));
|
|
250
|
+
matches.push(...parseClientCandidates(result).map((candidate) => ({ ...candidate, kind })));
|
|
251
|
+
}
|
|
252
|
+
if (matches.length === 1)
|
|
253
|
+
return matches[0];
|
|
254
|
+
throw new CliError(matches.length === 0 ? `No Person or Company matching "${partyName}".` : [
|
|
255
|
+
`Multiple People or Companies match "${partyName}".`,
|
|
256
|
+
...matches.map((candidate) => `${candidate.kind} ${candidate.client_id} ${candidate.name}`),
|
|
257
|
+
'Re-run with --company-id <id> or --person-id <id>.',
|
|
258
|
+
].join('\n'), ExitCode.NOT_FOUND, 'not_found', { candidates: matches });
|
|
259
|
+
}
|
|
248
260
|
throw new CliError('One of --company, --person, --company-id, or --person-id is required', ExitCode.USAGE, 'usage');
|
|
249
261
|
}
|
|
250
262
|
const tool = selector.kind === 'person' ? 'list_people' : 'list_companies';
|
|
@@ -270,7 +282,99 @@ export async function invoiceListCommand(opts = {}) {
|
|
|
270
282
|
await executeToolCall('list_invoices', opts, async () => args);
|
|
271
283
|
}
|
|
272
284
|
export async function invoiceSendCommand(invoiceId, opts = {}) {
|
|
273
|
-
await
|
|
285
|
+
await documentSendCommand('invoice', invoiceId, opts);
|
|
286
|
+
}
|
|
287
|
+
export async function proposalSendCommand(proposalId, opts = {}) {
|
|
288
|
+
await documentSendCommand('proposal', proposalId, opts);
|
|
289
|
+
}
|
|
290
|
+
async function documentSendCommand(kind, id, opts) {
|
|
291
|
+
if (opts.expectDigest !== undefined && !/^[a-f0-9]{64}$/.test(opts.expectDigest)) {
|
|
292
|
+
throw new CliError('--expect-digest must be the 64-character digest from the approved preview.', ExitCode.USAGE, 'usage');
|
|
293
|
+
}
|
|
294
|
+
let preview = {};
|
|
295
|
+
let binding;
|
|
296
|
+
await executeToolCall(`send_${kind}`, opts, async () => ({ [`${kind}_id`]: id, recipients: binding }), (data) => ({ ...data, preview }), {
|
|
297
|
+
recipientConfirmation: true,
|
|
298
|
+
beforeConfirmation: async () => {
|
|
299
|
+
const result = await invokeToolCall('preview_document_send', opts, async () => ({ document_kind: kind, document_id: id }));
|
|
300
|
+
preview = record(result.structured_content);
|
|
301
|
+
if (preview.document_id !== id || preview.document_kind !== kind) {
|
|
302
|
+
throw new CliError('The server returned a preview for a different document or kind. No document was sent.', ExitCode.GENERIC, 'send_preview_mismatch');
|
|
303
|
+
}
|
|
304
|
+
binding = recipientBinding(preview.recipients);
|
|
305
|
+
process.stderr.write(`${recipientLines(preview)}\n`);
|
|
306
|
+
if (opts.expectDigest !== undefined && binding.digest !== opts.expectDigest) {
|
|
307
|
+
throw new CliError('The recipient digest does not match --expect-digest. Review these recipients and get approval before you send again.', ExitCode.GENERIC, 'send_preparation_stale', { expected_digest: opts.expectDigest, actual_digest: binding.digest });
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function recipientPartyArgs(party, kind) {
|
|
313
|
+
return { party_kind: party.kind, party_id: party.client_id, document_kind: kind, kind };
|
|
314
|
+
}
|
|
315
|
+
export async function recipientsGetCommand(party, opts = {}) {
|
|
316
|
+
const kind = documentKind(opts.kind);
|
|
317
|
+
const resolved = await resolveClient(opts, party);
|
|
318
|
+
await executeToolCall('get_recipient_defaults', opts, async () => recipientPartyArgs(resolved, kind), undefined, undefined, (data) => recipientLines(record(data.structured_content)));
|
|
319
|
+
}
|
|
320
|
+
function resolveRecipientMethod(value, methods) {
|
|
321
|
+
const matches = methods.filter((method) => method.id === value ||
|
|
322
|
+
[method.delivery_address, method.normalized_value, method.value].some((address) => typeof address === 'string' && address.toLowerCase() === value.toLowerCase()));
|
|
323
|
+
if (matches.length !== 1 || typeof matches[0].id !== 'string') {
|
|
324
|
+
throw new CliError(matches.length > 1
|
|
325
|
+
? `Multiple eligible methods match "${value}". Use a method ID.`
|
|
326
|
+
: `No eligible email method matches "${value}". Run every recipients get first.`, ExitCode.USAGE, 'usage', { candidates: matches });
|
|
327
|
+
}
|
|
328
|
+
return matches[0].id;
|
|
329
|
+
}
|
|
330
|
+
export async function recipientsSetCommand(party, opts = {}) {
|
|
331
|
+
const kind = documentKind(opts.kind);
|
|
332
|
+
const to = nonEmpty(opts.to);
|
|
333
|
+
if (!to)
|
|
334
|
+
throw new CliError('--to is required', ExitCode.USAGE, 'usage');
|
|
335
|
+
if (opts.clearCc && opts.cc?.length) {
|
|
336
|
+
throw new CliError('Use --cc or --clear-cc, not both.', ExitCode.USAGE, 'usage');
|
|
337
|
+
}
|
|
338
|
+
let args = {};
|
|
339
|
+
await executeToolCall('set_recipient_defaults', opts, async () => args, undefined, {
|
|
340
|
+
beforeConfirmation: async () => {
|
|
341
|
+
const resolved = await resolveClient(opts, party);
|
|
342
|
+
const partyArgs = recipientPartyArgs(resolved, kind);
|
|
343
|
+
const defaults = record((await invokeToolCall('get_recipient_defaults', opts, async () => partyArgs)).structured_content);
|
|
344
|
+
if (!Number.isInteger(defaults.version) || Number(defaults.version) < 0 || !Array.isArray(defaults.eligible_methods)) {
|
|
345
|
+
throw new CliError('The server returned invalid recipient defaults. No defaults were changed.');
|
|
346
|
+
}
|
|
347
|
+
const noneIds = preservedExclusions(defaults);
|
|
348
|
+
const methods = defaults.eligible_methods.map(record);
|
|
349
|
+
const toId = resolveRecipientMethod(to, methods);
|
|
350
|
+
const currentCc = record(defaults.effective).cc_method_ids ?? defaults.cc_method_ids;
|
|
351
|
+
if (opts.cc === undefined && !opts.clearCc && !Array.isArray(currentCc)) {
|
|
352
|
+
throw new CliError('The current CC recipients are unavailable. Use --cc or --clear-cc explicitly.');
|
|
353
|
+
}
|
|
354
|
+
const ccIds = opts.clearCc ? [] : opts.cc
|
|
355
|
+
? opts.cc.map((value) => resolveRecipientMethod(value, methods))
|
|
356
|
+
: currentCc.filter((id) => id !== toId);
|
|
357
|
+
if (ccIds.includes(toId) || new Set(ccIds).size !== ccIds.length) {
|
|
358
|
+
throw new CliError('Select each recipient once. To and CC must use different methods.', ExitCode.USAGE, 'usage');
|
|
359
|
+
}
|
|
360
|
+
if ([toId, ...ccIds].some((id) => noneIds.includes(id))) {
|
|
361
|
+
throw new CliError('A selected method is excluded. This command preserves exclusions. Change the exclusion explicitly before you select it.', ExitCode.USAGE, 'usage');
|
|
362
|
+
}
|
|
363
|
+
const selected = [toId, ...ccIds].map((id) => {
|
|
364
|
+
resolveRecipientMethod(id, methods);
|
|
365
|
+
return methods.find((method) => method.id === id);
|
|
366
|
+
});
|
|
367
|
+
args = { ...partyArgs, command: {
|
|
368
|
+
operation_id: randomUUID(), expected_version: defaults.version,
|
|
369
|
+
to_method_id: toId, cc_method_ids: ccIds,
|
|
370
|
+
none_method_ids: noneIds,
|
|
371
|
+
} };
|
|
372
|
+
process.stderr.write(`${recipientLines({ eligible_methods: methods, recipient_preview: {
|
|
373
|
+
to: selected[0].delivery_address,
|
|
374
|
+
cc: selected.slice(1).map((method) => method.delivery_address),
|
|
375
|
+
} })}\n`);
|
|
376
|
+
},
|
|
377
|
+
}, (data) => recipientLines(record(data.structured_content)));
|
|
274
378
|
}
|
|
275
379
|
export async function invoiceCreateCommand(opts = {}) {
|
|
276
380
|
const amount = parsePositiveNumber(opts.amount, '--amount');
|
|
@@ -301,18 +405,226 @@ export async function invoiceCreateCommand(opts = {}) {
|
|
|
301
405
|
}
|
|
302
406
|
export async function dealListCommand(opts = {}) {
|
|
303
407
|
const args = {};
|
|
304
|
-
|
|
305
|
-
|
|
408
|
+
// Stages are per-workspace (a key or a label, e.g. "lead" or "Discovery
|
|
409
|
+
// booked"); the server resolves them and answers stage_not_found with the
|
|
410
|
+
// workspace's live list, so there is no client-side stage check.
|
|
411
|
+
if (opts.stage !== undefined)
|
|
306
412
|
args.stage = opts.stage;
|
|
307
|
-
}
|
|
308
413
|
if (opts.search !== undefined)
|
|
309
414
|
args.search = opts.search;
|
|
310
415
|
addLimit(args, opts.limit);
|
|
311
|
-
|
|
416
|
+
// The attention-sweep filters (list_deals, 2026-11). A call without them
|
|
417
|
+
// sends the same arguments and prints the same output as before.
|
|
418
|
+
const sweep = dealSweepArgs(opts);
|
|
419
|
+
Object.assign(args, sweep);
|
|
420
|
+
const human = Object.keys(sweep).length > 0 ? dealTableHuman : undefined;
|
|
421
|
+
await withStageErrors(opts.stage, () => executeToolCall('list_deals', opts, async () => args, undefined, undefined, human));
|
|
422
|
+
}
|
|
423
|
+
export const ATTENTION_REASONS = ['needs_reply', 'step_due', 'draft_ready', 'stale'];
|
|
424
|
+
const DEAL_SORTS = new Set(['last_activity_at']);
|
|
425
|
+
function parseAttention(values) {
|
|
426
|
+
if (values === undefined)
|
|
427
|
+
return undefined;
|
|
428
|
+
const reasons = Array.from(new Set(values
|
|
429
|
+
.flatMap((value) => value.split(','))
|
|
430
|
+
.map((value) => value.trim())
|
|
431
|
+
.filter(Boolean)));
|
|
432
|
+
const unknown = reasons.filter((reason) => !ATTENTION_REASONS.includes(reason));
|
|
433
|
+
if (reasons.length === 0 || unknown.length > 0) {
|
|
434
|
+
throw new CliError(`--attention must be one or more of: ${ATTENTION_REASONS.join(', ')}`, ExitCode.USAGE, 'usage');
|
|
435
|
+
}
|
|
436
|
+
return reasons;
|
|
437
|
+
}
|
|
438
|
+
function dealSweepArgs(opts) {
|
|
439
|
+
const args = {};
|
|
440
|
+
const attention = parseAttention(opts.attention);
|
|
441
|
+
if (attention)
|
|
442
|
+
args.attention = attention;
|
|
443
|
+
if (opts.staleDays !== undefined) {
|
|
444
|
+
const days = Number(opts.staleDays);
|
|
445
|
+
if (!Number.isInteger(days) || days < 1) {
|
|
446
|
+
throw new CliError('--stale-days must be a whole number of days, 1 or more', ExitCode.USAGE, 'usage');
|
|
447
|
+
}
|
|
448
|
+
args.inactive_days = days;
|
|
449
|
+
}
|
|
450
|
+
const owner = nonEmpty(opts.owner);
|
|
451
|
+
if (opts.owner !== undefined && !owner) {
|
|
452
|
+
throw new CliError('--owner must be me, an email, or a user id', ExitCode.USAGE, 'usage');
|
|
453
|
+
}
|
|
454
|
+
if (opts.mine && owner && owner !== 'me') {
|
|
455
|
+
throw new CliError('Use --mine or --owner, not both', ExitCode.USAGE, 'usage');
|
|
456
|
+
}
|
|
457
|
+
if (opts.mine)
|
|
458
|
+
args.owner = 'me';
|
|
459
|
+
else if (owner)
|
|
460
|
+
args.owner = owner;
|
|
461
|
+
if (opts.since !== undefined) {
|
|
462
|
+
const since = opts.since.trim();
|
|
463
|
+
if (!since || Number.isNaN(Date.parse(since))) {
|
|
464
|
+
throw new CliError('--since must be an ISO 8601 time, for example 2026-11-01T00:00:00Z', ExitCode.USAGE, 'usage');
|
|
465
|
+
}
|
|
466
|
+
args.updated_since = since;
|
|
467
|
+
}
|
|
468
|
+
if (opts.sort !== undefined) {
|
|
469
|
+
if (!DEAL_SORTS.has(opts.sort)) {
|
|
470
|
+
throw new CliError(`--sort must be: ${Array.from(DEAL_SORTS).join(', ')}`, ExitCode.USAGE, 'usage');
|
|
471
|
+
}
|
|
472
|
+
args.sort = opts.sort;
|
|
473
|
+
}
|
|
474
|
+
return args;
|
|
475
|
+
}
|
|
476
|
+
function dealName(deal) {
|
|
477
|
+
return stringField(deal, ['display_name', 'name', 'label', 'contact', 'company']) ?? '';
|
|
478
|
+
}
|
|
479
|
+
function nextStepText(value) {
|
|
480
|
+
const step = record(value);
|
|
481
|
+
const title = typeof step.title === 'string' ? step.title : '';
|
|
482
|
+
if (!title)
|
|
483
|
+
return '';
|
|
484
|
+
return typeof step.do_by === 'string' && step.do_by ? `${title} (${step.do_by})` : title;
|
|
485
|
+
}
|
|
486
|
+
/** The deal table for the attention-sweep filters. It shows only what the server returned. */
|
|
487
|
+
export function dealTableHuman(data) {
|
|
488
|
+
const structured = record(data.structured_content);
|
|
489
|
+
if (!Array.isArray(structured.deals))
|
|
490
|
+
return toolCallHuman(data);
|
|
491
|
+
const deals = structured.deals.map(record);
|
|
492
|
+
if (deals.length === 0)
|
|
493
|
+
return 'No deals match these filters.';
|
|
494
|
+
const columns = [
|
|
495
|
+
{ header: 'id', max: 36 },
|
|
496
|
+
{ header: 'deal', max: 32 },
|
|
497
|
+
{ header: 'stage', max: 20 },
|
|
498
|
+
];
|
|
499
|
+
const cells = [
|
|
500
|
+
(deal) => String(deal.id ?? ''),
|
|
501
|
+
dealName,
|
|
502
|
+
(deal) => stringField(deal, ['stage_label', 'stage']) ?? '',
|
|
503
|
+
];
|
|
504
|
+
if (deals.some((deal) => typeof deal.last_activity_at === 'string')) {
|
|
505
|
+
columns.push({ header: 'last activity', max: 16 });
|
|
506
|
+
cells.push((deal) => shortTime(deal.last_activity_at));
|
|
507
|
+
}
|
|
508
|
+
if (deals.some((deal) => nextStepText(deal.next_step))) {
|
|
509
|
+
columns.push({ header: 'next step', max: 48 });
|
|
510
|
+
cells.push((deal) => nextStepText(deal.next_step));
|
|
511
|
+
}
|
|
512
|
+
if (deals.some((deal) => Array.isArray(deal.attention) && deal.attention.length > 0)) {
|
|
513
|
+
columns.push({ header: 'attention' });
|
|
514
|
+
cells.push((deal) => (Array.isArray(deal.attention) ? deal.attention.join(', ') : ''));
|
|
515
|
+
}
|
|
516
|
+
const lines = [renderTable(columns, deals.map((deal) => cells.map((render) => render(deal))))];
|
|
517
|
+
const page = record(structured.pagination);
|
|
518
|
+
if (page.has_more === true) {
|
|
519
|
+
const total = typeof page.total_matched === 'number' ? ` of ${page.total_matched}` : '';
|
|
520
|
+
lines.push('', `Showing ${deals.length}${total} deals. Raise --limit to see more.`);
|
|
521
|
+
}
|
|
522
|
+
return lines.join('\n');
|
|
312
523
|
}
|
|
313
524
|
export async function dealMoveCommand(dealId, stage, opts = {}) {
|
|
314
|
-
|
|
315
|
-
|
|
525
|
+
await withStageErrors(stage, () => executeToolCall('move_deal_stage', opts, async () => ({ deal_id: dealId, stage })));
|
|
526
|
+
}
|
|
527
|
+
function stageName(stage) {
|
|
528
|
+
for (const field of ['label', 'key']) {
|
|
529
|
+
const value = stage[field];
|
|
530
|
+
if (typeof value === 'string' && value.trim())
|
|
531
|
+
return value.trim();
|
|
532
|
+
}
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
/** `Unknown stage "<input>". Available stages: Lead, Discovery booked, ...` */
|
|
536
|
+
export function unknownStageMessage(input, available) {
|
|
537
|
+
const names = Array.isArray(available)
|
|
538
|
+
? available
|
|
539
|
+
.map((entry) => entry && typeof entry === 'object' ? stageName(entry) : undefined)
|
|
540
|
+
.filter((name) => name !== undefined)
|
|
541
|
+
: [];
|
|
542
|
+
const list = names.length ? names.join(', ') : 'run `every deal stages` to list them';
|
|
543
|
+
return `Unknown stage "${input}". Available stages: ${list}`;
|
|
544
|
+
}
|
|
545
|
+
// The server's stage_not_found refusal carries the workspace's live stage list
|
|
546
|
+
// (structuredContent.error.available_stages). Re-render it as one readable
|
|
547
|
+
// sentence; the error code, exit status and tool_error details are unchanged.
|
|
548
|
+
async function withStageErrors(input, run) {
|
|
549
|
+
try {
|
|
550
|
+
await run();
|
|
551
|
+
}
|
|
552
|
+
catch (err) {
|
|
553
|
+
if (err instanceof CliError && err.code === 'stage_not_found') {
|
|
554
|
+
const toolError = (err.details?.tool_error ?? {});
|
|
555
|
+
const stage = typeof toolError.stage === 'string' ? toolError.stage : input ?? '';
|
|
556
|
+
throw new CliError(unknownStageMessage(stage, toolError.available_stages), err.exitCode, err.code, err.details);
|
|
557
|
+
}
|
|
558
|
+
throw err;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function oneLine(value, max = 80) {
|
|
562
|
+
const text = typeof value === 'string' ? value.replace(/\s+/g, ' ').trim() : '';
|
|
563
|
+
return text.length > max ? `${text.slice(0, max - 3)}...` : text;
|
|
564
|
+
}
|
|
565
|
+
/** The ordered stage list from get_pipeline_settings' structured result. */
|
|
566
|
+
export function parsePipelineStages(structured) {
|
|
567
|
+
if (!structured || typeof structured !== 'object')
|
|
568
|
+
return [];
|
|
569
|
+
const record = structured;
|
|
570
|
+
const body = (record.result && typeof record.result === 'object' ? record.result : record);
|
|
571
|
+
let entries = body.stages;
|
|
572
|
+
// A server that predates customizable stages returns a map keyed by the
|
|
573
|
+
// four default stage names instead of the ordered list.
|
|
574
|
+
if (entries && typeof entries === 'object' && !Array.isArray(entries)) {
|
|
575
|
+
entries = Object.entries(entries).map(([key, value]) => ({
|
|
576
|
+
...(value && typeof value === 'object' ? value : {}),
|
|
577
|
+
key,
|
|
578
|
+
label: key.charAt(0).toUpperCase() + key.slice(1),
|
|
579
|
+
role: LEGACY_STAGE_ROLES[key] ?? 'middle',
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
if (!Array.isArray(entries))
|
|
583
|
+
return [];
|
|
584
|
+
return entries
|
|
585
|
+
.filter((entry) => Boolean(entry) && typeof entry === 'object')
|
|
586
|
+
.map((entry) => ({
|
|
587
|
+
key: String(entry.key ?? entry.name ?? ''),
|
|
588
|
+
label: String(entry.label ?? entry.display_name ?? entry.key ?? ''),
|
|
589
|
+
role: String(entry.role ?? ''),
|
|
590
|
+
criteria: typeof entry.criteria === 'string' ? entry.criteria : '',
|
|
591
|
+
...(typeof entry.agent_can_move_to_stage === 'boolean'
|
|
592
|
+
? { agent_can_move_to_stage: entry.agent_can_move_to_stage }
|
|
593
|
+
: {}),
|
|
594
|
+
}))
|
|
595
|
+
.filter((stage) => stage.key);
|
|
596
|
+
}
|
|
597
|
+
const LEGACY_STAGE_ROLES = {
|
|
598
|
+
lead: 'lead',
|
|
599
|
+
opportunity: 'middle',
|
|
600
|
+
won: 'won',
|
|
601
|
+
lost: 'lost',
|
|
602
|
+
};
|
|
603
|
+
export function stagesHuman(stages) {
|
|
604
|
+
if (!stages.length) {
|
|
605
|
+
return 'No pipeline stages returned. Run: every tool call get_pipeline_settings --json';
|
|
606
|
+
}
|
|
607
|
+
// Labels can be up to 40 characters (the server limit), so the column fits them all.
|
|
608
|
+
const labelWidth = Math.min(40, Math.max('label'.length, ...stages.map((s) => s.label.length)));
|
|
609
|
+
const keyWidth = Math.min(20, Math.max('key'.length, ...stages.map((s) => s.key.length)));
|
|
610
|
+
const roleWidth = Math.max('role'.length, ...stages.map((s) => s.role.length));
|
|
611
|
+
const lines = [
|
|
612
|
+
`${'label'.padEnd(labelWidth)} ${'key'.padEnd(keyWidth)} ${'role'.padEnd(roleWidth)} criteria`,
|
|
613
|
+
`${'-'.repeat(labelWidth)} ${'-'.repeat(keyWidth)} ${'-'.repeat(roleWidth)} ${'-'.repeat(8)}`,
|
|
614
|
+
];
|
|
615
|
+
for (const stage of stages) {
|
|
616
|
+
lines.push(`${stage.label.padEnd(labelWidth)} ${stage.key.padEnd(keyWidth)} ${stage.role.padEnd(roleWidth)} ${oneLine(stage.criteria)}`);
|
|
617
|
+
}
|
|
618
|
+
lines.push('', 'Pass a key or a label to: every deal move <deal_id> <stage> | every deal list --stage <stage>');
|
|
619
|
+
return lines.join('\n');
|
|
620
|
+
}
|
|
621
|
+
export async function dealStagesCommand(opts = {}) {
|
|
622
|
+
const data = await invokeToolCall('get_pipeline_settings', opts);
|
|
623
|
+
const stages = parsePipelineStages(data.structured_content);
|
|
624
|
+
if (opts.json)
|
|
625
|
+
emit({ ...data, stages }, { json: true, staging: opts.staging });
|
|
626
|
+
else
|
|
627
|
+
process.stdout.write(`${stagesHuman(stages)}\n`);
|
|
316
628
|
}
|
|
317
629
|
export async function personListCommand(opts = {}) {
|
|
318
630
|
const args = {};
|