@ycodium-ai/agent-opencode 0.2.2634 → 0.2.2658
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/index.js +360 -56
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -838,6 +838,9 @@ function isOpenCodeNotFound(cause) {
|
|
|
838
838
|
}
|
|
839
839
|
return false;
|
|
840
840
|
}
|
|
841
|
+
function isOpenCodeAbortError(error) {
|
|
842
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === "MessageAbortedError";
|
|
843
|
+
}
|
|
841
844
|
function openCodeRuntimeErrorDetail(cause) {
|
|
842
845
|
if (cause instanceof Error && cause.message.trim().length > 0) return cause.message.trim();
|
|
843
846
|
if (cause && typeof cause === "object") {
|
|
@@ -1182,6 +1185,11 @@ async function isSameOpenCodeDirectory(left, right) {
|
|
|
1182
1185
|
return await canonicalize(lexicalLeft) === await canonicalize(lexicalRight);
|
|
1183
1186
|
}
|
|
1184
1187
|
|
|
1188
|
+
// src/model.ts
|
|
1189
|
+
import {
|
|
1190
|
+
describeExecutorSpawnFailure
|
|
1191
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
1192
|
+
|
|
1185
1193
|
// src/slug.ts
|
|
1186
1194
|
function parseOpenCodeModelSlug(slug) {
|
|
1187
1195
|
if (typeof slug !== "string") {
|
|
@@ -1236,6 +1244,9 @@ function compareSemverVersions(left, right) {
|
|
|
1236
1244
|
return a[2] - b[2];
|
|
1237
1245
|
}
|
|
1238
1246
|
var MINIMUM_OPENCODE_VERSION = "1.14.19";
|
|
1247
|
+
function openCodeTooOldDetail(version) {
|
|
1248
|
+
return compareSemverVersions(version, MINIMUM_OPENCODE_VERSION) < 0 ? `OpenCode v${version} is older than the required v${MINIMUM_OPENCODE_VERSION}.` : void 0;
|
|
1249
|
+
}
|
|
1239
1250
|
|
|
1240
1251
|
// src/model.ts
|
|
1241
1252
|
function extractJsonObject(raw) {
|
|
@@ -1344,7 +1355,7 @@ function openCodeCapabilitiesForModel(input) {
|
|
|
1344
1355
|
...variantOptions.length > 0 ? [
|
|
1345
1356
|
{
|
|
1346
1357
|
id: "variant",
|
|
1347
|
-
label: "
|
|
1358
|
+
label: "Reasoning",
|
|
1348
1359
|
type: "select",
|
|
1349
1360
|
options: variantOptions,
|
|
1350
1361
|
...defaultVariant ? { currentValue: defaultVariant } : {}
|
|
@@ -1425,11 +1436,11 @@ function formatOpenCodeProbeError(input) {
|
|
|
1425
1436
|
...detail ? { detail } : {}
|
|
1426
1437
|
};
|
|
1427
1438
|
}
|
|
1428
|
-
if (lower.includes("enoent") || lower.includes("notfound")) {
|
|
1439
|
+
if (describeExecutorSpawnFailure(input.cause).readiness === "not-installed" || lower.includes("enoent") || lower.includes("notfound")) {
|
|
1429
1440
|
return {
|
|
1430
1441
|
installed: false,
|
|
1431
1442
|
version,
|
|
1432
|
-
readiness: "
|
|
1443
|
+
readiness: "not-installed",
|
|
1433
1444
|
auth: { status: "unknown" },
|
|
1434
1445
|
...detail ? { detail } : {}
|
|
1435
1446
|
};
|
|
@@ -1444,6 +1455,7 @@ function formatOpenCodeProbeError(input) {
|
|
|
1444
1455
|
}
|
|
1445
1456
|
|
|
1446
1457
|
// src/permission.ts
|
|
1458
|
+
var OPENCODE_ALLOW_ALL_NATIVE_MODE_ID = "allow-all";
|
|
1447
1459
|
var OPENCODE_NATIVE_MODES = [
|
|
1448
1460
|
{
|
|
1449
1461
|
id: "ask",
|
|
@@ -1456,7 +1468,7 @@ var OPENCODE_NATIVE_MODES = [
|
|
|
1456
1468
|
description: "Edits files without asking; still asks for commands and network access."
|
|
1457
1469
|
},
|
|
1458
1470
|
{
|
|
1459
|
-
id:
|
|
1471
|
+
id: OPENCODE_ALLOW_ALL_NATIVE_MODE_ID,
|
|
1460
1472
|
name: "Allow everything",
|
|
1461
1473
|
description: "Never asks. Every tool runs immediately."
|
|
1462
1474
|
}
|
|
@@ -1475,7 +1487,7 @@ function openCodeNativeModeFor(runtimeMode, nativeModeId) {
|
|
|
1475
1487
|
return nativeModeId !== void 0 && isOpenCodeNativeModeId(nativeModeId) ? nativeModeId : OPENCODE_NATIVE_MODE_BY_RUNTIME_MODE[runtimeMode];
|
|
1476
1488
|
}
|
|
1477
1489
|
function openCodePermissionRulesForNativeMode(nativeModeId, readOnlyDirectories) {
|
|
1478
|
-
if (nativeModeId ===
|
|
1490
|
+
if (nativeModeId === OPENCODE_ALLOW_ALL_NATIVE_MODE_ID) {
|
|
1479
1491
|
return buildOpenCodePermissionRules("full-access");
|
|
1480
1492
|
}
|
|
1481
1493
|
const base = buildOpenCodePermissionRules(
|
|
@@ -1523,6 +1535,17 @@ function buildOpenCodePermissionRules(runtimeMode) {
|
|
|
1523
1535
|
const editAction = runtimeMode === "auto-accept-edits" ? "allow" : "ask";
|
|
1524
1536
|
return [
|
|
1525
1537
|
{ permission: "*", pattern: "*", action: "ask" },
|
|
1538
|
+
// 会话规则压过 agent 自带的默认,所以只读查询与任务清单要显式放行;
|
|
1539
|
+
// .env 沿用 OpenCode 自己的询问规则,.env.example 不算。
|
|
1540
|
+
{ permission: "read", pattern: "*", action: "allow" },
|
|
1541
|
+
{ permission: "read", pattern: "*.env", action: "ask" },
|
|
1542
|
+
{ permission: "read", pattern: "*.env.*", action: "ask" },
|
|
1543
|
+
{ permission: "read", pattern: "*.env.example", action: "allow" },
|
|
1544
|
+
{ permission: "glob", pattern: "*", action: "allow" },
|
|
1545
|
+
{ permission: "grep", pattern: "*", action: "allow" },
|
|
1546
|
+
{ permission: "lsp", pattern: "*", action: "allow" },
|
|
1547
|
+
{ permission: "skill", pattern: "*", action: "allow" },
|
|
1548
|
+
{ permission: "todowrite", pattern: "*", action: "allow" },
|
|
1526
1549
|
{ permission: "bash", pattern: "*", action: "ask" },
|
|
1527
1550
|
{ permission: "edit", pattern: "*", action: editAction },
|
|
1528
1551
|
{ permission: "webfetch", pattern: "*", action: "ask" },
|
|
@@ -7305,6 +7328,20 @@ async function connectToOpenCodeServer(input) {
|
|
|
7305
7328
|
...input.onSpawn === void 0 ? {} : { onSpawn: input.onSpawn }
|
|
7306
7329
|
});
|
|
7307
7330
|
}
|
|
7331
|
+
var OPENCODE_HEALTH_TIMEOUT_MS = 5e3;
|
|
7332
|
+
async function readOpenCodeServerVersion(client2) {
|
|
7333
|
+
const response = await client2.global.health({
|
|
7334
|
+
signal: AbortSignal.timeout(OPENCODE_HEALTH_TIMEOUT_MS)
|
|
7335
|
+
});
|
|
7336
|
+
const raw = response.data?.version;
|
|
7337
|
+
const version = typeof raw === "string" ? parseGenericCliVersion(raw) : null;
|
|
7338
|
+
if (version === null) {
|
|
7339
|
+
throw new Error(
|
|
7340
|
+
`OpenCode server returned an invalid version. Ycodium requires OpenCode v${MINIMUM_OPENCODE_VERSION} or newer.`
|
|
7341
|
+
);
|
|
7342
|
+
}
|
|
7343
|
+
return version;
|
|
7344
|
+
}
|
|
7308
7345
|
async function closeOpenCodeServer(handle) {
|
|
7309
7346
|
if (handle.external || !handle.process) return;
|
|
7310
7347
|
await terminateOwnedProcess(handle.process);
|
|
@@ -7505,7 +7542,7 @@ async function probeOpenCode(input) {
|
|
|
7505
7542
|
return {
|
|
7506
7543
|
installed: false,
|
|
7507
7544
|
version: null,
|
|
7508
|
-
readiness: "
|
|
7545
|
+
readiness: "not-installed",
|
|
7509
7546
|
auth: { status: "unknown" },
|
|
7510
7547
|
detail: "OpenCode program path is not configured"
|
|
7511
7548
|
};
|
|
@@ -7522,13 +7559,14 @@ async function probeOpenCode(input) {
|
|
|
7522
7559
|
});
|
|
7523
7560
|
version = parseGenericCliVersion(`${result.stdout}
|
|
7524
7561
|
${result.stderr}`);
|
|
7525
|
-
|
|
7562
|
+
const tooOld = version ? openCodeTooOldDetail(version) : void 0;
|
|
7563
|
+
if (version && tooOld) {
|
|
7526
7564
|
return {
|
|
7527
7565
|
installed: true,
|
|
7528
7566
|
version,
|
|
7529
7567
|
readiness: "error",
|
|
7530
7568
|
auth: { status: "unknown" },
|
|
7531
|
-
detail:
|
|
7569
|
+
detail: tooOld,
|
|
7532
7570
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7533
7571
|
};
|
|
7534
7572
|
}
|
|
@@ -7550,6 +7588,18 @@ ${result.stderr}`);
|
|
|
7550
7588
|
directory: ".",
|
|
7551
7589
|
password: handle.password
|
|
7552
7590
|
});
|
|
7591
|
+
version = await readOpenCodeServerVersion(client2);
|
|
7592
|
+
const tooOld = openCodeTooOldDetail(version);
|
|
7593
|
+
if (tooOld) {
|
|
7594
|
+
return {
|
|
7595
|
+
installed: true,
|
|
7596
|
+
version,
|
|
7597
|
+
readiness: "error",
|
|
7598
|
+
auth: { status: "unknown" },
|
|
7599
|
+
detail: tooOld,
|
|
7600
|
+
...OPENCODE_NATIVE_MODE_REPORT
|
|
7601
|
+
};
|
|
7602
|
+
}
|
|
7553
7603
|
const skillsClient = createOpenCodeSdkClient({
|
|
7554
7604
|
url: handle.url,
|
|
7555
7605
|
directory: NodeOS4.homedir(),
|
|
@@ -7684,6 +7734,9 @@ function appendOpenCodeAssistantTextDelta(previousText, delta) {
|
|
|
7684
7734
|
// src/toolClassify.ts
|
|
7685
7735
|
function toToolLifecycleItemType(toolName) {
|
|
7686
7736
|
const normalized = toolName.toLowerCase();
|
|
7737
|
+
if (normalized === "todowrite" || normalized === "todoread") {
|
|
7738
|
+
return "dynamic_tool_call";
|
|
7739
|
+
}
|
|
7687
7740
|
if (normalized.includes("bash") || normalized.includes("command")) {
|
|
7688
7741
|
return "command_execution";
|
|
7689
7742
|
}
|
|
@@ -7958,14 +8011,237 @@ function completeActiveTurn(events, context, state, extra) {
|
|
|
7958
8011
|
};
|
|
7959
8012
|
return usage;
|
|
7960
8013
|
}
|
|
8014
|
+
var OPENCODE_REQUEST_TIMEOUT_MS = 1e4;
|
|
8015
|
+
var OPENCODE_SESSION_ANCESTRY_MAX_DEPTH = 32;
|
|
8016
|
+
async function autoReplyPermissionOnce(context, requestId) {
|
|
8017
|
+
context.autoRepliedRequestIds.add(requestId);
|
|
8018
|
+
try {
|
|
8019
|
+
await context.client.permission.reply(
|
|
8020
|
+
{ requestID: requestId, directory: context.directory, reply: "once" },
|
|
8021
|
+
{ signal: AbortSignal.timeout(OPENCODE_REQUEST_TIMEOUT_MS) }
|
|
8022
|
+
);
|
|
8023
|
+
return true;
|
|
8024
|
+
} catch {
|
|
8025
|
+
context.autoRepliedRequestIds.delete(requestId);
|
|
8026
|
+
return false;
|
|
8027
|
+
}
|
|
8028
|
+
}
|
|
8029
|
+
async function openPermissionRequest(events, context, permission) {
|
|
8030
|
+
if (context.pendingPermissions.has(permission.id) || context.settledRequestIds.has(permission.id) || context.autoRepliedRequestIds.has(permission.id)) {
|
|
8031
|
+
return;
|
|
8032
|
+
}
|
|
8033
|
+
if (context.session.nativeModeId === OPENCODE_ALLOW_ALL_NATIVE_MODE_ID && await autoReplyPermissionOnce(context, permission.id)) {
|
|
8034
|
+
return;
|
|
8035
|
+
}
|
|
8036
|
+
if (context.settledRequestIds.has(permission.id)) return;
|
|
8037
|
+
context.pendingPermissions.set(permission.id, permission);
|
|
8038
|
+
emitEvent(events, context, "request.opened", toOpenCodeRequestOpenedPayload(permission), {
|
|
8039
|
+
requestId: permission.id
|
|
8040
|
+
});
|
|
8041
|
+
context.session = { ...context.session, status: "waiting", updatedAt: nowIso() };
|
|
8042
|
+
emitEvent(events, context, "session.state.changed", { state: "waiting" });
|
|
8043
|
+
}
|
|
8044
|
+
function resolvePermissionRequest(events, context, requestId, reply) {
|
|
8045
|
+
context.settledRequestIds.add(requestId);
|
|
8046
|
+
if (context.autoRepliedRequestIds.delete(requestId)) return;
|
|
8047
|
+
const pending = context.pendingPermissions.get(requestId);
|
|
8048
|
+
context.pendingPermissions.delete(requestId);
|
|
8049
|
+
const reason = context.declineReasons.get(requestId);
|
|
8050
|
+
context.declineReasons.delete(requestId);
|
|
8051
|
+
emitEvent(
|
|
8052
|
+
events,
|
|
8053
|
+
context,
|
|
8054
|
+
"request.resolved",
|
|
8055
|
+
{
|
|
8056
|
+
requestType: pending ? mapPermissionToRequestType(pending.permission) : "unknown",
|
|
8057
|
+
decision: mapPermissionDecision(reply),
|
|
8058
|
+
...reason ? { reason } : {}
|
|
8059
|
+
},
|
|
8060
|
+
{ requestId }
|
|
8061
|
+
);
|
|
8062
|
+
}
|
|
8063
|
+
function openQuestionRequest(events, context, request) {
|
|
8064
|
+
if (context.pendingQuestions.has(request.id) || context.settledRequestIds.has(request.id)) return;
|
|
8065
|
+
context.pendingQuestions.set(request.id, request);
|
|
8066
|
+
emitEvent(
|
|
8067
|
+
events,
|
|
8068
|
+
context,
|
|
8069
|
+
"user-input.requested",
|
|
8070
|
+
{ questions: normalizeQuestionRequest(request) },
|
|
8071
|
+
{ requestId: request.id }
|
|
8072
|
+
);
|
|
8073
|
+
context.session = { ...context.session, status: "waiting", updatedAt: nowIso() };
|
|
8074
|
+
emitEvent(events, context, "session.state.changed", { state: "waiting" });
|
|
8075
|
+
}
|
|
8076
|
+
function resolveQuestionRequest(events, context, requestId, answers) {
|
|
8077
|
+
context.settledRequestIds.add(requestId);
|
|
8078
|
+
context.pendingQuestions.delete(requestId);
|
|
8079
|
+
emitEvent(events, context, "user-input.resolved", { answers }, { requestId });
|
|
8080
|
+
}
|
|
8081
|
+
async function isRelatedSession(context, candidateId) {
|
|
8082
|
+
if (candidateId === context.sessionId || context.relatedSessionIds.has(candidateId)) return true;
|
|
8083
|
+
if (context.unrelatedSessionIds.has(candidateId)) return false;
|
|
8084
|
+
const chain = [];
|
|
8085
|
+
let current = candidateId;
|
|
8086
|
+
for (let depth = 0; depth < OPENCODE_SESSION_ANCESTRY_MAX_DEPTH; depth += 1) {
|
|
8087
|
+
if (current === void 0) {
|
|
8088
|
+
for (const id of chain) context.unrelatedSessionIds.add(id);
|
|
8089
|
+
return false;
|
|
8090
|
+
}
|
|
8091
|
+
if (current === context.sessionId || context.relatedSessionIds.has(current)) {
|
|
8092
|
+
for (const id of chain) context.relatedSessionIds.add(id);
|
|
8093
|
+
return true;
|
|
8094
|
+
}
|
|
8095
|
+
if (context.unrelatedSessionIds.has(current)) {
|
|
8096
|
+
for (const id of chain) context.unrelatedSessionIds.add(id);
|
|
8097
|
+
return false;
|
|
8098
|
+
}
|
|
8099
|
+
chain.push(current);
|
|
8100
|
+
const sessionID = current;
|
|
8101
|
+
try {
|
|
8102
|
+
const fetched = await context.client.session.get(
|
|
8103
|
+
{ sessionID, directory: context.directory },
|
|
8104
|
+
{ signal: AbortSignal.timeout(OPENCODE_REQUEST_TIMEOUT_MS) }
|
|
8105
|
+
);
|
|
8106
|
+
current = fetched.data?.parentID;
|
|
8107
|
+
} catch (cause) {
|
|
8108
|
+
if (isOpenCodeNotFound(cause)) return false;
|
|
8109
|
+
throw cause;
|
|
8110
|
+
}
|
|
8111
|
+
}
|
|
8112
|
+
return false;
|
|
8113
|
+
}
|
|
8114
|
+
async function routeRequestBySession(events, context, sessionId, open) {
|
|
8115
|
+
let related;
|
|
8116
|
+
try {
|
|
8117
|
+
related = await isRelatedSession(context, sessionId);
|
|
8118
|
+
} catch (cause) {
|
|
8119
|
+
emitEvent(events, context, "runtime.warning", {
|
|
8120
|
+
message: "OpenCode could not confirm which session a request belongs to.",
|
|
8121
|
+
detail: openCodeRuntimeErrorDetail(cause)
|
|
8122
|
+
});
|
|
8123
|
+
return;
|
|
8124
|
+
}
|
|
8125
|
+
if (related) await open();
|
|
8126
|
+
}
|
|
8127
|
+
async function recoverPendingRequests(events, context) {
|
|
8128
|
+
let permissions;
|
|
8129
|
+
let questions;
|
|
8130
|
+
try {
|
|
8131
|
+
const [listedPermissions, listedQuestions] = await Promise.all([
|
|
8132
|
+
context.client.permission.list(
|
|
8133
|
+
{ directory: context.directory },
|
|
8134
|
+
{ signal: AbortSignal.timeout(OPENCODE_REQUEST_TIMEOUT_MS) }
|
|
8135
|
+
),
|
|
8136
|
+
context.client.question.list(
|
|
8137
|
+
{ directory: context.directory },
|
|
8138
|
+
{ signal: AbortSignal.timeout(OPENCODE_REQUEST_TIMEOUT_MS) }
|
|
8139
|
+
)
|
|
8140
|
+
]);
|
|
8141
|
+
permissions = listedPermissions.data ?? [];
|
|
8142
|
+
questions = listedQuestions.data ?? [];
|
|
8143
|
+
} catch (cause) {
|
|
8144
|
+
emitEvent(events, context, "runtime.warning", {
|
|
8145
|
+
message: "OpenCode could not list pending requests after reconnecting.",
|
|
8146
|
+
detail: openCodeRuntimeErrorDetail(cause)
|
|
8147
|
+
});
|
|
8148
|
+
return;
|
|
8149
|
+
}
|
|
8150
|
+
for (const request of permissions) {
|
|
8151
|
+
await routeRequestBySession(
|
|
8152
|
+
events,
|
|
8153
|
+
context,
|
|
8154
|
+
request.sessionID,
|
|
8155
|
+
() => openPermissionRequest(events, context, request)
|
|
8156
|
+
);
|
|
8157
|
+
}
|
|
8158
|
+
for (const request of questions) {
|
|
8159
|
+
await routeRequestBySession(
|
|
8160
|
+
events,
|
|
8161
|
+
context,
|
|
8162
|
+
request.sessionID,
|
|
8163
|
+
() => openQuestionRequest(events, context, request)
|
|
8164
|
+
);
|
|
8165
|
+
}
|
|
8166
|
+
}
|
|
8167
|
+
async function handleOtherSessionEvent(input) {
|
|
8168
|
+
const { events, context, event } = input;
|
|
8169
|
+
switch (event.type) {
|
|
8170
|
+
case "session.created":
|
|
8171
|
+
case "session.updated": {
|
|
8172
|
+
const info = event.properties.info;
|
|
8173
|
+
if (info.parentID !== void 0 && (info.parentID === context.sessionId || context.relatedSessionIds.has(info.parentID))) {
|
|
8174
|
+
context.relatedSessionIds.add(info.id);
|
|
8175
|
+
}
|
|
8176
|
+
return;
|
|
8177
|
+
}
|
|
8178
|
+
case "session.deleted": {
|
|
8179
|
+
context.relatedSessionIds.delete(event.properties.info.id);
|
|
8180
|
+
context.unrelatedSessionIds.delete(event.properties.info.id);
|
|
8181
|
+
return;
|
|
8182
|
+
}
|
|
8183
|
+
case "permission.asked": {
|
|
8184
|
+
const permission = event.properties;
|
|
8185
|
+
await routeRequestBySession(
|
|
8186
|
+
events,
|
|
8187
|
+
context,
|
|
8188
|
+
permission.sessionID,
|
|
8189
|
+
() => openPermissionRequest(events, context, permission)
|
|
8190
|
+
);
|
|
8191
|
+
return;
|
|
8192
|
+
}
|
|
8193
|
+
case "question.asked": {
|
|
8194
|
+
const request = event.properties;
|
|
8195
|
+
await routeRequestBySession(
|
|
8196
|
+
events,
|
|
8197
|
+
context,
|
|
8198
|
+
request.sessionID,
|
|
8199
|
+
() => openQuestionRequest(events, context, request)
|
|
8200
|
+
);
|
|
8201
|
+
return;
|
|
8202
|
+
}
|
|
8203
|
+
case "permission.replied": {
|
|
8204
|
+
if (context.pendingPermissions.has(event.properties.requestID)) {
|
|
8205
|
+
resolvePermissionRequest(
|
|
8206
|
+
events,
|
|
8207
|
+
context,
|
|
8208
|
+
event.properties.requestID,
|
|
8209
|
+
event.properties.reply
|
|
8210
|
+
);
|
|
8211
|
+
}
|
|
8212
|
+
return;
|
|
8213
|
+
}
|
|
8214
|
+
case "question.replied":
|
|
8215
|
+
case "question.rejected": {
|
|
8216
|
+
if (context.pendingQuestions.has(event.properties.requestID)) {
|
|
8217
|
+
resolveQuestionRequest(
|
|
8218
|
+
events,
|
|
8219
|
+
context,
|
|
8220
|
+
event.properties.requestID,
|
|
8221
|
+
event.type === "question.replied" ? { answers: event.properties.answers } : { rejected: true }
|
|
8222
|
+
);
|
|
8223
|
+
}
|
|
8224
|
+
return;
|
|
8225
|
+
}
|
|
8226
|
+
default:
|
|
8227
|
+
return;
|
|
8228
|
+
}
|
|
8229
|
+
}
|
|
7961
8230
|
async function handleSubscribedEvent(input) {
|
|
7962
8231
|
const { events, context, event } = input;
|
|
7963
8232
|
void input.declineRelay;
|
|
7964
8233
|
const sessionId = openCodeEventSessionId(event);
|
|
7965
8234
|
if (sessionId !== void 0 && sessionId !== context.sessionId) {
|
|
8235
|
+
await handleOtherSessionEvent({ events, context, event });
|
|
7966
8236
|
return;
|
|
7967
8237
|
}
|
|
7968
8238
|
switch (event.type) {
|
|
8239
|
+
case "server.connected": {
|
|
8240
|
+
const reconnected = context.eventStreamConnected;
|
|
8241
|
+
context.eventStreamConnected = true;
|
|
8242
|
+
if (reconnected) await recoverPendingRequests(events, context);
|
|
8243
|
+
return;
|
|
8244
|
+
}
|
|
7969
8245
|
case "session.updated": {
|
|
7970
8246
|
const title = event.properties.info.title;
|
|
7971
8247
|
if (typeof title === "string" && title.trim().length > 0 && !isOpenCodeDefaultTitle(title)) {
|
|
@@ -8028,63 +8304,38 @@ async function handleSubscribedEvent(input) {
|
|
|
8028
8304
|
return;
|
|
8029
8305
|
}
|
|
8030
8306
|
case "permission.asked": {
|
|
8031
|
-
|
|
8032
|
-
context.pendingPermissions.set(permission.id, permission);
|
|
8033
|
-
emitEvent(events, context, "request.opened", toOpenCodeRequestOpenedPayload(permission), {
|
|
8034
|
-
requestId: permission.id
|
|
8035
|
-
});
|
|
8036
|
-
context.session = { ...context.session, status: "waiting", updatedAt: nowIso() };
|
|
8037
|
-
emitEvent(events, context, "session.state.changed", { state: "waiting" });
|
|
8307
|
+
await openPermissionRequest(events, context, event.properties);
|
|
8038
8308
|
return;
|
|
8039
8309
|
}
|
|
8040
8310
|
case "permission.replied": {
|
|
8041
|
-
|
|
8042
|
-
const pending = context.pendingPermissions.get(requestId);
|
|
8043
|
-
context.pendingPermissions.delete(requestId);
|
|
8044
|
-
const reason = context.declineReasons.get(requestId);
|
|
8045
|
-
context.declineReasons.delete(requestId);
|
|
8046
|
-
emitEvent(
|
|
8047
|
-
events,
|
|
8048
|
-
context,
|
|
8049
|
-
"request.resolved",
|
|
8050
|
-
{
|
|
8051
|
-
requestType: pending ? mapPermissionToRequestType(pending.permission) : "unknown",
|
|
8052
|
-
decision: mapPermissionDecision(event.properties.reply),
|
|
8053
|
-
...reason ? { reason } : {}
|
|
8054
|
-
},
|
|
8055
|
-
{ requestId }
|
|
8056
|
-
);
|
|
8311
|
+
resolvePermissionRequest(events, context, event.properties.requestID, event.properties.reply);
|
|
8057
8312
|
return;
|
|
8058
8313
|
}
|
|
8059
8314
|
case "question.asked": {
|
|
8060
|
-
|
|
8061
|
-
context.pendingQuestions.set(request.id, request);
|
|
8062
|
-
emitEvent(
|
|
8063
|
-
events,
|
|
8064
|
-
context,
|
|
8065
|
-
"user-input.requested",
|
|
8066
|
-
{ questions: normalizeQuestionRequest(request) },
|
|
8067
|
-
{ requestId: request.id }
|
|
8068
|
-
);
|
|
8069
|
-
context.session = { ...context.session, status: "waiting", updatedAt: nowIso() };
|
|
8070
|
-
emitEvent(events, context, "session.state.changed", { state: "waiting" });
|
|
8315
|
+
openQuestionRequest(events, context, event.properties);
|
|
8071
8316
|
return;
|
|
8072
8317
|
}
|
|
8073
8318
|
case "question.replied":
|
|
8074
8319
|
case "question.rejected": {
|
|
8075
|
-
|
|
8076
|
-
context.pendingQuestions.delete(requestId);
|
|
8077
|
-
emitEvent(
|
|
8320
|
+
resolveQuestionRequest(
|
|
8078
8321
|
events,
|
|
8079
8322
|
context,
|
|
8080
|
-
|
|
8081
|
-
{
|
|
8082
|
-
answers: event.type === "question.replied" ? { answers: event.properties.answers } : { rejected: true }
|
|
8083
|
-
},
|
|
8084
|
-
{ requestId }
|
|
8323
|
+
event.properties.requestID,
|
|
8324
|
+
event.type === "question.replied" ? { answers: event.properties.answers } : { rejected: true }
|
|
8085
8325
|
);
|
|
8086
8326
|
return;
|
|
8087
8327
|
}
|
|
8328
|
+
case "todo.updated": {
|
|
8329
|
+
const turnId = context.session.activeTurnId;
|
|
8330
|
+
if (turnId === void 0) return;
|
|
8331
|
+
const plan = event.properties.todos.filter((todo) => todo.status !== "cancelled").map((todo) => ({
|
|
8332
|
+
step: (typeof todo.content === "string" ? todo.content.trim() : "") || "Task",
|
|
8333
|
+
status: todo.status === "completed" ? "completed" : todo.status === "in_progress" ? "inProgress" : "pending"
|
|
8334
|
+
}));
|
|
8335
|
+
if (plan.length === 0) return;
|
|
8336
|
+
emitEvent(events, context, "turn.plan.updated", { plan }, { turnId });
|
|
8337
|
+
return;
|
|
8338
|
+
}
|
|
8088
8339
|
case "session.next.compaction.started": {
|
|
8089
8340
|
context.compaction = {
|
|
8090
8341
|
compactionId: randomUUID(),
|
|
@@ -8135,6 +8386,10 @@ async function handleSubscribedEvent(input) {
|
|
|
8135
8386
|
return;
|
|
8136
8387
|
}
|
|
8137
8388
|
case "session.error": {
|
|
8389
|
+
if (isOpenCodeAbortError(event.properties.error)) {
|
|
8390
|
+
completeActiveTurn(events, context, "interrupted");
|
|
8391
|
+
return;
|
|
8392
|
+
}
|
|
8138
8393
|
const message = sessionErrorMessage(event.properties.error);
|
|
8139
8394
|
completeActiveTurn(events, context, "failed", { errorMessage: message });
|
|
8140
8395
|
emitEvent(events, context, "runtime.error", {
|
|
@@ -8197,6 +8452,44 @@ function startEventPump(input) {
|
|
|
8197
8452
|
}
|
|
8198
8453
|
}
|
|
8199
8454
|
|
|
8455
|
+
// src/sessionTree.ts
|
|
8456
|
+
var OPENCODE_ABORT_REQUEST_TIMEOUT_MS = 1e4;
|
|
8457
|
+
async function abortOpenCodeSessionTree(input) {
|
|
8458
|
+
const { client: client2, directory, rootSessionId } = input;
|
|
8459
|
+
const abort = (sessionID) => client2.session.abort(
|
|
8460
|
+
{ sessionID, directory },
|
|
8461
|
+
{ signal: AbortSignal.timeout(OPENCODE_ABORT_REQUEST_TIMEOUT_MS) }
|
|
8462
|
+
);
|
|
8463
|
+
await abort(rootSessionId);
|
|
8464
|
+
let firstFailure;
|
|
8465
|
+
const visited = /* @__PURE__ */ new Set([rootSessionId]);
|
|
8466
|
+
const queue = [rootSessionId];
|
|
8467
|
+
for (let parentId = queue.shift(); parentId !== void 0; parentId = queue.shift()) {
|
|
8468
|
+
let children;
|
|
8469
|
+
try {
|
|
8470
|
+
const listed = await client2.session.children(
|
|
8471
|
+
{ sessionID: parentId, directory },
|
|
8472
|
+
{ signal: AbortSignal.timeout(OPENCODE_ABORT_REQUEST_TIMEOUT_MS) }
|
|
8473
|
+
);
|
|
8474
|
+
children = listed.data ?? [];
|
|
8475
|
+
} catch (cause) {
|
|
8476
|
+
if (!isOpenCodeNotFound(cause)) firstFailure ??= cause;
|
|
8477
|
+
continue;
|
|
8478
|
+
}
|
|
8479
|
+
for (const child of children) {
|
|
8480
|
+
if (visited.has(child.id)) continue;
|
|
8481
|
+
visited.add(child.id);
|
|
8482
|
+
queue.push(child.id);
|
|
8483
|
+
try {
|
|
8484
|
+
await abort(child.id);
|
|
8485
|
+
} catch (cause) {
|
|
8486
|
+
if (!isOpenCodeNotFound(cause)) firstFailure ??= cause;
|
|
8487
|
+
}
|
|
8488
|
+
}
|
|
8489
|
+
}
|
|
8490
|
+
if (firstFailure !== void 0) throw firstFailure;
|
|
8491
|
+
}
|
|
8492
|
+
|
|
8200
8493
|
// src/textGeneration.ts
|
|
8201
8494
|
import {
|
|
8202
8495
|
createCatalogModelMatcher
|
|
@@ -8940,9 +9233,10 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8940
9233
|
context.stopped = true;
|
|
8941
9234
|
context.eventAbort.abort();
|
|
8942
9235
|
try {
|
|
8943
|
-
await
|
|
8944
|
-
|
|
8945
|
-
directory: context.directory
|
|
9236
|
+
await abortOpenCodeSessionTree({
|
|
9237
|
+
client: context.client,
|
|
9238
|
+
directory: context.directory,
|
|
9239
|
+
rootSessionId: context.sessionId
|
|
8946
9240
|
});
|
|
8947
9241
|
} catch {
|
|
8948
9242
|
}
|
|
@@ -9001,6 +9295,10 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9001
9295
|
directory,
|
|
9002
9296
|
password: server.password
|
|
9003
9297
|
});
|
|
9298
|
+
if (server.external) {
|
|
9299
|
+
const tooOld = openCodeTooOldDetail(await readOpenCodeServerVersion(client2));
|
|
9300
|
+
if (tooOld) throw new Error(tooOld);
|
|
9301
|
+
}
|
|
9004
9302
|
const nativeModeId = openCodeNativeModeFor(input.runtimeMode, input.nativeModeId);
|
|
9005
9303
|
const permission = openCodePermissionRulesForNativeMode(
|
|
9006
9304
|
nativeModeId,
|
|
@@ -9104,6 +9402,11 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9104
9402
|
stopped: false,
|
|
9105
9403
|
pendingPermissions: /* @__PURE__ */ new Map(),
|
|
9106
9404
|
pendingQuestions: /* @__PURE__ */ new Map(),
|
|
9405
|
+
settledRequestIds: /* @__PURE__ */ new Set(),
|
|
9406
|
+
autoRepliedRequestIds: /* @__PURE__ */ new Set(),
|
|
9407
|
+
relatedSessionIds: /* @__PURE__ */ new Set(),
|
|
9408
|
+
unrelatedSessionIds: /* @__PURE__ */ new Set(),
|
|
9409
|
+
eventStreamConnected: false,
|
|
9107
9410
|
declineReasons: /* @__PURE__ */ new Map(),
|
|
9108
9411
|
usageByMessageId: /* @__PURE__ */ new Map(),
|
|
9109
9412
|
messageRoleById: /* @__PURE__ */ new Map(),
|
|
@@ -9232,9 +9535,10 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9232
9535
|
if (turnId !== void 0 && context.session.activeTurnId !== turnId) {
|
|
9233
9536
|
return;
|
|
9234
9537
|
}
|
|
9235
|
-
await
|
|
9236
|
-
|
|
9237
|
-
directory: context.directory
|
|
9538
|
+
await abortOpenCodeSessionTree({
|
|
9539
|
+
client: context.client,
|
|
9540
|
+
directory: context.directory,
|
|
9541
|
+
rootSessionId: context.sessionId
|
|
9238
9542
|
});
|
|
9239
9543
|
const active = context.session.activeTurnId;
|
|
9240
9544
|
if (active && (turnId === void 0 || turnId === active)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-opencode",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2658",
|
|
4
4
|
"description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"@types/node": "24.12.4",
|
|
25
25
|
"esbuild": "0.28.1",
|
|
26
26
|
"vite-plus": "0.2.2",
|
|
27
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
27
|
+
"@ycodium-ai/plugin-api": "0.2.2658",
|
|
28
28
|
"ycodium-executor-testing": "0.0.0"
|
|
29
29
|
},
|
|
30
30
|
"ycodium": {
|