> ## Documentation Index
> Fetch the complete documentation index at: https://www.sentrial.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Code Integration

> Connect your GitHub repository and fix agent issues directly in your codebase. Chat with AI, get suggestions, see diffs, and create PRs.

## The Problem

Traditional observability tools show you *what* went wrong, but leave you to figure out *how* to fix it. You end up context-switching between dashboards, code editors, and AI assistants — copying error messages, searching for relevant code, and manually piecing together solutions.

## The Solution

Sentrial's Code Integration connects the dots. When you find an issue, you can:

* See the issue with full context (session data, events, diagnosis)
* Chat with AI that knows both the issue AND your codebase
* Get code suggestions with real diffs
* Create a PR with one click

## How It Works

<CardGroup cols={2}>
  <Card title="Connect Repository">
    Link your GitHub repo in Settings. Sentrial indexes your codebase.
  </Card>

  <Card title="Select Files">
    Choose which files/folders are relevant to your agent code.
  </Card>

  <Card title="Chat with AI">
    Discuss issues with context. Ask questions, get explanations.
  </Card>

  <Card title="Create PR">
    Accept suggestions and create a pull request automatically.
  </Card>
</CardGroup>

## Setting Up Code Integration

<Steps>
  <Step title="Connect GitHub">
    Go to **Codebase** in the sidebar, then click **Add Repository**. Authenticate with GitHub and select the repositories you want to connect.

    Sentrial will index your repository. This usually takes 1–5 minutes depending on size.
  </Step>

  <Step title="Select Relevant Files">
    Use the file tree to select folders containing your agent code. This helps the AI focus on relevant files when generating suggestions.

    **Pro tip:** Select your agent directory, tools, and any prompt files.
  </Step>

  <Step title="Start Chatting">
    You're ready! When you find an issue, click **"Fix in Code"** to open the code integration view with context pre-loaded. Or open the Codebase page directly to chat.
  </Step>
</Steps>

## Using the AI Chat

The AI chat is context-aware — it knows about:

<CardGroup cols={3}>
  <Card title="Your Code">
    The selected files from your repository.
  </Card>

  <Card title="The Issue">
    Session data, events, and diagnosis.
  </Card>

  <Card title="Best Practices">
    Common patterns for agent development.
  </Card>
</CardGroup>

### Example Prompts

* "Why is the search\_kb tool returning empty results?"
* "How can I add a fallback when the API times out?"
* "The agent keeps asking clarifying questions instead of acting. How do I fix the prompt?"
* "Add error handling to the create\_ticket tool"
* "Optimize this function to reduce token usage"

## Creating Pull Requests

When the AI suggests code changes, you'll see a diff view showing exactly what will change. If you're happy with the changes:

<Steps>
  <Step title="Review the diff">
    You can ask for modifications if needed.
  </Step>

  <Step title="Apply Changes">
    Click **"Apply Changes"** to stage the changes.
  </Step>

  <Step title="Create PR">
    Click **"Create PR"** to open a pull request on GitHub.
  </Step>

  <Step title="Merge">
    Review and merge the PR in GitHub as usual.
  </Step>
</Steps>

<Warning>
  Sentrial creates PRs on your behalf using your GitHub credentials. You maintain full control over what gets merged.
</Warning>

## Security & Privacy

<AccordionGroup>
  <Accordion title="OAuth Authentication">
    We use GitHub OAuth — we never store your GitHub password.
  </Accordion>

  <Accordion title="Minimal Permissions">
    We only request the permissions needed to read code and create PRs.
  </Accordion>

  <Accordion title="No Storage">
    Your code is processed in real-time and not stored on our servers.
  </Accordion>

  <Accordion title="You Control Access">
    Revoke access anytime from your GitHub settings.
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Issues & Diagnosis" icon="magnifying-glass" href="/concepts/diagnosis">
    Learn how issues are detected.
  </Card>

  <Card title="Sessions & Tracking" icon="timeline" href="/concepts/sessions">
    Track your agents properly.
  </Card>
</CardGroup>
