@everyai/cli 0.8.1 → 0.9.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/dist/commands/aliases.js +110 -2
- package/dist/commands/tools.js +42 -6
- package/dist/index.js +34 -4
- package/dist/lib/policy.js +7 -0
- package/dist/lib/recipients.js +60 -0
- package/package.json +1 -1
- package/skills/use-every/SKILL.md +10 -4
package/dist/commands/aliases.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 { documentKind, preservedExclusions, record, recipientBinding, recipientLines } from '../lib/recipients.js';
|
|
4
5
|
import { executeToolCall, invokeToolCall, } from './tools.js';
|
|
5
6
|
const INVOICE_STATUSES = new Set(['draft', 'issued', 'void']);
|
|
6
7
|
const PAYMENT_STATUSES = new Set(['unpaid', 'paid', 'overdue', 'partial']);
|
|
@@ -231,7 +232,7 @@ function selectPartyId(opts) {
|
|
|
231
232
|
}
|
|
232
233
|
return given[0];
|
|
233
234
|
}
|
|
234
|
-
async function resolveClient(opts) {
|
|
235
|
+
async function resolveClient(opts, partyName) {
|
|
235
236
|
const partyId = selectPartyId(opts);
|
|
236
237
|
const selector = selectParty(opts);
|
|
237
238
|
if (partyId) {
|
|
@@ -245,6 +246,21 @@ async function resolveClient(opts) {
|
|
|
245
246
|
};
|
|
246
247
|
}
|
|
247
248
|
if (!selector) {
|
|
249
|
+
if (partyName) {
|
|
250
|
+
const matches = [];
|
|
251
|
+
for (const kind of ['company', 'person']) {
|
|
252
|
+
const tool = kind === 'company' ? 'list_companies' : 'list_people';
|
|
253
|
+
const result = await invokeToolCall(tool, opts, async () => ({ query: partyName }));
|
|
254
|
+
matches.push(...parseClientCandidates(result).map((candidate) => ({ ...candidate, kind })));
|
|
255
|
+
}
|
|
256
|
+
if (matches.length === 1)
|
|
257
|
+
return matches[0];
|
|
258
|
+
throw new CliError(matches.length === 0 ? `No Person or Company matching "${partyName}".` : [
|
|
259
|
+
`Multiple People or Companies match "${partyName}".`,
|
|
260
|
+
...matches.map((candidate) => `${candidate.kind} ${candidate.client_id} ${candidate.name}`),
|
|
261
|
+
'Re-run with --company-id <id> or --person-id <id>.',
|
|
262
|
+
].join('\n'), ExitCode.NOT_FOUND, 'not_found', { candidates: matches });
|
|
263
|
+
}
|
|
248
264
|
throw new CliError('One of --company, --person, --company-id, or --person-id is required', ExitCode.USAGE, 'usage');
|
|
249
265
|
}
|
|
250
266
|
const tool = selector.kind === 'person' ? 'list_people' : 'list_companies';
|
|
@@ -270,7 +286,99 @@ export async function invoiceListCommand(opts = {}) {
|
|
|
270
286
|
await executeToolCall('list_invoices', opts, async () => args);
|
|
271
287
|
}
|
|
272
288
|
export async function invoiceSendCommand(invoiceId, opts = {}) {
|
|
273
|
-
await
|
|
289
|
+
await documentSendCommand('invoice', invoiceId, opts);
|
|
290
|
+
}
|
|
291
|
+
export async function proposalSendCommand(proposalId, opts = {}) {
|
|
292
|
+
await documentSendCommand('proposal', proposalId, opts);
|
|
293
|
+
}
|
|
294
|
+
async function documentSendCommand(kind, id, opts) {
|
|
295
|
+
if (opts.expectDigest !== undefined && !/^[a-f0-9]{64}$/.test(opts.expectDigest)) {
|
|
296
|
+
throw new CliError('--expect-digest must be the 64-character digest from the approved preview.', ExitCode.USAGE, 'usage');
|
|
297
|
+
}
|
|
298
|
+
let preview = {};
|
|
299
|
+
let binding;
|
|
300
|
+
await executeToolCall(`send_${kind}`, opts, async () => ({ [`${kind}_id`]: id, recipients: binding }), (data) => ({ ...data, preview }), {
|
|
301
|
+
recipientConfirmation: true,
|
|
302
|
+
beforeConfirmation: async () => {
|
|
303
|
+
const result = await invokeToolCall('preview_document_send', opts, async () => ({ document_kind: kind, document_id: id }));
|
|
304
|
+
preview = record(result.structured_content);
|
|
305
|
+
if (preview.document_id !== id || preview.document_kind !== kind) {
|
|
306
|
+
throw new CliError('The server returned a preview for a different document or kind. No document was sent.', ExitCode.GENERIC, 'send_preview_mismatch');
|
|
307
|
+
}
|
|
308
|
+
binding = recipientBinding(preview.recipients);
|
|
309
|
+
process.stderr.write(`${recipientLines(preview)}\n`);
|
|
310
|
+
if (opts.expectDigest !== undefined && binding.digest !== opts.expectDigest) {
|
|
311
|
+
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 });
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
function recipientPartyArgs(party, kind) {
|
|
317
|
+
return { party_kind: party.kind, party_id: party.client_id, document_kind: kind, kind };
|
|
318
|
+
}
|
|
319
|
+
export async function recipientsGetCommand(party, opts = {}) {
|
|
320
|
+
const kind = documentKind(opts.kind);
|
|
321
|
+
const resolved = await resolveClient(opts, party);
|
|
322
|
+
await executeToolCall('get_recipient_defaults', opts, async () => recipientPartyArgs(resolved, kind), undefined, undefined, (data) => recipientLines(record(data.structured_content)));
|
|
323
|
+
}
|
|
324
|
+
function resolveRecipientMethod(value, methods) {
|
|
325
|
+
const matches = methods.filter((method) => method.id === value ||
|
|
326
|
+
[method.delivery_address, method.normalized_value, method.value].some((address) => typeof address === 'string' && address.toLowerCase() === value.toLowerCase()));
|
|
327
|
+
if (matches.length !== 1 || typeof matches[0].id !== 'string') {
|
|
328
|
+
throw new CliError(matches.length > 1
|
|
329
|
+
? `Multiple eligible methods match "${value}". Use a method ID.`
|
|
330
|
+
: `No eligible email method matches "${value}". Run every recipients get first.`, ExitCode.USAGE, 'usage', { candidates: matches });
|
|
331
|
+
}
|
|
332
|
+
return matches[0].id;
|
|
333
|
+
}
|
|
334
|
+
export async function recipientsSetCommand(party, opts = {}) {
|
|
335
|
+
const kind = documentKind(opts.kind);
|
|
336
|
+
const to = nonEmpty(opts.to);
|
|
337
|
+
if (!to)
|
|
338
|
+
throw new CliError('--to is required', ExitCode.USAGE, 'usage');
|
|
339
|
+
if (opts.clearCc && opts.cc?.length) {
|
|
340
|
+
throw new CliError('Use --cc or --clear-cc, not both.', ExitCode.USAGE, 'usage');
|
|
341
|
+
}
|
|
342
|
+
let args = {};
|
|
343
|
+
await executeToolCall('set_recipient_defaults', opts, async () => args, undefined, {
|
|
344
|
+
beforeConfirmation: async () => {
|
|
345
|
+
const resolved = await resolveClient(opts, party);
|
|
346
|
+
const partyArgs = recipientPartyArgs(resolved, kind);
|
|
347
|
+
const defaults = record((await invokeToolCall('get_recipient_defaults', opts, async () => partyArgs)).structured_content);
|
|
348
|
+
if (!Number.isInteger(defaults.version) || Number(defaults.version) < 0 || !Array.isArray(defaults.eligible_methods)) {
|
|
349
|
+
throw new CliError('The server returned invalid recipient defaults. No defaults were changed.');
|
|
350
|
+
}
|
|
351
|
+
const noneIds = preservedExclusions(defaults);
|
|
352
|
+
const methods = defaults.eligible_methods.map(record);
|
|
353
|
+
const toId = resolveRecipientMethod(to, methods);
|
|
354
|
+
const currentCc = record(defaults.effective).cc_method_ids ?? defaults.cc_method_ids;
|
|
355
|
+
if (opts.cc === undefined && !opts.clearCc && !Array.isArray(currentCc)) {
|
|
356
|
+
throw new CliError('The current CC recipients are unavailable. Use --cc or --clear-cc explicitly.');
|
|
357
|
+
}
|
|
358
|
+
const ccIds = opts.clearCc ? [] : opts.cc
|
|
359
|
+
? opts.cc.map((value) => resolveRecipientMethod(value, methods))
|
|
360
|
+
: currentCc.filter((id) => id !== toId);
|
|
361
|
+
if (ccIds.includes(toId) || new Set(ccIds).size !== ccIds.length) {
|
|
362
|
+
throw new CliError('Select each recipient once. To and CC must use different methods.', ExitCode.USAGE, 'usage');
|
|
363
|
+
}
|
|
364
|
+
if ([toId, ...ccIds].some((id) => noneIds.includes(id))) {
|
|
365
|
+
throw new CliError('A selected method is excluded. This command preserves exclusions. Change the exclusion explicitly before you select it.', ExitCode.USAGE, 'usage');
|
|
366
|
+
}
|
|
367
|
+
const selected = [toId, ...ccIds].map((id) => {
|
|
368
|
+
resolveRecipientMethod(id, methods);
|
|
369
|
+
return methods.find((method) => method.id === id);
|
|
370
|
+
});
|
|
371
|
+
args = { ...partyArgs, command: {
|
|
372
|
+
operation_id: randomUUID(), expected_version: defaults.version,
|
|
373
|
+
to_method_id: toId, cc_method_ids: ccIds,
|
|
374
|
+
none_method_ids: noneIds,
|
|
375
|
+
} };
|
|
376
|
+
process.stderr.write(`${recipientLines({ eligible_methods: methods, recipient_preview: {
|
|
377
|
+
to: selected[0].delivery_address,
|
|
378
|
+
cc: selected.slice(1).map((method) => method.delivery_address),
|
|
379
|
+
} })}\n`);
|
|
380
|
+
},
|
|
381
|
+
}, (data) => recipientLines(record(data.structured_content)));
|
|
274
382
|
}
|
|
275
383
|
export async function invoiceCreateCommand(opts = {}) {
|
|
276
384
|
const amount = parsePositiveNumber(opts.amount, '--amount');
|
package/dist/commands/tools.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CliError } from '../lib/errors.js';
|
|
|
4
4
|
import { ExitCode } from '../lib/exit-codes.js';
|
|
5
5
|
import { callTool, listTools } from '../lib/mcp.js';
|
|
6
6
|
import { emit } from '../lib/output.js';
|
|
7
|
+
import { recipientBinding, recipientLines } from '../lib/recipients.js';
|
|
7
8
|
import { classify, promptForTool, requirementDescription, requirementFor, } from '../lib/policy.js';
|
|
8
9
|
import { activeCredentialIsApiKey } from '../lib/auth/api-key.js';
|
|
9
10
|
import { getToken } from '../lib/auth/tokens.js';
|
|
@@ -17,6 +18,15 @@ import { parseMcpGateMetadata, SERVER_CONFIRMATION_ARG, withoutMcpGateMarker, }
|
|
|
17
18
|
*/
|
|
18
19
|
export const SIGNUP_INCOMPLETE_GUIDANCE = 'Finish signup first: run `every signup status` to see what is needed, confirm the ' +
|
|
19
20
|
'organization name with the user, then run `every signup complete --org-name "<name>" --yes`.';
|
|
21
|
+
const RECIPIENT_ERROR_MESSAGES = {
|
|
22
|
+
send_preparation_stale: 'The recipients changed after the preview. Run the command again to see the new recipients.',
|
|
23
|
+
recipient_required: 'Choose a To recipient with every recipients set <party> --kind invoice|proposal --to <email-or-id> before you send.',
|
|
24
|
+
recipient_model_quiet: 'Recipient changes and sends are paused. Try again later.',
|
|
25
|
+
recipient_model_unavailable: 'The recipient service is unavailable. Try again later.',
|
|
26
|
+
};
|
|
27
|
+
function recipientErrorCode(message) {
|
|
28
|
+
return message.trim().replace(/^Error executing tool ['"]?(?:send_invoice|send_proposal|preview_document_send|get_recipient_defaults|set_recipient_defaults)['"]?:\s*/, '');
|
|
29
|
+
}
|
|
20
30
|
function emitCommand(data, human, opts) {
|
|
21
31
|
if (opts.json)
|
|
22
32
|
emit(data, { json: true, staging: opts.staging });
|
|
@@ -253,10 +263,11 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
253
263
|
const requirement = requirementFor(classification.level, {
|
|
254
264
|
interactive,
|
|
255
265
|
yes: opts.yes,
|
|
256
|
-
allowDestructive: opts.allowDestructive,
|
|
266
|
+
allowDestructive: opts.allowDestructive || hooks.recipientConfirmation,
|
|
257
267
|
readOnlyMode,
|
|
258
268
|
});
|
|
259
|
-
|
|
269
|
+
const needsRecipientYes = hooks.recipientConfirmation && !interactive && !opts.yes && !readOnlyMode;
|
|
270
|
+
if (!requirement.allowed && !needsRecipientYes) {
|
|
260
271
|
throw new CliError(requirement.denialMessage ?? 'Tool call denied by policy.', ExitCode.PERMISSION, 'permission');
|
|
261
272
|
}
|
|
262
273
|
const gated = classification.level !== 'read';
|
|
@@ -264,8 +275,12 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
264
275
|
const userinfo = gated ? await resolveWriteTarget(baseUrl) : undefined;
|
|
265
276
|
const target = gated ? targetLabel(userinfo, environment) : undefined;
|
|
266
277
|
let locallyConfirmed = opts.yes === true;
|
|
278
|
+
await hooks.beforeConfirmation?.();
|
|
279
|
+
if (needsRecipientYes) {
|
|
280
|
+
throw new CliError('Re-run with --yes to send to these recipients.', ExitCode.USAGE, 'usage');
|
|
281
|
+
}
|
|
267
282
|
if (requirement.prompt) {
|
|
268
|
-
const confirmed = await promptForTool(name, classification.level, requirement.prompt, target);
|
|
283
|
+
const confirmed = await promptForTool(name, classification.level, hooks.recipientConfirmation ? 'confirm' : requirement.prompt, target);
|
|
269
284
|
if (!confirmed) {
|
|
270
285
|
throw new CliError('Tool call cancelled.', ExitCode.PERMISSION, 'permission');
|
|
271
286
|
}
|
|
@@ -286,6 +301,12 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
286
301
|
if (timeout)
|
|
287
302
|
throw timeout;
|
|
288
303
|
}
|
|
304
|
+
if (err instanceof CliError && err.code === 'generic') {
|
|
305
|
+
const code = recipientErrorCode(err.message);
|
|
306
|
+
if (RECIPIENT_ERROR_MESSAGES[code]) {
|
|
307
|
+
throw new CliError(RECIPIENT_ERROR_MESSAGES[code], err.exitCode, code, err.details);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
289
310
|
throw err;
|
|
290
311
|
}
|
|
291
312
|
};
|
|
@@ -330,6 +351,11 @@ export async function invokeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
330
351
|
next_steps: ['every signup status --json', 'every signup complete --org-name "<name>" --yes --json'],
|
|
331
352
|
});
|
|
332
353
|
}
|
|
354
|
+
// Some server exceptions return only their exact typed code as text.
|
|
355
|
+
const recipientCode = toolError?.code ?? recipientErrorCode(rawMessage);
|
|
356
|
+
if (RECIPIENT_ERROR_MESSAGES[recipientCode]) {
|
|
357
|
+
throw new CliError(RECIPIENT_ERROR_MESSAGES[recipientCode], ExitCode.GENERIC, recipientCode, toolError ? { tool_error: toolError } : undefined);
|
|
358
|
+
}
|
|
333
359
|
if (toolError) {
|
|
334
360
|
throw new CliError(rawMessage, ExitCode.GENERIC, toolError.code, { tool_error: toolError });
|
|
335
361
|
}
|
|
@@ -349,11 +375,21 @@ function structuredToolError(structured) {
|
|
|
349
375
|
return undefined;
|
|
350
376
|
return { ...error, code };
|
|
351
377
|
}
|
|
352
|
-
export async function executeToolCall(name, opts = {}, argsFactory = async () => ({}), augmentData = (data) => data) {
|
|
353
|
-
const data = await augmentData(await invokeToolCall(name, opts, argsFactory));
|
|
354
|
-
emitCommand(data,
|
|
378
|
+
export async function executeToolCall(name, opts = {}, argsFactory = async () => ({}), augmentData = (data) => data, hooks = {}, human = toolCallHuman) {
|
|
379
|
+
const data = await augmentData(await invokeToolCall(name, opts, argsFactory, hooks));
|
|
380
|
+
emitCommand(data, human(data), opts);
|
|
355
381
|
await maybeShowSkillHint();
|
|
356
382
|
}
|
|
357
383
|
export async function toolCallCommand(name, opts = {}) {
|
|
384
|
+
if (name === 'send_invoice' || name === 'send_proposal') {
|
|
385
|
+
const args = await assembleArgs(opts);
|
|
386
|
+
const binding = recipientBinding(args.recipients, 'argument');
|
|
387
|
+
await executeToolCall(name, opts, async () => args, undefined, {
|
|
388
|
+
beforeConfirmation: async () => {
|
|
389
|
+
process.stderr.write(`${recipientLines({ recipients: binding })}\n`);
|
|
390
|
+
},
|
|
391
|
+
});
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
358
394
|
await executeToolCall(name, opts, () => assembleArgs(opts));
|
|
359
395
|
}
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { authStatusCommand, loginCommand, logoutCommand, orgCommand, orgSwitchCo
|
|
|
7
7
|
import { policyExplainCommand } from './commands/policy.js';
|
|
8
8
|
import { signupCommand, signupCompleteCommand, signupStatusCommand, } from './commands/signup.js';
|
|
9
9
|
import { toolCallCommand, toolsDescribeCommand, toolsListCommand, } from './commands/tools.js';
|
|
10
|
-
import { dealListCommand, dealMoveCommand, invoiceCreateCommand, invoiceListCommand, invoiceSendCommand, personListCommand, } from './commands/aliases.js';
|
|
10
|
+
import { dealListCommand, dealMoveCommand, invoiceCreateCommand, invoiceListCommand, invoiceSendCommand, personListCommand, proposalSendCommand, recipientsGetCommand, recipientsSetCommand, } from './commands/aliases.js';
|
|
11
11
|
import { skillsInstallCommand, skillsListCommand } from './commands/skills.js';
|
|
12
12
|
import { CliError } from './lib/errors.js';
|
|
13
13
|
import { deprecationNote, emit, emitError } from './lib/output.js';
|
|
@@ -168,7 +168,7 @@ withGlobalOptions(toolsCommand
|
|
|
168
168
|
});
|
|
169
169
|
});
|
|
170
170
|
const toolCommand = withGlobalOptions(program.command('tool').description('Invoke a single Every MCP tool'));
|
|
171
|
-
function collectOption(value, previous) {
|
|
171
|
+
function collectOption(value, previous = []) {
|
|
172
172
|
previous.push(value);
|
|
173
173
|
return previous;
|
|
174
174
|
}
|
|
@@ -281,19 +281,49 @@ withGlobalOptions(withToolExecutionOptions(invoiceCommand
|
|
|
281
281
|
});
|
|
282
282
|
withGlobalOptions(withToolExecutionOptions(invoiceCommand
|
|
283
283
|
.command('send')
|
|
284
|
-
.description('
|
|
284
|
+
.description('Preview recipients, confirm, and send an invoice')
|
|
285
|
+
.option('--expect-digest <digest>', 'require the digest from the approved recipient preview')
|
|
285
286
|
.argument('<invoice_id>', 'invoice id'))).action(async (invoiceId, _options, command) => {
|
|
286
287
|
const opts = command.optsWithGlobals();
|
|
287
288
|
await invoiceSendCommand(invoiceId, {
|
|
288
289
|
json: opts.json,
|
|
289
290
|
staging: opts.staging,
|
|
290
|
-
noCache: opts.
|
|
291
|
+
noCache: opts.cache === false,
|
|
291
292
|
yes: opts.yes,
|
|
292
293
|
allowDestructive: opts.allowDestructive,
|
|
293
294
|
readOnly: opts.readOnly,
|
|
294
295
|
timeout: opts.timeout,
|
|
296
|
+
expectDigest: opts.expectDigest,
|
|
295
297
|
});
|
|
296
298
|
});
|
|
299
|
+
const proposalCommand = withToolExecutionOptions(withGlobalOptions(program.command('proposal').description('Work with proposals')));
|
|
300
|
+
withGlobalOptions(withToolExecutionOptions(proposalCommand.command('send').description('Preview recipients, confirm, and send a proposal')
|
|
301
|
+
.option('--expect-digest <digest>', 'require the digest from the approved recipient preview')
|
|
302
|
+
.argument('<proposal>', 'proposal id'))).action(async (proposal, _options, command) => {
|
|
303
|
+
const opts = command.optsWithGlobals();
|
|
304
|
+
await proposalSendCommand(proposal, { ...opts, noCache: opts.cache === false });
|
|
305
|
+
});
|
|
306
|
+
const recipientsCommand = withToolExecutionOptions(withGlobalOptions(program.command('recipients').description('Read or set invoice and proposal recipients')));
|
|
307
|
+
for (const action of ['get', 'set']) {
|
|
308
|
+
const command = withGlobalOptions(withToolExecutionOptions(recipientsCommand.command(action).description(`${action === 'get' ? 'Read' : 'Set'} exact To and CC recipients`)
|
|
309
|
+
.argument('<party>', 'Person or Company name')
|
|
310
|
+
.requiredOption('--kind <kind>', 'invoice or proposal')
|
|
311
|
+
.option('--company <name>', 'Company name to resolve via list_companies')
|
|
312
|
+
.option('--person <name>', 'Person name to resolve via list_people')
|
|
313
|
+
.option('--company-id <id>', 'Company id; skips name resolution')
|
|
314
|
+
.option('--person-id <id>', 'Person id; skips name resolution')));
|
|
315
|
+
if (action === 'set') {
|
|
316
|
+
command.requiredOption('--to <email-or-id>', 'To email address or eligible method id')
|
|
317
|
+
.option('--cc <email-or-id>', 'CC email address or eligible method id; repeat for more recipients', collectOption)
|
|
318
|
+
.option('--clear-cc', 'remove all CC recipients');
|
|
319
|
+
}
|
|
320
|
+
command.action(async (party, _options, cmd) => {
|
|
321
|
+
const opts = cmd.optsWithGlobals();
|
|
322
|
+
// Commander represents --no-cache as cache:false.
|
|
323
|
+
opts.noCache = opts.cache === false;
|
|
324
|
+
await (action === 'get' ? recipientsGetCommand : recipientsSetCommand)(party, opts);
|
|
325
|
+
});
|
|
326
|
+
}
|
|
297
327
|
const dealCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
298
328
|
.command('deal')
|
|
299
329
|
.description('Work with deals')
|
package/dist/lib/policy.js
CHANGED
|
@@ -58,6 +58,13 @@ 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
|
+
if (name === 'set_recipient_defaults') {
|
|
62
|
+
return {
|
|
63
|
+
level: 'destructive',
|
|
64
|
+
source: 'override',
|
|
65
|
+
reason: 'set_recipient_defaults changes the audience for future document sends. Require destructive confirmation regardless of server annotations.',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
61
68
|
// approve_prospect is the owner/bookkeeper review action next to
|
|
62
69
|
// approve_pending_deal (the path open to API keys); pin it the same way.
|
|
63
70
|
if (name === 'approve_prospect') {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CliError } from './errors.js';
|
|
2
|
+
import { ExitCode } from './exit-codes.js';
|
|
3
|
+
export function documentKind(value) {
|
|
4
|
+
if (value !== 'invoice' && value !== 'proposal') {
|
|
5
|
+
throw new CliError('--kind must be invoice or proposal', ExitCode.USAGE, 'usage');
|
|
6
|
+
}
|
|
7
|
+
return value;
|
|
8
|
+
}
|
|
9
|
+
export function record(value) {
|
|
10
|
+
return value && typeof value === 'object' && !Array.isArray(value)
|
|
11
|
+
? value
|
|
12
|
+
: {};
|
|
13
|
+
}
|
|
14
|
+
/** Validate the server object without changing any binding field. */
|
|
15
|
+
export function recipientBinding(value, source = 'preview') {
|
|
16
|
+
const binding = record(value);
|
|
17
|
+
if (Object.keys(binding).sort().join(',') !== 'cc,digest,to' ||
|
|
18
|
+
typeof binding.digest !== 'string' || !/^[a-f0-9]{64}$/.test(binding.digest) ||
|
|
19
|
+
typeof binding.to !== 'string' || binding.to.length === 0 ||
|
|
20
|
+
!Array.isArray(binding.cc) || !binding.cc.every((address) => typeof address === 'string')) {
|
|
21
|
+
if (source === 'argument') {
|
|
22
|
+
throw new CliError('Document sends require a recipients binding with exactly {digest, to, cc} from preview_document_send.', ExitCode.USAGE, 'usage');
|
|
23
|
+
}
|
|
24
|
+
throw new CliError('The server returned an invalid recipient preview. No document was sent.');
|
|
25
|
+
}
|
|
26
|
+
return binding;
|
|
27
|
+
}
|
|
28
|
+
/** Older servers omit model_state but return the complete exclusion list. */
|
|
29
|
+
export function preservedExclusions(defaults) {
|
|
30
|
+
const ids = defaults.none_method_ids;
|
|
31
|
+
const state = defaults.model_state;
|
|
32
|
+
if (!Array.isArray(ids) || !ids.every((id) => typeof id === 'string' &&
|
|
33
|
+
/^[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}$/i.test(id))) {
|
|
34
|
+
throw new CliError('The server cannot confirm current recipient exclusions. No defaults were changed.', ExitCode.PERMISSION, 'recipient_exclusions_unavailable');
|
|
35
|
+
}
|
|
36
|
+
if ((state !== undefined && state !== 'v1' && state !== 'v2') || (state === 'v2' && ids.length > 0)) {
|
|
37
|
+
throw new CliError('This recipient model cannot preserve the existing exclusions. No defaults were changed.', ExitCode.PERMISSION, 'recipient_exclusions_unavailable', { model_state: state });
|
|
38
|
+
}
|
|
39
|
+
return ids;
|
|
40
|
+
}
|
|
41
|
+
/** Use transport addresses as authority. Optional display details supply names only. */
|
|
42
|
+
export function recipientLines(data) {
|
|
43
|
+
const envelope = record(data.recipients ?? data.recipient_preview);
|
|
44
|
+
const details = record(data.recipient_details);
|
|
45
|
+
const detailRows = [details.to, ...(Array.isArray(details.cc) ? details.cc : [])].map(record);
|
|
46
|
+
const methods = (Array.isArray(data.eligible_methods) ? data.eligible_methods : []).map(record);
|
|
47
|
+
const line = (role, address) => {
|
|
48
|
+
const detail = detailRows.find((entry) => entry.address === address);
|
|
49
|
+
const method = methods.find((entry) => entry.delivery_address === address);
|
|
50
|
+
const name = detail?.owner_name ?? record(method?.owner).name;
|
|
51
|
+
return `${role}: ${typeof name === 'string' && name ? name : 'Name unavailable'} <${address}>`;
|
|
52
|
+
};
|
|
53
|
+
const cc = Array.isArray(envelope.cc) ? envelope.cc : [];
|
|
54
|
+
return [
|
|
55
|
+
typeof envelope.to === 'string' ? line('To', envelope.to) : 'To: none',
|
|
56
|
+
...cc.map((address) => line('CC', String(address))),
|
|
57
|
+
...(cc.length === 0 ? ['CC: none'] : []),
|
|
58
|
+
...(envelope.error ? [`Recipient error: ${envelope.error}`] : []),
|
|
59
|
+
].join('\n');
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: use-every
|
|
3
3
|
description: Drive the Every AI CLI (`every`) to manage the user's service business — invoices, People, Companies, proposals, deals, pipeline, payments, services, custom fields, and scheduled tasks. Use when the user asks “who owes me money?”, wants a lead or deal follow-up, asks to sign up for Every, asks to look up, create, update, convert, or send a business record, or mentions their Every workspace.
|
|
4
4
|
metadata:
|
|
5
|
-
every-skill-version: "
|
|
5
|
+
every-skill-version: "4"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Use Every
|
|
@@ -139,19 +139,25 @@ Conversion creates a linked DRAFT invoice. Review the returned invoice ID, then
|
|
|
139
139
|
|
|
140
140
|
```bash
|
|
141
141
|
every tool call view_invoice --arg identifier=<invoice_id> --json
|
|
142
|
-
every invoice send <invoice_id> --
|
|
142
|
+
every invoice send <invoice_id> --expect-digest <preview_digest> --yes --json
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
### Voiding an invoice
|
|
146
146
|
|
|
147
147
|
`void_invoice` (`invoice_id`, `expected_updated_at` from `view_invoice`, a fresh `operation_id`) voids an invoice: its status becomes void and it can no longer be paid, but the invoice and its history remain. It never deletes. It is destructive, so it needs explicit approval and both destructive flags.
|
|
148
148
|
|
|
149
|
+
### Invoice and proposal sends
|
|
150
|
+
|
|
151
|
+
Call `preview_document_send` before approval. Show the exact To and CC first, with one name and exact email per line. Show `CC: none` if empty. Never add a CC without a request.
|
|
152
|
+
|
|
153
|
+
After the owner approves those recipients, send with `--expect-digest <preview_digest>` and `--yes`. Both send aliases compare a fresh preview with that digest. A mismatch stops the send and shows the new recipients. Get approval for the new preview before another send. Direct send tools require the exact approved `{digest, to, cc}` binding and both destructive flags.
|
|
154
|
+
|
|
149
155
|
### Invoice re-sends
|
|
150
156
|
|
|
151
157
|
`send_invoice` re-sends the invoice email itself; it does not send custom reminder copy. For an overdue follow-up, confirm with the user, re-send the invoice, and give any custom message separately for the user to send:
|
|
152
158
|
|
|
153
159
|
```bash
|
|
154
|
-
every invoice send <invoice_id> --
|
|
160
|
+
every invoice send <invoice_id> --expect-digest <preview_digest> --yes --json
|
|
155
161
|
```
|
|
156
162
|
|
|
157
163
|
### Gmail is draft-first
|
|
@@ -235,7 +241,7 @@ Convert an accepted proposal:
|
|
|
235
241
|
every tool call view_proposal --arg identifier=<proposal_id> --json
|
|
236
242
|
every tool call convert_proposal_to_invoice --arg proposal_id=<proposal_id> --yes --json
|
|
237
243
|
every tool call view_invoice --arg identifier=<invoice_id> --json
|
|
238
|
-
every invoice send <invoice_id> --
|
|
244
|
+
every invoice send <invoice_id> --expect-digest <preview_digest> --yes --json
|
|
239
245
|
```
|
|
240
246
|
|
|
241
247
|
Stop if the proposal is not issued/approved. Review the linked draft and obtain approval before sending.
|