@ouro.bot/cli 0.1.0-alpha.28 → 0.1.0-alpha.281

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