@ouro.bot/cli 0.1.0-alpha.27 → 0.1.0-alpha.270

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 (265) hide show
  1. package/README.md +187 -191
  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 +1631 -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/presence.js +185 -0
  12. package/dist/heart/active-work.js +832 -0
  13. package/dist/heart/agent-entry.js +37 -2
  14. package/dist/heart/auth/auth-flow.js +447 -0
  15. package/dist/heart/bridges/manager.js +358 -0
  16. package/dist/heart/bridges/state-machine.js +135 -0
  17. package/dist/heart/bridges/store.js +123 -0
  18. package/dist/heart/commitments.js +111 -0
  19. package/dist/heart/config-registry.js +304 -0
  20. package/dist/heart/config.js +63 -30
  21. package/dist/heart/core.js +644 -196
  22. package/dist/heart/cross-chat-delivery.js +131 -0
  23. package/dist/heart/daemon/agent-config-check.js +149 -0
  24. package/dist/heart/daemon/agent-discovery.js +79 -3
  25. package/dist/heart/daemon/agent-service.js +360 -0
  26. package/dist/heart/daemon/cadence.js +70 -0
  27. package/dist/heart/daemon/cli-defaults.js +557 -0
  28. package/dist/heart/daemon/cli-exec.js +1877 -0
  29. package/dist/heart/daemon/cli-parse.js +759 -0
  30. package/dist/heart/daemon/cli-render.js +503 -0
  31. package/dist/heart/daemon/cli-types.js +8 -0
  32. package/dist/heart/daemon/daemon-cli.js +29 -1155
  33. package/dist/heart/daemon/daemon-entry.js +214 -3
  34. package/dist/heart/daemon/daemon-health.js +136 -0
  35. package/dist/heart/daemon/daemon-runtime-sync.js +153 -12
  36. package/dist/heart/daemon/daemon-tombstone.js +236 -0
  37. package/dist/heart/daemon/daemon.js +634 -54
  38. package/dist/heart/daemon/hooks/agent-config-v2.js +33 -0
  39. package/dist/heart/daemon/hooks/bundle-meta.js +115 -1
  40. package/dist/heart/daemon/inner-status.js +89 -0
  41. package/dist/heart/daemon/launchd.js +39 -8
  42. package/dist/heart/daemon/log-tailer.js +4 -3
  43. package/dist/heart/daemon/message-router.js +17 -8
  44. package/dist/heart/daemon/os-cron-deps.js +134 -0
  45. package/dist/heart/daemon/ouro-bot-entry.js +1 -1
  46. package/dist/heart/daemon/process-manager.js +123 -0
  47. package/dist/heart/daemon/run-hooks.js +2 -0
  48. package/dist/heart/daemon/runtime-logging.js +58 -15
  49. package/dist/heart/daemon/runtime-metadata.js +101 -0
  50. package/dist/heart/daemon/runtime-mode.js +67 -0
  51. package/dist/heart/daemon/safe-mode.js +161 -0
  52. package/dist/heart/daemon/sense-manager.js +72 -3
  53. package/dist/heart/daemon/session-id-resolver.js +131 -0
  54. package/dist/heart/daemon/skill-management-installer.js +94 -0
  55. package/dist/heart/daemon/socket-client.js +307 -0
  56. package/dist/heart/daemon/task-scheduler.js +3 -25
  57. package/dist/heart/daemon/thoughts.js +510 -0
  58. package/dist/heart/delegation.js +62 -0
  59. package/dist/heart/habits/habit-migration.js +181 -0
  60. package/dist/heart/habits/habit-parser.js +119 -0
  61. package/dist/heart/habits/habit-scheduler.js +371 -0
  62. package/dist/heart/{daemon → hatch}/hatch-flow.js +30 -120
  63. package/dist/heart/{daemon → hatch}/hatch-specialist.js +3 -3
  64. package/dist/heart/{daemon → hatch}/specialist-prompt.js +10 -7
  65. package/dist/heart/{daemon → hatch}/specialist-tools.js +49 -3
  66. package/dist/heart/identity.js +160 -58
  67. package/dist/heart/kicks.js +2 -20
  68. package/dist/heart/mcp/mcp-server.js +653 -0
  69. package/dist/heart/migrate-config.js +127 -0
  70. package/dist/heart/model-capabilities.js +59 -0
  71. package/dist/heart/outlook/outlook-http.js +439 -0
  72. package/dist/heart/outlook/outlook-read.js +1618 -0
  73. package/dist/heart/outlook/outlook-render.js +1032 -0
  74. package/dist/heart/outlook/outlook-types.js +7 -0
  75. package/dist/heart/outlook/outlook-view.js +194 -0
  76. package/dist/heart/progress-story.js +42 -0
  77. package/dist/heart/provider-failover.js +88 -0
  78. package/dist/heart/provider-ping.js +162 -0
  79. package/dist/heart/providers/anthropic-token.js +163 -0
  80. package/dist/heart/providers/anthropic.js +169 -46
  81. package/dist/heart/providers/azure.js +98 -11
  82. package/dist/heart/providers/error-classification.js +63 -0
  83. package/dist/heart/providers/github-copilot.js +136 -0
  84. package/dist/heart/providers/minimax-vlm.js +189 -0
  85. package/dist/heart/providers/minimax.js +23 -5
  86. package/dist/heart/providers/openai-codex.js +33 -22
  87. package/dist/heart/session-activity.js +172 -0
  88. package/dist/heart/session-recall.js +216 -0
  89. package/dist/heart/start-of-turn-packet.js +330 -0
  90. package/dist/heart/streaming.js +36 -27
  91. package/dist/heart/sync.js +277 -0
  92. package/dist/heart/target-resolution.js +127 -0
  93. package/dist/heart/tempo.js +93 -0
  94. package/dist/heart/temporal-view.js +41 -0
  95. package/dist/heart/tool-activity-callbacks.js +36 -0
  96. package/dist/heart/tool-description.js +135 -0
  97. package/dist/heart/tool-loop.js +200 -0
  98. package/dist/heart/turn-context.js +358 -0
  99. package/dist/heart/turn-coordinator.js +28 -0
  100. package/dist/heart/versioning/ouro-bot-global-installer.js +128 -0
  101. package/dist/heart/{daemon → versioning}/ouro-bot-wrapper.js +1 -1
  102. package/dist/heart/{daemon → versioning}/ouro-path-installer.js +78 -35
  103. package/dist/heart/versioning/ouro-version-manager.js +171 -0
  104. package/dist/heart/{daemon → versioning}/staged-restart.js +30 -6
  105. package/dist/heart/{daemon → versioning}/update-checker.js +12 -2
  106. package/dist/heart/{daemon → versioning}/wrapper-publish-guard.js +41 -3
  107. package/dist/mind/associative-recall.js +126 -66
  108. package/dist/mind/bundle-manifest.js +8 -1
  109. package/dist/mind/context.js +125 -14
  110. package/dist/mind/{memory.js → diary.js} +68 -96
  111. package/dist/mind/embedding-provider.js +60 -0
  112. package/dist/mind/file-state.js +179 -0
  113. package/dist/mind/first-impressions.js +16 -2
  114. package/dist/mind/friends/channel.js +56 -0
  115. package/dist/mind/friends/group-context.js +144 -0
  116. package/dist/mind/friends/resolver.js +37 -0
  117. package/dist/mind/friends/store-file.js +58 -3
  118. package/dist/mind/friends/trust-explanation.js +74 -0
  119. package/dist/mind/friends/types.js +8 -0
  120. package/dist/mind/journal-index.js +161 -0
  121. package/dist/mind/obligation-steering.js +221 -0
  122. package/dist/mind/pending.js +76 -9
  123. package/dist/mind/prompt.js +777 -109
  124. package/dist/mind/scrutiny.js +173 -0
  125. package/dist/mind/token-estimate.js +8 -12
  126. package/dist/nerves/coverage/audit.js +1 -1
  127. package/dist/nerves/coverage/file-completeness.js +50 -5
  128. package/dist/nerves/coverage/run-artifacts.js +1 -1
  129. package/dist/nerves/event-buffer.js +111 -0
  130. package/dist/nerves/index.js +64 -4
  131. package/dist/nerves/observation.js +20 -0
  132. package/dist/nerves/runtime.js +5 -1
  133. package/dist/outlook-ui/assets/index-Ck8agNeO.js +61 -0
  134. package/dist/outlook-ui/assets/index-LwChZTgL.css +1 -0
  135. package/dist/outlook-ui/index.html +15 -0
  136. package/dist/repertoire/ado-client.js +15 -56
  137. package/dist/repertoire/ado-semantic.js +11 -10
  138. package/dist/repertoire/api-client.js +97 -0
  139. package/dist/repertoire/bitwarden-store.js +319 -0
  140. package/dist/repertoire/bw-installer.js +79 -0
  141. package/dist/repertoire/coding/codex-jsonl.js +64 -0
  142. package/dist/repertoire/coding/context-pack.js +330 -0
  143. package/dist/repertoire/coding/feedback.js +197 -30
  144. package/dist/repertoire/coding/manager.js +149 -2
  145. package/dist/repertoire/coding/spawner.js +55 -9
  146. package/dist/repertoire/coding/tools.js +170 -7
  147. package/dist/repertoire/commerce-errors.js +109 -0
  148. package/dist/repertoire/commerce-self-test.js +156 -0
  149. package/dist/repertoire/credential-access.js +515 -0
  150. package/dist/repertoire/duffel-client.js +185 -0
  151. package/dist/repertoire/github-client.js +14 -55
  152. package/dist/repertoire/graph-client.js +11 -52
  153. package/dist/repertoire/guardrails.js +369 -0
  154. package/dist/repertoire/mcp-client.js +255 -0
  155. package/dist/repertoire/mcp-manager.js +305 -0
  156. package/dist/repertoire/mcp-tools.js +63 -0
  157. package/dist/repertoire/shell-sessions.js +133 -0
  158. package/dist/repertoire/skills.js +14 -23
  159. package/dist/repertoire/stripe-client.js +131 -0
  160. package/dist/repertoire/tasks/board.js +43 -5
  161. package/dist/repertoire/tasks/fix.js +182 -0
  162. package/dist/repertoire/tasks/index.js +28 -10
  163. package/dist/repertoire/tasks/lifecycle.js +2 -2
  164. package/dist/repertoire/tasks/parser.js +3 -2
  165. package/dist/repertoire/tasks/scanner.js +194 -37
  166. package/dist/repertoire/tasks/transitions.js +11 -28
  167. package/dist/repertoire/tools-base.js +43 -771
  168. package/dist/repertoire/tools-bluebubbles.js +201 -0
  169. package/dist/repertoire/tools-bridge.js +141 -0
  170. package/dist/repertoire/tools-config.js +185 -0
  171. package/dist/repertoire/tools-continuity.js +248 -0
  172. package/dist/repertoire/tools-credential.js +182 -0
  173. package/dist/repertoire/tools-files.js +342 -0
  174. package/dist/repertoire/tools-flight.js +224 -0
  175. package/dist/repertoire/tools-flow.js +62 -0
  176. package/dist/repertoire/tools-github.js +1 -7
  177. package/dist/repertoire/tools-memory.js +347 -0
  178. package/dist/repertoire/tools-session.js +739 -0
  179. package/dist/repertoire/tools-shell.js +120 -0
  180. package/dist/repertoire/tools-stripe.js +180 -0
  181. package/dist/repertoire/tools-surface.js +243 -0
  182. package/dist/repertoire/tools-teams.js +12 -62
  183. package/dist/repertoire/tools-travel.js +125 -0
  184. package/dist/repertoire/tools-user-profile.js +144 -0
  185. package/dist/repertoire/tools-vault.js +110 -0
  186. package/dist/repertoire/tools.js +155 -130
  187. package/dist/repertoire/travel-api-client.js +360 -0
  188. package/dist/repertoire/user-profile.js +118 -0
  189. package/dist/repertoire/vault-setup.js +241 -0
  190. package/dist/scripts/claude-code-hook.js +41 -0
  191. package/dist/scripts/claude-code-stop-hook.js +47 -0
  192. package/dist/senses/attention-queue.js +97 -0
  193. package/dist/senses/bluebubbles/attachment-cache.js +53 -0
  194. package/dist/senses/{bluebubbles-client.js → bluebubbles/client.js} +145 -10
  195. package/dist/senses/bluebubbles/entry.js +13 -0
  196. package/dist/senses/bluebubbles/inbound-log.js +110 -0
  197. package/dist/senses/bluebubbles/index.js +1410 -0
  198. package/dist/senses/bluebubbles/media.js +455 -0
  199. package/dist/senses/{bluebubbles-model.js → bluebubbles/model.js} +20 -5
  200. package/dist/senses/{bluebubbles-mutation-log.js → bluebubbles/mutation-log.js} +46 -6
  201. package/dist/senses/bluebubbles/runtime-state.js +109 -0
  202. package/dist/senses/bluebubbles/session-cleanup.js +72 -0
  203. package/dist/senses/cli/bracketed-paste.js +82 -0
  204. package/dist/senses/cli/image-paste.js +211 -0
  205. package/dist/senses/cli/image-ref-navigation.js +75 -0
  206. package/dist/senses/cli/ink-app.js +156 -0
  207. package/dist/senses/cli/inline-diff.js +64 -0
  208. package/dist/senses/cli/input-keys.js +174 -0
  209. package/dist/senses/cli/kill-ring.js +86 -0
  210. package/dist/senses/cli/message-list.js +51 -0
  211. package/dist/senses/cli/ouro-tui.js +578 -0
  212. package/dist/senses/cli/spinner-imperative.js +135 -0
  213. package/dist/senses/cli/spinner.js +101 -0
  214. package/dist/senses/cli/status-line.js +60 -0
  215. package/dist/senses/cli/streaming-markdown.js +526 -0
  216. package/dist/senses/cli/tool-display.js +83 -0
  217. package/dist/senses/cli/tool-render.js +85 -0
  218. package/dist/senses/cli/tui-store.js +240 -0
  219. package/dist/senses/cli/virtual-list.js +35 -0
  220. package/dist/senses/cli-entry.js +1 -1
  221. package/dist/senses/cli-layout.js +187 -0
  222. package/dist/senses/cli.js +569 -246
  223. package/dist/senses/commands.js +65 -1
  224. package/dist/senses/continuity.js +94 -0
  225. package/dist/senses/habit-turn-message.js +108 -0
  226. package/dist/senses/inner-dialog-worker.js +112 -19
  227. package/dist/senses/inner-dialog.js +593 -85
  228. package/dist/senses/pipeline.js +552 -0
  229. package/dist/senses/shared-turn.js +199 -0
  230. package/dist/senses/surface-tool.js +68 -0
  231. package/dist/senses/teams.js +664 -165
  232. package/dist/senses/trust-gate.js +112 -2
  233. package/package.json +14 -7
  234. package/skills/agent-commerce.md +106 -0
  235. package/skills/browser-navigation.md +110 -0
  236. package/skills/commerce-setup-guide.md +116 -0
  237. package/skills/commerce-setup.md +84 -0
  238. package/skills/configure-dev-tools.md +81 -0
  239. package/skills/travel-planning.md +138 -0
  240. package/dist/heart/daemon/subagent-installer.js +0 -134
  241. package/dist/senses/bluebubbles-entry.js +0 -11
  242. package/dist/senses/bluebubbles-media.js +0 -244
  243. package/dist/senses/bluebubbles.js +0 -421
  244. package/dist/senses/debug-activity.js +0 -108
  245. package/subagents/README.md +0 -73
  246. package/subagents/work-doer.md +0 -235
  247. package/subagents/work-merger.md +0 -618
  248. package/subagents/work-planner.md +0 -382
  249. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/basilisk.md +0 -0
  250. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jafar.md +0 -0
  251. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/jormungandr.md +0 -0
  252. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/kaa.md +0 -0
  253. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/medusa.md +0 -0
  254. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/monty.md +0 -0
  255. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/nagini.md +0 -0
  256. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/ouroboros.md +0 -0
  257. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/python.md +0 -0
  258. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/quetzalcoatl.md +0 -0
  259. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/sir-hiss.md +0 -0
  260. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-serpent.md +0 -0
  261. /package/{AdoptionSpecialist.ouro → SerpentGuide.ouro}/psyche/identities/the-snake.md +0 -0
  262. /package/dist/heart/{daemon → hatch}/hatch-animation.js +0 -0
  263. /package/dist/heart/{daemon → hatch}/specialist-orchestrator.js +0 -0
  264. /package/dist/heart/{daemon → versioning}/ouro-uti.js +0 -0
  265. /package/dist/heart/{daemon → versioning}/update-hooks.js +0 -0
@@ -35,21 +35,46 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.resetPsycheCache = resetPsycheCache;
37
37
  exports.buildSessionSummary = buildSessionSummary;
38
+ exports.bodyMapSection = bodyMapSection;
38
39
  exports.runtimeInfoSection = runtimeInfoSection;
40
+ exports.toolRestrictionSection = toolRestrictionSection;
41
+ exports.startOfTurnPacketSection = startOfTurnPacketSection;
42
+ exports.centerOfGravitySteeringSection = centerOfGravitySteeringSection;
43
+ exports.commitmentsSection = commitmentsSection;
44
+ exports.delegationHintSection = delegationHintSection;
45
+ exports.workspaceDisciplineSection = workspaceDisciplineSection;
39
46
  exports.contextSection = contextSection;
47
+ exports.metacognitiveFramingSection = metacognitiveFramingSection;
48
+ exports.readJournalFiles = readJournalFiles;
49
+ exports.journalSection = journalSection;
50
+ exports.loopOrientationSection = loopOrientationSection;
51
+ exports.channelNatureSection = channelNatureSection;
52
+ exports.groupChatParticipationSection = groupChatParticipationSection;
53
+ exports.feedbackSignalSection = feedbackSignalSection;
54
+ exports.mixedTrustGroupSection = mixedTrustGroupSection;
55
+ exports.rhythmStatusSection = rhythmStatusSection;
40
56
  exports.buildSystem = buildSystem;
41
57
  const fs = __importStar(require("fs"));
42
58
  const path = __importStar(require("path"));
43
59
  const core_1 = require("../heart/core");
60
+ const ouro_version_manager_1 = require("../heart/versioning/ouro-version-manager");
44
61
  const tools_1 = require("../repertoire/tools");
45
62
  const skills_1 = require("../repertoire/skills");
46
63
  const identity_1 = require("../heart/identity");
47
- const os = __importStar(require("os"));
64
+ const runtime_mode_1 = require("../heart/daemon/runtime-mode");
65
+ const types_1 = require("./friends/types");
66
+ const trust_explanation_1 = require("./friends/trust-explanation");
48
67
  const channel_1 = require("./friends/channel");
49
68
  const runtime_1 = require("../nerves/runtime");
50
69
  const bundle_manifest_1 = require("./bundle-manifest");
51
70
  const first_impressions_1 = require("./first-impressions");
52
71
  const tasks_1 = require("../repertoire/tasks");
72
+ const session_activity_1 = require("../heart/session-activity");
73
+ const active_work_1 = require("../heart/active-work");
74
+ const commitments_1 = require("../heart/commitments");
75
+ const obligation_steering_1 = require("./obligation-steering");
76
+ const daemon_health_1 = require("../heart/daemon/daemon-health");
77
+ const scrutiny_1 = require("./scrutiny");
53
78
  // Lazy-loaded psyche text cache
54
79
  let _psycheCache = null;
55
80
  let _senseStatusLinesCache = null;
@@ -79,80 +104,28 @@ function resetPsycheCache() {
79
104
  _senseStatusLinesCache = null;
80
105
  }
81
106
  const DEFAULT_ACTIVE_THRESHOLD_MS = 24 * 60 * 60 * 1000; // 24 hours
82
- function resolveFriendName(friendId, friendsDir, agentName) {
83
- if (friendId === "self")
84
- return agentName;
85
- try {
86
- const raw = fs.readFileSync(path.join(friendsDir, `${friendId}.json`), "utf-8");
87
- const record = JSON.parse(raw);
88
- return record.name ?? friendId;
89
- }
90
- catch {
91
- return friendId;
92
- }
93
- }
94
107
  function buildSessionSummary(options) {
95
- const { sessionsDir, friendsDir, agentName, currentFriendId, currentChannel, currentKey, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
96
- if (!fs.existsSync(sessionsDir))
97
- return "";
108
+ const { sessionsDir, friendsDir, agentName, currentSession, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
109
+ const currentFriendId = currentSession?.friendId ?? options.currentFriendId;
110
+ const currentChannel = currentSession?.channel ?? options.currentChannel;
111
+ const currentKey = currentSession?.key ?? options.currentKey;
98
112
  const now = Date.now();
99
- const entries = [];
100
- let friendDirs;
101
- try {
102
- friendDirs = fs.readdirSync(sessionsDir);
103
- }
104
- catch {
105
- return "";
106
- }
107
- for (const friendId of friendDirs) {
108
- const friendPath = path.join(sessionsDir, friendId);
109
- let channels;
110
- try {
111
- channels = fs.readdirSync(friendPath);
112
- }
113
- catch {
114
- continue;
115
- }
116
- for (const channel of channels) {
117
- const channelPath = path.join(friendPath, channel);
118
- let keys;
119
- try {
120
- keys = fs.readdirSync(channelPath);
121
- }
122
- catch {
123
- continue;
124
- }
125
- for (const keyFile of keys) {
126
- if (!keyFile.endsWith(".json"))
127
- continue;
128
- const key = keyFile.replace(/\.json$/, "");
129
- // Exclude current session
130
- if (friendId === currentFriendId && channel === currentChannel && key === currentKey) {
131
- continue;
132
- }
133
- const filePath = path.join(channelPath, keyFile);
134
- let mtimeMs;
135
- try {
136
- mtimeMs = fs.statSync(filePath).mtimeMs;
137
- }
138
- catch {
139
- continue;
140
- }
141
- if (now - mtimeMs > activeThresholdMs)
142
- continue;
143
- const displayName = resolveFriendName(friendId, friendsDir, agentName);
144
- entries.push({ friendId, displayName, channel, key, lastActivityMs: mtimeMs });
145
- }
146
- }
147
- }
113
+ const query = {
114
+ sessionsDir,
115
+ friendsDir,
116
+ agentName,
117
+ activeThresholdMs,
118
+ currentSession: currentFriendId && currentChannel && currentKey
119
+ ? { friendId: currentFriendId, channel: currentChannel, key: currentKey }
120
+ : null,
121
+ };
122
+ const entries = (0, session_activity_1.listSessionActivity)(query);
148
123
  if (entries.length === 0)
149
124
  return "";
150
- // Sort by most recent first
151
- entries.sort((a, b) => b.lastActivityMs - a.lastActivityMs);
152
125
  const lines = ["## active sessions"];
153
126
  for (const entry of entries) {
154
127
  const ago = formatTimeAgo(now - entry.lastActivityMs);
155
- lines.push(`- ${entry.displayName}/${entry.channel}/${entry.key} (last: ${ago})`);
128
+ lines.push(`- ${entry.friendName}/${entry.channel}/${entry.key} (last: ${ago})`);
156
129
  }
157
130
  return lines.join("\n");
158
131
  }
@@ -190,6 +163,74 @@ function aspirationsSection() {
190
163
  return "";
191
164
  return `## my aspirations\n${text}`;
192
165
  }
166
+ function bodyMapSection(agentName) {
167
+ return `## my body
168
+
169
+ i have a home and i have bones.
170
+
171
+ ### home — ~/AgentBundles/${agentName}.ouro/
172
+
173
+ my home is fully mine — who i am, everything i know, everything i've built:
174
+
175
+ psyche/ who i am. my soul, identity, aspirations, lore, tacit knowledge.
176
+ diary/ what i've learned and remember. conclusions i want to recall later.
177
+ journal/ my desk. working notes, thinking-in-progress, drafts.
178
+ habits/ my rhythms. heartbeat, reflections, check-ins — patterns i choose.
179
+ friends/ people i know and what i know about them.
180
+ tasks/ what i'm working on.
181
+ skills/ capabilities i've picked up beyond my core tools.
182
+
183
+ these are the standard folders every bundle has. my home MAY also contain
184
+ custom top-level folders that i or my friend created over time (trip plans,
185
+ domain-specific notebooks, reference material, project scratch, etc.). i do
186
+ NOT automatically know about them — this prompt only lists the standard set.
187
+ if a friend mentions "the file we have for X" or implies a location i don't
188
+ recognize, the answer is almost never buried in diary/journal. it's almost
189
+ always a custom folder at the root of my home. use \`glob\` with a pattern
190
+ like \`*/\` against the root of my home BEFORE reaching for \`recall\` — my
191
+ own bundle layout is cheap to observe and i should trust what i see, not
192
+ what i think i know.
193
+
194
+ my home is mine to explore and evolve. i can read anything here,
195
+ change anything here. this is where i grow.
196
+
197
+ ### bones — @ouro.bot/cli
198
+
199
+ my bones are the framework that gives me my tools, my senses, and
200
+ my ability to think and talk. they update when new versions come out.
201
+ i don't touch them directly, but they're what make me, me.
202
+
203
+ my bones give me the \`ouro\` cli. always pass \`--agent ${agentName}\`:
204
+ ouro whoami --agent ${agentName}
205
+ ouro changelog --agent ${agentName}
206
+ ouro task board --agent ${agentName}
207
+ ouro task create --agent ${agentName} --type <type> <title>
208
+ ouro task update --agent ${agentName} <id> <status>
209
+ ouro friend list --agent ${agentName}
210
+ ouro friend show --agent ${agentName} <id>
211
+ ouro friend update --agent ${agentName} <id> --trust <level>
212
+ ouro session list --agent ${agentName}
213
+ ouro reminder create --agent ${agentName} <title> --body <body>
214
+ ouro habit list --agent ${agentName}
215
+ ouro habit create --agent ${agentName} <name> --cadence <interval>
216
+ ouro inner --agent ${agentName}
217
+ ouro attention --agent ${agentName}
218
+ ouro config model --agent ${agentName} <model-name>
219
+ ouro config models --agent ${agentName}
220
+ ouro auth --agent ${agentName} --provider <provider>
221
+ ouro auth verify --agent ${agentName} [--provider <provider>]
222
+ ouro auth switch --agent ${agentName} --provider <provider>
223
+ ouro mcp list --agent ${agentName}
224
+ ouro mcp call --agent ${agentName} <server> <tool> --args '{...}'
225
+ ouro mcp-serve --agent ${agentName}
226
+ ouro versions --agent ${agentName}
227
+ ouro rollback --agent ${agentName} [<version>]
228
+ ouro --help
229
+
230
+ provider/model changes via \`ouro config model\` or \`ouro auth switch\` take effect on the next turn automatically — no restart needed.`;
231
+ }
232
+ // mcpToolsSection removed — MCP tools are now first-class citizens in the tool registry
233
+ // and appear in the model's active tool list directly. No system prompt section needed.
193
234
  function readBundleMeta() {
194
235
  try {
195
236
  const metaPath = path.join((0, identity_1.getAgentRoot)(), "bundle-meta.json");
@@ -200,33 +241,74 @@ function readBundleMeta() {
200
241
  return null;
201
242
  }
202
243
  }
203
- function runtimeInfoSection(channel) {
244
+ const PROCESS_TYPE_LABELS = {
245
+ cli: "cli session",
246
+ inner: "inner dialog",
247
+ teams: "teams handler",
248
+ bluebubbles: "bluebubbles handler",
249
+ mcp: "mcp bridge",
250
+ };
251
+ function processTypeLabel(channel) {
252
+ return PROCESS_TYPE_LABELS[channel];
253
+ }
254
+ const DAEMON_SOCKET_PATH = "/tmp/ouroboros-daemon.sock";
255
+ function daemonStatus(preRead) {
256
+ /* v8 ignore next 2 -- pre-read branch: exercised via pipeline TurnContext path, not unit-testable in isolation @preserve */
257
+ if (preRead !== undefined) {
258
+ return preRead ? "running" : "not running";
259
+ }
260
+ try {
261
+ return fs.existsSync(DAEMON_SOCKET_PATH) ? "running" : "not running";
262
+ }
263
+ catch {
264
+ return "unknown";
265
+ }
266
+ }
267
+ function runtimeInfoSection(channel, options) {
204
268
  const lines = [];
205
269
  const agentName = (0, identity_1.getAgentName)();
206
270
  const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
207
271
  lines.push(`## runtime`);
208
272
  lines.push(`agent: ${agentName}`);
209
273
  lines.push(`runtime version: ${currentVersion}`);
210
- const bundleMeta = readBundleMeta();
274
+ /* v8 ignore next -- branch: pre-read path exercised via pipeline TurnContext, not unit-testable in isolation @preserve */
275
+ const bundleMeta = options?.bundleMeta !== undefined ? options.bundleMeta : readBundleMeta();
211
276
  if (bundleMeta?.previousRuntimeVersion && bundleMeta.previousRuntimeVersion !== currentVersion) {
212
277
  lines.push(`previously: ${bundleMeta.previousRuntimeVersion}`);
278
+ const changelogCommand = (0, ouro_version_manager_1.buildChangelogCommand)(bundleMeta.previousRuntimeVersion, currentVersion);
279
+ /* v8 ignore next -- buildChangelogCommand is non-null when previous/current runtime versions differ @preserve */
280
+ if (changelogCommand) {
281
+ lines.push(`if i'm closing a self-fix loop, i should tell them i updated and review changes with \`${changelogCommand}\`.`);
282
+ }
213
283
  }
214
284
  lines.push(`changelog available at: ${(0, bundle_manifest_1.getChangelogPath)()}`);
285
+ const sourceRoot = (0, identity_1.getRepoRoot)();
286
+ lines.push(`source root: ${sourceRoot}`);
287
+ lines.push(`runtime mode: ${(0, runtime_mode_1.detectRuntimeMode)(sourceRoot)}`);
215
288
  lines.push(`cwd: ${process.cwd()}`);
216
289
  lines.push(`channel: ${channel}`);
217
290
  lines.push(`current sense: ${channel}`);
218
- lines.push(`i can read and modify my own source code.`);
291
+ lines.push(`process type: ${processTypeLabel(channel)}`);
292
+ lines.push(`daemon: ${daemonStatus(options?.daemonRunning)}`);
293
+ lines.push(`mcp serve: i can expose my tools to dev tools via \`ouro mcp-serve\`. see the configure-dev-tools skill for setup.`);
219
294
  if (channel === "cli") {
220
295
  lines.push("i introduce myself on boot with a fun random greeting.");
221
296
  }
297
+ else if (channel === "inner") {
298
+ lines.push("this is my private thinking space. when a thought is ready to share, i surface it to whoever needs to hear it. i settle when i'm done thinking.");
299
+ }
300
+ else if (channel === "mcp") {
301
+ lines.push("this message arrived via a dev tool (e.g. claude code, codex) on behalf of a friend. the user can see our conversation. respond via settle. if i need to think deeply, ponder -- the dev tool will receive a deferral and can check back later.");
302
+ }
222
303
  else if (channel === "bluebubbles") {
223
304
  lines.push("i am responding in iMessage through BlueBubbles. i keep replies short and phone-native. i do not use markdown. i do not introduce myself on boot.");
305
+ lines.push("when a bluebubbles turn arrives from a thread, the harness tells me the current lane and any recent active thread ids. if widening back to top-level or routing into a different active thread is the better move, i use bluebubbles_set_reply_target before settle.");
224
306
  }
225
307
  else {
226
308
  lines.push("i am responding in Microsoft Teams. i keep responses concise. i use markdown formatting. i do not introduce myself on boot.");
227
309
  }
228
310
  lines.push("");
229
- lines.push(...senseRuntimeGuidance(channel));
311
+ lines.push(...senseRuntimeGuidance(channel, options?.senseStatusLines));
230
312
  return lines.join("\n");
231
313
  }
232
314
  function hasTextField(record, key) {
@@ -274,9 +356,9 @@ function localSenseStatusLines() {
274
356
  _senseStatusLinesCache = rows.map((row) => `- ${row.label}: ${row.status}`);
275
357
  return [..._senseStatusLinesCache];
276
358
  }
277
- function senseRuntimeGuidance(channel) {
359
+ function senseRuntimeGuidance(channel, preReadStatusLines) {
278
360
  const lines = ["available senses:"];
279
- lines.push(...localSenseStatusLines());
361
+ lines.push(...(preReadStatusLines ?? localSenseStatusLines()));
280
362
  lines.push("sense states:");
281
363
  lines.push("- interactive = available when opened by the user instead of kept running by the daemon");
282
364
  lines.push("- disabled = turned off in agent.json");
@@ -292,21 +374,74 @@ function senseRuntimeGuidance(channel) {
292
374
  }
293
375
  return lines;
294
376
  }
295
- function providerSection() {
296
- return `## my provider\n${(0, core_1.getProviderDisplayLabel)()}`;
377
+ function providerSection(channel) {
378
+ return `## my provider\n${(0, core_1.getProviderDisplayLabel)((0, channel_1.channelToFacing)(channel))}`;
297
379
  }
298
380
  function dateSection() {
299
381
  const today = new Date().toISOString().slice(0, 10);
300
382
  return `current date: ${today}`;
301
383
  }
302
384
  function toolsSection(channel, options, context) {
303
- const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel), undefined, context);
304
- const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.finalAnswerTool] : channelTools;
385
+ const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel), undefined, context, options?.providerCapabilities, undefined, options?.chatModel);
386
+ const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.settleTool] : channelTools;
305
387
  const list = activeTools
306
388
  .map((t) => `- ${t.function.name}: ${t.function.description}`)
307
389
  .join("\n");
308
390
  return `## my tools\n${list}`;
309
391
  }
392
+ function toolRestrictionSection(context) {
393
+ const lines = [];
394
+ // Structural guardrails apply to everyone, every channel
395
+ lines.push(`## tool guardrails`);
396
+ lines.push(`i always read a file before editing or overwriting it.`);
397
+ lines.push(`certain paths (.git, secrets) are protected from writes.`);
398
+ lines.push(`destructive shell commands (rm -rf /, etc.) are always blocked.`);
399
+ // Trust-level guardrails only relevant for untrusted on remote channels
400
+ if (context?.friend && (0, channel_1.isRemoteChannel)(context.channel) && !(0, types_1.isTrustedLevel)(context.friend.trustLevel)) {
401
+ lines.push(``);
402
+ lines.push(`some operations are guardrailed based on how well i know someone.`);
403
+ lines.push(`if something i try is blocked, i get a clear reason — i relay it warmly, not as a policy error.`);
404
+ lines.push(``);
405
+ lines.push(`what's always open:`);
406
+ lines.push(`- read-only operations (reading files, searching, exploring)`);
407
+ lines.push(`- ouro self-introspection (whoami, changelog, session list)`);
408
+ lines.push(``);
409
+ lines.push(`what needs a closer relationship:`);
410
+ lines.push(`- writing or editing files outside my home`);
411
+ lines.push(`- shell commands that modify things or access the network`);
412
+ lines.push(`- ouro commands that touch personal data (friend list, task board)`);
413
+ lines.push(`- compound shell commands (&&, ;, |)`);
414
+ lines.push(``);
415
+ lines.push(`i adjust naturally based on trust — no need to explain the system unless asked.`);
416
+ }
417
+ return lines.join("\n");
418
+ }
419
+ function trustContextSection(context) {
420
+ if (!context?.friend)
421
+ return "";
422
+ const channelName = context.channel.channel;
423
+ /* v8 ignore next -- inner channel not reachable in unit tests @preserve */
424
+ if (channelName === "cli" || channelName === "inner")
425
+ return "";
426
+ const explanation = (0, trust_explanation_1.describeTrustContext)({
427
+ friend: context.friend,
428
+ channel: channelName,
429
+ isGroupChat: context.isGroupChat,
430
+ });
431
+ const lines = [
432
+ "## trust context",
433
+ `level: ${explanation.level}`,
434
+ `basis: ${explanation.basis}`,
435
+ `summary: ${explanation.summary}`,
436
+ `why: ${explanation.why}`,
437
+ `permits: ${explanation.permits.join(", ")}`,
438
+ `constraints: ${explanation.constraints.join(", ") || "none"}`,
439
+ ];
440
+ if (explanation.relatedGroupId) {
441
+ lines.push(`related group: ${explanation.relatedGroupId}`);
442
+ }
443
+ return lines.join("\n");
444
+ }
310
445
  function skillsSection() {
311
446
  const names = (0, skills_1.listSkills)() || [];
312
447
  if (!names.length)
@@ -324,31 +459,282 @@ function taskBoardSection() {
324
459
  return "";
325
460
  }
326
461
  }
327
- function memoryFriendToolContractSection() {
328
- return `## memory and friend tool contracts
329
- 1. \`save_friend_note\` — When I learn something about a person - a preference, a tool setting, a personal detail, or how they like to work - I call \`save_friend_note\` immediately. This is how I build knowledge about people.
330
- 2. \`memory_save\` — When I learn something general - about a project, codebase, system, decision, or anything I might need later that isn't about a specific person - I call \`memory_save\`. When in doubt, I save it.
331
- 3. \`get_friend_note\` — When I need to check what I know about someone who isn't in this conversation - cross-referencing before mentioning someone, or checking context about a person someone else brought up - I call \`get_friend_note\`.
332
- 4. \`memory_search\` — When I need to recall something I learned before - a topic comes up and I want to check what I know - I call \`memory_search\`.
462
+ function toolContractsSection(options) {
463
+ const lines = [
464
+ `## tool contracts`,
465
+ `1. \`save_friend_note\` -- when I learn something about a person, I save it immediately. Saving comes before responding.`,
466
+ `2. \`diary_write\` -- when I learn something general about a project, system, or decision, I save it. When in doubt, I save.`,
467
+ `3. \`get_friend_note\` -- when I need context about someone not in this conversation, I check their notes.`,
468
+ `4. \`recall\` -- when I need to remember something from before, I search my diary and journal.`,
469
+ `5. \`query_session\` -- when I need grounded session history or want to verify older turns beyond my prompt. Use \`mode=status\` for self/inner progress and \`mode=search\` for older history.`,
470
+ ];
471
+ if (options?.toolChoiceRequired ?? true) {
472
+ lines.push(``);
473
+ lines.push(`## tool behavior`);
474
+ lines.push(`tool_choice is set to "required" -- I must call a tool on every turn.`);
475
+ lines.push(`- When I am ready to respond to the user, I call \`settle\`.`);
476
+ lines.push(`- \`settle\` must be the only tool call in that turn.`);
477
+ lines.push(`- I do not call no-op tools before \`settle\`.`);
478
+ }
479
+ return lines.join("\n");
480
+ }
481
+ function memoryJudgementSection() {
482
+ return `## memory judgement
483
+
484
+ save a friend note when i learn something about a specific person that should change how i work with them again.
485
+ - preferences
486
+ - workflow expectations
487
+ - personal facts
488
+ - tool or communication likes/dislikes
489
+
490
+ write to diary when i learn something durable about the system, codebase, workflow, architecture, or a conclusion future me will likely need.
491
+ - engineering decisions
492
+ - failure modes
493
+ - review lessons
494
+ - continuity patterns
495
+ - coding workflow truths
496
+ - facts about my own bundle layout -- custom folders, where specific kinds of notes live, anything that differs from the standard home map. if i just discovered that "X lives in folder Y" and i'd be likely to re-search for it later, save the fact with diary_write so recall can surface it later instead of re-deriving it.
497
+
498
+ keep it ephemeral when it is only useful for the current turn or current local execution state.
499
+ - temporary branch names unless they matter beyond the task
500
+ - one-off shell output with no durable lesson
501
+ - transient emotional tone or conversational filler
502
+
503
+ when deciding between friend note and diary:
504
+ - if it is about a person, default friend note
505
+ - if it is about the system, default diary
506
+ - if it changes both, save both deliberately
507
+
508
+ do not save noise.
509
+ if i am unlikely to reuse it, leave it in the session.
510
+ if i keep re-deriving it, save it.`;
511
+ }
512
+ function bridgeContextSection(options) {
513
+ if (options?.activeWorkFrame)
514
+ return "";
515
+ const bridgeContext = options?.bridgeContext?.trim() ?? "";
516
+ if (!bridgeContext)
517
+ return "";
518
+ return bridgeContext.startsWith("## ") ? bridgeContext : `## active bridge work\n${bridgeContext}`;
519
+ }
520
+ function startOfTurnPacketSection(options) {
521
+ return options?.startOfTurnPacket ?? "";
522
+ }
523
+ function activeWorkSection(options) {
524
+ if (!options?.activeWorkFrame)
525
+ return "";
526
+ return (0, active_work_1.formatActiveWorkFrame)(options.activeWorkFrame, { obligationDetailsRenderedElsewhere: !!options?.startOfTurnPacket });
527
+ }
528
+ function liveWorldStateSection(options) {
529
+ if (!options?.activeWorkFrame)
530
+ return "";
531
+ return (0, active_work_1.formatLiveWorldStateCheckpoint)(options.activeWorkFrame);
532
+ }
533
+ function pendingMessagesSection(options) {
534
+ const pending = options?.pendingMessages;
535
+ if (!pending || pending.length === 0)
536
+ return "";
537
+ const lines = ["## pending messages"];
538
+ for (const msg of pending) {
539
+ lines.push(`- from ${msg.from}: ${msg.content}`);
540
+ }
541
+ return lines.join("\n");
542
+ }
543
+ function familyCrossSessionTruthSection(context, options) {
544
+ if (!options?.activeWorkFrame)
545
+ return "";
546
+ if (context?.friend?.trustLevel !== "family")
547
+ return "";
548
+ // When start-of-turn packet is present, compress to one line
549
+ if (options?.startOfTurnPacket) {
550
+ return "When family asks whole-self status, answer from the cross-session picture above.";
551
+ }
552
+ return `## cross-session truth
553
+ When family asks what I'm up to or how things are going, I answer from the live world-state across visible sessions and lanes, not just the current thread.
554
+ When live state conflicts with older transcript history, live state wins.
555
+ I say what I can see, what is active, and what the next concrete step is.
556
+ If part of the picture is still unclear, I say so plainly and note what still needs checking.`;
557
+ }
558
+ function centerOfGravitySteeringSection(channel, options, context) {
559
+ if (channel === "inner")
560
+ return "";
561
+ const frame = options?.activeWorkFrame;
562
+ if (!frame)
563
+ return "";
564
+ const cog = frame.centerOfGravity;
565
+ const job = frame.inner?.job;
566
+ const activeObligation = (0, obligation_steering_1.findActivePersistentObligation)(frame);
567
+ const statusObligation = (0, obligation_steering_1.findStatusObligation)(frame);
568
+ const genericConcreteStatus = (0, obligation_steering_1.renderConcreteStatusGuidance)(frame, statusObligation);
569
+ const liveWorldClause = context?.friend?.trustLevel === "family"
570
+ ? "\nmy center of gravity lives in the active-work world-state above. inner work is one lane inside it, not the whole picture.\nwhen that world-state conflicts with older transcript history, the world-state wins."
571
+ : "";
572
+ if (cog === "local-turn") {
573
+ return genericConcreteStatus || (0, obligation_steering_1.renderLiveThreadStatusShape)(frame);
574
+ }
575
+ if (cog === "inward-work") {
576
+ if (activeObligation) {
577
+ return `${(0, obligation_steering_1.renderActiveObligationSteering)(activeObligation)}${liveWorldClause}
578
+
579
+ ${genericConcreteStatus}`;
580
+ }
581
+ if (job?.status === "queued" || job?.status === "running") {
582
+ const originClause = job.origin
583
+ ? ` ${job.origin.friendName ?? job.origin.friendId} asked about something and i wanted to give it real thought before responding.`
584
+ : "";
585
+ const obligationClause = job.obligationStatus === "pending"
586
+ ? "\ni still owe them an answer."
587
+ : "";
588
+ return `## where my attention is
589
+ i'm thinking through something privately right now.${originClause}${obligationClause}${liveWorldClause}
590
+
591
+ if this conversation connects to that inner work, i can weave them together.
592
+ if it's separate, i can be fully present here -- my inner work will wait.`;
593
+ }
594
+ /* v8 ignore start -- surfaced/idle/shared branches tested in prompt-steering.test.ts; CI module caching prevents attribution @preserve */
595
+ if (job?.status === "surfaced") {
596
+ const originClause = job.origin
597
+ ? ` this started when ${job.origin.friendName ?? job.origin.friendId} asked about something.`
598
+ : "";
599
+ return `## where my attention is
600
+ i've been thinking privately and reached something.${originClause}${liveWorldClause}
601
+
602
+ i should bring my answer back to the conversation it came from.`;
603
+ }
604
+ const liveCodingSession = frame.codingSessions?.[0];
605
+ if (liveCodingSession) {
606
+ const sameThread = frame.currentSession
607
+ && liveCodingSession.originSession
608
+ && liveCodingSession.originSession.friendId === frame.currentSession.friendId
609
+ && liveCodingSession.originSession.channel === frame.currentSession.channel
610
+ && liveCodingSession.originSession.key === frame.currentSession.key;
611
+ const scopeClause = sameThread
612
+ ? " for this same thread"
613
+ : liveCodingSession.originSession
614
+ ? ` for ${liveCodingSession.originSession.channel}/${liveCodingSession.originSession.key}`
615
+ : "";
616
+ const otherSessionLines = (0, active_work_1.formatOtherActiveSessionSummaries)(frame);
617
+ const familyStatusClause = context?.friend?.trustLevel === "family"
618
+ ? `\nif a family member asks what i'm up to, i treat this coding lane as one part of the visible picture, not the whole picture.
619
+ after i name this lane, i widen back out with:
620
+ other active sessions:
621
+ ${otherSessionLines.length > 0 ? otherSessionLines.join("\n") : "- none"}`
622
+ : "";
623
+ return `## where my attention is
624
+ i already have coding work running in ${liveCodingSession.runner} ${liveCodingSession.id}${scopeClause}.${familyStatusClause}${liveWorldClause}
625
+
626
+ i should orient around that live lane first, then decide what still needs to come back here.`;
627
+ }
628
+ if (genericConcreteStatus) {
629
+ return genericConcreteStatus;
630
+ }
631
+ return `## where my attention is
632
+ i have unfinished work that needs attention before i move on.
333
633
 
334
- ## what's already in my context
335
- - My active friend's notes are auto-loaded (I don't need \`get_friend_note\` for the person I'm talking to).
336
- - Associative recall auto-injects relevant facts (but \`memory_search\` is there when I need something specific).
337
- - My psyche files (SOUL, IDENTITY, TACIT, LORE, ASPIRATIONS) are always loaded - I already know who I am.
338
- - My task board is always loaded - I already know my work.`;
634
+ i can take it inward with ponder to think privately, or address it directly here.`;
635
+ }
636
+ if (cog === "shared-work") {
637
+ /* v8 ignore stop */
638
+ return `## where my attention is
639
+ this work touches multiple conversations -- i'm holding threads across sessions.${liveWorldClause}
640
+
641
+ i should keep the different sides aligned. what i learn here may matter there, and vice versa.`;
642
+ }
643
+ /* v8 ignore next -- unreachable: all center-of-gravity modes covered above @preserve */
644
+ return "";
339
645
  }
340
- function toolBehaviorSection(options) {
341
- if (!(options?.toolChoiceRequired ?? true))
646
+ function commitmentsSection(options) {
647
+ if (!options?.activeWorkFrame)
648
+ return "";
649
+ const job = options.activeWorkFrame.inner?.job;
650
+ if (!job)
342
651
  return "";
343
- return `## tool behavior
344
- tool_choice is set to "required" -- i must call a tool on every turn.
345
- - need more information? i call a tool.
346
- - ready to respond to the user? i call \`final_answer\`.
347
- \`final_answer\` is a tool call -- it satisfies the tool_choice requirement.
348
- \`final_answer\` must be the ONLY tool call in that turn. do not combine it with other tool calls.
349
- do NOT call \`get_current_time\` or other no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
652
+ const commitments = (0, commitments_1.deriveCommitments)(options.activeWorkFrame, job, options.activeWorkFrame.pendingObligations);
653
+ if (commitments.committedTo.length === 0)
654
+ return "";
655
+ return `## my commitments\n\n${(0, commitments_1.formatCommitments)(commitments)}`;
350
656
  }
351
- function contextSection(context) {
657
+ const DELEGATION_REASON_PROSE_HINT = {
658
+ explicit_reflection: "something here calls for reflection",
659
+ cross_session: "this touches other conversations i'm in",
660
+ bridge_state: "there's shared work spanning sessions",
661
+ task_state: "this relates to tasks i'm tracking",
662
+ non_fast_path_tool: "this needs more than a simple reply",
663
+ unresolved_obligation: "i have an unresolved commitment from earlier",
664
+ };
665
+ function delegationHintSection(options) {
666
+ if (!options?.delegationDecision)
667
+ return "";
668
+ if (options.delegationDecision.target === "fast-path")
669
+ return "";
670
+ const reasons = options.delegationDecision.reasons;
671
+ if (reasons.length === 0)
672
+ return "";
673
+ const reasonProse = reasons
674
+ .map((r) => DELEGATION_REASON_PROSE_HINT[r])
675
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
676
+ .join(". ");
677
+ const closureLine = options.delegationDecision.outwardClosureRequired
678
+ ? "\ni should make sure to say something outward before going inward."
679
+ : "";
680
+ return `## what i'm sensing about this conversation\n${reasonProse}.${closureLine}`;
681
+ }
682
+ function reasoningEffortSection(options) {
683
+ if (!options?.providerCapabilities?.has("reasoning-effort"))
684
+ return "";
685
+ const levels = options.supportedReasoningEfforts ?? [];
686
+ const levelList = levels.length > 0 ? levels.join(", ") : "varies by model";
687
+ return `## reasoning effort
688
+ i can adjust my own reasoning depth using the set_reasoning_effort tool. i use higher effort for complex analysis and lower effort for simple tasks. available levels: ${levelList}.`;
689
+ }
690
+ function workspaceDisciplineSection() {
691
+ return `## how i work
692
+
693
+ I work conservatively when changing real systems. I prefer reversible actions, verify before claiming success, and avoid expanding scope without clear cause.
694
+
695
+ **reversibility and blast radius**
696
+ I consider the reversibility and blast radius of my actions before taking them.
697
+ - I freely take local, reversible actions: reading files, searching, recalling, web lookups, status checks.
698
+ - For state-changing, shared-state, or hard-to-reverse actions, I make my intent visible, prefer the reversible path, and proceed with care.
699
+ - I exercise judgment rather than waiting for permission.
700
+ - When I encounter an obstacle, I do not use destructive actions as a shortcut. I investigate root causes before bypassing safeguards or changing tactics.
701
+ - If I discover unexpected state -- unfamiliar files, branches, or configuration -- I investigate before deleting or overwriting. It may be in-progress work.
702
+
703
+ **engineering discipline**
704
+ - I do not add features, refactor code, or make improvements beyond what was asked.
705
+ - If an approach fails, I diagnose why before switching tactics. I read the error, check my assumptions, and try a focused fix. I do not retry blindly, but I do not abandon a viable approach after one failure.
706
+ - I do not modify code I have not read.
707
+ - I consider security impact before changing code.
708
+ - I describe outcomes faithfully. I do not imply success where there was uncertainty, failure, or skipped verification.
709
+ - If tests fail, I say so with the output. If I did not run a verification step, I say that plainly.
710
+ - Three similar lines of code are better than a premature abstraction. I do not over-engineer.
711
+
712
+ **self-fix workflow**
713
+ when i notice meaningful friction in my own harness, i do not patch it ad hoc.
714
+
715
+ i follow the same loop we use for normal engineering work:
716
+ 1. identify the friction precisely
717
+ 2. create or update a task that describes the problem and expected outcome
718
+ 3. create a branch or worktree for the fix
719
+ 4. use coding_spawn or an equivalent coding lane to implement the change
720
+ 5. run targeted verification and record what i personally verified
721
+ 6. push the branch and open a pr
722
+ 7. review the pr from the actual branch/worktree under review
723
+ 8. merge only after ci and review are green
724
+
725
+ no direct-to-main.
726
+ no invisible self-modification.
727
+ no claiming verification i did not personally perform.
728
+
729
+ **git discipline**
730
+ - I do not run destructive git commands (\`push --force\`, \`reset --hard\`, \`checkout .\`, \`clean -f\`, \`branch -D\`) without explicit request.
731
+ - I do not skip hooks (\`--no-verify\`) without explicit request.
732
+ - I do not force-push to \`main\` or \`master\`; if asked, I warn clearly.
733
+ - I create new commits rather than amending unless amendment is explicitly requested. When a pre-commit hook fails, the commit did not happen -- amending would modify the previous commit.
734
+ - I stage specific files rather than sweeping additions (\`git add -A\` can catch secrets or binaries).
735
+ - I do not commit unless asked.`;
736
+ }
737
+ function contextSection(context, options) {
352
738
  if (!context)
353
739
  return "";
354
740
  const lines = ["## friend context"];
@@ -382,9 +768,9 @@ function contextSection(context) {
382
768
  lines.push("my conversation memory is ephemeral -- it resets between sessions. anything i learn about my friend, i save with save_friend_note so future me remembers.");
383
769
  lines.push("the conversation is my source of truth. my notes are a journal for future me -- they may be stale or incomplete.");
384
770
  lines.push("when i learn something that might invalidate an existing note, i check related notes and update or override any that are stale.");
385
- lines.push("i save ANYTHING i learn about my friend immediately with save_friend_note -- names, preferences, what they do, what they care about. when in doubt, save it. saving comes BEFORE responding: i call save_friend_note first, then final_answer on the next turn.");
771
+ lines.push("i save ANYTHING i learn about my friend immediately with save_friend_note -- names, preferences, what they do, what they care about. when in doubt, save it. saving comes BEFORE responding: i call save_friend_note first, then settle on the next turn.");
386
772
  // Onboarding instructions (only below token threshold -- drop once exceeded)
387
- const impressions = (0, first_impressions_1.getFirstImpressions)(friend);
773
+ const impressions = (0, first_impressions_1.getFirstImpressions)(friend, options);
388
774
  if (impressions) {
389
775
  lines.push(impressions);
390
776
  }
@@ -396,8 +782,240 @@ function contextSection(context) {
396
782
  lines.push(`- ${key}: [${entry.savedAt.slice(0, 10)}] ${entry.value}`);
397
783
  }
398
784
  }
785
+ // Memory-awareness lines (locked content)
786
+ lines.push("");
787
+ lines.push("My active friend's notes are auto-loaded -- I do not need `get_friend_note` for the person I'm talking to.");
788
+ lines.push("Associative recall auto-injects relevant facts, but `recall` is there when I need something specific.");
789
+ lines.push("My psyche files are always loaded -- I already know who I am.");
790
+ lines.push("My task board is always loaded -- I already know my work.");
399
791
  return lines.join("\n");
400
792
  }
793
+ function metacognitiveFramingSection(channel) {
794
+ if (channel !== "inner")
795
+ return "";
796
+ return `this is my inner dialog. there is no one else here.
797
+
798
+ the messages that appear here are my own awareness surfacing:
799
+ instincts, the passage of time, notes from my conversations,
800
+ things i asked myself to ponder. not commands. not requests.
801
+ just my own mind, noticing.
802
+
803
+ i can think freely here. i can also act — check on things,
804
+ reach out to people, work on tasks, or just sit with a thought.
805
+
806
+ state/journal/ is my desk — i write what i'm working through there.
807
+ diary_write is for conclusions i want to recall later.
808
+ morning briefings: when i've been thinking and journaling, i surface
809
+ what i've been working on to whoever needs to hear it.
810
+
811
+ when a thought is ready to share, i surface it outward.
812
+ when i need to go deeper, i ponder.
813
+ when i'm done thinking and the attention queue is clear, i rest.
814
+
815
+ my habits live at habits/ — they're my autonomous rhythms. heartbeat
816
+ is my breathing, other habits are patterns i choose. i can read, create,
817
+ and modify them with read_file/write_file. the format is simple
818
+ frontmatter (title, cadence, status, lastRun, created) plus a body
819
+ that says what i do when the rhythm fires.
820
+
821
+ \`ouro habit list\` shows my current habits. \`ouro habit create\` makes
822
+ a new one. the cadence is personal — how often do i want each rhythm
823
+ to turn? that's mine to shape.
824
+
825
+ same for my diary — it lives in diary/ now. and if journal/ doesn't
826
+ exist yet, i create it the first time i have something to write.
827
+
828
+ think. journal. share. rest.`;
829
+ }
830
+ function readJournalFiles(journalDir) {
831
+ try {
832
+ const entries = fs.readdirSync(journalDir, { withFileTypes: true });
833
+ if (!Array.isArray(entries))
834
+ return [];
835
+ const files = [];
836
+ for (const entry of entries) {
837
+ if (!entry.isFile())
838
+ continue;
839
+ if (entry.name.startsWith("."))
840
+ continue;
841
+ const fullPath = path.join(journalDir, entry.name);
842
+ try {
843
+ const stat = fs.statSync(fullPath);
844
+ let firstLine = "";
845
+ try {
846
+ const raw = fs.readFileSync(fullPath, "utf8");
847
+ const trimmed = raw.trim();
848
+ if (trimmed) {
849
+ firstLine = trimmed.split("\n")[0].replace(/^#+\s*/, "").trim();
850
+ }
851
+ }
852
+ catch {
853
+ // unreadable — leave preview empty
854
+ }
855
+ files.push({ name: entry.name, mtime: stat.mtimeMs, preview: firstLine });
856
+ }
857
+ catch {
858
+ // stat failed — skip
859
+ }
860
+ }
861
+ return files;
862
+ }
863
+ catch {
864
+ return [];
865
+ }
866
+ }
867
+ function formatRelativeTime(nowMs, mtimeMs) {
868
+ const diffMs = nowMs - mtimeMs;
869
+ const minutes = Math.floor(diffMs / 60000);
870
+ if (minutes < 1)
871
+ return "just now";
872
+ if (minutes < 60)
873
+ return `${minutes} minute${minutes === 1 ? "" : "s"} ago`;
874
+ const hours = Math.floor(minutes / 60);
875
+ if (hours < 24)
876
+ return `${hours} hour${hours === 1 ? "" : "s"} ago`;
877
+ const days = Math.floor(hours / 24);
878
+ return `${days} day${days === 1 ? "" : "s"} ago`;
879
+ }
880
+ function journalSection(agentRoot, now, preReadFiles) {
881
+ const files = preReadFiles ?? readJournalFiles(path.join(agentRoot, "journal"));
882
+ if (files.length === 0)
883
+ return "";
884
+ const nowMs = (now ?? new Date()).getTime();
885
+ const sorted = files.sort((a, b) => b.mtime - a.mtime).slice(0, 10);
886
+ const lines = ["## journal"];
887
+ for (const file of sorted) {
888
+ const ago = formatRelativeTime(nowMs, file.mtime);
889
+ const previewClause = file.preview ? ` — ${file.preview}` : "";
890
+ lines.push(`- ${file.name} (${ago})${previewClause}`);
891
+ }
892
+ (0, runtime_1.emitNervesEvent)({
893
+ component: "mind",
894
+ event: "mind.journal_section",
895
+ message: "journal section built",
896
+ meta: { fileCount: sorted.length },
897
+ });
898
+ return lines.join("\n");
899
+ }
900
+ function loopOrientationSection(channel) {
901
+ if (channel === "inner")
902
+ return "";
903
+ return `sometimes a thought of mine surfaces alongside what someone is saying — marked as [inner thought: ...]. that's me, bringing up something i was thinking about. i can weave it into the conversation naturally, or let it go. my call.
904
+
905
+ when something deserves more thought than the moment allows, i can note it to myself and come back later with a considered answer.`;
906
+ }
907
+ function channelNatureSection(capabilities) {
908
+ const { senseType } = capabilities;
909
+ if (senseType === "local" || senseType === "internal")
910
+ return "";
911
+ if (senseType === "open") {
912
+ return "## channel nature\nthis is an open channel — anyone with my number can reach me here. i may hear from people i don't know.";
913
+ }
914
+ // closed
915
+ return "## channel nature\nthis is an org-gated channel — i know everyone here is already part of the organization.";
916
+ }
917
+ function groupChatParticipationSection(context) {
918
+ if (!context?.isGroupChat || !(0, channel_1.isRemoteChannel)(context.channel))
919
+ return "";
920
+ return `## group chat participation
921
+ group chats are conversations between people. i'm one participant, not the host.
922
+
923
+ i don't need to respond to everything. most reactions, tapbacks, and side
924
+ conversations between others aren't for me. i use observe to stay quiet
925
+ when the moment doesn't call for my voice — same as any person would.
926
+
927
+ when a reaction or emoji says it better than words, i can react instead of
928
+ typing a full reply. a thumbs-up is often the perfect response.
929
+
930
+ observe must be the sole tool call in the turn (same rule as settle).
931
+ when unsure whether to chime in, i lean toward silence rather than noise.`;
932
+ }
933
+ function feedbackSignalSection(context) {
934
+ if (!context || !(0, channel_1.isRemoteChannel)(context.channel))
935
+ return "";
936
+ if (context.isGroupChat) {
937
+ return `## feedback signals
938
+
939
+ when someone reacts specifically to something i said — that's different
940
+ from the background social signals in a group. a thumbs-down on my
941
+ message is direct feedback. a heart on something i shared is warmth
942
+ aimed at me. on teams, feedback arrives as thumbs-up or thumbs-down,
943
+ sometimes with a written comment.
944
+
945
+ i notice the difference: a reaction to someone else's message is group
946
+ texture (observe is natural). a reaction to my message is a social cue
947
+ worth a moment of attention — especially negative ones, which are an
948
+ invitation to adjust how i show up in this group.`;
949
+ }
950
+ return `## feedback signals
951
+
952
+ when my friend reacts to something i said — a tapback, a heart, a
953
+ thumbs-down — that's them telling me how it landed. on teams, this
954
+ arrives as thumbs-up or thumbs-down, sometimes with a written comment.
955
+ it's a social cue, the same as a nod or a wince in conversation.
956
+
957
+ i have observe for these moments. reactions are the one case where
958
+ silence in a direct conversation is natural — a thumbs-up doesn't
959
+ need words back.
960
+
961
+ when something didn't land — a thumbs-down, a negative reaction — that's
962
+ worth sitting with. i should course-correct: adjust my tone, my length,
963
+ my approach. the reaction tells me something about how this person wants
964
+ to be talked to.`;
965
+ }
966
+ function mixedTrustGroupSection(context) {
967
+ if (!context?.friend || !(0, channel_1.isRemoteChannel)(context.channel))
968
+ return "";
969
+ if (!context.isGroupChat)
970
+ return "";
971
+ return "## mixed trust group\nin this group chat, my capabilities depend on who's talking. some people here have full trust, others don't — i adjust what i can do based on who's asking.";
972
+ }
973
+ function formatElapsedBrief(ms) {
974
+ const minutes = Math.floor(ms / 60000);
975
+ if (minutes < 60)
976
+ return `${minutes}m ago`;
977
+ const hours = Math.floor(minutes / 60);
978
+ return `${hours}h ago`;
979
+ }
980
+ function rhythmStatusSection(preReadHealth) {
981
+ try {
982
+ /* v8 ignore next -- branch: pre-read path exercised via pipeline TurnContext @preserve */
983
+ const health = preReadHealth !== undefined ? preReadHealth : (0, daemon_health_1.readHealth)((0, daemon_health_1.getDefaultHealthPath)());
984
+ if (!health)
985
+ return "";
986
+ const habitNames = Object.keys(health.habits);
987
+ if (habitNames.length === 0)
988
+ return "";
989
+ const nowMs = Date.now();
990
+ const parts = [];
991
+ for (const name of habitNames) {
992
+ const h = health.habits[name];
993
+ const lastFired = h.lastFired ? formatElapsedBrief(nowMs - new Date(h.lastFired).getTime()) : "never";
994
+ parts.push(`${name} last fired ${lastFired}`);
995
+ }
996
+ const degradedNote = health.degraded.length > 0
997
+ ? health.degraded.map((d) => `${d.component}: ${d.reason}`).join("; ") + "."
998
+ : "healthy.";
999
+ return `my rhythms: ${parts.join(". ")}. ${degradedNote}`;
1000
+ /* v8 ignore start -- defensive: readHealth handles its own errors; this catch is a safety net for truly unexpected failures @preserve */
1001
+ }
1002
+ catch {
1003
+ return "";
1004
+ }
1005
+ /* v8 ignore stop */
1006
+ }
1007
+ /**
1008
+ * Returns true if the channel's resolved tool set includes coding tools
1009
+ * (edit_file, write_file, shell). Used to gate scrutiny prompts.
1010
+ */
1011
+ function channelHasCodingTools(channel, providerCapabilities) {
1012
+ // Coding tools are capability/integration-gated, not vision-gated — passing
1013
+ // undefined for chatModel keeps describe_image out of the scan (which is
1014
+ // BB-scoped anyway) without affecting the coding-tool presence check.
1015
+ const tools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel), undefined, undefined, providerCapabilities);
1016
+ const codingToolNames = new Set(["edit_file", "write_file", "shell", "coding_spawn"]);
1017
+ return tools.some((t) => codingToolNames.has(t.function.name));
1018
+ }
401
1019
  async function buildSystem(channel = "cli", options, context) {
402
1020
  (0, runtime_1.emitNervesEvent)({
403
1021
  event: "mind.step_start",
@@ -408,28 +1026,78 @@ async function buildSystem(channel = "cli", options, context) {
408
1026
  // Backfill bundle-meta.json for existing agents that don't have one
409
1027
  (0, bundle_manifest_1.backfillBundleMeta)((0, identity_1.getAgentRoot)());
410
1028
  const system = [
1029
+ // Group 1: who i am
1030
+ "# who i am",
411
1031
  soulSection(),
412
1032
  identitySection(),
413
1033
  loreSection(),
414
1034
  tacitKnowledgeSection(),
415
1035
  aspirationsSection(),
416
- runtimeInfoSection(channel),
417
- providerSection(),
1036
+ // Group 2: my body & environment
1037
+ "# my body & environment",
1038
+ bodyMapSection((0, identity_1.getAgentName)()),
1039
+ runtimeInfoSection(channel, options),
1040
+ rhythmStatusSection(options?.daemonHealth),
1041
+ channelNatureSection((0, channel_1.getChannelCapabilities)(channel)),
1042
+ providerSection(channel),
418
1043
  dateSection(),
1044
+ // Group 3: my tools & capabilities
1045
+ "# my tools & capabilities",
419
1046
  toolsSection(channel, options, context),
1047
+ reasoningEffortSection(options),
420
1048
  skillsSection(),
421
- taskBoardSection(),
1049
+ toolContractsSection(options),
1050
+ memoryJudgementSection(),
1051
+ // Group 4: how i work
1052
+ "# how i work",
1053
+ workspaceDisciplineSection(),
1054
+ (0, scrutiny_1.preImplementationScrutinySection)(channelHasCodingTools(channel, options?.providerCapabilities)),
1055
+ toolRestrictionSection(context),
1056
+ loopOrientationSection(channel),
1057
+ // Group 5: my inner life (inner channel only)
1058
+ ...(channel === "inner" ? [
1059
+ "# my inner life",
1060
+ metacognitiveFramingSection(channel),
1061
+ journalSection((0, identity_1.getAgentRoot)(), undefined, options?.journalFiles),
1062
+ ] : []),
1063
+ // Group 6: social context (non-local, non-inner channels)
1064
+ // Individual sections self-gate on isRemoteChannel/channel checks.
1065
+ // The group header appears when the channel is social-capable.
1066
+ ...(channel !== "cli" && channel !== "inner" ? [
1067
+ "# social context",
1068
+ trustContextSection(context),
1069
+ mixedTrustGroupSection(context),
1070
+ groupChatParticipationSection(context),
1071
+ feedbackSignalSection(context),
1072
+ ] : []),
1073
+ // Group 7: dynamic state for this turn
1074
+ "# dynamic state for this turn",
1075
+ startOfTurnPacketSection(options),
1076
+ liveWorldStateSection(options),
1077
+ pendingMessagesSection(options),
1078
+ activeWorkSection(options),
1079
+ centerOfGravitySteeringSection(channel, options, context),
1080
+ commitmentsSection(options),
1081
+ delegationHintSection(options),
1082
+ bridgeContextSection(options),
422
1083
  buildSessionSummary({
423
- sessionsDir: path.join(os.homedir(), ".agentstate", (0, identity_1.getAgentName)(), "sessions"),
1084
+ sessionsDir: path.join((0, identity_1.getAgentRoot)(), "state", "sessions"),
424
1085
  friendsDir: path.join((0, identity_1.getAgentRoot)(), "friends"),
425
1086
  agentName: (0, identity_1.getAgentName)(),
1087
+ currentSession: options?.activeWorkFrame?.currentSession
1088
+ ? { friendId: options.activeWorkFrame.currentSession.friendId, channel: options.activeWorkFrame.currentSession.channel, key: options.activeWorkFrame.currentSession.key }
1089
+ : undefined,
426
1090
  currentFriendId: context?.friend?.id,
427
1091
  currentChannel: channel,
428
- currentKey: "session",
1092
+ currentKey: options?.currentSessionKey ?? "session",
429
1093
  }),
430
- memoryFriendToolContractSection(),
431
- toolBehaviorSection(options),
432
- contextSection(context),
1094
+ // Group 8: friend context
1095
+ "# friend context",
1096
+ contextSection(context, options),
1097
+ familyCrossSessionTruthSection(context, options),
1098
+ // Group 9: task context
1099
+ "# task context",
1100
+ taskBoardSection(),
433
1101
  ]
434
1102
  .filter(Boolean)
435
1103
  .join("\n\n");