agl 42.2.1 → 43.0.0

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 (173) hide show
  1. package/changelog.md +22 -0
  2. package/dist_serve/bundle.js +6697 -5287
  3. package/dist_serve/bundle.js.map +2 -2
  4. package/dist_serve/bundle.js.third-party-notices.json +31 -31
  5. package/dist_serve/bundle.js.third-party-notices.txt +31 -31
  6. package/dist_serve/third-party-notices.md +597 -8
  7. package/dist_ts/00_commitinfo_data.js +1 -1
  8. package/dist_ts/aglapi/aglapisurface.document.js +114 -16
  9. package/dist_ts/aglapi/interfaces.d.ts +30 -0
  10. package/dist_ts/aglapi/interfaces.js +7 -1
  11. package/dist_ts/classes.authstore.d.ts +7 -0
  12. package/dist_ts/classes.authstore.js +12 -1
  13. package/dist_ts/classes.cli.js +10 -1
  14. package/dist_ts/classes.controller.d.ts +41 -11
  15. package/dist_ts/classes.controller.js +224 -48
  16. package/dist_ts/classes.harnessoperationmanager.d.ts +44 -0
  17. package/dist_ts/classes.harnessoperationmanager.js +15 -10
  18. package/dist_ts/classes.mcpclient.d.ts +5 -0
  19. package/dist_ts/classes.mcpclient.js +15 -3
  20. package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
  21. package/dist_ts/classes.mcpcontrollerhost.js +14 -2
  22. package/dist_ts/classes.mcptools.d.ts +4 -3
  23. package/dist_ts/classes.mcptools.js +20 -1
  24. package/dist_ts/classes.mcpvalidation.js +4 -1
  25. package/dist_ts/classes.ticketstore.d.ts +71 -3
  26. package/dist_ts/classes.ticketstore.js +299 -12
  27. package/dist_ts/classes.validation.d.ts +2 -0
  28. package/dist_ts/classes.validation.js +27 -5
  29. package/dist_ts/driver/classes.directreports.d.ts +23 -3
  30. package/dist_ts/driver/classes.directreports.js +59 -2
  31. package/dist_ts/driver/classes.drivereventrelay.js +3 -2
  32. package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
  33. package/dist_ts/driver/functions.driverinstructions.js +12 -3
  34. package/dist_ts/driver/functions.drivertools.d.ts +4 -0
  35. package/dist_ts/driver/functions.drivertools.js +8 -2
  36. package/dist_ts/fleet/classes.boardpump.d.ts +53 -3
  37. package/dist_ts/fleet/classes.boardpump.js +237 -32
  38. package/dist_ts/fleet/classes.claudeworkers.d.ts +10 -3
  39. package/dist_ts/fleet/classes.claudeworkers.js +43 -19
  40. package/dist_ts/fleet/classes.codexworkers.d.ts +5 -3
  41. package/dist_ts/fleet/classes.codexworkers.js +26 -9
  42. package/dist_ts/fleet/classes.deploymonitor.d.ts +253 -0
  43. package/dist_ts/fleet/classes.deploymonitor.js +821 -0
  44. package/dist_ts/fleet/classes.gitfacts.d.ts +61 -0
  45. package/dist_ts/fleet/classes.gitfacts.js +125 -0
  46. package/dist_ts/fleet/classes.releasereconciler.d.ts +51 -0
  47. package/dist_ts/fleet/classes.releasereconciler.js +101 -0
  48. package/dist_ts/fleet/classes.service.d.ts +13 -1
  49. package/dist_ts/fleet/classes.service.js +76 -7
  50. package/dist_ts/fleet/classes.ticketeffects.d.ts +13 -0
  51. package/dist_ts/fleet/classes.ticketeffects.js +42 -8
  52. package/dist_ts/fleet/classes.workers.d.ts +10 -3
  53. package/dist_ts/fleet/classes.workers.js +18 -3
  54. package/dist_ts/fleet/functions.controllerbuild.d.ts +23 -0
  55. package/dist_ts/fleet/functions.controllerbuild.js +75 -0
  56. package/dist_ts/fleet/functions.deployprobes.d.ts +39 -0
  57. package/dist_ts/fleet/functions.deployprobes.js +82 -0
  58. package/dist_ts/fleet/functions.deployvalidation.d.ts +27 -0
  59. package/dist_ts/fleet/functions.deployvalidation.js +43 -0
  60. package/dist_ts/fleet/functions.release.d.ts +2 -1
  61. package/dist_ts/fleet/functions.release.js +32 -5
  62. package/dist_ts/fleet/functions.releasefacts.d.ts +45 -0
  63. package/dist_ts/fleet/functions.releasefacts.js +68 -0
  64. package/dist_ts/fleet/functions.validation.d.ts +3 -3
  65. package/dist_ts/fleet/functions.validation.js +4 -7
  66. package/dist_ts/fleet/functions.watchprobes.js +7 -9
  67. package/dist_ts/fleet/functions.workervalidation.js +4 -3
  68. package/dist_ts/fleet/interfaces.workers.d.ts +30 -3
  69. package/dist_ts/fleet/interfaces.workers.js +14 -1
  70. package/dist_ts/functions.deploycli.d.ts +33 -0
  71. package/dist_ts/functions.deploycli.js +155 -0
  72. package/dist_ts/functions.mcpdeploytools.d.ts +13 -0
  73. package/dist_ts/functions.mcpdeploytools.js +16 -0
  74. package/dist_ts/functions.mcptickettools.d.ts +54 -0
  75. package/dist_ts/functions.mcptickettools.js +8 -7
  76. package/dist_ts/functions.monacoassets.js +3 -3
  77. package/dist_ts/functions.ticketautolabels.d.ts +2 -0
  78. package/dist_ts/functions.ticketautolabels.js +9 -3
  79. package/dist_ts/functions.ticketcli.d.ts +16 -2
  80. package/dist_ts/functions.ticketcli.js +105 -27
  81. package/dist_ts/functions.ticketvalidation.d.ts +55 -0
  82. package/dist_ts/functions.ticketvalidation.js +26 -8
  83. package/dist_ts_interfaces/deployments.d.ts +241 -0
  84. package/dist_ts_interfaces/deployments.js +5 -6
  85. package/dist_ts_interfaces/fleet.d.ts +12 -0
  86. package/dist_ts_interfaces/fleetworkers.d.ts +21 -1
  87. package/dist_ts_interfaces/interfaces.d.ts +4 -2
  88. package/dist_ts_interfaces/interfaces.js +4 -2
  89. package/dist_ts_interfaces/mcprequests.d.ts +3 -2
  90. package/dist_ts_interfaces/mcprequests.js +3 -1
  91. package/dist_ts_interfaces/requests.d.ts +3 -2
  92. package/dist_ts_interfaces/requests.directreports.d.ts +58 -6
  93. package/dist_ts_interfaces/requests.js +1 -1
  94. package/dist_ts_interfaces/requests.tickets.d.ts +25 -5
  95. package/dist_ts_interfaces/requests.tickets.js +2 -2
  96. package/dist_ts_interfaces/tickets.d.ts +71 -6
  97. package/dist_ts_interfaces/tickets.js +34 -6
  98. package/dist_ts_migration/classes.documentmigrationrunner.d.ts +7 -0
  99. package/dist_ts_migration/classes.documentmigrationrunner.js +14 -1
  100. package/dist_ts_migration/index.d.ts +2 -0
  101. package/dist_ts_migration/index.js +3 -1
  102. package/dist_ts_migration/v41_ticketclosedcolumn.d.ts +20 -0
  103. package/dist_ts_migration/v41_ticketclosedcolumn.js +118 -0
  104. package/dist_ts_migration/v41_ticketlinkrepos.d.ts +24 -0
  105. package/dist_ts_migration/v41_ticketlinkrepos.js +101 -0
  106. package/package.json +6 -2
  107. package/readme.md +307 -37
  108. package/third-party-notices.md +597 -8
  109. package/ts/00_commitinfo_data.ts +1 -1
  110. package/ts/aglapi/aglapisurface.document.ts +113 -15
  111. package/ts/aglapi/interfaces.ts +6 -0
  112. package/ts/classes.authstore.ts +13 -0
  113. package/ts/classes.cli.ts +9 -0
  114. package/ts/classes.controller.ts +238 -59
  115. package/ts/classes.harnessoperationmanager.ts +20 -14
  116. package/ts/classes.mcpclient.ts +17 -2
  117. package/ts/classes.mcpcontrollerhost.ts +15 -1
  118. package/ts/classes.mcptools.ts +21 -2
  119. package/ts/classes.mcpvalidation.ts +2 -0
  120. package/ts/classes.ticketstore.ts +312 -13
  121. package/ts/classes.validation.ts +28 -4
  122. package/ts/driver/classes.directreports.ts +58 -3
  123. package/ts/driver/classes.drivereventrelay.ts +2 -1
  124. package/ts/driver/functions.driverinstructions.ts +11 -2
  125. package/ts/driver/functions.drivertools.ts +10 -2
  126. package/ts/fleet/classes.boardpump.ts +235 -28
  127. package/ts/fleet/classes.claudeworkers.ts +36 -15
  128. package/ts/fleet/classes.codexworkers.ts +24 -7
  129. package/ts/fleet/classes.deploymonitor.ts +854 -0
  130. package/ts/fleet/classes.gitfacts.ts +135 -0
  131. package/ts/fleet/classes.releasereconciler.ts +103 -0
  132. package/ts/fleet/classes.service.ts +81 -8
  133. package/ts/fleet/classes.ticketeffects.ts +38 -6
  134. package/ts/fleet/classes.workers.ts +19 -5
  135. package/ts/fleet/functions.controllerbuild.ts +84 -0
  136. package/ts/fleet/functions.deployprobes.ts +84 -0
  137. package/ts/fleet/functions.deployvalidation.ts +50 -0
  138. package/ts/fleet/functions.release.ts +32 -3
  139. package/ts/fleet/functions.releasefacts.ts +91 -0
  140. package/ts/fleet/functions.validation.ts +3 -6
  141. package/ts/fleet/functions.watchprobes.ts +6 -8
  142. package/ts/fleet/functions.workervalidation.ts +3 -2
  143. package/ts/fleet/interfaces.workers.ts +23 -3
  144. package/ts/functions.deploycli.ts +151 -0
  145. package/ts/functions.mcpdeploytools.ts +18 -0
  146. package/ts/functions.mcptickettools.ts +7 -6
  147. package/ts/functions.monacoassets.ts +2 -2
  148. package/ts/functions.ticketautolabels.ts +10 -2
  149. package/ts/functions.ticketcli.ts +100 -24
  150. package/ts/functions.ticketvalidation.ts +26 -7
  151. package/ts_interfaces/deployments.ts +194 -0
  152. package/ts_interfaces/fleet.ts +17 -2
  153. package/ts_interfaces/fleetworkers.ts +20 -0
  154. package/ts_interfaces/interfaces.ts +3 -1
  155. package/ts_interfaces/mcprequests.ts +3 -0
  156. package/ts_interfaces/requests.directreports.ts +52 -8
  157. package/ts_interfaces/requests.tickets.ts +20 -4
  158. package/ts_interfaces/requests.ts +6 -1
  159. package/ts_interfaces/tickets.ts +53 -6
  160. package/ts_migration/classes.documentmigrationrunner.ts +15 -0
  161. package/ts_migration/index.ts +2 -0
  162. package/ts_migration/v41_ticketclosedcolumn.ts +106 -0
  163. package/ts_migration/v41_ticketlinkrepos.ts +91 -0
  164. package/ts_web/00_commitinfo_data.ts +1 -1
  165. package/ts_web/elements.deployments.ts +1066 -0
  166. package/ts_web/elements.directreport.ts +2 -2
  167. package/ts_web/elements.directreportsession.ts +5 -5
  168. package/ts_web/elements.harnesscontrollerapp.ts +179 -13
  169. package/ts_web/elements.makedirectreport.ts +444 -0
  170. package/ts_web/elements.nativesession.ts +29 -1
  171. package/ts_web/elements.ticketboard.ts +74 -18
  172. package/ts_web/functions.deployments.ts +225 -0
  173. package/ts_web/functions.sessionchat.ts +2 -0
@@ -0,0 +1,1066 @@
1
+ import * as plugins from './plugins.js';
2
+ import * as interfaces from '../ts_interfaces/index.js';
3
+ import {
4
+ deployAge, deployClock, deployGoView, deployMoment, deployNextStep, deployPlanLine, deployProbeText, deployTargetName, deployWhenText, deployWindowRange,
5
+ deployWindowStateView, shortSha, summarizeDeployments, type IDeploymentsSummary,
6
+ } from './functions.deployments.js';
7
+
8
+ const { html, css } = plugins.deesElement;
9
+
10
+ /** How the deploy views reach the controller: the socket client, or a test's recorder. */
11
+ export interface IDeploymentsSender {
12
+ fire<TRequest extends interfaces.TControllerRequest>(
13
+ methodArg: TRequest['method'],
14
+ requestArg: TRequest['request'],
15
+ optionsArg?: { abortSignal?: AbortSignal },
16
+ ): Promise<TRequest['response']>;
17
+ }
18
+
19
+ const deploy = <TOperation extends interfaces.TFleetDeployOperation>(senderArg: IDeploymentsSender, operationArg: TOperation,
20
+ requestArg: interfaces.IFleetDeployOperations[TOperation]['request']): Promise<interfaces.IFleetDeployOperations[TOperation]['response']> => (
21
+ senderArg.fire<interfaces.TControllerDeployTypedRequest>(`controller.deploy.${operationArg}`, requestArg as never) as Promise<
22
+ interfaces.IFleetDeployOperations[TOperation]['response']>
23
+ );
24
+ const ticket = <TMethod extends interfaces.TTicketOperation>(senderArg: IDeploymentsSender, operationArg: TMethod,
25
+ requestArg: interfaces.TTicketRequest<TMethod>): Promise<interfaces.TTicketResponse<TMethod>> => (
26
+ senderArg.fire<interfaces.TControllerTicketTypedRequest>(`controller.ticket.${operationArg}`, requestArg as never) as Promise<interfaces.TTicketResponse<TMethod>>
27
+ );
28
+
29
+ /**
30
+ * Inline styles for what the views render inside other elements' shadow roots (a table cell, a grouped-list row), where
31
+ * this element's stylesheet does not reach.
32
+ */
33
+ const inline = {
34
+ cell: 'display: grid; gap: 2px; min-width: 0; max-width: 170px; white-space: normal; line-height: 1.35;',
35
+ line: 'display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px;',
36
+ muted: 'color: var(--dees-color-text-secondary); font-size: 12px;',
37
+ name: 'font-weight: 600; color: var(--dees-color-text-primary);',
38
+ version: 'font-family: var(--dees-font-family-mono); font-size: 12px; font-weight: 600; color: var(--dees-color-text-primary);',
39
+ sha: 'font-family: var(--dees-font-family-mono); font-size: 11px; color: var(--dees-color-text-secondary);',
40
+ error: 'color: var(--dees-color-text-error);',
41
+ chip: 'display: inline-flex; align-items: center; padding: 0 5px; border-radius: 5px; border: 1px solid var(--dees-color-border-subtle); '
42
+ + 'background: transparent; color: var(--dees-color-text-secondary); font: 11px/16px var(--dees-font-family-mono); cursor: pointer;',
43
+ };
44
+
45
+ /** A ticket key inside something that is a button itself (an actionable row): the chip's look, no button of its own. */
46
+ const ticketKeyText = (keyArg: string) => html`<span style=${inline.chip}>${keyArg}</span>`;
47
+
48
+ /** A ticket key as the views show it: a chip that opens the ticket on the board. */
49
+ const ticketChip = (keyArg: string) => html`<button class="ticketKey" style=${inline.chip} data-ticket=${keyArg} @click=${(eventArg: Event) => {
50
+ eventArg.stopPropagation();
51
+ eventArg.currentTarget!.dispatchEvent(new CustomEvent('deploy-open-ticket', { detail: { key: keyArg }, bubbles: true, composed: true }));
52
+ }}>${keyArg}</button>`;
53
+
54
+ const sharedStyles = css`
55
+ .ticketKey {
56
+ display: inline-flex; align-items: center; padding: 0 5px; border-radius: 5px; border: 1px solid var(--dees-color-border-subtle);
57
+ background: transparent; color: var(--dees-color-text-secondary); font: 11px/16px var(--dees-font-family-mono); cursor: pointer;
58
+ }
59
+ .ticketKey:hover { color: var(--dees-color-text-primary); border-color: var(--dees-color-accent-primary); }
60
+ code, .mono { font-family: var(--dees-font-family-mono); font-size: 12px; }
61
+ .muted { color: var(--dees-color-text-secondary); }
62
+ .strong { font-weight: 600; color: var(--dees-color-text-primary); }
63
+ `;
64
+
65
+ /**
66
+ * The Deployments view (AGL-914, AGL-909): what each target runs, as its probe observed it, the plans and what changed.
67
+ * Everything comes from `controller.deploy.*`; a plan is a ticket's release plan, deploy plan or maintenance window,
68
+ * set with `controller.ticket.*`, and the owner's go on a deploy plan is the answer to its question.
69
+ */
70
+ @plugins.deesElement.customElement('agl-deployments')
71
+ export class AglDeployments extends plugins.deesElement.DeesElement {
72
+ @plugins.deesElement.property({ attribute: false })
73
+ accessor sender: IDeploymentsSender | undefined;
74
+
75
+ /** AGL's projects, for a new ticket a plan creates. */
76
+ @plugins.deesElement.property({ attribute: false })
77
+ accessor projects: interfaces.IControllerProject[] = [];
78
+
79
+ @plugins.deesElement.state()
80
+ accessor status: interfaces.IFleetDeployStatus | undefined;
81
+
82
+ @plugins.deesElement.state()
83
+ accessor release: interfaces.IFleetReleaseStatus | undefined;
84
+
85
+ /** Each target's observations, newest first, for what changed and the target sheet. */
86
+ @plugins.deesElement.state()
87
+ accessor histories: Record<string, interfaces.IFleetDeployObservation[]> = {};
88
+
89
+ @plugins.deesElement.state()
90
+ accessor loading = true;
91
+
92
+ @plugins.deesElement.state()
93
+ accessor error = '';
94
+
95
+ @plugins.deesElement.state()
96
+ accessor probing = false;
97
+
98
+ @plugins.deesElement.state()
99
+ accessor now = Date.now();
100
+
101
+ /** The open target sheet, kept current as the view reads again. */
102
+ private sheet: { targetId: string; modal: plugins.deesCatalog.DeesModal } | undefined;
103
+ private generation = 0;
104
+
105
+ public static styles = [
106
+ plugins.deesElement.cssManager.defaultStyles,
107
+ plugins.deesCatalog.themeDefaultStyles,
108
+ sharedStyles,
109
+ css`
110
+ :host { display: block; height: 100%; min-height: 0; overflow: auto; }
111
+ .page { display: grid; gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; }
112
+ .head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 16px; }
113
+ h2 { margin: 0; font-size: 22px; font-weight: 700; color: var(--dees-color-text-primary); }
114
+ .subtitle { margin: 4px 0 0; font-size: 13px; color: var(--dees-color-text-secondary); }
115
+ .actions { display: flex; flex-wrap: wrap; gap: 8px; }
116
+ .cell { display: grid; gap: 2px; min-width: 0; }
117
+ .cellLine { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
118
+ .targetName { font-weight: 600; color: var(--dees-color-text-primary); }
119
+ .lower { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
120
+ .note { margin: 0; font-size: 12px; color: var(--dees-color-text-secondary); }
121
+ .error { color: var(--dees-color-text-error); }
122
+ @media (max-width: 1100px) { .lower { grid-template-columns: minmax(0, 1fr); } }
123
+ @media (max-width: 600px) { .page { padding: 12px; gap: 14px; } h2 { font-size: 19px; } }
124
+ `,
125
+ ];
126
+
127
+ public async connectedCallback(): Promise<void> {
128
+ await super.connectedCallback();
129
+ void this.refresh();
130
+ }
131
+
132
+ public async disconnectedCallback(): Promise<void> {
133
+ this.generation += 1;
134
+ await this.sheet?.modal.destroy();
135
+ this.sheet = undefined;
136
+ await super.disconnectedCallback();
137
+ }
138
+
139
+ /** Reads every target's status, the release state and the targets' histories again; `deployments.changed` calls it. */
140
+ public async refresh(): Promise<void> {
141
+ const sender = this.sender;
142
+ if (!sender) return;
143
+ const generation = ++this.generation;
144
+ try {
145
+ const [status, release] = await Promise.all([deploy(sender, 'status', {}), deploy(sender, 'release', {})]);
146
+ const histories = Object.fromEntries(await Promise.all(status.targets.map(async (targetArg) => [targetArg.target.id,
147
+ (await deploy(sender, 'history', { targetId: targetArg.target.id, limit: 20 })).observations] as const)));
148
+ if (generation !== this.generation) return;
149
+ this.status = status; this.release = release; this.histories = histories; this.error = ''; this.now = Date.now();
150
+ this.updateSheet();
151
+ } catch (errorArg) {
152
+ if (generation === this.generation) this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
153
+ } finally {
154
+ if (generation === this.generation) this.loading = false;
155
+ }
156
+ }
157
+
158
+ public render(): plugins.deesElement.TemplateResult {
159
+ const status = this.status;
160
+ const summary = status ? summarizeDeployments(status) : undefined;
161
+ return html`
162
+ <div class="page">
163
+ <div class="head">
164
+ <div>
165
+ <h2>Deployments</h2>
166
+ <p class="subtitle">${status
167
+ ? `${status.targets.length} target${status.targets.length === 1 ? '' : 's'} · what runs comes from each target's probe, checked ${deployClock(status.checkedAt)}`
168
+ : this.loading ? 'Reading what each target runs…' : ''}</p>
169
+ </div>
170
+ <div class="actions">
171
+ <dees-button class="probeAllButton" type="outline" size="sm" .status=${this.probing ? 'pending' : 'normal'}
172
+ ?disabled=${!status || this.probing} @clicked=${() => void this.probeAll()}>
173
+ <dees-icon icon="lucide:RefreshCw" iconSize="14"></dees-icon> Probe all
174
+ </dees-button>
175
+ <dees-button class="planWindowButton" type="outline" size="sm" ?disabled=${!status} @clicked=${() => void this.planWindow()}>
176
+ <dees-icon icon="lucide:CalendarDays" iconSize="14"></dees-icon> Plan window
177
+ </dees-button>
178
+ <dees-button class="planHotfixButton" type="outline" size="sm" ?disabled=${!status} @clicked=${() => void this.planHotfix()}>
179
+ <dees-icon icon="lucide:Wrench" iconSize="14"></dees-icon> Plan hotfix
180
+ </dees-button>
181
+ <dees-button class="planReleaseButton" type="accent" size="sm" ?disabled=${!status} @clicked=${() => void this.planRelease()}>
182
+ <dees-icon icon="lucide:Plus" iconSize="14"></dees-icon> Plan release
183
+ </dees-button>
184
+ </div>
185
+ </div>
186
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
187
+ <dees-statsgrid density="compact" .minTileWidth=${220} .tiles=${summary ? this.tiles(summary) : []}></dees-statsgrid>
188
+ ${this.renderTargets(summary)}
189
+ <div class="lower">
190
+ ${this.renderPlans(summary)}
191
+ <dees-timeline class="changes" heading="What changed" headingSuffix="From probe observations"
192
+ emptyText="No target has been observed yet." .entries=${summary ? this.changes(summary) : []}></dees-timeline>
193
+ </div>
194
+ <p class="note">Running versions are what each target answers on its version endpoint, never the latest release. A release is the
195
+ repository's tag; what a release holds and where a fix runs are worked out from git. <code>agl deploy status</code> shows the same.</p>
196
+ </div>
197
+ `;
198
+ }
199
+
200
+ private tiles(summaryArg: IDeploymentsSummary): plugins.deesCatalog.IStatsTile[] {
201
+ const { targets, behind, down, releasedNotRunning, openBugs } = summaryArg;
202
+ const urgent = openBugs.filter((bugArg) => bugArg.priority === 'urgent').length;
203
+ const up = targets.filter((targetArg) => targetArg.probe.state === 'up').length;
204
+ const behindText = behind.map((targetArg) => targetArg.running?.rolledBack
205
+ ? `${deployTargetName(targetArg)} rolled back to ${targetArg.running.version}`
206
+ : `${deployTargetName(targetArg)} runs ${targetArg.running?.version ?? '?'} while ${targetArg.latest?.version ?? '?'} is out`).join('; ');
207
+ return [
208
+ { id: 'behind', title: 'Behind', type: 'number', value: behind.length, unit: `of ${targets.length} target${targets.length === 1 ? '' : 's'}`,
209
+ ...(behind.length ? { color: 'var(--dees-color-text-warning)' } : {}),
210
+ description: behind.length ? `${behindText}.` : 'Every target runs its repository\'s newest release.' },
211
+ { id: 'notRunning', title: 'Released, not running', type: 'number', value: releasedNotRunning.length, unit: 'tickets',
212
+ description: 'Shipped in a tag that some target of their repo does not run yet. On the board they carry "undeployed" until every target runs them.' },
213
+ { id: 'bugs', title: 'Open bugs on running versions', type: 'number', value: openBugs.length, unit: `${urgent} urgent`,
214
+ ...(urgent ? { color: 'var(--dees-color-text-error)' } : {}),
215
+ description: 'Tickets found in the version a target runs or an earlier one, whose fix does not run there.' },
216
+ { id: 'probes', title: 'Probes', type: 'number', value: up, unit: `up · ${down.length} down`,
217
+ ...(down.length ? { color: 'var(--dees-color-text-error)' } : {}),
218
+ description: down.length ? down.map((targetArg) => `${deployTargetName(targetArg)} hasn't answered since ${deployClock(targetArg.probe.downSince)}.`).join(' ')
219
+ : 'Every probe answers.' },
220
+ ];
221
+ }
222
+
223
+ private renderTargets(summaryArg: IDeploymentsSummary | undefined): plugins.deesElement.TemplateResult {
224
+ type TRow = interfaces.IFleetDeployTargetStatus & { key: string };
225
+ const rows: TRow[] = (summaryArg?.targets ?? []).map((targetArg) => ({ ...targetArg, key: targetArg.target.id }));
226
+ const now = this.now;
227
+ const columns: plugins.deesCatalog.Column<TRow>[] = [
228
+ { key: 'target', header: 'Target', value: (rowArg) => deployTargetName(rowArg), renderer: (_valueArg, rowArg) => html`<div style=${inline.cell}>
229
+ <span style=${inline.name}>${deployTargetName(rowArg)}</span>
230
+ <span style=${inline.muted}>${[rowArg.target.environment, rowArg.repository ?? rowArg.target.repo].filter(Boolean).join(' · ')}</span>
231
+ ${rowArg.deployWhen === 'window' ? html`<span style=${inline.muted}>deploys in a window</span>` : ''}</div>` },
232
+ { key: 'running', header: 'Running', value: (rowArg) => rowArg.running?.version ?? '', renderer: (_valueArg, rowArg) => html`<div style=${inline.cell}>
233
+ <span style=${inline.line}>${rowArg.running ? html`<span style=${inline.version}>${rowArg.running.version}</span><span style=${inline.sha}>${shortSha(rowArg.running.sha)}</span>
234
+ ${rowArg.running.untagged ? html`<dees-badge tone="warning" text="untagged" title="Its commit is not the one its version's tag names"></dees-badge>` : ''}`
235
+ : html`<span style=${inline.muted}>not observed yet</span>`}</span>
236
+ ${rowArg.probe.state === 'down'
237
+ ? html`<dees-badge inline dot tone="error" style=${inline.error} text=${`no answer since ${deployMoment(rowArg.probe.downSince, now)}`}></dees-badge>`
238
+ : rowArg.running ? html`<dees-badge inline dot tone=${rowArg.probe.state === 'up' ? 'success' : 'neutral'} style=${inline.muted}
239
+ title=${rowArg.probe.checkedAt ? `checked ${deployClock(rowArg.probe.checkedAt)}` : 'not probed yet'}
240
+ text=${`since ${deployMoment(rowArg.running.since, now)}`}></dees-badge>` : ''}
241
+ </div>` },
242
+ { key: 'latest', header: 'Latest release', value: (rowArg) => rowArg.latest?.version ?? '', renderer: (_valueArg, rowArg) => rowArg.latest
243
+ ? html`<div style=${inline.cell}><span style=${inline.version}>${rowArg.latest.version}</span><span style=${inline.muted}>${deployMoment(rowArg.latest.taggedAt, now)}</span></div>`
244
+ : html`<span style=${inline.muted}>${rowArg.repository ? 'no release tag' : 'no checkout'}</span>` },
245
+ { key: 'notRunning', header: 'Not running yet', sortable: false, renderer: (_valueArg, rowArg) => {
246
+ const { releases, tickets } = rowArg.notRunning;
247
+ if (!rowArg.running) return html`<span style=${inline.muted}>—</span>`;
248
+ if (rowArg.running.rolledBack) return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="warning" text="rolled back"></dees-badge></span>
249
+ <span style=${inline.muted}>${rowArg.running.previousVersion} → ${rowArg.running.version} ${deployMoment(rowArg.running.since, now)}</span></div>`;
250
+ if (releases.length) return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="warning"
251
+ text=${`${releases.length} release${releases.length === 1 ? '' : 's'} · ${tickets.length} ticket${tickets.length === 1 ? '' : 's'}`}></dees-badge></span>
252
+ <span style=${inline.muted}>released ${deployAge(releases.at(-1)!.taggedAt, now)}</span></div>`;
253
+ return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="success" icon="lucide:Check" text="Current"></dees-badge></span>
254
+ ${rowArg.landedAfterLatest.length ? html`<span style=${inline.muted}>${rowArg.landedAfterLatest.length} landed after ${rowArg.latest?.version ?? 'the last tag'}</span>` : ''}</div>`;
255
+ } },
256
+ { key: 'bugs', header: 'Open bugs', value: (rowArg) => rowArg.openBugs.length, renderer: (_valueArg, rowArg) => {
257
+ const first = rowArg.openBugs[0];
258
+ if (!first) return html`<span style=${inline.muted}>None</span>`;
259
+ const urgent = rowArg.openBugs.filter((bugArg) => bugArg.priority === 'urgent').length;
260
+ const count = urgent === rowArg.openBugs.length ? `${urgent} urgent` : `${rowArg.openBugs.length}${urgent ? ` · ${urgent} urgent` : ''}`;
261
+ return html`<div style=${inline.cell}><span style="${inline.line} ${urgent ? inline.error : ''}">${count} ${ticketChip(first.key)}</span>
262
+ <span style=${inline.muted}>found in ${first.foundIn}${first.fixLandedSha ? ', fix landed' : ''}</span></div>`;
263
+ } },
264
+ { key: 'next', header: 'Next', sortable: false, renderer: (_valueArg, rowArg) => {
265
+ const next = deployNextStep(rowArg);
266
+ if (next.kind === 'hotfix') return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="error" text="Hotfix proposed"></dees-badge></span>
267
+ <span style="${inline.line} ${inline.muted}">next release ${ticketChip(next.bug.key)}</span></div>`;
268
+ if (next.kind === 'deployPlan') {
269
+ const go = deployGoView(next.plan, rowArg.deployWhen);
270
+ return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone=${go.tone} text=${go.text}></dees-badge></span>
271
+ <span style="${inline.line} ${inline.muted}">${go.detail} ${ticketChip(next.plan.key)}</span></div>`;
272
+ }
273
+ if (next.kind === 'plan') return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="info" text="planned"></dees-badge></span>
274
+ <span style="${inline.line} ${inline.muted}">${next.plan.priority === 'urgent' ? 'Hotfix' : 'Release'} ${next.plan.plannedVersion ?? 'next'} ${ticketChip(next.plan.key)}</span></div>`;
275
+ if (next.kind === 'deploy') return html`<div style=${inline.cell}><span style=${inline.line}><dees-badge tone="warning" text="Not deployed"></dees-badge></span>
276
+ <span style=${inline.muted}>Deploy ${next.version}</span></div>`;
277
+ return html`<span style=${inline.muted}>—</span>`;
278
+ } },
279
+ ];
280
+ return html`<dees-table class="targetsTable" heading1="Targets" heading2="Set in Configuration › fleet.deployTargets"
281
+ .dataName=${{ one: 'target', other: 'targets' }} .data=${rows} .rowKey=${'key'} .columns=${columns}
282
+ .dataActions=${[{ name: 'Open', iconName: 'lucide:PanelRightOpen', type: ['rowClick', 'contextmenu'],
283
+ actionFunc: async ({ item }: plugins.deesCatalog.ITableActionDataArg<TRow>) => { this.openTarget(item.target.id); } }] satisfies plugins.deesCatalog.ITableAction<TRow>[]}
284
+ .loading=${this.loading && !summaryArg} .skeletonRows=${3} .error=${summaryArg ? '' : this.error} .onRetry=${() => this.refresh()}
285
+ ></dees-table>`;
286
+ }
287
+
288
+ /** Every release plan: those of the targets' repositories, and those of repositories no target runs. */
289
+ private plans(summaryArg: IDeploymentsSummary): (interfaces.IFleetReleasePlanTicket & { repo: string })[] {
290
+ const plans = new Map(summaryArg.plans.map((planArg) => [planArg.key, planArg]));
291
+ for (const repo of this.release?.repositories ?? []) for (const plan of repo.plans) if (!plans.has(plan.key)) plans.set(plan.key, { ...plan, repo: repo.repo });
292
+ return [...plans.values()].sort((leftArg, rightArg) => Number(rightArg.priority === 'urgent') - Number(leftArg.priority === 'urgent'));
293
+ }
294
+
295
+ /** A target's name by its id, for the windows that list them. */
296
+ private targetName(idArg: string): string {
297
+ const target = this.status?.targets.find((targetArg) => targetArg.target.id === idArg);
298
+ return target ? deployTargetName(target) : idArg;
299
+ }
300
+
301
+ private renderPlans(summaryArg: IDeploymentsSummary | undefined): plugins.deesElement.TemplateResult {
302
+ const deploys: plugins.deesCatalog.IGroupedListRow[] = (summaryArg?.deployPlans ?? []).map((planArg) => {
303
+ const go = deployGoView(planArg, planArg.targetStatus.deployWhen);
304
+ return {
305
+ key: `deploy:${planArg.key}`,
306
+ label: `${deployTargetName(planArg.targetStatus)} ${planArg.version}`,
307
+ description: `${planArg.key} · ${deployPlanLine(planArg)}`,
308
+ icon: 'lucide:Rocket',
309
+ iconColor: planArg.go === 'waiting' ? 'var(--dees-color-text-warning)' : 'var(--dees-color-accent-primary)',
310
+ accessory: html`<dees-badge tone=${go.tone} text=${go.text}></dees-badge>`,
311
+ action: () => planArg.go === 'waiting' ? this.answerGo(planArg.key) : this.openTicket(planArg.key),
312
+ };
313
+ });
314
+ const windows: plugins.deesCatalog.IGroupedListRow[] = (summaryArg?.windows ?? []).map((windowArg) => {
315
+ const state = deployWindowStateView(windowArg);
316
+ return {
317
+ key: `window:${windowArg.key}`,
318
+ label: deployWindowRange(windowArg),
319
+ description: `${windowArg.key} · ${windowArg.targets.map((idArg) => this.targetName(idArg)).join(', ')}`,
320
+ icon: 'lucide:CalendarDays',
321
+ iconColor: windowArg.go === 'waiting' ? 'var(--dees-color-text-warning)'
322
+ : windowArg.go === 'given' && windowArg.state === 'active' ? 'var(--dees-color-text-success)' : 'var(--dees-color-accent-primary)',
323
+ accessory: html`<dees-badge tone=${state.tone} text=${state.text}></dees-badge>`,
324
+ action: () => windowArg.go === 'waiting' ? this.answerGo(windowArg.key) : this.planWindow({ windowKey: windowArg.key }),
325
+ };
326
+ });
327
+ const releases: plugins.deesCatalog.IGroupedListRow[] = (summaryArg ? this.plans(summaryArg) : []).map((planArg) => {
328
+ const hotfix = planArg.priority === 'urgent';
329
+ return {
330
+ key: planArg.key,
331
+ label: `${hotfix ? 'Hotfix' : 'Release'} ${planArg.repo} ${planArg.plannedVersion ?? '(next)'}`,
332
+ description: `${planArg.key} · ${planArg.title}`,
333
+ icon: hotfix ? 'lucide:Wrench' : 'lucide:Tag',
334
+ iconColor: hotfix ? 'var(--dees-color-text-error)' : 'var(--dees-color-accent-primary)',
335
+ accessory: html`<dees-badge tone="info" text="planned"></dees-badge>`,
336
+ action: () => this.openTicket(planArg.key),
337
+ };
338
+ });
339
+ const sections: plugins.deesCatalog.IGroupedListSection[] = [
340
+ ...(deploys.length ? [{ header: 'Deploys', headerSuffix: html`<span class="muted">Each waits for your go</span>`, rows: deploys }] : []),
341
+ ...(windows.length ? [{ header: 'Maintenance windows', headerSuffix: html`<span class="muted">Window-bound targets deploy only inside one</span>`,
342
+ rows: windows }] : []),
343
+ ...(releases.length ? [{ header: 'Releases', headerSuffix: html`<span class="muted">Tickets with a release plan · on the board as "planned"</span>`,
344
+ rows: releases }] : []),
345
+ ];
346
+ return html`<dees-grouped-list class="plans" .inset=${false} .sections=${sections.length ? sections : [{ header: 'Plans', rows: [{ key: 'none',
347
+ label: this.loading ? 'Reading the plans…' : 'Nothing planned', icon: 'lucide:CalendarClock',
348
+ description: 'Plan a release, a hotfix or a maintenance window. A target that falls behind gets a deploy plan that waits for your go.' }] }]}
349
+ ></dees-grouped-list>`;
350
+ }
351
+
352
+ /** What changed, newest first: every observed version and the probes that stopped answering. */
353
+ private changes(summaryArg: IDeploymentsSummary): plugins.deesCatalog.ITimelineEntry[] {
354
+ const entries: plugins.deesCatalog.ITimelineEntry[] = [];
355
+ for (const target of summaryArg.targets) {
356
+ const name = deployTargetName(target);
357
+ if (target.probe.state === 'down' && target.probe.downSince) {
358
+ entries.push({ id: `${target.target.id}:down`, at: target.probe.downSince, tone: 'error',
359
+ content: html`<strong>${name}</strong> stopped answering. <span class="error">Probe down.</span>` });
360
+ }
361
+ for (const observation of this.histories[target.target.id] ?? []) {
362
+ const rollback = observation.previousVersion !== undefined && observation.previousVersion.localeCompare(observation.version, 'en', { numeric: true }) > 0;
363
+ entries.push({ id: observation.id, at: observation.observedAt, tone: rollback ? 'warning' : 'info',
364
+ content: html`<strong>${name}</strong> ${observation.previousVersion ? html`${observation.previousVersion} → ` : ''}<code>${observation.version}</code>
365
+ ${rollback ? html`<dees-badge tone="warning" text="rollback"></dees-badge>` : ''}${observation.previousVersion ? '' : html` <small>first observation</small>`}` });
366
+ }
367
+ }
368
+ return entries.sort((leftArg, rightArg) => rightArg.at.localeCompare(leftArg.at)).slice(0, 12);
369
+ }
370
+
371
+ private openTicket(keyArg: string): void {
372
+ this.dispatchEvent(new CustomEvent('deploy-open-ticket', { detail: { key: keyArg }, bubbles: true, composed: true }));
373
+ }
374
+
375
+ private async probeAll(): Promise<void> {
376
+ const sender = this.sender;
377
+ if (!sender || !this.status) return;
378
+ this.probing = true;
379
+ try {
380
+ for (const target of this.status.targets) await deploy(sender, 'probe', { targetId: target.target.id });
381
+ } catch (errorArg) {
382
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
383
+ } finally {
384
+ this.probing = false;
385
+ await this.refresh();
386
+ }
387
+ }
388
+
389
+ /** The target sheet: what it runs, what does not run there yet, its open bugs, its history and how it deploys. */
390
+ public openTarget(targetIdArg: string): void {
391
+ const target = this.status?.targets.find((targetArg) => targetArg.target.id === targetIdArg);
392
+ if (!target || !this.sender) return;
393
+ void this.sheet?.modal.destroy();
394
+ const sheet = document.createElement('agl-deploy-target') as AglDeployTarget;
395
+ sheet.sender = this.sender;
396
+ sheet.status = target;
397
+ sheet.observations = this.histories[targetIdArg] ?? [];
398
+ sheet.addEventListener('deploy-probed', () => void this.refresh());
399
+ sheet.addEventListener('deploy-plan-release', () => { void this.sheet?.modal.destroy(); void this.planRelease(target.repository ?? target.target.repo); });
400
+ sheet.addEventListener('deploy-plan-window', (eventArg) => {
401
+ const key = (eventArg as CustomEvent<{ key?: string }>).detail?.key;
402
+ void this.sheet?.modal.destroy();
403
+ void this.planWindow(key ? { windowKey: key } : { targetId: target.target.id });
404
+ });
405
+ sheet.addEventListener('deploy-go', (eventArg) => {
406
+ void this.sheet?.modal.destroy();
407
+ void this.answerGo((eventArg as CustomEvent<{ key: string }>).detail.key);
408
+ });
409
+ sheet.addEventListener('deploy-open-ticket', () => void this.sheet?.modal.destroy());
410
+ void plugins.deesCatalog.DeesModal.createAndShow({
411
+ heading: deployTargetName(target),
412
+ subheading: [target.target.environment, target.repository ?? target.target.repo,
413
+ target.target.probe.kind === 'controller' ? 'probe: the controller itself' : 'probe: HTTP'].filter(Boolean).join(' · '),
414
+ width: 640, mobileFullscreen: true,
415
+ content: html`${sheet}`,
416
+ menuOptions: [{ name: 'Close', action: async (modalArg) => { await modalArg?.destroy(); } }],
417
+ }).then((modalArg) => {
418
+ this.sheet = { targetId: targetIdArg, modal: modalArg };
419
+ // A sheet re-dispatches its ticket chips' events from inside the modal, which sits outside this view.
420
+ sheet.addEventListener('deploy-open-ticket', (eventArg) => this.openTicket((eventArg as CustomEvent<{ key: string }>).detail.key));
421
+ });
422
+ }
423
+
424
+ private updateSheet(): void {
425
+ if (!this.sheet) return;
426
+ const sheet = this.sheet.modal.querySelector?.('agl-deploy-target') as AglDeployTarget | null
427
+ ?? (this.sheet.modal.shadowRoot?.querySelector('agl-deploy-target') as AglDeployTarget | null);
428
+ const target = this.status?.targets.find((targetArg) => targetArg.target.id === this.sheet!.targetId);
429
+ if (!sheet || !target) return;
430
+ sheet.status = target;
431
+ sheet.observations = this.histories[target.target.id] ?? [];
432
+ }
433
+
434
+ /** The plan-release dialog: a ticket gets a release plan for a repository, optionally with a version. */
435
+ public async planRelease(repoArg?: string): Promise<void> {
436
+ await this.openPlanDialog('release', repoArg);
437
+ }
438
+
439
+ /** The plan-hotfix dialog: an urgent bug found in a running version gets an urgent release plan off main. */
440
+ public async planHotfix(bugKeyArg?: string): Promise<void> {
441
+ await this.openPlanDialog('hotfix', bugKeyArg);
442
+ }
443
+
444
+ /**
445
+ * The plan-window dialog: a new maintenance window for chosen targets, or a planned one to move or cancel. Window-bound
446
+ * targets deploy only inside one; the deploys the owner queued run in the next.
447
+ */
448
+ public async planWindow(optionsArg: { targetId?: string; windowKey?: string } = {}): Promise<void> {
449
+ const window = optionsArg.windowKey ? this.status?.windows.find((windowArg) => windowArg.key === optionsArg.windowKey) : undefined;
450
+ const dialog = this.planDialog('window');
451
+ if (!dialog) return;
452
+ if (window) dialog.windowKey = window.key;
453
+ else if (optionsArg.targetId) dialog.windowTargets = [optionsArg.targetId];
454
+ const done = async (modalArg?: plugins.deesCatalog.DeesModal) => { await modalArg?.destroy(); await this.refresh(); };
455
+ await plugins.deesCatalog.DeesModal.createAndShow({
456
+ heading: window ? `Maintenance window ${window.key}` : 'Plan a maintenance window',
457
+ subheading: window ? `${window.title} · ${deployWindowStateView(window).text}`
458
+ : 'A ticket with a time span and its targets. A target that deploys in windows deploys only inside one.',
459
+ width: 520, mobileFullscreen: true,
460
+ content: html`${dialog}`,
461
+ menuOptions: [
462
+ { name: window ? 'Close' : 'Cancel', action: async (modalArg) => { await modalArg?.destroy(); } },
463
+ ...(window ? [{ name: 'Cancel window', action: async (modalArg?: plugins.deesCatalog.DeesModal) => { if (await dialog.cancelWindow()) await done(modalArg); } }] : []),
464
+ { name: window ? 'Save window' : 'Plan window', action: async (modalArg) => { if (await dialog.submit()) await done(modalArg); } },
465
+ ],
466
+ });
467
+ }
468
+
469
+ /**
470
+ * The go dialog: the owner answers, as on its ticket, the question of a deploy plan (from the plan's options) or of a
471
+ * maintenance window the driver proposed (approve or decline).
472
+ */
473
+ public async answerGo(ticketKeyArg: string): Promise<void> {
474
+ const sender = this.sender;
475
+ const target = this.status?.targets.find((targetArg) => targetArg.deployPlans.some((planArg) => planArg.key === ticketKeyArg));
476
+ const plan = target?.deployPlans.find((planArg) => planArg.key === ticketKeyArg);
477
+ const window = plan ? undefined : this.status?.windows.find((windowArg) => windowArg.key === ticketKeyArg && windowArg.questionId);
478
+ const questionId = plan?.questionId ?? window?.questionId;
479
+ const subject = plan ?? window;
480
+ if (!sender || !subject || !questionId) return;
481
+ let question: interfaces.ITicketQuestion | undefined;
482
+ try {
483
+ question = (await ticket(sender, 'get', { ticketId: subject.key })).questions.find((questionArg) => questionArg.id === questionId);
484
+ } catch (errorArg) {
485
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
486
+ return;
487
+ }
488
+ if (!question) return;
489
+ const dialog = document.createElement('agl-deploy-go') as AglDeployGo;
490
+ dialog.sender = sender;
491
+ dialog.subjectKey = subject.key;
492
+ if (plan && target) { dialog.target = target; dialog.plan = plan; }
493
+ if (window) { dialog.window = window; dialog.targetNames = window.targets.map((idArg) => this.targetName(idArg)); }
494
+ dialog.question = question;
495
+ // A target that deploys at any time is deployed now; one that waits for a window or idle sessions, then. A window is approved.
496
+ const recommended = window ? interfaces.ticketWindowOptions.approve
497
+ : target?.deployWhen === 'anytime' ? interfaces.ticketDeployPlanOptions.now : interfaces.ticketDeployPlanOptions.later;
498
+ const answers = question.status === 'open' ? [...question.options].reverse().map((optionArg) => ({ name: optionArg.label,
499
+ ...(optionArg.id === recommended ? { primary: true } : {}),
500
+ action: async (modalArg?: plugins.deesCatalog.DeesModal) => {
501
+ if (await dialog.answer(optionArg.id)) { await modalArg?.destroy(); await this.refresh(); }
502
+ } })) : [];
503
+ await plugins.deesCatalog.DeesModal.createAndShow({
504
+ heading: question.question,
505
+ subheading: `${subject.key} · ${subject.title}`,
506
+ width: 520, mobileFullscreen: true,
507
+ content: html`${dialog}`,
508
+ menuOptions: answers.length ? answers : [{ name: 'Close', action: async (modalArg) => { await modalArg?.destroy(); } }],
509
+ });
510
+ }
511
+
512
+ private planDialog(modeArg: AglDeployPlan['mode']): AglDeployPlan | undefined {
513
+ const sender = this.sender;
514
+ if (!sender || !this.status) return undefined;
515
+ const dialog = document.createElement('agl-deploy-plan') as AglDeployPlan;
516
+ dialog.sender = sender;
517
+ dialog.mode = modeArg;
518
+ dialog.status = this.status;
519
+ dialog.release = this.release;
520
+ dialog.projects = this.projects;
521
+ return dialog;
522
+ }
523
+
524
+ private async openPlanDialog(modeArg: 'release' | 'hotfix', subjectArg?: string): Promise<void> {
525
+ const dialog = this.planDialog(modeArg);
526
+ if (!dialog) return;
527
+ if (modeArg === 'release' && subjectArg) dialog.repo = subjectArg;
528
+ if (modeArg === 'hotfix' && subjectArg) dialog.bugKey = subjectArg;
529
+ await plugins.deesCatalog.DeesModal.createAndShow({
530
+ heading: modeArg === 'release' ? 'Plan a release' : 'Plan a hotfix',
531
+ subheading: modeArg === 'release' ? 'A ticket on the board with a release plan. It shows as "planned" until fleet releases it.'
532
+ : 'From an urgent bug that a running version has. An urgent release plan off main; the driver puts it first.',
533
+ width: 480, mobileFullscreen: true,
534
+ content: html`${dialog}`,
535
+ menuOptions: [
536
+ { name: 'Cancel', action: async (modalArg) => { await modalArg?.destroy(); } },
537
+ { name: modeArg === 'release' ? 'Plan release' : 'Plan hotfix', action: async (modalArg) => {
538
+ if (await dialog.submit()) { await modalArg?.destroy(); await this.refresh(); }
539
+ } },
540
+ ],
541
+ });
542
+ }
543
+ }
544
+
545
+ /** The body of a target's sheet. */
546
+ @plugins.deesElement.customElement('agl-deploy-target')
547
+ export class AglDeployTarget extends plugins.deesElement.DeesElement {
548
+ @plugins.deesElement.property({ attribute: false })
549
+ accessor sender: IDeploymentsSender | undefined;
550
+
551
+ @plugins.deesElement.property({ attribute: false })
552
+ accessor status: interfaces.IFleetDeployTargetStatus | undefined;
553
+
554
+ @plugins.deesElement.property({ attribute: false })
555
+ accessor observations: interfaces.IFleetDeployObservation[] = [];
556
+
557
+ @plugins.deesElement.state()
558
+ accessor probing = false;
559
+
560
+ @plugins.deesElement.state()
561
+ accessor error = '';
562
+
563
+ public static styles = [
564
+ plugins.deesElement.cssManager.defaultStyles,
565
+ plugins.deesCatalog.themeDefaultStyles,
566
+ sharedStyles,
567
+ css`
568
+ :host { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; min-width: 0; }
569
+ .running { display: grid; gap: 6px; padding: 16px; border: 1px solid var(--dees-color-border-subtle); border-radius: 12px; }
570
+ .version { margin: 0; font: 600 26px/1.2 var(--dees-font-family-mono); color: var(--dees-color-text-primary); }
571
+ .actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
572
+ .command { margin: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--dees-color-border-subtle);
573
+ font: 12px/1.4 var(--dees-font-family-mono); color: var(--dees-color-text-primary); overflow-x: auto; white-space: nowrap; }
574
+ .command .prompt { color: var(--dees-color-text-success, var(--dees-color-accent-primary)); }
575
+ .error { color: var(--dees-color-text-error); margin: 0; }
576
+ `,
577
+ ];
578
+
579
+ public render(): plugins.deesElement.TemplateResult {
580
+ const target = this.status;
581
+ if (!target) return html``;
582
+ const now = Date.now();
583
+ const notRunning: plugins.deesCatalog.IGroupedListRow[] = [
584
+ ...target.notRunning.tickets.map((ticketArg) => ({ key: `released:${ticketArg.key}`, label: ticketArg.title, icon: 'lucide:PackageCheck',
585
+ action: () => this.openTicket(ticketArg.key), description: ticketArg.key,
586
+ accessory: html`<dees-badge tone="warning" text=${`in ${ticketArg.version}`}></dees-badge>` })),
587
+ ...target.landedAfterLatest.map((ticketArg) => ({ key: `landed:${ticketArg.key}`, label: ticketArg.title, icon: 'lucide:GitMerge',
588
+ action: () => this.openTicket(ticketArg.key), description: ticketArg.key,
589
+ accessory: html`<dees-badge tone="neutral" text="landed"></dees-badge>` })),
590
+ ];
591
+ // A row's label keeps one line, so the ticket key and the facts wrap in its description and the accessory is the state alone.
592
+ const bugs: plugins.deesCatalog.IGroupedListRow[] = target.openBugs.map((bugArg) => ({ key: bugArg.key, label: bugArg.title, icon: 'lucide:Bug',
593
+ action: () => this.openTicket(bugArg.key),
594
+ description: [bugArg.key, `found in ${bugArg.foundIn}`, bugArg.fixLandedSha ? `fix landed at ${shortSha(bugArg.fixLandedSha)}${bugArg.fixedIn ? `, released in ${bugArg.fixedIn}` : ''}` : '']
595
+ .filter(Boolean).join(' · '),
596
+ accessory: html`<dees-badge tone=${bugArg.priority === 'urgent' ? 'error' : bugArg.priority === 'high' ? 'warning' : 'neutral'} text=${bugArg.priority}></dees-badge>` }));
597
+ // Long values wrap as a row's description; a trailing value is one short line.
598
+ const facts: plugins.deesCatalog.IGroupedListRow[] = [
599
+ { key: 'repo', label: 'Repository', icon: 'lucide:GitBranch', description: `${target.repository ?? target.target.repo} · tags v<version>` },
600
+ { key: 'probe', label: 'Probe', icon: 'lucide:Radar', description: deployProbeText(target.target) },
601
+ ...(target.target.deploys ? [{ key: 'deploys', label: 'Deploys', icon: 'lucide:Rocket', description: target.target.deploys }] : []),
602
+ ...(target.target.downtime ? [{ key: 'downtime', label: 'Downtime', icon: 'lucide:Clock', description: target.target.downtime }] : []),
603
+ ];
604
+ const go = (planArg: interfaces.IFleetDeployPlan) => deployGoView(planArg, target.deployWhen);
605
+ const deploys: plugins.deesCatalog.IGroupedListRow[] = [
606
+ { key: 'when', label: 'When it deploys', icon: 'lucide:Clock', description: deployWhenText(target) },
607
+ ...target.deployPlans.map((planArg) => ({ key: `plan:${planArg.key}`, label: `Deploy ${planArg.version}`, icon: 'lucide:Rocket',
608
+ description: `${planArg.key} · ${deployPlanLine(planArg)}`,
609
+ accessory: html`<dees-badge tone=${go(planArg).tone} text=${go(planArg).text}></dees-badge>`,
610
+ action: () => planArg.go === 'waiting' ? this.emit('deploy-go', { key: planArg.key }) : this.openTicket(planArg.key) })),
611
+ ...target.windows.map((windowArg) => {
612
+ const state = deployWindowStateView(windowArg);
613
+ return { key: `window:${windowArg.key}`, label: deployWindowRange(windowArg), icon: 'lucide:CalendarDays', description: `${windowArg.key} · maintenance window`,
614
+ accessory: html`<dees-badge tone=${state.tone} text=${state.text}></dees-badge>`,
615
+ action: () => windowArg.go === 'waiting' ? this.emit('deploy-go', { key: windowArg.key }) : this.emit('deploy-plan-window', { key: windowArg.key }) };
616
+ }),
617
+ ];
618
+ const sections: plugins.deesCatalog.IGroupedListSection[] = [
619
+ { header: 'Deploys', headerSuffix: html`<span class="muted">${target.deployOpen ? 'a deploy may run now' : 'no deploy may run now'}</span>`, rows: deploys },
620
+ { header: 'Not running yet', headerSuffix: html`<span class="muted">${target.latest ? `released or landed after ${target.running?.version ?? '—'}` : ''}</span>`,
621
+ rows: notRunning.length ? notRunning : [{ key: 'none', label: 'Everything released runs here.' }] },
622
+ { header: `Open bugs on ${target.running?.version ?? 'the running version'}`, headerSuffix: html`<span class="muted">found in it or before, fix not running</span>`,
623
+ rows: bugs.length ? bugs : [{ key: 'none', label: 'No open bug was found in this version.' }] },
624
+ ];
625
+ return html`
626
+ <div class="running">
627
+ <p class="version">${target.running?.version ?? '—'}</p>
628
+ <span class="muted">${target.running ? [shortSha(target.running.sha), `running since ${deployMoment(target.running.since, now)}`,
629
+ target.probe.state === 'down' ? `no answer since ${deployMoment(target.probe.downSince, now)}` : target.probe.checkedAt ? `probe answered ${deployClock(target.probe.checkedAt)}` : '']
630
+ .filter(Boolean).join(' · ') : 'Not observed yet.'}</span>
631
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
632
+ <div class="actions">
633
+ <dees-button class="probeButton" type="outline" size="sm" .status=${this.probing ? 'pending' : 'normal'} ?disabled=${this.probing}
634
+ @clicked=${() => void this.probe()}><dees-icon icon="lucide:RefreshCw" iconSize="14"></dees-icon> Probe now</dees-button>
635
+ ${target.deployWhen === 'idle' ? '' : html`<dees-button class="planWindowButton" type="outline" size="sm"
636
+ @clicked=${() => this.emit('deploy-plan-window', {})}><dees-icon icon="lucide:CalendarDays" iconSize="14"></dees-icon> Plan window</dees-button>`}
637
+ <dees-button class="planButton" type="accent" size="sm" @clicked=${() => this.emit('deploy-plan-release', {})}>Plan release</dees-button>
638
+ </div>
639
+ </div>
640
+ <dees-grouped-list .inset=${false} .sections=${sections}></dees-grouped-list>
641
+ <dees-timeline heading="History" headingSuffix="observed versions" emptyText="No version observed yet."
642
+ .entries=${this.observations.map((observationArg, indexArg) => ({ id: observationArg.id, at: observationArg.observedAt,
643
+ tone: indexArg === 0 ? 'success' : 'neutral',
644
+ content: html`<strong>${observationArg.version}</strong>${observationArg.sha ? html` · <code>${shortSha(observationArg.sha)}</code>` : ''}${
645
+ observationArg.previousVersion ? html` <small>was ${observationArg.previousVersion}</small>` : ''}` }) satisfies plugins.deesCatalog.ITimelineEntry)}
646
+ ></dees-timeline>
647
+ <dees-grouped-list .inset=${false} .sections=${[{ header: 'Target', rows: facts }]}></dees-grouped-list>
648
+ <p class="command"><span class="prompt">$</span> agl deploy status ${target.target.id}</p>
649
+ `;
650
+ }
651
+
652
+ private openTicket(keyArg: string): void {
653
+ this.emit('deploy-open-ticket', { key: keyArg });
654
+ }
655
+
656
+ /** Asks the view for a dialog or a ticket; the sheet sits in a modal outside the view. */
657
+ private emit(nameArg: string, detailArg: Record<string, string>): void {
658
+ this.dispatchEvent(new CustomEvent(nameArg, { detail: detailArg, bubbles: true, composed: true }));
659
+ }
660
+
661
+ /** Probes the target now; the view reads again and hands the sheet its new status. */
662
+ private async probe(): Promise<void> {
663
+ if (!this.sender || !this.status) return;
664
+ this.probing = true;
665
+ try {
666
+ this.status = await deploy(this.sender, 'probe', { targetId: this.status.target.id });
667
+ this.error = '';
668
+ this.dispatchEvent(new CustomEvent('deploy-probed', { bubbles: true, composed: true }));
669
+ } catch (errorArg) {
670
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
671
+ } finally {
672
+ this.probing = false;
673
+ }
674
+ }
675
+ }
676
+
677
+ /** A ticket the plan dialogs offer. */
678
+ interface IPlanTicketChoice { key: string; label: string }
679
+
680
+ /**
681
+ * The plan dialogs' body. A release plan goes on a chosen ticket or a new one; a hotfix plan goes on the urgent bug
682
+ * itself (Q2: an urgent release off main, no branch). A maintenance window is a ticket of its own, for its targets.
683
+ */
684
+ @plugins.deesElement.customElement('agl-deploy-plan')
685
+ export class AglDeployPlan extends plugins.deesElement.DeesElement {
686
+ @plugins.deesElement.property({ attribute: false })
687
+ accessor sender: IDeploymentsSender | undefined;
688
+
689
+ @plugins.deesElement.property({ attribute: false })
690
+ accessor mode: 'release' | 'hotfix' | 'window' = 'release';
691
+
692
+ @plugins.deesElement.property({ attribute: false })
693
+ accessor status: interfaces.IFleetDeployStatus | undefined;
694
+
695
+ @plugins.deesElement.property({ attribute: false })
696
+ accessor release: interfaces.IFleetReleaseStatus | undefined;
697
+
698
+ @plugins.deesElement.property({ attribute: false })
699
+ accessor projects: interfaces.IControllerProject[] = [];
700
+
701
+ @plugins.deesElement.state()
702
+ accessor repo = '';
703
+
704
+ @plugins.deesElement.state()
705
+ accessor version = '';
706
+
707
+ /** The ticket a release plan goes on; `new` for a new ticket. */
708
+ @plugins.deesElement.state()
709
+ accessor ticketKey = '';
710
+
711
+ @plugins.deesElement.state()
712
+ accessor bugKey = '';
713
+
714
+ @plugins.deesElement.state()
715
+ accessor project = '';
716
+
717
+ @plugins.deesElement.state()
718
+ accessor tickets: IPlanTicketChoice[] = [];
719
+
720
+ /** The window's ticket when a planned window is moved or cancelled; empty for a new one. */
721
+ @plugins.deesElement.property({ attribute: false })
722
+ accessor windowKey = '';
723
+
724
+ /** The targets the window is for, by id. */
725
+ @plugins.deesElement.property({ attribute: false })
726
+ accessor windowTargets: string[] = [];
727
+
728
+ /** The window's start and end, as the date pickers hold them (ISO). */
729
+ @plugins.deesElement.state()
730
+ accessor from = '';
731
+
732
+ @plugins.deesElement.state()
733
+ accessor to = '';
734
+
735
+ @plugins.deesElement.state()
736
+ accessor error = '';
737
+
738
+ public static styles = [
739
+ plugins.deesElement.cssManager.defaultStyles,
740
+ plugins.deesCatalog.themeDefaultStyles,
741
+ sharedStyles,
742
+ css`
743
+ :host { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
744
+ .pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
745
+ .hint { margin: 0; font-size: 12px; color: var(--dees-color-text-secondary); }
746
+ .warning { margin: 0; padding: 10px 12px; border-radius: 8px; font-size: 13px; color: var(--dees-color-text-warning);
747
+ background: color-mix(in srgb, var(--dees-color-text-warning) 10%, transparent); }
748
+ .error { margin: 0; color: var(--dees-color-text-error); }
749
+ .targets { display: grid; gap: 4px; }
750
+ .fieldLabel { font-size: 13px; font-weight: 500; color: var(--dees-color-text-primary); }
751
+ @media (max-width: 480px) { .pair { grid-template-columns: minmax(0, 1fr); } }
752
+ `,
753
+ ];
754
+
755
+ public async connectedCallback(): Promise<void> {
756
+ await super.connectedCallback();
757
+ const repositories = this.repositories();
758
+ if (this.mode === 'release') {
759
+ this.repo ||= repositories[0] ?? '';
760
+ if (this.sender) {
761
+ const { tickets } = await ticket(this.sender, 'list', {});
762
+ this.tickets = tickets.filter((ticketArg) => ticketArg.columnId !== 'released' && ticketArg.columnId !== 'closed')
763
+ .sort((leftArg, rightArg) => Number(Boolean(rightArg.releasePlan)) - Number(Boolean(leftArg.releasePlan))
764
+ || rightArg.key.localeCompare(leftArg.key, 'en', { numeric: true }))
765
+ .map((ticketArg) => ({ key: ticketArg.key, label: `${ticketArg.key} · ${ticketArg.title}` }));
766
+ const plan = this.repoPlans()[0];
767
+ this.ticketKey ||= plan?.key ?? 'new';
768
+ if (plan && this.ticketKey === plan.key) this.version ||= plan.plannedVersion ?? '';
769
+ }
770
+ } else if (this.mode === 'hotfix') {
771
+ this.bugKey ||= this.bugs()[0]?.key ?? '';
772
+ } else {
773
+ const window = this.status?.windows.find((windowArg) => windowArg.key === this.windowKey);
774
+ if (window) {
775
+ this.from = window.from; this.to = window.to; this.windowTargets = [...window.targets];
776
+ } else {
777
+ if (!this.windowTargets.length) this.windowTargets = this.windowChoices().filter((targetArg) => targetArg.deployWhen === 'window').map((targetArg) => targetArg.target.id);
778
+ // The next full hour, for an hour: the owner moves it.
779
+ const start = new Date(this.now());
780
+ start.setMinutes(0, 0, 0);
781
+ start.setHours(start.getHours() + 1);
782
+ this.from = start.toISOString();
783
+ this.to = new Date(start.getTime() + 3_600_000).toISOString();
784
+ }
785
+ }
786
+ this.project ||= this.projects[0]?.name ?? '';
787
+ }
788
+
789
+ /** The current time; a test sets it. */
790
+ public now = (): number => Date.now();
791
+
792
+ /** The targets a window may name: every target but the AGL controller, which waits for idle sessions instead. */
793
+ private windowChoices(): interfaces.IFleetDeployTargetStatus[] {
794
+ return (this.status?.targets ?? []).filter((targetArg) => targetArg.deployWhen !== 'idle');
795
+ }
796
+
797
+ /** The repositories a plan may name: those of the targets and of the release state. */
798
+ private repositories(): string[] {
799
+ return [...new Set([...(this.status?.targets ?? []).map((targetArg) => targetArg.repository ?? targetArg.target.repo),
800
+ ...(this.release?.repositories ?? []).map((repoArg) => repoArg.repo)])];
801
+ }
802
+
803
+ private repoPlans(): interfaces.IFleetReleasePlanTicket[] {
804
+ return this.release?.repositories.find((repoArg) => repoArg.repo === this.repo)?.plans ?? [];
805
+ }
806
+
807
+ private bugs(): (interfaces.IFleetDeployBug & { targets: interfaces.IFleetDeployTargetStatus[] })[] {
808
+ const bugs = new Map<string, interfaces.IFleetDeployBug & { targets: interfaces.IFleetDeployTargetStatus[] }>();
809
+ for (const target of this.status?.targets ?? []) for (const bug of target.openBugs) {
810
+ bugs.set(bug.key, { ...bug, targets: [...bugs.get(bug.key)?.targets ?? [], target] });
811
+ }
812
+ return [...bugs.values()].sort((leftArg, rightArg) => Number(rightArg.priority === 'urgent') - Number(leftArg.priority === 'urgent'));
813
+ }
814
+
815
+ public render(): plugins.deesElement.TemplateResult {
816
+ return this.mode === 'release' ? this.renderRelease() : this.mode === 'hotfix' ? this.renderHotfix() : this.renderWindow();
817
+ }
818
+
819
+ private renderRelease(): plugins.deesElement.TemplateResult {
820
+ const repos = this.repositories();
821
+ const state = this.release?.repositories.find((repoArg) => repoArg.repo === this.repo);
822
+ const targets = (this.status?.targets ?? []).filter((targetArg) => (targetArg.repository ?? targetArg.target.repo) === this.repo);
823
+ const choices = [{ key: 'new', option: 'A new ticket' }, ...this.tickets.map((choiceArg) => ({ key: choiceArg.key, option: choiceArg.label }))];
824
+ return html`
825
+ <dees-input-dropdown class="repoInput" label="Repository" .options=${repos.map((repoArg) => ({ key: repoArg, option: repoArg }))}
826
+ .selectedOption=${this.repo ? { key: this.repo, option: this.repo } : null}
827
+ @selectedOption=${(eventArg: CustomEvent<{ key?: unknown }>) => { if (typeof eventArg.detail?.key === 'string') this.repo = eventArg.detail.key; }}></dees-input-dropdown>
828
+ <div class="pair">
829
+ <dees-input-text class="versionInput" label="Version" .value=${this.version} placeholder="next"
830
+ @input=${(eventArg: Event) => { this.version = String((eventArg.currentTarget as plugins.deesCatalog.DeesInputText).value ?? '').trim(); }}></dees-input-text>
831
+ <dees-input-dropdown class="ticketInput" label="Ticket" .enableSearch=${true} .options=${choices}
832
+ .selectedOption=${choices.find((choiceArg) => choiceArg.key === this.ticketKey) ?? null}
833
+ @selectedOption=${(eventArg: CustomEvent<{ key?: unknown }>) => { if (typeof eventArg.detail?.key === 'string') this.ticketKey = eventArg.detail.key; }}></dees-input-dropdown>
834
+ </div>
835
+ ${this.ticketKey === 'new' ? html`<dees-input-dropdown class="projectInput" label="Project of the new ticket"
836
+ .options=${this.projects.map((projectArg) => ({ key: projectArg.name, option: projectArg.name }))}
837
+ .selectedOption=${this.project ? { key: this.project, option: this.project } : null}
838
+ @selectedOption=${(eventArg: CustomEvent<{ key?: unknown }>) => { if (typeof eventArg.detail?.key === 'string') this.project = eventArg.detail.key; }}></dees-input-dropdown>` : ''}
839
+ <p class="hint">Leave the version empty for "the next one". If gitzone picks another version when it runs, fleet stops and asks you.</p>
840
+ <dees-grouped-list .inset=${false} .sections=${[{
841
+ header: `Would ship, from git (landed after ${state?.latest ? `v${state.latest.version}` : 'the last tag'})`,
842
+ rows: state?.landedAfterLatest.length ? state.landedAfterLatest.map((ticketArg) => ({ key: ticketArg.key, label: ticketArg.title, icon: 'lucide:GitMerge',
843
+ accessory: ticketKeyText(ticketArg.key) }))
844
+ : [{ key: 'none', label: 'Nothing landed after the last release tag yet.' }],
845
+ }, ...(targets.length ? [{ header: 'Deploy afterwards', footer: 'A target that falls behind gets a deploy plan that waits for your go.',
846
+ rows: targets.map((targetArg) => ({ key: targetArg.target.id, label: deployTargetName(targetArg), value: targetArg.target.environment ?? '' })) }] : [])]}></dees-grouped-list>
847
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
848
+ `;
849
+ }
850
+
851
+ private renderHotfix(): plugins.deesElement.TemplateResult {
852
+ const bugs = this.bugs();
853
+ const bug = bugs.find((bugArg) => bugArg.key === this.bugKey);
854
+ const repo = bug?.targets[0] ? bug.targets[0].repository ?? bug.targets[0].target.repo : '';
855
+ const along = (this.release?.repositories.find((repoArg) => repoArg.repo === repo)?.landedAfterLatest ?? []).filter((ticketArg) => ticketArg.key !== bug?.key);
856
+ const choices = bugs.map((bugArg) => ({ key: bugArg.key, option: `${bugArg.key} · ${bugArg.title}` }));
857
+ return html`
858
+ <dees-input-dropdown class="bugInput" label="Bug" .options=${choices} .selectedOption=${choices.find((choiceArg) => choiceArg.key === this.bugKey) ?? null}
859
+ @selectedOption=${(eventArg: CustomEvent<{ key?: unknown }>) => { if (typeof eventArg.detail?.key === 'string') this.bugKey = eventArg.detail.key; }}
860
+ ></dees-input-dropdown>
861
+ ${bug ? html`<dees-grouped-list .inset=${false} .sections=${[{ rows: [
862
+ { key: 'found', label: `found in ${repo} ${bug.foundIn}`, icon: 'lucide:Bug', iconColor: 'var(--dees-color-text-error)' },
863
+ { key: 'fix', label: bug.fixLandedSha ? `fix landed on main at ${shortSha(bug.fixLandedSha)}${bug.fixedIn ? `, released in ${bug.fixedIn}` : ''}` : 'no fix landed yet',
864
+ icon: 'lucide:GitCommitHorizontal' },
865
+ ...bug.targets.map((targetArg) => ({ key: `running:${targetArg.target.id}`, icon: 'lucide:Server',
866
+ label: `running ${deployTargetName(targetArg)} ${targetArg.running?.version ?? ''}${targetArg.probe.state === 'down' ? ` · probe down since ${deployClock(targetArg.probe.downSince)}` : ''}` })),
867
+ ] }]}></dees-grouped-list>` : html`<p class="hint">No open bug was found in a version a target runs. Record where a bug showed with
868
+ <code>agl ticket link AGL-… --affects REPO@VERSION</code>.</p>`}
869
+ <div class="pair">
870
+ <dees-input-text class="versionInput" label="Version" .value=${this.version} placeholder="next"
871
+ @input=${(eventArg: Event) => { this.version = String((eventArg.currentTarget as plugins.deesCatalog.DeesInputText).value ?? '').trim(); }}></dees-input-text>
872
+ <dees-input-text label="Deploy to" .value=${bug?.targets.map((targetArg) => deployTargetName(targetArg)).join(', ') ?? ''} .disabled=${true}></dees-input-text>
873
+ </div>
874
+ <p class="hint">Leave the version empty for "the next one": gitzone picks it when fleet releases.</p>
875
+ ${along.length ? html`<p class="warning">Releasing ships main as it is: ${along.map((ticketArg) => ticketArg.key).join(', ')}
876
+ landed too and go along.</p>` : ''}
877
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
878
+ `;
879
+ }
880
+
881
+ private renderWindow(): plugins.deesElement.TemplateResult {
882
+ const choices = this.windowChoices();
883
+ const chosen = choices.filter((targetArg) => this.windowTargets.includes(targetArg.target.id));
884
+ const what: plugins.deesCatalog.IGroupedListRow[] = [
885
+ ...chosen.map((targetArg) => {
886
+ const queued = targetArg.deployPlans.filter((planArg) => planArg.go === 'window').length;
887
+ return targetArg.deployWhen === 'window'
888
+ ? { key: targetArg.target.id, icon: 'lucide:CalendarCheck', label: `${deployTargetName(targetArg)} deploys inside it`,
889
+ description: queued ? `${queued} deploy${queued === 1 ? '' : 's'} queued for the next window run in the first one that opens.`
890
+ : 'It deploys only inside a window; a deploy queued for the next window runs in the first one that opens.' }
891
+ : { key: targetArg.target.id, icon: 'lucide:CalendarRange', label: `${deployTargetName(targetArg)} deploys at any time`,
892
+ description: 'The window is a time to deploy it in; nothing waits for it.' };
893
+ }),
894
+ { key: 'who', icon: 'lucide:User', label: 'Who deploys',
895
+ description: 'The driver, or the direct report for the target\'s project. AGL deploys nothing itself: it tells them when a window opens.' },
896
+ { key: 'cancel', icon: 'lucide:CalendarX', label: 'Closing its ticket cancels the window' },
897
+ ];
898
+ return html`
899
+ <div class="targets">
900
+ <span class="fieldLabel">Targets</span>
901
+ ${choices.map((targetArg) => html`<dees-input-checkbox class="windowTarget" data-target=${targetArg.target.id} .label=${deployTargetName(targetArg)}
902
+ .description=${[targetArg.target.environment, targetArg.deployWhen === 'window' ? 'deploys only in a window' : 'deploys at any time'].filter(Boolean).join(' · ')}
903
+ .value=${this.windowTargets.includes(targetArg.target.id)}
904
+ @newValue=${(eventArg: CustomEvent<boolean>) => {
905
+ const others = this.windowTargets.filter((idArg) => idArg !== targetArg.target.id);
906
+ this.windowTargets = eventArg.detail ? choices.map((choiceArg) => choiceArg.target.id).filter((idArg) => idArg === targetArg.target.id || others.includes(idArg)) : others;
907
+ }}></dees-input-checkbox>`)}
908
+ </div>
909
+ <div class="pair">
910
+ <dees-input-datepicker class="fromInput" label="From" .enableTime=${true} .value=${this.from}
911
+ @change=${(eventArg: CustomEvent<{ value?: unknown }>) => { this.from = String(eventArg.detail?.value ?? ''); }}></dees-input-datepicker>
912
+ <dees-input-datepicker class="toInput" label="To" .enableTime=${true} .value=${this.to} .minDate=${this.from}
913
+ @change=${(eventArg: CustomEvent<{ value?: unknown }>) => { this.to = String(eventArg.detail?.value ?? ''); }}></dees-input-datepicker>
914
+ </div>
915
+ <p class="hint">In your time zone; AGL keeps UTC. A window is at most seven days long.</p>
916
+ <dees-grouped-list .inset=${false} .sections=${[{ header: 'What happens', rows: what }]}></dees-grouped-list>
917
+ <p class="hint">The AGL controller takes no window: it upgrades when no session is busy.</p>
918
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
919
+ `;
920
+ }
921
+
922
+ /** Cancels the planned window: its ticket is closed. */
923
+ public async cancelWindow(): Promise<boolean> {
924
+ if (!this.sender || !this.windowKey) return false;
925
+ this.error = '';
926
+ try {
927
+ await ticket(this.sender, 'move', { ticketId: this.windowKey, columnId: 'closed' });
928
+ return true;
929
+ } catch (errorArg) {
930
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
931
+ return false;
932
+ }
933
+ }
934
+
935
+ /** Writes the plan; resolves false with the reason shown when the controller refuses it. */
936
+ public async submit(): Promise<boolean> {
937
+ const sender = this.sender;
938
+ if (!sender) return false;
939
+ this.error = '';
940
+ try {
941
+ if (this.mode === 'window') {
942
+ const targets = this.windowChoices().filter((targetArg) => this.windowTargets.includes(targetArg.target.id));
943
+ if (!targets.length) throw new Error('Choose the targets the window is for.');
944
+ if (!this.from || !this.to) throw new Error('Choose when the window starts and when it ends.');
945
+ const maintenanceWindow = { from: this.from, to: this.to, targets: targets.map((targetArg) => targetArg.target.id) };
946
+ if (this.windowKey) {
947
+ const { ticket: current } = await ticket(sender, 'get', { ticketId: this.windowKey });
948
+ await ticket(sender, 'update', { ticketId: this.windowKey, expectedRevision: current.revision, changes: { maintenanceWindow } });
949
+ return true;
950
+ }
951
+ await ticket(sender, 'create', { project: targets[0]!.target.project, columnId: 'ready', maintenanceWindow,
952
+ title: `Maintenance window · ${targets.map((targetArg) => deployTargetName(targetArg)).join(', ')}` });
953
+ return true;
954
+ }
955
+ if (this.mode === 'hotfix') {
956
+ const bug = this.bugs().find((bugArg) => bugArg.key === this.bugKey);
957
+ if (!bug) throw new Error('Choose the bug the hotfix fixes.');
958
+ const repo = bug.targets[0]!.repository ?? bug.targets[0]!.target.repo;
959
+ const { ticket: current } = await ticket(sender, 'get', { ticketId: bug.key });
960
+ await ticket(sender, 'update', { ticketId: bug.key, expectedRevision: current.revision,
961
+ changes: { priority: 'urgent', releasePlan: { repo, ...(this.version ? { version: this.version } : {}) } } });
962
+ return true;
963
+ }
964
+ if (!this.repo) throw new Error('Choose the repository to release.');
965
+ const releasePlan = { repo: this.repo, ...(this.version ? { version: this.version } : {}) };
966
+ if (this.ticketKey === 'new' || !this.ticketKey) {
967
+ if (!this.project) throw new Error('Choose the project of the new ticket.');
968
+ await ticket(sender, 'create', { project: this.project, title: `Release ${this.repo} ${this.version || '(next)'}`, releasePlan });
969
+ return true;
970
+ }
971
+ const { ticket: current } = await ticket(sender, 'get', { ticketId: this.ticketKey });
972
+ await ticket(sender, 'update', { ticketId: this.ticketKey, expectedRevision: current.revision, changes: { releasePlan } });
973
+ return true;
974
+ } catch (errorArg) {
975
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
976
+ return false;
977
+ }
978
+ }
979
+ }
980
+
981
+ /**
982
+ * The go dialog's body: the question of a deploy plan (what each answer does for the target, and who deploys it) or of a
983
+ * maintenance window the driver proposed (its time and targets). The answer is the owner's, as on the ticket; the
984
+ * dialog's buttons send it.
985
+ */
986
+ @plugins.deesElement.customElement('agl-deploy-go')
987
+ export class AglDeployGo extends plugins.deesElement.DeesElement {
988
+ @plugins.deesElement.property({ attribute: false })
989
+ accessor sender: IDeploymentsSender | undefined;
990
+
991
+ /** The ticket whose question the dialog answers: the plan's or the window's. */
992
+ @plugins.deesElement.property({ attribute: false })
993
+ accessor subjectKey = '';
994
+
995
+ @plugins.deesElement.property({ attribute: false })
996
+ accessor window: interfaces.IFleetDeployWindow | undefined;
997
+
998
+ /** The names of the window's targets, as the view shows them. */
999
+ @plugins.deesElement.property({ attribute: false })
1000
+ accessor targetNames: string[] = [];
1001
+
1002
+ @plugins.deesElement.property({ attribute: false })
1003
+ accessor target: interfaces.IFleetDeployTargetStatus | undefined;
1004
+
1005
+ @plugins.deesElement.property({ attribute: false })
1006
+ accessor plan: interfaces.IFleetDeployPlan | undefined;
1007
+
1008
+ @plugins.deesElement.property({ attribute: false })
1009
+ accessor question: interfaces.ITicketQuestion | undefined;
1010
+
1011
+ @plugins.deesElement.state()
1012
+ accessor error = '';
1013
+
1014
+ public static styles = [
1015
+ plugins.deesElement.cssManager.defaultStyles,
1016
+ plugins.deesCatalog.themeDefaultStyles,
1017
+ sharedStyles,
1018
+ css`
1019
+ :host { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-width: 0; }
1020
+ .error { margin: 0; color: var(--dees-color-text-error); }
1021
+ `,
1022
+ ];
1023
+
1024
+ public render(): plugins.deesElement.TemplateResult {
1025
+ const { target, plan, window, question } = this;
1026
+ if (!question || !(target && plan) && !window) return html``;
1027
+ const icons: Record<string, string> = window
1028
+ ? { [interfaces.ticketWindowOptions.approve]: 'lucide:CalendarCheck', [interfaces.ticketWindowOptions.decline]: 'lucide:CalendarX' }
1029
+ : { [interfaces.ticketDeployPlanOptions.now]: 'lucide:Rocket', [interfaces.ticketDeployPlanOptions.later]: 'lucide:CalendarClock',
1030
+ [interfaces.ticketDeployPlanOptions.hold]: 'lucide:CirclePause' };
1031
+ const answer = question.answer;
1032
+ const options: plugins.deesCatalog.IGroupedListRow[] = question.options.map((optionArg) => ({ key: optionArg.id, label: optionArg.label,
1033
+ icon: icons[optionArg.id] ?? 'lucide:Circle', ...(optionArg.description ? { description: optionArg.description } : {}),
1034
+ ...(answer?.choices.includes(optionArg.id) ? { accessory: html`<dees-badge tone="success" text="your answer"></dees-badge>` } : {}) }));
1035
+ const facts: plugins.deesCatalog.IGroupedListRow[] = window ? [
1036
+ { key: 'time', label: 'When', icon: 'lucide:Clock', description: deployWindowRange(window) },
1037
+ { key: 'targets', label: 'Targets', icon: 'lucide:Server', description: this.targetNames.join(', ') },
1038
+ { key: 'what', label: 'What it does', icon: 'lucide:Info',
1039
+ description: 'Approved, the targets that deploy only in a window may be deployed in it, and the deploys you queued into the next window run then.' },
1040
+ ] : [
1041
+ { key: 'runs', label: 'Runs now', icon: 'lucide:Server', value: target!.running ? target!.running.version : 'not observed yet' },
1042
+ { key: 'when', label: 'When it deploys', icon: 'lucide:Clock', description: deployWhenText(target!) },
1043
+ { key: 'who', label: 'Who deploys', icon: 'lucide:User',
1044
+ description: plan!.assignee ? `${plan!.assignee}, as the plan's assignee` : 'The driver: the plan has no assignee.' },
1045
+ ];
1046
+ return html`
1047
+ <dees-grouped-list .inset=${false} .sections=${[{ header: answer ? 'Answered' : 'Your go', rows: options,
1048
+ ...(answer ? { footer: `${answer.answeredBy.name} answered ${deployMoment(answer.answeredAt)}.` } : {}) },
1049
+ { header: window ? 'Maintenance window' : deployTargetName(target!), rows: facts }]}></dees-grouped-list>
1050
+ ${this.error ? html`<p class="error" role="alert">${this.error}</p>` : ''}
1051
+ `;
1052
+ }
1053
+
1054
+ /** Sends the owner's answer; resolves false with the reason shown when the controller refuses it. */
1055
+ public async answer(optionIdArg: string): Promise<boolean> {
1056
+ if (!this.sender || !this.subjectKey || !this.question) return false;
1057
+ this.error = '';
1058
+ try {
1059
+ await ticket(this.sender, 'answer', { ticketId: this.subjectKey, questionId: this.question.id, choices: [optionIdArg] });
1060
+ return true;
1061
+ } catch (errorArg) {
1062
+ this.error = errorArg instanceof Error ? errorArg.message : String(errorArg);
1063
+ return false;
1064
+ }
1065
+ }
1066
+ }