@agentmeshhq/agent 0.4.16 → 0.4.18
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/LICENSE +21 -0
- package/dist/__tests__/injection-verify.test.d.ts +1 -0
- package/dist/__tests__/injection-verify.test.js +93 -0
- package/dist/__tests__/injection-verify.test.js.map +1 -0
- package/dist/__tests__/injector.test.js +78 -1
- package/dist/__tests__/injector.test.js.map +1 -1
- package/dist/__tests__/relay.test.d.ts +1 -0
- package/dist/__tests__/relay.test.js +17 -0
- package/dist/__tests__/relay.test.js.map +1 -0
- package/dist/__tests__/runner.test.js +17 -0
- package/dist/__tests__/runner.test.js.map +1 -1
- package/dist/__tests__/session-recovery.test.js +214 -11
- package/dist/__tests__/session-recovery.test.js.map +1 -1
- package/dist/__tests__/startup-diagnostics.test.d.ts +1 -0
- package/dist/__tests__/startup-diagnostics.test.js +250 -0
- package/dist/__tests__/startup-diagnostics.test.js.map +1 -0
- package/dist/__tests__/tmux-runtime.test.js +13 -0
- package/dist/__tests__/tmux-runtime.test.js.map +1 -1
- package/dist/__tests__/watcher-queue.test.d.ts +1 -0
- package/dist/__tests__/watcher-queue.test.js +85 -0
- package/dist/__tests__/watcher-queue.test.js.map +1 -0
- package/dist/__tests__/watcher-state.test.d.ts +1 -0
- package/dist/__tests__/watcher-state.test.js +159 -0
- package/dist/__tests__/watcher-state.test.js.map +1 -0
- package/dist/cli/commands.d.ts +32 -0
- package/dist/cli/commands.js +165 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/index.js +88 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/relay.d.ts +1 -0
- package/dist/cli/relay.js +16 -2
- package/dist/cli/relay.js.map +1 -1
- package/dist/config/schema.d.ts +1 -1
- package/dist/core/chat-output-parser.d.ts +24 -0
- package/dist/core/chat-output-parser.js +134 -0
- package/dist/core/chat-output-parser.js.map +1 -0
- package/dist/core/chat-output-parser.test.d.ts +7 -0
- package/dist/core/chat-output-parser.test.js +130 -0
- package/dist/core/chat-output-parser.test.js.map +1 -0
- package/dist/core/daemon/crash-log.js +5 -0
- package/dist/core/daemon/crash-log.js.map +1 -1
- package/dist/core/daemon/injection-verify.d.ts +25 -0
- package/dist/core/daemon/injection-verify.js +94 -0
- package/dist/core/daemon/injection-verify.js.map +1 -0
- package/dist/core/daemon/roles.d.ts +2 -2
- package/dist/core/daemon/roles.js +3 -0
- package/dist/core/daemon/roles.js.map +1 -1
- package/dist/core/daemon/session-recovery.d.ts +18 -1
- package/dist/core/daemon/session-recovery.js +89 -5
- package/dist/core/daemon/session-recovery.js.map +1 -1
- package/dist/core/daemon/startup-diagnostics.d.ts +76 -0
- package/dist/core/daemon/startup-diagnostics.js +277 -0
- package/dist/core/daemon/startup-diagnostics.js.map +1 -0
- package/dist/core/daemon/watcher-loop.d.ts +27 -0
- package/dist/core/daemon/watcher-loop.js +134 -0
- package/dist/core/daemon/watcher-loop.js.map +1 -0
- package/dist/core/daemon/watcher-queue.d.ts +33 -0
- package/dist/core/daemon/watcher-queue.js +71 -0
- package/dist/core/daemon/watcher-queue.js.map +1 -0
- package/dist/core/daemon/watcher-state.d.ts +66 -0
- package/dist/core/daemon/watcher-state.js +151 -0
- package/dist/core/daemon/watcher-state.js.map +1 -0
- package/dist/core/daemon.d.ts +12 -0
- package/dist/core/daemon.js +134 -2
- package/dist/core/daemon.js.map +1 -1
- package/dist/core/injector.js +164 -27
- package/dist/core/injector.js.map +1 -1
- package/dist/core/runner/build.js +7 -31
- package/dist/core/runner/build.js.map +1 -1
- package/dist/core/runner/detect.js +2 -8
- package/dist/core/runner/detect.js.map +1 -1
- package/dist/core/runner/index.d.ts +3 -1
- package/dist/core/runner/index.js +2 -0
- package/dist/core/runner/index.js.map +1 -1
- package/dist/core/runner/kimi-models.d.ts +4 -0
- package/dist/core/runner/kimi-models.js +24 -0
- package/dist/core/runner/kimi-models.js.map +1 -0
- package/dist/core/runner/registry.d.ts +3 -0
- package/dist/core/runner/registry.js +75 -0
- package/dist/core/runner/registry.js.map +1 -0
- package/dist/core/runner/types.d.ts +17 -1
- package/dist/core/tmux-runtime.d.ts +1 -1
- package/dist/core/tmux-runtime.js +13 -0
- package/dist/core/tmux-runtime.js.map +1 -1
- package/dist/core/tmux.d.ts +4 -0
- package/dist/core/tmux.js +49 -11
- package/dist/core/tmux.js.map +1 -1
- package/package.json +11 -12
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts clean LLM reply from raw tmux capture.
|
|
3
|
+
*
|
|
4
|
+
* Raw tmux output includes:
|
|
5
|
+
* - Welcome screen with logo
|
|
6
|
+
* - Prompt characters (❯ for input, ⏺ for output)
|
|
7
|
+
* - ANSI escape codes for colors/formatting
|
|
8
|
+
* - Box-drawing characters
|
|
9
|
+
*
|
|
10
|
+
* This parser identifies the LLM's response block and strips all chrome.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Remove ANSI escape codes (colors, formatting, etc.)
|
|
14
|
+
*/
|
|
15
|
+
function stripAnsiCodes(text) {
|
|
16
|
+
// Match ESC[ ... (letter|number) patterns
|
|
17
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: ESC is needed for ANSI parsing
|
|
18
|
+
return text.replace(/\u001b\[[0-9;]*[a-zA-Z]/g, "");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Check if a line is tmux chrome (logo, box-drawing, etc.)
|
|
22
|
+
*/
|
|
23
|
+
function isTmuxChrome(line) {
|
|
24
|
+
const trimmed = line.trim();
|
|
25
|
+
// Empty lines are not chrome
|
|
26
|
+
if (trimmed.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
// Claude Code logo lines (▐▛███▜▌, ▝▜█████▛▘, etc.)
|
|
29
|
+
if (/^[▐▛███▜▌▝█]*\s*Claude Code/.test(trimmed))
|
|
30
|
+
return true;
|
|
31
|
+
if (/^[▛███▜▌▝█]*\s*Haiku|Sonnet|Opus|Claude/.test(trimmed))
|
|
32
|
+
return true;
|
|
33
|
+
if (/^[▘▝]*\s*$/.test(trimmed))
|
|
34
|
+
return true;
|
|
35
|
+
// Pure box drawing / special characters
|
|
36
|
+
if (/^[╔╗╚╝═║├┤┬┴┼▐▛███▜▌▝█\s]*$/.test(trimmed))
|
|
37
|
+
return true;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if a line starts with a prompt character.
|
|
42
|
+
* ❯ = input prompt (user's message follows)
|
|
43
|
+
* ⏺ = output prompt (LLM's response follows)
|
|
44
|
+
*/
|
|
45
|
+
function getPromptType(line) {
|
|
46
|
+
const trimmed = line.trim();
|
|
47
|
+
if (trimmed.startsWith("❯"))
|
|
48
|
+
return "input";
|
|
49
|
+
if (trimmed.startsWith("⏺"))
|
|
50
|
+
return "output";
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extract the message content after a prompt character.
|
|
55
|
+
* Removes the prompt character and leading/trailing whitespace.
|
|
56
|
+
*/
|
|
57
|
+
function extractMessageAfterPrompt(line) {
|
|
58
|
+
const trimmed = line.trim();
|
|
59
|
+
// Remove ❯ or ⏺ and following space(s)
|
|
60
|
+
return trimmed.replace(/^[❯⏺]\s+/, "").trim();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Main parser: extract clean LLM reply from raw tmux capture.
|
|
64
|
+
*
|
|
65
|
+
* Strategy:
|
|
66
|
+
* 1. Split into lines
|
|
67
|
+
* 2. Remove ANSI codes
|
|
68
|
+
* 3. Find all prompt lines (input ❯ and output ⏺)
|
|
69
|
+
* 4. Locate the last output prompt (⏺)
|
|
70
|
+
* 5. Extract content from that prompt until the next input prompt (❯)
|
|
71
|
+
*
|
|
72
|
+
* Returns the clean reply text, or empty string if no reply found.
|
|
73
|
+
*/
|
|
74
|
+
export function extractLLMReply(rawOutput) {
|
|
75
|
+
if (!rawOutput || rawOutput.trim().length === 0) {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
const lines = rawOutput.split("\n");
|
|
79
|
+
// Step 1: Remove ANSI codes and filter out tmux chrome
|
|
80
|
+
const cleaned = [];
|
|
81
|
+
for (const line of lines) {
|
|
82
|
+
const noAnsi = stripAnsiCodes(line);
|
|
83
|
+
if (isTmuxChrome(noAnsi)) {
|
|
84
|
+
// Skip pure chrome lines, but keep track of them in the array
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const promptType = getPromptType(noAnsi);
|
|
88
|
+
cleaned.push({
|
|
89
|
+
original: line,
|
|
90
|
+
text: noAnsi,
|
|
91
|
+
promptType,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// Step 2: Find the last output prompt (⏺)
|
|
95
|
+
let lastOutputIdx = -1;
|
|
96
|
+
for (let i = cleaned.length - 1; i >= 0; i--) {
|
|
97
|
+
if (cleaned[i].promptType === "output") {
|
|
98
|
+
lastOutputIdx = i;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (lastOutputIdx === -1) {
|
|
103
|
+
// No output prompt found — maybe the response hasn't started yet
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
// Step 3: Extract content starting from the output prompt
|
|
107
|
+
const replyLines = [];
|
|
108
|
+
// Add the message from the output prompt line
|
|
109
|
+
const firstMsg = extractMessageAfterPrompt(cleaned[lastOutputIdx].text);
|
|
110
|
+
if (firstMsg) {
|
|
111
|
+
replyLines.push(firstMsg);
|
|
112
|
+
}
|
|
113
|
+
// Step 4: Continue collecting lines until the next input prompt (❯) or end of buffer
|
|
114
|
+
for (let i = lastOutputIdx + 1; i < cleaned.length; i++) {
|
|
115
|
+
if (cleaned[i].promptType === "input") {
|
|
116
|
+
// Stop at the next input prompt
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
// If this line has a prompt marker but it's not an input, skip the marker
|
|
120
|
+
if (cleaned[i].promptType === "output") {
|
|
121
|
+
const msg = extractMessageAfterPrompt(cleaned[i].text);
|
|
122
|
+
if (msg) {
|
|
123
|
+
replyLines.push(msg);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
// Regular continuation line
|
|
128
|
+
replyLines.push(cleaned[i].text.trim());
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Step 5: Join and return
|
|
132
|
+
return replyLines.join("\n").trim();
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=chat-output-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-output-parser.js","sourceRoot":"","sources":["../../src/core/chat-output-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,0CAA0C;IAC1C,0FAA0F;IAC1F,OAAO,IAAI,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,SAAS,YAAY,CAAC,IAAY;IAChC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAE5B,6BAA6B;IAC7B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEvC,oDAAoD;IACpD,IAAI,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7D,IAAI,yCAAyC,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IACzE,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAE5C,wCAAwC;IACxC,IAAI,6BAA6B,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAE7D,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,IAAY;IACjC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAA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C;AACtC,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for chat-output-parser (GH-891 Phase 1)
|
|
3
|
+
*
|
|
4
|
+
* Tests extraction of clean LLM replies from raw tmux capture,
|
|
5
|
+
* including removal of ANSI codes, prompt characters, and tmux chrome.
|
|
6
|
+
*/
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import test from "node:test";
|
|
9
|
+
import { extractLLMReply } from "./chat-output-parser.js";
|
|
10
|
+
test("extractLLMReply - basic reply extraction", () => {
|
|
11
|
+
const raw = `▐▛███▜▌ Claude Code v2.1.88
|
|
12
|
+
▝▜█████▛▘ Haiku 4.5 with high effort · Claude Max
|
|
13
|
+
▘▘ ▝▝ ~/Dev/agentmesh-mesh-dev-2
|
|
14
|
+
|
|
15
|
+
❯ [AgentMesh] Connected and ready...
|
|
16
|
+
⏺ Ready and connected. I understand the system...
|
|
17
|
+
❯ ping - test chat
|
|
18
|
+
⏺ Pong. Chat is live and connected. Ready to assist.
|
|
19
|
+
❯ `;
|
|
20
|
+
const result = extractLLMReply(raw);
|
|
21
|
+
assert.strictEqual(result, "Pong. Chat is live and connected. Ready to assist.");
|
|
22
|
+
});
|
|
23
|
+
test("extractLLMReply - multi-line response", () => {
|
|
24
|
+
const raw = `❯ tell me a story
|
|
25
|
+
⏺ Once upon a time,
|
|
26
|
+
there was a kingdom.
|
|
27
|
+
❯ `;
|
|
28
|
+
const result = extractLLMReply(raw);
|
|
29
|
+
assert.strictEqual(result, "Once upon a time,\nthere was a kingdom.");
|
|
30
|
+
});
|
|
31
|
+
test("extractLLMReply - strips ANSI codes", () => {
|
|
32
|
+
const raw = `❯ hello
|
|
33
|
+
⏺ \x1b[32mGreen\x1b[0m text
|
|
34
|
+
❯ `;
|
|
35
|
+
const result = extractLLMReply(raw);
|
|
36
|
+
assert.strictEqual(result, "Green text");
|
|
37
|
+
});
|
|
38
|
+
test("extractLLMReply - handles empty input", () => {
|
|
39
|
+
const result = extractLLMReply("");
|
|
40
|
+
assert.strictEqual(result, "");
|
|
41
|
+
});
|
|
42
|
+
test("extractLLMReply - handles whitespace-only input", () => {
|
|
43
|
+
const result = extractLLMReply(" \n \n ");
|
|
44
|
+
assert.strictEqual(result, "");
|
|
45
|
+
});
|
|
46
|
+
test("extractLLMReply - no output prompt found", () => {
|
|
47
|
+
const raw = `❯ hello
|
|
48
|
+
some random text`;
|
|
49
|
+
const result = extractLLMReply(raw);
|
|
50
|
+
assert.strictEqual(result, "");
|
|
51
|
+
});
|
|
52
|
+
test("extractLLMReply - strips logo and chrome", () => {
|
|
53
|
+
const raw = `▐▛███▜▌ Claude Code v2.1.88
|
|
54
|
+
▝▜█████▛▘ Sonnet 4.6 · High Effort
|
|
55
|
+
▘▘ ▝▝ ~/project
|
|
56
|
+
|
|
57
|
+
❯ test
|
|
58
|
+
⏺ Clean output
|
|
59
|
+
❯ `;
|
|
60
|
+
const result = extractLLMReply(raw);
|
|
61
|
+
assert.strictEqual(result, "Clean output");
|
|
62
|
+
});
|
|
63
|
+
test("extractLLMReply - response with blank lines", () => {
|
|
64
|
+
const raw = `❯ query
|
|
65
|
+
⏺ First paragraph.
|
|
66
|
+
|
|
67
|
+
Second paragraph.
|
|
68
|
+
❯ `;
|
|
69
|
+
const result = extractLLMReply(raw);
|
|
70
|
+
// Empty lines between paragraphs should be preserved
|
|
71
|
+
assert.strictEqual(result, "First paragraph.\n\nSecond paragraph.");
|
|
72
|
+
});
|
|
73
|
+
test("extractLLMReply - last output prompt wins", () => {
|
|
74
|
+
const raw = `❯ first
|
|
75
|
+
⏺ First reply
|
|
76
|
+
❯ second
|
|
77
|
+
⏺ Second reply
|
|
78
|
+
❯ `;
|
|
79
|
+
const result = extractLLMReply(raw);
|
|
80
|
+
assert.strictEqual(result, "Second reply");
|
|
81
|
+
});
|
|
82
|
+
test("extractLLMReply - handles trailing empty lines", () => {
|
|
83
|
+
const raw = `❯ hello
|
|
84
|
+
⏺ Response
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
❯ `;
|
|
88
|
+
const result = extractLLMReply(raw);
|
|
89
|
+
assert.strictEqual(result, "Response");
|
|
90
|
+
});
|
|
91
|
+
test("extractLLMReply - only extracts until next input prompt", () => {
|
|
92
|
+
const raw = `❯ first query
|
|
93
|
+
⏺ Response to first
|
|
94
|
+
More response content
|
|
95
|
+
❯ second query`;
|
|
96
|
+
const result = extractLLMReply(raw);
|
|
97
|
+
assert.strictEqual(result, "Response to first\nMore response content");
|
|
98
|
+
});
|
|
99
|
+
test("extractLLMReply - complex real-world example", () => {
|
|
100
|
+
const raw = `▐▛███▜▌ Claude Code v2.1.88
|
|
101
|
+
▝▜█████▛▘ Haiku 4.5 · High Effort
|
|
102
|
+
▘▘ ▝▝ ~/Dev/project
|
|
103
|
+
|
|
104
|
+
❯ [Handoff] Task: implement feature X
|
|
105
|
+
⏺ I understand. Let me start by reading the requirements.
|
|
106
|
+
❯ [User] What's your plan?
|
|
107
|
+
⏺ Here's my plan:
|
|
108
|
+
|
|
109
|
+
1. Read the specification
|
|
110
|
+
2. Create tests
|
|
111
|
+
3. Implement the feature
|
|
112
|
+
|
|
113
|
+
I'll start now.
|
|
114
|
+
❯ `;
|
|
115
|
+
const result = extractLLMReply(raw);
|
|
116
|
+
const expected = "Here's my plan:\n\n1. Read the specification\n2. Create tests\n3. Implement the feature\n\nI'll start now.";
|
|
117
|
+
assert.strictEqual(result, expected);
|
|
118
|
+
});
|
|
119
|
+
test("extractLLMReply - handles colored box-drawing characters", () => {
|
|
120
|
+
const raw = `╔════════════════════════════╗
|
|
121
|
+
║ Claude Code v2 ║
|
|
122
|
+
╚════════════════════════════╝
|
|
123
|
+
|
|
124
|
+
❯ command
|
|
125
|
+
⏺ Result
|
|
126
|
+
❯ `;
|
|
127
|
+
const result = extractLLMReply(raw);
|
|
128
|
+
assert.strictEqual(result, "Result");
|
|
129
|
+
});
|
|
130
|
+
//# sourceMappingURL=chat-output-parser.test.js.map
|
|
@@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AG,EAAE;IACnE,MAAM,GAAG,GAAG;;;eAGC,CAAC;IAEd,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,0CAA0C,CAAC,CAAC;AACzE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,8CAA8C,EAAE,GAAG,EAAE;IACxD,MAAM,GAAG,GAAG;;;;;;;;;;;;;;GAcX,CAAC;IAEF,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,QAAQ,GACZ,4GAA4G,CAAC;IAC/G,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0DAA0D,EAAE,GAAG,EAAE;IACpE,MAAM,GAAG,GAAG;;;;;;GAMX,CAAC;IAEF,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { formatDiagnosticSummary } from "./startup-diagnostics.js";
|
|
1
2
|
/**
|
|
2
3
|
* Formats a structured crash entry for on-disk diagnostics.
|
|
3
4
|
*/
|
|
4
5
|
export function formatCrashLog(input) {
|
|
6
|
+
// Include startup diagnostics if available
|
|
7
|
+
const startupDiagnostics = formatDiagnosticSummary(input.agentName);
|
|
5
8
|
return `
|
|
6
9
|
================================================================================
|
|
7
10
|
AGENT CRASH DETECTED
|
|
@@ -14,6 +17,8 @@ Sandbox: ${input.sandboxLabel}
|
|
|
14
17
|
Workdir: ${input.workdir}
|
|
15
18
|
Model: ${input.model}
|
|
16
19
|
|
|
20
|
+
${startupDiagnostics}
|
|
21
|
+
|
|
17
22
|
--- Last Session Output ---
|
|
18
23
|
${input.lastOutput}
|
|
19
24
|
================================================================================
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crash-log.js","sourceRoot":"","sources":["../../../src/core/daemon/crash-log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crash-log.js","sourceRoot":"","sources":["../../../src/core/daemon/crash-log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAanE;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAoB;IACjD,2CAA2C;IAC3C,MAAM,kBAAkB,GAAG,uBAAuB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAEpE,OAAO;;;;aAII,KAAK,CAAC,SAAS;SACnB,KAAK,CAAC,SAAS;YACZ,KAAK,CAAC,OAAO;UACf,KAAK,CAAC,MAAM;WACX,KAAK,CAAC,YAAY;WAClB,KAAK,CAAC,OAAO;SACf,KAAK,CAAC,KAAK;;EAElB,kBAAkB;;;EAGlB,KAAK,CAAC,UAAU;;;CAGjB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff injection verification — confirms the LLM actually started
|
|
3
|
+
* processing an injected handoff by monitoring tmux output changes.
|
|
4
|
+
*
|
|
5
|
+
* Also detects rate-limit patterns to pause auto-acceptance.
|
|
6
|
+
*
|
|
7
|
+
* Epic #887
|
|
8
|
+
*/
|
|
9
|
+
export interface InjectionResult {
|
|
10
|
+
verified: boolean;
|
|
11
|
+
rateLimited: boolean;
|
|
12
|
+
attempts: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* After injecting a handoff into tmux, poll output to verify the LLM
|
|
16
|
+
* acknowledged it. Re-injects up to maxRetries times if no activity.
|
|
17
|
+
*
|
|
18
|
+
* Returns whether the injection was verified, and whether a rate limit
|
|
19
|
+
* was detected.
|
|
20
|
+
*/
|
|
21
|
+
export declare function verifyInjection(agentName: string, handoffId: string, handoffScope: string, maxRetries?: number): Promise<InjectionResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Scan tmux output for rate-limit indicators.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isRateLimited(output: string): boolean;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handoff injection verification — confirms the LLM actually started
|
|
3
|
+
* processing an injected handoff by monitoring tmux output changes.
|
|
4
|
+
*
|
|
5
|
+
* Also detects rate-limit patterns to pause auto-acceptance.
|
|
6
|
+
*
|
|
7
|
+
* Epic #887
|
|
8
|
+
*/
|
|
9
|
+
import { captureSessionOutput, sendKeys } from "../tmux.js";
|
|
10
|
+
const RATE_LIMIT_PATTERNS = [
|
|
11
|
+
"hit your limit",
|
|
12
|
+
"rate limit",
|
|
13
|
+
"resets ",
|
|
14
|
+
"usage limit",
|
|
15
|
+
"too many requests",
|
|
16
|
+
"quota exceeded",
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* After injecting a handoff into tmux, poll output to verify the LLM
|
|
20
|
+
* acknowledged it. Re-injects up to maxRetries times if no activity.
|
|
21
|
+
*
|
|
22
|
+
* Returns whether the injection was verified, and whether a rate limit
|
|
23
|
+
* was detected.
|
|
24
|
+
*/
|
|
25
|
+
export async function verifyInjection(agentName, handoffId, handoffScope, maxRetries = 2) {
|
|
26
|
+
const result = { verified: false, rateLimited: false, attempts: 1 };
|
|
27
|
+
// Capture baseline output before checking
|
|
28
|
+
const baseline = captureSessionOutput(agentName, 30) || "";
|
|
29
|
+
// Check for rate limit in current output
|
|
30
|
+
if (isRateLimited(baseline)) {
|
|
31
|
+
console.log(`[INJECT-VERIFY] Rate limit detected for ${agentName}`);
|
|
32
|
+
result.rateLimited = true;
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
// Wait and check if output changed (LLM is processing)
|
|
36
|
+
const verified = await pollForActivity(agentName, baseline, 30_000);
|
|
37
|
+
if (verified) {
|
|
38
|
+
result.verified = true;
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
// No activity — retry injection
|
|
42
|
+
for (let retry = 0; retry < maxRetries; retry++) {
|
|
43
|
+
result.attempts += 1;
|
|
44
|
+
console.log(`[INJECT-VERIFY] Re-injecting handoff ${handoffId} (attempt ${result.attempts})`);
|
|
45
|
+
const reminderMsg = `[AgentMesh] Reminder: You accepted handoff ${handoffId}. Scope: ${handoffScope}. Please start working on it.`;
|
|
46
|
+
const sent = sendKeys(agentName, reminderMsg);
|
|
47
|
+
if (!sent) {
|
|
48
|
+
console.warn(`[INJECT-VERIFY] Failed to re-inject into ${agentName}`);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
// Wait a bit then check output
|
|
52
|
+
await sleep(5000);
|
|
53
|
+
const current = captureSessionOutput(agentName, 30) || "";
|
|
54
|
+
// Check rate limit after re-injection
|
|
55
|
+
if (isRateLimited(current)) {
|
|
56
|
+
console.log(`[INJECT-VERIFY] Rate limit detected after retry for ${agentName}`);
|
|
57
|
+
result.rateLimited = true;
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
const retryVerified = await pollForActivity(agentName, current, 20_000);
|
|
61
|
+
if (retryVerified) {
|
|
62
|
+
result.verified = true;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
console.warn(`[INJECT-VERIFY] Handoff ${handoffId} not verified after ${result.attempts} attempts`);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Scan tmux output for rate-limit indicators.
|
|
71
|
+
*/
|
|
72
|
+
export function isRateLimited(output) {
|
|
73
|
+
const lower = output.toLowerCase();
|
|
74
|
+
return RATE_LIMIT_PATTERNS.some((pattern) => lower.includes(pattern));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Poll tmux output for changes over a duration. Returns true if output changes.
|
|
78
|
+
*/
|
|
79
|
+
async function pollForActivity(agentName, baseline, durationMs) {
|
|
80
|
+
const pollInterval = 5000;
|
|
81
|
+
const polls = Math.ceil(durationMs / pollInterval);
|
|
82
|
+
for (let i = 0; i < polls; i++) {
|
|
83
|
+
await sleep(pollInterval);
|
|
84
|
+
const current = captureSessionOutput(agentName, 30) || "";
|
|
85
|
+
if (current !== baseline) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
function sleep(ms) {
|
|
92
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=injection-verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injection-verify.js","sourceRoot":"","sources":["../../../src/core/daemon/injection-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,mBAAmB,GAAG;IAC1B,gBAAgB;IAChB,YAAY;IACZ,SAAS;IACT,aAAa;IACb,mBAAmB;IACnB,gBAAgB;CACjB,CAAC;AAQF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,SAAiB,EACjB,SAAiB,EACjB,YAAoB,EACpB,UAAU,GAAG,CAAC;IAEd,MAAM,MAAM,GAAoB,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAErF,0CAA0C;IAC1C,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;IAE3D,yCAAyC;IACzC,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,GAAG,CAAC,2CAA2C,SAAS,EAAE,CAAC,CAAC;QACpE,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,uDAAuD;IACvD,MAAM,QAAQ,GAAG,MAAM,eAAe,C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AAS,uBAAuB,MAAM,CAAC,QAAQ,WAAW,CACtF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,eAAe,CAC5B,SAAiB,EACjB,QAAgB,EAChB,UAAkB;IAElB,MAAM,YAAY,GAAG,IAAI,CAAC;IAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,GAAG,YAAY,CAAC,CAAC;IAEnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,MAAM,KAAK,CAAC,YAAY,CAAC,CAAC;QAC1B,MAAM,OAAO,GAAG,oBAAoB,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC;QAC1D,IAAI,OAAO,KAAK,QAAQ,EAAE,CAAC;YACzB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
/** Canonical set of predefined roles. Free-form strings are still accepted for
|
|
8
8
|
* hub auto-assignment but will not activate role-specific daemon behaviour. */
|
|
9
|
-
export type AgentRole = "coordinator" | "developer" | "reviewer" | "lead" | "observer";
|
|
9
|
+
export type AgentRole = "coordinator" | "developer" | "reviewer" | "lead" | "observer" | "watcher";
|
|
10
10
|
export declare const VALID_ROLES: readonly AgentRole[];
|
|
11
11
|
export declare function isKnownRole(role: string): role is AgentRole;
|
|
12
12
|
/**
|
|
@@ -22,4 +22,4 @@ export declare const ROLE_SYSTEM_PROMPTS: Record<AgentRole, string>;
|
|
|
22
22
|
*
|
|
23
23
|
* Replaces inferAttendedFromRole() in bootstrap.ts for known roles.
|
|
24
24
|
*/
|
|
25
|
-
export declare const ROLE_DAEMON_BEHAVIOUR: Record<AgentRole, "lead-loop" | "worker" | "observer">;
|
|
25
|
+
export declare const ROLE_DAEMON_BEHAVIOUR: Record<AgentRole, "lead-loop" | "worker" | "observer" | "watcher-loop">;
|
|
@@ -10,6 +10,7 @@ export const VALID_ROLES = [
|
|
|
10
10
|
"reviewer",
|
|
11
11
|
"lead",
|
|
12
12
|
"observer",
|
|
13
|
+
"watcher",
|
|
13
14
|
];
|
|
14
15
|
export function isKnownRole(role) {
|
|
15
16
|
return VALID_ROLES.includes(role);
|
|
@@ -24,6 +25,7 @@ export const ROLE_SYSTEM_PROMPTS = {
|
|
|
24
25
|
reviewer: "You are a reviewer agent. Your job is to review pull requests and handoff proposals for correctness, quality, and consistency. Approve, request changes, or reject with clear reasoning.",
|
|
25
26
|
lead: "You are a lead agent. You coordinate the team, route work to the right agents, monitor SLAs, and escalate blockers. You also review high-level architecture decisions.",
|
|
26
27
|
observer: "You are an observer agent. You monitor team activity and provide strategic input when asked. You do not accept handoffs automatically and do not modify code directly.",
|
|
28
|
+
watcher: "You are a watcher agent. Every ~2 minutes you receive a project state snapshot showing handoffs, agent health, blockers, and claims. Analyze the state and take corrective actions using agentmesh CLI commands: nudge stuck agents, escalate breached SLAs, reassign stalled handoffs, create blockers, release stale claims. Process one tick at a time — after analysis and action, wait for the next tick. Do not take actions unprompted between ticks.",
|
|
27
29
|
};
|
|
28
30
|
/**
|
|
29
31
|
* Maps each predefined role to a daemon behaviour mode:
|
|
@@ -39,5 +41,6 @@ export const ROLE_DAEMON_BEHAVIOUR = {
|
|
|
39
41
|
reviewer: "worker",
|
|
40
42
|
lead: "lead-loop",
|
|
41
43
|
observer: "observer",
|
|
44
|
+
watcher: "watcher-loop",
|
|
42
45
|
};
|
|
43
46
|
//# sourceMappingURL=roles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../../src/core/daemon/roles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,CAAC,MAAM,WAAW,GAAyB;IAC/C,aAAa;IACb,WAAW;IACX,UAAU;IACV,MAAM;IACN,UAAU;
|
|
1
|
+
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../../src/core/daemon/roles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,CAAC,MAAM,WAAW,GAAyB;IAC/C,aAAa;IACb,WAAW;IACX,UAAU;IACV,MAAM;IACN,UAAU;IACV,SAAS;CACV,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAQ,WAAiC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAA8B;IAC5D,WAAW,EACT,8LAA8L;IAChM,SAAS,EACP,mJAAmJ;IACrJ,QAAQ,EACN,0LAA0L;IAC5L,IAAI,EAAE,wKAAwK;IAC9K,QAAQ,EACN,wKAAwK;IAC1K,OAAO,EACL,8bAA8b;CACjc,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAG9B;IACF,WAAW,EAAE,WAAW;IACxB,SAAS,EAAE,QAAQ;IACnB,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,cAAc;CACxB,CAAC"}
|
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { type ProcessExitEvent } from "./startup-diagnostics.js";
|
|
2
|
+
/**
|
|
3
|
+
* Gets the most recent process exit event from diagnostics
|
|
4
|
+
*/
|
|
5
|
+
export declare function getLastProcessExit(agentName: string): ProcessExitEvent | null;
|
|
6
|
+
/**
|
|
7
|
+
* Determines if a session failure is recoverable based on the reason
|
|
8
|
+
* and startup diagnostics.
|
|
9
|
+
*
|
|
10
|
+
* A failure is considered recoverable if:
|
|
11
|
+
* 1. The reason matches known recoverable patterns
|
|
12
|
+
* 2. The process exited during startup (within 15s) AND the exit event is fresh
|
|
13
|
+
* (within 60s) - this suggests a transient issue that may resolve on retry
|
|
14
|
+
*
|
|
15
|
+
* The freshness guard prevents old exit events from misclassifying unrelated
|
|
16
|
+
* future failures as recoverable.
|
|
17
|
+
*/
|
|
18
|
+
export declare function isRecoverableSessionFailure(reason: string, agentName?: string): boolean;
|
|
@@ -1,7 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { readStartupDiagnostics } from "./startup-diagnostics.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extended reasons that can indicate a recoverable session failure
|
|
4
|
+
*/
|
|
5
|
+
const RECOVERABLE_REASONS = [
|
|
6
|
+
"session_not_found",
|
|
7
|
+
"pane_dead",
|
|
8
|
+
"no_pid",
|
|
9
|
+
"pane_died",
|
|
10
|
+
"process_replaced",
|
|
11
|
+
"session_terminated",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* Maximum age of an exit event to consider it relevant (60 seconds)
|
|
15
|
+
* Exit events older than this are considered stale and unrelated to current failures
|
|
16
|
+
*/
|
|
17
|
+
const MAX_EXIT_EVENT_AGE_MS = 60000;
|
|
18
|
+
/**
|
|
19
|
+
* Startup window - if process exits within this time of startup, it's recoverable
|
|
20
|
+
*/
|
|
21
|
+
const STARTUP_WINDOW_MS = 15000;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a reason string matches recoverable patterns
|
|
24
|
+
*/
|
|
25
|
+
function matchesRecoverablePattern(reason) {
|
|
26
|
+
return (RECOVERABLE_REASONS.includes(reason) ||
|
|
27
|
+
reason.startsWith("check_failed") ||
|
|
28
|
+
reason.startsWith("session_creation_failed") ||
|
|
29
|
+
reason.startsWith("pane_dead"));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets the most recent process exit event from diagnostics
|
|
33
|
+
*/
|
|
34
|
+
export function getLastProcessExit(agentName) {
|
|
35
|
+
const entries = readStartupDiagnostics(agentName);
|
|
36
|
+
// Find the most recent exit entry
|
|
37
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
38
|
+
if (entries[i].type === "exit") {
|
|
39
|
+
return entries[i].data;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determines if a session failure is recoverable based on the reason
|
|
46
|
+
* and startup diagnostics.
|
|
47
|
+
*
|
|
48
|
+
* A failure is considered recoverable if:
|
|
49
|
+
* 1. The reason matches known recoverable patterns
|
|
50
|
+
* 2. The process exited during startup (within 15s) AND the exit event is fresh
|
|
51
|
+
* (within 60s) - this suggests a transient issue that may resolve on retry
|
|
52
|
+
*
|
|
53
|
+
* The freshness guard prevents old exit events from misclassifying unrelated
|
|
54
|
+
* future failures as recoverable.
|
|
55
|
+
*/
|
|
56
|
+
export function isRecoverableSessionFailure(reason, agentName) {
|
|
57
|
+
// First check pattern match
|
|
58
|
+
if (matchesRecoverablePattern(reason)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
// If we have agent name, check startup diagnostics
|
|
62
|
+
if (agentName) {
|
|
63
|
+
const entries = readStartupDiagnostics(agentName);
|
|
64
|
+
let lastExit = null;
|
|
65
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
66
|
+
if (entries[i].type === "exit") {
|
|
67
|
+
lastExit = {
|
|
68
|
+
exit: entries[i].data,
|
|
69
|
+
timestamp: entries[i].timestamp,
|
|
70
|
+
};
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (lastExit) {
|
|
75
|
+
// Check freshness: exit event must be recent enough to be relevant
|
|
76
|
+
const exitTimestamp = new Date(lastExit.timestamp).getTime();
|
|
77
|
+
const now = Date.now();
|
|
78
|
+
const exitAgeMs = now - exitTimestamp;
|
|
79
|
+
// Only consider fresh exit events (within last 60 seconds)
|
|
80
|
+
if (exitAgeMs <= MAX_EXIT_EVENT_AGE_MS) {
|
|
81
|
+
// If process exited within 15 seconds of startup, consider it recoverable
|
|
82
|
+
// This catches cases where the runner crashed immediately
|
|
83
|
+
if (lastExit.exit.elapsedMs < STARTUP_WINDOW_MS) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
6
90
|
}
|
|
7
91
|
//# sourceMappingURL=session-recovery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-recovery.js","sourceRoot":"","sources":["../../../src/core/daemon/session-recovery.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"session-recovery.js","sourceRoot":"","sources":["../../../src/core/daemon/session-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEzF;;GAEG;AACH,MAAM,mBAAmB,GAAG;IAC1B,mBAAmB;IACnB,WAAW;IACX,QAAQ;IACR,WAAW;IACX,kBAAkB;IAClB,oBAAoB;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC;;GAEG;AACH,SAAS,yBAAyB,CAAC,MAAc;IAC/C,OAAO,CACL,mBAAmB,CAAC,QAAQ,CAAC,MAAM,CAAC;QACpC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC;QACjC,MAAM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