feat: session-first workspace activity and installable daemon
Workspaces page: - list the newest sessions across workspaces in the activity column; the daemon exposes GET /api/v1/sessions/recent as a disk projection and the browser enriches live rows from the per-workspace session relay - put recent activity first below 1100px and fix the mobile page-header flex-basis gap Smoke: - pin PI2_HOST=127.0.0.1 in both smoke scripts and make the startup-line assertion follow the configured host; the daemon default stays 0.0.0.0 Install: - standalone binary build/install scripts, packaging templates, CI/release hooks, CLI-first install docs and the supporting config/doctor changes
This commit is contained in:
1 parent
fc51c3be37
commit
d2e20d428a
50 files changed
+5104
-188
No files matched your search
@@ -64,7 +64,7 @@ export interface Discovery {
|
||||
/** Scan every `--*--` directory under the sessions root. */
|
||||
discover(): DiscoveredWorkspace[];
|
||||
/** Session files for a cwd, newest first (header-only, cheap). */
|
||||
listSessions(cwd: string): SessionFile[];
|
||||
listSessions(cwd: string, limit?: number): SessionFile[];
|
||||
/** Drop one directory's cache entry, or the whole cache when omitted. */
|
||||
invalidate(dir?: string): void;
|
||||
/** The encoded directory used for a cwd, when it has been discovered. */
|
||||
@@ -129,7 +129,7 @@ class DiskDiscovery implements Discovery {
|
||||
return out;
|
||||
}
|
||||
|
||||
listSessions(cwd: string): SessionFile[] {
|
||||
listSessions(cwd: string, limit?: number): SessionFile[] {
|
||||
if (typeof cwd !== "string" || cwd.length === 0 || !isAbsolute(cwd)) return [];
|
||||
const workspaceId = workspaceIdForCwd(cwd);
|
||||
const dirs = this.discover()
|
||||
@@ -137,15 +137,21 @@ class DiskDiscovery implements Discovery {
|
||||
.map((entry) => entry.dir);
|
||||
if (dirs.length === 0) return [];
|
||||
|
||||
const sessions: SessionFile[] = [];
|
||||
// Sort the raw file descriptors first so a `limit` reads only the headers
|
||||
// of the newest files instead of every session in the workspace.
|
||||
const infos: SessionFileInfo[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const dir of dirs) {
|
||||
for (const info of this.sessionFiles(dir)) {
|
||||
if (seen.has(info.file)) continue;
|
||||
seen.add(info.file);
|
||||
sessions.push(this.describeSession(info));
|
||||
infos.push(info);
|
||||
}
|
||||
}
|
||||
infos.sort((a, b) => b.mtimeMs - a.mtimeMs || b.size - a.size);
|
||||
const selected = limit !== undefined && limit > 0 ? infos.slice(0, limit) : infos;
|
||||
|
||||
const sessions = selected.map((info) => this.describeSession(info));
|
||||
sessions.sort((a, b) => b.modified - a.modified || b.timestamp - a.timestamp || a.id.localeCompare(b.id));
|
||||
return sessions;
|
||||
}
|
||||
@@ -336,8 +342,8 @@ export function discoverWorkspaces(options: DiscoveryOptions = {}): DiscoveredWo
|
||||
return sharedDiscovery(options.root, options.logger).discover();
|
||||
}
|
||||
|
||||
export function listSessions(cwd: string, options: DiscoveryOptions = {}): SessionFile[] {
|
||||
return sharedDiscovery(options.root, options.logger).listSessions(cwd);
|
||||
export function listSessions(cwd: string, options: DiscoveryOptions = {}, limit?: number): SessionFile[] {
|
||||
return sharedDiscovery(options.root, options.logger).listSessions(cwd, limit);
|
||||
}
|
||||
|
||||
/** Drop cached discovery results for every root (or one directory). */
|
||||
|
||||
@@ -18,6 +18,7 @@ import { dataDir, realpathSafe, workspaceIdForCwd } from "../core/paths.js";
|
||||
import { ERROR_CODES } from "../protocol/errors.js";
|
||||
import type {
|
||||
InstanceState,
|
||||
RecentSessionInfo,
|
||||
WorkspaceInfo,
|
||||
WorkspaceVisibility,
|
||||
WorkspaceVisibilityReason,
|
||||
@@ -241,6 +242,43 @@ class WorkspaceStore implements WorkspaceStoreHandle {
|
||||
return this.requireInfo(record.workspaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Newest session files across every known workspace (registry ∪ discovery).
|
||||
*
|
||||
* Each workspace asks discovery for at most `limit` rows, so the header scan
|
||||
* stays bounded even on a workspace with a long history. Rows are deduped by
|
||||
* session id (two encoded directories can resolve to the same cwd) and sorted
|
||||
* by file mtime, then header timestamp, then id for a deterministic order.
|
||||
*/
|
||||
recentSessions(limit = 20): RecentSessionInfo[] {
|
||||
const capped = clampLimit(limit);
|
||||
const rows: RecentSessionInfo[] = [];
|
||||
const seen = new Set<string>();
|
||||
for (const workspace of this.list()) {
|
||||
if (!workspace.cwd) continue;
|
||||
for (const file of this.discovery.listSessions(workspace.cwd, capped)) {
|
||||
if (file.id === "" || seen.has(file.id)) continue;
|
||||
seen.add(file.id);
|
||||
rows.push({
|
||||
sessionId: file.id,
|
||||
workspaceId: workspace.workspaceId,
|
||||
workspaceName: workspace.name,
|
||||
cwd: workspace.cwd,
|
||||
sessionFile: file.file,
|
||||
timestamp: file.timestamp,
|
||||
modified: file.modified,
|
||||
});
|
||||
}
|
||||
}
|
||||
rows.sort(
|
||||
(a, b) =>
|
||||
b.modified - a.modified ||
|
||||
b.timestamp - a.timestamp ||
|
||||
a.sessionId.localeCompare(b.sessionId),
|
||||
);
|
||||
return rows.slice(0, capped);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
private requireInfo(workspaceId: string): WorkspaceInfo {
|
||||
@@ -567,6 +605,12 @@ function liveCountOf(state: InstanceState): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Keeps a user-supplied recent-session limit in a cheap, predictable range. */
|
||||
function clampLimit(limit: number): number {
|
||||
if (!Number.isFinite(limit) || limit <= 0) return 20;
|
||||
return Math.min(200, Math.max(1, Math.floor(limit)));
|
||||
}
|
||||
|
||||
function mapFsError(error: unknown, path: string): WorkspaceError {
|
||||
const code = (error as NodeJS.ErrnoException | undefined)?.code;
|
||||
const detail = error instanceof Error ? error.message : String(error);
|
||||
|
||||
Reference in new issue
Block a user