@defend-tech/opencode-optima 0.1.13 → 0.1.15

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
@@ -9207,10 +9207,32 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
9207
9207
  const result = await client.session.create({ query: { directory }, body: { title } });
9208
9208
  return result?.data?.id || result?.id;
9209
9209
  }
9210
+ async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
9211
+ try {
9212
+ return await method({ sessionID: sessionId, ...flatPayload });
9213
+ } catch (flatError) {
9214
+ try {
9215
+ return await method({ ...structuredPayload, path: { sessionID: sessionId } });
9216
+ } catch {
9217
+ try {
9218
+ return await method({ ...structuredPayload, path: { id: sessionId } });
9219
+ } catch {
9220
+ throw flatError;
9221
+ }
9222
+ }
9223
+ }
9224
+ }
9210
9225
  async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
9211
- const payload = { path: { id: sessionId }, query: { directory }, body: { agent, parts: [{ type: "text", text }] } };
9212
- if (typeof client?.session?.promptAsync === "function") return client.session.promptAsync(payload);
9213
- return client.session.prompt(payload);
9226
+ const parts = [{ type: "text", text }];
9227
+ const flatPayload = { directory, agent, parts };
9228
+ const structuredPayload = { query: { directory }, body: { agent, parts } };
9229
+ if (typeof client?.session?.prompt === "function") {
9230
+ return callOpenCodePromptWithFallbacks(client.session.prompt.bind(client.session), sessionId, flatPayload, structuredPayload);
9231
+ }
9232
+ if (typeof client?.session?.promptAsync === "function") {
9233
+ return callOpenCodePromptWithFallbacks(client.session.promptAsync.bind(client.session), sessionId, flatPayload, structuredPayload);
9234
+ }
9235
+ throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
9214
9236
  }
9215
9237
  function formatClickUpWebhookPrompt({ eventType, taskId, payload }) {
9216
9238
  const comment = clickUpCommentFromPayload(payload);
@@ -9367,9 +9389,9 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
9367
9389
  appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
9368
9390
  throw error;
9369
9391
  }
9392
+ await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
9370
9393
  const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
9371
9394
  await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
9372
- await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
9373
9395
  const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
9374
9396
  stateToPersist = { ...stateToPersist, pendingSessions: remainingPending };
9375
9397
  return finish({ ok: true, action: "created_session", taskId, sessionId: pendingSessionId, eventKey });
@@ -11117,7 +11139,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
11117
11139
  }
11118
11140
  };
11119
11141
  }
11120
- OptimaPlugin.__internals = { buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, 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 };
11142
+ OptimaPlugin.__internals = { 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 };
11121
11143
  export {
11122
11144
  OptimaPlugin as default
11123
11145
  };
@@ -9214,10 +9214,32 @@ async function createOpenCodeSession(client, { title, directory } = {}) {
9214
9214
  const result = await client.session.create({ query: { directory }, body: { title } });
9215
9215
  return result?.data?.id || result?.id;
9216
9216
  }
9217
+ async function callOpenCodePromptWithFallbacks(method, sessionId, flatPayload, structuredPayload) {
9218
+ try {
9219
+ return await method({ sessionID: sessionId, ...flatPayload });
9220
+ } catch (flatError) {
9221
+ try {
9222
+ return await method({ ...structuredPayload, path: { sessionID: sessionId } });
9223
+ } catch {
9224
+ try {
9225
+ return await method({ ...structuredPayload, path: { id: sessionId } });
9226
+ } catch {
9227
+ throw flatError;
9228
+ }
9229
+ }
9230
+ }
9231
+ }
9217
9232
  async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, directory } = {}) {
9218
- const payload = { path: { id: sessionId }, query: { directory }, body: { agent, parts: [{ type: "text", text }] } };
9219
- if (typeof client?.session?.promptAsync === "function") return client.session.promptAsync(payload);
9220
- return client.session.prompt(payload);
9233
+ const parts = [{ type: "text", text }];
9234
+ const flatPayload = { directory, agent, parts };
9235
+ const structuredPayload = { query: { directory }, body: { agent, parts } };
9236
+ if (typeof client?.session?.prompt === "function") {
9237
+ return callOpenCodePromptWithFallbacks(client.session.prompt.bind(client.session), sessionId, flatPayload, structuredPayload);
9238
+ }
9239
+ if (typeof client?.session?.promptAsync === "function") {
9240
+ return callOpenCodePromptWithFallbacks(client.session.promptAsync.bind(client.session), sessionId, flatPayload, structuredPayload);
9241
+ }
9242
+ throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
9221
9243
  }
9222
9244
  function formatClickUpWebhookPrompt({ eventType, taskId, payload }) {
9223
9245
  const comment = clickUpCommentFromPayload(payload);
@@ -9374,9 +9396,9 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
9374
9396
  appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
9375
9397
  throw error;
9376
9398
  }
9399
+ await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
9377
9400
  const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
9378
9401
  await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
9379
- await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: config.basePath });
9380
9402
  const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
9381
9403
  stateToPersist = { ...stateToPersist, pendingSessions: remainingPending };
9382
9404
  return finish({ ok: true, action: "created_session", taskId, sessionId: pendingSessionId, eventKey });
@@ -11124,7 +11146,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
11124
11146
  }
11125
11147
  };
11126
11148
  }
11127
- OptimaPlugin.__internals = { buildClickUpApplyPayloadResult, buildClickUpCreateSubtasksPayload, buildClickUpStartTaskPayload, buildClickUpSummaryPayload, buildClickUpTransitionPayload, buildOptimaAgents, clickUpCommentMentionsProductManager, clickUpWebhookAuditLogDir, clickUpWebhookAuditLogPath, createClickUpApiClient, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, readClickUpWebhookState, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, 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 };
11149
+ OptimaPlugin.__internals = { 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 };
11128
11150
 
11129
11151
  // src/sanitize_cli.js
11130
11152
  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.13",
3
+ "version": "0.1.15",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+ssh://git@github.com/defend-tech/opencode-optima.git"