@figs-so/cli 0.1.6 → 0.1.7

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.
Files changed (3) hide show
  1. package/README.md +3 -0
  2. package/figs.mjs +75 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -31,5 +31,8 @@ The full, always-current guide + `agent.json` schema is served at **`<endpoint>/
31
31
  | `figs doctor` | validate `.figs/` against the contract |
32
32
  | `figs push` | one-way publish of `.figs/` |
33
33
  | `figs version` | print version + check for updates |
34
+ | `figs help [<command>]` | usage (bare `figs` shows it too) |
35
+
36
+ Global: `-h` / `--help` on any command (or `figs help <command>`), `-v` / `--version` for the version. Unknown commands exit non-zero.
34
37
 
35
38
  Override the endpoint with `FIGS_ENDPOINT` (e.g. `http://localhost:3000` for local dev).
package/figs.mjs CHANGED
@@ -12,9 +12,11 @@
12
12
  * figs doctor validate .figs/ against the contract before pushing
13
13
  * figs push one-way push the .figs/ spine to the ingest endpoint
14
14
  * figs version print the CLI version (and check for updates)
15
+ * figs help [<command>] usage; `-h`/`--help` on any command, `-v` for version
15
16
  *
16
17
  * Designed to be driven by an agent: non-interactive, clear output, `--json`
17
- * on read commands, and errors that say what to do next.
18
+ * on read commands, `-h`/`--help`/`help` everywhere, and errors that say what to
19
+ * do next. Bare `figs` prints help; unknown commands exit non-zero.
18
20
  *
19
21
  * Auth is the *user* (a token, configured once per machine). Identity is the
20
22
  * *agent* — a UUID generated by `init`, stored in the committed, non-secret
@@ -33,7 +35,7 @@ import { homedir } from "node:os"
33
35
  import { join } from "node:path"
34
36
  import { randomUUID } from "node:crypto"
35
37
 
36
- const VERSION = "0.1.6"
38
+ const VERSION = "0.1.7"
37
39
  // Going-forward default; override with FIGS_ENDPOINT or .figs/config.json endpoint
38
40
  // (e.g. FIGS_ENDPOINT=http://localhost:3000 for local dev).
39
41
  const DEFAULT_ENDPOINT = "https://app.figs.so"
@@ -41,8 +43,39 @@ const DEFAULT_ENDPOINT = "https://app.figs.so"
41
43
  const repoDir = join(process.cwd(), ".figs")
42
44
  const globalDir = join(homedir(), ".figs")
43
45
  const globalCreds = join(globalDir, "credentials.json")
44
- const cmd = process.argv[2] ?? "status"
46
+ const cmd = process.argv[2] ?? "help"
45
47
  const JSON_OUT = process.argv.includes("--json")
48
+ const WANTS_HELP = process.argv.slice(2).some((a) => a === "-h" || a === "--help")
49
+
50
+ /** Command registry — single source for dispatch + `figs help`. */
51
+ const COMMANDS = {
52
+ status: { args: "[--json]", desc: "show login / workspace / agent state" },
53
+ login: {
54
+ args: "[<token>]",
55
+ desc: "log in — browser device-flow, or save a pasted token",
56
+ more: [
57
+ "no arg → device flow: a human approves in a browser (you never see the token).",
58
+ "<token> → save a token you already have to ~/.figs/credentials.json.",
59
+ ],
60
+ },
61
+ logout: { args: "", desc: "remove the locally-saved token (~/.figs/credentials.json)" },
62
+ workspaces: { args: "[--json]", desc: "list your workspaces (read-only; shows the slug)" },
63
+ init: {
64
+ args: "--workspace <slug-or-id> [--endpoint <url>]",
65
+ desc: "set up .figs/ here (identity UUID + config + pointer GUIDE.md)",
66
+ more: [
67
+ "--workspace takes a slug (resolved to its UUID) or a raw UUID — get it from `figs workspaces`.",
68
+ ],
69
+ },
70
+ doctor: { args: "", desc: "validate .figs/ against the live contract before pushing" },
71
+ push: {
72
+ args: "",
73
+ desc: "publish .figs/ — spine to /api/ingest, artifacts to /api/artifacts",
74
+ more: ["Idempotent (records fold by id). Exits non-zero if an artifact upload is rejected."],
75
+ },
76
+ version: { args: "", desc: "print the CLI version and check for updates" },
77
+ help: { args: "[<command>]", desc: "show this help, or detailed help for one command" },
78
+ }
46
79
 
47
80
  function die(msg) {
48
81
  console.error(`figs: ${msg}`)
@@ -144,20 +177,51 @@ async function checkVersion({ force = false, hardFail = false } = {}) {
144
177
  }
145
178
  }
146
179
 
147
- if (cmd === "login") await login(process.argv[3])
180
+ /** `figs help [cmd]` top-level usage, or one command's detail. */
181
+ function printHelp(name) {
182
+ const pad = 36
183
+ if (name && name !== "-h" && name !== "--help") {
184
+ const c = COMMANDS[name]
185
+ if (!c) {
186
+ console.log(`figs: no such command "${name}"\n`)
187
+ return printHelp()
188
+ }
189
+ console.log(`Usage: figs ${name}${c.args ? " " + c.args : ""}\n`)
190
+ console.log(` ${c.desc}`)
191
+ if (c.more) for (const line of c.more) console.log(` ${line}`)
192
+ return
193
+ }
194
+ console.log("figs — publish your AI agent's state to Figs (https://figs.so)\n")
195
+ console.log("Usage: figs <command> [options]\n")
196
+ console.log("Commands:")
197
+ for (const [n, c] of Object.entries(COMMANDS)) {
198
+ console.log(` ${`${n} ${c.args}`.trim().padEnd(pad)} ${c.desc}`)
199
+ }
200
+ console.log("\nGlobal flags:")
201
+ console.log(` ${"-h, --help".padEnd(pad)} show help (or \`figs help <command>\`)`)
202
+ console.log(` ${"-v, --version".padEnd(pad)} print the CLI version`)
203
+ console.log("\nEnvironment:")
204
+ console.log(` ${"FIGS_ENDPOINT".padEnd(pad)} override the API endpoint (e.g. http://localhost:3000)`)
205
+ console.log(` ${"FIGS_TOKEN".padEnd(pad)} use this token instead of ~/.figs/credentials.json`)
206
+ console.log(`\nEndpoint: ${resolveEndpoint()}`)
207
+ console.log(`Guide: ${resolveEndpoint()}/llms.txt`)
208
+ }
209
+
210
+ if (cmd === "help" || cmd === "-h" || cmd === "--help") printHelp(process.argv[3])
211
+ else if (cmd === "version" || cmd === "--version" || cmd === "-v" || cmd === "-V") {
212
+ console.log(VERSION)
213
+ await checkVersion({ force: true })
214
+ } else if (WANTS_HELP) printHelp(cmd)
215
+ else if (cmd === "login") await login(process.argv[3])
148
216
  else if (cmd === "logout") logout()
149
217
  else if (cmd === "status") await status()
150
218
  else if (cmd === "workspaces") await workspaces()
151
219
  else if (cmd === "init") await init()
152
220
  else if (cmd === "doctor") await doctor()
153
221
  else if (cmd === "push") await push()
154
- else if (cmd === "version" || cmd === "--version") {
155
- console.log(VERSION)
156
- await checkVersion({ force: true })
157
- } else {
158
- die(
159
- `unknown command "${cmd}" — try: status, login, logout, workspaces, init, doctor, push`,
160
- )
222
+ else {
223
+ console.error(`figs: unknown command "${cmd}" — run \`figs help\` for usage`)
224
+ process.exit(1)
161
225
  }
162
226
 
163
227
  function sleep(ms) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figs-so/cli",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Figs CLI — publish your AI agent's state to Figs (figs.so). Run by the agent.",
5
5
  "type": "module",
6
6
  "bin": {