@@ -467,6 +467,19 @@ export interface ActiveShellIndexEntry extends Pick<
467467 readonly hasRemoteTasks : boolean ;
468468}
469469
470+ /** What thread listings filter and order an active thread by, without building its shell. */
471+ export type ActiveThreadListEntry = Pick <
472+ OrchestrationV2ThreadShell ,
473+ | "id"
474+ | "projectId"
475+ | "title"
476+ | "lineage"
477+ | "settledOverride"
478+ | "settledAt"
479+ | "snoozedUntil"
480+ | "updatedAt"
481+ > ;
482+
470483export interface OlderSettledThreadsQuery {
471484 readonly before : OrchestrationV2OlderSettledCursor ;
472485 readonly projectIds ?: ReadonlyArray < ProjectId > | undefined ;
@@ -567,6 +580,10 @@ export interface ProjectionStoreV2Shape {
567580 ReadonlyArray < ActiveShellIndexEntry > ,
568581 ProjectionStoreV2Error
569582 > ;
583+ /** Every active thread, or one project's. */
584+ readonly listActiveThreads : (
585+ projectId ?: ProjectId ,
586+ ) => Effect . Effect < ReadonlyArray < ActiveThreadListEntry > , ProjectionStoreV2Error > ;
570587 /** Older settled thread ids below a cursor, newest settle first, and per-project counts. */
571588 readonly listOlderSettledThreads : (
572589 query : OlderSettledThreadsQuery ,
@@ -1150,6 +1167,21 @@ const encodeTimelineSources = Schema.encodeEffect(
11501167 Schema . Array ( Schema . Struct ( { threadId : Schema . String , id : Schema . NullOr ( Schema . String ) } ) ) ,
11511168 ) ,
11521169) ;
1170+ const shellIndexLineage = ( row : {
1171+ readonly relationship_to_parent : string | null ;
1172+ readonly parent_thread_id : string | null ;
1173+ readonly root_thread_id : string ;
1174+ readonly side_chat : number | null ;
1175+ } ) : OrchestrationV2ThreadShell [ "lineage" ] => ( {
1176+ parentThreadId : row . parent_thread_id === null ? null : ThreadId . make ( row . parent_thread_id ) ,
1177+ relationshipToParent :
1178+ row . relationship_to_parent === "fork" || row . relationship_to_parent === "subagent"
1179+ ? row . relationship_to_parent
1180+ : null ,
1181+ rootThreadId : ThreadId . make ( row . root_thread_id ) ,
1182+ ...( row . side_chat === null ? { } : { sideChat : row . side_chat === 1 } ) ,
1183+ } ) ;
1184+
11531185const encodeIdList = Schema . encodeSync ( Schema . fromJsonString ( Schema . Array ( Schema . String ) ) ) ;
11541186
11551187// Empty filters still scan SQLite rows; short-circuit them, including turnItemTypes: [].
@@ -8770,16 +8802,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
87708802 return rows . map ( ( row ) : ActiveShellIndexEntry => ( {
87718803 id : ThreadId . make ( row . thread_id ) ,
87728804 projectId : ProjectId . make ( row . project_id ) ,
8773- lineage : {
8774- parentThreadId :
8775- row . parent_thread_id === null ? null : ThreadId . make ( row . parent_thread_id ) ,
8776- relationshipToParent :
8777- row . relationship_to_parent === "fork" || row . relationship_to_parent === "subagent"
8778- ? row . relationship_to_parent
8779- : null ,
8780- rootThreadId : ThreadId . make ( row . root_thread_id ) ,
8781- ...( row . side_chat === null ? { } : { sideChat : row . side_chat === 1 } ) ,
8782- } ,
8805+ lineage : shellIndexLineage ( row ) ,
87838806 settledOverride :
87848807 row . settled_override === "settled" || row . settled_override === "active"
87858808 ? row . settled_override
@@ -8792,6 +8815,53 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
87928815 } ) ) ;
87938816 } , Effect . mapError ( shellSnapshotReadError ) ) ;
87948817
8818+ const listActiveThreads = Effect . fn ( "ProjectionStore.listActiveThreads" ) ( function * (
8819+ projectId ?: ProjectId ,
8820+ ) {
8821+ const rows = yield * sql < {
8822+ readonly thread_id : string ;
8823+ readonly project_id : string ;
8824+ readonly title : string ;
8825+ readonly updated_at : string ;
8826+ readonly relationship_to_parent : string | null ;
8827+ readonly parent_thread_id : string | null ;
8828+ readonly root_thread_id : string ;
8829+ readonly side_chat : number | null ;
8830+ readonly settled_override : string | null ;
8831+ readonly settled_at : string | null ;
8832+ readonly snoozed_until : string | null ;
8833+ } > `
8834+ SELECT
8835+ t.thread_id,
8836+ t.project_id,
8837+ t.title,
8838+ t.updated_at,
8839+ json_extract(t.payload_json, '$.lineage.relationshipToParent') AS relationship_to_parent,
8840+ json_extract(t.payload_json, '$.lineage.parentThreadId') AS parent_thread_id,
8841+ json_extract(t.payload_json, '$.lineage.rootThreadId') AS root_thread_id,
8842+ json_extract(t.payload_json, '$.lineage.sideChat') AS side_chat,
8843+ json_extract(t.payload_json, '$.settledOverride') AS settled_override,
8844+ json_extract(t.payload_json, '$.settledAt') AS settled_at,
8845+ json_extract(t.payload_json, '$.snoozedUntil') AS snoozed_until
8846+ FROM orchestration_v2_projection_threads t
8847+ WHERE t.deleted_at IS NULL
8848+ AND t.archived_at IS NULL${ projectId === undefined ? sql `` : sql ` AND t.project_id = ${ projectId } ` }
8849+ ` ;
8850+ return rows . map ( ( row ) : ActiveThreadListEntry => ( {
8851+ id : ThreadId . make ( row . thread_id ) ,
8852+ projectId : ProjectId . make ( row . project_id ) ,
8853+ title : row . title ,
8854+ lineage : shellIndexLineage ( row ) ,
8855+ settledOverride :
8856+ row . settled_override === "settled" || row . settled_override === "active"
8857+ ? row . settled_override
8858+ : null ,
8859+ settledAt : row . settled_at === null ? null : DateTime . makeUnsafe ( row . settled_at ) ,
8860+ snoozedUntil : row . snoozed_until === null ? null : DateTime . makeUnsafe ( row . snoozed_until ) ,
8861+ updatedAt : DateTime . makeUnsafe ( row . updated_at ) ,
8862+ } ) ) ;
8863+ } , Effect . mapError ( shellSnapshotReadError ) ) ;
8864+
87958865 const getThreadLinkMetadata = Effect . fn ( "ProjectionStore.getThreadLinkMetadata" ) ( function * (
87968866 threadIds : ReadonlyArray < ThreadId > ,
87978867 ) {
@@ -8981,6 +9051,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
89819051 listActiveSubagentThreadIds : readOnReader ( listActiveSubagentThreadIds ) ,
89829052 countThreads : readOnReader ( countThreads ) ,
89839053 listActiveShellIndex : readOnReader ( listActiveShellIndex ) ,
9054+ listActiveThreads : readOnReader ( listActiveThreads ) ,
89849055 readShellSnapshot : readOnReader ( readShellSnapshot ) ,
89859056 listOlderSettledThreads : readOnReader ( listOlderSettledThreads ) ,
89869057 getThreadShell : readOnReader ( getThreadShell ) ,
0 commit comments