@ouro.bot/cli 0.1.0-alpha.17 → 0.1.0-alpha.170

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 (168) hide show
  1. package/AdoptionSpecialist.ouro/agent.json +3 -2
  2. package/AdoptionSpecialist.ouro/psyche/SOUL.md +3 -3
  3. package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
  4. package/README.md +187 -191
  5. package/changelog.json +1145 -0
  6. package/dist/heart/active-work.js +633 -0
  7. package/dist/heart/bridges/manager.js +358 -0
  8. package/dist/heart/bridges/state-machine.js +135 -0
  9. package/dist/heart/bridges/store.js +123 -0
  10. package/dist/heart/commitments.js +105 -0
  11. package/dist/heart/config.js +40 -30
  12. package/dist/heart/core.js +608 -123
  13. package/dist/heart/cross-chat-delivery.js +146 -0
  14. package/dist/heart/daemon/agent-discovery.js +81 -0
  15. package/dist/heart/daemon/agent-service.js +360 -0
  16. package/dist/heart/daemon/auth-flow.js +477 -0
  17. package/dist/heart/daemon/cadence.js +70 -0
  18. package/dist/heart/daemon/daemon-cli.js +2473 -206
  19. package/dist/heart/daemon/daemon-entry.js +140 -4
  20. package/dist/heart/daemon/daemon-health.js +136 -0
  21. package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
  22. package/dist/heart/daemon/daemon-tombstone.js +123 -0
  23. package/dist/heart/daemon/daemon.js +446 -17
  24. package/dist/heart/daemon/habit-migration.js +181 -0
  25. package/dist/heart/daemon/habit-parser.js +119 -0
  26. package/dist/heart/daemon/habit-scheduler.js +369 -0
  27. package/dist/heart/daemon/hatch-animation.js +10 -3
  28. package/dist/heart/daemon/hatch-flow.js +30 -111
  29. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  30. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  31. package/dist/heart/daemon/inner-status.js +89 -0
  32. package/dist/heart/daemon/launchd.js +161 -0
  33. package/dist/heart/daemon/log-tailer.js +4 -3
  34. package/dist/heart/daemon/mcp-server.js +591 -0
  35. package/dist/heart/daemon/message-router.js +17 -8
  36. package/dist/heart/daemon/os-cron-deps.js +134 -0
  37. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  38. package/dist/heart/daemon/ouro-path-installer.js +78 -34
  39. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  40. package/dist/heart/daemon/outlook-http.js +399 -0
  41. package/dist/heart/daemon/outlook-read.js +1291 -0
  42. package/dist/heart/daemon/outlook-render.js +1032 -0
  43. package/dist/heart/daemon/outlook-types.js +7 -0
  44. package/dist/heart/daemon/outlook-view.js +194 -0
  45. package/dist/heart/daemon/process-manager.js +75 -0
  46. package/dist/heart/daemon/run-hooks.js +39 -0
  47. package/dist/heart/daemon/runtime-logging.js +58 -15
  48. package/dist/heart/daemon/runtime-metadata.js +219 -0
  49. package/dist/heart/daemon/runtime-mode.js +67 -0
  50. package/dist/heart/daemon/safe-mode.js +161 -0
  51. package/dist/heart/daemon/sense-manager.js +50 -2
  52. package/dist/heart/daemon/session-id-resolver.js +131 -0
  53. package/dist/heart/daemon/skill-management-installer.js +94 -0
  54. package/dist/heart/daemon/socket-client.js +202 -0
  55. package/dist/heart/daemon/specialist-orchestrator.js +2 -2
  56. package/dist/heart/daemon/specialist-prompt.js +13 -8
  57. package/dist/heart/daemon/specialist-tools.js +53 -4
  58. package/dist/heart/daemon/staged-restart.js +114 -0
  59. package/dist/heart/daemon/task-scheduler.js +3 -25
  60. package/dist/heart/daemon/thoughts.js +507 -0
  61. package/dist/heart/daemon/update-checker.js +111 -0
  62. package/dist/heart/daemon/update-hooks.js +138 -0
  63. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  64. package/dist/heart/delegation.js +62 -0
  65. package/dist/heart/identity.js +136 -55
  66. package/dist/heart/kicks.js +2 -20
  67. package/dist/heart/migrate-config.js +127 -0
  68. package/dist/heart/model-capabilities.js +48 -0
  69. package/dist/heart/obligations.js +197 -0
  70. package/dist/heart/progress-story.js +42 -0
  71. package/dist/heart/provider-failover.js +88 -0
  72. package/dist/heart/provider-ping.js +172 -0
  73. package/dist/heart/providers/anthropic-token.js +163 -0
  74. package/dist/heart/providers/anthropic.js +196 -36
  75. package/dist/heart/providers/azure.js +116 -10
  76. package/dist/heart/providers/github-copilot.js +157 -0
  77. package/dist/heart/providers/minimax.js +33 -3
  78. package/dist/heart/providers/openai-codex.js +51 -16
  79. package/dist/heart/session-activity.js +172 -0
  80. package/dist/heart/session-recall.js +216 -0
  81. package/dist/heart/streaming.js +62 -32
  82. package/dist/heart/target-resolution.js +127 -0
  83. package/dist/heart/tool-activity-callbacks.js +36 -0
  84. package/dist/heart/tool-description.js +135 -0
  85. package/dist/heart/tool-loop.js +200 -0
  86. package/dist/heart/turn-coordinator.js +28 -0
  87. package/dist/mind/associative-recall.js +122 -32
  88. package/dist/mind/bundle-manifest.js +14 -0
  89. package/dist/mind/context.js +125 -14
  90. package/dist/mind/{memory.js → diary.js} +70 -56
  91. package/dist/mind/first-impressions.js +16 -2
  92. package/dist/mind/friends/channel.js +56 -0
  93. package/dist/mind/friends/group-context.js +144 -0
  94. package/dist/mind/friends/store-file.js +19 -0
  95. package/dist/mind/friends/trust-explanation.js +74 -0
  96. package/dist/mind/friends/types.js +8 -0
  97. package/dist/mind/journal-index.js +161 -0
  98. package/dist/mind/obligation-steering.js +221 -0
  99. package/dist/mind/obligations.js +134 -0
  100. package/dist/mind/pending.js +76 -9
  101. package/dist/mind/phrases.js +1 -0
  102. package/dist/mind/prompt.js +649 -89
  103. package/dist/mind/token-estimate.js +8 -12
  104. package/dist/nerves/cli-logging.js +15 -2
  105. package/dist/nerves/coverage/run-artifacts.js +1 -1
  106. package/dist/nerves/event-buffer.js +111 -0
  107. package/dist/nerves/index.js +63 -3
  108. package/dist/nerves/observation.js +20 -0
  109. package/dist/nerves/runtime.js +5 -1
  110. package/dist/outlook-ui/assets/index-CBueh0d3.css +1 -0
  111. package/dist/outlook-ui/assets/index-GtHoFpRM.js +61 -0
  112. package/dist/outlook-ui/index.html +15 -0
  113. package/dist/repertoire/ado-semantic.js +6 -0
  114. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  115. package/dist/repertoire/coding/context-pack.js +254 -0
  116. package/dist/repertoire/coding/feedback.js +197 -30
  117. package/dist/repertoire/coding/manager.js +149 -2
  118. package/dist/repertoire/coding/spawner.js +55 -9
  119. package/dist/repertoire/coding/tools.js +135 -2
  120. package/dist/repertoire/guardrails.js +291 -0
  121. package/dist/repertoire/mcp-client.js +254 -0
  122. package/dist/repertoire/mcp-manager.js +198 -0
  123. package/dist/repertoire/skills.js +14 -23
  124. package/dist/repertoire/tasks/board.js +43 -5
  125. package/dist/repertoire/tasks/fix.js +182 -0
  126. package/dist/repertoire/tasks/index.js +28 -10
  127. package/dist/repertoire/tasks/lifecycle.js +2 -2
  128. package/dist/repertoire/tasks/parser.js +3 -2
  129. package/dist/repertoire/tasks/scanner.js +194 -37
  130. package/dist/repertoire/tasks/transitions.js +11 -28
  131. package/dist/repertoire/tools-base.js +991 -272
  132. package/dist/repertoire/tools-bluebubbles.js +94 -0
  133. package/dist/repertoire/tools-github.js +1 -6
  134. package/dist/repertoire/tools-teams.js +12 -59
  135. package/dist/repertoire/tools.js +281 -122
  136. package/dist/scripts/claude-code-hook.js +41 -0
  137. package/dist/scripts/claude-code-stop-hook.js +47 -0
  138. package/dist/senses/attention-queue.js +97 -0
  139. package/dist/senses/bluebubbles-client.js +102 -3
  140. package/dist/senses/bluebubbles-entry.js +2 -0
  141. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  142. package/dist/senses/bluebubbles-media.js +118 -23
  143. package/dist/senses/bluebubbles-model.js +12 -4
  144. package/dist/senses/bluebubbles-mutation-log.js +45 -5
  145. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  146. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  147. package/dist/senses/bluebubbles.js +1008 -102
  148. package/dist/senses/cli-entry.js +1 -1
  149. package/dist/senses/cli-layout.js +187 -0
  150. package/dist/senses/cli.js +419 -152
  151. package/dist/senses/commands.js +38 -1
  152. package/dist/senses/continuity.js +94 -0
  153. package/dist/senses/habit-turn-message.js +108 -0
  154. package/dist/senses/inner-dialog-worker.js +112 -19
  155. package/dist/senses/inner-dialog.js +592 -84
  156. package/dist/senses/pipeline.js +502 -0
  157. package/dist/senses/shared-turn.js +196 -0
  158. package/dist/senses/surface-tool.js +95 -0
  159. package/dist/senses/teams.js +667 -120
  160. package/dist/senses/trust-gate.js +112 -2
  161. package/package.json +13 -5
  162. package/skills/configure-dev-tools.md +81 -0
  163. package/subagents/README.md +4 -70
  164. package/dist/heart/daemon/subagent-installer.js +0 -134
  165. package/dist/senses/debug-activity.js +0 -107
  166. package/subagents/work-doer.md +0 -235
  167. package/subagents/work-merger.md +0 -618
  168. package/subagents/work-planner.md +0 -382
@@ -0,0 +1,399 @@
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.startOutlookHttpServer = startOutlookHttpServer;
37
+ const fs = __importStar(require("fs"));
38
+ const http = __importStar(require("http"));
39
+ const path = __importStar(require("path"));
40
+ const runtime_1 = require("../../nerves/runtime");
41
+ const outlook_read_1 = require("./outlook-read");
42
+ function createSseBroadcaster() {
43
+ let nextId = 1;
44
+ const clients = new Set();
45
+ function add(response) {
46
+ const client = { id: nextId++, response };
47
+ clients.add(client);
48
+ response.on("close", () => clients.delete(client));
49
+ return client;
50
+ }
51
+ function broadcast(event, data = {}) {
52
+ const payload = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
53
+ for (const client of clients) {
54
+ try {
55
+ client.response.write(payload);
56
+ /* v8 ignore start */
57
+ }
58
+ catch {
59
+ clients.delete(client);
60
+ }
61
+ /* v8 ignore stop */
62
+ }
63
+ }
64
+ function disconnectAll() {
65
+ for (const client of clients) {
66
+ try {
67
+ client.response.end();
68
+ /* v8 ignore start */
69
+ }
70
+ catch {
71
+ /* already closed */
72
+ }
73
+ /* v8 ignore stop */
74
+ }
75
+ clients.clear();
76
+ }
77
+ return { add, broadcast, disconnectAll };
78
+ }
79
+ /* v8 ignore start — filesystem watcher, tested via integration */
80
+ function createBundleWatcher(bundlesRoot, onChange) {
81
+ const watchers = [];
82
+ let debounceTimer = null;
83
+ const DEBOUNCE_MS = 500;
84
+ function debouncedOnChange() {
85
+ if (debounceTimer)
86
+ clearTimeout(debounceTimer);
87
+ debounceTimer = setTimeout(onChange, DEBOUNCE_MS);
88
+ }
89
+ try {
90
+ if (fs.existsSync(bundlesRoot)) {
91
+ const watcher = fs.watch(bundlesRoot, { recursive: true }, debouncedOnChange);
92
+ watchers.push(watcher);
93
+ }
94
+ }
95
+ catch {
96
+ // watch not available — SSE will rely on manual broadcast
97
+ }
98
+ return {
99
+ stop() {
100
+ if (debounceTimer)
101
+ clearTimeout(debounceTimer);
102
+ for (const w of watchers)
103
+ try {
104
+ w.close();
105
+ }
106
+ catch { /* ignore */ }
107
+ watchers.length = 0;
108
+ },
109
+ };
110
+ }
111
+ /* v8 ignore stop */
112
+ function writeJson(response, statusCode, payload) {
113
+ response.writeHead(statusCode, { "content-type": "application/json; charset=utf-8" });
114
+ response.end(`${JSON.stringify(payload, null, 2)}\n`);
115
+ }
116
+ /* v8 ignore start — SPA static file serving infrastructure */
117
+ const MIME_TYPES = {
118
+ ".html": "text/html",
119
+ ".js": "application/javascript",
120
+ ".css": "text/css",
121
+ ".json": "application/json",
122
+ ".svg": "image/svg+xml",
123
+ ".png": "image/png",
124
+ ".ico": "image/x-icon",
125
+ ".woff2": "font/woff2",
126
+ };
127
+ function resolveSpaDistDir() {
128
+ // Look for the built SPA relative to this file's location
129
+ // In production: dist/heart/daemon/outlook-http.js -> ../../packages/outlook-ui/dist/
130
+ // In dev: packages/outlook-ui/dist/
131
+ const candidates = [
132
+ path.resolve(__dirname, "..", "..", "..", "packages", "outlook-ui", "dist"),
133
+ path.resolve(__dirname, "..", "..", "packages", "outlook-ui", "dist"),
134
+ path.resolve(__dirname, "..", "..", "..", "..", "packages", "outlook-ui", "dist"),
135
+ // npm-published layout: the SPA dist is copied to dist/outlook-ui/
136
+ path.resolve(__dirname, "..", "..", "outlook-ui"),
137
+ path.resolve(__dirname, "..", "outlook-ui"),
138
+ ];
139
+ for (const candidate of candidates) {
140
+ if (fs.existsSync(path.join(candidate, "index.html")))
141
+ return candidate;
142
+ }
143
+ return null;
144
+ }
145
+ function serveStaticFile(response, filePath) {
146
+ try {
147
+ if (!fs.existsSync(filePath))
148
+ return false;
149
+ const ext = path.extname(filePath);
150
+ const contentType = MIME_TYPES[ext] ?? "application/octet-stream";
151
+ const content = fs.readFileSync(filePath);
152
+ response.writeHead(200, {
153
+ "content-type": contentType,
154
+ "cache-control": ext === ".html" ? "no-cache" : "public, max-age=31536000, immutable",
155
+ });
156
+ response.end(content);
157
+ return true;
158
+ }
159
+ catch {
160
+ return false;
161
+ }
162
+ }
163
+ /* v8 ignore stop */
164
+ function normalizePath(urlValue = "/") {
165
+ const parsed = new URL(urlValue, "http://127.0.0.1");
166
+ const normalizedPath = parsed.pathname.replace(/\/+$/, "");
167
+ if (normalizedPath.length === 0)
168
+ return "/";
169
+ return normalizedPath;
170
+ }
171
+ async function startOutlookHttpServer(options = {}) {
172
+ const host = options.host ?? "127.0.0.1";
173
+ const port = options.port ?? 0;
174
+ const bundlesRoot = options.bundlesRoot;
175
+ const opts = bundlesRoot ? { bundlesRoot } : undefined;
176
+ const readMachineState = options.readMachineState ?? (() => (0, outlook_read_1.readOutlookMachineState)(opts));
177
+ const readMachineView = options.readMachineView;
178
+ /* v8 ignore start */
179
+ const readAgentState = options.readAgentState ?? ((agentName) => {
180
+ if (opts)
181
+ return (0, outlook_read_1.readOutlookAgentState)(agentName, opts);
182
+ return (0, outlook_read_1.readOutlookAgentState)(agentName);
183
+ });
184
+ /* v8 ignore stop */
185
+ const readAgentView = options.readAgentView;
186
+ /* v8 ignore start — default hook wiring, tested via integration */
187
+ const agentRoot = (agentName) => {
188
+ const base = bundlesRoot ?? "";
189
+ return path.join(base, `${agentName}.ouro`);
190
+ };
191
+ const hooks = {
192
+ readAgentSessions: options.readAgentSessions ?? ((agentName) => (0, outlook_read_1.readSessionInventory)(agentName, bundlesRoot ? { bundlesRoot } : undefined)),
193
+ readAgentTranscript: options.readAgentTranscript ?? ((agentName, friendId, channel, key) => (0, outlook_read_1.readSessionTranscript)(agentName, friendId, channel, key, bundlesRoot ? { bundlesRoot } : undefined)),
194
+ readAgentCoding: options.readAgentCoding ?? ((agentName) => (0, outlook_read_1.readCodingDeep)(agentRoot(agentName))),
195
+ readAgentAttention: options.readAgentAttention ?? ((agentName) => (0, outlook_read_1.readAttentionView)(agentName, bundlesRoot ? { bundlesRoot } : undefined)),
196
+ readAgentBridges: options.readAgentBridges ?? ((agentName) => (0, outlook_read_1.readBridgeInventory)(agentRoot(agentName))),
197
+ readAgentMemory: options.readAgentMemory ?? ((agentName) => (0, outlook_read_1.readMemoryView)(agentRoot(agentName))),
198
+ readAgentFriends: options.readAgentFriends ?? ((agentName) => (0, outlook_read_1.readFriendView)(agentName, bundlesRoot ? { bundlesRoot } : undefined)),
199
+ readAgentHabits: options.readAgentHabits ?? ((agentName) => (0, outlook_read_1.readHabitView)(agentRoot(agentName))),
200
+ readDaemonHealth: options.readDaemonHealth ?? (() => (0, outlook_read_1.readDaemonHealthDeep)(options.healthPath)),
201
+ readLogs: options.readLogs ?? (() => (0, outlook_read_1.readLogView)(options.logPath ?? null)),
202
+ };
203
+ /* v8 ignore stop */
204
+ const sse = createSseBroadcaster();
205
+ /* v8 ignore start — watcher callback fires on filesystem changes */
206
+ const bundleWatcher = bundlesRoot ? createBundleWatcher(bundlesRoot, () => {
207
+ sse.broadcast("state-changed", { at: new Date().toISOString() });
208
+ }) : null;
209
+ /* v8 ignore stop */
210
+ const server = http.createServer((request, response) => {
211
+ const pathname = normalizePath(request.url);
212
+ const origin = `http://${host}:${server.address().port}`;
213
+ if (pathname === "/outlook/api/events") {
214
+ response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", "connection": "keep-alive", "access-control-allow-origin": "*" });
215
+ response.write(":ok\n\n");
216
+ sse.add(response);
217
+ return;
218
+ }
219
+ /* v8 ignore start — SPA static asset serving */
220
+ // Serve built SPA static assets: /assets/*
221
+ if (pathname.startsWith("/assets/")) {
222
+ const spaDir = resolveSpaDistDir();
223
+ if (spaDir) {
224
+ const assetPath = path.join(spaDir, pathname);
225
+ if (serveStaticFile(response, assetPath))
226
+ return;
227
+ }
228
+ writeJson(response, 404, { ok: false, error: "asset not found" });
229
+ return;
230
+ }
231
+ /* v8 ignore stop */
232
+ // Legacy /outlook route — redirect to root
233
+ if (pathname === "/outlook") {
234
+ response.writeHead(301, { location: "/" });
235
+ response.end();
236
+ return;
237
+ }
238
+ if (pathname === "/outlook/api/machine") {
239
+ const machine = readMachineState();
240
+ const machineView = readMachineView?.({ origin, machine });
241
+ writeJson(response, 200, machineView ?? machine);
242
+ return;
243
+ }
244
+ if (pathname === "/outlook/api/machine/health") {
245
+ const health = hooks.readDaemonHealth();
246
+ writeJson(response, 200, health ?? { status: "unavailable" });
247
+ return;
248
+ }
249
+ if (pathname === "/outlook/api/machine/logs") {
250
+ writeJson(response, 200, hooks.readLogs());
251
+ return;
252
+ }
253
+ // Agent-level endpoints: /outlook/api/agents/:agent[/:surface[/:params...]]
254
+ const agentMatch = /^\/outlook\/api\/agents\/([^/]+)(?:\/(.+))?$/.exec(pathname);
255
+ if (agentMatch) {
256
+ const agent = decodeURIComponent(agentMatch[1]);
257
+ const surface = agentMatch[2] ?? null;
258
+ if (!surface) {
259
+ const view = readAgentView?.(agent);
260
+ if (view) {
261
+ writeJson(response, 200, view);
262
+ return;
263
+ }
264
+ const state = readAgentState(agent);
265
+ if (!state) {
266
+ writeJson(response, 404, { ok: false, error: `unknown agent: ${agent}` });
267
+ return;
268
+ }
269
+ writeJson(response, 200, state);
270
+ return;
271
+ }
272
+ if (surface === "sessions") {
273
+ writeJson(response, 200, hooks.readAgentSessions(agent));
274
+ return;
275
+ }
276
+ const transcriptMatch = /^sessions\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(surface);
277
+ if (transcriptMatch) {
278
+ const friendId = decodeURIComponent(transcriptMatch[1]);
279
+ const channel = decodeURIComponent(transcriptMatch[2]);
280
+ const key = decodeURIComponent(transcriptMatch[3]);
281
+ const transcript = hooks.readAgentTranscript(agent, friendId, channel, key);
282
+ if (!transcript) {
283
+ writeJson(response, 404, { ok: false, error: "session not found" });
284
+ return;
285
+ }
286
+ writeJson(response, 200, transcript);
287
+ return;
288
+ }
289
+ if (surface === "coding") {
290
+ writeJson(response, 200, hooks.readAgentCoding(agent));
291
+ return;
292
+ }
293
+ if (surface === "attention") {
294
+ writeJson(response, 200, hooks.readAgentAttention(agent));
295
+ return;
296
+ }
297
+ if (surface === "bridges") {
298
+ writeJson(response, 200, hooks.readAgentBridges(agent));
299
+ return;
300
+ }
301
+ if (surface === "memory") {
302
+ writeJson(response, 200, hooks.readAgentMemory(agent));
303
+ return;
304
+ }
305
+ if (surface === "friends") {
306
+ writeJson(response, 200, hooks.readAgentFriends(agent));
307
+ return;
308
+ }
309
+ /* v8 ignore start — desk prefs write + reads */
310
+ if (surface === "dismiss-obligation" && request.method === "POST") {
311
+ let body = "";
312
+ request.on("data", (chunk) => { body += chunk; });
313
+ request.on("end", () => {
314
+ try {
315
+ const { obligationId } = JSON.parse(body);
316
+ if (!obligationId) {
317
+ writeJson(response, 400, { ok: false, error: "obligationId required" });
318
+ return;
319
+ }
320
+ const prefsPath = path.join(agentRoot(agent), "state", "outlook-prefs.json");
321
+ let prefs = {};
322
+ try {
323
+ prefs = JSON.parse(fs.readFileSync(prefsPath, "utf-8"));
324
+ }
325
+ catch { /* new file */ }
326
+ const dismissed = Array.isArray(prefs.dismissedObligations) ? prefs.dismissedObligations : [];
327
+ if (!dismissed.includes(obligationId))
328
+ dismissed.push(obligationId);
329
+ prefs.dismissedObligations = dismissed;
330
+ fs.mkdirSync(path.dirname(prefsPath), { recursive: true });
331
+ fs.writeFileSync(prefsPath, JSON.stringify(prefs, null, 2) + "\n", "utf-8");
332
+ writeJson(response, 200, { ok: true, dismissed: dismissed.length });
333
+ }
334
+ catch (error) {
335
+ writeJson(response, 500, { ok: false, error: String(error) });
336
+ }
337
+ });
338
+ return;
339
+ }
340
+ if (surface === "desk-prefs") {
341
+ writeJson(response, 200, (0, outlook_read_1.readDeskPrefs)(agentRoot(agent)));
342
+ return;
343
+ }
344
+ if (surface === "needs-me") {
345
+ writeJson(response, 200, (0, outlook_read_1.readNeedsMeView)(agent, opts));
346
+ return;
347
+ }
348
+ /* v8 ignore stop */
349
+ if (surface === "habits") {
350
+ writeJson(response, 200, hooks.readAgentHabits(agent));
351
+ return;
352
+ }
353
+ if (surface === "inner-transcript") {
354
+ const transcript = hooks.readAgentTranscript(agent, "self", "inner", "dialog");
355
+ writeJson(response, 200, transcript ?? { messageCount: 0, messages: [] });
356
+ return;
357
+ }
358
+ writeJson(response, 404, { ok: false, error: `unknown agent surface: ${surface}` });
359
+ return;
360
+ }
361
+ /* v8 ignore start — SPA fallback for client-side routing */
362
+ const spaDir = resolveSpaDistDir();
363
+ if (spaDir) {
364
+ if (serveStaticFile(response, path.join(spaDir, "index.html")))
365
+ return;
366
+ }
367
+ /* v8 ignore stop */
368
+ writeJson(response, 404, { ok: false, error: `not found: ${pathname}` });
369
+ });
370
+ await new Promise((resolve, reject) => {
371
+ server.once("error", reject);
372
+ server.listen(port, host, () => resolve());
373
+ });
374
+ const address = server.address();
375
+ const origin = `http://${host}:${address.port}`;
376
+ (0, runtime_1.emitNervesEvent)({
377
+ component: "daemon",
378
+ event: "daemon.outlook_http_started",
379
+ message: "started Outlook HTTP server",
380
+ meta: { origin },
381
+ });
382
+ return {
383
+ origin,
384
+ broadcast(event, data) {
385
+ sse.broadcast(event, data);
386
+ },
387
+ async stop() {
388
+ bundleWatcher?.stop();
389
+ sse.disconnectAll();
390
+ await new Promise((resolve) => server.close(() => resolve()));
391
+ (0, runtime_1.emitNervesEvent)({
392
+ component: "daemon",
393
+ event: "daemon.outlook_http_stopped",
394
+ message: "stopped Outlook HTTP server",
395
+ meta: { origin },
396
+ });
397
+ },
398
+ };
399
+ }