@unson/brainbase-mcp 0.51.1 → 0.51.2
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.
|
@@ -148,7 +148,25 @@ export declare function extractLatestNonSystemUserInput(transcriptPath: unknown,
|
|
|
148
148
|
content: string;
|
|
149
149
|
} | null;
|
|
150
150
|
export declare function extractLastAssistantMessage(transcriptPath: unknown, options?: TranscriptReadOptions): string | undefined;
|
|
151
|
+
/**
|
|
152
|
+
* Splits whitespace/newline-concatenated top-level JSON objects/arrays (`{...}` / `[...]`)
|
|
153
|
+
* in a single strict O(n) character scan without regex backtracking.
|
|
154
|
+
*
|
|
155
|
+
* Antigravity CLI concatenates multiple MCP text content blocks with `\n` when writing
|
|
156
|
+
* `steps/<n>/output.txt` and `transcript*.jsonl` (for example, a primary tool result JSON
|
|
157
|
+
* followed by a trailing `{"connection_scope":{...}}` block). When 2+ top-level JSON
|
|
158
|
+
* containers are found and every block validates via `JSON.parse`, returns the individual
|
|
159
|
+
* blocks so `tool_response.content` restores the original multi-block MCP structure.
|
|
160
|
+
* For a single JSON value, non-JSON text, or any malformed/partial block, fails open and
|
|
161
|
+
* returns `[text]`.
|
|
162
|
+
*/
|
|
163
|
+
export declare function splitConcatenatedJsonTextBlocks(text: string): string[];
|
|
151
164
|
export declare function extractToolResultFromTranscript(transcriptPath: unknown, stepIdx: unknown, options?: TranscriptReadOptions): string | null;
|
|
165
|
+
/**
|
|
166
|
+
* Extracts a tool result from the authorized transcript / step output and restores
|
|
167
|
+
* whitespace/newline-concatenated MCP JSON text blocks into individual text block strings.
|
|
168
|
+
*/
|
|
169
|
+
export declare function extractToolResultTextBlocksFromTranscript(transcriptPath: unknown, stepIdx: unknown, options?: TranscriptReadOptions): string[] | null;
|
|
152
170
|
declare function turnKey(conversationId: string, configPath: string): string;
|
|
153
171
|
declare function statePath(env: NodeJS.ProcessEnv, key: string): string;
|
|
154
172
|
declare function lockPathFor(env: NodeJS.ProcessEnv, key: string): string;
|
|
@@ -1024,6 +1024,9 @@ function entryToolUseId(entry) {
|
|
|
1024
1024
|
function hasTruncatedContentField(entry) {
|
|
1025
1025
|
return Array.isArray(entry.truncated_fields) && entry.truncated_fields.includes('content');
|
|
1026
1026
|
}
|
|
1027
|
+
function isJsonWhitespaceCode(code) {
|
|
1028
|
+
return code === 0x20 || code === 0x09 || code === 0x0a || code === 0x0d;
|
|
1029
|
+
}
|
|
1027
1030
|
function isValidJsonText(text) {
|
|
1028
1031
|
try {
|
|
1029
1032
|
JSON.parse(text);
|
|
@@ -1033,12 +1036,112 @@ function isValidJsonText(text) {
|
|
|
1033
1036
|
return false;
|
|
1034
1037
|
}
|
|
1035
1038
|
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Splits whitespace/newline-concatenated top-level JSON objects/arrays (`{...}` / `[...]`)
|
|
1041
|
+
* in a single strict O(n) character scan without regex backtracking.
|
|
1042
|
+
*
|
|
1043
|
+
* Antigravity CLI concatenates multiple MCP text content blocks with `\n` when writing
|
|
1044
|
+
* `steps/<n>/output.txt` and `transcript*.jsonl` (for example, a primary tool result JSON
|
|
1045
|
+
* followed by a trailing `{"connection_scope":{...}}` block). When 2+ top-level JSON
|
|
1046
|
+
* containers are found and every block validates via `JSON.parse`, returns the individual
|
|
1047
|
+
* blocks so `tool_response.content` restores the original multi-block MCP structure.
|
|
1048
|
+
* For a single JSON value, non-JSON text, or any malformed/partial block, fails open and
|
|
1049
|
+
* returns `[text]`.
|
|
1050
|
+
*/
|
|
1051
|
+
export function splitConcatenatedJsonTextBlocks(text) {
|
|
1052
|
+
const length = text.length;
|
|
1053
|
+
if (length === 0)
|
|
1054
|
+
return [text];
|
|
1055
|
+
let i = 0;
|
|
1056
|
+
while (i < length && isJsonWhitespaceCode(text.charCodeAt(i))) {
|
|
1057
|
+
i += 1;
|
|
1058
|
+
}
|
|
1059
|
+
if (i >= length)
|
|
1060
|
+
return [text];
|
|
1061
|
+
const firstCode = text.charCodeAt(i);
|
|
1062
|
+
if (firstCode !== 0x7b && firstCode !== 0x5b) {
|
|
1063
|
+
return [text];
|
|
1064
|
+
}
|
|
1065
|
+
const candidates = [];
|
|
1066
|
+
const closeStack = [];
|
|
1067
|
+
while (i < length) {
|
|
1068
|
+
const start = i;
|
|
1069
|
+
const openCode = text.charCodeAt(i);
|
|
1070
|
+
if (openCode === 0x7b) {
|
|
1071
|
+
closeStack.push(0x7d);
|
|
1072
|
+
}
|
|
1073
|
+
else if (openCode === 0x5b) {
|
|
1074
|
+
closeStack.push(0x5d);
|
|
1075
|
+
}
|
|
1076
|
+
else {
|
|
1077
|
+
return [text];
|
|
1078
|
+
}
|
|
1079
|
+
i += 1;
|
|
1080
|
+
let inString = false;
|
|
1081
|
+
let escaped = false;
|
|
1082
|
+
while (i < length && closeStack.length > 0) {
|
|
1083
|
+
const code = text.charCodeAt(i);
|
|
1084
|
+
if (inString) {
|
|
1085
|
+
if (escaped) {
|
|
1086
|
+
escaped = false;
|
|
1087
|
+
}
|
|
1088
|
+
else if (code === 0x5c) {
|
|
1089
|
+
escaped = true;
|
|
1090
|
+
}
|
|
1091
|
+
else if (code === 0x22) {
|
|
1092
|
+
inString = false;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
else if (code === 0x22) {
|
|
1096
|
+
inString = true;
|
|
1097
|
+
}
|
|
1098
|
+
else if (code === 0x7b) {
|
|
1099
|
+
closeStack.push(0x7d);
|
|
1100
|
+
}
|
|
1101
|
+
else if (code === 0x5b) {
|
|
1102
|
+
closeStack.push(0x5d);
|
|
1103
|
+
}
|
|
1104
|
+
else if (code === 0x7d || code === 0x5d) {
|
|
1105
|
+
if (closeStack[closeStack.length - 1] !== code) {
|
|
1106
|
+
return [text];
|
|
1107
|
+
}
|
|
1108
|
+
closeStack.pop();
|
|
1109
|
+
}
|
|
1110
|
+
i += 1;
|
|
1111
|
+
}
|
|
1112
|
+
if (closeStack.length !== 0 || inString) {
|
|
1113
|
+
return [text];
|
|
1114
|
+
}
|
|
1115
|
+
candidates.push(text.slice(start, i));
|
|
1116
|
+
const wsStart = i;
|
|
1117
|
+
while (i < length && isJsonWhitespaceCode(text.charCodeAt(i))) {
|
|
1118
|
+
i += 1;
|
|
1119
|
+
}
|
|
1120
|
+
if (i < length && i === wsStart) {
|
|
1121
|
+
return [text];
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
if (candidates.length < 2) {
|
|
1125
|
+
return [text];
|
|
1126
|
+
}
|
|
1127
|
+
for (const block of candidates) {
|
|
1128
|
+
if (!isValidJsonText(block)) {
|
|
1129
|
+
return [text];
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return candidates;
|
|
1133
|
+
}
|
|
1134
|
+
function isValidJsonOrConcatenatedJsonText(text) {
|
|
1135
|
+
if (isValidJsonText(text))
|
|
1136
|
+
return true;
|
|
1137
|
+
return splitConcatenatedJsonTextBlocks(text).length > 1;
|
|
1138
|
+
}
|
|
1036
1139
|
function isTruncatedToolResult(entry, strippedContent) {
|
|
1037
1140
|
if (hasTruncatedContentField(entry))
|
|
1038
1141
|
return true;
|
|
1039
1142
|
if (TOOL_OUTPUT_TRUNCATION_BANNER_PATTERN.test(strippedContent))
|
|
1040
1143
|
return true;
|
|
1041
|
-
if (INLINE_TRUNCATION_MARKER_PATTERN.test(strippedContent) && !
|
|
1144
|
+
if (INLINE_TRUNCATION_MARKER_PATTERN.test(strippedContent) && !isValidJsonOrConcatenatedJsonText(strippedContent)) {
|
|
1042
1145
|
return true;
|
|
1043
1146
|
}
|
|
1044
1147
|
return false;
|
|
@@ -1310,6 +1413,16 @@ export function extractToolResultFromTranscript(transcriptPath, stepIdx, options
|
|
|
1310
1413
|
const referenceTexts = fullStripped !== null ? [fullStripped, baseStripped] : [baseStripped];
|
|
1311
1414
|
return readStepOutputFallback(baseTarget, conversationId, referenceTexts, effectiveStepCandidates, options);
|
|
1312
1415
|
}
|
|
1416
|
+
/**
|
|
1417
|
+
* Extracts a tool result from the authorized transcript / step output and restores
|
|
1418
|
+
* whitespace/newline-concatenated MCP JSON text blocks into individual text block strings.
|
|
1419
|
+
*/
|
|
1420
|
+
export function extractToolResultTextBlocksFromTranscript(transcriptPath, stepIdx, options) {
|
|
1421
|
+
const extracted = extractToolResultFromTranscript(transcriptPath, stepIdx, options);
|
|
1422
|
+
if (extracted === null)
|
|
1423
|
+
return null;
|
|
1424
|
+
return splitConcatenatedJsonTextBlocks(extracted);
|
|
1425
|
+
}
|
|
1313
1426
|
// ---- Turn state persistence & exclusive lock ----
|
|
1314
1427
|
function turnDirectory(env) {
|
|
1315
1428
|
return env.BRAINBASE_ANTIGRAVITY_JUDGMENT_TURN_DIR
|
|
@@ -2044,10 +2157,10 @@ async function handlePostToolUse(payload, conversationId, context) {
|
|
|
2044
2157
|
if (isBrainbase) {
|
|
2045
2158
|
toolInput = normalizedToolInput(rawName, normalizedName, toolCall?.args);
|
|
2046
2159
|
const toolCallId = typeof toolCall?.id === 'string' && toolCall.id.trim() ? toolCall.id.trim() : undefined;
|
|
2047
|
-
const
|
|
2048
|
-
if (
|
|
2160
|
+
const transcriptBlocks = extractToolResultTextBlocksFromTranscript(payload.transcriptPath, payload.stepIdx, toolCallId ? { ...transcriptOpts, toolUseId: toolCallId } : transcriptOpts);
|
|
2161
|
+
if (transcriptBlocks !== null) {
|
|
2049
2162
|
toolResponse = {
|
|
2050
|
-
content:
|
|
2163
|
+
content: transcriptBlocks.map((text) => ({ type: 'text', text })),
|
|
2051
2164
|
isError: hasError,
|
|
2052
2165
|
};
|
|
2053
2166
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unson/brainbase-mcp",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.2",
|
|
4
4
|
"description": "Local-first Brainbase judgment OS that lets supported AI agents reuse a user's approved goals, priorities, decisions, and judgment criteria.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -669,5 +669,5 @@
|
|
|
669
669
|
"url": "https://github.com/Unson-LLC/brainbase/issues"
|
|
670
670
|
},
|
|
671
671
|
"homepage": "https://github.com/Unson-LLC/brainbase#readme",
|
|
672
|
-
"gitHead": "
|
|
672
|
+
"gitHead": "4a7abf68a2e2f8da4b59d3f0c3efd7c5098eb64b"
|
|
673
673
|
}
|