@ouro.bot/cli 0.1.0-alpha.25 → 0.1.0-alpha.250

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