@synap-core/cli 1.12.2 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -8
  3. package/dist/build-info.json +2 -2
  4. package/dist/commands/agents.d.ts +0 -1
  5. package/dist/commands/agents.js +1 -1
  6. package/dist/commands/agents.js.map +1 -1
  7. package/dist/commands/app.js +2 -1
  8. package/dist/commands/app.js.map +1 -1
  9. package/dist/commands/automation.js +46 -41
  10. package/dist/commands/automation.js.map +1 -1
  11. package/dist/commands/box.d.ts +42 -0
  12. package/dist/commands/box.js +89 -0
  13. package/dist/commands/box.js.map +1 -0
  14. package/dist/commands/bridge-setup.js +3 -1
  15. package/dist/commands/bridge-setup.js.map +1 -1
  16. package/dist/commands/capability.d.ts +1 -1
  17. package/dist/commands/capability.js +57 -34
  18. package/dist/commands/capability.js.map +1 -1
  19. package/dist/commands/close-questions.d.ts +27 -0
  20. package/dist/commands/close-questions.js +49 -0
  21. package/dist/commands/close-questions.js.map +1 -0
  22. package/dist/commands/close-questions.test.d.ts +1 -0
  23. package/dist/commands/close-questions.test.js +52 -0
  24. package/dist/commands/close-questions.test.js.map +1 -0
  25. package/dist/commands/connect.d.ts +1 -3
  26. package/dist/commands/connect.js +2 -2
  27. package/dist/commands/connect.js.map +1 -1
  28. package/dist/commands/context.js +72 -43
  29. package/dist/commands/context.js.map +1 -1
  30. package/dist/commands/data-extra.js +12 -4
  31. package/dist/commands/data-extra.js.map +1 -1
  32. package/dist/commands/data.js +2 -1
  33. package/dist/commands/data.js.map +1 -1
  34. package/dist/commands/doctor.d.ts +21 -0
  35. package/dist/commands/doctor.js +108 -13
  36. package/dist/commands/doctor.js.map +1 -1
  37. package/dist/commands/hooks.d.ts +19 -0
  38. package/dist/commands/hooks.js +70 -0
  39. package/dist/commands/hooks.js.map +1 -0
  40. package/dist/commands/import.d.ts +25 -0
  41. package/dist/commands/import.js +98 -12
  42. package/dist/commands/import.js.map +1 -1
  43. package/dist/commands/init.d.ts +14 -0
  44. package/dist/commands/init.js +59 -19
  45. package/dist/commands/init.js.map +1 -1
  46. package/dist/commands/knowledge.js +4 -2
  47. package/dist/commands/knowledge.js.map +1 -1
  48. package/dist/commands/lens.js +2 -1
  49. package/dist/commands/lens.js.map +1 -1
  50. package/dist/commands/market-authoring.js +1 -1
  51. package/dist/commands/market-authoring.js.map +1 -1
  52. package/dist/commands/mcp.js +2 -2
  53. package/dist/commands/mcp.js.map +1 -1
  54. package/dist/commands/observe.category.test.d.ts +1 -0
  55. package/dist/commands/observe.category.test.js +59 -0
  56. package/dist/commands/observe.category.test.js.map +1 -0
  57. package/dist/commands/observe.d.ts +3 -0
  58. package/dist/commands/observe.js +7 -5
  59. package/dist/commands/observe.js.map +1 -1
  60. package/dist/commands/observe.title.test.d.ts +1 -0
  61. package/dist/commands/observe.title.test.js +37 -0
  62. package/dist/commands/observe.title.test.js.map +1 -0
  63. package/dist/commands/playbook.js +9 -0
  64. package/dist/commands/playbook.js.map +1 -1
  65. package/dist/commands/pods.d.ts +6 -1
  66. package/dist/commands/pods.js +32 -15
  67. package/dist/commands/pods.js.map +1 -1
  68. package/dist/commands/proton-setup.js +3 -1
  69. package/dist/commands/proton-setup.js.map +1 -1
  70. package/dist/commands/session-feed-wait.d.ts +48 -0
  71. package/dist/commands/session-feed-wait.js +261 -0
  72. package/dist/commands/session-feed-wait.js.map +1 -0
  73. package/dist/commands/session-post.d.ts +40 -0
  74. package/dist/commands/session-post.js +96 -0
  75. package/dist/commands/session-post.js.map +1 -0
  76. package/dist/commands/session-wait.d.ts +9 -4
  77. package/dist/commands/session-wait.js +20 -5
  78. package/dist/commands/session-wait.js.map +1 -1
  79. package/dist/commands/sessions.d.ts +2 -0
  80. package/dist/commands/sessions.js +23 -0
  81. package/dist/commands/sessions.js.map +1 -1
  82. package/dist/commands/skills-commands.d.ts +2 -0
  83. package/dist/commands/skills-commands.js +9 -1
  84. package/dist/commands/skills-commands.js.map +1 -1
  85. package/dist/commands/skills-commands.test.d.ts +1 -0
  86. package/dist/commands/skills-commands.test.js +57 -0
  87. package/dist/commands/skills-commands.test.js.map +1 -0
  88. package/dist/commands/status.js +1 -1
  89. package/dist/commands/status.js.map +1 -1
  90. package/dist/commands/template.d.ts +42 -0
  91. package/dist/commands/template.js +191 -0
  92. package/dist/commands/template.js.map +1 -0
  93. package/dist/commands/tracks.d.ts +67 -6
  94. package/dist/commands/tracks.js +268 -16
  95. package/dist/commands/tracks.js.map +1 -1
  96. package/dist/commands/whoami.d.ts +7 -0
  97. package/dist/commands/whoami.js +17 -0
  98. package/dist/commands/whoami.js.map +1 -1
  99. package/dist/commands/worker-accounts.d.ts +149 -0
  100. package/dist/commands/worker-accounts.js +339 -0
  101. package/dist/commands/worker-accounts.js.map +1 -0
  102. package/dist/commands/worker-accounts.test.d.ts +1 -0
  103. package/dist/commands/worker-accounts.test.js +224 -0
  104. package/dist/commands/worker-accounts.test.js.map +1 -0
  105. package/dist/commands/worker.d.ts +219 -10
  106. package/dist/commands/worker.js +749 -117
  107. package/dist/commands/worker.js.map +1 -1
  108. package/dist/commands/worker.test.js +321 -10
  109. package/dist/commands/worker.test.js.map +1 -1
  110. package/dist/index.js +164 -27
  111. package/dist/index.js.map +1 -1
  112. package/dist/lib/agent-door.d.ts +1 -3
  113. package/dist/lib/agent-door.js +10 -7
  114. package/dist/lib/agent-door.js.map +1 -1
  115. package/dist/lib/auth.d.ts +3 -2
  116. package/dist/lib/auth.js +3 -3
  117. package/dist/lib/auth.js.map +1 -1
  118. package/dist/lib/box/egress.d.ts +82 -0
  119. package/dist/lib/box/egress.js +264 -0
  120. package/dist/lib/box/egress.js.map +1 -0
  121. package/dist/lib/box/evidence.d.ts +86 -0
  122. package/dist/lib/box/evidence.js +121 -0
  123. package/dist/lib/box/evidence.js.map +1 -0
  124. package/dist/lib/box/job-server.d.ts +72 -0
  125. package/dist/lib/box/job-server.js +246 -0
  126. package/dist/lib/box/job-server.js.map +1 -0
  127. package/dist/lib/box/provisioner.d.ts +83 -0
  128. package/dist/lib/box/provisioner.js +312 -0
  129. package/dist/lib/box/provisioner.js.map +1 -0
  130. package/dist/lib/box/proxmox.d.ts +112 -0
  131. package/dist/lib/box/proxmox.js +211 -0
  132. package/dist/lib/box/proxmox.js.map +1 -0
  133. package/dist/lib/box/wire.d.ts +98 -0
  134. package/dist/lib/box/wire.js +70 -0
  135. package/dist/lib/box/wire.js.map +1 -0
  136. package/dist/lib/browser-auth.d.ts +35 -0
  137. package/dist/lib/browser-auth.js +170 -0
  138. package/dist/lib/browser-auth.js.map +1 -0
  139. package/dist/lib/client-header.test.d.ts +1 -0
  140. package/dist/lib/client-header.test.js +85 -0
  141. package/dist/lib/client-header.test.js.map +1 -0
  142. package/dist/lib/conversation-headers.d.ts +24 -9
  143. package/dist/lib/conversation-headers.js +40 -3
  144. package/dist/lib/conversation-headers.js.map +1 -1
  145. package/dist/lib/credential-class.d.ts +28 -1
  146. package/dist/lib/credential-class.js +28 -6
  147. package/dist/lib/credential-class.js.map +1 -1
  148. package/dist/lib/exporter-coverage.d.ts +1 -1
  149. package/dist/lib/exporter-coverage.js +1 -1
  150. package/dist/lib/goal-words.d.ts +38 -0
  151. package/dist/lib/goal-words.js +112 -0
  152. package/dist/lib/goal-words.js.map +1 -0
  153. package/dist/lib/hub-client.d.ts +28 -7
  154. package/dist/lib/hub-client.js +75 -34
  155. package/dist/lib/hub-client.js.map +1 -1
  156. package/dist/lib/init-handoff.d.ts +8 -0
  157. package/dist/lib/init-handoff.js +9 -2
  158. package/dist/lib/init-handoff.js.map +1 -1
  159. package/dist/lib/key-source.d.ts +3 -1
  160. package/dist/lib/key-source.js +7 -4
  161. package/dist/lib/key-source.js.map +1 -1
  162. package/dist/lib/knowledge-title.d.ts +3 -2
  163. package/dist/lib/knowledge-title.js +3 -2
  164. package/dist/lib/knowledge-title.js.map +1 -1
  165. package/dist/lib/mcp-bridge.d.ts +7 -0
  166. package/dist/lib/mcp-bridge.js +34 -1
  167. package/dist/lib/mcp-bridge.js.map +1 -1
  168. package/dist/lib/mcp-bridge.test.js +31 -3
  169. package/dist/lib/mcp-bridge.test.js.map +1 -1
  170. package/dist/lib/openclaw.d.ts +32 -0
  171. package/dist/lib/openclaw.js +165 -0
  172. package/dist/lib/openclaw.js.map +1 -0
  173. package/dist/lib/pod-moved.d.ts +70 -0
  174. package/dist/lib/pod-moved.js +146 -0
  175. package/dist/lib/pod-moved.js.map +1 -0
  176. package/dist/lib/pod-reach.d.ts +39 -0
  177. package/dist/lib/pod-reach.js +117 -0
  178. package/dist/lib/pod-reach.js.map +1 -0
  179. package/dist/lib/pod-reach.test.d.ts +1 -0
  180. package/dist/lib/pod-reach.test.js +67 -0
  181. package/dist/lib/pod-reach.test.js.map +1 -0
  182. package/dist/lib/pod.d.ts +8 -0
  183. package/dist/lib/pod.js +12 -3
  184. package/dist/lib/pod.js.map +1 -1
  185. package/dist/lib/register-claude-code-mcp.test.d.ts +1 -0
  186. package/dist/lib/register-claude-code-mcp.test.js +78 -0
  187. package/dist/lib/register-claude-code-mcp.test.js.map +1 -0
  188. package/dist/lib/review-credential.js +3 -1
  189. package/dist/lib/review-credential.js.map +1 -1
  190. package/dist/lib/seed.d.ts +13 -0
  191. package/dist/lib/seed.js +135 -0
  192. package/dist/lib/seed.js.map +1 -0
  193. package/dist/lib/session-feed.d.ts +185 -0
  194. package/dist/lib/session-feed.js +257 -0
  195. package/dist/lib/session-feed.js.map +1 -0
  196. package/dist/lib/targets.d.ts +21 -3
  197. package/dist/lib/targets.js +52 -107
  198. package/dist/lib/targets.js.map +1 -1
  199. package/dist/lib/wake-hook-settings.d.ts +57 -0
  200. package/dist/lib/wake-hook-settings.js +153 -0
  201. package/dist/lib/wake-hook-settings.js.map +1 -0
  202. package/dist/lib/wake-state.d.ts +65 -0
  203. package/dist/lib/wake-state.js +122 -0
  204. package/dist/lib/wake-state.js.map +1 -0
  205. package/package.json +5 -2
  206. package/skills/README.md +1 -1
  207. package/skills/agent-os/SKILL.md +8 -8
  208. package/skills/synap/SKILL.md +141 -84
  209. package/skills/synap/code-skills.md +70 -0
  210. package/skills/synap/concepts.md +28 -20
  211. package/skills/synap/creative-loop.md +1 -1
  212. package/skills/synap/document-embeds.md +3 -1
  213. package/skills/synap/focus-sessions.md +16 -7
  214. package/skills/synap/from-intent.md +32 -16
  215. package/skills/synap/governance-rules.md +1 -1
  216. package/skills/synap/lenses.md +4 -4
  217. package/skills/synap/linking.md +2 -2
  218. package/skills/synap/mental-model.md +1 -1
  219. package/skills/synap/operating-mode-rules.md +1 -1
  220. package/skills/synap/quick-reference.md +2 -1
  221. package/skills/synap/reflexes.md +6 -6
  222. package/skills/synap/viewframe-cells.md +1 -1
  223. package/skills/synap/work-model.md +24 -10
  224. package/skills/synap/workspace-design.md +5 -5
  225. package/skills/synap/writes.md +16 -9
  226. package/skills/synap-app/SKILL.md +148 -66
  227. package/skills/synap-app/creating-the-base-app.md +12 -7
  228. package/skills/synap-app/governance.md +27 -16
  229. package/skills/synap-app/install-commands.md +18 -9
  230. package/skills/synap-app/overview.md +16 -9
  231. package/skills/synap-app/using-the-sdk.md +75 -25
  232. package/skills/synap-schema/SKILL.md +21 -21
  233. package/skills/synap-schema/intent-vocabulary-ssot.md +21 -21
  234. package/templates/box/runner.py +206 -0
@@ -2,11 +2,17 @@
2
2
 
3
3
  ## Scaffold a full app (recommended for a fresh start)
4
4
 
5
+ > **Not published yet.** The scaffolder (`@synap-core/create-synap-app`) is not
6
+ > on npm and the base template is not public, so `npx` returns 404 today. Use the
7
+ > SDK path below until a release exists.
8
+
9
+ Once published:
10
+
5
11
  ```bash
6
- npx create-synap-app my-app
12
+ npx @synap-core/create-synap-app my-app
7
13
  ```
8
14
 
9
- Creates a Next.js + HeroUI project from the base template, with the SDK, auth,
15
+ It creates a Next.js + HeroUI project from the base template, with the SDK, auth,
10
16
  app shell, command palette, realtime, and mock mode pre-wired. It also drops an
11
17
  `AGENTS.md` into the project so your AI coding tool knows how to work with it.
12
18
 
@@ -22,24 +28,27 @@ npm install @synap-core/sdk@^1.0.0 @synap-core/react@^1.0.0
22
28
  # realtime
23
29
  npm install @synap-core/sdk-realtime
24
30
 
25
- # auth (browser sign-in) or auth-bootstrap (server credential bootstrap)
26
- npm install @synap-core/auth # or @synap-core/auth-bootstrap
31
+ # REST client for API-key holders (agents, scripts); also has setupAgent()
32
+ npm install @synap-core/hub-rest-client
27
33
  ```
28
34
 
35
+ Do not install `@synap-core/auth` (retired; its last release calls a removed pod
36
+ route) or `@synap-core/auth-bootstrap` (not published).
37
+
29
38
  Pin `@^1.0.0` on `sdk`/`react`. **Do not** install unpinned `@synap-core/sdk` —
30
39
  older `0.x` versions on the registry are a different, abandoned package.
31
40
 
32
41
  ## Get this knowledge into your AI coding tool
33
42
 
34
43
  ```bash
35
- # add the app-creation skill (this skill) to a connected AI tool
36
- synap skills get synap-app
44
+ # print this skill from your pod's skill knowledge base
45
+ synap skill get synap-app
37
46
 
38
- # or wire a tool end-to-end (skills + MCP), any target
39
- synap connect --target=cursor # or claude, …
47
+ # or wire a tool end-to-end (skills + MCP)
48
+ synap connect --target=cursor # or claude-code, claude-desktop, codex, …
40
49
  ```
41
50
 
42
- Alternatively, the scaffolded project ships an `AGENTS.md` at its root — most AI
51
+ Once the scaffolder is published, the scaffolded project ships an `AGENTS.md` at its root — most AI
43
52
  coding tools read it automatically, so a freshly-scaffolded app teaches the AI
44
53
  how to build on it with zero extra setup.
45
54
 
@@ -9,8 +9,8 @@ pod, and **every write is governed** (see `governance.md`).
9
9
  | The user has… | Do this | Read |
10
10
  |---|---|---|
11
11
  | an existing app (any framework) | add the SDK | `using-the-sdk.md`, `install-commands.md` |
12
- | nothing yet, wants a full app fast | scaffold the base app | `creating-the-base-app.md`, `install-commands.md` |
13
- | a server / script / CLI (no browser) | SDK with a session token or API key | `using-the-sdk.md` |
12
+ | nothing yet, wants a full app fast | scaffold the base app (scaffolder not published yet) | `creating-the-base-app.md`, `install-commands.md` |
13
+ | a server / script / CLI (no browser) | SDK with a session token, or the REST client with an API key | `using-the-sdk.md` |
14
14
 
15
15
  Both paths use the same underlying packages; only the amount of scaffolding differs.
16
16
 
@@ -18,9 +18,11 @@ Both paths use the same underlying packages; only the amount of scaffolding diff
18
18
 
19
19
  - `@synap-core/sdk` — typed tRPC client. `createSynapClient({ podUrl, ... })`. **The one you almost always want.**
20
20
  - `@synap-core/react` — React/TanStack-Query bindings (`SynapProvider`, hooks).
21
- - `@synap-core/sdk-realtime` — Socket.IO presence/live-updates (`createRealtimeClient`).
22
- - `@synap-core/auth` — sign-in orchestration (Synap Cloud + pod handshake), framework-agnostic.
23
- - `@synap-core/auth-bootstrap` — zero-dep server helpers (`setupAgent`, `handshake`) for machine clients.
21
+ - `@synap-core/sdk-realtime` — Socket.IO "something changed" events (`createRealtimeClient`).
22
+ - `@synap-core/hub-rest-client` — zero-dep REST client for API-key holders (`HubRestClient`, `setupAgent`).
23
+
24
+ Do not install `@synap-core/auth`: that package was retired, and its last npm
25
+ release signs in through a pod route that no longer exists.
24
26
 
25
27
  Pin `@^1.0.0` on `sdk`/`react` so you never resolve an old, abandoned `0.x`.
26
28
 
@@ -30,13 +32,18 @@ Pin `@^1.0.0` on `sdk`/`react` so you never resolve an old, abandoned `0.x`.
30
32
  the change is queued for the pod owner's review (like a PR). Surface the review,
31
33
  don't retry. Full contract: `governance.md`.
32
34
  2. **The pod URL has no `/trpc` suffix and no trailing slash.** The SDK appends `/trpc`.
33
- 3. **Non-browser clients (server/CLI/mobile) authenticate with a token or API key**,
34
- never a cookie. Browser apps use the Synap Cloud sign-in flow (`@synap-core/auth`).
35
+ 3. **Non-browser clients (server/CLI/mobile) authenticate with a session token or
36
+ an API key**, never a cookie. An API key only works on the REST client and
37
+ realtime, not on the tRPC SDK. Browser apps use the Kratos session cookie.
35
38
 
36
39
  ## Get a pod to build against
37
40
 
38
- - **Self-host (free):** `git clone` the backend, `docker compose up -d` (run its
39
- `install.sh` to generate secrets). Pod answers on `:4000`.
41
+ - **Self-host (free):** run the backend's `install.sh` (it installs Docker if
42
+ needed, fetches the release bundle, checks it against the release manifest's
43
+ sha256 and runs `synap install`); see the backend's `deploy/README.md`. It
44
+ also checks the manifest's signature: by default
45
+ (`SYNAP_RELEASE_VERIFY=warn`) it only warns and carries on when the signature
46
+ is missing or does not verify; `SYNAP_RELEASE_VERIFY=enforce` refuses.
40
47
  - **Managed (paid):** sign up at synap.live and provision a pod.
41
48
 
42
49
  You can develop the base app with **no pod at all** using its mock mode
@@ -7,33 +7,41 @@ import { createSynapClient } from "@synap-core/sdk";
7
7
 
8
8
  const synap = createSynapClient({
9
9
  podUrl: "https://pod.example.com", // NO trailing slash, NO /trpc suffix
10
- apiKey: process.env.SYNAP_API_KEY, // or sessionToken (see auth below)
10
+ sessionToken: process.env.SYNAP_SESSION_TOKEN, // see auth below
11
11
  workspaceId: process.env.SYNAP_WORKSPACE_ID ?? "",
12
+ onAuthError: () => {/* 401: sign in again */},
12
13
  });
13
14
 
14
15
  // It's a typed tRPC client — full autocomplete over every router.
15
16
  const me = await synap.users.me.query();
16
17
  const entities = await synap.entities.list.query({ /* filter */ });
17
18
  const result = await synap.entities.create.mutate({ /* ... */ });
18
- // result may be { status: "proposed", ... } — that is success. See governance.md.
19
+ // result.status may be "proposed" — that is success. See governance.md.
19
20
  ```
20
21
 
21
22
  ### Auth modes (pick ONE)
22
- - **`apiKey`** — a Bearer key generated in the workspace's developer settings.
23
- Best for servers, scripts, CLIs.
24
- - **`sessionToken`** — an Ory Kratos session token, sent as `X-Session-Token`.
25
- Best for non-browser clients that completed a sign-in.
26
- - **cookie fallback** — omit both; the client uses the ambient Kratos cookie.
27
- Browser, same-origin only.
28
-
29
- For machine clients that need to bootstrap a credential, use
30
- `@synap-core/auth-bootstrap` (`setupAgent(provisioningToken)` → API key,
31
- `handshake(jwt)` → session token). Zero-dependency, safe in edge/serverless.
23
+ - **`sessionToken`** — an Ory Kratos session token from a Kratos API (native)
24
+ login flow, sent as `X-Session-Token`. The normal choice for servers, scripts,
25
+ CLIs and mobile.
26
+ - **cookie fallback** — omit both; the client sends the ambient Kratos cookie
27
+ (`credentials: "include"`). Browser only.
28
+ - **`apiKey`** — only the local-mode token of a desktop pod, sent as
29
+ `Authorization: Bearer`. `/trpc` refuses hub and user API keys
30
+ (keys starting with synap_hub_ or synap_user_), and `createSynapClient` throws if you pass
31
+ one. For an API key, use `@synap-core/hub-rest-client` (below).
32
+
33
+ Other options: `extraHeaders`, and `onAuthError({ status, message })`, called on a
34
+ 401 (it also turns the pod's plain-JSON 401 body into a clean tRPC error).
35
+
36
+ To mint an API key for a machine client, `setupAgent(podUrl, provisioningToken,
37
+ agentType)` from `@synap-core/hub-rest-client` returns `{ hubApiKey, agentUserId,
38
+ workspaceId }`. That key works with the REST client and the realtime client, not
39
+ with `/trpc`.
32
40
 
33
41
  ## React — `@synap-core/react`
34
42
 
35
43
  ```tsx
36
- import { SynapProvider, useSynapContext } from "@synap-core/react";
44
+ import { SynapProvider, useSynap, useEntities } from "@synap-core/react";
37
45
 
38
46
  function App() {
39
47
  return (
@@ -42,31 +50,73 @@ function App() {
42
50
  </SynapProvider>
43
51
  );
44
52
  }
53
+
54
+ function Dashboard() {
55
+ const { data } = useEntities("note", { limit: 20 }); // thin data hook
56
+ const create = useSynap.entities.create.useMutation(); // raw tRPC hooks
57
+ // …
58
+ }
45
59
  ```
46
60
 
47
- `SynapProvider` honours every `createSynapClient` option, incl. `sessionToken`
48
- and `onAuthError` (a 401 handler). `react` is a peer of your app's React — it
49
- does not bundle its own.
61
+ `useSynap` is the tRPC React hook tree itself — write
62
+ `useSynap.entities.list.useQuery(…)`, **not** `useSynap().entities…`: calling it
63
+ returns `undefined` at runtime (some package docs still show the call form).
64
+
65
+ `SynapProvider` takes every `createSynapClient` option (incl. `sessionToken` and
66
+ `onAuthError`) plus an optional `queryClient` to share an existing TanStack Query
67
+ client. Exports: `SynapProvider`, `useSynapContext` (`{ podUrl, workspaceId }`),
68
+ `useSynap`, the data hooks `useEntity`, `useEntities`, `useLinks`, `useView`,
69
+ and the `RouterInputs` / `RouterOutputs` types. React 18 or 19 is a peer
70
+ dependency — the package does not bundle its own.
50
71
 
51
72
  ## Realtime — `@synap-core/sdk-realtime`
52
73
 
53
74
  ```ts
54
75
  import { createRealtimeClient } from "@synap-core/sdk-realtime";
55
76
 
56
- const rt = createRealtimeClient({ podUrl, sessionToken });
57
- const stop = rt.onInvalidate((target) => {
58
- // e.g. refetch the affected query
77
+ const rt = createRealtimeClient({
78
+ url: podUrl, // pod base URL; the client adds the /presence namespace
79
+ workspaceId,
80
+ sessionToken, // a Kratos session token…
81
+ userId, // …and the identity id it belongs to (both required)
82
+ // or, as a service account: apiKey (scope realtime:observe), no userId
83
+ onInvalidate: (event) => {
84
+ // entity/relation changed — refetch, e.g.
85
+ queryClient.invalidateQueries({ queryKey: ["entities"] });
86
+ },
59
87
  });
88
+
89
+ rt.connect(); // nothing connects until you call this
90
+ // … later
91
+ rt.disconnect();
60
92
  ```
61
93
 
62
- Websocket-only transport (credentials never ride a long-poll URL) and it refuses
63
- to send credentials over non-TLS unless you explicitly pass `allowInsecure`.
94
+ - Callbacks (all options, no subscribe methods): `onInvalidate` (the
95
+ entity/relation-changing subset), `onEvent` (every known event, `{ name, data }`),
96
+ `onConnect`, `onDisconnect(reason)`, `onError(error)`.
97
+ - The returned client has `connect()`, `disconnect()`, and read-only `connected`
98
+ and `state` (`"idle" | "connecting" | "connected" | "disconnected"`).
99
+ - `SYNAP_EVENT_NAMES` lists the forwarded events; `ENTITY_INVALIDATING_EVENTS` is
100
+ the subset behind `onInvalidate`.
101
+ - Websocket-only transport (credentials never ride a long-poll URL), and
102
+ `connect()` throws on a non-TLS URL unless you pass `allowInsecure: true`
103
+ (localhost dev only).
104
+
105
+ **Version note.** `@synap-core/sdk-realtime@0.1.0` (the current npm release) sends
106
+ every credential as `auth.token`. The pod reads `{ userId, token, workspaceId }`
107
+ for a user and `{ apiKey, workspaceId }` for a service account, so on 0.1.0 a
108
+ session token works only when you also pass `userId`, and an `apiKey` is always
109
+ refused. The fix — correct handshake keys, plus an up-front throw for no
110
+ credential, both credentials, or `sessionToken` without `userId` — lands in the
111
+ first release after 0.1.0. Until then, authenticate realtime with
112
+ `sessionToken` + `userId`.
64
113
 
65
114
  ## Two transports, on purpose
66
- - `@synap-core/sdk` (tRPC) — for apps. Typed, hooks, realtime.
67
- - `@synap-core/hub-rest-client` (REST, zero-dep) — for agents/CLIs/scripts. Carries
68
- agent verbs the tRPC surface has no first-class path for (`ask`, `orient`,
69
- `discover`). Use it when you want a dependency-free REST client, not a full app.
115
+ - `@synap-core/sdk` (tRPC) — for apps signed in as a user. Typed, React hooks.
116
+ - `@synap-core/hub-rest-client` (REST against `/api/hub/*`, zero-dep) — for
117
+ agents/CLIs/scripts holding an API key. `new HubRestClient({ podUrl, apiKey,
118
+ workspaceId })`. Carries agent verbs the tRPC surface has no first-class path
119
+ for (`ask`, `orient`, `discover`).
70
120
 
71
121
  ## Keep types fresh
72
122
  The SDK is typed by `@synap-core/api-types`, generated from the pod's live router.
@@ -315,7 +315,7 @@ Defining a relation def is rarely worth it — `relates_to` + a property usually
315
315
 
316
316
  ---
317
317
 
318
- ## The intent vocabulary — one SSOT, three mirrors
318
+ ## The intent vocabulary — one SSOT, two mirrors
319
319
 
320
320
  **What a capability DOES** — `send_message`, `generate_media`, `publish_post`,
321
321
  `delegate_agent_task` — is the
@@ -346,15 +346,17 @@ This is why every code-side copy is a **mirror** and not the source. A slug that
346
346
  none of the existing rows leaves `intent` UNSET; the vocabulary is deliberately not
347
347
  open for developers to mint (cf. W3C Web Intents, abandoned partly for that reason).
348
348
 
349
- ### The three mirrors, and why each one must exist
349
+ ### The two mirrors, and why each one must exist
350
350
 
351
- There are exactly **three**. A fourth was deleted in 2026-10-01 (see below).
351
+ There are exactly **two**. Two more were removed: `AbstractVerb` in
352
+ `@synap/playbooks` (deleted 2026-10-01, see below), and the pod's own
353
+ `ABSTRACT_VERBS` copy (collapsed 2026-10-26 — `@synap/database` now depends on
354
+ `@synap-core/types`, so it re-exports mirror 1 under that name).
352
355
 
353
- | # | Where | Kind | Why it cannot import the SSOT |
354
- | --- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
355
- | 1 | `synap-backend/packages/database/src/schema/tools.ts` — `ABSTRACT_VERBS` | runtime, the 0283 SEED union (13) | `@synap-core/types` **devDepends on** `@synap/database`. A reverse import is a build cycle — the same constraint that forces `GUIDELINE_SCOPE_ORDER` to be mirrored. |
356
- | 2 | `synap-backend/packages/types/src/capability-intents/` — `ABSTRACT_INTENTS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, published leaf | Same cycle, other direction. It is a **leaf subpath** (`@synap-core/types/capability-intents`) rather than the `./` barrel because the barrel re-exports `@synap/database` types and a VALUE import from a barrel crashes Hermes (relay ships React Native). |
357
- | 3 | `synap-control-plane-api/src/seeds/capability-intent-vocabulary.ts` — `ABSTRACT_VERBS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, the CP catalog seeder | The control plane is a **separate deploy target with its own `pnpm-lock.yaml`**. It resolves neither `@synap-core/types` nor the pod's packages (verified: `require.resolve('@synap-core/types')` → `MODULE_NOT_FOUND`). |
356
+ | # | Where | Kind | Why it cannot import the SSOT |
357
+ | --- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
358
+ | 1 | `synap-backend/packages/types/src/capability-intents/` — `ABSTRACT_INTENTS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, published leaf | The SSOT is SQL rows; a TypeScript list is a mirror by construction. The pod reads it too: `ABSTRACT_VERBS` in `packages/database/src/schema/tools.ts` is this `ABSTRACT_INTENTS`, re-exported (the 0283 SEED union, 13). |
359
+ | 2 | `synap-control-plane-api/src/seeds/capability-intent-vocabulary.ts` — `ABSTRACT_VERBS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, the CP catalog seeder | The control plane is a **separate deploy target with its own `pnpm-lock.yaml`**. It resolves neither `@synap-core/types` nor the pod's packages (verified: `require.resolve('@synap-core/types')` → `MODULE_NOT_FOUND`). |
358
360
 
359
361
  Consumed by: `@synap/api` (`intent-registry`, `create-from-definition`,
360
362
  `schemas/playbook-definition.ts`), `synap-app/packages/workspace-templates`
@@ -377,7 +379,7 @@ Search for this chapter by the field you are holding, not by the word "intent":
377
379
  All four are validated against this ONE vocabulary, so a workspace and a playbook
378
380
  cannot be spelled from two different lists.
379
381
 
380
- ### THE FOURTH MIRROR WAS DELETED — do not re-add it
382
+ ### THE PLAYBOOKS MIRROR WAS DELETED — do not re-add it
381
383
 
382
384
  `AbstractVerb` in `@synap/playbooks/src/index.ts` was a TYPE-only mirror of all 13
383
385
  slugs. It was **stale** (no `publish_post`) and **dead** — a whole-repo scan across
@@ -396,18 +398,16 @@ a package that consumes nothing would go stale in the one direction that is invi
396
398
  `INSERT INTO "capability_intents" ("slug", "effect", "statement") VALUES (...) ON CONFLICT ("slug") DO NOTHING;`
397
399
  `effect` ∈ `read|write|act`. Never `drizzle-kit generate` — hand-write it, and mirror it into
398
400
  `0000_baseline_schema.sql` if it adds a table or column.
399
- 2. **Add it to mirror 1** — `ABSTRACT_VERBS` in `packages/database/src/schema/tools.ts`,
400
- **only if it is a SEED slug**. A post-seed row does not belong there (that is what
401
- `publish_post` / `REGISTERED_EXTRAS` is for).
402
- Post-seed rows today: `publish_post` (0284, write) and `delegate_agent_task`
403
- (0314, act — every verb of an external-agent binding, `tools.config.agentBinding`:
404
- start / send / status / cancel).
405
- 3. **Add it to mirror 2** — `ABSTRACT_INTENTS` or `REGISTERED_EXTRAS` in
406
- `packages/types/src/capability-intents/index.ts`. Then **`cd packages/types && pnpm build`** —
401
+ 2. **Add it to mirror 1** — `ABSTRACT_INTENTS` (a SEED slug) or `REGISTERED_EXTRAS`
402
+ (a post-seed row) in `packages/types/src/capability-intents/index.ts`. The pod's
403
+ `ABSTRACT_VERBS` is `ABSTRACT_INTENTS`, so it follows. Then **`cd packages/types && pnpm build`** —
407
404
  consumers typecheck against the built `dist/`, so a skipped rebuild makes your gate lie.
408
- 4. **Add it to mirror 3** — the same two lists in the control plane's
405
+ Post-seed rows today: `publish_post` (0284, write), `delegate_agent_task`
406
+ (0314, act — every verb of an external-agent binding, `tools.config.agentBinding`:
407
+ start / send / status / cancel) and `read_webpage` (0329).
408
+ 3. **Add it to mirror 2** — the same two lists in the control plane's
409
409
  `capability-intent-vocabulary.ts`.
410
- 5. **Update the arity floors** — `SEED_SLUG_ARITY` / `EXTRA_SLUG_ARITY` in
410
+ 4. **Update the arity floors** — `SEED_SLUG_ARITY` / `EXTRA_SLUG_ARITY` in
411
411
  `packages/api/src/__tripwires__/intent-vocabulary-one-ssot.tripwire.test.ts`.
412
412
  These are the ONE place you must edit by hand, and the build stops until you do.
413
413
 
@@ -416,8 +416,8 @@ from the migration SQL, so it is a red build — never a divergence nobody notic
416
416
 
417
417
  ### What can still go wrong
418
418
 
419
- - **A mirror can be added.** Nothing structurally prevents a fifth copy; the tripwire
420
- only polices the names it knows. This is why step 5 exists as a hand-edit floor.
419
+ - **A mirror can be added.** Nothing structurally prevents a third copy; the tripwire
420
+ only polices the names it knows. This is why step 4 exists as a hand-edit floor.
421
421
  - **A guard proves SAMENESS, never CORRECTNESS.** If every mirror and the migration agree
422
422
  on a slug that should not exist, all four guards stay green. The vocabulary's MEANING is
423
423
  reviewed by a human, not derived.
@@ -1,4 +1,4 @@
1
- ## The intent vocabulary — one SSOT, three mirrors
1
+ ## The intent vocabulary — one SSOT, two mirrors
2
2
 
3
3
  **What a capability DOES** — `send_message`, `generate_media`, `publish_post`,
4
4
  `delegate_agent_task` — is the
@@ -29,15 +29,17 @@ This is why every code-side copy is a **mirror** and not the source. A slug that
29
29
  none of the existing rows leaves `intent` UNSET; the vocabulary is deliberately not
30
30
  open for developers to mint (cf. W3C Web Intents, abandoned partly for that reason).
31
31
 
32
- ### The three mirrors, and why each one must exist
32
+ ### The two mirrors, and why each one must exist
33
33
 
34
- There are exactly **three**. A fourth was deleted in 2026-10-01 (see below).
34
+ There are exactly **two**. Two more were removed: `AbstractVerb` in
35
+ `@synap/playbooks` (deleted 2026-10-01, see below), and the pod's own
36
+ `ABSTRACT_VERBS` copy (collapsed 2026-10-26 — `@synap/database` now depends on
37
+ `@synap-core/types`, so it re-exports mirror 1 under that name).
35
38
 
36
- | # | Where | Kind | Why it cannot import the SSOT |
37
- | --- | --------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
38
- | 1 | `synap-backend/packages/database/src/schema/tools.ts` — `ABSTRACT_VERBS` | runtime, the 0283 SEED union (13) | `@synap-core/types` **devDepends on** `@synap/database`. A reverse import is a build cycle — the same constraint that forces `GUIDELINE_SCOPE_ORDER` to be mirrored. |
39
- | 2 | `synap-backend/packages/types/src/capability-intents/` — `ABSTRACT_INTENTS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, published leaf | Same cycle, other direction. It is a **leaf subpath** (`@synap-core/types/capability-intents`) rather than the `./` barrel because the barrel re-exports `@synap/database` types and a VALUE import from a barrel crashes Hermes (relay ships React Native). |
40
- | 3 | `synap-control-plane-api/src/seeds/capability-intent-vocabulary.ts` — `ABSTRACT_VERBS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, the CP catalog seeder | The control plane is a **separate deploy target with its own `pnpm-lock.yaml`**. It resolves neither `@synap-core/types` nor the pod's packages (verified: `require.resolve('@synap-core/types')` → `MODULE_NOT_FOUND`). |
39
+ | # | Where | Kind | Why it cannot import the SSOT |
40
+ | --- | --------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
41
+ | 1 | `synap-backend/packages/types/src/capability-intents/` — `ABSTRACT_INTENTS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, published leaf | The SSOT is SQL rows; a TypeScript list is a mirror by construction. The pod reads it too: `ABSTRACT_VERBS` in `packages/database/src/schema/tools.ts` is this `ABSTRACT_INTENTS`, re-exported (the 0283 SEED union, 13). |
42
+ | 2 | `synap-control-plane-api/src/seeds/capability-intent-vocabulary.ts` — `ABSTRACT_VERBS`, `REGISTERED_EXTRAS`, `CAPABILITY_INTENTS` | runtime, the CP catalog seeder | The control plane is a **separate deploy target with its own `pnpm-lock.yaml`**. It resolves neither `@synap-core/types` nor the pod's packages (verified: `require.resolve('@synap-core/types')` → `MODULE_NOT_FOUND`). |
41
43
 
42
44
  Consumed by: `@synap/api` (`intent-registry`, `create-from-definition`,
43
45
  `schemas/playbook-definition.ts`), `synap-app/packages/workspace-templates`
@@ -60,7 +62,7 @@ Search for this chapter by the field you are holding, not by the word "intent":
60
62
  All four are validated against this ONE vocabulary, so a workspace and a playbook
61
63
  cannot be spelled from two different lists.
62
64
 
63
- ### THE FOURTH MIRROR WAS DELETED — do not re-add it
65
+ ### THE PLAYBOOKS MIRROR WAS DELETED — do not re-add it
64
66
 
65
67
  `AbstractVerb` in `@synap/playbooks/src/index.ts` was a TYPE-only mirror of all 13
66
68
  slugs. It was **stale** (no `publish_post`) and **dead** — a whole-repo scan across
@@ -79,18 +81,16 @@ a package that consumes nothing would go stale in the one direction that is invi
79
81
  `INSERT INTO "capability_intents" ("slug", "effect", "statement") VALUES (...) ON CONFLICT ("slug") DO NOTHING;`
80
82
  `effect` ∈ `read|write|act`. Never `drizzle-kit generate` — hand-write it, and mirror it into
81
83
  `0000_baseline_schema.sql` if it adds a table or column.
82
- 2. **Add it to mirror 1** — `ABSTRACT_VERBS` in `packages/database/src/schema/tools.ts`,
83
- **only if it is a SEED slug**. A post-seed row does not belong there (that is what
84
- `publish_post` / `REGISTERED_EXTRAS` is for).
85
- Post-seed rows today: `publish_post` (0284, write) and `delegate_agent_task`
86
- (0314, act — every verb of an external-agent binding, `tools.config.agentBinding`:
87
- start / send / status / cancel).
88
- 3. **Add it to mirror 2** — `ABSTRACT_INTENTS` or `REGISTERED_EXTRAS` in
89
- `packages/types/src/capability-intents/index.ts`. Then **`cd packages/types && pnpm build`** —
84
+ 2. **Add it to mirror 1** — `ABSTRACT_INTENTS` (a SEED slug) or `REGISTERED_EXTRAS`
85
+ (a post-seed row) in `packages/types/src/capability-intents/index.ts`. The pod's
86
+ `ABSTRACT_VERBS` is `ABSTRACT_INTENTS`, so it follows. Then **`cd packages/types && pnpm build`** —
90
87
  consumers typecheck against the built `dist/`, so a skipped rebuild makes your gate lie.
91
- 4. **Add it to mirror 3** — the same two lists in the control plane's
88
+ Post-seed rows today: `publish_post` (0284, write), `delegate_agent_task`
89
+ (0314, act — every verb of an external-agent binding, `tools.config.agentBinding`:
90
+ start / send / status / cancel) and `read_webpage` (0329).
91
+ 3. **Add it to mirror 2** — the same two lists in the control plane's
92
92
  `capability-intent-vocabulary.ts`.
93
- 5. **Update the arity floors** — `SEED_SLUG_ARITY` / `EXTRA_SLUG_ARITY` in
93
+ 4. **Update the arity floors** — `SEED_SLUG_ARITY` / `EXTRA_SLUG_ARITY` in
94
94
  `packages/api/src/__tripwires__/intent-vocabulary-one-ssot.tripwire.test.ts`.
95
95
  These are the ONE place you must edit by hand, and the build stops until you do.
96
96
 
@@ -99,8 +99,8 @@ from the migration SQL, so it is a red build — never a divergence nobody notic
99
99
 
100
100
  ### What can still go wrong
101
101
 
102
- - **A mirror can be added.** Nothing structurally prevents a fifth copy; the tripwire
103
- only polices the names it knows. This is why step 5 exists as a hand-edit floor.
102
+ - **A mirror can be added.** Nothing structurally prevents a third copy; the tripwire
103
+ only polices the names it knows. This is why step 4 exists as a hand-edit floor.
104
104
  - **A guard proves SAMENESS, never CORRECTNESS.** If every mirror and the migration agree
105
105
  on a slug that should not exist, all four guards stay green. The vocabulary's MEANING is
106
106
  reviewed by a human, not derived.
@@ -0,0 +1,206 @@
1
+ #!/usr/bin/env python3
2
+ """The synap box runner: the only program the box template starts on boot.
3
+
4
+ It holds no credential. It fetches its job from the provisioner by the
5
+ provisioner's address on the isolated bridge, installs the declared packages
6
+ (setup phase: the egress proxy lets only the package registries through),
7
+ tells the provisioner it is done installing (run phase: only the declared
8
+ hosts), runs the script as the unprivileged user `box` with /in and /out,
9
+ streams the log back, uploads /out and reports the exit code.
10
+
11
+ The provisioner, not this program, enforces the wall clock: it destroys the box.
12
+ Python stdlib only (Debian 12's python3), so the template needs nothing else to
13
+ run it. Contract with the provisioner: synap-cli src/lib/box/job-server.ts.
14
+ """
15
+
16
+ import json
17
+ import os
18
+ import pwd
19
+ import subprocess
20
+ import sys
21
+ import threading
22
+ import time
23
+ import urllib.parse
24
+ import urllib.request
25
+
26
+ BASE = os.environ.get("SYNAP_BOX_PROVISIONER", "http://10.20.0.1:8790")
27
+ PROXY = os.environ.get("SYNAP_BOX_PROXY", "http://10.20.0.1:3128")
28
+ WORK, IN, OUT = "/work", "/in", "/out"
29
+ USER = "box"
30
+ MAX_OUT_FILES = 20
31
+
32
+ # The job server is on the bridge: never through the proxy.
33
+ _direct = urllib.request.build_opener(urllib.request.ProxyHandler({}))
34
+
35
+
36
+ def call(method, path, body=None, ctype="application/json", timeout=60):
37
+ data = body if isinstance(body, (bytes, type(None))) else json.dumps(body).encode()
38
+ req = urllib.request.Request(BASE + path, data=data, method=method)
39
+ if data is not None:
40
+ req.add_header("Content-Type", ctype)
41
+ with _direct.open(req, timeout=timeout) as res:
42
+ raw = res.read()
43
+ return json.loads(raw) if raw and res.headers.get("content-type", "").startswith("application/json") else None
44
+
45
+
46
+ def fetch_job():
47
+ # The box may boot before the provisioner registers its address: retry.
48
+ deadline = time.time() + 180
49
+ while True:
50
+ try:
51
+ return call("GET", "/job")
52
+ except Exception as err: # noqa: BLE001
53
+ if time.time() > deadline:
54
+ raise SystemExit(f"no job from {BASE}: {err}")
55
+ time.sleep(2)
56
+
57
+
58
+ class LogPump:
59
+ """Batches output and POSTs it to /log about twice a second."""
60
+
61
+ def __init__(self):
62
+ self.buf = bytearray()
63
+ self.lock = threading.Lock()
64
+ self.stop = threading.Event()
65
+ self.thread = threading.Thread(target=self._loop, daemon=True)
66
+ self.thread.start()
67
+
68
+ def write(self, data):
69
+ with self.lock:
70
+ self.buf += data
71
+
72
+ def _flush(self):
73
+ with self.lock:
74
+ chunk, self.buf = bytes(self.buf), bytearray()
75
+ if chunk:
76
+ try:
77
+ call("POST", "/log", chunk, "application/octet-stream")
78
+ except Exception: # noqa: BLE001 - a lost log chunk must not kill the run
79
+ pass
80
+
81
+ def _loop(self):
82
+ while not self.stop.wait(0.5):
83
+ self._flush()
84
+
85
+ def close(self):
86
+ self.stop.set()
87
+ self.thread.join()
88
+ self._flush()
89
+
90
+
91
+ def demote(user):
92
+ pw = pwd.getpwnam(user)
93
+
94
+ def run_as():
95
+ os.setgroups([])
96
+ os.setgid(pw.pw_gid)
97
+ os.setuid(pw.pw_uid)
98
+
99
+ return run_as, pw
100
+
101
+
102
+ def run(cmd, env, pump):
103
+ """Run cmd as the box user; its stdout+stderr go to the log. Returns the exit code."""
104
+ pre, pw = demote(USER)
105
+ pump.write(("$ " + " ".join(cmd) + "\n").encode())
106
+ proc = subprocess.Popen(
107
+ cmd, cwd=WORK, env={**env, "HOME": pw.pw_dir, "USER": USER},
108
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=pre,
109
+ )
110
+ for chunk in iter(lambda: proc.stdout.read1(65536), b""):
111
+ pump.write(chunk)
112
+ return proc.wait()
113
+
114
+
115
+ def installed(job, env):
116
+ try:
117
+ if job["language"] == "python":
118
+ out = subprocess.run(
119
+ ["uv", "pip", "list", "--python", f"{WORK}/.venv/bin/python", "--format", "json"],
120
+ cwd=WORK, env=env, capture_output=True, timeout=60,
121
+ ).stdout
122
+ return [{"name": p["name"], "version": p["version"], "manager": "pip"} for p in json.loads(out or b"[]")]
123
+ out = subprocess.run(
124
+ ["pnpm", "list", "--json", "--depth", "0"], cwd=WORK, env=env, capture_output=True, timeout=60,
125
+ ).stdout
126
+ deps = (json.loads(out or b"[{}]") or [{}])[0].get("dependencies", {}) or {}
127
+ return [{"name": n, "version": d.get("version", ""), "manager": "npm"} for n, d in deps.items()]
128
+ except Exception: # noqa: BLE001 - the list is evidence, not the verdict
129
+ return []
130
+
131
+
132
+ def upload_out(pump):
133
+ sent = 0
134
+ for root, _dirs, files in os.walk(OUT):
135
+ for name in sorted(files):
136
+ full = os.path.join(root, name)
137
+ if os.path.islink(full) or not os.path.isfile(full):
138
+ continue
139
+ rel = os.path.relpath(full, OUT)
140
+ if sent >= MAX_OUT_FILES:
141
+ pump.write(f"\n[synap box] /out/{rel} skipped: at most {MAX_OUT_FILES} files\n".encode())
142
+ continue
143
+ try:
144
+ with open(full, "rb") as fh:
145
+ call("PUT", "/out/" + urllib.parse.quote(rel), fh.read(), "application/octet-stream", timeout=600)
146
+ sent += 1
147
+ except Exception as err: # noqa: BLE001
148
+ pump.write(f"\n[synap box] /out/{rel} not uploaded: {err}\n".encode())
149
+
150
+
151
+ def main():
152
+ job = fetch_job()
153
+ pump = LogPump()
154
+ for d in (WORK, IN, OUT):
155
+ os.makedirs(d, exist_ok=True)
156
+ pw = pwd.getpwnam(USER)
157
+ for d in (WORK, OUT):
158
+ os.chown(d, pw.pw_uid, pw.pw_gid)
159
+
160
+ entry = os.path.normpath(job["entrypoint"])
161
+ if entry.startswith("..") or os.path.isabs(entry):
162
+ raise SystemExit(f"bad entrypoint {job['entrypoint']!r}")
163
+ os.makedirs(os.path.dirname(os.path.join(WORK, entry)), exist_ok=True)
164
+ with open(os.path.join(WORK, entry), "w") as fh:
165
+ fh.write(job["code"])
166
+ os.chown(os.path.join(WORK, entry), pw.pw_uid, pw.pw_gid)
167
+ with open(os.path.join(IN, "parameters.json"), "w") as fh:
168
+ json.dump(job.get("parameters"), fh)
169
+
170
+ env = {
171
+ "PATH": "/usr/local/bin:/usr/bin:/bin",
172
+ "LANG": "C.UTF-8",
173
+ "HTTP_PROXY": PROXY, "HTTPS_PROXY": PROXY, "http_proxy": PROXY, "https_proxy": PROXY,
174
+ "npm_config_proxy": PROXY, "npm_config_https_proxy": PROXY,
175
+ # Node's own fetch ignores HTTP(S)_PROXY unless told (Node >= 22.21 / 24).
176
+ "NODE_USE_ENV_PROXY": "1",
177
+ "UV_CACHE_DIR": f"{WORK}/.cache/uv", "npm_config_cache": f"{WORK}/.cache/npm",
178
+ "SYNAP_PARAMETERS_FILE": f"{IN}/parameters.json", "SYNAP_OUT_DIR": OUT,
179
+ }
180
+ pkgs = job.get("packages") or []
181
+ if job["language"] == "python":
182
+ code = run(["uv", "venv", f"{WORK}/.venv"], env, pump)
183
+ if code == 0 and pkgs:
184
+ code = run(["uv", "pip", "install", "--python", f"{WORK}/.venv/bin/python",
185
+ *[f"{p['name']}=={p['version']}" for p in pkgs]], env, pump)
186
+ cmd = [f"{WORK}/.venv/bin/python", entry]
187
+ else:
188
+ with open(os.path.join(WORK, "package.json"), "w") as fh:
189
+ json.dump({"private": True}, fh)
190
+ os.chown(os.path.join(WORK, "package.json"), pw.pw_uid, pw.pw_gid)
191
+ code = run(["pnpm", "add", *[f"{p['name']}@{p['version']}" for p in pkgs]], env, pump) if pkgs else 0
192
+ cmd = ["node", entry]
193
+
194
+ call("POST", "/phase", {"phase": "run"})
195
+ if code == 0:
196
+ code = run(cmd, env, pump)
197
+ else:
198
+ pump.write(f"\n[synap box] packages did not install (exit {code}); the script was not run\n".encode())
199
+
200
+ upload_out(pump)
201
+ pump.close()
202
+ call("POST", "/done", {"exitCode": code, "installedPackages": installed(job, env)})
203
+
204
+
205
+ if __name__ == "__main__":
206
+ sys.exit(main())