@unhuman/wsync-cli 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.
Files changed (3) hide show
  1. package/README.md +112 -0
  2. package/dist/wsync.mjs +7303 -0
  3. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # @unhuman/wsync-cli
2
+
3
+ Captures your Claude Code sessions into an Unhuman **Work Context** project, so the next
4
+ session — on this machine or another — starts with what the last one learned: what you were
5
+ working on, which files mattered, which tickets came up, how it ended.
6
+
7
+ It runs as a set of Claude Code hooks plus a small offline spool. Nothing it does can fail your
8
+ turn: every hook is a fire-and-forget enqueue, and a `hook` invocation that throws for any reason
9
+ still prints `{}` and exits `0`.
10
+
11
+ ## Quick start
12
+
13
+ 1. In Unhuman, open **Work Context**, pick (or create) a project in the rail, and mint a capture key
14
+ (`wsp_…`) from its **Capture keys** action. (The in-app **How to connect** guide on that page walks
15
+ through both this and the MCP side.)
16
+ 2. Inside the repository you want captured:
17
+
18
+ ```sh
19
+ pnpm --filter @unhuman/wsync-cli build # once, from the repo root
20
+ node apps/wsync-cli/dist/wsync.mjs link wsp_your_key_here
21
+ ```
22
+
23
+ The server defaults to `https://unhuman.unbs.cloud/api`. Against a dev stack, pass
24
+ `--server http://localhost:3000` (or set `WSYNC_SERVER`).
25
+
26
+ > **Not `npx wsync`.** This package is not on npm, and the bare name `wsync` there belongs to an
27
+ > unrelated project — running it would fetch a stranger's code. Until the bundle is served from
28
+ > the app itself, invoke it by path; that is also exactly what the installed hooks do.
29
+
30
+ `link` does everything in one step: it checks the key against the server, records the link in
31
+ `~/.wsync/config.json`, installs the Claude Code hooks (see below), and registers the wsync MCP
32
+ server for this directory (`claude mcp add …`) so Claude can query context on demand, not just
33
+ at session start.
34
+ 3. Start Claude Code. Nothing else to do — captures happen automatically from here.
35
+
36
+ Run `wsync status` at any time to see the configured server, which directories are linked, and how
37
+ many captures are still waiting to be sent (e.g. because you were offline).
38
+
39
+ ## What gets captured
40
+
41
+ Once a directory is linked, wsync hooks into these Claude Code lifecycle events:
42
+
43
+ | Event | What happens |
44
+ |-----------------------|--------------|
45
+ | `SessionStart` | Injects a rendered summary of prior work on this project back into context (from a local cache — never blocks on the network). |
46
+ | `UserPromptSubmit`, `PostToolUse`, `PostToolUseFailure`, `Stop` | Spool a lightweight event (prompt text, tool name/response, assistant reply) for the activity timeline. |
47
+ | `PreCompact`, `SessionEnd` | Spool a **checkpoint**: a pointer at the transcript segment since the last checkpoint. A detached `wsync flush` then distills it (extracts prompts, files touched, tickets, git identity — all locally, no LLM call), redacts secrets, and uploads both the structured distillation and a gzip'd raw archive of that segment. |
48
+
49
+ Everything text-bearing is capped at 64KB per field before it ever leaves the spool, and redacted
50
+ (again, belt-and-braces with the server's own redaction pass) before upload. An unlinked directory
51
+ captures nothing — `SessionStart` tells you so, once, so you're never silently uncaptured.
52
+
53
+ ## Commands
54
+
55
+ ```
56
+ wsync link <key> [--server URL] link this directory to a project
57
+ wsync backfill [--limit N] [--key wsp_…] [--verbose]
58
+ import existing ~/.claude/projects transcripts
59
+ wsync flush [--verbose] drain the offline spool to the server
60
+ wsync status show config and pending spool
61
+ wsync install-hooks [--dry-run] register hooks in ~/.claude/settings.json
62
+ wsync uninstall-hooks remove them again
63
+ wsync refresh-context --cwd PATH refresh the local context cache
64
+ wsync hook <sub> invoked by Claude Code itself; reads stdin
65
+ ```
66
+
67
+ `backfill` imports transcripts already sitting under `~/.claude/projects` for repositories you
68
+ haven't been capturing since the start — entirely over HTTP, using whichever linked ancestor
69
+ directory owns each transcript's working directory, or `--key` as a fallback for anything with no
70
+ linked ancestor. Sessions that match neither are skipped and counted, never silently dropped.
71
+
72
+ ## Production server
73
+
74
+ The default server (used when you pass no `--server` and have none configured) is
75
+ `http://localhost:3000` — a local backend with nothing in front of it.
76
+
77
+ In production, requests go through the reverse proxy, which strips `/api` before they reach the
78
+ backend. So the server value you pass there is the site origin **plus** `/api`:
79
+
80
+ ```sh
81
+ node apps/wsync-cli/dist/wsync.mjs link wsp_your_key_here --server https://unhuman.unbs.cloud/api
82
+ ```
83
+
84
+ Every API call is a plain concatenation of the configured server and a `/wsync/...` path (see
85
+ `apiUrl` in `src/config.ts`), so this is the only place the `/api` prefix needs to be spelled out —
86
+ nothing else in the CLI knows or cares which environment it's talking to.
87
+
88
+ ## On-disk layout
89
+
90
+ Everything lives under `~/.wsync` (override with `WSYNC_HOME`):
91
+
92
+ ```
93
+ ~/.wsync/
94
+ config.json server + per-directory links, mode 0600
95
+ spool/ pending checkpoints and events, drained by `flush`
96
+ cache/ rendered context per linked directory + per-session segment bookmarks
97
+ wsync.log best-effort diagnostics from the hooks themselves
98
+ flush.lock single-holder lock so a hook-spawned flush and a manual one never race
99
+ ```
100
+
101
+ ## Development
102
+
103
+ ```sh
104
+ pnpm --filter @unhuman/wsync-cli typecheck # tsc --noEmit
105
+ pnpm --filter @unhuman/wsync-cli build # esbuild bundle -> dist/wsync.mjs
106
+ ```
107
+
108
+ This package reuses `@unhuman/wsync-core` for everything content-shaped — mechanical transcript
109
+ distillation, git/ticket identity resolution, and redaction — rather than reimplementing any of
110
+ it. It has no test suite of its own; correctness here is verified by the backend's wsync specs and
111
+ by live end-to-end use (linking a real directory, running Claude Code against it, checking
112
+ `wsync status` and the server's session view).