@rowan-agent/agent 0.25.0 → 0.26.0

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.
Files changed (2) hide show
  1. package/dist/index.js +39 -33
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,12 +9,15 @@ import Schema2 from "typebox/schema";
9
9
  function escapeXml(value) {
10
10
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;");
11
11
  }
12
+ function escapeXmlText(value) {
13
+ return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
14
+ }
12
15
  function buildStructuredSection(tag, items) {
13
16
  const lines = [];
14
17
  for (const item of items) {
15
18
  lines.push(` <${tag}>`);
16
19
  for (const [key, value] of Object.entries(item)) {
17
- lines.push(` <${key}>${escapeXml(value)}</${key}>`);
20
+ lines.push(` <${key}>${escapeXmlText(value)}</${key}>`);
18
21
  }
19
22
  lines.push(` </${tag}>`);
20
23
  }
@@ -26,9 +29,9 @@ function buildSkillsDescription(skills) {
26
29
  const lines = ["<available_skills>"];
27
30
  for (const skill of visibleSkills) {
28
31
  lines.push(" <skill>");
29
- lines.push(` <name>${escapeXml(skill.name)}</name>`);
30
- lines.push(` <description>${escapeXml(skill.description)}</description>`);
31
- lines.push(` <location>${escapeXml(skill.filePath)}</location>`);
32
+ lines.push(` <name>${escapeXmlText(skill.name)}</name>`);
33
+ lines.push(` <description>${escapeXmlText(skill.description)}</description>`);
34
+ lines.push(` <location>${escapeXmlText(skill.filePath)}</location>`);
32
35
  lines.push(" </skill>");
33
36
  }
34
37
  lines.push("</available_skills>");
@@ -67,7 +70,7 @@ function detectResourceType(filePath) {
67
70
  function jsonToXml(value, depth) {
68
71
  const indent = " ".repeat(depth);
69
72
  if (value === null || value === void 0) return "";
70
- if (typeof value !== "object") return `${indent}${escapeXml(String(value))}`;
73
+ if (typeof value !== "object") return `${indent}${escapeXmlText(String(value))}`;
71
74
  if (Array.isArray(value)) {
72
75
  return value.map((item) => {
73
76
  if (typeof item === "object" && item !== null) {
@@ -75,7 +78,7 @@ function jsonToXml(value, depth) {
75
78
  ${jsonToXml(item, depth + 1)}
76
79
  ${indent}</item>`;
77
80
  }
78
- return `${indent}<item>${escapeXml(String(item))}</item>`;
81
+ return `${indent}<item>${escapeXmlText(String(item))}</item>`;
79
82
  }).join("\n");
80
83
  }
81
84
  return Object.entries(value).map(([key, val]) => {
@@ -85,7 +88,7 @@ ${indent}</item>`;
85
88
  ${jsonToXml(val, depth + 1)}
86
89
  ${indent}</${tag}>`;
87
90
  }
88
- return `${indent}<${tag}>${escapeXml(String(val))}</${tag}>`;
91
+ return `${indent}<${tag}>${escapeXmlText(String(val))}</${tag}>`;
89
92
  }).join("\n");
90
93
  }
91
94
  function buildPhaseDirectiveMessage(phase, output) {
@@ -102,7 +105,7 @@ function buildPhaseDirectiveMessage(phase, output) {
102
105
  if (output.results && output.results.length > 0 || output.instruction) {
103
106
  parts.push(` <prev_phase_outputs>`);
104
107
  if (output.instruction) {
105
- parts.push(` <instruction>${escapeXml(output.instruction)}</instruction>`);
108
+ parts.push(` <instruction>${escapeXmlText(output.instruction)}</instruction>`);
106
109
  }
107
110
  for (const r of output.results ?? []) {
108
111
  parts.push(` <phase name="${escapeXml(r.name)}">`);
@@ -2496,13 +2499,10 @@ function createCompactPhase() {
2496
2499
  const tools = context.tools.filter((tool) => tool.name === "read" || tool.name === "bash");
2497
2500
  const working = { ...context, tools, skills: [...context.skills], messages: [...context.messages] };
2498
2501
  const instructions = compactInstructions(context);
2499
- if (instructions) {
2500
- working.messages.push(createMessage("user", `Additional compaction instructions:
2501
- ${instructions}`, {
2502
- kind: "phase_input",
2503
- phase: COMPACT_PHASE_ID
2504
- }));
2505
- }
2502
+ working.messages.push(createMessage("user", buildCompactionPrompt(instructions), {
2503
+ kind: "phase_input",
2504
+ phase: COMPACT_PHASE_ID
2505
+ }));
2506
2506
  let result = await execution.invokeModel(working, { output: "internal" });
2507
2507
  for (let attempt = 0; attempt < 8 && result.toolCalls.length > 0; attempt += 1) {
2508
2508
  const calls = result.toolCalls.filter((call) => tools.some((tool) => tool.name === call.name));
@@ -2522,26 +2522,16 @@ ${instructions}`, {
2522
2522
  kind: "phase_tool",
2523
2523
  phase: COMPACT_PHASE_ID
2524
2524
  }));
2525
- for (const call of normalizedCalls) {
2526
- const tool = tools.find((candidate) => candidate.name === call.name);
2527
- let toolResult2;
2528
- try {
2529
- toolResult2 = await tool.execute(call.args, {
2530
- skills: working.skills,
2531
- toolCallId: call.id
2532
- });
2533
- } catch (error) {
2534
- toolResult2 = {
2535
- toolCallId: call.id,
2536
- toolName: call.name,
2537
- ok: false,
2538
- content: null,
2539
- error: error instanceof Error ? error.message : String(error)
2540
- };
2541
- }
2525
+ const toolResults = await execution.executeTools(
2526
+ working,
2527
+ normalizedCalls,
2528
+ result.contentBlocks,
2529
+ result.model ? { model: result.model, usage: result.usage } : void 0
2530
+ );
2531
+ for (const toolResult2 of toolResults) {
2542
2532
  working.messages.push(createMessage("tool", [{
2543
2533
  type: "tool_result",
2544
- toolUseId: call.id,
2534
+ toolUseId: toolResult2.toolCallId,
2545
2535
  content: JSON.stringify(toolResult2),
2546
2536
  isError: !toolResult2.ok
2547
2537
  }], {
@@ -2568,6 +2558,22 @@ ${instructions}`, {
2568
2558
  }
2569
2559
  };
2570
2560
  }
2561
+ function buildCompactionPrompt(instructions) {
2562
+ const lines = [
2563
+ "The conversation above is to be summarized, not continued. Do not answer, carry out, or use Tools for any request in it.",
2564
+ "Output only the summary in a fixed structure:",
2565
+ "- Goal and state",
2566
+ "- Decisions with reasons",
2567
+ "- Open requests left unfinished",
2568
+ "- Files and archive references",
2569
+ "- Facts to keep"
2570
+ ];
2571
+ if (instructions) {
2572
+ lines.push("", `Additional compaction instructions:
2573
+ ${instructions}`);
2574
+ }
2575
+ return lines.join("\n");
2576
+ }
2571
2577
  function compactInstructions(context) {
2572
2578
  const payload = context.state.payload;
2573
2579
  if (typeof payload === "object" && payload !== null && "instructions" in payload) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rowan-agent/agent",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",