@@ -11,6 +11,7 @@ import { getMainSessionID, subagentSessions } from "../../features/claude-code-s
1111import { findNearestMessageWithFields , MESSAGE_STORAGE } from "../../features/hook-message-injector"
1212import { log } from "../../shared/logger"
1313import { createSystemDirective , SYSTEM_DIRECTIVE_PREFIX , SystemDirectiveTypes } from "../../shared/system-directive"
14+ import { isCallerOrchestrator , getMessageDir } from "../../shared/session-utils"
1415import type { BackgroundManager } from "../../features/background-agent"
1516
1617export const HOOK_NAME = "atlas"
@@ -380,28 +381,6 @@ interface ToolExecuteAfterOutput {
380381 metadata : Record < string , unknown >
381382}
382383
383- function getMessageDir ( sessionID : string ) : string | null {
384- if ( ! existsSync ( MESSAGE_STORAGE ) ) return null
385-
386- const directPath = join ( MESSAGE_STORAGE , sessionID )
387- if ( existsSync ( directPath ) ) return directPath
388-
389- for ( const dir of readdirSync ( MESSAGE_STORAGE ) ) {
390- const sessionPath = join ( MESSAGE_STORAGE , dir , sessionID )
391- if ( existsSync ( sessionPath ) ) return sessionPath
392- }
393-
394- return null
395- }
396-
397- function isCallerOrchestrator ( sessionID ?: string ) : boolean {
398- if ( ! sessionID ) return false
399- const messageDir = getMessageDir ( sessionID )
400- if ( ! messageDir ) return false
401- const nearest = findNearestMessageWithFields ( messageDir )
402- return nearest ?. agent ?. toLowerCase ( ) === "atlas"
403- }
404-
405384interface SessionState {
406385 lastEventWasAbortError ?: boolean
407386 lastContinuationInjectedAt ?: number
@@ -672,7 +651,7 @@ export function createAtlasHook(
672651 if ( input . tool === "delegate_task" ) {
673652 const prompt = output . args . prompt as string | undefined
674653 if ( prompt && ! prompt . includes ( SYSTEM_DIRECTIVE_PREFIX ) ) {
675- output . args . prompt = prompt + `\n <system-reminder>${ SINGLE_TASK_DIRECTIVE } </system-reminder>`
654+ output . args . prompt = ` <system-reminder>${ SINGLE_TASK_DIRECTIVE } </system-reminder>\n` + prompt
676655 log ( `[${ HOOK_NAME } ] Injected single-task directive to delegate_task` , {
677656 sessionID : input . sessionID ,
678657 } )
0 commit comments