opencara 0.105.0 → 0.105.1
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/dist/bin.js +37 -15
- package/dist/claude-acp.js +48 -27
- package/dist/opencara-mcp.js +8 -2
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -85,7 +85,8 @@ var AcpSpecSchema = z3.object({
|
|
|
85
85
|
systemPromptMd: z3.string(),
|
|
86
86
|
userPromptMd: z3.string(),
|
|
87
87
|
history: z3.array(AcpHistoryTurnSchema).default([]),
|
|
88
|
-
pageContextJson: z3.string().optional()
|
|
88
|
+
pageContextJson: z3.string().optional(),
|
|
89
|
+
priorSessionId: z3.string().optional()
|
|
89
90
|
});
|
|
90
91
|
var AgentSpecSchema = z3.object({
|
|
91
92
|
kind: z3.string(),
|
|
@@ -184,7 +185,12 @@ var RunDoneSchema = z4.object({
|
|
|
184
185
|
runId: z4.string(),
|
|
185
186
|
status: z4.enum(["succeeded", "failed", "cancelled"]),
|
|
186
187
|
exitCode: z4.number().int().nullable().optional(),
|
|
187
|
-
errorMessage: z4.string().optional()
|
|
188
|
+
errorMessage: z4.string().optional(),
|
|
189
|
+
/** ACP session id the agent ran under (fresh from session/new, or
|
|
190
|
+
* echoed from session/load). The orchestrator persists this per
|
|
191
|
+
* (repo, branch) so the next iteration can resume via session/load.
|
|
192
|
+
* Null/absent for non-ACP runs (worktree-allocate, write-session). */
|
|
193
|
+
acpSessionId: z4.string().nullable().optional()
|
|
188
194
|
});
|
|
189
195
|
var HelloAckSchema = z4.object({
|
|
190
196
|
type: z4.literal("hello-ack"),
|
|
@@ -561,6 +567,9 @@ var AcpConnection = class {
|
|
|
561
567
|
newSession(req) {
|
|
562
568
|
return this.request(ACP_METHODS.session_new, req);
|
|
563
569
|
}
|
|
570
|
+
loadSession(req) {
|
|
571
|
+
return this.request(ACP_METHODS.session_load, req);
|
|
572
|
+
}
|
|
564
573
|
prompt(req) {
|
|
565
574
|
return this.request(ACP_METHODS.session_prompt, req);
|
|
566
575
|
}
|
|
@@ -722,6 +731,9 @@ var AcpClient = class {
|
|
|
722
731
|
newSession(req) {
|
|
723
732
|
return this.must().newSession(req);
|
|
724
733
|
}
|
|
734
|
+
loadSession(req) {
|
|
735
|
+
return this.must().loadSession(req);
|
|
736
|
+
}
|
|
725
737
|
prompt(req) {
|
|
726
738
|
return this.must().prompt(req);
|
|
727
739
|
}
|
|
@@ -1065,26 +1077,35 @@ function runAcpJob(opts) {
|
|
|
1065
1077
|
}
|
|
1066
1078
|
};
|
|
1067
1079
|
const promise = (async () => {
|
|
1068
|
-
let result = { exitCode: 1, stopReason: "uninitialized" };
|
|
1080
|
+
let result = { exitCode: 1, stopReason: "uninitialized", sessionId: "" };
|
|
1069
1081
|
try {
|
|
1070
1082
|
await host.start();
|
|
1071
1083
|
client.start();
|
|
1072
|
-
await client.initialize({
|
|
1084
|
+
const initResult = await client.initialize({
|
|
1073
1085
|
protocolVersion: ACP_PROTOCOL_VERSION,
|
|
1074
1086
|
clientCapabilities: {}
|
|
1075
1087
|
});
|
|
1076
|
-
const
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1088
|
+
const cwd = spec.cwd ?? process.cwd();
|
|
1089
|
+
const mcpServers = [host.acpServerEntry()];
|
|
1090
|
+
const shimSupportsLoad = initResult.agentCapabilities?.loadSession === true;
|
|
1091
|
+
let sessionId;
|
|
1092
|
+
if (acpSpec.priorSessionId && shimSupportsLoad) {
|
|
1093
|
+
await client.loadSession({
|
|
1094
|
+
sessionId: acpSpec.priorSessionId,
|
|
1095
|
+
cwd,
|
|
1096
|
+
mcpServers
|
|
1097
|
+
});
|
|
1098
|
+
sessionId = acpSpec.priorSessionId;
|
|
1099
|
+
} else {
|
|
1100
|
+
const session = await client.newSession({ cwd, mcpServers });
|
|
1101
|
+
sessionId = session.sessionId;
|
|
1102
|
+
}
|
|
1080
1103
|
const prompt = buildPromptContent(acpSpec);
|
|
1081
|
-
const promptResult = await client.prompt({
|
|
1082
|
-
sessionId: session.sessionId,
|
|
1083
|
-
prompt
|
|
1084
|
-
});
|
|
1104
|
+
const promptResult = await client.prompt({ sessionId, prompt });
|
|
1085
1105
|
result = {
|
|
1086
1106
|
exitCode: promptResult.stopReason === "end_turn" ? 0 : 1,
|
|
1087
|
-
stopReason: promptResult.stopReason
|
|
1107
|
+
stopReason: promptResult.stopReason,
|
|
1108
|
+
sessionId
|
|
1088
1109
|
};
|
|
1089
1110
|
return result;
|
|
1090
1111
|
} finally {
|
|
@@ -1184,7 +1205,7 @@ function resolveLocalAcpAdapter(command, args) {
|
|
|
1184
1205
|
}
|
|
1185
1206
|
|
|
1186
1207
|
// src/commands/run.ts
|
|
1187
|
-
var PKG_VERSION = "0.105.
|
|
1208
|
+
var PKG_VERSION = "0.105.1";
|
|
1188
1209
|
var LOG_FLUSH_MS = 800;
|
|
1189
1210
|
var MAX_CHUNK_SIZE = 4 * 1024;
|
|
1190
1211
|
async function run(opts = {}) {
|
|
@@ -1286,7 +1307,8 @@ async function executeJob(job, client) {
|
|
|
1286
1307
|
type: "done",
|
|
1287
1308
|
runId,
|
|
1288
1309
|
status: result.exitCode === 0 ? "succeeded" : "failed",
|
|
1289
|
-
exitCode: result.exitCode
|
|
1310
|
+
exitCode: result.exitCode,
|
|
1311
|
+
acpSessionId: result.sessionId || null
|
|
1290
1312
|
});
|
|
1291
1313
|
console.log(
|
|
1292
1314
|
`[opencara] job ${runId.slice(-8)} (acp) \u2192 ${result.stopReason} exit=${result.exitCode}`
|
package/dist/claude-acp.js
CHANGED
|
@@ -74,23 +74,25 @@ async function runClaudeTurn(sessionId, state, promptText) {
|
|
|
74
74
|
"--include-partial-messages",
|
|
75
75
|
"--verbose",
|
|
76
76
|
"--session-id",
|
|
77
|
-
|
|
77
|
+
sessionId,
|
|
78
78
|
// Headless: no human in the loop to approve tool use. Matches the
|
|
79
79
|
// legacy `claudeAdapter` posture in agents/kinds.ts.
|
|
80
|
-
"--dangerously-skip-permissions"
|
|
81
|
-
promptText
|
|
80
|
+
"--dangerously-skip-permissions"
|
|
82
81
|
];
|
|
83
82
|
const child = spawn("claude", args, {
|
|
84
83
|
cwd: state.cwd,
|
|
85
84
|
env: process.env,
|
|
86
|
-
stdio: ["
|
|
85
|
+
stdio: ["pipe", "pipe", "pipe"]
|
|
86
|
+
});
|
|
87
|
+
child.stdin.on("error", () => {
|
|
87
88
|
});
|
|
88
|
-
|
|
89
|
+
child.stdin.end(promptText);
|
|
90
|
+
const decoder = new FrameDecoder();
|
|
89
91
|
let resolved = false;
|
|
90
92
|
let stopReason = "end_turn";
|
|
91
93
|
child.stdout.setEncoding("utf8");
|
|
92
94
|
child.stdout.on("data", (chunk) => {
|
|
93
|
-
const { messages, malformed } =
|
|
95
|
+
const { messages, malformed } = decoder.feed(chunk);
|
|
94
96
|
for (const line of malformed) {
|
|
95
97
|
stderr.write(`[claude-acp] malformed: ${line}
|
|
96
98
|
`);
|
|
@@ -189,10 +191,12 @@ function handleInitialize(_params) {
|
|
|
189
191
|
version: "0.0.1"
|
|
190
192
|
},
|
|
191
193
|
agentCapabilities: {
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
|
|
194
|
+
// Session resume works by passing the ACP sessionId back as
|
|
195
|
+
// `claude --session-id <uuid>` on the next prompt — Claude CLI
|
|
196
|
+
// replays its own JSONL internally. MCP via stdio is not yet
|
|
197
|
+
// propagated from ACP's mcpServers config (the `claude` CLI uses
|
|
198
|
+
// settings.json for that today; bridging is a separate change).
|
|
199
|
+
loadSession: true,
|
|
196
200
|
mcpCapabilities: {},
|
|
197
201
|
promptCapabilities: { embeddedContext: false, image: false, audio: false }
|
|
198
202
|
},
|
|
@@ -201,12 +205,16 @@ function handleInitialize(_params) {
|
|
|
201
205
|
}
|
|
202
206
|
function handleNewSession(params) {
|
|
203
207
|
const sessionId = randomUUID();
|
|
204
|
-
sessions.set(sessionId, {
|
|
205
|
-
claudeSessionId: randomUUID(),
|
|
206
|
-
cwd: params.cwd ?? process.cwd()
|
|
207
|
-
});
|
|
208
|
+
sessions.set(sessionId, { cwd: params.cwd ?? process.cwd() });
|
|
208
209
|
return { sessionId };
|
|
209
210
|
}
|
|
211
|
+
function handleLoadSession(params) {
|
|
212
|
+
if (typeof params.sessionId !== "string" || params.sessionId.length === 0) {
|
|
213
|
+
throw new Error("session/load: sessionId required");
|
|
214
|
+
}
|
|
215
|
+
sessions.set(params.sessionId, { cwd: params.cwd ?? process.cwd() });
|
|
216
|
+
return {};
|
|
217
|
+
}
|
|
210
218
|
async function handlePrompt(params) {
|
|
211
219
|
const state = sessions.get(params.sessionId);
|
|
212
220
|
if (!state) {
|
|
@@ -219,19 +227,22 @@ async function handlePrompt(params) {
|
|
|
219
227
|
const result = await runClaudeTurn(params.sessionId, state, promptText);
|
|
220
228
|
return { stopReason: result.stopReason };
|
|
221
229
|
}
|
|
222
|
-
var
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
230
|
+
var isMainModule = import.meta.url === `file://${process.argv[1]}` || process.argv[1]?.endsWith("claude-acp.ts") === true || process.argv[1]?.endsWith("claude-acp.js") === true;
|
|
231
|
+
if (isMainModule) {
|
|
232
|
+
const decoder = new FrameDecoder();
|
|
233
|
+
stdin.setEncoding("utf8");
|
|
234
|
+
stdin.on("data", (chunk) => {
|
|
235
|
+
const { messages, malformed } = decoder.feed(chunk);
|
|
236
|
+
for (const line of malformed) {
|
|
237
|
+
stderr.write(`[claude-acp] malformed inbound: ${line}
|
|
228
238
|
`);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
});
|
|
232
|
-
stdin.on("end", () => {
|
|
233
|
-
|
|
234
|
-
});
|
|
239
|
+
}
|
|
240
|
+
for (const msg of messages) void dispatch(msg);
|
|
241
|
+
});
|
|
242
|
+
stdin.on("end", () => {
|
|
243
|
+
exit(0);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
235
246
|
async function dispatch(msg) {
|
|
236
247
|
if (!("id" in msg) || msg.id == null) return;
|
|
237
248
|
if ("result" in msg || "error" in msg) return;
|
|
@@ -244,6 +255,9 @@ async function dispatch(msg) {
|
|
|
244
255
|
case "session/new":
|
|
245
256
|
reply(req.id, handleNewSession(req.params));
|
|
246
257
|
return;
|
|
258
|
+
case "session/load":
|
|
259
|
+
reply(req.id, handleLoadSession(req.params));
|
|
260
|
+
return;
|
|
247
261
|
case "session/prompt": {
|
|
248
262
|
const result = await handlePrompt(req.params);
|
|
249
263
|
reply(req.id, result);
|
|
@@ -258,10 +272,17 @@ async function dispatch(msg) {
|
|
|
258
272
|
}
|
|
259
273
|
} catch (err) {
|
|
260
274
|
const message = err instanceof Error ? err.message : String(err);
|
|
275
|
+
const isParamsError = err instanceof Error && (message.startsWith("session/prompt:") || message.startsWith("session/load:"));
|
|
261
276
|
replyError(
|
|
262
277
|
req.id,
|
|
263
|
-
|
|
278
|
+
isParamsError ? JSON_RPC_ERROR_INVALID_PARAMS : JSON_RPC_ERROR_INTERNAL,
|
|
264
279
|
message
|
|
265
280
|
);
|
|
266
281
|
}
|
|
267
282
|
}
|
|
283
|
+
export {
|
|
284
|
+
handleInitialize,
|
|
285
|
+
handleLoadSession,
|
|
286
|
+
handleNewSession,
|
|
287
|
+
sessions
|
|
288
|
+
};
|
package/dist/opencara-mcp.js
CHANGED
|
@@ -127,7 +127,8 @@ var AcpSpecSchema = z2.object({
|
|
|
127
127
|
systemPromptMd: z2.string(),
|
|
128
128
|
userPromptMd: z2.string(),
|
|
129
129
|
history: z2.array(AcpHistoryTurnSchema).default([]),
|
|
130
|
-
pageContextJson: z2.string().optional()
|
|
130
|
+
pageContextJson: z2.string().optional(),
|
|
131
|
+
priorSessionId: z2.string().optional()
|
|
131
132
|
});
|
|
132
133
|
var AgentSpecSchema = z2.object({
|
|
133
134
|
kind: z2.string(),
|
|
@@ -226,7 +227,12 @@ var RunDoneSchema = z3.object({
|
|
|
226
227
|
runId: z3.string(),
|
|
227
228
|
status: z3.enum(["succeeded", "failed", "cancelled"]),
|
|
228
229
|
exitCode: z3.number().int().nullable().optional(),
|
|
229
|
-
errorMessage: z3.string().optional()
|
|
230
|
+
errorMessage: z3.string().optional(),
|
|
231
|
+
/** ACP session id the agent ran under (fresh from session/new, or
|
|
232
|
+
* echoed from session/load). The orchestrator persists this per
|
|
233
|
+
* (repo, branch) so the next iteration can resume via session/load.
|
|
234
|
+
* Null/absent for non-ACP runs (worktree-allocate, write-session). */
|
|
235
|
+
acpSessionId: z3.string().nullable().optional()
|
|
230
236
|
});
|
|
231
237
|
var HelloAckSchema = z3.object({
|
|
232
238
|
type: z3.literal("hello-ack"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencara",
|
|
3
|
-
"version": "0.105.
|
|
3
|
+
"version": "0.105.1",
|
|
4
4
|
"description": "OpenCara agent-host CLI: register a machine as an agent host and run dispatched agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"dev": "tsx watch src/bin.ts",
|
|
39
39
|
"start": "node dist/bin.js",
|
|
40
40
|
"typecheck": "tsc -b",
|
|
41
|
-
"test": "node --import tsx --test --test-reporter=spec src/acp/__tests__/*.test.ts src/mcp/__tests__/*.test.ts src/runner/__tests__/*.test.ts",
|
|
41
|
+
"test": "node --import tsx --test --test-reporter=spec src/acp/__tests__/*.test.ts src/mcp/__tests__/*.test.ts src/runner/__tests__/*.test.ts src/bin/__tests__/*.test.ts",
|
|
42
42
|
"acp:spike": "tsx src/acp/spike.ts",
|
|
43
43
|
"mcp:smoke": "tsx src/mcp/smoke.ts",
|
|
44
44
|
"clean": "rm -rf dist *.tsbuildinfo"
|