gitnexushub 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,6 @@ export declare function resolveHookScriptPath(): string;
24
24
  */
25
25
  export declare function runConnect(tokenArg: string | undefined, opts: {
26
26
  editor?: string;
27
- hub: string;
27
+ hub?: string;
28
28
  skipProject?: boolean;
29
29
  }): Promise<undefined>;
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ program
56
56
  .description('Register Hub MCP, install skills, and write project files')
57
57
  .argument('[token]', 'gnx_ API token (optional if already saved)')
58
58
  .option('--editor <name>', 'Editor to configure: claude-code | cursor | windsurf | opencode')
59
- .option('--hub <url>', 'Hub URL', DEFAULT_HUB_URL)
59
+ .option('--hub <url>', `Hub URL (default: saved config or ${DEFAULT_HUB_URL})`)
60
60
  .option('--skip-project', 'Only configure MCP, skip project files')
61
61
  .action(connectAction);
62
62
  // ─── disconnect command ───────────────────────────────────────────
@@ -80,7 +80,7 @@ program
80
80
  program
81
81
  .command('index <repo>')
82
82
  .description('Index a GitHub repo (owner/repo or URL)')
83
- .option('--hub <url>', 'Hub URL', DEFAULT_HUB_URL)
83
+ .option('--hub <url>', `Hub URL (default: saved config or ${DEFAULT_HUB_URL})`)
84
84
  .option('--token <token>', 'gnx_ API token (optional if already saved)')
85
85
  .option('--wait', 'Wait for indexing to complete', false)
86
86
  .action(async (repo, opts) => {
@@ -100,7 +100,7 @@ program
100
100
  .command('sync')
101
101
  .description('Push local working-tree state to the hub for re-indexing')
102
102
  .option('--wait', 'Wait for indexing to complete', false)
103
- .option('--hub <url>', 'Hub URL', DEFAULT_HUB_URL)
103
+ .option('--hub <url>', `Hub URL (default: saved config or ${DEFAULT_HUB_URL})`)
104
104
  .action(async (opts) => {
105
105
  try {
106
106
  await runSync(opts);
@@ -20,11 +20,45 @@
20
20
  const fs = require('fs');
21
21
  const path = require('path');
22
22
  const os = require('os');
23
+ const crypto = require('crypto');
23
24
  const http = require('http');
24
25
  const https = require('https');
25
26
  const { spawnSync } = require('child_process');
26
27
  const { URL } = require('url');
27
28
 
29
+ /**
30
+ * Device fingerprint — stable per-machine identity the hub uses to bind
31
+ * device-scoped tokens. MUST match the algorithm in
32
+ * gitnexus-connect/src/fingerprint.ts (same SHA-256 of
33
+ * `hostname:username:platform:arch`, truncated to 16 hex chars) so the
34
+ * hook's requests share the same identity as `gnx connect`'s.
35
+ *
36
+ * Reimplemented inline here because the hook is a dependency-free .cjs
37
+ * and cannot import from the compiled connect bundle.
38
+ */
39
+ function computeFingerprint() {
40
+ const identity = `${os.hostname()}:${os.userInfo().username}:${os.platform()}:${os.arch()}`;
41
+ return crypto.createHash('sha256').update(identity).digest('hex').slice(0, 16);
42
+ }
43
+
44
+ function getDeviceName() {
45
+ return `${os.userInfo().username}@${os.hostname()}`;
46
+ }
47
+
48
+ /**
49
+ * Build the header bag the hub's auth middleware requires. Device tokens
50
+ * (issued by `gnx connect`) are rejected without both `X-Device-Fingerprint`
51
+ * and `X-Device-Name` — omitting them surfaces as a 403 and the hook would
52
+ * silently bail, so every call must go through this helper.
53
+ */
54
+ function authHeaders(config) {
55
+ return {
56
+ Authorization: `Bearer ${config.hubToken}`,
57
+ 'X-Device-Fingerprint': computeFingerprint(),
58
+ 'X-Device-Name': getDeviceName(),
59
+ };
60
+ }
61
+
28
62
  const HOOK_TIMEOUT_MS = 1500;
29
63
  const CONFIG_PATH = path.join(os.homedir(), '.gitnexus', 'config.json');
30
64
  const REGISTRY_PATH = path.join(os.homedir(), '.gitnexus', 'connect-registry.json');
@@ -298,7 +332,7 @@ async function handlePreToolUse(input, config, entry) {
298
332
 
299
333
  const res = await httpPostJson(
300
334
  `${config.hubUrl}/api/repos/${entry.hubRepoId}/augment`,
301
- { Authorization: `Bearer ${config.hubToken}` },
335
+ authHeaders(config),
302
336
  { pattern },
303
337
  );
304
338
  if (!res || res.status !== 200 || !res.body || !res.body.text) return;
@@ -360,9 +394,10 @@ async function handlePostToolUse(input, config, entry) {
360
394
 
361
395
  let meta = readMetaCache(entry.hubRepoId);
362
396
  if (!meta) {
363
- const res = await httpGetJson(`${config.hubUrl}/api/repos/${entry.hubRepoId}/meta`, {
364
- Authorization: `Bearer ${config.hubToken}`,
365
- });
397
+ const res = await httpGetJson(
398
+ `${config.hubUrl}/api/repos/${entry.hubRepoId}/meta`,
399
+ authHeaders(config),
400
+ );
366
401
  if (!res || res.status !== 200 || !res.body) return;
367
402
  meta = res.body;
368
403
  writeMetaCache(entry.hubRepoId, meta);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexushub",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Connect your editor to GitNexus Hub — one command MCP setup + project context",
5
5
  "author": "Abhigyan Patwari",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",