@contextgraph/agent 0.4.0
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/.claude/settings.local.json +32 -0
- package/CHANGELOG.md +32 -0
- package/README.md +258 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1793 -0
- package/dist/index.js.map +1 -0
- package/examples/completion-extraction.ts +243 -0
- package/package.json +47 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(git add:*)",
|
|
5
|
+
"Bash(git commit:*)",
|
|
6
|
+
"Bash(git push:*)",
|
|
7
|
+
"mcp__plugin_contextgraph_actions__create",
|
|
8
|
+
"mcp__plugin_contextgraph_actions__fetch_tree",
|
|
9
|
+
"Bash(git checkout:*)",
|
|
10
|
+
"Bash(git pull:*)",
|
|
11
|
+
"Bash(git cherry-pick:*)",
|
|
12
|
+
"mcp__plugin_contextgraph_actions__fetch",
|
|
13
|
+
"mcp__plugin_contextgraph_actions__update",
|
|
14
|
+
"mcp__plugin_contextgraph_actions__move",
|
|
15
|
+
"mcp__plugin_contextgraph_actions__complete",
|
|
16
|
+
"Bash(npm test:*)",
|
|
17
|
+
"mcp__axiom__listDatasets",
|
|
18
|
+
"mcp__axiom__queryDataset",
|
|
19
|
+
"mcp__axiom__getDatasetFields",
|
|
20
|
+
"Bash(curl:*)",
|
|
21
|
+
"mcp__plugin_contextgraph_actions__report_completed_work",
|
|
22
|
+
"Bash(npm run build:*)",
|
|
23
|
+
"mcp__plugin_contextgraph_actions__search",
|
|
24
|
+
"Bash(npm publish:*)",
|
|
25
|
+
"Bash(cat:*)",
|
|
26
|
+
"WebSearch",
|
|
27
|
+
"Bash(claude:*)"
|
|
28
|
+
],
|
|
29
|
+
"deny": [],
|
|
30
|
+
"ask": []
|
|
31
|
+
}
|
|
32
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.1.1] - 2025-11-16
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- Fixed 400 error on iteration 2 by using local findNextLeaf instead of nonexistent API endpoint
|
|
9
|
+
- Fixed auth command hanging after successful authentication by properly awaiting server close
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- Updated README to prioritize npx usage over global installation
|
|
13
|
+
- Removed unused ApiClient.findNextLeaf() method
|
|
14
|
+
- Simplified agent workflow to use local tree traversal
|
|
15
|
+
|
|
16
|
+
## [0.1.0] - 2025-11-15
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
- Initial release of @context-graph/agent
|
|
20
|
+
- OAuth authentication with contextgraph.dev
|
|
21
|
+
- CLI commands: auth, whoami, run, prepare, execute
|
|
22
|
+
- Autonomous agent loop with tree traversal
|
|
23
|
+
- Dependency-aware action execution
|
|
24
|
+
- Claude CLI integration for agent execution
|
|
25
|
+
- MCP server integration
|
|
26
|
+
- Secure credential storage in ~/.contextgraph/
|
|
27
|
+
|
|
28
|
+
### Technical Details
|
|
29
|
+
- ESM-only package for Node.js 18+
|
|
30
|
+
- Built with TypeScript and tsup
|
|
31
|
+
- Commander framework for CLI
|
|
32
|
+
- Extracted from actionbias repository
|
package/README.md
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# @context-graph/agent
|
|
2
|
+
|
|
3
|
+
Autonomous agent for contextgraph action execution.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
No installation required! Use npx to run commands directly:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @context-graph/agent <command>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or install globally for convenience:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install -g @context-graph/agent
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Prerequisites
|
|
20
|
+
|
|
21
|
+
- Node.js 18 or higher
|
|
22
|
+
- Active contextgraph.dev account
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Option 1: Interactive Authentication
|
|
27
|
+
|
|
28
|
+
1. Authenticate with contextgraph.dev:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @context-graph/agent auth
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Run the agent:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx @context-graph/agent run
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Option 2: API Token (CI/CD & Cloud Deployments)
|
|
41
|
+
|
|
42
|
+
For automated environments, use an API token:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
export CONTEXTGRAPH_API_TOKEN="your-api-token"
|
|
46
|
+
npx @context-graph/agent run
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Get your API token from https://contextgraph.dev/settings/tokens
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
### `auth`
|
|
54
|
+
Authenticate with contextgraph.dev using OAuth:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npx @context-graph/agent auth
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Opens your browser to complete authentication. Credentials are securely stored in `~/.contextgraph/`.
|
|
61
|
+
|
|
62
|
+
### `whoami`
|
|
63
|
+
Check your current authentication status:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx @context-graph/agent whoami
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Shows your user ID and token expiration.
|
|
70
|
+
|
|
71
|
+
### `run <action-id>`
|
|
72
|
+
Run the autonomous agent loop:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx @context-graph/agent run <action-id>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The agent will:
|
|
79
|
+
1. Fetch the action tree
|
|
80
|
+
2. Find the next unprepared/incomplete leaf action
|
|
81
|
+
3. Prepare it (if needed) - assess if it should be broken down
|
|
82
|
+
4. Execute it - implement the work using Claude
|
|
83
|
+
5. Repeat until all actions are complete
|
|
84
|
+
|
|
85
|
+
### `prepare <action-id>`
|
|
86
|
+
Prepare a single action:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
npx @context-graph/agent prepare <action-id>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Spawns Claude to assess whether the action should be broken down into child actions or is ready to execute.
|
|
93
|
+
|
|
94
|
+
### `execute <action-id>`
|
|
95
|
+
Execute a single prepared action:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
npx @context-graph/agent execute <action-id>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Spawns Claude to implement the action and mark it complete.
|
|
102
|
+
|
|
103
|
+
## How It Works
|
|
104
|
+
|
|
105
|
+
The agent implements a prepare/execute workflow:
|
|
106
|
+
|
|
107
|
+
**Prepare Phase:**
|
|
108
|
+
- Fetches action details including parent chain, siblings, and dependencies
|
|
109
|
+
- Analyzes whether the action is atomic or should be broken down
|
|
110
|
+
- If complex, creates child actions with proper dependencies
|
|
111
|
+
- Marks the action as prepared
|
|
112
|
+
|
|
113
|
+
**Execute Phase:**
|
|
114
|
+
- Implements the work described in the action
|
|
115
|
+
- Runs tests and builds to verify changes
|
|
116
|
+
- Commits and pushes changes to the appropriate branch
|
|
117
|
+
- Marks the action as complete with detailed completion context
|
|
118
|
+
|
|
119
|
+
**Autonomous Loop:**
|
|
120
|
+
- The `run` command traverses the action tree depth-first
|
|
121
|
+
- Automatically prepares and executes actions in dependency order
|
|
122
|
+
- Continues until all actions in the tree are complete
|
|
123
|
+
|
|
124
|
+
The agent integrates with contextgraph.dev's MCP server to:
|
|
125
|
+
- Fetch action details and relationships
|
|
126
|
+
- Create and update actions
|
|
127
|
+
- Track completion context and learnings
|
|
128
|
+
|
|
129
|
+
## Troubleshooting
|
|
130
|
+
|
|
131
|
+
### Authentication failures
|
|
132
|
+
|
|
133
|
+
If authentication fails or tokens expire:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx @context-graph/agent auth
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
This will open a new browser session to re-authenticate.
|
|
140
|
+
|
|
141
|
+
### Expired credentials
|
|
142
|
+
|
|
143
|
+
Tokens expire after a period of time. Re-authenticate with:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npx @context-graph/agent whoami # Check expiration
|
|
147
|
+
npx @context-graph/agent auth # Re-authenticate if expired
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Network errors
|
|
151
|
+
|
|
152
|
+
Ensure you have internet connectivity and can reach:
|
|
153
|
+
- https://www.contextgraph.dev (API endpoint)
|
|
154
|
+
- https://contextgraph.dev (authentication)
|
|
155
|
+
|
|
156
|
+
## Links
|
|
157
|
+
|
|
158
|
+
- [contextgraph.dev](https://contextgraph.dev) - Main platform
|
|
159
|
+
- [GitHub Repository](https://github.com/context-graph/agent) - Source code and issues
|
|
160
|
+
- [Issue Tracker](https://github.com/context-graph/agent/issues) - Report bugs or request features
|
|
161
|
+
|
|
162
|
+
## Configuration
|
|
163
|
+
|
|
164
|
+
### Credentials
|
|
165
|
+
|
|
166
|
+
The agent supports two authentication methods:
|
|
167
|
+
|
|
168
|
+
**1. Interactive OAuth (Default)**
|
|
169
|
+
|
|
170
|
+
Credentials are stored in `~/.contextgraph/credentials.json` after running `contextgraph-agent auth`.
|
|
171
|
+
|
|
172
|
+
**2. API Token (Environment Variable)**
|
|
173
|
+
|
|
174
|
+
Set the `CONTEXTGRAPH_API_TOKEN` environment variable for automated deployments:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
export CONTEXTGRAPH_API_TOKEN="your-api-token"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This is ideal for:
|
|
181
|
+
- CI/CD pipelines (GitHub Actions, GitLab CI, etc.)
|
|
182
|
+
- Cloud worker deployments (AWS Lambda, Modal, etc.)
|
|
183
|
+
- Docker containers
|
|
184
|
+
- Any automated environment where interactive login isn't possible
|
|
185
|
+
|
|
186
|
+
API tokens take precedence over file-based credentials when both are present.
|
|
187
|
+
|
|
188
|
+
### Worker Polling
|
|
189
|
+
|
|
190
|
+
The worker uses exponential backoff when no work is available to prevent server overload. Configure polling behavior with environment variables:
|
|
191
|
+
|
|
192
|
+
- `WORKER_INITIAL_POLL_INTERVAL` - Initial polling interval in milliseconds (default: 2000 / 2 seconds)
|
|
193
|
+
- `WORKER_MAX_POLL_INTERVAL` - Maximum polling interval in milliseconds (default: 30000 / 30 seconds)
|
|
194
|
+
|
|
195
|
+
When no work is available, the worker waits before polling again. The wait time increases exponentially (1.5x multiplier) up to the maximum interval. On successful claim, the interval resets to the initial value.
|
|
196
|
+
|
|
197
|
+
Example:
|
|
198
|
+
```bash
|
|
199
|
+
# Poll more frequently (every 1 second initially, up to 15 seconds max)
|
|
200
|
+
WORKER_INITIAL_POLL_INTERVAL=1000 WORKER_MAX_POLL_INTERVAL=15000 npx @context-graph/agent run <action-id>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Claude Agent SDK
|
|
204
|
+
|
|
205
|
+
The agent uses the [Claude Agent SDK](https://github.com/anthropics/anthropic-sdk-typescript/tree/main/packages/agent-sdk) for reliable, high-performance execution of actions. The SDK provides:
|
|
206
|
+
- Consistent error handling and recovery
|
|
207
|
+
- Direct API integration without CLI dependencies
|
|
208
|
+
- Better timeout and cancellation control
|
|
209
|
+
- Structured message parsing and formatting
|
|
210
|
+
|
|
211
|
+
#### SDK Authentication
|
|
212
|
+
|
|
213
|
+
The Claude Agent SDK requires Anthropic API credentials. Set the `ANTHROPIC_API_KEY` environment variable:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
export ANTHROPIC_API_KEY="your-anthropic-api-key"
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
This is required for:
|
|
220
|
+
- Worker agent execution
|
|
221
|
+
- Autonomous action processing
|
|
222
|
+
- Any command that spawns Claude for prepare/execute operations
|
|
223
|
+
|
|
224
|
+
**Generating Long-Lived Anthropic Tokens:**
|
|
225
|
+
|
|
226
|
+
For CI/CD pipelines, cloud deployments, and unattended worker execution, you'll need a long-lived Anthropic API key:
|
|
227
|
+
|
|
228
|
+
1. Visit the [Anthropic Console API Keys page](https://console.anthropic.com/settings/keys)
|
|
229
|
+
2. Click "Create Key" to generate a new API key
|
|
230
|
+
3. Give it a descriptive name (e.g., "Production Worker" or "CI/CD Pipeline")
|
|
231
|
+
4. Copy the key immediately - it won't be shown again
|
|
232
|
+
5. Store it securely in your environment or secrets manager
|
|
233
|
+
|
|
234
|
+
**Security Best Practices:**
|
|
235
|
+
- Never commit API keys to version control
|
|
236
|
+
- Use environment variables or secrets management systems (AWS Secrets Manager, GitHub Secrets, etc.)
|
|
237
|
+
- Rotate keys periodically
|
|
238
|
+
- Use separate keys for different environments (development, staging, production)
|
|
239
|
+
- Revoke compromised keys immediately from the Anthropic Console
|
|
240
|
+
|
|
241
|
+
For local development, you can set the key in your shell profile (`~/.bashrc`, `~/.zshrc`) or use a `.env` file (with proper `.gitignore` configuration).
|
|
242
|
+
|
|
243
|
+
## Development
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Install dependencies
|
|
247
|
+
pnpm install
|
|
248
|
+
|
|
249
|
+
# Build
|
|
250
|
+
pnpm build
|
|
251
|
+
|
|
252
|
+
# Development mode
|
|
253
|
+
pnpm dev
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
MIT
|
package/dist/index.d.ts
ADDED