@unhuman/wsync-cli 0.1.2 → 0.2.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 +24 -1
  2. package/dist/wsync.mjs +77 -14
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -60,7 +60,7 @@ wsync link <key> [--server URL] link this directory to a project
60
60
  wsync backfill [--limit N] [--key wsp_…] [--verbose]
61
61
  import existing ~/.claude/projects transcripts
62
62
  wsync flush [--verbose] drain the offline spool to the server
63
- wsync status show config and pending spool
63
+ wsync status show config, links (keys by prefix) and pending spool
64
64
  wsync install-hooks [--dry-run] register hooks in ~/.claude/settings.json
65
65
  wsync uninstall-hooks remove them again
66
66
  wsync refresh-context --cwd PATH refresh the local context cache
@@ -72,6 +72,29 @@ haven't been capturing since the start — entirely over HTTP, using whichever l
72
72
  directory owns each transcript's working directory, or `--key` as a fallback for anything with no
73
73
  linked ancestor. Sessions that match neither are skipped and counted, never silently dropped.
74
74
 
75
+ **Where a session is filed** depends on which command captured it:
76
+
77
+ - **Live capture (the hooks)** files every session under the project the directory's key names.
78
+ Always. The checkout's git remote is recorded as evidence and shown in the app when it disagrees,
79
+ but it never overrules the key and never creates a project.
80
+ - **`backfill`** sends `mode: backfill`, and there the remote may choose the project — among the
81
+ projects that already exist in your workspace (by slug, by a remote the workspace has seen before,
82
+ or by an unambiguous bare name). A transcript whose remote matches nothing lands in the app's
83
+ **Needs filing** queue with the remote named, for a person to file. Neither mode invents a project;
84
+ one key can import a whole machine without funnelling twenty repositories into one project.
85
+
86
+ **Re-linking a directory moves it.** `link` on a directory that already has a key verifies the new
87
+ key, writes it, and then retires the previous one — with that key, on the server — so a directory
88
+ has one live key at a time and `status` never lists ghosts. A retire the server refuses is reported
89
+ and does not undo the link; revoke the old key from the app's Keys list in that case.
90
+
91
+ **`.wsync.json`** in a repository root is an optional marker (`{ "project": "<slug>", "ticket":
92
+ "<KEY>" }`) the identity layer reads ahead of the git remote. It does not change where live capture
93
+ files a session — the key does that — but it names the project `backfill` should look for and the
94
+ ticket to prefer. It lives in the repository, so committing it shares the choice with everyone who
95
+ clones; whether a project name belongs in a public repository is the owner's call. `link` never
96
+ writes it.
97
+
75
98
  ## Production server
76
99
 
77
100
  The default server (used when you pass no `--server` and have none configured) is
package/dist/wsync.mjs CHANGED
@@ -5515,6 +5515,14 @@ var require_schemas = __commonJS({
5515
5515
  exports.ingestSchema = zod_1.z.object({
5516
5516
  distillation: exports.distillationSchema,
5517
5517
  identity: exports.identitySchema,
5518
+ /**
5519
+ * Which rule files the session. `live` (the hooks): the capture key names the project, always, and
5520
+ * the identity's remote is recorded as evidence. `backfill` (`wsync backfill`, one key for a whole
5521
+ * machine of history): the remote may choose the project — among projects that exist — and an
5522
+ * unmatched one goes to triage. Neither mode ever creates a project. Absent from older clients,
5523
+ * and absent means live, the strict rule.
5524
+ */
5525
+ mode: zod_1.z.enum(["live", "backfill"]).default("live"),
5518
5526
  transcriptPath: zod_1.z.string().max(4096),
5519
5527
  transcriptShaPrefix: zod_1.z.string().max(128),
5520
5528
  machineHostname: zod_1.z.string().max(300).optional(),
@@ -6095,10 +6103,13 @@ function saveLink(absPath, key, opts = {}) {
6095
6103
  }
6096
6104
  }
6097
6105
  const links = current["links"] ?? {};
6098
- links[resolve(absPath)] = key;
6106
+ const path = resolve(absPath);
6107
+ const previous = links[path];
6108
+ links[path] = key;
6099
6109
  current["links"] = links;
6100
6110
  if (opts.server) current["server"] = opts.server;
6101
6111
  writeFileSync(file, JSON.stringify(current, null, 2) + "\n", { mode: 384 });
6112
+ return previous && previous !== key ? previous : null;
6102
6113
  }
6103
6114
  var configFile;
6104
6115
  var init_links = __esm({
@@ -6225,7 +6236,7 @@ var init_package = __esm({
6225
6236
  "package.json"() {
6226
6237
  package_default = {
6227
6238
  name: "@unhuman/wsync-cli",
6228
- version: "0.1.2",
6239
+ version: "0.2.0",
6229
6240
  description: "Capture Claude Code sessions to an Unhuman Work Context project: link a checkout, install the hooks, drain the spool.",
6230
6241
  license: "UNLICENSED",
6231
6242
  repository: {
@@ -6430,8 +6441,15 @@ async function link(key, opts = {}) {
6430
6441
  process.exitCode = 1;
6431
6442
  return;
6432
6443
  }
6433
- saveLink(cwd, key, { server });
6444
+ const previous = saveLink(cwd, key, { server });
6434
6445
  console.log(` Linked ${cwd} \u2192 ${who.projectName ?? who.project} (${who.project})`);
6446
+ if (previous) await retirePrevious(server, previous);
6447
+ if (opts.capture) await installCapture();
6448
+ else console.log(" \xB7 session capture is off \u2014 memories go through MCP. Add --capture to also record transcripts.");
6449
+ registerMcp(cwd, server, key);
6450
+ console.log("\n Start Claude Code. Nothing else to do.");
6451
+ }
6452
+ async function installCapture() {
6435
6453
  const hooks = await installHooks({ quiet: true });
6436
6454
  console.log(hooks.added > 0 ? " \u2713 capture hooks installed" : " \u2713 capture hooks already present");
6437
6455
  const health = hookHealth();
@@ -6446,6 +6464,8 @@ async function link(key, opts = {}) {
6446
6464
  if (pending > 0) {
6447
6465
  console.log(` ! ${pending} spooled event(s) still pending \u2014 run \`wsync flush --verbose\` to see why`);
6448
6466
  }
6467
+ }
6468
+ function registerMcp(cwd, server, key) {
6449
6469
  spawnSync("claude", ["mcp", "remove", "wsync", "--scope", "local"], { cwd, stdio: "ignore" });
6450
6470
  const mcp = spawnSync("claude", [
6451
6471
  "mcp",
@@ -6466,7 +6486,26 @@ async function link(key, opts = {}) {
6466
6486
  console.log(` claude mcp add --scope local --transport http wsync ${server}/mcp \\`);
6467
6487
  console.log(` --header "Authorization: Bearer ${key}"`);
6468
6488
  }
6469
- console.log("\n Start Claude Code. Nothing else to do.");
6489
+ }
6490
+ async function retirePrevious(server, previous) {
6491
+ let res;
6492
+ try {
6493
+ res = await fetch(`${server}/wsync/keys/retire`, {
6494
+ method: "POST",
6495
+ headers: { authorization: `Bearer ${previous}` },
6496
+ signal: AbortSignal.timeout(1e4)
6497
+ });
6498
+ } catch (e) {
6499
+ console.log(` ! could not retire the key this directory used before (${String(e)}) \u2014 revoke it in the app's Keys list`);
6500
+ return;
6501
+ }
6502
+ if (res.ok) {
6503
+ console.log(" \u2713 the key this directory used before is retired");
6504
+ } else if (res.status === 401) {
6505
+ console.log(" \xB7 the key this directory used before was already revoked");
6506
+ } else {
6507
+ console.log(` ! could not retire the key this directory used before (${res.status}) \u2014 revoke it in the app's Keys list`);
6508
+ }
6470
6509
  }
6471
6510
  var init_link = __esm({
6472
6511
  "src/commands/link.ts"() {
@@ -6575,6 +6614,7 @@ async function backfill(opts = {}) {
6575
6614
  console.log(`discovered ${all.length} transcript(s) (${mb(all)}MB)`);
6576
6615
  let ingested = 0;
6577
6616
  let skipped = 0;
6617
+ let unfiled = 0;
6578
6618
  for (const f of all) {
6579
6619
  try {
6580
6620
  const d = await (0, import_wsync_core4.distillMechanically)(f.path, f.bytes);
@@ -6606,7 +6646,11 @@ async function backfill(opts = {}) {
6606
6646
  transcriptPath: f.path,
6607
6647
  transcriptShaPrefix: await (0, import_wsync_core4.transcriptPrefixSha)(f.path),
6608
6648
  // No `segment`: an absent segment tells the server this span is the
6609
- // whole file, not one tile of it.
6649
+ // whole file, not one tile of it. `mode` is what lets the remote choose
6650
+ // the project (among those that exist) instead of the key -- one key
6651
+ // imports a whole machine's history without funnelling it into one
6652
+ // project. Anything the remote does not match lands in triage.
6653
+ mode: "backfill",
6610
6654
  segmentKind: "backfill",
6611
6655
  isSidechain: f.isSidechain,
6612
6656
  parentSessionId: f.parentSessionId
@@ -6627,8 +6671,10 @@ async function backfill(opts = {}) {
6627
6671
  }
6628
6672
  }
6629
6673
  ingested++;
6674
+ if (body.projectId === null) unfiled++;
6630
6675
  if (opts.verbose) {
6631
- console.log(` [ok] ${d.sessionId.slice(0, 8)} ${identity.projectKey ?? "_unfiled"} (${identity.confidence.toFixed(2)})`);
6676
+ const where = body.projectId === null ? "-> triage (no project matches)" : "";
6677
+ console.log(` [ok] ${d.sessionId.slice(0, 8)} ${identity.projectKey ?? "_unfiled"} (${identity.confidence.toFixed(2)}) ${where}`.trimEnd());
6632
6678
  }
6633
6679
  } catch (e) {
6634
6680
  skipped++;
@@ -6636,7 +6682,10 @@ async function backfill(opts = {}) {
6636
6682
  }
6637
6683
  }
6638
6684
  console.log(`backfill: ${ingested} ingested, ${skipped} skipped, ${all.length} discovered`);
6639
- return { discovered: all.length, ingested, skipped };
6685
+ if (unfiled > 0) {
6686
+ console.log(` ${unfiled} session(s) matched no project and are waiting in triage. Create the project in the app, then file them from "Needs filing".`);
6687
+ }
6688
+ return { discovered: all.length, ingested, skipped, unfiled };
6640
6689
  }
6641
6690
  var import_wsync_core4, mb;
6642
6691
  var init_backfill = __esm({
@@ -6790,7 +6839,12 @@ async function setup(token, opts = {}) {
6790
6839
  }
6791
6840
  const result = await callTool(server, token, {
6792
6841
  name: "wsync_setup",
6793
- arguments: { projectKey, ...opts.name ? { name: opts.name } : {}, machine: opts.machine ?? hostname3() }
6842
+ arguments: {
6843
+ projectKey,
6844
+ ...opts.name ? { name: opts.name } : {},
6845
+ ...opts.create ? { create: true } : {},
6846
+ machine: opts.machine ?? hostname3()
6847
+ }
6794
6848
  });
6795
6849
  if (!result.ok) {
6796
6850
  console.error(result.message);
@@ -6806,7 +6860,7 @@ async function setup(token, opts = {}) {
6806
6860
  console.log(
6807
6861
  ` ${result.created ? "Created" : "Found"} project ${result.projectName ?? projectKey} (${result.projectKey ?? projectKey})`
6808
6862
  );
6809
- await link(key, { server });
6863
+ await link(key, { server, capture: opts.capture });
6810
6864
  }
6811
6865
  async function remoteProject(cwd) {
6812
6866
  const root = (0, import_wsync_core6.nearestGitRoot)(cwd);
@@ -7272,6 +7326,8 @@ async function sendTile(cfg, key, entry, byteStart, byteEnd, proposedSeq, fileSi
7272
7326
  spoolDepth: listSpool().length,
7273
7327
  transcriptPath: entry.transcriptPath,
7274
7328
  transcriptShaPrefix: await (0, import_wsync_core3.transcriptPrefixSha)(entry.transcriptPath),
7329
+ // Live: the key names the project. Said explicitly, though absent means the same.
7330
+ mode: "live",
7275
7331
  segment: { seq: proposedSeq, kind: entry.trigger, byteStart, byteEnd }
7276
7332
  });
7277
7333
  const res = await fetch(apiUrl(cfg, "/wsync/ingest"), {
@@ -7342,9 +7398,14 @@ var val = (n) => {
7342
7398
  };
7343
7399
  var USAGE = `wsync \u2014 work context across machines
7344
7400
 
7345
- wsync setup <api-token> [--server URL] [--project KEY] [--machine NAME]
7401
+ wsync setup <api-token> [--server URL] [--project KEY] [--machine NAME] [--create] [--capture]
7346
7402
  one paste: mint this machine's key and link
7347
- wsync link <key> [--server URL] link this directory to a project
7403
+ (connects Claude Code to the project's memories
7404
+ over MCP; --capture also records transcripts)
7405
+ (--create opens a new project; without it an
7406
+ unknown project is refused, not invented)
7407
+ wsync link <key> [--server URL] [--capture]
7408
+ link this directory to a project
7348
7409
  wsync backfill [--limit N] [--key wsp_\u2026] [--verbose]
7349
7410
  import existing transcripts over HTTP
7350
7411
  wsync flush [--verbose] drain the offline spool to the server
@@ -7373,7 +7434,7 @@ try {
7373
7434
  break;
7374
7435
  }
7375
7436
  const { link: link2 } = await Promise.resolve().then(() => (init_link(), link_exports));
7376
- await link2(key, { server: val("server") });
7437
+ await link2(key, { server: val("server"), capture: has("capture") });
7377
7438
  break;
7378
7439
  }
7379
7440
  case "backfill": {
@@ -7420,7 +7481,7 @@ try {
7420
7481
  console.log(`hooks ${health.installed} installed -> ${health.target}`);
7421
7482
  }
7422
7483
  console.log(`links ${links.length}`);
7423
- for (const [path, key] of links) console.log(` - ${path} -> ${key}`);
7484
+ for (const [path, key] of links) console.log(` - ${path} -> ${key.slice(0, 12)}\u2026`);
7424
7485
  console.log(`spool ${spool.length} pending`);
7425
7486
  for (const s of spool.slice(0, 10)) {
7426
7487
  const e = s.entry;
@@ -7442,7 +7503,9 @@ try {
7442
7503
  project: val("project"),
7443
7504
  name: val("name"),
7444
7505
  machine: val("machine"),
7445
- force: has("force")
7506
+ force: has("force"),
7507
+ create: has("create"),
7508
+ capture: has("capture")
7446
7509
  });
7447
7510
  break;
7448
7511
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unhuman/wsync-cli",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
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": {