@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/dist/index.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { Command, CommanderError } from 'commander';
|
|
4
4
|
import { pingCommand } from './commands/ping.js';
|
|
5
|
+
import { docsCommand } from './commands/docs.js';
|
|
5
6
|
import { authStatusCommand, loginCommand, logoutCommand, orgCommand, whoamiCommand, } from './commands/auth.js';
|
|
6
7
|
import { policyExplainCommand } from './commands/policy.js';
|
|
7
8
|
import { toolCallCommand, toolsDescribeCommand, toolsListCommand, } from './commands/tools.js';
|
|
8
|
-
import { contactListCommand, dealListCommand, dealMoveCommand, invoiceListCommand, invoiceSendCommand, } from './commands/aliases.js';
|
|
9
|
+
import { contactListCommand, dealListCommand, dealMoveCommand, invoiceCreateCommand, invoiceListCommand, invoiceSendCommand, } from './commands/aliases.js';
|
|
9
10
|
import { skillsInstallCommand, skillsListCommand } from './commands/skills.js';
|
|
10
11
|
import { CliError } from './lib/errors.js';
|
|
11
12
|
import { emit, emitError } from './lib/output.js';
|
|
12
13
|
import { ExitCode } from './lib/exit-codes.js';
|
|
14
|
+
import { runDefaultFirstRunMenu } from './lib/first-run.js';
|
|
13
15
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
14
16
|
/** Attach the global options every command accepts (before OR after the name). */
|
|
15
17
|
function withGlobalOptions(cmd) {
|
|
@@ -28,6 +30,12 @@ program.configureOutput({
|
|
|
28
30
|
else
|
|
29
31
|
process.stdout.write(str);
|
|
30
32
|
},
|
|
33
|
+
writeErr(str) {
|
|
34
|
+
if (jsonMode)
|
|
35
|
+
commanderStdout += str;
|
|
36
|
+
else
|
|
37
|
+
process.stderr.write(str);
|
|
38
|
+
},
|
|
31
39
|
outputError(str, write) {
|
|
32
40
|
if (!jsonMode)
|
|
33
41
|
write(str);
|
|
@@ -43,6 +51,12 @@ withGlobalOptions(program
|
|
|
43
51
|
const opts = command.optsWithGlobals();
|
|
44
52
|
await pingCommand({ json: opts.json, staging: opts.staging });
|
|
45
53
|
});
|
|
54
|
+
withGlobalOptions(program
|
|
55
|
+
.command('docs')
|
|
56
|
+
.description('Print complete offline CLI docs for humans and agents')).action(async (_options, command) => {
|
|
57
|
+
const opts = command.optsWithGlobals();
|
|
58
|
+
await docsCommand(program, { json: opts.json, staging: opts.staging });
|
|
59
|
+
});
|
|
46
60
|
withGlobalOptions(program
|
|
47
61
|
.command('login')
|
|
48
62
|
.description('Log in with browser-based OAuth and store tokens locally')).action(async (_options, command) => {
|
|
@@ -76,12 +90,14 @@ const toolsCommand = withGlobalOptions(program.command('tools').description('Ins
|
|
|
76
90
|
withGlobalOptions(toolsCommand
|
|
77
91
|
.command('list')
|
|
78
92
|
.description('List available MCP tools')
|
|
79
|
-
.option('--no-cache', 'bypass and rewrite the local tool registry cache')
|
|
93
|
+
.option('--no-cache', 'bypass and rewrite the local tool registry cache')
|
|
94
|
+
.option('--filter <substr>', 'case-insensitive substring filter for name or description')).action(async (_options, command) => {
|
|
80
95
|
const opts = command.optsWithGlobals();
|
|
81
96
|
await toolsListCommand({
|
|
82
97
|
json: opts.json,
|
|
83
98
|
staging: opts.staging,
|
|
84
99
|
noCache: opts.noCache,
|
|
100
|
+
filter: opts.filter,
|
|
85
101
|
});
|
|
86
102
|
});
|
|
87
103
|
withGlobalOptions(toolsCommand
|
|
@@ -109,6 +125,14 @@ function withToolExecutionOptions(cmd) {
|
|
|
109
125
|
.option('--read-only', 'deny write, destructive, and AI-mediated tool calls')
|
|
110
126
|
.option('--timeout <secs>', 'tool call timeout in seconds');
|
|
111
127
|
}
|
|
128
|
+
const TOOL_CALL_HELP = [
|
|
129
|
+
'',
|
|
130
|
+
'Fastest full-tool argument forms:',
|
|
131
|
+
' every tool call <name> --arg key=value --arg count=2',
|
|
132
|
+
' every tool call <name> --args -',
|
|
133
|
+
' every tool call <name> --args file.json',
|
|
134
|
+
'',
|
|
135
|
+
].join('\n');
|
|
112
136
|
withGlobalOptions(withToolExecutionOptions(toolCommand
|
|
113
137
|
.command('call')
|
|
114
138
|
.description('Call an MCP tool with JSON arguments')
|
|
@@ -131,7 +155,41 @@ withGlobalOptions(withToolExecutionOptions(toolCommand
|
|
|
131
155
|
const invoiceCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
132
156
|
.command('invoice')
|
|
133
157
|
.description('Work with invoices')
|
|
134
|
-
.addHelpText('after',
|
|
158
|
+
.addHelpText('after', [
|
|
159
|
+
'',
|
|
160
|
+
'Create a simple invoice:',
|
|
161
|
+
' every invoice create --client "Acme" --amount 100 --yes --json',
|
|
162
|
+
'',
|
|
163
|
+
'For rich invoices, use the full tool:',
|
|
164
|
+
' every tool call create_invoice --arg client_id=<id> --arg line_items=\'[{"description":"Work","quantity":1,"unit_price":100}]\'',
|
|
165
|
+
' every tool call create_invoice --args -',
|
|
166
|
+
' every tool call create_invoice --args file.json',
|
|
167
|
+
'',
|
|
168
|
+
].join('\n'))));
|
|
169
|
+
withGlobalOptions(withToolExecutionOptions(invoiceCommand
|
|
170
|
+
.command('create')
|
|
171
|
+
.description('Create a simple draft invoice')
|
|
172
|
+
.option('--client <name>', 'client name to resolve with list_clients')
|
|
173
|
+
.option('--client-id <id>', 'client id; skips client-name resolution')
|
|
174
|
+
.requiredOption('--amount <n>', 'unit price for the single line item')
|
|
175
|
+
.option('--description <text>', 'line item description')
|
|
176
|
+
.option('--quantity <q>', 'line item quantity'))).action(async (_options, command) => {
|
|
177
|
+
const opts = command.optsWithGlobals();
|
|
178
|
+
await invoiceCreateCommand({
|
|
179
|
+
json: opts.json,
|
|
180
|
+
staging: opts.staging,
|
|
181
|
+
noCache: opts.noCache,
|
|
182
|
+
yes: opts.yes,
|
|
183
|
+
allowDestructive: opts.allowDestructive,
|
|
184
|
+
readOnly: opts.readOnly,
|
|
185
|
+
timeout: opts.timeout,
|
|
186
|
+
client: opts.client,
|
|
187
|
+
clientId: opts.clientId,
|
|
188
|
+
amount: opts.amount,
|
|
189
|
+
description: opts.description,
|
|
190
|
+
quantity: opts.quantity,
|
|
191
|
+
});
|
|
192
|
+
});
|
|
135
193
|
withGlobalOptions(withToolExecutionOptions(invoiceCommand
|
|
136
194
|
.command('list')
|
|
137
195
|
.description('List invoices')
|
|
@@ -167,7 +225,10 @@ withGlobalOptions(withToolExecutionOptions(invoiceCommand
|
|
|
167
225
|
timeout: opts.timeout,
|
|
168
226
|
});
|
|
169
227
|
});
|
|
170
|
-
const dealCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
228
|
+
const dealCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
229
|
+
.command('deal')
|
|
230
|
+
.description('Work with deals')
|
|
231
|
+
.addHelpText('after', TOOL_CALL_HELP)));
|
|
171
232
|
withGlobalOptions(withToolExecutionOptions(dealCommand
|
|
172
233
|
.command('list')
|
|
173
234
|
.description('List deals')
|
|
@@ -204,7 +265,10 @@ withGlobalOptions(withToolExecutionOptions(dealCommand
|
|
|
204
265
|
timeout: opts.timeout,
|
|
205
266
|
});
|
|
206
267
|
});
|
|
207
|
-
const contactCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
268
|
+
const contactCommand = withToolExecutionOptions(withGlobalOptions(program
|
|
269
|
+
.command('contact')
|
|
270
|
+
.description('Work with contacts')
|
|
271
|
+
.addHelpText('after', TOOL_CALL_HELP)));
|
|
208
272
|
withGlobalOptions(withToolExecutionOptions(contactCommand
|
|
209
273
|
.command('list')
|
|
210
274
|
.description('List contacts')
|
|
@@ -270,7 +334,21 @@ function emitCommanderSuccess(err) {
|
|
|
270
334
|
emit({ version: pkg.version }, { json: true });
|
|
271
335
|
return;
|
|
272
336
|
}
|
|
273
|
-
emit({ help: commanderStdout.trimEnd() }, { json: true });
|
|
337
|
+
emit({ help: commanderStdout.trimEnd() || program.helpInformation().trimEnd() }, { json: true });
|
|
338
|
+
}
|
|
339
|
+
function isBareInvocation() {
|
|
340
|
+
return process.argv.slice(2).length === 0;
|
|
341
|
+
}
|
|
342
|
+
async function maybeRunFirstRunMenu() {
|
|
343
|
+
if (!isBareInvocation() || jsonMode || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
await runDefaultFirstRunMenu({
|
|
347
|
+
staging: program.opts().staging,
|
|
348
|
+
showHelp: () => program.outputHelp(),
|
|
349
|
+
login: () => loginCommand({ staging: program.opts().staging }),
|
|
350
|
+
});
|
|
351
|
+
return true;
|
|
274
352
|
}
|
|
275
353
|
async function main() {
|
|
276
354
|
jsonMode = process.argv.includes('--json');
|
|
@@ -278,6 +356,8 @@ async function main() {
|
|
|
278
356
|
try {
|
|
279
357
|
await program.parseAsync(process.argv);
|
|
280
358
|
if (program.args.length === 0) {
|
|
359
|
+
if (await maybeRunFirstRunMenu())
|
|
360
|
+
return;
|
|
281
361
|
if (jsonMode) {
|
|
282
362
|
emit({ help: program.helpInformation().trimEnd() }, { json: true });
|
|
283
363
|
}
|
|
@@ -298,7 +378,7 @@ async function main() {
|
|
|
298
378
|
process.exit(ExitCode.USAGE);
|
|
299
379
|
}
|
|
300
380
|
if (err instanceof CliError) {
|
|
301
|
-
emitError(err.message, err.code, { json: jsonMode });
|
|
381
|
+
emitError(err.message, err.code, { json: jsonMode }, err.details);
|
|
302
382
|
process.exit(err.exitCode);
|
|
303
383
|
}
|
|
304
384
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, stat, writeFile, chmod } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getConfigDir } from '../config.js';
|
|
4
|
+
import { CliError } from '../errors.js';
|
|
5
|
+
import { ExitCode } from '../exit-codes.js';
|
|
6
|
+
import { discoverOAuth, fetchJsonWithTimeout, HttpStatusError } from './discovery.js';
|
|
7
|
+
import { environmentKeyForBaseUrl, getToken, resolveAuthTarget, } from './tokens.js';
|
|
8
|
+
const USERINFO_TIMEOUT_MS = 10_000;
|
|
9
|
+
const USERINFO_CACHE_TTL_MS = 10 * 60 * 1000;
|
|
10
|
+
function trimTrailingSlash(value) {
|
|
11
|
+
return value.replace(/\/+$/, '');
|
|
12
|
+
}
|
|
13
|
+
function safeEnvironmentKey(baseUrl) {
|
|
14
|
+
return environmentKeyForBaseUrl(baseUrl).replace(/[^a-zA-Z0-9._-]/g, '_');
|
|
15
|
+
}
|
|
16
|
+
export function userInfoCacheFilePath(baseUrl) {
|
|
17
|
+
return path.join(getConfigDir(), 'cache', `userinfo-${safeEnvironmentKey(baseUrl)}.json`);
|
|
18
|
+
}
|
|
19
|
+
function fetchedAtMs(value) {
|
|
20
|
+
if (typeof value === 'number')
|
|
21
|
+
return value;
|
|
22
|
+
const parsed = Date.parse(value);
|
|
23
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
24
|
+
}
|
|
25
|
+
function stringOrNull(value) {
|
|
26
|
+
return typeof value === 'string' && value.length > 0 ? value : null;
|
|
27
|
+
}
|
|
28
|
+
function normalizeUserInfo(value) {
|
|
29
|
+
return {
|
|
30
|
+
user_id: stringOrNull(value.user_id) ?? stringOrNull(value.sub),
|
|
31
|
+
email: stringOrNull(value.email),
|
|
32
|
+
name: stringOrNull(value.name),
|
|
33
|
+
org_id: stringOrNull(value.org_id),
|
|
34
|
+
org_slug: stringOrNull(value.org_slug),
|
|
35
|
+
org_name: stringOrNull(value.org_name),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function isUserInfo(value) {
|
|
39
|
+
if (!value || typeof value !== 'object')
|
|
40
|
+
return false;
|
|
41
|
+
const candidate = value;
|
|
42
|
+
return ('user_id' in candidate &&
|
|
43
|
+
'email' in candidate &&
|
|
44
|
+
'name' in candidate &&
|
|
45
|
+
'org_id' in candidate &&
|
|
46
|
+
'org_slug' in candidate &&
|
|
47
|
+
'org_name' in candidate);
|
|
48
|
+
}
|
|
49
|
+
export async function readCachedUserInfo(baseUrl, { allowStale = false, now = Date.now, } = {}) {
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = JSON.parse(await readFile(userInfoCacheFilePath(baseUrl), 'utf8'));
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
if (!isUserInfo(parsed.userinfo))
|
|
61
|
+
return undefined;
|
|
62
|
+
if (!allowStale && now() - fetchedAtMs(parsed.fetched_at) > USERINFO_CACHE_TTL_MS) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
return parsed.userinfo;
|
|
66
|
+
}
|
|
67
|
+
async function writeUserInfoCache(baseUrl, userinfo) {
|
|
68
|
+
const filePath = userInfoCacheFilePath(baseUrl);
|
|
69
|
+
await mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
70
|
+
const tempPath = `${filePath}.${process.pid}.tmp`;
|
|
71
|
+
await writeFile(tempPath, JSON.stringify({ fetched_at: new Date().toISOString(), userinfo }, null, 2), { mode: 0o600 });
|
|
72
|
+
await chmod(tempPath, 0o600);
|
|
73
|
+
await rename(tempPath, filePath);
|
|
74
|
+
await chmod(filePath, 0o600);
|
|
75
|
+
}
|
|
76
|
+
export async function userInfoCacheFileMode(baseUrl) {
|
|
77
|
+
try {
|
|
78
|
+
return (await stat(userInfoCacheFilePath(baseUrl))).mode & 0o777;
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function fetchOpenIdConfiguration(issuer) {
|
|
88
|
+
const url = `${trimTrailingSlash(issuer)}/.well-known/openid-configuration`;
|
|
89
|
+
const metadata = await fetchJsonWithTimeout(url, { headers: { accept: 'application/json' } }, USERINFO_TIMEOUT_MS);
|
|
90
|
+
if (typeof metadata.userinfo_endpoint !== 'string' || metadata.userinfo_endpoint.length === 0) {
|
|
91
|
+
throw new CliError(`OpenID configuration at ${url} did not include userinfo_endpoint`, ExitCode.NETWORK, 'network');
|
|
92
|
+
}
|
|
93
|
+
return metadata;
|
|
94
|
+
}
|
|
95
|
+
export async function fetchUserInfo(opts = {}) {
|
|
96
|
+
const { baseUrl } = resolveAuthTarget(opts);
|
|
97
|
+
const token = await getToken({ baseUrl, store: opts.store, now: opts.now });
|
|
98
|
+
if (!opts.forceRefresh) {
|
|
99
|
+
const cached = await readCachedUserInfo(baseUrl, { now: opts.now }).catch(() => undefined);
|
|
100
|
+
if (cached)
|
|
101
|
+
return cached;
|
|
102
|
+
}
|
|
103
|
+
const discovery = await discoverOAuth(baseUrl);
|
|
104
|
+
const openid = await fetchOpenIdConfiguration(discovery.authServer.issuer);
|
|
105
|
+
let raw;
|
|
106
|
+
try {
|
|
107
|
+
raw = await fetchJsonWithTimeout(openid.userinfo_endpoint, {
|
|
108
|
+
headers: {
|
|
109
|
+
accept: 'application/json',
|
|
110
|
+
authorization: `Bearer ${token}`,
|
|
111
|
+
},
|
|
112
|
+
}, USERINFO_TIMEOUT_MS);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (err instanceof HttpStatusError && err.status === 401) {
|
|
116
|
+
throw new CliError('Not logged in. Run \'every login\'.', ExitCode.AUTH, 'auth');
|
|
117
|
+
}
|
|
118
|
+
if (err instanceof HttpStatusError) {
|
|
119
|
+
throw new CliError(`User info request failed for ${err.url}: HTTP ${err.status}`, ExitCode.NETWORK, 'network');
|
|
120
|
+
}
|
|
121
|
+
throw err;
|
|
122
|
+
}
|
|
123
|
+
const userinfo = normalizeUserInfo(raw);
|
|
124
|
+
await writeUserInfoCache(baseUrl, userinfo);
|
|
125
|
+
return userinfo;
|
|
126
|
+
}
|
package/dist/lib/config.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* later phase). Kept under the XDG-style `~/.config/everyai`.
|
|
4
|
+
* Default on-disk config location for the `every` CLI.
|
|
6
5
|
*/
|
|
7
6
|
export const CONFIG_DIR = path.join(os.homedir(), '.config', 'everyai');
|
|
8
7
|
/** Resolve the config directory dynamically so tests can isolate state. */
|
|
9
8
|
export function getConfigDir() {
|
|
10
|
-
|
|
9
|
+
if (process.env.EVERY_CONFIG_DIR)
|
|
10
|
+
return process.env.EVERY_CONFIG_DIR;
|
|
11
|
+
if (process.env.XDG_CONFIG_HOME)
|
|
12
|
+
return path.join(process.env.XDG_CONFIG_HOME, 'everyai');
|
|
13
|
+
return CONFIG_DIR;
|
|
11
14
|
}
|
|
12
15
|
/** Deployed MCP base URLs. */
|
|
13
16
|
export const PROD_BASE_URL = 'https://admin-mcp.every.ai';
|
|
@@ -16,13 +19,32 @@ export const STAGING_BASE_URL = 'https://admin-mcp-staging.up.railway.app';
|
|
|
16
19
|
* Resolve the MCP base URL to target.
|
|
17
20
|
*
|
|
18
21
|
* Precedence:
|
|
19
|
-
* 1. `
|
|
20
|
-
* 2. `
|
|
21
|
-
* 3.
|
|
22
|
+
* 1. `{ staging: true }` -> staging deployment
|
|
23
|
+
* 2. `EVERY_MCP_URL` env override
|
|
24
|
+
* 3. `EVERY_ENV=staging|production`
|
|
25
|
+
* 4. default -> production deployment
|
|
22
26
|
*/
|
|
23
27
|
export function resolveBaseUrl({ staging } = {}) {
|
|
28
|
+
if (staging)
|
|
29
|
+
return STAGING_BASE_URL;
|
|
24
30
|
const override = process.env.EVERY_MCP_URL;
|
|
25
31
|
if (override)
|
|
26
32
|
return override;
|
|
27
|
-
|
|
33
|
+
const env = process.env.EVERY_ENV?.toLowerCase();
|
|
34
|
+
if (env === 'staging')
|
|
35
|
+
return STAGING_BASE_URL;
|
|
36
|
+
if (env === 'production')
|
|
37
|
+
return PROD_BASE_URL;
|
|
38
|
+
return PROD_BASE_URL;
|
|
39
|
+
}
|
|
40
|
+
function trimTrailingSlash(value) {
|
|
41
|
+
return value.replace(/\/+$/, '');
|
|
42
|
+
}
|
|
43
|
+
export function environmentNameForBaseUrl(baseUrl) {
|
|
44
|
+
const normalized = trimTrailingSlash(baseUrl);
|
|
45
|
+
if (normalized === trimTrailingSlash(PROD_BASE_URL))
|
|
46
|
+
return 'production';
|
|
47
|
+
if (normalized === trimTrailingSlash(STAGING_BASE_URL))
|
|
48
|
+
return 'staging';
|
|
49
|
+
return 'custom';
|
|
28
50
|
}
|
package/dist/lib/errors.js
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
export class CliError extends Error {
|
|
8
8
|
exitCode;
|
|
9
9
|
code;
|
|
10
|
-
|
|
10
|
+
details;
|
|
11
|
+
constructor(message, exitCode = 1, code = 'generic', details) {
|
|
11
12
|
super(message);
|
|
12
13
|
this.exitCode = exitCode;
|
|
13
14
|
this.code = code;
|
|
15
|
+
this.details = details;
|
|
14
16
|
this.name = 'CliError';
|
|
15
17
|
}
|
|
16
18
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
import { resolveBaseUrl } from './config.js';
|
|
3
|
+
import { getAuthStatus } from './auth/tokens.js';
|
|
4
|
+
import { readCachedUserInfo } from './auth/userinfo.js';
|
|
5
|
+
function write(output, text) {
|
|
6
|
+
output.write(text);
|
|
7
|
+
}
|
|
8
|
+
export async function runFirstRunMenu(opts) {
|
|
9
|
+
const status = await opts.getStatus();
|
|
10
|
+
if (status.logged_in) {
|
|
11
|
+
const identity = await opts.getCachedIdentity();
|
|
12
|
+
if (identity) {
|
|
13
|
+
const email = identity.email ?? 'unknown';
|
|
14
|
+
const org = identity.org_name ?? 'unknown';
|
|
15
|
+
write(opts.output, `Logged in as ${email} · org ${org} · try: every tools list\n\n`);
|
|
16
|
+
}
|
|
17
|
+
opts.showHelp();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
write(opts.output, [
|
|
21
|
+
"Welcome to Every AI — you're not logged in.",
|
|
22
|
+
'',
|
|
23
|
+
'1) Log in or create an account (opens your browser)',
|
|
24
|
+
'2) Show all commands',
|
|
25
|
+
'3) Exit',
|
|
26
|
+
'',
|
|
27
|
+
].join('\n'));
|
|
28
|
+
const rl = createInterface({ input: opts.input, output: opts.output });
|
|
29
|
+
try {
|
|
30
|
+
const answer = (await rl.question('Choose [1]: ')).trim();
|
|
31
|
+
if (answer === '' || answer === '1') {
|
|
32
|
+
await opts.login();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (answer === '2')
|
|
36
|
+
opts.showHelp();
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
rl.close();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function runDefaultFirstRunMenu(params) {
|
|
43
|
+
const baseUrl = resolveBaseUrl({ staging: params.staging });
|
|
44
|
+
await runFirstRunMenu({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout,
|
|
47
|
+
showHelp: params.showHelp,
|
|
48
|
+
login: params.login,
|
|
49
|
+
getStatus: () => getAuthStatus({ baseUrl }),
|
|
50
|
+
getCachedIdentity: () => readCachedUserInfo(baseUrl, { allowStale: true }),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { access, mkdir, readFile, rename, writeFile, chmod } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getConfigDir } from './config.js';
|
|
4
|
+
const SKILL_HINT = 'Tip: teach your coding agent this CLI — run: every skills install claude|codex (shown once)';
|
|
5
|
+
function hintsPath() {
|
|
6
|
+
return path.join(getConfigDir(), 'hints.json');
|
|
7
|
+
}
|
|
8
|
+
async function pathExists(filePath) {
|
|
9
|
+
try {
|
|
10
|
+
await access(filePath);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function readHints() {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(await readFile(hintsPath(), 'utf8'));
|
|
20
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
21
|
+
}
|
|
22
|
+
catch (err) {
|
|
23
|
+
if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function writeHints(value) {
|
|
30
|
+
const filePath = hintsPath();
|
|
31
|
+
await mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
|
|
32
|
+
const tempPath = `${filePath}.${process.pid}.tmp`;
|
|
33
|
+
await writeFile(tempPath, JSON.stringify(value, null, 2), { mode: 0o600 });
|
|
34
|
+
await chmod(tempPath, 0o600);
|
|
35
|
+
await rename(tempPath, filePath);
|
|
36
|
+
await chmod(filePath, 0o600);
|
|
37
|
+
}
|
|
38
|
+
async function localSkillInstalled() {
|
|
39
|
+
const cwd = process.cwd();
|
|
40
|
+
return ((await pathExists(path.join(cwd, '.claude', 'skills', 'use-every'))) ||
|
|
41
|
+
(await pathExists(path.join(cwd, '.agents', 'skills', 'use-every'))));
|
|
42
|
+
}
|
|
43
|
+
export async function maybeShowSkillHint() {
|
|
44
|
+
try {
|
|
45
|
+
const hints = await readHints();
|
|
46
|
+
if (hints.skill_hint_shown)
|
|
47
|
+
return;
|
|
48
|
+
if (await localSkillInstalled())
|
|
49
|
+
return;
|
|
50
|
+
process.stderr.write(`${SKILL_HINT}\n`);
|
|
51
|
+
await writeHints({ ...hints, skill_hint_shown: true });
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// Hints must never affect command success.
|
|
55
|
+
}
|
|
56
|
+
}
|
package/dist/lib/output.js
CHANGED
|
@@ -2,17 +2,32 @@
|
|
|
2
2
|
* Stable output envelope for the `every` CLI.
|
|
3
3
|
*
|
|
4
4
|
* `--json` mode is a CLI CONTRACT that agents and scripts parse. Rules:
|
|
5
|
-
* - Success: `{ ok: true, data, schema_version: 1 }`
|
|
6
|
-
* - Failure: `{ ok: false, error: { message, code }, schema_version: 1 }`
|
|
5
|
+
* - Success: `{ ok: true, data, env, schema_version: 1 }`
|
|
6
|
+
* - Failure: `{ ok: false, error: { message, code }, env, schema_version: 1 }`
|
|
7
7
|
* - In `--json` mode the ONLY thing written is a single JSON object — never
|
|
8
8
|
* mix human prose into machine output.
|
|
9
9
|
*/
|
|
10
|
+
import { environmentNameForBaseUrl, resolveBaseUrl, } from './config.js';
|
|
10
11
|
export const SCHEMA_VERSION = 1;
|
|
11
|
-
|
|
12
|
-
return
|
|
12
|
+
function hasStagingArg() {
|
|
13
|
+
return process.argv.includes('--staging');
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
function envelopeEnv(opts = {}) {
|
|
16
|
+
if (opts.env)
|
|
17
|
+
return opts.env;
|
|
18
|
+
const baseUrl = opts.baseUrl ?? resolveBaseUrl({ staging: opts.staging ?? hasStagingArg() });
|
|
19
|
+
return environmentNameForBaseUrl(baseUrl);
|
|
20
|
+
}
|
|
21
|
+
export function successEnvelope(data, opts = {}) {
|
|
22
|
+
return { ok: true, data, env: envelopeEnv(opts), schema_version: SCHEMA_VERSION };
|
|
23
|
+
}
|
|
24
|
+
export function errorEnvelope(message, code, opts = {}, details = {}) {
|
|
25
|
+
return {
|
|
26
|
+
ok: false,
|
|
27
|
+
error: { message, code, ...details },
|
|
28
|
+
env: envelopeEnv(opts),
|
|
29
|
+
schema_version: SCHEMA_VERSION,
|
|
30
|
+
};
|
|
16
31
|
}
|
|
17
32
|
function humanize(data) {
|
|
18
33
|
if (data === null || data === undefined)
|
|
@@ -28,13 +43,13 @@ function humanize(data) {
|
|
|
28
43
|
/** Render a success result as a string (pure JSON when `json`, else human text). */
|
|
29
44
|
export function formatSuccess(data, opts = {}) {
|
|
30
45
|
if (opts.json)
|
|
31
|
-
return JSON.stringify(successEnvelope(data));
|
|
46
|
+
return JSON.stringify(successEnvelope(data, opts));
|
|
32
47
|
return humanize(data);
|
|
33
48
|
}
|
|
34
49
|
/** Render an error as a string (pure JSON when `json`, else human text). */
|
|
35
|
-
export function formatError(message, code, opts = {}) {
|
|
50
|
+
export function formatError(message, code, opts = {}, details = {}) {
|
|
36
51
|
if (opts.json)
|
|
37
|
-
return JSON.stringify(errorEnvelope(message, code));
|
|
52
|
+
return JSON.stringify(errorEnvelope(message, code, opts, details));
|
|
38
53
|
return `Error: ${message}`;
|
|
39
54
|
}
|
|
40
55
|
/** Emit a success result to stdout. */
|
|
@@ -45,8 +60,8 @@ export function emit(data, opts = {}) {
|
|
|
45
60
|
* Emit an error. In `--json` mode the envelope goes to stdout so a single
|
|
46
61
|
* parse of stdout always yields the machine result; human errors go to stderr.
|
|
47
62
|
*/
|
|
48
|
-
export function emitError(message, code, opts = {}) {
|
|
49
|
-
const rendered = formatError(message, code, opts);
|
|
63
|
+
export function emitError(message, code, opts = {}, details = {}) {
|
|
64
|
+
const rendered = formatError(message, code, opts, details);
|
|
50
65
|
if (opts.json) {
|
|
51
66
|
process.stdout.write(rendered + '\n');
|
|
52
67
|
}
|
package/dist/lib/policy.js
CHANGED
|
@@ -143,20 +143,22 @@ export function requirementDescription(level) {
|
|
|
143
143
|
non_interactive: 'Requires --yes and --allow-destructive.',
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
function confirmationPrompt(level) {
|
|
146
|
+
function confirmationPrompt(level, target) {
|
|
147
|
+
const targetText = target ? ` Target: ${target}.` : '';
|
|
147
148
|
if (level === 'ai-mediated') {
|
|
148
|
-
return `${aiMediatedExplanation()}\nContinue? [y/N] `;
|
|
149
|
+
return `${aiMediatedExplanation()}${targetText}\nContinue? [y/N] `;
|
|
149
150
|
}
|
|
150
|
-
return
|
|
151
|
+
return `This tool can modify your Every account.${targetText} Continue? [y/N] `;
|
|
151
152
|
}
|
|
152
|
-
export async function promptForTool(toolName, level, prompt) {
|
|
153
|
+
export async function promptForTool(toolName, level, prompt, target) {
|
|
153
154
|
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
154
155
|
try {
|
|
155
156
|
if (prompt === 'confirm') {
|
|
156
|
-
const answer = await rl.question(confirmationPrompt(level));
|
|
157
|
+
const answer = await rl.question(confirmationPrompt(level, target));
|
|
157
158
|
return answer.trim().toLowerCase() === 'y' || answer.trim().toLowerCase() === 'yes';
|
|
158
159
|
}
|
|
159
|
-
const
|
|
160
|
+
const targetText = target ? ` for ${target}` : '';
|
|
161
|
+
const answer = await rl.question(`Type ${toolName} to confirm${targetText}: `);
|
|
160
162
|
return answer.trim() === toolName;
|
|
161
163
|
}
|
|
162
164
|
finally {
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@everyai/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The agent-agnostic command-line surface for Every AI.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"bin": {
|
|
8
|
-
"every": "dist/index.js"
|
|
8
|
+
"every": "dist/index.js",
|
|
9
|
+
"everyai": "dist/index.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"dist",
|
|
12
|
-
"skills"
|
|
13
|
+
"skills",
|
|
14
|
+
"scripts/postinstall.mjs"
|
|
13
15
|
],
|
|
14
16
|
"engines": {
|
|
15
17
|
"node": ">=18"
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
"dev": "tsx src/index.ts",
|
|
24
26
|
"test": "vitest run",
|
|
25
27
|
"typecheck": "tsc --noEmit",
|
|
28
|
+
"postinstall": "node scripts/postinstall.mjs || exit 0",
|
|
26
29
|
"prepublishOnly": "npm run build"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
try {
|
|
4
|
+
process.stdout.write(
|
|
5
|
+
[
|
|
6
|
+
'@everyai/cli installed.',
|
|
7
|
+
'- Command: every (also available as everyai)',
|
|
8
|
+
'- Get started: every login',
|
|
9
|
+
'- Teach agents: every skills install claude|codex',
|
|
10
|
+
'- One-shot docs: every docs',
|
|
11
|
+
'',
|
|
12
|
+
].join('\n'),
|
|
13
|
+
);
|
|
14
|
+
} catch {
|
|
15
|
+
// Installing this package must never fail because of a notice.
|
|
16
|
+
} finally {
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
@@ -21,6 +21,7 @@ Always pass `--json`. Parse the envelope every time:
|
|
|
21
21
|
|
|
22
22
|
- `ok: true` means read `data`.
|
|
23
23
|
- `ok: false` means read `error.code` and `error.message`.
|
|
24
|
+
- `env` tells you whether the command targeted `production`, `staging`, or `custom`.
|
|
24
25
|
- `schema_version` must be present and understood before automating against the response.
|
|
25
26
|
|
|
26
27
|
Check process exit codes:
|
|
@@ -40,6 +41,7 @@ Never infer or guess IDs. List first, then act only with the exact ID shown in t
|
|
|
40
41
|
Use these commands to discover current tools and policy:
|
|
41
42
|
|
|
42
43
|
```bash
|
|
44
|
+
every docs
|
|
43
45
|
every tools list --json
|
|
44
46
|
every tools describe <name> --json
|
|
45
47
|
every policy explain <name> --json
|
|
@@ -53,6 +55,8 @@ For WRITE tools, add `--yes` only when the human user explicitly asked for the c
|
|
|
53
55
|
|
|
54
56
|
For DESTRUCTIVE tools, including sends, deletes, voids, and payments, add both `--yes` and `--allow-destructive` only when the human user explicitly asked for that external or irreversible action. Never add `--allow-destructive` unprompted.
|
|
55
57
|
|
|
58
|
+
`every whoami --json` reports the authenticated user, org, environment, base URL, and tool count. Write results echo the target org so you can confirm the blast radius before trusting the result.
|
|
59
|
+
|
|
56
60
|
In automation, prefer `--read-only` unless writes were requested.
|
|
57
61
|
|
|
58
62
|
Treat `ask_assistant` as AI-mediated. It routes to Every's agent and can act on the account. Prefer deterministic tools. Do not use `ask_assistant` in read-only automation.
|
|
@@ -76,10 +80,16 @@ Invoice flow:
|
|
|
76
80
|
|
|
77
81
|
```bash
|
|
78
82
|
every invoice list --status overdue --json
|
|
79
|
-
every
|
|
83
|
+
every invoice create --client "Acme" --amount 100 --yes --json
|
|
80
84
|
every invoice send <id> --yes --allow-destructive --json
|
|
81
85
|
```
|
|
82
86
|
|
|
87
|
+
For rich invoices with multiple line items, tax, dates, currency, or notes, use the full tool fallback:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
every tool call create_invoice --arg client_id=<id> --arg line_items='[{"description":"Work","quantity":1,"unit_price":100}]' --yes --json
|
|
91
|
+
```
|
|
92
|
+
|
|
83
93
|
Contacts:
|
|
84
94
|
|
|
85
95
|
```bash
|