mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 08:02:32 +00:00
* refactor: split agent config and auth services * chore: repoint wsl and global-fetch guards at split module paths * fix: restore merge-base Claude CLI error propagation Drop the secret-redaction rewriting added to Claude CLI error paths in the refactor: spawn errors again reject with the original Error (preserving .code/.errno/.syscall/.stack) and command output/auth-status logs are no longer rewritten.
159 lines
5.8 KiB
TypeScript
159 lines
5.8 KiB
TypeScript
export function getStatusPluginDeliverySource(): string[] {
|
|
return [
|
|
'',
|
|
'function enqueueLifecycle(task) {',
|
|
' // Why: OpenCode intentionally fire-and-forgets hook promises, so async',
|
|
' // lookups and posts need their own FIFO to preserve event order.',
|
|
' const run = lifecycleQueue.then(async () => {',
|
|
' try {',
|
|
' await task();',
|
|
' } catch {',
|
|
' // Hook delivery must never reject into OpenCode.',
|
|
' }',
|
|
' });',
|
|
' lifecycleQueue = run;',
|
|
' return run;',
|
|
'}',
|
|
'',
|
|
'function clearStatusRetry() {',
|
|
' if (statusRetryTimer) clearTimeout(statusRetryTimer);',
|
|
' statusRetryTimer = null;',
|
|
'}',
|
|
'',
|
|
'function scheduleStatusRetry(revision) {',
|
|
' if (',
|
|
' statusRetryTimer ||',
|
|
' revision !== statusRevision ||',
|
|
' !statusDeliveryDirty ||',
|
|
' !activeFactoryIDs.has(desiredFactoryID)',
|
|
' ) return;',
|
|
' const delay = Math.min(',
|
|
' STATUS_RETRY_BASE_MS * Math.pow(2, Math.min(statusRetryAttempt, 6)),',
|
|
' STATUS_RETRY_MAX_MS',
|
|
' );',
|
|
' statusRetryAttempt = Math.min(statusRetryAttempt + 1, 7);',
|
|
' statusRetryTimer = setTimeout(() => {',
|
|
' statusRetryTimer = null;',
|
|
' void enqueueLifecycle(async () => {',
|
|
' if (',
|
|
' revision !== statusRevision ||',
|
|
' !statusDeliveryDirty ||',
|
|
' !activeFactoryIDs.has(desiredFactoryID)',
|
|
' ) return;',
|
|
' await publishDesiredStatus(revision);',
|
|
' });',
|
|
' }, delay);',
|
|
' if (statusRetryTimer.unref) statusRetryTimer.unref();',
|
|
'}',
|
|
'',
|
|
'async function publishDesiredStatus(revision) {',
|
|
' if (revision !== statusRevision) return;',
|
|
' if (!activeFactoryIDs.has(desiredFactoryID)) return;',
|
|
' const endpointKey = hookEndpointKey();',
|
|
' if (',
|
|
' !statusDeliveryDirty &&',
|
|
' deliveredStatusKey === desiredStatusKey &&',
|
|
' deliveredEndpointKey === endpointKey &&',
|
|
' deliveredMessagePartFactoryID === null',
|
|
' ) return;',
|
|
' const delivered = await post(desiredHookEventName, desiredStatusProperties);',
|
|
' if (revision !== statusRevision) return;',
|
|
' if (!delivered) {',
|
|
' statusDeliveryDirty = true;',
|
|
' scheduleStatusRetry(revision);',
|
|
' return;',
|
|
' }',
|
|
' clearStatusRetry();',
|
|
' statusRetryAttempt = 0;',
|
|
' deliveredStatusKey = desiredStatusKey;',
|
|
' deliveredEndpointKey = endpointKey;',
|
|
' deliveredMessagePartFactoryID = null;',
|
|
' statusDeliveryDirty = false;',
|
|
'}',
|
|
'',
|
|
'async function setDeliveryTarget(',
|
|
' next,',
|
|
' nextKey,',
|
|
' hookEventName,',
|
|
' extraProperties,',
|
|
' factoryID',
|
|
') {',
|
|
' const endpointChanged = deliveredEndpointKey !== hookEndpointKey();',
|
|
' if (',
|
|
' nextKey === desiredStatusKey &&',
|
|
' nextKey === deliveredStatusKey &&',
|
|
' desiredFactoryID === factoryID &&',
|
|
' !statusDeliveryDirty &&',
|
|
' !endpointChanged &&',
|
|
' deliveredMessagePartFactoryID === null',
|
|
' ) return;',
|
|
' const targetChanged = nextKey !== desiredStatusKey || desiredFactoryID !== factoryID;',
|
|
' clearStatusRetry();',
|
|
' if (targetChanged) {',
|
|
' statusRetryAttempt = 0;',
|
|
' busyRecoveryUsed = false;',
|
|
' busyRecoveryEndpointKey = "";',
|
|
' }',
|
|
' desiredStatus = next;',
|
|
' desiredHookEventName = hookEventName;',
|
|
' desiredStatusKey = nextKey;',
|
|
' desiredStatusProperties = extraProperties || {};',
|
|
' desiredFactoryID = factoryID;',
|
|
' statusDeliveryDirty =',
|
|
' statusDeliveryDirty ||',
|
|
' deliveredMessagePartFactoryID !== null ||',
|
|
' deliveredStatusKey !== nextKey ||',
|
|
' endpointChanged;',
|
|
' const revision = ++statusRevision;',
|
|
' await publishDesiredStatus(revision);',
|
|
'}',
|
|
'',
|
|
'async function setStatus(next, extraProperties, factoryID) {',
|
|
' const nextKey = next + ":" + (extraProperties?.sessionID || "");',
|
|
' const hookEventName = next === "busy" ? "SessionBusy" : "SessionIdle";',
|
|
' await setDeliveryTarget(next, nextKey, hookEventName, extraProperties, factoryID);',
|
|
'}',
|
|
'',
|
|
'async function setAttention(hookEventName, properties, factoryID, sourceSessionID) {',
|
|
' const requestID = properties?.id || properties?.sessionID || "";',
|
|
' const requestKey = attentionKey(factoryID, hookEventName, requestID, sourceSessionID);',
|
|
' await flushPendingAssistantPart(true);',
|
|
' await setDeliveryTarget(',
|
|
' "waiting",',
|
|
' "waiting:" + requestKey,',
|
|
' hookEventName,',
|
|
' properties,',
|
|
' factoryID',
|
|
' );',
|
|
'}',
|
|
'',
|
|
'function recoverBusyFromDelta(client, sessionID, factoryID) {',
|
|
' if (busyRecoveryQueued) return lifecycleQueue;',
|
|
' if (',
|
|
' busyRecoveryUsed &&',
|
|
' busyRecoveryEndpointKey === hookEndpointKey()',
|
|
' ) return lifecycleQueue;',
|
|
' busyRecoveryQueued = true;',
|
|
' return enqueueLifecycle(async () => {',
|
|
' try {',
|
|
' if (!activeFactoryIDs.has(factoryID)) return;',
|
|
' if (sessionID && (await isChildSession(client, sessionID)) === true) return;',
|
|
' if (!activeFactoryIDs.has(factoryID)) return;',
|
|
' const endpointKey = hookEndpointKey();',
|
|
' const endpointChanged = deliveredEndpointKey !== endpointKey;',
|
|
' if (desiredStatus !== "busy" || (!statusDeliveryDirty && !endpointChanged)) return;',
|
|
' if (busyRecoveryUsed && !endpointChanged) return;',
|
|
' busyRecoveryUsed = true;',
|
|
' busyRecoveryEndpointKey = endpointKey;',
|
|
' clearStatusRetry();',
|
|
' statusDeliveryDirty = true;',
|
|
' const revision = ++statusRevision;',
|
|
' await publishDesiredStatus(revision);',
|
|
' } finally {',
|
|
' busyRecoveryQueued = false;',
|
|
' }',
|
|
' });',
|
|
'}'
|
|
]
|
|
}
|