brane 0.1.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/AGENTS.md +367 -0
  2. package/CHANGELOG.md +66 -0
  3. package/CONTRIBUTING.md +101 -0
  4. package/DESIGN.md +405 -0
  5. package/Dockerfile +61 -0
  6. package/LICENSE +656 -17
  7. package/README.md +174 -2
  8. package/SECURITY.md +213 -0
  9. package/dist/absorb/brane-id.js +11 -0
  10. package/dist/absorb/chatgpt.js +161 -0
  11. package/dist/absorb/claude-code.js +504 -0
  12. package/dist/absorb/index.js +543 -0
  13. package/dist/absorb/organelle.js +345 -0
  14. package/dist/absorb/run.js +520 -0
  15. package/dist/absorb/sources.js +168 -0
  16. package/dist/absorb/types.js +3 -0
  17. package/dist/agent-env.js +45 -0
  18. package/dist/agents.js +1168 -0
  19. package/dist/claude-live-session.js +124 -0
  20. package/dist/cli.js +50 -0
  21. package/dist/codex-tool-log.js +144 -0
  22. package/dist/commands/absorb.js +291 -0
  23. package/dist/commands/attach.js +31 -0
  24. package/dist/commands/certify.js +62 -0
  25. package/dist/commands/config.js +133 -0
  26. package/dist/commands/cost.js +126 -0
  27. package/dist/commands/daemon.js +350 -0
  28. package/dist/commands/doctor.js +262 -0
  29. package/dist/commands/fold.js +95 -0
  30. package/dist/commands/list.js +89 -0
  31. package/dist/commands/mcp.js +84 -0
  32. package/dist/commands/meld.js +360 -0
  33. package/dist/commands/memory.js +215 -0
  34. package/dist/commands/revive.js +74 -0
  35. package/dist/commands/run.js +85 -0
  36. package/dist/commands/spawn.js +1101 -0
  37. package/dist/commands/token.js +154 -0
  38. package/dist/copilot-tool-log.js +145 -0
  39. package/dist/cost/pricing.js +116 -0
  40. package/dist/cost/reprice.js +136 -0
  41. package/dist/crush-tool-log.js +293 -0
  42. package/dist/daemon/agent-scope.js +116 -0
  43. package/dist/daemon/awaiting.js +54 -0
  44. package/dist/daemon/cert-manager.js +349 -0
  45. package/dist/daemon/client.js +262 -0
  46. package/dist/daemon/gated-routes.js +112 -0
  47. package/dist/daemon/keep-awake.js +103 -0
  48. package/dist/daemon/local-socket.js +145 -0
  49. package/dist/daemon/presence-gate.js +206 -0
  50. package/dist/daemon/server.js +6353 -0
  51. package/dist/daemon/signal-source.js +35 -0
  52. package/dist/daemon/tailscale-rebind.js +58 -0
  53. package/dist/daemon/token-ring.js +263 -0
  54. package/dist/daemon/token-routes.js +190 -0
  55. package/dist/db/events.js +152 -0
  56. package/dist/db/mentions.js +179 -0
  57. package/dist/db/schema.js +643 -0
  58. package/dist/db/tokens.js +624 -0
  59. package/dist/db/tool-uses.js +647 -0
  60. package/dist/diagram/index.js +85 -0
  61. package/dist/diagram/label.js +455 -0
  62. package/dist/diagram/layout.js +476 -0
  63. package/dist/diagram/links.js +50 -0
  64. package/dist/diagram/metrics.js +152 -0
  65. package/dist/diagram/parse.js +487 -0
  66. package/dist/diagram/svg.js +389 -0
  67. package/dist/diagram/types.js +9 -0
  68. package/dist/export.js +629 -0
  69. package/dist/files/archive-types.js +2 -0
  70. package/dist/files/archive.js +182 -0
  71. package/dist/files/browse.js +327 -0
  72. package/dist/files/bytes.js +162 -0
  73. package/dist/files/codecs.js +33 -0
  74. package/dist/files/find.js +212 -0
  75. package/dist/files/tar.js +223 -0
  76. package/dist/files/zip.js +209 -0
  77. package/dist/folds.js +72 -0
  78. package/dist/grammars/ebnf.js +92 -0
  79. package/dist/highlight.js +250 -0
  80. package/dist/ids.js +24 -0
  81. package/dist/markdown-diagnostics.js +233 -0
  82. package/dist/math.js +168 -0
  83. package/dist/mcp/server.js +886 -0
  84. package/dist/memory/embedder.js +145 -0
  85. package/dist/memory/embedding-worker.js +71 -0
  86. package/dist/memory/embeddings.js +91 -0
  87. package/dist/memory/index.js +232 -0
  88. package/dist/memory/storage.js +587 -0
  89. package/dist/memory/wiki.js +688 -0
  90. package/dist/memory/wordpiece.js +247 -0
  91. package/dist/mentions-scan.js +40 -0
  92. package/dist/presence.js +259 -0
  93. package/dist/session-affinity.js +185 -0
  94. package/dist/shared/api-request.js +124 -0
  95. package/dist/shared/app-origin.js +26 -0
  96. package/dist/shared/block-glyphs.js +114 -0
  97. package/dist/shared/diagram-css.js +17 -0
  98. package/dist/shared/export-selection.js +101 -0
  99. package/dist/shared/find-in-text.js +110 -0
  100. package/dist/shared/glow-hues.js +225 -0
  101. package/dist/shared/hex-dump.js +62 -0
  102. package/dist/shared/hex-pages.js +52 -0
  103. package/dist/shared/hit-drum.js +79 -0
  104. package/dist/shared/known-nids.js +58 -0
  105. package/dist/shared/list-scroll-keys.js +56 -0
  106. package/dist/shared/markdown-lists.js +72 -0
  107. package/dist/shared/markdown-math.js +485 -0
  108. package/dist/shared/markdown-mentions.js +79 -0
  109. package/dist/shared/markdown-nids.js +41 -0
  110. package/dist/shared/markdown-protocols.js +53 -0
  111. package/dist/shared/markdown-refs.js +123 -0
  112. package/dist/shared/membrane-invasion.js +342 -0
  113. package/dist/shared/membrane-motion.js +83 -0
  114. package/dist/shared/membrane-palette.js +253 -0
  115. package/dist/shared/membrane-terrain.js +212 -0
  116. package/dist/shared/message-selection.js +123 -0
  117. package/dist/shared/mo-glyph.js +57 -0
  118. package/dist/shared/narrative-format.js +237 -0
  119. package/dist/shared/narrative-menu.js +84 -0
  120. package/dist/shared/narrative-sort.js +47 -0
  121. package/dist/shared/narrative-status.js +52 -0
  122. package/dist/shared/no-pan.js +85 -0
  123. package/dist/shared/pane-layout.js +50 -0
  124. package/dist/shared/payload-inline.js +83 -0
  125. package/dist/shared/speaker-color.js +61 -0
  126. package/dist/shared/token-rotation.js +14 -0
  127. package/dist/shared/view-url.js +216 -0
  128. package/dist/shared/wiki-links.js +70 -0
  129. package/dist/shared/wiki-window.js +4 -0
  130. package/dist/tailscale.js +55 -0
  131. package/dist/test/absorb-claude.test.js +892 -0
  132. package/dist/test/agent-scope.test.js +193 -0
  133. package/dist/test/agents.test.js +55 -0
  134. package/dist/test/api-request.test.js +122 -0
  135. package/dist/test/app-host-literal.test.js +53 -0
  136. package/dist/test/awaiting-glow.test.js +54 -0
  137. package/dist/test/awaiting.test.js +122 -0
  138. package/dist/test/bind-token.test.js +88 -0
  139. package/dist/test/block-glyphs.test.js +68 -0
  140. package/dist/test/cert-manager.test.js +262 -0
  141. package/dist/test/claude-live-session.test.js +110 -0
  142. package/dist/test/codex-tool-log.test.js +568 -0
  143. package/dist/test/config.test.js +71 -0
  144. package/dist/test/copilot-tool-log.test.js +93 -0
  145. package/dist/test/cors-preflight.test.js +56 -0
  146. package/dist/test/cost-linger.test.js +31 -0
  147. package/dist/test/cost-pricing.test.js +72 -0
  148. package/dist/test/cost-reprice.test.js +139 -0
  149. package/dist/test/cost-sessions.test.js +301 -0
  150. package/dist/test/crush-tool-log.test.js +289 -0
  151. package/dist/test/daemon-client.test.js +109 -0
  152. package/dist/test/daemon-socket.test.js +293 -0
  153. package/dist/test/diagram-arrows.test.js +205 -0
  154. package/dist/test/diagram-export.test.js +210 -0
  155. package/dist/test/diagram-labels.test.js +313 -0
  156. package/dist/test/diagram-parse.test.js +191 -0
  157. package/dist/test/diagram-render.test.js +175 -0
  158. package/dist/test/diagram-review.test.js +288 -0
  159. package/dist/test/diagram-self-loop-labels.test.js +303 -0
  160. package/dist/test/embedder.test.js +84 -0
  161. package/dist/test/events.test.js +123 -0
  162. package/dist/test/export-selection.test.js +102 -0
  163. package/dist/test/export.test.js +505 -0
  164. package/dist/test/files-browse.test.js +393 -0
  165. package/dist/test/files-find.test.js +272 -0
  166. package/dist/test/find-in-text.test.js +86 -0
  167. package/dist/test/first-paint-viewport.test.js +59 -0
  168. package/dist/test/fixtures/embedding-golden.js +23 -0
  169. package/dist/test/fixtures/wordpiece-golden.js +167 -0
  170. package/dist/test/glow-hues.test.js +202 -0
  171. package/dist/test/harness-cost.test.js +423 -0
  172. package/dist/test/helpers.js +21 -0
  173. package/dist/test/hex-pages.test.js +68 -0
  174. package/dist/test/highlight.test.js +69 -0
  175. package/dist/test/hit-drum.test.js +71 -0
  176. package/dist/test/hook-config.test.js +299 -0
  177. package/dist/test/json-gzip.test.js +70 -0
  178. package/dist/test/key-routing.test.js +58 -0
  179. package/dist/test/known-nids.test.js +106 -0
  180. package/dist/test/link-preview.test.js +67 -0
  181. package/dist/test/list-scroll-keys.test.js +66 -0
  182. package/dist/test/listen-own-words.test.js +147 -0
  183. package/dist/test/listen-timeout.test.js +33 -0
  184. package/dist/test/markdown-diagnostics.test.js +121 -0
  185. package/dist/test/markdown-lists.test.js +182 -0
  186. package/dist/test/markdown-math.test.js +256 -0
  187. package/dist/test/markdown-nids.test.js +146 -0
  188. package/dist/test/markdown-protocols.test.js +139 -0
  189. package/dist/test/mcp-bridge-cancel.test.js +98 -0
  190. package/dist/test/mcp-bridge-reconnect.test.js +121 -0
  191. package/dist/test/mcp-narrative.test.js +193 -0
  192. package/dist/test/mcp.test.js +548 -0
  193. package/dist/test/meld.test.js +143 -0
  194. package/dist/test/membrane-invasion.test.js +482 -0
  195. package/dist/test/membrane-motion.test.js +101 -0
  196. package/dist/test/membrane-palette.test.js +166 -0
  197. package/dist/test/membrane-terrain.test.js +170 -0
  198. package/dist/test/memory-log.test.js +202 -0
  199. package/dist/test/mentions-e2e.test.js +261 -0
  200. package/dist/test/mentions-ledger.test.js +265 -0
  201. package/dist/test/mentions-listen.test.js +265 -0
  202. package/dist/test/mentions.test.js +238 -0
  203. package/dist/test/message-selection.test.js +114 -0
  204. package/dist/test/mo-glyph.test.js +22 -0
  205. package/dist/test/model-resolution.test.js +166 -0
  206. package/dist/test/narrate-validate.test.js +77 -0
  207. package/dist/test/narrate-wait.test.js +160 -0
  208. package/dist/test/narrative-format.test.js +219 -0
  209. package/dist/test/narrative-menu.test.js +150 -0
  210. package/dist/test/narrative-sort.test.js +75 -0
  211. package/dist/test/no-pan.test.js +60 -0
  212. package/dist/test/pane-layout.test.js +153 -0
  213. package/dist/test/paths.test.js +37 -0
  214. package/dist/test/payload-inline.test.js +91 -0
  215. package/dist/test/precache-fonts.test.js +72 -0
  216. package/dist/test/presence-gate.test.js +440 -0
  217. package/dist/test/presence.test.js +160 -0
  218. package/dist/test/read-events.test.js +220 -0
  219. package/dist/test/remote-meld.test.js +128 -0
  220. package/dist/test/revive-cli.test.js +93 -0
  221. package/dist/test/search-floor.test.js +206 -0
  222. package/dist/test/search-fusion.test.js +168 -0
  223. package/dist/test/search.test.js +205 -0
  224. package/dist/test/security.test.js +48 -0
  225. package/dist/test/selection-wiring.test.js +61 -0
  226. package/dist/test/session-affinity.test.js +295 -0
  227. package/dist/test/signal-source.test.js +32 -0
  228. package/dist/test/socket-account.test.js +268 -0
  229. package/dist/test/spawn-toml.test.js +72 -0
  230. package/dist/test/speaker-color.test.js +90 -0
  231. package/dist/test/tailscale-rebind.test.js +79 -0
  232. package/dist/test/terminal-cursor.test.js +61 -0
  233. package/dist/test/terminal-resync.test.js +23 -0
  234. package/dist/test/terminal-size.test.js +36 -0
  235. package/dist/test/thin-cli.test.js +382 -0
  236. package/dist/test/token-bootstrap.test.js +272 -0
  237. package/dist/test/token-devices.test.js +646 -0
  238. package/dist/test/token-lapse.test.js +94 -0
  239. package/dist/test/token-ring.test.js +188 -0
  240. package/dist/test/token-rotate-cli.test.js +58 -0
  241. package/dist/test/token-routes.test.js +95 -0
  242. package/dist/test/tool-uses.test.js +1006 -0
  243. package/dist/test/usage-ledger.test.js +126 -0
  244. package/dist/test/view-url.test.js +627 -0
  245. package/dist/test/wiki-links.test.js +57 -0
  246. package/dist/test/wiki-sources.test.js +85 -0
  247. package/dist/test/wiki-window.test.js +31 -0
  248. package/dist/test/wiki.test.js +399 -0
  249. package/dist/test/wordpiece.test.js +68 -0
  250. package/dist/test/wrangler-route.test.js +27 -0
  251. package/dist/tls.js +148 -0
  252. package/dist/tmux.js +213 -0
  253. package/dist/user-agent.js +46 -0
  254. package/docker-entrypoint.sh +154 -0
  255. package/docs/README.md +3 -0
  256. package/docs/absorb.md +231 -0
  257. package/docs/cost-ledger.md +125 -0
  258. package/docs/daemon-api.md +189 -0
  259. package/docs/diagrams.md +163 -0
  260. package/docs/doctor.md +36 -0
  261. package/docs/export-scope.md +69 -0
  262. package/docs/files-view.md +133 -0
  263. package/docs/link-previews.md +38 -0
  264. package/docs/math.md +32 -0
  265. package/docs/mcp.md +69 -0
  266. package/docs/memory-search.md +75 -0
  267. package/docs/mentions.md +101 -0
  268. package/docs/multi-brane.md +14 -0
  269. package/docs/passkeys.md +165 -0
  270. package/docs/presence.md +202 -0
  271. package/docs/releasing.md +104 -0
  272. package/docs/rendering-warnings.md +22 -0
  273. package/docs/request-layer.md +72 -0
  274. package/docs/selection-store.md +50 -0
  275. package/docs/session-affinity.md +61 -0
  276. package/docs/terminal-mirroring.md +243 -0
  277. package/docs/token-rotation.md +431 -0
  278. package/docs/view-urls.md +134 -0
  279. package/docs/web-app.md +23 -0
  280. package/docs/wiki.md +43 -0
  281. package/expo/dist/_expo/static/js/web/entry-e94247f119fdcd3b424a1764233a41d2.js +1099 -0
  282. package/expo/dist/apple-touch-icon.png +0 -0
  283. package/expo/dist/favicon.svg +3 -0
  284. package/expo/dist/index.html +177 -0
  285. package/expo/dist/katex/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  286. package/expo/dist/katex/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  287. package/expo/dist/katex/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  288. package/expo/dist/katex/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  289. package/expo/dist/katex/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  290. package/expo/dist/katex/fonts/KaTeX_Main-Bold.woff2 +0 -0
  291. package/expo/dist/katex/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  292. package/expo/dist/katex/fonts/KaTeX_Main-Italic.woff2 +0 -0
  293. package/expo/dist/katex/fonts/KaTeX_Main-Regular.woff2 +0 -0
  294. package/expo/dist/katex/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  295. package/expo/dist/katex/fonts/KaTeX_Math-Italic.woff2 +0 -0
  296. package/expo/dist/katex/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  297. package/expo/dist/katex/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  298. package/expo/dist/katex/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  299. package/expo/dist/katex/fonts/KaTeX_Script-Regular.woff2 +0 -0
  300. package/expo/dist/katex/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  301. package/expo/dist/katex/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  302. package/expo/dist/katex/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  303. package/expo/dist/katex/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  304. package/expo/dist/katex/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  305. package/expo/dist/katex/katex.min.css +1 -0
  306. package/expo/dist/manifest.json +16 -0
  307. package/expo/dist/metadata.json +1 -0
  308. package/expo/dist/og/membrane.v1.png +0 -0
  309. package/expo/dist/pdf.min.mjs +28 -0
  310. package/expo/dist/pdf.worker.min.mjs +28 -0
  311. package/expo/dist/sw.js +154 -0
  312. package/package.json +79 -27
  313. package/protocols/LIVE_loop.md +407 -0
  314. package/protocols/bebrief.md +41 -0
  315. package/protocols/digest.md +231 -0
  316. package/protocols/fly.md +266 -0
  317. package/protocols/idle.md +81 -0
  318. package/protocols/keeper.md +829 -0
  319. package/protocols/markdown.md +80 -0
  320. package/protocols/memory.md +419 -0
  321. package/protocols/mentions.md +93 -0
  322. package/protocols/payloads.md +53 -0
  323. package/protocols/prelude.md +91 -0
  324. package/protocols/ramify.md +105 -0
  325. package/protocols/review.md +356 -0
  326. package/protocols/rrr.md +232 -0
  327. package/protocols/scribe.md +429 -0
  328. package/protocols/summarize.md +203 -0
  329. package/protocols/twin.md +174 -0
  330. package/protocols/wiki.md +438 -0
  331. package/protocols/worker.md +38 -0
  332. package/wiki/shared/append-only-event-log.md +148 -0
  333. package/wiki/shared/index.md +53 -0
  334. package/wiki/shared/owning-your-narratives.md +161 -0
  335. package/wiki/shared/premature-ontologies.md +435 -0
  336. package/wiki/shared/sedimentary-superintelligence.md +128 -0
  337. package/wiki/shared/sequestering-the-narrative.md +143 -0
  338. package/wiki/shared/why-wikis-work.md +216 -0
  339. package/.travis.yml +0 -7
  340. package/lib/brane.cjs.js +0 -12
  341. package/lib/brane.cjs.js.map +0 -1
  342. package/lib/brane.d.ts +0 -11
  343. package/lib/brane.js +0 -6
  344. package/lib/brane.js.map +0 -1
  345. package/lib/tests.d.ts +0 -1
  346. package/lib/tests.js +0 -8
  347. package/lib/tests.js.map +0 -1
  348. package/rollup.config.js +0 -21
  349. package/scripts/test.sh +0 -8
  350. package/src/brane.ts +0 -21
  351. package/src/tests.ts +0 -8
  352. package/tsconfig.json +0 -16
@@ -0,0 +1,168 @@
1
+ /** The inventory behind a bare `brane absorb`: every session store brane
2
+ * knows how to look for, whether it is on this machine, and what an import
3
+ * would do with it. Reads no message content — the survey is a promise a
4
+ * new user can be given ("it tells you what it found; nothing leaves the
5
+ * machine, nothing is imported until you say") and it is kept by
6
+ * construction: `LocalSource.survey` is a stat and a head read, and the
7
+ * probes below are `existsSync`.
8
+ */
9
+ import { existsSync, readdirSync, statSync } from "node:fs";
10
+ import { join } from "node:path";
11
+ import { claudeCodeSource } from "./claude-code.js";
12
+ import { toPortablePath } from "../db/schema.js";
13
+ import { deriveBraneId } from "./brane-id.js";
14
+ /** Local sources with an extractor, in the order the survey lists them. */
15
+ export const LOCAL_SOURCES = [claudeCodeSource];
16
+ export function getLocalSource(name) {
17
+ return LOCAL_SOURCES.find((s) => s.name === name);
18
+ }
19
+ /** Stores brane recognises but cannot read yet. Listed so the survey says
20
+ * "found, no extractor" rather than nothing — the operator learns what is
21
+ * on the machine either way, and which line to ask for next. Today the
22
+ * list is the agents brane can spawn (see `AGENTS` in src/agents.ts) plus
23
+ * the other Claude product with a local transcript, because those are the
24
+ * formats someone here has looked at. Nothing ties an entry — or a
25
+ * `LocalSource` — to spawn support: an importer for a tool brane cannot
26
+ * run is welcome (claude-xiy9e8wq:17); the list just isn't speculative. */
27
+ const PROBES = [
28
+ { name: "codex", label: "Codex CLI rollouts", under: (h) => join(h, ".codex", "sessions") },
29
+ { name: "goose", label: "goose sessions", under: (h) => join(h, ".local", "share", "goose", "sessions") },
30
+ { name: "copilot", label: "GitHub Copilot CLI session store", under: (h) => join(h, ".copilot", "session-store.db") },
31
+ { name: "gemini", label: "Gemini CLI", under: (h) => join(h, ".gemini", "tmp") },
32
+ { name: "cline", label: "Cline tasks", under: (h) => join(h, ".cline", "data", "tasks") },
33
+ { name: "amp", label: "Amp", under: (h) => join(h, ".amp") },
34
+ {
35
+ name: "claude-desktop",
36
+ label: "Claude Desktop agent-mode sessions",
37
+ under: (h) => join(h, "Library", "Application Support", "Claude", "local-agent-mode-sessions"),
38
+ },
39
+ ];
40
+ /** Classify every candidate against the database in one pass: managed by a
41
+ * live narrative (any brane), absorbed before into `braneId` (and whether
42
+ * the file has changed since), or new to that brane. Shared by the survey
43
+ * and the import so they cannot disagree. */
44
+ export function classifySessions(db, source, candidates, braneId) {
45
+ const out = new Map();
46
+ if (candidates.length === 0)
47
+ return out;
48
+ // Live narratives of this agent type: the session ids they have bound.
49
+ const managed = new Map();
50
+ const rows = db
51
+ .prepare(`SELECT id, agent_session_id, session_ids FROM narratives
52
+ WHERE agent_type = ? AND role != 'absorbed'
53
+ AND (agent_session_id IS NOT NULL OR session_ids IS NOT NULL)`)
54
+ .all(source.name);
55
+ for (const r of rows) {
56
+ if (r.agent_session_id)
57
+ managed.set(r.agent_session_id, r.id);
58
+ if (r.session_ids) {
59
+ try {
60
+ const ids = JSON.parse(r.session_ids);
61
+ if (Array.isArray(ids))
62
+ for (const id of ids)
63
+ if (typeof id === "string")
64
+ managed.set(id, r.id);
65
+ }
66
+ catch {
67
+ // malformed column value; agent_session_id above still counts
68
+ }
69
+ }
70
+ }
71
+ const absorbed = db.prepare(`SELECT id FROM narratives
72
+ WHERE agent_type = ? AND role = 'absorbed' AND agent_session_id = ? AND brane_id = ?`);
73
+ const fileRow = db.prepare("SELECT bytes, mtime, parser_version FROM absorb_files WHERE brane_id = ? AND provider = ? AND external_id = ?");
74
+ for (const c of candidates) {
75
+ const managedBy = managed.get(c.externalId) ?? null;
76
+ const abs = absorbed.get(source.name, c.externalId, braneId);
77
+ const f = fileRow.get(braneId, source.name, c.externalId);
78
+ // Unchanged means nothing new could come of reading it: the same
79
+ // bytes, read last time by a parser that knew what this one knows.
80
+ const sameFile = !!f && f.bytes === c.bytes && f.mtime === c.updatedAt;
81
+ const current = !!f && f.parser_version >= source.parserVersion;
82
+ out.set(c.externalId, {
83
+ managedBy,
84
+ absorbedBy: abs?.id ?? null,
85
+ unchanged: sameFile && current,
86
+ reparse: sameFile && !current,
87
+ });
88
+ }
89
+ return out;
90
+ }
91
+ export function surveyAbsorbSources(db, home) {
92
+ const sources = [];
93
+ for (const src of LOCAL_SOURCES) {
94
+ const root = src.locate(home);
95
+ const report = {
96
+ name: src.name,
97
+ label: labelFor(src.name),
98
+ path: toPortablePath(root ?? defaultPathFor(src.name, home)),
99
+ found: root !== null,
100
+ supported: true,
101
+ };
102
+ if (root) {
103
+ const candidates = src.survey(root);
104
+ // The survey answers for the brane a plain `brane absorb <source>`
105
+ // would target — the one derived from the account — since that is
106
+ // the import it is previewing.
107
+ const status = classifySessions(db, src, candidates, deriveBraneId(src.name, src.identity(home).id));
108
+ const s = { total: 0, new: 0, changed: 0, unchanged: 0, reparse: 0, managed: 0, bytes: 0, folds: 0, oldest: null, newest: null };
109
+ const folds = new Set();
110
+ for (const c of candidates) {
111
+ s.total++;
112
+ s.bytes += c.bytes;
113
+ if (c.cwd)
114
+ folds.add(c.cwd);
115
+ if (c.startedAt !== null && (s.oldest === null || c.startedAt < s.oldest))
116
+ s.oldest = c.startedAt;
117
+ if (s.newest === null || c.updatedAt > s.newest)
118
+ s.newest = c.updatedAt;
119
+ const st = status.get(c.externalId);
120
+ if (st.managedBy)
121
+ s.managed++;
122
+ else if (st.absorbedBy)
123
+ (st.unchanged ? s.unchanged++ : st.reparse ? s.reparse++ : s.changed++);
124
+ else
125
+ s.new++;
126
+ }
127
+ s.folds = folds.size;
128
+ report.sessions = s;
129
+ }
130
+ sources.push(report);
131
+ }
132
+ for (const probe of PROBES) {
133
+ const path = probe.under(home);
134
+ sources.push({
135
+ name: probe.name,
136
+ label: probe.label,
137
+ path: toPortablePath(path),
138
+ found: existsSync(path) && !isEmptyDir(path),
139
+ supported: false,
140
+ });
141
+ }
142
+ return { home, sources };
143
+ }
144
+ function isEmptyDir(path) {
145
+ try {
146
+ return statSync(path).isDirectory() && readdirSync(path).length === 0;
147
+ }
148
+ catch {
149
+ return false;
150
+ }
151
+ }
152
+ function labelFor(name) {
153
+ switch (name) {
154
+ case "claude":
155
+ return "Claude Code sessions";
156
+ default:
157
+ return name;
158
+ }
159
+ }
160
+ function defaultPathFor(name, home) {
161
+ switch (name) {
162
+ case "claude":
163
+ return join(home, ".claude", "projects");
164
+ default:
165
+ return home;
166
+ }
167
+ }
168
+ //# sourceMappingURL=sources.js.map
@@ -0,0 +1,3 @@
1
+ /** Shared types for the absorb (import) system */
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The environment variables that identify one agent session, which nothing
3
+ * the daemon starts may inherit.
4
+ *
5
+ * A daemon restarted from an agent's shell (as /rrr does) inherits that
6
+ * agent's environment, and so does every tmux server and session it then
7
+ * starts. Brane's own pair would let another session act as that agent
8
+ * (claude-jrjh1e8w:10). The harness's session variables do damage too: the
9
+ * MCP bridge forwards `CLAUDE_CODE_SESSION_ID` as its author's session, so a
10
+ * crush agent spawned by such a daemon stamped every narration with the
11
+ * restarting Claude session's id (claude-eiuzl79r:33), and carried a copy of
12
+ * that session's `CLAUDE_CODE_MESSAGING_TOKEN`. Claude overrides these for
13
+ * its own children; other harnesses do not.
14
+ *
15
+ * Only session-scoped names belong here. User configuration that happens to
16
+ * share a prefix (`CLAUDE_CODE_USE_BEDROCK`, `CLAUDE_CODE_MAX_OUTPUT_TOKENS`)
17
+ * is the operator's and passes through.
18
+ */
19
+ export const INHERITED_AGENT_ENV = [
20
+ "BRANE_NARRATIVE_ID",
21
+ "BRANE_NARRATIVE_SECRET",
22
+ "CLAUDECODE",
23
+ "CLAUDE_CODE_SESSION_ID",
24
+ "CLAUDE_CODE_CHILD_SESSION",
25
+ "CLAUDE_CODE_ENTRYPOINT",
26
+ "CLAUDE_CODE_EXECPATH",
27
+ "CLAUDE_CODE_MESSAGING_SOCKET",
28
+ "CLAUDE_CODE_MESSAGING_TOKEN",
29
+ "CLAUDE_CODE_SESSION_ATTENDED",
30
+ "CLAUDE_CODE_SSE_PORT",
31
+ "CLAUDE_PID",
32
+ ];
33
+ /** `env` without any inherited agent-session variable. */
34
+ export function withoutAgentEnv(env) {
35
+ const out = { ...env };
36
+ for (const name of INHERITED_AGENT_ENV)
37
+ delete out[name];
38
+ return out;
39
+ }
40
+ /** A shell prefix that runs a command with every inherited agent-session
41
+ * variable unset, for commands tmux starts from its global env. */
42
+ export function unsetAgentEnvPrefix() {
43
+ return `env ${INHERITED_AGENT_ENV.map((name) => `-u ${name}`).join(" ")}`;
44
+ }
45
+ //# sourceMappingURL=agent-env.js.map