@ouro.bot/cli 0.1.0-alpha.2 → 0.1.0-alpha.200

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 (215) hide show
  1. package/README.md +187 -191
  2. package/SerpentGuide.ouro/agent.json +82 -0
  3. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/SOUL.md +6 -3
  4. package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +2 -2
  5. package/assets/ouroboros.png +0 -0
  6. package/changelog.json +1248 -0
  7. package/dist/heart/active-work.js +832 -0
  8. package/dist/heart/bridges/manager.js +358 -0
  9. package/dist/heart/bridges/state-machine.js +135 -0
  10. package/dist/heart/bridges/store.js +123 -0
  11. package/dist/heart/cares.js +179 -0
  12. package/dist/heart/commitments.js +111 -0
  13. package/dist/heart/config.js +114 -28
  14. package/dist/heart/core.js +689 -120
  15. package/dist/heart/cross-chat-delivery.js +146 -0
  16. package/dist/heart/daemon/agent-config-check.js +149 -0
  17. package/dist/heart/daemon/agent-discovery.js +81 -0
  18. package/dist/heart/daemon/agent-service.js +360 -0
  19. package/dist/heart/daemon/auth-flow.js +477 -0
  20. package/dist/heart/daemon/cadence.js +70 -0
  21. package/dist/heart/daemon/daemon-cli.js +2897 -193
  22. package/dist/heart/daemon/daemon-entry.js +194 -8
  23. package/dist/heart/daemon/daemon-health.js +136 -0
  24. package/dist/heart/daemon/daemon-runtime-sync.js +231 -0
  25. package/dist/heart/daemon/daemon-tombstone.js +123 -0
  26. package/dist/heart/daemon/daemon.js +488 -13
  27. package/dist/heart/daemon/habit-migration.js +181 -0
  28. package/dist/heart/daemon/habit-parser.js +119 -0
  29. package/dist/heart/daemon/habit-scheduler.js +369 -0
  30. package/dist/heart/daemon/hatch-animation.js +35 -0
  31. package/dist/heart/daemon/hatch-flow.js +32 -122
  32. package/dist/heart/daemon/hatch-specialist.js +7 -2
  33. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  34. package/dist/heart/daemon/hooks/bundle-meta.js +206 -0
  35. package/dist/heart/daemon/inner-status.js +89 -0
  36. package/dist/heart/daemon/launchd.js +165 -0
  37. package/dist/heart/daemon/log-tailer.js +4 -3
  38. package/dist/heart/daemon/mcp-server.js +591 -0
  39. package/dist/heart/daemon/message-router.js +17 -8
  40. package/dist/heart/daemon/os-cron-deps.js +134 -0
  41. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  42. package/dist/heart/daemon/ouro-bot-wrapper.js +4 -3
  43. package/dist/heart/daemon/ouro-path-installer.js +221 -0
  44. package/dist/heart/daemon/ouro-uti.js +11 -2
  45. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  46. package/dist/heart/daemon/outlook-http.js +439 -0
  47. package/dist/heart/daemon/outlook-read.js +1618 -0
  48. package/dist/heart/daemon/outlook-render.js +1032 -0
  49. package/dist/heart/daemon/outlook-types.js +7 -0
  50. package/dist/heart/daemon/outlook-view.js +194 -0
  51. package/dist/heart/daemon/process-manager.js +94 -1
  52. package/dist/heart/daemon/run-hooks.js +39 -0
  53. package/dist/heart/daemon/runtime-logging.js +61 -14
  54. package/dist/heart/daemon/runtime-metadata.js +219 -0
  55. package/dist/heart/daemon/runtime-mode.js +67 -0
  56. package/dist/heart/daemon/safe-mode.js +161 -0
  57. package/dist/heart/daemon/sense-manager.js +314 -0
  58. package/dist/heart/daemon/session-id-resolver.js +131 -0
  59. package/dist/heart/daemon/skill-management-installer.js +94 -0
  60. package/dist/heart/daemon/socket-client.js +202 -0
  61. package/dist/heart/daemon/specialist-orchestrator.js +129 -0
  62. package/dist/heart/daemon/specialist-prompt.js +101 -0
  63. package/dist/heart/daemon/specialist-tools.js +283 -0
  64. package/dist/heart/daemon/staged-restart.js +138 -0
  65. package/dist/heart/daemon/task-scheduler.js +3 -25
  66. package/dist/heart/daemon/thoughts.js +507 -0
  67. package/dist/heart/daemon/update-checker.js +111 -0
  68. package/dist/heart/daemon/update-hooks.js +138 -0
  69. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  70. package/dist/heart/delegation.js +62 -0
  71. package/dist/heart/identity.js +220 -52
  72. package/dist/heart/intentions.js +173 -0
  73. package/dist/heart/kicks.js +2 -20
  74. package/dist/heart/migrate-config.js +127 -0
  75. package/dist/heart/model-capabilities.js +48 -0
  76. package/dist/heart/obligations.js +225 -0
  77. package/dist/heart/presence.js +185 -0
  78. package/dist/heart/progress-story.js +42 -0
  79. package/dist/heart/provider-failover.js +88 -0
  80. package/dist/heart/provider-ping.js +178 -0
  81. package/dist/heart/providers/anthropic-token.js +163 -0
  82. package/dist/heart/providers/anthropic.js +199 -36
  83. package/dist/heart/providers/azure.js +116 -10
  84. package/dist/heart/providers/github-copilot.js +157 -0
  85. package/dist/heart/providers/minimax.js +33 -3
  86. package/dist/heart/providers/openai-codex.js +51 -16
  87. package/dist/heart/sense-truth.js +61 -0
  88. package/dist/heart/session-activity.js +172 -0
  89. package/dist/heart/session-recall.js +216 -0
  90. package/dist/heart/start-of-turn-packet.js +232 -0
  91. package/dist/heart/streaming.js +120 -33
  92. package/dist/heart/sync.js +217 -0
  93. package/dist/heart/target-resolution.js +127 -0
  94. package/dist/heart/tempo.js +93 -0
  95. package/dist/heart/temporal-view.js +41 -0
  96. package/dist/heart/tool-activity-callbacks.js +36 -0
  97. package/dist/heart/tool-description.js +135 -0
  98. package/dist/heart/tool-loop.js +200 -0
  99. package/dist/heart/turn-coordinator.js +28 -0
  100. package/dist/mind/associative-recall.js +122 -32
  101. package/dist/mind/bundle-manifest.js +77 -1
  102. package/dist/mind/context.js +125 -14
  103. package/dist/mind/{memory.js → diary.js} +69 -56
  104. package/dist/mind/episodes.js +119 -0
  105. package/dist/mind/file-state.js +179 -0
  106. package/dist/mind/first-impressions.js +16 -2
  107. package/dist/mind/friends/channel.js +64 -0
  108. package/dist/mind/friends/group-context.js +144 -0
  109. package/dist/mind/friends/store-file.js +36 -0
  110. package/dist/mind/friends/trust-explanation.js +74 -0
  111. package/dist/mind/friends/types.js +9 -1
  112. package/dist/mind/journal-index.js +161 -0
  113. package/dist/mind/obligation-steering.js +221 -0
  114. package/dist/mind/obligations.js +138 -0
  115. package/dist/mind/pending.js +76 -9
  116. package/dist/mind/phrases.js +1 -0
  117. package/dist/mind/prompt.js +861 -105
  118. package/dist/mind/scrutiny.js +173 -0
  119. package/dist/mind/token-estimate.js +8 -12
  120. package/dist/nerves/cli-logging.js +15 -2
  121. package/dist/nerves/coverage/audit.js +1 -1
  122. package/dist/nerves/coverage/run-artifacts.js +1 -1
  123. package/dist/nerves/event-buffer.js +111 -0
  124. package/dist/nerves/index.js +63 -3
  125. package/dist/nerves/observation.js +20 -0
  126. package/dist/nerves/runtime.js +5 -1
  127. package/dist/outlook-ui/assets/index-Ck8agNeO.js +61 -0
  128. package/dist/outlook-ui/assets/index-LwChZTgL.css +1 -0
  129. package/dist/outlook-ui/index.html +15 -0
  130. package/dist/repertoire/ado-client.js +4 -2
  131. package/dist/repertoire/ado-semantic.js +11 -5
  132. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  133. package/dist/repertoire/coding/context-pack.js +330 -0
  134. package/dist/repertoire/coding/feedback.js +301 -0
  135. package/dist/repertoire/coding/index.js +4 -1
  136. package/dist/repertoire/coding/manager.js +210 -4
  137. package/dist/repertoire/coding/spawner.js +58 -12
  138. package/dist/repertoire/coding/tools.js +209 -7
  139. package/dist/repertoire/data/ado-endpoints.json +188 -0
  140. package/dist/repertoire/guardrails.js +291 -0
  141. package/dist/repertoire/mcp-client.js +254 -0
  142. package/dist/repertoire/mcp-manager.js +251 -0
  143. package/dist/repertoire/shell-sessions.js +133 -0
  144. package/dist/repertoire/skills.js +14 -23
  145. package/dist/repertoire/tasks/board.js +43 -5
  146. package/dist/repertoire/tasks/fix.js +182 -0
  147. package/dist/repertoire/tasks/index.js +28 -10
  148. package/dist/repertoire/tasks/lifecycle.js +2 -2
  149. package/dist/repertoire/tasks/parser.js +3 -2
  150. package/dist/repertoire/tasks/scanner.js +194 -37
  151. package/dist/repertoire/tasks/transitions.js +11 -28
  152. package/dist/repertoire/tools-base.js +1360 -271
  153. package/dist/repertoire/tools-bluebubbles.js +94 -0
  154. package/dist/repertoire/tools-github.js +1 -6
  155. package/dist/repertoire/tools-teams.js +65 -59
  156. package/dist/repertoire/tools.js +318 -91
  157. package/dist/scripts/claude-code-hook.js +41 -0
  158. package/dist/scripts/claude-code-stop-hook.js +47 -0
  159. package/dist/senses/attention-queue.js +97 -0
  160. package/dist/senses/bluebubbles-client.js +532 -0
  161. package/dist/senses/bluebubbles-entry.js +13 -0
  162. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  163. package/dist/senses/bluebubbles-media.js +339 -0
  164. package/dist/senses/bluebubbles-model.js +261 -0
  165. package/dist/senses/bluebubbles-mutation-log.js +116 -0
  166. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  167. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  168. package/dist/senses/bluebubbles.js +1327 -0
  169. package/dist/senses/cli/adapter.js +274 -0
  170. package/dist/senses/cli/ink-app.js +156 -0
  171. package/dist/senses/cli/inline-diff.js +64 -0
  172. package/dist/senses/cli/message-list.js +51 -0
  173. package/dist/senses/cli/ouro-tui.js +349 -0
  174. package/dist/senses/cli/spinner-imperative.js +135 -0
  175. package/dist/senses/cli/spinner.js +101 -0
  176. package/dist/senses/cli/status-line.js +60 -0
  177. package/dist/senses/cli/streaming-markdown.js +526 -0
  178. package/dist/senses/cli/tool-display.js +83 -0
  179. package/dist/senses/cli/tool-render.js +85 -0
  180. package/dist/senses/cli/tui-store.js +198 -0
  181. package/dist/senses/cli/virtual-list.js +35 -0
  182. package/dist/senses/cli-entry.js +1 -1
  183. package/dist/senses/cli-layout.js +187 -0
  184. package/dist/senses/cli.js +687 -262
  185. package/dist/senses/commands.js +65 -1
  186. package/dist/senses/continuity.js +94 -0
  187. package/dist/senses/habit-turn-message.js +108 -0
  188. package/dist/senses/inner-dialog-worker.js +112 -19
  189. package/dist/senses/inner-dialog.js +592 -84
  190. package/dist/senses/pipeline.js +693 -0
  191. package/dist/senses/shared-turn.js +196 -0
  192. package/dist/senses/surface-tool.js +95 -0
  193. package/dist/senses/teams.js +817 -151
  194. package/dist/senses/trust-gate.js +112 -2
  195. package/package.json +24 -7
  196. package/skills/configure-dev-tools.md +81 -0
  197. package/subagents/README.md +4 -70
  198. package/AdoptionSpecialist.ouro/agent.json +0 -20
  199. package/dist/heart/daemon/subagent-installer.js +0 -125
  200. package/dist/inner-worker-entry.js +0 -4
  201. package/subagents/work-doer.md +0 -233
  202. package/subagents/work-merger.md +0 -624
  203. package/subagents/work-planner.md +0 -373
  204. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  205. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  206. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  207. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  208. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  209. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  210. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  211. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  212. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  213. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  214. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +0 -0
  215. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
@@ -0,0 +1,171 @@
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.getOuroCliHome = getOuroCliHome;
37
+ exports.getCurrentVersion = getCurrentVersion;
38
+ exports.getPreviousVersion = getPreviousVersion;
39
+ exports.buildChangelogCommand = buildChangelogCommand;
40
+ exports.listInstalledVersions = listInstalledVersions;
41
+ exports.installVersion = installVersion;
42
+ exports.activateVersion = activateVersion;
43
+ exports.ensureLayout = ensureLayout;
44
+ const fs = __importStar(require("fs"));
45
+ const os = __importStar(require("os"));
46
+ const path = __importStar(require("path"));
47
+ const runtime_1 = require("../../nerves/runtime");
48
+ function getOuroCliHome(homeDir) {
49
+ /* v8 ignore next -- dep default: tests always inject @preserve */
50
+ const home = homeDir ?? os.homedir();
51
+ return path.join(home, ".ouro-cli");
52
+ }
53
+ function getCurrentVersion(deps) {
54
+ const cliHome = getOuroCliHome(deps.homeDir);
55
+ /* v8 ignore next -- dep default: tests always inject @preserve */
56
+ const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
57
+ try {
58
+ const target = readlinkSync(path.join(cliHome, "CurrentVersion"));
59
+ return path.basename(target);
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ function getPreviousVersion(deps) {
66
+ const cliHome = getOuroCliHome(deps.homeDir);
67
+ /* v8 ignore next -- dep default: tests always inject @preserve */
68
+ const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
69
+ try {
70
+ const target = readlinkSync(path.join(cliHome, "previous"));
71
+ return path.basename(target);
72
+ }
73
+ catch {
74
+ return null;
75
+ }
76
+ }
77
+ function buildChangelogCommand(previousVersion, currentVersion) {
78
+ if (!previousVersion || !currentVersion || previousVersion === currentVersion) {
79
+ return null;
80
+ }
81
+ return `ouro changelog --from ${previousVersion}`;
82
+ }
83
+ function listInstalledVersions(deps) {
84
+ const cliHome = getOuroCliHome(deps.homeDir);
85
+ /* v8 ignore next -- dep default: tests always inject @preserve */
86
+ const readdirSync = deps.readdirSync ?? ((p, opts) => fs.readdirSync(p, opts));
87
+ try {
88
+ const entries = readdirSync(path.join(cliHome, "versions"), { withFileTypes: true });
89
+ return entries.filter((e) => e.isDirectory()).map((e) => e.name);
90
+ }
91
+ catch {
92
+ return [];
93
+ }
94
+ }
95
+ function installVersion(version, deps) {
96
+ const cliHome = getOuroCliHome(deps.homeDir);
97
+ /* v8 ignore start -- dep defaults: tests always inject @preserve */
98
+ const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
99
+ const execSync = deps.execSync ?? ((cmd, opts) => require("child_process").execSync(cmd, opts));
100
+ /* v8 ignore stop */
101
+ const versionDir = path.join(cliHome, "versions", version);
102
+ (0, runtime_1.emitNervesEvent)({
103
+ component: "daemon",
104
+ event: "daemon.cli_version_install_start",
105
+ message: "installing CLI version",
106
+ meta: { version, versionDir },
107
+ });
108
+ mkdirSync(versionDir, { recursive: true });
109
+ execSync(`npm install --prefix ${versionDir} @ouro.bot/cli@${version}`, { stdio: "pipe" });
110
+ (0, runtime_1.emitNervesEvent)({
111
+ component: "daemon",
112
+ event: "daemon.cli_version_install_end",
113
+ message: "CLI version installed",
114
+ meta: { version, versionDir },
115
+ });
116
+ }
117
+ function activateVersion(version, deps) {
118
+ const cliHome = getOuroCliHome(deps.homeDir);
119
+ /* v8 ignore start -- dep defaults: tests always inject @preserve */
120
+ const readlinkSync = deps.readlinkSync ?? fs.readlinkSync;
121
+ const unlinkSync = deps.unlinkSync ?? fs.unlinkSync;
122
+ const symlinkSync = deps.symlinkSync ?? fs.symlinkSync;
123
+ const existsSync = deps.existsSync ?? fs.existsSync;
124
+ /* v8 ignore stop */
125
+ const currentVersionPath = path.join(cliHome, "CurrentVersion");
126
+ const previousPath = path.join(cliHome, "previous");
127
+ const newTarget = path.join(cliHome, "versions", version);
128
+ (0, runtime_1.emitNervesEvent)({
129
+ component: "daemon",
130
+ event: "daemon.cli_version_activate",
131
+ message: "activating CLI version",
132
+ meta: { version },
133
+ });
134
+ // Read old CurrentVersion target (may not exist)
135
+ let oldTarget = null;
136
+ try {
137
+ oldTarget = readlinkSync(currentVersionPath);
138
+ }
139
+ catch {
140
+ // No current version — first install
141
+ }
142
+ // Update previous symlink to point to old current
143
+ if (oldTarget) {
144
+ try {
145
+ unlinkSync(previousPath);
146
+ }
147
+ catch {
148
+ // previous symlink may not exist yet
149
+ }
150
+ symlinkSync(oldTarget, previousPath);
151
+ }
152
+ // Update CurrentVersion symlink
153
+ if (existsSync(currentVersionPath)) {
154
+ unlinkSync(currentVersionPath);
155
+ }
156
+ symlinkSync(newTarget, currentVersionPath);
157
+ }
158
+ function ensureLayout(deps) {
159
+ const cliHome = getOuroCliHome(deps.homeDir);
160
+ /* v8 ignore next -- dep default: tests always inject @preserve */
161
+ const mkdirSync = deps.mkdirSync ?? fs.mkdirSync;
162
+ mkdirSync(cliHome, { recursive: true });
163
+ mkdirSync(path.join(cliHome, "bin"), { recursive: true });
164
+ mkdirSync(path.join(cliHome, "versions"), { recursive: true });
165
+ (0, runtime_1.emitNervesEvent)({
166
+ component: "daemon",
167
+ event: "daemon.cli_layout_ensured",
168
+ message: "CLI directory layout ensured",
169
+ meta: { cliHome },
170
+ });
171
+ }
@@ -0,0 +1,439 @@
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
+ readAgentContinuity: options.readAgentContinuity ?? ((agentName) => (0, outlook_read_1.readOutlookContinuity)(agentRoot(agentName), agentName)),
200
+ readAgentOrientation: options.readAgentOrientation ?? ((agentName) => (0, outlook_read_1.readOrientationView)(agentRoot(agentName), agentName)),
201
+ readAgentObligations: options.readAgentObligations ?? ((agentName) => (0, outlook_read_1.readObligationDetailView)(agentRoot(agentName))),
202
+ readAgentChanges: options.readAgentChanges ?? ((agentName) => (0, outlook_read_1.readChangesView)(agentRoot(agentName))),
203
+ readAgentSelfFix: options.readAgentSelfFix ?? ((agentName) => (0, outlook_read_1.readSelfFixView)(agentRoot(agentName))),
204
+ readAgentMemoryDecisions: options.readAgentMemoryDecisions ?? ((agentName) => (0, outlook_read_1.readMemoryDecisionView)(agentRoot(agentName))),
205
+ readAgentHabits: options.readAgentHabits ?? ((agentName) => (0, outlook_read_1.readHabitView)(agentRoot(agentName))),
206
+ readDaemonHealth: options.readDaemonHealth ?? (() => (0, outlook_read_1.readDaemonHealthDeep)(options.healthPath)),
207
+ readLogs: options.readLogs ?? (() => (0, outlook_read_1.readLogView)(options.logPath ?? null)),
208
+ };
209
+ /* v8 ignore stop */
210
+ const sse = createSseBroadcaster();
211
+ /* v8 ignore start — watcher callback fires on filesystem changes */
212
+ const bundleWatcher = bundlesRoot ? createBundleWatcher(bundlesRoot, () => {
213
+ sse.broadcast("state-changed", { at: new Date().toISOString() });
214
+ }) : null;
215
+ /* v8 ignore stop */
216
+ const server = http.createServer((request, response) => {
217
+ let pathname = normalizePath(request.url);
218
+ const origin = `http://${host}:${server.address().port}`;
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
+ // Compatibility alias: /outlook/api/* → /api/*
239
+ /* v8 ignore start -- legacy compat path: tested via integration @preserve */
240
+ if (pathname.startsWith("/outlook/api/")) {
241
+ pathname = pathname.slice("/outlook".length);
242
+ }
243
+ else if (pathname === "/outlook/api") {
244
+ pathname = "/api";
245
+ }
246
+ /* v8 ignore stop */
247
+ // SSE event stream
248
+ if (pathname === "/api/events") {
249
+ response.writeHead(200, { "content-type": "text/event-stream", "cache-control": "no-cache", "connection": "keep-alive", "access-control-allow-origin": "*" });
250
+ response.write(":ok\n\n");
251
+ sse.add(response);
252
+ return;
253
+ }
254
+ if (pathname === "/api/machine") {
255
+ const machine = readMachineState();
256
+ const machineView = readMachineView?.({ origin, machine });
257
+ writeJson(response, 200, machineView ?? machine);
258
+ return;
259
+ }
260
+ if (pathname === "/api/machine/health") {
261
+ const health = hooks.readDaemonHealth();
262
+ writeJson(response, 200, health ?? { status: "unavailable" });
263
+ return;
264
+ }
265
+ if (pathname === "/api/machine/logs") {
266
+ writeJson(response, 200, hooks.readLogs());
267
+ return;
268
+ }
269
+ // Agent-level endpoints: /api/agents/:agent[/:surface[/:params...]]
270
+ const agentMatch = /^\/api\/agents\/([^/]+)(?:\/(.+))?$/.exec(pathname);
271
+ if (agentMatch) {
272
+ const agent = decodeURIComponent(agentMatch[1]);
273
+ const surface = agentMatch[2] ?? null;
274
+ if (!surface) {
275
+ const view = readAgentView?.(agent);
276
+ if (view) {
277
+ writeJson(response, 200, view);
278
+ return;
279
+ }
280
+ const state = readAgentState(agent);
281
+ if (!state) {
282
+ writeJson(response, 404, { ok: false, error: `unknown agent: ${agent}` });
283
+ return;
284
+ }
285
+ writeJson(response, 200, state);
286
+ return;
287
+ }
288
+ if (surface === "sessions") {
289
+ writeJson(response, 200, hooks.readAgentSessions(agent));
290
+ return;
291
+ }
292
+ const transcriptMatch = /^sessions\/([^/]+)\/([^/]+)\/([^/]+)$/.exec(surface);
293
+ if (transcriptMatch) {
294
+ const friendId = decodeURIComponent(transcriptMatch[1]);
295
+ const channel = decodeURIComponent(transcriptMatch[2]);
296
+ const key = decodeURIComponent(transcriptMatch[3]);
297
+ const transcript = hooks.readAgentTranscript(agent, friendId, channel, key);
298
+ if (!transcript) {
299
+ writeJson(response, 404, { ok: false, error: "session not found" });
300
+ return;
301
+ }
302
+ writeJson(response, 200, transcript);
303
+ return;
304
+ }
305
+ if (surface === "coding") {
306
+ writeJson(response, 200, hooks.readAgentCoding(agent));
307
+ return;
308
+ }
309
+ if (surface === "attention") {
310
+ writeJson(response, 200, hooks.readAgentAttention(agent));
311
+ return;
312
+ }
313
+ if (surface === "bridges") {
314
+ writeJson(response, 200, hooks.readAgentBridges(agent));
315
+ return;
316
+ }
317
+ if (surface === "memory") {
318
+ writeJson(response, 200, hooks.readAgentMemory(agent));
319
+ return;
320
+ }
321
+ if (surface === "friends") {
322
+ writeJson(response, 200, hooks.readAgentFriends(agent));
323
+ return;
324
+ }
325
+ if (surface === "continuity") {
326
+ writeJson(response, 200, hooks.readAgentContinuity(agent));
327
+ return;
328
+ }
329
+ if (surface === "orientation") {
330
+ writeJson(response, 200, hooks.readAgentOrientation(agent));
331
+ return;
332
+ }
333
+ if (surface === "obligations") {
334
+ writeJson(response, 200, hooks.readAgentObligations(agent));
335
+ return;
336
+ }
337
+ if (surface === "changes") {
338
+ writeJson(response, 200, hooks.readAgentChanges(agent));
339
+ return;
340
+ }
341
+ if (surface === "self-fix") {
342
+ writeJson(response, 200, hooks.readAgentSelfFix(agent));
343
+ return;
344
+ }
345
+ if (surface === "memory-decisions") {
346
+ writeJson(response, 200, hooks.readAgentMemoryDecisions(agent));
347
+ return;
348
+ }
349
+ /* v8 ignore start — desk prefs write + reads */
350
+ if (surface === "dismiss-obligation" && request.method === "POST") {
351
+ let body = "";
352
+ request.on("data", (chunk) => { body += chunk; });
353
+ request.on("end", () => {
354
+ try {
355
+ const { obligationId } = JSON.parse(body);
356
+ if (!obligationId) {
357
+ writeJson(response, 400, { ok: false, error: "obligationId required" });
358
+ return;
359
+ }
360
+ const prefsPath = path.join(agentRoot(agent), "state", "outlook-prefs.json");
361
+ let prefs = {};
362
+ try {
363
+ prefs = JSON.parse(fs.readFileSync(prefsPath, "utf-8"));
364
+ }
365
+ catch { /* new file */ }
366
+ const dismissed = Array.isArray(prefs.dismissedObligations) ? prefs.dismissedObligations : [];
367
+ if (!dismissed.includes(obligationId))
368
+ dismissed.push(obligationId);
369
+ prefs.dismissedObligations = dismissed;
370
+ fs.mkdirSync(path.dirname(prefsPath), { recursive: true });
371
+ fs.writeFileSync(prefsPath, JSON.stringify(prefs, null, 2) + "\n", "utf-8");
372
+ writeJson(response, 200, { ok: true, dismissed: dismissed.length });
373
+ }
374
+ catch (error) {
375
+ writeJson(response, 500, { ok: false, error: String(error) });
376
+ }
377
+ });
378
+ return;
379
+ }
380
+ if (surface === "desk-prefs") {
381
+ writeJson(response, 200, (0, outlook_read_1.readDeskPrefs)(agentRoot(agent)));
382
+ return;
383
+ }
384
+ if (surface === "needs-me") {
385
+ writeJson(response, 200, (0, outlook_read_1.readNeedsMeView)(agent, opts));
386
+ return;
387
+ }
388
+ /* v8 ignore stop */
389
+ if (surface === "habits") {
390
+ writeJson(response, 200, hooks.readAgentHabits(agent));
391
+ return;
392
+ }
393
+ if (surface === "inner-transcript") {
394
+ const transcript = hooks.readAgentTranscript(agent, "self", "inner", "dialog");
395
+ writeJson(response, 200, transcript ?? { messageCount: 0, messages: [] });
396
+ return;
397
+ }
398
+ writeJson(response, 404, { ok: false, error: `unknown agent surface: ${surface}` });
399
+ return;
400
+ }
401
+ /* v8 ignore start — SPA fallback for client-side routing */
402
+ const spaDir = resolveSpaDistDir();
403
+ if (spaDir) {
404
+ if (serveStaticFile(response, path.join(spaDir, "index.html")))
405
+ return;
406
+ }
407
+ /* v8 ignore stop */
408
+ writeJson(response, 404, { ok: false, error: `not found: ${pathname}` });
409
+ });
410
+ await new Promise((resolve, reject) => {
411
+ server.once("error", reject);
412
+ server.listen(port, host, () => resolve());
413
+ });
414
+ const address = server.address();
415
+ const origin = `http://${host}:${address.port}`;
416
+ (0, runtime_1.emitNervesEvent)({
417
+ component: "daemon",
418
+ event: "daemon.outlook_http_started",
419
+ message: "started Outlook HTTP server",
420
+ meta: { origin },
421
+ });
422
+ return {
423
+ origin,
424
+ broadcast(event, data) {
425
+ sse.broadcast(event, data);
426
+ },
427
+ async stop() {
428
+ bundleWatcher?.stop();
429
+ sse.disconnectAll();
430
+ await new Promise((resolve) => server.close(() => resolve()));
431
+ (0, runtime_1.emitNervesEvent)({
432
+ component: "daemon",
433
+ event: "daemon.outlook_http_stopped",
434
+ message: "stopped Outlook HTTP server",
435
+ meta: { origin },
436
+ });
437
+ },
438
+ };
439
+ }