@agentlogs/opencode 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,177 @@
1
+ # @agentlogs/opencode
2
+
3
+ OpenCode plugin for [AgentLogs](https://agentlogs.ai) - automatically capture and upload AI coding session transcripts.
4
+
5
+ ## Features
6
+
7
+ - **Automatic transcript capture**: Uploads session transcripts when OpenCode becomes idle
8
+ - **Git commit enhancement**: Automatically adds transcript links to git commit messages
9
+ - **Token & cost tracking**: Calculates and tracks token usage and costs
10
+ - **Git context preservation**: Captures repository, branch, and working directory context
11
+
12
+ ## Installation
13
+
14
+ ### From npm
15
+
16
+ ```bash
17
+ npm install -g @agentlogs/opencode
18
+ # or
19
+ bun add -g @agentlogs/opencode
20
+ ```
21
+
22
+ ### Configure OpenCode
23
+
24
+ Add the plugin to your `opencode.json` config file:
25
+
26
+ ```json
27
+ {
28
+ "$schema": "https://opencode.ai/config.json",
29
+ "plugin": ["@agentlogs/opencode"]
30
+ }
31
+ ```
32
+
33
+ Or for local development:
34
+
35
+ ```json
36
+ {
37
+ "plugin": [".opencode/plugin/agentlogs.ts"]
38
+ }
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ ### Environment Variables
44
+
45
+ | Variable | Required | Description |
46
+ | --------------- | -------- | -------------------------------------------- |
47
+ | `VI_AUTH_TOKEN` | Yes | Your AgentLogs authentication token |
48
+ | `VI_SERVER_URL` | No | Server URL (default: `https://agentlogs.ai`) |
49
+
50
+ Alternative variable names are also supported:
51
+
52
+ - `VIBEINSIGHTS_AUTH_TOKEN` (alias for `VI_AUTH_TOKEN`)
53
+ - `VIBEINSIGHTS_BASE_URL` (alias for `VI_SERVER_URL`)
54
+
55
+ ### Getting an Auth Token
56
+
57
+ 1. Visit [agentlogs.ai](https://agentlogs.ai)
58
+ 2. Sign in with GitHub
59
+ 3. Go to Settings → API Tokens
60
+ 4. Generate a new token
61
+
62
+ ## How It Works
63
+
64
+ ### Transcript Capture
65
+
66
+ The plugin listens to OpenCode events and maintains a record of the current session:
67
+
68
+ 1. **`session.created`**: Initializes tracking for a new session
69
+ 2. **`message.updated`**: Collects messages as they're added/updated
70
+ 3. **`session.idle`**: Uploads the complete transcript when the session becomes idle
71
+
72
+ ### Git Commit Enhancement
73
+
74
+ When you make a git commit during a session, the plugin:
75
+
76
+ 1. Intercepts the `tool.execute.before` event for shell commands
77
+ 2. Detects git commit commands
78
+ 3. Uploads the current transcript (if not already uploaded)
79
+ 4. Appends a transcript link to the commit message
80
+
81
+ Example enhanced commit:
82
+
83
+ ```
84
+ feat: add user authentication
85
+
86
+ Transcript: https://agentlogs.ai/app/logs/abc123
87
+ ```
88
+
89
+ ## Plugin Events
90
+
91
+ The plugin responds to these OpenCode events:
92
+
93
+ | Event | Action |
94
+ | ----------------- | -------------------------- |
95
+ | `session.created` | Start tracking new session |
96
+ | `session.updated` | Update session metadata |
97
+ | `message.updated` | Collect message content |
98
+ | `session.idle` | Upload transcript |
99
+ | `session.deleted` | Clear session state |
100
+
101
+ ## API
102
+
103
+ ### Exports
104
+
105
+ ```typescript
106
+ import {
107
+ agentLogsPlugin, // Main plugin function
108
+ extractGitContext, // Extract git repo/branch info
109
+ isGitCommitCommand, // Check if command is git commit
110
+ uploadOpenCodeTranscript, // Manual transcript upload
111
+ buildTranscriptUrl, // Build transcript URL from ID
112
+ } from "@agentlogs/opencode";
113
+ ```
114
+
115
+ ### Manual Upload
116
+
117
+ You can also upload transcripts programmatically:
118
+
119
+ ```typescript
120
+ import { uploadOpenCodeTranscript } from "@agentlogs/opencode";
121
+
122
+ const result = await uploadOpenCodeTranscript({
123
+ session: { id: "...", createdAt: "...", ... },
124
+ messages: [...],
125
+ gitContext: { repo: "...", branch: "...", relativeCwd: "..." },
126
+ cwd: "/path/to/project",
127
+ });
128
+
129
+ if (result.success) {
130
+ console.log(`Transcript: ${result.transcriptUrl}`);
131
+ }
132
+ ```
133
+
134
+ ## Troubleshooting
135
+
136
+ ### Transcript not uploading
137
+
138
+ 1. Check that `VI_AUTH_TOKEN` is set correctly
139
+ 2. Verify network connectivity to agentlogs.ai
140
+ 3. Check plugin logs for errors (look for `[agentlogs]` prefix)
141
+
142
+ ### Commit message not enhanced
143
+
144
+ 1. Ensure a transcript was uploaded successfully first
145
+ 2. Check that the commit command uses `-m` flag
146
+ 3. Verify the plugin is loaded (check OpenCode startup logs)
147
+
148
+ ## Development
149
+
150
+ ### Local Setup
151
+
152
+ ```bash
153
+ # Clone the repo
154
+ git clone https://github.com/agentlogs/agentlogs.git
155
+ cd agentlogs
156
+
157
+ # Install dependencies
158
+ bun install
159
+
160
+ # Link the plugin locally
161
+ cd packages/opencode
162
+ bun link
163
+ ```
164
+
165
+ ### Testing
166
+
167
+ ```bash
168
+ # Run type checking
169
+ bun run check
170
+
171
+ # Build
172
+ bun run build
173
+ ```
174
+
175
+ ## License
176
+
177
+ MIT