Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions cli/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
title: "Authentication"
description: "How the Linkrunner CLI authenticates with your account"
icon: "key"
---

The CLI uses **API keys** to authenticate with the Linkrunner API. There are two ways to obtain a key: the device login flow (recommended) or manual key creation from the dashboard.

## Device Login Flow

When you run `lr login`, the CLI uses an OAuth2 Device Authorization flow:

1. The CLI requests a **user code** from the Linkrunner API
2. You are shown a code (e.g. `BVKD-3NH7`) and a URL to open in your browser
3. You open the URL, log into the Linkrunner dashboard, and authorize the code
4. The CLI polls for approval and receives an API key automatically

```
$ lr login

Your device code: BVKD-3NH7

Open this URL to authorize:
https://dashboard.linkrunner.io/cli/auth?code=BVKD-3NH7

Waiting for authorization...

✔ Logged in successfully!
```

<Note>
The device code expires after **10 minutes**. If it expires, run `lr login` again to get a new code.
</Note>
Comment on lines +9 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check login.mdx for magic link documentation
echo "=== Current login.mdx authentication flow documentation ==="
rg -n -A 10 "## Authentication Flow" cli/commands/login.mdx

echo -e "\n=== Check for any other references to magic link ==="
rg -n "magic link" cli/

echo -e "\n=== Check for any other references to device code/OAuth2 ==="
rg -n -i "device code|device authorization|oauth" cli/

Repository: linkrunner-labs/docs

Length of output: 1971


Authentication flow in this section is incorrect—contradicts actual implementation documented in cli/commands/login.mdx and other files.

This section documents an OAuth2 Device Authorization flow where users receive a device code in the CLI and authorize it in the browser. However, cli/commands/login.mdx, cli/quickstart.mdx, cli/installation.mdx, and cli/troubleshooting.mdx all consistently document a magic link email flow:

  • CLI prompts for email
  • Magic link sent to inbox (15-minute expiration)
  • User pastes token/URL from email into terminal or opens link in browser

These flows are incompatible. The device code approach here appears outdated or incorrect. Update this section to match the actual magic link authentication flow, or clarify if this file documents a different/legacy flow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/authentication.mdx` around lines 9 - 33, The Device Login Flow doc is
incorrect and must be changed to the magic-link email flow used by the actual
implementation: update the content under "Device Login Flow" (and any example
output for the `lr login` command) to describe the CLI prompting for an email,
sending a magic link/token (15-minute expiration) to the user's inbox, and
instructing the user to paste the token or open the link in their browser to
complete login; ensure the text and example match the behavior and phrasing used
in cli/commands/login.mdx, cli/quickstart.mdx, cli/installation.mdx, and
cli/troubleshooting.mdx, or else mark this file explicitly as documenting a
legacy/alternate flow if that is intended.


## API Keys

Each login creates an API key that is stored locally. Keys have the prefix `lr_cli_` and can be managed from the Linkrunner dashboard.

### Key Properties

| Property | Description |
|---|---|
| **Prefix** | Starts with `lr_cli_` (first 12 chars visible in dashboard) |
| **Label** | Optional name for identification (auto-set to "CLI Login" for device flow) |
| **Last Used** | Timestamp of the most recent API call |
| **Created** | When the key was generated |

### Managing Keys from the Dashboard

Go to **Settings > CLI Keys** in the Linkrunner dashboard to:

- **View** all active CLI API keys and when they were last used
- **Create** a new key manually (useful for CI/CD or shared environments)
- **Revoke** a key to immediately invalidate it

<Warning>
Revoking a key is permanent. Any CLI session using that key will need to re-authenticate with `lr login`.
</Warning>

### Creating Keys for CI/CD

For automated environments where interactive login isn't possible, create a key manually:

1. Go to **Settings > CLI Keys** in the dashboard
2. Click **Create New Key**
3. Copy the key (it's only shown once)
4. Set it as an environment variable:

```bash
export LINKRUNNER_API_KEY=lr_cli_...
```

The CLI automatically picks up the `LINKRUNNER_API_KEY` environment variable when no stored session exists.

## Credential Storage

Your API key is stored in a local config file managed by [conf](https://github.com/sindresorhus/conf):

- **macOS:** `~/Library/Preferences/linkrunner-nodejs/config.json`
- **Linux:** `~/.config/linkrunner-nodejs/config.json`
- **Windows:** `%APPDATA%/linkrunner-nodejs/config.json`
Comment on lines +75 to +81

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check what login.mdx says is stored
echo "=== login.mdx credential storage documentation ==="
rg -n -A 5 "## Credential Storage" cli/commands/login.mdx

# Check for any other references to what's stored
echo -e "\n=== References to 'auth token' in CLI docs ==="
rg -n "auth token" cli/

echo -e "\n=== References to 'API key' storage ==="
rg -n "API key.*stored|stored.*API key" cli/

Repository: linkrunner-labs/docs

Length of output: 1599


Inconsistent credential terminology across documentation.

This section refers to the stored credential as "Your API key", but cli/commands/login.mdx (lines 59-62) and other CLI docs (cli/quickstart.mdx, cli/troubleshooting.mdx) consistently refer to the same stored credential as "Your auth token and email".

Both reference the same config file with identical paths. Clarify whether "API key" and "auth token" refer to the same credential, or if this documentation is incorrect. Align terminology across all files.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/authentication.mdx` around lines 75 - 81, The "Credential Storage"
section uses "Your API key" which conflicts with other docs that call the stored
data "your auth token and email" (see cli/commands/login.mdx,
cli/quickstart.mdx, cli/troubleshooting.mdx); update cli/authentication.mdx to
use the same terminology—either replace "Your API key" with "Your auth token and
email" or explicitly state that "API key" is synonymous with "auth token" and
include the same config file paths; ensure the phrasing matches the other CLI
docs so all references to the stored credential are consistent.


## Logout

To clear your stored credentials:

```bash
lr logout
```

This removes the locally stored API key but does **not** revoke it on the server. To fully revoke access, also delete the key from **Settings > CLI Keys** in the dashboard.

## Security

- API keys are hashed (SHA-256) before storage on the server — the raw key is never stored
- Keys are scoped to your user account, not individual projects
- The device flow codes use an ambiguity-excluded character set to avoid typos
- Device codes are single-use and expire after 10 minutes
168 changes: 168 additions & 0 deletions cli/ci-cd.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
title: "CI/CD Integration"
description: "Use the Linkrunner CLI in your CI/CD pipelines"
icon: "rotate"
---

## Overview

The Linkrunner CLI supports CI/CD workflows through two key features:

- **`--ci` flag** -- commands exit with code 0 (pass) or 1 (fail) instead of remaining interactive
- **`--json` flag** -- structured JSON output for machine parsing

These flags are available on `lr doctor`, `lr validate`, `lr analyze`, and `lr test`.

## Exit Codes

| Code | Meaning |
|---|---|
| `0` | All checks passed (no errors) |
| `1` | One or more errors found |

By default, warnings do not cause a non-zero exit. Add `--fail-on-warn` to treat warnings as failures.

## Commands for CI

### lr doctor --ci

Validates platform configuration and source code:

```bash
# Fail on errors only
lr doctor --ci

# Fail on errors AND warnings
lr doctor --ci --fail-on-warn
```

### lr test --ci

Verifies API connectivity and token validity:

```bash
lr test --ci
```

### lr analyze --ci

Runs standard checks plus AI-powered deep analysis:

```bash
lr analyze --ci --fail-on-warn
```

## Pipeline Examples

### GitHub Actions

```yaml
name: Linkrunner SDK Check
on: [push, pull_request]

jobs:
sdk-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Linkrunner CLI
run: npm install -g linkrunner-cli

- name: Validate SDK integration
run: lr doctor --ci --fail-on-warn

- name: Test API connectivity
run: lr test --ci
```

### GitLab CI

```yaml
sdk-check:
image: node:20
script:
- npm install -g linkrunner-cli
- lr doctor --ci --fail-on-warn
- lr test --ci
```

### Bitbucket Pipelines

```yaml
pipelines:
default:
- step:
name: SDK Validation
image: node:20
script:
- npm install -g linkrunner-cli
- lr doctor --ci --fail-on-warn
```

## JSON Output

Use `--json` to get machine-readable output for custom processing:

```bash
lr doctor --json | jq '.summary.errors'
```

The JSON structure for `lr doctor --json`:

```json
{
"project": {
"type": "flutter",
"sdkVersion": "3.2.1",
"root": "/path/to/project"
},
"results": [
{
"id": "check-id",
"name": "Check name",
"status": "pass",
"severity": "error",
"message": "Description",
"fix": "Suggested fix",
"autoFixable": false,
"docsUrl": "https://..."
}
],
"summary": {
"passed": 5,
"warnings": 1,
"errors": 0
}
}
```

## Combining Flags

You can combine `--ci` and `--json` for both structured output and exit codes:

```bash
# Get JSON output AND exit code
lr doctor --ci --json > results.json
echo "Exit code: $?"
```

## Requirements

- The project must contain a `.linkrunner.json` file (for `lr test`) or recognizable project files (for `lr doctor`)
- No interactive prompts are shown when `--ci` or `--json` is used
- `lr test` and `lr status` require a `.linkrunner.json` file created by `lr init`

<Note>
For CI environments, run `lr init` locally first and commit the `.linkrunner.json` file to your repository. The CLI reads this file to identify your project during CI runs.
</Note>

## Related

- [lr doctor](/cli/commands/doctor) -- full diagnostics reference
- [lr test](/cli/commands/test) -- API connectivity checks
- [lr analyze](/cli/commands/analyze) -- AI-powered analysis
105 changes: 105 additions & 0 deletions cli/commands/analyze.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: "lr analyze"
description: "Run AI-powered deep analysis of your SDK integration"
icon: "robot"
---

## Usage

```bash
lr analyze [options]
```

## Description

Runs all standard `lr doctor` checks plus an AI-powered deep analysis of your codebase. This is equivalent to running `lr doctor --deep`.

The AI analysis inspects your source code for subtle integration issues, incorrect usage patterns, missing best practices, and platform-specific problems that pattern-based checks cannot catch.

<Note>Requires authentication. Run `lr login` first.</Note>

## Options

| Flag | Description |
|---|---|
| `--json` | Output results as JSON |
| `--ci` | Exit with code 0 (pass) or 1 (fail) |
| `--fail-on-warn` | Treat warnings as failures in CI mode |

## What It Does

1. Runs all standard platform configuration checks (same as `lr doctor`)
2. Runs source code pattern scanning (same as `lr doctor`)
3. Sends project context to an AI model for deep analysis
4. Reports any additional issues found by the AI, including:
- File path and line number of the issue
- Severity level (error, warn, or info)
- Suggested fix

## Examples

### Basic analysis

```bash
lr analyze
```

```
Linkrunner Doctor
Diagnosing your SDK integration...

Project: react-native (SDK v2.3.0)
Root: /path/to/project

── Platform Configuration ──
✔ rn-linkrunner found in package.json
...

── Source Code ──
✔ init() call found
...

── Deep Analysis (AI-powered) ──
✘ [src/App.tsx:15] init() called outside useEffect - may run on every render
Fix: Move init() inside a useEffect with an empty dependency array
⚠ [src/screens/Payment.tsx:42] capturePayment amount is hardcoded
Fix: Use the actual transaction amount from your payment provider
✔ No additional issues found by AI analysis.
Comment on lines +62 to +67

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Example output contradicts itself.

Line 63–67 lists AI findings and then says “No additional issues found,” which is confusing. Remove that line or move it to a no‑findings example.

✂️ Suggested fix
-  ✔ No additional issues found by AI analysis.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
── Deep Analysis (AI-powered) ──
[src/App.tsx:15] init() called outside useEffect - may run on every render
Fix: Move init() inside a useEffect with an empty dependency array
[src/screens/Payment.tsx:42] capturePayment amount is hardcoded
Fix: Use the actual transaction amount from your payment provider
✔ No additional issues found by AI analysis.
── Deep Analysis (AI-powered) ──
[src/App.tsx:15] init() called outside useEffect - may run on every render
Fix: Move init() inside a useEffect with an empty dependency array
[src/screens/Payment.tsx:42] capturePayment amount is hardcoded
Fix: Use the actual transaction amount from your payment provider
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cli/commands/analyze.mdx` around lines 62 - 67, The example Deep Analysis
block is contradictory because it lists specific findings and then prints the
sentence "No additional issues found by AI analysis."; update the example output
in analyze.mdx so the "No additional issues found by AI analysis." line is
removed from this findings example (or moved to a separate "no-findings"
example). Locate the block starting with "── Deep Analysis (AI-powered) ──" and
the specific phrase "No additional issues found by AI analysis." and either
delete that sentence or create a separate example section that demonstrates the
no-findings case.

```

### JSON output for scripting

```bash
lr analyze --json
```

The JSON output includes a `deepAnalysis` array in addition to the standard `results`:

```json
{
"project": { "type": "react-native", "sdkVersion": "2.3.0", "root": "..." },
"results": [...],
"summary": { "passed": 5, "warnings": 1, "errors": 1 },
"deepAnalysis": [
{
"file": "src/App.tsx",
"line": 15,
"severity": "error",
"message": "init() called outside useEffect",
"fix": "Move init() inside a useEffect with an empty dependency array"
}
]
}
```

### In CI

```bash
lr analyze --ci --fail-on-warn
```

## Related

- [lr doctor](/cli/commands/doctor) -- standard diagnostics without AI analysis
- [lr suggest](/cli/commands/suggest) -- AI-powered feature suggestions
- [CI/CD Integration](/cli/ci-cd) -- pipeline examples
Loading