negotium 0.23.8 → 0.23.9
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/dist/agent-helpers.js +4 -3
- package/dist/agent-helpers.js.map +4 -4
- package/dist/{chunk-g5etvfj3.js → chunk-jsv1te9a.js} +2 -2
- package/dist/{chunk-g5etvfj3.js.map → chunk-jsv1te9a.js.map} +2 -2
- package/dist/hosted-agent.js +2 -2
- package/dist/hosted-agent.js.map +2 -2
- package/dist/main.js +477 -338
- package/dist/main.js.map +12 -8
- package/dist/mcp-factories.js +310 -255
- package/dist/mcp-factories.js.map +10 -7
- package/dist/prompts.js +3 -2
- package/dist/prompts.js.map +3 -3
- package/dist/registry.js +1 -1
- package/dist/runtime/src/mcp/factories/session-comm.ts +16 -2
- package/dist/runtime/src/mcp/factories/session-history.ts +21 -306
- package/dist/runtime/src/mcp/session-comm/default-host.ts +14 -0
- package/dist/runtime/src/mcp/session-comm/history-target.ts +89 -0
- package/dist/runtime/src/mcp/session-comm/history-tools.ts +113 -0
- package/dist/runtime/src/mcp/session-comm/server.ts +16 -2
- package/dist/runtime/src/mcp/session-history-limits.ts +36 -0
- package/dist/runtime/src/mcp/session-history-reader.ts +359 -0
- package/dist/runtime/src/mcp/session-history-server.ts +2 -10
- package/dist/runtime/src/prompts/builders.ts +2 -1
- package/dist/runtime/src/version.ts +1 -1
- package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +6 -0
- package/dist/types/packages/core/src/mcp/session-comm/history-tools.d.ts +31 -0
- package/dist/types/packages/core/src/mcp/session-history-limits.d.ts +20 -0
- package/dist/types/packages/core/src/mcp/session-history-reader.d.ts +35 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/mcp-factories.js
CHANGED
|
@@ -5359,7 +5359,7 @@ var init_codex = __esm(async () => {
|
|
|
5359
5359
|
});
|
|
5360
5360
|
|
|
5361
5361
|
// ../../packages/core/src/version.ts
|
|
5362
|
-
var NEGOTIUM_VERSION = "0.23.
|
|
5362
|
+
var NEGOTIUM_VERSION = "0.23.9";
|
|
5363
5363
|
|
|
5364
5364
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
5365
5365
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -12862,8 +12862,9 @@ function buildRuntimeToolSection(opts, extensions) {
|
|
|
12862
12862
|
"The session-comm MCP server is the only cross-topic messaging surface. Its canonical tools are `list_sessions`, `peek_session`, `tell_session`, `ask_session`, and `abort_session`.",
|
|
12863
12863
|
"`list_sessions` inspects topics; `ask_session` is for read-only questions whose answer must return here; `tell_session` is one-way delegation/handoff with no reply back. Do not call `tell_session` bidirectional, and do not claim `ask_session` is unavailable without first checking the session-comm tools."
|
|
12864
12864
|
],
|
|
12865
|
+
"To hand over context, point instead of pasting: in `tell_session`/`ask_session`, state the instruction and cite the relevant part of your own history (an entry range from `list_session_boundaries`, or a `sessionId`) rather than copying long transcripts. A session that receives such a message (`[from <topic>]`) reads the sender's history with `read_session_history_of`/`search_session_history_of` (`to` = the sender as `list_sessions` shows it). Only sessions listed by `list_sessions` are readable; if the sender is not listed, ask for the details instead.",
|
|
12865
12866
|
...agentKind === "maestro" ? [
|
|
12866
|
-
subagentParentTitle ? "Session-comm schemas may initially be deferred. Activate `mcp__session-comm__list_sessions` and `mcp__session-comm__tell_session` with ToolSearch before use." : 'Session-comm schemas may initially be deferred. Before using or judging availability, call ToolSearch("select:mcp__session-comm__list_sessions,mcp__session-comm__peek_session,mcp__session-comm__tell_session,mcp__session-comm__ask_session,mcp__session-comm__abort_session") to activate the exact tools. Never substitute a similarly described runtime tool.'
|
|
12867
|
+
subagentParentTitle ? "Session-comm schemas may initially be deferred. Activate `mcp__session-comm__list_sessions` and `mcp__session-comm__tell_session` with ToolSearch before use." : 'Session-comm schemas may initially be deferred. Before using or judging availability, call ToolSearch("select:mcp__session-comm__list_sessions,mcp__session-comm__peek_session,mcp__session-comm__tell_session,mcp__session-comm__ask_session,mcp__session-comm__abort_session,mcp__session-comm__read_session_history_of,mcp__session-comm__search_session_history_of") to activate the exact tools. Never substitute a similarly described runtime tool.'
|
|
12867
12868
|
] : [],
|
|
12868
12869
|
"Do not use session communication to make another topic perform destructive changes without the user's clear intent.",
|
|
12869
12870
|
...spawnSubagentSection,
|
|
@@ -14204,12 +14205,12 @@ function deleteTopicStats(userId, topicId) {
|
|
|
14204
14205
|
logger.warn({ err: e, userId, topicId }, "token-stats: Failed to delete topic stats");
|
|
14205
14206
|
}
|
|
14206
14207
|
}
|
|
14207
|
-
function getStats(userId, from,
|
|
14208
|
+
function getStats(userId, from, to2) {
|
|
14208
14209
|
const records = loadRecords(userId);
|
|
14209
14210
|
const fromTs = from ? new Date(from).getTime() : 0;
|
|
14210
|
-
const toTs =
|
|
14211
|
-
if (from && Number.isNaN(fromTs) ||
|
|
14212
|
-
logger.warn({ from, to }, "token-stats: Invalid date range, returning empty");
|
|
14211
|
+
const toTs = to2 ? new Date(to2).getTime() : Infinity;
|
|
14212
|
+
if (from && Number.isNaN(fromTs) || to2 && Number.isNaN(toTs)) {
|
|
14213
|
+
logger.warn({ from, to: to2 }, "token-stats: Invalid date range, returning empty");
|
|
14213
14214
|
return {
|
|
14214
14215
|
total: emptyBucket(),
|
|
14215
14216
|
byHour: {},
|
|
@@ -16025,14 +16026,14 @@ function parsePendingAsks(value2) {
|
|
|
16025
16026
|
for (const entry of value2) {
|
|
16026
16027
|
if (!isPlainRecord(entry))
|
|
16027
16028
|
return null;
|
|
16028
|
-
const { to, requestId, status } = entry;
|
|
16029
|
-
if (typeof
|
|
16029
|
+
const { to: to2, requestId, status } = entry;
|
|
16030
|
+
if (typeof to2 !== "string" || !to2.trim())
|
|
16030
16031
|
return null;
|
|
16031
16032
|
if (typeof requestId !== "string" || !requestId.trim())
|
|
16032
16033
|
return null;
|
|
16033
16034
|
if (status !== "forwarded" && status !== "reply_pending")
|
|
16034
16035
|
return null;
|
|
16035
|
-
asks.push({ to, requestId, status });
|
|
16036
|
+
asks.push({ to: to2, requestId, status });
|
|
16036
16037
|
}
|
|
16037
16038
|
return asks;
|
|
16038
16039
|
}
|
|
@@ -16505,8 +16506,8 @@ function deletePendingAsksForTopic(args) {
|
|
|
16505
16506
|
to: parsed?.to ?? ""
|
|
16506
16507
|
});
|
|
16507
16508
|
const from = record?.from ?? parsed?.from;
|
|
16508
|
-
const
|
|
16509
|
-
if (from !== args.topicName &&
|
|
16509
|
+
const to2 = record?.to ?? parsed?.to;
|
|
16510
|
+
if (from !== args.topicName && to2 !== args.topicName)
|
|
16510
16511
|
continue;
|
|
16511
16512
|
try {
|
|
16512
16513
|
unlinkSync17(path);
|
|
@@ -18298,7 +18299,7 @@ var init_ask_user_gates = __esm(async () => {
|
|
|
18298
18299
|
|
|
18299
18300
|
// ../../packages/core/src/agents/mcp-tools/ask-user.ts
|
|
18300
18301
|
import { createHash as createHash11, randomUUID as randomUUID16 } from "crypto";
|
|
18301
|
-
import { z as
|
|
18302
|
+
import { z as z5 } from "zod";
|
|
18302
18303
|
function normalizeAskText(value2, maxChars) {
|
|
18303
18304
|
if (typeof value2 !== "string")
|
|
18304
18305
|
return;
|
|
@@ -18591,12 +18592,12 @@ function createAskUserRuntime(host) {
|
|
|
18591
18592
|
name: "ask_user_question",
|
|
18592
18593
|
description: "Ask the user a blocking multiple-choice question in the chat and wait for their selection. Use this instead of provider built-in AskUserQuestion. Use only when you cannot proceed safely without the user's choice.",
|
|
18593
18594
|
schema: {
|
|
18594
|
-
question:
|
|
18595
|
-
choices:
|
|
18596
|
-
label:
|
|
18597
|
-
description:
|
|
18595
|
+
question: z5.string().describe("The concise question to show to the user."),
|
|
18596
|
+
choices: z5.array(z5.object({
|
|
18597
|
+
label: z5.string().describe("Choice label shown on the button."),
|
|
18598
|
+
description: z5.string().optional().describe("Optional one-sentence consequence.")
|
|
18598
18599
|
})).min(1).max(MAX_CHOICES).describe("Choices the user can select."),
|
|
18599
|
-
idempotency_key:
|
|
18600
|
+
idempotency_key: z5.string().max(MAX_IDEMPOTENCY_KEY_CHARS).optional().describe("Optional retry key. Reusing it with the same question replays the existing result; reusing it with different content fails.")
|
|
18600
18601
|
},
|
|
18601
18602
|
async handler(input) {
|
|
18602
18603
|
return askUserQuestion(ctx, input);
|
|
@@ -18868,7 +18869,7 @@ var init_vault_request_gates = __esm(async () => {
|
|
|
18868
18869
|
|
|
18869
18870
|
// ../../packages/core/src/agents/mcp-tools/request-vault.ts
|
|
18870
18871
|
import { createHash as createHash12, randomUUID as randomUUID17 } from "crypto";
|
|
18871
|
-
import { z as
|
|
18872
|
+
import { z as z6 } from "zod";
|
|
18872
18873
|
function requestBodyHash(key, description) {
|
|
18873
18874
|
return createHash12("sha256").update(JSON.stringify({ key, description })).digest("hex");
|
|
18874
18875
|
}
|
|
@@ -19135,10 +19136,10 @@ function createRequestVaultRuntime(host) {
|
|
|
19135
19136
|
name: "request_vault_secret",
|
|
19136
19137
|
description: "Ask the user to store a secret value in their Vault. You choose the key name and a short description of what to paste; the user types only the value on a surface that can mask it, and you never see the raw value. Use this instead of asking the user to paste a secret directly into chat. After it succeeds, reference the value as {{KEY}} in supported transient tool inputs. Fails if the key already exists unless you pass overwrite: true.",
|
|
19137
19138
|
schema: {
|
|
19138
|
-
key:
|
|
19139
|
-
description:
|
|
19140
|
-
overwrite:
|
|
19141
|
-
idempotency_key:
|
|
19139
|
+
key: z6.string().describe("Vault key name, e.g. STRIPE_API_KEY. Letters/digits/underscores, must start with a letter."),
|
|
19140
|
+
description: z6.string().max(MAX_DESCRIPTION_CHARS).describe("One sentence telling the user what value to paste and where it's from."),
|
|
19141
|
+
overwrite: z6.boolean().optional().describe("Set true to replace the value of a key that already exists. Defaults to false, which fails instead of silently clobbering an existing secret."),
|
|
19142
|
+
idempotency_key: z6.string().max(MAX_IDEMPOTENCY_KEY_CHARS2).optional().describe("Optional retry key. Reusing it with the same key/description replays the existing result; reusing it with different content fails.")
|
|
19142
19143
|
},
|
|
19143
19144
|
async handler(input) {
|
|
19144
19145
|
return requestVaultSecret(ctx, input);
|
|
@@ -19175,7 +19176,7 @@ function createRequestVaultRuntime(host) {
|
|
|
19175
19176
|
name: "delete_vault_secret",
|
|
19176
19177
|
description: "Permanently delete a key from the user's Vault. This removes the stored value outright \u2014 there is no confirmation step and no undo. Use request_vault_secret with overwrite: true instead if the goal is just to replace a value.",
|
|
19177
19178
|
schema: {
|
|
19178
|
-
key:
|
|
19179
|
+
key: z6.string().describe("Vault key name to delete, e.g. STRIPE_API_KEY.")
|
|
19179
19180
|
},
|
|
19180
19181
|
async handler(input) {
|
|
19181
19182
|
return deleteVaultSecret(ctx, input);
|
|
@@ -22000,7 +22001,7 @@ var init_auth_check = __esm(async () => {
|
|
|
22000
22001
|
});
|
|
22001
22002
|
|
|
22002
22003
|
// ../../packages/core/src/agents/mcp-tools/spawn-subagent.ts
|
|
22003
|
-
import { z as
|
|
22004
|
+
import { z as z7 } from "zod";
|
|
22004
22005
|
function activeQueryUserId(topic) {
|
|
22005
22006
|
return topic?.participants.find((participant) => hasActiveQuery(participant.userId, topic.id))?.userId;
|
|
22006
22007
|
}
|
|
@@ -22567,7 +22568,7 @@ ${card.task}${reportInstruction}`;
|
|
|
22567
22568
|
name: "start_subagent",
|
|
22568
22569
|
description: "Start a prepared descendant subagent task.",
|
|
22569
22570
|
schema: {
|
|
22570
|
-
topic_id:
|
|
22571
|
+
topic_id: z7.string().describe("Prepared subagent room id.")
|
|
22571
22572
|
},
|
|
22572
22573
|
async handler(input) {
|
|
22573
22574
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22587,7 +22588,7 @@ ${card.task}${reportInstruction}`;
|
|
|
22587
22588
|
name: "delete_subagent",
|
|
22588
22589
|
description: "Permanently delete one descendant subagent room managed by the current room. " + "This removes its conversation, workspace, runtime state, and topic. Keep it when follow-up work is likely.",
|
|
22589
22590
|
schema: {
|
|
22590
|
-
topic_id:
|
|
22591
|
+
topic_id: z7.string().describe("Exact subagent room id returned by list_subagents; names are not accepted.")
|
|
22591
22592
|
},
|
|
22592
22593
|
async handler(input) {
|
|
22593
22594
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22611,8 +22612,8 @@ ${card.task}${reportInstruction}`;
|
|
|
22611
22612
|
name: "grant_subagent_tell",
|
|
22612
22613
|
description: "Allow one descendant subagent to tell_session another topic in this managed subagent tree. " + "Direct-parent reporting is always allowed and does not need a grant.",
|
|
22613
22614
|
schema: {
|
|
22614
|
-
subagent_topic_id:
|
|
22615
|
-
target_topic_id:
|
|
22615
|
+
subagent_topic_id: z7.string().describe("Source descendant subagent topic id."),
|
|
22616
|
+
target_topic_id: z7.string().describe("Target topic id: this manager room or another descendant in its tree.")
|
|
22616
22617
|
},
|
|
22617
22618
|
async handler(input) {
|
|
22618
22619
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22637,8 +22638,8 @@ ${card.task}${reportInstruction}`;
|
|
|
22637
22638
|
name: "revoke_subagent_tell",
|
|
22638
22639
|
description: "Remove an extra tell_session connection previously granted to a descendant subagent.",
|
|
22639
22640
|
schema: {
|
|
22640
|
-
subagent_topic_id:
|
|
22641
|
-
target_topic_id:
|
|
22641
|
+
subagent_topic_id: z7.string().describe("Source descendant subagent topic id."),
|
|
22642
|
+
target_topic_id: z7.string().describe("Granted target topic id.")
|
|
22642
22643
|
},
|
|
22643
22644
|
async handler(input) {
|
|
22644
22645
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22660,18 +22661,18 @@ ${card.task}${reportInstruction}`;
|
|
|
22660
22661
|
}
|
|
22661
22662
|
function createSpawnSubagentToolDefinition(ctx, options = {}) {
|
|
22662
22663
|
const executionOverrideSchema = options.executionOverrides === false ? {} : {
|
|
22663
|
-
agent:
|
|
22664
|
-
model:
|
|
22664
|
+
agent: z7.enum(["claude", "codex", "maestro"]).optional().describe("Agent backend override. Defaults to this room's agent."),
|
|
22665
|
+
model: z7.string().optional().describe(`Best-fit model override from the system prompt catalog. Omit agent+model to inherit ${ctx.agent}/${ctx.model ?? "default"}; overriding agent without model uses that agent's default.`)
|
|
22665
22666
|
};
|
|
22666
22667
|
return {
|
|
22667
22668
|
name: "spawn_subagent",
|
|
22668
22669
|
description: "Delegate a self-contained task to a subagent that works in its own new agent room. " + "Returns immediately; the subagent runs in the background and reports according to report_mode. " + "The fresh room has no parent conversation history; it receives the task plus the selected or inherited topic memory. " + "Use for parallelizable or long-running side work. Do not use provider built-in Task/Agent subagents.",
|
|
22669
22670
|
schema: {
|
|
22670
|
-
task:
|
|
22671
|
-
name:
|
|
22671
|
+
task: z7.string().describe("Self-contained task brief. The worker has topic memory but no parent conversation history, so include all task-specific context."),
|
|
22672
|
+
name: z7.string().optional().describe("Short name for the subagent room. Auto-generated when omitted."),
|
|
22672
22673
|
...executionOverrideSchema,
|
|
22673
|
-
memory_topic:
|
|
22674
|
-
report_mode:
|
|
22674
|
+
memory_topic: z7.string().optional().describe("Optional knowledge source: an accessible topic id/title or topic/*.md brief. Defaults to the parent room's effective topic brief."),
|
|
22675
|
+
report_mode: z7.enum(["auto", "tell", "status-only"]).optional().describe("Completion reporting: auto injects the final result, tell requires tell_session, status-only updates only the lifecycle card.")
|
|
22675
22676
|
},
|
|
22676
22677
|
async handler(input) {
|
|
22677
22678
|
return createSubagent(ctx, input, true);
|
|
@@ -22683,14 +22684,14 @@ ${card.task}${reportInstruction}`;
|
|
|
22683
22684
|
name: "create_subagent",
|
|
22684
22685
|
description: "Create a prepared subagent room and task definition without starting its AI turn. " + "Use start_subagent when the team is ready to run it.",
|
|
22685
22686
|
schema: {
|
|
22686
|
-
task:
|
|
22687
|
-
name:
|
|
22687
|
+
task: z7.string().describe("Self-contained task brief for the subagent."),
|
|
22688
|
+
name: z7.string().optional().describe("Short room name. Auto-generated when omitted."),
|
|
22688
22689
|
...options.executionOverrides === false ? {} : {
|
|
22689
|
-
agent:
|
|
22690
|
-
model:
|
|
22690
|
+
agent: z7.enum(["claude", "codex", "maestro"]).optional(),
|
|
22691
|
+
model: z7.string().optional()
|
|
22691
22692
|
},
|
|
22692
|
-
memory_topic:
|
|
22693
|
-
report_mode:
|
|
22693
|
+
memory_topic: z7.string().optional().describe("Optional accessible topic id/title or topic/*.md brief to use as this worker's knowledge source. Defaults to the parent."),
|
|
22694
|
+
report_mode: z7.enum(["auto", "tell", "status-only"]).optional()
|
|
22694
22695
|
},
|
|
22695
22696
|
async handler(input) {
|
|
22696
22697
|
return createSubagent(ctx, input, false);
|
|
@@ -25620,7 +25621,56 @@ ${renderDecisionList(decisions)}`);
|
|
|
25620
25621
|
}
|
|
25621
25622
|
// ../../packages/core/src/mcp/factories/session-comm.ts
|
|
25622
25623
|
import { McpServer as McpServer4 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25623
|
-
import { z as
|
|
25624
|
+
import { z as z8 } from "zod";
|
|
25625
|
+
|
|
25626
|
+
// ../../packages/core/src/mcp/session-comm/history-tools.ts
|
|
25627
|
+
import { z as z4 } from "zod";
|
|
25628
|
+
|
|
25629
|
+
// ../../packages/core/src/mcp/session-history-limits.ts
|
|
25630
|
+
var SESSION_HISTORY_DEFAULT_MAX_CALLS = 20;
|
|
25631
|
+
var SESSION_HISTORY_DEFAULT_MAX_TOTAL_BYTES = 768 * 1024;
|
|
25632
|
+
var SESSION_HISTORY_DEFAULT_MAX_CHUNK_BYTES = 64 * 1024;
|
|
25633
|
+
var SESSION_HISTORY_DEFAULT_LINE_LIMIT = 300;
|
|
25634
|
+
var SESSION_HISTORY_MAX_LINE_LIMIT = 500;
|
|
25635
|
+
var SESSION_HISTORY_DEFAULT_SEARCH_LIMIT = 20;
|
|
25636
|
+
var SESSION_HISTORY_MAX_SEARCH_LIMIT = 50;
|
|
25637
|
+
|
|
25638
|
+
// ../../packages/core/src/mcp/session-comm/history-tools.ts
|
|
25639
|
+
var to = z4.string().describe("Target session/topic name, exactly as list_sessions shows it (local sessions only).");
|
|
25640
|
+
function registerSessionHistoryOfTools(server, reader) {
|
|
25641
|
+
server.tool("list_session_boundaries_of", [
|
|
25642
|
+
"Like list_session_boundaries, but for ANOTHER local session you can see in list_sessions:",
|
|
25643
|
+
"lists that topic's provider sessions (compactions, agent switches) with their 1-based",
|
|
25644
|
+
"entry ranges from its append-only raw conversation manifest. Call this before",
|
|
25645
|
+
"read_session_history_of / search_session_history_of to target a range. Read-only: the",
|
|
25646
|
+
"other session is not notified and nothing is injected into it. Use your own",
|
|
25647
|
+
"list_session_boundaries for the current topic."
|
|
25648
|
+
].join(" "), { to }, async (args) => reader.listBoundaries(args.to));
|
|
25649
|
+
server.tool("read_session_history_of", [
|
|
25650
|
+
"Read ANOTHER local session's full-fidelity raw conversation manifest in bounded chunks",
|
|
25651
|
+
"(messages, tool calls, reasoning \u2014 including what its /compact summarized away). Use it",
|
|
25652
|
+
"when a tell_session/ask_session message points you at the sender's history (an entry",
|
|
25653
|
+
"range or sessionId) instead of pasting it, or when you need another topic's exact prior",
|
|
25654
|
+
"context. Only sessions listed by list_sessions are readable. Shares this turn's read",
|
|
25655
|
+
"budget with the other *_of tools."
|
|
25656
|
+
].join(" "), {
|
|
25657
|
+
to,
|
|
25658
|
+
offset: z4.number().optional().describe("One-based entry number. Defaults to 1."),
|
|
25659
|
+
limit: z4.number().optional().describe(`Number of entries. Defaults to ${SESSION_HISTORY_DEFAULT_LINE_LIMIT}, max ${SESSION_HISTORY_MAX_LINE_LIMIT}.`),
|
|
25660
|
+
sessionId: z4.string().optional().describe("Restrict to one session's entry range (see list_session_boundaries_of).")
|
|
25661
|
+
}, async ({ to: target, ...args }) => reader.read(target, args));
|
|
25662
|
+
server.tool("search_session_history_of", [
|
|
25663
|
+
"Keyword-search ANOTHER local session's full raw conversation manifest (case-insensitive",
|
|
25664
|
+
"substring). Returns matching entry numbers with snippets \u2014 pass one to",
|
|
25665
|
+
"read_session_history_of for full context. Only sessions listed by list_sessions are",
|
|
25666
|
+
"searchable."
|
|
25667
|
+
].join(" "), {
|
|
25668
|
+
to,
|
|
25669
|
+
query: z4.string().min(1).describe("Case-insensitive substring to search for."),
|
|
25670
|
+
sessionId: z4.string().optional().describe("Restrict the scan to one session's range."),
|
|
25671
|
+
limit: z4.number().optional().describe(`Max matches to return. Defaults to ${SESSION_HISTORY_DEFAULT_SEARCH_LIMIT}, max ${SESSION_HISTORY_MAX_SEARCH_LIMIT}.`)
|
|
25672
|
+
}, async ({ to: target, ...args }) => reader.search(target, args));
|
|
25673
|
+
}
|
|
25624
25674
|
|
|
25625
25675
|
// ../../packages/core/src/mcp/session-comm/tell-permissions.ts
|
|
25626
25676
|
await __promiseAll([
|
|
@@ -25661,29 +25711,32 @@ function createSessionCommMcpServer(context, host, options = {}) {
|
|
|
25661
25711
|
const subagentIdentity = resolveSubagentTellIdentity(context.currentTopicId, context.subagentParentTopicId);
|
|
25662
25712
|
server.tool("list_sessions", "List available sessions and remote peer sessions for inter-session communication.", {}, async () => host.listSessions(context));
|
|
25663
25713
|
server.tool("configure_mcp", `Configure optional MCP servers for the current topic. Required: ${required}. Optional: ${optional}.`, {
|
|
25664
|
-
enabled:
|
|
25714
|
+
enabled: z8.array(z8.string()).nullable().optional()
|
|
25665
25715
|
}, async ({ enabled }) => host.configureMcp(context, enabled));
|
|
25666
25716
|
server.tool("get_mcp_config", "Get the current topic MCP configuration.", {}, async () => host.getMcpConfig(context));
|
|
25667
25717
|
if (host.getBrowserProfile) {
|
|
25668
25718
|
server.tool("get_browser_profile", "Get this topic's browser profile and the profiles owned by the same user.", {}, async () => host.getBrowserProfile(context));
|
|
25669
25719
|
}
|
|
25670
25720
|
if (host.setBrowserProfile) {
|
|
25671
|
-
server.tool("set_browser_profile", "Assign this topic to a named shared browser profile. Takes effect next turn.", { profile:
|
|
25721
|
+
server.tool("set_browser_profile", "Assign this topic to a named shared browser profile. Takes effect next turn.", { profile: z8.string() }, async ({ profile }) => host.setBrowserProfile(context, profile));
|
|
25672
25722
|
}
|
|
25673
25723
|
if (host.deleteBrowserProfile) {
|
|
25674
|
-
server.tool("delete_browser_profile", "Delete an unused named browser profile and its on-disk data. The default or an assigned profile cannot be deleted.", { profile:
|
|
25724
|
+
server.tool("delete_browser_profile", "Delete an unused named browser profile and its on-disk data. The default or an assigned profile cannot be deleted.", { profile: z8.string() }, async ({ profile }) => host.deleteBrowserProfile(context, profile));
|
|
25675
25725
|
}
|
|
25676
25726
|
server.tool("peek_session", "Inspect running and idle sessions, including pending ask_session calls.", {}, async () => host.peekSession(context));
|
|
25677
|
-
server.tool("set_description", "Set the current session description used as a routing hint.", { description:
|
|
25727
|
+
server.tool("set_description", "Set the current session description used as a routing hint.", { description: z8.string() }, async ({ description }) => host.setDescription(context, description));
|
|
25728
|
+
if (host.sessionHistoryOf) {
|
|
25729
|
+
registerSessionHistoryOfTools(server, host.sessionHistoryOf(context));
|
|
25730
|
+
}
|
|
25678
25731
|
if (!context.replyOnly) {
|
|
25679
25732
|
if (!subagentIdentity.restricted) {
|
|
25680
|
-
server.tool("ask_session", "Ask another local or remote session a question and wait for its answer.", { to:
|
|
25681
|
-
server.tool("ask_cron", "Ask this topic's shared Cron session a question. The answer is injected asynchronously into the current conversation.", { message:
|
|
25733
|
+
server.tool("ask_session", "Ask another local or remote session a question and wait for its answer. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to: z8.string(), message: z8.string() }, async (input) => host.askSession(context, input));
|
|
25734
|
+
server.tool("ask_cron", "Ask this topic's shared Cron session a question. The answer is injected asynchronously into the current conversation.", { message: z8.string() }, async ({ message }) => host.askCron(context, message));
|
|
25682
25735
|
}
|
|
25683
25736
|
if (!subagentIdentity.restricted) {
|
|
25684
|
-
server.tool("abort_session", "Abort the active query in another session.", { to:
|
|
25737
|
+
server.tool("abort_session", "Abort the active query in another session.", { to: z8.string() }, async ({ to: to2 }) => host.abortSession(context, to2));
|
|
25685
25738
|
}
|
|
25686
|
-
server.tool("tell_session", "Send a one-way message to another local or remote session.", { to:
|
|
25739
|
+
server.tool("tell_session", "Send a one-way message to another local or remote session. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to: z8.string(), message: z8.string() }, async (input) => {
|
|
25687
25740
|
if (subagentIdentity.restricted && !canSubagentTellTargetByName(subagentIdentity, input.to)) {
|
|
25688
25741
|
return {
|
|
25689
25742
|
content: [
|
|
@@ -25702,19 +25755,15 @@ function createSessionCommMcpServer(context, host, options = {}) {
|
|
|
25702
25755
|
}
|
|
25703
25756
|
// ../../packages/core/src/mcp/factories/session-history.ts
|
|
25704
25757
|
init_mcp_helpers();
|
|
25758
|
+
import { McpServer as McpServer5 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25759
|
+
import { z as z9 } from "zod";
|
|
25760
|
+
|
|
25761
|
+
// ../../packages/core/src/mcp/session-history-reader.ts
|
|
25762
|
+
init_mcp_helpers();
|
|
25705
25763
|
await __promiseAll([
|
|
25706
25764
|
init_conversations(),
|
|
25707
25765
|
init_topic_archive()
|
|
25708
25766
|
]);
|
|
25709
|
-
import { McpServer as McpServer5 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25710
|
-
import { z as z8 } from "zod";
|
|
25711
|
-
var DEFAULT_MAX_CALLS2 = 20;
|
|
25712
|
-
var DEFAULT_MAX_TOTAL_BYTES2 = 768 * 1024;
|
|
25713
|
-
var DEFAULT_MAX_CHUNK_BYTES2 = 64 * 1024;
|
|
25714
|
-
var DEFAULT_LINE_LIMIT2 = 300;
|
|
25715
|
-
var MAX_LINE_LIMIT2 = 500;
|
|
25716
|
-
var DEFAULT_SEARCH_LIMIT = 20;
|
|
25717
|
-
var MAX_SEARCH_LIMIT = 50;
|
|
25718
25767
|
var SEARCH_SNIPPET_RADIUS = 160;
|
|
25719
25768
|
function positiveInt2(value2, fallback) {
|
|
25720
25769
|
return Number.isFinite(value2) && value2 && value2 > 0 ? Math.floor(value2) : fallback;
|
|
@@ -25777,20 +25826,27 @@ function deriveBoundaries(entries) {
|
|
|
25777
25826
|
}
|
|
25778
25827
|
return boundaries;
|
|
25779
25828
|
}
|
|
25780
|
-
function
|
|
25781
|
-
|
|
25782
|
-
|
|
25783
|
-
const
|
|
25829
|
+
function sessionRange(entries, sessionId) {
|
|
25830
|
+
if (!sessionId)
|
|
25831
|
+
return { lower: 0, upper: entries.length };
|
|
25832
|
+
const boundaries = deriveBoundaries(entries);
|
|
25833
|
+
const match = boundaries.find((b) => b.sessionId === sessionId);
|
|
25834
|
+
if (!match)
|
|
25835
|
+
return null;
|
|
25836
|
+
const next = boundaries.find((b) => b.entryIndex > match.entryIndex);
|
|
25837
|
+
return { lower: match.entryIndex - 1, upper: next ? next.entryIndex - 1 : entries.length };
|
|
25838
|
+
}
|
|
25839
|
+
function topicField(target) {
|
|
25840
|
+
return target.label ? { topic: target.label } : {};
|
|
25841
|
+
}
|
|
25842
|
+
function createSessionHistoryReader(budget = {}) {
|
|
25843
|
+
const maxCalls = positiveInt2(budget.maxCalls, SESSION_HISTORY_DEFAULT_MAX_CALLS);
|
|
25844
|
+
const maxTotalBytes = positiveInt2(budget.maxTotalBytes, SESSION_HISTORY_DEFAULT_MAX_TOTAL_BYTES);
|
|
25845
|
+
const maxChunkBytes = positiveInt2(budget.maxChunkBytes, SESSION_HISTORY_DEFAULT_MAX_CHUNK_BYTES);
|
|
25784
25846
|
let calls = 0;
|
|
25785
25847
|
let totalBytes = 0;
|
|
25786
|
-
const
|
|
25787
|
-
|
|
25788
|
-
if (!context.userId || !context.topic) {
|
|
25789
|
-
return mcpError("Error: missing userId/topic context.");
|
|
25790
|
-
}
|
|
25791
|
-
return null;
|
|
25792
|
-
};
|
|
25793
|
-
const budgetExceeded = () => {
|
|
25848
|
+
const spendCall = () => {
|
|
25849
|
+
calls += 1;
|
|
25794
25850
|
if (calls > maxCalls || totalBytes >= maxTotalBytes) {
|
|
25795
25851
|
return mcpError(JSON.stringify({
|
|
25796
25852
|
error: "session-history read budget exhausted for this turn; answer with what you already read",
|
|
@@ -25802,6 +25858,155 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25802
25858
|
}
|
|
25803
25859
|
return null;
|
|
25804
25860
|
};
|
|
25861
|
+
return {
|
|
25862
|
+
listBoundaries(target) {
|
|
25863
|
+
const budgetError = spendCall();
|
|
25864
|
+
if (budgetError)
|
|
25865
|
+
return budgetError;
|
|
25866
|
+
try {
|
|
25867
|
+
const entries = readRawConversation(target.userId, target.topic);
|
|
25868
|
+
const boundaries = deriveBoundaries(entries);
|
|
25869
|
+
const payload = JSON.stringify({ ...topicField(target), total_entries: entries.length, sessions: boundaries }, null, 2);
|
|
25870
|
+
totalBytes += Buffer.byteLength(payload, "utf8");
|
|
25871
|
+
return mcpOk(payload);
|
|
25872
|
+
} catch (error) {
|
|
25873
|
+
return mcpError(`list_session_boundaries failed: ${errMsg(error)}`);
|
|
25874
|
+
}
|
|
25875
|
+
},
|
|
25876
|
+
read(target, { offset: rawOffset, limit: rawLimit, sessionId }) {
|
|
25877
|
+
const budgetError = spendCall();
|
|
25878
|
+
if (budgetError)
|
|
25879
|
+
return budgetError;
|
|
25880
|
+
try {
|
|
25881
|
+
const entries = readRawConversation(target.userId, target.topic);
|
|
25882
|
+
const range = sessionRange(entries, sessionId);
|
|
25883
|
+
if (!range)
|
|
25884
|
+
return mcpError(`Unknown sessionId: ${sessionId}`);
|
|
25885
|
+
const { lower, upper } = range;
|
|
25886
|
+
const offset = positiveInt2(rawOffset, 1);
|
|
25887
|
+
const limit = Math.min(positiveInt2(rawLimit, SESSION_HISTORY_DEFAULT_LINE_LIMIT), SESSION_HISTORY_MAX_LINE_LIMIT);
|
|
25888
|
+
const start = Math.max(lower, offset - 1);
|
|
25889
|
+
if (start >= upper) {
|
|
25890
|
+
return mcpOk(JSON.stringify({
|
|
25891
|
+
...topicField(target),
|
|
25892
|
+
content: "(end of range)",
|
|
25893
|
+
offset,
|
|
25894
|
+
returned_entries: 0,
|
|
25895
|
+
total_entries: entries.length,
|
|
25896
|
+
calls
|
|
25897
|
+
}));
|
|
25898
|
+
}
|
|
25899
|
+
const rendered = [];
|
|
25900
|
+
let returnedBytes = 0;
|
|
25901
|
+
let index = start;
|
|
25902
|
+
const callBudget = Math.min(maxChunkBytes, Math.max(1, maxTotalBytes - totalBytes));
|
|
25903
|
+
while (index < upper && rendered.length < limit) {
|
|
25904
|
+
const line = fitUtf82(renderEntry(entries[index], index + 1), Math.max(1, callBudget));
|
|
25905
|
+
const separatorBytes = rendered.length > 0 ? 1 : 0;
|
|
25906
|
+
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
25907
|
+
if (rendered.length > 0 && returnedBytes + separatorBytes + lineBytes > callBudget)
|
|
25908
|
+
break;
|
|
25909
|
+
rendered.push(line);
|
|
25910
|
+
returnedBytes += separatorBytes + lineBytes;
|
|
25911
|
+
index += 1;
|
|
25912
|
+
if (returnedBytes >= callBudget)
|
|
25913
|
+
break;
|
|
25914
|
+
}
|
|
25915
|
+
totalBytes += returnedBytes;
|
|
25916
|
+
return mcpOk(JSON.stringify({
|
|
25917
|
+
...topicField(target),
|
|
25918
|
+
content: rendered.join(`
|
|
25919
|
+
`),
|
|
25920
|
+
offset,
|
|
25921
|
+
returned_entries: rendered.length,
|
|
25922
|
+
returned_bytes: returnedBytes,
|
|
25923
|
+
total_entries: entries.length,
|
|
25924
|
+
total_read_bytes: totalBytes,
|
|
25925
|
+
calls,
|
|
25926
|
+
...index < upper ? { next_offset: index + 1 } : {},
|
|
25927
|
+
...calls >= maxCalls || totalBytes >= maxTotalBytes ? { note: "Read budget nearly exhausted; wrap up with what you have." } : {}
|
|
25928
|
+
}));
|
|
25929
|
+
} catch (error) {
|
|
25930
|
+
return mcpError(`read_session_history failed: ${errMsg(error)}`);
|
|
25931
|
+
}
|
|
25932
|
+
},
|
|
25933
|
+
search(target, { query: query2, sessionId, limit: rawLimit }) {
|
|
25934
|
+
const budgetError = spendCall();
|
|
25935
|
+
if (budgetError)
|
|
25936
|
+
return budgetError;
|
|
25937
|
+
try {
|
|
25938
|
+
const entries = readRawConversation(target.userId, target.topic);
|
|
25939
|
+
const range = sessionRange(entries, sessionId);
|
|
25940
|
+
if (!range)
|
|
25941
|
+
return mcpError(`Unknown sessionId: ${sessionId}`);
|
|
25942
|
+
const { lower, upper } = range;
|
|
25943
|
+
const limit = Math.min(positiveInt2(rawLimit, SESSION_HISTORY_DEFAULT_SEARCH_LIMIT), SESSION_HISTORY_MAX_SEARCH_LIMIT);
|
|
25944
|
+
const needleRegex = new RegExp(escapeRegExp4(query2), "i");
|
|
25945
|
+
const matches = [];
|
|
25946
|
+
const boundaries = sessionId ? undefined : deriveBoundaries(entries);
|
|
25947
|
+
let returnedBytes = 0;
|
|
25948
|
+
let budgetStopped = false;
|
|
25949
|
+
const callBudget = Math.min(maxChunkBytes, Math.max(1, maxTotalBytes - totalBytes));
|
|
25950
|
+
for (let i = lower;i < upper && matches.length < limit; i++) {
|
|
25951
|
+
const entry = entries[i];
|
|
25952
|
+
const text2 = eventText(entry.event);
|
|
25953
|
+
const found = needleRegex.exec(text2);
|
|
25954
|
+
if (!found)
|
|
25955
|
+
continue;
|
|
25956
|
+
const at = found.index;
|
|
25957
|
+
const start = Math.max(0, at - SEARCH_SNIPPET_RADIUS);
|
|
25958
|
+
const end = Math.min(text2.length, at + found[0].length + SEARCH_SNIPPET_RADIUS);
|
|
25959
|
+
const snippet = `${start > 0 ? "\u2026" : ""}${text2.slice(start, end)}${end < text2.length ? "\u2026" : ""}`;
|
|
25960
|
+
const matchedSessionId = sessionId ?? boundaries?.findLast((b) => b.entryIndex <= i + 1)?.sessionId;
|
|
25961
|
+
const candidate = {
|
|
25962
|
+
entry: i + 1,
|
|
25963
|
+
sessionId: matchedSessionId,
|
|
25964
|
+
agent: entry.agent,
|
|
25965
|
+
ts: entry.ts,
|
|
25966
|
+
snippet
|
|
25967
|
+
};
|
|
25968
|
+
const lineBytes = Buffer.byteLength(JSON.stringify(candidate), "utf8");
|
|
25969
|
+
if (returnedBytes + lineBytes > callBudget) {
|
|
25970
|
+
budgetStopped = true;
|
|
25971
|
+
break;
|
|
25972
|
+
}
|
|
25973
|
+
returnedBytes += lineBytes;
|
|
25974
|
+
matches.push(candidate);
|
|
25975
|
+
}
|
|
25976
|
+
totalBytes += returnedBytes;
|
|
25977
|
+
return mcpOk(JSON.stringify({
|
|
25978
|
+
...topicField(target),
|
|
25979
|
+
query: query2,
|
|
25980
|
+
matches,
|
|
25981
|
+
match_count: matches.length,
|
|
25982
|
+
total_entries: entries.length,
|
|
25983
|
+
calls,
|
|
25984
|
+
...matches.length >= limit ? { note: "Hit the match limit; narrow the query or pass sessionId for more." } : budgetStopped ? {
|
|
25985
|
+
note: "Read budget ran out before the scan finished; this result is incomplete, not necessarily 'no matches'."
|
|
25986
|
+
} : {}
|
|
25987
|
+
}));
|
|
25988
|
+
} catch (error) {
|
|
25989
|
+
return mcpError(`search_session_history failed: ${errMsg(error)}`);
|
|
25990
|
+
}
|
|
25991
|
+
}
|
|
25992
|
+
};
|
|
25993
|
+
}
|
|
25994
|
+
|
|
25995
|
+
// ../../packages/core/src/mcp/factories/session-history.ts
|
|
25996
|
+
function createSessionHistoryMcpServer(context) {
|
|
25997
|
+
const reader = createSessionHistoryReader({
|
|
25998
|
+
maxCalls: context.maxCalls,
|
|
25999
|
+
maxTotalBytes: context.maxTotalBytes,
|
|
26000
|
+
maxChunkBytes: context.maxChunkBytes
|
|
26001
|
+
});
|
|
26002
|
+
const self = { userId: context.userId, topic: context.topic };
|
|
26003
|
+
const server = new McpServer5({ name: "session-history", version: "1.0.0" });
|
|
26004
|
+
const requireContext = () => {
|
|
26005
|
+
if (!context.userId || !context.topic) {
|
|
26006
|
+
return mcpError("Error: missing userId/topic context.");
|
|
26007
|
+
}
|
|
26008
|
+
return null;
|
|
26009
|
+
};
|
|
25805
26010
|
server.tool("list_session_boundaries", [
|
|
25806
26011
|
"List every provider session this topic has had, in order, from the append-only raw",
|
|
25807
26012
|
"conversation manifest (survives /compact and agent switches \u2014 nothing is ever deleted",
|
|
@@ -25809,24 +26014,7 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25809
26014
|
"it ended via compaction or an agent switch, and its provider sessionId. Call this BEFORE",
|
|
25810
26015
|
"read_session_history or search_session_history so you know which entry range to target",
|
|
25811
26016
|
"instead of scanning from entry 1."
|
|
25812
|
-
].join(" "), {}, async () =>
|
|
25813
|
-
const guard = requireContext();
|
|
25814
|
-
if (guard)
|
|
25815
|
-
return guard;
|
|
25816
|
-
calls += 1;
|
|
25817
|
-
const budget = budgetExceeded();
|
|
25818
|
-
if (budget)
|
|
25819
|
-
return budget;
|
|
25820
|
-
try {
|
|
25821
|
-
const entries = readRawConversation(context.userId, context.topic);
|
|
25822
|
-
const boundaries = deriveBoundaries(entries);
|
|
25823
|
-
const payload = JSON.stringify({ total_entries: entries.length, sessions: boundaries }, null, 2);
|
|
25824
|
-
totalBytes += Buffer.byteLength(payload, "utf8");
|
|
25825
|
-
return mcpOk(payload);
|
|
25826
|
-
} catch (error) {
|
|
25827
|
-
return mcpError(`list_session_boundaries failed: ${errMsg(error)}`);
|
|
25828
|
-
}
|
|
25829
|
-
});
|
|
26017
|
+
].join(" "), {}, async () => requireContext() ?? reader.listBoundaries(self));
|
|
25830
26018
|
server.tool("read_session_history", [
|
|
25831
26019
|
"Read the full-fidelity raw conversation manifest in bounded chunks \u2014 includes everything",
|
|
25832
26020
|
"that ever happened in this topic (messages, tool calls, reasoning, session/compact",
|
|
@@ -25835,75 +26023,10 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25835
26023
|
"list_session_boundaries, then pass sessionId to read only that session's range instead of",
|
|
25836
26024
|
"paging through the whole topic."
|
|
25837
26025
|
].join(" "), {
|
|
25838
|
-
offset:
|
|
25839
|
-
limit:
|
|
25840
|
-
sessionId:
|
|
25841
|
-
}, async (
|
|
25842
|
-
const guard = requireContext();
|
|
25843
|
-
if (guard)
|
|
25844
|
-
return guard;
|
|
25845
|
-
calls += 1;
|
|
25846
|
-
const budget = budgetExceeded();
|
|
25847
|
-
if (budget)
|
|
25848
|
-
return budget;
|
|
25849
|
-
try {
|
|
25850
|
-
const entries = readRawConversation(context.userId, context.topic);
|
|
25851
|
-
let lower = 0;
|
|
25852
|
-
let upper = entries.length;
|
|
25853
|
-
if (sessionId) {
|
|
25854
|
-
const boundaries = deriveBoundaries(entries);
|
|
25855
|
-
const match = boundaries.find((b) => b.sessionId === sessionId);
|
|
25856
|
-
if (!match)
|
|
25857
|
-
return mcpError(`Unknown sessionId: ${sessionId}`);
|
|
25858
|
-
lower = match.entryIndex - 1;
|
|
25859
|
-
const next = boundaries.find((b) => b.entryIndex > match.entryIndex);
|
|
25860
|
-
upper = next ? next.entryIndex - 1 : entries.length;
|
|
25861
|
-
}
|
|
25862
|
-
const offset = positiveInt2(rawOffset, 1);
|
|
25863
|
-
const limit = Math.min(positiveInt2(rawLimit, DEFAULT_LINE_LIMIT2), MAX_LINE_LIMIT2);
|
|
25864
|
-
const start = Math.max(lower, offset - 1);
|
|
25865
|
-
if (start >= upper) {
|
|
25866
|
-
return mcpOk(JSON.stringify({
|
|
25867
|
-
content: "(end of range)",
|
|
25868
|
-
offset,
|
|
25869
|
-
returned_entries: 0,
|
|
25870
|
-
total_entries: entries.length,
|
|
25871
|
-
calls
|
|
25872
|
-
}));
|
|
25873
|
-
}
|
|
25874
|
-
const rendered = [];
|
|
25875
|
-
let returnedBytes = 0;
|
|
25876
|
-
let index = start;
|
|
25877
|
-
const callBudget = Math.min(maxChunkBytes, Math.max(1, maxTotalBytes - totalBytes));
|
|
25878
|
-
while (index < upper && rendered.length < limit) {
|
|
25879
|
-
const line = fitUtf82(renderEntry(entries[index], index + 1), Math.max(1, callBudget));
|
|
25880
|
-
const separatorBytes = rendered.length > 0 ? 1 : 0;
|
|
25881
|
-
const lineBytes = Buffer.byteLength(line, "utf8");
|
|
25882
|
-
if (rendered.length > 0 && returnedBytes + separatorBytes + lineBytes > callBudget)
|
|
25883
|
-
break;
|
|
25884
|
-
rendered.push(line);
|
|
25885
|
-
returnedBytes += separatorBytes + lineBytes;
|
|
25886
|
-
index += 1;
|
|
25887
|
-
if (returnedBytes >= callBudget)
|
|
25888
|
-
break;
|
|
25889
|
-
}
|
|
25890
|
-
totalBytes += returnedBytes;
|
|
25891
|
-
return mcpOk(JSON.stringify({
|
|
25892
|
-
content: rendered.join(`
|
|
25893
|
-
`),
|
|
25894
|
-
offset,
|
|
25895
|
-
returned_entries: rendered.length,
|
|
25896
|
-
returned_bytes: returnedBytes,
|
|
25897
|
-
total_entries: entries.length,
|
|
25898
|
-
total_read_bytes: totalBytes,
|
|
25899
|
-
calls,
|
|
25900
|
-
...index < upper ? { next_offset: index + 1 } : {},
|
|
25901
|
-
...calls >= maxCalls || totalBytes >= maxTotalBytes ? { note: "Read budget nearly exhausted; wrap up with what you have." } : {}
|
|
25902
|
-
}));
|
|
25903
|
-
} catch (error) {
|
|
25904
|
-
return mcpError(`read_session_history failed: ${errMsg(error)}`);
|
|
25905
|
-
}
|
|
25906
|
-
});
|
|
26026
|
+
offset: z9.number().optional().describe("One-based entry number. Defaults to 1."),
|
|
26027
|
+
limit: z9.number().optional().describe(`Number of entries. Defaults to ${SESSION_HISTORY_DEFAULT_LINE_LIMIT}, max ${SESSION_HISTORY_MAX_LINE_LIMIT}.`),
|
|
26028
|
+
sessionId: z9.string().optional().describe("Restrict to one session's entry range (see list_session_boundaries).")
|
|
26029
|
+
}, async (args) => requireContext() ?? reader.read(self, args));
|
|
25907
26030
|
server.tool("search_session_history", [
|
|
25908
26031
|
"Keyword-search the full raw conversation manifest (case-insensitive substring match)",
|
|
25909
26032
|
"across every session this topic has ever had, including content a /compact summarized",
|
|
@@ -25912,78 +26035,10 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25912
26035
|
"topic's size, but prefer sessionId to narrow the scan when you already know which session",
|
|
25913
26036
|
"from list_session_boundaries."
|
|
25914
26037
|
].join(" "), {
|
|
25915
|
-
query:
|
|
25916
|
-
sessionId:
|
|
25917
|
-
limit:
|
|
25918
|
-
}, async (
|
|
25919
|
-
const guard = requireContext();
|
|
25920
|
-
if (guard)
|
|
25921
|
-
return guard;
|
|
25922
|
-
calls += 1;
|
|
25923
|
-
const budget = budgetExceeded();
|
|
25924
|
-
if (budget)
|
|
25925
|
-
return budget;
|
|
25926
|
-
try {
|
|
25927
|
-
const entries = readRawConversation(context.userId, context.topic);
|
|
25928
|
-
let lower = 0;
|
|
25929
|
-
let upper = entries.length;
|
|
25930
|
-
if (sessionId) {
|
|
25931
|
-
const boundaries2 = deriveBoundaries(entries);
|
|
25932
|
-
const match = boundaries2.find((b) => b.sessionId === sessionId);
|
|
25933
|
-
if (!match)
|
|
25934
|
-
return mcpError(`Unknown sessionId: ${sessionId}`);
|
|
25935
|
-
lower = match.entryIndex - 1;
|
|
25936
|
-
const next = boundaries2.find((b) => b.entryIndex > match.entryIndex);
|
|
25937
|
-
upper = next ? next.entryIndex - 1 : entries.length;
|
|
25938
|
-
}
|
|
25939
|
-
const limit = Math.min(positiveInt2(rawLimit, DEFAULT_SEARCH_LIMIT), MAX_SEARCH_LIMIT);
|
|
25940
|
-
const needleRegex = new RegExp(escapeRegExp4(query2), "i");
|
|
25941
|
-
const matches = [];
|
|
25942
|
-
const boundaries = sessionId ? undefined : deriveBoundaries(entries);
|
|
25943
|
-
let returnedBytes = 0;
|
|
25944
|
-
let budgetStopped = false;
|
|
25945
|
-
const callBudget = Math.min(maxChunkBytes, Math.max(1, maxTotalBytes - totalBytes));
|
|
25946
|
-
for (let i = lower;i < upper && matches.length < limit; i++) {
|
|
25947
|
-
const entry = entries[i];
|
|
25948
|
-
const text2 = eventText(entry.event);
|
|
25949
|
-
const found = needleRegex.exec(text2);
|
|
25950
|
-
if (!found)
|
|
25951
|
-
continue;
|
|
25952
|
-
const at = found.index;
|
|
25953
|
-
const start = Math.max(0, at - SEARCH_SNIPPET_RADIUS);
|
|
25954
|
-
const end = Math.min(text2.length, at + found[0].length + SEARCH_SNIPPET_RADIUS);
|
|
25955
|
-
const snippet = `${start > 0 ? "\u2026" : ""}${text2.slice(start, end)}${end < text2.length ? "\u2026" : ""}`;
|
|
25956
|
-
const matchedSessionId = sessionId ?? boundaries?.findLast((b) => b.entryIndex <= i + 1)?.sessionId;
|
|
25957
|
-
const candidate = {
|
|
25958
|
-
entry: i + 1,
|
|
25959
|
-
sessionId: matchedSessionId,
|
|
25960
|
-
agent: entry.agent,
|
|
25961
|
-
ts: entry.ts,
|
|
25962
|
-
snippet
|
|
25963
|
-
};
|
|
25964
|
-
const lineBytes = Buffer.byteLength(JSON.stringify(candidate), "utf8");
|
|
25965
|
-
if (returnedBytes + lineBytes > callBudget) {
|
|
25966
|
-
budgetStopped = true;
|
|
25967
|
-
break;
|
|
25968
|
-
}
|
|
25969
|
-
returnedBytes += lineBytes;
|
|
25970
|
-
matches.push(candidate);
|
|
25971
|
-
}
|
|
25972
|
-
totalBytes += returnedBytes;
|
|
25973
|
-
return mcpOk(JSON.stringify({
|
|
25974
|
-
query: query2,
|
|
25975
|
-
matches,
|
|
25976
|
-
match_count: matches.length,
|
|
25977
|
-
total_entries: entries.length,
|
|
25978
|
-
calls,
|
|
25979
|
-
...matches.length >= limit ? { note: "Hit the match limit; narrow the query or pass sessionId for more." } : budgetStopped ? {
|
|
25980
|
-
note: "Read budget ran out before the scan finished; this result is incomplete, not necessarily 'no matches'."
|
|
25981
|
-
} : {}
|
|
25982
|
-
}));
|
|
25983
|
-
} catch (error) {
|
|
25984
|
-
return mcpError(`search_session_history failed: ${errMsg(error)}`);
|
|
25985
|
-
}
|
|
25986
|
-
});
|
|
26038
|
+
query: z9.string().min(1).describe("Case-insensitive substring to search for."),
|
|
26039
|
+
sessionId: z9.string().optional().describe("Restrict the scan to one session's range."),
|
|
26040
|
+
limit: z9.number().optional().describe(`Max matches to return. Defaults to ${SESSION_HISTORY_DEFAULT_SEARCH_LIMIT}, max ${SESSION_HISTORY_MAX_SEARCH_LIMIT}.`)
|
|
26041
|
+
}, async (args) => requireContext() ?? reader.search(self, args));
|
|
25987
26042
|
return server;
|
|
25988
26043
|
}
|
|
25989
26044
|
// ../../packages/core/src/mcp/factories/stdio-protection.ts
|
|
@@ -26186,7 +26241,7 @@ function createSystemHealthMcpServer(host = defaultSystemHealthMcpHost) {
|
|
|
26186
26241
|
init_mcp_helpers();
|
|
26187
26242
|
await init_tasks();
|
|
26188
26243
|
import { McpServer as McpServer7 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
26189
|
-
import { z as
|
|
26244
|
+
import { z as z10 } from "zod";
|
|
26190
26245
|
var defaultTaskMcpHost = {
|
|
26191
26246
|
readTasks,
|
|
26192
26247
|
writeTasks
|
|
@@ -26200,13 +26255,13 @@ function createTaskMcpServer(context, host = defaultTaskMcpHost) {
|
|
|
26200
26255
|
}
|
|
26201
26256
|
return null;
|
|
26202
26257
|
};
|
|
26203
|
-
const statusEnum =
|
|
26258
|
+
const statusEnum = z10.enum(TASK_STATUS_VALUES);
|
|
26204
26259
|
server.tool("task_create", "Add one or more tasks to this topic's shared Otium task list. Use this instead of provider-native todo/task tools.", {
|
|
26205
|
-
tasks:
|
|
26206
|
-
subject:
|
|
26207
|
-
active_form:
|
|
26208
|
-
blocked_by:
|
|
26209
|
-
owner:
|
|
26260
|
+
tasks: z10.array(z10.object({
|
|
26261
|
+
subject: z10.string().min(1).describe("Short imperative task description"),
|
|
26262
|
+
active_form: z10.string().optional().describe("Label to show while the task is in progress"),
|
|
26263
|
+
blocked_by: z10.array(z10.string()).optional().describe("Task ids blocking this task"),
|
|
26264
|
+
owner: z10.string().optional().describe("Owner/agent label for multi-agent work")
|
|
26210
26265
|
})).min(1)
|
|
26211
26266
|
}, async ({ tasks: inputs }) => {
|
|
26212
26267
|
const guard = requireContext();
|
|
@@ -26230,13 +26285,13 @@ ${renderTaskList(tasks2)}`);
|
|
|
26230
26285
|
}
|
|
26231
26286
|
});
|
|
26232
26287
|
server.tool("task_update", "Update task status/content in this topic's shared Otium task list. Batch related status changes in one call.", {
|
|
26233
|
-
updates:
|
|
26234
|
-
id:
|
|
26288
|
+
updates: z10.array(z10.object({
|
|
26289
|
+
id: z10.string().describe("Target task id"),
|
|
26235
26290
|
status: statusEnum.optional().describe("New status"),
|
|
26236
|
-
subject:
|
|
26237
|
-
active_form:
|
|
26238
|
-
blocked_by:
|
|
26239
|
-
owner:
|
|
26291
|
+
subject: z10.string().min(1).optional().describe("Replacement task description"),
|
|
26292
|
+
active_form: z10.string().optional().describe("Replacement in-progress label; empty string clears it"),
|
|
26293
|
+
blocked_by: z10.array(z10.string()).optional().describe("Replacement blocker id list"),
|
|
26294
|
+
owner: z10.string().optional().describe("Replacement owner; empty string clears it")
|
|
26240
26295
|
})).min(1)
|
|
26241
26296
|
}, async ({ updates }) => {
|
|
26242
26297
|
const guard = requireContext();
|
|
@@ -26270,7 +26325,7 @@ Missing ids ignored: ${missing.join(", ")}` : "";
|
|
|
26270
26325
|
return mcpError(`task_list failed: ${errMsg(error)}`);
|
|
26271
26326
|
}
|
|
26272
26327
|
});
|
|
26273
|
-
server.tool("task_get", "Read one task from this topic's shared Otium task list as JSON.", { id:
|
|
26328
|
+
server.tool("task_get", "Read one task from this topic's shared Otium task list as JSON.", { id: z10.string().describe("Task id") }, async ({ id }) => {
|
|
26274
26329
|
const guard = requireContext();
|
|
26275
26330
|
if (guard)
|
|
26276
26331
|
return guard;
|
|
@@ -26284,8 +26339,8 @@ Missing ids ignored: ${missing.join(", ")}` : "";
|
|
|
26284
26339
|
}
|
|
26285
26340
|
});
|
|
26286
26341
|
server.tool("task_delete", "Delete tasks from this topic's shared Otium task list. Use all=true only when starting a new plan.", {
|
|
26287
|
-
ids:
|
|
26288
|
-
all:
|
|
26342
|
+
ids: z10.array(z10.string()).optional().describe("Task ids to delete"),
|
|
26343
|
+
all: z10.boolean().optional().describe("Delete the whole list")
|
|
26289
26344
|
}, async ({ ids, all }) => {
|
|
26290
26345
|
const guard = requireContext();
|
|
26291
26346
|
if (guard)
|
|
@@ -26308,7 +26363,7 @@ ${renderTaskList(tasks2)}`);
|
|
|
26308
26363
|
// ../../packages/core/src/mcp/factories/token-stats.ts
|
|
26309
26364
|
await init_token_stats();
|
|
26310
26365
|
import { McpServer as McpServer8 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
26311
|
-
import { z as
|
|
26366
|
+
import { z as z11 } from "zod";
|
|
26312
26367
|
var defaultTokenStatsMcpHost = {
|
|
26313
26368
|
getStats,
|
|
26314
26369
|
calcCost
|
|
@@ -26328,11 +26383,11 @@ function createTokenStatsMcpServer(context, host = defaultTokenStatsMcpHost) {
|
|
|
26328
26383
|
"groupBy: 'session'\uC73C\uB85C \uC124\uC815\uD558\uBA74 \uC138\uC158\uBCC4 \uD1A0\uD070 \uC0AC\uC6A9\uB7C9 \uB7AD\uD0B9\uC744 \uBC18\uD658\uD569\uB2C8\uB2E4."
|
|
26329
26384
|
].join(`
|
|
26330
26385
|
`), {
|
|
26331
|
-
from:
|
|
26332
|
-
to:
|
|
26333
|
-
groupBy:
|
|
26334
|
-
}, async ({ from, to, groupBy = "hour" }) => {
|
|
26335
|
-
const snapshot = host.getStats(context.userId, from,
|
|
26386
|
+
from: z11.string().optional().describe("\uC2DC\uC791 \uC2DC\uAC01 ISO 8601. \uC608: '2026-03-28T09:00:00Z'"),
|
|
26387
|
+
to: z11.string().optional().describe("\uC885\uB8CC \uC2DC\uAC01 ISO 8601. \uC0DD\uB7B5 \uC2DC \uD604\uC7AC"),
|
|
26388
|
+
groupBy: z11.enum(["hour", "session"]).optional().describe("\uC9D1\uACC4 \uAE30\uC900. \uAE30\uBCF8\uAC12: hour")
|
|
26389
|
+
}, async ({ from, to: to2, groupBy = "hour" }) => {
|
|
26390
|
+
const snapshot = host.getStats(context.userId, from, to2);
|
|
26336
26391
|
const {
|
|
26337
26392
|
total,
|
|
26338
26393
|
byHour,
|
|
@@ -26343,7 +26398,7 @@ function createTokenStatsMcpServer(context, host = defaultTokenStatsMcpHost) {
|
|
|
26343
26398
|
} = snapshot;
|
|
26344
26399
|
const lines = [
|
|
26345
26400
|
"\uD83D\uDCCA Agent \uC0AC\uC6A9\uB7C9",
|
|
26346
|
-
from ||
|
|
26401
|
+
from || to2 ? `\uAE30\uAC04: ${from ?? "\uC804\uCCB4"} ~ ${to2 ?? "\uD604\uC7AC"}` : "\uAE30\uAC04: \uC804\uCCB4",
|
|
26347
26402
|
"",
|
|
26348
26403
|
`\uCFFC\uB9AC \uD69F\uC218: ${total.queries.toLocaleString()}\uD68C`,
|
|
26349
26404
|
`\uCE90\uC2DC \uBBF8\uC801\uC911 \uC785\uB825: ${total.inputTokens.toLocaleString()}`,
|
|
@@ -26441,4 +26496,4 @@ export {
|
|
|
26441
26496
|
createAgentHealthMcpServer
|
|
26442
26497
|
};
|
|
26443
26498
|
|
|
26444
|
-
//# debugId=
|
|
26499
|
+
//# debugId=520A60CFD9E38F3664756E2164756E21
|