@learncard/cli 3.6.8 → 4.0.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.
Files changed (72) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +36 -12
  3. package/dist/index.js +6673 -2038
  4. package/package.json +27 -15
  5. package/project.json +0 -42
  6. package/rollup.config.js +0 -34
  7. package/scripts/embed-snippets.ts +0 -47
  8. package/src/auth-grant.test.ts +0 -54
  9. package/src/auth-grant.ts +0 -34
  10. package/src/clr/validate.test.ts +0 -65
  11. package/src/clr/validate.ts +0 -242
  12. package/src/clr.ts +0 -119
  13. package/src/consent-contract.ts +0 -116
  14. package/src/demo-inbox-refresh.test.ts +0 -737
  15. package/src/demo-inbox-refresh.ts +0 -804
  16. package/src/demo-refresh-command.test.ts +0 -57
  17. package/src/demo-refresh-command.ts +0 -22
  18. package/src/demo-refresh-ui.test.ts +0 -66
  19. package/src/demo-refresh-ui.ts +0 -65
  20. package/src/demo-refresh.test.ts +0 -140
  21. package/src/demo-refresh.ts +0 -309
  22. package/src/doctor/checks.test.ts +0 -448
  23. package/src/doctor/checks.ts +0 -497
  24. package/src/doctor.test.ts +0 -67
  25. package/src/doctor.ts +0 -118
  26. package/src/embed.ts +0 -102
  27. package/src/inbox.test.ts +0 -257
  28. package/src/inbox.ts +0 -221
  29. package/src/index.tsx +0 -876
  30. package/src/init.ts +0 -26
  31. package/src/open.test.ts +0 -40
  32. package/src/open.ts +0 -186
  33. package/src/org/apply.test.ts +0 -1108
  34. package/src/org/apply.ts +0 -924
  35. package/src/org/branding.test.ts +0 -60
  36. package/src/org/diff.ts +0 -14
  37. package/src/org/load.ts +0 -50
  38. package/src/org/schema.test.ts +0 -256
  39. package/src/org/schema.ts +0 -216
  40. package/src/org.ts +0 -124
  41. package/src/out.test.ts +0 -40
  42. package/src/out.ts +0 -16
  43. package/src/phase-two.test.ts +0 -154
  44. package/src/project.test.ts +0 -232
  45. package/src/project.ts +0 -489
  46. package/src/promote.test.ts +0 -142
  47. package/src/promote.ts +0 -202
  48. package/src/random.ts +0 -3
  49. package/src/refresh.test.ts +0 -86
  50. package/src/refresh.ts +0 -93
  51. package/src/replHelpers.test.ts +0 -80
  52. package/src/replHelpers.ts +0 -45
  53. package/src/revoke.test.ts +0 -29
  54. package/src/revoke.ts +0 -65
  55. package/src/send-template.test.ts +0 -20
  56. package/src/send.test.ts +0 -321
  57. package/src/send.ts +0 -373
  58. package/src/setup-signing.test.ts +0 -62
  59. package/src/setup-signing.ts +0 -185
  60. package/src/snippet-files.ts +0 -16
  61. package/src/status.test.ts +0 -33
  62. package/src/status.ts +0 -94
  63. package/src/token.test.ts +0 -28
  64. package/src/token.ts +0 -139
  65. package/src/types.d.ts +0 -17
  66. package/src/verify.test.ts +0 -35
  67. package/src/verify.ts +0 -66
  68. package/src/webhook.ts +0 -247
  69. package/src/whoami.test.ts +0 -67
  70. package/src/whoami.ts +0 -129
  71. package/tsconfig.json +0 -38
  72. package/vitest.config.ts +0 -8
package/CHANGELOG.md CHANGED
@@ -1,5 +1,72 @@
1
1
  # @learncard/cli
2
2
 
3
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#1908](https://github.com/learningeconomy/LearnCard/pull/1908) [`e580fe754ca4697a52c4642faac056c31b0280b9`](https://github.com/learningeconomy/LearnCard/commit/e580fe754ca4697a52c4642faac056c31b0280b9) Thanks [@Custard7](https://github.com/Custard7)! - Make the CLI safer and more predictable for scripts and AI agents.
8
+
9
+ **Upgrading from 3.x.** This release is a major version because scripts that parse CLI output or rely on the old behaviour may break:
10
+
11
+ - `verify --json` prints one line, `{ ok, command: "verify", verified, result }`. Read `verified` and `result` instead of the raw result.
12
+ - `token --json` no longer includes `token`. Read `API_TOKEN` from the `.env` named in `tokenSavedTo`, or pass `--show-secret`.
13
+ - `open --json --url-fragment` returns the URL without `#seed=`. Pass `--show-secret` for the old URL.
14
+ - Read-only commands (`whoami`, `status`, `inbox list`, `refresh history`, `doctor`, `revoke`, `token --list`/`--revoke`, `open`) fail with `NO_IDENTITY` in a folder with no identity instead of creating one. Run `init` (or `org apply`) first.
15
+ - Invalid flag values that used to be accepted are now rejected, as described below.
16
+ - Node 20 or later is required (`engines.node >= 20`).
17
+
18
+ **All changes:**
19
+
20
+ - `revoke`, `token --list` and `token --revoke` no longer create a seed, `.env` or profile in an empty folder. All commands that only read or act on an existing identity (`whoami`, `status`, `inbox list`, `refresh history`, `doctor`, `revoke`, `token --list`, `token --revoke`, `open`, `clr validate --dry-run-sign`) now fail in such a folder with `code: "NO_IDENTITY"` and the same hint to run `init`, and no longer write `NETWORK_URL` to `.env`. When `init`, `send`, `org apply` or another setup command creates a new identity, it says so on stderr and adds `identityCreated: { profileId, did, network }` to the `--json` result.
21
+ - `--profile-id`, `send --guardian-email` and `send --webhook-url` are checked before an identity is created, so a malformed value no longer leaves a broken `.env` behind.
22
+ - Flags and arguments are checked before anything is written or sent: an invalid recipient, `--network`, `--expires`, `--scope`, `status --limit`/`--event`, `inbox list --status`/`--limit`, or `setup-signing --endpoint`/`--did`.
23
+ - `--network` accepts `production`, `prod`, `staging`, `local` or a tRPC URL on every command (`--network production` used to fail with "Invalid URL" everywhere except `promote`).
24
+ - Every command except `repl` accepts `-y`, `--json` and `--network`. Commands that don't use a flag accept and ignore it.
25
+ - `--json` errors are now `{ ok: false, command, error, code, hint?, detail? }`. `detail` holds the full message when it spans several lines. With `--json`, usage errors (unknown command or option, missing argument, `--json` placed before the command) also print one JSON line with `code: "USAGE"`.
26
+ - `--json` errors are `code: "USAGE"` when a required value is missing in a non-interactive run or a flag value is invalid. If a command created a new identity before it failed, the error envelope also carries `identityCreated`. `--json` never prompts, so stdout holds only the JSON line even at a terminal without `-y`.
27
+ - **Breaking for scripts:** `verify --json` now prints one line, `{ ok: true, command: "verify", verified, result }`, instead of the raw result spread over several lines. It still exits 1 when the credential does not verify.
28
+ - **Breaking for scripts:** `token --json` no longer includes the raw `token` unless you pass `--show-secret`. It adds `tokenSavedTo`, the `.env` path where the token is saved as `API_TOKEN`.
29
+ - **Breaking for scripts:** `open --json --url-fragment` returns the URL without the `#seed=` fragment, plus `seedInFragment: true`, unless you pass `--show-secret`. `open` only copies the seed to the clipboard when stdout is a terminal; piped or `--json` runs (e.g. `$(cli open | tail -1)`) no longer copy it and no longer wait 60 seconds to clear the clipboard.
30
+ - Human-mode `webhook` now stops after `--timeout` (default 60 seconds) when stdin is not a terminal, as `--json` already did.
31
+ - Stricter flag validation rejects values that used to be accepted: `webhook --timeout`, `token --expires` (a positive number of days) and `status --limit` (a whole number from 1 to 100).
32
+ - The package installs a `learncard` binary as well as the existing `cli`. It now declares `engines.node >= 20` and publishes only `dist`, `examples` and the docs.
33
+
34
+ ### Minor Changes
35
+
36
+ - [#1911](https://github.com/learningeconomy/LearnCard/pull/1911) [`076f2548d018060a4a744305167e387ed8380ec1`](https://github.com/learningeconomy/LearnCard/commit/076f2548d018060a4a744305167e387ed8380ec1) Thanks [@Custard7](https://github.com/Custard7)! - Help coding agents discover and use the whole LearnCard surface from the CLI.
37
+
38
+ - `commands [name...] [--json]` prints a manifest of every command, built from the CLI's own command tree: arguments, options, effect (`read`, `write`, `local` or `varies`), whether it can create an identity or connect, output fields and examples, plus global flags, environment variables, error codes and docs links. Each command's `--help` now ends with examples.
39
+ - `capabilities [id] [--json]` maps what LearnCard can do to the CLI command, SDK method, Network REST route and docs page for each.
40
+ - `call <method>` calls any `learnCard.invoke` SDK method as the folder's identity (`--args <json|@file|->`, `--as`, `--list`, `--describe`, `--dry-run`). `--describe` shows a method's TypeScript signature, parameters, the flags a call needs and an example, offline; `--args` also takes a bare non-JSON value such as an `lc:` URI as one string. Methods that can change data need `--write`, and methods that return secrets need `--show-secret`. On-chain methods (`transferTokens`) also need `--chain <name>`, and the wallet's chain is checked before anything is submitted; mainnet is used only when named. It never creates an identity, read calls don't register DIDs with LearnCloud, and results are converted to plain JSON.
41
+ - `api <METHOD> <path>` calls the LearnCard Network REST API with `LEARNCARD_API_KEY` or the folder's `API_TOKEN` (`--data`, `--query`, `--timeout`, `--dry-run`, `--spec [--fetch]`). Methods other than `GET`/`HEAD` need `--write`, as do the `GET` routes that change state (`/challenges`, `/inbox/guardian-approval/{token}`) however the path is spelled. The token is never printed, and non-2xx responses fail with code `HTTP_<status>`.
42
+ - `skill install` writes the LearnCard skill for coding agents to `.claude/skills/`, `.cursor/rules/` or `.agents/skills/` (`--target`, `--dir`, `--force`, `--print`). It works offline, never touches the folder's identity, and refuses to write through symlinks (`UNSAFE_PATH`).
43
+
44
+ Smaller fixes found by running the CLI as an agent on staging and production:
45
+
46
+ - `doctor` checks the production signing service (`api.learncard.app`) when no `LCA_API_URL` is set, instead of reporting hosted signing as unavailable while `setup-signing` used it.
47
+ - `send --suppress-delivery` no longer says the recipient will get a claim email.
48
+ - `call` and `api` no longer repeat the result on stderr in `--json` mode.
49
+ - Using `--network` that differs from the folder's network fails with `NETWORK_MISMATCH` and a hint; an unknown `status` activity ID fails with `NOT_FOUND`. Unknown commands get a "Did you mean …?" `hint`.
50
+ - `--json`, `-y` and `--network` may come before the command (`learncard --json whoami`).
51
+ - `identityCreated.did` is now the new profile's DID (the same as the result's `did`); the seed's `did:key` moves to `identityCreated.keyDid`.
52
+ - `--help` lists `LEARNCARD_AS`, `LEARNCARD_API_KEY` and `CLOUD_URL` with the other environment variables.
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies [[`c20460f6fef685272227f506f536b6811f90b8a0`](https://github.com/learningeconomy/LearnCard/commit/c20460f6fef685272227f506f536b6811f90b8a0)]:
57
+ - @learncard/types@5.24.1
58
+ - @learncard/holder-continuity@0.2.27
59
+ - @learncard/core@9.4.42
60
+ - @learncard/init@2.5.8
61
+ - @learncard/network-brain-client@2.6.2
62
+ - @learncard/didkit-plugin@1.10.8
63
+ - @learncard/lca-api-plugin@2.0.14
64
+ - @learncard/learn-cloud-plugin@2.3.50
65
+ - @learncard/ler-rs-plugin@0.1.33
66
+ - @learncard/linked-claims-plugin@0.2.42
67
+ - @learncard/open-badge-v2-plugin@1.1.43
68
+ - @learncard/render-method-plugin@12.0.1
69
+
3
70
  ## 3.6.8
4
71
 
5
72
  ### Patch Changes
package/README.md CHANGED
@@ -6,8 +6,14 @@
6
6
  [![npm downloads](https://img.shields.io/npm/dw/@learncard/cli)](https://www.npmjs.com/package/@learncard/cli)
7
7
  [![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/@learncard/cli)](https://www.npmjs.com/package/@learncard/cli)
8
8
 
9
- **LearnCard CLI** is an easy to use node REPL that instantiates a Learn Card wallet for you and gives
10
- you all the tools you need to easily play around with the Learn Card SDK!
9
+ **LearnCard CLI** sets up and operates a credential issuer from the terminal: send credentials,
10
+ track claims, manage signing, tokens and organizations, and verify what you receive. It also
11
+ includes an interactive REPL with a LearnCard wallet preloaded for exploring the SDK.
12
+
13
+ Run it with `npx @learncard/cli <command>` (Node.js 20 or later). A global install
14
+ (`npm i -g @learncard/cli`) exposes the same commands as `learncard <command>`.
15
+ Command reference: https://docs.learncard.com/reference/learncard-cli. Using it from an AI agent or
16
+ script: https://docs.learncard.com/start-here/for-ai-agents.
11
17
 
12
18
  ![LearnCard CLI](https://user-images.githubusercontent.com/2185016/201382605-13eb7bb2-f6b6-4099-97a1-1a623bf58486.gif)
13
19
 
@@ -31,7 +37,7 @@ Prompts for a recipient if omitted (or pass it: `send you@yourdomain.com`), gene
31
37
  Run a guided, real-network demonstration without writing code:
32
38
 
33
39
  ```bash
34
- learncard demo refresh
40
+ npx @learncard/cli demo refresh
35
41
  ```
36
42
 
37
43
  Press Enter between each step: send a **Provisional Course Certificate**, publish a
@@ -40,11 +46,11 @@ before and after and verifies that the credential keeps its identity. It uses th
40
46
  existing `sendBoost` flow with `enableRefresh: true` and publishes using the receipt
41
47
  returned by that send. No second badge is sent.
42
48
 
43
- The default network is `http://localhost:4000/trpc`. A developer must first start
44
- the local services with managed refresh enabled. To present against staging once
45
- LC-2198's service and SDK changes are deployed, use `learncard demo refresh --network staging`.
46
- This command requires a CLI build containing this feature; it is not available in
47
- older published versions. From this branch's repository root, run:
49
+ `demo refresh` requires `@learncard/cli` 3.6.0 or later. The default network is
50
+ `http://localhost:4000/trpc`, so a developer must first start the local services with
51
+ managed refresh enabled. To present against a staging network that has managed refresh
52
+ enabled, use `npx @learncard/cli demo refresh --network staging`. To run the current
53
+ source instead of the published package, run this from the repository root:
48
54
 
49
55
  ```bash
50
56
  bun --cwd packages/learn-card-cli start demo refresh
@@ -104,7 +110,7 @@ the locally configured delivery service to email a **provisional** claim link, y
104
110
  in the app, then the school publishes a single visible **final** update.
105
111
 
106
112
  ```bash
107
- bun --cwd packages/learn-card-cli start demo refresh --inbox --ui --email you@example.com
113
+ bun --cwd packages/learn-card-cli start demo refresh --inbox --ui --email you@yourdomain.com
108
114
  ```
109
115
 
110
116
  `--email` without a value prompts for the address. It requires `--inbox`, `--ui`, and an
@@ -206,12 +212,18 @@ authority, publication, claim binding, and refresh are all real. The direct
206
212
  ### Interactive REPL
207
213
 
208
214
  ```bash
209
- npx @learncard/cli
215
+ npx @learncard/cli repl
210
216
 
211
- # Optionally specify a seed
212
- npx @learncard/cli 1b498556081a298261313657c32d5d0a9ce8285dc4d659e6787392207e4a7ac2
217
+ # Optionally specify a deterministic seed (hex)
218
+ LEARNCARD_CLI_SEED=1b498556081a298261313657c32d5d0a9ce8285dc4d659e6787392207e4a7ac2 npx @learncard/cli repl
213
219
  ```
214
220
 
221
+ Running `npx @learncard/cli` with no command in an interactive terminal also opens the REPL; without a
222
+ TTY it prints help instead. `repl <seed>` takes the seed as an argument, but `LEARNCARD_CLI_SEED` (or
223
+ `SEED`) takes precedence over it and keeps the seed out of your shell history. The REPL does not read
224
+ the folder's `.env` identity: it starts a separate wallet from that seed (random if none is given),
225
+ always on the production network, and prints the seed on startup.
226
+
215
227
  ## Holder continuity export
216
228
 
217
229
  The CLI exposes REPL helpers from `@learncard/holder-continuity` for holder-controlled export, restore, and self-import:
@@ -300,6 +312,18 @@ npx @learncard/cli promote --from staging --to production --org ./org.yaml
300
312
 
301
313
  Re-applies your org spec in its own `.learncard/production` folder (each network needs its own `.env`), writes fresh service-account tokens to `<target>/secrets.env` (or `--secrets-out`), and runs `doctor` — then prints the per-network checklist (profile, tokens, signing authority, templates, ConsentFlow contracts, credentials) that doesn't carry over; only your seed's `did:key` does. Add `--dry-run` to preview or `--skip-doctor` to skip the preflight.
302
314
 
315
+ ## Coding agents and scripts
316
+
317
+ ```bash
318
+ npx @learncard/cli skill install # LearnCard skill for Claude Code, Cursor or .agents/
319
+ npx @learncard/cli commands --json # every command: effect, options, output fields, examples
320
+ npx @learncard/cli capabilities --json # task -> CLI command, SDK method, REST route, docs
321
+ npx @learncard/cli call getProfile --network staging --json # any learnCard.invoke method
322
+ npx @learncard/cli api GET /profile --network staging --json # any Network REST route
323
+ ```
324
+
325
+ `call` and `api` run reads as-is and refuse anything that can change data unless you pass `--write` (`--dry-run` shows what would run). Neither creates an identity, and without `--show-secret` neither prints the seed or an API token (`call --show-secret` can print private keys equivalent to the seed, and API tokens). Guide: https://docs.learncard.com/start-here/for-ai-agents/use-learncard-with-coding-agents
326
+
303
327
  ## Contributing
304
328
 
305
329
  Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.