@ouro.bot/cli 0.1.0-alpha.9 → 0.1.0-alpha.91
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AdoptionSpecialist.ouro/agent.json +70 -9
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
- package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
- package/README.md +147 -205
- package/assets/ouroboros.png +0 -0
- package/changelog.json +536 -0
- package/dist/heart/active-work.js +251 -0
- package/dist/heart/bridges/manager.js +358 -0
- package/dist/heart/bridges/state-machine.js +135 -0
- package/dist/heart/bridges/store.js +123 -0
- package/dist/heart/commitments.js +109 -0
- package/dist/heart/config.js +68 -23
- package/dist/heart/core.js +452 -93
- package/dist/heart/cross-chat-delivery.js +146 -0
- package/dist/heart/daemon/agent-discovery.js +81 -0
- package/dist/heart/daemon/auth-flow.js +430 -0
- package/dist/heart/daemon/daemon-cli.js +1738 -269
- package/dist/heart/daemon/daemon-entry.js +55 -6
- package/dist/heart/daemon/daemon-runtime-sync.js +212 -0
- package/dist/heart/daemon/daemon.js +216 -10
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +7 -82
- package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
- package/dist/heart/daemon/launchd.js +159 -0
- package/dist/heart/daemon/log-tailer.js +4 -3
- package/dist/heart/daemon/message-router.js +17 -8
- package/dist/heart/daemon/ouro-bot-entry.js +0 -0
- package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
- package/dist/heart/daemon/ouro-entry.js +0 -0
- package/dist/heart/daemon/ouro-path-installer.js +260 -0
- package/dist/heart/daemon/ouro-uti.js +11 -2
- package/dist/heart/daemon/ouro-version-manager.js +171 -0
- package/dist/heart/daemon/process-manager.js +14 -1
- package/dist/heart/daemon/run-hooks.js +37 -0
- package/dist/heart/daemon/runtime-logging.js +58 -15
- package/dist/heart/daemon/runtime-metadata.js +219 -0
- package/dist/heart/daemon/runtime-mode.js +67 -0
- package/dist/heart/daemon/sense-manager.js +307 -0
- package/dist/heart/daemon/skill-management-installer.js +94 -0
- package/dist/heart/daemon/socket-client.js +202 -0
- package/dist/heart/daemon/specialist-orchestrator.js +53 -84
- package/dist/heart/daemon/specialist-prompt.js +63 -11
- package/dist/heart/daemon/specialist-tools.js +211 -60
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/thoughts.js +507 -0
- package/dist/heart/daemon/update-checker.js +111 -0
- package/dist/heart/daemon/update-hooks.js +138 -0
- package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
- package/dist/heart/delegation.js +62 -0
- package/dist/heart/identity.js +126 -21
- package/dist/heart/kicks.js +1 -19
- package/dist/heart/model-capabilities.js +48 -0
- package/dist/heart/obligations.js +191 -0
- package/dist/heart/progress-story.js +42 -0
- package/dist/heart/providers/anthropic.js +74 -9
- package/dist/heart/providers/azure.js +86 -7
- package/dist/heart/providers/github-copilot.js +149 -0
- package/dist/heart/providers/minimax.js +4 -0
- package/dist/heart/providers/openai-codex.js +12 -3
- package/dist/heart/safe-workspace.js +362 -0
- package/dist/heart/sense-truth.js +61 -0
- package/dist/heart/session-activity.js +169 -0
- package/dist/heart/session-recall.js +116 -0
- package/dist/heart/streaming.js +100 -22
- package/dist/heart/target-resolution.js +123 -0
- package/dist/heart/turn-coordinator.js +28 -0
- package/dist/mind/associative-recall.js +14 -2
- package/dist/mind/bundle-manifest.js +70 -0
- package/dist/mind/context.js +57 -11
- package/dist/mind/first-impressions.js +16 -2
- package/dist/mind/friends/channel.js +35 -0
- package/dist/mind/friends/group-context.js +144 -0
- package/dist/mind/friends/store-file.js +19 -0
- package/dist/mind/friends/trust-explanation.js +74 -0
- package/dist/mind/friends/types.js +8 -0
- package/dist/mind/memory.js +27 -26
- package/dist/mind/obligation-steering.js +31 -0
- package/dist/mind/pending.js +76 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +467 -77
- package/dist/mind/token-estimate.js +8 -12
- package/dist/nerves/cli-logging.js +15 -2
- package/dist/nerves/coverage/run-artifacts.js +1 -1
- package/dist/nerves/index.js +12 -0
- package/dist/repertoire/ado-client.js +4 -2
- package/dist/repertoire/coding/feedback.js +180 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +69 -4
- package/dist/repertoire/coding/spawner.js +21 -3
- package/dist/repertoire/coding/tools.js +105 -2
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- package/dist/repertoire/guardrails.js +290 -0
- package/dist/repertoire/mcp-client.js +254 -0
- package/dist/repertoire/mcp-manager.js +195 -0
- package/dist/repertoire/skills.js +3 -26
- package/dist/repertoire/tasks/board.js +12 -0
- package/dist/repertoire/tasks/index.js +23 -9
- package/dist/repertoire/tasks/transitions.js +1 -2
- package/dist/repertoire/tools-base.js +714 -249
- package/dist/repertoire/tools-bluebubbles.js +93 -0
- package/dist/repertoire/tools-teams.js +58 -25
- package/dist/repertoire/tools.js +106 -53
- package/dist/senses/bluebubbles-client.js +210 -5
- package/dist/senses/bluebubbles-entry.js +2 -0
- package/dist/senses/bluebubbles-inbound-log.js +109 -0
- package/dist/senses/bluebubbles-media.js +339 -0
- package/dist/senses/bluebubbles-model.js +12 -4
- package/dist/senses/bluebubbles-mutation-log.js +45 -5
- package/dist/senses/bluebubbles-runtime-state.js +109 -0
- package/dist/senses/bluebubbles-session-cleanup.js +72 -0
- package/dist/senses/bluebubbles.js +894 -45
- package/dist/senses/cli-layout.js +187 -0
- package/dist/senses/cli.js +400 -164
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/debug-activity.js +154 -0
- package/dist/senses/inner-dialog-worker.js +47 -18
- package/dist/senses/inner-dialog.js +377 -83
- package/dist/senses/pipeline.js +307 -0
- package/dist/senses/teams.js +573 -129
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -3
- package/subagents/README.md +4 -70
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/heart/daemon/subagent-installer.js +0 -125
- package/dist/inner-worker-entry.js +0 -4
- package/subagents/work-doer.md +0 -233
- package/subagents/work-merger.md +0 -624
- package/subagents/work-planner.md +0 -373
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Formats inner dialog session turns for human consumption.
|
|
3
|
+
// Used by `ouro thoughts` CLI command to show what the agent has been thinking.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.formatSurfacedValue = formatSurfacedValue;
|
|
39
|
+
exports.deriveInnerDialogStatus = deriveInnerDialogStatus;
|
|
40
|
+
exports.deriveInnerJob = deriveInnerJob;
|
|
41
|
+
exports.formatInnerDialogStatus = formatInnerDialogStatus;
|
|
42
|
+
exports.extractThoughtResponseFromMessages = extractThoughtResponseFromMessages;
|
|
43
|
+
exports.parseInnerDialogSession = parseInnerDialogSession;
|
|
44
|
+
exports.formatThoughtTurns = formatThoughtTurns;
|
|
45
|
+
exports.getInnerDialogSessionPath = getInnerDialogSessionPath;
|
|
46
|
+
exports.readInnerDialogStatus = readInnerDialogStatus;
|
|
47
|
+
exports.readInnerDialogRawData = readInnerDialogRawData;
|
|
48
|
+
exports.followThoughts = followThoughts;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
52
|
+
function contentToText(content) {
|
|
53
|
+
if (typeof content === "string")
|
|
54
|
+
return content;
|
|
55
|
+
if (!Array.isArray(content))
|
|
56
|
+
return "";
|
|
57
|
+
return content
|
|
58
|
+
.map((part) => {
|
|
59
|
+
if (typeof part === "string")
|
|
60
|
+
return part;
|
|
61
|
+
if (part && typeof part === "object" && "text" in part && typeof part.text === "string") {
|
|
62
|
+
return part.text;
|
|
63
|
+
}
|
|
64
|
+
return "";
|
|
65
|
+
})
|
|
66
|
+
.join("\n");
|
|
67
|
+
}
|
|
68
|
+
function extractToolFunction(toolCall) {
|
|
69
|
+
if (!toolCall || typeof toolCall !== "object" || !("function" in toolCall))
|
|
70
|
+
return null;
|
|
71
|
+
const maybeFunction = toolCall.function;
|
|
72
|
+
if (!maybeFunction || typeof maybeFunction !== "object")
|
|
73
|
+
return null;
|
|
74
|
+
const name = "name" in maybeFunction && typeof maybeFunction.name === "string"
|
|
75
|
+
? maybeFunction.name
|
|
76
|
+
: undefined;
|
|
77
|
+
const argumentsValue = "arguments" in maybeFunction && typeof maybeFunction.arguments === "string"
|
|
78
|
+
? maybeFunction.arguments
|
|
79
|
+
: undefined;
|
|
80
|
+
return { name, arguments: argumentsValue };
|
|
81
|
+
}
|
|
82
|
+
function classifyTurn(userText) {
|
|
83
|
+
if (userText.includes("waking up."))
|
|
84
|
+
return { type: "boot" };
|
|
85
|
+
const taskMatch = /## task: (.+)$/m.exec(userText);
|
|
86
|
+
if (taskMatch)
|
|
87
|
+
return { type: "task", taskId: taskMatch[1] };
|
|
88
|
+
return { type: "heartbeat" };
|
|
89
|
+
}
|
|
90
|
+
function extractToolNames(messages) {
|
|
91
|
+
const names = [];
|
|
92
|
+
for (const msg of messages) {
|
|
93
|
+
if (msg.role === "assistant" && Array.isArray(msg.tool_calls)) {
|
|
94
|
+
for (const tc of msg.tool_calls) {
|
|
95
|
+
const toolFunction = extractToolFunction(tc);
|
|
96
|
+
if (toolFunction?.name && toolFunction.name !== "final_answer")
|
|
97
|
+
names.push(toolFunction.name);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return names;
|
|
102
|
+
}
|
|
103
|
+
function extractPendingPromptMessages(prompt) {
|
|
104
|
+
return prompt
|
|
105
|
+
.split("\n")
|
|
106
|
+
.map((line) => line.trim())
|
|
107
|
+
.filter((line) => line.startsWith("[pending from "))
|
|
108
|
+
.map((line) => {
|
|
109
|
+
const separator = line.indexOf("]: ");
|
|
110
|
+
return separator >= 0 ? line.slice(separator + 3).trim() : "";
|
|
111
|
+
})
|
|
112
|
+
.filter((line) => line.length > 0);
|
|
113
|
+
}
|
|
114
|
+
function readPendingMessagesForStatus(pendingDir) {
|
|
115
|
+
if (!fs.existsSync(pendingDir))
|
|
116
|
+
return [];
|
|
117
|
+
let entries;
|
|
118
|
+
try {
|
|
119
|
+
entries = fs.readdirSync(pendingDir);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const files = [
|
|
125
|
+
...entries.filter((entry) => entry.endsWith(".json.processing")),
|
|
126
|
+
...entries.filter((entry) => entry.endsWith(".json") && !entry.endsWith(".json.processing")),
|
|
127
|
+
].sort((a, b) => a.localeCompare(b));
|
|
128
|
+
const messages = [];
|
|
129
|
+
for (const file of files) {
|
|
130
|
+
try {
|
|
131
|
+
const raw = fs.readFileSync(path.join(pendingDir, file), "utf-8");
|
|
132
|
+
const parsed = JSON.parse(raw);
|
|
133
|
+
if (typeof parsed.content === "string") {
|
|
134
|
+
messages.push(parsed);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
// unreadable pending files should not break status queries
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return messages;
|
|
142
|
+
}
|
|
143
|
+
function formatSurfacedValue(text, maxLength = 120) {
|
|
144
|
+
const firstLine = text
|
|
145
|
+
.split("\n")
|
|
146
|
+
.map((line) => line.trim())
|
|
147
|
+
.find((line) => line.length > 0);
|
|
148
|
+
if (!firstLine)
|
|
149
|
+
return "no outward result";
|
|
150
|
+
if (firstLine.length <= maxLength)
|
|
151
|
+
return `"${firstLine}"`;
|
|
152
|
+
return `"${firstLine.slice(0, maxLength - 3)}..."`;
|
|
153
|
+
}
|
|
154
|
+
function extractEnrichedFields(pendingMessages) {
|
|
155
|
+
const delegated = pendingMessages.find((msg) => msg.delegatedFrom);
|
|
156
|
+
if (!delegated?.delegatedFrom)
|
|
157
|
+
return {};
|
|
158
|
+
const snippet = delegated.content.length > 80 ? delegated.content.slice(0, 77) + "..." : delegated.content;
|
|
159
|
+
return {
|
|
160
|
+
origin: {
|
|
161
|
+
friendId: delegated.delegatedFrom.friendId,
|
|
162
|
+
channel: delegated.delegatedFrom.channel,
|
|
163
|
+
key: delegated.delegatedFrom.key,
|
|
164
|
+
},
|
|
165
|
+
contentSnippet: snippet,
|
|
166
|
+
...(delegated.obligationStatus === "pending" ? { obligationPending: true } : {}),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function deriveInnerDialogStatus(pendingMessages, turns, runtimeState) {
|
|
170
|
+
if (runtimeState?.status === "running") {
|
|
171
|
+
if (pendingMessages.length > 0) {
|
|
172
|
+
return {
|
|
173
|
+
queue: "queued to inner/dialog",
|
|
174
|
+
wake: "queued behind active turn",
|
|
175
|
+
processing: "pending",
|
|
176
|
+
surfaced: "nothing yet",
|
|
177
|
+
...extractEnrichedFields(pendingMessages),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
queue: "clear",
|
|
182
|
+
wake: "in progress",
|
|
183
|
+
processing: "started",
|
|
184
|
+
surfaced: "nothing yet",
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
if (pendingMessages.length > 0) {
|
|
188
|
+
return {
|
|
189
|
+
queue: "queued to inner/dialog",
|
|
190
|
+
wake: "awaiting inner session",
|
|
191
|
+
processing: "pending",
|
|
192
|
+
surfaced: "nothing yet",
|
|
193
|
+
...extractEnrichedFields(pendingMessages),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
const latestProcessedPendingTurn = [...turns]
|
|
197
|
+
.reverse()
|
|
198
|
+
.find((turn) => extractPendingPromptMessages(turn.prompt).length > 0);
|
|
199
|
+
if (!latestProcessedPendingTurn) {
|
|
200
|
+
return {
|
|
201
|
+
queue: "clear",
|
|
202
|
+
wake: "idle",
|
|
203
|
+
processing: "idle",
|
|
204
|
+
surfaced: "nothing recent",
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
queue: "clear",
|
|
209
|
+
wake: "completed",
|
|
210
|
+
processing: "processed",
|
|
211
|
+
surfaced: formatSurfacedValue(latestProcessedPendingTurn.response),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
function deriveInnerJob(pendingMessages, turns, runtimeState) {
|
|
215
|
+
const isRunning = runtimeState?.status === "running";
|
|
216
|
+
const delegated = pendingMessages.find((msg) => msg.delegatedFrom);
|
|
217
|
+
const enriched = extractEnrichedFields(pendingMessages);
|
|
218
|
+
const pendingMode = delegated && "mode" in delegated && delegated.mode ? delegated.mode : "reflect";
|
|
219
|
+
const origin = enriched.origin ?? null;
|
|
220
|
+
const content = delegated?.content ?? null;
|
|
221
|
+
const obligationStatus = delegated?.obligationStatus ?? null;
|
|
222
|
+
const queuedAt = delegated?.timestamp ?? null;
|
|
223
|
+
if (isRunning) {
|
|
224
|
+
(0, runtime_1.emitNervesEvent)({
|
|
225
|
+
component: "engine",
|
|
226
|
+
event: "engine.inner_job_derive",
|
|
227
|
+
message: "derived inner job state",
|
|
228
|
+
meta: { status: "running", mode: pendingMode, hasOrigin: origin !== null, hasObligation: obligationStatus !== null },
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
status: "running",
|
|
232
|
+
content,
|
|
233
|
+
origin,
|
|
234
|
+
mode: pendingMode,
|
|
235
|
+
obligationStatus,
|
|
236
|
+
surfacedResult: null,
|
|
237
|
+
queuedAt,
|
|
238
|
+
startedAt: runtimeState?.startedAt ?? null,
|
|
239
|
+
surfacedAt: null,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (pendingMessages.length > 0) {
|
|
243
|
+
(0, runtime_1.emitNervesEvent)({
|
|
244
|
+
component: "engine",
|
|
245
|
+
event: "engine.inner_job_derive",
|
|
246
|
+
message: "derived inner job state",
|
|
247
|
+
meta: { status: "queued", mode: pendingMode, hasOrigin: origin !== null, hasObligation: obligationStatus !== null },
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
status: "queued",
|
|
251
|
+
content,
|
|
252
|
+
origin,
|
|
253
|
+
mode: pendingMode,
|
|
254
|
+
obligationStatus,
|
|
255
|
+
surfacedResult: null,
|
|
256
|
+
queuedAt,
|
|
257
|
+
startedAt: null,
|
|
258
|
+
surfacedAt: null,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
// No pending, not running -- check for surfaced result
|
|
262
|
+
const latestProcessedPendingTurn = [...turns]
|
|
263
|
+
.reverse()
|
|
264
|
+
.find((turn) => extractPendingPromptMessages(turn.prompt).length > 0);
|
|
265
|
+
if (latestProcessedPendingTurn) {
|
|
266
|
+
const surfacedResult = extractThoughtResponseFromMessages([
|
|
267
|
+
{ role: "assistant", content: latestProcessedPendingTurn.response },
|
|
268
|
+
]);
|
|
269
|
+
(0, runtime_1.emitNervesEvent)({
|
|
270
|
+
component: "engine",
|
|
271
|
+
event: "engine.inner_job_derive",
|
|
272
|
+
message: "derived inner job state",
|
|
273
|
+
meta: { status: "surfaced", mode: "reflect", hasOrigin: false, hasObligation: false },
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
status: "surfaced",
|
|
277
|
+
content: null,
|
|
278
|
+
origin: null,
|
|
279
|
+
mode: "reflect",
|
|
280
|
+
obligationStatus: null,
|
|
281
|
+
/* v8 ignore next -- defensive: surfacedResult fallback @preserve */
|
|
282
|
+
surfacedResult: surfacedResult || null,
|
|
283
|
+
queuedAt: null,
|
|
284
|
+
startedAt: null,
|
|
285
|
+
surfacedAt: null,
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
(0, runtime_1.emitNervesEvent)({
|
|
289
|
+
component: "engine",
|
|
290
|
+
event: "engine.inner_job_derive",
|
|
291
|
+
message: "derived inner job state",
|
|
292
|
+
meta: { status: "idle", mode: "reflect", hasOrigin: false, hasObligation: false },
|
|
293
|
+
});
|
|
294
|
+
return {
|
|
295
|
+
status: "idle",
|
|
296
|
+
content: null,
|
|
297
|
+
origin: null,
|
|
298
|
+
mode: "reflect",
|
|
299
|
+
obligationStatus: null,
|
|
300
|
+
surfacedResult: null,
|
|
301
|
+
queuedAt: null,
|
|
302
|
+
startedAt: null,
|
|
303
|
+
surfacedAt: null,
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function formatInnerDialogStatus(status) {
|
|
307
|
+
const lines = [
|
|
308
|
+
`queue: ${status.queue}`,
|
|
309
|
+
`wake: ${status.wake}`,
|
|
310
|
+
`processing: ${status.processing}`,
|
|
311
|
+
`surfaced: ${status.surfaced}`,
|
|
312
|
+
];
|
|
313
|
+
if (status.origin) {
|
|
314
|
+
lines.push(`origin: ${status.origin.friendId}/${status.origin.channel}/${status.origin.key}`);
|
|
315
|
+
}
|
|
316
|
+
if (status.contentSnippet) {
|
|
317
|
+
lines.push(`asked: ${status.contentSnippet}`);
|
|
318
|
+
}
|
|
319
|
+
if (status.obligationPending) {
|
|
320
|
+
lines.push("obligation: pending");
|
|
321
|
+
}
|
|
322
|
+
return lines.join("\n");
|
|
323
|
+
}
|
|
324
|
+
/** Extract text from a final_answer tool call's arguments. */
|
|
325
|
+
function extractFinalAnswer(messages) {
|
|
326
|
+
for (let k = messages.length - 1; k >= 0; k--) {
|
|
327
|
+
const msg = messages[k];
|
|
328
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.tool_calls))
|
|
329
|
+
continue;
|
|
330
|
+
for (const tc of msg.tool_calls) {
|
|
331
|
+
const toolFunction = extractToolFunction(tc);
|
|
332
|
+
if (toolFunction?.name !== "final_answer")
|
|
333
|
+
continue;
|
|
334
|
+
try {
|
|
335
|
+
const parsed = JSON.parse(toolFunction.arguments ?? "{}");
|
|
336
|
+
if (typeof parsed.answer === "string" && parsed.answer.trim())
|
|
337
|
+
return parsed.answer.trim();
|
|
338
|
+
}
|
|
339
|
+
catch {
|
|
340
|
+
// malformed arguments — skip
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return "";
|
|
345
|
+
}
|
|
346
|
+
function extractThoughtResponseFromMessages(messages) {
|
|
347
|
+
const assistantMsgs = messages.filter((message) => message.role === "assistant");
|
|
348
|
+
const lastAssistant = assistantMsgs.reverse().find((message) => contentToText(message.content).trim().length > 0);
|
|
349
|
+
return lastAssistant
|
|
350
|
+
? contentToText(lastAssistant.content).trim()
|
|
351
|
+
: extractFinalAnswer(messages);
|
|
352
|
+
}
|
|
353
|
+
function parseInnerDialogSession(sessionPath) {
|
|
354
|
+
(0, runtime_1.emitNervesEvent)({
|
|
355
|
+
component: "daemon",
|
|
356
|
+
event: "daemon.thoughts_parse",
|
|
357
|
+
message: "parsing inner dialog session",
|
|
358
|
+
meta: { sessionPath },
|
|
359
|
+
});
|
|
360
|
+
let raw;
|
|
361
|
+
try {
|
|
362
|
+
raw = fs.readFileSync(sessionPath, "utf-8");
|
|
363
|
+
}
|
|
364
|
+
catch {
|
|
365
|
+
return [];
|
|
366
|
+
}
|
|
367
|
+
let data;
|
|
368
|
+
try {
|
|
369
|
+
data = JSON.parse(raw);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
return [];
|
|
373
|
+
}
|
|
374
|
+
if (data.version !== 1 || !Array.isArray(data.messages))
|
|
375
|
+
return [];
|
|
376
|
+
const turns = [];
|
|
377
|
+
const messages = data.messages;
|
|
378
|
+
// Walk messages, pairing user → (tool calls) → assistant sequences
|
|
379
|
+
let i = 0;
|
|
380
|
+
while (i < messages.length) {
|
|
381
|
+
const msg = messages[i];
|
|
382
|
+
if (msg.role === "system") {
|
|
383
|
+
i++;
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if (msg.role !== "user") {
|
|
387
|
+
i++;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const userText = contentToText(msg.content);
|
|
391
|
+
const classification = classifyTurn(userText);
|
|
392
|
+
// Collect all messages until the next user message (or end)
|
|
393
|
+
const turnMessages = [];
|
|
394
|
+
let j = i + 1;
|
|
395
|
+
while (j < messages.length && messages[j].role !== "user") {
|
|
396
|
+
turnMessages.push(messages[j]);
|
|
397
|
+
j++;
|
|
398
|
+
}
|
|
399
|
+
// Find the last assistant text response in this turn.
|
|
400
|
+
// With tool_choice="required", the response may be inside a final_answer tool call.
|
|
401
|
+
const response = extractThoughtResponseFromMessages(turnMessages);
|
|
402
|
+
const tools = extractToolNames(turnMessages);
|
|
403
|
+
turns.push({
|
|
404
|
+
type: classification.type,
|
|
405
|
+
prompt: userText.trim(),
|
|
406
|
+
response,
|
|
407
|
+
tools,
|
|
408
|
+
...(classification.taskId ? { taskId: classification.taskId } : {}),
|
|
409
|
+
});
|
|
410
|
+
i = j;
|
|
411
|
+
}
|
|
412
|
+
return turns;
|
|
413
|
+
}
|
|
414
|
+
function formatThoughtTurns(turns, lastN) {
|
|
415
|
+
if (turns.length === 0)
|
|
416
|
+
return "no inner dialog activity";
|
|
417
|
+
const selected = lastN > 0 ? turns.slice(-lastN) : turns;
|
|
418
|
+
/* v8 ignore next -- unreachable: turns.length > 0 checked above, slice always returns ≥1 @preserve */
|
|
419
|
+
if (selected.length === 0)
|
|
420
|
+
return "no inner dialog activity";
|
|
421
|
+
const lines = [];
|
|
422
|
+
for (const turn of selected) {
|
|
423
|
+
const typeLabel = turn.type === "task" && turn.taskId
|
|
424
|
+
? `task: ${turn.taskId}`
|
|
425
|
+
: turn.type;
|
|
426
|
+
lines.push(`--- ${typeLabel} ---`);
|
|
427
|
+
if (turn.tools.length > 0) {
|
|
428
|
+
lines.push(`tools: ${turn.tools.join(", ")}`);
|
|
429
|
+
}
|
|
430
|
+
if (turn.response) {
|
|
431
|
+
lines.push(turn.response);
|
|
432
|
+
}
|
|
433
|
+
else {
|
|
434
|
+
lines.push("(no response)");
|
|
435
|
+
}
|
|
436
|
+
lines.push("");
|
|
437
|
+
}
|
|
438
|
+
return lines.join("\n").trim();
|
|
439
|
+
}
|
|
440
|
+
function getInnerDialogSessionPath(agentRoot) {
|
|
441
|
+
return path.join(agentRoot, "state", "sessions", "self", "inner", "dialog.json");
|
|
442
|
+
}
|
|
443
|
+
function getInnerDialogRuntimeStatePath(sessionPath) {
|
|
444
|
+
return path.join(path.dirname(sessionPath), "runtime.json");
|
|
445
|
+
}
|
|
446
|
+
function readInnerDialogRuntimeState(runtimePath) {
|
|
447
|
+
try {
|
|
448
|
+
const raw = fs.readFileSync(runtimePath, "utf-8");
|
|
449
|
+
const parsed = JSON.parse(raw);
|
|
450
|
+
if (parsed.status !== "running" && parsed.status !== "idle")
|
|
451
|
+
return null;
|
|
452
|
+
return {
|
|
453
|
+
status: parsed.status,
|
|
454
|
+
reason: parsed.reason === "boot" || parsed.reason === "heartbeat" || parsed.reason === "instinct"
|
|
455
|
+
? parsed.reason
|
|
456
|
+
: undefined,
|
|
457
|
+
startedAt: typeof parsed.startedAt === "string" ? parsed.startedAt : undefined,
|
|
458
|
+
lastCompletedAt: typeof parsed.lastCompletedAt === "string" ? parsed.lastCompletedAt : undefined,
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
catch {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function readInnerDialogStatus(sessionPath, pendingDir, runtimePath = getInnerDialogRuntimeStatePath(sessionPath)) {
|
|
466
|
+
const pendingMessages = readPendingMessagesForStatus(pendingDir);
|
|
467
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
468
|
+
const runtimeState = readInnerDialogRuntimeState(runtimePath);
|
|
469
|
+
return deriveInnerDialogStatus(pendingMessages, turns, runtimeState);
|
|
470
|
+
}
|
|
471
|
+
function readInnerDialogRawData(sessionPath, pendingDir) {
|
|
472
|
+
const runtimePath = getInnerDialogRuntimeStatePath(sessionPath);
|
|
473
|
+
const pendingMessages = readPendingMessagesForStatus(pendingDir);
|
|
474
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
475
|
+
const runtimeState = readInnerDialogRuntimeState(runtimePath);
|
|
476
|
+
return { pendingMessages, turns, runtimeState };
|
|
477
|
+
}
|
|
478
|
+
/**
|
|
479
|
+
* Watch a session file and emit new turns as they appear.
|
|
480
|
+
* Returns a cleanup function that stops the watcher.
|
|
481
|
+
*/
|
|
482
|
+
function followThoughts(sessionPath, onNewTurns, pollIntervalMs = 1000) {
|
|
483
|
+
let displayedCount = parseInnerDialogSession(sessionPath).length;
|
|
484
|
+
(0, runtime_1.emitNervesEvent)({
|
|
485
|
+
component: "daemon",
|
|
486
|
+
event: "daemon.thoughts_follow_start",
|
|
487
|
+
message: "started following inner dialog session",
|
|
488
|
+
meta: { sessionPath, initialTurns: displayedCount },
|
|
489
|
+
});
|
|
490
|
+
fs.watchFile(sessionPath, { interval: pollIntervalMs }, () => {
|
|
491
|
+
const turns = parseInnerDialogSession(sessionPath);
|
|
492
|
+
if (turns.length > displayedCount) {
|
|
493
|
+
const newTurns = turns.slice(displayedCount);
|
|
494
|
+
onNewTurns(formatThoughtTurns(newTurns, 0));
|
|
495
|
+
displayedCount = turns.length;
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
return () => {
|
|
499
|
+
fs.unwatchFile(sessionPath);
|
|
500
|
+
(0, runtime_1.emitNervesEvent)({
|
|
501
|
+
component: "daemon",
|
|
502
|
+
event: "daemon.thoughts_follow_stop",
|
|
503
|
+
message: "stopped following inner dialog session",
|
|
504
|
+
meta: { sessionPath, totalTurns: displayedCount },
|
|
505
|
+
});
|
|
506
|
+
};
|
|
507
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.checkForUpdate = checkForUpdate;
|
|
37
|
+
exports.startUpdateChecker = startUpdateChecker;
|
|
38
|
+
exports.stopUpdateChecker = stopUpdateChecker;
|
|
39
|
+
const semver = __importStar(require("semver"));
|
|
40
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
41
|
+
const DEFAULT_INTERVAL_MS = 30 * 60 * 1000; // 30 minutes
|
|
42
|
+
async function checkForUpdate(currentVersion, deps) {
|
|
43
|
+
(0, runtime_1.emitNervesEvent)({
|
|
44
|
+
component: "daemon",
|
|
45
|
+
event: "daemon.update_check",
|
|
46
|
+
message: "checking for update",
|
|
47
|
+
meta: { currentVersion, distTag: deps.distTag },
|
|
48
|
+
});
|
|
49
|
+
let registryData;
|
|
50
|
+
try {
|
|
51
|
+
registryData = (await deps.fetchRegistryJson());
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
const errorMessage = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
|
|
55
|
+
return { available: false, error: errorMessage };
|
|
56
|
+
}
|
|
57
|
+
const distTags = registryData?.["dist-tags"];
|
|
58
|
+
if (!distTags) {
|
|
59
|
+
return { available: false, error: "registry response missing dist-tags" };
|
|
60
|
+
}
|
|
61
|
+
const latestVersion = distTags[deps.distTag];
|
|
62
|
+
if (!latestVersion) {
|
|
63
|
+
return { available: false, error: `dist-tag "${deps.distTag}" not found in registry` };
|
|
64
|
+
}
|
|
65
|
+
const available = semver.gt(latestVersion, currentVersion);
|
|
66
|
+
(0, runtime_1.emitNervesEvent)({
|
|
67
|
+
component: "daemon",
|
|
68
|
+
event: "daemon.update_check_result",
|
|
69
|
+
message: available ? "update available" : "no update available",
|
|
70
|
+
meta: { currentVersion, latestVersion, available },
|
|
71
|
+
});
|
|
72
|
+
return { available, latestVersion };
|
|
73
|
+
}
|
|
74
|
+
let _intervalId = null;
|
|
75
|
+
function startUpdateChecker(options) {
|
|
76
|
+
const intervalMs = options.intervalMs ?? DEFAULT_INTERVAL_MS;
|
|
77
|
+
(0, runtime_1.emitNervesEvent)({
|
|
78
|
+
component: "daemon",
|
|
79
|
+
event: "daemon.update_checker_start",
|
|
80
|
+
message: "starting update checker",
|
|
81
|
+
meta: { intervalMs, currentVersion: options.currentVersion },
|
|
82
|
+
});
|
|
83
|
+
_intervalId = setInterval(() => {
|
|
84
|
+
void (async () => {
|
|
85
|
+
const result = await checkForUpdate(options.currentVersion, options.deps);
|
|
86
|
+
if (result.available && options.onUpdate) {
|
|
87
|
+
await options.onUpdate(result);
|
|
88
|
+
}
|
|
89
|
+
})().catch((err) => {
|
|
90
|
+
(0, runtime_1.emitNervesEvent)({
|
|
91
|
+
component: "daemon",
|
|
92
|
+
event: "daemon.update_checker_error",
|
|
93
|
+
level: "warn",
|
|
94
|
+
message: "update checker tick failed",
|
|
95
|
+
meta: { reason: err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err) },
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}, intervalMs);
|
|
99
|
+
}
|
|
100
|
+
function stopUpdateChecker() {
|
|
101
|
+
if (_intervalId) {
|
|
102
|
+
clearInterval(_intervalId);
|
|
103
|
+
_intervalId = null;
|
|
104
|
+
}
|
|
105
|
+
(0, runtime_1.emitNervesEvent)({
|
|
106
|
+
component: "daemon",
|
|
107
|
+
event: "daemon.update_checker_stop",
|
|
108
|
+
message: "stopping update checker",
|
|
109
|
+
meta: {},
|
|
110
|
+
});
|
|
111
|
+
}
|