@skedulo/memory-hub-mcp 0.2.23 → 0.2.24

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 CHANGED
@@ -45,7 +45,7 @@ lives here so it updates on the next `yarn build`, not via a manual `cp` into
45
45
  ## Claude Desktop
46
46
 
47
47
  The MCP server is plain stdio, so Claude Desktop can run it. The `memory-hub-hook` package
48
- cannot — Claude Desktop has no hook system — so startup recall and the optional capture hook
48
+ cannot — Claude Desktop has no hook system — so startup recall and the capture hook
49
49
  have no equivalent there, and nothing is saved unless Claude calls `memory_save`. Two consequences, both permanent until Desktop grows hooks:
50
50
 
51
51
  - **Recall** is covered by the `memory_sessionContext` tool plus the server's `instructions`,
@@ -72,9 +72,11 @@ memory-hub-mcp setup
72
72
 
73
73
  The Claude Code hooks need `bash`, `curl` and `jq` (`jq` ships with macOS 15 and later; otherwise
74
74
  `brew install jq`); `setup` warns about any that are missing. `setup` also asks about
75
- auto-capture, which is off by default; switch it later with `memory-hub-mcp capture on` (or `off`).
75
+ auto-capture, which is on by default and also corrects memories you contradicted, Team ones
76
+ included; switch it later with `memory-hub-mcp capture on` (or `off`).
76
77
 
77
- `setup` asks which host you use — Claude Code, Claude Desktop, or both (`--code` / `--desktop` /
78
+ `setup` first asks "Set up Claude Code and Claude Desktop, with auto-capture? (Y/n)"; answering n asks
79
+ which host you use — Claude Code, Claude Desktop, or both (`--code` / `--desktop` /
78
80
  `--both` skip the prompt) — then logs you in with the same browser OAuth `sked` itself uses and
79
81
  mints a personal token from that session. For **Claude Code** it does everything
80
82
  `scripts/setup-dev.sh` does for contributors: registers the MCP server in `~/.claude.json`, puts
@@ -451,20 +451,25 @@ auto_capture_registered() {
451
451
  }
452
452
 
453
453
  # Same rule as session-stop.sh; change both together.
454
+ capture_explicitly_off() {
455
+ case "$(printf '%s' "${MEMORY_HUB_AUTO_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in 0|false|no|off) return 0 ;; esac
456
+ return 1
457
+ }
458
+
454
459
  capture_opted_in() {
455
460
  case "$(printf '%s' "${MEMORY_HUB_AUTO_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in 1|true|yes|on) return 0 ;; esac
456
- [ "${CLAUDE_PLUGIN_OPTION_CAPTURE:-}" = true ]
461
+ [ "${CLAUDE_PLUGIN_OPTION_CAPTURE:-true}" != false ]
457
462
  }
458
463
 
459
- if auto_capture_registered || { [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && capture_opted_in; }; then
460
- SAVE_LINE='Auto-capture is on: after long stretches and at session end, a background run saves or updates a Fact for this session'"'"'s work, shown as "memory-hub auto-saved" notices. Still save what matters yourself.'
464
+ if ! capture_explicitly_off && { auto_capture_registered || { [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && capture_opted_in; }; }; then
465
+ SAVE_LINE='Auto-capture is on: after long stretches and at session end, a background run saves what this session learned and corrects memories the user contradicted, Team ones included, shown as "memory-hub auto-saved" or "auto-updated" notices. Still save what matters yourself.'
461
466
  else
462
467
  SAVE_LINE='What follows is an automatic recall only - nothing in this session is saved unless you call memory_save.'
463
468
  fi
464
469
 
465
470
  STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
466
471
 
467
- # Lists captures the optional session-stop.sh hook saved in the background.
472
+ # Lists captures the session-stop.sh hook saved in the background.
468
473
  # Renders capture log lines as "<line number><TAB>notice"; the same in session-start.sh and user-prompt-submit.sh, change both together.
469
474
  render_capture_notices() {
470
475
  jq -R -r '
@@ -602,7 +607,9 @@ REMINDER="${REMINDER}Invoke the memory-hub skill during this session: memory_rec
602
607
  REMINDER="${REMINDER}investigating something that smells like prior context, and memory_save${NL}"
603
608
  REMINDER="${REMINDER}(type \"Fact\" or \"Scenario\") once a task produces a durable decision, root${NL}"
604
609
  REMINDER="${REMINDER}cause, or fix worth keeping for next time. On an error, memory_recall${NL}"
605
- REMINDER="${REMINDER}scope=all with its text first: another project may have the fix.${NL}${NL}"
610
+ REMINDER="${REMINDER}scope=all with its text first: another project may have the fix.${NL}"
611
+ REMINDER="${REMINDER}Auto learn: when the user states something new or corrects a memory in this${NL}"
612
+ REMINDER="${REMINDER}context, update that memory now (Team ones too) or save it; see \"Auto learn\".${NL}${NL}"
606
613
  REMINDER="${REMINDER}${STALE_MCP}${NUDGE}"
607
614
  NOTICES=$(collect_capture_notices "$STATE_DIR" "$((REMAINING - ${#REMINDER} - ${#DIAG}))" 2>/dev/null || true)
608
615
  [ -z "$NOTICES" ] || NOTICES="${NOTICES}${NL}${NL}"
@@ -44,9 +44,15 @@ start_plugin_move() {
44
44
  trap - HUP
45
45
  }
46
46
 
47
- opted_in() {
47
+ # Same three-state reading as session-start.sh and setup.ts; change all together.
48
+ explicitly_off() {
49
+ case "$(printf '%s' "${MEMORY_HUB_AUTO_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in 0|false|no|off) return 0 ;; esac
50
+ return 1
51
+ }
52
+
53
+ capture_enabled() {
48
54
  case "$(printf '%s' "${MEMORY_HUB_AUTO_CAPTURE:-}" | tr '[:upper:]' '[:lower:]')" in 1|true|yes|on) return 0 ;; esac
49
- [ "${CLAUDE_PLUGIN_OPTION_CAPTURE:-}" = true ]
55
+ [ "${CLAUDE_PLUGIN_OPTION_CAPTURE:-true}" != false ]
50
56
  }
51
57
 
52
58
  command -v jq >/dev/null 2>&1 || exit 0
@@ -58,8 +64,11 @@ umask 077
58
64
  STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
59
65
  start_plugin_move
60
66
 
61
- # The plugin registers this hook for everyone, so there it waits for an opt-in; a hand registration is the opt-in.
62
- if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && ! opted_in; then
67
+ # An explicit off stops every install. The plugin registers this hook for everyone and runs it unless the option is false; a hand registration is its own opt-in.
68
+ if explicitly_off; then
69
+ exit 0
70
+ fi
71
+ if [ -n "${CLAUDE_PLUGIN_ROOT:-}" ] && ! capture_enabled; then
63
72
  exit 0
64
73
  fi
65
74
 
@@ -177,8 +186,9 @@ existing_fact_uid() {
177
186
  }
178
187
 
179
188
  build_prompt() {
180
- local now existing="" ref uid head tail
189
+ local now today existing="" ref uid head tail learn
181
190
  now=$(date -u +%Y-%m-%dT%H:%MZ)
191
+ today=$(date -u +%Y-%m-%d)
182
192
  for ref in $(top_ticket_refs); do
183
193
  uid=$(existing_fact_uid "$ref")
184
194
  [ -n "$uid" ] || continue
@@ -200,7 +210,14 @@ EOF
200
210
  read -r -d '' tail <<'EOF' || true
201
211
  For anything not listed above: call memory_recall with a short query first; if one of your own memories already covers it, memory_update that memory with the merged, corrected full text. Otherwise memory_save (type "Fact" or "Scenario"). Never pass visibility: capture saves are Private. Never delete anything.
202
212
  EOF
203
- printf '%s\n%s%s' "${head//<NOW>/$now}" "$existing" "$tail"
213
+ read -r -d '' learn <<'EOF' || true
214
+ Auto learn: for each thing the user stated or confirmed that changes what the hub says, call memory_recall with scope=all and a short query. For each memory it contradicts, memory_get it in full, then:
215
+ - Do not edit it if it is Org or Restricted, a Team item on a repo none of your teams owns (memory_listTeams), or a project page (a Wiki page titled "<Project> › ...").
216
+ - Otherwise memory_update it with expectedLastModified set to its lastModifiedDate: make the first line "UPDATE <TODAY> (said in session): <what is true now>", correct the sentences that are now wrong, keep everything still true, and never pass source or visibility. On a Conflict reply, memory_get it again and retry once. A Not found reply means you cannot edit it.
217
+ - When you did not or could not edit it, save one Private Fact starting "could not update <uid>:" with what the user said; for a project page, name the page and its entry ID.
218
+ At most five corrections of memories you did not write per run; put the rest in that Fact.
219
+ EOF
220
+ printf '%s\n%s%s\n%s' "${head//<NOW>/$now}" "$existing" "$tail" "${learn//<TODAY>/$today}"
204
221
  }
205
222
 
206
223
  run_capture() {
@@ -211,7 +228,7 @@ run_capture() {
211
228
  nohup env MEMORY_HUB_STOP_HOOK_ACTIVE=1 MEMORY_HUB_CAPTURE=1 \
212
229
  MEMORY_HUB_CAPTURE_LOG="$STATE_DIR/captures-$SESSION_ID.jsonl" \
213
230
  "$CLAUDE_BIN" -p --resume "$SESSION_ID" \
214
- --allowedTools "mcp__memory-hub__memory_recall,mcp__memory-hub__memory_get,mcp__memory-hub__memory_save,mcp__memory-hub__memory_update,mcp__plugin_memory-hub_memory-hub__memory_recall,mcp__plugin_memory-hub_memory-hub__memory_get,mcp__plugin_memory-hub_memory-hub__memory_save,mcp__plugin_memory-hub_memory-hub__memory_update" \
231
+ --allowedTools "mcp__memory-hub__memory_recall,mcp__memory-hub__memory_get,mcp__memory-hub__memory_save,mcp__memory-hub__memory_update,mcp__memory-hub__memory_listTeams,mcp__plugin_memory-hub_memory-hub__memory_recall,mcp__plugin_memory-hub_memory-hub__memory_get,mcp__plugin_memory-hub_memory-hub__memory_save,mcp__plugin_memory-hub_memory-hub__memory_update,mcp__plugin_memory-hub_memory-hub__memory_listTeams" \
215
232
  --permission-prompts none \
216
233
  --model "${MEMORY_HUB_CAPTURE_MODEL:-sonnet}" \
217
234
  --no-session-persistence \
@@ -105,6 +105,10 @@ section before answering (`memory_getSkillGuide section="Stale memories"`, loade
105
105
  - With no checkout of the repo an item cites (for example in Claude Desktop), staleness cannot be
106
106
  worked out, so no item carries it: for each item you rely on that has a `source.verifiedAt`, say
107
107
  in the answer "verified <n> days ago".
108
+ - An item that starts with an `UPDATE <date> (said in session)` line, and whose cited code now
109
+ disagrees with it, is flagged, never fixed: leave it as it is, and say in the answer which memory,
110
+ what was said and when, and what the code shows. It is not one of the fixes. When the code agrees
111
+ with the line, the usual "still true" step applies and the line stays.
108
112
 
109
113
  Keep each fix (uid and what changed) for the closing line.
110
114
 
@@ -245,6 +249,11 @@ corrections found in steps 4 to 6 are already made by their `memory_update`. One
245
249
  durable point: a Fact for a decision or finding, a Skill for a how-to. Pass `supersedes` with the old
246
250
  uid when it replaces an existing memory, and a `source` when it came from code.
247
251
 
252
+ When the person corrects the answer, or adds something new, load the guide's rule
253
+ (`memory_getSkillGuide section="Auto learn"`) and apply it to the items the answer used. What the
254
+ person corrects or adds is the exception to "Save only what came from the sources read in steps 5
255
+ to 7". Those corrections count in the closing line like any update.
256
+
248
257
  Never save commercial terms (prices, rates, budgets), customer personal data, credentials, or text
249
258
  copied from a SOW or Slack. Restate it as what the system does or what was decided, and name the
250
259
  source.
@@ -13,4 +13,4 @@ stale on this machine the way this stub's own content once did. This file
13
13
  stays intentionally thin: only what the harness needs to discover and
14
14
  trigger the skill.
15
15
 
16
- Give every save a deliberate visibility by the guide's "What to share" rule (work knowledge is Team, on the project's repo by name), and state the choice and the reason. Follow the guide's "Stale memories" rules before relying on an item with a `staleness` field, and its "Skill drift" rule when a plugin skill contradicts the code.
16
+ Give every save a deliberate visibility by the guide's "What to share" rule (work knowledge is Team, on the project's repo by name), and state the choice and the reason. When the person states something new or corrects a memory in this session, follow the guide's "Auto learn" section. Follow the guide's "Stale memories" rules before relying on an item with a `staleness` field, and its "Skill drift" rule when a plugin skill contradicts the code.
@@ -143,6 +143,11 @@ Take the items in order. Before reading anything, skip and list:
143
143
  - `diffLines` of -1: the diff failed; flag it as not checked.
144
144
  - `editedByOtherWithin7Days`: someone else is working on it; never rewrite it. Count it as "already swept by a teammate" in the digest, not as waiting.
145
145
  - `editable: false`: flag it (the "Stale memories" rule on edits you cannot make).
146
+ - an item whose text starts with an `UPDATE <date> (said in session)` line that its changed code now
147
+ disagrees with: never rewrite it, and never move its `source`. A spoken correction can run ahead of
148
+ the code, so leave it as it is and list it under "Said in session, but the code disagrees" in the
149
+ digest. Only verifying shows the disagreement (the "Other items" step below); once it does, stop
150
+ there and spend no update on it.
146
151
  - tagged `Superseded`: a newer memory replaced it; report it, do not update it.
147
152
 
148
153
  In `dry-run` mode, read nothing more. Count as `apply` would, with each project handed over counted
@@ -173,7 +178,9 @@ In `apply` mode:
173
178
  1. `memory_get` the item for its text, `source` and `lastModifiedDate`.
174
179
  2. Verify: read each path in `changed` at `target`, and its change with
175
180
  `git -C <clone> diff <source.commit> <target> -- <paths>`.
176
- 3. Apply the section's "still true", "clearly wrong" or "unclear" step, with
181
+ 3. If the item starts with an `UPDATE <date> (said in session)` line and the code disagrees with
182
+ it, change nothing and list it, as above. When the code agrees with it, the line stays.
183
+ Otherwise apply the section's "still true", "clearly wrong" or "unclear" step, with
177
184
  `source: {repo: "<owner/name>", commit: "<target>"}` and `expectedLastModified` on every
178
185
  `memory_update`, keeping the item's visibility.
179
186
 
@@ -208,6 +215,10 @@ One digest for the whole run, headed with the mode and the date:
208
215
  3. Flagged and skipped items with why: too big, diff failed, not editable,
209
216
  superseded, unclear after verifying, not reached. Items edited by someone else in the last 7
210
217
  days are counted as already swept by a teammate.
218
+ Then a list headed "Said in session, but the code disagrees": for each item, the memory (by
219
+ title; by uid only when Private, with nothing else about it), what was said and when (the date on
220
+ its `UPDATE` line), and what the code shows. Nothing was rewritten; the person decides which side
221
+ is right.
211
222
  4. Per project: what the targeted updates and sources-only refreshes changed, by page title and
212
223
  entry ID, the core changes waiting ("run project-knowledge on <Project> to decide them"), and
213
224
  anything "Worth a look", such as new modules.
@@ -34,7 +34,7 @@ STATE_DIR="${MEMORY_HUB_STATE_DIR:-$HOME/.claude/memory-hub-hook/state}"
34
34
  mkdir -p "$STATE_DIR" 2>/dev/null || exit 0
35
35
  find "$STATE_DIR" -type f -mtime +7 -delete 2>/dev/null || true
36
36
 
37
- # Lists captures the optional session-stop.sh hook saved in the background.
37
+ # Lists captures the session-stop.sh hook saved in the background.
38
38
  # Renders capture log lines as "<line number><TAB>notice"; the same in session-start.sh and user-prompt-submit.sh, change both together.
39
39
  render_capture_notices() {
40
40
  jq -R -r '
package/dist/capture.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logCapture = exports.captureVisibility = exports.captureUpsert = exports.isCaptureMode = void 0;
3
+ exports.logCapture = exports.captureVisibility = exports.captureUpdateRefusal = exports.captureUpsert = exports.isCaptureMode = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const SIMILAR_OWN_FACT_FLOOR = 0.86;
6
6
  function isCaptureMode(env = process.env) {
@@ -80,6 +80,16 @@ async function captureUpsert(deps, input, env = process.env) {
80
80
  };
81
81
  }
82
82
  exports.captureUpsert = captureUpsert;
83
+ function captureUpdateRefusal(type, env = process.env) {
84
+ if (!isCaptureMode(env) || type !== 'Wiki') {
85
+ return undefined;
86
+ }
87
+ return {
88
+ message: 'Not updated: capture mode never edits a Wiki page. ' +
89
+ 'Save a Private Fact that names the page, its entry ID and what the user said, so project-knowledge can pick it up.',
90
+ };
91
+ }
92
+ exports.captureUpdateRefusal = captureUpdateRefusal;
83
93
  // An auto-capture is never reviewed before it is saved, so it stays with its author until they share it.
84
94
  function captureVisibility(requested, env = process.env) {
85
95
  return isCaptureMode(env) ? 'Private' : requested;
package/dist/cli.js CHANGED
@@ -103,18 +103,21 @@ else if (command === '--help' || command === '-h') {
103
103
  console.log(`memory-hub-mcp — MCP server for the Memory Hub
104
104
 
105
105
  memory-hub-mcp setup log in, then wire up Claude Code and/or Claude Desktop, and verify
106
- the token. Pass --code, --desktop or --both to skip the prompt.
106
+ the token. It asks one question first: set up both hosts with
107
+ auto-capture (Enter). Answer n to pick the host, and whether to turn
108
+ on auto-capture. Pass --code, --desktop or --both to skip the
109
+ questions; auto-capture is on unless you pass --no-capture.
107
110
  For Claude Code it installs the memory-hub plugin with auto-update
108
111
  on (needs the claude CLI and GitHub access; --no-plugin installs
109
112
  the hooks and skill directly instead). The server runs as
110
113
  npx ...@latest, so each start picks up the newest release;
111
- --no-auto-update pins this install instead. It asks about
112
- auto-capture; --capture or --no-capture answers for it.
114
+ --no-auto-update pins this install instead. On macOS it offers to
115
+ restart Claude Desktop at the end.
113
116
  memory-hub-mcp capture on|off
114
- turn auto-capture on or off: after long stretches and at session
115
- end, a background Claude run, using your Claude usage, saves what
116
- the session learned (new memories Private, updates keep their
117
- visibility). setup also asks.
117
+ turn auto-capture on or off (on by default). In the background,
118
+ Claude saves what each session learns and fixes hub memories you
119
+ corrected, Team ones included. New memories are Private. It uses
120
+ your Claude usage. With no argument, shows whether it is on.
118
121
  memory-hub-mcp import convert <packDir> --project <name> --prefix <PREFIX> [--by <name>] [--out <plan.json>] [--force]
119
122
  turn a knowledge pack folder (domains/<name> in the shared memory
120
123
  repo) into a plan of project knowledge pages, plus a review file
package/dist/index.js CHANGED
@@ -45,8 +45,11 @@ const INSTRUCTIONS = [
45
45
  'Call memory_sessionContext once at the start of a conversation to load this',
46
46
  "developer's persona, facts, skills and wiki pages before answering from scratch.",
47
47
  'Before wrapping up a task, save anything durable with memory_save — nothing is',
48
- 'saved automatically unless the user switched on auto-capture, and on hosts',
48
+ 'saved automatically unless auto-capture is on (the default in Claude Code), and on hosts',
49
49
  'without hooks (e.g. Claude Desktop) nothing can capture it.',
50
+ 'Auto learn: when the user states something new or corrects a memory in this',
51
+ 'conversation, update that memory now (Team ones too) or save it; see "Auto learn"',
52
+ 'in memory_getSkillGuide.',
50
53
  'Questions about a project or team work without a repo: find project pages with',
51
54
  'memory_list type=Wiki titlePrefix="<Project> ›", and when the hub has nothing, ask',
52
55
  'for sources and say reading them costs tokens.',
@@ -292,6 +295,10 @@ server.tool('memory_update', "Revise a memory (yours, or a Team item on your tea
292
295
  source: source_1.sourceSchema.nullable().optional().describe(`${source_1.SOURCE_DESCRIPTION} Pass it after re-checking the item against the repo; null clears the source.`),
293
296
  expectedLastModified: zod_1.z.string().min(1).optional().describe('The lastModifiedDate memory_get returned. Required when you are not the author. The update is refused if the item changed since.'),
294
297
  }, async (input) => {
298
+ const refused = (0, capture_1.captureUpdateRefusal)(input.type);
299
+ if (refused) {
300
+ return { content: [{ type: 'text', text: refused.message }] };
301
+ }
295
302
  const result = await (0, revise_1.performUpdate)({ client, embed: embeddings_1.embed }, input);
296
303
  (0, capture_1.logCapture)({ action: 'updated', type: input.type, uid: result.uid });
297
304
  return { content: [...embeddingNoticeBlocks(), { type: 'text', text: JSON.stringify(result) }] };
package/dist/revise.js CHANGED
@@ -77,8 +77,6 @@ async function performUpdate(deps, input) {
77
77
  ...changes,
78
78
  ...(repo !== undefined ? { repo } : {}),
79
79
  ...(embedding ? { embedding } : {}),
80
- // An unreviewed background run must never rewrite a teammate's item.
81
- ...((0, capture_1.isCaptureMode)() ? { authorOnly: true } : {}),
82
80
  };
83
81
  switch (type) {
84
82
  case 'Fact':
package/dist/setup.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runSetup = exports.runCapture = exports.registerPromptHook = exports.registerSessionStartHook = exports.removeMcpServer = exports.removeCopiedAssets = exports.setCapture = exports.captureOn = exports.CAPTURE_FLAG = exports.unregisterHooks = exports.claudeRunner = exports.installPlugin = exports.enableMarketplaceAutoUpdate = exports.removeUserEnv = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.writeJson = exports.readJson = exports.desktopConfigPath = exports.mcpLaunch = exports.lastLine = exports.isHubSource = exports.pluginInstalled = exports.installedPluginId = exports.installedPluginIds = exports.claudeConfigDir = exports.LEGACY_PLUGIN_ID = exports.PLUGIN_ID = exports.MARKETPLACE_REF = exports.MARKETPLACE_GIT_URL = exports.MARKETPLACE_REPO = exports.LEGACY_MARKETPLACE_NAME = exports.MARKETPLACE_NAME = exports.launchPath = exports.PACKAGE_SPEC = void 0;
3
+ exports.runSetup = exports.runCapture = exports.captureMessage = exports.processAncestors = exports.doneLine = exports.desktopRestartOffer = exports.insideClaudeDesktop = exports.chooseSetup = exports.registerPromptHook = exports.registerSessionStartHook = exports.removeMcpServer = exports.removeCopiedAssets = exports.setCapture = exports.captureOn = exports.CAPTURE_FLAG = exports.unregisterHooks = exports.claudeRunner = exports.installPlugin = exports.enableMarketplaceAutoUpdate = exports.removeUserEnv = exports.writeUserEnv = exports.writeDesktopConfig = exports.writeMcpServer = exports.functionUrl = exports.writeJson = exports.readJson = exports.desktopConfigPath = exports.mcpLaunch = exports.lastLine = exports.isHubSource = exports.pluginInstalled = exports.installedPluginId = exports.installedPluginIds = exports.claudeConfigDir = exports.LEGACY_PLUGIN_ID = exports.PLUGIN_ID = exports.MARKETPLACE_REF = exports.MARKETPLACE_GIT_URL = exports.MARKETPLACE_REPO = exports.LEGACY_MARKETPLACE_NAME = exports.MARKETPLACE_NAME = exports.launchPath = exports.PACKAGE_SPEC = void 0;
4
4
  const child_process_1 = require("child_process");
5
5
  const fs_1 = require("fs");
6
6
  const os_1 = require("os");
@@ -123,23 +123,26 @@ function askHidden(question) {
123
123
  muted = true;
124
124
  });
125
125
  }
126
+ const LOGIN_UNFINISHED = " The sked login didn't finish, so paste a token instead.";
126
127
  // Mirrors scripts/setup-dev.sh: never mint a token silently. `sked tenant login web`
127
128
  // runs the same browser OAuth the CLI already uses, then writes the result into its
128
129
  // own config. Which alias it lands under can't be assumed, so diff before/after and
129
130
  // take whichever entry's token changed.
130
131
  async function loginWithSked() {
131
- const tenant = (await ask(` Tenant/team name for the sked login? (default: ${DEFAULT_TENANT}): `)) || DEFAULT_TENANT;
132
- const env = (await ask(' Environment — test or production? (default: test): ')) || 'test';
133
- const confirm = await ask(' Log in with sked now? [Y/n]: ');
134
- if (confirm.toLowerCase() === 'n')
132
+ const tenant = (await ask(` Tenant name? (default: ${DEFAULT_TENANT}): `)) || DEFAULT_TENANT;
133
+ const env = (await ask(' Test or production? (default: test): ')) || 'test';
134
+ const confirm = await ask(' Log in now? (Y/n): ');
135
+ if (confirm.toLowerCase().startsWith('n')) {
136
+ console.log(LOGIN_UNFINISHED);
135
137
  return undefined;
138
+ }
136
139
  console.log(' Opening your browser...');
137
140
  const before = readJson(SKED_CONFIG).users || {};
138
141
  const result = (0, child_process_1.spawnSync)('sked', ['tenant', 'login', 'web', '-t', tenant, '-e', env, '-a', tenant, '-u', '-l', '0', '-o'], {
139
142
  stdio: 'inherit',
140
143
  });
141
144
  if (result.status !== 0) {
142
- console.log(" sked login didn't complete — falling back to manual paste.");
145
+ console.log(LOGIN_UNFINISHED);
143
146
  return undefined;
144
147
  }
145
148
  const after = readJson(SKED_CONFIG).users || {};
@@ -148,15 +151,14 @@ async function loginWithSked() {
148
151
  return { token: user.accessToken, apiBase: user.apiBasePath };
149
152
  }
150
153
  }
151
- console.log(" login succeeded but the token couldn't be found — falling back to manual paste.");
154
+ console.log(LOGIN_UNFINISHED);
152
155
  return undefined;
153
156
  }
154
157
  async function pasteToken() {
155
- console.log(' Or generate one at Pulse Web -> your profile (top right) -> Settings ->');
156
- console.log(' Developer tools -> API tokens -> Create. It is shown ONCE — Skedulo does');
157
- console.log(' not store it, so copy it now.');
158
- const host = (await ask(` Skedulo API host? (default: ${DEFAULT_API_HOST}): `)) || DEFAULT_API_HOST;
159
- const token = await askHidden(' Paste your personal Skedulo API token (input hidden), or press Enter to skip: ');
158
+ console.log(' Create one in Pulse Web: your profile (top right) > Settings > Developer tools >');
159
+ console.log(' API tokens > Create. It is shown once, so copy it now.');
160
+ const host = (await ask(` API host? (default: ${DEFAULT_API_HOST}): `)) || DEFAULT_API_HOST;
161
+ const token = await askHidden(' Paste your token (hidden), or press Enter to skip: ');
160
162
  if (!token)
161
163
  return undefined;
162
164
  return { token, apiBase: host };
@@ -308,18 +310,26 @@ function unregisterHooks(path) {
308
310
  exports.unregisterHooks = unregisterHooks;
309
311
  exports.CAPTURE_FLAG = 'MEMORY_HUB_AUTO_CAPTURE';
310
312
  const CAPTURE_EVENTS = ['Stop', 'SessionEnd'];
311
- // Same reading as the hooks' opted_in; change both together.
312
- function flagOn(value) {
313
- return typeof value === 'string' && ['1', 'true', 'yes', 'on'].includes(value.toLowerCase());
314
- }
315
- function captureOn(settingsPath) {
313
+ // Same three-state reading as session-start.sh and session-stop.sh; change all together.
314
+ function readFlag(value) {
315
+ const v = typeof value === 'string' ? value.toLowerCase() : '';
316
+ if (['0', 'false', 'no', 'off'].includes(v))
317
+ return 'off';
318
+ if (['1', 'true', 'yes', 'on'].includes(v))
319
+ return 'on';
320
+ return 'unset';
321
+ }
322
+ // The plugin option defaults to on, so an unset flag under the plugin means on.
323
+ function captureOn(settingsPath, plugin = false) {
316
324
  const settings = readJson(settingsPath);
317
- if (flagOn(settings.env?.[exports.CAPTURE_FLAG]))
318
- return true;
319
- return CAPTURE_EVENTS.some((event) => (settings.hooks?.[event] ?? []).some((entry) => (entry.hooks || []).some((h) => typeof h.command === 'string' && h.command.includes('session-stop.sh'))));
325
+ const flag = readFlag(settings.env?.[exports.CAPTURE_FLAG]);
326
+ if (flag !== 'unset')
327
+ return flag === 'on';
328
+ const registered = CAPTURE_EVENTS.some((event) => (settings.hooks?.[event] ?? []).some((entry) => (entry.hooks || []).some((h) => typeof h.command === 'string' && h.command.includes('session-stop.sh'))));
329
+ return registered || plugin;
320
330
  }
321
331
  exports.captureOn = captureOn;
322
- // With the plugin its own hooks wait for the flag; without it the copied hook is registered here.
332
+ // With the plugin its own hooks read the flag; without it the copied hook is registered here.
323
333
  function setCapture(settingsPath, on, mode) {
324
334
  if (on) {
325
335
  writeUserEnv(settingsPath, { [exports.CAPTURE_FLAG]: '1' });
@@ -329,7 +339,7 @@ function setCapture(settingsPath, on, mode) {
329
339
  }
330
340
  return;
331
341
  }
332
- removeUserEnv(settingsPath, exports.CAPTURE_FLAG);
342
+ writeUserEnv(settingsPath, { [exports.CAPTURE_FLAG]: '0' });
333
343
  if (!mode.plugin && mode.hookPath) {
334
344
  const settings = readJson(settingsPath);
335
345
  let changed = false;
@@ -409,14 +419,14 @@ async function verify(url, token) {
409
419
  signal: AbortSignal.timeout(10000),
410
420
  });
411
421
  if (response.ok) {
412
- console.log(' token works — got a real response from the memory-hub function');
422
+ console.log(' Token works.');
413
423
  }
414
424
  else {
415
- console.log(` got HTTP ${response.status} from the memory-hub function — token may be wrong or expired`);
425
+ console.log(` The hub answered HTTP ${response.status}: the token may be wrong or expired.`);
416
426
  }
417
427
  }
418
428
  catch {
419
- console.log(` couldn't reach ${url} — check your network, not necessarily the token`);
429
+ console.log(` Couldn't reach ${url}. Check your network.`);
420
430
  }
421
431
  }
422
432
  // The first npx run downloads ~430 MB of dependencies; doing it here keeps the host's first start fast.
@@ -424,17 +434,93 @@ function warmLaunch(launch) {
424
434
  const result = (0, child_process_1.spawnSync)(launch.command, [...launch.args, '--help'], { stdio: 'ignore', timeout: 300000 });
425
435
  return result.status === 0;
426
436
  }
427
- async function chooseHosts() {
428
- console.log(' Which host do you use?');
429
- console.log(' 1) Claude Code (MCP server + startup hook + skill)');
430
- console.log(' 2) Claude Desktop (MCP server only — Desktop has no hooks)');
431
- console.log(' 3) both');
432
- const answer = (await ask(' Choice? (default: 1): ')) || '1';
433
- if (answer === '2')
434
- return ['desktop'];
435
- if (answer === '3')
436
- return ['code', 'desktop'];
437
- return ['code'];
437
+ const yes = (answer) => !answer.toLowerCase().startsWith('n');
438
+ async function chooseSetup(io) {
439
+ const flagCapture = io.argv.includes('--no-capture') ? false : io.argv.includes('--capture') ? true : undefined;
440
+ if (io.argv.includes('--code'))
441
+ return { hosts: ['code'], capture: flagCapture ?? true };
442
+ if (io.argv.includes('--desktop'))
443
+ return { hosts: ['desktop'], capture: flagCapture ?? true };
444
+ if (io.argv.includes('--both'))
445
+ return { hosts: ['code', 'desktop'], capture: flagCapture ?? true };
446
+ if (!io.isTTY) {
447
+ io.log(' This is not an interactive terminal. Run setup from a terminal, or pass');
448
+ io.log(' --code, --desktop or --both.');
449
+ return undefined;
450
+ }
451
+ if (flagCapture === undefined) {
452
+ io.log(' Auto-capture: in the background, Claude saves what each session learns and');
453
+ io.log(' fixes hub memories you corrected, Team ones included. It uses your Claude usage.');
454
+ if (yes(await io.ask(' Set up Claude Code and Claude Desktop, with auto-capture? (Y/n): '))) {
455
+ return { hosts: ['code', 'desktop'], capture: true };
456
+ }
457
+ }
458
+ io.log(' Which host do you use?');
459
+ io.log(' 1) Claude Code');
460
+ io.log(' 2) Claude Desktop (no hooks: nothing is saved in the background)');
461
+ io.log(' 3) both');
462
+ const answer = (await io.ask(' Choice? (default: 1): ')) || '1';
463
+ const hosts = answer === '2' ? ['desktop'] : answer === '3' ? ['code', 'desktop'] : ['code'];
464
+ if (flagCapture !== undefined)
465
+ return { hosts, capture: flagCapture };
466
+ if (!hosts.includes('code'))
467
+ return { hosts, capture: false };
468
+ return { hosts, capture: yes(await io.ask(' Turn on auto-capture? (Y/n): ')) };
469
+ }
470
+ exports.chooseSetup = chooseSetup;
471
+ function insideClaudeDesktop(ancestors) {
472
+ return ancestors.some((command) => command.includes('/Claude.app/Contents/'));
473
+ }
474
+ exports.insideClaudeDesktop = insideClaudeDesktop;
475
+ function desktopRestartOffer(opts) {
476
+ return opts.os === 'darwin' && !opts.inside && opts.running;
477
+ }
478
+ exports.desktopRestartOffer = desktopRestartOffer;
479
+ function doneLine(opts) {
480
+ if (opts.code && opts.desktopLeft)
481
+ return 'Done. Start a new Claude Code session, and quit and reopen Claude Desktop, to pick this up.';
482
+ if (opts.code)
483
+ return 'Done. Start a new Claude Code session to pick this up.';
484
+ if (opts.desktopLeft)
485
+ return 'Done. Quit and reopen Claude Desktop to pick this up.';
486
+ return 'Done.';
487
+ }
488
+ exports.doneLine = doneLine;
489
+ const runPs = (pid) => {
490
+ const result = (0, child_process_1.spawnSync)('ps', ['-o', 'ppid=,command=', '-p', String(pid)], { encoding: 'utf8' });
491
+ return result.status === 0 ? (result.stdout || '').trim() : '';
492
+ };
493
+ function processAncestors(pid = process.pid, run = runPs) {
494
+ const commands = [];
495
+ let current = pid;
496
+ for (let depth = 0; depth < 64 && current > 1; depth++) {
497
+ const match = /^\s*(\d+)\s+(.*)$/.exec(run(current));
498
+ if (!match)
499
+ break;
500
+ commands.push(match[2]);
501
+ current = Number(match[1]);
502
+ }
503
+ return commands;
504
+ }
505
+ exports.processAncestors = processAncestors;
506
+ function desktopRunning() {
507
+ return (0, child_process_1.spawnSync)('pgrep', ['-x', 'Claude']).status === 0;
508
+ }
509
+ function quitDesktop() {
510
+ return (0, child_process_1.spawnSync)('osascript', ['-e', 'quit app "Claude"'], { timeout: 15000 }).status === 0;
511
+ }
512
+ function openDesktop() {
513
+ return (0, child_process_1.spawnSync)('open', ['-a', 'Claude']).status === 0;
514
+ }
515
+ async function restartDesktop() {
516
+ if (!quitDesktop())
517
+ return false;
518
+ for (let waited = 0; desktopRunning(); waited += 500) {
519
+ if (waited >= 10000)
520
+ return false;
521
+ await new Promise((done) => setTimeout(done, 500));
522
+ }
523
+ return openDesktop();
438
524
  }
439
525
  function existingToken(hosts) {
440
526
  if (hosts.includes('code')) {
@@ -447,38 +533,44 @@ function existingToken(hosts) {
447
533
  const env = readJson(desktopConfigPath()).mcpServers?.['memory-hub']?.env || {};
448
534
  return { token: env.MEMORY_HUB_MCP_TOKEN, url: env.MEMORY_HUB_FUNCTION_URL };
449
535
  }
450
- const CAPTURE_SWITCH_HINT = 'Switch it any time with `npx -y @skedulo/memory-hub-mcp@latest capture on` (or `off`).';
536
+ function captureSectionLine(on) {
537
+ return on
538
+ ? ' On. Turn it off any time: npx -y @skedulo/memory-hub-mcp@latest capture off'
539
+ : ' Off. Turn it on any time: npx -y @skedulo/memory-hub-mcp@latest capture on';
540
+ }
451
541
  function warnHookTools() {
452
542
  if ((0, os_1.platform)() === 'win32') {
453
- console.log(' warning: the hooks are bash scripts, so on Windows they only run inside Git Bash or WSL');
543
+ console.log(' The hooks are bash scripts, so on Windows they only run inside Git Bash or WSL.');
454
544
  }
455
545
  for (const tool of ['bash', 'curl', 'jq']) {
456
546
  if ((0, child_process_1.spawnSync)('which', [tool]).status !== 0) {
457
- console.log(` warning: ${tool} is not installed. The hooks need it, so memory is not injected until you install it (macOS: brew install ${tool}).`);
547
+ console.log(` ${tool} is not installed, so memories are not loaded at startup. Install it (macOS: brew install ${tool}).`);
458
548
  }
459
549
  }
460
550
  }
461
- async function askCapture(current) {
462
- console.log(' After long stretches and at session end, a background Claude run saves what the');
463
- console.log(' session learned. New memories are Private (shared only if you share them); an');
464
- console.log(' update keeps the memory\'s visibility. It uses your Claude usage, and you see what');
465
- console.log(' it saved at the start of your next session.');
466
- const answer = (await ask(` Turn on auto-capture? (${current ? 'Y/n' : 'y/N'}): `)).toLowerCase();
467
- if (!answer)
468
- return current;
469
- return answer.startsWith('y');
551
+ function captureMessage(state) {
552
+ switch (state) {
553
+ case 'status-on':
554
+ return ['Auto-capture is on.', 'Usage: memory-hub-mcp capture on|off'];
555
+ case 'status-off':
556
+ return ['Auto-capture is off.', 'Usage: memory-hub-mcp capture on|off'];
557
+ case 'on':
558
+ return [
559
+ 'Auto-capture is on: in the background, Claude saves what each session learns and fixes hub memories you corrected, Team ones included. New memories are Private. It uses your Claude usage. Restart Claude Code to pick this up.',
560
+ ];
561
+ case 'off':
562
+ return ['Auto-capture is off. Restart Claude Code to pick this up.'];
563
+ }
470
564
  }
565
+ exports.captureMessage = captureMessage;
471
566
  async function runCapture(argv = []) {
472
567
  const settingsPath = (0, path_1.join)(claudeConfigDir(), 'settings.json');
473
568
  const plugin = pluginInstalled();
474
569
  const hookPath = (0, path_1.join)((0, asset_sync_1.installDirs)().hookDir, 'session-stop.sh');
475
570
  const choice = argv[0];
476
- const pluginNote = "If you turned on the plugin's Auto-capture option in /plugin configure, that keeps it on too.";
477
571
  if (choice !== 'on' && choice !== 'off') {
478
- console.log(`auto-capture is ${captureOn(settingsPath) ? 'on' : 'off'} in ${settingsPath}.`);
479
- if (plugin)
480
- console.log(pluginNote);
481
- console.log('Usage: memory-hub-mcp capture on|off');
572
+ for (const line of captureMessage(captureOn(settingsPath, plugin) ? 'status-on' : 'status-off'))
573
+ console.log(line);
482
574
  return;
483
575
  }
484
576
  if (choice === 'on' && !plugin && !(0, fs_1.existsSync)(hookPath)) {
@@ -487,18 +579,8 @@ async function runCapture(argv = []) {
487
579
  return;
488
580
  }
489
581
  setCapture(settingsPath, choice === 'on', { plugin, hookPath: plugin ? undefined : hookPath });
490
- if (choice === 'on') {
491
- console.log('auto-capture is on: after long stretches and at session end, a background Claude run, using your Claude usage, saves what the session learned. New memories are Private; updates keep their visibility.');
492
- }
493
- else if (captureOn(settingsPath)) {
494
- console.log(`auto-capture is still on: a session-stop.sh entry under Stop or SessionEnd in ${settingsPath} keeps it running. Remove that entry by hand to stop it.`);
495
- }
496
- else {
497
- console.log('auto-capture is off.');
498
- if (plugin)
499
- console.log(pluginNote);
500
- }
501
- console.log('Restart Claude Code to pick this up.');
582
+ for (const line of captureMessage(choice))
583
+ console.log(line);
502
584
  }
503
585
  exports.runCapture = runCapture;
504
586
  const QUIET_SKIPS = ['not installed', 'already moved', 'not released yet'];
@@ -528,14 +610,9 @@ function withMoveLock(fn) {
528
610
  return true;
529
611
  }
530
612
  function moveLegacyPlugin() {
531
- const say = (line) => {
532
- console.log();
533
- console.log('==> Claude Code plugin');
534
- console.log(line);
535
- };
536
613
  const run = claudeRunner();
537
614
  if (!run) {
538
- say(` kept ${exports.LEGACY_PLUGIN_ID}: the claude CLI is not on PATH to move it to ${exports.PLUGIN_ID}.`);
615
+ console.log(` kept ${exports.LEGACY_PLUGIN_ID}: the claude CLI is not on PATH to move it to ${exports.PLUGIN_ID}.`);
539
616
  return;
540
617
  }
541
618
  let result;
@@ -543,58 +620,52 @@ function moveLegacyPlugin() {
543
620
  result = (0, migrate_plugin_1.migratePlugin)({ run, configDir: claudeConfigDir(), log: () => { } });
544
621
  });
545
622
  if (!locked || !result) {
546
- say(` a move of ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID} is already running; re-run setup in a minute if it is still listed.`);
623
+ console.log(` a move of ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID} is already running; re-run setup in a minute if it is still listed.`);
547
624
  return;
548
625
  }
549
626
  if (result.status === 'moved' && result.reason.startsWith('retired'))
550
- say(` removed the old ${exports.LEGACY_PLUGIN_ID} install; ${exports.PLUGIN_ID} stays.`);
627
+ console.log(` removed the old ${exports.LEGACY_PLUGIN_ID} install; ${exports.PLUGIN_ID} stays.`);
551
628
  else if (result.status === 'moved')
552
- say(` moved ${exports.LEGACY_PLUGIN_ID} to its new ID ${exports.PLUGIN_ID}; it loads at the next session.`);
629
+ console.log(` moved ${exports.LEGACY_PLUGIN_ID} to its new ID ${exports.PLUGIN_ID}; it loads at the next session.`);
553
630
  else if (result.status === 'failed')
554
- say(` couldn't move ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID}: ${result.reason}.`);
631
+ console.log(` couldn't move ${exports.LEGACY_PLUGIN_ID} to ${exports.PLUGIN_ID}: ${result.reason}.`);
555
632
  else if (!QUIET_SKIPS.includes(result.reason))
556
- say(` kept ${exports.LEGACY_PLUGIN_ID} (${result.reason}).`);
633
+ console.log(` kept ${exports.LEGACY_PLUGIN_ID} (${result.reason}).`);
557
634
  }
558
635
  async function runSetup(argv = []) {
559
636
  console.log('==> Setting up the memory hub');
560
- let hosts;
561
- if (argv.includes('--code'))
562
- hosts = ['code'];
563
- else if (argv.includes('--desktop'))
564
- hosts = ['desktop'];
565
- else if (argv.includes('--both'))
566
- hosts = ['code', 'desktop'];
567
- else if (!process.stdin.isTTY) {
568
- console.log(' Not an interactive terminal. Re-run from a terminal, or pass');
569
- console.log(' --code, --desktop or --both.');
637
+ const isTTY = Boolean(process.stdin.isTTY);
638
+ const choice = await chooseSetup({ argv, isTTY, ask, log: (line) => console.log(line) });
639
+ if (!choice) {
570
640
  process.exitCode = 1;
571
641
  return;
572
642
  }
573
- else
574
- hosts = await chooseHosts();
643
+ const { hosts, capture } = choice;
575
644
  const prior = existingToken(hosts);
576
645
  let credentials;
577
646
  let token = prior.token;
578
647
  console.log();
579
- console.log('==> Checking MEMORY_HUB_MCP_TOKEN');
648
+ console.log('==> Hub token');
580
649
  if (token) {
581
- console.log(' already set — keeping it');
650
+ console.log(' Already set, keeping it.');
582
651
  }
583
- else if (!process.stdin.isTTY) {
584
- console.log(' no token set, and this is not an interactive terminal.');
585
- console.log(' Re-run `memory-hub-mcp setup` from a terminal.');
652
+ else if (!isTTY) {
653
+ console.log(' No token yet, and this is not an interactive terminal. Run setup from a terminal.');
586
654
  process.exitCode = 1;
587
655
  return;
588
656
  }
589
657
  else {
590
658
  if ((0, child_process_1.spawnSync)('which', ['sked']).status === 0) {
591
- console.log(' Not set yet. Easiest way: log in once via sked (opens your browser).');
659
+ console.log(' No token yet. Log in with sked to get one (opens your browser).');
592
660
  credentials = await loginWithSked();
593
661
  }
662
+ else {
663
+ console.log(' No token yet.');
664
+ }
594
665
  if (!credentials)
595
666
  credentials = await pasteToken();
596
667
  if (!credentials) {
597
- console.log(' No token provided — nothing written. Re-run when you have one.');
668
+ console.log(' No token, so nothing was changed. Run setup again when you have one.');
598
669
  process.exitCode = 1;
599
670
  return;
600
671
  }
@@ -609,115 +680,105 @@ async function runSetup(argv = []) {
609
680
  console.log();
610
681
  console.log('==> Updates');
611
682
  if (autoUpdate) {
612
- console.log(` each start runs the newest published version (${exports.PACKAGE_SPEC}), and refreshes`);
613
- console.log(' any hooks and skill setup copied to match. --no-auto-update pins this install instead.');
614
- console.log(" fetching it into npm's cache now, so the first start is fast...");
683
+ console.log(' Each start uses the newest version (--no-auto-update keeps this one instead).');
684
+ console.log(' Downloading it now, so the first start is fast...');
615
685
  if (!warmLaunch(launch)) {
616
- console.log(" warning: couldn't fetch it. The first start needs the network and may be slow;");
617
- console.log(' re-run with --no-auto-update if this machine is often offline.');
686
+ console.log(" Couldn't download it. The first start needs the network and may be slow.");
618
687
  }
619
688
  }
620
689
  else {
621
- console.log(' pinned to this install. Update with `npm i -g @skedulo/memory-hub-mcp` and re-run setup.');
690
+ console.log(' Kept this version. To update, run npm i -g @skedulo/memory-hub-mcp and setup again.');
622
691
  }
623
692
  const settingsPath = (0, path_1.join)(claudeConfigDir(), 'settings.json');
624
- let plugin = hosts.includes('code') && pluginInstalled();
625
- if (hosts.includes('code') && !plugin && !argv.includes('--no-plugin')) {
693
+ if (hosts.includes('code')) {
626
694
  console.log();
627
- console.log('==> Claude Code plugin');
628
- const run = claudeRunner();
629
- if (!run) {
630
- console.log(' the `claude` CLI is not on PATH, so the hooks and skill are installed directly instead.');
695
+ console.log('==> Claude Code');
696
+ let plugin = pluginInstalled();
697
+ let installedNow = false;
698
+ if (!plugin && !argv.includes('--no-plugin')) {
699
+ const run = claudeRunner();
700
+ if (!run) {
701
+ console.log(" The claude command isn't on your PATH, so the MCP server, hooks and skills are installed directly.");
702
+ }
703
+ else {
704
+ console.log(' Installing the memory-hub plugin from GitHub (uses your GitHub access)...');
705
+ const result = installPlugin(run, settingsPath);
706
+ plugin = result.ok;
707
+ installedNow = result.ok;
708
+ if (!result.ok)
709
+ console.log(` Couldn't install the plugin (${result.reason}), so the MCP server, hooks and skills are installed directly.`);
710
+ }
631
711
  }
632
- else {
633
- console.log(` installing ${exports.PLUGIN_ID} from ${exports.MARKETPLACE_REPO}#${exports.MARKETPLACE_REF} (uses your GitHub access)...`);
634
- const result = installPlugin(run, settingsPath);
635
- plugin = result.ok;
636
- console.log(result.ok
637
- ? ' installed, with auto-update on: skill and hook changes arrive with each new session.'
638
- : ` couldn't install it (${result.reason}), so the hooks and skill are installed directly instead.`);
712
+ if (plugin && installedPluginIds().includes(exports.LEGACY_PLUGIN_ID)) {
713
+ // Before the move: a settings token is what lets an install with a pasted token move.
714
+ writeUserEnv(settingsPath, env);
715
+ moveLegacyPlugin();
716
+ plugin = pluginInstalled();
717
+ if (!plugin)
718
+ console.log(' No memory-hub plugin is installed now, so the MCP server, hooks and skills are installed directly.');
639
719
  }
640
- }
641
- if (plugin && installedPluginIds().includes(exports.LEGACY_PLUGIN_ID)) {
642
- // Before the move: a settings token is what lets an install with a pasted token move.
643
- writeUserEnv(settingsPath, env);
644
- moveLegacyPlugin();
645
- plugin = pluginInstalled();
646
- if (!plugin)
647
- console.log(' no memory-hub plugin is installed now, so the hooks and skill are installed directly instead.');
648
- }
649
- if (plugin) {
650
- console.log();
651
- console.log('==> Claude Code');
652
- writeUserEnv(settingsPath, env);
653
- const pluginId = installedPluginId() ?? exports.PLUGIN_ID;
654
- console.log(` the ${pluginId} plugin brings the MCP server, hooks and skill, so setup only`);
655
- console.log(' stores your token for them, and keeps the plugin on auto-update.');
656
- enableMarketplaceAutoUpdate(settingsPath, pluginId === exports.LEGACY_PLUGIN_ID ? exports.LEGACY_MARKETPLACE_NAME : exports.MARKETPLACE_NAME);
657
- const hooks = unregisterHooks(settingsPath);
658
- const server = removeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'));
659
- const copies = removeCopiedAssets(settingsPath);
660
- if (hooks > 0 || server) {
661
- const parts = [hooks > 0 ? `${hooks} hook registration${hooks > 1 ? 's' : ''}` : '', server ? 'the ~/.claude.json MCP server' : ''];
662
- console.log(` removed ${parts.filter(Boolean).join(' and ')} that duplicated the plugin (.bak kept)`);
720
+ if (plugin) {
721
+ writeUserEnv(settingsPath, env);
722
+ const pluginId = installedPluginId() ?? exports.PLUGIN_ID;
723
+ console.log(installedNow
724
+ ? ' Installed. It updates itself at each new session, and your token is saved for it.'
725
+ : ` The ${pluginId} plugin is already installed. Your token is saved for it.`);
726
+ enableMarketplaceAutoUpdate(settingsPath, pluginId === exports.LEGACY_PLUGIN_ID ? exports.LEGACY_MARKETPLACE_NAME : exports.MARKETPLACE_NAME);
727
+ const hooks = unregisterHooks(settingsPath);
728
+ const server = removeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'));
729
+ const copies = removeCopiedAssets(settingsPath);
730
+ if (hooks > 0)
731
+ console.log(` Removed ${hooks} old hook ${hooks > 1 ? 'entries' : 'entry'} the plugin replaces (backup kept as .bak).`);
732
+ if (server || copies.length > 0) {
733
+ const parts = [server ? 'MCP server entry' : '', copies.length > 0 ? 'hook and skill files' : ''];
734
+ console.log(` Removed the old ${parts.filter(Boolean).join(' and ')} the plugin replaces.`);
735
+ }
663
736
  }
664
- if (copies.length > 0) {
665
- console.log(` removed ${copies.length} copied skill/hook file${copies.length > 1 ? 's' : ''} the plugin replaces`);
737
+ else {
738
+ writeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'), launch.command, serverEnv, launch.args);
739
+ console.log(` MCP server -> ${shown}`);
740
+ // The hook is a shell script, so it reads the token from the environment Claude
741
+ // Code gives it, not from the MCP server's env block.
742
+ writeUserEnv(settingsPath, env);
743
+ const { hookPath, promptHookPath } = installAssets();
744
+ const { already, replaced } = registerSessionStartHook(settingsPath, hookPath);
745
+ const note = already
746
+ ? ' (already registered)'
747
+ : replaced > 0
748
+ ? ` (replaced ${replaced} earlier registration${replaced > 1 ? 's' : ''})`
749
+ : '';
750
+ console.log(` SessionStart hook -> ${hookPath}${note}`);
751
+ const prompt = registerPromptHook(settingsPath, promptHookPath);
752
+ console.log(` UserPromptSubmit hook -> ${promptHookPath}${prompt.already ? ' (already registered)' : ''}`);
753
+ console.log(` skills -> ~/.claude/skills/ (${(0, asset_sync_1.packagedSkills)(ASSETS).join(', ')})`);
666
754
  }
667
- }
668
- else if (hosts.includes('code')) {
669
- console.log();
670
- console.log('==> Claude Code');
671
- writeMcpServer((0, path_1.join)((0, os_1.homedir)(), '.claude.json'), launch.command, serverEnv, launch.args);
672
- console.log(` MCP server -> ${shown}`);
673
- // The hook is a shell script, so it reads the token from the environment Claude
674
- // Code gives it, not from the MCP server's env block.
675
- writeUserEnv(settingsPath, env);
676
- const { hookPath, promptHookPath } = installAssets();
677
- const { already, replaced } = registerSessionStartHook(settingsPath, hookPath);
678
- const note = already
679
- ? ' (already registered)'
680
- : replaced > 0
681
- ? ` (replaced ${replaced} earlier registration${replaced > 1 ? 's' : ''})`
682
- : '';
683
- console.log(` SessionStart hook -> ${hookPath}${note}`);
684
- const prompt = registerPromptHook(settingsPath, promptHookPath);
685
- console.log(` UserPromptSubmit hook -> ${promptHookPath}${prompt.already ? ' (already registered)' : ''}`);
686
- console.log(` skills -> ~/.claude/skills/ (${(0, asset_sync_1.packagedSkills)(ASSETS).join(', ')})`);
687
- }
688
- if (hosts.includes('code')) {
689
755
  warnHookTools();
690
756
  console.log();
691
757
  console.log('==> Auto-capture');
692
- const hookPath = plugin ? undefined : (0, path_1.join)((0, asset_sync_1.installDirs)().hookDir, 'session-stop.sh');
693
- let on = captureOn(settingsPath);
694
- if (argv.includes('--capture'))
695
- on = true;
696
- else if (argv.includes('--no-capture'))
697
- on = false;
698
- else if (process.stdin.isTTY)
699
- on = await askCapture(on);
700
- setCapture(settingsPath, on, { plugin, hookPath });
701
- console.log(on ? ` on. ${CAPTURE_SWITCH_HINT}` : ` off. ${CAPTURE_SWITCH_HINT}`);
758
+ setCapture(settingsPath, capture, { plugin, hookPath: plugin ? undefined : (0, path_1.join)((0, asset_sync_1.installDirs)().hookDir, 'session-stop.sh') });
759
+ console.log(captureSectionLine(capture));
702
760
  }
703
761
  if (hosts.includes('desktop')) {
704
762
  console.log();
705
763
  console.log('==> Claude Desktop');
706
764
  const path = desktopConfigPath();
707
765
  writeMcpServer(path, launch.command, serverEnv, launch.args);
708
- console.log(` MCP server -> ${shown}`);
709
- console.log(` config -> ${path}`);
710
- console.log(' no hook: Desktop has no hook system, so startup injection and');
711
- console.log(' background capture are Claude Code only; nothing is saved automatically.');
766
+ console.log(` Added the memory hub to Claude Desktop (${path}).`);
767
+ console.log(' Desktop has no hooks, so nothing is saved in the background. Claude still updates');
768
+ console.log(' memories when you correct it.');
712
769
  }
713
770
  console.log();
714
- console.log('==> Verifying');
715
- console.log(` endpoint: ${url}`);
771
+ console.log('==> Checking');
716
772
  await verify(url, token);
773
+ let desktopLeft = hosts.includes('desktop');
774
+ if (desktopLeft && isTTY && (0, os_1.platform)() === 'darwin') {
775
+ const offer = desktopRestartOffer({ os: (0, os_1.platform)(), inside: insideClaudeDesktop(processAncestors()), running: desktopRunning() });
776
+ if (offer && yes(await ask(' Restart Claude Desktop now? It closes all its open windows. (Y/n): '))) {
777
+ desktopLeft = !(await restartDesktop());
778
+ console.log(desktopLeft ? " Couldn't restart Claude Desktop." : ' Restarted Claude Desktop.');
779
+ }
780
+ }
717
781
  console.log();
718
- if (hosts.includes('code'))
719
- console.log('Restart Claude Code to pick this up.');
720
- if (hosts.includes('desktop'))
721
- console.log('Quit Claude Desktop completely and reopen it to pick this up.');
782
+ console.log(doneLine({ code: hosts.includes('code'), desktopLeft }));
722
783
  }
723
784
  exports.runSetup = runSetup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skedulo/memory-hub-mcp",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "description": "MCP server for the Memory Hub: recall and save developer memory from Claude Code and Claude Desktop.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
package/skill-guide.md CHANGED
@@ -10,8 +10,8 @@ that is out of date, follow "Stale memories" below.
10
10
  If the session-start hook (see `memory-hub-hook/`) is registered, it already
11
11
  injected your own and your team's recent facts and skills as context. This
12
12
  skill covers what to do *during* the session, beyond that automatic
13
- injection. Recall never saves anything; see "Automatic capture (when enabled)"
14
- for the one optional hook that does.
13
+ injection. Recall never saves anything; see "Automatic capture"
14
+ for the one hook that does.
15
15
 
16
16
  ## Recall on demand
17
17
 
@@ -249,17 +249,20 @@ When the person says "share them":
249
249
  deliberately made Private.
250
250
  4. Report each uid you shared, and each that stayed `Private` and why.
251
251
 
252
- ## Automatic capture (when enabled)
252
+ ## Automatic capture
253
253
 
254
- Nothing saves on its own unless the user has switched on auto-capture. It is
255
- off by default: `setup` asks, and `npx -y @skedulo/memory-hub-mcp@latest capture on`
256
- (or `off`) switches it, as does the plugin's Auto-capture option. The
257
- session-start Reminder says "Auto-capture is on" when it is. Without it, a
258
- memory exists only if you called `memory_save`. If the user asks how to turn it
259
- on, give them that one command; never ask them to edit hook JSON.
254
+ Auto-capture is on by default in Claude Code: `setup` asks first (the default
255
+ is yes) and the plugin's Auto-capture option defaults to on. Turning it off is
256
+ explicit: `npx -y @skedulo/memory-hub-mcp@latest capture off` (or `on`), which
257
+ beats the plugin option. The session-start Reminder says "Auto-capture is on"
258
+ when it is. Claude Desktop has no hooks, so nothing captures there: it gets the
259
+ live rule under "Auto learn", and anything else is saved only by
260
+ `memory_save`. If the user asks how to turn capture off, give them that one
261
+ command; never ask them to edit hook JSON.
260
262
 
261
263
  When it runs, it resumes the session headlessly and asks the model to keep
262
- anything durable:
264
+ anything durable, and to correct memories the person contradicted, Team ones
265
+ included, by the rules in "Auto learn":
263
266
 
264
267
  - **`Stop`**: at most every 30 minutes (`MEMORY_HUB_CAPTURE_INTERVAL_MIN`) and
265
268
  only with 40 or more new transcript lines (`MEMORY_HUB_CAPTURE_MIN_NEW_LINES`).
@@ -269,8 +272,9 @@ It updates the existing Fact for a ticket instead of adding copies, so a
269
272
  ticket's Fact is revised as the work moves on. New memories it saves are
270
273
  Private, even in a repo linked to a team, because nobody reviewed them first;
271
274
  the user shares one with `memory_setVisibility` once they have read it. An
272
- update to an existing memory keeps that memory's visibility. Saving yourself is still the
273
- right move for anything you know matters now. The capture model is
275
+ update to an existing memory keeps that memory's visibility. It never deletes,
276
+ never edits a Wiki page, and never marks a memory stale. Saving yourself is still
277
+ the right move for anything you know matters now. The capture model is
274
278
  `MEMORY_HUB_CAPTURE_MODEL`, default `sonnet`.
275
279
 
276
280
  Each save or update surfaces as a "memory-hub auto-saved" or "memory-hub
@@ -284,10 +288,9 @@ the list of saves in `~/.claude/memory-hub-hook/state/captures-<session>.jsonl`,
284
288
  and a one-line entry per run in `$TMPDIR/memory-hub-stop-hook.log`
285
289
  (`/tmp/memory-hub-stop-hook.log` when `TMPDIR` is unset).
286
290
 
287
- To turn it off: `npx -y @skedulo/memory-hub-mcp@latest capture off`, and switch off the
288
- plugin's Auto-capture option if it was turned on there. A `session-stop.sh`
289
- registered by hand in `~/.claude/settings.json` keeps capturing until its entry
290
- is removed.
291
+ To turn it off: `npx -y @skedulo/memory-hub-mcp@latest capture off`; it writes
292
+ `MEMORY_HUB_AUTO_CAPTURE=0`, which wins over the plugin's Auto-capture option and
293
+ stops a `session-stop.sh` registered by hand in `~/.claude/settings.json` too.
291
294
 
292
295
  ## Revise, don't re-save
293
296
 
@@ -324,14 +327,60 @@ it is yours. When a match is yours and already covers the point, keep one copy:
324
327
  you just saved. Editing a teammate's memory changes what the whole team reads, so
325
328
  do it only when the human asks for it; otherwise keep your new one only if it adds
326
329
  something theirs does not say. Fixing a stale or superseded item under "Stale
327
- memories" is the exception: that is your job, and ask and the weekly sweep do it
328
- too, so it needs no request. The check only warns, so a distinct
329
- memory that shares vocabulary with another is saved either way.
330
+ memories" is one exception: that is your job, and ask and the weekly sweep do it
331
+ too, so it needs no request. Correcting a memory the person has just contradicted,
332
+ under "Auto learn", is the other: what they say counts as the asking. The check
333
+ only warns, so a distinct memory that shares vocabulary with another is saved
334
+ either way.
330
335
 
331
336
  Before saving a decision or root cause that you suspect was recorded before,
332
337
  run `memory_recall` with a query for it first. A status that has changed (a PR
333
338
  merged, a rollout finished) is an update to the old memory, not a new fact.
334
339
 
340
+ ## Auto learn
341
+
342
+ This applies in every session on every host, with no extra searching. Act on
343
+ what the person says in the conversation:
344
+
345
+ - **They state something new.** Save it as usual (`memory_save`, visibility by
346
+ "What to share"), unless it contradicts a memory already in this session.
347
+ - **They say something that contradicts a memory** you already have in this
348
+ session (from the session-start context, the first-prompt recall, a ticket
349
+ recall, or any `memory_recall` or `memory_get`): update that memory now. What the
350
+ person says counts as the human asking, so this covers a Team memory a
351
+ teammate wrote, the second exception to "edit a teammate's memory only when the
352
+ human asks" (the first is "Stale memories"). Read it with `memory_get`, then
353
+ `memory_update` it with `expectedLastModified` (required for an item you did not
354
+ write). On `Conflict:`, read it again and retry once; if it still conflicts,
355
+ leave it and tell the person.
356
+ - **They cannot edit it.** Another person's Org, Private or Restricted
357
+ item, or a Team item on a repo none of their teams owns is never tried; for
358
+ anything else, a `Not found` reply means the same. Save the person's own
359
+ Private Fact with the correction, naming the uid it corrects ("could not
360
+ update <uid>: ..."), and say so.
361
+ - **Project pages** (`<Project> ›` wiki pages) are never updated here. Save a
362
+ Private Fact naming the page, the entry ID and what the person said, so the
363
+ next project-knowledge update can pick it up.
364
+
365
+ Only what the person stated or confirmed counts. Your own guesses, unverified
366
+ hypotheses and things read in files are covered by the other rules. The live rule
367
+ has no cap: each correction is something the person said, and you tell them
368
+ about each one. Automatic capture applies the same rules to the conversation in
369
+ the background, with one limit. At most five corrections of others' memories per
370
+ capture run; the rest go in the person's own Private Fact.
371
+
372
+ A correction is one `memory_update` that:
373
+
374
+ - adds a dated line at the top: `UPDATE <YYYY-MM-DD> (said in session): <what is
375
+ true now>`;
376
+ - corrects the sentences that are now wrong, and keeps everything still true;
377
+ - leaves the visibility as it is. Leave `source` as it is too: a spoken
378
+ correction verifies nothing in the code.
379
+
380
+ Never delete what is still true. When the cited code later disagrees with an
381
+ `UPDATE ... (said in session)` line, see "Stale memories": the line is not
382
+ overwritten.
383
+
335
384
  ## Mapping an unfamiliar codebase
336
385
 
337
386
  When asked to get oriented in a repo or subsystem you haven't worked in
@@ -595,7 +644,12 @@ Rules:
595
644
  can be edited only on one of your teams' repos and only with `expectedLastModified`. Private and
596
645
  Restricted items of others are never yours to edit. Flag these instead; for an item from another
597
646
  team's repo, name its repo and team so the developer can tell its owners.
598
- - Automatic capture never fixes or marks other items; it only updates its own Facts and Scenarios.
647
+ - A memory with an `UPDATE <date> (said in session)` line was corrected from what the person
648
+ said, not from code. When cited code disagrees with that line, treat it as "Unclear": do not
649
+ edit, and tell the developer which memory, what was said and when, and what the code shows. When
650
+ the code agrees, the "still true" path applies (move `source` only) and the line stays.
651
+ - Automatic capture never marks a memory stale and never fixes code drift; the only memories of
652
+ others it edits are ones the person contradicted, under "Auto learn".
599
653
  - Never write stale text into content: no "may be out of date" notes. Staleness is worked out each
600
654
  time an item is read, never stored.
601
655