@codexhost/cli-darwin-x64 0.10.0 → 0.10.1

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.
@@ -20861,7 +20861,8 @@ var ModernRemoteConnection = class {
20861
20861
  } catch (error51) {
20862
20862
  throw this.#transportFailure("DeepSeek Harness Web authentication failed", error51);
20863
20863
  }
20864
- if (response.status !== 303 || response.headers.get("location") !== "/") {
20864
+ const location = response.headers.get("location");
20865
+ if (response.status !== 303 || location !== "/" && location !== "./") {
20865
20866
  await cancelResponse(response);
20866
20867
  throw new ModernRemoteConnectionError(response.status === 401 || response.status === 403 ? "authenticationRequired" : "protocolError", "DeepSeek Harness Web rejected its bootstrap authentication exchange");
20867
20868
  }
@@ -21393,7 +21394,7 @@ function parseEvent(value, format = 0) {
21393
21394
  throw protocolError("journal event has invalid scalar fields");
21394
21395
  }
21395
21396
  assertJsonValue(value.data, "journal event data");
21396
- if (format === 3 && value.ignorable === true) {
21397
+ if (format >= 3 && value.ignorable === true) {
21397
21398
  if (Object.hasOwn(value, "sourceEventSeqs"))
21398
21399
  assertJsonValue(value.sourceEventSeqs, "journal event sourceEventSeqs");
21399
21400
  if (Object.hasOwn(value, "surfaceOp"))
@@ -21412,8 +21413,8 @@ function parseEvent(value, format = 0) {
21412
21413
  function parseSurfaceOp(value, format) {
21413
21414
  if (value === "append")
21414
21415
  return value;
21415
- const start = format === 3 ? "startSeq" : "start";
21416
- const end = format === 3 ? "endSeq" : "end";
21416
+ const start = format >= 3 ? "startSeq" : "start";
21417
+ const end = format >= 3 ? "endSeq" : "end";
21417
21418
  if (!isRecord3(value) || !hasExactKeys2(value, ["op", start, end]) || value.op !== "replace" || !isSeq(value[start]) || !isSeq(value[end])) {
21418
21419
  throw protocolError("journal event has an invalid surfaceOp");
21419
21420
  }
@@ -21915,12 +21916,33 @@ function parseArguments(value) {
21915
21916
  return value;
21916
21917
  }
21917
21918
  }
21919
+ function contentText(value) {
21920
+ if (!isRecord4(value) || !Array.isArray(value.content))
21921
+ return "";
21922
+ return value.content.filter((block) => isRecord4(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text).join("");
21923
+ }
21918
21924
  function projectToolResult(value, limit) {
21919
21925
  if (!isRecord4(value) || !isRecord4(value.source) || value.source.kind !== "tool")
21920
21926
  return null;
21921
21927
  const callId = value.source.callId;
21922
21928
  if (!nonBlankString(callId) || !Array.isArray(value.content))
21923
21929
  return null;
21930
+ if (value.role === "tool") {
21931
+ if (value.toolCallId !== callId || value.isError !== void 0 && typeof value.isError !== "boolean")
21932
+ return null;
21933
+ const text2 = contentText(value);
21934
+ const truncated2 = text2.length > limit;
21935
+ return {
21936
+ callId,
21937
+ failed: value.isError === true,
21938
+ ...text2 ? {
21939
+ output: {
21940
+ content: [{ type: "text", text: truncated2 ? text2.slice(0, limit) : text2 }],
21941
+ ...truncated2 ? { truncated: true } : {}
21942
+ }
21943
+ } : {}
21944
+ };
21945
+ }
21924
21946
  const resultBlocks = value.content.filter((block) => isRecord4(block) && block.type === "tool-result" && block.toolCallId === callId && Array.isArray(block.content));
21925
21947
  if (resultBlocks.length === 0)
21926
21948
  return null;
@@ -22036,6 +22058,12 @@ function projectTurnReason(value) {
22036
22058
  history: { status: "cancelled", reason: "Cancelled by user" }
22037
22059
  };
22038
22060
  }
22061
+ if (value.kind === "forked") {
22062
+ return {
22063
+ outcome: { status: "cancelled", reason: "Forked from parent Session" },
22064
+ history: { status: "cancelled", reason: "Forked from parent Session" }
22065
+ };
22066
+ }
22039
22067
  const error51 = {
22040
22068
  code: "nativeFailure",
22041
22069
  message: value.kind === "error" && isRecord4(value.error) && typeof value.error.message === "string" ? value.error.message : `DeepSeek Harness Turn ended with '${value.kind}'`,
@@ -22174,6 +22202,12 @@ function positiveInteger(value, label) {
22174
22202
  function nonNegativeInteger(value, label) {
22175
22203
  return boundedInteger(value, label, 0);
22176
22204
  }
22205
+ function nonNegativeFiniteNumber(value, label) {
22206
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
22207
+ fail(`${label} must be a finite number greater than or equal to 0`);
22208
+ }
22209
+ return value;
22210
+ }
22177
22211
  function nonNegativeSafeInteger2(value) {
22178
22212
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
22179
22213
  }
@@ -22874,13 +22908,219 @@ function matchesForkTail2(expectedPrefix, childEvents) {
22874
22908
  return childOwned.every((event) => event.type !== "turn/start" && event.type !== "session/end-seed");
22875
22909
  }
22876
22910
 
22911
+ // dist/profiles/v017.js
22912
+ function invalid2(label) {
22913
+ throw new ModernHistoryError("protocolError", `DSH V4 ${label} is malformed`);
22914
+ }
22915
+ function requiredFields(value, fields) {
22916
+ if (fields.some((field) => !Object.hasOwn(value, field)))
22917
+ invalid2("required fields");
22918
+ }
22919
+ function validateV4Content(value) {
22920
+ if (!Array.isArray(value))
22921
+ invalid2("content");
22922
+ for (const block of value) {
22923
+ if (!isRecord3(block) || block.type === "tool-result")
22924
+ invalid2("content block");
22925
+ if (block.type === "tool-addition" || block.type === "tool-removal") {
22926
+ requiredString(block.toolName, "tool change toolName");
22927
+ continue;
22928
+ }
22929
+ if (block.type === "image" && block.offloaded !== void 0 && block.offloaded !== true) {
22930
+ invalid2("image offloaded marker");
22931
+ }
22932
+ const ordinary = Object.fromEntries(Object.entries(block).filter(([key]) => key !== "offloaded"));
22933
+ const canonical = block.type === "text" || block.type === "reasoning" ? { type: block.type, text: block.text } : block.type === "image" || block.type === "file" ? { type: block.type, attachment: block.attachment } : block.type === "tool-call" ? { type: block.type, id: block.id, name: block.name, arguments: block.arguments } : ordinary;
22934
+ DEEPSEEK_V015_PROFILE.validateContent([canonical]);
22935
+ }
22936
+ }
22937
+ function validateV4Chunk(value) {
22938
+ DEEPSEEK_V015_PROFILE.validateChunk(value);
22939
+ if (!isRecord3(value))
22940
+ invalid2("assistant chunk");
22941
+ const blockType = value.type === "block-start" ? value.blockType : value.type === "block-end" && isRecord3(value.block) ? value.block.type : void 0;
22942
+ if (blockType === "tool-result" || blockType === "tool-addition" || blockType === "tool-removal") {
22943
+ invalid2("assistant tool-change block");
22944
+ }
22945
+ }
22946
+ function validateV4Stream(value) {
22947
+ for (const entry of expandV015AssistantStream(value))
22948
+ validateV4Chunk(entry.chunk);
22949
+ }
22950
+ function validateDeveloperMessage(event) {
22951
+ if (!isRecord3(event.data))
22952
+ invalid2("developer/message data");
22953
+ const data = event.data;
22954
+ requiredFields(data, ["turn", "step", "message"]);
22955
+ if (Object.hasOwn(data, "headerSeq") && !Number.isSafeInteger(data.headerSeq))
22956
+ invalid2("developer/message headerSeq");
22957
+ positiveInteger(data.turn, "developer/message turn");
22958
+ positiveInteger(data.step, "developer/message step");
22959
+ if (!isRecord3(data.message))
22960
+ invalid2("developer/message message");
22961
+ const message = data.message;
22962
+ requiredFields(message, ["id", "role", "content", "source"]);
22963
+ requiredString(message.id, "developer/message id");
22964
+ if (message.role !== "developer" || !isRecord3(message.source) || typeof message.source.kind !== "string" || !message.source.kind || message.source.kind === "plugin" || !Array.isArray(message.content)) {
22965
+ invalid2("developer/message role, source or content");
22966
+ }
22967
+ let additions = false;
22968
+ for (const block of message.content) {
22969
+ if (!isRecord3(block))
22970
+ invalid2("developer content block");
22971
+ if (block.type === "tool-addition" || block.type === "tool-removal") {
22972
+ requiredString(block.toolName, "developer toolName");
22973
+ additions ||= block.type === "tool-addition";
22974
+ } else {
22975
+ validateV4Content([block]);
22976
+ }
22977
+ }
22978
+ if (additions !== Object.hasOwn(data, "headerSeq") || additions && (!Number.isSafeInteger(data.headerSeq) || Object.is(data.headerSeq, -0) || data.headerSeq < 0 || data.headerSeq >= event.seq)) {
22979
+ invalid2("developer/message headerSeq");
22980
+ }
22981
+ }
22982
+ function matchesV4ForkTail(prefix, child) {
22983
+ if (!DEEPSEEK_V015_PROFILE.matchesForkTail(prefix, child))
22984
+ return false;
22985
+ const tail = child.slice(prefix.length + 1);
22986
+ const openTurn = prefix.reduce((turn, event) => event.type === "turn/start" ? event.data.turn : event.type === "turn/end" ? null : turn, null);
22987
+ const closer = tail.find((event) => event.type === "turn/end");
22988
+ if (openTurn === null)
22989
+ return closer === void 0 && !tail.some((event) => event.type === "step/end");
22990
+ return closer !== void 0 && isRecord3(closer.data) && closer.data.turn === openTurn && isRecord3(closer.data.reason) && closer.data.reason.kind === "forked";
22991
+ }
22992
+ var DEEPSEEK_V017_PROFILE = Object.freeze({
22993
+ ...DEEPSEEK_V015_PROFILE,
22994
+ version: "0.1.7-rc.1",
22995
+ checkpointPrefix: "v4-turn-end:",
22996
+ sessionFormatVersion: 4,
22997
+ matchesForkTail: matchesV4ForkTail,
22998
+ parseHeader(value, expected) {
22999
+ if (!isRecord3(value) || value.version !== 4)
23000
+ invalid2("journal header");
23001
+ if (value.delegationDepth !== void 0 && (!Number.isSafeInteger(value.delegationDepth) || Object.is(value.delegationDepth, -0) || value.delegationDepth < 0)) {
23002
+ invalid2("journal header delegationDepth");
23003
+ }
23004
+ const delegationDepth = value.delegationDepth ?? 0;
23005
+ DEEPSEEK_V015_PROFILE.parseHeader({ ...value, version: 3, delegationDepth }, expected);
23006
+ return { ...value, delegationDepth };
23007
+ },
23008
+ parseHistoryRecord: (value, remaining) => parseV015HistoryRecord(value, remaining, (event) => parseEvent(event, 4)),
23009
+ parseLiveItem: (value) => {
23010
+ const item = parseV015LiveItem(value, (event) => parseEvent(event, 4));
23011
+ if (item.type === "assistant-stream" && "frame" in item && item.frame.type === "chunk") {
23012
+ validateV4Chunk(item.frame.chunk);
23013
+ }
23014
+ return item;
23015
+ },
23016
+ parseAssistantBaseline(value) {
23017
+ const baseline = parseV015AssistantBaseline(value);
23018
+ if (baseline.activeAttempt)
23019
+ validateV4Stream(baseline.activeAttempt.stream);
23020
+ return baseline;
23021
+ },
23022
+ validateContent: validateV4Content,
23023
+ validateChunk: validateV4Chunk,
23024
+ validateEvent(event) {
23025
+ if (event.type === "developer/message") {
23026
+ validateDeveloperMessage(event);
23027
+ } else if (event.type === "system/message") {
23028
+ if (!isRecord3(event.data) || !isRecord3(event.data.message))
23029
+ invalid2("system/message");
23030
+ exactKeys2(event.data, ["turn", "step", "message"]);
23031
+ const message = event.data.message;
23032
+ requiredFields(message, ["id", "role", "content", "source"]);
23033
+ requiredString(message.id, "system/message id");
23034
+ if (message.role !== "system" || !isRecord3(message.source) || message.source.kind !== "system-prompt") {
23035
+ invalid2("system/message source");
23036
+ }
23037
+ validateV4Content(message.content);
23038
+ } else if (event.type === "image/offload") {
23039
+ if (!isRecord3(event.data))
23040
+ invalid2("image/offload");
23041
+ exactKeys2(event.data, ["targets"]);
23042
+ if (!Array.isArray(event.data.targets) || event.data.targets.length === 0)
23043
+ invalid2("image/offload targets");
23044
+ } else if (event.type === "workspace/changes") {
23045
+ if (!isRecord3(event.data))
23046
+ invalid2("workspace/changes");
23047
+ exactKeys2(event.data, ["turn"]);
23048
+ positiveInteger(event.data.turn, "workspace/changes turn");
23049
+ } else if (event.type === "tool/result") {
23050
+ if (!isRecord3(event.data))
23051
+ invalid2("tool/result");
23052
+ const message = event.data.message;
23053
+ if (event.data.error !== void 0 && (!isRecord3(message) || message.isError !== true)) {
23054
+ invalid2("tool/result error marker");
23055
+ }
23056
+ } else if (event.type === "request/header") {
23057
+ DEEPSEEK_V015_PROFILE.validateEvent(event);
23058
+ if (!isRecord3(event.data) || !isRecord3(event.data.header))
23059
+ invalid2("request/header");
23060
+ const tools = event.data.header.tools;
23061
+ if (tools !== void 0 && (!Array.isArray(tools) || tools.some((tool) => !isRecord3(tool) || tool.deferLoading !== void 0 && tool.deferLoading !== true))) {
23062
+ invalid2("request/header tools");
23063
+ }
23064
+ } else if (event.type === "assistant/message" || event.type === "assistant/attempt") {
23065
+ DEEPSEEK_V015_PROFILE.validateEvent(event);
23066
+ if (!isRecord3(event.data))
23067
+ invalid2("assistant settlement");
23068
+ validateV4Stream(event.data.stream);
23069
+ } else {
23070
+ DEEPSEEK_V015_PROFILE.validateEvent(event);
23071
+ }
23072
+ }
23073
+ });
23074
+
22877
23075
  // dist/profiles/profile.js
23076
+ var V4_MINIMUM = parseSemVer("0.1.7-rc.1");
23077
+ function parseSemVer(value) {
23078
+ const match = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/u.exec(value);
23079
+ if (!match)
23080
+ return void 0;
23081
+ const prerelease = match[4] ? match[4].split(".").map((part) => /^\d+$/u.test(part) ? Number(part) : part) : [];
23082
+ return {
23083
+ major: Number(match[1]),
23084
+ minor: Number(match[2]),
23085
+ patch: Number(match[3]),
23086
+ prerelease
23087
+ };
23088
+ }
23089
+ function compareSemVer(left, right) {
23090
+ for (const key of ["major", "minor", "patch"]) {
23091
+ if (left[key] !== right[key])
23092
+ return left[key] > right[key] ? 1 : -1;
23093
+ }
23094
+ if (left.prerelease.length === 0 || right.prerelease.length === 0) {
23095
+ return left.prerelease.length === right.prerelease.length ? 0 : left.prerelease.length === 0 ? 1 : -1;
23096
+ }
23097
+ const length = Math.max(left.prerelease.length, right.prerelease.length);
23098
+ for (let index = 0; index < length; index += 1) {
23099
+ const leftPart = left.prerelease[index];
23100
+ const rightPart = right.prerelease[index];
23101
+ if (leftPart === void 0 || rightPart === void 0) {
23102
+ return leftPart === rightPart ? 0 : leftPart === void 0 ? -1 : 1;
23103
+ }
23104
+ if (leftPart === rightPart)
23105
+ continue;
23106
+ if (typeof leftPart === "number" && typeof rightPart === "string")
23107
+ return -1;
23108
+ if (typeof leftPart === "string" && typeof rightPart === "number")
23109
+ return 1;
23110
+ return leftPart > rightPart ? 1 : -1;
23111
+ }
23112
+ return 0;
23113
+ }
23114
+ function usesV4Profile(version2) {
23115
+ const parsed = parseSemVer(version2);
23116
+ return parsed !== void 0 && V4_MINIMUM !== void 0 && compareSemVer(parsed, V4_MINIMUM) >= 0;
23117
+ }
22878
23118
  function deepSeekModernProfile(version2) {
22879
- const base = /^0\.1\.2(?:-|\+|$)/u.test(version2) ? DEEPSEEK_V012_PROFILE : DEEPSEEK_V015_PROFILE;
23119
+ const base = /^0\.1\.2(?:-|\+|$)/u.test(version2) ? DEEPSEEK_V012_PROFILE : usesV4Profile(version2) ? DEEPSEEK_V017_PROFILE : DEEPSEEK_V015_PROFILE;
22880
23120
  return base.version === version2 ? base : Object.freeze({ ...base, version: version2 });
22881
23121
  }
22882
- function isDeepSeekV015(profile) {
22883
- return profile.sessionFormatVersion === 3;
23122
+ function hasDeepSeekModernStream(profile) {
23123
+ return profile.sessionFormatVersion >= 3;
22884
23124
  }
22885
23125
 
22886
23126
  // dist/modern/commands.js
@@ -22962,7 +23202,7 @@ async function callModernCommand(remote, endpoint, args, parse3, signal, timeout
22962
23202
  }
22963
23203
  }
22964
23204
  function executeModernCommand(remote, agentId, line, signal, profile = DEEPSEEK_V012_PROFILE) {
22965
- return callModernCommand(remote, "commands/execute", isDeepSeekV015(profile) ? { agentId, line, submittedAttachments: [] } : { agentId, line, images: [] }, parseModernCommandExecution, signal, null);
23205
+ return callModernCommand(remote, "commands/execute", profile.sessionFormatVersion !== 0 ? { agentId, line, submittedAttachments: [] } : { agentId, line, images: [] }, parseModernCommandExecution, signal, null);
22966
23206
  }
22967
23207
 
22968
23208
  // dist/modern/control-store.js
@@ -23234,13 +23474,15 @@ function parseSessionCollection(value, kind, sessions, maxSessions) {
23234
23474
  }
23235
23475
  }
23236
23476
  }
23237
- function parseBaseline(value, maxSessions, maxKeys) {
23238
- if (!isRecord6(value) || !hasExactKeys4(value, ["queues", "jobs", "projections"]) || !isPlainRecord3(value.projections)) {
23477
+ function parseBaseline(value, maxSessions, maxKeys, formatVersion) {
23478
+ if (!isRecord6(value) || !hasExactKeys4(value, formatVersion === 4 ? ["projections"] : ["queues", "jobs", "projections"]) || !isPlainRecord3(value.projections)) {
23239
23479
  throw storeError("protocolError", "DeepSeek Harness control stream emitted an invalid baseline");
23240
23480
  }
23241
23481
  const sessions = /* @__PURE__ */ new Set();
23242
- parseSessionCollection(value.queues, "queues", sessions, maxSessions);
23243
- parseSessionCollection(value.jobs, "jobs", sessions, maxSessions);
23482
+ if (formatVersion !== 4) {
23483
+ parseSessionCollection(value.queues, "queues", sessions, maxSessions);
23484
+ parseSessionCollection(value.jobs, "jobs", sessions, maxSessions);
23485
+ }
23244
23486
  const projections = /* @__PURE__ */ Object.create(null);
23245
23487
  for (const [sessionId, block] of Object.entries(value.projections)) {
23246
23488
  if (!validIdentifier(sessionId)) {
@@ -23254,12 +23496,15 @@ function parseBaseline(value, maxSessions, maxKeys) {
23254
23496
  }
23255
23497
  return { projections };
23256
23498
  }
23257
- function parseControlFrame(value, maxSessions, maxKeys) {
23499
+ function parseControlFrame(value, maxSessions, maxKeys, formatVersion) {
23258
23500
  if (!isRecord6(value) || typeof value.type !== "string") {
23259
23501
  throw storeError("protocolError", "DeepSeek Harness control stream emitted an invalid frame");
23260
23502
  }
23261
23503
  if (value.type === "baseline" && hasExactKeys4(value, ["type", "value"])) {
23262
- return { type: "baseline", value: parseBaseline(value.value, maxSessions, maxKeys) };
23504
+ return {
23505
+ type: "baseline",
23506
+ value: parseBaseline(value.value, maxSessions, maxKeys, formatVersion)
23507
+ };
23263
23508
  }
23264
23509
  if (value.type === "projection" && hasExactKeys4(value, ["type", "sessionId", "key", "value", "seq"]) && validIdentifier(value.sessionId) && validProjectionKey(value.key) && validSeq(value.seq)) {
23265
23510
  const projection = measureProjection(value.key, value.value);
@@ -23272,12 +23517,12 @@ function parseControlFrame(value, maxSessions, maxKeys) {
23272
23517
  bytes: projection.bytes
23273
23518
  };
23274
23519
  }
23275
- if (value.type === "queue" && hasExactKeys4(value, ["type", "sessionId", "items"]) && validIdentifier(value.sessionId) && Array.isArray(value.items) && value.items.length <= MAX_COLLECTION_ITEMS) {
23520
+ if (formatVersion !== 4 && value.type === "queue" && hasExactKeys4(value, ["type", "sessionId", "items"]) && validIdentifier(value.sessionId) && Array.isArray(value.items) && value.items.length <= MAX_COLLECTION_ITEMS) {
23276
23521
  for (const item of value.items)
23277
23522
  parseQueueItem(item);
23278
23523
  return { type: "queue", sessionId: value.sessionId };
23279
23524
  }
23280
- if (value.type === "jobs" && hasExactKeys4(value, ["type", "sessionId", "jobs"]) && validIdentifier(value.sessionId) && Array.isArray(value.jobs) && value.jobs.length <= MAX_COLLECTION_ITEMS) {
23525
+ if (formatVersion !== 4 && value.type === "jobs" && hasExactKeys4(value, ["type", "sessionId", "jobs"]) && validIdentifier(value.sessionId) && Array.isArray(value.jobs) && value.jobs.length <= MAX_COLLECTION_ITEMS) {
23281
23526
  for (const job of value.jobs)
23282
23527
  parseJob(job);
23283
23528
  return { type: "jobs", sessionId: value.sessionId };
@@ -23289,6 +23534,7 @@ function parseSeed(value, maxKeys) {
23289
23534
  }
23290
23535
  var ModernControlStore = class {
23291
23536
  #lifetime = new AbortController();
23537
+ #formatVersion;
23292
23538
  #maxKeys;
23293
23539
  #maxSessions;
23294
23540
  #maxWaiters;
@@ -23309,6 +23555,7 @@ var ModernControlStore = class {
23309
23555
  #readyResolve;
23310
23556
  constructor(source, options = {}) {
23311
23557
  this.#source = source;
23558
+ this.#formatVersion = options.profile?.sessionFormatVersion ?? 3;
23312
23559
  this.#maxSessions = positiveInteger3(options.maxSessions ?? DEFAULT_MAX_SESSIONS, "maxSessions");
23313
23560
  this.#maxKeys = positiveInteger3(options.maxKeysPerSession ?? DEFAULT_MAX_KEYS_PER_SESSION, "maxKeysPerSession");
23314
23561
  this.#maxWaiters = positiveInteger3(options.maxWaiters ?? DEFAULT_MAX_WAITERS, "maxWaiters");
@@ -23477,7 +23724,7 @@ var ModernControlStore = class {
23477
23724
  replaceBaseline(frame) {
23478
23725
  this.#assertUsable();
23479
23726
  try {
23480
- const parsed = parseControlFrame(frame, this.#maxSessions, this.#maxKeys);
23727
+ const parsed = parseControlFrame(frame, this.#maxSessions, this.#maxKeys, this.#formatVersion);
23481
23728
  if (parsed.type !== "baseline") {
23482
23729
  throw storeError("protocolError", "Control baseline replacement requires a baseline frame");
23483
23730
  }
@@ -23518,7 +23765,7 @@ var ModernControlStore = class {
23518
23765
  return;
23519
23766
  throw storeError(this.#opened ? "unavailable" : "protocolError", this.#opened ? "DeepSeek Harness control stream ended unexpectedly" : "DeepSeek Harness control stream ended before its baseline");
23520
23767
  }
23521
- const frame = parseControlFrame(next.value, this.#maxSessions, this.#maxKeys);
23768
+ const frame = parseControlFrame(next.value, this.#maxSessions, this.#maxKeys, this.#formatVersion);
23522
23769
  if (!generationOpened && frame.type !== "baseline") {
23523
23770
  throw storeError("protocolError", "DeepSeek Harness control stream omitted its baseline");
23524
23771
  }
@@ -24649,7 +24896,7 @@ function validateSecrets(value) {
24649
24896
  }
24650
24897
  return value;
24651
24898
  }
24652
- function parseDescribe(value) {
24899
+ function parseDescribe(value, profile) {
24653
24900
  assertBoundedJson2(value);
24654
24901
  if (!isPlainRecord4(value) || !exactKeys3(value, ["writable", "hasDocument", "namespaces"])) {
24655
24902
  throw permissionError("protocolError", "DeepSeek Harness returned an invalid settings response");
@@ -24663,7 +24910,7 @@ function parseDescribe(value) {
24663
24910
  const namespaceIds = [];
24664
24911
  const permissionNamespaces = [];
24665
24912
  for (const candidate of value.namespaces) {
24666
- if (!isPlainRecord4(candidate) || !exactKeys3(candidate, ["ns", "schema", "value", "applies", "secrets", "revision"], ["base", "user"]) || candidate.applies !== "live" && candidate.applies !== "restart" || !validRevision(candidate.revision)) {
24913
+ if (!isPlainRecord4(candidate) || !exactKeys3(candidate, profile.sessionFormatVersion === 4 ? ["ns", "autoGenerate", "schema", "value", "applies", "secrets", "revision"] : ["ns", "schema", "value", "applies", "secrets", "revision"], ["base", "user"]) || profile.sessionFormatVersion === 4 && typeof candidate.autoGenerate !== "boolean" || candidate.applies !== "live" && candidate.applies !== "restart" || !validRevision(candidate.revision)) {
24667
24914
  throw permissionError("protocolError", "DeepSeek Harness returned an invalid settings namespace");
24668
24915
  }
24669
24916
  const ns = nonBlankString2(candidate.ns, MAX_NAMESPACE_ID_LENGTH, "settings namespace id");
@@ -24701,7 +24948,7 @@ function permissionSection(value, requireDefault, knownIds, area) {
24701
24948
  }
24702
24949
  }
24703
24950
  }
24704
- function catalogFromNamespace(view) {
24951
+ function catalogFromNamespace(view, profile) {
24705
24952
  if (view.applies !== "live") {
24706
24953
  throw permissionError("protocolError", "DeepSeek Harness permission settings are not live");
24707
24954
  }
@@ -24720,10 +24967,14 @@ function catalogFromNamespace(view) {
24720
24967
  }
24721
24968
  const field = dictionary.defaultPreset;
24722
24969
  if (field.meta?.required !== true) {
24970
+ if (profile.sessionFormatVersion === 4)
24971
+ return null;
24723
24972
  throw permissionError("protocolError", "DeepSeek Harness permission default is not required");
24724
24973
  }
24725
24974
  const choices = field.type === "union" ? field.list : field.type === "const" ? [field] : void 0;
24726
24975
  if (!Array.isArray(choices) || choices.length === 0) {
24976
+ if (profile.sessionFormatVersion === 4)
24977
+ return null;
24727
24978
  throw permissionError("protocolError", "DeepSeek Harness permission schema has no preset choices");
24728
24979
  }
24729
24980
  if (choices.length > HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH) {
@@ -24763,18 +25014,18 @@ function catalogFromNamespace(view) {
24763
25014
  throw permissionError("protocolError", "DeepSeek Harness returned an unusable permission catalog");
24764
25015
  }
24765
25016
  }
24766
- function parseModernPermissionModeCatalog(value) {
24767
- const permission = parseDescribe(value);
24768
- return permission ? catalogFromNamespace(permission) : null;
25017
+ function parseModernPermissionModeCatalog(value, profile = DEEPSEEK_V015_PROFILE) {
25018
+ const permission = parseDescribe(value, profile);
25019
+ return permission ? catalogFromNamespace(permission, profile) : null;
24769
25020
  }
24770
- async function loadModernPermissionModeCatalog(remote, signal) {
25021
+ async function loadModernPermissionModeCatalog(remote, signal, profile = DEEPSEEK_V015_PROFILE) {
24771
25022
  try {
24772
25023
  const result = await remote.call("settings/describe", {}, signal);
24773
25024
  if (!result.ok) {
24774
25025
  const safe = sanitizeModernRemoteFailure(result.error);
24775
25026
  throw permissionError("remoteError", `DeepSeek Harness settings/describe failed: ${safe.message}`, safe.code);
24776
25027
  }
24777
- return parseModernPermissionModeCatalog(result.value);
25028
+ return parseModernPermissionModeCatalog(result.value, profile);
24778
25029
  } catch (error51) {
24779
25030
  if (error51 instanceof ModernPermissionModeError)
24780
25031
  throw error51;
@@ -24830,8 +25081,10 @@ function parseProjectionValue(value, catalog) {
24830
25081
  }
24831
25082
  return current.data;
24832
25083
  }
24833
- function readModernPermissionModeState(row, catalog) {
25084
+ function readModernPermissionModeState(row, catalog, profile) {
24834
25085
  if (!catalog) {
25086
+ if (profile?.sessionFormatVersion === 4)
25087
+ return void 0;
24835
25088
  if (row) {
24836
25089
  throw permissionError("protocolError", "DeepSeek Harness exposed permissions without a settings catalog");
24837
25090
  }
@@ -24966,7 +25219,7 @@ function readModernConfigurationSnapshot(input) {
24966
25219
  throw configurationError("protocolError", "DeepSeek Harness control state is detached");
24967
25220
  }
24968
25221
  const model = readModernModelSelectionState(rows[MODERN_MODEL_SELECTION_PROJECTION_KEY], input.modelCatalog);
24969
- const permission = readModernPermissionModeState(rows[MODERN_PERMISSION_PROJECTION_KEY], input.permissionModes);
25222
+ const permission = readModernPermissionModeState(rows[MODERN_PERMISSION_PROJECTION_KEY], input.permissionModes, input.profile);
24970
25223
  return {
24971
25224
  model,
24972
25225
  state: stateForSelection(input.nativeRef, model.selection, input.modelCatalog, permission?.permissionModeId),
@@ -25941,10 +26194,14 @@ function parseQuestionOption(value) {
25941
26194
  };
25942
26195
  }
25943
26196
  function parseQuestionIntent(value) {
25944
- if (!isPlainRecord6(value) || !hasExactKeys5(value, ["kind", "approve"]) || value.kind !== "plan-review" || !nonBlankString3(value.approve)) {
26197
+ if (!isPlainRecord6(value) || !hasOnlyKeys(value, ["kind", "approve"], ["callId"]) || value.kind !== "plan-review" || !nonBlankString3(value.approve) || Object.hasOwn(value, "callId") && !nonBlankString3(value.callId)) {
25945
26198
  throw invalidFrame();
25946
26199
  }
25947
- return { kind: "plan-review", approve: value.approve };
26200
+ return {
26201
+ kind: "plan-review",
26202
+ approve: value.approve,
26203
+ ...typeof value.callId === "string" ? { callId: value.callId } : {}
26204
+ };
25948
26205
  }
25949
26206
  function parseQuestionAnswer(value) {
25950
26207
  if (!isPlainRecord6(value) || !hasExactKeys5(value, ["answers"]) || !Array.isArray(value.answers)) {
@@ -26728,6 +26985,13 @@ var KNOWN_EVENT_TYPES = /* @__PURE__ */ new Set([
26728
26985
  "user/message",
26729
26986
  "web/deepseek-search-llm-request"
26730
26987
  ]);
26988
+ var V4_EVENT_TYPES = /* @__PURE__ */ new Set(["developer/message", "image/offload", "workspace/changes"]);
26989
+ function knownEvent(type, profile) {
26990
+ return KNOWN_EVENT_TYPES.has(type) || profile.sessionFormatVersion === 4 && V4_EVENT_TYPES.has(type);
26991
+ }
26992
+ function surfaceEvent(type, profile) {
26993
+ return SURFACE_EVENT_TYPES.has(type) || profile.sessionFormatVersion === 4 && type === "developer/message";
26994
+ }
26731
26995
  var SURFACE_EVENT_TYPES = /* @__PURE__ */ new Set([
26732
26996
  "system/message",
26733
26997
  "user/message",
@@ -26746,7 +27010,10 @@ var ModernEventValidator = class {
26746
27010
  surface: [],
26747
27011
  pendingCalls: /* @__PURE__ */ new Set(),
26748
27012
  commandStates: /* @__PURE__ */ new Map(),
26749
- commandEventSeqs: /* @__PURE__ */ new Set()
27013
+ commandEventSeqs: /* @__PURE__ */ new Set(),
27014
+ requestHeaders: /* @__PURE__ */ new Map(),
27015
+ offloadedImages: /* @__PURE__ */ new Set(),
27016
+ toolCalls: /* @__PURE__ */ new Map()
26750
27017
  };
26751
27018
  constructor(maxEvents = MODERN_HISTORY_MAX_EVENTS, profile = DEEPSEEK_V012_PROFILE) {
26752
27019
  this.#maxEvents = boundedInteger(maxEvents, "maxEvents", 1);
@@ -26759,16 +27026,16 @@ var ModernEventValidator = class {
26759
27026
  if (event.seq !== trace.count)
26760
27027
  fail("Modern history is not a contiguous zero-based prefix");
26761
27028
  trace.count += 1;
26762
- if (isDeepSeekV015(this.#profile) && !KNOWN_EVENT_TYPES.has(event.type) && event.ignorable === true)
27029
+ if (hasDeepSeekModernStream(this.#profile) && !knownEvent(event.type, this.#profile) && event.ignorable === true)
26763
27030
  return;
26764
- if (!SURFACE_EVENT_TYPES.has(event.type)) {
27031
+ if (!surfaceEvent(event.type, this.#profile)) {
26765
27032
  if (event.surfaceOp !== void 0 || event.sourceEventSeqs !== void 0) {
26766
27033
  fail("Modern history has surface metadata on a log-only event");
26767
27034
  }
26768
27035
  } else if (event.surfaceOp === void 0) {
26769
27036
  fail("Modern history surface event omitted surfaceOp");
26770
27037
  }
26771
- if (!KNOWN_EVENT_TYPES.has(event.type)) {
27038
+ if (!knownEvent(event.type, this.#profile)) {
26772
27039
  if (event.ignorable === true)
26773
27040
  return;
26774
27041
  fail("Modern history contains an unknown required event");
@@ -26792,10 +27059,13 @@ var ModernEventValidator = class {
26792
27059
  case "turn/end": {
26793
27060
  exactKeys2(data, ["turn", "reason"]);
26794
27061
  const turn = positiveInteger(data.turn, "turn/end turn");
26795
- validateTurnReason(data.reason);
27062
+ validateTurnReason(data.reason, this.#profile);
26796
27063
  if (trace.openTurn !== turn || trace.openStep !== null) {
26797
27064
  fail("Modern history has an invalid turn/end boundary");
26798
27065
  }
27066
+ if (this.#profile.sessionFormatVersion === 4 && trace.toolCalls.size > 0) {
27067
+ fail("Modern history turn/end leaves unresolved tool calls");
27068
+ }
26799
27069
  trace.openTurn = null;
26800
27070
  trace.nextTurn += 1;
26801
27071
  return;
@@ -26812,6 +27082,9 @@ var ModernEventValidator = class {
26812
27082
  case "step/end": {
26813
27083
  exactKeys2(data, ["turn", "step"]);
26814
27084
  requireOpenStep(trace, data, "step/end");
27085
+ if (this.#profile.sessionFormatVersion === 4 && trace.toolCalls.size > 0) {
27086
+ fail("Modern history step/end leaves unresolved tool calls");
27087
+ }
26815
27088
  trace.openStep = null;
26816
27089
  trace.nextStep += 1;
26817
27090
  trace.pendingCalls.clear();
@@ -26820,6 +27093,10 @@ var ModernEventValidator = class {
26820
27093
  case "user/message":
26821
27094
  validateUserMessage(data, this.#profile);
26822
27095
  return;
27096
+ case "developer/message":
27097
+ requireOpenStep(trace, data, "developer/message");
27098
+ validateDeveloperHeader(event, trace);
27099
+ return;
26823
27100
  case "system/message":
26824
27101
  requireOpenStep(trace, data, "system/message");
26825
27102
  return;
@@ -26831,6 +27108,8 @@ var ModernEventValidator = class {
26831
27108
  case "assistant/message": {
26832
27109
  requireOpenStep(trace, data, "assistant/message");
26833
27110
  validateAssistantMessage(data.message, this.#profile);
27111
+ if (this.#profile.sessionFormatVersion === 4)
27112
+ registerV4ToolCalls(data.message, trace);
26834
27113
  if (data.interrupted !== void 0 && data.interrupted !== true) {
26835
27114
  fail("Modern history assistant/message has invalid interrupted marker");
26836
27115
  }
@@ -26844,10 +27123,18 @@ var ModernEventValidator = class {
26844
27123
  exactKeys2(data, ["turn", "step", "callId", "name", "arguments"]);
26845
27124
  requireOpenStep(trace, data, "tool/call");
26846
27125
  const callId = requiredString(data.callId, "tool/call callId");
26847
- requiredString(data.name, "tool/call name");
27126
+ const name = requiredString(data.name, "tool/call name");
26848
27127
  if (typeof data.arguments !== "string" || trace.pendingCalls.has(callId)) {
26849
27128
  fail("Modern history contains an invalid tool/call");
26850
27129
  }
27130
+ if (this.#profile.sessionFormatVersion === 4) {
27131
+ const tool = trace.toolCalls.get(callId);
27132
+ if (!tool || tool.started || tool.name !== name || tool.arguments !== data.arguments) {
27133
+ fail("Modern history tool/call does not match its advertised tool call");
27134
+ }
27135
+ tool.started = true;
27136
+ return;
27137
+ }
26851
27138
  trace.pendingCalls.add(callId);
26852
27139
  return;
26853
27140
  }
@@ -26855,10 +27142,16 @@ var ModernEventValidator = class {
26855
27142
  requiredOptionalKeys(data, ["turn", "step", "message"], ["error", "meta"]);
26856
27143
  const callId = validateToolResultMessage(data.message, this.#profile);
26857
27144
  if (data.error !== void 0)
26858
- validateToolError(data.error);
27145
+ validateToolError(data.error, this.#profile);
26859
27146
  if (event.surfaceOp === "append") {
26860
27147
  requireOpenStep(trace, data, "tool/result");
26861
- if (!trace.pendingCalls.delete(callId)) {
27148
+ if (this.#profile.sessionFormatVersion === 4) {
27149
+ const tool = trace.toolCalls.get(callId);
27150
+ if (!tool || !tool.started && !isV4ForkToolResult(data, event.sourceEventSeqs, event.seq)) {
27151
+ fail("Modern history contains an unmatched tool/result");
27152
+ }
27153
+ trace.toolCalls.delete(callId);
27154
+ } else if (!trace.pendingCalls.delete(callId)) {
26862
27155
  fail("Modern history contains an unmatched tool/result");
26863
27156
  }
26864
27157
  } else if (trace.openTurn === null) {
@@ -26870,6 +27163,7 @@ var ModernEventValidator = class {
26870
27163
  validateRequestHeader(data);
26871
27164
  if (trace.openTurn === null)
26872
27165
  fail("Modern history request/header is outside a Turn");
27166
+ trace.requestHeaders.set(event.seq, data.header);
26873
27167
  return;
26874
27168
  case "request/context":
26875
27169
  validateRequestContext(data, this.#profile);
@@ -26881,6 +27175,11 @@ var ModernEventValidator = class {
26881
27175
  return;
26882
27176
  case "session/end-seed":
26883
27177
  return;
27178
+ case "image/offload":
27179
+ validateImageOffload(data, trace);
27180
+ return;
27181
+ case "workspace/changes":
27182
+ return;
26884
27183
  case "agent-preset/selected":
26885
27184
  exactKeys2(data, ["agentPreset"]);
26886
27185
  requiredString(data.agentPreset, "agent-preset/selected agentPreset");
@@ -27010,20 +27309,113 @@ var ModernEventValidator = class {
27010
27309
  }
27011
27310
  }
27012
27311
  };
27312
+ function registerV4ToolCalls(value, trace) {
27313
+ if (!isRecord4(value) || !Array.isArray(value.content))
27314
+ return;
27315
+ for (const block of value.content) {
27316
+ if (!isRecord4(block) || block.type !== "tool-call")
27317
+ continue;
27318
+ const callId = requiredString(block.id, "assistant tool-call id");
27319
+ const name = requiredString(block.name, "assistant tool-call name");
27320
+ if (typeof block.arguments !== "string" || trace.toolCalls.has(callId)) {
27321
+ fail("Modern history assistant/message repeats an advertised tool call");
27322
+ }
27323
+ trace.toolCalls.set(callId, { name, arguments: block.arguments, started: false });
27324
+ }
27325
+ }
27326
+ function isV4ForkToolResult(data, sourceEventSeqs, seq) {
27327
+ if (!isRecord4(data.error) || data.error.name !== "ToolNotStartedError" || data.error.code !== "TOOL_NOT_STARTED" || !isRecord4(data.message) || data.message.role !== "tool" || data.message.isError !== true || !isRecord4(data.message.source) || data.message.source.kind !== "tool" || typeof data.message.source.callId !== "string" || data.message.toolCallId !== data.message.source.callId || typeof data.message.id !== "string" || data.message.id !== `forked-tool-result-${data.message.source.callId}-${seq}` || sourceEventSeqs !== void 0 || !Array.isArray(data.message.content) || data.message.content.length !== 1) {
27328
+ return false;
27329
+ }
27330
+ const content = data.message.content[0];
27331
+ return isRecord4(content) && content.type === "text" && typeof content.text === "string" && data.message.id.endsWith(`-${seq}`);
27332
+ }
27333
+ function validateDeveloperHeader(event, trace) {
27334
+ const data = event.data;
27335
+ if (data.headerSeq === void 0)
27336
+ return;
27337
+ const header = trace.requestHeaders.get(data.headerSeq);
27338
+ if (!header || !Array.isArray(header.tools)) {
27339
+ fail("Modern history developer/message references an invalid request/header");
27340
+ }
27341
+ const message = data.message;
27342
+ for (const block of message.content) {
27343
+ if (!isRecord4(block) || block.type !== "tool-addition")
27344
+ continue;
27345
+ const matching = header.tools.filter((tool) => isRecord4(tool) && tool.name === block.toolName);
27346
+ if (matching.length !== 1 || !isRecord4(matching[0]) || typeof matching[0].description !== "string" || !isRecord4(matching[0].parameters) || matching[0].deferLoading !== void 0 && matching[0].deferLoading !== true) {
27347
+ fail("Modern history developer/message references an invalid tool definition");
27348
+ }
27349
+ }
27350
+ }
27351
+ function strictIndex(value, label) {
27352
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || Object.is(value, -0)) {
27353
+ fail(`Modern history ${label} is malformed`);
27354
+ }
27355
+ return value;
27356
+ }
27357
+ function validateImageOffload(data, trace) {
27358
+ const seen = /* @__PURE__ */ new Set();
27359
+ for (const target of data.targets) {
27360
+ if (!isRecord4(target))
27361
+ fail("Modern history image/offload target is malformed");
27362
+ exactKeys2(target, ["seq", "imageIndexes"]);
27363
+ const seq = strictIndex(target.seq, "image/offload target seq");
27364
+ if (seen.has(seq))
27365
+ fail("Modern history image/offload repeats a target");
27366
+ seen.add(seq);
27367
+ const source = trace.surface.find((event) => event.seq === seq);
27368
+ if (!source || source.type !== "user/message" && source.type !== "tool/result") {
27369
+ fail("Modern history image/offload target is not a current message");
27370
+ }
27371
+ const sourceData = source.type === "user/message" ? source.data : source.data.message;
27372
+ const content = isRecord4(sourceData) ? sourceData.content : void 0;
27373
+ if (!Array.isArray(content) || !Array.isArray(target.imageIndexes) || !target.imageIndexes.length) {
27374
+ fail("Modern history image/offload indexes are malformed");
27375
+ }
27376
+ const images = [];
27377
+ const collectImages = (value) => {
27378
+ if (!Array.isArray(value))
27379
+ return;
27380
+ for (const block of value) {
27381
+ if (!isRecord4(block))
27382
+ continue;
27383
+ if (block.type === "image")
27384
+ images.push(block);
27385
+ if (Array.isArray(block.content))
27386
+ collectImages(block.content);
27387
+ }
27388
+ };
27389
+ collectImages(content);
27390
+ let previous = -1;
27391
+ for (const value of target.imageIndexes) {
27392
+ const index = strictIndex(value, "image/offload index");
27393
+ const image = images[index];
27394
+ if (index <= previous || !isRecord4(image) || image.offloaded === true || trace.offloadedImages.has(`${seq}:${index}`)) {
27395
+ fail("Modern history image/offload references an invalid image occurrence");
27396
+ }
27397
+ trace.offloadedImages.add(`${seq}:${index}`);
27398
+ previous = index;
27399
+ }
27400
+ }
27401
+ }
27013
27402
  function acceptSurfaceEvent(trace, event, profile) {
27014
- if (!SURFACE_EVENT_TYPES.has(event.type))
27403
+ if (!surfaceEvent(event.type, profile))
27015
27404
  return;
27016
27405
  const sources = event.sourceEventSeqs;
27017
- if (sources !== void 0 && (!Array.isArray(sources) || sources.some((seq) => !nonNegativeSafeInteger2(seq) || Object.is(seq, -0) || seq >= event.seq) || new Set(sources).size !== sources.length || sources.length === 0 && event.type !== "assistant/message")) {
27406
+ if (sources !== void 0 && (!Array.isArray(sources) || sources.some((seq) => !nonNegativeSafeInteger2(seq) || Object.is(seq, -0) || seq >= event.seq) || new Set(sources).size !== sources.length || sources.length === 0 && (profile.sessionFormatVersion === 4 || event.type !== "assistant/message"))) {
27018
27407
  fail("Modern history surface event has invalid sourceEventSeqs");
27019
27408
  }
27020
27409
  const op = event.surfaceOp;
27021
27410
  if (op === "append") {
27411
+ if (profile.sessionFormatVersion === 4 && event.type === "system/message" && trace.surface.length > 0 && !trace.surface.some((surface) => surface.type === "system/message")) {
27412
+ fail("Modern history system/message must remain the protected surface head");
27413
+ }
27022
27414
  trace.surface.push(event);
27023
27415
  return;
27024
27416
  }
27025
- const start = isDeepSeekV015(profile) ? "startSeq" : "start";
27026
- const end = isDeepSeekV015(profile) ? "endSeq" : "end";
27417
+ const start = hasDeepSeekModernStream(profile) ? "startSeq" : "start";
27418
+ const end = hasDeepSeekModernStream(profile) ? "endSeq" : "end";
27027
27419
  if (!isRecord4(op) || Reflect.ownKeys(op).length !== 3 || !Object.hasOwn(op, "op") || !Object.hasOwn(op, start) || !Object.hasOwn(op, end) || op.op !== "replace" || !nonNegativeSafeInteger2(op[start]) || Object.is(op[start], -0) || !nonNegativeSafeInteger2(op[end]) || Object.is(op[end], -0)) {
27028
27420
  fail("Modern history surface event has an invalid replacement operation");
27029
27421
  }
@@ -27041,17 +27433,20 @@ function acceptSurfaceEvent(trace, event, profile) {
27041
27433
  fail("Modern history system head may only be replaced by one system/message");
27042
27434
  }
27043
27435
  if (event.type === "tool/result") {
27044
- if (shadowed.length !== 1 || shadowed[0]?.type !== "tool/result" || !isDeepStrictEqual6(comparableToolResultData(shadowed[0]), comparableToolResultData(event))) {
27436
+ if (shadowed.length !== 1 || shadowed[0]?.type !== "tool/result" || !isDeepStrictEqual6(comparableToolResultData(shadowed[0], profile), comparableToolResultData(event, profile))) {
27045
27437
  fail("Modern history tool/result replacement changed more than result content");
27046
27438
  }
27047
27439
  }
27048
27440
  trace.surface.splice(startIndex, endIndex - startIndex + 1, event);
27049
27441
  }
27050
- function comparableToolResultData(event) {
27442
+ function comparableToolResultData(event, profile) {
27051
27443
  const data = event.data;
27052
- if (!isRecord4(data) || !isRecord4(data.message) || !Array.isArray(data.message.content) || !isRecord4(data.message.content[0])) {
27444
+ if (!isRecord4(data) || !isRecord4(data.message) || !Array.isArray(data.message.content) || profile.sessionFormatVersion !== 4 && !isRecord4(data.message.content[0])) {
27053
27445
  fail("Modern history tool/result replacement is malformed");
27054
27446
  }
27447
+ if (profile.sessionFormatVersion === 4) {
27448
+ return { ...data, message: { ...data.message, content: null } };
27449
+ }
27055
27450
  return {
27056
27451
  ...data,
27057
27452
  message: {
@@ -27074,6 +27469,8 @@ function resolveModernForkBoundary(events, checkpointId, profile = DEEPSEEK_V012
27074
27469
  if (atSeq === null || events[atSeq]?.seq !== atSeq || events[atSeq]?.type !== "turn/end") {
27075
27470
  return null;
27076
27471
  }
27472
+ if (profile.sessionFormatVersion === 4)
27473
+ return { atSeq, events: events.slice(0, atSeq + 1) };
27077
27474
  let cut = atSeq + 1;
27078
27475
  while (cut < events.length && events[cut]?.type !== "turn/start")
27079
27476
  cut += 1;
@@ -27122,7 +27519,7 @@ function projectModernHistory(input) {
27122
27519
  };
27123
27520
  for (const [index, event] of input.events.entries()) {
27124
27521
  validator.accept(event);
27125
- if (!KNOWN_EVENT_TYPES.has(event.type) || !isRecord4(event.data))
27522
+ if (!knownEvent(event.type, profile) || !isRecord4(event.data))
27126
27523
  continue;
27127
27524
  const data = event.data;
27128
27525
  switch (event.type) {
@@ -27133,6 +27530,7 @@ function projectModernHistory(input) {
27133
27530
  input: [],
27134
27531
  items: [],
27135
27532
  tools: /* @__PURE__ */ new Map(),
27533
+ advertisedTools: /* @__PURE__ */ new Map(),
27136
27534
  model: effectiveModel
27137
27535
  };
27138
27536
  break;
@@ -27211,7 +27609,7 @@ function projectModernHistory(input) {
27211
27609
  harnessId,
27212
27610
  nativeSessionId: input.sessionId,
27213
27611
  formatVersion: 1,
27214
- ...isDeepSeekV015(profile) ? { locator: { dshVersion: profile.version } } : {}
27612
+ ...hasDeepSeekModernStream(profile) ? { locator: { dshVersion: profile.version } } : {}
27215
27613
  });
27216
27614
  const state = {
27217
27615
  nativeRef,
@@ -27243,7 +27641,7 @@ function modernCheckpointRef(harnessId, sessionId, seq, profile = DEEPSEEK_V012_
27243
27641
  nativeSessionId: sessionId,
27244
27642
  checkpointId: `${profile.checkpointPrefix}${seq}`,
27245
27643
  formatVersion: 1,
27246
- ...isDeepSeekV015(profile) ? { locator: { dshVersion: profile.version } } : {}
27644
+ ...hasDeepSeekModernStream(profile) ? { locator: { dshVersion: profile.version } } : {}
27247
27645
  });
27248
27646
  }
27249
27647
  function modernItemId(sessionId, key) {
@@ -27251,6 +27649,13 @@ function modernItemId(sessionId, key) {
27251
27649
  }
27252
27650
  function projectAssistantMessage(turn, sessionId, data) {
27253
27651
  const message = data.message;
27652
+ if (Array.isArray(message.content)) {
27653
+ for (const block of message.content) {
27654
+ if (isRecord4(block) && block.type === "tool-call" && typeof block.id === "string" && typeof block.name === "string" && typeof block.arguments === "string") {
27655
+ turn.advertisedTools.set(block.id, { toolName: block.name, arguments: block.arguments });
27656
+ }
27657
+ }
27658
+ }
27254
27659
  const reasoning2 = contentByType(message.content, "reasoning");
27255
27660
  if (reasoning2) {
27256
27661
  const item = {
@@ -27283,15 +27688,32 @@ function projectToolCall(turn, sessionId, data, seq) {
27283
27688
  const itemIndex = turn.items.length;
27284
27689
  turn.items.push({ item, outcome: incompleteToolOutcome(item.toolName) });
27285
27690
  turn.tools.set(data.callId, { itemIndex, item, toolName: item.toolName });
27691
+ turn.advertisedTools.delete(data.callId);
27286
27692
  }
27287
27693
  function projectToolResultEvent(turn, sessionId, data, seq, limit) {
27288
27694
  const result = projectToolResult(data.message, limit);
27289
27695
  if (!result)
27290
27696
  fail("Modern history contains an unprojectable tool/result");
27291
- const tool = turn.tools.get(result.callId);
27292
- if (!tool)
27697
+ let tool = turn.tools.get(result.callId);
27698
+ if (!tool) {
27699
+ const advertised = turn.advertisedTools.get(result.callId);
27700
+ if (advertised && isForkedToolResult(data, result.callId, seq)) {
27701
+ const item2 = {
27702
+ type: "toolExecution",
27703
+ itemId: modernItemId(sessionId, `event:${seq}:tool`),
27704
+ toolName: advertised.toolName,
27705
+ arguments: parseArguments(advertised.arguments)
27706
+ };
27707
+ const itemIndex = turn.items.length;
27708
+ turn.items.push({ item: item2, outcome: incompleteToolOutcome(item2.toolName) });
27709
+ tool = { itemIndex, item: item2, toolName: item2.toolName };
27710
+ }
27711
+ }
27712
+ if (!tool) {
27293
27713
  fail("Modern history contains an unmatched projected tool/result");
27714
+ }
27294
27715
  turn.tools.delete(result.callId);
27716
+ turn.advertisedTools.delete(result.callId);
27295
27717
  const item = { ...tool.item, ...result.output ? { output: result.output } : {} };
27296
27718
  turn.items[tool.itemIndex] = {
27297
27719
  item,
@@ -27317,6 +27739,10 @@ function projectToolResultEvent(turn, sessionId, data, seq, limit) {
27317
27739
  }
27318
27740
  }
27319
27741
  }
27742
+ function isForkedToolResult(data, callId, seq) {
27743
+ const message = data.message;
27744
+ return isRecord4(data.error) && data.error.name === "ToolNotStartedError" && data.error.code === "TOOL_NOT_STARTED" && isRecord4(message) && message.role === "tool" && message.isError === true && message.toolCallId === callId && typeof message.id === "string" && message.id === `forked-tool-result-${callId}-${seq}`;
27745
+ }
27320
27746
  function finishIncompleteTools(turn, outcome) {
27321
27747
  for (const tool of turn.tools.values())
27322
27748
  turn.items[tool.itemIndex] = { item: tool.item, outcome };
@@ -27387,12 +27813,15 @@ function stepPosition(data, label) {
27387
27813
  };
27388
27814
  }
27389
27815
  function validateUserMessage(data, profile = DEEPSEEK_V012_PROFILE) {
27390
- exactKeys2(data, ["id", "role", "content", "source"]);
27816
+ if (profile.sessionFormatVersion === 4)
27817
+ requiredFields2(data, ["id", "role", "content", "source"]);
27818
+ else
27819
+ exactKeys2(data, ["id", "role", "content", "source"]);
27391
27820
  requiredString(data.id, "user/message id");
27392
27821
  if (data.role !== "user")
27393
27822
  fail("Modern history user/message has an invalid role");
27394
27823
  profile.validateContent(data.content);
27395
- if (!isRecord4(data.source) || !requiredString(data.source.kind, "user/message source kind")) {
27824
+ if (!isRecord4(data.source) || !requiredString(data.source.kind, "user/message source kind") || profile.sessionFormatVersion === 4 && data.source.kind === "plugin") {
27396
27825
  fail("Modern history user/message has an invalid source");
27397
27826
  }
27398
27827
  if (data.source.kind === "user" && data.source.rpcId !== void 0) {
@@ -27402,7 +27831,10 @@ function validateUserMessage(data, profile = DEEPSEEK_V012_PROFILE) {
27402
27831
  function validateAssistantMessage(value, profile = DEEPSEEK_V012_PROFILE) {
27403
27832
  if (!isRecord4(value))
27404
27833
  fail("Modern history assistant/message is malformed");
27405
- exactKeys2(value, ["id", "role", "content", "source"]);
27834
+ if (profile.sessionFormatVersion === 4)
27835
+ requiredFields2(value, ["id", "role", "content", "source"]);
27836
+ else
27837
+ exactKeys2(value, ["id", "role", "content", "source"]);
27406
27838
  requiredString(value.id, "assistant/message id");
27407
27839
  if (value.role !== "assistant")
27408
27840
  fail("Modern history assistant/message has an invalid role");
@@ -27414,6 +27846,19 @@ function validateAssistantMessage(value, profile = DEEPSEEK_V012_PROFILE) {
27414
27846
  function validateToolResultMessage(value, profile = DEEPSEEK_V012_PROFILE) {
27415
27847
  if (!isRecord4(value))
27416
27848
  fail("Modern history tool/result message is malformed");
27849
+ if (profile.sessionFormatVersion === 4) {
27850
+ requiredFields2(value, ["id", "role", "content", "source", "toolCallId"]);
27851
+ requiredString(value.id, "tool/result message id");
27852
+ if (value.role !== "tool" || !isRecord4(value.source) || value.source.kind !== "tool") {
27853
+ fail("Modern history tool/result message has an invalid role or source");
27854
+ }
27855
+ const callId2 = requiredString(value.source.callId, "tool/result source callId");
27856
+ if (value.toolCallId !== callId2 || value.isError !== void 0 && typeof value.isError !== "boolean") {
27857
+ fail("Modern history tool/result message has invalid callId or isError");
27858
+ }
27859
+ profile.validateContent(value.content);
27860
+ return callId2;
27861
+ }
27417
27862
  exactKeys2(value, ["id", "role", "content", "source"]);
27418
27863
  requiredString(value.id, "tool/result message id");
27419
27864
  if (value.role !== "user" || !isRecord4(value.source) || value.source.kind !== "tool") {
@@ -27434,6 +27879,11 @@ function validateToolResultMessage(value, profile = DEEPSEEK_V012_PROFILE) {
27434
27879
  }
27435
27880
  return callId;
27436
27881
  }
27882
+ function requiredFields2(value, fields) {
27883
+ if (fields.some((field) => !Object.hasOwn(value, field))) {
27884
+ fail("Modern history known event omitted a required field");
27885
+ }
27886
+ }
27437
27887
  function validateUsage(value) {
27438
27888
  if (!validUsage(value))
27439
27889
  fail("Modern history usage is malformed");
@@ -27457,7 +27907,7 @@ function validUsage(value) {
27457
27907
  }
27458
27908
  return fields.slice(2).every((field) => value[field] === void 0 || nonNegativeSafeInteger2(value[field]));
27459
27909
  }
27460
- function validateTurnReason(value) {
27910
+ function validateTurnReason(value, profile) {
27461
27911
  if (!isRecord4(value) || typeof value.kind !== "string") {
27462
27912
  fail("Modern history turn/end reason is malformed");
27463
27913
  }
@@ -27468,6 +27918,11 @@ function validateTurnReason(value) {
27468
27918
  case "interrupted":
27469
27919
  exactKeys2(value, ["kind"]);
27470
27920
  return;
27921
+ case "forked":
27922
+ if (profile.sessionFormatVersion !== 4)
27923
+ fail("Modern history contains an unknown Turn outcome");
27924
+ exactKeys2(value, ["kind"]);
27925
+ return;
27471
27926
  case "aborted":
27472
27927
  exactKeys2(value, ["kind", "reason"]);
27473
27928
  if (!isRecord4(value.reason) || typeof value.reason.kind !== "string") {
@@ -27522,7 +27977,7 @@ function validateRequestHeader(data) {
27522
27977
  }
27523
27978
  }
27524
27979
  function validateRequestContext(data, profile) {
27525
- requiredOptionalKeys(data, ["provider", "model"], isDeepSeekV015(profile) ? ["contextWindow", "systemPromptUpdate"] : ["contextWindow"]);
27980
+ requiredOptionalKeys(data, ["provider", "model"], hasDeepSeekModernStream(profile) ? ["contextWindow", "systemPromptUpdate"] : ["contextWindow"]);
27526
27981
  if (!nonBlankString(data.provider) || !nonBlankString(data.model)) {
27527
27982
  fail("Modern history request/context has an invalid Model route");
27528
27983
  }
@@ -27540,12 +27995,15 @@ function validateModelSelection(data) {
27540
27995
  fail("Modern history model/selection has invalid reasoningEffort");
27541
27996
  }
27542
27997
  }
27543
- function validateToolError(value) {
27998
+ function validateToolError(value, profile) {
27544
27999
  if (!isRecord4(value))
27545
28000
  fail("Modern history tool/result error is malformed");
27546
- exactKeys2(value, ["name", "code"]);
28001
+ requiredOptionalKeys(value, ["name", "code"], profile.sessionFormatVersion === 4 ? ["reason"] : []);
27547
28002
  requiredString(value.name, "tool/result error name");
27548
28003
  requiredString(value.code, "tool/result error code");
28004
+ if (value.reason !== void 0 && typeof value.reason !== "string") {
28005
+ fail("Modern history tool/result error reason is malformed");
28006
+ }
27549
28007
  }
27550
28008
  function validateInboxSplice(data, profile) {
27551
28009
  requiredOptionalKeys(data, ["target", "start", "inserted"], ["removedCount", "outcome"]);
@@ -27655,7 +28113,7 @@ function validateRetry(data) {
27655
28113
  requiredString(data.provider, "llm/retry provider");
27656
28114
  requiredString(data.policyKey, "llm/retry policyKey");
27657
28115
  positiveInteger(data.retry, "llm/retry retry");
27658
- nonNegativeInteger(data.delayMs, "llm/retry delayMs");
28116
+ nonNegativeFiniteNumber(data.delayMs, "llm/retry delayMs");
27659
28117
  if (mode === "normal")
27660
28118
  positiveInteger(data.maxRetries, "llm/retry maxRetries");
27661
28119
  validateLlmFailure(data.failure, "llm/retry failure");
@@ -27869,7 +28327,7 @@ function validateSubagentModelPolicy(data) {
27869
28327
  validateModelRoute(route, "subagent Model policy route");
27870
28328
  }
27871
28329
  function validateTeamEvent(type, data, profile) {
27872
- if (data.version !== (isDeepSeekV015(profile) ? 2 : 1))
28330
+ if (data.version !== (hasDeepSeekModernStream(profile) ? 2 : 1))
27873
28331
  fail("Modern history team event version is malformed");
27874
28332
  requiredString(data.teamId, "team event teamId");
27875
28333
  if (type === "team/message/delivered") {
@@ -28057,7 +28515,8 @@ var ModernHarnessSession = class {
28057
28515
  sessionId: this.#sessionId,
28058
28516
  nativeRef: projection.nativeRef,
28059
28517
  modelCatalog: this.#modelCatalog,
28060
- permissionModes: this.#permissionModes
28518
+ permissionModes: this.#permissionModes,
28519
+ profile: this.#profile
28061
28520
  });
28062
28521
  this.#nativeRef = projection.nativeRef;
28063
28522
  this.initialState = configuration.state;
@@ -28357,7 +28816,8 @@ ${question.detail}` : question.question;
28357
28816
  sessionId: this.#sessionId,
28358
28817
  nativeRef: this.#nativeRef,
28359
28818
  modelCatalog: this.#modelCatalog,
28360
- permissionModes: this.#permissionModes
28819
+ permissionModes: this.#permissionModes,
28820
+ profile: this.#profile
28361
28821
  });
28362
28822
  }
28363
28823
  #onConfigurationProjection() {
@@ -28991,6 +29451,9 @@ ${question.detail}` : question.question;
28991
29451
  if (attempt && !attempt.projected && active?.nativeTurn === attempt.turn && active.agent) {
28992
29452
  this.#cancelAgentItem(active);
28993
29453
  }
29454
+ if (attempt && active?.reasoning?.attemptId === attempt.attemptId) {
29455
+ this.#cancelReasoningItem(active);
29456
+ }
28994
29457
  this.#assistantAttempt = void 0;
28995
29458
  }
28996
29459
  #cancelAgentItem(active) {
@@ -29008,6 +29471,13 @@ ${question.detail}` : question.question;
29008
29471
  delete active.agent;
29009
29472
  this.#completeItem(active, agent.item, { status: "cancelled" });
29010
29473
  }
29474
+ #cancelReasoningItem(active) {
29475
+ const reasoning2 = active.reasoning;
29476
+ if (!reasoning2)
29477
+ return;
29478
+ delete active.reasoning;
29479
+ this.#completeItem(active, reasoning2.item, { status: "cancelled" });
29480
+ }
29011
29481
  #projectAssistantLiveChunks() {
29012
29482
  const attempt = this.#assistantAttempt;
29013
29483
  const active = this.#active;
@@ -29042,6 +29512,7 @@ ${question.detail}` : question.question;
29042
29512
  this.#projectAssistantLiveChunks();
29043
29513
  } else {
29044
29514
  this.#cancelAgentItem(active);
29515
+ this.#cancelReasoningItem(active);
29045
29516
  }
29046
29517
  attempt.projected = true;
29047
29518
  if (attempt.ended)
@@ -29261,6 +29732,7 @@ ${question.detail}` : question.question;
29261
29732
  input: [...input],
29262
29733
  autonomous,
29263
29734
  tools: /* @__PURE__ */ new Map(),
29735
+ reasoningOrdinal: 0,
29264
29736
  interactions: /* @__PURE__ */ new Set(),
29265
29737
  terminal: false,
29266
29738
  cancelAcknowledged: false
@@ -29316,6 +29788,9 @@ ${question.detail}` : question.question;
29316
29788
  if (event.surfaceOp === "append")
29317
29789
  this.#completeTool(active, data, event.seq);
29318
29790
  return;
29791
+ case "step/end":
29792
+ this.#cancelReasoningItem(active);
29793
+ return;
29319
29794
  case "turn/end":
29320
29795
  this.#finishTurn(buffer, active, data.reason, event.seq);
29321
29796
  return;
@@ -29327,6 +29802,7 @@ ${question.detail}` : question.question;
29327
29802
  if (chunk.type === "text-delta") {
29328
29803
  this.#appendAgent(active, chunk.text, step, attemptId);
29329
29804
  } else if (chunk.type === "reasoning-delta") {
29805
+ this.#appendReasoning(active, chunk.text, step, true, attemptId);
29330
29806
  } else if (chunk.type === "usage" && !initialReplay) {
29331
29807
  this.#publishUsageChanges(active.turnId);
29332
29808
  }
@@ -29352,36 +29828,48 @@ ${question.detail}` : question.question;
29352
29828
  update: { type: "text.append", text }
29353
29829
  });
29354
29830
  }
29355
- #startReasoning(active, step) {
29831
+ #startReasoning(active, step, provisional, attemptId) {
29356
29832
  if (!active.reasoning) {
29833
+ const key = provisional ? `reasoning:provisional:${++active.reasoningOrdinal}` : "reasoning";
29357
29834
  const item = {
29358
29835
  type: "reasoning",
29359
- itemId: modernItemId(this.#sessionId, `turn:${active.nativeTurn}:step:${step}:reasoning`),
29836
+ itemId: modernItemId(this.#sessionId, `turn:${active.nativeTurn}:step:${step}:${key}`),
29360
29837
  text: ""
29361
29838
  };
29362
- active.reasoning = { item, text: "" };
29839
+ active.reasoning = {
29840
+ item,
29841
+ text: "",
29842
+ provisional,
29843
+ pendingLineBreaks: "",
29844
+ ...attemptId ? { attemptId } : {}
29845
+ };
29363
29846
  this.#emit({ type: "item.started", turnId: active.turnId, item });
29364
29847
  }
29365
29848
  return active.reasoning;
29366
29849
  }
29367
- #appendReasoning(active, text, step) {
29850
+ #appendReasoning(active, text, step, provisional = false, attemptId, final = false) {
29368
29851
  if (!text)
29369
29852
  return;
29370
- const reasoning2 = this.#startReasoning(active, step);
29371
- reasoning2.text += text;
29853
+ const reasoning2 = this.#startReasoning(active, step, provisional, attemptId);
29854
+ const candidate = final ? text : reasoning2.pendingLineBreaks + text;
29855
+ const appended = final ? candidate : candidate.replace(/[\r\n]+$/u, "");
29856
+ reasoning2.pendingLineBreaks = final ? "" : candidate.slice(appended.length);
29857
+ if (!appended)
29858
+ return;
29859
+ reasoning2.text += appended;
29372
29860
  reasoning2.item = { ...reasoning2.item, text: reasoning2.text };
29373
29861
  this.#emit({
29374
29862
  type: "item.updated",
29375
29863
  turnId: active.turnId,
29376
29864
  itemId: reasoning2.item.itemId,
29377
- update: { type: "text.append", text }
29865
+ update: { type: "text.append", text: appended }
29378
29866
  });
29379
29867
  }
29380
29868
  #completeAssistant(active, data) {
29381
29869
  const message = data.message;
29382
29870
  const step = data.step;
29383
- const reasoning2 = contentText(message.content, "reasoning");
29384
- const text = contentText(message.content, "text");
29871
+ const reasoning2 = contentText2(message.content, "reasoning");
29872
+ const text = contentText2(message.content, "text");
29385
29873
  if (this.#profile.assistantStream && active.agent && !text.startsWith(active.agent.text)) {
29386
29874
  this.#cancelAgentItem(active);
29387
29875
  }
@@ -29396,8 +29884,12 @@ ${question.detail}` : question.question;
29396
29884
  }
29397
29885
  }
29398
29886
  #completeReasoning(active, finalText, step) {
29399
- if (finalText)
29400
- this.#appendReasoning(active, finalText, step);
29887
+ if (active.reasoning && !finalText.startsWith(active.reasoning.text)) {
29888
+ this.#cancelReasoningItem(active);
29889
+ }
29890
+ const suffix = finalText.slice(active.reasoning?.text.length ?? 0);
29891
+ if (suffix)
29892
+ this.#appendReasoning(active, suffix, step, false, void 0, true);
29401
29893
  const current = active.reasoning;
29402
29894
  if (!current)
29403
29895
  return;
@@ -29482,6 +29974,7 @@ ${question.detail}` : question.question;
29482
29974
  const projected = turnOutcome(reason);
29483
29975
  const itemOutcome2 = toItemOutcome(projected);
29484
29976
  this.#discardAssistantAttempt();
29977
+ this.#cancelReasoningItem(active);
29485
29978
  this.#closeActiveInteractions(active);
29486
29979
  this.#completeOpenItems(active, itemOutcome2);
29487
29980
  active.terminal = true;
@@ -29593,6 +30086,7 @@ ${question.detail}` : question.question;
29593
30086
  input: hostBound ? [...pending.command.input] : [...buffer.input],
29594
30087
  autonomous: !hostBound,
29595
30088
  tools: /* @__PURE__ */ new Map(),
30089
+ reasoningOrdinal: 0,
29596
30090
  interactions: /* @__PURE__ */ new Set(),
29597
30091
  terminal: false,
29598
30092
  cancelAcknowledged: false
@@ -30033,6 +30527,9 @@ function turnOutcome(reason) {
30033
30527
  if (reason.kind === "aborted") {
30034
30528
  return { status: "cancelled", reason: "Cancelled by user" };
30035
30529
  }
30530
+ if (reason.kind === "forked") {
30531
+ return { status: "cancelled", reason: "Forked from parent Session" };
30532
+ }
30036
30533
  return {
30037
30534
  status: "failed",
30038
30535
  error: {
@@ -30053,7 +30550,7 @@ function toItemOutcome(outcome) {
30053
30550
  function textInputs2(value) {
30054
30551
  return Array.isArray(value) ? value.flatMap((block) => isRecord4(block) && block.type === "text" && typeof block.text === "string" ? [{ type: "text", text: block.text }] : []) : [];
30055
30552
  }
30056
- function contentText(value, type) {
30553
+ function contentText2(value, type) {
30057
30554
  return Array.isArray(value) ? value.filter((block) => isRecord4(block) && block.type === type && typeof block.text === "string").map((block) => block.text).join("") : "";
30058
30555
  }
30059
30556
  function isVisibleWork(event) {
@@ -30160,17 +30657,17 @@ function boundedId(value, area) {
30160
30657
  function validUpdatedAt(value) {
30161
30658
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 && value <= DEEPSEEK_MODERN_SESSION_UPDATED_AT_MAX && !Object.is(value, -0);
30162
30659
  }
30163
- function titleFromProjections(value) {
30660
+ function titleFromProjections(value, profile) {
30164
30661
  if (value === void 0)
30165
30662
  return null;
30166
- if (!isPlainRecord7(value) || !exactKeys5(value, ["asOfSeq", "values"]) || !Number.isSafeInteger(value.asOfSeq) || value.asOfSeq < -1 || !isPlainRecord7(value.values)) {
30663
+ if (!isPlainRecord7(value) || !exactKeys5(value, profile.sessionFormatVersion === 4 ? ["kind", "asOfSeq", "values"] : ["asOfSeq", "values"]) || profile.sessionFormatVersion === 4 && value.kind !== "cached" && value.kind !== "sequenced" || !Number.isSafeInteger(value.asOfSeq) || value.asOfSeq < -1 || !isPlainRecord7(value.values)) {
30167
30664
  throw sessionListError("protocolError", "DeepSeek Harness returned invalid Session list projections");
30168
30665
  }
30169
30666
  const title = value.values.title;
30170
30667
  return typeof title === "string" && title.trim().length > 0 && title.length <= DEEPSEEK_MODERN_SESSION_TITLE_MAX_LENGTH && !title.includes("\0") ? title : null;
30171
30668
  }
30172
- function parseSummary(value) {
30173
- if (!isPlainRecord7(value) || !exactKeys5(value, ["sessionId", "updatedAt", "running", "blank"], ["parentSessionId", "origin", "cwd", "projections"]) || typeof value.running !== "boolean" || typeof value.blank !== "boolean" || !validUpdatedAt(value.updatedAt)) {
30669
+ function parseSummary(value, profile) {
30670
+ if (!isPlainRecord7(value) || !exactKeys5(value, profile.sessionFormatVersion === 4 ? ["sessionId", "updatedAt", "agentAvailable", "running", "blank"] : ["sessionId", "updatedAt", "running", "blank"], ["parentSessionId", "origin", "cwd", "projections"]) || typeof value.running !== "boolean" || typeof value.blank !== "boolean" || profile.sessionFormatVersion === 4 && typeof value.agentAvailable !== "boolean" || !validUpdatedAt(value.updatedAt)) {
30174
30671
  throw sessionListError("protocolError", "DeepSeek Harness returned an invalid Session row");
30175
30672
  }
30176
30673
  const sessionId = boundedId(value.sessionId, "Session id");
@@ -30193,13 +30690,13 @@ function parseSummary(value) {
30193
30690
  blank: value.blank,
30194
30691
  ...value.origin === void 0 ? {} : { origin: value.origin },
30195
30692
  ...value.cwd === void 0 ? {} : { cwd: value.cwd },
30196
- title: titleFromProjections(value.projections)
30693
+ title: titleFromProjections(value.projections, profile)
30197
30694
  };
30198
30695
  }
30199
30696
  function isCanonicalAbsoluteCwd(value) {
30200
30697
  return value !== void 0 && value.trim().length > 0 && !value.includes("\0") && path2.isAbsolute(value) && path2.resolve(value) === value;
30201
30698
  }
30202
- function parseModernSessionCandidates(value) {
30699
+ function parseModernSessionCandidates(value, profile = DEEPSEEK_V015_PROFILE) {
30203
30700
  assertBoundedJson4(value);
30204
30701
  if (!isPlainRecord7(value) || !exactKeys5(value, ["items"]) || !Array.isArray(value.items)) {
30205
30702
  throw sessionListError("protocolError", "DeepSeek Harness returned an invalid Session list");
@@ -30209,7 +30706,7 @@ function parseModernSessionCandidates(value) {
30209
30706
  }
30210
30707
  const seen = /* @__PURE__ */ new Set();
30211
30708
  const summaries = value.items.map((item) => {
30212
- const summary = parseSummary(item);
30709
+ const summary = parseSummary(item, profile);
30213
30710
  if (seen.has(summary.sessionId)) {
30214
30711
  throw sessionListError("protocolError", "DeepSeek Harness returned duplicate Session identities");
30215
30712
  }
@@ -30231,14 +30728,14 @@ function parseModernSessionCandidates(value) {
30231
30728
  ];
30232
30729
  });
30233
30730
  }
30234
- async function loadModernSessionCandidates(remote, signal) {
30731
+ async function loadModernSessionCandidates(remote, signal, profile = DEEPSEEK_V015_PROFILE) {
30235
30732
  try {
30236
30733
  const result = await remote.call("session/list", { _request: {} }, signal);
30237
30734
  if (!result.ok) {
30238
30735
  const safe = sanitizeModernRemoteFailure(result.error);
30239
30736
  throw sessionListError("remoteError", `DeepSeek Harness session/list failed: ${safe.message}`, safe.code);
30240
30737
  }
30241
- return parseModernSessionCandidates(result.value);
30738
+ return parseModernSessionCandidates(result.value, profile);
30242
30739
  } catch (error51) {
30243
30740
  if (error51 instanceof ModernSessionListError)
30244
30741
  throw error51;
@@ -30307,6 +30804,7 @@ var ModernDeepSeekHarnessAdapter = class {
30307
30804
  onFault: (error51) => this.#fail(toHarnessError(error51, "unavailable"))
30308
30805
  });
30309
30806
  this.#control = new ModernControlStore(this.#connection, {
30807
+ profile: this.#profile,
30310
30808
  onFault: (error51) => this.#fail(toHarnessError(error51, "unavailable"))
30311
30809
  });
30312
30810
  this.#removeConnectionFaultListener = this.#connection.onFault((error51) => {
@@ -30379,7 +30877,7 @@ var ModernDeepSeekHarnessAdapter = class {
30379
30877
  try {
30380
30878
  await this.#connection.connect();
30381
30879
  this.#assertAccepting();
30382
- const candidates = await loadModernSessionCandidates(this.#connection, this.#lifetime.signal);
30880
+ const candidates = await loadModernSessionCandidates(this.#connection, this.#lifetime.signal, this.#profile);
30383
30881
  this.#assertAccepting();
30384
30882
  return { ok: true, value: candidates };
30385
30883
  } catch (error51) {
@@ -30475,7 +30973,7 @@ var ModernDeepSeekHarnessAdapter = class {
30475
30973
  this.#assertAccepting();
30476
30974
  if (forkExpectation) {
30477
30975
  await this.#verifyForkJournal(forkExpectation, journal, cwd);
30478
- if (isDeepSeekV015(this.#profile) && await clearInheritedForkInbox(this.#connection, journal, this.#lifetime.signal)) {
30976
+ if (hasDeepSeekModernStream(this.#profile) && await clearInheritedForkInbox(this.#connection, journal, this.#lifetime.signal)) {
30479
30977
  await journal.close();
30480
30978
  journal = await openModernJournal(this.#connection, { sessionId, cwd }, this.#journalOptions());
30481
30979
  await this.#verifyForkJournal(forkExpectation, journal, cwd);
@@ -30511,10 +31009,11 @@ var ModernDeepSeekHarnessAdapter = class {
30511
31009
  harnessId: this.harnessId,
30512
31010
  nativeSessionId: sessionId,
30513
31011
  formatVersion: 1,
30514
- ...isDeepSeekV015(this.#profile) ? { locator: { dshVersion: this.#profile.version } } : {}
31012
+ ...hasDeepSeekModernStream(this.#profile) ? { locator: { dshVersion: this.#profile.version } } : {}
30515
31013
  }),
30516
31014
  modelCatalog: catalog,
30517
- permissionModes
31015
+ permissionModes,
31016
+ profile: this.#profile
30518
31017
  });
30519
31018
  verifyCreateConfiguration(createConfiguration, openedConfiguration);
30520
31019
  if (createConfiguration?.unattended && !delegationPermissionIsApplied(journal.events)) {
@@ -30532,7 +31031,7 @@ var ModernDeepSeekHarnessAdapter = class {
30532
31031
  modelCatalog: catalog,
30533
31032
  permissionModes,
30534
31033
  sessionId,
30535
- ...isDeepSeekV015(this.#profile) ? { flushSession: () => this.#connection.flushSession(sessionId) } : {},
31034
+ ...hasDeepSeekModernStream(this.#profile) ? { flushSession: () => this.#connection.flushSession(sessionId) } : {},
30536
31035
  randomUUID: this.#dependencies.randomUUID,
30537
31036
  now: this.#dependencies.now,
30538
31037
  ...this.#options.toolOutputLimit === void 0 ? {} : { toolOutputLimit: this.#options.toolOutputLimit },
@@ -30674,7 +31173,7 @@ var ModernDeepSeekHarnessAdapter = class {
30674
31173
  }
30675
31174
  atSeq = boundary.atSeq;
30676
31175
  minimumSeedLength = boundary.events.length;
30677
- if (boundary.events.length < source.events.length) {
31176
+ if (this.#profile.sessionFormatVersion === 4 || boundary.events.length < source.events.length) {
30678
31177
  exactSeedLength = boundary.events.length;
30679
31178
  }
30680
31179
  } finally {
@@ -30767,7 +31266,7 @@ var ModernDeepSeekHarnessAdapter = class {
30767
31266
  }
30768
31267
  if (this.#permissionModesPromise)
30769
31268
  return this.#permissionModesPromise;
30770
- const operation = loadModernPermissionModeCatalog(this.#connection).then((catalog) => {
31269
+ const operation = loadModernPermissionModeCatalog(this.#connection, this.#lifetime.signal, this.#profile).then((catalog) => {
30771
31270
  this.#permissionModes = catalog;
30772
31271
  this.#permissionModesLoaded = true;
30773
31272
  return catalog;
@@ -30992,18 +31491,19 @@ function parseModernForkInput(input, profile) {
30992
31491
  function sessionLocatorMatches(locator, profile) {
30993
31492
  if (locator === void 0)
30994
31493
  return true;
30995
- if (!isDeepSeekV015(profile) || !isRecord8(locator) || Reflect.ownKeys(locator).length !== 1 || typeof locator.dshVersion !== "string") {
31494
+ if (!hasDeepSeekModernStream(profile) || !isRecord8(locator) || Reflect.ownKeys(locator).length !== 1 || typeof locator.dshVersion !== "string") {
30996
31495
  return false;
30997
31496
  }
30998
31497
  try {
30999
31498
  const { version: version2 } = classifyDeepSeekVersionOutput(locator.dshVersion);
31000
- return isDeepSeekV015(deepSeekModernProfile(version2));
31499
+ const original = deepSeekModernProfile(version2);
31500
+ return original.sessionFormatVersion === profile.sessionFormatVersion || profile.sessionFormatVersion === 4 && original.sessionFormatVersion === 3;
31001
31501
  } catch {
31002
31502
  return false;
31003
31503
  }
31004
31504
  }
31005
31505
  function checkpointLocatorMatches(locator, profile) {
31006
- return isDeepSeekV015(profile) ? profileLocatorMatches(locator, profile) : locator === void 0;
31506
+ return hasDeepSeekModernStream(profile) ? profileLocatorMatches(locator, profile) : locator === void 0;
31007
31507
  }
31008
31508
  function profileLocatorMatches(locator, profile) {
31009
31509
  return isRecord8(locator) && Reflect.ownKeys(locator).length === 1 && locator.dshVersion === profile.version;
@@ -31214,7 +31714,7 @@ var DeepSeekHarnessAdapter = class {
31214
31714
  harnessId: this.harnessId,
31215
31715
  nativeSessionId,
31216
31716
  formatVersion: 1,
31217
- ...this.#delegate && isDeepSeekV015(deepSeekModernProfile(this.#delegate.version)) ? { locator: { dshVersion: this.#delegate.version } } : {}
31717
+ ...this.#delegate && hasDeepSeekModernStream(deepSeekModernProfile(this.#delegate.version)) ? { locator: { dshVersion: this.#delegate.version } } : {}
31218
31718
  })
31219
31719
  }
31220
31720
  };