pi-harness-runtime 1.1.465 → 1.1.466
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/CHANGELOG.md +43 -0
- package/harness/honcho-init.ts +4 -1
- package/harness/mcp-connector.ts +507 -0
- package/index.ts +100 -1
- package/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/contracts/package.json +1 -1
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/write-review/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.1.466](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.466) (2026-11-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* **delegation:** a child is only a child when it really ran ([ac4e678](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ac4e6782d7d4bc4941e458425c8a9f38a51fc9d4))
|
|
11
|
+
* **delegation:** the scope of a request is measured before it is judged ([684b6a5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/684b6a55184f63d3be24c48dcecfb0b13410dc15))
|
|
12
|
+
* **honcho:** the memory service speaks the native MCP of Pi ([f9f740c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f9f740c12869bae4c4380afbe8c76e12388bb744))
|
|
13
|
+
* **jev:** the evaluation of a choice sees what the options mean ([f0c207e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/f0c207e074701e6b7dab0965170ec39453d9d502))
|
|
14
|
+
* **jev:** the pending question carries the ask and the answer ([a792133](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a792133e517fb8c12d3363e98942f3af30270f27))
|
|
15
|
+
* **jev:** the pending question counts down to the decision ([d0cc171](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d0cc171223986b2d32c670b6c1c74712fe0a4ad8))
|
|
16
|
+
* **keys:** the key files are repaired when their permissions are unsafe ([e9c2c26](https://github.com/ManotLuijiu/pi-harness-runtime/commit/e9c2c26b287665b56ed749de269737e8403bb8af))
|
|
17
|
+
* **mcp:** the harness connects the registered servers when nobody else does ([7fef951](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7fef95137ad4664df57f045cd91b7d233315b0bc))
|
|
18
|
+
* **merge:** a manual run can leave the merge to the pull request event ([b3d1950](https://github.com/ManotLuijiu/pi-harness-runtime/commit/b3d1950b5941c78ccd56951acdafd1d4afbe1bff))
|
|
19
|
+
* **phase:** the agent owns the todo list and the harness says so ([c489370](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c489370bd7926aece8cb1a77aa20ca2d2672f1fb))
|
|
20
|
+
* **review:** the review starts on its own when the implementation is done ([04f51f5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/04f51f599cd3222b6c74dd8fadb1373bd72d9bd7))
|
|
21
|
+
* **status:** the status line names the phase, the progress and the children ([0167bf3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/0167bf396a0b987c1d44f3b869351976a951dd65))
|
|
22
|
+
* **test:** the task waits for the final tier of the validation plan ([fa147db](https://github.com/ManotLuijiu/pi-harness-runtime/commit/fa147dbf7d50d56e6ea48c6d8fbb4fcb190caf8a))
|
|
23
|
+
* **validation:** a large job starts with a measured pilot ([425964b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/425964b04a3d4fa02adfabed47ff62c5ec2b9c28))
|
|
24
|
+
* **validation:** the size of a job is a fact, not a phrase ([8aa6c11](https://github.com/ManotLuijiu/pi-harness-runtime/commit/8aa6c119565d0f8412dc8aeafa6b295d47d3f093))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* **ci:** every run of a required check counts, and the worst one decides ([da9e0da](https://github.com/ManotLuijiu/pi-harness-runtime/commit/da9e0da6b0ca29cb320764fd5fc1b8a8dee8b1e0))
|
|
30
|
+
* **ci:** the newest attempt of a run decides, not the attempt that failed ([9d7adcc](https://github.com/ManotLuijiu/pi-harness-runtime/commit/9d7adcc31cbacc517c3c1a9bcd3956be94c908ef))
|
|
31
|
+
* **honcho:** the report names the state of the MCP server, not the registration ([762f4d5](https://github.com/ManotLuijiu/pi-harness-runtime/commit/762f4d59e4eabcab9a1c21a61aa522c3267621b3))
|
|
32
|
+
* **hooks:** a tag is checked through the commit behind it ([c823e8e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/c823e8e1f6973c62b5449a97c101759a4d5cbba5))
|
|
33
|
+
* **jev:** a session switch ends the wait of the old session ([ca03d39](https://github.com/ManotLuijiu/pi-harness-runtime/commit/ca03d399c0d4a1b2dd428ac39836ab53c0e51ab6))
|
|
34
|
+
* **jev:** the alternatives of a question are parsed without a quadratic pattern ([63016a3](https://github.com/ManotLuijiu/pi-harness-runtime/commit/63016a3f0488acb801990dd46770c00d382b5858))
|
|
35
|
+
* **jev:** the facts of an option survive the wording of the agent ([5a6250c](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5a6250c07aa8d965bc6ae242cccbf519477598f8))
|
|
36
|
+
* **keys:** the key directory is audited as a tree ([081cc75](https://github.com/ManotLuijiu/pi-harness-runtime/commit/081cc75ac8ceff36b0d619c3f76371dc08459d3c))
|
|
37
|
+
* **merge:** the boolean input is read as a boolean ([971b716](https://github.com/ManotLuijiu/pi-harness-runtime/commit/971b7169a43db382dbdeb6bb9bab02ab56e0351c))
|
|
38
|
+
* **merge:** the manual job needs the right of the merge ([7ba685e](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7ba685ec43d815f90aa35b742579e87e76c69209))
|
|
39
|
+
* **merge:** the merge of the pull request is the GraphQL mutation ([972bab4](https://github.com/ManotLuijiu/pi-harness-runtime/commit/972bab4b0f7faf1b0047f3bb767ef6db3de4b2fa))
|
|
40
|
+
* **merge:** the workflow merges the pull request the gates cleared ([d7639ec](https://github.com/ManotLuijiu/pi-harness-runtime/commit/d7639ec9b83723510acb4a5c4e23d5d6167c3af6))
|
|
41
|
+
* **release:** a manual release keeps the version of its manifest ([122e661](https://github.com/ManotLuijiu/pi-harness-runtime/commit/122e661ea48cb8aff14c71dbd0221a4cf0ba4c8e))
|
|
42
|
+
* **release:** the alignment names the reason of a failure ([5814dd0](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5814dd0b780f5839cf8011ed0cbbbb31e7eb0418))
|
|
43
|
+
* **release:** the channels of the package name the release ([a7a273f](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a7a273ffe8398e2b5b07ef1c321777de41792c6e))
|
|
44
|
+
* **release:** the release publishes and leaves the channels alone ([5871746](https://github.com/ManotLuijiu/pi-harness-runtime/commit/5871746589c1281d855dbeb591b02419fa43f22e))
|
|
45
|
+
* **release:** the release pull request names the version of its branch ([a846e83](https://github.com/ManotLuijiu/pi-harness-runtime/commit/a846e83e6de6e529f4bca05e869db0b5eebb37c5))
|
|
46
|
+
* **release:** the release scans the tree of the commit it publishes ([7d47a0b](https://github.com/ManotLuijiu/pi-harness-runtime/commit/7d47a0b5406480a1e1d3a52623a76aabd1e2d0ba))
|
|
47
|
+
|
|
5
48
|
### [1.1.465](https://github.com/ManotLuijiu/pi-harness-runtime/compare/v1.1.448...v1.1.465) (2026-11-07)
|
|
6
49
|
|
|
7
50
|
|
package/harness/honcho-init.ts
CHANGED
|
@@ -164,7 +164,7 @@ export interface HonchoMcpRegistrar {
|
|
|
164
164
|
const HONCHO_MCP_URL = "https://mcp.honcho.dev";
|
|
165
165
|
|
|
166
166
|
/** The name of the Honcho MCP server in Pi. */
|
|
167
|
-
const HONCHO_SERVER_NAME = "honcho";
|
|
167
|
+
export const HONCHO_SERVER_NAME = "honcho";
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* The prefix of the names of the tools of the Honcho server.
|
|
@@ -1184,6 +1184,9 @@ export function honchoMcpReport(
|
|
|
1184
1184
|
text: "MCP registered, not connected",
|
|
1185
1185
|
status: "warn",
|
|
1186
1186
|
details: [
|
|
1187
|
+
...(reason
|
|
1188
|
+
? [`The connection failed: ${reason}`]
|
|
1189
|
+
: []),
|
|
1187
1190
|
"The Honcho server is registered with Pi.",
|
|
1188
1191
|
"Its tools reach the model only while an MCP connector is active.",
|
|
1189
1192
|
"Check /mcp for the connection state.",
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fallback connector for the MCP servers that extensions register.
|
|
3
|
+
*
|
|
4
|
+
* Pi's built-in MCP extension connects the registered servers. While it is
|
|
5
|
+
* active, it does that job and this connector stays out of the way: it only
|
|
6
|
+
* connects a server that nobody else connected. The evidence of another
|
|
7
|
+
* connector is the tools of the server in the session - the same evidence
|
|
8
|
+
* the startup report of Honcho uses.
|
|
9
|
+
*
|
|
10
|
+
* The connector never claims a readiness it did not reach: a server it could
|
|
11
|
+
* not connect is reported with its reason, and its tools stay absent.
|
|
12
|
+
*
|
|
13
|
+
* The connector handles the change of the registered servers because Pi
|
|
14
|
+
* expects the extension that handles it to be the one that connects them.
|
|
15
|
+
* Handling the event is therefore a promise, and this module keeps it: a
|
|
16
|
+
* registered server is connected here unless another connector got there
|
|
17
|
+
* first.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { createHash } from "node:crypto";
|
|
21
|
+
|
|
22
|
+
/** A server registered by an extension. */
|
|
23
|
+
export interface RegisteredMcpServerLike {
|
|
24
|
+
name: string;
|
|
25
|
+
config: McpServerConfigLike;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The configuration of a registered server. */
|
|
29
|
+
export interface McpServerConfigLike {
|
|
30
|
+
/** The url of a streamable HTTP server. */
|
|
31
|
+
url?: string;
|
|
32
|
+
/** The headers of the request, for example the credential. */
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/** The command of a stdio server. */
|
|
35
|
+
command?: string;
|
|
36
|
+
/** The arguments of the command. */
|
|
37
|
+
args?: string[];
|
|
38
|
+
/** The environment of the command. */
|
|
39
|
+
env?: Record<string, string>;
|
|
40
|
+
/** The working directory of the command. */
|
|
41
|
+
cwd?: string;
|
|
42
|
+
/** How the model reaches the tools. Default: `codemode`. */
|
|
43
|
+
exposure?: string;
|
|
44
|
+
/** What the server offers, in a sentence. */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** A server that is not enabled is kept without connecting. */
|
|
47
|
+
enabled?: boolean;
|
|
48
|
+
/** The timeout of a request, in seconds. */
|
|
49
|
+
timeout?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** A transport of Pi's MCP library. */
|
|
53
|
+
export interface McpTransportLike {
|
|
54
|
+
start?(): Promise<void>;
|
|
55
|
+
send?(message: unknown): Promise<void>;
|
|
56
|
+
close?(): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The part of Pi's client the connector uses. */
|
|
60
|
+
export interface McpClientLike {
|
|
61
|
+
connect(transport: unknown): Promise<unknown>;
|
|
62
|
+
listTools(): Promise<McpToolLike[]>;
|
|
63
|
+
callTool(
|
|
64
|
+
name: string,
|
|
65
|
+
args?: Record<string, unknown>,
|
|
66
|
+
options?: { signal?: AbortSignal; timeoutMs?: number },
|
|
67
|
+
): Promise<unknown>;
|
|
68
|
+
close(): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A tool of an MCP server. */
|
|
72
|
+
export interface McpToolLike {
|
|
73
|
+
name: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
inputSchema?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The transports and the client of Pi's MCP library. */
|
|
79
|
+
export interface McpClientLibrary {
|
|
80
|
+
McpClient: new (options: {
|
|
81
|
+
name: string;
|
|
82
|
+
version: string;
|
|
83
|
+
requestTimeoutMs?: number;
|
|
84
|
+
}) => McpClientLike;
|
|
85
|
+
StreamableHttpTransport: new (options: {
|
|
86
|
+
url: string;
|
|
87
|
+
headers?: Record<string, string>;
|
|
88
|
+
}) => McpTransportLike;
|
|
89
|
+
StdioTransport: new (options: {
|
|
90
|
+
command: string;
|
|
91
|
+
args?: readonly string[];
|
|
92
|
+
env?: Record<string, string>;
|
|
93
|
+
cwd?: string;
|
|
94
|
+
}) => McpTransportLike;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The result of a tool call, in the shape Pi expects. */
|
|
98
|
+
export interface McpToolResult {
|
|
99
|
+
content: Array<{ type: "text"; text: string }>;
|
|
100
|
+
isError?: boolean;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The tool the connector registers. */
|
|
104
|
+
export interface McpToolDefinition {
|
|
105
|
+
name: string;
|
|
106
|
+
label: string;
|
|
107
|
+
description: string;
|
|
108
|
+
parameters: Record<string, unknown>;
|
|
109
|
+
exposure: string;
|
|
110
|
+
namespace: { name: string; aliases?: string[] };
|
|
111
|
+
execute(
|
|
112
|
+
toolCallId: string,
|
|
113
|
+
params: Record<string, unknown>,
|
|
114
|
+
signal?: AbortSignal,
|
|
115
|
+
): Promise<McpToolResult>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The API of Pi that the connector needs. */
|
|
119
|
+
export interface McpConnectorApi {
|
|
120
|
+
/** The servers registered by the extensions. */
|
|
121
|
+
getMcpServers?: () => RegisteredMcpServerLike[];
|
|
122
|
+
/** The tools of the session. */
|
|
123
|
+
getAllTools?: () => Array<{ name?: unknown }>;
|
|
124
|
+
/** Registers a tool of the session. */
|
|
125
|
+
registerTool?: (tool: McpToolDefinition) => void;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The options of the connector. */
|
|
129
|
+
export interface McpConnectorOptions {
|
|
130
|
+
/**
|
|
131
|
+
* How long the connector waits before it connects a server.
|
|
132
|
+
*
|
|
133
|
+
* Another connector may be at work: the built-in extension of Pi
|
|
134
|
+
* connects the registered servers in the background. The wait gives it
|
|
135
|
+
* the time, and the evidence of its work is the tools of the server.
|
|
136
|
+
*/
|
|
137
|
+
graceMs?: number;
|
|
138
|
+
/** The library of Pi that carries the client and the transports. */
|
|
139
|
+
loadLibrary: () => Promise<McpClientLibrary>;
|
|
140
|
+
/** The log of the connector. */
|
|
141
|
+
log?: (message: string) => void;
|
|
142
|
+
/** The wait, replaced by the tests. */
|
|
143
|
+
delay?: (ms: number) => Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** What the connector knows about a server. */
|
|
147
|
+
export interface McpServerStatus {
|
|
148
|
+
/**
|
|
149
|
+
* - "connected": the connector connected the server and registered its
|
|
150
|
+
* tools.
|
|
151
|
+
* - "skipped": another connector connected the server.
|
|
152
|
+
* - "failed": the connector could not connect the server, and the
|
|
153
|
+
* reason says why.
|
|
154
|
+
*/
|
|
155
|
+
state: "connected" | "skipped" | "failed";
|
|
156
|
+
/** The names of the tools of the server. */
|
|
157
|
+
tools: string[];
|
|
158
|
+
/** The reason of a failure or of a skip. */
|
|
159
|
+
reason?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The connector of the session. */
|
|
163
|
+
export interface McpConnector {
|
|
164
|
+
/** Connect the servers that nobody else connected. */
|
|
165
|
+
connectPending(): Promise<void>;
|
|
166
|
+
/** What the connector knows about every server it saw. */
|
|
167
|
+
readonly statuses: Map<string, McpServerStatus>;
|
|
168
|
+
/** Close the connections of the connector. */
|
|
169
|
+
close(): Promise<void>;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** The default wait before the connector connects a server. */
|
|
173
|
+
const DEFAULT_GRACE_MS = 1_500;
|
|
174
|
+
|
|
175
|
+
/** The longest name a tool may have, the same limit Pi uses. */
|
|
176
|
+
const MAX_TOOL_NAME_LENGTH = 64;
|
|
177
|
+
|
|
178
|
+
/** The timeout of a request of the connector, in milliseconds. */
|
|
179
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The name of a tool of an MCP server.
|
|
183
|
+
*
|
|
184
|
+
* The name follows the convention of Pi, so the tools of the connector and
|
|
185
|
+
* the tools of the built-in extension are the same tools and not two of
|
|
186
|
+
* them: the session keeps one entry per name. A name that is too long or
|
|
187
|
+
* that another tool already took gets the same hash suffix as in Pi, so the
|
|
188
|
+
* names of the two connectors agree.
|
|
189
|
+
*
|
|
190
|
+
* @param server The name of the server
|
|
191
|
+
* @param tool The name of the tool in the server
|
|
192
|
+
* @param isTaken Whether a name is already in use
|
|
193
|
+
* @returns The name of the tool in the session
|
|
194
|
+
*/
|
|
195
|
+
export function mcpToolName(
|
|
196
|
+
server: string,
|
|
197
|
+
tool: string,
|
|
198
|
+
isTaken: (candidate: string) => boolean = () => false,
|
|
199
|
+
): string {
|
|
200
|
+
const name = `mcp__${server}__${tool}`.replace(/[^A-Za-z0-9_]/g, "_");
|
|
201
|
+
if (name.length <= MAX_TOOL_NAME_LENGTH && !isTaken(name)) return name;
|
|
202
|
+
const hash = createHash("sha256")
|
|
203
|
+
.update(`${server}\0${tool}`)
|
|
204
|
+
.digest("hex")
|
|
205
|
+
.slice(0, 8);
|
|
206
|
+
return `${name.slice(0, MAX_TOOL_NAME_LENGTH - hash.length - 1)}_${hash}`;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The namespace of the tools of a server.
|
|
211
|
+
*
|
|
212
|
+
* The namespace replaces a dash with an underscore, so a server and a
|
|
213
|
+
* namespace never collide.
|
|
214
|
+
*/
|
|
215
|
+
export function mcpNamespace(server: string): string {
|
|
216
|
+
return `mcp__${server.replace(/-/g, "_")}`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* The tools of a server that the session has.
|
|
221
|
+
*
|
|
222
|
+
* The tools are the evidence of a connection: a server that nobody connected
|
|
223
|
+
* has none.
|
|
224
|
+
*
|
|
225
|
+
* @param api The API of Pi
|
|
226
|
+
* @param server The name of the server
|
|
227
|
+
* @returns The names of the tools of the server
|
|
228
|
+
*/
|
|
229
|
+
export function serverToolNames(
|
|
230
|
+
api: McpConnectorApi,
|
|
231
|
+
server: string,
|
|
232
|
+
): string[] {
|
|
233
|
+
if (typeof api.getAllTools !== "function") return [];
|
|
234
|
+
let tools: Array<{ name?: unknown }>;
|
|
235
|
+
try {
|
|
236
|
+
tools = api.getAllTools();
|
|
237
|
+
} catch {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
240
|
+
if (!Array.isArray(tools)) return [];
|
|
241
|
+
const prefix = `${mcpNamespace(server)}__`;
|
|
242
|
+
const names: string[] = [];
|
|
243
|
+
for (const tool of tools) {
|
|
244
|
+
const name = typeof tool?.name === "string" ? tool.name : "";
|
|
245
|
+
if (name.startsWith(prefix) && !names.includes(name)) names.push(name);
|
|
246
|
+
}
|
|
247
|
+
return names;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* The parameter schema of a tool of a server.
|
|
252
|
+
*
|
|
253
|
+
* A tool of an MCP server describes its input with a JSON schema. The schema
|
|
254
|
+
* of a tool has to be an object, and some servers leave the type out.
|
|
255
|
+
*/
|
|
256
|
+
export function toParameters(
|
|
257
|
+
schema: Record<string, unknown> | undefined,
|
|
258
|
+
): Record<string, unknown> {
|
|
259
|
+
const value = schema ?? {};
|
|
260
|
+
return {
|
|
261
|
+
...value,
|
|
262
|
+
type: typeof value.type === "string" ? value.type : "object",
|
|
263
|
+
...(value.properties === undefined ? { properties: {} } : {}),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* The result of a tool call of a server, in the shape Pi expects.
|
|
269
|
+
*
|
|
270
|
+
* The blocks that are not text become text, so the model always gets
|
|
271
|
+
* something it can read.
|
|
272
|
+
*/
|
|
273
|
+
export function toToolResult(result: unknown): McpToolResult {
|
|
274
|
+
const value = (result ?? {}) as {
|
|
275
|
+
content?: unknown;
|
|
276
|
+
structuredContent?: unknown;
|
|
277
|
+
isError?: boolean;
|
|
278
|
+
};
|
|
279
|
+
const blocks = Array.isArray(value.content) ? value.content : [];
|
|
280
|
+
const content = blocks.map((block) => {
|
|
281
|
+
const item = (block ?? {}) as { type?: string; text?: unknown };
|
|
282
|
+
if (item.type === "text" && typeof item.text === "string") {
|
|
283
|
+
return { type: "text" as const, text: item.text };
|
|
284
|
+
}
|
|
285
|
+
return { type: "text" as const, text: JSON.stringify(block) };
|
|
286
|
+
});
|
|
287
|
+
if (content.length === 0 && value.structuredContent !== undefined) {
|
|
288
|
+
content.push({ type: "text", text: JSON.stringify(value.structuredContent) });
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
content,
|
|
292
|
+
...(value.isError === true ? { isError: true } : {}),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The transport of a registered server.
|
|
298
|
+
*
|
|
299
|
+
* A server is a streamable HTTP server or a stdio server. A server with
|
|
300
|
+
* neither cannot be connected, and the connector says so instead of guessing.
|
|
301
|
+
*/
|
|
302
|
+
export function createTransport(
|
|
303
|
+
library: McpClientLibrary,
|
|
304
|
+
config: McpServerConfigLike,
|
|
305
|
+
): McpTransportLike {
|
|
306
|
+
if (typeof config.url === "string" && config.url !== "") {
|
|
307
|
+
return new library.StreamableHttpTransport({
|
|
308
|
+
url: config.url,
|
|
309
|
+
...(config.headers ? { headers: config.headers } : {}),
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
if (typeof config.command === "string" && config.command !== "") {
|
|
313
|
+
return new library.StdioTransport({
|
|
314
|
+
command: config.command,
|
|
315
|
+
...(config.args ? { args: config.args } : {}),
|
|
316
|
+
...(config.env ? { env: config.env } : {}),
|
|
317
|
+
...(config.cwd ? { cwd: config.cwd } : {}),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
throw new Error(
|
|
321
|
+
"the server has neither a url nor a command, so it cannot be connected",
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* The tool of a server, in the shape Pi expects.
|
|
327
|
+
*
|
|
328
|
+
* The tool calls the server through the connection of the connector, and the
|
|
329
|
+
* result of the server becomes the result of the tool.
|
|
330
|
+
*/
|
|
331
|
+
export function createToolDefinition(
|
|
332
|
+
server: RegisteredMcpServerLike,
|
|
333
|
+
tool: McpToolLike,
|
|
334
|
+
getClient: () => McpClientLike,
|
|
335
|
+
isTaken: (candidate: string) => boolean = () => false,
|
|
336
|
+
): McpToolDefinition {
|
|
337
|
+
const name = mcpToolName(server.name, tool.name, isTaken);
|
|
338
|
+
return {
|
|
339
|
+
name,
|
|
340
|
+
label: `${server.name}/${tool.name}`,
|
|
341
|
+
description:
|
|
342
|
+
tool.description?.trim() ||
|
|
343
|
+
`MCP tool ${tool.name} from server ${server.name}`,
|
|
344
|
+
parameters: toParameters(tool.inputSchema),
|
|
345
|
+
exposure: server.config?.exposure ?? "codemode",
|
|
346
|
+
namespace: { name: mcpNamespace(server.name), aliases: [server.name] },
|
|
347
|
+
async execute(
|
|
348
|
+
_toolCallId: string,
|
|
349
|
+
params: Record<string, unknown>,
|
|
350
|
+
signal?: AbortSignal,
|
|
351
|
+
): Promise<McpToolResult> {
|
|
352
|
+
const client = getClient();
|
|
353
|
+
const result = await client.callTool(tool.name, params ?? {}, {
|
|
354
|
+
...(signal ? { signal } : {}),
|
|
355
|
+
...(server.config?.timeout
|
|
356
|
+
? { timeoutMs: server.config.timeout * 1000 }
|
|
357
|
+
: {}),
|
|
358
|
+
});
|
|
359
|
+
return toToolResult(result);
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The secrets of a configuration, removed from a text.
|
|
366
|
+
*
|
|
367
|
+
* The credential of a server travels in the headers of the request, and a
|
|
368
|
+
* server that quotes its own configuration in an error must not put the
|
|
369
|
+
* credential into the log of the harness.
|
|
370
|
+
*
|
|
371
|
+
* @param text The text that may hold a secret
|
|
372
|
+
* @param config The configuration of the server
|
|
373
|
+
* @returns The text without the secrets
|
|
374
|
+
*/
|
|
375
|
+
export function redactConfigSecrets(
|
|
376
|
+
text: string,
|
|
377
|
+
config: McpServerConfigLike | undefined,
|
|
378
|
+
): string {
|
|
379
|
+
let result = text;
|
|
380
|
+
const values = [
|
|
381
|
+
...Object.values(config?.headers ?? {}),
|
|
382
|
+
...Object.values(config?.env ?? {}),
|
|
383
|
+
];
|
|
384
|
+
for (const value of values) {
|
|
385
|
+
if (typeof value !== "string" || value.length < 8) continue;
|
|
386
|
+
result = result.split(value).join("[REDACTED]");
|
|
387
|
+
}
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* The connector of the session.
|
|
393
|
+
*
|
|
394
|
+
* The connector connects the servers that no other connector connected, and
|
|
395
|
+
* it closes its own connections when the session ends.
|
|
396
|
+
*
|
|
397
|
+
* @param api The API of Pi
|
|
398
|
+
* @param options The options of the connector
|
|
399
|
+
* @returns The connector
|
|
400
|
+
*/
|
|
401
|
+
export function createMcpConnector(
|
|
402
|
+
api: McpConnectorApi,
|
|
403
|
+
options: McpConnectorOptions,
|
|
404
|
+
): McpConnector {
|
|
405
|
+
const graceMs = options.graceMs ?? DEFAULT_GRACE_MS;
|
|
406
|
+
const delay = options.delay ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
|
|
407
|
+
const log = options.log ?? ((): void => {});
|
|
408
|
+
const statuses = new Map<string, McpServerStatus>();
|
|
409
|
+
const clients = new Map<string, McpClientLike>();
|
|
410
|
+
|
|
411
|
+
async function connectServer(
|
|
412
|
+
server: RegisteredMcpServerLike,
|
|
413
|
+
): Promise<McpServerStatus> {
|
|
414
|
+
let client: McpClientLike | null = null;
|
|
415
|
+
try {
|
|
416
|
+
if (typeof api.registerTool !== "function") {
|
|
417
|
+
throw new Error(
|
|
418
|
+
"the runtime cannot register tools, so the tools of the server would stay invisible",
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
const library = await options.loadLibrary();
|
|
422
|
+
const transport = createTransport(library, server.config ?? {});
|
|
423
|
+
client = new library.McpClient({
|
|
424
|
+
name: "pi-harness-runtime",
|
|
425
|
+
version: "1.0.0",
|
|
426
|
+
requestTimeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
|
|
427
|
+
});
|
|
428
|
+
await client.connect(transport);
|
|
429
|
+
const tools = await client.listTools();
|
|
430
|
+
const names: string[] = [];
|
|
431
|
+
const taken = new Set<string>();
|
|
432
|
+
for (const tool of tools ?? []) {
|
|
433
|
+
if (!tool || typeof tool.name !== "string") continue;
|
|
434
|
+
const definition = createToolDefinition(
|
|
435
|
+
server,
|
|
436
|
+
tool,
|
|
437
|
+
() => client as McpClientLike,
|
|
438
|
+
(candidate) => taken.has(candidate),
|
|
439
|
+
);
|
|
440
|
+
taken.add(definition.name);
|
|
441
|
+
api.registerTool?.(definition);
|
|
442
|
+
names.push(definition.name);
|
|
443
|
+
}
|
|
444
|
+
clients.set(server.name, client);
|
|
445
|
+
log(`MCP server "${server.name}" connected by the harness (${names.length} tools)`);
|
|
446
|
+
return { state: "connected", tools: names };
|
|
447
|
+
} catch (error) {
|
|
448
|
+
const reason = redactConfigSecrets(
|
|
449
|
+
error instanceof Error ? error.message : String(error),
|
|
450
|
+
server.config,
|
|
451
|
+
);
|
|
452
|
+
try {
|
|
453
|
+
await client?.close();
|
|
454
|
+
} catch {
|
|
455
|
+
// The connection is already broken: the reason is the error.
|
|
456
|
+
}
|
|
457
|
+
log(`MCP server "${server.name}" could not be connected: ${reason}`);
|
|
458
|
+
return { state: "failed", tools: [], reason };
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
return {
|
|
463
|
+
statuses,
|
|
464
|
+
|
|
465
|
+
async connectPending(): Promise<void> {
|
|
466
|
+
const servers = api.getMcpServers?.() ?? [];
|
|
467
|
+
const wanted = servers.filter(
|
|
468
|
+
(server) => server?.name && server.config?.enabled !== false,
|
|
469
|
+
);
|
|
470
|
+
if (wanted.length === 0) return;
|
|
471
|
+
// Another connector may be at work. The wait gives it the time,
|
|
472
|
+
// and its work is visible in the tools of the session.
|
|
473
|
+
await delay(graceMs);
|
|
474
|
+
for (const server of wanted) {
|
|
475
|
+
const known = statuses.get(server.name);
|
|
476
|
+
// A server that was connected is done, and a server that
|
|
477
|
+
// another connector connected belongs to it. A server that
|
|
478
|
+
// failed may be tried again.
|
|
479
|
+
if (known && known.state !== "failed") continue;
|
|
480
|
+
const foreign = serverToolNames(api, server.name);
|
|
481
|
+
if (foreign.length > 0) {
|
|
482
|
+
statuses.set(server.name, {
|
|
483
|
+
state: "skipped",
|
|
484
|
+
tools: foreign,
|
|
485
|
+
reason: "another connector connected the server",
|
|
486
|
+
});
|
|
487
|
+
log(
|
|
488
|
+
`MCP server "${server.name}" was connected by another connector (${foreign.length} tools)`,
|
|
489
|
+
);
|
|
490
|
+
continue;
|
|
491
|
+
}
|
|
492
|
+
statuses.set(server.name, await connectServer(server));
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
async close(): Promise<void> {
|
|
497
|
+
for (const [name, client] of clients) {
|
|
498
|
+
try {
|
|
499
|
+
await client.close();
|
|
500
|
+
} catch {
|
|
501
|
+
// A broken connection needs no closing.
|
|
502
|
+
}
|
|
503
|
+
clients.delete(name);
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
};
|
|
507
|
+
}
|
package/index.ts
CHANGED
|
@@ -48,6 +48,12 @@ import {
|
|
|
48
48
|
} from "./harness/pending-countdown.ts";
|
|
49
49
|
import { endPendingWait, releaseWait } from "./harness/pending-wait.ts";
|
|
50
50
|
import { isChannelDisabled, setChannelDisabled } from "./harness/notification-settings.ts";
|
|
51
|
+
import {
|
|
52
|
+
createMcpConnector,
|
|
53
|
+
type McpClientLibrary,
|
|
54
|
+
type McpConnector,
|
|
55
|
+
type McpConnectorApi,
|
|
56
|
+
} from "./harness/mcp-connector.ts";
|
|
51
57
|
// The Honcho contract lives with the Honcho integration. A type-only import
|
|
52
58
|
// is erased at runtime, so the startup keeps loading the module lazily.
|
|
53
59
|
import type {
|
|
@@ -3463,6 +3469,68 @@ function initConsoleGuard(pi: ExtensionAPI): void {
|
|
|
3463
3469
|
});
|
|
3464
3470
|
}
|
|
3465
3471
|
|
|
3472
|
+
/**
|
|
3473
|
+
* The fallback connector for the MCP servers that extensions register.
|
|
3474
|
+
*
|
|
3475
|
+
* Pi expects the extension that handles `mcp_servers_change` to be the one
|
|
3476
|
+
* that connects the registered servers. The built-in MCP extension of Pi
|
|
3477
|
+
* does that job while it is active; this connector takes over only the
|
|
3478
|
+
* servers that nobody else connected, and the tools of the session are the
|
|
3479
|
+
* evidence of who did what.
|
|
3480
|
+
*
|
|
3481
|
+
* The connector works in the background: the session does not wait for it,
|
|
3482
|
+
* because a server that nobody connected is a rare case and the tools of a
|
|
3483
|
+
* server that is still connecting arrive late anyway.
|
|
3484
|
+
*/
|
|
3485
|
+
function initMcpConnector(pi: ExtensionAPI): void {
|
|
3486
|
+
// The typings of the installed runtime may be older than the event
|
|
3487
|
+
// itself, so the registration uses the structural type of the API.
|
|
3488
|
+
const registrar = pi as unknown as {
|
|
3489
|
+
on: (
|
|
3490
|
+
event: string,
|
|
3491
|
+
handler: (...args: unknown[]) => void | Promise<void>,
|
|
3492
|
+
) => void;
|
|
3493
|
+
};
|
|
3494
|
+
const connector = createMcpConnector(pi as unknown as McpConnectorApi, {
|
|
3495
|
+
loadLibrary: async (): Promise<McpClientLibrary> => {
|
|
3496
|
+
const mod = await import("@earendil-works/pi-mcp");
|
|
3497
|
+
// SAFETY: the package exports the client and the two transports
|
|
3498
|
+
// with these names; the interface describes how the connector
|
|
3499
|
+
// uses them.
|
|
3500
|
+
return mod as unknown as McpClientLibrary;
|
|
3501
|
+
},
|
|
3502
|
+
log: (message: string): void => {
|
|
3503
|
+
logStartup(`[pi-harness] ${message}`);
|
|
3504
|
+
},
|
|
3505
|
+
});
|
|
3506
|
+
mcpConnector = connector;
|
|
3507
|
+
|
|
3508
|
+
// The registration of a server while the extensions load is read with
|
|
3509
|
+
// getMcpServers() on session_start; a later registration fires the
|
|
3510
|
+
// change event. Both paths lead to the same place.
|
|
3511
|
+
pi.on("session_start", () => {
|
|
3512
|
+
void connector.connectPending().catch((error: unknown) => {
|
|
3513
|
+
logStartup(
|
|
3514
|
+
`[pi-harness] the MCP fallback connector failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3515
|
+
);
|
|
3516
|
+
});
|
|
3517
|
+
});
|
|
3518
|
+
|
|
3519
|
+
registrar.on("mcp_servers_change", () => {
|
|
3520
|
+
void connector.connectPending().catch((error: unknown) => {
|
|
3521
|
+
logStartup(
|
|
3522
|
+
`[pi-harness] the MCP fallback connector failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
3523
|
+
);
|
|
3524
|
+
});
|
|
3525
|
+
});
|
|
3526
|
+
|
|
3527
|
+
pi.on("session_shutdown", () => {
|
|
3528
|
+
void connector.close().catch(() => {
|
|
3529
|
+
// A broken connection needs no closing.
|
|
3530
|
+
});
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
|
|
3466
3534
|
// --- honcho-memory: Honcho MCP for peer/user memory via https://mcp.honcho.dev ------
|
|
3467
3535
|
// Registers the Honcho MCP server with Pi's NATIVE MCP support and implements
|
|
3468
3536
|
// the automatic memory lifecycle:
|
|
@@ -3515,6 +3583,22 @@ const HONCHO_MCP_WAIT_MS = 15_000;
|
|
|
3515
3583
|
/** The interval between two checks of the tools of the session. */
|
|
3516
3584
|
const HONCHO_MCP_WAIT_INTERVAL_MS = 500;
|
|
3517
3585
|
|
|
3586
|
+
/**
|
|
3587
|
+
* The connector of the session.
|
|
3588
|
+
*
|
|
3589
|
+
* The startup report of Honcho names the reason a connection failed, so the
|
|
3590
|
+
* report can tell the user what went wrong.
|
|
3591
|
+
*/
|
|
3592
|
+
let mcpConnector: McpConnector | null = null;
|
|
3593
|
+
|
|
3594
|
+
/**
|
|
3595
|
+
* The name of the Honcho MCP server in Pi.
|
|
3596
|
+
*
|
|
3597
|
+
* The integration keeps the name in its own module, which is loaded lazily:
|
|
3598
|
+
* a value import here would load the whole integration at the startup.
|
|
3599
|
+
*/
|
|
3600
|
+
const HONCHO_MCP_SERVER_NAME = "honcho";
|
|
3601
|
+
|
|
3518
3602
|
/**
|
|
3519
3603
|
* Correct the report when the tools of the Honcho server appear.
|
|
3520
3604
|
*
|
|
@@ -3537,9 +3621,17 @@ function watchHonchoMcpTools(pi: ExtensionAPI, honcho: HonchoModule): void {
|
|
|
3537
3621
|
return;
|
|
3538
3622
|
}
|
|
3539
3623
|
if (Date.now() >= deadline) {
|
|
3624
|
+
// The fallback connector knows why the connection failed, and
|
|
3625
|
+
// the reason is more useful than "nobody connected it".
|
|
3626
|
+
const status = mcpConnector?.statuses.get(HONCHO_MCP_SERVER_NAME);
|
|
3627
|
+
const reason = status?.state === "failed" ? status.reason : undefined;
|
|
3540
3628
|
logStartup(
|
|
3541
|
-
|
|
3629
|
+
`[pi-harness] Honcho: no connector connected the MCP server (the model sees no Honcho tools)${reason ? `: ${reason}` : ""}`,
|
|
3542
3630
|
);
|
|
3631
|
+
if (reason) {
|
|
3632
|
+
const report = honcho.honchoMcpReport("registered", reason);
|
|
3633
|
+
addHarnessMessage("Honcho", report.text, report.status, report.details);
|
|
3634
|
+
}
|
|
3543
3635
|
return;
|
|
3544
3636
|
}
|
|
3545
3637
|
const timer = setTimeout(check, HONCHO_MCP_WAIT_INTERVAL_MS);
|
|
@@ -5112,6 +5204,13 @@ export default async function (pi: ExtensionAPI) {
|
|
|
5112
5204
|
// prompt input field. The guard sends it to the harness log instead.
|
|
5113
5205
|
initConsoleGuard(pi);
|
|
5114
5206
|
|
|
5207
|
+
// --- mcp-connector: the fallback for the MCP servers of the extensions ----
|
|
5208
|
+
// The built-in MCP extension of Pi connects the servers that extensions
|
|
5209
|
+
// register. The connector takes over only the servers that nobody else
|
|
5210
|
+
// connected, so the tools of Honcho reach the model even when the
|
|
5211
|
+
// built-in support is disabled or replaced.
|
|
5212
|
+
initMcpConnector(pi);
|
|
5213
|
+
|
|
5115
5214
|
// --- line-voice-queue: Watch for LINE voice commands ----
|
|
5116
5215
|
void initLineVoiceQueue(pi);
|
|
5117
5216
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-harness/two-phase-review",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.466",
|
|
4
4
|
"description": "pi-harness-runtime — two-phase implementation and review workflow (queue review signals, gate the phase, scope the diff)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|