Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions web/adapter/pi-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ export class PiWebAdapter {
status: this.runtime.isIdle()
? ("idle" as const)
: ("running" as const),
trust: this.runtime.projectTrustState ?? "unknown",
capabilities: webCapabilitySnapshot(this.runtime.sessionManager),
},
truncation: {
Expand All @@ -510,6 +511,22 @@ export class PiWebAdapter {
return snapshot;
}

async searchSessions(query: string, includeArchived = false) {
const normalized = query.trim().toLocaleLowerCase();
if (!normalized || normalized.length > 200) return [];
const projection = await this.listSessionProjection();
return projection.sessions
.filter((session) => includeArchived || session.archived !== true)
.filter((session) =>
[session.name, session.firstMessage, session.cwd]
.filter((value): value is string => typeof value === "string")
.join("\n")
.toLocaleLowerCase()
.includes(normalized),
)
.slice(0, 100);
}

private fitSnapshot(snapshot: {
currentSessionId?: string;
workspaces: WebWorkspaceSummary[];
Expand Down
13 changes: 13 additions & 0 deletions web/host/web-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ export class WebHost {
error: "session is not in the current workspace",
});
}
if (url.pathname === "/api/search") {
const query = url.searchParams.get("q") ?? "";
const includeArchived = url.searchParams.get("archived") === "true";
if (query.length > 200) {
return this.json(response, 400, { error: "search query must be at most 200 characters" });
}
const sessions = await this.adapter.searchSessions(query, includeArchived);
return this.json(response, 200, {
query,
sessions,
truncated: sessions.length >= 100,
});
}
this.json(response, 404, { error: "not found" });
}

Expand Down
1 change: 1 addition & 0 deletions web/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface WebSnapshot {
models: WebModelSummary[];
runtime: {
status: "idle" | "running" | "unknown";
trust: "trusted" | "untrusted" | "unknown";
capabilities: WebCapabilitySnapshot;
};
truncation: WebSnapshotTruncation;
Expand Down
11 changes: 11 additions & 0 deletions web/runtime/pi-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ export class PiWebRuntime implements WebRuntimeController {
private disposePromise?: Promise<void>;
private hasSelectedWorkspace: boolean;

get projectTrustState() {
if (!this.hasSelectedWorkspace) return "unknown" as const;
try {
return this.runtime.session.settingsManager.isProjectTrusted()
? ("trusted" as const)
: ("untrusted" as const);
} catch {
return "unknown" as const;
}
}

private constructor(
runtime: AgentSessionRuntime,
webSessionDirectory: string,
Expand Down
1 change: 1 addition & 0 deletions web/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface WebRuntimeController {
readonly workspaceSelected: boolean;
readonly sessionDirectory: string;
readonly sessionManager: SessionManager;
readonly projectTrustState?: "trusted" | "untrusted" | "unknown";
isIdle(): boolean;
sendPrompt(content: string, options?: WebPromptOptions): Promise<void>;
newSession(
Expand Down
Loading