@nowcrew/daemon 0.5.22 → 0.5.23
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/dist/console-collapse.js +13 -0
- package/dist/console-formatter.js +14 -1
- package/dist/console.js +9 -1
- package/dist/json-result.js +27 -0
- package/dist/skill-preview.js +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const MESSAGE_READ = /\bcrew\s+(?:message|thread)\s+read\b/i;
|
|
2
|
+
const TASK_LIST = /\bcrew\s+task\s+list\b/i;
|
|
3
|
+
export function buildCollapsedResult(command, output) {
|
|
4
|
+
if (MESSAGE_READ.test(command)) {
|
|
5
|
+
const count = output.split("\n").filter((line) => /^#\d+\s+\(msg=/.test(line.trim())).length;
|
|
6
|
+
return { kind: "collapsed_result", label: "CHANNEL HISTORY", count };
|
|
7
|
+
}
|
|
8
|
+
if (TASK_LIST.test(command)) {
|
|
9
|
+
const count = output.split("\n").filter((line) => /^#\d+\s+\[/.test(line.trim())).length;
|
|
10
|
+
return { kind: "collapsed_result", label: "TASK LIST", count };
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
import { buildFilePreview } from "./console-payload.js";
|
|
6
6
|
import { toConsoleLines, TOOL_RESULT_CAP } from "./console.js";
|
|
7
7
|
import { parseUnifiedDiff } from "./unified-diff.js";
|
|
8
|
+
import { buildJsonResult } from "./json-result.js";
|
|
9
|
+
import { buildCollapsedResult } from "./console-collapse.js";
|
|
10
|
+
import { buildSkillPreview } from "./skill-preview.js";
|
|
8
11
|
const extract = (content) => {
|
|
9
12
|
if (typeof content === "string")
|
|
10
13
|
return content;
|
|
@@ -48,9 +51,19 @@ export function createConsoleFormatter() {
|
|
|
48
51
|
continue;
|
|
49
52
|
}
|
|
50
53
|
const patch = block.is_error ? null : parseUnifiedDiff(text);
|
|
54
|
+
const command = tool?.name === "Bash" && typeof tool.input?.command === "string" ? tool.input.command : "";
|
|
55
|
+
const skill = block.is_error || tool?.name !== "Skill" ? null : buildSkillPreview(text);
|
|
56
|
+
const collapsed = block.is_error || patch || skill || !command ? null : buildCollapsedResult(command, text);
|
|
57
|
+
const json = block.is_error || patch || skill || collapsed || !command ? null : buildJsonResult(command, text);
|
|
51
58
|
out.push(patch
|
|
52
59
|
? { stream: "tool_result", text: `Changed ${patch.files.length} file(s): +${patch.additions} -${patch.deletions}`, payload: patch }
|
|
53
|
-
:
|
|
60
|
+
: skill
|
|
61
|
+
? { stream: "tool_result", text: "READ SKILL", payload: skill }
|
|
62
|
+
: collapsed
|
|
63
|
+
? { stream: "tool_result", text: collapsed.label, payload: collapsed }
|
|
64
|
+
: json
|
|
65
|
+
? { stream: "tool_result", text: json.label, payload: json }
|
|
66
|
+
: { stream: "tool_result", text: clip(text) });
|
|
54
67
|
}
|
|
55
68
|
return out;
|
|
56
69
|
}
|
package/dist/console.js
CHANGED
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
import { detectDaemonLang, translateDaemon } from "./i18n.js";
|
|
16
16
|
import { buildFilePreview, buildSnippetDiff } from "./console-payload.js";
|
|
17
17
|
import { parseUnifiedDiff } from "./unified-diff.js";
|
|
18
|
+
import { buildJsonResult } from "./json-result.js";
|
|
19
|
+
import { buildCollapsedResult } from "./console-collapse.js";
|
|
18
20
|
/** 单条工具返回正文上限(超出截断并标注),避免单条把终端/DB 撑爆。 */
|
|
19
21
|
export const TOOL_RESULT_CAP = 4000;
|
|
20
22
|
/** 工具输入摘要上限(标题行那一段)。 */
|
|
@@ -174,9 +176,15 @@ function codexItemChunks(item, td) {
|
|
|
174
176
|
const output = item.aggregated_output?.trim();
|
|
175
177
|
if (output) {
|
|
176
178
|
const patch = parseUnifiedDiff(output);
|
|
179
|
+
const collapsed = patch ? null : buildCollapsedResult(command, output);
|
|
180
|
+
const json = patch || collapsed ? null : buildJsonResult(command, output);
|
|
177
181
|
out.push(patch
|
|
178
182
|
? { stream: "tool_result", text: `Changed ${patch.files.length} file(s): +${patch.additions} -${patch.deletions}`, payload: patch }
|
|
179
|
-
:
|
|
183
|
+
: collapsed
|
|
184
|
+
? { stream: "tool_result", text: collapsed.label, payload: collapsed }
|
|
185
|
+
: json
|
|
186
|
+
? { stream: "tool_result", text: json.label, payload: json }
|
|
187
|
+
: { stream: "tool_result", text: clip(output, TOOL_RESULT_CAP) });
|
|
180
188
|
}
|
|
181
189
|
return out;
|
|
182
190
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** 命令 JSON 输出识别与有界 pretty-print;供 AgentConsole 语法高亮,不引入重量级 highlighter。 */
|
|
2
|
+
const MAX_JSON_CHARS = 12_000;
|
|
3
|
+
const TASK_COMMAND = /\bcrew\s+task\s+(create|update|claim|assign|close)\b/i;
|
|
4
|
+
const MESSAGE_COMMAND = /\bcrew\s+message\s+(send|read)\b/i;
|
|
5
|
+
export function buildJsonResult(command, output) {
|
|
6
|
+
const trimmed = output.trim();
|
|
7
|
+
if (!trimmed || (trimmed[0] !== "{" && trimmed[0] !== "["))
|
|
8
|
+
return null;
|
|
9
|
+
try {
|
|
10
|
+
const value = JSON.parse(trimmed);
|
|
11
|
+
const pretty = JSON.stringify(value, null, 2);
|
|
12
|
+
const commandType = command.match(TASK_COMMAND)?.[1]?.toUpperCase().replace("CLOSE", "UPDATE")
|
|
13
|
+
?? command.match(MESSAGE_COMMAND)?.[1]?.toUpperCase()
|
|
14
|
+
?? "RESULT";
|
|
15
|
+
const entity = TASK_COMMAND.test(command) ? "TASK" : MESSAGE_COMMAND.test(command) ? "MESSAGE" : "JSON";
|
|
16
|
+
const label = `${entity} ${commandType}`;
|
|
17
|
+
return {
|
|
18
|
+
kind: "json_result",
|
|
19
|
+
label,
|
|
20
|
+
json: pretty.length > MAX_JSON_CHARS ? `${pretty.slice(0, MAX_JSON_CHARS)}\n…` : pretty,
|
|
21
|
+
truncated: pretty.length > MAX_JSON_CHARS,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const FRONTMATTER = /(?:^|\n)---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
|
|
2
|
+
export function buildSkillPreview(output) {
|
|
3
|
+
const frontmatter = output.match(FRONTMATTER)?.[1];
|
|
4
|
+
if (!frontmatter)
|
|
5
|
+
return null;
|
|
6
|
+
const name = scalar(frontmatter, "name");
|
|
7
|
+
const description = scalar(frontmatter, "description");
|
|
8
|
+
if (!name && !description)
|
|
9
|
+
return null;
|
|
10
|
+
return {
|
|
11
|
+
kind: "skill_preview",
|
|
12
|
+
name: name || "skill",
|
|
13
|
+
description,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function scalar(frontmatter, key) {
|
|
17
|
+
const match = frontmatter.match(new RegExp(`^${key}:\\s*(.+)$`, "m"));
|
|
18
|
+
if (!match)
|
|
19
|
+
return "";
|
|
20
|
+
return match[1].trim().replace(/^['"]|['"]$/g, "").slice(0, 500);
|
|
21
|
+
}
|