@everyai/cli 0.1.0 → 0.2.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 +23 -8
- package/dist/commands/aliases.js +177 -1
- package/dist/commands/auth.js +61 -32
- package/dist/commands/docs.js +91 -0
- package/dist/commands/ping.js +1 -1
- package/dist/commands/policy.js +1 -1
- package/dist/commands/tools.js +52 -5
- package/dist/index.js +87 -7
- package/dist/lib/auth/userinfo.js +126 -0
- package/dist/lib/config.js +29 -7
- package/dist/lib/errors.js +3 -1
- package/dist/lib/first-run.js +52 -0
- package/dist/lib/hints.js +56 -0
- package/dist/lib/output.js +26 -11
- package/dist/lib/policy.js +8 -6
- package/package.json +6 -3
- package/scripts/postinstall.mjs +18 -0
- package/skills/use-every/SKILL.md +11 -1
package/README.md
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
# @everyai/cli
|
|
2
2
|
|
|
3
|
-
The **agent-agnostic** command line for [Every AI](https://every.ai) — manage
|
|
3
|
+
The **agent-agnostic** command line for [Every AI](https://every.ai) — manage invoices, clients, contacts, proposals, deals, and pipeline work from any shell, coding agent, or CI job.
|
|
4
4
|
|
|
5
|
-
Install once, log in once, and the same `every` command
|
|
5
|
+
Install once, log in once, and teach each coding agent the same `every` command instead of wiring MCP + OAuth separately into every host.
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
8
|
npm install -g @everyai/cli
|
|
9
|
-
every
|
|
10
|
-
every
|
|
11
|
-
every
|
|
9
|
+
every docs # offline command tree, output contract, workflows
|
|
10
|
+
every login # opens your browser; tokens land in your OS keychain
|
|
11
|
+
every skills install claude|codex # teach Claude Code or Codex how to use Every
|
|
12
|
+
every whoami # user, org, environment, tool-count check
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
One-shot invoice example with inline args:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
every invoice list --status overdue --json
|
|
19
|
+
every tool call create_invoice \
|
|
20
|
+
--arg client_id=client_123 \
|
|
21
|
+
--arg line_items='[{"description":"Strategy work","quantity":1,"unit_price":1500}]' \
|
|
22
|
+
--yes \
|
|
23
|
+
--json
|
|
12
24
|
```
|
|
13
25
|
|
|
14
26
|
## Why a CLI (vs. adding the MCP server to each host)
|
|
@@ -27,7 +39,8 @@ every login [--staging] # browser OAuth; keychain storage; refresh handle
|
|
|
27
39
|
every logout | whoami | auth status | org
|
|
28
40
|
|
|
29
41
|
# Discovery
|
|
30
|
-
every
|
|
42
|
+
every docs
|
|
43
|
+
every tools list [--filter <substr>] [--no-cache]
|
|
31
44
|
every tools describe <name>
|
|
32
45
|
every policy explain <name> # classification + exactly what running it requires
|
|
33
46
|
|
|
@@ -51,8 +64,8 @@ every skills install codex # → .agents/skills/use-every/
|
|
|
51
64
|
Every command supports `--json`: exactly one JSON document on stdout, nothing else.
|
|
52
65
|
|
|
53
66
|
```jsonc
|
|
54
|
-
{ "ok": true, "data": { /* ... */ }, "schema_version": 1 }
|
|
55
|
-
{ "ok": false, "error": { "message": "...", "code": "..." }, "schema_version": 1 }
|
|
67
|
+
{ "ok": true, "data": { /* ... */ }, "env": "production", "schema_version": 1 }
|
|
68
|
+
{ "ok": false, "error": { "message": "...", "code": "..." }, "env": "production", "schema_version": 1 }
|
|
56
69
|
```
|
|
57
70
|
|
|
58
71
|
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.
|
|
@@ -61,6 +74,8 @@ Exit codes: `0` ok · `1` tool/generic error · `2` usage · `3` auth (run `ever
|
|
|
61
74
|
|
|
62
75
|
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.
|
|
63
76
|
|
|
77
|
+
Target precedence: `--staging` > `EVERY_MCP_URL` > `EVERY_ENV=staging|production` > production.
|
|
78
|
+
|
|
64
79
|
## Status
|
|
65
80
|
|
|
66
81
|
Pre-release. Built against Every's production MCP surface; `--staging` targets Every's internal staging environment.
|
package/dist/commands/aliases.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { CliError } from '../lib/errors.js';
|
|
2
2
|
import { ExitCode } from '../lib/exit-codes.js';
|
|
3
|
-
import { executeToolCall } from './tools.js';
|
|
3
|
+
import { executeToolCall, invokeToolCall, } from './tools.js';
|
|
4
4
|
const INVOICE_STATUSES = new Set(['draft', 'issued', 'void']);
|
|
5
5
|
const PAYMENT_STATUSES = new Set(['unpaid', 'paid', 'overdue', 'partial']);
|
|
6
6
|
const DEAL_STAGES = new Set(['lead', 'opportunity', 'won', 'lost']);
|
|
7
|
+
const LIST_CLIENTS_NAME_PARAM = 'name';
|
|
8
|
+
const CREATE_INVOICE_CLIENT_ID_PARAM = 'client_id';
|
|
9
|
+
const CREATE_INVOICE_LINE_ITEMS_PARAM = 'line_items';
|
|
10
|
+
const LINE_ITEM_DESCRIPTION_PARAM = 'description';
|
|
11
|
+
const LINE_ITEM_QUANTITY_PARAM = 'quantity';
|
|
12
|
+
const LINE_ITEM_UNIT_PRICE_PARAM = 'unit_price';
|
|
7
13
|
function parseLimit(value) {
|
|
8
14
|
if (value === undefined)
|
|
9
15
|
return undefined;
|
|
@@ -39,6 +45,158 @@ function addInvoiceStatus(args, value) {
|
|
|
39
45
|
...Array.from(PAYMENT_STATUSES),
|
|
40
46
|
].join(', ')}`, ExitCode.USAGE, 'usage');
|
|
41
47
|
}
|
|
48
|
+
function parsePositiveNumber(value, flag) {
|
|
49
|
+
if (value === undefined || value.trim() === '') {
|
|
50
|
+
throw new CliError(`${flag} is required`, ExitCode.USAGE, 'usage');
|
|
51
|
+
}
|
|
52
|
+
const parsed = Number(value);
|
|
53
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
54
|
+
throw new CliError(`${flag} must be a positive number`, ExitCode.USAGE, 'usage');
|
|
55
|
+
}
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
function nonEmpty(value) {
|
|
59
|
+
const trimmed = value?.trim();
|
|
60
|
+
return trimmed ? trimmed : undefined;
|
|
61
|
+
}
|
|
62
|
+
function stringField(record, keys) {
|
|
63
|
+
for (const key of keys) {
|
|
64
|
+
const value = record[key];
|
|
65
|
+
if (typeof value === 'string' && value.trim())
|
|
66
|
+
return value.trim();
|
|
67
|
+
}
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
function stripMarkdown(value) {
|
|
71
|
+
return value
|
|
72
|
+
.replace(/\*\*/g, '')
|
|
73
|
+
.replace(/__/g, '')
|
|
74
|
+
.replace(/`/g, '')
|
|
75
|
+
.replace(/\[(.*?)\]\([^)]*\)/g, '$1');
|
|
76
|
+
}
|
|
77
|
+
function cleanClientNameFromLine(value) {
|
|
78
|
+
let name = stripMarkdown(value)
|
|
79
|
+
.replace(/^\s*(?:[-*+]|\d+[.)])\s*/, '')
|
|
80
|
+
.replace(/^client(?:\s+name)?:\s*/i, '')
|
|
81
|
+
// Drop a trailing status parenthetical like "(active)" / "(archived)".
|
|
82
|
+
.replace(/\s*\((?:active|inactive|archived)\)\s*$/i, '')
|
|
83
|
+
.trim();
|
|
84
|
+
if (name.includes('|')) {
|
|
85
|
+
const cells = name.split('|').map((cell) => cell.trim()).filter(Boolean);
|
|
86
|
+
name = cells.find((cell) => !/^id$/i.test(cell) && !/@/.test(cell)) ?? cells[0] ?? '';
|
|
87
|
+
}
|
|
88
|
+
name = name
|
|
89
|
+
.replace(/\s+[–—]\s+.*$/, '')
|
|
90
|
+
.replace(/\s+-\s+.*$/, '')
|
|
91
|
+
.replace(/\s+<[^>]+>\s*$/, '')
|
|
92
|
+
.replace(/\s+\([^)]*@[^)]*\)\s*$/, '')
|
|
93
|
+
.trim();
|
|
94
|
+
return name || undefined;
|
|
95
|
+
}
|
|
96
|
+
function parseClientCandidatesFromText(text) {
|
|
97
|
+
const candidates = [];
|
|
98
|
+
for (const line of text.split(/\r?\n/)) {
|
|
99
|
+
const match = line.match(/\[id:\s*([^\]\s]+)\s*\]/i);
|
|
100
|
+
if (!match?.[1])
|
|
101
|
+
continue;
|
|
102
|
+
const name = cleanClientNameFromLine(line.slice(0, match.index));
|
|
103
|
+
if (!name)
|
|
104
|
+
continue;
|
|
105
|
+
candidates.push({ client_id: match[1], name });
|
|
106
|
+
}
|
|
107
|
+
return candidates;
|
|
108
|
+
}
|
|
109
|
+
function candidateFromObject(value) {
|
|
110
|
+
const clientId = stringField(value, ['client_id', 'clientId', 'id']);
|
|
111
|
+
const name = stringField(value, ['name', 'client_name', 'clientName']);
|
|
112
|
+
if (!clientId || !name)
|
|
113
|
+
return undefined;
|
|
114
|
+
return { client_id: clientId, name };
|
|
115
|
+
}
|
|
116
|
+
function collectStructuredCandidates(value, seen = new Set()) {
|
|
117
|
+
if (!value || typeof value !== 'object')
|
|
118
|
+
return [];
|
|
119
|
+
if (seen.has(value))
|
|
120
|
+
return [];
|
|
121
|
+
seen.add(value);
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
return value.flatMap((entry) => collectStructuredCandidates(entry, seen));
|
|
124
|
+
}
|
|
125
|
+
const record = value;
|
|
126
|
+
const direct = candidateFromObject(record);
|
|
127
|
+
const nested = Object.values(record).flatMap((entry) => collectStructuredCandidates(entry, seen));
|
|
128
|
+
return direct ? [direct, ...nested] : nested;
|
|
129
|
+
}
|
|
130
|
+
function textFromContent(content) {
|
|
131
|
+
if (typeof content === 'string')
|
|
132
|
+
return content;
|
|
133
|
+
if (!Array.isArray(content))
|
|
134
|
+
return '';
|
|
135
|
+
return content
|
|
136
|
+
.map((block) => {
|
|
137
|
+
if (!block || typeof block !== 'object')
|
|
138
|
+
return undefined;
|
|
139
|
+
const candidate = block;
|
|
140
|
+
return candidate.type === 'text' && typeof candidate.text === 'string'
|
|
141
|
+
? candidate.text
|
|
142
|
+
: undefined;
|
|
143
|
+
})
|
|
144
|
+
.filter((text) => text !== undefined)
|
|
145
|
+
.join('\n');
|
|
146
|
+
}
|
|
147
|
+
function textFromStructuredContent(value) {
|
|
148
|
+
if (typeof value === 'string')
|
|
149
|
+
return value;
|
|
150
|
+
if (!value || typeof value !== 'object')
|
|
151
|
+
return '';
|
|
152
|
+
const result = value.result;
|
|
153
|
+
return typeof result === 'string' ? result : '';
|
|
154
|
+
}
|
|
155
|
+
function dedupeCandidates(candidates) {
|
|
156
|
+
const seen = new Set();
|
|
157
|
+
const deduped = [];
|
|
158
|
+
for (const candidate of candidates) {
|
|
159
|
+
const key = `${candidate.client_id}\0${candidate.name}`;
|
|
160
|
+
if (seen.has(key))
|
|
161
|
+
continue;
|
|
162
|
+
seen.add(key);
|
|
163
|
+
deduped.push(candidate);
|
|
164
|
+
}
|
|
165
|
+
return deduped;
|
|
166
|
+
}
|
|
167
|
+
export function parseClientCandidates(result) {
|
|
168
|
+
return dedupeCandidates([
|
|
169
|
+
...collectStructuredCandidates(result.structured_content),
|
|
170
|
+
...parseClientCandidatesFromText(textFromStructuredContent(result.structured_content)),
|
|
171
|
+
...parseClientCandidatesFromText(textFromContent(result.content)),
|
|
172
|
+
]);
|
|
173
|
+
}
|
|
174
|
+
function clientCandidatesMessage(query, candidates) {
|
|
175
|
+
return [
|
|
176
|
+
`Multiple clients matching "${query}".`,
|
|
177
|
+
...candidates.map((candidate) => `${candidate.client_id} ${candidate.name}`),
|
|
178
|
+
'Re-run with --client-id <id>',
|
|
179
|
+
].join('\n');
|
|
180
|
+
}
|
|
181
|
+
async function resolveClient(opts) {
|
|
182
|
+
const clientId = nonEmpty(opts.clientId);
|
|
183
|
+
const clientName = nonEmpty(opts.client);
|
|
184
|
+
if (clientId)
|
|
185
|
+
return { client_id: clientId, name: clientName ?? null };
|
|
186
|
+
if (!clientName) {
|
|
187
|
+
throw new CliError('--client or --client-id is required', ExitCode.USAGE, 'usage');
|
|
188
|
+
}
|
|
189
|
+
const result = await invokeToolCall('list_clients', opts, async () => ({
|
|
190
|
+
[LIST_CLIENTS_NAME_PARAM]: clientName,
|
|
191
|
+
}));
|
|
192
|
+
const candidates = parseClientCandidates(result);
|
|
193
|
+
if (candidates.length === 1)
|
|
194
|
+
return candidates[0];
|
|
195
|
+
if (candidates.length === 0) {
|
|
196
|
+
throw new CliError(`No client matching "${clientName}". Run: every tool call list_clients --json`, ExitCode.NOT_FOUND, 'not_found');
|
|
197
|
+
}
|
|
198
|
+
throw new CliError(clientCandidatesMessage(clientName, candidates), ExitCode.NOT_FOUND, 'not_found', { candidates });
|
|
199
|
+
}
|
|
42
200
|
export async function invoiceListCommand(opts = {}) {
|
|
43
201
|
const args = {};
|
|
44
202
|
addInvoiceStatus(args, opts.status);
|
|
@@ -50,6 +208,24 @@ export async function invoiceListCommand(opts = {}) {
|
|
|
50
208
|
export async function invoiceSendCommand(invoiceId, opts = {}) {
|
|
51
209
|
await executeToolCall('send_invoice', opts, async () => ({ invoice_id: invoiceId }));
|
|
52
210
|
}
|
|
211
|
+
export async function invoiceCreateCommand(opts = {}) {
|
|
212
|
+
const amount = parsePositiveNumber(opts.amount, '--amount');
|
|
213
|
+
const quantity = opts.quantity === undefined
|
|
214
|
+
? 1
|
|
215
|
+
: parsePositiveNumber(opts.quantity, '--quantity');
|
|
216
|
+
const resolvedClient = await resolveClient(opts);
|
|
217
|
+
const args = {
|
|
218
|
+
[CREATE_INVOICE_CLIENT_ID_PARAM]: resolvedClient.client_id,
|
|
219
|
+
[CREATE_INVOICE_LINE_ITEMS_PARAM]: [
|
|
220
|
+
{
|
|
221
|
+
[LINE_ITEM_DESCRIPTION_PARAM]: opts.description ?? 'Services',
|
|
222
|
+
[LINE_ITEM_QUANTITY_PARAM]: quantity,
|
|
223
|
+
[LINE_ITEM_UNIT_PRICE_PARAM]: amount,
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
await executeToolCall('create_invoice', opts, async () => args, (data) => ({ ...data, resolved_client: resolvedClient }));
|
|
228
|
+
}
|
|
53
229
|
export async function dealListCommand(opts = {}) {
|
|
54
230
|
const args = {};
|
|
55
231
|
if (opts.stage !== undefined) {
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { resolveBaseUrl } from '../lib/config.js';
|
|
1
|
+
import { environmentNameForBaseUrl, resolveBaseUrl } from '../lib/config.js';
|
|
2
2
|
import { CliError } from '../lib/errors.js';
|
|
3
3
|
import { ExitCode } from '../lib/exit-codes.js';
|
|
4
4
|
import { mcpCall } from '../lib/mcp.js';
|
|
5
5
|
import { loginFlow } from '../lib/auth/flow.js';
|
|
6
6
|
import { decodeJwtClaims } from '../lib/auth/jwt.js';
|
|
7
7
|
import { createTokenStore, deleteTokenFromAllStores, getAuthStatus, getToken, resolveAuthTarget, } from '../lib/auth/tokens.js';
|
|
8
|
+
import { fetchUserInfo } from '../lib/auth/userinfo.js';
|
|
9
|
+
import { maybeShowSkillHint } from '../lib/hints.js';
|
|
8
10
|
import { emit } from '../lib/output.js';
|
|
9
11
|
const WHOAMI_TIMEOUT_MS = 10_000;
|
|
10
12
|
function emitCommand(data, human, opts) {
|
|
11
13
|
if (opts.json)
|
|
12
|
-
emit(data, { json: true });
|
|
14
|
+
emit(data, { json: true, staging: opts.staging });
|
|
13
15
|
else
|
|
14
16
|
process.stdout.write(`${human}\n`);
|
|
15
17
|
}
|
|
@@ -26,6 +28,24 @@ function loginHuman(data) {
|
|
|
26
28
|
const identity = data.email ?? data.subject;
|
|
27
29
|
return identity ? `Logged in as ${identity}` : 'Logged in';
|
|
28
30
|
}
|
|
31
|
+
function loginNextSteps() {
|
|
32
|
+
return [
|
|
33
|
+
'Next steps:',
|
|
34
|
+
' every whoami',
|
|
35
|
+
' every tools list',
|
|
36
|
+
' every skills install claude|codex',
|
|
37
|
+
].join('\n');
|
|
38
|
+
}
|
|
39
|
+
function emitLogin(data, opts) {
|
|
40
|
+
const human = `${loginHuman(data)}\n${loginNextSteps()}`;
|
|
41
|
+
if (opts.json) {
|
|
42
|
+
emit(data, { json: true, staging: opts.staging });
|
|
43
|
+
process.stderr.write(`${loginNextSteps()}\n`);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
process.stdout.write(`${human}\n`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
29
49
|
function statusHuman(status) {
|
|
30
50
|
return [
|
|
31
51
|
`Logged in: ${status.logged_in ? 'yes' : 'no'}`,
|
|
@@ -38,29 +58,34 @@ function statusHuman(status) {
|
|
|
38
58
|
`Refresh token: ${status.refresh_token ? 'yes' : 'no'}`,
|
|
39
59
|
].join('\n');
|
|
40
60
|
}
|
|
41
|
-
function
|
|
61
|
+
function orgFromUserInfo(userinfo) {
|
|
42
62
|
return {
|
|
43
|
-
org_id:
|
|
44
|
-
org_slug:
|
|
45
|
-
org_name:
|
|
46
|
-
organization_id:
|
|
47
|
-
organization_slug:
|
|
48
|
-
organization_name:
|
|
63
|
+
org_id: userinfo.org_id,
|
|
64
|
+
org_slug: userinfo.org_slug,
|
|
65
|
+
org_name: userinfo.org_name,
|
|
66
|
+
organization_id: userinfo.org_id,
|
|
67
|
+
organization_slug: userinfo.org_slug,
|
|
68
|
+
organization_name: userinfo.org_name,
|
|
49
69
|
};
|
|
50
70
|
}
|
|
51
71
|
function orgHuman(org) {
|
|
52
72
|
const lines = [
|
|
53
|
-
`
|
|
54
|
-
`
|
|
55
|
-
|
|
73
|
+
`Org: ${formatOrg(org.org_name, org.org_id)}`,
|
|
74
|
+
`Slug: ${org.org_slug ?? 'none'}`,
|
|
75
|
+
'Note: the server scopes writes to this org.',
|
|
56
76
|
];
|
|
57
|
-
if (org.organization_id || org.organization_slug || org.organization_name) {
|
|
58
|
-
lines.push(`organization_id: ${org.organization_id ?? 'none'}`);
|
|
59
|
-
lines.push(`organization_slug: ${org.organization_slug ?? 'none'}`);
|
|
60
|
-
lines.push(`organization_name: ${org.organization_name ?? 'none'}`);
|
|
61
|
-
}
|
|
62
77
|
return lines.join('\n');
|
|
63
78
|
}
|
|
79
|
+
function formatUser(userinfo) {
|
|
80
|
+
if (userinfo.name && userinfo.email)
|
|
81
|
+
return `${userinfo.name} (${userinfo.email})`;
|
|
82
|
+
return userinfo.name ?? userinfo.email ?? userinfo.user_id ?? 'unknown';
|
|
83
|
+
}
|
|
84
|
+
function formatOrg(orgName, orgId) {
|
|
85
|
+
if (orgName && orgId)
|
|
86
|
+
return `${orgName} (${orgId})`;
|
|
87
|
+
return orgName ?? orgId ?? 'none';
|
|
88
|
+
}
|
|
64
89
|
async function verifyMcpLiveness(baseUrl, token) {
|
|
65
90
|
const body = await mcpCall(baseUrl, token, 'tools/list', {}, { timeoutMs: WHOAMI_TIMEOUT_MS });
|
|
66
91
|
return {
|
|
@@ -79,7 +104,7 @@ export async function loginCommand(opts = {}) {
|
|
|
79
104
|
storage_backend: null,
|
|
80
105
|
every_token: true,
|
|
81
106
|
};
|
|
82
|
-
|
|
107
|
+
emitLogin(data, opts);
|
|
83
108
|
return;
|
|
84
109
|
}
|
|
85
110
|
if (!process.stdout.isTTY) {
|
|
@@ -104,7 +129,7 @@ export async function loginCommand(opts = {}) {
|
|
|
104
129
|
storage_backend: store.backend,
|
|
105
130
|
every_token: false,
|
|
106
131
|
};
|
|
107
|
-
|
|
132
|
+
emitLogin(data, opts);
|
|
108
133
|
}
|
|
109
134
|
export async function logoutCommand(opts = {}) {
|
|
110
135
|
const { environmentKey } = resolveAuthTarget({ staging: opts.staging });
|
|
@@ -121,30 +146,34 @@ export async function authStatusCommand(opts = {}) {
|
|
|
121
146
|
}
|
|
122
147
|
export async function whoamiCommand(opts = {}) {
|
|
123
148
|
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
149
|
+
const userinfo = await fetchUserInfo({ baseUrl });
|
|
124
150
|
const token = await getToken({ baseUrl });
|
|
125
|
-
const claims = decodeJwtClaims(token);
|
|
126
151
|
const liveness = await verifyMcpLiveness(baseUrl, token);
|
|
152
|
+
const environment = environmentNameForBaseUrl(baseUrl);
|
|
127
153
|
const data = {
|
|
128
154
|
authenticated: liveness.authenticated,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
155
|
+
user_id: userinfo.user_id,
|
|
156
|
+
subject: userinfo.user_id,
|
|
157
|
+
email: userinfo.email,
|
|
158
|
+
name: userinfo.name,
|
|
159
|
+
org_id: userinfo.org_id,
|
|
160
|
+
org_slug: userinfo.org_slug,
|
|
161
|
+
org_name: userinfo.org_name,
|
|
162
|
+
environment,
|
|
163
|
+
base_url: baseUrl,
|
|
136
164
|
tools: liveness.tools,
|
|
137
165
|
};
|
|
138
|
-
const identity = data.email ?? data.subject ?? 'unknown';
|
|
139
166
|
emitCommand(data, [
|
|
140
167
|
`Authenticated: yes`,
|
|
141
|
-
`User: ${
|
|
142
|
-
`Org: ${
|
|
168
|
+
`User: ${formatUser(userinfo)}`,
|
|
169
|
+
`Org: ${formatOrg(userinfo.org_name, userinfo.org_id)}`,
|
|
170
|
+
`Environment: ${environment} (${baseUrl})`,
|
|
143
171
|
`Tools: ${data.tools}`,
|
|
144
172
|
].join('\n'), opts);
|
|
173
|
+
await maybeShowSkillHint();
|
|
145
174
|
}
|
|
146
175
|
export async function orgCommand(opts = {}) {
|
|
147
|
-
const
|
|
148
|
-
const org =
|
|
176
|
+
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
177
|
+
const org = orgFromUserInfo(await fetchUserInfo({ baseUrl }));
|
|
149
178
|
emitCommand(org, orgHuman(org), opts);
|
|
150
179
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import { emit } from '../lib/output.js';
|
|
4
|
+
function optionFlags(command) {
|
|
5
|
+
return command.options
|
|
6
|
+
.filter((option) => !option.hidden)
|
|
7
|
+
.map((option) => option.flags);
|
|
8
|
+
}
|
|
9
|
+
function argumentUsage(command) {
|
|
10
|
+
const registered = command.registeredArguments;
|
|
11
|
+
return (registered ?? []).map((arg) => {
|
|
12
|
+
const name = arg.name?.() ?? 'arg';
|
|
13
|
+
return arg.required ? `<${name}>` : `[${name}]`;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function commandLine(command, parents) {
|
|
17
|
+
const names = [...parents, command.name()].filter(Boolean);
|
|
18
|
+
const parts = [names.join(' '), ...argumentUsage(command), ...optionFlags(command)];
|
|
19
|
+
return parts.join(' ').replace(/\s+/g, ' ').trim();
|
|
20
|
+
}
|
|
21
|
+
function walkCommands(command, parents = []) {
|
|
22
|
+
const line = commandLine(command, parents);
|
|
23
|
+
const children = command.commands.flatMap((child) => walkCommands(child, [...parents, command.name()]));
|
|
24
|
+
return [line, ...children];
|
|
25
|
+
}
|
|
26
|
+
export function commandTree(program) {
|
|
27
|
+
return walkCommands(program).join('\n');
|
|
28
|
+
}
|
|
29
|
+
export function conventionsBlock() {
|
|
30
|
+
return [
|
|
31
|
+
'JSON envelope:',
|
|
32
|
+
' Success: {"ok":true,"data":...,"env":"production|staging|custom","schema_version":1}',
|
|
33
|
+
' Error: {"ok":false,"error":{"message":"...","code":"..."},"env":"production|staging|custom","schema_version":1}',
|
|
34
|
+
'',
|
|
35
|
+
'Exit codes:',
|
|
36
|
+
' 0 ok',
|
|
37
|
+
' 1 tool/generic error',
|
|
38
|
+
' 2 usage',
|
|
39
|
+
' 3 auth',
|
|
40
|
+
' 4 permission/confirmation needed',
|
|
41
|
+
' 5 rate limited',
|
|
42
|
+
' 6 not found',
|
|
43
|
+
' 7 network/timeout',
|
|
44
|
+
'',
|
|
45
|
+
'Safety tiers:',
|
|
46
|
+
' read: runs without confirmation',
|
|
47
|
+
' write: requires y/N interactively or --yes non-interactively',
|
|
48
|
+
' destructive: requires typed confirmation interactively or --yes --allow-destructive non-interactively',
|
|
49
|
+
' ai-mediated: treated as write-capable because it routes to Every AI',
|
|
50
|
+
'',
|
|
51
|
+
'Argument forms:',
|
|
52
|
+
' every tool call <name> --arg k=v --arg count=2',
|
|
53
|
+
' every tool call <name> --args -',
|
|
54
|
+
' every tool call <name> --args file.json',
|
|
55
|
+
'',
|
|
56
|
+
'Environment:',
|
|
57
|
+
' EVERY_TOKEN skips browser login for headless use.',
|
|
58
|
+
' Target precedence: --staging > EVERY_MCP_URL > EVERY_ENV=staging|production > production.',
|
|
59
|
+
].join('\n');
|
|
60
|
+
}
|
|
61
|
+
function bundledSkillPath() {
|
|
62
|
+
return fileURLToPath(new URL('../../skills/use-every/SKILL.md', import.meta.url));
|
|
63
|
+
}
|
|
64
|
+
function canonicalWorkflows(markdown) {
|
|
65
|
+
const match = markdown.match(/## Canonical Workflows\s*([\s\S]*?)(?:\n## |\s*$)/);
|
|
66
|
+
return match?.[1]?.trim() ?? markdown.trim();
|
|
67
|
+
}
|
|
68
|
+
export async function docsCommand(program, opts = {}) {
|
|
69
|
+
const workflows = canonicalWorkflows(await readFile(bundledSkillPath(), 'utf8'));
|
|
70
|
+
const data = {
|
|
71
|
+
commands: commandTree(program),
|
|
72
|
+
conventions: conventionsBlock(),
|
|
73
|
+
workflows,
|
|
74
|
+
};
|
|
75
|
+
if (opts.json) {
|
|
76
|
+
emit(data, { json: true, staging: opts.staging });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
process.stdout.write([
|
|
80
|
+
'# every docs',
|
|
81
|
+
'',
|
|
82
|
+
'## Commands',
|
|
83
|
+
data.commands,
|
|
84
|
+
'',
|
|
85
|
+
'## Conventions',
|
|
86
|
+
data.conventions,
|
|
87
|
+
'',
|
|
88
|
+
'## Workflows',
|
|
89
|
+
data.workflows,
|
|
90
|
+
].join('\n') + '\n');
|
|
91
|
+
}
|
package/dist/commands/ping.js
CHANGED
package/dist/commands/policy.js
CHANGED
|
@@ -4,7 +4,7 @@ import { emit } from '../lib/output.js';
|
|
|
4
4
|
import { classify, requirementDescription } from '../lib/policy.js';
|
|
5
5
|
function emitCommand(data, human, opts) {
|
|
6
6
|
if (opts.json)
|
|
7
|
-
emit(data, { json: true });
|
|
7
|
+
emit(data, { json: true, staging: opts.staging });
|
|
8
8
|
else
|
|
9
9
|
process.stdout.write(`${human}\n`);
|
|
10
10
|
}
|
package/dist/commands/tools.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { resolveBaseUrl } from '../lib/config.js';
|
|
2
|
+
import { environmentNameForBaseUrl, resolveBaseUrl } from '../lib/config.js';
|
|
3
3
|
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
7
|
import { classify, promptForTool, requirementDescription, requirementFor, } from '../lib/policy.js';
|
|
8
8
|
import { getToken } from '../lib/auth/tokens.js';
|
|
9
|
+
import { fetchUserInfo } from '../lib/auth/userinfo.js';
|
|
10
|
+
import { maybeShowSkillHint } from '../lib/hints.js';
|
|
9
11
|
function emitCommand(data, human, opts) {
|
|
10
12
|
if (opts.json)
|
|
11
|
-
emit(data, { json: true });
|
|
13
|
+
emit(data, { json: true, staging: opts.staging });
|
|
12
14
|
else
|
|
13
15
|
process.stdout.write(`${human}\n`);
|
|
14
16
|
}
|
|
@@ -68,6 +70,7 @@ function describeHuman(tool) {
|
|
|
68
70
|
if (tool.description)
|
|
69
71
|
lines.push('', 'Description:', String(tool.description).trim());
|
|
70
72
|
lines.push('', 'Input schema:', JSON.stringify(tool.inputSchema ?? {}, null, 2));
|
|
73
|
+
lines.push('', 'Fastest argument forms:', ` every tool call ${tool.name} --arg key=value --arg other='{"json":true}'`, ` every tool call ${tool.name} --args -`, ` every tool call ${tool.name} --args file.json`);
|
|
71
74
|
return lines.join('\n');
|
|
72
75
|
}
|
|
73
76
|
async function resolveTools(opts) {
|
|
@@ -76,8 +79,17 @@ async function resolveTools(opts) {
|
|
|
76
79
|
return listTools(baseUrl, token, { noCache: opts.noCache });
|
|
77
80
|
}
|
|
78
81
|
export async function toolsListCommand(opts = {}) {
|
|
79
|
-
const
|
|
82
|
+
const filter = opts.filter?.toLowerCase();
|
|
83
|
+
const tools = (await resolveTools(opts))
|
|
84
|
+
.filter((tool) => {
|
|
85
|
+
if (!filter)
|
|
86
|
+
return true;
|
|
87
|
+
return (tool.name.toLowerCase().includes(filter) ||
|
|
88
|
+
compactText(tool.description).toLowerCase().includes(filter));
|
|
89
|
+
})
|
|
90
|
+
.map(withClassification);
|
|
80
91
|
emitCommand(tools, toolsListHuman(tools), opts);
|
|
92
|
+
await maybeShowSkillHint();
|
|
81
93
|
}
|
|
82
94
|
export async function toolsDescribeCommand(name, opts = {}) {
|
|
83
95
|
const tool = withClassification(findTool(await resolveTools(opts), name));
|
|
@@ -88,6 +100,7 @@ export async function toolsDescribeCommand(name, opts = {}) {
|
|
|
88
100
|
requirements,
|
|
89
101
|
input_schema: tool.inputSchema ?? {},
|
|
90
102
|
}, describeHuman(tool), opts);
|
|
103
|
+
await maybeShowSkillHint();
|
|
91
104
|
}
|
|
92
105
|
async function readStdin() {
|
|
93
106
|
process.stdin.setEncoding('utf8');
|
|
@@ -178,7 +191,28 @@ function toolCallHuman(result) {
|
|
|
178
191
|
}
|
|
179
192
|
return parts.join('\n');
|
|
180
193
|
}
|
|
181
|
-
|
|
194
|
+
function orgLabel(userinfo) {
|
|
195
|
+
return {
|
|
196
|
+
org_id: userinfo?.org_id ?? null,
|
|
197
|
+
org_name: userinfo?.org_name ?? null,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function targetLabel(userinfo, environment) {
|
|
201
|
+
const orgName = userinfo?.org_name ?? 'unknown org';
|
|
202
|
+
const orgId = userinfo?.org_id ?? 'unknown';
|
|
203
|
+
return `${orgName} (${orgId}) · ${environment}`;
|
|
204
|
+
}
|
|
205
|
+
async function resolveWriteTarget(baseUrl) {
|
|
206
|
+
try {
|
|
207
|
+
return await fetchUserInfo({ baseUrl });
|
|
208
|
+
}
|
|
209
|
+
catch (err) {
|
|
210
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
211
|
+
process.stderr.write(`Warning: could not verify target org: ${message}\n`);
|
|
212
|
+
return undefined;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
export async function invokeToolCall(name, opts = {}, argsFactory = async () => ({})) {
|
|
182
216
|
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
183
217
|
const token = await getToken({ baseUrl });
|
|
184
218
|
const tools = await listTools(baseUrl, token, { noCache: opts.noCache });
|
|
@@ -195,12 +229,19 @@ export async function executeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
195
229
|
if (!requirement.allowed) {
|
|
196
230
|
throw new CliError(requirement.denialMessage ?? 'Tool call denied by policy.', ExitCode.PERMISSION, 'permission');
|
|
197
231
|
}
|
|
232
|
+
const gated = classification.level !== 'read';
|
|
233
|
+
const environment = environmentNameForBaseUrl(baseUrl);
|
|
234
|
+
const userinfo = gated ? await resolveWriteTarget(baseUrl) : undefined;
|
|
235
|
+
const target = gated ? targetLabel(userinfo, environment) : undefined;
|
|
198
236
|
if (requirement.prompt) {
|
|
199
|
-
const confirmed = await promptForTool(name, classification.level, requirement.prompt);
|
|
237
|
+
const confirmed = await promptForTool(name, classification.level, requirement.prompt, target);
|
|
200
238
|
if (!confirmed) {
|
|
201
239
|
throw new CliError('Tool call cancelled.', ExitCode.PERMISSION, 'permission');
|
|
202
240
|
}
|
|
203
241
|
}
|
|
242
|
+
if (gated && !opts.json && target) {
|
|
243
|
+
process.stderr.write(`→ ${target}\n`);
|
|
244
|
+
}
|
|
204
245
|
const args = await argsFactory();
|
|
205
246
|
const result = await callTool(baseUrl, token, name, args, { timeoutMs: timeoutMs(opts.timeout) });
|
|
206
247
|
const data = {
|
|
@@ -208,12 +249,18 @@ export async function executeToolCall(name, opts = {}, argsFactory = async () =>
|
|
|
208
249
|
is_error: result.isError,
|
|
209
250
|
content: result.content,
|
|
210
251
|
structured_content: result.structuredContent,
|
|
252
|
+
...(gated ? { org: orgLabel(userinfo) } : {}),
|
|
211
253
|
};
|
|
212
254
|
if (result.isError) {
|
|
213
255
|
const message = contentAsText(result.content) || 'Tool returned an error.';
|
|
214
256
|
throw new CliError(message, ExitCode.GENERIC, 'generic');
|
|
215
257
|
}
|
|
258
|
+
return data;
|
|
259
|
+
}
|
|
260
|
+
export async function executeToolCall(name, opts = {}, argsFactory = async () => ({}), augmentData = (data) => data) {
|
|
261
|
+
const data = await augmentData(await invokeToolCall(name, opts, argsFactory));
|
|
216
262
|
emitCommand(data, toolCallHuman(data), opts);
|
|
263
|
+
await maybeShowSkillHint();
|
|
217
264
|
}
|
|
218
265
|
export async function toolCallCommand(name, opts = {}) {
|
|
219
266
|
await executeToolCall(name, opts, () => assembleArgs(opts));
|