@kbediako/codex-orchestrator 0.1.4 → 0.1.5

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.
@@ -831,6 +831,42 @@ async function runJsonRpcServer(handler, options = {}) {
831
831
  }
832
832
  const headerEnd = buffer.indexOf('\r\n\r\n');
833
833
  if (headerEnd === -1) {
834
+ const newlineIndex = buffer.indexOf('\n');
835
+ if (newlineIndex !== -1) {
836
+ const lineBuffer = buffer.slice(0, newlineIndex);
837
+ const line = lineBuffer.toString('utf8').trim();
838
+ buffer = buffer.slice(newlineIndex + 1);
839
+ if (!line) {
840
+ continue;
841
+ }
842
+ const normalizedLine = line.trimStart();
843
+ const looksLikeHeaderLine = /^[A-Za-z0-9-]+:/.test(normalizedLine);
844
+ const looksLikeJson = normalizedLine.startsWith('{') || normalizedLine.startsWith('[');
845
+ const isContentLength = normalizedLine.toLowerCase().startsWith('content-length:');
846
+ let restoredHeader = false;
847
+ if (!looksLikeJson && looksLikeHeaderLine) {
848
+ // Fall through to header-size checks for partial Content-Length frames (and other header lines).
849
+ buffer = Buffer.concat([Buffer.from(lineBuffer), Buffer.from('\n'), buffer]);
850
+ restoredHeader = true;
851
+ }
852
+ else if (!isContentLength) {
853
+ const lineBytes = Buffer.byteLength(line, 'utf8');
854
+ if (lineBytes > MAX_MCP_MESSAGE_BYTES) {
855
+ handleProtocolViolation(`Rejecting MCP payload (${lineBytes} bytes) larger than ${MAX_MCP_MESSAGE_BYTES}`);
856
+ return;
857
+ }
858
+ await handleMessage(line);
859
+ continue;
860
+ }
861
+ if (!restoredHeader && isContentLength) {
862
+ // Fall through to header-size checks for partial Content-Length frames.
863
+ buffer = Buffer.concat([Buffer.from(lineBuffer), Buffer.from('\n'), buffer]);
864
+ }
865
+ }
866
+ else if (buffer.length > MAX_MCP_MESSAGE_BYTES) {
867
+ handleProtocolViolation(`Rejecting MCP payload (${buffer.length} bytes) larger than ${MAX_MCP_MESSAGE_BYTES}`);
868
+ return;
869
+ }
834
870
  if (buffer.length > MAX_MCP_HEADER_BYTES) {
835
871
  const overflow = buffer.slice(MAX_MCP_HEADER_BYTES);
836
872
  const allowedPrefix = MCP_HEADER_DELIMITER_BUFFER.subarray(0, overflow.length);
@@ -851,6 +887,19 @@ async function runJsonRpcServer(handler, options = {}) {
851
887
  return;
852
888
  }
853
889
  if (parsed.length === null) {
890
+ const lines = header.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
891
+ if (lines.length === 0) {
892
+ buffer = buffer.slice(headerEnd + 4);
893
+ continue;
894
+ }
895
+ const allJsonLike = lines.every((line) => line.startsWith('{') || line.startsWith('['));
896
+ if (allJsonLike) {
897
+ buffer = buffer.slice(headerEnd + 4);
898
+ for (const line of lines) {
899
+ await handleMessage(line);
900
+ }
901
+ continue;
902
+ }
854
903
  handleProtocolViolation('Missing Content-Length header in MCP message');
855
904
  return;
856
905
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kbediako/codex-orchestrator",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "bin": {