shapewall 0.0.0-stage → 0.2.2

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 (304) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/Dockerfile.agent +45 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +12 -0
  5. package/README.md +651 -2
  6. package/THIRD_PARTY.md +165 -0
  7. package/bin/shapewall.js +29 -0
  8. package/dist/agent/package-lock.json +8384 -0
  9. package/dist/client/assets/BoardChat-D5SFd8HE.js +28 -0
  10. package/dist/client/assets/BuzzDialog-HWXBy52W.js +1 -0
  11. package/dist/client/assets/ChecksPanel-DTdImWoD.js +1 -0
  12. package/dist/client/assets/History-CEv6b-av.js +1 -0
  13. package/dist/client/assets/LocalSettings-C4vriEVQ.js +1 -0
  14. package/dist/client/assets/Management-DCfhcEUY.js +1 -0
  15. package/dist/client/assets/QuickConnect-DQGgUsl1.js +1 -0
  16. package/dist/client/assets/ShareDialog-C_plIto0.js +2 -0
  17. package/dist/client/assets/app-update-dialog-2hPz_N9G.js +1 -0
  18. package/dist/client/assets/circle-x-BZMPi8Zf.js +1 -0
  19. package/dist/client/assets/index-ByQRKVit.css +2 -0
  20. package/dist/client/assets/index-DweQ8Qtu.js +29 -0
  21. package/dist/client/assets/refresh-cw-CRow0Nbq.js +1 -0
  22. package/dist/client/assets/runtime-Bft6x_6E.js +4 -0
  23. package/dist/client/assets/square-A8EnIYLR.js +1 -0
  24. package/dist/client/assets/tts-dist-DYlBQmwG.js +18 -0
  25. package/dist/client/assets/tts-en-g2p-BPUtBFGG.js +1 -0
  26. package/dist/client/assets/tts-ort-wasm-simd-threaded-qh98TCA_.wasm +0 -0
  27. package/dist/client/assets/tts-ort.wasm.bundle.min-rEkcs_ow.js +12 -0
  28. package/dist/client/assets/tts-rolldown-runtime-D8NudN84.js +1 -0
  29. package/dist/client/assets/tts-spacy-en-tokenizer-6SNMl--A.json +1 -0
  30. package/dist/client/assets/tts-tts.worker-Bzm6aWbv.js +1 -0
  31. package/dist/client/assets/tts-us_gold-DcjeNMH1.json +92589 -0
  32. package/dist/client/assets/tts-us_silver-C964mEB5.json +93363 -0
  33. package/dist/client/assets/ui-CLbws0rx.js +41 -0
  34. package/dist/client/build-info.json +1 -0
  35. package/dist/client/favicon.svg +7 -0
  36. package/dist/client/icons/apple-touch-icon.png +0 -0
  37. package/dist/client/icons/icon-192.png +0 -0
  38. package/dist/client/icons/icon-512.png +0 -0
  39. package/dist/client/icons/maskable-512.png +0 -0
  40. package/dist/client/index.html +25 -0
  41. package/dist/client/manifest.webmanifest +15 -0
  42. package/dist/client/sw.js +53 -0
  43. package/dist/client/theme-boot.js +27 -0
  44. package/dist/console/assets/LocalAccountsApp-BQCcmj3x.js +1 -0
  45. package/dist/console/assets/LocalConsole-Bb2FUDs7.js +1 -0
  46. package/dist/console/assets/app-update-dialog-DIeYepLZ.js +1 -0
  47. package/dist/console/assets/console-C7uJLLOn.js +51 -0
  48. package/dist/console/assets/console-R8IBY3Am.css +2 -0
  49. package/dist/console/build-info.json +1 -0
  50. package/dist/console/console.html +21 -0
  51. package/dist/console/favicon.svg +7 -0
  52. package/dist/console/icons/apple-touch-icon.png +0 -0
  53. package/dist/console/icons/icon-192.png +0 -0
  54. package/dist/console/icons/icon-512.png +0 -0
  55. package/dist/console/icons/maskable-512.png +0 -0
  56. package/dist/console/manifest.webmanifest +15 -0
  57. package/dist/console/theme-boot.js +27 -0
  58. package/docs/agent-hardening.md +342 -0
  59. package/docs/agent-recipes.md +187 -0
  60. package/docs/agent-workflow.md +320 -0
  61. package/docs/agents.md +894 -0
  62. package/docs/architecture.md +242 -0
  63. package/docs/buzz.md +140 -0
  64. package/docs/capture-warnings.md +57 -0
  65. package/docs/config.md +489 -0
  66. package/docs/deployment.md +289 -0
  67. package/docs/design-system.md +162 -0
  68. package/docs/github.md +107 -0
  69. package/docs/hosted.md +764 -0
  70. package/docs/images/board-overview.png +0 -0
  71. package/docs/images/journeys.png +0 -0
  72. package/docs/images/live-comment.png +0 -0
  73. package/docs/images/phone-comment.png +0 -0
  74. package/docs/images/phone-overview.png +0 -0
  75. package/docs/images/variant.png +0 -0
  76. package/docs/interaction-audits.md +40 -0
  77. package/docs/journeys.md +137 -0
  78. package/docs/local-accounts.md +80 -0
  79. package/docs/notifications.md +237 -0
  80. package/docs/page-checks.md +69 -0
  81. package/docs/performance.md +174 -0
  82. package/docs/starter-agent.md +325 -0
  83. package/docs/updates.md +87 -0
  84. package/examples/audits/interaction.audit.json +17 -0
  85. package/package.json +132 -4
  86. package/src/accounts/avatar.js +121 -0
  87. package/src/accounts/local.js +464 -0
  88. package/src/agent/acp/command.js +204 -0
  89. package/src/agent/acp/detect.js +75 -0
  90. package/src/agent/acp/sandbox.js +160 -0
  91. package/src/agent/agent-health.js +75 -0
  92. package/src/agent/backends/acp.js +1297 -0
  93. package/src/agent/backends/index.js +61 -0
  94. package/src/agent/backends/openai.js +308 -0
  95. package/src/agent/composer.js +221 -0
  96. package/src/agent/config.js +338 -0
  97. package/src/agent/context.js +191 -0
  98. package/src/agent/control.js +122 -0
  99. package/src/agent/errors.js +17 -0
  100. package/src/agent/feedback-loop.js +137 -0
  101. package/src/agent/manage.js +94 -0
  102. package/src/agent/next-steps.js +51 -0
  103. package/src/agent/owner-mcp.js +38 -0
  104. package/src/agent/plain-text.js +52 -0
  105. package/src/agent/ratings-core.js +213 -0
  106. package/src/agent/ratings.js +100 -0
  107. package/src/agent/reply-text.js +67 -0
  108. package/src/agent/routes.js +1065 -0
  109. package/src/agent/run.js +326 -0
  110. package/src/agent/settings-routes.js +704 -0
  111. package/src/agent/showable.js +23 -0
  112. package/src/agent/starter/approvals.js +181 -0
  113. package/src/agent/starter/build-image.js +90 -0
  114. package/src/agent/starter/cli.js +163 -0
  115. package/src/agent/starter/disk.js +53 -0
  116. package/src/agent/starter/doctor.js +180 -0
  117. package/src/agent/starter/egress-proxy.js +351 -0
  118. package/src/agent/starter/gate.js +90 -0
  119. package/src/agent/starter/loop.js +114 -0
  120. package/src/agent/starter/model-relay.js +289 -0
  121. package/src/agent/starter/pause.js +14 -0
  122. package/src/agent/starter/probe.js +272 -0
  123. package/src/agent/starter/prompt.js +41 -0
  124. package/src/agent/starter/push-guard.js +146 -0
  125. package/src/agent/starter/rpc.js +164 -0
  126. package/src/agent/starter/runtime.js +287 -0
  127. package/src/agent/starter/sandbox-main.js +121 -0
  128. package/src/agent/starter/settings.js +290 -0
  129. package/src/agent/starter/source.js +69 -0
  130. package/src/agent/starter/supervisor.js +755 -0
  131. package/src/agent/starter/sweep.js +46 -0
  132. package/src/agent/starter/tools.js +524 -0
  133. package/src/agent/starter/watch.js +84 -0
  134. package/src/agent/starter/worktree.js +409 -0
  135. package/src/agent/text-diff.js +210 -0
  136. package/src/agent/thread-history.js +223 -0
  137. package/src/agent/threads.js +399 -0
  138. package/src/agent/tools.js +200 -0
  139. package/src/agent/turn-changes.js +424 -0
  140. package/src/agent/undo-state.js +26 -0
  141. package/src/agent/user-settings.js +308 -0
  142. package/src/auth/record.js +375 -0
  143. package/src/broken-links.js +164 -0
  144. package/src/buzz/client.js +75 -0
  145. package/src/buzz/config.js +151 -0
  146. package/src/buzz/environment.js +13 -0
  147. package/src/buzz/gateway.js +192 -0
  148. package/src/buzz/routes.js +61 -0
  149. package/src/buzz/signer-child.js +205 -0
  150. package/src/buzz/store.js +89 -0
  151. package/src/buzz/transport.js +60 -0
  152. package/src/buzz/verify.js +140 -0
  153. package/src/capture/actions.js +159 -0
  154. package/src/capture/capture.js +776 -0
  155. package/src/capture/dom-names.js +189 -0
  156. package/src/capture/element-map.js +509 -0
  157. package/src/capture/live.js +827 -0
  158. package/src/capture/media-scheme.js +317 -0
  159. package/src/capture/network-summary.js +86 -0
  160. package/src/capture/pacing.js +34 -0
  161. package/src/capture/requests.js +167 -0
  162. package/src/capture/sanitize.js +752 -0
  163. package/src/checks/accessibility.js +134 -0
  164. package/src/checks/budgets.js +58 -0
  165. package/src/checks/cli.js +55 -0
  166. package/src/checks/comparison.js +113 -0
  167. package/src/checks/environments.js +32 -0
  168. package/src/checks/flow-config.js +82 -0
  169. package/src/checks/flow-origin.js +53 -0
  170. package/src/checks/flows.js +398 -0
  171. package/src/checks/lighthouse-auth.js +145 -0
  172. package/src/checks/lighthouse-findings.js +130 -0
  173. package/src/checks/lighthouse.js +395 -0
  174. package/src/checks/robots.js +85 -0
  175. package/src/checks/routes.js +52 -0
  176. package/src/checks/run-control.js +259 -0
  177. package/src/checks/runner.js +724 -0
  178. package/src/checks/schema.js +133 -0
  179. package/src/checks/seo-analysis.js +443 -0
  180. package/src/checks/seo-probe.js +190 -0
  181. package/src/checks/seo-snapshot.js +99 -0
  182. package/src/checks/store.js +214 -0
  183. package/src/checks/transport.js +47 -0
  184. package/src/cli/args.js +319 -0
  185. package/src/cli/capture.js +79 -0
  186. package/src/cli/commands.js +92 -0
  187. package/src/cli/comments.js +84 -0
  188. package/src/cli/help.js +243 -0
  189. package/src/cli/init.js +214 -0
  190. package/src/cli/misc.js +64 -0
  191. package/src/cli/notify.js +87 -0
  192. package/src/cli/open.js +22 -0
  193. package/src/cli/serve.js +274 -0
  194. package/src/cli/variant.js +82 -0
  195. package/src/cli/watch.js +70 -0
  196. package/src/cli.js +130 -0
  197. package/src/comment-fields.js +76 -0
  198. package/src/comments-cli.js +208 -0
  199. package/src/config-reload.js +100 -0
  200. package/src/config.js +1061 -0
  201. package/src/devices-cli.js +21 -0
  202. package/src/diff.js +95 -0
  203. package/src/discover.js +284 -0
  204. package/src/doctor.js +295 -0
  205. package/src/event-log.js +268 -0
  206. package/src/events-cli.js +102 -0
  207. package/src/events.js +113 -0
  208. package/src/export.js +119 -0
  209. package/src/feedback.js +246 -0
  210. package/src/github.js +551 -0
  211. package/src/hosted/LICENSE.md +105 -0
  212. package/src/hosted/access-cli.js +78 -0
  213. package/src/hosted/admin.js +682 -0
  214. package/src/hosted/agent-approvals.js +163 -0
  215. package/src/hosted/agent-policy.js +189 -0
  216. package/src/hosted/app.js +510 -0
  217. package/src/hosted/auth-routes.js +540 -0
  218. package/src/hosted/auth.js +536 -0
  219. package/src/hosted/backup.js +483 -0
  220. package/src/hosted/board-context.js +35 -0
  221. package/src/hosted/board-routes.js +486 -0
  222. package/src/hosted/board-view.js +94 -0
  223. package/src/hosted/clean-worker.js +24 -0
  224. package/src/hosted/cleaner.js +89 -0
  225. package/src/hosted/comments.js +355 -0
  226. package/src/hosted/console-routes.js +401 -0
  227. package/src/hosted/cookies.js +18 -0
  228. package/src/hosted/crypto.js +80 -0
  229. package/src/hosted/db.js +496 -0
  230. package/src/hosted/device-routes.js +175 -0
  231. package/src/hosted/device.js +233 -0
  232. package/src/hosted/events.js +63 -0
  233. package/src/hosted/guards.js +172 -0
  234. package/src/hosted/guest-view.js +65 -0
  235. package/src/hosted/http.js +39 -0
  236. package/src/hosted/import.js +300 -0
  237. package/src/hosted/mail.js +73 -0
  238. package/src/hosted/mcp-http.js +71 -0
  239. package/src/hosted/membership.js +114 -0
  240. package/src/hosted/operator.js +478 -0
  241. package/src/hosted/ops-cli.js +345 -0
  242. package/src/hosted/pages.js +146 -0
  243. package/src/hosted/permissions.js +113 -0
  244. package/src/hosted/presence.js +372 -0
  245. package/src/hosted/projects.js +124 -0
  246. package/src/hosted/public.js +109 -0
  247. package/src/hosted/push.js +622 -0
  248. package/src/hosted/quotas.js +115 -0
  249. package/src/hosted/ratelimit.js +96 -0
  250. package/src/hosted/rebind.js +316 -0
  251. package/src/hosted/retention.js +128 -0
  252. package/src/hosted/server.js +260 -0
  253. package/src/hosted/setup-link.js +64 -0
  254. package/src/hosted/setup.js +323 -0
  255. package/src/hosted/shares.js +444 -0
  256. package/src/hosted/tailscale.js +204 -0
  257. package/src/hosted/tenancy.js +301 -0
  258. package/src/hosted/token-api.js +455 -0
  259. package/src/hosted/token-events.js +60 -0
  260. package/src/hosted/tokens.js +57 -0
  261. package/src/hosted/turnstile.js +49 -0
  262. package/src/hosted/usercontent.js +154 -0
  263. package/src/hosted/zip.js +155 -0
  264. package/src/invocation.js +58 -0
  265. package/src/journey-paths.js +282 -0
  266. package/src/journeys.js +189 -0
  267. package/src/links.js +106 -0
  268. package/src/local-projects.js +182 -0
  269. package/src/lock.js +193 -0
  270. package/src/mcp.js +417 -0
  271. package/src/mentions.js +151 -0
  272. package/src/net.js +15 -0
  273. package/src/notify/config.js +275 -0
  274. package/src/notify/index.js +301 -0
  275. package/src/notify/lease.js +73 -0
  276. package/src/notify/messages.js +212 -0
  277. package/src/notify/run.js +174 -0
  278. package/src/pixeldiff.js +49 -0
  279. package/src/png.js +143 -0
  280. package/src/reactions.js +111 -0
  281. package/src/remote/cli.js +133 -0
  282. package/src/remote/credentials.js +62 -0
  283. package/src/remote/ids.js +12 -0
  284. package/src/remote/login.js +155 -0
  285. package/src/remote/remote-mcp.js +237 -0
  286. package/src/remote/remote-watch.js +291 -0
  287. package/src/remote/remote.js +313 -0
  288. package/src/remote/share-state.js +78 -0
  289. package/src/remote/share.js +369 -0
  290. package/src/remote/terminal.js +13 -0
  291. package/src/serve-state.js +64 -0
  292. package/src/server/app.js +824 -0
  293. package/src/server/devices.js +186 -0
  294. package/src/server/local-console.js +28 -0
  295. package/src/server/local-user.js +59 -0
  296. package/src/server/pairing-routes.js +159 -0
  297. package/src/server/share-routes.js +89 -0
  298. package/src/server/tailscale.js +97 -0
  299. package/src/sitemap.js +431 -0
  300. package/src/store.js +983 -0
  301. package/src/tokens.js +11 -0
  302. package/src/update/routes.js +245 -0
  303. package/src/watch.js +403 -0
  304. package/src/which.js +58 -0
@@ -0,0 +1,75 @@
1
+ // Which ACP agents are installed on this machine, for the one-click Connect
2
+ // in an unconnected chat panel and the startup line of `shapewall serve`.
3
+ //
4
+ // Only PATH lookups: nothing is started, installed or downloaded here. Each
5
+ // agent is offered in the restricted form of the Settings > Agent buttons
6
+ // (client/src/settings/AgentSettings.jsx, docs/agent-hardening.md), and the
7
+ // command is this fixed list's, never one the board sends. The result is
8
+ // shown only on the token-protected settings route (src/agent/settings-routes.js)
9
+ // and in the terminal that runs `shapewall serve`.
10
+
11
+ import { lookupProgram } from '../../which.js'
12
+ import { loginHint } from './command.js'
13
+
14
+ // adapter: the program that speaks ACP. cli: the agent's own CLI, which on
15
+ // its own is not enough when an adapter is needed (Claude Code, Codex).
16
+ export const KNOWN_AGENTS = [
17
+ {
18
+ id: 'claude',
19
+ label: 'Claude Code',
20
+ adapter: 'claude-agent-acp',
21
+ command: 'claude-agent-acp',
22
+ cli: 'claude',
23
+ install: 'npm install -g @agentclientprotocol/claude-agent-acp',
24
+ },
25
+ {
26
+ id: 'codex',
27
+ label: 'Codex',
28
+ adapter: 'codex-acp',
29
+ command: 'codex-acp',
30
+ cli: 'codex',
31
+ install: 'npm install -g @agentclientprotocol/codex-acp',
32
+ },
33
+ {
34
+ id: 'goose',
35
+ label: 'goose',
36
+ adapter: 'goose',
37
+ command: 'goose acp --with-builtin developer',
38
+ cli: 'goose',
39
+ install: null,
40
+ },
41
+ {
42
+ id: 'gemini',
43
+ label: 'Gemini CLI',
44
+ adapter: 'gemini',
45
+ command: 'gemini --acp',
46
+ cli: 'gemini',
47
+ install: 'npm install -g @google/gemini-cli',
48
+ },
49
+ ]
50
+
51
+ // [{ id, label, command, state, path, install, login }] for the agents
52
+ // found; agents with neither the adapter nor the CLI are left out. state:
53
+ // 'ready' (Connect works), 'needs-adapter' (the CLI without its ACP
54
+ // adapter), 'needs-shell' (Windows: only a .cmd/.bat wrapper, which needs a
55
+ // shell Shapewall never uses; point Settings > Agent at node and the
56
+ // adapter's script instead). Absolute PATH entries only (src/which.js).
57
+ export function detectAgents(env = process.env, { platform = process.platform } = {}) {
58
+ const found = []
59
+ for (const agent of KNOWN_AGENTS) {
60
+ const adapter = lookupProgram(agent.adapter, env, { platform })
61
+ const cli = agent.cli === agent.adapter ? adapter : lookupProgram(agent.cli, env, { platform })
62
+ if (!adapter && !cli) continue
63
+ const state = adapter?.runnable ? 'ready' : adapter ? 'needs-shell' : 'needs-adapter'
64
+ found.push({
65
+ id: agent.id,
66
+ label: agent.label,
67
+ command: agent.command,
68
+ state,
69
+ path: (adapter || cli).path,
70
+ install: state === 'needs-adapter' ? agent.install : null,
71
+ login: loginHint(agent.command.split(' ')),
72
+ })
73
+ }
74
+ return found
75
+ }
@@ -0,0 +1,160 @@
1
+ // What an ACP agent may read and write through Shapewall (fs/read_text_file,
2
+ // fs/write_text_file): text files inside the project root, nowhere else.
3
+ //
4
+ // A path is checked after resolving symlinks (the native realpath, so case
5
+ // and short names on macOS and Windows resolve to the real file), so a link
6
+ // inside the project that points outside it is refused like the outside path
7
+ // itself. For a file that does not exist yet, the nearest folder that does is
8
+ // resolved instead. On case-insensitive systems paths are compared
9
+ // case-folded.
10
+ //
11
+ // Writes are refused inside .git and Shapewall's own store (comments, chat
12
+ // threads, captures), so an agent cannot rewrite the review it is reading.
13
+ // Files that decide what runs later (dotfiles and dot folders such as
14
+ // .claude, .codex, .gemini, .goose, .husky, .vscode, .envrc, .github, and
15
+ // package.json, shapewall.config.json, Makefile, Dockerfile, and the login
16
+ // script and storage state the config names) are
17
+ // `sensitive`: the bridge asks the person before writing one.
18
+
19
+ import fs from 'node:fs'
20
+ import path from 'node:path'
21
+ import { randomBytes } from 'node:crypto'
22
+
23
+ export const READ_BYTES_MAX = 4 * 1024 * 1024
24
+ export const WRITE_BYTES_MAX = 4 * 1024 * 1024
25
+ const FOLD = process.platform === 'darwin' || process.platform === 'win32'
26
+ const SENSITIVE_NAMES = new Set(['package.json', 'shapewall.config.json', 'makefile', 'dockerfile', 'justfile', 'taskfile.yml'])
27
+ const O_NOFOLLOW = fs.constants.O_NOFOLLOW || 0
28
+
29
+ export class SandboxError extends Error {
30
+ constructor(message) {
31
+ super(message)
32
+ this.code = 'sandbox'
33
+ }
34
+ }
35
+
36
+ const fold = (value) => (FOLD ? value.toLowerCase() : value)
37
+
38
+ export function inside(root, target) {
39
+ const relative = path.relative(fold(root), fold(target))
40
+ // A child named "..foo" is inside; only ".." itself or a "../" prefix leaves.
41
+ return relative === '' || (relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
42
+ }
43
+
44
+ const realpath = (value) => (fs.realpathSync.native || fs.realpathSync)(value)
45
+
46
+ // The real path of `target`, or of its nearest existing parent with the rest
47
+ // appended. Throws for anything that is not an absolute path.
48
+ function realTarget(target) {
49
+ if (typeof target !== 'string' || !target || target.includes('\0')) throw new SandboxError('a file path is required')
50
+ if (!path.isAbsolute(target)) throw new SandboxError('paths must be absolute')
51
+ let current = path.resolve(target)
52
+ const rest = []
53
+ for (;;) {
54
+ try {
55
+ return path.join(realpath(current), ...rest.reverse())
56
+ } catch (error) {
57
+ if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') throw new SandboxError(`cannot read ${target}`)
58
+ const parent = path.dirname(current)
59
+ if (parent === current) throw new SandboxError(`cannot resolve ${target}`)
60
+ rest.push(path.basename(current))
61
+ current = parent
62
+ }
63
+ }
64
+ }
65
+
66
+ // createSandbox({ root, protect }) -> { root, resolve, sensitive, read, write }.
67
+ // `protect` lists folders (inside the root) that may be read but not written.
68
+ // `sensitivePaths` (a list, or a function returning one) names more files
69
+ // that need approval to write: the config's auth.loginScript (capture runs
70
+ // it) and auth.storageState (the login capture uses).
71
+ export function createSandbox({ root, protect = [], sensitivePaths = [] }) {
72
+ const realRoot = realpath(root)
73
+ const realProtected = [path.join(realRoot, '.git'), ...protect.map((dir) => realTarget(path.resolve(dir)))]
74
+
75
+ const check = (target, real, write) => {
76
+ if (!inside(realRoot, real)) throw new SandboxError(`${target} is outside the project; only files under ${realRoot} are allowed`)
77
+ if (write && realProtected.some((dir) => inside(dir, real))) {
78
+ throw new SandboxError(`${target} is in a folder agents may not write (.git or the Shapewall store)`)
79
+ }
80
+ return real
81
+ }
82
+ const resolve = (target, { write = false } = {}) => check(target, realTarget(target), write)
83
+
84
+ // A real path (from resolve) that needs the person's approval to write.
85
+ const sensitive = (real) => {
86
+ const parts = path.relative(realRoot, real).split(path.sep).filter(Boolean)
87
+ if (parts.some((part) => part.startsWith('.'))) return true
88
+ const named = typeof sensitivePaths === 'function' ? sensitivePaths() : sensitivePaths
89
+ for (const file of Array.isArray(named) ? named : []) {
90
+ try {
91
+ if (typeof file === 'string' && file && fold(realTarget(path.resolve(file))) === fold(real)) return true
92
+ } catch {
93
+ // a path that cannot be resolved names no file here
94
+ }
95
+ }
96
+ return SENSITIVE_NAMES.has(fold(parts.at(-1) || '').toLowerCase())
97
+ }
98
+
99
+ return {
100
+ root: realRoot,
101
+ resolve,
102
+ sensitive,
103
+ // ACP's line is 1-based; limit is a number of lines.
104
+ read({ path: target, line = null, limit = null }) {
105
+ const file = resolve(target)
106
+ let stat
107
+ try {
108
+ stat = fs.statSync(file)
109
+ } catch {
110
+ throw new SandboxError(`${target} does not exist`)
111
+ }
112
+ if (!stat.isFile()) throw new SandboxError(`${target} is not a file`)
113
+ if (stat.size > READ_BYTES_MAX) throw new SandboxError(`${target} is larger than ${READ_BYTES_MAX / 1024 / 1024} MB`)
114
+ const content = fs.readFileSync(file, 'utf8')
115
+ if (!line && !limit) return content
116
+ const lines = content.split('\n')
117
+ const start = Math.max(0, (Number.isInteger(line) && line > 0 ? line : 1) - 1)
118
+ const end = Number.isInteger(limit) && limit > 0 ? start + limit : lines.length
119
+ return lines.slice(start, end).join('\n')
120
+ },
121
+ write({ path: target, content }) {
122
+ if (typeof content !== 'string') throw new SandboxError('content must be text')
123
+ if (Buffer.byteLength(content) > WRITE_BYTES_MAX) throw new SandboxError(`at most ${WRITE_BYTES_MAX / 1024 / 1024} MB per file`)
124
+ const file = resolve(target, { write: true })
125
+ fs.mkdirSync(path.dirname(file), { recursive: true })
126
+ // Check again once the folders exist: a symlink swapped in while they
127
+ // were made must not carry the write out of the project.
128
+ const dir = check(target, realpath(path.dirname(file)), true)
129
+ const final = path.join(dir, path.basename(file))
130
+ let mode = null
131
+ try {
132
+ const stat = fs.lstatSync(final)
133
+ if (stat.isSymbolicLink()) {
134
+ // Replaced, never followed: but only a link that stays inside.
135
+ check(target, realTarget(final), true)
136
+ } else if (!stat.isFile()) throw new SandboxError(`${target} is not a file`)
137
+ else mode = stat.mode & 0o777
138
+ } catch (error) {
139
+ if (error instanceof SandboxError) throw error
140
+ }
141
+ // Written through a new temporary file (exclusive, never through a
142
+ // link), then renamed over the target, so a reader never sees half of
143
+ // it and a link at the target is replaced, not followed.
144
+ const temp = path.join(dir, `.${path.basename(final)}.${randomBytes(6).toString('hex')}.tmp`)
145
+ const fd = fs.openSync(temp, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | O_NOFOLLOW, mode ?? 0o644)
146
+ try {
147
+ fs.writeSync(fd, content)
148
+ } finally {
149
+ fs.closeSync(fd)
150
+ }
151
+ try {
152
+ fs.renameSync(temp, final)
153
+ } catch (error) {
154
+ fs.rmSync(temp, { force: true })
155
+ throw error
156
+ }
157
+ return final
158
+ },
159
+ }
160
+ }
@@ -0,0 +1,75 @@
1
+ // How each connected agent is doing, in plain words, for the agent picker
2
+ // and Settings: derived only from what this server already saw (the last
3
+ // turn or connection test, and agent processes starting right now). Nothing
4
+ // polls an agent to find out.
5
+ //
6
+ // ready connected, and the last turn or test went fine (or none yet)
7
+ // login the last turn or test said it is not logged in (agent_auth)
8
+ // starting an agent process for it is starting now
9
+ // not-responding the last turn or test: it did not start, did not answer
10
+ // in time, or stopped
11
+ // unavailable not set up (no command, a removed profile)
12
+ //
13
+ // Kept in memory per server process; a restart starts from "ready".
14
+
15
+ import { loginHint } from './acp/command.js'
16
+
17
+ export const AGENT_STATES = ['ready', 'login', 'starting', 'not-responding', 'unavailable']
18
+
19
+ // One key per thing that runs: the default connection and the profile that
20
+ // runs the same command share what was learned about it.
21
+ export function healthKey(settings) {
22
+ if (!settings) return null
23
+ if (settings.backend === 'acp') return settings.acp?.argv ? `acp:${settings.acp.argv.join('\u0000')}` : null
24
+ return settings.baseUrl ? `api:${settings.baseUrl}|${settings.model || ''}` : null
25
+ }
26
+
27
+ // What one turn (a stored reply: { status, error }) or connection test
28
+ // ({ ok, code, message }) says: 'ok', 'login', 'not-responding', or null
29
+ // when it says nothing about the agent (stopped by the person, a tool error,
30
+ // a long answer cut at the time limit).
31
+ export function outcomeOf(result) {
32
+ if (!result) return null
33
+ if (result.ok === true) return 'ok'
34
+ const code = result.ok === false ? result.code : result.error?.code
35
+ if (code === 'agent_auth') return 'login'
36
+ if (result.ok === false) return /not (logged|signed) in/i.test(result.message || '') ? 'login' : 'not-responding'
37
+ if (['agent_start', 'agent_exited'].includes(code)) return 'not-responding'
38
+ if (result.status === 'done' && !result.error) return 'ok'
39
+ return null
40
+ }
41
+
42
+ // The state of one agent. `outcome`: the last outcomeOf; `starting`: an
43
+ // agent process for it is starting now.
44
+ export function agentState({ configured, outcome = null, starting = false }) {
45
+ if (!configured) return 'unavailable'
46
+ if (starting) return 'starting'
47
+ if (outcome === 'login') return 'login'
48
+ if (outcome === 'not-responding') return 'not-responding'
49
+ return 'ready'
50
+ }
51
+
52
+ // The store: record(settings, result) after a turn or test, and
53
+ // status(settings, pool) for the fields the board gets:
54
+ // { state, loginHint } (loginHint only for a native agent).
55
+ export function createAgentHealth() {
56
+ const last = new Map()
57
+ return {
58
+ record(settings, result) {
59
+ const key = healthKey(settings)
60
+ const outcome = outcomeOf(result)
61
+ if (key && outcome) last.set(key, outcome)
62
+ },
63
+ outcome(settings) {
64
+ return last.get(healthKey(settings)) || null
65
+ },
66
+ status(settings, processPool = null) {
67
+ const argv = settings?.acp?.argv ? settings.acp.argv.join('\u0000') : null
68
+ const starting = Boolean(
69
+ argv && [...(processPool?.agents || [])].some((agent) => agent.state === 'starting' && (agent.argv || []).join('\u0000') === argv),
70
+ )
71
+ const state = agentState({ configured: Boolean(settings?.configured), outcome: last.get(healthKey(settings)) || null, starting })
72
+ return { state, ...(settings?.backend === 'acp' && settings.acp?.argv ? { loginHint: loginHint(settings.acp.argv) } : {}) }
73
+ },
74
+ }
75
+ }