@defend-tech/opencode-optima 0.1.18 → 0.1.20
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 +73 -14
- package/dist/sanitize_cli.js +73 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8831,10 +8831,21 @@ function resolveOptimaPluginOptions(rawInput = {}, pluginOptions = {}) {
|
|
|
8831
8831
|
function pickConfiguredClickUp(rawInput = {}, repoCfg = {}, pluginOptions = {}) {
|
|
8832
8832
|
return pluginOptions?.clickup || pluginOptions?.experimental?.optima?.clickup || rawInput?.options?.clickup || rawInput?.options?.experimental?.optima?.clickup || rawInput?.experimental?.optima?.clickup || rawInput?.config?.experimental?.optima?.clickup || rawInput?.opencode?.experimental?.optima?.clickup || repoCfg?.experimental?.optima?.clickup || repoCfg?.clickup || null;
|
|
8833
8833
|
}
|
|
8834
|
+
function normalizeOpenCodeBaseUrl(value, defaultValue = "http://127.0.0.1:3001") {
|
|
8835
|
+
const candidate = String(value || defaultValue || "").trim();
|
|
8836
|
+
if (!candidate) return "";
|
|
8837
|
+
try {
|
|
8838
|
+
const url = new URL(candidate);
|
|
8839
|
+
return url.toString().replace(/\/+$/, "");
|
|
8840
|
+
} catch {
|
|
8841
|
+
return candidate.replace(/\/+$/, "");
|
|
8842
|
+
}
|
|
8843
|
+
}
|
|
8834
8844
|
function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd()) {
|
|
8835
8845
|
const raw = isPlainObject(rawClickUp) ? rawClickUp : {};
|
|
8836
8846
|
const webhook = isPlainObject(raw.webhook) ? raw.webhook : {};
|
|
8837
8847
|
const routing = isPlainObject(raw.routing) ? raw.routing : {};
|
|
8848
|
+
const opencode = isPlainObject(raw.opencode) ? raw.opencode : {};
|
|
8838
8849
|
const location = isPlainObject(webhook.location) ? webhook.location : {};
|
|
8839
8850
|
const events = Array.isArray(webhook.events) && webhook.events.length > 0 ? [...new Set(webhook.events.map((event) => String(event || "").trim()).filter(Boolean))] : [...CLICKUP_WEBHOOK_EVENTS];
|
|
8840
8851
|
const ignoredStatuses = Array.isArray(routing.ignored_statuses) && routing.ignored_statuses.length > 0 ? routing.ignored_statuses : CLICKUP_WEBHOOK_TERMINAL_STATUSES;
|
|
@@ -8844,6 +8855,9 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
8844
8855
|
teamId: String(raw.team_id || raw.teamId || "").trim(),
|
|
8845
8856
|
apiToken: String(raw.api_token || raw.apiToken || "").trim(),
|
|
8846
8857
|
log: normalizeClickUpWebhookLogLevel(raw.log),
|
|
8858
|
+
opencode: {
|
|
8859
|
+
baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl)
|
|
8860
|
+
},
|
|
8847
8861
|
webhook: {
|
|
8848
8862
|
publicUrl: String(webhook.public_url || webhook.publicUrl || "").trim(),
|
|
8849
8863
|
bindHost: String(webhook.bind_host || webhook.bindHost || "127.0.0.1").trim(),
|
|
@@ -8877,6 +8891,13 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
8877
8891
|
if (!config.webhook.bindHost) errors.push("clickup.webhook.bind_host is required");
|
|
8878
8892
|
if (!Number.isInteger(config.webhook.bindPort) || config.webhook.bindPort <= 0) errors.push("clickup.webhook.bind_port must be a positive integer");
|
|
8879
8893
|
if (!config.webhook.location.list_id && !config.webhook.location.folder_id && !config.webhook.location.space_id) errors.push("one clickup.webhook.location id is required");
|
|
8894
|
+
if (config.opencode.baseUrl) {
|
|
8895
|
+
try {
|
|
8896
|
+
new URL(config.opencode.baseUrl);
|
|
8897
|
+
} catch {
|
|
8898
|
+
errors.push("clickup.opencode.base_url must be a valid URL");
|
|
8899
|
+
}
|
|
8900
|
+
}
|
|
8880
8901
|
const missingEvents = CLICKUP_WEBHOOK_EVENTS.filter((event) => !config.webhook.events.includes(event));
|
|
8881
8902
|
if (missingEvents.length > 0) errors.push(`clickup.webhook.events missing: ${missingEvents.join(", ")}`);
|
|
8882
8903
|
if (config.routing.targetAgent !== "workflow_product_manager") errors.push("clickup.routing.target_agent must be workflow_product_manager");
|
|
@@ -9238,22 +9259,60 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
|
|
|
9238
9259
|
const result = await client.session.create({ query: { directory }, body: { title } });
|
|
9239
9260
|
return result?.data?.id || result?.id;
|
|
9240
9261
|
}
|
|
9262
|
+
function assertOpenCodePromptAccepted(result) {
|
|
9263
|
+
const status = Number(result?.status || result?.response?.status || result?.error?.status || 0);
|
|
9264
|
+
if (status >= 400 || result?.ok === false || result?.error) {
|
|
9265
|
+
const message = result?.error?.message || result?.message || `OpenCode prompt request failed${status ? ` with status ${status}` : ""}.`;
|
|
9266
|
+
throw new Error(message);
|
|
9267
|
+
}
|
|
9268
|
+
return result;
|
|
9269
|
+
}
|
|
9270
|
+
async function sendOpenCodeSessionEventDirect({ baseUrl, sessionId, text, fetchImpl = globalThis.fetch } = {}) {
|
|
9271
|
+
if (typeof fetchImpl !== "function") throw new Error("OpenCode direct prompt delivery requires fetch.");
|
|
9272
|
+
const root = normalizeOpenCodeBaseUrl(baseUrl, "");
|
|
9273
|
+
if (!root) throw new Error("OpenCode direct prompt delivery requires a base URL.");
|
|
9274
|
+
const url = `${root}/api/session/${encodeURIComponent(sessionId)}/prompt`;
|
|
9275
|
+
const response = await fetchImpl(url, {
|
|
9276
|
+
method: "POST",
|
|
9277
|
+
headers: { "content-type": "application/json" },
|
|
9278
|
+
body: JSON.stringify({ prompt: { text }, delivery: "queue", resume: true })
|
|
9279
|
+
});
|
|
9280
|
+
const raw = await response.text();
|
|
9281
|
+
let data = null;
|
|
9282
|
+
if (raw) {
|
|
9283
|
+
try {
|
|
9284
|
+
data = JSON.parse(raw);
|
|
9285
|
+
} catch (error) {
|
|
9286
|
+
if (response.ok) throw new Error(`OpenCode prompt response was not JSON: ${error.message}`);
|
|
9287
|
+
}
|
|
9288
|
+
}
|
|
9289
|
+
if (!response.ok) {
|
|
9290
|
+
const message = data?.error?.message || data?.message || raw || `OpenCode prompt request failed with status ${response.status}.`;
|
|
9291
|
+
throw new Error(message);
|
|
9292
|
+
}
|
|
9293
|
+
if (!data?.data?.id) throw new Error("OpenCode prompt response did not include data.id.");
|
|
9294
|
+
return { ok: true, method: "http", status: response.status, data: data.data, response: data };
|
|
9295
|
+
}
|
|
9241
9296
|
async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9297
|
+
const attempts = [
|
|
9298
|
+
{ id: sessionId, ...flatPayload },
|
|
9299
|
+
{ sessionID: sessionId, ...flatPayload },
|
|
9300
|
+
{ ...structuredPayload, path: { sessionID: sessionId } },
|
|
9301
|
+
{ ...structuredPayload, path: { id: sessionId } }
|
|
9302
|
+
];
|
|
9303
|
+
let firstError = null;
|
|
9304
|
+
for (const attempt of attempts) {
|
|
9245
9305
|
try {
|
|
9246
|
-
return await method(
|
|
9247
|
-
} catch {
|
|
9248
|
-
|
|
9249
|
-
return await method({ ...structuredPayload, path: { id: sessionId } });
|
|
9250
|
-
} catch {
|
|
9251
|
-
throw flatError;
|
|
9252
|
-
}
|
|
9306
|
+
return assertOpenCodePromptAccepted(await method(attempt));
|
|
9307
|
+
} catch (error) {
|
|
9308
|
+
firstError ??= error;
|
|
9253
9309
|
}
|
|
9254
9310
|
}
|
|
9311
|
+
throw firstError;
|
|
9255
9312
|
}
|
|
9256
|
-
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
|
|
9313
|
+
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory, opencodeBaseUrl, baseUrl, fetchImpl } = {}) {
|
|
9314
|
+
const directBaseUrl = opencodeBaseUrl || baseUrl;
|
|
9315
|
+
if (directBaseUrl) return sendOpenCodeSessionEventDirect({ baseUrl: directBaseUrl, sessionId, text, fetchImpl });
|
|
9257
9316
|
const parts = [{ type: "text", text }];
|
|
9258
9317
|
const flatPayload = { directory, agent, parts };
|
|
9259
9318
|
const structuredPayload = { query: { directory }, body: { agent, parts } };
|
|
@@ -9507,7 +9566,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9507
9566
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
9508
9567
|
throw error;
|
|
9509
9568
|
}
|
|
9510
|
-
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
|
|
9569
|
+
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9511
9570
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
9512
9571
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
9513
9572
|
const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
|
|
@@ -9516,7 +9575,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9516
9575
|
}
|
|
9517
9576
|
const sessionId = String(existingSessionId);
|
|
9518
9577
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
9519
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
|
|
9578
|
+
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9520
9579
|
return finish({ ok: true, action: "sent_to_existing_session", taskId, sessionId, eventKey });
|
|
9521
9580
|
}
|
|
9522
9581
|
const at = now().toISOString();
|
|
@@ -11267,7 +11326,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
11267
11326
|
}
|
|
11268
11327
|
};
|
|
11269
11328
|
}
|
|
11270
|
-
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
11329
|
+
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
11271
11330
|
export {
|
|
11272
11331
|
OptimaPlugin as default
|
|
11273
11332
|
};
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -8838,10 +8838,21 @@ function resolveOptimaPluginOptions(rawInput = {}, pluginOptions = {}) {
|
|
|
8838
8838
|
function pickConfiguredClickUp(rawInput = {}, repoCfg = {}, pluginOptions = {}) {
|
|
8839
8839
|
return pluginOptions?.clickup || pluginOptions?.experimental?.optima?.clickup || rawInput?.options?.clickup || rawInput?.options?.experimental?.optima?.clickup || rawInput?.experimental?.optima?.clickup || rawInput?.config?.experimental?.optima?.clickup || rawInput?.opencode?.experimental?.optima?.clickup || repoCfg?.experimental?.optima?.clickup || repoCfg?.clickup || null;
|
|
8840
8840
|
}
|
|
8841
|
+
function normalizeOpenCodeBaseUrl(value, defaultValue = "http://127.0.0.1:3001") {
|
|
8842
|
+
const candidate = String(value || defaultValue || "").trim();
|
|
8843
|
+
if (!candidate) return "";
|
|
8844
|
+
try {
|
|
8845
|
+
const url = new URL(candidate);
|
|
8846
|
+
return url.toString().replace(/\/+$/, "");
|
|
8847
|
+
} catch {
|
|
8848
|
+
return candidate.replace(/\/+$/, "");
|
|
8849
|
+
}
|
|
8850
|
+
}
|
|
8841
8851
|
function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd()) {
|
|
8842
8852
|
const raw = isPlainObject(rawClickUp) ? rawClickUp : {};
|
|
8843
8853
|
const webhook = isPlainObject(raw.webhook) ? raw.webhook : {};
|
|
8844
8854
|
const routing = isPlainObject(raw.routing) ? raw.routing : {};
|
|
8855
|
+
const opencode = isPlainObject(raw.opencode) ? raw.opencode : {};
|
|
8845
8856
|
const location = isPlainObject(webhook.location) ? webhook.location : {};
|
|
8846
8857
|
const events = Array.isArray(webhook.events) && webhook.events.length > 0 ? [...new Set(webhook.events.map((event) => String(event || "").trim()).filter(Boolean))] : [...CLICKUP_WEBHOOK_EVENTS];
|
|
8847
8858
|
const ignoredStatuses = Array.isArray(routing.ignored_statuses) && routing.ignored_statuses.length > 0 ? routing.ignored_statuses : CLICKUP_WEBHOOK_TERMINAL_STATUSES;
|
|
@@ -8851,6 +8862,9 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
8851
8862
|
teamId: String(raw.team_id || raw.teamId || "").trim(),
|
|
8852
8863
|
apiToken: String(raw.api_token || raw.apiToken || "").trim(),
|
|
8853
8864
|
log: normalizeClickUpWebhookLogLevel(raw.log),
|
|
8865
|
+
opencode: {
|
|
8866
|
+
baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl)
|
|
8867
|
+
},
|
|
8854
8868
|
webhook: {
|
|
8855
8869
|
publicUrl: String(webhook.public_url || webhook.publicUrl || "").trim(),
|
|
8856
8870
|
bindHost: String(webhook.bind_host || webhook.bindHost || "127.0.0.1").trim(),
|
|
@@ -8884,6 +8898,13 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
8884
8898
|
if (!config.webhook.bindHost) errors.push("clickup.webhook.bind_host is required");
|
|
8885
8899
|
if (!Number.isInteger(config.webhook.bindPort) || config.webhook.bindPort <= 0) errors.push("clickup.webhook.bind_port must be a positive integer");
|
|
8886
8900
|
if (!config.webhook.location.list_id && !config.webhook.location.folder_id && !config.webhook.location.space_id) errors.push("one clickup.webhook.location id is required");
|
|
8901
|
+
if (config.opencode.baseUrl) {
|
|
8902
|
+
try {
|
|
8903
|
+
new URL(config.opencode.baseUrl);
|
|
8904
|
+
} catch {
|
|
8905
|
+
errors.push("clickup.opencode.base_url must be a valid URL");
|
|
8906
|
+
}
|
|
8907
|
+
}
|
|
8887
8908
|
const missingEvents = CLICKUP_WEBHOOK_EVENTS.filter((event) => !config.webhook.events.includes(event));
|
|
8888
8909
|
if (missingEvents.length > 0) errors.push(`clickup.webhook.events missing: ${missingEvents.join(", ")}`);
|
|
8889
8910
|
if (config.routing.targetAgent !== "workflow_product_manager") errors.push("clickup.routing.target_agent must be workflow_product_manager");
|
|
@@ -9245,22 +9266,60 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
|
|
|
9245
9266
|
const result = await client.session.create({ query: { directory }, body: { title } });
|
|
9246
9267
|
return result?.data?.id || result?.id;
|
|
9247
9268
|
}
|
|
9269
|
+
function assertOpenCodePromptAccepted(result) {
|
|
9270
|
+
const status = Number(result?.status || result?.response?.status || result?.error?.status || 0);
|
|
9271
|
+
if (status >= 400 || result?.ok === false || result?.error) {
|
|
9272
|
+
const message = result?.error?.message || result?.message || `OpenCode prompt request failed${status ? ` with status ${status}` : ""}.`;
|
|
9273
|
+
throw new Error(message);
|
|
9274
|
+
}
|
|
9275
|
+
return result;
|
|
9276
|
+
}
|
|
9277
|
+
async function sendOpenCodeSessionEventDirect({ baseUrl, sessionId, text, fetchImpl = globalThis.fetch } = {}) {
|
|
9278
|
+
if (typeof fetchImpl !== "function") throw new Error("OpenCode direct prompt delivery requires fetch.");
|
|
9279
|
+
const root = normalizeOpenCodeBaseUrl(baseUrl, "");
|
|
9280
|
+
if (!root) throw new Error("OpenCode direct prompt delivery requires a base URL.");
|
|
9281
|
+
const url = `${root}/api/session/${encodeURIComponent(sessionId)}/prompt`;
|
|
9282
|
+
const response = await fetchImpl(url, {
|
|
9283
|
+
method: "POST",
|
|
9284
|
+
headers: { "content-type": "application/json" },
|
|
9285
|
+
body: JSON.stringify({ prompt: { text }, delivery: "queue", resume: true })
|
|
9286
|
+
});
|
|
9287
|
+
const raw = await response.text();
|
|
9288
|
+
let data = null;
|
|
9289
|
+
if (raw) {
|
|
9290
|
+
try {
|
|
9291
|
+
data = JSON.parse(raw);
|
|
9292
|
+
} catch (error) {
|
|
9293
|
+
if (response.ok) throw new Error(`OpenCode prompt response was not JSON: ${error.message}`);
|
|
9294
|
+
}
|
|
9295
|
+
}
|
|
9296
|
+
if (!response.ok) {
|
|
9297
|
+
const message = data?.error?.message || data?.message || raw || `OpenCode prompt request failed with status ${response.status}.`;
|
|
9298
|
+
throw new Error(message);
|
|
9299
|
+
}
|
|
9300
|
+
if (!data?.data?.id) throw new Error("OpenCode prompt response did not include data.id.");
|
|
9301
|
+
return { ok: true, method: "http", status: response.status, data: data.data, response: data };
|
|
9302
|
+
}
|
|
9248
9303
|
async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9304
|
+
const attempts = [
|
|
9305
|
+
{ id: sessionId, ...flatPayload },
|
|
9306
|
+
{ sessionID: sessionId, ...flatPayload },
|
|
9307
|
+
{ ...structuredPayload, path: { sessionID: sessionId } },
|
|
9308
|
+
{ ...structuredPayload, path: { id: sessionId } }
|
|
9309
|
+
];
|
|
9310
|
+
let firstError = null;
|
|
9311
|
+
for (const attempt of attempts) {
|
|
9252
9312
|
try {
|
|
9253
|
-
return await method(
|
|
9254
|
-
} catch {
|
|
9255
|
-
|
|
9256
|
-
return await method({ ...structuredPayload, path: { id: sessionId } });
|
|
9257
|
-
} catch {
|
|
9258
|
-
throw flatError;
|
|
9259
|
-
}
|
|
9313
|
+
return assertOpenCodePromptAccepted(await method(attempt));
|
|
9314
|
+
} catch (error) {
|
|
9315
|
+
firstError ??= error;
|
|
9260
9316
|
}
|
|
9261
9317
|
}
|
|
9318
|
+
throw firstError;
|
|
9262
9319
|
}
|
|
9263
|
-
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
|
|
9320
|
+
async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory, opencodeBaseUrl, baseUrl, fetchImpl } = {}) {
|
|
9321
|
+
const directBaseUrl = opencodeBaseUrl || baseUrl;
|
|
9322
|
+
if (directBaseUrl) return sendOpenCodeSessionEventDirect({ baseUrl: directBaseUrl, sessionId, text, fetchImpl });
|
|
9264
9323
|
const parts = [{ type: "text", text }];
|
|
9265
9324
|
const flatPayload = { directory, agent, parts };
|
|
9266
9325
|
const structuredPayload = { query: { directory }, body: { agent, parts } };
|
|
@@ -9514,7 +9573,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9514
9573
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
9515
9574
|
throw error;
|
|
9516
9575
|
}
|
|
9517
|
-
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
|
|
9576
|
+
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9518
9577
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
9519
9578
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
9520
9579
|
const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
|
|
@@ -9523,7 +9582,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9523
9582
|
}
|
|
9524
9583
|
const sessionId = String(existingSessionId);
|
|
9525
9584
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
9526
|
-
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
|
|
9585
|
+
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9527
9586
|
return finish({ ok: true, action: "sent_to_existing_session", taskId, sessionId, eventKey });
|
|
9528
9587
|
}
|
|
9529
9588
|
const at = now().toISOString();
|
|
@@ -11274,7 +11333,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
11274
11333
|
}
|
|
11275
11334
|
};
|
|
11276
11335
|
}
|
|
11277
|
-
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
11336
|
+
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
11278
11337
|
|
|
11279
11338
|
// src/sanitize_cli.js
|
|
11280
11339
|
var { migrateLegacyOptimaLayout: migrateLegacyOptimaLayout2 } = OptimaPlugin.__internals;
|