@herbertgao/pi-extensions 2026.9.11 → 2026.9.13

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.
Files changed (192) hide show
  1. package/README.md +4 -4
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
  4. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +8 -0
  5. package/node_modules/@herbertgao/pi-subagents/package.json +1 -1
  6. package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +5 -4
  7. package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +39 -16
  8. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
  9. package/node_modules/@narumitw/pi-btw/README.md +21 -4
  10. package/node_modules/@narumitw/pi-btw/dist/index.ts +1668 -958
  11. package/node_modules/@narumitw/pi-btw/dist/index.ts.map +4 -4
  12. package/node_modules/@narumitw/pi-btw/docs/workflows.md +10 -2
  13. package/node_modules/@narumitw/pi-btw/package.json +1 -1
  14. package/node_modules/@narumitw/pi-btw/src/btw.ts +17 -79
  15. package/node_modules/@narumitw/pi-btw/src/conversation-context.ts +74 -0
  16. package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +196 -7
  17. package/node_modules/@narumitw/pi-btw/src/main-thread-updates.ts +40 -0
  18. package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
  19. package/node_modules/@narumitw/pi-btw/src/settings.ts +49 -0
  20. package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +9 -1
  21. package/node_modules/@narumitw/pi-btw/src/workspace-layout.ts +559 -0
  22. package/node_modules/pi-mcp-adapter/CHANGELOG.md +62 -0
  23. package/node_modules/pi-mcp-adapter/README.md +75 -7
  24. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +193 -0
  25. package/node_modules/pi-mcp-adapter/cli.js +56 -5
  26. package/node_modules/pi-mcp-adapter/commands.ts +96 -5
  27. package/node_modules/pi-mcp-adapter/config.ts +73 -6
  28. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +22 -28
  29. package/node_modules/pi-mcp-adapter/direct-tools.ts +13 -5
  30. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +2 -0
  31. package/node_modules/pi-mcp-adapter/dist/abort.js +36 -0
  32. package/node_modules/pi-mcp-adapter/dist/abort.js.map +1 -0
  33. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +6 -0
  34. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +194 -0
  35. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +1 -0
  36. package/node_modules/pi-mcp-adapter/dist/config.d.ts +5 -0
  37. package/node_modules/pi-mcp-adapter/dist/config.js +75 -6
  38. package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
  39. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +18 -0
  40. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +88 -0
  41. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +1 -0
  42. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +17 -0
  43. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +316 -0
  44. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +1 -0
  45. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +131 -0
  46. package/node_modules/pi-mcp-adapter/dist/errors.js +278 -0
  47. package/node_modules/pi-mcp-adapter/dist/errors.js.map +1 -0
  48. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +8 -0
  49. package/node_modules/pi-mcp-adapter/dist/http-ca.js +88 -0
  50. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +1 -0
  51. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +15 -0
  52. package/node_modules/pi-mcp-adapter/dist/jev-client.js +340 -0
  53. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +1 -0
  54. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +77 -0
  55. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +2 -0
  56. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +1 -0
  57. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +22 -0
  58. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +85 -0
  59. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +1 -0
  60. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +2 -0
  61. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +55 -0
  62. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +1 -0
  63. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +56 -0
  64. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +410 -0
  65. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +1 -0
  66. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +51 -0
  67. package/node_modules/pi-mcp-adapter/dist/logger.js +131 -0
  68. package/node_modules/pi-mcp-adapter/dist/logger.js.map +1 -0
  69. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +26 -0
  70. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +103 -0
  71. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +1 -0
  72. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +118 -0
  73. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +1098 -0
  74. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +1 -0
  75. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +168 -0
  76. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +1117 -0
  77. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +1 -0
  78. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +7 -140
  79. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -1
  80. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +53 -0
  81. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +441 -0
  82. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +1 -0
  83. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +148 -0
  84. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +689 -0
  85. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +1 -0
  86. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +6 -0
  87. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +166 -0
  88. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +1 -0
  89. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +102 -0
  90. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +369 -0
  91. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +1 -0
  92. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +95 -0
  93. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +242 -0
  94. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +1 -0
  95. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +2 -11
  96. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +1 -1
  97. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +6 -0
  98. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +505 -0
  99. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +1 -0
  100. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +10 -0
  101. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +312 -0
  102. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +1 -0
  103. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +13 -0
  104. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +97 -0
  105. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +1 -0
  106. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +17 -0
  107. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +203 -0
  108. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +1 -0
  109. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +11 -0
  110. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +172 -0
  111. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +1 -0
  112. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +157 -0
  113. package/node_modules/pi-mcp-adapter/dist/server-manager.js +1743 -0
  114. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +1 -0
  115. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +34 -0
  116. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +140 -0
  117. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +1 -0
  118. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +26 -0
  119. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +142 -0
  120. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +1 -0
  121. package/node_modules/pi-mcp-adapter/dist/state.d.ts +73 -0
  122. package/node_modules/pi-mcp-adapter/dist/state.js +2 -0
  123. package/node_modules/pi-mcp-adapter/dist/state.js.map +1 -0
  124. package/node_modules/pi-mcp-adapter/dist/types.d.ts +36 -0
  125. package/node_modules/pi-mcp-adapter/dist/types.js +18 -0
  126. package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
  127. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +17 -0
  128. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +219 -0
  129. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +1 -0
  130. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +15 -0
  131. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +85 -0
  132. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +1 -0
  133. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +1 -0
  134. package/node_modules/pi-mcp-adapter/dist/utils.js +13 -0
  135. package/node_modules/pi-mcp-adapter/dist/utils.js.map +1 -1
  136. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +29 -19
  137. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +85 -0
  138. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +34 -0
  139. package/node_modules/pi-mcp-adapter/index.ts +129 -6
  140. package/node_modules/pi-mcp-adapter/init.ts +6 -19
  141. package/node_modules/pi-mcp-adapter/jev-client.ts +273 -0
  142. package/node_modules/pi-mcp-adapter/jev-contracts.ts +53 -0
  143. package/node_modules/pi-mcp-adapter/jev-key-store.ts +79 -0
  144. package/node_modules/pi-mcp-adapter/lifecycle.ts +14 -3
  145. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +7 -142
  146. package/node_modules/pi-mcp-adapter/mcp-code.ts +119 -11
  147. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +4 -0
  148. package/node_modules/pi-mcp-adapter/mcp-references.ts +5 -3
  149. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +5 -0
  150. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +467 -0
  151. package/node_modules/pi-mcp-adapter/metadata-cache.ts +2 -13
  152. package/node_modules/pi-mcp-adapter/namespace-tools.ts +1 -1
  153. package/node_modules/pi-mcp-adapter/package.json +17 -9
  154. package/node_modules/pi-mcp-adapter/proxy-modes.ts +319 -166
  155. package/node_modules/pi-mcp-adapter/request-headers-command.ts +6 -3
  156. package/node_modules/pi-mcp-adapter/search-ranking.ts +38 -7
  157. package/node_modules/pi-mcp-adapter/secure-keyring.ts +170 -0
  158. package/node_modules/pi-mcp-adapter/semantic-search.ts +186 -0
  159. package/node_modules/pi-mcp-adapter/server-manager.ts +293 -50
  160. package/node_modules/pi-mcp-adapter/session-approvals.ts +14 -0
  161. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +2 -0
  162. package/node_modules/pi-mcp-adapter/state.ts +3 -1
  163. package/node_modules/pi-mcp-adapter/tool-approval.ts +26 -4
  164. package/node_modules/pi-mcp-adapter/tool-metadata.ts +6 -14
  165. package/node_modules/pi-mcp-adapter/tool-registrar.ts +8 -6
  166. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +4 -1
  167. package/node_modules/pi-mcp-adapter/types.ts +53 -0
  168. package/node_modules/pi-mcp-adapter/ui-server.ts +17 -9
  169. package/node_modules/pi-mcp-adapter/utils.ts +16 -0
  170. package/node_modules/pi-multi-account/CHANGELOG.md +23 -0
  171. package/node_modules/pi-multi-account/README.md +38 -11
  172. package/node_modules/pi-multi-account/index.ts +371 -96
  173. package/node_modules/pi-multi-account/package.json +5 -4
  174. package/node_modules/pi-multi-account/provider-payload-stream.ts +36 -28
  175. package/node_modules/pi-multi-account/usage.ts +31 -2
  176. package/node_modules/pi-typesafe/README.md +3 -1
  177. package/node_modules/pi-typesafe/dist/auth.d.ts +10 -3
  178. package/node_modules/pi-typesafe/dist/auth.js +13 -7
  179. package/node_modules/pi-typesafe/dist/backends.d.ts +31 -0
  180. package/node_modules/pi-typesafe/dist/backends.js +33 -0
  181. package/node_modules/pi-typesafe/dist/client.d.ts +3 -9
  182. package/node_modules/pi-typesafe/dist/client.js +63 -39
  183. package/node_modules/pi-typesafe/dist/credentials.d.ts +11 -5
  184. package/node_modules/pi-typesafe/dist/credentials.js +15 -8
  185. package/node_modules/pi-typesafe/dist/extension.js +4 -1
  186. package/node_modules/pi-typesafe/dist/index.d.ts +1 -1
  187. package/node_modules/pi-typesafe/dist/index.js +1 -1
  188. package/node_modules/pi-typesafe/dist/login.d.ts +13 -7
  189. package/node_modules/pi-typesafe/dist/login.js +17 -8
  190. package/node_modules/pi-typesafe/dist/schema.js +19 -13
  191. package/node_modules/pi-typesafe/package.json +1 -1
  192. package/package.json +11 -10
@@ -0,0 +1,467 @@
1
+ /**
2
+ * MCP Tasks extension support (io.modelcontextprotocol/tasks, SEP-2663).
3
+ *
4
+ * Built on @modelcontextprotocol/ext-tasks, the official requester-side
5
+ * package. On 2026-07-28 connections the SDK client's wire codec rejects
6
+ * task-shaped traffic (resultType: "task" inbound, tasks/* methods outbound),
7
+ * so ext-tasks requires a host-supplied raw dispatch channel: a way to send
8
+ * JSON-RPC frames on the connection's transport and correlate their responses
9
+ * below the SDK client. RawRequestChannel provides that channel, mirroring
10
+ * the reference integration in the MCP Inspector.
11
+ *
12
+ * The channel attaches to the already-connected transport by chaining its
13
+ * message and close handlers, never replacing the transport object itself.
14
+ * This keeps the transport's class identity and optional surface
15
+ * (hasPerRequestStream, stdio stderr/pid) intact for the SDK's version
16
+ * negotiation probe and per-request-stream cancellation, and it means inbound
17
+ * raw responses pass through an installed trace wrapper before being
18
+ * consumed, so both directions of task traffic appear in /mcp-trace.
19
+ *
20
+ * Enabled per server via `tasks: true`. A task session is only attached when
21
+ * the connected 2026-07-28 server advertises the extension, so non-task
22
+ * servers keep the exact pre-existing call path.
23
+ */
24
+ import type {
25
+ Client,
26
+ CreateMessageRequest,
27
+ CreateMessageResult,
28
+ ElicitRequest,
29
+ ElicitResult,
30
+ JSONRPCMessage,
31
+ JSONRPCRequest,
32
+ Transport,
33
+ } from "@modelcontextprotocol/client";
34
+ import { ProtocolError } from "@modelcontextprotocol/client";
35
+ import {
36
+ createApplicationInputHandler,
37
+ createTaskSessionEndpointId,
38
+ createTaskSessionFromClient,
39
+ DispatchError,
40
+ JsonRpcResponseError,
41
+ resultFromTaskOutcome,
42
+ TaskCancelledError,
43
+ TaskFailedError,
44
+ type ApplicationElicitContentValue,
45
+ type RawClientDispatch,
46
+ type TaskEnabledSession,
47
+ } from "@modelcontextprotocol/ext-tasks/client";
48
+ import type { ServerDefinition } from "./types.ts";
49
+ import { logger } from "./logger.ts";
50
+
51
+ export const TASKS_EXTENSION_ID = "io.modelcontextprotocol/tasks";
52
+
53
+ const RAW_REQUEST_ID_PREFIX = "pi-mcp-tasks-";
54
+
55
+ const DEFAULT_RAW_REQUEST_TIMEOUT_MS = 60_000;
56
+ const LATE_TASK_HANDLE_GRACE_MS = 60_000;
57
+
58
+ type JsonRpcResponseShape = { kind: "result"; result: unknown } | {
59
+ kind: "error";
60
+ error: { code: number; message: string; data?: unknown };
61
+ };
62
+
63
+ interface PendingRawRequest {
64
+ id: string;
65
+ resolve: (response: JsonRpcResponseShape) => void;
66
+ reject: (error: Error) => void;
67
+ state: "pending" | "observing";
68
+ signal?: AbortSignal;
69
+ onAbort?: () => void;
70
+ requestTimer?: ReturnType<typeof setTimeout>;
71
+ observationTimer?: ReturnType<typeof setTimeout>;
72
+ observationController?: AbortController;
73
+ }
74
+
75
+ function abortError(signal: AbortSignal): Error {
76
+ return signal.reason instanceof Error
77
+ ? signal.reason
78
+ : new DOMException("This operation was aborted", "AbortError");
79
+ }
80
+
81
+ function isJsonRecord(value: unknown): value is Record<string, unknown> {
82
+ return value !== null && typeof value === "object" && !Array.isArray(value);
83
+ }
84
+
85
+ /**
86
+ * Raw JSON-RPC request channel chained onto a connected transport. Raw
87
+ * requests use string ids with a reserved prefix, which cannot collide with
88
+ * the SDK's numeric ids; their responses are consumed before the SDK client
89
+ * sees them. All other traffic passes through unchanged.
90
+ *
91
+ * Attach only after Client.connect has installed its transport handlers:
92
+ * attach() reads the current onmessage/onclose (through any wrapper
93
+ * accessors) and chains in front of them.
94
+ */
95
+ export class RawRequestChannel {
96
+ private readonly transport: Transport;
97
+ private readonly pending = new Map<string, PendingRawRequest>();
98
+ private requestCounter = 0;
99
+ private readonly defaultTimeoutMs: number;
100
+ private attached = false;
101
+
102
+ constructor(transport: Transport, defaultTimeoutMs?: number) {
103
+ this.transport = transport;
104
+ this.defaultTimeoutMs = defaultTimeoutMs ?? DEFAULT_RAW_REQUEST_TIMEOUT_MS;
105
+ }
106
+
107
+ attach(): void {
108
+ if (this.attached) return;
109
+ this.attached = true;
110
+ const previousOnMessage = this.transport.onmessage;
111
+ this.transport.onmessage = (message, extra) => {
112
+ if (this.consumeRawResponse(message)) return;
113
+ previousOnMessage?.(message, extra);
114
+ };
115
+ const previousOnClose = this.transport.onclose;
116
+ this.transport.onclose = () => {
117
+ this.rejectAll("MCP connection closed");
118
+ previousOnClose?.();
119
+ };
120
+ }
121
+
122
+ /** Sends a raw JSON-RPC request and resolves with its correlated response. */
123
+ rawDispatch: RawClientDispatch = (request, options) => {
124
+ if (!isJsonRecord(request) || typeof request.method !== "string") {
125
+ return Promise.reject(new Error("Raw MCP request must be a JSON object with a string method"));
126
+ }
127
+ const params = request.params;
128
+ if (params !== undefined && !isJsonRecord(params)) {
129
+ return Promise.reject(new Error("Raw MCP request params must be a JSON object"));
130
+ }
131
+ const signal = options?.signal;
132
+ if (signal?.aborted) return Promise.reject(abortError(signal));
133
+
134
+ const id = `${RAW_REQUEST_ID_PREFIX}${++this.requestCounter}`;
135
+ const message = {
136
+ jsonrpc: "2.0",
137
+ id,
138
+ method: request.method,
139
+ ...(params === undefined ? {} : { params }),
140
+ } as unknown as JSONRPCRequest;
141
+ const timeoutMs = options?.context?.requestTimeoutMs ?? this.defaultTimeoutMs;
142
+
143
+ return new Promise<JsonRpcResponseShape>((resolve, reject) => {
144
+ const entry: PendingRawRequest = {
145
+ id,
146
+ resolve,
147
+ reject,
148
+ state: "pending",
149
+ ...(signal === undefined ? {} : { signal }),
150
+ ...(message.method === "tools/call" ? { observationController: new AbortController() } : {}),
151
+ };
152
+ entry.requestTimer = setTimeout(() => {
153
+ this.terminateLocalWait(entry, new Error(`MCP task request "${message.method}" timed out after ${timeoutMs}ms`));
154
+ }, timeoutMs);
155
+ this.pending.set(id, entry);
156
+ if (signal) {
157
+ entry.onAbort = () => {
158
+ this.terminateLocalWait(entry, abortError(signal));
159
+ };
160
+ signal.addEventListener("abort", entry.onAbort, { once: true });
161
+ }
162
+ const fail = (error: unknown) => {
163
+ if (this.pending.get(id) !== entry) return;
164
+ const wasPending = entry.state === "pending";
165
+ this.finishRequest(entry, true);
166
+ if (wasPending) reject(error instanceof Error ? error : new Error(String(error)));
167
+ };
168
+ // ext-tasks supplies the SEP-2663 Mcp-Name routing header (and any
169
+ // host headers) via context.headers. A task-producing tools/call owns
170
+ // its transport observation independently from the caller's wait.
171
+ try {
172
+ Promise.resolve(this.transport.send(message, {
173
+ ...(options?.context?.headers === undefined ? {} : { headers: options.context.headers }),
174
+ ...(entry.observationController !== undefined
175
+ ? { requestSignal: entry.observationController.signal }
176
+ : signal === undefined ? {} : { requestSignal: signal }),
177
+ })).catch(fail);
178
+ } catch (error) {
179
+ fail(error);
180
+ }
181
+ }) as ReturnType<RawClientDispatch>;
182
+ };
183
+
184
+ private consumeRawResponse(message: JSONRPCMessage): boolean {
185
+ if (!("id" in message) || typeof message.id !== "string") return false;
186
+ if (!message.id.startsWith(RAW_REQUEST_ID_PREFIX)) return false;
187
+ // A server request may choose any string ID, including our client-side
188
+ // prefix. Method-bearing frames still belong to the SDK request handler.
189
+ if ("method" in message) return false;
190
+ const entry = this.pending.get(message.id);
191
+ if (!entry) return true; // ours, but already completed or its bounded observation expired
192
+ const wasObserving = entry.state === "observing";
193
+ this.finishRequest(entry, true);
194
+ if (wasObserving) {
195
+ this.cancelLateTask(message);
196
+ return true;
197
+ }
198
+ if ("error" in message) {
199
+ const { code, message: errorMessage, data } = message.error;
200
+ entry.resolve({ kind: "error", error: { code, message: errorMessage, ...(data === undefined ? {} : { data }) } });
201
+ } else if ("result" in message) {
202
+ entry.resolve({ kind: "result", result: message.result });
203
+ } else {
204
+ entry.reject(new Error("MCP task response frame carried neither result nor error"));
205
+ }
206
+ return true;
207
+ }
208
+
209
+ private terminateLocalWait(entry: PendingRawRequest, error: Error): void {
210
+ if (this.pending.get(entry.id) !== entry || entry.state !== "pending") return;
211
+ if (entry.observationController === undefined) {
212
+ this.finishRequest(entry, false);
213
+ } else {
214
+ entry.state = "observing";
215
+ this.clearLocalWait(entry);
216
+ entry.observationTimer = setTimeout(() => {
217
+ this.finishRequest(entry, true);
218
+ }, LATE_TASK_HANDLE_GRACE_MS);
219
+ }
220
+ entry.reject(error);
221
+ }
222
+
223
+ private clearLocalWait(entry: PendingRawRequest): void {
224
+ if (entry.requestTimer !== undefined) clearTimeout(entry.requestTimer);
225
+ delete entry.requestTimer;
226
+ if (entry.signal !== undefined && entry.onAbort !== undefined) {
227
+ entry.signal.removeEventListener("abort", entry.onAbort);
228
+ }
229
+ delete entry.onAbort;
230
+ }
231
+
232
+ private finishRequest(entry: PendingRawRequest, abortObservation: boolean): void {
233
+ if (this.pending.get(entry.id) !== entry) return;
234
+ this.clearLocalWait(entry);
235
+ if (entry.observationTimer !== undefined) clearTimeout(entry.observationTimer);
236
+ delete entry.observationTimer;
237
+ this.pending.delete(entry.id);
238
+ if (abortObservation) entry.observationController?.abort();
239
+ }
240
+
241
+ private cancelLateTask(message: JSONRPCMessage): void {
242
+ if (!("result" in message) || !isJsonRecord(message.result)) return;
243
+ if (message.result.resultType !== "task" || typeof message.result.taskId !== "string") return;
244
+ const taskId = message.result.taskId;
245
+ void this.rawDispatch(
246
+ { method: "tasks/cancel", params: { taskId } },
247
+ { context: { headers: { "Mcp-Name": taskId } } },
248
+ ).catch(() => {});
249
+ }
250
+
251
+ rejectAll(reason: string): void {
252
+ const entries = [...this.pending.values()];
253
+ for (const entry of entries) {
254
+ const wasPending = entry.state === "pending";
255
+ this.finishRequest(entry, true);
256
+ if (wasPending) entry.reject(new Error(reason));
257
+ }
258
+ }
259
+ }
260
+
261
+ /**
262
+ * Whether a connected 2026-07-28 server advertises the tasks extension.
263
+ * ext-tasks requires the exact empty-object declaration; anything else
264
+ * downgrades the session, so mirror its check here.
265
+ *
266
+ * Legacy (2025-11-25) task servers are intentionally out of scope: driving
267
+ * their opt-in `task` parameter requires per-tool taskSupport declarations,
268
+ * which this integration does not supply.
269
+ */
270
+ export function serverAdvertisesTasks(client: Client): boolean {
271
+ if (client.getProtocolEra?.() !== "modern") return false;
272
+ const capabilities = client.getServerCapabilities();
273
+ const extension = (capabilities?.extensions as Record<string, unknown> | undefined)?.[TASKS_EXTENSION_ID];
274
+ return isJsonRecord(extension) && Object.keys(extension).length === 0;
275
+ }
276
+
277
+ /** Missing-handler errors carry the SDK's capability shape so call sites can classify them. */
278
+ function capabilityNotSupportedError(serverName: string, method: string, inputKey: string | undefined): Error {
279
+ const error = new Error(
280
+ `MCP server ${serverName} requested ${method} during a task, but this session has no handler for it`,
281
+ );
282
+ Object.assign(error, {
283
+ code: "CAPABILITY_NOT_SUPPORTED",
284
+ data: { key: inputKey ?? "unknown", method },
285
+ });
286
+ return error;
287
+ }
288
+
289
+ export interface AttachTaskSessionOptions {
290
+ client: Client;
291
+ serverName: string;
292
+ definition: ServerDefinition;
293
+ transport: Transport;
294
+ requestTimeoutMs?: number | undefined;
295
+ clientInfo: { name: string; version: string };
296
+ clientCapabilities: Record<string, unknown>;
297
+ onElicitation?: (request: ElicitRequest, signal?: AbortSignal) => Promise<ElicitResult>;
298
+ onSampling?: (request: CreateMessageRequest, signal?: AbortSignal) => Promise<CreateMessageResult>;
299
+ }
300
+
301
+ export interface TaskSessionAttachment {
302
+ session: TaskEnabledSession;
303
+ channel: RawRequestChannel;
304
+ }
305
+
306
+ /**
307
+ * Attaches an ext-tasks requester session to a connected client when the
308
+ * server advertises task support. Returns undefined otherwise, leaving the
309
+ * plain callTool path untouched.
310
+ */
311
+ export async function attachTaskSession(
312
+ options: AttachTaskSessionOptions,
313
+ ): Promise<TaskSessionAttachment | undefined> {
314
+ const { client, serverName, definition } = options;
315
+ if (!serverAdvertisesTasks(client)) return undefined;
316
+ const protocolVersion = client.getNegotiatedProtocolVersion?.();
317
+ if (protocolVersion === undefined) return undefined;
318
+
319
+ const endpointId = await createTaskSessionEndpointId("pi-mcp-adapter", {
320
+ server: serverName,
321
+ ...(definition.command !== undefined
322
+ ? { transport: { type: "stdio", command: definition.command, args: definition.args ?? [] } }
323
+ : definition.url !== undefined
324
+ ? { transport: { type: "http", url: definition.url } }
325
+ : { transport: { type: "unix-socket", socket: definition.socket ?? null } }),
326
+ });
327
+
328
+ const onInputRequest = createApplicationInputHandler({
329
+ elicitation: async (request, context) => {
330
+ if (options.onElicitation === undefined) {
331
+ throw capabilityNotSupportedError(serverName, "elicitation/create", context.inputId);
332
+ }
333
+ const result = await options.onElicitation(
334
+ { method: "elicitation/create", params: request.params } as unknown as ElicitRequest,
335
+ context.signal,
336
+ );
337
+ return {
338
+ action: result.action,
339
+ ...(result.content === undefined
340
+ ? {}
341
+ : { content: result.content as Readonly<Record<string, ApplicationElicitContentValue>> }),
342
+ };
343
+ },
344
+ sampling: async (request, context) => {
345
+ if (options.onSampling === undefined) {
346
+ throw capabilityNotSupportedError(serverName, "sampling/createMessage", context.inputId);
347
+ }
348
+ const result = await options.onSampling(
349
+ { method: "sampling/createMessage", params: request.params } as unknown as CreateMessageRequest,
350
+ context.signal,
351
+ );
352
+ return {
353
+ model: result.model,
354
+ role: result.role,
355
+ content: result.content as never,
356
+ };
357
+ },
358
+ roots: async () => ({ roots: [] }),
359
+ });
360
+
361
+ const channel = new RawRequestChannel(options.transport, options.requestTimeoutMs);
362
+ channel.attach();
363
+ const session = createTaskSessionFromClient(client, {
364
+ endpointId,
365
+ rawDispatch: channel.rawDispatch,
366
+ v2RequestFraming: {
367
+ protocolVersion,
368
+ clientInfo: options.clientInfo,
369
+ clientCapabilities: options.clientCapabilities as never,
370
+ },
371
+ // Tool declarations only add per-tool taskSupport hints; the adapter's
372
+ // cached tools/list is not threaded through here, and a miss is harmless.
373
+ tools: { currentTool: () => undefined },
374
+ onInputRequest,
375
+ onError: (error) => logger.warn(`ext-tasks background error for ${serverName}: ${String(error)}`),
376
+ });
377
+ // A downgraded session (server capability mismatch) would silently route
378
+ // plain tool calls through the generic request path, skipping callTool's
379
+ // output-schema validation. Refuse it and keep the plain path instead.
380
+ if (!session.capabilities.execution) {
381
+ await session.close().catch(() => {});
382
+ channel.rejectAll("Task session downgraded");
383
+ return undefined;
384
+ }
385
+ return { session, channel };
386
+ }
387
+
388
+ export interface TaskToolCallOptions {
389
+ name: string;
390
+ args: Record<string, unknown>;
391
+ meta?: Record<string, unknown> | undefined;
392
+ signal?: AbortSignal | undefined;
393
+ requestTimeoutMs?: number | undefined;
394
+ }
395
+
396
+ /**
397
+ * Preserves error-shape parity with Client.callTool: JSON-RPC failures —
398
+ * immediate (JsonRpcResponseError) or terminal task errors (TaskFailedError
399
+ * with a code) — become the typed ProtocolError subclass for their code, so
400
+ * call-site handling (session recovery, URL elicitation) keeps working.
401
+ * Local failures rethrow their original cause instead of being relabeled.
402
+ */
403
+ function toCallToolError(error: unknown, signal: AbortSignal | undefined): unknown {
404
+ if (error instanceof TaskCancelledError && signal?.aborted === true) {
405
+ return abortError(signal);
406
+ }
407
+ if (error instanceof JsonRpcResponseError) {
408
+ return ProtocolError.fromError(error.code, error.message, error.data);
409
+ }
410
+ if (error instanceof TaskFailedError && error.code !== undefined) {
411
+ return ProtocolError.fromError(error.code, error.message, error.data);
412
+ }
413
+ if (error instanceof DispatchError) {
414
+ return error.cause ?? error;
415
+ }
416
+ return error;
417
+ }
418
+
419
+ /**
420
+ * Calls a tool through a task session and blocks until settlement, preserving
421
+ * the plain callTool contract: an immediate result returns as-is, a
422
+ * task-backed execution is polled to completion, a failed task throws the
423
+ * underlying JSON-RPC error, and aborting cancels the remote task.
424
+ */
425
+ export async function callToolViaTaskSession(
426
+ session: TaskEnabledSession,
427
+ options: TaskToolCallOptions,
428
+ ): Promise<Record<string, unknown>> {
429
+ const { signal } = options;
430
+ let execution;
431
+ try {
432
+ execution = await session.callTool(options.name, options.args as never, {
433
+ ...(options.meta === undefined ? {} : { metadata: options.meta as never }),
434
+ ...(signal === undefined ? {} : { signal }),
435
+ ...(options.requestTimeoutMs === undefined ? {} : { requestTimeoutMs: options.requestTimeoutMs }),
436
+ });
437
+ } catch (error) {
438
+ throw toCallToolError(error, signal);
439
+ }
440
+ let onAbort: (() => void) | undefined;
441
+ if (signal !== undefined && execution.kind === "task") {
442
+ // settle({ signal }) only stops waiting locally; propagate the abort as a
443
+ // cooperative remote cancellation so the server can stop the work. The
444
+ // signal may have aborted while callTool was resolving, so fire directly
445
+ // for an abort the listener would miss.
446
+ onAbort = () => {
447
+ void execution.cancel().catch(() => {});
448
+ };
449
+ if (signal.aborted) onAbort();
450
+ else signal.addEventListener("abort", onAbort, { once: true });
451
+ }
452
+ try {
453
+ const settlement = await execution.settle(signal === undefined ? {} : { signal });
454
+ const result = resultFromTaskOutcome(settlement.outcome);
455
+ if (!isJsonRecord(result)) {
456
+ throw new Error(`Task-backed tool ${options.name} settled with a non-object result`);
457
+ }
458
+ // Match Client.callTool's lifted shape, which strips the wire-only discriminator.
459
+ const { resultType: _resultType, ...lifted } = result;
460
+ return lifted;
461
+ } catch (error) {
462
+ throw toCallToolError(error, signal);
463
+ } finally {
464
+ if (signal !== undefined && onAbort !== undefined) signal.removeEventListener("abort", onAbort);
465
+ await execution.close().catch(() => {});
466
+ }
467
+ }
@@ -20,7 +20,7 @@ import type {
20
20
  ToolMetadata,
21
21
  PromptMetadata,
22
22
  } from "./types.ts";
23
- import { createToolSelectorCandidateIndex, formatPromptCommandName, formatToolName, getToolNameCandidates, isServerDisabled, isToolAllowed, resolveToolPrefix, type ToolPrefix, type ToolSelectorCandidateIndex } from "./types.ts";
23
+ import { createToolSelectorCandidateIndex, formatPromptCommandName, formatToolName, getToolNameCandidates, isServerDisabled, isToolAllowed, resolveToolPrefix, resolveUniqueNameOwnership, type ToolPrefix, type ToolSelectorCandidateIndex } from "./types.ts";
24
24
  import { resourceNameToToolName } from "./resource-tools.ts";
25
25
  import {
26
26
  extractToolUiStreamMode,
@@ -202,7 +202,6 @@ export function reconstructToolMetadata(
202
202
  sharedSelectorCandidateIndex?: ToolSelectorCandidateIndex,
203
203
  ): ToolMetadata[] {
204
204
  const metadata: ToolMetadata[] = [];
205
- const seenNames = new Set<string>();
206
205
  const effectivePrefix = resolveToolPrefix(definition, prefix);
207
206
  const hasToolFilters =
208
207
  (Array.isArray(definition.includeTools) && definition.includeTools.length > 0) ||
@@ -223,11 +222,6 @@ export function reconstructToolMetadata(
223
222
  }
224
223
 
225
224
  const name = formatToolName(tool.name, serverName, effectivePrefix);
226
- if (seenNames.has(name)) {
227
- continue;
228
- }
229
- seenNames.add(name);
230
-
231
225
  metadata.push({
232
226
  name,
233
227
  originalName: tool.name,
@@ -249,11 +243,6 @@ export function reconstructToolMetadata(
249
243
  }
250
244
 
251
245
  const name = formatToolName(baseName, serverName, effectivePrefix);
252
- if (seenNames.has(name)) {
253
- continue;
254
- }
255
- seenNames.add(name);
256
-
257
246
  metadata.push({
258
247
  name,
259
248
  originalName: baseName,
@@ -263,7 +252,7 @@ export function reconstructToolMetadata(
263
252
  }
264
253
  }
265
254
 
266
- return metadata;
255
+ return resolveUniqueNameOwnership(metadata, (tool) => tool.name).unique;
267
256
  }
268
257
 
269
258
  export function createCachedToolSelectorCandidateIndex(
@@ -77,7 +77,7 @@ function resolveNamespaceProxyTools(
77
77
  existingDirectNames: Set<string>,
78
78
  unavailableServers: ReadonlySet<string>,
79
79
  ): NamespaceProxySpec[] {
80
- if (!config || !cache) return [];
80
+ if (!config || !cache || config.settings?.namespaceProxyTools === false) return [];
81
81
  return filterCollidingNamespaceProxyTools(
82
82
  Object.keys(config.mcpServers)
83
83
  .map((serverName) => namespaceProxyCandidate(config, cache, envOverride, existingDirectNames, serverName))
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mcp-adapter",
3
- "version": "2.34.0",
3
+ "version": "2.36.0",
4
4
  "description": "MCP (Model Context Protocol) adapter extension for Pi coding agent",
5
5
  "type": "module",
6
6
  "types": "./index.ts",
@@ -71,9 +71,6 @@
71
71
  "extensions": [
72
72
  "./index.ts"
73
73
  ],
74
- "skills": [
75
- "./skills"
76
- ],
77
74
  "video": "https://github.com/nicobailon/pi-mcp-adapter/raw/refs/heads/main/pi-mcp.mp4"
78
75
  },
79
76
  "files": [
@@ -111,6 +108,7 @@
111
108
  "claude-plugin-loader.ts",
112
109
  "package-mcp-loader.ts",
113
110
  "server-manager.ts",
111
+ "bearer-command-resolver.ts",
114
112
  "http-ca.ts",
115
113
  "request-headers-command.ts",
116
114
  "unix-socket-transport.ts",
@@ -142,6 +140,13 @@
142
140
  "oauth.ts",
143
141
  "mcp-auth.ts",
144
142
  "mcp-bearer-store.ts",
143
+ "secure-keyring.ts",
144
+ "jev-contracts.ts",
145
+ "jev-key-store.ts",
146
+ "jev-client.ts",
147
+ "semantic-search.ts",
148
+ "examples/jev-semantic-filter.mjs",
149
+ "examples/jev-accessibility-loop.mjs",
145
150
  "mcp-keyring-helper.cjs",
146
151
  "mcp-oauth-provider.ts",
147
152
  "mcp-callback-server.ts",
@@ -150,6 +155,7 @@
150
155
  "mcp-panel.ts",
151
156
  "mcp-panel-theme.ts",
152
157
  "panel-keys.ts",
158
+ "mcp-tasks.ts",
153
159
  "mcp-trace.ts",
154
160
  "logger.ts",
155
161
  "errors.ts",
@@ -165,19 +171,21 @@
165
171
  "@modelcontextprotocol/client": "2.0.0",
166
172
  "@modelcontextprotocol/core": "2.0.0",
167
173
  "@modelcontextprotocol/ext-apps": "^1.2.2",
174
+ "@modelcontextprotocol/ext-tasks": "^0.1.0",
168
175
  "@napi-rs/keyring": "^1.3.0",
176
+ "@typesafe-ai/sdk": "0.6.0",
169
177
  "ajv": "^8.17.1",
170
178
  "ajv-formats": "^3.0.1",
171
179
  "cross-spawn": "^7.0.6",
172
180
  "open": "^10.2.0",
173
- "recheck": "^4.5.0",
181
+ "recheck": "4.6.0-beta.3",
174
182
  "smol-toml": "^1.6.1",
175
183
  "strip-json-comments": "^5.0.3",
176
184
  "undici": "^6.28.1",
177
185
  "zod": "^3.25.0 || ^4.0.0"
178
186
  },
179
187
  "peerDependencies": {
180
- "@earendil-works/pi-ai": "^0.84.1 || ^0.85.0",
188
+ "@earendil-works/pi-ai": "^0.84.1 || ^0.85.0 || ^0.86.0",
181
189
  "@earendil-works/pi-tui": "*",
182
190
  "typebox": "*",
183
191
  "zod": "^3.25.0 || ^4.0.0"
@@ -194,9 +202,9 @@
194
202
  }
195
203
  },
196
204
  "devDependencies": {
197
- "@earendil-works/pi-ai": "0.84.1",
198
- "@earendil-works/pi-coding-agent": "0.84.1",
199
- "@earendil-works/pi-tui": "0.84.1",
205
+ "@earendil-works/pi-ai": "0.86.0",
206
+ "@earendil-works/pi-coding-agent": "0.86.0",
207
+ "@earendil-works/pi-tui": "0.86.0",
200
208
  "@modelcontextprotocol/conformance": "0.1.16",
201
209
  "@types/bun": "^1.0.0",
202
210
  "@types/cross-spawn": "6.0.6",