@otium-team/negotium 0.23.14 → 0.24.0
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 +956 -243
- package/dist/agent-helpers.js.map +12 -9
- package/dist/{chunk-3v58ejrk.js → chunk-3r4xfhkx.js} +3 -3
- package/dist/{chunk-3v58ejrk.js.map → chunk-3r4xfhkx.js.map} +2 -2
- 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/hosted-agent.js +19 -3
- package/dist/hosted-agent.js.map +5 -5
- package/dist/main.js +38697 -37819
- package/dist/main.js.map +89 -85
- package/dist/mcp-factories.js +946 -227
- package/dist/mcp-factories.js.map +13 -10
- 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/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 +104 -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/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/mcp-factories.js
CHANGED
|
@@ -3093,6 +3093,7 @@ function initializeApiTopicsSchema() {
|
|
|
3093
3093
|
browser_profile TEXT NOT NULL DEFAULT 'default',
|
|
3094
3094
|
browser_profile_owner TEXT,
|
|
3095
3095
|
browser_connect_port INTEGER,
|
|
3096
|
+
plugins_json TEXT,
|
|
3096
3097
|
session_id TEXT,
|
|
3097
3098
|
CHECK (
|
|
3098
3099
|
(kind = 'channel' AND response_policy = 'off' AND agent IS NULL) OR
|
|
@@ -3213,6 +3214,10 @@ function initializeApiTopicsSchema() {
|
|
|
3213
3214
|
if (!tableColumns("api_topics").has("browser_connect_port")) {
|
|
3214
3215
|
db.exec("ALTER TABLE api_topics ADD COLUMN browser_connect_port INTEGER");
|
|
3215
3216
|
}
|
|
3217
|
+
if (!tableColumns("api_topics").has("plugins_json")) {
|
|
3218
|
+
db.exec("ALTER TABLE api_topics ADD COLUMN plugins_json TEXT");
|
|
3219
|
+
}
|
|
3220
|
+
db.exec("DROP TABLE IF EXISTS api_topic_plugin_variables");
|
|
3216
3221
|
if (!tableColumns("api_topics").has("subagent_report_mode")) {
|
|
3217
3222
|
db.exec("ALTER TABLE api_topics ADD COLUMN subagent_report_mode TEXT NOT NULL DEFAULT 'auto'");
|
|
3218
3223
|
}
|
|
@@ -3451,9 +3456,20 @@ function rowToDto2(r, participants = getTopicParticipants(r.id), tellTargets) {
|
|
|
3451
3456
|
visibility: normalizeTopicVisibility(r.visibility),
|
|
3452
3457
|
surface: normalizeTopicSurface(r.surface),
|
|
3453
3458
|
surfaceScope: normalizeSurfaceScope(r.surface_scope),
|
|
3454
|
-
...r.browser_connect_port != null ? { browserConnectPort: r.browser_connect_port } : {}
|
|
3459
|
+
...r.browser_connect_port != null ? { browserConnectPort: r.browser_connect_port } : {},
|
|
3460
|
+
...pluginsField(r.plugins_json)
|
|
3455
3461
|
};
|
|
3456
3462
|
}
|
|
3463
|
+
function pluginsField(json) {
|
|
3464
|
+
if (!json)
|
|
3465
|
+
return {};
|
|
3466
|
+
try {
|
|
3467
|
+
const plugins = JSON.parse(json);
|
|
3468
|
+
return Array.isArray(plugins) && plugins.every((dir) => typeof dir === "string") ? { plugins } : {};
|
|
3469
|
+
} catch {
|
|
3470
|
+
return {};
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3457
3473
|
function normalizeTopicVisibility(value) {
|
|
3458
3474
|
return value === "hidden" ? "hidden" : "visible";
|
|
3459
3475
|
}
|
|
@@ -3859,6 +3875,22 @@ function refreshForumCatalogViews() {
|
|
|
3859
3875
|
function isReservedRuntimeMcpServerName(name) {
|
|
3860
3876
|
return Object.hasOwn(MCP_CATALOG, name) || nodeMcpEntries.some((entry) => entry.key === name);
|
|
3861
3877
|
}
|
|
3878
|
+
function pluginMcpRefusal(topic, names, hostNames = []) {
|
|
3879
|
+
if (names.length > 0 && topic.isSubagent)
|
|
3880
|
+
return "plugin servers are not allowed for subagent topics";
|
|
3881
|
+
for (const name of names) {
|
|
3882
|
+
if (isReservedRuntimeMcpServerName(name)) {
|
|
3883
|
+
return `plugin MCP server name conflicts with node catalog: ${name}`;
|
|
3884
|
+
}
|
|
3885
|
+
if (topic.kind !== "manager" && MANAGER_ONLY_HOST_MCP_NAMES.has(name)) {
|
|
3886
|
+
return `${name} is only allowed for manager topics`;
|
|
3887
|
+
}
|
|
3888
|
+
if (hostNames.includes(name)) {
|
|
3889
|
+
return `plugin MCP server name conflicts with a host MCP server: ${name}`;
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
return null;
|
|
3893
|
+
}
|
|
3862
3894
|
function withoutManagerOnlyHostMcpServers(hostMcpServers) {
|
|
3863
3895
|
if (!hostMcpServers)
|
|
3864
3896
|
return;
|
|
@@ -5316,7 +5348,7 @@ var init_codex = __esm(async () => {
|
|
|
5316
5348
|
});
|
|
5317
5349
|
|
|
5318
5350
|
// ../../packages/core/src/version.ts
|
|
5319
|
-
var NEGOTIUM_VERSION = "0.
|
|
5351
|
+
var NEGOTIUM_VERSION = "0.24.0";
|
|
5320
5352
|
|
|
5321
5353
|
// ../../packages/core/src/agents/codex-native-multi-agent.ts
|
|
5322
5354
|
import { spawn as spawn2 } from "child_process";
|
|
@@ -12584,11 +12616,578 @@ var init_agents = __esm(async () => {
|
|
|
12584
12616
|
loadMaestroProvider = memoizeImport(() => init_maestro_provider().then(() => exports_maestro_provider));
|
|
12585
12617
|
});
|
|
12586
12618
|
|
|
12619
|
+
// ../../packages/core/src/runtime-gateway.ts
|
|
12620
|
+
function parseHostMcpServers(value) {
|
|
12621
|
+
if (value === undefined)
|
|
12622
|
+
return;
|
|
12623
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
12624
|
+
throw new TypeError("hostMcpServers must be an object");
|
|
12625
|
+
}
|
|
12626
|
+
const parsedEntries = [];
|
|
12627
|
+
for (const [name, raw] of Object.entries(value)) {
|
|
12628
|
+
if (!HOST_MCP_SERVER_NAME.test(name)) {
|
|
12629
|
+
throw new TypeError(`invalid host MCP server name: ${name}`);
|
|
12630
|
+
}
|
|
12631
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
12632
|
+
throw new TypeError(`hostMcpServers.${name} must be an object`);
|
|
12633
|
+
}
|
|
12634
|
+
const spec = raw;
|
|
12635
|
+
const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));
|
|
12636
|
+
if (unsupported) {
|
|
12637
|
+
throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);
|
|
12638
|
+
}
|
|
12639
|
+
if (spec.type !== "sse" && spec.type !== "http") {
|
|
12640
|
+
throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);
|
|
12641
|
+
}
|
|
12642
|
+
if (typeof spec.url !== "string") {
|
|
12643
|
+
throw new TypeError(`hostMcpServers.${name}.url must be a string`);
|
|
12644
|
+
}
|
|
12645
|
+
let url;
|
|
12646
|
+
try {
|
|
12647
|
+
url = new URL(spec.url);
|
|
12648
|
+
} catch {
|
|
12649
|
+
throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);
|
|
12650
|
+
}
|
|
12651
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
12652
|
+
throw new TypeError(`hostMcpServers.${name}.url must use http or https`);
|
|
12653
|
+
}
|
|
12654
|
+
let headers;
|
|
12655
|
+
if (spec.headers !== undefined) {
|
|
12656
|
+
if (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)) {
|
|
12657
|
+
throw new TypeError(`hostMcpServers.${name}.headers must be an object`);
|
|
12658
|
+
}
|
|
12659
|
+
const headerEntries = [];
|
|
12660
|
+
for (const [key, headerValue] of Object.entries(spec.headers)) {
|
|
12661
|
+
if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== "string") {
|
|
12662
|
+
throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);
|
|
12663
|
+
}
|
|
12664
|
+
try {
|
|
12665
|
+
new Headers([[key, headerValue]]);
|
|
12666
|
+
} catch {
|
|
12667
|
+
throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);
|
|
12668
|
+
}
|
|
12669
|
+
headerEntries.push([key, headerValue]);
|
|
12670
|
+
}
|
|
12671
|
+
headers = Object.fromEntries(headerEntries);
|
|
12672
|
+
}
|
|
12673
|
+
if (spec.timeout !== undefined && (typeof spec.timeout !== "number" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)) {
|
|
12674
|
+
throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);
|
|
12675
|
+
}
|
|
12676
|
+
parsedEntries.push([
|
|
12677
|
+
name,
|
|
12678
|
+
{
|
|
12679
|
+
type: spec.type,
|
|
12680
|
+
url: url.toString(),
|
|
12681
|
+
...headers ? { headers } : {},
|
|
12682
|
+
...spec.timeout !== undefined ? { timeout: spec.timeout } : {}
|
|
12683
|
+
}
|
|
12684
|
+
]);
|
|
12685
|
+
}
|
|
12686
|
+
return Object.fromEntries(parsedEntries);
|
|
12687
|
+
}
|
|
12688
|
+
var HOST_MCP_SERVER_NAME, HOST_MCP_SERVER_KEYS, HTTP_HEADER_NAME;
|
|
12689
|
+
var init_runtime_gateway = __esm(() => {
|
|
12690
|
+
HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
12691
|
+
HOST_MCP_SERVER_KEYS = new Set(["type", "url", "headers", "timeout"]);
|
|
12692
|
+
HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
12693
|
+
});
|
|
12694
|
+
|
|
12695
|
+
// ../../packages/core/src/topics/agent-plugins/mcp.schema.json
|
|
12696
|
+
var mcp_schema_default;
|
|
12697
|
+
var init_mcp_schema = __esm(() => {
|
|
12698
|
+
mcp_schema_default = {
|
|
12699
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
12700
|
+
$id: "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
12701
|
+
title: "Agent Plugins MCP Configuration",
|
|
12702
|
+
description: "Machine-readable schema for mcp.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.",
|
|
12703
|
+
type: "object",
|
|
12704
|
+
properties: {
|
|
12705
|
+
$schema: {
|
|
12706
|
+
const: "https://agent-plugins.org/schemas/1.0.0/mcp.schema.json",
|
|
12707
|
+
description: "Canonical identifier of the MCP configuration schema for the Agent Plugins version targeted by this document."
|
|
12708
|
+
},
|
|
12709
|
+
mcpServers: {
|
|
12710
|
+
type: "object",
|
|
12711
|
+
additionalProperties: {
|
|
12712
|
+
$ref: "#/$defs/server"
|
|
12713
|
+
}
|
|
12714
|
+
}
|
|
12715
|
+
},
|
|
12716
|
+
required: ["$schema", "mcpServers"],
|
|
12717
|
+
additionalProperties: false,
|
|
12718
|
+
$defs: {
|
|
12719
|
+
server: {
|
|
12720
|
+
title: "MCP server",
|
|
12721
|
+
oneOf: [
|
|
12722
|
+
{
|
|
12723
|
+
$ref: "#/$defs/stdioServer"
|
|
12724
|
+
},
|
|
12725
|
+
{
|
|
12726
|
+
$ref: "#/$defs/streamableHttpServer"
|
|
12727
|
+
},
|
|
12728
|
+
{
|
|
12729
|
+
$ref: "#/$defs/sseServer"
|
|
12730
|
+
}
|
|
12731
|
+
]
|
|
12732
|
+
},
|
|
12733
|
+
stdioServer: {
|
|
12734
|
+
title: "stdio MCP server",
|
|
12735
|
+
type: "object",
|
|
12736
|
+
properties: {
|
|
12737
|
+
type: {
|
|
12738
|
+
const: "stdio"
|
|
12739
|
+
},
|
|
12740
|
+
command: {
|
|
12741
|
+
type: "string",
|
|
12742
|
+
minLength: 1,
|
|
12743
|
+
description: "Executable token. Resolution rules are defined by the Agent Plugins specification."
|
|
12744
|
+
},
|
|
12745
|
+
args: {
|
|
12746
|
+
type: "array",
|
|
12747
|
+
items: {
|
|
12748
|
+
type: "string"
|
|
12749
|
+
}
|
|
12750
|
+
},
|
|
12751
|
+
env: {
|
|
12752
|
+
type: "object",
|
|
12753
|
+
propertyNames: {
|
|
12754
|
+
not: {
|
|
12755
|
+
enum: ["PLUGIN_ROOT", "PLUGIN_DATA"]
|
|
12756
|
+
}
|
|
12757
|
+
},
|
|
12758
|
+
additionalProperties: {
|
|
12759
|
+
type: "string"
|
|
12760
|
+
}
|
|
12761
|
+
},
|
|
12762
|
+
cwd: {
|
|
12763
|
+
type: "string",
|
|
12764
|
+
pattern: "^(?:\\./|\\$\\{PLUGIN_ROOT\\}(?:/|$)|\\$\\{PLUGIN_DATA\\}(?:/|$))",
|
|
12765
|
+
description: "Plugin-relative, PLUGIN_ROOT-rooted, or PLUGIN_DATA-rooted working directory. Filesystem containment is validated separately."
|
|
12766
|
+
}
|
|
12767
|
+
},
|
|
12768
|
+
required: ["type", "command"],
|
|
12769
|
+
additionalProperties: false
|
|
12770
|
+
},
|
|
12771
|
+
streamableHttpServer: {
|
|
12772
|
+
title: "Streamable HTTP MCP server",
|
|
12773
|
+
type: "object",
|
|
12774
|
+
properties: {
|
|
12775
|
+
type: {
|
|
12776
|
+
const: "streamable-http"
|
|
12777
|
+
},
|
|
12778
|
+
url: {
|
|
12779
|
+
type: "string",
|
|
12780
|
+
minLength: 1,
|
|
12781
|
+
description: "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
12782
|
+
},
|
|
12783
|
+
headers: {
|
|
12784
|
+
$ref: "#/$defs/headers"
|
|
12785
|
+
}
|
|
12786
|
+
},
|
|
12787
|
+
required: ["type", "url"],
|
|
12788
|
+
additionalProperties: false
|
|
12789
|
+
},
|
|
12790
|
+
sseServer: {
|
|
12791
|
+
title: "Legacy HTTP+SSE MCP server",
|
|
12792
|
+
type: "object",
|
|
12793
|
+
properties: {
|
|
12794
|
+
type: {
|
|
12795
|
+
const: "sse"
|
|
12796
|
+
},
|
|
12797
|
+
url: {
|
|
12798
|
+
type: "string",
|
|
12799
|
+
minLength: 1,
|
|
12800
|
+
description: "MCP endpoint URL. URL semantics are defined by the Agent Plugins specification."
|
|
12801
|
+
},
|
|
12802
|
+
headers: {
|
|
12803
|
+
$ref: "#/$defs/headers"
|
|
12804
|
+
}
|
|
12805
|
+
},
|
|
12806
|
+
required: ["type", "url"],
|
|
12807
|
+
additionalProperties: false
|
|
12808
|
+
},
|
|
12809
|
+
headers: {
|
|
12810
|
+
title: "HTTP headers",
|
|
12811
|
+
type: "object",
|
|
12812
|
+
additionalProperties: {
|
|
12813
|
+
type: "string"
|
|
12814
|
+
}
|
|
12815
|
+
}
|
|
12816
|
+
}
|
|
12817
|
+
};
|
|
12818
|
+
});
|
|
12819
|
+
|
|
12820
|
+
// ../../packages/core/src/topics/agent-plugins/plugin.schema.json
|
|
12821
|
+
var plugin_schema_default;
|
|
12822
|
+
var init_plugin_schema = __esm(() => {
|
|
12823
|
+
plugin_schema_default = {
|
|
12824
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
12825
|
+
$id: "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
12826
|
+
title: "Agent Plugins Manifest",
|
|
12827
|
+
description: "Machine-readable schema for plugin.json in Agent Plugins 1.0.0. The Agent Plugins specification defines additional semantic and operational requirements.",
|
|
12828
|
+
type: "object",
|
|
12829
|
+
properties: {
|
|
12830
|
+
$schema: {
|
|
12831
|
+
const: "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
12832
|
+
description: "Canonical identifier of the plugin manifest schema for the Agent Plugins version targeted by this document."
|
|
12833
|
+
},
|
|
12834
|
+
name: {
|
|
12835
|
+
type: "string",
|
|
12836
|
+
minLength: 1,
|
|
12837
|
+
maxLength: 64,
|
|
12838
|
+
pattern: "^(?!.*(?:--|\\.\\.))[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?$",
|
|
12839
|
+
description: "Human-readable plugin name."
|
|
12840
|
+
},
|
|
12841
|
+
version: {
|
|
12842
|
+
type: "string"
|
|
12843
|
+
},
|
|
12844
|
+
description: {
|
|
12845
|
+
type: "string"
|
|
12846
|
+
},
|
|
12847
|
+
author: {
|
|
12848
|
+
type: "object",
|
|
12849
|
+
properties: {
|
|
12850
|
+
name: {
|
|
12851
|
+
type: "string"
|
|
12852
|
+
},
|
|
12853
|
+
email: {
|
|
12854
|
+
type: "string"
|
|
12855
|
+
},
|
|
12856
|
+
url: {
|
|
12857
|
+
type: "string"
|
|
12858
|
+
}
|
|
12859
|
+
},
|
|
12860
|
+
additionalProperties: false
|
|
12861
|
+
},
|
|
12862
|
+
homepage: {
|
|
12863
|
+
type: "string"
|
|
12864
|
+
},
|
|
12865
|
+
repository: {
|
|
12866
|
+
type: "string"
|
|
12867
|
+
},
|
|
12868
|
+
license: {
|
|
12869
|
+
type: "string"
|
|
12870
|
+
},
|
|
12871
|
+
keywords: {
|
|
12872
|
+
type: "array",
|
|
12873
|
+
items: {
|
|
12874
|
+
type: "string"
|
|
12875
|
+
}
|
|
12876
|
+
},
|
|
12877
|
+
extensions: {
|
|
12878
|
+
type: "object",
|
|
12879
|
+
description: "Client-specific manifest data keyed by reverse-domain extension namespace. Agent Plugins assigns no semantics to namespace object contents.",
|
|
12880
|
+
additionalProperties: {
|
|
12881
|
+
type: "object"
|
|
12882
|
+
}
|
|
12883
|
+
}
|
|
12884
|
+
},
|
|
12885
|
+
required: ["$schema", "name"],
|
|
12886
|
+
additionalProperties: false
|
|
12887
|
+
};
|
|
12888
|
+
});
|
|
12889
|
+
|
|
12890
|
+
// ../../packages/core/src/topics/plugins.ts
|
|
12891
|
+
import { existsSync as existsSync22, readdirSync as readdirSync5, readFileSync as readFileSync17, realpathSync as realpathSync6, statSync as statSync8 } from "fs";
|
|
12892
|
+
import { isAbsolute as isAbsolute6, join as join23, relative as relative4 } from "path";
|
|
12893
|
+
import { z as z5 } from "zod";
|
|
12894
|
+
function readText(path) {
|
|
12895
|
+
return readFileSync17(path, "utf-8").replace(/^\uFEFF/, "").replace(/\r\n/g, `
|
|
12896
|
+
`);
|
|
12897
|
+
}
|
|
12898
|
+
function pathKind(root, path) {
|
|
12899
|
+
if (!existsSync22(path))
|
|
12900
|
+
return "missing";
|
|
12901
|
+
const real = realpathSync6(path);
|
|
12902
|
+
const fromRoot = relative4(root, real);
|
|
12903
|
+
if (fromRoot.startsWith("..") || isAbsolute6(fromRoot))
|
|
12904
|
+
return "outside";
|
|
12905
|
+
const stat = statSync8(real);
|
|
12906
|
+
return stat.isFile() ? "file" : stat.isDirectory() ? "dir" : "other";
|
|
12907
|
+
}
|
|
12908
|
+
function parseFrontmatter(raw) {
|
|
12909
|
+
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
12910
|
+
if (!match)
|
|
12911
|
+
return { ok: false, problem: "missing the --- frontmatter block" };
|
|
12912
|
+
let meta;
|
|
12913
|
+
try {
|
|
12914
|
+
meta = Bun.YAML.parse(match[1]);
|
|
12915
|
+
} catch (error) {
|
|
12916
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
12917
|
+
return { ok: false, problem: `frontmatter is not valid YAML (${reason})` };
|
|
12918
|
+
}
|
|
12919
|
+
if (!isObject(meta))
|
|
12920
|
+
return { ok: false, problem: "frontmatter must be a YAML mapping" };
|
|
12921
|
+
return { ok: true, meta, body: match[2] };
|
|
12922
|
+
}
|
|
12923
|
+
function readJson(path, fail) {
|
|
12924
|
+
try {
|
|
12925
|
+
return JSON.parse(readText(path));
|
|
12926
|
+
} catch (error) {
|
|
12927
|
+
fail(`not valid JSON (${error instanceof Error ? error.message : String(error)})`);
|
|
12928
|
+
return;
|
|
12929
|
+
}
|
|
12930
|
+
}
|
|
12931
|
+
function manifestSchema() {
|
|
12932
|
+
manifestValidator ??= z5.fromJSONSchema(plugin_schema_default);
|
|
12933
|
+
return manifestValidator;
|
|
12934
|
+
}
|
|
12935
|
+
function readManifest(root, fail) {
|
|
12936
|
+
const path = join23(root, MANIFEST_FILE);
|
|
12937
|
+
const kind = pathKind(root, path);
|
|
12938
|
+
if (kind !== "file") {
|
|
12939
|
+
fail(kind === "outside" ? "resolves outside the plugin folder" : "missing");
|
|
12940
|
+
return null;
|
|
12941
|
+
}
|
|
12942
|
+
const raw = readJson(path, fail);
|
|
12943
|
+
if (raw === undefined)
|
|
12944
|
+
return null;
|
|
12945
|
+
if (!isObject(raw)) {
|
|
12946
|
+
fail("must be a JSON object");
|
|
12947
|
+
return null;
|
|
12948
|
+
}
|
|
12949
|
+
const manifest = {};
|
|
12950
|
+
for (const [field, value] of Object.entries(raw)) {
|
|
12951
|
+
if (!MANIFEST_FIELDS.has(field))
|
|
12952
|
+
fail(`unknown field "${field}" is ignored`);
|
|
12953
|
+
else if (field === "extensions" && !isObject(value)) {
|
|
12954
|
+
fail('"extensions" is not an object and is ignored');
|
|
12955
|
+
} else
|
|
12956
|
+
manifest[field] = value;
|
|
12957
|
+
}
|
|
12958
|
+
if (typeof manifest.$schema === "string" && manifest.$schema !== MANIFEST_SCHEMA_ID) {
|
|
12959
|
+
fail(`unsupported Agent Plugins version: $schema "${manifest.$schema}"`);
|
|
12960
|
+
return null;
|
|
12961
|
+
}
|
|
12962
|
+
const checked = manifestSchema().safeParse(manifest);
|
|
12963
|
+
if (!checked.success) {
|
|
12964
|
+
for (const issue of checked.error.issues) {
|
|
12965
|
+
fail(`${issue.path.length > 0 ? `${issue.path.join(".")}: ` : ""}${issue.message}`);
|
|
12966
|
+
}
|
|
12967
|
+
return null;
|
|
12968
|
+
}
|
|
12969
|
+
return { id: String(manifest.name) };
|
|
12970
|
+
}
|
|
12971
|
+
function readSkill(root, dir, name, fail) {
|
|
12972
|
+
const where = `${SKILLS_DIR}/${name}/${SKILL_FILE}`;
|
|
12973
|
+
const path = join23(dir, SKILLS_DIR, name, SKILL_FILE);
|
|
12974
|
+
const kind = pathKind(root, path);
|
|
12975
|
+
if (kind === "outside") {
|
|
12976
|
+
fail(where, "resolves outside the plugin folder; skipped");
|
|
12977
|
+
return null;
|
|
12978
|
+
}
|
|
12979
|
+
if (kind !== "file")
|
|
12980
|
+
return null;
|
|
12981
|
+
const parsed = parseFrontmatter(readText(path));
|
|
12982
|
+
if (!parsed.ok) {
|
|
12983
|
+
fail(where, `${parsed.problem}; skipped`);
|
|
12984
|
+
return null;
|
|
12985
|
+
}
|
|
12986
|
+
const problems = [];
|
|
12987
|
+
const skillName = parsed.meta.name;
|
|
12988
|
+
const description = typeof parsed.meta.description === "string" ? parsed.meta.description.trim() : "";
|
|
12989
|
+
if (skillName !== name)
|
|
12990
|
+
problems.push(`name must be the folder's name "${name}"`);
|
|
12991
|
+
else if (!SKILL_NAME.test(name) || name.length > MAX_SKILL_NAME_CHARS) {
|
|
12992
|
+
problems.push("name must be 1-64 lowercase letters, digits and single inner hyphens");
|
|
12993
|
+
}
|
|
12994
|
+
if (!description)
|
|
12995
|
+
problems.push("description (when to read it) is missing");
|
|
12996
|
+
else if (description.length > MAX_SKILL_DESCRIPTION_CHARS) {
|
|
12997
|
+
problems.push(`description is over ${MAX_SKILL_DESCRIPTION_CHARS} characters`);
|
|
12998
|
+
}
|
|
12999
|
+
if (problems.length > 0) {
|
|
13000
|
+
fail(where, `${problems.join("; ")}; skipped`);
|
|
13001
|
+
return null;
|
|
13002
|
+
}
|
|
13003
|
+
return { name, description, path };
|
|
13004
|
+
}
|
|
13005
|
+
function readSkills(root, dir, fail) {
|
|
13006
|
+
const skillsDir = join23(root, SKILLS_DIR);
|
|
13007
|
+
const kind = pathKind(root, skillsDir);
|
|
13008
|
+
if (kind === "missing")
|
|
13009
|
+
return [];
|
|
13010
|
+
if (kind !== "dir") {
|
|
13011
|
+
fail(SKILLS_DIR, kind === "outside" ? "resolves outside the plugin folder" : "not a folder");
|
|
13012
|
+
return [];
|
|
13013
|
+
}
|
|
13014
|
+
return readdirSync5(skillsDir).filter(visible).sort(byName).flatMap((name) => readSkill(root, dir, name, fail) ?? []);
|
|
13015
|
+
}
|
|
13016
|
+
function remoteUrlProblem(raw) {
|
|
13017
|
+
let url;
|
|
13018
|
+
try {
|
|
13019
|
+
url = new URL(raw);
|
|
13020
|
+
} catch {
|
|
13021
|
+
return "url must be an absolute http or https URL";
|
|
13022
|
+
}
|
|
13023
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
13024
|
+
return "url must be an absolute http or https URL";
|
|
13025
|
+
}
|
|
13026
|
+
if (url.username || url.password)
|
|
13027
|
+
return "url must not contain user information";
|
|
13028
|
+
if (url.hash || raw.includes("#"))
|
|
13029
|
+
return "url must not contain a fragment";
|
|
13030
|
+
if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
|
|
13031
|
+
return "a non-loopback url must use https";
|
|
13032
|
+
}
|
|
13033
|
+
return null;
|
|
13034
|
+
}
|
|
13035
|
+
function isLoopbackHost(hostname) {
|
|
13036
|
+
if (hostname === "localhost" || hostname === "[::1]")
|
|
13037
|
+
return true;
|
|
13038
|
+
const parts = hostname.split(".");
|
|
13039
|
+
return parts.length === 4 && parts[0] === "127" && parts.every((part) => /^\d{1,3}$/.test(part) && Number(part) <= 255);
|
|
13040
|
+
}
|
|
13041
|
+
function readServer(name, spec, fail) {
|
|
13042
|
+
if (!isObject(spec) || typeof spec.type !== "string") {
|
|
13043
|
+
fail(`"${name}": a server is an object with a "type"; skipped`);
|
|
13044
|
+
return null;
|
|
13045
|
+
}
|
|
13046
|
+
if (spec.type === "stdio") {
|
|
13047
|
+
fail(`"${name}": stdio servers are not supported here (remote servers only); skipped`);
|
|
13048
|
+
return null;
|
|
13049
|
+
}
|
|
13050
|
+
const variant = REMOTE_SERVERS[spec.type];
|
|
13051
|
+
if (!variant) {
|
|
13052
|
+
fail(`"${name}": unknown type "${spec.type}"; skipped`);
|
|
13053
|
+
return null;
|
|
13054
|
+
}
|
|
13055
|
+
const allowed = new Set(Object.keys(variant.properties));
|
|
13056
|
+
const unknown = Object.keys(spec).find((key) => !allowed.has(key));
|
|
13057
|
+
if (unknown) {
|
|
13058
|
+
fail(`"${name}": field "${unknown}" does not belong to a ${spec.type} server; skipped`);
|
|
13059
|
+
return null;
|
|
13060
|
+
}
|
|
13061
|
+
if (typeof spec.url !== "string" || !spec.url) {
|
|
13062
|
+
fail(`"${name}": url is required; skipped`);
|
|
13063
|
+
return null;
|
|
13064
|
+
}
|
|
13065
|
+
const headers = spec.headers;
|
|
13066
|
+
if (headers !== undefined) {
|
|
13067
|
+
const values = isObject(headers) ? Object.entries(headers) : null;
|
|
13068
|
+
const lower = values?.map(([key]) => key.toLowerCase()) ?? [];
|
|
13069
|
+
if (!values || values.some(([, value]) => typeof value !== "string") || new Set(lower).size !== lower.length) {
|
|
13070
|
+
fail(`"${name}": headers must be distinct header names with string values; skipped`);
|
|
13071
|
+
return null;
|
|
13072
|
+
}
|
|
13073
|
+
}
|
|
13074
|
+
const server = {
|
|
13075
|
+
type: NODE_TRANSPORT[spec.type],
|
|
13076
|
+
url: spec.url,
|
|
13077
|
+
...headers ? { headers } : {}
|
|
13078
|
+
};
|
|
13079
|
+
const urlProblem = remoteUrlProblem(spec.url);
|
|
13080
|
+
if (urlProblem) {
|
|
13081
|
+
fail(`"${name}": ${urlProblem}; skipped`);
|
|
13082
|
+
return null;
|
|
13083
|
+
}
|
|
13084
|
+
try {
|
|
13085
|
+
parseHostMcpServers({ [name]: server });
|
|
13086
|
+
} catch (error) {
|
|
13087
|
+
fail(`"${name}": ${error instanceof Error ? error.message : String(error)}; skipped`);
|
|
13088
|
+
return null;
|
|
13089
|
+
}
|
|
13090
|
+
return server;
|
|
13091
|
+
}
|
|
13092
|
+
function readMcpFile(root, fail) {
|
|
13093
|
+
const path = join23(root, MCP_FILE);
|
|
13094
|
+
const kind = pathKind(root, path);
|
|
13095
|
+
if (kind === "missing")
|
|
13096
|
+
return {};
|
|
13097
|
+
if (kind !== "file") {
|
|
13098
|
+
fail(`${kind === "outside" ? "resolves outside the plugin folder" : "not a file"}; no servers`);
|
|
13099
|
+
return {};
|
|
13100
|
+
}
|
|
13101
|
+
const raw = readJson(path, fail);
|
|
13102
|
+
if (raw === undefined)
|
|
13103
|
+
return {};
|
|
13104
|
+
const extra = isObject(raw) ? Object.keys(raw).find((key) => key !== "$schema" && key !== "mcpServers") : undefined;
|
|
13105
|
+
if (!isObject(raw) || raw.$schema !== MCP_SCHEMA_ID || !isObject(raw.mcpServers) || extra) {
|
|
13106
|
+
fail(`must be {"$schema": "${MCP_SCHEMA_ID}", "mcpServers": {\u2026}} and nothing else; no servers`);
|
|
13107
|
+
return {};
|
|
13108
|
+
}
|
|
13109
|
+
const servers = {};
|
|
13110
|
+
for (const [name, spec] of Object.entries(raw.mcpServers)) {
|
|
13111
|
+
const server = readServer(name, spec, fail);
|
|
13112
|
+
if (server)
|
|
13113
|
+
servers[name] = server;
|
|
13114
|
+
}
|
|
13115
|
+
return servers;
|
|
13116
|
+
}
|
|
13117
|
+
function loadTopicPlugins(dirs) {
|
|
13118
|
+
const problems = [];
|
|
13119
|
+
const plugins = [];
|
|
13120
|
+
const pluginOwner = new Map;
|
|
13121
|
+
const skillOwner = new Map;
|
|
13122
|
+
const serverOwner = new Map;
|
|
13123
|
+
for (const dir of dirs) {
|
|
13124
|
+
if (!isAbsolute6(dir)) {
|
|
13125
|
+
problems.push(`${dir}: a plugin is given by its folder's absolute path`);
|
|
13126
|
+
continue;
|
|
13127
|
+
}
|
|
13128
|
+
if (!existsSync22(dir) || !statSync8(dir).isDirectory()) {
|
|
13129
|
+
problems.push(`${dir}: not a folder`);
|
|
13130
|
+
continue;
|
|
13131
|
+
}
|
|
13132
|
+
const root = realpathSync6(dir);
|
|
13133
|
+
const failIn = (file, problem) => problems.push(`${dir}/${file}: ${problem}`);
|
|
13134
|
+
const manifest = readManifest(root, (problem) => failIn(MANIFEST_FILE, problem));
|
|
13135
|
+
if (!manifest)
|
|
13136
|
+
continue;
|
|
13137
|
+
const owner = pluginOwner.get(manifest.id);
|
|
13138
|
+
if (owner) {
|
|
13139
|
+
failIn(MANIFEST_FILE, `plugin name "${manifest.id}" is already used by ${owner}; skipped`);
|
|
13140
|
+
continue;
|
|
13141
|
+
}
|
|
13142
|
+
pluginOwner.set(manifest.id, dir);
|
|
13143
|
+
const unique = (owners, key, what, file) => {
|
|
13144
|
+
const other = owners.get(key);
|
|
13145
|
+
if (other)
|
|
13146
|
+
failIn(file, `${what} "${key}" is already used by ${other}; skipped`);
|
|
13147
|
+
else
|
|
13148
|
+
owners.set(key, dir);
|
|
13149
|
+
return !other;
|
|
13150
|
+
};
|
|
13151
|
+
const skills = readSkills(root, dir, failIn).filter((skill) => unique(skillOwner, skill.name, "skill name", SKILLS_DIR));
|
|
13152
|
+
const mcpServers = Object.fromEntries(Object.entries(readMcpFile(root, (problem) => failIn(MCP_FILE, problem))).filter(([name]) => unique(serverOwner, name, "server name", MCP_FILE)));
|
|
13153
|
+
plugins.push({ ...manifest, dir, skills, mcpServers });
|
|
13154
|
+
}
|
|
13155
|
+
return { plugins, problems };
|
|
13156
|
+
}
|
|
13157
|
+
function renderTopicPluginsPrompt(plugins) {
|
|
13158
|
+
const skills = plugins.flatMap((plugin) => plugin.skills);
|
|
13159
|
+
if (skills.length === 0)
|
|
13160
|
+
return "";
|
|
13161
|
+
return [
|
|
13162
|
+
"## Skills",
|
|
13163
|
+
"",
|
|
13164
|
+
"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.",
|
|
13165
|
+
"",
|
|
13166
|
+
...skills.map((skill) => `- \`${skill.name}\`: ${skill.description} (file: ${skill.path})`)
|
|
13167
|
+
].join(`
|
|
13168
|
+
`);
|
|
13169
|
+
}
|
|
13170
|
+
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;
|
|
13171
|
+
var init_plugins = __esm(() => {
|
|
13172
|
+
init_runtime_gateway();
|
|
13173
|
+
init_mcp_schema();
|
|
13174
|
+
init_plugin_schema();
|
|
13175
|
+
MANIFEST_SCHEMA_ID = plugin_schema_default.properties.$schema.const;
|
|
13176
|
+
MCP_SCHEMA_ID = mcp_schema_default.properties.$schema.const;
|
|
13177
|
+
MANIFEST_FIELDS = new Set(Object.keys(plugin_schema_default.properties));
|
|
13178
|
+
REMOTE_SERVERS = {
|
|
13179
|
+
"streamable-http": mcp_schema_default.$defs.streamableHttpServer,
|
|
13180
|
+
sse: mcp_schema_default.$defs.sseServer
|
|
13181
|
+
};
|
|
13182
|
+
NODE_TRANSPORT = { "streamable-http": "http", sse: "sse" };
|
|
13183
|
+
SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
13184
|
+
});
|
|
13185
|
+
|
|
12587
13186
|
// ../../packages/core/src/prompts/builders.ts
|
|
12588
|
-
import { readFileSync as
|
|
13187
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
12589
13188
|
import { resolve as resolve16 } from "path";
|
|
12590
13189
|
function loadPrompt(filename, dir = SESSIONS_DIR) {
|
|
12591
|
-
const raw =
|
|
13190
|
+
const raw = readFileSync18(resolve16(dir, filename), "utf-8");
|
|
12592
13191
|
return raw.replace(/\{\{RESOURCES_DIR\}\}/g, RESOURCES_DIR);
|
|
12593
13192
|
}
|
|
12594
13193
|
function replaceVars(template, vars) {
|
|
@@ -12651,7 +13250,7 @@ function visualDesignGuide() {
|
|
|
12651
13250
|
return _visualDesignGuide;
|
|
12652
13251
|
}
|
|
12653
13252
|
function loadAgentPrompt(filename) {
|
|
12654
|
-
const raw =
|
|
13253
|
+
const raw = readFileSync18(resolve16(AGENTS_PROMPTS_DIR, filename), "utf-8");
|
|
12655
13254
|
const match = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
12656
13255
|
if (!match)
|
|
12657
13256
|
throw new Error(`Agent prompt ${filename} is missing frontmatter`);
|
|
@@ -12899,6 +13498,11 @@ function createPromptBuilders(host = {}) {
|
|
|
12899
13498
|
## Topic-Specific Instructions
|
|
12900
13499
|
${opts.description.trim()}`;
|
|
12901
13500
|
}
|
|
13501
|
+
const plugins = renderTopicPluginsPrompt(opts.plugins ?? []);
|
|
13502
|
+
if (plugins)
|
|
13503
|
+
prompt += `
|
|
13504
|
+
|
|
13505
|
+
${plugins}`;
|
|
12902
13506
|
if (sessionKind === "manager") {
|
|
12903
13507
|
const managerTemplate = replaceVars(template(opts.surface === "otium" ? {
|
|
12904
13508
|
kind: "surface-profile",
|
|
@@ -12988,6 +13592,7 @@ var init_builders = __esm(() => {
|
|
|
12988
13592
|
init_browser_backend();
|
|
12989
13593
|
init_config();
|
|
12990
13594
|
init_logger();
|
|
13595
|
+
init_plugins();
|
|
12991
13596
|
PROMPTS_DIR = resolve16(PROJECT_ROOT, "src/prompts");
|
|
12992
13597
|
SESSIONS_DIR = resolve16(PROMPTS_DIR, "sessions");
|
|
12993
13598
|
SURFACE_PROFILE_FILES = {
|
|
@@ -13072,9 +13677,9 @@ var init_api_topic_brief = __esm(async () => {
|
|
|
13072
13677
|
});
|
|
13073
13678
|
|
|
13074
13679
|
// ../../packages/core/src/storage/wiki.ts
|
|
13075
|
-
import { basename as basename5, dirname as dirname15, join as
|
|
13680
|
+
import { basename as basename5, dirname as dirname15, join as join24 } from "path";
|
|
13076
13681
|
function getSharedWikiDir(workspaceDir = resolveStorageWorkspaceDir()) {
|
|
13077
|
-
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() :
|
|
13682
|
+
return workspaceDir === resolveStorageWorkspaceDir() ? resolveStorageSharedWikiDir() : join24(workspaceDir, "wiki");
|
|
13078
13683
|
}
|
|
13079
13684
|
var init_wiki = __esm(async () => {
|
|
13080
13685
|
await init_storage_host();
|
|
@@ -13082,8 +13687,8 @@ var init_wiki = __esm(async () => {
|
|
|
13082
13687
|
|
|
13083
13688
|
// ../../packages/core/src/agents/archiver.ts
|
|
13084
13689
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
13085
|
-
import { existsSync as
|
|
13086
|
-
import { join as
|
|
13690
|
+
import { existsSync as existsSync23, readdirSync as readdirSync6, readFileSync as readFileSync19, statSync as statSync9 } from "fs";
|
|
13691
|
+
import { join as join25 } from "path";
|
|
13087
13692
|
function resolveMemoryLanguage() {
|
|
13088
13693
|
const override = process.env.NEGOTIUM_MEMORY_LANG?.trim();
|
|
13089
13694
|
return override && override.length > 0 ? override : resolveOutputLanguage();
|
|
@@ -13341,10 +13946,10 @@ function distillOneLine(summaryMd) {
|
|
|
13341
13946
|
return "";
|
|
13342
13947
|
}
|
|
13343
13948
|
function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
13344
|
-
const dir =
|
|
13949
|
+
const dir = join25(storage.getWikiDir(), "summaries");
|
|
13345
13950
|
if (!storage.fileExists(dir))
|
|
13346
13951
|
return null;
|
|
13347
|
-
const predicted =
|
|
13952
|
+
const predicted = join25(dir, wikiSummaryFilename(date, topicTitle, topicId));
|
|
13348
13953
|
if (storage.fileExists(predicted) && storage.fileModifiedAt(predicted) >= sinceMs)
|
|
13349
13954
|
return predicted;
|
|
13350
13955
|
let best = null;
|
|
@@ -13352,7 +13957,7 @@ function findSummaryFile(storage, topicTitle, date, sinceMs, topicId) {
|
|
|
13352
13957
|
if (!f.startsWith(`${date}-`) || !isTopicSummaryFile(f, topicId ?? "", topicTitle)) {
|
|
13353
13958
|
continue;
|
|
13354
13959
|
}
|
|
13355
|
-
const p =
|
|
13960
|
+
const p = join25(dir, f);
|
|
13356
13961
|
try {
|
|
13357
13962
|
const m = storage.fileModifiedAt(p);
|
|
13358
13963
|
if (m >= sinceMs && (!best || m > best.mtime))
|
|
@@ -13438,11 +14043,11 @@ var init_archiver = __esm(async () => {
|
|
|
13438
14043
|
defaultArchiverRuntime = createArchiverRuntime({
|
|
13439
14044
|
storage: {
|
|
13440
14045
|
getWikiDir: getSharedWikiDir,
|
|
13441
|
-
fileExists:
|
|
13442
|
-
listDirectory:
|
|
13443
|
-
readTextFile: (path) =>
|
|
13444
|
-
fileSize: (path) =>
|
|
13445
|
-
fileModifiedAt: (path) =>
|
|
14046
|
+
fileExists: existsSync23,
|
|
14047
|
+
listDirectory: readdirSync6,
|
|
14048
|
+
readTextFile: (path) => readFileSync19(path, "utf-8"),
|
|
14049
|
+
fileSize: (path) => statSync9(path).size,
|
|
14050
|
+
fileModifiedAt: (path) => statSync9(path).mtimeMs,
|
|
13446
14051
|
getGeneralTopicId: (userId, sourceTopicId) => {
|
|
13447
14052
|
const source = sourceTopicId ? getTopic(sourceTopicId) : null;
|
|
13448
14053
|
return source ? ensurePersonalGeneral(userId, source.surface, {
|
|
@@ -13566,13 +14171,13 @@ function formatTopicArchiveTranscriptRecord(row, topicTitle, index) {
|
|
|
13566
14171
|
|
|
13567
14172
|
// ../../packages/core/src/storage/topic-archive.ts
|
|
13568
14173
|
import { mkdirSync as mkdirSync14, writeFileSync as writeFileSync12 } from "fs";
|
|
13569
|
-
import { join as
|
|
14174
|
+
import { join as join26 } from "path";
|
|
13570
14175
|
function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
13571
14176
|
const rows = options.afterRowid !== undefined ? getMessagesForTopicAfterRowid(topicId, options.afterRowid) : getAllMessagesForTopic(topicId);
|
|
13572
14177
|
if (rows.length === 0)
|
|
13573
14178
|
return null;
|
|
13574
14179
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
13575
|
-
const archiveDir =
|
|
14180
|
+
const archiveDir = join26(getSharedWikiDir(), "archive");
|
|
13576
14181
|
mkdirSync14(archiveDir, { recursive: true });
|
|
13577
14182
|
const date = new Date().toISOString().slice(0, 10);
|
|
13578
14183
|
const reasonSuffix = options.reason && options.reason !== "delete" ? `_${options.reason}` : "";
|
|
@@ -13585,7 +14190,7 @@ function archiveTopicMessages(topicId, topicTitle, options = {}) {
|
|
|
13585
14190
|
let path;
|
|
13586
14191
|
while (true) {
|
|
13587
14192
|
filename = `${safeTopic}_${date}${reasonSuffix}${counter === 1 ? "" : `_${counter}`}.jsonl`;
|
|
13588
|
-
path =
|
|
14193
|
+
path = join26(archiveDir, filename);
|
|
13589
14194
|
try {
|
|
13590
14195
|
writeFileSync12(path, body, { flag: "wx" });
|
|
13591
14196
|
break;
|
|
@@ -13630,7 +14235,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
13630
14235
|
const entries = readRawConversation(userId, topicTitle);
|
|
13631
14236
|
if (entries.length === 0)
|
|
13632
14237
|
return null;
|
|
13633
|
-
const archiveDir =
|
|
14238
|
+
const archiveDir = join26(getSharedWikiDir(), "archive");
|
|
13634
14239
|
mkdirSync14(archiveDir, { recursive: true });
|
|
13635
14240
|
const safeTopic = sanitizeTopicName(topicTitle, true);
|
|
13636
14241
|
const date = new Date().toISOString().slice(0, 10);
|
|
@@ -13658,7 +14263,7 @@ function archiveConversationEvents(topicId, topicTitle, userId, options = {}) {
|
|
|
13658
14263
|
let counter = 1;
|
|
13659
14264
|
while (true) {
|
|
13660
14265
|
const suffix = counter === 1 ? "" : `_${counter}`;
|
|
13661
|
-
const path =
|
|
14266
|
+
const path = join26(archiveDir, `${safeTopic}_${date}${reasonSuffix}_events${suffix}.jsonl`);
|
|
13662
14267
|
try {
|
|
13663
14268
|
writeFileSync12(path, body, { flag: "wx" });
|
|
13664
14269
|
logger.info({ topicId, topicTitle, archive: path, eventCount: entries.length }, "archiveConversationEvents: archived raw conversation events");
|
|
@@ -13986,7 +14591,7 @@ var init_idle_archiver = __esm(async () => {
|
|
|
13986
14591
|
// ../../packages/core/src/storage/token-stats.ts
|
|
13987
14592
|
import { createHash as createHash7 } from "crypto";
|
|
13988
14593
|
import { mkdirSync as mkdirSync15, writeFileSync as writeFileSync13 } from "fs";
|
|
13989
|
-
import { join as
|
|
14594
|
+
import { join as join27 } from "path";
|
|
13990
14595
|
function emptyBucket() {
|
|
13991
14596
|
return {
|
|
13992
14597
|
inputTokens: 0,
|
|
@@ -14005,7 +14610,7 @@ function queriesPath(userId) {
|
|
|
14005
14610
|
const fileId = tokenStatsFileId(userId);
|
|
14006
14611
|
const logDir = resolveStorageLogDir();
|
|
14007
14612
|
mkdirSync15(logDir, { recursive: true });
|
|
14008
|
-
return
|
|
14613
|
+
return join27(logDir, `token-queries-${fileId}.jsonl`);
|
|
14009
14614
|
}
|
|
14010
14615
|
function loadRecords(userId) {
|
|
14011
14616
|
try {
|
|
@@ -14632,7 +15237,7 @@ var init_usage_alert = __esm(() => {
|
|
|
14632
15237
|
import { randomUUID as randomUUID12 } from "crypto";
|
|
14633
15238
|
import { mkdtempSync as mkdtempSync2, rmSync as rmSync4, writeFileSync as writeFileSync15 } from "fs";
|
|
14634
15239
|
import { tmpdir as tmpdir4 } from "os";
|
|
14635
|
-
import { join as
|
|
15240
|
+
import { join as join28 } from "path";
|
|
14636
15241
|
async function fenceTopicWork(topicId, maintenance) {
|
|
14637
15242
|
for (const queryId of cancelRuntimeUserTurnRequestsBeforeEpoch(topicId, maintenance.epoch)) {
|
|
14638
15243
|
WsHub.get().broadcastAborted(topicId, queryId, "stopped");
|
|
@@ -14841,7 +15446,7 @@ function formatCompactElapsed(startedAt) {
|
|
|
14841
15446
|
async function summarizeTopicContext(request) {
|
|
14842
15447
|
const startedAt = Date.now();
|
|
14843
15448
|
const sessionIds = [];
|
|
14844
|
-
const compactCwd = mkdtempSync2(
|
|
15449
|
+
const compactCwd = mkdtempSync2(join28(tmpdir4(), "negotium-compact-"));
|
|
14845
15450
|
const abortController = new AbortController;
|
|
14846
15451
|
const relayAbort = () => abortController.abort(request.signal?.reason);
|
|
14847
15452
|
if (request.signal?.aborted)
|
|
@@ -14868,7 +15473,7 @@ async function summarizeTopicContext(request) {
|
|
|
14868
15473
|
let error = "";
|
|
14869
15474
|
let toolViolation = false;
|
|
14870
15475
|
let compactionLogCalls = 0;
|
|
14871
|
-
const compactionLogPath =
|
|
15476
|
+
const compactionLogPath = join28(compactCwd, "conversation.log");
|
|
14872
15477
|
try {
|
|
14873
15478
|
const compactionMcp = useCompactionLog ? {
|
|
14874
15479
|
compact_log: {
|
|
@@ -15627,14 +16232,14 @@ var init_derive = __esm(async () => {
|
|
|
15627
16232
|
});
|
|
15628
16233
|
|
|
15629
16234
|
// ../../packages/core/src/query/session-inbox-path.ts
|
|
15630
|
-
import { join as
|
|
16235
|
+
import { join as join29 } from "path";
|
|
15631
16236
|
function sessionInboxPath(userId, topicId) {
|
|
15632
16237
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
15633
|
-
return
|
|
16238
|
+
return join29(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${JSONL_SUFFIX}`);
|
|
15634
16239
|
}
|
|
15635
16240
|
function scheduledSessionInboxPath(userId, topicId) {
|
|
15636
16241
|
const key = Buffer.from(topicId, "utf8").toString("base64url");
|
|
15637
|
-
return
|
|
16242
|
+
return join29(SESSION_INBOX_DIR, userId, `${TOPIC_ID_FILE_PREFIX}${key}${SCHEDULE_SUFFIX}`);
|
|
15638
16243
|
}
|
|
15639
16244
|
var TOPIC_ID_FILE_PREFIX = "topic-id-", JSONL_SUFFIX = ".jsonl", SCHEDULE_SUFFIX = ".schedule";
|
|
15640
16245
|
var init_session_inbox_path = __esm(() => {
|
|
@@ -15642,12 +16247,12 @@ var init_session_inbox_path = __esm(() => {
|
|
|
15642
16247
|
});
|
|
15643
16248
|
|
|
15644
16249
|
// ../../packages/core/src/storage/session-inbox-signal.ts
|
|
15645
|
-
import { join as
|
|
16250
|
+
import { join as join30 } from "path";
|
|
15646
16251
|
var SESSION_INBOX_WAKE_FILE, listeners;
|
|
15647
16252
|
var init_session_inbox_signal = __esm(() => {
|
|
15648
16253
|
init_config();
|
|
15649
16254
|
init_logger();
|
|
15650
|
-
SESSION_INBOX_WAKE_FILE =
|
|
16255
|
+
SESSION_INBOX_WAKE_FILE = join30(SESSION_INBOX_DIR, ".wake");
|
|
15651
16256
|
listeners = new Set;
|
|
15652
16257
|
});
|
|
15653
16258
|
|
|
@@ -15685,13 +16290,13 @@ var init_session_inbox = __esm(async () => {
|
|
|
15685
16290
|
|
|
15686
16291
|
// ../../packages/core/src/query/session-inbox-cleanup.ts
|
|
15687
16292
|
import { unlinkSync as unlinkSync16 } from "fs";
|
|
15688
|
-
import { basename as basename6, join as
|
|
16293
|
+
import { basename as basename6, join as join31 } from "path";
|
|
15689
16294
|
function cleanupSessionInboxFiles(userId, topicId, legacyTopicTitle) {
|
|
15690
16295
|
const live = sessionInboxPath(userId, topicId);
|
|
15691
16296
|
const scheduled = scheduledSessionInboxPath(userId, topicId);
|
|
15692
16297
|
const candidates = new Set([live, `${live}.processing`, scheduled, `${scheduled}.processing`]);
|
|
15693
16298
|
if (legacyTopicTitle && legacyTopicTitle !== "." && legacyTopicTitle !== ".." && basename6(legacyTopicTitle) === legacyTopicTitle) {
|
|
15694
|
-
const legacyBase =
|
|
16299
|
+
const legacyBase = join31(SESSION_INBOX_DIR, userId, legacyTopicTitle);
|
|
15695
16300
|
for (const suffix of [".jsonl", ".jsonl.processing", ".schedule", ".schedule.processing"]) {
|
|
15696
16301
|
candidates.add(`${legacyBase}${suffix}`);
|
|
15697
16302
|
}
|
|
@@ -15931,35 +16536,35 @@ import {
|
|
|
15931
16536
|
closeSync as closeSync3,
|
|
15932
16537
|
mkdirSync as mkdirSync18,
|
|
15933
16538
|
openSync as openSync3,
|
|
15934
|
-
readdirSync as
|
|
15935
|
-
readFileSync as
|
|
15936
|
-
statSync as
|
|
16539
|
+
readdirSync as readdirSync7,
|
|
16540
|
+
readFileSync as readFileSync20,
|
|
16541
|
+
statSync as statSync10,
|
|
15937
16542
|
unlinkSync as unlinkSync17,
|
|
15938
16543
|
writeFileSync as writeFileSync16
|
|
15939
16544
|
} from "fs";
|
|
15940
|
-
import { dirname as dirname17, join as
|
|
16545
|
+
import { dirname as dirname17, join as join32 } from "path";
|
|
15941
16546
|
function pendingAskDir(userId) {
|
|
15942
16547
|
const rawUserId = String(userId);
|
|
15943
16548
|
const safeUserId = /^[A-Za-z0-9][A-Za-z0-9_.@-]{0,255}$/.test(rawUserId) && !rawUserId.includes("..") ? rawUserId : `sha256-${createHash9("sha256").update(rawUserId).digest("hex")}`;
|
|
15944
|
-
return
|
|
16549
|
+
return join32(resolveStorageSessionAsksDir(), safeUserId);
|
|
15945
16550
|
}
|
|
15946
16551
|
function encodeAskKey(key) {
|
|
15947
16552
|
return JSON.stringify([key.from, key.to]);
|
|
15948
16553
|
}
|
|
15949
16554
|
function pendingAskPath(key) {
|
|
15950
16555
|
const digest = createHash9("sha256").update(encodeAskKey(key)).digest("hex");
|
|
15951
|
-
return
|
|
16556
|
+
return join32(pendingAskDir(key.userId), `${ASK_FILENAME_PREFIX}${digest}.pending`);
|
|
15952
16557
|
}
|
|
15953
16558
|
function v2PendingAskPath(key) {
|
|
15954
16559
|
const encoded = Buffer.from(encodeAskKey(key), "utf8").toString("base64url");
|
|
15955
|
-
return
|
|
16560
|
+
return join32(pendingAskDir(key.userId), `${V2_ASK_FILENAME_PREFIX}${encoded}.pending`);
|
|
15956
16561
|
}
|
|
15957
16562
|
function legacyPendingAskPath(key) {
|
|
15958
16563
|
if (key.from.includes("/") || key.from.includes("\\") || key.to.includes("/") || key.to.includes("\\") || key.from.includes("\x00") || key.to.includes("\x00")) {
|
|
15959
16564
|
return null;
|
|
15960
16565
|
}
|
|
15961
16566
|
const dir = pendingAskDir(key.userId);
|
|
15962
|
-
const candidate =
|
|
16567
|
+
const candidate = join32(dir, `${key.from}___${key.to}.pending`);
|
|
15963
16568
|
return dirname17(candidate) === dir ? candidate : null;
|
|
15964
16569
|
}
|
|
15965
16570
|
function parsePendingAskFilename(fileName) {
|
|
@@ -15981,11 +16586,11 @@ function parsePendingAskFilename(fileName) {
|
|
|
15981
16586
|
}
|
|
15982
16587
|
function readPendingAskFile(path, fallback) {
|
|
15983
16588
|
try {
|
|
15984
|
-
const raw =
|
|
16589
|
+
const raw = readFileSync20(path, "utf8").trim();
|
|
15985
16590
|
if (!raw)
|
|
15986
16591
|
return null;
|
|
15987
16592
|
if (!raw.startsWith("{")) {
|
|
15988
|
-
const ts = new Date(
|
|
16593
|
+
const ts = new Date(statSync10(path).mtimeMs).toISOString();
|
|
15989
16594
|
return {
|
|
15990
16595
|
userId: fallback.userId,
|
|
15991
16596
|
from: fallback.from,
|
|
@@ -16105,13 +16710,13 @@ function deletePendingAsksForTopic(args) {
|
|
|
16105
16710
|
const dir = pendingAskDir(args.userId);
|
|
16106
16711
|
let files;
|
|
16107
16712
|
try {
|
|
16108
|
-
files =
|
|
16713
|
+
files = readdirSync7(dir);
|
|
16109
16714
|
} catch {
|
|
16110
16715
|
return 0;
|
|
16111
16716
|
}
|
|
16112
16717
|
let deleted = 0;
|
|
16113
16718
|
for (const fileName of files) {
|
|
16114
|
-
const path =
|
|
16719
|
+
const path = join32(dir, fileName);
|
|
16115
16720
|
const parsed = parsePendingAskFilename(fileName);
|
|
16116
16721
|
const record = readPendingAskFile(path, {
|
|
16117
16722
|
userId: args.userId,
|
|
@@ -16827,82 +17432,6 @@ var init_self_schedules = __esm(async () => {
|
|
|
16827
17432
|
});
|
|
16828
17433
|
});
|
|
16829
17434
|
|
|
16830
|
-
// ../../packages/core/src/runtime-gateway.ts
|
|
16831
|
-
function parseHostMcpServers(value) {
|
|
16832
|
-
if (value === undefined)
|
|
16833
|
-
return;
|
|
16834
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
16835
|
-
throw new TypeError("hostMcpServers must be an object");
|
|
16836
|
-
}
|
|
16837
|
-
const parsedEntries = [];
|
|
16838
|
-
for (const [name, raw] of Object.entries(value)) {
|
|
16839
|
-
if (!HOST_MCP_SERVER_NAME.test(name)) {
|
|
16840
|
-
throw new TypeError(`invalid host MCP server name: ${name}`);
|
|
16841
|
-
}
|
|
16842
|
-
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
16843
|
-
throw new TypeError(`hostMcpServers.${name} must be an object`);
|
|
16844
|
-
}
|
|
16845
|
-
const spec = raw;
|
|
16846
|
-
const unsupported = Object.keys(spec).find((key) => !HOST_MCP_SERVER_KEYS.has(key));
|
|
16847
|
-
if (unsupported) {
|
|
16848
|
-
throw new TypeError(`hostMcpServers.${name}.${unsupported} is not allowed`);
|
|
16849
|
-
}
|
|
16850
|
-
if (spec.type !== "sse" && spec.type !== "http") {
|
|
16851
|
-
throw new TypeError(`hostMcpServers.${name}.type must be sse or http`);
|
|
16852
|
-
}
|
|
16853
|
-
if (typeof spec.url !== "string") {
|
|
16854
|
-
throw new TypeError(`hostMcpServers.${name}.url must be a string`);
|
|
16855
|
-
}
|
|
16856
|
-
let url;
|
|
16857
|
-
try {
|
|
16858
|
-
url = new URL(spec.url);
|
|
16859
|
-
} catch {
|
|
16860
|
-
throw new TypeError(`hostMcpServers.${name}.url must be a valid URL`);
|
|
16861
|
-
}
|
|
16862
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
16863
|
-
throw new TypeError(`hostMcpServers.${name}.url must use http or https`);
|
|
16864
|
-
}
|
|
16865
|
-
let headers;
|
|
16866
|
-
if (spec.headers !== undefined) {
|
|
16867
|
-
if (!spec.headers || typeof spec.headers !== "object" || Array.isArray(spec.headers)) {
|
|
16868
|
-
throw new TypeError(`hostMcpServers.${name}.headers must be an object`);
|
|
16869
|
-
}
|
|
16870
|
-
const headerEntries = [];
|
|
16871
|
-
for (const [key, headerValue] of Object.entries(spec.headers)) {
|
|
16872
|
-
if (!HTTP_HEADER_NAME.test(key) || typeof headerValue !== "string") {
|
|
16873
|
-
throw new TypeError(`hostMcpServers.${name}.headers must contain string values`);
|
|
16874
|
-
}
|
|
16875
|
-
try {
|
|
16876
|
-
new Headers([[key, headerValue]]);
|
|
16877
|
-
} catch {
|
|
16878
|
-
throw new TypeError(`hostMcpServers.${name}.headers contains an invalid header`);
|
|
16879
|
-
}
|
|
16880
|
-
headerEntries.push([key, headerValue]);
|
|
16881
|
-
}
|
|
16882
|
-
headers = Object.fromEntries(headerEntries);
|
|
16883
|
-
}
|
|
16884
|
-
if (spec.timeout !== undefined && (typeof spec.timeout !== "number" || !Number.isFinite(spec.timeout) || spec.timeout <= 0)) {
|
|
16885
|
-
throw new TypeError(`hostMcpServers.${name}.timeout must be a positive number`);
|
|
16886
|
-
}
|
|
16887
|
-
parsedEntries.push([
|
|
16888
|
-
name,
|
|
16889
|
-
{
|
|
16890
|
-
type: spec.type,
|
|
16891
|
-
url: url.toString(),
|
|
16892
|
-
...headers ? { headers } : {},
|
|
16893
|
-
...spec.timeout !== undefined ? { timeout: spec.timeout } : {}
|
|
16894
|
-
}
|
|
16895
|
-
]);
|
|
16896
|
-
}
|
|
16897
|
-
return Object.fromEntries(parsedEntries);
|
|
16898
|
-
}
|
|
16899
|
-
var HOST_MCP_SERVER_NAME, HOST_MCP_SERVER_KEYS, HTTP_HEADER_NAME;
|
|
16900
|
-
var init_runtime_gateway = __esm(() => {
|
|
16901
|
-
HOST_MCP_SERVER_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
16902
|
-
HOST_MCP_SERVER_KEYS = new Set(["type", "url", "headers", "timeout"]);
|
|
16903
|
-
HTTP_HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
16904
|
-
});
|
|
16905
|
-
|
|
16906
17435
|
// ../../packages/core/src/storage/topic-host-mcp-grants.ts
|
|
16907
17436
|
function getTopicHostMcpGrant(topicId) {
|
|
16908
17437
|
const row = db.query("SELECT servers_json FROM api_topic_host_mcp_grants WHERE topic_id = ?").get(topicId);
|
|
@@ -17211,7 +17740,7 @@ var init_lifecycle = __esm(async () => {
|
|
|
17211
17740
|
|
|
17212
17741
|
// ../../packages/core/src/runtime/attachments.ts
|
|
17213
17742
|
import { copyFileSync as copyFileSync2, mkdirSync as mkdirSync19, writeFileSync as writeFileSync17 } from "fs";
|
|
17214
|
-
import { basename as basename7, join as
|
|
17743
|
+
import { basename as basename7, join as join33 } from "path";
|
|
17215
17744
|
function workspaceCwdFor(topicId) {
|
|
17216
17745
|
return resolveTopicWorkspaceDir(topicId);
|
|
17217
17746
|
}
|
|
@@ -17224,7 +17753,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
17224
17753
|
if (!attachmentIds?.length)
|
|
17225
17754
|
return [];
|
|
17226
17755
|
const out = [];
|
|
17227
|
-
const destDir =
|
|
17756
|
+
const destDir = join33(workspaceCwdFor(topicId), "attachments", queryId);
|
|
17228
17757
|
for (const rawId of attachmentIds) {
|
|
17229
17758
|
if (typeof rawId !== "string")
|
|
17230
17759
|
continue;
|
|
@@ -17241,7 +17770,7 @@ function materializePromptAttachments(topicId, queryId, attachmentIds) {
|
|
|
17241
17770
|
mkdirSync19(destDir, { recursive: true });
|
|
17242
17771
|
const index = String(out.length + 1).padStart(2, "0");
|
|
17243
17772
|
const safeName = safeAttachmentFilename(attachment.filename, fileId);
|
|
17244
|
-
const destPath =
|
|
17773
|
+
const destPath = join33(destDir, `${index}-${fileId.slice(0, 8)}-${safeName}`);
|
|
17245
17774
|
copyFileSync2(sourcePath, destPath);
|
|
17246
17775
|
out.push({
|
|
17247
17776
|
id: attachment.id,
|
|
@@ -17725,7 +18254,7 @@ var init_ask_user_gates = __esm(async () => {
|
|
|
17725
18254
|
|
|
17726
18255
|
// ../../packages/core/src/agents/mcp-tools/ask-user.ts
|
|
17727
18256
|
import { createHash as createHash11, randomUUID as randomUUID16 } from "crypto";
|
|
17728
|
-
import { z as
|
|
18257
|
+
import { z as z6 } from "zod";
|
|
17729
18258
|
function normalizeAskText(value, maxChars) {
|
|
17730
18259
|
if (typeof value !== "string")
|
|
17731
18260
|
return;
|
|
@@ -18018,12 +18547,12 @@ function createAskUserRuntime(host) {
|
|
|
18018
18547
|
name: "ask_user_question",
|
|
18019
18548
|
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.",
|
|
18020
18549
|
schema: {
|
|
18021
|
-
question:
|
|
18022
|
-
choices:
|
|
18023
|
-
label:
|
|
18024
|
-
description:
|
|
18550
|
+
question: z6.string().describe("The concise question to show to the user."),
|
|
18551
|
+
choices: z6.array(z6.object({
|
|
18552
|
+
label: z6.string().describe("Choice label shown on the button."),
|
|
18553
|
+
description: z6.string().optional().describe("Optional one-sentence consequence.")
|
|
18025
18554
|
})).min(1).max(MAX_CHOICES).describe("Choices the user can select."),
|
|
18026
|
-
idempotency_key:
|
|
18555
|
+
idempotency_key: z6.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.")
|
|
18027
18556
|
},
|
|
18028
18557
|
async handler(input) {
|
|
18029
18558
|
return askUserQuestion(ctx, input);
|
|
@@ -18295,7 +18824,7 @@ var init_vault_request_gates = __esm(async () => {
|
|
|
18295
18824
|
|
|
18296
18825
|
// ../../packages/core/src/agents/mcp-tools/request-vault.ts
|
|
18297
18826
|
import { createHash as createHash12, randomUUID as randomUUID17 } from "crypto";
|
|
18298
|
-
import { z as
|
|
18827
|
+
import { z as z7 } from "zod";
|
|
18299
18828
|
function requestBodyHash(key, description) {
|
|
18300
18829
|
return createHash12("sha256").update(JSON.stringify({ key, description })).digest("hex");
|
|
18301
18830
|
}
|
|
@@ -18562,10 +19091,10 @@ function createRequestVaultRuntime(host) {
|
|
|
18562
19091
|
name: "request_vault_secret",
|
|
18563
19092
|
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.",
|
|
18564
19093
|
schema: {
|
|
18565
|
-
key:
|
|
18566
|
-
description:
|
|
18567
|
-
overwrite:
|
|
18568
|
-
idempotency_key:
|
|
19094
|
+
key: z7.string().describe("Vault key name, e.g. STRIPE_API_KEY. Letters/digits/underscores, must start with a letter."),
|
|
19095
|
+
description: z7.string().max(MAX_DESCRIPTION_CHARS).describe("One sentence telling the user what value to paste and where it's from."),
|
|
19096
|
+
overwrite: z7.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."),
|
|
19097
|
+
idempotency_key: z7.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.")
|
|
18569
19098
|
},
|
|
18570
19099
|
async handler(input) {
|
|
18571
19100
|
return requestVaultSecret(ctx, input);
|
|
@@ -18602,7 +19131,7 @@ function createRequestVaultRuntime(host) {
|
|
|
18602
19131
|
name: "delete_vault_secret",
|
|
18603
19132
|
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.",
|
|
18604
19133
|
schema: {
|
|
18605
|
-
key:
|
|
19134
|
+
key: z7.string().describe("Vault key name to delete, e.g. STRIPE_API_KEY.")
|
|
18606
19135
|
},
|
|
18607
19136
|
async handler(input) {
|
|
18608
19137
|
return deleteVaultSecret(ctx, input);
|
|
@@ -18908,8 +19437,8 @@ var init_visual_html = __esm(() => {
|
|
|
18908
19437
|
});
|
|
18909
19438
|
|
|
18910
19439
|
// ../../packages/core/src/runtime/visuals.ts
|
|
18911
|
-
import { realpathSync as
|
|
18912
|
-
import { isAbsolute as
|
|
19440
|
+
import { realpathSync as realpathSync7 } from "fs";
|
|
19441
|
+
import { isAbsolute as isAbsolute7, resolve as resolve17 } from "path";
|
|
18913
19442
|
function activeVisualHtmlForPrompt(html) {
|
|
18914
19443
|
if (html.length <= ACTIVE_VISUAL_PROMPT_MAX_CHARS) {
|
|
18915
19444
|
return { html, omittedChars: 0 };
|
|
@@ -18958,8 +19487,8 @@ function topicAllowsVisualFileId(topicId, fileId) {
|
|
|
18958
19487
|
}
|
|
18959
19488
|
function isPathInside(baseDir, filePath) {
|
|
18960
19489
|
try {
|
|
18961
|
-
const realBase =
|
|
18962
|
-
const real =
|
|
19490
|
+
const realBase = realpathSync7(resolve17(baseDir));
|
|
19491
|
+
const real = realpathSync7(resolve17(filePath));
|
|
18963
19492
|
return isInsideDir(real, realBase);
|
|
18964
19493
|
} catch {
|
|
18965
19494
|
return false;
|
|
@@ -19014,10 +19543,10 @@ function locateVisualMediaInput(topicId, input) {
|
|
|
19014
19543
|
}
|
|
19015
19544
|
const rawPath = input.file_path.trim();
|
|
19016
19545
|
const cwd = workspaceCwdFor(topicId);
|
|
19017
|
-
const candidate =
|
|
19546
|
+
const candidate = isAbsolute7(rawPath) ? rawPath : resolve17(cwd, rawPath);
|
|
19018
19547
|
let realCandidate;
|
|
19019
19548
|
try {
|
|
19020
|
-
realCandidate =
|
|
19549
|
+
realCandidate = realpathSync7(candidate);
|
|
19021
19550
|
} catch {
|
|
19022
19551
|
return { error: `file not found: ${rawPath}` };
|
|
19023
19552
|
}
|
|
@@ -19070,8 +19599,8 @@ var init_visuals = __esm(async () => {
|
|
|
19070
19599
|
|
|
19071
19600
|
// ../../packages/core/src/runtime/turn-event-stream.ts
|
|
19072
19601
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
19073
|
-
import { realpathSync as
|
|
19074
|
-
import { isAbsolute as
|
|
19602
|
+
import { realpathSync as realpathSync8, statSync as statSync11 } from "fs";
|
|
19603
|
+
import { isAbsolute as isAbsolute8, resolve as resolve18 } from "path";
|
|
19075
19604
|
function sessionEventMatchesCurrentExecution(topicId, queryId, agent, model) {
|
|
19076
19605
|
if (getRoomQuery(topicId)?.queryId !== queryId)
|
|
19077
19606
|
return false;
|
|
@@ -19496,15 +20025,15 @@ ${JSON.stringify(event.input ?? {})}`);
|
|
|
19496
20025
|
case "file":
|
|
19497
20026
|
if (!silent && peerBridge) {
|
|
19498
20027
|
const cwd = workspaceCwdFor(topicId);
|
|
19499
|
-
const path =
|
|
20028
|
+
const path = isAbsolute8(event.path) ? event.path : resolve18(cwd, event.path);
|
|
19500
20029
|
if (!isPathInside(cwd, path)) {
|
|
19501
20030
|
logger.warn({ topicId, path }, "peer output file is outside the topic workspace");
|
|
19502
20031
|
break;
|
|
19503
20032
|
}
|
|
19504
20033
|
let safePath;
|
|
19505
20034
|
try {
|
|
19506
|
-
safePath =
|
|
19507
|
-
if (!
|
|
20035
|
+
safePath = realpathSync8(path);
|
|
20036
|
+
if (!statSync11(safePath).isFile()) {
|
|
19508
20037
|
logger.warn({ topicId, path }, "peer output path is not a regular file");
|
|
19509
20038
|
break;
|
|
19510
20039
|
}
|
|
@@ -19833,16 +20362,16 @@ var init_turn_session = __esm(async () => {
|
|
|
19833
20362
|
});
|
|
19834
20363
|
|
|
19835
20364
|
// ../../packages/core/src/storage/app-settings.ts
|
|
19836
|
-
import { existsSync as
|
|
19837
|
-
import { dirname as dirname18, join as
|
|
20365
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync20, readFileSync as readFileSync21, writeFileSync as writeFileSync18 } from "fs";
|
|
20366
|
+
import { dirname as dirname18, join as join34 } from "path";
|
|
19838
20367
|
function settingsFile() {
|
|
19839
|
-
return
|
|
20368
|
+
return join34(resolveStorageDataDir(), "otium-settings.json");
|
|
19840
20369
|
}
|
|
19841
20370
|
function getGlobalAiName() {
|
|
19842
20371
|
const path = settingsFile();
|
|
19843
20372
|
try {
|
|
19844
|
-
if (
|
|
19845
|
-
const data = JSON.parse(
|
|
20373
|
+
if (existsSync24(path)) {
|
|
20374
|
+
const data = JSON.parse(readFileSync21(path, "utf8"));
|
|
19846
20375
|
if (typeof data.aiName === "string" && data.aiName.trim()) {
|
|
19847
20376
|
return data.aiName.trim();
|
|
19848
20377
|
}
|
|
@@ -19855,10 +20384,154 @@ var init_app_settings = __esm(async () => {
|
|
|
19855
20384
|
await init_storage_host();
|
|
19856
20385
|
});
|
|
19857
20386
|
|
|
20387
|
+
// ../../packages/core/src/topics/plugin-server-instructions.ts
|
|
20388
|
+
import { Client as Client2 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
20389
|
+
import { SSEClientTransport as SSEClientTransport2 } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
20390
|
+
import { StreamableHTTPClientTransport as StreamableHTTPClientTransport2 } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
20391
|
+
function cacheKey(server, spec) {
|
|
20392
|
+
const headers = Object.entries(spec.headers ?? {}).map(([name, value]) => [name.toLowerCase(), value]).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
20393
|
+
return JSON.stringify([server, spec.type, spec.url, headers]);
|
|
20394
|
+
}
|
|
20395
|
+
function transportFor(spec, signal) {
|
|
20396
|
+
const url = new URL(spec.url);
|
|
20397
|
+
const requestInit = spec.headers ? { headers: spec.headers } : undefined;
|
|
20398
|
+
const noRedirect = (input, init) => fetch(input, {
|
|
20399
|
+
...init,
|
|
20400
|
+
redirect: "error",
|
|
20401
|
+
signal: init?.signal ? AbortSignal.any([init.signal, signal]) : signal
|
|
20402
|
+
});
|
|
20403
|
+
return spec.type === "sse" ? new SSEClientTransport2(url, { requestInit, fetch: noRedirect }) : new StreamableHTTPClientTransport2(url, { requestInit, fetch: noRedirect });
|
|
20404
|
+
}
|
|
20405
|
+
async function readInstructions(spec, timeoutMs, stop) {
|
|
20406
|
+
const ended = new AbortController;
|
|
20407
|
+
const timer = setTimeout(() => ended.abort(new Error(`no answer in ${timeoutMs} ms`)), timeoutMs);
|
|
20408
|
+
timer.unref?.();
|
|
20409
|
+
const onStop = () => ended.abort(new Error("the turn was stopped"));
|
|
20410
|
+
if (stop?.aborted)
|
|
20411
|
+
onStop();
|
|
20412
|
+
else
|
|
20413
|
+
stop?.addEventListener("abort", onStop, { once: true });
|
|
20414
|
+
const client = new Client2({ name: "negotium-plugin-instructions", version: "1.0.0" });
|
|
20415
|
+
const transport = transportFor(spec, ended.signal);
|
|
20416
|
+
try {
|
|
20417
|
+
return await Promise.race([
|
|
20418
|
+
client.connect(transport).then(() => client.getInstructions() ?? ""),
|
|
20419
|
+
new Promise((_, reject) => {
|
|
20420
|
+
if (ended.signal.aborted)
|
|
20421
|
+
reject(ended.signal.reason);
|
|
20422
|
+
ended.signal.addEventListener("abort", () => reject(ended.signal.reason), { once: true });
|
|
20423
|
+
})
|
|
20424
|
+
]);
|
|
20425
|
+
} finally {
|
|
20426
|
+
clearTimeout(timer);
|
|
20427
|
+
stop?.removeEventListener("abort", onStop);
|
|
20428
|
+
const ending = !ended.signal.aborted && transport instanceof StreamableHTTPClientTransport2 ? transport.terminateSession() : Promise.resolve();
|
|
20429
|
+
ending.catch(() => {}).finally(() => client.close().catch(() => {}));
|
|
20430
|
+
}
|
|
20431
|
+
}
|
|
20432
|
+
async function fetchMcpServerInstructions(servers, options = {}) {
|
|
20433
|
+
const timeoutMs = options.timeoutMs ?? SERVER_INSTRUCTIONS_TIMEOUT_MS;
|
|
20434
|
+
const entries = Object.entries(servers);
|
|
20435
|
+
const results = await Promise.allSettled(entries.map(async ([server, spec]) => {
|
|
20436
|
+
const key = cacheKey(server, spec);
|
|
20437
|
+
const hit = cache.get(key);
|
|
20438
|
+
if (hit && hit.expires > Date.now())
|
|
20439
|
+
return hit.text;
|
|
20440
|
+
const text = await readInstructions(spec, timeoutMs, options.signal);
|
|
20441
|
+
cache.set(key, { text, expires: Date.now() + SERVER_INSTRUCTIONS_TTL_MS });
|
|
20442
|
+
return text;
|
|
20443
|
+
}));
|
|
20444
|
+
const fetched = { instructions: [], problems: [] };
|
|
20445
|
+
results.forEach((result, index) => {
|
|
20446
|
+
const server = entries[index][0];
|
|
20447
|
+
if (result.status === "rejected") {
|
|
20448
|
+
const reason = result.reason instanceof Error ? result.reason.message : String(result.reason);
|
|
20449
|
+
fetched.problems.push(`plugin server "${server}": instructions not read (${reason})`);
|
|
20450
|
+
} else if (result.value.trim()) {
|
|
20451
|
+
fetched.instructions.push({ server, text: result.value });
|
|
20452
|
+
}
|
|
20453
|
+
});
|
|
20454
|
+
return fetched;
|
|
20455
|
+
}
|
|
20456
|
+
function cutToBytes(text, maxBytes) {
|
|
20457
|
+
const encoded = encoder.encode(text);
|
|
20458
|
+
let end = Math.max(0, maxBytes);
|
|
20459
|
+
while (end > 0 && (encoded[end] & 192) === 128)
|
|
20460
|
+
end--;
|
|
20461
|
+
return new TextDecoder().decode(encoded.subarray(0, end));
|
|
20462
|
+
}
|
|
20463
|
+
function renderMcpServerInstructions(instructions) {
|
|
20464
|
+
const head = [
|
|
20465
|
+
"## MCP Server Instructions",
|
|
20466
|
+
"",
|
|
20467
|
+
"The following MCP servers have provided instructions for how to use their tools and resources:"
|
|
20468
|
+
].join(`
|
|
20469
|
+
`);
|
|
20470
|
+
const blocks = [];
|
|
20471
|
+
const problems = [];
|
|
20472
|
+
let left = INSTRUCTIONS_SECTION_MAX_BYTES - byteLength(head);
|
|
20473
|
+
for (const { server, text: sent } of instructions) {
|
|
20474
|
+
const heading = `
|
|
20475
|
+
|
|
20476
|
+
### ${server}
|
|
20477
|
+
|
|
20478
|
+
`;
|
|
20479
|
+
const text = sent.trim();
|
|
20480
|
+
const size = byteLength(text);
|
|
20481
|
+
const room = Math.min(SERVER_INSTRUCTIONS_MAX_BYTES, left - byteLength(heading));
|
|
20482
|
+
if (size <= room) {
|
|
20483
|
+
blocks.push(`${heading}${text}`);
|
|
20484
|
+
left -= byteLength(heading) + size;
|
|
20485
|
+
continue;
|
|
20486
|
+
}
|
|
20487
|
+
const marker = cutMarker(server, size);
|
|
20488
|
+
if (room <= byteLength(marker)) {
|
|
20489
|
+
problems.push(`plugin server "${server}": instructions left out (the section is full)`);
|
|
20490
|
+
continue;
|
|
20491
|
+
}
|
|
20492
|
+
const shown = `${cutToBytes(text, room - byteLength(marker))}${marker}`;
|
|
20493
|
+
blocks.push(`${heading}${shown}`);
|
|
20494
|
+
left -= byteLength(heading) + byteLength(shown);
|
|
20495
|
+
problems.push(`plugin server "${server}": instructions cut from ${size} bytes`);
|
|
20496
|
+
}
|
|
20497
|
+
return { section: blocks.length > 0 ? `${head}${blocks.join("")}` : "", problems };
|
|
20498
|
+
}
|
|
20499
|
+
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) => `
|
|
20500
|
+
|
|
20501
|
+
[negotium cut the instructions of "${server}" here; the server sent ${sent} bytes]`;
|
|
20502
|
+
var init_plugin_server_instructions = __esm(() => {
|
|
20503
|
+
SERVER_INSTRUCTIONS_TTL_MS = 5 * 60 * 1000;
|
|
20504
|
+
SERVER_INSTRUCTIONS_MAX_BYTES = 8 * 1024;
|
|
20505
|
+
INSTRUCTIONS_SECTION_MAX_BYTES = 32 * 1024;
|
|
20506
|
+
cache = new Map;
|
|
20507
|
+
encoder = new TextEncoder;
|
|
20508
|
+
});
|
|
20509
|
+
|
|
20510
|
+
// ../../packages/core/src/topics/plugin-turn.ts
|
|
20511
|
+
function resolveTopicPluginTurn(topic, hostServerNames) {
|
|
20512
|
+
if (!topic.plugins?.length)
|
|
20513
|
+
return NONE;
|
|
20514
|
+
const { plugins, problems: loadProblems } = loadTopicPlugins(topic.plugins);
|
|
20515
|
+
const servers = Object.assign({}, ...plugins.map((plugin) => plugin.mcpServers));
|
|
20516
|
+
const refusal = pluginMcpRefusal(topic, Object.keys(servers), hostServerNames);
|
|
20517
|
+
return {
|
|
20518
|
+
plugins,
|
|
20519
|
+
mcpServers: refusal ? {} : servers,
|
|
20520
|
+
loadProblems,
|
|
20521
|
+
serverProblems: refusal ? [refusal] : []
|
|
20522
|
+
};
|
|
20523
|
+
}
|
|
20524
|
+
var NONE;
|
|
20525
|
+
var init_plugin_turn = __esm(async () => {
|
|
20526
|
+
init_plugins();
|
|
20527
|
+
await init_mcp_config();
|
|
20528
|
+
NONE = { plugins: [], mcpServers: {}, loadProblems: [], serverProblems: [] };
|
|
20529
|
+
});
|
|
20530
|
+
|
|
19858
20531
|
// ../../packages/core/src/runtime/turn-runner.ts
|
|
19859
20532
|
import { randomUUID as randomUUID19 } from "crypto";
|
|
19860
|
-
import { existsSync as
|
|
19861
|
-
import { join as
|
|
20533
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync21, readdirSync as readdirSync8, statSync as statSync12 } from "fs";
|
|
20534
|
+
import { join as join35 } from "path";
|
|
19862
20535
|
function withDefaultPlaywright(configuredMcp, isManager) {
|
|
19863
20536
|
if (isManager)
|
|
19864
20537
|
return configuredMcp;
|
|
@@ -19922,19 +20595,19 @@ function appendAskReplyMessage(topicId, text, sourceLabel, body, kind, agentType
|
|
|
19922
20595
|
return message;
|
|
19923
20596
|
}
|
|
19924
20597
|
function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, matchesTitle, preferExact = true) {
|
|
19925
|
-
const preferred =
|
|
19926
|
-
if (preferExact &&
|
|
20598
|
+
const preferred = join35(directory, preferredFilename);
|
|
20599
|
+
if (preferExact && existsSync25(preferred))
|
|
19927
20600
|
return preferred;
|
|
19928
20601
|
let newestLegacyId = null;
|
|
19929
20602
|
let newestTitle = null;
|
|
19930
20603
|
try {
|
|
19931
|
-
for (const filename of
|
|
20604
|
+
for (const filename of readdirSync8(directory)) {
|
|
19932
20605
|
const titleMatch = matchesTitle(filename);
|
|
19933
20606
|
const legacyIdMatch = !titleMatch && matchesLegacyId(filename);
|
|
19934
20607
|
if (!titleMatch && !legacyIdMatch)
|
|
19935
20608
|
continue;
|
|
19936
|
-
const path =
|
|
19937
|
-
const mtimeMs =
|
|
20609
|
+
const path = join35(directory, filename);
|
|
20610
|
+
const mtimeMs = statSync12(path).mtimeMs;
|
|
19938
20611
|
if (titleMatch) {
|
|
19939
20612
|
if (!newestTitle || mtimeMs > newestTitle.mtimeMs) {
|
|
19940
20613
|
newestTitle = { path, mtimeMs };
|
|
@@ -19947,10 +20620,10 @@ function resolveWikiMirrorPath(directory, preferredFilename, matchesLegacyId, ma
|
|
|
19947
20620
|
return newestTitle?.path ?? newestLegacyId?.path ?? preferred;
|
|
19948
20621
|
}
|
|
19949
20622
|
function resolveWikiMemoryMirror(wikiDir, topicId, topicTitle) {
|
|
19950
|
-
const briefFile = resolveWikiMirrorPath(
|
|
19951
|
-
const hasBriefFile =
|
|
19952
|
-
const latestSummaryCandidate = resolveWikiMirrorPath(
|
|
19953
|
-
const latestSummaryFile =
|
|
20623
|
+
const briefFile = resolveWikiMirrorPath(join35(wikiDir, "topic"), `${wikiBriefStorageKey(topicTitle, topicId)}.md`, (filename) => isTopicBriefFile(filename, topicId), (filename) => isTopicBriefFile(filename, topicId, topicTitle));
|
|
20624
|
+
const hasBriefFile = existsSync25(briefFile) && statSync12(briefFile).isFile();
|
|
20625
|
+
const latestSummaryCandidate = resolveWikiMirrorPath(join35(wikiDir, "summaries"), `__missing__-${wikiSummaryFilename("0000-00-00", topicTitle, topicId)}`, (filename) => isTopicSummaryFile(filename, topicId), (filename) => isTopicSummaryFile(filename, topicId, topicTitle), false);
|
|
20626
|
+
const latestSummaryFile = existsSync25(latestSummaryCandidate) && statSync12(latestSummaryCandidate).isFile() ? latestSummaryCandidate : null;
|
|
19954
20627
|
return { briefFile, hasBriefFile, latestSummaryFile };
|
|
19955
20628
|
}
|
|
19956
20629
|
async function streamAgentEvents(topicId, topicTitle, queryId, events, control, agentType, model, effort, userId, retryableSessionExpired = true, onSessionId, execution) {
|
|
@@ -20185,6 +20858,23 @@ function resolveTurnHostMcpServers(topic, sessionType) {
|
|
|
20185
20858
|
return;
|
|
20186
20859
|
return getTopicHostMcpGrant(topic.id) ?? undefined;
|
|
20187
20860
|
}
|
|
20861
|
+
function resolveTurnPlugins(topic, sessionType, hostMcpServers) {
|
|
20862
|
+
const ownScope = topic.kind === "manager" ? "manager" : "forum";
|
|
20863
|
+
const stored = getTopic(topic.id);
|
|
20864
|
+
if (!stored?.plugins?.length || (sessionType ?? ownScope) !== ownScope) {
|
|
20865
|
+
return { plugins: [], pluginMcpServers: {}, hostMcpServers };
|
|
20866
|
+
}
|
|
20867
|
+
const turn = resolveTopicPluginTurn(stored, Object.keys(hostMcpServers ?? {}));
|
|
20868
|
+
const problems = [...turn.loadProblems, ...turn.serverProblems];
|
|
20869
|
+
if (problems.length > 0) {
|
|
20870
|
+
logger.warn({ topicId: topic.id, problems }, "ai: topic plugins partly or wholly left out of the turn");
|
|
20871
|
+
}
|
|
20872
|
+
return {
|
|
20873
|
+
plugins: turn.plugins,
|
|
20874
|
+
pluginMcpServers: turn.mcpServers,
|
|
20875
|
+
hostMcpServers: Object.keys(turn.mcpServers).length > 0 ? { ...hostMcpServers, ...turn.mcpServers } : hostMcpServers
|
|
20876
|
+
};
|
|
20877
|
+
}
|
|
20188
20878
|
function sameTurnActor(runningActorUserId, incomingActorUserId) {
|
|
20189
20879
|
return (runningActorUserId ?? null) === (incomingActorUserId ?? null);
|
|
20190
20880
|
}
|
|
@@ -20342,7 +21032,7 @@ function startAiTurn(params) {
|
|
|
20342
21032
|
const sessionName = params.sessionName ?? topic.title;
|
|
20343
21033
|
const sessionType = params.sessionType;
|
|
20344
21034
|
const { visualTools, fileDeliveryTools } = resolveTurnToolCapabilities(topicId, params);
|
|
20345
|
-
const hostMcpServers = resolveTurnHostMcpServers(topic, sessionType);
|
|
21035
|
+
const { plugins, pluginMcpServers, hostMcpServers } = resolveTurnPlugins(topic, sessionType, resolveTurnHostMcpServers(topic, sessionType));
|
|
20346
21036
|
const onSessionId = params.onSessionId;
|
|
20347
21037
|
const onSessionReset = params.onSessionReset;
|
|
20348
21038
|
const bridgeSessionFromHistory = params.bridgeSessionFromHistory === true;
|
|
@@ -20461,6 +21151,11 @@ function startAiTurn(params) {
|
|
|
20461
21151
|
}
|
|
20462
21152
|
if (decision.action === "abort-replace") {
|
|
20463
21153
|
const running = decision.running;
|
|
21154
|
+
const runningRequestIds = new Set(running.durableRequestIds ?? []);
|
|
21155
|
+
if (durableRequestIds.length > 0 && durableRequestIds.every((requestId) => runningRequestIds.has(requestId))) {
|
|
21156
|
+
logger.warn({ topicId, queryId: running.queryId, durableRequestIds }, "ai: ignored a replay of the durable request this room is already running");
|
|
21157
|
+
return running.queryId;
|
|
21158
|
+
}
|
|
20464
21159
|
if (isUserOrigin(running.origin) && !sameTurnActor(running.actorUserId, params.actorUserId)) {
|
|
20465
21160
|
const queuedQueryId = waitToStartRemoteUserTurn({
|
|
20466
21161
|
...params,
|
|
@@ -20718,7 +21413,8 @@ function startAiTurn(params) {
|
|
|
20718
21413
|
subagentParentTitle: topicRecord?.isSubagent && topicRecord.parentTopicId ? getTopic(topicRecord.parentTopicId)?.title : undefined,
|
|
20719
21414
|
subagentReportMode: topicRecord?.isSubagent ? subagentReportMode(topicId) : undefined,
|
|
20720
21415
|
visualTools,
|
|
20721
|
-
fileDeliveryTools
|
|
21416
|
+
fileDeliveryTools,
|
|
21417
|
+
plugins
|
|
20722
21418
|
};
|
|
20723
21419
|
const isManager = topicRecord?.kind === "manager";
|
|
20724
21420
|
const isMentionOnlyChannel = topic.aiMode === "mention" && !isManager;
|
|
@@ -20864,6 +21560,21 @@ function startAiTurn(params) {
|
|
|
20864
21560
|
if (consumePlaywrightUnavailable(userId, topic.title)) {
|
|
20865
21561
|
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>");
|
|
20866
21562
|
}
|
|
21563
|
+
if (Object.keys(pluginMcpServers).length > 0) {
|
|
21564
|
+
const fetched = await fetchMcpServerInstructions(pluginMcpServers, {
|
|
21565
|
+
signal: abortController.signal
|
|
21566
|
+
});
|
|
21567
|
+
if (abortController.signal.aborted)
|
|
21568
|
+
return;
|
|
21569
|
+
const { section, problems } = renderMcpServerInstructions(fetched.instructions);
|
|
21570
|
+
if (fetched.problems.length + problems.length > 0) {
|
|
21571
|
+
logger.warn({ topicId, problems: [...fetched.problems, ...problems] }, "ai: plugin server instructions cut or left out of the turn");
|
|
21572
|
+
}
|
|
21573
|
+
if (section)
|
|
21574
|
+
systemPrompt += `
|
|
21575
|
+
|
|
21576
|
+
${section}`;
|
|
21577
|
+
}
|
|
20867
21578
|
const reminderQuery = buildTurnReminderQuery(agentKind, agentPrompt, turnReminders);
|
|
20868
21579
|
try {
|
|
20869
21580
|
yield* runAgent({
|
|
@@ -21226,6 +21937,7 @@ var init_turn_runner = __esm(async () => {
|
|
|
21226
21937
|
init_remote_session_grant();
|
|
21227
21938
|
init_user_turn_envelope();
|
|
21228
21939
|
init_wiki_summary_names();
|
|
21940
|
+
init_plugin_server_instructions();
|
|
21229
21941
|
init_user_turn_envelope();
|
|
21230
21942
|
await __promiseAll([
|
|
21231
21943
|
init_fork(),
|
|
@@ -21256,7 +21968,8 @@ var init_turn_runner = __esm(async () => {
|
|
|
21256
21968
|
init_topic_host_mcp_grants(),
|
|
21257
21969
|
init_topic_tool_capabilities(),
|
|
21258
21970
|
init_wiki(),
|
|
21259
|
-
init_derive()
|
|
21971
|
+
init_derive(),
|
|
21972
|
+
init_plugin_turn()
|
|
21260
21973
|
]);
|
|
21261
21974
|
init_model_catalog();
|
|
21262
21975
|
init_attachments();
|
|
@@ -21278,9 +21991,9 @@ var init_turn_runner = __esm(async () => {
|
|
|
21278
21991
|
|
|
21279
21992
|
// ../../packages/core/src/agents/auth-check.ts
|
|
21280
21993
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
21281
|
-
import { existsSync as
|
|
21994
|
+
import { existsSync as existsSync26 } from "fs";
|
|
21282
21995
|
import { homedir as homedir9, platform } from "os";
|
|
21283
|
-
import { join as
|
|
21996
|
+
import { join as join36 } from "path";
|
|
21284
21997
|
function hasMaestroCredential(host, key, userId) {
|
|
21285
21998
|
if (userId && host.getVaultValue(userId, key)?.trim())
|
|
21286
21999
|
return true;
|
|
@@ -21300,7 +22013,7 @@ function checkAgentAuth(agent, host = defaultAgentAuthHost, userId) {
|
|
|
21300
22013
|
case "claude": {
|
|
21301
22014
|
if (host.environment.ANTHROPIC_API_KEY)
|
|
21302
22015
|
return { ok: true };
|
|
21303
|
-
const path =
|
|
22016
|
+
const path = join36(host.homeDirectory(), ".claude", ".credentials.json");
|
|
21304
22017
|
if (host.operatingSystem() === "darwin") {
|
|
21305
22018
|
if (host.hasMacOsCredential("Claude Code-credentials") || host.exists(path)) {
|
|
21306
22019
|
return { ok: true };
|
|
@@ -21357,7 +22070,7 @@ var init_auth_check = __esm(async () => {
|
|
|
21357
22070
|
await init_vault();
|
|
21358
22071
|
defaultAgentAuthHost = {
|
|
21359
22072
|
codexAuthFilePath,
|
|
21360
|
-
exists:
|
|
22073
|
+
exists: existsSync26,
|
|
21361
22074
|
environment: process.env,
|
|
21362
22075
|
homeDirectory: homedir9,
|
|
21363
22076
|
operatingSystem: platform,
|
|
@@ -21374,7 +22087,7 @@ var init_auth_check = __esm(async () => {
|
|
|
21374
22087
|
});
|
|
21375
22088
|
|
|
21376
22089
|
// ../../packages/core/src/agents/mcp-tools/spawn-subagent.ts
|
|
21377
|
-
import { z as
|
|
22090
|
+
import { z as z8 } from "zod";
|
|
21378
22091
|
function activeQueryUserId(topic) {
|
|
21379
22092
|
return topic?.participants.find((participant) => hasActiveQuery(participant.userId, topic.id))?.userId;
|
|
21380
22093
|
}
|
|
@@ -21941,7 +22654,7 @@ ${card.task}${reportInstruction}`;
|
|
|
21941
22654
|
name: "start_subagent",
|
|
21942
22655
|
description: "Start a prepared descendant subagent task.",
|
|
21943
22656
|
schema: {
|
|
21944
|
-
topic_id:
|
|
22657
|
+
topic_id: z8.string().describe("Prepared subagent room id.")
|
|
21945
22658
|
},
|
|
21946
22659
|
async handler(input) {
|
|
21947
22660
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21961,7 +22674,7 @@ ${card.task}${reportInstruction}`;
|
|
|
21961
22674
|
name: "delete_subagent",
|
|
21962
22675
|
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.",
|
|
21963
22676
|
schema: {
|
|
21964
|
-
topic_id:
|
|
22677
|
+
topic_id: z8.string().describe("Exact subagent room id returned by list_subagents; names are not accepted.")
|
|
21965
22678
|
},
|
|
21966
22679
|
async handler(input) {
|
|
21967
22680
|
const result = ownedSubagentTree(ctx);
|
|
@@ -21985,8 +22698,8 @@ ${card.task}${reportInstruction}`;
|
|
|
21985
22698
|
name: "grant_subagent_tell",
|
|
21986
22699
|
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.",
|
|
21987
22700
|
schema: {
|
|
21988
|
-
subagent_topic_id:
|
|
21989
|
-
target_topic_id:
|
|
22701
|
+
subagent_topic_id: z8.string().describe("Source descendant subagent topic id."),
|
|
22702
|
+
target_topic_id: z8.string().describe("Target topic id: this manager room or another descendant in its tree.")
|
|
21990
22703
|
},
|
|
21991
22704
|
async handler(input) {
|
|
21992
22705
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22011,8 +22724,8 @@ ${card.task}${reportInstruction}`;
|
|
|
22011
22724
|
name: "revoke_subagent_tell",
|
|
22012
22725
|
description: "Remove an extra tell_session connection previously granted to a descendant subagent.",
|
|
22013
22726
|
schema: {
|
|
22014
|
-
subagent_topic_id:
|
|
22015
|
-
target_topic_id:
|
|
22727
|
+
subagent_topic_id: z8.string().describe("Source descendant subagent topic id."),
|
|
22728
|
+
target_topic_id: z8.string().describe("Granted target topic id.")
|
|
22016
22729
|
},
|
|
22017
22730
|
async handler(input) {
|
|
22018
22731
|
const result = ownedSubagentTree(ctx);
|
|
@@ -22034,18 +22747,18 @@ ${card.task}${reportInstruction}`;
|
|
|
22034
22747
|
}
|
|
22035
22748
|
function createSpawnSubagentToolDefinition(ctx, options = {}) {
|
|
22036
22749
|
const executionOverrideSchema = options.executionOverrides === false ? {} : {
|
|
22037
|
-
agent:
|
|
22038
|
-
model:
|
|
22750
|
+
agent: z8.enum(["claude", "codex", "maestro"]).optional().describe("Agent backend override. Defaults to this room's agent."),
|
|
22751
|
+
model: z8.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.`)
|
|
22039
22752
|
};
|
|
22040
22753
|
return {
|
|
22041
22754
|
name: "spawn_subagent",
|
|
22042
22755
|
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.",
|
|
22043
22756
|
schema: {
|
|
22044
|
-
task:
|
|
22045
|
-
name:
|
|
22757
|
+
task: z8.string().describe("Self-contained task brief. The worker has topic memory but no parent conversation history, so include all task-specific context."),
|
|
22758
|
+
name: z8.string().optional().describe("Short name for the subagent room. Auto-generated when omitted."),
|
|
22046
22759
|
...executionOverrideSchema,
|
|
22047
|
-
memory_topic:
|
|
22048
|
-
report_mode:
|
|
22760
|
+
memory_topic: z8.string().optional().describe("Optional knowledge source: an accessible topic id/title or topic/*.md brief. Defaults to the parent room's effective topic brief."),
|
|
22761
|
+
report_mode: z8.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.")
|
|
22049
22762
|
},
|
|
22050
22763
|
async handler(input) {
|
|
22051
22764
|
return createSubagent(ctx, input, true);
|
|
@@ -22057,14 +22770,14 @@ ${card.task}${reportInstruction}`;
|
|
|
22057
22770
|
name: "create_subagent",
|
|
22058
22771
|
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.",
|
|
22059
22772
|
schema: {
|
|
22060
|
-
task:
|
|
22061
|
-
name:
|
|
22773
|
+
task: z8.string().describe("Self-contained task brief for the subagent."),
|
|
22774
|
+
name: z8.string().optional().describe("Short room name. Auto-generated when omitted."),
|
|
22062
22775
|
...options.executionOverrides === false ? {} : {
|
|
22063
|
-
agent:
|
|
22064
|
-
model:
|
|
22776
|
+
agent: z8.enum(["claude", "codex", "maestro"]).optional(),
|
|
22777
|
+
model: z8.string().optional()
|
|
22065
22778
|
},
|
|
22066
|
-
memory_topic:
|
|
22067
|
-
report_mode:
|
|
22779
|
+
memory_topic: z8.string().optional().describe("Optional accessible topic id/title or topic/*.md brief to use as this worker's knowledge source. Defaults to the parent."),
|
|
22780
|
+
report_mode: z8.enum(["auto", "tell", "status-only"]).optional()
|
|
22068
22781
|
},
|
|
22069
22782
|
async handler(input) {
|
|
22070
22783
|
return createSubagent(ctx, input, false);
|
|
@@ -23680,6 +24393,12 @@ ${fresh.join(`
|
|
|
23680
24393
|
`;
|
|
23681
24394
|
}
|
|
23682
24395
|
const skillDir = resolve2(runtime().skillsDir, name);
|
|
24396
|
+
if (dirname2(skillDir) !== resolve2(runtime().skillsDir) || name !== basename(skillDir)) {
|
|
24397
|
+
return {
|
|
24398
|
+
content: [{ type: "text", text: "Skill name must be a single folder name." }],
|
|
24399
|
+
isError: true
|
|
24400
|
+
};
|
|
24401
|
+
}
|
|
23683
24402
|
ensureDir(skillDir);
|
|
23684
24403
|
const skillPath = resolve2(skillDir, "skill.md");
|
|
23685
24404
|
let finalContent = content;
|
|
@@ -25007,7 +25726,7 @@ ${renderDecisionList(decisions)}`);
|
|
|
25007
25726
|
}
|
|
25008
25727
|
// ../../packages/core/src/mcp/factories/session-comm.ts
|
|
25009
25728
|
import { McpServer as McpServer4 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25010
|
-
import { z as
|
|
25729
|
+
import { z as z9 } from "zod";
|
|
25011
25730
|
|
|
25012
25731
|
// ../../packages/core/src/mcp/session-comm/history-tools.ts
|
|
25013
25732
|
import { z as z4 } from "zod";
|
|
@@ -25097,32 +25816,32 @@ function createSessionCommMcpServer(context, host, options = {}) {
|
|
|
25097
25816
|
const subagentIdentity = resolveSubagentTellIdentity(context.currentTopicId, context.subagentParentTopicId);
|
|
25098
25817
|
server.tool("list_sessions", "List available sessions and remote peer sessions for inter-session communication.", {}, async () => host.listSessions(context));
|
|
25099
25818
|
server.tool("configure_mcp", `Configure optional MCP servers for the current topic. Required: ${required}. Optional: ${optional}.`, {
|
|
25100
|
-
enabled:
|
|
25819
|
+
enabled: z9.array(z9.string()).nullable().optional()
|
|
25101
25820
|
}, async ({ enabled }) => host.configureMcp(context, enabled));
|
|
25102
25821
|
server.tool("get_mcp_config", "Get the current topic MCP configuration.", {}, async () => host.getMcpConfig(context));
|
|
25103
25822
|
if (host.getBrowserProfile) {
|
|
25104
25823
|
server.tool("get_browser_profile", "Get this topic's browser profile and the profiles owned by the same user.", {}, async () => host.getBrowserProfile(context));
|
|
25105
25824
|
}
|
|
25106
25825
|
if (host.setBrowserProfile) {
|
|
25107
|
-
server.tool("set_browser_profile", "Assign this topic to a named shared browser profile. Takes effect next turn.", { profile:
|
|
25826
|
+
server.tool("set_browser_profile", "Assign this topic to a named shared browser profile. Takes effect next turn.", { profile: z9.string() }, async ({ profile }) => host.setBrowserProfile(context, profile));
|
|
25108
25827
|
}
|
|
25109
25828
|
if (host.deleteBrowserProfile) {
|
|
25110
|
-
server.tool("delete_browser_profile", "Delete an unused named browser profile and its on-disk data. The default or an assigned profile cannot be deleted.", { profile:
|
|
25829
|
+
server.tool("delete_browser_profile", "Delete an unused named browser profile and its on-disk data. The default or an assigned profile cannot be deleted.", { profile: z9.string() }, async ({ profile }) => host.deleteBrowserProfile(context, profile));
|
|
25111
25830
|
}
|
|
25112
25831
|
server.tool("peek_session", "Inspect running and idle sessions, including pending ask_session calls.", {}, async () => host.peekSession(context));
|
|
25113
|
-
server.tool("set_description", "Set the current session description used as a routing hint.", { description:
|
|
25832
|
+
server.tool("set_description", "Set the current session description used as a routing hint.", { description: z9.string() }, async ({ description }) => host.setDescription(context, description));
|
|
25114
25833
|
if (host.sessionHistoryOf) {
|
|
25115
25834
|
registerSessionHistoryOfTools(server, host.sessionHistoryOf(context));
|
|
25116
25835
|
}
|
|
25117
25836
|
if (!context.replyOnly) {
|
|
25118
25837
|
if (!subagentIdentity.restricted) {
|
|
25119
|
-
server.tool("ask_session", "Ask another local or remote session a question and wait for its answer. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to:
|
|
25120
|
-
server.tool("ask_cron", "Ask this topic's shared Cron session a question. The answer is injected asynchronously into the current conversation.", { message:
|
|
25838
|
+
server.tool("ask_session", "Ask another local or remote session a question and wait for its answer. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to: z9.string(), message: z9.string() }, async (input) => host.askSession(context, input));
|
|
25839
|
+
server.tool("ask_cron", "Ask this topic's shared Cron session a question. The answer is injected asynchronously into the current conversation.", { message: z9.string() }, async ({ message }) => host.askCron(context, message));
|
|
25121
25840
|
}
|
|
25122
25841
|
if (!subagentIdentity.restricted) {
|
|
25123
|
-
server.tool("abort_session", "Abort the active query in another session.", { to:
|
|
25842
|
+
server.tool("abort_session", "Abort the active query in another session.", { to: z9.string() }, async ({ to }) => host.abortSession(context, to));
|
|
25124
25843
|
}
|
|
25125
|
-
server.tool("tell_session", "Send a one-way message to another local or remote session. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to:
|
|
25844
|
+
server.tool("tell_session", "Send a one-way message to another local or remote session. To hand over long context, cite an entry range or sessionId of your own history (list_session_boundaries) instead of pasting it \u2014 the target can read it with read_session_history_of.", { to: z9.string(), message: z9.string() }, async (input) => {
|
|
25126
25845
|
if (subagentIdentity.restricted && !canSubagentTellTargetByName(subagentIdentity, input.to)) {
|
|
25127
25846
|
return {
|
|
25128
25847
|
content: [
|
|
@@ -25142,7 +25861,7 @@ function createSessionCommMcpServer(context, host, options = {}) {
|
|
|
25142
25861
|
// ../../packages/core/src/mcp/factories/session-history.ts
|
|
25143
25862
|
init_mcp_helpers();
|
|
25144
25863
|
import { McpServer as McpServer5 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25145
|
-
import { z as
|
|
25864
|
+
import { z as z10 } from "zod";
|
|
25146
25865
|
|
|
25147
25866
|
// ../../packages/core/src/mcp/session-history-reader.ts
|
|
25148
25867
|
init_mcp_helpers();
|
|
@@ -25409,9 +26128,9 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25409
26128
|
"list_session_boundaries, then pass sessionId to read only that session's range instead of",
|
|
25410
26129
|
"paging through the whole topic."
|
|
25411
26130
|
].join(" "), {
|
|
25412
|
-
offset:
|
|
25413
|
-
limit:
|
|
25414
|
-
sessionId:
|
|
26131
|
+
offset: z10.number().optional().describe("One-based entry number. Defaults to 1."),
|
|
26132
|
+
limit: z10.number().optional().describe(`Number of entries. Defaults to ${SESSION_HISTORY_DEFAULT_LINE_LIMIT}, max ${SESSION_HISTORY_MAX_LINE_LIMIT}.`),
|
|
26133
|
+
sessionId: z10.string().optional().describe("Restrict to one session's entry range (see list_session_boundaries).")
|
|
25415
26134
|
}, async (args) => requireContext() ?? reader.read(self, args));
|
|
25416
26135
|
server.tool("search_session_history", [
|
|
25417
26136
|
"Keyword-search the full raw conversation manifest (case-insensitive substring match)",
|
|
@@ -25421,9 +26140,9 @@ function createSessionHistoryMcpServer(context) {
|
|
|
25421
26140
|
"topic's size, but prefer sessionId to narrow the scan when you already know which session",
|
|
25422
26141
|
"from list_session_boundaries."
|
|
25423
26142
|
].join(" "), {
|
|
25424
|
-
query:
|
|
25425
|
-
sessionId:
|
|
25426
|
-
limit:
|
|
26143
|
+
query: z10.string().min(1).describe("Case-insensitive substring to search for."),
|
|
26144
|
+
sessionId: z10.string().optional().describe("Restrict the scan to one session's range."),
|
|
26145
|
+
limit: z10.number().optional().describe(`Max matches to return. Defaults to ${SESSION_HISTORY_DEFAULT_SEARCH_LIMIT}, max ${SESSION_HISTORY_MAX_SEARCH_LIMIT}.`)
|
|
25427
26146
|
}, async (args) => requireContext() ?? reader.search(self, args));
|
|
25428
26147
|
return server;
|
|
25429
26148
|
}
|
|
@@ -25627,7 +26346,7 @@ function createSystemHealthMcpServer(host = defaultSystemHealthMcpHost) {
|
|
|
25627
26346
|
init_mcp_helpers();
|
|
25628
26347
|
await init_tasks();
|
|
25629
26348
|
import { McpServer as McpServer7 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25630
|
-
import { z as
|
|
26349
|
+
import { z as z11 } from "zod";
|
|
25631
26350
|
var defaultTaskMcpHost = {
|
|
25632
26351
|
readTasks,
|
|
25633
26352
|
writeTasks
|
|
@@ -25641,13 +26360,13 @@ function createTaskMcpServer(context, host = defaultTaskMcpHost) {
|
|
|
25641
26360
|
}
|
|
25642
26361
|
return null;
|
|
25643
26362
|
};
|
|
25644
|
-
const statusEnum =
|
|
26363
|
+
const statusEnum = z11.enum(TASK_STATUS_VALUES);
|
|
25645
26364
|
server.tool("task_create", "Add one or more tasks to this topic's shared Otium task list. Use this instead of provider-native todo/task tools.", {
|
|
25646
|
-
tasks:
|
|
25647
|
-
subject:
|
|
25648
|
-
active_form:
|
|
25649
|
-
blocked_by:
|
|
25650
|
-
owner:
|
|
26365
|
+
tasks: z11.array(z11.object({
|
|
26366
|
+
subject: z11.string().min(1).describe("Short imperative task description"),
|
|
26367
|
+
active_form: z11.string().optional().describe("Label to show while the task is in progress"),
|
|
26368
|
+
blocked_by: z11.array(z11.string()).optional().describe("Task ids blocking this task"),
|
|
26369
|
+
owner: z11.string().optional().describe("Owner/agent label for multi-agent work")
|
|
25651
26370
|
})).min(1)
|
|
25652
26371
|
}, async ({ tasks: inputs }) => {
|
|
25653
26372
|
const guard = requireContext();
|
|
@@ -25671,13 +26390,13 @@ ${renderTaskList(tasks)}`);
|
|
|
25671
26390
|
}
|
|
25672
26391
|
});
|
|
25673
26392
|
server.tool("task_update", "Update task status/content in this topic's shared Otium task list. Batch related status changes in one call.", {
|
|
25674
|
-
updates:
|
|
25675
|
-
id:
|
|
26393
|
+
updates: z11.array(z11.object({
|
|
26394
|
+
id: z11.string().describe("Target task id"),
|
|
25676
26395
|
status: statusEnum.optional().describe("New status"),
|
|
25677
|
-
subject:
|
|
25678
|
-
active_form:
|
|
25679
|
-
blocked_by:
|
|
25680
|
-
owner:
|
|
26396
|
+
subject: z11.string().min(1).optional().describe("Replacement task description"),
|
|
26397
|
+
active_form: z11.string().optional().describe("Replacement in-progress label; empty string clears it"),
|
|
26398
|
+
blocked_by: z11.array(z11.string()).optional().describe("Replacement blocker id list"),
|
|
26399
|
+
owner: z11.string().optional().describe("Replacement owner; empty string clears it")
|
|
25681
26400
|
})).min(1)
|
|
25682
26401
|
}, async ({ updates }) => {
|
|
25683
26402
|
const guard = requireContext();
|
|
@@ -25711,7 +26430,7 @@ Missing ids ignored: ${missing.join(", ")}` : "";
|
|
|
25711
26430
|
return mcpError(`task_list failed: ${errMsg(error)}`);
|
|
25712
26431
|
}
|
|
25713
26432
|
});
|
|
25714
|
-
server.tool("task_get", "Read one task from this topic's shared Otium task list as JSON.", { id:
|
|
26433
|
+
server.tool("task_get", "Read one task from this topic's shared Otium task list as JSON.", { id: z11.string().describe("Task id") }, async ({ id }) => {
|
|
25715
26434
|
const guard = requireContext();
|
|
25716
26435
|
if (guard)
|
|
25717
26436
|
return guard;
|
|
@@ -25725,8 +26444,8 @@ Missing ids ignored: ${missing.join(", ")}` : "";
|
|
|
25725
26444
|
}
|
|
25726
26445
|
});
|
|
25727
26446
|
server.tool("task_delete", "Delete tasks from this topic's shared Otium task list. Use all=true only when starting a new plan.", {
|
|
25728
|
-
ids:
|
|
25729
|
-
all:
|
|
26447
|
+
ids: z11.array(z11.string()).optional().describe("Task ids to delete"),
|
|
26448
|
+
all: z11.boolean().optional().describe("Delete the whole list")
|
|
25730
26449
|
}, async ({ ids, all }) => {
|
|
25731
26450
|
const guard = requireContext();
|
|
25732
26451
|
if (guard)
|
|
@@ -25749,7 +26468,7 @@ ${renderTaskList(tasks)}`);
|
|
|
25749
26468
|
// ../../packages/core/src/mcp/factories/token-stats.ts
|
|
25750
26469
|
await init_token_stats();
|
|
25751
26470
|
import { McpServer as McpServer8 } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25752
|
-
import { z as
|
|
26471
|
+
import { z as z12 } from "zod";
|
|
25753
26472
|
var defaultTokenStatsMcpHost = {
|
|
25754
26473
|
getStats,
|
|
25755
26474
|
calcCost
|
|
@@ -25769,9 +26488,9 @@ function createTokenStatsMcpServer(context, host = defaultTokenStatsMcpHost) {
|
|
|
25769
26488
|
"groupBy: 'session'\uC73C\uB85C \uC124\uC815\uD558\uBA74 \uC138\uC158\uBCC4 \uD1A0\uD070 \uC0AC\uC6A9\uB7C9 \uB7AD\uD0B9\uC744 \uBC18\uD658\uD569\uB2C8\uB2E4."
|
|
25770
26489
|
].join(`
|
|
25771
26490
|
`), {
|
|
25772
|
-
from:
|
|
25773
|
-
to:
|
|
25774
|
-
groupBy:
|
|
26491
|
+
from: z12.string().optional().describe("\uC2DC\uC791 \uC2DC\uAC01 ISO 8601. \uC608: '2026-03-28T09:00:00Z'"),
|
|
26492
|
+
to: z12.string().optional().describe("\uC885\uB8CC \uC2DC\uAC01 ISO 8601. \uC0DD\uB7B5 \uC2DC \uD604\uC7AC"),
|
|
26493
|
+
groupBy: z12.enum(["hour", "session"]).optional().describe("\uC9D1\uACC4 \uAE30\uC900. \uAE30\uBCF8\uAC12: hour")
|
|
25775
26494
|
}, async ({ from, to, groupBy = "hour" }) => {
|
|
25776
26495
|
const snapshot = host.getStats(context.userId, from, to);
|
|
25777
26496
|
const {
|
|
@@ -25882,4 +26601,4 @@ export {
|
|
|
25882
26601
|
protectMcpStdio
|
|
25883
26602
|
};
|
|
25884
26603
|
|
|
25885
|
-
//# debugId=
|
|
26604
|
+
//# debugId=D4E958794177860164756E2164756E21
|