@@ -3,6 +3,7 @@ import { SessionID } from "@/session/schema"
33import { WorkspaceID } from "@/control-plane/schema"
44import { and , asc , desc , eq , gt , gte , isNull , like , lt , or , type SQL } from "@/storage/db"
55import * as Database from "@/storage/db"
6+ import { realpathSync } from "fs"
67import { Context , DateTime , Effect , Layer , Option , Schema } from "effect"
78import { SessionMessage } from "./session-message"
89import type { Prompt } from "./session-prompt"
@@ -20,6 +21,17 @@ export type Delivery = Schema.Schema.Type<typeof Delivery>
2021
2122export const DefaultDelivery = "immediate" satisfies Delivery
2223
24+ function directoryMatchCondition ( directory : string ) : SQL {
25+ if ( process . platform !== "win32" ) return eq ( SessionTable . directory , directory )
26+ const alternatives = [ directory ]
27+ try {
28+ const real = realpathSync ( directory )
29+ if ( real !== directory && ! alternatives . includes ( real ) ) alternatives . push ( real )
30+ } catch { }
31+ if ( alternatives . length === 1 ) return eq ( SessionTable . directory , directory )
32+ return or ( ...alternatives . map ( ( d ) => eq ( SessionTable . directory , d ) ) ) !
33+ }
34+
2335export class Info extends Schema . Class < Info > ( "Session.Info" ) ( {
2436 id : SessionID ,
2537 parentID : optionalOmitUndefined ( SessionID ) ,
@@ -158,7 +170,7 @@ export const layer = Layer.effect(
158170 if ( direction === "previous" && order === "asc" ) order = "desc"
159171 if ( direction === "previous" && order === "desc" ) order = "asc"
160172 const conditions : SQL [ ] = [ ]
161- if ( input . directory ) conditions . push ( eq ( SessionTable . directory , input . directory ) )
173+ if ( input . directory ) conditions . push ( directoryMatchCondition ( input . directory ) )
162174 if ( input . path )
163175 conditions . push ( or ( eq ( SessionTable . path , input . path ) , like ( SessionTable . path , `${ input . path } /%` ) ) ! )
164176 if ( input . workspaceID ) conditions . push ( eq ( SessionTable . workspace_id , input . workspaceID ) )
0 commit comments