@defend-tech/opencode-optima 0.1.56 → 0.1.58
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 +51 -8
- package/dist/sanitize_cli.js +51 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9585,12 +9585,15 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
9585
9585
|
const ignoredStatuses = Array.isArray(routing.ignored_statuses) && routing.ignored_statuses.length > 0 ? routing.ignored_statuses : CLICKUP_WEBHOOK_TERMINAL_STATUSES;
|
|
9586
9586
|
const config = {
|
|
9587
9587
|
enabled: raw.enabled === true,
|
|
9588
|
+
test: raw.test === true || raw.test_mode === true || raw.testMode === true,
|
|
9588
9589
|
basePath: String(raw.base_path || raw.basePath || worktree || "").trim(),
|
|
9589
9590
|
teamId: String(raw.team_id || raw.teamId || "").trim(),
|
|
9590
9591
|
apiToken: String(raw.api_token || raw.apiToken || "").trim(),
|
|
9591
9592
|
log: normalizeClickUpWebhookLogLevel(raw.log),
|
|
9592
9593
|
opencode: {
|
|
9593
9594
|
baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl),
|
|
9595
|
+
promptDelivery: ["http", "direct"].includes(String(opencode.prompt_delivery || opencode.promptDelivery || raw.prompt_delivery || raw.promptDelivery || "").trim().toLowerCase()) ? "http" : "sdk",
|
|
9596
|
+
acceptPromptAdmission: opencode.accept_prompt_admission === true || opencode.acceptPromptAdmission === true || raw.accept_prompt_admission === true || raw.acceptPromptAdmission === true,
|
|
9594
9597
|
startupReconciliationDelayMs: normalizeNonNegativeInteger(
|
|
9595
9598
|
opencode.startup_reconciliation_delay_ms ?? opencode.startupReconciliationDelayMs ?? raw.startup_reconciliation_delay_ms ?? raw.startupReconciliationDelayMs,
|
|
9596
9599
|
CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS
|
|
@@ -9782,6 +9785,40 @@ function createClickUpApiClient(config, fetchImpl = globalThis.fetch) {
|
|
|
9782
9785
|
}
|
|
9783
9786
|
};
|
|
9784
9787
|
}
|
|
9788
|
+
function createTestClickUpApiClient(config) {
|
|
9789
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
9790
|
+
return {
|
|
9791
|
+
async createWebhook({ endpoint, events, location } = {}) {
|
|
9792
|
+
return {
|
|
9793
|
+
webhook: {
|
|
9794
|
+
id: "optima-test-webhook",
|
|
9795
|
+
endpoint: endpoint || config.webhook.publicUrl,
|
|
9796
|
+
events: events || config.webhook.events,
|
|
9797
|
+
location: location || config.webhook.location,
|
|
9798
|
+
secret: "optima-test-secret",
|
|
9799
|
+
active: true
|
|
9800
|
+
}
|
|
9801
|
+
};
|
|
9802
|
+
},
|
|
9803
|
+
async getTask(taskId) {
|
|
9804
|
+
return null;
|
|
9805
|
+
},
|
|
9806
|
+
async updateTaskMetadata({ taskId, value }) {
|
|
9807
|
+
metadata.set(String(taskId || ""), value);
|
|
9808
|
+
return { ok: true };
|
|
9809
|
+
},
|
|
9810
|
+
async postTaskComment() {
|
|
9811
|
+
return { ok: true };
|
|
9812
|
+
},
|
|
9813
|
+
async addTaskTag() {
|
|
9814
|
+
return { ok: true };
|
|
9815
|
+
},
|
|
9816
|
+
async listAssignedTasks() {
|
|
9817
|
+
return { tasks: [] };
|
|
9818
|
+
},
|
|
9819
|
+
__metadata: metadata
|
|
9820
|
+
};
|
|
9821
|
+
}
|
|
9785
9822
|
function normalizeClickUpWebhookApiResponse(response = {}, fallbackConfig = null) {
|
|
9786
9823
|
const webhook = response?.webhook || response?.data || response || {};
|
|
9787
9824
|
const healthStatus = String(webhook.health?.status || webhook.health_status || "").trim().toLowerCase();
|
|
@@ -10612,9 +10649,9 @@ function openCodeBlockingPromptVerification(result, sessionId) {
|
|
|
10612
10649
|
if (parts.length > 0 || messageId) return { ok: true, method: parts.length > 0 ? "blocking_prompt_parts" : "blocking_prompt_message", messageId: messageId ? String(messageId) : null, sessionId: deliveredSessionId ? String(deliveredSessionId) : String(sessionId), parts: parts.length };
|
|
10613
10650
|
return null;
|
|
10614
10651
|
}
|
|
10615
|
-
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
10652
|
+
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, directPrompt = false, acceptPromptAdmission = false, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
10616
10653
|
const beforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, directory, limit: 50 }).catch(() => null);
|
|
10617
|
-
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, allowDirectFallback:
|
|
10654
|
+
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: directPrompt, allowDirectFallback: directPrompt });
|
|
10618
10655
|
let blockingPromptVerification = null;
|
|
10619
10656
|
let admissionVerification = null;
|
|
10620
10657
|
try {
|
|
@@ -10627,6 +10664,9 @@ async function deliverClickUpSessionEventWithVerification({ openCodeClient, send
|
|
|
10627
10664
|
return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false, blockerTag: blocker2 };
|
|
10628
10665
|
}
|
|
10629
10666
|
if (blockingPromptVerification) return { ok: true, verification: blockingPromptVerification, admissionVerification: null, fallback: false };
|
|
10667
|
+
if (admissionVerification && acceptPromptAdmission) {
|
|
10668
|
+
return { ok: true, verification: admissionVerification, admissionVerification, fallback: false, admissionOnly: true };
|
|
10669
|
+
}
|
|
10630
10670
|
let verification = await verifySessionEventDelivery(openCodeClient, { sessionId, directory, beforeMessages, expectedText: text, markers: eventMarkers });
|
|
10631
10671
|
if (verification?.ok) return { ok: true, verification, admissionVerification, fallback: false };
|
|
10632
10672
|
if (admissionVerification) {
|
|
@@ -10664,6 +10704,8 @@ async function recoverClickUpPmSession({ openCodeClient, sendSessionEvent, click
|
|
|
10664
10704
|
text: prompt,
|
|
10665
10705
|
directory: taskRoute.worktree,
|
|
10666
10706
|
opencodeBaseUrl: config.opencode?.baseUrl,
|
|
10707
|
+
directPrompt: config.opencode?.promptDelivery === "http",
|
|
10708
|
+
acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true,
|
|
10667
10709
|
eventMarkers,
|
|
10668
10710
|
verifySessionEventDelivery,
|
|
10669
10711
|
applyBlockerOnFailure: false
|
|
@@ -10930,7 +10972,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10930
10972
|
const subtaskId = parentTaskId && parentTaskId !== taskId ? taskId : "";
|
|
10931
10973
|
let taskRoute;
|
|
10932
10974
|
try {
|
|
10933
|
-
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" });
|
|
10975
|
+
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" || config.test === true });
|
|
10934
10976
|
} catch (error) {
|
|
10935
10977
|
const message = `Optima webhook could not create or reuse a task worktree for ${taskId}: ${error.message}`;
|
|
10936
10978
|
appendClickUpWebhookLocalLog(worktree, { type: "task_worktree_failed", taskId, message });
|
|
@@ -10966,7 +11008,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10966
11008
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
10967
11009
|
throw error;
|
|
10968
11010
|
}
|
|
10969
|
-
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, eventMarkers: [taskId, eventType], verifySessionEventDelivery });
|
|
11011
|
+
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, directPrompt: config.opencode?.promptDelivery === "http", acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true, eventMarkers: [taskId, eventType], verifySessionEventDelivery });
|
|
10970
11012
|
if (!delivery.ok) return finish({ ...delivery, eventKey, branch: taskRoute.branch, worktree: taskRoute.worktree, deliveryEvidencePath, evidencePath: routingMetadata.evidence_path });
|
|
10971
11013
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
10972
11014
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
@@ -10977,7 +11019,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10977
11019
|
const sessionId = String(existingSessionId);
|
|
10978
11020
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
10979
11021
|
if (typeof clickupClient?.updateTaskMetadata === "function") await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: metadataWithRouting });
|
|
10980
|
-
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, eventMarkers: [taskId, eventType], verifySessionEventDelivery, applyBlockerOnFailure: false });
|
|
11022
|
+
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, directPrompt: config.opencode?.promptDelivery === "http", acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true, eventMarkers: [taskId, eventType], verifySessionEventDelivery, applyBlockerOnFailure: false });
|
|
10981
11023
|
if (!delivery.ok) {
|
|
10982
11024
|
const recovery2 = await recoverClickUpPmSession({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, staleSessionId: sessionId, sessionTitle, taskRoute, metadataWithRouting, config, prompt, eventMarkers: [taskId, eventType], deliveryEvidencePath, evidencePath: routingMetadata.evidence_path, eventKey, createSession, verifySessionEventDelivery });
|
|
10983
11025
|
return finish(recovery2);
|
|
@@ -12365,13 +12407,14 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
|
|
|
12365
12407
|
syncGeneratedPolicies(worktree, repoCfg);
|
|
12366
12408
|
const operatingTeamMode = getOperatingTeamMode(repoCfg);
|
|
12367
12409
|
const clickUpWebhookValidation = normalizeClickUpWebhookConfig(pickConfiguredClickUp(input, repoCfg, resolvedPluginOptions), worktree);
|
|
12410
|
+
const runtimeClickUpClient = input.clickupClient || (clickUpWebhookValidation.config?.test === true ? createTestClickUpApiClient(clickUpWebhookValidation.config) : createClickUpApiClient(clickUpWebhookValidation.config, input.fetch));
|
|
12368
12411
|
let clickUpWebhookRuntime = { active: false, valid: false, reason: "not_configured" };
|
|
12369
12412
|
if (clickUpWebhookValidation.complete) {
|
|
12370
12413
|
try {
|
|
12371
12414
|
clickUpWebhookRuntime = await ensureClickUpWebhookSubscription({
|
|
12372
12415
|
validation: clickUpWebhookValidation,
|
|
12373
12416
|
worktree,
|
|
12374
|
-
clickupClient:
|
|
12417
|
+
clickupClient: runtimeClickUpClient
|
|
12375
12418
|
});
|
|
12376
12419
|
} catch (error) {
|
|
12377
12420
|
clickUpWebhookRuntime = { active: false, valid: false, reason: "subscription_failed", error: error.message };
|
|
@@ -12381,7 +12424,7 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
|
|
|
12381
12424
|
let clickUpWebhookActive = clickUpWebhookRuntime.active === true && clickUpWebhookRuntime.valid === true;
|
|
12382
12425
|
if (clickUpWebhookActive && input.startClickUpWebhookListener !== false) {
|
|
12383
12426
|
try {
|
|
12384
|
-
const lifecycleClickUpClient =
|
|
12427
|
+
const lifecycleClickUpClient = runtimeClickUpClient;
|
|
12385
12428
|
const listenerRegistry = input.clickUpWebhookListenerRegistry || activeClickUpWebhookListeners;
|
|
12386
12429
|
const listenerState = clickUpWebhookRuntime.state || readClickUpWebhookState(worktree, clickUpWebhookValidation.config);
|
|
12387
12430
|
const listener = startClickUpWebhookListener({
|
|
@@ -13054,7 +13097,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
13054
13097
|
}
|
|
13055
13098
|
};
|
|
13056
13099
|
}
|
|
13057
|
-
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, BUNDLE_ASSETS_DIR, CLICKUP_DEFINITION_DOC_PARENT, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentLedgerKey, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, compactPromptPath, createClickUpApiClient, createOpenCodeSession, createOpenCodeSessionControl, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, isSameOrNestedPath, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, promptOpenCodeSessionControl, probeOpenCodeSessionControl, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionControl, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveIncludeFile, resolveIncludes, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, summarizeOpenCodeMessages, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatRepairResult, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, optimaRepairDependencies, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, planOptimaRepair, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
13100
|
+
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, BUNDLE_ASSETS_DIR, CLICKUP_DEFINITION_DOC_PARENT, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentLedgerKey, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, compactPromptPath, createClickUpApiClient, createTestClickUpApiClient, createOpenCodeSession, createOpenCodeSessionControl, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, isSameOrNestedPath, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, promptOpenCodeSessionControl, probeOpenCodeSessionControl, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionControl, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveIncludeFile, resolveIncludes, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, summarizeOpenCodeMessages, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatRepairResult, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, optimaRepairDependencies, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, planOptimaRepair, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
13058
13101
|
export {
|
|
13059
13102
|
OptimaPlugin as default
|
|
13060
13103
|
};
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -9592,12 +9592,15 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
|
|
|
9592
9592
|
const ignoredStatuses = Array.isArray(routing.ignored_statuses) && routing.ignored_statuses.length > 0 ? routing.ignored_statuses : CLICKUP_WEBHOOK_TERMINAL_STATUSES;
|
|
9593
9593
|
const config = {
|
|
9594
9594
|
enabled: raw.enabled === true,
|
|
9595
|
+
test: raw.test === true || raw.test_mode === true || raw.testMode === true,
|
|
9595
9596
|
basePath: String(raw.base_path || raw.basePath || worktree || "").trim(),
|
|
9596
9597
|
teamId: String(raw.team_id || raw.teamId || "").trim(),
|
|
9597
9598
|
apiToken: String(raw.api_token || raw.apiToken || "").trim(),
|
|
9598
9599
|
log: normalizeClickUpWebhookLogLevel(raw.log),
|
|
9599
9600
|
opencode: {
|
|
9600
9601
|
baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl),
|
|
9602
|
+
promptDelivery: ["http", "direct"].includes(String(opencode.prompt_delivery || opencode.promptDelivery || raw.prompt_delivery || raw.promptDelivery || "").trim().toLowerCase()) ? "http" : "sdk",
|
|
9603
|
+
acceptPromptAdmission: opencode.accept_prompt_admission === true || opencode.acceptPromptAdmission === true || raw.accept_prompt_admission === true || raw.acceptPromptAdmission === true,
|
|
9601
9604
|
startupReconciliationDelayMs: normalizeNonNegativeInteger(
|
|
9602
9605
|
opencode.startup_reconciliation_delay_ms ?? opencode.startupReconciliationDelayMs ?? raw.startup_reconciliation_delay_ms ?? raw.startupReconciliationDelayMs,
|
|
9603
9606
|
CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS
|
|
@@ -9789,6 +9792,40 @@ function createClickUpApiClient(config, fetchImpl = globalThis.fetch) {
|
|
|
9789
9792
|
}
|
|
9790
9793
|
};
|
|
9791
9794
|
}
|
|
9795
|
+
function createTestClickUpApiClient(config) {
|
|
9796
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
9797
|
+
return {
|
|
9798
|
+
async createWebhook({ endpoint, events, location } = {}) {
|
|
9799
|
+
return {
|
|
9800
|
+
webhook: {
|
|
9801
|
+
id: "optima-test-webhook",
|
|
9802
|
+
endpoint: endpoint || config.webhook.publicUrl,
|
|
9803
|
+
events: events || config.webhook.events,
|
|
9804
|
+
location: location || config.webhook.location,
|
|
9805
|
+
secret: "optima-test-secret",
|
|
9806
|
+
active: true
|
|
9807
|
+
}
|
|
9808
|
+
};
|
|
9809
|
+
},
|
|
9810
|
+
async getTask(taskId) {
|
|
9811
|
+
return null;
|
|
9812
|
+
},
|
|
9813
|
+
async updateTaskMetadata({ taskId, value }) {
|
|
9814
|
+
metadata.set(String(taskId || ""), value);
|
|
9815
|
+
return { ok: true };
|
|
9816
|
+
},
|
|
9817
|
+
async postTaskComment() {
|
|
9818
|
+
return { ok: true };
|
|
9819
|
+
},
|
|
9820
|
+
async addTaskTag() {
|
|
9821
|
+
return { ok: true };
|
|
9822
|
+
},
|
|
9823
|
+
async listAssignedTasks() {
|
|
9824
|
+
return { tasks: [] };
|
|
9825
|
+
},
|
|
9826
|
+
__metadata: metadata
|
|
9827
|
+
};
|
|
9828
|
+
}
|
|
9792
9829
|
function normalizeClickUpWebhookApiResponse(response = {}, fallbackConfig = null) {
|
|
9793
9830
|
const webhook = response?.webhook || response?.data || response || {};
|
|
9794
9831
|
const healthStatus = String(webhook.health?.status || webhook.health_status || "").trim().toLowerCase();
|
|
@@ -10619,9 +10656,9 @@ function openCodeBlockingPromptVerification(result, sessionId) {
|
|
|
10619
10656
|
if (parts.length > 0 || messageId) return { ok: true, method: parts.length > 0 ? "blocking_prompt_parts" : "blocking_prompt_message", messageId: messageId ? String(messageId) : null, sessionId: deliveredSessionId ? String(deliveredSessionId) : String(sessionId), parts: parts.length };
|
|
10620
10657
|
return null;
|
|
10621
10658
|
}
|
|
10622
|
-
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
10659
|
+
async function deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent, text, directory, opencodeBaseUrl, directPrompt = false, acceptPromptAdmission = false, eventMarkers = [], verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, applyBlockerOnFailure = true } = {}) {
|
|
10623
10660
|
const beforeMessages = await readOpenCodeSessionMessages(openCodeClient, { sessionId, directory, limit: 50 }).catch(() => null);
|
|
10624
|
-
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, allowDirectFallback:
|
|
10661
|
+
const sendResult = await sendSessionEvent(openCodeClient, { sessionId, agent, text, directory, opencodeBaseUrl, direct: directPrompt, allowDirectFallback: directPrompt });
|
|
10625
10662
|
let blockingPromptVerification = null;
|
|
10626
10663
|
let admissionVerification = null;
|
|
10627
10664
|
try {
|
|
@@ -10634,6 +10671,9 @@ async function deliverClickUpSessionEventWithVerification({ openCodeClient, send
|
|
|
10634
10671
|
return { ok: false, action: "message_delivery_failed", reason: error.message, taskId, sessionId, fallbackAttempted: false, blockerTag: blocker2 };
|
|
10635
10672
|
}
|
|
10636
10673
|
if (blockingPromptVerification) return { ok: true, verification: blockingPromptVerification, admissionVerification: null, fallback: false };
|
|
10674
|
+
if (admissionVerification && acceptPromptAdmission) {
|
|
10675
|
+
return { ok: true, verification: admissionVerification, admissionVerification, fallback: false, admissionOnly: true };
|
|
10676
|
+
}
|
|
10637
10677
|
let verification = await verifySessionEventDelivery(openCodeClient, { sessionId, directory, beforeMessages, expectedText: text, markers: eventMarkers });
|
|
10638
10678
|
if (verification?.ok) return { ok: true, verification, admissionVerification, fallback: false };
|
|
10639
10679
|
if (admissionVerification) {
|
|
@@ -10671,6 +10711,8 @@ async function recoverClickUpPmSession({ openCodeClient, sendSessionEvent, click
|
|
|
10671
10711
|
text: prompt,
|
|
10672
10712
|
directory: taskRoute.worktree,
|
|
10673
10713
|
opencodeBaseUrl: config.opencode?.baseUrl,
|
|
10714
|
+
directPrompt: config.opencode?.promptDelivery === "http",
|
|
10715
|
+
acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true,
|
|
10674
10716
|
eventMarkers,
|
|
10675
10717
|
verifySessionEventDelivery,
|
|
10676
10718
|
applyBlockerOnFailure: false
|
|
@@ -10937,7 +10979,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10937
10979
|
const subtaskId = parentTaskId && parentTaskId !== taskId ? taskId : "";
|
|
10938
10980
|
let taskRoute;
|
|
10939
10981
|
try {
|
|
10940
|
-
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" });
|
|
10982
|
+
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" || config.test === true });
|
|
10941
10983
|
} catch (error) {
|
|
10942
10984
|
const message = `Optima webhook could not create or reuse a task worktree for ${taskId}: ${error.message}`;
|
|
10943
10985
|
appendClickUpWebhookLocalLog(worktree, { type: "task_worktree_failed", taskId, message });
|
|
@@ -10973,7 +11015,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10973
11015
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
10974
11016
|
throw error;
|
|
10975
11017
|
}
|
|
10976
|
-
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, eventMarkers: [taskId, eventType], verifySessionEventDelivery });
|
|
11018
|
+
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, directPrompt: config.opencode?.promptDelivery === "http", acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true, eventMarkers: [taskId, eventType], verifySessionEventDelivery });
|
|
10977
11019
|
if (!delivery.ok) return finish({ ...delivery, eventKey, branch: taskRoute.branch, worktree: taskRoute.worktree, deliveryEvidencePath, evidencePath: routingMetadata.evidence_path });
|
|
10978
11020
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
10979
11021
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
@@ -10984,7 +11026,7 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
10984
11026
|
const sessionId = String(existingSessionId);
|
|
10985
11027
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
10986
11028
|
if (typeof clickupClient?.updateTaskMetadata === "function") await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: metadataWithRouting });
|
|
10987
|
-
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, eventMarkers: [taskId, eventType], verifySessionEventDelivery, applyBlockerOnFailure: false });
|
|
11029
|
+
const delivery = await deliverClickUpSessionEventWithVerification({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl, directPrompt: config.opencode?.promptDelivery === "http", acceptPromptAdmission: config.opencode?.acceptPromptAdmission === true, eventMarkers: [taskId, eventType], verifySessionEventDelivery, applyBlockerOnFailure: false });
|
|
10988
11030
|
if (!delivery.ok) {
|
|
10989
11031
|
const recovery2 = await recoverClickUpPmSession({ openCodeClient, sendSessionEvent, clickupClient, worktree, taskId, staleSessionId: sessionId, sessionTitle, taskRoute, metadataWithRouting, config, prompt, eventMarkers: [taskId, eventType], deliveryEvidencePath, evidencePath: routingMetadata.evidence_path, eventKey, createSession, verifySessionEventDelivery });
|
|
10990
11032
|
return finish(recovery2);
|
|
@@ -12372,13 +12414,14 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
|
|
|
12372
12414
|
syncGeneratedPolicies(worktree, repoCfg);
|
|
12373
12415
|
const operatingTeamMode = getOperatingTeamMode(repoCfg);
|
|
12374
12416
|
const clickUpWebhookValidation = normalizeClickUpWebhookConfig(pickConfiguredClickUp(input, repoCfg, resolvedPluginOptions), worktree);
|
|
12417
|
+
const runtimeClickUpClient = input.clickupClient || (clickUpWebhookValidation.config?.test === true ? createTestClickUpApiClient(clickUpWebhookValidation.config) : createClickUpApiClient(clickUpWebhookValidation.config, input.fetch));
|
|
12375
12418
|
let clickUpWebhookRuntime = { active: false, valid: false, reason: "not_configured" };
|
|
12376
12419
|
if (clickUpWebhookValidation.complete) {
|
|
12377
12420
|
try {
|
|
12378
12421
|
clickUpWebhookRuntime = await ensureClickUpWebhookSubscription({
|
|
12379
12422
|
validation: clickUpWebhookValidation,
|
|
12380
12423
|
worktree,
|
|
12381
|
-
clickupClient:
|
|
12424
|
+
clickupClient: runtimeClickUpClient
|
|
12382
12425
|
});
|
|
12383
12426
|
} catch (error) {
|
|
12384
12427
|
clickUpWebhookRuntime = { active: false, valid: false, reason: "subscription_failed", error: error.message };
|
|
@@ -12388,7 +12431,7 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
|
|
|
12388
12431
|
let clickUpWebhookActive = clickUpWebhookRuntime.active === true && clickUpWebhookRuntime.valid === true;
|
|
12389
12432
|
if (clickUpWebhookActive && input.startClickUpWebhookListener !== false) {
|
|
12390
12433
|
try {
|
|
12391
|
-
const lifecycleClickUpClient =
|
|
12434
|
+
const lifecycleClickUpClient = runtimeClickUpClient;
|
|
12392
12435
|
const listenerRegistry = input.clickUpWebhookListenerRegistry || activeClickUpWebhookListeners;
|
|
12393
12436
|
const listenerState = clickUpWebhookRuntime.state || readClickUpWebhookState(worktree, clickUpWebhookValidation.config);
|
|
12394
12437
|
const listener = startClickUpWebhookListener({
|
|
@@ -13061,7 +13104,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
13061
13104
|
}
|
|
13062
13105
|
};
|
|
13063
13106
|
}
|
|
13064
|
-
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, BUNDLE_ASSETS_DIR, CLICKUP_DEFINITION_DOC_PARENT, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentLedgerKey, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, compactPromptPath, createClickUpApiClient, createOpenCodeSession, createOpenCodeSessionControl, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, isSameOrNestedPath, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, promptOpenCodeSessionControl, probeOpenCodeSessionControl, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionControl, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveIncludeFile, resolveIncludes, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, summarizeOpenCodeMessages, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatRepairResult, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, optimaRepairDependencies, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, planOptimaRepair, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
13107
|
+
OptimaPlugin.__internals = { BUNDLE_AGENTS_DIR, BUNDLE_ASSETS_DIR, CLICKUP_DEFINITION_DOC_PARENT, activeClickUpWebhookLifecycleRegistry, cleanupManagedClickUpWebhook, deleteClickUpWebhookBestEffort, BUNDLE_POLICIES_DIR, buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentLedgerKey, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, compactPromptPath, createClickUpApiClient, createTestClickUpApiClient, createOpenCodeSession, createOpenCodeSessionControl, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, isSameOrNestedPath, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, promptOpenCodeSessionControl, probeOpenCodeSessionControl, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionControl, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveIncludeFile, resolveIncludes, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, summarizeOpenCodeMessages, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, startClickUpWebhookListener, validateClickUpWebhookState, verifyClickUpSignature, writeClickUpWebhookState, decideClickUpStatusAction, deriveClickUpBranchName, deriveClickUpPendingSubtaskBranch, deriveClickUpPrTarget, deriveClickUpWorktree, determineClickUpMergeAuthority, ensureOptimaGitignoreRules, explicitSafeInputWorktree, finalApprovalAssignees, formatRepairResult, formatValidationResult, isIgnoredClickUpTaskType, isOptimaPluginPackageWorktree, isSafeWritableDirectory, loadHumansRegistry, mergeClickUpAgentMetadata, mergeClickUpSessionMetadata, migrateLegacyOptimaLayout, normalizeAgentMetadataJson, normalizeClickUpStatus, normalizeClickUpTaskType, normalizePromptResponseParts, normalizeWorkflowTaskPath, optimaRepairDependencies, parseClickUpSubtasksMarkdown, parseHumansRegistry, parseMarkdownArtifact, parseMarkdownSections, planOptimaRepair, preEstimateClickUpWork, readMarkdownArtifact, resolveHumanRoles, resolveSafeWorktree, safeWorktreeOrFailure, stripRawLogSections, validateMainWorkspaceBranchSafety, workflowFinalMessageFromPromptResponse };
|
|
13065
13108
|
|
|
13066
13109
|
// src/sanitize_cli.js
|
|
13067
13110
|
var { migrateLegacyOptimaLayout: migrateLegacyOptimaLayout2 } = OptimaPlugin.__internals;
|