chat session context scoping, fix sandboxed pi config mounts, dedupe zai/opencode providers
- Add context/contextId fields to session types, storage, and index - Filter sessions by context (project, workspace, or default chat) - Pass context through websocket, REST API, and frontend hooks - Mount ~/.pi/agent into sandboxed containers for auth + writable sessions - Remove PI_CODING_AGENT_DIR override so container pi uses ~/.pi/agent - Deduplicate zai/opencode models (same service, show as opencode) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -251,6 +251,8 @@ export function messagesToJnlEntries(messages: Message[], meta: SessionMeta): Jn
|
||||
messageCount: meta.messageCount,
|
||||
createdAt: meta.createdAt,
|
||||
updatedAt: meta.updatedAt,
|
||||
context: meta.context,
|
||||
contextId: meta.contextId,
|
||||
},
|
||||
};
|
||||
entries.push(infoEntry);
|
||||
@@ -357,6 +359,8 @@ function indexEntryToMeta(sessionId: string, entry: SessionIndexEntry): SessionM
|
||||
messageCount: entry.messageCount,
|
||||
cost: entry.cost,
|
||||
groupSlug: entry.groupSlug ?? null,
|
||||
context: entry.context,
|
||||
contextId: entry.contextId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -371,6 +375,8 @@ function metaToIndexEntry(meta: SessionMeta, relFile: string): SessionIndexEntry
|
||||
messageCount: meta.messageCount,
|
||||
cost: meta.cost,
|
||||
groupSlug: meta.groupSlug ?? null,
|
||||
context: meta.context,
|
||||
contextId: meta.contextId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -495,14 +501,28 @@ export async function deleteSession(
|
||||
await saveIndex(baseCwd, index);
|
||||
}
|
||||
|
||||
export async function listUserSessions(baseCwd: string): Promise<SessionMeta[]> {
|
||||
type SessionFilter = {
|
||||
context?: string;
|
||||
contextId?: string;
|
||||
};
|
||||
|
||||
export async function listUserSessions(baseCwd: string, filter?: SessionFilter): Promise<SessionMeta[]> {
|
||||
let index = await loadIndex(baseCwd);
|
||||
|
||||
if (Object.keys(index).length === 0) {
|
||||
index = await rebuildIndex(baseCwd);
|
||||
}
|
||||
|
||||
const sessions: SessionMeta[] = Object.entries(index).map(([id, entry]) => indexEntryToMeta(id, entry));
|
||||
let sessions: SessionMeta[] = Object.entries(index).map(([id, entry]) => indexEntryToMeta(id, entry));
|
||||
|
||||
if (filter?.context) {
|
||||
if (filter.context === 'chat') {
|
||||
// 'chat' matches sessions with no context or context='chat'
|
||||
sessions = sessions.filter((s) => !s.context || s.context === 'chat');
|
||||
} else {
|
||||
sessions = sessions.filter((s) => s.context === filter.context && s.contextId === filter.contextId);
|
||||
}
|
||||
}
|
||||
|
||||
sessions.sort((a, b) => b.updatedAt - a.updatedAt);
|
||||
return sessions;
|
||||
@@ -748,6 +768,8 @@ export async function rebuildIndex(baseCwd: string): Promise<SessionIndex> {
|
||||
let createdAt = new Date(header.timestamp).getTime();
|
||||
let updatedAt = createdAt;
|
||||
let groupSlug: string | null = null;
|
||||
let context: string | undefined;
|
||||
let contextId: string | undefined;
|
||||
|
||||
// Count message entries and find session_info
|
||||
for (const entry of entries) {
|
||||
@@ -763,6 +785,8 @@ export async function rebuildIndex(baseCwd: string): Promise<SessionIndex> {
|
||||
createdAt = info.officer.createdAt;
|
||||
updatedAt = info.officer.updatedAt;
|
||||
groupSlug = info.officer.groupSlug ?? null;
|
||||
context = info.officer.context;
|
||||
contextId = info.officer.contextId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -777,6 +801,8 @@ export async function rebuildIndex(baseCwd: string): Promise<SessionIndex> {
|
||||
messageCount,
|
||||
cost,
|
||||
groupSlug,
|
||||
context,
|
||||
contextId,
|
||||
};
|
||||
} catch {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user