sphica 0.6.63 → 0.6.65

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://anthropic.com/claude-code/plugin.schema.json",
3
3
  "name": "sphica",
4
- "version": "0.6.63",
4
+ "version": "0.6.65",
5
5
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
6
6
  "author": {
7
7
  "name": "iroha924",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.63",
3
+ "version": "0.6.65",
4
4
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
5
5
  "author": {
6
6
  "name": "iroha924",
@@ -10,7 +10,7 @@ This file is generated by `node scripts/third-party-notices.mjs`. Do not edit it
10
10
  | @clack/core | 1.5.1 | MIT |
11
11
  | @clack/prompts | 1.8.1 | MIT |
12
12
  | @hono/node-server | 2.1.1 | MIT |
13
- | @modelcontextprotocol/sdk | 1.31.0 | MIT |
13
+ | @modelcontextprotocol/sdk | 1.32.1 | MIT |
14
14
  | @stricli/core | 1.3.0 | Apache-2.0 |
15
15
  | accepts | 2.0.0 | MIT |
16
16
  | ajv | 8.20.0 | MIT |
@@ -56,7 +56,7 @@ This file is generated by `node scripts/third-party-notices.mjs`. Do not edit it
56
56
  | gopd | 1.2.0 | MIT |
57
57
  | has-symbols | 1.1.0 | MIT |
58
58
  | hasown | 2.0.4 | MIT |
59
- | hono | 4.13.8 | MIT |
59
+ | hono | 4.13.13 | MIT |
60
60
  | http-errors | 2.0.1 | MIT |
61
61
  | iconv-lite | 0.7.3 | MIT |
62
62
  | inherits | 2.0.4 | ISC |
@@ -174,7 +174,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
174
174
  SOFTWARE.
175
175
  ```
176
176
 
177
- ## @modelcontextprotocol/sdk 1.31.0
177
+ ## @modelcontextprotocol/sdk 1.32.1
178
178
 
179
179
  SPDX: MIT
180
180
  Source: https://github.com/modelcontextprotocol/typescript-sdk
@@ -1726,7 +1726,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1726
1726
  SOFTWARE.
1727
1727
  ```
1728
1728
 
1729
- ## hono 4.13.8
1729
+ ## hono 4.13.13
1730
1730
 
1731
1731
  SPDX: MIT
1732
1732
  Source: https://github.com/honojs/hono
package/dist/capture.js CHANGED
@@ -46,6 +46,9 @@ function codexThread(input) {
46
46
  var ownThread = (input, thread) => Boolean(input.session_id) && thread?.id === input.session_id && thread?.threadSource === "user";
47
47
  var childThread = (input, thread) => input.session_id && thread?.threadSource === "subagent" && thread.parent === input.session_id && thread.id !== null && thread.id !== input.session_id && /^[\x21-\x7e]{1,200}$/.test(thread.id) ? thread.id : null;
48
48
 
49
+ // server/src/db-write.ts
50
+ import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
51
+
49
52
  // server/node_modules/kysely/dist/util/object-utils.js
50
53
  function isUndefined(obj) {
51
54
  return typeof obj === "undefined" || obj === undefined;
@@ -11693,7 +11696,6 @@ function sqliteCode(e) {
11693
11696
  }
11694
11697
 
11695
11698
  // server/src/db-write.ts
11696
- import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
11697
11699
  var ddl = null;
11698
11700
  var DDL = () => ddl ??= new Set([
11699
11701
  "SQLITE_ALTER_TABLE",
@@ -12403,7 +12405,7 @@ async function closeTurn(dir, turn, root) {
12403
12405
  return () => {
12404
12406
  if (newestTurn(readStarts(dir)) !== turn || JSON.stringify(readStart(startFile(dir, turn))) !== JSON.stringify(own))
12405
12407
  return [];
12406
- writeStart(dir, { ...own, ...now ?? {}, running: false });
12408
+ writeStart(dir, { ...own, ...now, running: false });
12407
12409
  return now ? changed(root, before, now) : [];
12408
12410
  };
12409
12411
  }
package/dist/cli.js CHANGED
@@ -5231,6 +5231,9 @@ function codexThread(input) {
5231
5231
  var ownThread = (input, thread) => Boolean(input.session_id) && thread?.id === input.session_id && thread?.threadSource === "user";
5232
5232
  var childThread = (input, thread) => input.session_id && thread?.threadSource === "subagent" && thread.parent === input.session_id && thread.id !== null && thread.id !== input.session_id && /^[\x21-\x7e]{1,200}$/.test(thread.id) ? thread.id : null;
5233
5233
 
5234
+ // server/src/db-write.ts
5235
+ import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
5236
+
5234
5237
  // server/node_modules/kysely/dist/util/object-utils.js
5235
5238
  function isUndefined(obj) {
5236
5239
  return typeof obj === "undefined" || obj === undefined;
@@ -16073,7 +16076,6 @@ function sqliteCode(e) {
16073
16076
  }
16074
16077
 
16075
16078
  // server/src/db-write.ts
16076
- import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
16077
16079
  var ddl = null;
16078
16080
  var DDL = () => ddl ??= new Set([
16079
16081
  "SQLITE_ALTER_TABLE",
@@ -16925,7 +16927,7 @@ async function closeTurn(dir, turn, root) {
16925
16927
  return () => {
16926
16928
  if (newestTurn(readStarts(dir)) !== turn || JSON.stringify(readStart(startFile(dir, turn))) !== JSON.stringify(own))
16927
16929
  return [];
16928
- writeStart(dir, { ...own, ...now ?? {}, running: false });
16930
+ writeStart(dir, { ...own, ...now, running: false });
16929
16931
  return now ? changed(root, before, now) : [];
16930
16932
  };
16931
16933
  }
package/dist/deliver.js CHANGED
@@ -11124,6 +11124,9 @@ function codexThread(input) {
11124
11124
  var ownThread = (input, thread) => Boolean(input.session_id) && thread?.id === input.session_id && thread?.threadSource === "user";
11125
11125
  var childThread = (input, thread) => input.session_id && thread?.threadSource === "subagent" && thread.parent === input.session_id && thread.id !== null && thread.id !== input.session_id && /^[\x21-\x7e]{1,200}$/.test(thread.id) ? thread.id : null;
11126
11126
 
11127
+ // server/src/db-write.ts
11128
+ import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
11129
+
11127
11130
  // server/src/kysely-node-sqlite.ts
11128
11131
  var plain = (row) => {
11129
11132
  const out = {};
@@ -11791,7 +11794,6 @@ function byUnit(rows) {
11791
11794
  }
11792
11795
 
11793
11796
  // server/src/db-write.ts
11794
- import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
11795
11797
  var ddl = null;
11796
11798
  var DDL = () => ddl ??= new Set([
11797
11799
  "SQLITE_ALTER_TABLE",
@@ -12498,7 +12500,7 @@ async function closeTurn(dir, turn, root) {
12498
12500
  return () => {
12499
12501
  if (newestTurn(readStarts(dir)) !== turn || JSON.stringify(readStart(startFile(dir, turn))) !== JSON.stringify(own))
12500
12502
  return [];
12501
- writeStart(dir, { ...own, ...now ?? {}, running: false });
12503
+ writeStart(dir, { ...own, ...now, running: false });
12502
12504
  return now ? changed(root, before, now) : [];
12503
12505
  };
12504
12506
  }
@@ -13127,6 +13129,10 @@ if (process.argv[1] && /capture\.(ts|js)$/.test(process.argv[1])) {
13127
13129
  main().catch(() => {});
13128
13130
  }
13129
13131
 
13132
+ // server/src/review-bridge.ts
13133
+ import fs9 from "node:fs";
13134
+ import path10 from "node:path";
13135
+
13130
13136
  // server/src/reply-budget.ts
13131
13137
  var READ_BUDGET = 32 * 1024;
13132
13138
 
@@ -13275,8 +13281,6 @@ async function selectForReview(db, projectId2, files) {
13275
13281
  }
13276
13282
 
13277
13283
  // server/src/review-bridge.ts
13278
- import fs9 from "node:fs";
13279
- import path10 from "node:path";
13280
13284
  var NAME = /^[\w.:/-]{1,100}$/;
13281
13285
  var MAX_DIFF = 4 * 1024 * 1024;
13282
13286
  var DIFF_DEADLINE = 5000;
@@ -32522,6 +32522,9 @@ class Protocol {
32522
32522
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
32523
32523
  const handleTaskResult = async () => {
32524
32524
  const taskId = request.params.taskId;
32525
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
32526
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
32527
+ }
32525
32528
  if (this._taskMessageQueue) {
32526
32529
  let queuedMessage;
32527
32530
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -32552,12 +32555,12 @@ class Protocol {
32552
32555
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
32553
32556
  }
32554
32557
  if (!isTerminal(task.status)) {
32555
- await this._waitForTaskUpdate(taskId, extra.signal);
32558
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
32556
32559
  return await handleTaskResult();
32557
32560
  }
32558
32561
  if (isTerminal(task.status)) {
32559
32562
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
32560
- this._clearTaskQueue(taskId);
32563
+ this._clearTaskQueue(taskId, extra.sessionId);
32561
32564
  return {
32562
32565
  ...result,
32563
32566
  _meta: {
@@ -32594,7 +32597,7 @@ class Protocol {
32594
32597
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
32595
32598
  }
32596
32599
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
32597
- this._clearTaskQueue(request.params.taskId);
32600
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
32598
32601
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
32599
32602
  if (!cancelledTask) {
32600
32603
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -32717,6 +32720,19 @@ class Protocol {
32717
32720
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
32718
32721
  const capturedTransport = this._transport;
32719
32722
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
32723
+ const sessionId = capturedTransport?.sessionId;
32724
+ const store = this._taskStore;
32725
+ let relatedTaskFound = true;
32726
+ let relatedTaskLookup;
32727
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== undefined) {
32728
+ relatedTaskFound = false;
32729
+ relatedTaskLookup = (async () => {
32730
+ if (!await store.getTask(relatedTaskId, sessionId)) {
32731
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
32732
+ }
32733
+ relatedTaskFound = true;
32734
+ })();
32735
+ }
32720
32736
  if (handler === undefined) {
32721
32737
  const errorResponse = {
32722
32738
  jsonrpc: "2.0",
@@ -32726,7 +32742,10 @@ class Protocol {
32726
32742
  message: "Method not found"
32727
32743
  }
32728
32744
  };
32729
- if (relatedTaskId && this._taskMessageQueue) {
32745
+ if (relatedTaskId && relatedTaskLookup) {
32746
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
32747
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error62) => this._onerror(new Error(`Failed to send an error response: ${error62}`)));
32748
+ } else if (relatedTaskId && this._taskMessageQueue) {
32730
32749
  this._enqueueTaskMessage(relatedTaskId, {
32731
32750
  type: "error",
32732
32751
  message: errorResponse,
@@ -32777,7 +32796,10 @@ class Protocol {
32777
32796
  closeSSEStream: extra?.closeSSEStream,
32778
32797
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
32779
32798
  };
32780
- Promise.resolve().then(() => {
32799
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
32800
+ if (relatedTaskLookup && abortController.signal.aborted) {
32801
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
32802
+ }
32781
32803
  if (taskCreationParams) {
32782
32804
  this.assertTaskHandlerCapability(request.method);
32783
32805
  }
@@ -32812,7 +32834,7 @@ class Protocol {
32812
32834
  ...error62["data"] !== undefined && { data: error62["data"] }
32813
32835
  }
32814
32836
  };
32815
- if (relatedTaskId && this._taskMessageQueue) {
32837
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
32816
32838
  await this._enqueueTaskMessage(relatedTaskId, {
32817
32839
  type: "error",
32818
32840
  message: errorResponse,
@@ -33200,7 +33222,7 @@ class Protocol {
33200
33222
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
33201
33223
  }
33202
33224
  const maxQueueSize = this._options?.maxTaskQueueSize;
33203
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
33225
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
33204
33226
  }
33205
33227
  async _clearTaskQueue(taskId, sessionId) {
33206
33228
  if (this._taskMessageQueue) {
@@ -33219,10 +33241,10 @@ class Protocol {
33219
33241
  }
33220
33242
  }
33221
33243
  }
33222
- async _waitForTaskUpdate(taskId, signal) {
33244
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
33223
33245
  let interval = this._options?.defaultTaskPollInterval ?? 1000;
33224
33246
  try {
33225
- const task = await this._taskStore?.getTask(taskId);
33247
+ const task = await this._taskStore?.getTask(taskId, sessionId);
33226
33248
  if (task?.pollInterval) {
33227
33249
  interval = task.pollInterval;
33228
33250
  }
@@ -33889,6 +33911,43 @@ class ExperimentalMcpServerTasks {
33889
33911
  }
33890
33912
  }
33891
33913
  // server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
33914
+ function toolInputElementCount(value, max) {
33915
+ let count = 0;
33916
+ const stack = [value];
33917
+ while (stack.length > 0) {
33918
+ const node2 = stack.pop();
33919
+ if (node2 === null || typeof node2 !== "object")
33920
+ continue;
33921
+ if (Array.isArray(node2)) {
33922
+ for (const child of node2) {
33923
+ if (++count > max)
33924
+ return count;
33925
+ if (child !== null && typeof child === "object")
33926
+ stack.push(child);
33927
+ }
33928
+ } else {
33929
+ for (const key in node2) {
33930
+ if (!Object.prototype.hasOwnProperty.call(node2, key))
33931
+ continue;
33932
+ if (++count > max)
33933
+ return count;
33934
+ const child = node2[key];
33935
+ if (child !== null && typeof child === "object")
33936
+ stack.push(child);
33937
+ }
33938
+ }
33939
+ }
33940
+ return count;
33941
+ }
33942
+ function resolveMaxToolInputElements(value) {
33943
+ if (value === undefined || value === Infinity)
33944
+ return;
33945
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
33946
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
33947
+ }
33948
+ return value;
33949
+ }
33950
+
33892
33951
  class McpServer {
33893
33952
  constructor(serverInfo, options) {
33894
33953
  this._registeredResources = {};
@@ -33900,6 +33959,7 @@ class McpServer {
33900
33959
  this._resourceHandlersInitialized = false;
33901
33960
  this._promptHandlersInitialized = false;
33902
33961
  this.server = new Server(serverInfo, options);
33962
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
33903
33963
  }
33904
33964
  get experimental() {
33905
33965
  if (!this._experimental) {
@@ -34006,12 +34066,15 @@ class McpServer {
34006
34066
  };
34007
34067
  }
34008
34068
  async validateToolInput(tool, args, toolName) {
34069
+ if (this._maxToolInputElements !== undefined && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
34070
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
34071
+ }
34009
34072
  if (!tool.inputSchema) {
34010
34073
  return;
34011
34074
  }
34012
34075
  const inputObj = normalizeObjectSchema(tool.inputSchema);
34013
34076
  const schemaToParse = inputObj ?? tool.inputSchema;
34014
- const parseResult = await safeParseAsync2(schemaToParse, args);
34077
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
34015
34078
  if (!parseResult.success) {
34016
34079
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
34017
34080
  const errorMessage = getParseErrorMessage(error62);
@@ -34236,7 +34299,7 @@ class McpServer {
34236
34299
  }
34237
34300
  if (prompt.argsSchema) {
34238
34301
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
34239
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
34302
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
34240
34303
  if (!parseResult.success) {
34241
34304
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
34242
34305
  const errorMessage = getParseErrorMessage(error62);
@@ -34749,6 +34812,9 @@ function callerOf(meta3, env = process.env) {
34749
34812
  return { host: "claude-code", session, turn: null, toolUseId, mode, raw: entrypoint };
34750
34813
  }
34751
34814
 
34815
+ // server/src/db-write.ts
34816
+ import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
34817
+
34752
34818
  // server/node_modules/kysely/dist/util/object-utils.js
34753
34819
  function isUndefined(obj) {
34754
34820
  return typeof obj === "undefined" || obj === undefined;
@@ -46485,7 +46551,6 @@ function sqliteCode(e) {
46485
46551
  }
46486
46552
 
46487
46553
  // server/src/db-write.ts
46488
- import { constants as C2, DatabaseSync as DatabaseSync2 } from "node:sqlite";
46489
46554
  var ddl = null;
46490
46555
  var DDL = () => ddl ??= new Set([
46491
46556
  "SQLITE_ALTER_TABLE",
@@ -47447,7 +47512,7 @@ async function closeTurn(dir, turn, root) {
47447
47512
  return () => {
47448
47513
  if (newestTurn(readStarts(dir)) !== turn || JSON.stringify(readStart(startFile(dir, turn))) !== JSON.stringify(own2))
47449
47514
  return [];
47450
- writeStart(dir, { ...own2, ...now ?? {}, running: false });
47515
+ writeStart(dir, { ...own2, ...now, running: false });
47451
47516
  return now ? changed(root, before, now) : [];
47452
47517
  };
47453
47518
  }
package/dist/mcp.js CHANGED
@@ -32522,6 +32522,9 @@ class Protocol {
32522
32522
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
32523
32523
  const handleTaskResult = async () => {
32524
32524
  const taskId = request.params.taskId;
32525
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
32526
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
32527
+ }
32525
32528
  if (this._taskMessageQueue) {
32526
32529
  let queuedMessage;
32527
32530
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -32552,12 +32555,12 @@ class Protocol {
32552
32555
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
32553
32556
  }
32554
32557
  if (!isTerminal(task.status)) {
32555
- await this._waitForTaskUpdate(taskId, extra.signal);
32558
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
32556
32559
  return await handleTaskResult();
32557
32560
  }
32558
32561
  if (isTerminal(task.status)) {
32559
32562
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
32560
- this._clearTaskQueue(taskId);
32563
+ this._clearTaskQueue(taskId, extra.sessionId);
32561
32564
  return {
32562
32565
  ...result,
32563
32566
  _meta: {
@@ -32594,7 +32597,7 @@ class Protocol {
32594
32597
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
32595
32598
  }
32596
32599
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
32597
- this._clearTaskQueue(request.params.taskId);
32600
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
32598
32601
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
32599
32602
  if (!cancelledTask) {
32600
32603
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -32717,6 +32720,19 @@ class Protocol {
32717
32720
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
32718
32721
  const capturedTransport = this._transport;
32719
32722
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
32723
+ const sessionId = capturedTransport?.sessionId;
32724
+ const store = this._taskStore;
32725
+ let relatedTaskFound = true;
32726
+ let relatedTaskLookup;
32727
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== undefined) {
32728
+ relatedTaskFound = false;
32729
+ relatedTaskLookup = (async () => {
32730
+ if (!await store.getTask(relatedTaskId, sessionId)) {
32731
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
32732
+ }
32733
+ relatedTaskFound = true;
32734
+ })();
32735
+ }
32720
32736
  if (handler === undefined) {
32721
32737
  const errorResponse = {
32722
32738
  jsonrpc: "2.0",
@@ -32726,7 +32742,10 @@ class Protocol {
32726
32742
  message: "Method not found"
32727
32743
  }
32728
32744
  };
32729
- if (relatedTaskId && this._taskMessageQueue) {
32745
+ if (relatedTaskId && relatedTaskLookup) {
32746
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
32747
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error62) => this._onerror(new Error(`Failed to send an error response: ${error62}`)));
32748
+ } else if (relatedTaskId && this._taskMessageQueue) {
32730
32749
  this._enqueueTaskMessage(relatedTaskId, {
32731
32750
  type: "error",
32732
32751
  message: errorResponse,
@@ -32777,7 +32796,10 @@ class Protocol {
32777
32796
  closeSSEStream: extra?.closeSSEStream,
32778
32797
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
32779
32798
  };
32780
- Promise.resolve().then(() => {
32799
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
32800
+ if (relatedTaskLookup && abortController.signal.aborted) {
32801
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
32802
+ }
32781
32803
  if (taskCreationParams) {
32782
32804
  this.assertTaskHandlerCapability(request.method);
32783
32805
  }
@@ -32812,7 +32834,7 @@ class Protocol {
32812
32834
  ...error62["data"] !== undefined && { data: error62["data"] }
32813
32835
  }
32814
32836
  };
32815
- if (relatedTaskId && this._taskMessageQueue) {
32837
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
32816
32838
  await this._enqueueTaskMessage(relatedTaskId, {
32817
32839
  type: "error",
32818
32840
  message: errorResponse,
@@ -33200,7 +33222,7 @@ class Protocol {
33200
33222
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
33201
33223
  }
33202
33224
  const maxQueueSize = this._options?.maxTaskQueueSize;
33203
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
33225
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
33204
33226
  }
33205
33227
  async _clearTaskQueue(taskId, sessionId) {
33206
33228
  if (this._taskMessageQueue) {
@@ -33219,10 +33241,10 @@ class Protocol {
33219
33241
  }
33220
33242
  }
33221
33243
  }
33222
- async _waitForTaskUpdate(taskId, signal) {
33244
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
33223
33245
  let interval = this._options?.defaultTaskPollInterval ?? 1000;
33224
33246
  try {
33225
- const task = await this._taskStore?.getTask(taskId);
33247
+ const task = await this._taskStore?.getTask(taskId, sessionId);
33226
33248
  if (task?.pollInterval) {
33227
33249
  interval = task.pollInterval;
33228
33250
  }
@@ -33889,6 +33911,43 @@ class ExperimentalMcpServerTasks {
33889
33911
  }
33890
33912
  }
33891
33913
  // server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js
33914
+ function toolInputElementCount(value, max) {
33915
+ let count = 0;
33916
+ const stack = [value];
33917
+ while (stack.length > 0) {
33918
+ const node2 = stack.pop();
33919
+ if (node2 === null || typeof node2 !== "object")
33920
+ continue;
33921
+ if (Array.isArray(node2)) {
33922
+ for (const child of node2) {
33923
+ if (++count > max)
33924
+ return count;
33925
+ if (child !== null && typeof child === "object")
33926
+ stack.push(child);
33927
+ }
33928
+ } else {
33929
+ for (const key in node2) {
33930
+ if (!Object.prototype.hasOwnProperty.call(node2, key))
33931
+ continue;
33932
+ if (++count > max)
33933
+ return count;
33934
+ const child = node2[key];
33935
+ if (child !== null && typeof child === "object")
33936
+ stack.push(child);
33937
+ }
33938
+ }
33939
+ }
33940
+ return count;
33941
+ }
33942
+ function resolveMaxToolInputElements(value) {
33943
+ if (value === undefined || value === Infinity)
33944
+ return;
33945
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) {
33946
+ throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
33947
+ }
33948
+ return value;
33949
+ }
33950
+
33892
33951
  class McpServer {
33893
33952
  constructor(serverInfo, options) {
33894
33953
  this._registeredResources = {};
@@ -33900,6 +33959,7 @@ class McpServer {
33900
33959
  this._resourceHandlersInitialized = false;
33901
33960
  this._promptHandlersInitialized = false;
33902
33961
  this.server = new Server(serverInfo, options);
33962
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
33903
33963
  }
33904
33964
  get experimental() {
33905
33965
  if (!this._experimental) {
@@ -34006,12 +34066,15 @@ class McpServer {
34006
34066
  };
34007
34067
  }
34008
34068
  async validateToolInput(tool, args, toolName) {
34069
+ if (this._maxToolInputElements !== undefined && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) {
34070
+ throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
34071
+ }
34009
34072
  if (!tool.inputSchema) {
34010
34073
  return;
34011
34074
  }
34012
34075
  const inputObj = normalizeObjectSchema(tool.inputSchema);
34013
34076
  const schemaToParse = inputObj ?? tool.inputSchema;
34014
- const parseResult = await safeParseAsync2(schemaToParse, args);
34077
+ const parseResult = await safeParseAsync2(schemaToParse, args ?? {});
34015
34078
  if (!parseResult.success) {
34016
34079
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
34017
34080
  const errorMessage = getParseErrorMessage(error62);
@@ -34236,7 +34299,7 @@ class McpServer {
34236
34299
  }
34237
34300
  if (prompt.argsSchema) {
34238
34301
  const argsObj = normalizeObjectSchema(prompt.argsSchema);
34239
- const parseResult = await safeParseAsync2(argsObj, request.params.arguments);
34302
+ const parseResult = await safeParseAsync2(argsObj, request.params.arguments ?? {});
34240
34303
  if (!parseResult.success) {
34241
34304
  const error62 = "error" in parseResult ? parseResult.error : "Unknown error";
34242
34305
  const errorMessage = getParseErrorMessage(error62);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sphica",
3
- "version": "0.6.63",
3
+ "version": "0.6.65",
4
4
  "description": "Records Claude Code and Codex sessions on your machine and keeps past implementation and decisions, with their sources, for your agent to find.",
5
5
  "license": "MIT",
6
6
  "type": "module",