chainlesschain 0.166.145 → 0.166.147
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -10
- package/package.json +2 -2
- package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
- package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
- package/src/command-help-index.json +2 -2
- package/src/commands/agent.js +20 -1
- package/src/commands/mcp-tasks.js +37 -4
- package/src/commands/mcp.js +24 -0
- package/src/commands/memory.js +131 -7
- package/src/data/changelog.json +26 -0
- package/src/generated/cc-agent-protocol.schema.json +175 -69
- package/src/harness/jsonl-session-store.js +4 -0
- package/src/harness/mcp-client.js +273 -48
- package/src/harness/prompt-compressor.js +1 -0
- package/src/harness/session-index.js +8 -0
- package/src/harness/session-list-index.js +2 -0
- package/src/lib/agent-session-export.js +19 -0
- package/src/lib/app-server/context-memory-notifications.js +11 -2
- package/src/lib/app-server/server.js +1 -0
- package/src/lib/background-launch-profile.js +38 -6
- package/src/lib/context-memory-kernel/local-semantic-source.js +426 -0
- package/src/lib/context-memory-kernel/local-semantic-worker.py +109 -0
- package/src/lib/context-memory-kernel/memory-service.js +35 -2
- package/src/lib/context-memory-kernel/provider-context.js +1 -1
- package/src/lib/context-memory-kernel/runtime.js +40 -0
- package/src/lib/evolution/evolution-artifact-ports.js +36 -1
- package/src/lib/evolution/evolution-ledger-file-manifest-head-store.js +19 -0
- package/src/lib/evolution/evolution-ledger-manifest-catalog.js +13 -0
- package/src/lib/evolution/evolution-ledger-manifest-head-store.js +17 -0
- package/src/lib/evolution/evolution-ledger-v2-manifest-backend.js +29 -2
- package/src/lib/formal-budget-authority.js +56 -3
- package/src/lib/formal-budget-contract.js +90 -5
- package/src/lib/mcp-client.js +1 -0
- package/src/lib/mcp-stateless-protocol.js +158 -0
- package/src/lib/mcp-task-continuation-contract.js +129 -0
- package/src/lib/mcp-task-continuation.js +147 -0
- package/src/lib/mcp-task-journal-projection.js +49 -4
- package/src/lib/mcp-task-runtime.js +148 -1
- package/src/lib/mcp-tasks.js +24 -0
- package/src/lib/session-host-snapshot.js +31 -0
- package/src/lib/session-input-lifecycle.js +147 -0
- package/src/lib/session-input-receipt.js +64 -0
- package/src/lib/session-message-provenance.js +6 -5
- package/src/lib/session-model-usage-recovery.js +115 -0
- package/src/lib/session-transcript-history.js +3 -0
- package/src/lib/session-transcript-structure.js +8 -1
- package/src/lib/storage-failure-cause-codes.js +79 -0
- package/src/repl/agent-repl.js +348 -23
- package/src/runtime/agent-core.js +29 -11
- package/src/runtime/headless-runner.js +1 -0
- package/src/runtime/headless-stream.js +40 -33
- package/src/runtime/mcp-config.js +5 -3
- package/src/runtime/policies/agent-policy.js +1 -0
|
@@ -36,7 +36,13 @@ import {
|
|
|
36
36
|
requireMcpTaskCapability,
|
|
37
37
|
requireMcpToolTaskMode,
|
|
38
38
|
admitMcpTaskResponse,
|
|
39
|
+
MCP_STATELESS_PROTOCOL_VERSION,
|
|
39
40
|
} from "../lib/mcp-tasks.js";
|
|
41
|
+
import {
|
|
42
|
+
statelessMcpRequest,
|
|
43
|
+
admitStatelessMcpTask,
|
|
44
|
+
assertStatelessMcpAck,
|
|
45
|
+
} from "../lib/mcp-stateless-protocol.js";
|
|
40
46
|
|
|
41
47
|
import { terminateOwnedProcessTree } from "../lib/process-tree-termination.js";
|
|
42
48
|
import {
|
|
@@ -379,6 +385,7 @@ export const SUPPORTED_MCP_PROTOCOL_VERSIONS = Object.freeze([
|
|
|
379
385
|
"2025-03-26",
|
|
380
386
|
"2025-06-18",
|
|
381
387
|
MCP_PROTOCOL_VERSION,
|
|
388
|
+
MCP_STATELESS_PROTOCOL_VERSION,
|
|
382
389
|
]);
|
|
383
390
|
const supportedMcpProtocolVersions = new Set(SUPPORTED_MCP_PROTOCOL_VERSIONS);
|
|
384
391
|
|
|
@@ -455,6 +462,7 @@ function discoveryCacheKey(name, entry) {
|
|
|
455
462
|
entry?.httpUrl || entry?.socketUrl || config.url || null,
|
|
456
463
|
config.command || null,
|
|
457
464
|
Array.isArray(config.args) ? config.args : [],
|
|
465
|
+
entry?.protocolVersion ?? null,
|
|
458
466
|
]);
|
|
459
467
|
}
|
|
460
468
|
|
|
@@ -483,6 +491,23 @@ export function assertSupportedMcpProtocolVersion(value) {
|
|
|
483
491
|
}
|
|
484
492
|
return value;
|
|
485
493
|
}
|
|
494
|
+
|
|
495
|
+
export function mcpProtocolVersionField(config = {}) {
|
|
496
|
+
if (config.protocolVersion == null) return {};
|
|
497
|
+
const protocolVersion = assertSupportedMcpProtocolVersion(
|
|
498
|
+
config.protocolVersion,
|
|
499
|
+
);
|
|
500
|
+
if (
|
|
501
|
+
protocolVersion === MCP_STATELESS_PROTOCOL_VERSION &&
|
|
502
|
+
!["http", "https"].includes(inferTransport(config))
|
|
503
|
+
) {
|
|
504
|
+
throw mcpTaskError(
|
|
505
|
+
"CC_MCP_STATELESS_TRANSPORT_UNSUPPORTED",
|
|
506
|
+
"MCP stateless configuration requires Streamable HTTP",
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
return { protocolVersion };
|
|
510
|
+
}
|
|
486
511
|
const URL_ELICITATION_REQUIRED = -32042;
|
|
487
512
|
const MCP_RPC_ERROR_CODE = "CC_MCP_RPC_ERROR";
|
|
488
513
|
const mcpRpcControlData = new WeakMap();
|
|
@@ -1173,7 +1198,16 @@ function safeRpcErrorText(error) {
|
|
|
1173
1198
|
return typeof message === "string" ? message : "";
|
|
1174
1199
|
}
|
|
1175
1200
|
|
|
1201
|
+
function unsupportedStatelessClientRequest() {
|
|
1202
|
+
return mcpTaskError(
|
|
1203
|
+
"CC_MCP_STATELESS_CLIENT_REQUEST_UNSUPPORTED",
|
|
1204
|
+
"MCP stateless response requires unadvertised client interaction",
|
|
1205
|
+
true,
|
|
1206
|
+
);
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1176
1209
|
const MCP_NON_RETRYABLE_PROTOCOL_ERROR_CODES = new Set([
|
|
1210
|
+
"CC_MCP_STATELESS_CLIENT_REQUEST_UNSUPPORTED",
|
|
1177
1211
|
"CC_MCP_WS_PAYLOAD_TOO_LARGE",
|
|
1178
1212
|
"CC_MCP_WS_BINARY_MESSAGE",
|
|
1179
1213
|
"CC_MCP_WS_INVALID_MESSAGE",
|
|
@@ -1909,6 +1943,8 @@ export class MCPClient extends EventEmitter {
|
|
|
1909
1943
|
}
|
|
1910
1944
|
|
|
1911
1945
|
async _resolveElicitation(serverName, requestId, params = {}) {
|
|
1946
|
+
if (this.servers.get(String(serverName))?.statelessHttp)
|
|
1947
|
+
throw unsupportedStatelessClientRequest();
|
|
1912
1948
|
if (this._activeElicitations >= this._maxConcurrentElicitations) {
|
|
1913
1949
|
const request = normalizeMcpElicitationRequest(
|
|
1914
1950
|
serverName,
|
|
@@ -2133,6 +2169,7 @@ export class MCPClient extends EventEmitter {
|
|
|
2133
2169
|
}
|
|
2134
2170
|
|
|
2135
2171
|
_handleElicitationComplete(serverName, params = {}) {
|
|
2172
|
+
if (this.servers.get(String(serverName))?.statelessHttp) return false;
|
|
2136
2173
|
const elicitationId = String(params.elicitationId || "");
|
|
2137
2174
|
const entry = this._urlElicitations.get(elicitationId);
|
|
2138
2175
|
if (!entry || entry.server !== String(serverName)) {
|
|
@@ -2449,6 +2486,17 @@ export class MCPClient extends EventEmitter {
|
|
|
2449
2486
|
}
|
|
2450
2487
|
|
|
2451
2488
|
const transportKind = inferTransport(config);
|
|
2489
|
+
const requestedProtocolVersion = assertSupportedMcpProtocolVersion(
|
|
2490
|
+
config?.protocolVersion ?? this._protocolVersion,
|
|
2491
|
+
);
|
|
2492
|
+
const statelessHttp =
|
|
2493
|
+
requestedProtocolVersion === MCP_STATELESS_PROTOCOL_VERSION;
|
|
2494
|
+
if (statelessHttp && !["http", "https"].includes(transportKind)) {
|
|
2495
|
+
throw mcpTaskError(
|
|
2496
|
+
"CC_MCP_STATELESS_TRANSPORT_UNSUPPORTED",
|
|
2497
|
+
"MCP 2026-07-28 currently requires explicit Streamable HTTP configuration",
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2452
2500
|
let stdioExecutionApproval = null;
|
|
2453
2501
|
let approvedStdioInvocation = null;
|
|
2454
2502
|
if (transportKind === "stdio") {
|
|
@@ -2587,7 +2635,8 @@ export class MCPClient extends EventEmitter {
|
|
|
2587
2635
|
httpUrl: null,
|
|
2588
2636
|
httpHeaders: connectionHeaders,
|
|
2589
2637
|
httpSessionId: null,
|
|
2590
|
-
protocolVersion: null,
|
|
2638
|
+
protocolVersion: statelessHttp ? MCP_STATELESS_PROTOCOL_VERSION : null,
|
|
2639
|
+
statelessHttp,
|
|
2591
2640
|
_httpMessageStream: null,
|
|
2592
2641
|
_httpRequestControllers: new Set(),
|
|
2593
2642
|
_httpDiscardControllers: new Set(),
|
|
@@ -3175,33 +3224,63 @@ export class MCPClient extends EventEmitter {
|
|
|
3175
3224
|
this._transitionLifecycle(entry, MCP_LIFECYCLE_PHASES.INITIALIZING, {
|
|
3176
3225
|
tlsIdentityDigest: entry._tlsIdentityDigest,
|
|
3177
3226
|
});
|
|
3178
|
-
const initResult = await this._requestWithRetry(
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3227
|
+
const initResult = await this._requestWithRetry(
|
|
3228
|
+
name,
|
|
3229
|
+
statelessHttp ? "server/discover" : "initialize",
|
|
3230
|
+
statelessHttp
|
|
3231
|
+
? {}
|
|
3232
|
+
: {
|
|
3233
|
+
protocolVersion: requestedProtocolVersion,
|
|
3234
|
+
capabilities: {
|
|
3235
|
+
tools: {},
|
|
3236
|
+
resources: {},
|
|
3237
|
+
prompts: {},
|
|
3238
|
+
elicitation: supportsUrlElicitationVersion(
|
|
3239
|
+
requestedProtocolVersion,
|
|
3240
|
+
)
|
|
3241
|
+
? { form: {}, url: {} }
|
|
3242
|
+
: { form: {} },
|
|
3243
|
+
// Client-side roots capability: servers may request roots/list and
|
|
3244
|
+
// subscribe to list_changed notifications (Claude-Code 2.1.203).
|
|
3245
|
+
roots: { listChanged: true },
|
|
3246
|
+
},
|
|
3247
|
+
clientInfo: { name: "chainlesschain-cli", version: "0.37.9" },
|
|
3248
|
+
},
|
|
3196
3249
|
);
|
|
3250
|
+
|
|
3251
|
+
if (statelessHttp) {
|
|
3252
|
+
if (
|
|
3253
|
+
!Array.isArray(initResult?.supportedVersions) ||
|
|
3254
|
+
!initResult.supportedVersions.includes(MCP_STATELESS_PROTOCOL_VERSION)
|
|
3255
|
+
) {
|
|
3256
|
+
throw mcpTaskError(
|
|
3257
|
+
"CC_MCP_PROTOCOL_VERSION_UNSUPPORTED",
|
|
3258
|
+
"MCP discovery did not confirm the requested protocol",
|
|
3259
|
+
);
|
|
3260
|
+
}
|
|
3261
|
+
} else {
|
|
3262
|
+
entry.protocolVersion = assertSupportedMcpProtocolVersion(
|
|
3263
|
+
initResult?.protocolVersion,
|
|
3264
|
+
);
|
|
3265
|
+
if (entry.protocolVersion === MCP_STATELESS_PROTOCOL_VERSION) {
|
|
3266
|
+
throw mcpTaskError(
|
|
3267
|
+
"CC_MCP_PROTOCOL_VERSION_UNSUPPORTED",
|
|
3268
|
+
"MCP stateless protocol requires explicit discovery; initialization cannot upgrade it",
|
|
3269
|
+
);
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3197
3272
|
this._transitionLifecycle(entry, MCP_LIFECYCLE_PHASES.DISCOVERING, {
|
|
3198
3273
|
tlsIdentityDigest: entry._tlsIdentityDigest,
|
|
3199
3274
|
});
|
|
3200
3275
|
// Send initialized notification
|
|
3201
|
-
|
|
3276
|
+
if (!statelessHttp)
|
|
3277
|
+
this._sendNotification(name, "notifications/initialized", {});
|
|
3202
3278
|
|
|
3203
3279
|
entry.state = ServerState.CONNECTED;
|
|
3204
|
-
entry.serverInfo =
|
|
3280
|
+
entry.serverInfo =
|
|
3281
|
+
(statelessHttp
|
|
3282
|
+
? initResult?._meta?.["io.modelcontextprotocol/serverInfo"]
|
|
3283
|
+
: initResult?.serverInfo) || {};
|
|
3205
3284
|
entry.capabilities = initResult?.capabilities || {};
|
|
3206
3285
|
// Optional top-level usage instructions from the server's initialize
|
|
3207
3286
|
// response (previously discarded). Surfaced by tool search so a deferred
|
|
@@ -3363,6 +3442,7 @@ export class MCPClient extends EventEmitter {
|
|
|
3363
3442
|
});
|
|
3364
3443
|
if (
|
|
3365
3444
|
entry.httpUrl &&
|
|
3445
|
+
!entry.statelessHttp &&
|
|
3366
3446
|
(this._elicitationHandler || this._elicitationHandlers.size > 0)
|
|
3367
3447
|
) {
|
|
3368
3448
|
this._ensureHttpMessageStream(name);
|
|
@@ -3842,6 +3922,7 @@ export class MCPClient extends EventEmitter {
|
|
|
3842
3922
|
}
|
|
3843
3923
|
|
|
3844
3924
|
async _resolveRequiredUrlElicitations(serverName, error) {
|
|
3925
|
+
if (this.servers.get(serverName)?.statelessHttp) return false;
|
|
3845
3926
|
const requested = mcpRpcControlData.get(error)?.elicitations;
|
|
3846
3927
|
if (
|
|
3847
3928
|
!Array.isArray(requested) ||
|
|
@@ -3926,6 +4007,12 @@ export class MCPClient extends EventEmitter {
|
|
|
3926
4007
|
const release = reserveTaskBinding(this);
|
|
3927
4008
|
try {
|
|
3928
4009
|
const entry = this.servers.get(serverName);
|
|
4010
|
+
if (entry?.statelessHttp && options.ttl !== undefined) {
|
|
4011
|
+
throw mcpTaskError(
|
|
4012
|
+
"CC_MCP_TASK_TTL_UNSUPPORTED",
|
|
4013
|
+
"Stateless task TTL is selected by the server; a client TTL cannot be requested",
|
|
4014
|
+
);
|
|
4015
|
+
}
|
|
3929
4016
|
const identity = taskConnectionIdentity(entry || {});
|
|
3930
4017
|
let result;
|
|
3931
4018
|
try {
|
|
@@ -4077,7 +4164,12 @@ export class MCPClient extends EventEmitter {
|
|
|
4077
4164
|
}
|
|
4078
4165
|
let value;
|
|
4079
4166
|
try {
|
|
4080
|
-
value = await this._sendRequest(
|
|
4167
|
+
value = await this._sendRequest(
|
|
4168
|
+
serverName,
|
|
4169
|
+
entry.statelessHttp && kind === "result" ? "tasks/get" : method,
|
|
4170
|
+
params,
|
|
4171
|
+
options,
|
|
4172
|
+
);
|
|
4081
4173
|
} catch (error) {
|
|
4082
4174
|
if (
|
|
4083
4175
|
kind === "cancel" &&
|
|
@@ -4103,6 +4195,29 @@ export class MCPClient extends EventEmitter {
|
|
|
4103
4195
|
true,
|
|
4104
4196
|
);
|
|
4105
4197
|
}
|
|
4198
|
+
if (entry.statelessHttp) {
|
|
4199
|
+
if (kind === "cancel") {
|
|
4200
|
+
assertStatelessMcpAck(serverName, value, entry.config);
|
|
4201
|
+
// Acknowledgement means accepted, not cancelled. Obtain a separate
|
|
4202
|
+
// observation before reporting the remote terminal state.
|
|
4203
|
+
return this.getTask(serverName, params.taskId, options);
|
|
4204
|
+
}
|
|
4205
|
+
const modern = admitStatelessMcpTask(serverName, value, entry.config, {
|
|
4206
|
+
taskId: params.taskId,
|
|
4207
|
+
});
|
|
4208
|
+
rememberTasks(this, serverName, entry, identity, [modern.task]);
|
|
4209
|
+
if (kind === "result") {
|
|
4210
|
+
if (!modern.result) {
|
|
4211
|
+
throw mcpTaskError(
|
|
4212
|
+
"CC_MCP_TASK_RESULT_UNAVAILABLE",
|
|
4213
|
+
"MCP task has no completed result; no tool invocation was replayed",
|
|
4214
|
+
true,
|
|
4215
|
+
);
|
|
4216
|
+
}
|
|
4217
|
+
return modern.result;
|
|
4218
|
+
}
|
|
4219
|
+
return modern.task;
|
|
4220
|
+
}
|
|
4106
4221
|
const admitted = admitMcpTaskResponse(serverName, value, entry.config, {
|
|
4107
4222
|
kind,
|
|
4108
4223
|
taskId: params.taskId,
|
|
@@ -4236,7 +4351,7 @@ export class MCPClient extends EventEmitter {
|
|
|
4236
4351
|
{
|
|
4237
4352
|
name: toolName,
|
|
4238
4353
|
arguments: args,
|
|
4239
|
-
...(task === undefined ? {} : { task }),
|
|
4354
|
+
...(task === undefined || entry.statelessHttp ? {} : { task }),
|
|
4240
4355
|
_meta: { progressToken },
|
|
4241
4356
|
},
|
|
4242
4357
|
{ ...options, signal: controller.signal },
|
|
@@ -4275,6 +4390,12 @@ export class MCPClient extends EventEmitter {
|
|
|
4275
4390
|
true,
|
|
4276
4391
|
);
|
|
4277
4392
|
}
|
|
4393
|
+
if (entry.statelessHttp) {
|
|
4394
|
+
const modern = admitStatelessMcpTask(serverName, result, entry.config, {
|
|
4395
|
+
create: true,
|
|
4396
|
+
});
|
|
4397
|
+
return { task: modern.task };
|
|
4398
|
+
}
|
|
4278
4399
|
return admitMcpTaskResponse(serverName, result, entry.config, {
|
|
4279
4400
|
kind: "create",
|
|
4280
4401
|
});
|
|
@@ -4284,7 +4405,7 @@ export class MCPClient extends EventEmitter {
|
|
|
4284
4405
|
result,
|
|
4285
4406
|
entry.config,
|
|
4286
4407
|
).result;
|
|
4287
|
-
if (Object.hasOwn(admitted, "task")) {
|
|
4408
|
+
if (Object.hasOwn(admitted, "task") || admitted.resultType === "task") {
|
|
4288
4409
|
throw mcpTaskError(
|
|
4289
4410
|
"CC_MCP_TASK_UNEXPECTED",
|
|
4290
4411
|
"MCP task acceptance cannot settle an ordinary tool call",
|
|
@@ -4901,6 +5022,7 @@ export class MCPClient extends EventEmitter {
|
|
|
4901
5022
|
}
|
|
4902
5023
|
|
|
4903
5024
|
_sendRequestCancellation(serverName, method, requestId, reason) {
|
|
5025
|
+
if (this.servers.get(serverName)?.statelessHttp) return;
|
|
4904
5026
|
// The initialize handshake establishes the protocol/session needed for
|
|
4905
5027
|
// later notifications, so it cannot itself be cancelled safely.
|
|
4906
5028
|
if (method === "initialize") return;
|
|
@@ -4956,6 +5078,7 @@ export class MCPClient extends EventEmitter {
|
|
|
4956
5078
|
*/
|
|
4957
5079
|
_ensureHttpMessageStream(serverName) {
|
|
4958
5080
|
const entry = this.servers.get(serverName);
|
|
5081
|
+
if (entry?.statelessHttp) return false;
|
|
4959
5082
|
if (
|
|
4960
5083
|
!entry?.httpUrl ||
|
|
4961
5084
|
entry.state !== ServerState.CONNECTED ||
|
|
@@ -5137,7 +5260,19 @@ export class MCPClient extends EventEmitter {
|
|
|
5137
5260
|
}
|
|
5138
5261
|
|
|
5139
5262
|
const id = this._nextId++;
|
|
5140
|
-
const
|
|
5263
|
+
const modern = entry.statelessHttp
|
|
5264
|
+
? statelessMcpRequest(method, params, {
|
|
5265
|
+
tasks:
|
|
5266
|
+
options[MCP_TASK_REQUEST] !== undefined ||
|
|
5267
|
+
method.startsWith("tasks/"),
|
|
5268
|
+
})
|
|
5269
|
+
: null;
|
|
5270
|
+
const body = JSON.stringify({
|
|
5271
|
+
jsonrpc: "2.0",
|
|
5272
|
+
id,
|
|
5273
|
+
method,
|
|
5274
|
+
params: modern?.params || params,
|
|
5275
|
+
});
|
|
5141
5276
|
this._registerLifecycleRpc(entry, id, method);
|
|
5142
5277
|
let lifecycleSettled = false;
|
|
5143
5278
|
const settleLifecycle = (outcome) => {
|
|
@@ -5158,6 +5293,20 @@ export class MCPClient extends EventEmitter {
|
|
|
5158
5293
|
headers["MCP-Protocol-Version"] =
|
|
5159
5294
|
entry.protocolVersion || this._protocolVersion;
|
|
5160
5295
|
}
|
|
5296
|
+
if (modern) {
|
|
5297
|
+
for (const key of Object.keys(headers)) {
|
|
5298
|
+
if (
|
|
5299
|
+
[
|
|
5300
|
+
"mcp-session-id",
|
|
5301
|
+
"mcp-protocol-version",
|
|
5302
|
+
"mcp-method",
|
|
5303
|
+
"mcp-name",
|
|
5304
|
+
].includes(key.toLowerCase())
|
|
5305
|
+
)
|
|
5306
|
+
delete headers[key];
|
|
5307
|
+
}
|
|
5308
|
+
Object.assign(headers, modern.headers);
|
|
5309
|
+
}
|
|
5161
5310
|
|
|
5162
5311
|
// Every request owns a controller so caller cancellation and disconnect
|
|
5163
5312
|
// remain enforceable even when its optional deadline is disabled.
|
|
@@ -5280,6 +5429,7 @@ export class MCPClient extends EventEmitter {
|
|
|
5280
5429
|
? response.headers.get("mcp-session-id") ||
|
|
5281
5430
|
response.headers.get("Mcp-Session-Id")
|
|
5282
5431
|
: null) || null;
|
|
5432
|
+
if (sessionId && entry.statelessHttp) throw mcpRpcInvalidResponseError();
|
|
5283
5433
|
if (sessionId && !entry.httpSessionId) {
|
|
5284
5434
|
entry.httpSessionId = sessionId;
|
|
5285
5435
|
}
|
|
@@ -5350,7 +5500,18 @@ export class MCPClient extends EventEmitter {
|
|
|
5350
5500
|
response,
|
|
5351
5501
|
id,
|
|
5352
5502
|
cap,
|
|
5353
|
-
(message) =>
|
|
5503
|
+
(message) =>
|
|
5504
|
+
entry.statelessHttp
|
|
5505
|
+
? this._handleStatelessProgress(
|
|
5506
|
+
serverName,
|
|
5507
|
+
entry,
|
|
5508
|
+
message,
|
|
5509
|
+
safeRpcProperty(
|
|
5510
|
+
safeRpcProperty(params, "_meta"),
|
|
5511
|
+
"progressToken",
|
|
5512
|
+
),
|
|
5513
|
+
)
|
|
5514
|
+
: this._handleMessage(serverName, message, entry),
|
|
5354
5515
|
controller?.signal,
|
|
5355
5516
|
(text) => parseMcpJson(text, serverName, entry),
|
|
5356
5517
|
);
|
|
@@ -5382,6 +5543,18 @@ export class MCPClient extends EventEmitter {
|
|
|
5382
5543
|
if (wire.hasError) {
|
|
5383
5544
|
throw mcpRpcError(wire.error);
|
|
5384
5545
|
}
|
|
5546
|
+
if (
|
|
5547
|
+
entry.statelessHttp &&
|
|
5548
|
+
(!wire.result ||
|
|
5549
|
+
(wire.result.resultType !== "complete" &&
|
|
5550
|
+
!(method === "tools/call" && wire.result.resultType === "task")))
|
|
5551
|
+
) {
|
|
5552
|
+
throw mcpTaskError(
|
|
5553
|
+
"CC_MCP_STATELESS_RESULT_UNSUPPORTED",
|
|
5554
|
+
"MCP result requires an unsupported continuation; no request was replayed",
|
|
5555
|
+
true,
|
|
5556
|
+
);
|
|
5557
|
+
}
|
|
5385
5558
|
throwIfAborted();
|
|
5386
5559
|
if (!settleLifecycle("completed")) {
|
|
5387
5560
|
throw this._staleLifecycleCallbackError();
|
|
@@ -5419,7 +5592,13 @@ export class MCPClient extends EventEmitter {
|
|
|
5419
5592
|
/** Fire-and-forget JSON-RPC notification over HTTP. Errors swallowed. */
|
|
5420
5593
|
_sendHttpNotification(serverName, method, params) {
|
|
5421
5594
|
const entry = this.servers.get(serverName);
|
|
5422
|
-
if (
|
|
5595
|
+
if (
|
|
5596
|
+
!entry ||
|
|
5597
|
+
!entry.httpUrl ||
|
|
5598
|
+
entry._httpDiscardStopping ||
|
|
5599
|
+
entry.statelessHttp
|
|
5600
|
+
)
|
|
5601
|
+
return;
|
|
5423
5602
|
const body = JSON.stringify({ jsonrpc: "2.0", method, params });
|
|
5424
5603
|
const headers = {
|
|
5425
5604
|
"Content-Type": "application/json",
|
|
@@ -5631,10 +5810,55 @@ export class MCPClient extends EventEmitter {
|
|
|
5631
5810
|
return error;
|
|
5632
5811
|
}
|
|
5633
5812
|
|
|
5813
|
+
_handleStatelessProgress(serverName, entry, message, expectedToken) {
|
|
5814
|
+
if (this.servers.get(serverName) !== entry)
|
|
5815
|
+
throw this._staleLifecycleCallbackError();
|
|
5816
|
+
const wire = snapshotRpcMessage(message);
|
|
5817
|
+
// Stateless requests advertise no reverse-RPC or subscription authority.
|
|
5818
|
+
// Reject the whole response before dispatching an unexpected SSE envelope;
|
|
5819
|
+
// a later tool result cannot erase callbacks or data already sent to a peer.
|
|
5820
|
+
if (
|
|
5821
|
+
!wire ||
|
|
5822
|
+
!wire.hasJsonrpc ||
|
|
5823
|
+
wire.jsonrpc !== "2.0" ||
|
|
5824
|
+
wire.hasId ||
|
|
5825
|
+
wire.hasResult ||
|
|
5826
|
+
wire.hasError ||
|
|
5827
|
+
!wire.hasMethod ||
|
|
5828
|
+
wire.method !== "notifications/progress" ||
|
|
5829
|
+
typeof expectedToken !== "string" ||
|
|
5830
|
+
expectedToken.length === 0 ||
|
|
5831
|
+
safeRpcProperty(wire.params, "progressToken") !== expectedToken
|
|
5832
|
+
)
|
|
5833
|
+
throw unsupportedStatelessClientRequest();
|
|
5834
|
+
this._handleToolProgress(serverName, wire.params);
|
|
5835
|
+
}
|
|
5836
|
+
|
|
5837
|
+
_handleToolProgress(serverName, params) {
|
|
5838
|
+
const progressToken = safeRpcProperty(params, "progressToken");
|
|
5839
|
+
const resetIdle =
|
|
5840
|
+
typeof progressToken === "string"
|
|
5841
|
+
? this._toolProgress.get(progressToken)
|
|
5842
|
+
: null;
|
|
5843
|
+
if (resetIdle) resetIdle();
|
|
5844
|
+
// Peer status text is tool data, not host diagnostics or interaction.
|
|
5845
|
+
this.emit("tool-progress", {
|
|
5846
|
+
server: serverName,
|
|
5847
|
+
...(typeof progressToken === "string" ? { progressToken } : {}),
|
|
5848
|
+
...(Number.isFinite(safeRpcProperty(params, "progress"))
|
|
5849
|
+
? { progress: safeRpcProperty(params, "progress") }
|
|
5850
|
+
: {}),
|
|
5851
|
+
...(Number.isFinite(safeRpcProperty(params, "total"))
|
|
5852
|
+
? { total: safeRpcProperty(params, "total") }
|
|
5853
|
+
: {}),
|
|
5854
|
+
});
|
|
5855
|
+
}
|
|
5856
|
+
|
|
5634
5857
|
_handleMessage(serverName, msg, sourceEntry = null) {
|
|
5635
5858
|
const currentEntry = this.servers.get(serverName);
|
|
5636
5859
|
const entry = sourceEntry || currentEntry;
|
|
5637
|
-
|
|
5860
|
+
// HTTP stateless progress has a separate request-correlated admission path.
|
|
5861
|
+
if (!entry || entry.statelessHttp) return;
|
|
5638
5862
|
if (sourceEntry && currentEntry !== sourceEntry) {
|
|
5639
5863
|
const wire = snapshotRpcMessage(msg);
|
|
5640
5864
|
if (wire?.hasId && !wire.hasMethod) {
|
|
@@ -5764,24 +5988,7 @@ export class MCPClient extends EventEmitter {
|
|
|
5764
5988
|
this._refreshServerList(serverName, "resources");
|
|
5765
5989
|
this._refreshServerList(serverName, "resourceTemplates");
|
|
5766
5990
|
} else if (wire.method === "notifications/progress") {
|
|
5767
|
-
|
|
5768
|
-
const resetIdle =
|
|
5769
|
-
typeof progressToken === "string"
|
|
5770
|
-
? this._toolProgress.get(progressToken)
|
|
5771
|
-
: null;
|
|
5772
|
-
if (resetIdle) resetIdle();
|
|
5773
|
-
// Project only numeric progress. Server-controlled status text belongs
|
|
5774
|
-
// to the tool result, not host diagnostics/events.
|
|
5775
|
-
this.emit("tool-progress", {
|
|
5776
|
-
server: serverName,
|
|
5777
|
-
...(typeof progressToken === "string" ? { progressToken } : {}),
|
|
5778
|
-
...(Number.isFinite(safeRpcProperty(wire.params, "progress"))
|
|
5779
|
-
? { progress: safeRpcProperty(wire.params, "progress") }
|
|
5780
|
-
: {}),
|
|
5781
|
-
...(Number.isFinite(safeRpcProperty(wire.params, "total"))
|
|
5782
|
-
? { total: safeRpcProperty(wire.params, "total") }
|
|
5783
|
-
: {}),
|
|
5784
|
-
});
|
|
5991
|
+
this._handleToolProgress(serverName, wire.params);
|
|
5785
5992
|
} else if (wire.method === "notifications/resources/updated") {
|
|
5786
5993
|
this.emit("resource-updated", {
|
|
5787
5994
|
server: serverName,
|
|
@@ -5912,6 +6119,7 @@ export class MCPClient extends EventEmitter {
|
|
|
5912
6119
|
* method-not-found error instead of silence, so the server fails fast.
|
|
5913
6120
|
*/
|
|
5914
6121
|
_handleServerRequest(serverName, msg) {
|
|
6122
|
+
if (this.servers.get(serverName)?.statelessHttp) return;
|
|
5915
6123
|
const { id, method } = msg;
|
|
5916
6124
|
if (method === "roots/list") {
|
|
5917
6125
|
this._sendResponse(serverName, id, { roots: this.listRoots() });
|
|
@@ -5941,7 +6149,7 @@ export class MCPClient extends EventEmitter {
|
|
|
5941
6149
|
/** Write a JSON-RPC response back over stdio or Streamable HTTP POST. */
|
|
5942
6150
|
_sendResponse(serverName, id, result, error) {
|
|
5943
6151
|
const entry = this.servers.get(serverName);
|
|
5944
|
-
if (!entry || entry._httpDiscardStopping) return;
|
|
6152
|
+
if (!entry || entry._httpDiscardStopping || entry.statelessHttp) return;
|
|
5945
6153
|
const envelope =
|
|
5946
6154
|
error !== undefined
|
|
5947
6155
|
? { jsonrpc: "2.0", id, error }
|
|
@@ -6530,6 +6738,7 @@ export class MCPServerConfig {
|
|
|
6530
6738
|
transport TEXT DEFAULT 'stdio',
|
|
6531
6739
|
headers TEXT DEFAULT '{}',
|
|
6532
6740
|
headers_helper TEXT,
|
|
6741
|
+
protocol_version TEXT,
|
|
6533
6742
|
config_scope TEXT DEFAULT 'user',
|
|
6534
6743
|
config_source TEXT,
|
|
6535
6744
|
project_path TEXT,
|
|
@@ -6578,6 +6787,11 @@ export class MCPServerConfig {
|
|
|
6578
6787
|
if (!cols.has("headers_helper")) {
|
|
6579
6788
|
this.db.exec("ALTER TABLE mcp_servers ADD COLUMN headers_helper TEXT");
|
|
6580
6789
|
}
|
|
6790
|
+
if (!cols.has("protocol_version")) {
|
|
6791
|
+
this.db.exec(
|
|
6792
|
+
"ALTER TABLE mcp_servers ADD COLUMN protocol_version TEXT",
|
|
6793
|
+
);
|
|
6794
|
+
}
|
|
6581
6795
|
if (!cols.has("config_scope")) {
|
|
6582
6796
|
this.db.exec(
|
|
6583
6797
|
"ALTER TABLE mcp_servers ADD COLUMN config_scope TEXT DEFAULT 'user'",
|
|
@@ -6653,6 +6867,11 @@ export class MCPServerConfig {
|
|
|
6653
6867
|
const existingRow = this.db
|
|
6654
6868
|
.prepare("SELECT * FROM mcp_servers WHERE name = ?")
|
|
6655
6869
|
.get(storageName);
|
|
6870
|
+
const protocolVersion =
|
|
6871
|
+
config.protocolVersion === undefined
|
|
6872
|
+
? (existingRow?.protocol_version ?? null)
|
|
6873
|
+
: config.protocolVersion;
|
|
6874
|
+
mcpProtocolVersionField({ ...config, protocolVersion });
|
|
6656
6875
|
const cwdUpdate = readMcpStdioCwd(config, {
|
|
6657
6876
|
label: `MCP server "${name}"`,
|
|
6658
6877
|
});
|
|
@@ -6675,7 +6894,7 @@ export class MCPServerConfig {
|
|
|
6675
6894
|
}
|
|
6676
6895
|
this.db
|
|
6677
6896
|
.prepare(
|
|
6678
|
-
"INSERT OR REPLACE INTO mcp_servers (name, command, args, env, runtime_kind, cwd, sandbox_policy, auto_connect, url, transport, headers, headers_helper, config_scope, config_source, project_path, display_name, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))",
|
|
6897
|
+
"INSERT OR REPLACE INTO mcp_servers (name, command, args, env, runtime_kind, cwd, sandbox_policy, auto_connect, url, transport, headers, headers_helper, protocol_version, config_scope, config_source, project_path, display_name, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, datetime('now'))",
|
|
6679
6898
|
)
|
|
6680
6899
|
.run(
|
|
6681
6900
|
storageName,
|
|
@@ -6690,6 +6909,7 @@ export class MCPServerConfig {
|
|
|
6690
6909
|
transport,
|
|
6691
6910
|
JSON.stringify(config.headers || {}),
|
|
6692
6911
|
headersHelper,
|
|
6912
|
+
protocolVersion,
|
|
6693
6913
|
configScope,
|
|
6694
6914
|
configSource,
|
|
6695
6915
|
projectPath,
|
|
@@ -6757,6 +6977,11 @@ export class MCPServerConfig {
|
|
|
6757
6977
|
transport:
|
|
6758
6978
|
row.transport || (row.url ? inferTransport({ url: row.url }) : "stdio"),
|
|
6759
6979
|
headers: safeJsonParse(row.headers, {}),
|
|
6980
|
+
...mcpProtocolVersionField({
|
|
6981
|
+
protocolVersion: row.protocol_version,
|
|
6982
|
+
url: row.url,
|
|
6983
|
+
transport: row.transport,
|
|
6984
|
+
}),
|
|
6760
6985
|
...(typeof row.headers_helper === "string" && row.headers_helper.trim()
|
|
6761
6986
|
? { headersHelper: row.headers_helper }
|
|
6762
6987
|
: {}),
|
|
@@ -131,6 +131,7 @@ function summaryPrompt(messages, maxChars) {
|
|
|
131
131
|
`Return exactly one strict JSON object with all keys in this order: ${schema}.`,
|
|
132
132
|
'"objective" must be a string; every other value must be an array of strings.',
|
|
133
133
|
"Preserve constraints, exact file paths, test evidence, unresolved external side effects, blockers, and actionable next steps. Do not use Markdown.",
|
|
134
|
+
"Keep the JSON concise: use short phrases, avoid repetition, and target no more than 3 items per array so the complete object fits a bounded response.",
|
|
134
135
|
"Conversation history:",
|
|
135
136
|
].join("\n");
|
|
136
137
|
const historyBudget = Math.max(0, maxChars - instructions.length - 1);
|
|
@@ -24,6 +24,7 @@ import { ensureClaudeProjectStorageTree, getHomeDir } from "../lib/paths.js";
|
|
|
24
24
|
import { resolveClaudeProjectStorageDir } from "../lib/claude-project-storage-layout.js";
|
|
25
25
|
import { ensurePrivateDirectory, ensurePrivateFile } from "../lib/secure-fs.js";
|
|
26
26
|
import { readVerifiedProjection } from "./jsonl-session-store.js";
|
|
27
|
+
import { projectSessionInputMessages } from "../lib/session-input-lifecycle.js";
|
|
27
28
|
|
|
28
29
|
const requireCjs = createRequire(import.meta.url);
|
|
29
30
|
|
|
@@ -156,6 +157,13 @@ function summarizeVerifiedSession(id) {
|
|
|
156
157
|
messageCount += 2;
|
|
157
158
|
acceptContent(event.data.user.content);
|
|
158
159
|
acceptContent(event.data.assistant.content);
|
|
160
|
+
} else if (event.type === "session_input_settled") {
|
|
161
|
+
const pair = projectSessionInputMessages(event);
|
|
162
|
+
if (pair) {
|
|
163
|
+
messageCount += 2;
|
|
164
|
+
acceptContent(pair[0].content);
|
|
165
|
+
acceptContent(pair[1].content);
|
|
166
|
+
}
|
|
159
167
|
}
|
|
160
168
|
if (typeof event.hash === "string") chainHash = event.hash;
|
|
161
169
|
},
|
|
@@ -290,6 +290,8 @@ export function applyEventToSessionMeta(meta, event, lastHash) {
|
|
|
290
290
|
event.data?.assistant?.role === "assistant"
|
|
291
291
|
) {
|
|
292
292
|
next.message_count = Math.max(0, Number(next.message_count) || 0) + 2;
|
|
293
|
+
} else if (event?.type === "session_input_settled") {
|
|
294
|
+
next.message_count = Math.max(0, Number(next.message_count) || 0) + 2;
|
|
293
295
|
}
|
|
294
296
|
const generation = normalizeSessionGenerationAuthority(
|
|
295
297
|
event?.data?.[SESSION_GENERATION_AUTHORITY_FIELD],
|
|
@@ -14,6 +14,7 @@ import { projectToolRoundMessages } from "./session-tool-round.js";
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
export const TOOL_BLOCK_CAP = 4000;
|
|
17
|
+
import { projectSessionInputMessages } from "./session-input-lifecycle.js";
|
|
17
18
|
|
|
18
19
|
function asText(content) {
|
|
19
20
|
if (content == null) return "";
|
|
@@ -116,6 +117,24 @@ export function renderAgentSessionMarkdown(sessionId, events, opts = {}) {
|
|
|
116
117
|
L.push("");
|
|
117
118
|
}
|
|
118
119
|
break;
|
|
120
|
+
case "session_input_settled": {
|
|
121
|
+
const pair = projectSessionInputMessages(ev);
|
|
122
|
+
if (pair) {
|
|
123
|
+
users += 1;
|
|
124
|
+
assistants += 1;
|
|
125
|
+
L.push(
|
|
126
|
+
"## 👤 User",
|
|
127
|
+
"",
|
|
128
|
+
asText(pair[0].content),
|
|
129
|
+
"",
|
|
130
|
+
"## 🤖 Assistant",
|
|
131
|
+
"",
|
|
132
|
+
asText(pair[1].content),
|
|
133
|
+
"",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
119
138
|
case "system":
|
|
120
139
|
L.push("## ⚙ System");
|
|
121
140
|
L.push("");
|
|
@@ -2,6 +2,7 @@ const MEMORY_MUTATION_EVENTS = new Set([
|
|
|
2
2
|
"memory.candidate.created",
|
|
3
3
|
"memory.activated",
|
|
4
4
|
"memory.reinforced",
|
|
5
|
+
"memory.corrected",
|
|
5
6
|
"memory.superseded",
|
|
6
7
|
"memory.expired",
|
|
7
8
|
]);
|
|
@@ -29,12 +30,20 @@ export function memoryMutationNotification(mutation) {
|
|
|
29
30
|
memory_id: mutation.record.memoryId,
|
|
30
31
|
revision: mutation.record.revision,
|
|
31
32
|
record_digest: mutation.record.digest,
|
|
32
|
-
|
|
33
|
+
...(mutation.event.type === "memory.corrected"
|
|
34
|
+
? {
|
|
35
|
+
previous_revision: mutation.event.previousRevision,
|
|
36
|
+
previous_record_digest: mutation.event.previousRecordDigest,
|
|
37
|
+
}
|
|
38
|
+
: { record: mutation.record }),
|
|
33
39
|
},
|
|
34
40
|
};
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
export function memoryDeletionNotification(
|
|
43
|
+
export function memoryDeletionNotification(
|
|
44
|
+
receipt,
|
|
45
|
+
operationId = receipt?.requestId,
|
|
46
|
+
) {
|
|
38
47
|
if (!receipt?.memoryId || !receipt?.recordDigest || !receipt?.revision) {
|
|
39
48
|
return null;
|
|
40
49
|
}
|