@exagone313/dsh-podman 1.7.0 → 1.8.1

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 +46 -28
  112. package/docs/development.zh.md +60 -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 +6 -5
@@ -1,29 +1,65 @@
1
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 container edit dialog: the whole configuration one container holds — its
6
+ // read-only name, image, environment, mounts, PATH variable additions, secret
7
+ // environment variables and published ports — in one readable surface. It is a
8
+ // pure view over the row's own draft: Discard drops it, and the dialog's one
9
+ // primary action applies it, confirmed first, naming the container. That action
10
+ // says what it does: it recreates the container when the change rebuilds it,
11
+ // and updates the running container otherwise. The row keeps the draft, so
12
+ // closing the dialog loses nothing. The shell is the shared ContainerDialog and
13
+ // the body is the shared ContainerForm, so the dialog stays the same shape as
14
+ // the Add and Create dialogs; the staged marker is the one thing it adds to
15
+ // their footer.
16
+ import { configsEqual } from "./container-card-config.js";
2
17
  import { ContainerDialog } from "./container-card-dialog.js";
3
18
  import { ContainerForm } from "./container-card-form.js";
4
- import { ConfirmButton } from "./container-card-shared.js";
19
+ import { ConfirmButton, DiscardChangesModal } from "./container-card-shared.js";
5
20
  import { Button } from "@deepseek-ai/dsh-client-ui-primitives";
21
+ import { useEffect, useState } from "react";
6
22
  export function ContainerEditModal(props) {
7
- const { t, open, container, images, volumes, secrets, busy, enabled, usable, canPublish, gatewayUnavailable, projectName, projectsRoot, directoryPicker, writable, draft, dirty, pending, marker, markerError, onBlockingError, rebuilds, recreatePending, onCreateSecret, onChange, onDiscard, onApply, onClose, } = props;
23
+ const { t, open, container, images, volumes, secrets, busy, enabled, usable, canPublish, gatewayUnavailable, projectName, projectsRoot, directoryPicker, forcedProject, writable, draft, dirty, pending, marker, markerError, onBlockingError, rebuilds, recreatePending, createVolume, onCreateSecret, onChange, onDiscard, onApply, onClose, onBack, backBaseline, } = props;
8
24
  // The one primary action names what it does: a change that rebuilds the
9
25
  // container reads as a destructive recreate, and one the running container
10
26
  // takes on its own reads as an update.
11
27
  const applyLabel = rebuilds ? t("recreateContainer") : t("updateContainer");
12
- return (_jsx(ContainerDialog, { t: t, open: open, title: t("editContainerTitle"), onClose: onClose, marker: marker, markerError: markerError, actions: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "sm", disabled: !enabled || (!dirty && !pending), onClick: onDiscard, children: t("discard") }), _jsx(ConfirmButton, { t: t, label: applyLabel, variant: rebuilds ? "outline" : "primary", destructive: rebuilds, title: rebuilds ? t("recreate") : t("updateContainer"), description: rebuilds
13
- ? t("confirmRecreate", {
14
- workspace: projectName,
15
- container: container.containerName,
16
- })
17
- : t("confirmUpdate", {
18
- workspace: projectName,
19
- container: container.containerName,
20
- }), confirmLabel: applyLabel, disabled: !usable || marker === undefined || markerError === true, pending: recreatePending || busy, onConfirm: onApply })] }), children: _jsx(ContainerForm, { t: t, image: draft.image, env: draft.env, mounts: draft.mounts, paths: draft.paths, secretEnv: draft.secretEnv, ports: draft.ports, images: images, volumes: volumes, secrets: secrets, busy: busy, enabled: enabled, canPublish: canPublish, gatewayUnavailable: gatewayUnavailable, writable: writable, projectsRoot: projectsRoot, directoryPicker: directoryPicker, mainProject: projectName, primaryProject: container.containerName === "default"
21
- ? projectName
22
- : "", confirmRemoveMount: true, onCreateSecret: onCreateSecret, onChangeImage: (image) => onChange({ ...draft, image }), onChangeEnv: (env) => onChange({ ...draft, env }), onChangeMounts: (mounts) => onChange({ ...draft, mounts }), onChangePaths: (paths) => onChange({ ...draft, paths }), onChangeSecretEnv: (secretEnv) => onChange({ ...draft, secretEnv }), onChangePorts: (ports) => onChange({ ...draft, ports }), onBlockingError: onBlockingError, name: {
23
- /* A container's name is its identity, so the group states it. */
24
- value: container.containerName,
25
- error: "",
26
- readOnly: true,
27
- disabled: false,
28
- } }) }));
28
+ // Back drops the editor's draft, so a draft that no longer matches the one
29
+ // the template supplied is confirmed first; an untouched draft goes straight
30
+ // back and leaves the popup's own edits intact.
31
+ const [confirmBack, setConfirmBack] = useState(false);
32
+ const backDirty = backBaseline !== undefined &&
33
+ !configsEqual(draft, backBaseline);
34
+ useEffect(() => {
35
+ if (!open)
36
+ setConfirmBack(false);
37
+ }, [open]);
38
+ const requestBack = () => {
39
+ if (backDirty)
40
+ setConfirmBack(true);
41
+ else
42
+ onBack?.();
43
+ };
44
+ const discardAndBack = () => {
45
+ setConfirmBack(false);
46
+ onBack?.();
47
+ };
48
+ return (_jsxs(_Fragment, { children: [_jsx(ContainerDialog, { t: t, open: open, title: t("editContainerTitle"), onClose: onClose, marker: marker, markerError: markerError, actions: _jsxs(_Fragment, { children: [onBack === undefined ? null : (_jsx(Button, { variant: "outline", size: "sm", onClick: requestBack, children: t("templateBack") })), _jsx(Button, { variant: "ghost", size: "sm", disabled: !enabled || (!dirty && !pending), onClick: onDiscard, children: t("discard") }), _jsx(ConfirmButton, { t: t, label: applyLabel, variant: rebuilds ? "outline" : "primary", destructive: rebuilds, title: rebuilds ? t("recreate") : t("updateContainer"), description: rebuilds
49
+ ? t("confirmRecreate", {
50
+ workspace: projectName,
51
+ container: container.containerName,
52
+ })
53
+ : t("confirmUpdate", {
54
+ workspace: projectName,
55
+ container: container.containerName,
56
+ }), confirmLabel: applyLabel, disabled: !usable || marker === undefined || markerError === true, pending: recreatePending || busy, onConfirm: onApply })] }), children: _jsx(ContainerForm, { t: t, image: draft.image, env: draft.env, mounts: draft.mounts, paths: draft.paths, secretEnv: draft.secretEnv, ports: draft.ports, images: images, volumes: volumes, secrets: secrets, busy: busy, enabled: enabled, canPublish: canPublish, gatewayUnavailable: gatewayUnavailable, writable: writable, projectsRoot: projectsRoot, directoryPicker: directoryPicker, mainProject: projectName, primaryProject: container.containerName === "default"
57
+ ? projectName
58
+ : (forcedProject ?? ""), confirmRemoveMount: true, onCreateVolume: createVolume, onCreateSecret: onCreateSecret, onChangeImage: (image) => onChange({ ...draft, image }), onChangeEnv: (env) => onChange({ ...draft, env }), onChangeMounts: (mounts) => onChange({ ...draft, mounts }), onChangePaths: (paths) => onChange({ ...draft, paths }), onChangeSecretEnv: (secretEnv) => onChange({ ...draft, secretEnv }), onChangePorts: (ports) => onChange({ ...draft, ports }), onBlockingError: onBlockingError, name: {
59
+ /* A container's name is its identity, so the group states it. */
60
+ value: container.containerName,
61
+ error: "",
62
+ readOnly: true,
63
+ disabled: false,
64
+ } }) }), _jsx(DiscardChangesModal, { t: t, open: confirmBack, onCancel: () => setConfirmBack(false), onDiscard: discardAndBack })] }));
29
65
  }
@@ -22,11 +22,20 @@ export declare function MountsEditor(props: {
22
22
  }[];
23
23
  busy: boolean;
24
24
  enabled: boolean;
25
+ writable: boolean;
26
+ onCreateVolume: (name: string) => Promise<boolean>;
27
+ onCreateSecret: (name: string, length?: number, charset?: string) => Promise<boolean>;
25
28
  projectsRoot: string;
26
29
  directoryPicker?: DirectoryPickerFace;
27
30
  confirmRemove?: boolean;
28
31
  primaryProject?: string;
29
32
  mainProject?: string;
33
+ projectPathEditable?: boolean;
34
+ rowError?: (mount: MountInput, index: number) => string | undefined;
35
+ onProjectBlur?: (index: number) => void;
36
+ onProjectBrowse?: (index: number) => void;
37
+ projectBrowseLabel?: string;
38
+ actions?: ReactNode;
30
39
  onAdd: (mount: MountInput) => void;
31
40
  onRemove: (mount: MountInput) => void;
32
41
  onUpdate?: (mount: MountInput, index: number) => void;
@@ -2,15 +2,17 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
2
2
  // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
3
3
  //
4
4
  // SPDX-License-Identifier: MIT
5
- import { DiscardChangesModal, emptyMount, EnvRow, MountRow, orderedMounts, } from "./container-card-shared.js";
5
+ import { DiscardChangesModal, emptyMount, EnvRow, mountDestination, MountRow, } from "./container-card-shared.js";
6
+ import { isPrimaryProjectMount, orderedMounts } from "../mount-order.js";
7
+ import { nonProjectDestinationError, withPreselectedStorageSource, } from "./container-card-mount-sources.js";
6
8
  import { imageSelect } from "./container-card-styles.js";
7
9
  import { ROW_LIST_CLASS } from "./container-card-table-styles.js";
8
10
  import { mountInputsEqual, recordsEqual } from "./container-card-config.js";
9
11
  import { DirectoryPickerModal } from "./container-card-directory.js";
10
12
  import { conflictingEnvNames, emptyEnvRow, envEditRows, envRecordFromRows, firstDuplicateEnvName, } from "../env-rows.js";
11
- import { hostPathForProjectName, projectNameFromHostPath, } from "../project-path.js";
13
+ import { decideProjectPath, hostPathForProjectName, projectNameFromHostPath, } from "../project-path.js";
12
14
  import { Button, Modal } from "@deepseek-ai/dsh-client-ui-primitives";
13
- import { useEffect, useMemo, useState } from "react";
15
+ import { useEffect, useMemo, useRef, useState } from "react";
14
16
  export function EnvEditor(props) {
15
17
  const { t, env, busy, onChange, onBlockingError, otherNames, onNames } = props;
16
18
  // The rows are the editor's own: a row keeps its place while its key is
@@ -75,56 +77,286 @@ export function EnvEditor(props) {
75
77
  return (_jsx(EnvRow, { t: t, mode: "edit", name: row.key, value: row.value, disabled: busy, autoFocus: row.id === focusId, keyInvalid: conflicts.has(row.key), onChangeName: (key) => updateKey(row.id, key), onChangeValue: (value) => updateValue(row.id, value), onRemove: () => remove(row.id), removeLabel: removeLabel }, row.id));
76
78
  }), _jsx("div", { children: _jsx(Button, { variant: "outline", size: "sm", disabled: busy, onClick: add, children: t("addEnv") }) })] }));
77
79
  }
78
- // The destination a mount row shows for a mount: a project mount's derived
79
- // mirror under the projects root, or the destination the other kinds carry.
80
- function mountDestination(mount, projectsRoot) {
81
- if (mount.kind !== "project")
82
- return mount.destination;
83
- return mount.project.trim() === ""
84
- ? ""
85
- : hostPathForProjectName(projectsRoot, mount.project);
80
+ // The inline error a refused typed project path raises. The path's shape and
81
+ // its existence are different mistakes, so they get different wording.
82
+ function projectPathError(t, reason) {
83
+ return t(reason === "missing"
84
+ ? "mountProjectPathMissing"
85
+ : "mountProjectPathInvalid");
86
+ }
87
+ // projectDirectoryExists asks the dsh host's own directory picker whether
88
+ // projectsRoot/<project> is an existing directory. It is the service Browse
89
+ // lists through — host filesystem access, never the container, the pod, the
90
+ // guest agent or the orchestrator.
91
+ async function projectDirectoryExists(picker, projectsRoot, project) {
92
+ try {
93
+ await picker.list(hostPathForProjectName(projectsRoot, project));
94
+ return true;
95
+ }
96
+ catch {
97
+ return false;
98
+ }
86
99
  }
87
100
  export function MountsEditor(props) {
88
- const { t, mounts, volumes, secrets, busy, enabled, projectsRoot, directoryPicker, confirmRemove, primaryProject = "", mainProject = "", onAdd, onRemove, onUpdate, } = props;
101
+ const { t, mounts, volumes, secrets, busy, enabled, writable, onCreateVolume, onCreateSecret, projectsRoot, directoryPicker, confirmRemove, primaryProject = "", mainProject = "", projectPathEditable, rowError, onProjectBlur, onProjectBrowse, projectBrowseLabel, actions, onAdd, onRemove, onUpdate, } = props;
89
102
  const [adding, setAdding] = useState(false);
90
103
  const [browsing, setBrowsing] = useState(false);
91
104
  const [browseError, setBrowseError] = useState("");
92
105
  const [confirmClose, setConfirmClose] = useState(false);
93
106
  const [draft, setDraft] = useState(emptyMount());
107
+ // The storage lists may fill or change while the popup stays open — a storage
108
+ // created from it appears in one of them — so an empty draft adopts the first
109
+ // entry of the list its kind reads, exactly what the picker shows. A value
110
+ // already chosen is never replaced.
111
+ useEffect(() => {
112
+ if (!adding)
113
+ return;
114
+ setDraft((previous) => withPreselectedStorageSource(previous, volumes, secrets));
115
+ }, [adding, volumes, secrets]);
116
+ // Where the draft's project path came from: typing it arms the host check on
117
+ // submit, while a Browse pick skips it.
118
+ const [projectOrigin, setProjectOrigin] = useState("typed");
119
+ // Whether the host check a submit started is still running, and a token that
120
+ // invalidates its result once the popup closes, another submit starts or the
121
+ // draft's project path changes.
122
+ const [checking, setChecking] = useState(false);
123
+ const checkToken = useRef(0);
124
+ // The host's answer to the draft project path the field last listed on blur:
125
+ // the value it was started for, so an answer never marks a newer value, and
126
+ // whether the directory was missing. `listing` blocks Add while the host is
127
+ // still answering.
128
+ const [projectListing, setProjectListing] = useState(undefined);
129
+ const [listing, setListing] = useState(false);
130
+ // Whether the project field has been left or typed into, so an empty value
131
+ // stays quiet until the user has actually made a choice.
132
+ const [projectTouched, setProjectTouched] = useState(false);
133
+ // The listed rows live in memoized components, so their callbacks keep one
134
+ // identity for as long as the list has the same length. Each callback reads
135
+ // the row and the parent's handler through refs, which therefore always point
136
+ // at the latest render: editing one row re-renders that row alone.
137
+ const mountsRef = useRef(mounts);
138
+ mountsRef.current = mounts;
139
+ const onUpdateRef = useRef(onUpdate);
140
+ onUpdateRef.current = onUpdate;
141
+ const onRemoveRef = useRef(onRemove);
142
+ onRemoveRef.current = onRemove;
143
+ const onProjectBlurRef = useRef(onProjectBlur);
144
+ onProjectBlurRef.current = onProjectBlur;
145
+ const onProjectBrowseRef = useRef(onProjectBrowse);
146
+ onProjectBrowseRef.current = onProjectBrowse;
147
+ const rowCallbacks = useMemo(() => Array.from({ length: mounts.length }, (_, index) => ({
148
+ update: (patch) => {
149
+ const mount = mountsRef.current[index];
150
+ if (mount === undefined)
151
+ return;
152
+ onUpdateRef.current?.({ ...mount, ...patch }, index);
153
+ },
154
+ remove: () => {
155
+ const mount = mountsRef.current[index];
156
+ if (mount !== undefined)
157
+ onRemoveRef.current(mount);
158
+ },
159
+ blur: () => {
160
+ onProjectBlurRef.current?.(index);
161
+ },
162
+ browse: () => {
163
+ onProjectBrowseRef.current?.(index);
164
+ },
165
+ })), [mounts.length]);
94
166
  const updateDraft = (patch) => {
167
+ if (patch.project !== undefined) {
168
+ // A new value invalidates the host answer and listing the previous one
169
+ // held: a stale answer must never mark the value on screen. An empty
170
+ // value is not a mistake while it is being retyped, so only a non-empty
171
+ // one counts as touched; leaving the field is what reports emptiness.
172
+ checkToken.current += 1;
173
+ setProjectOrigin("typed");
174
+ setProjectListing(undefined);
175
+ setListing(false);
176
+ setProjectTouched(patch.project !== "");
177
+ setBrowseError("");
178
+ }
95
179
  setDraft((prev) => ({ ...prev, ...patch }));
96
180
  };
97
181
  // Picking a kind is not an edit; anything typed into the pristine kind's
98
- // fields is, and closing then would lose it.
99
- const dirty = !mountInputsEqual(draft, emptyMount(draft.kind));
182
+ // fields is, and closing then would lose it. The first storage a kind
183
+ // preselects is not an edit either, so the pristine draft carries it too.
184
+ const dirty = !mountInputsEqual(draft, withPreselectedStorageSource(emptyMount(draft.kind), volumes, secrets));
185
+ const closeAdd = () => {
186
+ checkToken.current += 1;
187
+ setChecking(false);
188
+ setListing(false);
189
+ setAdding(false);
190
+ };
100
191
  const requestClose = () => {
101
192
  if (dirty)
102
193
  setConfirmClose(true);
103
194
  else
104
- setAdding(false);
195
+ closeAdd();
105
196
  };
106
197
  const discardAndClose = () => {
107
198
  setConfirmClose(false);
108
- setAdding(false);
199
+ closeAdd();
109
200
  };
110
- const canAdd = draft.kind === "project"
111
- ? draft.project.trim() !== ""
112
- : draft.kind === "volume"
113
- ? draft.volume !== ""
114
- : draft.kind === "secret"
115
- ? draft.secret !== ""
116
- : true;
201
+ // A volume, secret or tmpfs destination is validated while it is typed, the
202
+ // same rule the host applies: an empty, relative, unclean or overlapping
203
+ // destination refuses Add and says why under the row. A project mount derives
204
+ // its destination, so it is never checked here.
205
+ const draftDestination = nonProjectDestinationError(draft.kind, draft.destination, projectsRoot);
206
+ const draftDestinationError = draftDestination === undefined
207
+ ? undefined
208
+ : t(draftDestination.key, draftDestination.params);
209
+ // The draft's project path is judged lexically as it is typed, with the same
210
+ // pure decision the submit makes; its directory is listed only on blur. A
211
+ // project mount derives its destination, so the destination rule never
212
+ // applies to it, and the other kinds never carry a project path.
213
+ const draftProjectDecision = draft.kind === "project"
214
+ ? decideProjectPath({
215
+ origin: projectOrigin,
216
+ project: draft.project,
217
+ directoryExists: true,
218
+ })
219
+ : undefined;
220
+ const draftProjectMissing = draft.kind === "project" &&
221
+ projectOrigin === "typed" &&
222
+ projectListing !== undefined &&
223
+ projectListing.project === draft.project &&
224
+ projectListing.missing;
225
+ // The row's one error slot carries the project wording for a project mount
226
+ // and the destination wording for every other kind. An empty project path
227
+ // stays quiet until the field is touched, since it is a choice still to
228
+ // make; every other refusal reports itself as it is typed or listed.
229
+ let draftProjectError;
230
+ if (draft.kind === "project" && draftProjectDecision !== undefined) {
231
+ if (!draftProjectDecision.ok) {
232
+ if (draftProjectDecision.reason !== "empty" || projectTouched) {
233
+ draftProjectError = projectPathError(t, draftProjectDecision.reason);
234
+ }
235
+ }
236
+ else if (draftProjectMissing) {
237
+ draftProjectError = t("mountProjectPathMissing");
238
+ }
239
+ }
240
+ const draftError = draft.kind === "project"
241
+ ? draftProjectError
242
+ : draftDestinationError;
243
+ // Add is refused while the project path is lexically invalid, after the host
244
+ // reported its directory missing, and while a listing is still running. The
245
+ // submit-time check below stays the final gate.
246
+ const canAdd = draftDestination === undefined &&
247
+ (draft.kind === "project"
248
+ ? draftProjectDecision?.ok === true && !draftProjectMissing && !listing
249
+ : draft.kind === "volume"
250
+ ? draft.volume !== ""
251
+ : draft.kind === "secret"
252
+ ? draft.secret !== ""
253
+ : true);
117
254
  const openAdd = () => {
118
- setDraft(emptyMount());
255
+ checkToken.current += 1;
256
+ setDraft(withPreselectedStorageSource(emptyMount(), volumes, secrets));
257
+ setProjectOrigin("typed");
258
+ setChecking(false);
259
+ setProjectListing(undefined);
260
+ setListing(false);
261
+ setProjectTouched(false);
119
262
  setBrowseError("");
120
263
  setConfirmClose(false);
121
264
  setAdding(true);
122
265
  };
123
- const submit = () => {
124
- if (!canAdd)
266
+ // A typed project path is listed against the host's directory picker when
267
+ // the field loses focus, never on a keystroke: the lexical decision already
268
+ // covers the shape, and only the host knows whether the directory exists. A
269
+ // browsed path names a directory the picker already listed, and a deployment
270
+ // without a picker cannot check one, so both skip the listing and the
271
+ // submit-time check stays the final gate.
272
+ const checkDraftProject = async () => {
273
+ setProjectTouched(true);
274
+ const decision = decideProjectPath({
275
+ origin: projectOrigin,
276
+ project: draft.project,
277
+ directoryExists: true,
278
+ });
279
+ if (draft.kind !== "project" ||
280
+ projectOrigin === "browsed" ||
281
+ !decision.ok ||
282
+ directoryPicker === undefined ||
283
+ checking) {
125
284
  return;
126
- onAdd(draft);
127
- setAdding(false);
285
+ }
286
+ const project = draft.project;
287
+ const token = ++checkToken.current;
288
+ setListing(true);
289
+ try {
290
+ const exists = await projectDirectoryExists(directoryPicker, projectsRoot, project);
291
+ // The popup closed, a submit started or the value changed while the host
292
+ // listed it: this answer belongs to no draft on screen.
293
+ if (token !== checkToken.current)
294
+ return;
295
+ setProjectListing({ project, missing: !exists });
296
+ }
297
+ catch {
298
+ // A listing that fails outright says nothing about the path, so the
299
+ // value stays unchecked and the submit-time check decides.
300
+ }
301
+ finally {
302
+ if (token === checkToken.current)
303
+ setListing(false);
304
+ }
305
+ };
306
+ // A typed project path is checked against the host on submit: a value chosen
307
+ // through Browse already names a listed directory and skips the check, and a
308
+ // deployment without a directory picker cannot check one, so the orchestrator
309
+ // still enforces it at apply time. The check never reaches the container, the
310
+ // pod, the guest agent or the orchestrator.
311
+ const submit = async () => {
312
+ if (!canAdd || checking)
313
+ return;
314
+ const token = ++checkToken.current;
315
+ setChecking(true);
316
+ try {
317
+ // Only a project mount carries a path to check; the other kinds are
318
+ // added as they are.
319
+ let mount = draft;
320
+ if (draft.kind === "project") {
321
+ let decision = decideProjectPath({
322
+ origin: projectOrigin,
323
+ project: draft.project,
324
+ directoryExists: true,
325
+ });
326
+ if (!decision.ok) {
327
+ setBrowseError(projectPathError(t, decision.reason));
328
+ return;
329
+ }
330
+ if (projectOrigin === "typed" && directoryPicker !== undefined) {
331
+ const directoryExists = await projectDirectoryExists(directoryPicker, projectsRoot, draft.project);
332
+ // The popup closed or another submit started while the host listed
333
+ // the directory: this result no longer belongs to the draft on
334
+ // screen.
335
+ if (token !== checkToken.current)
336
+ return;
337
+ decision = decideProjectPath({
338
+ origin: projectOrigin,
339
+ project: draft.project,
340
+ directoryExists,
341
+ });
342
+ }
343
+ if (!decision.ok) {
344
+ setBrowseError(projectPathError(t, decision.reason));
345
+ return;
346
+ }
347
+ mount = decision.project === draft.project
348
+ ? draft
349
+ : { ...draft, project: decision.project };
350
+ }
351
+ setBrowseError("");
352
+ onAdd(mount);
353
+ closeAdd();
354
+ }
355
+ finally {
356
+ // A stale submit must not clear the state of the one that replaced it.
357
+ if (token === checkToken.current)
358
+ setChecking(false);
359
+ }
128
360
  };
129
361
  // The destination a project mount lands at: its project path mirrored under
130
362
  // the projects root, which the host computes and the editor previews. The
@@ -133,30 +365,55 @@ export function MountsEditor(props) {
133
365
  ? ""
134
366
  : hostPathForProjectName(projectsRoot, draft.project);
135
367
  return (_jsxs("div", { className: ROW_LIST_CLASS, style: { display: "flex", flexDirection: "column", gap: "8px" }, children: [orderedMounts(mounts, mainProject).map(({ mount, index }) => {
136
- const removable = mount.kind !== "project" ||
137
- primaryProject === "" ||
138
- mount.project !== primaryProject;
139
- const update = (patch) => {
140
- onUpdate?.({ ...mount, ...patch }, index);
141
- };
368
+ // The workspace's own project mount is the one row a container's
369
+ // editor locks; every other mount stays removable.
370
+ const removable = !isPrimaryProjectMount(mount, primaryProject);
371
+ const callbacks = rowCallbacks[index];
142
372
  return (_jsx(MountRow
143
373
  // A mount keeps the index it has in the draft as its key, so a
144
374
  // category change reorders the list without remounting the row.
145
- , { t: t, mode: "edit", mount: mount, destination: mountDestination(mount, projectsRoot), disabled: !enabled, volumes: volumes, secrets: secrets, onUpdate: update, onRemove: removable ? () => onRemove(mount) : undefined, confirmRemove: confirmRemove, removeDisabledReason: removable
375
+ , { t: t, mode: "edit", mount: mount, destination: mountDestination(mount, projectsRoot), disabled: !enabled, volumes: volumes, secrets: secrets, onUpdate: callbacks.update, writable: writable, busy: busy, onRemove: removable ? callbacks.remove : undefined, confirmRemove: confirmRemove, removeDisabledReason: removable
376
+ ? undefined
377
+ : t("defaultMountNotRemovable"), error: rowError?.(mount, index), onProjectBlur: onProjectBlur === undefined
378
+ ? undefined
379
+ : callbacks.blur, onProjectBrowse: onProjectBrowse === undefined
146
380
  ? undefined
147
- : t("defaultMountNotRemovable") }, index));
148
- }), _jsx("div", { children: _jsx(Button, { variant: "outline", size: "sm", disabled: !enabled, onClick: openAdd, children: t("addMount") }) }), _jsx(Modal, { open: adding, onClose: requestClose, title: t("addMount"), closeLabel: t("cancel"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", size: "sm", onClick: requestClose, children: t("cancel") }), _jsx(Button, { variant: "primary", size: "sm", disabled: busy || !canAdd, onClick: submit, children: t("addMount") })] }), children: _jsx(MountRow, { t: t, mode: "edit", mount: draft, destination: draft.kind === "project"
149
- ? projectDestination
150
- : draft.destination, kindValue: _jsxs("select", { style: imageSelect, value: draft.kind, disabled: busy, "aria-label": t("mountKind"), onChange: (event) => setDraft(emptyMount(event.target.value)), children: [_jsx("option", { value: "project", children: t("mountProject") }), _jsx("option", { value: "tmpfs", children: t("mountTmpfs") }), _jsx("option", { value: "volume", children: t("mountVolume") }), _jsx("option", { value: "secret", children: t("mountSecret") })] }), disabled: busy, volumes: volumes, secrets: secrets, onUpdate: updateDraft, onBrowse: directoryPicker === undefined ? undefined : () => {
151
- setBrowseError("");
152
- setBrowsing(true);
153
- }, browseError: browseError }) }), _jsx(DiscardChangesModal, { t: t, open: confirmClose, onCancel: () => setConfirmClose(false), onDiscard: discardAndClose }), directoryPicker === undefined ? null : (_jsx(DirectoryPickerModal, { t: t, open: browsing, root: projectsRoot, start: hostPathForProjectName(projectsRoot, draft.project), picker: directoryPicker, onSelect: (path) => {
381
+ : callbacks.browse, projectBrowseLabel: projectBrowseLabel, projectPathLocked: projectPathEditable !== true }, index));
382
+ }), _jsxs("div", { style: actions === undefined ? undefined : {
383
+ display: "flex",
384
+ flexWrap: "wrap",
385
+ alignItems: "center",
386
+ gap: "8px",
387
+ }, children: [_jsx(Button, { variant: "outline", size: "sm", disabled: !enabled, onClick: openAdd, children: t("addMount") }), actions ?? null] }), _jsx(Modal, { open: adding, onClose: requestClose, title: t("addMount"), closeLabel: t("cancel"), footer: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "outline", size: "sm", onClick: requestClose, children: t("cancel") }), _jsx(Button, { variant: "primary", size: "sm", disabled: busy || !canAdd || checking, onClick: () => void submit(), children: t("addMount") })] }), children: _jsx("div", { style: { display: "flex", flexDirection: "column", gap: "8px" }, children: _jsx(MountRow, { t: t, mode: "edit", mount: draft, destination: draft.kind === "project"
388
+ ? projectDestination
389
+ : draft.destination, kindValue: _jsxs("select", { style: imageSelect, value: draft.kind, disabled: busy || checking, "aria-label": t("mountKind"), onChange: (event) => {
390
+ const next = emptyMount(event.target.value);
391
+ setDraft(withPreselectedStorageSource(next, volumes, secrets));
392
+ // Another kind has another source and destination to judge;
393
+ // the previous project answer and message do not carry over.
394
+ checkToken.current += 1;
395
+ setProjectOrigin("typed");
396
+ setProjectListing(undefined);
397
+ setListing(false);
398
+ setProjectTouched(false);
399
+ setBrowseError("");
400
+ }, children: [_jsx("option", { value: "project", children: t("mountProject") }), _jsx("option", { value: "tmpfs", children: t("mountTmpfs") }), _jsx("option", { value: "volume", children: t("mountVolume") }), _jsx("option", { value: "secret", children: t("mountSecret") })] }), disabled: busy || checking, volumes: volumes, secrets: secrets, onUpdate: updateDraft, writable: writable, busy: busy, error: draftError, onProjectBlur: () => void checkDraftProject(), onCreateVolume: onCreateVolume, onCreateSecret: onCreateSecret, onBrowse: directoryPicker === undefined ? undefined : () => {
401
+ setBrowseError("");
402
+ setBrowsing(true);
403
+ }, browseError: browseError }) }) }), _jsx(DiscardChangesModal, { t: t, open: confirmClose, onCancel: () => setConfirmClose(false), onDiscard: discardAndClose }), directoryPicker === undefined ? null : (_jsx(DirectoryPickerModal, { t: t, open: browsing, root: projectsRoot, start: hostPathForProjectName(projectsRoot, draft.project), picker: directoryPicker, onSelect: (path) => {
154
404
  const project = projectNameFromHostPath(projectsRoot, path);
155
405
  if (project === undefined) {
156
406
  setBrowseError(t("browseOutsideRoot"));
157
407
  return;
158
408
  }
159
- updateDraft({ project });
409
+ setDraft((previous) => ({ ...previous, project }));
410
+ setProjectOrigin("browsed");
411
+ // A browsed path names a directory the picker just listed: it is
412
+ // checked already, and any listing for the typed value is stale.
413
+ checkToken.current += 1;
414
+ setProjectListing(undefined);
415
+ setListing(false);
416
+ setProjectTouched(false);
160
417
  setBrowseError("");
161
418
  setBrowsing(false);
162
419
  }, onClose: () => setBrowsing(false) }))] }));
@@ -35,7 +35,8 @@ export declare function ContainerForm(props: {
35
35
  mainProject: string;
36
36
  primaryProject?: string;
37
37
  confirmRemoveMount?: boolean;
38
- onCreateSecret: (name: string, length?: number, charset?: string) => void;
38
+ onCreateVolume: (name: string) => Promise<boolean>;
39
+ onCreateSecret: (name: string, length?: number, charset?: string) => Promise<boolean>;
39
40
  onChangeImage: (image: string) => void;
40
41
  onChangeEnv: (env: Record<string, string>) => void;
41
42
  onChangeMounts: (mounts: MountInput[]) => void;
@@ -1,7 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { EnvEditor, MountsEditor } from "./container-card-editors.js";
3
+ import { firstMountDestinationError, nonProjectDestinationError, } from "./container-card-mount-sources.js";
3
4
  import { PathsEditor } from "./container-card-paths.js";
4
5
  import { PortsEditor } from "./container-card-ports.js";
6
+ import { buildParentImages } from "./container-card-ptc.js";
5
7
  import { SecretEnvEditor } from "./container-card-secrets.js";
6
8
  import { DialogGroup, ImageRow, LockGlyph } from "./container-card-shared.js";
7
9
  import { FIELD_CLASS } from "./container-card-field-styles.js";
@@ -17,11 +19,12 @@ const dialogBody = {
17
19
  gap: "20px",
18
20
  };
19
21
  export function ContainerForm(props) {
20
- const { t, image, env, mounts, paths, secretEnv, ports, images, volumes, secrets, busy, enabled, canPublish, gatewayUnavailable, writable, projectsRoot, directoryPicker, mainProject, primaryProject, confirmRemoveMount, onCreateSecret, onChangeImage, onChangeEnv, onChangeMounts, onChangePaths, onChangeSecretEnv, onChangePorts, name, onBlockingError, } = props;
22
+ const { t, image, env, mounts, paths, secretEnv, ports, images, volumes, secrets, busy, enabled, canPublish, gatewayUnavailable, writable, projectsRoot, directoryPicker, mainProject, primaryProject, confirmRemoveMount, onCreateVolume, onCreateSecret, onChangeImage, onChangeEnv, onChangeMounts, onChangePaths, onChangeSecretEnv, onChangePorts, name, onBlockingError, } = props;
21
23
  const nameId = useId();
22
24
  // The two variable editors report their own appended row here; the form keeps
23
25
  // both so the first one names the reason, and bubbles it to the dialog's
24
- // footer action.
26
+ // footer action. A refused mount destination is folded in from the mounts
27
+ // below, so the same footer refuses the action too.
25
28
  const [blocking, setBlocking] = useState({});
26
29
  const reportEnv = useCallback((error) => {
27
30
  setBlocking((current) => current.env === error ? current : { ...current, env: error });
@@ -29,7 +32,19 @@ export function ContainerForm(props) {
29
32
  const reportSecretEnv = useCallback((error) => {
30
33
  setBlocking((current) => current.secretEnv === error ? current : { ...current, secretEnv: error });
31
34
  }, []);
32
- const blockingKey = blocking.env ?? blocking.secretEnv;
35
+ // A volume, secret or tmpfs row's destination is validated from the form's
36
+ // current mounts, so the row error and the footer reason never disagree. A
37
+ // project mount derives its destination and is exempt.
38
+ const reportMountError = useCallback((mount) => {
39
+ const error = nonProjectDestinationError(mount.kind, mount.destination, projectsRoot);
40
+ return error === undefined ? undefined : t(error.key, error.params);
41
+ }, [projectsRoot, t]);
42
+ // The first refused destination names the footer reason only when no variable
43
+ // editor already does: fixing the destination must not clear — or be hidden by
44
+ // — another field's blocking error.
45
+ const mountDestinationBlocking = firstMountDestinationError(mounts, projectsRoot);
46
+ const blockingKey = blocking.env ?? blocking.secretEnv ??
47
+ mountDestinationBlocking;
33
48
  useEffect(() => {
34
49
  onBlockingError?.(blockingKey);
35
50
  return () => onBlockingError?.(undefined);
@@ -46,16 +61,19 @@ export function ContainerForm(props) {
46
61
  setRowNames((current) => current.secretEnv === names ? current : { ...current, secretEnv: names });
47
62
  }, []);
48
63
  // The candidate images in the order the Images tab lists them: base images
49
- // first, custom ones after. An image the snapshot no longer lists stays
50
- // selectable rather than silently replaced by the first candidate.
64
+ // first, custom ones after, and never the reserved PTC image the orchestrator
65
+ // owns. An image the snapshot no longer lists stays selectable rather than
66
+ // silently replaced by the first candidate, so a container already running
67
+ // the PTC image keeps showing it as its current value.
68
+ const offered = buildParentImages(images);
51
69
  const candidates = [
52
- ...images.filter((candidate) => candidate.isBase),
53
- ...images.filter((candidate) => !candidate.isBase),
70
+ ...offered.filter((candidate) => candidate.isBase),
71
+ ...offered.filter((candidate) => !candidate.isBase),
54
72
  ].map((candidate) => candidate.imageId);
55
73
  return (_jsxs("div", { style: dialogBody, children: [_jsxs(DialogGroup, { title: t("containerName"), children: [_jsx(Input, { id: nameId,
56
74
  // A container's fixed identity sits on the read-only field's own
57
75
  // surface, so the dialog shows it is not a value being chosen.
58
76
  className: name.readOnly ? FIELD_CLASS : undefined, icon: name.readOnly ? _jsx(LockGlyph, {}) : undefined, value: name.value, readOnly: name.readOnly, disabled: name.disabled, "aria-label": t("containerName"), onChange: (event) => name.onChange?.(event.target.value) }), name.error === ""
59
77
  ? null
60
- : (_jsx("p", { style: { ...hint, margin: 0 }, role: "alert", children: name.error }))] }), _jsx(ImageRow, { t: t, mode: "edit", image: image, candidates: candidates, disabled: !enabled, onChange: onChangeImage }), _jsx(DialogGroup, { title: t("envTitle"), children: _jsx(EnvEditor, { t: t, env: env, busy: busy, onChange: onChangeEnv, onBlockingError: reportEnv, otherNames: rowNames.secretEnv, onNames: reportEnvNames }) }), _jsx(DialogGroup, { title: t("mountsTitle"), children: _jsx(MountsEditor, { t: t, mounts: mounts, volumes: volumes, secrets: secrets, busy: busy, enabled: enabled, projectsRoot: projectsRoot, directoryPicker: directoryPicker, confirmRemove: confirmRemoveMount, primaryProject: primaryProject, mainProject: mainProject, onAdd: (mount) => onChangeMounts([...mounts, mount]), onRemove: (mount) => onChangeMounts(mounts.filter((item) => item !== mount)), onUpdate: (mount, index) => onChangeMounts(mounts.map((item, at) => (at === index ? mount : item))) }) }), _jsx(DialogGroup, { title: t("pathsTitle"), children: _jsx(PathsEditor, { t: t, paths: paths, busy: busy, enabled: enabled, onApply: onChangePaths }) }), _jsx(DialogGroup, { title: t("containerSecretsTitle"), children: _jsx(SecretEnvEditor, { t: t, secretEnv: secretEnv, secrets: secrets, busy: busy, enabled: enabled, writable: writable, onCreateSecret: onCreateSecret, onChange: onChangeSecretEnv, onBlockingError: reportSecretEnv, otherNames: rowNames.env, onNames: reportSecretEnvNames }) }), _jsx(DialogGroup, { title: t("portsTitle"), children: _jsx(PortsEditor, { t: t, ports: ports, busy: busy, enabled: enabled, canPublish: canPublish, gatewayUnavailable: gatewayUnavailable, onChange: onChangePorts }) })] }));
78
+ : (_jsx("p", { style: { ...hint, margin: 0 }, role: "alert", children: name.error }))] }), _jsx(ImageRow, { t: t, mode: "edit", image: image, candidates: candidates, disabled: !enabled, onChange: onChangeImage }), _jsx(DialogGroup, { title: t("envTitle"), children: _jsx(EnvEditor, { t: t, env: env, busy: busy, onChange: onChangeEnv, onBlockingError: reportEnv, otherNames: rowNames.secretEnv, onNames: reportEnvNames }) }), _jsx(DialogGroup, { title: t("mountsTitle"), children: _jsx(MountsEditor, { t: t, mounts: mounts, volumes: volumes, secrets: secrets, busy: busy, enabled: enabled, writable: writable, projectsRoot: projectsRoot, directoryPicker: directoryPicker, confirmRemove: confirmRemoveMount, primaryProject: primaryProject, mainProject: mainProject, rowError: reportMountError, onCreateVolume: onCreateVolume, onCreateSecret: onCreateSecret, onAdd: (mount) => onChangeMounts([...mounts, mount]), onRemove: (mount) => onChangeMounts(mounts.filter((item) => item !== mount)), onUpdate: (mount, index) => onChangeMounts(mounts.map((item, at) => (at === index ? mount : item))) }) }), _jsx(DialogGroup, { title: t("pathsTitle"), children: _jsx(PathsEditor, { t: t, paths: paths, busy: busy, enabled: enabled, onApply: onChangePaths }) }), _jsx(DialogGroup, { title: t("containerSecretsTitle"), children: _jsx(SecretEnvEditor, { t: t, secretEnv: secretEnv, secrets: secrets, busy: busy, enabled: enabled, writable: writable, onCreateSecret: onCreateSecret, onChange: onChangeSecretEnv, onBlockingError: reportSecretEnv, otherNames: rowNames.env, onNames: reportSecretEnvNames }) }), _jsx(DialogGroup, { title: t("portsTitle"), children: _jsx(PortsEditor, { t: t, ports: ports, busy: busy, enabled: enabled, canPublish: canPublish, gatewayUnavailable: gatewayUnavailable, onChange: onChangePorts }) })] }));
61
79
  }