@@ -93,6 +93,7 @@ import * as SqlClient from "effect/sql/SqlClient";
9393import type * as Statement from "effect/sql/Statement" ;
9494
9595import { MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp" ;
96+ import { normalizeProjectPathForComparison } from "@t3tools/shared/path" ;
9697import { threadHtmlRenderAttachmentIds } from "../attachmentStore.ts" ;
9798import {
9899 isThreadHistoryUserTurn ,
@@ -973,6 +974,7 @@ type ShellThreadRow = {
973974 readonly thread_id : string ;
974975 readonly payload_json : string ;
975976 readonly forked_from_run_source_thread_id : string | null ;
977+ readonly worktree_path : string | null ;
976978 readonly latest_run_id : string | null ;
977979 readonly latest_run_status : string | null ;
978980 readonly latest_run_requested_at : string | null ;
@@ -6001,6 +6003,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60016003 THEN json_extract(t.payload_json, '$.forkedFrom.threadId')
60026004 ELSE NULL
60036005 END AS forked_from_run_source_thread_id,
6006+ json_extract(t.payload_json, '$.worktreePath') AS worktree_path,
60046007 presented.run_id AS latest_run_id,
60056008 presented.status AS latest_run_status,
60066009 presented.requested_at AS latest_run_requested_at,
@@ -6194,7 +6197,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
61946197 } ${
61956198 worktreePath === undefined
61966199 ? sql ``
6197- : sql ` AND json_extract(t.payload_json, '$.worktreePath') = ${ worktreePath } `
6200+ : // Loose match of any spelling of the path; readShellSnapshotRows keeps exact ones.
6201+ // SQLite's lower() folds only ASCII, so other paths always reach that check.
6202+ sql ` AND (json_extract(t.payload_json, '$.worktreePath') GLOB '*[^ -~]*'
6203+ OR lower(rtrim(replace(trim(json_extract(t.payload_json, '$.worktreePath')), '\\', '/'), '/'))
6204+ = lower(rtrim(replace(trim(${ worktreePath } ), '\\', '/'), '/')))`
61986205 } ${ threadIds === undefined ? sql `` : sql ` AND t.thread_id IN (SELECT value FROM json_each(${ encodeIdList ( threadIds ) } ))` }
61996206 ORDER BY t.updated_at ASC, t.thread_id ASC
62006207 ` ;
@@ -6734,7 +6741,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
67346741 const readShellSnapshotRows = Effect . fn ( "ProjectionStore.readShellSnapshotRows" ) ( function * (
67356742 options : ShellSnapshotOptions | undefined ,
67366743 ) {
6737- const targetThreadRows = yield * selectShellThreadRows ( undefined , options ) ;
6744+ const worktreeKey =
6745+ options ?. worktreePath === undefined
6746+ ? undefined
6747+ : normalizeProjectPathForComparison ( options . worktreePath ) ;
6748+ const targetThreadRows = ( yield * selectShellThreadRows ( undefined , options ) ) . filter (
6749+ ( row ) =>
6750+ worktreeKey === undefined ||
6751+ ( row . worktree_path !== null &&
6752+ normalizeProjectPathForComparison ( row . worktree_path ) === worktreeKey ) ,
6753+ ) ;
67386754 const targetThreadIds = new Set ( targetThreadRows . map ( ( row ) => ThreadId . make ( row . thread_id ) ) ) ;
67396755 const rowsByThreadId = new Map (
67406756 targetThreadRows . map ( ( row ) => [ ThreadId . make ( row . thread_id ) , row ] as const ) ,
0 commit comments