@everyai/cli 0.1.0 → 0.3.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.
@@ -0,0 +1,74 @@
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 GENERIC_SKILL_TARGET = 'claude|codex';
5
+ function skillHintTargetForEnv(env) {
6
+ if (env.CLAUDECODE !== undefined)
7
+ return 'claude';
8
+ if (Object.keys(env).some((key) => key.startsWith('CODEX_') && env[key] !== undefined)) {
9
+ return 'codex';
10
+ }
11
+ return GENERIC_SKILL_TARGET;
12
+ }
13
+ export function skillHintForEnv(env = process.env) {
14
+ const target = skillHintTargetForEnv(env);
15
+ return `Tip: teach your coding agent this CLI — run: every skills install ${target} (shown once)`;
16
+ }
17
+ function hintsPath() {
18
+ return path.join(getConfigDir(), 'hints.json');
19
+ }
20
+ async function pathExists(filePath) {
21
+ try {
22
+ await access(filePath);
23
+ return true;
24
+ }
25
+ catch {
26
+ return false;
27
+ }
28
+ }
29
+ export async function readHints() {
30
+ try {
31
+ const parsed = JSON.parse(await readFile(hintsPath(), 'utf8'));
32
+ return parsed && typeof parsed === 'object' ? parsed : {};
33
+ }
34
+ catch (err) {
35
+ if (err && typeof err === 'object' && 'code' in err && err.code === 'ENOENT') {
36
+ return {};
37
+ }
38
+ return {};
39
+ }
40
+ }
41
+ export async function writeHints(value) {
42
+ const filePath = hintsPath();
43
+ await mkdir(path.dirname(filePath), { recursive: true, mode: 0o700 });
44
+ const tempPath = `${filePath}.${process.pid}.tmp`;
45
+ await writeFile(tempPath, JSON.stringify(value, null, 2), { mode: 0o600 });
46
+ await chmod(tempPath, 0o600);
47
+ await rename(tempPath, filePath);
48
+ await chmod(filePath, 0o600);
49
+ }
50
+ async function localSkillInstalled(env = process.env) {
51
+ const cwd = process.cwd();
52
+ const target = skillHintTargetForEnv(env);
53
+ const claudeInstalled = () => pathExists(path.join(cwd, '.claude', 'skills', 'use-every'));
54
+ const codexInstalled = () => pathExists(path.join(cwd, '.agents', 'skills', 'use-every'));
55
+ if (target === 'claude')
56
+ return claudeInstalled();
57
+ if (target === 'codex')
58
+ return codexInstalled();
59
+ return (await claudeInstalled()) || (await codexInstalled());
60
+ }
61
+ export async function maybeShowSkillHint() {
62
+ try {
63
+ const hints = await readHints();
64
+ if (hints.skill_hint_shown)
65
+ return;
66
+ if (await localSkillInstalled())
67
+ return;
68
+ process.stderr.write(`${skillHintForEnv()}\n`);
69
+ await writeHints({ ...hints, skill_hint_shown: true });
70
+ }
71
+ catch {
72
+ // Hints must never affect command success.
73
+ }
74
+ }
@@ -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
- export function successEnvelope(data) {
12
- return { ok: true, data, schema_version: SCHEMA_VERSION };
12
+ function hasStagingArg() {
13
+ return process.argv.includes('--staging');
13
14
  }
14
- export function errorEnvelope(message, code) {
15
- return { ok: false, error: { message, code }, schema_version: SCHEMA_VERSION };
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
  }
@@ -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 'This tool can modify your Every account. Continue? [y/N] ';
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 answer = await rl.question(`Type ${toolName} to confirm: `);
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.1.0",
3
+ "version": "0.3.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
+ }
@@ -1,45 +1,51 @@
1
1
  ---
2
2
  name: use-every
3
- description: Drive the Every AI CLI (`every`) to manage the user's business — invoices, clients, contacts, proposals, deals, pipeline, payments. Use when the user asks to look up, create, update, or send any of those, or mentions their Every workspace.
3
+ description: Drive the Every AI CLI (`every`) to manage the user's service business — invoices, clients, contacts, proposals, deals, pipeline, payments, services, and bookings. Use when the user asks “who owes me money?”, wants a lead or deal follow-up, asks to look up, create, update, convert, or send a business record, or mentions their Every workspace.
4
4
  ---
5
5
 
6
6
  # Use Every
7
7
 
8
8
  ## Setup Check
9
9
 
10
- Run `every --version` first. If the CLI is missing, suggest `npm install -g @everyai/cli`. If any authenticated command exits `3`, tell the user to run `every login` (it opens their browser; you cannot complete it for them).
10
+ Run `every --version` first. If the CLI is missing, suggest `npm i -g @everyai/cli`. If any authenticated command exits `3`, tell the user to run `every login` (it opens their browser; you cannot complete it for them).
11
+
12
+ For headless use, accept `EVERY_TOKEN` from the environment instead of browser login. Never print, log, or persist the token.
11
13
 
12
14
  ## What Every Is
13
15
 
14
- Use Every as an SMB business-ops workspace for invoices, clients, contacts, proposals, deals, payments, and pipeline work.
16
+ Use Every as a service-business workspace for the sales pipeline, deals, contacts and clients, proposals, invoices, payments, services, and bookings. The authenticated CLI operates on one connected Every workspace at a time. If the user means a different business, tell them to switch accounts in Every.
17
+
18
+ ## Required Workflow
15
19
 
16
- Use the `every` CLI as authenticated access to the user's Every workspace from any coding agent shell. Assume the user must have run `every login` once before authenticated commands can work.
20
+ 1. Resolve records with list/view commands. Never guess an ID; use the exact ID returned in `[id: ...]`. If a name is ambiguous, show the candidates and ask.
21
+ 2. Before a write, state exactly what will be created or changed, including amounts and recipients.
22
+ 3. Get explicit approval before anything client-visible or financially consequential, including sends, deletes, voids, and recording payments.
23
+ 4. Execute with complete inputs, then echo the returned number, status, total, and `public_url`. Suggest the natural next step. Share only `public_url` links with clients, never internal IDs.
17
24
 
18
- ## Conventions
25
+ ## CLI Contract
19
26
 
20
27
  Always pass `--json`. Parse the envelope every time:
21
28
 
22
29
  - `ok: true` means read `data`.
23
30
  - `ok: false` means read `error.code` and `error.message`.
31
+ - `env` tells you whether the command targeted `production`, `staging`, or `custom`.
24
32
  - `schema_version` must be present and understood before automating against the response.
25
33
 
26
34
  Check process exit codes:
27
35
 
28
36
  - `0`: success.
37
+ - `1`: tool or generic error. Read the error message before deciding whether to retry.
29
38
  - `2`: usage error. Fix the command or arguments.
30
39
  - `3`: auth error. Tell the user to run `every login`.
31
- - `4`: permission or confirmation needed. Ask the user before adding confirmation flags.
40
+ - `4`: permission or confirmation needed. Ask before adding confirmation flags.
32
41
  - `5`: rate limited. Back off and retry later.
33
42
  - `6`: not found. Re-list records and verify the ID.
34
43
  - `7`: network error. Retry after checking connectivity.
35
44
 
36
- Never infer or guess IDs. List first, then act only with the exact ID shown in the result, such as `[id: ...]`.
37
-
38
- ## Discovery
39
-
40
- Use these commands to discover current tools and policy:
45
+ Use current tool schemas rather than assuming arguments:
41
46
 
42
47
  ```bash
48
+ every docs
43
49
  every tools list --json
44
50
  every tools describe <name> --json
45
51
  every policy explain <name> --json
@@ -49,44 +55,135 @@ every policy explain <name> --json
49
55
 
50
56
  Run read tools freely.
51
57
 
52
- For WRITE tools, add `--yes` only when the human user explicitly asked for the change.
58
+ For WRITE tools, add `--yes` only when the human explicitly asked for the change.
59
+
60
+ For DESTRUCTIVE tools, including sends, deletes, voids, and payments, add both `--yes` and `--allow-destructive` only when the human explicitly asked for that external or irreversible action. Never add `--allow-destructive` unprompted.
61
+
62
+ Use `every whoami --json` to verify the authenticated user, org, environment, base URL, and tool count. Write results echo the target org; confirm the blast radius before trusting them. In automation, prefer `--read-only` unless writes were requested.
63
+
64
+ `ask_assistant` is a server-enforced read-only analytical fallback; prefer deterministic tools for actions.
65
+
66
+ ## Domain Rules
67
+
68
+ ### Deal activity auto-tracking is creation-only
69
+
70
+ Creating a proposal, invoice, or booking automatically records activity on a matching deal when exactly one deal/client matches. After an Every creation command, never double-log that action:
71
+
72
+ ```bash
73
+ every invoice create --client-id <client_id> --amount 100 --yes --json
74
+ every tool call create_proposal --args proposal.json --yes --json
75
+ ```
76
+
77
+ Use `log_deal_activity` ONLY for a completed outside event the user reports, such as a call, meeting, or email/DM thread. Never use it for an action performed through Every tools:
78
+
79
+ ```bash
80
+ every deal list --search "Acme" --json
81
+ every tool call log_deal_activity --arg deal_id=<deal_id> --arg note="Call completed; client approved scope" --yes --json
82
+ ```
83
+
84
+ ### Won deals require completed client promotion
85
+
86
+ Pipeline stages are `lead`, `opportunity`, `won`, and `lost`:
87
+
88
+ ```bash
89
+ every deal move <deal_id> won --yes --json
90
+ ```
91
+
92
+ Moving to `won` requires completed client promotion. No CLI or chat tool can set that promotion. If the command returns a client-resolution error, tell the user to finish converting the contact to a client in the Every app, then retry the same command.
93
+
94
+ ### Invoice rates and tax
95
+
96
+ Treat `unit_price` as the per-unit rate, not the line total. The simple CLI's `--amount` maps to that per-unit rate:
97
+
98
+ ```bash
99
+ every invoice create --client-id <client_id> --description "Workshop" --quantity 3 --amount 100 --yes --json
100
+ every tool call create_invoice --arg client_id=<client_id> --arg line_items='[{"description":"Workshop","quantity":3,"unit_price":100}]' --yes --json
101
+ ```
102
+
103
+ Leave `sales_tax_applied` unset so the business default applies. Never add tax as a line item. When currency, tax, or timezone matters, read settings first with `every tool call business_settings --json`; let Every compute tax, numbering, due dates, and totals.
104
+
105
+ ### Proposal to invoice
106
+
107
+ Only issued or approved proposals convert. View the proposal first, use the conversion tool so the linkage is preserved, and never re-create the invoice manually:
108
+
109
+ ```bash
110
+ every tool call view_proposal --arg identifier=<proposal_id> --json
111
+ every tool call convert_proposal_to_invoice --arg proposal_id=<proposal_id> --yes --json
112
+ ```
113
+
114
+ Conversion creates a linked DRAFT invoice. Review the returned invoice ID, then send only after the user approves:
115
+
116
+ ```bash
117
+ every tool call view_invoice --arg identifier=<invoice_id> --json
118
+ every invoice send <invoice_id> --yes --allow-destructive --json
119
+ ```
120
+
121
+ ### Invoice re-sends
53
122
 
54
- 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.
123
+ `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:
55
124
 
56
- In automation, prefer `--read-only` unless writes were requested.
125
+ ```bash
126
+ every invoice send <invoice_id> --yes --allow-destructive --json
127
+ ```
128
+
129
+ ### Complete money totals
130
+
131
+ For invoice counts or money totals, filter `overdue` and `issued` separately and paginate until every result is fetched. Never total one default page; it gives confidently wrong numbers. Use the full tool so you can increment `offset` by `limit` until a page returns fewer records than the limit:
132
+
133
+ ```bash
134
+ every tool call list_invoices --arg payment_status=overdue --arg limit=100 --arg offset=0 --json
135
+ every tool call list_invoices --arg status=issued --arg limit=100 --arg offset=0 --json
136
+ ```
57
137
 
58
- 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.
138
+ Repeat each command with offsets `100`, `200`, and so on until complete. Report the two filtered totals separately unless the user asks for a different calculation.
59
139
 
60
140
  ## Canonical Workflows
61
141
 
62
- Review pipeline:
142
+ Review the pipeline:
63
143
 
64
144
  ```bash
65
- every deal list --json
66
- every tool call view_deal --arg deal_id=<id> --json
145
+ every tool call get_pipeline_summary --json
146
+ every deal list --stage opportunity --json
147
+ every tool call view_deal --arg deal_id=<deal_id> --json
148
+ every deal move <deal_id> <stage> --yes --json
67
149
  ```
68
150
 
69
- Move a deal:
151
+ Recommend follow-ups before moving anything. Log only outside events the user reports; creation of proposals, invoices, and bookings is already tracked.
152
+
153
+ Invoice flow: find who owes money:
70
154
 
71
155
  ```bash
72
- every deal move <id> <stage> --yes --json
156
+ every tool call list_invoices --arg payment_status=overdue --arg limit=100 --arg offset=0 --json
157
+ every tool call list_invoices --arg status=issued --arg limit=100 --arg offset=0 --json
158
+ every tool call view_invoice --arg identifier=<invoice_id> --json
73
159
  ```
74
160
 
75
- Invoice flow:
161
+ Paginate both filtered lists completely, then report client, invoice number, balance, due date, and totals. Offer to re-send an invoice after confirmation or record a payment only when the user reports it received.
162
+
163
+ Convert an accepted proposal:
76
164
 
77
165
  ```bash
78
- every invoice list --status overdue --json
79
- every tool call create_invoice --args invoice.json --yes --json
80
- every invoice send <id> --yes --allow-destructive --json
166
+ every tool call view_proposal --arg identifier=<proposal_id> --json
167
+ every tool call convert_proposal_to_invoice --arg proposal_id=<proposal_id> --yes --json
168
+ every tool call view_invoice --arg identifier=<invoice_id> --json
169
+ every invoice send <invoice_id> --yes --allow-destructive --json
81
170
  ```
82
171
 
83
- Contacts:
172
+ Stop if the proposal is not issued/approved. Review the linked draft and obtain approval before sending.
173
+
174
+ Intake a new lead:
84
175
 
85
176
  ```bash
86
- every contact list --search "acme" --json
177
+ every contact list --search "person@example.com" --json
178
+ every tool call create_contact --args contact.json --yes --json
179
+ every tool call create_deal --args deal.json --yes --json
87
180
  ```
88
181
 
89
- ## Recovery And Debug
182
+ Search contacts first because email deduplication is real. Create only missing records, then progress the deal as the relationship develops.
183
+
184
+ For a general activity snapshot, combine complete/paginated invoice reads with recent payments and expenses. Use the currency from `business_settings`; if any source is only a partial page, describe it as recent activity rather than a definitive cash position.
185
+
186
+ ## Recovery and Debugging
90
187
 
91
188
  Use these commands when auth, identity, or connectivity is unclear:
92
189
 
@@ -97,6 +194,4 @@ every ping --json
97
194
  every logout && every login
98
195
  ```
99
196
 
100
- ## Staging
101
-
102
197
  Use `--staging` only for Every's staging environment. Treat it as internal/testing only.