@ai-setting/roy-agent-cli 1.5.107 → 1.5.111

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.
@@ -7427,7 +7427,7 @@ var require_dist = __commonJS((exports) => {
7427
7427
  var require_package = __commonJS((exports, module) => {
7428
7428
  module.exports = {
7429
7429
  name: "@ai-setting/roy-agent-cli",
7430
- version: "1.5.107",
7430
+ version: "1.5.111",
7431
7431
  type: "module",
7432
7432
  description: "CLI for roy-agent - Non-interactive command execution",
7433
7433
  main: "./dist/index.js",
@@ -9354,12 +9354,21 @@ Task #${taskId}`;
9354
9354
  return `${minutes}分${seconds}秒`;
9355
9355
  }
9356
9356
  formatWithEvent(event) {
9357
+ const triggerSessionId = extractTriggerSessionId(event);
9357
9358
  return {
9358
9359
  message: this.format(event),
9359
- envEvent: event
9360
+ envEvent: event,
9361
+ triggerSessionId
9360
9362
  };
9361
9363
  }
9362
9364
  }
9365
+ function extractTriggerSessionId(event) {
9366
+ const triggerSessionId = event?.metadata?.trigger_session_id;
9367
+ if (typeof triggerSessionId === "string" && triggerSessionId.length > 0) {
9368
+ return triggerSessionId;
9369
+ }
9370
+ return;
9371
+ }
9363
9372
 
9364
9373
  // src/commands/shared/event-handler.ts
9365
9374
  import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
@@ -9483,6 +9492,25 @@ class EventHandler {
9483
9492
  return null;
9484
9493
  if (this.activeEventSessionId)
9485
9494
  return this.activeEventSessionId;
9495
+ const triggerSessionId = this.queue.map((item) => item.triggerSessionId).find((id) => !!id);
9496
+ if (triggerSessionId) {
9497
+ try {
9498
+ const existing = await this.sessionComponent.get(triggerSessionId);
9499
+ if (existing) {
9500
+ if (this.isStopped) {
9501
+ return null;
9502
+ }
9503
+ this.activeEventSessionId = existing.id;
9504
+ return existing.id;
9505
+ }
9506
+ console.warn(`[EventHandler] Parent session ${triggerSessionId} not found, creating new session`);
9507
+ } catch (error) {
9508
+ console.error(`[EventHandler] Failed to lookup parent session ${triggerSessionId}:`, error);
9509
+ }
9510
+ }
9511
+ return this.createNewEventSession();
9512
+ }
9513
+ async createNewEventSession() {
9486
9514
  try {
9487
9515
  const session = await this.sessionComponent.create({
9488
9516
  title: `Event Session - ${new Date().toLocaleString()}`
@@ -11316,6 +11344,152 @@ var DeleteCommand = {
11316
11344
 
11317
11345
  // src/commands/sessions/messages.ts
11318
11346
  import chalk11 from "chalk";
11347
+
11348
+ // src/commands/sessions/format-message-content.ts
11349
+ var TEXT_MAX_CHARS = 300;
11350
+ var TOOL_ARGS_MAX_CHARS = 200;
11351
+ var TOOL_RESULT_MAX_CHARS = 200;
11352
+ var LEGACY_CONTENT_MAX_CHARS = 200;
11353
+ var REASONING_MAX_LINES = 5;
11354
+ var CHECKPOINT_MAX_LINES = 10;
11355
+ var INPUT_VALUE_MAX_CHARS = 50;
11356
+ var WORKFLOW_RESULT_MAX_CHARS = 200;
11357
+ var WORKFLOW_RESULT_MAX_LINES = 5;
11358
+ var WORKFLOW_END_MAX_CHARS = 300;
11359
+ var WORKFLOW_END_MAX_LINES = 6;
11360
+ var ELLIPSIS = "...";
11361
+ function truncateChars(s, max) {
11362
+ if (s.length > max) {
11363
+ return s.slice(0, max - ELLIPSIS.length) + ELLIPSIS;
11364
+ }
11365
+ return s;
11366
+ }
11367
+ function formatCheckpointContent(content, opts = {}) {
11368
+ const detail = opts.detail ?? false;
11369
+ const lines = content.split(`
11370
+ `);
11371
+ if (detail) {
11372
+ return lines.join(`
11373
+ `);
11374
+ }
11375
+ return lines.slice(0, CHECKPOINT_MAX_LINES).join(`
11376
+ `) + (lines.length > CHECKPOINT_MAX_LINES ? `
11377
+ ` + ELLIPSIS : "");
11378
+ }
11379
+ function formatMessageContent(m, opts = {}) {
11380
+ const detail = opts.detail ?? false;
11381
+ const lines = [];
11382
+ if (m.parts && m.parts.length > 0) {
11383
+ for (const part of m.parts) {
11384
+ if (part.type === "text") {
11385
+ const raw = part.content || "";
11386
+ const text = detail ? raw : truncateChars(raw, TEXT_MAX_CHARS);
11387
+ lines.push(...text.split(`
11388
+ `).map((l) => l || " "));
11389
+ } else if (part.type === "tool-call") {
11390
+ lines.push(`[Tool Call] ${part.toolName}`);
11391
+ const argsStr = typeof part.arguments === "string" ? part.arguments : JSON.stringify(part.arguments ?? null, null, 2);
11392
+ if (argsStr) {
11393
+ const final = detail ? argsStr : truncateChars(argsStr, TOOL_ARGS_MAX_CHARS);
11394
+ lines.push(...final.split(`
11395
+ `));
11396
+ }
11397
+ } else if (part.type === "tool-result") {
11398
+ lines.push(`[Tool Result] ${part.toolName}`);
11399
+ const raw = part.output || "No output";
11400
+ const output = detail ? raw : truncateChars(raw, TOOL_RESULT_MAX_CHARS);
11401
+ lines.push(...output.split(`
11402
+ `));
11403
+ } else if (part.type === "reasoning") {
11404
+ lines.push(`[Reasoning]`);
11405
+ const content = part.content || "";
11406
+ if (detail) {
11407
+ lines.push(...content.split(`
11408
+ `));
11409
+ } else {
11410
+ lines.push(...content.split(`
11411
+ `).slice(0, REASONING_MAX_LINES));
11412
+ }
11413
+ } else if (part.type === "checkpoint") {
11414
+ lines.push(`[Checkpoint]`);
11415
+ } else if (part.type === "workflow-node-call") {
11416
+ lines.push(`[Node Call] ${part.nodeType}: ${part.nodeId}`);
11417
+ if (part.input && Object.keys(part.input).length > 0) {
11418
+ const entries = Object.entries(part.input).slice(0, 3);
11419
+ const inputSummary = entries.map(([k, v]) => {
11420
+ const vStr = JSON.stringify(v);
11421
+ const final = detail ? vStr : vStr.slice(0, INPUT_VALUE_MAX_CHARS);
11422
+ return `${k}: ${final}`;
11423
+ }).join(", ");
11424
+ lines.push(...inputSummary.split(`
11425
+ `).map((l) => ` ${l}`));
11426
+ }
11427
+ if (part.agentSessionId) {
11428
+ lines.push(` agentSessionId: ${part.agentSessionId}`);
11429
+ }
11430
+ } else if (part.type === "workflow-node-interrupt") {
11431
+ lines.push(`[Node Interrupt] ${part.nodeType}: ${part.nodeId}`);
11432
+ lines.push(` Query: ${part.query}`);
11433
+ if (part.options && part.options.length > 0) {
11434
+ lines.push(` Options: ${part.options.join(", ")}`);
11435
+ }
11436
+ if (part.agentSessionId) {
11437
+ lines.push(` agentSessionId: ${part.agentSessionId}`);
11438
+ }
11439
+ } else if (part.type === "workflow-node-result") {
11440
+ const status = part.error ? "❌" : "✅";
11441
+ lines.push(`${status} [Node Result] ${part.nodeType}: ${part.nodeId}`);
11442
+ if (part.output) {
11443
+ let outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output);
11444
+ if (!detail) {
11445
+ outputStr = outputStr.slice(0, WORKFLOW_RESULT_MAX_CHARS);
11446
+ }
11447
+ const outputLines = outputStr.split(`
11448
+ `);
11449
+ const slicedLines = detail ? outputLines : outputLines.slice(0, WORKFLOW_RESULT_MAX_LINES);
11450
+ lines.push(...slicedLines.map((l) => ` ${l}`));
11451
+ }
11452
+ if (part.error) {
11453
+ lines.push(` Error: ${part.error}`);
11454
+ }
11455
+ if (part.durationMs !== undefined) {
11456
+ lines.push(` Duration: ${part.durationMs}ms`);
11457
+ }
11458
+ } else if (part.type === "workflow-node-resume") {
11459
+ lines.push(`[Node Resume] Response: ${part.response}`);
11460
+ } else if (part.type === "workflow-node-start") {
11461
+ lines.push(`[Node Start] ${part.nodeId}`);
11462
+ } else if (part.type === "workflow-node-end") {
11463
+ const status = part.error ? "❌" : "✅";
11464
+ lines.push(`${status} [Node End] ${part.nodeId}`);
11465
+ if (part.output) {
11466
+ let outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output, null, 2);
11467
+ if (!detail) {
11468
+ outputStr = outputStr.slice(0, WORKFLOW_END_MAX_CHARS);
11469
+ }
11470
+ const outputLines = outputStr.split(`
11471
+ `);
11472
+ const slicedLines = detail ? outputLines : outputLines.slice(0, WORKFLOW_END_MAX_LINES);
11473
+ lines.push(...slicedLines.map((l) => ` ${l}`));
11474
+ }
11475
+ if (part.error) {
11476
+ lines.push(` Error: ${part.error}`);
11477
+ }
11478
+ if (part.durationMs !== undefined) {
11479
+ lines.push(` Duration: ${part.durationMs}ms`);
11480
+ }
11481
+ }
11482
+ }
11483
+ } else if (m.content) {
11484
+ const content = detail ? m.content : truncateChars(m.content, LEGACY_CONTENT_MAX_CHARS);
11485
+ lines.push(...content.split(`
11486
+ `).map((l) => l || " "));
11487
+ }
11488
+ return lines.length > 0 ? lines : ["(empty)"];
11489
+ }
11490
+
11491
+ // src/commands/sessions/messages.ts
11492
+ var MAX_CONTENT_LINES = 20;
11319
11493
  var MessagesCommand = {
11320
11494
  command: "messages <session-id>",
11321
11495
  aliases: ["msgs"],
@@ -11324,7 +11498,11 @@ var MessagesCommand = {
11324
11498
  describe: "会话 ID",
11325
11499
  type: "string",
11326
11500
  demandOption: true
11327
- }).option("limit", { alias: "n", type: "number", demandOption: true, describe: "返回消息数量" }).option("offset", { alias: "o", type: "number", demandOption: true, describe: "起始偏移量" }).option("reverse", { alias: "r", type: "boolean", default: false }).option("json", { alias: "j", type: "boolean", default: false }),
11501
+ }).option("limit", { alias: "n", type: "number", demandOption: true, describe: "返回消息数量" }).option("offset", { alias: "o", type: "number", demandOption: true, describe: "起始偏移量" }).option("reverse", { alias: "r", type: "boolean", default: false }).option("json", { alias: "j", type: "boolean", default: false }).option("detail", {
11502
+ type: "boolean",
11503
+ default: false,
11504
+ describe: "显示完整消息内容(不截断)"
11505
+ }),
11328
11506
  async handler(args) {
11329
11507
  const a = args;
11330
11508
  const output = new OutputService2;
@@ -11375,111 +11553,13 @@ var MessagesCommand = {
11375
11553
  }))
11376
11554
  });
11377
11555
  } else {
11378
- const checkpointStyle = (content) => {
11379
- const lines = content.split(`
11380
- `);
11381
- return lines.slice(0, 10).join(`
11382
- `) + (lines.length > 10 ? `
11383
- ...` : "");
11384
- };
11556
+ const detail = a.detail === true;
11385
11557
  const roleColors = {
11386
11558
  user: chalk11.blue,
11387
11559
  assistant: chalk11.green,
11388
11560
  system: chalk11.gray,
11389
11561
  tool: chalk11.yellow
11390
11562
  };
11391
- const formatMessageContent = (m) => {
11392
- const lines = [];
11393
- if (m.parts && m.parts.length > 0) {
11394
- for (const part of m.parts) {
11395
- if (part.type === "text") {
11396
- const text = part.content?.length > 300 ? part.content.slice(0, 297) + "..." : part.content || "";
11397
- lines.push(...text.split(`
11398
- `).map((l) => l || " "));
11399
- } else if (part.type === "tool-call") {
11400
- lines.push(chalk11.cyan(`[Tool Call] ${part.toolName}`));
11401
- const argsStr = typeof part.arguments === "string" ? part.arguments : JSON.stringify(part.arguments ?? null, null, 2);
11402
- if (argsStr && argsStr.length > 200) {
11403
- lines.push(...argsStr.slice(0, 197).split(`
11404
- `).map((l) => chalk11.gray(l)));
11405
- lines.push(chalk11.gray("..."));
11406
- } else if (argsStr) {
11407
- lines.push(...argsStr.split(`
11408
- `).map((l) => chalk11.gray(l)));
11409
- }
11410
- } else if (part.type === "tool-result") {
11411
- lines.push(chalk11.yellow(`[Tool Result] ${part.toolName}`));
11412
- const output2 = part.output?.length > 200 ? part.output.slice(0, 197) + "..." : part.output || "No output";
11413
- lines.push(...output2.split(`
11414
- `).map((l) => chalk11.gray(l)));
11415
- } else if (part.type === "reasoning") {
11416
- lines.push(chalk11.magenta(`[Reasoning]`));
11417
- lines.push(...(part.content || "").split(`
11418
- `).slice(0, 5).map((l) => chalk11.gray(l)));
11419
- } else if (part.type === "checkpoint") {
11420
- lines.push(chalk11.cyan(`[Checkpoint]`));
11421
- } else if (part.type === "workflow-node-call") {
11422
- lines.push(chalk11.blue(`[Node Call] ${part.nodeType}: ${part.nodeId}`));
11423
- if (part.input && Object.keys(part.input).length > 0) {
11424
- const inputSummary = Object.entries(part.input).slice(0, 3).map(([k, v]) => `${k}: ${JSON.stringify(v).slice(0, 50)}`).join(", ");
11425
- lines.push(...inputSummary.split(`
11426
- `).map((l) => chalk11.gray(` ${l}`)));
11427
- }
11428
- if (part.agentSessionId) {
11429
- lines.push(chalk11.gray(` agentSessionId: ${part.agentSessionId}`));
11430
- }
11431
- } else if (part.type === "workflow-node-interrupt") {
11432
- lines.push(chalk11.yellow(`[Node Interrupt] ${part.nodeType}: ${part.nodeId}`));
11433
- lines.push(chalk11.bold(` Query: ${part.query}`));
11434
- if (part.options && part.options.length > 0) {
11435
- lines.push(chalk11.gray(` Options: ${part.options.join(", ")}`));
11436
- }
11437
- if (part.agentSessionId) {
11438
- lines.push(chalk11.gray(` agentSessionId: ${part.agentSessionId}`));
11439
- }
11440
- } else if (part.type === "workflow-node-result") {
11441
- const status = part.error ? "❌" : "✅";
11442
- lines.push(chalk11.green(`${status} [Node Result] ${part.nodeType}: ${part.nodeId}`));
11443
- if (part.output) {
11444
- const outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output).slice(0, 200);
11445
- lines.push(...outputStr.split(`
11446
- `).slice(0, 5).map((l) => chalk11.gray(` ${l}`)));
11447
- }
11448
- if (part.error) {
11449
- lines.push(chalk11.red(` Error: ${part.error}`));
11450
- }
11451
- if (part.durationMs !== undefined) {
11452
- lines.push(chalk11.gray(` Duration: ${part.durationMs}ms`));
11453
- }
11454
- } else if (part.type === "workflow-node-resume") {
11455
- lines.push(chalk11.green(`[Node Resume] Response: ${part.response}`));
11456
- } else if (part.type === "workflow-node-start") {
11457
- lines.push(chalk11.blue(`[Node Start] ${part.nodeId}`));
11458
- } else if (part.type === "workflow-node-end") {
11459
- const status = part.error ? "❌" : "✅";
11460
- lines.push(chalk11.green(`${status} [Node End] ${part.nodeId}`));
11461
- if (part.output) {
11462
- const outputStr = typeof part.output === "string" ? part.output.slice(0, 300) : JSON.stringify(part.output, null, 2).slice(0, 300);
11463
- lines.push(...outputStr.split(`
11464
- `).slice(0, 6).map((l) => chalk11.gray(` ${l}`)));
11465
- if (outputStr.length >= 300)
11466
- lines.push(chalk11.gray(" ..."));
11467
- }
11468
- if (part.error) {
11469
- lines.push(chalk11.red(` Error: ${part.error}`));
11470
- }
11471
- if (part.durationMs !== undefined) {
11472
- lines.push(chalk11.gray(` Duration: ${part.durationMs}ms`));
11473
- }
11474
- }
11475
- }
11476
- } else if (m.content) {
11477
- const content = m.content.length > 200 ? m.content.slice(0, 197) + "..." : m.content;
11478
- lines.push(...content.split(`
11479
- `).map((l) => l || " "));
11480
- }
11481
- return lines.length > 0 ? lines : ["(empty)"];
11482
- };
11483
11563
  output.log(chalk11.bold(`┌─ Messages (${a.sessionId}) ────────────────────────┐`));
11484
11564
  messages.forEach((m, i) => {
11485
11565
  const roleColor = roleColors[m.role] || chalk11.white;
@@ -11490,18 +11570,21 @@ var MessagesCommand = {
11490
11570
  if (m.metadata?.isCheckpoint) {
11491
11571
  output.log(chalk11.cyan("├─ #" + (a.offset + i + 1) + " checkpoint") + " " + chalk11.gray(time));
11492
11572
  output.log("│");
11493
- output.log("│ " + checkpointStyle(m.content).split(`
11573
+ const checkpointContent = formatCheckpointContent(m.content, { detail });
11574
+ output.log("│ " + checkpointContent.split(`
11494
11575
  `).join(`
11495
11576
  │ `));
11496
11577
  output.log("│");
11497
11578
  } else {
11498
11579
  output.log(chalk11.cyan("├─ #" + (a.offset + i + 1) + " ") + roleColor(m.role.padEnd(10)) + " " + chalk11.gray(time));
11499
- const contentLines = formatMessageContent(m);
11500
- for (const line of contentLines.slice(0, 20)) {
11580
+ const rawLines = formatMessageContent(m, { detail });
11581
+ const contentLines = colorizeContentLines(rawLines, m);
11582
+ const finalLines = detail ? contentLines : contentLines.slice(0, MAX_CONTENT_LINES);
11583
+ for (const line of finalLines) {
11501
11584
  output.log("│ " + line);
11502
11585
  }
11503
- if (contentLines.length > 20) {
11504
- output.log("│ " + chalk11.gray("... (truncated)"));
11586
+ if (!detail && contentLines.length > MAX_CONTENT_LINES) {
11587
+ output.log("│ " + chalk11.gray(`... (truncated, total ${contentLines.length} lines)`));
11505
11588
  }
11506
11589
  output.log("│");
11507
11590
  }
@@ -11519,6 +11602,43 @@ var MessagesCommand = {
11519
11602
  }
11520
11603
  }
11521
11604
  };
11605
+ function colorizeContentLines(lines, _m) {
11606
+ return lines.map((line) => {
11607
+ if (line.startsWith("[Tool Call]"))
11608
+ return chalk11.cyan(line);
11609
+ if (line.startsWith("[Tool Result]"))
11610
+ return chalk11.yellow(line);
11611
+ if (line === "[Reasoning]")
11612
+ return chalk11.magenta(line);
11613
+ if (line === "[Checkpoint]")
11614
+ return chalk11.cyan(line);
11615
+ if (line.startsWith("[Node Call]"))
11616
+ return chalk11.blue(line);
11617
+ if (line.startsWith("[Node Interrupt]"))
11618
+ return chalk11.yellow(line);
11619
+ if (line.startsWith("[Node Resume]"))
11620
+ return chalk11.green(line);
11621
+ if (line.startsWith("[Node Start]"))
11622
+ return chalk11.blue(line);
11623
+ if (line.startsWith("✅") || line.startsWith("❌")) {
11624
+ if (line.includes("[Node Result]"))
11625
+ return chalk11.green(line);
11626
+ if (line.includes("[Node End]"))
11627
+ return chalk11.green(line);
11628
+ return line;
11629
+ }
11630
+ if (line.startsWith(" ")) {
11631
+ if (line.startsWith(" Error:"))
11632
+ return chalk11.red(line);
11633
+ if (line.startsWith(" Query:"))
11634
+ return chalk11.bold(line);
11635
+ if (line.startsWith(" Options:") || line.startsWith(" agentSessionId:") || line.startsWith(" Duration:"))
11636
+ return chalk11.gray(line);
11637
+ return chalk11.gray(line);
11638
+ }
11639
+ return line;
11640
+ });
11641
+ }
11522
11642
 
11523
11643
  // src/commands/sessions/compact.ts
11524
11644
  import chalk12 from "chalk";
package/dist/index.js CHANGED
@@ -7426,7 +7426,7 @@ var require_dist = __commonJS((exports) => {
7426
7426
  var require_package = __commonJS((exports, module) => {
7427
7427
  module.exports = {
7428
7428
  name: "@ai-setting/roy-agent-cli",
7429
- version: "1.5.107",
7429
+ version: "1.5.111",
7430
7430
  type: "module",
7431
7431
  description: "CLI for roy-agent - Non-interactive command execution",
7432
7432
  main: "./dist/index.js",
@@ -9353,12 +9353,21 @@ Task #${taskId}`;
9353
9353
  return `${minutes}分${seconds}秒`;
9354
9354
  }
9355
9355
  formatWithEvent(event) {
9356
+ const triggerSessionId = extractTriggerSessionId(event);
9356
9357
  return {
9357
9358
  message: this.format(event),
9358
- envEvent: event
9359
+ envEvent: event,
9360
+ triggerSessionId
9359
9361
  };
9360
9362
  }
9361
9363
  }
9364
+ function extractTriggerSessionId(event) {
9365
+ const triggerSessionId = event?.metadata?.trigger_session_id;
9366
+ if (typeof triggerSessionId === "string" && triggerSessionId.length > 0) {
9367
+ return triggerSessionId;
9368
+ }
9369
+ return;
9370
+ }
9362
9371
 
9363
9372
  // src/commands/shared/event-handler.ts
9364
9373
  import { TracedAs as TracedAs3 } from "@ai-setting/roy-agent-core";
@@ -9482,6 +9491,25 @@ class EventHandler {
9482
9491
  return null;
9483
9492
  if (this.activeEventSessionId)
9484
9493
  return this.activeEventSessionId;
9494
+ const triggerSessionId = this.queue.map((item) => item.triggerSessionId).find((id) => !!id);
9495
+ if (triggerSessionId) {
9496
+ try {
9497
+ const existing = await this.sessionComponent.get(triggerSessionId);
9498
+ if (existing) {
9499
+ if (this.isStopped) {
9500
+ return null;
9501
+ }
9502
+ this.activeEventSessionId = existing.id;
9503
+ return existing.id;
9504
+ }
9505
+ console.warn(`[EventHandler] Parent session ${triggerSessionId} not found, creating new session`);
9506
+ } catch (error) {
9507
+ console.error(`[EventHandler] Failed to lookup parent session ${triggerSessionId}:`, error);
9508
+ }
9509
+ }
9510
+ return this.createNewEventSession();
9511
+ }
9512
+ async createNewEventSession() {
9485
9513
  try {
9486
9514
  const session = await this.sessionComponent.create({
9487
9515
  title: `Event Session - ${new Date().toLocaleString()}`
@@ -11315,6 +11343,152 @@ var DeleteCommand = {
11315
11343
 
11316
11344
  // src/commands/sessions/messages.ts
11317
11345
  import chalk11 from "chalk";
11346
+
11347
+ // src/commands/sessions/format-message-content.ts
11348
+ var TEXT_MAX_CHARS = 300;
11349
+ var TOOL_ARGS_MAX_CHARS = 200;
11350
+ var TOOL_RESULT_MAX_CHARS = 200;
11351
+ var LEGACY_CONTENT_MAX_CHARS = 200;
11352
+ var REASONING_MAX_LINES = 5;
11353
+ var CHECKPOINT_MAX_LINES = 10;
11354
+ var INPUT_VALUE_MAX_CHARS = 50;
11355
+ var WORKFLOW_RESULT_MAX_CHARS = 200;
11356
+ var WORKFLOW_RESULT_MAX_LINES = 5;
11357
+ var WORKFLOW_END_MAX_CHARS = 300;
11358
+ var WORKFLOW_END_MAX_LINES = 6;
11359
+ var ELLIPSIS = "...";
11360
+ function truncateChars(s, max) {
11361
+ if (s.length > max) {
11362
+ return s.slice(0, max - ELLIPSIS.length) + ELLIPSIS;
11363
+ }
11364
+ return s;
11365
+ }
11366
+ function formatCheckpointContent(content, opts = {}) {
11367
+ const detail = opts.detail ?? false;
11368
+ const lines = content.split(`
11369
+ `);
11370
+ if (detail) {
11371
+ return lines.join(`
11372
+ `);
11373
+ }
11374
+ return lines.slice(0, CHECKPOINT_MAX_LINES).join(`
11375
+ `) + (lines.length > CHECKPOINT_MAX_LINES ? `
11376
+ ` + ELLIPSIS : "");
11377
+ }
11378
+ function formatMessageContent(m, opts = {}) {
11379
+ const detail = opts.detail ?? false;
11380
+ const lines = [];
11381
+ if (m.parts && m.parts.length > 0) {
11382
+ for (const part of m.parts) {
11383
+ if (part.type === "text") {
11384
+ const raw = part.content || "";
11385
+ const text = detail ? raw : truncateChars(raw, TEXT_MAX_CHARS);
11386
+ lines.push(...text.split(`
11387
+ `).map((l) => l || " "));
11388
+ } else if (part.type === "tool-call") {
11389
+ lines.push(`[Tool Call] ${part.toolName}`);
11390
+ const argsStr = typeof part.arguments === "string" ? part.arguments : JSON.stringify(part.arguments ?? null, null, 2);
11391
+ if (argsStr) {
11392
+ const final = detail ? argsStr : truncateChars(argsStr, TOOL_ARGS_MAX_CHARS);
11393
+ lines.push(...final.split(`
11394
+ `));
11395
+ }
11396
+ } else if (part.type === "tool-result") {
11397
+ lines.push(`[Tool Result] ${part.toolName}`);
11398
+ const raw = part.output || "No output";
11399
+ const output = detail ? raw : truncateChars(raw, TOOL_RESULT_MAX_CHARS);
11400
+ lines.push(...output.split(`
11401
+ `));
11402
+ } else if (part.type === "reasoning") {
11403
+ lines.push(`[Reasoning]`);
11404
+ const content = part.content || "";
11405
+ if (detail) {
11406
+ lines.push(...content.split(`
11407
+ `));
11408
+ } else {
11409
+ lines.push(...content.split(`
11410
+ `).slice(0, REASONING_MAX_LINES));
11411
+ }
11412
+ } else if (part.type === "checkpoint") {
11413
+ lines.push(`[Checkpoint]`);
11414
+ } else if (part.type === "workflow-node-call") {
11415
+ lines.push(`[Node Call] ${part.nodeType}: ${part.nodeId}`);
11416
+ if (part.input && Object.keys(part.input).length > 0) {
11417
+ const entries = Object.entries(part.input).slice(0, 3);
11418
+ const inputSummary = entries.map(([k, v]) => {
11419
+ const vStr = JSON.stringify(v);
11420
+ const final = detail ? vStr : vStr.slice(0, INPUT_VALUE_MAX_CHARS);
11421
+ return `${k}: ${final}`;
11422
+ }).join(", ");
11423
+ lines.push(...inputSummary.split(`
11424
+ `).map((l) => ` ${l}`));
11425
+ }
11426
+ if (part.agentSessionId) {
11427
+ lines.push(` agentSessionId: ${part.agentSessionId}`);
11428
+ }
11429
+ } else if (part.type === "workflow-node-interrupt") {
11430
+ lines.push(`[Node Interrupt] ${part.nodeType}: ${part.nodeId}`);
11431
+ lines.push(` Query: ${part.query}`);
11432
+ if (part.options && part.options.length > 0) {
11433
+ lines.push(` Options: ${part.options.join(", ")}`);
11434
+ }
11435
+ if (part.agentSessionId) {
11436
+ lines.push(` agentSessionId: ${part.agentSessionId}`);
11437
+ }
11438
+ } else if (part.type === "workflow-node-result") {
11439
+ const status = part.error ? "❌" : "✅";
11440
+ lines.push(`${status} [Node Result] ${part.nodeType}: ${part.nodeId}`);
11441
+ if (part.output) {
11442
+ let outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output);
11443
+ if (!detail) {
11444
+ outputStr = outputStr.slice(0, WORKFLOW_RESULT_MAX_CHARS);
11445
+ }
11446
+ const outputLines = outputStr.split(`
11447
+ `);
11448
+ const slicedLines = detail ? outputLines : outputLines.slice(0, WORKFLOW_RESULT_MAX_LINES);
11449
+ lines.push(...slicedLines.map((l) => ` ${l}`));
11450
+ }
11451
+ if (part.error) {
11452
+ lines.push(` Error: ${part.error}`);
11453
+ }
11454
+ if (part.durationMs !== undefined) {
11455
+ lines.push(` Duration: ${part.durationMs}ms`);
11456
+ }
11457
+ } else if (part.type === "workflow-node-resume") {
11458
+ lines.push(`[Node Resume] Response: ${part.response}`);
11459
+ } else if (part.type === "workflow-node-start") {
11460
+ lines.push(`[Node Start] ${part.nodeId}`);
11461
+ } else if (part.type === "workflow-node-end") {
11462
+ const status = part.error ? "❌" : "✅";
11463
+ lines.push(`${status} [Node End] ${part.nodeId}`);
11464
+ if (part.output) {
11465
+ let outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output, null, 2);
11466
+ if (!detail) {
11467
+ outputStr = outputStr.slice(0, WORKFLOW_END_MAX_CHARS);
11468
+ }
11469
+ const outputLines = outputStr.split(`
11470
+ `);
11471
+ const slicedLines = detail ? outputLines : outputLines.slice(0, WORKFLOW_END_MAX_LINES);
11472
+ lines.push(...slicedLines.map((l) => ` ${l}`));
11473
+ }
11474
+ if (part.error) {
11475
+ lines.push(` Error: ${part.error}`);
11476
+ }
11477
+ if (part.durationMs !== undefined) {
11478
+ lines.push(` Duration: ${part.durationMs}ms`);
11479
+ }
11480
+ }
11481
+ }
11482
+ } else if (m.content) {
11483
+ const content = detail ? m.content : truncateChars(m.content, LEGACY_CONTENT_MAX_CHARS);
11484
+ lines.push(...content.split(`
11485
+ `).map((l) => l || " "));
11486
+ }
11487
+ return lines.length > 0 ? lines : ["(empty)"];
11488
+ }
11489
+
11490
+ // src/commands/sessions/messages.ts
11491
+ var MAX_CONTENT_LINES = 20;
11318
11492
  var MessagesCommand = {
11319
11493
  command: "messages <session-id>",
11320
11494
  aliases: ["msgs"],
@@ -11323,7 +11497,11 @@ var MessagesCommand = {
11323
11497
  describe: "会话 ID",
11324
11498
  type: "string",
11325
11499
  demandOption: true
11326
- }).option("limit", { alias: "n", type: "number", demandOption: true, describe: "返回消息数量" }).option("offset", { alias: "o", type: "number", demandOption: true, describe: "起始偏移量" }).option("reverse", { alias: "r", type: "boolean", default: false }).option("json", { alias: "j", type: "boolean", default: false }),
11500
+ }).option("limit", { alias: "n", type: "number", demandOption: true, describe: "返回消息数量" }).option("offset", { alias: "o", type: "number", demandOption: true, describe: "起始偏移量" }).option("reverse", { alias: "r", type: "boolean", default: false }).option("json", { alias: "j", type: "boolean", default: false }).option("detail", {
11501
+ type: "boolean",
11502
+ default: false,
11503
+ describe: "显示完整消息内容(不截断)"
11504
+ }),
11327
11505
  async handler(args) {
11328
11506
  const a = args;
11329
11507
  const output = new OutputService2;
@@ -11374,111 +11552,13 @@ var MessagesCommand = {
11374
11552
  }))
11375
11553
  });
11376
11554
  } else {
11377
- const checkpointStyle = (content) => {
11378
- const lines = content.split(`
11379
- `);
11380
- return lines.slice(0, 10).join(`
11381
- `) + (lines.length > 10 ? `
11382
- ...` : "");
11383
- };
11555
+ const detail = a.detail === true;
11384
11556
  const roleColors = {
11385
11557
  user: chalk11.blue,
11386
11558
  assistant: chalk11.green,
11387
11559
  system: chalk11.gray,
11388
11560
  tool: chalk11.yellow
11389
11561
  };
11390
- const formatMessageContent = (m) => {
11391
- const lines = [];
11392
- if (m.parts && m.parts.length > 0) {
11393
- for (const part of m.parts) {
11394
- if (part.type === "text") {
11395
- const text = part.content?.length > 300 ? part.content.slice(0, 297) + "..." : part.content || "";
11396
- lines.push(...text.split(`
11397
- `).map((l) => l || " "));
11398
- } else if (part.type === "tool-call") {
11399
- lines.push(chalk11.cyan(`[Tool Call] ${part.toolName}`));
11400
- const argsStr = typeof part.arguments === "string" ? part.arguments : JSON.stringify(part.arguments ?? null, null, 2);
11401
- if (argsStr && argsStr.length > 200) {
11402
- lines.push(...argsStr.slice(0, 197).split(`
11403
- `).map((l) => chalk11.gray(l)));
11404
- lines.push(chalk11.gray("..."));
11405
- } else if (argsStr) {
11406
- lines.push(...argsStr.split(`
11407
- `).map((l) => chalk11.gray(l)));
11408
- }
11409
- } else if (part.type === "tool-result") {
11410
- lines.push(chalk11.yellow(`[Tool Result] ${part.toolName}`));
11411
- const output2 = part.output?.length > 200 ? part.output.slice(0, 197) + "..." : part.output || "No output";
11412
- lines.push(...output2.split(`
11413
- `).map((l) => chalk11.gray(l)));
11414
- } else if (part.type === "reasoning") {
11415
- lines.push(chalk11.magenta(`[Reasoning]`));
11416
- lines.push(...(part.content || "").split(`
11417
- `).slice(0, 5).map((l) => chalk11.gray(l)));
11418
- } else if (part.type === "checkpoint") {
11419
- lines.push(chalk11.cyan(`[Checkpoint]`));
11420
- } else if (part.type === "workflow-node-call") {
11421
- lines.push(chalk11.blue(`[Node Call] ${part.nodeType}: ${part.nodeId}`));
11422
- if (part.input && Object.keys(part.input).length > 0) {
11423
- const inputSummary = Object.entries(part.input).slice(0, 3).map(([k, v]) => `${k}: ${JSON.stringify(v).slice(0, 50)}`).join(", ");
11424
- lines.push(...inputSummary.split(`
11425
- `).map((l) => chalk11.gray(` ${l}`)));
11426
- }
11427
- if (part.agentSessionId) {
11428
- lines.push(chalk11.gray(` agentSessionId: ${part.agentSessionId}`));
11429
- }
11430
- } else if (part.type === "workflow-node-interrupt") {
11431
- lines.push(chalk11.yellow(`[Node Interrupt] ${part.nodeType}: ${part.nodeId}`));
11432
- lines.push(chalk11.bold(` Query: ${part.query}`));
11433
- if (part.options && part.options.length > 0) {
11434
- lines.push(chalk11.gray(` Options: ${part.options.join(", ")}`));
11435
- }
11436
- if (part.agentSessionId) {
11437
- lines.push(chalk11.gray(` agentSessionId: ${part.agentSessionId}`));
11438
- }
11439
- } else if (part.type === "workflow-node-result") {
11440
- const status = part.error ? "❌" : "✅";
11441
- lines.push(chalk11.green(`${status} [Node Result] ${part.nodeType}: ${part.nodeId}`));
11442
- if (part.output) {
11443
- const outputStr = typeof part.output === "string" ? part.output : JSON.stringify(part.output).slice(0, 200);
11444
- lines.push(...outputStr.split(`
11445
- `).slice(0, 5).map((l) => chalk11.gray(` ${l}`)));
11446
- }
11447
- if (part.error) {
11448
- lines.push(chalk11.red(` Error: ${part.error}`));
11449
- }
11450
- if (part.durationMs !== undefined) {
11451
- lines.push(chalk11.gray(` Duration: ${part.durationMs}ms`));
11452
- }
11453
- } else if (part.type === "workflow-node-resume") {
11454
- lines.push(chalk11.green(`[Node Resume] Response: ${part.response}`));
11455
- } else if (part.type === "workflow-node-start") {
11456
- lines.push(chalk11.blue(`[Node Start] ${part.nodeId}`));
11457
- } else if (part.type === "workflow-node-end") {
11458
- const status = part.error ? "❌" : "✅";
11459
- lines.push(chalk11.green(`${status} [Node End] ${part.nodeId}`));
11460
- if (part.output) {
11461
- const outputStr = typeof part.output === "string" ? part.output.slice(0, 300) : JSON.stringify(part.output, null, 2).slice(0, 300);
11462
- lines.push(...outputStr.split(`
11463
- `).slice(0, 6).map((l) => chalk11.gray(` ${l}`)));
11464
- if (outputStr.length >= 300)
11465
- lines.push(chalk11.gray(" ..."));
11466
- }
11467
- if (part.error) {
11468
- lines.push(chalk11.red(` Error: ${part.error}`));
11469
- }
11470
- if (part.durationMs !== undefined) {
11471
- lines.push(chalk11.gray(` Duration: ${part.durationMs}ms`));
11472
- }
11473
- }
11474
- }
11475
- } else if (m.content) {
11476
- const content = m.content.length > 200 ? m.content.slice(0, 197) + "..." : m.content;
11477
- lines.push(...content.split(`
11478
- `).map((l) => l || " "));
11479
- }
11480
- return lines.length > 0 ? lines : ["(empty)"];
11481
- };
11482
11562
  output.log(chalk11.bold(`┌─ Messages (${a.sessionId}) ────────────────────────┐`));
11483
11563
  messages.forEach((m, i) => {
11484
11564
  const roleColor = roleColors[m.role] || chalk11.white;
@@ -11489,18 +11569,21 @@ var MessagesCommand = {
11489
11569
  if (m.metadata?.isCheckpoint) {
11490
11570
  output.log(chalk11.cyan("├─ #" + (a.offset + i + 1) + " checkpoint") + " " + chalk11.gray(time));
11491
11571
  output.log("│");
11492
- output.log("│ " + checkpointStyle(m.content).split(`
11572
+ const checkpointContent = formatCheckpointContent(m.content, { detail });
11573
+ output.log("│ " + checkpointContent.split(`
11493
11574
  `).join(`
11494
11575
  │ `));
11495
11576
  output.log("│");
11496
11577
  } else {
11497
11578
  output.log(chalk11.cyan("├─ #" + (a.offset + i + 1) + " ") + roleColor(m.role.padEnd(10)) + " " + chalk11.gray(time));
11498
- const contentLines = formatMessageContent(m);
11499
- for (const line of contentLines.slice(0, 20)) {
11579
+ const rawLines = formatMessageContent(m, { detail });
11580
+ const contentLines = colorizeContentLines(rawLines, m);
11581
+ const finalLines = detail ? contentLines : contentLines.slice(0, MAX_CONTENT_LINES);
11582
+ for (const line of finalLines) {
11500
11583
  output.log("│ " + line);
11501
11584
  }
11502
- if (contentLines.length > 20) {
11503
- output.log("│ " + chalk11.gray("... (truncated)"));
11585
+ if (!detail && contentLines.length > MAX_CONTENT_LINES) {
11586
+ output.log("│ " + chalk11.gray(`... (truncated, total ${contentLines.length} lines)`));
11504
11587
  }
11505
11588
  output.log("│");
11506
11589
  }
@@ -11518,6 +11601,43 @@ var MessagesCommand = {
11518
11601
  }
11519
11602
  }
11520
11603
  };
11604
+ function colorizeContentLines(lines, _m) {
11605
+ return lines.map((line) => {
11606
+ if (line.startsWith("[Tool Call]"))
11607
+ return chalk11.cyan(line);
11608
+ if (line.startsWith("[Tool Result]"))
11609
+ return chalk11.yellow(line);
11610
+ if (line === "[Reasoning]")
11611
+ return chalk11.magenta(line);
11612
+ if (line === "[Checkpoint]")
11613
+ return chalk11.cyan(line);
11614
+ if (line.startsWith("[Node Call]"))
11615
+ return chalk11.blue(line);
11616
+ if (line.startsWith("[Node Interrupt]"))
11617
+ return chalk11.yellow(line);
11618
+ if (line.startsWith("[Node Resume]"))
11619
+ return chalk11.green(line);
11620
+ if (line.startsWith("[Node Start]"))
11621
+ return chalk11.blue(line);
11622
+ if (line.startsWith("✅") || line.startsWith("❌")) {
11623
+ if (line.includes("[Node Result]"))
11624
+ return chalk11.green(line);
11625
+ if (line.includes("[Node End]"))
11626
+ return chalk11.green(line);
11627
+ return line;
11628
+ }
11629
+ if (line.startsWith(" ")) {
11630
+ if (line.startsWith(" Error:"))
11631
+ return chalk11.red(line);
11632
+ if (line.startsWith(" Query:"))
11633
+ return chalk11.bold(line);
11634
+ if (line.startsWith(" Options:") || line.startsWith(" agentSessionId:") || line.startsWith(" Duration:"))
11635
+ return chalk11.gray(line);
11636
+ return chalk11.gray(line);
11637
+ }
11638
+ return line;
11639
+ });
11640
+ }
11521
11641
 
11522
11642
  // src/commands/sessions/compact.ts
11523
11643
  import chalk12 from "chalk";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-setting/roy-agent-cli",
3
- "version": "1.5.107",
3
+ "version": "1.5.111",
4
4
  "type": "module",
5
5
  "description": "CLI for roy-agent - Non-interactive command execution",
6
6
  "main": "./dist/index.js",