@defend-tech/opencode-optima 0.1.43 → 0.1.44
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 +31 -3
- package/dist/sanitize_cli.js +31 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9592,6 +9592,18 @@ function assertOpenCodePromptAccepted(result) {
|
|
|
9592
9592
|
}
|
|
9593
9593
|
return result;
|
|
9594
9594
|
}
|
|
9595
|
+
function openCodePromptAdmissionVerification(result, sessionId) {
|
|
9596
|
+
const response = result?.response ?? result;
|
|
9597
|
+
const data = response?.data ?? result?.data ?? null;
|
|
9598
|
+
const promptId = data?.id ?? response?.id ?? result?.id;
|
|
9599
|
+
const admittedSessionId = response?.sessionID ?? response?.sessionId ?? data?.sessionID ?? data?.sessionId ?? result?.sessionID ?? result?.sessionId;
|
|
9600
|
+
const admittedSeq = response?.admittedSeq ?? data?.admittedSeq ?? result?.admittedSeq;
|
|
9601
|
+
if (!promptId || admittedSeq === void 0 || admittedSeq === null || !admittedSessionId) return null;
|
|
9602
|
+
if (String(admittedSessionId) !== String(sessionId)) {
|
|
9603
|
+
throw new Error(`OpenCode prompt admission targeted foreign session ${admittedSessionId}.`);
|
|
9604
|
+
}
|
|
9605
|
+
return { ok: true, method: "prompt_admission", promptId: String(promptId), sessionId: String(admittedSessionId), admittedSeq };
|
|
9606
|
+
}
|
|
9595
9607
|
function responseLooksLikeHtml(contentType = "", raw = "") {
|
|
9596
9608
|
return String(contentType || "").toLowerCase().includes("text/html") || /^\s*<!doctype\s+html\b/i.test(raw) || /^\s*<html\b/i.test(raw);
|
|
9597
9609
|
}
|
|
@@ -9621,7 +9633,7 @@ async function sendOpenCodeSessionEventDirect({ baseUrl, sessionId, text, agent,
|
|
|
9621
9633
|
body: { prompt: { text }, delivery: "queue", resume: true },
|
|
9622
9634
|
accept: (response, data) => {
|
|
9623
9635
|
if (!response.ok) return null;
|
|
9624
|
-
if (!data
|
|
9636
|
+
if (!openCodePromptAdmissionVerification(data, sessionId)) throw new Error("OpenCode v2 prompt response did not include a valid prompt admission.");
|
|
9625
9637
|
return { ok: true, method: "http", endpoint: "/api/session/{sessionID}/prompt", status: response.status, data: data.data, response: data };
|
|
9626
9638
|
}
|
|
9627
9639
|
},
|
|
@@ -9735,13 +9747,29 @@ async function applyClickUpBlockerTag({ clickupClient, worktree, taskId, reason,
|
|
|
9735
9747
|
}
|
|
9736
9748
|
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
9737
9749
|
const beforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, limit: 50 }).catch(() => null);
|
|
9738
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl });
|
|
9750
|
+
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl });
|
|
9751
|
+
let admissionVerification = null;
|
|
9752
|
+
try {
|
|
9753
|
+
admissionVerification = openCodePromptAdmissionVerification(sendResult, sessionId);
|
|
9754
|
+
} catch (error) {
|
|
9755
|
+
appendClickUpWebhookLocalLog(worktree, { type: "message_delivery_failed", taskId, sessionId, reason: error.message, fallbackAttempted: false });
|
|
9756
|
+
if (!applyBlockerOnFailure) return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false };
|
|
9757
|
+
const blocker2 = await applyClickUpBlockerTag({ clickupClient, worktree, taskId, reason: error.message, source: "delivery_admission_failed" });
|
|
9758
|
+
return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false, blockerTag: blocker2 };
|
|
9759
|
+
}
|
|
9760
|
+
if (admissionVerification) return { ok: true, verification: admissionVerification, fallback: false };
|
|
9739
9761
|
let verification = await verifySessionEventDelivery(openCodeClient, { sessionId, beforeMessages, expectedText: text, markers: eventMarkers });
|
|
9740
9762
|
if (verification?.ok) return { ok: true, verification, fallback: false };
|
|
9741
9763
|
const canFallbackDirect = Boolean(opencodeBaseUrl);
|
|
9742
9764
|
if (canFallbackDirect) {
|
|
9743
9765
|
const retryBeforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, limit: 50 }).catch(() => beforeMessages);
|
|
9744
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: true });
|
|
9766
|
+
const retrySendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: true });
|
|
9767
|
+
try {
|
|
9768
|
+
admissionVerification = openCodePromptAdmissionVerification(retrySendResult, sessionId);
|
|
9769
|
+
} catch (error) {
|
|
9770
|
+
verification = { ok: false, reason: error.message };
|
|
9771
|
+
}
|
|
9772
|
+
if (admissionVerification) return { ok: true, verification: admissionVerification, fallback: true };
|
|
9745
9773
|
verification = await verifySessionEventDelivery(openCodeClient, { sessionId, beforeMessages: retryBeforeMessages, expectedText: text, markers: eventMarkers });
|
|
9746
9774
|
if (verification?.ok) return { ok: true, verification, fallback: true };
|
|
9747
9775
|
}
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -9599,6 +9599,18 @@ function assertOpenCodePromptAccepted(result) {
|
|
|
9599
9599
|
}
|
|
9600
9600
|
return result;
|
|
9601
9601
|
}
|
|
9602
|
+
function openCodePromptAdmissionVerification(result, sessionId) {
|
|
9603
|
+
const response = result?.response ?? result;
|
|
9604
|
+
const data = response?.data ?? result?.data ?? null;
|
|
9605
|
+
const promptId = data?.id ?? response?.id ?? result?.id;
|
|
9606
|
+
const admittedSessionId = response?.sessionID ?? response?.sessionId ?? data?.sessionID ?? data?.sessionId ?? result?.sessionID ?? result?.sessionId;
|
|
9607
|
+
const admittedSeq = response?.admittedSeq ?? data?.admittedSeq ?? result?.admittedSeq;
|
|
9608
|
+
if (!promptId || admittedSeq === void 0 || admittedSeq === null || !admittedSessionId) return null;
|
|
9609
|
+
if (String(admittedSessionId) !== String(sessionId)) {
|
|
9610
|
+
throw new Error(`OpenCode prompt admission targeted foreign session ${admittedSessionId}.`);
|
|
9611
|
+
}
|
|
9612
|
+
return { ok: true, method: "prompt_admission", promptId: String(promptId), sessionId: String(admittedSessionId), admittedSeq };
|
|
9613
|
+
}
|
|
9602
9614
|
function responseLooksLikeHtml(contentType = "", raw = "") {
|
|
9603
9615
|
return String(contentType || "").toLowerCase().includes("text/html") || /^\s*<!doctype\s+html\b/i.test(raw) || /^\s*<html\b/i.test(raw);
|
|
9604
9616
|
}
|
|
@@ -9628,7 +9640,7 @@ async function sendOpenCodeSessionEventDirect({ baseUrl, sessionId, text, agent,
|
|
|
9628
9640
|
body: { prompt: { text }, delivery: "queue", resume: true },
|
|
9629
9641
|
accept: (response, data) => {
|
|
9630
9642
|
if (!response.ok) return null;
|
|
9631
|
-
if (!data
|
|
9643
|
+
if (!openCodePromptAdmissionVerification(data, sessionId)) throw new Error("OpenCode v2 prompt response did not include a valid prompt admission.");
|
|
9632
9644
|
return { ok: true, method: "http", endpoint: "/api/session/{sessionID}/prompt", status: response.status, data: data.data, response: data };
|
|
9633
9645
|
}
|
|
9634
9646
|
},
|
|
@@ -9742,13 +9754,29 @@ async function applyClickUpBlockerTag({ clickupClient, worktree, taskId, reason,
|
|
|
9742
9754
|
}
|
|
9743
9755
|
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
9744
9756
|
const beforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, limit: 50 }).catch(() => null);
|
|
9745
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl });
|
|
9757
|
+
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl });
|
|
9758
|
+
let admissionVerification = null;
|
|
9759
|
+
try {
|
|
9760
|
+
admissionVerification = openCodePromptAdmissionVerification(sendResult, sessionId);
|
|
9761
|
+
} catch (error) {
|
|
9762
|
+
appendClickUpWebhookLocalLog(worktree, { type: "message_delivery_failed", taskId, sessionId, reason: error.message, fallbackAttempted: false });
|
|
9763
|
+
if (!applyBlockerOnFailure) return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false };
|
|
9764
|
+
const blocker2 = await applyClickUpBlockerTag({ clickupClient, worktree, taskId, reason: error.message, source: "delivery_admission_failed" });
|
|
9765
|
+
return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false, blockerTag: blocker2 };
|
|
9766
|
+
}
|
|
9767
|
+
if (admissionVerification) return { ok: true, verification: admissionVerification, fallback: false };
|
|
9746
9768
|
let verification = await verifySessionEventDelivery(openCodeClient, { sessionId, beforeMessages, expectedText: text, markers: eventMarkers });
|
|
9747
9769
|
if (verification?.ok) return { ok: true, verification, fallback: false };
|
|
9748
9770
|
const canFallbackDirect = Boolean(opencodeBaseUrl);
|
|
9749
9771
|
if (canFallbackDirect) {
|
|
9750
9772
|
const retryBeforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, limit: 50 }).catch(() => beforeMessages);
|
|
9751
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: true });
|
|
9773
|
+
const retrySendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: true });
|
|
9774
|
+
try {
|
|
9775
|
+
admissionVerification = openCodePromptAdmissionVerification(retrySendResult, sessionId);
|
|
9776
|
+
} catch (error) {
|
|
9777
|
+
verification = { ok: false, reason: error.message };
|
|
9778
|
+
}
|
|
9779
|
+
if (admissionVerification) return { ok: true, verification: admissionVerification, fallback: true };
|
|
9752
9780
|
verification = await verifySessionEventDelivery(openCodeClient, { sessionId, beforeMessages: retryBeforeMessages, expectedText: text, markers: eventMarkers });
|
|
9753
9781
|
if (verification?.ok) return { ok: true, verification, fallback: true };
|
|
9754
9782
|
}
|