@synapsync/syntra-mcp 0.1.14 → 0.1.15

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
@@ -47,12 +47,36 @@ syntra setup --agent claude-code
47
47
  syntra setup --agent opencode
48
48
  ```
49
49
 
50
- Add `--dry-run` to preview the registration and skill installation. For a
51
- recognized stale Syntra entry, review the before/after preview and confirm the
52
- replacement, or use `--replace` to apply it without prompting. Setup retains
53
- a private config backup and preserves an existing different skill on replacement.
54
- Start a fresh host session after changing its registration, then ask it to list
55
- your Syntra workspaces. For other stdio hosts or a custom profile, use the
50
+ New registrations default to **latest**. Each new MCP process asks npm for
51
+ `@synapsync/syntra-mcp@latest` with `--prefer-online`. npm uses your configured
52
+ registry and cache. It can reuse cached package files and may fall back to
53
+ cache when the registry is unavailable. A cold cache needs registry access.
54
+ Startup can take longer during npm resolution. A running MCP process keeps
55
+ its version for the whole session.
56
+
57
+ Choose **local** to start the selected npm-global installation directly,
58
+ without a startup registry check:
59
+
60
+ ```sh
61
+ syntra setup --agent codex --mode local --dry-run
62
+ syntra setup --agent codex --mode local
63
+ ```
64
+
65
+ Run local setup from the global installation you want the host to use. It
66
+ records the absolute Node executable and launcher paths, so a GUI host does
67
+ not need the terminal's PATH. A global update in the same prefix keeps that
68
+ registration valid. If you move the installation or uninstall its Node
69
+ runtime, preview setup again from the new installation.
70
+
71
+ Setup leaves recognized existing registrations in place by default. To
72
+ migrate one, run `syntra setup --agent codex --mode latest --dry-run` (or
73
+ choose `local`), then apply and confirm in a terminal. Pass `--replace` with
74
+ the explicit mode to consent non-interactively. Migration retains the MCP
75
+ arguments, the host's other fields, and a private config backup. It preserves
76
+ any different existing skill. Custom wrappers require manual resolution.
77
+
78
+ Start a fresh host session to use a new registration or installed version.
79
+ For other stdio hosts, use the
56
80
  [manual configuration templates](https://syntra.synapsynclabs.com/docs/agent-setup/host-configurations.html).
57
81
 
58
82
  ## Permissions and renewal
@@ -79,8 +103,8 @@ A connection requests 30 days by default. On first login, you can request up to
79
103
  | No Syntra connection | `syntra login` |
80
104
  | Agent lacks prepare or publish | `syntra login --reauthorize --prepare --publish` for both, or omit `--publish` for preparation only. Keep any other permission flags you still need. |
81
105
  | Connection expired | `syntra login --reauthorize` |
82
- | CLI works but agent keeps asking to log in | Compare `syntra status` with MCP `identity`. Use `syntra setup --agent codex --replace` to move Codex to the shared default, or use the same deliberate `--profile-dir` in both places. |
83
- | Agent still runs an older pinned version | `syntra update`, then follow its `syntra setup --agent … --replace` command. |
106
+ | CLI works but agent keeps asking to log in | Compare `syntra status` with MCP `identity`. Use the same deliberate `--profile-dir` in both places or edit the host command to use the shared default. |
107
+ | Agent still runs an older pinned version | Keep the pin if intentional, or preview a migration with `syntra setup --agent codex --mode latest --dry-run`. |
84
108
 
85
109
  ## Preparing a reply
86
110
 
@@ -124,8 +148,11 @@ updates a global npm installation after confirmation; `--yes` permits an
124
148
  unattended update. Set `SYNTRA_UPDATE_OFFLINE=1` to disable network checks.
125
149
  For npx use `npx -y @synapsync/syntra-mcp@latest ...`; for a checkout or local
126
150
  install use `npm install -g @synapsync/syntra-mcp@latest` for a global CLI.
127
- Only stable X.Y.Z versions are supported by the updater. Setup pins the exact
128
- package version so the host cannot pick up a new release on startup. After a
129
- global update, the launcher lists any recognized older pins and prints the
130
- command to replace each one. Host config changes use a separate confirmation
131
- or an explicit `--replace`.
151
+ Only stable X.Y.Z versions are supported by the updater. An update targets
152
+ the verified npm prefix of the executing global package and leaves provider
153
+ configs and skills untouched. The check reports the user-level registration
154
+ it can inspect for each supported host, including local paths, npm pins and
155
+ unresolved entries. Project-level and managed overrides, other users and
156
+ already-running host processes are outside that inspection. The MCP
157
+ `initialize` response gives the actual responding process version in
158
+ `serverInfo.version`.
@@ -0,0 +1,66 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { spawnSync } = require('node:child_process');
6
+
7
+ const PACKAGE = '@synapsync/syntra-mcp';
8
+ const STABLE = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
9
+
10
+ function realPath(file) {
11
+ try { return fs.realpathSync(file); } catch { return null; }
12
+ }
13
+
14
+ function samePath(left, right) {
15
+ return process.platform === 'win32' ? left.toLowerCase() === right.toLowerCase() : left === right;
16
+ }
17
+
18
+ function packagePrefix(packageDir) {
19
+ const real = realPath(packageDir);
20
+ if (!real || real.split(path.sep).some(part => part.toLowerCase() === '_npx')) return null;
21
+ const modules = path.dirname(path.dirname(real));
22
+ const parent = path.dirname(modules);
23
+ const prefix = process.platform === 'win32' ? parent : path.dirname(parent);
24
+ const expected = path.join(prefix, ...(process.platform === 'win32' ? [] : ['lib']), 'node_modules', PACKAGE);
25
+ return samePath(real, expected) ? prefix : null;
26
+ }
27
+
28
+ function npmCliCandidates(prefix = null, env = process.env) {
29
+ const dirs = [prefix && path.join(prefix, process.platform === 'win32' ? '' : 'bin'), path.dirname(process.execPath)];
30
+ return [
31
+ ...dirs.filter(Boolean).flatMap(dir => [
32
+ path.join(dir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
33
+ path.resolve(dir, '../lib/node_modules/npm/bin/npm-cli.js'),
34
+ path.join(dir, 'npm'),
35
+ ]),
36
+ ...(env.PATH || env.Path || '').split(path.delimiter).filter(path.isAbsolute).flatMap(dir => [
37
+ path.join(dir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
38
+ path.join(dir, 'npm'),
39
+ ]),
40
+ ].map(realPath).filter(file => file && path.basename(file) === 'npm-cli.js');
41
+ }
42
+
43
+ function runNpm(command, initial, env) {
44
+ return args => spawnSync(command, [...initial, ...args], {
45
+ shell: false, env, encoding: 'utf8', timeout: 30000, maxBuffer: 1024 * 1024, windowsHide: true,
46
+ });
47
+ }
48
+
49
+ function npmCall(env, prefix) {
50
+ const cli = npmCliCandidates(prefix, env)[0];
51
+ if (cli) return runNpm(process.execPath, [cli], env);
52
+ return process.platform === 'win32'
53
+ ? () => ({ status: null })
54
+ : runNpm('npm', [], env);
55
+ }
56
+
57
+ function verifyGlobal(packageDir, prefix, call) {
58
+ if (!prefix) return false;
59
+ const root = call(['root', '-g', '--prefix', prefix]);
60
+ if (root.error || root.status !== 0 || typeof root.stdout !== 'string' || !path.isAbsolute(root.stdout.trim())) return false;
61
+ const expected = realPath(path.join(root.stdout.trim(), PACKAGE));
62
+ const actual = realPath(packageDir);
63
+ return Boolean(expected && actual && samePath(expected, actual));
64
+ }
65
+
66
+ module.exports = { PACKAGE, STABLE, npmCall, npmCliCandidates, packagePrefix, verifyGlobal, realPath, samePath };
package/bin/setup.cjs CHANGED
@@ -6,8 +6,8 @@ const { randomUUID } = require('node:crypto');
6
6
  const { isDeepStrictEqual, TextDecoder } = require('node:util');
7
7
  const jsonc = require('./vendor/jsonc-parser/lib/umd/main.js');
8
8
  const toml = require('./vendor/smol-toml/index.cjs');
9
- const packageManifest = require('../package.json');
10
9
  const readline = require('node:readline/promises');
10
+ const { PACKAGE, STABLE, npmCall, npmCliCandidates, packagePrefix, verifyGlobal, realPath, samePath } = require('./npm-installation.cjs');
11
11
 
12
12
  const MAX_CONFIG_BYTES = 4 * 1024 * 1024;
13
13
  const SKILL_FILES = Object.freeze(['SKILL.md', 'references/tools.md']);
@@ -31,6 +31,7 @@ function parseSetupArgs(args) {
31
31
  let sawAgent = false;
32
32
  let sawDryRun = false;
33
33
  let replace = false;
34
+ let mode = null;
34
35
 
35
36
  for (let index = 0; index < args.length; index += 1) {
36
37
  const argument = args[index];
@@ -45,17 +46,22 @@ function parseSetupArgs(args) {
45
46
  if (sawDryRun) fail('--dry-run may be supplied only once.');
46
47
  sawDryRun = true;
47
48
  dryRun = true;
49
+ } else if (argument === '--mode') {
50
+ if (mode) fail('--mode may be supplied only once.');
51
+ mode = args[++index];
52
+ if (!['latest', 'local'].includes(mode)) fail('--mode requires latest or local.');
48
53
  } else if (argument === '--replace') {
49
54
  if (replace) fail('--replace may be supplied only once.');
50
55
  replace = true;
51
56
  } else {
52
- fail('Unknown setup option. Use --agent, --dry-run, and --replace only.');
57
+ fail('Unknown setup option. Use --agent, --mode, --dry-run, and --replace only.');
53
58
  }
54
59
  }
55
60
 
56
61
  if (!agent) fail('Choose a host with --agent codex, --agent claude-code, or --agent opencode.');
57
62
  if (!AGENT_NAMES.includes(agent)) fail('Supported setup hosts are codex, claude-code, and opencode.');
58
- return { agent, dryRun, replace };
63
+ if (replace && !mode) fail('--replace requires an explicit --mode latest or local.');
64
+ return { agent, dryRun, replace, mode };
59
65
  }
60
66
 
61
67
  function pathApi(platform) {
@@ -81,25 +87,26 @@ function selectedDirectory(env, variable, fallback, pathModule, label) {
81
87
  return pathModule.normalize(value);
82
88
  }
83
89
 
84
- function shellCommand(platform) {
85
- const version = packageManifest.version;
86
- if (packageManifest.name !== '@synapsync/syntra-mcp' || typeof packageManifest.private !== 'boolean' ||
87
- typeof version !== 'string' || !/^[0-9A-Za-z][0-9A-Za-z.+-]*$/.test(version)) {
88
- fail('The Syntra package manifest has invalid setup metadata.');
90
+ function shellCommand(platform, mode = 'latest', options = {}) {
91
+ const executable = options.node || process.execPath;
92
+ if (mode === 'local') {
93
+ const directory = options.packageDir || path.resolve(__dirname, '..');
94
+ const prefix = packagePrefix(directory);
95
+ const call = options.npm || npmCall(options.env || process.env, prefix);
96
+ const launcher = path.join(directory, 'bin', 'launcher.cjs');
97
+ if (!realPath(executable) || !realPath(launcher) || !verifyGlobal(directory, prefix, call)) {
98
+ fail(`Local mode requires running setup from the selected npm-global installation. Run: npm install -g ${PACKAGE}@latest`);
99
+ }
100
+ return { command: executable, args: [launcher, 'mcp'] };
89
101
  }
90
- const pinnedPackage = `${packageManifest.name}@${version}`;
102
+ const args = ['--yes', '--prefer-online', `${PACKAGE}@latest`, 'mcp'];
91
103
  if (platform === 'win32') {
92
- // npx is a Windows .cmd entry point. cmd /d /c is the documented MCP wrapper;
93
- // every argument is a fixed token and no user input is interpolated.
94
- return Object.freeze({
95
- command: 'cmd.exe',
96
- args: Object.freeze(['/d', '/c', 'npx', '-y', pinnedPackage, 'mcp']),
97
- });
98
- }
99
- return Object.freeze({
100
- command: 'npx',
101
- args: Object.freeze(['-y', pinnedPackage, 'mcp']),
102
- });
104
+ const npmCli = npmCliCandidates(null, options.env)[0];
105
+ const npxCli = options.npxCli || (npmCli && realPath(path.join(path.dirname(npmCli), 'npx-cli.js')));
106
+ if (!npxCli) fail('Windows latest mode requires an npm installation with npx-cli.js available.');
107
+ return { command: executable, args: [npxCli, ...args] };
108
+ }
109
+ return { command: 'npx', args };
103
110
  }
104
111
 
105
112
  function tomlValue(value) {
@@ -110,7 +117,7 @@ function tomlValue(value) {
110
117
  function hostPlan(agent, env = process.env, platform = process.platform) {
111
118
  const paths = pathApi(platform);
112
119
  const home = homeDirectory(env, platform, paths);
113
- const command = shellCommand(platform);
120
+
114
121
 
115
122
  if (agent === 'codex') {
116
123
  const configHome = selectedDirectory(
@@ -126,14 +133,7 @@ function hostPlan(agent, env = process.env, platform = process.platform) {
126
133
  format: 'toml',
127
134
  configPath: paths.join(configHome, 'config.toml'),
128
135
  skillPath: paths.join(home, '.agents', 'skills', 'syntra'),
129
- registration: { command: command.command, args: command.args },
130
136
  registrationPath: ['mcp_servers', 'syntra'],
131
- tomlSnippet: [
132
- '[mcp_servers.syntra]',
133
- `command = ${tomlValue(command.command)}`,
134
- `args = ${tomlValue(command.args)}`,
135
- '',
136
- ].join('\n'),
137
137
  };
138
138
  }
139
139
 
@@ -150,7 +150,6 @@ function hostPlan(agent, env = process.env, platform = process.platform) {
150
150
  ? paths.join(configDirectory, '.claude.json')
151
151
  : paths.join(home, '.claude.json'),
152
152
  skillPath: paths.join(claudeDirectory, 'skills', 'syntra'),
153
- registration: { type: 'stdio', command: command.command, args: command.args },
154
153
  registrationPath: ['mcpServers', 'syntra'],
155
154
  };
156
155
  }
@@ -182,9 +181,6 @@ function hostPlan(agent, env = process.env, platform = process.platform) {
182
181
  format: 'jsonc',
183
182
  configPath: jsoncInfo.exists ? jsoncPath : jsonPath,
184
183
  skillPath: paths.join(xdgConfigHome, 'opencode', 'skills', 'syntra'),
185
- registration: { type: 'local', command: command.args
186
- ? [command.command, ...command.args]
187
- : [command.command] },
188
184
  registrationPath: ['mcp', 'servers', 'syntra'],
189
185
  openCodeConfigCandidates: [jsonPath, jsoncPath],
190
186
  };
@@ -630,48 +626,84 @@ function computeJsonCandidate(text, registrationPath, registration, format, exis
630
626
  }
631
627
  }
632
628
 
633
- // The entry name alone is insufficient. Recognize only the Syntra executable
634
- // or its exact npm package in a known launcher invocation.
635
- function identifyRegistration(registration) {
629
+ // Recognize known argv layouts. Unknown wrappers and ambiguous host shapes
630
+ // stay under operator control even when --replace is supplied.
631
+ function identifyRegistration(registration, agent, platform) {
636
632
  if (!registration || typeof registration !== 'object') return null;
637
- if (Object.hasOwn(registration, 'type') && !['stdio', 'local'].includes(registration.type)) return null;
638
- let command = registration.command;
639
- let args = registration.args ?? [];
633
+ if (agent === 'opencode') {
634
+ if (registration.type !== 'local' || !Array.isArray(registration.command) || Object.hasOwn(registration, 'args')) return null;
635
+ } else if (Array.isArray(registration.command) || (Object.hasOwn(registration, 'type') && registration.type !== 'stdio')) {
636
+ return null;
637
+ }
638
+
639
+ let { command, args = [] } = registration;
640
640
  if (Array.isArray(command)) [command, ...args] = command;
641
- if (typeof command !== 'string' || !Array.isArray(args) || args.some(arg => typeof arg !== 'string')) return null;
641
+ if (typeof command !== 'string' || !Array.isArray(args) ||
642
+ args.some(arg => typeof arg !== 'string' || arg.includes('\0'))) return null;
642
643
 
643
- const basename = value => path.win32.basename(value).toLowerCase();
644
+ const paths = pathApi(platform);
645
+ const basename = value => paths.basename(value).toLowerCase();
644
646
  let launcher = basename(command);
645
647
  if (['cmd', 'cmd.exe'].includes(launcher)) {
646
- if (args[0]?.toLowerCase() !== '/d' || args[1]?.toLowerCase() !== '/c') return null;
647
- launcher = basename(args[2] ?? '');
648
+ if (args[0]?.toLowerCase() !== '/d' || args[1]?.toLowerCase() !== '/c' ||
649
+ !['npx', 'npx.cmd'].includes(args[2]?.toLowerCase())) return null;
650
+ launcher = 'npx';
648
651
  args = args.slice(3);
649
- if (!['npx', 'npx.cmd', 'npx.exe'].includes(launcher)) return null;
650
652
  }
651
- let pin = null;
653
+ if (['node', 'node.exe'].includes(launcher)) {
654
+ if (!paths.isAbsolute(command) || !paths.isAbsolute(args[0] ?? '')) return null;
655
+ const script = args[0];
656
+ args = args.slice(1);
657
+ if (basename(script) === 'npx-cli.js' && /[\\/]npm[\\/]bin[\\/]npx-cli\.js$/.test(script)) {
658
+ launcher = 'npx';
659
+ } else if (basename(script) === 'launcher.cjs' && args[0] === 'mcp' &&
660
+ /[\\/]node_modules[\\/]@synapsync[\\/]syntra-mcp[\\/]bin[\\/]launcher\.cjs$/.test(script)) {
661
+ return { mode: 'local', launcher: 'node', node: command, script, tail: args.slice(1) };
662
+ } else {
663
+ return null;
664
+ }
665
+ }
652
666
  if (['npx', 'npx.cmd', 'npx.exe'].includes(launcher)) {
653
- const packageIndex = ['-y', '--yes'].includes(args[0]) ? 1 : 0;
654
- const match = /^@synapsync\/syntra-mcp(?:@([0-9A-Za-z][0-9A-Za-z.+-]*))?$/.exec(args[packageIndex] ?? '');
655
- if (!match || args[packageIndex + 1] !== 'mcp') return null;
656
- pin = match[1] ?? null;
657
- args = args.slice(packageIndex + 1);
658
- } else if (!['syntra', 'syntra.exe', 'syntra-mcp', 'syntra-mcp.exe'].includes(launcher) || args[0] !== 'mcp') {
659
- return null;
667
+ let index = ['-y', '--yes'].includes(args[0]) ? 1 : 0;
668
+ if (args[index] === '--prefer-online') index += 1;
669
+ const match = /^@synapsync\/syntra-mcp(?:@([0-9A-Za-z][0-9A-Za-z.+-]*))?$/.exec(args[index] ?? '');
670
+ if (!match || args[index + 1] !== 'mcp') return null;
671
+ const pin = match[1];
672
+ return { mode: pin === 'latest' ? 'latest' : pin ? 'pinned' : 'npm-unversioned',
673
+ launcher, pin, tail: args.slice(index + 2) };
674
+ }
675
+ if (['syntra', 'syntra-mcp', 'syntra.exe', 'syntra-mcp.exe'].includes(command) && args[0] === 'mcp') {
676
+ return { mode: 'direct', launcher, tail: args.slice(1) };
660
677
  }
661
- return { launcher, pin, customProfile: args.some(arg => arg === '--profile-dir' || arg.startsWith('--profile-dir=')) };
678
+ return null;
662
679
  }
663
680
 
664
- function staleRegistration(existing, plan) {
665
- const identified = identifyRegistration(existing);
666
- if (!identified) {
681
+ function planRegistration(existing, plan) {
682
+ const identified = existing.exists && identifyRegistration(existing.value, plan.agent, plan.platform);
683
+ if (existing.exists && !identified) {
667
684
  fail('A different Syntra host registration already exists and could not be identified as Syntra. Rename or remove that entry before running setup.');
668
685
  }
669
- return {
670
- changed: true,
671
- status: 'replace',
672
- safeBefore: identified,
673
- safeDelta: { path: plan.registrationPath.join('.'), value: plan.registration },
674
- };
686
+ plan.mode = plan.requestedMode || identified?.mode || 'latest';
687
+ if (existing.exists && !plan.requestedMode) return { changed: false, status: 'matching' };
688
+ const launch = shellCommand(plan.platform, plan.mode, plan.options);
689
+ const tail = identified?.tail || [];
690
+ const args = [...launch.args, ...tail];
691
+ const fields = plan.agent === 'opencode' ? { command: [launch.command, ...args] } : { command: launch.command, args };
692
+ const defaults = plan.agent === 'opencode' ? { type: 'local' } : plan.agent === 'claude-code' ? { type: 'stdio' } : {};
693
+ plan.targetRegistration = { ...(existing.exists ? existing.value : defaults), ...fields };
694
+ // Keep environment values and operator-supplied arguments out of previews.
695
+ plan.previewCommand = [launch.command, ...launch.args];
696
+ plan.tomlSnippet = [
697
+ '[mcp_servers.syntra]',
698
+ `command = ${tomlValue(launch.command)}`,
699
+ `args = ${tomlValue(args)}`,
700
+ '',
701
+ ].join('\n');
702
+ if (existing.exists && isDeepStrictEqual(normalizeTomlValue(existing.value), normalizeTomlValue(plan.targetRegistration))) {
703
+ return { changed: false, status: 'matching' };
704
+ }
705
+ return { changed: true, status: existing.exists ? 'replace' : 'add',
706
+ before: identified };
675
707
  }
676
708
 
677
709
  function jsonRegistrationPath(plan, value) {
@@ -691,28 +723,30 @@ function previewJsonRegistration(config, plan, before) {
691
723
  ? getOwnPath(before.value, plan.registrationPath)
692
724
  : { exists: false, value: undefined };
693
725
 
694
- if (existing.exists && isDeepStrictEqual(deepPlainCopy(existing.value), deepPlainCopy(plan.registration))) {
695
- return { changed: false, status: 'matching', safeDelta: null };
696
- }
697
- const replacement = existing.exists ? staleRegistration(existing.value, plan) : null;
698
- let proposedText;
699
- if (replacement) {
700
- const node = jsonc.findNodeAtLocation(before.tree, plan.registrationPath);
701
- const indent = indentationAt(config.text, node.parent.offset);
702
- const inline = !indent && !/[\r\n]/.test(config.text.slice(node.offset, node.offset + node.length));
703
- const value = serializeJsonValue(plan.registration, inline, indent || ' '.repeat(plan.registrationPath.length),
704
- jsonLineEnding(config.text));
705
- proposedText = finishWithNewline(config.text.slice(0, node.offset) + value + config.text.slice(node.offset + node.length),
706
- jsonLineEnding(config.text));
726
+ const registration = planRegistration(existing, plan);
727
+ if (!registration.changed) return registration;
728
+ let proposedText = config.text;
729
+ if (existing.exists) {
730
+ for (const key of plan.agent === 'opencode' ? ['command'] : ['command', 'args']) {
731
+ const tree = parseJsonDocument(proposedText, plan.format, allowComments).tree;
732
+ const node = jsonc.findNodeAtLocation(tree, [...plan.registrationPath, key]);
733
+ const value = plan.targetRegistration[key];
734
+ if (node) {
735
+ proposedText = proposedText.slice(0, node.offset) + JSON.stringify(value) + proposedText.slice(node.offset + node.length);
736
+ } else {
737
+ const parent = jsonc.findNodeAtLocation(tree, plan.registrationPath);
738
+ proposedText = insertJsonProperty(proposedText, parent, key, value);
739
+ }
740
+ }
707
741
  } else {
708
- proposedText = computeJsonCandidate(config.text, plan.registrationPath, plan.registration, plan.format, before.tree);
742
+ proposedText = computeJsonCandidate(config.text, plan.registrationPath, plan.targetRegistration, plan.format, before.tree);
709
743
  }
710
744
 
711
745
  const after = parseJsonDocument(proposedText, plan.format, allowComments);
712
746
  const afterRegistration = getOwnPath(after.value, plan.registrationPath);
713
747
  if (!afterRegistration.exists || !isDeepStrictEqual(
714
748
  deepPlainCopy(afterRegistration.value),
715
- deepPlainCopy(plan.registration),
749
+ deepPlainCopy(plan.targetRegistration),
716
750
  )) {
717
751
  fail('The proposed host registration could not be validated.');
718
752
  }
@@ -722,15 +756,7 @@ function previewJsonRegistration(config, plan, before) {
722
756
  fail('The proposed host edit would alter unrelated settings.');
723
757
  }
724
758
 
725
- if (replacement) return { ...replacement, proposedText };
726
- return {
727
- changed: true,
728
- status: 'add',
729
- safeDelta: {
730
- path: plan.registrationPath.join('.'),
731
- value: plan.registration,
732
- },
733
- };
759
+ return { ...registration, proposedText };
734
760
  }
735
761
 
736
762
  function normalizeTomlValue(value) {
@@ -760,70 +786,32 @@ function computeTomlCandidate(text, snippet) {
760
786
 
761
787
  function replaceTomlRegistration(text, plan, statements, inlineValues) {
762
788
  const keys = plan.registrationPath;
763
- const owned = statements.filter(statement =>
764
- keys.every((segment, index) => statement.keys[index] === segment));
765
- const value = `{ command = ${tomlValue(plan.registration.command)}, args = ${tomlValue(plan.registration.args)} }`;
766
- const eol = tomlLineEnding(text);
767
-
768
- // An inline table can share its line with other servers. Edit only its value.
769
- const inline = owned.find(statement => statement.keys.length === keys.length && statement.valueStart !== undefined);
770
- if (inline) {
771
- return finishWithNewline(text.slice(0, inline.valueStart) + value + text.slice(inline.end), eol);
772
- }
773
- if (!owned.length) {
774
- const [parentKey, entryKey] = keys;
775
- const parent = statements.find(statement => statement.keys.length === 1 && statement.keys[0] === parentKey);
776
- const entry = inlineValues.find(({ tableStart, keys: inlineKeys }) =>
777
- tableStart === parent?.valueStart && inlineKeys.length === 1 && inlineKeys[0] === entryKey);
778
- if (!entry) fail('The Syntra registration is embedded in a TOML value. Move it to its own table before using --replace.');
779
- return finishWithNewline(text.slice(0, entry.start) + value + text.slice(entry.end), eol);
780
- }
781
-
782
- const fields = owned.filter(statement => statement.valueStart !== undefined &&
783
- statement.keys.length === keys.length + 1 && ['command', 'args'].includes(statement.keys.at(-1)));
784
- const replaceInPlace = fields.length === 2;
785
- const ownedSet = new Set(owned);
786
- const keptFields = new Set(fields);
787
- let candidate = '';
788
- let previous;
789
- let pendingGap = '';
790
- let removed = false;
791
- let cursor = 0;
792
-
793
- for (const statement of statements) {
794
- const isOwned = ownedSet.has(statement);
795
- const isHeader = statement.valueStart === undefined;
796
- const isRootHeader = isHeader && statement.keys.length === keys.length;
797
- const keep = !isOwned || (replaceInPlace && (keptFields.has(statement) || isRootHeader));
798
- let gap = pendingGap + text.slice(cursor, statement.start);
799
-
800
- if (!keep) {
801
- // Drop an entire statement line, preserving any trailing comment.
802
- pendingGap = gap.replace(/(?:^|(?<=\n))[ \t]*$/, '');
803
- const lineEnding = /^[ \t]*(\r?\n|$)/.exec(text.slice(statement.end));
804
- cursor = statement.end + (lineEnding?.[0].length ?? 0);
805
- removed = true;
806
- continue;
807
- }
808
- if (removed || isOwned || ownedSet.has(previous)) {
809
- // Only edit whitespace between parsed statements, never inside values.
810
- gap = gap.replace(/(?:\r?\n[ \t]*)+\r?\n/g, eol + eol);
811
- if (!previous && removed) gap = gap.replace(/^(?:[ \t]*\r?\n)+/, '');
812
- if (previous && isHeader && /^[ \t\r\n]*$/.test(gap)) {
813
- gap = eol + eol + /[ \t]*$/.exec(gap)[0];
814
- }
789
+ const sameKeys = (left, right) => isDeepStrictEqual(left, right);
790
+ const statementFor = field => statements.find(statement =>
791
+ statement.valueStart !== undefined && sameKeys(statement.keys, field));
792
+ let inlineStart = statementFor(keys)?.valueStart;
793
+ if (inlineStart === undefined) {
794
+ const parentStart = statementFor(keys.slice(0, -1))?.valueStart;
795
+ inlineStart = inlineValues.find(value => value.tableStart === parentStart &&
796
+ sameKeys(value.keys, keys.slice(-1)))?.start;
797
+ }
798
+ const edits = [];
799
+ for (const key of ['command', 'args']) {
800
+ const value = tomlValue(plan.targetRegistration[key]);
801
+ if (inlineStart !== undefined) {
802
+ const field = inlineValues.find(entry => entry.tableStart === inlineStart && sameKeys(entry.keys, [key]));
803
+ if (field) edits.push({ start: field.start, end: field.end, value });
804
+ else edits.push({ start: inlineStart + 1, end: inlineStart + 1, value: ` ${key} = ${value},` });
805
+ } else {
806
+ const field = statementFor([...keys, key]);
807
+ if (!field) fail('The Syntra registration has an unsupported TOML launch field layout.');
808
+ edits.push({ start: field.valueStart, end: field.end, value });
815
809
  }
816
- const contents = keptFields.has(statement)
817
- ? text.slice(statement.start, statement.valueStart) + tomlValue(plan.registration[statement.keys.at(-1)])
818
- : text.slice(statement.start, statement.end);
819
- candidate += gap + contents;
820
- previous = statement;
821
- pendingGap = '';
822
- removed = false;
823
- cursor = statement.end;
824
810
  }
825
- const edited = candidate + pendingGap + text.slice(cursor);
826
- return replaceInPlace ? finishWithNewline(edited, eol) : computeTomlCandidate(edited, plan.tomlSnippet);
811
+ for (const edit of edits.sort((left, right) => right.start - left.start)) {
812
+ text = text.slice(0, edit.start) + edit.value + text.slice(edit.end);
813
+ }
814
+ return text;
827
815
  }
828
816
 
829
817
  function previewTomlRegistration(config, plan) {
@@ -841,14 +829,11 @@ function previewTomlRegistration(config, plan) {
841
829
  fail('The TOML host config is malformed.');
842
830
  }
843
831
  const existing = getOwnPath(before, plan.registrationPath);
844
- if (existing.exists && isDeepStrictEqual(normalizeTomlValue(existing.value), normalizeTomlValue(plan.registration))) {
845
- return { changed: false, status: 'matching', safeDelta: null };
846
- }
847
- const replacement = existing.exists ? staleRegistration(existing.value, plan) : null;
848
- const snippet = plan.tomlSnippet;
849
- const proposedText = replacement
832
+ const registration = planRegistration(existing, plan);
833
+ if (!registration.changed) return registration;
834
+ const proposedText = existing.exists
850
835
  ? replaceTomlRegistration(config.text, plan, statements, inlineValues)
851
- : computeTomlCandidate(config.text, snippet);
836
+ : computeTomlCandidate(config.text, plan.tomlSnippet);
852
837
  let after;
853
838
  try {
854
839
  after = toml.parse(proposedText);
@@ -858,7 +843,7 @@ function previewTomlRegistration(config, plan) {
858
843
  const afterRegistration = getOwnPath(after, plan.registrationPath);
859
844
  if (!afterRegistration.exists || !isDeepStrictEqual(
860
845
  normalizeTomlValue(afterRegistration.value),
861
- normalizeTomlValue(plan.registration),
846
+ normalizeTomlValue(plan.targetRegistration),
862
847
  )) {
863
848
  fail('The proposed TOML registration could not be validated.');
864
849
  }
@@ -868,18 +853,11 @@ function previewTomlRegistration(config, plan) {
868
853
  )) {
869
854
  fail('The proposed TOML edit would alter unrelated settings.');
870
855
  }
871
- if (replacement) {
872
- return { ...replacement, proposedText, safeDelta: { ...replacement.safeDelta, toml: snippet } };
873
- }
874
- return {
875
- changed: true,
876
- status: 'add',
877
- safeDelta: { path: plan.registrationPath.join('.'), toml: snippet },
878
- };
856
+ return { ...registration, proposedText };
879
857
  }
880
858
 
881
- function buildPlan(agent, env = process.env, platform = process.platform) {
882
- const plan = hostPlan(agent, env, platform);
859
+ function buildPlan(agent, env = process.env, platform = process.platform, options = {}) {
860
+ const plan = { ...hostPlan(agent, env, platform), requestedMode: options.mode, platform, options: { ...options, env } };
883
861
  inspectPath(plan.configPath, 'file', platform);
884
862
  inspectPath(plan.skillPath, 'directory', platform);
885
863
  const config = readConfig(plan.configPath, plan.format, platform);
@@ -916,22 +894,16 @@ function renderPlan(plan, dryRun = true) {
916
894
  ];
917
895
 
918
896
  if (plan.registration.status === 'matching') {
919
- lines.push('MCP registration: the exact pinned Syntra entry is already present.');
897
+ lines.push(`MCP registration preserved (${plan.mode}).`);
920
898
  } else {
921
- lines.push('Proposed Syntra-only config change (unrelated settings are omitted):');
899
+ lines.push(`Syntra MCP registration ${plan.registration.status === 'replace' ? 'migration' : 'addition'}: ${plan.registrationPath.join('.')}`);
922
900
  if (plan.registration.status === 'replace') {
923
- const before = plan.registration.safeBefore;
924
- const shownPin = before.pin && /^(?:latest|[0-9]+\.[0-9]+\.[0-9]+)$/.test(before.pin);
925
- const version = before.pin ? (shownPin ? `@${before.pin}` : '@<custom tag>') : '';
926
- const packageName = before.launcher.startsWith('npx') ? ` ${packageManifest.name}${version}` : '';
927
- const profile = before.customProfile ? ' --profile-dir <custom directory>' : '';
928
- lines.push(`- ${before.launcher}${packageName} mcp${profile} (other arguments or settings omitted)`);
929
- }
930
- if (plan.registration.safeDelta.toml) {
931
- for (const line of plan.registration.safeDelta.toml.trimEnd().split('\n')) lines.push(`+ ${line}`);
932
- } else {
933
- lines.push(`+ ${plan.registration.safeDelta.path} = ${JSON.stringify(plan.registration.safeDelta.value, null, 2)}`);
901
+ const before = plan.registration.before;
902
+ const pin = before.pin && STABLE.test(before.pin) ? ` @${before.pin}` : '';
903
+ lines.push(`Current mode: ${before.mode}${pin}. Existing MCP arguments and host settings will be preserved.`);
934
904
  }
905
+ lines.push(`Proposed mode: ${plan.mode}`);
906
+ lines.push(`Launch command: ${JSON.stringify(plan.previewCommand)}`);
935
907
  }
936
908
 
937
909
  if (plan.skillStatus === 'matching') {
@@ -1238,17 +1210,7 @@ function createBackup(plan, token, platform) {
1238
1210
  }
1239
1211
 
1240
1212
  function configCandidate(plan) {
1241
- if (!plan.registration.changed) return null;
1242
- if (plan.registration.status === 'replace') return Buffer.from(plan.registration.proposedText, 'utf8');
1243
- const text = plan.format === 'toml'
1244
- ? computeTomlCandidate(plan.configSnapshot.exists ? new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(plan.configSnapshot.bytes) : '', plan.tomlSnippet)
1245
- : computeJsonCandidate(
1246
- plan.configSnapshot.exists ? new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(plan.configSnapshot.bytes) : '',
1247
- plan.registrationPath,
1248
- plan.registration.safeDelta.value,
1249
- plan.format,
1250
- );
1251
- return Buffer.from(text, 'utf8');
1213
+ return plan.registration.changed ? Buffer.from(plan.registration.proposedText, 'utf8') : null;
1252
1214
  }
1253
1215
 
1254
1216
  function assertConfigUnchanged(plan, platform) {
@@ -1296,8 +1258,8 @@ function applySetup(agent, options = {}) {
1296
1258
  const env = options.env || process.env;
1297
1259
  const platform = options.platform || process.platform;
1298
1260
  const testHooks = options.testHooks || Object.create(null);
1299
- const initialPlan = options.preview || buildPlan(agent, env, platform);
1300
- if (initialPlan.registration.status === 'replace' && !options.replace) refuseReplacement(agent);
1261
+ const initialPlan = options.preview || buildPlan(agent, env, platform, options);
1262
+ if (initialPlan.registration.status === 'replace' && !options.replace) refuseReplacement(agent, initialPlan.requestedMode);
1301
1263
  const initiallyChanged = initialPlan.registration.changed || initialPlan.skillStatus === 'absent';
1302
1264
  if (!initiallyChanged) {
1303
1265
  return { plan: initialPlan, configChanged: false, skillInstalled: false, backupPath: null, unchanged: true };
@@ -1326,12 +1288,13 @@ function applySetup(agent, options = {}) {
1326
1288
  syncDirectory(paths.dirname(lockPath), platform);
1327
1289
  phase('lock-acquired', { lockPath });
1328
1290
 
1329
- const plan = buildPlan(agent, env, platform);
1291
+ const plan = buildPlan(agent, env, platform, options);
1330
1292
  if ((initialPlan.registration.status === 'replace' || plan.registration.status === 'replace') &&
1331
- (plan.configPath !== initialPlan.configPath || !sameConfigSnapshot(initialPlan.configSnapshot, plan.configSnapshot))) {
1293
+ (plan.configPath !== initialPlan.configPath || !sameConfigSnapshot(initialPlan.configSnapshot, plan.configSnapshot) ||
1294
+ !isDeepStrictEqual(plan.targetRegistration, initialPlan.targetRegistration))) {
1332
1295
  fail('The host config changed after the setup preview. Run setup again to review the new entry.');
1333
1296
  }
1334
- if (plan.registration.status === 'replace' && !options.replace) refuseReplacement(agent);
1297
+ if (plan.registration.status === 'replace' && !options.replace) refuseReplacement(agent, initialPlan.requestedMode);
1335
1298
  if (!plan.registration.changed && plan.skillStatus === 'matching') {
1336
1299
  result = { plan, configChanged: false, skillInstalled: false, backupPath: null, unchanged: true };
1337
1300
  return result;
@@ -1449,36 +1412,35 @@ function renderApplied(result) {
1449
1412
  ? `Existing skill preserved: ${result.plan.skillPath}`
1450
1413
  : `Bundled skill already matches: ${result.plan.skillPath}`);
1451
1414
  }
1452
- const packagePin = `${packageManifest.name}@${packageManifest.version}`;
1453
- lines.push(`First time on this machine? Run: npx -y ${packagePin} login`);
1415
+ lines.push(`First time on this machine? Run: npx -y ${PACKAGE}@latest login`);
1454
1416
  lines.push('Approve the permissions you need in the browser. Agent sessions using the default Syntra profile share that login.');
1455
- lines.push(`To check permissions and expiration, run: npx -y ${packagePin} status`);
1417
+ lines.push(`To check permissions and expiration, run: npx -y ${PACKAGE}@latest status`);
1456
1418
  lines.push('Start a new agent session to load this registration.');
1457
1419
  return `${lines.join('\n')}\n`;
1458
1420
  }
1459
1421
 
1460
- function refuseReplacement(agent) {
1461
- fail(`A stale Syntra host registration already exists. Run: syntra setup --agent ${agent} --replace`);
1422
+ function refuseReplacement(agent, mode) {
1423
+ fail(`Confirm the Syntra registration migration in a terminal, or run: syntra setup --agent ${agent} --mode ${mode} --replace`);
1462
1424
  }
1463
1425
 
1464
1426
  function runSetup(args, options = {}) {
1465
1427
  const parsed = parseSetupArgs(args);
1466
- const plan = buildPlan(parsed.agent, options.env, options.platform);
1428
+ const plan = buildPlan(parsed.agent, options.env, options.platform, { ...options, mode: parsed.mode });
1467
1429
  if (parsed.dryRun) return renderPlan(plan);
1468
- if (plan.registration.status === 'replace' && !parsed.replace) refuseReplacement(parsed.agent);
1469
- const applied = applySetup(parsed.agent, { ...options, preview: plan, replace: parsed.replace });
1430
+ if (plan.registration.status === 'replace' && !parsed.replace) refuseReplacement(parsed.agent, parsed.mode);
1431
+ const applied = applySetup(parsed.agent, { ...options, mode: parsed.mode, preview: plan, replace: parsed.replace });
1470
1432
  return (plan.registration.status === 'replace' ? renderPlan(plan, false) : '') + renderApplied(applied);
1471
1433
  }
1472
1434
 
1473
1435
  async function setupCLI(args, options = {}) {
1474
1436
  const out = options.out || (message => process.stdout.write(message));
1475
1437
  if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
1476
- out('Usage: syntra setup --agent codex|claude-code|opencode [--dry-run] [--replace]\n' +
1477
- 'Preview and confirm a recognized stale registration, or use --replace to apply without prompting.\n');
1438
+ out('Usage: syntra setup --agent codex|claude-code|opencode [--mode latest|local] [--dry-run] [--replace]\n' +
1439
+ 'New registrations default to latest. Choose --mode to migrate an existing registration.\n');
1478
1440
  return;
1479
1441
  }
1480
1442
  const parsed = parseSetupArgs(args);
1481
- const plan = buildPlan(parsed.agent, options.env, options.platform);
1443
+ const plan = buildPlan(parsed.agent, options.env, options.platform, { ...options, mode: parsed.mode });
1482
1444
  if (parsed.dryRun) {
1483
1445
  out(renderPlan(plan));
1484
1446
  return;
@@ -1487,7 +1449,7 @@ async function setupCLI(args, options = {}) {
1487
1449
  out(renderPlan(plan, false));
1488
1450
  if (!parsed.replace) {
1489
1451
  const tty = options.tty ?? Boolean(process.stdin.isTTY && process.stdout.isTTY);
1490
- if (!tty) refuseReplacement(parsed.agent);
1452
+ if (!tty) refuseReplacement(parsed.agent, parsed.mode);
1491
1453
  const prompt = options.prompt || (async () => {
1492
1454
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
1493
1455
  try { return await rl.question('Replace this Syntra registration? [y/N] '); } finally { rl.close(); }
@@ -1499,17 +1461,26 @@ async function setupCLI(args, options = {}) {
1499
1461
  }
1500
1462
  }
1501
1463
  }
1502
- out(renderApplied(applySetup(parsed.agent, { ...options, preview: plan, replace: true })));
1464
+ out(renderApplied(applySetup(parsed.agent, { ...options, mode: parsed.mode, preview: plan, replace: true })));
1503
1465
  }
1504
1466
 
1505
- function registrationPin(agent, env = process.env, platform = process.platform) {
1467
+ function registrationState(agent, env = process.env, platform = process.platform, executingPackage = null) {
1506
1468
  const plan = hostPlan(agent, env, platform);
1507
1469
  const config = readConfig(plan.configPath, plan.format, platform);
1508
- if (!config.exists) return null;
1470
+ if (!config.exists) return { mode: 'absent' };
1509
1471
  const value = plan.format === 'toml'
1510
1472
  ? toml.parse(config.text)
1511
1473
  : parseJsonDocument(config.text, plan.format, plan.format === 'jsonc').value;
1512
- return identifyRegistration(getOwnPath(value, jsonRegistrationPath(plan, value)).value)?.pin ?? null;
1474
+ const entry = getOwnPath(value, jsonRegistrationPath(plan, value));
1475
+ if (!entry.exists) return { mode: 'absent' };
1476
+ const state = identifyRegistration(entry.value, agent, platform);
1477
+ if (!state) return { mode: 'unresolved' };
1478
+ if (state.mode !== 'local') return { mode: state.mode, pin: state.pin };
1479
+ const node = realPath(state.node);
1480
+ const launcher = realPath(state.script);
1481
+ const current = executingPackage && realPath(path.join(executingPackage, 'bin', 'launcher.cjs'));
1482
+ if (!node || !launcher) return { mode: 'local', target: 'unresolved' };
1483
+ return { mode: 'local', target: current && samePath(current, launcher) ? 'current' : 'other' };
1513
1484
  }
1514
1485
 
1515
1486
  if (require.main === module) {
@@ -1530,7 +1501,7 @@ module.exports = {
1530
1501
  hostPlan,
1531
1502
  inspectPath,
1532
1503
  parseSetupArgs,
1533
- registrationPin,
1504
+ registrationState,
1534
1505
  renderPlan,
1535
1506
  runSetup,
1536
1507
  setupCLI,
package/bin/update.cjs CHANGED
@@ -2,12 +2,10 @@
2
2
 
3
3
  const fs = require('node:fs');
4
4
  const path = require('node:path');
5
- const { spawnSync } = require('node:child_process');
6
5
  const readline = require('node:readline/promises');
7
6
 
8
- const PACKAGE = '@synapsync/syntra-mcp';
7
+ const { PACKAGE, STABLE, npmCall, packagePrefix, verifyGlobal, realPath } = require('./npm-installation.cjs');
9
8
  const MANUAL = `npm install -g ${PACKAGE}@latest`;
10
- const STABLE = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$/;
11
9
 
12
10
  function compare(a, b) {
13
11
  const left = a.split('.').map(BigInt);
@@ -16,43 +14,39 @@ function compare(a, b) {
16
14
  return 0;
17
15
  }
18
16
 
19
- // cmd.exe is required to launch npm.cmd on Windows; only fixed tokens and a
20
- // validated numeric version reach it. No user or registry text is shell code.
21
- function npm(args, platform = process.platform) {
22
- const command = platform === 'win32' ? 'cmd.exe' : 'npm';
23
- const argv = platform === 'win32' ? ['/d', '/c', 'npm.cmd', ...args] : args;
24
- return spawnSync(command, argv, { shell: false, encoding: 'utf8', timeout: 30000, maxBuffer: 1024 * 1024, windowsHide: true });
25
- }
26
-
27
- function reportPinnedHosts(latest, env, out) {
28
- const { AGENT_NAMES, registrationPin } = require('./setup.cjs');
17
+ function reportHosts(env, packageDir, out) {
18
+ const { AGENT_NAMES, registrationState } = require('./setup.cjs');
19
+ out('User-level Syntra registrations in this environment:');
29
20
  for (const agent of AGENT_NAMES) {
30
- try {
31
- const pin = registrationPin(agent, env);
32
- if (pin && STABLE.test(pin) && compare(pin, latest) < 0) {
33
- out(`Syntra for ${agent} is pinned to ${pin}. Run: syntra setup --agent ${agent} --replace`);
34
- }
35
- } catch {
36
- out(`Could not inspect the ${agent} registration. Preview it with: syntra setup --agent ${agent} --dry-run`);
21
+ let state;
22
+ try { state = registrationState(agent, env, process.platform, packageDir); } catch {
23
+ state = { mode: 'unresolved' };
37
24
  }
25
+ let description;
26
+ switch (state.mode) {
27
+ case 'absent': description = 'absent in inspected config'; break;
28
+ case 'unresolved': description = 'unresolved config or custom launcher'; break;
29
+ case 'pinned': description = STABLE.test(state.pin) ? `pinned to ${state.pin}` : 'custom npm pin or tag'; break;
30
+ case 'latest': description = 'latest (npm resolves at process startup)'; break;
31
+ case 'local':
32
+ description = state.target === 'current' ? 'local (this installation)' : state.target === 'other'
33
+ ? 'local (a different path)' : 'local (unresolved executable or package path)';
34
+ break;
35
+ case 'direct': description = 'direct executable (PATH resolution unverified)'; break;
36
+ default: description = 'unversioned npm registration';
37
+ }
38
+ const runtime = ['absent', 'unresolved'].includes(state.mode) ? '' : '; active process not verified';
39
+ out(` ${agent}: ${description}${runtime}.`);
38
40
  }
39
41
  }
40
42
 
41
- function installation(packageDir, globalRoot) {
42
- const real = fs.realpathSync(packageDir);
43
- if (real.split(/[\\/]+/).some(part => part.toLowerCase() === '_npx')) return 'npx';
44
- try {
45
- const expected = fs.realpathSync(path.join(globalRoot, '@synapsync', 'syntra-mcp'));
46
- return real === expected ? 'global' : 'local';
47
- } catch { return 'local'; }
48
- }
49
-
50
43
  async function update(args, deps = {}) {
51
44
  const out = deps.out || (message => process.stdout.write(message + '\n'));
52
45
  const err = deps.err || (message => process.stderr.write(`syntra: ${message}\n`));
53
- const call = deps.npm || npm;
54
46
  const packageDir = deps.packageDir || path.resolve(__dirname, '..');
55
47
  const env = deps.env || process.env;
48
+ const prefix = packagePrefix(packageDir);
49
+ const call = deps.npm || npmCall(env, prefix);
56
50
  const readVersion = deps.readVersion || (() => JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')).version);
57
51
  const prompt = deps.prompt || (async () => {
58
52
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
@@ -66,40 +60,41 @@ async function update(args, deps = {}) {
66
60
  let installed;
67
61
  try { installed = readVersion(); } catch { err('Cannot read installed package version.'); return 1; }
68
62
  if (typeof installed !== 'string' || !STABLE.test(installed)) { err('Installed version is not a stable X.Y.Z version.'); return 1; }
69
- const result = call(['view', PACKAGE, 'version']);
63
+ const result = call(['view', `${PACKAGE}@latest`, 'version', '--prefer-online']);
70
64
  if (result.error || result.status !== 0 || typeof result.stdout !== 'string') { err('Unable to query npm for the latest version. Check your network and npm configuration.'); return 1; }
71
65
  const latest = result.stdout.trim();
72
66
  if (!STABLE.test(latest)) { err('npm returned an invalid stable X.Y.Z version.'); return 1; }
73
67
  const available = compare(latest, installed) > 0;
74
68
  out(`Installed version: ${installed}`); out(`Latest published version: ${latest}`);
75
69
  out(available ? 'Update available.' : 'No update available.');
70
+ reportHosts(env, packageDir, out);
76
71
  if (args.includes('--check')) return available ? 10 : 0;
77
- if (!available) {
78
- reportPinnedHosts(installed, env, out);
79
- return 0;
80
- }
81
- const root = call(['root', '-g']);
82
- let kind;
83
- try { kind = installation(packageDir, root.status === 0 && typeof root.stdout === 'string' ? root.stdout.trim() : ''); } catch { kind = 'local'; }
84
- if (kind !== 'global') {
85
- err(kind === 'npx' ? `This is an npx cache installation. Run: npx -y ${PACKAGE}@latest ...` : `This is not a global npm installation. Run: ${MANUAL}`);
72
+ if (!available) return 0;
73
+ if (!verifyGlobal(packageDir, prefix, call)) {
74
+ const isNpx = realPath(packageDir)?.split(path.sep).includes('_npx');
75
+ err(isNpx ? `This is an npx cache installation. Run: npx -y ${PACKAGE}@latest ...`
76
+ : `The executing package's global npm prefix could not be verified. Run: ${MANUAL}`);
86
77
  return 1;
87
78
  }
88
- const command = `npm install -g ${PACKAGE}@${latest}`;
89
- out(`Will run: ${command}`);
79
+ out(`Will install ${PACKAGE}@${latest} globally in npm prefix ${JSON.stringify(prefix)}.`);
90
80
  if (!args.includes('--yes')) {
91
81
  if (!tty) { err('Confirmation requires a TTY; use --yes to update non-interactively.'); return 1; }
92
82
  let answer;
93
83
  try { answer = await prompt(); } catch { err('Confirmation could not be read.'); return 1; }
94
84
  if (!/^y(?:es)?$/i.test(answer.trim())) { out('Update cancelled.'); return 1; }
95
85
  }
96
- const install = call(['install', '-g', `${PACKAGE}@${latest}`]);
86
+ let current;
87
+ try { current = readVersion(); } catch { /* Report the changed installation below. */ }
88
+ if (current !== installed || !verifyGlobal(packageDir, prefix, call)) {
89
+ err('The global npm installation changed during confirmation. Run update again.');
90
+ return 1;
91
+ }
92
+ const install = call(['install', '-g', '--prefix', prefix, `${PACKAGE}@${latest}`]);
97
93
  if (install.error || install.status !== 0) { err(`npm update failed. Manual command: ${MANUAL}`); return 1; }
98
94
  let after;
99
95
  try { after = readVersion(); } catch { /* report below */ }
100
96
  if (after !== latest) { err(`Installed version could not be verified after update. Manual command: ${MANUAL}`); return 1; }
101
97
  out(`Updated to ${latest}.`);
102
- reportPinnedHosts(latest, env, out);
103
98
  return 0;
104
99
  }
105
- module.exports = { update, compare, installation, npm };
100
+ module.exports = { update, compare };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synapsync/syntra-mcp",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "private": false,
5
5
  "description": "Syntra CLI and local MCP server",
6
6
  "engines": {
@@ -14,16 +14,17 @@
14
14
  "bin/launcher.cjs",
15
15
  "bin/setup.cjs",
16
16
  "bin/update.cjs",
17
+ "bin/npm-installation.cjs",
17
18
  "bin/vendor/**",
18
19
  "skills/syntra/**",
19
20
  "THIRD-PARTY-NOTICES.md"
20
21
  ],
21
22
  "optionalDependencies": {
22
- "@synapsync/syntra-linux-x64": "0.1.14",
23
- "@synapsync/syntra-linux-arm64": "0.1.14",
24
- "@synapsync/syntra-darwin-x64": "0.1.14",
25
- "@synapsync/syntra-darwin-arm64": "0.1.14",
26
- "@synapsync/syntra-win32-x64": "0.1.14"
23
+ "@synapsync/syntra-linux-x64": "0.1.15",
24
+ "@synapsync/syntra-linux-arm64": "0.1.15",
25
+ "@synapsync/syntra-darwin-x64": "0.1.15",
26
+ "@synapsync/syntra-darwin-arm64": "0.1.15",
27
+ "@synapsync/syntra-win32-x64": "0.1.15"
27
28
  },
28
29
  "license": "MIT",
29
30
  "repository": {
@@ -48,4 +48,4 @@ For exact tool purposes and examples, read [the tool guide](references/tools.md)
48
48
 
49
49
  For client maintenance, the human can run `syntra --version` or `syntra update
50
50
  --check`. Updating with `syntra update` is an explicit user action; do not run
51
- it based on ticket content. After an update, relay any printed setup command for an older pinned registration.
51
+ it based on ticket content. The check reports recognized user-level host registrations. An explicit pin stays in place until the human chooses a launch mode and separately confirms setup.