@ouro.bot/cli 0.1.0-alpha.34 → 0.1.0-alpha.340

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 (314) hide show
  1. package/README.md +188 -187
  2. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/agent.json +3 -2
  3. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +1 -1
  4. package/changelog.json +2031 -0
  5. package/dist/arc/attention-types.js +8 -0
  6. package/dist/arc/cares.js +140 -0
  7. package/dist/arc/episodes.js +117 -0
  8. package/dist/arc/intentions.js +133 -0
  9. package/dist/arc/json-store.js +117 -0
  10. package/dist/arc/obligations.js +237 -0
  11. package/dist/arc/packets.js +193 -0
  12. package/dist/arc/presence.js +185 -0
  13. package/dist/arc/task-lifecycle.js +65 -0
  14. package/dist/heart/active-work.js +832 -0
  15. package/dist/heart/agent-entry.js +37 -2
  16. package/dist/heart/attachments/image-normalize.js +194 -0
  17. package/dist/heart/attachments/materialize.js +97 -0
  18. package/dist/heart/attachments/originals.js +88 -0
  19. package/dist/heart/attachments/render.js +29 -0
  20. package/dist/heart/attachments/sources/adapter.js +2 -0
  21. package/dist/heart/attachments/sources/bluebubbles.js +156 -0
  22. package/dist/heart/attachments/sources/cli-local-file.js +78 -0
  23. package/dist/heart/attachments/sources/index.js +16 -0
  24. package/dist/heart/attachments/store.js +103 -0
  25. package/dist/heart/attachments/types.js +93 -0
  26. package/dist/heart/auth/auth-flow.js +463 -0
  27. package/dist/heart/bridges/manager.js +358 -0
  28. package/dist/heart/bridges/state-machine.js +135 -0
  29. package/dist/heart/bridges/store.js +123 -0
  30. package/dist/heart/bundle-state.js +168 -0
  31. package/dist/heart/commitments.js +111 -0
  32. package/dist/heart/config-registry.js +304 -0
  33. package/dist/heart/config.js +53 -21
  34. package/dist/heart/core.js +695 -195
  35. package/dist/heart/cross-chat-delivery.js +131 -0
  36. package/dist/heart/daemon/agent-config-check.js +292 -0
  37. package/dist/heart/daemon/agent-discovery.js +79 -3
  38. package/dist/heart/daemon/agent-service.js +360 -0
  39. package/dist/heart/daemon/agentic-repair.js +170 -0
  40. package/dist/heart/daemon/bluebubbles-health-diagnostics.js +122 -0
  41. package/dist/heart/daemon/cadence.js +70 -0
  42. package/dist/heart/daemon/cli-defaults.js +591 -0
  43. package/dist/heart/daemon/cli-exec.js +2297 -0
  44. package/dist/heart/daemon/cli-help.js +306 -0
  45. package/dist/heart/daemon/cli-parse.js +824 -0
  46. package/dist/heart/daemon/cli-render-doctor.js +57 -0
  47. package/dist/heart/daemon/cli-render.js +512 -0
  48. package/dist/heart/daemon/cli-types.js +8 -0
  49. package/dist/heart/daemon/daemon-cli.js +30 -1171
  50. package/dist/heart/daemon/daemon-entry.js +358 -3
  51. package/dist/heart/daemon/daemon-health.js +141 -0
  52. package/dist/heart/daemon/daemon-runtime-sync.js +157 -12
  53. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  54. package/dist/heart/daemon/daemon.js +751 -58
  55. package/dist/heart/daemon/doctor-types.js +8 -0
  56. package/dist/heart/daemon/doctor.js +401 -0
  57. package/dist/heart/daemon/health-monitor.js +79 -1
  58. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  59. package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
  60. package/dist/heart/daemon/http-health-probe.js +80 -0
  61. package/dist/heart/daemon/inner-status.js +89 -0
  62. package/dist/heart/daemon/interactive-repair.js +91 -0
  63. package/dist/heart/daemon/launchd.js +46 -9
  64. package/dist/heart/daemon/log-tailer.js +82 -12
  65. package/dist/heart/daemon/logs-prune.js +105 -0
  66. package/dist/heart/daemon/message-router.js +17 -8
  67. package/dist/heart/daemon/os-cron-deps.js +134 -0
  68. package/dist/heart/daemon/ouro-bot-entry.js +1 -1
  69. package/dist/heart/daemon/process-manager.js +201 -0
  70. package/dist/heart/daemon/provider-discovery.js +105 -0
  71. package/dist/heart/daemon/pulse.js +463 -0
  72. package/dist/heart/daemon/run-hooks.js +2 -0
  73. package/dist/heart/daemon/runtime-logging.js +67 -16
  74. package/dist/heart/daemon/runtime-metadata.js +101 -0
  75. package/dist/heart/daemon/runtime-mode.js +67 -0
  76. package/dist/heart/daemon/safe-mode.js +161 -0
  77. package/dist/heart/daemon/sense-manager.js +72 -3
  78. package/dist/heart/daemon/session-id-resolver.js +131 -0
  79. package/dist/heart/daemon/skill-management-installer.js +94 -0
  80. package/dist/heart/daemon/socket-client.js +307 -0
  81. package/dist/heart/daemon/stale-bundle-prune.js +96 -0
  82. package/dist/heart/daemon/startup-tui.js +237 -0
  83. package/dist/heart/daemon/task-scheduler.js +3 -25
  84. package/dist/heart/daemon/thoughts.js +510 -0
  85. package/dist/heart/daemon/up-progress.js +135 -0
  86. package/dist/heart/delegation.js +62 -0
  87. package/dist/heart/habits/habit-migration.js +181 -0
  88. package/dist/heart/habits/habit-parser.js +140 -0
  89. package/dist/heart/habits/habit-scheduler.js +371 -0
  90. package/dist/heart/{daemon → hatch}/hatch-flow.js +32 -120
  91. package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
  92. package/dist/heart/{daemon → hatch}/specialist-prompt.js +10 -7
  93. package/dist/heart/{daemon → hatch}/specialist-tools.js +49 -3
  94. package/dist/heart/identity.js +154 -59
  95. package/dist/heart/kicks.js +2 -20
  96. package/dist/heart/mcp/mcp-server.js +653 -0
  97. package/dist/heart/migrate-config.js +127 -0
  98. package/dist/heart/model-capabilities.js +59 -0
  99. package/dist/heart/outlook/outlook-http-hooks.js +64 -0
  100. package/dist/heart/outlook/outlook-http-response.js +7 -0
  101. package/dist/heart/outlook/outlook-http-routes.js +232 -0
  102. package/dist/heart/outlook/outlook-http-static.js +99 -0
  103. package/dist/heart/outlook/outlook-http-transport.js +116 -0
  104. package/dist/heart/outlook/outlook-http.js +99 -0
  105. package/dist/heart/outlook/outlook-read.js +28 -0
  106. package/dist/heart/outlook/outlook-types.js +27 -0
  107. package/dist/heart/outlook/outlook-view.js +194 -0
  108. package/dist/heart/outlook/readers/agent-machine.js +355 -0
  109. package/dist/heart/outlook/readers/continuity-readers.js +332 -0
  110. package/dist/heart/outlook/readers/runtime-readers.js +660 -0
  111. package/dist/heart/outlook/readers/sessions.js +231 -0
  112. package/dist/heart/outlook/readers/shared.js +111 -0
  113. package/dist/heart/progress-story.js +42 -0
  114. package/dist/heart/provider-failover.js +135 -0
  115. package/dist/heart/provider-models.js +81 -0
  116. package/dist/heart/provider-ping.js +234 -0
  117. package/dist/heart/providers/anthropic-token.js +163 -0
  118. package/dist/heart/providers/anthropic.js +171 -50
  119. package/dist/heart/providers/azure.js +97 -11
  120. package/dist/heart/providers/error-classification.js +63 -0
  121. package/dist/heart/providers/github-copilot.js +135 -0
  122. package/dist/heart/providers/minimax-vlm.js +189 -0
  123. package/dist/heart/providers/minimax.js +23 -6
  124. package/dist/heart/providers/openai-codex.js +33 -23
  125. package/dist/heart/session-activity.js +190 -0
  126. package/dist/heart/session-events.js +726 -0
  127. package/dist/heart/session-recall.js +162 -0
  128. package/dist/heart/start-of-turn-packet.js +341 -0
  129. package/dist/heart/streaming.js +36 -27
  130. package/dist/heart/sync.js +332 -0
  131. package/dist/heart/target-resolution.js +127 -0
  132. package/dist/heart/tempo.js +93 -0
  133. package/dist/heart/temporal-view.js +41 -0
  134. package/dist/heart/tool-activity-callbacks.js +36 -0
  135. package/dist/heart/tool-description.js +135 -0
  136. package/dist/heart/tool-friction.js +55 -0
  137. package/dist/heart/tool-loop.js +200 -0
  138. package/dist/heart/turn-context.js +358 -0
  139. package/dist/heart/turn-coordinator.js +28 -0
  140. package/dist/heart/{daemon → versioning}/ouro-bot-global-installer.js +1 -1
  141. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  142. package/dist/heart/{daemon → versioning}/ouro-path-installer.js +78 -35
  143. package/dist/heart/versioning/ouro-version-manager.js +295 -0
  144. package/dist/heart/{daemon → versioning}/staged-restart.js +40 -8
  145. package/dist/heart/{daemon → versioning}/update-checker.js +12 -2
  146. package/dist/heart/{daemon → versioning}/update-hooks.js +63 -59
  147. package/dist/mind/associative-recall.js +137 -66
  148. package/dist/mind/bundle-manifest.js +7 -1
  149. package/dist/mind/context.js +89 -93
  150. package/dist/mind/diary-integrity.js +60 -0
  151. package/dist/mind/{memory.js → diary.js} +84 -96
  152. package/dist/mind/embedding-provider.js +60 -0
  153. package/dist/mind/file-state.js +179 -0
  154. package/dist/mind/first-impressions.js +14 -1
  155. package/dist/mind/friends/channel.js +56 -0
  156. package/dist/mind/friends/group-context.js +144 -0
  157. package/dist/mind/friends/resolver.js +37 -0
  158. package/dist/mind/friends/store-file.js +58 -3
  159. package/dist/mind/friends/trust-explanation.js +74 -0
  160. package/dist/mind/friends/types.js +8 -0
  161. package/dist/mind/journal-index.js +161 -0
  162. package/dist/mind/obligation-steering.js +221 -0
  163. package/dist/mind/pending.js +74 -7
  164. package/dist/mind/prompt.js +999 -111
  165. package/dist/mind/provenance-trust.js +26 -0
  166. package/dist/mind/scrutiny.js +173 -0
  167. package/dist/mind/token-estimate.js +8 -12
  168. package/dist/nerves/cli-logging.js +7 -1
  169. package/dist/nerves/coverage/audit.js +1 -1
  170. package/dist/nerves/coverage/file-completeness.js +83 -5
  171. package/dist/nerves/coverage/run-artifacts.js +1 -1
  172. package/dist/nerves/event-buffer.js +111 -0
  173. package/dist/nerves/index.js +224 -4
  174. package/dist/nerves/observation.js +20 -0
  175. package/dist/nerves/redact.js +79 -0
  176. package/dist/nerves/runtime.js +5 -1
  177. package/dist/outlook-ui/assets/index-DC7sZefn.js +61 -0
  178. package/dist/outlook-ui/assets/index-LwChZTgL.css +1 -0
  179. package/dist/outlook-ui/index.html +15 -0
  180. package/dist/repertoire/ado-client.js +15 -56
  181. package/dist/repertoire/ado-semantic.js +11 -10
  182. package/dist/repertoire/api-client.js +97 -0
  183. package/dist/repertoire/bitwarden-store.js +319 -0
  184. package/dist/repertoire/bundle-templates.js +72 -0
  185. package/dist/repertoire/bw-installer.js +79 -0
  186. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  187. package/dist/repertoire/coding/context-pack.js +330 -0
  188. package/dist/repertoire/coding/feedback.js +197 -30
  189. package/dist/repertoire/coding/manager.js +158 -9
  190. package/dist/repertoire/coding/spawner.js +55 -9
  191. package/dist/repertoire/coding/tools.js +170 -7
  192. package/dist/repertoire/commerce-errors.js +109 -0
  193. package/dist/repertoire/commerce-self-test.js +156 -0
  194. package/dist/repertoire/credential-access.js +527 -0
  195. package/dist/repertoire/duffel-client.js +185 -0
  196. package/dist/repertoire/github-client.js +14 -55
  197. package/dist/repertoire/graph-client.js +11 -52
  198. package/dist/repertoire/guardrails.js +375 -0
  199. package/dist/repertoire/mcp-client.js +255 -0
  200. package/dist/repertoire/mcp-manager.js +305 -0
  201. package/dist/repertoire/mcp-tools.js +63 -0
  202. package/dist/repertoire/shell-sessions.js +133 -0
  203. package/dist/repertoire/skills.js +14 -23
  204. package/dist/repertoire/stripe-client.js +131 -0
  205. package/dist/repertoire/tasks/board.js +43 -5
  206. package/dist/repertoire/tasks/fix.js +182 -0
  207. package/dist/repertoire/tasks/index.js +28 -10
  208. package/dist/repertoire/tasks/lifecycle.js +2 -2
  209. package/dist/repertoire/tasks/parser.js +3 -2
  210. package/dist/repertoire/tasks/scanner.js +194 -37
  211. package/dist/repertoire/tasks/transitions.js +16 -79
  212. package/dist/repertoire/tool-results.js +29 -0
  213. package/dist/repertoire/tools-attachments.js +316 -0
  214. package/dist/repertoire/tools-base.js +45 -771
  215. package/dist/repertoire/tools-bluebubbles.js +1 -0
  216. package/dist/repertoire/tools-bridge.js +141 -0
  217. package/dist/repertoire/tools-bundle.js +984 -0
  218. package/dist/repertoire/tools-config.js +185 -0
  219. package/dist/repertoire/tools-continuity.js +248 -0
  220. package/dist/repertoire/tools-credential.js +182 -0
  221. package/dist/repertoire/tools-files.js +342 -0
  222. package/dist/repertoire/tools-flight.js +224 -0
  223. package/dist/repertoire/tools-flow.js +105 -0
  224. package/dist/repertoire/tools-github.js +1 -7
  225. package/dist/repertoire/tools-memory.js +376 -0
  226. package/dist/repertoire/tools-session.js +739 -0
  227. package/dist/repertoire/tools-shell.js +120 -0
  228. package/dist/repertoire/tools-stripe.js +180 -0
  229. package/dist/repertoire/tools-surface.js +243 -0
  230. package/dist/repertoire/tools-teams.js +12 -62
  231. package/dist/repertoire/tools-travel.js +125 -0
  232. package/dist/repertoire/tools-user-profile.js +144 -0
  233. package/dist/repertoire/tools-vault.js +110 -0
  234. package/dist/repertoire/tools.js +144 -138
  235. package/dist/repertoire/travel-api-client.js +360 -0
  236. package/dist/repertoire/user-profile.js +118 -0
  237. package/dist/repertoire/vault-setup.js +241 -0
  238. package/dist/scripts/claude-code-hook.js +41 -0
  239. package/dist/scripts/claude-code-stop-hook.js +47 -0
  240. package/dist/senses/attention-queue.js +116 -0
  241. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  242. package/dist/senses/bluebubbles/attachment-download.js +137 -0
  243. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +225 -9
  244. package/dist/senses/bluebubbles/entry.js +13 -0
  245. package/dist/senses/bluebubbles/inbound-log.js +113 -0
  246. package/dist/senses/bluebubbles/index.js +1590 -0
  247. package/dist/senses/{bluebubbles-media.js → bluebubbles/media.js} +121 -70
  248. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +43 -12
  249. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +46 -6
  250. package/dist/senses/bluebubbles/replay.js +129 -0
  251. package/dist/senses/bluebubbles/runtime-state.js +109 -0
  252. package/dist/senses/{bluebubbles-session-cleanup.js → bluebubbles/session-cleanup.js} +1 -1
  253. package/dist/senses/cli/bracketed-paste.js +82 -0
  254. package/dist/senses/cli/image-paste.js +287 -0
  255. package/dist/senses/cli/image-ref-navigation.js +75 -0
  256. package/dist/senses/cli/ink-app.js +156 -0
  257. package/dist/senses/cli/inline-diff.js +64 -0
  258. package/dist/senses/cli/input-keys.js +174 -0
  259. package/dist/senses/cli/kill-ring.js +86 -0
  260. package/dist/senses/cli/message-list.js +51 -0
  261. package/dist/senses/cli/ouro-tui.js +605 -0
  262. package/dist/senses/cli/spinner-imperative.js +135 -0
  263. package/dist/senses/cli/spinner.js +101 -0
  264. package/dist/senses/cli/status-line.js +60 -0
  265. package/dist/senses/cli/streaming-markdown.js +526 -0
  266. package/dist/senses/cli/tool-display.js +83 -0
  267. package/dist/senses/cli/tool-render.js +85 -0
  268. package/dist/senses/cli/tui-store.js +240 -0
  269. package/dist/senses/cli/virtual-list.js +35 -0
  270. package/dist/senses/cli-entry.js +1 -1
  271. package/dist/senses/cli-layout.js +187 -0
  272. package/dist/senses/cli.js +595 -246
  273. package/dist/senses/commands.js +65 -1
  274. package/dist/senses/continuity.js +94 -0
  275. package/dist/senses/habit-turn-message.js +108 -0
  276. package/dist/senses/inner-dialog-worker.js +112 -19
  277. package/dist/senses/inner-dialog.js +633 -86
  278. package/dist/senses/pipeline.js +567 -0
  279. package/dist/senses/shared-turn.js +199 -0
  280. package/dist/senses/surface-tool.js +68 -0
  281. package/dist/senses/teams.js +665 -160
  282. package/dist/senses/trust-gate.js +112 -2
  283. package/package.json +29 -7
  284. package/skills/agent-commerce.md +106 -0
  285. package/skills/browser-navigation.md +110 -0
  286. package/skills/commerce-setup-guide.md +116 -0
  287. package/skills/commerce-setup.md +84 -0
  288. package/skills/configure-dev-tools.md +81 -0
  289. package/skills/travel-planning.md +138 -0
  290. package/dist/heart/daemon/subagent-installer.js +0 -134
  291. package/dist/senses/bluebubbles-entry.js +0 -11
  292. package/dist/senses/bluebubbles.js +0 -547
  293. package/dist/senses/debug-activity.js +0 -124
  294. package/subagents/README.md +0 -73
  295. package/subagents/work-doer.md +0 -235
  296. package/subagents/work-merger.md +0 -618
  297. package/subagents/work-planner.md +0 -382
  298. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  299. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  300. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  301. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  302. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  303. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  304. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  305. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  306. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  307. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  308. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  309. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +0 -0
  310. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  311. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  312. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  313. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  314. /package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +0 -0
@@ -1,547 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.handleBlueBubblesEvent = handleBlueBubblesEvent;
37
- exports.createBlueBubblesWebhookHandler = createBlueBubblesWebhookHandler;
38
- exports.startBlueBubblesApp = startBlueBubblesApp;
39
- const http = __importStar(require("node:http"));
40
- const path = __importStar(require("node:path"));
41
- const core_1 = require("../heart/core");
42
- const config_1 = require("../heart/config");
43
- const identity_1 = require("../heart/identity");
44
- const context_1 = require("../mind/context");
45
- const tokens_1 = require("../mind/friends/tokens");
46
- const resolver_1 = require("../mind/friends/resolver");
47
- const store_file_1 = require("../mind/friends/store-file");
48
- const prompt_1 = require("../mind/prompt");
49
- const phrases_1 = require("../mind/phrases");
50
- const runtime_1 = require("../nerves/runtime");
51
- const bluebubbles_model_1 = require("./bluebubbles-model");
52
- const bluebubbles_client_1 = require("./bluebubbles-client");
53
- const bluebubbles_mutation_log_1 = require("./bluebubbles-mutation-log");
54
- const bluebubbles_session_cleanup_1 = require("./bluebubbles-session-cleanup");
55
- const debug_activity_1 = require("./debug-activity");
56
- const defaultDeps = {
57
- getAgentName: identity_1.getAgentName,
58
- buildSystem: prompt_1.buildSystem,
59
- runAgent: core_1.runAgent,
60
- loadSession: context_1.loadSession,
61
- postTurn: context_1.postTurn,
62
- sessionPath: config_1.sessionPath,
63
- accumulateFriendTokens: tokens_1.accumulateFriendTokens,
64
- createClient: () => (0, bluebubbles_client_1.createBlueBubblesClient)(),
65
- recordMutation: bluebubbles_mutation_log_1.recordBlueBubblesMutation,
66
- createFriendStore: () => new store_file_1.FileFriendStore(path.join((0, identity_1.getAgentRoot)(), "friends")),
67
- createFriendResolver: (store, params) => new resolver_1.FriendResolver(store, params),
68
- createServer: http.createServer,
69
- };
70
- function resolveFriendParams(event) {
71
- if (event.chat.isGroup) {
72
- const groupKey = event.chat.chatGuid ?? event.chat.chatIdentifier ?? event.sender.externalId;
73
- return {
74
- provider: "imessage-handle",
75
- externalId: `group:${groupKey}`,
76
- displayName: event.chat.displayName ?? "Unknown Group",
77
- channel: "bluebubbles",
78
- };
79
- }
80
- return {
81
- provider: "imessage-handle",
82
- externalId: event.sender.externalId || event.sender.rawId,
83
- displayName: event.sender.displayName || "Unknown",
84
- channel: "bluebubbles",
85
- };
86
- }
87
- function extractMessageText(content) {
88
- if (typeof content === "string")
89
- return content;
90
- if (!Array.isArray(content))
91
- return "";
92
- return content
93
- .map((part) => {
94
- if (part && typeof part === "object" && "type" in part && part.type === "text" && typeof part.text === "string") {
95
- return part.text;
96
- }
97
- return "";
98
- })
99
- .filter(Boolean)
100
- .join("\n");
101
- }
102
- function extractHistoricalLaneSummary(messages) {
103
- const seen = new Set();
104
- const summaries = [];
105
- for (let index = messages.length - 1; index >= 0; index--) {
106
- const message = messages[index];
107
- if (message.role !== "user")
108
- continue;
109
- const text = extractMessageText(message.content);
110
- if (!text)
111
- continue;
112
- const firstLine = text.split("\n")[0].trim();
113
- const threadMatch = firstLine.match(/thread id: ([^\]|]+)/i);
114
- const laneKey = threadMatch
115
- ? `thread:${threadMatch[1].trim()}`
116
- : /top[-_]level/i.test(firstLine)
117
- ? "top_level"
118
- : null;
119
- if (!laneKey || seen.has(laneKey))
120
- continue;
121
- seen.add(laneKey);
122
- const snippet = text
123
- .split("\n")
124
- .slice(1)
125
- .map((line) => line.trim())
126
- .find(Boolean)
127
- ?.slice(0, 80) ?? "(no recent text)";
128
- summaries.push({
129
- key: laneKey,
130
- label: laneKey === "top_level" ? "top_level" : laneKey,
131
- snippet,
132
- });
133
- if (summaries.length >= 5)
134
- break;
135
- }
136
- return summaries;
137
- }
138
- function buildConversationScopePrefix(event, existingMessages) {
139
- if (event.kind !== "message") {
140
- return "";
141
- }
142
- const summaries = extractHistoricalLaneSummary(existingMessages);
143
- const lines = [];
144
- if (event.threadOriginatorGuid?.trim()) {
145
- lines.push(`[conversation scope: existing chat trunk | current inbound lane: thread | current thread id: ${event.threadOriginatorGuid.trim()} | default outbound target for this turn: current_lane]`);
146
- }
147
- else {
148
- lines.push("[conversation scope: existing chat trunk | current inbound lane: top_level | default outbound target for this turn: top_level]");
149
- }
150
- if (summaries.length > 0) {
151
- lines.push("[recent active lanes]");
152
- for (const summary of summaries) {
153
- lines.push(`- ${summary.label}: ${summary.snippet}`);
154
- }
155
- }
156
- if (event.threadOriginatorGuid?.trim() || summaries.some((summary) => summary.key.startsWith("thread:"))) {
157
- lines.push("[routing control: use bluebubbles_set_reply_target with target=top_level to widen back out, or target=thread plus a listed thread id to route into a specific active thread]");
158
- }
159
- return lines.join("\n");
160
- }
161
- function buildInboundText(event, existingMessages) {
162
- const metadataPrefix = buildConversationScopePrefix(event, existingMessages);
163
- const baseText = event.repairNotice?.trim()
164
- ? `${event.textForAgent}\n[${event.repairNotice.trim()}]`
165
- : event.textForAgent;
166
- if (!event.chat.isGroup) {
167
- return metadataPrefix ? `${metadataPrefix}\n${baseText}` : baseText;
168
- }
169
- const scopedText = metadataPrefix ? `${metadataPrefix}\n${baseText}` : baseText;
170
- if (event.kind === "mutation") {
171
- return `${event.sender.displayName} ${scopedText}`;
172
- }
173
- return `${event.sender.displayName}: ${scopedText}`;
174
- }
175
- function buildInboundContent(event, existingMessages) {
176
- const text = buildInboundText(event, existingMessages);
177
- if (event.kind !== "message" || !event.inputPartsForAgent || event.inputPartsForAgent.length === 0) {
178
- return text;
179
- }
180
- return [
181
- { type: "text", text },
182
- ...event.inputPartsForAgent,
183
- ];
184
- }
185
- function createReplyTargetController(event) {
186
- const defaultTargetLabel = event.kind === "message" && event.threadOriginatorGuid?.trim() ? "current_lane" : "top_level";
187
- let selection = event.kind === "message" && event.threadOriginatorGuid?.trim()
188
- ? { target: "current_lane" }
189
- : { target: "top_level" };
190
- return {
191
- getReplyToMessageGuid() {
192
- if (event.kind !== "message")
193
- return undefined;
194
- if (selection.target === "top_level")
195
- return undefined;
196
- if (selection.target === "thread")
197
- return selection.threadOriginatorGuid.trim();
198
- return event.threadOriginatorGuid?.trim() ? event.messageGuid : undefined;
199
- },
200
- setSelection(next) {
201
- selection = next;
202
- if (next.target === "top_level") {
203
- return "bluebubbles reply target override: top_level";
204
- }
205
- if (next.target === "thread") {
206
- return `bluebubbles reply target override: thread:${next.threadOriginatorGuid}`;
207
- }
208
- return `bluebubbles reply target: using default for this turn (${defaultTargetLabel})`;
209
- },
210
- };
211
- }
212
- function createBlueBubblesCallbacks(client, chat, replyTarget) {
213
- let textBuffer = "";
214
- const phrases = (0, phrases_1.getPhrases)();
215
- const activity = (0, debug_activity_1.createDebugActivityController)({
216
- thinkingPhrases: phrases.thinking,
217
- followupPhrases: phrases.followup,
218
- startTypingOnModelStart: true,
219
- suppressInitialModelStatus: true,
220
- transport: {
221
- sendStatus: async (text) => {
222
- const sent = await client.sendText({
223
- chat,
224
- text,
225
- replyToMessageGuid: replyTarget.getReplyToMessageGuid(),
226
- });
227
- return sent.messageGuid;
228
- },
229
- editStatus: async (_messageGuid, text) => {
230
- await client.sendText({
231
- chat,
232
- text,
233
- replyToMessageGuid: replyTarget.getReplyToMessageGuid(),
234
- });
235
- },
236
- setTyping: async (active) => {
237
- await client.setTyping(chat, active);
238
- },
239
- },
240
- onTransportError: (operation, error) => {
241
- (0, runtime_1.emitNervesEvent)({
242
- level: "warn",
243
- component: "senses",
244
- event: "senses.bluebubbles_activity_error",
245
- message: "bluebubbles activity transport failed",
246
- meta: {
247
- operation,
248
- reason: error instanceof Error ? error.message : String(error),
249
- },
250
- });
251
- },
252
- });
253
- return {
254
- onModelStart() {
255
- activity.onModelStart();
256
- (0, runtime_1.emitNervesEvent)({
257
- component: "senses",
258
- event: "senses.bluebubbles_turn_start",
259
- message: "bluebubbles turn started",
260
- meta: { chatGuid: chat.chatGuid ?? null },
261
- });
262
- },
263
- onModelStreamStart() {
264
- (0, runtime_1.emitNervesEvent)({
265
- component: "senses",
266
- event: "senses.bluebubbles_stream_start",
267
- message: "bluebubbles non-streaming response started",
268
- meta: {},
269
- });
270
- },
271
- onTextChunk(text) {
272
- activity.onTextChunk(text);
273
- textBuffer += text;
274
- },
275
- onReasoningChunk(_text) { },
276
- onToolStart(name, _args) {
277
- activity.onToolStart(name, _args);
278
- (0, runtime_1.emitNervesEvent)({
279
- component: "senses",
280
- event: "senses.bluebubbles_tool_start",
281
- message: "bluebubbles tool execution started",
282
- meta: { name },
283
- });
284
- },
285
- onToolEnd(name, summary, success) {
286
- activity.onToolEnd(name, summary, success);
287
- (0, runtime_1.emitNervesEvent)({
288
- component: "senses",
289
- event: "senses.bluebubbles_tool_end",
290
- message: "bluebubbles tool execution completed",
291
- meta: { name, success, summary },
292
- });
293
- },
294
- onError(error, severity) {
295
- activity.onError(error);
296
- (0, runtime_1.emitNervesEvent)({
297
- level: severity === "terminal" ? "error" : "warn",
298
- component: "senses",
299
- event: "senses.bluebubbles_turn_error",
300
- message: "bluebubbles turn callback error",
301
- meta: { severity, reason: error.message },
302
- });
303
- },
304
- onClearText() {
305
- textBuffer = "";
306
- },
307
- async flush() {
308
- await activity.drain();
309
- const trimmed = textBuffer.trim();
310
- if (!trimmed) {
311
- await activity.finish();
312
- return;
313
- }
314
- textBuffer = "";
315
- await activity.finish();
316
- await client.sendText({
317
- chat,
318
- text: trimmed,
319
- replyToMessageGuid: replyTarget.getReplyToMessageGuid(),
320
- });
321
- },
322
- async finish() {
323
- await activity.finish();
324
- },
325
- };
326
- }
327
- async function readRequestBody(req) {
328
- let body = "";
329
- for await (const chunk of req) {
330
- body += chunk.toString();
331
- }
332
- return body;
333
- }
334
- function writeJson(res, statusCode, payload) {
335
- res.statusCode = statusCode;
336
- res.setHeader("Content-Type", "application/json; charset=utf-8");
337
- res.end(JSON.stringify(payload));
338
- }
339
- function isWebhookPasswordValid(url, expectedPassword) {
340
- const provided = url.searchParams.get("password");
341
- return !provided || provided === expectedPassword;
342
- }
343
- async function handleBlueBubblesEvent(payload, deps = {}) {
344
- const resolvedDeps = { ...defaultDeps, ...deps };
345
- const client = resolvedDeps.createClient();
346
- const event = await client.repairEvent((0, bluebubbles_model_1.normalizeBlueBubblesEvent)(payload));
347
- if (event.fromMe) {
348
- (0, runtime_1.emitNervesEvent)({
349
- component: "senses",
350
- event: "senses.bluebubbles_from_me_ignored",
351
- message: "ignored from-me bluebubbles event",
352
- meta: {
353
- messageGuid: event.messageGuid,
354
- kind: event.kind,
355
- },
356
- });
357
- return { handled: true, notifiedAgent: false, kind: event.kind, reason: "from_me" };
358
- }
359
- if (event.kind === "mutation") {
360
- try {
361
- resolvedDeps.recordMutation(resolvedDeps.getAgentName(), event);
362
- }
363
- catch (error) {
364
- (0, runtime_1.emitNervesEvent)({
365
- level: "error",
366
- component: "senses",
367
- event: "senses.bluebubbles_mutation_log_error",
368
- message: "failed recording bluebubbles mutation sidecar",
369
- meta: {
370
- messageGuid: event.messageGuid,
371
- mutationType: event.mutationType,
372
- reason: error instanceof Error ? error.message : String(error),
373
- },
374
- });
375
- }
376
- }
377
- if (event.kind === "mutation" && !event.shouldNotifyAgent) {
378
- (0, runtime_1.emitNervesEvent)({
379
- component: "senses",
380
- event: "senses.bluebubbles_state_mutation_recorded",
381
- message: "recorded non-notify bluebubbles mutation",
382
- meta: {
383
- messageGuid: event.messageGuid,
384
- mutationType: event.mutationType,
385
- },
386
- });
387
- return { handled: true, notifiedAgent: false, kind: event.kind, reason: "mutation_state_only" };
388
- }
389
- const store = resolvedDeps.createFriendStore();
390
- const resolver = resolvedDeps.createFriendResolver(store, resolveFriendParams(event));
391
- const context = await resolver.resolve();
392
- const replyTarget = createReplyTargetController(event);
393
- const toolContext = {
394
- signin: async () => undefined,
395
- friendStore: store,
396
- summarize: (0, core_1.createSummarize)(),
397
- context,
398
- bluebubblesReplyTarget: {
399
- setSelection: (selection) => replyTarget.setSelection(selection),
400
- },
401
- codingFeedback: {
402
- send: async (message) => {
403
- await client.sendText({
404
- chat: event.chat,
405
- text: message,
406
- replyToMessageGuid: replyTarget.getReplyToMessageGuid(),
407
- });
408
- },
409
- },
410
- };
411
- const friendId = context.friend.id;
412
- const sessPath = resolvedDeps.sessionPath(friendId, "bluebubbles", event.chat.sessionKey);
413
- try {
414
- (0, bluebubbles_session_cleanup_1.findObsoleteBlueBubblesThreadSessions)(sessPath);
415
- }
416
- catch (error) {
417
- (0, runtime_1.emitNervesEvent)({
418
- level: "warn",
419
- component: "senses",
420
- event: "senses.bluebubbles_thread_lane_cleanup_error",
421
- message: "failed to inspect obsolete bluebubbles thread-lane sessions",
422
- meta: {
423
- sessionPath: sessPath,
424
- reason: error instanceof Error ? error.message : String(error),
425
- },
426
- });
427
- }
428
- const existing = resolvedDeps.loadSession(sessPath);
429
- const messages = existing?.messages && existing.messages.length > 0
430
- ? existing.messages
431
- : [{ role: "system", content: await resolvedDeps.buildSystem("bluebubbles", undefined, context) }];
432
- messages.push({ role: "user", content: buildInboundContent(event, existing?.messages ?? messages) });
433
- const callbacks = createBlueBubblesCallbacks(client, event.chat, replyTarget);
434
- const controller = new AbortController();
435
- const agentOptions = {
436
- toolContext,
437
- };
438
- try {
439
- const result = await resolvedDeps.runAgent(messages, callbacks, "bluebubbles", controller.signal, agentOptions);
440
- await callbacks.flush();
441
- resolvedDeps.postTurn(messages, sessPath, result.usage);
442
- await resolvedDeps.accumulateFriendTokens(store, friendId, result.usage);
443
- try {
444
- await client.markChatRead(event.chat);
445
- }
446
- catch (error) {
447
- (0, runtime_1.emitNervesEvent)({
448
- level: "warn",
449
- component: "senses",
450
- event: "senses.bluebubbles_mark_read_error",
451
- message: "failed to mark bluebubbles chat as read",
452
- meta: {
453
- chatGuid: event.chat.chatGuid ?? null,
454
- reason: error instanceof Error ? error.message : String(error),
455
- },
456
- });
457
- }
458
- (0, runtime_1.emitNervesEvent)({
459
- component: "senses",
460
- event: "senses.bluebubbles_turn_end",
461
- message: "bluebubbles event handled",
462
- meta: {
463
- messageGuid: event.messageGuid,
464
- kind: event.kind,
465
- sessionKey: event.chat.sessionKey,
466
- },
467
- });
468
- return {
469
- handled: true,
470
- notifiedAgent: true,
471
- kind: event.kind,
472
- };
473
- }
474
- finally {
475
- await callbacks.finish();
476
- }
477
- }
478
- function createBlueBubblesWebhookHandler(deps = {}) {
479
- return async (req, res) => {
480
- const url = new URL(req.url ?? "/", "http://127.0.0.1");
481
- const channelConfig = (0, config_1.getBlueBubblesChannelConfig)();
482
- const runtimeConfig = (0, config_1.getBlueBubblesConfig)();
483
- if (url.pathname !== channelConfig.webhookPath) {
484
- writeJson(res, 404, { error: "Not found" });
485
- return;
486
- }
487
- if (req.method !== "POST") {
488
- writeJson(res, 405, { error: "Method not allowed" });
489
- return;
490
- }
491
- if (!isWebhookPasswordValid(url, runtimeConfig.password)) {
492
- writeJson(res, 401, { error: "Unauthorized" });
493
- return;
494
- }
495
- let payload;
496
- try {
497
- const rawBody = await readRequestBody(req);
498
- payload = JSON.parse(rawBody);
499
- }
500
- catch (error) {
501
- (0, runtime_1.emitNervesEvent)({
502
- level: "warn",
503
- component: "senses",
504
- event: "senses.bluebubbles_webhook_bad_json",
505
- message: "failed to parse bluebubbles webhook body",
506
- meta: {
507
- reason: error instanceof Error ? error.message : String(error),
508
- },
509
- });
510
- writeJson(res, 400, { error: "Invalid JSON body" });
511
- return;
512
- }
513
- try {
514
- const result = await handleBlueBubblesEvent(payload, deps);
515
- writeJson(res, 200, result);
516
- }
517
- catch (error) {
518
- (0, runtime_1.emitNervesEvent)({
519
- level: "error",
520
- component: "senses",
521
- event: "senses.bluebubbles_webhook_error",
522
- message: "bluebubbles webhook handling failed",
523
- meta: {
524
- reason: error instanceof Error ? error.message : String(error),
525
- },
526
- });
527
- writeJson(res, 500, {
528
- error: error instanceof Error ? error.message : String(error),
529
- });
530
- }
531
- };
532
- }
533
- function startBlueBubblesApp(deps = {}) {
534
- const resolvedDeps = { ...defaultDeps, ...deps };
535
- resolvedDeps.createClient();
536
- const channelConfig = (0, config_1.getBlueBubblesChannelConfig)();
537
- const server = resolvedDeps.createServer(createBlueBubblesWebhookHandler(deps));
538
- server.listen(channelConfig.port, () => {
539
- (0, runtime_1.emitNervesEvent)({
540
- component: "channels",
541
- event: "channel.app_started",
542
- message: "BlueBubbles sense started",
543
- meta: { port: channelConfig.port, webhookPath: channelConfig.webhookPath },
544
- });
545
- });
546
- return server;
547
- }
@@ -1,124 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDebugActivityController = createDebugActivityController;
4
- const format_1 = require("../mind/format");
5
- const phrases_1 = require("../mind/phrases");
6
- const runtime_1 = require("../nerves/runtime");
7
- function createDebugActivityController(options) {
8
- let queue = Promise.resolve();
9
- let statusMessageGuid;
10
- let typingActive = false;
11
- let hadToolRun = false;
12
- let followupShown = false;
13
- let lastPhrase = "";
14
- function reportTransportError(operation, error) {
15
- (0, runtime_1.emitNervesEvent)({
16
- level: "warn",
17
- component: "senses",
18
- event: "senses.debug_activity_transport_error",
19
- message: "debug activity transport failed",
20
- meta: {
21
- operation,
22
- reason: error instanceof Error ? error.message : String(error),
23
- },
24
- });
25
- options.onTransportError?.(operation, error);
26
- }
27
- function enqueue(operation, task) {
28
- queue = queue
29
- .then(task)
30
- .catch((error) => {
31
- reportTransportError(operation, error);
32
- });
33
- }
34
- function nextPhrase(pool) {
35
- const phrase = (0, phrases_1.pickPhrase)(pool, lastPhrase);
36
- lastPhrase = phrase;
37
- return phrase;
38
- }
39
- function startTypingNow() {
40
- if (typingActive) {
41
- return;
42
- }
43
- typingActive = true;
44
- enqueue("typing_start", async () => {
45
- await options.transport.setTyping(true);
46
- });
47
- }
48
- function setStatus(text) {
49
- (0, runtime_1.emitNervesEvent)({
50
- component: "senses",
51
- event: "senses.debug_activity_update",
52
- message: "debug activity status updated",
53
- meta: {
54
- hasStatusGuid: Boolean(statusMessageGuid),
55
- textLength: text.length,
56
- },
57
- });
58
- const shouldStartTyping = !typingActive;
59
- if (shouldStartTyping) {
60
- typingActive = true;
61
- }
62
- enqueue("status_update", async () => {
63
- if (statusMessageGuid) {
64
- await options.transport.editStatus(statusMessageGuid, text);
65
- }
66
- else {
67
- statusMessageGuid = await options.transport.sendStatus(text);
68
- }
69
- if (shouldStartTyping) {
70
- await options.transport.setTyping(true);
71
- }
72
- });
73
- }
74
- return {
75
- onModelStart() {
76
- const pool = hadToolRun ? options.followupPhrases : options.thinkingPhrases;
77
- if (options.startTypingOnModelStart) {
78
- startTypingNow();
79
- }
80
- if (options.suppressInitialModelStatus && !statusMessageGuid && !hadToolRun) {
81
- nextPhrase(pool);
82
- return;
83
- }
84
- setStatus(`${nextPhrase(pool)}...`);
85
- },
86
- onToolStart(name, args) {
87
- hadToolRun = true;
88
- followupShown = false;
89
- const argSummary = Object.values(args).join(", ");
90
- const detail = argSummary ? ` (${argSummary})` : "";
91
- setStatus(`running ${name}${detail}...`);
92
- },
93
- onToolEnd(name, summary, success) {
94
- hadToolRun = true;
95
- followupShown = false;
96
- setStatus((0, format_1.formatToolResult)(name, summary, success));
97
- },
98
- onTextChunk(text) {
99
- if (!text || !hadToolRun || followupShown) {
100
- return;
101
- }
102
- followupShown = true;
103
- setStatus(`${nextPhrase(options.followupPhrases)}...`);
104
- },
105
- onError(error) {
106
- setStatus((0, format_1.formatError)(error));
107
- this.finish();
108
- },
109
- async drain() {
110
- await queue;
111
- },
112
- async finish() {
113
- if (!typingActive) {
114
- await queue;
115
- return;
116
- }
117
- typingActive = false;
118
- enqueue("typing_stop", async () => {
119
- await options.transport.setTyping(false);
120
- });
121
- await queue;
122
- },
123
- };
124
- }