picocode-core 0.9.237 → 0.9.239
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 +1 -1
- package/package.json +1 -1
- package/src/acp/README.md +41 -0
- package/src/acp/connect.js +108 -0
- package/src/acp/engine.js +531 -0
- package/src/acp/pico-agent.js +295 -0
- package/src/acp/rpc.js +75 -0
- package/src/acp/translate.js +163 -0
- package/src/antigravity/README.md +42 -0
- package/src/antigravity/adapter.js +146 -0
- package/src/antigravity/conversations.js +22 -0
- package/src/antigravity/engine.js +27 -0
- package/src/antigravity/models.js +91 -0
- package/src/antigravity/process.js +60 -0
- package/src/boot.js +3 -2
- package/src/catalog-snapshot.json +1 -1
- package/src/claude-code/README.md +14 -20
- package/src/claude-code/adapter.js +278 -0
- package/src/claude-code/cli.js +6 -2
- package/src/claude-code/engine.js +30 -398
- package/src/claude-code/models.js +7 -4
- package/src/claude-code/token.js +23 -0
- package/src/claude-code/translate.js +65 -180
- package/src/controller.js +5 -2
- package/src/engine-history.js +87 -0
- package/src/engines.js +3 -1
- package/src/local-session.js +49 -0
- package/src/mcp.js +12 -1
- package/src/model-runtime.js +94 -0
- package/src/openai-auth.js +9 -1
- package/src/sign-in/antigravity.js +123 -0
- package/src/sign-in/chatgpt.js +32 -0
- package/src/sign-in/claude-code.js +73 -0
- package/src/sign-in/index.js +32 -0
- package/src/sign-in/screen.js +56 -0
- package/src/sign-in/supergrok.js +21 -0
- package/src/{claude-code/mcp-server.js → tool-bridge-server.js} +3 -3
- package/src/{claude-code/bridge.js → tool-bridge.js} +42 -12
- package/src/xai-auth.js +6 -1
package/README.md
CHANGED
|
@@ -12,4 +12,4 @@ import { deriveState } from 'picocode-core/derive.js'
|
|
|
12
12
|
import { createToolset } from 'picocode-core/tools/index.js'
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Model access goes through [@prsm/ai](https://github.com/prsmjs/ai), except for models whose provider has a turn engine (`engines.js`): Claude Code models (`claude-code/*`) run through the local `claude` command on the user's Claude subscription;
|
|
15
|
+
Model access goes through [@prsm/ai](https://github.com/prsmjs/ai), except for models whose provider has a turn engine (`engines.js`): Claude Code models (`claude-code/*`) run through the local `claude` command on the user's Claude subscription, and Antigravity models (`antigravity/*`) through Google's `agy acp` on the user's Google AI plan, both over ACP; and pico serves itself to any ACP app with `pico acp`. See `src/acp/README.md`. The package is plain ESM and requires Node 24 or newer.
|
package/package.json
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# ACP
|
|
2
|
+
|
|
3
|
+
pico speaks the Agent Client Protocol (ACP) on both sides. Every coding agent pico drives is reached as an ACP agent, and pico itself is one, for any ACP app.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
ACP app (Zed, ...) ──ACP──▶ pico acp (pico-agent.js: whole pico sessions, any model)
|
|
7
|
+
│
|
|
8
|
+
pico's sessions ── turn ──▶ ACP engine (engine.js)
|
|
9
|
+
│
|
|
10
|
+
┌───────┴────────┐
|
|
11
|
+
──ACP──▶ ──ACP──▶
|
|
12
|
+
Claude Code adapter Antigravity adapter
|
|
13
|
+
(claude -p, stream-json) (agy acp, passed through)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Models pico calls itself (API keys, ChatGPT for Codex, SuperGrok for Grok) run in pico's own agent loop; the agents with programs of their own (Claude Code, Antigravity) run through the ACP engine. Either way a session is a pico session, so a conversation can move between them.
|
|
17
|
+
|
|
18
|
+
| File | Role |
|
|
19
|
+
| --- | --- |
|
|
20
|
+
| `rpc.js` | JSON-RPC 2.0 peers, one message per line |
|
|
21
|
+
| `connect.js` | The three ways to meet an agent, one connection shape: `connectAgent` (an adapter in this process), `spawnAgent` (a program speaking ACP), `serveAgent` (pico offering an agent over stdio) |
|
|
22
|
+
| `engine.js` | The turn engine for every ACP agent: history sync, tool rows, diffs, questions, subagents, usage |
|
|
23
|
+
| `translate.js` | Pure mapping between ACP and pico shapes, and pico's `_meta.pico` extensions |
|
|
24
|
+
| `pico-agent.js` | pico as an ACP agent: `pico acp` |
|
|
25
|
+
|
|
26
|
+
## Adapters
|
|
27
|
+
|
|
28
|
+
An adapter makes one agent an ACP agent and owns everything particular to it: launching its program, its protocol, its tool names. It labels each tool call with the pico tool it amounts to (`_meta.pico.tool`), so the engine knows nothing of any one agent.
|
|
29
|
+
|
|
30
|
+
- `../claude-code/adapter.js`: translates Claude Code's stream-json; a session's id is Claude Code's own, so sessions resume and fork across restarts.
|
|
31
|
+
- `../antigravity/adapter.js`: passes `agy acp` through, adding pico's rules (no API keys in its environment, no permission prompts, questions marked for the person).
|
|
32
|
+
|
|
33
|
+
Each provider's `engine.js` is a few lines: the adapter, its label, and what pico adds to its instructions.
|
|
34
|
+
|
|
35
|
+
## Sign-ins
|
|
36
|
+
|
|
37
|
+
`../sign-in/` holds every subscription sign-in behind the same calls (status, start, finish, sign out): Claude Code's long-lived token, ChatGPT, SuperGrok and Antigravity. `pico --connect <provider>` uses them, and `pico acp` offers them as ACP auth methods.
|
|
38
|
+
|
|
39
|
+
## Checking it
|
|
40
|
+
|
|
41
|
+
`test/acp.test.js` runs the engine against a scripted agent, `test/pico-agent.test.js` the server against a scripted session, and each adapter has its own tests. `node scripts/claude-code-smoke.js` plays real Claude Code turns through the whole layer.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// The three ways pico meets an ACP agent, all giving the same connection:
|
|
2
|
+
// { request, notify, close, alive, stderr }.
|
|
3
|
+
//
|
|
4
|
+
// An agent pico implements itself (an adapter, such as Claude Code's, or
|
|
5
|
+
// pico's own) is a function `createAgent(client, { exit })`: `client`
|
|
6
|
+
// is how it reports (`notify`) and asks (`request`) the side using it,
|
|
7
|
+
// and `exit(error)` says it has stopped on its own. It returns
|
|
8
|
+
// `{ handle(method, params), notification(method, params), close() }`.
|
|
9
|
+
//
|
|
10
|
+
// - connectAgent runs such an agent in this process.
|
|
11
|
+
// - spawnAgent starts a program that speaks ACP on stdin and stdout.
|
|
12
|
+
// - serveAgent offers such an agent to an ACP app over a pair of streams.
|
|
13
|
+
|
|
14
|
+
import { spawn } from 'node:child_process'
|
|
15
|
+
import { streamPeer } from './rpc.js'
|
|
16
|
+
|
|
17
|
+
const reported = (error) => (error ? Object.assign(new Error(String(error.message || error)), { code: error.code ?? -32603, ...(error.data !== undefined ? { data: error.data } : {}) }) : error)
|
|
18
|
+
|
|
19
|
+
export function connectAgent(createAgent, { onNotification = () => {}, onRequest = async () => null, onExit = () => {} } = {}) {
|
|
20
|
+
let alive = true
|
|
21
|
+
const finish = (error = null) => {
|
|
22
|
+
if (!alive) return
|
|
23
|
+
alive = false
|
|
24
|
+
onExit({ error, stderr: '' })
|
|
25
|
+
}
|
|
26
|
+
const agent = createAgent({
|
|
27
|
+
notify: (method, params = {}) => { if (alive) onNotification(method, params) },
|
|
28
|
+
request: (method, params = {}) => (alive ? onRequest(method, params) : Promise.reject(new Error('the client has gone'))),
|
|
29
|
+
}, { exit: finish })
|
|
30
|
+
return {
|
|
31
|
+
get alive() { return alive },
|
|
32
|
+
get stderr() { return agent.stderr ?? '' },
|
|
33
|
+
request: async (method, params = {}) => {
|
|
34
|
+
if (!alive) throw new Error('the agent has stopped')
|
|
35
|
+
try { return (await agent.handle(method, params)) ?? null } catch (error) { throw reported(error) }
|
|
36
|
+
},
|
|
37
|
+
notify: (method, params = {}) => { if (alive) agent.notification?.(method, params) },
|
|
38
|
+
close() {
|
|
39
|
+
if (!alive) return
|
|
40
|
+
agent.close?.()
|
|
41
|
+
finish(null)
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function spawnAgent({ command, args = [], cwd, env = process.env, onNotification, onRequest, onExit = () => {}, missing = `${command} not found` }) {
|
|
47
|
+
const child = spawn(command, args, { cwd, env, stdio: ['pipe', 'pipe', 'pipe'] })
|
|
48
|
+
let stderr = ''
|
|
49
|
+
let alive = true
|
|
50
|
+
const peer = streamPeer({ input: child.stdout, output: child.stdin, onNotification, onRequest })
|
|
51
|
+
child.stderr.setEncoding('utf8')
|
|
52
|
+
child.stderr.on('data', (chunk) => { stderr = (stderr + chunk).slice(-4000) })
|
|
53
|
+
child.stdin.on('error', () => {})
|
|
54
|
+
const finish = (error) => {
|
|
55
|
+
if (!alive) return
|
|
56
|
+
alive = false
|
|
57
|
+
peer.close(error ?? new Error(`${command} stopped`))
|
|
58
|
+
onExit({ error, stderr: stderr.trim() })
|
|
59
|
+
}
|
|
60
|
+
child.on('error', (error) => finish(error.code === 'ENOENT' ? new Error(missing) : error))
|
|
61
|
+
child.on('exit', (code, signal) => finish(code === 0 || signal === 'SIGTERM' || signal === 'SIGKILL' ? null : new Error(`${command} exited with ${signal ?? `code ${code}`}`)))
|
|
62
|
+
return {
|
|
63
|
+
get alive() { return alive },
|
|
64
|
+
get stderr() { return stderr.trim() },
|
|
65
|
+
request: (method, params = {}) => (alive ? peer.request(method, params) : Promise.reject(new Error(`${command} is not running`))),
|
|
66
|
+
notify: (method, params = {}) => { if (alive) peer.notify(method, params) },
|
|
67
|
+
close() {
|
|
68
|
+
if (!alive) return
|
|
69
|
+
child.stdin.end()
|
|
70
|
+
child.kill('SIGTERM')
|
|
71
|
+
setTimeout(() => { if (alive) child.kill('SIGKILL') }, 3000).unref()
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// resolves once the app has gone (its input ended) and the agent has closed
|
|
77
|
+
export function serveAgent(createAgent, { input = process.stdin, output = process.stdout } = {}) {
|
|
78
|
+
let agent = null
|
|
79
|
+
const peer = streamPeer({
|
|
80
|
+
input,
|
|
81
|
+
output,
|
|
82
|
+
onRequest: (method, params) => agent.handle(method, params),
|
|
83
|
+
onNotification: (method, params) => agent.notification?.(method, params),
|
|
84
|
+
})
|
|
85
|
+
return new Promise((resolve) => {
|
|
86
|
+
let ended = false
|
|
87
|
+
const done = async () => {
|
|
88
|
+
if (ended) return
|
|
89
|
+
ended = true
|
|
90
|
+
peer.close()
|
|
91
|
+
await agent?.close?.()
|
|
92
|
+
resolve()
|
|
93
|
+
}
|
|
94
|
+
agent = createAgent({ notify: peer.notify, request: peer.request }, { exit: done })
|
|
95
|
+
input.on('end', done)
|
|
96
|
+
input.on('close', done)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// the handshake every connection starts with. The agent uses its own tools
|
|
101
|
+
// for files and commands, so pico offers it neither
|
|
102
|
+
export function initialize(conn) {
|
|
103
|
+
return conn.request('initialize', {
|
|
104
|
+
protocolVersion: 1,
|
|
105
|
+
clientCapabilities: { fs: { readTextFile: false, writeTextFile: false }, terminal: false },
|
|
106
|
+
clientInfo: { name: 'pico', title: 'pico', version: '1' },
|
|
107
|
+
})
|
|
108
|
+
}
|