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
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Antigravity as an ACP agent: Google's `agy acp` already speaks ACP, so
|
|
2
|
+
// this adapter passes every message through, and adds only pico's rules
|
|
3
|
+
// and what pico knows of agy's tools:
|
|
4
|
+
//
|
|
5
|
+
// - agy runs without API keys in its environment (process.js), on the
|
|
6
|
+
// Google sign-in it keeps, with no permission prompts
|
|
7
|
+
// - pico's instructions reach agy as its own system prompt extension
|
|
8
|
+
// - each tool call is labelled with the pico tool it amounts to, from
|
|
9
|
+
// agy's own argument names; a call to the client's MCP server, and one
|
|
10
|
+
// that starts a subagent, say so
|
|
11
|
+
// - a permission agy means as a question to the person is marked as one
|
|
12
|
+
// - the models a session offers are kept as the catalog (models.js)
|
|
13
|
+
// - a session opened for one question is removed from agy's history
|
|
14
|
+
|
|
15
|
+
import { spawnAgent } from '../acp/connect.js'
|
|
16
|
+
import { modelsOffered, shortPath } from '../acp/translate.js'
|
|
17
|
+
import { AGY_ARGS, agyEnv } from './process.js'
|
|
18
|
+
import { agyCommand, writeCatalog } from './models.js'
|
|
19
|
+
import { agyDataDir, forgetConversation } from './conversations.js'
|
|
20
|
+
|
|
21
|
+
const pick = (input, keys) => {
|
|
22
|
+
for (const key of keys) if (input?.[key] != null && input[key] !== '') return input[key]
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
const PATH_KEYS = ['AbsolutePath', 'absolute_path', 'TargetFile', 'target_file', 'FilePath', 'file_path', 'Path', 'path']
|
|
26
|
+
const COMMAND_KEYS = ['CommandLine', 'command_line', 'commandLine', 'command']
|
|
27
|
+
const CWD_KEYS = ['Cwd', 'WorkingDirectory', 'working_dir', 'workingDir', 'cwd']
|
|
28
|
+
const SUBAGENT_TOOLS = new Set(['start_subagent', 'invoke_subagent'])
|
|
29
|
+
|
|
30
|
+
// what an agy tool call names itself by: "Running run_command" while it
|
|
31
|
+
// runs, "Run run_command?" while it waits for approval
|
|
32
|
+
export function agyToolName(call = {}) {
|
|
33
|
+
return String(call.title ?? '').match(/^(?:Running|Run|Ran)\s+([A-Za-z0-9_.:/-]+)\??$/)?.[1] ?? null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// the MCP tool a call reached, when it went to one of `servers`: agy names
|
|
37
|
+
// it with the server's name before the tool's
|
|
38
|
+
export function mcpTool(call = {}, servers = []) {
|
|
39
|
+
const name = agyToolName(call) ?? String(call.title ?? '')
|
|
40
|
+
for (const server of servers) {
|
|
41
|
+
const match = name.match(new RegExp(`^(?:mcp[_:/.]+)?${server}[_:/.]+(.+)$`))
|
|
42
|
+
if (match) return match[1]
|
|
43
|
+
}
|
|
44
|
+
return null
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// the pico tool an agy tool call amounts to
|
|
48
|
+
export function picoTool(call = {}, cwd, servers = []) {
|
|
49
|
+
const input = call.rawInput ?? {}
|
|
50
|
+
const bridged = mcpTool(call, servers)
|
|
51
|
+
if (bridged) return { tool: { name: bridged, args: input }, bridged: true }
|
|
52
|
+
const tool = agyToolName(call)
|
|
53
|
+
if (tool && SUBAGENT_TOOLS.has(tool)) {
|
|
54
|
+
const description = pick(input, ['Description', 'description', 'Role', 'role', 'TaskName', 'task_name'])
|
|
55
|
+
const prompt = pick(input, ['Prompt', 'prompt', 'Task', 'task', 'Instructions', 'instructions']) ?? ''
|
|
56
|
+
return { tool: { name: 'Task', args: { description, prompt } }, subagent: { description, prompt } }
|
|
57
|
+
}
|
|
58
|
+
const path = shortPath(call.locations?.[0]?.path ?? pick(input, PATH_KEYS), cwd)
|
|
59
|
+
switch (call.kind) {
|
|
60
|
+
case 'execute': {
|
|
61
|
+
const at = pick(input, CWD_KEYS)
|
|
62
|
+
return { tool: { name: 'bash', args: { command: pick(input, COMMAND_KEYS) ?? call.title, ...(at ? { cwd: shortPath(at, cwd) } : {}) } } }
|
|
63
|
+
}
|
|
64
|
+
case 'search': return { tool: { name: 'grep', args: { pattern: pick(input, ['Query', 'query', 'Pattern', 'pattern', 'SearchPattern']), ...(path ? { path } : {}) } } }
|
|
65
|
+
case 'fetch': return { tool: { name: 'web_fetch', args: { url: pick(input, ['Url', 'url', 'URL']) ?? call.title } } }
|
|
66
|
+
case 'edit': case 'delete': case 'move': case 'read': return { tool: { name: call.kind, args: { path } } }
|
|
67
|
+
default: return { tool: { name: tool ?? call.kind ?? 'tool', args: input } }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// a command's output, which agy reports under its own names rather than
|
|
72
|
+
// as the call's content
|
|
73
|
+
const OUTPUT_KEYS = ['combinedOutput', 'combined_output', 'output']
|
|
74
|
+
export function withOutput(update) {
|
|
75
|
+
if (update.content?.length || !update.rawOutput || typeof update.rawOutput !== 'object') return update
|
|
76
|
+
const text = pick(update.rawOutput, OUTPUT_KEYS)
|
|
77
|
+
return typeof text === 'string' ? { ...update, content: [{ type: 'content', content: { type: 'text', text } }] } : update
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// a call's location, from agy's own argument names when it gives none
|
|
81
|
+
const located = (call) => {
|
|
82
|
+
if (call.locations?.length) return call
|
|
83
|
+
const path = pick(call.rawInput, PATH_KEYS)
|
|
84
|
+
return path ? { ...call, locations: [{ path }] } : call
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function connectAntigravity({ cwd, env = {}, onNotification = () => {}, onRequest = async () => null, onExit = () => {}, command = agyCommand() }) {
|
|
88
|
+
// per agy session: the MCP servers it was given, its folder, and
|
|
89
|
+
// whether it is only for one question
|
|
90
|
+
const sessions = new Map()
|
|
91
|
+
const known = (sessionId) => sessions.get(sessionId) ?? { servers: [], cwd, ephemeral: false }
|
|
92
|
+
|
|
93
|
+
const normalizeUpdate = (params) => {
|
|
94
|
+
const update = withOutput(params.update ?? {})
|
|
95
|
+
if (update !== params.update) params = { ...params, update }
|
|
96
|
+
if (update.sessionUpdate !== 'tool_call' && !(update.sessionUpdate === 'tool_call_update' && (update.title || update.rawInput))) return params
|
|
97
|
+
const session = known(params.sessionId)
|
|
98
|
+
const call = located(update)
|
|
99
|
+
const meta = picoTool(call, session.cwd, session.servers)
|
|
100
|
+
return { ...params, update: { ...call, _meta: { ...call._meta, pico: { ...call._meta?.pico, ...meta } } } }
|
|
101
|
+
}
|
|
102
|
+
const normalizePermission = (params) => (String(params.toolCall?.toolCallId ?? '').startsWith('interaction_') ? { ...params, _meta: { ...params._meta, pico: { ...params._meta?.pico, question: true } } } : params)
|
|
103
|
+
|
|
104
|
+
if (!command) {
|
|
105
|
+
queueMicrotask(() => onExit({ error: new Error('The Antigravity CLI is not installed on this machine'), stderr: '' }))
|
|
106
|
+
return { alive: false, stderr: '', request: () => Promise.reject(new Error('The Antigravity CLI is not installed on this machine')), notify() {}, close() {} }
|
|
107
|
+
}
|
|
108
|
+
const conn = spawnAgent({
|
|
109
|
+
command,
|
|
110
|
+
args: AGY_ARGS,
|
|
111
|
+
cwd,
|
|
112
|
+
env: agyEnv({ ...process.env, ...env }),
|
|
113
|
+
missing: 'The Antigravity CLI is not installed on this machine',
|
|
114
|
+
onNotification: (method, params) => onNotification(method, method === 'session/update' ? normalizeUpdate(params) : params),
|
|
115
|
+
onRequest: (method, params) => onRequest(method, method === 'session/request_permission' ? normalizePermission(params) : params),
|
|
116
|
+
onExit,
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// pico's own session options, as agy takes them
|
|
120
|
+
const outgoing = (params) => {
|
|
121
|
+
const { pico, ...meta } = params._meta ?? {}
|
|
122
|
+
if (!pico) return params
|
|
123
|
+
return { ...params, _meta: { ...meta, ...(pico.systemPrompt ? { antigravity: { ...meta.antigravity, systemPrompt: { append: pico.systemPrompt } } } : {}) } }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function request(method, params = {}) {
|
|
127
|
+
const opens = ['session/new', 'session/resume', 'session/load', 'session/fork'].includes(method)
|
|
128
|
+
const result = await conn.request(method, opens ? outgoing(params) : params)
|
|
129
|
+
if (opens) {
|
|
130
|
+
const sessionId = result?.sessionId ?? params.sessionId
|
|
131
|
+
sessions.set(sessionId, { servers: (params.mcpServers ?? []).map((s) => s.name), cwd: params.cwd ?? cwd, ephemeral: !!params._meta?.pico?.ephemeral })
|
|
132
|
+
const models = modelsOffered(result?.configOptions)
|
|
133
|
+
if (models.length) writeCatalog(models)
|
|
134
|
+
}
|
|
135
|
+
if (method === 'session/close' && known(params.sessionId).ephemeral) forgetConversation(params.sessionId, { dir: agyDataDir({ ...process.env, ...env }) })
|
|
136
|
+
return result
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
get alive() { return conn.alive },
|
|
141
|
+
get stderr() { return conn.stderr },
|
|
142
|
+
request,
|
|
143
|
+
notify: conn.notify,
|
|
144
|
+
close: conn.close,
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// agy keeps every conversation it has, for its own history. A session pico
|
|
2
|
+
// opens only to sign in, or to answer one question outside any
|
|
3
|
+
// conversation, is not one the person had, so it is removed afterward.
|
|
4
|
+
|
|
5
|
+
import { rmSync, readdirSync } from 'node:fs'
|
|
6
|
+
import { homedir } from 'node:os'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
|
|
9
|
+
const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
10
|
+
|
|
11
|
+
export function agyDataDir(env = process.env) {
|
|
12
|
+
return join(env.GEMINI_HOME || join(homedir(), '.gemini'), 'antigravity-cli')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function forgetConversation(sessionId, { dir = agyDataDir() } = {}) {
|
|
16
|
+
if (!ID.test(String(sessionId))) return
|
|
17
|
+
const conversations = join(dir, 'conversations')
|
|
18
|
+
try {
|
|
19
|
+
for (const name of readdirSync(conversations)) if (name.startsWith(`${sessionId}.`)) rmSync(join(conversations, name), { force: true })
|
|
20
|
+
} catch {}
|
|
21
|
+
rmSync(join(dir, 'brain', sessionId), { recursive: true, force: true })
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Antigravity as pico's sessions run it: the ACP engine (../acp/engine.js)
|
|
2
|
+
// over Google's own `agy acp`, through the Antigravity adapter.
|
|
3
|
+
|
|
4
|
+
import { basename, dirname, isAbsolute, relative } from 'node:path'
|
|
5
|
+
import { createAcpEngine, HOST_NOTE } from '../acp/engine.js'
|
|
6
|
+
import { connectAntigravity } from './adapter.js'
|
|
7
|
+
import { ANTIGRAVITY_PROVIDER } from './models.js'
|
|
8
|
+
|
|
9
|
+
// agy reads the AGENTS.md and GEMINI.md files of the project it works in
|
|
10
|
+
// itself; any other instructions pico would give its own models (a global
|
|
11
|
+
// AGENTS.md, say) are passed along
|
|
12
|
+
export function systemPrompt({ contextFiles = [], memoryIndexText = '', cwd } = {}) {
|
|
13
|
+
const own = (file) => {
|
|
14
|
+
if (!['AGENTS.md', 'GEMINI.md'].includes(basename(file.path)) || !cwd) return false
|
|
15
|
+
const rel = relative(dirname(file.path), cwd)
|
|
16
|
+
return !rel.startsWith('..') && !isAbsolute(rel)
|
|
17
|
+
}
|
|
18
|
+
const files = contextFiles.filter((file) => !own(file) && file.content?.trim())
|
|
19
|
+
const parts = [HOST_NOTE]
|
|
20
|
+
if (memoryIndexText) parts.push(memoryIndexText.replace(/\bthe (remember|recall) tool\b/g, 'the pico server\'s $1 tool'))
|
|
21
|
+
if (files.length) parts.push(`Project instructions:\n\n${files.map((file) => `<file path="${file.path}">\n${file.content.trim()}\n</file>`).join('\n\n')}`)
|
|
22
|
+
return parts.join('\n\n')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function createAntigravityEngine({ connect = connectAntigravity, ...options } = {}) {
|
|
26
|
+
return createAcpEngine({ provider: ANTIGRAVITY_PROVIDER, label: 'Antigravity', connect, systemPrompt, ...options })
|
|
27
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The Antigravity models pico offers, and whether this machine can run
|
|
2
|
+
// them. They are reached through Google's own `agy` command and the
|
|
3
|
+
// Google sign-in it keeps, never through an API key.
|
|
4
|
+
|
|
5
|
+
import { execFile } from 'node:child_process'
|
|
6
|
+
import { accessSync, constants, readFileSync, writeFileSync, mkdirSync, renameSync } from 'node:fs'
|
|
7
|
+
import { homedir } from 'node:os'
|
|
8
|
+
import { delimiter, dirname, join } from 'node:path'
|
|
9
|
+
import { promisify } from 'node:util'
|
|
10
|
+
import { picoHome } from '../paths.js'
|
|
11
|
+
import { agyEnv } from './process.js'
|
|
12
|
+
|
|
13
|
+
const exec = promisify(execFile)
|
|
14
|
+
|
|
15
|
+
export const ANTIGRAVITY_PROVIDER = 'antigravity'
|
|
16
|
+
|
|
17
|
+
// Gemini's context window; agy does not report one
|
|
18
|
+
const CONTEXT = 1000000
|
|
19
|
+
|
|
20
|
+
// the `agy` executable. A host started from a desktop launcher does not
|
|
21
|
+
// have the user's shell PATH, so the installer's own location is looked in too
|
|
22
|
+
export function agyCommand(env = process.env) {
|
|
23
|
+
const candidates = [
|
|
24
|
+
...String(env.PATH ?? '').split(delimiter).filter(Boolean).map((dir) => join(dir, 'agy')),
|
|
25
|
+
join(homedir(), '.local', 'bin', 'agy'),
|
|
26
|
+
]
|
|
27
|
+
for (const path of candidates) {
|
|
28
|
+
try { accessSync(path, constants.X_OK); return path } catch {}
|
|
29
|
+
}
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// the models agy last said this sign-in may use, kept between runs so a
|
|
34
|
+
// host can list them before any session starts
|
|
35
|
+
const catalogFile = () => join(picoHome(), 'antigravity-models.json')
|
|
36
|
+
|
|
37
|
+
export function readCatalog() {
|
|
38
|
+
try { return JSON.parse(readFileSync(catalogFile(), 'utf8')) } catch { return [] }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function writeCatalog(models) {
|
|
42
|
+
if (JSON.stringify(models) === JSON.stringify(readCatalog())) return
|
|
43
|
+
mkdirSync(dirname(catalogFile()), { recursive: true })
|
|
44
|
+
writeFileSync(`${catalogFile()}.new`, JSON.stringify(models))
|
|
45
|
+
renameSync(`${catalogFile()}.new`, catalogFile())
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// the models `agy models` lists: one per line, its id first
|
|
49
|
+
export function parseModelList(stdout) {
|
|
50
|
+
const models = []
|
|
51
|
+
for (const line of String(stdout).split('\n')) {
|
|
52
|
+
const match = line.trim().replace(/^[-*•]\s*/, '').match(/^([a-z][a-z0-9]*(?:[-._][a-z0-9]+)+)\b\s*[-:(]?\s*(.*?)\)?\s*$/i)
|
|
53
|
+
if (match) models.push({ id: match[1], label: match[2] || match[1] })
|
|
54
|
+
}
|
|
55
|
+
return models
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function antigravityModels(catalog = readCatalog(), { available = true } = {}) {
|
|
59
|
+
return catalog.map(({ id, label }) => ({
|
|
60
|
+
name: `${ANTIGRAVITY_PROVIDER}/${id}`,
|
|
61
|
+
label: `${label} (Antigravity)`,
|
|
62
|
+
provider: ANTIGRAVITY_PROVIDER,
|
|
63
|
+
context: CONTEXT,
|
|
64
|
+
effort: true,
|
|
65
|
+
vision: true,
|
|
66
|
+
speed: false,
|
|
67
|
+
available,
|
|
68
|
+
keyHint: 'Sign in to Antigravity',
|
|
69
|
+
}))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// the id agy takes for a pico model name
|
|
73
|
+
export function agyModel(name) {
|
|
74
|
+
return String(name).startsWith(`${ANTIGRAVITY_PROVIDER}/`) ? name.slice(ANTIGRAVITY_PROVIDER.length + 1) : name
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// whether `agy` is installed and signed in to a Google account. It reads
|
|
78
|
+
// only what `agy models` prints: agy's login stays agy's
|
|
79
|
+
export async function antigravityStatus({ command = agyCommand() } = {}) {
|
|
80
|
+
if (!command) return { installed: false, connected: false, models: [] }
|
|
81
|
+
try {
|
|
82
|
+
const { stdout } = await exec(command, ['models'], { env: agyEnv(), timeout: 30000, cwd: homedir() })
|
|
83
|
+
const listed = parseModelList(stdout)
|
|
84
|
+
const known = readCatalog()
|
|
85
|
+
// the session's own list names models best; the command's adds any it lacks
|
|
86
|
+
const models = [...known, ...listed.filter((m) => !known.some((k) => k.id === m.id))]
|
|
87
|
+
return { installed: true, connected: true, models }
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return { installed: error.code !== 'ENOENT', connected: false, models: [], ...(/sign in/i.test(`${error.stdout}${error.stderr}`) ? {} : { error: String(error.stderr || error.message).trim().split('\n').at(-1) }) }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// What an `agy acp` process runs with: Google's own Antigravity agent,
|
|
2
|
+
// unmodified, which signs in, keeps its login and talks to Google itself.
|
|
3
|
+
// pico never reads or passes on agy's credentials.
|
|
4
|
+
|
|
5
|
+
import { mkdtempSync, rmSync, writeFileSync, watch, readFileSync, existsSync } from 'node:fs'
|
|
6
|
+
import { tmpdir } from 'node:os'
|
|
7
|
+
import { delimiter, join } from 'node:path'
|
|
8
|
+
|
|
9
|
+
// these make agy use an API key or a Cloud project in place of the Google
|
|
10
|
+
// sign-in, silently; a session in pico always runs on the subscription
|
|
11
|
+
const API_AUTH_VARIABLES = [
|
|
12
|
+
'GEMINI_API_KEY', 'GOOGLE_API_KEY', 'GOOGLE_APPLICATION_CREDENTIALS', 'GOOGLE_CLOUD_PROJECT', 'GOOGLE_CLOUD_LOCATION',
|
|
13
|
+
'GOOGLE_CLOUD_QUOTA_PROJECT', 'GOOGLE_GENAI_USE_VERTEXAI', 'GCLOUD_PROJECT', 'CLOUDSDK_CORE_PROJECT', 'AGY_ADC_AUTH',
|
|
14
|
+
'GOOGLE_GEMINI_BASE_URL',
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
export function agyEnv(env = process.env) {
|
|
18
|
+
const out = { ...env }
|
|
19
|
+
for (const key of API_AUTH_VARIABLES) delete out[key]
|
|
20
|
+
return out
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// the programs agy may open a web page with; stood in for while signing
|
|
24
|
+
// in, so the page is shown where the person is rather than on this machine
|
|
25
|
+
const OPENERS = ['xdg-open', 'open', 'sensible-browser', 'x-www-browser', 'gnome-open', 'kde-open', 'wslview']
|
|
26
|
+
|
|
27
|
+
// a folder of stand-in openers that write the page they were asked to open
|
|
28
|
+
// to a file, and a way to wait for it. agy runs them with their output
|
|
29
|
+
// thrown away, so the file is the only way the address comes back
|
|
30
|
+
export function pageCatcher() {
|
|
31
|
+
const dir = mkdtempSync(join(tmpdir(), 'pico-agy-open-'))
|
|
32
|
+
const file = join(dir, 'opened')
|
|
33
|
+
const script = `#!/bin/sh\nprintf '%s\\n' "$1" >> '${file}'\n`
|
|
34
|
+
for (const opener of OPENERS) writeFileSync(join(dir, opener), script, { mode: 0o755 })
|
|
35
|
+
let watcher = null
|
|
36
|
+
return {
|
|
37
|
+
env: (env) => ({ ...env, PATH: `${dir}${delimiter}${env.PATH ?? ''}`, BROWSER: join(dir, 'xdg-open') }),
|
|
38
|
+
// the first page agy opens
|
|
39
|
+
next() {
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
const read = () => {
|
|
42
|
+
if (!existsSync(file)) return false
|
|
43
|
+
const url = readFileSync(file, 'utf8').split('\n').find(Boolean)
|
|
44
|
+
if (url) { watcher?.close(); watcher = null; resolve(url.trim()) }
|
|
45
|
+
return !!url
|
|
46
|
+
}
|
|
47
|
+
if (read()) return
|
|
48
|
+
watcher = watch(dir, () => { read() })
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
close() {
|
|
52
|
+
watcher?.close()
|
|
53
|
+
rmSync(dir, { recursive: true, force: true })
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// agy as pico runs it: an ACP agent, with no permission prompts, as pico
|
|
59
|
+
// runs; questions still come, and go to the person
|
|
60
|
+
export const AGY_ARGS = ['acp', '--dangerously-skip-permissions']
|
package/src/boot.js
CHANGED
|
@@ -6,7 +6,8 @@ import { createCommandIndex } from './commands.js'
|
|
|
6
6
|
import { createMcpRuntime } from './mcp.js'
|
|
7
7
|
import { createMemory } from './memory.js'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// `mcpServers` are the session's own MCP servers (name to command), from the app that opened it
|
|
10
|
+
export async function buildProjectBoot(cwd, { onMcpChange = () => {}, mcpServers = {} } = {}) {
|
|
10
11
|
const home = homedir()
|
|
11
12
|
const root = findProjectRoot(cwd)
|
|
12
13
|
const startupContext = loadStartupContext(cwd)
|
|
@@ -22,7 +23,7 @@ export async function buildProjectBoot(cwd, { onMcpChange = () => {} } = {}) {
|
|
|
22
23
|
tracker,
|
|
23
24
|
skills: await createSkillIndex(root),
|
|
24
25
|
commands: await createCommandIndex(root),
|
|
25
|
-
mcp: await createMcpRuntime({ root, onChange: onMcpChange }),
|
|
26
|
+
mcp: await createMcpRuntime({ root, onChange: onMcpChange, sessionServers: mcpServers }),
|
|
26
27
|
memory: createMemory(root),
|
|
27
28
|
}
|
|
28
29
|
}
|