synabun 2.4.4 → 2.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/docs/browser-extension-bridge.md +5 -4
  4. package/docs/whatsapp.md +3 -3
  5. package/mcp-server/dist/services/neural-interface.d.ts +1 -0
  6. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  7. package/mcp-server/dist/services/neural-interface.js +1 -0
  8. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  9. package/mcp-server/dist/tools/agents.d.ts +16 -3
  10. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  11. package/mcp-server/dist/tools/agents.js +74 -11
  12. package/mcp-server/dist/tools/agents.js.map +1 -1
  13. package/mcp-server/package-lock.json +2 -2
  14. package/mcp-server/package.json +1 -1
  15. package/mcp-server/src/services/neural-interface.ts +2 -1
  16. package/mcp-server/src/tools/agents.ts +67 -11
  17. package/neural-interface/i18n/en.json +349 -9
  18. package/neural-interface/i18n/pt-BR.json +349 -9
  19. package/neural-interface/lib/agents-studio-api.js +7 -2
  20. package/neural-interface/lib/antigravity/home.js +43 -8
  21. package/neural-interface/lib/antigravity/tool-call.js +14 -0
  22. package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
  23. package/neural-interface/lib/assistant-persona.js +8 -3
  24. package/neural-interface/lib/assistant-route-gate.js +11 -2
  25. package/neural-interface/lib/assistant-runtime.js +16 -5
  26. package/neural-interface/lib/assistant-spilled-output.js +53 -0
  27. package/neural-interface/lib/browser-default.js +22 -2
  28. package/neural-interface/lib/browser-extension-bridge.js +50 -3
  29. package/neural-interface/lib/browser-extension-pin.json +7 -7
  30. package/neural-interface/lib/browser-extension-protocol.js +30 -1
  31. package/neural-interface/lib/browser-extension-setup.js +204 -36
  32. package/neural-interface/lib/remote-policy.js +24 -7
  33. package/neural-interface/lib/teams/README.md +22 -1
  34. package/neural-interface/lib/teams/api.js +79 -6
  35. package/neural-interface/lib/teams/index.js +2 -0
  36. package/neural-interface/lib/teams/recovery.js +68 -0
  37. package/neural-interface/lib/teams/scheduler.js +349 -29
  38. package/neural-interface/lib/teams/worktrees.js +123 -30
  39. package/neural-interface/package-lock.json +2 -2
  40. package/neural-interface/package.json +1 -1
  41. package/neural-interface/public/extension-setup.html +6 -2
  42. package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
  43. package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
  44. package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
  45. package/neural-interface/public/shared/browser-extension-updates.js +3 -1
  46. package/neural-interface/public/shared/extension-setup/es-page.js +23 -4
  47. package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
  48. package/neural-interface/public/shared/extension-update-view.js +1 -1
  49. package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
  50. package/neural-interface/public/shared/settings/settings-browser-extension.js +575 -197
  51. package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
  52. package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
  53. package/neural-interface/public/shared/settings/settings-ia.js +2 -2
  54. package/neural-interface/public/shared/settings/settings-shell.js +5 -0
  55. package/neural-interface/public/shared/styles.css +196 -13
  56. package/neural-interface/public/shared/ui-settings.js +48 -11
  57. package/neural-interface/server.js +20 -1
  58. package/npm-shrinkwrap.json +2 -2
  59. package/package.json +1 -1
@@ -9,11 +9,26 @@
9
9
  // integration branch and its last test result, the landing, and the feed of the team's events and messages. Land
10
10
  // and Discard are the owner's, each behind a question that says what it does.
11
11
  //
12
- // The routes are the team scheduler's (GET /teams, /teams/:id, POST /teams/:id/land and /discard). A server that
13
- // does not have them yet answers "not there": the place then says what teams are and waits, without an error.
12
+ // The list is in two: Open (under way, the rail's count) and Finished (landed, completed, discarded, failed). A
13
+ // finished team says what of it is still on disk and in git, and offers the one step that fits: Clean up worktrees
14
+ // (landed), Force delete kept work (a discard that kept work), Remove (nothing left); Clear finished removes every
15
+ // finished team that can go and says how many stay. Each is behind a question that names what goes.
16
+ //
17
+ // A ready team whose work somebody merged into its base branch outside SynaBun says "Already on <branch>" instead
18
+ // of "Ready to land", in the list and in its detail, and offers Clean up & remove when nothing would be lost (or
19
+ // says what is in the way). A card of the Open list that waits on the owner (needs attention, ready; never a running
20
+ // one, never one with a live worker) has one quick action beside it: Clean up & remove, Discard & remove (nothing
21
+ // of the team on disk) or Discard. The decisions are ax-teams.js `quickActionOf` / `teamView`.
22
+ //
23
+ // The routes are the team scheduler's (GET /teams, /teams/:id, POST /teams/:id/land and /discard; with the
24
+ // capabilities `teams-cleanup` and `teams-remove`, POST /teams/:id/cleanup, DELETE /teams/:id and POST
25
+ // /teams/clear-finished; with `teams-on-target`, POST /teams/:id/cleanup-merged; with `teams-quick-discard`, the
26
+ // list's `liveRuns` / `left` and discard's `remove`). A server that does not have them yet answers "not there": the
27
+ // place then says what teams are and waits, without an error; a server without a capability is offered nothing that
28
+ // needs it.
14
29
 
15
30
  import { html, setHTML, ICONS } from '../../skills/studio/sx-dom.js';
16
- import { teamRows, teamView } from './ax-teams.js';
31
+ import { teamRows, teamView, splitTeams, clearableTeams, quickActionOf } from './ax-teams.js';
17
32
  import { baseName } from './ax-library.js';
18
33
  import { AX_ICONS } from './ax-icons.js';
19
34
  import { timeTag, loadingHTML, errorHTML, emptyHTML, errorText, wordOr } from './ax-ui.js';
@@ -38,6 +53,15 @@ const chip = (label, tone) => html`<span class="sx-state-chip ax-run-state ax-ru
38
53
  const teamState = (t, state) => wordOr(t, 'agentsStudio.teams.state', state || 'unknown');
39
54
  const sliceState = (t, state) => wordOr(t, 'agentsStudio.teams.sliceState', state || 'unknown');
40
55
  const shortCommit = (commit) => String(commit || '').slice(0, 9);
56
+ /** A team's status as a chip: "Already on <branch>" for a ready team whose work is there, its status otherwise. */
57
+ const statusChip = (t, team) => (team.onTarget ? chip(t('agentsStudio.teams.onTarget', { branch: team.onTarget.branch }), team.tone) : chip(teamState(t, team.status), team.tone));
58
+
59
+ /** A card's quick action: its words and its kind of button (the decision is ax-teams.js `quickActionOf`). */
60
+ const QUICK = Object.freeze({
61
+ 'cleanup-merged': { label: 'agentsStudio.teams.cleanupMerged', kind: 'primary' },
62
+ 'discard-remove': { label: 'agentsStudio.teams.discardRemove', kind: 'danger' },
63
+ discard: { label: 'agentsStudio.teams.discard', kind: 'danger' },
64
+ });
41
65
 
42
66
  function listHTML(ctx, st) {
43
67
  const { t } = ctx;
@@ -50,10 +74,113 @@ function listHTML(ctx, st) {
50
74
  lines: [t('agentsStudio.teams.emptyHelp'), st.available === false ? t(st.notRunning ? 'agentsStudio.teams.notRunning' : 'agentsStudio.teams.notAvailable') : t('agentsStudio.teams.emptyHow')],
51
75
  });
52
76
  }
53
- return html`<ul class="ax-team-list" aria-label="${t('agentsStudio.rail.teams')}">${rows.map((row, n) => html`<li><button type="button" class="ax-team-row" data-act="open-team" data-team="${row.id}"${n === 0 ? html` data-autofocus` : ''}>
54
- <span class="ax-team-row-main"><span class="ax-team-title">${row.title || row.id}</span><span class="sx-mono ax-team-id">${row.id}</span></span>
55
- <span class="ax-team-row-meta">${chip(teamState(t, row.status), row.tone)}${row.slices !== null ? html`<span>${ctx.tp('agentsStudio.teams.slices', row.slices)}</span>` : ''}${row.density ? html`<span>${wordOr(t, 'agentsStudio.teams.density', row.density)}</span>` : ''}${row.project ? html`<span class="sx-tag" title="${row.project}">${AX_ICONS.pin}<span>${baseName(row.project)}</span></span>` : ''}<span class="sx-spacer"></span>${timeTag(row.createdAt, ctx.locale)}</span>
56
- </button></li>`)}</ul>`;
77
+ const { open, finished } = splitTeams(rows);
78
+ // Whether the server can say a finished team still has worktrees (and remove the ones that do not).
79
+ const removing = ctx.caps.has('teams-remove');
80
+ const clear = clearableTeams(rows);
81
+ const canClear = ctx.owner && removing && clear.removable.length > 0;
82
+ let first = true;
83
+ const rowHTML = (row) => {
84
+ const autofocus = first;
85
+ first = false;
86
+ // The card opens the team; its quick action (the owner's, a team that waits on the owner) is a button of its own
87
+ // beside it, never inside it, and the team's title describes it.
88
+ const quick = ctx.owner ? quickActionOf(row, ctx.caps) : null;
89
+ const titleId = `ax-team-t-${row.id}`;
90
+ return html`<li class="ax-team-item"><button type="button" class="ax-team-row" data-act="open-team" data-team="${row.id}"${autofocus ? html` data-autofocus` : ''}>
91
+ <span class="ax-team-row-main"><span class="ax-team-title" id="${titleId}">${row.title || row.id}</span><span class="sx-mono ax-team-id">${row.id}</span></span>
92
+ <span class="ax-team-row-meta">${statusChip(t, row)}${row.onTarget && !row.onTarget.clean ? html`<span class="ax-team-left">${t('agentsStudio.teams.onTargetBlocked')}</span>` : ''}${row.finished && removing && !row.removable ? html`<span class="ax-team-left">${t('agentsStudio.teams.leftTag')}</span>` : ''}${row.slices !== null ? html`<span>${ctx.tp('agentsStudio.teams.slices', row.slices)}</span>` : ''}${row.density ? html`<span>${wordOr(t, 'agentsStudio.teams.density', row.density)}</span>` : ''}${row.project ? html`<span class="sx-tag" title="${row.project}">${AX_ICONS.pin}<span>${baseName(row.project)}</span></span>` : ''}<span class="sx-spacer"></span>${timeTag(row.createdAt, ctx.locale)}</span>
93
+ </button>${quick ? html`<span class="ax-team-quick"><button type="button" class="sx-btn sx-btn--sm sx-btn--${QUICK[quick].kind}" data-act="quick" data-quick="${quick}" data-team="${row.id}" aria-describedby="${titleId}"${st.busy ? html` disabled` : ''}>${ICONS.trash}${t(QUICK[quick].label)}</button></span>` : ''}</li>`;
94
+ };
95
+ return html`<div class="ax-team-groups">
96
+ <section class="ax-team-group" aria-labelledby="ax-teams-open-title">
97
+ <header class="ax-team-group-head"><h4 class="sx-section-title" id="ax-teams-open-title">${t('agentsStudio.teams.openTitle')}</h4><span class="ax-team-group-count">${open.length}</span></header>
98
+ ${open.length ? html`<ul class="ax-team-list" aria-labelledby="ax-teams-open-title">${open.map(rowHTML)}</ul>` : html`<p class="sx-note">${t('agentsStudio.teams.openEmpty')}</p>`}
99
+ </section>
100
+ ${finished.length ? html`<section class="ax-team-group" aria-labelledby="ax-teams-finished-title">
101
+ <header class="ax-team-group-head"><h4 class="sx-section-title" id="ax-teams-finished-title">${t('agentsStudio.teams.finishedTitle')}</h4><span class="ax-team-group-count">${finished.length}</span><span class="sx-spacer"></span>${canClear ? html`<button type="button" class="sx-btn sx-btn--sm" data-act="clear-finished"${st.busy ? html` disabled` : ''}>${ICONS.trash}${t('agentsStudio.teams.clearFinished')}</button>` : ''}</header>
102
+ <ul class="ax-team-list" aria-labelledby="ax-teams-finished-title">${finished.map(rowHTML)}</ul>
103
+ </section>` : ''}
104
+ </div>`;
105
+ }
106
+
107
+ /** How one thing that is left reads in a list: its folder (or branch), its branch beside it. */
108
+ const leftLine = (item) => (item.path && item.branch ? `${item.path} · ${item.branch}` : item.path || item.branch);
109
+
110
+ /** Why a discard kept a worktree, as a short note: the reason, the files, the commits. */
111
+ function keptNote(ctx, kept) {
112
+ if (!kept) return '';
113
+ const { t } = ctx;
114
+ const parts = [kept.reason ? wordOr(t, 'agentsStudio.teams.keptReason', kept.reason) : ''];
115
+ if (kept.files.length) parts.push(ctx.tp('agentsStudio.teams.keptFiles', kept.files.length));
116
+ if (kept.commits) parts.push(ctx.tp('agentsStudio.teams.keptCommits', kept.commits));
117
+ return parts.filter(Boolean).join(' · ');
118
+ }
119
+
120
+ /** Why a finished team's record cannot go, when nothing that is left is the reason. */
121
+ function blockedText(t, code) {
122
+ const said = t(`agentsStudio.teams.removalBlocked.${code}`);
123
+ return said === `agentsStudio.teams.removalBlocked.${code}` ? t('agentsStudio.teams.removalBlocked.other') : said;
124
+ }
125
+
126
+ /** Why a team stayed in the list after a step that would have removed it (the answer's `removal`). */
127
+ function stayReason(t, removal) {
128
+ const code = removal?.code;
129
+ return !code || code === 'TEAM_WORKTREES_LEFT' ? t('agentsStudio.teams.leftTag') : blockedText(t, code);
130
+ }
131
+
132
+ /**
133
+ * A finished team's worktrees and branches: what is still on disk and in git, and the one step that fits (the
134
+ * owner's only). Nothing is drawn for a server that does not say (no `removal`).
135
+ */
136
+ function diskHTML(ctx, st, team) {
137
+ const { t } = ctx;
138
+ const r = team.removal;
139
+ if (!team.finished || !r) return '';
140
+ const busy = st.busy ? html` disabled` : '';
141
+ const keptBy = new Map(team.kept.filter((item) => item.sliceId).map((item) => [item.sliceId, item]));
142
+ const lead = r.next === 'cleanup' ? 'agentsStudio.teams.cleanupLead' : r.next === 'force_discard' ? 'agentsStudio.teams.keptLead' : 'agentsStudio.teams.byHandLead';
143
+ const owner = ctx.owner;
144
+ const actions = [
145
+ owner && team.canCleanup && ctx.caps.has('teams-cleanup') ? html`<button type="button" class="sx-btn sx-btn--primary" data-act="cleanup"${busy}>${ICONS.trash}${t('agentsStudio.teams.cleanup')}</button>` : '',
146
+ owner && team.canForceDiscard ? html`<button type="button" class="sx-btn sx-btn--danger" data-act="force-discard"${busy}>${ICONS.trash}${t('agentsStudio.teams.forceDiscard')}</button>` : '',
147
+ owner && team.canRemove && ctx.caps.has('teams-remove') ? html`<button type="button" class="sx-btn sx-btn--danger" data-act="remove"${busy}>${ICONS.trash}${t('agentsStudio.teams.remove')}</button>` : '',
148
+ ].filter(Boolean);
149
+ return html`<section class="ax-side-card ax-team-disk" aria-labelledby="ax-team-disk-title">
150
+ <h4 class="sx-section-title" id="ax-team-disk-title">${AX_ICONS.branch} ${t('agentsStudio.teams.diskTitle')}</h4>
151
+ ${r.removable ? html`<p class="sx-note">${t('agentsStudio.teams.diskClean')}</p>` : ''}
152
+ ${!r.removable && r.left.length ? html`<p class="sx-field-note${r.next === 'force_discard' ? ' sx-warn-text' : ''}" role="note">${t(lead)}</p>
153
+ <ul class="sx-plain-list ax-left-list">${r.left.map((item) => { const note = keptNote(ctx, keptBy.get(item.sliceId)); return html`<li><span class="sx-mono ax-left-path">${item.path || item.branch}</span>${item.path && item.branch ? html`<span class="sx-mono sx-dim">${item.branch}</span>` : ''}${note ? html`<span class="sx-help">${note}</span>` : ''}</li>`; })}</ul>` : ''}
154
+ ${!r.removable && !r.left.length ? html`<p class="sx-field-note sx-warn-text" role="note">${blockedText(t, r.code)}</p>` : ''}
155
+ ${actions.length ? html`<div class="sx-row ax-team-actions">${actions}</div>` : ''}
156
+ </section>`;
157
+ }
158
+
159
+ /**
160
+ * A ready team whose work is on its base branch already (merged outside SynaBun): where it is, and either the one
161
+ * step that fits (Clean up & remove, the owner's) or exactly what keeps the worktrees and branches from going
162
+ * (uncommitted edits per worktree, commits the base branch lacks, a live worker, git's own words).
163
+ */
164
+ function onTargetHTML(ctx, st, team) {
165
+ const o = team.onTarget;
166
+ if (!o) return '';
167
+ const { t } = ctx;
168
+ const branch = o.branch;
169
+ const problems = [
170
+ ...o.dirty.map((item) => html`<li><span class="sx-mono ax-left-path">${ctx.tp('agentsStudio.teams.onTargetDirty', item.files.length, { path: item.path })}</span><span class="sx-mono sx-dim">${item.files.slice(0, 6).join(', ')}${item.files.length > 6 ? ' …' : ''}</span></li>`),
171
+ ...o.unmerged.map((item) => html`<li><span class="sx-mono ax-left-path">${ctx.tp('agentsStudio.teams.onTargetUnmerged', item.commits, { branch: item.branch, target: branch })}</span></li>`),
172
+ ...(o.runs === null ? [html`<li><span class="sx-help">${t('agentsStudio.teams.onTargetNoRuns')}</span></li>`] : o.runs > 0 ? [html`<li><span class="sx-help">${ctx.tp('agentsStudio.teams.onTargetRuns', o.runs)}</span></li>`] : []),
173
+ ...o.other.map((line) => html`<li><span class="sx-mono sx-dim">${line}</span></li>`),
174
+ ];
175
+ const offer = ctx.owner && team.canCleanupMerged && ctx.caps.has('teams-on-target');
176
+ return html`<section class="ax-side-card ax-team-ontarget${o.clean ? '' : ' is-blocked'}" aria-labelledby="ax-team-ontarget-title">
177
+ <h4 class="sx-section-title" id="ax-team-ontarget-title">${AX_ICONS.branch} ${t('agentsStudio.teams.onTarget', { branch })}</h4>
178
+ <p class="sx-note">${t('agentsStudio.teams.onTargetLead', { branch })}</p>
179
+ ${o.clean ? html`<p class="sx-field-note" role="note">${t('agentsStudio.teams.onTargetClean', { branch })}</p>` : html`<p class="sx-field-note sx-warn-text" role="note">${t('agentsStudio.teams.onTargetNotClean')}</p>
180
+ ${problems.length ? html`<ul class="sx-plain-list ax-left-list">${problems}</ul>` : ''}
181
+ <p class="sx-help">${t('agentsStudio.teams.onTargetFix', { branch })}</p>`}
182
+ ${offer ? html`<div class="sx-row ax-team-actions"><button type="button" class="sx-btn sx-btn--primary" data-act="cleanup-merged"${st.busy ? html` disabled` : ''}>${ICONS.trash}${t('agentsStudio.teams.cleanupMerged')}</button></div>` : ''}
183
+ </section>`;
57
184
  }
58
185
 
59
186
  function sliceHTML(ctx, slice) {
@@ -83,10 +210,12 @@ function detailHTML(ctx, st) {
83
210
  const i = team.integration;
84
211
  const l = team.landing;
85
212
  const tests = i.tests;
213
+ // Why Land is not offered: its work is on its base branch already, or the team is not ready yet.
214
+ const landHelp = team.onTarget ? t('agentsStudio.teams.onTargetNothingToLand', { branch: team.onTarget.branch }) : t('agentsStudio.teams.landNotReady');
86
215
  return html`<div class="ax-team">
87
216
  <section class="ax-team-summary" aria-label="${t('agentsStudio.teams.summary')}">
88
217
  <dl class="ax-facts">
89
- <div><dt>${t('agentsStudio.teams.status')}</dt><dd>${chip(teamState(t, team.status), team.tone)}</dd></div>
218
+ <div><dt>${t('agentsStudio.teams.status')}</dt><dd>${statusChip(t, team)}</dd></div>
90
219
  ${team.project ? html`<div><dt>${t('agentsStudio.teams.project')}</dt><dd class="sx-mono" title="${team.project}">${team.project}</dd></div>` : ''}
91
220
  ${team.density ? html`<div><dt>${t('agentsStudio.teams.densityLabel')}</dt><dd>${wordOr(t, 'agentsStudio.teams.density', team.density)}</dd></div>` : ''}
92
221
  ${team.baseBranch || team.baseCommit ? html`<div><dt>${t('agentsStudio.teams.base')}</dt><dd class="sx-mono">${team.baseBranch}${team.baseCommit ? ` @ ${shortCommit(team.baseCommit)}` : ''}</dd></div>` : ''}
@@ -94,6 +223,8 @@ function detailHTML(ctx, st) {
94
223
  </dl>
95
224
  ${team.attention ? html`<p class="sx-field-note sx-warn-text ax-team-attention" role="note">${team.attention}</p>` : ''}
96
225
  </section>
226
+ ${onTargetHTML(ctx, st, team)}
227
+ ${diskHTML(ctx, st, team)}
97
228
  <section aria-labelledby="ax-team-slices-title">
98
229
  <h4 class="sx-section-title" id="ax-team-slices-title">${ctx.tp('agentsStudio.teams.slices', team.slices.length)}</h4>
99
230
  ${team.slices.length ? html`<div class="ax-slices">${team.slices.map((slice) => sliceHTML(ctx, slice))}</div>` : html`<p class="sx-note">${t('agentsStudio.teams.noSlices')}</p>`}
@@ -114,16 +245,16 @@ function detailHTML(ctx, st) {
114
245
  <section class="ax-side-card" aria-labelledby="ax-team-land-title">
115
246
  <h4 class="sx-section-title" id="ax-team-land-title">${ICONS.publish} ${t('agentsStudio.teams.landing')}</h4>
116
247
  <dl class="ax-facts">
117
- <div><dt>${t('agentsStudio.teams.status')}</dt><dd>${l.state ? wordOr(t, 'agentsStudio.teams.landingState', l.state) : t(team.status === 'merged' || team.status === 'landed' ? 'agentsStudio.teams.landed' : 'agentsStudio.teams.notLanded')}</dd></div>
248
+ <div><dt>${t('agentsStudio.teams.status')}</dt><dd>${team.onTarget ? t('agentsStudio.teams.onTarget', { branch: team.onTarget.branch }) : l.state ? wordOr(t, 'agentsStudio.teams.landingState', l.state) : t(team.status === 'merged' || team.status === 'landed' ? 'agentsStudio.teams.landed' : 'agentsStudio.teams.notLanded')}</dd></div>
118
249
  ${l.targetBranch ? html`<div><dt>${t('agentsStudio.teams.target')}</dt><dd class="sx-mono">${l.targetBranch}</dd></div>` : ''}
119
250
  ${l.commit ? html`<div><dt>${t('agentsStudio.teams.head')}</dt><dd class="sx-mono">${shortCommit(l.commit)}</dd></div>` : ''}
120
251
  ${l.at ? html`<div><dt>${t('agentsStudio.teams.landedAt')}</dt><dd>${timeTag(l.at, ctx.locale)}</dd></div>` : ''}
121
252
  </dl>
122
253
  ${l.error ? html`<p class="sx-field-note sx-err-text">${l.error}</p>` : ''}
123
254
  ${ctx.owner ? html`<div class="sx-row ax-team-actions">
124
- <button type="button" class="sx-btn sx-btn--primary" data-act="land"${team.canLand && !st.busy ? '' : html` disabled`} title="${team.canLand ? t('agentsStudio.teams.landHelp') : t('agentsStudio.teams.landNotReady')}">${ICONS.publish}${t('agentsStudio.teams.land')}</button>
255
+ <button type="button" class="sx-btn sx-btn--primary" data-act="land"${team.canLand && !st.busy ? '' : html` disabled`} title="${team.canLand ? t('agentsStudio.teams.landHelp') : landHelp}">${ICONS.publish}${t('agentsStudio.teams.land')}</button>
125
256
  <button type="button" class="sx-btn sx-btn--danger" data-act="discard"${team.canDiscard && !st.busy ? '' : html` disabled`}>${ICONS.trash}${t('agentsStudio.teams.discard')}</button>
126
- </div>${team.canLand ? '' : html`<p class="sx-help">${t('agentsStudio.teams.landNotReady')}</p>`}` : ''}
257
+ </div>${team.canLand ? '' : html`<p class="sx-help">${landHelp}</p>`}` : ''}
127
258
  </section>
128
259
  </div>`}
129
260
  <section aria-labelledby="ax-team-feed-title">
@@ -234,8 +365,15 @@ export function renderTeams(main, ctx, st) {
234
365
  st.busy = true;
235
366
  ctx.render({ keepFocus: true });
236
367
  try {
237
- if (land) await ctx.api.landTeam(view.id, {}); else await ctx.api.discardTeam(view.id, {});
238
- ctx.toast(t(land ? 'agentsStudio.teams.landedToast' : 'agentsStudio.teams.discardedToast'));
368
+ if (land) {
369
+ await ctx.api.landTeam(view.id, {});
370
+ ctx.toast(t('agentsStudio.teams.landedToast'));
371
+ } else {
372
+ const out = await ctx.api.discardTeam(view.id, {});
373
+ const kept = Array.isArray(out?.kept) ? out.kept.length : 0;
374
+ // What holds work is kept: say so, and where it can be deleted.
375
+ ctx.toast(kept ? ctx.tp('agentsStudio.teams.discardKeptToast', kept) : t('agentsStudio.teams.discardedToast'));
376
+ }
239
377
  } catch (error) {
240
378
  ctx.toast(t(land ? 'agentsStudio.teams.landFailed' : 'agentsStudio.teams.discardFailed', { error: errorText(t, error) }), 'error');
241
379
  }
@@ -243,6 +381,157 @@ export function renderTeams(main, ctx, st) {
243
381
  await reload();
244
382
  };
245
383
 
384
+ /** The things a question lists: at most ten, then how many more. */
385
+ const listed = (items) => [...items.slice(0, 10).map((item) => `• ${leftLine(item)}`), items.length > 10 ? ctx.tp('agentsStudio.teams.moreItems', items.length - 10) : null];
386
+
387
+ /** Clean up worktrees, Force delete kept work, or Remove: one finished team, behind its question. */
388
+ const finish = async (which) => {
389
+ const view = teamView(st.team);
390
+ const name = view.title || view.id;
391
+ const left = view.removal?.left || [];
392
+ const asks = {
393
+ cleanup: {
394
+ title: t('agentsStudio.teams.cleanupTitle', { name }),
395
+ lines: [t('agentsStudio.teams.cleanupAsk'), ...listed(left), t('agentsStudio.teams.cleanupSafe', { branch: view.landing.targetBranch || view.baseBranch || t('agentsStudio.teams.yourBranch') })],
396
+ label: t('agentsStudio.teams.cleanup'), kind: 'primary',
397
+ },
398
+ 'force-discard': {
399
+ title: t('agentsStudio.teams.forceTitle', { name }),
400
+ lines: [t('agentsStudio.teams.forceAsk'), ...listed(left), t('agentsStudio.teams.forceWarn')],
401
+ label: t('agentsStudio.teams.forceDiscard'), kind: 'danger',
402
+ },
403
+ remove: {
404
+ title: t('agentsStudio.teams.removeTitle', { name }),
405
+ lines: [t('agentsStudio.teams.removeAsk'), t('agentsStudio.teams.removeKeeps')],
406
+ label: t('agentsStudio.teams.remove'), kind: 'danger',
407
+ },
408
+ };
409
+ const q = asks[which];
410
+ const answer = await ctx.ask({ title: q.title, lines: q.lines, className: 'ax-dlg', buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'go', label: q.label, kind: q.kind }], focus: 'cancel' });
411
+ if (answer !== 'go') return;
412
+ st.busy = true;
413
+ ctx.render({ keepFocus: true });
414
+ try {
415
+ if (which === 'cleanup') {
416
+ await ctx.api.cleanupTeam(view.id);
417
+ ctx.toast(t('agentsStudio.teams.cleanedToast'));
418
+ } else if (which === 'force-discard') {
419
+ const out = await ctx.api.discardTeam(view.id, { force: true });
420
+ const kept = Array.isArray(out?.kept) ? out.kept.length : 0;
421
+ ctx.toast(kept ? ctx.tp('agentsStudio.teams.forceIncomplete', kept) : t('agentsStudio.teams.forcedToast'), kept ? 'error' : 'info');
422
+ } else {
423
+ await ctx.api.removeTeam(view.id);
424
+ ctx.toast(t('agentsStudio.teams.removedToast'));
425
+ st.busy = false;
426
+ // The team is gone: back to the list, read again.
427
+ st.rows = (st.rows || []).filter((row) => row.id !== view.id);
428
+ st.team = null;
429
+ ctx.go({ type: 'back' });
430
+ await reload();
431
+ return;
432
+ }
433
+ } catch (error) {
434
+ const key = which === 'cleanup' ? 'agentsStudio.teams.cleanupFailed' : which === 'force-discard' ? 'agentsStudio.teams.forceFailed' : 'agentsStudio.teams.removeFailed';
435
+ ctx.toast(t(key, { error: errorText(t, error) }), 'error');
436
+ }
437
+ st.busy = false;
438
+ await reload();
439
+ };
440
+
441
+ /** A team that left the list: drawn without it now (the reload confirms), and its detail closed when it was open. */
442
+ const dropTeam = (teamId) => {
443
+ st.rows = (st.rows || []).filter((row) => row.id !== teamId);
444
+ if (st.teamId === teamId) st.team = null;
445
+ if (ctx.view.teamId === teamId) ctx.go({ type: 'back' });
446
+ };
447
+
448
+ /**
449
+ * Clean up & remove a ready team whose work is on its base branch already: behind a question that says where the
450
+ * work is, what is deleted and that git is asked again first (the server refuses, deleting nothing, if a worktree
451
+ * got edits or a branch got commits since this page read it).
452
+ */
453
+ const cleanupMerged = async ({ id, name, branch, count, items = [] }) => {
454
+ const answer = await ctx.ask({
455
+ title: t('agentsStudio.teams.cleanupMergedTitle', { name }),
456
+ lines: [ctx.tp('agentsStudio.teams.cleanupMergedAsk', count, { branch }), ...listed(items), t('agentsStudio.teams.cleanupMergedSafe', { branch })],
457
+ className: 'ax-dlg',
458
+ buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'go', label: t('agentsStudio.teams.cleanupMerged'), kind: 'primary' }],
459
+ focus: 'cancel',
460
+ });
461
+ if (answer !== 'go') return;
462
+ st.busy = true;
463
+ ctx.render({ keepFocus: true });
464
+ try {
465
+ const out = await ctx.api.cleanupMergedTeam(id);
466
+ if (out?.teamRemoved === false) ctx.toast(t('agentsStudio.teams.cleanupMergedKeptToast', { reason: stayReason(t, out.removal) }));
467
+ else { ctx.toast(t('agentsStudio.teams.cleanupMergedToast', { branch: out?.branch || branch })); dropTeam(id); }
468
+ } catch (error) {
469
+ ctx.toast(t('agentsStudio.teams.cleanupMergedFailed', { error: errorText(t, error) }), 'error');
470
+ }
471
+ st.busy = false;
472
+ await reload();
473
+ };
474
+
475
+ /**
476
+ * A card's Discard, or Discard & remove when nothing of the team is on disk or in git. Each question says whether
477
+ * the card leaves the list: Discard moves it to Finished; Discard & remove takes it off, and keeps the team (in
478
+ * Finished, discarded) when a worktree or branch holding work turns up after all.
479
+ */
480
+ const quickDiscard = async (row, remove) => {
481
+ const name = row.title || row.id;
482
+ const answer = await ctx.ask({
483
+ title: t(remove ? 'agentsStudio.teams.discardRemoveTitle' : 'agentsStudio.teams.discardTitle', { name }),
484
+ lines: remove
485
+ ? [t('agentsStudio.teams.discardRemoveAsk'), t('agentsStudio.teams.discardRemoveSafe')]
486
+ : [t('agentsStudio.teams.discardAsk'), t('agentsStudio.teams.discardMoves'), t('agentsStudio.teams.discardKeeps')],
487
+ className: 'ax-dlg',
488
+ buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'go', label: t(remove ? 'agentsStudio.teams.discardRemove' : 'agentsStudio.teams.discard'), kind: 'danger' }],
489
+ focus: 'cancel',
490
+ });
491
+ if (answer !== 'go') return;
492
+ st.busy = true;
493
+ ctx.render({ keepFocus: true });
494
+ try {
495
+ const out = await ctx.api.discardTeam(row.id, remove ? { remove: true } : {});
496
+ const kept = Array.isArray(out?.kept) ? out.kept.length : 0;
497
+ if (kept) ctx.toast(ctx.tp('agentsStudio.teams.discardKeptToast', kept));
498
+ else if (remove && out?.teamRemoved === true) { ctx.toast(t('agentsStudio.teams.discardRemovedToast')); dropTeam(row.id); }
499
+ else if (remove) ctx.toast(t('agentsStudio.teams.discardStaysToast', { reason: stayReason(t, out?.removal) }));
500
+ else ctx.toast(t('agentsStudio.teams.discardedToast'));
501
+ } catch (error) {
502
+ ctx.toast(t('agentsStudio.teams.discardFailed', { error: errorText(t, error) }), 'error');
503
+ }
504
+ st.busy = false;
505
+ await reload();
506
+ };
507
+
508
+ /** Clear finished: every finished team with nothing left goes; the rest stay, and the toast says how many. */
509
+ const clearFinished = async () => {
510
+ const { removable, kept } = clearableTeams(st.rows || []);
511
+ if (!removable.length) return;
512
+ const answer = await ctx.ask({
513
+ title: t('agentsStudio.teams.clearTitle'),
514
+ lines: [ctx.tp('agentsStudio.teams.clearAsk', removable.length), kept ? ctx.tp('agentsStudio.teams.clearSkips', kept) : null, t('agentsStudio.teams.removeKeeps')],
515
+ className: 'ax-dlg',
516
+ buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'go', label: t('agentsStudio.teams.clearFinished'), kind: 'danger' }],
517
+ focus: 'cancel',
518
+ });
519
+ if (answer !== 'go') return;
520
+ st.busy = true;
521
+ ctx.render({ keepFocus: true });
522
+ try {
523
+ const out = await ctx.api.clearFinishedTeams();
524
+ const removed = Array.isArray(out?.removed) ? out.removed.length : 0;
525
+ const skipped = Array.isArray(out?.skipped) ? out.skipped.length : 0;
526
+ const said = [removed ? ctx.tp('agentsStudio.teams.clearedToast', removed) : t('agentsStudio.teams.clearNothing'), skipped ? ctx.tp('agentsStudio.teams.clearSkippedToast', skipped) : ''].filter(Boolean).join(' ');
527
+ ctx.toast(said, removed ? 'info' : 'error');
528
+ } catch (error) {
529
+ ctx.toast(t('agentsStudio.teams.clearFailed', { error: errorText(t, error) }), 'error');
530
+ }
531
+ st.busy = false;
532
+ await reload();
533
+ };
534
+
246
535
  main.addEventListener('click', (e) => {
247
536
  const el = e.target.closest?.('[data-act]');
248
537
  if (!el || !main.contains(el) || el.disabled) return;
@@ -252,5 +541,21 @@ export function renderTeams(main, ctx, st) {
252
541
  else if (act === 'refresh' || act === 'retry') { st.error = null; st.detailError = null; reload(); }
253
542
  else if (act === 'focus-run') ctx.focusRun(el.dataset.run);
254
543
  else if (act === 'land' || act === 'discard') decide(act);
544
+ else if (act === 'cleanup' || act === 'force-discard' || act === 'remove') finish(act);
545
+ else if (act === 'clear-finished') clearFinished();
546
+ else if (act === 'quick') {
547
+ // A card's own action: never the card's click (which opens the team).
548
+ e.stopPropagation();
549
+ const row = (st.rows || []).find((r) => r.id === el.dataset.team);
550
+ const which = row ? quickActionOf(row, ctx.caps) : null;
551
+ if (!which || which !== el.dataset.quick) return;
552
+ if (which === 'cleanup-merged') cleanupMerged({ id: row.id, name: row.title || row.id, branch: row.onTarget.branch, count: row.left ?? 1 });
553
+ else quickDiscard(row, which === 'discard-remove');
554
+ } else if (act === 'cleanup-merged' && st.team) {
555
+ const view = teamView(st.team);
556
+ if (!view.canCleanupMerged) return;
557
+ const items = [...view.slices.filter((slice) => slice.worktree || slice.branch).map((slice) => ({ path: slice.worktree, branch: slice.branch })), ...(view.integration.branch ? [{ path: '', branch: view.integration.branch }] : [])];
558
+ cleanupMerged({ id: view.id, name: view.title || view.id, branch: view.onTarget.branch, count: items.length || 1, items });
559
+ }
255
560
  }, { signal });
256
561
  }
@@ -24,6 +24,19 @@ export const SLICE_STATES = Object.freeze(['planned', 'pending', 'blocked', 'run
24
24
  const TEAM_TONES = { creating: 'idle', planned: 'idle', running: 'active', integrating: 'active', ready: 'ok', landing: 'active', merged: 'done', completed: 'done', failed: 'err', cancelled: 'off', needs_attention: 'warn', landed: 'done', discarded: 'off' };
25
25
  /** A team that reached the owner's branch, is on its way there, or was thrown away: nothing more to land or discard. */
26
26
  const SETTLED_TEAM = new Set(['merged', 'landing', 'landed', 'discarded', 'completed']);
27
+ /**
28
+ * A team that is over (the scheduler's closed statuses, lib/teams/scheduler.js CLOSED_TEAM_STATUSES, and the
29
+ * journal's words for the same ends): the Finished list. Every other team, a state this page does not know
30
+ * included, is Open (never offered for removal), and the Open list is the rail's count.
31
+ */
32
+ export const FINISHED_TEAM_STATUSES = Object.freeze(['landed', 'completed', 'discarded', 'failed', 'merged', 'cancelled']);
33
+ const FINISHED_TEAM = new Set(FINISHED_TEAM_STATUSES);
34
+ /** What the server says to do about a closed team that still has something on disk (lib/teams/scheduler.js removalOf). */
35
+ export const REMOVAL_NEXT = Object.freeze(['cleanup', 'force_discard', 'by_hand']);
36
+ /** Why a closed team's record cannot go yet, when it is not what is left on disk (`agentsStudio.teams.removalBlocked.*`). */
37
+ export const REMOVAL_BLOCKED = Object.freeze(['TEAM_RUNS_ACTIVE', 'DISPATCH_UNAVAILABLE', 'PROJECT_NOT_FOUND', 'NOT_A_REPOSITORY', 'GIT_UNAVAILABLE', 'TEAM_NEEDS_RECOVERY', 'TEAM_OPEN']);
38
+ /** Why a discard kept a worktree or a branch (lib/teams/worktrees.js `kept[].reason`; `agentsStudio.teams.keptReason.*`). */
39
+ export const KEPT_REASONS = Object.freeze(['uncommitted_changes', 'unintegrated_commits', 'folder_is_not_a_worktree', 'worktree_not_removed', 'branch_not_removed', 'worktree_not_verified', 'worker_commits']);
27
40
  const SLICE_TONES = { planned: 'idle', pending: 'idle', blocked: 'warn', running: 'active', done: 'ok', rejected: 'err', integrating: 'active', integrated: 'done', completed: 'done', conflict: 'err', 'tests-failed': 'err', failed: 'err', cancelled: 'off' };
28
41
 
29
42
  const isObject = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
@@ -35,34 +48,137 @@ const stateOf = (value) => text(first(value?.status, value?.state), 40).toLowerC
35
48
  /** The tone of a team's or a slice's state: idle / active / ok / done / warn / err / off. */
36
49
  export const teamTone = (state) => TEAM_TONES[state] || 'idle';
37
50
  export const sliceTone = (state) => SLICE_TONES[state] || 'idle';
51
+ /** Is a team over (Finished)? */
52
+ export const isFinishedTeam = (status) => FINISHED_TEAM.has(String(status || '').toLowerCase());
53
+
54
+ /** The open statuses a card offers a quick action on: a team that waits on the owner. Never a running team. */
55
+ export const QUICK_TEAM_STATUSES = Object.freeze(['needs_attention', 'ready']);
56
+ /** The quick actions of a card: Clean up & remove, Discard & remove, Discard. */
57
+ export const QUICK_ACTIONS = Object.freeze(['cleanup-merged', 'discard-remove', 'discard']);
58
+ const count = (value) => (Number.isInteger(value) && value >= 0 ? value : null);
59
+
60
+ /**
61
+ * A ready team whose work is on its base branch already (lib/teams/scheduler.js `onTargetOf`), or null: where
62
+ * (`branch`), whether its worktrees and branches could go now (`clean`), and, in a team's detail, what keeps it from
63
+ * being clean (uncommitted files per worktree, branches with commits the base branch lacks, a live worker, other).
64
+ * Only for a ready team: any other status, or an answer without a branch, is null.
65
+ */
66
+ export function onTargetOf(team) {
67
+ const o = isObject(team?.alreadyOnTarget) ? team.alreadyOnTarget : null;
68
+ if (!o || stateOf(team) !== 'ready' || team?.plan?.readOnly === true) return null;
69
+ const branch = text(o.branch, 300);
70
+ if (!branch) return null;
71
+ const list = (value) => (Array.isArray(value) ? value.filter(isObject) : []);
72
+ return {
73
+ branch,
74
+ head: text(o.head, 80),
75
+ clean: o.clean === true,
76
+ runs: count(o.runs),
77
+ dirty: list(o.dirty).map((item) => ({ sliceId: text(item.sliceId, 128) || null, path: text(item.path, 1024), files: (Array.isArray(item.files) ? item.files : []).filter((f) => typeof f === 'string').slice(0, 50) })).filter((item) => item.path).slice(0, 20),
78
+ unmerged: list(o.unmerged).map((item) => ({ sliceId: text(item.sliceId, 128) || null, branch: text(item.branch, 300), commits: (Array.isArray(item.commits) ? item.commits : []).filter((c) => typeof c === 'string').length })).filter((item) => item.branch).slice(0, 20),
79
+ other: (Array.isArray(o.other) ? o.other : []).filter((line) => typeof line === 'string' && line).map((line) => line.slice(0, 600)).slice(0, 10),
80
+ };
81
+ }
38
82
 
39
83
  /** A row of the teams list. */
40
84
  export function teamRow(team) {
41
85
  const t = isObject(team) ? team : {};
42
86
  const slices = Array.isArray(t.slices) ? t.slices.length : isObject(t.slices) ? Object.keys(t.slices).length : number(first(t.slices, t.sliceCount, t.slicesCount));
43
87
  const status = stateOf(t);
88
+ const onTarget = onTargetOf(t);
44
89
  return {
45
90
  id: text(first(t.id, t.teamId), 128),
46
91
  title: text(first(t.title, t.plan?.title, t.name), 200),
47
92
  project: text(first(t.project, t.projectPath, t.plan?.projectPath), 1024),
48
- status, tone: teamTone(status),
93
+ // A ready team whose work is on its base branch already says so instead of "Ready to land".
94
+ status, tone: onTarget ? (onTarget.clean ? 'done' : 'warn') : teamTone(status),
49
95
  density: text(first(t.density, t.plan?.density), 40),
50
96
  slices: slices ?? null,
51
97
  createdAt: text(first(t.createdAt, t.created_at), 40),
52
98
  updatedAt: text(first(t.updatedAt, t.updated_at), 40),
99
+ finished: isFinishedTeam(status),
100
+ // Only a finished team the server said can go now (nothing of it on disk or in git, no live worker).
101
+ removable: isFinishedTeam(status) && t.removable === true,
102
+ onTarget,
103
+ // An open team that waits on the owner: its live workers and what of it is on disk (null: not said).
104
+ liveRuns: count(t.liveRuns),
105
+ left: count(t.left),
53
106
  };
54
107
  }
55
108
 
109
+ /**
110
+ * The one quick action a card of the Open list offers, or null. Never on a running team, on a team with a live
111
+ * worker or on one whose workers the server did not count; never without the capability its route needs.
112
+ * cleanup-merged a ready team whose work is on its base branch already, clean (`teams-on-target`)
113
+ * discard-remove needs attention or ready, nothing of it on disk or in git (`teams-quick-discard`)
114
+ * discard needs attention or ready, with worktrees or branches (`teams-quick-discard`)
115
+ * A ready team on its base branch that is not clean gets none: discarding it would say its landed work was given up.
116
+ * @param {object} row a teamRow
117
+ * @param {{ has: (cap: string) => boolean }} caps
118
+ */
119
+ export function quickActionOf(row, caps) {
120
+ const has = (cap) => typeof caps?.has === 'function' && caps.has(cap);
121
+ if (!row?.id || row.finished || !QUICK_TEAM_STATUSES.includes(row.status)) return null;
122
+ if (row.onTarget) return row.onTarget.clean && has('teams-on-target') ? 'cleanup-merged' : null;
123
+ if (!has('teams-quick-discard') || row.liveRuns !== 0 || row.left === null) return null;
124
+ return row.left === 0 ? 'discard-remove' : 'discard';
125
+ }
126
+
56
127
  /** The list, newest first, a team without an id left out. */
57
128
  export function teamRows(teams) {
58
129
  return (Array.isArray(teams) ? teams : []).map(teamRow).filter((row) => row.id)
59
130
  .sort((a, b) => String(b.createdAt).localeCompare(String(a.createdAt)));
60
131
  }
61
132
 
62
- /** How many teams are under way (the rail's count). */
133
+ /** The list in two: the teams under way (Open) and the teams that are over (Finished), each newest first. */
134
+ export function splitTeams(rows) {
135
+ const list = Array.isArray(rows) ? rows : [];
136
+ return { open: list.filter((row) => !row.finished), finished: list.filter((row) => row.finished) };
137
+ }
138
+
139
+ /** How many teams are under way (the rail's count): the Open list. A team that waits on the owner is under way. */
63
140
  export function activeTeams(rows) {
64
- // A team that waits on the owner (`needs_attention`) is still under way.
65
- return (Array.isArray(rows) ? rows : []).filter((row) => ['active', 'ok', 'warn'].includes(row.tone)).length;
141
+ return splitTeams(rows).open.length;
142
+ }
143
+
144
+ /** The finished teams Clear finished removes (the server checks each again) and how many it leaves. */
145
+ export function clearableTeams(rows) {
146
+ const { finished } = splitTeams(rows);
147
+ const removable = finished.filter((row) => row.removable);
148
+ return { removable, kept: finished.length - removable.length };
149
+ }
150
+
151
+ /** A closed team's removal view (lib/teams/scheduler.js `removalView`), or null when the answer has none. */
152
+ export function removalOf(team) {
153
+ const r = isObject(team?.removal) ? team.removal : null;
154
+ if (!r) return null;
155
+ const left = (Array.isArray(r.left) ? r.left : []).filter(isObject).map((item) => ({
156
+ sliceId: text(item.sliceId, 128) || null,
157
+ path: text(item.path, 1024),
158
+ branch: text(item.branch, 300),
159
+ worktree: item.worktree === true,
160
+ branchExists: item.branchExists === true,
161
+ })).filter((item) => item.path || item.branch).slice(0, 200);
162
+ return {
163
+ removable: r.removable === true,
164
+ code: text(r.code, 80) || null,
165
+ next: REMOVAL_NEXT.includes(r.next) ? r.next : null,
166
+ message: text(r.message, 1200),
167
+ left,
168
+ };
169
+ }
170
+
171
+ /** What a discard kept, and why (the scheduler's `cleanup.kept`, in the landing part of the answer). */
172
+ export function keptWork(team) {
173
+ const cleanup = isObject(team?.landing?.cleanup) ? team.landing.cleanup : isObject(team?.cleanup) ? team.cleanup : {};
174
+ return (Array.isArray(cleanup.kept) ? cleanup.kept : []).filter(isObject).map((item) => ({
175
+ sliceId: text(item.sliceId, 128) || null,
176
+ path: text(item.path, 1024),
177
+ branch: text(item.branch, 300),
178
+ reason: text(item.reason, 60),
179
+ files: (Array.isArray(item.files) ? item.files : []).filter((f) => typeof f === 'string').slice(0, 20),
180
+ commits: number(item.commits),
181
+ })).slice(0, 100);
66
182
  }
67
183
 
68
184
  function sliceOf(raw, plan) {
@@ -182,19 +298,35 @@ export function teamView(team) {
182
298
  const row = teamRow(team);
183
299
  const slices = sliceRows(team);
184
300
  const integration = integrationOf(team);
301
+ const readOnly = team?.plan?.readOnly === true;
302
+ // A finished team: the server's look at git and the disk (null from a server without it: nothing is offered).
303
+ const removal = row.finished ? removalOf(team) : null;
304
+ const leftWith = (next) => !!removal && !removal.removable && removal.next === next && removal.left.length > 0;
185
305
  return {
186
306
  ...row,
187
307
  slices,
188
- readOnly: team?.plan?.readOnly === true,
308
+ readOnly,
309
+ removal,
310
+ kept: keptWork(team),
311
+ // Landed, its worktrees and branches still there: the owner cleans them up (merged and clean, or nothing goes).
312
+ canCleanup: !readOnly && (row.status === 'landed' || row.status === 'merged') && leftWith('cleanup'),
313
+ // Discarded (or failed) with work kept: the owner deletes it with a forced discard.
314
+ canForceDiscard: !readOnly && ['discarded', 'cancelled', 'failed'].includes(row.status) && leftWith('force_discard'),
315
+ // Nothing of it is left and no worker lives: its record can go.
316
+ canRemove: row.finished && removal?.removable === true,
189
317
  baseBranch: text(first(team?.baseBranch, team?.plan?.baseBranch), 300),
190
318
  baseCommit: text(first(team?.baseCommit, team?.plan?.baseCommit), 80),
191
319
  integration, landing: landingOf(team), claims: claimRows(team), feed: feedItems(team),
192
320
  // What the scheduler waits on the owner for (status `needs_attention`): its sentence, shown as text.
193
321
  attention: text(isObject(team?.attention) ? first(team.attention.message, team.attention.code) : team?.attention, 600),
194
- // Landing is offered once the integration branch is ready (the server refuses anything else and says why).
195
- canLand: team?.plan?.readOnly !== true && row.status === 'ready',
196
- // A team that reached the owner's branch, or is on its way there, is not thrown away from here.
197
- canDiscard: !!row.id && !SETTLED_TEAM.has(row.status) && team?.removed !== true,
322
+ // Landing is offered once the integration branch is ready (the server refuses anything else and says why), and
323
+ // never for a team whose work is on its base branch already: there is nothing left to land.
324
+ canLand: team?.plan?.readOnly !== true && row.status === 'ready' && !row.onTarget,
325
+ // A team that reached the owner's branch, or is on its way there, is not thrown away from here; neither is one
326
+ // whose work is on its base branch already (a discard would record its landed work as given up).
327
+ canDiscard: !!row.id && !SETTLED_TEAM.has(row.status) && team?.removed !== true && !row.onTarget,
328
+ // Its work is on its base branch already and nothing would be lost: Clean up & remove.
329
+ canCleanupMerged: !!row.onTarget && row.onTarget.clean,
198
330
  sliceCounts: slices.reduce((acc, slice) => { acc[slice.tone] = (acc[slice.tone] || 0) + 1; return acc; }, {}),
199
331
  };
200
332
  }
@@ -30,7 +30,9 @@ export function refreshExtensionUpdate() {
30
30
  return reading;
31
31
  }
32
32
 
33
- export const extensionUpdateSettings = { tab: 'browser', expand: 'bcg-profiles', scrollTo: 'bc-extension-update-flow' };
33
+ // The update flow heads the extension card, in the Browser page's first card (Browser choice). An open setup guide
34
+ // steps aside for it (settings-browser-extension.js listens for settings-shell.js's settings-reveal).
35
+ export const extensionUpdateSettings = { tab: 'browser', expand: 'setup-browser', scrollTo: 'bc-extension-update-flow' };
34
36
  export function openExtensionUpdate() {
35
37
  return import('./ui-settings-entry.js').then(({ openSettingsModal }) => openSettingsModal(extensionUpdateSettings));
36
38
  }