@lotstech/cli 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +47 -2
- package/bin/lots.mjs +305 -0
- package/package.json +33 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LotsTech
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
-
#
|
|
1
|
+
# lots
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Every LotsTech app from the command line: LotsInvoice, LotsCRM, LotsSocial, LotsBlog, LotsLink, LotsMail, LotsNotes,
|
|
4
|
+
LotsTeam, LotsBusiness, LotsStore and LotsDirectory. Built for people and for AI agents.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npx @lotstech/cli login invoice
|
|
8
|
+
npx @lotstech/cli invoice tools
|
|
9
|
+
npx @lotstech/cli invoice list_documents --business-id <id> --limit 5
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Or install it once: `npm install -g @lotstech/cli`, then use `lots`.
|
|
13
|
+
|
|
14
|
+
## Sign in
|
|
15
|
+
|
|
16
|
+
- `lots login <app>` opens your browser to sign in to the app. On the approval screen you choose what this sign-in may
|
|
17
|
+
do, and, where the app offers agent seats, whether it acts as you or as one of your agents.
|
|
18
|
+
- `lots login <app> --key` uses a key you made at https://www.lotstech.com/api instead (pass it after `--key`, or on
|
|
19
|
+
standard input). For scripts, set `LOTS_API_KEY` (or `LOTS_INVOICE_KEY`, `LOTS_CRM_KEY` and so on per app).
|
|
20
|
+
- Sign-ins are kept in `~/.config/lots/credentials.json`, readable only by you. `lots logout <app>` removes one.
|
|
21
|
+
- You see and can remove every connection and key at https://www.lotstech.com/api.
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
lots apps # the apps
|
|
27
|
+
lots <app> tools # what you can do here, with each tool's inputs
|
|
28
|
+
lots <app> <tool> --name value ... # run a tool; --json '{...}' for complex inputs
|
|
29
|
+
lots init <app> # commands to add the app's MCP server to Claude Code, Codex and Cursor
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Flags become the tool's inputs: `--business-id 7c..` is `business_id`, numbers and `true`/`false` are read as such, and
|
|
33
|
+
values starting with `{` or `[` as JSON.
|
|
34
|
+
|
|
35
|
+
## For AI agents
|
|
36
|
+
|
|
37
|
+
- Output is JSON. Errors go to standard error as `{"error": {...}}`.
|
|
38
|
+
- Exit codes: `0` ok, `1` error, `2` usage, `3` needs `--confirm`, `4` not signed in, `5` refused (permission, role or
|
|
39
|
+
not allowed for an agent seat).
|
|
40
|
+
- Anything that sends, moves money or deletes needs `--confirm`.
|
|
41
|
+
- Each app's setup guide for agents: `https://api.<app host>/setup.md`, for example https://api.lotsinvoice.com/setup.md
|
|
42
|
+
|
|
43
|
+
The commands come from each app's MCP server (`tools/list`), so they always match what the app offers and what your
|
|
44
|
+
sign-in may do.
|
|
45
|
+
|
|
46
|
+
## License
|
|
47
|
+
|
|
48
|
+
MIT
|
package/bin/lots.mjs
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* lots: one command line for every LotsTech app (task 85a4d04a, founder decisions 29 Nov 2026).
|
|
4
|
+
*
|
|
5
|
+
* It is a thin client of the LotsTech API gateway: every command is an MCP call (tools/list, tools/call) to
|
|
6
|
+
* https://api.<app>/mcp, so the commands always match what the app offers and what this sign-in may do.
|
|
7
|
+
* Sign-in always happens in the browser (OAuth with PKCE, the app's own approval screen, where the person can
|
|
8
|
+
* also choose an agent seat); scripts can use a key instead (LOTS_API_KEY, or `lots login <app> --key`).
|
|
9
|
+
* Built for agents: JSON output, stable exit codes, and --confirm before anything that sends, moves money or deletes.
|
|
10
|
+
* No dependencies; Node 18 or later.
|
|
11
|
+
*/
|
|
12
|
+
import { createServer } from 'node:http'
|
|
13
|
+
import { createHash, randomBytes } from 'node:crypto'
|
|
14
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from 'node:fs'
|
|
15
|
+
import { homedir, platform } from 'node:os'
|
|
16
|
+
import { join } from 'node:path'
|
|
17
|
+
import { spawn } from 'node:child_process'
|
|
18
|
+
|
|
19
|
+
const VERSION = '0.1.0'
|
|
20
|
+
export const APPS = {
|
|
21
|
+
invoice: { key: 'lotsinvoice', name: 'LotsInvoice', domain: 'api.lotsinvoice.com' },
|
|
22
|
+
crm: { key: 'lotscrm', name: 'LotsCRM', domain: 'api.lotscrm.com' },
|
|
23
|
+
social: { key: 'lotssocial', name: 'LotsSocial', domain: 'api.lots.social' },
|
|
24
|
+
blog: { key: 'lotsblog', name: 'LotsBlog', domain: 'api.lots.blog' },
|
|
25
|
+
link: { key: 'lotslink', name: 'LotsLink', domain: 'api.lots.link' },
|
|
26
|
+
mail: { key: 'lotsmail', name: 'LotsMail', domain: 'api.lotsmail.to' },
|
|
27
|
+
notes: { key: 'lotsnotes', name: 'LotsNotes', domain: 'api.lotsnotes.com' },
|
|
28
|
+
team: { key: 'lotsteam', name: 'LotsTeam', domain: 'api.lots.team' },
|
|
29
|
+
business: { key: 'lotsbusiness', name: 'LotsBusiness', domain: 'api.lots.business' },
|
|
30
|
+
store: { key: 'lotscommerce', name: 'LotsStore', domain: 'api.lotsstore.app' },
|
|
31
|
+
directory: { key: 'lotsdirectory', name: 'LotsDirectory', domain: 'api.lots.directory' },
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Exit codes: 0 ok, 1 error, 2 usage, 3 needs --confirm, 4 not signed in, 5 refused (permission, role, not allowed).
|
|
35
|
+
const EXIT = { OK: 0, ERROR: 1, USAGE: 2, CONFIRM: 3, AUTH: 4, REFUSED: 5 }
|
|
36
|
+
const RISKY = new Set(['send', 'money', 'delete'])
|
|
37
|
+
|
|
38
|
+
const CONFIG_DIR = process.env.LOTS_CONFIG_DIR || join(homedir(), '.config', 'lots')
|
|
39
|
+
const CREDENTIALS = join(CONFIG_DIR, 'credentials.json')
|
|
40
|
+
|
|
41
|
+
function out(value, code = EXIT.OK) {
|
|
42
|
+
process.stdout.write((typeof value === 'string' ? value : JSON.stringify(value, null, process.stdout.isTTY ? 2 : 0)) + '\n')
|
|
43
|
+
process.exit(code)
|
|
44
|
+
}
|
|
45
|
+
function fail(message, code = EXIT.ERROR, extra = {}) {
|
|
46
|
+
process.stderr.write(JSON.stringify({ error: { message, ...extra } }) + '\n')
|
|
47
|
+
process.exit(code)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readCredentials() {
|
|
51
|
+
try { return JSON.parse(readFileSync(CREDENTIALS, 'utf8')) } catch { return {} }
|
|
52
|
+
}
|
|
53
|
+
function writeCredentials(all) {
|
|
54
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 })
|
|
55
|
+
writeFileSync(CREDENTIALS, JSON.stringify(all, null, 2), { mode: 0o600 })
|
|
56
|
+
chmodSync(CREDENTIALS, 0o600)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function parseArgs(argv) {
|
|
60
|
+
const positional = []
|
|
61
|
+
const flags = {}
|
|
62
|
+
for (let i = 0; i < argv.length; i++) {
|
|
63
|
+
const a = argv[i]
|
|
64
|
+
if (a.startsWith('--')) {
|
|
65
|
+
const [k, inline] = a.slice(2).split(/=(.*)/s)
|
|
66
|
+
if (inline !== undefined) flags[k] = inline
|
|
67
|
+
else if (i + 1 < argv.length && !argv[i + 1].startsWith('--')) flags[k] = argv[++i]
|
|
68
|
+
else flags[k] = true
|
|
69
|
+
} else positional.push(a)
|
|
70
|
+
}
|
|
71
|
+
return { positional, flags }
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** --name value pairs to tool arguments: numbers and true/false and JSON values are understood; --json '{...}' merges. */
|
|
75
|
+
export function toolArguments(flags) {
|
|
76
|
+
const skip = new Set(['json', 'confirm', 'pretty'])
|
|
77
|
+
const args = {}
|
|
78
|
+
if (typeof flags.json === 'string') {
|
|
79
|
+
try { Object.assign(args, JSON.parse(flags.json)) } catch { fail('--json is not valid JSON.', EXIT.USAGE) }
|
|
80
|
+
}
|
|
81
|
+
for (const [k, v] of Object.entries(flags)) {
|
|
82
|
+
if (skip.has(k)) continue
|
|
83
|
+
const name = k.replace(/-/g, '_')
|
|
84
|
+
if (v === true) { args[name] = true; continue }
|
|
85
|
+
const s = String(v)
|
|
86
|
+
if (/^(true|false)$/.test(s)) args[name] = s === 'true'
|
|
87
|
+
else if (/^-?\d+(\.\d+)?$/.test(s) && !/^0\d/.test(s)) args[name] = Number(s)
|
|
88
|
+
else if (/^[[{]/.test(s)) { try { args[name] = JSON.parse(s) } catch { args[name] = s } }
|
|
89
|
+
else args[name] = s
|
|
90
|
+
}
|
|
91
|
+
return args
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function appOf(name) {
|
|
95
|
+
const app = APPS[name]
|
|
96
|
+
if (!app) fail(`Unknown app "${name}". Apps: ${Object.keys(APPS).join(', ')}.`, EXIT.USAGE)
|
|
97
|
+
return app
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ---------------------------------------------------------------------------------------------
|
|
101
|
+
// Sign-in
|
|
102
|
+
// ---------------------------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
function openBrowser(url) {
|
|
105
|
+
const cmd = platform() === 'darwin' ? 'open' : platform() === 'win32' ? 'cmd' : 'xdg-open'
|
|
106
|
+
const args = platform() === 'win32' ? ['/c', 'start', '', url] : [url]
|
|
107
|
+
try { spawn(cmd, args, { stdio: 'ignore', detached: true }).unref() } catch { /* the URL is printed too */ }
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function login(app, flags) {
|
|
111
|
+
const all = readCredentials()
|
|
112
|
+
if (flags.key) {
|
|
113
|
+
const key = typeof flags.key === 'string' ? flags.key : process.env.LOTS_API_KEY || readFileSync(0, 'utf8').trim()
|
|
114
|
+
if (!/^sk_(live|agent|proj)_/.test(key || '')) fail('That is not a LotsTech key (sk_live_, sk_agent_ or sk_proj_).', EXIT.USAGE)
|
|
115
|
+
all[app.key] = { type: 'key', key, saved_at: new Date().toISOString() }
|
|
116
|
+
writeCredentials(all)
|
|
117
|
+
return out({ signed_in: app.name, with: 'key' })
|
|
118
|
+
}
|
|
119
|
+
const base = `https://${app.domain}`
|
|
120
|
+
const verifier = randomBytes(32).toString('base64url')
|
|
121
|
+
const challenge = createHash('sha256').update(verifier).digest('base64url')
|
|
122
|
+
const state = randomBytes(16).toString('base64url')
|
|
123
|
+
|
|
124
|
+
const server = createServer()
|
|
125
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
|
|
126
|
+
const port = server.address().port
|
|
127
|
+
const redirectUri = `http://127.0.0.1:${port}/callback`
|
|
128
|
+
|
|
129
|
+
const reg = await fetch(`${base}/api/oauth/register`, {
|
|
130
|
+
method: 'POST', headers: { 'content-type': 'application/json' },
|
|
131
|
+
body: JSON.stringify({ client_name: 'LotsTech CLI', redirect_uris: [redirectUri], grant_types: ['authorization_code', 'refresh_token'], response_types: ['code'], token_endpoint_auth_method: 'none' }),
|
|
132
|
+
}).then((r) => r.json()).catch(() => null)
|
|
133
|
+
if (!reg?.client_id) { server.close(); fail('Could not start the sign-in. Try again.') }
|
|
134
|
+
|
|
135
|
+
const auth = new URL(`${base}/api/oauth/authorize`)
|
|
136
|
+
auth.search = new URLSearchParams({
|
|
137
|
+
response_type: 'code', client_id: reg.client_id, redirect_uri: redirectUri, state,
|
|
138
|
+
code_challenge: challenge, code_challenge_method: 'S256', resource: `${base}/mcp`,
|
|
139
|
+
scope: 'mcp:read mcp:write mcp:send mcp:money mcp:delete offline_access',
|
|
140
|
+
}).toString()
|
|
141
|
+
|
|
142
|
+
process.stderr.write(`Opening your browser to sign in to ${app.name}. If it does not open, visit:\n${auth}\n`)
|
|
143
|
+
openBrowser(auth.toString())
|
|
144
|
+
|
|
145
|
+
const code = await new Promise((resolve) => {
|
|
146
|
+
const timer = setTimeout(() => { server.close(); fail('Sign-in timed out after 5 minutes.', EXIT.AUTH) }, 300_000)
|
|
147
|
+
server.on('request', (req, res) => {
|
|
148
|
+
const url = new URL(req.url, redirectUri)
|
|
149
|
+
if (url.pathname !== '/callback') { res.writeHead(404).end(); return }
|
|
150
|
+
const ok = url.searchParams.get('state') === state && url.searchParams.get('code')
|
|
151
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' })
|
|
152
|
+
res.end(ok ? '<p style="font:16px system-ui">Signed in. You can close this tab and go back to the terminal.</p>' : '<p style="font:16px system-ui">Sign-in was not completed.</p>')
|
|
153
|
+
clearTimeout(timer)
|
|
154
|
+
server.close()
|
|
155
|
+
if (!ok) fail(url.searchParams.get('error_description') || 'Sign-in was not completed.', EXIT.AUTH)
|
|
156
|
+
resolve(url.searchParams.get('code'))
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const token = await fetch(`${base}/api/oauth/token`, {
|
|
161
|
+
method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
162
|
+
body: new URLSearchParams({ grant_type: 'authorization_code', code, redirect_uri: redirectUri, client_id: reg.client_id, code_verifier: verifier, resource: `${base}/mcp` }),
|
|
163
|
+
}).then((r) => r.json()).catch(() => null)
|
|
164
|
+
if (!token?.access_token) fail(token?.error_description || 'Could not finish the sign-in.', EXIT.AUTH)
|
|
165
|
+
all[app.key] = {
|
|
166
|
+
type: 'oauth', client_id: reg.client_id, access_token: token.access_token, refresh_token: token.refresh_token || null,
|
|
167
|
+
expires_at: Date.now() + (Number(token.expires_in) || 3600) * 1000, scope: token.scope || null, saved_at: new Date().toISOString(),
|
|
168
|
+
}
|
|
169
|
+
writeCredentials(all)
|
|
170
|
+
out({ signed_in: app.name, with: 'browser', can: (token.scope || '').split(' ').filter((s) => s.startsWith('mcp:')).map((s) => s.slice(4)) })
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function bearer(app) {
|
|
174
|
+
const envKey = process.env[`LOTS_${app.key.replace(/^lots/, '').toUpperCase()}_KEY`] || process.env.LOTS_API_KEY
|
|
175
|
+
if (envKey) return envKey
|
|
176
|
+
const all = readCredentials()
|
|
177
|
+
const c = all[app.key]
|
|
178
|
+
if (!c) fail(`Not signed in to ${app.name}. Run: lots login ${Object.keys(APPS).find((k) => APPS[k] === app)}`, EXIT.AUTH)
|
|
179
|
+
if (c.type === 'key') return c.key
|
|
180
|
+
if (c.expires_at > Date.now() + 30_000) return c.access_token
|
|
181
|
+
if (!c.refresh_token) fail(`Your ${app.name} sign-in ended. Run lots login again.`, EXIT.AUTH)
|
|
182
|
+
const token = await fetch(`https://${app.domain}/api/oauth/token`, {
|
|
183
|
+
method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
184
|
+
body: new URLSearchParams({ grant_type: 'refresh_token', refresh_token: c.refresh_token, client_id: c.client_id, resource: `https://${app.domain}/mcp` }),
|
|
185
|
+
}).then((r) => r.json()).catch(() => null)
|
|
186
|
+
if (!token?.access_token) fail(`Your ${app.name} sign-in ended. Run lots login again.`, EXIT.AUTH)
|
|
187
|
+
all[app.key] = { ...c, access_token: token.access_token, refresh_token: token.refresh_token || c.refresh_token, expires_at: Date.now() + (Number(token.expires_in) || 3600) * 1000 }
|
|
188
|
+
writeCredentials(all)
|
|
189
|
+
return token.access_token
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// ---------------------------------------------------------------------------------------------
|
|
193
|
+
// MCP calls
|
|
194
|
+
// ---------------------------------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
/** One JSON-RPC message from a JSON or event-stream answer. */
|
|
197
|
+
export function rpcResult(text) {
|
|
198
|
+
const trimmed = text.trim()
|
|
199
|
+
if (trimmed.startsWith('{')) return JSON.parse(trimmed)
|
|
200
|
+
const data = trimmed.split('\n').filter((l) => l.startsWith('data:')).map((l) => l.slice(5).trim()).join('')
|
|
201
|
+
return JSON.parse(data)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function rpc(app, method, params) {
|
|
205
|
+
const token = await bearer(app)
|
|
206
|
+
const res = await fetch(`https://${app.domain}/mcp`, {
|
|
207
|
+
method: 'POST',
|
|
208
|
+
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json', accept: 'application/json, text/event-stream', 'user-agent': `lots-cli/${VERSION}` },
|
|
209
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method, params }),
|
|
210
|
+
}).catch(() => null)
|
|
211
|
+
if (!res) fail(`Could not reach ${app.name}. Check your connection.`)
|
|
212
|
+
const text = await res.text()
|
|
213
|
+
let msg
|
|
214
|
+
try { msg = rpcResult(text) } catch { fail(`${app.name} answered ${res.status}.`) }
|
|
215
|
+
if (res.status === 401) fail(msg?.error?.message || `Not signed in to ${app.name}.`, EXIT.AUTH)
|
|
216
|
+
if (msg.error) fail(msg.error.message, res.status === 403 ? EXIT.REFUSED : EXIT.ERROR, { code: msg.error.data?.code ?? null })
|
|
217
|
+
return msg.result
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function permissions(app) {
|
|
221
|
+
const r = await fetch(`https://${app.domain}/tools.json`).then((x) => x.json()).catch(() => null)
|
|
222
|
+
return new Map((r?.tools || []).map((t) => [t.name, t.permission_max || t.permission]))
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function callTool(app, tool, flags) {
|
|
226
|
+
const perm = (await permissions(app)).get(tool)
|
|
227
|
+
if (perm && RISKY.has(perm) && !flags.confirm) {
|
|
228
|
+
fail(`${tool} can ${perm === 'money' ? 'move money' : perm === 'send' ? 'send or publish' : 'delete'}. Run it again with --confirm.`, EXIT.CONFIRM, { permission: perm })
|
|
229
|
+
}
|
|
230
|
+
const result = await rpc(app, 'tools/call', { name: tool, arguments: toolArguments(flags) })
|
|
231
|
+
const text = (result?.content || []).filter((c) => c.type === 'text').map((c) => c.text).join('\n')
|
|
232
|
+
let body
|
|
233
|
+
try { body = JSON.parse(text) } catch { body = text }
|
|
234
|
+
if (result?.isError) {
|
|
235
|
+
const code = body?.error?.code
|
|
236
|
+
process.stderr.write(JSON.stringify({ error: body?.error || { message: String(body) } }) + '\n')
|
|
237
|
+
process.exit(['INSUFFICIENT_SCOPE', 'ROLE_NOT_ALLOWED', 'AGENT_NOT_ALLOWED', 'NOT_AVAILABLE_IN_THIS_APP', 'FORBIDDEN'].includes(code) ? EXIT.REFUSED : EXIT.ERROR)
|
|
238
|
+
}
|
|
239
|
+
out(body)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// ---------------------------------------------------------------------------------------------
|
|
243
|
+
// Commands
|
|
244
|
+
// ---------------------------------------------------------------------------------------------
|
|
245
|
+
|
|
246
|
+
const HELP = `lots ${VERSION}: every LotsTech app from the command line.
|
|
247
|
+
|
|
248
|
+
Usage
|
|
249
|
+
lots apps The apps
|
|
250
|
+
lots login <app> Sign in in the browser (you can choose an agent seat there)
|
|
251
|
+
lots login <app> --key [sk_...] Use a key instead (or LOTS_API_KEY; reads stdin when no value)
|
|
252
|
+
lots logout <app>
|
|
253
|
+
lots whoami Where you are signed in
|
|
254
|
+
lots <app> tools What you can do (names, descriptions, inputs)
|
|
255
|
+
lots <app> <tool> [--name value ...] [--json '{...}'] [--confirm]
|
|
256
|
+
lots init <app> Commands to add the app's MCP server to Claude Code, Cursor and Codex
|
|
257
|
+
|
|
258
|
+
Examples
|
|
259
|
+
lots login invoice
|
|
260
|
+
lots invoice list_documents --business-id 7c... --limit 5
|
|
261
|
+
lots invoice send_document --business-id 7c... --document-id 9d... --confirm
|
|
262
|
+
|
|
263
|
+
Output is JSON. Exit codes: 0 ok, 1 error, 2 usage, 3 needs --confirm, 4 not signed in, 5 refused.
|
|
264
|
+
Docs for agents: https://<app api host>/setup.md`
|
|
265
|
+
|
|
266
|
+
async function main() {
|
|
267
|
+
const { positional, flags } = parseArgs(process.argv.slice(2))
|
|
268
|
+
const [first, second] = positional
|
|
269
|
+
if (!first || first === 'help' || flags.help) out(HELP)
|
|
270
|
+
if (first === 'version' || flags.version) out(VERSION)
|
|
271
|
+
if (first === 'apps') out(Object.entries(APPS).map(([cmd, a]) => ({ command: cmd, app: a.name, mcp: `https://${a.domain}/mcp` })))
|
|
272
|
+
if (first === 'whoami') {
|
|
273
|
+
const all = readCredentials()
|
|
274
|
+
out(Object.entries(APPS).filter(([, a]) => all[a.key]).map(([cmd, a]) => ({ app: a.name, command: cmd, with: all[a.key].type, since: all[a.key].saved_at })))
|
|
275
|
+
}
|
|
276
|
+
if (first === 'login') return login(appOf(second), flags)
|
|
277
|
+
if (first === 'logout') {
|
|
278
|
+
const app = appOf(second)
|
|
279
|
+
const all = readCredentials()
|
|
280
|
+
delete all[app.key]
|
|
281
|
+
writeCredentials(all)
|
|
282
|
+
out({ signed_out: app.name })
|
|
283
|
+
}
|
|
284
|
+
if (first === 'init') {
|
|
285
|
+
const app = appOf(second)
|
|
286
|
+
const mcp = `https://${app.domain}/mcp`
|
|
287
|
+
out({
|
|
288
|
+
claude_code: `claude mcp add --transport http ${app.key} ${mcp}`,
|
|
289
|
+
codex: `codex mcp add ${app.key} --url ${mcp}`,
|
|
290
|
+
cursor: `cursor://anysphere.cursor-deeplink/mcp/install?name=${encodeURIComponent(app.name)}&config=${encodeURIComponent(Buffer.from(JSON.stringify({ url: mcp })).toString('base64'))}`,
|
|
291
|
+
setup: `https://${app.domain}/setup.md`,
|
|
292
|
+
})
|
|
293
|
+
}
|
|
294
|
+
const app = appOf(first)
|
|
295
|
+
if (!second) fail(`Say what to do: lots ${first} tools, or lots ${first} <tool> ...`, EXIT.USAGE)
|
|
296
|
+
if (second === 'tools') {
|
|
297
|
+
const result = await rpc(app, 'tools/list', {})
|
|
298
|
+
out((result?.tools || []).map((t) => ({ name: t.name, description: t.description, inputs: t.inputSchema?.properties ? Object.keys(t.inputSchema.properties) : [], required: t.inputSchema?.required || [] })))
|
|
299
|
+
}
|
|
300
|
+
return callTool(app, second, flags)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith('/lots') || process.argv[1]?.endsWith('lots.mjs')) {
|
|
304
|
+
main().catch((error) => fail(error?.message || String(error)))
|
|
305
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lotstech/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Every LotsTech app from the command line: invoices, CRM, social, blog, links, mail, notes and more. Built for people and AI agents.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/sivaguruayyadurai/lots-cli.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://www.lotstech.com/mcp",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"bin": {
|
|
13
|
+
"lots": "bin/lots.mjs"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"bin",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "node --test test/cli.test.mjs",
|
|
25
|
+
"check": "node --check bin/lots.mjs"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"lotstech",
|
|
29
|
+
"mcp",
|
|
30
|
+
"cli",
|
|
31
|
+
"ai-agent",
|
|
32
|
+
"invoicing",
|
|
33
|
+
"crm"
|
|
34
|
+
]
|
|
35
|
+
}
|