@rozek/nanoclaw 1.2.17

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 (305) hide show
  1. package/.claude/settings.json +1 -0
  2. package/.claude/skills/add-compact/SKILL.md +135 -0
  3. package/.claude/skills/add-discord/SKILL.md +203 -0
  4. package/.claude/skills/add-gmail/SKILL.md +220 -0
  5. package/.claude/skills/add-image-vision/SKILL.md +94 -0
  6. package/.claude/skills/add-ollama-tool/SKILL.md +153 -0
  7. package/.claude/skills/add-parallel/SKILL.md +290 -0
  8. package/.claude/skills/add-pdf-reader/SKILL.md +104 -0
  9. package/.claude/skills/add-reactions/SKILL.md +117 -0
  10. package/.claude/skills/add-slack/SKILL.md +207 -0
  11. package/.claude/skills/add-telegram/SKILL.md +222 -0
  12. package/.claude/skills/add-telegram-swarm/SKILL.md +384 -0
  13. package/.claude/skills/add-voice-transcription/SKILL.md +148 -0
  14. package/.claude/skills/add-whatsapp/SKILL.md +372 -0
  15. package/.claude/skills/convert-to-apple-container/SKILL.md +175 -0
  16. package/.claude/skills/customize/SKILL.md +110 -0
  17. package/.claude/skills/debug/SKILL.md +349 -0
  18. package/.claude/skills/get-qodo-rules/SKILL.md +122 -0
  19. package/.claude/skills/get-qodo-rules/references/output-format.md +41 -0
  20. package/.claude/skills/get-qodo-rules/references/pagination.md +33 -0
  21. package/.claude/skills/get-qodo-rules/references/repository-scope.md +26 -0
  22. package/.claude/skills/qodo-pr-resolver/SKILL.md +326 -0
  23. package/.claude/skills/qodo-pr-resolver/resources/providers.md +329 -0
  24. package/.claude/skills/setup/SKILL.md +218 -0
  25. package/.claude/skills/update-nanoclaw/SKILL.md +235 -0
  26. package/.claude/skills/update-skills/SKILL.md +130 -0
  27. package/.claude/skills/use-local-whisper/SKILL.md +152 -0
  28. package/.claude/skills/x-integration/SKILL.md +417 -0
  29. package/.claude/skills/x-integration/agent.ts +243 -0
  30. package/.claude/skills/x-integration/host.ts +159 -0
  31. package/.claude/skills/x-integration/lib/browser.ts +148 -0
  32. package/.claude/skills/x-integration/lib/config.ts +62 -0
  33. package/.claude/skills/x-integration/scripts/like.ts +56 -0
  34. package/.claude/skills/x-integration/scripts/post.ts +66 -0
  35. package/.claude/skills/x-integration/scripts/quote.ts +80 -0
  36. package/.claude/skills/x-integration/scripts/reply.ts +74 -0
  37. package/.claude/skills/x-integration/scripts/retweet.ts +62 -0
  38. package/.claude/skills/x-integration/scripts/setup.ts +87 -0
  39. package/.env.example +1 -0
  40. package/.github/CODEOWNERS +10 -0
  41. package/.github/PULL_REQUEST_TEMPLATE.md +14 -0
  42. package/.github/workflows/bump-version.yml +32 -0
  43. package/.github/workflows/ci.yml +25 -0
  44. package/.github/workflows/merge-forward-skills.yml +160 -0
  45. package/.github/workflows/update-tokens.yml +42 -0
  46. package/.husky/pre-commit +1 -0
  47. package/.mcp.json +3 -0
  48. package/.nvmrc +1 -0
  49. package/.prettierrc +3 -0
  50. package/CHANGELOG.md +8 -0
  51. package/CLAUDE.md +64 -0
  52. package/CONTRIBUTING.md +23 -0
  53. package/CONTRIBUTORS.md +15 -0
  54. package/LICENSE +21 -0
  55. package/NanoClaw_with_Web-Support.md +290 -0
  56. package/README.md +261 -0
  57. package/README_zh.md +200 -0
  58. package/assets/nanoclaw-favicon.png +0 -0
  59. package/assets/nanoclaw-icon.png +0 -0
  60. package/assets/nanoclaw-logo-dark.png +0 -0
  61. package/assets/nanoclaw-logo.png +0 -0
  62. package/assets/nanoclaw-profile.jpeg +0 -0
  63. package/assets/nanoclaw-sales.png +0 -0
  64. package/assets/social-preview.jpg +0 -0
  65. package/config-examples/mount-allowlist.json +25 -0
  66. package/container/Dockerfile +70 -0
  67. package/container/agent-runner/package-lock.json +1524 -0
  68. package/container/agent-runner/package.json +21 -0
  69. package/container/agent-runner/src/index.ts +558 -0
  70. package/container/agent-runner/src/ipc-mcp-stdio.ts +338 -0
  71. package/container/agent-runner/tsconfig.json +15 -0
  72. package/container/build.sh +23 -0
  73. package/container/skills/agent-browser/SKILL.md +159 -0
  74. package/container/skills/capabilities/SKILL.md +100 -0
  75. package/container/skills/status/SKILL.md +104 -0
  76. package/dist/channels/index.d.ts +2 -0
  77. package/dist/channels/index.d.ts.map +1 -0
  78. package/dist/channels/index.js +9 -0
  79. package/dist/channels/index.js.map +1 -0
  80. package/dist/channels/registry.d.ts +13 -0
  81. package/dist/channels/registry.d.ts.map +1 -0
  82. package/dist/channels/registry.js +11 -0
  83. package/dist/channels/registry.js.map +1 -0
  84. package/dist/channels/registry.test.d.ts +2 -0
  85. package/dist/channels/registry.test.d.ts.map +1 -0
  86. package/dist/channels/registry.test.js +32 -0
  87. package/dist/channels/registry.test.js.map +1 -0
  88. package/dist/channels/web.d.ts +2 -0
  89. package/dist/channels/web.d.ts.map +1 -0
  90. package/dist/channels/web.js +1738 -0
  91. package/dist/channels/web.js.map +1 -0
  92. package/dist/cli.d.ts +11 -0
  93. package/dist/cli.d.ts.map +1 -0
  94. package/dist/cli.js +182 -0
  95. package/dist/cli.js.map +1 -0
  96. package/dist/config.d.ts +19 -0
  97. package/dist/config.d.ts.map +1 -0
  98. package/dist/config.js +36 -0
  99. package/dist/config.js.map +1 -0
  100. package/dist/container-runner.d.ts +44 -0
  101. package/dist/container-runner.d.ts.map +1 -0
  102. package/dist/container-runner.js +467 -0
  103. package/dist/container-runner.js.map +1 -0
  104. package/dist/container-runner.test.d.ts +2 -0
  105. package/dist/container-runner.test.d.ts.map +1 -0
  106. package/dist/container-runner.test.js +150 -0
  107. package/dist/container-runner.test.js.map +1 -0
  108. package/dist/container-runtime.d.ts +22 -0
  109. package/dist/container-runtime.d.ts.map +1 -0
  110. package/dist/container-runtime.js +96 -0
  111. package/dist/container-runtime.js.map +1 -0
  112. package/dist/container-runtime.test.d.ts +2 -0
  113. package/dist/container-runtime.test.d.ts.map +1 -0
  114. package/dist/container-runtime.test.js +93 -0
  115. package/dist/container-runtime.test.js.map +1 -0
  116. package/dist/credential-proxy.d.ts +21 -0
  117. package/dist/credential-proxy.d.ts.map +1 -0
  118. package/dist/credential-proxy.js +95 -0
  119. package/dist/credential-proxy.js.map +1 -0
  120. package/dist/credential-proxy.test.d.ts +2 -0
  121. package/dist/credential-proxy.test.d.ts.map +1 -0
  122. package/dist/credential-proxy.test.js +134 -0
  123. package/dist/credential-proxy.test.js.map +1 -0
  124. package/dist/db.d.ts +115 -0
  125. package/dist/db.d.ts.map +1 -0
  126. package/dist/db.js +549 -0
  127. package/dist/db.js.map +1 -0
  128. package/dist/db.test.d.ts +2 -0
  129. package/dist/db.test.d.ts.map +1 -0
  130. package/dist/db.test.js +360 -0
  131. package/dist/db.test.js.map +1 -0
  132. package/dist/env.d.ts +8 -0
  133. package/dist/env.d.ts.map +1 -0
  134. package/dist/env.js +42 -0
  135. package/dist/env.js.map +1 -0
  136. package/dist/formatting.test.d.ts +2 -0
  137. package/dist/formatting.test.d.ts.map +1 -0
  138. package/dist/formatting.test.js +183 -0
  139. package/dist/formatting.test.js.map +1 -0
  140. package/dist/group-folder.d.ts +5 -0
  141. package/dist/group-folder.d.ts.map +1 -0
  142. package/dist/group-folder.js +44 -0
  143. package/dist/group-folder.js.map +1 -0
  144. package/dist/group-folder.test.d.ts +2 -0
  145. package/dist/group-folder.test.d.ts.map +1 -0
  146. package/dist/group-folder.test.js +29 -0
  147. package/dist/group-folder.test.js.map +1 -0
  148. package/dist/group-queue.d.ts +34 -0
  149. package/dist/group-queue.d.ts.map +1 -0
  150. package/dist/group-queue.js +263 -0
  151. package/dist/group-queue.js.map +1 -0
  152. package/dist/group-queue.test.d.ts +2 -0
  153. package/dist/group-queue.test.d.ts.map +1 -0
  154. package/dist/group-queue.test.js +341 -0
  155. package/dist/group-queue.test.js.map +1 -0
  156. package/dist/index.d.ts +12 -0
  157. package/dist/index.d.ts.map +1 -0
  158. package/dist/index.js +518 -0
  159. package/dist/index.js.map +1 -0
  160. package/dist/ipc-auth.test.d.ts +2 -0
  161. package/dist/ipc-auth.test.d.ts.map +1 -0
  162. package/dist/ipc-auth.test.js +434 -0
  163. package/dist/ipc-auth.test.js.map +1 -0
  164. package/dist/ipc.d.ts +32 -0
  165. package/dist/ipc.d.ts.map +1 -0
  166. package/dist/ipc.js +311 -0
  167. package/dist/ipc.js.map +1 -0
  168. package/dist/logger.d.ts +3 -0
  169. package/dist/logger.d.ts.map +1 -0
  170. package/dist/logger.js +14 -0
  171. package/dist/logger.js.map +1 -0
  172. package/dist/mount-security.d.ts +34 -0
  173. package/dist/mount-security.d.ts.map +1 -0
  174. package/dist/mount-security.js +325 -0
  175. package/dist/mount-security.js.map +1 -0
  176. package/dist/remote-control.d.ts +32 -0
  177. package/dist/remote-control.d.ts.map +1 -0
  178. package/dist/remote-control.js +185 -0
  179. package/dist/remote-control.js.map +1 -0
  180. package/dist/remote-control.test.d.ts +2 -0
  181. package/dist/remote-control.test.d.ts.map +1 -0
  182. package/dist/remote-control.test.js +321 -0
  183. package/dist/remote-control.test.js.map +1 -0
  184. package/dist/router.d.ts +8 -0
  185. package/dist/router.d.ts.map +1 -0
  186. package/dist/router.js +37 -0
  187. package/dist/router.js.map +1 -0
  188. package/dist/routing.test.d.ts +2 -0
  189. package/dist/routing.test.d.ts.map +1 -0
  190. package/dist/routing.test.js +81 -0
  191. package/dist/routing.test.js.map +1 -0
  192. package/dist/sender-allowlist.d.ts +14 -0
  193. package/dist/sender-allowlist.d.ts.map +1 -0
  194. package/dist/sender-allowlist.js +79 -0
  195. package/dist/sender-allowlist.js.map +1 -0
  196. package/dist/sender-allowlist.test.d.ts +2 -0
  197. package/dist/sender-allowlist.test.d.ts.map +1 -0
  198. package/dist/sender-allowlist.test.js +186 -0
  199. package/dist/sender-allowlist.test.js.map +1 -0
  200. package/dist/session-commands.d.ts +47 -0
  201. package/dist/session-commands.d.ts.map +1 -0
  202. package/dist/session-commands.js +102 -0
  203. package/dist/session-commands.js.map +1 -0
  204. package/dist/session-commands.test.d.ts +2 -0
  205. package/dist/session-commands.test.d.ts.map +1 -0
  206. package/dist/session-commands.test.js +190 -0
  207. package/dist/session-commands.test.js.map +1 -0
  208. package/dist/task-scheduler.d.ts +22 -0
  209. package/dist/task-scheduler.d.ts.map +1 -0
  210. package/dist/task-scheduler.js +210 -0
  211. package/dist/task-scheduler.js.map +1 -0
  212. package/dist/task-scheduler.test.d.ts +2 -0
  213. package/dist/task-scheduler.test.d.ts.map +1 -0
  214. package/dist/task-scheduler.test.js +107 -0
  215. package/dist/task-scheduler.test.js.map +1 -0
  216. package/dist/timezone.d.ts +6 -0
  217. package/dist/timezone.d.ts.map +1 -0
  218. package/dist/timezone.js +17 -0
  219. package/dist/timezone.js.map +1 -0
  220. package/dist/timezone.test.d.ts +2 -0
  221. package/dist/timezone.test.d.ts.map +1 -0
  222. package/dist/timezone.test.js +23 -0
  223. package/dist/timezone.test.js.map +1 -0
  224. package/dist/types.d.ts +78 -0
  225. package/dist/types.d.ts.map +1 -0
  226. package/dist/types.js +2 -0
  227. package/dist/types.js.map +1 -0
  228. package/docs/APPLE-CONTAINER-NETWORKING.md +90 -0
  229. package/docs/DEBUG_CHECKLIST.md +143 -0
  230. package/docs/REQUIREMENTS.md +196 -0
  231. package/docs/SDK_DEEP_DIVE.md +643 -0
  232. package/docs/SECURITY.md +122 -0
  233. package/docs/SPEC.md +785 -0
  234. package/docs/docker-sandboxes.md +359 -0
  235. package/docs/nanoclaw-architecture-final.md +1063 -0
  236. package/docs/nanorepo-architecture.md +168 -0
  237. package/docs/skills-as-branches.md +662 -0
  238. package/groups/global/CLAUDE.md +58 -0
  239. package/groups/main/CLAUDE.md +246 -0
  240. package/launchd/com.nanoclaw.plist +32 -0
  241. package/package.json +45 -0
  242. package/repo-tokens/README.md +113 -0
  243. package/repo-tokens/action.yml +186 -0
  244. package/repo-tokens/badge.svg +23 -0
  245. package/repo-tokens/examples/green.svg +14 -0
  246. package/repo-tokens/examples/red.svg +14 -0
  247. package/repo-tokens/examples/yellow-green.svg +14 -0
  248. package/repo-tokens/examples/yellow.svg +14 -0
  249. package/scripts/run-migrations.ts +105 -0
  250. package/setup/container.ts +144 -0
  251. package/setup/environment.test.ts +121 -0
  252. package/setup/environment.ts +94 -0
  253. package/setup/groups.ts +229 -0
  254. package/setup/index.ts +58 -0
  255. package/setup/mounts.ts +115 -0
  256. package/setup/platform.test.ts +120 -0
  257. package/setup/platform.ts +132 -0
  258. package/setup/register.test.ts +257 -0
  259. package/setup/register.ts +177 -0
  260. package/setup/service.test.ts +187 -0
  261. package/setup/service.ts +362 -0
  262. package/setup/status.ts +16 -0
  263. package/setup/verify.ts +192 -0
  264. package/setup.sh +161 -0
  265. package/src/channels/index.ts +12 -0
  266. package/src/channels/registry.test.ts +42 -0
  267. package/src/channels/registry.ts +32 -0
  268. package/src/channels/web.ts +1856 -0
  269. package/src/cli.ts +209 -0
  270. package/src/config.ts +73 -0
  271. package/src/container-runner.test.ts +210 -0
  272. package/src/container-runner.ts +707 -0
  273. package/src/container-runtime.test.ts +149 -0
  274. package/src/container-runtime.ts +127 -0
  275. package/src/credential-proxy.test.ts +192 -0
  276. package/src/credential-proxy.ts +125 -0
  277. package/src/db.test.ts +484 -0
  278. package/src/db.ts +803 -0
  279. package/src/env.ts +42 -0
  280. package/src/formatting.test.ts +256 -0
  281. package/src/group-folder.test.ts +43 -0
  282. package/src/group-folder.ts +44 -0
  283. package/src/group-queue.test.ts +484 -0
  284. package/src/group-queue.ts +365 -0
  285. package/src/index.ts +731 -0
  286. package/src/ipc-auth.test.ts +679 -0
  287. package/src/ipc.ts +461 -0
  288. package/src/logger.ts +16 -0
  289. package/src/mount-security.ts +419 -0
  290. package/src/remote-control.test.ts +397 -0
  291. package/src/remote-control.ts +224 -0
  292. package/src/router.ts +52 -0
  293. package/src/routing.test.ts +170 -0
  294. package/src/sender-allowlist.test.ts +216 -0
  295. package/src/sender-allowlist.ts +128 -0
  296. package/src/session-commands.test.ts +247 -0
  297. package/src/session-commands.ts +163 -0
  298. package/src/task-scheduler.test.ts +129 -0
  299. package/src/task-scheduler.ts +295 -0
  300. package/src/timezone.test.ts +29 -0
  301. package/src/timezone.ts +16 -0
  302. package/src/types.ts +107 -0
  303. package/tsconfig.json +20 -0
  304. package/vitest.config.ts +7 -0
  305. package/vitest.skills.config.ts +7 -0
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Mount Security Module for NanoClaw
3
+ *
4
+ * Validates additional mounts against an allowlist stored OUTSIDE the project root.
5
+ * This prevents container agents from modifying security configuration.
6
+ *
7
+ * Allowlist location: ~/.config/nanoclaw/mount-allowlist.json
8
+ */
9
+ import fs from 'fs';
10
+ import os from 'os';
11
+ import path from 'path';
12
+ import pino from 'pino';
13
+
14
+ import { MOUNT_ALLOWLIST_PATH } from './config.js';
15
+ import { AdditionalMount, AllowedRoot, MountAllowlist } from './types.js';
16
+
17
+ const logger = pino({
18
+ level: process.env.LOG_LEVEL || 'info',
19
+ transport: { target: 'pino-pretty', options: { colorize: true } },
20
+ });
21
+
22
+ // Cache the allowlist in memory - only reloads on process restart
23
+ let cachedAllowlist: MountAllowlist | null = null;
24
+ let allowlistLoadError: string | null = null;
25
+
26
+ /**
27
+ * Default blocked patterns - paths that should never be mounted
28
+ */
29
+ const DEFAULT_BLOCKED_PATTERNS = [
30
+ '.ssh',
31
+ '.gnupg',
32
+ '.gpg',
33
+ '.aws',
34
+ '.azure',
35
+ '.gcloud',
36
+ '.kube',
37
+ '.docker',
38
+ 'credentials',
39
+ '.env',
40
+ '.netrc',
41
+ '.npmrc',
42
+ '.pypirc',
43
+ 'id_rsa',
44
+ 'id_ed25519',
45
+ 'private_key',
46
+ '.secret',
47
+ ];
48
+
49
+ /**
50
+ * Load the mount allowlist from the external config location.
51
+ * Returns null if the file doesn't exist or is invalid.
52
+ * Result is cached in memory for the lifetime of the process.
53
+ */
54
+ export function loadMountAllowlist(): MountAllowlist | null {
55
+ if (cachedAllowlist !== null) {
56
+ return cachedAllowlist;
57
+ }
58
+
59
+ if (allowlistLoadError !== null) {
60
+ // Already tried and failed, don't spam logs
61
+ return null;
62
+ }
63
+
64
+ try {
65
+ if (!fs.existsSync(MOUNT_ALLOWLIST_PATH)) {
66
+ allowlistLoadError = `Mount allowlist not found at ${MOUNT_ALLOWLIST_PATH}`;
67
+ logger.warn(
68
+ { path: MOUNT_ALLOWLIST_PATH },
69
+ 'Mount allowlist not found - additional mounts will be BLOCKED. ' +
70
+ 'Create the file to enable additional mounts.',
71
+ );
72
+ return null;
73
+ }
74
+
75
+ const content = fs.readFileSync(MOUNT_ALLOWLIST_PATH, 'utf-8');
76
+ const allowlist = JSON.parse(content) as MountAllowlist;
77
+
78
+ // Validate structure
79
+ if (!Array.isArray(allowlist.allowedRoots)) {
80
+ throw new Error('allowedRoots must be an array');
81
+ }
82
+
83
+ if (!Array.isArray(allowlist.blockedPatterns)) {
84
+ throw new Error('blockedPatterns must be an array');
85
+ }
86
+
87
+ if (typeof allowlist.nonMainReadOnly !== 'boolean') {
88
+ throw new Error('nonMainReadOnly must be a boolean');
89
+ }
90
+
91
+ // Merge with default blocked patterns
92
+ const mergedBlockedPatterns = [
93
+ ...new Set([...DEFAULT_BLOCKED_PATTERNS, ...allowlist.blockedPatterns]),
94
+ ];
95
+ allowlist.blockedPatterns = mergedBlockedPatterns;
96
+
97
+ cachedAllowlist = allowlist;
98
+ logger.info(
99
+ {
100
+ path: MOUNT_ALLOWLIST_PATH,
101
+ allowedRoots: allowlist.allowedRoots.length,
102
+ blockedPatterns: allowlist.blockedPatterns.length,
103
+ },
104
+ 'Mount allowlist loaded successfully',
105
+ );
106
+
107
+ return cachedAllowlist;
108
+ } catch (err) {
109
+ allowlistLoadError = err instanceof Error ? err.message : String(err);
110
+ logger.error(
111
+ {
112
+ path: MOUNT_ALLOWLIST_PATH,
113
+ error: allowlistLoadError,
114
+ },
115
+ 'Failed to load mount allowlist - additional mounts will be BLOCKED',
116
+ );
117
+ return null;
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Expand ~ to home directory and resolve to absolute path
123
+ */
124
+ function expandPath(p: string): string {
125
+ const homeDir = process.env.HOME || os.homedir();
126
+ if (p.startsWith('~/')) {
127
+ return path.join(homeDir, p.slice(2));
128
+ }
129
+ if (p === '~') {
130
+ return homeDir;
131
+ }
132
+ return path.resolve(p);
133
+ }
134
+
135
+ /**
136
+ * Get the real path, resolving symlinks.
137
+ * Returns null if the path doesn't exist.
138
+ */
139
+ function getRealPath(p: string): string | null {
140
+ try {
141
+ return fs.realpathSync(p);
142
+ } catch {
143
+ return null;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Check if a path matches any blocked pattern
149
+ */
150
+ function matchesBlockedPattern(
151
+ realPath: string,
152
+ blockedPatterns: string[],
153
+ ): string | null {
154
+ const pathParts = realPath.split(path.sep);
155
+
156
+ for (const pattern of blockedPatterns) {
157
+ // Check if any path component matches the pattern
158
+ for (const part of pathParts) {
159
+ if (part === pattern || part.includes(pattern)) {
160
+ return pattern;
161
+ }
162
+ }
163
+
164
+ // Also check if the full path contains the pattern
165
+ if (realPath.includes(pattern)) {
166
+ return pattern;
167
+ }
168
+ }
169
+
170
+ return null;
171
+ }
172
+
173
+ /**
174
+ * Check if a real path is under an allowed root
175
+ */
176
+ function findAllowedRoot(
177
+ realPath: string,
178
+ allowedRoots: AllowedRoot[],
179
+ ): AllowedRoot | null {
180
+ for (const root of allowedRoots) {
181
+ const expandedRoot = expandPath(root.path);
182
+ const realRoot = getRealPath(expandedRoot);
183
+
184
+ if (realRoot === null) {
185
+ // Allowed root doesn't exist, skip it
186
+ continue;
187
+ }
188
+
189
+ // Check if realPath is under realRoot
190
+ const relative = path.relative(realRoot, realPath);
191
+ if (!relative.startsWith('..') && !path.isAbsolute(relative)) {
192
+ return root;
193
+ }
194
+ }
195
+
196
+ return null;
197
+ }
198
+
199
+ /**
200
+ * Validate the container path to prevent escaping /workspace/extra/
201
+ */
202
+ function isValidContainerPath(containerPath: string): boolean {
203
+ // Must not contain .. to prevent path traversal
204
+ if (containerPath.includes('..')) {
205
+ return false;
206
+ }
207
+
208
+ // Must not be absolute (it will be prefixed with /workspace/extra/)
209
+ if (containerPath.startsWith('/')) {
210
+ return false;
211
+ }
212
+
213
+ // Must not be empty
214
+ if (!containerPath || containerPath.trim() === '') {
215
+ return false;
216
+ }
217
+
218
+ return true;
219
+ }
220
+
221
+ export interface MountValidationResult {
222
+ allowed: boolean;
223
+ reason: string;
224
+ realHostPath?: string;
225
+ resolvedContainerPath?: string;
226
+ effectiveReadonly?: boolean;
227
+ }
228
+
229
+ /**
230
+ * Validate a single additional mount against the allowlist.
231
+ * Returns validation result with reason.
232
+ */
233
+ export function validateMount(
234
+ mount: AdditionalMount,
235
+ isMain: boolean,
236
+ ): MountValidationResult {
237
+ const allowlist = loadMountAllowlist();
238
+
239
+ // If no allowlist, block all additional mounts
240
+ if (allowlist === null) {
241
+ return {
242
+ allowed: false,
243
+ reason: `No mount allowlist configured at ${MOUNT_ALLOWLIST_PATH}`,
244
+ };
245
+ }
246
+
247
+ // Derive containerPath from hostPath basename if not specified
248
+ const containerPath = mount.containerPath || path.basename(mount.hostPath);
249
+
250
+ // Validate container path (cheap check)
251
+ if (!isValidContainerPath(containerPath)) {
252
+ return {
253
+ allowed: false,
254
+ reason: `Invalid container path: "${containerPath}" - must be relative, non-empty, and not contain ".."`,
255
+ };
256
+ }
257
+
258
+ // Expand and resolve the host path
259
+ const expandedPath = expandPath(mount.hostPath);
260
+ const realPath = getRealPath(expandedPath);
261
+
262
+ if (realPath === null) {
263
+ return {
264
+ allowed: false,
265
+ reason: `Host path does not exist: "${mount.hostPath}" (expanded: "${expandedPath}")`,
266
+ };
267
+ }
268
+
269
+ // Check against blocked patterns
270
+ const blockedMatch = matchesBlockedPattern(
271
+ realPath,
272
+ allowlist.blockedPatterns,
273
+ );
274
+ if (blockedMatch !== null) {
275
+ return {
276
+ allowed: false,
277
+ reason: `Path matches blocked pattern "${blockedMatch}": "${realPath}"`,
278
+ };
279
+ }
280
+
281
+ // Check if under an allowed root
282
+ const allowedRoot = findAllowedRoot(realPath, allowlist.allowedRoots);
283
+ if (allowedRoot === null) {
284
+ return {
285
+ allowed: false,
286
+ reason: `Path "${realPath}" is not under any allowed root. Allowed roots: ${allowlist.allowedRoots
287
+ .map((r) => expandPath(r.path))
288
+ .join(', ')}`,
289
+ };
290
+ }
291
+
292
+ // Determine effective readonly status
293
+ const requestedReadWrite = mount.readonly === false;
294
+ let effectiveReadonly = true; // Default to readonly
295
+
296
+ if (requestedReadWrite) {
297
+ if (!isMain && allowlist.nonMainReadOnly) {
298
+ // Non-main groups forced to read-only
299
+ effectiveReadonly = true;
300
+ logger.info(
301
+ {
302
+ mount: mount.hostPath,
303
+ },
304
+ 'Mount forced to read-only for non-main group',
305
+ );
306
+ } else if (!allowedRoot.allowReadWrite) {
307
+ // Root doesn't allow read-write
308
+ effectiveReadonly = true;
309
+ logger.info(
310
+ {
311
+ mount: mount.hostPath,
312
+ root: allowedRoot.path,
313
+ },
314
+ 'Mount forced to read-only - root does not allow read-write',
315
+ );
316
+ } else {
317
+ // Read-write allowed
318
+ effectiveReadonly = false;
319
+ }
320
+ }
321
+
322
+ return {
323
+ allowed: true,
324
+ reason: `Allowed under root "${allowedRoot.path}"${allowedRoot.description ? ` (${allowedRoot.description})` : ''}`,
325
+ realHostPath: realPath,
326
+ resolvedContainerPath: containerPath,
327
+ effectiveReadonly,
328
+ };
329
+ }
330
+
331
+ /**
332
+ * Validate all additional mounts for a group.
333
+ * Returns array of validated mounts (only those that passed validation).
334
+ * Logs warnings for rejected mounts.
335
+ */
336
+ export function validateAdditionalMounts(
337
+ mounts: AdditionalMount[],
338
+ groupName: string,
339
+ isMain: boolean,
340
+ ): Array<{
341
+ hostPath: string;
342
+ containerPath: string;
343
+ readonly: boolean;
344
+ }> {
345
+ const validatedMounts: Array<{
346
+ hostPath: string;
347
+ containerPath: string;
348
+ readonly: boolean;
349
+ }> = [];
350
+
351
+ for (const mount of mounts) {
352
+ const result = validateMount(mount, isMain);
353
+
354
+ if (result.allowed) {
355
+ validatedMounts.push({
356
+ hostPath: result.realHostPath!,
357
+ containerPath: `/workspace/extra/${result.resolvedContainerPath}`,
358
+ readonly: result.effectiveReadonly!,
359
+ });
360
+
361
+ logger.debug(
362
+ {
363
+ group: groupName,
364
+ hostPath: result.realHostPath,
365
+ containerPath: result.resolvedContainerPath,
366
+ readonly: result.effectiveReadonly,
367
+ reason: result.reason,
368
+ },
369
+ 'Mount validated successfully',
370
+ );
371
+ } else {
372
+ logger.warn(
373
+ {
374
+ group: groupName,
375
+ requestedPath: mount.hostPath,
376
+ containerPath: mount.containerPath,
377
+ reason: result.reason,
378
+ },
379
+ 'Additional mount REJECTED',
380
+ );
381
+ }
382
+ }
383
+
384
+ return validatedMounts;
385
+ }
386
+
387
+ /**
388
+ * Generate a template allowlist file for users to customize
389
+ */
390
+ export function generateAllowlistTemplate(): string {
391
+ const template: MountAllowlist = {
392
+ allowedRoots: [
393
+ {
394
+ path: '~/projects',
395
+ allowReadWrite: true,
396
+ description: 'Development projects',
397
+ },
398
+ {
399
+ path: '~/repos',
400
+ allowReadWrite: true,
401
+ description: 'Git repositories',
402
+ },
403
+ {
404
+ path: '~/Documents/work',
405
+ allowReadWrite: false,
406
+ description: 'Work documents (read-only)',
407
+ },
408
+ ],
409
+ blockedPatterns: [
410
+ // Additional patterns beyond defaults
411
+ 'password',
412
+ 'secret',
413
+ 'token',
414
+ ],
415
+ nonMainReadOnly: true,
416
+ };
417
+
418
+ return JSON.stringify(template, null, 2);
419
+ }