@tylerl0706/ahpx 0.2.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/LICENSE +21 -0
- package/README.md +309 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +3090 -0
- package/dist/chunk-B6RV43UP.js +2384 -0
- package/dist/index.d.ts +3397 -0
- package/dist/index.js +229 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Tyler Leonhardt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# ahpx
|
|
2
|
+
|
|
3
|
+
**Agent Host Protocol client** — CLI and Node.js library for managing AHP server connections, sessions, and agent interactions.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/TylerLeonhardt/ahpx/actions/workflows/ci.yml)
|
|
6
|
+
[](https://www.npmjs.com/package/@tylerl0706/ahpx)
|
|
7
|
+
|
|
8
|
+
## What is ahpx?
|
|
9
|
+
|
|
10
|
+
ahpx is a client for the [Agent Host Protocol](https://github.com/anthropics/agent-host-protocol) (AHP) — a WebSocket-based JSON-RPC protocol for managing AI agent sessions. Use ahpx to connect to AHP servers, create sessions, send prompts, stream responses, and handle tool confirmations, either from the command line or programmatically as a Node.js library.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🔌 **Connect to AHP servers** via WebSocket with saved connection profiles
|
|
15
|
+
- 💬 **Interactive and one-shot prompting** with streaming output
|
|
16
|
+
- 📡 **Multi-session management** — concurrent sessions on a single connection
|
|
17
|
+
- 🔄 **Event forwarding** — webhook and WebSocket targets for dashboards and pipelines
|
|
18
|
+
- 🏗️ **Fleet management** — health checks, status monitoring, and server tagging
|
|
19
|
+
- 💾 **Session persistence** — resume sessions, export/import history
|
|
20
|
+
- 📦 **Use as CLI or Node.js library** with full TypeScript types
|
|
21
|
+
- 🔒 **Configurable permission modes** — approve-all, approve-reads, deny-all
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g @tylerl0706/ahpx
|
|
27
|
+
|
|
28
|
+
# Add a server
|
|
29
|
+
ahpx server add local --url ws://localhost:8082 --default
|
|
30
|
+
|
|
31
|
+
# Start prompting
|
|
32
|
+
ahpx "what files are in this directory?"
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or use `exec` for one-shot tasks that create and dispose of a session automatically:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
ahpx exec "summarize this repo"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## CLI Commands
|
|
42
|
+
|
|
43
|
+
### Prompting
|
|
44
|
+
|
|
45
|
+
| Command | Description |
|
|
46
|
+
|---------|-------------|
|
|
47
|
+
| `ahpx <text>` | Send a prompt (implicit — any text that isn't a command) |
|
|
48
|
+
| `ahpx prompt <text>` | Send a prompt to an existing session |
|
|
49
|
+
| `ahpx exec <text>` | One-shot: create a temp session, prompt, dispose |
|
|
50
|
+
| `ahpx cancel` | Cancel the active turn in a session |
|
|
51
|
+
|
|
52
|
+
Prompt options: `-s <server>`, `-n <session-name>`, `-f <file>`, `--cwd <dir>`, `--approve-all`, `--approve-reads`, `--deny-all`, `--idle-timeout <seconds>`, `--tag <key=value>`, `--forward-webhook <url>`, `--forward-ws <url>`, `--forward-filter <types>`, `--forward-headers <json>`
|
|
53
|
+
|
|
54
|
+
`exec` also accepts: `-p <provider>`, `-m <model>`
|
|
55
|
+
|
|
56
|
+
### Server Management
|
|
57
|
+
|
|
58
|
+
| Command | Description |
|
|
59
|
+
|---------|-------------|
|
|
60
|
+
| `ahpx server add <name> --url <url>` | Save a named connection profile |
|
|
61
|
+
| `ahpx server list` | List saved connections |
|
|
62
|
+
| `ahpx server remove <name>` | Remove a saved connection |
|
|
63
|
+
| `ahpx server test <target>` | Test connectivity to a server |
|
|
64
|
+
| `ahpx server status` | Health check all saved servers |
|
|
65
|
+
| `ahpx server health <name>` | Detailed health check for a single server |
|
|
66
|
+
|
|
67
|
+
`server add` options: `--token <token>`, `--default`, `--tag <tag>` (repeatable)
|
|
68
|
+
|
|
69
|
+
### Session Management
|
|
70
|
+
|
|
71
|
+
| Command | Description |
|
|
72
|
+
|---------|-------------|
|
|
73
|
+
| `ahpx session new` | Create a new agent session |
|
|
74
|
+
| `ahpx session list` | List sessions (default: active only) |
|
|
75
|
+
| `ahpx session show [id]` | Show session details |
|
|
76
|
+
| `ahpx session close [id]` | Close a session (keeps record for history) |
|
|
77
|
+
| `ahpx session history [id]` | Show turn history for a session |
|
|
78
|
+
| `ahpx session active` | Show all active sessions on the server (live query) |
|
|
79
|
+
| `ahpx session export <id>` | Export a session record to JSON |
|
|
80
|
+
| `ahpx session import <file>` | Import a session record from JSON |
|
|
81
|
+
|
|
82
|
+
`session new` options: `-s <server>`, `-p <provider>`, `-m <model>`, `-n <name>`, `--cwd <dir>`, `-t <timeout>`
|
|
83
|
+
|
|
84
|
+
### Configuration
|
|
85
|
+
|
|
86
|
+
| Command | Description |
|
|
87
|
+
|---------|-------------|
|
|
88
|
+
| `ahpx config show` | Print resolved config with source annotations |
|
|
89
|
+
| `ahpx config init` | Create `~/.ahpx/config.json` with defaults |
|
|
90
|
+
|
|
91
|
+
### Utilities
|
|
92
|
+
|
|
93
|
+
| Command | Description |
|
|
94
|
+
|---------|-------------|
|
|
95
|
+
| `ahpx connect [target]` | Connect to a server and print server info |
|
|
96
|
+
| `ahpx agents` | List available agents and models on the server |
|
|
97
|
+
| `ahpx content <uri>` | Fetch content by URI from the server |
|
|
98
|
+
| `ahpx model <model-id>` | Switch the model for a session |
|
|
99
|
+
| `ahpx watch [id]` | Attach to a session as an observer and stream activity |
|
|
100
|
+
| `ahpx browse [directory]` | Browse server filesystem |
|
|
101
|
+
| `ahpx completions bash\|zsh\|fish` | Generate shell completion scripts |
|
|
102
|
+
|
|
103
|
+
### Global Options
|
|
104
|
+
|
|
105
|
+
| Flag | Description |
|
|
106
|
+
|------|-------------|
|
|
107
|
+
| `--format <format>` | Output format: `text`, `json`, or `quiet` (default: `text`) |
|
|
108
|
+
| `--json-strict` | Suppress non-JSON stderr output (use with `--format json`) |
|
|
109
|
+
| `-v, --verbose` | Enable debug logging to stderr |
|
|
110
|
+
| `--version` | Print version |
|
|
111
|
+
| `--help` | Show help |
|
|
112
|
+
|
|
113
|
+
## Library Usage
|
|
114
|
+
|
|
115
|
+
ahpx exports a full TypeScript API. Install it as a dependency:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
npm install @tylerl0706/ahpx
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Connect and list agents
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { AhpClient } from '@tylerl0706/ahpx';
|
|
125
|
+
|
|
126
|
+
const client = new AhpClient({ initialSubscriptions: ['agenthost:/root'] });
|
|
127
|
+
const result = await client.connect('ws://localhost:8082');
|
|
128
|
+
|
|
129
|
+
console.log('Agents:', result.agents);
|
|
130
|
+
console.log('Connected:', client.connected);
|
|
131
|
+
|
|
132
|
+
await client.disconnect();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Create a session and send a prompt
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { AhpClient, ActionType } from '@tylerl0706/ahpx';
|
|
139
|
+
import { randomUUID } from 'node:crypto';
|
|
140
|
+
|
|
141
|
+
const client = new AhpClient({ initialSubscriptions: ['agenthost:/root'] });
|
|
142
|
+
await client.connect('ws://localhost:8082');
|
|
143
|
+
|
|
144
|
+
// Create a session
|
|
145
|
+
const sessionUri = `copilot:/${randomUUID()}`;
|
|
146
|
+
await client.createSession(sessionUri, { provider: 'copilot' });
|
|
147
|
+
await client.subscribe(sessionUri);
|
|
148
|
+
|
|
149
|
+
// Listen for streaming events
|
|
150
|
+
client.on('action', (envelope) => {
|
|
151
|
+
const { action } = envelope;
|
|
152
|
+
switch (action.type) {
|
|
153
|
+
case ActionType.SessionDelta:
|
|
154
|
+
process.stdout.write(action.content);
|
|
155
|
+
break;
|
|
156
|
+
case ActionType.SessionTurnComplete:
|
|
157
|
+
console.log('\n--- Turn complete ---');
|
|
158
|
+
break;
|
|
159
|
+
case ActionType.SessionError:
|
|
160
|
+
console.error('Error:', action.error);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Send a prompt
|
|
166
|
+
client.dispatchAction({
|
|
167
|
+
type: ActionType.SessionTurnStarted,
|
|
168
|
+
session: sessionUri,
|
|
169
|
+
turnId: randomUUID(),
|
|
170
|
+
userMessage: { text: 'Fix the failing test' },
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Handle authentication
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { AhpClient, AuthHandler } from '@tylerl0706/ahpx';
|
|
178
|
+
|
|
179
|
+
const client = new AhpClient();
|
|
180
|
+
const auth = new AuthHandler(client, { token: process.env.MY_TOKEN });
|
|
181
|
+
|
|
182
|
+
client.on('notification', async (notification) => {
|
|
183
|
+
if (notification.type === 'authRequired') {
|
|
184
|
+
await auth.handleAuthRequired(notification.resource);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
await client.connect('ws://localhost:8082');
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Read state from the state mirror
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
const client = new AhpClient();
|
|
195
|
+
await client.connect('ws://localhost:8082');
|
|
196
|
+
|
|
197
|
+
// Root state (agents, active sessions)
|
|
198
|
+
console.log('Agents:', client.state.root.agents);
|
|
199
|
+
|
|
200
|
+
// Session state (after subscribing)
|
|
201
|
+
const session = client.state.getSession('copilot:/my-session');
|
|
202
|
+
console.log('Title:', session?.summary?.title);
|
|
203
|
+
console.log('Active turn:', session?.activeTurn);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Error handling
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { AhpClient, RpcError, RpcTimeoutError } from '@tylerl0706/ahpx';
|
|
210
|
+
|
|
211
|
+
const client = new AhpClient();
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
await client.connect('ws://localhost:8082');
|
|
215
|
+
} catch (err) {
|
|
216
|
+
if (err instanceof RpcTimeoutError) {
|
|
217
|
+
console.error(`Request ${err.method} timed out after ${err.timeoutMs}ms`);
|
|
218
|
+
} else if (err instanceof RpcError) {
|
|
219
|
+
console.error(`RPC error ${err.code}: ${err.message}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Additional APIs
|
|
225
|
+
|
|
226
|
+
- **`SessionHandle`** — per-session wrapper with scoped event listeners and lifecycle management
|
|
227
|
+
- **`ConnectionPool`** — connection reuse across multiple sessions to the same server
|
|
228
|
+
- **`WebhookForwarder` / `WebSocketForwarder`** — forward NDJSON events to external targets
|
|
229
|
+
- **`HealthChecker`** — fleet-level health monitoring across saved servers
|
|
230
|
+
|
|
231
|
+
See the exported TypeScript declarations for the full API reference.
|
|
232
|
+
|
|
233
|
+
## Exit Codes
|
|
234
|
+
|
|
235
|
+
ahpx uses semantic exit codes so scripts and automation can react to failures:
|
|
236
|
+
|
|
237
|
+
| Code | Meaning | Description |
|
|
238
|
+
|------|---------|-------------|
|
|
239
|
+
| `0` | Success | Command completed successfully |
|
|
240
|
+
| `1` | Runtime error | Unexpected error during execution |
|
|
241
|
+
| `2` | Usage error | Bad CLI arguments or missing required flags |
|
|
242
|
+
| `3` | Timeout | Connection or request timed out |
|
|
243
|
+
| `4` | No session | Session not found — run `session new` first |
|
|
244
|
+
| `5` | Permission denied | All permission requests were denied |
|
|
245
|
+
| `130` | Interrupted | Process was interrupted (Ctrl+C) |
|
|
246
|
+
|
|
247
|
+
See [docs/errors.md](docs/errors.md) for the full error reference.
|
|
248
|
+
|
|
249
|
+
## Configuration
|
|
250
|
+
|
|
251
|
+
ahpx uses a layered configuration system. Settings are resolved in order of precedence:
|
|
252
|
+
|
|
253
|
+
1. **CLI flags** — highest priority (e.g. `--format json`)
|
|
254
|
+
2. **Project config** — `.ahpxrc.json` in the current directory or git root
|
|
255
|
+
3. **Global config** — `~/.ahpx/config.json`
|
|
256
|
+
4. **Defaults** — built-in fallback values
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
# Initialize global config
|
|
260
|
+
ahpx config init
|
|
261
|
+
|
|
262
|
+
# View resolved config with source annotations
|
|
263
|
+
ahpx config show
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Documentation
|
|
267
|
+
|
|
268
|
+
| Document | Description |
|
|
269
|
+
|----------|-------------|
|
|
270
|
+
| [PUBLISHING.md](PUBLISHING.md) | Publishing setup — OIDC trusted publishers, provenance, first-time config |
|
|
271
|
+
| [docs/quick-reference.md](docs/quick-reference.md) | One-page command cheat sheet |
|
|
272
|
+
| [docs/user-guide.md](docs/user-guide.md) | Comprehensive user guide — CLI reference, SDK API, architecture |
|
|
273
|
+
| [docs/roadmap.md](docs/roadmap.md) | v0.2 roadmap with phase details and acceptance criteria |
|
|
274
|
+
| [docs/errors.md](docs/errors.md) | Error catalog and exit code reference |
|
|
275
|
+
| [docs/george-integration.md](docs/george-integration.md) | Integration guide for George agent dispatch |
|
|
276
|
+
| [docs/protocol-feedback.md](docs/protocol-feedback.md) | AHP protocol gap analysis and workarounds |
|
|
277
|
+
|
|
278
|
+
## Development
|
|
279
|
+
|
|
280
|
+
Requires Node.js ≥ 20.
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
npm install # Install dependencies
|
|
284
|
+
npm run build # Build with tsup
|
|
285
|
+
npm run dev # Watch mode
|
|
286
|
+
npm run typecheck # Type check with tsc
|
|
287
|
+
npm run lint # Lint with Biome
|
|
288
|
+
npm test # Run tests with Vitest
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
All four quality gates must pass before committing:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
npm run typecheck && npm run lint && npm test && npm run build
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
## Contributing
|
|
298
|
+
|
|
299
|
+
Project knowledge lives in `.github/` so both humans and agents can find it:
|
|
300
|
+
|
|
301
|
+
- **[`.github/skills/ahp-protocol/`](.github/skills/ahp-protocol/SKILL.md)** — AHP protocol fundamentals
|
|
302
|
+
- **[`.github/skills/ahpx-architecture/`](.github/skills/ahpx-architecture/SKILL.md)** — Codebase architecture and design
|
|
303
|
+
- **[`.github/agents/team-lead.md`](.github/agents/team-lead.md)** — Team lead agent with quality gates and workflow
|
|
304
|
+
|
|
305
|
+
Read the relevant skill docs before making changes — they'll save you time.
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT
|
package/dist/bin.d.ts
ADDED