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

+2
View File
@@ -7692,6 +7692,8 @@ class CodemanApp {
this._tabLayoutEditor = null;
}
this.tabLayout = next;
// An open Case settings popover lists the groups as its Default session group options.
this._refreshCaseDefaultGroupOptions?.(next);
const storage = this._getTabCollapseStorage();
const collapsed = storage && next
? window.CodemanTabLayout.loadCollapsedGroupIds(storage, next.groups.map((group) => group.id))
+3
View File
@@ -678,6 +678,9 @@
'Agent Teams': '智能体团队',
'Claude Model': 'Claude 模型',
'1M Opus Context': 'Opus 100 万上下文',
'Default session group': '默认会话分组',
'New sessions for this case land in this group': '此案例的新会话将放入此分组',
'Could not save the default session group.': '无法保存默认会话分组。',
'Remote auto-reconnect': '远程自动重连',
'Pin tab names on the CLI': '在 CLI 上固定标签名',
"Launch every Claude session with its tab name, so the CLI's prompt label and /resume list match your tabs. Claude then stops generating its own titles for those sessions, and a rename in Codeman holds only until the next turn. Applies from the next session start or respawn, no server restart needed.":
+10
View File
@@ -774,6 +774,11 @@
<span>1M Opus Context</span>
</label>
<span class="form-hint">Use 1M token context window for new sessions</span>
<label class="case-default-group-label" for="caseDefaultGroup">Default session group</label>
<select id="caseDefaultGroup" class="case-default-group-select" onchange="app.onCaseDefaultGroupChanged(this)">
<option value="">Ungrouped</option>
</select>
<span class="form-hint">New sessions for this case land in this group</span>
</div>
</div>
<!-- Mobile-only case button + gear -->
@@ -818,6 +823,11 @@
<span>1M Opus Context</span>
</label>
<span class="form-hint">Use 1M token context window</span>
<label class="case-default-group-label" for="caseDefaultGroupMobile">Default session group</label>
<select id="caseDefaultGroupMobile" class="case-default-group-select" onchange="app.onCaseDefaultGroupChanged(this)">
<option value="">Ungrouped</option>
</select>
<span class="form-hint">New sessions for this case land in this group</span>
</div>
</div>
+93
View File
@@ -3272,6 +3272,7 @@ Object.assign(CodemanApp.prototype, {
document.getElementById('caseAgentTeams').checked = settings.agentTeams;
document.getElementById('caseOpusContext1m').checked = settings.opusContext1m;
popover.classList.remove('hidden');
this._loadCaseDefaultGroup();
// Close on outside click (one-shot listener)
const closeHandler = (e) => {
@@ -3320,6 +3321,7 @@ Object.assign(CodemanApp.prototype, {
document.getElementById('caseAgentTeamsMobile').checked = settings.agentTeams;
document.getElementById('caseOpusContext1mMobile').checked = settings.opusContext1m;
popover.classList.remove('hidden');
this._loadCaseDefaultGroup();
const closeHandler = (e) => {
if (!popover.contains(e.target) && !e.target.classList.contains('btn-case-settings-mobile')) {
@@ -3346,6 +3348,97 @@ Object.assign(CodemanApp.prototype, {
if (desktopOpusCheckbox) desktopOpusCheckbox.checked = settings.opusContext1m;
},
// ── Default session group (server-side, per owner + case) ──
//
// Unlike the two checkboxes above (this browser's localStorage), the default
// group lives on the server, because the server places a new session in it in
// the same layout write that registers it. The value is a group ID; '' in the
// <select> is Ungrouped (null on the wire). Desktop and phone popovers mirror.
_caseDefaultGroupSelects() {
return ['caseDefaultGroup', 'caseDefaultGroupMobile']
.map((id) => document.getElementById(id))
.filter(Boolean);
},
/** Rebuild both selectors from `groups`, keeping `groupId` if it still exists. */
_renderCaseDefaultGroupSelects(groups, groupId) {
const known = groups.some((group) => group.id === groupId);
const value = known ? groupId : '';
for (const select of this._caseDefaultGroupSelects()) {
const ungrouped = document.createElement('option');
ungrouped.value = '';
ungrouped.textContent = 'Ungrouped';
const options = groups.map((group) => {
const option = document.createElement('option');
option.value = group.id;
option.textContent = group.name;
option.setAttribute('data-i18n-skip', '');
return option;
});
select.replaceChildren(ungrouped, ...options);
select.value = value;
}
return value;
},
/** Read the selected case's default group from the server (popover open). */
async _loadCaseDefaultGroup() {
const caseName = document.getElementById('quickStartCase')?.value;
const selects = this._caseDefaultGroupSelects();
if (!caseName || selects.length === 0) return;
for (const select of selects) select.disabled = true;
const data = await this._apiJson(`/api/cases/${encodeURIComponent(caseName)}/default-group`);
if (document.getElementById('quickStartCase')?.value !== caseName) return; // case switched meanwhile
const groups = Array.isArray(data?.groups) ? data.groups : [];
const groupId = typeof data?.groupId === 'string' ? data.groupId : null;
this._caseDefaultGroupState = { caseName, groupId, groups };
this._renderCaseDefaultGroupSelects(groups, groupId);
for (const select of selects) select.disabled = !data;
},
/** Save a selector change; on refusal restore the last confirmed value. */
async onCaseDefaultGroupChanged(select) {
const state = this._caseDefaultGroupState;
if (!state) return;
const groupId = select.value || null;
const selects = this._caseDefaultGroupSelects();
for (const other of selects) {
other.value = select.value;
other.disabled = true;
}
const res = await this._apiPut(`/api/cases/${encodeURIComponent(state.caseName)}/default-group`, { groupId });
let saved = null;
if (res?.ok) {
try {
saved = (await res.json())?.data ?? null;
} catch {
saved = null;
}
}
if (saved) {
state.groupId = typeof saved.groupId === 'string' ? saved.groupId : null;
if (Array.isArray(saved.groups)) state.groups = saved.groups;
} else {
this.showToast?.('Could not save the default session group.', 'error');
}
this._renderCaseDefaultGroupSelects(state.groups, state.groupId);
for (const other of selects) other.disabled = false;
},
/**
* The tab layout changed (a group was created, renamed or deleted): redraw the
* options from it. A deleted selection shows as Ungrouped, which is where the
* server now places new sessions (it forgets the stale ID on its next read).
*/
_refreshCaseDefaultGroupOptions(layout) {
const state = this._caseDefaultGroupState;
if (!state || !layout || !Array.isArray(layout.groups)) return;
state.groups = layout.groups.map((group) => ({ id: group.id, name: group.name }));
const value = this._renderCaseDefaultGroupSelects(state.groups, state.groupId);
if (!value) state.groupId = null;
},
// ═══════════════════════════════════════════════════════════════
// Create Case Modal
// ═══════════════════════════════════════════════════════════════
+21
View File
@@ -6669,6 +6669,27 @@ html[data-skin="og"] .welcome-primary:hover {
display: none;
}
/* Default session group selector (Case settings, desktop and phone popovers) */
.case-default-group-label {
display: block;
margin-top: 8px;
font-size: 0.75rem;
color: var(--text);
}
.case-default-group-select {
display: block;
width: 100%;
margin-top: 4px;
padding: 3px 6px;
font: inherit;
font-size: 0.75rem;
color: var(--text);
background: var(--bg-input, var(--bg-card));
border: 1px solid var(--control-border);
border-radius: 6px;
}
.case-settings-popover .form-hint {
margin-top: 0.2rem;
font-size: 0.6rem;