@exagone313/dsh-podman 1.6.1 → 1.8.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 (117) hide show
  1. package/cordis.patch.yml +3 -1
  2. package/dist/approval-reasons.d.ts +37 -0
  3. package/dist/approval-reasons.js +128 -0
  4. package/dist/approval-template-summary.d.ts +8 -0
  5. package/dist/approval-template-summary.js +163 -0
  6. package/dist/approval.d.ts +8 -4
  7. package/dist/approval.js +104 -10
  8. package/dist/client/ContainerCard.js +8 -2
  9. package/dist/client/container-card-controller.d.ts +13 -5
  10. package/dist/client/container-card-controller.js +60 -24
  11. package/dist/client/container-card-create-config.d.ts +23 -0
  12. package/dist/client/container-card-create-config.js +48 -0
  13. package/dist/client/container-card-create-modal.d.ts +9 -1
  14. package/dist/client/container-card-create-modal.js +37 -41
  15. package/dist/client/container-card-create-volume.d.ts +10 -0
  16. package/dist/client/container-card-create-volume.js +34 -0
  17. package/dist/client/container-card-dialog-styles.d.ts +4 -2
  18. package/dist/client/container-card-dialog-styles.js +47 -4
  19. package/dist/client/container-card-edit-modal.d.ts +5 -1
  20. package/dist/client/container-card-edit-modal.js +55 -19
  21. package/dist/client/container-card-editors.d.ts +9 -0
  22. package/dist/client/container-card-editors.js +300 -43
  23. package/dist/client/container-card-form.d.ts +2 -1
  24. package/dist/client/container-card-form.js +26 -8
  25. package/dist/client/container-card-images.js +9 -31
  26. package/dist/client/container-card-mount-actions.d.ts +12 -0
  27. package/dist/client/container-card-mount-actions.js +35 -0
  28. package/dist/client/container-card-mount-sources.d.ts +34 -0
  29. package/dist/client/container-card-mount-sources.js +180 -0
  30. package/dist/client/container-card-names.d.ts +2 -0
  31. package/dist/client/container-card-names.js +12 -0
  32. package/dist/client/container-card-row.d.ts +16 -1
  33. package/dist/client/container-card-row.js +69 -25
  34. package/dist/client/container-card-secrets.d.ts +2 -0
  35. package/dist/client/container-card-secrets.js +60 -17
  36. package/dist/client/container-card-shared.d.ts +17 -9
  37. package/dist/client/container-card-shared.js +122 -93
  38. package/dist/client/container-card-styles.d.ts +6 -0
  39. package/dist/client/container-card-styles.js +22 -0
  40. package/dist/client/container-card-table-styles.d.ts +2 -1
  41. package/dist/client/container-card-table-styles.js +14 -0
  42. package/dist/client/container-card-templates.d.ts +81 -0
  43. package/dist/client/container-card-templates.js +1004 -0
  44. package/dist/client/container-card-toast.js +1 -1
  45. package/dist/client/container-card-volumes.js +6 -20
  46. package/dist/client/container-card-workspace.d.ts +10 -2
  47. package/dist/client/container-card-workspace.js +98 -5
  48. package/dist/client/container-template-ui.d.ts +163 -0
  49. package/dist/client/container-template-ui.js +579 -0
  50. package/dist/client/download.d.ts +1 -0
  51. package/dist/client/download.js +23 -0
  52. package/dist/client/image-facts.d.ts +18 -0
  53. package/dist/client/image-facts.js +44 -0
  54. package/dist/client/index.js +13478 -3438
  55. package/dist/client/locales.d.ts +1 -1
  56. package/dist/client/locales.js +120 -0
  57. package/dist/client/podman-containers.js +47 -18
  58. package/dist/client/podman-terminal-guide.js +4 -2
  59. package/dist/client/podman-terminal.js +4 -2
  60. package/dist/client/template-client.d.ts +9 -0
  61. package/dist/client/template-client.js +52 -0
  62. package/dist/client/template-protocol.d.ts +60 -0
  63. package/dist/client/template-protocol.js +4 -0
  64. package/dist/client/terminal-errors.d.ts +11 -0
  65. package/dist/client/terminal-errors.js +26 -0
  66. package/dist/client/terminal-protocol.d.ts +5 -0
  67. package/dist/client/terminal-protocol.js +5 -0
  68. package/dist/client/terminal-styles.d.ts +2 -1
  69. package/dist/client/terminal-styles.js +9 -1
  70. package/dist/client/terminal-transport.d.ts +17 -2
  71. package/dist/client/terminal-transport.js +31 -8
  72. package/dist/client/tool-presentations.d.ts +32 -0
  73. package/dist/client/tool-presentations.js +33 -0
  74. package/dist/client/tool-views.js +17 -7
  75. package/dist/client/workspace-target.d.ts +54 -0
  76. package/dist/client/workspace-target.js +86 -0
  77. package/dist/container-template.d.ts +153 -0
  78. package/dist/container-template.js +1058 -0
  79. package/dist/generated/version.d.ts +2 -2
  80. package/dist/generated/version.js +2 -2
  81. package/dist/grpc/proto/dshguest/v1/guest.proto +11 -0
  82. package/dist/guest-rpc.d.ts +1 -0
  83. package/dist/guest-rpc.js +12 -0
  84. package/dist/index.js +7 -1
  85. package/dist/mount-enums.d.ts +2 -0
  86. package/dist/mount-enums.js +17 -0
  87. package/dist/mount-order.d.ts +14 -0
  88. package/dist/mount-order.js +49 -0
  89. package/dist/project-path.d.ts +14 -0
  90. package/dist/project-path.js +25 -0
  91. package/dist/template-apply.d.ts +21 -0
  92. package/dist/template-apply.js +102 -0
  93. package/dist/template-files.d.ts +23 -0
  94. package/dist/template-files.js +186 -0
  95. package/dist/template-image.d.ts +22 -0
  96. package/dist/template-image.js +80 -0
  97. package/dist/template-route.d.ts +9 -0
  98. package/dist/template-route.js +278 -0
  99. package/dist/terminal-route.js +49 -7
  100. package/dist/tool-defs.js +27 -1
  101. package/dist/tool-handlers.js +69 -1
  102. package/dist/tool-params.d.ts +38 -0
  103. package/dist/tool-params.js +30 -0
  104. package/docs/README.md +4 -3
  105. package/docs/architecture.md +42 -12
  106. package/docs/architecture.zh.md +22 -8
  107. package/docs/configuration.md +19 -20
  108. package/docs/configuration.zh.md +3 -4
  109. package/docs/development-prompt.md +49 -45
  110. package/docs/development-prompt.zh.md +47 -43
  111. package/docs/development.md +45 -28
  112. package/docs/development.zh.md +59 -46
  113. package/docs/uninstall.md +3 -3
  114. package/docs/uninstall.zh.md +2 -2
  115. package/docs/usage.md +155 -23
  116. package/docs/usage.zh.md +104 -14
  117. package/package.json +34 -33
@@ -0,0 +1,579 @@
1
+ // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+ // The load-template popup's decisions, kept out of the React component so they
5
+ // can be tested: the editor draft a template prefills, which image action the
6
+ // card offers, and whether the Create action is currently allowed.
7
+ import { effectiveImage, parseContainerTemplate, templateMountInputs, } from "../container-template.js";
8
+ import { buildParentImages, isPtcImage } from "./container-card-ptc.js";
9
+ import { mergeDefaultEnv } from "../container-env.js";
10
+ import { orderedEnvRecord } from "../env-rows.js";
11
+ import { decideProjectPath, hostPathForProjectName, } from "../project-path.js";
12
+ // templateImageFacts describes the template's own image. A base-only template
13
+ // runs the base itself, so its card states the base's upstream reference and
14
+ // packages, read from the listed base image: built, pulled and missing bases
15
+ // then differ only in their status chip and build time. A custom template names
16
+ // its base as the parent and carries its effective extras. A base row the list
17
+ // does not hold leaves both lines hidden, since the plan alone does not know
18
+ // them.
19
+ export function templateImageFacts(plan, images) {
20
+ const effective = plan.effective;
21
+ const status = plan.needsBuild ? "missing" : "built";
22
+ if (effective.kind === "template") {
23
+ return {
24
+ imageId: plan.imageId,
25
+ status,
26
+ builtAt: plan.builtAt,
27
+ source: effective.base,
28
+ packages: effective.packages,
29
+ };
30
+ }
31
+ const base = images.find((image) => image.imageId === effective.base);
32
+ return {
33
+ imageId: plan.imageId,
34
+ status,
35
+ builtAt: plan.builtAt,
36
+ source: base?.primitive ?? "",
37
+ packages: base?.packages,
38
+ };
39
+ }
40
+ // templateOwnImageId is the id the template's own image is offered and matched
41
+ // under: a custom template's derived id, or the effective base of a base-only
42
+ // one.
43
+ function templateOwnImageId(plan) {
44
+ if (plan === null)
45
+ return undefined;
46
+ return plan.effective?.kind === "base" ? plan.effective.base : plan.imageId;
47
+ }
48
+ // isTemplateImage reports whether a draft image is the template's own: the
49
+ // plan's image id, or a base-only plan's effective base. Both normally name the
50
+ // same image, but an inspection can carry one while the plan carries the other.
51
+ function isTemplateImage(plan, draftImage) {
52
+ return draftImage === plan.imageId ||
53
+ (plan.effective?.kind === "base" && draftImage === plan.effective.base);
54
+ }
55
+ // compareImageIds orders two image ids case-insensitively. It returns 0 for ids
56
+ // that differ only by case, and the stable sort keeps the workspace's order for
57
+ // them.
58
+ function compareImageIds(left, right) {
59
+ const a = left.toLowerCase();
60
+ const b = right.toLowerCase();
61
+ if (a === b)
62
+ return 0;
63
+ return a < b ? -1 : 1;
64
+ }
65
+ // templateImageCandidates lists the image ids the details popup's picker
66
+ // offers: the template's own image first, then the other base images, then the
67
+ // other custom images, each group sorted by image id, without duplicates or
68
+ // empty ids. The template's own image is the plan's derived id, or a base-only
69
+ // plan's effective base, whether or not the workspace list holds it: a custom
70
+ // template's derived image only joins the list once it is built, so it is added
71
+ // here rather than lost: after the draft switches to another image, the picker
72
+ // must still be able to return to it. A listed own image is not repeated in its
73
+ // group. The reserved PTC image is never offered, as in the container editor.
74
+ export function templateImageCandidates(plan, images) {
75
+ const offered = buildParentImages(images);
76
+ const own = templateOwnImageId(plan);
77
+ const others = offered.filter((image) => image.imageId !== "" && image.imageId !== own);
78
+ const bases = others.filter((image) => image.isBase)
79
+ .map((image) => image.imageId)
80
+ .sort(compareImageIds);
81
+ const custom = others.filter((image) => !image.isBase)
82
+ .map((image) => image.imageId)
83
+ .sort(compareImageIds);
84
+ const first = own === undefined || own === "" ? [] : [own];
85
+ return [...new Set([...first, ...bases, ...custom])];
86
+ }
87
+ // templateDraftImageFacts is the image card's answer for the draft's image. The
88
+ // template's own image describes the plan (including a build the card can run
89
+ // here); any other listed image is described from the workspace's image list;
90
+ // an id the list no longer holds is missing, and the card offers no build for
91
+ // it because this popup only builds the template's image.
92
+ export function templateDraftImageFacts(plan, draftImage, images) {
93
+ if (isTemplateImage(plan, draftImage)) {
94
+ return templateImageFacts(plan, images);
95
+ }
96
+ const image = images.find((candidate) => candidate.imageId === draftImage);
97
+ if (image === undefined) {
98
+ return {
99
+ imageId: draftImage,
100
+ status: "missing",
101
+ builtAt: "",
102
+ source: "",
103
+ packages: undefined,
104
+ };
105
+ }
106
+ return {
107
+ imageId: image.imageId,
108
+ status: image.status,
109
+ builtAt: image.builtAt,
110
+ source: image.parent !== "" ? image.parent : image.primitive,
111
+ packages: image.packages,
112
+ };
113
+ }
114
+ // templateDisplayName is the name a template is listed under: its file name
115
+ // without the YAML suffix. The full file name stays available as muted secondary
116
+ // text (the details header) or the picker row's file-name tooltip, so the row is
117
+ // led by the template rather than by the file it happens to live in; the tooltip
118
+ // never carries facts, which the row shows in full.
119
+ export function templateDisplayName(fileName) {
120
+ const name = fileName.replace(/\.(?:ya?ml)$/i, "").trim();
121
+ return name === "" ? fileName : name;
122
+ }
123
+ // invalidTemplateReason is the parser's message, trimmed. The parser's message
124
+ // is the one thing the user can act on, so every line is kept and nothing is
125
+ // shortened: the picker's error block wraps to the lines the reason needs.
126
+ export function invalidTemplateReason(error) {
127
+ const message = error instanceof Error ? error.message : String(error);
128
+ return message.trim();
129
+ }
130
+ // templateSecretNames lists every secret a template requires, in first-use
131
+ // order: the secret an environment variable names, then the secrets its mounts
132
+ // name. The picker counts these and the details popup marks them, so both agree
133
+ // on what "one secret" means.
134
+ export function templateSecretNames(template) {
135
+ const names = [];
136
+ const add = (name) => {
137
+ if (name !== "" && !names.includes(name))
138
+ names.push(name);
139
+ };
140
+ for (const secret of Object.values(template.spec.secretEnv))
141
+ add(secret);
142
+ for (const mount of template.spec.mounts) {
143
+ if (mount.kind === "secret")
144
+ add(mount.secret);
145
+ }
146
+ return names;
147
+ }
148
+ // templateEnvNames lists the plain environment variables a template sets, in
149
+ // the template's own order. Secret environment variables are described by the
150
+ // secret they name, which the row states in its secrets fact instead.
151
+ export function templateEnvNames(template) {
152
+ return Object.keys(template.spec.env);
153
+ }
154
+ // templateMountSource is the identity a picker row names for one mount. A
155
+ // project, volume or secret mount is named by its source; tmpfs has no source,
156
+ // so its destination is the only identity it carries. The kind itself is never
157
+ // shown.
158
+ export function templateMountSource(mount) {
159
+ switch (mount.kind) {
160
+ case "project":
161
+ return mount.project;
162
+ case "volume":
163
+ return mount.volume;
164
+ case "secret":
165
+ return mount.secret;
166
+ case "tmpfs":
167
+ return mount.destination;
168
+ }
169
+ }
170
+ // templatePortRowValue is what a picker row shows for one port: the container
171
+ // port alone, or "container→host" when a host port differs from it.
172
+ export function templatePortRowValue(port) {
173
+ return port.host !== undefined && port.host !== port.container
174
+ ? `${port.container}→${port.host}`
175
+ : String(port.container);
176
+ }
177
+ // templateSpecSummary parses one template file locally and describes what it
178
+ // does. The picker reads its row from this parsed spec, never from the file name
179
+ // or a second parse guess; a document that does not parse is reported as invalid
180
+ // with the parser's reason.
181
+ export function templateSpecSummary(yaml) {
182
+ try {
183
+ const template = parseContainerTemplate(yaml);
184
+ const image = effectiveImage(template);
185
+ return {
186
+ valid: true,
187
+ image,
188
+ packages: image.kind === "template" ? image.packages.length : 0,
189
+ envNames: templateEnvNames(template),
190
+ mounts: template.spec.mounts.map(templateMountSource),
191
+ paths: [...template.spec.paths],
192
+ ports: template.spec.ports.map(templatePortRowValue),
193
+ secrets: templateSecretNames(template),
194
+ };
195
+ }
196
+ catch (error) {
197
+ return { valid: false, reason: invalidTemplateReason(error) };
198
+ }
199
+ }
200
+ // templateChoiceActionable reports whether the picker's Next may open the
201
+ // details: the chosen file's summary must have parsed, and the command must be
202
+ // idle. A missing summary is not actionable either, so a selection the picker
203
+ // could not describe never continues.
204
+ export function templateChoiceActionable(summary, busy) {
205
+ return !busy && summary !== undefined && summary.valid;
206
+ }
207
+ // Two values are still readable beside their label; a third is what turns the
208
+ // segment into a count, which is why the break point is exactly here.
209
+ const NAMED_FACT_LIMIT = 2;
210
+ // Ports are the one category with a lower limit: a single mapping is a fact the
211
+ // row can state, but two full mappings read as noise beside the categories that
212
+ // name their subjects, so ports collapse from the second.
213
+ const NAMED_PORT_LIMIT = 1;
214
+ function summarySegment(label, values, limit = NAMED_FACT_LIMIT) {
215
+ if (values.length === 0)
216
+ return undefined;
217
+ return values.length <= limit
218
+ ? { label, values: [...values] }
219
+ : { label, values: [], count: values.length };
220
+ }
221
+ // templateSummarySegments renders one picker row's facts as labelled segments,
222
+ // in the row's fixed order: the image alone first, then environment, mounts,
223
+ // secrets, PATH additions and ports. A category with no entries is omitted, and
224
+ // a category past its naming limit keeps only its count (ports from the second,
225
+ // every other category from the third). The labels are the only copy the row
226
+ // needs: a collapsed category already names its unit, so its count is the bare
227
+ // number rather than a second cardinal phrase.
228
+ export function templateSummarySegments(t, summary) {
229
+ if (!summary.valid)
230
+ return [];
231
+ const image = summary.image.kind === "base"
232
+ ? summary.image.base
233
+ : `${summary.image.base} +${summary.packages} ${t(summary.packages === 1
234
+ ? "templateFactPackageOne"
235
+ : "templateFactPackageMany")}`;
236
+ const segments = [{ label: "", values: [image] }];
237
+ const append = (label, values, limit) => {
238
+ const segment = summarySegment(label, values, limit);
239
+ if (segment !== undefined)
240
+ segments.push(segment);
241
+ };
242
+ append(t("templateFactEnv"), summary.envNames);
243
+ append(t("templateFactMounts"), summary.mounts);
244
+ append(t("templateFactSecrets"), summary.secrets);
245
+ append(t("templateFactPath"), summary.paths);
246
+ append(t("templateFactPorts"), summary.ports, NAMED_PORT_LIMIT);
247
+ return segments;
248
+ }
249
+ // templateSummarySegmentValue is the value half of one segment: the listed
250
+ // values in full, or the bare count that replaced them.
251
+ export function templateSummarySegmentValue(segment) {
252
+ return segment.count === undefined
253
+ ? segment.values.join(", ")
254
+ : String(segment.count);
255
+ }
256
+ // templateSummarySegmentText is one segment as the user reads it: the image
257
+ // unprefixed, every other segment as "label: value".
258
+ export function templateSummarySegmentText(segment) {
259
+ const value = templateSummarySegmentValue(segment);
260
+ return segment.label === "" ? value : `${segment.label}: ${value}`;
261
+ }
262
+ // templateSummaryLineText joins a row's segments with the separator the picker
263
+ // paints, so the visible line and the accessible label are the same text.
264
+ export function templateSummaryLineText(segments) {
265
+ return segments.map(templateSummarySegmentText).join(" · ");
266
+ }
267
+ // templateSummaryAccessibleLabel is the row's accessible name: the display name
268
+ // the row is led by, then the same complete summary text the eye reads, or the
269
+ // invalid file's reason in place of facts. It never reduces the row to its name
270
+ // alone.
271
+ export function templateSummaryAccessibleLabel(t, name, summary) {
272
+ if (summary === undefined)
273
+ return name;
274
+ if (!summary.valid)
275
+ return `${name} · ${summary.reason}`;
276
+ return [name, templateSummaryLineText(templateSummarySegments(t, summary))]
277
+ .join(" · ");
278
+ }
279
+ // templateDraftReferences lists every reference the draft carries, in the order
280
+ // the editors list it: secret environment values first, then each mount's own
281
+ // source. A row that names nothing is listed too — an emptied project path, a
282
+ // mount whose source was cleared, a secret variable left without a secret —
283
+ // because such a row still reaches the editor and would be refused there; it is
284
+ // simply missing from the workspace's names.
285
+ export function templateDraftReferences(draft) {
286
+ const references = [];
287
+ for (const [env, secret] of Object.entries(draft.secretEnv)) {
288
+ references.push({ kind: "secret", name: secret, env });
289
+ }
290
+ draft.mounts.forEach((mount, index) => {
291
+ switch (mount.kind) {
292
+ case "project":
293
+ references.push({
294
+ kind: "project",
295
+ name: mount.project,
296
+ mountIndex: index,
297
+ });
298
+ break;
299
+ case "volume":
300
+ references.push({
301
+ kind: "volume",
302
+ name: mount.volume,
303
+ mountIndex: index,
304
+ });
305
+ break;
306
+ case "secret":
307
+ references.push({
308
+ kind: "secret",
309
+ name: mount.secret,
310
+ mountIndex: index,
311
+ });
312
+ break;
313
+ }
314
+ });
315
+ return references;
316
+ }
317
+ // templateDraftMissingReferences is the references the draft names that the
318
+ // workspace no longer holds, once per kind and name. The popup marks their
319
+ // rows and counts them in the footer; the editor's own Apply is still the only
320
+ // write, so Continue waits until nothing is left unresolved.
321
+ export function templateDraftMissingReferences(references, known) {
322
+ const secretNames = new Set(known.secrets.map((secret) => secret.name));
323
+ const volumeNames = new Set(known.volumes.map((volume) => volume.name));
324
+ const projectNames = new Set(known.projects);
325
+ const missing = [];
326
+ const seen = new Set();
327
+ for (const reference of references) {
328
+ const knownHere = reference.kind === "secret"
329
+ ? secretNames.has(reference.name)
330
+ : reference.kind === "volume"
331
+ ? volumeNames.has(reference.name)
332
+ : projectNames.has(reference.name);
333
+ if (knownHere)
334
+ continue;
335
+ const key = `${reference.kind}:${reference.name}`;
336
+ if (seen.has(key))
337
+ continue;
338
+ seen.add(key);
339
+ missing.push(reference);
340
+ }
341
+ return missing;
342
+ }
343
+ // templateProjectPathDecision validates a typed project reference the way the
344
+ // mount editor does: lexical shape first, then the host's directory listing of
345
+ // the path under the projects root. The listing is injected so this decision is
346
+ // testable without a host; a deployment without a picker keeps the lexical
347
+ // answer, exactly as the mount editor does.
348
+ export async function templateProjectPathDecision(options) {
349
+ const lexical = decideProjectPath({
350
+ origin: "typed",
351
+ project: options.project,
352
+ directoryExists: true,
353
+ });
354
+ if (!lexical.ok || options.listDirectory === undefined)
355
+ return lexical;
356
+ let directoryExists = true;
357
+ try {
358
+ await options.listDirectory(hostPathForProjectName(options.projectsRoot, lexical.project));
359
+ }
360
+ catch {
361
+ directoryExists = false;
362
+ }
363
+ return decideProjectPath({
364
+ origin: "typed",
365
+ project: options.project,
366
+ directoryExists,
367
+ });
368
+ }
369
+ // templateProjectPathError is the popup's wording for a refused project
370
+ // reference. Unlike the mount editor's keys it names the offending value in
371
+ // every message, and it distinguishes an empty field — a choice still to make —
372
+ // from a path the host refused. The lexical and host failures stay separate
373
+ // mistakes with separate wording.
374
+ export function templateProjectPathError(t, project, reason) {
375
+ if (reason === "empty")
376
+ return t("templateChooseProject");
377
+ return t(reason === "missing" ? "templateProjectMissing" : "templateProjectInvalid", { project });
378
+ }
379
+ // templateProjectChecksEqual reports whether two check maps say the same thing.
380
+ // The popup writes a check map only when this is false, so a re-check that
381
+ // reaches the same answer causes no render at all — in particular while typing,
382
+ // when no host call is made and the stored answer stands.
383
+ export function templateProjectChecksEqual(left, right) {
384
+ const keys = Object.keys(left);
385
+ if (keys.length !== Object.keys(right).length)
386
+ return false;
387
+ for (const key of keys) {
388
+ const a = left[Number(key)];
389
+ const b = right[Number(key)];
390
+ if (b === undefined)
391
+ return false;
392
+ if (a.state !== b.state || a.project !== b.project)
393
+ return false;
394
+ if (a.state === "error" && b.state === "error" && a.error !== b.error) {
395
+ return false;
396
+ }
397
+ }
398
+ return true;
399
+ }
400
+ // templateConfigForEditor is the draft the details popup seeds and Continue
401
+ // hands to the create or edit editor. The mounts are exactly the ones the
402
+ // template writes, in its order; nothing is synthesised for a template that
403
+ // omits the workspace's project mount. The environment is the same one a
404
+ // hand-created container opens on: the workspace's default environment (the
405
+ // create dialog's own merge), then, for a replace, the container's current
406
+ // values, then the template's own — each later layer wins key by key, so a
407
+ // template never loses a default it does not mention and an export/edit round
408
+ // trip reproduces the container's environment. The draft is ordered the way the
409
+ // editor lists it, and it is exactly what Apply sends. A new container stages
410
+ // the template's ports for the create to publish; a replace keeps the
411
+ // container's current ports instead because the host publishes the template's
412
+ // after the editor's own Apply, and the template's image and every other field
413
+ // it defines replace the current ones while the fields it omits are shown as
414
+ // they currently are.
415
+ export function templateConfigForEditor(template, imageId, options = {}) {
416
+ const current = options.current;
417
+ // The layers are applied in precedence order: defaults first, then a
418
+ // replace's current values, then the template's own entries.
419
+ const env = orderedEnvRecord(mergeDefaultEnv(options.defaultEnv, current === undefined
420
+ ? template.spec.env
421
+ : { ...current.env, ...template.spec.env }));
422
+ if (current === undefined) {
423
+ return {
424
+ image: imageId,
425
+ env,
426
+ mounts: templateMountInputs(template),
427
+ paths: [...template.spec.paths],
428
+ secretEnv: { ...template.spec.secretEnv },
429
+ ports: template.spec.ports.map((port) => ({
430
+ port: port.container,
431
+ protocol: "tcp",
432
+ endpoint: "",
433
+ suggestedHostPort: port.host ?? 0,
434
+ hostPort: 0,
435
+ })),
436
+ };
437
+ }
438
+ return {
439
+ image: imageId,
440
+ env,
441
+ mounts: template.spec.mounts.length > 0
442
+ ? templateMountInputs(template)
443
+ : [...current.mounts],
444
+ paths: template.spec.paths.length > 0
445
+ ? [...template.spec.paths]
446
+ : [...current.paths],
447
+ secretEnv: Object.keys(template.spec.secretEnv).length > 0
448
+ ? { ...template.spec.secretEnv }
449
+ : { ...current.secretEnv },
450
+ ports: current.ports.map((port) => ({ ...port })),
451
+ };
452
+ }
453
+ // templateBlockReason reports why the Continue action must stay disabled, or
454
+ // undefined once it may run. The draft image is the gate that changed: only the
455
+ // template's own derived image is buildable here, so its plan blocks Continue
456
+ // while it needs a build, while the build runs and after a failure; another
457
+ // listed image needs no build, and an image the list no longer holds blocks
458
+ // because this popup cannot build it. Missing references block first — a
459
+ // pending project check counts as one, so its row's number stays put while the
460
+ // check reruns — and the checking state is reported only once nothing is
461
+ // missing. A replace with no chosen container blocks. Creating never blocks on a
462
+ // name here: the container name is chosen in the create editor the step opens.
463
+ export function templateBlockReason(options) {
464
+ if (options.inspection === null)
465
+ return "loading";
466
+ const plan = options.inspection.image;
467
+ if (options.draftImage === plan.imageId) {
468
+ if (options.buildInProgress)
469
+ return "build";
470
+ if (options.buildFailed !== "")
471
+ return "build-failed";
472
+ if (plan.needsBuild)
473
+ return "build";
474
+ }
475
+ else if (!options.images.some((image) => image.imageId === options.draftImage)) {
476
+ return "image-missing";
477
+ }
478
+ if (options.missingReferences > 0)
479
+ return "missing-references";
480
+ if (options.pendingReferences > 0)
481
+ return "checking";
482
+ if (options.mode === "replace") {
483
+ return options.replaceTarget === "" ? "no-container" : undefined;
484
+ }
485
+ return undefined;
486
+ }
487
+ // templateBuildAction is what the details popup's image card offers for the
488
+ // template's own image. A plan whose image is missing (or whose recipe changed)
489
+ // gets Build, a ready image gets Rebuild, and while a build runs the button is
490
+ // disabled and labelled as progress. A base-only plan's image is its effective
491
+ // base, so a draft on either id that names it counts as the template's own; the
492
+ // callback's `force` flag then rebuilds or pulls that base. Choosing another
493
+ // listed image, or an image the list no longer holds, gets no action here — this
494
+ // popup only runs the template route for the template's image.
495
+ export function templateBuildAction(options) {
496
+ if (options.plan === null || !isTemplateImage(options.plan, options.draftImage)) {
497
+ return "none";
498
+ }
499
+ if (options.building) {
500
+ return options.plan.needsBuild ? "building" : "rebuilding";
501
+ }
502
+ if (options.plan.needsBuild)
503
+ return "build";
504
+ return "rebuild";
505
+ }
506
+ // templateImageAction is what the details popup's image card offers for the
507
+ // draft's image, and the command behind it. The template's own image keeps the
508
+ // template action (Build while the plan needs it, Rebuild once it is ready, and
509
+ // progress while that call runs). Any other listed image offers what the Images
510
+ // tab offers for it: a custom image is rebuilt when its record is built and
511
+ // built when it is missing; a base is rebuilt when it is present, built when it
512
+ // is missing, and pulled instead when its tag comes from a public registry,
513
+ // where a base is pulled whether it is missing or already pulled. An image the
514
+ // list does not hold, like the reserved PTC image, offers no action: only the
515
+ // template's own image is built from the plan rather than from the list.
516
+ export function templateImageAction(options) {
517
+ const decision = (action, command) => ({ action, command });
518
+ const metadata = options.plan === null ? "none" : templateBuildAction({
519
+ plan: options.plan,
520
+ draftImage: options.draftImage,
521
+ building: options.building,
522
+ buildFailed: options.buildFailed ?? "",
523
+ });
524
+ switch (metadata) {
525
+ case "build":
526
+ return decision("build", "template-build");
527
+ case "building":
528
+ return decision("building", "template-build");
529
+ case "rebuild":
530
+ return decision("rebuild", "template-rebuild");
531
+ case "rebuilding":
532
+ return decision("rebuilding", "template-rebuild");
533
+ case "none":
534
+ // No chosen template means no details and no action at all.
535
+ if (options.plan === null)
536
+ return decision("none", "none");
537
+ }
538
+ const image = options.images.find((candidate) => candidate.imageId === options.draftImage);
539
+ if (image === undefined || isPtcImage(image.imageId)) {
540
+ return decision("none", "none");
541
+ }
542
+ if (image.isBase) {
543
+ // The Images tab pulls a public base instead of building it, whether it is
544
+ // missing or already pulled, and offers Pull only for that same state.
545
+ if (image.basePublic) {
546
+ return image.status === "missing" || image.status === "pulled"
547
+ ? decision("pull", "base-pull")
548
+ : decision("none", "none");
549
+ }
550
+ if (image.status === "missing") {
551
+ return decision("build", "base-build");
552
+ }
553
+ // "pulled" belongs to the public prefix, so a local base is normally
554
+ // "built"; accepting both means a present base always offers Rebuild.
555
+ return image.status === "built" || image.status === "pulled"
556
+ ? decision("rebuild", "base-rebuild")
557
+ : decision("none", "none");
558
+ }
559
+ if (image.status === "missing") {
560
+ return decision("build", "custom-build");
561
+ }
562
+ return image.status === "built"
563
+ ? decision("rebuild", "custom-rebuild")
564
+ : decision("none", "none");
565
+ }
566
+ // missingSecretNames lists the secrets a container configuration requires that
567
+ // the workspace no longer has, in first-use order. The editor offers creating
568
+ // each one in place.
569
+ export function missingSecretNames(secretEnv, secrets) {
570
+ const known = new Set(secrets.map((secret) => secret.name));
571
+ const missing = [];
572
+ for (const secret of Object.values(secretEnv)) {
573
+ if (secret === "" || known.has(secret) || missing.includes(secret)) {
574
+ continue;
575
+ }
576
+ missing.push(secret);
577
+ }
578
+ return missing;
579
+ }
@@ -0,0 +1 @@
1
+ export declare function downloadTextFile(filename: string, text: string, type?: string): void;
@@ -0,0 +1,23 @@
1
+ // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+ // Trigger the browser's save dialog for a text document. The object URL is
5
+ // revoked on the next task, after the browser has started the download, so the
6
+ // document is never kept alive by the page.
7
+ export function downloadTextFile(filename, text, type = "application/yaml") {
8
+ const blob = new Blob([text], { type });
9
+ const url = URL.createObjectURL(blob);
10
+ try {
11
+ const anchor = document.createElement("a");
12
+ anchor.href = url;
13
+ anchor.download = filename;
14
+ anchor.rel = "noopener";
15
+ anchor.style.display = "none";
16
+ document.body.appendChild(anchor);
17
+ anchor.click();
18
+ anchor.remove();
19
+ }
20
+ finally {
21
+ setTimeout(() => URL.revokeObjectURL(url), 0);
22
+ }
23
+ }
@@ -0,0 +1,18 @@
1
+ import type { Translate } from "./locales.js";
2
+ import { type ReactNode } from "react";
3
+ export declare function ImageField(props: {
4
+ label: string;
5
+ ownLine?: boolean;
6
+ children: ReactNode;
7
+ }): ReactNode;
8
+ export declare function ImageFacts(props: {
9
+ t: Translate;
10
+ locale: string;
11
+ imageId: string;
12
+ status: string;
13
+ builtAt: string;
14
+ source: string;
15
+ packages?: readonly string[] | undefined;
16
+ isDefault?: boolean;
17
+ actions?: ReactNode;
18
+ }): ReactNode;
@@ -0,0 +1,44 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
3
+ //
4
+ // SPDX-License-Identifier: MIT
5
+ // The facts half of an image's block, shared by the settings images tab and the
6
+ // template details popup: the name with its status chip and optional default
7
+ // pill, the build time, the image it descends from and its packages. The
8
+ // settings tab adds the image's own actions through the slot, so both places
9
+ // read the same facts instead of drifting.
10
+ import { Chip, imageStatusLabel, imageStatusTone, StatusChip, } from "./container-card-shared.js";
11
+ import { FIELD_ROW_CLASS } from "./container-card-table-styles.js";
12
+ import { actionRow, containerNameHeading, imageFieldLabel, imageFieldOwnLine, imageFields, imageFieldValue, rowActions, rowMain, } from "./container-card-styles.js";
13
+ import { relativeTimeLabel } from "./relative-time.js";
14
+ import { Pill } from "@deepseek-ai/dsh-client-ui-primitives";
15
+ // The packages an image was built with, or the fact that none were recorded:
16
+ // chips on their own line under the Packages label.
17
+ function Packages(props) {
18
+ const { t, packages } = props;
19
+ if (packages.length === 0)
20
+ return t("noPackages");
21
+ return (_jsx(_Fragment, { children: packages.map((pkg) => _jsx(Chip, { t: t, label: pkg }, pkg)) }));
22
+ }
23
+ // One labelled line of an image's block: the field's label, then its value. The
24
+ // class keeps the label beside the value while the block has room and stacks it
25
+ // above once it is narrow.
26
+ export function ImageField(props) {
27
+ const { label, ownLine, children } = props;
28
+ return (_jsxs("div", { className: FIELD_ROW_CLASS, children: [_jsx("span", { style: imageFieldLabel, children: label }), ownLine === true
29
+ ? _jsx("div", { style: imageFieldOwnLine, children: children })
30
+ : _jsx("span", { style: imageFieldValue, children: children })] }));
31
+ }
32
+ // ImageFacts is an image's own block: line one is the name (14/600) with its
33
+ // status chip and, for the default image, its pill; the image's own actions sit
34
+ // at the line's right end when the caller passes them. Below are one labelled
35
+ // line per fact. The action group drops below the name when it no longer fits
36
+ // beside it.
37
+ export function ImageFacts(props) {
38
+ const { t, locale, imageId, status, builtAt, source, packages, isDefault, actions, } = props;
39
+ return (_jsxs("div", { children: [_jsxs("div", { style: actionRow, children: [_jsxs("div", { style: rowMain, children: [_jsx("span", { style: containerNameHeading, children: imageId }), isDefault === true ? _jsx(Pill, { children: t("defaultImage") }) : null, _jsx(StatusChip, { tone: imageStatusTone(status), label: imageStatusLabel(t, status) })] }), actions === undefined ? null : _jsx("div", { style: rowActions, children: actions })] }), _jsxs("div", { style: imageFields, children: [builtAt === "" ? null : (_jsx(ImageField, { label: t("built"), children: _jsx("span", { title: builtAt, children: relativeTimeLabel(builtAt, locale) }) })), source === ""
40
+ ? null
41
+ : _jsx(ImageField, { label: t("parentImage"), children: source }), packages === undefined
42
+ ? null
43
+ : (_jsx(ImageField, { label: t("packages"), ownLine: true, children: _jsx(Packages, { t: t, packages: packages }) }))] })] }));
44
+ }