@applica-software-guru/sdd-core 1.8.2 → 1.8.3
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/agent/agent-defaults.js +2 -2
- package/dist/agent/agent-defaults.js.map +1 -1
- package/dist/agent/agent-runner.d.ts +17 -0
- package/dist/agent/agent-runner.d.ts.map +1 -1
- package/dist/agent/agent-runner.js +163 -11
- package/dist/agent/agent-runner.js.map +1 -1
- package/dist/agent/worker-daemon.d.ts +12 -0
- package/dist/agent/worker-daemon.d.ts.map +1 -0
- package/dist/agent/worker-daemon.js +220 -0
- package/dist/agent/worker-daemon.js.map +1 -0
- package/dist/git/git.d.ts +6 -0
- package/dist/git/git.d.ts.map +1 -1
- package/dist/git/git.js +60 -0
- package/dist/git/git.js.map +1 -1
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt/draft-prompt-generator.d.ts.map +1 -1
- package/dist/prompt/draft-prompt-generator.js +4 -0
- package/dist/prompt/draft-prompt-generator.js.map +1 -1
- package/dist/prompt/prompt-generator.d.ts.map +1 -1
- package/dist/prompt/prompt-generator.js +5 -0
- package/dist/prompt/prompt-generator.js.map +1 -1
- package/dist/remote/sync-engine.d.ts.map +1 -1
- package/dist/remote/sync-engine.js +1 -0
- package/dist/remote/sync-engine.js.map +1 -1
- package/dist/remote/worker-client.d.ts +22 -0
- package/dist/remote/worker-client.d.ts.map +1 -0
- package/dist/remote/worker-client.js +88 -0
- package/dist/remote/worker-client.js.map +1 -0
- package/dist/remote/worker-types.d.ts +38 -0
- package/dist/remote/worker-types.d.ts.map +1 -0
- package/dist/remote/worker-types.js +3 -0
- package/dist/remote/worker-types.js.map +1 -0
- package/dist/scaffold/templates.generated.d.ts +1 -1
- package/dist/scaffold/templates.generated.d.ts.map +1 -1
- package/dist/scaffold/templates.generated.js +51 -33
- package/dist/scaffold/templates.generated.js.map +1 -1
- package/package.json +1 -1
- package/src/agent/agent-defaults.ts +2 -2
- package/src/agent/agent-runner.ts +184 -12
- package/src/agent/worker-daemon.ts +254 -0
- package/src/git/git.ts +61 -0
- package/src/index.ts +7 -2
- package/src/prompt/draft-prompt-generator.ts +8 -0
- package/src/prompt/prompt-generator.ts +8 -0
- package/src/remote/sync-engine.ts +1 -0
- package/src/remote/worker-client.ts +141 -0
- package/src/remote/worker-types.ts +40 -0
- package/src/scaffold/templates.generated.ts +51 -33
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DEFAULT_AGENTS = void 0;
|
|
4
4
|
exports.resolveAgentCommand = resolveAgentCommand;
|
|
5
5
|
exports.DEFAULT_AGENTS = {
|
|
6
|
-
claude: 'claude -p "$(cat $PROMPT_FILE)" --
|
|
7
|
-
codex: 'codex -q "$(cat $PROMPT_FILE)"',
|
|
6
|
+
claude: 'claude -p "$(cat $PROMPT_FILE)" --permission-mode auto --verbose --model $MODEL',
|
|
7
|
+
codex: 'codex -q "$(cat $PROMPT_FILE)" -m $MODEL',
|
|
8
8
|
opencode: 'opencode -p "$(cat $PROMPT_FILE)"',
|
|
9
9
|
};
|
|
10
10
|
function resolveAgentCommand(name, configAgents) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-defaults.js","sourceRoot":"","sources":["../../src/agent/agent-defaults.ts"],"names":[],"mappings":";;;AAMA,kDAKC;AAXY,QAAA,cAAc,GAA2B;IACpD,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"agent-defaults.js","sourceRoot":"","sources":["../../src/agent/agent-defaults.ts"],"names":[],"mappings":";;;AAMA,kDAKC;AAXY,QAAA,cAAc,GAA2B;IACpD,MAAM,EAAE,iFAAiF;IACzF,KAAK,EAAE,0CAA0C;IACjD,QAAQ,EAAE,mCAAmC;CAC9C,CAAC;AAEF,SAAgB,mBAAmB,CACjC,IAAY,EACZ,YAAqC;IAErC,OAAO,YAAY,EAAE,CAAC,IAAI,CAAC,IAAI,sBAAc,CAAC,IAAI,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -2,8 +2,25 @@ export interface AgentRunnerOptions {
|
|
|
2
2
|
root: string;
|
|
3
3
|
prompt: string;
|
|
4
4
|
agent: string;
|
|
5
|
+
model?: string;
|
|
5
6
|
agents?: Record<string, string>;
|
|
6
7
|
onOutput?: (data: string) => void;
|
|
7
8
|
}
|
|
9
|
+
/** Handle returned by startAgent() for interactive worker mode. */
|
|
10
|
+
export interface AgentRunnerHandle {
|
|
11
|
+
/** Resolves with the exit code when the agent process exits. */
|
|
12
|
+
exitPromise: Promise<number>;
|
|
13
|
+
/** Write data to the agent's stdin (for Q&A relay). */
|
|
14
|
+
writeStdin: (data: string) => void;
|
|
15
|
+
/** Kill the agent process. */
|
|
16
|
+
kill: () => void;
|
|
17
|
+
/** Path to the temp prompt file (cleaned up on exit). */
|
|
18
|
+
promptFile: string;
|
|
19
|
+
}
|
|
8
20
|
export declare function runAgent(options: AgentRunnerOptions): Promise<number>;
|
|
21
|
+
/**
|
|
22
|
+
* Start an agent in interactive mode (stdin piped for Q&A).
|
|
23
|
+
* Returns a handle for writing to stdin, killing the process, and awaiting exit.
|
|
24
|
+
*/
|
|
25
|
+
export declare function startAgent(options: AgentRunnerOptions): Promise<AgentRunnerHandle>;
|
|
9
26
|
//# sourceMappingURL=agent-runner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.d.ts","sourceRoot":"","sources":["../../src/agent/agent-runner.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,wBAAsB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"agent-runner.d.ts","sourceRoot":"","sources":["../../src/agent/agent-runner.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,WAAW,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7B,uDAAuD;IACvD,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,8BAA8B;IAC9B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;CACpB;AAwHD,wBAAsB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAiC3E;AAED;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwCxF"}
|
|
@@ -1,35 +1,143 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.runAgent = runAgent;
|
|
4
|
+
exports.startAgent = startAgent;
|
|
4
5
|
const node_child_process_1 = require("node:child_process");
|
|
5
6
|
const promises_1 = require("node:fs/promises");
|
|
6
7
|
const node_os_1 = require("node:os");
|
|
7
8
|
const node_path_1 = require("node:path");
|
|
8
9
|
const node_crypto_1 = require("node:crypto");
|
|
9
10
|
const agent_defaults_js_1 = require("./agent-defaults.js");
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Extract human-readable text from a single stream-json NDJSON line.
|
|
13
|
+
* Returns the text to emit, or null if the line should be suppressed.
|
|
14
|
+
* Falls back to the raw line if it is not valid JSON (e.g. stderr noise).
|
|
15
|
+
*/
|
|
16
|
+
function extractStreamJsonText(line) {
|
|
17
|
+
let event;
|
|
18
|
+
try {
|
|
19
|
+
event = JSON.parse(line);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Not JSON — pass raw (e.g. stderr lines from subprocesses)
|
|
23
|
+
return line;
|
|
24
|
+
}
|
|
25
|
+
if (typeof event !== 'object' || event === null || !('type' in event)) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const { type } = event;
|
|
29
|
+
if (type === 'assistant') {
|
|
30
|
+
const message = event.message;
|
|
31
|
+
if (typeof message === 'object' && message !== null && 'content' in message) {
|
|
32
|
+
const content = message.content;
|
|
33
|
+
if (Array.isArray(content)) {
|
|
34
|
+
const texts = content
|
|
35
|
+
.filter((b) => b?.type === 'text' && typeof b?.text === 'string')
|
|
36
|
+
.map((b) => b.text);
|
|
37
|
+
return texts.length > 0 ? texts.join('') : null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (type === 'result') {
|
|
43
|
+
const result = event.result;
|
|
44
|
+
if (typeof result === 'string' && result.trim()) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
// Suppress system/init/tool events — not useful for display
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Attach NDJSON-parsing stream handlers to a child process.
|
|
54
|
+
* Each complete JSON line is parsed and the extracted text forwarded to `sink`.
|
|
55
|
+
* stderr lines are forwarded raw (they are not stream-json).
|
|
56
|
+
*/
|
|
57
|
+
function pipeWithNdjsonParsing(child, sink) {
|
|
58
|
+
if (child.stdout) {
|
|
59
|
+
let buf = '';
|
|
60
|
+
child.stdout.on('data', (data) => {
|
|
61
|
+
buf += data.toString();
|
|
62
|
+
const lines = buf.split('\n');
|
|
63
|
+
buf = lines.pop() ?? '';
|
|
64
|
+
for (const line of lines) {
|
|
65
|
+
if (!line.trim())
|
|
66
|
+
continue;
|
|
67
|
+
const text = extractStreamJsonText(line);
|
|
68
|
+
if (text)
|
|
69
|
+
sink(text);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
child.stdout.on('end', () => {
|
|
73
|
+
if (buf.trim()) {
|
|
74
|
+
const text = extractStreamJsonText(buf);
|
|
75
|
+
if (text)
|
|
76
|
+
sink(text);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (child.stderr) {
|
|
81
|
+
child.stderr.on('data', (data) => sink(data.toString()));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function prepareAgent(options) {
|
|
85
|
+
const { prompt, agent, model, agents } = options;
|
|
12
86
|
const template = (0, agent_defaults_js_1.resolveAgentCommand)(agent, agents);
|
|
13
87
|
if (!template) {
|
|
14
88
|
throw new Error(`Unknown agent "${agent}". Available: ${Object.keys(agents ?? {}).join(', ') || 'claude, codex, opencode'}`);
|
|
15
89
|
}
|
|
16
|
-
// Write prompt to temp file (too large for CLI arg)
|
|
17
90
|
const tmpFile = (0, node_path_1.join)((0, node_os_1.tmpdir)(), `sdd-prompt-${(0, node_crypto_1.randomBytes)(6).toString('hex')}.md`);
|
|
18
91
|
await (0, promises_1.writeFile)(tmpFile, prompt, 'utf-8');
|
|
19
|
-
|
|
20
|
-
|
|
92
|
+
let command = template.replace(/\$PROMPT_FILE/g, tmpFile);
|
|
93
|
+
if (model) {
|
|
94
|
+
command = command.replace(/\$MODEL/g, model);
|
|
95
|
+
// If template doesn't have $MODEL but model is specified, inject --model flag
|
|
96
|
+
if (!template.includes('$MODEL')) {
|
|
97
|
+
command = command.replace(/^(\S+)/, `$1 --model ${model}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Remove $MODEL placeholder and surrounding flags if not provided
|
|
102
|
+
command = command.replace(/--model\s+\$MODEL\s*/g, '');
|
|
103
|
+
command = command.replace(/\$MODEL\s*/g, '');
|
|
104
|
+
}
|
|
105
|
+
// For the claude CLI: switch to stream-json output for real-time streaming.
|
|
106
|
+
// --verbose is required alongside --output-format stream-json when using -p.
|
|
107
|
+
const isClaudeAgent = command.trimStart().startsWith('claude');
|
|
108
|
+
if (isClaudeAgent) {
|
|
109
|
+
// Ensure --verbose is present (required by stream-json in print mode)
|
|
110
|
+
if (!command.includes('--verbose')) {
|
|
111
|
+
command = command.trimEnd() + ' --verbose';
|
|
112
|
+
}
|
|
113
|
+
command = command.trimEnd() + ' --output-format stream-json';
|
|
114
|
+
}
|
|
115
|
+
return { command, tmpFile, isClaudeAgent };
|
|
116
|
+
}
|
|
117
|
+
async function runAgent(options) {
|
|
118
|
+
const { root, onOutput } = options;
|
|
119
|
+
const { command, tmpFile, isClaudeAgent } = await prepareAgent(options);
|
|
21
120
|
try {
|
|
22
121
|
const exitCode = await new Promise((resolve, reject) => {
|
|
122
|
+
// For claude with stream-json we always pipe stdout so we can parse NDJSON.
|
|
123
|
+
// For other agents we inherit stdio when no onOutput is provided.
|
|
124
|
+
const usesPipe = isClaudeAgent || !!onOutput;
|
|
23
125
|
const child = (0, node_child_process_1.spawn)(command, {
|
|
24
126
|
cwd: root,
|
|
25
127
|
shell: true,
|
|
26
|
-
stdio:
|
|
128
|
+
stdio: usesPipe ? ['inherit', 'pipe', 'pipe'] : 'inherit',
|
|
27
129
|
});
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
130
|
+
if (usesPipe) {
|
|
131
|
+
const sink = onOutput ?? ((text) => process.stdout.write(text));
|
|
132
|
+
if (isClaudeAgent) {
|
|
133
|
+
pipeWithNdjsonParsing(child, sink);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (child.stdout)
|
|
137
|
+
child.stdout.on('data', (data) => sink(data.toString()));
|
|
138
|
+
if (child.stderr)
|
|
139
|
+
child.stderr.on('data', (data) => sink(data.toString()));
|
|
140
|
+
}
|
|
33
141
|
}
|
|
34
142
|
child.on('error', reject);
|
|
35
143
|
child.on('close', (code) => resolve(code ?? 1));
|
|
@@ -40,4 +148,48 @@ async function runAgent(options) {
|
|
|
40
148
|
await (0, promises_1.unlink)(tmpFile).catch(() => { });
|
|
41
149
|
}
|
|
42
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Start an agent in interactive mode (stdin piped for Q&A).
|
|
153
|
+
* Returns a handle for writing to stdin, killing the process, and awaiting exit.
|
|
154
|
+
*/
|
|
155
|
+
async function startAgent(options) {
|
|
156
|
+
const { root, onOutput } = options;
|
|
157
|
+
const { command, tmpFile, isClaudeAgent } = await prepareAgent(options);
|
|
158
|
+
const child = (0, node_child_process_1.spawn)(command, {
|
|
159
|
+
cwd: root,
|
|
160
|
+
shell: true,
|
|
161
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
162
|
+
});
|
|
163
|
+
const sink = onOutput ?? ((text) => process.stdout.write(text));
|
|
164
|
+
if (isClaudeAgent) {
|
|
165
|
+
pipeWithNdjsonParsing(child, sink);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
if (child.stdout)
|
|
169
|
+
child.stdout.on('data', (data) => sink(data.toString()));
|
|
170
|
+
if (child.stderr)
|
|
171
|
+
child.stderr.on('data', (data) => sink(data.toString()));
|
|
172
|
+
}
|
|
173
|
+
const exitPromise = new Promise((resolve, reject) => {
|
|
174
|
+
child.on('error', reject);
|
|
175
|
+
child.on('close', (code) => {
|
|
176
|
+
(0, promises_1.unlink)(tmpFile).catch(() => { });
|
|
177
|
+
resolve(code ?? 1);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
exitPromise,
|
|
182
|
+
writeStdin: (data) => {
|
|
183
|
+
if (child.stdin && !child.stdin.destroyed) {
|
|
184
|
+
child.stdin.write(data);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
kill: () => {
|
|
188
|
+
if (!child.killed) {
|
|
189
|
+
child.kill('SIGTERM');
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
promptFile: tmpFile,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
43
195
|
//# sourceMappingURL=agent-runner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-runner.js","sourceRoot":"","sources":["../../src/agent/agent-runner.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"agent-runner.js","sourceRoot":"","sources":["../../src/agent/agent-runner.ts"],"names":[],"mappings":";;AAkJA,4BAiCC;AAMD,gCAwCC;AAjOD,2DAA8D;AAC9D,+CAAqD;AACrD,qCAAiC;AACjC,yCAAiC;AACjC,6CAA0C;AAC1C,2DAA0D;AAuB1D;;;;GAIG;AACH,SAAS,qBAAqB,CAAC,IAAY;IACzC,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,MAAM,CAAC;QACP,4DAA4D;QAC5D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC,EAAE,CAAC;QACtE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,KAAgC,CAAC;IAElD,IAAI,IAAI,KAAK,WAAW,EAAE,CAAC;QACzB,MAAM,OAAO,GAAI,KAAiC,CAAC,OAAO,CAAC;QAC3D,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,O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AE,CAAC,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC1D,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE;YACzB,IAAA,iBAAM,EAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YAChC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,WAAW;QACX,UAAU,EAAE,CAAC,IAAY,EAAE,EAAE;YAC3B,IAAI,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC1C,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,IAAI,EAAE,GAAG,EAAE;YACT,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;gBAClB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;QACD,UAAU,EAAE,OAAO;KACpB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ApiClientConfig } from '../remote/api-client.js';
|
|
2
|
+
export interface WorkerDaemonOptions {
|
|
3
|
+
root: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
agent: string;
|
|
6
|
+
agents?: Record<string, string>;
|
|
7
|
+
apiConfig: ApiClientConfig;
|
|
8
|
+
onLog?: (message: string) => void;
|
|
9
|
+
renderPrompt?: (prompt: string) => string;
|
|
10
|
+
}
|
|
11
|
+
export declare function startWorkerDaemon(options: WorkerDaemonOptions): Promise<void>;
|
|
12
|
+
//# sourceMappingURL=worker-daemon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-daemon.d.ts","sourceRoot":"","sources":["../../src/agent/worker-daemon.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAe/D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,SAAS,EAAE,eAAe,CAAC;IAC3B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C;AAOD,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwNnF"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startWorkerDaemon = startWorkerDaemon;
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const worker_client_js_1 = require("../remote/worker-client.js");
|
|
8
|
+
const agent_runner_js_1 = require("./agent-runner.js");
|
|
9
|
+
const git_js_1 = require("../git/git.js");
|
|
10
|
+
const HEARTBEAT_INTERVAL_MS = 15_000;
|
|
11
|
+
const OUTPUT_FLUSH_INTERVAL_MS = 2_000;
|
|
12
|
+
const QA_POLL_INTERVAL_MS = 2_000;
|
|
13
|
+
const WORKER_STATE_FILE = 'worker.json';
|
|
14
|
+
async function startWorkerDaemon(options) {
|
|
15
|
+
const { root, agent, agents, apiConfig, onLog, renderPrompt } = options;
|
|
16
|
+
const workerName = options.name ?? (0, node_os_1.hostname)();
|
|
17
|
+
const sddDir = (0, node_path_1.join)(root, '.sdd');
|
|
18
|
+
const stateFile = (0, node_path_1.join)(sddDir, WORKER_STATE_FILE);
|
|
19
|
+
const log = onLog ?? ((msg) => process.stderr.write(`[worker] ${msg}\n`));
|
|
20
|
+
const shortId = (id) => id.slice(0, 8);
|
|
21
|
+
// --- Read current branch (informational — no checkout) ---
|
|
22
|
+
const branch = (0, git_js_1.getCurrentBranch)(root) ?? undefined;
|
|
23
|
+
// --- Register ---
|
|
24
|
+
log(`Registering worker "${workerName}" with agent "${agent}"${branch ? ` (branch: ${branch})` : ''}...`);
|
|
25
|
+
const registration = await (0, worker_client_js_1.registerWorker)(apiConfig, workerName, agent, branch, {
|
|
26
|
+
hostname: (0, node_os_1.hostname)(),
|
|
27
|
+
platform: process.platform,
|
|
28
|
+
arch: process.arch,
|
|
29
|
+
});
|
|
30
|
+
const state = {
|
|
31
|
+
workerId: registration.id,
|
|
32
|
+
name: workerName,
|
|
33
|
+
registeredAt: registration.registered_at,
|
|
34
|
+
};
|
|
35
|
+
await (0, promises_1.writeFile)(stateFile, JSON.stringify(state, null, 2), 'utf-8');
|
|
36
|
+
log(`Registered as worker ${shortId(registration.id)}`);
|
|
37
|
+
let running = true;
|
|
38
|
+
let currentJobKill = null;
|
|
39
|
+
// --- Graceful shutdown ---
|
|
40
|
+
const shutdown = async () => {
|
|
41
|
+
log('Shutting down...');
|
|
42
|
+
running = false;
|
|
43
|
+
if (currentJobKill) {
|
|
44
|
+
currentJobKill();
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await (0, worker_client_js_1.workerHeartbeat)(apiConfig, registration.id, 'online');
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
// best effort
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
process.on('SIGINT', () => { shutdown(); });
|
|
54
|
+
process.on('SIGTERM', () => { shutdown(); });
|
|
55
|
+
// --- Heartbeat loop ---
|
|
56
|
+
const heartbeatLoop = async () => {
|
|
57
|
+
while (running) {
|
|
58
|
+
try {
|
|
59
|
+
await (0, worker_client_js_1.workerHeartbeat)(apiConfig, registration.id, currentJobKill ? 'busy' : 'online');
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
const msg = err.message;
|
|
63
|
+
if (!msg.includes('abort')) {
|
|
64
|
+
log(`Heartbeat error: ${msg}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
await sleep(HEARTBEAT_INTERVAL_MS);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// --- Poll & execute loop ---
|
|
71
|
+
const pollLoop = async () => {
|
|
72
|
+
while (running) {
|
|
73
|
+
try {
|
|
74
|
+
const job = await (0, worker_client_js_1.workerPoll)(apiConfig, registration.id);
|
|
75
|
+
if (job && running) {
|
|
76
|
+
await executeJob(job);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
if (!running)
|
|
81
|
+
break;
|
|
82
|
+
const msg = err.message;
|
|
83
|
+
// Don't log abort errors during shutdown
|
|
84
|
+
if (!msg.includes('abort')) {
|
|
85
|
+
log(`Poll error: ${msg}`);
|
|
86
|
+
}
|
|
87
|
+
await sleep(3_000);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
// --- Job execution ---
|
|
92
|
+
const executeJob = async (job) => {
|
|
93
|
+
const jobDesc = job.entity_type ? `${job.entity_type}/${job.entity_id}` : 'sync';
|
|
94
|
+
const jid = shortId(job.job_id);
|
|
95
|
+
log(`┌─ Job ${jid} (${jobDesc})`);
|
|
96
|
+
log(`│ Agent: ${job.agent}${job.model ? ` Model: ${job.model}` : ''}${job.branch ? ` Branch: ${job.branch}` : ''}`);
|
|
97
|
+
const promptPreview = job.prompt.split('\n').find(l => l.trim().length > 0) ?? '';
|
|
98
|
+
log(`└─ ${promptPreview.length > 80 ? promptPreview.slice(0, 80) + '…' : promptPreview}`);
|
|
99
|
+
// Checkout branch if the job explicitly requests one different from the current
|
|
100
|
+
if (job.branch && job.branch !== (0, git_js_1.getCurrentBranch)(root)) {
|
|
101
|
+
log(`Checking out branch "${job.branch}" for job ${job.job_id}...`);
|
|
102
|
+
try {
|
|
103
|
+
(0, git_js_1.checkoutBranch)(root, job.branch);
|
|
104
|
+
}
|
|
105
|
+
catch (err) {
|
|
106
|
+
log(`Warning: could not checkout branch "${job.branch}": ${err.message}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Capture git state before the job starts so we can diff at the end
|
|
110
|
+
const baseCommit = (0, git_js_1.getCurrentCommit)(root);
|
|
111
|
+
try {
|
|
112
|
+
await (0, worker_client_js_1.workerJobStarted)(apiConfig, job.job_id);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
log(`Failed to notify job start: ${err.message}`);
|
|
116
|
+
}
|
|
117
|
+
// Buffer for batched output
|
|
118
|
+
let outputBuffer = [];
|
|
119
|
+
let lastFlush = Date.now();
|
|
120
|
+
let lastAnswerSequence = 0;
|
|
121
|
+
let waitingForAnswer = false;
|
|
122
|
+
const flushOutput = async () => {
|
|
123
|
+
if (outputBuffer.length === 0)
|
|
124
|
+
return;
|
|
125
|
+
const lines = outputBuffer.splice(0);
|
|
126
|
+
try {
|
|
127
|
+
await (0, worker_client_js_1.workerJobOutput)(apiConfig, job.job_id, lines);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
log(`Output flush error: ${err.message}`);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
// Start the agent with interactive mode
|
|
134
|
+
const handle = await (0, agent_runner_js_1.startAgent)({
|
|
135
|
+
root,
|
|
136
|
+
prompt: job.prompt,
|
|
137
|
+
agent: job.agent,
|
|
138
|
+
model: job.model,
|
|
139
|
+
agents,
|
|
140
|
+
onOutput: (data) => {
|
|
141
|
+
// Split into lines but preserve partial lines
|
|
142
|
+
const lines = data.split('\n');
|
|
143
|
+
for (const line of lines) {
|
|
144
|
+
// Suppress the Claude CLI stdin warning — prompt is passed via -p flag,
|
|
145
|
+
// stdin is kept open only for Q&A relay and does not need initial data.
|
|
146
|
+
if (line.includes('no stdin data received') || line.includes('redirect stdin explicitly')) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (line.length > 0) {
|
|
150
|
+
outputBuffer.push(line);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// Flush if enough time has passed
|
|
154
|
+
if (Date.now() - lastFlush >= OUTPUT_FLUSH_INTERVAL_MS) {
|
|
155
|
+
lastFlush = Date.now();
|
|
156
|
+
flushOutput();
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
currentJobKill = handle.kill;
|
|
161
|
+
// Periodic output flush + answer polling loop
|
|
162
|
+
const flushAndPollLoop = async () => {
|
|
163
|
+
while (running) {
|
|
164
|
+
// Flush pending output
|
|
165
|
+
await flushOutput();
|
|
166
|
+
lastFlush = Date.now();
|
|
167
|
+
// If we detected a question, poll for answers
|
|
168
|
+
if (waitingForAnswer) {
|
|
169
|
+
try {
|
|
170
|
+
const answers = await (0, worker_client_js_1.workerJobAnswers)(apiConfig, job.job_id, lastAnswerSequence);
|
|
171
|
+
if (answers.length > 0) {
|
|
172
|
+
for (const ans of answers) {
|
|
173
|
+
handle.writeStdin(ans.content + '\n');
|
|
174
|
+
lastAnswerSequence = ans.sequence;
|
|
175
|
+
}
|
|
176
|
+
waitingForAnswer = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
log(`Answer poll error: ${err.message}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
await sleep(QA_POLL_INTERVAL_MS);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
// Run the flush/poll loop concurrently with the agent
|
|
187
|
+
const flushPromise = flushAndPollLoop();
|
|
188
|
+
try {
|
|
189
|
+
const exitCode = await handle.exitPromise;
|
|
190
|
+
// Final flush
|
|
191
|
+
running = true; // temporarily re-enable to allow final flush
|
|
192
|
+
await flushOutput();
|
|
193
|
+
const changedFiles = (0, git_js_1.getJobChangedFiles)(root, baseCommit);
|
|
194
|
+
const filesMsg = changedFiles.length > 0 ? `, ${changedFiles.length} file(s) changed` : '';
|
|
195
|
+
log(`Job ${jid} done — exit ${exitCode}${filesMsg}`);
|
|
196
|
+
await (0, worker_client_js_1.workerJobCompleted)(apiConfig, job.job_id, exitCode, changedFiles);
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
log(`Job ${jid} error: ${err.message}`);
|
|
200
|
+
try {
|
|
201
|
+
const changedFiles = (0, git_js_1.getJobChangedFiles)(root, baseCommit);
|
|
202
|
+
await (0, worker_client_js_1.workerJobCompleted)(apiConfig, job.job_id, 1, changedFiles);
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
// best effort
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
currentJobKill = null;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
// --- Start concurrent loops ---
|
|
213
|
+
log(`Worker "${workerName}" is online. Waiting for jobs… (id: ${shortId(registration.id)})`);
|
|
214
|
+
await Promise.all([heartbeatLoop(), pollLoop()]);
|
|
215
|
+
log('Worker stopped.');
|
|
216
|
+
}
|
|
217
|
+
function sleep(ms) {
|
|
218
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=worker-daemon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-daemon.js","sourceRoot":"","sources":["../../src/agent/worker-daemon.ts"],"names":[],"mappings":";;AAiCA,8CAwNC;AAzPD,qCAAmC;AACnC,+CAAuD;AACvD,yCAA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jC,GAAG,CAAC,WAAW,UAAU,uCAAuC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAC7F,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IACjD,GAAG,CAAC,iBAAiB,CAAC,CAAC;AACzB,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"}
|
package/dist/git/git.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ export declare function getCurrentCommit(root: string): string | null;
|
|
|
5
5
|
export declare function getGitDiff(root: string, fromCommit: string | null): string;
|
|
6
6
|
export declare function getFileDiff(root: string, filePath: string): string;
|
|
7
7
|
export declare function getGitModifiedFiles(root: string): Set<string>;
|
|
8
|
+
export declare function getCurrentBranch(root: string): string | null;
|
|
9
|
+
export declare function checkoutBranch(root: string, branch: string): void;
|
|
10
|
+
export declare function getJobChangedFiles(root: string, fromCommit: string | null): Array<{
|
|
11
|
+
path: string;
|
|
12
|
+
status: 'new' | 'modified' | 'deleted';
|
|
13
|
+
}>;
|
|
8
14
|
export declare function getChangedFiles(root: string, fromCommit: string | null): Array<{
|
|
9
15
|
path: string;
|
|
10
16
|
status: 'new' | 'modified' | 'deleted';
|
package/dist/git/git.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/git/git.ts"],"names":[],"mappings":"AAQA,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,OAA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MAAM,CAAC,CAgB7D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM5D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAOjE;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC,CAuCjE;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,KAAK,GAAG,UAAU,GAAG,SAAS,CAAA;CAAE,CAAC,CAyBxI"}
|
package/dist/git/git.js
CHANGED
|
@@ -7,6 +7,9 @@ exports.getCurrentCommit = getCurrentCommit;
|
|
|
7
7
|
exports.getGitDiff = getGitDiff;
|
|
8
8
|
exports.getFileDiff = getFileDiff;
|
|
9
9
|
exports.getGitModifiedFiles = getGitModifiedFiles;
|
|
10
|
+
exports.getCurrentBranch = getCurrentBranch;
|
|
11
|
+
exports.checkoutBranch = checkoutBranch;
|
|
12
|
+
exports.getJobChangedFiles = getJobChangedFiles;
|
|
10
13
|
exports.getChangedFiles = getChangedFiles;
|
|
11
14
|
const node_child_process_1 = require("node:child_process");
|
|
12
15
|
const node_fs_1 = require("node:fs");
|
|
@@ -96,6 +99,63 @@ function getGitModifiedFiles(root) {
|
|
|
96
99
|
}
|
|
97
100
|
return modified;
|
|
98
101
|
}
|
|
102
|
+
function getCurrentBranch(root) {
|
|
103
|
+
try {
|
|
104
|
+
return run('git rev-parse --abbrev-ref HEAD', root) || null;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function checkoutBranch(root, branch) {
|
|
111
|
+
try {
|
|
112
|
+
run(`git checkout ${branch}`, root);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// branch doesn't exist — create it
|
|
116
|
+
run(`git checkout -b ${branch}`, root);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function getJobChangedFiles(root, fromCommit) {
|
|
120
|
+
const result = new Map();
|
|
121
|
+
try {
|
|
122
|
+
// Committed changes since the base commit
|
|
123
|
+
if (fromCommit) {
|
|
124
|
+
const committed = run(`git diff --name-status ${fromCommit} HEAD`, root);
|
|
125
|
+
for (const line of committed.split('\n').filter(Boolean)) {
|
|
126
|
+
const parts = line.split('\t');
|
|
127
|
+
const flag = parts[0][0]; // first char (A/M/D/R/C)
|
|
128
|
+
// Renames have two paths: old\tnew — use the new path
|
|
129
|
+
const path = parts.length >= 3 ? parts[2] : parts[1];
|
|
130
|
+
const fileStatus = flag === 'A' ? 'new' : flag === 'D' ? 'deleted' : 'modified';
|
|
131
|
+
result.set(path, fileStatus);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// Uncommitted working tree changes (staged + unstaged + untracked)
|
|
135
|
+
const porcelain = run('git status --porcelain', root);
|
|
136
|
+
for (const line of porcelain.split('\n').filter(Boolean)) {
|
|
137
|
+
const xy = line.substring(0, 2);
|
|
138
|
+
const rawPath = line.substring(3).trim();
|
|
139
|
+
// Renamed files show as "old -> new" in porcelain v1
|
|
140
|
+
const path = rawPath.includes(' -> ') ? rawPath.split(' -> ')[1] : rawPath;
|
|
141
|
+
if (xy[0] === 'D' || xy[1] === 'D') {
|
|
142
|
+
result.set(path, 'deleted');
|
|
143
|
+
}
|
|
144
|
+
else if (xy === '??' || xy[0] === 'A' || xy[1] === 'A') {
|
|
145
|
+
if (!result.has(path))
|
|
146
|
+
result.set(path, 'new');
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
if (!result.has(path))
|
|
150
|
+
result.set(path, 'modified');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// not a git repo or no commits — return empty
|
|
156
|
+
}
|
|
157
|
+
return Array.from(result.entries()).map(([path, status]) => ({ path, status }));
|
|
158
|
+
}
|
|
99
159
|
function getChangedFiles(root, fromCommit) {
|
|
100
160
|
try {
|
|
101
161
|
if (!fromCommit) {
|
package/dist/git/git.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git/git.ts"],"names":[],"mappings":";;AAQA,8BAEC;AAED,0BAEC;AAED,0CASC;AAED,4CAMC;AAED,gCAoBC;AAED,kCAUC;AAED,kDAgBC;AAED,0CAyBC;
|
|
1
|
+
{"version":3,"file":"git.js","sourceRoot":"","sources":["../../src/git/git.ts"],"names":[],"mappings":";;AAQA,8BAEC;AAED,0BAEC;AAED,0CASC;AAED,4CAMC;AAED,gCAoBC;AAED,kCAUC;AAED,kDAgBC;AAED,4CAMC;AAED,wCAOC;AAED,gDA0CC;AAED,0CAyBC;AA7KD,2DAA8C;AAC9C,qCAAqC;AACrC,yCAAoC;AAEpC,SAAS,GAAG,CAAC,GAAW,EAAE,GAAW;IACnC,OAAO,IAAA,6BAAQ,EAAC,GAAG,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAC3F,CAAC;AAED,SAAgB,SAAS,CAAC,IAAY;IACpC,OAAO,IAAA,oBAAU,EAAC,IAAA,mBAAO,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,SAAgB,OAAO,CAAC,IAAY;IAClC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC;AAED,SAAgB,eAAe,CAAC,IAAY,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