gitnexushub 0.4.5 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -311,11 +311,103 @@ function httpGetJson(urlStr, headers) {
311
311
  }
312
312
 
313
313
  /**
314
- * Emit the Claude Code / Cursor / OpenCode hookSpecificOutput envelope.
315
- * The editor will prepend `message` to the tool's output before handing
316
- * control back to the model.
314
+ * Map raw `hook_event_name` strings (as written by each editor) onto
315
+ * the Claude Code-canonical PascalCase form the rest of this script
316
+ * uses. Returns null if the event isn't one we handle.
317
+ *
318
+ * Claude Code / OpenCode → "PreToolUse" / "PostToolUse" (PascalCase)
319
+ * Cursor 2.4+ → "preToolUse" / "postToolUse" (camelCase, see cursor.com/docs/hooks)
320
+ * Kiro IDE → "pre-tool-use" / "post-tool-use" (kebab-case, see kiro.dev/docs/hooks/types)
321
+ *
322
+ * Three different conventions; one script. Without this normalisation
323
+ * Cursor and Kiro hooks fire but the script bails on the event check
324
+ * and emits nothing — which is exactly the bug v0.6.0 shipped with.
325
+ */
326
+ function normaliseEvent(rawEvent) {
327
+ if (rawEvent === 'PreToolUse' || rawEvent === 'pre-tool-use' || rawEvent === 'preToolUse') {
328
+ return 'PreToolUse';
329
+ }
330
+ if (
331
+ rawEvent === 'PostToolUse' ||
332
+ rawEvent === 'post-tool-use' ||
333
+ rawEvent === 'postToolUse'
334
+ ) {
335
+ return 'PostToolUse';
336
+ }
337
+ return null;
338
+ }
339
+
340
+ /**
341
+ * Read an explicit agent override from argv. Each hook installer
342
+ * appends `--agent=<id>` to the spawn command so `/api/activity/*`
343
+ * captures can split rows by editor (claude-code vs cursor vs
344
+ * opencode vs kiro). The stdin payload alone can't distinguish
345
+ * Cursor from Claude Code from OpenCode — they all emit
346
+ * `hook_event_name: PreToolUse` — so the agent identity has to be
347
+ * baked in at install time.
348
+ *
349
+ * Returns null when the flag isn't present; callers fall back to
350
+ * stdin-based detection.
351
+ */
352
+ function parseAgentArg() {
353
+ for (const arg of process.argv.slice(2)) {
354
+ const m = arg.match(/^--agent=(.+)$/);
355
+ if (m) return m[1];
356
+ }
357
+ return null;
358
+ }
359
+
360
+ /**
361
+ * Detect which editor invoked us, used to tag /api/activity captures
362
+ * with the right `agentName`. Priority:
363
+ * 1. `--agent=<id>` argv flag (set by the hook installer at
364
+ * install time — the only reliable way to distinguish editors
365
+ * that share the PascalCase MCP convention)
366
+ * 2. kebab-case `pre-tool-use` / `post-tool-use` event → `kiro`
367
+ * (Kiro is the only editor emitting kebab-case)
368
+ * 3. fallback → `claude-code` (matches the historical hardcoded
369
+ * value, so older installs without the argv flag keep working)
370
+ */
371
+ function detectAgent(rawEvent) {
372
+ const explicit = parseAgentArg();
373
+ if (explicit) return explicit;
374
+ if (rawEvent === 'pre-tool-use' || rawEvent === 'post-tool-use') return 'kiro';
375
+ if (rawEvent === 'preToolUse' || rawEvent === 'postToolUse') return 'cursor';
376
+ return 'claude-code';
377
+ }
378
+
379
+ /**
380
+ * Normalise the editor-specific tool name onto the Claude Code-
381
+ * canonical PascalCase shape the rest of this script uses. Cursor
382
+ * calls the shell tool `Shell` (cursor.com/docs/hooks postToolUse
383
+ * example), Claude Code / Kiro / OpenCode call it `Bash`. Other
384
+ * tool names match across editors so far.
385
+ */
386
+ function normaliseToolName(raw) {
387
+ if (raw === 'Shell') return 'Bash';
388
+ return raw || '';
389
+ }
390
+
391
+ /**
392
+ * Emit the response in the format the source editor expects. Three
393
+ * envelopes today, one script:
394
+ *
395
+ * Claude Code / OpenCode → `hookSpecificOutput` envelope
396
+ * ({ hookSpecificOutput: { hookEventName, additionalContext } })
397
+ * Cursor 2.4+ → `additional_context` (snake_case top-level)
398
+ * ({ additional_context: "..." }) see cursor.com/docs/hooks
399
+ * Kiro IDE → plain stdout (kiro.dev/docs/hooks/actions
400
+ * "the stdout output of the command is added to the agent's context")
317
401
  */
318
- function sendResponse(event, message) {
402
+ function sendResponse(event, agentName, message) {
403
+ if (agentName === 'kiro') {
404
+ process.stdout.write(message + '\n');
405
+ return;
406
+ }
407
+ if (agentName === 'cursor') {
408
+ process.stdout.write(JSON.stringify({ additional_context: message }) + '\n');
409
+ return;
410
+ }
319
411
  process.stdout.write(
320
412
  JSON.stringify({
321
413
  hookSpecificOutput: { hookEventName: event, additionalContext: message },
@@ -323,8 +415,8 @@ function sendResponse(event, message) {
323
415
  );
324
416
  }
325
417
 
326
- async function handlePreToolUse(input, config, entry) {
327
- const toolName = input.tool_name || '';
418
+ async function handlePreToolUse(input, config, entry, agentName) {
419
+ const toolName = normaliseToolName(input.tool_name);
328
420
  if (toolName !== 'Grep' && toolName !== 'Glob' && toolName !== 'Bash') return;
329
421
 
330
422
  const pattern = extractPattern(toolName, input.tool_input || {});
@@ -339,7 +431,7 @@ async function handlePreToolUse(input, config, entry) {
339
431
 
340
432
  const text = String(res.body.text).trim();
341
433
  if (!text) return;
342
- sendResponse('PreToolUse', text);
434
+ sendResponse('PreToolUse', agentName, text);
343
435
  }
344
436
 
345
437
  /**
@@ -368,8 +460,54 @@ function writeMetaCache(repoId, meta) {
368
460
  }
369
461
  }
370
462
 
371
- async function handlePostToolUse(input, config, entry) {
372
- if (input.tool_name !== 'Bash') return;
463
+ /**
464
+ * Edit-closure capture. After Edit/Write/MultiEdit succeeds in the agent,
465
+ * fire a fire-and-forget POST telling the hub which file was edited. The
466
+ * hub correlates against recent MCP result_symbols to record whether
467
+ * GitNexus drove this edit (the strongest possible quality signal).
468
+ *
469
+ * Best-effort: never blocks the editor, never re-tries, swallows errors.
470
+ */
471
+ async function handleEditObservation(input, config, entry, agentName) {
472
+ const tool = normaliseToolName(input.tool_name);
473
+ if (tool !== 'Edit' && tool !== 'Write' && tool !== 'MultiEdit') return;
474
+
475
+ // Only fire when the edit succeeded. Some editors omit exit info; treat
476
+ // missing as success so we don't drop legitimate edits.
477
+ const out = input.tool_output;
478
+ if (out && out.exit_code !== undefined && out.exit_code !== 0) return;
479
+ if (out && out.error) return;
480
+
481
+ const filePath = (input.tool_input && input.tool_input.file_path) || '';
482
+ if (!filePath || typeof filePath !== 'string') return;
483
+
484
+ // Best-effort line extraction. Edit tool input often carries a `line`
485
+ // hint; MultiEdit usually doesn't.
486
+ const line = Number.isInteger(input.tool_input && input.tool_input.line)
487
+ ? Number(input.tool_input.line)
488
+ : null;
489
+
490
+ await httpPostJson(`${config.hubUrl}/api/activity/edit-observed`, authHeaders(config), {
491
+ sessionId: input.session_id || null,
492
+ repoId: entry.hubRepoId,
493
+ filePath,
494
+ line,
495
+ tool,
496
+ agentName,
497
+ });
498
+ }
499
+
500
+ async function handlePostToolUse(input, config, entry, agentName) {
501
+ const toolName = normaliseToolName(input.tool_name);
502
+
503
+ // Fan out: edit observations are independent of the git-staleness check.
504
+ // Both run on PostToolUse; we don't want one to block the other.
505
+ if (toolName === 'Edit' || toolName === 'Write' || toolName === 'MultiEdit') {
506
+ await handleEditObservation(input, config, entry, agentName);
507
+ return;
508
+ }
509
+
510
+ if (toolName !== 'Bash') return;
373
511
  const cmd = (input.tool_input && input.tool_input.command) || '';
374
512
  if (!/\bgit\s+(commit|merge|rebase|cherry-pick|pull)(\s|$)/.test(cmd)) return;
375
513
 
@@ -407,20 +545,114 @@ async function handlePostToolUse(input, config, entry) {
407
545
  const shortOld = meta.last_commit ? String(meta.last_commit).slice(0, 7) : 'none';
408
546
  sendResponse(
409
547
  'PostToolUse',
548
+ agentName,
410
549
  `GitNexus index is stale (last indexed: ${shortOld}). Run \`gnx sync\` to update.`,
411
550
  );
412
551
  }
413
552
 
553
+ // ─── Soft-nudge upgrade flow ──────────────────────────────────────────────
554
+ //
555
+ // Hook version is read from the bundled package.json. Once per local day
556
+ // we hit /api/activity/hook-version and compare. If the published latest
557
+ // is ahead of ours, we print a single stderr line — never blocks editing.
558
+ // State is held in ~/.gitnexus/hook-version-check.json so we don't spam
559
+ // the hub on every PreToolUse.
560
+
561
+ const VERSION_CHECK_FILE = path.join(os.homedir(), '.gitnexus', 'hook-version-check.json');
562
+ const VERSION_CHECK_TTL_MS = 24 * 60 * 60 * 1000; // once per day
563
+
564
+ function readPackageVersion() {
565
+ try {
566
+ const pkgPath = path.join(__dirname, '..', 'package.json');
567
+ return JSON.parse(fs.readFileSync(pkgPath, 'utf-8')).version || null;
568
+ } catch {
569
+ return null;
570
+ }
571
+ }
572
+
573
+ function readVersionCheckState() {
574
+ try {
575
+ const stat = fs.statSync(VERSION_CHECK_FILE);
576
+ if (Date.now() - stat.mtimeMs > VERSION_CHECK_TTL_MS) return null;
577
+ return JSON.parse(fs.readFileSync(VERSION_CHECK_FILE, 'utf-8'));
578
+ } catch {
579
+ return null;
580
+ }
581
+ }
582
+
583
+ function writeVersionCheckState(state) {
584
+ try {
585
+ fs.mkdirSync(path.dirname(VERSION_CHECK_FILE), { recursive: true });
586
+ fs.writeFileSync(VERSION_CHECK_FILE, JSON.stringify(state));
587
+ } catch {
588
+ /* ignore — best effort */
589
+ }
590
+ }
591
+
592
+ /**
593
+ * Compare two semver strings (major.minor.patch only — pre-releases ignored).
594
+ * Returns -1 if a < b, 0 if equal, 1 if a > b. Defensive against malformed.
595
+ */
596
+ function compareSemver(a, b) {
597
+ const pa = String(a || '0.0.0')
598
+ .split('.')
599
+ .map((n) => parseInt(n, 10) || 0);
600
+ const pb = String(b || '0.0.0')
601
+ .split('.')
602
+ .map((n) => parseInt(n, 10) || 0);
603
+ for (let i = 0; i < 3; i++) {
604
+ const x = pa[i] || 0;
605
+ const y = pb[i] || 0;
606
+ if (x < y) return -1;
607
+ if (x > y) return 1;
608
+ }
609
+ return 0;
610
+ }
611
+
612
+ async function maybeNudgeUpgrade(config) {
613
+ const local = readPackageVersion();
614
+ if (!local) return;
615
+
616
+ const cached = readVersionCheckState();
617
+ if (cached && compareSemver(local, cached.latestVersion) >= 0) return;
618
+
619
+ const res = await httpGetJson(`${config.hubUrl}/api/activity/hook-version`, authHeaders(config));
620
+ if (!res || res.status !== 200 || !res.body) return;
621
+
622
+ const latest = res.body.latestVersion;
623
+ if (!latest) return;
624
+
625
+ writeVersionCheckState({ latestVersion: latest, checkedAt: Date.now() });
626
+
627
+ if (compareSemver(local, latest) < 0) {
628
+ const note = res.body.notes ? ` — ${res.body.notes}` : '';
629
+ process.stderr.write(
630
+ `[gitnexus] connect hook ${local} → update available (${latest})${note}. ` +
631
+ `Run: npm update -g gitnexushub\n`,
632
+ );
633
+ }
634
+ }
635
+
414
636
  async function main() {
415
637
  if (process.env.GITNEXUS_NO_AUGMENT === '1') return;
416
638
 
417
639
  const input = readInput();
418
- const event = input.hook_event_name;
419
- if (event !== 'PreToolUse' && event !== 'PostToolUse') return;
640
+ const rawEvent = input.hook_event_name;
641
+ const event = normaliseEvent(rawEvent);
642
+ if (!event) return;
643
+
644
+ const agentName = detectAgent(rawEvent);
420
645
 
421
646
  const config = readConfig();
422
647
  if (!config || !config.hubToken || !config.hubUrl) return;
423
648
 
649
+ // Once-per-day soft-nudge if we're behind. Best-effort, won't block.
650
+ // Skipped entirely on PostToolUse so the editor's response path stays
651
+ // hot — PreToolUse fires more often, so the check still happens daily.
652
+ if (event === 'PreToolUse') {
653
+ maybeNudgeUpgrade(config).catch(() => {});
654
+ }
655
+
424
656
  const entries = readRegistry();
425
657
  const cwd = input.cwd || process.cwd();
426
658
  const entry = resolveCwdToRepo(cwd, entries);
@@ -428,9 +660,9 @@ async function main() {
428
660
 
429
661
  try {
430
662
  if (event === 'PreToolUse') {
431
- await handlePreToolUse(input, config, entry);
663
+ await handlePreToolUse(input, config, entry, agentName);
432
664
  } else {
433
- await handlePostToolUse(input, config, entry);
665
+ await handlePostToolUse(input, config, entry, agentName);
434
666
  }
435
667
  } catch (err) {
436
668
  if (process.env.GITNEXUS_DEBUG) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexushub",
3
- "version": "0.4.5",
3
+ "version": "0.7.0",
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",
@@ -1,89 +1,89 @@
1
- ---
2
- name: gitnexus-debugging
3
- description: "Use when the user is debugging a bug, tracing an error, or asking why something fails. Examples: \"Why is X failing?\", \"Where does this error come from?\", \"Trace this bug\""
4
- ---
5
-
6
- # Debugging with GitNexus
7
-
8
- ## When to Use
9
-
10
- - "Why is this function failing?"
11
- - "Trace where this error comes from"
12
- - "Who calls this method?"
13
- - "This endpoint returns 500"
14
- - Investigating bugs, errors, or unexpected behavior
15
-
16
- ## Workflow
17
-
18
- ```
19
- 1. gitnexus_query({query: "<error or symptom>"}) → Find related execution flows
20
- 2. gitnexus_context({name: "<suspect>"}) → See callers/callees/processes
21
- 3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow
22
- 4. gitnexus_cypher({query: "MATCH path..."}) → Custom traces if needed
23
- ```
24
-
25
- > If "Index is stale" → trigger re-indexing from the Hub dashboard.
26
-
27
- ## Checklist
28
-
29
- ```
30
- - [ ] Understand the symptom (error message, unexpected behavior)
31
- - [ ] gitnexus_query for error text or related code
32
- - [ ] Identify the suspect function from returned processes
33
- - [ ] gitnexus_context to see callers and callees
34
- - [ ] Trace execution flow via process resource if applicable
35
- - [ ] gitnexus_cypher for custom call chain traces if needed
36
- - [ ] Read source files to confirm root cause
37
- ```
38
-
39
- ## Debugging Patterns
40
-
41
- | Symptom | GitNexus Approach |
42
- | -------------------- | ---------------------------------------------------------- |
43
- | Error message | `gitnexus_query` for error text → `context` on throw sites |
44
- | Wrong return value | `context` on the function → trace callees for data flow |
45
- | Intermittent failure | `context` → look for external calls, async deps |
46
- | Performance issue | `context` → find symbols with many callers (hot paths) |
47
- | Recent regression | `impact` on changed functions → check what callers broke |
48
-
49
- ## Tools
50
-
51
- **gitnexus_query** — find code related to error:
52
-
53
- ```
54
- gitnexus_query({query: "payment validation error"})
55
- → Processes: CheckoutFlow, ErrorHandling
56
- → Symbols: validatePayment, handlePaymentError, PaymentException
57
- ```
58
-
59
- **gitnexus_context** — full context for a suspect:
60
-
61
- ```
62
- gitnexus_context({name: "validatePayment"})
63
- → Incoming calls: processCheckout, webhookHandler
64
- → Outgoing calls: verifyCard, fetchRates (external API!)
65
- → Processes: CheckoutFlow (step 3/7)
66
- ```
67
-
68
- **gitnexus_cypher** — custom call chain traces:
69
-
70
- ```cypher
71
- MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
72
- RETURN [n IN nodes(path) | n.name] AS chain
73
- ```
74
-
75
- ## Example: "Payment endpoint returns 500 intermittently"
76
-
77
- ```
78
- 1. gitnexus_query({query: "payment error handling"})
79
- → Processes: CheckoutFlow, ErrorHandling
80
- → Symbols: validatePayment, handlePaymentError
81
-
82
- 2. gitnexus_context({name: "validatePayment"})
83
- → Outgoing calls: verifyCard, fetchRates (external API!)
84
-
85
- 3. READ gitnexus://repo/my-app/process/CheckoutFlow
86
- → Step 3: validatePayment → calls fetchRates (external)
87
-
88
- 4. Root cause: fetchRates calls external API without proper timeout
89
- ```
1
+ ---
2
+ name: gitnexus-debugging
3
+ description: "Use when the user is debugging a bug, tracing an error, or asking why something fails. Examples: \"Why is X failing?\", \"Where does this error come from?\", \"Trace this bug\""
4
+ ---
5
+
6
+ # Debugging with GitNexus
7
+
8
+ ## When to Use
9
+
10
+ - "Why is this function failing?"
11
+ - "Trace where this error comes from"
12
+ - "Who calls this method?"
13
+ - "This endpoint returns 500"
14
+ - Investigating bugs, errors, or unexpected behavior
15
+
16
+ ## Workflow
17
+
18
+ ```
19
+ 1. gitnexus_query({query: "<error or symptom>"}) → Find related execution flows
20
+ 2. gitnexus_context({name: "<suspect>"}) → See callers/callees/processes
21
+ 3. READ gitnexus://repo/{name}/process/{name} → Trace execution flow
22
+ 4. gitnexus_cypher({query: "MATCH path..."}) → Custom traces if needed
23
+ ```
24
+
25
+ > If "Index is stale" → trigger re-indexing from the Hub dashboard.
26
+
27
+ ## Checklist
28
+
29
+ ```
30
+ - [ ] Understand the symptom (error message, unexpected behavior)
31
+ - [ ] gitnexus_query for error text or related code
32
+ - [ ] Identify the suspect function from returned processes
33
+ - [ ] gitnexus_context to see callers and callees
34
+ - [ ] Trace execution flow via process resource if applicable
35
+ - [ ] gitnexus_cypher for custom call chain traces if needed
36
+ - [ ] Read source files to confirm root cause
37
+ ```
38
+
39
+ ## Debugging Patterns
40
+
41
+ | Symptom | GitNexus Approach |
42
+ | -------------------- | ---------------------------------------------------------- |
43
+ | Error message | `gitnexus_query` for error text → `context` on throw sites |
44
+ | Wrong return value | `context` on the function → trace callees for data flow |
45
+ | Intermittent failure | `context` → look for external calls, async deps |
46
+ | Performance issue | `context` → find symbols with many callers (hot paths) |
47
+ | Recent regression | `impact` on changed functions → check what callers broke |
48
+
49
+ ## Tools
50
+
51
+ **gitnexus_query** — find code related to error:
52
+
53
+ ```
54
+ gitnexus_query({query: "payment validation error"})
55
+ → Processes: CheckoutFlow, ErrorHandling
56
+ → Symbols: validatePayment, handlePaymentError, PaymentException
57
+ ```
58
+
59
+ **gitnexus_context** — full context for a suspect:
60
+
61
+ ```
62
+ gitnexus_context({name: "validatePayment"})
63
+ → Incoming calls: processCheckout, webhookHandler
64
+ → Outgoing calls: verifyCard, fetchRates (external API!)
65
+ → Processes: CheckoutFlow (step 3/7)
66
+ ```
67
+
68
+ **gitnexus_cypher** — custom call chain traces:
69
+
70
+ ```cypher
71
+ MATCH path = (a)-[:CodeRelation {type: 'CALLS'}*1..2]->(b:Function {name: "validatePayment"})
72
+ RETURN [n IN nodes(path) | n.name] AS chain
73
+ ```
74
+
75
+ ## Example: "Payment endpoint returns 500 intermittently"
76
+
77
+ ```
78
+ 1. gitnexus_query({query: "payment error handling"})
79
+ → Processes: CheckoutFlow, ErrorHandling
80
+ → Symbols: validatePayment, handlePaymentError
81
+
82
+ 2. gitnexus_context({name: "validatePayment"})
83
+ → Outgoing calls: verifyCard, fetchRates (external API!)
84
+
85
+ 3. READ gitnexus://repo/my-app/process/CheckoutFlow
86
+ → Step 3: validatePayment → calls fetchRates (external)
87
+
88
+ 4. Root cause: fetchRates calls external API without proper timeout
89
+ ```
@@ -1,78 +1,78 @@
1
- ---
2
- name: gitnexus-exploring
3
- description: "Use when the user asks how code works, wants to understand architecture, trace execution flows, or explore unfamiliar parts of the codebase. Examples: \"How does X work?\", \"What calls this function?\", \"Show me the auth flow\""
4
- ---
5
-
6
- # Exploring Codebases with GitNexus
7
-
8
- ## When to Use
9
-
10
- - "How does authentication work?"
11
- - "What's the project structure?"
12
- - "Show me the main components"
13
- - "Where is the database logic?"
14
- - Understanding code you haven't seen before
15
-
16
- ## Workflow
17
-
18
- ```
19
- 1. READ gitnexus://repos → Discover indexed repos
20
- 2. READ gitnexus://repo/{name}/context → Codebase overview, check staleness
21
- 3. gitnexus_query({query: "<what you want to understand>"}) → Find related execution flows
22
- 4. gitnexus_context({name: "<symbol>"}) → Deep dive on specific symbol
23
- 5. READ gitnexus://repo/{name}/process/{name} → Trace full execution flow
24
- ```
25
-
26
- > If step 2 says "Index is stale" → trigger re-indexing from the Hub dashboard.
27
-
28
- ## Checklist
29
-
30
- ```
31
- - [ ] READ gitnexus://repo/{name}/context
32
- - [ ] gitnexus_query for the concept you want to understand
33
- - [ ] Review returned processes (execution flows)
34
- - [ ] gitnexus_context on key symbols for callers/callees
35
- - [ ] READ process resource for full execution traces
36
- - [ ] Read source files for implementation details
37
- ```
38
-
39
- ## Resources
40
-
41
- | Resource | What you get |
42
- | --------------------------------------- | ------------------------------------------------------- |
43
- | `gitnexus://repo/{name}/context` | Stats, staleness warning (~150 tokens) |
44
- | `gitnexus://repo/{name}/clusters` | All functional areas with cohesion scores (~300 tokens) |
45
- | `gitnexus://repo/{name}/cluster/{name}` | Area members with file paths (~500 tokens) |
46
- | `gitnexus://repo/{name}/process/{name}` | Step-by-step execution trace (~200 tokens) |
47
-
48
- ## Tools
49
-
50
- **gitnexus_query** — find execution flows related to a concept:
51
-
52
- ```
53
- gitnexus_query({query: "payment processing"})
54
- → Processes: CheckoutFlow, RefundFlow, WebhookHandler
55
- → Symbols grouped by flow with file locations
56
- ```
57
-
58
- **gitnexus_context** — 360-degree view of a symbol:
59
-
60
- ```
61
- gitnexus_context({name: "validateUser"})
62
- → Incoming calls: loginHandler, apiMiddleware
63
- → Outgoing calls: checkToken, getUserById
64
- → Processes: LoginFlow (step 2/5), TokenRefresh (step 1/3)
65
- ```
66
-
67
- ## Example: "How does payment processing work?"
68
-
69
- ```
70
- 1. READ gitnexus://repo/my-app/context → 918 symbols, 45 processes
71
- 2. gitnexus_query({query: "payment processing"})
72
- → CheckoutFlow: processPayment → validateCard → chargeStripe
73
- → RefundFlow: initiateRefund → calculateRefund → processRefund
74
- 3. gitnexus_context({name: "processPayment"})
75
- → Incoming: checkoutHandler, webhookHandler
76
- → Outgoing: validateCard, chargeStripe, saveTransaction
77
- 4. Read src/payments/processor.ts for implementation details
78
- ```
1
+ ---
2
+ name: gitnexus-exploring
3
+ description: "Use when the user asks how code works, wants to understand architecture, trace execution flows, or explore unfamiliar parts of the codebase. Examples: \"How does X work?\", \"What calls this function?\", \"Show me the auth flow\""
4
+ ---
5
+
6
+ # Exploring Codebases with GitNexus
7
+
8
+ ## When to Use
9
+
10
+ - "How does authentication work?"
11
+ - "What's the project structure?"
12
+ - "Show me the main components"
13
+ - "Where is the database logic?"
14
+ - Understanding code you haven't seen before
15
+
16
+ ## Workflow
17
+
18
+ ```
19
+ 1. READ gitnexus://repos → Discover indexed repos
20
+ 2. READ gitnexus://repo/{name}/context → Codebase overview, check staleness
21
+ 3. gitnexus_query({query: "<what you want to understand>"}) → Find related execution flows
22
+ 4. gitnexus_context({name: "<symbol>"}) → Deep dive on specific symbol
23
+ 5. READ gitnexus://repo/{name}/process/{name} → Trace full execution flow
24
+ ```
25
+
26
+ > If step 2 says "Index is stale" → trigger re-indexing from the Hub dashboard.
27
+
28
+ ## Checklist
29
+
30
+ ```
31
+ - [ ] READ gitnexus://repo/{name}/context
32
+ - [ ] gitnexus_query for the concept you want to understand
33
+ - [ ] Review returned processes (execution flows)
34
+ - [ ] gitnexus_context on key symbols for callers/callees
35
+ - [ ] READ process resource for full execution traces
36
+ - [ ] Read source files for implementation details
37
+ ```
38
+
39
+ ## Resources
40
+
41
+ | Resource | What you get |
42
+ | --------------------------------------- | ------------------------------------------------------- |
43
+ | `gitnexus://repo/{name}/context` | Stats, staleness warning (~150 tokens) |
44
+ | `gitnexus://repo/{name}/clusters` | All functional areas with cohesion scores (~300 tokens) |
45
+ | `gitnexus://repo/{name}/cluster/{name}` | Area members with file paths (~500 tokens) |
46
+ | `gitnexus://repo/{name}/process/{name}` | Step-by-step execution trace (~200 tokens) |
47
+
48
+ ## Tools
49
+
50
+ **gitnexus_query** — find execution flows related to a concept:
51
+
52
+ ```
53
+ gitnexus_query({query: "payment processing"})
54
+ → Processes: CheckoutFlow, RefundFlow, WebhookHandler
55
+ → Symbols grouped by flow with file locations
56
+ ```
57
+
58
+ **gitnexus_context** — 360-degree view of a symbol:
59
+
60
+ ```
61
+ gitnexus_context({name: "validateUser"})
62
+ → Incoming calls: loginHandler, apiMiddleware
63
+ → Outgoing calls: checkToken, getUserById
64
+ → Processes: LoginFlow (step 2/5), TokenRefresh (step 1/3)
65
+ ```
66
+
67
+ ## Example: "How does payment processing work?"
68
+
69
+ ```
70
+ 1. READ gitnexus://repo/my-app/context → 918 symbols, 45 processes
71
+ 2. gitnexus_query({query: "payment processing"})
72
+ → CheckoutFlow: processPayment → validateCard → chargeStripe
73
+ → RefundFlow: initiateRefund → calculateRefund → processRefund
74
+ 3. gitnexus_context({name: "processPayment"})
75
+ → Incoming: checkoutHandler, webhookHandler
76
+ → Outgoing: validateCard, chargeStripe, saveTransaction
77
+ 4. Read src/payments/processor.ts for implementation details
78
+ ```