@agentlogs/opencode
v0.0.1
Published
AgentLogs plugin for OpenCode - automatically captures and uploads AI coding session transcripts
Maintainers
Readme
@agentlogs/opencode
OpenCode plugin for AgentLogs - automatically capture and upload AI coding session transcripts.
Features
- Automatic transcript capture: Uploads session transcripts when OpenCode becomes idle
- Git commit enhancement: Automatically adds transcript links to git commit messages
- Token & cost tracking: Calculates and tracks token usage and costs
- Git context preservation: Captures repository, branch, and working directory context
Installation
From npm
npm install -g @agentlogs/opencode
# or
bun add -g @agentlogs/opencodeConfigure OpenCode
Add the plugin to your opencode.json config file:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["@agentlogs/opencode"]
}Or for local development:
{
"plugin": [".opencode/plugin/agentlogs.ts"]
}Configuration
Environment Variables
| Variable | Required | Description |
| --------------- | -------- | -------------------------------------------- |
| VI_AUTH_TOKEN | Yes | Your AgentLogs authentication token |
| VI_SERVER_URL | No | Server URL (default: https://agentlogs.ai) |
Alternative variable names are also supported:
VIBEINSIGHTS_AUTH_TOKEN(alias forVI_AUTH_TOKEN)VIBEINSIGHTS_BASE_URL(alias forVI_SERVER_URL)
Getting an Auth Token
- Visit agentlogs.ai
- Sign in with GitHub
- Go to Settings → API Tokens
- Generate a new token
How It Works
Transcript Capture
The plugin listens to OpenCode events and maintains a record of the current session:
session.created: Initializes tracking for a new sessionmessage.updated: Collects messages as they're added/updatedsession.idle: Uploads the complete transcript when the session becomes idle
Git Commit Enhancement
When you make a git commit during a session, the plugin:
- Intercepts the
tool.execute.beforeevent for shell commands - Detects git commit commands
- Uploads the current transcript (if not already uploaded)
- Appends a transcript link to the commit message
Example enhanced commit:
feat: add user authentication
Transcript: https://agentlogs.ai/app/logs/abc123Plugin Events
The plugin responds to these OpenCode events:
| Event | Action |
| ----------------- | -------------------------- |
| session.created | Start tracking new session |
| session.updated | Update session metadata |
| message.updated | Collect message content |
| session.idle | Upload transcript |
| session.deleted | Clear session state |
API
Exports
import {
agentLogsPlugin, // Main plugin function
extractGitContext, // Extract git repo/branch info
isGitCommitCommand, // Check if command is git commit
uploadOpenCodeTranscript, // Manual transcript upload
buildTranscriptUrl, // Build transcript URL from ID
} from "@agentlogs/opencode";Manual Upload
You can also upload transcripts programmatically:
import { uploadOpenCodeTranscript } from "@agentlogs/opencode";
const result = await uploadOpenCodeTranscript({
session: { id: "...", createdAt: "...", ... },
messages: [...],
gitContext: { repo: "...", branch: "...", relativeCwd: "..." },
cwd: "/path/to/project",
});
if (result.success) {
console.log(`Transcript: ${result.transcriptUrl}`);
}Troubleshooting
Transcript not uploading
- Check that
VI_AUTH_TOKENis set correctly - Verify network connectivity to agentlogs.ai
- Check plugin logs for errors (look for
[agentlogs]prefix)
Commit message not enhanced
- Ensure a transcript was uploaded successfully first
- Check that the commit command uses
-mflag - Verify the plugin is loaded (check OpenCode startup logs)
Development
Local Setup
# Clone the repo
git clone https://github.com/agentlogs/agentlogs.git
cd agentlogs
# Install dependencies
bun install
# Link the plugin locally
cd packages/opencode
bun linkTesting
# Run type checking
bun run check
# Build
bun run buildLicense
MIT
