@unhuman/wsync-cli 0.1.0 → 0.1.2

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 +9 -6
  2. package/dist/wsync.mjs +243 -62
  3. package/package.json +5 -3
package/README.md CHANGED
@@ -16,16 +16,19 @@ still prints `{}` and exits `0`.
16
16
  2. Inside the repository you want captured:
17
17
 
18
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
19
+ npx @unhuman/wsync-cli link wsp_your_key_here
21
20
  ```
22
21
 
23
22
  The server defaults to `https://unhuman.unbs.cloud/api`. Against a dev stack, pass
24
23
  `--server http://localhost:3000` (or set `WSYNC_SERVER`).
25
24
 
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.
25
+ > **Mind the scope.** Plain `npx wsync` is an unrelated package by someone else; it has to be
26
+ > `@unhuman/wsync-cli`.
27
+
28
+ > **From a checkout**, run the working copy instead: `pnpm --filter @unhuman/wsync-cli build`
29
+ > then `node apps/wsync-cli/dist/wsync.mjs …`. Do not `npm i` inside this repo — npm cannot read
30
+ > the `workspace:*` protocol pnpm uses here, and fails with `EUNSUPPORTEDPROTOCOL` before it ever
31
+ > reaches the registry.
29
32
 
30
33
  `link` does everything in one step: it checks the key against the server, records the link in
31
34
  `~/.wsync/config.json`, installs the Claude Code hooks (see below), and registers the wsync MCP
@@ -78,7 +81,7 @@ In production, requests go through the reverse proxy, which strips `/api` before
78
81
  backend. So the server value you pass there is the site origin **plus** `/api`:
79
82
 
80
83
  ```sh
81
- node apps/wsync-cli/dist/wsync.mjs link wsp_your_key_here --server https://unhuman.unbs.cloud/api
84
+ npx @unhuman/wsync-cli link wsp_your_key_here --server https://unhuman.unbs.cloud/api
82
85
  ```
83
86
 
84
87
  Every API call is a plain concatenation of the configured server and a `/wsync/...` path (see
package/dist/wsync.mjs CHANGED
@@ -178,8 +178,8 @@ var require_git = __commonJS({
178
178
  Object.defineProperty(exports, "__esModule", { value: true });
179
179
  exports.getBranch = exports.getRemote = void 0;
180
180
  exports.outermostContiguousGitRoot = outermostContiguousGitRoot;
181
- exports.nearestGitRoot = nearestGitRoot2;
182
- exports.normaliseRemote = normaliseRemote;
181
+ exports.nearestGitRoot = nearestGitRoot3;
182
+ exports.normaliseRemote = normaliseRemote2;
183
183
  var node_child_process_1 = __require("node:child_process");
184
184
  var node_fs_1 = __require("node:fs");
185
185
  var node_path_1 = __require("node:path");
@@ -211,7 +211,7 @@ var require_git = __commonJS({
211
211
  }
212
212
  return best;
213
213
  }
214
- function nearestGitRoot2(dir) {
214
+ function nearestGitRoot3(dir) {
215
215
  let cur = (0, node_path_1.resolve)(dir);
216
216
  for (; ; ) {
217
217
  if ((0, node_fs_1.existsSync)((0, node_path_1.join)(cur, ".git")))
@@ -222,11 +222,11 @@ var require_git = __commonJS({
222
222
  cur = parent;
223
223
  }
224
224
  }
225
- var getRemote = (root) => git(root, ["remote", "get-url", "origin"]);
226
- exports.getRemote = getRemote;
225
+ var getRemote2 = (root) => git(root, ["remote", "get-url", "origin"]);
226
+ exports.getRemote = getRemote2;
227
227
  var getBranch2 = (root) => git(root, ["rev-parse", "--abbrev-ref", "HEAD"]);
228
228
  exports.getBranch = getBranch2;
229
- function normaliseRemote(url) {
229
+ function normaliseRemote2(url) {
230
230
  let s = url.trim();
231
231
  s = s.replace(/^[a-z+]+:\/\//i, "");
232
232
  s = s.replace(/^[^@/]+@/, "");
@@ -1136,7 +1136,7 @@ ${spine}`;
1136
1136
  return JSON.parse(extractJson(text));
1137
1137
  }
1138
1138
  function run(cmd2, args2, stdin, timeoutMs) {
1139
- return new Promise((resolve4, reject) => {
1139
+ return new Promise((resolve5, reject) => {
1140
1140
  const child = (0, node_child_process_1.spawn)(cmd2, args2, {
1141
1141
  stdio: ["pipe", "pipe", "pipe"],
1142
1142
  env: { ...process.env, WSYNC_CHILD: "1" }
@@ -1159,7 +1159,7 @@ ${spine}`;
1159
1159
  child.on("close", (code) => {
1160
1160
  clearTimeout(timer);
1161
1161
  if (code === 0)
1162
- resolve4(out);
1162
+ resolve5(out);
1163
1163
  else
1164
1164
  reject(new Error(`${cmd2} exited ${code}: ${err.slice(0, 400)}`));
1165
1165
  });
@@ -5782,6 +5782,14 @@ var require_render_context = __commonJS({
5782
5782
  priority: 1,
5783
5783
  render: () => {
5784
5784
  const lines = [`## wsync context \u2014 ${ctx.project?.name ?? "unknown project"}`];
5785
+ if (ctx.workstream) {
5786
+ const w = ctx.workstream;
5787
+ const handle = w.key && w.key.toLowerCase() !== w.slug ? `${w.slug}, ${w.key}` : w.slug;
5788
+ const moved = w.lastActivityAt ? `, last activity ${w.lastActivityAt.toISOString().slice(0, 10)}` : "";
5789
+ const fresh = w.sessions === 0 ? " No sessions filed yet \u2014 the briefing below is project-wide." : "";
5790
+ lines.push(`Workstream: ${w.title} (${handle}) \u2014 ${w.status}${moved}.${fresh}`);
5791
+ lines.push("Working on something else? Call wsync_start_work with a handle, branch or one sentence.");
5792
+ }
5785
5793
  if (ctx.tickets.length) {
5786
5794
  lines.push(`Tickets: ${ctx.tickets.slice(0, 6).map((t) => t.summary ? `${t.key} (${t.summary})` : t.key).join(", ")}`);
5787
5795
  }
@@ -6101,6 +6109,58 @@ var init_links = __esm({
6101
6109
  }
6102
6110
  });
6103
6111
 
6112
+ // src/spool.ts
6113
+ import { writeFileSync as writeFileSync2, readdirSync, readFileSync as readFileSync3, unlinkSync, renameSync, existsSync as existsSync3 } from "node:fs";
6114
+ import { join as join3 } from "node:path";
6115
+ import { randomUUID } from "node:crypto";
6116
+ function enqueue(entry) {
6117
+ ensureDirs();
6118
+ const name = `${Date.now()}-${randomUUID().slice(0, 8)}.json`;
6119
+ const tmp = join3(SPOOL_DIR, `.${name}.tmp`);
6120
+ const dest = join3(SPOOL_DIR, name);
6121
+ writeFileSync2(tmp, JSON.stringify({ ...entry, queuedAt: (/* @__PURE__ */ new Date()).toISOString(), attempts: 0 }), { mode: 384 });
6122
+ renameSync(tmp, dest);
6123
+ return dest;
6124
+ }
6125
+ function listSpool() {
6126
+ if (!existsSync3(SPOOL_DIR)) return [];
6127
+ return readdirSync(SPOOL_DIR).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort().flatMap((f) => {
6128
+ const p = join3(SPOOL_DIR, f);
6129
+ try {
6130
+ return [{ path: p, entry: JSON.parse(readFileSync3(p, "utf8")) }];
6131
+ } catch {
6132
+ return [];
6133
+ }
6134
+ });
6135
+ }
6136
+ function dequeue(path) {
6137
+ try {
6138
+ unlinkSync(path);
6139
+ } catch {
6140
+ }
6141
+ }
6142
+ function recordAttempt(path, entry) {
6143
+ try {
6144
+ writeFileSync2(path, JSON.stringify({ ...entry, attempts: entry.attempts + 1 }), { mode: 384 });
6145
+ } catch {
6146
+ }
6147
+ }
6148
+ function trimSpool() {
6149
+ const all = listSpool();
6150
+ if (all.length <= MAX_SPOOL_ENTRIES) return 0;
6151
+ const excess = all.slice(0, all.length - MAX_SPOOL_ENTRIES);
6152
+ for (const e of excess) dequeue(e.path);
6153
+ return excess.length;
6154
+ }
6155
+ var MAX_SPOOL_ENTRIES;
6156
+ var init_spool = __esm({
6157
+ "src/spool.ts"() {
6158
+ "use strict";
6159
+ init_config();
6160
+ MAX_SPOOL_ENTRIES = 500;
6161
+ }
6162
+ });
6163
+
6104
6164
  // src/artifact.ts
6105
6165
  import { createReadStream } from "node:fs";
6106
6166
  import { gzipSync } from "node:zlib";
@@ -6143,9 +6203,9 @@ async function fitArtifactEnd(path, start, fileEnd) {
6143
6203
  }
6144
6204
  }
6145
6205
  function readRange(path, start, end) {
6146
- return new Promise((resolve4, reject) => {
6206
+ return new Promise((resolve5, reject) => {
6147
6207
  const chunks = [];
6148
- createReadStream(path, { start, end: end - 1 }).on("data", (c) => chunks.push(c)).on("end", () => resolve4(Buffer.concat(chunks))).on("error", reject);
6208
+ createReadStream(path, { start, end: end - 1 }).on("data", (c) => chunks.push(c)).on("end", () => resolve5(Buffer.concat(chunks))).on("error", reject);
6149
6209
  });
6150
6210
  }
6151
6211
  var import_wsync_core2, ARTIFACT_GZ_TARGET, MIN_FIT_SPAN;
@@ -6165,7 +6225,7 @@ var init_package = __esm({
6165
6225
  "package.json"() {
6166
6226
  package_default = {
6167
6227
  name: "@unhuman/wsync-cli",
6168
- version: "0.1.0",
6228
+ version: "0.1.2",
6169
6229
  description: "Capture Claude Code sessions to an Unhuman Work Context project: link a checkout, install the hooks, drain the spool.",
6170
6230
  license: "UNLICENSED",
6171
6231
  repository: {
@@ -6196,13 +6256,15 @@ var init_package = __esm({
6196
6256
  scripts: {
6197
6257
  build: `esbuild --bundle --platform=node --format=esm --packages=bundle --banner:js="import{createRequire as __wsyncCreateRequire}from'module';const require=__wsyncCreateRequire(import.meta.url);" --outfile=dist/wsync.mjs src/bin.ts`,
6198
6258
  typecheck: "tsc -p tsconfig.json --noEmit",
6199
- prepublishOnly: "pnpm run build"
6259
+ prepublishOnly: "pnpm run build",
6260
+ test: "vitest run"
6200
6261
  },
6201
6262
  devDependencies: {
6202
6263
  "@types/node": "^22.10.0",
6203
6264
  esbuild: "^0.24.0",
6204
6265
  typescript: "^5.7.0",
6205
- "@unhuman/wsync-core": "workspace:*"
6266
+ "@unhuman/wsync-core": "workspace:*",
6267
+ vitest: "^3.2.0"
6206
6268
  }
6207
6269
  };
6208
6270
  }
@@ -6224,10 +6286,21 @@ import { join as join7, resolve as resolve2, dirname } from "node:path";
6224
6286
  import { homedir as homedir2 } from "node:os";
6225
6287
  import { fileURLToPath } from "node:url";
6226
6288
  function cliPath() {
6227
- const running = process.argv[1];
6228
- if (running && running.endsWith(".mjs") && existsSync7(running)) return resolve2(running);
6229
6289
  const here = dirname(fileURLToPath(import.meta.url));
6230
- return resolve2(here, "../../dist/wsync.mjs");
6290
+ const candidates = [
6291
+ process.argv[1] && process.argv[1].endsWith(".mjs") ? resolve2(process.argv[1]) : null,
6292
+ resolve2(here, "wsync.mjs"),
6293
+ // bundled: this file *is* dist/wsync.mjs
6294
+ resolve2(here, "../../dist/wsync.mjs"),
6295
+ // from source: src/commands → package root
6296
+ resolve2(here, "../dist/wsync.mjs")
6297
+ ].filter((p) => Boolean(p));
6298
+ for (const candidate of candidates) {
6299
+ if (existsSync7(candidate)) return candidate;
6300
+ }
6301
+ throw new Error(
6302
+ `Cannot find the wsync bundle to install hooks for (looked in: ${candidates.join(", ")}). Reinstall @unhuman/wsync-cli, or run install-hooks with \`node <path>/dist/wsync.mjs\`.`
6303
+ );
6231
6304
  }
6232
6305
  function ourEntry(event, matcher, isAsync) {
6233
6306
  const cmd2 = `node ${cliPath()} hook ${event}`;
@@ -6243,6 +6316,7 @@ function ourEntry(event, matcher, isAsync) {
6243
6316
  };
6244
6317
  }
6245
6318
  async function installHooks(opts = {}) {
6319
+ cliPath();
6246
6320
  const settings = readSettings();
6247
6321
  const hooks = settings["hooks"] ?? {};
6248
6322
  let added = 0;
@@ -6269,6 +6343,12 @@ async function installHooks(opts = {}) {
6269
6343
  }
6270
6344
  return { added };
6271
6345
  }
6346
+ function hookHealth() {
6347
+ const hooks = readSettings()["hooks"] ?? {};
6348
+ const commands = Object.values(hooks).flatMap((list) => list ?? []).flatMap((matcher) => matcher.hooks ?? []).map((hook) => hook.command ?? "").filter((command) => command.includes(MARKER));
6349
+ const target = commands[0]?.match(/node\s+(\S+wsync\.mjs)/)?.[1] ?? null;
6350
+ return { installed: commands.length, target, targetExists: Boolean(target && existsSync7(target)) };
6351
+ }
6272
6352
  async function uninstallHooks() {
6273
6353
  const settings = readSettings();
6274
6354
  const hooks = settings["hooks"] ?? {};
@@ -6354,6 +6434,18 @@ async function link(key, opts = {}) {
6354
6434
  console.log(` Linked ${cwd} \u2192 ${who.projectName ?? who.project} (${who.project})`);
6355
6435
  const hooks = await installHooks({ quiet: true });
6356
6436
  console.log(hooks.added > 0 ? " \u2713 capture hooks installed" : " \u2713 capture hooks already present");
6437
+ const health = hookHealth();
6438
+ if (!health.targetExists) {
6439
+ console.log(` ! the hooks point at ${health.target ?? "nothing"}, which does not exist \u2014 nothing will be captured`);
6440
+ console.log(" Re-run install-hooks from the installed package, or report this with `wsync status`.");
6441
+ process.exitCode = 1;
6442
+ } else {
6443
+ console.log(` they run ${health.target}`);
6444
+ }
6445
+ const pending = listSpool().length;
6446
+ if (pending > 0) {
6447
+ console.log(` ! ${pending} spooled event(s) still pending \u2014 run \`wsync flush --verbose\` to see why`);
6448
+ }
6357
6449
  spawnSync("claude", ["mcp", "remove", "wsync", "--scope", "local"], { cwd, stdio: "ignore" });
6358
6450
  const mcp = spawnSync("claude", [
6359
6451
  "mcp",
@@ -6382,6 +6474,7 @@ var init_link = __esm({
6382
6474
  init_config();
6383
6475
  init_links();
6384
6476
  init_install();
6477
+ init_spool();
6385
6478
  }
6386
6479
  });
6387
6480
 
@@ -6665,64 +6758,122 @@ var init_enrich = __esm({
6665
6758
  }
6666
6759
  });
6667
6760
 
6668
- // src/commands/flush.ts
6669
- var import_wsync_core3 = __toESM(require_dist(), 1);
6670
- init_config();
6671
- init_links();
6672
- import { statSync as statSync2, existsSync as existsSync6, writeFileSync as writeFileSync5 } from "node:fs";
6673
- import { createHash as createHash2 } from "node:crypto";
6674
- import { join as join6 } from "node:path";
6675
- import { hostname, platform } from "node:os";
6676
-
6677
- // src/spool.ts
6678
- init_config();
6679
- import { writeFileSync as writeFileSync2, readdirSync, readFileSync as readFileSync3, unlinkSync, renameSync, existsSync as existsSync3 } from "node:fs";
6680
- import { join as join3 } from "node:path";
6681
- import { randomUUID } from "node:crypto";
6682
- function enqueue(entry) {
6683
- ensureDirs();
6684
- const name = `${Date.now()}-${randomUUID().slice(0, 8)}.json`;
6685
- const tmp = join3(SPOOL_DIR, `.${name}.tmp`);
6686
- const dest = join3(SPOOL_DIR, name);
6687
- writeFileSync2(tmp, JSON.stringify({ ...entry, queuedAt: (/* @__PURE__ */ new Date()).toISOString(), attempts: 0 }), { mode: 384 });
6688
- renameSync(tmp, dest);
6689
- return dest;
6690
- }
6691
- function listSpool() {
6692
- if (!existsSync3(SPOOL_DIR)) return [];
6693
- return readdirSync(SPOOL_DIR).filter((f) => f.endsWith(".json") && !f.startsWith(".")).sort().flatMap((f) => {
6694
- const p = join3(SPOOL_DIR, f);
6695
- try {
6696
- return [{ path: p, entry: JSON.parse(readFileSync3(p, "utf8")) }];
6697
- } catch {
6698
- return [];
6699
- }
6761
+ // src/commands/setup.ts
6762
+ var setup_exports = {};
6763
+ __export(setup_exports, {
6764
+ setup: () => setup
6765
+ });
6766
+ import { hostname as osHostname } from "node:os";
6767
+ import { resolve as resolve4 } from "node:path";
6768
+ async function setup(token, opts = {}) {
6769
+ const cfg = loadConfig();
6770
+ const server = (opts.server ?? cfg.server).replace(/\/+$/, "");
6771
+ const cwd = resolve4(process.cwd());
6772
+ if (!token || token.startsWith("wsp_")) {
6773
+ console.error("setup takes a workspace API token. If you already have a wsp_ capture key, run: wsync link <key>");
6774
+ process.exitCode = 1;
6775
+ return;
6776
+ }
6777
+ const existing = resolveLink(cfg.links, cwd);
6778
+ if (existing && !opts.force) {
6779
+ console.log(` ${existing.path} is already linked. Nothing to do.`);
6780
+ console.log(" Re-run with --force to mint a new key for this machine, or `wsync status` to see the links.");
6781
+ return;
6782
+ }
6783
+ const projectKey = opts.project?.trim() || await remoteProject(cwd);
6784
+ if (!projectKey) {
6785
+ console.error(
6786
+ `No git remote in ${cwd}, so there is nothing to name the project after. Pass --project <key> (e.g. github.com/team/repo).`
6787
+ );
6788
+ process.exitCode = 1;
6789
+ return;
6790
+ }
6791
+ const result = await callTool(server, token, {
6792
+ name: "wsync_setup",
6793
+ arguments: { projectKey, ...opts.name ? { name: opts.name } : {}, machine: opts.machine ?? hostname3() }
6700
6794
  });
6795
+ if (!result.ok) {
6796
+ console.error(result.message);
6797
+ process.exitCode = 1;
6798
+ return;
6799
+ }
6800
+ const key = /link\s+(wsp_[A-Za-z0-9_-]+)/.exec(result.command)?.[1];
6801
+ if (!key) {
6802
+ console.error(`${server} answered, but without a capture key to use. Check the token has owner or admin rights.`);
6803
+ process.exitCode = 1;
6804
+ return;
6805
+ }
6806
+ console.log(
6807
+ ` ${result.created ? "Created" : "Found"} project ${result.projectName ?? projectKey} (${result.projectKey ?? projectKey})`
6808
+ );
6809
+ await link(key, { server });
6701
6810
  }
6702
- function dequeue(path) {
6811
+ async function remoteProject(cwd) {
6812
+ const root = (0, import_wsync_core6.nearestGitRoot)(cwd);
6813
+ if (!root) return null;
6814
+ const remote = await (0, import_wsync_core6.getRemote)(root);
6815
+ return remote ? (0, import_wsync_core6.normaliseRemote)(remote) : null;
6816
+ }
6817
+ function hostname3() {
6818
+ return osHostname().trim() || "this machine";
6819
+ }
6820
+ async function callTool(server, token, params) {
6821
+ let res;
6703
6822
  try {
6704
- unlinkSync(path);
6705
- } catch {
6823
+ res = await fetch(`${server}/mcp`, {
6824
+ method: "POST",
6825
+ headers: { authorization: `Bearer ${token}`, "content-type": "application/json", accept: "application/json" },
6826
+ body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params }),
6827
+ signal: AbortSignal.timeout(2e4)
6828
+ });
6829
+ } catch (e) {
6830
+ return { ok: false, message: `Could not reach ${server}: ${String(e)}` };
6706
6831
  }
6707
- }
6708
- function recordAttempt(path, entry) {
6832
+ if (res.status === 401) return { ok: false, message: `${server} rejected that token. Mint one in Settings \u2192 Claude (MCP).` };
6833
+ if (!res.ok) return { ok: false, message: `${server} answered ${res.status}.` };
6834
+ const body = await res.json().catch(() => ({}));
6835
+ if (body.error) return { ok: false, message: body.error.message ?? "The server refused the call." };
6836
+ const text = body.result?.content?.[0]?.text ?? "";
6837
+ if (body.result?.isError) return { ok: false, message: text || "The server refused the call." };
6709
6838
  try {
6710
- writeFileSync2(path, JSON.stringify({ ...entry, attempts: entry.attempts + 1 }), { mode: 384 });
6839
+ const parsed = JSON.parse(text);
6840
+ if (!parsed.command) return { ok: false, message: text || "No command came back from the server." };
6841
+ return {
6842
+ ok: true,
6843
+ command: parsed.command,
6844
+ projectKey: parsed.project?.projectKey,
6845
+ projectName: parsed.project?.name,
6846
+ created: Boolean(parsed.project?.created)
6847
+ };
6711
6848
  } catch {
6849
+ return { ok: false, message: text || "The server answered in a shape this CLI does not understand." };
6712
6850
  }
6713
6851
  }
6714
- var MAX_SPOOL_ENTRIES = 500;
6715
- function trimSpool() {
6716
- const all = listSpool();
6717
- if (all.length <= MAX_SPOOL_ENTRIES) return 0;
6718
- const excess = all.slice(0, all.length - MAX_SPOOL_ENTRIES);
6719
- for (const e of excess) dequeue(e.path);
6720
- return excess.length;
6721
- }
6852
+ var import_wsync_core6;
6853
+ var init_setup = __esm({
6854
+ "src/commands/setup.ts"() {
6855
+ "use strict";
6856
+ import_wsync_core6 = __toESM(require_dist(), 1);
6857
+ init_config();
6858
+ init_links();
6859
+ init_link();
6860
+ }
6861
+ });
6862
+
6863
+ // src/commands/flush.ts
6864
+ var import_wsync_core3 = __toESM(require_dist(), 1);
6865
+ init_config();
6866
+ init_links();
6867
+ init_spool();
6868
+ import { statSync as statSync2, existsSync as existsSync6, writeFileSync as writeFileSync5 } from "node:fs";
6869
+ import { createHash as createHash2 } from "node:crypto";
6870
+ import { join as join6 } from "node:path";
6871
+ import { hostname, platform } from "node:os";
6722
6872
 
6723
6873
  // src/commands/hook.ts
6724
6874
  init_config();
6725
6875
  init_links();
6876
+ init_spool();
6726
6877
  import { spawn } from "node:child_process";
6727
6878
  import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync4, statSync, appendFileSync } from "node:fs";
6728
6879
  import { join as join4 } from "node:path";
@@ -6732,6 +6883,7 @@ import { createHash } from "node:crypto";
6732
6883
  var import_wsync_core = __toESM(require_dist(), 1);
6733
6884
  init_config();
6734
6885
  init_links();
6886
+ init_spool();
6735
6887
  import { randomUUID as randomUUID2 } from "node:crypto";
6736
6888
  var EVENT_SUBCOMMANDS = {
6737
6889
  "event-prompt": "prompt",
@@ -7179,6 +7331,7 @@ async function refreshContext(cwd) {
7179
7331
 
7180
7332
  // src/bin.ts
7181
7333
  init_install();
7334
+ init_spool();
7182
7335
  init_config();
7183
7336
  var [cmd, sub, ...rest] = process.argv.slice(2);
7184
7337
  var args = [sub, ...rest].filter(Boolean);
@@ -7189,6 +7342,8 @@ var val = (n) => {
7189
7342
  };
7190
7343
  var USAGE = `wsync \u2014 work context across machines
7191
7344
 
7345
+ wsync setup <api-token> [--server URL] [--project KEY] [--machine NAME]
7346
+ one paste: mint this machine's key and link
7192
7347
  wsync link <key> [--server URL] link this directory to a project
7193
7348
  wsync backfill [--limit N] [--key wsp_\u2026] [--verbose]
7194
7349
  import existing transcripts over HTTP
@@ -7255,6 +7410,15 @@ try {
7255
7410
  const links = Object.entries(cfg.links);
7256
7411
  console.log(`home ${WSYNC_HOME}`);
7257
7412
  console.log(`server ${cfg.server}`);
7413
+ const health = hookHealth();
7414
+ if (health.installed === 0) {
7415
+ console.log("hooks NOT INSTALLED \u2014 run: wsync install-hooks");
7416
+ } else if (!health.targetExists) {
7417
+ console.log(`hooks ${health.installed} installed but BROKEN \u2014 ${health.target} does not exist`);
7418
+ console.log(" nothing is being captured. Re-run: wsync install-hooks");
7419
+ } else {
7420
+ console.log(`hooks ${health.installed} installed -> ${health.target}`);
7421
+ }
7258
7422
  console.log(`links ${links.length}`);
7259
7423
  for (const [path, key] of links) console.log(` - ${path} -> ${key}`);
7260
7424
  console.log(`spool ${spool.length} pending`);
@@ -7265,6 +7429,23 @@ try {
7265
7429
  }
7266
7430
  break;
7267
7431
  }
7432
+ case "setup": {
7433
+ const { setup: setup2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
7434
+ const token = args[0];
7435
+ if (!token || token.startsWith("--")) {
7436
+ console.error("Usage: wsync setup <api-token> [--server URL] [--project KEY] [--machine NAME]");
7437
+ process.exitCode = 1;
7438
+ break;
7439
+ }
7440
+ await setup2(token, {
7441
+ server: val("server"),
7442
+ project: val("project"),
7443
+ name: val("name"),
7444
+ machine: val("machine"),
7445
+ force: has("force")
7446
+ });
7447
+ break;
7448
+ }
7268
7449
  case "install-hooks":
7269
7450
  await installHooks({ dryRun: has("dry-run") });
7270
7451
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unhuman/wsync-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Capture Claude Code sessions to an Unhuman Work Context project: link a checkout, install the hooks, drain the spool.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -31,12 +31,14 @@
31
31
  "scripts": {
32
32
  "build": "esbuild --bundle --platform=node --format=esm --packages=bundle --banner:js=\"import{createRequire as __wsyncCreateRequire}from'module';const require=__wsyncCreateRequire(import.meta.url);\" --outfile=dist/wsync.mjs src/bin.ts",
33
33
  "typecheck": "tsc -p tsconfig.json --noEmit",
34
- "prepublishOnly": "pnpm run build"
34
+ "prepublishOnly": "pnpm run build",
35
+ "test": "vitest run"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "^22.10.0",
38
39
  "esbuild": "^0.24.0",
39
40
  "typescript": "^5.7.0",
40
- "@unhuman/wsync-core": "workspace:*"
41
+ "@unhuman/wsync-core": "workspace:*",
42
+ "vitest": "^3.2.0"
41
43
  }
42
44
  }