@khalilgharbaoui/opencode-claude-code-plugin 0.42.0 → 0.42.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 +79 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3783,12 +3783,16 @@ async function fetchSessionParentId(sessionID) {
|
|
|
3783
3783
|
return void 0;
|
|
3784
3784
|
}
|
|
3785
3785
|
}
|
|
3786
|
-
async function fetchSessionRunState(sessionID) {
|
|
3786
|
+
async function fetchSessionRunState(sessionID, directory) {
|
|
3787
3787
|
if (!sessionID || sessionID === "default") return "unknown";
|
|
3788
3788
|
const status = opencodeClient?.session?.status;
|
|
3789
3789
|
if (!status) return "unknown";
|
|
3790
3790
|
try {
|
|
3791
|
-
const
|
|
3791
|
+
const dir = directory ?? await fetchSessionDirectory(sessionID);
|
|
3792
|
+
const res = await status.call(
|
|
3793
|
+
opencodeClient.session,
|
|
3794
|
+
dir ? { query: { directory: dir } } : void 0
|
|
3795
|
+
);
|
|
3792
3796
|
const data = res.data;
|
|
3793
3797
|
if (!data || typeof data !== "object") return "unknown";
|
|
3794
3798
|
const entry = data[sessionID];
|
|
@@ -3808,8 +3812,10 @@ async function settleSessionRunState(sessionID, options = {}) {
|
|
|
3808
3812
|
const windowMs = options.windowMs ?? 1500;
|
|
3809
3813
|
const started = Date.now();
|
|
3810
3814
|
let last = "unknown";
|
|
3815
|
+
let directory = options.directory;
|
|
3811
3816
|
for (; ; ) {
|
|
3812
|
-
|
|
3817
|
+
directory ??= await fetchSessionDirectory(sessionID);
|
|
3818
|
+
const state = await fetchSessionRunState(sessionID, directory ?? "");
|
|
3813
3819
|
if (state === "busy") return "busy";
|
|
3814
3820
|
if (state !== "unknown") last = state;
|
|
3815
3821
|
if (Date.now() - started >= windowMs) return last;
|
|
@@ -8219,6 +8225,38 @@ Now continuing with the current message:
|
|
|
8219
8225
|
}
|
|
8220
8226
|
});
|
|
8221
8227
|
}
|
|
8228
|
+
function getTrailingUserMessages(prompt, opts = {}) {
|
|
8229
|
+
prompt = stripAccountFailoverParts(prompt);
|
|
8230
|
+
if (opts.stripContextReminders) prompt = stripContextReminders(prompt).prompt;
|
|
8231
|
+
let assistantIndex = -1;
|
|
8232
|
+
for (let i = prompt.length - 1; i >= 0; i--) {
|
|
8233
|
+
if (prompt[i].role === "assistant") {
|
|
8234
|
+
assistantIndex = i;
|
|
8235
|
+
break;
|
|
8236
|
+
}
|
|
8237
|
+
}
|
|
8238
|
+
const messages = [];
|
|
8239
|
+
for (let i = assistantIndex + 1; i < prompt.length; i++) {
|
|
8240
|
+
const msg = prompt[i];
|
|
8241
|
+
if (msg.role !== "user") continue;
|
|
8242
|
+
if (parseSideQuestionContent(msg.content) !== null) continue;
|
|
8243
|
+
const blocks = [];
|
|
8244
|
+
if (typeof msg.content === "string") {
|
|
8245
|
+
if (msg.content.trim()) blocks.push({ type: "text", text: msg.content });
|
|
8246
|
+
} else if (Array.isArray(msg.content)) {
|
|
8247
|
+
for (const part of msg.content) {
|
|
8248
|
+
if (part.type === "text") {
|
|
8249
|
+
if (part.text && part.text.trim()) blocks.push({ type: "text", text: part.text });
|
|
8250
|
+
} else if (part.type === "file" || part.type === "image") {
|
|
8251
|
+
const block = toImageBlock(part);
|
|
8252
|
+
if (block) blocks.push(block);
|
|
8253
|
+
}
|
|
8254
|
+
}
|
|
8255
|
+
}
|
|
8256
|
+
if (blocks.length > 0) messages.push(blocks);
|
|
8257
|
+
}
|
|
8258
|
+
return { assistantIndex, messages };
|
|
8259
|
+
}
|
|
8222
8260
|
|
|
8223
8261
|
// src/skill-bridge.ts
|
|
8224
8262
|
import * as crypto3 from "crypto";
|
|
@@ -12502,6 +12540,7 @@ async function isProxyCallStillServed(callId) {
|
|
|
12502
12540
|
return await fetchSessionRunState(session) === "busy";
|
|
12503
12541
|
}
|
|
12504
12542
|
setProxyDeadlineGuard(({ callId }) => isProxyCallStillServed(callId));
|
|
12543
|
+
var FORWARD_SETTLE_MS = 250;
|
|
12505
12544
|
var CHILD_EXIT_STATUS_GRACE_MS = 250;
|
|
12506
12545
|
var ClaudeCodeLanguageModel = class {
|
|
12507
12546
|
specificationVersion = "v3";
|
|
@@ -13422,7 +13461,7 @@ var ClaudeCodeLanguageModel = class {
|
|
|
13422
13461
|
});
|
|
13423
13462
|
return;
|
|
13424
13463
|
}
|
|
13425
|
-
log.info("abort between proxy tool boundaries; releasing pending calls", { sk, reason });
|
|
13464
|
+
log.info("abort between proxy tool boundaries; releasing pending calls", { sk, reason, session: stopped });
|
|
13426
13465
|
void interruptTurn(stoppedProcess).then((idle) => {
|
|
13427
13466
|
log.info("interrupt sent for aborted turn", { sk, idle });
|
|
13428
13467
|
});
|
|
@@ -14253,6 +14292,34 @@ var ClaudeCodeLanguageModel = class {
|
|
|
14253
14292
|
state.proc.on("error", procErrorHandler);
|
|
14254
14293
|
if (hasMatchedPendingResults) {
|
|
14255
14294
|
state.cliAskedForWork = true;
|
|
14295
|
+
const forwardTrailingUserMessages = () => {
|
|
14296
|
+
if (compactionMode || !state.activeProcess) return 0;
|
|
14297
|
+
if (state.activeProcess.interactiveControl) return 0;
|
|
14298
|
+
const trailing = getTrailingUserMessages(effectivePrompt, {
|
|
14299
|
+
stripContextReminders: self.stripContextRemindersEnabled()
|
|
14300
|
+
});
|
|
14301
|
+
const sent = state.activeProcess.forwardedUserMessages?.assistantIndex === trailing.assistantIndex ? state.activeProcess.forwardedUserMessages.count : 0;
|
|
14302
|
+
const fresh = trailing.messages.slice(sent);
|
|
14303
|
+
if (fresh.length === 0) return 0;
|
|
14304
|
+
state.activeProcess.forwardedUserMessages = {
|
|
14305
|
+
assistantIndex: trailing.assistantIndex,
|
|
14306
|
+
count: trailing.messages.length
|
|
14307
|
+
};
|
|
14308
|
+
for (const content of fresh) {
|
|
14309
|
+
state.proc.stdin?.write(
|
|
14310
|
+
JSON.stringify({ type: "user", message: { role: "user", content } }) + "\n"
|
|
14311
|
+
);
|
|
14312
|
+
}
|
|
14313
|
+
log.info("forwarded user messages that arrived beside tool results", {
|
|
14314
|
+
sessionKey: sk,
|
|
14315
|
+
messages: fresh.length
|
|
14316
|
+
});
|
|
14317
|
+
return fresh.length;
|
|
14318
|
+
};
|
|
14319
|
+
if (!state.unattendedTurnEnded && forwardTrailingUserMessages() > 0) {
|
|
14320
|
+
await new Promise((resolve6) => setTimeout(resolve6, FORWARD_SETTLE_MS));
|
|
14321
|
+
if (state.controllerClosed) return;
|
|
14322
|
+
}
|
|
14256
14323
|
for (const { call, result } of previousPendingProxyMatches) {
|
|
14257
14324
|
if (result) {
|
|
14258
14325
|
const channelClosed = isPendingProxyCallChannelClosed(call);
|
|
@@ -14282,7 +14349,10 @@ var ClaudeCodeLanguageModel = class {
|
|
|
14282
14349
|
);
|
|
14283
14350
|
}
|
|
14284
14351
|
}
|
|
14285
|
-
if (state.unattendedTurnEnded)
|
|
14352
|
+
if (state.unattendedTurnEnded) {
|
|
14353
|
+
deliverPendingCompletions(state);
|
|
14354
|
+
forwardTrailingUserMessages();
|
|
14355
|
+
}
|
|
14286
14356
|
const unemitted = getPendingProxyCalls(sk).filter(
|
|
14287
14357
|
(call) => !call.emitted
|
|
14288
14358
|
);
|
|
@@ -14311,7 +14381,10 @@ var ClaudeCodeLanguageModel = class {
|
|
|
14311
14381
|
}
|
|
14312
14382
|
}
|
|
14313
14383
|
state.cliAskedForWork = true;
|
|
14314
|
-
if (state.activeProcess)
|
|
14384
|
+
if (state.activeProcess) {
|
|
14385
|
+
noteTurnStarted(state.activeProcess);
|
|
14386
|
+
state.activeProcess.forwardedUserMessages = void 0;
|
|
14387
|
+
}
|
|
14315
14388
|
state.proc.stdin?.write(userMsg + "\n");
|
|
14316
14389
|
log.debug("sent user message", { textLength: userMsg.length });
|
|
14317
14390
|
armStartWatchdog(state);
|