@@ -424,6 +424,10 @@ export interface ProjectionStoreV2Shape {
424424 readonly getShellSnapshot : (
425425 options ?: ShellSnapshotOptions ,
426426 ) => Effect . Effect < OrchestrationV2ThreadShellSnapshot , ProjectionStoreV2Error > ;
427+ readonly listActiveSubagentThreadIds : ( ) => Effect . Effect <
428+ ReadonlyArray < ThreadId > ,
429+ ProjectionStoreV2Error
430+ > ;
427431 /**
428432 * Callers that combine the shell with other reads run this inside their own
429433 * transaction and the returned decode after it commits, so the shared
@@ -6430,6 +6434,20 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
64306434 . withTransaction ( readShellSnapshotRows ( options ) )
64316435 . pipe ( Effect . mapError ( shellSnapshotReadError ) , Effect . flatMap ( decodeShellSnapshot ) ) ;
64326436
6437+ const listActiveSubagentThreadIds = Effect . fn ( "ProjectionStore.listActiveSubagentThreadIds" ) (
6438+ function * ( ) {
6439+ const rows = yield * sql < { readonly thread_id : string } > `
6440+ SELECT thread_id
6441+ FROM orchestration_v2_projection_threads
6442+ WHERE deleted_at IS NULL
6443+ AND json_extract(payload_json, '$.archivedAt') IS NULL
6444+ AND json_extract(payload_json, '$.lineage.relationshipToParent') = 'subagent'
6445+ ` ;
6446+ return rows . map ( ( row ) => ThreadId . make ( row . thread_id ) ) ;
6447+ } ,
6448+ Effect . mapError ( shellSnapshotReadError ) ,
6449+ ) ;
6450+
64336451 const getThreadShell : ProjectionStoreV2Shape [ "getThreadShell" ] = ( threadId ) =>
64346452 sql
64356453 . withTransaction (
@@ -6522,6 +6540,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
65226540 return {
65236541 apply,
65246542 getShellSnapshot : readOnReader ( getShellSnapshot ) ,
6543+ listActiveSubagentThreadIds : readOnReader ( listActiveSubagentThreadIds ) ,
65256544 readShellSnapshot : readOnReader ( readShellSnapshot ) ,
65266545 getThreadShell : readOnReader ( getThreadShell ) ,
65276546 getThread : readOnReader ( getThread ) ,
@@ -6630,6 +6649,19 @@ export const layerMemory: Layer.Layer<ProjectionStoreV2> = Layer.effect(
66306649 archivedThreads : visible . filter ( ( thread ) => thread . archivedAt !== null ) ,
66316650 } ;
66326651 } ) ,
6652+ listActiveSubagentThreadIds : Effect . fn ( "ProjectionStore.listActiveSubagentThreadIds" ) (
6653+ function * ( ) {
6654+ const existing = ( yield * Ref . get ( replayState ) ) . projections ;
6655+ return [ ...existing . values ( ) ]
6656+ . filter (
6657+ ( { thread } ) =>
6658+ thread . deletedAt === null &&
6659+ thread . archivedAt === null &&
6660+ thread . lineage . relationshipToParent === "subagent" ,
6661+ )
6662+ . map ( ( { thread } ) => thread . id ) ;
6663+ } ,
6664+ ) ,
66336665 readShellSnapshot : ( options ) =>
66346666 service . getShellSnapshot ( options ) . pipe ( Effect . map ( Effect . succeed ) ) ,
66356667 getThreadShell : Effect . fn ( "ProjectionStore.getThreadShell" ) ( function * ( threadId ) {
0 commit comments