agentp 0.1.1 → 0.1.2
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/.ocmux.json +1 -0
- package/AGENTS.md +38 -0
- package/README.md +13 -2
- package/bin/agentp +15 -13
- package/package.json +1 -1
package/.ocmux.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"url":"http://127.0.0.1:4096","logfile":"/tmp/opencode-serve-6cdb98e4626e.log","window_index":1}
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# agentp — agent notes
|
|
2
|
+
|
|
3
|
+
## What it is
|
|
4
|
+
|
|
5
|
+
Single-file Node.js CLI (`bin/agentp`) that pipes stdin into a running OpenCode TUI session and streams the assistant answer to stdout. Zero npm dependencies, CommonJS, no build step.
|
|
6
|
+
|
|
7
|
+
## Entrypoint
|
|
8
|
+
|
|
9
|
+
`bin/agentp` — the only source file. No other modules.
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
| Action | Command |
|
|
14
|
+
|---|---|
|
|
15
|
+
| Dev install | `npm link` or `npm install -g .` |
|
|
16
|
+
| Run | `printf "prompt" \| agentp` |
|
|
17
|
+
|
|
18
|
+
No tests, no lint, no typecheck, no codegen. `npm test` is a noop placeholder.
|
|
19
|
+
|
|
20
|
+
## Requirements
|
|
21
|
+
|
|
22
|
+
- Node.js 18+
|
|
23
|
+
- `opencode --serve` running locally (default port `4096`). See `.ocmux.json` for the local server URL/log path.
|
|
24
|
+
- `opencode --attach` optional but useful to monitor conversations.
|
|
25
|
+
|
|
26
|
+
## Architecture
|
|
27
|
+
|
|
28
|
+
- Communicates with OpenCode via HTTP: `/tui/clear-prompt`, `/tui/append-prompt`, `/tui/submit-prompt`, `/event` (SSE).
|
|
29
|
+
- Default server `http://localhost:4096`; override as positional arg with a port number (`agentp 4097`) or full URL (`agentp http://host:4096`)
|
|
30
|
+
- `--qa` flag prints human/agent separator rows before streaming output.
|
|
31
|
+
- Streams assistant `text` parts from SSE, filters out user echo by tracking `message.updated` events with role `user`.
|
|
32
|
+
- Stops on `session.idle` event.
|
|
33
|
+
|
|
34
|
+
## Gotchas
|
|
35
|
+
|
|
36
|
+
- Stdin is consumed line-byline via `readline`. Each line is sent as a separate `append-prompt` request (no batching).
|
|
37
|
+
- The script does NOT handle OpenCode not being running — it will crash with a connection error.
|
|
38
|
+
- No test suite exists; manual testing via `printf "hi" | node bin/agentp`.
|
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# agentp
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/agentp)
|
|
4
|
+
[](https://www.npmjs.com/package/agentp)
|
|
5
|
+
[](https://www.npmjs.com/package/agentp)
|
|
6
|
+
[](https://www.npmjs.com/package/agentp)
|
|
7
|
+
|
|
3
8
|
`agentp` is a tiny CLI that pipes prompt text into a running OpenCode TUI session and streams the assistant final answer back to stdout.
|
|
4
9
|
|
|
5
10
|
It is designed for prompt-driven workflows where you want to do things like:
|
|
@@ -37,7 +42,7 @@ Notes:
|
|
|
37
42
|
## Usage
|
|
38
43
|
|
|
39
44
|
```bash
|
|
40
|
-
agentp [options] [
|
|
45
|
+
agentp [options] [url]
|
|
41
46
|
```
|
|
42
47
|
|
|
43
48
|
Options:
|
|
@@ -47,7 +52,7 @@ Options:
|
|
|
47
52
|
|
|
48
53
|
Arguments:
|
|
49
54
|
|
|
50
|
-
- `
|
|
55
|
+
- `url`: OpenCode TUI server URL or port number (defaults to `4096`). Examples: `4096`, `http://localhost:4096`, `http://192.168.1.50:4096`
|
|
51
56
|
|
|
52
57
|
## Examples
|
|
53
58
|
|
|
@@ -82,6 +87,12 @@ Capture answer to a file:
|
|
|
82
87
|
cat prompt.txt | agentp > answer.txt
|
|
83
88
|
```
|
|
84
89
|
|
|
90
|
+
Connect to a remote OpenCode server:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
cat prompt.txt | agentp http://192.168.1.50:4096
|
|
94
|
+
```
|
|
95
|
+
|
|
85
96
|
From Vim/Neovim, send the current visual selection and replace it in place with the assistant answer:
|
|
86
97
|
|
|
87
98
|
```vim
|
package/bin/agentp
CHANGED
|
@@ -46,8 +46,7 @@ async function submitPrompt(server) {
|
|
|
46
46
|
await makeRequest(buildJsonRequest(url, 'POST', '{}'), '{}');
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async function sendPrompt(
|
|
50
|
-
const server = `http://localhost:${port}`;
|
|
49
|
+
async function sendPrompt(server) {
|
|
51
50
|
let promptText = '';
|
|
52
51
|
|
|
53
52
|
await clearPrompt(server);
|
|
@@ -70,9 +69,9 @@ const HUMAN_ROW = '👤:  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄
|
|
|
70
69
|
const AGENT_ROW = '🤖:  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n'
|
|
71
70
|
const FINAL_ROW = ' ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄\n';
|
|
72
71
|
|
|
73
|
-
function listenForFinalAnswer(
|
|
72
|
+
function listenForFinalAnswer(server, showFinalRow) {
|
|
74
73
|
return new Promise((resolve, reject) => {
|
|
75
|
-
const url =
|
|
74
|
+
const url = `${server}/event`;
|
|
76
75
|
const parsed = new URL(url);
|
|
77
76
|
|
|
78
77
|
const req = http.request({
|
|
@@ -154,36 +153,39 @@ function listenForFinalAnswer(port, showFinalRow) {
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
async function main() {
|
|
157
|
-
let
|
|
156
|
+
let serverBase = 'http://localhost:4096';
|
|
158
157
|
let qaMode = false;
|
|
159
158
|
|
|
160
159
|
const args = process.argv.slice(2);
|
|
161
160
|
for (let i = 0; i < args.length; i++) {
|
|
162
161
|
if (args[i] === '--help') {
|
|
163
|
-
console.error('Usage: agentp [options] [
|
|
162
|
+
console.error('Usage: agentp [options] [url]');
|
|
164
163
|
console.error('');
|
|
165
|
-
console.error('Pipe prompt text to an OpenCode TUI session
|
|
166
|
-
console.error('The assistant response is streamed to stdout.');
|
|
164
|
+
console.error('Pipe prompt text to an OpenCode TUI session and stream the assistant response to stdout.');
|
|
167
165
|
console.error('');
|
|
168
166
|
console.error('Options:');
|
|
169
167
|
console.error(' --qa Print question/answer separators before streaming output');
|
|
170
168
|
console.error(' --help Show this help message');
|
|
171
169
|
console.error('');
|
|
172
170
|
console.error('Arguments:');
|
|
173
|
-
console.error('
|
|
171
|
+
console.error(' url OpenCode TUI server URL or port number (default: 4096)');
|
|
172
|
+
console.error(' Examples: 4096, http://localhost:4096, http://192.168.1.50:4096');
|
|
174
173
|
console.error('');
|
|
175
174
|
console.error('Examples:');
|
|
176
175
|
console.error(' printf "Summarize this file" | agentp');
|
|
177
176
|
console.error(' cat prompt.txt | agentp --qa 4096');
|
|
177
|
+
console.error(' cat prompt.txt | agentp http://192.168.1.50:4096');
|
|
178
178
|
process.exit(0);
|
|
179
179
|
} else if (args[i] === '--qa') {
|
|
180
180
|
qaMode = true;
|
|
181
|
-
} else if (
|
|
182
|
-
|
|
181
|
+
} else if (args[i].includes('://')) {
|
|
182
|
+
serverBase = args[i].replace(/\/+$/, '');
|
|
183
|
+
} else if (/^\d+$/.test(args[i])) {
|
|
184
|
+
serverBase = 'http://localhost:' + args[i];
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
|
|
186
|
-
const promptText = await sendPrompt(
|
|
188
|
+
const promptText = await sendPrompt(serverBase);
|
|
187
189
|
|
|
188
190
|
if (qaMode) {
|
|
189
191
|
process.stdout.write(HUMAN_ROW);
|
|
@@ -191,7 +193,7 @@ async function main() {
|
|
|
191
193
|
process.stdout.write(AGENT_ROW);
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
await listenForFinalAnswer(
|
|
196
|
+
await listenForFinalAnswer(serverBase, qaMode);
|
|
195
197
|
}
|
|
196
198
|
|
|
197
199
|
main().catch((err) => {
|