@bakers-build/addon-bakers-ui 0.12.1-next.1 → 0.12.1-next.3

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.
@@ -4,6 +4,8 @@ import type { ListTable, Page } from '../../collection.js';
4
4
  export interface MachineRow {
5
5
  id: string;
6
6
  name: string;
7
+ /** The machine_id the site tools take. */
8
+ hostKey: string;
7
9
  /** Online when any of its conductors is. */
8
10
  online: boolean;
9
11
  /** The machine's reported `current_load`: its active runs. */
@@ -28,6 +28,7 @@ export const listMachineRows = async (client, ownerUserId, nowSeconds) => {
28
28
  machines.set(included.id, {
29
29
  id: included.id,
30
30
  name: String(attrs.name || attrs.host_key || '(unnamed)'),
31
+ hostKey: String(attrs.host_key ?? ''),
31
32
  online: false,
32
33
  active: Number(attrs.current_load ?? 0),
33
34
  conductorIds: [],
@@ -139,7 +139,7 @@ export class ConductorsScreen extends ListScreen {
139
139
  return confirmNavigation(restartRunsRequest({
140
140
  level: 'conductor',
141
141
  label: row.label,
142
- conductorIds: [row.id],
142
+ args: { conductor: row.id },
143
143
  online: row.derivedStatus === 'online',
144
144
  }));
145
145
  }
@@ -79,7 +79,7 @@ export class MachinesScreen extends ListScreen {
79
79
  return confirmNavigation(restartRunsRequest({
80
80
  level: 'machine',
81
81
  label: row.name,
82
- conductorIds: row.conductorIds,
82
+ args: { machine_id: row.hostKey },
83
83
  online: row.online,
84
84
  }));
85
85
  }
@@ -1,40 +1,29 @@
1
1
  import type { ConfirmRequest } from '../../../Screen/confirm-dialog.js';
2
- import type { DropshClient } from '../../../types.js';
3
- /** One run Restart runs cancels. */
4
- export interface CoveredRun {
5
- readonly id: string;
6
- readonly number: string;
7
- readonly state: string;
8
- readonly identifier: string;
9
- readonly frozen: boolean;
10
- /** JSON:API returns `error_log` empty (`BbRun::preSave` files it); its size tells whether one exists. */
11
- readonly errorLogBytes: number;
2
+ /** One ticket with the runs a restart cancels, grouped from `bakers_run_list`. */
3
+ export interface RestartableTicket {
4
+ readonly ticket: string;
5
+ readonly title: string;
6
+ readonly runs: readonly {
7
+ readonly uuid: string;
8
+ readonly number: number;
9
+ readonly state: string;
10
+ }[];
12
11
  }
13
- /** What Restart runs acts on: a machine (all its conductors) or one conductor. */
12
+ /** What Restart runs acts on: a machine, one conductor or one ticket. */
14
13
  export interface RestartTarget {
15
- readonly level: 'machine' | 'conductor';
14
+ readonly level: 'machine' | 'conductor' | 'ticket';
16
15
  readonly label: string;
17
- readonly conductorIds: readonly string[];
16
+ /** The `bakers_run_list` input naming the target. */
17
+ readonly args: Readonly<Record<string, string>>;
18
18
  /** Whether the conductor, or any conductor of the machine, is online. */
19
- readonly online: boolean;
19
+ readonly online?: boolean;
20
20
  }
21
21
  /**
22
- * The runs Restart runs cancels: every claimed or running run of these
23
- * conductors, plus each open ticket's newest run when it failed on one of them.
24
- *
25
- * shortcut: the server's rule (`TicketInterventions::restartCoveredRuns`) is
26
- * mirrored here, and each of the two reads takes one page of 50 (active runs
27
- * stay below a machine's capacity; failed runs are read newest first by
28
- * `changed`, then id, as `isNewest`); unify
29
- * once the site offers a restart endpoint.
30
- */
31
- export declare const restartCoveredRuns: (client: DropshClient, conductorIds: readonly string[]) => Promise<CoveredRun[]>;
32
- /** The error-log line naming Restart runs, its level and the person. */
33
- export declare const restartNote: (target: RestartTarget, person: string) => string;
34
- /**
35
- * Restart runs, for the confirmation dialog: cancel every covered run with a
36
- * note; the conductor then gives each ticket one fresh run.
37
- *
38
- * Confirm reads the set again and writes nothing when it changed.
22
+ * Restart runs, for the confirmation dialog. The site lists the covered runs
23
+ * by ticket (`bakers_run_list` restartable); a machine or conductor offers its
24
+ * tickets checked, a ticket confirms its own runs. OK reads the list again,
25
+ * cancels nothing when it changed, and else cancels the runs of the checked
26
+ * tickets in one `bakers_run_cancel`; the conductor gives each ticket one
27
+ * fresh run.
39
28
  */
40
29
  export declare const restartRunsRequest: (target: RestartTarget) => ConfirmRequest;
@@ -1,144 +1,90 @@
1
- import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
- import { CANCELLED_RUN_STATE } from '../../run/Form/edit.js';
3
- /** Whether `runId` is its ticket's newest run, in the failed-run breaker's order. */
4
- const isNewest = async (client, ticketId, runId) => {
5
- const params = new DrupalJsonApiParams()
6
- .addFilter('ticket_id.id', ticketId)
7
- .addSort('changed', 'DESC')
8
- .addSort('drupal_internal__id', 'DESC')
9
- .addFields('bb_run--bb_run', ['drupal_internal__id'])
10
- .addPageLimit(1);
11
- const doc = (await client.get('bb_run/bb_run', params));
12
- return doc.data?.[0]?.id === runId;
13
- };
14
- /** One page of these conductors' runs in `states`, tickets included. */
15
- const readRuns = async (client, conductorIds, states, order, openTicketsOnly = false) => {
16
- const params = new DrupalJsonApiParams()
17
- .addFilter('conductor_id.id', [...conductorIds], 'IN')
18
- .addFilter('state', states, 'IN')
19
- .addInclude(['ticket_id'])
20
- .addFields('bb_run--bb_run', [
21
- 'state',
22
- 'drupal_internal__id',
23
- 'error_log_bytes',
24
- 'ticket_id',
25
- ])
26
- .addFields('bb_ticket--bb_ticket', ['identifier', 'frozen'])
27
- .addSort('changed', order)
28
- .addSort('drupal_internal__id', order)
29
- .addPageLimit(50);
30
- if (openTicketsOnly)
31
- params.addFilter('ticket_id.closed', '0');
32
- const doc = (await client.get('bb_run/bb_run', params));
33
- const tickets = new Map((doc.included ?? []).map((t) => [t.id ?? '', t.attributes ?? {}]));
34
- return (doc.data ?? []).map((run) => {
35
- const ticketId = run.relationships?.ticket_id?.data?.id ?? '';
36
- const ticket = tickets.get(ticketId) ?? {};
37
- return {
38
- ticketId,
39
- run: {
40
- id: run.id ?? '',
41
- number: String(run.attributes?.drupal_internal__id ?? ''),
42
- state: String(run.attributes?.state ?? ''),
43
- identifier: String(ticket.identifier ?? '?'),
44
- frozen: ticket.frozen === true,
45
- errorLogBytes: Number(run.attributes?.error_log_bytes ?? 0),
46
- },
47
- };
1
+ import { siteTools } from '../../../lib/site-tools.js';
2
+ const readTickets = async (context, target) => {
3
+ const result = await siteTools(context.services)('bakers_run_list', {
4
+ ...target.args,
5
+ restartable: true,
48
6
  });
49
- };
50
- /**
51
- * The runs Restart runs cancels: every claimed or running run of these
52
- * conductors, plus each open ticket's newest run when it failed on one of them.
53
- *
54
- * shortcut: the server's rule (`TicketInterventions::restartCoveredRuns`) is
55
- * mirrored here, and each of the two reads takes one page of 50 (active runs
56
- * stay below a machine's capacity; failed runs are read newest first by
57
- * `changed`, then id, as `isNewest`); unify
58
- * once the site offers a restart endpoint.
59
- */
60
- export const restartCoveredRuns = async (client, conductorIds) => {
61
- if (conductorIds.length === 0)
62
- return [];
63
- const active = await readRuns(client, conductorIds, ['claimed', 'running'], 'ASC');
64
- const failed = await readRuns(client, conductorIds, ['failed'], 'DESC', true);
65
- const covered = active.map(({ run }) => run);
66
- const seen = new Set();
67
- for (const { ticketId, run } of failed) {
68
- // Newest first in isNewest's order: only a ticket's first failed run here can be its newest.
69
- if (seen.has(ticketId))
70
- continue;
71
- seen.add(ticketId);
72
- if (await isNewest(client, ticketId, run.id))
73
- covered.push(run);
7
+ // The site lists the runs grouped by ticket; keep that order.
8
+ const tickets = new Map();
9
+ for (const run of (result.runs ?? [])) {
10
+ const { ticket, ticket_title, ...rest } = run;
11
+ const entry = tickets.get(ticket) ?? {
12
+ ticket,
13
+ title: ticket_title,
14
+ runs: [],
15
+ };
16
+ entry.runs.push(rest);
17
+ tickets.set(ticket, entry);
74
18
  }
75
- return covered;
19
+ return [...tickets.values()];
76
20
  };
77
- /** The error-log line naming Restart runs, its level and the person. */
78
- export const restartNote = (target, person) => `Restart runs (${target.level} ${target.label}) by ${person}`;
79
- const runLine = (run) => `${run.identifier} · run #${run.number} · ${run.state}${run.frozen ? ' · frozen: the fresh run follows unfreeze' : ''}`;
80
- const sameRuns = (a, b) => a
81
- .map((run) => run.id)
21
+ const runList = (ticket) => ticket.runs.map((run) => `run #${run.number} (${run.state})`).join(', ');
22
+ const sameTickets = (a, b) => a
23
+ .map((ticket) => ticket.ticket)
82
24
  .sort()
83
25
  .join() ===
84
26
  b
85
- .map((run) => run.id)
27
+ .map((ticket) => ticket.ticket)
86
28
  .sort()
87
29
  .join();
88
30
  /**
89
- * Restart runs, for the confirmation dialog: cancel every covered run with a
90
- * note; the conductor then gives each ticket one fresh run.
91
- *
92
- * Confirm reads the set again and writes nothing when it changed.
31
+ * Restart runs, for the confirmation dialog. The site lists the covered runs
32
+ * by ticket (`bakers_run_list` restartable); a machine or conductor offers its
33
+ * tickets checked, a ticket confirms its own runs. OK reads the list again,
34
+ * cancels nothing when it changed, and else cancels the runs of the checked
35
+ * tickets in one `bakers_run_cancel`; the conductor gives each ticket one
36
+ * fresh run.
93
37
  */
94
38
  export const restartRunsRequest = (target) => ({
95
39
  title: '↻ Restart runs',
96
40
  prepare: async (context) => {
97
- const client = context.services?.client;
98
- if (!client)
99
- throw new Error('No connection to read the runs.');
100
- const runs = await restartCoveredRuns(client, target.conductorIds);
101
- const name = `${target.level} ${target.label}`;
102
- if (runs.length === 0)
103
- return { message: `No runs to restart on ${name}.` };
41
+ const tickets = await readTickets(context, target);
42
+ const name = target.level === 'ticket'
43
+ ? target.label
44
+ : `${target.level} ${target.label}`;
45
+ if (tickets.length === 0)
46
+ return {
47
+ message: target.level === 'ticket'
48
+ ? 'There is no run to restart.'
49
+ : `No runs to restart on ${name}.`,
50
+ };
51
+ const offline = target.online === false
52
+ ? [
53
+ 'It is offline: tab and runtime cleanup and the fresh runs follow its next start.',
54
+ ]
55
+ : [];
104
56
  return {
105
- message: `Restart runs on ${name}?`,
106
- detail: [
107
- ...runs.map(runLine),
108
- 'Each run is cancelled; its ticket gets one fresh run.',
109
- ...(target.online
110
- ? []
111
- : [
112
- 'It is offline: tab and runtime cleanup and the fresh runs follow its next start.',
113
- ]),
114
- ].join('\n'),
115
- confirm: async (confirmContext) => {
116
- const services = confirmContext.services;
117
- if (!services)
118
- throw new Error('No connection to restart the runs.');
119
- const fresh = await restartCoveredRuns(services.client, target.conductorIds);
120
- if (!sameRuns(fresh, runs))
57
+ labels: { confirm: 'OK', close: 'Cancel' },
58
+ ...(target.level === 'ticket'
59
+ ? {
60
+ message: `Restart ${name}?`,
61
+ detail: `${tickets.map(runList).join(', ')} is cancelled; the ticket gets one fresh run.`,
62
+ }
63
+ : {
64
+ message: `Restart runs on ${name}?`,
65
+ detail: [
66
+ "Each checked ticket's runs are cancelled; the ticket gets one fresh run.",
67
+ ...offline,
68
+ ].join('\n'),
69
+ checklist: tickets.map((ticket) => ({
70
+ id: ticket.ticket,
71
+ label: `${ticket.ticket} · ${ticket.title} · ${runList(ticket)}`,
72
+ })),
73
+ }),
74
+ confirm: async (confirmContext, checked) => {
75
+ const fresh = await readTickets(confirmContext, target);
76
+ if (!sameTickets(fresh, tickets))
121
77
  throw new Error('The runs changed since the dialog opened. Open it again.');
122
- const note = restartNote(target, services.currentUser ?? 'unknown');
123
- const writer = services.writeClient ?? services.client;
124
- // A PATCH replaces the stored error log, so read every existing one before writing any.
125
- const logs = await Promise.all(fresh.map((run) => {
126
- if (run.errorLogBytes === 0)
127
- return '';
128
- if (!writer.runLog)
129
- throw new Error("Cannot read the runs' error logs to keep them.");
130
- return writer.runLog(run.id, 'error_log');
131
- }));
132
- for (const [i, run] of fresh.entries()) {
133
- const log = logs[i]?.replace(/[\r\n]+$/, '') ?? '';
134
- await writer.update('bb_run--bb_run', run.id, {
135
- attributes: {
136
- state: CANCELLED_RUN_STATE,
137
- error_log: log ? `${log}\n${note}` : note,
138
- },
78
+ const chosen = target.level === 'ticket'
79
+ ? fresh
80
+ : fresh.filter((ticket) => checked.includes(ticket.ticket));
81
+ const runs = chosen.flatMap((ticket) => ticket.runs.map((r) => r.uuid));
82
+ if (runs.length > 0)
83
+ await siteTools(confirmContext.services)('bakers_run_cancel', {
84
+ runs,
85
+ reason: `Restart runs (${target.level} ${target.label})`,
139
86
  });
140
- }
141
- return { type: 'runs-restarted', count: fresh.length };
87
+ return { type: 'runs-restarted', count: runs.length };
142
88
  },
143
89
  };
144
90
  },
@@ -1,16 +1,6 @@
1
1
  export declare const CANCELLED_RUN_STATE = "cancelled";
2
2
  /**
3
- * The run states `cancel` leaves, mirroring `bb_run.transitions.cancel.from`
4
- * in `bb_core.workflows.yml` by hand.
5
- *
6
- * No served fact carries workflow transition edges, so widen this set together
7
- * with the YAML transition whenever its source states change.
3
+ * Whether a run offers Cancel run: claimed or running, or failed as its
4
+ * ticket's newest run. The site decides whether the cancel is allowed.
8
5
  */
9
- export declare const CANCELLABLE_RUN_STATES: ReadonlySet<string>;
10
- export interface CancelRunPayload {
11
- attributes: {
12
- state: typeof CANCELLED_RUN_STATE;
13
- };
14
- }
15
- export declare const cancelRunPayload: () => CancelRunPayload;
16
- export declare const isRunCancellable: (state: string) => boolean;
6
+ export declare const offersCancelRun: (state: string, newest: boolean) => boolean;
@@ -1,16 +1,6 @@
1
1
  export const CANCELLED_RUN_STATE = 'cancelled';
2
2
  /**
3
- * The run states `cancel` leaves, mirroring `bb_run.transitions.cancel.from`
4
- * in `bb_core.workflows.yml` by hand.
5
- *
6
- * No served fact carries workflow transition edges, so widen this set together
7
- * with the YAML transition whenever its source states change.
3
+ * Whether a run offers Cancel run: claimed or running, or failed as its
4
+ * ticket's newest run. The site decides whether the cancel is allowed.
8
5
  */
9
- export const CANCELLABLE_RUN_STATES = new Set([
10
- 'claimed',
11
- 'running',
12
- ]);
13
- export const cancelRunPayload = () => ({
14
- attributes: { state: CANCELLED_RUN_STATE },
15
- });
16
- export const isRunCancellable = (state) => CANCELLABLE_RUN_STATES.has(state);
6
+ export const offersCancelRun = (state, newest) => state === 'claimed' || state === 'running' || (state === 'failed' && newest);
@@ -10,8 +10,8 @@ export interface RunCancelledResult {
10
10
  /** `#<number>` of a run in `document`, or `''` when it is not included. */
11
11
  export declare const runNumber: (document: TicketDetailDocument, runId: string) => string;
12
12
  /**
13
- * PATCH the run to cancelled and return `document` with that run's state
14
- * patched, so the caller repaints without a refetch.
13
+ * Cancel the run through `bakers_run_cancel` and return `document` with that
14
+ * run's state patched, so the caller repaints without a refetch.
15
15
  */
16
16
  export declare const cancelRun: (context: ScreenContext, document: TicketDetailDocument, runId: string) => Promise<RunCancelledResult>;
17
17
  /** Cancel run, for the confirmation dialog. */
@@ -1,5 +1,6 @@
1
+ import { siteTools } from '../../../lib/site-tools.js';
1
2
  import { runResource } from '../Component/run-detail/index.js';
2
- import { CANCELLED_RUN_STATE, cancelRunPayload } from '../Form/edit.js';
3
+ import { CANCELLED_RUN_STATE } from '../Form/edit.js';
3
4
  /** `#<number>` of a run in `document`, or `''` when it is not included. */
4
5
  export const runNumber = (document, runId) => {
5
6
  const run = runResource(document, runId);
@@ -8,14 +9,14 @@ export const runNumber = (document, runId) => {
8
9
  : '';
9
10
  };
10
11
  /**
11
- * PATCH the run to cancelled and return `document` with that run's state
12
- * patched, so the caller repaints without a refetch.
12
+ * Cancel the run through `bakers_run_cancel` and return `document` with that
13
+ * run's state patched, so the caller repaints without a refetch.
13
14
  */
14
15
  export const cancelRun = async (context, document, runId) => {
15
- const client = context.services?.writeClient ?? context.services?.client;
16
- if (!client)
17
- throw new Error('No connection to cancel the run.');
18
- await client.update('bb_run--bb_run', runId, cancelRunPayload());
16
+ await siteTools(context.services)('bakers_run_cancel', {
17
+ runs: [runId],
18
+ reason: 'Cancel run',
19
+ });
19
20
  return {
20
21
  type: 'run-cancelled',
21
22
  runId,
@@ -4,7 +4,8 @@ import { defineContext } from '../../../Routing/context.js';
4
4
  import { AsyncScreen } from '../../../Screen/async-screen.js';
5
5
  import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
6
6
  import { runDetailRows, runDetailTitle, runDetailTree, runResource, } from '../Component/run-detail/index.js';
7
- import { isRunCancellable } from '../Form/edit.js';
7
+ import { ticketRunRows } from '../Data/runs.js';
8
+ import { offersCancelRun } from '../Form/edit.js';
8
9
  import { cancelRunRequest } from './run-actions.js';
9
10
  export const runDetailInputContext = defineContext('run-detail-input', 'input');
10
11
  /**
@@ -65,7 +66,8 @@ export class RunDetailScreen extends AsyncScreen {
65
66
  didLoad(document, context) {
66
67
  const run = runResource(document, context.params?.runId);
67
68
  this.cancellable =
68
- !!run && isRunCancellable(String(run.attributes?.state ?? ''));
69
+ !!run &&
70
+ offersCancelRun(String(run.attributes?.state ?? ''), ticketRunRows(document)[0]?.id === run.id);
69
71
  }
70
72
  actions() {
71
73
  return this.cancellable
@@ -3,11 +3,8 @@ import type { TicketDetailDocument } from '../../../types.js';
3
3
  /** Cancel ticket, for the confirmation dialog. */
4
4
  export declare const cancelTicketRequest: (document: TicketDetailDocument) => ConfirmRequest;
5
5
  /**
6
- * Restart run, for the confirmation dialog: cancel the ticket's active run and
7
- * nothing else; the conductor claims the ticket again as usual.
8
- *
9
- * The Overview document carries no runs (transcripts are big), so the dialog
10
- * reads them when it opens, with only the fields it needs. A run that ended
11
- * since leaves nothing to confirm.
6
+ * Restart runs of one ticket, for the confirmation dialog: the site lists the
7
+ * ticket's runs to restart, OK cancels them. Returns the ticket as read
8
+ * afterwards, so the detail repaints with its runs and derived_status.
12
9
  */
13
- export declare const restartRunRequest: (ticketId: string, identifier: string) => ConfirmRequest;
10
+ export declare const restartTicketRequest: (ticketId: string, identifier: string) => ConfirmRequest;
@@ -1,6 +1,4 @@
1
- import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
- import { CANCELLABLE_RUN_STATES } from '../../run/Form/edit.js';
3
- import { cancelRun, runNumber } from '../../run/Screen/run-actions.js';
1
+ import { restartRunsRequest } from '../../conductor/Screen/restart-runs.js';
4
2
  import { loadTicketDetail } from '../Data/detail.js';
5
3
  import { cancelEditPayload } from '../Form/edit.js';
6
4
  const identifierOf = (document) => String(document.data?.attributes?.identifier ?? document.data?.id ?? '');
@@ -24,38 +22,35 @@ export const cancelTicketRequest = (document) => ({
24
22
  }),
25
23
  });
26
24
  /**
27
- * Restart run, for the confirmation dialog: cancel the ticket's active run and
28
- * nothing else; the conductor claims the ticket again as usual.
29
- *
30
- * The Overview document carries no runs (transcripts are big), so the dialog
31
- * reads them when it opens, with only the fields it needs. A run that ended
32
- * since leaves nothing to confirm.
25
+ * Restart runs of one ticket, for the confirmation dialog: the site lists the
26
+ * ticket's runs to restart, OK cancels them. Returns the ticket as read
27
+ * afterwards, so the detail repaints with its runs and derived_status.
33
28
  */
34
- export const restartRunRequest = (ticketId, identifier) => ({
35
- title: '↻ Restart run',
36
- prepare: async (context) => {
37
- const client = context.services?.client;
38
- if (!client)
39
- throw new Error('No connection to read the runs.');
40
- const readRuns = () => client.get(`bb_ticket/bb_ticket/${ticketId}`, new DrupalJsonApiParams()
41
- .addInclude(['runs'])
42
- .addFields('bb_run--bb_run', ['state', 'drupal_internal__id']));
43
- const document = await readRuns();
44
- const active = document.included?.find((resource) => resource.type === 'bb_run--bb_run' &&
45
- CANCELLABLE_RUN_STATES.has(String(resource.attributes?.state ?? '')));
46
- const runId = active?.id;
47
- if (!runId)
48
- return { message: 'No active run any more.' };
49
- return {
50
- message: `Restart run${runNumber(document, runId)} of ${identifier}?`,
51
- detail: 'The active run is cancelled; the conductor starts a new one.',
52
- // Read again after the write: the ticket's derived_status changes with it.
53
- confirm: async (confirmContext) => {
54
- const cancelled = await cancelRun(confirmContext, document, runId);
55
- // The write landed; a failed re-read must not report it as failed.
56
- const fresh = await readRuns().catch(() => cancelled.document);
57
- return { ...cancelled, document: fresh };
58
- },
59
- };
60
- },
61
- });
29
+ export const restartTicketRequest = (ticketId, identifier) => {
30
+ const request = restartRunsRequest({
31
+ level: 'ticket',
32
+ label: identifier,
33
+ args: { ticket: ticketId },
34
+ });
35
+ return {
36
+ ...request,
37
+ prepare: async (context) => {
38
+ const prompt = await request.prepare(context);
39
+ const confirm = prompt.confirm;
40
+ if (!confirm)
41
+ return prompt;
42
+ return {
43
+ ...prompt,
44
+ confirm: async (confirmContext, checked) => {
45
+ await confirm(confirmContext, checked);
46
+ const client = confirmContext.services?.client;
47
+ // The cancel landed; a failed re-read must not report it as failed.
48
+ const document = client
49
+ ? await loadTicketDetail(client, ticketId).catch(() => undefined)
50
+ : undefined;
51
+ return { type: 'run-cancelled', document };
52
+ },
53
+ };
54
+ },
55
+ };
56
+ };
@@ -70,6 +70,7 @@ export declare abstract class TicketContentScreen extends AsyncScreen<TicketDeta
70
70
  private toggleFrozen;
71
71
  handleInput(input: string, context: ScreenContext): boolean;
72
72
  private cancellable;
73
+ /** The dialog asks the site which runs to restart; a closed or frozen ticket has none. */
73
74
  private restartable;
74
75
  commandForInput(input: string): string | undefined;
75
76
  actionForInput(input: string, context: ScreenContext): ScreenAction | undefined;
@@ -5,7 +5,6 @@ import { BORDER, textNode } from '../../../lib/vnode.js';
5
5
  import { AsyncScreen, } from '../../../Screen/async-screen.js';
6
6
  import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
7
7
  import { runRowAction } from '../../../Screen/row-action.js';
8
- import { activeRunInfo } from '../../run/Data/active-run.js';
9
8
  import { ADDONS_KEY, hasAddonsMessages, TicketContent, } from '../Component/ticket-content/index.js';
10
9
  import { initialExpandedKeys, resolveSelectedKey, retainExpandedKeys, ticketContentModel, ticketContentRowId, } from '../Component/ticket-content/model.js';
11
10
  import { handleTicketCopy, ticketCopyActions, ticketEditAction, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
@@ -16,7 +15,7 @@ import { ticketDetailInputContext } from '../Data/input.js';
16
15
  import { loadTicketView, mergeTicketDocuments, readTicket, refreshTicket, saveTicket, ticketLoaded, watchTicket, } from '../Data/store.js';
17
16
  import { updateTicketFrozen } from '../Data/write.js';
18
17
  import { isTicketCancellable } from '../Form/edit.js';
19
- import { cancelTicketRequest, restartRunRequest } from './ticket-actions.js';
18
+ import { cancelTicketRequest, restartTicketRequest } from './ticket-actions.js';
20
19
  /** Overview width when the context carries none — a pipe has no terminal. */
21
20
  const DEFAULT_COLUMNS = 80;
22
21
  /**
@@ -325,8 +324,9 @@ export class TicketContentScreen extends AsyncScreen {
325
324
  cancellable() {
326
325
  return !!this.document && isTicketCancellable(this.document);
327
326
  }
327
+ /** The dialog asks the site which runs to restart; a closed or frozen ticket has none. */
328
328
  restartable() {
329
- return !!this.document && activeRunInfo(this.document) !== null;
329
+ return this.cancellable() && !this.isFrozen();
330
330
  }
331
331
  commandForInput(input) {
332
332
  if (this.state !== 'ready' || this.viewMode !== 'full')
@@ -336,7 +336,7 @@ export class TicketContentScreen extends AsyncScreen {
336
336
  if (input === 'x' && this.cancellable())
337
337
  return 'cancel-ticket';
338
338
  if (input === 'r' && this.restartable())
339
- return 'restart-run';
339
+ return 'restart-runs';
340
340
  return undefined;
341
341
  }
342
342
  actionForInput(input, context) {
@@ -345,8 +345,8 @@ export class TicketContentScreen extends AsyncScreen {
345
345
  return ticketEditAction(context, this.document);
346
346
  if (command === 'cancel-ticket' && this.document)
347
347
  return confirmNavigation(cancelTicketRequest(this.document));
348
- if (command === 'restart-run' && this.document)
349
- return confirmNavigation(restartRunRequest(this.document.data?.id ?? context.params?.ticketId ?? '', ticketTitleOf(this.document).identifier));
348
+ if (command === 'restart-runs' && this.document)
349
+ return confirmNavigation(restartTicketRequest(this.document.data?.id ?? context.params?.ticketId ?? '', ticketTitleOf(this.document).identifier));
350
350
  return undefined;
351
351
  }
352
352
  receiveResult(result, context) {
@@ -355,7 +355,7 @@ export class TicketContentScreen extends AsyncScreen {
355
355
  : undefined;
356
356
  if (type === 'ticket-cancelled' || type === 'run-cancelled') {
357
357
  const document = result.document;
358
- // Restart run returns a sparse read: merged, so this view's includes stay.
358
+ // Merged, so this view's includes stay.
359
359
  if (document)
360
360
  this.replaceReady(saveTicket(context, mergeTicketDocuments(this.document, document)));
361
361
  context.requestDraw();
@@ -417,14 +417,14 @@ export class TicketContentScreen extends AsyncScreen {
417
417
  ...(this.cancellable()
418
418
  ? [actionItem('ticket-cancel', 'x', 'cancel ticket')]
419
419
  : []),
420
- ...(this.restartable()
421
- ? [actionItem('detail-restart', 'r', 'restart run')]
422
- : []),
423
- // Freeze and paging before copy: at 80 columns the footer clips the
424
- // tail, and `Y:Copy link` is the hint that yields.
420
+ // Freeze and paging before restart and copy: at 80 columns the footer
421
+ // clips the tail, and those hints yield.
425
422
  actionItem('detail-freeze', 'f', this.isFrozen() ? 'unfreeze' : 'freeze'),
426
423
  actionItem('detail-arrows', '↑↓', selectable > 1 ? 'select' : 'scroll'),
427
424
  actionItem('detail-page', 'PgUp/PgDn', 'page'),
425
+ ...(this.restartable()
426
+ ? [actionItem('detail-restart', 'r', 'restart runs')]
427
+ : []),
428
428
  ...ticketCopyActions(),
429
429
  ...(selectable > 0
430
430
  ? [actionItem('detail-enter', 'Enter/Space', 'expand')]
@@ -42,7 +42,7 @@ export declare class TicketRunsScreen extends AsyncScreen<TicketDetailDocument>
42
42
  select(index: number, context: ScreenContext): boolean;
43
43
  activate(index: number, context: ScreenContext): boolean;
44
44
  handleInput(input: string, context: ScreenContext): boolean;
45
- /** The selected run, when it can still be cancelled (claimed or running). */
45
+ /** The selected run, when it offers Cancel run (rows are newest first). */
46
46
  private cancellableRun;
47
47
  commandForInput(input: string): string | undefined;
48
48
  actionForInput(input: string): ScreenAction | undefined;
@@ -6,7 +6,7 @@ import { AsyncScreen } from '../../../Screen/async-screen.js';
6
6
  import { confirmNavigation } from '../../../Screen/confirm-dialog.js';
7
7
  import { listRowIds, listTableRows, listTableTree } from '../../collection.js';
8
8
  import { TICKET_RUN_TABLE, ticketRunRows } from '../../run/Data/runs.js';
9
- import { isRunCancellable } from '../../run/Form/edit.js';
9
+ import { offersCancelRun } from '../../run/Form/edit.js';
10
10
  import { cancelRunRequest } from '../../run/Screen/run-actions.js';
11
11
  import { handleTicketCopy, ticketCopyActions, ticketHeaderTree, ticketTitleOf, } from '../Component/ticket-detail/index.js';
12
12
  import { ticketDetailInputContext, ticketInputContext } from '../Data/input.js';
@@ -134,12 +134,14 @@ export class TicketRunsScreen extends AsyncScreen {
134
134
  return this.select(view.selectable - 1, context);
135
135
  return false;
136
136
  }
137
- /** The selected run, when it can still be cancelled (claimed or running). */
137
+ /** The selected run, when it offers Cancel run (rows are newest first). */
138
138
  cancellableRun() {
139
139
  if (!this.document)
140
140
  return undefined;
141
141
  const run = ticketRunRows(this.document)[this.cursor.index];
142
- return run?.id && isRunCancellable(run.state) ? { id: run.id } : undefined;
142
+ return run?.id && offersCancelRun(run.state, this.cursor.index === 0)
143
+ ? { id: run.id }
144
+ : undefined;
143
145
  }
144
146
  commandForInput(input) {
145
147
  return this.state === 'ready' && input === 'x' && this.cancellableRun()
@@ -2,12 +2,24 @@ import type { VNode } from '@opentui/core';
2
2
  import { AsyncModalScreen } from './async-modal-screen.js';
3
3
  import type { ModalChrome } from './modal-screen.js';
4
4
  import type { ScreenAction, ScreenContext } from './screen.js';
5
+ /** One row of a confirmation's checklist. */
6
+ export interface ChecklistItem {
7
+ readonly id: string;
8
+ readonly label: string;
9
+ }
5
10
  /** What the dialog shows once its request is prepared. */
6
11
  export interface ConfirmPrompt {
7
12
  readonly message: string;
8
13
  readonly detail?: string;
14
+ /** Rows the person may uncheck, all checked at first; confirm gets the checked ids. */
15
+ readonly checklist?: readonly ChecklistItem[];
16
+ /** Button labels; default Confirm and Close. */
17
+ readonly labels?: {
18
+ readonly confirm: string;
19
+ readonly close: string;
20
+ };
9
21
  /** Absent: there is nothing to confirm, and Enter writes nothing. */
10
- readonly confirm?: (context: ScreenContext) => Promise<unknown>;
22
+ readonly confirm?: (context: ScreenContext, checked: readonly string[]) => Promise<unknown>;
11
23
  }
12
24
  /**
13
25
  * One confirmable action. The dialog knows no entity: each slice builds its
@@ -20,7 +32,10 @@ export interface ConfirmRequest {
20
32
  export declare const confirmRequestContext: import("../Routing/context.js").ContextKey<ConfirmRequest>;
21
33
  /** The action that opens the dialog for `request`. */
22
34
  export declare const confirmNavigation: (request: ConfirmRequest) => ScreenAction;
23
- /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
35
+ /**
36
+ * The confirmation dialog: Enter confirms, Esc closes and writes nothing. A
37
+ * checklist moves with ↑/↓ and toggles with Space.
38
+ */
24
39
  export declare class ConfirmDialogScreen extends AsyncModalScreen<ConfirmPrompt> {
25
40
  static readonly route: {
26
41
  id: string;
@@ -35,6 +50,11 @@ export declare class ConfirmDialogScreen extends AsyncModalScreen<ConfirmPrompt>
35
50
  private submitting;
36
51
  /** Index of the focused button; Confirm, the first, when there is one. */
37
52
  private focus;
53
+ /** The checklist's checked ids and cursor, for the prompt they were set up for. */
54
+ private checked;
55
+ private cursor;
56
+ private checklistOf;
57
+ private checklist;
38
58
  private buttons;
39
59
  protected load(context: ScreenContext): Promise<ConfirmPrompt>;
40
60
  protected renderLoading(): string[];
@@ -23,7 +23,10 @@ const BUTTON_LABELS = {
23
23
  confirm: 'Confirm',
24
24
  close: 'Close',
25
25
  };
26
- /** The confirmation dialog: Enter confirms, Esc closes and writes nothing. */
26
+ /**
27
+ * The confirmation dialog: Enter confirms, Esc closes and writes nothing. A
28
+ * checklist moves with ↑/↓ and toggles with Space.
29
+ */
27
30
  export class ConfirmDialogScreen extends AsyncModalScreen {
28
31
  static route = {
29
32
  id: 'confirm',
@@ -38,6 +41,19 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
38
41
  submitting = false;
39
42
  /** Index of the focused button; Confirm, the first, when there is one. */
40
43
  focus = 0;
44
+ /** The checklist's checked ids and cursor, for the prompt they were set up for. */
45
+ checked = new Set();
46
+ cursor = 0;
47
+ checklistOf;
48
+ checklist(prompt) {
49
+ const items = prompt.checklist ?? [];
50
+ if (this.checklistOf !== prompt) {
51
+ this.checklistOf = prompt;
52
+ this.checked = new Set(items.map((item) => item.id));
53
+ this.cursor = 0;
54
+ }
55
+ return items;
56
+ }
41
57
  buttons() {
42
58
  return this.readyValue?.confirm ? ['confirm', 'close'] : ['close'];
43
59
  }
@@ -51,13 +67,17 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
51
67
  return ['Loading…'];
52
68
  }
53
69
  renderReady(prompt) {
54
- return columnNode('confirm-dialog', ...rowsOf('confirm-dialog-message', prompt.message), ...rowsOf('confirm-dialog-detail', this.message || prompt.detail || ''), textNode({ id: 'confirm-dialog-gap', content: '' }), rowNode('confirm-dialog-buttons', ...this.buttons().flatMap((button, index) => [
70
+ return columnNode('confirm-dialog', ...rowsOf('confirm-dialog-message', prompt.message), ...rowsOf('confirm-dialog-detail', this.message || prompt.detail || ''), ...this.checklist(prompt).map((item, index) => textNode({
71
+ id: `confirm-dialog-item-${index}`,
72
+ content: `${index === this.cursor ? '▸' : ' '}[${this.checked.has(item.id) ? 'x' : ' '}] ${item.label}`,
73
+ selected: index === this.cursor,
74
+ })), textNode({ id: 'confirm-dialog-gap', content: '' }), rowNode('confirm-dialog-buttons', ...this.buttons().flatMap((button, index) => [
55
75
  ...(index > 0
56
76
  ? [textNode({ id: `confirm-dialog-gap-${index}`, content: ' ' })]
57
77
  : []),
58
78
  textNode({
59
79
  id: `confirm-dialog-button-${button}`,
60
- content: `${index === this.focus ? '▸' : ' '}[ ${BUTTON_LABELS[button]} ]`,
80
+ content: `${index === this.focus ? '▸' : ' '}[ ${prompt.labels?.[button] ?? BUTTON_LABELS[button]} ]`,
61
81
  selected: index === this.focus,
62
82
  }),
63
83
  ])));
@@ -67,6 +87,12 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
67
87
  }
68
88
  actions() {
69
89
  return [
90
+ ...(this.readyValue?.checklist?.length
91
+ ? [
92
+ actionItem('confirm-rows', '↑↓', 'row'),
93
+ actionItem('confirm-toggle', 'Space', 'check'),
94
+ ]
95
+ : []),
70
96
  actionItem('confirm-move', '←→', 'button'),
71
97
  actionItem('confirm-press', 'Enter', 'press'),
72
98
  actionItem('confirm-esc', 'Esc', 'close'),
@@ -82,6 +108,22 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
82
108
  return true;
83
109
  if (!this.readyValue)
84
110
  return false;
111
+ const items = this.checklist(this.readyValue);
112
+ if (items.length > 0 && !this.submitting) {
113
+ const move = input === 'down' ? 1 : input === 'up' ? -1 : 0;
114
+ if (move !== 0) {
115
+ this.cursor = (this.cursor + move + items.length) % items.length;
116
+ context.requestDraw();
117
+ return true;
118
+ }
119
+ const item = input === ' ' ? items[this.cursor] : undefined;
120
+ if (item) {
121
+ if (!this.checked.delete(item.id))
122
+ this.checked.add(item.id);
123
+ context.requestDraw();
124
+ return true;
125
+ }
126
+ }
85
127
  const buttons = this.buttons();
86
128
  const step = input === 'right' || input === 'tab'
87
129
  ? 1
@@ -113,7 +155,10 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
113
155
  }
114
156
  this.submitting = true;
115
157
  this.message = '';
116
- void confirm(context)
158
+ const checked = items
159
+ .filter((item) => this.checked.has(item.id))
160
+ .map((item) => item.id);
161
+ void confirm(context, checked)
117
162
  .then((result) => {
118
163
  if (!context.isActive())
119
164
  return;
@@ -143,6 +188,9 @@ export class ConfirmDialogScreen extends AsyncModalScreen {
143
188
  this.message = '';
144
189
  this.submitting = false;
145
190
  this.focus = 0;
191
+ this.checked = new Set();
192
+ this.cursor = 0;
193
+ this.checklistOf = undefined;
146
194
  super.reset();
147
195
  }
148
196
  }
@@ -0,0 +1,3 @@
1
+ import type { RendererServices } from '../types.js';
2
+ /** The connection's site tool caller, or an error naming what is missing. */
3
+ export declare const siteTools: (services: RendererServices | undefined) => (name: string, args: Record<string, unknown>) => Promise<Record<string, unknown>>;
@@ -0,0 +1,7 @@
1
+ /** The connection's site tool caller, or an error naming what is missing. */
2
+ export const siteTools = (services) => {
3
+ const client = services?.writeClient ?? services?.client;
4
+ if (!client?.callTool)
5
+ throw new Error('No connection to the site tools.');
6
+ return client.callTool.bind(client);
7
+ };
@@ -52,6 +52,12 @@ export interface DropshClient {
52
52
  * returns `log` and `error_log` empty.
53
53
  */
54
54
  runLog?(runId: string, kind: 'log' | 'error_log'): Promise<string>;
55
+ /**
56
+ * Calls a site tool on `/mcp` by its plain name (`bakers_run_cancel`) and
57
+ * returns its structured result; a refusal throws with the site's text.
58
+ * Only the write client built by `bakers ui` carries it.
59
+ */
60
+ callTool?(name: string, args: Record<string, unknown>): Promise<Record<string, unknown>>;
55
61
  }
56
62
  /** A JSON:API relationship linkage. */
57
63
  export interface JsonApiRelationship {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bakers-build/addon-bakers-ui",
3
- "version": "0.12.1-next.1",
3
+ "version": "0.12.1-next.3",
4
4
  "description": "bakers.build TUI: interactive terminal UI (dashboard, projects, tickets) as a dropsh `tui` renderer plugin.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,11 +32,11 @@
32
32
  "zustand": "^5.0.15"
33
33
  },
34
34
  "peerDependencies": {
35
- "@bakers-build/core": "^0.12.1-next.1",
36
- "@bakers-build/message": "^0.12.1-next.1"
35
+ "@bakers-build/core": "^0.12.1-next.3",
36
+ "@bakers-build/message": "^0.12.1-next.3"
37
37
  },
38
38
  "bakersBuild": {
39
- "commit": "faa5ecb660013bf826a791b95c2cb2373cb5a907",
39
+ "commit": "44b684b677784841cc9111f737fc185759363485",
40
40
  "channel": "next"
41
41
  }
42
42
  }