feat: per-case default session group

Case settings gains a "Default session group" selector (Ungrouped plus every
named tab group of the owner). A new session of the case lands in that group
in the same versioned layout write that registers it, so it is drawn in place
with no Ungrouped-to-group jump.

- Stored per owner and case in state.json (caseDefaultGroups), as the group's
  stable id or null for Ungrouped; read and written only through
  TabLayoutService under the owner lock.
- Precedence in sessionCreated: explicit tabGroupId, then the parent
  placement, then the case default, else Ungrouped. A deleted or foreign id
  never fails a spawn and is forgotten only after the creating write lands.
- POST /api/quick-start (local, linked, remote, Docker) and
  /api/ralph-loop/start pass their case; POST /api/sessions infers it
  lexically from workingDir. The create response carries tabLayout when a
  case default placed the session.
- GET/PUT /api/cases/:name/default-group; deleting a case (or an admin
  deleting a user's case folder) forgets the value.
- The selector mirrors desktop and phone, reverts on a refused save, and is
  redrawn from every adopted tab layout; zh-CN strings added.
This commit is contained in:
Aamer Akhter committed 2026-10-22 03:42:42 -04:00
1 parent 39077281d1
commit 74c980413a
24 files changed
+1362 -26

No files matched your search

+35
View File
@@ -286,6 +286,9 @@ export class StateStore {
if (this.state.tabLayouts !== undefined) {
parts.push(`"tabLayouts":${JSON.stringify(this.state.tabLayouts)}`);
}
if (this.state.caseDefaultGroups !== undefined) {
parts.push(`"caseDefaultGroups":${JSON.stringify(this.state.caseDefaultGroups)}`);
}
return `{${parts.join(',')}}`;
}
@@ -710,6 +713,38 @@ export class StateStore {
return { layouts: structuredClone(validated), sessionOrder: [...sessionOrder] };
}
/**
* An owner's default session group for a case: a group id, `null` for an
* intentional Ungrouped choice, or `undefined` when unset. state.json is read
* unvalidated, so anything but a string or null reads as unset.
*/
getCaseDefaultGroup(owner: string, caseName: string): string | null | undefined {
const all = this.state.caseDefaultGroups;
if (!all || typeof all !== 'object' || !Object.hasOwn(all, owner)) return undefined;
const forOwner = all[owner];
if (!forOwner || typeof forOwner !== 'object' || !Object.hasOwn(forOwner, caseName)) return undefined;
const value = forOwner[caseName];
return typeof value === 'string' || value === null ? value : undefined;
}
/** Persist an owner's default session group for a case (`null` = Ungrouped). */
setCaseDefaultGroup(owner: string, caseName: string, groupId: string | null): void {
const all = this.state.caseDefaultGroups ?? {};
const forOwner = Object.hasOwn(all, owner) ? all[owner] : {};
this.state.caseDefaultGroups = { ...all, [owner]: { ...forOwner, [caseName]: groupId } };
this.save();
}
/** Forget an owner's default session group for a case (unset, not Ungrouped). */
deleteCaseDefaultGroup(owner: string, caseName: string): void {
if (this.getCaseDefaultGroup(owner, caseName) === undefined) return;
const all = this.state.caseDefaultGroups ?? {};
const forOwner = { ...all[owner] };
delete forOwner[caseName];
this.state.caseDefaultGroups = { ...all, [owner]: forOwner };
this.save();
}
/** Resets all state to initial values and saves immediately. */
reset(): void {
this.state = createInitialState();