@xcanwin/manyoyo 5.6.6 → 5.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/codex-output.js +25 -0
- package/lib/dev-release.js +2 -20
- package/lib/web/server.js +14 -33
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function extractAgentMessageFromCodexJsonl(text) {
|
|
4
|
+
let lastMessage = '';
|
|
5
|
+
for (const rawLine of String(text || '').split('\n')) {
|
|
6
|
+
const line = rawLine.trim();
|
|
7
|
+
if (!line) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
let payload;
|
|
11
|
+
try {
|
|
12
|
+
payload = JSON.parse(line);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
if (payload && payload.type === 'item.completed' && payload.item && payload.item.type === 'agent_message') {
|
|
17
|
+
lastMessage = String(payload.item.text || '');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return lastMessage.trim();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
extractAgentMessageFromCodexJsonl
|
|
25
|
+
};
|
package/lib/dev-release.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { extractAgentMessageFromCodexJsonl } = require('./codex-output');
|
|
2
|
+
|
|
1
3
|
function parseReleaseVersion(version) {
|
|
2
4
|
const match = String(version || '').trim().match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
3
5
|
if (!match) {
|
|
@@ -123,26 +125,6 @@ function normalizeCommitMessage(text) {
|
|
|
123
125
|
return lines.slice(start, end).join('\n').trim();
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
function extractAgentMessageFromCodexJsonl(text) {
|
|
127
|
-
let lastMessage = '';
|
|
128
|
-
for (const rawLine of String(text || '').split('\n')) {
|
|
129
|
-
const line = rawLine.trim();
|
|
130
|
-
if (!line) {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
let payload;
|
|
134
|
-
try {
|
|
135
|
-
payload = JSON.parse(line);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (payload && payload.type === 'item.completed' && payload.item && payload.item.type === 'agent_message') {
|
|
140
|
-
lastMessage = String(payload.item.text || '');
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return lastMessage.trim();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
128
|
module.exports = {
|
|
147
129
|
parseReleaseVersion,
|
|
148
130
|
compareReleaseVersions,
|
package/lib/web/server.js
CHANGED
|
@@ -9,6 +9,7 @@ const http = require('http');
|
|
|
9
9
|
const WebSocket = require('ws');
|
|
10
10
|
const JSON5 = require('json5');
|
|
11
11
|
const { buildContainerRunArgs } = require('../container-run');
|
|
12
|
+
const { extractAgentMessageFromCodexJsonl } = require('../codex-output');
|
|
12
13
|
const {
|
|
13
14
|
resolveAgentProgram,
|
|
14
15
|
resolveAgentPromptCommandTemplate,
|
|
@@ -26,8 +27,6 @@ const WEB_TERMINAL_MIN_ROWS = 12;
|
|
|
26
27
|
const WEB_AGENT_CONTEXT_MAX_MESSAGES = 24;
|
|
27
28
|
const WEB_AGENT_CONTEXT_MAX_CHARS = 6000;
|
|
28
29
|
const WEB_AGENT_CONTEXT_PER_MESSAGE_MAX_CHARS = 600;
|
|
29
|
-
const WEB_AGENT_LAST_MESSAGE_BEGIN_MARKER = '__MANYOYO_LAST_MESSAGE_BEGIN__';
|
|
30
|
-
const WEB_AGENT_LAST_MESSAGE_END_MARKER = '__MANYOYO_LAST_MESSAGE_END__';
|
|
31
30
|
const WEB_AUTH_COOKIE_NAME = 'manyoyo_web_auth';
|
|
32
31
|
const WEB_AUTH_TTL_SECONDS = 12 * 60 * 60;
|
|
33
32
|
const FRONTEND_DIR = path.join(__dirname, 'frontend');
|
|
@@ -282,23 +281,20 @@ function renderAgentPromptCommand(template, prompt) {
|
|
|
282
281
|
|
|
283
282
|
function buildCodexAgentExecCommand(template, prompt) {
|
|
284
283
|
const templateText = normalizeAgentPromptCommandTemplate(template, 'agentPromptCommand');
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
const codexTemplate = templateText.replace(
|
|
288
|
-
/^((?:(?:[A-Za-z_][A-Za-z0-9_]*=)(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\s]+)\s+)*)codex\s+exec\b/,
|
|
289
|
-
`$1codex exec --output-last-message ${quotedOutputFile}`
|
|
284
|
+
const execMatch = templateText.match(
|
|
285
|
+
/^((?:(?:[A-Za-z_][A-Za-z0-9_]*=)(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|[^\s]+)\s+)*)codex\s+exec\b/
|
|
290
286
|
);
|
|
291
|
-
|
|
287
|
+
let codexTemplate = templateText;
|
|
288
|
+
if (execMatch) {
|
|
289
|
+
const prefix = execMatch[1] || '';
|
|
290
|
+
const suffix = templateText.slice(execMatch[0].length);
|
|
291
|
+
const hasJson = /(?:^|\s)--json(?:\s|$)/.test(suffix);
|
|
292
|
+
const injectedFlags = hasJson ? '' : ' --json';
|
|
293
|
+
codexTemplate = `${prefix}codex exec${injectedFlags}${suffix}`;
|
|
294
|
+
}
|
|
295
|
+
return codexTemplate === templateText
|
|
292
296
|
? renderAgentPromptCommand(templateText, prompt)
|
|
293
297
|
: renderAgentPromptCommand(codexTemplate, prompt);
|
|
294
|
-
return [
|
|
295
|
-
`rm -f ${quotedOutputFile}`,
|
|
296
|
-
command,
|
|
297
|
-
'__manyoyo_agent_exit=$?',
|
|
298
|
-
`if [ -f ${quotedOutputFile} ]; then printf '\\n${WEB_AGENT_LAST_MESSAGE_BEGIN_MARKER}\\n'; cat ${quotedOutputFile}; printf '\\n${WEB_AGENT_LAST_MESSAGE_END_MARKER}\\n'; fi`,
|
|
299
|
-
`rm -f ${quotedOutputFile}`,
|
|
300
|
-
'exit $__manyoyo_agent_exit'
|
|
301
|
-
].join('; ');
|
|
302
298
|
}
|
|
303
299
|
|
|
304
300
|
function buildWebAgentExecCommand(template, prompt, agentProgram) {
|
|
@@ -308,21 +304,6 @@ function buildWebAgentExecCommand(template, prompt, agentProgram) {
|
|
|
308
304
|
return renderAgentPromptCommand(template, prompt);
|
|
309
305
|
}
|
|
310
306
|
|
|
311
|
-
function extractLastMessageOutput(text) {
|
|
312
|
-
const raw = String(text || '');
|
|
313
|
-
const pattern = new RegExp(
|
|
314
|
-
`(?:^|\\r?\\n)${WEB_AGENT_LAST_MESSAGE_BEGIN_MARKER}\\r?\\n([\\s\\S]*?)(?:\\r?\\n)${WEB_AGENT_LAST_MESSAGE_END_MARKER}(?:\\r?\\n|$)`,
|
|
315
|
-
'g'
|
|
316
|
-
);
|
|
317
|
-
let lastMatch = null;
|
|
318
|
-
let matched = pattern.exec(raw);
|
|
319
|
-
while (matched) {
|
|
320
|
-
lastMatch = matched[1];
|
|
321
|
-
matched = pattern.exec(raw);
|
|
322
|
-
}
|
|
323
|
-
return String(lastMatch || '').trim();
|
|
324
|
-
}
|
|
325
|
-
|
|
326
307
|
function getAgentRuntimeMeta(history) {
|
|
327
308
|
const sessionHistory = history && typeof history === 'object' ? history : {};
|
|
328
309
|
const template = normalizeAgentPromptCommandTemplate(sessionHistory.agentPromptCommand, 'agentPromptCommand');
|
|
@@ -1188,8 +1169,8 @@ async function execCommandInWebContainer(ctx, containerName, command) {
|
|
|
1188
1169
|
const clippedStdout = stdoutTruncated ? `${stdoutOutput}\n...[stdout-truncated]` : stdoutOutput;
|
|
1189
1170
|
const clippedStderr = stderrTruncated ? `${stderrOutput}\n...[stderr-truncated]` : stderrOutput;
|
|
1190
1171
|
const clippedRaw = `${clippedStdout}${clippedStdout && clippedStderr ? '\n' : ''}${clippedStderr}`;
|
|
1191
|
-
const
|
|
1192
|
-
const cleanOutputSource =
|
|
1172
|
+
const extractedJsonAgentMessage = extractAgentMessageFromCodexJsonl(clippedStdout);
|
|
1173
|
+
const cleanOutputSource = extractedJsonAgentMessage || clippedRaw;
|
|
1193
1174
|
const output = clipText(stripAnsi(cleanOutputSource).trim() || '(无输出)');
|
|
1194
1175
|
resolve({ exitCode, output });
|
|
1195
1176
|
});
|