@@ -37,6 +37,11 @@ export interface ImporterDeps {
3737 now ?: ( ) => string ;
3838 /** Key-free diagnostic sink. */
3939 log ?: ( message : string ) => void ;
40+ /**
41+ * FEA-1548: resolve the current authenticated user's identity for stamping
42+ * on new sessions. Returns null when no user is signed in.
43+ */
44+ getUserIdentity ?: ( ) => { userId : string ; organizationId : string | null } | null ;
4045}
4146
4247export interface ImportResult {
@@ -64,8 +69,8 @@ export function createImporter(db: DatabaseSync, deps: ImporterDeps): Importer {
6469 "SELECT id, status, ended_at FROM sessions WHERE id = ?" ,
6570 ) ;
6671 const insertSessionStmt = db . prepare ( `
67- INSERT INTO sessions (id, name, status, cwd, model, started_at, updated_at, ended_at, harness, billing_mode, metadata)
68- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
72+ INSERT INTO sessions (id, name, status, cwd, model, started_at, updated_at, ended_at, harness, billing_mode, metadata, user_id, organization_id )
73+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
6974 ` ) ;
7075 // Fill only missing fields on an existing row; never clobber a live status.
7176 // Always refresh metadata so new fields (diffStats, artifacts, etc.) are populated.
@@ -193,6 +198,7 @@ export function createImporter(db: DatabaseSync, deps: ImporterDeps): Importer {
193198 if ( ! existing ) {
194199 const status = recentlyActive ? "active" : "completed" ;
195200 const billingMode = safe ( ( ) => deps . detectBillingMode ( harness ) ) ?? "unknown" ;
201+ const identity = safe ( ( ) => deps . getUserIdentity ?.( ) ) ?? null ;
196202 insertSessionStmt . run (
197203 session . sessionId ,
198204 session . name ?? null ,
@@ -205,6 +211,8 @@ export function createImporter(db: DatabaseSync, deps: ImporterDeps): Importer {
205211 harness ,
206212 billingMode ,
207213 buildMetadata ( session , harness ) ,
214+ identity ?. userId ?? null ,
215+ identity ?. organizationId ?? null ,
208216 ) ;
209217 insertAgentStmt . run (
210218 mainId ,
0 commit comments