@otium-team/negotium 0.23.15 → 0.24.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 +969 -245
- package/dist/agent-helpers.js.map +13 -10
- package/dist/{chunk-ng13grfj.js → chunk-fzfzskjq.js} +18 -2
- package/dist/{chunk-ng13grfj.js.map → chunk-fzfzskjq.js.map} +4 -4
- package/dist/{chunk-m1ngkjdd.js → chunk-hn2cqdd0.js} +1 -1
- package/dist/{chunk-3hf8y6bd.js → chunk-kfckfff2.js} +3 -3
- package/dist/{chunk-3hf8y6bd.js.map → chunk-kfckfff2.js.map} +2 -2
- package/dist/hosted-agent.js +19 -3
- package/dist/hosted-agent.js.map +5 -5
- package/dist/main.js +3744 -2928
- package/dist/main.js.map +18 -15
- package/dist/mcp-factories.js +959 -229
- package/dist/mcp-factories.js.map +14 -11
- package/dist/prompts.js +221 -1
- package/dist/prompts.js.map +7 -5
- package/dist/registry.js +3 -3
- package/dist/rollout.js +2 -2
- package/dist/runtime/src/agents/mcp-tools/ask-user.ts +56 -1
- package/dist/runtime/src/application/submit-runtime-gateway-turn.ts +71 -0
- package/dist/runtime/src/application/turn-follow-ups.ts +7 -0
- package/dist/runtime/src/mcp/wiki-server.ts +8 -0
- package/dist/runtime/src/platform/mcp-config.ts +26 -0
- package/dist/runtime/src/prompts/builders.ts +5 -0
- package/dist/runtime/src/runtime/turn-runner.ts +65 -1
- package/dist/runtime/src/storage/api-topics.ts +29 -0
- package/dist/runtime/src/topics/agent-plugins/mcp.schema.json +120 -0
- package/dist/runtime/src/topics/agent-plugins/plugin.schema.json +65 -0
- package/dist/runtime/src/topics/plugin-server-instructions.ts +201 -0
- package/dist/runtime/src/topics/plugin-turn.ts +37 -0
- package/dist/runtime/src/topics/plugins.ts +445 -0
- package/dist/runtime/src/topics/update.ts +34 -0
- package/dist/runtime/src/types/api.ts +5 -0
- package/dist/runtime/src/version.ts +1 -1
- package/dist/storage.js +23 -2
- package/dist/storage.js.map +3 -3
- package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +14 -0
- package/dist/types/packages/core/src/platform/mcp-config.d.ts +6 -0
- package/dist/types/packages/core/src/prompts/builders.d.ts +3 -0
- package/dist/types/packages/core/src/runtime/turn-runner.d.ts +14 -1
- package/dist/types/packages/core/src/storage/api-topics.d.ts +3 -0
- package/dist/types/packages/core/src/topics/plugin-server-instructions.d.ts +55 -0
- package/dist/types/packages/core/src/topics/plugin-turn.d.ts +17 -0
- package/dist/types/packages/core/src/topics/plugins.d.ts +66 -0
- package/dist/types/packages/core/src/types/api.d.ts +5 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{chunk-m1ngkjdd.js.map → chunk-hn2cqdd0.js.map} +0 -0
package/dist/agent-helpers.js
CHANGED
|
@@ -2441,6 +2441,7 @@ function initializeApiTopicsSchema() {
|
|
|
2441
2441
|
browser_profile TEXT NOT NULL DEFAULT 'default',
|
|
2442
2442
|
browser_profile_owner TEXT,
|
|
2443
2443
|
browser_connect_port INTEGER,
|
|
2444
|
+
plugins_json TEXT,
|
|
2444
2445
|
session_id TEXT,
|
|
2445
2446
|
CHECK (
|
|
2446
2447
|
(kind = 'channel' AND response_policy = 'off' AND agent IS NULL) OR
|
|
@@ -2561,6 +2562,10 @@ function initializeApiTopicsSchema() {
|
|
|
2561
2562
|
if (!tableColumns("api_topics").has("browser_connect_port")) {
|
|
2562
2563
|
db.exec("ALTER TABLE api_topics ADD COLUMN browser_connect_port INTEGER");
|
|
2563
2564
|
}
|
|
2565
|
+
if (!tableColumns("api_topics").has("plugins_json")) {
|
|
2566
|
+
db.exec("ALTER TABLE api_topics ADD COLUMN plugins_json TEXT");
|
|
2567
|
+
}
|
|
2568
|
+
db.exec("DROP TABLE IF EXISTS api_topic_plugin_variables");
|
|
2564
2569
|
if (!tableColumns("api_topics").has("subagent_report_mode")) {
|
|
2565
2570
|
db.exec("ALTER TABLE api_topics ADD COLUMN subagent_report_mode TEXT NOT NULL DEFAULT 'auto'");
|
|
2566
2571
|
}
|
|
@@ -2799,9 +2804,20 @@ function rowToDto2(r, participants = getTopicParticipants(r.id), tellTargets) {
|
|
|
2799
2804
|
visibility: normalizeTopicVisibility(r.visibility),
|
|
2800
2805
|
surface: normalizeTopicSurface(r.surface),
|
|
2801
2806
|
surfaceScope: normalizeSurfaceScope(r.surface_scope),
|
|
2802
|
-
...r.browser_connect_port != null ? { browserConnectPort: r.browser_connect_port } : {}
|
|
2807
|
+
...r.browser_connect_port != null ? { browserConnectPort: r.browser_connect_port } : {},
|
|
2808
|
+
...pluginsField(r.plugins_json)
|
|
2803
2809
|
};
|
|
2804
2810
|
}
|
|
2811
|
+
function pluginsField(json) {
|
|
2812
|
+
if (!json)
|
|
2813
|
+
return {};
|
|
2814
|
+
try {
|
|
2815
|
+
const plugins = JSON.parse(json);
|
|
2816
|
+
return Array.isArray(plugins) && plugins.every((dir) => typeof dir === "string") ? { plugins } : {};
|
|
2817
|
+
} catch {
|
|
2818
|
+
return {};
|
|
2819
|
+
}
|
|
2820
|
+
}
|
|
2805
2821
|
function normalizeTopicVisibility(value) {
|
|
2806
2822
|
return value === "hidden" ? "hidden" : "visible";
|
|
2807
2823
|
}
|
|
@@ -3203,6 +3219,22 @@ function refreshForumCatalogViews() {
|
|
|
3203
3219
|
function isReservedRuntimeMcpServerName(name) {
|
|
3204
3220
|
return Object.hasOwn(MCP_CATALOG, name) || nodeMcpEntries.some((entry) => entry.key === name);
|
|
3205
3221
|
}
|
|
3222
|
+
function pluginMcpRefusal(topic, names, hostNames = []) {
|
|
3223
|
+
if (names.length > 0 && topic.isSubagent)
|
|
3224
|
+
return "plugin servers are not allowed for subagent topics";
|
|
3225
|
+
for (const name of names) {
|
|
3226
|
+
if (isReservedRuntimeMcpServerName(name)) {
|
|
3227
|
+
return `plugin MCP server name conflicts with node catalog: ${name}`;
|
|
3228
|
+
}
|
|
3229
|
+
if (topic.kind !== "manager" && MANAGER_ONLY_HOST_MCP_NAMES.has(name)) {
|
|
3230
|
+
return `${name} is only allowed for manager topics`;
|
|
3231
|
+
}
|
|
3232
|
+
if (hostNames.includes(name)) {
|
|
3233
|
+
return `plugin MCP server name conflicts with a host MCP server: ${name}`;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
return null;
|
|
3237
|
+
}
|
|
3206
3238
|
function withoutManagerOnlyHostMcpServers(hostMcpServers) {
|
|
3207
3239
|
if (!hostMcpServers)
|
|
3208
3240
|
return;
|
|
@@ -5270,7 +5302,7 @@ var init_codex = __esm(async () => {
|
|
|
5270
5302
|
});
|
|
5271
5303
|
|
|
5272
5304
|
// ../../packages/core/src/version.ts
|
|
5273
|
-
var NEGOTIUM_VERSION = "0.
|
|
5305
|
+
var NEGOTIUM_VERSION = "0.24.1";
|
|
5274
5306
|
|
|
5275
5307
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
5276
5308
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -9649,11 +9681,578 @@ var init_bus = __esm(async () => {
|
|
|
9649
9681
|
};
|
|
9650
9682
|
});
|
|
9651
9683
|
|
|
9684
|
+
// ../../packages/core/src/runtime-gateway.ts
|
|
9685
|
+
function parseHostMcpServers(value) {
|
|
9686
|
+
if (value === undefined)
|
|
9687
|
+
return;
|
|
9688
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
9689
|
+
throw new TypeError("hostMcpServers must be an object");
|
|
9690
|
+
}
|
|
9691
|
+
const parsedEntries = [];
|
|
9692
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
9693
|
+
if (!HOST_MCP_SERVER_NAME.test(name)) {
|
|
9694
|
+
throw new TypeError(`invalid host MCP server name: ${name}`);
|
|
9695
|
+
}
|
|
9696
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
9697
|
+
throw new TypeError(`hostMcpServers.${name} must be an object`);
|
|
9698
|
+
}
|
|
9699
|
+
const spec = raw;
|
|
9700
|
+
const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));
|
|
9701
|
+
if (unsupported) {
|
|
9702
|
+
throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);
|
|
9703
|
+
}
|
|
9704
|
+
if (spec.type !== "sse" && spec.type !== "http") {
|
|
9705
|
+
throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);
|
|
9706
|
+
}
|
|
9707
|
+
if (typeof spec.url !== "string") {
|
|
9708
|
+
throw new TypeError(`hostMcpServers.${name}.url must be a string`);
|
|
9709
|
+
}
|
|
9710
|
+
let url;
|
|
9711
|
+
try {
|
|
9712
|
+
url = new URL(spec.url);
|
|
9713
|
+
} catch {
|
|
9714
|
+
throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);
|
|
9715
|
+
}
|
|
9716
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
9717
|
+
throw new TypeError(`hostMcpServers.${name}.url must use http or https`);
|
|
9718
|
+
}
|
|
9719
|
+
let headers;
|
|
9720
|
+
if (spec.headers !== undefined) {
|
|
9721
|
+
if (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)) {
|
|
9722
|
+
throw new TypeError(`hostMcpServers.${name}.headers must be an object`);
|
|
9723
|
+
}
|
|
9724
|
+
const headerEntries = [];
|
|
9725
|
+
for (const [key, headerValue] of Object.entries(spec.headers)) {
|
|
9726
|
+
if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== "string") {
|
|
9727
|
+
throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);
|
|
9728
|
+
}
|
|
9729
|
+
try {
|
|
9730
|
+
new Headers([[key, headerValue]]);
|
|
9731
|
+
} catch {
|
|
9732
|
+
throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);
|
|
9733
|
+
}
|
|
9734
|
+
headerEntries.push([key, headerValue]);
|
|
9735
|
+
}
|
|
9736
|
+
headers = Object.fromEntries(headerEntries);
|
|
9737
|
+
}
|
|
9738
|
+
if (spec.timeout !== undefined && (typeof spec.timeout !== "number" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)) {
|
|
9739
|
+
throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);
|
|
9740
|
+
}
|
|
9741
|
+
parsedEntries.push([
|
|
9742
|
+
name,
|
|
9743
|
+
{
|
|
9744
|
+
type: spec.type,
|
|
9745
|
+
url: url.toString(),
|
|
9746
|
+
...headers ? { headers } : {},
|
|
9747
|
+
...spec.timeout !== undefined ? { timeout: spec.timeout } : {}
|
|
9748
|
+
}
|
|
9749
|
+
]);
|
|
9750
|
+
}
|
|
9751
|
+
return Object.fromEntries(parsedEntries);
|
|
9752
|
+
}
|
|
9753
|
+
var HOST_MCP_SERVER_NAME, HOST_MCP_SERVER_KEYS, HTTP_HEADER_NAME;
|
|
9754
|
+
var init_runtime_gateway = __esm(() => {
|
|
9755
|
+
HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
9756
|
+
HOST_MCP_SERVER_KEYS = new Set(["type", "url", "headers", "timeout"]);
|
|
9757
|
+
HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
9758
|
+
});
|
|
9759
|
+
|
|
9760
|
+
// ../../packages/core/src/topics/agent-plugins/mcp.schema.json
|
|
9761
|
+
var mcp_schema_default;
|
|
9762
|
+
var init_mcp_schema = __esm(() => {
|
|
9763
|
+
mcp_schema_default = {
|
|
9764
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9765
|
+
$id: "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
9766
|
+
title: "Agent Plugins MCP Configuration",
|
|
9767
|
+
description: "Machine-readable schema for mcp.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.",
|
|
9768
|
+
type: "object",
|
|
9769
|
+
properties: {
|
|
9770
|
+
$schema: {
|
|
9771
|
+
const: "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
9772
|
+
description: "Canonical identifier of the MCP configuration schema for the Agent Plugins version targeted by this document."
|
|
9773
|
+
},
|
|
9774
|
+
mcpServers: {
|
|
9775
|
+
type: "object",
|
|
9776
|
+
additionalProperties: {
|
|
9777
|
+
$ref: "#/$defs/server"
|
|
9778
|
+
}
|
|
9779
|
+
}
|
|
9780
|
+
},
|
|
9781
|
+
required: ["$schema", "mcpServers"],
|
|
9782
|
+
additionalProperties: false,
|
|
9783
|
+
$defs: {
|
|
9784
|
+
server: {
|
|
9785
|
+
title: "MCP server",
|
|
9786
|
+
oneOf: [
|
|
9787
|
+
{
|
|
9788
|
+
$ref: "#/$defs/stdioServer"
|
|
9789
|
+
},
|
|
9790
|
+
{
|
|
9791
|
+
$ref: "#/$defs/streamableHttpServer"
|
|
9792
|
+
},
|
|
9793
|
+
{
|
|
9794
|
+
$ref: "#/$defs/sseServer"
|
|
9795
|
+
}
|
|
9796
|
+
]
|
|
9797
|
+
},
|
|
9798
|
+
stdioServer: {
|
|
9799
|
+
title: "stdio MCP server",
|
|
9800
|
+
type: "object",
|
|
9801
|
+
properties: {
|
|
9802
|
+
type: {
|
|
9803
|
+
const: "stdio"
|
|
9804
|
+
},
|
|
9805
|
+
command: {
|
|
9806
|
+
type: "string",
|
|
9807
|
+
minLength: 1,
|
|
9808
|
+
description: "Executable token. Resolution rules are defined by the Agent Plugins specification."
|
|
9809
|
+
},
|
|
9810
|
+
args: {
|
|
9811
|
+
type: "array",
|
|
9812
|
+
items: {
|
|
9813
|
+
type: "string"
|
|
9814
|
+
}
|
|
9815
|
+
},
|
|
9816
|
+
env: {
|
|
9817
|
+
type: "object",
|
|
9818
|
+
propertyNames: {
|
|
9819
|
+
not: {
|
|
9820
|
+
enum: ["PLUGIN_ROOT", "PLUGIN_DATA"]
|
|
9821
|
+
}
|
|
9822
|
+
},
|
|
9823
|
+
additionalProperties: {
|
|
9824
|
+
type: "string"
|
|
9825
|
+
}
|
|
9826
|
+
},
|
|
9827
|
+
cwd: {
|
|
9828
|
+
type: "string",
|
|
9829
|
+
pattern: "^(?:\\./|\\$\\{PLUGIN_ROOT\\}(?:/|$)|\\$\\{PLUGIN_DATA\\}(?:/|$))",
|
|
9830
|
+
description: "Plugin-relative, PLUGIN_ROOT-rooted, or PLUGIN_DATA-rooted working directory. Filesystem containment is validated separately."
|
|
9831
|
+
}
|
|
9832
|
+
},
|
|
9833
|
+
required: ["type", "command"],
|
|
9834
|
+
additionalProperties: false
|
|
9835
|
+
},
|
|
9836
|
+
streamableHttpServer: {
|
|
9837
|
+
title: "Streamable HTTP MCP server",
|
|
9838
|
+
type: "object",
|
|
9839
|
+
properties: {
|
|
9840
|
+
type: {
|
|
9841
|
+
const: "streamable-http"
|
|
9842
|
+
},
|
|
9843
|
+
url: {
|
|
9844
|
+
type: "string",
|
|
9845
|
+
minLength: 1,
|
|
9846
|
+
description: "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
9847
|
+
},
|
|
9848
|
+
headers: {
|
|
9849
|
+
$ref: "#/$defs/headers"
|
|
9850
|
+
}
|
|
9851
|
+
},
|
|
9852
|
+
required: ["type", "url"],
|
|
9853
|
+
additionalProperties: false
|
|
9854
|
+
},
|
|
9855
|
+
sseServer: {
|
|
9856
|
+
title: "Legacy HTTP+SSE MCP server",
|
|
9857
|
+
type: "object",
|
|
9858
|
+
properties: {
|
|
9859
|
+
type: {
|
|
9860
|
+
const: "sse"
|
|
9861
|
+
},
|
|
9862
|
+
url: {
|
|
9863
|
+
type: "string",
|
|
9864
|
+
minLength: 1,
|
|
9865
|
+
description: "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
9866
|
+
},
|
|
9867
|
+
headers: {
|
|
9868
|
+
$ref: "#/$defs/headers"
|
|
9869
|
+
}
|
|
9870
|
+
},
|
|
9871
|
+
required: ["type", "url"],
|
|
9872
|
+
additionalProperties: false
|
|
9873
|
+
},
|
|
9874
|
+
headers: {
|
|
9875
|
+
title: "HTTP headers",
|
|
9876
|
+
type: "object",
|
|
9877
|
+
additionalProperties: {
|
|
9878
|
+
type: "string"
|
|
9879
|
+
}
|
|
9880
|
+
}
|
|
9881
|
+
}
|
|
9882
|
+
};
|
|
9883
|
+
});
|
|
9884
|
+
|
|
9885
|
+
// ../../packages/core/src/topics/agent-plugins/plugin.schema.json
|
|
9886
|
+
var plugin_schema_default;
|
|
9887
|
+
var init_plugin_schema = __esm(() => {
|
|
9888
|
+
plugin_schema_default = {
|
|
9889
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
9890
|
+
$id: "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
9891
|
+
title: "Agent Plugins Manifest",
|
|
9892
|
+
description: "Machine-readable schema for plugin.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.",
|
|
9893
|
+
type: "object",
|
|
9894
|
+
properties: {
|
|
9895
|
+
$schema: {
|
|
9896
|
+
const: "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
9897
|
+
description: "Canonical identifier of the plugin manifest schema for the Agent Plugins version targeted by this document."
|
|
9898
|
+
},
|
|
9899
|
+
name: {
|
|
9900
|
+
type: "string",
|
|
9901
|
+
minLength: 1,
|
|
9902
|
+
maxLength: 64,
|
|
9903
|
+
pattern: "^(?!.*(?:--|\\.\\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$",
|
|
9904
|
+
description: "Human-readable plugin name."
|
|
9905
|
+
},
|
|
9906
|
+
version: {
|
|
9907
|
+
type: "string"
|
|
9908
|
+
},
|
|
9909
|
+
description: {
|
|
9910
|
+
type: "string"
|
|
9911
|
+
},
|
|
9912
|
+
author: {
|
|
9913
|
+
type: "object",
|
|
9914
|
+
properties: {
|
|
9915
|
+
name: {
|
|
9916
|
+
type: "string"
|
|
9917
|
+
},
|
|
9918
|
+
email: {
|
|
9919
|
+
type: "string"
|
|
9920
|
+
},
|
|
9921
|
+
url: {
|
|
9922
|
+
type: "string"
|
|
9923
|
+
}
|
|
9924
|
+
},
|
|
9925
|
+
additionalProperties: false
|
|
9926
|
+
},
|
|
9927
|
+
homepage: {
|
|
9928
|
+
type: "string"
|
|
9929
|
+
},
|
|
9930
|
+
repository: {
|
|
9931
|
+
type: "string"
|
|
9932
|
+
},
|
|
9933
|
+
license: {
|
|
9934
|
+
type: "string"
|
|
9935
|
+
},
|
|
9936
|
+
keywords: {
|
|
9937
|
+
type: "array",
|
|
9938
|
+
items: {
|
|
9939
|
+
type: "string"
|
|
9940
|
+
}
|
|
9941
|
+
},
|
|
9942
|
+
extensions: {
|
|
9943
|
+
type: "object",
|
|
9944
|
+
description: "Client-specific manifest data keyed by reverse-domain extension namespace. Agent Plugins assigns no semantics to namespace object contents.",
|
|
9945
|
+
additionalProperties: {
|
|
9946
|
+
type: "object"
|
|
9947
|
+
}
|
|
9948
|
+
}
|
|
9949
|
+
},
|
|
9950
|
+
required: ["$schema", "name"],
|
|
9951
|
+
additionalProperties: false
|
|
9952
|
+
};
|
|
9953
|
+
});
|
|
9954
|
+
|
|
9955
|
+
// ../../packages/core/src/topics/plugins.ts
|
|
9956
|
+
import { existsSync as existsSync16, readdirSync as readdirSync2, readFileSync as readFileSync12, realpathSync as realpathSync5, statSync as statSync7 } from "fs";
|
|
9957
|
+
import { isAbsolute as isAbsolute5, join as join17, relative as relative3 } from "path";
|
|
9958
|
+
import { z } from "zod";
|
|
9959
|
+
function readText(path) {
|
|
9960
|
+
return readFileSync12(path, "utf-8").replace(/^\uFEFF/, "").replace(/\r\n/g, `
|
|
9961
|
+
`);
|
|
9962
|
+
}
|
|
9963
|
+
function pathKind(root, path) {
|
|
9964
|
+
if (!existsSync16(path))
|
|
9965
|
+
return "missing";
|
|
9966
|
+
const real = realpathSync5(path);
|
|
9967
|
+
const fromRoot = relative3(root, real);
|
|
9968
|
+
if (fromRoot.startsWith("..") || isAbsolute5(fromRoot))
|
|
9969
|
+
return "outside";
|
|
9970
|
+
const stat = statSync7(real);
|
|
9971
|
+
return stat.isFile() ? "file" : stat.isDirectory() ? "dir" : "other";
|
|
9972
|
+
}
|
|
9973
|
+
function parseFrontmatter(raw) {
|
|
9974
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
9975
|
+
if (!match)
|
|
9976
|
+
return { ok: false, problem: "missing the --- frontmatter block" };
|
|
9977
|
+
let meta;
|
|
9978
|
+
try {
|
|
9979
|
+
meta = Bun.YAML.parse(match[1]);
|
|
9980
|
+
} catch (error) {
|
|
9981
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
9982
|
+
return { ok: false, problem: `frontmatter is not valid YAML (${reason})` };
|
|
9983
|
+
}
|
|
9984
|
+
if (!isObject(meta))
|
|
9985
|
+
return { ok: false, problem: "frontmatter must be a YAML mapping" };
|
|
9986
|
+
return { ok: true, meta, body: match[2] };
|
|
9987
|
+
}
|
|
9988
|
+
function readJson(path, fail) {
|
|
9989
|
+
try {
|
|
9990
|
+
return JSON.parse(readText(path));
|
|
9991
|
+
} catch (error) {
|
|
9992
|
+
fail(`not valid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
9993
|
+
return;
|
|
9994
|
+
}
|
|
9995
|
+
}
|
|
9996
|
+
function manifestSchema() {
|
|
9997
|
+
manifestValidator ??= z.fromJSONSchema(plugin_schema_default);
|
|
9998
|
+
return manifestValidator;
|
|
9999
|
+
}
|
|
10000
|
+
function readManifest(root, fail) {
|
|
10001
|
+
const path = join17(root, MANIFEST_FILE);
|
|
10002
|
+
const kind = pathKind(root, path);
|
|
10003
|
+
if (kind !== "file") {
|
|
10004
|
+
fail(kind === "outside" ? "resolves outside the plugin folder" : "missing");
|
|
10005
|
+
return null;
|
|
10006
|
+
}
|
|
10007
|
+
const raw = readJson(path, fail);
|
|
10008
|
+
if (raw === undefined)
|
|
10009
|
+
return null;
|
|
10010
|
+
if (!isObject(raw)) {
|
|
10011
|
+
fail("must be a JSON object");
|
|
10012
|
+
return null;
|
|
10013
|
+
}
|
|
10014
|
+
const manifest = {};
|
|
10015
|
+
for (const [field, value] of Object.entries(raw)) {
|
|
10016
|
+
if (!MANIFEST_FIELDS.has(field))
|
|
10017
|
+
fail(`unknown field "${field}" is ignored`);
|
|
10018
|
+
else if (field === "extensions" && !isObject(value)) {
|
|
10019
|
+
fail('"extensions" is not an object and is ignored');
|
|
10020
|
+
} else
|
|
10021
|
+
manifest[field] = value;
|
|
10022
|
+
}
|
|
10023
|
+
if (typeof manifest.$schema === "string" && manifest.$schema !== MANIFEST_SCHEMA_ID) {
|
|
10024
|
+
fail(`unsupported Agent Plugins version: $schema "${manifest.$schema}"`);
|
|
10025
|
+
return null;
|
|
10026
|
+
}
|
|
10027
|
+
const checked = manifestSchema().safeParse(manifest);
|
|
10028
|
+
if (!checked.success) {
|
|
10029
|
+
for (const issue of checked.error.issues) {
|
|
10030
|
+
fail(`${issue.path.length > 0 ? `${issue.path.join(".")}: ` : ""}${issue.message}`);
|
|
10031
|
+
}
|
|
10032
|
+
return null;
|
|
10033
|
+
}
|
|
10034
|
+
return { id: String(manifest.name) };
|
|
10035
|
+
}
|
|
10036
|
+
function readSkill(root, dir, name, fail) {
|
|
10037
|
+
const where = `${SKILLS_DIR}/${name}/${SKILL_FILE}`;
|
|
10038
|
+
const path = join17(dir, SKILLS_DIR, name, SKILL_FILE);
|
|
10039
|
+
const kind = pathKind(root, path);
|
|
10040
|
+
if (kind === "outside") {
|
|
10041
|
+
fail(where, "resolves outside the plugin folder; skipped");
|
|
10042
|
+
return null;
|
|
10043
|
+
}
|
|
10044
|
+
if (kind !== "file")
|
|
10045
|
+
return null;
|
|
10046
|
+
const parsed = parseFrontmatter(readText(path));
|
|
10047
|
+
if (!parsed.ok) {
|
|
10048
|
+
fail(where, `${parsed.problem}; skipped`);
|
|
10049
|
+
return null;
|
|
10050
|
+
}
|
|
10051
|
+
const problems = [];
|
|
10052
|
+
const skillName = parsed.meta.name;
|
|
10053
|
+
const description = typeof parsed.meta.description === "string" ? parsed.meta.description.trim() : "";
|
|
10054
|
+
if (skillName !== name)
|
|
10055
|
+
problems.push(`name must be the folder's name "${name}"`);
|
|
10056
|
+
else if (!SKILL_NAME.test(name) || name.length > MAX_SKILL_NAME_CHARS) {
|
|
10057
|
+
problems.push("name must be 1-64 lowercase letters, digits and single inner hyphens");
|
|
10058
|
+
}
|
|
10059
|
+
if (!description)
|
|
10060
|
+
problems.push("description (when to read it) is missing");
|
|
10061
|
+
else if (description.length > MAX_SKILL_DESCRIPTION_CHARS) {
|
|
10062
|
+
problems.push(`description is over ${MAX_SKILL_DESCRIPTION_CHARS} characters`);
|
|
10063
|
+
}
|
|
10064
|
+
if (problems.length > 0) {
|
|
10065
|
+
fail(where, `${problems.join("; ")}; skipped`);
|
|
10066
|
+
return null;
|
|
10067
|
+
}
|
|
10068
|
+
return { name, description, path };
|
|
10069
|
+
}
|
|
10070
|
+
function readSkills(root, dir, fail) {
|
|
10071
|
+
const skillsDir = join17(root, SKILLS_DIR);
|
|
10072
|
+
const kind = pathKind(root, skillsDir);
|
|
10073
|
+
if (kind === "missing")
|
|
10074
|
+
return [];
|
|
10075
|
+
if (kind !== "dir") {
|
|
10076
|
+
fail(SKILLS_DIR, kind === "outside" ? "resolves outside the plugin folder" : "not a folder");
|
|
10077
|
+
return [];
|
|
10078
|
+
}
|
|
10079
|
+
return readdirSync2(skillsDir).filter(visible).sort(byName).flatMap((name) => readSkill(root, dir, name, fail) ?? []);
|
|
10080
|
+
}
|
|
10081
|
+
function remoteUrlProblem(raw) {
|
|
10082
|
+
let url;
|
|
10083
|
+
try {
|
|
10084
|
+
url = new URL(raw);
|
|
10085
|
+
} catch {
|
|
10086
|
+
return "url must be an absolute http or https URL";
|
|
10087
|
+
}
|
|
10088
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
10089
|
+
return "url must be an absolute http or https URL";
|
|
10090
|
+
}
|
|
10091
|
+
if (url.username || url.password)
|
|
10092
|
+
return "url must not contain user information";
|
|
10093
|
+
if (url.hash || raw.includes("#"))
|
|
10094
|
+
return "url must not contain a fragment";
|
|
10095
|
+
if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
|
|
10096
|
+
return "a non-loopback url must use https";
|
|
10097
|
+
}
|
|
10098
|
+
return null;
|
|
10099
|
+
}
|
|
10100
|
+
function isLoopbackHost(hostname) {
|
|
10101
|
+
if (hostname === "localhost" || hostname === "[::1]")
|
|
10102
|
+
return true;
|
|
10103
|
+
const parts = hostname.split(".");
|
|
10104
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
|
|
10105
|
+
}
|
|
10106
|
+
function readServer(name, spec, fail) {
|
|
10107
|
+
if (!isObject(spec) || typeof spec.type !== "string") {
|
|
10108
|
+
fail(`"${name}": a server is an object with a "type"; skipped`);
|
|
10109
|
+
return null;
|
|
10110
|
+
}
|
|
10111
|
+
if (spec.type === "stdio") {
|
|
10112
|
+
fail(`"${name}": stdio servers are not supported here (remote servers only); skipped`);
|
|
10113
|
+
return null;
|
|
10114
|
+
}
|
|
10115
|
+
const variant = REMOTE_SERVERS[spec.type];
|
|
10116
|
+
if (!variant) {
|
|
10117
|
+
fail(`"${name}": unknown type "${spec.type}"; skipped`);
|
|
10118
|
+
return null;
|
|
10119
|
+
}
|
|
10120
|
+
const allowed = new Set(Object.keys(variant.properties));
|
|
10121
|
+
const unknown = Object.keys(spec).find((key) => !allowed.has(key));
|
|
10122
|
+
if (unknown) {
|
|
10123
|
+
fail(`"${name}": field "${unknown}" does not belong to a ${spec.type} server; skipped`);
|
|
10124
|
+
return null;
|
|
10125
|
+
}
|
|
10126
|
+
if (typeof spec.url !== "string" || !spec.url) {
|
|
10127
|
+
fail(`"${name}": url is required; skipped`);
|
|
10128
|
+
return null;
|
|
10129
|
+
}
|
|
10130
|
+
const headers = spec.headers;
|
|
10131
|
+
if (headers !== undefined) {
|
|
10132
|
+
const values = isObject(headers) ? Object.entries(headers) : null;
|
|
10133
|
+
const lower = values?.map(([key]) => key.toLowerCase()) ?? [];
|
|
10134
|
+
if (!values || values.some(([, value]) => typeof value !== "string") || new Set(lower).size !== lower.length) {
|
|
10135
|
+
fail(`"${name}": headers must be distinct header names with string values; skipped`);
|
|
10136
|
+
return null;
|
|
10137
|
+
}
|
|
10138
|
+
}
|
|
10139
|
+
const server = {
|
|
10140
|
+
type: NODE_TRANSPORT[spec.type],
|
|
10141
|
+
url: spec.url,
|
|
10142
|
+
...headers ? { headers } : {}
|
|
10143
|
+
};
|
|
10144
|
+
const urlProblem = remoteUrlProblem(spec.url);
|
|
10145
|
+
if (urlProblem) {
|
|
10146
|
+
fail(`"${name}": ${urlProblem}; skipped`);
|
|
10147
|
+
return null;
|
|
10148
|
+
}
|
|
10149
|
+
try {
|
|
10150
|
+
parseHostMcpServers({ [name]: server });
|
|
10151
|
+
} catch (error) {
|
|
10152
|
+
fail(`"${name}": ${error instanceof Error ? error.message : String(error)}; skipped`);
|
|
10153
|
+
return null;
|
|
10154
|
+
}
|
|
10155
|
+
return server;
|
|
10156
|
+
}
|
|
10157
|
+
function readMcpFile(root, fail) {
|
|
10158
|
+
const path = join17(root, MCP_FILE);
|
|
10159
|
+
const kind = pathKind(root, path);
|
|
10160
|
+
if (kind === "missing")
|
|
10161
|
+
return {};
|
|
10162
|
+
if (kind !== "file") {
|
|
10163
|
+
fail(`${kind === "outside" ? "resolves outside the plugin folder" : "not a file"}; no servers`);
|
|
10164
|
+
return {};
|
|
10165
|
+
}
|
|
10166
|
+
const raw = readJson(path, fail);
|
|
10167
|
+
if (raw === undefined)
|
|
10168
|
+
return {};
|
|
10169
|
+
const extra = isObject(raw) ? Object.keys(raw).find((key) => key !== "$schema" && key !== "mcpServers") : undefined;
|
|
10170
|
+
if (!isObject(raw) || raw.$schema !== MCP_SCHEMA_ID || !isObject(raw.mcpServers) || extra) {
|
|
10171
|
+
fail(`must be {"$schema": "${MCP_SCHEMA_ID}", "mcpServers": {\u2026}} and nothing else; no servers`);
|
|
10172
|
+
return {};
|
|
10173
|
+
}
|
|
10174
|
+
const servers = {};
|
|
10175
|
+
for (const [name, spec] of Object.entries(raw.mcpServers)) {
|
|
10176
|
+
const server = readServer(name, spec, fail);
|
|
10177
|
+
if (server)
|
|
10178
|
+
servers[name] = server;
|
|
10179
|
+
}
|
|
10180
|
+
return servers;
|
|
10181
|
+
}
|
|
10182
|
+
function loadTopicPlugins(dirs) {
|
|
10183
|
+
const problems = [];
|
|
10184
|
+
const plugins = [];
|
|
10185
|
+
const pluginOwner = new Map;
|
|
10186
|
+
const skillOwner = new Map;
|
|
10187
|
+
const serverOwner = new Map;
|
|
10188
|
+
for (const dir of dirs) {
|
|
10189
|
+
if (!isAbsolute5(dir)) {
|
|
10190
|
+
problems.push(`${dir}: a plugin is given by its folder's absolute path`);
|
|
10191
|
+
continue;
|
|
10192
|
+
}
|
|
10193
|
+
if (!existsSync16(dir) || !statSync7(dir).isDirectory()) {
|
|
10194
|
+
problems.push(`${dir}: not a folder`);
|
|
10195
|
+
continue;
|
|
10196
|
+
}
|
|
10197
|
+
const root = realpathSync5(dir);
|
|
10198
|
+
const failIn = (file, problem) => problems.push(`${dir}/${file}: ${problem}`);
|
|
10199
|
+
const manifest = readManifest(root, (problem) => failIn(MANIFEST_FILE, problem));
|
|
10200
|
+
if (!manifest)
|
|
10201
|
+
continue;
|
|
10202
|
+
const owner = pluginOwner.get(manifest.id);
|
|
10203
|
+
if (owner) {
|
|
10204
|
+
failIn(MANIFEST_FILE, `plugin name "${manifest.id}" is already used by ${owner}; skipped`);
|
|
10205
|
+
continue;
|
|
10206
|
+
}
|
|
10207
|
+
pluginOwner.set(manifest.id, dir);
|
|
10208
|
+
const unique = (owners, key, what, file) => {
|
|
10209
|
+
const other = owners.get(key);
|
|
10210
|
+
if (other)
|
|
10211
|
+
failIn(file, `${what} "${key}" is already used by ${other}; skipped`);
|
|
10212
|
+
else
|
|
10213
|
+
owners.set(key, dir);
|
|
10214
|
+
return !other;
|
|
10215
|
+
};
|
|
10216
|
+
const skills = readSkills(root, dir, failIn).filter((skill) => unique(skillOwner, skill.name, "skill name", SKILLS_DIR));
|
|
10217
|
+
const mcpServers = Object.fromEntries(Object.entries(readMcpFile(root, (problem) => failIn(MCP_FILE, problem))).filter(([name]) => unique(serverOwner, name, "server name", MCP_FILE)));
|
|
10218
|
+
plugins.push({ ...manifest, dir, skills, mcpServers });
|
|
10219
|
+
}
|
|
10220
|
+
return { plugins, problems };
|
|
10221
|
+
}
|
|
10222
|
+
function renderTopicPluginsPrompt(plugins) {
|
|
10223
|
+
const skills = plugins.flatMap((plugin) => plugin.skills);
|
|
10224
|
+
if (skills.length === 0)
|
|
10225
|
+
return "";
|
|
10226
|
+
return [
|
|
10227
|
+
"## Skills",
|
|
10228
|
+
"",
|
|
10229
|
+
"Each skill below is a guide for one kind of task. When a skill's description fits what you are about to do, first open its SKILL.md with your file-read tool and follow it. Other files of a skill sit in its folder and are linked from its SKILL.md.",
|
|
10230
|
+
"",
|
|
10231
|
+
...skills.map((skill) => `- \`${skill.name}\`: ${skill.description} (file: ${skill.path})`)
|
|
10232
|
+
].join(`
|
|
10233
|
+
`);
|
|
10234
|
+
}
|
|
10235
|
+
var MANIFEST_FILE = "plugin.json", SKILLS_DIR = "skills", SKILL_FILE = "SKILL.md", MCP_FILE = "mcp.json", MANIFEST_SCHEMA_ID, MCP_SCHEMA_ID, MANIFEST_FIELDS, REMOTE_SERVERS, NODE_TRANSPORT, SKILL_NAME, MAX_SKILL_NAME_CHARS = 64, MAX_SKILL_DESCRIPTION_CHARS = 1024, visible = (name) => !name.startsWith("."), byName = (a, b) => a < b ? -1 : a > b ? 1 : 0, isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value), manifestValidator = null;
|
|
10236
|
+
var init_plugins = __esm(() => {
|
|
10237
|
+
init_runtime_gateway();
|
|
10238
|
+
init_mcp_schema();
|
|
10239
|
+
init_plugin_schema();
|
|
10240
|
+
MANIFEST_SCHEMA_ID = plugin_schema_default.properties.$schema.const;
|
|
10241
|
+
MCP_SCHEMA_ID = mcp_schema_default.properties.$schema.const;
|
|
10242
|
+
MANIFEST_FIELDS = new Set(Object.keys(plugin_schema_default.properties));
|
|
10243
|
+
REMOTE_SERVERS = {
|
|
10244
|
+
"streamable-http": mcp_schema_default.$defs.streamableHttpServer,
|
|
10245
|
+
sse: mcp_schema_default.$defs.sseServer
|
|
10246
|
+
};
|
|
10247
|
+
NODE_TRANSPORT = { "streamable-http": "http", sse: "sse" };
|
|
10248
|
+
SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
10249
|
+
});
|
|
10250
|
+
|
|
9652
10251
|
// ../../packages/core/src/prompts/builders.ts
|
|
9653
|
-
import { readFileSync as
|
|
10252
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
9654
10253
|
import { resolve as resolve12 } from "path";
|
|
9655
10254
|
function loadPrompt(filename, dir = SESSIONS_DIR) {
|
|
9656
|
-
const raw =
|
|
10255
|
+
const raw = readFileSync13(resolve12(dir, filename), "utf-8");
|
|
9657
10256
|
return raw.replace(/\{\{RESOURCES_DIR\}\}/g, RESOURCES_DIR);
|
|
9658
10257
|
}
|
|
9659
10258
|
function replaceVars(template, vars) {
|
|
@@ -9716,7 +10315,7 @@ function visualDesignGuide() {
|
|
|
9716
10315
|
return _visualDesignGuide;
|
|
9717
10316
|
}
|
|
9718
10317
|
function loadAgentPrompt(filename) {
|
|
9719
|
-
const raw =
|
|
10318
|
+
const raw = readFileSync13(resolve12(AGENTS_PROMPTS_DIR, filename), "utf-8");
|
|
9720
10319
|
const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
9721
10320
|
if (!match)
|
|
9722
10321
|
throw new Error(`Agent prompt ${filename} is missing frontmatter`);
|
|
@@ -9964,6 +10563,11 @@ function createPromptBuilders(host = {}) {
|
|
|
9964
10563
|
## Topic-Specific Instructions
|
|
9965
10564
|
${opts.description.trim()}`;
|
|
9966
10565
|
}
|
|
10566
|
+
const plugins = renderTopicPluginsPrompt(opts.plugins ?? []);
|
|
10567
|
+
if (plugins)
|
|
10568
|
+
prompt += `
|
|
10569
|
+
|
|
10570
|
+
${plugins}`;
|
|
9967
10571
|
if (sessionKind === "manager") {
|
|
9968
10572
|
const managerTemplate = replaceVars(template(opts.surface === "otium" ? {
|
|
9969
10573
|
kind: "surface-profile",
|
|
@@ -10053,6 +10657,7 @@ var init_builders = __esm(() => {
|
|
|
10053
10657
|
init_browser_backend();
|
|
10054
10658
|
init_config();
|
|
10055
10659
|
init_logger();
|
|
10660
|
+
init_plugins();
|
|
10056
10661
|
PROMPTS_DIR = resolve12(PROJECT_ROOT, "src/prompts");
|
|
10057
10662
|
SESSIONS_DIR = resolve12(PROMPTS_DIR, "sessions");
|
|
10058
10663
|
SURFACE_PROFILE_FILES = {
|
|
@@ -10176,9 +10781,9 @@ var init_api_topic_brief = __esm(async () => {
|
|
|
10176
10781
|
});
|
|
10177
10782
|
|
|
10178
10783
|
// ../../packages/core/src/storage/wiki.ts
|
|
10179
|
-
import { basename as basename3, dirname as dirname12, join as
|
|
10784
|
+
import { basename as basename3, dirname as dirname12, join as join18 } from "path";
|
|
10180
10785
|
function getSharedWikiDir(workspaceDir = resolveStorageWorkspaceDir()) {
|
|
10181
|
-
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() :
|
|
10786
|
+
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() : join18(workspaceDir, "wiki");
|
|
10182
10787
|
}
|
|
10183
10788
|
var init_wiki = __esm(async () => {
|
|
10184
10789
|
await init_storage_host();
|
|
@@ -10358,8 +10963,8 @@ var init_personal_general = __esm(async () => {
|
|
|
10358
10963
|
|
|
10359
10964
|
// ../../packages/core/src/agents/archiver.ts
|
|
10360
10965
|
import { randomUUID as randomUUID9 } from "crypto";
|
|
10361
|
-
import { existsSync as
|
|
10362
|
-
import { join as
|
|
10966
|
+
import { existsSync as existsSync17, readdirSync as readdirSync3, readFileSync as readFileSync14, statSync as statSync8 } from "fs";
|
|
10967
|
+
import { join as join19 } from "path";
|
|
10363
10968
|
function resolveMemoryLanguage() {
|
|
10364
10969
|
const override = process.env.NEGOTIUM_MEMORY_LANG?.trim();
|
|
10365
10970
|
return override && override.length > 0 ? override : resolveOutputLanguage();
|
|
@@ -10617,10 +11222,10 @@ function distillOneLine(summaryMd) {
|
|
|
10617
11222
|
return "";
|
|
10618
11223
|
}
|
|
10619
11224
|
function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
10620
|
-
const dir =
|
|
11225
|
+
const dir = join19(storage.getWikiDir(), "summaries");
|
|
10621
11226
|
if (!storage.fileExists(dir))
|
|
10622
11227
|
return null;
|
|
10623
|
-
const predicted =
|
|
11228
|
+
const predicted = join19(dir, wikiSummaryFilename(date, topicTitle, topicId));
|
|
10624
11229
|
if (storage.fileExists(predicted) && storage.fileModifiedAt(predicted) >= sinceMs)
|
|
10625
11230
|
return predicted;
|
|
10626
11231
|
let best = null;
|
|
@@ -10628,7 +11233,7 @@ function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
|
10628
11233
|
if (!f.startsWith(`${date}-`) || !isTopicSummaryFile(f, topicId ?? "", topicTitle)) {
|
|
10629
11234
|
continue;
|
|
10630
11235
|
}
|
|
10631
|
-
const p =
|
|
11236
|
+
const p = join19(dir, f);
|
|
10632
11237
|
try {
|
|
10633
11238
|
const m = storage.fileModifiedAt(p);
|
|
10634
11239
|
if (m >= sinceMs && (!best || m > best.mtime))
|
|
@@ -10714,11 +11319,11 @@ var init_archiver = __esm(async () => {
|
|
|
10714
11319
|
defaultArchiverRuntime = createArchiverRuntime({
|
|
10715
11320
|
storage: {
|
|
10716
11321
|
getWikiDir: getSharedWikiDir,
|
|
10717
|
-
fileExists:
|
|
10718
|
-
listDirectory:
|
|
10719
|
-
readTextFile: (path) =>
|
|
10720
|
-
fileSize: (path) =>
|
|
10721
|
-
fileModifiedAt: (path) =>
|
|
11322
|
+
fileExists: existsSync17,
|
|
11323
|
+
listDirectory: readdirSync3,
|
|
11324
|
+
readTextFile: (path) => readFileSync14(path, "utf-8"),
|
|
11325
|
+
fileSize: (path) => statSync8(path).size,
|
|
11326
|
+
fileModifiedAt: (path) => statSync8(path).mtimeMs,
|
|
10722
11327
|
getGeneralTopicId: (userId, sourceTopicId) => {
|
|
10723
11328
|
const source = sourceTopicId ? getTopic(sourceTopicId) : null;
|
|
10724
11329
|
return source ? ensurePersonalGeneral(userId, source.surface, {
|
|
@@ -10759,9 +11364,9 @@ var init_archiver = __esm(async () => {
|
|
|
10759
11364
|
|
|
10760
11365
|
// ../../packages/core/src/agents/auth-check.ts
|
|
10761
11366
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
10762
|
-
import { existsSync as
|
|
11367
|
+
import { existsSync as existsSync18 } from "fs";
|
|
10763
11368
|
import { homedir as homedir9, platform } from "os";
|
|
10764
|
-
import { join as
|
|
11369
|
+
import { join as join20 } from "path";
|
|
10765
11370
|
function hasMaestroCredential(host, key, userId) {
|
|
10766
11371
|
if (userId && host.getVaultValue(userId, key)?.trim())
|
|
10767
11372
|
return true;
|
|
@@ -10781,7 +11386,7 @@ function checkAgentAuth(agent, host = defaultAgentAuthHost, userId) {
|
|
|
10781
11386
|
case "claude": {
|
|
10782
11387
|
if (host.environment.ANTHROPIC_API_KEY)
|
|
10783
11388
|
return { ok: true };
|
|
10784
|
-
const path =
|
|
11389
|
+
const path = join20(host.homeDirectory(), ".claude", ".credentials.json");
|
|
10785
11390
|
if (host.operatingSystem() === "darwin") {
|
|
10786
11391
|
if (host.hasMacOsCredential("Claude Code-credentials") || host.exists(path)) {
|
|
10787
11392
|
return { ok: true };
|
|
@@ -10838,7 +11443,7 @@ var init_auth_check = __esm(async () => {
|
|
|
10838
11443
|
await init_vault();
|
|
10839
11444
|
defaultAgentAuthHost = {
|
|
10840
11445
|
codexAuthFilePath,
|
|
10841
|
-
exists:
|
|
11446
|
+
exists: existsSync18,
|
|
10842
11447
|
environment: process.env,
|
|
10843
11448
|
homeDirectory: homedir9,
|
|
10844
11449
|
operatingSystem: platform,
|
|
@@ -10855,7 +11460,7 @@ var init_auth_check = __esm(async () => {
|
|
|
10855
11460
|
});
|
|
10856
11461
|
|
|
10857
11462
|
// ../../packages/core/src/agents/fork.ts
|
|
10858
|
-
import { existsSync as
|
|
11463
|
+
import { existsSync as existsSync19, unlinkSync as unlinkSync8 } from "fs";
|
|
10859
11464
|
function createAgentForkHelpers(host) {
|
|
10860
11465
|
return {
|
|
10861
11466
|
async forkAgentSession(options) {
|
|
@@ -10892,7 +11497,7 @@ var init_fork = __esm(async () => {
|
|
|
10892
11497
|
await init_registry();
|
|
10893
11498
|
defaultForkHelpers = createAgentForkHelpers({
|
|
10894
11499
|
forkSession: (agent, options) => getRegistryOperations(agent).forkSession(options),
|
|
10895
|
-
exists:
|
|
11500
|
+
exists: existsSync19,
|
|
10896
11501
|
unlink: unlinkSync8,
|
|
10897
11502
|
warn: (details, message) => logger.warn(details, message)
|
|
10898
11503
|
});
|
|
@@ -11438,13 +12043,13 @@ function formatTopicArchiveTranscriptRecord(row, topicTitle, index) {
|
|
|
11438
12043
|
|
|
11439
12044
|
// ../../packages/core/src/storage/topic-archive.ts
|
|
11440
12045
|
import { mkdirSync as mkdirSync10, writeFileSync as writeFileSync8 } from "fs";
|
|
11441
|
-
import { join as
|
|
12046
|
+
import { join as join21 } from "path";
|
|
11442
12047
|
function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
11443
12048
|
const rows = options.afterRowid !== undefined ? getMessagesForTopicAfterRowid(topicId, options.afterRowid) : getAllMessagesForTopic(topicId);
|
|
11444
12049
|
if (rows.length === 0)
|
|
11445
12050
|
return null;
|
|
11446
12051
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
11447
|
-
const archiveDir =
|
|
12052
|
+
const archiveDir = join21(getSharedWikiDir(), "archive");
|
|
11448
12053
|
mkdirSync10(archiveDir, { recursive: true });
|
|
11449
12054
|
const date = new Date().toISOString().slice(0, 10);
|
|
11450
12055
|
const reasonSuffix = options.reason && options.reason !== "delete" ? `_${options.reason}` : "";
|
|
@@ -11457,7 +12062,7 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
|
11457
12062
|
let path;
|
|
11458
12063
|
while (true) {
|
|
11459
12064
|
filename = `${safeTopic}_${date}${reasonSuffix}${counter === 1 ? "" : `_${counter}`}.jsonl`;
|
|
11460
|
-
path =
|
|
12065
|
+
path = join21(archiveDir, filename);
|
|
11461
12066
|
try {
|
|
11462
12067
|
writeFileSync8(path, body, { flag: "wx" });
|
|
11463
12068
|
break;
|
|
@@ -11502,7 +12107,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
11502
12107
|
const entries = readRawConversation(userId, topicTitle);
|
|
11503
12108
|
if (entries.length === 0)
|
|
11504
12109
|
return null;
|
|
11505
|
-
const archiveDir =
|
|
12110
|
+
const archiveDir = join21(getSharedWikiDir(), "archive");
|
|
11506
12111
|
mkdirSync10(archiveDir, { recursive: true });
|
|
11507
12112
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
11508
12113
|
const date = new Date().toISOString().slice(0, 10);
|
|
@@ -11530,7 +12135,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
11530
12135
|
let counter = 1;
|
|
11531
12136
|
while (true) {
|
|
11532
12137
|
const suffix = counter === 1 ? "" : `_${counter}`;
|
|
11533
|
-
const path =
|
|
12138
|
+
const path = join21(archiveDir, `${safeTopic}_${date}${reasonSuffix}_events${suffix}.jsonl`);
|
|
11534
12139
|
try {
|
|
11535
12140
|
writeFileSync8(path, body, { flag: "wx" });
|
|
11536
12141
|
logger.info({ topicId, topicTitle, archive: path, eventCount: entries.length }, "archiveConversationEvents: archived raw conversation events");
|
|
@@ -12228,7 +12833,7 @@ var init_runtime_process_leases = __esm(async () => {
|
|
|
12228
12833
|
|
|
12229
12834
|
// ../../packages/core/src/agents/mcp-tools/ask-user.ts
|
|
12230
12835
|
import { createHash as createHash5, randomUUID as randomUUID11 } from "crypto";
|
|
12231
|
-
import { z } from "zod";
|
|
12836
|
+
import { z as z2 } from "zod";
|
|
12232
12837
|
function normalizeAskText(value, maxChars) {
|
|
12233
12838
|
if (typeof value !== "string")
|
|
12234
12839
|
return;
|
|
@@ -12273,8 +12878,8 @@ function answerToolResult(answer) {
|
|
|
12273
12878
|
return textResult("The user skipped this question. Continue using your best judgment and finish the current turn.");
|
|
12274
12879
|
}
|
|
12275
12880
|
if (answer.kind === "custom") {
|
|
12276
|
-
return textResult(`
|
|
12277
|
-
Continue from this answer and finish the current turn.`);
|
|
12881
|
+
return textResult(`The user did not pick a listed option. They typed this reply in the chat instead: "${answer.label}"
|
|
12882
|
+
Treat it as their free-text answer to your question and read it for what it says. If it hands the decision back to you (for example "decide yourself" or "you handle it"), choose the best option yourself and go on. Continue from this answer and finish the current turn.`);
|
|
12278
12883
|
}
|
|
12279
12884
|
const description = answer.description ? `
|
|
12280
12885
|
Description: ${answer.description}` : "";
|
|
@@ -12366,6 +12971,7 @@ function createAskUserRuntime(host) {
|
|
|
12366
12971
|
id: createId(),
|
|
12367
12972
|
topicId,
|
|
12368
12973
|
authorId: userId,
|
|
12974
|
+
...options.answerMessage,
|
|
12369
12975
|
text: label,
|
|
12370
12976
|
parentId: messageId,
|
|
12371
12977
|
...existing.threadRootId ? { threadRootId: existing.threadRootId } : {},
|
|
@@ -12384,6 +12990,20 @@ function createAskUserRuntime(host) {
|
|
|
12384
12990
|
pending.resolve({ ...choice, userId, ...kind ? { kind } : {} });
|
|
12385
12991
|
return { ok: true, queryId: pending.queryId, answerMessage };
|
|
12386
12992
|
}
|
|
12993
|
+
function answerOpenQuestionWithText(topicId, text, userId, options = {}) {
|
|
12994
|
+
for (const [messageId, pending] of pendingAsks) {
|
|
12995
|
+
if (pending.topicId !== topicId)
|
|
12996
|
+
continue;
|
|
12997
|
+
const card = host.messaging.persistence.getMessage(topicId, messageId);
|
|
12998
|
+
if ((card?.threadRootId ?? undefined) !== (options.threadRootId ?? undefined))
|
|
12999
|
+
continue;
|
|
13000
|
+
return answerPendingQuestion(topicId, messageId, text, userId, {
|
|
13001
|
+
kind: "custom",
|
|
13002
|
+
...options.answerMessage ? { answerMessage: options.answerMessage } : {}
|
|
13003
|
+
});
|
|
13004
|
+
}
|
|
13005
|
+
return null;
|
|
13006
|
+
}
|
|
12387
13007
|
function cancelPendingQuestions(topicId, queryId) {
|
|
12388
13008
|
for (const [messageId, pending] of pendingAsks) {
|
|
12389
13009
|
if (pending.topicId === topicId && pending.queryId === queryId) {
|
|
@@ -12521,12 +13141,12 @@ function createAskUserRuntime(host) {
|
|
|
12521
13141
|
name: "ask_user_question",
|
|
12522
13142
|
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.",
|
|
12523
13143
|
schema: {
|
|
12524
|
-
question:
|
|
12525
|
-
choices:
|
|
12526
|
-
label:
|
|
12527
|
-
description:
|
|
13144
|
+
question: z2.string().describe("The concise question to show to the user."),
|
|
13145
|
+
choices: z2.array(z2.object({
|
|
13146
|
+
label: z2.string().describe("Choice label shown on the button."),
|
|
13147
|
+
description: z2.string().optional().describe("Optional one-sentence consequence.")
|
|
12528
13148
|
})).min(1).max(MAX_CHOICES).describe("Choices the user can select."),
|
|
12529
|
-
idempotency_key:
|
|
13149
|
+
idempotency_key: z2.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.")
|
|
12530
13150
|
},
|
|
12531
13151
|
async handler(input) {
|
|
12532
13152
|
return askUserQuestion(ctx, input);
|
|
@@ -12539,6 +13159,7 @@ function createAskUserRuntime(host) {
|
|
|
12539
13159
|
reconcilePendingGates,
|
|
12540
13160
|
hasPendingQuestion,
|
|
12541
13161
|
answerPendingQuestion,
|
|
13162
|
+
answerOpenQuestionWithText,
|
|
12542
13163
|
cancelPendingQuestions,
|
|
12543
13164
|
createToolDefinition
|
|
12544
13165
|
};
|
|
@@ -12760,7 +13381,7 @@ var init_manager_utils = () => {};
|
|
|
12760
13381
|
|
|
12761
13382
|
// ../../packages/core/src/platform/playwright/browser-processes.ts
|
|
12762
13383
|
import { execFileSync as execFileSync6 } from "child_process";
|
|
12763
|
-
import { readdirSync as
|
|
13384
|
+
import { readdirSync as readdirSync4, unlinkSync as unlinkSync10 } from "fs";
|
|
12764
13385
|
import { createServer as createServer2 } from "net";
|
|
12765
13386
|
import { resolve as resolve14, sep as sep2 } from "path";
|
|
12766
13387
|
function isPortInUse(port) {
|
|
@@ -12885,7 +13506,7 @@ function reapOrphanBrowsers(liveUserDataDirs) {
|
|
|
12885
13506
|
}
|
|
12886
13507
|
function cleanSingletonFiles(userDataDir) {
|
|
12887
13508
|
try {
|
|
12888
|
-
const files =
|
|
13509
|
+
const files = readdirSync4(userDataDir);
|
|
12889
13510
|
for (const f of files) {
|
|
12890
13511
|
if (f.startsWith("Singleton")) {
|
|
12891
13512
|
try {
|
|
@@ -12929,9 +13550,9 @@ var init_browser_processes = __esm(async () => {
|
|
|
12929
13550
|
|
|
12930
13551
|
// ../../packages/core/src/platform/playwright/headed-launch.ts
|
|
12931
13552
|
import { accessSync as accessSync3, constants as constants3 } from "fs";
|
|
12932
|
-
import { delimiter as delimiter2, isAbsolute as
|
|
13553
|
+
import { delimiter as delimiter2, isAbsolute as isAbsolute7, resolve as resolve15 } from "path";
|
|
12933
13554
|
function findExecutableOnPath(command, environment = process.env) {
|
|
12934
|
-
const candidates =
|
|
13555
|
+
const candidates = isAbsolute7(command) ? [command] : (environment.PATH ?? "").split(delimiter2).filter(Boolean).map((directory) => resolve15(directory, command));
|
|
12935
13556
|
for (const candidate of candidates) {
|
|
12936
13557
|
try {
|
|
12937
13558
|
accessSync3(candidate, constants3.X_OK);
|
|
@@ -13032,7 +13653,7 @@ var init_vault_public = __esm(async () => {
|
|
|
13032
13653
|
import { randomBytes as randomBytes6, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
13033
13654
|
import { createServer as createServer3 } from "net";
|
|
13034
13655
|
import { tmpdir as tmpdir3 } from "os";
|
|
13035
|
-
import { join as
|
|
13656
|
+
import { join as join22 } from "path";
|
|
13036
13657
|
function deepMapStrings2(value, transform) {
|
|
13037
13658
|
if (typeof value === "string")
|
|
13038
13659
|
return transform(value);
|
|
@@ -13119,7 +13740,7 @@ function authorized(actual, expected) {
|
|
|
13119
13740
|
}
|
|
13120
13741
|
async function createBrowserVaultBroker(userId) {
|
|
13121
13742
|
const token = randomBytes6(32).toString("hex");
|
|
13122
|
-
const socketPath = ipcEndpoint(
|
|
13743
|
+
const socketPath = ipcEndpoint(join22(process.platform === "win32" ? tmpdir3() : "/tmp", `negotium-browser-vault-${process.pid}-${randomBytes6(8).toString("hex")}.sock`));
|
|
13123
13744
|
const retainedForms = new Map;
|
|
13124
13745
|
const leases = new Map;
|
|
13125
13746
|
const sockets = new Set;
|
|
@@ -13334,21 +13955,21 @@ import { execFileSync as execFileSync7, spawn as spawn5 } from "child_process";
|
|
|
13334
13955
|
import { createHash as createHash6, randomBytes as randomBytes7, timingSafeEqual as timingSafeEqual3 } from "crypto";
|
|
13335
13956
|
import {
|
|
13336
13957
|
cpSync,
|
|
13337
|
-
existsSync as
|
|
13958
|
+
existsSync as existsSync21,
|
|
13338
13959
|
mkdirSync as mkdirSync11,
|
|
13339
|
-
readFileSync as
|
|
13960
|
+
readFileSync as readFileSync16,
|
|
13340
13961
|
rmSync as rmSync3,
|
|
13341
13962
|
unlinkSync as unlinkSync11,
|
|
13342
13963
|
writeFileSync as writeFileSync9
|
|
13343
13964
|
} from "fs";
|
|
13344
|
-
import { dirname as dirname13, join as
|
|
13965
|
+
import { dirname as dirname13, join as join23, resolve as resolve16 } from "path";
|
|
13345
13966
|
function removeDefaultProfileDataDir(userDataDir) {
|
|
13346
13967
|
const root = resolve16(BROWSER_PROFILES_DIR);
|
|
13347
13968
|
const target = resolve16(userDataDir);
|
|
13348
13969
|
if (dirname13(target) !== root) {
|
|
13349
13970
|
throw new Error(`Refusing to delete browser profile outside managed root: ${target}`);
|
|
13350
13971
|
}
|
|
13351
|
-
const existed =
|
|
13972
|
+
const existed = existsSync21(target);
|
|
13352
13973
|
rmSync3(target, { recursive: true, force: true });
|
|
13353
13974
|
return existed;
|
|
13354
13975
|
}
|
|
@@ -13437,14 +14058,14 @@ function portFileName(instanceKey) {
|
|
|
13437
14058
|
function writePortFile(instanceKey, port) {
|
|
13438
14059
|
try {
|
|
13439
14060
|
mkdirSync11(managerHost.portsDir, { recursive: true });
|
|
13440
|
-
writeFileSync9(
|
|
14061
|
+
writeFileSync9(join23(managerHost.portsDir, portFileName(instanceKey)), String(port));
|
|
13441
14062
|
} catch (e) {
|
|
13442
14063
|
logger.warn({ err: e, instanceKey, port }, "Failed to save playwright port file");
|
|
13443
14064
|
}
|
|
13444
14065
|
}
|
|
13445
14066
|
function deletePortFile(instanceKey) {
|
|
13446
14067
|
try {
|
|
13447
|
-
unlinkSync11(
|
|
14068
|
+
unlinkSync11(join23(managerHost.portsDir, portFileName(instanceKey)));
|
|
13448
14069
|
} catch (e) {
|
|
13449
14070
|
if (e.code === "ENOENT")
|
|
13450
14071
|
return;
|
|
@@ -13944,11 +14565,11 @@ async function cloneProfileForChild(opts) {
|
|
|
13944
14565
|
killInstance(dstKey);
|
|
13945
14566
|
await delay(500);
|
|
13946
14567
|
}
|
|
13947
|
-
if (!
|
|
14568
|
+
if (!existsSync21(srcDir)) {
|
|
13948
14569
|
return { copied: false, srcDir, dstDir, reason: "src-missing" };
|
|
13949
14570
|
}
|
|
13950
14571
|
try {
|
|
13951
|
-
if (
|
|
14572
|
+
if (existsSync21(dstDir)) {
|
|
13952
14573
|
rmSync3(dstDir, { recursive: true, force: true });
|
|
13953
14574
|
}
|
|
13954
14575
|
mkdirSync11(dirname13(dstDir), { recursive: true });
|
|
@@ -14247,7 +14868,7 @@ var init_compaction_tool_projection = __esm(() => {
|
|
|
14247
14868
|
// ../../packages/core/src/storage/token-stats.ts
|
|
14248
14869
|
import { createHash as createHash8 } from "crypto";
|
|
14249
14870
|
import { mkdirSync as mkdirSync12, writeFileSync as writeFileSync10 } from "fs";
|
|
14250
|
-
import { join as
|
|
14871
|
+
import { join as join24 } from "path";
|
|
14251
14872
|
function emptyBucket() {
|
|
14252
14873
|
return {
|
|
14253
14874
|
inputTokens: 0,
|
|
@@ -14266,7 +14887,7 @@ function queriesPath(userId) {
|
|
|
14266
14887
|
const fileId = tokenStatsFileId(userId);
|
|
14267
14888
|
const logDir = resolveStorageLogDir();
|
|
14268
14889
|
mkdirSync12(logDir, { recursive: true });
|
|
14269
|
-
return
|
|
14890
|
+
return join24(logDir, `token-queries-${fileId}.jsonl`);
|
|
14270
14891
|
}
|
|
14271
14892
|
function loadRecords(userId) {
|
|
14272
14893
|
try {
|
|
@@ -15108,7 +15729,7 @@ var init_runtime_turn_requests = __esm(async () => {
|
|
|
15108
15729
|
import { randomUUID as randomUUID13 } from "crypto";
|
|
15109
15730
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync4, writeFileSync as writeFileSync12 } from "fs";
|
|
15110
15731
|
import { tmpdir as tmpdir4 } from "os";
|
|
15111
|
-
import { join as
|
|
15732
|
+
import { join as join25 } from "path";
|
|
15112
15733
|
async function fenceTopicWork(topicId, maintenance) {
|
|
15113
15734
|
for (const queryId of cancelRuntimeUserTurnRequestsBeforeEpoch(topicId, maintenance.epoch)) {
|
|
15114
15735
|
WsHub.get().broadcastAborted(topicId, queryId, "stopped");
|
|
@@ -15317,7 +15938,7 @@ function formatCompactElapsed(startedAt) {
|
|
|
15317
15938
|
async function summarizeTopicContext(request) {
|
|
15318
15939
|
const startedAt = Date.now();
|
|
15319
15940
|
const sessionIds = [];
|
|
15320
|
-
const compactCwd = mkdtempSync2(
|
|
15941
|
+
const compactCwd = mkdtempSync2(join25(tmpdir4(), "negotium-compact-"));
|
|
15321
15942
|
const abortController = new AbortController;
|
|
15322
15943
|
const relayAbort = () => abortController.abort(request.signal?.reason);
|
|
15323
15944
|
if (request.signal?.aborted)
|
|
@@ -15344,7 +15965,7 @@ async function summarizeTopicContext(request) {
|
|
|
15344
15965
|
let error = "";
|
|
15345
15966
|
let toolViolation = false;
|
|
15346
15967
|
let compactionLogCalls = 0;
|
|
15347
|
-
const compactionLogPath =
|
|
15968
|
+
const compactionLogPath = join25(compactCwd, "conversation.log");
|
|
15348
15969
|
try {
|
|
15349
15970
|
const compactionMcp = useCompactionLog ? {
|
|
15350
15971
|
compact_log: {
|
|
@@ -16104,16 +16725,16 @@ var init_derive = __esm(async () => {
|
|
|
16104
16725
|
|
|
16105
16726
|
// ../../packages/core/src/query/state.ts
|
|
16106
16727
|
import { mkdirSync as mkdirSync15, renameSync as renameSync7, unlinkSync as unlinkSync14, writeFileSync as writeFileSync13 } from "fs";
|
|
16107
|
-
import { basename as basename4, join as
|
|
16728
|
+
import { basename as basename4, join as join26 } from "path";
|
|
16108
16729
|
function createQueryStateStore(options) {
|
|
16109
16730
|
const sanitize = options.sanitizeTopicId ?? sanitizeId;
|
|
16110
|
-
const queryStateDirPath = (userId) =>
|
|
16111
|
-
const queryStateFile = (userId, topicId) =>
|
|
16731
|
+
const queryStateDirPath = (userId) => join26(options.usersLogDir, String(userId), "active-queries");
|
|
16732
|
+
const queryStateFile = (userId, topicId) => join26(queryStateDirPath(userId), `${sanitize(topicId)}.json`);
|
|
16112
16733
|
const legacyQueryStateFile = (userId, topicName) => {
|
|
16113
16734
|
if (!topicName || topicName === "." || topicName === ".." || basename4(topicName) !== topicName) {
|
|
16114
16735
|
return null;
|
|
16115
16736
|
}
|
|
16116
|
-
return
|
|
16737
|
+
return join26(queryStateDirPath(userId), `${topicName}.json`);
|
|
16117
16738
|
};
|
|
16118
16739
|
return {
|
|
16119
16740
|
write(userId, topicId, topicName, task) {
|
|
@@ -16234,14 +16855,14 @@ var init_actor_topic_reach = __esm(async () => {
|
|
|
16234
16855
|
});
|
|
16235
16856
|
|
|
16236
16857
|
// ../../packages/core/src/query/session-inbox-path.ts
|
|
16237
|
-
import { join as
|
|
16858
|
+
import { join as join27 } from "path";
|
|
16238
16859
|
function sessionInboxPath(userId, topicId) {
|
|
16239
16860
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
16240
|
-
return
|
|
16861
|
+
return join27(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${JSONL_SUFFIX}`);
|
|
16241
16862
|
}
|
|
16242
16863
|
function scheduledSessionInboxPath(userId, topicId) {
|
|
16243
16864
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
16244
|
-
return
|
|
16865
|
+
return join27(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${SCHEDULE_SUFFIX}`);
|
|
16245
16866
|
}
|
|
16246
16867
|
var TOPIC_ID_FILE_PREFIX = "topic-id-", JSONL_SUFFIX = ".jsonl", SCHEDULE_SUFFIX = ".schedule";
|
|
16247
16868
|
var init_session_inbox_path = __esm(() => {
|
|
@@ -16249,12 +16870,12 @@ var init_session_inbox_path = __esm(() => {
|
|
|
16249
16870
|
});
|
|
16250
16871
|
|
|
16251
16872
|
// ../../packages/core/src/storage/session-inbox-signal.ts
|
|
16252
|
-
import { join as
|
|
16873
|
+
import { join as join28 } from "path";
|
|
16253
16874
|
var SESSION_INBOX_WAKE_FILE, listeners;
|
|
16254
16875
|
var init_session_inbox_signal = __esm(() => {
|
|
16255
16876
|
init_config();
|
|
16256
16877
|
init_logger();
|
|
16257
|
-
SESSION_INBOX_WAKE_FILE =
|
|
16878
|
+
SESSION_INBOX_WAKE_FILE = join28(SESSION_INBOX_DIR, ".wake");
|
|
16258
16879
|
listeners = new Set;
|
|
16259
16880
|
});
|
|
16260
16881
|
|
|
@@ -16292,13 +16913,13 @@ var init_session_inbox = __esm(async () => {
|
|
|
16292
16913
|
|
|
16293
16914
|
// ../../packages/core/src/query/session-inbox-cleanup.ts
|
|
16294
16915
|
import { unlinkSync as unlinkSync15 } from "fs";
|
|
16295
|
-
import { basename as basename5, join as
|
|
16916
|
+
import { basename as basename5, join as join29 } from "path";
|
|
16296
16917
|
function cleanupSessionInboxFiles(userId, topicId, legacyTopicTitle) {
|
|
16297
16918
|
const live = sessionInboxPath(userId, topicId);
|
|
16298
16919
|
const scheduled = scheduledSessionInboxPath(userId, topicId);
|
|
16299
16920
|
const candidates = new Set([live, `${live}.processing`, scheduled, `${scheduled}.processing`]);
|
|
16300
16921
|
if (legacyTopicTitle && legacyTopicTitle !== "." && legacyTopicTitle !== ".." && basename5(legacyTopicTitle) === legacyTopicTitle) {
|
|
16301
|
-
const legacyBase =
|
|
16922
|
+
const legacyBase = join29(SESSION_INBOX_DIR, userId, legacyTopicTitle);
|
|
16302
16923
|
for (const suffix of [".jsonl", ".jsonl.processing", ".schedule", ".schedule.processing"]) {
|
|
16303
16924
|
candidates.add(`${legacyBase}${suffix}`);
|
|
16304
16925
|
}
|
|
@@ -16538,35 +17159,35 @@ import {
|
|
|
16538
17159
|
closeSync as closeSync2,
|
|
16539
17160
|
mkdirSync as mkdirSync16,
|
|
16540
17161
|
openSync as openSync2,
|
|
16541
|
-
readdirSync as
|
|
16542
|
-
readFileSync as
|
|
16543
|
-
statSync as
|
|
17162
|
+
readdirSync as readdirSync5,
|
|
17163
|
+
readFileSync as readFileSync17,
|
|
17164
|
+
statSync as statSync10,
|
|
16544
17165
|
unlinkSync as unlinkSync16,
|
|
16545
17166
|
writeFileSync as writeFileSync14
|
|
16546
17167
|
} from "fs";
|
|
16547
|
-
import { dirname as dirname15, join as
|
|
17168
|
+
import { dirname as dirname15, join as join30 } from "path";
|
|
16548
17169
|
function pendingAskDir(userId) {
|
|
16549
17170
|
const rawUserId = String(userId);
|
|
16550
17171
|
const safeUserId = /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,255}$/.test(rawUserId) && !rawUserId.includes("..") ? rawUserId : `sha256-${createHash10("sha256").update(rawUserId).digest("hex")}`;
|
|
16551
|
-
return
|
|
17172
|
+
return join30(resolveStorageSessionAsksDir(), safeUserId);
|
|
16552
17173
|
}
|
|
16553
17174
|
function encodeAskKey(key) {
|
|
16554
17175
|
return JSON.stringify([key.from, key.to]);
|
|
16555
17176
|
}
|
|
16556
17177
|
function pendingAskPath(key) {
|
|
16557
17178
|
const digest = createHash10("sha256").update(encodeAskKey(key)).digest("hex");
|
|
16558
|
-
return
|
|
17179
|
+
return join30(pendingAskDir(key.userId), `${ASK_FILENAME_PREFIX}${digest}.pending`);
|
|
16559
17180
|
}
|
|
16560
17181
|
function v2PendingAskPath(key) {
|
|
16561
17182
|
const encoded = Buffer.from(encodeAskKey(key), "utf8").toString("base64url");
|
|
16562
|
-
return
|
|
17183
|
+
return join30(pendingAskDir(key.userId), `${V2_ASK_FILENAME_PREFIX}${encoded}.pending`);
|
|
16563
17184
|
}
|
|
16564
17185
|
function legacyPendingAskPath(key) {
|
|
16565
17186
|
if (key.from.includes("/") || key.from.includes("\\") || key.to.includes("/") || key.to.includes("\\") || key.from.includes("\x00") || key.to.includes("\x00")) {
|
|
16566
17187
|
return null;
|
|
16567
17188
|
}
|
|
16568
17189
|
const dir = pendingAskDir(key.userId);
|
|
16569
|
-
const candidate =
|
|
17190
|
+
const candidate = join30(dir, `${key.from}___${key.to}.pending`);
|
|
16570
17191
|
return dirname15(candidate) === dir ? candidate : null;
|
|
16571
17192
|
}
|
|
16572
17193
|
function parsePendingAskFilename(fileName) {
|
|
@@ -16588,11 +17209,11 @@ function parsePendingAskFilename(fileName) {
|
|
|
16588
17209
|
}
|
|
16589
17210
|
function readPendingAskFile(path, fallback) {
|
|
16590
17211
|
try {
|
|
16591
|
-
const raw =
|
|
17212
|
+
const raw = readFileSync17(path, "utf8").trim();
|
|
16592
17213
|
if (!raw)
|
|
16593
17214
|
return null;
|
|
16594
17215
|
if (!raw.startsWith("{")) {
|
|
16595
|
-
const ts = new Date(
|
|
17216
|
+
const ts = new Date(statSync10(path).mtimeMs).toISOString();
|
|
16596
17217
|
return {
|
|
16597
17218
|
userId: fallback.userId,
|
|
16598
17219
|
from: fallback.from,
|
|
@@ -16712,13 +17333,13 @@ function deletePendingAsksForTopic(args) {
|
|
|
16712
17333
|
const dir = pendingAskDir(args.userId);
|
|
16713
17334
|
let files;
|
|
16714
17335
|
try {
|
|
16715
|
-
files =
|
|
17336
|
+
files = readdirSync5(dir);
|
|
16716
17337
|
} catch {
|
|
16717
17338
|
return 0;
|
|
16718
17339
|
}
|
|
16719
17340
|
let deleted = 0;
|
|
16720
17341
|
for (const fileName of files) {
|
|
16721
|
-
const path =
|
|
17342
|
+
const path = join30(dir, fileName);
|
|
16722
17343
|
const parsed = parsePendingAskFilename(fileName);
|
|
16723
17344
|
const record = readPendingAskFile(path, {
|
|
16724
17345
|
userId: args.userId,
|
|
@@ -17394,82 +18015,6 @@ body{font-family:system-ui,-apple-system,"Segoe UI",sans-serif;background:var(--
|
|
|
17394
18015
|
</style>`;
|
|
17395
18016
|
});
|
|
17396
18017
|
|
|
17397
|
-
// ../../packages/core/src/runtime-gateway.ts
|
|
17398
|
-
function parseHostMcpServers(value) {
|
|
17399
|
-
if (value === undefined)
|
|
17400
|
-
return;
|
|
17401
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
17402
|
-
throw new TypeError("hostMcpServers must be an object");
|
|
17403
|
-
}
|
|
17404
|
-
const parsedEntries = [];
|
|
17405
|
-
for (const [name, raw] of Object.entries(value)) {
|
|
17406
|
-
if (!HOST_MCP_SERVER_NAME.test(name)) {
|
|
17407
|
-
throw new TypeError(`invalid host MCP server name: ${name}`);
|
|
17408
|
-
}
|
|
17409
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
17410
|
-
throw new TypeError(`hostMcpServers.${name} must be an object`);
|
|
17411
|
-
}
|
|
17412
|
-
const spec = raw;
|
|
17413
|
-
const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));
|
|
17414
|
-
if (unsupported) {
|
|
17415
|
-
throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);
|
|
17416
|
-
}
|
|
17417
|
-
if (spec.type !== "sse" && spec.type !== "http") {
|
|
17418
|
-
throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);
|
|
17419
|
-
}
|
|
17420
|
-
if (typeof spec.url !== "string") {
|
|
17421
|
-
throw new TypeError(`hostMcpServers.${name}.url must be a string`);
|
|
17422
|
-
}
|
|
17423
|
-
let url;
|
|
17424
|
-
try {
|
|
17425
|
-
url = new URL(spec.url);
|
|
17426
|
-
} catch {
|
|
17427
|
-
throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);
|
|
17428
|
-
}
|
|
17429
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
17430
|
-
throw new TypeError(`hostMcpServers.${name}.url must use http or https`);
|
|
17431
|
-
}
|
|
17432
|
-
let headers;
|
|
17433
|
-
if (spec.headers !== undefined) {
|
|
17434
|
-
if (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)) {
|
|
17435
|
-
throw new TypeError(`hostMcpServers.${name}.headers must be an object`);
|
|
17436
|
-
}
|
|
17437
|
-
const headerEntries = [];
|
|
17438
|
-
for (const [key, headerValue] of Object.entries(spec.headers)) {
|
|
17439
|
-
if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== "string") {
|
|
17440
|
-
throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);
|
|
17441
|
-
}
|
|
17442
|
-
try {
|
|
17443
|
-
new Headers([[key, headerValue]]);
|
|
17444
|
-
} catch {
|
|
17445
|
-
throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);
|
|
17446
|
-
}
|
|
17447
|
-
headerEntries.push([key, headerValue]);
|
|
17448
|
-
}
|
|
17449
|
-
headers = Object.fromEntries(headerEntries);
|
|
17450
|
-
}
|
|
17451
|
-
if (spec.timeout !== undefined && (typeof spec.timeout !== "number" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)) {
|
|
17452
|
-
throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);
|
|
17453
|
-
}
|
|
17454
|
-
parsedEntries.push([
|
|
17455
|
-
name,
|
|
17456
|
-
{
|
|
17457
|
-
type: spec.type,
|
|
17458
|
-
url: url.toString(),
|
|
17459
|
-
...headers ? { headers } : {},
|
|
17460
|
-
...spec.timeout !== undefined ? { timeout: spec.timeout } : {}
|
|
17461
|
-
}
|
|
17462
|
-
]);
|
|
17463
|
-
}
|
|
17464
|
-
return Object.fromEntries(parsedEntries);
|
|
17465
|
-
}
|
|
17466
|
-
var HOST_MCP_SERVER_NAME, HOST_MCP_SERVER_KEYS, HTTP_HEADER_NAME;
|
|
17467
|
-
var init_runtime_gateway = __esm(() => {
|
|
17468
|
-
HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
17469
|
-
HOST_MCP_SERVER_KEYS = new Set(["type", "url", "headers", "timeout"]);
|
|
17470
|
-
HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
17471
|
-
});
|
|
17472
|
-
|
|
17473
18018
|
// ../../packages/core/src/storage/topic-host-mcp-grants.ts
|
|
17474
18019
|
function getTopicHostMcpGrant(topicId) {
|
|
17475
18020
|
const row = db.query("SELECT servers_json FROM api_topic_host_mcp_grants WHERE topic_id = ?").get(topicId);
|
|
@@ -17778,7 +18323,7 @@ var init_lifecycle = __esm(async () => {
|
|
|
17778
18323
|
|
|
17779
18324
|
// ../../packages/core/src/runtime/attachments.ts
|
|
17780
18325
|
import { copyFileSync as copyFileSync2, mkdirSync as mkdirSync17, writeFileSync as writeFileSync15 } from "fs";
|
|
17781
|
-
import { basename as basename6, join as
|
|
18326
|
+
import { basename as basename6, join as join31 } from "path";
|
|
17782
18327
|
function workspaceCwdFor(topicId) {
|
|
17783
18328
|
return resolveTopicWorkspaceDir(topicId);
|
|
17784
18329
|
}
|
|
@@ -17791,7 +18336,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
17791
18336
|
if (!attachmentIds?.length)
|
|
17792
18337
|
return [];
|
|
17793
18338
|
const out = [];
|
|
17794
|
-
const destDir =
|
|
18339
|
+
const destDir = join31(workspaceCwdFor(topicId), "attachments", queryId);
|
|
17795
18340
|
for (const rawId of attachmentIds) {
|
|
17796
18341
|
if (typeof rawId !== "string")
|
|
17797
18342
|
continue;
|
|
@@ -17808,7 +18353,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
17808
18353
|
mkdirSync17(destDir, { recursive: true });
|
|
17809
18354
|
const index = String(out.length + 1).padStart(2, "0");
|
|
17810
18355
|
const safeName = safeAttachmentFilename(attachment.filename, fileId);
|
|
17811
|
-
const destPath =
|
|
18356
|
+
const destPath = join31(destDir, `${index}-${fileId.slice(0, 8)}-${safeName}`);
|
|
17812
18357
|
copyFileSync2(sourcePath, destPath);
|
|
17813
18358
|
out.push({
|
|
17814
18359
|
id: attachment.id,
|
|
@@ -18292,7 +18837,7 @@ var init_vault_request_gates = __esm(async () => {
|
|
|
18292
18837
|
|
|
18293
18838
|
// ../../packages/core/src/agents/mcp-tools/request-vault.ts
|
|
18294
18839
|
import { createHash as createHash12, randomUUID as randomUUID17 } from "crypto";
|
|
18295
|
-
import { z as
|
|
18840
|
+
import { z as z5 } from "zod";
|
|
18296
18841
|
function requestBodyHash(key, description) {
|
|
18297
18842
|
return createHash12("sha256").update(JSON.stringify({ key, description })).digest("hex");
|
|
18298
18843
|
}
|
|
@@ -18559,10 +19104,10 @@ function createRequestVaultRuntime(host) {
|
|
|
18559
19104
|
name: "request_vault_secret",
|
|
18560
19105
|
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.",
|
|
18561
19106
|
schema: {
|
|
18562
|
-
key:
|
|
18563
|
-
description:
|
|
18564
|
-
overwrite:
|
|
18565
|
-
idempotency_key:
|
|
19107
|
+
key: z5.string().describe("Vault key name, e.g. STRIPE_API_KEY. Letters/digits/underscores, must start with a letter."),
|
|
19108
|
+
description: z5.string().max(MAX_DESCRIPTION_CHARS).describe("One sentence telling the user what value to paste and where it's from."),
|
|
19109
|
+
overwrite: z5.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."),
|
|
19110
|
+
idempotency_key: z5.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.")
|
|
18566
19111
|
},
|
|
18567
19112
|
async handler(input) {
|
|
18568
19113
|
return requestVaultSecret(ctx, input);
|
|
@@ -18599,7 +19144,7 @@ function createRequestVaultRuntime(host) {
|
|
|
18599
19144
|
name: "delete_vault_secret",
|
|
18600
19145
|
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.",
|
|
18601
19146
|
schema: {
|
|
18602
|
-
key:
|
|
19147
|
+
key: z5.string().describe("Vault key name to delete, e.g. STRIPE_API_KEY.")
|
|
18603
19148
|
},
|
|
18604
19149
|
async handler(input) {
|
|
18605
19150
|
return deleteVaultSecret(ctx, input);
|
|
@@ -18905,8 +19450,8 @@ var init_visual_html = __esm(() => {
|
|
|
18905
19450
|
});
|
|
18906
19451
|
|
|
18907
19452
|
// ../../packages/core/src/runtime/visuals.ts
|
|
18908
|
-
import { realpathSync as
|
|
18909
|
-
import { isAbsolute as
|
|
19453
|
+
import { realpathSync as realpathSync6 } from "fs";
|
|
19454
|
+
import { isAbsolute as isAbsolute8, resolve as resolve17 } from "path";
|
|
18910
19455
|
function activeVisualHtmlForPrompt(html) {
|
|
18911
19456
|
if (html.length <= ACTIVE_VISUAL_PROMPT_MAX_CHARS) {
|
|
18912
19457
|
return { html, omittedChars: 0 };
|
|
@@ -18955,8 +19500,8 @@ function topicAllowsVisualFileId(topicId, fileId) {
|
|
|
18955
19500
|
}
|
|
18956
19501
|
function isPathInside(baseDir, filePath) {
|
|
18957
19502
|
try {
|
|
18958
|
-
const realBase =
|
|
18959
|
-
const real =
|
|
19503
|
+
const realBase = realpathSync6(resolve17(baseDir));
|
|
19504
|
+
const real = realpathSync6(resolve17(filePath));
|
|
18960
19505
|
return isInsideDir(real, realBase);
|
|
18961
19506
|
} catch {
|
|
18962
19507
|
return false;
|
|
@@ -19011,10 +19556,10 @@ function locateVisualMediaInput(topicId, input) {
|
|
|
19011
19556
|
}
|
|
19012
19557
|
const rawPath = input.file_path.trim();
|
|
19013
19558
|
const cwd = workspaceCwdFor(topicId);
|
|
19014
|
-
const candidate =
|
|
19559
|
+
const candidate = isAbsolute8(rawPath) ? rawPath : resolve17(cwd, rawPath);
|
|
19015
19560
|
let realCandidate;
|
|
19016
19561
|
try {
|
|
19017
|
-
realCandidate =
|
|
19562
|
+
realCandidate = realpathSync6(candidate);
|
|
19018
19563
|
} catch {
|
|
19019
19564
|
return { error: `file not found: ${rawPath}` };
|
|
19020
19565
|
}
|
|
@@ -19067,8 +19612,8 @@ var init_visuals = __esm(async () => {
|
|
|
19067
19612
|
|
|
19068
19613
|
// ../../packages/core/src/runtime/turn-event-stream.ts
|
|
19069
19614
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
19070
|
-
import { realpathSync as
|
|
19071
|
-
import { isAbsolute as
|
|
19615
|
+
import { realpathSync as realpathSync7, statSync as statSync11 } from "fs";
|
|
19616
|
+
import { isAbsolute as isAbsolute9, resolve as resolve18 } from "path";
|
|
19072
19617
|
function sessionEventMatchesCurrentExecution(topicId, queryId, agent, model) {
|
|
19073
19618
|
if (getRoomQuery(topicId)?.queryId !== queryId)
|
|
19074
19619
|
return false;
|
|
@@ -19493,15 +20038,15 @@ ${JSON.stringify(event.input ?? {})}`);
|
|
|
19493
20038
|
case "file":
|
|
19494
20039
|
if (!silent && peerBridge) {
|
|
19495
20040
|
const cwd = workspaceCwdFor(topicId);
|
|
19496
|
-
const path =
|
|
20041
|
+
const path = isAbsolute9(event.path) ? event.path : resolve18(cwd, event.path);
|
|
19497
20042
|
if (!isPathInside(cwd, path)) {
|
|
19498
20043
|
logger.warn({ topicId, path }, "peer output file is outside the topic workspace");
|
|
19499
20044
|
break;
|
|
19500
20045
|
}
|
|
19501
20046
|
let safePath;
|
|
19502
20047
|
try {
|
|
19503
|
-
safePath =
|
|
19504
|
-
if (!
|
|
20048
|
+
safePath = realpathSync7(path);
|
|
20049
|
+
if (!statSync11(safePath).isFile()) {
|
|
19505
20050
|
logger.warn({ topicId, path }, "peer output path is not a regular file");
|
|
19506
20051
|
break;
|
|
19507
20052
|
}
|
|
@@ -19830,16 +20375,16 @@ var init_turn_session = __esm(async () => {
|
|
|
19830
20375
|
});
|
|
19831
20376
|
|
|
19832
20377
|
// ../../packages/core/src/storage/app-settings.ts
|
|
19833
|
-
import { existsSync as
|
|
19834
|
-
import { dirname as dirname16, join as
|
|
20378
|
+
import { existsSync as existsSync22, mkdirSync as mkdirSync18, readFileSync as readFileSync18, writeFileSync as writeFileSync16 } from "fs";
|
|
20379
|
+
import { dirname as dirname16, join as join32 } from "path";
|
|
19835
20380
|
function settingsFile() {
|
|
19836
|
-
return
|
|
20381
|
+
return join32(resolveStorageDataDir(), "otium-settings.json");
|
|
19837
20382
|
}
|
|
19838
20383
|
function getGlobalAiName() {
|
|
19839
20384
|
const path = settingsFile();
|
|
19840
20385
|
try {
|
|
19841
|
-
if (
|
|
19842
|
-
const data = JSON.parse(
|
|
20386
|
+
if (existsSync22(path)) {
|
|
20387
|
+
const data = JSON.parse(readFileSync18(path, "utf8"));
|
|
19843
20388
|
if (typeof data.aiName === "string" && data.aiName.trim()) {
|
|
19844
20389
|
return data.aiName.trim();
|
|
19845
20390
|
}
|
|
@@ -19852,10 +20397,154 @@ var init_app_settings = __esm(async () => {
|
|
|
19852
20397
|
await init_storage_host();
|
|
19853
20398
|
});
|
|
19854
20399
|
|
|
20400
|
+
// ../../packages/core/src/topics/plugin-server-instructions.ts
|
|
20401
|
+
import { Client as Client2 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
20402
|
+
import { SSEClientTransport as SSEClientTransport2 } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
20403
|
+
import { StreamableHTTPClientTransport as StreamableHTTPClientTransport2 } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
20404
|
+
function cacheKey(server, spec) {
|
|
20405
|
+
const headers = Object.entries(spec.headers ?? {}).map(([name, value]) => [name.toLowerCase(), value]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
20406
|
+
return JSON.stringify([server, spec.type, spec.url, headers]);
|
|
20407
|
+
}
|
|
20408
|
+
function transportFor(spec, signal) {
|
|
20409
|
+
const url = new URL(spec.url);
|
|
20410
|
+
const requestInit = spec.headers ? { headers: spec.headers } : undefined;
|
|
20411
|
+
const noRedirect = (input, init) => fetch(input, {
|
|
20412
|
+
...init,
|
|
20413
|
+
redirect: "error",
|
|
20414
|
+
signal: init?.signal ? AbortSignal.any([init.signal, signal]) : signal
|
|
20415
|
+
});
|
|
20416
|
+
return spec.type === "sse" ? new SSEClientTransport2(url, { requestInit, fetch: noRedirect }) : new StreamableHTTPClientTransport2(url, { requestInit, fetch: noRedirect });
|
|
20417
|
+
}
|
|
20418
|
+
async function readInstructions(spec, timeoutMs, stop) {
|
|
20419
|
+
const ended = new AbortController;
|
|
20420
|
+
const timer = setTimeout(() => ended.abort(new Error(`no answer in ${timeoutMs} ms`)), timeoutMs);
|
|
20421
|
+
timer.unref?.();
|
|
20422
|
+
const onStop = () => ended.abort(new Error("the turn was stopped"));
|
|
20423
|
+
if (stop?.aborted)
|
|
20424
|
+
onStop();
|
|
20425
|
+
else
|
|
20426
|
+
stop?.addEventListener("abort", onStop, { once: true });
|
|
20427
|
+
const client = new Client2({ name: "negotium-plugin-instructions", version: "1.0.0" });
|
|
20428
|
+
const transport = transportFor(spec, ended.signal);
|
|
20429
|
+
try {
|
|
20430
|
+
return await Promise.race([
|
|
20431
|
+
client.connect(transport).then(() => client.getInstructions() ?? ""),
|
|
20432
|
+
new Promise((_, reject) => {
|
|
20433
|
+
if (ended.signal.aborted)
|
|
20434
|
+
reject(ended.signal.reason);
|
|
20435
|
+
ended.signal.addEventListener("abort", () => reject(ended.signal.reason), { once: true });
|
|
20436
|
+
})
|
|
20437
|
+
]);
|
|
20438
|
+
} finally {
|
|
20439
|
+
clearTimeout(timer);
|
|
20440
|
+
stop?.removeEventListener("abort", onStop);
|
|
20441
|
+
const ending = !ended.signal.aborted && transport instanceof StreamableHTTPClientTransport2 ? transport.terminateSession() : Promise.resolve();
|
|
20442
|
+
ending.catch(() => {}).finally(() => client.close().catch(() => {}));
|
|
20443
|
+
}
|
|
20444
|
+
}
|
|
20445
|
+
async function fetchMcpServerInstructions(servers, options = {}) {
|
|
20446
|
+
const timeoutMs = options.timeoutMs ?? SERVER_INSTRUCTIONS_TIMEOUT_MS;
|
|
20447
|
+
const entries = Object.entries(servers);
|
|
20448
|
+
const results = await Promise.allSettled(entries.map(async ([server, spec]) => {
|
|
20449
|
+
const key = cacheKey(server, spec);
|
|
20450
|
+
const hit = cache.get(key);
|
|
20451
|
+
if (hit && hit.expires > Date.now())
|
|
20452
|
+
return hit.text;
|
|
20453
|
+
const text = await readInstructions(spec, timeoutMs, options.signal);
|
|
20454
|
+
cache.set(key, { text, expires: Date.now() + SERVER_INSTRUCTIONS_TTL_MS });
|
|
20455
|
+
return text;
|
|
20456
|
+
}));
|
|
20457
|
+
const fetched = { instructions: [], problems: [] };
|
|
20458
|
+
results.forEach((result, index) => {
|
|
20459
|
+
const server = entries[index][0];
|
|
20460
|
+
if (result.status === "rejected") {
|
|
20461
|
+
const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
20462
|
+
fetched.problems.push(`plugin server "${server}": instructions not read (${reason})`);
|
|
20463
|
+
} else if (result.value.trim()) {
|
|
20464
|
+
fetched.instructions.push({ server, text: result.value });
|
|
20465
|
+
}
|
|
20466
|
+
});
|
|
20467
|
+
return fetched;
|
|
20468
|
+
}
|
|
20469
|
+
function cutToBytes(text, maxBytes) {
|
|
20470
|
+
const encoded = encoder.encode(text);
|
|
20471
|
+
let end = Math.max(0, maxBytes);
|
|
20472
|
+
while (end > 0 && (encoded[end] & 192) === 128)
|
|
20473
|
+
end--;
|
|
20474
|
+
return new TextDecoder().decode(encoded.subarray(0, end));
|
|
20475
|
+
}
|
|
20476
|
+
function renderMcpServerInstructions(instructions) {
|
|
20477
|
+
const head = [
|
|
20478
|
+
"## MCP Server Instructions",
|
|
20479
|
+
"",
|
|
20480
|
+
"The following MCP servers have provided instructions for how to use their tools and resources:"
|
|
20481
|
+
].join(`
|
|
20482
|
+
`);
|
|
20483
|
+
const blocks = [];
|
|
20484
|
+
const problems = [];
|
|
20485
|
+
let left = INSTRUCTIONS_SECTION_MAX_BYTES - byteLength(head);
|
|
20486
|
+
for (const { server, text: sent } of instructions) {
|
|
20487
|
+
const heading = `
|
|
20488
|
+
|
|
20489
|
+
### ${server}
|
|
20490
|
+
|
|
20491
|
+
`;
|
|
20492
|
+
const text = sent.trim();
|
|
20493
|
+
const size = byteLength(text);
|
|
20494
|
+
const room = Math.min(SERVER_INSTRUCTIONS_MAX_BYTES, left - byteLength(heading));
|
|
20495
|
+
if (size <= room) {
|
|
20496
|
+
blocks.push(`${heading}${text}`);
|
|
20497
|
+
left -= byteLength(heading) + size;
|
|
20498
|
+
continue;
|
|
20499
|
+
}
|
|
20500
|
+
const marker = cutMarker(server, size);
|
|
20501
|
+
if (room <= byteLength(marker)) {
|
|
20502
|
+
problems.push(`plugin server "${server}": instructions left out (the section is full)`);
|
|
20503
|
+
continue;
|
|
20504
|
+
}
|
|
20505
|
+
const shown = `${cutToBytes(text, room - byteLength(marker))}${marker}`;
|
|
20506
|
+
blocks.push(`${heading}${shown}`);
|
|
20507
|
+
left -= byteLength(heading) + byteLength(shown);
|
|
20508
|
+
problems.push(`plugin server "${server}": instructions cut from ${size} bytes`);
|
|
20509
|
+
}
|
|
20510
|
+
return { section: blocks.length > 0 ? `${head}${blocks.join("")}` : "", problems };
|
|
20511
|
+
}
|
|
20512
|
+
var SERVER_INSTRUCTIONS_TIMEOUT_MS = 3000, SERVER_INSTRUCTIONS_TTL_MS, SERVER_INSTRUCTIONS_MAX_BYTES, INSTRUCTIONS_SECTION_MAX_BYTES, cache, encoder, byteLength = (text) => encoder.encode(text).length, cutMarker = (server, sent) => `
|
|
20513
|
+
|
|
20514
|
+
[negotium cut the instructions of "${server}" here; the server sent ${sent} bytes]`;
|
|
20515
|
+
var init_plugin_server_instructions = __esm(() => {
|
|
20516
|
+
SERVER_INSTRUCTIONS_TTL_MS = 5 * 60 * 1000;
|
|
20517
|
+
SERVER_INSTRUCTIONS_MAX_BYTES = 8 * 1024;
|
|
20518
|
+
INSTRUCTIONS_SECTION_MAX_BYTES = 32 * 1024;
|
|
20519
|
+
cache = new Map;
|
|
20520
|
+
encoder = new TextEncoder;
|
|
20521
|
+
});
|
|
20522
|
+
|
|
20523
|
+
// ../../packages/core/src/topics/plugin-turn.ts
|
|
20524
|
+
function resolveTopicPluginTurn(topic, hostServerNames) {
|
|
20525
|
+
if (!topic.plugins?.length)
|
|
20526
|
+
return NONE;
|
|
20527
|
+
const { plugins, problems: loadProblems } = loadTopicPlugins(topic.plugins);
|
|
20528
|
+
const servers = Object.assign({}, ...plugins.map((plugin) => plugin.mcpServers));
|
|
20529
|
+
const refusal = pluginMcpRefusal(topic, Object.keys(servers), hostServerNames);
|
|
20530
|
+
return {
|
|
20531
|
+
plugins,
|
|
20532
|
+
mcpServers: refusal ? {} : servers,
|
|
20533
|
+
loadProblems,
|
|
20534
|
+
serverProblems: refusal ? [refusal] : []
|
|
20535
|
+
};
|
|
20536
|
+
}
|
|
20537
|
+
var NONE;
|
|
20538
|
+
var init_plugin_turn = __esm(async () => {
|
|
20539
|
+
init_plugins();
|
|
20540
|
+
await init_mcp_config();
|
|
20541
|
+
NONE = { plugins: [], mcpServers: {}, loadProblems: [], serverProblems: [] };
|
|
20542
|
+
});
|
|
20543
|
+
|
|
19855
20544
|
// ../../packages/core/src/runtime/turn-runner.ts
|
|
19856
20545
|
import { randomUUID as randomUUID19 } from "crypto";
|
|
19857
|
-
import { existsSync as
|
|
19858
|
-
import { join as
|
|
20546
|
+
import { existsSync as existsSync23, mkdirSync as mkdirSync19, readdirSync as readdirSync6, statSync as statSync12 } from "fs";
|
|
20547
|
+
import { join as join33 } from "path";
|
|
19859
20548
|
function withDefaultPlaywright(configuredMcp, isManager) {
|
|
19860
20549
|
if (isManager)
|
|
19861
20550
|
return configuredMcp;
|
|
@@ -19919,19 +20608,19 @@ function appendAskReplyMessage(topicId, text, sourceLabel, body, kind, agentType
|
|
|
19919
20608
|
return message;
|
|
19920
20609
|
}
|
|
19921
20610
|
function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, matchesTitle, preferExact = true) {
|
|
19922
|
-
const preferred =
|
|
19923
|
-
if (preferExact &&
|
|
20611
|
+
const preferred = join33(directory, preferredFilename);
|
|
20612
|
+
if (preferExact && existsSync23(preferred))
|
|
19924
20613
|
return preferred;
|
|
19925
20614
|
let newestLegacyId = null;
|
|
19926
20615
|
let newestTitle = null;
|
|
19927
20616
|
try {
|
|
19928
|
-
for (const filename of
|
|
20617
|
+
for (const filename of readdirSync6(directory)) {
|
|
19929
20618
|
const titleMatch = matchesTitle(filename);
|
|
19930
20619
|
const legacyIdMatch = !titleMatch && matchesLegacyId(filename);
|
|
19931
20620
|
if (!titleMatch && !legacyIdMatch)
|
|
19932
20621
|
continue;
|
|
19933
|
-
const path =
|
|
19934
|
-
const mtimeMs =
|
|
20622
|
+
const path = join33(directory, filename);
|
|
20623
|
+
const mtimeMs = statSync12(path).mtimeMs;
|
|
19935
20624
|
if (titleMatch) {
|
|
19936
20625
|
if (!newestTitle || mtimeMs > newestTitle.mtimeMs) {
|
|
19937
20626
|
newestTitle = { path, mtimeMs };
|
|
@@ -19944,10 +20633,10 @@ function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, ma
|
|
|
19944
20633
|
return newestTitle?.path ?? newestLegacyId?.path ?? preferred;
|
|
19945
20634
|
}
|
|
19946
20635
|
function resolveWikiMemoryMirror(wikiDir, topicId, topicTitle) {
|
|
19947
|
-
const briefFile = resolveWikiMirrorPath(
|
|
19948
|
-
const hasBriefFile =
|
|
19949
|
-
const latestSummaryCandidate = resolveWikiMirrorPath(
|
|
19950
|
-
const latestSummaryFile =
|
|
20636
|
+
const briefFile = resolveWikiMirrorPath(join33(wikiDir, "topic"), `${wikiBriefStorageKey(topicTitle, topicId)}.md`, (filename) => isTopicBriefFile(filename, topicId), (filename) => isTopicBriefFile(filename, topicId, topicTitle));
|
|
20637
|
+
const hasBriefFile = existsSync23(briefFile) && statSync12(briefFile).isFile();
|
|
20638
|
+
const latestSummaryCandidate = resolveWikiMirrorPath(join33(wikiDir, "summaries"), `__missing__-${wikiSummaryFilename("0000-00-00", topicTitle, topicId)}`, (filename) => isTopicSummaryFile(filename, topicId), (filename) => isTopicSummaryFile(filename, topicId, topicTitle), false);
|
|
20639
|
+
const latestSummaryFile = existsSync23(latestSummaryCandidate) && statSync12(latestSummaryCandidate).isFile() ? latestSummaryCandidate : null;
|
|
19951
20640
|
return { briefFile, hasBriefFile, latestSummaryFile };
|
|
19952
20641
|
}
|
|
19953
20642
|
async function streamAgentEvents(topicId, topicTitle, queryId, events, control, agentType, model, effort, userId, retryableSessionExpired = true, onSessionId, execution) {
|
|
@@ -20182,6 +20871,23 @@ function resolveTurnHostMcpServers(topic, sessionType) {
|
|
|
20182
20871
|
return;
|
|
20183
20872
|
return getTopicHostMcpGrant(topic.id) ?? undefined;
|
|
20184
20873
|
}
|
|
20874
|
+
function resolveTurnPlugins(topic, sessionType, hostMcpServers) {
|
|
20875
|
+
const ownScope = topic.kind === "manager" ? "manager" : "forum";
|
|
20876
|
+
const stored = getTopic(topic.id);
|
|
20877
|
+
if (!stored?.plugins?.length || (sessionType ?? ownScope) !== ownScope) {
|
|
20878
|
+
return { plugins: [], pluginMcpServers: {}, hostMcpServers };
|
|
20879
|
+
}
|
|
20880
|
+
const turn = resolveTopicPluginTurn(stored, Object.keys(hostMcpServers ?? {}));
|
|
20881
|
+
const problems = [...turn.loadProblems, ...turn.serverProblems];
|
|
20882
|
+
if (problems.length > 0) {
|
|
20883
|
+
logger.warn({ topicId: topic.id, problems }, "ai: topic plugins partly or wholly left out of the turn");
|
|
20884
|
+
}
|
|
20885
|
+
return {
|
|
20886
|
+
plugins: turn.plugins,
|
|
20887
|
+
pluginMcpServers: turn.mcpServers,
|
|
20888
|
+
hostMcpServers: Object.keys(turn.mcpServers).length > 0 ? { ...hostMcpServers, ...turn.mcpServers } : hostMcpServers
|
|
20889
|
+
};
|
|
20890
|
+
}
|
|
20185
20891
|
function sameTurnActor(runningActorUserId, incomingActorUserId) {
|
|
20186
20892
|
return (runningActorUserId ?? null) === (incomingActorUserId ?? null);
|
|
20187
20893
|
}
|
|
@@ -20339,7 +21045,7 @@ function startAiTurn(params) {
|
|
|
20339
21045
|
const sessionName = params.sessionName ?? topic.title;
|
|
20340
21046
|
const sessionType = params.sessionType;
|
|
20341
21047
|
const { visualTools, fileDeliveryTools } = resolveTurnToolCapabilities(topicId, params);
|
|
20342
|
-
const hostMcpServers = resolveTurnHostMcpServers(topic, sessionType);
|
|
21048
|
+
const { plugins, pluginMcpServers, hostMcpServers } = resolveTurnPlugins(topic, sessionType, resolveTurnHostMcpServers(topic, sessionType));
|
|
20343
21049
|
const onSessionId = params.onSessionId;
|
|
20344
21050
|
const onSessionReset = params.onSessionReset;
|
|
20345
21051
|
const bridgeSessionFromHistory = params.bridgeSessionFromHistory === true;
|
|
@@ -20720,7 +21426,8 @@ function startAiTurn(params) {
|
|
|
20720
21426
|
subagentParentTitle: topicRecord?.isSubagent && topicRecord.parentTopicId ? getTopic(topicRecord.parentTopicId)?.title : undefined,
|
|
20721
21427
|
subagentReportMode: topicRecord?.isSubagent ? subagentReportMode(topicId) : undefined,
|
|
20722
21428
|
visualTools,
|
|
20723
|
-
fileDeliveryTools
|
|
21429
|
+
fileDeliveryTools,
|
|
21430
|
+
plugins
|
|
20724
21431
|
};
|
|
20725
21432
|
const isManager = topicRecord?.kind === "manager";
|
|
20726
21433
|
const isMentionOnlyChannel = topic.aiMode === "mention" && !isManager;
|
|
@@ -20866,6 +21573,21 @@ function startAiTurn(params) {
|
|
|
20866
21573
|
if (consumePlaywrightUnavailable(userId, topic.title)) {
|
|
20867
21574
|
turnReminders.push("<system-reminder>Playwright browser tools are UNAVAILABLE this turn. The `mcp__playwright__*` tools have been removed from this turn's catalog because the long-lived browser MCP could not be prepared. Do not attempt to call browser tools. If browser interaction is required, ask the user to retry shortly or use a non-browser alternative.</system-reminder>");
|
|
20868
21575
|
}
|
|
21576
|
+
if (Object.keys(pluginMcpServers).length > 0) {
|
|
21577
|
+
const fetched = await fetchMcpServerInstructions(pluginMcpServers, {
|
|
21578
|
+
signal: abortController.signal
|
|
21579
|
+
});
|
|
21580
|
+
if (abortController.signal.aborted)
|
|
21581
|
+
return;
|
|
21582
|
+
const { section, problems } = renderMcpServerInstructions(fetched.instructions);
|
|
21583
|
+
if (fetched.problems.length + problems.length > 0) {
|
|
21584
|
+
logger.warn({ topicId, problems: [...fetched.problems, ...problems] }, "ai: plugin server instructions cut or left out of the turn");
|
|
21585
|
+
}
|
|
21586
|
+
if (section)
|
|
21587
|
+
systemPrompt += `
|
|
21588
|
+
|
|
21589
|
+
${section}`;
|
|
21590
|
+
}
|
|
20869
21591
|
const reminderQuery = buildTurnReminderQuery(agentKind, agentPrompt, turnReminders);
|
|
20870
21592
|
try {
|
|
20871
21593
|
yield* runAgent({
|
|
@@ -21228,6 +21950,7 @@ var init_turn_runner = __esm(async () => {
|
|
|
21228
21950
|
init_remote_session_grant();
|
|
21229
21951
|
init_user_turn_envelope();
|
|
21230
21952
|
init_wiki_summary_names();
|
|
21953
|
+
init_plugin_server_instructions();
|
|
21231
21954
|
init_user_turn_envelope();
|
|
21232
21955
|
await __promiseAll([
|
|
21233
21956
|
init_fork(),
|
|
@@ -21258,7 +21981,8 @@ var init_turn_runner = __esm(async () => {
|
|
|
21258
21981
|
init_topic_host_mcp_grants(),
|
|
21259
21982
|
init_topic_tool_capabilities(),
|
|
21260
21983
|
init_wiki(),
|
|
21261
|
-
init_derive()
|
|
21984
|
+
init_derive(),
|
|
21985
|
+
init_plugin_turn()
|
|
21262
21986
|
]);
|
|
21263
21987
|
init_model_catalog();
|
|
21264
21988
|
init_attachments();
|
|
@@ -21279,7 +22003,7 @@ var init_turn_runner = __esm(async () => {
|
|
|
21279
22003
|
});
|
|
21280
22004
|
|
|
21281
22005
|
// ../../packages/core/src/agents/mcp-tools/spawn-subagent.ts
|
|
21282
|
-
import { z as
|
|
22006
|
+
import { z as z6 } from "zod";
|
|
21283
22007
|
function activeQueryUserId(topic) {
|
|
21284
22008
|
return topic?.participants.find((participant) => hasActiveQuery(participant.userId, topic.id))?.userId;
|
|
21285
22009
|
}
|
|
@@ -21846,7 +22570,7 @@ ${card.task}${reportInstruction}`;
|
|
|
21846
22570
|
name: "start_subagent",
|
|
21847
22571
|
description: "Start a prepared descendant subagent task.",
|
|
21848
22572
|
schema: {
|
|
21849
|
-
topic_id:
|
|
22573
|
+
topic_id: z6.string().describe("Prepared subagent room id.")
|
|
21850
22574
|
},
|
|
21851
22575
|
async handler(input) {
|
|
21852
22576
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21866,7 +22590,7 @@ ${card.task}${reportInstruction}`;
|
|
|
21866
22590
|
name: "delete_subagent",
|
|
21867
22591
|
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.",
|
|
21868
22592
|
schema: {
|
|
21869
|
-
topic_id:
|
|
22593
|
+
topic_id: z6.string().describe("Exact subagent room id returned by list_subagents; names are not accepted.")
|
|
21870
22594
|
},
|
|
21871
22595
|
async handler(input) {
|
|
21872
22596
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21890,8 +22614,8 @@ ${card.task}${reportInstruction}`;
|
|
|
21890
22614
|
name: "grant_subagent_tell",
|
|
21891
22615
|
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.",
|
|
21892
22616
|
schema: {
|
|
21893
|
-
subagent_topic_id:
|
|
21894
|
-
target_topic_id:
|
|
22617
|
+
subagent_topic_id: z6.string().describe("Source descendant subagent topic id."),
|
|
22618
|
+
target_topic_id: z6.string().describe("Target topic id: this manager room or another descendant in its tree.")
|
|
21895
22619
|
},
|
|
21896
22620
|
async handler(input) {
|
|
21897
22621
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21916,8 +22640,8 @@ ${card.task}${reportInstruction}`;
|
|
|
21916
22640
|
name: "revoke_subagent_tell",
|
|
21917
22641
|
description: "Remove an extra tell_session connection previously granted to a descendant subagent.",
|
|
21918
22642
|
schema: {
|
|
21919
|
-
subagent_topic_id:
|
|
21920
|
-
target_topic_id:
|
|
22643
|
+
subagent_topic_id: z6.string().describe("Source descendant subagent topic id."),
|
|
22644
|
+
target_topic_id: z6.string().describe("Granted target topic id.")
|
|
21921
22645
|
},
|
|
21922
22646
|
async handler(input) {
|
|
21923
22647
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21939,18 +22663,18 @@ ${card.task}${reportInstruction}`;
|
|
|
21939
22663
|
}
|
|
21940
22664
|
function createSpawnSubagentToolDefinition(ctx, options = {}) {
|
|
21941
22665
|
const executionOverrideSchema = options.executionOverrides === false ? {} : {
|
|
21942
|
-
agent:
|
|
21943
|
-
model:
|
|
22666
|
+
agent: z6.enum(["claude", "codex", "maestro"]).optional().describe("Agent backend override. Defaults to this room's agent."),
|
|
22667
|
+
model: z6.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.`)
|
|
21944
22668
|
};
|
|
21945
22669
|
return {
|
|
21946
22670
|
name: "spawn_subagent",
|
|
21947
22671
|
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.",
|
|
21948
22672
|
schema: {
|
|
21949
|
-
task:
|
|
21950
|
-
name:
|
|
22673
|
+
task: z6.string().describe("Self-contained task brief. The worker has topic memory but no parent conversation history, so include all task-specific context."),
|
|
22674
|
+
name: z6.string().optional().describe("Short name for the subagent room. Auto-generated when omitted."),
|
|
21951
22675
|
...executionOverrideSchema,
|
|
21952
|
-
memory_topic:
|
|
21953
|
-
report_mode:
|
|
22676
|
+
memory_topic: z6.string().optional().describe("Optional knowledge source: an accessible topic id/title or topic/*.md brief. Defaults to the parent room's effective topic brief."),
|
|
22677
|
+
report_mode: z6.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.")
|
|
21954
22678
|
},
|
|
21955
22679
|
async handler(input) {
|
|
21956
22680
|
return createSubagent(ctx, input, true);
|
|
@@ -21962,14 +22686,14 @@ ${card.task}${reportInstruction}`;
|
|
|
21962
22686
|
name: "create_subagent",
|
|
21963
22687
|
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.",
|
|
21964
22688
|
schema: {
|
|
21965
|
-
task:
|
|
21966
|
-
name:
|
|
22689
|
+
task: z6.string().describe("Self-contained task brief for the subagent."),
|
|
22690
|
+
name: z6.string().optional().describe("Short room name. Auto-generated when omitted."),
|
|
21967
22691
|
...options.executionOverrides === false ? {} : {
|
|
21968
|
-
agent:
|
|
21969
|
-
model:
|
|
22692
|
+
agent: z6.enum(["claude", "codex", "maestro"]).optional(),
|
|
22693
|
+
model: z6.string().optional()
|
|
21970
22694
|
},
|
|
21971
|
-
memory_topic:
|
|
21972
|
-
report_mode:
|
|
22695
|
+
memory_topic: z6.string().optional().describe("Optional accessible topic id/title or topic/*.md brief to use as this worker's knowledge source. Defaults to the parent."),
|
|
22696
|
+
report_mode: z6.enum(["auto", "tell", "status-only"]).optional()
|
|
21973
22697
|
},
|
|
21974
22698
|
async handler(input) {
|
|
21975
22699
|
return createSubagent(ctx, input, false);
|
|
@@ -22164,11 +22888,11 @@ await __promiseAll([
|
|
|
22164
22888
|
|
|
22165
22889
|
// ../../packages/core/src/agents/mcp-tools/publish-html.ts
|
|
22166
22890
|
init_common();
|
|
22167
|
-
import { z as
|
|
22891
|
+
import { z as z3 } from "zod";
|
|
22168
22892
|
|
|
22169
22893
|
// ../../packages/core/src/agents/mcp-tools/inline-assets.ts
|
|
22170
|
-
import { existsSync as
|
|
22171
|
-
import { extname, isAbsolute as
|
|
22894
|
+
import { existsSync as existsSync20, readFileSync as readFileSync15, statSync as statSync9 } from "fs";
|
|
22895
|
+
import { extname, isAbsolute as isAbsolute6, resolve as resolve13 } from "path";
|
|
22172
22896
|
var MIME_BY_EXT = {
|
|
22173
22897
|
".apng": "image/apng",
|
|
22174
22898
|
".avif": "image/avif",
|
|
@@ -22217,15 +22941,15 @@ function inlineLocalAssets(html, options) {
|
|
|
22217
22941
|
const relPath = stripSuffix(ref);
|
|
22218
22942
|
if (!relPath)
|
|
22219
22943
|
return null;
|
|
22220
|
-
const abs =
|
|
22944
|
+
const abs = isAbsolute6(relPath) ? relPath : resolve13(baseDir, relPath);
|
|
22221
22945
|
let bytes;
|
|
22222
22946
|
try {
|
|
22223
|
-
if (!
|
|
22947
|
+
if (!existsSync20(abs) || !statSync9(abs).isFile()) {
|
|
22224
22948
|
unresolved.push(ref);
|
|
22225
22949
|
cache.set(ref, null);
|
|
22226
22950
|
return null;
|
|
22227
22951
|
}
|
|
22228
|
-
bytes =
|
|
22952
|
+
bytes = statSync9(abs).size;
|
|
22229
22953
|
} catch {
|
|
22230
22954
|
unresolved.push(ref);
|
|
22231
22955
|
cache.set(ref, null);
|
|
@@ -22245,7 +22969,7 @@ function inlineLocalAssets(html, options) {
|
|
|
22245
22969
|
let uri;
|
|
22246
22970
|
try {
|
|
22247
22971
|
const mime = MIME_BY_EXT[extname(abs).toLowerCase()] ?? "application/octet-stream";
|
|
22248
|
-
uri = `data:${mime};base64,${
|
|
22972
|
+
uri = `data:${mime};base64,${readFileSync15(abs).toString("base64")}`;
|
|
22249
22973
|
} catch {
|
|
22250
22974
|
unresolved.push(ref);
|
|
22251
22975
|
cache.set(ref, null);
|
|
@@ -22342,8 +23066,8 @@ function createPublishHtmlToolDefinitions(ctx, options = {}) {
|
|
|
22342
23066
|
"working after your workspace is gone."
|
|
22343
23067
|
].join(" "),
|
|
22344
23068
|
schema: {
|
|
22345
|
-
html:
|
|
22346
|
-
base_dir:
|
|
23069
|
+
html: z3.string().describe("Complete standalone HTML document to publish. Inline the CSS and JS."),
|
|
23070
|
+
base_dir: z3.string().optional().describe("Directory that relative image paths resolve against. Defaults to the working directory.")
|
|
22347
23071
|
},
|
|
22348
23072
|
async handler(input) {
|
|
22349
23073
|
const html = input?.html ?? "";
|
|
@@ -22394,7 +23118,7 @@ function createPublishHtmlToolDefinitions(ctx, options = {}) {
|
|
|
22394
23118
|
name: "unpublish_html",
|
|
22395
23119
|
description: "Delete a previously published HTML document before its 72-hour expiry. Accepts the URL returned by publish_html, or its id.",
|
|
22396
23120
|
schema: {
|
|
22397
|
-
snippet:
|
|
23121
|
+
snippet: z3.string().describe("URL returned by publish_html, or the bare id.")
|
|
22398
23122
|
},
|
|
22399
23123
|
async handler(input) {
|
|
22400
23124
|
const id = parseSnippetId(input?.snippet ?? "");
|
|
@@ -22410,7 +23134,7 @@ function createPublishHtmlToolDefinitions(ctx, options = {}) {
|
|
|
22410
23134
|
}
|
|
22411
23135
|
// ../../packages/core/src/agents/mcp-tools/self-config.ts
|
|
22412
23136
|
init_common();
|
|
22413
|
-
import { z as
|
|
23137
|
+
import { z as z4 } from "zod";
|
|
22414
23138
|
|
|
22415
23139
|
// ../../packages/core/src/agents/api-topic-agent-switch.ts
|
|
22416
23140
|
init_model_catalog();
|
|
@@ -22950,7 +23674,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
22950
23674
|
{
|
|
22951
23675
|
name: "set_model",
|
|
22952
23676
|
description: toolDescription(core, "set_model", "Set the model for THIS topic; it persists and applies from the NEXT turn. Use a model from the system prompt's same-agent catalog. Cross-agent changes require an explicit user-requested set_agent first. Fails if the user locked this setting. NEVER use 'fable' or 'fable-5.2' unless explicitly requested."),
|
|
22953
|
-
schema: { model:
|
|
23677
|
+
schema: { model: z4.string().describe("Model id valid for the topic's current agent.") },
|
|
22954
23678
|
async handler({ model }) {
|
|
22955
23679
|
return mcpResult(core.setModel(getCtx(), model));
|
|
22956
23680
|
}
|
|
@@ -22966,7 +23690,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
22966
23690
|
{
|
|
22967
23691
|
name: "set_agent",
|
|
22968
23692
|
description: toolDescription(core, "set_agent", "Switch the agent backend for THIS topic between 'claude', 'codex', and 'maestro'. Clears the topic's model/effort override so the new agent starts at its defaults. Fails if the user locked this setting. Use only when the user explicitly asks to switch the runtime itself."),
|
|
22969
|
-
schema: { agent:
|
|
23693
|
+
schema: { agent: z4.enum(AGENT_VALUES) },
|
|
22970
23694
|
async handler({ agent }) {
|
|
22971
23695
|
return mcpResult(core.setAgent(getCtx(), agent));
|
|
22972
23696
|
}
|
|
@@ -22983,7 +23707,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
22983
23707
|
name: "set_effort",
|
|
22984
23708
|
description: toolDescription(core, "set_effort", "Set the reasoning effort for THIS topic. Claude: low/medium/high/xhigh/max. Codex: low/medium/high/xhigh. Maestro: low/medium/high/xhigh/max. Higher effort costs more and is slower. Fails if the user locked this setting."),
|
|
22985
23709
|
schema: {
|
|
22986
|
-
effort:
|
|
23710
|
+
effort: z4.enum(EFFORT_VALUES).describe("Reasoning effort level valid for the topic's current agent.")
|
|
22987
23711
|
},
|
|
22988
23712
|
async handler({ effort }) {
|
|
22989
23713
|
return mcpResult(core.setEffort(getCtx(), effort));
|
|
@@ -23003,8 +23727,8 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
23003
23727
|
name: "schedule_self",
|
|
23004
23728
|
description: toolDescription(core, "schedule_self", "Create the one pending durable delayed continuation allowed for THIS topic without blocking the current turn. Use it to check a long-running operation or resume work later. The future message must be self-contained. If one already exists, use get_self_schedule then update_self_schedule or cancel_self_schedule. For recurring or longer-lived schedules, use cron-manager instead."),
|
|
23005
23729
|
schema: {
|
|
23006
|
-
delay_seconds:
|
|
23007
|
-
message:
|
|
23730
|
+
delay_seconds: z4.number().int().min(1).max(core.product.scheduleMaxDelaySeconds).describe(`Seconds before this topic resumes, from 1 through ${core.product.scheduleMaxDelaySeconds}${core.product.scheduleMaxDelaySeconds === 86400 ? " (24 hours)" : ""}.`),
|
|
23731
|
+
message: z4.string().min(1).max(core.product.scheduleMaxMessageLength).describe("Self-contained instruction delivered to your future turn.")
|
|
23008
23732
|
},
|
|
23009
23733
|
async handler({ delay_seconds, message }) {
|
|
23010
23734
|
return mcpResult(core.scheduleContinue(getCtx(), delay_seconds, message));
|
|
@@ -23022,9 +23746,9 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
23022
23746
|
name: "update_self_schedule",
|
|
23023
23747
|
description: toolDescription(core, "update_self_schedule", "Edit THIS topic's pending self-schedule. Provide its schedule_id from schedule_self/get_self_schedule and change delay_seconds, message, or both. delay_seconds is measured from this update. A schedule that already started cannot be edited."),
|
|
23024
23748
|
schema: {
|
|
23025
|
-
schedule_id:
|
|
23026
|
-
delay_seconds:
|
|
23027
|
-
message:
|
|
23749
|
+
schedule_id: z4.string().min(1).describe("Exact ID of the pending self-schedule."),
|
|
23750
|
+
delay_seconds: z4.number().int().min(1).max(core.product.scheduleMaxDelaySeconds).optional().describe(`New delay from now, from 1 through ${core.product.scheduleMaxDelaySeconds} seconds.`),
|
|
23751
|
+
message: z4.string().min(1).max(core.product.scheduleMaxMessageLength).optional().describe("Replacement self-contained future instruction.")
|
|
23028
23752
|
},
|
|
23029
23753
|
async handler({
|
|
23030
23754
|
schedule_id,
|
|
@@ -23041,7 +23765,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
23041
23765
|
name: "cancel_self_schedule",
|
|
23042
23766
|
description: toolDescription(core, "cancel_self_schedule", "Cancel THIS topic's pending self-schedule by its exact schedule_id. A schedule that already started cannot be cancelled with this tool."),
|
|
23043
23767
|
schema: {
|
|
23044
|
-
schedule_id:
|
|
23768
|
+
schedule_id: z4.string().min(1).describe("Exact ID of the pending self-schedule.")
|
|
23045
23769
|
},
|
|
23046
23770
|
async handler({ schedule_id }) {
|
|
23047
23771
|
return mcpResult(core.cancelSchedule(getCtx(), schedule_id));
|
|
@@ -23053,7 +23777,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
23053
23777
|
name: "spawn_topic",
|
|
23054
23778
|
description: toolDescription(core, "spawn_topic", `Create a new forum topic that inherits all settings from THIS topic but starts with a fresh session. Limited to ${core.product.derivedTopicLimit} calls per conversation turn.`),
|
|
23055
23779
|
schema: {
|
|
23056
|
-
name:
|
|
23780
|
+
name: z4.string().optional().describe("New topic name. Auto-generated if omitted.")
|
|
23057
23781
|
},
|
|
23058
23782
|
async handler({ name }) {
|
|
23059
23783
|
if (derivedCount >= core.product.derivedTopicLimit) {
|
|
@@ -23070,7 +23794,7 @@ function createSelfConfigToolDefinitionsForCore(core, ctx, capabilities) {
|
|
|
23070
23794
|
name: "fork_topic",
|
|
23071
23795
|
description: toolDescription(core, "fork_topic", `Fork THIS topic by creating a new topic that inherits both settings AND conversation history. Limited to ${core.product.derivedTopicLimit} calls per conversation turn.`),
|
|
23072
23796
|
schema: {
|
|
23073
|
-
name:
|
|
23797
|
+
name: z4.string().optional().describe("New topic name. Auto-generated if omitted.")
|
|
23074
23798
|
},
|
|
23075
23799
|
async handler({ name }) {
|
|
23076
23800
|
if (derivedCount >= core.product.derivedTopicLimit) {
|
|
@@ -23092,14 +23816,14 @@ await init_spawn_subagent();
|
|
|
23092
23816
|
|
|
23093
23817
|
// ../../packages/core/src/agents/mcp-tools/visuals.ts
|
|
23094
23818
|
init_common();
|
|
23095
|
-
import { z as
|
|
23819
|
+
import { z as z7 } from "zod";
|
|
23096
23820
|
var VISUALS_MCP_KEY = "visuals";
|
|
23097
23821
|
var showHtmlTool = {
|
|
23098
23822
|
name: "show_html",
|
|
23099
23823
|
description: "Display charts, tables, or interactive HTML to the user in a sandboxed WebView side panel. Pass a complete, self-contained HTML string with inline CSS/JS. Local DOM interactions are supported. Links (<a href> to http/https URLs) are safe to include: a click opens the URL in the user's system browser. Network requests, external scripts, form posts, popups, and parent-window access are blocked.",
|
|
23100
23824
|
schema: {
|
|
23101
|
-
html:
|
|
23102
|
-
title:
|
|
23825
|
+
html: z7.string().describe("Complete, self-contained HTML document or fragment to render."),
|
|
23826
|
+
title: z7.string().optional().describe("Optional title shown above the rendered card.")
|
|
23103
23827
|
},
|
|
23104
23828
|
async handler() {
|
|
23105
23829
|
return textResult("HTML card displayed to the user.");
|
|
@@ -23109,9 +23833,9 @@ var showMermaidTool = {
|
|
|
23109
23833
|
name: "show_mermaid",
|
|
23110
23834
|
description: "Render a Mermaid diagram in the user's visual side panel. Pass Mermaid DSL only, not markdown fences. Use this for flowcharts, sequence diagrams, class diagrams, state diagrams, ER diagrams, timelines, and architecture diagrams.",
|
|
23111
23835
|
schema: {
|
|
23112
|
-
code:
|
|
23113
|
-
title:
|
|
23114
|
-
theme:
|
|
23836
|
+
code: z7.string().describe("Mermaid diagram source without markdown code fences."),
|
|
23837
|
+
title: z7.string().optional().describe("Optional title shown above the rendered card."),
|
|
23838
|
+
theme: z7.enum(["default", "neutral", "dark", "forest"]).optional().describe("Optional Mermaid theme. Defaults to neutral.")
|
|
23115
23839
|
},
|
|
23116
23840
|
async handler() {
|
|
23117
23841
|
return textResult("Mermaid diagram displayed to the user.");
|
|
@@ -23121,10 +23845,10 @@ var showImageTool = {
|
|
|
23121
23845
|
name: "show_image",
|
|
23122
23846
|
description: "Display an image in the user's visual side panel. Provide either file_path for an image in the topic workspace, or file_id for an uploaded file already attached in this topic.",
|
|
23123
23847
|
schema: {
|
|
23124
|
-
file_path:
|
|
23125
|
-
file_id:
|
|
23126
|
-
title:
|
|
23127
|
-
alt:
|
|
23848
|
+
file_path: z7.string().optional().describe("Absolute or workspace-relative path to an image file."),
|
|
23849
|
+
file_id: z7.string().optional().describe("Full Otium uploaded file UUID for an image attached in this topic."),
|
|
23850
|
+
title: z7.string().optional().describe("Optional title shown above the rendered card."),
|
|
23851
|
+
alt: z7.string().optional().describe("Optional alt text for the image.")
|
|
23128
23852
|
},
|
|
23129
23853
|
async handler(input) {
|
|
23130
23854
|
if (!input?.file_path && !input?.file_id) {
|
|
@@ -23210,4 +23934,4 @@ export {
|
|
|
23210
23934
|
withTaskSnapshots
|
|
23211
23935
|
};
|
|
23212
23936
|
|
|
23213
|
-
//# debugId=
|
|
23937
|
+
//# debugId=1C65A31EFCF179BC64756E2164756E21
|