negotium 0.2.33 → 0.3.1
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 +57 -5
- package/dist/agent-helpers.js.map +12 -12
- package/dist/background-bash.js +3 -2
- package/dist/background-bash.js.map +4 -4
- package/dist/browser-runtime.js +3 -2
- package/dist/browser-runtime.js.map +4 -4
- package/dist/chunk-s2gez3wg.js.map +1 -1
- package/dist/{chunk-1y2xw0xe.js → chunk-vvfwqxnh.js} +33 -3
- package/dist/{chunk-1y2xw0xe.js.map → chunk-vvfwqxnh.js.map} +8 -8
- package/dist/hosted-agent.js +34 -4
- package/dist/hosted-agent.js.map +8 -8
- package/dist/main.js +1135 -370
- package/dist/main.js.map +27 -24
- package/dist/mcp-catalog.js +2 -1
- package/dist/mcp-catalog.js.map +3 -3
- package/dist/mcp-factories.js +585 -255
- package/dist/mcp-factories.js.map +16 -14
- package/dist/mcp-servers.js +3 -1
- package/dist/mcp-servers.js.map +3 -3
- package/dist/prompts.js +8 -2
- package/dist/prompts.js.map +5 -5
- package/dist/query-runtime.js +3 -2
- package/dist/query-runtime.js.map +4 -4
- package/dist/registry.js +3 -3
- package/dist/registry.js.map +2 -2
- package/dist/rollout.js +1 -1
- package/dist/runtime/cron/mcp-server.ts +2 -2
- package/dist/runtime/src/mcp/canonical-bridge-config.ts +1 -1
- package/dist/runtime/src/mcp/canonical-proxy-server.ts +74 -1
- package/dist/runtime/src/mcp/decision-server.ts +21 -0
- package/dist/runtime/src/mcp/factories/decision.ts +178 -0
- package/dist/runtime/src/mcp/factories/index.ts +6 -0
- package/dist/runtime/src/mcp/runtime-spec.ts +1 -0
- package/dist/runtime/src/mcp/session-comm/topic-config.ts +7 -1
- package/dist/runtime/src/node-host.ts +1 -0
- package/dist/runtime/src/platform/config.ts +2 -1
- package/dist/runtime/src/platform/mcp-catalog-policy.ts +1 -0
- package/dist/runtime/src/platform/mcp-config.ts +31 -1
- package/dist/runtime/src/prompts/builders.ts +5 -0
- package/dist/runtime/src/runtime/inbox.ts +6 -4
- package/dist/runtime/src/runtime/visual-html.ts +18 -1
- package/dist/runtime/src/storage/api-topics.ts +30 -2
- package/dist/runtime/src/storage/decisions.ts +231 -0
- package/dist/runtime/src/storage/storage-public.ts +2 -0
- package/dist/runtime/src/types.ts +13 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js +21 -3
- package/dist/runtime-helpers.js.map +5 -5
- package/dist/storage.js +263 -57
- package/dist/storage.js.map +6 -5
- package/dist/types/apps/negotium/src/mcp-servers.d.ts +1 -1
- package/dist/types/packages/core/src/mcp/canonical-bridge-config.d.ts +1 -1
- package/dist/types/packages/core/src/mcp/factories/decision.d.ts +16 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +1 -0
- package/dist/types/packages/core/src/mcp/runtime-spec.d.ts +1 -1
- package/dist/types/packages/core/src/platform/config.d.ts +2 -1
- package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +4 -0
- package/dist/types/packages/core/src/storage/api-topics.d.ts +29 -4
- package/dist/types/packages/core/src/storage/decisions.d.ts +45 -0
- package/dist/types/packages/core/src/storage/storage-public.d.ts +2 -0
- package/dist/types/packages/core/src/types.d.ts +12 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +3 -2
- package/dist/vault.js.map +4 -4
- package/install-browser-rs.mjs +3 -3
- package/package.json +2 -2
|
@@ -85,6 +85,72 @@ const taskTools: Tool[] = [
|
|
|
85
85
|
},
|
|
86
86
|
];
|
|
87
87
|
|
|
88
|
+
const decisionStatus = ["proposed", "accepted", "executed", "rejected", "superseded"];
|
|
89
|
+
const decisionFields = {
|
|
90
|
+
action: { type: "string" },
|
|
91
|
+
reasoning: { type: "string" },
|
|
92
|
+
status: { type: "string", enum: decisionStatus },
|
|
93
|
+
caused_by: { type: "array", items: { type: "string" } },
|
|
94
|
+
} as const;
|
|
95
|
+
const decisionTools: Tool[] = [
|
|
96
|
+
{
|
|
97
|
+
name: "decision_create",
|
|
98
|
+
description: "Record durable decisions and their causal predecessors in this topic.",
|
|
99
|
+
inputSchema: {
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: {
|
|
102
|
+
decisions: {
|
|
103
|
+
type: "array",
|
|
104
|
+
minItems: 1,
|
|
105
|
+
items: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: decisionFields,
|
|
108
|
+
required: ["action", "reasoning"],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ["decisions"],
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: "decision_update",
|
|
117
|
+
description: "Update decisions or causal links in this topic.",
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: "object",
|
|
120
|
+
properties: {
|
|
121
|
+
updates: {
|
|
122
|
+
type: "array",
|
|
123
|
+
minItems: 1,
|
|
124
|
+
items: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: { id: { type: "string" }, ...decisionFields },
|
|
127
|
+
required: ["id"],
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
required: ["updates"],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "decision_list",
|
|
136
|
+
description: "Read this topic's decisions.",
|
|
137
|
+
inputSchema: { type: "object", properties: {} },
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: "decision_get",
|
|
141
|
+
description: "Read one decision as JSON.",
|
|
142
|
+
inputSchema: { type: "object", properties: { id: { type: "string" } }, required: ["id"] },
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: "decision_delete",
|
|
146
|
+
description: "Delete decisions from this topic.",
|
|
147
|
+
inputSchema: {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: { ids: { type: "array", items: { type: "string" } }, all: { type: "boolean" } },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
];
|
|
153
|
+
|
|
88
154
|
const wikiTools: Tool[] = [
|
|
89
155
|
{
|
|
90
156
|
name: "wiki_query",
|
|
@@ -160,7 +226,14 @@ const wikiTools: Tool[] = [
|
|
|
160
226
|
},
|
|
161
227
|
];
|
|
162
228
|
|
|
163
|
-
const tools =
|
|
229
|
+
const tools =
|
|
230
|
+
surface === "task"
|
|
231
|
+
? taskTools
|
|
232
|
+
: surface === "decision"
|
|
233
|
+
? decisionTools
|
|
234
|
+
: surface === "wiki"
|
|
235
|
+
? wikiTools
|
|
236
|
+
: [];
|
|
164
237
|
const allowed = new Set(tools.map((tool) => tool.name));
|
|
165
238
|
|
|
166
239
|
function error(text: string): CallToolResult {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import "./stdio-protect";
|
|
3
|
+
import { createDecisionMcpServer } from "#mcp/factories/decision";
|
|
4
|
+
import { connectStdio, parseUserIdArg } from "#mcp/mcp-helpers";
|
|
5
|
+
import { isAgentKind } from "#types";
|
|
6
|
+
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const topic = args.find((arg) => arg.startsWith("--topic="))?.slice("--topic=".length) || "";
|
|
9
|
+
const topicId = args.find((arg) => arg.startsWith("--topic-id="))?.slice("--topic-id=".length);
|
|
10
|
+
const agentArg = args.find((arg) => arg.startsWith("--agent="))?.slice("--agent=".length);
|
|
11
|
+
const model = args.find((arg) => arg.startsWith("--model="))?.slice("--model=".length);
|
|
12
|
+
|
|
13
|
+
await connectStdio(
|
|
14
|
+
createDecisionMcpServer({
|
|
15
|
+
userId: parseUserIdArg(args),
|
|
16
|
+
topic,
|
|
17
|
+
topicId,
|
|
18
|
+
agent: agentArg && isAgentKind(agentArg) ? agentArg : "codex",
|
|
19
|
+
model,
|
|
20
|
+
}),
|
|
21
|
+
);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { errMsg } from "#platform/error";
|
|
4
|
+
import {
|
|
5
|
+
createDecisions,
|
|
6
|
+
DECISION_STATUS_VALUES,
|
|
7
|
+
decisionScopeKey,
|
|
8
|
+
deleteDecisions,
|
|
9
|
+
readDecisions,
|
|
10
|
+
renderDecisionList,
|
|
11
|
+
type StoredDecision,
|
|
12
|
+
updateDecisions,
|
|
13
|
+
writeDecisions,
|
|
14
|
+
} from "#storage/decisions";
|
|
15
|
+
import type { AgentKind } from "#types";
|
|
16
|
+
import { mcpError, mcpOk } from "../mcp-helpers";
|
|
17
|
+
|
|
18
|
+
export interface DecisionMcpContext {
|
|
19
|
+
userId: string;
|
|
20
|
+
topic: string;
|
|
21
|
+
topicId?: string;
|
|
22
|
+
agent: AgentKind;
|
|
23
|
+
model?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface DecisionMcpHost {
|
|
27
|
+
readDecisions(userId: string, scopeKey: string): StoredDecision[];
|
|
28
|
+
writeDecisions(userId: string, scopeKey: string, decisions: StoredDecision[]): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const defaultDecisionMcpHost: DecisionMcpHost = { readDecisions, writeDecisions };
|
|
32
|
+
|
|
33
|
+
export function createDecisionMcpServer(
|
|
34
|
+
context: DecisionMcpContext,
|
|
35
|
+
host: DecisionMcpHost = defaultDecisionMcpHost,
|
|
36
|
+
): McpServer {
|
|
37
|
+
const scopeKey = context.topic
|
|
38
|
+
? decisionScopeKey({ topicId: context.topicId, session: context.topic })
|
|
39
|
+
: "";
|
|
40
|
+
const server = new McpServer({ name: "decision", version: "1.0.0" });
|
|
41
|
+
const requireContext = (): ReturnType<typeof mcpError> | null =>
|
|
42
|
+
!context.userId || !scopeKey ? mcpError("Error: missing userId/topic context.") : null;
|
|
43
|
+
const statusEnum = z.enum(DECISION_STATUS_VALUES);
|
|
44
|
+
|
|
45
|
+
server.tool(
|
|
46
|
+
"decision_create",
|
|
47
|
+
"Record one or more durable decisions in this topic. Include the rationale and causal predecessors.",
|
|
48
|
+
{
|
|
49
|
+
decisions: z
|
|
50
|
+
.array(
|
|
51
|
+
z.object({
|
|
52
|
+
action: z.string().min(1).describe("Concise statement of what was decided"),
|
|
53
|
+
reasoning: z.string().min(1).describe("Why this choice was made"),
|
|
54
|
+
status: statusEnum.optional().describe("Defaults to accepted"),
|
|
55
|
+
caused_by: z.array(z.string()).optional().describe("Upstream decision ids"),
|
|
56
|
+
}),
|
|
57
|
+
)
|
|
58
|
+
.min(1),
|
|
59
|
+
},
|
|
60
|
+
async ({ decisions: inputs }) => {
|
|
61
|
+
const guard = requireContext();
|
|
62
|
+
if (guard) return guard;
|
|
63
|
+
try {
|
|
64
|
+
const current = host.readDecisions(context.userId, scopeKey);
|
|
65
|
+
const { decisions, created } = createDecisions(
|
|
66
|
+
current,
|
|
67
|
+
inputs.map((input) => ({
|
|
68
|
+
action: input.action,
|
|
69
|
+
reasoning: input.reasoning,
|
|
70
|
+
status: input.status,
|
|
71
|
+
causedBy: input.caused_by,
|
|
72
|
+
agent: context.agent,
|
|
73
|
+
model: context.model,
|
|
74
|
+
})),
|
|
75
|
+
);
|
|
76
|
+
host.writeDecisions(context.userId, scopeKey, decisions);
|
|
77
|
+
return mcpOk(
|
|
78
|
+
`${created.length} decision(s) recorded (${created.map((item) => `#${item.id}`).join(", ")})\n\n${renderDecisionList(decisions)}`,
|
|
79
|
+
);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return mcpError(`decision_create failed: ${errMsg(error)}`);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
server.tool(
|
|
87
|
+
"decision_update",
|
|
88
|
+
"Update decisions or their causal links in this topic.",
|
|
89
|
+
{
|
|
90
|
+
updates: z
|
|
91
|
+
.array(
|
|
92
|
+
z.object({
|
|
93
|
+
id: z.string(),
|
|
94
|
+
action: z.string().min(1).optional(),
|
|
95
|
+
reasoning: z.string().min(1).optional(),
|
|
96
|
+
status: statusEnum.optional(),
|
|
97
|
+
caused_by: z.array(z.string()).optional().describe("Replacement upstream decision ids"),
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
.min(1),
|
|
101
|
+
},
|
|
102
|
+
async ({ updates }) => {
|
|
103
|
+
const guard = requireContext();
|
|
104
|
+
if (guard) return guard;
|
|
105
|
+
try {
|
|
106
|
+
const current = host.readDecisions(context.userId, scopeKey);
|
|
107
|
+
const { decisions, missing } = updateDecisions(
|
|
108
|
+
current,
|
|
109
|
+
updates.map((update) => ({
|
|
110
|
+
...update,
|
|
111
|
+
causedBy: update.caused_by,
|
|
112
|
+
})),
|
|
113
|
+
);
|
|
114
|
+
host.writeDecisions(context.userId, scopeKey, decisions);
|
|
115
|
+
const warning = missing.length ? `\nMissing ids ignored: ${missing.join(", ")}` : "";
|
|
116
|
+
return mcpOk(`${renderDecisionList(decisions)}${warning}`);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
return mcpError(`decision_update failed: ${errMsg(error)}`);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
server.tool(
|
|
124
|
+
"decision_list",
|
|
125
|
+
"Read this topic's decision graph as a concise list.",
|
|
126
|
+
{},
|
|
127
|
+
async () => {
|
|
128
|
+
const guard = requireContext();
|
|
129
|
+
if (guard) return guard;
|
|
130
|
+
try {
|
|
131
|
+
return mcpOk(renderDecisionList(host.readDecisions(context.userId, scopeKey)));
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return mcpError(`decision_list failed: ${errMsg(error)}`);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
server.tool(
|
|
139
|
+
"decision_get",
|
|
140
|
+
"Read one topic decision as JSON.",
|
|
141
|
+
{ id: z.string() },
|
|
142
|
+
async ({ id }) => {
|
|
143
|
+
const guard = requireContext();
|
|
144
|
+
if (guard) return guard;
|
|
145
|
+
try {
|
|
146
|
+
const decision = host
|
|
147
|
+
.readDecisions(context.userId, scopeKey)
|
|
148
|
+
.find((item) => item.id === id);
|
|
149
|
+
return decision
|
|
150
|
+
? mcpOk(JSON.stringify(decision, null, 2))
|
|
151
|
+
: mcpError(`Decision #${id} not found.`);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return mcpError(`decision_get failed: ${errMsg(error)}`);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
server.tool(
|
|
159
|
+
"decision_delete",
|
|
160
|
+
"Delete decisions. Downstream causal references to deleted decisions are removed.",
|
|
161
|
+
{ ids: z.array(z.string()).optional(), all: z.boolean().optional() },
|
|
162
|
+
async ({ ids, all }) => {
|
|
163
|
+
const guard = requireContext();
|
|
164
|
+
if (guard) return guard;
|
|
165
|
+
if (!all && (!ids || ids.length === 0)) return mcpError("Provide ids or all=true.");
|
|
166
|
+
try {
|
|
167
|
+
const current = host.readDecisions(context.userId, scopeKey);
|
|
168
|
+
const { decisions, removed } = deleteDecisions(current, { ids, all });
|
|
169
|
+
host.writeDecisions(context.userId, scopeKey, decisions);
|
|
170
|
+
return mcpOk(`${removed} decision(s) deleted\n\n${renderDecisionList(decisions)}`);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
return mcpError(`decision_delete failed: ${errMsg(error)}`);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
return server;
|
|
178
|
+
}
|
|
@@ -29,6 +29,12 @@ export {
|
|
|
29
29
|
type CompactionLogMcpContext,
|
|
30
30
|
createCompactionLogMcpServer,
|
|
31
31
|
} from "./compaction-log";
|
|
32
|
+
export {
|
|
33
|
+
createDecisionMcpServer,
|
|
34
|
+
type DecisionMcpContext,
|
|
35
|
+
type DecisionMcpHost,
|
|
36
|
+
defaultDecisionMcpHost,
|
|
37
|
+
} from "./decision";
|
|
32
38
|
export {
|
|
33
39
|
createSessionCommMcpServer,
|
|
34
40
|
type SessionCommMcpHost,
|
|
@@ -40,7 +40,13 @@ export function currentApiTopicId(): string | null {
|
|
|
40
40
|
}
|
|
41
41
|
if (!currentTopic) return null;
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
// Resolving THIS session's own room from its title, reached only when the
|
|
44
|
+
// host started us without a topic id. The surface we would scope to is the
|
|
45
|
+
// very thing being determined, so there is nothing to narrow by; the
|
|
46
|
+
// participation filter inside the lookup is what keeps it honest, and a
|
|
47
|
+
// title shared across surfaces resolves to null rather than to a guess.
|
|
48
|
+
// Hosts that pass `--topic-id` — every current one — never come here.
|
|
49
|
+
return getTopicByNameForUser(currentTopic, userId, { scope: "all" })?.id ?? null;
|
|
44
50
|
} catch (e) {
|
|
45
51
|
process.stderr.write(`warn: session-comm: api topic lookup failed: ${e}\n`);
|
|
46
52
|
return null;
|
|
@@ -67,6 +67,7 @@ export { startSessionInboxWorker } from "#runtime/inbox";
|
|
|
67
67
|
export { startAiTurn, startDurableTurnRequestWorker } from "#runtime/turn-runner";
|
|
68
68
|
export { appendApiMessage, getApiMessage, listApiMessages } from "#storage/api-messages";
|
|
69
69
|
export { getTopic, upsertTopic } from "#storage/api-topics";
|
|
70
|
+
export { readDecisions, writeDecisionGraphSvg } from "#storage/decisions";
|
|
70
71
|
export type { StoredRuntimeEvent } from "#storage/runtime-events";
|
|
71
72
|
export {
|
|
72
73
|
latestRuntimeEventSeq,
|
|
@@ -99,7 +99,7 @@ export function resolveOutputLanguage(): string {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
/** Browser.rs release tested with this Negotium version. */
|
|
102
|
-
export const BROWSER_RS_VERSION = "v0.1.
|
|
102
|
+
export const BROWSER_RS_VERSION = "v0.1.21";
|
|
103
103
|
/** Require the authenticated listener and the current Browser.rs tool contract. */
|
|
104
104
|
export const BROWSER_RS_MIN_SECURE_VERSION = "0.1.15";
|
|
105
105
|
|
|
@@ -277,6 +277,7 @@ export const TSCONFIG_PATH = resolve(PROJECT_ROOT, "tsconfig.json");
|
|
|
277
277
|
export const SESSION_COMM_SERVER = resolve(PROJECT_ROOT, "src/mcp/session-comm/server.ts");
|
|
278
278
|
|
|
279
279
|
export const TASK_SERVER = resolve(PROJECT_ROOT, "src/mcp/task-server.ts");
|
|
280
|
+
export const DECISION_SERVER = resolve(PROJECT_ROOT, "src/mcp/decision-server.ts");
|
|
280
281
|
export const BROWSER_MCP_SSE_PROXY_SERVER = resolve(
|
|
281
282
|
PROJECT_ROOT,
|
|
282
283
|
"src/mcp/browser-sse-proxy-server.ts",
|
|
@@ -11,6 +11,7 @@ export const COMMON_RUNTIME_MCP_POLICY = {
|
|
|
11
11
|
runtime: { scopes: ["forum", "manager", "fork", "cron"], forumRequired: true },
|
|
12
12
|
"token-stats": { scopes: ["dm", "forum", "manager", "cron"], forumRequired: true },
|
|
13
13
|
task: { scopes: ["dm", "forum", "manager", "cron"], forumRequired: true },
|
|
14
|
+
decision: { scopes: ["dm", "forum", "manager", "cron"], forumRequired: true },
|
|
14
15
|
"session-comm": { scopes: ["forum", "fork", "manager"], forumRequired: true },
|
|
15
16
|
wiki: { scopes: ["dm", "forum", "manager", "cron"], forumRequired: true },
|
|
16
17
|
skills: { scopes: ["dm", "forum", "manager", "cron"], forumRequired: true },
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
AGENT_HEALTH_SERVER,
|
|
12
12
|
BROWSER_MCP_SSE_PROXY_SERVER,
|
|
13
13
|
CANONICAL_MCP_PROXY_SERVER,
|
|
14
|
+
DECISION_SERVER,
|
|
14
15
|
envText,
|
|
15
16
|
FALLBACK_AGENT,
|
|
16
17
|
resolveTopicWorkspaceDir,
|
|
@@ -417,6 +418,35 @@ const MCP_CATALOG: Record<string, RuntimeMcpCatalogEntry> = {
|
|
|
417
418
|
);
|
|
418
419
|
},
|
|
419
420
|
},
|
|
421
|
+
decision: {
|
|
422
|
+
...commonRuntimeMcpPolicy("decision"),
|
|
423
|
+
build(ctx) {
|
|
424
|
+
const { userId, session, topicId, queryId, agent, model, peerBridge } = ctx;
|
|
425
|
+
if (peerBridge) {
|
|
426
|
+
if (!topicId || !queryId) return null;
|
|
427
|
+
const env = canonicalMcpBridgeEnv({
|
|
428
|
+
surface: "decision",
|
|
429
|
+
userId,
|
|
430
|
+
topicId,
|
|
431
|
+
queryId,
|
|
432
|
+
peerBridge,
|
|
433
|
+
});
|
|
434
|
+
return env
|
|
435
|
+
? buildStdioMcpServer(agent, CANONICAL_MCP_PROXY_SERVER, ["--surface=decision"], env)
|
|
436
|
+
: null;
|
|
437
|
+
}
|
|
438
|
+
const args = [
|
|
439
|
+
`--user-id=${userId}`,
|
|
440
|
+
`--topic=${session}`,
|
|
441
|
+
`--agent=${agent ?? FALLBACK_AGENT}`,
|
|
442
|
+
];
|
|
443
|
+
if (topicId) args.push(`--topic-id=${topicId}`);
|
|
444
|
+
if (model) args.push(`--model=${model}`);
|
|
445
|
+
return buildBuiltinMcpServer("decision", ctx, () =>
|
|
446
|
+
buildStdioMcpServer(agent, DECISION_SERVER, args),
|
|
447
|
+
);
|
|
448
|
+
},
|
|
449
|
+
},
|
|
420
450
|
"session-comm": {
|
|
421
451
|
// Exposed in `manager` scope as well so the General-topic manager agent
|
|
422
452
|
// can wake fresh-created topics via tell_session/ask_session right after
|
|
@@ -818,7 +848,7 @@ export function getForumMcpServers(opts: {
|
|
|
818
848
|
} = opts;
|
|
819
849
|
|
|
820
850
|
const filter = (name: string) => {
|
|
821
|
-
if (silent && name === "task") return false;
|
|
851
|
+
if (silent && (name === "task" || name === "decision")) return false;
|
|
822
852
|
if (enabled === null) return true;
|
|
823
853
|
return (
|
|
824
854
|
enabled.includes(name) || (REQUIRED_FORUM_MCP_SERVERS as readonly string[]).includes(name)
|
|
@@ -274,6 +274,7 @@ function buildRuntimeToolSection(
|
|
|
274
274
|
} = opts;
|
|
275
275
|
const runtimeNamespace = "mcp__runtime";
|
|
276
276
|
const taskNamespace = "mcp__task";
|
|
277
|
+
const decisionNamespace = "mcp__decision";
|
|
277
278
|
const visualToolLine =
|
|
278
279
|
agentKind === "codex"
|
|
279
280
|
? `To display charts, tables, or interactive HTML results to the user, call the \`show_html\` function in the \`${runtimeNamespace}\` namespace with { html: "<complete HTML string>", title?: "optional title" }.`
|
|
@@ -302,6 +303,7 @@ function buildRuntimeToolSection(
|
|
|
302
303
|
agentKind === "codex"
|
|
303
304
|
? `For task tracking, use \`task_create\`, \`task_update\`, \`task_list\`, \`task_get\`, and \`task_delete\` functions in the \`${taskNamespace}\` namespace.`
|
|
304
305
|
: `For task tracking, use MCP tools "${taskNamespace}__task_create", "${taskNamespace}__task_update", "${taskNamespace}__task_list", "${taskNamespace}__task_get", and "${taskNamespace}__task_delete".`;
|
|
306
|
+
const decisionToolLine = `Use the shared Decision tools in the \`${decisionNamespace}\` namespace when an architectural, product, or operational choice establishes or changes a durable direction or constraint. Do not record routine task progress or temporary implementation details; link causal predecessors when relevant.`;
|
|
305
307
|
const runtimeToolRef = (name: string): string =>
|
|
306
308
|
agentKind === "codex" ? `\`${name}\`` : `"${runtimeNamespace}__${name}"`;
|
|
307
309
|
const spawnSubagentToolLine = `Use ${runtimeToolRef("spawn_subagent")} for self-contained parallel or long-running background work; keep quick work inline.`;
|
|
@@ -364,6 +366,9 @@ function buildRuntimeToolSection(
|
|
|
364
366
|
taskToolLine,
|
|
365
367
|
"Use this shared task store for plans, progress, and checklist updates; it is visible across claude/codex/maestro turns.",
|
|
366
368
|
nativeTaskPolicyLine,
|
|
369
|
+
"",
|
|
370
|
+
"## Shared Decisions",
|
|
371
|
+
decisionToolLine,
|
|
367
372
|
...extensions.render("after-shared-tasks"),
|
|
368
373
|
...fileDeliverySection,
|
|
369
374
|
...extensions.render("before-session-communication"),
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
} from "#query/session-inbox-path";
|
|
33
33
|
import { AbortReason } from "#query/types";
|
|
34
34
|
import { appendApiMessage, getApiMessage } from "#storage/api-messages";
|
|
35
|
+
import type { TopicNameLookupScope } from "#storage/api-topics";
|
|
35
36
|
import type { ConversationEntry } from "#storage/conversations";
|
|
36
37
|
import { RUNTIME_INSTANCE_ID } from "#storage/runtime-leases";
|
|
37
38
|
import {
|
|
@@ -216,10 +217,10 @@ function callerScope(
|
|
|
216
217
|
return surface ? { kind: "surface", on: surface as TopicSurface } : { kind: "deny" };
|
|
217
218
|
}
|
|
218
219
|
|
|
219
|
-
/** `getTopicByNameForUser`
|
|
220
|
-
function scopeToLookupOpts(scope: CallerScope):
|
|
220
|
+
/** `getTopicByNameForUser` scope for a caller scope, or null when it must not run. */
|
|
221
|
+
function scopeToLookupOpts(scope: CallerScope): TopicNameLookupScope | null {
|
|
221
222
|
if (scope.kind === "deny") return null;
|
|
222
|
-
return scope.kind === "surface" ? { surface: scope.on } : {};
|
|
223
|
+
return scope.kind === "surface" ? { surface: scope.on } : { scope: "all" };
|
|
223
224
|
}
|
|
224
225
|
|
|
225
226
|
async function resolveEntryCallerTopic(
|
|
@@ -733,11 +734,12 @@ async function handleAbortEntry(
|
|
|
733
734
|
// Closing it properly means adding sender identity to the abort entry format
|
|
734
735
|
// and is a wire-format change, not a call-site fix — deliberately left out
|
|
735
736
|
// of this change rather than papered over with a scope that is always empty.
|
|
737
|
+
// `scope: "all"` states that here instead of leaving it to a default.
|
|
736
738
|
const topic = topicId
|
|
737
739
|
? byId?.participants.some((participant) => participant.userId === userId)
|
|
738
740
|
? byId
|
|
739
741
|
: null
|
|
740
|
-
: getTopicByNameForUser(topicName, userId);
|
|
742
|
+
: getTopicByNameForUser(topicName, userId, { scope: "all" });
|
|
741
743
|
if (!topic) {
|
|
742
744
|
logger.warn({ topicName }, "session-inbox: abort for unknown topic, skipping");
|
|
743
745
|
return;
|
|
@@ -55,6 +55,10 @@ export function buildMermaidHtml(
|
|
|
55
55
|
.controls button:focus-visible{outline:2px solid var(--celadon);outline-offset:1px}
|
|
56
56
|
.zoom-value{min-width:46px;color:var(--graphite);font:500 11px/1 Geist,system-ui,sans-serif;text-align:center;font-variant-numeric:tabular-nums}
|
|
57
57
|
.error{margin:0;white-space:pre-wrap;color:#7D2E2E;background:#FFF5F2;border:1px solid #E4B9B1;border-radius:6px;padding:14px;font:13px ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
58
|
+
.failure{max-width:56ch;margin:0 auto}
|
|
59
|
+
.failure p{margin:0 0 12px;color:var(--graphite);font:14px/1.6 Geist,system-ui,sans-serif}
|
|
60
|
+
.failure details{color:var(--graphite);font:12px/1.5 Geist,system-ui,sans-serif}
|
|
61
|
+
.failure summary{cursor:pointer;padding:4px 0}
|
|
58
62
|
@media(max-width:600px){.viewport{padding:54px 14px 18px}.controls{top:10px;right:10px}}
|
|
59
63
|
</style>
|
|
60
64
|
</head>
|
|
@@ -100,7 +104,20 @@ export function buildMermaidHtml(
|
|
|
100
104
|
applyScale(scale, false);
|
|
101
105
|
} catch (error) {
|
|
102
106
|
document.querySelector(".controls")?.remove();
|
|
103
|
-
|
|
107
|
+
const raw = String(error && error.message ? error.message : error);
|
|
108
|
+
const escape = (value) => value.replace(/[&<>]/g, c => ({'&':'&','<':'<','>':'>'}[c]));
|
|
109
|
+
// Mermaid aborts the whole render when it cannot place an edge label:
|
|
110
|
+
// cardinality markers ask for a point a fixed distance along the edge,
|
|
111
|
+
// and a relation laid out shorter than that walks off the end. Nothing
|
|
112
|
+
// is wrong with the diagram, so the raw message sends authors looking
|
|
113
|
+
// for a syntax error that does not exist. Say what actually moves it.
|
|
114
|
+
const note = raw.indexOf("Could not find a suitable point") !== -1
|
|
115
|
+
? "Two nodes ended up too close together for Mermaid to fit a label on the edge between them. Renaming a node, adding another, or setting an explicit direction usually spreads the layout enough to render."
|
|
116
|
+
: "This diagram could not be rendered.";
|
|
117
|
+
document.querySelector(".viewport").innerHTML =
|
|
118
|
+
'<div class="failure"><p>' + escape(note) +
|
|
119
|
+
'</p><details><summary>Technical detail</summary><pre class="error">' +
|
|
120
|
+
escape(raw) + '</pre></details></div>';
|
|
104
121
|
}
|
|
105
122
|
})();
|
|
106
123
|
</script>
|
|
@@ -1128,12 +1128,40 @@ export function setTopicSurfaces(topicIds: readonly string[], surface: TopicSurf
|
|
|
1128
1128
|
return changed;
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
|
-
/**
|
|
1131
|
+
/**
|
|
1132
|
+
* How wide a title lookup is allowed to reach.
|
|
1133
|
+
*
|
|
1134
|
+
* `surface` is required rather than optional. It used to default to "search
|
|
1135
|
+
* every surface", which contradicted S-6's promise that a missed call site
|
|
1136
|
+
* "cannot leak a topic across surfaces" — the guarantee only held where a
|
|
1137
|
+
* caller remembered to opt in, and four did not: Telegram's `/load` and `/del`
|
|
1138
|
+
* (the latter could delete a terminal room), the runtime MCP id path, the cron
|
|
1139
|
+
* id path, and the session inbox. Every one of those was a silent leak with a
|
|
1140
|
+
* correct-looking call. Making the parameter explicit turns each future
|
|
1141
|
+
* omission into a compile error instead.
|
|
1142
|
+
*
|
|
1143
|
+
* `{ scope: "all" }` is the deliberate way to search every surface. It exists
|
|
1144
|
+
* for operator tooling — the CLI manages jobs across surfaces on purpose — and
|
|
1145
|
+
* reads as a decision at the call site rather than as an oversight.
|
|
1146
|
+
*/
|
|
1147
|
+
export type TopicNameLookupScope =
|
|
1148
|
+
| { surface: TopicSurface; surfaceScope?: string | null }
|
|
1149
|
+
| { scope: "all" };
|
|
1150
|
+
|
|
1151
|
+
/**
|
|
1152
|
+
* Look up a topic by title, restricted to topics where `userId` participates.
|
|
1153
|
+
*
|
|
1154
|
+
* Answers only on a single match: a title is unique per surface (S-3), so an
|
|
1155
|
+
* `{ scope: "all" }` lookup of a name used on two surfaces resolves to null
|
|
1156
|
+
* rather than picking one.
|
|
1157
|
+
*/
|
|
1132
1158
|
export function getTopicByNameForUser(
|
|
1133
1159
|
title: string,
|
|
1134
1160
|
userId: string,
|
|
1135
|
-
|
|
1161
|
+
lookupScope: TopicNameLookupScope,
|
|
1136
1162
|
): TopicDto | null {
|
|
1163
|
+
const opts: { surface?: TopicSurface; surfaceScope?: string | null } =
|
|
1164
|
+
"scope" in lookupScope ? {} : lookupScope;
|
|
1137
1165
|
const trimmed = title.trim();
|
|
1138
1166
|
const qualified = /^(agent|channel|manager):(.+)$/i.exec(trimmed);
|
|
1139
1167
|
const requestedKind = qualified ? normalizeTopicKind(qualified[1]?.toLowerCase()) : null;
|