$npx -y skills add magnusrodseth/sparebank1-cli --skill sparebank1-sharedRuntime contract for the sb1 CLI (SpareBank 1 personal banking). Covers install, BankID login, secret-storage backends, output formats, global flags, the command map, and error handling. Use this as the foundation before any other sparebank1 skill, or whenever a user asks to ch
| 1 | # sparebank1-shared |
| 2 | |
| 3 | Foundation skill for the `sb1` CLI, a client for the |
| 4 | [SpareBank 1 personal banking API](https://developer.sparebank1.no). Read this |
| 5 | before using any other `sparebank1` skill. |
| 6 | |
| 7 | **This is real money and real bank data. Be conservative.** Never invent account |
| 8 | numbers or amounts; only act on what commands return or what the user states. |
| 9 | |
| 10 | ## Install & first-time setup |
| 11 | |
| 12 | ```bash |
| 13 | cargo install sparebank1-cli # installs the `sb1` binary |
| 14 | ``` |
| 15 | |
| 16 | One-time setup the user must do themselves (requires their BankID): |
| 17 | |
| 18 | 1. Register a **personal client** app at https://developer.sparebank1.no |
| 19 | 2. Set its redirect URI to exactly `http://localhost:12345/callback` |
| 20 | 3. Put `CLIENT_ID` / `CLIENT_SECRET` in a `.env` (git-ignored) or env vars |
| 21 | 4. `sb1 login`, opens the browser for BankID, stores the token |
| 22 | |
| 23 | Do not run `sb1 login` on the user's behalf without asking; it triggers an |
| 24 | interactive BankID flow. |
| 25 | |
| 26 | ## Authentication & storage |
| 27 | |
| 28 | ```bash |
| 29 | sb1 status # logged in? token expiry? which storage backend? |
| 30 | sb1 refresh # force a token refresh |
| 31 | sb1 logout # remove the token (add --all to also drop client credentials) |
| 32 | ``` |
| 33 | |
| 34 | Tokens auto-refresh before expiry; the user normally does not re-login between |
| 35 | sessions. Secrets live in one of three backends, chosen by `SB1_STORE`: |
| 36 | |
| 37 | | `SB1_STORE` | Where | |
| 38 | |---|---| |
| 39 | | _unset_ / `keychain` | OS keychain (macOS Keychain / Linux keyutils / Windows Credential Manager), **default** | |
| 40 | | `op` / `1password` | 1Password via the `op` CLI (`SB1_OP_VAULT`, `SB1_OP_ACCOUNT`) | |
| 41 | | `file` | `~/.config/sparebank1-cli/*.json` (0600), **plaintext, opt-in** for headless/automation | |
| 42 | |
| 43 | If a command reports "not logged in" or the client secret is rejected, tell the |
| 44 | user to run `sb1 login` (the secret has limited validity and may need rotating |
| 45 | in the developer portal). Do not retry in a loop. |
| 46 | |
| 47 | ## Output & flags |
| 48 | |
| 49 | - Default output is human-readable tables (Norwegian amounts: `kr 1 234,56`). |
| 50 | - Add `--json` to **any** command for machine-readable output, always use this |
| 51 | when parsing programmatically. |
| 52 | - Errors print to stderr with a non-zero exit code. |
| 53 | |
| 54 | ## Command map |
| 55 | |
| 56 | | Command | Purpose | Skill | |
| 57 | |---|---|---| |
| 58 | | `login` / `logout` / `refresh` / `status` / `hello` | auth & health | this skill | |
| 59 | | `accounts` | list accounts | sparebank1-accounts | |
| 60 | | `account <ref> [--details\|--roles]` | one account | sparebank1-accounts | |
| 61 | | `balance <number>` | balance by account number | sparebank1-accounts | |
| 62 | | `transactions ...` | list/filter/export transactions | sparebank1-accounts | |
| 63 | | `transaction <id>` | one transaction's details | sparebank1-accounts | |
| 64 | | `export ...` | server-side CSV export | sparebank1-accounts | |
| 65 | | `transfer debit\|creditcard\|pension` | move money | sparebank1-transfers | |
| 66 | | `summary [--months N]` | net worth + cash flow + categories | sparebank1-accounts | |
| 67 | |
| 68 | `<ref>` for an account accepts its **name** ("Brukskonto"), **key**, or |
| 69 | **number**, the CLI resolves it. Verify with `sb1 accounts` first when unsure. |
| 70 | |
| 71 | ## Etiquette (API terms) |
| 72 | |
| 73 | The bank enforces rate limits and monitors usage. Do **not** add retry/polling |
| 74 | loops or try to bypass limits. On HTTP 429 the CLI reports a `Retry-After`; wait, |
| 75 | don't hammer. Usage is strictly personal; never expose credentials in output. |