@cavelon/cli 0.2.6 → 0.2.8

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.
@@ -36355,6 +36355,9 @@ var Protocol = class {
36355
36355
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
36356
36356
  const handleTaskResult = async () => {
36357
36357
  const taskId = request.params.taskId;
36358
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
36359
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
36360
+ }
36358
36361
  if (this._taskMessageQueue) {
36359
36362
  let queuedMessage;
36360
36363
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -36385,12 +36388,12 @@ var Protocol = class {
36385
36388
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
36386
36389
  }
36387
36390
  if (!isTerminal(task.status)) {
36388
- await this._waitForTaskUpdate(taskId, extra.signal);
36391
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
36389
36392
  return await handleTaskResult();
36390
36393
  }
36391
36394
  if (isTerminal(task.status)) {
36392
36395
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
36393
- this._clearTaskQueue(taskId);
36396
+ this._clearTaskQueue(taskId, extra.sessionId);
36394
36397
  return {
36395
36398
  ...result,
36396
36399
  _meta: {
@@ -36427,7 +36430,7 @@ var Protocol = class {
36427
36430
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
36428
36431
  }
36429
36432
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
36430
- this._clearTaskQueue(request.params.taskId);
36433
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
36431
36434
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
36432
36435
  if (!cancelledTask) {
36433
36436
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -36555,6 +36558,19 @@ var Protocol = class {
36555
36558
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
36556
36559
  const capturedTransport = this._transport;
36557
36560
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
36561
+ const sessionId = capturedTransport?.sessionId;
36562
+ const store = this._taskStore;
36563
+ let relatedTaskFound = true;
36564
+ let relatedTaskLookup;
36565
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
36566
+ relatedTaskFound = false;
36567
+ relatedTaskLookup = (async () => {
36568
+ if (!await store.getTask(relatedTaskId, sessionId)) {
36569
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
36570
+ }
36571
+ relatedTaskFound = true;
36572
+ })();
36573
+ }
36558
36574
  if (handler === void 0) {
36559
36575
  const errorResponse = {
36560
36576
  jsonrpc: "2.0",
@@ -36564,7 +36580,10 @@ var Protocol = class {
36564
36580
  message: "Method not found"
36565
36581
  }
36566
36582
  };
36567
- if (relatedTaskId && this._taskMessageQueue) {
36583
+ if (relatedTaskId && relatedTaskLookup) {
36584
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
36585
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error62) => this._onerror(new Error(`Failed to send an error response: ${error62}`)));
36586
+ } else if (relatedTaskId && this._taskMessageQueue) {
36568
36587
  this._enqueueTaskMessage(relatedTaskId, {
36569
36588
  type: "error",
36570
36589
  message: errorResponse,
@@ -36615,7 +36634,10 @@ var Protocol = class {
36615
36634
  closeSSEStream: extra?.closeSSEStream,
36616
36635
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
36617
36636
  };
36618
- Promise.resolve().then(() => {
36637
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
36638
+ if (relatedTaskLookup && abortController.signal.aborted) {
36639
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
36640
+ }
36619
36641
  if (taskCreationParams) {
36620
36642
  this.assertTaskHandlerCapability(request.method);
36621
36643
  }
@@ -36650,7 +36672,7 @@ var Protocol = class {
36650
36672
  ...error62["data"] !== void 0 && { data: error62["data"] }
36651
36673
  }
36652
36674
  };
36653
- if (relatedTaskId && this._taskMessageQueue) {
36675
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
36654
36676
  await this._enqueueTaskMessage(relatedTaskId, {
36655
36677
  type: "error",
36656
36678
  message: errorResponse,
@@ -37130,7 +37152,7 @@ var Protocol = class {
37130
37152
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
37131
37153
  }
37132
37154
  const maxQueueSize = this._options?.maxTaskQueueSize;
37133
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
37155
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
37134
37156
  }
37135
37157
  /**
37136
37158
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -37159,12 +37181,13 @@ var Protocol = class {
37159
37181
  * Uses polling to check for updates at the task's configured poll interval.
37160
37182
  * @param taskId The task ID to wait for
37161
37183
  * @param signal Abort signal to cancel the wait
37184
+ * @param sessionId Session of the request that waits, passed to the task store
37162
37185
  * @returns Promise that resolves when an update occurs or rejects if aborted
37163
37186
  */
37164
- async _waitForTaskUpdate(taskId, signal) {
37187
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
37165
37188
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
37166
37189
  try {
37167
- const task = await this._taskStore?.getTask(taskId);
37190
+ const task = await this._taskStore?.getTask(taskId, sessionId);
37168
37191
  if (task?.pollInterval) {
37169
37192
  interval = task.pollInterval;
37170
37193
  }
@@ -23049,6 +23049,9 @@ var Protocol = class {
23049
23049
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
23050
23050
  const handleTaskResult = async () => {
23051
23051
  const taskId = request.params.taskId;
23052
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
23053
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
23054
+ }
23052
23055
  if (this._taskMessageQueue) {
23053
23056
  let queuedMessage;
23054
23057
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -23079,12 +23082,12 @@ var Protocol = class {
23079
23082
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
23080
23083
  }
23081
23084
  if (!isTerminal(task.status)) {
23082
- await this._waitForTaskUpdate(taskId, extra.signal);
23085
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
23083
23086
  return await handleTaskResult();
23084
23087
  }
23085
23088
  if (isTerminal(task.status)) {
23086
23089
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
23087
- this._clearTaskQueue(taskId);
23090
+ this._clearTaskQueue(taskId, extra.sessionId);
23088
23091
  return {
23089
23092
  ...result,
23090
23093
  _meta: {
@@ -23121,7 +23124,7 @@ var Protocol = class {
23121
23124
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
23122
23125
  }
23123
23126
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
23124
- this._clearTaskQueue(request.params.taskId);
23127
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
23125
23128
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
23126
23129
  if (!cancelledTask) {
23127
23130
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -23249,6 +23252,19 @@ var Protocol = class {
23249
23252
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
23250
23253
  const capturedTransport = this._transport;
23251
23254
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
23255
+ const sessionId = capturedTransport?.sessionId;
23256
+ const store = this._taskStore;
23257
+ let relatedTaskFound = true;
23258
+ let relatedTaskLookup;
23259
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
23260
+ relatedTaskFound = false;
23261
+ relatedTaskLookup = (async () => {
23262
+ if (!await store.getTask(relatedTaskId, sessionId)) {
23263
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
23264
+ }
23265
+ relatedTaskFound = true;
23266
+ })();
23267
+ }
23252
23268
  if (handler === void 0) {
23253
23269
  const errorResponse = {
23254
23270
  jsonrpc: "2.0",
@@ -23258,7 +23274,10 @@ var Protocol = class {
23258
23274
  message: "Method not found"
23259
23275
  }
23260
23276
  };
23261
- if (relatedTaskId && this._taskMessageQueue) {
23277
+ if (relatedTaskId && relatedTaskLookup) {
23278
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
23279
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
23280
+ } else if (relatedTaskId && this._taskMessageQueue) {
23262
23281
  this._enqueueTaskMessage(relatedTaskId, {
23263
23282
  type: "error",
23264
23283
  message: errorResponse,
@@ -23309,7 +23328,10 @@ var Protocol = class {
23309
23328
  closeSSEStream: extra?.closeSSEStream,
23310
23329
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
23311
23330
  };
23312
- Promise.resolve().then(() => {
23331
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
23332
+ if (relatedTaskLookup && abortController.signal.aborted) {
23333
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
23334
+ }
23313
23335
  if (taskCreationParams) {
23314
23336
  this.assertTaskHandlerCapability(request.method);
23315
23337
  }
@@ -23344,7 +23366,7 @@ var Protocol = class {
23344
23366
  ...error2["data"] !== void 0 && { data: error2["data"] }
23345
23367
  }
23346
23368
  };
23347
- if (relatedTaskId && this._taskMessageQueue) {
23369
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
23348
23370
  await this._enqueueTaskMessage(relatedTaskId, {
23349
23371
  type: "error",
23350
23372
  message: errorResponse,
@@ -23824,7 +23846,7 @@ var Protocol = class {
23824
23846
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
23825
23847
  }
23826
23848
  const maxQueueSize = this._options?.maxTaskQueueSize;
23827
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
23849
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
23828
23850
  }
23829
23851
  /**
23830
23852
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -23853,12 +23875,13 @@ var Protocol = class {
23853
23875
  * Uses polling to check for updates at the task's configured poll interval.
23854
23876
  * @param taskId The task ID to wait for
23855
23877
  * @param signal Abort signal to cancel the wait
23878
+ * @param sessionId Session of the request that waits, passed to the task store
23856
23879
  * @returns Promise that resolves when an update occurs or rejects if aborted
23857
23880
  */
23858
- async _waitForTaskUpdate(taskId, signal) {
23881
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
23859
23882
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
23860
23883
  try {
23861
- const task = await this._taskStore?.getTask(taskId);
23884
+ const task = await this._taskStore?.getTask(taskId, sessionId);
23862
23885
  if (task?.pollInterval) {
23863
23886
  interval = task.pollInterval;
23864
23887
  }
@@ -15063,6 +15063,7 @@ __export(settings_exports, {
15063
15063
  // node_modules/typebox/build/guard/guard.mjs
15064
15064
  var guard_exports = {};
15065
15065
  __export(guard_exports, {
15066
+ CodePointCount: () => CodePointCount2,
15066
15067
  Counted: () => Counted,
15067
15068
  Entries: () => Entries,
15068
15069
  EntriesRegExp: () => EntriesRegExp,
@@ -15103,16 +15104,13 @@ __export(guard_exports, {
15103
15104
  Values: () => Values
15104
15105
  });
15105
15106
 
15106
- // node_modules/typebox/build/guard/string.mjs
15107
+ // node_modules/typebox/build/guard/unicode/unicode_segment.mjs
15107
15108
  function IsBetween(value, min, max) {
15108
15109
  return value >= min && value <= max;
15109
15110
  }
15110
15111
  function IsZeroWidthJoiner(value) {
15111
15112
  return value === 8205;
15112
15113
  }
15113
- function IsHighSurrogate(value) {
15114
- return IsBetween(value, 55296, 56319);
15115
- }
15116
15114
  function IsRegionalIndicator(value) {
15117
15115
  return IsBetween(value, 127462, 127487);
15118
15116
  }
@@ -15150,64 +15148,30 @@ function NextGraphemeClusterIndex(value, clusterStart) {
15150
15148
  }
15151
15149
  return clusterEnd;
15152
15150
  }
15153
- function IsGraphemeCodePoint(value) {
15154
- return value >= 768 && // above special range
15155
- (IsHighSurrogate(value) || IsCombiningMark(value) || IsVariationSelector(value) || IsZeroWidthJoiner(value));
15156
- }
15157
15151
  function GraphemeCount(value) {
15158
- let count = 0;
15159
- let index = 0;
15152
+ let count = 0, index = 0;
15160
15153
  while (index < value.length) {
15161
15154
  index = NextGraphemeClusterIndex(value, index);
15162
15155
  count++;
15163
15156
  }
15164
15157
  return count;
15165
15158
  }
15166
- function IsMinLengthSegmented(value, minLength) {
15167
- let count = 0;
15168
- let index = 0;
15159
+
15160
+ // node_modules/typebox/build/guard/unicode/unicode.mjs
15161
+ function CodePointCount(value) {
15162
+ let result = 0, index = 0, prev = 0;
15169
15163
  while (index < value.length) {
15170
- index = NextGraphemeClusterIndex(value, index);
15171
- if (++count >= minLength)
15172
- return true;
15164
+ const next = value.charCodeAt(index++) >> 10;
15165
+ result += +((prev << 8 | next) !== 13879);
15166
+ prev = next;
15173
15167
  }
15174
- return false;
15168
+ return result;
15175
15169
  }
15176
- function IsMaxLengthSegmented(value, maxLength) {
15177
- let count = 0;
15178
- let index = 0;
15179
- while (index < value.length) {
15180
- index = NextGraphemeClusterIndex(value, index);
15181
- if (++count > maxLength)
15182
- return false;
15183
- }
15184
- return true;
15170
+ function IsMaxLength(value, maxLength) {
15171
+ return value.length <= maxLength || value.length <= maxLength << 1 && CodePointCount(value) <= maxLength;
15185
15172
  }
15186
15173
  function IsMinLength(value, minLength) {
15187
- if (minLength === 0)
15188
- return true;
15189
- if (value.length < minLength)
15190
- return false;
15191
- let index = 0;
15192
- while (true) {
15193
- if (IsGraphemeCodePoint(value.charCodeAt(index))) {
15194
- return IsMinLengthSegmented(value, minLength);
15195
- }
15196
- if (++index >= minLength)
15197
- return true;
15198
- }
15199
- }
15200
- function IsMaxLength(value, maxLength) {
15201
- if (value.length <= maxLength)
15202
- return true;
15203
- let index = 0;
15204
- while (true) {
15205
- if (IsGraphemeCodePoint(value.charCodeAt(index))) {
15206
- return IsMaxLengthSegmented(value, maxLength);
15207
- }
15208
- if (++index > maxLength)
15209
- return false;
15210
- }
15174
+ return value.length >= minLength << 1 || value.length >= minLength && CodePointCount(value) >= minLength;
15211
15175
  }
15212
15176
 
15213
15177
  // node_modules/typebox/build/guard/guard.mjs
@@ -15298,11 +15262,14 @@ function IsValueLike(value) {
15298
15262
  function GraphemeCount2(value) {
15299
15263
  return GraphemeCount(value);
15300
15264
  }
15301
- function IsMaxLength2(value, length) {
15302
- return IsMaxLength(value, length);
15265
+ function CodePointCount2(value) {
15266
+ return CodePointCount(value);
15303
15267
  }
15304
- function IsMinLength2(value, length) {
15305
- return IsMinLength(value, length);
15268
+ function IsMaxLength2(value, maxLength) {
15269
+ return IsMaxLength(value, maxLength);
15270
+ }
15271
+ function IsMinLength2(value, minLength) {
15272
+ return IsMinLength(value, minLength);
15306
15273
  }
15307
15274
  function Every(value, offset, callback) {
15308
15275
  return value.every((item, index) => index < offset || callback(item, index));
@@ -15451,6 +15418,7 @@ function IsMap(value) {
15451
15418
  var settings = {
15452
15419
  immutableTypes: false,
15453
15420
  maxErrors: 8,
15421
+ maxParseErrors: 1,
15454
15422
  maxInstantiationCount: 128,
15455
15423
  useAcceleration: true,
15456
15424
  exactOptionalPropertyTypes: false,
@@ -15461,6 +15429,7 @@ var settings = {
15461
15429
  function Reset() {
15462
15430
  settings.immutableTypes = false;
15463
15431
  settings.maxErrors = 8;
15432
+ settings.maxParseErrors = 1;
15464
15433
  settings.maxInstantiationCount = 128;
15465
15434
  settings.useAcceleration = true;
15466
15435
  settings.exactOptionalPropertyTypes = false;
@@ -17736,8 +17705,14 @@ function TryRestInferable(type) {
17736
17705
  function TryInferable(type) {
17737
17706
  return IsInfer(type) ? Inferrable(type.name, type.extends) : void 0;
17738
17707
  }
17739
- function TryInferResults(rest, right, result = []) {
17740
- return guard_exports.ShiftLeft(rest, (head, tail) => Match3(ExtendsLeft({}, head, right), () => TryInferResults(tail, right, [...result, head]), () => void 0), () => result);
17708
+ function TryInferResults(rest, right) {
17709
+ const result = [];
17710
+ for (const head of rest) {
17711
+ if (!IsExtendsTrueLike(ExtendsLeft({}, head, right)))
17712
+ return void 0;
17713
+ result.push(head);
17714
+ }
17715
+ return result;
17741
17716
  }
17742
17717
  function InferTupleResult(inferred, name, left, right) {
17743
17718
  const results = TryInferResults(left, right);
@@ -17781,9 +17756,18 @@ function ExtendsTupleToTuple(inferred, left, right) {
17781
17756
  const reversed = Reversed(instantiatedRight);
17782
17757
  return Elements(inferred, reversed, ApplyReverse(left, reversed), ApplyReverse(instantiatedRight, reversed));
17783
17758
  }
17759
+ function ExtendsTupleToArrayReduce(inferred, left, right) {
17760
+ for (const head of left) {
17761
+ const result = ExtendsLeft(inferred, head, right);
17762
+ if (!IsExtendsTrueLike(result))
17763
+ return result;
17764
+ inferred = result.inferred;
17765
+ }
17766
+ return ExtendsTrue(inferred);
17767
+ }
17784
17768
  function ExtendsTupleToArray(inferred, left, right) {
17785
17769
  const inferrable = TryInferable(right);
17786
- return IsInferable(inferrable) ? InferUnionResult(inferred, inferrable["name"], left, inferrable["type"]) : guard_exports.ShiftLeft(left, (head, tail) => Match3(ExtendsLeft(inferred, head, right), (inferred2) => ExtendsTupleToArray(inferred2, tail, right), () => ExtendsFalse()), () => ExtendsTrue(inferred));
17770
+ return IsInferable(inferrable) ? InferUnionResult(inferred, inferrable["name"], left, inferrable["type"]) : ExtendsTupleToArrayReduce(inferred, left, right);
17787
17771
  }
17788
17772
  function ExtendsTuple(inferred, left, right) {
17789
17773
  const instantiatedLeft = InstantiateElements(inferred, State([], []), left);
@@ -27456,6 +27440,9 @@ var Protocol = class {
27456
27440
  this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
27457
27441
  const handleTaskResult = async () => {
27458
27442
  const taskId = request.params.taskId;
27443
+ if (!await this._taskStore.getTask(taskId, extra.sessionId)) {
27444
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
27445
+ }
27459
27446
  if (this._taskMessageQueue) {
27460
27447
  let queuedMessage;
27461
27448
  while (queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId)) {
@@ -27486,12 +27473,12 @@ var Protocol = class {
27486
27473
  throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
27487
27474
  }
27488
27475
  if (!isTerminal(task.status)) {
27489
- await this._waitForTaskUpdate(taskId, extra.signal);
27476
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
27490
27477
  return await handleTaskResult();
27491
27478
  }
27492
27479
  if (isTerminal(task.status)) {
27493
27480
  const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
27494
- this._clearTaskQueue(taskId);
27481
+ this._clearTaskQueue(taskId, extra.sessionId);
27495
27482
  return {
27496
27483
  ...result,
27497
27484
  _meta: {
@@ -27528,7 +27515,7 @@ var Protocol = class {
27528
27515
  throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
27529
27516
  }
27530
27517
  await this._taskStore.updateTaskStatus(request.params.taskId, "cancelled", "Client cancelled task execution.", extra.sessionId);
27531
- this._clearTaskQueue(request.params.taskId);
27518
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
27532
27519
  const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
27533
27520
  if (!cancelledTask) {
27534
27521
  throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
@@ -27656,6 +27643,19 @@ var Protocol = class {
27656
27643
  const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
27657
27644
  const capturedTransport = this._transport;
27658
27645
  const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
27646
+ const sessionId = capturedTransport?.sessionId;
27647
+ const store = this._taskStore;
27648
+ let relatedTaskFound = true;
27649
+ let relatedTaskLookup;
27650
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== void 0) {
27651
+ relatedTaskFound = false;
27652
+ relatedTaskLookup = (async () => {
27653
+ if (!await store.getTask(relatedTaskId, sessionId)) {
27654
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
27655
+ }
27656
+ relatedTaskFound = true;
27657
+ })();
27658
+ }
27659
27659
  if (handler === void 0) {
27660
27660
  const errorResponse = {
27661
27661
  jsonrpc: "2.0",
@@ -27665,7 +27665,10 @@ var Protocol = class {
27665
27665
  message: "Method not found"
27666
27666
  }
27667
27667
  };
27668
- if (relatedTaskId && this._taskMessageQueue) {
27668
+ if (relatedTaskId && relatedTaskLookup) {
27669
+ const queuedError = { type: "error", message: errorResponse, timestamp: Date.now() };
27670
+ relatedTaskLookup.then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse)).catch((error2) => this._onerror(new Error(`Failed to send an error response: ${error2}`)));
27671
+ } else if (relatedTaskId && this._taskMessageQueue) {
27669
27672
  this._enqueueTaskMessage(relatedTaskId, {
27670
27673
  type: "error",
27671
27674
  message: errorResponse,
@@ -27716,7 +27719,10 @@ var Protocol = class {
27716
27719
  closeSSEStream: extra?.closeSSEStream,
27717
27720
  closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
27718
27721
  };
27719
- Promise.resolve().then(() => {
27722
+ (relatedTaskLookup ?? Promise.resolve()).then(() => {
27723
+ if (relatedTaskLookup && abortController.signal.aborted) {
27724
+ throw new McpError(ErrorCode.ConnectionClosed, "Request was cancelled");
27725
+ }
27720
27726
  if (taskCreationParams) {
27721
27727
  this.assertTaskHandlerCapability(request.method);
27722
27728
  }
@@ -27751,7 +27757,7 @@ var Protocol = class {
27751
27757
  ...error2["data"] !== void 0 && { data: error2["data"] }
27752
27758
  }
27753
27759
  };
27754
- if (relatedTaskId && this._taskMessageQueue) {
27760
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
27755
27761
  await this._enqueueTaskMessage(relatedTaskId, {
27756
27762
  type: "error",
27757
27763
  message: errorResponse,
@@ -28231,7 +28237,7 @@ var Protocol = class {
28231
28237
  throw new Error("Cannot enqueue task message: taskStore and taskMessageQueue are not configured");
28232
28238
  }
28233
28239
  const maxQueueSize = this._options?.maxTaskQueueSize;
28234
- await this._taskMessageQueue.enqueue(taskId, message, sessionId, maxQueueSize);
28240
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
28235
28241
  }
28236
28242
  /**
28237
28243
  * Clears the message queue for a task and rejects any pending request resolvers.
@@ -28260,12 +28266,13 @@ var Protocol = class {
28260
28266
  * Uses polling to check for updates at the task's configured poll interval.
28261
28267
  * @param taskId The task ID to wait for
28262
28268
  * @param signal Abort signal to cancel the wait
28269
+ * @param sessionId Session of the request that waits, passed to the task store
28263
28270
  * @returns Promise that resolves when an update occurs or rejects if aborted
28264
28271
  */
28265
- async _waitForTaskUpdate(taskId, signal) {
28272
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
28266
28273
  let interval = this._options?.defaultTaskPollInterval ?? 1e3;
28267
28274
  try {
28268
- const task = await this._taskStore?.getTask(taskId);
28275
+ const task = await this._taskStore?.getTask(taskId, sessionId);
28269
28276
  if (task?.pollInterval) {
28270
28277
  interval = task.pollInterval;
28271
28278
  }
@@ -242,6 +242,19 @@ and fill the field in to set it. A file of comments only sets nothing.
242
242
  The preview names them with the Admin path where a person sets them.
243
243
  - **Knowledge-base documents** are not in the repository: the package declares
244
244
  the knowledge bases; `cavelon kb upload` brings the documents.
245
+ For tables/privacy, `document_processing_config` takes `table_optimizer`,
246
+ `export_tables_xlsx`, `privacy_document` and `privacy_outputs` (each privacy
247
+ mode is `off`, `pseudonymize` or `anonymize`), and `privacy_model` (a tenant
248
+ model registry entry's `id`, not `model_id`, or null). The names model must
249
+ be active with a non-OpenAI, non-Azure-OpenAI endpoint; its credentials stay
250
+ with a person in the Admin. The table optimizer uses `vision_model`.
251
+ `bitmap_area_threshold` no longer affects OCR on the current instance.
252
+ `read_document(file: "redacted_pdf" | "tables_xlsx")` fetches a readable
253
+ conversion file into the conversation; `max_chars: 0` lists the available
254
+ file kinds. The vault and conversion report are never agent-readable.
255
+ A `held_for_privacy_review` response needs a person's review in the Admin;
256
+ never release a held document yourself. See the instance's
257
+ `reference/kb-management-api` and `reference/builtin-tools` pages.
245
258
  - **A knowledge base reaches an agent only through a tool that reads it.**
246
259
  Naming it in a skill's `knowledge_base_assignments` only scopes the tools;
247
260
  the skill (or the agent) also needs a built-in that reads a knowledge base in
@@ -154,7 +154,21 @@ use it when you parse the result.
154
154
 
155
155
  ## The loop
156
156
 
157
- 1. **Pull** what is live: `cavelon pull`. It refuses when `package/` has
157
+ When the instance advertises solution publication, an active solution's scoped
158
+ graph apply writes an unpublished draft. Read the explicit `publication`
159
+ report; older instances keep their previous behavior. Inspect it with
160
+ `cavelon harness publication <solution> --json`, run tests and fix readiness,
161
+ then review `cavelon publish --harness <solution>`. Publication changes live
162
+ traffic and always needs the person's fresh MCP/own-terminal confirmation,
163
+ including in YOLO. Never force it from the kit. Conflicting versions, revisions
164
+ or affected waiting runs require a fresh review. Shared tenant resources keep
165
+ their existing behavior and are not isolated by the graph draft.
166
+ `cavelon harness discard-draft --harness <solution>` reviews removal of the
167
+ pending draft; `cavelon harness rollback --harness <solution>` reviews an earlier
168
+ pinned version as a new publication. Rollback first retains unpublished edits
169
+ in a pinned recovery snapshot and clears the draft; report its warnings.
170
+
171
+ 1. **Pull** the instance's editable package: `cavelon pull`. It refuses when `package/` has
158
172
  uncommitted changes (outside git: files changed since the last pull);
159
173
  commit or apply them first. A file as the last pull or confirmed apply left
160
174
  it counts as unchanged, so a pull right after an apply goes ahead without a
@@ -233,6 +247,16 @@ use it when you parse the result.
233
247
  uploads on (`kb_upload_archive_enabled`) and it stays within their file
234
248
  count, unpacked size and compression ratio (exit 3, naming the limit and who
235
249
  changes it).
250
+ Inspect status with `cavelon kb documents --kb <kb>` (`kb_documents` over
251
+ MCP). A `held` document is not indexed or readable: ask a person with
252
+ `knowledge_bases.manage_documents` to review and release it in the Admin.
253
+ Neither release route accepts tokens, even from a person's terminal or in
254
+ YOLO. Never call it or retry ingestion to get around privacy review.
255
+ `kb files <document-id> --kb <kb>` lists conversion file ids and a privacy
256
+ summary. `kb download <document-id> --kb <kb> --file <file-id> --output <new-path>`
257
+ saves a readable PDF/workbook inside the solution; omit `--file` for the
258
+ instance's normal (redacted where configured) download. The vault and
259
+ conversion report stay with a dashboard person.
236
260
  **Updating a document**: upload the new version under the same file name.
237
261
  `kb upload` names each file that matches an active document of the
238
262
  knowledge base, and what happens to it depends on the instance (try it with
@@ -313,7 +337,7 @@ A technical preview is not a request for a chat approval. Within the user's
313
337
  requested work, read and confirm a preview that needs no person without
314
338
  asking them again or showing every intermediate preview. For `apply`, check
315
339
  `show_to_person: false` and no `needs_person` requirement. This includes
316
- `apply` to a draft solution in a test environment (no query
340
+ `apply` to a draft solution, or an active solution's explicitly reported isolated graph draft, in a test environment (no query
317
341
  writes or other reason to show it to a person), `loop start` of a trigger
318
342
  of a draft solution, `loop cancel` and `sandbox seed` of a test run or Sandbox
319
343
  you started, `kb upload --replace`, and known routine `api` operations.
@@ -321,7 +345,7 @@ Summarize the outcome with the work. A preview needs the person's decision
321
345
  when:
322
346
 
323
347
  - the preview lists an active solution under "reaches active", or the target
324
- solution is active;
348
+ solution is active without explicit isolated-draft metadata;
325
349
  - the environment is `prod` (`--env prod`), or the preview deletes anything
326
350
  (`--mode replace`);
327
351
  - the preview changes tenant-wide sections (`tenant-wide: … change for every
@@ -233,6 +233,19 @@ the Admin. Then:
233
233
  the model with on the tool's span (`error_code`); `cavelon explain <code>`
234
234
  says how to fix it.
235
235
 
236
+ Unattended schedules, where offered by the instance, are enabled by a person in
237
+ the Admin. A schedule or automatic run is useful regression evidence but does
238
+ not replace the latest manually started whole-suite run required for activation.
239
+ Read the instance's current Graph Check errors and published catalog; fix the
240
+ named node/configuration before trying activation again.
241
+
242
+ On an instance with graph drafts, testing/Playground and live traffic may use
243
+ different graph versions. Read `cavelon harness publication <solution> --json`
244
+ and the instance's run/version metadata; a passing draft test does not put its
245
+ changes live. Review `cavelon publish --harness <solution>` only after fixing
246
+ readiness, and follow its person-confirmation instruction. Older instances
247
+ keep their existing execution behavior.
248
+
236
249
  ## Reading what happened
237
250
 
238
251
  ```bash
@@ -251,6 +264,23 @@ under the test run's id; a wrong id answers with a hint naming the right one.
251
264
  The spans list suggests the span to open first: the one that failed, else the
252
265
  last model call, else the knowledge search.
253
266
 
267
+ To keep the instance's original conversation trace export, including its
268
+ integrity manifest, save it to a new file inside the solution:
269
+
270
+ ```bash
271
+ cavelon trace <conversation-id> --kind conversation --trace <trace-id> --export trace.json
272
+ ```
273
+
274
+ This needs `conversations.view` and `conversations.export`; an instance that
275
+ does not advertise the export operation reports it as unavailable. The same
276
+ option is available on the MCP `trace` tool. The file is never overwritten,
277
+ and the exported bytes are not shortened or reformatted. JSON output reports
278
+ `file_sha256` for the saved file and preserves the instance's `manifest`.
279
+ `manifest.trace_sha256` and a possible HMAC signature are supplied by the
280
+ instance; the kit does not verify that HMAC or request its signing secret.
281
+ An unsigned manifest (`signed: false`) is allowed. Treat the export as trace
282
+ data with the same access and sharing restrictions as the original trace.
283
+
254
284
  Each step lists its assertions with pass or FAIL (`Assertions (1 of 2
255
285
  passed)`, then one line each with the expected and observed value of a failed
256
286
  one and the reasoning), the judge's criteria with their scores, and the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "The cavelon binary: CLI and local MCP server for building Cavelon solutions with a coding agent.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/goodguys-gmbh/cavelon-dev-kit",
@@ -46,7 +46,7 @@
46
46
  "@types/node": "^20.19.0",
47
47
  "esbuild": "0.28.2",
48
48
  "eslint": "^10.12.0",
49
- "typebox": "1.3.27",
49
+ "typebox": "1.3.36",
50
50
  "typescript": "~6.0.3",
51
51
  "typescript-eslint": "^8.71.0",
52
52
  "vitest": "^4.0.0",