@defend-tech/opencode-optima 0.1.49 → 0.1.50

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 CHANGED
@@ -7938,6 +7938,7 @@ var CLICKUP_WEBHOOK_MAX_BODY_BYTES = 1024 * 1024;
7938
7938
  var CLICKUP_WEBHOOK_REQUEST_TIMEOUT_MS = 1e4;
7939
7939
  var CLICKUP_WEBHOOK_STARTUP_TASK_LIMIT = 50;
7940
7940
  var CLICKUP_WEBHOOK_STARTUP_COMMENT_LIMIT = 100;
7941
+ var CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS = 3e4;
7941
7942
  var CLICKUP_WEBHOOK_LOG_LEVELS = /* @__PURE__ */ new Set(["error", "info", "verbose"]);
7942
7943
  var CLICKUP_WEBHOOK_REDACTED = "[REDACTED]";
7943
7944
  var DISCUSSION_BACKFILL_FETCH_LIMIT = 100;
@@ -9013,6 +9014,11 @@ function normalizeOpenCodeBaseUrl(value, defaultValue = "http://127.0.0.1:3001")
9013
9014
  return candidate.replace(/\/+$/, "");
9014
9015
  }
9015
9016
  }
9017
+ function normalizeNonNegativeInteger(value, defaultValue) {
9018
+ if (value === void 0 || value === null || value === "") return defaultValue;
9019
+ const number = Number(value);
9020
+ return Number.isInteger(number) && number >= 0 ? number : defaultValue;
9021
+ }
9016
9022
  function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd()) {
9017
9023
  const raw = isPlainObject(rawClickUp) ? rawClickUp : {};
9018
9024
  const webhook = isPlainObject(raw.webhook) ? raw.webhook : {};
@@ -9028,7 +9034,11 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
9028
9034
  apiToken: String(raw.api_token || raw.apiToken || "").trim(),
9029
9035
  log: normalizeClickUpWebhookLogLevel(raw.log),
9030
9036
  opencode: {
9031
- baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl)
9037
+ baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl),
9038
+ startupReconciliationDelayMs: normalizeNonNegativeInteger(
9039
+ opencode.startup_reconciliation_delay_ms ?? opencode.startupReconciliationDelayMs ?? raw.startup_reconciliation_delay_ms ?? raw.startupReconciliationDelayMs,
9040
+ CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS
9041
+ )
9032
9042
  },
9033
9043
  webhook: {
9034
9044
  publicUrl: String(webhook.public_url || webhook.publicUrl || "").trim(),
@@ -10259,11 +10269,44 @@ async function routeClickUpWebhookEvent(options = {}) {
10259
10269
  const taskId = clickUpTaskIdFromPayload(options.payload || {});
10260
10270
  return withClickUpTaskRouteLock(taskId, () => routeClickUpWebhookEventUnlocked(options));
10261
10271
  }
10272
+ function defaultStartupReconciliationScheduler(run, delayMs) {
10273
+ return setTimeout(run, delayMs);
10274
+ }
10275
+ function scheduleClickUpStartupReconciliation({ config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, scheduler = defaultStartupReconciliationScheduler, delayMs = config?.opencode?.startupReconciliationDelayMs ?? CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS, saveState = null, reconcile = reconcileClickUpStartup } = {}) {
10276
+ const normalizedDelayMs = normalizeNonNegativeInteger(delayMs, CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS);
10277
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_scheduled", delayMs: normalizedDelayMs, webhookId: state?.webhookId || null });
10278
+ const run = () => {
10279
+ Promise.resolve().then(() => reconcile({
10280
+ config,
10281
+ state,
10282
+ worktree,
10283
+ clickupClient,
10284
+ openCodeClient,
10285
+ saveState
10286
+ })).catch((error) => {
10287
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
10288
+ appendClickUpWebhookLocalLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
10289
+ });
10290
+ };
10291
+ const timer = scheduler(run, normalizedDelayMs);
10292
+ timer?.unref?.();
10293
+ return { scheduled: true, delayMs: normalizedDelayMs, timer };
10294
+ }
10262
10295
  async function reconcileClickUpStartup({ config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, waitForReadiness = waitForOpenCodeReadiness, saveState = null, now = () => /* @__PURE__ */ new Date(), limit = CLICKUP_WEBHOOK_STARTUP_TASK_LIMIT } = {}) {
10263
- if (!config || !clickupClient?.listAssignedTasks) return { ok: true, skipped: true, reason: "clickup_task_listing_unavailable", assigned: 0, comments: 0 };
10296
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_started", lastWebhookAt: state.lastWebhookAt || null });
10297
+ if (!config || !clickupClient?.listAssignedTasks) {
10298
+ const skipped = { ok: true, skipped: true, reason: "clickup_task_listing_unavailable", assigned: 0, comments: 0 };
10299
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_finished", ...skipped });
10300
+ return skipped;
10301
+ }
10264
10302
  const readiness = await waitForReadiness(openCodeClient, { worktree, now });
10265
10303
  appendClickUpWebhookLocalLog(worktree, { type: readiness.ok ? "startup_reconciliation_readiness_ready" : "startup_reconciliation_readiness_failed", ...readiness });
10266
- if (!readiness.ok) return { ok: false, skipped: true, reason: "opencode_not_ready", readiness, assigned: 0, comments: 0, ignored: 0, errors: 1, undelivered: 1, tasks: [], validation: { undelivered: 1, emptyPromptSessions: [] } };
10304
+ if (!readiness.ok) {
10305
+ const failed = { ok: false, skipped: true, reason: "opencode_not_ready", readiness, assigned: 0, comments: 0, ignored: 0, errors: 1, undelivered: 1, tasks: [], validation: { undelivered: 1, emptyPromptSessions: [] } };
10306
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_failed", reason: failed.reason, readiness });
10307
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_finished", ...failed });
10308
+ return failed;
10309
+ }
10267
10310
  let authorizedUserId = "";
10268
10311
  if (clickupClient?.getAuthorizedUser) {
10269
10312
  try {
@@ -10281,7 +10324,6 @@ async function reconcileClickUpStartup({ config, state = {}, worktree = process.
10281
10324
  const lastWebhookMs = clickUpTimestampMs(mutableState.lastWebhookAt);
10282
10325
  const ignored = new Set((config.routing?.ignoredStatuses || CLICKUP_WEBHOOK_TERMINAL_STATUSES).map(normalizeClickUpStatus));
10283
10326
  const routed = { assigned: 0, comments: 0, ignored: 0, errors: 0, undelivered: 0, tasks: [] };
10284
- clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_started", lastWebhookAt: state.lastWebhookAt || null });
10285
10327
  const listed = await clickupClient.listAssignedTasks({ assigneeId: config.routing.productManagerAssigneeId, limit });
10286
10328
  const tasks = clickUpTaskListItems(listed).slice(0, limit);
10287
10329
  for (const task of tasks) {
@@ -11599,18 +11641,16 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
11599
11641
  listener: { bindHost: clickUpWebhookValidation.config.webhook.bindHost, bindPort: clickUpWebhookValidation.config.webhook.bindPort, startedAt: (/* @__PURE__ */ new Date()).toISOString() }
11600
11642
  }, clickUpWebhookValidation.config);
11601
11643
  registerClickUpWebhookLifecycle({ config: clickUpWebhookValidation.config, state: activeState, worktree, clickupClient: lifecycleClickUpClient, listener: readyListener, listenerRegistry });
11602
- try {
11603
- await reconcileClickUpStartup({
11604
- config: clickUpWebhookValidation.config,
11605
- state: activeState,
11606
- worktree,
11607
- clickupClient: lifecycleClickUpClient,
11608
- openCodeClient: input.client,
11609
- saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, clickUpWebhookValidation.config)
11610
- });
11611
- } catch (error) {
11612
- appendClickUpWebhookLocalLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
11613
- }
11644
+ scheduleClickUpStartupReconciliation({
11645
+ config: clickUpWebhookValidation.config,
11646
+ state: activeState,
11647
+ worktree,
11648
+ clickupClient: lifecycleClickUpClient,
11649
+ openCodeClient: input.client,
11650
+ scheduler: input.startupReconciliationScheduler,
11651
+ delayMs: input.startupReconciliationDelayMs,
11652
+ saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, clickUpWebhookValidation.config)
11653
+ });
11614
11654
  } else {
11615
11655
  clickUpWebhookLifecycleLog(worktree, { type: "remote_webhook_preserved", reason: readyListener.reason || "listener_unavailable", webhookId: listenerState.webhookId });
11616
11656
  markClickUpWebhookInactive(worktree, listenerState, clickUpWebhookValidation.config);
@@ -12185,7 +12225,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
12185
12225
  }
12186
12226
  };
12187
12227
  }
12188
- 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, createClickUpApiClient, createOpenCodeSession, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionMessages, reconcileClickUpStartup, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, 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 };
12228
+ 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, createClickUpApiClient, createOpenCodeSession, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, 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 };
12189
12229
  export {
12190
12230
  OptimaPlugin as default
12191
12231
  };
@@ -7945,6 +7945,7 @@ var CLICKUP_WEBHOOK_MAX_BODY_BYTES = 1024 * 1024;
7945
7945
  var CLICKUP_WEBHOOK_REQUEST_TIMEOUT_MS = 1e4;
7946
7946
  var CLICKUP_WEBHOOK_STARTUP_TASK_LIMIT = 50;
7947
7947
  var CLICKUP_WEBHOOK_STARTUP_COMMENT_LIMIT = 100;
7948
+ var CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS = 3e4;
7948
7949
  var CLICKUP_WEBHOOK_LOG_LEVELS = /* @__PURE__ */ new Set(["error", "info", "verbose"]);
7949
7950
  var CLICKUP_WEBHOOK_REDACTED = "[REDACTED]";
7950
7951
  var DISCUSSION_BACKFILL_FETCH_LIMIT = 100;
@@ -9020,6 +9021,11 @@ function normalizeOpenCodeBaseUrl(value, defaultValue = "http://127.0.0.1:3001")
9020
9021
  return candidate.replace(/\/+$/, "");
9021
9022
  }
9022
9023
  }
9024
+ function normalizeNonNegativeInteger(value, defaultValue) {
9025
+ if (value === void 0 || value === null || value === "") return defaultValue;
9026
+ const number = Number(value);
9027
+ return Number.isInteger(number) && number >= 0 ? number : defaultValue;
9028
+ }
9023
9029
  function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd()) {
9024
9030
  const raw = isPlainObject(rawClickUp) ? rawClickUp : {};
9025
9031
  const webhook = isPlainObject(raw.webhook) ? raw.webhook : {};
@@ -9035,7 +9041,11 @@ function normalizeClickUpWebhookConfig(rawClickUp = null, worktree = process.cwd
9035
9041
  apiToken: String(raw.api_token || raw.apiToken || "").trim(),
9036
9042
  log: normalizeClickUpWebhookLogLevel(raw.log),
9037
9043
  opencode: {
9038
- baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl)
9044
+ baseUrl: normalizeOpenCodeBaseUrl(opencode.base_url || opencode.baseUrl || raw.opencode_base_url || raw.opencodeBaseUrl),
9045
+ startupReconciliationDelayMs: normalizeNonNegativeInteger(
9046
+ opencode.startup_reconciliation_delay_ms ?? opencode.startupReconciliationDelayMs ?? raw.startup_reconciliation_delay_ms ?? raw.startupReconciliationDelayMs,
9047
+ CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS
9048
+ )
9039
9049
  },
9040
9050
  webhook: {
9041
9051
  publicUrl: String(webhook.public_url || webhook.publicUrl || "").trim(),
@@ -10266,11 +10276,44 @@ async function routeClickUpWebhookEvent(options = {}) {
10266
10276
  const taskId = clickUpTaskIdFromPayload(options.payload || {});
10267
10277
  return withClickUpTaskRouteLock(taskId, () => routeClickUpWebhookEventUnlocked(options));
10268
10278
  }
10279
+ function defaultStartupReconciliationScheduler(run, delayMs) {
10280
+ return setTimeout(run, delayMs);
10281
+ }
10282
+ function scheduleClickUpStartupReconciliation({ config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, scheduler = defaultStartupReconciliationScheduler, delayMs = config?.opencode?.startupReconciliationDelayMs ?? CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS, saveState = null, reconcile = reconcileClickUpStartup } = {}) {
10283
+ const normalizedDelayMs = normalizeNonNegativeInteger(delayMs, CLICKUP_WEBHOOK_STARTUP_RECONCILIATION_DELAY_MS);
10284
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_scheduled", delayMs: normalizedDelayMs, webhookId: state?.webhookId || null });
10285
+ const run = () => {
10286
+ Promise.resolve().then(() => reconcile({
10287
+ config,
10288
+ state,
10289
+ worktree,
10290
+ clickupClient,
10291
+ openCodeClient,
10292
+ saveState
10293
+ })).catch((error) => {
10294
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
10295
+ appendClickUpWebhookLocalLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
10296
+ });
10297
+ };
10298
+ const timer = scheduler(run, normalizedDelayMs);
10299
+ timer?.unref?.();
10300
+ return { scheduled: true, delayMs: normalizedDelayMs, timer };
10301
+ }
10269
10302
  async function reconcileClickUpStartup({ config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, verifySessionEventDelivery = verifyOpenCodeSessionEventDelivery, waitForReadiness = waitForOpenCodeReadiness, saveState = null, now = () => /* @__PURE__ */ new Date(), limit = CLICKUP_WEBHOOK_STARTUP_TASK_LIMIT } = {}) {
10270
- if (!config || !clickupClient?.listAssignedTasks) return { ok: true, skipped: true, reason: "clickup_task_listing_unavailable", assigned: 0, comments: 0 };
10303
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_started", lastWebhookAt: state.lastWebhookAt || null });
10304
+ if (!config || !clickupClient?.listAssignedTasks) {
10305
+ const skipped = { ok: true, skipped: true, reason: "clickup_task_listing_unavailable", assigned: 0, comments: 0 };
10306
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_finished", ...skipped });
10307
+ return skipped;
10308
+ }
10271
10309
  const readiness = await waitForReadiness(openCodeClient, { worktree, now });
10272
10310
  appendClickUpWebhookLocalLog(worktree, { type: readiness.ok ? "startup_reconciliation_readiness_ready" : "startup_reconciliation_readiness_failed", ...readiness });
10273
- if (!readiness.ok) return { ok: false, skipped: true, reason: "opencode_not_ready", readiness, assigned: 0, comments: 0, ignored: 0, errors: 1, undelivered: 1, tasks: [], validation: { undelivered: 1, emptyPromptSessions: [] } };
10311
+ if (!readiness.ok) {
10312
+ const failed = { ok: false, skipped: true, reason: "opencode_not_ready", readiness, assigned: 0, comments: 0, ignored: 0, errors: 1, undelivered: 1, tasks: [], validation: { undelivered: 1, emptyPromptSessions: [] } };
10313
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_failed", reason: failed.reason, readiness });
10314
+ clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_finished", ...failed });
10315
+ return failed;
10316
+ }
10274
10317
  let authorizedUserId = "";
10275
10318
  if (clickupClient?.getAuthorizedUser) {
10276
10319
  try {
@@ -10288,7 +10331,6 @@ async function reconcileClickUpStartup({ config, state = {}, worktree = process.
10288
10331
  const lastWebhookMs = clickUpTimestampMs(mutableState.lastWebhookAt);
10289
10332
  const ignored = new Set((config.routing?.ignoredStatuses || CLICKUP_WEBHOOK_TERMINAL_STATUSES).map(normalizeClickUpStatus));
10290
10333
  const routed = { assigned: 0, comments: 0, ignored: 0, errors: 0, undelivered: 0, tasks: [] };
10291
- clickUpWebhookLifecycleLog(worktree, { type: "startup_reconciliation_started", lastWebhookAt: state.lastWebhookAt || null });
10292
10334
  const listed = await clickupClient.listAssignedTasks({ assigneeId: config.routing.productManagerAssigneeId, limit });
10293
10335
  const tasks = clickUpTaskListItems(listed).slice(0, limit);
10294
10336
  for (const task of tasks) {
@@ -11606,18 +11648,16 @@ async function OptimaPlugin(input = {}, pluginOptions = {}) {
11606
11648
  listener: { bindHost: clickUpWebhookValidation.config.webhook.bindHost, bindPort: clickUpWebhookValidation.config.webhook.bindPort, startedAt: (/* @__PURE__ */ new Date()).toISOString() }
11607
11649
  }, clickUpWebhookValidation.config);
11608
11650
  registerClickUpWebhookLifecycle({ config: clickUpWebhookValidation.config, state: activeState, worktree, clickupClient: lifecycleClickUpClient, listener: readyListener, listenerRegistry });
11609
- try {
11610
- await reconcileClickUpStartup({
11611
- config: clickUpWebhookValidation.config,
11612
- state: activeState,
11613
- worktree,
11614
- clickupClient: lifecycleClickUpClient,
11615
- openCodeClient: input.client,
11616
- saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, clickUpWebhookValidation.config)
11617
- });
11618
- } catch (error) {
11619
- appendClickUpWebhookLocalLog(worktree, { type: "startup_reconciliation_failed", message: error.message });
11620
- }
11651
+ scheduleClickUpStartupReconciliation({
11652
+ config: clickUpWebhookValidation.config,
11653
+ state: activeState,
11654
+ worktree,
11655
+ clickupClient: lifecycleClickUpClient,
11656
+ openCodeClient: input.client,
11657
+ scheduler: input.startupReconciliationScheduler,
11658
+ delayMs: input.startupReconciliationDelayMs,
11659
+ saveState: (nextState) => writeClickUpWebhookState(worktree, nextState, clickUpWebhookValidation.config)
11660
+ });
11621
11661
  } else {
11622
11662
  clickUpWebhookLifecycleLog(worktree, { type: "remote_webhook_preserved", reason: readyListener.reason || "listener_unavailable", webhookId: listenerState.webhookId });
11623
11663
  markClickUpWebhookInactive(worktree, listenerState, clickUpWebhookValidation.config);
@@ -12192,7 +12232,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
12192
12232
  }
12193
12233
  };
12194
12234
  }
12195
- 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, createClickUpApiClient, createOpenCodeSession, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionMessages, reconcileClickUpStartup, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, 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 };
12235
+ 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, createClickUpApiClient, createOpenCodeSession, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, openCodeSessionExists, readClickUpCommentLedger, readClickUpWebhookState, readOpenCodeSessionMessages, reconcileClickUpStartup, scheduleClickUpStartupReconciliation, waitForOpenCodeReadiness, recordClickUpCommentVersionProcessed, resyncClickUpWebhookForSignatureDrift, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, verifyOpenCodeSessionEventDelivery, stableClickUpCommentVersionMarker, 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 };
12196
12236
 
12197
12237
  // src/sanitize_cli.js
12198
12238
  var { migrateLegacyOptimaLayout: migrateLegacyOptimaLayout2 } = OptimaPlugin.__internals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defend-tech/opencode-optima",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@github.com/defend-tech/opencode-optima.git"