@openagents-org/agent-launcher 0.2.215 → 0.2.217
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/icons/kiro.svg +11 -0
- package/package.json +1 -1
- package/registry.json +103 -3
- package/src/adapters/acp-client.js +217 -0
- package/src/adapters/claude.js +64 -8
- package/src/adapters/codex.js +126 -33
- package/src/adapters/hermes.js +164 -87
- package/src/adapters/index.js +4 -1
- package/src/adapters/kiro-runtime.js +318 -0
- package/src/adapters/kiro.js +813 -0
- package/src/adapters/opencode.js +37 -1
- package/src/daemon.js +7 -8
- package/src/index.js +7 -13
- package/src/install-preflight.js +20 -1
- package/src/paths.js +6 -0
- package/src/utils.js +12 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Pure helpers for KiroAdapter (kiro.js): everything that can be decided
|
|
5
|
+
* without a process, a socket or adapter state, so each rule is unit-tested
|
|
6
|
+
* on its own (test/kiro-runtime.test.js).
|
|
7
|
+
*
|
|
8
|
+
* The adapter drives `kiro-cli acp` — Kiro CLI's Agent Client Protocol server,
|
|
9
|
+
* JSON-RPC 2.0 over stdio — instead of scraping a TUI. The facts below were
|
|
10
|
+
* read off kiro-cli 2.37.0 with a recording client, not taken from docs:
|
|
11
|
+
*
|
|
12
|
+
* - `initialize` answers protocolVersion 1 with loadSession: true and
|
|
13
|
+
* mcpCapabilities { http: true, sse: false } (stdio servers are always on).
|
|
14
|
+
* - `session/new { cwd, mcpServers }` starts the servers it is handed NEXT TO
|
|
15
|
+
* the ones the selected Kiro agent profile declares (`--agent <name>`), so
|
|
16
|
+
* the workspace tools and the agent's own tools coexist.
|
|
17
|
+
* - `session/load` replays the transcript as ordinary session/update frames
|
|
18
|
+
* tagged `_meta.kiro.replay: true` before it answers. They are history,
|
|
19
|
+
* not this turn's output, and must not reach the channel.
|
|
20
|
+
* - A session id the CLI no longer has fails session/load with JSON-RPC
|
|
21
|
+
* -32603 and data "Failed to start session: Session not found: <id>".
|
|
22
|
+
* - Without `--trust-all-tools` every tool call that needs approval arrives
|
|
23
|
+
* as a `session/request_permission` request offering allow_once /
|
|
24
|
+
* allow_always / reject_once; the tool_call update that precedes it
|
|
25
|
+
* carries the tool's `kind` and `_meta.kiro.mcpServerName`.
|
|
26
|
+
* - `session/cancel` ends the prompt with stopReason "cancelled".
|
|
27
|
+
* - An unknown `--agent` does not fail: the CLI sends
|
|
28
|
+
* `_kiro.dev/agent/not_found` and silently runs its default agent.
|
|
29
|
+
* - Narration before a tool call streams as agent_message_chunk exactly like
|
|
30
|
+
* the answer does; only the text after the LAST tool call is the reply.
|
|
31
|
+
* - Vendor notifications live under `_kiro.dev/` and carry nothing a
|
|
32
|
+
* channel needs.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
const { redactSecrets } = require('./utils');
|
|
36
|
+
|
|
37
|
+
/** The CLI binary the official installers put on PATH. */
|
|
38
|
+
const KIRO_BINARY = 'kiro-cli';
|
|
39
|
+
|
|
40
|
+
/** The version every claim above was verified against. */
|
|
41
|
+
const KIRO_MIN_VERSION = '2.37.0';
|
|
42
|
+
|
|
43
|
+
/** ACP protocol version this client speaks. */
|
|
44
|
+
const ACP_PROTOCOL_VERSION = 1;
|
|
45
|
+
|
|
46
|
+
/** Name the workspace MCP server is registered under, same as every adapter. */
|
|
47
|
+
const WORKSPACE_MCP_NAME = 'openagents-workspace';
|
|
48
|
+
|
|
49
|
+
/** ACP tool kinds that never change anything — allowed in plan mode. */
|
|
50
|
+
const READ_ONLY_KINDS = new Set(['read', 'search', 'think', 'fetch']);
|
|
51
|
+
|
|
52
|
+
function installHint(platform = process.platform) {
|
|
53
|
+
return platform === 'win32'
|
|
54
|
+
? 'irm https://cli.kiro.dev/install.ps1 | iex'
|
|
55
|
+
: 'curl -fsSL https://cli.kiro.dev/install | bash';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** "kiro-cli 2.37.0" → [2, 37, 0]; null when there is no version in it. */
|
|
59
|
+
function parseKiroVersion(text) {
|
|
60
|
+
const m = String(text || '').match(/(\d+)\.(\d+)\.(\d+)/);
|
|
61
|
+
return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function compareVersions(a, b) {
|
|
65
|
+
for (let i = 0; i < 3; i++) {
|
|
66
|
+
const d = (a[i] || 0) - (b[i] || 0);
|
|
67
|
+
if (d) return d < 0 ? -1 : 1;
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* `--version` output → { version, supported }. supported is null when the
|
|
74
|
+
* output names no version (the adapter proceeds leniently rather than block
|
|
75
|
+
* an agent on a probe it cannot read).
|
|
76
|
+
*/
|
|
77
|
+
function classifyKiroVersion(text, min = KIRO_MIN_VERSION) {
|
|
78
|
+
const parsed = parseKiroVersion(text);
|
|
79
|
+
if (!parsed) return { version: null, supported: null };
|
|
80
|
+
return {
|
|
81
|
+
version: parsed.join('.'),
|
|
82
|
+
supported: compareVersions(parsed, parseKiroVersion(min)) >= 0,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The Kiro agent profile and model this agent runs, from its env. A model
|
|
88
|
+
* picked in the workspace wins over the one saved for the agent.
|
|
89
|
+
*
|
|
90
|
+
* KIRO_AGENT names a profile in <workingDir>/.kiro/agents or
|
|
91
|
+
* ~/.kiro/agents — that profile carries the agent's own prompt, tools and MCP
|
|
92
|
+
* servers, which is how one machine runs several distinct Kiro agents.
|
|
93
|
+
*/
|
|
94
|
+
function resolveKiroSettings(env = {}, workspaceModel = null) {
|
|
95
|
+
const clean = (v) => {
|
|
96
|
+
const s = String(v || '').trim();
|
|
97
|
+
return s || null;
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
agent: clean(env.KIRO_AGENT),
|
|
101
|
+
model: clean(workspaceModel) || clean(env.KIRO_MODEL) || clean(env.LLM_MODEL),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* argv for one `kiro-cli acp` server. No `--trust-all-tools`: approvals are
|
|
107
|
+
* answered by the adapter, which is what lets plan mode refuse writes.
|
|
108
|
+
* The agent and model names are passed through as single argv entries and
|
|
109
|
+
* never reach a shell.
|
|
110
|
+
*/
|
|
111
|
+
function buildKiroArgs({ agent = null, model = null } = {}) {
|
|
112
|
+
const args = ['acp'];
|
|
113
|
+
if (agent) args.push('--agent', agent);
|
|
114
|
+
if (model) args.push('--model', model);
|
|
115
|
+
return args;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The ACP stdio form of an MCP server: env is a list of {name, value}, not
|
|
120
|
+
* an object. Values travel to Kiro over stdin in the JSON-RPC message; they are
|
|
121
|
+
* never in argv or written to disk by OpenAgents (Kiro may persist them).
|
|
122
|
+
*/
|
|
123
|
+
function toAcpMcpServer(name, { command, args = [], env = {} }) {
|
|
124
|
+
return {
|
|
125
|
+
name,
|
|
126
|
+
command,
|
|
127
|
+
args: [...args],
|
|
128
|
+
env: Object.entries(env)
|
|
129
|
+
.filter(([, v]) => v !== undefined && v !== null && v !== '')
|
|
130
|
+
.map(([k, v]) => ({ name: k, value: String(v) })),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Text out of an ACP content block (or a tool_call content entry). */
|
|
135
|
+
function contentText(content) {
|
|
136
|
+
if (!content) return '';
|
|
137
|
+
if (typeof content === 'string') return content;
|
|
138
|
+
if (content.type === 'text') return String(content.text || '');
|
|
139
|
+
if (content.type === 'content' && content.content) return contentText(content.content);
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function truncate(s, n) {
|
|
144
|
+
const str = String(s || '');
|
|
145
|
+
return str.length > n ? `${str.slice(0, n - 1)}…` : str;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A short label for a tool call. Kiro titles MCP calls "Running: @server/tool"
|
|
150
|
+
* and shell calls "Running: <command>"; the label keeps the tool and what it
|
|
151
|
+
* is doing without saying either twice.
|
|
152
|
+
*/
|
|
153
|
+
function toolLabel(update, meta) {
|
|
154
|
+
const name = meta.toolName || '';
|
|
155
|
+
const title = String(update.title || '').replace(/^Running:\s*/i, '').trim();
|
|
156
|
+
const mcp = title.match(/^@([^/\s]+)\/(\S+)$/);
|
|
157
|
+
if (mcp) return `${mcp[1]} › ${mcp[2]}`;
|
|
158
|
+
if (!name) return title || 'tool';
|
|
159
|
+
if (!title || title === name) return name;
|
|
160
|
+
return `${name} › ${title}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* One `session/update` notification → a small event the adapter can act on.
|
|
165
|
+
*
|
|
166
|
+
* { kind: 'replay' } — history from session/load; ignore
|
|
167
|
+
* { kind: 'message', text } — reply/narration chunk
|
|
168
|
+
* { kind: 'thought', text } — reasoning chunk
|
|
169
|
+
* { kind: 'tool_start', id, label, toolKind, server }
|
|
170
|
+
* { kind: 'tool_end', id, failed, denied }
|
|
171
|
+
* { kind: 'plan', todos } — the agent's plan, workspace todo shape
|
|
172
|
+
* { kind: 'ignore' }
|
|
173
|
+
*/
|
|
174
|
+
function interpretUpdate(params, secrets = []) {
|
|
175
|
+
const update = (params && params.update) || {};
|
|
176
|
+
const meta = (update._meta && update._meta.kiro) || {};
|
|
177
|
+
if (meta.replay) return { kind: 'replay' };
|
|
178
|
+
|
|
179
|
+
switch (update.sessionUpdate) {
|
|
180
|
+
case 'agent_message_chunk':
|
|
181
|
+
return { kind: 'message', text: contentText(update.content) };
|
|
182
|
+
case 'agent_thought_chunk':
|
|
183
|
+
return { kind: 'thought', text: contentText(update.content) };
|
|
184
|
+
case 'tool_call': {
|
|
185
|
+
const label = redactSecrets(truncate(toolLabel(update, meta), 160), secrets);
|
|
186
|
+
return {
|
|
187
|
+
kind: 'tool_start',
|
|
188
|
+
id: update.toolCallId || null,
|
|
189
|
+
label,
|
|
190
|
+
toolKind: update.kind || 'other',
|
|
191
|
+
server: meta.mcpServerName || null,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
case 'tool_call_update': {
|
|
195
|
+
const status = update.status;
|
|
196
|
+
if (status !== 'completed' && status !== 'failed') return { kind: 'ignore' };
|
|
197
|
+
return {
|
|
198
|
+
kind: 'tool_end',
|
|
199
|
+
id: update.toolCallId || null,
|
|
200
|
+
failed: status === 'failed',
|
|
201
|
+
denied: meta.toolCallFailureReason === 'permission_denied',
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
case 'plan': {
|
|
205
|
+
const entries = Array.isArray(update.entries) ? update.entries : [];
|
|
206
|
+
const todos = entries
|
|
207
|
+
.map((e) => ({
|
|
208
|
+
content: redactSecrets(String((e && e.content) || '').trim(), secrets),
|
|
209
|
+
status: ['pending', 'in_progress', 'completed'].includes(e && e.status) ? e.status : 'pending',
|
|
210
|
+
}))
|
|
211
|
+
.filter((t) => t.content);
|
|
212
|
+
return { kind: 'plan', todos };
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
return { kind: 'ignore' };
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Answer a `session/request_permission`. In execute mode the agent runs
|
|
221
|
+
* headless, so every call is allowed once (never "always": that would
|
|
222
|
+
* persist trust into the user's Kiro settings). In plan mode only tools that
|
|
223
|
+
* change nothing, and the workspace's own tools, are allowed.
|
|
224
|
+
*
|
|
225
|
+
* Plan mode can only refuse tools Kiro asks permission for: tools in the
|
|
226
|
+
* profile's `allowedTools`, or that Kiro trusts by default, never reach this
|
|
227
|
+
* gate and bypass it — keep allowedTools empty/read-only for agents you use
|
|
228
|
+
* in plan mode.
|
|
229
|
+
*
|
|
230
|
+
* `known` is what the preceding tool_call said about this call
|
|
231
|
+
* ({ toolKind, server }), since the request itself may not repeat it.
|
|
232
|
+
*/
|
|
233
|
+
function permissionOutcome(params, { mode = 'execute', known = null } = {}) {
|
|
234
|
+
const options = (params && Array.isArray(params.options)) ? params.options : [];
|
|
235
|
+
const pick = (...kinds) => {
|
|
236
|
+
for (const k of kinds) {
|
|
237
|
+
const o = options.find((opt) => opt && opt.kind === k);
|
|
238
|
+
if (o) return o.optionId;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
};
|
|
242
|
+
const allowId = pick('allow_once', 'allow_always');
|
|
243
|
+
const rejectId = pick('reject_once', 'reject_always');
|
|
244
|
+
|
|
245
|
+
let allow = true;
|
|
246
|
+
if (mode === 'plan') {
|
|
247
|
+
const toolKind = (params && params.toolCall && params.toolCall.kind) || (known && known.toolKind) || 'other';
|
|
248
|
+
const server = known && known.server;
|
|
249
|
+
allow = READ_ONLY_KINDS.has(toolKind) || server === WORKSPACE_MCP_NAME;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const optionId = allow ? allowId : rejectId;
|
|
253
|
+
if (!optionId) return { outcome: { outcome: 'cancelled' } };
|
|
254
|
+
return { outcome: { outcome: 'selected', optionId } };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** True when a JSON-RPC error says the session id is unknown to the CLI. */
|
|
258
|
+
function isStaleSessionError(error) {
|
|
259
|
+
if (!error) return false;
|
|
260
|
+
const text = `${error.message || ''} ${typeof error.data === 'string' ? error.data : JSON.stringify(error.data || '')}`;
|
|
261
|
+
return /session not found|no session found/i.test(text);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Flatten a JSON-RPC error into one line of text for classification. */
|
|
265
|
+
function rpcErrorText(error) {
|
|
266
|
+
if (!error) return '';
|
|
267
|
+
if (typeof error === 'string') return error;
|
|
268
|
+
const data = typeof error.data === 'string' ? error.data : (error.data ? JSON.stringify(error.data) : '');
|
|
269
|
+
return [error.message, data].filter(Boolean).join(': ');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** What each failure kind should tell the user to do, in Kiro's terms. */
|
|
273
|
+
const KIRO_GUIDANCE = {
|
|
274
|
+
auth: 'Kiro CLI is not signed in on this machine. Run `kiro-cli login` (or `agn login kiro`), or set KIRO_API_KEY for this agent.',
|
|
275
|
+
quota: 'Kiro reported a usage or rate limit for this account. Wait and try again, or check your Kiro plan.',
|
|
276
|
+
model: 'Kiro rejected the requested model. Pick another one (`kiro-cli chat --list-models`) or clear the model for this agent.',
|
|
277
|
+
network: 'Kiro CLI could not reach its service from this device. Check the network or proxy.',
|
|
278
|
+
session: "Kiro could not resume this channel's previous session.",
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* A `--agent` profile the CLI could not find. Kiro does NOT fail on it: it
|
|
283
|
+
* announces `_kiro.dev/agent/not_found { requestedAgent, fallbackAgent }` and
|
|
284
|
+
* carries on as its default agent — without the profile's prompt, tools or
|
|
285
|
+
* MCP servers. The adapter refuses the turn instead of letting an agent run
|
|
286
|
+
* as someone else.
|
|
287
|
+
*/
|
|
288
|
+
function agentNotFoundMessage(params, fallbackAgent) {
|
|
289
|
+
const requested = (params && params.requestedAgent) || fallbackAgent || 'the configured agent';
|
|
290
|
+
return `Kiro agent profile "${requested}" was not found, so this turn was not run `
|
|
291
|
+
+ `(Kiro would have fallen back to "${(params && params.fallbackAgent) || 'its default agent'}", `
|
|
292
|
+
+ "without that profile's prompt, tools or MCP servers). Create it in "
|
|
293
|
+
+ `<working dir>/.kiro/agents/${requested}.json or ~/.kiro/agents, or clear KIRO_AGENT for this agent.`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
module.exports = {
|
|
297
|
+
KIRO_BINARY,
|
|
298
|
+
KIRO_MIN_VERSION,
|
|
299
|
+
ACP_PROTOCOL_VERSION,
|
|
300
|
+
WORKSPACE_MCP_NAME,
|
|
301
|
+
READ_ONLY_KINDS,
|
|
302
|
+
KIRO_GUIDANCE,
|
|
303
|
+
installHint,
|
|
304
|
+
parseKiroVersion,
|
|
305
|
+
compareVersions,
|
|
306
|
+
classifyKiroVersion,
|
|
307
|
+
resolveKiroSettings,
|
|
308
|
+
buildKiroArgs,
|
|
309
|
+
toAcpMcpServer,
|
|
310
|
+
contentText,
|
|
311
|
+
toolLabel,
|
|
312
|
+
truncate,
|
|
313
|
+
interpretUpdate,
|
|
314
|
+
permissionOutcome,
|
|
315
|
+
isStaleSessionError,
|
|
316
|
+
rpcErrorText,
|
|
317
|
+
agentNotFoundMessage,
|
|
318
|
+
};
|