@defend-tech/opencode-optima 0.1.32 → 0.1.33
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 +104 -14
- package/dist/sanitize_cli.js +104 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7946,8 +7946,8 @@ var LEGACY_NOMADWORKS_DIRNAME = ".nomadworks";
|
|
|
7946
7946
|
var LEGACY_ORBITA_DIRNAME = ".orbita";
|
|
7947
7947
|
var LEGACY_STATICENG_DIRNAME = ".staticeng";
|
|
7948
7948
|
var OPTIMA_GITIGNORE_RULES = [
|
|
7949
|
-
".optima/",
|
|
7950
|
-
".optima/.config/",
|
|
7949
|
+
".optima/tasks/current.md",
|
|
7950
|
+
".optima/.config/runtime/*",
|
|
7951
7951
|
".optima/**/.env",
|
|
7952
7952
|
".optima/**/.env.*",
|
|
7953
7953
|
".optima/**/*.env",
|
|
@@ -8497,9 +8497,11 @@ function buildClickUpSummaryPayload({ summaryMarkdown = "", summaryPath = "", ta
|
|
|
8497
8497
|
["Open Risks", sectionValue(summarySections, ["Open Risks"])],
|
|
8498
8498
|
["Recommended Next Step", sectionValue(summarySections, ["Recommended Next Step"])]
|
|
8499
8499
|
];
|
|
8500
|
+
const deliveryPath = summaryPath.includes("docs/delivery/") ? summaryPath : "";
|
|
8500
8501
|
const contextParts = [
|
|
8501
8502
|
branchValue ? `- Branch: ${compactMarkdownValue(branchValue)}` : null,
|
|
8502
8503
|
worktreeValue ? `- Worktree: ${compactMarkdownValue(worktreeValue)}` : null,
|
|
8504
|
+
deliveryPath ? `- Delivery evidence: ${compactMarkdownValue(deliveryPath)}` : null,
|
|
8503
8505
|
prValue ? `- PR: ${compactMarkdownValue(prValue)}` : null
|
|
8504
8506
|
].filter(Boolean);
|
|
8505
8507
|
const comment = [
|
|
@@ -8524,7 +8526,8 @@ function buildClickUpSummaryPayload({ summaryMarkdown = "", summaryPath = "", ta
|
|
|
8524
8526
|
recommended_next_step: compactMarkdownValue(sectionValue(summarySections, ["Recommended Next Step"])),
|
|
8525
8527
|
branch: compactMarkdownValue(branchValue),
|
|
8526
8528
|
worktree: compactMarkdownValue(worktreeValue),
|
|
8527
|
-
pr: compactMarkdownValue(prValue)
|
|
8529
|
+
pr: compactMarkdownValue(prValue),
|
|
8530
|
+
delivery_evidence_path: compactMarkdownValue(deliveryPath)
|
|
8528
8531
|
}
|
|
8529
8532
|
},
|
|
8530
8533
|
parsed: { summary: summarySections, task: taskSections }
|
|
@@ -8535,6 +8538,60 @@ function deriveClickUpWorktree({ baseWorktree = "", taskId, taskType, parentTask
|
|
|
8535
8538
|
const root = baseWorktree || process.cwd();
|
|
8536
8539
|
return path2.join(path2.dirname(root), `${path2.basename(root)}-${branch.replace(/\//g, "-")}`);
|
|
8537
8540
|
}
|
|
8541
|
+
function clickUpCustomFieldValue(task = {}, names = []) {
|
|
8542
|
+
const fields = Array.isArray(task.custom_fields) ? task.custom_fields : [];
|
|
8543
|
+
const wanted = new Set(names.map((name) => normalizeLooseToken(name)));
|
|
8544
|
+
const field = fields.find((item) => wanted.has(normalizeLooseToken(item?.name || item?.id || "")));
|
|
8545
|
+
return field?.value ?? "";
|
|
8546
|
+
}
|
|
8547
|
+
function clickUpTaskType(task = {}, fallback = "Tarea") {
|
|
8548
|
+
return task.type || task.task_type || task.taskType || clickUpCustomFieldValue(task, ["Type", "Tipo", "Task Type"]) || fallback;
|
|
8549
|
+
}
|
|
8550
|
+
function clickUpParentTaskId(task = {}) {
|
|
8551
|
+
return task.parent || task.parent_id || task.parentId || task.parent_task_id || task.parentTaskId || "";
|
|
8552
|
+
}
|
|
8553
|
+
function deliveryEvidencePathForClickUpTask(taskId) {
|
|
8554
|
+
return `docs/delivery/${branchSafeClickUpId(taskId)}/SUMMARY.md`;
|
|
8555
|
+
}
|
|
8556
|
+
function metadataTaskRouting(metadata = {}) {
|
|
8557
|
+
return isPlainObject(metadata.task) ? metadata.task : {};
|
|
8558
|
+
}
|
|
8559
|
+
function safeExistingClickUpWorktree({ metadata = {}, branch = "" } = {}) {
|
|
8560
|
+
const taskMetadata = metadataTaskRouting(metadata);
|
|
8561
|
+
const existingWorktree = typeof taskMetadata.worktree === "string" ? taskMetadata.worktree.trim() : "";
|
|
8562
|
+
const existingBranch = typeof taskMetadata.branch === "string" ? taskMetadata.branch.trim() : "";
|
|
8563
|
+
if (!existingWorktree || !path2.isAbsolute(existingWorktree) || !fs2.existsSync(existingWorktree)) return null;
|
|
8564
|
+
try {
|
|
8565
|
+
const stat = fs2.statSync(existingWorktree);
|
|
8566
|
+
if (!stat.isDirectory()) return null;
|
|
8567
|
+
if (branch && existingBranch && existingBranch !== branch) return null;
|
|
8568
|
+
return { branch: existingBranch || branch, worktree: path2.resolve(existingWorktree), reused: true };
|
|
8569
|
+
} catch {
|
|
8570
|
+
return null;
|
|
8571
|
+
}
|
|
8572
|
+
}
|
|
8573
|
+
function ensureClickUpTaskWorktree({ baseWorktree = "", taskId, taskType = "Tarea", parentTaskId = "", subtaskId = "", existingMetadata = {}, runGitFn = runGit, allowNonGitFallback = false } = {}) {
|
|
8574
|
+
const effectiveParent = parentTaskId || taskId;
|
|
8575
|
+
const branch = deriveClickUpBranchName({ taskType, parentTaskId: effectiveParent, subtaskId, taskId });
|
|
8576
|
+
const existing = safeExistingClickUpWorktree({ metadata: existingMetadata, branch });
|
|
8577
|
+
if (existing) return { ...existing, branch };
|
|
8578
|
+
const worktreePath = deriveClickUpWorktree({ baseWorktree, taskId, taskType, parentTaskId: effectiveParent, subtaskId });
|
|
8579
|
+
if (fs2.existsSync(worktreePath)) return { branch, worktree: path2.resolve(worktreePath), reused: true };
|
|
8580
|
+
if (allowNonGitFallback) {
|
|
8581
|
+
fs2.mkdirSync(worktreePath, { recursive: true });
|
|
8582
|
+
return { branch, worktree: path2.resolve(worktreePath), reused: false, fallback: "non_git" };
|
|
8583
|
+
}
|
|
8584
|
+
const startPoint = (() => {
|
|
8585
|
+
try {
|
|
8586
|
+
runGitFn(baseWorktree, ["rev-parse", "--verify", "dev"]);
|
|
8587
|
+
return "dev";
|
|
8588
|
+
} catch {
|
|
8589
|
+
return "origin/dev";
|
|
8590
|
+
}
|
|
8591
|
+
})();
|
|
8592
|
+
runGitFn(baseWorktree, ["worktree", "add", "-b", branch, worktreePath, startPoint]);
|
|
8593
|
+
return { branch, worktree: path2.resolve(worktreePath), reused: false, startPoint };
|
|
8594
|
+
}
|
|
8538
8595
|
function normalizeClickUpDefinitionDocParent(parent = {}) {
|
|
8539
8596
|
const docId = String(parent.doc_id || parent.docId || CLICKUP_DEFINITION_DOC_PARENT.doc_id).trim();
|
|
8540
8597
|
const pageId = String(parent.page_id || parent.pageId || CLICKUP_DEFINITION_DOC_PARENT.page_id).trim();
|
|
@@ -8564,6 +8621,7 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8564
8621
|
worktree,
|
|
8565
8622
|
mirror_task_path: `.optima/tasks/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}.md`,
|
|
8566
8623
|
evidence_path: `.optima/evidences/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}/SUMMARY.md`,
|
|
8624
|
+
delivery_evidence_path: deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent),
|
|
8567
8625
|
...agentMetadata
|
|
8568
8626
|
}
|
|
8569
8627
|
});
|
|
@@ -8574,7 +8632,8 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8574
8632
|
required_first_actions: [
|
|
8575
8633
|
"Create or reuse the task-specific branch/worktree before planning or writing local .optima mirrors.",
|
|
8576
8634
|
`Use branch ${branch} from dev and worktree ${worktree} for this task workspace.`,
|
|
8577
|
-
"Write planning state, .optima/tasks/current.md, task mirrors, and evidence only inside the task worktree.",
|
|
8635
|
+
"Write planning state, .optima/tasks/current.md, task mirrors, and local evidence only inside the task worktree.",
|
|
8636
|
+
`Write merge-trackable final evidence under ${deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent)}; .optima remains local mirror/staging.`,
|
|
8578
8637
|
"Do not update the principal dev workspace .optima/tasks/current.md for ClickUp task planning.",
|
|
8579
8638
|
"If another active task is present in current.md, move to or create this task worktree instead of stopping."
|
|
8580
8639
|
],
|
|
@@ -8587,13 +8646,14 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8587
8646
|
mirror: {
|
|
8588
8647
|
taskPath: `.optima/tasks/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}.md`,
|
|
8589
8648
|
evidenceSummaryPath: `.optima/evidences/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}/SUMMARY.md`,
|
|
8649
|
+
deliveryEvidencePath: deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent),
|
|
8590
8650
|
workspace: "task_worktree_only",
|
|
8591
8651
|
principalWorkspaceCurrentMd: "do_not_update",
|
|
8592
8652
|
currentMdConflictPolicy: "move_to_or_create_task_worktree",
|
|
8593
8653
|
wouldCreate: true
|
|
8594
8654
|
},
|
|
8595
8655
|
clickup: {
|
|
8596
|
-
comment: `Starting task from dev. Branch: ${branch}. Worktree: ${worktree}.`,
|
|
8656
|
+
comment: `Starting task from dev. Branch: ${branch}. Worktree: ${worktree}. Delivery evidence: ${deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent)}.`,
|
|
8597
8657
|
description,
|
|
8598
8658
|
fields: {
|
|
8599
8659
|
Definition: definitionContent,
|
|
@@ -9384,6 +9444,11 @@ function clickUpPendingSessionKey(metadataKey) {
|
|
|
9384
9444
|
function mergeClickUpPendingSessionMetadata(existing, metadataKey, sessionId) {
|
|
9385
9445
|
return mergeClickUpSessionMetadata(existing, clickUpPendingSessionKey(metadataKey), sessionId);
|
|
9386
9446
|
}
|
|
9447
|
+
function setClickUpTaskRoutingMetadata(existing, routing = {}) {
|
|
9448
|
+
const root = normalizeAgentMetadataJson(existing);
|
|
9449
|
+
root.task = { ...isPlainObject(root.task) ? root.task : {}, ...routing };
|
|
9450
|
+
return JSON.stringify(sortJsonValue(root), null, 2);
|
|
9451
|
+
}
|
|
9387
9452
|
function setClickUpSessionMetadata(existing, metadataKey, sessionId) {
|
|
9388
9453
|
const root = normalizeAgentMetadataJson(existing);
|
|
9389
9454
|
const parts = String(metadataKey || CLICKUP_PM_METADATA_KEY).split(".").filter(Boolean);
|
|
@@ -9478,16 +9543,20 @@ async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, direct
|
|
|
9478
9543
|
if (directBaseUrl) return sendOpenCodeSessionEventDirect({ baseUrl: directBaseUrl, sessionId, text, fetchImpl });
|
|
9479
9544
|
throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
|
|
9480
9545
|
}
|
|
9481
|
-
function formatClickUpWebhookPrompt({ eventType, taskId, payload }) {
|
|
9546
|
+
function formatClickUpWebhookPrompt({ eventType, taskId, payload, branch = "", worktree = "", deliveryEvidencePath = "" }) {
|
|
9482
9547
|
const comment = clickUpCommentFromPayload(payload);
|
|
9483
9548
|
const commentText = clickUpCommentText(comment).trim();
|
|
9484
9549
|
return [
|
|
9485
9550
|
"[ClickUp Webhook Event]",
|
|
9486
9551
|
`Event: ${eventType}`,
|
|
9487
9552
|
`Task ID: ${taskId}`,
|
|
9553
|
+
branch ? `Branch: ${branch}` : null,
|
|
9554
|
+
worktree ? `Worktree: ${worktree}` : null,
|
|
9555
|
+
deliveryEvidencePath ? `Delivery evidence path: ${deliveryEvidencePath}` : null,
|
|
9488
9556
|
commentText ? `Comment: ${commentText}` : null,
|
|
9489
9557
|
"",
|
|
9490
|
-
"Handle this ClickUp Product Manager event using the ClickUp-first workflow rules. Do not assume broad chat routing; this event passed Optima webhook gates."
|
|
9558
|
+
"Handle this ClickUp Product Manager event using the ClickUp-first workflow rules. Do not assume broad chat routing; this event passed Optima webhook gates.",
|
|
9559
|
+
deliveryEvidencePath ? `Final merge-trackable evidence must be written under ${deliveryEvidencePath}; use .optima only as local mirror/staging.` : null
|
|
9491
9560
|
].filter((part) => part !== null).join("\n");
|
|
9492
9561
|
}
|
|
9493
9562
|
function appendClickUpWebhookLocalLog(worktree, entry) {
|
|
@@ -9666,7 +9735,7 @@ async function withClickUpTaskRouteLock(taskId, operation) {
|
|
|
9666
9735
|
if (activeClickUpTaskRoutes.get(key) === current) activeClickUpTaskRoutes.delete(key);
|
|
9667
9736
|
}
|
|
9668
9737
|
}
|
|
9669
|
-
async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, saveState = null, now = () => /* @__PURE__ */ new Date(), host = os.hostname(), commentLedgerPath = clickUpCommentLedgerPath(worktree) } = {}) {
|
|
9738
|
+
async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, ensureTaskWorktree = ensureClickUpTaskWorktree, saveState = null, now = () => /* @__PURE__ */ new Date(), host = os.hostname(), commentLedgerPath = clickUpCommentLedgerPath(worktree) } = {}) {
|
|
9670
9739
|
const eventType = clickUpEventType(payload);
|
|
9671
9740
|
const eventKey = clickUpWebhookEventKey(payload);
|
|
9672
9741
|
const remembered = rememberClickUpWebhookEvent(state, eventKey);
|
|
@@ -9714,11 +9783,31 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9714
9783
|
const existingMetadata = clickUpTaskAgentMetadata(task, config.routing.metadataFieldId);
|
|
9715
9784
|
const metadata = normalizeAgentMetadataJson(existingMetadata);
|
|
9716
9785
|
const existingSessionId = getNestedMetadataValue(metadata, config.routing.metadataKey);
|
|
9717
|
-
const
|
|
9786
|
+
const taskType = clickUpTaskType(task);
|
|
9787
|
+
const parentTaskId = clickUpParentTaskId(task) || taskId;
|
|
9788
|
+
const subtaskId = parentTaskId && parentTaskId !== taskId ? taskId : "";
|
|
9789
|
+
let taskRoute;
|
|
9790
|
+
try {
|
|
9791
|
+
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" });
|
|
9792
|
+
} catch (error) {
|
|
9793
|
+
const message = `Optima webhook could not create or reuse a task worktree for ${taskId}: ${error.message}`;
|
|
9794
|
+
appendClickUpWebhookLocalLog(worktree, { type: "task_worktree_failed", taskId, message });
|
|
9795
|
+
if (typeof clickupClient?.postTaskComment === "function") await clickupClient.postTaskComment({ taskId, comment: message });
|
|
9796
|
+
return { ok: false, action: "error", reason: "task_worktree_failed", taskId, message };
|
|
9797
|
+
}
|
|
9798
|
+
const deliveryEvidencePath = deliveryEvidencePathForClickUpTask(taskId);
|
|
9799
|
+
const routingMetadata = {
|
|
9800
|
+
branch: taskRoute.branch,
|
|
9801
|
+
worktree: taskRoute.worktree,
|
|
9802
|
+
delivery_evidence_path: deliveryEvidencePath,
|
|
9803
|
+
evidence_path: `.optima/evidences/${branchSafeClickUpId(taskId)}/SUMMARY.md`
|
|
9804
|
+
};
|
|
9805
|
+
const metadataWithRouting = setClickUpTaskRoutingMetadata(existingMetadata, routingMetadata);
|
|
9806
|
+
const prompt = formatClickUpWebhookPrompt({ eventType, taskId, payload, branch: taskRoute.branch, worktree: taskRoute.worktree, deliveryEvidencePath });
|
|
9718
9807
|
if (!existingSessionId) {
|
|
9719
9808
|
let pendingSessionId = getNestedMetadataValue(metadata, clickUpPendingSessionKey(config.routing.metadataKey)) || state.pendingSessions?.[taskId];
|
|
9720
9809
|
if (!pendingSessionId) {
|
|
9721
|
-
pendingSessionId = await createSession(openCodeClient, { title: sessionTitle, directory:
|
|
9810
|
+
pendingSessionId = await createSession(openCodeClient, { title: sessionTitle, directory: taskRoute.worktree, agent: config.routing.targetAgent });
|
|
9722
9811
|
if (!String(pendingSessionId || "").startsWith("ses_")) return { ok: false, action: "error", reason: "session_create_failed", taskId };
|
|
9723
9812
|
if (saveState) {
|
|
9724
9813
|
saveState({
|
|
@@ -9727,14 +9816,14 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9727
9816
|
});
|
|
9728
9817
|
}
|
|
9729
9818
|
}
|
|
9730
|
-
const pendingMetadata = mergeClickUpPendingSessionMetadata(
|
|
9819
|
+
const pendingMetadata = mergeClickUpPendingSessionMetadata(metadataWithRouting, config.routing.metadataKey, pendingSessionId);
|
|
9731
9820
|
try {
|
|
9732
9821
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: pendingMetadata });
|
|
9733
9822
|
} catch (error) {
|
|
9734
9823
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
9735
9824
|
throw error;
|
|
9736
9825
|
}
|
|
9737
|
-
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory:
|
|
9826
|
+
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9738
9827
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
9739
9828
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
9740
9829
|
const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
|
|
@@ -9743,7 +9832,8 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9743
9832
|
}
|
|
9744
9833
|
const sessionId = String(existingSessionId);
|
|
9745
9834
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
9746
|
-
|
|
9835
|
+
if (typeof clickupClient?.updateTaskMetadata === "function") await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: metadataWithRouting });
|
|
9836
|
+
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9747
9837
|
return finish({ ok: true, action: "sent_to_existing_session", taskId, sessionId, eventKey });
|
|
9748
9838
|
}
|
|
9749
9839
|
const at = now().toISOString();
|
|
@@ -11515,7 +11605,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
11515
11605
|
}
|
|
11516
11606
|
};
|
|
11517
11607
|
}
|
|
11518
|
-
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, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpCommentLedger, readClickUpWebhookState, recordClickUpCommentVersionProcessed, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, 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 };
|
|
11608
|
+
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, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpCommentLedger, readClickUpWebhookState, recordClickUpCommentVersionProcessed, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, 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 };
|
|
11519
11609
|
export {
|
|
11520
11610
|
OptimaPlugin as default
|
|
11521
11611
|
};
|
package/dist/sanitize_cli.js
CHANGED
|
@@ -7953,8 +7953,8 @@ var LEGACY_NOMADWORKS_DIRNAME = ".nomadworks";
|
|
|
7953
7953
|
var LEGACY_ORBITA_DIRNAME = ".orbita";
|
|
7954
7954
|
var LEGACY_STATICENG_DIRNAME = ".staticeng";
|
|
7955
7955
|
var OPTIMA_GITIGNORE_RULES = [
|
|
7956
|
-
".optima/",
|
|
7957
|
-
".optima/.config/",
|
|
7956
|
+
".optima/tasks/current.md",
|
|
7957
|
+
".optima/.config/runtime/*",
|
|
7958
7958
|
".optima/**/.env",
|
|
7959
7959
|
".optima/**/.env.*",
|
|
7960
7960
|
".optima/**/*.env",
|
|
@@ -8504,9 +8504,11 @@ function buildClickUpSummaryPayload({ summaryMarkdown = "", summaryPath = "", ta
|
|
|
8504
8504
|
["Open Risks", sectionValue(summarySections, ["Open Risks"])],
|
|
8505
8505
|
["Recommended Next Step", sectionValue(summarySections, ["Recommended Next Step"])]
|
|
8506
8506
|
];
|
|
8507
|
+
const deliveryPath = summaryPath.includes("docs/delivery/") ? summaryPath : "";
|
|
8507
8508
|
const contextParts = [
|
|
8508
8509
|
branchValue ? `- Branch: ${compactMarkdownValue(branchValue)}` : null,
|
|
8509
8510
|
worktreeValue ? `- Worktree: ${compactMarkdownValue(worktreeValue)}` : null,
|
|
8511
|
+
deliveryPath ? `- Delivery evidence: ${compactMarkdownValue(deliveryPath)}` : null,
|
|
8510
8512
|
prValue ? `- PR: ${compactMarkdownValue(prValue)}` : null
|
|
8511
8513
|
].filter(Boolean);
|
|
8512
8514
|
const comment = [
|
|
@@ -8531,7 +8533,8 @@ function buildClickUpSummaryPayload({ summaryMarkdown = "", summaryPath = "", ta
|
|
|
8531
8533
|
recommended_next_step: compactMarkdownValue(sectionValue(summarySections, ["Recommended Next Step"])),
|
|
8532
8534
|
branch: compactMarkdownValue(branchValue),
|
|
8533
8535
|
worktree: compactMarkdownValue(worktreeValue),
|
|
8534
|
-
pr: compactMarkdownValue(prValue)
|
|
8536
|
+
pr: compactMarkdownValue(prValue),
|
|
8537
|
+
delivery_evidence_path: compactMarkdownValue(deliveryPath)
|
|
8535
8538
|
}
|
|
8536
8539
|
},
|
|
8537
8540
|
parsed: { summary: summarySections, task: taskSections }
|
|
@@ -8542,6 +8545,60 @@ function deriveClickUpWorktree({ baseWorktree = "", taskId, taskType, parentTask
|
|
|
8542
8545
|
const root = baseWorktree || process.cwd();
|
|
8543
8546
|
return path2.join(path2.dirname(root), `${path2.basename(root)}-${branch.replace(/\//g, "-")}`);
|
|
8544
8547
|
}
|
|
8548
|
+
function clickUpCustomFieldValue(task = {}, names = []) {
|
|
8549
|
+
const fields = Array.isArray(task.custom_fields) ? task.custom_fields : [];
|
|
8550
|
+
const wanted = new Set(names.map((name) => normalizeLooseToken(name)));
|
|
8551
|
+
const field = fields.find((item) => wanted.has(normalizeLooseToken(item?.name || item?.id || "")));
|
|
8552
|
+
return field?.value ?? "";
|
|
8553
|
+
}
|
|
8554
|
+
function clickUpTaskType(task = {}, fallback = "Tarea") {
|
|
8555
|
+
return task.type || task.task_type || task.taskType || clickUpCustomFieldValue(task, ["Type", "Tipo", "Task Type"]) || fallback;
|
|
8556
|
+
}
|
|
8557
|
+
function clickUpParentTaskId(task = {}) {
|
|
8558
|
+
return task.parent || task.parent_id || task.parentId || task.parent_task_id || task.parentTaskId || "";
|
|
8559
|
+
}
|
|
8560
|
+
function deliveryEvidencePathForClickUpTask(taskId) {
|
|
8561
|
+
return `docs/delivery/${branchSafeClickUpId(taskId)}/SUMMARY.md`;
|
|
8562
|
+
}
|
|
8563
|
+
function metadataTaskRouting(metadata = {}) {
|
|
8564
|
+
return isPlainObject(metadata.task) ? metadata.task : {};
|
|
8565
|
+
}
|
|
8566
|
+
function safeExistingClickUpWorktree({ metadata = {}, branch = "" } = {}) {
|
|
8567
|
+
const taskMetadata = metadataTaskRouting(metadata);
|
|
8568
|
+
const existingWorktree = typeof taskMetadata.worktree === "string" ? taskMetadata.worktree.trim() : "";
|
|
8569
|
+
const existingBranch = typeof taskMetadata.branch === "string" ? taskMetadata.branch.trim() : "";
|
|
8570
|
+
if (!existingWorktree || !path2.isAbsolute(existingWorktree) || !fs2.existsSync(existingWorktree)) return null;
|
|
8571
|
+
try {
|
|
8572
|
+
const stat = fs2.statSync(existingWorktree);
|
|
8573
|
+
if (!stat.isDirectory()) return null;
|
|
8574
|
+
if (branch && existingBranch && existingBranch !== branch) return null;
|
|
8575
|
+
return { branch: existingBranch || branch, worktree: path2.resolve(existingWorktree), reused: true };
|
|
8576
|
+
} catch {
|
|
8577
|
+
return null;
|
|
8578
|
+
}
|
|
8579
|
+
}
|
|
8580
|
+
function ensureClickUpTaskWorktree({ baseWorktree = "", taskId, taskType = "Tarea", parentTaskId = "", subtaskId = "", existingMetadata = {}, runGitFn = runGit, allowNonGitFallback = false } = {}) {
|
|
8581
|
+
const effectiveParent = parentTaskId || taskId;
|
|
8582
|
+
const branch = deriveClickUpBranchName({ taskType, parentTaskId: effectiveParent, subtaskId, taskId });
|
|
8583
|
+
const existing = safeExistingClickUpWorktree({ metadata: existingMetadata, branch });
|
|
8584
|
+
if (existing) return { ...existing, branch };
|
|
8585
|
+
const worktreePath = deriveClickUpWorktree({ baseWorktree, taskId, taskType, parentTaskId: effectiveParent, subtaskId });
|
|
8586
|
+
if (fs2.existsSync(worktreePath)) return { branch, worktree: path2.resolve(worktreePath), reused: true };
|
|
8587
|
+
if (allowNonGitFallback) {
|
|
8588
|
+
fs2.mkdirSync(worktreePath, { recursive: true });
|
|
8589
|
+
return { branch, worktree: path2.resolve(worktreePath), reused: false, fallback: "non_git" };
|
|
8590
|
+
}
|
|
8591
|
+
const startPoint = (() => {
|
|
8592
|
+
try {
|
|
8593
|
+
runGitFn(baseWorktree, ["rev-parse", "--verify", "dev"]);
|
|
8594
|
+
return "dev";
|
|
8595
|
+
} catch {
|
|
8596
|
+
return "origin/dev";
|
|
8597
|
+
}
|
|
8598
|
+
})();
|
|
8599
|
+
runGitFn(baseWorktree, ["worktree", "add", "-b", branch, worktreePath, startPoint]);
|
|
8600
|
+
return { branch, worktree: path2.resolve(worktreePath), reused: false, startPoint };
|
|
8601
|
+
}
|
|
8545
8602
|
function normalizeClickUpDefinitionDocParent(parent = {}) {
|
|
8546
8603
|
const docId = String(parent.doc_id || parent.docId || CLICKUP_DEFINITION_DOC_PARENT.doc_id).trim();
|
|
8547
8604
|
const pageId = String(parent.page_id || parent.pageId || CLICKUP_DEFINITION_DOC_PARENT.page_id).trim();
|
|
@@ -8571,6 +8628,7 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8571
8628
|
worktree,
|
|
8572
8629
|
mirror_task_path: `.optima/tasks/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}.md`,
|
|
8573
8630
|
evidence_path: `.optima/evidences/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}/SUMMARY.md`,
|
|
8631
|
+
delivery_evidence_path: deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent),
|
|
8574
8632
|
...agentMetadata
|
|
8575
8633
|
}
|
|
8576
8634
|
});
|
|
@@ -8581,7 +8639,8 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8581
8639
|
required_first_actions: [
|
|
8582
8640
|
"Create or reuse the task-specific branch/worktree before planning or writing local .optima mirrors.",
|
|
8583
8641
|
`Use branch ${branch} from dev and worktree ${worktree} for this task workspace.`,
|
|
8584
|
-
"Write planning state, .optima/tasks/current.md, task mirrors, and evidence only inside the task worktree.",
|
|
8642
|
+
"Write planning state, .optima/tasks/current.md, task mirrors, and local evidence only inside the task worktree.",
|
|
8643
|
+
`Write merge-trackable final evidence under ${deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent)}; .optima remains local mirror/staging.`,
|
|
8585
8644
|
"Do not update the principal dev workspace .optima/tasks/current.md for ClickUp task planning.",
|
|
8586
8645
|
"If another active task is present in current.md, move to or create this task worktree instead of stopping."
|
|
8587
8646
|
],
|
|
@@ -8594,13 +8653,14 @@ function buildClickUpStartTaskPayload({ taskId, taskType = "Tarea", parentTaskId
|
|
|
8594
8653
|
mirror: {
|
|
8595
8654
|
taskPath: `.optima/tasks/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}.md`,
|
|
8596
8655
|
evidenceSummaryPath: `.optima/evidences/${branchSafeClickUpId(taskId || subtaskId || effectiveParent)}/SUMMARY.md`,
|
|
8656
|
+
deliveryEvidencePath: deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent),
|
|
8597
8657
|
workspace: "task_worktree_only",
|
|
8598
8658
|
principalWorkspaceCurrentMd: "do_not_update",
|
|
8599
8659
|
currentMdConflictPolicy: "move_to_or_create_task_worktree",
|
|
8600
8660
|
wouldCreate: true
|
|
8601
8661
|
},
|
|
8602
8662
|
clickup: {
|
|
8603
|
-
comment: `Starting task from dev. Branch: ${branch}. Worktree: ${worktree}.`,
|
|
8663
|
+
comment: `Starting task from dev. Branch: ${branch}. Worktree: ${worktree}. Delivery evidence: ${deliveryEvidencePathForClickUpTask(taskId || subtaskId || effectiveParent)}.`,
|
|
8604
8664
|
description,
|
|
8605
8665
|
fields: {
|
|
8606
8666
|
Definition: definitionContent,
|
|
@@ -9391,6 +9451,11 @@ function clickUpPendingSessionKey(metadataKey) {
|
|
|
9391
9451
|
function mergeClickUpPendingSessionMetadata(existing, metadataKey, sessionId) {
|
|
9392
9452
|
return mergeClickUpSessionMetadata(existing, clickUpPendingSessionKey(metadataKey), sessionId);
|
|
9393
9453
|
}
|
|
9454
|
+
function setClickUpTaskRoutingMetadata(existing, routing = {}) {
|
|
9455
|
+
const root = normalizeAgentMetadataJson(existing);
|
|
9456
|
+
root.task = { ...isPlainObject(root.task) ? root.task : {}, ...routing };
|
|
9457
|
+
return JSON.stringify(sortJsonValue(root), null, 2);
|
|
9458
|
+
}
|
|
9394
9459
|
function setClickUpSessionMetadata(existing, metadataKey, sessionId) {
|
|
9395
9460
|
const root = normalizeAgentMetadataJson(existing);
|
|
9396
9461
|
const parts = String(metadataKey || CLICKUP_PM_METADATA_KEY).split(".").filter(Boolean);
|
|
@@ -9485,16 +9550,20 @@ async function sendOpenCodeSessionEvent(client, { sessionId, agent, text, direct
|
|
|
9485
9550
|
if (directBaseUrl) return sendOpenCodeSessionEventDirect({ baseUrl: directBaseUrl, sessionId, text, fetchImpl });
|
|
9486
9551
|
throw new Error("OpenCode client does not expose session.prompt or session.promptAsync.");
|
|
9487
9552
|
}
|
|
9488
|
-
function formatClickUpWebhookPrompt({ eventType, taskId, payload }) {
|
|
9553
|
+
function formatClickUpWebhookPrompt({ eventType, taskId, payload, branch = "", worktree = "", deliveryEvidencePath = "" }) {
|
|
9489
9554
|
const comment = clickUpCommentFromPayload(payload);
|
|
9490
9555
|
const commentText = clickUpCommentText(comment).trim();
|
|
9491
9556
|
return [
|
|
9492
9557
|
"[ClickUp Webhook Event]",
|
|
9493
9558
|
`Event: ${eventType}`,
|
|
9494
9559
|
`Task ID: ${taskId}`,
|
|
9560
|
+
branch ? `Branch: ${branch}` : null,
|
|
9561
|
+
worktree ? `Worktree: ${worktree}` : null,
|
|
9562
|
+
deliveryEvidencePath ? `Delivery evidence path: ${deliveryEvidencePath}` : null,
|
|
9495
9563
|
commentText ? `Comment: ${commentText}` : null,
|
|
9496
9564
|
"",
|
|
9497
|
-
"Handle this ClickUp Product Manager event using the ClickUp-first workflow rules. Do not assume broad chat routing; this event passed Optima webhook gates."
|
|
9565
|
+
"Handle this ClickUp Product Manager event using the ClickUp-first workflow rules. Do not assume broad chat routing; this event passed Optima webhook gates.",
|
|
9566
|
+
deliveryEvidencePath ? `Final merge-trackable evidence must be written under ${deliveryEvidencePath}; use .optima only as local mirror/staging.` : null
|
|
9498
9567
|
].filter((part) => part !== null).join("\n");
|
|
9499
9568
|
}
|
|
9500
9569
|
function appendClickUpWebhookLocalLog(worktree, entry) {
|
|
@@ -9673,7 +9742,7 @@ async function withClickUpTaskRouteLock(taskId, operation) {
|
|
|
9673
9742
|
if (activeClickUpTaskRoutes.get(key) === current) activeClickUpTaskRoutes.delete(key);
|
|
9674
9743
|
}
|
|
9675
9744
|
}
|
|
9676
|
-
async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, saveState = null, now = () => /* @__PURE__ */ new Date(), host = os.hostname(), commentLedgerPath = clickUpCommentLedgerPath(worktree) } = {}) {
|
|
9745
|
+
async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, worktree = process.cwd(), clickupClient, openCodeClient, sessionExists = openCodeSessionExists, createSession = createOpenCodeSession, sendSessionEvent = sendOpenCodeSessionEvent, ensureTaskWorktree = ensureClickUpTaskWorktree, saveState = null, now = () => /* @__PURE__ */ new Date(), host = os.hostname(), commentLedgerPath = clickUpCommentLedgerPath(worktree) } = {}) {
|
|
9677
9746
|
const eventType = clickUpEventType(payload);
|
|
9678
9747
|
const eventKey = clickUpWebhookEventKey(payload);
|
|
9679
9748
|
const remembered = rememberClickUpWebhookEvent(state, eventKey);
|
|
@@ -9721,11 +9790,31 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9721
9790
|
const existingMetadata = clickUpTaskAgentMetadata(task, config.routing.metadataFieldId);
|
|
9722
9791
|
const metadata = normalizeAgentMetadataJson(existingMetadata);
|
|
9723
9792
|
const existingSessionId = getNestedMetadataValue(metadata, config.routing.metadataKey);
|
|
9724
|
-
const
|
|
9793
|
+
const taskType = clickUpTaskType(task);
|
|
9794
|
+
const parentTaskId = clickUpParentTaskId(task) || taskId;
|
|
9795
|
+
const subtaskId = parentTaskId && parentTaskId !== taskId ? taskId : "";
|
|
9796
|
+
let taskRoute;
|
|
9797
|
+
try {
|
|
9798
|
+
taskRoute = ensureTaskWorktree({ baseWorktree: config.basePath, taskId, taskType, parentTaskId, subtaskId, existingMetadata: metadata, allowNonGitFallback: process.env.NODE_ENV === "test" });
|
|
9799
|
+
} catch (error) {
|
|
9800
|
+
const message = `Optima webhook could not create or reuse a task worktree for ${taskId}: ${error.message}`;
|
|
9801
|
+
appendClickUpWebhookLocalLog(worktree, { type: "task_worktree_failed", taskId, message });
|
|
9802
|
+
if (typeof clickupClient?.postTaskComment === "function") await clickupClient.postTaskComment({ taskId, comment: message });
|
|
9803
|
+
return { ok: false, action: "error", reason: "task_worktree_failed", taskId, message };
|
|
9804
|
+
}
|
|
9805
|
+
const deliveryEvidencePath = deliveryEvidencePathForClickUpTask(taskId);
|
|
9806
|
+
const routingMetadata = {
|
|
9807
|
+
branch: taskRoute.branch,
|
|
9808
|
+
worktree: taskRoute.worktree,
|
|
9809
|
+
delivery_evidence_path: deliveryEvidencePath,
|
|
9810
|
+
evidence_path: `.optima/evidences/${branchSafeClickUpId(taskId)}/SUMMARY.md`
|
|
9811
|
+
};
|
|
9812
|
+
const metadataWithRouting = setClickUpTaskRoutingMetadata(existingMetadata, routingMetadata);
|
|
9813
|
+
const prompt = formatClickUpWebhookPrompt({ eventType, taskId, payload, branch: taskRoute.branch, worktree: taskRoute.worktree, deliveryEvidencePath });
|
|
9725
9814
|
if (!existingSessionId) {
|
|
9726
9815
|
let pendingSessionId = getNestedMetadataValue(metadata, clickUpPendingSessionKey(config.routing.metadataKey)) || state.pendingSessions?.[taskId];
|
|
9727
9816
|
if (!pendingSessionId) {
|
|
9728
|
-
pendingSessionId = await createSession(openCodeClient, { title: sessionTitle, directory:
|
|
9817
|
+
pendingSessionId = await createSession(openCodeClient, { title: sessionTitle, directory: taskRoute.worktree, agent: config.routing.targetAgent });
|
|
9729
9818
|
if (!String(pendingSessionId || "").startsWith("ses_")) return { ok: false, action: "error", reason: "session_create_failed", taskId };
|
|
9730
9819
|
if (saveState) {
|
|
9731
9820
|
saveState({
|
|
@@ -9734,14 +9823,14 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9734
9823
|
});
|
|
9735
9824
|
}
|
|
9736
9825
|
}
|
|
9737
|
-
const pendingMetadata = mergeClickUpPendingSessionMetadata(
|
|
9826
|
+
const pendingMetadata = mergeClickUpPendingSessionMetadata(metadataWithRouting, config.routing.metadataKey, pendingSessionId);
|
|
9738
9827
|
try {
|
|
9739
9828
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: pendingMetadata });
|
|
9740
9829
|
} catch (error) {
|
|
9741
9830
|
appendClickUpWebhookLocalLog(worktree, { type: "pending_session_metadata_failed", taskId, sessionId: pendingSessionId, message: error.message });
|
|
9742
9831
|
throw error;
|
|
9743
9832
|
}
|
|
9744
|
-
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory:
|
|
9833
|
+
await sendSessionEvent(openCodeClient, { sessionId: pendingSessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9745
9834
|
const nextMetadata = clearClickUpPendingSessionMetadata(setClickUpSessionMetadata(pendingMetadata, config.routing.metadataKey, pendingSessionId), config.routing.metadataKey);
|
|
9746
9835
|
await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: nextMetadata });
|
|
9747
9836
|
const { [taskId]: _completedPending, ...remainingPending } = stateToPersist.pendingSessions || {};
|
|
@@ -9750,7 +9839,8 @@ async function routeClickUpWebhookEventUnlocked({ payload, config, state = {}, w
|
|
|
9750
9839
|
}
|
|
9751
9840
|
const sessionId = String(existingSessionId);
|
|
9752
9841
|
if (await sessionExists(openCodeClient, sessionId)) {
|
|
9753
|
-
|
|
9842
|
+
if (typeof clickupClient?.updateTaskMetadata === "function") await clickupClient.updateTaskMetadata({ taskId, fieldId: config.routing.metadataFieldId, value: metadataWithRouting });
|
|
9843
|
+
await sendSessionEvent(openCodeClient, { sessionId, agent: config.routing.targetAgent, text: prompt, directory: taskRoute.worktree, opencodeBaseUrl: config.opencode?.baseUrl });
|
|
9754
9844
|
return finish({ ok: true, action: "sent_to_existing_session", taskId, sessionId, eventKey });
|
|
9755
9845
|
}
|
|
9756
9846
|
const at = now().toISOString();
|
|
@@ -11522,7 +11612,7 @@ Follow-up: use optima_prompt_workflow with session_id '${sessionId}' to check in
|
|
|
11522
11612
|
}
|
|
11523
11613
|
};
|
|
11524
11614
|
}
|
|
11525
|
-
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, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpCommentLedger, readClickUpWebhookState, recordClickUpCommentVersionProcessed, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, 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 };
|
|
11615
|
+
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, deliveryEvidencePathForClickUpTask, ensureClickUpTaskWorktree, ensureClickUpWebhookSubscription, handleClickUpWebhookRequest, isClickUpWebhookStateActive, normalizeClickUpWebhookConfig, normalizeClickUpWebhookLogLevel, normalizeOpenCodeBaseUrl, readClickUpCommentLedger, readClickUpWebhookState, recordClickUpCommentVersionProcessed, resolveOptimaPluginOptions, resolveSecretReference, routeClickUpWebhookEvent, sendOpenCodeSessionEvent, sendOpenCodeSessionEventDirect, 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 };
|
|
11526
11616
|
|
|
11527
11617
|
// src/sanitize_cli.js
|
|
11528
11618
|
var { migrateLegacyOptimaLayout: migrateLegacyOptimaLayout2 } = OptimaPlugin.__internals;
|