@anyslate/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.
- package/README.md +313 -19
- package/package.json +6 -6
- package/src/auth.mjs +310 -0
- package/src/commands/checkpoint.mjs +61 -18
- package/src/commands/doctor.mjs +616 -0
- package/src/commands/hook.mjs +81 -23
- package/src/commands/login.mjs +362 -25
- package/src/commands/logout.mjs +131 -0
- package/src/commands/upload-artifact.mjs +136 -26
- package/src/config.mjs +162 -13
- package/src/credentials.mjs +162 -0
- package/src/hooks.mjs +170 -8
- package/src/index.mjs +61 -6
- package/src/io.mjs +30 -0
- package/src/mcp-client.mjs +291 -45
- package/src/oauth.mjs +633 -0
- package/src/runlog.mjs +196 -0
- package/src/stdin.mjs +85 -15
- package/src/verify.mjs +262 -0
- package/src/version.mjs +21 -0
- package/templates/git/post-commit +71 -0
package/README.md
CHANGED
|
@@ -1,74 +1,368 @@
|
|
|
1
1
|
# @anyslate/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The bridge that lets your AI tools quietly tell AnySlate what you've been working on - without you having to remember to checkpoint anything.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## What this is
|
|
6
|
+
|
|
7
|
+
A small command-line tool that runs on your machine. Your AI tools (Claude Code, git, CI) call it on your behalf as you work. It records what's happening into your AnySlate **Activity feed** - file edits, shell commands, commits - automatically and continuously.
|
|
8
|
+
|
|
9
|
+
Think of it like a Fitbit, but for your AI work. You don't tell a Fitbit "I just took 47 steps." You wear it, walk around, the count updates. Same shape here. You install this once, paste a small config snippet into your AI tool's settings, and from that point on, capture happens in the background while you work.
|
|
10
|
+
|
|
11
|
+
**You almost never run a CLI command yourself.** The tool exists to be invisible plumbing that other tools call. The setup below takes 5 minutes and ends with `anyslate doctor` telling you it works.
|
|
12
|
+
|
|
13
|
+
## Where it fits in your workflow
|
|
14
|
+
|
|
15
|
+
Most days you'll never type `anyslate` yourself. Here's what actually happens:
|
|
16
|
+
|
|
17
|
+
| Trigger | Who calls the CLI | What lands |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| You open a Claude Code session | Claude Code's `SessionStart` hook | Session-start activity; the AnySlate session is created on first sight |
|
|
20
|
+
| Claude edits `routes/auth.ts` | Claude Code's `PostToolUse` hook | "Edited routes/auth.ts" in the activity ledger |
|
|
21
|
+
| Claude runs `npm test` | Claude Code's `PostToolUse` hook | Command + output in the activity ledger |
|
|
22
|
+
| You `git commit` | Git's `post-commit` hook | Commit metadata + diff stats captured |
|
|
23
|
+
| Teammate merges your PR | GitHub webhook (no CLI needed) | PR-merged event captured |
|
|
24
|
+
| You close the laptop | Claude Code's `Stop` hook | Session-end marker captured |
|
|
25
|
+
| **You manually want to checkpoint a decision** | **You typing `anyslate checkpoint ...`** | **Captured immediately** |
|
|
26
|
+
| **You want to upload a file as an artifact** | **You typing `anyslate upload-artifact ...`** | **File stored, returns `cloud://artifact/<id>`** |
|
|
27
|
+
|
|
28
|
+
The first six rows are automatic - that's what the lifecycle hooks do. The bottom two are the rare moments where you'd actually type something yourself.
|
|
29
|
+
|
|
30
|
+
### What hook captures actually write - read this before you form expectations
|
|
31
|
+
|
|
32
|
+
Hook captures land in a dedicated **`## Activity Ledger`** section of your memory page: which files were touched, which commands ran, what exit status they returned. That is the whole contract. The ledger is capped (25 files / 15 commands per entry) and is built deterministically - no LLM runs in the hook path, so capture never bills against your AI quota.
|
|
33
|
+
|
|
34
|
+
Hook captures **do not** write to the **Decisions** or **Open Tasks** sections. Those stay human- and LLM-authored, and are populated by `anyslate checkpoint`, by the in-host MCP flow (`/anyslate-new`, `/anyslate-continue`), or by you editing the page. A hook firing on `Bash` has no decision in it to extract, and the product no longer pretends otherwise.
|
|
35
|
+
|
|
36
|
+
If you want a decision recorded, type it:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
anyslate checkpoint --note "Decided: Redis for session cache, not memcached"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Approval: hook captures auto-promote
|
|
43
|
+
|
|
44
|
+
Every lifecycle hook - `Edit` / `Write` / `MultiEdit`, `Bash`, and the session start/stop markers - classifies **low-risk** and auto-promotes on its own, 30-90 seconds after capture. An edit-heavy session does **not** build an approval queue.
|
|
45
|
+
|
|
46
|
+
Rows still wait for approval in **AI Memory → Activity** when they are genuinely riskier: a capture aimed at a different session than the one that produced it, a decision that supersedes an earlier one, a submission from an untrusted source, or one carrying `confidence < 0.8`.
|
|
47
|
+
|
|
48
|
+
File edits used to map to `artifact_produced`, which is high-risk by classification. That was wrong on two counts: it forced a manual approval on the single most common event in a session, and `artifact_produced` is a contract meaning "I stored an artifact, here is its id" - which a hook can never satisfy, so the server rejected it. Edits now map to `task_completed` and carry the touched paths in the ledger.
|
|
49
|
+
|
|
50
|
+
## What you get back
|
|
51
|
+
|
|
52
|
+
After the setup is in place:
|
|
53
|
+
|
|
54
|
+
- **You stop forgetting to checkpoint.** Capture happens whether you remember or not.
|
|
55
|
+
- **AnySlate sees what actually happened, not just what the AI claimed.** Git knows what files really changed. The hooks know what commands really ran.
|
|
56
|
+
- **Your work follows you across tools.** Claude Code at home, Cursor at work, terminal in between - all feed the same memory. (Cursor and Windsurf feed it through the in-host MCP server, not this CLI - see the FAQ.)
|
|
6
57
|
|
|
7
58
|
## Install
|
|
8
59
|
|
|
9
60
|
```bash
|
|
10
61
|
npm i -g @anyslate/cli
|
|
11
|
-
# or
|
|
62
|
+
# or run on demand without installing:
|
|
12
63
|
npx @anyslate/cli --help
|
|
13
64
|
```
|
|
14
65
|
|
|
15
66
|
Requires Node ≥ 20.
|
|
16
67
|
|
|
68
|
+
> **macOS users hitting `EACCES` on global install:** don't use `sudo`. Configure a user-writable npm prefix instead:
|
|
69
|
+
>
|
|
70
|
+
> ```bash
|
|
71
|
+
> mkdir -p ~/.npm-global
|
|
72
|
+
> npm config set prefix '~/.npm-global'
|
|
73
|
+
> echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
|
|
74
|
+
> source ~/.zshrc
|
|
75
|
+
> npm install -g @anyslate/cli
|
|
76
|
+
> ```
|
|
77
|
+
|
|
17
78
|
## Authenticate
|
|
18
79
|
|
|
19
|
-
|
|
80
|
+
```bash
|
|
81
|
+
anyslate login
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
That's it. `login` opens your browser, you approve the CLI on the AnySlate consent screen, and the credentials land in `~/.anyslate/cli.json` (mode `0600`). Nothing to copy, nothing to paste.
|
|
85
|
+
|
|
86
|
+
What happens under the hood, in case you're the kind of person who wants to know before you run it: OAuth 2.1 authorization code with PKCE. The CLI reads every endpoint from the server's discovery documents (`/.well-known/oauth-authorization-server` and `/.well-known/oauth-protected-resource`) rather than assuming any path, registers itself once via Dynamic Client Registration and caches the resulting client id, binds a short-lived listener on `127.0.0.1` for the callback, and verifies the resulting token with one live request before writing anything.
|
|
87
|
+
|
|
88
|
+
The access token lasts **one hour**; a refresh token lasts **30 days**. The CLI refreshes automatically — five minutes ahead of expiry, and again if a call comes back `401` — so your hooks keep capturing without you thinking about it. Refresh tokens are single-use and rotate on every refresh; the new one is written to disk immediately.
|
|
89
|
+
|
|
90
|
+
Then confirm the whole install:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
anyslate doctor
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Signing in to a non-production environment
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
anyslate login --api-url https://anyslate-mcp-service-development.example.workers.dev
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`--api-url` takes the service **root** (no `/mcp` suffix — see [the two URL conventions](#the-two-url-conventions---the-one-thing-people-get-wrong)). Every OAuth endpoint, and the OAuth `resource` identifier, is then read from *that* root's discovery documents. Dev and production issue different client ids, so the CLI caches one per root and reuses it.
|
|
103
|
+
|
|
104
|
+
If discovery fails, `login` says which host it tried and stops. It will not fall back to guessed endpoint paths.
|
|
105
|
+
|
|
106
|
+
### Static tokens, for CI
|
|
107
|
+
|
|
108
|
+
Browsers are in short supply on a build agent. The token path is unchanged and stays supported:
|
|
20
109
|
|
|
21
110
|
```bash
|
|
22
111
|
anyslate login --token as_mcp_your_token_here
|
|
112
|
+
# or, with no config file at all:
|
|
113
|
+
export ANYSLATE_MCP_TOKEN=as_mcp_your_token_here
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Mint the token in the AnySlate app: **Avatar (top-right) → API Tokens → Tokens tab → Create Token**. This is the same dialog on the desktop app and on the cloud app at `https://cloud.anyslate.io`; the dialog is titled *MCP Tokens*. MCP token minting is **available on every plan** - Free, Pro and Unlimited - with no token quota. Copy the token (it starts with `as_mcp_`; you only see it once).
|
|
117
|
+
|
|
118
|
+
`login --token` verifies the token against the server before writing anything. If the host is unreachable, the URL isn't an AnySlate MCP service, or the token is unrecognised/revoked/expired, it prints the reason, **writes nothing, and exits non-zero**. See [`anyslate login`](#anyslate-login) for the `--force` / `--no-verify` escapes.
|
|
119
|
+
|
|
120
|
+
Static tokens never expire and are never refreshed. That is the trade: convenient for CI, and the reason the browser flow is the default everywhere else.
|
|
121
|
+
|
|
122
|
+
### Signing out
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
anyslate logout
|
|
23
126
|
```
|
|
24
127
|
|
|
25
|
-
|
|
128
|
+
Revokes the session server-side, then removes the credentials from `~/.anyslate/cli.json`. Your `apiUrl`, `handle` and cached client registration are kept, so `anyslate login` afterwards is a one-liner.
|
|
129
|
+
|
|
130
|
+
### Environment variables
|
|
26
131
|
|
|
27
132
|
```bash
|
|
28
133
|
export ANYSLATE_MCP_TOKEN=as_mcp_your_token_here
|
|
29
|
-
export ANYSLATE_API_URL=https://mcp.anyslate.io # optional
|
|
30
|
-
export ANYSLATE_HANDLE=
|
|
134
|
+
export ANYSLATE_API_URL=https://mcp.anyslate.io # optional; service ROOT, no /mcp
|
|
135
|
+
export ANYSLATE_HANDLE=mh_xxxxxxxx # optional, scope to one capability handle
|
|
136
|
+
export ANYSLATE_DISABLE=1 # optional, disables capture for this shell
|
|
137
|
+
export ANYSLATE_HOME=/path/to/dir # optional, overrides ~/.anyslate
|
|
138
|
+
export ANYSLATE_STDIN_TIMEOUT_MS=10000 # optional, stdin idle timeout (0 disables)
|
|
31
139
|
```
|
|
32
140
|
|
|
33
141
|
Env vars override `~/.anyslate/cli.json`.
|
|
34
142
|
|
|
143
|
+
The bearer the CLI actually sends is resolved in this order, first hit wins:
|
|
144
|
+
|
|
145
|
+
1. `ANYSLATE_MCP_TOKEN` — a static token from the environment. Never refreshed.
|
|
146
|
+
2. The OAuth access token from `cli.json`, refreshed if it is expired or close to it.
|
|
147
|
+
3. The static `mcp_token` in `cli.json`.
|
|
148
|
+
|
|
149
|
+
`anyslate doctor` prints which of the three won, so an `ANYSLATE_MCP_TOKEN` you exported weeks ago and forgot cannot silently shadow a browser sign-in.
|
|
150
|
+
|
|
151
|
+
`ANYSLATE_DISABLE=1` stops `hook` / `checkpoint` / `upload-artifact` from making any network call (they exit 0). `doctor` and `login` still run, so you can diagnose and set up while capture is off. Any value counts as "on" except empty, `0`, `false`, `no`, `off`.
|
|
152
|
+
|
|
153
|
+
Capability handles are `mh_` + a 32-character id (e.g. `mh_V1StGXR8Z5jdHi6BmyT0aQx3nKpL7cWe`), minted alongside a scoped token in the **Handles** tab of the same dialog. **A handle id that isn't yours or doesn't exist is rejected server-side** - since 0.2.0 the CLI reports that as a failure instead of exiting 0 silently.
|
|
154
|
+
|
|
155
|
+
**If your token was minted with a memory scope, it already carries that scope server-side and `ANYSLATE_HANDLE` / `--handle` is ignored.** Scoped tokens cannot be widened per-call by design. To capture workspace-wide, mint an unscoped token. `anyslate doctor` reports which case you're in.
|
|
156
|
+
|
|
157
|
+
### The two URL conventions - the one thing people get wrong
|
|
158
|
+
|
|
159
|
+
AnySlate ships two clients and they want **different** URLs. This trips up nearly everyone:
|
|
160
|
+
|
|
161
|
+
| Client | Variable / flag | Wants | Example |
|
|
162
|
+
|---|---|---|---|
|
|
163
|
+
| **`@anyslate/mcp` bridge** (Claude Desktop, Cursor, Windsurf…) | `ANYSLATE_MCP_URL` | the **MCP endpoint** - *with* `/mcp` | `https://mcp.anyslate.io/mcp` |
|
|
164
|
+
| **`@anyslate/cli`** (this package) | `--api-url` / `ANYSLATE_API_URL` | the **service root** - *without* `/mcp` | `https://mcp.anyslate.io` |
|
|
165
|
+
|
|
166
|
+
The CLI appends `/mcp` itself. Pasting the bridge's URL into `--api-url` used to produce `…/mcp/mcp`, a permanent `404 {"error":"Not found"}` that masks every other diagnosis - because the 404 fires before authentication, so a wrong URL makes a valid token look invalid.
|
|
167
|
+
|
|
168
|
+
**Since 0.2.0 the CLI accepts either form and normalizes**, stripping any trailing `/mcp` segments (`/mcp`, `/mcp/mcp`, `/MCP/`, trailing slashes). Normalization happens on every read, so a `cli.json` written by an older version self-heals without re-running `login`. When it rewrites a value it tells you:
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
anyslate: apiUrl "https://mcp.anyslate.io/mcp" ends in /mcp — the CLI wants the service ROOT and appends /mcp itself.
|
|
172
|
+
anyslate: using "https://mcp.anyslate.io". Run `anyslate login --api-url https://mcp.anyslate.io` to persist.
|
|
173
|
+
```
|
|
174
|
+
|
|
35
175
|
## Subcommands
|
|
36
176
|
|
|
37
177
|
```
|
|
38
|
-
anyslate hook <session-start|post-tool-use|stop> [--strict]
|
|
39
|
-
anyslate checkpoint --note "..." [--kind milestone] [--session <id>]
|
|
40
|
-
anyslate upload-artifact --session <id> --kind <kind> [--file <path>]
|
|
41
|
-
anyslate login --
|
|
178
|
+
anyslate hook <session-start|post-tool-use|stop> [--strict] [--session <id>] [--note <text>] [--host <hint>]
|
|
179
|
+
anyslate checkpoint --note "..." [--kind milestone] [--session <id>] [--host <hint>] [--source <source>]
|
|
180
|
+
anyslate upload-artifact --session <id> --kind <kind> [--file <path>] [--language <lang>] [--path-hint <path>]
|
|
181
|
+
anyslate login [--api-url <URL>] [--no-browser] [--timeout <seconds>] [--handle <ID>]
|
|
182
|
+
anyslate login --token <BEARER> [--handle <ID>] [--api-url <URL>] [--force] [--no-verify]
|
|
183
|
+
anyslate logout [--local]
|
|
184
|
+
anyslate doctor [--deep] [--refresh]
|
|
42
185
|
anyslate version | help
|
|
43
186
|
```
|
|
44
187
|
|
|
188
|
+
### `anyslate doctor`
|
|
189
|
+
|
|
190
|
+
The one command whose job is to fail loudly. Run it after setup and any time capture seems dead. It exits non-zero if any check FAILs.
|
|
191
|
+
|
|
192
|
+
It checks, in order: which config layer won (env var vs `cli.json`) per key; that a credential is present; **which auth mode is in use** — OAuth or static token — and for OAuth how long the access token has left and whether a refresh token is stored; that the token *looks* like a token; that the URL parses and has the right shape (**before** any token verdict, because a wrong URL 404s ahead of auth and would otherwise be misread as a bad token); that the host is reachable and healthy; **whether refresh works**; that the token is valid (and, if not, whether it is unrecognised, revoked or expired); that the token carries `memory:write`; the effective handle scope; that `anyslate` is on the PATH a hook subprocess would get; and whether Claude Code's hooks are actually wired in `~/.claude/settings.json`.
|
|
193
|
+
|
|
194
|
+
The refresh check runs **after** reachability on purpose: a refresh against a host that is down fails for a reason that has nothing to do with your credentials, and reporting that as "refresh is broken" sends you hunting for the wrong bug. If the access token is still comfortably valid, `doctor` reports the refresh token as present but does not spend it — pass `--refresh` to force a real refresh round trip (which rotates the token).
|
|
195
|
+
|
|
196
|
+
An expired OAuth access token is a **WARN**, not a FAIL: access tokens are supposed to expire hourly. The FAIL you care about is `oauth-refresh`, which means renewal itself is broken and you need to run `anyslate login` again.
|
|
197
|
+
|
|
198
|
+
Reading the output:
|
|
199
|
+
|
|
200
|
+
- **PASS** - checked and observed good.
|
|
201
|
+
- **WARN** - works, but something is narrower or more fragile than you probably intend (e.g. a project-scoped token, or a config key coming from an env var you forgot you exported).
|
|
202
|
+
- **FAIL** - this is why capture isn't working. Each FAIL prints the specific remedy.
|
|
203
|
+
|
|
204
|
+
`doctor` is **not** side-effect-free: verifying the token updates its `last_used_at`, consumes rate-limit budget, and writes an audit-log row. `--deep` additionally submits a real `doctor_probe` activity, which is visible in your Activity feed - that's why it's opt-in. `--refresh` forces an OAuth refresh, which rotates your refresh token - also why it's opt-in.
|
|
205
|
+
|
|
45
206
|
### `anyslate hook ...`
|
|
46
207
|
|
|
47
|
-
Reads JSON event payload from stdin (Claude Code lifecycle event format). Fails open by default
|
|
208
|
+
Reads a JSON event payload from stdin (Claude Code lifecycle event format). **Fails open by default** - a network blip, an invalid token or a server-side rejection logs to stderr and exits 0, so your Claude Code session is never broken. Pass `--strict` to exit 1 on failure instead (useful in CI smoke tests).
|
|
209
|
+
|
|
210
|
+
Because fail-open means you won't see stderr in normal use, every run is recorded to `~/.anyslate/cli-last-run.json` and a capped ring log at `~/.anyslate/cli-runs.ndjson` (both mode 0600, token redacted). After repeated consecutive failures the `SessionStart` hook surfaces a message in Claude Code itself telling you to run `anyslate doctor`. One-off failures stay quiet.
|
|
211
|
+
|
|
212
|
+
Kind mapping: `hook session-start` → `topic_shift`; `hook stop` → `conversation_end`; `hook post-tool-use` maps `Edit`/`Write`/`MultiEdit`/`Create` and `Bash`/`Shell`/`Run`/`GitCommit` → `task_completed`, everything else → `topic_shift`.
|
|
213
|
+
|
|
214
|
+
Hooks never emit `artifact_produced`. That kind is a contract — "I stored an artifact, here is its id in `artifact_refs`" — and the server rejects it without one. A hook observes a file touch; it stores nothing. The touched path is carried in the `files_touched` ledger field instead, so edits auto-promote as activity entries rather than piling up an approval queue.
|
|
48
215
|
|
|
49
|
-
`
|
|
216
|
+
**Session identity is handled for you.** Claude Code's `session_id` is a UUID from its own namespace; AnySlate session ids are a different format entirely. The server resolves the incoming UUID against `conversation_id_external`, and **creates the AnySlate session on first sight** if there's no match, titling it from the host and working directory. You do **not** need to pass `--session` in the Claude Code hook config, and re-running under the same Claude Code session reuses the same AnySlate session. `--session` remains available for git hooks and CI, where you want to pin captures to one specific memory.
|
|
217
|
+
|
|
218
|
+
Fields read from the stdin payload: `session_id` (or `sessionId`), `tool_name` (or `toolName`), `tool_input` (or `toolInput`), `tool_response` (or `toolResponse`, JSON-stringified into `conversation_excerpt`), `transcript_path`, `client_checkpoint_id`. Anything else in the payload is ignored.
|
|
219
|
+
|
|
220
|
+
**The activity ledger.** From `tool_input` and `tool_response` the hook derives three structured fields — `files_touched`, `commands_run` and `exit_status` — and sends them as first-class payload fields. They record what a tool call *did*, and they land in the activity/ledger section of the memory page. They are deliberately **not** folded into `notes`: `notes` is the prose the server mines for Decisions and Open Tasks, and turning shell commands into decisions would manufacture entries you never made. Fields with nothing to record are omitted rather than sent empty. No LLM runs anywhere on this path.
|
|
50
221
|
|
|
51
222
|
### `anyslate checkpoint`
|
|
52
223
|
|
|
53
|
-
User-initiated, exits non-zero on failure. Defaults `--kind milestone`, `--source api`. Allowed kinds: `topic_shift | decision_committed | task_completed | task_added | artifact_produced | milestone | conversation_end`.
|
|
224
|
+
User-initiated, exits non-zero on failure - including on server-side rejections, not just network errors. Defaults `--kind milestone`, `--source api`. Allowed kinds: `topic_shift | decision_committed | task_completed | task_added | artifact_produced | milestone | conversation_end`.
|
|
225
|
+
|
|
226
|
+
`--host <hint>` sets the advisory `host_hint`; `--source <source>` overrides the activity source.
|
|
227
|
+
|
|
228
|
+
Low-risk items reach your memory page after a **30-second quiet period plus the next once-a-minute promoter run** - so 30-90 seconds, not instantly.
|
|
54
229
|
|
|
55
230
|
### `anyslate upload-artifact`
|
|
56
231
|
|
|
57
|
-
Reads file or stdin, calls the `upload_artifact` MCP tool.
|
|
232
|
+
Reads a file or stdin, calls the `upload_artifact` MCP tool. Prints `cloud://artifact/<id>` on stdout on success; on failure prints nothing to stdout, writes the reason to stderr and exits non-zero. Allowed kinds: `code_block | file_path | error_message | shell_command | config_snippet | url_reference | fenced_quote`. 5 MB content cap on both the `--file` and stdin paths.
|
|
233
|
+
|
|
234
|
+
Content is read as UTF-8. Binary files are not supported and are refused rather than silently mangled.
|
|
58
235
|
|
|
59
236
|
### `anyslate login`
|
|
60
237
|
|
|
61
|
-
|
|
238
|
+
Two paths, one config file. `--token` selects the static path; its absence selects the browser flow.
|
|
239
|
+
|
|
240
|
+
Both end the same way: one live request to `/mcp/auth/verify` that proves reachability, URL shape, token validity and scopes in a single round trip, then a `0600` write to `~/.anyslate/cli.json`. **On verification failure it writes nothing and exits non-zero.** Both are idempotent — they preserve the `apiUrl` and `handle` you already had (and re-normalize a stored `apiUrl` that carries a stale `/mcp` suffix).
|
|
241
|
+
|
|
242
|
+
A token missing the `memory:write` scope is a **warning**, not a block - but `anyslate hook` needs it, so heed it.
|
|
243
|
+
|
|
244
|
+
**Browser flow flags**
|
|
245
|
+
|
|
246
|
+
- `--api-url <root>` - which environment to sign in to. Defaults to production. Every OAuth endpoint comes from that root's discovery documents.
|
|
247
|
+
- `--no-browser` - print the authorization URL instead of launching anything. For SSH sessions and containers. The URL is printed either way, so a browser that fails to appear never leaves you stuck.
|
|
248
|
+
- `--timeout <seconds>` - how long to wait for the callback. Default `180`.
|
|
249
|
+
- `--handle <ID>` - store a capability handle alongside the credentials.
|
|
250
|
+
|
|
251
|
+
**Static-token flags**
|
|
252
|
+
|
|
253
|
+
- `--force` - write anyway, with a warning. For when you know the server is temporarily down.
|
|
254
|
+
- `--no-verify` - skip the probe entirely. For air-gapped or offline setup.
|
|
255
|
+
|
|
256
|
+
**What gets stored.** The browser flow writes an `oauth` block: the client id, the access token, the refresh token, the absolute expiry, and the token endpoint and `resource` it discovered (cached so a background refresh costs one request instead of three, and bound to the root so switching environments re-discovers rather than reusing the wrong one). The static flow writes `mcp_token`, exactly as before. Neither path touches the other's keys.
|
|
257
|
+
|
|
258
|
+
**Refresh.** Handled automatically by whichever command needs it — `hook`, `checkpoint`, `upload-artifact`, `doctor`. It happens five minutes before expiry, and once more on a `401`. Since hooks can fire in parallel, refreshes are serialized with a lock file and the config is replaced atomically, so two concurrent hooks cannot lose each other's rotated token. A hook **never** opens a browser: if refresh fails there, it logs the reason and exits 0 like any other failure.
|
|
259
|
+
|
|
260
|
+
### `anyslate logout`
|
|
261
|
+
|
|
262
|
+
Revokes the OAuth session at the server's revocation endpoint (refresh token first — it's the 30-day one), then removes `oauth` and `mcp_token` from `~/.anyslate/cli.json`.
|
|
263
|
+
|
|
264
|
+
Revocation is best effort. If the host is unreachable the credentials are still cleared and you get a warning, because a `logout` that refuses to run offline is a `logout` you cannot use when you most need one.
|
|
265
|
+
|
|
266
|
+
`apiUrl`, `handle` and the cached client registration survive. The registration is not a credential, and re-registering costs one of the ten Dynamic Client Registrations allowed per hour.
|
|
267
|
+
|
|
268
|
+
- `--local` - skip revocation and only clear the local file. The server-side session then stays live until it expires.
|
|
269
|
+
|
|
270
|
+
If `ANYSLATE_MCP_TOKEN` is set in your environment, `logout` says so: it overrides the config, so capture keeps working until you unset it.
|
|
62
271
|
|
|
63
272
|
## Wiring into Claude Code
|
|
64
273
|
|
|
65
|
-
|
|
274
|
+
Claude Code is the only host today with a native lifecycle-hook surface. Edit `~/.claude/settings.json` (create it if missing) and **merge** this into any `hooks` block already there - don't replace the file:
|
|
275
|
+
|
|
276
|
+
```json
|
|
277
|
+
{
|
|
278
|
+
"hooks": {
|
|
279
|
+
"SessionStart": [
|
|
280
|
+
{ "hooks": [ { "type": "command", "command": "anyslate hook session-start" } ] }
|
|
281
|
+
],
|
|
282
|
+
"PostToolUse": [
|
|
283
|
+
{
|
|
284
|
+
"matcher": "Edit|Write|MultiEdit|Bash",
|
|
285
|
+
"hooks": [ { "type": "command", "command": "anyslate hook post-tool-use" } ]
|
|
286
|
+
}
|
|
287
|
+
],
|
|
288
|
+
"Stop": [
|
|
289
|
+
{ "hooks": [ { "type": "command", "command": "anyslate hook stop" } ] }
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Restart Claude Code, then run `anyslate doctor` - it parses this file and tells you whether the wiring took.
|
|
296
|
+
|
|
297
|
+
**If `anyslate` isn't found when the hook fires**, Claude Code spawned it with a minimal `PATH`. Use the absolute path (`command -v anyslate` prints it) or `npx --yes @anyslate/cli hook session-start`. `anyslate doctor` checks this explicitly.
|
|
298
|
+
|
|
299
|
+
## Git capture
|
|
300
|
+
|
|
301
|
+
Requires a global install (the template ships in the package). The guard on the first line means a missing template stops the recipe *before* it touches your hook file - it can never leave you with an empty one:
|
|
302
|
+
|
|
303
|
+
```bash
|
|
304
|
+
# from the repo root
|
|
305
|
+
src="$(npm root -g)/@anyslate/cli/templates/git/post-commit"
|
|
306
|
+
[ -s "$src" ] && install -m 0755 "$src" .git/hooks/post-commit \
|
|
307
|
+
|| echo "template not found - install @anyslate/cli globally first (npm i -g @anyslate/cli)"
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Optional, exported before the next commit:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
export ANYSLATE_SESSION=<anyslate_session_id> # routes commits into a specific memory
|
|
314
|
+
export ANYSLATE_HOST=git_post_commit # host_hint advisory
|
|
315
|
+
export ANYSLATE_QUIET=1 # swallow CLI stderr
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
`ANYSLATE_SESSION` is read by **this git template only** (it passes `--session` through); the CLI itself does not read it. It has no effect on Claude Code hooks, which don't need it - see the session-identity note above.
|
|
319
|
+
|
|
320
|
+
Commit metadata (`repo`, `branch`, `sha`, `subject`, `author`, `stats`) is JSON-encoded into the capture's `conversation_excerpt`. It is not a set of first-class queryable fields.
|
|
321
|
+
|
|
322
|
+
## FAQ
|
|
323
|
+
|
|
324
|
+
**Do I have to type `anyslate ...` regularly?**
|
|
325
|
+
No. After setup, your AI tools call it automatically. The only commands you might type yourself are `checkpoint`, `upload-artifact`, and `doctor` when something looks wrong.
|
|
326
|
+
|
|
327
|
+
**Will this slow down my AI tool?**
|
|
328
|
+
Each hook invocation is three sequential HTTPS round trips (`initialize`, `notifications/initialized`, `tools/call`) sharing one 15-second timeout budget. Typically well under a second. It is fail-open, so a network blip logs to stderr and exits cleanly rather than blocking your session.
|
|
329
|
+
|
|
330
|
+
**What if I want to disable capture for one session?**
|
|
331
|
+
Set `ANYSLATE_DISABLE=1` in the shell where you're running the AI tool. The CLI makes no network call and captures nothing for that shell.
|
|
332
|
+
|
|
333
|
+
Setting `ANYSLATE_MCP_TOKEN=` (empty) does **not** disable capture - an empty string falls through to the token in `~/.anyslate/cli.json`, so capture keeps running. Earlier versions of this README claimed otherwise; that claim was wrong. Use `ANYSLATE_DISABLE=1`.
|
|
334
|
+
|
|
335
|
+
**Where does the data live?**
|
|
336
|
+
In your AnySlate workspace. The CLI is a stateless client; it sends events to the AnySlate MCP service over HTTPS and stores nothing locally beyond your credentials in `~/.anyslate/cli.json` and the local run logs described under `anyslate hook` (all mode 0600). The run logs redact anything token-shaped before writing.
|
|
337
|
+
|
|
338
|
+
**Do I need to log in again every hour?**
|
|
339
|
+
No. The one-hour lifetime is the access token's; the CLI renews it in the background from a 30-day refresh token, including inside hooks running unattended. You'll re-authenticate roughly monthly, or whenever you run `anyslate logout`.
|
|
340
|
+
|
|
341
|
+
**I'm on a headless box / over SSH. Can I still use the browser flow?**
|
|
342
|
+
Yes - `anyslate login --no-browser` prints the URL, you open it on a machine that has a browser, and it redirects back to `127.0.0.1` on the port the CLI is listening on. That only works if the browser can reach that loopback address, so from a remote box you'll want an SSH tunnel - or just use `--token`, which is what it's there for.
|
|
343
|
+
|
|
344
|
+
**Is the CLI adding dependencies to do OAuth?**
|
|
345
|
+
No. It has no runtime dependencies. PKCE, the loopback listener and the browser launch are all `node:` builtins, and there's a test that fails the build if an import ever points outside them.
|
|
346
|
+
|
|
347
|
+
**Can I see what was captured?**
|
|
348
|
+
Yes - **AI Memory → Activity** shows every captured row with its status (pending / merged / rejected / failed), and failures under the **Failed** tab carry the reason. High-risk items wait for approval; low-risk items promote on their own in 30-90 seconds.
|
|
349
|
+
|
|
350
|
+
**How do I undo a bad capture?**
|
|
351
|
+
Open the Activity panel, find the row, click **Reject**. Pre-promotion rejections never touch your memory pages. Post-promotion: open the memory and edit or delete the merged content.
|
|
352
|
+
|
|
353
|
+
**Does this work with tools that aren't Claude Code?**
|
|
354
|
+
Auto-firing lifecycle hooks are Claude Code only - it's the only host with a native hook surface. For Cursor / Windsurf / Cline / Claude Desktop / ChatGPT, capture happens **inside the host** via the AnySlate MCP server (`/anyslate-new`, `/anyslate-continue`). The CLI on the side handles git capture, CI capture, and manual checkpoints from anywhere a shell command can run.
|
|
355
|
+
|
|
356
|
+
**What's the privacy story?**
|
|
357
|
+
Bearer-token auth, optional capability handles that scope a token to one project or topic, HTTPS-only transport, payload caps. Tokens are revocable from the same dialog you minted them in. `notes` is clipped at **4,000 characters** and `conversation_excerpt` at **16,000 characters** - both are string lengths, not bytes, and clipping applies to the `hook` path only (`checkpoint --note` is sent as given).
|
|
358
|
+
|
|
359
|
+
**What if I'm offline?**
|
|
360
|
+
Hooks fail open - no error to your AI tool, just no capture for those events. There is no offline queue, so events missed while offline are not retroactively captured. The failure is recorded locally and surfaced by `anyslate doctor`.
|
|
66
361
|
|
|
67
362
|
## Tests
|
|
68
363
|
|
|
69
364
|
```bash
|
|
70
|
-
npm test
|
|
71
|
-
# 23 tests · node --test · no external deps
|
|
365
|
+
npm test # node --test, no external deps
|
|
72
366
|
```
|
|
73
367
|
|
|
74
368
|
## License
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anyslate/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "AnySlate CLI
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "AnySlate CLI - lifecycle hooks, git/CI capture, and manual checkpoints for AI memory. Validates its connection at login, diagnoses itself with `anyslate doctor`, and fails open without failing silent.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"anyslate": "./bin/anyslate.mjs"
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"bin",
|
|
11
11
|
"src/*.mjs",
|
|
12
12
|
"src/commands",
|
|
13
|
+
"templates",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"scripts": {
|
|
@@ -32,9 +33,8 @@
|
|
|
32
33
|
"cli"
|
|
33
34
|
],
|
|
34
35
|
"license": "MIT",
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
"url": "https://
|
|
38
|
-
"directory": "cli"
|
|
36
|
+
"homepage": "https://anyslate.io",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://anyslate.io/support"
|
|
39
39
|
}
|
|
40
40
|
}
|