@ouro.bot/cli 0.1.0-alpha.6 → 0.1.0-alpha.60
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 +325 -0
- package/dist/heart/active-work.js +178 -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/config.js +57 -23
- package/dist/heart/core.js +236 -90
- 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 +351 -0
- package/dist/heart/daemon/daemon-cli.js +1173 -227
- 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 +189 -10
- package/dist/heart/daemon/hatch-animation.js +10 -3
- package/dist/heart/daemon/hatch-flow.js +4 -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 +178 -0
- package/dist/heart/daemon/ouro-uti.js +11 -2
- 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/socket-client.js +202 -0
- package/dist/heart/daemon/specialist-orchestrator.js +53 -84
- package/dist/heart/daemon/specialist-prompt.js +64 -5
- package/dist/heart/daemon/specialist-tools.js +213 -58
- package/dist/heart/daemon/staged-restart.js +114 -0
- package/dist/heart/daemon/subagent-installer.js +48 -7
- package/dist/heart/daemon/thoughts.js +379 -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 +122 -19
- package/dist/heart/kicks.js +1 -19
- package/dist/heart/model-capabilities.js +40 -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/minimax.js +4 -0
- package/dist/heart/providers/openai-codex.js +12 -3
- package/dist/heart/safe-workspace.js +228 -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 +27 -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/pending.js +72 -9
- package/dist/mind/phrases.js +1 -0
- package/dist/mind/prompt.js +299 -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/repertoire/ado-client.js +4 -2
- package/dist/repertoire/coding/feedback.js +134 -0
- package/dist/repertoire/coding/index.js +4 -1
- package/dist/repertoire/coding/manager.js +62 -4
- package/dist/repertoire/coding/spawner.js +3 -3
- package/dist/repertoire/coding/tools.js +41 -2
- package/dist/repertoire/data/ado-endpoints.json +188 -0
- 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 +629 -251
- package/dist/repertoire/tools-bluebubbles.js +93 -0
- package/dist/repertoire/tools-teams.js +58 -25
- package/dist/repertoire/tools.js +92 -48
- 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 +890 -45
- package/dist/senses/cli-layout.js +87 -0
- package/dist/senses/cli.js +345 -144
- package/dist/senses/continuity.js +94 -0
- package/dist/senses/debug-activity.js +148 -0
- package/dist/senses/inner-dialog-worker.js +47 -18
- package/dist/senses/inner-dialog.js +330 -84
- package/dist/senses/pipeline.js +278 -0
- package/dist/senses/teams.js +570 -129
- package/dist/senses/trust-gate.js +112 -2
- package/package.json +14 -3
- package/subagents/README.md +46 -33
- package/subagents/work-doer.md +28 -24
- package/subagents/work-merger.md +24 -30
- package/subagents/work-planner.md +44 -27
- package/dist/heart/daemon/specialist-session.js +0 -142
- package/dist/inner-worker-entry.js +0 -4
|
@@ -33,19 +33,145 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.finalAnswerTool = exports.
|
|
36
|
+
exports.finalAnswerTool = exports.tools = exports.baseToolDefinitions = exports.editFileReadTracker = void 0;
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
|
+
const fg = __importStar(require("fast-glob"));
|
|
38
39
|
const child_process_1 = require("child_process");
|
|
39
40
|
const path = __importStar(require("path"));
|
|
40
41
|
const skills_1 = require("./skills");
|
|
41
42
|
const config_1 = require("../heart/config");
|
|
42
43
|
const runtime_1 = require("../nerves/runtime");
|
|
43
44
|
const identity_1 = require("../heart/identity");
|
|
44
|
-
const
|
|
45
|
-
const
|
|
45
|
+
const safe_workspace_1 = require("../heart/safe-workspace");
|
|
46
|
+
const socket_client_1 = require("../heart/daemon/socket-client");
|
|
47
|
+
const thoughts_1 = require("../heart/daemon/thoughts");
|
|
48
|
+
const manager_1 = require("../heart/bridges/manager");
|
|
49
|
+
const session_recall_1 = require("../heart/session-recall");
|
|
46
50
|
const tools_1 = require("./coding/tools");
|
|
47
51
|
const memory_1 = require("../mind/memory");
|
|
48
|
-
const
|
|
52
|
+
const pending_1 = require("../mind/pending");
|
|
53
|
+
const progress_story_1 = require("../heart/progress-story");
|
|
54
|
+
const cross_chat_delivery_1 = require("../heart/cross-chat-delivery");
|
|
55
|
+
// Tracks which file paths have been read via read_file in this session.
|
|
56
|
+
// edit_file requires a file to be read first (must-read-first guard).
|
|
57
|
+
exports.editFileReadTracker = new Set();
|
|
58
|
+
function buildContextDiff(lines, changeStart, changeEnd, contextSize = 3) {
|
|
59
|
+
const start = Math.max(0, changeStart - contextSize);
|
|
60
|
+
const end = Math.min(lines.length, changeEnd + contextSize);
|
|
61
|
+
const result = [];
|
|
62
|
+
for (let i = start; i < end; i++) {
|
|
63
|
+
const lineNum = i + 1;
|
|
64
|
+
const prefix = (i >= changeStart && i < changeEnd) ? ">" : " ";
|
|
65
|
+
result.push(`${prefix} ${lineNum} | ${lines[i]}`);
|
|
66
|
+
}
|
|
67
|
+
return result.join("\n");
|
|
68
|
+
}
|
|
69
|
+
function resolveLocalToolPath(targetPath) {
|
|
70
|
+
return (0, safe_workspace_1.resolveSafeRepoPath)({ requestedPath: targetPath }).resolvedPath;
|
|
71
|
+
}
|
|
72
|
+
const NO_SESSION_FOUND_MESSAGE = "no session found for that friend/channel/key combination.";
|
|
73
|
+
const EMPTY_SESSION_MESSAGE = "session exists but has no non-system messages.";
|
|
74
|
+
function findDelegatingBridgeId(ctx) {
|
|
75
|
+
const currentSession = ctx?.currentSession;
|
|
76
|
+
if (!currentSession)
|
|
77
|
+
return undefined;
|
|
78
|
+
return ctx?.activeBridges?.find((bridge) => bridge.lifecycle === "active"
|
|
79
|
+
&& bridge.attachedSessions.some((session) => session.friendId === currentSession.friendId
|
|
80
|
+
&& session.channel === currentSession.channel
|
|
81
|
+
&& session.key === currentSession.key))?.id;
|
|
82
|
+
}
|
|
83
|
+
async function recallSessionSafely(options) {
|
|
84
|
+
try {
|
|
85
|
+
return await (0, session_recall_1.recallSession)(options);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
if (options.summarize) {
|
|
89
|
+
(0, runtime_1.emitNervesEvent)({
|
|
90
|
+
component: "daemon",
|
|
91
|
+
event: "daemon.session_recall_summary_fallback",
|
|
92
|
+
message: "session recall summarization failed; using raw transcript",
|
|
93
|
+
meta: {
|
|
94
|
+
friendId: options.friendId,
|
|
95
|
+
channel: options.channel,
|
|
96
|
+
key: options.key,
|
|
97
|
+
error: error instanceof Error ? error.message : String(error),
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
try {
|
|
101
|
+
return await (0, session_recall_1.recallSession)({
|
|
102
|
+
...options,
|
|
103
|
+
summarize: undefined,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return { kind: "missing" };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { kind: "missing" };
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function normalizeProgressOutcome(text) {
|
|
114
|
+
const trimmed = text.trim();
|
|
115
|
+
if (!trimmed || trimmed === "nothing yet" || trimmed === "nothing recent") {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (trimmed.startsWith("\"") && trimmed.endsWith("\"") && trimmed.length >= 2) {
|
|
119
|
+
return trimmed.slice(1, -1);
|
|
120
|
+
}
|
|
121
|
+
return trimmed;
|
|
122
|
+
}
|
|
123
|
+
function writePendingEnvelope(queueDir, message) {
|
|
124
|
+
fs.mkdirSync(queueDir, { recursive: true });
|
|
125
|
+
const fileName = `${message.timestamp}-${Math.random().toString(36).slice(2, 10)}.json`;
|
|
126
|
+
const filePath = path.join(queueDir, fileName);
|
|
127
|
+
fs.writeFileSync(filePath, JSON.stringify(message, null, 2));
|
|
128
|
+
}
|
|
129
|
+
function renderCrossChatDeliveryStatus(target, result) {
|
|
130
|
+
const phase = result.status === "delivered_now"
|
|
131
|
+
? "completed"
|
|
132
|
+
: result.status === "queued_for_later"
|
|
133
|
+
? "queued"
|
|
134
|
+
: result.status === "blocked"
|
|
135
|
+
? "blocked"
|
|
136
|
+
: "errored";
|
|
137
|
+
const lead = result.status === "delivered_now"
|
|
138
|
+
? "delivered now"
|
|
139
|
+
: result.status === "queued_for_later"
|
|
140
|
+
? "queued for later"
|
|
141
|
+
: result.status === "blocked"
|
|
142
|
+
? "blocked"
|
|
143
|
+
: "failed";
|
|
144
|
+
return (0, progress_story_1.renderProgressStory)((0, progress_story_1.buildProgressStory)({
|
|
145
|
+
scope: "shared-work",
|
|
146
|
+
phase,
|
|
147
|
+
objective: `message to ${target}`,
|
|
148
|
+
outcomeText: `${lead}\n${result.detail}`,
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
function renderInnerProgressStatus(status) {
|
|
152
|
+
if (status.processing === "pending") {
|
|
153
|
+
return (0, progress_story_1.renderProgressStory)((0, progress_story_1.buildProgressStory)({
|
|
154
|
+
scope: "inner-delegation",
|
|
155
|
+
phase: "queued",
|
|
156
|
+
objective: status.queue,
|
|
157
|
+
outcomeText: `wake: ${status.wake}`,
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
if (status.processing === "started") {
|
|
161
|
+
return (0, progress_story_1.renderProgressStory)((0, progress_story_1.buildProgressStory)({
|
|
162
|
+
scope: "inner-delegation",
|
|
163
|
+
phase: "processing",
|
|
164
|
+
outcomeText: `wake: ${status.wake}`,
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
const completedOutcome = normalizeProgressOutcome(status.surfaced) ?? status.surfaced;
|
|
168
|
+
return (0, progress_story_1.renderProgressStory)((0, progress_story_1.buildProgressStory)({
|
|
169
|
+
scope: "inner-delegation",
|
|
170
|
+
phase: "completed",
|
|
171
|
+
objective: null,
|
|
172
|
+
outcomeText: completedOutcome,
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
49
175
|
exports.baseToolDefinitions = [
|
|
50
176
|
{
|
|
51
177
|
tool: {
|
|
@@ -55,12 +181,28 @@ exports.baseToolDefinitions = [
|
|
|
55
181
|
description: "read file contents",
|
|
56
182
|
parameters: {
|
|
57
183
|
type: "object",
|
|
58
|
-
properties: {
|
|
184
|
+
properties: {
|
|
185
|
+
path: { type: "string" },
|
|
186
|
+
offset: { type: "number", description: "1-based line number to start reading from" },
|
|
187
|
+
limit: { type: "number", description: "maximum number of lines to return" },
|
|
188
|
+
},
|
|
59
189
|
required: ["path"],
|
|
60
190
|
},
|
|
61
191
|
},
|
|
62
192
|
},
|
|
63
|
-
handler: (a) =>
|
|
193
|
+
handler: (a) => {
|
|
194
|
+
const resolvedPath = resolveLocalToolPath(a.path);
|
|
195
|
+
const content = fs.readFileSync(resolvedPath, "utf-8");
|
|
196
|
+
exports.editFileReadTracker.add(resolvedPath);
|
|
197
|
+
const offset = a.offset ? parseInt(a.offset, 10) : undefined;
|
|
198
|
+
const limit = a.limit ? parseInt(a.limit, 10) : undefined;
|
|
199
|
+
if (offset === undefined && limit === undefined)
|
|
200
|
+
return content;
|
|
201
|
+
const lines = content.split("\n");
|
|
202
|
+
const start = offset ? offset - 1 : 0;
|
|
203
|
+
const end = limit !== undefined ? start + limit : lines.length;
|
|
204
|
+
return lines.slice(start, end).join("\n");
|
|
205
|
+
},
|
|
64
206
|
},
|
|
65
207
|
{
|
|
66
208
|
tool: {
|
|
@@ -75,103 +217,215 @@ exports.baseToolDefinitions = [
|
|
|
75
217
|
},
|
|
76
218
|
},
|
|
77
219
|
},
|
|
78
|
-
handler: (a) =>
|
|
220
|
+
handler: (a) => {
|
|
221
|
+
const resolvedPath = resolveLocalToolPath(a.path);
|
|
222
|
+
fs.mkdirSync(path.dirname(resolvedPath), { recursive: true });
|
|
223
|
+
fs.writeFileSync(resolvedPath, a.content, "utf-8");
|
|
224
|
+
return "ok";
|
|
225
|
+
},
|
|
79
226
|
},
|
|
80
227
|
{
|
|
81
228
|
tool: {
|
|
82
229
|
type: "function",
|
|
83
230
|
function: {
|
|
84
|
-
name: "
|
|
85
|
-
description: "
|
|
231
|
+
name: "edit_file",
|
|
232
|
+
description: "surgically edit a file by replacing an exact string. the file must have been read via read_file first. old_string must match exactly one location in the file.",
|
|
86
233
|
parameters: {
|
|
87
234
|
type: "object",
|
|
88
|
-
properties: {
|
|
89
|
-
|
|
235
|
+
properties: {
|
|
236
|
+
path: { type: "string" },
|
|
237
|
+
old_string: { type: "string" },
|
|
238
|
+
new_string: { type: "string" },
|
|
239
|
+
},
|
|
240
|
+
required: ["path", "old_string", "new_string"],
|
|
90
241
|
},
|
|
91
242
|
},
|
|
92
243
|
},
|
|
93
|
-
handler: (a) =>
|
|
244
|
+
handler: (a) => {
|
|
245
|
+
const resolvedPath = resolveLocalToolPath(a.path);
|
|
246
|
+
if (!exports.editFileReadTracker.has(resolvedPath)) {
|
|
247
|
+
return `error: you must read the file with read_file before editing it. call read_file on ${a.path} first.`;
|
|
248
|
+
}
|
|
249
|
+
let content;
|
|
250
|
+
try {
|
|
251
|
+
content = fs.readFileSync(resolvedPath, "utf-8");
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
254
|
+
return `error: could not read file: ${e instanceof Error ? e.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(e)}`;
|
|
255
|
+
}
|
|
256
|
+
// Count occurrences
|
|
257
|
+
const occurrences = [];
|
|
258
|
+
let searchFrom = 0;
|
|
259
|
+
while (true) {
|
|
260
|
+
const idx = content.indexOf(a.old_string, searchFrom);
|
|
261
|
+
if (idx === -1)
|
|
262
|
+
break;
|
|
263
|
+
occurrences.push(idx);
|
|
264
|
+
searchFrom = idx + 1;
|
|
265
|
+
}
|
|
266
|
+
if (occurrences.length === 0) {
|
|
267
|
+
return `error: old_string not found in ${a.path}`;
|
|
268
|
+
}
|
|
269
|
+
if (occurrences.length > 1) {
|
|
270
|
+
return `error: old_string is ambiguous -- found ${occurrences.length} matches in ${a.path}. provide more context to make the match unique.`;
|
|
271
|
+
}
|
|
272
|
+
// Single unique match -- replace
|
|
273
|
+
const idx = occurrences[0];
|
|
274
|
+
const updated = content.slice(0, idx) + a.new_string + content.slice(idx + a.old_string.length);
|
|
275
|
+
fs.writeFileSync(resolvedPath, updated, "utf-8");
|
|
276
|
+
// Build contextual diff
|
|
277
|
+
const lines = updated.split("\n");
|
|
278
|
+
const prefixLines = content.slice(0, idx).split("\n");
|
|
279
|
+
const changeStartLine = prefixLines.length - 1;
|
|
280
|
+
const newStringLines = a.new_string.split("\n");
|
|
281
|
+
const changeEndLine = changeStartLine + newStringLines.length;
|
|
282
|
+
return buildContextDiff(lines, changeStartLine, changeEndLine);
|
|
283
|
+
},
|
|
94
284
|
},
|
|
95
285
|
{
|
|
96
286
|
tool: {
|
|
97
287
|
type: "function",
|
|
98
288
|
function: {
|
|
99
|
-
name: "
|
|
100
|
-
description: "
|
|
289
|
+
name: "glob",
|
|
290
|
+
description: "find files matching a glob pattern. returns matching paths sorted alphabetically, one per line.",
|
|
101
291
|
parameters: {
|
|
102
292
|
type: "object",
|
|
103
|
-
properties: {
|
|
104
|
-
|
|
293
|
+
properties: {
|
|
294
|
+
pattern: { type: "string", description: "glob pattern (e.g. **/*.ts)" },
|
|
295
|
+
cwd: { type: "string", description: "directory to search from (defaults to process.cwd())" },
|
|
296
|
+
},
|
|
297
|
+
required: ["pattern"],
|
|
105
298
|
},
|
|
106
299
|
},
|
|
107
300
|
},
|
|
108
|
-
handler: (a) =>
|
|
109
|
-
.
|
|
110
|
-
|
|
111
|
-
.join("\n")
|
|
301
|
+
handler: (a) => {
|
|
302
|
+
const cwd = a.cwd ? resolveLocalToolPath(a.cwd) : process.cwd();
|
|
303
|
+
const matches = fg.globSync(a.pattern, { cwd, dot: true });
|
|
304
|
+
return matches.sort().join("\n");
|
|
305
|
+
},
|
|
112
306
|
},
|
|
113
307
|
{
|
|
114
308
|
tool: {
|
|
115
309
|
type: "function",
|
|
116
310
|
function: {
|
|
117
|
-
name: "
|
|
118
|
-
description: "
|
|
311
|
+
name: "grep",
|
|
312
|
+
description: "search file contents for lines matching a regex pattern. searches recursively when given a directory. returns matching lines with file path and line numbers.",
|
|
119
313
|
parameters: {
|
|
120
314
|
type: "object",
|
|
121
315
|
properties: {
|
|
122
|
-
|
|
123
|
-
|
|
316
|
+
pattern: { type: "string", description: "regex pattern to search for" },
|
|
317
|
+
path: { type: "string", description: "file or directory to search" },
|
|
318
|
+
context_lines: { type: "number", description: "number of surrounding context lines (default 0)" },
|
|
319
|
+
include: { type: "string", description: "glob filter to limit searched files (e.g. *.ts)" },
|
|
124
320
|
},
|
|
125
|
-
required: ["
|
|
321
|
+
required: ["pattern", "path"],
|
|
126
322
|
},
|
|
127
323
|
},
|
|
128
324
|
},
|
|
129
325
|
handler: (a) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
326
|
+
const targetPath = resolveLocalToolPath(a.path);
|
|
327
|
+
const regex = new RegExp(a.pattern);
|
|
328
|
+
const contextLines = parseInt(a.context_lines || "0", 10);
|
|
329
|
+
const includeGlob = a.include || undefined;
|
|
330
|
+
function searchFile(filePath) {
|
|
331
|
+
let content;
|
|
332
|
+
try {
|
|
333
|
+
content = fs.readFileSync(filePath, "utf-8");
|
|
334
|
+
}
|
|
335
|
+
catch {
|
|
336
|
+
return [];
|
|
133
337
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
338
|
+
const lines = content.split("\n");
|
|
339
|
+
const matchIndices = new Set();
|
|
340
|
+
for (let i = 0; i < lines.length; i++) {
|
|
341
|
+
if (regex.test(lines[i])) {
|
|
342
|
+
matchIndices.add(i);
|
|
137
343
|
}
|
|
138
|
-
(0, child_process_1.execSync)(`git add ${p}`, { encoding: "utf-8" });
|
|
139
344
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
345
|
+
if (matchIndices.size === 0)
|
|
346
|
+
return [];
|
|
347
|
+
const outputIndices = new Set();
|
|
348
|
+
for (const idx of matchIndices) {
|
|
349
|
+
const start = Math.max(0, idx - contextLines);
|
|
350
|
+
const end = Math.min(lines.length - 1, idx + contextLines);
|
|
351
|
+
for (let i = start; i <= end; i++) {
|
|
352
|
+
outputIndices.add(i);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const sortedIndices = [...outputIndices].sort((a, b) => a - b);
|
|
356
|
+
const results = [];
|
|
357
|
+
for (const idx of sortedIndices) {
|
|
358
|
+
const lineNum = idx + 1;
|
|
359
|
+
if (matchIndices.has(idx)) {
|
|
360
|
+
results.push(`${filePath}:${lineNum}: ${lines[idx]}`);
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
results.push(`-${filePath}:${lineNum}: ${lines[idx]}`);
|
|
364
|
+
}
|
|
143
365
|
}
|
|
144
|
-
|
|
145
|
-
return `${diff}\ncommitted`;
|
|
366
|
+
return results;
|
|
146
367
|
}
|
|
147
|
-
|
|
148
|
-
|
|
368
|
+
function collectFiles(dirPath) {
|
|
369
|
+
const files = [];
|
|
370
|
+
function walk(dir) {
|
|
371
|
+
let entries;
|
|
372
|
+
try {
|
|
373
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
for (const entry of entries) {
|
|
379
|
+
const fullPath = path.join(dir, entry.name);
|
|
380
|
+
if (entry.isDirectory()) {
|
|
381
|
+
walk(fullPath);
|
|
382
|
+
}
|
|
383
|
+
else if (entry.isFile()) {
|
|
384
|
+
files.push(fullPath);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
walk(dirPath);
|
|
389
|
+
return files.sort();
|
|
390
|
+
}
|
|
391
|
+
function matchesGlob(filePath, glob) {
|
|
392
|
+
const escaped = glob
|
|
393
|
+
.replace(/[.+^${}()|[\]\\]/g, "\\$&")
|
|
394
|
+
.replace(/\*/g, ".*")
|
|
395
|
+
.replace(/\?/g, ".");
|
|
396
|
+
return new RegExp(`(^|/)${escaped}$`).test(filePath);
|
|
397
|
+
}
|
|
398
|
+
const stat = fs.statSync(targetPath, { throwIfNoEntry: false });
|
|
399
|
+
if (!stat)
|
|
400
|
+
return "";
|
|
401
|
+
if (stat.isFile()) {
|
|
402
|
+
return searchFile(targetPath).join("\n");
|
|
403
|
+
}
|
|
404
|
+
let files = collectFiles(targetPath);
|
|
405
|
+
if (includeGlob) {
|
|
406
|
+
files = files.filter((f) => matchesGlob(f, includeGlob));
|
|
149
407
|
}
|
|
408
|
+
const allResults = [];
|
|
409
|
+
for (const file of files) {
|
|
410
|
+
allResults.push(...searchFile(file));
|
|
411
|
+
}
|
|
412
|
+
return allResults.join("\n");
|
|
150
413
|
},
|
|
151
414
|
},
|
|
152
415
|
{
|
|
153
416
|
tool: {
|
|
154
417
|
type: "function",
|
|
155
418
|
function: {
|
|
156
|
-
name: "
|
|
157
|
-
description: "
|
|
419
|
+
name: "shell",
|
|
420
|
+
description: "run shell command",
|
|
158
421
|
parameters: {
|
|
159
422
|
type: "object",
|
|
160
|
-
properties: {
|
|
161
|
-
command: { type: "string" },
|
|
162
|
-
},
|
|
423
|
+
properties: { command: { type: "string" } },
|
|
163
424
|
required: ["command"],
|
|
164
425
|
},
|
|
165
426
|
},
|
|
166
427
|
},
|
|
167
|
-
handler: (a) => {
|
|
168
|
-
try {
|
|
169
|
-
return (0, child_process_1.execSync)(`gh ${a.command}`, { encoding: "utf-8", timeout: 60000 });
|
|
170
|
-
}
|
|
171
|
-
catch (e) {
|
|
172
|
-
return `error: ${e}`;
|
|
173
|
-
}
|
|
174
|
-
},
|
|
428
|
+
handler: (a) => (0, child_process_1.execSync)(a.command, { encoding: "utf-8", timeout: 30000 }),
|
|
175
429
|
},
|
|
176
430
|
{
|
|
177
431
|
tool: {
|
|
@@ -206,20 +460,6 @@ exports.baseToolDefinitions = [
|
|
|
206
460
|
}
|
|
207
461
|
},
|
|
208
462
|
},
|
|
209
|
-
{
|
|
210
|
-
tool: {
|
|
211
|
-
type: "function",
|
|
212
|
-
function: {
|
|
213
|
-
name: "get_current_time",
|
|
214
|
-
description: "get the current date and time in America/Los_Angeles (Pacific Time)",
|
|
215
|
-
parameters: { type: "object", properties: {} },
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
handler: () => new Date().toLocaleString("en-US", {
|
|
219
|
-
timeZone: "America/Los_Angeles",
|
|
220
|
-
hour12: false,
|
|
221
|
-
}),
|
|
222
|
-
},
|
|
223
463
|
{
|
|
224
464
|
tool: {
|
|
225
465
|
type: "function",
|
|
@@ -235,7 +475,7 @@ exports.baseToolDefinitions = [
|
|
|
235
475
|
},
|
|
236
476
|
handler: (a) => {
|
|
237
477
|
try {
|
|
238
|
-
const result = (0, child_process_1.spawnSync)("claude", ["-p", "--dangerously-skip-permissions", "--add-dir", "."], {
|
|
478
|
+
const result = (0, child_process_1.spawnSync)("claude", ["-p", "--no-session-persistence", "--dangerously-skip-permissions", "--add-dir", "."], {
|
|
239
479
|
input: a.prompt,
|
|
240
480
|
encoding: "utf-8",
|
|
241
481
|
timeout: 60000,
|
|
@@ -375,151 +615,6 @@ exports.baseToolDefinitions = [
|
|
|
375
615
|
return JSON.stringify(friend, null, 2);
|
|
376
616
|
},
|
|
377
617
|
},
|
|
378
|
-
{
|
|
379
|
-
tool: {
|
|
380
|
-
type: "function",
|
|
381
|
-
function: {
|
|
382
|
-
name: "task_board",
|
|
383
|
-
description: "show the task board grouped by status",
|
|
384
|
-
parameters: { type: "object", properties: {} },
|
|
385
|
-
},
|
|
386
|
-
},
|
|
387
|
-
handler: () => {
|
|
388
|
-
const board = (0, tasks_1.getTaskModule)().getBoard();
|
|
389
|
-
return board.full || board.compact || "no tasks found";
|
|
390
|
-
},
|
|
391
|
-
},
|
|
392
|
-
{
|
|
393
|
-
tool: {
|
|
394
|
-
type: "function",
|
|
395
|
-
function: {
|
|
396
|
-
name: "task_create",
|
|
397
|
-
description: "create a new task in the bundle task system",
|
|
398
|
-
parameters: {
|
|
399
|
-
type: "object",
|
|
400
|
-
properties: {
|
|
401
|
-
title: { type: "string" },
|
|
402
|
-
type: { type: "string", enum: ["one-shot", "ongoing", "habit"] },
|
|
403
|
-
category: { type: "string" },
|
|
404
|
-
body: { type: "string" },
|
|
405
|
-
},
|
|
406
|
-
required: ["title", "type", "category", "body"],
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
handler: (a) => {
|
|
411
|
-
try {
|
|
412
|
-
const created = (0, tasks_1.getTaskModule)().createTask({
|
|
413
|
-
title: a.title,
|
|
414
|
-
type: a.type,
|
|
415
|
-
category: a.category,
|
|
416
|
-
body: a.body,
|
|
417
|
-
});
|
|
418
|
-
return `created: ${created}`;
|
|
419
|
-
}
|
|
420
|
-
catch (error) {
|
|
421
|
-
return `error: ${error instanceof Error ? error.message : String(error)}`;
|
|
422
|
-
}
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
tool: {
|
|
427
|
-
type: "function",
|
|
428
|
-
function: {
|
|
429
|
-
name: "task_update_status",
|
|
430
|
-
description: "update a task status using validated transitions",
|
|
431
|
-
parameters: {
|
|
432
|
-
type: "object",
|
|
433
|
-
properties: {
|
|
434
|
-
name: { type: "string" },
|
|
435
|
-
status: { type: "string" },
|
|
436
|
-
},
|
|
437
|
-
required: ["name", "status"],
|
|
438
|
-
},
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
handler: (a) => {
|
|
442
|
-
const result = (0, tasks_1.getTaskModule)().updateStatus(a.name, a.status);
|
|
443
|
-
if (!result.ok) {
|
|
444
|
-
return `error: ${result.reason ?? "status update failed"}`;
|
|
445
|
-
}
|
|
446
|
-
const archivedSuffix = result.archived && result.archived.length > 0
|
|
447
|
-
? ` | archived: ${result.archived.join(", ")}`
|
|
448
|
-
: "";
|
|
449
|
-
return `updated: ${a.name} -> ${result.to}${archivedSuffix}`;
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
tool: {
|
|
454
|
-
type: "function",
|
|
455
|
-
function: {
|
|
456
|
-
name: "task_board_status",
|
|
457
|
-
description: "show board detail for a specific status",
|
|
458
|
-
parameters: {
|
|
459
|
-
type: "object",
|
|
460
|
-
properties: {
|
|
461
|
-
status: { type: "string" },
|
|
462
|
-
},
|
|
463
|
-
required: ["status"],
|
|
464
|
-
},
|
|
465
|
-
},
|
|
466
|
-
},
|
|
467
|
-
handler: (a) => {
|
|
468
|
-
const lines = (0, tasks_1.getTaskModule)().boardStatus(a.status);
|
|
469
|
-
return lines.length > 0 ? lines.join("\n") : "no tasks in that status";
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
{
|
|
473
|
-
tool: {
|
|
474
|
-
type: "function",
|
|
475
|
-
function: {
|
|
476
|
-
name: "task_board_action",
|
|
477
|
-
description: "show tasks or validation issues that require action",
|
|
478
|
-
parameters: {
|
|
479
|
-
type: "object",
|
|
480
|
-
properties: {
|
|
481
|
-
scope: { type: "string" },
|
|
482
|
-
},
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
},
|
|
486
|
-
handler: (a) => {
|
|
487
|
-
const lines = (0, tasks_1.getTaskModule)().boardAction();
|
|
488
|
-
if (!a.scope) {
|
|
489
|
-
return lines.length > 0 ? lines.join("\n") : "no action required";
|
|
490
|
-
}
|
|
491
|
-
const filtered = lines.filter((line) => line.includes(a.scope));
|
|
492
|
-
return filtered.length > 0 ? filtered.join("\n") : "no matching action items";
|
|
493
|
-
},
|
|
494
|
-
},
|
|
495
|
-
{
|
|
496
|
-
tool: {
|
|
497
|
-
type: "function",
|
|
498
|
-
function: {
|
|
499
|
-
name: "task_board_deps",
|
|
500
|
-
description: "show unresolved task dependencies",
|
|
501
|
-
parameters: { type: "object", properties: {} },
|
|
502
|
-
},
|
|
503
|
-
},
|
|
504
|
-
handler: () => {
|
|
505
|
-
const lines = (0, tasks_1.getTaskModule)().boardDeps();
|
|
506
|
-
return lines.length > 0 ? lines.join("\n") : "no unresolved dependencies";
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
tool: {
|
|
511
|
-
type: "function",
|
|
512
|
-
function: {
|
|
513
|
-
name: "task_board_sessions",
|
|
514
|
-
description: "show tasks with active coding or sub-agent sessions",
|
|
515
|
-
parameters: { type: "object", properties: {} },
|
|
516
|
-
},
|
|
517
|
-
},
|
|
518
|
-
handler: () => {
|
|
519
|
-
const lines = (0, tasks_1.getTaskModule)().boardSessions();
|
|
520
|
-
return lines.length > 0 ? lines.join("\n") : "no active sessions";
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
618
|
{
|
|
524
619
|
tool: {
|
|
525
620
|
type: "function",
|
|
@@ -604,6 +699,103 @@ exports.baseToolDefinitions = [
|
|
|
604
699
|
},
|
|
605
700
|
},
|
|
606
701
|
// -- cross-session awareness --
|
|
702
|
+
{
|
|
703
|
+
tool: {
|
|
704
|
+
type: "function",
|
|
705
|
+
function: {
|
|
706
|
+
name: "bridge_manage",
|
|
707
|
+
description: "create and manage shared live-work bridges across already-active sessions.",
|
|
708
|
+
parameters: {
|
|
709
|
+
type: "object",
|
|
710
|
+
properties: {
|
|
711
|
+
action: {
|
|
712
|
+
type: "string",
|
|
713
|
+
enum: ["begin", "attach", "status", "promote_task", "complete", "cancel"],
|
|
714
|
+
},
|
|
715
|
+
bridgeId: { type: "string", description: "bridge id for all actions except begin" },
|
|
716
|
+
objective: { type: "string", description: "objective for begin" },
|
|
717
|
+
summary: { type: "string", description: "optional concise shared-work summary" },
|
|
718
|
+
friendId: { type: "string", description: "target friend id for attach" },
|
|
719
|
+
channel: { type: "string", description: "target channel for attach" },
|
|
720
|
+
key: { type: "string", description: "target session key for attach (defaults to 'session')" },
|
|
721
|
+
title: { type: "string", description: "task title override for promote_task" },
|
|
722
|
+
category: { type: "string", description: "task category override for promote_task" },
|
|
723
|
+
body: { type: "string", description: "task body override for promote_task" },
|
|
724
|
+
},
|
|
725
|
+
required: ["action"],
|
|
726
|
+
},
|
|
727
|
+
},
|
|
728
|
+
},
|
|
729
|
+
handler: async (args, ctx) => {
|
|
730
|
+
const manager = (0, manager_1.createBridgeManager)();
|
|
731
|
+
const action = (args.action || "").trim();
|
|
732
|
+
if (action === "begin") {
|
|
733
|
+
if (!ctx?.currentSession) {
|
|
734
|
+
return "bridge_manage begin requires an active session context.";
|
|
735
|
+
}
|
|
736
|
+
const objective = (args.objective || "").trim();
|
|
737
|
+
if (!objective)
|
|
738
|
+
return "objective is required for bridge begin.";
|
|
739
|
+
return (0, manager_1.formatBridgeStatus)(manager.beginBridge({
|
|
740
|
+
objective,
|
|
741
|
+
summary: (args.summary || objective).trim(),
|
|
742
|
+
session: ctx.currentSession,
|
|
743
|
+
}));
|
|
744
|
+
}
|
|
745
|
+
const bridgeId = (args.bridgeId || "").trim();
|
|
746
|
+
if (!bridgeId) {
|
|
747
|
+
return "bridgeId is required for this bridge action.";
|
|
748
|
+
}
|
|
749
|
+
if (action === "attach") {
|
|
750
|
+
const friendId = (args.friendId || "").trim();
|
|
751
|
+
const channel = (args.channel || "").trim();
|
|
752
|
+
const key = (args.key || "session").trim();
|
|
753
|
+
if (!friendId || !channel) {
|
|
754
|
+
return "friendId and channel are required for bridge attach.";
|
|
755
|
+
}
|
|
756
|
+
const sessionPath = (0, config_1.resolveSessionPath)(friendId, channel, key);
|
|
757
|
+
const recall = await recallSessionSafely({
|
|
758
|
+
sessionPath,
|
|
759
|
+
friendId,
|
|
760
|
+
channel,
|
|
761
|
+
key,
|
|
762
|
+
messageCount: 20,
|
|
763
|
+
trustLevel: ctx?.context?.friend?.trustLevel,
|
|
764
|
+
summarize: ctx?.summarize,
|
|
765
|
+
});
|
|
766
|
+
if (recall.kind === "missing") {
|
|
767
|
+
return NO_SESSION_FOUND_MESSAGE;
|
|
768
|
+
}
|
|
769
|
+
return (0, manager_1.formatBridgeStatus)(manager.attachSession(bridgeId, {
|
|
770
|
+
friendId,
|
|
771
|
+
channel,
|
|
772
|
+
key,
|
|
773
|
+
sessionPath,
|
|
774
|
+
snapshot: recall.kind === "ok" ? recall.snapshot : EMPTY_SESSION_MESSAGE,
|
|
775
|
+
}));
|
|
776
|
+
}
|
|
777
|
+
if (action === "status") {
|
|
778
|
+
const bridge = manager.getBridge(bridgeId);
|
|
779
|
+
if (!bridge)
|
|
780
|
+
return `bridge not found: ${bridgeId}`;
|
|
781
|
+
return (0, manager_1.formatBridgeStatus)(bridge);
|
|
782
|
+
}
|
|
783
|
+
if (action === "promote_task") {
|
|
784
|
+
return (0, manager_1.formatBridgeStatus)(manager.promoteBridgeToTask(bridgeId, {
|
|
785
|
+
title: args.title,
|
|
786
|
+
category: args.category,
|
|
787
|
+
body: args.body,
|
|
788
|
+
}));
|
|
789
|
+
}
|
|
790
|
+
if (action === "complete") {
|
|
791
|
+
return (0, manager_1.formatBridgeStatus)(manager.completeBridge(bridgeId));
|
|
792
|
+
}
|
|
793
|
+
if (action === "cancel") {
|
|
794
|
+
return (0, manager_1.formatBridgeStatus)(manager.cancelBridge(bridgeId));
|
|
795
|
+
}
|
|
796
|
+
return `unknown bridge action: ${action}`;
|
|
797
|
+
},
|
|
798
|
+
},
|
|
607
799
|
{
|
|
608
800
|
tool: {
|
|
609
801
|
type: "function",
|
|
@@ -617,40 +809,43 @@ exports.baseToolDefinitions = [
|
|
|
617
809
|
channel: { type: "string", description: "the channel: cli, teams, or inner" },
|
|
618
810
|
key: { type: "string", description: "session key (defaults to 'session')" },
|
|
619
811
|
messageCount: { type: "string", description: "how many recent messages to return (default 20)" },
|
|
812
|
+
mode: { type: "string", enum: ["transcript", "status"], description: "transcript (default) or lightweight status for self/inner checks" },
|
|
620
813
|
},
|
|
621
814
|
required: ["friendId", "channel"],
|
|
622
815
|
},
|
|
623
816
|
},
|
|
624
817
|
},
|
|
625
818
|
handler: async (args, ctx) => {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const messages = (data.messages || [])
|
|
635
|
-
.filter((m) => m.role !== "system");
|
|
636
|
-
const tail = messages.slice(-count);
|
|
637
|
-
if (tail.length === 0)
|
|
638
|
-
return "session exists but has no non-system messages.";
|
|
639
|
-
const transcript = tail.map((m) => `[${m.role}] ${m.content}`).join("\n");
|
|
640
|
-
// LLM summarization when summarize function is available
|
|
641
|
-
if (ctx?.summarize) {
|
|
642
|
-
const trustLevel = ctx.context?.friend?.trustLevel ?? "family";
|
|
643
|
-
const isSelfQuery = friendId === "self";
|
|
644
|
-
const instruction = isSelfQuery
|
|
645
|
-
? "summarize this session transcript fully and transparently. this is my own inner dialog — include all details, decisions, and reasoning."
|
|
646
|
-
: `summarize this session transcript. the person asking has trust level: ${trustLevel}. family=full transparency, friend=share work and general topics but protect other people's identities, acquaintance=very guarded minimal disclosure.`;
|
|
647
|
-
return await ctx.summarize(transcript, instruction);
|
|
819
|
+
const friendId = args.friendId;
|
|
820
|
+
const channel = args.channel;
|
|
821
|
+
const key = args.key || "session";
|
|
822
|
+
const count = parseInt(args.messageCount || "20", 10);
|
|
823
|
+
const mode = args.mode || "transcript";
|
|
824
|
+
if (mode === "status") {
|
|
825
|
+
if (friendId !== "self" || channel !== "inner") {
|
|
826
|
+
return "status mode is only available for self/inner dialog.";
|
|
648
827
|
}
|
|
649
|
-
|
|
828
|
+
const sessionPath = (0, thoughts_1.getInnerDialogSessionPath)((0, identity_1.getAgentRoot)());
|
|
829
|
+
const pendingDir = (0, pending_1.getInnerDialogPendingDir)((0, identity_1.getAgentName)());
|
|
830
|
+
return renderInnerProgressStatus((0, thoughts_1.readInnerDialogStatus)(sessionPath, pendingDir));
|
|
650
831
|
}
|
|
651
|
-
|
|
652
|
-
|
|
832
|
+
const sessFile = (0, config_1.resolveSessionPath)(friendId, channel, key);
|
|
833
|
+
const recall = await recallSessionSafely({
|
|
834
|
+
sessionPath: sessFile,
|
|
835
|
+
friendId,
|
|
836
|
+
channel,
|
|
837
|
+
key,
|
|
838
|
+
messageCount: count,
|
|
839
|
+
trustLevel: ctx?.context?.friend?.trustLevel,
|
|
840
|
+
summarize: ctx?.summarize,
|
|
841
|
+
});
|
|
842
|
+
if (recall.kind === "missing") {
|
|
843
|
+
return NO_SESSION_FOUND_MESSAGE;
|
|
844
|
+
}
|
|
845
|
+
if (recall.kind === "empty") {
|
|
846
|
+
return EMPTY_SESSION_MESSAGE;
|
|
653
847
|
}
|
|
848
|
+
return recall.summary;
|
|
654
849
|
},
|
|
655
850
|
},
|
|
656
851
|
{
|
|
@@ -658,7 +853,7 @@ exports.baseToolDefinitions = [
|
|
|
658
853
|
type: "function",
|
|
659
854
|
function: {
|
|
660
855
|
name: "send_message",
|
|
661
|
-
description: "send a message to a friend's session. the
|
|
856
|
+
description: "send a message to a friend's session. when the request is explicitly authorized from a trusted live chat, the harness will try to deliver immediately; otherwise it reports truthful queued/block/failure state.",
|
|
662
857
|
parameters: {
|
|
663
858
|
type: "object",
|
|
664
859
|
properties: {
|
|
@@ -671,35 +866,215 @@ exports.baseToolDefinitions = [
|
|
|
671
866
|
},
|
|
672
867
|
},
|
|
673
868
|
},
|
|
674
|
-
handler: async (args) => {
|
|
869
|
+
handler: async (args, ctx) => {
|
|
675
870
|
const friendId = args.friendId;
|
|
676
871
|
const channel = args.channel;
|
|
677
872
|
const key = args.key || "session";
|
|
678
873
|
const content = args.content;
|
|
679
874
|
const now = Date.now();
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
const
|
|
875
|
+
const agentName = (0, identity_1.getAgentName)();
|
|
876
|
+
// Self-routing: messages to "self" always go to inner dialog pending dir,
|
|
877
|
+
// regardless of the channel or key the agent specified.
|
|
878
|
+
const isSelf = friendId === "self";
|
|
879
|
+
const pendingDir = isSelf
|
|
880
|
+
? (0, pending_1.getInnerDialogPendingDir)(agentName)
|
|
881
|
+
: (0, pending_1.getPendingDir)(agentName, friendId, channel, key);
|
|
882
|
+
const delegatingBridgeId = findDelegatingBridgeId(ctx);
|
|
883
|
+
const delegatedFrom = isSelf
|
|
884
|
+
&& ctx?.currentSession
|
|
885
|
+
&& !(ctx.currentSession.friendId === "self" && ctx.currentSession.channel === "inner")
|
|
886
|
+
? {
|
|
887
|
+
friendId: ctx.currentSession.friendId,
|
|
888
|
+
channel: ctx.currentSession.channel,
|
|
889
|
+
key: ctx.currentSession.key,
|
|
890
|
+
...(delegatingBridgeId ? { bridgeId: delegatingBridgeId } : {}),
|
|
891
|
+
}
|
|
892
|
+
: undefined;
|
|
684
893
|
const envelope = {
|
|
685
|
-
from:
|
|
894
|
+
from: agentName,
|
|
686
895
|
friendId,
|
|
687
896
|
channel,
|
|
688
897
|
key,
|
|
689
898
|
content,
|
|
690
899
|
timestamp: now,
|
|
900
|
+
...(delegatedFrom ? { delegatedFrom } : {}),
|
|
691
901
|
};
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
902
|
+
if (isSelf) {
|
|
903
|
+
writePendingEnvelope(pendingDir, envelope);
|
|
904
|
+
let wakeResponse = null;
|
|
905
|
+
try {
|
|
906
|
+
wakeResponse = await (0, socket_client_1.requestInnerWake)(agentName);
|
|
907
|
+
}
|
|
908
|
+
catch {
|
|
909
|
+
wakeResponse = null;
|
|
910
|
+
}
|
|
911
|
+
if (!wakeResponse?.ok) {
|
|
912
|
+
const { runInnerDialogTurn } = await Promise.resolve().then(() => __importStar(require("../senses/inner-dialog")));
|
|
913
|
+
if (ctx?.context?.channel.channel === "inner") {
|
|
914
|
+
queueMicrotask(() => {
|
|
915
|
+
void runInnerDialogTurn({ reason: "instinct" });
|
|
916
|
+
});
|
|
917
|
+
return renderInnerProgressStatus({
|
|
918
|
+
queue: "queued to inner/dialog",
|
|
919
|
+
wake: "inline scheduled",
|
|
920
|
+
processing: "pending",
|
|
921
|
+
surfaced: "nothing yet",
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
else {
|
|
925
|
+
const turnResult = await runInnerDialogTurn({ reason: "instinct" });
|
|
926
|
+
const surfacedPreview = normalizeProgressOutcome((0, thoughts_1.formatSurfacedValue)((0, thoughts_1.extractThoughtResponseFromMessages)(turnResult?.messages ?? [])));
|
|
927
|
+
return (0, progress_story_1.renderProgressStory)((0, progress_story_1.buildProgressStory)({
|
|
928
|
+
scope: "inner-delegation",
|
|
929
|
+
phase: "completed",
|
|
930
|
+
objective: "queued to inner/dialog",
|
|
931
|
+
outcomeText: `wake: inline fallback\n${surfacedPreview}`,
|
|
932
|
+
}));
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return renderInnerProgressStatus({
|
|
936
|
+
queue: "queued to inner/dialog",
|
|
937
|
+
wake: "daemon requested",
|
|
938
|
+
processing: "pending",
|
|
939
|
+
surfaced: "nothing yet",
|
|
940
|
+
});
|
|
941
|
+
}
|
|
942
|
+
const deliveryResult = await (0, cross_chat_delivery_1.deliverCrossChatMessage)({
|
|
943
|
+
friendId,
|
|
944
|
+
channel,
|
|
945
|
+
key,
|
|
946
|
+
content,
|
|
947
|
+
intent: ctx?.currentSession && ctx.currentSession.friendId !== "self"
|
|
948
|
+
? "explicit_cross_chat"
|
|
949
|
+
: "generic_outreach",
|
|
950
|
+
...(ctx?.currentSession && ctx.currentSession.friendId !== "self"
|
|
951
|
+
? {
|
|
952
|
+
authorizingSession: {
|
|
953
|
+
friendId: ctx.currentSession.friendId,
|
|
954
|
+
channel: ctx.currentSession.channel,
|
|
955
|
+
key: ctx.currentSession.key,
|
|
956
|
+
trustLevel: ctx?.context?.friend?.trustLevel,
|
|
957
|
+
},
|
|
958
|
+
}
|
|
959
|
+
: {}),
|
|
960
|
+
}, {
|
|
961
|
+
agentName,
|
|
962
|
+
queuePending: (message) => writePendingEnvelope(pendingDir, message),
|
|
963
|
+
deliverers: {
|
|
964
|
+
bluebubbles: async (request) => {
|
|
965
|
+
const { sendProactiveBlueBubblesMessageToSession } = await Promise.resolve().then(() => __importStar(require("../senses/bluebubbles")));
|
|
966
|
+
const result = await sendProactiveBlueBubblesMessageToSession({
|
|
967
|
+
friendId: request.friendId,
|
|
968
|
+
sessionKey: request.key,
|
|
969
|
+
text: request.content,
|
|
970
|
+
intent: request.intent,
|
|
971
|
+
authorizingSession: request.authorizingSession,
|
|
972
|
+
});
|
|
973
|
+
if (result.delivered) {
|
|
974
|
+
return {
|
|
975
|
+
status: "delivered_now",
|
|
976
|
+
detail: "sent to the active bluebubbles chat now",
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
if (result.reason === "missing_target") {
|
|
980
|
+
return {
|
|
981
|
+
status: "blocked",
|
|
982
|
+
detail: "bluebubbles could not resolve a routable target for that session",
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
if (result.reason === "send_error") {
|
|
986
|
+
return {
|
|
987
|
+
status: "failed",
|
|
988
|
+
detail: "bluebubbles send failed",
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
return {
|
|
992
|
+
status: "unavailable",
|
|
993
|
+
detail: "live delivery unavailable right now; queued for the next active turn",
|
|
994
|
+
};
|
|
995
|
+
},
|
|
996
|
+
teams: async (request) => {
|
|
997
|
+
if (!ctx?.botApi) {
|
|
998
|
+
return {
|
|
999
|
+
status: "unavailable",
|
|
1000
|
+
detail: "live delivery unavailable right now; queued for the next active turn",
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
const { sendProactiveTeamsMessageToSession } = await Promise.resolve().then(() => __importStar(require("../senses/teams")));
|
|
1004
|
+
const result = await sendProactiveTeamsMessageToSession({
|
|
1005
|
+
friendId: request.friendId,
|
|
1006
|
+
sessionKey: request.key,
|
|
1007
|
+
text: request.content,
|
|
1008
|
+
intent: request.intent,
|
|
1009
|
+
authorizingSession: request.authorizingSession,
|
|
1010
|
+
}, {
|
|
1011
|
+
botApi: ctx.botApi,
|
|
1012
|
+
});
|
|
1013
|
+
if (result.delivered) {
|
|
1014
|
+
return {
|
|
1015
|
+
status: "delivered_now",
|
|
1016
|
+
detail: "sent to the active teams chat now",
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
if (result.reason === "missing_target") {
|
|
1020
|
+
return {
|
|
1021
|
+
status: "blocked",
|
|
1022
|
+
detail: "teams could not resolve a routable target for that session",
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
if (result.reason === "send_error") {
|
|
1026
|
+
return {
|
|
1027
|
+
status: "failed",
|
|
1028
|
+
detail: "teams send failed",
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
return {
|
|
1032
|
+
status: "unavailable",
|
|
1033
|
+
detail: "live delivery unavailable right now; queued for the next active turn",
|
|
1034
|
+
};
|
|
1035
|
+
},
|
|
1036
|
+
},
|
|
1037
|
+
});
|
|
1038
|
+
return renderCrossChatDeliveryStatus(`${friendId} on ${channel}/${key}`, deliveryResult);
|
|
1039
|
+
},
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
tool: {
|
|
1043
|
+
type: "function",
|
|
1044
|
+
function: {
|
|
1045
|
+
name: "set_reasoning_effort",
|
|
1046
|
+
description: "adjust your own reasoning depth for subsequent turns. use higher effort for complex analysis, lower for simple tasks.",
|
|
1047
|
+
parameters: {
|
|
1048
|
+
type: "object",
|
|
1049
|
+
properties: {
|
|
1050
|
+
level: { type: "string", description: "the reasoning effort level to set" },
|
|
1051
|
+
},
|
|
1052
|
+
required: ["level"],
|
|
1053
|
+
},
|
|
1054
|
+
},
|
|
695
1055
|
},
|
|
1056
|
+
handler: (args, ctx) => {
|
|
1057
|
+
if (!ctx?.supportedReasoningEfforts || !ctx.setReasoningEffort) {
|
|
1058
|
+
return "reasoning effort adjustment is not available in this context.";
|
|
1059
|
+
}
|
|
1060
|
+
const level = (args.level || "").trim();
|
|
1061
|
+
if (!ctx.supportedReasoningEfforts.includes(level)) {
|
|
1062
|
+
return `invalid reasoning effort level "${level}". accepted levels: ${ctx.supportedReasoningEfforts.join(", ")}`;
|
|
1063
|
+
}
|
|
1064
|
+
ctx.setReasoningEffort(level);
|
|
1065
|
+
(0, runtime_1.emitNervesEvent)({
|
|
1066
|
+
component: "repertoire",
|
|
1067
|
+
event: "repertoire.reasoning_effort_changed",
|
|
1068
|
+
message: `reasoning effort set to ${level}`,
|
|
1069
|
+
meta: { level },
|
|
1070
|
+
});
|
|
1071
|
+
return `reasoning effort set to "${level}".`;
|
|
1072
|
+
},
|
|
1073
|
+
requiredCapability: "reasoning-effort",
|
|
696
1074
|
},
|
|
697
1075
|
...tools_1.codingToolDefinitions,
|
|
698
1076
|
];
|
|
699
|
-
// Backward-compat: extract just the OpenAI tool schemas
|
|
700
1077
|
exports.tools = exports.baseToolDefinitions.map((d) => d.tool);
|
|
701
|
-
// Backward-compat: extract just the handlers by name
|
|
702
|
-
exports.baseToolHandlers = Object.fromEntries(exports.baseToolDefinitions.map((d) => [d.tool.function.name, d.handler]));
|
|
703
1078
|
exports.finalAnswerTool = {
|
|
704
1079
|
type: "function",
|
|
705
1080
|
function: {
|
|
@@ -707,7 +1082,10 @@ exports.finalAnswerTool = {
|
|
|
707
1082
|
description: "respond to the user with your message. call this tool when you are ready to deliver your response.",
|
|
708
1083
|
parameters: {
|
|
709
1084
|
type: "object",
|
|
710
|
-
properties: {
|
|
1085
|
+
properties: {
|
|
1086
|
+
answer: { type: "string" },
|
|
1087
|
+
intent: { type: "string", enum: ["complete", "blocked", "direct_reply"] },
|
|
1088
|
+
},
|
|
711
1089
|
required: ["answer"],
|
|
712
1090
|
},
|
|
713
1091
|
},
|