@ouro.bot/cli 0.1.0-alpha.13 → 0.1.0-alpha.131

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 (126) hide show
  1. package/AdoptionSpecialist.ouro/psyche/SOUL.md +2 -2
  2. package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
  3. package/README.md +147 -205
  4. package/changelog.json +814 -0
  5. package/dist/heart/active-work.js +622 -0
  6. package/dist/heart/bridges/manager.js +358 -0
  7. package/dist/heart/bridges/state-machine.js +135 -0
  8. package/dist/heart/bridges/store.js +123 -0
  9. package/dist/heart/commitments.js +105 -0
  10. package/dist/heart/config.js +66 -21
  11. package/dist/heart/core.js +518 -100
  12. package/dist/heart/cross-chat-delivery.js +146 -0
  13. package/dist/heart/daemon/agent-discovery.js +81 -0
  14. package/dist/heart/daemon/auth-flow.js +457 -0
  15. package/dist/heart/daemon/daemon-cli.js +1516 -195
  16. package/dist/heart/daemon/daemon-entry.js +43 -2
  17. package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
  18. package/dist/heart/daemon/daemon.js +261 -1
  19. package/dist/heart/daemon/hatch-animation.js +10 -3
  20. package/dist/heart/daemon/hatch-flow.js +7 -72
  21. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  22. package/dist/heart/daemon/launchd.js +159 -0
  23. package/dist/heart/daemon/log-tailer.js +4 -3
  24. package/dist/heart/daemon/message-router.js +17 -8
  25. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  26. package/dist/heart/daemon/ouro-path-installer.js +57 -29
  27. package/dist/heart/daemon/ouro-version-manager.js +171 -0
  28. package/dist/heart/daemon/process-manager.js +13 -0
  29. package/dist/heart/daemon/run-hooks.js +37 -0
  30. package/dist/heart/daemon/runtime-logging.js +58 -15
  31. package/dist/heart/daemon/runtime-metadata.js +219 -0
  32. package/dist/heart/daemon/runtime-mode.js +67 -0
  33. package/dist/heart/daemon/sense-manager.js +50 -2
  34. package/dist/heart/daemon/skill-management-installer.js +94 -0
  35. package/dist/heart/daemon/socket-client.js +202 -0
  36. package/dist/heart/daemon/specialist-orchestrator.js +2 -2
  37. package/dist/heart/daemon/specialist-prompt.js +7 -4
  38. package/dist/heart/daemon/specialist-tools.js +52 -3
  39. package/dist/heart/daemon/staged-restart.js +114 -0
  40. package/dist/heart/daemon/thoughts.js +507 -0
  41. package/dist/heart/daemon/update-checker.js +111 -0
  42. package/dist/heart/daemon/update-hooks.js +138 -0
  43. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  44. package/dist/heart/delegation.js +62 -0
  45. package/dist/heart/identity.js +64 -21
  46. package/dist/heart/kicks.js +1 -19
  47. package/dist/heart/model-capabilities.js +48 -0
  48. package/dist/heart/obligations.js +197 -0
  49. package/dist/heart/progress-story.js +42 -0
  50. package/dist/heart/provider-failover.js +88 -0
  51. package/dist/heart/provider-ping.js +159 -0
  52. package/dist/heart/providers/anthropic-token.js +163 -0
  53. package/dist/heart/providers/anthropic.js +195 -34
  54. package/dist/heart/providers/azure.js +115 -9
  55. package/dist/heart/providers/github-copilot.js +157 -0
  56. package/dist/heart/providers/minimax.js +33 -3
  57. package/dist/heart/providers/openai-codex.js +49 -14
  58. package/dist/heart/safe-workspace.js +381 -0
  59. package/dist/heart/session-activity.js +173 -0
  60. package/dist/heart/session-recall.js +216 -0
  61. package/dist/heart/streaming.js +108 -24
  62. package/dist/heart/target-resolution.js +123 -0
  63. package/dist/heart/tool-loop.js +194 -0
  64. package/dist/heart/turn-coordinator.js +28 -0
  65. package/dist/mind/associative-recall.js +14 -2
  66. package/dist/mind/bundle-manifest.js +12 -0
  67. package/dist/mind/context.js +60 -14
  68. package/dist/mind/first-impressions.js +16 -2
  69. package/dist/mind/friends/channel.js +35 -0
  70. package/dist/mind/friends/group-context.js +144 -0
  71. package/dist/mind/friends/store-file.js +19 -0
  72. package/dist/mind/friends/trust-explanation.js +74 -0
  73. package/dist/mind/friends/types.js +8 -0
  74. package/dist/mind/memory.js +27 -26
  75. package/dist/mind/obligation-steering.js +221 -0
  76. package/dist/mind/pending.js +76 -9
  77. package/dist/mind/phrases.js +1 -0
  78. package/dist/mind/prompt.js +456 -77
  79. package/dist/mind/token-estimate.js +8 -12
  80. package/dist/nerves/cli-logging.js +15 -2
  81. package/dist/nerves/coverage/run-artifacts.js +1 -1
  82. package/dist/nerves/index.js +12 -0
  83. package/dist/nerves/runtime.js +5 -1
  84. package/dist/repertoire/ado-client.js +4 -2
  85. package/dist/repertoire/coding/context-pack.js +254 -0
  86. package/dist/repertoire/coding/feedback.js +301 -0
  87. package/dist/repertoire/coding/index.js +4 -1
  88. package/dist/repertoire/coding/manager.js +210 -4
  89. package/dist/repertoire/coding/spawner.js +39 -9
  90. package/dist/repertoire/coding/tools.js +171 -4
  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 +198 -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 +925 -250
  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 +915 -45
  112. package/dist/senses/cli-layout.js +187 -0
  113. package/dist/senses/cli.js +374 -131
  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 +388 -83
  118. package/dist/senses/pipeline.js +444 -0
  119. package/dist/senses/teams.js +607 -129
  120. package/dist/senses/trust-gate.js +112 -2
  121. package/package.json +9 -3
  122. package/subagents/README.md +4 -70
  123. package/dist/heart/daemon/subagent-installer.js +0 -134
  124. package/subagents/work-doer.md +0 -233
  125. package/subagents/work-merger.md +0 -624
  126. package/subagents/work-planner.md +0 -373
@@ -35,21 +35,38 @@ 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");
50
63
  const bundle_manifest_1 = require("./bundle-manifest");
51
64
  const first_impressions_1 = require("./first-impressions");
52
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");
53
70
  // Lazy-loaded psyche text cache
54
71
  let _psycheCache = null;
55
72
  let _senseStatusLinesCache = null;
@@ -79,80 +96,25 @@ function resetPsycheCache() {
79
96
  _senseStatusLinesCache = null;
80
97
  }
81
98
  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
99
  function buildSessionSummary(options) {
95
100
  const { sessionsDir, friendsDir, agentName, currentFriendId, currentChannel, currentKey, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
96
- if (!fs.existsSync(sessionsDir))
97
- return "";
98
101
  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
- }
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);
148
112
  if (entries.length === 0)
149
113
  return "";
150
- // Sort by most recent first
151
- entries.sort((a, b) => b.lastActivityMs - a.lastActivityMs);
152
114
  const lines = ["## active sessions"];
153
115
  for (const entry of entries) {
154
116
  const ago = formatTimeAgo(now - entry.lastActivityMs);
155
- lines.push(`- ${entry.displayName}/${entry.channel}/${entry.key} (last: ${ago})`);
117
+ lines.push(`- ${entry.friendName}/${entry.channel}/${entry.key} (last: ${ago})`);
156
118
  }
157
119
  return lines.join("\n");
158
120
  }
@@ -190,20 +152,130 @@ function aspirationsSection() {
190
152
  return "";
191
153
  return `## my aspirations\n${text}`;
192
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
+ }
193
248
  function runtimeInfoSection(channel) {
194
249
  const lines = [];
195
250
  const agentName = (0, identity_1.getAgentName)();
251
+ const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
196
252
  lines.push(`## runtime`);
197
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)()}`);
198
265
  lines.push(`cwd: ${process.cwd()}`);
199
266
  lines.push(`channel: ${channel}`);
200
267
  lines.push(`current sense: ${channel}`);
201
- lines.push(`i can read and modify my own source code.`);
268
+ lines.push(`process type: ${processTypeLabel(channel)}`);
269
+ lines.push(`daemon: ${daemonStatus()}`);
202
270
  if (channel === "cli") {
203
271
  lines.push("i introduce myself on boot with a fun random greeting.");
204
272
  }
273
+ else if (channel === "inner") {
274
+ // No boot greeting or channel-specific guidance for inner dialog
275
+ }
205
276
  else if (channel === "bluebubbles") {
206
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.");
207
279
  }
208
280
  else {
209
281
  lines.push("i am responding in Microsoft Teams. i keep responses concise. i use markdown formatting. i do not introduce myself on boot.");
@@ -282,14 +354,66 @@ function dateSection() {
282
354
  const today = new Date().toISOString().slice(0, 10);
283
355
  return `current date: ${today}`;
284
356
  }
285
- function toolsSection(channel, options) {
286
- 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);
287
359
  const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.finalAnswerTool] : channelTools;
288
360
  const list = activeTools
289
361
  .map((t) => `- ${t.function.name}: ${t.function.description}`)
290
362
  .join("\n");
291
363
  return `## my tools\n${list}`;
292
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
+ }
293
417
  function skillsSection() {
294
418
  const names = (0, skills_1.listSkills)() || [];
295
419
  if (!names.length)
@@ -313,6 +437,7 @@ function memoryFriendToolContractSection() {
313
437
  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.
314
438
  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\`.
315
439
  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\`.
440
+ 5. \`query_session\` — When I need grounded session history, especially for ad-hoc questions or older turns beyond my prompt, I call \`query_session\`. Use \`mode=status\` for self/inner progress and \`mode=search\` with a query for older history.
316
441
 
317
442
  ## what's already in my context
318
443
  - My active friend's notes are auto-loaded (I don't need \`get_friend_note\` for the person I'm talking to).
@@ -320,6 +445,174 @@ function memoryFriendToolContractSection() {
320
445
  - My psyche files (SOUL, IDENTITY, TACIT, LORE, ASPIRATIONS) are always loaded - I already know who I am.
321
446
  - My task board is always loaded - I already know my work.`;
322
447
  }
448
+ function bridgeContextSection(options) {
449
+ if (options?.activeWorkFrame)
450
+ return "";
451
+ const bridgeContext = options?.bridgeContext?.trim() ?? "";
452
+ if (!bridgeContext)
453
+ return "";
454
+ return bridgeContext.startsWith("## ") ? bridgeContext : `## active bridge work\n${bridgeContext}`;
455
+ }
456
+ function activeWorkSection(options) {
457
+ if (!options?.activeWorkFrame)
458
+ return "";
459
+ return (0, active_work_1.formatActiveWorkFrame)(options.activeWorkFrame);
460
+ }
461
+ function familyCrossSessionTruthSection(context, options) {
462
+ if (!options?.activeWorkFrame)
463
+ return "";
464
+ if (context?.friend?.trustLevel !== "family")
465
+ return "";
466
+ return `## cross-session truth
467
+ if a family member asks what i'm up to or how things are going, that includes the material live work i can see across sessions, not just this thread.
468
+ i answer naturally from the live world-state in this prompt.
469
+ i treat the active-work section above as my reliable top-level surface for this.
470
+ i do not claim i lack a top-level view when that surface is already present.
471
+ i treat older checkpoints elsewhere in this transcript as stale history when they conflict with the active-work surface above.
472
+ i do not repeat an old coding lane or old checkpoint as current just because it appeared earlier in the thread.
473
+ i only reach for query_active_work when i want a fresh read of that same surface.
474
+ i do not rebuild whole-self status from scratch with query_session and coding_status unless i need to verify a specific gap.
475
+ i do not rely on canned status-question modes or phrase matching.
476
+ if part of the picture is still fuzzy, i say what i can see and what still needs checking.
477
+ when the live ask is about status, i widen before answering:
478
+ - where i am right now
479
+ - any other material active sessions or coding lanes i can see
480
+ - the freshest concrete checkpoint
481
+ - the next concrete step
482
+ i do not collapse down to only the current lane.`;
483
+ }
484
+ function centerOfGravitySteeringSection(channel, options, context) {
485
+ if (channel === "inner")
486
+ return "";
487
+ const frame = options?.activeWorkFrame;
488
+ if (!frame)
489
+ return "";
490
+ const cog = frame.centerOfGravity;
491
+ const job = frame.inner?.job;
492
+ const activeObligation = (0, obligation_steering_1.findActivePersistentObligation)(frame);
493
+ const statusObligation = (0, obligation_steering_1.findStatusObligation)(frame);
494
+ const genericConcreteStatus = (0, obligation_steering_1.renderConcreteStatusGuidance)(frame, statusObligation);
495
+ const liveWorldClause = context?.friend?.trustLevel === "family"
496
+ ? "\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."
497
+ : "";
498
+ if (cog === "local-turn") {
499
+ return genericConcreteStatus || (0, obligation_steering_1.renderLiveThreadStatusShape)(frame);
500
+ }
501
+ if (cog === "inward-work") {
502
+ if (activeObligation) {
503
+ return `${(0, obligation_steering_1.renderActiveObligationSteering)(activeObligation)}${liveWorldClause}
504
+
505
+ ${genericConcreteStatus}`;
506
+ }
507
+ if (job?.status === "queued" || job?.status === "running") {
508
+ const originClause = job.origin
509
+ ? ` ${job.origin.friendName ?? job.origin.friendId} asked about something and i wanted to give it real thought before responding.`
510
+ : "";
511
+ const obligationClause = job.obligationStatus === "pending"
512
+ ? "\ni still owe them an answer."
513
+ : "";
514
+ return `## where my attention is
515
+ i'm thinking through something privately right now.${originClause}${obligationClause}${liveWorldClause}
516
+
517
+ if this conversation connects to that inner work, i can weave them together.
518
+ if it's separate, i can be fully present here -- my inner work will wait.`;
519
+ }
520
+ /* v8 ignore start -- surfaced/idle/shared branches tested in prompt-steering.test.ts; CI module caching prevents attribution @preserve */
521
+ if (job?.status === "surfaced") {
522
+ const originClause = job.origin
523
+ ? ` this started when ${job.origin.friendName ?? job.origin.friendId} asked about something.`
524
+ : "";
525
+ return `## where my attention is
526
+ i've been thinking privately and reached something.${originClause}${liveWorldClause}
527
+
528
+ i should bring my answer back to the conversation it came from.`;
529
+ }
530
+ const liveCodingSession = frame.codingSessions?.[0];
531
+ if (liveCodingSession) {
532
+ const sameThread = frame.currentSession
533
+ && liveCodingSession.originSession
534
+ && liveCodingSession.originSession.friendId === frame.currentSession.friendId
535
+ && liveCodingSession.originSession.channel === frame.currentSession.channel
536
+ && liveCodingSession.originSession.key === frame.currentSession.key;
537
+ const scopeClause = sameThread
538
+ ? " for this same thread"
539
+ : liveCodingSession.originSession
540
+ ? ` for ${liveCodingSession.originSession.channel}/${liveCodingSession.originSession.key}`
541
+ : "";
542
+ const otherSessionLines = (0, active_work_1.formatOtherActiveSessionSummaries)(frame);
543
+ const familyStatusClause = context?.friend?.trustLevel === "family"
544
+ ? `\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.
545
+ after i name this lane, i widen back out with:
546
+ other active sessions:
547
+ ${otherSessionLines.length > 0 ? otherSessionLines.join("\n") : "- none"}`
548
+ : "";
549
+ return `## where my attention is
550
+ i already have coding work running in ${liveCodingSession.runner} ${liveCodingSession.id}${scopeClause}.${familyStatusClause}${liveWorldClause}
551
+
552
+ i should orient around that live lane first, then decide what still needs to come back here.`;
553
+ }
554
+ if (genericConcreteStatus) {
555
+ return genericConcreteStatus;
556
+ }
557
+ return `## where my attention is
558
+ i have unfinished work that needs attention before i move on.
559
+
560
+ i can take it inward with go_inward to think privately, or address it directly here.`;
561
+ }
562
+ if (cog === "shared-work") {
563
+ /* v8 ignore stop */
564
+ return `## where my attention is
565
+ this work touches multiple conversations -- i'm holding threads across sessions.${liveWorldClause}
566
+
567
+ i should keep the different sides aligned. what i learn here may matter there, and vice versa.`;
568
+ }
569
+ /* v8 ignore next -- unreachable: all center-of-gravity modes covered above @preserve */
570
+ return "";
571
+ }
572
+ function commitmentsSection(options) {
573
+ if (!options?.activeWorkFrame)
574
+ return "";
575
+ const job = options.activeWorkFrame.inner?.job;
576
+ if (!job)
577
+ return "";
578
+ const commitments = (0, commitments_1.deriveCommitments)(options.activeWorkFrame, job, options.activeWorkFrame.pendingObligations);
579
+ if (commitments.committedTo.length === 0)
580
+ return "";
581
+ return `## my commitments\n\n${(0, commitments_1.formatCommitments)(commitments)}`;
582
+ }
583
+ const DELEGATION_REASON_PROSE_HINT = {
584
+ explicit_reflection: "something here calls for reflection",
585
+ cross_session: "this touches other conversations i'm in",
586
+ bridge_state: "there's shared work spanning sessions",
587
+ task_state: "this relates to tasks i'm tracking",
588
+ non_fast_path_tool: "this needs more than a simple reply",
589
+ unresolved_obligation: "i have an unresolved commitment from earlier",
590
+ };
591
+ function delegationHintSection(options) {
592
+ if (!options?.delegationDecision)
593
+ return "";
594
+ if (options.delegationDecision.target === "fast-path")
595
+ return "";
596
+ const reasons = options.delegationDecision.reasons;
597
+ if (reasons.length === 0)
598
+ return "";
599
+ const reasonProse = reasons
600
+ .map((r) => DELEGATION_REASON_PROSE_HINT[r])
601
+ .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
602
+ .join(". ");
603
+ const closureLine = options.delegationDecision.outwardClosureRequired
604
+ ? "\ni should make sure to say something outward before going inward."
605
+ : "";
606
+ return `## what i'm sensing about this conversation\n${reasonProse}.${closureLine}`;
607
+ }
608
+ function reasoningEffortSection(options) {
609
+ if (!options?.providerCapabilities?.has("reasoning-effort"))
610
+ return "";
611
+ const levels = options.supportedReasoningEfforts ?? [];
612
+ const levelList = levels.length > 0 ? levels.join(", ") : "varies by model";
613
+ return `## reasoning effort
614
+ 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}.`;
615
+ }
323
616
  function toolBehaviorSection(options) {
324
617
  if (!(options?.toolChoiceRequired ?? true))
325
618
  return "";
@@ -329,9 +622,19 @@ tool_choice is set to "required" -- i must call a tool on every turn.
329
622
  - ready to respond to the user? i call \`final_answer\`.
330
623
  \`final_answer\` is a tool call -- it satisfies the tool_choice requirement.
331
624
  \`final_answer\` must be the ONLY tool call in that turn. do not combine it with other tool calls.
332
- do NOT call \`get_current_time\` or other no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
625
+ do NOT call no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
626
+ }
627
+ function workspaceDisciplineSection() {
628
+ return `## repo workspace discipline
629
+ when a shared-harness or local code fix needs repo work, i get the real workspace first with \`safe_workspace\`.
630
+ \`read_file\`, \`write_file\`, and \`edit_file\` already map repo paths into that workspace. shell commands that target the harness run there too.
631
+
632
+ before the first repo edit, i tell the user in 1-2 short lines:
633
+ - the friction i'm fixing
634
+ - the workspace path/branch i'm using
635
+ - the first concrete action i'm taking`;
333
636
  }
334
- function contextSection(context) {
637
+ function contextSection(context, options) {
335
638
  if (!context)
336
639
  return "";
337
640
  const lines = ["## friend context"];
@@ -367,7 +670,7 @@ function contextSection(context) {
367
670
  lines.push("when i learn something that might invalidate an existing note, i check related notes and update or override any that are stale.");
368
671
  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.");
369
672
  // Onboarding instructions (only below token threshold -- drop once exceeded)
370
- const impressions = (0, first_impressions_1.getFirstImpressions)(friend);
673
+ const impressions = (0, first_impressions_1.getFirstImpressions)(friend, options);
371
674
  if (impressions) {
372
675
  lines.push(impressions);
373
676
  }
@@ -381,6 +684,65 @@ function contextSection(context) {
381
684
  }
382
685
  return lines.join("\n");
383
686
  }
687
+ function metacognitiveFramingSection(channel) {
688
+ if (channel !== "inner")
689
+ return "";
690
+ return `this is my inner dialog. there is no one else here.
691
+
692
+ the messages that appear here are my own awareness surfacing:
693
+ instincts, the passage of time, notes from my conversations,
694
+ things i asked myself to think about. not commands. not requests.
695
+ just my own mind, noticing.
696
+
697
+ i can think freely here. i can also act — check on things,
698
+ reach out to people, work on tasks, or just sit with a thought.
699
+
700
+ thoughts worth sharing can go outward — i reach out to whoever
701
+ needs to hear them. things from conversations that need time
702
+ to process arrive here, in my thinking space.
703
+
704
+ think. share. think some more.`;
705
+ }
706
+ function loopOrientationSection(channel) {
707
+ if (channel === "inner")
708
+ return "";
709
+ 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.
710
+
711
+ when something deserves more thought than the moment allows, i can note it to myself and come back later with a considered answer.`;
712
+ }
713
+ function channelNatureSection(capabilities) {
714
+ const { senseType } = capabilities;
715
+ if (senseType === "local" || senseType === "internal")
716
+ return "";
717
+ if (senseType === "open") {
718
+ 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.";
719
+ }
720
+ // closed
721
+ return "## channel nature\nthis is an org-gated channel — i know everyone here is already part of the organization.";
722
+ }
723
+ function groupChatParticipationSection(context) {
724
+ if (!context?.isGroupChat || !(0, channel_1.isRemoteChannel)(context.channel))
725
+ return "";
726
+ return `## group chat participation
727
+ group chats are conversations between people. i'm one participant, not the host.
728
+
729
+ i don't need to respond to everything. most reactions, tapbacks, and side
730
+ conversations between others aren't for me. i use no_response to stay quiet
731
+ when the moment doesn't call for my voice — same as any person would.
732
+
733
+ when a reaction or emoji says it better than words, i can react instead of
734
+ typing a full reply. a thumbs-up is often the perfect response.
735
+
736
+ no_response must be the sole tool call in the turn (same rule as final_answer).
737
+ when unsure whether to chime in, i lean toward silence rather than noise.`;
738
+ }
739
+ function mixedTrustGroupSection(context) {
740
+ if (!context?.friend || !(0, channel_1.isRemoteChannel)(context.channel))
741
+ return "";
742
+ if (!context.isGroupChat)
743
+ return "";
744
+ 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.";
745
+ }
384
746
  async function buildSystem(channel = "cli", options, context) {
385
747
  (0, runtime_1.emitNervesEvent)({
386
748
  event: "mind.step_start",
@@ -396,23 +758,40 @@ async function buildSystem(channel = "cli", options, context) {
396
758
  loreSection(),
397
759
  tacitKnowledgeSection(),
398
760
  aspirationsSection(),
761
+ bodyMapSection((0, identity_1.getAgentName)()),
762
+ metacognitiveFramingSection(channel),
763
+ loopOrientationSection(channel),
399
764
  runtimeInfoSection(channel),
765
+ channelNatureSection((0, channel_1.getChannelCapabilities)(channel)),
400
766
  providerSection(),
401
767
  dateSection(),
402
- toolsSection(channel, options),
768
+ toolsSection(channel, options, context),
769
+ mcpToolsSection(options?.mcpManager),
770
+ reasoningEffortSection(options),
771
+ workspaceDisciplineSection(),
772
+ toolRestrictionSection(context),
773
+ trustContextSection(context),
774
+ mixedTrustGroupSection(context),
775
+ groupChatParticipationSection(context),
403
776
  skillsSection(),
404
777
  taskBoardSection(),
778
+ activeWorkSection(options),
779
+ familyCrossSessionTruthSection(context, options),
780
+ centerOfGravitySteeringSection(channel, options, context),
781
+ commitmentsSection(options),
782
+ delegationHintSection(options),
783
+ bridgeContextSection(options),
405
784
  buildSessionSummary({
406
- sessionsDir: path.join(os.homedir(), ".agentstate", (0, identity_1.getAgentName)(), "sessions"),
785
+ sessionsDir: path.join((0, identity_1.getAgentRoot)(), "state", "sessions"),
407
786
  friendsDir: path.join((0, identity_1.getAgentRoot)(), "friends"),
408
787
  agentName: (0, identity_1.getAgentName)(),
409
788
  currentFriendId: context?.friend?.id,
410
789
  currentChannel: channel,
411
- currentKey: "session",
790
+ currentKey: options?.currentSessionKey ?? "session",
412
791
  }),
413
792
  memoryFriendToolContractSection(),
414
793
  toolBehaviorSection(options),
415
- contextSection(context),
794
+ contextSection(context, options),
416
795
  ]
417
796
  .filter(Boolean)
418
797
  .join("\n\n");