@khalilgharbaoui/opencode-claude-code-plugin 0.26.0 → 0.26.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/index.js +64 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4088,6 +4088,39 @@ async function fetchSessionParentId(sessionID) {
|
|
|
4088
4088
|
return void 0;
|
|
4089
4089
|
}
|
|
4090
4090
|
}
|
|
4091
|
+
async function fetchSessionRunState(sessionID) {
|
|
4092
|
+
if (!sessionID || sessionID === "default") return "unknown";
|
|
4093
|
+
const status = opencodeClient?.session?.status;
|
|
4094
|
+
if (!status) return "unknown";
|
|
4095
|
+
try {
|
|
4096
|
+
const res = await status.call(opencodeClient.session);
|
|
4097
|
+
const data = res.data;
|
|
4098
|
+
if (!data || typeof data !== "object") return "unknown";
|
|
4099
|
+
const entry = data[sessionID];
|
|
4100
|
+
if (!entry || typeof entry !== "object") return "idle";
|
|
4101
|
+
const type = entry.type;
|
|
4102
|
+
return type === "idle" ? "idle" : "busy";
|
|
4103
|
+
} catch (err) {
|
|
4104
|
+
log.debug("failed to read opencode session status", {
|
|
4105
|
+
sessionID,
|
|
4106
|
+
error: err instanceof Error ? err.message : String(err)
|
|
4107
|
+
});
|
|
4108
|
+
return "unknown";
|
|
4109
|
+
}
|
|
4110
|
+
}
|
|
4111
|
+
async function settleSessionRunState(sessionID, options = {}) {
|
|
4112
|
+
const pollMs = options.pollMs ?? 150;
|
|
4113
|
+
const windowMs = options.windowMs ?? 1500;
|
|
4114
|
+
const started = Date.now();
|
|
4115
|
+
let last = "unknown";
|
|
4116
|
+
for (; ; ) {
|
|
4117
|
+
const state = await fetchSessionRunState(sessionID);
|
|
4118
|
+
if (state === "busy") return "busy";
|
|
4119
|
+
if (state !== "unknown") last = state;
|
|
4120
|
+
if (Date.now() - started >= windowMs) return last;
|
|
4121
|
+
await new Promise((resolve5) => setTimeout(resolve5, pollMs));
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4091
4124
|
async function getRuntimeMcpStatus() {
|
|
4092
4125
|
const client = opencodeClient;
|
|
4093
4126
|
if (!client?.mcp?.status) return void 0;
|
|
@@ -6205,6 +6238,16 @@ function resolveOpencodeAgent(headers, providerOptions, providerKey) {
|
|
|
6205
6238
|
}
|
|
6206
6239
|
return void 0;
|
|
6207
6240
|
}
|
|
6241
|
+
function describeAbortReason(reason) {
|
|
6242
|
+
if (reason === void 0) return "undefined";
|
|
6243
|
+
if (reason instanceof Error) return `${reason.name}: ${reason.message}`;
|
|
6244
|
+
if (typeof reason === "string") return reason;
|
|
6245
|
+
try {
|
|
6246
|
+
return JSON.stringify(reason) ?? typeof reason;
|
|
6247
|
+
} catch {
|
|
6248
|
+
return typeof reason;
|
|
6249
|
+
}
|
|
6250
|
+
}
|
|
6208
6251
|
var KNOWN_DELTA_TYPES = /* @__PURE__ */ new Set([
|
|
6209
6252
|
"thinking_delta",
|
|
6210
6253
|
"text_delta",
|
|
@@ -9578,14 +9621,28 @@ ${plan}
|
|
|
9578
9621
|
options.abortSignal.addEventListener("abort", () => {
|
|
9579
9622
|
autoContinueState.aborted = true;
|
|
9580
9623
|
if (turnCompleted || controllerClosed) {
|
|
9581
|
-
|
|
9582
|
-
|
|
9583
|
-
|
|
9584
|
-
|
|
9624
|
+
const stoppedProcess = activeProcess;
|
|
9625
|
+
if (stoppedProcess && stoppedProcess.lineEmitter.listenerCount("line") === 0 && getPendingProxyCalls(sk).length > 0) {
|
|
9626
|
+
const reason = describeAbortReason(options.abortSignal?.reason);
|
|
9627
|
+
void settleSessionRunState(affinity).then((stopped) => {
|
|
9628
|
+
const stillParked = stoppedProcess.lineEmitter.listenerCount("line") === 0 && getPendingProxyCalls(sk).length > 0;
|
|
9629
|
+
if (stopped === "busy" || !stillParked) {
|
|
9630
|
+
log.debug("abort at a tool boundary while opencode is still running the turn; keeping pending calls", {
|
|
9631
|
+
sk,
|
|
9632
|
+
session: stopped,
|
|
9633
|
+
stillParked,
|
|
9634
|
+
reason
|
|
9635
|
+
});
|
|
9636
|
+
return;
|
|
9637
|
+
}
|
|
9638
|
+
log.info("abort between proxy tool boundaries; releasing pending calls", { sk, reason });
|
|
9639
|
+
void interruptTurn(stoppedProcess).then((idle) => {
|
|
9640
|
+
log.info("interrupt sent for aborted turn", { sk, idle });
|
|
9641
|
+
});
|
|
9642
|
+
releaseAbandonedProxyCalls(
|
|
9643
|
+
"Provider stream was aborted while opencode was running its proxy tool calls"
|
|
9644
|
+
);
|
|
9585
9645
|
});
|
|
9586
|
-
releaseAbandonedProxyCalls(
|
|
9587
|
-
"Provider stream was aborted while opencode was running its proxy tool calls"
|
|
9588
|
-
);
|
|
9589
9646
|
}
|
|
9590
9647
|
return;
|
|
9591
9648
|
}
|