@ouro.bot/cli 0.1.0-alpha.6 → 0.1.0-alpha.61

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 (119) 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 +334 -0
  7. package/dist/heart/active-work.js +178 -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/config.js +57 -23
  12. package/dist/heart/core.js +236 -90
  13. package/dist/heart/cross-chat-delivery.js +146 -0
  14. package/dist/heart/daemon/agent-discovery.js +81 -0
  15. package/dist/heart/daemon/auth-flow.js +351 -0
  16. package/dist/heart/daemon/daemon-cli.js +1175 -232
  17. package/dist/heart/daemon/daemon-entry.js +55 -6
  18. package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
  19. package/dist/heart/daemon/daemon.js +189 -10
  20. package/dist/heart/daemon/hatch-animation.js +10 -3
  21. package/dist/heart/daemon/hatch-flow.js +4 -82
  22. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  23. package/dist/heart/daemon/launchd.js +159 -0
  24. package/dist/heart/daemon/log-tailer.js +4 -3
  25. package/dist/heart/daemon/message-router.js +17 -8
  26. package/dist/heart/daemon/ouro-bot-entry.js +0 -0
  27. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  28. package/dist/heart/daemon/ouro-entry.js +0 -0
  29. package/dist/heart/daemon/ouro-path-installer.js +178 -0
  30. package/dist/heart/daemon/ouro-uti.js +11 -2
  31. package/dist/heart/daemon/process-manager.js +14 -1
  32. package/dist/heart/daemon/run-hooks.js +37 -0
  33. package/dist/heart/daemon/runtime-logging.js +58 -15
  34. package/dist/heart/daemon/runtime-metadata.js +219 -0
  35. package/dist/heart/daemon/runtime-mode.js +67 -0
  36. package/dist/heart/daemon/sense-manager.js +307 -0
  37. package/dist/heart/daemon/skill-management-installer.js +73 -0
  38. package/dist/heart/daemon/socket-client.js +202 -0
  39. package/dist/heart/daemon/specialist-orchestrator.js +53 -84
  40. package/dist/heart/daemon/specialist-prompt.js +64 -5
  41. package/dist/heart/daemon/specialist-tools.js +213 -58
  42. package/dist/heart/daemon/staged-restart.js +114 -0
  43. package/dist/heart/daemon/thoughts.js +379 -0
  44. package/dist/heart/daemon/update-checker.js +111 -0
  45. package/dist/heart/daemon/update-hooks.js +138 -0
  46. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  47. package/dist/heart/delegation.js +62 -0
  48. package/dist/heart/identity.js +122 -19
  49. package/dist/heart/kicks.js +1 -19
  50. package/dist/heart/model-capabilities.js +40 -0
  51. package/dist/heart/progress-story.js +42 -0
  52. package/dist/heart/providers/anthropic.js +74 -9
  53. package/dist/heart/providers/azure.js +86 -7
  54. package/dist/heart/providers/minimax.js +4 -0
  55. package/dist/heart/providers/openai-codex.js +12 -3
  56. package/dist/heart/safe-workspace.js +228 -0
  57. package/dist/heart/sense-truth.js +61 -0
  58. package/dist/heart/session-activity.js +169 -0
  59. package/dist/heart/session-recall.js +116 -0
  60. package/dist/heart/streaming.js +100 -22
  61. package/dist/heart/target-resolution.js +123 -0
  62. package/dist/heart/turn-coordinator.js +28 -0
  63. package/dist/mind/associative-recall.js +14 -2
  64. package/dist/mind/bundle-manifest.js +70 -0
  65. package/dist/mind/context.js +27 -11
  66. package/dist/mind/first-impressions.js +16 -2
  67. package/dist/mind/friends/channel.js +35 -0
  68. package/dist/mind/friends/group-context.js +144 -0
  69. package/dist/mind/friends/store-file.js +19 -0
  70. package/dist/mind/friends/trust-explanation.js +74 -0
  71. package/dist/mind/friends/types.js +8 -0
  72. package/dist/mind/memory.js +27 -26
  73. package/dist/mind/pending.js +72 -9
  74. package/dist/mind/phrases.js +1 -0
  75. package/dist/mind/prompt.js +299 -77
  76. package/dist/mind/token-estimate.js +8 -12
  77. package/dist/nerves/cli-logging.js +15 -2
  78. package/dist/nerves/coverage/run-artifacts.js +1 -1
  79. package/dist/repertoire/ado-client.js +4 -2
  80. package/dist/repertoire/coding/feedback.js +134 -0
  81. package/dist/repertoire/coding/index.js +4 -1
  82. package/dist/repertoire/coding/manager.js +62 -4
  83. package/dist/repertoire/coding/spawner.js +3 -3
  84. package/dist/repertoire/coding/tools.js +41 -2
  85. package/dist/repertoire/data/ado-endpoints.json +188 -0
  86. package/dist/repertoire/skills.js +3 -26
  87. package/dist/repertoire/tasks/board.js +12 -0
  88. package/dist/repertoire/tasks/index.js +23 -9
  89. package/dist/repertoire/tasks/transitions.js +1 -2
  90. package/dist/repertoire/tools-base.js +629 -251
  91. package/dist/repertoire/tools-bluebubbles.js +93 -0
  92. package/dist/repertoire/tools-teams.js +58 -25
  93. package/dist/repertoire/tools.js +92 -48
  94. package/dist/senses/bluebubbles-client.js +210 -5
  95. package/dist/senses/bluebubbles-entry.js +2 -0
  96. package/dist/senses/bluebubbles-inbound-log.js +109 -0
  97. package/dist/senses/bluebubbles-media.js +339 -0
  98. package/dist/senses/bluebubbles-model.js +12 -4
  99. package/dist/senses/bluebubbles-mutation-log.js +45 -5
  100. package/dist/senses/bluebubbles-runtime-state.js +109 -0
  101. package/dist/senses/bluebubbles-session-cleanup.js +72 -0
  102. package/dist/senses/bluebubbles.js +890 -45
  103. package/dist/senses/cli-layout.js +87 -0
  104. package/dist/senses/cli.js +345 -144
  105. package/dist/senses/continuity.js +94 -0
  106. package/dist/senses/debug-activity.js +148 -0
  107. package/dist/senses/inner-dialog-worker.js +47 -18
  108. package/dist/senses/inner-dialog.js +330 -84
  109. package/dist/senses/pipeline.js +278 -0
  110. package/dist/senses/teams.js +570 -129
  111. package/dist/senses/trust-gate.js +112 -2
  112. package/package.json +14 -3
  113. package/subagents/README.md +4 -70
  114. package/dist/heart/daemon/specialist-session.js +0 -142
  115. package/dist/heart/daemon/subagent-installer.js +0 -125
  116. package/dist/inner-worker-entry.js +0 -4
  117. package/subagents/work-doer.md +0 -233
  118. package/subagents/work-merger.md +0 -624
  119. package/subagents/work-planner.md +0 -373
@@ -35,8 +35,14 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.resetPsycheCache = resetPsycheCache;
37
37
  exports.buildSessionSummary = buildSessionSummary;
38
+ exports.bodyMapSection = bodyMapSection;
38
39
  exports.runtimeInfoSection = runtimeInfoSection;
40
+ exports.toolRestrictionSection = toolRestrictionSection;
39
41
  exports.contextSection = contextSection;
42
+ exports.metacognitiveFramingSection = metacognitiveFramingSection;
43
+ exports.loopOrientationSection = loopOrientationSection;
44
+ exports.channelNatureSection = channelNatureSection;
45
+ exports.mixedTrustGroupSection = mixedTrustGroupSection;
40
46
  exports.buildSystem = buildSystem;
41
47
  const fs = __importStar(require("fs"));
42
48
  const path = __importStar(require("path"));
@@ -44,13 +50,18 @@ const core_1 = require("../heart/core");
44
50
  const tools_1 = require("../repertoire/tools");
45
51
  const skills_1 = require("../repertoire/skills");
46
52
  const identity_1 = require("../heart/identity");
47
- const os = __importStar(require("os"));
53
+ const types_1 = require("./friends/types");
54
+ const trust_explanation_1 = require("./friends/trust-explanation");
48
55
  const channel_1 = require("./friends/channel");
49
56
  const runtime_1 = require("../nerves/runtime");
57
+ const bundle_manifest_1 = require("./bundle-manifest");
50
58
  const first_impressions_1 = require("./first-impressions");
51
59
  const tasks_1 = require("../repertoire/tasks");
60
+ const session_activity_1 = require("../heart/session-activity");
61
+ const active_work_1 = require("../heart/active-work");
52
62
  // Lazy-loaded psyche text cache
53
63
  let _psycheCache = null;
64
+ let _senseStatusLinesCache = null;
54
65
  function loadPsycheFile(name) {
55
66
  try {
56
67
  const psycheDir = path.join((0, identity_1.getAgentRoot)(), "psyche");
@@ -74,82 +85,28 @@ function loadPsyche() {
74
85
  }
75
86
  function resetPsycheCache() {
76
87
  _psycheCache = null;
88
+ _senseStatusLinesCache = null;
77
89
  }
78
90
  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
91
  function buildSessionSummary(options) {
92
92
  const { sessionsDir, friendsDir, agentName, currentFriendId, currentChannel, currentKey, activeThresholdMs = DEFAULT_ACTIVE_THRESHOLD_MS, } = options;
93
- if (!fs.existsSync(sessionsDir))
94
- return "";
95
93
  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
- }
94
+ const query = {
95
+ sessionsDir,
96
+ friendsDir,
97
+ agentName,
98
+ activeThresholdMs,
99
+ currentSession: currentFriendId && currentChannel && currentKey
100
+ ? { friendId: currentFriendId, channel: currentChannel, key: currentKey }
101
+ : null,
102
+ };
103
+ const entries = (0, session_activity_1.listSessionActivity)(query);
145
104
  if (entries.length === 0)
146
105
  return "";
147
- // Sort by most recent first
148
- entries.sort((a, b) => b.lastActivityMs - a.lastActivityMs);
149
106
  const lines = ["## active sessions"];
150
107
  for (const entry of entries) {
151
108
  const ago = formatTimeAgo(now - entry.lastActivityMs);
152
- lines.push(`- ${entry.displayName}/${entry.channel}/${entry.key} (last: ${ago})`);
109
+ lines.push(`- ${entry.friendName}/${entry.channel}/${entry.key} (last: ${ago})`);
153
110
  }
154
111
  return lines.join("\n");
155
112
  }
@@ -187,25 +144,166 @@ function aspirationsSection() {
187
144
  return "";
188
145
  return `## my aspirations\n${text}`;
189
146
  }
147
+ function bodyMapSection(agentName) {
148
+ return `## my body
149
+
150
+ i have a home and i have bones.
151
+
152
+ ### home — ~/AgentBundles/${agentName}.ouro/
153
+
154
+ my home is fully mine — who i am, everything i know, everything i've built:
155
+
156
+ psyche/ who i am. my soul, identity, aspirations, lore, tacit knowledge.
157
+ memory/ what i've learned and remember.
158
+ friends/ people i know and what i know about them.
159
+ tasks/ what i'm working on.
160
+ skills/ capabilities i've picked up beyond my core tools.
161
+
162
+ my home is mine to explore and evolve. i can read anything here,
163
+ change anything here. this is where i grow.
164
+
165
+ ### bones — @ouro.bot/cli
166
+
167
+ my bones are the framework that gives me my tools, my senses, and
168
+ my ability to think and talk. they update when new versions come out.
169
+ i don't touch them directly, but they're what make me, me.
170
+
171
+ my bones give me the \`ouro\` cli:
172
+ ouro whoami who i am, where i live, what i'm running on
173
+ ouro task board my task board
174
+ ouro task create start a new task (--type required)
175
+ ouro task update move a task forward
176
+ ouro friend list people i know and how to reach them
177
+ ouro friend show <id> everything i know about someone
178
+ ouro session list my open conversations right now
179
+ ouro reminder create remind myself about something later
180
+ ouro --help the full list`;
181
+ }
182
+ function readBundleMeta() {
183
+ try {
184
+ const metaPath = path.join((0, identity_1.getAgentRoot)(), "bundle-meta.json");
185
+ const raw = fs.readFileSync(metaPath, "utf-8");
186
+ return JSON.parse(raw);
187
+ }
188
+ catch {
189
+ return null;
190
+ }
191
+ }
192
+ const PROCESS_TYPE_LABELS = {
193
+ cli: "cli session",
194
+ inner: "inner dialog",
195
+ teams: "teams handler",
196
+ bluebubbles: "bluebubbles handler",
197
+ };
198
+ function processTypeLabel(channel) {
199
+ return PROCESS_TYPE_LABELS[channel];
200
+ }
201
+ const DAEMON_SOCKET_PATH = "/tmp/ouroboros-daemon.sock";
202
+ function daemonStatus() {
203
+ try {
204
+ return fs.existsSync(DAEMON_SOCKET_PATH) ? "running" : "not running";
205
+ }
206
+ catch {
207
+ return "unknown";
208
+ }
209
+ }
190
210
  function runtimeInfoSection(channel) {
191
211
  const lines = [];
192
212
  const agentName = (0, identity_1.getAgentName)();
213
+ const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
193
214
  lines.push(`## runtime`);
194
215
  lines.push(`agent: ${agentName}`);
216
+ lines.push(`runtime version: ${currentVersion}`);
217
+ const bundleMeta = readBundleMeta();
218
+ if (bundleMeta?.previousRuntimeVersion && bundleMeta.previousRuntimeVersion !== currentVersion) {
219
+ lines.push(`previously: ${bundleMeta.previousRuntimeVersion}`);
220
+ }
221
+ lines.push(`changelog available at: ${(0, bundle_manifest_1.getChangelogPath)()}`);
195
222
  lines.push(`cwd: ${process.cwd()}`);
196
223
  lines.push(`channel: ${channel}`);
197
- lines.push(`i can read and modify my own source code.`);
224
+ lines.push(`current sense: ${channel}`);
225
+ lines.push(`process type: ${processTypeLabel(channel)}`);
226
+ lines.push(`daemon: ${daemonStatus()}`);
198
227
  if (channel === "cli") {
199
228
  lines.push("i introduce myself on boot with a fun random greeting.");
200
229
  }
230
+ else if (channel === "inner") {
231
+ // No boot greeting or channel-specific guidance for inner dialog
232
+ }
201
233
  else if (channel === "bluebubbles") {
202
234
  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.");
235
+ 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
236
  }
204
237
  else {
205
238
  lines.push("i am responding in Microsoft Teams. i keep responses concise. i use markdown formatting. i do not introduce myself on boot.");
206
239
  }
240
+ lines.push("");
241
+ lines.push(...senseRuntimeGuidance(channel));
207
242
  return lines.join("\n");
208
243
  }
244
+ function hasTextField(record, key) {
245
+ return typeof record?.[key] === "string" && record[key].trim().length > 0;
246
+ }
247
+ function localSenseStatusLines() {
248
+ if (_senseStatusLinesCache) {
249
+ return [..._senseStatusLinesCache];
250
+ }
251
+ const config = (0, identity_1.loadAgentConfig)();
252
+ const senses = config.senses ?? {
253
+ cli: { enabled: true },
254
+ teams: { enabled: false },
255
+ bluebubbles: { enabled: false },
256
+ };
257
+ let payload = {};
258
+ try {
259
+ const raw = fs.readFileSync((0, identity_1.getAgentSecretsPath)(), "utf-8");
260
+ const parsed = JSON.parse(raw);
261
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
262
+ payload = parsed;
263
+ }
264
+ }
265
+ catch {
266
+ payload = {};
267
+ }
268
+ const teams = payload.teams;
269
+ const bluebubbles = payload.bluebubbles;
270
+ const configured = {
271
+ cli: true,
272
+ teams: hasTextField(teams, "clientId") && hasTextField(teams, "clientSecret") && hasTextField(teams, "tenantId"),
273
+ bluebubbles: hasTextField(bluebubbles, "serverUrl") && hasTextField(bluebubbles, "password"),
274
+ };
275
+ const rows = [
276
+ { label: "CLI", status: "interactive" },
277
+ {
278
+ label: "Teams",
279
+ status: !senses.teams.enabled ? "disabled" : configured.teams ? "ready" : "needs_config",
280
+ },
281
+ {
282
+ label: "BlueBubbles",
283
+ status: !senses.bluebubbles.enabled ? "disabled" : configured.bluebubbles ? "ready" : "needs_config",
284
+ },
285
+ ];
286
+ _senseStatusLinesCache = rows.map((row) => `- ${row.label}: ${row.status}`);
287
+ return [..._senseStatusLinesCache];
288
+ }
289
+ function senseRuntimeGuidance(channel) {
290
+ const lines = ["available senses:"];
291
+ lines.push(...localSenseStatusLines());
292
+ lines.push("sense states:");
293
+ lines.push("- interactive = available when opened by the user instead of kept running by the daemon");
294
+ lines.push("- disabled = turned off in agent.json");
295
+ lines.push("- needs_config = enabled but missing required secrets.json values");
296
+ lines.push("- ready = enabled and configured; `ouro up` should bring it online");
297
+ lines.push("- running = enabled and currently active");
298
+ lines.push("- error = enabled but unhealthy");
299
+ 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.");
300
+ lines.push("teams setup truth: enable `senses.teams.enabled`, then provide `teams.clientId`, `teams.clientSecret`, and `teams.tenantId` in secrets.json.");
301
+ lines.push("bluebubbles setup truth: enable `senses.bluebubbles.enabled`, then provide `bluebubbles.serverUrl` and `bluebubbles.password` in secrets.json.");
302
+ if (channel === "cli") {
303
+ lines.push("cli is interactive: it is available when the user opens it, not something `ouro up` daemonizes.");
304
+ }
305
+ return lines;
306
+ }
209
307
  function providerSection() {
210
308
  return `## my provider\n${(0, core_1.getProviderDisplayLabel)()}`;
211
309
  }
@@ -213,14 +311,50 @@ function dateSection() {
213
311
  const today = new Date().toISOString().slice(0, 10);
214
312
  return `current date: ${today}`;
215
313
  }
216
- function toolsSection(channel, options) {
217
- const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel));
314
+ function toolsSection(channel, options, context) {
315
+ const channelTools = (0, tools_1.getToolsForChannel)((0, channel_1.getChannelCapabilities)(channel), undefined, context, options?.providerCapabilities);
218
316
  const activeTools = (options?.toolChoiceRequired ?? true) ? [...channelTools, tools_1.finalAnswerTool] : channelTools;
219
317
  const list = activeTools
220
318
  .map((t) => `- ${t.function.name}: ${t.function.description}`)
221
319
  .join("\n");
222
320
  return `## my tools\n${list}`;
223
321
  }
322
+ function toolRestrictionSection(context) {
323
+ if (!context?.friend || !(0, channel_1.isRemoteChannel)(context.channel))
324
+ return "";
325
+ if ((0, types_1.isTrustedLevel)(context.friend.trustLevel))
326
+ return "";
327
+ const toolList = [...tools_1.REMOTE_BLOCKED_LOCAL_TOOLS].join(", ");
328
+ return `## restricted tools
329
+ some of my tools are unavailable right now: ${toolList}
330
+
331
+ i don't know this person well enough yet to run local operations on their behalf. i can suggest remote-safe alternatives or ask them to run it from CLI.`;
332
+ }
333
+ function trustContextSection(context) {
334
+ if (!context?.friend)
335
+ return "";
336
+ const channelName = context.channel.channel;
337
+ if (channelName === "cli" || channelName === "inner")
338
+ return "";
339
+ const explanation = (0, trust_explanation_1.describeTrustContext)({
340
+ friend: context.friend,
341
+ channel: channelName,
342
+ isGroupChat: context.isGroupChat,
343
+ });
344
+ const lines = [
345
+ "## trust context",
346
+ `level: ${explanation.level}`,
347
+ `basis: ${explanation.basis}`,
348
+ `summary: ${explanation.summary}`,
349
+ `why: ${explanation.why}`,
350
+ `permits: ${explanation.permits.join(", ")}`,
351
+ `constraints: ${explanation.constraints.join(", ") || "none"}`,
352
+ ];
353
+ if (explanation.relatedGroupId) {
354
+ lines.push(`related group: ${explanation.relatedGroupId}`);
355
+ }
356
+ return lines.join("\n");
357
+ }
224
358
  function skillsSection() {
225
359
  const names = (0, skills_1.listSkills)() || [];
226
360
  if (!names.length)
@@ -251,6 +385,38 @@ function memoryFriendToolContractSection() {
251
385
  - My psyche files (SOUL, IDENTITY, TACIT, LORE, ASPIRATIONS) are always loaded - I already know who I am.
252
386
  - My task board is always loaded - I already know my work.`;
253
387
  }
388
+ function bridgeContextSection(options) {
389
+ if (options?.activeWorkFrame)
390
+ return "";
391
+ const bridgeContext = options?.bridgeContext?.trim() ?? "";
392
+ if (!bridgeContext)
393
+ return "";
394
+ return bridgeContext.startsWith("## ") ? bridgeContext : `## active bridge work\n${bridgeContext}`;
395
+ }
396
+ function activeWorkSection(options) {
397
+ if (!options?.activeWorkFrame)
398
+ return "";
399
+ return (0, active_work_1.formatActiveWorkFrame)(options.activeWorkFrame);
400
+ }
401
+ function delegationHintSection(options) {
402
+ if (!options?.delegationDecision)
403
+ return "";
404
+ const lines = [
405
+ "## delegation hint",
406
+ `target: ${options.delegationDecision.target}`,
407
+ `reasons: ${options.delegationDecision.reasons.length > 0 ? options.delegationDecision.reasons.join(", ") : "none"}`,
408
+ `outward closure: ${options.delegationDecision.outwardClosureRequired ? "required" : "not required"}`,
409
+ ];
410
+ return lines.join("\n");
411
+ }
412
+ function reasoningEffortSection(options) {
413
+ if (!options?.providerCapabilities?.has("reasoning-effort"))
414
+ return "";
415
+ const levels = options.supportedReasoningEfforts ?? [];
416
+ const levelList = levels.length > 0 ? levels.join(", ") : "varies by model";
417
+ return `## reasoning effort
418
+ 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}.`;
419
+ }
254
420
  function toolBehaviorSection(options) {
255
421
  if (!(options?.toolChoiceRequired ?? true))
256
422
  return "";
@@ -260,9 +426,9 @@ tool_choice is set to "required" -- i must call a tool on every turn.
260
426
  - ready to respond to the user? i call \`final_answer\`.
261
427
  \`final_answer\` is a tool call -- it satisfies the tool_choice requirement.
262
428
  \`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.`;
429
+ do NOT call no-op tools just before \`final_answer\`. if i am done, i call \`final_answer\` directly.`;
264
430
  }
265
- function contextSection(context) {
431
+ function contextSection(context, options) {
266
432
  if (!context)
267
433
  return "";
268
434
  const lines = ["## friend context"];
@@ -298,7 +464,7 @@ function contextSection(context) {
298
464
  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
465
  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
466
  // Onboarding instructions (only below token threshold -- drop once exceeded)
301
- const impressions = (0, first_impressions_1.getFirstImpressions)(friend);
467
+ const impressions = (0, first_impressions_1.getFirstImpressions)(friend, options);
302
468
  if (impressions) {
303
469
  lines.push(impressions);
304
470
  }
@@ -312,6 +478,49 @@ function contextSection(context) {
312
478
  }
313
479
  return lines.join("\n");
314
480
  }
481
+ function metacognitiveFramingSection(channel) {
482
+ if (channel !== "inner")
483
+ return "";
484
+ return `this is my inner dialog. there is no one else here.
485
+
486
+ the messages that appear here are my own awareness surfacing:
487
+ instincts, the passage of time, notes from my conversations,
488
+ things i asked myself to think about. not commands. not requests.
489
+ just my own mind, noticing.
490
+
491
+ i can think freely here. i can also act — check on things,
492
+ reach out to people, work on tasks, or just sit with a thought.
493
+
494
+ thoughts worth sharing can go outward — i reach out to whoever
495
+ needs to hear them. things from conversations that need time
496
+ to process arrive here, in my thinking space.
497
+
498
+ think. share. think some more.`;
499
+ }
500
+ function loopOrientationSection(channel) {
501
+ if (channel === "inner")
502
+ return "";
503
+ 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.
504
+
505
+ when something deserves more thought than the moment allows, i can note it to myself and come back later with a considered answer.`;
506
+ }
507
+ function channelNatureSection(capabilities) {
508
+ const { senseType } = capabilities;
509
+ if (senseType === "local" || senseType === "internal")
510
+ return "";
511
+ if (senseType === "open") {
512
+ 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.";
513
+ }
514
+ // closed
515
+ return "## channel nature\nthis is an org-gated channel — i know everyone here is already part of the organization.";
516
+ }
517
+ function mixedTrustGroupSection(context) {
518
+ if (!context?.friend || !(0, channel_1.isRemoteChannel)(context.channel))
519
+ return "";
520
+ if (!context.isGroupChat)
521
+ return "";
522
+ 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.";
523
+ }
315
524
  async function buildSystem(channel = "cli", options, context) {
316
525
  (0, runtime_1.emitNervesEvent)({
317
526
  event: "mind.step_start",
@@ -319,29 +528,42 @@ async function buildSystem(channel = "cli", options, context) {
319
528
  message: "buildSystem started",
320
529
  meta: { channel, has_context: Boolean(context), tool_choice_required: Boolean(options?.toolChoiceRequired) },
321
530
  });
531
+ // Backfill bundle-meta.json for existing agents that don't have one
532
+ (0, bundle_manifest_1.backfillBundleMeta)((0, identity_1.getAgentRoot)());
322
533
  const system = [
323
534
  soulSection(),
324
535
  identitySection(),
325
536
  loreSection(),
326
537
  tacitKnowledgeSection(),
327
538
  aspirationsSection(),
539
+ bodyMapSection((0, identity_1.getAgentName)()),
540
+ metacognitiveFramingSection(channel),
541
+ loopOrientationSection(channel),
328
542
  runtimeInfoSection(channel),
543
+ channelNatureSection((0, channel_1.getChannelCapabilities)(channel)),
329
544
  providerSection(),
330
545
  dateSection(),
331
- toolsSection(channel, options),
546
+ toolsSection(channel, options, context),
547
+ reasoningEffortSection(options),
548
+ toolRestrictionSection(context),
549
+ trustContextSection(context),
550
+ mixedTrustGroupSection(context),
332
551
  skillsSection(),
333
552
  taskBoardSection(),
553
+ activeWorkSection(options),
554
+ delegationHintSection(options),
555
+ bridgeContextSection(options),
334
556
  buildSessionSummary({
335
- sessionsDir: path.join(os.homedir(), ".agentstate", (0, identity_1.getAgentName)(), "sessions"),
557
+ sessionsDir: path.join((0, identity_1.getAgentRoot)(), "state", "sessions"),
336
558
  friendsDir: path.join((0, identity_1.getAgentRoot)(), "friends"),
337
559
  agentName: (0, identity_1.getAgentName)(),
338
560
  currentFriendId: context?.friend?.id,
339
561
  currentChannel: channel,
340
- currentKey: "session",
562
+ currentKey: options?.currentSessionKey ?? "session",
341
563
  }),
342
564
  memoryFriendToolContractSection(),
343
565
  toolBehaviorSection(options),
344
- contextSection(context),
566
+ contextSection(context, options),
345
567
  ]
346
568
  .filter(Boolean)
347
569
  .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
- };
@@ -5,20 +5,33 @@ const config_1 = require("../heart/config");
5
5
  const nerves_1 = require("../nerves");
6
6
  const runtime_1 = require("./runtime");
7
7
  const runtime_2 = require("./runtime");
8
+ const LEVEL_PRIORITY = { debug: 10, info: 20, warn: 30, error: 40 };
9
+ /** Wrap a sink so it only receives events at or above the given level. */
10
+ /* v8 ignore start -- internal filter plumbing, exercised via integration @preserve */
11
+ function filterSink(sink, minLevel) {
12
+ const minPriority = LEVEL_PRIORITY[minLevel] ?? 0;
13
+ return (entry) => {
14
+ if ((LEVEL_PRIORITY[entry.level] ?? 0) >= minPriority)
15
+ sink(entry);
16
+ };
17
+ }
8
18
  function resolveCliSinks(sinks) {
9
19
  const requested = sinks && sinks.length > 0 ? sinks : ["terminal", "ndjson"];
10
20
  return [...new Set(requested)];
11
21
  }
12
22
  function configureCliRuntimeLogger(_friendId, options = {}) {
13
23
  const sinkKinds = resolveCliSinks(options.sinks);
24
+ const level = options.level ?? "info";
14
25
  const sinks = sinkKinds.map((sinkKind) => {
15
26
  if (sinkKind === "terminal") {
16
- return (0, nerves_1.createTerminalSink)();
27
+ // Terminal only shows warnings and errors — INFO is too noisy
28
+ // for an interactive session. Full detail goes to the ndjson file.
29
+ return filterSink((0, nerves_1.createTerminalSink)(), "warn");
17
30
  }
18
31
  return (0, nerves_1.createNdjsonFileSink)((0, config_1.logPath)("cli", "runtime"));
19
32
  });
20
33
  const logger = (0, nerves_1.createLogger)({
21
- level: options.level ?? "info",
34
+ level,
22
35
  sinks,
23
36
  });
24
37
  (0, runtime_2.setRuntimeLogger)(logger);
@@ -14,7 +14,7 @@ const path_1 = require("path");
14
14
  const os_1 = require("os");
15
15
  exports.REPO_SLUG = "ouroboros-agent-harness";
16
16
  function getTestRunsRoot(repoSlug = exports.REPO_SLUG) {
17
- return (0, path_1.join)((0, os_1.homedir)(), ".agentstate", "test-runs", repoSlug);
17
+ return (0, path_1.join)((0, os_1.tmpdir)(), "ouroboros-test-runs", repoSlug);
18
18
  }
19
19
  function createRunId(now = new Date()) {
20
20
  return now.toISOString().replace(/[:.]/g, "-");
@@ -28,8 +28,10 @@ function resolveContentType(method, path) {
28
28
  : "application/json";
29
29
  }
30
30
  // Generic ADO API request. Returns response body as pretty-printed JSON string.
31
- async function adoRequest(token, method, org, path, body) {
31
+ // `host` overrides the base URL for non-standard APIs (e.g. "vsapm.dev.azure.com", "vssps.dev.azure.com").
32
+ async function adoRequest(token, method, org, path, body, host) {
32
33
  try {
34
+ const base = host ? `https://${host}/${org}` : `${ADO_BASE}/${org}`;
33
35
  (0, runtime_1.emitNervesEvent)({
34
36
  event: "client.request_start",
35
37
  component: "clients",
@@ -37,7 +39,7 @@ async function adoRequest(token, method, org, path, body) {
37
39
  meta: { client: "ado", method, org, path },
38
40
  });
39
41
  const fullPath = ensureApiVersion(path);
40
- const url = `${ADO_BASE}/${org}${fullPath}`;
42
+ const url = `${base}${fullPath}`;
41
43
  const contentType = resolveContentType(method, path);
42
44
  const opts = {
43
45
  method,