@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
package/cordis.patch.yml CHANGED
@@ -44,7 +44,9 @@
44
44
  You manage container infrastructure through the dsh-podman tools: images
45
45
  (image_list, image_get, image_build, image_rebuild, image_rebuild_all,
46
46
  image_remove), containers (container_list, container_start,
47
- container_recreate, container_remove), mounts (container_mount_list,
47
+ container_recreate, container_remove), container templates
48
+ (container_template_load, container_template_export,
49
+ container_template_save), mounts (container_mount_list,
48
50
  container_mount_add, container_mount_remove, container_mount_update),
49
51
  PATH additions (container_path_set, container_path_add,
50
52
  container_path_remove), volumes (volume_list,
@@ -5,6 +5,33 @@ export interface MountFact {
5
5
  destination?: string;
6
6
  readOnly?: boolean;
7
7
  }
8
+ export interface TemplateImageFact {
9
+ base: string;
10
+ packages?: readonly string[];
11
+ }
12
+ export interface TemplateSecretEnvFact {
13
+ env: string;
14
+ secret: string;
15
+ }
16
+ export interface TemplatePortFact {
17
+ container: number;
18
+ host?: number;
19
+ }
20
+ export interface TemplateLoadRemovals {
21
+ mounts: number;
22
+ env: number;
23
+ secretEnv: number;
24
+ paths: number;
25
+ }
26
+ export interface TemplateLoadSummary {
27
+ image: TemplateImageFact;
28
+ mounts: readonly MountFact[];
29
+ secretEnv: readonly TemplateSecretEnvFact[];
30
+ ports: readonly TemplatePortFact[];
31
+ envCount: number;
32
+ pathCount: number;
33
+ removals: TemplateLoadRemovals;
34
+ }
8
35
  export type ReasonFact = {
9
36
  kind: "image_build";
10
37
  image: string;
@@ -29,6 +56,16 @@ export type ReasonFact = {
29
56
  } | {
30
57
  kind: "container_remove";
31
58
  container: string;
59
+ } | {
60
+ kind: "container_template_load";
61
+ template: string;
62
+ container?: string;
63
+ summary?: TemplateLoadSummary;
64
+ } | {
65
+ kind: "container_template_save";
66
+ name: string;
67
+ container: string;
68
+ path: string;
32
69
  } | {
33
70
  kind: "container_mount_add";
34
71
  container: string;
@@ -83,6 +83,115 @@ function mountText(locale, mount) {
83
83
  : pick(locale, ` (${mode})`, `(${mode})`);
84
84
  return `${mountSourceText(locale, mount)}${suffix}`;
85
85
  }
86
+ // Render one template mount compactly for the apply summary. The template
87
+ // sentences keep Chinese naming tight against its quotation marks
88
+ // (`项目“app”`), so they cannot reuse mountText's spaced labels.
89
+ function templateMountText(locale, mount) {
90
+ const name = quoted(locale, mount.source);
91
+ const destination = mount.destination === undefined
92
+ ? undefined
93
+ : quoted(locale, mount.destination);
94
+ const mode = mountModeName(locale, mount);
95
+ const suffix = mode === undefined
96
+ ? ""
97
+ : pick(locale, ` (${mode})`, `(${mode})`);
98
+ switch (mount.kind) {
99
+ case "tmpfs":
100
+ return pick(locale, `tmpfs at ${destination ?? ""}`, `tmpfs 挂载到${destination ?? ""}`);
101
+ case "volume":
102
+ return pick(locale, `volume ${name} at ${destination ?? ""}${suffix}`, `卷${name}挂载到${destination ?? ""}${suffix}`);
103
+ case "secret":
104
+ return pick(locale, `secret ${name} at ${destination ?? ""}`, `机密${name}挂载到${destination ?? ""}`);
105
+ default:
106
+ return pick(locale, `project ${name}${suffix}`, `项目${name}${suffix}`);
107
+ }
108
+ }
109
+ // Render a template's image: the base alone, or the base plus its extra
110
+ // packages.
111
+ function templateImageText(locale, image) {
112
+ const packages = image.packages ?? [];
113
+ if (packages.length === 0) {
114
+ return pick(locale, `Image: ${image.base}.`, `镜像:${image.base}。`);
115
+ }
116
+ const count = packages.length;
117
+ return pick(locale, `Image: ${image.base} plus ${count} ${count === 1 ? "package" : "packages"} (${packages.join(", ")}).`, `镜像:以 ${image.base} 为基础,另加 ${count} 个软件包(${packages.join("、")})。`);
118
+ }
119
+ // Render every mount the template stages, semicolon-separated.
120
+ function templateMountsText(locale, mounts) {
121
+ if (mounts.length === 0) {
122
+ return pick(locale, "Mounts: none.", "挂载:无。");
123
+ }
124
+ const list = mounts.map((mount) => templateMountText(locale, mount));
125
+ return pick(locale, `Mounts: ${list.join("; ")}.`, `挂载:${list.join(";")}。`);
126
+ }
127
+ // Render the template's secret environment entries, or "none" when it declares
128
+ // no secrets.
129
+ function templateSecretEnvText(locale, pairs) {
130
+ if (pairs.length === 0) {
131
+ return pick(locale, "Secret environment: none.", "机密环境变量:无。");
132
+ }
133
+ const list = pairs.map((pair) => pick(locale, `${quoted(locale, pair.env)} from secret ${quoted(locale, pair.secret)}`, `${quoted(locale, pair.env)}来自机密${quoted(locale, pair.secret)}`));
134
+ return pick(locale, `Secret environment: ${list.join("; ")}.`, `机密环境变量:${list.join(";")}。`);
135
+ }
136
+ // Render the template's published ports, omitting the host port when the
137
+ // gateway will pick one.
138
+ function templatePortsText(locale, ports) {
139
+ if (ports.length === 0) {
140
+ return pick(locale, "Ports: none.", "端口:无。");
141
+ }
142
+ const list = ports.map((port) => port.host === undefined
143
+ ? pick(locale, `container ${port.container}`, `容器 ${port.container}`)
144
+ : pick(locale, `container ${port.container} to host ${port.host}`, `容器 ${port.container} 映射到主机 ${port.host}`));
145
+ return pick(locale, `Ports: ${list.join("; ")}.`, `端口:${list.join(";")}。`);
146
+ }
147
+ // A count with its noun: `1 mount` / `2 mounts` and their Chinese unit.
148
+ function countedNoun(locale, count, singular, plural, zhUnit) {
149
+ return pick(locale, `${count} ${count === 1 ? singular : plural}`, `${count} ${zhUnit}`);
150
+ }
151
+ // Render the environment and PATH counts. A zero group is omitted; when both
152
+ // are zero the sentence is omitted entirely.
153
+ function templateCountsText(locale, envCount, pathCount) {
154
+ const env = countedNoun(locale, envCount, "variable", "variables", "个");
155
+ const paths = countedNoun(locale, pathCount, "addition", "additions", "个");
156
+ if (envCount > 0 && pathCount > 0) {
157
+ return pick(locale, `Environment: ${env}. PATH: ${paths}.`, `环境变量:${env};PATH 追加项:${paths}。`);
158
+ }
159
+ if (envCount > 0) {
160
+ return pick(locale, `Environment: ${env}.`, `环境变量:${env}。`);
161
+ }
162
+ if (pathCount > 0) {
163
+ return pick(locale, `PATH: ${paths}.`, `PATH 追加项:${paths}。`);
164
+ }
165
+ return "";
166
+ }
167
+ // Join groups the way each locale lists them: `a, b and c` / `a、b和c`.
168
+ function joinGroups(locale, groups) {
169
+ if (groups.length <= 1)
170
+ return groups.join("");
171
+ const head = groups.slice(0, -1).join(pick(locale, ", ", "、"));
172
+ const tail = groups[groups.length - 1];
173
+ return pick(locale, `${head} and ${tail}`, `${head}和 ${tail}`);
174
+ }
175
+ // Render how many current items the apply removes. Only non-zero groups are
176
+ // listed, and a zero total omits the sentence.
177
+ function templateRemovalsText(locale, removals) {
178
+ const groups = [];
179
+ if (removals.mounts > 0) {
180
+ groups.push(countedNoun(locale, removals.mounts, "mount", "mounts", "个挂载"));
181
+ }
182
+ if (removals.env > 0) {
183
+ groups.push(countedNoun(locale, removals.env, "environment variable", "environment variables", "个环境变量"));
184
+ }
185
+ if (removals.secretEnv > 0) {
186
+ groups.push(countedNoun(locale, removals.secretEnv, "secret environment variable", "secret environment variables", "个机密环境变量"));
187
+ }
188
+ if (removals.paths > 0) {
189
+ groups.push(countedNoun(locale, removals.paths, "PATH addition", "PATH additions", "个 PATH 追加项"));
190
+ }
191
+ if (groups.length === 0)
192
+ return "";
193
+ return pick(locale, `Removes ${joinGroups(locale, groups)}.`, `将移除 ${joinGroups(locale, groups)}。`);
194
+ }
86
195
  // Render a command word list, capped at 8 words with an ellipsis tail.
87
196
  function argvText(argv) {
88
197
  const shown = argv.slice(0, 8).join(" ");
@@ -141,6 +250,25 @@ export function renderReason(locale, fact) {
141
250
  return containerRun(locale, fact);
142
251
  case "container_remove":
143
252
  return pick(locale, `Remove container ${quoted(locale, fact.container)}.`, `移除容器 ${quoted(locale, fact.container)}。`);
253
+ case "container_template_load": {
254
+ const base = fact.container === undefined
255
+ ? pick(locale, `Apply container template ${quoted(locale, fact.template)} to the default container.`, `将容器模板${quoted(locale, fact.template)}应用到默认容器。`)
256
+ : pick(locale, `Apply container template ${quoted(locale, fact.template)} to container ${quoted(locale, fact.container)}.`, `将容器模板${quoted(locale, fact.template)}应用到容器${quoted(locale, fact.container)}。`);
257
+ if (fact.summary === undefined)
258
+ return base;
259
+ const summary = fact.summary;
260
+ const sentences = [
261
+ templateImageText(locale, summary.image),
262
+ templateMountsText(locale, summary.mounts),
263
+ templateSecretEnvText(locale, summary.secretEnv),
264
+ templatePortsText(locale, summary.ports),
265
+ templateCountsText(locale, summary.envCount, summary.pathCount),
266
+ templateRemovalsText(locale, summary.removals),
267
+ ].filter((sentence) => sentence !== "");
268
+ return pick(locale, [base, ...sentences].join(" "), base + sentences.join(""));
269
+ }
270
+ case "container_template_save":
271
+ return pick(locale, `Save container ${quoted(locale, fact.container)} as template ${quoted(locale, fact.name)} at ${quoted(locale, fact.path)}.`, `将容器 ${quoted(locale, fact.container)} 保存为模板 ${quoted(locale, fact.name)},路径为 ${quoted(locale, fact.path)}。`);
144
272
  case "container_mount_add":
145
273
  return pick(locale, `Add mount to container ${quoted(locale, fact.container)}: ${mountText(locale, fact.mount)}.`, `在容器 ${quoted(locale, fact.container)} 中添加挂载:${mountText(locale, fact.mount)}。`);
146
274
  case "container_publish_port": {
@@ -0,0 +1,8 @@
1
+ import type { TemplateLoadSummary } from "./approval-reasons.js";
2
+ import type { WorkspaceResolver } from "./workspace-binding.js";
3
+ export interface TemplateLoadSummaryRequest {
4
+ template: string;
5
+ container: string;
6
+ cwd?: string;
7
+ }
8
+ export declare function readTemplateLoadSummary(resolver: WorkspaceResolver, projectsRoot: string, request: TemplateLoadSummaryRequest): Promise<TemplateLoadSummary | undefined>;
@@ -0,0 +1,163 @@
1
+ // SPDX-FileCopyrightText: 2026 Elouan Martinet <exa@elou.world>
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+ // Reading what a `container_template_load` call will apply before the user
5
+ // approves it: the template's image, mounts, secret environment and ports, plus
6
+ // how many of the existing container's items the replace drops. The approval
7
+ // policy calls this async provider so the reason itself can stay synchronous.
8
+ //
9
+ // Every failure (no workspace for the session cwd, an unreadable or invalid
10
+ // template, a control error) returns undefined: the prompt then keeps its base
11
+ // sentence rather than blocking the call.
12
+ import { effectiveImage, parseContainerTemplate, templateMountInputs, withForcedProjectMount, } from "./container-template.js";
13
+ import { normalizeMountKind } from "./mount-enums.js";
14
+ import { readProjectTemplate, workspaceForCwd } from "./template-files.js";
15
+ // readTemplateLoadSummary builds the approval summary for one template apply,
16
+ // or undefined when any part of it cannot be read.
17
+ export async function readTemplateLoadSummary(resolver, projectsRoot, request) {
18
+ try {
19
+ const workspace = await workspaceForCwd(resolver.registry, projectsRoot, request.cwd);
20
+ const file = await readProjectTemplate(workspace.projectPath, request.template);
21
+ const template = parseContainerTemplate(file.yaml);
22
+ // The staged mounts are exactly what applyContainerTemplate sends: the
23
+ // template's own list plus the forced workspace project mount first.
24
+ const staged = withForcedProjectMount(templateMountInputs(template), workspace.projectName);
25
+ const current = await readCurrentContainer(resolver, workspace.workspaceSlug, request.container);
26
+ const image = effectiveImage(template);
27
+ return {
28
+ image: {
29
+ base: image.base,
30
+ ...(image.kind === "template" ? { packages: image.packages } : {}),
31
+ },
32
+ mounts: staged.map(templateMountFact),
33
+ secretEnv: Object.entries(template.spec.secretEnv).map(([env, secret]) => ({ env, secret })),
34
+ ports: template.spec.ports.map((port) => port.host === undefined
35
+ ? { container: port.container }
36
+ : { container: port.container, host: port.host }),
37
+ envCount: Object.keys(template.spec.env).length,
38
+ pathCount: template.spec.paths.length,
39
+ removals: removalCounts(staged, template, current),
40
+ };
41
+ }
42
+ catch {
43
+ return undefined;
44
+ }
45
+ }
46
+ // readCurrentContainer returns the container StartContainer will replace, or
47
+ // undefined when the workspace has none (the apply creates one, so nothing is
48
+ // removed). listContainers carries every container field; listWorkspaces only
49
+ // describes the default container, and its PATH additions are not projected
50
+ // there, so it is a fallback for a default container listContainers hides.
51
+ async function readCurrentContainer(resolver, workspaceSlug, container) {
52
+ const listed = await resolver.control("listContainers", {});
53
+ const row = (listed.containers ?? []).find((candidate) => candidate?.workspaceSlug === workspaceSlug &&
54
+ stringField(candidate?.containerName, "default") === container);
55
+ if (row !== undefined)
56
+ return row;
57
+ if (container !== "default")
58
+ return undefined;
59
+ const workspaces = await resolver.control("listWorkspaces", {});
60
+ const workspace = (workspaces.workspaces ?? []).find((candidate) => candidate?.workspaceSlug === workspaceSlug);
61
+ if (workspace === undefined)
62
+ return undefined;
63
+ return {
64
+ mounts: Array.isArray(workspace.mounts) ? workspace.mounts : [],
65
+ env: workspace.env,
66
+ secretEnv: workspace.secretEnv,
67
+ };
68
+ }
69
+ // templateMountFact renders one staged mount. Project and volume mounts carry
70
+ // the mode the template chose (defaulting read-only); secrets and tmpfs carry
71
+ // no mode.
72
+ function templateMountFact(mount) {
73
+ const readOnly = mount.mode !== "read_write";
74
+ switch (mount.kind) {
75
+ case "tmpfs":
76
+ return { kind: "tmpfs", source: "", destination: mount.destination };
77
+ case "volume":
78
+ return {
79
+ kind: "volume",
80
+ source: mount.volume,
81
+ destination: mount.destination,
82
+ readOnly,
83
+ };
84
+ case "secret":
85
+ return {
86
+ kind: "secret",
87
+ source: mount.secret,
88
+ destination: mount.destination,
89
+ };
90
+ default:
91
+ return { kind: "project", source: mount.project, readOnly };
92
+ }
93
+ }
94
+ // The identity of one mount for replacement: project mounts compare by project,
95
+ // volumes and secrets by name and destination, tmpfs by destination only.
96
+ function stagedMountKey(mount) {
97
+ switch (mount.kind) {
98
+ case "tmpfs":
99
+ return `tmpfs\0${mount.destination}`;
100
+ case "volume":
101
+ return `volume\0${mount.volume}\0${mount.destination}`;
102
+ case "secret":
103
+ return `secret\0${mount.secret}\0${mount.destination}`;
104
+ default:
105
+ return `project\0${mount.project}`;
106
+ }
107
+ }
108
+ function currentMountKey(mount) {
109
+ const kind = normalizeMountKind(mount?.kind);
110
+ switch (kind) {
111
+ case "tmpfs":
112
+ return `tmpfs\0${stringField(mount?.destination)}`;
113
+ case "volume":
114
+ return `volume\0${stringField(mount?.volume)}\0${stringField(mount?.destination)}`;
115
+ case "secret":
116
+ return `secret\0${stringField(mount?.secret)}\0${stringField(mount?.destination)}`;
117
+ default:
118
+ return `project\0${stringField(mount?.projectName)}`;
119
+ }
120
+ }
121
+ // removalCounts counts the current items absent from the staged template. A
122
+ // group the template leaves undeclared is kept by StartContainer, so its
123
+ // current values are not removed and its count stays zero.
124
+ function removalCounts(staged, template, current) {
125
+ if (current === undefined) {
126
+ return { mounts: 0, env: 0, secretEnv: 0, paths: 0 };
127
+ }
128
+ const stagedKeys = new Set(staged.map(stagedMountKey));
129
+ const currentMounts = Array.isArray(current.mounts) ? current.mounts : [];
130
+ const mounts = currentMounts.filter((mount) => !stagedKeys.has(currentMountKey(mount)))
131
+ .length;
132
+ const env = removedKeys(current.env, template.spec.env);
133
+ const secretEnv = removedKeys(current.secretEnv, template.spec.secretEnv);
134
+ const paths = removedPaths(current.paths, template.spec.paths);
135
+ return { mounts, env, secretEnv, paths };
136
+ }
137
+ // removedKeys counts the current keys a declared map does not name. An empty
138
+ // declared map means the group was not declared, so nothing is removed.
139
+ function removedKeys(current, declared) {
140
+ const declaredKeys = Object.keys(declared);
141
+ if (declaredKeys.length === 0)
142
+ return 0;
143
+ const declaredSet = new Set(declaredKeys);
144
+ return objectKeys(current).filter((key) => !declaredSet.has(key)).length;
145
+ }
146
+ // removedPaths counts the current PATH additions a declared list does not
147
+ // name. An empty list means PATH is not replaced, so nothing is removed.
148
+ function removedPaths(current, declared) {
149
+ if (declared.length === 0)
150
+ return 0;
151
+ const declaredSet = new Set(declared);
152
+ const paths = Array.isArray(current) ? current.map(String) : [];
153
+ return paths.filter((path) => !declaredSet.has(path)).length;
154
+ }
155
+ function objectKeys(value) {
156
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
157
+ return [];
158
+ }
159
+ return Object.keys(value);
160
+ }
161
+ function stringField(value, fallback = "") {
162
+ return typeof value === "string" && value !== "" ? value : fallback;
163
+ }
@@ -1,8 +1,8 @@
1
1
  import { type ReadOnlyShellDecision } from "./read-only-shell.js";
2
- import { type ReasonFact, type ReasonLocale } from "./approval-reasons.js";
2
+ import { type ReasonFact, type ReasonLocale, type TemplateLoadSummary } from "./approval-reasons.js";
3
3
  export declare function reasonFact(name: string, args: Record<string, unknown>, sessionCwd?: unknown): ReasonFact | undefined;
4
- export declare function summarizeArgs(name: string, args: Record<string, unknown>, sessionCwd?: unknown, locale?: ReasonLocale): string;
5
- export declare function approvalDecision(name: string, args?: Record<string, unknown>, sessionCwd?: unknown, locale?: ReasonLocale): {
4
+ export declare function summarizeArgs(name: string, args: Record<string, unknown>, sessionCwd?: unknown, locale?: ReasonLocale, templateSummary?: TemplateLoadSummary): string;
5
+ export declare function approvalDecision(name: string, args?: Record<string, unknown>, sessionCwd?: unknown, locale?: ReasonLocale, templateSummary?: TemplateLoadSummary): {
6
6
  kind: "ask";
7
7
  reason?: string;
8
8
  } | undefined;
@@ -23,7 +23,11 @@ export declare function preExecutePolicy(exec: {
23
23
  agent?: {
24
24
  session?: unknown;
25
25
  };
26
- }, next: () => Promise<unknown>, getProjectsRoot?: () => string, getLocale?: () => ReasonLocale, readSession?: (session: unknown) => SessionFacts, readOnlyShell?: (exec: unknown, locale: ReasonLocale) => Promise<ReadOnlyShellDecision>): Promise<unknown>;
26
+ }, next: () => Promise<unknown>, getProjectsRoot?: () => string, getLocale?: () => ReasonLocale, readSession?: (session: unknown) => SessionFacts, readOnlyShell?: (exec: unknown, locale: ReasonLocale) => Promise<ReadOnlyShellDecision>, readTemplateLoadSummary?: (request: {
27
+ template: string;
28
+ container: string;
29
+ cwd?: string;
30
+ }) => Promise<TemplateLoadSummary | undefined>): Promise<unknown>;
27
31
  export declare function mountDestinationsReason(name: string, args: Record<string, unknown> | undefined, projectsRoot: string | undefined, locale?: ReasonLocale): string | undefined;
28
32
  export declare const SANDBOX_ESCALATION_REASON_PREFIX = "escalate sandbox to ";
29
33
  export declare function isSandboxEscalation(request: unknown): boolean;
package/dist/approval.js CHANGED
@@ -2,10 +2,23 @@
2
2
  //
3
3
  // SPDX-License-Identifier: MIT
4
4
  import { approvalPath, currentCwd } from "./guest-rpc.js";
5
+ import { TEMPLATE_DIRECTORY } from "./container-template.js";
6
+ import { templateFileName } from "./template-files.js";
5
7
  import { inferMountKind, projectMountDestinationReason, } from "./mount-input.js";
6
8
  import { defaultMountMode } from "./mount-enums.js";
7
9
  import { TOOLS } from "./tool-schemas.js";
8
10
  import { renderDenial, renderReason, } from "./approval-reasons.js";
11
+ // templateFileForApproval resolves the file name a save will write without
12
+ // throwing: the prompt must render even for a name the handler is about to
13
+ // reject, so an invalid name is shown as given.
14
+ function templateFileForApproval(name) {
15
+ try {
16
+ return templateFileName(name);
17
+ }
18
+ catch {
19
+ return name;
20
+ }
21
+ }
9
22
  // Build the mount fact for one mount object, or undefined when it names no
10
23
  // source. `readOnly` is the mount's mode when the call carries one; omit it
11
24
  // when the call does not (removal), so the reason names no mode.
@@ -225,6 +238,33 @@ export function reasonFact(name, args, sessionCwd) {
225
238
  return undefined;
226
239
  return { kind: name, container, path };
227
240
  }
241
+ case "container_template_load": {
242
+ const template = str("template");
243
+ if (template === undefined)
244
+ return undefined;
245
+ const container = str("container");
246
+ return {
247
+ kind: "container_template_load",
248
+ template,
249
+ ...(container === undefined ? {} : { container }),
250
+ };
251
+ }
252
+ case "container_template_save": {
253
+ const name = str("name");
254
+ const container = str("container");
255
+ if (name === undefined || container === undefined)
256
+ return undefined;
257
+ // Show the file that will be written, not just the requested name: the
258
+ // handler appends the canonical ".yml" suffix, and a traversal attempt
259
+ // still reaches the prompt (the handler is what refuses it).
260
+ const file = templateFileForApproval(name);
261
+ return {
262
+ kind: "container_template_save",
263
+ name: file,
264
+ container,
265
+ path: approvalPath(`${TEMPLATE_DIRECTORY}/${file}`, sessionCwd),
266
+ };
267
+ }
228
268
  case "container_bash": {
229
269
  const container = str("container");
230
270
  const command = str("command");
@@ -283,16 +323,22 @@ export function reasonFact(name, args, sessionCwd) {
283
323
  //
284
324
  // sessionCwd is used to name the resolved target of a relative path, so the
285
325
  // prompt describes the file that will actually be touched. `locale` selects
286
- // the language; it defaults to English.
287
- export function summarizeArgs(name, args, sessionCwd, locale = "en") {
326
+ // the language; it defaults to English. `templateSummary` carries the
327
+ // pre-read facts of a template apply; without it the base sentence renders.
328
+ export function summarizeArgs(name, args, sessionCwd, locale = "en", templateSummary) {
288
329
  const fact = reasonFact(name, args, sessionCwd);
289
- return fact === undefined ? "" : renderReason(locale, fact);
330
+ if (fact === undefined)
331
+ return "";
332
+ const withSummary = fact.kind === "container_template_load" && templateSummary !== undefined
333
+ ? { ...fact, summary: templateSummary }
334
+ : fact;
335
+ return renderReason(locale, withSummary);
290
336
  }
291
337
  // The ask reason, omitted when no summary can be derived so the approval panel
292
338
  // shows its own localized fallback instead of a blank headline (the panel only
293
339
  // substitutes for a nullish reason, not an empty string).
294
- function askReason(name, args, sessionCwd, locale = "en") {
295
- const reason = summarizeArgs(name, args, sessionCwd, locale);
340
+ function askReason(name, args, sessionCwd, locale = "en", templateSummary) {
341
+ const reason = summarizeArgs(name, args, sessionCwd, locale, templateSummary);
296
342
  return reason === "" ? {} : { reason };
297
343
  }
298
344
  // Decide whether a tool call needs approval. DSH resolves an `ask` decision
@@ -301,15 +347,21 @@ function askReason(name, args, sessionCwd, locale = "en") {
301
347
  // Approval is per tool, optionally conditional on the call's arguments via a
302
348
  // tool's `approvalWhen` predicate (e.g. container_start only asks when project
303
349
  // mounts are supplied).
304
- export function approvalDecision(name, args, sessionCwd, locale = "en") {
350
+ export function approvalDecision(name, args, sessionCwd, locale = "en", templateSummary) {
305
351
  const tool = TOOLS.find((entry) => entry.name === name);
306
352
  if (tool === undefined)
307
353
  return undefined;
308
354
  if (tool.approval === true) {
309
- return { kind: "ask", ...askReason(name, args ?? {}, sessionCwd, locale) };
355
+ return {
356
+ kind: "ask",
357
+ ...askReason(name, args ?? {}, sessionCwd, locale, templateSummary),
358
+ };
310
359
  }
311
360
  if (tool.approvalWhen !== undefined && tool.approvalWhen(args ?? {})) {
312
- return { kind: "ask", ...askReason(name, args ?? {}, sessionCwd, locale) };
361
+ return {
362
+ kind: "ask",
363
+ ...askReason(name, args ?? {}, sessionCwd, locale, templateSummary),
364
+ };
313
365
  }
314
366
  return undefined;
315
367
  }
@@ -326,6 +378,7 @@ export const READ_ONLY_TOOLS = new Set([
326
378
  "secret_list",
327
379
  "daemon_list",
328
380
  "daemon_logs",
381
+ "container_template_export",
329
382
  ]);
330
383
  // The agent preset id this plugin ships ("Podman operator mode"). Tools in
331
384
  // PODMAN_OPS_APPROVAL_TOOLS are gated behind approval only for agents composed
@@ -358,7 +411,7 @@ const BUILTIN_FILE_TOOLS = new Set(["write", "edit", "bash", "pwsh"]);
358
411
  // - approval policy "never" (Full access): run without asking.
359
412
  // - otherwise (Workspace Write): ask for the approval-gated tools, including
360
413
  // the tools the Podman operator-mode preset gates per preset.
361
- export async function preExecutePolicy(exec, next, getProjectsRoot, getLocale, readSession, readOnlyShell) {
414
+ export async function preExecutePolicy(exec, next, getProjectsRoot, getLocale, readSession, readOnlyShell, readTemplateLoadSummary) {
362
415
  const name = exec.name;
363
416
  const locale = getLocale?.() ?? "en";
364
417
  const session = exec.agent?.session;
@@ -405,7 +458,48 @@ export async function preExecutePolicy(exec, next, getProjectsRoot, getLocale, r
405
458
  ...askReason(name, parsed ?? {}, sessionCwd, locale),
406
459
  };
407
460
  }
408
- return approvalDecision(name, parsed, sessionCwd, locale) ?? next();
461
+ const decision = approvalDecision(name, parsed, sessionCwd, locale);
462
+ if (decision === undefined)
463
+ return next();
464
+ if (name !== "container_template_load" ||
465
+ readTemplateLoadSummary === undefined) {
466
+ return decision;
467
+ }
468
+ const request = templateLoadSummaryRequest(parsed, sessionCwd);
469
+ if (request === undefined)
470
+ return decision;
471
+ let summary;
472
+ try {
473
+ summary = await readTemplateLoadSummary(request);
474
+ }
475
+ catch {
476
+ // The provider is documented to fail closed to undefined; a rejection is
477
+ // the same fallback so the prompt still renders its base sentence.
478
+ summary = undefined;
479
+ }
480
+ if (summary === undefined)
481
+ return decision;
482
+ return approvalDecision(name, parsed, sessionCwd, locale, summary) ??
483
+ decision;
484
+ }
485
+ // The template and target an apply will use, or undefined when the call carries
486
+ // no template to read. The handler treats an empty target as the default one.
487
+ function templateLoadSummaryRequest(args, sessionCwd) {
488
+ const template = typeof args?.template === "string" && args.template !== ""
489
+ ? args.template
490
+ : undefined;
491
+ if (template === undefined)
492
+ return undefined;
493
+ const container = typeof args?.container === "string" && args.container !== ""
494
+ ? args.container
495
+ : "default";
496
+ return {
497
+ template,
498
+ container,
499
+ ...(typeof sessionCwd === "string" && sessionCwd !== ""
500
+ ? { cwd: sessionCwd }
501
+ : {}),
502
+ };
409
503
  }
410
504
  // The reason to deny a mount-bearing tool call that puts a destination on a
411
505
  // project (or unnamed) mount, or undefined when the call is allowed. Checks the
@@ -165,6 +165,12 @@ export function ContainerCard(props) {
165
165
  id: tabId("status"),
166
166
  panelId: panelId("status"),
167
167
  },
168
- ] }), _jsx("div", { id: panelId("workspaces"), role: "tabpanel", "aria-labelledby": tabId("workspaces"), hidden: tab !== "workspaces", style: tab === "workspaces" ? tabPanel : undefined, children: noWorkspace ? _jsx("p", { style: hint, children: t("noWorkspaces") }) : (workspaceRows.map(({ workspace, containers }) => (_jsx(WorkspaceSection, { t: t, workspace: workspace, containers: containers, images: state.images, volumes: state.volumes, secrets: state.secrets, busy: state.busy, writable: state.writable, locale: state.locale, pendingActions: state.pendingActions, defaultImage: state.defaultImage, defaultEnv: state.containerEnv, projectsRoot: state.projectsRoot, directoryPicker: state.directoryPicker, onRemove: props.remove, onRecreate: props.recreate, onRemoveWorkspace: props.removeWorkspace, onCreate: props.createContainer, onCreateSecret: props.createSecret, onStartContainer: props.startContainer, onApplyContainerConfig: props.applyContainerConfig, gatewayUnavailable: state.gatewayState === "absent" ||
169
- state.gatewayState === "incompatible" }, workspace.workspaceSlug)))) }), _jsx("div", { id: panelId("images"), role: "tabpanel", "aria-labelledby": tabId("images"), hidden: tab !== "images", style: tab === "images" ? tabPanel : undefined, children: _jsx(ImagesSection, { t: t, images: state.images, busy: state.busy, pendingActions: state.pendingActions, defaultImage: state.defaultImage, locale: state.locale, onBuildImage: props.buildImage, onRebuildAllImages: props.rebuildAllImages, onRebuildBaseImage: props.rebuildBaseImage, onPullBaseImage: props.pullBaseImage, onRemoveImage: props.removeImage, onRebuildImage: props.rebuildImage, onBuildPtcImage: props.buildPtcImage, onSetDefaultImage: props.setDefaultImage }) }), _jsx("div", { id: panelId("storage"), role: "tabpanel", "aria-labelledby": tabId("storage"), hidden: tab !== "storage", style: tab === "storage" ? tabPanel : undefined, children: _jsx(StorageSection, { t: t, volumes: state.volumes, secrets: state.secrets, caches: state.caches, busy: state.busy, writable: state.writable, pendingActions: state.pendingActions, onCleanCaches: props.cleanCaches, onCreateVolume: props.createVolume, onRemoveVolume: props.removeVolume, onCreateSecret: props.createSecret, onRemoveSecret: props.removeSecret, onSetSecret: props.setSecret }) }), _jsx("div", { id: panelId("defaults"), role: "tabpanel", "aria-labelledby": tabId("defaults"), hidden: tab !== "defaults", style: tab === "defaults" ? tabPanel : undefined, children: _jsx(DefaultsSection, { t: t, images: state.images, defaultImage: state.defaultImage, env: state.containerEnv, workspaces: state.workspaces, containers: state.containers, busy: state.busy, writable: state.writable, onSetDefaultImage: props.setDefaultImage, onSaveEnv: props.saveContainerEnv, onApplyDefaultEnv: props.applyDefaultEnv }) }), _jsx("div", { id: panelId("status"), role: "tabpanel", "aria-labelledby": tabId("status"), hidden: tab !== "status", style: tab === "status" ? tabPanel : undefined, children: _jsx(StatusSection, { t: t, dshVersion: state.dshVersion, version: state.version, commit: state.commit, versionState: state.versionState, orchestratorVersion: state.orchestratorVersion, orchestratorCommit: state.orchestratorCommit, orchestratorReady: state.orchestratorReady, orchestratorKnown: state.orchestratorKnown, gatewayState: state.gatewayState, gatewayVersion: state.gatewayVersion, gatewayCommit: state.gatewayCommit, gatewayVersionState: state.gatewayVersionState, ptc: state.ptc, locale: state.locale, pendingActions: state.pendingActions, onRecreatePtc: props.recreatePtc, onRemovePtc: props.removePtc }) }), _jsx("div", { style: actionRow, children: _jsx(Button, { variant: "outline", size: "sm", disabled: state.busy, onClick: props.reload, children: state.busy ? t("busy") : t("reload") }) })] }));
168
+ ] }), _jsx("div", { id: panelId("workspaces"), role: "tabpanel", "aria-labelledby": tabId("workspaces"), hidden: tab !== "workspaces", style: tab === "workspaces" ? tabPanel : undefined, children: noWorkspace ? _jsx("p", { style: hint, children: t("noWorkspaces") }) : (workspaceRows.map(({ workspace, containers }) => (_jsx(WorkspaceSection, { t: t, workspace: workspace, containers: containers, images: state.images, volumes: state.volumes, secrets: state.secrets, busy: state.busy, writable: state.writable, locale: state.locale, pendingActions: state.pendingActions, defaultImage: state.defaultImage, defaultEnv: state.containerEnv, projectsRoot: state.projectsRoot, directoryPicker: state.directoryPicker, onRemove: props.remove, onRecreate: props.recreate, onRemoveWorkspace: props.removeWorkspace, onCreate: props.createContainer, onCreateVolume: props.createVolume, onCreateSecret: props.createSecret, onStartContainer: props.startContainer, onApplyContainerConfig: props.applyContainerConfig, gatewayUnavailable: state.gatewayState === "absent" ||
169
+ state.gatewayState === "incompatible", templateActions: {
170
+ listTemplates: props.listTemplates,
171
+ inspectTemplate: props.inspectTemplate,
172
+ buildTemplate: props.buildTemplate,
173
+ applyTemplate: props.applyTemplate,
174
+ publishTemplate: props.publishTemplate,
175
+ }, onBuildImage: props.buildImage, onRebuildImage: props.rebuildImage, onRebuildBaseImage: props.rebuildBaseImage, onPullBaseImage: props.pullBaseImage, onReload: props.reload }, workspace.workspaceSlug)))) }), _jsx("div", { id: panelId("images"), role: "tabpanel", "aria-labelledby": tabId("images"), hidden: tab !== "images", style: tab === "images" ? tabPanel : undefined, children: _jsx(ImagesSection, { t: t, images: state.images, busy: state.busy, pendingActions: state.pendingActions, defaultImage: state.defaultImage, locale: state.locale, onBuildImage: props.buildImage, onRebuildAllImages: props.rebuildAllImages, onRebuildBaseImage: props.rebuildBaseImage, onPullBaseImage: props.pullBaseImage, onRemoveImage: props.removeImage, onRebuildImage: props.rebuildImage, onBuildPtcImage: props.buildPtcImage, onSetDefaultImage: props.setDefaultImage }) }), _jsx("div", { id: panelId("storage"), role: "tabpanel", "aria-labelledby": tabId("storage"), hidden: tab !== "storage", style: tab === "storage" ? tabPanel : undefined, children: _jsx(StorageSection, { t: t, volumes: state.volumes, secrets: state.secrets, caches: state.caches, busy: state.busy, writable: state.writable, pendingActions: state.pendingActions, onCleanCaches: props.cleanCaches, onCreateVolume: props.createVolume, onRemoveVolume: props.removeVolume, onCreateSecret: props.createSecret, onRemoveSecret: props.removeSecret, onSetSecret: props.setSecret }) }), _jsx("div", { id: panelId("defaults"), role: "tabpanel", "aria-labelledby": tabId("defaults"), hidden: tab !== "defaults", style: tab === "defaults" ? tabPanel : undefined, children: _jsx(DefaultsSection, { t: t, images: state.images, defaultImage: state.defaultImage, env: state.containerEnv, workspaces: state.workspaces, containers: state.containers, busy: state.busy, writable: state.writable, onSetDefaultImage: props.setDefaultImage, onSaveEnv: props.saveContainerEnv, onApplyDefaultEnv: props.applyDefaultEnv }) }), _jsx("div", { id: panelId("status"), role: "tabpanel", "aria-labelledby": tabId("status"), hidden: tab !== "status", style: tab === "status" ? tabPanel : undefined, children: _jsx(StatusSection, { t: t, dshVersion: state.dshVersion, version: state.version, commit: state.commit, versionState: state.versionState, orchestratorVersion: state.orchestratorVersion, orchestratorCommit: state.orchestratorCommit, orchestratorReady: state.orchestratorReady, orchestratorKnown: state.orchestratorKnown, gatewayState: state.gatewayState, gatewayVersion: state.gatewayVersion, gatewayCommit: state.gatewayCommit, gatewayVersionState: state.gatewayVersionState, ptc: state.ptc, locale: state.locale, pendingActions: state.pendingActions, onRecreatePtc: props.recreatePtc, onRemovePtc: props.removePtc }) }), _jsx("div", { style: actionRow, children: _jsx(Button, { variant: "outline", size: "sm", disabled: state.busy, onClick: props.reload, children: state.busy ? t("busy") : t("reload") }) })] }));
170
176
  }