# 1. Find and follow code with Axon

Source: https://usecns.dev/tutorial-axon/

[Learning path](https://usecns.dev/get-started/) · **1. Axon** → [2. Soma](https://usecns.dev/tutorial-soma/) → [3. Activate a rule](https://usecns.dev/tutorial-soma-gate/)

**Goal:** find the code behind a retry, follow its caller, and inspect an edit's structural impact. Use this workflow when you are new to a repository or need to narrow a change before reading everything.

## 1. Install only Axon

Install Axon with one Homebrew command. The tap is private: see [installation and access](https://usecns.dev/install/) first. On a Linux server, install the release archive instead (same page).

```
brew install ivannovak/cns/axon
```

Check the installation:

```
axon --version
```

The remaining example was exercised with **Axon 1.6.4**. There is no need to install the other organs.

## 2. Create a small repository

Run this in a directory where `cns-first-steps` does not already exist. Keep this shell in the new repository for the rest of the lessons.

```
mkdir cns-first-steps
cd cns-first-steps
git init
git checkout -b main
mkdir src test
printf '%s\n' '{"name":"cns-first-steps","private":true,"type":"module"}' > package.json
printf '%s\n' '.axon/' > .gitignore

cat > src/invoices.js <<'EOF'
export function processInvoice(invoice, submit) {
  return submit({ invoiceId: invoice.id, idempotencyKey: invoice.id });
}

export function retryInvoice(invoice, submit) {
  return processInvoice(invoice, submit);
}
EOF

cat > test/invoices.test.js <<'EOF'
import test from 'node:test';
import assert from 'node:assert/strict';
import { processInvoice, retryInvoice } from '../src/invoices.js';

test('retry keeps the original invoice idempotency key', () => {
  const requests = [];
  const submit = request => requests.push(request);
  const invoice = { id: 'invoice-42' };
  processInvoice(invoice, submit);
  retryInvoice(invoice, submit);
  assert.deepEqual(requests.map(r => r.idempotencyKey), ['invoice-42', 'invoice-42']);
});
EOF

node --test
git add .gitignore package.json src test
git commit -m 'Add invoice retry example'
```

**Expected:** one passing test and an initial commit. Git needs your existing author identity; configure it locally if Git asks. No network request or actual invoice is sent: `submit` only appends to an array.

The rule is simple: an invoice's first submission and its retry must use the **same idempotency key**. Generating a new key on retry could cause a real downstream service to treat it as a second operation.

## 3. Index and find the implementation

```
axon index --full --json
axon status --json
axon search processInvoice --json
```

**Expected:** the index is created under `.axon/`; the search returns the `processInvoice` symbol and its file path, `src/invoices.js`. Open that file rather than copying an opaque node ID from someone else's machine. Index counts and identifiers can vary with the installed version.

The search result includes these fields (excerpt):

```
{
  "filePath": "src/invoices.js",
  "languageId": "javascript",
  "symbolKind": "Function",
  "symbolName": "processInvoice"
}
```

Open that function. You should see `invoice.id` used as both the invoice identifier and the idempotency key. `status` describes the index; a successful exit alone does not prove it is fresh or that extraction is complete.

## 4. Follow the caller

```
axon trace processInvoice --direction incoming --depth 3 --json
```

**Look for:** `retryInvoice` calling `processInvoice`. Confirm that relationship by opening the small source file. This is structural evidence, not a proof that every runtime caller has been found. If your project has several functions with the same name, use the exact node ID returned by `search`.

No embedding provider or relay is used by these name and structural queries. You can stop here and already use Axon to orient yourself in a codebase.

## 5. Inspect an edit without changing its behavior

Make a harmless local rename inside `retryInvoice`:

```
python3 - <<'PY'
from pathlib import Path
path = Path('src/invoices.js')
text = path.read_text()
text = text.replace('retryInvoice(invoice, submit)', 'retryInvoice(invoice, send)')
text = text.replace('return processInvoice(invoice, submit);', 'return processInvoice(invoice, send);')
path.write_text(text)
PY
node --test
axon index --full --json
axon delta --base main --json
git diff -- src/invoices.js
```

**Expected:** the application test still passes. The diff renames a parameter without changing the retry behavior. The delta describes the comparison with `main`, including the working-tree edit; inspect its changed files/symbols and trust or truncation information. It is not a safety verdict.

For this exact block you also need Python 3, used only to make the edit repeatable; you can instead rename the parameter and its use in your editor.

Restore this disposable edit before continuing:

```
git restore -- src/invoices.js
axon index --full --json
node --test
```

Use `git restore` here only because this lesson owns the edit in a disposable example. Do not copy that reset over work you want to keep in your real repository.

## What you have learned

Axon answers **where the code is, what calls it, and what an edit may reach**. It does not remember the project's rule about retry keys or execute the application test for you.

**Next:** [install Soma and express that rule as a concern →](https://usecns.dev/tutorial-soma/). Keep this repository; you will not start over.