refactor: cleanup shared constants and add async SDK support for isCallerOrchestrator
- Use shared OPENCODE_STORAGE, MESSAGE_STORAGE, PART_STORAGE constants - Make isCallerOrchestrator async with SDK fallback for beta - Fix cache implementation using Symbol sentinel - Update atlas hooks and sisyphus-junior-notepad to use async isCallerOrchestrator
This commit is contained in:
@@ -3,10 +3,11 @@ import { join } from "node:path"
|
||||
import { getDataDir } from "./data-path"
|
||||
import { isOpenCodeVersionAtLeast, OPENCODE_SQLITE_VERSION } from "./opencode-version"
|
||||
|
||||
let cachedResult: boolean | null = null
|
||||
const NOT_CACHED = Symbol("NOT_CACHED")
|
||||
let cachedResult: boolean | typeof NOT_CACHED = NOT_CACHED
|
||||
|
||||
export function isSqliteBackend(): boolean {
|
||||
if (cachedResult !== null) {
|
||||
if (cachedResult !== NOT_CACHED) {
|
||||
return cachedResult
|
||||
}
|
||||
|
||||
@@ -19,5 +20,5 @@ export function isSqliteBackend(): boolean {
|
||||
}
|
||||
|
||||
export function resetSqliteBackendCache(): void {
|
||||
cachedResult = null
|
||||
cachedResult = NOT_CACHED
|
||||
}
|
||||
@@ -1,12 +1,22 @@
|
||||
import * as path from "node:path"
|
||||
import * as os from "node:os"
|
||||
import { existsSync, readdirSync } from "node:fs"
|
||||
import { join } from "node:path"
|
||||
import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../features/hook-message-injector"
|
||||
import { findNearestMessageWithFields, findNearestMessageWithFieldsFromSDK } from "../features/hook-message-injector"
|
||||
import { getMessageDir } from "./opencode-message-dir"
|
||||
import { isSqliteBackend } from "./opencode-storage-detection"
|
||||
import type { PluginInput } from "@opencode-ai/plugin"
|
||||
|
||||
export function isCallerOrchestrator(sessionID?: string): boolean {
|
||||
export async function isCallerOrchestrator(sessionID?: string, client?: PluginInput["client"]): Promise<boolean> {
|
||||
if (!sessionID) return false
|
||||
|
||||
// Beta mode: use SDK if client provided
|
||||
if (isSqliteBackend() && client) {
|
||||
try {
|
||||
const nearest = await findNearestMessageWithFieldsFromSDK(client, sessionID)
|
||||
return nearest?.agent?.toLowerCase() === "atlas"
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Stable mode: use JSON files
|
||||
const messageDir = getMessageDir(sessionID)
|
||||
if (!messageDir) return false
|
||||
const nearest = findNearestMessageWithFields(messageDir)
|
||||
|
||||
Reference in New Issue
Block a user