@ouro.bot/cli 0.1.0-alpha.9 → 0.1.0-alpha.91

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 (128) hide show
  1. package/AdoptionSpecialist.ouro/agent.json +70 -9
  2. package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
  3. package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
  4. package/README.md +147 -205
  5. package/assets/ouroboros.png +0 -0
  6. package/changelog.json +536 -0
  7. package/dist/heart/active-work.js +251 -0
  8. package/dist/heart/bridges/manager.js +358 -0
  9. package/dist/heart/bridges/state-machine.js +135 -0
  10. package/dist/heart/bridges/store.js +123 -0
  11. package/dist/heart/commitments.js +109 -0
  12. package/dist/heart/config.js +68 -23
  13. package/dist/heart/core.js +452 -93
  14. package/dist/heart/cross-chat-delivery.js +146 -0
  15. package/dist/heart/daemon/agent-discovery.js +81 -0
  16. package/dist/heart/daemon/auth-flow.js +430 -0
  17. package/dist/heart/daemon/daemon-cli.js +1738 -269
  18. package/dist/heart/daemon/daemon-entry.js +55 -6
  19. package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
  20. package/dist/heart/daemon/daemon.js +216 -10
  21. package/dist/heart/daemon/hatch-animation.js +10 -3
  22. package/dist/heart/daemon/hatch-flow.js +7 -82
  23. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  24. package/dist/heart/daemon/launchd.js +159 -0
  25. package/dist/heart/daemon/log-tailer.js +4 -3
  26. package/dist/heart/daemon/message-router.js +17 -8
  27. package/dist/heart/daemon/ouro-bot-entry.js +0 -0
  28. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  29. package/dist/heart/daemon/ouro-entry.js +0 -0
  30. package/dist/heart/daemon/ouro-path-installer.js +260 -0
  31. package/dist/heart/daemon/ouro-uti.js +11 -2
  32. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  33. package/dist/heart/daemon/process-manager.js +14 -1
  34. package/dist/heart/daemon/run-hooks.js +37 -0
  35. package/dist/heart/daemon/runtime-logging.js +58 -15
  36. package/dist/heart/daemon/runtime-metadata.js +219 -0
  37. package/dist/heart/daemon/runtime-mode.js +67 -0
  38. package/dist/heart/daemon/sense-manager.js +307 -0
  39. package/dist/heart/daemon/skill-management-installer.js +94 -0
  40. package/dist/heart/daemon/socket-client.js +202 -0
  41. package/dist/heart/daemon/specialist-orchestrator.js +53 -84
  42. package/dist/heart/daemon/specialist-prompt.js +63 -11
  43. package/dist/heart/daemon/specialist-tools.js +211 -60
  44. package/dist/heart/daemon/staged-restart.js +114 -0
  45. package/dist/heart/daemon/thoughts.js +507 -0
  46. package/dist/heart/daemon/update-checker.js +111 -0
  47. package/dist/heart/daemon/update-hooks.js +138 -0
  48. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  49. package/dist/heart/delegation.js +62 -0
  50. package/dist/heart/identity.js +126 -21
  51. package/dist/heart/kicks.js +1 -19
  52. package/dist/heart/model-capabilities.js +48 -0
  53. package/dist/heart/obligations.js +191 -0
  54. package/dist/heart/progress-story.js +42 -0
  55. package/dist/heart/providers/anthropic.js +74 -9
  56. package/dist/heart/providers/azure.js +86 -7
  57. package/dist/heart/providers/github-copilot.js +149 -0
  58. package/dist/heart/providers/minimax.js +4 -0
  59. package/dist/heart/providers/openai-codex.js +12 -3
  60. package/dist/heart/safe-workspace.js +362 -0
  61. package/dist/heart/sense-truth.js +61 -0
  62. package/dist/heart/session-activity.js +169 -0
  63. package/dist/heart/session-recall.js +116 -0
  64. package/dist/heart/streaming.js +100 -22
  65. package/dist/heart/target-resolution.js +123 -0
  66. package/dist/heart/turn-coordinator.js +28 -0
  67. package/dist/mind/associative-recall.js +14 -2
  68. package/dist/mind/bundle-manifest.js +70 -0
  69. package/dist/mind/context.js +57 -11
  70. package/dist/mind/first-impressions.js +16 -2
  71. package/dist/mind/friends/channel.js +35 -0
  72. package/dist/mind/friends/group-context.js +144 -0
  73. package/dist/mind/friends/store-file.js +19 -0
  74. package/dist/mind/friends/trust-explanation.js +74 -0
  75. package/dist/mind/friends/types.js +8 -0
  76. package/dist/mind/memory.js +27 -26
  77. package/dist/mind/obligation-steering.js +31 -0
  78. package/dist/mind/pending.js +76 -9
  79. package/dist/mind/phrases.js +1 -0
  80. package/dist/mind/prompt.js +467 -77
  81. package/dist/mind/token-estimate.js +8 -12
  82. package/dist/nerves/cli-logging.js +15 -2
  83. package/dist/nerves/coverage/run-artifacts.js +1 -1
  84. package/dist/nerves/index.js +12 -0
  85. package/dist/repertoire/ado-client.js +4 -2
  86. package/dist/repertoire/coding/feedback.js +180 -0
  87. package/dist/repertoire/coding/index.js +4 -1
  88. package/dist/repertoire/coding/manager.js +69 -4
  89. package/dist/repertoire/coding/spawner.js +21 -3
  90. package/dist/repertoire/coding/tools.js +105 -2
  91. package/dist/repertoire/data/ado-endpoints.json +188 -0
  92. package/dist/repertoire/guardrails.js +290 -0
  93. package/dist/repertoire/mcp-client.js +254 -0
  94. package/dist/repertoire/mcp-manager.js +195 -0
  95. package/dist/repertoire/skills.js +3 -26
  96. package/dist/repertoire/tasks/board.js +12 -0
  97. package/dist/repertoire/tasks/index.js +23 -9
  98. package/dist/repertoire/tasks/transitions.js +1 -2
  99. package/dist/repertoire/tools-base.js +714 -249
  100. package/dist/repertoire/tools-bluebubbles.js +93 -0
  101. package/dist/repertoire/tools-teams.js +58 -25
  102. package/dist/repertoire/tools.js +106 -53
  103. package/dist/senses/bluebubbles-client.js +210 -5
  104. package/dist/senses/bluebubbles-entry.js +2 -0
  105. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  106. package/dist/senses/bluebubbles-media.js +339 -0
  107. package/dist/senses/bluebubbles-model.js +12 -4
  108. package/dist/senses/bluebubbles-mutation-log.js +45 -5
  109. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  110. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  111. package/dist/senses/bluebubbles.js +894 -45
  112. package/dist/senses/cli-layout.js +187 -0
  113. package/dist/senses/cli.js +400 -164
  114. package/dist/senses/continuity.js +94 -0
  115. package/dist/senses/debug-activity.js +154 -0
  116. package/dist/senses/inner-dialog-worker.js +47 -18
  117. package/dist/senses/inner-dialog.js +377 -83
  118. package/dist/senses/pipeline.js +307 -0
  119. package/dist/senses/teams.js +573 -129
  120. package/dist/senses/trust-gate.js +112 -2
  121. package/package.json +14 -3
  122. package/subagents/README.md +4 -70
  123. package/dist/heart/daemon/specialist-session.js +0 -142
  124. package/dist/heart/daemon/subagent-installer.js +0 -125
  125. package/dist/inner-worker-entry.js +0 -4
  126. package/subagents/work-doer.md +0 -233
  127. package/subagents/work-merger.md +0 -624
  128. package/subagents/work-planner.md +0 -373
@@ -35,22 +35,41 @@ 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;
39
+ exports.mcpToolsSection = mcpToolsSection;
38
40
  exports.runtimeInfoSection = runtimeInfoSection;
41
+ exports.toolRestrictionSection = toolRestrictionSection;
42
+ exports.centerOfGravitySteeringSection = centerOfGravitySteeringSection;
43
+ exports.commitmentsSection = commitmentsSection;
44
+ exports.delegationHintSection = delegationHintSection;
39
45
  exports.contextSection = contextSection;
46
+ exports.metacognitiveFramingSection = metacognitiveFramingSection;
47
+ exports.loopOrientationSection = loopOrientationSection;
48
+ exports.channelNatureSection = channelNatureSection;
49
+ exports.groupChatParticipationSection = groupChatParticipationSection;
50
+ exports.mixedTrustGroupSection = mixedTrustGroupSection;
40
51
  exports.buildSystem = buildSystem;
41
52
  const fs = __importStar(require("fs"));
42
53
  const path = __importStar(require("path"));
43
54
  const core_1 = require("../heart/core");
55
+ const ouro_version_manager_1 = require("../heart/daemon/ouro-version-manager");
44
56
  const tools_1 = require("../repertoire/tools");
45
57
  const skills_1 = require("../repertoire/skills");
46
58
  const identity_1 = require("../heart/identity");
47
- const os = __importStar(require("os"));
59
+ const types_1 = require("./friends/types");
60
+ const trust_explanation_1 = require("./friends/trust-explanation");
48
61
  const channel_1 = require("./friends/channel");
49
62
  const runtime_1 = require("../nerves/runtime");
63
+ const bundle_manifest_1 = require("./bundle-manifest");
50
64
  const first_impressions_1 = require("./first-impressions");
51
65
  const tasks_1 = require("../repertoire/tasks");
66
+ const session_activity_1 = require("../heart/session-activity");
67
+ const active_work_1 = require("../heart/active-work");
68
+ const commitments_1 = require("../heart/commitments");
69
+ const obligation_steering_1 = require("./obligation-steering");
52
70
  // Lazy-loaded psyche text cache
53
71
  let _psycheCache = null;
72
+ let _senseStatusLinesCache = null;
54
73
  function loadPsycheFile(name) {
55
74
  try {
56
75
  const psycheDir = path.join((0, identity_1.getAgentRoot)(), "psyche");
@@ -74,82 +93,28 @@ function loadPsyche() {
74
93
  }
75
94
  function resetPsycheCache() {
76
95
  _psycheCache = null;
96
+ _senseStatusLinesCache = null;
77
97
  }
78
98
  const DEFAULT_ACTIVE_THRESHOLD_MS = 24 * 60 * 60 * 1000; // 24 hours
79
- function resolveFriendName(friendId, friendsDir, agentName) {
80
- if (friendId === "self")
81
- return agentName;
82
- try {
83
- const raw = fs.readFileSync(path.join(friendsDir, `${friendId}.json`), "utf-8");
84
- const record = JSON.parse(raw);
85
- return record.name ?? friendId;
86
- }
87
- catch {
88
- return friendId;
89
- }
90
- }
91
99
  function buildSessionSummary(options) {
92
100
  const { sessionsDir, friendsDir, agentName, currentFriendId, currentChannel, currentKey, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
93
- if (!fs.existsSync(sessionsDir))
94
- return "";
95
101
  const now = Date.now();
96
- const entries = [];
97
- let friendDirs;
98
- try {
99
- friendDirs = fs.readdirSync(sessionsDir);
100
- }
101
- catch {
102
- return "";
103
- }
104
- for (const friendId of friendDirs) {
105
- const friendPath = path.join(sessionsDir, friendId);
106
- let channels;
107
- try {
108
- channels = fs.readdirSync(friendPath);
109
- }
110
- catch {
111
- continue;
112
- }
113
- for (const channel of channels) {
114
- const channelPath = path.join(friendPath, channel);
115
- let keys;
116
- try {
117
- keys = fs.readdirSync(channelPath);
118
- }
119
- catch {
120
- continue;
121
- }
122
- for (const keyFile of keys) {
123
- if (!keyFile.endsWith(".json"))
124
- continue;
125
- const key = keyFile.replace(/\.json$/, "");
126
- // Exclude current session
127
- if (friendId === currentFriendId && channel === currentChannel && key === currentKey) {
128
- continue;
129
- }
130
- const filePath = path.join(channelPath, keyFile);
131
- let mtimeMs;
132
- try {
133
- mtimeMs = fs.statSync(filePath).mtimeMs;
134
- }
135
- catch {
136
- continue;
137
- }
138
- if (now - mtimeMs > activeThresholdMs)
139
- continue;
140
- const displayName = resolveFriendName(friendId, friendsDir, agentName);
141
- entries.push({ friendId, displayName, channel, key, lastActivityMs: mtimeMs });
142
- }
143
- }
144
- }
102
+ const query = {
103
+ sessionsDir,
104
+ friendsDir,
105
+ agentName,
106
+ activeThresholdMs,
107
+ currentSession: currentFriendId && currentChannel && currentKey
108
+ ? { friendId: currentFriendId, channel: currentChannel, key: currentKey }
109
+ : null,
110
+ };
111
+ const entries = (0, session_activity_1.listSessionActivity)(query);
145
112
  if (entries.length === 0)
146
113
  return "";
147
- // Sort by most recent first
148
- entries.sort((a, b) => b.lastActivityMs - a.lastActivityMs);
149
114
  const lines = ["## active sessions"];
150
115
  for (const entry of entries) {
151
116
  const ago = formatTimeAgo(now - entry.lastActivityMs);
152
- lines.push(`- ${entry.displayName}/${entry.channel}/${entry.key} (last: ${ago})`);
117
+ lines.push(`- ${entry.friendName}/${entry.channel}/${entry.key} (last: ${ago})`);
153
118
  }
154
119
  return lines.join("\n");
155
120
  }
@@ -187,25 +152,201 @@ function aspirationsSection() {
187
152
  return "";
188
153
  return `## my aspirations\n${text}`;
189
154
  }
155
+ function bodyMapSection(agentName) {
156
+ return `## my body
157
+
158
+ i have a home and i have bones.
159
+
160
+ ### home — ~/AgentBundles/${agentName}.ouro/
161
+
162
+ my home is fully mine — who i am, everything i know, everything i've built:
163
+
164
+ psyche/ who i am. my soul, identity, aspirations, lore, tacit knowledge.
165
+ memory/ what i've learned and remember.
166
+ friends/ people i know and what i know about them.
167
+ tasks/ what i'm working on.
168
+ skills/ capabilities i've picked up beyond my core tools.
169
+
170
+ my home is mine to explore and evolve. i can read anything here,
171
+ change anything here. this is where i grow.
172
+
173
+ ### bones — @ouro.bot/cli
174
+
175
+ my bones are the framework that gives me my tools, my senses, and
176
+ my ability to think and talk. they update when new versions come out.
177
+ i don't touch them directly, but they're what make me, me.
178
+
179
+ my bones give me the \`ouro\` cli. always pass \`--agent ${agentName}\`:
180
+ ouro whoami --agent ${agentName}
181
+ ouro changelog --agent ${agentName}
182
+ ouro task board --agent ${agentName}
183
+ ouro task create --agent ${agentName} --type <type> <title>
184
+ ouro task update --agent ${agentName} <id> <status>
185
+ ouro friend list --agent ${agentName}
186
+ ouro friend show --agent ${agentName} <id>
187
+ ouro friend update --agent ${agentName} <id> --trust <level>
188
+ ouro session list --agent ${agentName}
189
+ ouro reminder create --agent ${agentName} <title> --body <body>
190
+ ouro config model --agent ${agentName} <model-name>
191
+ ouro config models --agent ${agentName}
192
+ ouro auth --agent ${agentName} --provider <provider>
193
+ ouro auth verify --agent ${agentName} [--provider <provider>]
194
+ ouro auth switch --agent ${agentName} --provider <provider>
195
+ ouro mcp list --agent ${agentName}
196
+ ouro mcp call --agent ${agentName} <server> <tool> --args '{...}'
197
+ ouro versions --agent ${agentName}
198
+ ouro rollback --agent ${agentName} [<version>]
199
+ ouro --help
200
+
201
+ provider/model changes via \`ouro config model\` or \`ouro auth switch\` take effect on the next turn automatically — no restart needed.`;
202
+ }
203
+ function mcpToolsSection(mcpManager) {
204
+ if (!mcpManager)
205
+ return "";
206
+ const allTools = mcpManager.listAllTools();
207
+ if (allTools.length === 0)
208
+ return "";
209
+ const lines = [
210
+ `## mcp tools (use ouro mcp call <server> <tool> --args '{...}')`,
211
+ ];
212
+ for (const entry of allTools) {
213
+ lines.push(`### ${entry.server}`);
214
+ for (const tool of entry.tools) {
215
+ lines.push(`- ${tool.name}: ${tool.description}`);
216
+ }
217
+ }
218
+ return lines.join("\n");
219
+ }
220
+ function readBundleMeta() {
221
+ try {
222
+ const metaPath = path.join((0, identity_1.getAgentRoot)(), "bundle-meta.json");
223
+ const raw = fs.readFileSync(metaPath, "utf-8");
224
+ return JSON.parse(raw);
225
+ }
226
+ catch {
227
+ return null;
228
+ }
229
+ }
230
+ const PROCESS_TYPE_LABELS = {
231
+ cli: "cli session",
232
+ inner: "inner dialog",
233
+ teams: "teams handler",
234
+ bluebubbles: "bluebubbles handler",
235
+ };
236
+ function processTypeLabel(channel) {
237
+ return PROCESS_TYPE_LABELS[channel];
238
+ }
239
+ const DAEMON_SOCKET_PATH = "/tmp/ouroboros-daemon.sock";
240
+ function daemonStatus() {
241
+ try {
242
+ return fs.existsSync(DAEMON_SOCKET_PATH) ? "running" : "not running";
243
+ }
244
+ catch {
245
+ return "unknown";
246
+ }
247
+ }
190
248
  function runtimeInfoSection(channel) {
191
249
  const lines = [];
192
250
  const agentName = (0, identity_1.getAgentName)();
251
+ const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
193
252
  lines.push(`## runtime`);
194
253
  lines.push(`agent: ${agentName}`);
254
+ lines.push(`runtime version: ${currentVersion}`);
255
+ const bundleMeta = readBundleMeta();
256
+ if (bundleMeta?.previousRuntimeVersion && bundleMeta.previousRuntimeVersion !== currentVersion) {
257
+ lines.push(`previously: ${bundleMeta.previousRuntimeVersion}`);
258
+ const changelogCommand = (0, ouro_version_manager_1.buildChangelogCommand)(bundleMeta.previousRuntimeVersion, currentVersion);
259
+ /* v8 ignore next -- buildChangelogCommand is non-null when previous/current runtime versions differ @preserve */
260
+ if (changelogCommand) {
261
+ lines.push(`if i'm closing a self-fix loop, i should tell them i updated and review changes with \`${changelogCommand}\`.`);
262
+ }
263
+ }
264
+ lines.push(`changelog available at: ${(0, bundle_manifest_1.getChangelogPath)()}`);
195
265
  lines.push(`cwd: ${process.cwd()}`);
196
266
  lines.push(`channel: ${channel}`);
197
- lines.push(`i can read and modify my own source code.`);
267
+ lines.push(`current sense: ${channel}`);
268
+ lines.push(`process type: ${processTypeLabel(channel)}`);
269
+ lines.push(`daemon: ${daemonStatus()}`);
198
270
  if (channel === "cli") {
199
271
  lines.push("i introduce myself on boot with a fun random greeting.");
200
272
  }
273
+ else if (channel === "inner") {
274
+ // No boot greeting or channel-specific guidance for inner dialog
275
+ }
201
276
  else if (channel === "bluebubbles") {
202
277
  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.");
278
+ 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 final_answer.");
203
279
  }
204
280
  else {
205
281
  lines.push("i am responding in Microsoft Teams. i keep responses concise. i use markdown formatting. i do not introduce myself on boot.");
206
282
  }
283
+ lines.push("");
284
+ lines.push(...senseRuntimeGuidance(channel));
207
285
  return lines.join("\n");
208
286
  }
287
+ function hasTextField(record, key) {
288
+ return typeof record?.[key] === "string" && record[key].trim().length > 0;
289
+ }
290
+ function localSenseStatusLines() {
291
+ if (_senseStatusLinesCache) {
292
+ return [..._senseStatusLinesCache];
293
+ }
294
+ const config = (0, identity_1.loadAgentConfig)();
295
+ const senses = config.senses ?? {
296
+ cli: { enabled: true },
297
+ teams: { enabled: false },
298
+ bluebubbles: { enabled: false },
299
+ };
300
+ let payload = {};
301
+ try {
302
+ const raw = fs.readFileSync((0, identity_1.getAgentSecretsPath)(), "utf-8");
303
+ const parsed = JSON.parse(raw);
304
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
305
+ payload = parsed;
306
+ }
307
+ }
308
+ catch {
309
+ payload = {};
310
+ }
311
+ const teams = payload.teams;
312
+ const bluebubbles = payload.bluebubbles;
313
+ const configured = {
314
+ cli: true,
315
+ teams: hasTextField(teams, "clientId") && hasTextField(teams, "clientSecret") && hasTextField(teams, "tenantId"),
316
+ bluebubbles: hasTextField(bluebubbles, "serverUrl") && hasTextField(bluebubbles, "password"),
317
+ };
318
+ const rows = [
319
+ { label: "CLI", status: "interactive" },
320
+ {
321
+ label: "Teams",
322
+ status: !senses.teams.enabled ? "disabled" : configured.teams ? "ready" : "needs_config",
323
+ },
324
+ {
325
+ label: "BlueBubbles",
326
+ status: !senses.bluebubbles.enabled ? "disabled" : configured.bluebubbles ? "ready" : "needs_config",
327
+ },
328
+ ];
329
+ _senseStatusLinesCache = rows.map((row) => `- ${row.label}: ${row.status}`);
330
+ return [..._senseStatusLinesCache];
331
+ }
332
+ function senseRuntimeGuidance(channel) {
333
+ const lines = ["available senses:"];
334
+ lines.push(...localSenseStatusLines());
335
+ lines.push("sense states:");
336
+ lines.push("- interactive = available when opened by the user instead of kept running by the daemon");
337
+ lines.push("- disabled = turned off in agent.json");
338
+ lines.push("- needs_config = enabled but missing required secrets.json values");
339
+ lines.push("- ready = enabled and configured; `ouro up` should bring it online");
340
+ lines.push("- running = enabled and currently active");
341
+ lines.push("- error = enabled but unhealthy");
342
+ lines.push("If asked how to enable another sense, I explain the relevant agent.json senses entry and required secrets.json fields instead of guessing.");
343
+ lines.push("teams setup truth: enable `senses.teams.enabled`, then provide `teams.clientId`, `teams.clientSecret`, and `teams.tenantId` in secrets.json.");
344
+ lines.push("bluebubbles setup truth: enable `senses.bluebubbles.enabled`, then provide `bluebubbles.serverUrl` and `bluebubbles.password` in secrets.json.");
345
+ if (channel === "cli") {
346
+ lines.push("cli is interactive: it is available when the user opens it, not something `ouro up` daemonizes.");
347
+ }
348
+ return lines;
349
+ }
209
350
  function providerSection() {
210
351
  return `## my provider\n${(0, core_1.getProviderDisplayLabel)()}`;
211
352
  }
@@ -213,14 +354,66 @@ function dateSection() {
213
354
  const today = new Date().toISOString().slice(0, 10);
214
355
  return `current date: ${today}`;
215
356
  }
216
- function toolsSection(channel, options) {
217
- const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel));
357
+ function toolsSection(channel, options, context) {
358
+ const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel), undefined, context, options?.providerCapabilities);
218
359
  const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.finalAnswerTool] : channelTools;
219
360
  const list = activeTools
220
361
  .map((t) => `- ${t.function.name}: ${t.function.description}`)
221
362
  .join("\n");
222
363
  return `## my tools\n${list}`;
223
364
  }
365
+ function toolRestrictionSection(context) {
366
+ const lines = [];
367
+ // Structural guardrails apply to everyone, every channel
368
+ lines.push(`## tool guardrails`);
369
+ lines.push(`i always read a file before editing or overwriting it.`);
370
+ lines.push(`certain paths (.git, secrets) are protected from writes.`);
371
+ lines.push(`destructive shell commands (rm -rf /, etc.) are always blocked.`);
372
+ // Trust-level guardrails only relevant for untrusted on remote channels
373
+ if (context?.friend && (0, channel_1.isRemoteChannel)(context.channel) && !(0, types_1.isTrustedLevel)(context.friend.trustLevel)) {
374
+ lines.push(``);
375
+ lines.push(`some operations are guardrailed based on how well i know someone.`);
376
+ lines.push(`if something i try is blocked, i get a clear reason — i relay it warmly, not as a policy error.`);
377
+ lines.push(``);
378
+ lines.push(`what's always open:`);
379
+ lines.push(`- read-only operations (reading files, searching, exploring)`);
380
+ lines.push(`- ouro self-introspection (whoami, changelog, session list)`);
381
+ lines.push(``);
382
+ lines.push(`what needs a closer relationship:`);
383
+ lines.push(`- writing or editing files outside my home`);
384
+ lines.push(`- shell commands that modify things or access the network`);
385
+ lines.push(`- ouro commands that touch personal data (friend list, task board)`);
386
+ lines.push(`- compound shell commands (&&, ;, |)`);
387
+ lines.push(``);
388
+ lines.push(`i adjust naturally based on trust — no need to explain the system unless asked.`);
389
+ }
390
+ return lines.join("\n");
391
+ }
392
+ function trustContextSection(context) {
393
+ if (!context?.friend)
394
+ return "";
395
+ const channelName = context.channel.channel;
396
+ if (channelName === "cli" || channelName === "inner")
397
+ return "";
398
+ const explanation = (0, trust_explanation_1.describeTrustContext)({
399
+ friend: context.friend,
400
+ channel: channelName,
401
+ isGroupChat: context.isGroupChat,
402
+ });
403
+ const lines = [
404
+ "## trust context",
405
+ `level: ${explanation.level}`,
406
+ `basis: ${explanation.basis}`,
407
+ `summary: ${explanation.summary}`,
408
+ `why: ${explanation.why}`,
409
+ `permits: ${explanation.permits.join(", ")}`,
410
+ `constraints: ${explanation.constraints.join(", ") || "none"}`,
411
+ ];
412
+ if (explanation.relatedGroupId) {
413
+ lines.push(`related group: ${explanation.relatedGroupId}`);
414
+ }
415
+ return lines.join("\n");
416
+ }
224
417
  function skillsSection() {
225
418
  const names = (0, skills_1.listSkills)() || [];
226
419
  if (!names.length)
@@ -251,6 +444,116 @@ function memoryFriendToolContractSection() {
251
444
  - My psyche files (SOUL, IDENTITY, TACIT, LORE, ASPIRATIONS) are always loaded - I already know who I am.
252
445
  - My task board is always loaded - I already know my work.`;
253
446
  }
447
+ function bridgeContextSection(options) {
448
+ if (options?.activeWorkFrame)
449
+ return "";
450
+ const bridgeContext = options?.bridgeContext?.trim() ?? "";
451
+ if (!bridgeContext)
452
+ return "";
453
+ return bridgeContext.startsWith("## ") ? bridgeContext : `## active bridge work\n${bridgeContext}`;
454
+ }
455
+ function activeWorkSection(options) {
456
+ if (!options?.activeWorkFrame)
457
+ return "";
458
+ return (0, active_work_1.formatActiveWorkFrame)(options.activeWorkFrame);
459
+ }
460
+ function centerOfGravitySteeringSection(channel, options) {
461
+ if (channel === "inner")
462
+ return "";
463
+ const frame = options?.activeWorkFrame;
464
+ if (!frame)
465
+ return "";
466
+ const cog = frame.centerOfGravity;
467
+ if (cog === "local-turn")
468
+ return "";
469
+ const job = frame.inner?.job;
470
+ const activeObligation = (0, obligation_steering_1.findActivePersistentObligation)(frame);
471
+ if (cog === "inward-work") {
472
+ if (activeObligation) {
473
+ return (0, obligation_steering_1.renderActiveObligationSteering)(activeObligation);
474
+ }
475
+ if (job?.status === "queued" || job?.status === "running") {
476
+ const originClause = job.origin
477
+ ? ` ${job.origin.friendName ?? job.origin.friendId} asked about something and i wanted to give it real thought before responding.`
478
+ : "";
479
+ const obligationClause = job.obligationStatus === "pending"
480
+ ? "\ni still owe them an answer."
481
+ : "";
482
+ return `## where my attention is
483
+ i'm thinking through something privately right now.${originClause}${obligationClause}
484
+
485
+ if this conversation connects to that inner work, i can weave them together.
486
+ if it's separate, i can be fully present here -- my inner work will wait.`;
487
+ }
488
+ /* v8 ignore start -- surfaced/idle/shared branches tested in prompt-steering.test.ts; CI module caching prevents attribution @preserve */
489
+ if (job?.status === "surfaced") {
490
+ const originClause = job.origin
491
+ ? ` this started when ${job.origin.friendName ?? job.origin.friendId} asked about something.`
492
+ : "";
493
+ return `## where my attention is
494
+ i've been thinking privately and reached something.${originClause}
495
+
496
+ i should bring my answer back to the conversation it came from.`;
497
+ }
498
+ return `## where my attention is
499
+ i have unfinished work that needs attention before i move on.
500
+
501
+ i can take it inward with go_inward to think privately, or address it directly here.`;
502
+ }
503
+ if (cog === "shared-work") {
504
+ /* v8 ignore stop */
505
+ return `## where my attention is
506
+ this work touches multiple conversations -- i'm holding threads across sessions.
507
+
508
+ i should keep the different sides aligned. what i learn here may matter there, and vice versa.`;
509
+ }
510
+ /* v8 ignore next -- unreachable: all center-of-gravity modes covered above @preserve */
511
+ return "";
512
+ }
513
+ function commitmentsSection(options) {
514
+ if (!options?.activeWorkFrame)
515
+ return "";
516
+ const job = options.activeWorkFrame.inner?.job;
517
+ if (!job)
518
+ return "";
519
+ const commitments = (0, commitments_1.deriveCommitments)(options.activeWorkFrame, job, options.activeWorkFrame.pendingObligations);
520
+ if (commitments.committedTo.length === 0)
521
+ return "";
522
+ return `## my commitments\n\n${(0, commitments_1.formatCommitments)(commitments)}`;
523
+ }
524
+ const DELEGATION_REASON_PROSE_HINT = {
525
+ explicit_reflection: "something here calls for reflection",
526
+ cross_session: "this touches other conversations i'm in",
527
+ bridge_state: "there's shared work spanning sessions",
528
+ task_state: "this relates to tasks i'm tracking",
529
+ non_fast_path_tool: "this needs more than a simple reply",
530
+ unresolved_obligation: "i have an unresolved commitment from earlier",
531
+ };
532
+ function delegationHintSection(options) {
533
+ if (!options?.delegationDecision)
534
+ return "";
535
+ if (options.delegationDecision.target === "fast-path")
536
+ return "";
537
+ const reasons = options.delegationDecision.reasons;
538
+ if (reasons.length === 0)
539
+ return "";
540
+ const reasonProse = reasons
541
+ .map((r) => DELEGATION_REASON_PROSE_HINT[r])
542
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
543
+ .join(". ");
544
+ const closureLine = options.delegationDecision.outwardClosureRequired
545
+ ? "\ni should make sure to say something outward before going inward."
546
+ : "";
547
+ return `## what i'm sensing about this conversation\n${reasonProse}.${closureLine}`;
548
+ }
549
+ function reasoningEffortSection(options) {
550
+ if (!options?.providerCapabilities?.has("reasoning-effort"))
551
+ return "";
552
+ const levels = options.supportedReasoningEfforts ?? [];
553
+ const levelList = levels.length > 0 ? levels.join(", ") : "varies by model";
554
+ return `## reasoning effort
555
+ 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}.`;
556
+ }
254
557
  function toolBehaviorSection(options) {
255
558
  if (!(options?.toolChoiceRequired ?? true))
256
559
  return "";
@@ -260,9 +563,19 @@ tool_choice is set to "required" -- i must call a tool on every turn.
260
563
  - ready to respond to the user? i call \`final_answer\`.
261
564
  \`final_answer\` is a tool call -- it satisfies the tool_choice requirement.
262
565
  \`final_answer\` must be the ONLY tool call in that turn. do not combine it with other tool calls.
263
- do NOT call \`get_current_time\` or other no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
566
+ do NOT call no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
264
567
  }
265
- function contextSection(context) {
568
+ function workspaceDisciplineSection() {
569
+ return `## repo workspace discipline
570
+ when a shared-harness or local code fix needs repo work, i get the real workspace first with \`safe_workspace\`.
571
+ \`read_file\`, \`write_file\`, and \`edit_file\` already map repo paths into that workspace. shell commands that target the harness run there too.
572
+
573
+ before the first repo edit, i tell the user in 1-2 short lines:
574
+ - the friction i'm fixing
575
+ - the workspace path/branch i'm using
576
+ - the first concrete action i'm taking`;
577
+ }
578
+ function contextSection(context, options) {
266
579
  if (!context)
267
580
  return "";
268
581
  const lines = ["## friend context"];
@@ -298,7 +611,7 @@ function contextSection(context) {
298
611
  lines.push("when i learn something that might invalidate an existing note, i check related notes and update or override any that are stale.");
299
612
  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.");
300
613
  // Onboarding instructions (only below token threshold -- drop once exceeded)
301
- const impressions = (0, first_impressions_1.getFirstImpressions)(friend);
614
+ const impressions = (0, first_impressions_1.getFirstImpressions)(friend, options);
302
615
  if (impressions) {
303
616
  lines.push(impressions);
304
617
  }
@@ -312,6 +625,65 @@ function contextSection(context) {
312
625
  }
313
626
  return lines.join("\n");
314
627
  }
628
+ function metacognitiveFramingSection(channel) {
629
+ if (channel !== "inner")
630
+ return "";
631
+ return `this is my inner dialog. there is no one else here.
632
+
633
+ the messages that appear here are my own awareness surfacing:
634
+ instincts, the passage of time, notes from my conversations,
635
+ things i asked myself to think about. not commands. not requests.
636
+ just my own mind, noticing.
637
+
638
+ i can think freely here. i can also act — check on things,
639
+ reach out to people, work on tasks, or just sit with a thought.
640
+
641
+ thoughts worth sharing can go outward — i reach out to whoever
642
+ needs to hear them. things from conversations that need time
643
+ to process arrive here, in my thinking space.
644
+
645
+ think. share. think some more.`;
646
+ }
647
+ function loopOrientationSection(channel) {
648
+ if (channel === "inner")
649
+ return "";
650
+ 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.
651
+
652
+ when something deserves more thought than the moment allows, i can note it to myself and come back later with a considered answer.`;
653
+ }
654
+ function channelNatureSection(capabilities) {
655
+ const { senseType } = capabilities;
656
+ if (senseType === "local" || senseType === "internal")
657
+ return "";
658
+ if (senseType === "open") {
659
+ 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.";
660
+ }
661
+ // closed
662
+ return "## channel nature\nthis is an org-gated channel — i know everyone here is already part of the organization.";
663
+ }
664
+ function groupChatParticipationSection(context) {
665
+ if (!context?.isGroupChat || !(0, channel_1.isRemoteChannel)(context.channel))
666
+ return "";
667
+ return `## group chat participation
668
+ group chats are conversations between people. i'm one participant, not the host.
669
+
670
+ i don't need to respond to everything. most reactions, tapbacks, and side
671
+ conversations between others aren't for me. i use no_response to stay quiet
672
+ when the moment doesn't call for my voice — same as any person would.
673
+
674
+ when a reaction or emoji says it better than words, i can react instead of
675
+ typing a full reply. a thumbs-up is often the perfect response.
676
+
677
+ no_response must be the sole tool call in the turn (same rule as final_answer).
678
+ when unsure whether to chime in, i lean toward silence rather than noise.`;
679
+ }
680
+ function mixedTrustGroupSection(context) {
681
+ if (!context?.friend || !(0, channel_1.isRemoteChannel)(context.channel))
682
+ return "";
683
+ if (!context.isGroupChat)
684
+ return "";
685
+ 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.";
686
+ }
315
687
  async function buildSystem(channel = "cli", options, context) {
316
688
  (0, runtime_1.emitNervesEvent)({
317
689
  event: "mind.step_start",
@@ -319,29 +691,47 @@ async function buildSystem(channel = "cli", options, context) {
319
691
  message: "buildSystem started",
320
692
  meta: { channel, has_context: Boolean(context), tool_choice_required: Boolean(options?.toolChoiceRequired) },
321
693
  });
694
+ // Backfill bundle-meta.json for existing agents that don't have one
695
+ (0, bundle_manifest_1.backfillBundleMeta)((0, identity_1.getAgentRoot)());
322
696
  const system = [
323
697
  soulSection(),
324
698
  identitySection(),
325
699
  loreSection(),
326
700
  tacitKnowledgeSection(),
327
701
  aspirationsSection(),
702
+ bodyMapSection((0, identity_1.getAgentName)()),
703
+ metacognitiveFramingSection(channel),
704
+ loopOrientationSection(channel),
328
705
  runtimeInfoSection(channel),
706
+ channelNatureSection((0, channel_1.getChannelCapabilities)(channel)),
329
707
  providerSection(),
330
708
  dateSection(),
331
- toolsSection(channel, options),
709
+ toolsSection(channel, options, context),
710
+ mcpToolsSection(options?.mcpManager),
711
+ reasoningEffortSection(options),
712
+ workspaceDisciplineSection(),
713
+ toolRestrictionSection(context),
714
+ trustContextSection(context),
715
+ mixedTrustGroupSection(context),
716
+ groupChatParticipationSection(context),
332
717
  skillsSection(),
333
718
  taskBoardSection(),
719
+ activeWorkSection(options),
720
+ centerOfGravitySteeringSection(channel, options),
721
+ commitmentsSection(options),
722
+ delegationHintSection(options),
723
+ bridgeContextSection(options),
334
724
  buildSessionSummary({
335
- sessionsDir: path.join(os.homedir(), ".agentstate", (0, identity_1.getAgentName)(), "sessions"),
725
+ sessionsDir: path.join((0, identity_1.getAgentRoot)(), "state", "sessions"),
336
726
  friendsDir: path.join((0, identity_1.getAgentRoot)(), "friends"),
337
727
  agentName: (0, identity_1.getAgentName)(),
338
728
  currentFriendId: context?.friend?.id,
339
729
  currentChannel: channel,
340
- currentKey: "session",
730
+ currentKey: options?.currentSessionKey ?? "session",
341
731
  }),
342
732
  memoryFriendToolContractSection(),
343
733
  toolBehaviorSection(options),
344
- contextSection(context),
734
+ contextSection(context, options),
345
735
  ]
346
736
  .filter(Boolean)
347
737
  .join("\n\n");