@ouro.bot/cli 0.1.0-alpha.1 → 0.1.0-alpha.100

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 (132) 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 +596 -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 +102 -23
  13. package/dist/heart/core.js +512 -94
  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 +1935 -185
  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 +218 -9
  21. package/dist/heart/daemon/hatch-animation.js +35 -0
  22. package/dist/heart/daemon/hatch-flow.js +10 -83
  23. package/dist/heart/daemon/hatch-specialist.js +6 -1
  24. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  25. package/dist/heart/daemon/launchd.js +159 -0
  26. package/dist/heart/daemon/log-tailer.js +147 -0
  27. package/dist/heart/daemon/message-router.js +17 -8
  28. package/dist/heart/daemon/os-cron.js +260 -0
  29. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  30. package/dist/heart/daemon/ouro-bot-wrapper.js +4 -3
  31. package/dist/heart/daemon/ouro-path-installer.js +260 -0
  32. package/dist/heart/daemon/ouro-uti.js +11 -2
  33. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  34. package/dist/heart/daemon/process-manager.js +32 -2
  35. package/dist/heart/daemon/run-hooks.js +37 -0
  36. package/dist/heart/daemon/runtime-logging.js +61 -14
  37. package/dist/heart/daemon/runtime-metadata.js +219 -0
  38. package/dist/heart/daemon/runtime-mode.js +67 -0
  39. package/dist/heart/daemon/sense-manager.js +307 -0
  40. package/dist/heart/daemon/skill-management-installer.js +94 -0
  41. package/dist/heart/daemon/socket-client.js +202 -0
  42. package/dist/heart/daemon/specialist-orchestrator.js +129 -0
  43. package/dist/heart/daemon/specialist-prompt.js +99 -0
  44. package/dist/heart/daemon/specialist-tools.js +283 -0
  45. package/dist/heart/daemon/staged-restart.js +114 -0
  46. package/dist/heart/daemon/task-scheduler.js +4 -1
  47. package/dist/heart/daemon/thoughts.js +507 -0
  48. package/dist/heart/daemon/update-checker.js +111 -0
  49. package/dist/heart/daemon/update-hooks.js +138 -0
  50. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  51. package/dist/heart/delegation.js +62 -0
  52. package/dist/heart/identity.js +153 -23
  53. package/dist/heart/kicks.js +1 -19
  54. package/dist/heart/model-capabilities.js +48 -0
  55. package/dist/heart/obligations.js +191 -0
  56. package/dist/heart/progress-story.js +42 -0
  57. package/dist/heart/providers/anthropic.js +77 -9
  58. package/dist/heart/providers/azure.js +86 -7
  59. package/dist/heart/providers/github-copilot.js +149 -0
  60. package/dist/heart/providers/minimax.js +4 -0
  61. package/dist/heart/providers/openai-codex.js +12 -3
  62. package/dist/heart/safe-workspace.js +381 -0
  63. package/dist/heart/sense-truth.js +61 -0
  64. package/dist/heart/session-activity.js +169 -0
  65. package/dist/heart/session-recall.js +116 -0
  66. package/dist/heart/streaming.js +103 -22
  67. package/dist/heart/target-resolution.js +123 -0
  68. package/dist/heart/turn-coordinator.js +28 -0
  69. package/dist/mind/associative-recall.js +37 -4
  70. package/dist/mind/bundle-manifest.js +70 -0
  71. package/dist/mind/context.js +141 -11
  72. package/dist/mind/first-impressions.js +16 -2
  73. package/dist/mind/friends/channel.js +43 -0
  74. package/dist/mind/friends/group-context.js +144 -0
  75. package/dist/mind/friends/store-file.js +19 -0
  76. package/dist/mind/friends/trust-explanation.js +74 -0
  77. package/dist/mind/friends/types.js +9 -1
  78. package/dist/mind/memory.js +89 -26
  79. package/dist/mind/obligation-steering.js +31 -0
  80. package/dist/mind/pending.js +160 -0
  81. package/dist/mind/phrases.js +1 -0
  82. package/dist/mind/prompt-refresh.js +20 -0
  83. package/dist/mind/prompt.js +499 -8
  84. package/dist/mind/token-estimate.js +8 -12
  85. package/dist/nerves/cli-logging.js +15 -2
  86. package/dist/nerves/coverage/file-completeness.js +14 -4
  87. package/dist/nerves/coverage/run-artifacts.js +1 -1
  88. package/dist/nerves/index.js +12 -0
  89. package/dist/repertoire/ado-client.js +4 -2
  90. package/dist/repertoire/coding/feedback.js +210 -0
  91. package/dist/repertoire/coding/index.js +4 -1
  92. package/dist/repertoire/coding/manager.js +69 -4
  93. package/dist/repertoire/coding/spawner.js +21 -3
  94. package/dist/repertoire/coding/tools.js +105 -2
  95. package/dist/repertoire/data/ado-endpoints.json +188 -0
  96. package/dist/repertoire/guardrails.js +290 -0
  97. package/dist/repertoire/mcp-client.js +254 -0
  98. package/dist/repertoire/mcp-manager.js +195 -0
  99. package/dist/repertoire/skills.js +3 -26
  100. package/dist/repertoire/tasks/board.js +12 -0
  101. package/dist/repertoire/tasks/index.js +23 -9
  102. package/dist/repertoire/tasks/transitions.js +1 -2
  103. package/dist/repertoire/tools-base.js +770 -213
  104. package/dist/repertoire/tools-bluebubbles.js +93 -0
  105. package/dist/repertoire/tools-teams.js +58 -25
  106. package/dist/repertoire/tools.js +106 -53
  107. package/dist/senses/bluebubbles-client.js +484 -0
  108. package/dist/senses/bluebubbles-entry.js +13 -0
  109. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  110. package/dist/senses/bluebubbles-media.js +339 -0
  111. package/dist/senses/bluebubbles-model.js +261 -0
  112. package/dist/senses/bluebubbles-mutation-log.js +116 -0
  113. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  114. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  115. package/dist/senses/bluebubbles.js +1181 -0
  116. package/dist/senses/cli-layout.js +187 -0
  117. package/dist/senses/cli.js +452 -99
  118. package/dist/senses/continuity.js +94 -0
  119. package/dist/senses/debug-activity.js +154 -0
  120. package/dist/senses/inner-dialog-worker.js +47 -18
  121. package/dist/senses/inner-dialog.js +387 -70
  122. package/dist/senses/pipeline.js +307 -0
  123. package/dist/senses/session-lock.js +119 -0
  124. package/dist/senses/teams.js +574 -129
  125. package/dist/senses/trust-gate.js +112 -2
  126. package/package.json +16 -4
  127. package/subagents/README.md +4 -68
  128. package/dist/heart/daemon/subagent-installer.js +0 -125
  129. package/dist/inner-worker-entry.js +0 -4
  130. package/subagents/work-doer.md +0 -233
  131. package/subagents/work-merger.md +0 -593
  132. package/subagents/work-planner.md +0 -373
@@ -34,21 +34,42 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.resetPsycheCache = resetPsycheCache;
37
+ exports.buildSessionSummary = buildSessionSummary;
38
+ exports.bodyMapSection = bodyMapSection;
39
+ exports.mcpToolsSection = mcpToolsSection;
37
40
  exports.runtimeInfoSection = runtimeInfoSection;
41
+ exports.toolRestrictionSection = toolRestrictionSection;
42
+ exports.centerOfGravitySteeringSection = centerOfGravitySteeringSection;
43
+ exports.commitmentsSection = commitmentsSection;
44
+ exports.delegationHintSection = delegationHintSection;
38
45
  exports.contextSection = contextSection;
46
+ exports.metacognitiveFramingSection = metacognitiveFramingSection;
47
+ exports.loopOrientationSection = loopOrientationSection;
48
+ exports.channelNatureSection = channelNatureSection;
49
+ exports.groupChatParticipationSection = groupChatParticipationSection;
50
+ exports.mixedTrustGroupSection = mixedTrustGroupSection;
39
51
  exports.buildSystem = buildSystem;
40
52
  const fs = __importStar(require("fs"));
41
53
  const path = __importStar(require("path"));
42
54
  const core_1 = require("../heart/core");
55
+ const ouro_version_manager_1 = require("../heart/daemon/ouro-version-manager");
43
56
  const tools_1 = require("../repertoire/tools");
44
57
  const skills_1 = require("../repertoire/skills");
45
58
  const identity_1 = require("../heart/identity");
59
+ const types_1 = require("./friends/types");
60
+ const trust_explanation_1 = require("./friends/trust-explanation");
46
61
  const channel_1 = require("./friends/channel");
47
62
  const runtime_1 = require("../nerves/runtime");
63
+ const bundle_manifest_1 = require("./bundle-manifest");
48
64
  const first_impressions_1 = require("./first-impressions");
49
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");
50
70
  // Lazy-loaded psyche text cache
51
71
  let _psycheCache = null;
72
+ let _senseStatusLinesCache = null;
52
73
  function loadPsycheFile(name) {
53
74
  try {
54
75
  const psycheDir = path.join((0, identity_1.getAgentRoot)(), "psyche");
@@ -72,6 +93,40 @@ function loadPsyche() {
72
93
  }
73
94
  function resetPsycheCache() {
74
95
  _psycheCache = null;
96
+ _senseStatusLinesCache = null;
97
+ }
98
+ const DEFAULT_ACTIVE_THRESHOLD_MS = 24 * 60 * 60 * 1000; // 24 hours
99
+ function buildSessionSummary(options) {
100
+ const { sessionsDir, friendsDir, agentName, currentFriendId, currentChannel, currentKey, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
101
+ const now = Date.now();
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);
112
+ if (entries.length === 0)
113
+ return "";
114
+ const lines = ["## active sessions"];
115
+ for (const entry of entries) {
116
+ const ago = formatTimeAgo(now - entry.lastActivityMs);
117
+ lines.push(`- ${entry.friendName}/${entry.channel}/${entry.key} (last: ${ago})`);
118
+ }
119
+ return lines.join("\n");
120
+ }
121
+ function formatTimeAgo(ms) {
122
+ const minutes = Math.floor(ms / 60000);
123
+ if (minutes < 60)
124
+ return `${minutes}m ago`;
125
+ const hours = Math.floor(minutes / 60);
126
+ if (hours < 24)
127
+ return `${hours}h ago`;
128
+ const days = Math.floor(hours / 24);
129
+ return `${days}d ago`;
75
130
  }
76
131
  function soulSection() {
77
132
  return loadPsyche().soul;
@@ -97,22 +152,201 @@ function aspirationsSection() {
97
152
  return "";
98
153
  return `## my aspirations\n${text}`;
99
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
+ }
100
248
  function runtimeInfoSection(channel) {
101
249
  const lines = [];
102
250
  const agentName = (0, identity_1.getAgentName)();
251
+ const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
103
252
  lines.push(`## runtime`);
104
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)()}`);
105
265
  lines.push(`cwd: ${process.cwd()}`);
106
266
  lines.push(`channel: ${channel}`);
107
- 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()}`);
108
270
  if (channel === "cli") {
109
271
  lines.push("i introduce myself on boot with a fun random greeting.");
110
272
  }
273
+ else if (channel === "inner") {
274
+ // No boot greeting or channel-specific guidance for inner dialog
275
+ }
276
+ else if (channel === "bluebubbles") {
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.");
279
+ }
111
280
  else {
112
281
  lines.push("i am responding in Microsoft Teams. i keep responses concise. i use markdown formatting. i do not introduce myself on boot.");
113
282
  }
283
+ lines.push("");
284
+ lines.push(...senseRuntimeGuidance(channel));
114
285
  return lines.join("\n");
115
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
+ }
116
350
  function providerSection() {
117
351
  return `## my provider\n${(0, core_1.getProviderDisplayLabel)()}`;
118
352
  }
@@ -120,14 +354,66 @@ function dateSection() {
120
354
  const today = new Date().toISOString().slice(0, 10);
121
355
  return `current date: ${today}`;
122
356
  }
123
- function toolsSection(channel, options) {
124
- 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);
125
359
  const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.finalAnswerTool] : channelTools;
126
360
  const list = activeTools
127
361
  .map((t) => `- ${t.function.name}: ${t.function.description}`)
128
362
  .join("\n");
129
363
  return `## my tools\n${list}`;
130
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
+ }
131
417
  function skillsSection() {
132
418
  const names = (0, skills_1.listSkills)() || [];
133
419
  if (!names.length)
@@ -158,6 +444,116 @@ function memoryFriendToolContractSection() {
158
444
  - My psyche files (SOUL, IDENTITY, TACIT, LORE, ASPIRATIONS) are always loaded - I already know who I am.
159
445
  - My task board is always loaded - I already know my work.`;
160
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
+ }
161
557
  function toolBehaviorSection(options) {
162
558
  if (!(options?.toolChoiceRequired ?? true))
163
559
  return "";
@@ -167,9 +563,19 @@ tool_choice is set to "required" -- i must call a tool on every turn.
167
563
  - ready to respond to the user? i call \`final_answer\`.
168
564
  \`final_answer\` is a tool call -- it satisfies the tool_choice requirement.
169
565
  \`final_answer\` must be the ONLY tool call in that turn. do not combine it with other tool calls.
170
- 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.`;
567
+ }
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`;
171
577
  }
172
- function contextSection(context) {
578
+ function contextSection(context, options) {
173
579
  if (!context)
174
580
  return "";
175
581
  const lines = ["## friend context"];
@@ -205,7 +611,7 @@ function contextSection(context) {
205
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.");
206
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.");
207
613
  // Onboarding instructions (only below token threshold -- drop once exceeded)
208
- const impressions = (0, first_impressions_1.getFirstImpressions)(friend);
614
+ const impressions = (0, first_impressions_1.getFirstImpressions)(friend, options);
209
615
  if (impressions) {
210
616
  lines.push(impressions);
211
617
  }
@@ -219,6 +625,65 @@ function contextSection(context) {
219
625
  }
220
626
  return lines.join("\n");
221
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
+ }
222
687
  async function buildSystem(channel = "cli", options, context) {
223
688
  (0, runtime_1.emitNervesEvent)({
224
689
  event: "mind.step_start",
@@ -226,21 +691,47 @@ async function buildSystem(channel = "cli", options, context) {
226
691
  message: "buildSystem started",
227
692
  meta: { channel, has_context: Boolean(context), tool_choice_required: Boolean(options?.toolChoiceRequired) },
228
693
  });
694
+ // Backfill bundle-meta.json for existing agents that don't have one
695
+ (0, bundle_manifest_1.backfillBundleMeta)((0, identity_1.getAgentRoot)());
229
696
  const system = [
230
697
  soulSection(),
231
698
  identitySection(),
232
699
  loreSection(),
233
700
  tacitKnowledgeSection(),
234
701
  aspirationsSection(),
702
+ bodyMapSection((0, identity_1.getAgentName)()),
703
+ metacognitiveFramingSection(channel),
704
+ loopOrientationSection(channel),
235
705
  runtimeInfoSection(channel),
706
+ channelNatureSection((0, channel_1.getChannelCapabilities)(channel)),
236
707
  providerSection(),
237
708
  dateSection(),
238
- 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),
239
717
  skillsSection(),
240
718
  taskBoardSection(),
719
+ activeWorkSection(options),
720
+ centerOfGravitySteeringSection(channel, options),
721
+ commitmentsSection(options),
722
+ delegationHintSection(options),
723
+ bridgeContextSection(options),
724
+ buildSessionSummary({
725
+ sessionsDir: path.join((0, identity_1.getAgentRoot)(), "state", "sessions"),
726
+ friendsDir: path.join((0, identity_1.getAgentRoot)(), "friends"),
727
+ agentName: (0, identity_1.getAgentName)(),
728
+ currentFriendId: context?.friend?.id,
729
+ currentChannel: channel,
730
+ currentKey: options?.currentSessionKey ?? "session",
731
+ }),
241
732
  memoryFriendToolContractSection(),
242
733
  toolBehaviorSection(options),
243
- contextSection(context),
734
+ contextSection(context, options),
244
735
  ]
245
736
  .filter(Boolean)
246
737
  .join("\n\n");
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.__internal = void 0;
4
3
  exports.estimateTokensForMessage = estimateTokensForMessage;
5
4
  exports.estimateTokensForMessages = estimateTokensForMessages;
6
5
  const runtime_1 = require("../nerves/runtime");
@@ -53,7 +52,7 @@ function countCharsInContent(content) {
53
52
  return c.text.length;
54
53
  if (typeof c.content === "string")
55
54
  return c.content.length;
56
- return safeStringify(content).length;
55
+ return safeStringify(c).length;
57
56
  }
58
57
  return 0;
59
58
  }
@@ -70,12 +69,13 @@ function countCharsInToolCalls(toolCalls) {
70
69
  if (typeof t.type === "string")
71
70
  total += t.type.length;
72
71
  if (t.function && typeof t.function === "object") {
73
- if (typeof t.function.name === "string")
74
- total += t.function.name.length;
75
- if (typeof t.function.arguments === "string")
76
- total += t.function.arguments.length;
77
- else if (t.function.arguments != null)
78
- total += safeStringify(t.function.arguments).length;
72
+ const fn = t.function;
73
+ if (typeof fn.name === "string")
74
+ total += fn.name.length;
75
+ if (typeof fn.arguments === "string")
76
+ total += fn.arguments.length;
77
+ else if (fn.arguments != null)
78
+ total += safeStringify(fn.arguments).length;
79
79
  }
80
80
  }
81
81
  return total;
@@ -113,7 +113,3 @@ function estimateTokensForMessages(msgs) {
113
113
  total += estimateTokensForMessage(msg);
114
114
  return total;
115
115
  }
116
- exports.__internal = {
117
- CHARS_PER_TOKEN,
118
- PER_MESSAGE_OVERHEAD_TOKENS,
119
- };