@everyai/cli 0.1.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 +76 -0
- package/dist/commands/aliases.js +74 -0
- package/dist/commands/auth.js +150 -0
- package/dist/commands/ping.js +57 -0
- package/dist/commands/policy.js +38 -0
- package/dist/commands/skills.js +98 -0
- package/dist/commands/tools.js +220 -0
- package/dist/index.js +309 -0
- package/dist/lib/auth/dcr.js +80 -0
- package/dist/lib/auth/discovery.js +87 -0
- package/dist/lib/auth/flow.js +177 -0
- package/dist/lib/auth/jwt.js +15 -0
- package/dist/lib/auth/pkce.js +12 -0
- package/dist/lib/auth/tokens.js +302 -0
- package/dist/lib/config.js +28 -0
- package/dist/lib/errors.js +16 -0
- package/dist/lib/exit-codes.js +16 -0
- package/dist/lib/mcp.js +214 -0
- package/dist/lib/output.js +56 -0
- package/dist/lib/policy.js +165 -0
- package/package.json +39 -0
- package/skills/use-every/SKILL.md +102 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @everyai/cli
|
|
2
|
+
|
|
3
|
+
The **agent-agnostic** command line for [Every AI](https://every.ai) — manage your business (invoices, clients, contacts, proposals, deals) from any shell, any coding agent, or CI.
|
|
4
|
+
|
|
5
|
+
Install once, log in once, and the same `every` command works everywhere your agents run — Claude Code, Codex, Cursor, plain terminals, cron, CI — instead of wiring a bespoke MCP + OAuth setup into each host.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @everyai/cli
|
|
9
|
+
every login # opens your browser (OAuth + PKCE); tokens land in your OS keychain
|
|
10
|
+
every whoami --json # authenticated check: who you are + how many tools you have
|
|
11
|
+
every tools list # the full tool surface, with safety classifications
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Why a CLI (vs. adding the MCP server to each host)
|
|
15
|
+
|
|
16
|
+
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:
|
|
17
|
+
|
|
18
|
+
- **Portability** — one install + one login covers every agent and machine context; remote-MCP config is per-host, per-format, and often impossible in CI.
|
|
19
|
+
- **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.
|
|
20
|
+
- **Deterministic output** — a stable `--json` envelope and exit-code taxonomy an agent can parse and branch on.
|
|
21
|
+
|
|
22
|
+
## Commands
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Auth
|
|
26
|
+
every login [--staging] # browser OAuth; keychain storage; refresh handled
|
|
27
|
+
every logout | whoami | auth status | org
|
|
28
|
+
|
|
29
|
+
# Discovery
|
|
30
|
+
every tools list [--no-cache]
|
|
31
|
+
every tools describe <name>
|
|
32
|
+
every policy explain <name> # classification + exactly what running it requires
|
|
33
|
+
|
|
34
|
+
# Run any tool
|
|
35
|
+
every tool call <name> [--args file.json|-] [--arg k=v ...] [--yes] [--allow-destructive] [--read-only]
|
|
36
|
+
|
|
37
|
+
# Curated aliases (same gates, nicer flags)
|
|
38
|
+
every invoice list [--status <s>] [--search <q>] [--limit <n>]
|
|
39
|
+
every invoice send <invoice_id> # destructive: needs --yes --allow-destructive
|
|
40
|
+
every deal list [--stage <s>] [--search <q>]
|
|
41
|
+
every deal move <deal_id> <stage> # write: needs --yes
|
|
42
|
+
every contact list [--search <q>]
|
|
43
|
+
|
|
44
|
+
# Teach your coding agent to use all of this well
|
|
45
|
+
every skills install claude # → .claude/skills/use-every/
|
|
46
|
+
every skills install codex # → .agents/skills/use-every/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Output contract
|
|
50
|
+
|
|
51
|
+
Every command supports `--json`: exactly one JSON document on stdout, nothing else.
|
|
52
|
+
|
|
53
|
+
```jsonc
|
|
54
|
+
{ "ok": true, "data": { /* ... */ }, "schema_version": 1 }
|
|
55
|
+
{ "ok": false, "error": { "message": "...", "code": "..." }, "schema_version": 1 }
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
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.
|
|
59
|
+
|
|
60
|
+
## Headless / CI
|
|
61
|
+
|
|
62
|
+
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
|
+
|
|
64
|
+
## Status
|
|
65
|
+
|
|
66
|
+
Pre-release. Built against Every's production MCP surface; `--staging` targets Every's internal staging environment.
|
|
67
|
+
|
|
68
|
+
## Development
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install
|
|
72
|
+
npm run dev -- ping --staging --json # run from source
|
|
73
|
+
npm run typecheck
|
|
74
|
+
npm test
|
|
75
|
+
npm run build
|
|
76
|
+
```
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CliError } from '../lib/errors.js';
|
|
2
|
+
import { ExitCode } from '../lib/exit-codes.js';
|
|
3
|
+
import { executeToolCall } from './tools.js';
|
|
4
|
+
const INVOICE_STATUSES = new Set(['draft', 'issued', 'void']);
|
|
5
|
+
const PAYMENT_STATUSES = new Set(['unpaid', 'paid', 'overdue', 'partial']);
|
|
6
|
+
const DEAL_STAGES = new Set(['lead', 'opportunity', 'won', 'lost']);
|
|
7
|
+
function parseLimit(value) {
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return undefined;
|
|
10
|
+
const limit = Number(value);
|
|
11
|
+
if (!Number.isInteger(limit) || limit < 0) {
|
|
12
|
+
throw new CliError('--limit must be a non-negative integer', ExitCode.USAGE, 'usage');
|
|
13
|
+
}
|
|
14
|
+
return limit;
|
|
15
|
+
}
|
|
16
|
+
function assertDealStage(stage) {
|
|
17
|
+
if (!DEAL_STAGES.has(stage)) {
|
|
18
|
+
throw new CliError(`stage must be one of: ${Array.from(DEAL_STAGES).join(', ')}`, ExitCode.USAGE, 'usage');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function addLimit(args, value) {
|
|
22
|
+
const limit = parseLimit(value);
|
|
23
|
+
if (limit !== undefined)
|
|
24
|
+
args.limit = limit;
|
|
25
|
+
}
|
|
26
|
+
function addInvoiceStatus(args, value) {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
return;
|
|
29
|
+
if (PAYMENT_STATUSES.has(value)) {
|
|
30
|
+
args.payment_status = value;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (INVOICE_STATUSES.has(value)) {
|
|
34
|
+
args.status = value;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw new CliError(`--status must be one of: ${[
|
|
38
|
+
...Array.from(INVOICE_STATUSES),
|
|
39
|
+
...Array.from(PAYMENT_STATUSES),
|
|
40
|
+
].join(', ')}`, ExitCode.USAGE, 'usage');
|
|
41
|
+
}
|
|
42
|
+
export async function invoiceListCommand(opts = {}) {
|
|
43
|
+
const args = {};
|
|
44
|
+
addInvoiceStatus(args, opts.status);
|
|
45
|
+
if (opts.search !== undefined)
|
|
46
|
+
args.search = opts.search;
|
|
47
|
+
addLimit(args, opts.limit);
|
|
48
|
+
await executeToolCall('list_invoices', opts, async () => args);
|
|
49
|
+
}
|
|
50
|
+
export async function invoiceSendCommand(invoiceId, opts = {}) {
|
|
51
|
+
await executeToolCall('send_invoice', opts, async () => ({ invoice_id: invoiceId }));
|
|
52
|
+
}
|
|
53
|
+
export async function dealListCommand(opts = {}) {
|
|
54
|
+
const args = {};
|
|
55
|
+
if (opts.stage !== undefined) {
|
|
56
|
+
assertDealStage(opts.stage);
|
|
57
|
+
args.stage = opts.stage;
|
|
58
|
+
}
|
|
59
|
+
if (opts.search !== undefined)
|
|
60
|
+
args.search = opts.search;
|
|
61
|
+
addLimit(args, opts.limit);
|
|
62
|
+
await executeToolCall('list_deals', opts, async () => args);
|
|
63
|
+
}
|
|
64
|
+
export async function dealMoveCommand(dealId, stage, opts = {}) {
|
|
65
|
+
assertDealStage(stage);
|
|
66
|
+
await executeToolCall('move_deal_stage', opts, async () => ({ deal_id: dealId, stage }));
|
|
67
|
+
}
|
|
68
|
+
export async function contactListCommand(opts = {}) {
|
|
69
|
+
const args = {};
|
|
70
|
+
if (opts.search !== undefined)
|
|
71
|
+
args.name = opts.search;
|
|
72
|
+
addLimit(args, opts.limit);
|
|
73
|
+
await executeToolCall('list_contacts', opts, async () => args);
|
|
74
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { resolveBaseUrl } from '../lib/config.js';
|
|
2
|
+
import { CliError } from '../lib/errors.js';
|
|
3
|
+
import { ExitCode } from '../lib/exit-codes.js';
|
|
4
|
+
import { mcpCall } from '../lib/mcp.js';
|
|
5
|
+
import { loginFlow } from '../lib/auth/flow.js';
|
|
6
|
+
import { decodeJwtClaims } from '../lib/auth/jwt.js';
|
|
7
|
+
import { createTokenStore, deleteTokenFromAllStores, getAuthStatus, getToken, resolveAuthTarget, } from '../lib/auth/tokens.js';
|
|
8
|
+
import { emit } from '../lib/output.js';
|
|
9
|
+
const WHOAMI_TIMEOUT_MS = 10_000;
|
|
10
|
+
function emitCommand(data, human, opts) {
|
|
11
|
+
if (opts.json)
|
|
12
|
+
emit(data, { json: true });
|
|
13
|
+
else
|
|
14
|
+
process.stdout.write(`${human}\n`);
|
|
15
|
+
}
|
|
16
|
+
function identityFromToken(token) {
|
|
17
|
+
const claims = decodeJwtClaims(token);
|
|
18
|
+
return {
|
|
19
|
+
subject: claims?.sub ?? null,
|
|
20
|
+
email: claims?.email ?? null,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function loginHuman(data) {
|
|
24
|
+
if (data.every_token)
|
|
25
|
+
return 'EVERY_TOKEN is set; login is unnecessary.';
|
|
26
|
+
const identity = data.email ?? data.subject;
|
|
27
|
+
return identity ? `Logged in as ${identity}` : 'Logged in';
|
|
28
|
+
}
|
|
29
|
+
function statusHuman(status) {
|
|
30
|
+
return [
|
|
31
|
+
`Logged in: ${status.logged_in ? 'yes' : 'no'}`,
|
|
32
|
+
`Environment: ${status.environment}`,
|
|
33
|
+
`Base URL: ${status.base_url}`,
|
|
34
|
+
`Storage: ${status.storage_backend}`,
|
|
35
|
+
`EVERY_TOKEN: ${status.every_token ? 'overriding' : 'not set'}`,
|
|
36
|
+
`Issuer: ${status.issuer ?? 'none'}`,
|
|
37
|
+
`Expires: ${status.expires ?? 'unknown'}`,
|
|
38
|
+
`Refresh token: ${status.refresh_token ? 'yes' : 'no'}`,
|
|
39
|
+
].join('\n');
|
|
40
|
+
}
|
|
41
|
+
function orgFromClaims(claims) {
|
|
42
|
+
return {
|
|
43
|
+
org_id: typeof claims?.org_id === 'string' ? claims.org_id : null,
|
|
44
|
+
org_slug: typeof claims?.org_slug === 'string' ? claims.org_slug : null,
|
|
45
|
+
org_name: typeof claims?.org_name === 'string' ? claims.org_name : null,
|
|
46
|
+
organization_id: typeof claims?.organization_id === 'string' ? claims.organization_id : null,
|
|
47
|
+
organization_slug: typeof claims?.organization_slug === 'string' ? claims.organization_slug : null,
|
|
48
|
+
organization_name: typeof claims?.organization_name === 'string' ? claims.organization_name : null,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function orgHuman(org) {
|
|
52
|
+
const lines = [
|
|
53
|
+
`org_id: ${org.org_id ?? 'none'}`,
|
|
54
|
+
`org_slug: ${org.org_slug ?? 'none'}`,
|
|
55
|
+
`org_name: ${org.org_name ?? 'none'}`,
|
|
56
|
+
];
|
|
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
|
+
return lines.join('\n');
|
|
63
|
+
}
|
|
64
|
+
async function verifyMcpLiveness(baseUrl, token) {
|
|
65
|
+
const body = await mcpCall(baseUrl, token, 'tools/list', {}, { timeoutMs: WHOAMI_TIMEOUT_MS });
|
|
66
|
+
return {
|
|
67
|
+
authenticated: true,
|
|
68
|
+
tools: Array.isArray(body.tools) ? body.tools.length : 0,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export async function loginCommand(opts = {}) {
|
|
72
|
+
if (process.env.EVERY_TOKEN) {
|
|
73
|
+
const identity = identityFromToken(process.env.EVERY_TOKEN);
|
|
74
|
+
const data = {
|
|
75
|
+
logged_in: true,
|
|
76
|
+
issuer: null,
|
|
77
|
+
subject: identity.subject,
|
|
78
|
+
email: identity.email,
|
|
79
|
+
storage_backend: null,
|
|
80
|
+
every_token: true,
|
|
81
|
+
};
|
|
82
|
+
emitCommand(data, loginHuman(data), opts);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!process.stdout.isTTY) {
|
|
86
|
+
throw new CliError('login requires a browser; set EVERY_TOKEN for headless use', ExitCode.AUTH, 'auth');
|
|
87
|
+
}
|
|
88
|
+
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
89
|
+
const { environmentKey } = resolveAuthTarget({ baseUrl });
|
|
90
|
+
const tokenSet = await loginFlow({
|
|
91
|
+
baseUrl,
|
|
92
|
+
onAuthorizationUrl(url) {
|
|
93
|
+
process.stderr.write(`Open this URL to log in:\n${url}\n`);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const store = await createTokenStore();
|
|
97
|
+
await store.set(environmentKey, tokenSet);
|
|
98
|
+
const identity = identityFromToken(tokenSet.access_token);
|
|
99
|
+
const data = {
|
|
100
|
+
logged_in: true,
|
|
101
|
+
issuer: tokenSet.issuer,
|
|
102
|
+
subject: identity.subject,
|
|
103
|
+
email: identity.email,
|
|
104
|
+
storage_backend: store.backend,
|
|
105
|
+
every_token: false,
|
|
106
|
+
};
|
|
107
|
+
emitCommand(data, loginHuman(data), opts);
|
|
108
|
+
}
|
|
109
|
+
export async function logoutCommand(opts = {}) {
|
|
110
|
+
const { environmentKey } = resolveAuthTarget({ staging: opts.staging });
|
|
111
|
+
await deleteTokenFromAllStores(environmentKey);
|
|
112
|
+
const data = {
|
|
113
|
+
logged_out: true,
|
|
114
|
+
environment: environmentKey,
|
|
115
|
+
};
|
|
116
|
+
emitCommand(data, 'Logged out', opts);
|
|
117
|
+
}
|
|
118
|
+
export async function authStatusCommand(opts = {}) {
|
|
119
|
+
const status = await getAuthStatus({ staging: opts.staging });
|
|
120
|
+
emitCommand(status, statusHuman(status), opts);
|
|
121
|
+
}
|
|
122
|
+
export async function whoamiCommand(opts = {}) {
|
|
123
|
+
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
124
|
+
const token = await getToken({ baseUrl });
|
|
125
|
+
const claims = decodeJwtClaims(token);
|
|
126
|
+
const liveness = await verifyMcpLiveness(baseUrl, token);
|
|
127
|
+
const data = {
|
|
128
|
+
authenticated: liveness.authenticated,
|
|
129
|
+
subject: claims?.sub ?? null,
|
|
130
|
+
email: claims?.email ?? null,
|
|
131
|
+
org_id: typeof claims?.org_id === 'string'
|
|
132
|
+
? claims.org_id
|
|
133
|
+
: typeof claims?.organization_id === 'string'
|
|
134
|
+
? claims.organization_id
|
|
135
|
+
: null,
|
|
136
|
+
tools: liveness.tools,
|
|
137
|
+
};
|
|
138
|
+
const identity = data.email ?? data.subject ?? 'unknown';
|
|
139
|
+
emitCommand(data, [
|
|
140
|
+
`Authenticated: yes`,
|
|
141
|
+
`User: ${identity}`,
|
|
142
|
+
`Org: ${data.org_id ?? 'none'}`,
|
|
143
|
+
`Tools: ${data.tools}`,
|
|
144
|
+
].join('\n'), opts);
|
|
145
|
+
}
|
|
146
|
+
export async function orgCommand(opts = {}) {
|
|
147
|
+
const token = await getToken({ staging: opts.staging });
|
|
148
|
+
const org = orgFromClaims(decodeJwtClaims(token));
|
|
149
|
+
emitCommand(org, orgHuman(org), opts);
|
|
150
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { resolveBaseUrl } from '../lib/config.js';
|
|
2
|
+
import { emit } from '../lib/output.js';
|
|
3
|
+
import { CliError } from '../lib/errors.js';
|
|
4
|
+
import { ExitCode } from '../lib/exit-codes.js';
|
|
5
|
+
const PING_TIMEOUT_MS = 10_000;
|
|
6
|
+
function classifyHttpStatus(status) {
|
|
7
|
+
if (status === 401)
|
|
8
|
+
return { exitCode: ExitCode.AUTH, code: 'auth' };
|
|
9
|
+
if (status === 402 || status === 403) {
|
|
10
|
+
return { exitCode: ExitCode.PERMISSION, code: 'permission' };
|
|
11
|
+
}
|
|
12
|
+
if (status === 404)
|
|
13
|
+
return { exitCode: ExitCode.NOT_FOUND, code: 'not_found' };
|
|
14
|
+
if (status === 429)
|
|
15
|
+
return { exitCode: ExitCode.RATE_LIMIT, code: 'rate_limit' };
|
|
16
|
+
if (status >= 500)
|
|
17
|
+
return { exitCode: ExitCode.NETWORK, code: 'network' };
|
|
18
|
+
return { exitCode: ExitCode.GENERIC, code: 'generic' };
|
|
19
|
+
}
|
|
20
|
+
function isTimeoutError(err) {
|
|
21
|
+
return err instanceof Error && (err.name === 'AbortError' || err.name === 'TimeoutError');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `every ping` — unauthenticated connectivity check against the MCP server's
|
|
25
|
+
* `/health` endpoint. Emits `{ status, service, base_url }` on success.
|
|
26
|
+
*/
|
|
27
|
+
export async function pingCommand(opts = {}) {
|
|
28
|
+
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
29
|
+
const url = `${baseUrl}/health`;
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
response = await fetch(url, { signal: AbortSignal.timeout(PING_TIMEOUT_MS) });
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
if (isTimeoutError(err)) {
|
|
36
|
+
throw new CliError(`Timed out reaching ${url} after ${PING_TIMEOUT_MS}ms`, ExitCode.NETWORK, 'network');
|
|
37
|
+
}
|
|
38
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
39
|
+
throw new CliError(`Failed to reach ${url}: ${detail}`, ExitCode.NETWORK, 'network');
|
|
40
|
+
}
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
const classified = classifyHttpStatus(response.status);
|
|
43
|
+
throw new CliError(`Health check failed for ${url}: HTTP ${response.status}`, classified.exitCode, classified.code);
|
|
44
|
+
}
|
|
45
|
+
let body = {};
|
|
46
|
+
try {
|
|
47
|
+
body = (await response.json());
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// Non-JSON 200 is still "reachable"; fall back to a healthy default.
|
|
51
|
+
}
|
|
52
|
+
emit({
|
|
53
|
+
status: body.status ?? 'ok',
|
|
54
|
+
service: body.service ?? null,
|
|
55
|
+
base_url: baseUrl,
|
|
56
|
+
}, { json: opts.json });
|
|
57
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { resolveBaseUrl } from '../lib/config.js';
|
|
2
|
+
import { readCachedTools } from '../lib/mcp.js';
|
|
3
|
+
import { emit } from '../lib/output.js';
|
|
4
|
+
import { classify, requirementDescription } from '../lib/policy.js';
|
|
5
|
+
function emitCommand(data, human, opts) {
|
|
6
|
+
if (opts.json)
|
|
7
|
+
emit(data, { json: true });
|
|
8
|
+
else
|
|
9
|
+
process.stdout.write(`${human}\n`);
|
|
10
|
+
}
|
|
11
|
+
export async function policyExplainCommand(name, opts = {}) {
|
|
12
|
+
const baseUrl = resolveBaseUrl({ staging: opts.staging });
|
|
13
|
+
const cachedTools = await readCachedTools(baseUrl, { allowStale: true }).catch(() => undefined);
|
|
14
|
+
const tool = cachedTools?.find((candidate) => candidate.name === name) ?? { name };
|
|
15
|
+
const classification = classify(tool);
|
|
16
|
+
const requirements = requirementDescription(classification.level);
|
|
17
|
+
const note = cachedTools?.some((candidate) => candidate.name === name)
|
|
18
|
+
? undefined
|
|
19
|
+
: 'No cached tool metadata matched this name; classification used local overrides and name patterns only.';
|
|
20
|
+
const data = {
|
|
21
|
+
tool: name,
|
|
22
|
+
level: classification.level,
|
|
23
|
+
source: classification.source,
|
|
24
|
+
reason: classification.reason,
|
|
25
|
+
requirements,
|
|
26
|
+
note,
|
|
27
|
+
};
|
|
28
|
+
const human = [
|
|
29
|
+
`Tool: ${name}`,
|
|
30
|
+
`Level: ${data.level}`,
|
|
31
|
+
`Source: ${data.source}`,
|
|
32
|
+
`Reason: ${data.reason}`,
|
|
33
|
+
`Interactive: ${requirements.interactive}`,
|
|
34
|
+
`Non-interactive: ${requirements.non_interactive}`,
|
|
35
|
+
note ? `Note: ${note}` : undefined,
|
|
36
|
+
].filter((line) => Boolean(line)).join('\n');
|
|
37
|
+
emitCommand(data, human, opts);
|
|
38
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { cp, mkdir, readdir, rm } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { CliError } from '../lib/errors.js';
|
|
6
|
+
import { ExitCode } from '../lib/exit-codes.js';
|
|
7
|
+
import { emit } from '../lib/output.js';
|
|
8
|
+
const SKILL_NAME = 'use-every';
|
|
9
|
+
const TARGET_ROOTS = {
|
|
10
|
+
claude: {
|
|
11
|
+
local: ['.claude', 'skills'],
|
|
12
|
+
global: ['.claude', 'skills'],
|
|
13
|
+
},
|
|
14
|
+
codex: {
|
|
15
|
+
local: ['.agents', 'skills'],
|
|
16
|
+
global: ['.agents', 'skills'],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
function bundledSkillDir() {
|
|
20
|
+
return fileURLToPath(new URL('../../skills/use-every/', import.meta.url));
|
|
21
|
+
}
|
|
22
|
+
function assertTarget(target) {
|
|
23
|
+
if (target !== 'claude' && target !== 'codex') {
|
|
24
|
+
throw new CliError(`Unknown skills target: ${target}`, ExitCode.USAGE, 'usage');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function targetRoot(target, opts) {
|
|
28
|
+
if (opts.dir)
|
|
29
|
+
return path.resolve(opts.dir);
|
|
30
|
+
const parts = opts.global ? TARGET_ROOTS[target].global : TARGET_ROOTS[target].local;
|
|
31
|
+
return opts.global ? path.join(os.homedir(), ...parts) : path.join(process.cwd(), ...parts);
|
|
32
|
+
}
|
|
33
|
+
function targetInfo(target, opts) {
|
|
34
|
+
const root = targetRoot(target, opts);
|
|
35
|
+
return {
|
|
36
|
+
target,
|
|
37
|
+
root,
|
|
38
|
+
install_to: path.join(root, SKILL_NAME),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function normalizeRelativePath(value) {
|
|
42
|
+
return value.split(path.sep).join('/');
|
|
43
|
+
}
|
|
44
|
+
async function listFiles(root, prefix = '') {
|
|
45
|
+
const entries = await readdir(path.join(root, prefix), { withFileTypes: true });
|
|
46
|
+
const files = [];
|
|
47
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
48
|
+
const relative = path.join(prefix, entry.name);
|
|
49
|
+
if (entry.isDirectory())
|
|
50
|
+
files.push(...await listFiles(root, relative));
|
|
51
|
+
else if (entry.isFile())
|
|
52
|
+
files.push(normalizeRelativePath(relative));
|
|
53
|
+
}
|
|
54
|
+
return files;
|
|
55
|
+
}
|
|
56
|
+
function emitCommand(data, human, opts) {
|
|
57
|
+
if (opts.json)
|
|
58
|
+
emit(data, { json: true });
|
|
59
|
+
else
|
|
60
|
+
process.stdout.write(`${human}\n`);
|
|
61
|
+
}
|
|
62
|
+
function installHuman(target, files) {
|
|
63
|
+
const lines = [`Installed ${SKILL_NAME} for ${target.target} to ${target.install_to}`];
|
|
64
|
+
for (const file of files)
|
|
65
|
+
lines.push(`- ${file}`);
|
|
66
|
+
return lines.join('\n');
|
|
67
|
+
}
|
|
68
|
+
export async function skillsInstallCommand(target, opts = {}) {
|
|
69
|
+
assertTarget(target);
|
|
70
|
+
const info = targetInfo(target, opts);
|
|
71
|
+
const source = bundledSkillDir();
|
|
72
|
+
const files = await listFiles(source);
|
|
73
|
+
await mkdir(info.root, { recursive: true });
|
|
74
|
+
await rm(info.install_to, { recursive: true, force: true });
|
|
75
|
+
await cp(source, info.install_to, { recursive: true, force: true });
|
|
76
|
+
emitCommand({ installed_to: info.install_to, files }, installHuman(info, files), opts);
|
|
77
|
+
}
|
|
78
|
+
function listHuman(skills) {
|
|
79
|
+
const lines = ['Available bundled skills:'];
|
|
80
|
+
for (const skill of skills) {
|
|
81
|
+
lines.push(skill.name);
|
|
82
|
+
lines.push(` claude: ${skill.targets.claude.install_to}`);
|
|
83
|
+
lines.push(` codex: ${skill.targets.codex.install_to}`);
|
|
84
|
+
}
|
|
85
|
+
return lines.join('\n');
|
|
86
|
+
}
|
|
87
|
+
export async function skillsListCommand(opts = {}) {
|
|
88
|
+
const skills = [
|
|
89
|
+
{
|
|
90
|
+
name: SKILL_NAME,
|
|
91
|
+
targets: {
|
|
92
|
+
claude: targetInfo('claude', opts),
|
|
93
|
+
codex: targetInfo('codex', opts),
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
];
|
|
97
|
+
emitCommand({ skills }, listHuman(skills), opts);
|
|
98
|
+
}
|